the-campfire 0.4.1 → 0.4.2
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/assets/{MermaidDiagram-Cas1Ngze.js → MermaidDiagram-MEJPd6mx.js} +2 -2
- package/dist/assets/{_basePickBy-D1h3RRT9.js → _basePickBy-D70yI6q2.js} +1 -1
- package/dist/assets/{_baseUniq-Z9p6uaM9.js → _baseUniq-DSr-1Cmr.js} +1 -1
- package/dist/assets/{arc-DJLNkmre.js → arc-DxFi1YLd.js} +1 -1
- package/dist/assets/{architectureDiagram-VXUJARFQ-CBHHYg8R.js → architectureDiagram-VXUJARFQ-BLtizKYR.js} +1 -1
- package/dist/assets/{blockDiagram-VD42YOAC-DMtvAHPO.js → blockDiagram-VD42YOAC-CejRqy-r.js} +1 -1
- package/dist/assets/{c4Diagram-YG6GDRKO-G9Zj2LWB.js → c4Diagram-YG6GDRKO-DAlwCYNw.js} +1 -1
- package/dist/assets/channel-Bfa7iezh.js +1 -0
- package/dist/assets/{chunk-4BX2VUAB-s3svQOtk.js → chunk-4BX2VUAB-DiH2UFun.js} +1 -1
- package/dist/assets/{chunk-55IACEB6-C6fhtS_L.js → chunk-55IACEB6-C_-j-CBK.js} +1 -1
- package/dist/assets/{chunk-B4BG7PRW-CpePj3eQ.js → chunk-B4BG7PRW-CR7rsRrQ.js} +1 -1
- package/dist/assets/{chunk-DI55MBZ5-Dq9AChBD.js → chunk-DI55MBZ5-DZyJcgkv.js} +1 -1
- package/dist/assets/{chunk-FMBD7UC4-DSOMddvX.js → chunk-FMBD7UC4-BfSY8Fz-.js} +1 -1
- package/dist/assets/{chunk-QN33PNHL-ZrdWE4nY.js → chunk-QN33PNHL-DqGEAMj7.js} +1 -1
- package/dist/assets/{chunk-QZHKN3VN-BqLE4kwR.js → chunk-QZHKN3VN-BYORtGB9.js} +1 -1
- package/dist/assets/{chunk-TZMSLE5B-DY7GliuX.js → chunk-TZMSLE5B-ML2-LHxr.js} +1 -1
- package/dist/assets/classDiagram-2ON5EDUG-Bdi8d5vQ.js +1 -0
- package/dist/assets/classDiagram-v2-WZHVMYZB-Bdi8d5vQ.js +1 -0
- package/dist/assets/clone-B6MoOTpy.js +1 -0
- package/dist/assets/{cose-bilkent-S5V4N54A-DmRYvz2l.js → cose-bilkent-S5V4N54A-D7RON1r5.js} +1 -1
- package/dist/assets/{dagre-6UL2VRFP-D4IfaYgb.js → dagre-6UL2VRFP-DOEU1l1w.js} +1 -1
- package/dist/assets/{diagram-PSM6KHXK-ClfgeCpw.js → diagram-PSM6KHXK-Bzd2xfRy.js} +1 -1
- package/dist/assets/{diagram-QEK2KX5R-BaBfarh-.js → diagram-QEK2KX5R-CR2bplQ8.js} +1 -1
- package/dist/assets/{diagram-S2PKOQOG-DT1eYmOM.js → diagram-S2PKOQOG-DXUFWseu.js} +1 -1
- package/dist/assets/{erDiagram-Q2GNP2WA-C5ZVoHhn.js → erDiagram-Q2GNP2WA-zellTdL6.js} +1 -1
- package/dist/assets/{flowDiagram-NV44I4VS-C9MYAakn.js → flowDiagram-NV44I4VS-DSQE0oto.js} +1 -1
- package/dist/assets/{ganttDiagram-JELNMOA3-HHt6rJj9.js → ganttDiagram-JELNMOA3-n33b_Mok.js} +1 -1
- package/dist/assets/{gitGraphDiagram-V2S2FVAM-CfA3qwoT.js → gitGraphDiagram-V2S2FVAM-C6w9ezf9.js} +1 -1
- package/dist/assets/{graph-BLJloKEi.js → graph-lEDIRLIz.js} +1 -1
- package/dist/assets/{index-CxNtY8EJ.js → index-r6xPXN5y.js} +23 -23
- package/dist/assets/{infoDiagram-HS3SLOUP-ASXl-hwl.js → infoDiagram-HS3SLOUP-CCXoee5C.js} +1 -1
- package/dist/assets/{journeyDiagram-XKPGCS4Q-B-wDjjzW.js → journeyDiagram-XKPGCS4Q-BlvGkmG9.js} +1 -1
- package/dist/assets/{kanban-definition-3W4ZIXB7-BNWLVKm2.js → kanban-definition-3W4ZIXB7-DsZMbBk9.js} +1 -1
- package/dist/assets/{layout-cpBTqNBI.js → layout-DkcQqbvb.js} +1 -1
- package/dist/assets/{linear-DAonGknK.js → linear-CQfT1IRD.js} +1 -1
- package/dist/assets/{mermaid.core-BdetWGOO.js → mermaid.core-BXpZOyO2.js} +4 -4
- package/dist/assets/{mindmap-definition-VGOIOE7T-CJOEqJKm.js → mindmap-definition-VGOIOE7T-CIpeZEaH.js} +1 -1
- package/dist/assets/{pieDiagram-ADFJNKIX-Dnc1ekZC.js → pieDiagram-ADFJNKIX-CcWLJn44.js} +1 -1
- package/dist/assets/{quadrantDiagram-AYHSOK5B-Dr56Xspi.js → quadrantDiagram-AYHSOK5B-3UAt3O_I.js} +1 -1
- package/dist/assets/{requirementDiagram-UZGBJVZJ-z-G-ThCz.js → requirementDiagram-UZGBJVZJ-ZAMh9JXd.js} +1 -1
- package/dist/assets/{sankeyDiagram-TZEHDZUN-D_4p6Me1.js → sankeyDiagram-TZEHDZUN-CDWs199P.js} +1 -1
- package/dist/assets/{sequenceDiagram-WL72ISMW-DD1K4OoS.js → sequenceDiagram-WL72ISMW-CI6pFtxS.js} +1 -1
- package/dist/assets/{stateDiagram-FKZM4ZOC-ENIvCriI.js → stateDiagram-FKZM4ZOC-T2aD4Oly.js} +1 -1
- package/dist/assets/stateDiagram-v2-4FDKWEC3-ClCJKqOH.js +1 -0
- package/dist/assets/{timeline-definition-IT6M3QCI-V8I1MBPc.js → timeline-definition-IT6M3QCI-DQ-1OoLg.js} +1 -1
- package/dist/assets/{treemap-GDKQZRPO-1lnlvkR3.js → treemap-GDKQZRPO-C1lt_oA_.js} +1 -1
- package/dist/assets/{xychartDiagram-PRI3JC2R-CrSrN3UV.js → xychartDiagram-PRI3JC2R-CS02b1Nn.js} +1 -1
- package/dist/index.html +1 -1
- package/package.json +1 -1
- package/server/env-sanitizer.ts +48 -0
- package/server/index.ts +11 -0
- package/dist/assets/channel-CcCVj0rn.js +0 -1
- package/dist/assets/classDiagram-2ON5EDUG-8I6xWkSV.js +0 -1
- package/dist/assets/classDiagram-v2-WZHVMYZB-8I6xWkSV.js +0 -1
- package/dist/assets/clone-zAvPgvOP.js +0 -1
- package/dist/assets/stateDiagram-v2-4FDKWEC3-BgJoZY9E.js +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const a of document.querySelectorAll('link[rel="modulepreload"]'))n(a);new MutationObserver(a=>{for(const l of a)if(l.type==="childList")for(const c of l.addedNodes)c.tagName==="LINK"&&c.rel==="modulepreload"&&n(c)}).observe(document,{childList:!0,subtree:!0});function s(a){const l={};return a.integrity&&(l.integrity=a.integrity),a.referrerPolicy&&(l.referrerPolicy=a.referrerPolicy),a.crossOrigin==="use-credentials"?l.credentials="include":a.crossOrigin==="anonymous"?l.credentials="omit":l.credentials="same-origin",l}function n(a){if(a.ep)return;a.ep=!0;const l=s(a);fetch(a.href,l)}})();function b0(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function
|
|
1
|
+
(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const a of document.querySelectorAll('link[rel="modulepreload"]'))n(a);new MutationObserver(a=>{for(const l of a)if(l.type==="childList")for(const c of l.addedNodes)c.tagName==="LINK"&&c.rel==="modulepreload"&&n(c)}).observe(document,{childList:!0,subtree:!0});function s(a){const l={};return a.integrity&&(l.integrity=a.integrity),a.referrerPolicy&&(l.referrerPolicy=a.referrerPolicy),a.crossOrigin==="use-credentials"?l.credentials="include":a.crossOrigin==="anonymous"?l.credentials="omit":l.credentials="same-origin",l}function n(a){if(a.ep)return;a.ep=!0;const l=s(a);fetch(a.href,l)}})();function b0(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function QH(e){if(Object.prototype.hasOwnProperty.call(e,"__esModule"))return e;var t=e.default;if(typeof t=="function"){var s=function n(){return this instanceof n?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};s.prototype=t.prototype}else s={};return Object.defineProperty(s,"__esModule",{value:!0}),Object.keys(e).forEach(function(n){var a=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(s,n,a.get?a:{enumerable:!0,get:function(){return e[n]}})}),s}var xm={exports:{}},ql={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.js
|
|
4
4
|
*
|
|
@@ -92,7 +92,7 @@ Error generating stack: `+p.message+`
|
|
|
92
92
|
`);return t?s.pop():s.push(s.pop().slice(0,-1)),s}function zL(e,t){return BL("","",e,t,"","",{context:3}).hunks.map(n=>{const a=`@@ -${n.oldStart},${n.oldLines} +${n.newStart},${n.newLines} @@`,l=[];let c=n.oldStart,d=n.newStart;for(const f of n.lines){const h=f[0],m=f.slice(1);h==="-"?l.push({type:"del",content:m,oldLineNo:c++}):h==="+"?l.push({type:"add",content:m,newLineNo:d++}):l.push({type:"context",content:m,oldLineNo:c++,newLineNo:d++})}return Zk(l),{header:a,lines:l}})}function PL(e){const t=[],s=e.split(`
|
|
93
93
|
`);let n=null,a=null,l=0,c=0;for(const d of s){if(d.startsWith("diff --git")||d.startsWith("diff --cc")){a&&n&&n.hunks.push(a),n&&t.push(n),n={fileName:"",hunks:[]},a=null;continue}if(d.startsWith("--- a/")||d.startsWith("--- /dev/null"))continue;if(d.startsWith("+++ b/")){n&&(n.fileName=d.slice(6));continue}if(d.startsWith("+++ /dev/null")||d.startsWith("index ")||d.startsWith("new file")||d.startsWith("deleted file")||d.startsWith("old mode")||d.startsWith("new mode")||d.startsWith("rename from")||d.startsWith("rename to")||d.startsWith("similarity index")||d.startsWith("Binary files"))continue;const f=d.match(/^@@\s+-(\d+)(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s+@@(.*)$/);if(f){a&&n&&n.hunks.push(a),l=parseInt(f[1],10),c=parseInt(f[2],10),a={header:d,lines:[]};continue}a&&(d.startsWith("+")?a.lines.push({type:"add",content:d.slice(1),newLineNo:c++}):d.startsWith("-")?a.lines.push({type:"del",content:d.slice(1),oldLineNo:l++}):d.startsWith(" ")&&a.lines.push({type:"context",content:d.slice(1),oldLineNo:l++,newLineNo:c++}))}a&&n&&n.hunks.push(a),n&&t.push(n);for(const d of t)for(const f of d.hunks)Zk(f.lines);return t}function Zk(e){let t=0;for(;t<e.length;){const s=t;for(;t<e.length&&e[t].type==="del";)t++;const n=t,a=t;for(;t<e.length&&e[t].type==="add";)t++;const l=t,c=n-s,d=l-a;if(c>0&&d>0){const f=Math.min(c,d);for(let h=0;h<f;h++){const m=e[s+h],g=e[a+h],b=AL(m.content,g.content);m.wordChanges=b.filter(v=>!v.added).map(v=>({value:v.value,removed:v.removed})),g.wordChanges=b.filter(v=>!v.removed).map(v=>({value:v.value,added:v.added}))}}t===s&&t++}}function $L({line:e}){return e.wordChanges?r.jsx(r.Fragment,{children:e.wordChanges.map((t,s)=>t.added?r.jsx("span",{className:"diff-word-add",children:t.value},s):t.removed?r.jsx("span",{className:"diff-word-del",children:t.value},s):r.jsx("span",{children:t.value},s))}):r.jsx(r.Fragment,{children:e.content})}function IL({hunk:e,showLineNumbers:t}){return r.jsxs("div",{className:"diff-hunk",children:[r.jsx("div",{className:"diff-hunk-header",children:e.header}),e.lines.map((s,n)=>r.jsxs("div",{className:`diff-line diff-line-${s.type}`,children:[t&&r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"diff-gutter diff-gutter-old",children:s.oldLineNo??""}),r.jsx("span",{className:"diff-gutter diff-gutter-new",children:s.newLineNo??""})]}),r.jsx("span",{className:"diff-marker",children:s.type==="add"?"+":s.type==="del"?"-":" "}),r.jsxs("span",{className:"diff-content",children:[r.jsx($L,{line:s}),!s.content&&" "]})]},n))]})}function FL({fileName:e}){const t=e.split("/"),s=t.pop()||e,n=t.join("/");return r.jsxs("div",{className:"diff-file-header",children:[r.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"w-3.5 h-3.5 text-cc-primary shrink-0",children:[r.jsx("path",{d:"M9 1H4a1 1 0 00-1 1v12a1 1 0 001 1h8a1 1 0 001-1V5L9 1z"}),r.jsx("polyline",{points:"9 1 9 5 13 5"})]}),n&&r.jsxs("span",{className:"text-cc-muted",children:[n,"/"]}),r.jsx("span",{className:"font-semibold text-cc-fg",children:s})]})}function yr({oldText:e,newText:t,unifiedDiff:s,fileName:n,mode:a="compact"}){const l=a==="compact",c=!l,d=w.useMemo(()=>{if(s)return PL(s);const f=e??"",h=t??"";if(!f&&!h)return[];const m=zL(f,h);return[{fileName:n||"",hunks:m}]},[e,t,s,n]);return d.length===0||d.every(f=>f.hunks.length===0)?r.jsx("div",{className:"diff-viewer diff-empty",children:r.jsx("span",{className:"text-cc-muted text-xs",children:"No changes"})}):r.jsx("div",{className:`diff-viewer ${l?"diff-compact":"diff-full"}`,children:d.map((f,h)=>r.jsxs("div",{className:"diff-file",children:[(f.fileName||n)&&r.jsx(FL,{fileName:f.fileName||n||""}),f.hunks.map((m,g)=>r.jsx(IL,{hunk:m,showLineNumbers:c},g))]},h))})}const HL={Bash:"terminal",Read:"file",Write:"file-plus",Edit:"file-edit",Glob:"search",Grep:"search",WebFetch:"globe",WebSearch:"globe",NotebookEdit:"notebook",Task:"agent",TodoWrite:"checklist",TaskCreate:"list",TaskUpdate:"list",SendMessage:"message",web_search:"globe",mcp_tool_call:"tool"};function du(e){return HL[e]||"tool"}function Ta(e){return e==="Bash"?"Terminal":e==="Read"?"Read File":e==="Write"?"Write File":e==="Edit"?"Edit File":e==="Glob"?"Find Files":e==="Grep"?"Search Content":e==="WebSearch"?"Web Search":e==="WebFetch"?"Web Fetch":e==="Task"?"Subagent":e==="TodoWrite"?"Tasks":e==="NotebookEdit"?"Notebook":e==="SendMessage"?"Message":e==="web_search"?"Web Search":e==="mcp_tool_call"?"MCP Tool":e.startsWith("mcp:")?e.split(":").slice(1).join(":"):e}function mn({name:e,input:t,toolUseId:s}){const[n,a]=w.useState(!1),l=du(e),c=Ta(e),d=Ko(e,t);return r.jsxs("div",{className:`rounded-lg border border-cc-border/60 bg-cc-card shadow-sm transition-all duration-200 ${n?"":"hover:bg-cc-hover/50"}`,children:[r.jsxs("button",{onClick:()=>a(!n),className:"w-full flex items-center gap-2 px-3 py-1.5 text-left rounded-lg transition-all duration-200 cursor-pointer",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:`w-4 h-4 text-cc-muted/60 transition-transform duration-200 shrink-0 ${n?"rotate-90":""}`,children:r.jsx("path",{d:"M6 4l4 4-4 4"})}),r.jsx(Aa,{type:l}),r.jsx("span",{className:"text-[12px] font-medium text-cc-fg font-mono-code",children:c}),d&&r.jsx("span",{className:"text-[11px] text-cc-muted/80 font-mono-code truncate flex-1",children:d})]}),n&&r.jsx("div",{className:"border-t border-cc-border/40 px-4 py-3 bg-cc-bg/50 rounded-b-lg",children:r.jsx(UL,{name:e,input:t})})]})}function UL({name:e,input:t}){switch(e){case"Bash":return r.jsx(VL,{input:t});case"Edit":return r.jsx(WL,{input:t});case"Write":return r.jsx(qL,{input:t});case"Read":return r.jsx(GL,{input:t});case"Glob":return r.jsx(KL,{input:t});case"Grep":return r.jsx(YL,{input:t});case"WebSearch":case"web_search":return r.jsx(XL,{input:t});case"WebFetch":return r.jsx(JL,{input:t});case"Task":return r.jsx(QL,{input:t});case"TodoWrite":return r.jsx(ZL,{input:t});case"NotebookEdit":return r.jsx(eB,{input:t});case"SendMessage":return r.jsx(tB,{input:t});default:return r.jsx("pre",{className:"text-[11px] text-cc-muted font-mono-code whitespace-pre-wrap leading-relaxed max-h-60 overflow-y-auto",children:JSON.stringify(t,null,2)})}}function VL({input:e}){return r.jsxs("div",{className:"space-y-2",children:[!!e.description&&r.jsx("div",{className:"text-[11px] text-cc-muted italic mb-2",children:String(e.description)}),r.jsxs("pre",{className:"px-3 py-2.5 rounded-lg border border-cc-border bg-cc-code-bg text-cc-code-fg text-[12px] font-mono-code leading-relaxed overflow-x-auto",children:[r.jsx("span",{className:"text-cc-muted select-none",children:"$ "}),String(e.command||"")]}),!!e.timeout&&r.jsxs("span",{className:"inline-block rounded-full bg-cc-warning/10 text-cc-warning px-2 py-0.5 text-[10px] font-medium",children:["timeout: ",String(e.timeout),"ms"]})]})}function WL({input:e}){const t=String(e.file_path||""),s=String(e.old_string||""),n=String(e.new_string||"");return r.jsxs("div",{className:"space-y-2",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"rounded-md bg-cc-hover px-2 py-0.5 text-[11px] font-mono-code text-cc-fg truncate",children:t}),!!e.replace_all&&r.jsx("span",{className:"shrink-0 rounded-full bg-cc-warning/10 text-cc-warning px-2 py-0.5 text-[10px] font-medium",children:"replace all"})]}),r.jsx(yr,{oldText:s,newText:n,fileName:t,mode:"compact"})]})}function qL({input:e}){const t=String(e.file_path||""),s=String(e.content||"");return r.jsxs("div",{className:"space-y-2",children:[r.jsx("div",{className:"rounded-md bg-cc-hover px-2 py-0.5 text-[11px] font-mono-code text-cc-fg truncate inline-block",children:t}),r.jsx(yr,{newText:s,fileName:t,mode:"compact"})]})}function GL({input:e}){const t=String(e.file_path||e.path||""),s=e.offset,n=e.limit,a=s!=null||n!=null,l=s??1,c=n!=null?l+n-1:void 0;return r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-[11px] font-mono-code text-cc-fg truncate",children:t}),a&&r.jsx("span",{className:"shrink-0 rounded-full bg-cc-hover px-2 py-0.5 text-[10px] font-medium text-cc-muted",children:c!=null?`lines ${l}–${c}`:`from line ${l}`})]})}function KL({input:e}){return r.jsxs("div",{className:"space-y-2",children:[r.jsx("pre",{className:"inline-block px-2.5 py-1 rounded-lg border border-cc-border bg-cc-code-bg text-cc-code-fg text-[11px] font-mono-code",children:String(e.pattern||"")}),!!e.path&&r.jsxs("div",{className:"text-[10px] text-cc-muted",children:["path: ",r.jsx("span",{className:"font-mono-code",children:String(e.path)})]})]})}function YL({input:e}){return r.jsxs("div",{className:"space-y-2",children:[r.jsx("pre",{className:"px-3 py-2 rounded-lg border border-cc-border bg-cc-code-bg text-cc-code-fg text-[12px] font-mono-code overflow-x-auto",children:String(e.pattern||"")}),r.jsxs("div",{className:"flex flex-wrap gap-1.5 text-[10px]",children:[!!e.path&&r.jsxs("span",{className:"rounded-full bg-cc-hover px-2 py-0.5 text-cc-muted font-medium",children:["path: ",r.jsx("span",{className:"font-mono-code",children:String(e.path)})]}),!!e.glob&&r.jsxs("span",{className:"rounded-full bg-cc-hover px-2 py-0.5 text-cc-muted font-medium",children:["glob: ",r.jsx("span",{className:"font-mono-code",children:String(e.glob)})]}),!!e.output_mode&&r.jsxs("span",{className:"rounded-full bg-cc-hover px-2 py-0.5 text-cc-muted font-medium",children:["mode: ",String(e.output_mode)]}),!!e.context&&r.jsxs("span",{className:"rounded-full bg-cc-hover px-2 py-0.5 text-cc-muted font-medium",children:["context: ",String(e.context)]}),!!e.head_limit&&r.jsxs("span",{className:"rounded-full bg-cc-hover px-2 py-0.5 text-cc-muted font-medium",children:["limit: ",String(e.head_limit)]})]})]})}function XL({input:e}){return r.jsxs("div",{className:"space-y-2",children:[r.jsx("div",{className:"text-xs text-cc-fg font-medium",children:String(e.query||"")}),Array.isArray(e.allowed_domains)&&e.allowed_domains.length>0&&r.jsx("div",{className:"flex flex-wrap gap-1.5",children:e.allowed_domains.map((t,s)=>r.jsx("span",{className:"rounded-full bg-cc-hover px-2 py-0.5 text-[10px] text-cc-muted font-medium font-mono-code",children:t},s))})]})}function JL({input:e}){return r.jsxs("div",{className:"space-y-2",children:[!!e.url&&r.jsx("div",{className:"text-xs font-mono-code text-cc-primary truncate",children:String(e.url)}),!!e.prompt&&r.jsx("div",{className:"text-[11px] text-cc-muted italic line-clamp-2",children:String(e.prompt)})]})}function QL({input:e}){return r.jsxs("div",{className:"space-y-2",children:[!!e.description&&r.jsx("div",{className:"text-xs text-cc-fg font-medium",children:String(e.description)}),!!e.subagent_type&&r.jsx("span",{className:"inline-block rounded-full bg-cc-primary/10 text-cc-primary px-2 py-0.5 text-[10px] font-medium",children:String(e.subagent_type)}),!!e.prompt&&r.jsx("pre",{className:"px-3 py-2.5 rounded-lg border border-cc-border bg-cc-code-bg text-[11px] text-cc-muted font-mono-code whitespace-pre-wrap leading-relaxed max-h-40 overflow-y-auto",children:String(e.prompt)})]})}function ZL({input:e}){const t=e.todos;return Array.isArray(t)?r.jsx("div",{className:"rounded-lg border border-cc-border/40 bg-cc-card p-2.5 space-y-1",children:t.map((s,n)=>{const a=s.status||"pending";return r.jsxs("div",{className:"flex items-start gap-2 py-0.5",children:[r.jsx("span",{className:"shrink-0 mt-0.5",children:a==="completed"?r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 text-cc-success",children:r.jsx("path",{fillRule:"evenodd",d:"M8 15A7 7 0 108 1a7 7 0 000 14zm3.354-9.354a.5.5 0 00-.708-.708L7 8.586 5.354 6.94a.5.5 0 10-.708.708l2 2a.5.5 0 00.708 0l4-4z",clipRule:"evenodd"})}):a==="in_progress"?r.jsx("svg",{className:"w-3.5 h-3.5 text-cc-primary animate-spin",viewBox:"0 0 16 16",fill:"none",children:r.jsx("circle",{cx:"8",cy:"8",r:"6",stroke:"currentColor",strokeWidth:"1.5",strokeDasharray:"28",strokeDashoffset:"8",strokeLinecap:"round"})}):r.jsx("svg",{viewBox:"0 0 16 16",fill:"none",className:"w-3.5 h-3.5 text-cc-muted",children:r.jsx("circle",{cx:"8",cy:"8",r:"6",stroke:"currentColor",strokeWidth:"1.5"})})}),r.jsx("span",{className:`text-[11px] leading-snug ${a==="completed"?"text-cc-muted line-through":"text-cc-fg"}`,children:s.content||"Task"})]},n)})}):r.jsx("pre",{className:"text-[11px] text-cc-muted font-mono-code whitespace-pre-wrap leading-relaxed max-h-60 overflow-y-auto",children:JSON.stringify(e,null,2)})}function eB({input:e}){const t=String(e.notebook_path||""),s=e.cell_type,n=e.edit_mode;return r.jsxs("div",{className:"space-y-2",children:[r.jsx("div",{className:"rounded-md bg-cc-hover px-2 py-0.5 text-[11px] font-mono-code text-cc-fg inline-block",children:t}),r.jsxs("div",{className:"flex gap-1.5 text-[10px]",children:[s&&r.jsxs("span",{className:"rounded-full bg-cc-hover px-2 py-0.5 text-cc-muted font-medium",children:["type: ",s]}),n&&r.jsxs("span",{className:"rounded-full bg-cc-hover px-2 py-0.5 text-cc-muted font-medium",children:["mode: ",n]}),e.cell_number!=null&&r.jsxs("span",{className:"rounded-full bg-cc-hover px-2 py-0.5 text-cc-muted font-medium",children:["cell: ",String(e.cell_number)]})]}),!!e.new_source&&r.jsx("pre",{className:"px-3 py-2.5 rounded-lg border border-cc-border bg-cc-code-bg text-cc-code-fg text-[11px] font-mono-code leading-relaxed max-h-40 overflow-y-auto",children:String(e.new_source)})]})}function tB({input:e}){return r.jsxs("div",{className:"space-y-2",children:[!!e.recipient&&r.jsxs("div",{className:"text-[11px] text-cc-muted",children:["to: ",r.jsx("span",{className:"font-medium text-cc-fg",children:String(e.recipient)})]}),!!e.content&&r.jsx("div",{className:"text-xs text-cc-fg whitespace-pre-wrap",children:String(e.content)})]})}function Ko(e,t){if(e==="Bash"&&typeof t.command=="string"){const s=t.command;return s.length>60?s.slice(0,60)+"…":s}if(e==="Edit"&&t.file_path){const n=String(t.file_path).split("/").slice(-2).join("/"),a=typeof t.old_string=="string"?t.old_string:"",l=typeof t.new_string=="string"?t.new_string:"";if(a||l){const c=a.split(`
|
|
94
94
|
`).length,d=l.split(`
|
|
95
|
-
`).length;return`${n} +${d}/-${c}`}return n}if((e==="Read"||e==="Write")&&t.file_path)return String(t.file_path).split("/").slice(-2).join("/");if(e==="Glob"&&t.pattern)return String(t.pattern);if(e==="Grep"&&t.pattern){const s=String(t.pattern),n=t.path?` in ${String(t.path).split("/").slice(-2).join("/")}`:"",a=s+n;return a.length>60?a.slice(0,60)+"…":a}if((e==="WebSearch"||e==="web_search")&&t.query)return String(t.query);if(e==="WebFetch"&&t.url)try{const s=new URL(String(t.url));return s.hostname+s.pathname}catch{return String(t.url).slice(0,60)}return e==="Task"&&t.description?String(t.description):e==="TodoWrite"&&Array.isArray(t.todos)?`${t.todos.length} task${t.todos.length!==1?"s":""}`:e==="NotebookEdit"&&t.notebook_path?String(t.notebook_path).split("/").pop()||"":e==="SendMessage"&&t.recipient?`→ ${String(t.recipient)}`:""}function Aa({type:e}){const t="w-4 h-4 text-cc-muted/60 shrink-0";return e==="terminal"?r.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:t,children:[r.jsx("polyline",{points:"3 11 6 8 3 5"}),r.jsx("line",{x1:"8",y1:"11",x2:"13",y2:"11"})]}):e==="file"||e==="file-plus"||e==="file-edit"?r.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:t,children:[r.jsx("path",{d:"M9 1H4a1 1 0 00-1 1v12a1 1 0 001 1h8a1 1 0 001-1V5L9 1z"}),r.jsx("polyline",{points:"9 1 9 5 13 5"})]}):e==="search"?r.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:t,children:[r.jsx("circle",{cx:"7",cy:"7",r:"4"}),r.jsx("path",{d:"M13 13l-3-3"})]}):e==="globe"?r.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:t,children:[r.jsx("circle",{cx:"8",cy:"8",r:"6"}),r.jsx("path",{d:"M2 8h12M8 2c2 2 3 4 3 6s-1 4-3 6c-2-2-3-4-3-6s1-4 3-6z"})]}):e==="message"?r.jsx("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:t,children:r.jsx("path",{d:"M14 10a1 1 0 01-1 1H5l-3 3V3a1 1 0 011-1h10a1 1 0 011 1v7z"})}):e==="list"?r.jsx("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:t,children:r.jsx("path",{d:"M3 4h10M3 8h10M3 12h6"})}):e==="agent"?r.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:t,children:[r.jsx("circle",{cx:"8",cy:"5",r:"3"}),r.jsx("path",{d:"M3 14c0-2.8 2.2-5 5-5s5 2.2 5 5",strokeLinecap:"round"})]}):e==="checklist"?r.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:t,children:[r.jsx("path",{d:"M3 4l1.5 1.5L7 3M3 8l1.5 1.5L7 7M3 12l1.5 1.5L7 11",strokeLinecap:"round",strokeLinejoin:"round"}),r.jsx("path",{d:"M9 4h4M9 8h4M9 12h4"})]}):e==="notebook"?r.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:t,children:[r.jsx("rect",{x:"3",y:"1",width:"10",height:"14",rx:"1"}),r.jsx("path",{d:"M6 1v14M3 5h3M3 9h3M3 13h3"})]}):r.jsx("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:t,children:r.jsx("path",{d:"M10.5 2.5l3 3-8 8H2.5v-3l8-8z"})})}const sB=w.lazy(()=>Xi(()=>import("./MermaidDiagram-
|
|
95
|
+
`).length;return`${n} +${d}/-${c}`}return n}if((e==="Read"||e==="Write")&&t.file_path)return String(t.file_path).split("/").slice(-2).join("/");if(e==="Glob"&&t.pattern)return String(t.pattern);if(e==="Grep"&&t.pattern){const s=String(t.pattern),n=t.path?` in ${String(t.path).split("/").slice(-2).join("/")}`:"",a=s+n;return a.length>60?a.slice(0,60)+"…":a}if((e==="WebSearch"||e==="web_search")&&t.query)return String(t.query);if(e==="WebFetch"&&t.url)try{const s=new URL(String(t.url));return s.hostname+s.pathname}catch{return String(t.url).slice(0,60)}return e==="Task"&&t.description?String(t.description):e==="TodoWrite"&&Array.isArray(t.todos)?`${t.todos.length} task${t.todos.length!==1?"s":""}`:e==="NotebookEdit"&&t.notebook_path?String(t.notebook_path).split("/").pop()||"":e==="SendMessage"&&t.recipient?`→ ${String(t.recipient)}`:""}function Aa({type:e}){const t="w-4 h-4 text-cc-muted/60 shrink-0";return e==="terminal"?r.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:t,children:[r.jsx("polyline",{points:"3 11 6 8 3 5"}),r.jsx("line",{x1:"8",y1:"11",x2:"13",y2:"11"})]}):e==="file"||e==="file-plus"||e==="file-edit"?r.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:t,children:[r.jsx("path",{d:"M9 1H4a1 1 0 00-1 1v12a1 1 0 001 1h8a1 1 0 001-1V5L9 1z"}),r.jsx("polyline",{points:"9 1 9 5 13 5"})]}):e==="search"?r.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:t,children:[r.jsx("circle",{cx:"7",cy:"7",r:"4"}),r.jsx("path",{d:"M13 13l-3-3"})]}):e==="globe"?r.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:t,children:[r.jsx("circle",{cx:"8",cy:"8",r:"6"}),r.jsx("path",{d:"M2 8h12M8 2c2 2 3 4 3 6s-1 4-3 6c-2-2-3-4-3-6s1-4 3-6z"})]}):e==="message"?r.jsx("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:t,children:r.jsx("path",{d:"M14 10a1 1 0 01-1 1H5l-3 3V3a1 1 0 011-1h10a1 1 0 011 1v7z"})}):e==="list"?r.jsx("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:t,children:r.jsx("path",{d:"M3 4h10M3 8h10M3 12h6"})}):e==="agent"?r.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:t,children:[r.jsx("circle",{cx:"8",cy:"5",r:"3"}),r.jsx("path",{d:"M3 14c0-2.8 2.2-5 5-5s5 2.2 5 5",strokeLinecap:"round"})]}):e==="checklist"?r.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:t,children:[r.jsx("path",{d:"M3 4l1.5 1.5L7 3M3 8l1.5 1.5L7 7M3 12l1.5 1.5L7 11",strokeLinecap:"round",strokeLinejoin:"round"}),r.jsx("path",{d:"M9 4h4M9 8h4M9 12h4"})]}):e==="notebook"?r.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:t,children:[r.jsx("rect",{x:"3",y:"1",width:"10",height:"14",rx:"1"}),r.jsx("path",{d:"M6 1v14M3 5h3M3 9h3M3 13h3"})]}):r.jsx("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:t,children:r.jsx("path",{d:"M10.5 2.5l3 3-8 8H2.5v-3l8-8z"})})}const sB=w.lazy(()=>Xi(()=>import("./MermaidDiagram-MEJPd6mx.js"),[]).then(e=>({default:e.MermaidDiagram})));function nB(e){var t,s;if(e.content&&typeof e.content=="string"){if((t=e.contentBlocks)!=null&&t.length){const n=e.contentBlocks.filter(a=>a.type==="text").map(a=>a.text);if(n.length>0)return n.join(`
|
|
96
96
|
|
|
97
97
|
`)}return e.content}return(s=e.contentBlocks)!=null&&s.length?e.contentBlocks.filter(n=>n.type==="text").map(n=>n.text).join(`
|
|
98
98
|
|
|
@@ -125,7 +125,7 @@ ${D}`},[f]);return c?G.length===0?r.jsxs("div",{className:"h-full flex flex-col
|
|
|
125
125
|
fixed sm:relative z-30 sm:z-auto
|
|
126
126
|
${I?"sm:w-[220px]":"sm:w-0 sm:-translate-x-full"}
|
|
127
127
|
shrink-0 h-full flex flex-col bg-cc-sidebar border-r border-cc-border transition-all duration-200 overflow-hidden
|
|
128
|
-
`,children:[r.jsxs("div",{className:"w-[220px] px-4 py-3 text-[11px] font-semibold text-cc-fg uppercase tracking-wider border-b border-cc-border shrink-0 flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"w-2 h-2 rounded-full bg-cc-warning"}),r.jsxs("span",{children:["Changed (",G.length,")"]})]}),r.jsx("button",{onClick:()=>H(!1),className:"w-5 h-5 flex items-center justify-center rounded-md text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer sm:hidden",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"w-3 h-3",children:r.jsx("path",{d:"M4 4l8 8M12 4l-8 8",strokeLinecap:"round"})})})]}),r.jsx("div",{className:"flex-1 overflow-y-auto overflow-x-hidden py-1",children:G.map(({abs:W,rel:U})=>r.jsxs("button",{onClick:()=>R(W),className:`flex items-center gap-2 w-full mx-1 px-2 py-1.5 text-[13px] rounded-lg hover:bg-cc-hover transition-colors cursor-pointer whitespace-nowrap ${W===n?"bg-cc-active text-cc-fg":"text-cc-fg/70"}`,style:{width:"calc(100% - 8px)"},children:[r.jsx("svg",{viewBox:"0 0 20 20",fill:"currentColor",className:"w-3.5 h-3.5 text-cc-warning shrink-0",children:r.jsx("path",{fillRule:"evenodd",d:"M4 4a2 2 0 012-2h4.586A2 2 0 0112 2.586L15.414 6A2 2 0 0116 7.414V16a2 2 0 01-2 2H6a2 2 0 01-2-2V4z",clipRule:"evenodd"})}),r.jsx("span",{className:"truncate leading-snug",children:U})]},W))})]}),r.jsxs("div",{className:"flex-1 min-w-0 h-full flex flex-col",children:[n&&r.jsxs("div",{className:"shrink-0 flex items-center gap-2 sm:gap-2.5 px-2 sm:px-4 py-2.5 bg-cc-card border-b border-cc-border",children:[!I&&r.jsx("button",{onClick:()=>H(!0),className:"flex items-center justify-center w-6 h-6 rounded-md text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer shrink-0",title:"Show file list",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:r.jsx("path",{d:"M1 3.5A1.5 1.5 0 012.5 2h3.379a1.5 1.5 0 011.06.44l.622.621a.5.5 0 00.353.146H13.5A1.5 1.5 0 0115 4.707V12.5a1.5 1.5 0 01-1.5 1.5h-11A1.5 1.5 0 011 12.5v-9z"})})}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("span",{className:"text-cc-fg text-[13px] font-medium truncate block",children:M==null?void 0:M.split("/").pop()}),r.jsx("span",{className:"text-cc-muted truncate text-[11px] hidden sm:block font-mono-code",children:M})]}),r.jsx("span",{className:"text-cc-muted text-[11px] shrink-0 hidden sm:inline",children:"Compared to session start"}),r.jsxs("div",{className:"ml-2 hidden sm:flex items-center gap-1 rounded-md bg-cc-bg border border-cc-border p-0.5 text-[11px]",children:[r.jsx("button",{onClick:()=>S("diff"),className:`px-2 py-0.5 rounded cursor-pointer transition-colors ${y==="diff"?"bg-cc-active text-cc-fg":"text-cc-muted hover:text-cc-fg"}`,children:"Diff"}),r.jsx("button",{onClick:()=>S("edit"),className:`px-2 py-0.5 rounded cursor-pointer transition-colors ${y==="edit"?"bg-cc-active text-cc-fg":"text-cc-muted hover:text-cc-fg"}`,children:"Edit"}),r.jsx("button",{onClick:()=>S("raw"),className:`px-2 py-0.5 rounded cursor-pointer transition-colors ${y==="raw"?"bg-cc-active text-cc-fg":"text-cc-muted hover:text-cc-fg"}`,children:"Raw"})]}),y==="edit"&&r.jsxs("div",{className:"ml-2 flex items-center gap-2",children:[r.jsx("button",{onClick:q,disabled:B||!X,className:"px-3 py-1 rounded-md bg-cc-primary text-white text-[11px] font-medium hover:bg-cc-primary-hover transition-colors cursor-pointer disabled:opacity-40",children:B?"Saving...":"Save"}),P&&r.jsx("span",{className:"text-[10px] text-cc-success",children:"Saved"}),X&&!P&&r.jsx("span",{className:"text-[10px] text-cc-warning",children:"Unsaved"})]})]}),r.jsx("div",{className:"flex-1 overflow-auto",children:m?r.jsx("div",{className:"h-full flex items-center justify-center",children:r.jsx("div",{className:"w-5 h-5 border-2 border-cc-primary border-t-transparent rounded-full animate-spin"})}):n&&y==="edit"?E?r.jsx("div",{className:"h-full flex items-center justify-center",children:r.jsx("div",{className:"w-5 h-5 border-2 border-cc-primary border-t-transparent rounded-full animate-spin"})}):r.jsx(w.Suspense,{fallback:r.jsx("div",{className:"h-full flex items-center justify-center text-cc-muted text-[12px]",children:"Loading editor..."}),children:r.jsx(qz,{value:j,onChange:W=>{k(W),Z(!0)},language:av(n),height:"calc(100vh - 120px)",minimap:!0,lineNumbers:!0,wordWrap:!1,ariaLabel:`Editing ${M||n}`,className:"border-0 rounded-none"})}):n?r.jsx("div",{className:"p-4",children:!b&&!f.trim()?r.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-12",children:[r.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"w-8 h-8 text-cc-muted",children:r.jsx("path",{d:"M12 9v4m0 4h.01M5.07 19h13.86c1.05 0 1.7-1.14 1.18-2.06l-6.93-12a1.33 1.33 0 00-2.36 0l-6.93 12c-.52.92.13 2.06 1.18 2.06z",strokeLinecap:"round",strokeLinejoin:"round"})}),r.jsx("p",{className:"text-cc-muted text-sm",children:"File not found on disk"}),r.jsx("p",{className:"text-cc-muted text-xs",children:"The file may have been deleted or the write was not executed."})]}):y==="raw"?O?r.jsx("div",{className:"markdown-body text-[12px] text-cc-fg leading-[1.7]",children:r.jsx(Y0,{remarkPlugins:[Z0],children:O})}):r.jsx("p",{className:"text-cc-muted text-sm",children:"No diff content returned."}):r.jsx(yr,{unifiedDiff:f,fileName:M||void 0,mode:"full"})}):r.jsxs("div",{className:"h-full flex flex-col items-center justify-center",children:[!I&&r.jsxs("button",{onClick:()=>H(!0),className:"mb-4 flex items-center gap-2 px-3 py-2 rounded-lg text-xs text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:r.jsx("path",{d:"M1 3.5A1.5 1.5 0 012.5 2h3.379a1.5 1.5 0 011.06.44l.622.621a.5.5 0 00.353.146H13.5A1.5 1.5 0 0115 4.707V12.5a1.5 1.5 0 01-1.5 1.5h-11A1.5 1.5 0 011 12.5v-9z"})}),"Show file list"]}),r.jsx("p",{className:"text-cc-muted text-sm",children:"Select a file to view changes"})]})})]})]}):r.jsx("div",{className:"flex-1 flex items-center justify-center h-full",children:r.jsx("p",{className:"text-cc-muted text-sm",children:"Waiting for session to initialize..."})})}const Kz=w.lazy(()=>Xi(()=>Promise.resolve().then(()=>fu),void 0).then(e=>({default:e.CodeEditor}))),Yz=new Set(["png","jpg","jpeg","gif","svg","webp","ico","bmp"]);function Tx(e){var s;const t=((s=e.split(".").pop())==null?void 0:s.toLowerCase())||"";return Yz.has(t)}function Xz({sessionId:e}){const t=Y(U=>U.sessions.get(e)),s=Y(U=>U.sdkSessions.find(D=>D.sessionId===e)),n=Y(U=>U.changedFiles.get(e)),a=(t==null?void 0:t.cwd)||(s==null?void 0:s.cwd)||"",[l,c]=w.useState({expanded:new Set,children:new Map,loading:new Set}),[d,f]=w.useState(null),[h,m]=w.useState(""),[g,b]=w.useState(""),[v,y]=w.useState(!1),[S,j]=w.useState(!1),[k,E]=w.useState(!1),[N,B]=w.useState(!1),[A,P]=w.useState(""),[K,X]=w.useState(!1),[Z,I]=w.useState(!0),H=w.useMemo(()=>n??new Set,[n]);w.useEffect(()=>{a&&F(a)},[a,K]);function F(U){c(D=>{const $=new Set(D.loading);return $.add(U),{...D,loading:$}}),se.listEntries(U,K).then(D=>{const $=[...D.entries].sort((z,T)=>z.type!==T.type?z.type==="directory"?-1:1:z.name.localeCompare(T.name));c(z=>{const T=new Map(z.children);T.set(U,$);const ae=new Set(z.loading);return ae.delete(U),{...z,children:T,loading:ae}})}).catch(()=>{c(D=>{const $=new Set(D.loading);return $.delete(U),{...D,loading:$}})})}function G(U){c(D=>{const $=new Set(D.expanded);return $.has(U)?$.delete(U):($.add(U),D.children.has(U)||F(U)),{...D,expanded:$}})}w.useEffect(()=>{if(!d||Tx(d))return;let U=!1;return y(!0),j(!1),B(!1),se.readFile(d).then(D=>{U||(m(D.content),b(D.content),y(!1))}).catch(()=>{U||(m(""),b(""),y(!1))}),()=>{U=!0}},[d]);const q=w.useCallback(async()=>{if(!(!d||k)){E(!0);try{await se.writeFile(d,h),b(h),j(!1),B(!0),setTimeout(()=>B(!1),2e3)}catch{}E(!1)}},[d,h,k]),R=w.useCallback(()=>{m(g),j(!1)},[g]),M=w.useCallback(U=>{S&&!globalThis.confirm("Discard unsaved changes?")||(f(U),globalThis.innerWidth<640&&I(!1))},[S]),O=A.toLowerCase();if(!a)return r.jsx("div",{className:"flex-1 flex items-center justify-center h-full",children:r.jsx("p",{className:"text-cc-muted text-sm",children:"Waiting for session to initialize..."})});const W=(d==null?void 0:d.split("/").pop())||"";return r.jsxs("div",{className:"h-full flex bg-cc-bg relative",children:[Z&&r.jsx("button",{className:"fixed inset-0 bg-black/30 z-20 sm:hidden cursor-default border-none",onClick:()=>I(!1),"aria-label":"Close file tree",tabIndex:-1}),r.jsxs("div",{className:`${Z?"w-[240px] translate-x-0":"w-0 -translate-x-full"} fixed sm:relative z-30 sm:z-auto shrink-0 h-full flex flex-col bg-cc-sidebar border-r border-cc-border transition-all duration-200 overflow-hidden`,children:[r.jsxs("div",{className:"w-[240px] shrink-0",children:[r.jsxs("div",{className:"px-3 py-2.5 border-b border-cc-border flex items-center gap-2",children:[r.jsx("span",{className:"text-[11px] font-semibold text-cc-fg uppercase tracking-wider flex-1",children:"Files"}),r.jsx("button",{onClick:()=>X(U=>!U),title:K?"Hide dotfiles":"Show dotfiles",className:`w-5 h-5 flex items-center justify-center rounded text-[10px] cursor-pointer transition-colors ${K?"text-cc-primary bg-cc-primary/10":"text-cc-muted/40 hover:text-cc-muted"}`,children:".*"}),r.jsx("button",{onClick:()=>F(a),title:"Refresh",className:"w-5 h-5 flex items-center justify-center rounded text-cc-muted/50 hover:text-cc-muted cursor-pointer",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3","aria-hidden":!0,children:r.jsx("path",{d:"M1.705 8.005a.75.75 0 01.834.656 5.5 5.5 0 009.592 2.97l-1.204-1.204a.25.25 0 01.177-.427h3.646a.25.25 0 01.25.25v3.646a.25.25 0 01-.427.177l-1.38-1.38A7.002 7.002 0 011.05 8.84a.75.75 0 01.656-.834zM8 2.5a5.487 5.487 0 00-4.131 1.869l1.204 1.204A.25.25 0 014.896 6H1.25A.25.25 0 011 5.75V2.104a.25.25 0 01.427-.177l1.38 1.38A7.002 7.002 0 0114.95 7.16a.75.75 0 11-1.49.178A5.5 5.5 0 008 2.5z"})})})]}),r.jsx("div",{className:"px-3 py-2 border-b border-cc-border",children:r.jsx("input",{value:A,onChange:U=>P(U.target.value),placeholder:"Filter files...",className:"w-full h-7 px-2 rounded-md border border-cc-border bg-cc-input-bg text-[11px] text-cc-fg placeholder:text-cc-muted/30 focus:outline-none focus:ring-1 focus:ring-cc-primary/30"})})]}),r.jsx("div",{className:"flex-1 overflow-y-auto overflow-x-hidden py-1 w-[240px]",children:r.jsx(RC,{parentPath:a,tree:l,filter:O,changedFiles:H,selectedFile:d,onToggleDir:G,onSelectFile:M,depth:0})})]}),r.jsxs("div",{className:"flex-1 min-w-0 h-full flex flex-col",children:[d&&r.jsxs("div",{className:"shrink-0 flex items-center gap-2 px-3 py-2.5 bg-cc-card border-b border-cc-border",children:[!Z&&r.jsx("button",{onClick:()=>I(!0),className:"w-6 h-6 flex items-center justify-center rounded-md text-cc-muted hover:text-cc-fg hover:bg-cc-hover cursor-pointer shrink-0",title:"Show file tree",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5","aria-hidden":!0,children:r.jsx("path",{d:"M1 3.5A1.5 1.5 0 012.5 2h3.379a1.5 1.5 0 011.06.44l.622.621a.5.5 0 00.353.146H13.5A1.5 1.5 0 0115 4.707V12.5a1.5 1.5 0 01-1.5 1.5h-11A1.5 1.5 0 011 12.5v-9z"})})}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("span",{className:"text-[13px] font-medium text-cc-fg truncate block",children:W}),r.jsx("span",{className:"text-[10px] text-cc-muted font-mono-code truncate block",children:d.replace(a+"/","")})]}),!Tx(d)&&r.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[S&&!N&&r.jsx("span",{className:"text-[10px] text-cc-warning",children:"Unsaved"}),N&&r.jsx("span",{className:"text-[10px] text-cc-success",children:"Saved"}),S&&r.jsx("button",{onClick:R,className:"px-3 py-1 rounded-md text-[11px] font-medium text-cc-muted hover:text-cc-fg hover:bg-cc-hover cursor-pointer transition-colors",children:"Cancel"}),r.jsx("button",{onClick:q,disabled:k||!S,className:"px-3 py-1 rounded-md bg-cc-primary text-white text-[11px] font-medium hover:bg-cc-primary-hover cursor-pointer disabled:opacity-40 transition-colors",children:k?"Saving...":"Save"})]})]}),r.jsx("div",{className:"flex-1 overflow-auto",children:r.jsx(Jz,{selectedFile:d,selectedName:W,fileLoading:v,fileContent:h,onContentChange:U=>{m(U),j(!0)}})})]})]})}function Jz({selectedFile:e,selectedName:t,fileLoading:s,fileContent:n,onContentChange:a}){return e?s?r.jsx("div",{className:"h-full flex items-center justify-center",children:r.jsx("div",{className:"w-5 h-5 border-2 border-cc-primary border-t-transparent rounded-full animate-spin"})}):Tx(e)?r.jsx("div",{className:"h-full flex items-center justify-center p-8 bg-cc-bg",children:r.jsx("img",{src:`/api/fs/read-raw?path=${encodeURIComponent(e)}`,alt:t,className:"max-w-full max-h-full object-contain rounded-lg shadow-panel"})}):r.jsx(w.Suspense,{fallback:r.jsx("div",{className:"h-full flex items-center justify-center text-cc-muted text-[12px]",children:"Loading editor..."}),children:r.jsx(Kz,{value:n,onChange:a,language:av(e),height:"calc(100vh - 120px)",minimap:!0,lineNumbers:!0,wordWrap:!1,ariaLabel:`Editing ${t}`,className:"border-0 rounded-none"})}):r.jsxs("div",{className:"h-full flex flex-col items-center justify-center gap-3 select-none px-6",children:[r.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"w-8 h-8 text-cc-muted/40","aria-hidden":!0,children:[r.jsx("path",{d:"M13 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V9l-7-7z",strokeLinecap:"round",strokeLinejoin:"round"}),r.jsx("polyline",{points:"13 2 13 9 20 9",strokeLinecap:"round",strokeLinejoin:"round"})]}),r.jsx("p",{className:"text-sm text-cc-muted",children:"Select a file to view or edit"})]})}function RC({parentPath:e,tree:t,filter:s,changedFiles:n,selectedFile:a,onToggleDir:l,onSelectFile:c,depth:d}){const f=t.children.get(e);if(t.loading.has(e)&&!f)return r.jsx("div",{className:"px-3 py-1 text-[10px] text-cc-muted",style:{paddingLeft:12+d*16},children:"Loading..."});if(!f)return null;const m=s?f.filter(g=>g.name.toLowerCase().includes(s)):f;return r.jsx(r.Fragment,{children:m.map(g=>{const b=g.type==="directory",v=t.expanded.has(g.path),y=g.path===a,S=n.has(g.path);return b?r.jsxs("div",{children:[r.jsxs("button",{onClick:()=>l(g.path),className:"flex items-center gap-1.5 w-full px-2 py-1 text-[12px] text-cc-fg/80 hover:bg-cc-hover transition-colors cursor-pointer",style:{paddingLeft:8+d*16},children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:`w-3 h-3 text-cc-muted/50 shrink-0 transition-transform duration-150 ${v?"rotate-90":""}`,"aria-hidden":!0,children:r.jsx("path",{d:"M6 4l4 4-4 4V4z"})}),r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 text-cc-warning/60 shrink-0","aria-hidden":!0,children:r.jsx("path",{d:"M1 3.5A1.5 1.5 0 012.5 2h3.379a1.5 1.5 0 011.06.44l.622.621a.5.5 0 00.353.146H13.5A1.5 1.5 0 0115 4.707V12.5a1.5 1.5 0 01-1.5 1.5h-11A1.5 1.5 0 011 12.5v-9z"})}),r.jsx("span",{className:"truncate",children:g.name})]}),v&&r.jsx(RC,{parentPath:g.path,tree:t,filter:s,changedFiles:n,selectedFile:a,onToggleDir:l,onSelectFile:c,depth:d+1})]},g.path):r.jsxs("button",{onClick:()=>c(g.path),className:`flex items-center gap-1.5 w-full px-2 py-1 text-[12px] transition-colors cursor-pointer ${y?"bg-cc-active text-cc-fg":"text-cc-fg/70 hover:bg-cc-hover"}`,style:{paddingLeft:8+d*16+16},children:[S?r.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-cc-warning shrink-0",title:"Modified by agent"}):r.jsx("span",{className:"w-1.5 h-1.5 shrink-0"}),r.jsx("span",{className:`truncate ${S?"text-cc-warning":""}`,children:g.name})]},g.path)})})}function DC(){const e=Y(h=>h.updateInfo),t=Y(h=>h.updateDismissedVersion),s=Y(h=>h.dismissUpdate),n=Y(h=>h.setUpdateOverlayActive),[a,l]=w.useState(!1);if(!(e!=null&&e.updateAvailable)||!e.latestVersion||t===e.latestVersion)return null;const c=async()=>{l(!0);try{await se.triggerUpdate(),n(!0)}catch(h){console.error("Update failed:",h),l(!1)}},d=()=>{s(e.latestVersion)},f=a||e.updateInProgress;return r.jsxs("div",{className:"px-4 py-1.5 bg-cc-primary/10 border-b border-cc-primary/20 flex items-center justify-center gap-3 animate-[fadeSlideIn_0.2s_ease-out]",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 text-cc-primary shrink-0",children:r.jsx("path",{d:"M8 1a7 7 0 1 1 0 14A7 7 0 0 1 8 1zm0 2a.75.75 0 0 0-.75.75v3.69L5.78 6.15a.75.75 0 0 0-.96 1.15l2.5 2.08a.75.75 0 0 0 1.08-.12l2-2.5a.75.75 0 1 0-1.17-.94L8.75 6.5V3.75A.75.75 0 0 0 8 3z"})}),r.jsxs("span",{className:"text-xs text-cc-fg",children:[r.jsxs("span",{className:"font-medium",children:["v",e.latestVersion]})," available",r.jsxs("span",{className:"text-cc-muted ml-1",children:["(current: v",e.currentVersion,")"]})]}),e.isServiceMode?r.jsx("button",{onClick:c,disabled:f,className:"text-xs font-medium px-2.5 py-0.5 rounded-md bg-cc-primary hover:bg-cc-primary-hover text-white transition-colors cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed",children:f?"Updating...":"Update & Restart"}):r.jsxs("span",{className:"text-xs text-cc-muted",children:["Run"," ",r.jsx("code",{className:"font-mono-code bg-cc-code-bg px-1 py-0.5 rounded text-cc-code-fg",children:"the-campfire install"})," ","for auto-updates"]}),r.jsx("button",{onClick:d,className:"text-cc-muted hover:text-cc-fg transition-colors cursor-pointer ml-auto",title:"Dismiss",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"w-3 h-3",children:r.jsx("path",{d:"M4 4l8 8M12 4l-8 8"})})})]})}function Qz(e){if(e<6e4)return`${Math.round(e/1e3)}s`;const t=Math.floor(e/6e4);if(t<60)return`${t}m`;const s=Math.floor(t/60),n=t%60;return n>0?`${s}h ${n}m`:`${s}h`}function Zz(e){return e===0?"$0":e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}function eP(e){const t=Date.now()-e,s=Math.floor(t/6e4);if(s<1)return"just now";if(s<60)return`${s}m ago`;const n=Math.floor(s/60);return n<24?`${n}h ago`:`${Math.floor(n/24)}d ago`}const tP={claude:"text-[#5BA8A0] bg-[#5BA8A0]/10 border-[#5BA8A0]/20",codex:"text-blue-500 bg-blue-500/10 border-blue-500/20",goose:"text-amber-600 bg-amber-500/10 border-amber-500/20",aider:"text-purple-500 bg-purple-500/10 border-purple-500/20",openhands:"text-rose-500 bg-rose-500/10 border-rose-500/20",openclaw:"text-orange-500 bg-orange-500/10 border-orange-500/20"};function oh({entry:e,onVote:t,onDelete:s,onFeature:n,onExportClawHub:a,clawHubAvailable:l,onPostMoltbook:c,moltbookAvailable:d,onCreatePublicLink:f}){const[h,m]=w.useState(null),[g,b]=w.useState(!1);async function v(S){if(!h){m(S);try{t(e.id,S)}finally{m(null)}}}const y=tP[e.backendType]||"text-cc-fg/60 bg-cc-hover border-cc-border/40";return r.jsxs("div",{className:"rounded-xl border border-cc-border/60 bg-cc-card hover:border-cc-border transition-all duration-200 overflow-hidden group",children:[r.jsx("div",{className:"px-5 py-4",children:r.jsxs("div",{className:"flex items-start gap-4",children:[r.jsxs("div",{className:"flex flex-col items-center gap-0.5 pt-0.5 shrink-0",children:[r.jsx("button",{onClick:()=>v(1),disabled:h!==null,className:"w-7 h-6 flex items-center justify-center rounded-md text-cc-fg/35 hover:text-cc-primary hover:bg-cc-primary/5 transition-colors cursor-pointer disabled:opacity-50",title:"Upvote","aria-label":"Upvote",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-4 h-4",children:r.jsx("path",{d:"M8 4l4 5H4l4-5z"})})}),r.jsx("span",{className:`text-[13px] font-bold tabular-nums leading-none ${e.votes>0?"text-cc-primary":e.votes<0?"text-cc-error":"text-cc-fg/40"}`,children:e.votes}),r.jsx("button",{onClick:()=>v(-1),disabled:h!==null,className:"w-7 h-6 flex items-center justify-center rounded-md text-cc-fg/35 hover:text-cc-error hover:bg-cc-error/5 transition-colors cursor-pointer disabled:opacity-50",title:"Downvote","aria-label":"Downvote",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-4 h-4",children:r.jsx("path",{d:"M8 12l4-5H4l4 5z"})})})]}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[e.featured&&r.jsx("span",{className:"text-amber-500 shrink-0",title:"Featured",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-4 h-4",children:r.jsx("path",{d:"M8 1.5l2.09 4.26 4.66.68-3.38 3.28.8 4.64L8 12.17l-4.17 2.19.8-4.64-3.38-3.28 4.66-.68L8 1.5z"})})}),r.jsx("h3",{className:"text-[14px] font-semibold text-cc-fg truncate",children:e.name}),r.jsx("span",{className:"text-[11px] text-cc-fg/40 shrink-0 ml-auto",children:eP(e.createdAt)})]}),e.description&&r.jsx("p",{className:"mt-1 text-[12px] text-cc-fg/55 line-clamp-2 leading-relaxed",children:e.description}),r.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mt-3",children:[r.jsx("span",{className:`text-[10px] font-semibold px-2 py-0.5 rounded-full border ${y}`,children:e.backendType}),e.model&&r.jsx("span",{className:"text-[10px] font-medium px-2 py-0.5 rounded-full bg-cc-hover/70 text-cc-fg/55 border border-cc-border/30 truncate max-w-[140px]",children:e.model}),e.totalCostUsd>0&&r.jsx("span",{className:"text-[10px] font-medium px-2 py-0.5 rounded-full bg-cc-hover/70 text-cc-fg/55 border border-cc-border/30",children:Zz(e.totalCostUsd)}),e.numTurns>0&&r.jsxs("span",{className:"text-[10px] font-medium px-2 py-0.5 rounded-full bg-cc-hover/70 text-cc-fg/55 border border-cc-border/30",children:[e.numTurns," turns"]}),e.durationMs>0&&r.jsx("span",{className:"text-[10px] font-medium px-2 py-0.5 rounded-full bg-cc-hover/70 text-cc-fg/55 border border-cc-border/30",children:Qz(e.durationMs)}),(e.totalLinesAdded>0||e.totalLinesRemoved>0)&&r.jsxs("span",{className:"text-[10px] font-medium px-2 py-0.5 rounded-full bg-cc-hover/70 border border-cc-border/30",children:[r.jsxs("span",{className:"text-green-500",children:["+",e.totalLinesAdded]}),r.jsx("span",{className:"text-cc-fg/30 mx-0.5",children:"/"}),r.jsxs("span",{className:"text-red-500",children:["-",e.totalLinesRemoved]})]})]}),e.tags.length>0&&r.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2.5",children:e.tags.map(S=>r.jsxs("span",{className:"text-[10px] font-medium px-2 py-0.5 rounded-full bg-cc-primary/5 text-cc-primary/70 border border-cc-primary/10",children:["#",S]},S))})]})]})}),r.jsxs("div",{className:"flex items-center justify-between px-5 py-2.5 border-t border-cc-border/30 bg-cc-bg/50",children:[r.jsxs("a",{href:`#/replay/session/${e.sessionId}`,className:"inline-flex items-center gap-1.5 text-[11px] font-medium text-cc-primary hover:text-cc-primary-hover transition-colors",title:"Watch replay",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:r.jsx("path",{d:"M4.5 3.5A.5.5 0 015.22 3l7 4.5a.5.5 0 010 .86l-7 4.5A.5.5 0 014.5 12.5v-9z"})}),"Watch Replay"]}),r.jsxs("div",{className:"flex items-center gap-0.5",children:[n&&r.jsx("button",{onClick:()=>n(e.id),className:`w-7 h-7 flex items-center justify-center rounded-lg transition-colors cursor-pointer ${e.featured?"text-amber-500 bg-amber-500/10":"text-cc-fg/30 hover:text-amber-500 hover:bg-amber-500/5"}`,title:e.featured?"Unfeature":"Feature","aria-label":e.featured?"Unfeature":"Feature",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:r.jsx("path",{d:"M8 1.5l2.09 4.26 4.66.68-3.38 3.28.8 4.64L8 12.17l-4.17 2.19.8-4.64-3.38-3.28 4.66-.68L8 1.5z"})})}),a&&l&&r.jsx("button",{onClick:()=>a(e.id),className:"w-7 h-7 flex items-center justify-center rounded-lg text-cc-fg/30 hover:text-orange-500 hover:bg-orange-500/5 transition-colors cursor-pointer",title:"Export to ClawHub","aria-label":"Export to ClawHub",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"w-3.5 h-3.5",children:r.jsx("path",{d:"M7 1h8v8M15 1L8 8M6 3H2v11h11v-4",strokeLinecap:"round",strokeLinejoin:"round"})})}),c&&d&&r.jsx("button",{onClick:()=>c(e.id),className:"w-7 h-7 flex items-center justify-center rounded-lg text-cc-fg/30 hover:text-violet-500 hover:bg-violet-500/5 transition-colors cursor-pointer",title:"Post to Moltbook","aria-label":"Post to Moltbook",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:r.jsx("path",{d:"M8 0a8 8 0 110 16A8 8 0 018 0zm0 2a1.5 1.5 0 00-1.5 1.5v3.793l-1.146-1.147a1.5 1.5 0 00-2.122 2.122l3.5 3.5a1.5 1.5 0 002.122 0l3.5-3.5a1.5 1.5 0 00-2.122-2.122L9.5 7.293V3.5A1.5 1.5 0 008 2z"})})}),f&&r.jsx("button",{onClick:()=>f(e.id),className:"w-7 h-7 flex items-center justify-center rounded-lg text-cc-fg/30 hover:text-cc-primary hover:bg-cc-primary/5 transition-colors cursor-pointer",title:"Copy public link","aria-label":"Copy public replay link",children:r.jsxs("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:[r.jsx("path",{d:"M4.715 6.542L3.343 7.914a3 3 0 104.243 4.243l1.828-1.829A3 3 0 008.586 5.5L8 6.086a1.002 1.002 0 00-.154.199 2 2 0 01.861 3.337L6.88 11.45a2 2 0 11-2.83-2.83l.793-.792a4.018 4.018 0 01-.128-1.287z"}),r.jsx("path",{d:"M11.285 9.458l1.372-1.372a3 3 0 10-4.243-4.243L6.586 5.672A3 3 0 007.414 10.5l.586-.586a1.002 1.002 0 00.154-.199 2 2 0 01-.861-3.337L9.12 4.55a2 2 0 112.83 2.83l-.793.792c.112.42.155.855.128 1.287z"})]})}),s&&!g&&r.jsx("button",{onClick:()=>b(!0),className:"w-7 h-7 flex items-center justify-center rounded-lg text-cc-fg/30 hover:text-cc-error hover:bg-cc-error/5 transition-colors cursor-pointer",title:"Delete","aria-label":"Delete",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"w-3.5 h-3.5",children:r.jsx("path",{d:"M3 4h10M5.5 4V2.5h5V4M6 6.5v5M10 6.5v5M4.5 4l.5 9.5h6l.5-9.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),s&&g&&r.jsxs("div",{className:"flex items-center gap-1 ml-1",children:[r.jsx("button",{onClick:()=>b(!1),className:"px-2 py-1 rounded-md text-[10px] font-medium text-cc-fg/50 hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:"Cancel"}),r.jsx("button",{onClick:()=>{s(e.id),b(!1)},className:"px-2 py-1 rounded-md text-[10px] font-medium bg-cc-error text-white hover:bg-cc-error/90 transition-colors cursor-pointer",children:"Delete"})]})]})]})]})}const Ys="playground-session",Wd=[{id:"mem-1",kind:"knowledge",namespace:"repo:a1b2c3d4",tag:"rate-limiting",summary:"API routes use the Hono middleware stack; rate limiting belongs in web/server/routes.ts before auth checks.",weight:.92},{id:"mem-2",kind:"knowledge",namespace:"global",tag:"testing",summary:"All new backend code must include colocated Vitest tests (routes.test.ts next to routes.ts).",weight:.78},{id:"mem-3",kind:"fragment",namespace:"repo:a1b2c3d4",summary:"Decided to use token-bucket over sliding-window because the session store already tracks per-session timestamps.",weight:.55},{id:"mem-4",kind:"fragment",namespace:"agent:claude",summary:"Claude Code sessions reconnect with --resume; middleware must tolerate duplicate session init.",weight:.31}];function bn(e){return{request_id:`perm-${Math.random().toString(36).slice(2,8)}`,tool_use_id:`tu-${Math.random().toString(36).slice(2,8)}`,timestamp:Date.now(),...e}}const Z5=bn({tool_name:"Bash",input:{command:"git log --oneline -20 && npm run build",description:"View recent commits and build the project"},permission_suggestions:[{type:"addRules",rules:[{toolName:"Bash",ruleContent:"git log --oneline -20 && npm run build"}],behavior:"allow",destination:"session"},{type:"addRules",rules:[{toolName:"Bash",ruleContent:"git log --oneline -20 && npm run build"}],behavior:"allow",destination:"projectSettings"}]}),sP=bn({tool_name:"Edit",input:{file_path:"/Users/stan/Dev/project/src/utils/format.ts",old_string:`export function formatDate(d: Date) {
|
|
128
|
+
`,children:[r.jsxs("div",{className:"w-[220px] px-4 py-3 text-[11px] font-semibold text-cc-fg uppercase tracking-wider border-b border-cc-border shrink-0 flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"w-2 h-2 rounded-full bg-cc-warning"}),r.jsxs("span",{children:["Changed (",G.length,")"]})]}),r.jsx("button",{onClick:()=>H(!1),className:"w-5 h-5 flex items-center justify-center rounded-md text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer sm:hidden",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"w-3 h-3",children:r.jsx("path",{d:"M4 4l8 8M12 4l-8 8",strokeLinecap:"round"})})})]}),r.jsx("div",{className:"flex-1 overflow-y-auto overflow-x-hidden py-1",children:G.map(({abs:W,rel:U})=>r.jsxs("button",{onClick:()=>R(W),className:`flex items-center gap-2 w-full mx-1 px-2 py-1.5 text-[13px] rounded-lg hover:bg-cc-hover transition-colors cursor-pointer whitespace-nowrap ${W===n?"bg-cc-active text-cc-fg":"text-cc-fg/70"}`,style:{width:"calc(100% - 8px)"},children:[r.jsx("svg",{viewBox:"0 0 20 20",fill:"currentColor",className:"w-3.5 h-3.5 text-cc-warning shrink-0",children:r.jsx("path",{fillRule:"evenodd",d:"M4 4a2 2 0 012-2h4.586A2 2 0 0112 2.586L15.414 6A2 2 0 0116 7.414V16a2 2 0 01-2 2H6a2 2 0 01-2-2V4z",clipRule:"evenodd"})}),r.jsx("span",{className:"truncate leading-snug",children:U})]},W))})]}),r.jsxs("div",{className:"flex-1 min-w-0 h-full flex flex-col",children:[n&&r.jsxs("div",{className:"shrink-0 flex items-center gap-2 sm:gap-2.5 px-2 sm:px-4 py-2.5 bg-cc-card border-b border-cc-border",children:[!I&&r.jsx("button",{onClick:()=>H(!0),className:"flex items-center justify-center w-6 h-6 rounded-md text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer shrink-0",title:"Show file list",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:r.jsx("path",{d:"M1 3.5A1.5 1.5 0 012.5 2h3.379a1.5 1.5 0 011.06.44l.622.621a.5.5 0 00.353.146H13.5A1.5 1.5 0 0115 4.707V12.5a1.5 1.5 0 01-1.5 1.5h-11A1.5 1.5 0 011 12.5v-9z"})})}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("span",{className:"text-cc-fg text-[13px] font-medium truncate block",children:M==null?void 0:M.split("/").pop()}),r.jsx("span",{className:"text-cc-muted truncate text-[11px] hidden sm:block font-mono-code",children:M})]}),r.jsx("span",{className:"text-cc-muted text-[11px] shrink-0 hidden sm:inline",children:"Compared to session start"}),r.jsxs("div",{className:"ml-2 hidden sm:flex items-center gap-1 rounded-md bg-cc-bg border border-cc-border p-0.5 text-[11px]",children:[r.jsx("button",{onClick:()=>S("diff"),className:`px-2 py-0.5 rounded cursor-pointer transition-colors ${y==="diff"?"bg-cc-active text-cc-fg":"text-cc-muted hover:text-cc-fg"}`,children:"Diff"}),r.jsx("button",{onClick:()=>S("edit"),className:`px-2 py-0.5 rounded cursor-pointer transition-colors ${y==="edit"?"bg-cc-active text-cc-fg":"text-cc-muted hover:text-cc-fg"}`,children:"Edit"}),r.jsx("button",{onClick:()=>S("raw"),className:`px-2 py-0.5 rounded cursor-pointer transition-colors ${y==="raw"?"bg-cc-active text-cc-fg":"text-cc-muted hover:text-cc-fg"}`,children:"Raw"})]}),y==="edit"&&r.jsxs("div",{className:"ml-2 flex items-center gap-2",children:[r.jsx("button",{onClick:q,disabled:B||!X,className:"px-3 py-1 rounded-md bg-cc-primary text-white text-[11px] font-medium hover:bg-cc-primary-hover transition-colors cursor-pointer disabled:opacity-40",children:B?"Saving...":"Save"}),P&&r.jsx("span",{className:"text-[10px] text-cc-success",children:"Saved"}),X&&!P&&r.jsx("span",{className:"text-[10px] text-cc-warning",children:"Unsaved"})]})]}),r.jsx("div",{className:"flex-1 overflow-auto",children:m?r.jsx("div",{className:"h-full flex items-center justify-center",children:r.jsx("div",{className:"w-5 h-5 border-2 border-cc-primary border-t-transparent rounded-full animate-spin"})}):n&&y==="edit"?E?r.jsx("div",{className:"h-full flex items-center justify-center",children:r.jsx("div",{className:"w-5 h-5 border-2 border-cc-primary border-t-transparent rounded-full animate-spin"})}):r.jsx(w.Suspense,{fallback:r.jsx("div",{className:"h-full flex items-center justify-center text-cc-muted text-[12px]",children:"Loading editor..."}),children:r.jsx(qz,{value:j,onChange:W=>{k(W),Z(!0)},language:av(n),height:"calc(100vh - 120px)",minimap:!0,lineNumbers:!0,wordWrap:!1,ariaLabel:`Editing ${M||n}`,className:"border-0 rounded-none"})}):n?r.jsx("div",{className:"p-4",children:!b&&!f.trim()?r.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-12",children:[r.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"w-8 h-8 text-cc-muted",children:r.jsx("path",{d:"M12 9v4m0 4h.01M5.07 19h13.86c1.05 0 1.7-1.14 1.18-2.06l-6.93-12a1.33 1.33 0 00-2.36 0l-6.93 12c-.52.92.13 2.06 1.18 2.06z",strokeLinecap:"round",strokeLinejoin:"round"})}),r.jsx("p",{className:"text-cc-muted text-sm",children:"File not found on disk"}),r.jsx("p",{className:"text-cc-muted text-xs",children:"The file may have been deleted or the write was not executed."})]}):y==="raw"?O?r.jsx("div",{className:"markdown-body text-[12px] text-cc-fg leading-[1.7]",children:r.jsx(Y0,{remarkPlugins:[Z0],children:O})}):r.jsx("p",{className:"text-cc-muted text-sm",children:"No diff content returned."}):r.jsx(yr,{unifiedDiff:f,fileName:M||void 0,mode:"full"})}):r.jsxs("div",{className:"h-full flex flex-col items-center justify-center",children:[!I&&r.jsxs("button",{onClick:()=>H(!0),className:"mb-4 flex items-center gap-2 px-3 py-2 rounded-lg text-xs text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:r.jsx("path",{d:"M1 3.5A1.5 1.5 0 012.5 2h3.379a1.5 1.5 0 011.06.44l.622.621a.5.5 0 00.353.146H13.5A1.5 1.5 0 0115 4.707V12.5a1.5 1.5 0 01-1.5 1.5h-11A1.5 1.5 0 011 12.5v-9z"})}),"Show file list"]}),r.jsx("p",{className:"text-cc-muted text-sm",children:"Select a file to view changes"})]})})]})]}):r.jsx("div",{className:"flex-1 flex items-center justify-center h-full",children:r.jsx("p",{className:"text-cc-muted text-sm",children:"Waiting for session to initialize..."})})}const Kz=w.lazy(()=>Xi(()=>Promise.resolve().then(()=>fu),void 0).then(e=>({default:e.CodeEditor}))),Yz=new Set(["png","jpg","jpeg","gif","svg","webp","ico","bmp"]);function Tx(e){var s;const t=((s=e.split(".").pop())==null?void 0:s.toLowerCase())||"";return Yz.has(t)}function Xz({sessionId:e}){const t=Y(U=>U.sessions.get(e)),s=Y(U=>U.sdkSessions.find(D=>D.sessionId===e)),n=Y(U=>U.changedFiles.get(e)),a=(t==null?void 0:t.cwd)||(s==null?void 0:s.cwd)||"",[l,c]=w.useState({expanded:new Set,children:new Map,loading:new Set}),[d,f]=w.useState(null),[h,m]=w.useState(""),[g,b]=w.useState(""),[v,y]=w.useState(!1),[S,j]=w.useState(!1),[k,E]=w.useState(!1),[N,B]=w.useState(!1),[A,P]=w.useState(""),[K,X]=w.useState(!1),[Z,I]=w.useState(!0),H=w.useMemo(()=>n??new Set,[n]);w.useEffect(()=>{a&&F(a)},[a,K]);function F(U){c(D=>{const $=new Set(D.loading);return $.add(U),{...D,loading:$}}),se.listEntries(U,K).then(D=>{const $=[...D.entries].sort((z,T)=>z.type!==T.type?z.type==="directory"?-1:1:z.name.localeCompare(T.name));c(z=>{const T=new Map(z.children);T.set(U,$);const ae=new Set(z.loading);return ae.delete(U),{...z,children:T,loading:ae}})}).catch(()=>{c(D=>{const $=new Set(D.loading);return $.delete(U),{...D,loading:$}})})}function G(U){c(D=>{const $=new Set(D.expanded);return $.has(U)?$.delete(U):($.add(U),D.children.has(U)||F(U)),{...D,expanded:$}})}w.useEffect(()=>{if(!d||Tx(d))return;let U=!1;return y(!0),j(!1),B(!1),se.readFile(d).then(D=>{U||(m(D.content),b(D.content),y(!1))}).catch(()=>{U||(m(""),b(""),y(!1))}),()=>{U=!0}},[d]);const q=w.useCallback(async()=>{if(!(!d||k)){E(!0);try{await se.writeFile(d,h),b(h),j(!1),B(!0),setTimeout(()=>B(!1),2e3)}catch{}E(!1)}},[d,h,k]),R=w.useCallback(()=>{m(g),j(!1)},[g]),M=w.useCallback(U=>{S&&!globalThis.confirm("Discard unsaved changes?")||(f(U),globalThis.innerWidth<640&&I(!1))},[S]),O=A.toLowerCase();if(!a)return r.jsx("div",{className:"flex-1 flex items-center justify-center h-full",children:r.jsx("p",{className:"text-cc-muted text-sm",children:"Waiting for session to initialize..."})});const W=(d==null?void 0:d.split("/").pop())||"";return r.jsxs("div",{className:"h-full flex bg-cc-bg relative",children:[Z&&r.jsx("button",{className:"fixed inset-0 bg-black/30 z-20 sm:hidden cursor-default border-none",onClick:()=>I(!1),"aria-label":"Close file tree",tabIndex:-1}),r.jsxs("div",{className:`${Z?"w-[240px] translate-x-0":"w-0 -translate-x-full"} fixed sm:relative z-30 sm:z-auto shrink-0 h-full flex flex-col bg-cc-sidebar border-r border-cc-border transition-all duration-200 overflow-hidden`,children:[r.jsxs("div",{className:"w-[240px] shrink-0",children:[r.jsxs("div",{className:"px-3 py-2.5 border-b border-cc-border flex items-center gap-2",children:[r.jsx("span",{className:"text-[11px] font-semibold text-cc-fg uppercase tracking-wider flex-1",children:"Files"}),r.jsx("button",{onClick:()=>X(U=>!U),title:K?"Hide dotfiles":"Show dotfiles",className:`w-5 h-5 flex items-center justify-center rounded text-[10px] cursor-pointer transition-colors ${K?"text-cc-primary bg-cc-primary/10":"text-cc-muted/40 hover:text-cc-muted"}`,children:".*"}),r.jsx("button",{onClick:()=>F(a),title:"Refresh",className:"w-5 h-5 flex items-center justify-center rounded text-cc-muted/50 hover:text-cc-muted cursor-pointer",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3","aria-hidden":!0,children:r.jsx("path",{d:"M1.705 8.005a.75.75 0 01.834.656 5.5 5.5 0 009.592 2.97l-1.204-1.204a.25.25 0 01.177-.427h3.646a.25.25 0 01.25.25v3.646a.25.25 0 01-.427.177l-1.38-1.38A7.002 7.002 0 011.05 8.84a.75.75 0 01.656-.834zM8 2.5a5.487 5.487 0 00-4.131 1.869l1.204 1.204A.25.25 0 014.896 6H1.25A.25.25 0 011 5.75V2.104a.25.25 0 01.427-.177l1.38 1.38A7.002 7.002 0 0114.95 7.16a.75.75 0 11-1.49.178A5.5 5.5 0 008 2.5z"})})})]}),r.jsx("div",{className:"px-3 py-2 border-b border-cc-border",children:r.jsx("input",{value:A,onChange:U=>P(U.target.value),placeholder:"Filter files...",className:"w-full h-7 px-2 rounded-md border border-cc-border bg-cc-input-bg text-[11px] text-cc-fg placeholder:text-cc-muted/30 focus:outline-none focus:ring-1 focus:ring-cc-primary/30"})})]}),r.jsx("div",{className:"flex-1 overflow-y-auto overflow-x-hidden py-1 w-[240px]",children:r.jsx(RC,{parentPath:a,tree:l,filter:O,changedFiles:H,selectedFile:d,onToggleDir:G,onSelectFile:M,depth:0})})]}),r.jsxs("div",{className:"flex-1 min-w-0 h-full flex flex-col",children:[d&&r.jsxs("div",{className:"shrink-0 flex items-center gap-2 px-3 py-2.5 bg-cc-card border-b border-cc-border",children:[!Z&&r.jsx("button",{onClick:()=>I(!0),className:"w-6 h-6 flex items-center justify-center rounded-md text-cc-muted hover:text-cc-fg hover:bg-cc-hover cursor-pointer shrink-0",title:"Show file tree",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5","aria-hidden":!0,children:r.jsx("path",{d:"M1 3.5A1.5 1.5 0 012.5 2h3.379a1.5 1.5 0 011.06.44l.622.621a.5.5 0 00.353.146H13.5A1.5 1.5 0 0115 4.707V12.5a1.5 1.5 0 01-1.5 1.5h-11A1.5 1.5 0 011 12.5v-9z"})})}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("span",{className:"text-[13px] font-medium text-cc-fg truncate block",children:W}),r.jsx("span",{className:"text-[10px] text-cc-muted font-mono-code truncate block",children:d.replace(a+"/","")})]}),!Tx(d)&&r.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[S&&!N&&r.jsx("span",{className:"text-[10px] text-cc-warning",children:"Unsaved"}),N&&r.jsx("span",{className:"text-[10px] text-cc-success",children:"Saved"}),S&&r.jsx("button",{onClick:R,className:"px-3 py-1 rounded-md text-[11px] font-medium text-cc-muted hover:text-cc-fg hover:bg-cc-hover cursor-pointer transition-colors",children:"Cancel"}),r.jsx("button",{onClick:q,disabled:k||!S,className:"px-3 py-1 rounded-md bg-cc-primary text-white text-[11px] font-medium hover:bg-cc-primary-hover cursor-pointer disabled:opacity-40 transition-colors",children:k?"Saving...":"Save"})]})]}),r.jsx("div",{className:"flex-1 overflow-auto",children:r.jsx(Jz,{selectedFile:d,selectedName:W,fileLoading:v,fileContent:h,onContentChange:U=>{m(U),j(!0)}})})]})]})}function Jz({selectedFile:e,selectedName:t,fileLoading:s,fileContent:n,onContentChange:a}){return e?s?r.jsx("div",{className:"h-full flex items-center justify-center",children:r.jsx("div",{className:"w-5 h-5 border-2 border-cc-primary border-t-transparent rounded-full animate-spin"})}):Tx(e)?r.jsx("div",{className:"h-full flex items-center justify-center p-8 bg-cc-bg",children:r.jsx("img",{src:`/api/fs/read-raw?path=${encodeURIComponent(e)}`,alt:t,className:"max-w-full max-h-full object-contain rounded-lg shadow-panel"})}):r.jsx(w.Suspense,{fallback:r.jsx("div",{className:"h-full flex items-center justify-center text-cc-muted text-[12px]",children:"Loading editor..."}),children:r.jsx(Kz,{value:n,onChange:a,language:av(e),height:"calc(100vh - 120px)",minimap:!0,lineNumbers:!0,wordWrap:!1,ariaLabel:`Editing ${t}`,className:"border-0 rounded-none"})}):r.jsxs("div",{className:"h-full flex flex-col items-center justify-center gap-3 select-none px-6",children:[r.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"w-8 h-8 text-cc-muted/40","aria-hidden":!0,children:[r.jsx("path",{d:"M13 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V9l-7-7z",strokeLinecap:"round",strokeLinejoin:"round"}),r.jsx("polyline",{points:"13 2 13 9 20 9",strokeLinecap:"round",strokeLinejoin:"round"})]}),r.jsx("p",{className:"text-sm text-cc-muted",children:"Select a file to view or edit"})]})}function RC({parentPath:e,tree:t,filter:s,changedFiles:n,selectedFile:a,onToggleDir:l,onSelectFile:c,depth:d}){const f=t.children.get(e);if(t.loading.has(e)&&!f)return r.jsx("div",{className:"px-3 py-1 text-[10px] text-cc-muted",style:{paddingLeft:12+d*16},children:"Loading..."});if(!f)return null;const m=s?f.filter(g=>g.name.toLowerCase().includes(s)):f;return r.jsx(r.Fragment,{children:m.map(g=>{const b=g.type==="directory",v=t.expanded.has(g.path),y=g.path===a,S=n.has(g.path);return b?r.jsxs("div",{children:[r.jsxs("button",{onClick:()=>l(g.path),className:"flex items-center gap-1.5 w-full px-2 py-1 text-[12px] text-cc-fg/80 hover:bg-cc-hover transition-colors cursor-pointer",style:{paddingLeft:8+d*16},children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:`w-3 h-3 text-cc-muted/50 shrink-0 transition-transform duration-150 ${v?"rotate-90":""}`,"aria-hidden":!0,children:r.jsx("path",{d:"M6 4l4 4-4 4V4z"})}),r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 text-cc-warning/60 shrink-0","aria-hidden":!0,children:r.jsx("path",{d:"M1 3.5A1.5 1.5 0 012.5 2h3.379a1.5 1.5 0 011.06.44l.622.621a.5.5 0 00.353.146H13.5A1.5 1.5 0 0115 4.707V12.5a1.5 1.5 0 01-1.5 1.5h-11A1.5 1.5 0 011 12.5v-9z"})}),r.jsx("span",{className:"truncate",children:g.name})]}),v&&r.jsx(RC,{parentPath:g.path,tree:t,filter:s,changedFiles:n,selectedFile:a,onToggleDir:l,onSelectFile:c,depth:d+1})]},g.path):r.jsxs("button",{onClick:()=>c(g.path),className:`flex items-center gap-1.5 w-full px-2 py-1 text-[12px] transition-colors cursor-pointer ${y?"bg-cc-active text-cc-fg":"text-cc-fg/70 hover:bg-cc-hover"}`,style:{paddingLeft:8+d*16+16},children:[S?r.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-cc-warning shrink-0",title:"Modified by agent"}):r.jsx("span",{className:"w-1.5 h-1.5 shrink-0"}),r.jsx("span",{className:`truncate ${S?"text-cc-warning":""}`,children:g.name})]},g.path)})})}function Qz(){var e;return!!((e=window.campfireDesktop)!=null&&e.isDesktop)}function DC(){const e=Y(h=>h.updateInfo),t=Y(h=>h.updateDismissedVersion),s=Y(h=>h.dismissUpdate),n=Y(h=>h.setUpdateOverlayActive),[a,l]=w.useState(!1);if(!(e!=null&&e.updateAvailable)||!e.latestVersion||t===e.latestVersion)return null;const c=async()=>{l(!0);try{await se.triggerUpdate(),n(!0)}catch(h){console.error("Update failed:",h),l(!1)}},d=()=>{s(e.latestVersion)},f=a||e.updateInProgress;return r.jsxs("div",{className:"px-4 py-1.5 bg-cc-primary/10 border-b border-cc-primary/20 flex items-center justify-center gap-3 animate-[fadeSlideIn_0.2s_ease-out]",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 text-cc-primary shrink-0",children:r.jsx("path",{d:"M8 1a7 7 0 1 1 0 14A7 7 0 0 1 8 1zm0 2a.75.75 0 0 0-.75.75v3.69L5.78 6.15a.75.75 0 0 0-.96 1.15l2.5 2.08a.75.75 0 0 0 1.08-.12l2-2.5a.75.75 0 1 0-1.17-.94L8.75 6.5V3.75A.75.75 0 0 0 8 3z"})}),r.jsxs("span",{className:"text-xs text-cc-fg",children:[r.jsxs("span",{className:"font-medium",children:["v",e.latestVersion]})," available",r.jsxs("span",{className:"text-cc-muted ml-1",children:["(current: v",e.currentVersion,")"]})]}),Qz()?r.jsx("a",{href:"https://github.com/stretchcloud/campfire/releases/latest",target:"_blank",rel:"noreferrer",className:"text-xs font-medium px-2.5 py-0.5 rounded-md bg-cc-primary hover:bg-cc-primary-hover text-white transition-colors",children:"Download update"}):e.isServiceMode?r.jsx("button",{onClick:c,disabled:f,className:"text-xs font-medium px-2.5 py-0.5 rounded-md bg-cc-primary hover:bg-cc-primary-hover text-white transition-colors cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed",children:f?"Updating...":"Update & Restart"}):r.jsxs("span",{className:"text-xs text-cc-muted",children:["Run"," ",r.jsx("code",{className:"font-mono-code bg-cc-code-bg px-1 py-0.5 rounded text-cc-code-fg",children:"the-campfire install"})," ","for auto-updates"]}),r.jsx("button",{onClick:d,className:"text-cc-muted hover:text-cc-fg transition-colors cursor-pointer ml-auto",title:"Dismiss",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"w-3 h-3",children:r.jsx("path",{d:"M4 4l8 8M12 4l-8 8"})})})]})}function Zz(e){if(e<6e4)return`${Math.round(e/1e3)}s`;const t=Math.floor(e/6e4);if(t<60)return`${t}m`;const s=Math.floor(t/60),n=t%60;return n>0?`${s}h ${n}m`:`${s}h`}function eP(e){return e===0?"$0":e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}function tP(e){const t=Date.now()-e,s=Math.floor(t/6e4);if(s<1)return"just now";if(s<60)return`${s}m ago`;const n=Math.floor(s/60);return n<24?`${n}h ago`:`${Math.floor(n/24)}d ago`}const sP={claude:"text-[#5BA8A0] bg-[#5BA8A0]/10 border-[#5BA8A0]/20",codex:"text-blue-500 bg-blue-500/10 border-blue-500/20",goose:"text-amber-600 bg-amber-500/10 border-amber-500/20",aider:"text-purple-500 bg-purple-500/10 border-purple-500/20",openhands:"text-rose-500 bg-rose-500/10 border-rose-500/20",openclaw:"text-orange-500 bg-orange-500/10 border-orange-500/20"};function oh({entry:e,onVote:t,onDelete:s,onFeature:n,onExportClawHub:a,clawHubAvailable:l,onPostMoltbook:c,moltbookAvailable:d,onCreatePublicLink:f}){const[h,m]=w.useState(null),[g,b]=w.useState(!1);async function v(S){if(!h){m(S);try{t(e.id,S)}finally{m(null)}}}const y=sP[e.backendType]||"text-cc-fg/60 bg-cc-hover border-cc-border/40";return r.jsxs("div",{className:"rounded-xl border border-cc-border/60 bg-cc-card hover:border-cc-border transition-all duration-200 overflow-hidden group",children:[r.jsx("div",{className:"px-5 py-4",children:r.jsxs("div",{className:"flex items-start gap-4",children:[r.jsxs("div",{className:"flex flex-col items-center gap-0.5 pt-0.5 shrink-0",children:[r.jsx("button",{onClick:()=>v(1),disabled:h!==null,className:"w-7 h-6 flex items-center justify-center rounded-md text-cc-fg/35 hover:text-cc-primary hover:bg-cc-primary/5 transition-colors cursor-pointer disabled:opacity-50",title:"Upvote","aria-label":"Upvote",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-4 h-4",children:r.jsx("path",{d:"M8 4l4 5H4l4-5z"})})}),r.jsx("span",{className:`text-[13px] font-bold tabular-nums leading-none ${e.votes>0?"text-cc-primary":e.votes<0?"text-cc-error":"text-cc-fg/40"}`,children:e.votes}),r.jsx("button",{onClick:()=>v(-1),disabled:h!==null,className:"w-7 h-6 flex items-center justify-center rounded-md text-cc-fg/35 hover:text-cc-error hover:bg-cc-error/5 transition-colors cursor-pointer disabled:opacity-50",title:"Downvote","aria-label":"Downvote",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-4 h-4",children:r.jsx("path",{d:"M8 12l4-5H4l4 5z"})})})]}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[e.featured&&r.jsx("span",{className:"text-amber-500 shrink-0",title:"Featured",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-4 h-4",children:r.jsx("path",{d:"M8 1.5l2.09 4.26 4.66.68-3.38 3.28.8 4.64L8 12.17l-4.17 2.19.8-4.64-3.38-3.28 4.66-.68L8 1.5z"})})}),r.jsx("h3",{className:"text-[14px] font-semibold text-cc-fg truncate",children:e.name}),r.jsx("span",{className:"text-[11px] text-cc-fg/40 shrink-0 ml-auto",children:tP(e.createdAt)})]}),e.description&&r.jsx("p",{className:"mt-1 text-[12px] text-cc-fg/55 line-clamp-2 leading-relaxed",children:e.description}),r.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mt-3",children:[r.jsx("span",{className:`text-[10px] font-semibold px-2 py-0.5 rounded-full border ${y}`,children:e.backendType}),e.model&&r.jsx("span",{className:"text-[10px] font-medium px-2 py-0.5 rounded-full bg-cc-hover/70 text-cc-fg/55 border border-cc-border/30 truncate max-w-[140px]",children:e.model}),e.totalCostUsd>0&&r.jsx("span",{className:"text-[10px] font-medium px-2 py-0.5 rounded-full bg-cc-hover/70 text-cc-fg/55 border border-cc-border/30",children:eP(e.totalCostUsd)}),e.numTurns>0&&r.jsxs("span",{className:"text-[10px] font-medium px-2 py-0.5 rounded-full bg-cc-hover/70 text-cc-fg/55 border border-cc-border/30",children:[e.numTurns," turns"]}),e.durationMs>0&&r.jsx("span",{className:"text-[10px] font-medium px-2 py-0.5 rounded-full bg-cc-hover/70 text-cc-fg/55 border border-cc-border/30",children:Zz(e.durationMs)}),(e.totalLinesAdded>0||e.totalLinesRemoved>0)&&r.jsxs("span",{className:"text-[10px] font-medium px-2 py-0.5 rounded-full bg-cc-hover/70 border border-cc-border/30",children:[r.jsxs("span",{className:"text-green-500",children:["+",e.totalLinesAdded]}),r.jsx("span",{className:"text-cc-fg/30 mx-0.5",children:"/"}),r.jsxs("span",{className:"text-red-500",children:["-",e.totalLinesRemoved]})]})]}),e.tags.length>0&&r.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2.5",children:e.tags.map(S=>r.jsxs("span",{className:"text-[10px] font-medium px-2 py-0.5 rounded-full bg-cc-primary/5 text-cc-primary/70 border border-cc-primary/10",children:["#",S]},S))})]})]})}),r.jsxs("div",{className:"flex items-center justify-between px-5 py-2.5 border-t border-cc-border/30 bg-cc-bg/50",children:[r.jsxs("a",{href:`#/replay/session/${e.sessionId}`,className:"inline-flex items-center gap-1.5 text-[11px] font-medium text-cc-primary hover:text-cc-primary-hover transition-colors",title:"Watch replay",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:r.jsx("path",{d:"M4.5 3.5A.5.5 0 015.22 3l7 4.5a.5.5 0 010 .86l-7 4.5A.5.5 0 014.5 12.5v-9z"})}),"Watch Replay"]}),r.jsxs("div",{className:"flex items-center gap-0.5",children:[n&&r.jsx("button",{onClick:()=>n(e.id),className:`w-7 h-7 flex items-center justify-center rounded-lg transition-colors cursor-pointer ${e.featured?"text-amber-500 bg-amber-500/10":"text-cc-fg/30 hover:text-amber-500 hover:bg-amber-500/5"}`,title:e.featured?"Unfeature":"Feature","aria-label":e.featured?"Unfeature":"Feature",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:r.jsx("path",{d:"M8 1.5l2.09 4.26 4.66.68-3.38 3.28.8 4.64L8 12.17l-4.17 2.19.8-4.64-3.38-3.28 4.66-.68L8 1.5z"})})}),a&&l&&r.jsx("button",{onClick:()=>a(e.id),className:"w-7 h-7 flex items-center justify-center rounded-lg text-cc-fg/30 hover:text-orange-500 hover:bg-orange-500/5 transition-colors cursor-pointer",title:"Export to ClawHub","aria-label":"Export to ClawHub",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"w-3.5 h-3.5",children:r.jsx("path",{d:"M7 1h8v8M15 1L8 8M6 3H2v11h11v-4",strokeLinecap:"round",strokeLinejoin:"round"})})}),c&&d&&r.jsx("button",{onClick:()=>c(e.id),className:"w-7 h-7 flex items-center justify-center rounded-lg text-cc-fg/30 hover:text-violet-500 hover:bg-violet-500/5 transition-colors cursor-pointer",title:"Post to Moltbook","aria-label":"Post to Moltbook",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:r.jsx("path",{d:"M8 0a8 8 0 110 16A8 8 0 018 0zm0 2a1.5 1.5 0 00-1.5 1.5v3.793l-1.146-1.147a1.5 1.5 0 00-2.122 2.122l3.5 3.5a1.5 1.5 0 002.122 0l3.5-3.5a1.5 1.5 0 00-2.122-2.122L9.5 7.293V3.5A1.5 1.5 0 008 2z"})})}),f&&r.jsx("button",{onClick:()=>f(e.id),className:"w-7 h-7 flex items-center justify-center rounded-lg text-cc-fg/30 hover:text-cc-primary hover:bg-cc-primary/5 transition-colors cursor-pointer",title:"Copy public link","aria-label":"Copy public replay link",children:r.jsxs("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:[r.jsx("path",{d:"M4.715 6.542L3.343 7.914a3 3 0 104.243 4.243l1.828-1.829A3 3 0 008.586 5.5L8 6.086a1.002 1.002 0 00-.154.199 2 2 0 01.861 3.337L6.88 11.45a2 2 0 11-2.83-2.83l.793-.792a4.018 4.018 0 01-.128-1.287z"}),r.jsx("path",{d:"M11.285 9.458l1.372-1.372a3 3 0 10-4.243-4.243L6.586 5.672A3 3 0 007.414 10.5l.586-.586a1.002 1.002 0 00.154-.199 2 2 0 01-.861-3.337L9.12 4.55a2 2 0 112.83 2.83l-.793.792c.112.42.155.855.128 1.287z"})]})}),s&&!g&&r.jsx("button",{onClick:()=>b(!0),className:"w-7 h-7 flex items-center justify-center rounded-lg text-cc-fg/30 hover:text-cc-error hover:bg-cc-error/5 transition-colors cursor-pointer",title:"Delete","aria-label":"Delete",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"w-3.5 h-3.5",children:r.jsx("path",{d:"M3 4h10M5.5 4V2.5h5V4M6 6.5v5M10 6.5v5M4.5 4l.5 9.5h6l.5-9.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),s&&g&&r.jsxs("div",{className:"flex items-center gap-1 ml-1",children:[r.jsx("button",{onClick:()=>b(!1),className:"px-2 py-1 rounded-md text-[10px] font-medium text-cc-fg/50 hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:"Cancel"}),r.jsx("button",{onClick:()=>{s(e.id),b(!1)},className:"px-2 py-1 rounded-md text-[10px] font-medium bg-cc-error text-white hover:bg-cc-error/90 transition-colors cursor-pointer",children:"Delete"})]})]})]})]})}const Ys="playground-session",Wd=[{id:"mem-1",kind:"knowledge",namespace:"repo:a1b2c3d4",tag:"rate-limiting",summary:"API routes use the Hono middleware stack; rate limiting belongs in web/server/routes.ts before auth checks.",weight:.92},{id:"mem-2",kind:"knowledge",namespace:"global",tag:"testing",summary:"All new backend code must include colocated Vitest tests (routes.test.ts next to routes.ts).",weight:.78},{id:"mem-3",kind:"fragment",namespace:"repo:a1b2c3d4",summary:"Decided to use token-bucket over sliding-window because the session store already tracks per-session timestamps.",weight:.55},{id:"mem-4",kind:"fragment",namespace:"agent:claude",summary:"Claude Code sessions reconnect with --resume; middleware must tolerate duplicate session init.",weight:.31}];function bn(e){return{request_id:`perm-${Math.random().toString(36).slice(2,8)}`,tool_use_id:`tu-${Math.random().toString(36).slice(2,8)}`,timestamp:Date.now(),...e}}const Z5=bn({tool_name:"Bash",input:{command:"git log --oneline -20 && npm run build",description:"View recent commits and build the project"},permission_suggestions:[{type:"addRules",rules:[{toolName:"Bash",ruleContent:"git log --oneline -20 && npm run build"}],behavior:"allow",destination:"session"},{type:"addRules",rules:[{toolName:"Bash",ruleContent:"git log --oneline -20 && npm run build"}],behavior:"allow",destination:"projectSettings"}]}),nP=bn({tool_name:"Edit",input:{file_path:"/Users/stan/Dev/project/src/utils/format.ts",old_string:`export function formatDate(d: Date) {
|
|
129
129
|
return d.toISOString();
|
|
130
130
|
}`,new_string:`export function formatDate(d: Date, locale = "en-US") {
|
|
131
131
|
return d.toLocaleDateString(locale, {
|
|
@@ -133,13 +133,13 @@ ${D}`},[f]);return c?G.length===0?r.jsxs("div",{className:"h-full flex flex-col
|
|
|
133
133
|
month: "short",
|
|
134
134
|
day: "numeric",
|
|
135
135
|
});
|
|
136
|
-
}`},permission_suggestions:[{type:"addRules",rules:[{toolName:"Edit"}],behavior:"allow",destination:"session"}]}),
|
|
136
|
+
}`},permission_suggestions:[{type:"addRules",rules:[{toolName:"Edit"}],behavior:"allow",destination:"session"}]}),rP=bn({tool_name:"Write",input:{file_path:"/Users/stan/Dev/project/src/config.ts",content:`export const config = {
|
|
137
137
|
apiUrl: "https://api.example.com",
|
|
138
138
|
timeout: 5000,
|
|
139
139
|
retries: 3,
|
|
140
140
|
debug: process.env.NODE_ENV !== "production",
|
|
141
141
|
};
|
|
142
|
-
`}}),
|
|
142
|
+
`}}),iP=bn({tool_name:"Read",input:{file_path:"/Users/stan/Dev/project/package.json"},permission_suggestions:[{type:"addRules",rules:[{toolName:"Read"}],behavior:"allow",destination:"session"},{type:"addRules",rules:[{toolName:"Read"}],behavior:"allow",destination:"userSettings"}]}),aP=bn({tool_name:"Glob",input:{pattern:"**/*.test.ts",path:"/Users/stan/Dev/project/src"}}),oP=bn({tool_name:"Grep",input:{pattern:"TODO|FIXME|HACK",path:"/Users/stan/Dev/project/src",glob:"*.ts"}}),lP=bn({tool_name:"ExitPlanMode",input:{plan:`## Summary
|
|
143
143
|
Refactor the authentication module to use JWT tokens instead of session cookies.
|
|
144
144
|
|
|
145
145
|
## Changes
|
|
@@ -150,7 +150,7 @@ Refactor the authentication module to use JWT tokens instead of session cookies.
|
|
|
150
150
|
|
|
151
151
|
## Test plan
|
|
152
152
|
- Run \`npm test -- --grep auth\`
|
|
153
|
-
- Manual test with curl`,allowedPrompts:[{tool:"Bash",prompt:"run tests"},{tool:"Bash",prompt:"install dependencies"}]}}),
|
|
153
|
+
- Manual test with curl`,allowedPrompts:[{tool:"Bash",prompt:"run tests"},{tool:"Bash",prompt:"install dependencies"}]}}),cP=bn({tool_name:"WebSearch",input:{query:"TypeScript 5.5 new features",allowed_domains:["typescriptlang.org","github.com"]},description:"Search the web for TypeScript 5.5 features"}),e2=bn({tool_name:"dynamic:code_interpreter",input:{code:"print('hello from dynamic tool')"},description:"Custom tool call: code_interpreter"}),uP=bn({tool_name:"AskUserQuestion",input:{questions:[{header:"Auth method",question:"Which authentication method should we use for the API?",options:[{label:"JWT tokens (Recommended)",description:"Stateless, scalable, works well with microservices"},{label:"Session cookies",description:"Traditional approach, simpler but requires session storage"},{label:"OAuth 2.0",description:"Delegated auth, best for third-party integrations"}],multiSelect:!1}]}}),dP=bn({tool_name:"AskUserQuestion",input:{questions:[{header:"Database",question:"Which database should we use?",options:[{label:"PostgreSQL",description:"Relational, strong consistency"},{label:"MongoDB",description:"Document store, flexible schema"}],multiSelect:!1},{header:"Cache",question:"Do you want to add a caching layer?",options:[{label:"Redis",description:"In-memory, fast, supports pub/sub"},{label:"No cache",description:"Keep it simple for now"}],multiSelect:!1}]}}),t2={id:"msg-1",role:"user",content:"Can you help me refactor the authentication module to use JWT tokens?",timestamp:Date.now()-6e4},hP={id:"msg-2",role:"user",content:"Here's a screenshot of the error I'm seeing",images:[{media_type:"image/png",data:"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPj/HwADBwIAMCbHYQAAAABJRU5ErkJggg=="}],timestamp:Date.now()-55e3},pg={id:"msg-3",role:"assistant",content:"",contentBlocks:[{type:"text",text:`I'll help you refactor the authentication module. Let me first look at the current implementation.
|
|
154
154
|
|
|
155
155
|
Here's what I found:
|
|
156
156
|
- The current auth uses **session cookies** via \`express-session\`
|
|
@@ -178,7 +178,7 @@ src/auth/session.ts`},{type:"tool_use",id:"tu-2",name:"Read",input:{file_path:"s
|
|
|
178
178
|
return res.status(401).json({ error: "Unauthorized" });
|
|
179
179
|
}
|
|
180
180
|
next();
|
|
181
|
-
}`},{type:"text",text:"Now I understand the current structure. Let me create the JWT utility."}],timestamp:Date.now()-45e3},
|
|
181
|
+
}`},{type:"text",text:"Now I understand the current structure. Let me create the JWT utility."}],timestamp:Date.now()-45e3},fP={id:"msg-5",role:"assistant",content:"",contentBlocks:[{type:"thinking",thinking:`Let me think about the best approach here. The user wants to migrate from session cookies to JWT. I need to:
|
|
182
182
|
1. Create a JWT sign/verify utility
|
|
183
183
|
2. Update the middleware to read Authorization header
|
|
184
184
|
3. Change the login endpoint to return a token
|
|
@@ -186,15 +186,15 @@ src/auth/session.ts`},{type:"tool_use",id:"tu-2",name:"Read",input:{file_path:"s
|
|
|
186
186
|
|
|
187
187
|
I should use jsonwebtoken package for signing and jose for verification in edge environments. But since this is a Node.js server, jsonwebtoken is fine.
|
|
188
188
|
|
|
189
|
-
The token should contain: userId, role, iat, exp. Expiry should be configurable. I'll also add a refresh token mechanism.`},{type:"text",text:"I've analyzed the codebase and have a clear plan. Let me start implementing."}],timestamp:Date.now()-4e4},
|
|
189
|
+
The token should contain: userId, role, iat, exp. Expiry should be configurable. I'll also add a refresh token mechanism.`},{type:"text",text:"I've analyzed the codebase and have a clear plan. Let me start implementing."}],timestamp:Date.now()-4e4},pP={id:"msg-6",role:"system",content:"Context compacted successfully",timestamp:Date.now()-3e4},n2={id:"msg-7",role:"assistant",content:"",contentBlocks:[{type:"text",text:"Let me try running the tests."},{type:"tool_use",id:"tu-3",name:"Bash",input:{command:"npm test -- --grep auth"}},{type:"tool_result",tool_use_id:"tu-3",content:`FAIL src/auth/__tests__/middleware.test.ts
|
|
190
190
|
● Auth Middleware › should reject expired tokens
|
|
191
191
|
Expected: 401
|
|
192
192
|
Received: 500
|
|
193
193
|
|
|
194
|
-
TypeError: Cannot read property 'verify' of undefined`,is_error:!0},{type:"text",text:"There's a test failure. Let me fix the issue."}],timestamp:Date.now()-2e4},r2=[{id:"1",subject:"Create JWT utility module",description:"",status:"completed"},{id:"2",subject:"Update auth middleware",description:"",status:"completed",activeForm:"Updating auth middleware"},{id:"3",subject:"Migrate login endpoint",description:"",status:"in_progress",activeForm:"Refactoring login to return JWT"},{id:"4",subject:"Add refresh token support",description:"",status:"pending"},{id:"5",subject:"Update all auth tests",description:"",status:"pending",blockedBy:["3"]},{id:"6",subject:"Run full test suite and fix failures",description:"",status:"pending",blockedBy:["5"]}],pP=[{id:"tg-1",name:"Read",input:{file_path:"src/auth/middleware.ts"}},{id:"tg-2",name:"Read",input:{file_path:"src/auth/login.ts"}},{id:"tg-3",name:"Read",input:{file_path:"src/auth/session.ts"}},{id:"tg-4",name:"Read",input:{file_path:"src/auth/types.ts"}}],mP=[{id:"sa-1",name:"Grep",input:{pattern:"useAuth",path:"src/"}},{id:"sa-2",name:"Grep",input:{pattern:"session.userId",path:"src/"}}],gP={number:162,title:"feat: add dark mode toggle to application settings",url:"https://github.com/example/project/pull/162",state:"OPEN",isDraft:!1,reviewDecision:"CHANGES_REQUESTED",additions:91,deletions:88,changedFiles:24,checks:[{name:"CI / Build",status:"COMPLETED",conclusion:"SUCCESS"},{name:"CI / Test",status:"COMPLETED",conclusion:"FAILURE"},{name:"CI / Lint",status:"COMPLETED",conclusion:"SUCCESS"}],checksSummary:{total:3,success:2,failure:1,pending:0},reviewThreads:{total:4,resolved:2,unresolved:2}},xP={number:158,title:"fix: prevent mobile keyboard layout shift and iOS zoom",url:"https://github.com/example/project/pull/158",state:"OPEN",isDraft:!1,reviewDecision:"APPROVED",additions:42,deletions:12,changedFiles:3,checks:[{name:"CI / Build",status:"COMPLETED",conclusion:"SUCCESS"},{name:"CI / Test",status:"COMPLETED",conclusion:"SUCCESS"}],checksSummary:{total:2,success:2,failure:0,pending:0},reviewThreads:{total:1,resolved:1,unresolved:0}},vP={number:165,title:"refactor: migrate auth module to JWT tokens with refresh support",url:"https://github.com/example/project/pull/165",state:"OPEN",isDraft:!0,reviewDecision:null,additions:340,deletions:156,changedFiles:18,checks:[{name:"CI / Build",status:"IN_PROGRESS",conclusion:null},{name:"CI / Test",status:"QUEUED",conclusion:null}],checksSummary:{total:2,success:0,failure:0,pending:2},reviewThreads:{total:0,resolved:0,unresolved:0}},bP={number:155,title:"feat(cli): add service install/uninstall and separate dev/prod ports",url:"https://github.com/example/project/pull/155",state:"MERGED",isDraft:!1,reviewDecision:"APPROVED",additions:287,deletions:63,changedFiles:11,checks:[{name:"CI / Build",status:"COMPLETED",conclusion:"SUCCESS"},{name:"CI / Test",status:"COMPLETED",conclusion:"SUCCESS"},{name:"CI / Lint",status:"COMPLETED",conclusion:"SUCCESS"}],checksSummary:{total:3,success:3,failure:0,pending:0},reviewThreads:{total:3,resolved:3,unresolved:0}},_P={id:"auth-refactor",sessionId:"sess-abc-123",name:"Auth System Refactor",description:"Migrated from cookie-based auth to JWT with refresh tokens. Full test coverage included.",tags:["auth","jwt","refactor"],featured:!0,votes:24,createdAt:Date.now()-864e5*3,updatedAt:Date.now()-864e5*2,backendType:"claude",model:"claude-opus-4-6",totalCostUsd:1.45,durationMs:18e5,totalLinesAdded:542,totalLinesRemoved:218,numTurns:28},yP={id:"api-tests",sessionId:"sess-def-456",name:"API Integration Tests",description:"Added comprehensive integration tests for all REST endpoints.",tags:["testing","api"],featured:!1,votes:7,createdAt:Date.now()-864e5,updatedAt:Date.now()-864e5,backendType:"claude",model:"claude-sonnet-4-5-20250929",totalCostUsd:.38,durationMs:6e5,totalLinesAdded:890,totalLinesRemoved:12,numTurns:12},wP={id:"quick-bugfix",sessionId:"sess-ghi-789",name:"Fix Race Condition",description:"Fixed async race condition in the event queue.",tags:["bugfix"],featured:!1,votes:-2,createdAt:Date.now()-36e5,updatedAt:Date.now()-36e5,backendType:"codex",model:"gpt-5.3-codex",totalCostUsd:.02,durationMs:45e3,totalLinesAdded:8,totalLinesRemoved:3,numTurns:3},SP=[{name:"filesystem",status:"connected",config:{type:"stdio",command:"npx",args:["-y","@anthropic/mcp-fs"]},scope:"project",tools:[{name:"read_file",annotations:{readOnly:!0}},{name:"write_file",annotations:{destructive:!0}},{name:"list_directory",annotations:{readOnly:!0}}]},{name:"github",status:"connected",config:{type:"stdio",command:"npx",args:["-y","@anthropic/mcp-github"]},scope:"user",tools:[{name:"create_issue"},{name:"list_prs",annotations:{readOnly:!0}},{name:"create_pr"}]},{name:"postgres",status:"failed",error:"Connection refused: ECONNREFUSED 127.0.0.1:5432",config:{type:"stdio",command:"npx",args:["-y","@anthropic/mcp-postgres"]},scope:"project",tools:[]},{name:"web-search",status:"disabled",config:{type:"sse",url:"http://localhost:8080/sse"},scope:"user",tools:[{name:"search",annotations:{readOnly:!0,openWorld:!0}}]},{name:"docker",status:"connecting",config:{type:"stdio",command:"docker-mcp-server"},scope:"project",tools:[]}],mg=[{id:"v-1",name:"Alice",role:"owner"},{id:"v-2",name:"Bob",role:"collaborator"},{id:"v-3",name:"Carol",role:"spectator"}],jP=[{viewerId:"v-1",viewerName:"Alice",vote:"allow",timestamp:Date.now()-5e3},{viewerId:"v-2",viewerName:"Bob",vote:"deny",timestamp:Date.now()-3e3}],i2=bn({tool_name:"Bash",input:{command:"rm -rf node_modules && npm install",description:"Clean reinstall dependencies"}}),a2=bn({tool_name:"Write",input:{file_path:"src/config.ts",content:"export default {}"}}),kP=bn({tool_name:"Bash",input:{command:"npm test",description:"Run tests"}});function CP(){const[e,t]=w.useState(()=>document.documentElement.classList.contains("dark"));return w.useEffect(()=>{document.documentElement.classList.toggle("dark",e)},[e]),w.useEffect(()=>{const s=Y.getState(),n=Y.getState(),a=Ys,l=n.sessions.get(a),c=n.messages.get(a),d=n.pendingPermissions.get(a),f=n.connectionStatus.get(a),h=n.cliConnected.get(a),m=n.sessionStatus.get(a),g=n.streaming.get(a),b=n.streamingStartedAt.get(a),v=n.streamingOutputTokens.get(a),y={session_id:a,backend_type:"claude",model:"claude-sonnet-4-5",cwd:"/Users/stan/Dev/project",tools:["Bash","Read","Edit","Write","Glob","Grep","WebSearch"],permissionMode:"default",claude_code_version:"1.0.0",mcp_servers:[],agents:[],slash_commands:["explain","review","fix"],skills:["doc-coauthoring","frontend-design"],total_cost_usd:.1847,num_turns:14,context_used_percent:62,is_compacting:!1,git_branch:"feat/jwt-auth",is_worktree:!0,repo_root:"/Users/stan/Dev/project",git_ahead:3,git_behind:0,total_lines_added:142,total_lines_removed:38,total_duration_api_ms:0};return s.addSession(y),s.setConnectionStatus(a,"connected"),s.setCliConnected(a,!0),s.setSessionStatus(a,"running"),s.setMessages(a,[t2,pg,s2,n2]),s.setStreaming(a,"I'm updating tests and then I'll run the full suite."),s.setStreamingStats(a,{startedAt:Date.now()-12e3,outputTokens:1200}),s.addPermission(a,Z5),s.addPermission(a,e2),s.setSessionViewers(a,mg),s.setMyRole(a,"owner"),s.setMyViewerId(a,"v-1"),s.setPermissionVotes(a,i2.request_id,{votes:jP,votersTotal:3,deadline:Date.now()+25e3}),s.setVoteResult(a,a2.request_id,{result:"allow",policy:"majority-rules"}),()=>{Y.setState(S=>{const j=new Map(S.sessions),k=new Map(S.messages),E=new Map(S.pendingPermissions),N=new Map(S.connectionStatus),B=new Map(S.cliConnected),A=new Map(S.sessionStatus),P=new Map(S.streaming),K=new Map(S.streamingStartedAt),X=new Map(S.streamingOutputTokens);l?j.set(a,l):j.delete(a),c?k.set(a,c):k.delete(a),d?E.set(a,d):E.delete(a),f?N.set(a,f):N.delete(a),typeof h=="boolean"?B.set(a,h):B.delete(a),m?A.set(a,m):A.delete(a),typeof g=="string"?P.set(a,g):P.delete(a),typeof b=="number"?K.set(a,b):K.delete(a),typeof v=="number"?X.set(a,v):X.delete(a);const Z=new Map(S.sessionViewers);Z.delete(a);const I=new Map(S.myRole);I.delete(a);const H=new Map(S.myViewerId);H.delete(a);const F=new Map(S.permissionVotes);F.delete(a);const G=new Map(S.voteResults);return G.delete(a),{sessions:j,messages:k,pendingPermissions:E,connectionStatus:N,cliConnected:B,sessionStatus:A,streaming:P,streamingStartedAt:K,streamingOutputTokens:X,sessionViewers:Z,myRole:I,myViewerId:H,permissionVotes:F,voteResults:G}})}},[]),r.jsxs("div",{className:"min-h-screen bg-cc-bg text-cc-fg font-sans-ui",children:[r.jsx("header",{className:"sticky top-0 z-50 bg-cc-sidebar border-b border-cc-border",children:r.jsxs("div",{className:"max-w-5xl mx-auto px-6 py-4 flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("h1",{className:"text-lg font-semibold text-cc-fg tracking-tight",children:"Component Playground"}),r.jsx("p",{className:"text-xs text-cc-muted mt-0.5",children:"Visual catalog of all UI components"})]}),r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("button",{onClick:()=>{window.location.hash=""},className:"px-3 py-1.5 text-xs font-medium rounded-lg bg-cc-hover hover:bg-cc-active text-cc-fg border border-cc-border transition-colors cursor-pointer",children:"Back to App"}),r.jsx("button",{onClick:()=>t(!e),className:"px-3 py-1.5 text-xs font-medium rounded-lg bg-cc-primary/10 hover:bg-cc-primary/20 text-cc-primary border border-cc-primary/20 transition-colors cursor-pointer",children:e?"Light Mode":"Dark Mode"})]})]})}),r.jsxs("div",{className:"max-w-5xl mx-auto px-6 py-8 space-y-12",children:[r.jsx(vt,{title:"Permission Banners",description:"Tool approval requests shown above the composer",children:r.jsxs("div",{className:"border border-cc-border rounded-xl overflow-hidden bg-cc-card divide-y divide-cc-border",children:[r.jsx(Zs,{permission:Z5,sessionId:Ys}),r.jsx(Zs,{permission:sP,sessionId:Ys}),r.jsx(Zs,{permission:nP,sessionId:Ys}),r.jsx(Zs,{permission:rP,sessionId:Ys}),r.jsx(Zs,{permission:iP,sessionId:Ys}),r.jsx(Zs,{permission:aP,sessionId:Ys}),r.jsx(Zs,{permission:lP,sessionId:Ys}),r.jsx(Zs,{permission:e2,sessionId:Ys})]})}),r.jsx(vt,{title:"Presence Indicators",description:"Viewer avatars with role-based coloring — shown in TopBar when multiple viewers are connected",children:r.jsxs("div",{className:"space-y-4",children:[r.jsx(Le,{label:"Viewers connected (owner, collaborator, spectator)",children:r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("div",{className:"flex items-center -space-x-1.5",children:mg.map(s=>r.jsx("div",{className:`w-6 h-6 rounded-full flex items-center justify-center text-[10px] font-bold border-2 border-cc-card ${s.role==="owner"?"bg-cc-primary/20 text-cc-primary":s.role==="spectator"?"bg-cc-muted/20 text-cc-muted":"bg-cc-success/20 text-cc-success"}`,title:`${s.name} (${s.role})`,children:s.name.charAt(0).toUpperCase()},s.id))}),r.jsxs("div",{className:"text-xs text-cc-muted",children:[mg.length," viewers connected"]})]})}),r.jsx(Le,{label:"Role legend",children:r.jsx("div",{className:"flex items-center gap-4",children:["owner","collaborator","spectator"].map(s=>r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx("div",{className:`w-3 h-3 rounded-full ${s==="owner"?"bg-cc-primary/40":s==="collaborator"?"bg-cc-success/40":"bg-cc-muted/40"}`}),r.jsx("span",{className:"text-[11px] text-cc-fg capitalize",children:s})]},s))})})]})}),r.jsx(vt,{title:"Permission Voting",description:"Multi-viewer vote collection with countdown timer, vote counts, and resolved state",children:r.jsxs("div",{className:"space-y-4",children:[r.jsx(Le,{label:"Active vote (2/3 voted, countdown running)",children:r.jsx("div",{className:"border border-cc-border rounded-xl overflow-hidden bg-cc-card",children:r.jsx(Zs,{permission:i2,sessionId:Ys})})}),r.jsx(Le,{label:"Resolved vote (majority allow)",children:r.jsx("div",{className:"border border-cc-border rounded-xl overflow-hidden bg-cc-card",children:r.jsx(Zs,{permission:a2,sessionId:Ys})})}),r.jsx(Le,{label:"Spectator view (buttons disabled)",children:r.jsx(RP,{})})]})}),r.jsx(vt,{title:"Real Chat Stack",description:"Integrated ChatView using real MessageFeed + PermissionBanner + Composer components",children:r.jsx("div",{"data-testid":"playground-real-chat-stack",className:"max-w-3xl border border-cc-border rounded-xl overflow-hidden bg-cc-card h-[620px]",children:r.jsx(mC,{sessionId:Ys})})}),r.jsx(vt,{title:"Session Replay Controls",description:"Replay player UI — play/pause, speed selector, timeline scrubber, and recording metadata",children:r.jsxs("div",{className:"space-y-4",children:[r.jsx(Le,{label:"Replay controls (idle)",children:r.jsx(qd,{state:"idle",position:0,total:42,speed:1})}),r.jsx(Le,{label:"Replay controls (playing at 4x)",children:r.jsx(qd,{state:"playing",position:18,total:42,speed:4})}),r.jsx(Le,{label:"Replay controls (paused mid-way)",children:r.jsx(qd,{state:"paused",position:30,total:42,speed:2})}),r.jsx(Le,{label:"Replay controls (ended)",children:r.jsx(qd,{state:"ended",position:42,total:42,speed:1})}),r.jsx(Le,{label:"Replay header bar",children:r.jsxs("div",{className:"flex items-center justify-between px-4 py-3 bg-cc-sidebar border border-cc-border rounded-lg",children:[r.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[r.jsx("div",{className:"w-8 h-8 rounded-full bg-cc-primary/10 flex items-center justify-center shrink-0",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-4 h-4 text-cc-primary",children:r.jsx("path",{d:"M4 2l10 6-10 6V2z"})})}),r.jsxs("div",{className:"min-w-0",children:[r.jsx("div",{className:"text-sm font-medium text-cc-fg truncate",children:"Session Replay"}),r.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-cc-muted",children:[r.jsx("span",{className:"px-1.5 py-0.5 bg-cc-hover rounded text-[10px] font-medium",children:"claude"}),r.jsx("span",{children:"claude-sonnet-4-5"}),r.jsx("span",{className:"text-cc-muted/40",children:"|"}),r.jsx("span",{children:"42 messages"})]})]})]}),r.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[r.jsx("button",{className:"p-2 rounded-lg hover:bg-cc-hover text-cc-muted transition-colors cursor-pointer",title:"Share replay link",children:r.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"w-4 h-4",children:[r.jsx("path",{d:"M6 10l4-4M10 10V6H6",strokeLinecap:"round",strokeLinejoin:"round"}),r.jsx("rect",{x:"2",y:"2",width:"12",height:"12",rx:"2"})]})}),r.jsx("button",{className:"p-2 rounded-lg hover:bg-cc-hover text-cc-muted transition-colors cursor-pointer",title:"Close replay",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-4 h-4",children:r.jsx("path",{d:"M4.646 4.646a.5.5 0 01.708 0L8 7.293l2.646-2.647a.5.5 0 01.708.708L8.707 8l2.647 2.646a.5.5 0 01-.708.708L8 8.707l-2.646 2.647a.5.5 0 01-.708-.708L7.293 8 4.646 5.354a.5.5 0 010-.708z"})})})]})]})}),r.jsx(Le,{label:"Fork from message (hover icon)",children:r.jsx("div",{className:"max-w-3xl",children:r.jsx(sr,{message:pg,onFork:()=>{}})})})]})}),r.jsx(vt,{title:"ExitPlanMode",description:"Plan approval request — previously rendered as raw JSON, now shows formatted markdown",children:r.jsx("div",{className:"border border-cc-border rounded-xl overflow-hidden bg-cc-card",children:r.jsx(Zs,{permission:oP,sessionId:Ys})})}),r.jsx(vt,{title:"AskUserQuestion",description:"Interactive questions with selectable options",children:r.jsxs("div",{className:"space-y-4",children:[r.jsx(Le,{label:"Single question",children:r.jsx(Zs,{permission:cP,sessionId:Ys})}),r.jsx(Le,{label:"Multi-question",children:r.jsx(Zs,{permission:uP,sessionId:Ys})})]})}),r.jsx(vt,{title:"Messages",description:"Chat message bubbles for all roles",children:r.jsxs("div",{className:"space-y-4 max-w-3xl",children:[r.jsx(Le,{label:"User message",children:r.jsx(sr,{message:t2})}),r.jsx(Le,{label:"User message with image",children:r.jsx(sr,{message:dP})}),r.jsx(Le,{label:"Assistant message (markdown)",children:r.jsx(sr,{message:pg})}),r.jsx(Le,{label:"Assistant message (with tool calls)",children:r.jsx(sr,{message:s2})}),r.jsx(Le,{label:"Assistant message (thinking block)",children:r.jsx(sr,{message:hP})}),r.jsx(Le,{label:"Tool result with error",children:r.jsx(sr,{message:n2})}),r.jsx(Le,{label:"System message",children:r.jsx(sr,{message:fP})})]})}),r.jsx(vt,{title:"Tool Blocks",description:"Expandable tool call visualization",children:r.jsxs("div",{className:"space-y-2 max-w-3xl",children:[r.jsx(mn,{name:"Bash",input:{command:"git status && npm run lint",description:"Check git status and lint"},toolUseId:"tb-1"}),r.jsx(mn,{name:"Read",input:{file_path:"/Users/stan/Dev/project/src/index.ts",offset:10,limit:50},toolUseId:"tb-2"}),r.jsx(mn,{name:"Edit",input:{file_path:"src/utils.ts",old_string:"const x = 1;",new_string:"const x = 2;",replace_all:!0},toolUseId:"tb-3"}),r.jsx(mn,{name:"Write",input:{file_path:"src/new-file.ts",content:`export const hello = "world";
|
|
194
|
+
TypeError: Cannot read property 'verify' of undefined`,is_error:!0},{type:"text",text:"There's a test failure. Let me fix the issue."}],timestamp:Date.now()-2e4},r2=[{id:"1",subject:"Create JWT utility module",description:"",status:"completed"},{id:"2",subject:"Update auth middleware",description:"",status:"completed",activeForm:"Updating auth middleware"},{id:"3",subject:"Migrate login endpoint",description:"",status:"in_progress",activeForm:"Refactoring login to return JWT"},{id:"4",subject:"Add refresh token support",description:"",status:"pending"},{id:"5",subject:"Update all auth tests",description:"",status:"pending",blockedBy:["3"]},{id:"6",subject:"Run full test suite and fix failures",description:"",status:"pending",blockedBy:["5"]}],mP=[{id:"tg-1",name:"Read",input:{file_path:"src/auth/middleware.ts"}},{id:"tg-2",name:"Read",input:{file_path:"src/auth/login.ts"}},{id:"tg-3",name:"Read",input:{file_path:"src/auth/session.ts"}},{id:"tg-4",name:"Read",input:{file_path:"src/auth/types.ts"}}],gP=[{id:"sa-1",name:"Grep",input:{pattern:"useAuth",path:"src/"}},{id:"sa-2",name:"Grep",input:{pattern:"session.userId",path:"src/"}}],xP={number:162,title:"feat: add dark mode toggle to application settings",url:"https://github.com/example/project/pull/162",state:"OPEN",isDraft:!1,reviewDecision:"CHANGES_REQUESTED",additions:91,deletions:88,changedFiles:24,checks:[{name:"CI / Build",status:"COMPLETED",conclusion:"SUCCESS"},{name:"CI / Test",status:"COMPLETED",conclusion:"FAILURE"},{name:"CI / Lint",status:"COMPLETED",conclusion:"SUCCESS"}],checksSummary:{total:3,success:2,failure:1,pending:0},reviewThreads:{total:4,resolved:2,unresolved:2}},vP={number:158,title:"fix: prevent mobile keyboard layout shift and iOS zoom",url:"https://github.com/example/project/pull/158",state:"OPEN",isDraft:!1,reviewDecision:"APPROVED",additions:42,deletions:12,changedFiles:3,checks:[{name:"CI / Build",status:"COMPLETED",conclusion:"SUCCESS"},{name:"CI / Test",status:"COMPLETED",conclusion:"SUCCESS"}],checksSummary:{total:2,success:2,failure:0,pending:0},reviewThreads:{total:1,resolved:1,unresolved:0}},bP={number:165,title:"refactor: migrate auth module to JWT tokens with refresh support",url:"https://github.com/example/project/pull/165",state:"OPEN",isDraft:!0,reviewDecision:null,additions:340,deletions:156,changedFiles:18,checks:[{name:"CI / Build",status:"IN_PROGRESS",conclusion:null},{name:"CI / Test",status:"QUEUED",conclusion:null}],checksSummary:{total:2,success:0,failure:0,pending:2},reviewThreads:{total:0,resolved:0,unresolved:0}},_P={number:155,title:"feat(cli): add service install/uninstall and separate dev/prod ports",url:"https://github.com/example/project/pull/155",state:"MERGED",isDraft:!1,reviewDecision:"APPROVED",additions:287,deletions:63,changedFiles:11,checks:[{name:"CI / Build",status:"COMPLETED",conclusion:"SUCCESS"},{name:"CI / Test",status:"COMPLETED",conclusion:"SUCCESS"},{name:"CI / Lint",status:"COMPLETED",conclusion:"SUCCESS"}],checksSummary:{total:3,success:3,failure:0,pending:0},reviewThreads:{total:3,resolved:3,unresolved:0}},yP={id:"auth-refactor",sessionId:"sess-abc-123",name:"Auth System Refactor",description:"Migrated from cookie-based auth to JWT with refresh tokens. Full test coverage included.",tags:["auth","jwt","refactor"],featured:!0,votes:24,createdAt:Date.now()-864e5*3,updatedAt:Date.now()-864e5*2,backendType:"claude",model:"claude-opus-4-6",totalCostUsd:1.45,durationMs:18e5,totalLinesAdded:542,totalLinesRemoved:218,numTurns:28},wP={id:"api-tests",sessionId:"sess-def-456",name:"API Integration Tests",description:"Added comprehensive integration tests for all REST endpoints.",tags:["testing","api"],featured:!1,votes:7,createdAt:Date.now()-864e5,updatedAt:Date.now()-864e5,backendType:"claude",model:"claude-sonnet-4-5-20250929",totalCostUsd:.38,durationMs:6e5,totalLinesAdded:890,totalLinesRemoved:12,numTurns:12},SP={id:"quick-bugfix",sessionId:"sess-ghi-789",name:"Fix Race Condition",description:"Fixed async race condition in the event queue.",tags:["bugfix"],featured:!1,votes:-2,createdAt:Date.now()-36e5,updatedAt:Date.now()-36e5,backendType:"codex",model:"gpt-5.3-codex",totalCostUsd:.02,durationMs:45e3,totalLinesAdded:8,totalLinesRemoved:3,numTurns:3},jP=[{name:"filesystem",status:"connected",config:{type:"stdio",command:"npx",args:["-y","@anthropic/mcp-fs"]},scope:"project",tools:[{name:"read_file",annotations:{readOnly:!0}},{name:"write_file",annotations:{destructive:!0}},{name:"list_directory",annotations:{readOnly:!0}}]},{name:"github",status:"connected",config:{type:"stdio",command:"npx",args:["-y","@anthropic/mcp-github"]},scope:"user",tools:[{name:"create_issue"},{name:"list_prs",annotations:{readOnly:!0}},{name:"create_pr"}]},{name:"postgres",status:"failed",error:"Connection refused: ECONNREFUSED 127.0.0.1:5432",config:{type:"stdio",command:"npx",args:["-y","@anthropic/mcp-postgres"]},scope:"project",tools:[]},{name:"web-search",status:"disabled",config:{type:"sse",url:"http://localhost:8080/sse"},scope:"user",tools:[{name:"search",annotations:{readOnly:!0,openWorld:!0}}]},{name:"docker",status:"connecting",config:{type:"stdio",command:"docker-mcp-server"},scope:"project",tools:[]}],mg=[{id:"v-1",name:"Alice",role:"owner"},{id:"v-2",name:"Bob",role:"collaborator"},{id:"v-3",name:"Carol",role:"spectator"}],kP=[{viewerId:"v-1",viewerName:"Alice",vote:"allow",timestamp:Date.now()-5e3},{viewerId:"v-2",viewerName:"Bob",vote:"deny",timestamp:Date.now()-3e3}],i2=bn({tool_name:"Bash",input:{command:"rm -rf node_modules && npm install",description:"Clean reinstall dependencies"}}),a2=bn({tool_name:"Write",input:{file_path:"src/config.ts",content:"export default {}"}}),CP=bn({tool_name:"Bash",input:{command:"npm test",description:"Run tests"}});function NP(){const[e,t]=w.useState(()=>document.documentElement.classList.contains("dark"));return w.useEffect(()=>{document.documentElement.classList.toggle("dark",e)},[e]),w.useEffect(()=>{const s=Y.getState(),n=Y.getState(),a=Ys,l=n.sessions.get(a),c=n.messages.get(a),d=n.pendingPermissions.get(a),f=n.connectionStatus.get(a),h=n.cliConnected.get(a),m=n.sessionStatus.get(a),g=n.streaming.get(a),b=n.streamingStartedAt.get(a),v=n.streamingOutputTokens.get(a),y={session_id:a,backend_type:"claude",model:"claude-sonnet-4-5",cwd:"/Users/stan/Dev/project",tools:["Bash","Read","Edit","Write","Glob","Grep","WebSearch"],permissionMode:"default",claude_code_version:"1.0.0",mcp_servers:[],agents:[],slash_commands:["explain","review","fix"],skills:["doc-coauthoring","frontend-design"],total_cost_usd:.1847,num_turns:14,context_used_percent:62,is_compacting:!1,git_branch:"feat/jwt-auth",is_worktree:!0,repo_root:"/Users/stan/Dev/project",git_ahead:3,git_behind:0,total_lines_added:142,total_lines_removed:38,total_duration_api_ms:0};return s.addSession(y),s.setConnectionStatus(a,"connected"),s.setCliConnected(a,!0),s.setSessionStatus(a,"running"),s.setMessages(a,[t2,pg,s2,n2]),s.setStreaming(a,"I'm updating tests and then I'll run the full suite."),s.setStreamingStats(a,{startedAt:Date.now()-12e3,outputTokens:1200}),s.addPermission(a,Z5),s.addPermission(a,e2),s.setSessionViewers(a,mg),s.setMyRole(a,"owner"),s.setMyViewerId(a,"v-1"),s.setPermissionVotes(a,i2.request_id,{votes:kP,votersTotal:3,deadline:Date.now()+25e3}),s.setVoteResult(a,a2.request_id,{result:"allow",policy:"majority-rules"}),()=>{Y.setState(S=>{const j=new Map(S.sessions),k=new Map(S.messages),E=new Map(S.pendingPermissions),N=new Map(S.connectionStatus),B=new Map(S.cliConnected),A=new Map(S.sessionStatus),P=new Map(S.streaming),K=new Map(S.streamingStartedAt),X=new Map(S.streamingOutputTokens);l?j.set(a,l):j.delete(a),c?k.set(a,c):k.delete(a),d?E.set(a,d):E.delete(a),f?N.set(a,f):N.delete(a),typeof h=="boolean"?B.set(a,h):B.delete(a),m?A.set(a,m):A.delete(a),typeof g=="string"?P.set(a,g):P.delete(a),typeof b=="number"?K.set(a,b):K.delete(a),typeof v=="number"?X.set(a,v):X.delete(a);const Z=new Map(S.sessionViewers);Z.delete(a);const I=new Map(S.myRole);I.delete(a);const H=new Map(S.myViewerId);H.delete(a);const F=new Map(S.permissionVotes);F.delete(a);const G=new Map(S.voteResults);return G.delete(a),{sessions:j,messages:k,pendingPermissions:E,connectionStatus:N,cliConnected:B,sessionStatus:A,streaming:P,streamingStartedAt:K,streamingOutputTokens:X,sessionViewers:Z,myRole:I,myViewerId:H,permissionVotes:F,voteResults:G}})}},[]),r.jsxs("div",{className:"min-h-screen bg-cc-bg text-cc-fg font-sans-ui",children:[r.jsx("header",{className:"sticky top-0 z-50 bg-cc-sidebar border-b border-cc-border",children:r.jsxs("div",{className:"max-w-5xl mx-auto px-6 py-4 flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("h1",{className:"text-lg font-semibold text-cc-fg tracking-tight",children:"Component Playground"}),r.jsx("p",{className:"text-xs text-cc-muted mt-0.5",children:"Visual catalog of all UI components"})]}),r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("button",{onClick:()=>{window.location.hash=""},className:"px-3 py-1.5 text-xs font-medium rounded-lg bg-cc-hover hover:bg-cc-active text-cc-fg border border-cc-border transition-colors cursor-pointer",children:"Back to App"}),r.jsx("button",{onClick:()=>t(!e),className:"px-3 py-1.5 text-xs font-medium rounded-lg bg-cc-primary/10 hover:bg-cc-primary/20 text-cc-primary border border-cc-primary/20 transition-colors cursor-pointer",children:e?"Light Mode":"Dark Mode"})]})]})}),r.jsxs("div",{className:"max-w-5xl mx-auto px-6 py-8 space-y-12",children:[r.jsx(vt,{title:"Permission Banners",description:"Tool approval requests shown above the composer",children:r.jsxs("div",{className:"border border-cc-border rounded-xl overflow-hidden bg-cc-card divide-y divide-cc-border",children:[r.jsx(Zs,{permission:Z5,sessionId:Ys}),r.jsx(Zs,{permission:nP,sessionId:Ys}),r.jsx(Zs,{permission:rP,sessionId:Ys}),r.jsx(Zs,{permission:iP,sessionId:Ys}),r.jsx(Zs,{permission:aP,sessionId:Ys}),r.jsx(Zs,{permission:oP,sessionId:Ys}),r.jsx(Zs,{permission:cP,sessionId:Ys}),r.jsx(Zs,{permission:e2,sessionId:Ys})]})}),r.jsx(vt,{title:"Presence Indicators",description:"Viewer avatars with role-based coloring — shown in TopBar when multiple viewers are connected",children:r.jsxs("div",{className:"space-y-4",children:[r.jsx(Le,{label:"Viewers connected (owner, collaborator, spectator)",children:r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("div",{className:"flex items-center -space-x-1.5",children:mg.map(s=>r.jsx("div",{className:`w-6 h-6 rounded-full flex items-center justify-center text-[10px] font-bold border-2 border-cc-card ${s.role==="owner"?"bg-cc-primary/20 text-cc-primary":s.role==="spectator"?"bg-cc-muted/20 text-cc-muted":"bg-cc-success/20 text-cc-success"}`,title:`${s.name} (${s.role})`,children:s.name.charAt(0).toUpperCase()},s.id))}),r.jsxs("div",{className:"text-xs text-cc-muted",children:[mg.length," viewers connected"]})]})}),r.jsx(Le,{label:"Role legend",children:r.jsx("div",{className:"flex items-center gap-4",children:["owner","collaborator","spectator"].map(s=>r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx("div",{className:`w-3 h-3 rounded-full ${s==="owner"?"bg-cc-primary/40":s==="collaborator"?"bg-cc-success/40":"bg-cc-muted/40"}`}),r.jsx("span",{className:"text-[11px] text-cc-fg capitalize",children:s})]},s))})})]})}),r.jsx(vt,{title:"Permission Voting",description:"Multi-viewer vote collection with countdown timer, vote counts, and resolved state",children:r.jsxs("div",{className:"space-y-4",children:[r.jsx(Le,{label:"Active vote (2/3 voted, countdown running)",children:r.jsx("div",{className:"border border-cc-border rounded-xl overflow-hidden bg-cc-card",children:r.jsx(Zs,{permission:i2,sessionId:Ys})})}),r.jsx(Le,{label:"Resolved vote (majority allow)",children:r.jsx("div",{className:"border border-cc-border rounded-xl overflow-hidden bg-cc-card",children:r.jsx(Zs,{permission:a2,sessionId:Ys})})}),r.jsx(Le,{label:"Spectator view (buttons disabled)",children:r.jsx(DP,{})})]})}),r.jsx(vt,{title:"Real Chat Stack",description:"Integrated ChatView using real MessageFeed + PermissionBanner + Composer components",children:r.jsx("div",{"data-testid":"playground-real-chat-stack",className:"max-w-3xl border border-cc-border rounded-xl overflow-hidden bg-cc-card h-[620px]",children:r.jsx(mC,{sessionId:Ys})})}),r.jsx(vt,{title:"Session Replay Controls",description:"Replay player UI — play/pause, speed selector, timeline scrubber, and recording metadata",children:r.jsxs("div",{className:"space-y-4",children:[r.jsx(Le,{label:"Replay controls (idle)",children:r.jsx(qd,{state:"idle",position:0,total:42,speed:1})}),r.jsx(Le,{label:"Replay controls (playing at 4x)",children:r.jsx(qd,{state:"playing",position:18,total:42,speed:4})}),r.jsx(Le,{label:"Replay controls (paused mid-way)",children:r.jsx(qd,{state:"paused",position:30,total:42,speed:2})}),r.jsx(Le,{label:"Replay controls (ended)",children:r.jsx(qd,{state:"ended",position:42,total:42,speed:1})}),r.jsx(Le,{label:"Replay header bar",children:r.jsxs("div",{className:"flex items-center justify-between px-4 py-3 bg-cc-sidebar border border-cc-border rounded-lg",children:[r.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[r.jsx("div",{className:"w-8 h-8 rounded-full bg-cc-primary/10 flex items-center justify-center shrink-0",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-4 h-4 text-cc-primary",children:r.jsx("path",{d:"M4 2l10 6-10 6V2z"})})}),r.jsxs("div",{className:"min-w-0",children:[r.jsx("div",{className:"text-sm font-medium text-cc-fg truncate",children:"Session Replay"}),r.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-cc-muted",children:[r.jsx("span",{className:"px-1.5 py-0.5 bg-cc-hover rounded text-[10px] font-medium",children:"claude"}),r.jsx("span",{children:"claude-sonnet-4-5"}),r.jsx("span",{className:"text-cc-muted/40",children:"|"}),r.jsx("span",{children:"42 messages"})]})]})]}),r.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[r.jsx("button",{className:"p-2 rounded-lg hover:bg-cc-hover text-cc-muted transition-colors cursor-pointer",title:"Share replay link",children:r.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"w-4 h-4",children:[r.jsx("path",{d:"M6 10l4-4M10 10V6H6",strokeLinecap:"round",strokeLinejoin:"round"}),r.jsx("rect",{x:"2",y:"2",width:"12",height:"12",rx:"2"})]})}),r.jsx("button",{className:"p-2 rounded-lg hover:bg-cc-hover text-cc-muted transition-colors cursor-pointer",title:"Close replay",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-4 h-4",children:r.jsx("path",{d:"M4.646 4.646a.5.5 0 01.708 0L8 7.293l2.646-2.647a.5.5 0 01.708.708L8.707 8l2.647 2.646a.5.5 0 01-.708.708L8 8.707l-2.646 2.647a.5.5 0 01-.708-.708L7.293 8 4.646 5.354a.5.5 0 010-.708z"})})})]})]})}),r.jsx(Le,{label:"Fork from message (hover icon)",children:r.jsx("div",{className:"max-w-3xl",children:r.jsx(sr,{message:pg,onFork:()=>{}})})})]})}),r.jsx(vt,{title:"ExitPlanMode",description:"Plan approval request — previously rendered as raw JSON, now shows formatted markdown",children:r.jsx("div",{className:"border border-cc-border rounded-xl overflow-hidden bg-cc-card",children:r.jsx(Zs,{permission:lP,sessionId:Ys})})}),r.jsx(vt,{title:"AskUserQuestion",description:"Interactive questions with selectable options",children:r.jsxs("div",{className:"space-y-4",children:[r.jsx(Le,{label:"Single question",children:r.jsx(Zs,{permission:uP,sessionId:Ys})}),r.jsx(Le,{label:"Multi-question",children:r.jsx(Zs,{permission:dP,sessionId:Ys})})]})}),r.jsx(vt,{title:"Messages",description:"Chat message bubbles for all roles",children:r.jsxs("div",{className:"space-y-4 max-w-3xl",children:[r.jsx(Le,{label:"User message",children:r.jsx(sr,{message:t2})}),r.jsx(Le,{label:"User message with image",children:r.jsx(sr,{message:hP})}),r.jsx(Le,{label:"Assistant message (markdown)",children:r.jsx(sr,{message:pg})}),r.jsx(Le,{label:"Assistant message (with tool calls)",children:r.jsx(sr,{message:s2})}),r.jsx(Le,{label:"Assistant message (thinking block)",children:r.jsx(sr,{message:fP})}),r.jsx(Le,{label:"Tool result with error",children:r.jsx(sr,{message:n2})}),r.jsx(Le,{label:"System message",children:r.jsx(sr,{message:pP})})]})}),r.jsx(vt,{title:"Tool Blocks",description:"Expandable tool call visualization",children:r.jsxs("div",{className:"space-y-2 max-w-3xl",children:[r.jsx(mn,{name:"Bash",input:{command:"git status && npm run lint",description:"Check git status and lint"},toolUseId:"tb-1"}),r.jsx(mn,{name:"Read",input:{file_path:"/Users/stan/Dev/project/src/index.ts",offset:10,limit:50},toolUseId:"tb-2"}),r.jsx(mn,{name:"Edit",input:{file_path:"src/utils.ts",old_string:"const x = 1;",new_string:"const x = 2;",replace_all:!0},toolUseId:"tb-3"}),r.jsx(mn,{name:"Write",input:{file_path:"src/new-file.ts",content:`export const hello = "world";
|
|
195
195
|
`},toolUseId:"tb-4"}),r.jsx(mn,{name:"Glob",input:{pattern:"**/*.tsx",path:"/Users/stan/Dev/project/src"},toolUseId:"tb-5"}),r.jsx(mn,{name:"Grep",input:{pattern:"useEffect",path:"src/",glob:"*.tsx",output_mode:"content",context:3,head_limit:20},toolUseId:"tb-6"}),r.jsx(mn,{name:"WebSearch",input:{query:"React 19 new features",allowed_domains:["react.dev","github.com"]},toolUseId:"tb-7"}),r.jsx(mn,{name:"WebFetch",input:{url:"https://react.dev/blog/2024/12/05/react-19",prompt:"Summarize the key changes in React 19"},toolUseId:"tb-8"}),r.jsx(mn,{name:"Task",input:{description:"Search for auth patterns",subagent_type:"Explore",prompt:"Find all files related to authentication and authorization in the codebase. Look for middleware, guards, and token handling."},toolUseId:"tb-9"}),r.jsx(mn,{name:"TodoWrite",input:{todos:[{content:"Create JWT utility module",status:"completed",activeForm:"Creating JWT module"},{content:"Update auth middleware",status:"in_progress",activeForm:"Updating middleware"},{content:"Migrate login endpoint",status:"pending",activeForm:"Migrating login"},{content:"Run full test suite",status:"pending",activeForm:"Running tests"}]},toolUseId:"tb-10"}),r.jsx(mn,{name:"NotebookEdit",input:{notebook_path:"/Users/stan/Dev/project/analysis.ipynb",cell_type:"code",edit_mode:"replace",cell_number:3,new_source:`import pandas as pd
|
|
196
196
|
df = pd.read_csv('data.csv')
|
|
197
|
-
df.describe()`},toolUseId:"tb-11"}),r.jsx(mn,{name:"SendMessage",input:{type:"message",recipient:"researcher",content:"Please investigate the auth module structure and report back.",summary:"Requesting auth module investigation"},toolUseId:"tb-12"})]})}),r.jsx(vt,{title:"Tool Progress",description:"Real-time progress indicator shown while tools are running",children:r.jsxs("div",{className:"space-y-4 max-w-3xl",children:[r.jsx(Le,{label:"Single tool running",children:r.jsxs("div",{className:"flex items-center gap-1.5 text-[11px] text-cc-muted font-mono-code pl-9",children:[r.jsx("span",{className:"inline-block w-1.5 h-1.5 rounded-full bg-cc-primary animate-pulse"}),r.jsx("span",{children:"Terminal"}),r.jsx("span",{className:"text-cc-muted/60",children:"8s"})]})}),r.jsx(Le,{label:"Multiple tools running",children:r.jsxs("div",{className:"flex items-center gap-1.5 text-[11px] text-cc-muted font-mono-code pl-9",children:[r.jsx("span",{className:"inline-block w-1.5 h-1.5 rounded-full bg-cc-primary animate-pulse"}),r.jsx("span",{children:"Search Content"}),r.jsx("span",{className:"text-cc-muted/60",children:"3s"}),r.jsx("span",{className:"text-cc-muted/40",children:"·"}),r.jsx("span",{children:"Find Files"}),r.jsx("span",{className:"text-cc-muted/60",children:"2s"})]})})]})}),r.jsx(vt,{title:"Tool Use Summary",description:"System message summarizing batch tool execution",children:r.jsx("div",{className:"space-y-4 max-w-3xl",children:r.jsx(Le,{label:"Summary as system message",children:r.jsx(sr,{message:{id:"summary-1",role:"system",content:"Read 4 files, searched 12 matches across 3 directories",timestamp:Date.now()}})})})}),r.jsx(vt,{title:"Tasks",description:"Task list states: pending, in progress, completed, blocked",children:r.jsxs("div",{className:"w-[280px] border border-cc-border rounded-xl overflow-hidden bg-cc-card",children:[r.jsxs("div",{className:"px-4 py-3 border-b border-cc-border space-y-2.5",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-[11px] text-cc-muted uppercase tracking-wider",children:"Cost"}),r.jsx("span",{className:"text-[13px] font-medium text-cc-fg tabular-nums",children:"$0.1847"})]}),r.jsxs("div",{className:"space-y-1",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-[11px] text-cc-muted uppercase tracking-wider",children:"Context"}),r.jsx("span",{className:"text-[11px] text-cc-muted tabular-nums",children:"62%"})]}),r.jsx("div",{className:"w-full h-1.5 rounded-full bg-cc-hover overflow-hidden",children:r.jsx("div",{className:"h-full rounded-full bg-cc-warning transition-all duration-500",style:{width:"62%"}})})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-[11px] text-cc-muted uppercase tracking-wider",children:"Turns"}),r.jsx("span",{className:"text-[13px] font-medium text-cc-fg tabular-nums",children:"14"})]})]}),r.jsxs("div",{className:"px-4 py-2.5 border-b border-cc-border flex items-center justify-between",children:[r.jsx("span",{className:"text-[12px] font-semibold text-cc-fg",children:"Tasks"}),r.jsxs("span",{className:"text-[11px] text-cc-muted tabular-nums",children:["2/",r2.length]})]}),r.jsx("div",{className:"px-3 py-2 space-y-0.5",children:r2.map(s=>r.jsx(DP,{task:s},s.id))})]})}),r.jsx(vt,{title:"Session Pulse",description:"Unified floating activity widget — combines per-session agent/task tracking with cross-session awareness. Two tabs: Agents (current session subagents + tasks) and Sessions (other running sessions).",children:r.jsxs("div",{className:"space-y-4 max-w-3xl",children:[r.jsx(Le,{label:"Trigger pill — agents + sessions active",children:r.jsx("div",{className:"relative h-14 bg-cc-bg rounded-lg border border-cc-border/30 flex items-end justify-end p-3",children:r.jsxs("div",{className:"flex items-center gap-2 px-3 h-8 rounded-full border border-cc-border/50 bg-cc-card/90 backdrop-blur-lg shadow-panel",children:[r.jsxs("span",{className:"relative flex h-2 w-2",children:[r.jsx("span",{className:"absolute inset-0 rounded-full bg-cc-primary opacity-75 animate-ping"}),r.jsx("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-cc-primary"})]}),r.jsx("span",{className:"text-[11px] font-medium text-cc-fg/80 font-mono-code",children:"2 agents · 1 tool · 3/5 · 1 session"}),r.jsx("span",{className:"flex items-center justify-center min-w-[16px] h-4 px-1 rounded-full bg-cc-warning/15 text-cc-warning text-[9px] font-semibold",children:"1"}),r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 text-cc-muted/60",children:r.jsx("path",{d:"M4.427 9.573l3.396-3.396a.25.25 0 01.354 0l3.396 3.396a.25.25 0 01-.177.427H4.604a.25.25 0 01-.177-.427z"})})]})})}),r.jsx(Le,{label:"Activity tab — agents, tools, and tasks (all backends)",children:r.jsxs("div",{className:"w-80 rounded-xl border border-cc-border/60 bg-cc-card/95 shadow-float overflow-hidden",children:[r.jsxs("div",{className:"flex items-center gap-1 px-2 pt-2 pb-1 border-b border-cc-border/40",children:[r.jsxs("span",{className:"px-2.5 py-1 rounded-md text-[10px] font-semibold uppercase tracking-wider bg-cc-primary/10 text-cc-primary",children:["Activity ",r.jsx("span",{className:"ml-1 text-[9px] tabular-nums opacity-70",children:"5"})]}),r.jsxs("span",{className:"px-2.5 py-1 rounded-md text-[10px] font-semibold uppercase tracking-wider text-cc-muted hover:text-cc-fg cursor-pointer",children:["Sessions ",r.jsx("span",{className:"ml-1 text-[9px] tabular-nums opacity-70",children:"1"})]}),r.jsx("div",{className:"flex-1"}),r.jsx("span",{className:"p-1 rounded hover:bg-cc-hover cursor-pointer",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 text-cc-muted",children:r.jsx("path",{d:"M4.28 3.22a.75.75 0 00-1.06 1.06L6.94 8l-3.72 3.72a.75.75 0 101.06 1.06L8 9.06l3.72 3.72a.75.75 0 101.06-1.06L9.06 8l3.72-3.72a.75.75 0 00-1.06-1.06L8 6.94 4.28 3.22z"})})})]}),r.jsxs("div",{className:"py-1.5",children:[r.jsx("div",{className:"px-3 py-1",children:r.jsx("span",{className:"text-[9px] text-cc-muted/50 uppercase tracking-widest font-semibold",children:"Agents"})}),r.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-1.5",children:[r.jsxs("span",{className:"relative flex h-1.5 w-1.5 shrink-0",children:[r.jsx("span",{className:"absolute inset-0 rounded-full bg-cc-primary opacity-75 animate-breathing"}),r.jsx("span",{className:"relative inline-flex rounded-full h-1.5 w-1.5 bg-cc-primary"})]}),r.jsx("div",{className:"flex-1 min-w-0",children:r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:"text-[11px] font-medium text-cc-fg truncate",children:"Search codebase for utils"}),r.jsx("span",{className:"text-[8px] text-cc-muted/40 uppercase font-mono-code",children:"Explore"})]})}),r.jsx("span",{className:"text-[10px] text-cc-muted/50 font-mono-code tabular-nums shrink-0",children:"32s"})]}),r.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-1.5",children:[r.jsx("span",{className:"relative flex h-1.5 w-1.5 shrink-0",children:r.jsx("span",{className:"relative inline-flex rounded-full h-1.5 w-1.5 bg-cc-success"})}),r.jsx("div",{className:"flex-1 min-w-0",children:r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:"text-[11px] font-medium text-cc-fg/60 truncate",children:"Analyze test coverage"}),r.jsx("span",{className:"text-[8px] text-cc-muted/40 uppercase font-mono-code",children:"general-purpose"})]})}),r.jsx("span",{className:"text-[10px] text-cc-muted/50 font-mono-code tabular-nums shrink-0",children:"1m 14s"})]}),r.jsx("hr",{className:"mx-3 my-1.5 border-t border-cc-border/30 border-b-0 border-x-0"}),r.jsx("div",{className:"px-3 py-1",children:r.jsx("span",{className:"text-[9px] text-cc-muted/50 uppercase tracking-widest font-semibold",children:"Tools"})}),r.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-1.5",children:[r.jsxs("svg",{className:"w-3.5 h-3.5 text-cc-primary animate-spin shrink-0",viewBox:"0 0 16 16",fill:"none",children:[r.jsx("circle",{cx:"8",cy:"8",r:"6",stroke:"currentColor",strokeWidth:"2",opacity:"0.25"}),r.jsx("path",{d:"M14 8a6 6 0 00-6-6",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]}),r.jsx("span",{className:"text-[11px] font-medium text-cc-fg truncate flex-1",children:"Bash"}),r.jsx("span",{className:"text-[10px] text-cc-muted/50 font-mono-code tabular-nums shrink-0",children:"8s"})]}),r.jsx("hr",{className:"mx-3 my-1.5 border-t border-cc-border/30 border-b-0 border-x-0"}),r.jsx("div",{className:"px-3 py-1",children:r.jsx("span",{className:"text-[9px] text-cc-muted/50 uppercase tracking-widest font-semibold",children:"Tasks"})}),r.jsxs("div",{className:"flex items-center gap-2 px-3 py-1",children:[r.jsx("svg",{className:"w-3.5 h-3.5 text-cc-success shrink-0",viewBox:"0 0 16 16",fill:"currentColor",children:r.jsx("path",{d:"M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"})}),r.jsx("span",{className:"text-[11px] text-cc-muted/50 line-through truncate",children:"Set up test infrastructure"})]}),r.jsxs("div",{className:"flex items-center gap-2 px-3 py-1",children:[r.jsxs("svg",{className:"w-3.5 h-3.5 text-cc-primary animate-spin shrink-0",viewBox:"0 0 16 16",fill:"none",children:[r.jsx("circle",{cx:"8",cy:"8",r:"6",stroke:"currentColor",strokeWidth:"2",opacity:"0.25"}),r.jsx("path",{d:"M14 8a6 6 0 00-6-6",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("span",{className:"text-[11px] text-cc-fg truncate block",children:"Write unit tests for API"}),r.jsx("span",{className:"text-[10px] text-cc-muted/50 italic truncate block",children:"Writing unit tests for API"})]})]}),r.jsxs("div",{className:"flex items-center gap-2 px-3 py-1",children:[r.jsx("svg",{className:"w-3.5 h-3.5 text-cc-muted/30 shrink-0",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:r.jsx("circle",{cx:"8",cy:"8",r:"5.5"})}),r.jsx("span",{className:"text-[11px] text-cc-fg truncate",children:"Run integration tests"})]})]})]})}),r.jsx(Le,{label:"Sessions tab — cross-session awareness",children:r.jsxs("div",{className:"w-80 rounded-xl border border-cc-border/60 bg-cc-card/95 shadow-float overflow-hidden",children:[r.jsxs("div",{className:"flex items-center gap-1 px-2 pt-2 pb-1 border-b border-cc-border/40",children:[r.jsxs("span",{className:"px-2.5 py-1 rounded-md text-[10px] font-semibold uppercase tracking-wider text-cc-muted hover:text-cc-fg cursor-pointer",children:["Activity ",r.jsx("span",{className:"ml-1 text-[9px] tabular-nums opacity-70",children:"5"})]}),r.jsxs("span",{className:"px-2.5 py-1 rounded-md text-[10px] font-semibold uppercase tracking-wider bg-cc-primary/10 text-cc-primary",children:["Sessions ",r.jsx("span",{className:"ml-1 text-[9px] tabular-nums opacity-70",children:"2"})]}),r.jsx("div",{className:"flex-1"}),r.jsx("span",{className:"p-1 rounded hover:bg-cc-hover cursor-pointer",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 text-cc-muted",children:r.jsx("path",{d:"M4.28 3.22a.75.75 0 00-1.06 1.06L6.94 8l-3.72 3.72a.75.75 0 101.06 1.06L8 9.06l3.72 3.72a.75.75 0 101.06-1.06L9.06 8l3.72-3.72a.75.75 0 00-1.06-1.06L8 6.94 4.28 3.22z"})})})]}),r.jsxs("div",{className:"py-1",children:[r.jsxs("div",{className:"w-full flex items-center gap-2.5 px-3 py-2 hover:bg-cc-hover/60 transition-colors text-left cursor-pointer group",children:[r.jsxs("span",{className:"relative flex h-1.5 w-1.5 shrink-0",children:[r.jsx("span",{className:"absolute inset-0 rounded-full bg-cc-primary opacity-75 animate-breathing"}),r.jsx("span",{className:"relative inline-flex rounded-full h-1.5 w-1.5 bg-cc-primary"})]}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("span",{className:"text-[11px] font-medium text-cc-fg truncate block",children:"Refactor API layer"}),r.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[r.jsx("span",{className:"text-[10px] text-cc-muted/50 font-mono-code tabular-nums",children:"4m 23s"}),r.jsx("span",{className:"text-[10px] text-cc-muted/50 font-mono-code tabular-nums",children:"$0.12"})]})]}),r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 text-cc-muted/30 group-hover:text-cc-primary/60 transition-colors shrink-0",children:r.jsx("path",{d:"M8.22 2.97a.75.75 0 011.06 0l4.25 4.25a.75.75 0 010 1.06l-4.25 4.25a.75.75 0 01-1.06-1.06l2.97-2.97H3.75a.75.75 0 010-1.5h7.44L8.22 4.03a.75.75 0 010-1.06z"})})]}),r.jsxs("div",{className:"w-full flex items-center gap-2.5 px-3 py-2 hover:bg-cc-hover/60 transition-colors text-left cursor-pointer group",children:[r.jsxs("span",{className:"relative flex h-1.5 w-1.5 shrink-0",children:[r.jsx("span",{className:"absolute inset-0 rounded-full bg-cc-primary opacity-75 animate-breathing"}),r.jsx("span",{className:"relative inline-flex rounded-full h-1.5 w-1.5 bg-cc-primary"})]}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("span",{className:"text-[11px] font-medium text-cc-fg truncate block",children:"Write unit tests"}),r.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[r.jsx("span",{className:"text-[10px] text-cc-muted/50 font-mono-code tabular-nums",children:"1m 47s"}),r.jsx("span",{className:"text-[10px] text-cc-muted/50 font-mono-code tabular-nums",children:"$0.08"})]})]}),r.jsxs("span",{className:"flex items-center gap-1 px-1.5 py-0.5 rounded-full bg-cc-warning/10 shrink-0",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-2.5 h-2.5 text-cc-warning",children:r.jsx("path",{d:"M8.22 1.754a.25.25 0 00-.44 0L1.698 13.132a.25.25 0 00.22.368h12.164a.25.25 0 00.22-.368L8.22 1.754zm-1.763-.707c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0114.082 15H1.918a1.75 1.75 0 01-1.543-2.575L6.457 1.047zM9 11a1 1 0 11-2 0 1 1 0 012 0zm-.25-5.25a.75.75 0 00-1.5 0v2.5a.75.75 0 001.5 0v-2.5z"})}),r.jsx("span",{className:"text-[9px] font-semibold text-cc-warning tabular-nums",children:"1"})]}),r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 text-cc-muted/30 group-hover:text-cc-primary/60 transition-colors shrink-0",children:r.jsx("path",{d:"M8.22 2.97a.75.75 0 011.06 0l4.25 4.25a.75.75 0 010 1.06l-4.25 4.25a.75.75 0 01-1.06-1.06l2.97-2.97H3.75a.75.75 0 010-1.5h7.44L8.22 4.03a.75.75 0 010-1.06z"})})]})]})]})})]})}),r.jsx(vt,{title:"Environment Detection",description:"Detected project services and missing environment variables shown in the session panel",children:r.jsx(Le,{label:"Detected Next.js, Prisma, and Stripe",children:r.jsx("div",{className:"w-[280px] border border-cc-border rounded-xl overflow-hidden bg-cc-bg py-1",children:r.jsx(_C,{detected:{cwd:"/Users/stan/Dev/project",scannedAt:Date.now(),mcpServers:{},rules:[{id:"vercel",name:"Vercel",description:"Vercel or Next.js deployment target detected."},{id:"prisma",name:"Prisma",description:"Prisma schema or dependency detected.",envRequired:["DATABASE_URL"],envMissing:["DATABASE_URL"],envPresent:[]},{id:"stripe",name:"Stripe",description:"Stripe SDK or secret key detected.",envRequired:["STRIPE_SECRET_KEY"],envPresent:["STRIPE_SECRET_KEY"],envMissing:[]}]}})})})}),r.jsx(vt,{title:"Cost Card",description:"Shareable session summary card with key metrics and PNG export",children:r.jsxs("div",{className:"space-y-4",children:[r.jsx(Le,{label:"Completed session with cost",children:r.jsx("div",{className:"w-[280px] border border-cc-border rounded-xl overflow-hidden bg-cc-card",children:r.jsx(Mx,{sessionName:"Implement auth flow",cost:.2847,turns:14,durationMs:12*6e4,model:"claude-opus-4-6",backend:"claude",linesAdded:342,linesRemoved:87})})}),r.jsx(Le,{label:"Low-cost quick task",children:r.jsx("div",{className:"w-[280px] border border-cc-border rounded-xl overflow-hidden bg-cc-card",children:r.jsx(Mx,{sessionName:"Fix typo in README",cost:.0043,turns:2,durationMs:45e3,model:"claude-sonnet-4-5-20250929",backend:"claude",linesAdded:1,linesRemoved:1})})})]})}),r.jsx(vt,{title:"GitHub PR Status",description:"PR health shown in the TaskPanel — checks, reviews, unresolved comments",children:r.jsxs("div",{className:"space-y-4",children:[r.jsx(Le,{label:"Open PR — failing checks + changes requested",children:r.jsx("div",{className:"w-[280px] border border-cc-border rounded-xl overflow-hidden bg-cc-card",children:r.jsx(Nc,{pr:gP})})}),r.jsx(Le,{label:"Open PR — all checks passed + approved",children:r.jsx("div",{className:"w-[280px] border border-cc-border rounded-xl overflow-hidden bg-cc-card",children:r.jsx(Nc,{pr:xP})})}),r.jsx(Le,{label:"Draft PR — pending checks",children:r.jsx("div",{className:"w-[280px] border border-cc-border rounded-xl overflow-hidden bg-cc-card",children:r.jsx(Nc,{pr:vP})})}),r.jsx(Le,{label:"Merged PR",children:r.jsx("div",{className:"w-[280px] border border-cc-border rounded-xl overflow-hidden bg-cc-card",children:r.jsx(Nc,{pr:bP})})})]})}),r.jsx(vt,{title:"MCP Servers",description:"MCP server status display with toggle, reconnect, and tool listing",children:r.jsx("div",{className:"space-y-4",children:r.jsx(Le,{label:"All server states (connected, failed, disabled, connecting)",children:r.jsxs("div",{className:"w-[280px] border border-cc-border rounded-xl overflow-hidden bg-cc-card",children:[r.jsxs("div",{className:"shrink-0 px-4 py-2.5 border-b border-cc-border flex items-center justify-between",children:[r.jsxs("span",{className:"text-[12px] font-semibold text-cc-fg flex items-center gap-1.5",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 text-cc-muted",children:r.jsx("path",{d:"M1.5 3A1.5 1.5 0 013 1.5h10A1.5 1.5 0 0114.5 3v1A1.5 1.5 0 0113 5.5H3A1.5 1.5 0 011.5 4V3zm0 5A1.5 1.5 0 013 6.5h10A1.5 1.5 0 0114.5 8v1A1.5 1.5 0 0113 10.5H3A1.5 1.5 0 011.5 9V8zm0 5A1.5 1.5 0 013 11.5h10a1.5 1.5 0 011.5 1.5v1a1.5 1.5 0 01-1.5 1.5H3A1.5 1.5 0 011.5 14v-1z"})}),"MCP Servers"]}),r.jsx("span",{className:"text-[11px] text-cc-muted",children:r.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"w-3.5 h-3.5",children:[r.jsx("path",{d:"M2.5 8a5.5 5.5 0 019.78-3.5M13.5 8a5.5 5.5 0 01-9.78 3.5",strokeLinecap:"round"}),r.jsx("path",{d:"M12.5 2v3h-3M3.5 14v-3h3",strokeLinecap:"round",strokeLinejoin:"round"})]})})]}),r.jsx("div",{className:"px-3 py-2 space-y-1.5",children:SP.map(s=>r.jsx(AP,{server:s},s.name))})]})})})}),r.jsx(vt,{title:"Codex Session Details",description:"Rate limits and token details for Codex (OpenAI) sessions — streamed via session_update",children:r.jsx("div",{className:"space-y-4",children:r.jsx(Le,{label:"Rate limits with token breakdown",children:r.jsx(EP,{})})})}),r.jsx(vt,{title:"Claude Session Details",description:"Token usage and cost for Claude Code sessions — updated at turn end from modelUsage",children:r.jsx("div",{className:"space-y-4",children:r.jsx(Le,{label:"Token breakdown with cost",children:r.jsx(MP,{})})})}),r.jsx(vt,{title:"Update Banner",description:"Notification banner for available updates",children:r.jsxs("div",{className:"space-y-4 max-w-3xl",children:[r.jsx(Le,{label:"Service mode (auto-update)",children:r.jsx(gg,{updateInfo:{currentVersion:"0.22.1",latestVersion:"0.23.0",updateAvailable:!0,isServiceMode:!0,updateInProgress:!1,lastChecked:Date.now()}})}),r.jsx(Le,{label:"Foreground mode (manual)",children:r.jsx(gg,{updateInfo:{currentVersion:"0.22.1",latestVersion:"0.23.0",updateAvailable:!0,isServiceMode:!1,updateInProgress:!1,lastChecked:Date.now()}})}),r.jsx(Le,{label:"Update in progress",children:r.jsx(gg,{updateInfo:{currentVersion:"0.22.1",latestVersion:"0.23.0",updateAvailable:!0,isServiceMode:!0,updateInProgress:!0,lastChecked:Date.now()}})})]})}),r.jsx(vt,{title:"Status Indicators",description:"Connection and session status banners",children:r.jsxs("div",{className:"space-y-3 max-w-3xl",children:[r.jsx(Le,{label:"Disconnected warning",children:r.jsx("div",{className:"px-4 py-2 bg-cc-warning/10 border border-cc-warning/20 rounded-lg text-center",children:r.jsx("span",{className:"text-xs text-cc-warning font-medium",children:"Reconnecting to session..."})})}),r.jsx(Le,{label:"Connected",children:r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 bg-cc-card border border-cc-border rounded-lg",children:[r.jsx("span",{className:"w-2 h-2 rounded-full bg-cc-success"}),r.jsx("span",{className:"text-xs text-cc-fg font-medium",children:"Connected"}),r.jsx("span",{className:"text-[11px] text-cc-muted ml-auto",children:"claude-opus-4-6"})]})}),r.jsx(Le,{label:"Running / Thinking",children:r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 bg-cc-card border border-cc-border rounded-lg",children:[r.jsx("span",{className:"w-2 h-2 rounded-full bg-cc-primary animate-[pulse-dot_1.5s_ease-in-out_infinite]"}),r.jsx("span",{className:"text-xs text-cc-fg font-medium",children:"Thinking"})]})}),r.jsx(Le,{label:"Compacting",children:r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 bg-cc-card border border-cc-border rounded-lg",children:[r.jsx("svg",{className:"w-3.5 h-3.5 text-cc-muted animate-spin",viewBox:"0 0 16 16",fill:"none",children:r.jsx("circle",{cx:"8",cy:"8",r:"6",stroke:"currentColor",strokeWidth:"1.5",strokeDasharray:"28",strokeDashoffset:"8",strokeLinecap:"round"})}),r.jsx("span",{className:"text-xs text-cc-muted font-medium",children:"Compacting context..."})]})})]})}),r.jsx(vt,{title:"Session Items",description:"Sidebar session items with status-first layout, model badges, and hover-revealed git stats",children:r.jsxs("div",{className:"max-w-xs space-y-1 bg-cc-bg p-2 rounded-lg border border-cc-border",children:[r.jsx("div",{className:"relative group",children:r.jsxs("div",{className:"w-full pl-3.5 pr-8 py-2.5 sm:py-2 text-left rounded-lg bg-cc-active",children:[r.jsx("span",{className:"absolute left-0 top-1.5 bottom-1.5 w-[3px] rounded-full bg-cc-success animate-[pulse-dot_1.5s_ease-in-out_infinite] opacity-100"}),r.jsxs("div",{className:"flex flex-col gap-0.5 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:"text-[13px] font-medium truncate text-cc-fg leading-snug",children:"Refactor auth module"}),r.jsx("span",{className:"text-[9px] font-medium px-1.5 rounded-full leading-[16px] shrink-0 text-[#5BA8A0] bg-[#5BA8A0]/10",children:"Sonnet"})]}),r.jsxs("div",{className:"flex items-center gap-1 text-[10.5px] text-cc-muted leading-tight truncate",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-2.5 h-2.5 shrink-0 opacity-50",children:r.jsx("path",{d:"M11.75 2.5a.75.75 0 100 1.5.75.75 0 000-1.5zm-2.116.862a2.25 2.25 0 10-.862.862A4.48 4.48 0 007.25 7.5h-1.5A2.25 2.25 0 003.5 9.75v.318a2.25 2.25 0 101.5 0V9.75a.75.75 0 01.75-.75h1.5a5.98 5.98 0 003.884-1.435A2.25 2.25 0 109.634 3.362zM4.25 12a.75.75 0 100 1.5.75.75 0 000-1.5z"})}),r.jsx("span",{className:"truncate",children:"feat/auth-jwt"})]}),r.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-cc-muted",children:[r.jsx("span",{className:"flex items-center gap-0.5",children:r.jsx("span",{className:"text-green-500",children:"2↑"})}),r.jsxs("span",{className:"flex items-center gap-1 shrink-0",children:[r.jsx("span",{className:"text-green-500",children:"+48"}),r.jsx("span",{className:"text-red-400",children:"-12"})]})]})]})]})}),r.jsx("div",{className:"relative group",children:r.jsxs("div",{className:"w-full pl-3.5 pr-8 py-2.5 sm:py-2 text-left rounded-lg hover:bg-cc-hover",children:[r.jsx("span",{className:"absolute left-0 top-1.5 bottom-1.5 w-[3px] rounded-full bg-cc-success/60 opacity-60"}),r.jsxs("div",{className:"flex flex-col gap-0.5 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:"text-[13px] font-medium truncate text-cc-fg leading-snug",children:"Fix CI pipeline"}),r.jsx("span",{className:"text-[9px] font-medium px-1.5 rounded-full leading-[16px] shrink-0 text-blue-400 bg-blue-500/10",children:"Codex"})]}),r.jsxs("div",{className:"flex items-center gap-1 text-[10.5px] text-cc-muted leading-tight truncate",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-2.5 h-2.5 shrink-0 opacity-50",children:r.jsx("path",{d:"M11.75 2.5a.75.75 0 100 1.5.75.75 0 000-1.5zm-2.116.862a2.25 2.25 0 10-.862.862A4.48 4.48 0 007.25 7.5h-1.5A2.25 2.25 0 003.5 9.75v.318a2.25 2.25 0 101.5 0V9.75a.75.75 0 01.75-.75h1.5a5.98 5.98 0 003.884-1.435A2.25 2.25 0 109.634 3.362zM4.25 12a.75.75 0 100 1.5.75.75 0 000-1.5z"})}),r.jsx("span",{className:"truncate",children:"main"})]})]})]})}),r.jsxs("div",{className:"relative group",children:[r.jsxs("div",{className:"w-full pl-3.5 pr-8 py-2.5 sm:py-2 text-left rounded-lg hover:bg-cc-hover",children:[r.jsx("span",{className:"absolute left-0 top-1.5 bottom-1.5 w-[3px] rounded-full bg-cc-warning animate-[pulse-dot_1.5s_ease-in-out_infinite] opacity-100"}),r.jsx("div",{className:"flex flex-col gap-0.5 min-w-0",children:r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:"text-[13px] font-medium truncate text-cc-fg leading-snug",children:"Update dependencies"}),r.jsx("span",{className:"text-[9px] font-medium px-1.5 rounded-full leading-[16px] shrink-0 text-[#5BA8A0] bg-[#5BA8A0]/10",children:"Opus"})]})})]}),r.jsx("span",{className:"absolute right-2 top-1/2 -translate-y-1/2 min-w-[18px] h-[18px] flex items-center justify-center rounded-full bg-cc-warning text-white text-[10px] font-bold leading-none px-1",children:"2"})]}),r.jsx("div",{className:"relative group",children:r.jsxs("div",{className:"w-full pl-3.5 pr-8 py-2.5 sm:py-2 text-left rounded-lg hover:bg-cc-hover",children:[r.jsx("span",{className:"absolute left-0 top-1.5 bottom-1.5 w-[3px] rounded-full bg-cc-muted/30 opacity-60"}),r.jsx("div",{className:"flex flex-col gap-0.5 min-w-0",children:r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:"text-[13px] font-medium truncate text-cc-fg leading-snug",children:"Add dark mode toggle"}),r.jsx("span",{className:"text-[9px] font-medium px-1.5 rounded-full leading-[16px] shrink-0 text-[#5BA8A0] bg-[#5BA8A0]/10",children:"Haiku"})]})})]})})]})}),r.jsx(vt,{title:"Session Launch Overlay",description:"Container session creation progress with step indicators and progress bar",children:r.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[r.jsx(Le,{label:"In progress — pulling image",children:r.jsxs("div",{className:"relative rounded-xl border border-neutral-200 bg-white p-6 dark:border-neutral-700 dark:bg-neutral-900",children:[r.jsx("h3",{className:"mb-4 text-lg font-semibold text-neutral-900 dark:text-neutral-100",children:"Launching Container Session"}),r.jsx("div",{className:"mb-4 space-y-2",children:["Checking image","Pulling image","Creating container","Seeding authentication","Launching agent"].map((s,n)=>r.jsxs("div",{className:`flex items-center gap-2 text-sm ${n<1?"text-green-600 dark:text-green-400":n===1?"font-medium text-blue-600 dark:text-blue-400":"text-neutral-400 dark:text-neutral-600"}`,children:[n<1?r.jsx("svg",{className:"h-4 w-4 flex-shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}):n===1?r.jsxs("svg",{className:"h-4 w-4 flex-shrink-0 animate-spin",fill:"none",viewBox:"0 0 24 24",children:[r.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),r.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}):r.jsx("div",{className:"h-4 w-4 flex-shrink-0 rounded-full border border-neutral-300 dark:border-neutral-600"}),r.jsx("span",{children:s})]},s))}),r.jsxs("div",{className:"mb-3",children:[r.jsx("div",{className:"h-2 overflow-hidden rounded-full bg-neutral-200 dark:bg-neutral-700",children:r.jsx("div",{className:"h-full rounded-full bg-blue-600 transition-all duration-300",style:{width:"63%"}})}),r.jsx("p",{className:"mt-1 text-xs text-neutral-500",children:"63%"})]}),r.jsx("p",{className:"text-xs text-neutral-500 dark:text-neutral-400 truncate",children:"Downloading layer sha256:a1b2c3d4..."})]})}),r.jsx(Le,{label:"Error state",children:r.jsxs("div",{className:"relative rounded-xl border border-neutral-200 bg-white p-6 dark:border-neutral-700 dark:bg-neutral-900",children:[r.jsxs("div",{className:"mb-4 flex items-center gap-2 text-red-600 dark:text-red-400",children:[r.jsx("svg",{className:"h-5 w-5 flex-shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L4.082 16.5c-.77.833.192 2.5 1.732 2.5z"})}),r.jsx("h3",{className:"text-lg font-semibold",children:"Container Launch Failed"})]}),r.jsx("p",{className:"mb-4 text-sm text-neutral-600 dark:text-neutral-400",children:"Failed to pull image campfire-dev:latest — connection timed out"}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("button",{className:"flex-1 rounded-lg bg-blue-600 px-4 py-2 text-sm font-medium text-white hover:bg-blue-700",children:"Retry"}),r.jsx("button",{className:"flex-1 rounded-lg border border-neutral-300 px-4 py-2 text-sm font-medium text-neutral-700 hover:bg-neutral-100 dark:border-neutral-600 dark:text-neutral-300 dark:hover:bg-neutral-800",children:"Cancel"})]})]})})]})}),r.jsx(vt,{title:"Composer",description:"Message input bar with mode toggle, image upload, and send/stop buttons",children:r.jsxs("div",{className:"max-w-3xl",children:[r.jsx(Le,{label:"Connected — code mode",children:r.jsx("div",{className:"border-t border-cc-border bg-cc-card px-4 py-3",children:r.jsxs("div",{className:"bg-cc-input-bg border border-cc-border rounded-xl overflow-hidden",children:[r.jsx("textarea",{readOnly:!0,value:"Can you refactor the auth module to use JWT?",rows:1,className:"w-full px-4 pt-3 pb-1 text-sm bg-transparent resize-none text-cc-fg font-sans-ui",style:{minHeight:"36px"}}),r.jsxs("div",{className:"flex items-center justify-between px-2.5 pb-2.5",children:[r.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1 rounded-md text-[12px] font-medium text-cc-muted",children:[r.jsxs("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:[r.jsx("path",{d:"M2.5 4l4 4-4 4",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),r.jsx("path",{d:"M8.5 4l4 4-4 4",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]}),r.jsx("span",{children:"code"})]}),r.jsxs("div",{className:"flex items-center gap-1",children:[r.jsx("div",{className:"flex items-center justify-center w-8 h-8 rounded-lg text-cc-muted",children:r.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"w-4 h-4",children:[r.jsx("rect",{x:"2",y:"2",width:"12",height:"12",rx:"2"}),r.jsx("circle",{cx:"5.5",cy:"5.5",r:"1",fill:"currentColor",stroke:"none"}),r.jsx("path",{d:"M2 11l3-3 2 2 3-4 4 5",strokeLinecap:"round",strokeLinejoin:"round"})]})}),r.jsx("div",{className:"flex items-center justify-center w-8 h-8 rounded-full bg-cc-primary text-white",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:r.jsx("path",{d:"M3 2l11 6-11 6V9.5l7-1.5-7-1.5V2z"})})})]})]})]})})}),r.jsx("div",{className:"mt-4"}),r.jsx(Le,{label:"Plan mode active",children:r.jsx("div",{className:"border-t border-cc-border bg-cc-card px-4 py-3",children:r.jsxs("div",{className:"bg-cc-input-bg border border-cc-primary/40 rounded-xl overflow-hidden",children:[r.jsx("textarea",{readOnly:!0,value:"",placeholder:"Type a message... (/ for commands)",rows:1,className:"w-full px-4 pt-3 pb-1 text-sm bg-transparent resize-none text-cc-fg font-sans-ui placeholder:text-cc-muted",style:{minHeight:"36px"}}),r.jsxs("div",{className:"flex items-center justify-between px-2.5 pb-2.5",children:[r.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1 rounded-md text-[12px] font-medium text-cc-primary",children:[r.jsxs("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:[r.jsx("rect",{x:"3",y:"3",width:"3.5",height:"10",rx:"0.75"}),r.jsx("rect",{x:"9.5",y:"3",width:"3.5",height:"10",rx:"0.75"})]}),r.jsx("span",{children:"plan"})]}),r.jsxs("div",{className:"flex items-center gap-1",children:[r.jsx("div",{className:"flex items-center justify-center w-8 h-8 rounded-lg text-cc-muted",children:r.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"w-4 h-4",children:[r.jsx("rect",{x:"2",y:"2",width:"12",height:"12",rx:"2"}),r.jsx("circle",{cx:"5.5",cy:"5.5",r:"1",fill:"currentColor",stroke:"none"}),r.jsx("path",{d:"M2 11l3-3 2 2 3-4 4 5",strokeLinecap:"round",strokeLinejoin:"round"})]})}),r.jsx("div",{className:"flex items-center justify-center w-8 h-8 rounded-full bg-cc-hover text-cc-muted",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:r.jsx("path",{d:"M3 2l11 6-11 6V9.5l7-1.5-7-1.5V2z"})})})]})]})]})})}),r.jsx("div",{className:"mt-4"}),r.jsx(Le,{label:"Running — stop button visible",children:r.jsx("div",{className:"border-t border-cc-border bg-cc-card px-4 py-3",children:r.jsxs("div",{className:"bg-cc-input-bg border border-cc-border rounded-xl overflow-hidden",children:[r.jsx("textarea",{readOnly:!0,value:"",placeholder:"Type a message... (/ for commands)",rows:1,className:"w-full px-4 pt-3 pb-1 text-sm bg-transparent resize-none text-cc-fg font-sans-ui placeholder:text-cc-muted",style:{minHeight:"36px"}}),r.jsxs("div",{className:"flex items-center gap-2 px-4 pb-1 text-[11px] text-cc-muted overflow-hidden",children:[r.jsxs("span",{className:"flex items-center gap-1 truncate min-w-0",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 shrink-0 opacity-60",children:r.jsx("path",{d:"M11.75 2.5a.75.75 0 100 1.5.75.75 0 000-1.5zm-2.116.862a2.25 2.25 0 10-.862.862A4.48 4.48 0 007.25 7.5h-1.5A2.25 2.25 0 003.5 9.75v.318a2.25 2.25 0 101.5 0V9.75a.75.75 0 01.75-.75h1.5a5.98 5.98 0 003.884-1.435A2.25 2.25 0 109.634 3.362zM4.25 12a.75.75 0 100 1.5.75.75 0 000-1.5z"})}),r.jsx("span",{className:"truncate",children:"feat/jwt-auth"}),r.jsx("span",{className:"text-[10px] bg-cc-hover text-cc-muted px-1 rounded",children:"worktree"})]}),r.jsx("span",{className:"flex items-center gap-0.5 text-[10px]",children:r.jsx("span",{className:"text-green-500",children:"3↑"})}),r.jsxs("span",{className:"flex items-center gap-1 shrink-0",children:[r.jsx("span",{className:"text-green-500",children:"+142"}),r.jsx("span",{className:"text-red-400",children:"-38"})]})]}),r.jsxs("div",{className:"flex items-center justify-between px-2.5 pb-2.5",children:[r.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1 rounded-md text-[12px] font-medium text-cc-muted",children:[r.jsxs("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:[r.jsx("path",{d:"M2.5 4l4 4-4 4",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),r.jsx("path",{d:"M8.5 4l4 4-4 4",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]}),r.jsx("span",{children:"code"})]}),r.jsxs("div",{className:"flex items-center gap-1",children:[r.jsx("div",{className:"flex items-center justify-center w-8 h-8 rounded-lg text-cc-muted",children:r.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"w-4 h-4",children:[r.jsx("rect",{x:"2",y:"2",width:"12",height:"12",rx:"2"}),r.jsx("circle",{cx:"5.5",cy:"5.5",r:"1",fill:"currentColor",stroke:"none"}),r.jsx("path",{d:"M2 11l3-3 2 2 3-4 4 5",strokeLinecap:"round",strokeLinejoin:"round"})]})}),r.jsx("div",{className:"flex items-center justify-center w-8 h-8 rounded-lg bg-cc-error/10 text-cc-error",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:r.jsx("rect",{x:"3",y:"3",width:"10",height:"10",rx:"1"})})})]})]})]})})})]})}),r.jsx(vt,{title:"Streaming Indicator",description:"Live typing animation shown while the assistant is generating",children:r.jsxs("div",{className:"space-y-4 max-w-3xl",children:[r.jsx(Le,{label:"Streaming with cursor",children:r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx("div",{className:"w-6 h-6 rounded-full bg-cc-primary/10 flex items-center justify-center shrink-0 mt-0.5",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"none",className:"w-3.5 h-3.5 text-cc-primary",children:r.jsx("path",{d:"M8 1v14M1 8h14",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})})}),r.jsx("div",{className:"flex-1 min-w-0",children:r.jsxs("pre",{className:"font-sans-ui text-[15px] text-cc-fg whitespace-pre-wrap break-words leading-relaxed",children:["I'll start by creating the JWT utility module with sign and verify helpers. Let me first check what dependencies are already installed...",r.jsx("span",{className:"inline-block w-0.5 h-4 bg-cc-primary ml-0.5 align-middle animate-[pulse-dot_0.8s_ease-in-out_infinite]"})]})})]})}),r.jsx(Le,{label:"Generation stats bar",children:r.jsxs("div",{className:"flex items-center gap-1.5 text-[11px] text-cc-muted font-mono-code pl-9",children:[r.jsx("span",{className:"inline-block w-1.5 h-1.5 rounded-full bg-cc-primary animate-pulse"}),r.jsx("span",{children:"Generating..."}),r.jsx("span",{className:"text-cc-muted/60",children:"("}),r.jsx("span",{children:"12s"}),r.jsx("span",{className:"text-cc-muted/40",children:"·"}),r.jsx("span",{children:"↓ 1.2k"}),r.jsx("span",{className:"text-cc-muted/60",children:")"})]})})]})}),r.jsx(vt,{title:"Tool Message Groups",description:"Consecutive same-tool calls collapsed into a single expandable row",children:r.jsxs("div",{className:"space-y-4 max-w-3xl",children:[r.jsx(Le,{label:"Multi-item group (4 Reads)",children:r.jsx(Ax,{toolName:"Read",items:pP})}),r.jsx(Le,{label:"Single-item group",children:r.jsx(Ax,{toolName:"Glob",items:[{id:"sg-1",name:"Glob",input:{pattern:"src/auth/**/*.ts"}}]})})]})}),r.jsx(vt,{title:"Subagent Groups",description:"Nested messages from Task tool subagents shown in a collapsible indent",children:r.jsx("div",{className:"space-y-4 max-w-3xl",children:r.jsx(Le,{label:"Subagent with nested tool calls",children:r.jsx(NP,{description:"Search codebase for auth patterns",agentType:"Explore",items:mP})})})}),r.jsx(vt,{title:"Recalled Memory Context",description:"Collapsible chip shown with a user message when semantic memory enriched the prompt (memory_enriched broadcast)",children:r.jsxs("div",{className:"space-y-4 max-w-3xl",children:[r.jsxs(Le,{label:"Collapsed (default) — one-line summary under the user message",children:[r.jsx(sr,{message:{id:"mem-user-1",role:"user",content:"Add rate limiting to the API endpoints",timestamp:Date.now()}}),r.jsx(Cc,{items:Wd})]}),r.jsx(Le,{label:"Expanded — namespace badges, tags, decayed-weight bars, staleness hint",children:r.jsx(Cc,{items:Wd,defaultOpen:!0})}),r.jsx(Le,{label:"Truncated — context budget hit, some recalled items omitted",children:r.jsx(Cc,{items:Wd.slice(0,2),truncated:!0,defaultOpen:!0})}),r.jsx(Le,{label:"Single memory recalled",children:r.jsx(Cc,{items:Wd.slice(0,1)})})]})}),r.jsx(vt,{title:"Diff Viewer",description:"Unified diff rendering with word-level highlighting — used in ToolBlock, PermissionBanner, and DiffPanel",children:r.jsxs("div",{className:"space-y-4 max-w-3xl",children:[r.jsx(Le,{label:"Edit diff (compact mode)",children:r.jsx(yr,{oldText:`export function formatDate(d: Date) {
|
|
197
|
+
df.describe()`},toolUseId:"tb-11"}),r.jsx(mn,{name:"SendMessage",input:{type:"message",recipient:"researcher",content:"Please investigate the auth module structure and report back.",summary:"Requesting auth module investigation"},toolUseId:"tb-12"})]})}),r.jsx(vt,{title:"Tool Progress",description:"Real-time progress indicator shown while tools are running",children:r.jsxs("div",{className:"space-y-4 max-w-3xl",children:[r.jsx(Le,{label:"Single tool running",children:r.jsxs("div",{className:"flex items-center gap-1.5 text-[11px] text-cc-muted font-mono-code pl-9",children:[r.jsx("span",{className:"inline-block w-1.5 h-1.5 rounded-full bg-cc-primary animate-pulse"}),r.jsx("span",{children:"Terminal"}),r.jsx("span",{className:"text-cc-muted/60",children:"8s"})]})}),r.jsx(Le,{label:"Multiple tools running",children:r.jsxs("div",{className:"flex items-center gap-1.5 text-[11px] text-cc-muted font-mono-code pl-9",children:[r.jsx("span",{className:"inline-block w-1.5 h-1.5 rounded-full bg-cc-primary animate-pulse"}),r.jsx("span",{children:"Search Content"}),r.jsx("span",{className:"text-cc-muted/60",children:"3s"}),r.jsx("span",{className:"text-cc-muted/40",children:"·"}),r.jsx("span",{children:"Find Files"}),r.jsx("span",{className:"text-cc-muted/60",children:"2s"})]})})]})}),r.jsx(vt,{title:"Tool Use Summary",description:"System message summarizing batch tool execution",children:r.jsx("div",{className:"space-y-4 max-w-3xl",children:r.jsx(Le,{label:"Summary as system message",children:r.jsx(sr,{message:{id:"summary-1",role:"system",content:"Read 4 files, searched 12 matches across 3 directories",timestamp:Date.now()}})})})}),r.jsx(vt,{title:"Tasks",description:"Task list states: pending, in progress, completed, blocked",children:r.jsxs("div",{className:"w-[280px] border border-cc-border rounded-xl overflow-hidden bg-cc-card",children:[r.jsxs("div",{className:"px-4 py-3 border-b border-cc-border space-y-2.5",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-[11px] text-cc-muted uppercase tracking-wider",children:"Cost"}),r.jsx("span",{className:"text-[13px] font-medium text-cc-fg tabular-nums",children:"$0.1847"})]}),r.jsxs("div",{className:"space-y-1",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-[11px] text-cc-muted uppercase tracking-wider",children:"Context"}),r.jsx("span",{className:"text-[11px] text-cc-muted tabular-nums",children:"62%"})]}),r.jsx("div",{className:"w-full h-1.5 rounded-full bg-cc-hover overflow-hidden",children:r.jsx("div",{className:"h-full rounded-full bg-cc-warning transition-all duration-500",style:{width:"62%"}})})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-[11px] text-cc-muted uppercase tracking-wider",children:"Turns"}),r.jsx("span",{className:"text-[13px] font-medium text-cc-fg tabular-nums",children:"14"})]})]}),r.jsxs("div",{className:"px-4 py-2.5 border-b border-cc-border flex items-center justify-between",children:[r.jsx("span",{className:"text-[12px] font-semibold text-cc-fg",children:"Tasks"}),r.jsxs("span",{className:"text-[11px] text-cc-muted tabular-nums",children:["2/",r2.length]})]}),r.jsx("div",{className:"px-3 py-2 space-y-0.5",children:r2.map(s=>r.jsx(LP,{task:s},s.id))})]})}),r.jsx(vt,{title:"Session Pulse",description:"Unified floating activity widget — combines per-session agent/task tracking with cross-session awareness. Two tabs: Agents (current session subagents + tasks) and Sessions (other running sessions).",children:r.jsxs("div",{className:"space-y-4 max-w-3xl",children:[r.jsx(Le,{label:"Trigger pill — agents + sessions active",children:r.jsx("div",{className:"relative h-14 bg-cc-bg rounded-lg border border-cc-border/30 flex items-end justify-end p-3",children:r.jsxs("div",{className:"flex items-center gap-2 px-3 h-8 rounded-full border border-cc-border/50 bg-cc-card/90 backdrop-blur-lg shadow-panel",children:[r.jsxs("span",{className:"relative flex h-2 w-2",children:[r.jsx("span",{className:"absolute inset-0 rounded-full bg-cc-primary opacity-75 animate-ping"}),r.jsx("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-cc-primary"})]}),r.jsx("span",{className:"text-[11px] font-medium text-cc-fg/80 font-mono-code",children:"2 agents · 1 tool · 3/5 · 1 session"}),r.jsx("span",{className:"flex items-center justify-center min-w-[16px] h-4 px-1 rounded-full bg-cc-warning/15 text-cc-warning text-[9px] font-semibold",children:"1"}),r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 text-cc-muted/60",children:r.jsx("path",{d:"M4.427 9.573l3.396-3.396a.25.25 0 01.354 0l3.396 3.396a.25.25 0 01-.177.427H4.604a.25.25 0 01-.177-.427z"})})]})})}),r.jsx(Le,{label:"Activity tab — agents, tools, and tasks (all backends)",children:r.jsxs("div",{className:"w-80 rounded-xl border border-cc-border/60 bg-cc-card/95 shadow-float overflow-hidden",children:[r.jsxs("div",{className:"flex items-center gap-1 px-2 pt-2 pb-1 border-b border-cc-border/40",children:[r.jsxs("span",{className:"px-2.5 py-1 rounded-md text-[10px] font-semibold uppercase tracking-wider bg-cc-primary/10 text-cc-primary",children:["Activity ",r.jsx("span",{className:"ml-1 text-[9px] tabular-nums opacity-70",children:"5"})]}),r.jsxs("span",{className:"px-2.5 py-1 rounded-md text-[10px] font-semibold uppercase tracking-wider text-cc-muted hover:text-cc-fg cursor-pointer",children:["Sessions ",r.jsx("span",{className:"ml-1 text-[9px] tabular-nums opacity-70",children:"1"})]}),r.jsx("div",{className:"flex-1"}),r.jsx("span",{className:"p-1 rounded hover:bg-cc-hover cursor-pointer",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 text-cc-muted",children:r.jsx("path",{d:"M4.28 3.22a.75.75 0 00-1.06 1.06L6.94 8l-3.72 3.72a.75.75 0 101.06 1.06L8 9.06l3.72 3.72a.75.75 0 101.06-1.06L9.06 8l3.72-3.72a.75.75 0 00-1.06-1.06L8 6.94 4.28 3.22z"})})})]}),r.jsxs("div",{className:"py-1.5",children:[r.jsx("div",{className:"px-3 py-1",children:r.jsx("span",{className:"text-[9px] text-cc-muted/50 uppercase tracking-widest font-semibold",children:"Agents"})}),r.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-1.5",children:[r.jsxs("span",{className:"relative flex h-1.5 w-1.5 shrink-0",children:[r.jsx("span",{className:"absolute inset-0 rounded-full bg-cc-primary opacity-75 animate-breathing"}),r.jsx("span",{className:"relative inline-flex rounded-full h-1.5 w-1.5 bg-cc-primary"})]}),r.jsx("div",{className:"flex-1 min-w-0",children:r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:"text-[11px] font-medium text-cc-fg truncate",children:"Search codebase for utils"}),r.jsx("span",{className:"text-[8px] text-cc-muted/40 uppercase font-mono-code",children:"Explore"})]})}),r.jsx("span",{className:"text-[10px] text-cc-muted/50 font-mono-code tabular-nums shrink-0",children:"32s"})]}),r.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-1.5",children:[r.jsx("span",{className:"relative flex h-1.5 w-1.5 shrink-0",children:r.jsx("span",{className:"relative inline-flex rounded-full h-1.5 w-1.5 bg-cc-success"})}),r.jsx("div",{className:"flex-1 min-w-0",children:r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:"text-[11px] font-medium text-cc-fg/60 truncate",children:"Analyze test coverage"}),r.jsx("span",{className:"text-[8px] text-cc-muted/40 uppercase font-mono-code",children:"general-purpose"})]})}),r.jsx("span",{className:"text-[10px] text-cc-muted/50 font-mono-code tabular-nums shrink-0",children:"1m 14s"})]}),r.jsx("hr",{className:"mx-3 my-1.5 border-t border-cc-border/30 border-b-0 border-x-0"}),r.jsx("div",{className:"px-3 py-1",children:r.jsx("span",{className:"text-[9px] text-cc-muted/50 uppercase tracking-widest font-semibold",children:"Tools"})}),r.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-1.5",children:[r.jsxs("svg",{className:"w-3.5 h-3.5 text-cc-primary animate-spin shrink-0",viewBox:"0 0 16 16",fill:"none",children:[r.jsx("circle",{cx:"8",cy:"8",r:"6",stroke:"currentColor",strokeWidth:"2",opacity:"0.25"}),r.jsx("path",{d:"M14 8a6 6 0 00-6-6",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]}),r.jsx("span",{className:"text-[11px] font-medium text-cc-fg truncate flex-1",children:"Bash"}),r.jsx("span",{className:"text-[10px] text-cc-muted/50 font-mono-code tabular-nums shrink-0",children:"8s"})]}),r.jsx("hr",{className:"mx-3 my-1.5 border-t border-cc-border/30 border-b-0 border-x-0"}),r.jsx("div",{className:"px-3 py-1",children:r.jsx("span",{className:"text-[9px] text-cc-muted/50 uppercase tracking-widest font-semibold",children:"Tasks"})}),r.jsxs("div",{className:"flex items-center gap-2 px-3 py-1",children:[r.jsx("svg",{className:"w-3.5 h-3.5 text-cc-success shrink-0",viewBox:"0 0 16 16",fill:"currentColor",children:r.jsx("path",{d:"M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"})}),r.jsx("span",{className:"text-[11px] text-cc-muted/50 line-through truncate",children:"Set up test infrastructure"})]}),r.jsxs("div",{className:"flex items-center gap-2 px-3 py-1",children:[r.jsxs("svg",{className:"w-3.5 h-3.5 text-cc-primary animate-spin shrink-0",viewBox:"0 0 16 16",fill:"none",children:[r.jsx("circle",{cx:"8",cy:"8",r:"6",stroke:"currentColor",strokeWidth:"2",opacity:"0.25"}),r.jsx("path",{d:"M14 8a6 6 0 00-6-6",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("span",{className:"text-[11px] text-cc-fg truncate block",children:"Write unit tests for API"}),r.jsx("span",{className:"text-[10px] text-cc-muted/50 italic truncate block",children:"Writing unit tests for API"})]})]}),r.jsxs("div",{className:"flex items-center gap-2 px-3 py-1",children:[r.jsx("svg",{className:"w-3.5 h-3.5 text-cc-muted/30 shrink-0",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:r.jsx("circle",{cx:"8",cy:"8",r:"5.5"})}),r.jsx("span",{className:"text-[11px] text-cc-fg truncate",children:"Run integration tests"})]})]})]})}),r.jsx(Le,{label:"Sessions tab — cross-session awareness",children:r.jsxs("div",{className:"w-80 rounded-xl border border-cc-border/60 bg-cc-card/95 shadow-float overflow-hidden",children:[r.jsxs("div",{className:"flex items-center gap-1 px-2 pt-2 pb-1 border-b border-cc-border/40",children:[r.jsxs("span",{className:"px-2.5 py-1 rounded-md text-[10px] font-semibold uppercase tracking-wider text-cc-muted hover:text-cc-fg cursor-pointer",children:["Activity ",r.jsx("span",{className:"ml-1 text-[9px] tabular-nums opacity-70",children:"5"})]}),r.jsxs("span",{className:"px-2.5 py-1 rounded-md text-[10px] font-semibold uppercase tracking-wider bg-cc-primary/10 text-cc-primary",children:["Sessions ",r.jsx("span",{className:"ml-1 text-[9px] tabular-nums opacity-70",children:"2"})]}),r.jsx("div",{className:"flex-1"}),r.jsx("span",{className:"p-1 rounded hover:bg-cc-hover cursor-pointer",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 text-cc-muted",children:r.jsx("path",{d:"M4.28 3.22a.75.75 0 00-1.06 1.06L6.94 8l-3.72 3.72a.75.75 0 101.06 1.06L8 9.06l3.72 3.72a.75.75 0 101.06-1.06L9.06 8l3.72-3.72a.75.75 0 00-1.06-1.06L8 6.94 4.28 3.22z"})})})]}),r.jsxs("div",{className:"py-1",children:[r.jsxs("div",{className:"w-full flex items-center gap-2.5 px-3 py-2 hover:bg-cc-hover/60 transition-colors text-left cursor-pointer group",children:[r.jsxs("span",{className:"relative flex h-1.5 w-1.5 shrink-0",children:[r.jsx("span",{className:"absolute inset-0 rounded-full bg-cc-primary opacity-75 animate-breathing"}),r.jsx("span",{className:"relative inline-flex rounded-full h-1.5 w-1.5 bg-cc-primary"})]}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("span",{className:"text-[11px] font-medium text-cc-fg truncate block",children:"Refactor API layer"}),r.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[r.jsx("span",{className:"text-[10px] text-cc-muted/50 font-mono-code tabular-nums",children:"4m 23s"}),r.jsx("span",{className:"text-[10px] text-cc-muted/50 font-mono-code tabular-nums",children:"$0.12"})]})]}),r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 text-cc-muted/30 group-hover:text-cc-primary/60 transition-colors shrink-0",children:r.jsx("path",{d:"M8.22 2.97a.75.75 0 011.06 0l4.25 4.25a.75.75 0 010 1.06l-4.25 4.25a.75.75 0 01-1.06-1.06l2.97-2.97H3.75a.75.75 0 010-1.5h7.44L8.22 4.03a.75.75 0 010-1.06z"})})]}),r.jsxs("div",{className:"w-full flex items-center gap-2.5 px-3 py-2 hover:bg-cc-hover/60 transition-colors text-left cursor-pointer group",children:[r.jsxs("span",{className:"relative flex h-1.5 w-1.5 shrink-0",children:[r.jsx("span",{className:"absolute inset-0 rounded-full bg-cc-primary opacity-75 animate-breathing"}),r.jsx("span",{className:"relative inline-flex rounded-full h-1.5 w-1.5 bg-cc-primary"})]}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("span",{className:"text-[11px] font-medium text-cc-fg truncate block",children:"Write unit tests"}),r.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[r.jsx("span",{className:"text-[10px] text-cc-muted/50 font-mono-code tabular-nums",children:"1m 47s"}),r.jsx("span",{className:"text-[10px] text-cc-muted/50 font-mono-code tabular-nums",children:"$0.08"})]})]}),r.jsxs("span",{className:"flex items-center gap-1 px-1.5 py-0.5 rounded-full bg-cc-warning/10 shrink-0",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-2.5 h-2.5 text-cc-warning",children:r.jsx("path",{d:"M8.22 1.754a.25.25 0 00-.44 0L1.698 13.132a.25.25 0 00.22.368h12.164a.25.25 0 00.22-.368L8.22 1.754zm-1.763-.707c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0114.082 15H1.918a1.75 1.75 0 01-1.543-2.575L6.457 1.047zM9 11a1 1 0 11-2 0 1 1 0 012 0zm-.25-5.25a.75.75 0 00-1.5 0v2.5a.75.75 0 001.5 0v-2.5z"})}),r.jsx("span",{className:"text-[9px] font-semibold text-cc-warning tabular-nums",children:"1"})]}),r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 text-cc-muted/30 group-hover:text-cc-primary/60 transition-colors shrink-0",children:r.jsx("path",{d:"M8.22 2.97a.75.75 0 011.06 0l4.25 4.25a.75.75 0 010 1.06l-4.25 4.25a.75.75 0 01-1.06-1.06l2.97-2.97H3.75a.75.75 0 010-1.5h7.44L8.22 4.03a.75.75 0 010-1.06z"})})]})]})]})})]})}),r.jsx(vt,{title:"Environment Detection",description:"Detected project services and missing environment variables shown in the session panel",children:r.jsx(Le,{label:"Detected Next.js, Prisma, and Stripe",children:r.jsx("div",{className:"w-[280px] border border-cc-border rounded-xl overflow-hidden bg-cc-bg py-1",children:r.jsx(_C,{detected:{cwd:"/Users/stan/Dev/project",scannedAt:Date.now(),mcpServers:{},rules:[{id:"vercel",name:"Vercel",description:"Vercel or Next.js deployment target detected."},{id:"prisma",name:"Prisma",description:"Prisma schema or dependency detected.",envRequired:["DATABASE_URL"],envMissing:["DATABASE_URL"],envPresent:[]},{id:"stripe",name:"Stripe",description:"Stripe SDK or secret key detected.",envRequired:["STRIPE_SECRET_KEY"],envPresent:["STRIPE_SECRET_KEY"],envMissing:[]}]}})})})}),r.jsx(vt,{title:"Cost Card",description:"Shareable session summary card with key metrics and PNG export",children:r.jsxs("div",{className:"space-y-4",children:[r.jsx(Le,{label:"Completed session with cost",children:r.jsx("div",{className:"w-[280px] border border-cc-border rounded-xl overflow-hidden bg-cc-card",children:r.jsx(Mx,{sessionName:"Implement auth flow",cost:.2847,turns:14,durationMs:12*6e4,model:"claude-opus-4-6",backend:"claude",linesAdded:342,linesRemoved:87})})}),r.jsx(Le,{label:"Low-cost quick task",children:r.jsx("div",{className:"w-[280px] border border-cc-border rounded-xl overflow-hidden bg-cc-card",children:r.jsx(Mx,{sessionName:"Fix typo in README",cost:.0043,turns:2,durationMs:45e3,model:"claude-sonnet-4-5-20250929",backend:"claude",linesAdded:1,linesRemoved:1})})})]})}),r.jsx(vt,{title:"GitHub PR Status",description:"PR health shown in the TaskPanel — checks, reviews, unresolved comments",children:r.jsxs("div",{className:"space-y-4",children:[r.jsx(Le,{label:"Open PR — failing checks + changes requested",children:r.jsx("div",{className:"w-[280px] border border-cc-border rounded-xl overflow-hidden bg-cc-card",children:r.jsx(Nc,{pr:xP})})}),r.jsx(Le,{label:"Open PR — all checks passed + approved",children:r.jsx("div",{className:"w-[280px] border border-cc-border rounded-xl overflow-hidden bg-cc-card",children:r.jsx(Nc,{pr:vP})})}),r.jsx(Le,{label:"Draft PR — pending checks",children:r.jsx("div",{className:"w-[280px] border border-cc-border rounded-xl overflow-hidden bg-cc-card",children:r.jsx(Nc,{pr:bP})})}),r.jsx(Le,{label:"Merged PR",children:r.jsx("div",{className:"w-[280px] border border-cc-border rounded-xl overflow-hidden bg-cc-card",children:r.jsx(Nc,{pr:_P})})})]})}),r.jsx(vt,{title:"MCP Servers",description:"MCP server status display with toggle, reconnect, and tool listing",children:r.jsx("div",{className:"space-y-4",children:r.jsx(Le,{label:"All server states (connected, failed, disabled, connecting)",children:r.jsxs("div",{className:"w-[280px] border border-cc-border rounded-xl overflow-hidden bg-cc-card",children:[r.jsxs("div",{className:"shrink-0 px-4 py-2.5 border-b border-cc-border flex items-center justify-between",children:[r.jsxs("span",{className:"text-[12px] font-semibold text-cc-fg flex items-center gap-1.5",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 text-cc-muted",children:r.jsx("path",{d:"M1.5 3A1.5 1.5 0 013 1.5h10A1.5 1.5 0 0114.5 3v1A1.5 1.5 0 0113 5.5H3A1.5 1.5 0 011.5 4V3zm0 5A1.5 1.5 0 013 6.5h10A1.5 1.5 0 0114.5 8v1A1.5 1.5 0 0113 10.5H3A1.5 1.5 0 011.5 9V8zm0 5A1.5 1.5 0 013 11.5h10a1.5 1.5 0 011.5 1.5v1a1.5 1.5 0 01-1.5 1.5H3A1.5 1.5 0 011.5 14v-1z"})}),"MCP Servers"]}),r.jsx("span",{className:"text-[11px] text-cc-muted",children:r.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"w-3.5 h-3.5",children:[r.jsx("path",{d:"M2.5 8a5.5 5.5 0 019.78-3.5M13.5 8a5.5 5.5 0 01-9.78 3.5",strokeLinecap:"round"}),r.jsx("path",{d:"M12.5 2v3h-3M3.5 14v-3h3",strokeLinecap:"round",strokeLinejoin:"round"})]})})]}),r.jsx("div",{className:"px-3 py-2 space-y-1.5",children:jP.map(s=>r.jsx(RP,{server:s},s.name))})]})})})}),r.jsx(vt,{title:"Codex Session Details",description:"Rate limits and token details for Codex (OpenAI) sessions — streamed via session_update",children:r.jsx("div",{className:"space-y-4",children:r.jsx(Le,{label:"Rate limits with token breakdown",children:r.jsx(MP,{})})})}),r.jsx(vt,{title:"Claude Session Details",description:"Token usage and cost for Claude Code sessions — updated at turn end from modelUsage",children:r.jsx("div",{className:"space-y-4",children:r.jsx(Le,{label:"Token breakdown with cost",children:r.jsx(TP,{})})})}),r.jsx(vt,{title:"Update Banner",description:"Notification banner for available updates",children:r.jsxs("div",{className:"space-y-4 max-w-3xl",children:[r.jsx(Le,{label:"Service mode (auto-update)",children:r.jsx(gg,{updateInfo:{currentVersion:"0.22.1",latestVersion:"0.23.0",updateAvailable:!0,isServiceMode:!0,updateInProgress:!1,lastChecked:Date.now()}})}),r.jsx(Le,{label:"Foreground mode (manual)",children:r.jsx(gg,{updateInfo:{currentVersion:"0.22.1",latestVersion:"0.23.0",updateAvailable:!0,isServiceMode:!1,updateInProgress:!1,lastChecked:Date.now()}})}),r.jsx(Le,{label:"Update in progress",children:r.jsx(gg,{updateInfo:{currentVersion:"0.22.1",latestVersion:"0.23.0",updateAvailable:!0,isServiceMode:!0,updateInProgress:!0,lastChecked:Date.now()}})})]})}),r.jsx(vt,{title:"Status Indicators",description:"Connection and session status banners",children:r.jsxs("div",{className:"space-y-3 max-w-3xl",children:[r.jsx(Le,{label:"Disconnected warning",children:r.jsx("div",{className:"px-4 py-2 bg-cc-warning/10 border border-cc-warning/20 rounded-lg text-center",children:r.jsx("span",{className:"text-xs text-cc-warning font-medium",children:"Reconnecting to session..."})})}),r.jsx(Le,{label:"Connected",children:r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 bg-cc-card border border-cc-border rounded-lg",children:[r.jsx("span",{className:"w-2 h-2 rounded-full bg-cc-success"}),r.jsx("span",{className:"text-xs text-cc-fg font-medium",children:"Connected"}),r.jsx("span",{className:"text-[11px] text-cc-muted ml-auto",children:"claude-opus-4-6"})]})}),r.jsx(Le,{label:"Running / Thinking",children:r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 bg-cc-card border border-cc-border rounded-lg",children:[r.jsx("span",{className:"w-2 h-2 rounded-full bg-cc-primary animate-[pulse-dot_1.5s_ease-in-out_infinite]"}),r.jsx("span",{className:"text-xs text-cc-fg font-medium",children:"Thinking"})]})}),r.jsx(Le,{label:"Compacting",children:r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 bg-cc-card border border-cc-border rounded-lg",children:[r.jsx("svg",{className:"w-3.5 h-3.5 text-cc-muted animate-spin",viewBox:"0 0 16 16",fill:"none",children:r.jsx("circle",{cx:"8",cy:"8",r:"6",stroke:"currentColor",strokeWidth:"1.5",strokeDasharray:"28",strokeDashoffset:"8",strokeLinecap:"round"})}),r.jsx("span",{className:"text-xs text-cc-muted font-medium",children:"Compacting context..."})]})})]})}),r.jsx(vt,{title:"Session Items",description:"Sidebar session items with status-first layout, model badges, and hover-revealed git stats",children:r.jsxs("div",{className:"max-w-xs space-y-1 bg-cc-bg p-2 rounded-lg border border-cc-border",children:[r.jsx("div",{className:"relative group",children:r.jsxs("div",{className:"w-full pl-3.5 pr-8 py-2.5 sm:py-2 text-left rounded-lg bg-cc-active",children:[r.jsx("span",{className:"absolute left-0 top-1.5 bottom-1.5 w-[3px] rounded-full bg-cc-success animate-[pulse-dot_1.5s_ease-in-out_infinite] opacity-100"}),r.jsxs("div",{className:"flex flex-col gap-0.5 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:"text-[13px] font-medium truncate text-cc-fg leading-snug",children:"Refactor auth module"}),r.jsx("span",{className:"text-[9px] font-medium px-1.5 rounded-full leading-[16px] shrink-0 text-[#5BA8A0] bg-[#5BA8A0]/10",children:"Sonnet"})]}),r.jsxs("div",{className:"flex items-center gap-1 text-[10.5px] text-cc-muted leading-tight truncate",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-2.5 h-2.5 shrink-0 opacity-50",children:r.jsx("path",{d:"M11.75 2.5a.75.75 0 100 1.5.75.75 0 000-1.5zm-2.116.862a2.25 2.25 0 10-.862.862A4.48 4.48 0 007.25 7.5h-1.5A2.25 2.25 0 003.5 9.75v.318a2.25 2.25 0 101.5 0V9.75a.75.75 0 01.75-.75h1.5a5.98 5.98 0 003.884-1.435A2.25 2.25 0 109.634 3.362zM4.25 12a.75.75 0 100 1.5.75.75 0 000-1.5z"})}),r.jsx("span",{className:"truncate",children:"feat/auth-jwt"})]}),r.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-cc-muted",children:[r.jsx("span",{className:"flex items-center gap-0.5",children:r.jsx("span",{className:"text-green-500",children:"2↑"})}),r.jsxs("span",{className:"flex items-center gap-1 shrink-0",children:[r.jsx("span",{className:"text-green-500",children:"+48"}),r.jsx("span",{className:"text-red-400",children:"-12"})]})]})]})]})}),r.jsx("div",{className:"relative group",children:r.jsxs("div",{className:"w-full pl-3.5 pr-8 py-2.5 sm:py-2 text-left rounded-lg hover:bg-cc-hover",children:[r.jsx("span",{className:"absolute left-0 top-1.5 bottom-1.5 w-[3px] rounded-full bg-cc-success/60 opacity-60"}),r.jsxs("div",{className:"flex flex-col gap-0.5 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:"text-[13px] font-medium truncate text-cc-fg leading-snug",children:"Fix CI pipeline"}),r.jsx("span",{className:"text-[9px] font-medium px-1.5 rounded-full leading-[16px] shrink-0 text-blue-400 bg-blue-500/10",children:"Codex"})]}),r.jsxs("div",{className:"flex items-center gap-1 text-[10.5px] text-cc-muted leading-tight truncate",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-2.5 h-2.5 shrink-0 opacity-50",children:r.jsx("path",{d:"M11.75 2.5a.75.75 0 100 1.5.75.75 0 000-1.5zm-2.116.862a2.25 2.25 0 10-.862.862A4.48 4.48 0 007.25 7.5h-1.5A2.25 2.25 0 003.5 9.75v.318a2.25 2.25 0 101.5 0V9.75a.75.75 0 01.75-.75h1.5a5.98 5.98 0 003.884-1.435A2.25 2.25 0 109.634 3.362zM4.25 12a.75.75 0 100 1.5.75.75 0 000-1.5z"})}),r.jsx("span",{className:"truncate",children:"main"})]})]})]})}),r.jsxs("div",{className:"relative group",children:[r.jsxs("div",{className:"w-full pl-3.5 pr-8 py-2.5 sm:py-2 text-left rounded-lg hover:bg-cc-hover",children:[r.jsx("span",{className:"absolute left-0 top-1.5 bottom-1.5 w-[3px] rounded-full bg-cc-warning animate-[pulse-dot_1.5s_ease-in-out_infinite] opacity-100"}),r.jsx("div",{className:"flex flex-col gap-0.5 min-w-0",children:r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:"text-[13px] font-medium truncate text-cc-fg leading-snug",children:"Update dependencies"}),r.jsx("span",{className:"text-[9px] font-medium px-1.5 rounded-full leading-[16px] shrink-0 text-[#5BA8A0] bg-[#5BA8A0]/10",children:"Opus"})]})})]}),r.jsx("span",{className:"absolute right-2 top-1/2 -translate-y-1/2 min-w-[18px] h-[18px] flex items-center justify-center rounded-full bg-cc-warning text-white text-[10px] font-bold leading-none px-1",children:"2"})]}),r.jsx("div",{className:"relative group",children:r.jsxs("div",{className:"w-full pl-3.5 pr-8 py-2.5 sm:py-2 text-left rounded-lg hover:bg-cc-hover",children:[r.jsx("span",{className:"absolute left-0 top-1.5 bottom-1.5 w-[3px] rounded-full bg-cc-muted/30 opacity-60"}),r.jsx("div",{className:"flex flex-col gap-0.5 min-w-0",children:r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:"text-[13px] font-medium truncate text-cc-fg leading-snug",children:"Add dark mode toggle"}),r.jsx("span",{className:"text-[9px] font-medium px-1.5 rounded-full leading-[16px] shrink-0 text-[#5BA8A0] bg-[#5BA8A0]/10",children:"Haiku"})]})})]})})]})}),r.jsx(vt,{title:"Session Launch Overlay",description:"Container session creation progress with step indicators and progress bar",children:r.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[r.jsx(Le,{label:"In progress — pulling image",children:r.jsxs("div",{className:"relative rounded-xl border border-neutral-200 bg-white p-6 dark:border-neutral-700 dark:bg-neutral-900",children:[r.jsx("h3",{className:"mb-4 text-lg font-semibold text-neutral-900 dark:text-neutral-100",children:"Launching Container Session"}),r.jsx("div",{className:"mb-4 space-y-2",children:["Checking image","Pulling image","Creating container","Seeding authentication","Launching agent"].map((s,n)=>r.jsxs("div",{className:`flex items-center gap-2 text-sm ${n<1?"text-green-600 dark:text-green-400":n===1?"font-medium text-blue-600 dark:text-blue-400":"text-neutral-400 dark:text-neutral-600"}`,children:[n<1?r.jsx("svg",{className:"h-4 w-4 flex-shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}):n===1?r.jsxs("svg",{className:"h-4 w-4 flex-shrink-0 animate-spin",fill:"none",viewBox:"0 0 24 24",children:[r.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),r.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}):r.jsx("div",{className:"h-4 w-4 flex-shrink-0 rounded-full border border-neutral-300 dark:border-neutral-600"}),r.jsx("span",{children:s})]},s))}),r.jsxs("div",{className:"mb-3",children:[r.jsx("div",{className:"h-2 overflow-hidden rounded-full bg-neutral-200 dark:bg-neutral-700",children:r.jsx("div",{className:"h-full rounded-full bg-blue-600 transition-all duration-300",style:{width:"63%"}})}),r.jsx("p",{className:"mt-1 text-xs text-neutral-500",children:"63%"})]}),r.jsx("p",{className:"text-xs text-neutral-500 dark:text-neutral-400 truncate",children:"Downloading layer sha256:a1b2c3d4..."})]})}),r.jsx(Le,{label:"Error state",children:r.jsxs("div",{className:"relative rounded-xl border border-neutral-200 bg-white p-6 dark:border-neutral-700 dark:bg-neutral-900",children:[r.jsxs("div",{className:"mb-4 flex items-center gap-2 text-red-600 dark:text-red-400",children:[r.jsx("svg",{className:"h-5 w-5 flex-shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L4.082 16.5c-.77.833.192 2.5 1.732 2.5z"})}),r.jsx("h3",{className:"text-lg font-semibold",children:"Container Launch Failed"})]}),r.jsx("p",{className:"mb-4 text-sm text-neutral-600 dark:text-neutral-400",children:"Failed to pull image campfire-dev:latest — connection timed out"}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("button",{className:"flex-1 rounded-lg bg-blue-600 px-4 py-2 text-sm font-medium text-white hover:bg-blue-700",children:"Retry"}),r.jsx("button",{className:"flex-1 rounded-lg border border-neutral-300 px-4 py-2 text-sm font-medium text-neutral-700 hover:bg-neutral-100 dark:border-neutral-600 dark:text-neutral-300 dark:hover:bg-neutral-800",children:"Cancel"})]})]})})]})}),r.jsx(vt,{title:"Composer",description:"Message input bar with mode toggle, image upload, and send/stop buttons",children:r.jsxs("div",{className:"max-w-3xl",children:[r.jsx(Le,{label:"Connected — code mode",children:r.jsx("div",{className:"border-t border-cc-border bg-cc-card px-4 py-3",children:r.jsxs("div",{className:"bg-cc-input-bg border border-cc-border rounded-xl overflow-hidden",children:[r.jsx("textarea",{readOnly:!0,value:"Can you refactor the auth module to use JWT?",rows:1,className:"w-full px-4 pt-3 pb-1 text-sm bg-transparent resize-none text-cc-fg font-sans-ui",style:{minHeight:"36px"}}),r.jsxs("div",{className:"flex items-center justify-between px-2.5 pb-2.5",children:[r.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1 rounded-md text-[12px] font-medium text-cc-muted",children:[r.jsxs("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:[r.jsx("path",{d:"M2.5 4l4 4-4 4",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),r.jsx("path",{d:"M8.5 4l4 4-4 4",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]}),r.jsx("span",{children:"code"})]}),r.jsxs("div",{className:"flex items-center gap-1",children:[r.jsx("div",{className:"flex items-center justify-center w-8 h-8 rounded-lg text-cc-muted",children:r.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"w-4 h-4",children:[r.jsx("rect",{x:"2",y:"2",width:"12",height:"12",rx:"2"}),r.jsx("circle",{cx:"5.5",cy:"5.5",r:"1",fill:"currentColor",stroke:"none"}),r.jsx("path",{d:"M2 11l3-3 2 2 3-4 4 5",strokeLinecap:"round",strokeLinejoin:"round"})]})}),r.jsx("div",{className:"flex items-center justify-center w-8 h-8 rounded-full bg-cc-primary text-white",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:r.jsx("path",{d:"M3 2l11 6-11 6V9.5l7-1.5-7-1.5V2z"})})})]})]})]})})}),r.jsx("div",{className:"mt-4"}),r.jsx(Le,{label:"Plan mode active",children:r.jsx("div",{className:"border-t border-cc-border bg-cc-card px-4 py-3",children:r.jsxs("div",{className:"bg-cc-input-bg border border-cc-primary/40 rounded-xl overflow-hidden",children:[r.jsx("textarea",{readOnly:!0,value:"",placeholder:"Type a message... (/ for commands)",rows:1,className:"w-full px-4 pt-3 pb-1 text-sm bg-transparent resize-none text-cc-fg font-sans-ui placeholder:text-cc-muted",style:{minHeight:"36px"}}),r.jsxs("div",{className:"flex items-center justify-between px-2.5 pb-2.5",children:[r.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1 rounded-md text-[12px] font-medium text-cc-primary",children:[r.jsxs("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:[r.jsx("rect",{x:"3",y:"3",width:"3.5",height:"10",rx:"0.75"}),r.jsx("rect",{x:"9.5",y:"3",width:"3.5",height:"10",rx:"0.75"})]}),r.jsx("span",{children:"plan"})]}),r.jsxs("div",{className:"flex items-center gap-1",children:[r.jsx("div",{className:"flex items-center justify-center w-8 h-8 rounded-lg text-cc-muted",children:r.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"w-4 h-4",children:[r.jsx("rect",{x:"2",y:"2",width:"12",height:"12",rx:"2"}),r.jsx("circle",{cx:"5.5",cy:"5.5",r:"1",fill:"currentColor",stroke:"none"}),r.jsx("path",{d:"M2 11l3-3 2 2 3-4 4 5",strokeLinecap:"round",strokeLinejoin:"round"})]})}),r.jsx("div",{className:"flex items-center justify-center w-8 h-8 rounded-full bg-cc-hover text-cc-muted",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:r.jsx("path",{d:"M3 2l11 6-11 6V9.5l7-1.5-7-1.5V2z"})})})]})]})]})})}),r.jsx("div",{className:"mt-4"}),r.jsx(Le,{label:"Running — stop button visible",children:r.jsx("div",{className:"border-t border-cc-border bg-cc-card px-4 py-3",children:r.jsxs("div",{className:"bg-cc-input-bg border border-cc-border rounded-xl overflow-hidden",children:[r.jsx("textarea",{readOnly:!0,value:"",placeholder:"Type a message... (/ for commands)",rows:1,className:"w-full px-4 pt-3 pb-1 text-sm bg-transparent resize-none text-cc-fg font-sans-ui placeholder:text-cc-muted",style:{minHeight:"36px"}}),r.jsxs("div",{className:"flex items-center gap-2 px-4 pb-1 text-[11px] text-cc-muted overflow-hidden",children:[r.jsxs("span",{className:"flex items-center gap-1 truncate min-w-0",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 shrink-0 opacity-60",children:r.jsx("path",{d:"M11.75 2.5a.75.75 0 100 1.5.75.75 0 000-1.5zm-2.116.862a2.25 2.25 0 10-.862.862A4.48 4.48 0 007.25 7.5h-1.5A2.25 2.25 0 003.5 9.75v.318a2.25 2.25 0 101.5 0V9.75a.75.75 0 01.75-.75h1.5a5.98 5.98 0 003.884-1.435A2.25 2.25 0 109.634 3.362zM4.25 12a.75.75 0 100 1.5.75.75 0 000-1.5z"})}),r.jsx("span",{className:"truncate",children:"feat/jwt-auth"}),r.jsx("span",{className:"text-[10px] bg-cc-hover text-cc-muted px-1 rounded",children:"worktree"})]}),r.jsx("span",{className:"flex items-center gap-0.5 text-[10px]",children:r.jsx("span",{className:"text-green-500",children:"3↑"})}),r.jsxs("span",{className:"flex items-center gap-1 shrink-0",children:[r.jsx("span",{className:"text-green-500",children:"+142"}),r.jsx("span",{className:"text-red-400",children:"-38"})]})]}),r.jsxs("div",{className:"flex items-center justify-between px-2.5 pb-2.5",children:[r.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1 rounded-md text-[12px] font-medium text-cc-muted",children:[r.jsxs("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:[r.jsx("path",{d:"M2.5 4l4 4-4 4",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),r.jsx("path",{d:"M8.5 4l4 4-4 4",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]}),r.jsx("span",{children:"code"})]}),r.jsxs("div",{className:"flex items-center gap-1",children:[r.jsx("div",{className:"flex items-center justify-center w-8 h-8 rounded-lg text-cc-muted",children:r.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"w-4 h-4",children:[r.jsx("rect",{x:"2",y:"2",width:"12",height:"12",rx:"2"}),r.jsx("circle",{cx:"5.5",cy:"5.5",r:"1",fill:"currentColor",stroke:"none"}),r.jsx("path",{d:"M2 11l3-3 2 2 3-4 4 5",strokeLinecap:"round",strokeLinejoin:"round"})]})}),r.jsx("div",{className:"flex items-center justify-center w-8 h-8 rounded-lg bg-cc-error/10 text-cc-error",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:r.jsx("rect",{x:"3",y:"3",width:"10",height:"10",rx:"1"})})})]})]})]})})})]})}),r.jsx(vt,{title:"Streaming Indicator",description:"Live typing animation shown while the assistant is generating",children:r.jsxs("div",{className:"space-y-4 max-w-3xl",children:[r.jsx(Le,{label:"Streaming with cursor",children:r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx("div",{className:"w-6 h-6 rounded-full bg-cc-primary/10 flex items-center justify-center shrink-0 mt-0.5",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"none",className:"w-3.5 h-3.5 text-cc-primary",children:r.jsx("path",{d:"M8 1v14M1 8h14",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})})}),r.jsx("div",{className:"flex-1 min-w-0",children:r.jsxs("pre",{className:"font-sans-ui text-[15px] text-cc-fg whitespace-pre-wrap break-words leading-relaxed",children:["I'll start by creating the JWT utility module with sign and verify helpers. Let me first check what dependencies are already installed...",r.jsx("span",{className:"inline-block w-0.5 h-4 bg-cc-primary ml-0.5 align-middle animate-[pulse-dot_0.8s_ease-in-out_infinite]"})]})})]})}),r.jsx(Le,{label:"Generation stats bar",children:r.jsxs("div",{className:"flex items-center gap-1.5 text-[11px] text-cc-muted font-mono-code pl-9",children:[r.jsx("span",{className:"inline-block w-1.5 h-1.5 rounded-full bg-cc-primary animate-pulse"}),r.jsx("span",{children:"Generating..."}),r.jsx("span",{className:"text-cc-muted/60",children:"("}),r.jsx("span",{children:"12s"}),r.jsx("span",{className:"text-cc-muted/40",children:"·"}),r.jsx("span",{children:"↓ 1.2k"}),r.jsx("span",{className:"text-cc-muted/60",children:")"})]})})]})}),r.jsx(vt,{title:"Tool Message Groups",description:"Consecutive same-tool calls collapsed into a single expandable row",children:r.jsxs("div",{className:"space-y-4 max-w-3xl",children:[r.jsx(Le,{label:"Multi-item group (4 Reads)",children:r.jsx(Ax,{toolName:"Read",items:mP})}),r.jsx(Le,{label:"Single-item group",children:r.jsx(Ax,{toolName:"Glob",items:[{id:"sg-1",name:"Glob",input:{pattern:"src/auth/**/*.ts"}}]})})]})}),r.jsx(vt,{title:"Subagent Groups",description:"Nested messages from Task tool subagents shown in a collapsible indent",children:r.jsx("div",{className:"space-y-4 max-w-3xl",children:r.jsx(Le,{label:"Subagent with nested tool calls",children:r.jsx(EP,{description:"Search codebase for auth patterns",agentType:"Explore",items:gP})})})}),r.jsx(vt,{title:"Recalled Memory Context",description:"Collapsible chip shown with a user message when semantic memory enriched the prompt (memory_enriched broadcast)",children:r.jsxs("div",{className:"space-y-4 max-w-3xl",children:[r.jsxs(Le,{label:"Collapsed (default) — one-line summary under the user message",children:[r.jsx(sr,{message:{id:"mem-user-1",role:"user",content:"Add rate limiting to the API endpoints",timestamp:Date.now()}}),r.jsx(Cc,{items:Wd})]}),r.jsx(Le,{label:"Expanded — namespace badges, tags, decayed-weight bars, staleness hint",children:r.jsx(Cc,{items:Wd,defaultOpen:!0})}),r.jsx(Le,{label:"Truncated — context budget hit, some recalled items omitted",children:r.jsx(Cc,{items:Wd.slice(0,2),truncated:!0,defaultOpen:!0})}),r.jsx(Le,{label:"Single memory recalled",children:r.jsx(Cc,{items:Wd.slice(0,1)})})]})}),r.jsx(vt,{title:"Diff Viewer",description:"Unified diff rendering with word-level highlighting — used in ToolBlock, PermissionBanner, and DiffPanel",children:r.jsxs("div",{className:"space-y-4 max-w-3xl",children:[r.jsx(Le,{label:"Edit diff (compact mode)",children:r.jsx(yr,{oldText:`export function formatDate(d: Date) {
|
|
198
198
|
return d.toISOString();
|
|
199
199
|
}`,newText:`export function formatDate(d: Date, locale = "en-US") {
|
|
200
200
|
return d.toLocaleDateString(locale, {
|
|
@@ -230,7 +230,7 @@ df.describe()`},toolUseId:"tb-11"}),r.jsx(mn,{name:"SendMessage",input:{type:"me
|
|
|
230
230
|
+ if (!payload) return res.status(401).json({ error: "Invalid token" });
|
|
231
231
|
+ req.userId = payload.userId;
|
|
232
232
|
next();
|
|
233
|
-
}`,mode:"full"})}),r.jsx(Le,{label:"No changes",children:r.jsx(yr,{oldText:"same content",newText:"same content"})})]})}),r.jsx(vt,{title:"CLAUDE.md Editor",description:"Modal for viewing and editing project CLAUDE.md instructions",children:r.jsx("div",{className:"space-y-4 max-w-3xl",children:r.jsx(Le,{label:"Open editor button (from TopBar)",children:r.jsx(TP,{})})})}),r.jsx(vt,{title:"Gallery Cards",description:"Session gallery entries with voting, tags, featured badge, and stats",children:r.jsxs("div",{className:"space-y-4 max-w-3xl",children:[r.jsx(Le,{label:"Featured entry with high votes",children:r.jsx(oh,{entry:_P,onVote:()=>{},onDelete:()=>{},onFeature:()=>{}})}),r.jsx(Le,{label:"Regular entry with tags",children:r.jsx(oh,{entry:yP,onVote:()=>{},onDelete:()=>{},onFeature:()=>{}})}),r.jsx(Le,{label:"Codex entry with low cost",children:r.jsx(oh,{entry:wP,onVote:()=>{},onDelete:()=>{},onFeature:()=>{}})})]})}),r.jsx(vt,{title:"Webhook & Adapter Pages",description:"Management UIs for webhooks and community adapters (navigate to #/webhooks or #/adapters)",children:r.jsxs("div",{className:"space-y-4 max-w-3xl",children:[r.jsx(Le,{label:"Webhook card with delivery stats",children:r.jsxs("div",{className:"border border-cc-border rounded-lg overflow-hidden bg-cc-card",children:[r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5 bg-cc-card border-b border-cc-border",children:[r.jsx("span",{className:"text-sm font-medium text-cc-fg flex-1 truncate",children:"Slack Notifications"}),r.jsx("span",{className:"text-[9px] font-medium px-1.5 rounded-full leading-[16px] shrink-0 text-cc-success bg-cc-success/10",children:"47/50"}),r.jsx("span",{className:"relative w-8 h-[18px] rounded-full bg-cc-primary shrink-0",children:r.jsx("span",{className:"absolute top-[2px] left-[16px] w-[14px] h-[14px] rounded-full bg-white"})})]}),r.jsxs("div",{className:"px-3 py-2.5 space-y-1.5",children:[r.jsx("div",{className:"text-xs text-cc-muted font-mono-code truncate",children:"https://hooks.slack.com/services/T00.../B00.../xxx"}),r.jsx("div",{className:"flex flex-wrap gap-1.5",children:["session.completed","session.failed","cost.threshold"].map(s=>r.jsx("span",{className:"text-[9px] font-medium px-1.5 py-0.5 rounded-full bg-cc-hover text-cc-muted",children:s},s))}),r.jsxs("div",{className:"flex items-center gap-3 text-[11px] text-cc-muted",children:[r.jsxs("span",{className:"flex items-center gap-1",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3",children:r.jsx("path",{d:"M8 1a3.5 3.5 0 00-3.5 3.5V7H4a1 1 0 00-1 1v5a1 1 0 001 1h8a1 1 0 001-1V8a1 1 0 00-1-1h-.5V4.5A3.5 3.5 0 008 1zm2 6H6V4.5a2 2 0 114 0V7z"})}),"Signed"]}),r.jsx("span",{children:"Last: 5m ago"})]})]})]})}),r.jsx(Le,{label:"Adapter card with models",children:r.jsxs("div",{className:"border border-cc-border rounded-lg overflow-hidden bg-cc-card",children:[r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5 bg-cc-card border-b border-cc-border",children:[r.jsx("span",{className:"text-sm font-medium text-cc-fg flex-1 truncate",children:"My Custom Agent"}),r.jsx("span",{className:"text-[9px] font-medium px-1.5 rounded-full leading-[16px] shrink-0 text-cc-muted bg-cc-hover",children:"v1.2.0"}),r.jsx("span",{className:"text-[9px] font-medium px-1.5 rounded-full leading-[16px] shrink-0 text-blue-500 bg-blue-500/10",children:"WebSocket"})]}),r.jsxs("div",{className:"px-3 py-2.5 space-y-1.5",children:[r.jsx("div",{className:"text-xs text-cc-muted",children:"A custom agent for automated code review"}),r.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px] text-cc-muted",children:[r.jsx("span",{className:"font-mono-code",children:"my-agent"}),r.jsx("span",{children:"3 models"}),r.jsx("span",{children:"by @community"}),r.jsx("span",{className:"font-mono-code",children:"@campfire/my-agent"})]}),r.jsx("div",{className:"flex flex-wrap gap-1",children:["GPT-4o","GPT-4o-mini","o1-preview"].map(s=>r.jsx("span",{className:"text-[9px] font-medium px-1.5 py-0.5 rounded-full bg-cc-hover text-cc-muted",children:s},s))})]})]})})]})})]})]})}function vt({title:e,description:t,children:s}){return r.jsxs("section",{children:[r.jsxs("div",{className:"mb-4",children:[r.jsx("h2",{className:"text-base font-semibold text-cc-fg",children:e}),r.jsx("p",{className:"text-xs text-cc-muted mt-0.5",children:t})]}),s]})}function Le({label:e,children:t}){return r.jsxs("div",{className:"border border-cc-border rounded-xl overflow-hidden bg-cc-card",children:[r.jsx("div",{className:"px-3 py-1.5 bg-cc-hover/50 border-b border-cc-border",children:r.jsx("span",{className:"text-[10px] text-cc-muted font-mono-code uppercase tracking-wider",children:e})}),r.jsx("div",{className:"p-4",children:t})]})}function Ax({toolName:e,items:t}){const[s,n]=w.useState(!1),a=du(e),l=Ta(e),c=t.length;if(c===1){const d=t[0];return r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx("div",{className:"w-6 h-6 rounded-full bg-cc-primary/10 flex items-center justify-center shrink-0 mt-0.5",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 text-cc-primary",children:r.jsx("circle",{cx:"8",cy:"8",r:"3"})})}),r.jsx("div",{className:"flex-1 min-w-0",children:r.jsxs("div",{className:"border border-cc-border rounded-lg overflow-hidden bg-cc-card",children:[r.jsxs("button",{onClick:()=>n(!s),className:"w-full flex items-center gap-2.5 px-3 py-2 text-left hover:bg-cc-hover transition-colors cursor-pointer",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:`w-3 h-3 text-cc-muted transition-transform shrink-0 ${s?"rotate-90":""}`,children:r.jsx("path",{d:"M6 4l4 4-4 4"})}),r.jsx(Aa,{type:a}),r.jsx("span",{className:"text-xs font-medium text-cc-fg",children:l}),r.jsx("span",{className:"text-xs text-cc-muted truncate flex-1 font-mono-code",children:Ko(d.name,d.input)})]}),s&&r.jsx("div",{className:"px-3 pb-3 pt-0 border-t border-cc-border mt-0",children:r.jsx("pre",{className:"mt-2 text-[11px] text-cc-muted font-mono-code whitespace-pre-wrap leading-relaxed max-h-60 overflow-y-auto",children:JSON.stringify(d.input,null,2)})})]})})]})}return r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx("div",{className:"w-6 h-6 rounded-full bg-cc-primary/10 flex items-center justify-center shrink-0 mt-0.5",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 text-cc-primary",children:r.jsx("circle",{cx:"8",cy:"8",r:"3"})})}),r.jsx("div",{className:"flex-1 min-w-0",children:r.jsxs("div",{className:"border border-cc-border rounded-lg overflow-hidden bg-cc-card",children:[r.jsxs("button",{onClick:()=>n(!s),className:"w-full flex items-center gap-2.5 px-3 py-2 text-left hover:bg-cc-hover transition-colors cursor-pointer",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:`w-3 h-3 text-cc-muted transition-transform shrink-0 ${s?"rotate-90":""}`,children:r.jsx("path",{d:"M6 4l4 4-4 4"})}),r.jsx(Aa,{type:a}),r.jsx("span",{className:"text-xs font-medium text-cc-fg",children:l}),r.jsx("span",{className:"text-[10px] text-cc-muted bg-cc-hover rounded-full px-1.5 py-0.5 tabular-nums font-medium",children:c})]}),s&&r.jsx("div",{className:"border-t border-cc-border px-3 py-1.5",children:t.map((d,f)=>{const h=Ko(d.name,d.input);return r.jsxs("div",{className:"flex items-center gap-2 py-1 text-xs text-cc-muted font-mono-code truncate",children:[r.jsx("span",{className:"w-1 h-1 rounded-full bg-cc-muted/40 shrink-0"}),r.jsx("span",{className:"truncate",children:h||JSON.stringify(d.input).slice(0,80)})]},d.id||f)})})]})})]})}function NP({description:e,agentType:t,items:s}){var l;const[n,a]=w.useState(!0);return r.jsxs("div",{className:"ml-9 border-l-2 border-cc-border pl-4",children:[r.jsxs("button",{onClick:()=>a(!n),className:"w-full flex items-center gap-2 py-1.5 text-left cursor-pointer mb-1",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:`w-3 h-3 text-cc-muted transition-transform shrink-0 ${n?"rotate-90":""}`,children:r.jsx("path",{d:"M6 4l4 4-4 4"})}),r.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"w-3.5 h-3.5 text-cc-primary shrink-0",children:[r.jsx("circle",{cx:"8",cy:"8",r:"5"}),r.jsx("path",{d:"M8 5v3l2 1",strokeLinecap:"round"})]}),r.jsx("span",{className:"text-xs font-medium text-cc-fg truncate",children:e}),t&&r.jsx("span",{className:"text-[10px] text-cc-muted bg-cc-hover rounded-full px-1.5 py-0.5 shrink-0",children:t}),r.jsx("span",{className:"text-[10px] text-cc-muted bg-cc-hover rounded-full px-1.5 py-0.5 tabular-nums shrink-0 ml-auto",children:s.length})]}),n&&r.jsx("div",{className:"space-y-3 pb-2",children:r.jsx(Ax,{toolName:((l=s[0])==null?void 0:l.name)||"Grep",items:s})})]})}const No="codex-playground-demo";function EP(){return w.useEffect(()=>{const e=Y.getState(),t=e.sessions.get(No);return e.addSession({session_id:No,backend_type:"codex",model:"o3",cwd:"/Users/demo/project",tools:[],permissionMode:"bypassPermissions",claude_code_version:"0.1.0",mcp_servers:[],agents:[],slash_commands:[],skills:[],total_cost_usd:0,num_turns:8,context_used_percent:45,is_compacting:!1,git_branch:"main",is_worktree:!1,repo_root:"/Users/demo/project",git_ahead:0,git_behind:0,total_lines_added:0,total_lines_removed:0,total_duration_api_ms:0,codex_rate_limits:{primary:{usedPercent:62,windowDurationMins:300,resetsAt:Date.now()+2*36e5},secondary:{usedPercent:18,windowDurationMins:10080,resetsAt:Date.now()+5*864e5}},codex_token_details:{inputTokens:84230,outputTokens:12450,cachedInputTokens:41200,reasoningOutputTokens:8900,modelContextWindow:2e5}}),()=>{Y.setState(s=>{const n=new Map(s.sessions);return t?n.set(No,t):n.delete(No),{sessions:n}})}},[]),r.jsxs("div",{className:"w-[280px] border border-cc-border rounded-xl overflow-hidden bg-cc-card",children:[r.jsx(yC,{sessionId:No}),r.jsx(wC,{sessionId:No})]})}const cc="claude-playground-demo";function MP(){return w.useEffect(()=>{const e=Y.getState(),t=e.sessions.get(cc);return e.addSession({session_id:cc,backend_type:"claude",model:"claude-sonnet-4-20250514",cwd:"/Users/demo/project",tools:[],permissionMode:"default",claude_code_version:"1.0.0",mcp_servers:[],agents:[],slash_commands:[],skills:[],total_cost_usd:.87,num_turns:5,context_used_percent:38,is_compacting:!1,git_branch:"feat/auth",is_worktree:!1,repo_root:"/Users/demo/project",git_ahead:2,git_behind:0,total_lines_added:142,total_lines_removed:23,total_duration_api_ms:45e3,claude_token_details:{inputTokens:125400,outputTokens:18200,cacheReadInputTokens:98300,cacheCreationInputTokens:12600,contextWindow:2e5,costUsd:.87}}),()=>{Y.setState(s=>{const n=new Map(s.sessions);return t?n.set(cc,t):n.delete(cc),{sessions:n}})}},[]),r.jsx("div",{className:"w-[280px] border border-cc-border rounded-xl overflow-hidden bg-cc-card",children:r.jsx(SC,{sessionId:cc})})}function gg({updateInfo:e}){return w.useEffect(()=>{const t=Y.getState().updateInfo,s=Y.getState().updateDismissedVersion;return Y.getState().setUpdateInfo(e),s&&Y.setState({updateDismissedVersion:null}),()=>{Y.getState().setUpdateInfo(t),s&&Y.setState({updateDismissedVersion:s})}},[e]),r.jsx(DC,{})}function TP(){const[e,t]=w.useState(!1),[s,n]=w.useState("/tmp");return w.useEffect(()=>{se.getHome().then(a=>n(a.cwd)).catch(()=>{})},[]),r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsxs("button",{onClick:()=>t(!0),className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-cc-hover border border-cc-border hover:bg-cc-active transition-colors cursor-pointer",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-4 h-4 text-cc-primary",children:r.jsx("path",{d:"M4 1.5a.5.5 0 01.5-.5h7a.5.5 0 01.354.146l2 2A.5.5 0 0114 3.5v11a.5.5 0 01-.5.5h-11a.5.5 0 01-.5-.5v-13zm1 .5v12h8V4h-1.5a.5.5 0 01-.5-.5V2H5zm6 0v1h1l-1-1zM6.5 7a.5.5 0 000 1h5a.5.5 0 000-1h-5zm0 2a.5.5 0 000 1h5a.5.5 0 000-1h-5zm0 2a.5.5 0 000 1h3a.5.5 0 000-1h-3z"})}),r.jsx("span",{className:"text-xs font-medium text-cc-fg",children:"Edit CLAUDE.md"})]}),r.jsx("span",{className:"text-[11px] text-cc-muted",children:"Click to open the editor modal (uses server working directory)"}),r.jsx(gC,{cwd:s,open:e,onClose:()=>t(!1)})]})}function AP({server:e}){var l;const[t,s]=w.useState(!1),n={connected:{label:"Connected",cls:"text-cc-success bg-cc-success/10",dot:"bg-cc-success"},connecting:{label:"Connecting",cls:"text-cc-warning bg-cc-warning/10",dot:"bg-cc-warning animate-pulse"},failed:{label:"Failed",cls:"text-cc-error bg-cc-error/10",dot:"bg-cc-error"},disabled:{label:"Disabled",cls:"text-cc-muted bg-cc-hover",dot:"bg-cc-muted opacity-40"}},a=n[e.status]||n.disabled;return r.jsxs("div",{className:"rounded-lg border border-cc-border bg-cc-bg",children:[r.jsxs("div",{className:"flex items-center gap-2 px-2.5 py-2",children:[r.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${a.dot}`}),r.jsx("button",{onClick:()=>s(!t),className:"flex-1 min-w-0 text-left cursor-pointer",children:r.jsx("span",{className:"text-[12px] font-medium text-cc-fg truncate block",children:e.name})}),r.jsx("span",{className:`text-[9px] font-medium px-1.5 rounded-full leading-[16px] shrink-0 ${a.cls}`,children:a.label})]}),t&&r.jsxs("div",{className:"px-2.5 pb-2.5 space-y-1.5 border-t border-cc-border pt-2",children:[r.jsxs("div",{className:"text-[11px] text-cc-muted space-y-0.5",children:[r.jsxs("div",{className:"flex items-center gap-1",children:[r.jsx("span",{className:"text-cc-muted/60",children:"Type:"}),r.jsx("span",{children:e.config.type})]}),e.config.command&&r.jsxs("div",{className:"flex items-start gap-1",children:[r.jsx("span",{className:"text-cc-muted/60 shrink-0",children:"Cmd:"}),r.jsxs("span",{className:"font-mono text-[10px] break-all",children:[e.config.command,(l=e.config.args)!=null&&l.length?` ${e.config.args.join(" ")}`:""]})]}),e.config.url&&r.jsxs("div",{className:"flex items-start gap-1",children:[r.jsx("span",{className:"text-cc-muted/60 shrink-0",children:"URL:"}),r.jsx("span",{className:"font-mono text-[10px] break-all",children:e.config.url})]}),r.jsxs("div",{className:"flex items-center gap-1",children:[r.jsx("span",{className:"text-cc-muted/60",children:"Scope:"}),r.jsx("span",{children:e.scope})]})]}),e.error&&r.jsx("div",{className:"text-[11px] text-cc-error bg-cc-error/5 rounded px-2 py-1",children:e.error}),e.tools&&e.tools.length>0&&r.jsxs("div",{className:"space-y-1",children:[r.jsxs("span",{className:"text-[10px] text-cc-muted uppercase tracking-wider",children:["Tools (",e.tools.length,")"]}),r.jsx("div",{className:"flex flex-wrap gap-1",children:e.tools.map(c=>r.jsx("span",{className:"text-[10px] font-mono px-1.5 py-0.5 rounded bg-cc-hover text-cc-fg",children:c.name},c.name))})]})]})]})}const uc="playground-spectator";function RP(){return w.useEffect(()=>{const e=Y.getState();return e.addSession({session_id:uc,backend_type:"claude",model:"claude-sonnet-4-5",cwd:"/tmp",tools:[],permissionMode:"default",claude_code_version:"1.0.0",mcp_servers:[],agents:[],slash_commands:[],skills:[],total_cost_usd:0,num_turns:0,context_used_percent:0,is_compacting:!1,git_branch:"main",is_worktree:!1,repo_root:"/tmp",git_ahead:0,git_behind:0,total_lines_added:0,total_lines_removed:0,total_duration_api_ms:0}),e.setMyRole(uc,"spectator"),()=>{Y.setState(t=>{const s=new Map(t.sessions);s.delete(uc);const n=new Map(t.myRole);return n.delete(uc),{sessions:s,myRole:n}})}},[]),r.jsx("div",{className:"border border-cc-border rounded-xl overflow-hidden bg-cc-card",children:r.jsx(Zs,{permission:kP,sessionId:uc})})}function qd({state:e,position:t,total:s,speed:n}){const a=e==="playing",l=e==="ended";return r.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 bg-cc-sidebar border border-cc-border rounded-lg",children:[r.jsx("button",{className:"w-8 h-8 rounded-full bg-cc-primary/10 flex items-center justify-center text-cc-primary hover:bg-cc-primary/20 transition-colors cursor-pointer shrink-0",children:l?r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:r.jsx("path",{d:"M2.5 2a.5.5 0 01.854-.354l4.646 4.647V2.5a.5.5 0 01.854-.354l5 5a.5.5 0 010 .708l-5 5A.5.5 0 018 12.5V8.707l-4.646 4.647A.5.5 0 012.5 13V2z"})}):a?r.jsxs("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:[r.jsx("rect",{x:"4",y:"3",width:"3",height:"10",rx:"0.75"}),r.jsx("rect",{x:"9",y:"3",width:"3",height:"10",rx:"0.75"})]}):r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:r.jsx("path",{d:"M4 2l10 6-10 6V2z"})})}),r.jsx("div",{className:"flex-1 min-w-0",children:r.jsx("div",{className:"relative w-full h-1.5 rounded-full bg-cc-hover overflow-hidden",children:r.jsx("div",{className:"absolute inset-y-0 left-0 rounded-full bg-cc-primary transition-all duration-300",style:{width:`${s>0?t/s*100:0}%`}})})}),r.jsxs("span",{className:"text-[11px] text-cc-muted tabular-nums font-mono-code shrink-0",children:[t,"/",s]}),r.jsx("div",{className:"flex items-center gap-0.5 shrink-0",children:[1,2,4,8].map(c=>r.jsxs("button",{className:`px-1.5 py-0.5 text-[10px] font-medium rounded transition-colors cursor-pointer ${c===n?"bg-cc-primary/20 text-cc-primary":"text-cc-muted hover:bg-cc-hover"}`,children:[c,"x"]},c))})]})}function DP({task:e}){const t=e.status==="completed",s=e.status==="in_progress";return r.jsxs("div",{className:`px-2.5 py-2 rounded-lg ${t?"opacity-50":""}`,children:[r.jsxs("div",{className:"flex items-start gap-2",children:[r.jsx("span",{className:"shrink-0 flex items-center justify-center w-4 h-4 mt-px",children:s?r.jsx("svg",{className:"w-4 h-4 text-cc-primary animate-spin",viewBox:"0 0 16 16",fill:"none",children:r.jsx("circle",{cx:"8",cy:"8",r:"6",stroke:"currentColor",strokeWidth:"1.5",strokeDasharray:"28",strokeDashoffset:"8",strokeLinecap:"round"})}):t?r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-4 h-4 text-cc-success",children:r.jsx("path",{fillRule:"evenodd",d:"M8 15A7 7 0 108 1a7 7 0 000 14zm3.354-9.354a.5.5 0 00-.708-.708L7 8.586 5.354 6.94a.5.5 0 10-.708.708l2 2a.5.5 0 00.708 0l4-4z",clipRule:"evenodd"})}):r.jsx("svg",{viewBox:"0 0 16 16",fill:"none",className:"w-4 h-4 text-cc-muted",children:r.jsx("circle",{cx:"8",cy:"8",r:"6",stroke:"currentColor",strokeWidth:"1.5"})})}),r.jsx("span",{className:`text-[13px] leading-snug flex-1 ${t?"text-cc-muted line-through":"text-cc-fg"}`,children:e.subject})]}),s&&e.activeForm&&r.jsx("p",{className:"mt-1 ml-6 text-[11px] text-cc-muted italic truncate",children:e.activeForm}),e.blockedBy&&e.blockedBy.length>0&&r.jsxs("p",{className:"mt-1 ml-6 text-[11px] text-cc-muted flex items-center gap-1",children:[r.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",className:"w-3 h-3 shrink-0",children:[r.jsx("circle",{cx:"8",cy:"8",r:"6",stroke:"currentColor",strokeWidth:"1.5"}),r.jsx("path",{d:"M5 8h6",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]}),r.jsxs("span",{children:["blocked by ",e.blockedBy.map(n=>`#${n}`).join(", ")]})]})]})}const LP={checking_image:"Checking image",pulling_image:"Pulling image",creating_container:"Creating container",seeding_auth:"Seeding authentication",launching_agent:"Launching agent"};function BP(e,t,s){return t?OP(t,s):PP(e,s)}function OP(e,t){const s=["checking_image","pulling_image","creating_container","seeding_auth","launching_agent"],n=s.indexOf(e.step),a=s.map((l,c)=>{let d="pending";return c<n?d="done":c===n&&(d="active"),{label:LP[l]||l,status:d}});if(t)for(const l of a)l.status="done";return a}function zP(e,t){return t?"done":e?"active":"pending"}function PP(e,t){const s=e==="starting",n=t||e==="connected"||e==="running";return[{label:"Spawning process",status:s||n?"done":"active"},{label:"Waiting for connection",status:zP(s,n)},{label:"Ready",status:n?"done":"pending"}]}function $P(e,t=2e3){const[s,n]=w.useState(!1),a=w.useRef(void 0);return w.useEffect(()=>(clearTimeout(a.current),e?a.current=setTimeout(()=>n(!0),t):n(!1),()=>clearTimeout(a.current)),[e,t]),s}function IP(){const e=Y(k=>k.sdkSessions),t=Y(k=>k.cliConnected),s=Y(k=>k.sessionCreating),n=Y(k=>k.creationProgress),a=Y(k=>k.creationError),l=Y(k=>k.sessionNames),c=e.filter(k=>k.state==="starting"&&!k.archived),d=s&&!a,f=c.length>0||d,h=c.length>0?c[c.length-1]:null,m=h==null?void 0:h.sessionId,g=m?l.get(m):null,b=h==null?void 0:h.state,v=m?t.get(m)??!1:!1,y=BP(b,d?n:null,v),S=y.every(k=>k.status==="done"),j=$P(S);return!f&&!a||j&&!a?null:a?r.jsx("div",{className:"fixed bottom-4 left-4 z-40 w-72 rounded-xl border border-cc-error/30 bg-cc-card shadow-float animate-slide-up overflow-hidden",children:r.jsxs("div",{className:"px-3 py-2.5 flex items-center gap-2",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-4 h-4 text-cc-error shrink-0","aria-hidden":!0,children:r.jsx("path",{d:"M3.72 3.72a.75.75 0 011.06 0L8 6.94l3.22-3.22a.75.75 0 111.06 1.06L9.06 8l3.22 3.22a.75.75 0 11-1.06 1.06L8 9.06l-3.22 3.22a.75.75 0 01-1.06-1.06L6.94 8 3.72 4.78a.75.75 0 010-1.06z"})}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-[11px] font-medium text-cc-error",children:"Launch failed"}),r.jsx("p",{className:"text-[10px] text-cc-muted truncate",children:a})]})]})}):r.jsxs("div",{className:"fixed bottom-4 left-4 z-40 w-64 rounded-xl border border-cc-border/60 bg-cc-card/95 backdrop-blur-xl shadow-float animate-slide-up overflow-hidden",style:{transition:"opacity 0.4s ease-out",opacity:j?0:1},children:[r.jsxs("div",{className:"px-3 py-2 border-b border-cc-border/30 flex items-center gap-2",children:[!S&&r.jsxs("svg",{className:"w-3.5 h-3.5 text-cc-primary animate-spin shrink-0",viewBox:"0 0 16 16",fill:"none","aria-hidden":!0,children:[r.jsx("circle",{cx:"8",cy:"8",r:"6",stroke:"currentColor",strokeWidth:"2",opacity:"0.25"}),r.jsx("path",{d:"M14 8a6 6 0 00-6-6",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]}),S&&r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 text-cc-success shrink-0","aria-hidden":!0,children:r.jsx("path",{d:"M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"})}),r.jsx("span",{className:"text-[11px] font-medium text-cc-fg truncate",children:S?"Session ready":"Launching session"}),g&&r.jsx("span",{className:"text-[9px] text-cc-muted font-mono-code truncate ml-auto",children:g})]}),r.jsx("div",{className:"px-3 py-2 space-y-1",children:y.map(k=>r.jsx(HP,{step:k},k.label))}),(n==null?void 0:n.percent)!=null&&r.jsxs("div",{className:"px-3 pb-2",children:[r.jsx("div",{className:"w-full h-1 rounded-full bg-cc-hover overflow-hidden",children:r.jsx("div",{className:"h-full rounded-full bg-cc-primary transition-all duration-300",style:{width:`${Math.min(100,n.percent)}%`}})}),r.jsx("p",{className:"text-[9px] text-cc-muted/60 font-mono-code mt-0.5 truncate",children:n.message})]})]})}function FP(e){return e==="done"?"text-cc-muted/50":e==="active"?"text-cc-fg":"text-cc-muted/40"}function HP({step:e}){return r.jsxs("div",{className:"flex items-center gap-2",children:[e.status==="done"&&r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 text-cc-success shrink-0","aria-hidden":!0,children:r.jsx("path",{d:"M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"})}),e.status==="active"&&r.jsxs("svg",{className:"w-3 h-3 text-cc-primary animate-spin shrink-0",viewBox:"0 0 16 16",fill:"none","aria-hidden":!0,children:[r.jsx("circle",{cx:"8",cy:"8",r:"5",stroke:"currentColor",strokeWidth:"2",opacity:"0.25"}),r.jsx("path",{d:"M13 8a5 5 0 00-5-5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]}),e.status==="pending"&&r.jsx("svg",{className:"w-3 h-3 text-cc-muted/30 shrink-0",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5","aria-hidden":!0,children:r.jsx("circle",{cx:"8",cy:"8",r:"4.5"})}),r.jsx("span",{className:`text-[10px] ${FP(e.status)}`,children:e.label})]})}function Rx(e){if(e<6e4)return`${Math.round(e/1e3)}s`;const t=Math.floor(e/6e4);return t<60?`${t}m`:`${Math.floor(t/60)}h ${t%60}m`}function UP(e){return new Date(e).toLocaleDateString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function VP(e){return e==="playable"?"Playable":e==="metadata"?"Metadata only":"All types"}function WP(e){if(e.compatible)return"Protocol Compatible";const t=e.diffs.length;return`${t} Issue${t>1?"s":""}`}const qP=new Set(["assistant","result","user_message","stream_event","permission_request","permission_cancelled","status_change","session_init","session_update","cli_connected","error","tool_progress","session_name_update"]);function xg(e){return Object.keys(e).some(t=>qP.has(t))}const LC={claude:"text-[#5BA8A0] bg-[#5BA8A0]/10",codex:"text-blue-500 bg-blue-500/10",goose:"text-amber-500 bg-amber-500/10",aider:"text-purple-500 bg-purple-500/10",openhands:"text-rose-500 bg-rose-500/10",openclaw:"text-orange-500 bg-orange-500/10",opencode:"text-teal-500 bg-teal-500/10"};function GP({embedded:e=!1}){const[t,s]=w.useState([]),[n,a]=w.useState(!0),[l,c]=w.useState(!1),[d,f]=w.useState(null),[h,m]=w.useState(null),[g,b]=w.useState(null),[v,y]=w.useState(!1),[S,j]=w.useState(""),[k,E]=w.useState("all"),[N,B]=w.useState("all"),[A,P]=w.useState("newest"),K=w.useCallback(()=>{se.listHubRecordings().then(s).catch(()=>{}).finally(()=>a(!1))},[]);w.useEffect(()=>{K()},[K]);async function X(){c(!0);try{(await se.indexAllRecordings()).imported>0&&K()}catch{}c(!1)}async function Z(R){if(d===R){f(null);return}f(R),m(null),b(null),y(!0);try{const[M,O]=await Promise.all([se.validateRecording(R),se.getRecordingDiagnostics(R)]);m(M),b(O)}catch{}y(!1)}async function I(R){await se.deleteHubRecording(R).catch(()=>{}),K()}const H=w.useCallback(R=>{globalThis.location.hash=`#/replay/${encodeURIComponent(R)}`},[]),F=w.useMemo(()=>[...new Set(t.map(M=>M.backendType))].sort((M,O)=>M.localeCompare(O)),[t]),G=w.useMemo(()=>{const R={all:t.length};for(const M of t)R[M.backendType]=(R[M.backendType]||0)+1;return R},[t]),q=w.useMemo(()=>{let R=t;if(S){const M=S.toLowerCase();R=R.filter(O=>O.filename.toLowerCase().includes(M)||O.backendType.includes(M)||O.tags.some(W=>W.toLowerCase().includes(M)))}return k!=="all"&&(R=R.filter(M=>M.backendType===k)),N==="playable"?R=R.filter(M=>xg(M.messageTypeSummary)):N==="metadata"&&(R=R.filter(M=>!xg(M.messageTypeSummary))),[...R].sort((M,O)=>A==="oldest"?M.startedAt-O.startedAt:A==="longest"?O.duration-M.duration:A==="most-messages"?O.entryCount-M.entryCount:O.startedAt-M.startedAt)},[t,S,k,N,A]);return r.jsxs("div",{className:e?"px-4 py-6 max-w-5xl mx-auto":"p-6 max-w-5xl mx-auto",children:[r.jsxs("div",{className:"flex items-center justify-between mb-5",children:[r.jsxs("div",{children:[r.jsx("h1",{className:"text-lg font-semibold text-cc-fg",children:"Recording Hub"}),r.jsx("p",{className:"text-[12px] text-cc-muted mt-0.5",children:"Browse, validate, and diagnose session recordings"})]}),r.jsx("button",{onClick:X,disabled:l,className:"px-3 py-1.5 rounded-lg bg-cc-primary text-white text-[12px] font-medium hover:bg-cc-primary-hover transition-colors cursor-pointer disabled:opacity-40",children:l?"Indexing...":"Index Recordings"})]}),r.jsx("div",{className:"mb-3",children:r.jsx("input",{value:S,onChange:R=>j(R.target.value),placeholder:"Search by filename, backend, or tag...",className:"w-full h-9 px-3 rounded-lg border border-cc-border bg-cc-input-bg text-[13px] text-cc-fg placeholder:text-cc-muted/30 focus:outline-none focus:ring-2 focus:ring-cc-primary/20"})}),r.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-4",children:[r.jsxs("div",{className:"flex items-center gap-1",children:[r.jsxs("button",{onClick:()=>E("all"),className:`px-2 py-1 rounded-md text-[10px] font-medium transition-colors cursor-pointer ${k==="all"?"bg-cc-primary/10 text-cc-primary":"text-cc-muted hover:text-cc-fg hover:bg-cc-hover"}`,children:["All ",r.jsx("span",{className:"ml-0.5 opacity-60 tabular-nums",children:G.all})]}),F.map(R=>{const M=LC[R]||"text-cc-muted bg-cc-hover";return r.jsxs("button",{onClick:()=>E(k===R?"all":R),className:`px-2 py-1 rounded-md text-[10px] font-medium transition-colors cursor-pointer ${k===R?M:"text-cc-muted hover:text-cc-fg hover:bg-cc-hover"}`,children:[R," ",r.jsx("span",{className:"ml-0.5 opacity-60 tabular-nums",children:G[R]||0})]},R)})]}),r.jsx("div",{className:"w-px h-4 bg-cc-border/50"}),r.jsx("div",{className:"flex items-center gap-1",children:["all","playable","metadata"].map(R=>r.jsx("button",{onClick:()=>B(R),className:`px-2 py-1 rounded-md text-[10px] font-medium transition-colors cursor-pointer ${N===R?"bg-cc-primary/10 text-cc-primary":"text-cc-muted hover:text-cc-fg hover:bg-cc-hover"}`,children:VP(R)},R))}),r.jsx("div",{className:"w-px h-4 bg-cc-border/50"}),r.jsxs("select",{value:A,onChange:R=>P(R.target.value),className:"h-7 px-2 rounded-md border border-cc-border bg-cc-input-bg text-[10px] text-cc-fg cursor-pointer","aria-label":"Sort recordings",children:[r.jsx("option",{value:"newest",children:"Newest first"}),r.jsx("option",{value:"oldest",children:"Oldest first"}),r.jsx("option",{value:"longest",children:"Longest duration"}),r.jsx("option",{value:"most-messages",children:"Most messages"})]}),r.jsxs("span",{className:"text-[10px] text-cc-muted/50 ml-auto tabular-nums",children:[q.length," recording",q.length===1?"":"s"]})]}),n&&r.jsx("p",{className:"text-cc-muted text-sm",children:"Loading..."}),!n&&q.length===0&&r.jsxs("div",{className:"text-center py-12 text-cc-muted",children:[r.jsx("p",{className:"text-sm",children:"No recordings found yet"}),r.jsx("p",{className:"text-xs mt-1",children:'Use "Index Recordings" to refresh the recording index'})]}),r.jsx("div",{className:"space-y-2",children:q.map(R=>r.jsxs("div",{children:[r.jsx(KP,{recording:R,playable:xg(R.messageTypeSummary),isExpanded:d===R.id,onExpand:()=>Z(R.id),onDelete:()=>I(R.id),onReplay:()=>H(R.filename)}),d===R.id&&r.jsx(YP,{recording:R,validation:h,diagnostics:g,loading:v})]},R.id))})]})}function KP({recording:e,playable:t,isExpanded:s,onExpand:n,onDelete:a,onReplay:l}){const c=LC[e.backendType]||"text-cc-muted bg-cc-hover";return r.jsx("div",{className:`border rounded-lg transition-all ${s?"border-cc-primary/30 bg-cc-primary/[0.02]":"border-cc-border bg-cc-card hover:shadow-panel"}`,children:r.jsxs("div",{className:"flex items-center gap-3 px-4 py-3",children:[r.jsx("span",{className:`text-[9px] font-semibold px-2 py-0.5 rounded-full ${c}`,children:e.backendType}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("span",{className:"text-[12px] font-medium text-cc-fg truncate block font-mono-code",children:e.filename}),r.jsxs("div",{className:"flex items-center gap-3 mt-0.5 text-[10px] text-cc-muted",children:[r.jsx("span",{children:UP(e.startedAt)}),r.jsx("span",{className:"tabular-nums",children:Rx(e.duration)}),r.jsxs("span",{className:"tabular-nums",children:[e.entryCount," msgs"]}),!t&&r.jsx("span",{className:"text-cc-muted/40",children:"metadata only"})]})]}),e.tags.length>0&&r.jsx("div",{className:"flex gap-1 shrink-0",children:e.tags.slice(0,3).map(d=>r.jsx("span",{className:"text-[8px] px-1.5 py-0.5 rounded-full bg-cc-hover text-cc-muted",children:d},d))}),r.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[r.jsx("button",{onClick:l,disabled:!t,title:t?"Replay":"No playable messages",className:`p-1.5 rounded-md transition-colors ${t?"hover:bg-cc-hover text-cc-primary cursor-pointer":"text-cc-muted/30 cursor-not-allowed"}`,children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5","aria-hidden":!0,children:r.jsx("path",{d:"M4 2l10 6-10 6V2z"})})}),r.jsx("button",{onClick:n,title:"Details",className:`p-1.5 rounded-md hover:bg-cc-hover cursor-pointer transition-colors ${s?"text-cc-primary":"text-cc-muted"}`,children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5","aria-hidden":!0,children:r.jsx("path",{d:"M8 2a6 6 0 100 12A6 6 0 008 2zm.75 3.5a.75.75 0 00-1.5 0v2.25H5a.75.75 0 000 1.5h2.25V11.5a.75.75 0 001.5 0V9.25H11a.75.75 0 000-1.5H8.75V5.5z"})})}),r.jsx("button",{onClick:a,title:"Remove from hub",className:"p-1.5 rounded-md hover:bg-cc-hover text-cc-muted hover:text-cc-error cursor-pointer transition-colors",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5","aria-hidden":!0,children:r.jsx("path",{d:"M6.5 1.75a.25.25 0 01.25-.25h2.5a.25.25 0 01.25.25V3h-3V1.75zM11 3V1.75A1.75 1.75 0 009.25 0h-2.5A1.75 1.75 0 005 1.75V3H2.75a.75.75 0 000 1.5h.928l.856 10.268A1.75 1.75 0 006.282 16h3.436a1.75 1.75 0 001.748-1.632l.856-10.268h.928a.75.75 0 000-1.5H11z"})})})]})]})})}function YP({recording:e,validation:t,diagnostics:s,loading:n}){return n?r.jsxs("div",{className:"ml-4 my-2 flex items-center gap-2 text-cc-muted text-[11px]",children:[r.jsx("div",{className:"w-3.5 h-3.5 border-2 border-cc-primary border-t-transparent rounded-full animate-spin"}),"Analyzing recording..."]}):r.jsxs("div",{className:"mx-4 mb-3 mt-1 grid grid-cols-1 sm:grid-cols-2 gap-3",children:[t&&r.jsxs("div",{className:`rounded-lg border p-3 ${t.compatible?"border-cc-success/30 bg-cc-success/[0.03]":"border-cc-error/30 bg-cc-error/[0.03]"}`,children:[r.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[t.compatible?r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-4 h-4 text-cc-success","aria-hidden":!0,children:r.jsx("path",{d:"M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"})}):r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-4 h-4 text-cc-error","aria-hidden":!0,children:r.jsx("path",{d:"M3.72 3.72a.75.75 0 011.06 0L8 6.94l3.22-3.22a.75.75 0 111.06 1.06L9.06 8l3.22 3.22a.75.75 0 11-1.06 1.06L8 9.06l-3.22 3.22a.75.75 0 01-1.06-1.06L6.94 8 3.72 4.78a.75.75 0 010-1.06z"})}),r.jsx("span",{className:"text-[12px] font-semibold text-cc-fg",children:WP(t)})]}),r.jsxs("div",{className:"text-[10px] text-cc-muted space-y-0.5",children:[r.jsxs("p",{children:["Checked ",t.checkedMessages," of ",t.totalMessages," messages"]}),r.jsx("div",{className:"flex flex-wrap gap-1 mt-1",children:Object.entries(t.messageTypeBreakdown).slice(0,8).map(([a,l])=>r.jsxs("span",{className:`px-1.5 py-0.5 rounded text-[8px] font-mono-code ${l.issues>0?"bg-cc-error/10 text-cc-error":"bg-cc-hover text-cc-muted"}`,children:[a,": ",l.count]},a))})]})]}),s&&r.jsxs("div",{className:"rounded-lg border border-cc-border p-3",children:[r.jsx("h4",{className:"text-[12px] font-semibold text-cc-fg mb-2",children:"Health Report"}),r.jsxs("div",{className:"grid grid-cols-2 gap-x-4 gap-y-1 text-[10px]",children:[r.jsx("span",{className:"text-cc-muted",children:"Duration"}),r.jsx("span",{className:"text-cc-fg font-mono-code tabular-nums",children:Rx(s.totalDuration)}),r.jsx("span",{className:"text-cc-muted",children:"Messages"}),r.jsx("span",{className:"text-cc-fg font-mono-code tabular-nums",children:s.totalMessages}),r.jsx("span",{className:"text-cc-muted",children:"Msg/min"}),r.jsx("span",{className:"text-cc-fg font-mono-code tabular-nums",children:s.messageRate}),r.jsx("span",{className:"text-cc-muted",children:"Disconnections"}),r.jsx("span",{className:`font-mono-code tabular-nums ${s.disconnections.length>0?"text-cc-error":"text-cc-fg"}`,children:s.disconnections.length}),r.jsx("span",{className:"text-cc-muted",children:"Data Gaps"}),r.jsx("span",{className:`font-mono-code tabular-nums ${s.dataGaps.length>0?"text-cc-warning":"text-cc-fg"}`,children:s.dataGaps.length}),s.avgPermissionResponseMs!==null&&r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"text-cc-muted",children:"Avg Perm Response"}),r.jsx("span",{className:"text-cc-fg font-mono-code tabular-nums",children:Rx(s.avgPermissionResponseMs)})]})]}),r.jsx("div",{className:"mt-2 space-y-0.5",children:s.patterns.map(a=>r.jsx("p",{className:`text-[9px] ${a.includes("No anomalies")?"text-cc-success":"text-cc-warning"}`,children:a},a))})]})]})}function XP(e){const t=Math.floor(e/1e3);if(t<60)return`${t}s`;const s=Math.floor(t/60);return s<60?`${s}m ${t%60}s`:`${Math.floor(s/60)}h ${s%60}m`}function o2(e){return new Date(e).toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit",second:"2-digit"})}const l2={claude:"text-[#5BA8A0]",codex:"text-blue-500",goose:"text-amber-500",aider:"text-purple-500",openhands:"text-rose-500",openclaw:"text-orange-500",opencode:"text-teal-500"};function JP({embedded:e=!1}){const[t,s]=w.useState(null),[n,a]=w.useState(!0),l=Y(d=>d.sessionNames),c=w.useCallback(()=>{se.getMonitorStats().then(s).catch(()=>{}).finally(()=>a(!1))},[]);return w.useEffect(()=>{c();const d=setInterval(c,3e3);return()=>clearInterval(d)},[c]),n?r.jsx("div",{className:"flex items-center justify-center h-64 text-cc-muted text-sm",children:"Loading monitor..."}):t?r.jsxs("div",{className:e?"px-4 py-6 max-w-5xl mx-auto":"p-6 max-w-5xl mx-auto",children:[r.jsxs("div",{className:"flex items-center justify-between mb-5",children:[r.jsxs("div",{children:[r.jsx("h1",{className:"text-lg font-semibold text-cc-fg",children:"Protocol Monitor"}),r.jsx("p",{className:"text-[12px] text-cc-muted mt-0.5",children:"Real-time WebSocket message flow and health metrics"})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"w-2 h-2 rounded-full bg-cc-success animate-breathing"}),r.jsxs("span",{className:"text-[11px] text-cc-muted font-mono-code",children:["Live · ",XP(t.uptime)]})]})]}),r.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3 mb-5",children:[r.jsx(Gd,{label:"Total Messages",value:t.totalMessages.toLocaleString()}),r.jsx(Gd,{label:"Messages/min",value:String(t.globalMessagesPerMinute),accent:t.globalMessagesPerMinute>0}),r.jsx(Gd,{label:"Active Sessions",value:String(t.activeSessions)}),r.jsx(Gd,{label:"Errors",value:String(t.totalErrors),error:t.totalErrors>0})]}),Object.keys(t.backendBreakdown).length>0&&r.jsxs("div",{className:"mb-5",children:[r.jsx("h2",{className:"text-[12px] font-semibold text-cc-fg mb-2",children:"Backend Breakdown"}),r.jsx("div",{className:"flex flex-wrap gap-2",children:Object.entries(t.backendBreakdown).map(([d,f])=>r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg border border-cc-border bg-cc-card",children:[r.jsx("span",{className:`text-[12px] font-semibold ${l2[d]||"text-cc-muted"}`,children:d}),r.jsxs("span",{className:"text-[11px] text-cc-fg font-mono-code tabular-nums",children:[f.messages," msgs"]}),f.errors>0&&r.jsxs("span",{className:"text-[10px] text-cc-error font-mono-code tabular-nums",children:[f.errors," err"]})]},d))})]}),Object.keys(t.messageTypeGlobal).length>0&&r.jsxs("div",{className:"mb-5",children:[r.jsx("h2",{className:"text-[12px] font-semibold text-cc-fg mb-2",children:"Message Types (5min window)"}),r.jsx("div",{className:"flex flex-wrap gap-1",children:Object.entries(t.messageTypeGlobal).sort(([,d],[,f])=>f-d).slice(0,20).map(([d,f])=>r.jsxs("span",{className:"text-[9px] font-mono-code px-1.5 py-0.5 rounded bg-cc-hover text-cc-muted",children:[d,": ",r.jsx("span",{className:"text-cc-fg tabular-nums",children:f})]},d))})]}),t.sessionStats.length>0&&r.jsxs("div",{className:"mb-5",children:[r.jsx("h2",{className:"text-[12px] font-semibold text-cc-fg mb-2",children:"Active Sessions"}),r.jsx("div",{className:"space-y-1.5",children:t.sessionStats.map(d=>{const f=l.get(d.sessionId)||d.sessionId.slice(0,8);return r.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 rounded-lg border border-cc-border bg-cc-card",children:[r.jsx("span",{className:`text-[10px] font-semibold px-1.5 py-0.5 rounded-full ${l2[d.backendType]||"text-cc-muted"} bg-current/10`,children:d.backendType}),r.jsx("span",{className:"text-[12px] font-medium text-cc-fg truncate flex-1",children:f}),r.jsxs("span",{className:"text-[10px] text-cc-muted font-mono-code tabular-nums",children:[d.messageCount," msgs"]}),r.jsxs("span",{className:"text-[10px] text-cc-muted font-mono-code tabular-nums",children:[d.messagesPerMinute,"/min"]}),d.errorCount>0&&r.jsxs("span",{className:"text-[10px] text-cc-error font-mono-code tabular-nums",children:[d.errorCount," err"]}),r.jsx("span",{className:"text-[10px] text-cc-muted/50 font-mono-code",children:o2(d.lastMessageAt)})]},d.sessionId)})})]}),t.recentDrifts.length>0&&r.jsxs("div",{children:[r.jsx("h2",{className:"text-[12px] font-semibold text-cc-error mb-2",children:"Protocol Drift Alerts"}),r.jsx("div",{className:"space-y-1",children:t.recentDrifts.map(d=>r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg border border-cc-error/20 bg-cc-error/[0.03]",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 text-cc-error shrink-0","aria-hidden":!0,children:r.jsx("path",{d:"M8.22 1.754a.25.25 0 00-.44 0L1.698 13.132a.25.25 0 00.22.368h12.164a.25.25 0 00.22-.368L8.22 1.754z"})}),r.jsx("span",{className:"text-[11px] font-medium text-cc-fg",children:d.backendType}),r.jsxs("span",{className:"text-[10px] text-cc-muted font-mono-code",children:[d.direction," ",d.messageType]}),r.jsx("span",{className:"text-[10px] text-cc-error/70 flex-1 truncate",children:d.details}),r.jsx("span",{className:"text-[9px] text-cc-muted/50 font-mono-code",children:o2(d.timestamp)})]},`${d.backendType}-${d.messageType}-${d.timestamp}`))})]}),t.activeSessions===0&&t.totalMessages===0&&r.jsxs("div",{className:"text-center py-12 text-cc-muted",children:[r.jsx("p",{className:"text-sm",children:"No activity yet"}),r.jsx("p",{className:"text-xs mt-1",children:"Start a session to see real-time protocol metrics"})]})]}):r.jsx("div",{className:"flex items-center justify-center h-64 text-cc-muted text-sm",children:"Monitor not available"})}function QP(e,t){return e?"text-cc-error":t?"text-cc-primary":"text-cc-fg"}function Gd({label:e,value:t,accent:s=!1,error:n=!1}){return r.jsxs("div",{className:"rounded-xl border border-cc-border bg-cc-card px-4 py-3",children:[r.jsx("p",{className:"text-[10px] text-cc-muted uppercase tracking-wider mb-1",children:e}),r.jsx("p",{className:`text-xl font-bold font-mono-code tabular-nums ${QP(n,s)}`,children:t})]})}const ZP={help:"Show available commands and keyboard shortcuts",clear:"Clear conversation history and start fresh",compact:"Compact conversation to save context window space",cost:"Show token usage and cost for this session",doctor:"Check health of Claude Code installation",init:"Initialize a new CLAUDE.md project file",login:"Switch accounts or re-authenticate",logout:"Sign out of current account",memory:"View and edit CLAUDE.md memory files",model:"Switch the AI model for this session",permissions:"View and manage tool permissions",review:"Review recent changes made by Claude",status:"Show session status, model, and connection info","terminal-setup":"Configure terminal integration (Shift+Enter)",vim:"Toggle vim keybindings mode"};function e9({embedded:e=!1}){var F,G;const[t,s]=w.useState([]),[n,a]=w.useState([]),[l,c]=w.useState(!0),[d,f]=w.useState(""),[h,m]=w.useState(null),[g,b]=w.useState(""),[v,y]=w.useState(!1),S=Y(q=>q.currentSessionId),j=Y(q=>q.sessions),k=Y(q=>q.sdkSessions),E=S?((F=j.get(S))==null?void 0:F.cwd)||((G=k.find(q=>q.sessionId===S))==null?void 0:G.cwd):void 0,N=w.useCallback(()=>{se.discoverCommands(E).then(q=>{s(q.commands),a(q.skills)}).catch(()=>{}).finally(()=>c(!1))},[E]);w.useEffect(()=>{N()},[N]);async function B(q){if(h===q){m(null);return}m(q),y(!0);try{const R=await se.readCommand(q);b(R.content)}catch{b("Failed to read file")}y(!1)}const A=d.toLowerCase(),P=A?t.filter(q=>q.name.includes(A)||q.description.toLowerCase().includes(A)):t,K=A?n.filter(q=>q.slug.includes(A)||q.name.toLowerCase().includes(A)||q.description.toLowerCase().includes(A)):n,[X,Z]=w.useState([]);w.useEffect(()=>{se.getSlashCommands().then(q=>{Z(q.commands.map(R=>({name:R,description:ZP[R]||""})))}).catch(()=>{})},[]);const I=A?X.filter(q=>q.name.includes(A)||q.description.toLowerCase().includes(A)):X,H=P.length+K.length+I.length;return r.jsxs("div",{className:e?"px-4 py-6 max-w-4xl mx-auto":"p-6 max-w-4xl mx-auto",children:[r.jsxs("div",{className:"flex items-center justify-between mb-5",children:[r.jsxs("div",{children:[r.jsx("h1",{className:"text-lg font-semibold text-cc-fg",children:"Commands & Skills"}),r.jsxs("p",{className:"text-[12px] text-cc-muted mt-0.5",children:["Slash commands from ",r.jsx("code",{className:"font-mono-code text-[10px] bg-cc-hover px-1 rounded",children:"~/.claude/commands/"})," and skills from ",r.jsx("code",{className:"font-mono-code text-[10px] bg-cc-hover px-1 rounded",children:"~/.claude/skills/"})]})]}),r.jsx("button",{onClick:N,className:"px-3 py-1.5 rounded-lg text-[12px] text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:"Refresh"})]}),r.jsx("div",{className:"mb-4",children:r.jsx("input",{value:d,onChange:q=>f(q.target.value),placeholder:"Search commands and skills...",className:"w-full h-9 px-3 rounded-lg border border-cc-border bg-cc-input-bg text-[13px] text-cc-fg placeholder:text-cc-muted/30 focus:outline-none focus:ring-2 focus:ring-cc-primary/20"})}),l&&r.jsx("p",{className:"text-cc-muted text-sm",children:"Discovering commands..."}),!l&&H===0&&r.jsxs("div",{className:"text-center py-12 text-cc-muted",children:[r.jsx("p",{className:"text-sm",children:"No commands or skills found"}),r.jsxs("p",{className:"text-xs mt-1",children:["Create ",r.jsx("code",{className:"font-mono-code bg-cc-hover px-1 rounded",children:"~/.claude/commands/my-command.md"})," to add a slash command"]})]}),I.length>0&&r.jsxs("div",{className:"mb-6",children:[r.jsxs("h2",{className:"text-[11px] font-semibold text-cc-muted uppercase tracking-wider mb-2",children:["Built-in Commands ",r.jsx("span",{className:"text-cc-muted/50 tabular-nums ml-1",children:I.length})]}),r.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-1.5",children:I.map(q=>r.jsxs("div",{className:"flex items-center gap-3 px-4 py-2.5 rounded-lg border border-cc-border bg-cc-card",children:[r.jsx("span",{className:"w-7 h-7 rounded-md bg-cc-muted/10 text-cc-muted flex items-center justify-center text-[13px] font-bold shrink-0",children:"/"}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("span",{className:"text-[12px] font-medium text-cc-fg font-mono-code",children:["/",q.name]}),r.jsx("p",{className:"text-[10px] text-cc-muted truncate",children:q.description})]})]},q.name))})]}),P.length>0&&r.jsxs("div",{className:"mb-6",children:[r.jsxs("h2",{className:"text-[11px] font-semibold text-cc-muted uppercase tracking-wider mb-2",children:["Custom Commands ",r.jsx("span",{className:"text-cc-muted/50 tabular-nums ml-1",children:P.length})]}),r.jsx("div",{className:"space-y-1.5",children:P.map(q=>r.jsxs("div",{children:[r.jsxs("button",{onClick:()=>B(q.path),className:`w-full flex items-center gap-3 px-4 py-2.5 rounded-lg border text-left transition-all cursor-pointer ${h===q.path?"border-cc-primary/30 bg-cc-primary/[0.03]":"border-cc-border bg-cc-card hover:shadow-panel"}`,children:[r.jsx("span",{className:"w-7 h-7 rounded-md bg-cc-primary/10 text-cc-primary flex items-center justify-center text-[13px] font-bold shrink-0",children:"/"}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("span",{className:"text-[13px] font-medium text-cc-fg font-mono-code",children:["/",q.name]}),r.jsx("span",{className:`text-[8px] font-semibold px-1.5 rounded-full ${q.source==="project"?"text-amber-500 bg-amber-500/10":"text-cc-muted bg-cc-hover"}`,children:q.source})]}),q.description&&r.jsx("p",{className:"text-[11px] text-cc-muted truncate mt-0.5",children:q.description})]}),r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:`w-3 h-3 text-cc-muted/40 transition-transform duration-150 shrink-0 ${h===q.path?"rotate-90":""}`,"aria-hidden":!0,children:r.jsx("path",{d:"M6 4l4 4-4 4V4z"})})]}),h===q.path&&r.jsx("div",{className:"ml-10 mt-1 mb-2",children:v?r.jsx("p",{className:"text-[11px] text-cc-muted py-2",children:"Loading..."}):r.jsx("pre",{className:"text-[11px] text-cc-code-fg bg-cc-code-bg rounded-lg p-3 overflow-x-auto max-h-64 overflow-y-auto font-mono-code leading-relaxed",children:g})})]},q.path))})]}),K.length>0&&r.jsxs("div",{children:[r.jsxs("h2",{className:"text-[11px] font-semibold text-cc-muted uppercase tracking-wider mb-2",children:["Skills ",r.jsx("span",{className:"text-cc-muted/50 tabular-nums ml-1",children:K.length})]}),r.jsx("div",{className:"space-y-1.5",children:K.map(q=>r.jsxs("div",{children:[r.jsxs("button",{onClick:()=>B(q.path),className:`w-full flex items-center gap-3 px-4 py-2.5 rounded-lg border text-left transition-all cursor-pointer ${h===q.path?"border-cc-primary/30 bg-cc-primary/[0.03]":"border-cc-border bg-cc-card hover:shadow-panel"}`,children:[r.jsx("span",{className:"w-7 h-7 rounded-md bg-cc-success/10 text-cc-success flex items-center justify-center shrink-0",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5","aria-hidden":!0,children:r.jsx("path",{d:"M8.22 1.754a.25.25 0 00-.44 0L1.698 13.132a.25.25 0 00.22.368h12.164a.25.25 0 00.22-.368L8.22 1.754z"})})}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("span",{className:"text-[13px] font-medium text-cc-fg",children:q.name}),q.description&&r.jsx("p",{className:"text-[11px] text-cc-muted truncate mt-0.5",children:q.description})]}),r.jsx("span",{className:"text-[9px] font-mono-code text-cc-muted/40 shrink-0",children:q.slug}),r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:`w-3 h-3 text-cc-muted/40 transition-transform duration-150 shrink-0 ${h===q.path?"rotate-90":""}`,"aria-hidden":!0,children:r.jsx("path",{d:"M6 4l4 4-4 4V4z"})})]}),h===q.path&&r.jsx("div",{className:"ml-10 mt-1 mb-2",children:v?r.jsx("p",{className:"text-[11px] text-cc-muted py-2",children:"Loading..."}):r.jsx("pre",{className:"text-[11px] text-cc-code-fg bg-cc-code-bg rounded-lg p-3 overflow-x-auto max-h-64 overflow-y-auto font-mono-code leading-relaxed",children:g})})]},q.path))})]})]})}const t9=["welcome","providers","workspace","tour","launch"];function s9(e){return t9.indexOf(e)}function n9(e,t){return e?"bg-cc-primary text-white":t?"bg-cc-primary/15 text-cc-primary ring-2 ring-cc-primary/30":"bg-cc-hover text-cc-muted/50"}function r9(e){return e==="subscription"?"Logged in":e==="oauth-token"?"Token set":e==="api-key"?"API key set":""}function i9({onComplete:e}){const[t,s]=w.useState("welcome"),[n,a]=w.useState(null),[l,c]=w.useState(""),[d,f]=w.useState(""),[h,m]=w.useState(""),[g,b]=w.useState(!1),[v,y]=w.useState(""),S=w.useRef(null),j=s9(t);w.useEffect(()=>{var B;(B=S.current)==null||B.focus()},[t]),w.useEffect(()=>{se.getProviderAuthStatus().then(a).catch(()=>{})},[t]);const k=w.useCallback(async()=>{try{await se.updateSettings({onboardingCompleted:!0})}catch{}e()},[e]);async function E(){b(!0),y("");try{const B={};l.trim()&&(B.claudeOAuthToken=l.trim()),d.trim()&&(B.openaiApiKey=d.trim()),Object.keys(B).length>0&&await se.updateSettings(B),s("workspace")}catch(B){y(B instanceof Error?B.message:"Failed to save")}finally{b(!1)}}function N(){se.getProviderAuthStatus().then(a).catch(()=>{})}return r.jsx("dialog",{ref:S,open:!0,"aria-label":"Campfire setup wizard",className:"fixed inset-0 z-50 flex items-center justify-center w-full h-full m-0 p-0 bg-black/50 backdrop-blur-md border-none outline-none",children:r.jsxs("div",{className:"w-full max-w-[520px] mx-5 bg-cc-card rounded-2xl shadow-float border border-cc-border/60 overflow-hidden animate-slide-up",children:[r.jsx(a9,{current:j,total:4}),r.jsxs("div",{className:"px-7 pb-7 pt-5",children:[t==="welcome"&&r.jsx(o9,{onNext:()=>s("providers"),onSkip:k}),t==="providers"&&r.jsx(l9,{authStatus:n,claudeToken:l,openaiKey:d,onClaudeTokenChange:c,onOpenaiKeyChange:f,saving:g,error:v,onSave:E,onSkip:()=>s("workspace"),onRefreshAuth:N}),t==="workspace"&&r.jsx(c9,{cwd:h,onCwdChange:m,onNext:()=>s("tour"),onSkip:()=>s("tour")}),t==="tour"&&r.jsx(d9,{onNext:()=>s("launch")}),t==="launch"&&r.jsx(h9,{cwd:h,onComplete:k})]})]})})}const c2=["Welcome","Providers","Workspace","Features"];function a9({current:e,total:t}){return e>=t?null:r.jsxs("output",{className:"block px-7 pt-6 pb-1","aria-label":`Step ${e+1} of ${t}: ${c2[e]}`,children:[r.jsx("div",{className:"flex items-center gap-1.5",children:Array.from({length:t},(s,n)=>{const a=n<e,l=n===e;return r.jsxs("div",{className:"flex items-center gap-1.5 flex-1",children:[r.jsx("div",{className:`w-6 h-6 rounded-full flex items-center justify-center text-[10px] font-semibold shrink-0 transition-all duration-300 ${n9(a,l)}`,children:a?r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3","aria-hidden":!0,children:r.jsx("path",{d:"M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"})}):n+1}),n<t-1&&r.jsx("div",{className:`flex-1 h-[2px] rounded-full transition-colors duration-300 ${n<e?"bg-cc-primary":"bg-cc-border"}`})]},n)})}),r.jsx("p",{className:"text-[10px] text-cc-muted mt-2 font-medium",children:c2[e]})]})}function o9({onNext:e,onSkip:t}){return r.jsxs("div",{className:"text-center",children:[r.jsx("div",{className:"w-16 h-16 mx-auto mb-5 rounded-2xl bg-gradient-to-br from-cc-primary/20 to-cc-primary/5 flex items-center justify-center border border-cc-primary/10",children:r.jsx("span",{className:"text-3xl",role:"img","aria-label":"Campfire",children:"🔥"})}),r.jsx("h1",{className:"text-[22px] font-bold text-cc-fg tracking-tight",children:"Welcome to Campfire"}),r.jsx("p",{className:"text-[14px] text-cc-muted mt-2 leading-relaxed max-w-[380px] mx-auto",children:"A unified web interface for AI coding agents. Run Claude, Codex, Goose, Aider and more from your browser."}),r.jsxs("div",{className:"mt-8 space-y-3",children:[r.jsx("button",{onClick:e,autoFocus:!0,className:"w-full h-11 rounded-xl bg-cc-primary text-white text-[14px] font-semibold hover:bg-cc-primary-hover active:scale-[0.98] transition-all cursor-pointer shadow-sm",children:"Get Started"}),r.jsx("button",{onClick:t,className:"w-full text-[12px] text-cc-muted/60 hover:text-cc-muted transition-colors cursor-pointer py-1",children:"Skip setup — I'll configure later in Settings"})]})]})}function l9({authStatus:e,claudeToken:t,openaiKey:s,onClaudeTokenChange:n,onOpenaiKeyChange:a,saving:l,error:c,onSave:d,onSkip:f,onRefreshAuth:h}){return r.jsxs("div",{children:[r.jsx("h2",{className:"text-[18px] font-bold text-cc-fg tracking-tight",children:"Connect Providers"}),r.jsx("p",{className:"text-[13px] text-cc-muted mt-1 mb-5",children:"Set up one or both. You can add more anytime in Settings."}),c&&r.jsxs("div",{className:"mb-4 flex items-center gap-2 px-3 py-2.5 rounded-xl bg-cc-error/8 border border-cc-error/15",role:"alert",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-4 h-4 text-cc-error shrink-0","aria-hidden":!0,children:r.jsx("path",{d:"M3.72 3.72a.75.75 0 011.06 0L8 6.94l3.22-3.22a.75.75 0 111.06 1.06L9.06 8l3.22 3.22a.75.75 0 11-1.06 1.06L8 9.06l-3.22 3.22a.75.75 0 01-1.06-1.06L6.94 8 3.72 4.78a.75.75 0 010-1.06z"})}),r.jsx("p",{className:"text-[12px] text-cc-error",children:c})]}),r.jsxs("div",{className:"space-y-3",children:[r.jsx(u2,{name:"Claude Code",description:"Anthropic's coding agent",accentColor:"bg-[#5BA8A0]",authenticated:(e==null?void 0:e.claude.authenticated)??!1,method:(e==null?void 0:e.claude.method)??null,loginCommand:"claude auth login",loginHint:"Signs in with your Claude Pro, Max, or Team subscription",tokenLabel:"OAuth token or API key",tokenPlaceholder:"sk-ant-... or paste from claude setup-token",tokenValue:t,onTokenChange:n,onRefresh:h}),r.jsx(u2,{name:"Codex",description:"OpenAI's coding agent",accentColor:"bg-blue-500",authenticated:(e==null?void 0:e.codex.authenticated)??!1,method:(e==null?void 0:e.codex.method)??null,loginCommand:"codex login",loginHint:"Signs in with your ChatGPT Plus or Pro subscription",tokenLabel:"OpenAI API key",tokenPlaceholder:"sk-...",tokenValue:s,onTokenChange:a,onRefresh:h})]}),r.jsxs("div",{className:"flex items-center gap-3 mt-6",children:[r.jsx("button",{onClick:d,disabled:l,className:"flex-1 h-11 rounded-xl bg-cc-primary text-white text-[14px] font-semibold hover:bg-cc-primary-hover active:scale-[0.98] transition-all cursor-pointer disabled:opacity-40 shadow-sm",children:l?"Saving...":"Continue"}),r.jsx("button",{onClick:f,className:"h-11 px-5 rounded-xl text-[13px] font-medium text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:"Skip"})]})]})}function u2({name:e,description:t,accentColor:s,authenticated:n,method:a,loginCommand:l,loginHint:c,tokenLabel:d,tokenPlaceholder:f,tokenValue:h,onTokenChange:m,onRefresh:g}){const[b,v]=w.useState(!1),[y,S]=w.useState(!1);function j(){navigator.clipboard.writeText(l).catch(()=>{}),S(!0),setTimeout(()=>S(!1),1500)}return r.jsxs("div",{className:`rounded-xl border transition-colors ${n?"border-cc-success/30 bg-cc-success/[0.03]":"border-cc-border hover:border-cc-border/80"}`,children:[r.jsxs("div",{className:"flex items-center gap-3 px-4 py-3",children:[r.jsx("div",{className:`w-8 h-8 rounded-lg ${s} flex items-center justify-center`,children:r.jsx("span",{className:"text-white text-sm font-bold",children:e.charAt(0)})}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("h3",{className:"text-[13px] font-semibold text-cc-fg",children:e}),r.jsx("p",{className:"text-[11px] text-cc-muted",children:t})]}),n&&r.jsxs("span",{className:"flex items-center gap-1.5 text-[11px] font-medium text-cc-success bg-cc-success/10 px-2.5 py-1 rounded-full",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3","aria-hidden":!0,children:r.jsx("path",{d:"M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"})}),r9(a)]})]}),!n&&r.jsxs("div",{className:"px-4 pb-4 space-y-3",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-[11px] text-cc-muted mb-1.5",children:"Run in your terminal:"}),r.jsxs("div",{className:"flex items-center bg-cc-code-bg rounded-lg border border-cc-border/30 overflow-hidden",children:[r.jsxs("div",{className:"flex-1 flex items-center gap-2 px-3 py-2.5 min-w-0",children:[r.jsx("span",{className:"text-cc-code-fg/40 text-[12px] font-mono-code select-none","aria-hidden":!0,children:"$"}),r.jsx("code",{className:"text-[12px] font-mono-code text-cc-code-fg truncate",children:l})]}),r.jsx("button",{onClick:j,className:"px-3 py-2.5 text-[10px] font-medium text-cc-code-fg/50 hover:text-cc-code-fg/80 hover:bg-white/5 transition-colors cursor-pointer border-l border-cc-border/20","aria-label":`Copy command: ${l}`,children:y?"Copied!":"Copy"})]}),r.jsx("p",{className:"text-[10px] text-cc-muted/70 mt-1.5",children:c})]}),r.jsxs("button",{onClick:g,className:"flex items-center gap-1.5 text-[11px] font-medium text-cc-primary hover:text-cc-primary-hover transition-colors cursor-pointer",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3","aria-hidden":!0,children:r.jsx("path",{d:"M1.705 8.005a.75.75 0 01.834.656 5.5 5.5 0 009.592 2.97l-1.204-1.204a.25.25 0 01.177-.427h3.646a.25.25 0 01.25.25v3.646a.25.25 0 01-.427.177l-1.38-1.38A7.002 7.002 0 011.05 8.84a.75.75 0 01.656-.834zM8 2.5a5.487 5.487 0 00-4.131 1.869l1.204 1.204A.25.25 0 014.896 6H1.25A.25.25 0 011 5.75V2.104a.25.25 0 01.427-.177l1.38 1.38A7.002 7.002 0 0114.95 7.16a.75.75 0 11-1.49.178A5.5 5.5 0 008 2.5z"})}),"I've logged in — check again"]}),r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("div",{className:"flex-1 h-px bg-cc-border/50"}),r.jsx("button",{onClick:()=>v(k=>!k),className:"text-[10px] text-cc-muted/50 hover:text-cc-muted transition-colors cursor-pointer shrink-0",children:b?"Hide API key":"Or use an API key"}),r.jsx("div",{className:"flex-1 h-px bg-cc-border/50"})]}),b&&r.jsxs("div",{children:[r.jsx("label",{htmlFor:`key-${e}`,className:"text-[11px] font-medium text-cc-muted block mb-1",children:d}),r.jsx("input",{id:`key-${e}`,type:"password",value:h,onChange:k=>m(k.target.value),placeholder:f,className:"w-full h-9 px-3 rounded-lg border border-cc-border bg-cc-input-bg text-[12px] text-cc-fg font-mono-code placeholder:text-cc-muted/30 focus:outline-none focus:ring-2 focus:ring-cc-primary/20 focus:border-cc-primary/40 transition-all"})]})]})]})}function c9({cwd:e,onCwdChange:t,onNext:s,onSkip:n}){return r.jsxs("div",{children:[r.jsx("h2",{className:"text-[18px] font-bold text-cc-fg tracking-tight",children:"Your Workspace"}),r.jsx("p",{className:"text-[13px] text-cc-muted mt-1 mb-5",children:"Set a default working directory for new sessions. You can always change this per session."}),r.jsxs("div",{className:"mb-6",children:[r.jsx("label",{htmlFor:"onboarding-cwd",className:"text-[12px] font-medium text-cc-fg block mb-2",children:"Project directory"}),r.jsxs("div",{className:"relative",children:[r.jsx("div",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-cc-muted/40","aria-hidden":!0,children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-4 h-4",children:r.jsx("path",{d:"M1.75 1A1.75 1.75 0 000 2.75v10.5C0 14.216.784 15 1.75 15h12.5A1.75 1.75 0 0016 13.25v-8.5A1.75 1.75 0 0014.25 3H7.5a.25.25 0 01-.2-.1l-.9-1.2C6.07 1.26 5.55 1 5 1H1.75z"})})}),r.jsx("input",{id:"onboarding-cwd",value:e,onChange:a=>t(a.target.value),placeholder:"/home/user/my-project",autoFocus:!0,className:"w-full h-11 pl-10 pr-3 rounded-xl border border-cc-border bg-cc-input-bg text-[13px] text-cc-fg font-mono-code placeholder:text-cc-muted/30 focus:outline-none focus:ring-2 focus:ring-cc-primary/20 focus:border-cc-primary/40 transition-all"})]}),r.jsxs("p",{className:"text-[11px] text-cc-muted/60 mt-2",children:["Use the absolute path to your project root, e.g. ",r.jsx("code",{className:"font-mono-code bg-cc-hover px-1 rounded text-[10px]",children:"~/projects/my-app"})]})]}),r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("button",{onClick:s,className:"flex-1 h-11 rounded-xl bg-cc-primary text-white text-[14px] font-semibold hover:bg-cc-primary-hover active:scale-[0.98] transition-all cursor-pointer shadow-sm",children:"Continue"}),r.jsx("button",{onClick:n,className:"h-11 px-5 rounded-xl text-[13px] font-medium text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:"Skip"})]})]})}const u9=[{icon:r.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"w-5 h-5",children:r.jsx("path",{d:"M20 12V8H6a2 2 0 01-2-2c0-1.1.9-2 2-2h12v4M20 12v4H6a2 2 0 00-2 2c0 1.1.9 2 2 2h12v-4M20 12H9",strokeLinecap:"round",strokeLinejoin:"round"})}),title:"Multi-Session",desc:"Run multiple agents in parallel across different projects and backends",color:"text-cc-primary bg-cc-primary/10"},{icon:r.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"w-5 h-5",children:r.jsx("path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z",strokeLinecap:"round",strokeLinejoin:"round"})}),title:"Permission Control",desc:"Approve or deny tool calls before they execute — full visibility and safety",color:"text-cc-success bg-cc-success/10"},{icon:r.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"w-5 h-5",children:r.jsx("path",{d:"M12 8V4H8M2 12h4M20 12h2M12 20v-4M4.93 4.93l2.83 2.83M16.24 16.24l2.83 2.83M4.93 19.07l2.83-2.83M16.24 7.76l2.83-2.83",strokeLinecap:"round"})}),title:"Agent Profiles",desc:"Create persistent agents with custom prompts, webhooks, and cron schedules",color:"text-amber-500 bg-amber-500/10"},{icon:r.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"w-5 h-5",children:r.jsx("path",{d:"M17 21v-2a4 4 0 00-4-4H5a4 4 0 00-4 4v2M9 11a4 4 0 100-8 4 4 0 000 8zM23 21v-2a4 4 0 00-3-3.87M16 3.13a4 4 0 010 7.75",strokeLinecap:"round",strokeLinejoin:"round"})}),title:"Collaboration",desc:"Share sessions with teammates and vote on permissions together",color:"text-purple-500 bg-purple-500/10"}];function d9({onNext:e}){return r.jsxs("div",{children:[r.jsx("h2",{className:"text-[18px] font-bold text-cc-fg tracking-tight",children:"What you can do"}),r.jsx("p",{className:"text-[13px] text-cc-muted mt-1 mb-5",children:"A quick look at Campfire's key capabilities."}),r.jsx("div",{className:"grid grid-cols-2 gap-3 mb-6",children:u9.map(t=>r.jsxs("div",{className:"rounded-xl border border-cc-border/50 p-4 hover:border-cc-border transition-colors",children:[r.jsx("div",{className:`w-9 h-9 rounded-lg ${t.color} flex items-center justify-center mb-3`,children:t.icon}),r.jsx("h3",{className:"text-[13px] font-semibold text-cc-fg",children:t.title}),r.jsx("p",{className:"text-[11px] text-cc-muted leading-relaxed mt-1",children:t.desc})]},t.title))}),r.jsx("button",{onClick:e,autoFocus:!0,className:"w-full h-11 rounded-xl bg-cc-primary text-white text-[14px] font-semibold hover:bg-cc-primary-hover active:scale-[0.98] transition-all cursor-pointer shadow-sm",children:"Let's Go"})]})}function h9({cwd:e,onComplete:t}){return r.jsxs("div",{className:"text-center py-4",children:[r.jsx("div",{className:"w-16 h-16 mx-auto mb-5 rounded-full bg-cc-success/10 flex items-center justify-center",children:r.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"w-8 h-8 text-cc-success","aria-hidden":!0,children:r.jsx("path",{d:"M20 6L9 17l-5-5",strokeLinecap:"round",strokeLinejoin:"round"})})}),r.jsx("h2",{className:"text-[22px] font-bold text-cc-fg tracking-tight",children:"You're all set!"}),r.jsx("p",{className:"text-[14px] text-cc-muted mt-2 max-w-[360px] mx-auto leading-relaxed",children:e?r.jsxs(r.Fragment,{children:["Your workspace is set to ",r.jsx("code",{className:"font-mono-code text-[12px] bg-cc-hover px-1.5 py-0.5 rounded",children:e})]}):"Start your first session from the home page"}),r.jsx("p",{className:"text-[12px] text-cc-muted/50 mt-2",children:"Providers and settings can be updated anytime."}),r.jsx("button",{onClick:t,autoFocus:!0,className:"w-full h-11 mt-8 rounded-xl bg-cc-primary text-white text-[14px] font-semibold hover:bg-cc-primary-hover active:scale-[0.98] transition-all cursor-pointer shadow-sm",children:"Open Campfire"})]})}const f9={installing:"Installing update...",restarting:"Restarting server...",waiting:"Waiting for server...",ready:"Update complete."};function p9(){const e=qh();return e?{Authorization:`Bearer ${e}`}:{}}function m9(e){const[t,s]=w.useState("installing"),n=w.useRef(null),a=w.useRef(!0);return w.useEffect(()=>(a.current=!0,()=>{a.current=!1,n.current&&clearTimeout(n.current)}),[]),w.useEffect(()=>{if(!e){s("installing");return}const l=setTimeout(()=>{a.current&&s("restarting")},3e3),c=setTimeout(()=>{a.current&&s("waiting"),d()},5e3);function d(){a.current&&fetch("/api/update-check",{headers:p9(),signal:AbortSignal.timeout(3e3)}).then(f=>{if(!f.ok)throw new Error("Server is not ready");return f.json()}).then(f=>{if(f.updateInProgress)throw new Error("Update is still running");a.current&&(s("ready"),setTimeout(()=>{a.current&&window.location.reload()},800))}).catch(()=>{n.current=setTimeout(d,1500)})}return()=>{clearTimeout(l),clearTimeout(c),n.current&&clearTimeout(n.current)}},[e]),t}function g9({active:e}){const t=m9(e);if(!e)return null;const s=t==="ready";return r.jsxs("div",{className:"fixed inset-0 z-[100] flex flex-col items-center justify-center bg-cc-bg text-cc-fg animate-[fadeSlideIn_0.15s_ease-out]",role:"status","aria-live":"polite","data-testid":"update-overlay",children:[r.jsxs("div",{className:"relative mb-7",children:[!s&&r.jsx("div",{className:"absolute inset-0 -m-4 rounded-full bg-cc-primary/10 animate-pulse"}),r.jsx("img",{src:"/logo.svg",alt:"Campfire",className:`relative z-10 h-20 w-20 transition-transform duration-500 ${s?"":"scale-110"}`}),!s&&r.jsx("div",{className:"absolute -inset-3 z-0",children:r.jsx("svg",{className:"h-full w-full animate-[spin_1.2s_linear_infinite]",viewBox:"0 0 100 100",children:r.jsx("circle",{cx:"50",cy:"50",r:"46",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeDasharray:"60 230",strokeLinecap:"round",className:"text-cc-primary/45"})})}),s&&r.jsx("div",{className:"absolute -inset-3 z-0 rounded-full border-2 border-cc-success/30"})]}),r.jsx("p",{className:`mb-2 text-sm font-medium ${s?"text-cc-success":"text-cc-fg"}`,children:f9[t]}),r.jsx("p",{className:"text-xs text-cc-muted",children:s?"Reloading...":"This page will refresh automatically"}),!s&&r.jsx("div",{className:"mt-6 flex gap-1.5",children:[0,1,2].map(n=>r.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-cc-primary/50",style:{animation:"pulse-dot 1.4s ease-in-out infinite",animationDelay:`${n*.2}s`}},n))}),r.jsx("div",{className:"absolute bottom-0 left-0 right-0 h-0.5 bg-cc-border/40",children:r.jsx("div",{className:"h-full bg-cc-primary/70 transition-all duration-1000",style:{width:s?"100%":"70%"}})})]})}const x9=[{id:"general",label:"General"},{id:"providers",label:"Providers"},{id:"api-keys",label:"API Keys"},{id:"memory",label:"Memory"},{id:"security",label:"Security"},{id:"notifications",label:"Notifications"},{id:"appearance",label:"Appearance"},{id:"updates",label:"Updates"}];function v9(e,t){return e?`${t} active session${t===1?"":"s"}`:"Anyone with the URL can access this instance"}function b9(e){return e!=null&&e.latestVersion?e.updateAvailable?`v${e.latestVersion} available`:"You're on the latest version":"Check for updates to see the latest version"}function _9(e){return e?"text-cc-success bg-cc-success/10":"text-cc-warning bg-cc-warning/10"}function Lh({enabled:e,onToggle:t,label:s}){return r.jsx("button",{type:"button",role:"switch","aria-checked":e,"aria-label":s,onClick:t,className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors duration-200 cursor-pointer shrink-0 ${e?"bg-cc-primary":"bg-cc-border"}`,children:r.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white shadow-sm transition-transform duration-200 ${e?"translate-x-[18px]":"translate-x-[3px]"}`})})}function ar({title:e,description:t,children:s}){return r.jsxs("div",{className:"bg-cc-card border border-cc-border/60 rounded-xl",children:[r.jsxs("div",{className:"px-5 py-4 border-b border-cc-border/40",children:[r.jsx("h3",{className:"text-[13px] font-semibold text-cc-fg",children:e}),t&&r.jsx("p",{className:"mt-0.5 text-[12px] text-cc-fg/60",children:t})]}),r.jsx("div",{className:"px-5 py-4",children:s})]})}function Bh({label:e,description:t,children:s}){return r.jsxs("div",{className:"flex items-center justify-between gap-4 py-3 first:pt-0 last:pb-0 border-b border-cc-border/20 last:border-0",children:[r.jsxs("div",{className:"min-w-0",children:[r.jsx("span",{className:"text-[13px] font-medium text-cc-fg",children:e}),t&&r.jsx("p",{className:"text-[11px] text-cc-fg/55 mt-0.5",children:t})]}),r.jsx("div",{className:"shrink-0",children:s})]})}function y9({telemetryEnabled:e,setTelemetryEnabled:t}){return r.jsxs(r.Fragment,{children:[r.jsx(ar,{title:"Telemetry",description:"Help improve Campfire with anonymous usage data",children:r.jsx(Bh,{label:"Usage analytics and crash reports",description:"Anonymous product analytics via PostHog. Browser Do Not Track is respected automatically.",children:r.jsx(Lh,{enabled:e,label:"Toggle telemetry",onToggle:()=>{const s=!e;RM(s),t(s)}})})}),r.jsx(ar,{title:"Environments",description:"Manage reusable environment profiles for sessions",children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("p",{className:"text-[12px] text-cc-fg/60",children:"Configure named sets of environment variables to use when creating sessions."}),r.jsx("button",{type:"button",onClick:()=>{globalThis.location.hash="#/environments"},className:"px-3.5 py-2 rounded-lg text-[12px] font-medium bg-cc-primary hover:bg-cc-primary-hover text-white transition-colors cursor-pointer shrink-0 ml-4",children:"Manage"})]})})]})}function w9({claudeOAuthToken:e,setClaudeOAuthToken:t,claudeConfigured:s,setClaudeConfigured:n,openaiApiKey:a,setOpenaiApiKey:l,openaiConfigured:c,setOpenaiConfigured:d,anthropicApiKey:f,setAnthropicApiKey:h,anthropicConfigured:m,setAnthropicConfigured:g,providerSaving:b,setProviderSaving:v,providerSaved:y,setProviderSaved:S,error:j,setError:k}){return r.jsxs("div",{className:"space-y-5",children:[r.jsx(ar,{title:"AI Provider Tokens",description:"Tokens are auto-injected into sessions for matching backends. Environment profiles take precedence.",children:r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[r.jsx("label",{htmlFor:"claude-oauth",className:"text-[12px] font-medium text-cc-fg",children:"Claude Code OAuth Token"}),r.jsx("span",{className:`text-[10px] font-medium px-1.5 rounded-full ${s?"text-cc-success bg-cc-success/10":"text-cc-muted bg-cc-hover"}`,children:s?"Configured":"Not set"})]}),r.jsxs("p",{className:"text-[11px] text-cc-muted mb-1.5",children:["Injected as ",r.jsx("code",{className:"font-mono-code text-[10px] bg-cc-hover px-1 rounded",children:"CLAUDE_CODE_OAUTH_TOKEN"})," for Claude sessions"]}),r.jsx("input",{id:"claude-oauth",type:"password",value:e,onChange:E=>t(E.target.value),placeholder:s?"•••••••••••• (configured)":"Paste token from claude setup-token",className:"w-full h-9 px-3 rounded-lg border border-cc-border bg-cc-input-bg text-[12px] text-cc-fg font-mono-code"})]}),r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[r.jsx("label",{htmlFor:"openai-key",className:"text-[12px] font-medium text-cc-fg",children:"OpenAI API Key"}),r.jsx("span",{className:`text-[10px] font-medium px-1.5 rounded-full ${c?"text-cc-success bg-cc-success/10":"text-cc-muted bg-cc-hover"}`,children:c?"Configured":"Not set"})]}),r.jsxs("p",{className:"text-[11px] text-cc-muted mb-1.5",children:["Injected as ",r.jsx("code",{className:"font-mono-code text-[10px] bg-cc-hover px-1 rounded",children:"OPENAI_API_KEY"})," for Codex sessions"]}),r.jsx("input",{id:"openai-key",type:"password",value:a,onChange:E=>l(E.target.value),placeholder:c?"•••••••••••• (configured)":"sk-...",className:"w-full h-9 px-3 rounded-lg border border-cc-border bg-cc-input-bg text-[12px] text-cc-fg font-mono-code"})]}),r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[r.jsx("label",{htmlFor:"anthropic-key",className:"text-[12px] font-medium text-cc-fg",children:"Anthropic API Key"}),r.jsx("span",{className:`text-[10px] font-medium px-1.5 rounded-full ${m?"text-cc-success bg-cc-success/10":"text-cc-muted bg-cc-hover"}`,children:m?"Configured":"Not set"})]}),r.jsxs("p",{className:"text-[11px] text-cc-muted mb-1.5",children:["Injected as ",r.jsx("code",{className:"font-mono-code text-[10px] bg-cc-hover px-1 rounded",children:"ANTHROPIC_API_KEY"})," for all sessions (Goose, Aider, etc.)"]}),r.jsx("input",{id:"anthropic-key",type:"password",value:f,onChange:E=>h(E.target.value),placeholder:m?"•••••••••••• (configured)":"sk-ant-api03-...",className:"w-full h-9 px-3 rounded-lg border border-cc-border bg-cc-input-bg text-[12px] text-cc-fg font-mono-code"})]})]})}),r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("button",{type:"button",onClick:async()=>{v(!0),k("");try{const E={};if(e.trim()&&(E.claudeOAuthToken=e.trim()),a.trim()&&(E.openaiApiKey=a.trim()),f.trim()&&(E.anthropicApiKey=f.trim()),Object.keys(E).length===0)return;const N=await se.updateSettings(E);n(N.claudeOAuthTokenConfigured??!1),d(N.openaiApiKeyConfigured??!1),g(N.anthropicApiKeyConfigured??!1),t(""),l(""),h(""),S(!0),setTimeout(()=>S(!1),1800)}catch(E){k(E instanceof Error?E.message:"Save failed")}finally{v(!1)}},disabled:b,className:"px-4 py-1.5 rounded-lg bg-cc-primary text-white text-[12px] font-medium hover:bg-cc-primary-hover transition-colors cursor-pointer disabled:opacity-40",children:b?"Saving...":"Save Providers"}),y&&r.jsx("span",{className:"text-[11px] text-cc-success",children:"Saved"}),j&&r.jsx("span",{className:"text-[11px] text-cc-error",children:j})]}),r.jsx("div",{className:"rounded-lg border border-cc-border/40 bg-cc-hover/30 px-4 py-3",children:r.jsxs("p",{className:"text-[11px] text-cc-muted leading-relaxed",children:["Provider tokens are automatically injected into new sessions for the matching backend. If an environment profile already sets the same variable, the profile value takes precedence. Tokens are stored in ",r.jsx("code",{className:"font-mono-code text-[10px] bg-cc-hover px-1 rounded",children:"~/.campfire/settings.json"}),"."]})})]})}function S9({openrouterApiKey:e,setOpenrouterApiKey:t,openrouterModel:s,setOpenrouterModel:n,configured:a,moltbookApiKey:l,setMoltbookApiKey:c,moltbookConfigured:d,loading:f,saving:h,error:m,saved:g,onSave:b}){return r.jsxs("form",{onSubmit:b,className:"space-y-5",children:[r.jsx(ar,{title:"OpenRouter",description:"Used for auto-naming sessions after the first turn",children:r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-[12px] font-medium text-cc-fg mb-1.5",htmlFor:"openrouter-key",children:"API Key"}),r.jsx("input",{id:"openrouter-key",type:"password",value:e,onChange:v=>t(v.target.value),placeholder:a?"Configured — enter a new key to replace":"sk-or-v1-...",className:"w-full px-3.5 py-2.5 text-[13px] bg-cc-bg border border-cc-border/60 rounded-lg text-cc-fg placeholder:text-cc-fg/40 focus:outline-none focus:border-cc-primary/60 focus:ring-1 focus:ring-cc-primary/20 transition-all"}),r.jsx("div",{className:"flex items-center gap-2 mt-2",children:a?r.jsxs("span",{className:"inline-flex items-center gap-1 text-[11px] text-cc-success font-medium",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3",children:r.jsx("path",{d:"M8 0a8 8 0 110 16A8 8 0 018 0zm3.78 4.97a.75.75 0 00-1.06 0L7 8.69 5.28 6.97a.75.75 0 00-1.06 1.06l2.25 2.25a.75.75 0 001.06 0l4.25-4.25a.75.75 0 000-1.06z"})}),"Configured"]}):r.jsx("span",{className:"text-[11px] text-cc-fg/50",children:"Not configured — auto-naming is disabled"})})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-[12px] font-medium text-cc-fg mb-1.5",htmlFor:"openrouter-model",children:"Model"}),r.jsx("input",{id:"openrouter-model",type:"text",value:s,onChange:v=>n(v.target.value),placeholder:"openrouter/free",className:"w-full px-3.5 py-2.5 text-[13px] bg-cc-bg border border-cc-border/60 rounded-lg text-cc-fg placeholder:text-cc-fg/40 focus:outline-none focus:border-cc-primary/60 focus:ring-1 focus:ring-cc-primary/20 transition-all"})]})]})}),r.jsx(ar,{title:"Moltbook",description:"Required to post gallery sessions to Moltbook",children:r.jsxs("div",{children:[r.jsx("label",{className:"block text-[12px] font-medium text-cc-fg mb-1.5",htmlFor:"moltbook-key",children:"API Key"}),r.jsx("input",{id:"moltbook-key",type:"password",value:l,onChange:v=>c(v.target.value),placeholder:d?"Configured — enter a new key to replace":"Paste your Moltbook API key",className:"w-full px-3.5 py-2.5 text-[13px] bg-cc-bg border border-cc-border/60 rounded-lg text-cc-fg placeholder:text-cc-fg/40 focus:outline-none focus:border-cc-primary/60 focus:ring-1 focus:ring-cc-primary/20 transition-all"}),r.jsx("div",{className:"flex items-center gap-2 mt-2",children:d?r.jsxs("span",{className:"inline-flex items-center gap-1 text-[11px] text-cc-success font-medium",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3",children:r.jsx("path",{d:"M8 0a8 8 0 110 16A8 8 0 018 0zm3.78 4.97a.75.75 0 00-1.06 0L7 8.69 5.28 6.97a.75.75 0 00-1.06 1.06l2.25 2.25a.75.75 0 001.06 0l4.25-4.25a.75.75 0 000-1.06z"})}),"Configured"]}):r.jsx("span",{className:"text-[11px] text-cc-fg/50",children:"Get a key at moltbook.com by registering an agent"})})]})}),r.jsxs("div",{className:"flex items-center justify-between bg-cc-card border border-cc-border/60 rounded-xl px-5 py-3.5",children:[r.jsxs("div",{className:"text-[12px]",children:[m&&r.jsx("span",{className:"text-cc-error",children:m}),g&&r.jsx("span",{className:"text-cc-success font-medium",children:"Settings saved successfully"}),!m&&!g&&r.jsx("span",{className:"text-cc-fg/50",children:f?"Loading...":"Changes are saved immediately"})]}),r.jsx("button",{type:"submit",disabled:h||f,className:`px-4 py-2 rounded-lg text-[13px] font-medium transition-all ${h||f?"bg-cc-hover text-cc-fg/40 cursor-not-allowed":"bg-cc-primary hover:bg-cc-primary-hover text-white shadow-sm cursor-pointer"}`,children:h?"Saving...":"Save API Keys"})]})]})}const Oh=[{key:"global",label:"Global",description:"Cross-repo conventions, user preferences, tool quirks"},{key:"repo",label:"Repository",description:"Architecture, conventions, distilled patterns per repo"},{key:"session",label:"Session",description:"Episodic fragments of one session (pre-consolidation)"},{key:"agent",label:"Agent",description:"Backend-specific behavior notes"}];function vg(e){var n;const t={},s={};for(const{key:a}of Oh){const l=e.decay[a]??Eh.decay[a];t[a]={halfLifeDays:l.halfLifeHours==null?"":String(l.halfLifeHours/24),reinforceMultiplier:String(l.reinforceMultiplier)},s[a]=String(((n=e.recallDepth)==null?void 0:n[a])??Eh.recallDepth[a])}return{decay:t,recallDepth:s}}function j9(e){const t={},s={};for(const{key:n,label:a}of Oh){const l=e.decay[n].halfLifeDays.trim();let c=null;if(l!==""){const h=Number(l);if(!Number.isFinite(h)||h<=0)return{error:`${a}: half-life must be a positive number of days (leave empty to never decay)`};c=Math.round(h*24)}const d=Number(e.decay[n].reinforceMultiplier);if(!Number.isFinite(d)||d<1)return{error:`${a}: reinforce multiplier must be a number ≥ 1`};const f=Number(e.recallDepth[n]);if(!Number.isInteger(f)||f<0)return{error:`${a}: recall depth must be a whole number ≥ 0`};t[n]={halfLifeHours:c,reinforceMultiplier:d},s[n]=f}return{settings:{decay:t,recallDepth:s}}}function k9({initial:e}){const[t,s]=w.useState(()=>vg(e)),[n,a]=w.useState(!1),[l,c]=w.useState(!1),[d,f]=w.useState("");w.useEffect(()=>{s(vg(e))},[e]);function h(b,v,y){s(S=>({...S,decay:{...S.decay,[b]:{...S.decay[b],[v]:y}}}))}function m(b,v){s(y=>({...y,recallDepth:{...y.recallDepth,[b]:v}}))}async function g(){f(""),c(!1);const{settings:b,error:v}=j9(t);if(!b){f(v||"Invalid memory settings");return}a(!0);try{const y=await se.updateSettings({memory:b});y.memory&&s(vg(y.memory)),c(!0),setTimeout(()=>c(!1),1800)}catch(y){f(y instanceof Error?y.message:"Save failed")}finally{a(!1)}}return r.jsxs("div",{className:"space-y-5",children:[r.jsx(ar,{title:"Memory Decay",description:"Per-namespace half-life for recalled memories. Leave half-life empty to never decay. Reinforcement extends the half-life each time a memory is actually used.",children:r.jsx("div",{className:"space-y-4",children:Oh.map(({key:b,label:v,description:y})=>r.jsxs("div",{className:"flex flex-wrap items-end gap-3 py-1 border-b border-cc-border/20 last:border-0 pb-3 last:pb-0",children:[r.jsxs("div",{className:"min-w-[160px] flex-1",children:[r.jsx("span",{className:"text-[13px] font-medium text-cc-fg",children:v}),r.jsx("p",{className:"text-[11px] text-cc-fg/55 mt-0.5",children:y})]}),r.jsxs("div",{children:[r.jsx("label",{htmlFor:`memory-halflife-${b}`,className:"block text-[11px] text-cc-fg/60 mb-1",children:"Half-life (days)"}),r.jsx("input",{id:`memory-halflife-${b}`,type:"number",min:"0",step:"1",value:t.decay[b].halfLifeDays,onChange:S=>h(b,"halfLifeDays",S.target.value),placeholder:"never",className:"w-24 h-9 px-3 rounded-lg border border-cc-border bg-cc-input-bg text-[12px] text-cc-fg font-mono-code"})]}),r.jsxs("div",{children:[r.jsx("label",{htmlFor:`memory-reinforce-${b}`,className:"block text-[11px] text-cc-fg/60 mb-1",children:"Reinforce ×"}),r.jsx("input",{id:`memory-reinforce-${b}`,type:"number",min:"1",step:"0.1",value:t.decay[b].reinforceMultiplier,onChange:S=>h(b,"reinforceMultiplier",S.target.value),className:"w-20 h-9 px-3 rounded-lg border border-cc-border bg-cc-input-bg text-[12px] text-cc-fg font-mono-code"})]})]},b))})}),r.jsx(ar,{title:"Recall Depth",description:"How many memories each namespace contributes when enriching a prompt with recalled context.",children:r.jsx("div",{className:"flex flex-wrap gap-4",children:Oh.map(({key:b,label:v})=>r.jsxs("div",{children:[r.jsx("label",{htmlFor:`memory-depth-${b}`,className:"block text-[11px] text-cc-fg/60 mb-1",children:v}),r.jsx("input",{id:`memory-depth-${b}`,type:"number",min:"0",step:"1",value:t.recallDepth[b],onChange:y=>m(b,y.target.value),className:"w-20 h-9 px-3 rounded-lg border border-cc-border bg-cc-input-bg text-[12px] text-cc-fg font-mono-code"})]},b))})}),r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("button",{type:"button",onClick:g,disabled:n,className:"px-4 py-1.5 rounded-lg bg-cc-primary text-white text-[12px] font-medium hover:bg-cc-primary-hover transition-colors cursor-pointer disabled:opacity-40",children:n?"Saving...":"Save Memory Settings"}),l&&r.jsx("span",{className:"text-[11px] text-cc-success",children:"Saved"}),d&&r.jsx("span",{className:"text-[11px] text-cc-error",children:d})]}),r.jsx("div",{className:"rounded-lg border border-cc-border/40 bg-cc-hover/30 px-4 py-3",children:r.jsxs("p",{className:"text-[11px] text-cc-muted leading-relaxed",children:["Pinned memories never decay regardless of half-life. Defaults: Global 90d, Repository 30d, Session 7d, Agent 60d. Settings are stored in ",r.jsx("code",{className:"font-mono-code text-[10px] bg-cc-hover px-1 rounded",children:"~/.campfire/settings.json"}),"."]})})]})}function C9({authEnabled:e,setAuthEnabled:t,authPassword:s,setAuthPassword:n,authSaving:a,setAuthSaving:l,authSaved:c,setAuthSaved:d,authError:f,setAuthError:h,authSessions:m}){return r.jsx("div",{className:"space-y-5",children:r.jsxs(ar,{title:"Authentication",description:"Protect your Campfire instance with a password. When enabled, all API and WebSocket connections require a valid session token.",children:[r.jsxs("div",{className:"flex items-center gap-3 mb-4 pb-4 border-b border-cc-border/30",children:[r.jsx("div",{className:`w-10 h-10 rounded-xl flex items-center justify-center ${e?"bg-cc-success/10":"bg-cc-hover"}`,children:r.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:`w-5 h-5 ${e?"text-cc-success":"text-cc-muted"}`,"aria-hidden":!0,children:r.jsx("path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z",strokeLinecap:"round",strokeLinejoin:"round"})})}),r.jsxs("div",{className:"flex-1",children:[r.jsxs("p",{className:"text-[13px] font-medium text-cc-fg",children:["Authentication is ",e?"enabled":"disabled"]}),r.jsx("p",{className:"text-[11px] text-cc-muted",children:v9(e,m)})]}),r.jsx("span",{className:`text-[10px] font-semibold px-2.5 py-1 rounded-full ${_9(e)}`,children:e?"Protected":"Open"})]}),f&&r.jsx("div",{className:"mb-3 px-3 py-2 rounded-lg bg-cc-error/8 border border-cc-error/15",role:"alert",children:r.jsx("p",{className:"text-[11px] text-cc-error",children:f})}),e?r.jsx(R9,{saving:a,onDisable:async()=>{l(!0),h("");try{await se.disableAuth(),t(!1),d(!0),setTimeout(()=>d(!1),2e3)}catch(g){h(g instanceof Error?g.message:"Failed to disable auth")}finally{l(!1)}}}):r.jsx(A9,{password:s,saving:a,onPasswordChange:n,onEnable:async()=>{l(!0),h("");try{await se.setupAuth(s);const{token:g}=await se.login(s);Oj(g),t(!0),n(""),d(!0),setTimeout(()=>d(!1),2e3)}catch(g){h(g instanceof Error?g.message:"Failed to enable auth")}finally{l(!1)}}}),c&&r.jsx("p",{className:"text-[11px] text-cc-success mt-2",children:"Saved"})]})})}function N9({notificationSound:e,toggleNotificationSound:t,notificationDesktop:s,setNotificationDesktop:n,notificationApiAvailable:a}){return r.jsxs(ar,{title:"Notification Preferences",description:"Control how Campfire alerts you",children:[r.jsx(Bh,{label:"Sound",description:"Play a notification sound when a permission request arrives",children:r.jsx(Lh,{enabled:e,label:"Toggle notification sound",onToggle:t})}),a&&r.jsx(Bh,{label:"Desktop Alerts",description:"Show native browser notifications for permission requests",children:r.jsx(Lh,{enabled:s,label:"Toggle desktop notifications",onToggle:async()=>{if(s)n(!1);else{if(Notification.permission!=="granted"&&await Notification.requestPermission()!=="granted")return;n(!0)}}})})]})}function E9({darkMode:e,toggleDarkMode:t}){return r.jsx(ar,{title:"Theme",description:"Choose your preferred color scheme",children:r.jsx(Bh,{label:"Dark Mode",description:"Switch between light and dark themes",children:r.jsx(Lh,{enabled:e,label:"Toggle dark mode",onToggle:t})})})}function M9({updateInfo:e,updateError:t,updateStatus:s,checkingUpdates:n,updatingApp:a,onCheckUpdates:l,onTriggerUpdate:c}){return r.jsx(ar,{title:"Software Updates",description:"Keep Campfire up to date",children:r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{className:"flex items-center gap-3 py-2",children:[r.jsx("div",{className:"w-10 h-10 rounded-xl bg-cc-primary/10 flex items-center justify-center shrink-0",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-5 h-5 text-cc-primary",children:r.jsx("path",{d:"M8 0a8 8 0 110 16A8 8 0 018 0zm0 1.5a6.5 6.5 0 100 13 6.5 6.5 0 000-13zM8 4a.75.75 0 01.75.75v3.5h2.5a.75.75 0 010 1.5h-3.25a.75.75 0 01-.75-.75v-4.25A.75.75 0 018 4z"})})}),r.jsxs("div",{children:[r.jsx("p",{className:"text-[13px] font-medium text-cc-fg",children:e?`v${e.currentVersion}`:"Loading..."}),r.jsx("p",{className:"text-[11px] text-cc-fg/55",children:b9(e)})]})]}),t&&r.jsx("div",{className:"px-3.5 py-2.5 rounded-lg bg-cc-error/8 border border-cc-error/15 text-[12px] text-cc-error",children:t}),s&&r.jsx("div",{className:"px-3.5 py-2.5 rounded-lg bg-cc-success/8 border border-cc-success/15 text-[12px] text-cc-success",children:s}),r.jsxs("div",{className:"flex items-center gap-2.5 pt-1",children:[r.jsx("button",{type:"button",onClick:l,disabled:n,className:`px-4 py-2 rounded-lg text-[13px] font-medium transition-all ${n?"bg-cc-hover text-cc-fg/40 cursor-not-allowed":"bg-cc-hover hover:bg-cc-active text-cc-fg cursor-pointer"}`,children:n?r.jsxs("span",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"w-3.5 h-3.5 border-2 border-cc-fg/20 border-t-cc-fg/60 rounded-full animate-spin"})," ","Checking..."]}):"Check for Updates"}),e!=null&&e.isServiceMode?r.jsx("button",{type:"button",onClick:c,disabled:a||e.updateInProgress||!e.updateAvailable,className:`px-4 py-2 rounded-lg text-[13px] font-medium transition-all ${a||e.updateInProgress||!e.updateAvailable?"bg-cc-hover text-cc-fg/40 cursor-not-allowed":"bg-cc-primary hover:bg-cc-primary-hover text-white shadow-sm cursor-pointer"}`,children:a||e.updateInProgress?"Updating...":"Update & Restart"}):r.jsxs("p",{className:"text-[11px] text-cc-fg/55 self-center",children:["Run ",r.jsx("code",{className:"font-mono-code bg-cc-code-bg px-1.5 py-0.5 rounded text-cc-code-fg text-[10px]",children:"the-campfire install"})," to enable one-click updates"]})]})]})})}function T9({embedded:e=!1}){const[t,s]=w.useState("general"),[n,a]=w.useState(""),[l,c]=w.useState("openrouter/free"),[d,f]=w.useState(!1),[h,m]=w.useState(""),[g,b]=w.useState(!1),[v,y]=w.useState(""),[S,j]=w.useState(!1),[k,E]=w.useState(""),[N,B]=w.useState(!1),[A,P]=w.useState(""),[K,X]=w.useState(!1),[Z,I]=w.useState(!1),[H,F]=w.useState(!1),[G,q]=w.useState(!0),[R,M]=w.useState(!1),[O,W]=w.useState(""),[U,D]=w.useState(!1),[$,z]=w.useState(!1),[T,ae]=w.useState(""),[be,ne]=w.useState(!1),[ve,Ae]=w.useState(!1),[De,ke]=w.useState(""),[Xe,Je]=w.useState(0),[$e,we]=w.useState(Eh),Ze=Y(ye=>ye.darkMode),ft=Y(ye=>ye.toggleDarkMode),mt=Y(ye=>ye.notificationSound),ss=Y(ye=>ye.toggleNotificationSound),Kt=Y(ye=>ye.notificationDesktop),Ft=Y(ye=>ye.setNotificationDesktop),Dt=Y(ye=>ye.updateInfo),Hs=Y(ye=>ye.setUpdateInfo),xs=Y(ye=>ye.setUpdateOverlayActive),_t=typeof Notification<"u",[lr,de]=w.useState(!1),[_e,Pe]=w.useState(!1),[qe,Ke]=w.useState(""),[Yt,Xt]=w.useState(""),[te,fe]=w.useState(Dj());w.useEffect(()=>{se.getSettings().then(ye=>{f(ye.openrouterApiKeyConfigured),c(ye.openrouterModel||"openrouter/free"),b(ye.moltbookApiKeyConfigured),j(ye.claudeOAuthTokenConfigured??!1),B(ye.openaiApiKeyConfigured??!1),X(ye.anthropicApiKeyConfigured??!1),we(ye.memory??Eh)}).catch(ye=>W(ye instanceof Error?ye.message:"Unknown error")).finally(()=>q(!1)),se.getAuthStatus().then(ye=>{z(ye.enabled),Je(ye.activeSessions)}).catch(()=>{})},[]);async function V(ye){ye.preventDefault(),M(!0),W(""),D(!1);try{const Mt=n.trim(),ns=h.trim(),rn={openrouterModel:l.trim()||"openrouter/free"};Mt&&(rn.openrouterApiKey=Mt),ns&&(rn.moltbookApiKey=ns);const Qn=await se.updateSettings(rn);f(Qn.openrouterApiKeyConfigured),b(Qn.moltbookApiKeyConfigured),a(""),m(""),D(!0),setTimeout(()=>D(!1),1800)}catch(Mt){W(Mt instanceof Error?Mt.message:"Unknown error")}finally{M(!1)}}async function le(){de(!0),Ke(""),Xt("");try{const ye=await se.forceCheckForUpdate();Hs(ye),ye.updateAvailable&&ye.latestVersion?Ke(`Update v${ye.latestVersion} is available.`):Ke("You are up to date.")}catch(ye){Xt(ye instanceof Error?ye.message:"Unknown error")}finally{de(!1)}}async function Ve(){Pe(!0),Ke(""),Xt("");try{const ye=await se.triggerUpdate();Ke(ye.message),xs(!0)}catch(ye){Xt(ye instanceof Error?ye.message:"Unknown error"),Pe(!1)}}return r.jsx("div",{className:`${e?"h-full":"h-[100dvh]"} bg-cc-bg text-cc-fg font-sans-ui antialiased overflow-y-auto`,children:r.jsxs("div",{className:"max-w-3xl mx-auto px-4 sm:px-8 py-6 sm:py-10",children:[r.jsxs("div",{className:"flex items-center gap-3 mb-1",children:[!e&&r.jsx("button",{onClick:()=>{globalThis.location.hash=""},className:"flex items-center justify-center w-8 h-8 rounded-lg text-cc-fg/60 hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer","aria-label":"Go back",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.8",className:"w-4 h-4",children:r.jsx("path",{d:"M10 3L5 8l5 5",strokeLinecap:"round",strokeLinejoin:"round"})})}),r.jsxs("div",{children:[r.jsx("p",{className:"text-[11px] text-cc-fg/50 font-medium",children:"Settings"}),r.jsx("h1",{className:"text-xl font-semibold text-cc-fg -mt-0.5",children:"Settings"})]})]}),r.jsx("div",{className:"mt-5 mb-6 border-b border-cc-border/40",children:r.jsx("nav",{className:"flex gap-0 -mb-px overflow-x-auto","aria-label":"Settings tabs",children:x9.map(ye=>r.jsx("button",{onClick:()=>s(ye.id),className:`px-4 py-2.5 text-[13px] font-medium whitespace-nowrap border-b-2 transition-colors cursor-pointer ${t===ye.id?"border-cc-primary text-cc-fg":"border-transparent text-cc-fg/55 hover:text-cc-fg hover:border-cc-border/60"}`,"aria-selected":t===ye.id,role:"tab",children:ye.label},ye.id))})}),r.jsxs("div",{className:"space-y-5",children:[t==="general"&&r.jsx(y9,{telemetryEnabled:te,setTelemetryEnabled:fe}),t==="providers"&&r.jsx(w9,{claudeOAuthToken:v,setClaudeOAuthToken:y,claudeConfigured:S,setClaudeConfigured:j,openaiApiKey:k,setOpenaiApiKey:E,openaiConfigured:N,setOpenaiConfigured:B,anthropicApiKey:A,setAnthropicApiKey:P,anthropicConfigured:K,setAnthropicConfigured:X,providerSaving:Z,setProviderSaving:I,providerSaved:H,setProviderSaved:F,error:O,setError:W}),t==="api-keys"&&r.jsx(S9,{openrouterApiKey:n,setOpenrouterApiKey:a,openrouterModel:l,setOpenrouterModel:c,configured:d,moltbookApiKey:h,setMoltbookApiKey:m,moltbookConfigured:g,loading:G,saving:R,error:O,saved:U,onSave:V}),t==="memory"&&r.jsx(k9,{initial:$e}),t==="security"&&r.jsx(C9,{authEnabled:$,setAuthEnabled:z,authPassword:T,setAuthPassword:ae,authSaving:be,setAuthSaving:ne,authSaved:ve,setAuthSaved:Ae,authError:De,setAuthError:ke,authSessions:Xe}),t==="notifications"&&r.jsx(N9,{notificationSound:mt,toggleNotificationSound:ss,notificationDesktop:Kt,setNotificationDesktop:Ft,notificationApiAvailable:_t}),t==="appearance"&&r.jsx(E9,{darkMode:Ze,toggleDarkMode:ft}),t==="updates"&&r.jsx(M9,{updateInfo:Dt,updateError:Yt,updateStatus:qe,checkingUpdates:lr,updatingApp:_e,onCheckUpdates:le,onTriggerUpdate:Ve})]})]})})}function A9({password:e,saving:t,onPasswordChange:s,onEnable:n}){return r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{children:[r.jsx("label",{htmlFor:"auth-password",className:"text-[12px] font-medium text-cc-fg block mb-1.5",children:"Set a password"}),r.jsx("input",{id:"auth-password",type:"password",value:e,onChange:a=>s(a.target.value),placeholder:"Minimum 4 characters",className:"w-full h-10 px-3 rounded-lg border border-cc-border bg-cc-input-bg text-[13px] text-cc-fg focus:outline-none focus:ring-2 focus:ring-cc-primary/20 focus:border-cc-primary/40"})]}),r.jsx("button",{type:"button",disabled:e.length<4||t,onClick:n,className:"w-full h-10 rounded-lg bg-cc-primary text-white text-[13px] font-medium hover:bg-cc-primary-hover transition-colors cursor-pointer disabled:opacity-40",children:t?"Enabling...":"Enable Authentication"})]})}function R9({saving:e,onDisable:t}){return r.jsxs("div",{className:"space-y-3",children:[r.jsx("div",{className:"rounded-lg border border-cc-border/40 bg-cc-hover/30 px-4 py-3",children:r.jsxs("p",{className:"text-[11px] text-cc-muted leading-relaxed",children:["All REST API requests require a ",r.jsx("code",{className:"font-mono-code text-[10px] bg-cc-hover px-1 rounded",children:"Bearer"})," token. All WebSocket connections require an ",r.jsx("code",{className:"font-mono-code text-[10px] bg-cc-hover px-1 rounded",children:"auth_token"})," parameter. CLI connections from localhost are allowed without a token."]})}),r.jsx("button",{type:"button",disabled:e,onClick:t,className:"w-full h-10 rounded-lg border border-cc-error/30 text-cc-error text-[13px] font-medium hover:bg-cc-error/5 transition-colors cursor-pointer disabled:opacity-40",children:e?"Disabling...":"Disable Authentication"})]})}const D9=w.lazy(()=>Xi(()=>Promise.resolve().then(()=>fu),void 0).then(e=>({default:e.CodeEditor})));function L9(e){const t=Date.now()-e,s=Math.floor(t/6e4);if(s<1)return"just now";if(s<60)return`${s}m ago`;const n=Math.floor(s/60);return n<24?`${n}h ago`:`${Math.floor(n/24)}d ago`}function B9(e){const t=e-Date.now();if(t<=0)return"now";const s=Math.floor(t/6e4);if(s<60)return`in ${s}m`;const n=Math.floor(s/60);return n<24?`in ${n}h`:`in ${Math.floor(n/24)}d`}function BC(e,t){if(!t)return"One-time";const s=e.trim().split(/\s+/);if(s.length!==5)return e;const[n,a,l,c,d]=s;if(e==="* * * * *")return"Every minute";if(a==="*"&&l==="*"&&c==="*"&&d==="*"&&n.startsWith("*/")){const f=parseInt(n.slice(2),10);return f===1?"Every minute":`Every ${f} minutes`}if(n==="0"&&l==="*"&&c==="*"&&d==="*"){if(a==="*")return"Every hour";if(a.startsWith("*/")){const f=parseInt(a.slice(2),10);return f===1?"Every hour":`Every ${f} hours`}}if(l==="*"&&c==="*"&&n!=="*"&&a!=="*"&&!a.includes("/")&&!a.includes(",")){const f=parseInt(a,10),h=parseInt(n,10);if(!isNaN(f)&&!isNaN(h)){const m=f>=12?"PM":"AM",g=f===0?12:f>12?f-12:f,b=h.toString().padStart(2,"0"),v=`${g}:${b} ${m}`;if(d==="*")return`Every day at ${v}`;if(d==="1-5")return`Weekdays at ${v}`;if(d==="0,6")return`Weekends at ${v}`}}return e}const bg={name:"",prompt:"",recurring:!0,schedule:"0 8 * * *",oneTimeDate:"",backendType:"claude",model:ri("claude"),cwd:""},O9=[{label:"Every hour",value:"0 * * * *"},{label:"Every day at 8am",value:"0 8 * * *"},{label:"Every 2 hours",value:"0 */2 * * *"},{label:"Weekdays at 9am",value:"0 9 * * 1-5"}];function z9({onClose:e,embedded:t=!1}){const[s,n]=w.useState([]),[a,l]=w.useState(!0),[c,d]=w.useState(""),[f,h]=w.useState(null),[m,g]=w.useState(bg),[b,v]=w.useState(bg),[y,S]=w.useState(!1),[j,k]=w.useState(!0),[E,N]=w.useState(new Set),B=w.useCallback(()=>{se.listCronJobs().then(n).catch(()=>{}).finally(()=>l(!1))},[]);w.useEffect(()=>{B();const M=setInterval(B,1e4);return()=>clearInterval(M)},[B]);async function A(){const M=b.name.trim(),O=b.prompt.trim();if(!M||!O)return;S(!0),d("");let W=b.schedule;!b.recurring&&b.oneTimeDate&&(W=new Date(b.oneTimeDate).toISOString());try{await se.createCronJob({name:M,prompt:O,schedule:W,recurring:b.recurring,backendType:b.backendType,model:b.backendType==="codex"?"":b.model.trim()||void 0,cwd:b.cwd.trim()||void 0}),v(bg),k(!0),B()}catch(U){d(U instanceof Error?U.message:String(U))}finally{S(!1)}}function P(M){h(M.id),g({name:M.name,prompt:M.prompt,recurring:M.recurring,schedule:M.schedule,oneTimeDate:"",backendType:M.backendType,model:M.model,cwd:M.cwd}),d("")}function K(){h(null),d("")}async function X(){if(!f)return;const M=m.name.trim(),O=m.prompt.trim();if(!M||!O)return;let W=m.schedule;!m.recurring&&m.oneTimeDate&&(W=new Date(m.oneTimeDate).toISOString());try{await se.updateCronJob(f,{name:M,prompt:O,schedule:W,recurring:m.recurring,backendType:m.backendType,model:m.backendType==="codex"?"":m.model.trim()||void 0,cwd:m.cwd.trim()||void 0}),h(null),d(""),B()}catch(U){d(U instanceof Error?U.message:String(U))}}async function Z(M){try{await se.deleteCronJob(M),f===M&&h(null),B()}catch(O){d(O instanceof Error?O.message:String(O))}}async function I(M){try{await se.toggleCronJob(M),B()}catch(O){d(O instanceof Error?O.message:String(O))}}async function H(M){N(O=>new Set(O).add(M));try{await se.runCronJob(M),B()}catch(O){d(O instanceof Error?O.message:String(O))}finally{N(O=>{const W=new Set(O);return W.delete(M),W})}}const F=c&&r.jsx("div",{className:"px-3 py-2 rounded-lg bg-cc-error/10 border border-cc-error/20 text-xs text-cc-error",children:c}),G=a?r.jsx("div",{className:"text-sm text-cc-muted text-center py-6",children:"Loading scheduled tasks..."}):s.length===0?r.jsx("div",{className:"text-sm text-cc-muted text-center py-6",children:"No scheduled tasks yet. Create one below."}):r.jsx("div",{className:"space-y-3",children:s.map(M=>r.jsxs("div",{className:"border border-cc-border rounded-lg overflow-hidden bg-cc-card",children:[r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5 bg-cc-card border-b border-cc-border",children:[r.jsx("span",{className:"text-sm font-medium text-cc-fg flex-1 truncate",children:M.name}),r.jsx("span",{className:`text-[9px] font-medium px-1.5 rounded-full leading-[16px] shrink-0 ${M.backendType==="codex"?"text-blue-500 bg-blue-500/10":"text-[#5BA8A0] bg-[#5BA8A0]/10"}`,children:M.backendType==="codex"?"Codex":"Claude"}),M.consecutiveFailures>0&&r.jsxs("span",{className:"text-[9px] font-medium px-1.5 rounded-full leading-[16px] shrink-0 text-cc-error bg-cc-error/10",children:[M.consecutiveFailures," fail",M.consecutiveFailures!==1?"s":""]}),r.jsx("button",{onClick:()=>I(M.id),className:`relative w-8 h-[18px] rounded-full transition-colors cursor-pointer shrink-0 ${M.enabled?"bg-cc-primary":"bg-cc-border"}`,title:M.enabled?"Disable":"Enable",children:r.jsx("span",{className:`absolute top-[2px] w-[14px] h-[14px] rounded-full bg-white transition-transform ${M.enabled?"left-[16px]":"left-[2px]"}`})}),f===M.id?r.jsx("button",{onClick:K,className:"text-xs text-cc-muted hover:text-cc-fg cursor-pointer",children:"Cancel"}):r.jsxs(r.Fragment,{children:[r.jsx("button",{onClick:()=>H(M.id),disabled:E.has(M.id),className:`text-xs cursor-pointer ${E.has(M.id)?"text-cc-muted cursor-not-allowed":"text-cc-primary hover:text-cc-primary-hover"}`,children:E.has(M.id)?"Running...":"Run Now"}),r.jsx("button",{onClick:()=>P(M),className:"text-xs text-cc-muted hover:text-cc-fg cursor-pointer",children:"Edit"}),r.jsx("button",{onClick:()=>Z(M.id),className:"text-xs text-cc-muted hover:text-cc-error cursor-pointer",children:"Delete"})]})]}),f===M.id&&r.jsxs("div",{className:"px-3 py-3 space-y-2.5",children:[r.jsx(d2,{form:m,onChange:g}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("button",{onClick:X,className:"px-3 py-2 text-xs font-medium bg-cc-primary hover:bg-cc-primary-hover text-white rounded-lg transition-colors cursor-pointer",children:"Save"}),r.jsx("button",{onClick:K,className:"px-3 py-2 text-xs font-medium text-cc-muted hover:text-cc-fg rounded-lg transition-colors cursor-pointer",children:"Cancel"})]})]}),f!==M.id&&r.jsxs("div",{className:"px-3 py-2.5 space-y-1.5",children:[r.jsx("div",{className:"text-xs text-cc-muted truncate",title:M.prompt,children:M.prompt}),r.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px] text-cc-muted",children:[r.jsx("span",{children:BC(M.schedule,M.recurring)}),M.nextRunAt!=null&&M.enabled&&r.jsxs("span",{children:["Next: ",B9(M.nextRunAt)]}),M.lastRunAt!=null&&r.jsxs("span",{className:"flex items-center gap-1",children:["Last: ",L9(M.lastRunAt),M.consecutiveFailures===0?r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 text-cc-success",children:r.jsx("path",{d:"M12.207 4.793a1 1 0 010 1.414l-5 5a1 1 0 01-1.414 0l-2.5-2.5a1 1 0 011.414-1.414L6.5 9.086l4.293-4.293a1 1 0 011.414 0z"})}):r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 text-cc-error",children:r.jsx("path",{d:"M4.646 4.646a.5.5 0 01.708 0L8 7.293l2.646-2.647a.5.5 0 01.708.708L8.707 8l2.647 2.646a.5.5 0 01-.708.708L8 8.707l-2.646 2.647a.5.5 0 01-.708-.708L7.293 8 4.646 5.354a.5.5 0 010-.708z"})})]}),M.totalRuns>0&&r.jsxs("span",{children:[M.totalRuns," run",M.totalRuns!==1?"s":""]}),M.cwd&&r.jsx("span",{className:"font-mono-code truncate max-w-[200px]",title:M.cwd,children:M.cwd})]})]})]},M.id))}),q=r.jsxs("div",{className:"border border-cc-border rounded-lg overflow-hidden bg-cc-card",children:[r.jsxs("button",{onClick:()=>k(!j),className:"w-full flex items-center gap-2 px-3 py-2.5 bg-cc-card border-b border-cc-border cursor-pointer hover:bg-cc-hover transition-colors",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",className:`w-3 h-3 text-cc-muted transition-transform ${j?"":"rotate-90"}`,children:r.jsx("path",{d:"M6 4l4 4-4 4",strokeLinecap:"round",strokeLinejoin:"round"})}),r.jsx("span",{className:"text-sm font-medium text-cc-fg",children:"New Scheduled Task"})]}),!j&&r.jsxs("div",{className:"px-3 py-3 space-y-2.5",children:[r.jsx(d2,{form:b,onChange:v}),r.jsx("div",{className:"text-[10px] text-cc-muted",children:"Scheduled tasks run with full autonomy (bypassPermissions)"}),r.jsx("button",{onClick:A,disabled:!b.name.trim()||!b.prompt.trim()||y,className:`px-3 py-2 text-xs font-medium rounded-lg transition-colors ${b.name.trim()&&b.prompt.trim()&&!y?"bg-cc-primary hover:bg-cc-primary-hover text-white cursor-pointer":"bg-cc-hover text-cc-muted cursor-not-allowed"}`,children:y?"Creating...":"Create"})]})]});if(t)return r.jsx("div",{className:"h-full bg-cc-bg overflow-y-auto",children:r.jsxs("div",{className:"max-w-5xl mx-auto px-4 sm:px-8 py-6 sm:py-10",children:[r.jsxs("div",{className:"mb-6",children:[r.jsx("h1",{className:"text-xl font-semibold text-cc-fg",children:"Scheduled Tasks"}),r.jsx("p",{className:"mt-1 text-sm text-cc-muted",children:"Run autonomous Claude Code or Codex sessions on a schedule."})]}),F,r.jsxs("div",{className:"mt-4 space-y-4",children:[r.jsxs("section",{className:"bg-cc-card border border-cc-border rounded-xl p-4 sm:p-5 space-y-3",children:[r.jsx("h2",{className:"text-sm font-semibold text-cc-fg",children:"Tasks"}),G]}),r.jsx("section",{className:"bg-cc-card border border-cc-border rounded-xl p-4 sm:p-5 space-y-3",children:q})]})]})});const R=r.jsxs("div",{className:"w-full max-w-2xl max-h-[90dvh] sm:max-h-[80dvh] mx-0 sm:mx-4 flex flex-col bg-cc-bg border border-cc-border rounded-t-xl sm:rounded-xl shadow-2xl overflow-hidden",onClick:M=>M.stopPropagation(),children:[r.jsxs("div",{className:"flex items-center justify-between px-4 sm:px-5 py-3 sm:py-4 border-b border-cc-border",children:[r.jsxs("div",{children:[r.jsx("h2",{className:"text-sm font-semibold text-cc-fg",children:"Scheduled Tasks"}),r.jsx("p",{className:"text-xs text-cc-muted mt-0.5",children:"Run autonomous Claude Code or Codex sessions on a schedule"})]}),e&&r.jsx("button",{onClick:e,className:"w-6 h-6 flex items-center justify-center rounded-md text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"w-3.5 h-3.5",children:r.jsx("path",{d:"M4 4l8 8M12 4l-8 8",strokeLinecap:"round"})})})]}),r.jsxs("div",{className:"flex-1 overflow-y-auto px-3 sm:px-5 py-3 sm:py-4 space-y-4",children:[F,G,q]})]});return rv.createPortal(r.jsx("div",{className:"fixed inset-0 z-50 flex items-end sm:items-center justify-center bg-black/50",onClick:e,children:R}),document.body)}function d2({form:e,onChange:t}){const s=g=>t({...e,...g}),[n,a]=w.useState(!1),l=w.useRef(null),[c,d]=w.useState(!1),f=Zh(e.backendType),h=f.find(g=>g.value===e.model)||f[0];w.useEffect(()=>{e.model||s({model:ri(e.backendType)})},[]),w.useEffect(()=>{if(!n)return;function g(b){l.current&&!l.current.contains(b.target)&&a(!1)}return document.addEventListener("pointerdown",g),()=>document.removeEventListener("pointerdown",g)},[n]);const m=e.cwd?e.cwd.split("/").pop()||e.cwd:"Select folder";return r.jsxs("div",{className:"space-y-2.5",children:[r.jsx("input",{type:"text",value:e.name,onChange:g=>s({name:g.target.value}),placeholder:"Task name (e.g. Daily test suite)",className:"w-full px-3 py-2 text-sm bg-cc-input-bg border border-cc-border rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:border-cc-primary/50"}),r.jsx("div",{children:r.jsx(w.Suspense,{fallback:r.jsx("div",{className:"h-[150px] rounded-xl border border-cc-border flex items-center justify-center text-cc-muted text-[12px]",children:"Loading editor..."}),children:r.jsx(D9,{value:e.prompt,onChange:g=>s({prompt:g}),language:"markdown",height:"150px",minimap:!1,wordWrap:!0,ariaLabel:"Cron job prompt editor"})})}),r.jsxs("div",{className:"space-y-2",children:[r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx("button",{onClick:()=>s({recurring:!0}),className:`px-2.5 py-1.5 text-xs font-medium rounded-lg transition-colors cursor-pointer ${e.recurring?"bg-cc-primary text-white":"bg-cc-hover text-cc-muted hover:text-cc-fg"}`,children:"Recurring"}),r.jsx("button",{onClick:()=>s({recurring:!1}),className:`px-2.5 py-1.5 text-xs font-medium rounded-lg transition-colors cursor-pointer ${e.recurring?"bg-cc-hover text-cc-muted hover:text-cc-fg":"bg-cc-primary text-white"}`,children:"One-time"})]}),e.recurring?r.jsxs("div",{className:"space-y-1.5",children:[r.jsx("div",{className:"flex flex-wrap gap-1.5",children:O9.map(g=>r.jsx("button",{onClick:()=>s({schedule:g.value}),className:`px-2 py-1 text-[10px] font-medium rounded-md transition-colors cursor-pointer ${e.schedule===g.value?"bg-cc-primary/20 text-cc-primary border border-cc-primary/30":"bg-cc-hover text-cc-muted hover:text-cc-fg border border-transparent"}`,children:g.label},g.value))}),r.jsx("input",{type:"text",value:e.schedule,onChange:g=>s({schedule:g.target.value}),placeholder:"Cron expression (e.g. 0 8 * * *)",className:"w-full px-3 py-2 text-sm font-mono-code bg-cc-input-bg border border-cc-border rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:border-cc-primary/50"}),r.jsx("div",{className:"text-[10px] text-cc-muted",children:BC(e.schedule,!0)})]}):r.jsx("input",{type:"datetime-local",value:e.oneTimeDate,onChange:g=>s({oneTimeDate:g.target.value}),className:"w-full px-3 py-2 text-sm bg-cc-input-bg border border-cc-border rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:border-cc-primary/50"})]}),r.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[r.jsx("button",{onClick:()=>{const g=["claude","codex","goose","aider","openhands","openclaw","opencode"],b=g.indexOf(e.backendType),v=g[(b+1)%g.length];s({backendType:v,model:ri(v)})},className:`px-2.5 py-1.5 text-xs font-medium rounded-lg transition-colors cursor-pointer ${e.backendType==="codex"?"bg-blue-500/15 text-blue-500 border border-blue-500/30":"bg-[#5BA8A0]/15 text-[#5BA8A0] border border-[#5BA8A0]/30"}`,children:e.backendType==="codex"?"Codex":"Claude Code"}),e.backendType==="codex"?r.jsx("div",{className:"flex items-center gap-1.5 px-2 py-1.5 text-xs text-cc-muted rounded-lg border border-cc-border",children:"Codex default"}):r.jsxs("div",{className:"relative",ref:l,children:[r.jsxs("button",{onClick:()=>a(!n),className:"flex items-center gap-1.5 px-2 py-1.5 text-xs text-cc-muted hover:text-cc-fg rounded-lg hover:bg-cc-hover transition-colors cursor-pointer border border-cc-border",children:[r.jsx("span",{children:h==null?void 0:h.icon}),r.jsx("span",{children:h==null?void 0:h.label}),r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 opacity-50",children:r.jsx("path",{d:"M4 6l4 4 4-4"})})]}),n&&r.jsx("div",{className:"absolute left-0 bottom-full mb-1 w-52 bg-cc-card border border-cc-border rounded-lg shadow-lg z-10 py-1",children:f.map(g=>r.jsxs("button",{onClick:()=>{s({model:g.value}),a(!1)},className:`w-full px-3 py-2 text-xs text-left hover:bg-cc-hover transition-colors cursor-pointer flex items-center gap-2 ${g.value===e.model?"text-cc-primary font-medium":"text-cc-fg"}`,children:[r.jsx("span",{children:g.icon}),g.label]},g.value))})]}),r.jsxs("button",{onClick:()=>d(!0),className:"flex items-center gap-1.5 px-2 py-1.5 text-xs text-cc-muted hover:text-cc-fg rounded-lg hover:bg-cc-hover transition-colors cursor-pointer border border-cc-border",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 opacity-60",children:r.jsx("path",{d:"M1 3.5A1.5 1.5 0 012.5 2h3.379a1.5 1.5 0 011.06.44l.622.621a.5.5 0 00.353.146H13.5A1.5 1.5 0 0115 4.707V12.5a1.5 1.5 0 01-1.5 1.5h-11A1.5 1.5 0 011 12.5v-9z"})}),r.jsx("span",{className:"max-w-[200px] truncate font-mono-code",children:m}),r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 opacity-50",children:r.jsx("path",{d:"M4 6l4 4 4-4"})})]}),c&&r.jsx(iv,{initialPath:e.cwd||"",onSelect:g=>s({cwd:g}),onClose:()=>d(!1)})]})]})}/**
|
|
233
|
+
}`,mode:"full"})}),r.jsx(Le,{label:"No changes",children:r.jsx(yr,{oldText:"same content",newText:"same content"})})]})}),r.jsx(vt,{title:"CLAUDE.md Editor",description:"Modal for viewing and editing project CLAUDE.md instructions",children:r.jsx("div",{className:"space-y-4 max-w-3xl",children:r.jsx(Le,{label:"Open editor button (from TopBar)",children:r.jsx(AP,{})})})}),r.jsx(vt,{title:"Gallery Cards",description:"Session gallery entries with voting, tags, featured badge, and stats",children:r.jsxs("div",{className:"space-y-4 max-w-3xl",children:[r.jsx(Le,{label:"Featured entry with high votes",children:r.jsx(oh,{entry:yP,onVote:()=>{},onDelete:()=>{},onFeature:()=>{}})}),r.jsx(Le,{label:"Regular entry with tags",children:r.jsx(oh,{entry:wP,onVote:()=>{},onDelete:()=>{},onFeature:()=>{}})}),r.jsx(Le,{label:"Codex entry with low cost",children:r.jsx(oh,{entry:SP,onVote:()=>{},onDelete:()=>{},onFeature:()=>{}})})]})}),r.jsx(vt,{title:"Webhook & Adapter Pages",description:"Management UIs for webhooks and community adapters (navigate to #/webhooks or #/adapters)",children:r.jsxs("div",{className:"space-y-4 max-w-3xl",children:[r.jsx(Le,{label:"Webhook card with delivery stats",children:r.jsxs("div",{className:"border border-cc-border rounded-lg overflow-hidden bg-cc-card",children:[r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5 bg-cc-card border-b border-cc-border",children:[r.jsx("span",{className:"text-sm font-medium text-cc-fg flex-1 truncate",children:"Slack Notifications"}),r.jsx("span",{className:"text-[9px] font-medium px-1.5 rounded-full leading-[16px] shrink-0 text-cc-success bg-cc-success/10",children:"47/50"}),r.jsx("span",{className:"relative w-8 h-[18px] rounded-full bg-cc-primary shrink-0",children:r.jsx("span",{className:"absolute top-[2px] left-[16px] w-[14px] h-[14px] rounded-full bg-white"})})]}),r.jsxs("div",{className:"px-3 py-2.5 space-y-1.5",children:[r.jsx("div",{className:"text-xs text-cc-muted font-mono-code truncate",children:"https://hooks.slack.com/services/T00.../B00.../xxx"}),r.jsx("div",{className:"flex flex-wrap gap-1.5",children:["session.completed","session.failed","cost.threshold"].map(s=>r.jsx("span",{className:"text-[9px] font-medium px-1.5 py-0.5 rounded-full bg-cc-hover text-cc-muted",children:s},s))}),r.jsxs("div",{className:"flex items-center gap-3 text-[11px] text-cc-muted",children:[r.jsxs("span",{className:"flex items-center gap-1",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3",children:r.jsx("path",{d:"M8 1a3.5 3.5 0 00-3.5 3.5V7H4a1 1 0 00-1 1v5a1 1 0 001 1h8a1 1 0 001-1V8a1 1 0 00-1-1h-.5V4.5A3.5 3.5 0 008 1zm2 6H6V4.5a2 2 0 114 0V7z"})}),"Signed"]}),r.jsx("span",{children:"Last: 5m ago"})]})]})]})}),r.jsx(Le,{label:"Adapter card with models",children:r.jsxs("div",{className:"border border-cc-border rounded-lg overflow-hidden bg-cc-card",children:[r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5 bg-cc-card border-b border-cc-border",children:[r.jsx("span",{className:"text-sm font-medium text-cc-fg flex-1 truncate",children:"My Custom Agent"}),r.jsx("span",{className:"text-[9px] font-medium px-1.5 rounded-full leading-[16px] shrink-0 text-cc-muted bg-cc-hover",children:"v1.2.0"}),r.jsx("span",{className:"text-[9px] font-medium px-1.5 rounded-full leading-[16px] shrink-0 text-blue-500 bg-blue-500/10",children:"WebSocket"})]}),r.jsxs("div",{className:"px-3 py-2.5 space-y-1.5",children:[r.jsx("div",{className:"text-xs text-cc-muted",children:"A custom agent for automated code review"}),r.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px] text-cc-muted",children:[r.jsx("span",{className:"font-mono-code",children:"my-agent"}),r.jsx("span",{children:"3 models"}),r.jsx("span",{children:"by @community"}),r.jsx("span",{className:"font-mono-code",children:"@campfire/my-agent"})]}),r.jsx("div",{className:"flex flex-wrap gap-1",children:["GPT-4o","GPT-4o-mini","o1-preview"].map(s=>r.jsx("span",{className:"text-[9px] font-medium px-1.5 py-0.5 rounded-full bg-cc-hover text-cc-muted",children:s},s))})]})]})})]})})]})]})}function vt({title:e,description:t,children:s}){return r.jsxs("section",{children:[r.jsxs("div",{className:"mb-4",children:[r.jsx("h2",{className:"text-base font-semibold text-cc-fg",children:e}),r.jsx("p",{className:"text-xs text-cc-muted mt-0.5",children:t})]}),s]})}function Le({label:e,children:t}){return r.jsxs("div",{className:"border border-cc-border rounded-xl overflow-hidden bg-cc-card",children:[r.jsx("div",{className:"px-3 py-1.5 bg-cc-hover/50 border-b border-cc-border",children:r.jsx("span",{className:"text-[10px] text-cc-muted font-mono-code uppercase tracking-wider",children:e})}),r.jsx("div",{className:"p-4",children:t})]})}function Ax({toolName:e,items:t}){const[s,n]=w.useState(!1),a=du(e),l=Ta(e),c=t.length;if(c===1){const d=t[0];return r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx("div",{className:"w-6 h-6 rounded-full bg-cc-primary/10 flex items-center justify-center shrink-0 mt-0.5",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 text-cc-primary",children:r.jsx("circle",{cx:"8",cy:"8",r:"3"})})}),r.jsx("div",{className:"flex-1 min-w-0",children:r.jsxs("div",{className:"border border-cc-border rounded-lg overflow-hidden bg-cc-card",children:[r.jsxs("button",{onClick:()=>n(!s),className:"w-full flex items-center gap-2.5 px-3 py-2 text-left hover:bg-cc-hover transition-colors cursor-pointer",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:`w-3 h-3 text-cc-muted transition-transform shrink-0 ${s?"rotate-90":""}`,children:r.jsx("path",{d:"M6 4l4 4-4 4"})}),r.jsx(Aa,{type:a}),r.jsx("span",{className:"text-xs font-medium text-cc-fg",children:l}),r.jsx("span",{className:"text-xs text-cc-muted truncate flex-1 font-mono-code",children:Ko(d.name,d.input)})]}),s&&r.jsx("div",{className:"px-3 pb-3 pt-0 border-t border-cc-border mt-0",children:r.jsx("pre",{className:"mt-2 text-[11px] text-cc-muted font-mono-code whitespace-pre-wrap leading-relaxed max-h-60 overflow-y-auto",children:JSON.stringify(d.input,null,2)})})]})})]})}return r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx("div",{className:"w-6 h-6 rounded-full bg-cc-primary/10 flex items-center justify-center shrink-0 mt-0.5",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 text-cc-primary",children:r.jsx("circle",{cx:"8",cy:"8",r:"3"})})}),r.jsx("div",{className:"flex-1 min-w-0",children:r.jsxs("div",{className:"border border-cc-border rounded-lg overflow-hidden bg-cc-card",children:[r.jsxs("button",{onClick:()=>n(!s),className:"w-full flex items-center gap-2.5 px-3 py-2 text-left hover:bg-cc-hover transition-colors cursor-pointer",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:`w-3 h-3 text-cc-muted transition-transform shrink-0 ${s?"rotate-90":""}`,children:r.jsx("path",{d:"M6 4l4 4-4 4"})}),r.jsx(Aa,{type:a}),r.jsx("span",{className:"text-xs font-medium text-cc-fg",children:l}),r.jsx("span",{className:"text-[10px] text-cc-muted bg-cc-hover rounded-full px-1.5 py-0.5 tabular-nums font-medium",children:c})]}),s&&r.jsx("div",{className:"border-t border-cc-border px-3 py-1.5",children:t.map((d,f)=>{const h=Ko(d.name,d.input);return r.jsxs("div",{className:"flex items-center gap-2 py-1 text-xs text-cc-muted font-mono-code truncate",children:[r.jsx("span",{className:"w-1 h-1 rounded-full bg-cc-muted/40 shrink-0"}),r.jsx("span",{className:"truncate",children:h||JSON.stringify(d.input).slice(0,80)})]},d.id||f)})})]})})]})}function EP({description:e,agentType:t,items:s}){var l;const[n,a]=w.useState(!0);return r.jsxs("div",{className:"ml-9 border-l-2 border-cc-border pl-4",children:[r.jsxs("button",{onClick:()=>a(!n),className:"w-full flex items-center gap-2 py-1.5 text-left cursor-pointer mb-1",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:`w-3 h-3 text-cc-muted transition-transform shrink-0 ${n?"rotate-90":""}`,children:r.jsx("path",{d:"M6 4l4 4-4 4"})}),r.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"w-3.5 h-3.5 text-cc-primary shrink-0",children:[r.jsx("circle",{cx:"8",cy:"8",r:"5"}),r.jsx("path",{d:"M8 5v3l2 1",strokeLinecap:"round"})]}),r.jsx("span",{className:"text-xs font-medium text-cc-fg truncate",children:e}),t&&r.jsx("span",{className:"text-[10px] text-cc-muted bg-cc-hover rounded-full px-1.5 py-0.5 shrink-0",children:t}),r.jsx("span",{className:"text-[10px] text-cc-muted bg-cc-hover rounded-full px-1.5 py-0.5 tabular-nums shrink-0 ml-auto",children:s.length})]}),n&&r.jsx("div",{className:"space-y-3 pb-2",children:r.jsx(Ax,{toolName:((l=s[0])==null?void 0:l.name)||"Grep",items:s})})]})}const No="codex-playground-demo";function MP(){return w.useEffect(()=>{const e=Y.getState(),t=e.sessions.get(No);return e.addSession({session_id:No,backend_type:"codex",model:"o3",cwd:"/Users/demo/project",tools:[],permissionMode:"bypassPermissions",claude_code_version:"0.1.0",mcp_servers:[],agents:[],slash_commands:[],skills:[],total_cost_usd:0,num_turns:8,context_used_percent:45,is_compacting:!1,git_branch:"main",is_worktree:!1,repo_root:"/Users/demo/project",git_ahead:0,git_behind:0,total_lines_added:0,total_lines_removed:0,total_duration_api_ms:0,codex_rate_limits:{primary:{usedPercent:62,windowDurationMins:300,resetsAt:Date.now()+2*36e5},secondary:{usedPercent:18,windowDurationMins:10080,resetsAt:Date.now()+5*864e5}},codex_token_details:{inputTokens:84230,outputTokens:12450,cachedInputTokens:41200,reasoningOutputTokens:8900,modelContextWindow:2e5}}),()=>{Y.setState(s=>{const n=new Map(s.sessions);return t?n.set(No,t):n.delete(No),{sessions:n}})}},[]),r.jsxs("div",{className:"w-[280px] border border-cc-border rounded-xl overflow-hidden bg-cc-card",children:[r.jsx(yC,{sessionId:No}),r.jsx(wC,{sessionId:No})]})}const cc="claude-playground-demo";function TP(){return w.useEffect(()=>{const e=Y.getState(),t=e.sessions.get(cc);return e.addSession({session_id:cc,backend_type:"claude",model:"claude-sonnet-4-20250514",cwd:"/Users/demo/project",tools:[],permissionMode:"default",claude_code_version:"1.0.0",mcp_servers:[],agents:[],slash_commands:[],skills:[],total_cost_usd:.87,num_turns:5,context_used_percent:38,is_compacting:!1,git_branch:"feat/auth",is_worktree:!1,repo_root:"/Users/demo/project",git_ahead:2,git_behind:0,total_lines_added:142,total_lines_removed:23,total_duration_api_ms:45e3,claude_token_details:{inputTokens:125400,outputTokens:18200,cacheReadInputTokens:98300,cacheCreationInputTokens:12600,contextWindow:2e5,costUsd:.87}}),()=>{Y.setState(s=>{const n=new Map(s.sessions);return t?n.set(cc,t):n.delete(cc),{sessions:n}})}},[]),r.jsx("div",{className:"w-[280px] border border-cc-border rounded-xl overflow-hidden bg-cc-card",children:r.jsx(SC,{sessionId:cc})})}function gg({updateInfo:e}){return w.useEffect(()=>{const t=Y.getState().updateInfo,s=Y.getState().updateDismissedVersion;return Y.getState().setUpdateInfo(e),s&&Y.setState({updateDismissedVersion:null}),()=>{Y.getState().setUpdateInfo(t),s&&Y.setState({updateDismissedVersion:s})}},[e]),r.jsx(DC,{})}function AP(){const[e,t]=w.useState(!1),[s,n]=w.useState("/tmp");return w.useEffect(()=>{se.getHome().then(a=>n(a.cwd)).catch(()=>{})},[]),r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsxs("button",{onClick:()=>t(!0),className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-cc-hover border border-cc-border hover:bg-cc-active transition-colors cursor-pointer",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-4 h-4 text-cc-primary",children:r.jsx("path",{d:"M4 1.5a.5.5 0 01.5-.5h7a.5.5 0 01.354.146l2 2A.5.5 0 0114 3.5v11a.5.5 0 01-.5.5h-11a.5.5 0 01-.5-.5v-13zm1 .5v12h8V4h-1.5a.5.5 0 01-.5-.5V2H5zm6 0v1h1l-1-1zM6.5 7a.5.5 0 000 1h5a.5.5 0 000-1h-5zm0 2a.5.5 0 000 1h5a.5.5 0 000-1h-5zm0 2a.5.5 0 000 1h3a.5.5 0 000-1h-3z"})}),r.jsx("span",{className:"text-xs font-medium text-cc-fg",children:"Edit CLAUDE.md"})]}),r.jsx("span",{className:"text-[11px] text-cc-muted",children:"Click to open the editor modal (uses server working directory)"}),r.jsx(gC,{cwd:s,open:e,onClose:()=>t(!1)})]})}function RP({server:e}){var l;const[t,s]=w.useState(!1),n={connected:{label:"Connected",cls:"text-cc-success bg-cc-success/10",dot:"bg-cc-success"},connecting:{label:"Connecting",cls:"text-cc-warning bg-cc-warning/10",dot:"bg-cc-warning animate-pulse"},failed:{label:"Failed",cls:"text-cc-error bg-cc-error/10",dot:"bg-cc-error"},disabled:{label:"Disabled",cls:"text-cc-muted bg-cc-hover",dot:"bg-cc-muted opacity-40"}},a=n[e.status]||n.disabled;return r.jsxs("div",{className:"rounded-lg border border-cc-border bg-cc-bg",children:[r.jsxs("div",{className:"flex items-center gap-2 px-2.5 py-2",children:[r.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${a.dot}`}),r.jsx("button",{onClick:()=>s(!t),className:"flex-1 min-w-0 text-left cursor-pointer",children:r.jsx("span",{className:"text-[12px] font-medium text-cc-fg truncate block",children:e.name})}),r.jsx("span",{className:`text-[9px] font-medium px-1.5 rounded-full leading-[16px] shrink-0 ${a.cls}`,children:a.label})]}),t&&r.jsxs("div",{className:"px-2.5 pb-2.5 space-y-1.5 border-t border-cc-border pt-2",children:[r.jsxs("div",{className:"text-[11px] text-cc-muted space-y-0.5",children:[r.jsxs("div",{className:"flex items-center gap-1",children:[r.jsx("span",{className:"text-cc-muted/60",children:"Type:"}),r.jsx("span",{children:e.config.type})]}),e.config.command&&r.jsxs("div",{className:"flex items-start gap-1",children:[r.jsx("span",{className:"text-cc-muted/60 shrink-0",children:"Cmd:"}),r.jsxs("span",{className:"font-mono text-[10px] break-all",children:[e.config.command,(l=e.config.args)!=null&&l.length?` ${e.config.args.join(" ")}`:""]})]}),e.config.url&&r.jsxs("div",{className:"flex items-start gap-1",children:[r.jsx("span",{className:"text-cc-muted/60 shrink-0",children:"URL:"}),r.jsx("span",{className:"font-mono text-[10px] break-all",children:e.config.url})]}),r.jsxs("div",{className:"flex items-center gap-1",children:[r.jsx("span",{className:"text-cc-muted/60",children:"Scope:"}),r.jsx("span",{children:e.scope})]})]}),e.error&&r.jsx("div",{className:"text-[11px] text-cc-error bg-cc-error/5 rounded px-2 py-1",children:e.error}),e.tools&&e.tools.length>0&&r.jsxs("div",{className:"space-y-1",children:[r.jsxs("span",{className:"text-[10px] text-cc-muted uppercase tracking-wider",children:["Tools (",e.tools.length,")"]}),r.jsx("div",{className:"flex flex-wrap gap-1",children:e.tools.map(c=>r.jsx("span",{className:"text-[10px] font-mono px-1.5 py-0.5 rounded bg-cc-hover text-cc-fg",children:c.name},c.name))})]})]})]})}const uc="playground-spectator";function DP(){return w.useEffect(()=>{const e=Y.getState();return e.addSession({session_id:uc,backend_type:"claude",model:"claude-sonnet-4-5",cwd:"/tmp",tools:[],permissionMode:"default",claude_code_version:"1.0.0",mcp_servers:[],agents:[],slash_commands:[],skills:[],total_cost_usd:0,num_turns:0,context_used_percent:0,is_compacting:!1,git_branch:"main",is_worktree:!1,repo_root:"/tmp",git_ahead:0,git_behind:0,total_lines_added:0,total_lines_removed:0,total_duration_api_ms:0}),e.setMyRole(uc,"spectator"),()=>{Y.setState(t=>{const s=new Map(t.sessions);s.delete(uc);const n=new Map(t.myRole);return n.delete(uc),{sessions:s,myRole:n}})}},[]),r.jsx("div",{className:"border border-cc-border rounded-xl overflow-hidden bg-cc-card",children:r.jsx(Zs,{permission:CP,sessionId:uc})})}function qd({state:e,position:t,total:s,speed:n}){const a=e==="playing",l=e==="ended";return r.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 bg-cc-sidebar border border-cc-border rounded-lg",children:[r.jsx("button",{className:"w-8 h-8 rounded-full bg-cc-primary/10 flex items-center justify-center text-cc-primary hover:bg-cc-primary/20 transition-colors cursor-pointer shrink-0",children:l?r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:r.jsx("path",{d:"M2.5 2a.5.5 0 01.854-.354l4.646 4.647V2.5a.5.5 0 01.854-.354l5 5a.5.5 0 010 .708l-5 5A.5.5 0 018 12.5V8.707l-4.646 4.647A.5.5 0 012.5 13V2z"})}):a?r.jsxs("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:[r.jsx("rect",{x:"4",y:"3",width:"3",height:"10",rx:"0.75"}),r.jsx("rect",{x:"9",y:"3",width:"3",height:"10",rx:"0.75"})]}):r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:r.jsx("path",{d:"M4 2l10 6-10 6V2z"})})}),r.jsx("div",{className:"flex-1 min-w-0",children:r.jsx("div",{className:"relative w-full h-1.5 rounded-full bg-cc-hover overflow-hidden",children:r.jsx("div",{className:"absolute inset-y-0 left-0 rounded-full bg-cc-primary transition-all duration-300",style:{width:`${s>0?t/s*100:0}%`}})})}),r.jsxs("span",{className:"text-[11px] text-cc-muted tabular-nums font-mono-code shrink-0",children:[t,"/",s]}),r.jsx("div",{className:"flex items-center gap-0.5 shrink-0",children:[1,2,4,8].map(c=>r.jsxs("button",{className:`px-1.5 py-0.5 text-[10px] font-medium rounded transition-colors cursor-pointer ${c===n?"bg-cc-primary/20 text-cc-primary":"text-cc-muted hover:bg-cc-hover"}`,children:[c,"x"]},c))})]})}function LP({task:e}){const t=e.status==="completed",s=e.status==="in_progress";return r.jsxs("div",{className:`px-2.5 py-2 rounded-lg ${t?"opacity-50":""}`,children:[r.jsxs("div",{className:"flex items-start gap-2",children:[r.jsx("span",{className:"shrink-0 flex items-center justify-center w-4 h-4 mt-px",children:s?r.jsx("svg",{className:"w-4 h-4 text-cc-primary animate-spin",viewBox:"0 0 16 16",fill:"none",children:r.jsx("circle",{cx:"8",cy:"8",r:"6",stroke:"currentColor",strokeWidth:"1.5",strokeDasharray:"28",strokeDashoffset:"8",strokeLinecap:"round"})}):t?r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-4 h-4 text-cc-success",children:r.jsx("path",{fillRule:"evenodd",d:"M8 15A7 7 0 108 1a7 7 0 000 14zm3.354-9.354a.5.5 0 00-.708-.708L7 8.586 5.354 6.94a.5.5 0 10-.708.708l2 2a.5.5 0 00.708 0l4-4z",clipRule:"evenodd"})}):r.jsx("svg",{viewBox:"0 0 16 16",fill:"none",className:"w-4 h-4 text-cc-muted",children:r.jsx("circle",{cx:"8",cy:"8",r:"6",stroke:"currentColor",strokeWidth:"1.5"})})}),r.jsx("span",{className:`text-[13px] leading-snug flex-1 ${t?"text-cc-muted line-through":"text-cc-fg"}`,children:e.subject})]}),s&&e.activeForm&&r.jsx("p",{className:"mt-1 ml-6 text-[11px] text-cc-muted italic truncate",children:e.activeForm}),e.blockedBy&&e.blockedBy.length>0&&r.jsxs("p",{className:"mt-1 ml-6 text-[11px] text-cc-muted flex items-center gap-1",children:[r.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",className:"w-3 h-3 shrink-0",children:[r.jsx("circle",{cx:"8",cy:"8",r:"6",stroke:"currentColor",strokeWidth:"1.5"}),r.jsx("path",{d:"M5 8h6",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]}),r.jsxs("span",{children:["blocked by ",e.blockedBy.map(n=>`#${n}`).join(", ")]})]})]})}const BP={checking_image:"Checking image",pulling_image:"Pulling image",creating_container:"Creating container",seeding_auth:"Seeding authentication",launching_agent:"Launching agent"};function OP(e,t,s){return t?zP(t,s):$P(e,s)}function zP(e,t){const s=["checking_image","pulling_image","creating_container","seeding_auth","launching_agent"],n=s.indexOf(e.step),a=s.map((l,c)=>{let d="pending";return c<n?d="done":c===n&&(d="active"),{label:BP[l]||l,status:d}});if(t)for(const l of a)l.status="done";return a}function PP(e,t){return t?"done":e?"active":"pending"}function $P(e,t){const s=e==="starting",n=t||e==="connected"||e==="running";return[{label:"Spawning process",status:s||n?"done":"active"},{label:"Waiting for connection",status:PP(s,n)},{label:"Ready",status:n?"done":"pending"}]}function IP(e,t=2e3){const[s,n]=w.useState(!1),a=w.useRef(void 0);return w.useEffect(()=>(clearTimeout(a.current),e?a.current=setTimeout(()=>n(!0),t):n(!1),()=>clearTimeout(a.current)),[e,t]),s}function FP(){const e=Y(k=>k.sdkSessions),t=Y(k=>k.cliConnected),s=Y(k=>k.sessionCreating),n=Y(k=>k.creationProgress),a=Y(k=>k.creationError),l=Y(k=>k.sessionNames),c=e.filter(k=>k.state==="starting"&&!k.archived),d=s&&!a,f=c.length>0||d,h=c.length>0?c[c.length-1]:null,m=h==null?void 0:h.sessionId,g=m?l.get(m):null,b=h==null?void 0:h.state,v=m?t.get(m)??!1:!1,y=OP(b,d?n:null,v),S=y.every(k=>k.status==="done"),j=IP(S);return!f&&!a||j&&!a?null:a?r.jsx("div",{className:"fixed bottom-4 left-4 z-40 w-72 rounded-xl border border-cc-error/30 bg-cc-card shadow-float animate-slide-up overflow-hidden",children:r.jsxs("div",{className:"px-3 py-2.5 flex items-center gap-2",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-4 h-4 text-cc-error shrink-0","aria-hidden":!0,children:r.jsx("path",{d:"M3.72 3.72a.75.75 0 011.06 0L8 6.94l3.22-3.22a.75.75 0 111.06 1.06L9.06 8l3.22 3.22a.75.75 0 11-1.06 1.06L8 9.06l-3.22 3.22a.75.75 0 01-1.06-1.06L6.94 8 3.72 4.78a.75.75 0 010-1.06z"})}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-[11px] font-medium text-cc-error",children:"Launch failed"}),r.jsx("p",{className:"text-[10px] text-cc-muted truncate",children:a})]})]})}):r.jsxs("div",{className:"fixed bottom-4 left-4 z-40 w-64 rounded-xl border border-cc-border/60 bg-cc-card/95 backdrop-blur-xl shadow-float animate-slide-up overflow-hidden",style:{transition:"opacity 0.4s ease-out",opacity:j?0:1},children:[r.jsxs("div",{className:"px-3 py-2 border-b border-cc-border/30 flex items-center gap-2",children:[!S&&r.jsxs("svg",{className:"w-3.5 h-3.5 text-cc-primary animate-spin shrink-0",viewBox:"0 0 16 16",fill:"none","aria-hidden":!0,children:[r.jsx("circle",{cx:"8",cy:"8",r:"6",stroke:"currentColor",strokeWidth:"2",opacity:"0.25"}),r.jsx("path",{d:"M14 8a6 6 0 00-6-6",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]}),S&&r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 text-cc-success shrink-0","aria-hidden":!0,children:r.jsx("path",{d:"M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"})}),r.jsx("span",{className:"text-[11px] font-medium text-cc-fg truncate",children:S?"Session ready":"Launching session"}),g&&r.jsx("span",{className:"text-[9px] text-cc-muted font-mono-code truncate ml-auto",children:g})]}),r.jsx("div",{className:"px-3 py-2 space-y-1",children:y.map(k=>r.jsx(UP,{step:k},k.label))}),(n==null?void 0:n.percent)!=null&&r.jsxs("div",{className:"px-3 pb-2",children:[r.jsx("div",{className:"w-full h-1 rounded-full bg-cc-hover overflow-hidden",children:r.jsx("div",{className:"h-full rounded-full bg-cc-primary transition-all duration-300",style:{width:`${Math.min(100,n.percent)}%`}})}),r.jsx("p",{className:"text-[9px] text-cc-muted/60 font-mono-code mt-0.5 truncate",children:n.message})]})]})}function HP(e){return e==="done"?"text-cc-muted/50":e==="active"?"text-cc-fg":"text-cc-muted/40"}function UP({step:e}){return r.jsxs("div",{className:"flex items-center gap-2",children:[e.status==="done"&&r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 text-cc-success shrink-0","aria-hidden":!0,children:r.jsx("path",{d:"M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"})}),e.status==="active"&&r.jsxs("svg",{className:"w-3 h-3 text-cc-primary animate-spin shrink-0",viewBox:"0 0 16 16",fill:"none","aria-hidden":!0,children:[r.jsx("circle",{cx:"8",cy:"8",r:"5",stroke:"currentColor",strokeWidth:"2",opacity:"0.25"}),r.jsx("path",{d:"M13 8a5 5 0 00-5-5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]}),e.status==="pending"&&r.jsx("svg",{className:"w-3 h-3 text-cc-muted/30 shrink-0",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5","aria-hidden":!0,children:r.jsx("circle",{cx:"8",cy:"8",r:"4.5"})}),r.jsx("span",{className:`text-[10px] ${HP(e.status)}`,children:e.label})]})}function Rx(e){if(e<6e4)return`${Math.round(e/1e3)}s`;const t=Math.floor(e/6e4);return t<60?`${t}m`:`${Math.floor(t/60)}h ${t%60}m`}function VP(e){return new Date(e).toLocaleDateString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function WP(e){return e==="playable"?"Playable":e==="metadata"?"Metadata only":"All types"}function qP(e){if(e.compatible)return"Protocol Compatible";const t=e.diffs.length;return`${t} Issue${t>1?"s":""}`}const GP=new Set(["assistant","result","user_message","stream_event","permission_request","permission_cancelled","status_change","session_init","session_update","cli_connected","error","tool_progress","session_name_update"]);function xg(e){return Object.keys(e).some(t=>GP.has(t))}const LC={claude:"text-[#5BA8A0] bg-[#5BA8A0]/10",codex:"text-blue-500 bg-blue-500/10",goose:"text-amber-500 bg-amber-500/10",aider:"text-purple-500 bg-purple-500/10",openhands:"text-rose-500 bg-rose-500/10",openclaw:"text-orange-500 bg-orange-500/10",opencode:"text-teal-500 bg-teal-500/10"};function KP({embedded:e=!1}){const[t,s]=w.useState([]),[n,a]=w.useState(!0),[l,c]=w.useState(!1),[d,f]=w.useState(null),[h,m]=w.useState(null),[g,b]=w.useState(null),[v,y]=w.useState(!1),[S,j]=w.useState(""),[k,E]=w.useState("all"),[N,B]=w.useState("all"),[A,P]=w.useState("newest"),K=w.useCallback(()=>{se.listHubRecordings().then(s).catch(()=>{}).finally(()=>a(!1))},[]);w.useEffect(()=>{K()},[K]);async function X(){c(!0);try{(await se.indexAllRecordings()).imported>0&&K()}catch{}c(!1)}async function Z(R){if(d===R){f(null);return}f(R),m(null),b(null),y(!0);try{const[M,O]=await Promise.all([se.validateRecording(R),se.getRecordingDiagnostics(R)]);m(M),b(O)}catch{}y(!1)}async function I(R){await se.deleteHubRecording(R).catch(()=>{}),K()}const H=w.useCallback(R=>{globalThis.location.hash=`#/replay/${encodeURIComponent(R)}`},[]),F=w.useMemo(()=>[...new Set(t.map(M=>M.backendType))].sort((M,O)=>M.localeCompare(O)),[t]),G=w.useMemo(()=>{const R={all:t.length};for(const M of t)R[M.backendType]=(R[M.backendType]||0)+1;return R},[t]),q=w.useMemo(()=>{let R=t;if(S){const M=S.toLowerCase();R=R.filter(O=>O.filename.toLowerCase().includes(M)||O.backendType.includes(M)||O.tags.some(W=>W.toLowerCase().includes(M)))}return k!=="all"&&(R=R.filter(M=>M.backendType===k)),N==="playable"?R=R.filter(M=>xg(M.messageTypeSummary)):N==="metadata"&&(R=R.filter(M=>!xg(M.messageTypeSummary))),[...R].sort((M,O)=>A==="oldest"?M.startedAt-O.startedAt:A==="longest"?O.duration-M.duration:A==="most-messages"?O.entryCount-M.entryCount:O.startedAt-M.startedAt)},[t,S,k,N,A]);return r.jsxs("div",{className:e?"px-4 py-6 max-w-5xl mx-auto":"p-6 max-w-5xl mx-auto",children:[r.jsxs("div",{className:"flex items-center justify-between mb-5",children:[r.jsxs("div",{children:[r.jsx("h1",{className:"text-lg font-semibold text-cc-fg",children:"Recording Hub"}),r.jsx("p",{className:"text-[12px] text-cc-muted mt-0.5",children:"Browse, validate, and diagnose session recordings"})]}),r.jsx("button",{onClick:X,disabled:l,className:"px-3 py-1.5 rounded-lg bg-cc-primary text-white text-[12px] font-medium hover:bg-cc-primary-hover transition-colors cursor-pointer disabled:opacity-40",children:l?"Indexing...":"Index Recordings"})]}),r.jsx("div",{className:"mb-3",children:r.jsx("input",{value:S,onChange:R=>j(R.target.value),placeholder:"Search by filename, backend, or tag...",className:"w-full h-9 px-3 rounded-lg border border-cc-border bg-cc-input-bg text-[13px] text-cc-fg placeholder:text-cc-muted/30 focus:outline-none focus:ring-2 focus:ring-cc-primary/20"})}),r.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-4",children:[r.jsxs("div",{className:"flex items-center gap-1",children:[r.jsxs("button",{onClick:()=>E("all"),className:`px-2 py-1 rounded-md text-[10px] font-medium transition-colors cursor-pointer ${k==="all"?"bg-cc-primary/10 text-cc-primary":"text-cc-muted hover:text-cc-fg hover:bg-cc-hover"}`,children:["All ",r.jsx("span",{className:"ml-0.5 opacity-60 tabular-nums",children:G.all})]}),F.map(R=>{const M=LC[R]||"text-cc-muted bg-cc-hover";return r.jsxs("button",{onClick:()=>E(k===R?"all":R),className:`px-2 py-1 rounded-md text-[10px] font-medium transition-colors cursor-pointer ${k===R?M:"text-cc-muted hover:text-cc-fg hover:bg-cc-hover"}`,children:[R," ",r.jsx("span",{className:"ml-0.5 opacity-60 tabular-nums",children:G[R]||0})]},R)})]}),r.jsx("div",{className:"w-px h-4 bg-cc-border/50"}),r.jsx("div",{className:"flex items-center gap-1",children:["all","playable","metadata"].map(R=>r.jsx("button",{onClick:()=>B(R),className:`px-2 py-1 rounded-md text-[10px] font-medium transition-colors cursor-pointer ${N===R?"bg-cc-primary/10 text-cc-primary":"text-cc-muted hover:text-cc-fg hover:bg-cc-hover"}`,children:WP(R)},R))}),r.jsx("div",{className:"w-px h-4 bg-cc-border/50"}),r.jsxs("select",{value:A,onChange:R=>P(R.target.value),className:"h-7 px-2 rounded-md border border-cc-border bg-cc-input-bg text-[10px] text-cc-fg cursor-pointer","aria-label":"Sort recordings",children:[r.jsx("option",{value:"newest",children:"Newest first"}),r.jsx("option",{value:"oldest",children:"Oldest first"}),r.jsx("option",{value:"longest",children:"Longest duration"}),r.jsx("option",{value:"most-messages",children:"Most messages"})]}),r.jsxs("span",{className:"text-[10px] text-cc-muted/50 ml-auto tabular-nums",children:[q.length," recording",q.length===1?"":"s"]})]}),n&&r.jsx("p",{className:"text-cc-muted text-sm",children:"Loading..."}),!n&&q.length===0&&r.jsxs("div",{className:"text-center py-12 text-cc-muted",children:[r.jsx("p",{className:"text-sm",children:"No recordings found yet"}),r.jsx("p",{className:"text-xs mt-1",children:'Use "Index Recordings" to refresh the recording index'})]}),r.jsx("div",{className:"space-y-2",children:q.map(R=>r.jsxs("div",{children:[r.jsx(YP,{recording:R,playable:xg(R.messageTypeSummary),isExpanded:d===R.id,onExpand:()=>Z(R.id),onDelete:()=>I(R.id),onReplay:()=>H(R.filename)}),d===R.id&&r.jsx(XP,{recording:R,validation:h,diagnostics:g,loading:v})]},R.id))})]})}function YP({recording:e,playable:t,isExpanded:s,onExpand:n,onDelete:a,onReplay:l}){const c=LC[e.backendType]||"text-cc-muted bg-cc-hover";return r.jsx("div",{className:`border rounded-lg transition-all ${s?"border-cc-primary/30 bg-cc-primary/[0.02]":"border-cc-border bg-cc-card hover:shadow-panel"}`,children:r.jsxs("div",{className:"flex items-center gap-3 px-4 py-3",children:[r.jsx("span",{className:`text-[9px] font-semibold px-2 py-0.5 rounded-full ${c}`,children:e.backendType}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("span",{className:"text-[12px] font-medium text-cc-fg truncate block font-mono-code",children:e.filename}),r.jsxs("div",{className:"flex items-center gap-3 mt-0.5 text-[10px] text-cc-muted",children:[r.jsx("span",{children:VP(e.startedAt)}),r.jsx("span",{className:"tabular-nums",children:Rx(e.duration)}),r.jsxs("span",{className:"tabular-nums",children:[e.entryCount," msgs"]}),!t&&r.jsx("span",{className:"text-cc-muted/40",children:"metadata only"})]})]}),e.tags.length>0&&r.jsx("div",{className:"flex gap-1 shrink-0",children:e.tags.slice(0,3).map(d=>r.jsx("span",{className:"text-[8px] px-1.5 py-0.5 rounded-full bg-cc-hover text-cc-muted",children:d},d))}),r.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[r.jsx("button",{onClick:l,disabled:!t,title:t?"Replay":"No playable messages",className:`p-1.5 rounded-md transition-colors ${t?"hover:bg-cc-hover text-cc-primary cursor-pointer":"text-cc-muted/30 cursor-not-allowed"}`,children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5","aria-hidden":!0,children:r.jsx("path",{d:"M4 2l10 6-10 6V2z"})})}),r.jsx("button",{onClick:n,title:"Details",className:`p-1.5 rounded-md hover:bg-cc-hover cursor-pointer transition-colors ${s?"text-cc-primary":"text-cc-muted"}`,children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5","aria-hidden":!0,children:r.jsx("path",{d:"M8 2a6 6 0 100 12A6 6 0 008 2zm.75 3.5a.75.75 0 00-1.5 0v2.25H5a.75.75 0 000 1.5h2.25V11.5a.75.75 0 001.5 0V9.25H11a.75.75 0 000-1.5H8.75V5.5z"})})}),r.jsx("button",{onClick:a,title:"Remove from hub",className:"p-1.5 rounded-md hover:bg-cc-hover text-cc-muted hover:text-cc-error cursor-pointer transition-colors",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5","aria-hidden":!0,children:r.jsx("path",{d:"M6.5 1.75a.25.25 0 01.25-.25h2.5a.25.25 0 01.25.25V3h-3V1.75zM11 3V1.75A1.75 1.75 0 009.25 0h-2.5A1.75 1.75 0 005 1.75V3H2.75a.75.75 0 000 1.5h.928l.856 10.268A1.75 1.75 0 006.282 16h3.436a1.75 1.75 0 001.748-1.632l.856-10.268h.928a.75.75 0 000-1.5H11z"})})})]})]})})}function XP({recording:e,validation:t,diagnostics:s,loading:n}){return n?r.jsxs("div",{className:"ml-4 my-2 flex items-center gap-2 text-cc-muted text-[11px]",children:[r.jsx("div",{className:"w-3.5 h-3.5 border-2 border-cc-primary border-t-transparent rounded-full animate-spin"}),"Analyzing recording..."]}):r.jsxs("div",{className:"mx-4 mb-3 mt-1 grid grid-cols-1 sm:grid-cols-2 gap-3",children:[t&&r.jsxs("div",{className:`rounded-lg border p-3 ${t.compatible?"border-cc-success/30 bg-cc-success/[0.03]":"border-cc-error/30 bg-cc-error/[0.03]"}`,children:[r.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[t.compatible?r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-4 h-4 text-cc-success","aria-hidden":!0,children:r.jsx("path",{d:"M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"})}):r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-4 h-4 text-cc-error","aria-hidden":!0,children:r.jsx("path",{d:"M3.72 3.72a.75.75 0 011.06 0L8 6.94l3.22-3.22a.75.75 0 111.06 1.06L9.06 8l3.22 3.22a.75.75 0 11-1.06 1.06L8 9.06l-3.22 3.22a.75.75 0 01-1.06-1.06L6.94 8 3.72 4.78a.75.75 0 010-1.06z"})}),r.jsx("span",{className:"text-[12px] font-semibold text-cc-fg",children:qP(t)})]}),r.jsxs("div",{className:"text-[10px] text-cc-muted space-y-0.5",children:[r.jsxs("p",{children:["Checked ",t.checkedMessages," of ",t.totalMessages," messages"]}),r.jsx("div",{className:"flex flex-wrap gap-1 mt-1",children:Object.entries(t.messageTypeBreakdown).slice(0,8).map(([a,l])=>r.jsxs("span",{className:`px-1.5 py-0.5 rounded text-[8px] font-mono-code ${l.issues>0?"bg-cc-error/10 text-cc-error":"bg-cc-hover text-cc-muted"}`,children:[a,": ",l.count]},a))})]})]}),s&&r.jsxs("div",{className:"rounded-lg border border-cc-border p-3",children:[r.jsx("h4",{className:"text-[12px] font-semibold text-cc-fg mb-2",children:"Health Report"}),r.jsxs("div",{className:"grid grid-cols-2 gap-x-4 gap-y-1 text-[10px]",children:[r.jsx("span",{className:"text-cc-muted",children:"Duration"}),r.jsx("span",{className:"text-cc-fg font-mono-code tabular-nums",children:Rx(s.totalDuration)}),r.jsx("span",{className:"text-cc-muted",children:"Messages"}),r.jsx("span",{className:"text-cc-fg font-mono-code tabular-nums",children:s.totalMessages}),r.jsx("span",{className:"text-cc-muted",children:"Msg/min"}),r.jsx("span",{className:"text-cc-fg font-mono-code tabular-nums",children:s.messageRate}),r.jsx("span",{className:"text-cc-muted",children:"Disconnections"}),r.jsx("span",{className:`font-mono-code tabular-nums ${s.disconnections.length>0?"text-cc-error":"text-cc-fg"}`,children:s.disconnections.length}),r.jsx("span",{className:"text-cc-muted",children:"Data Gaps"}),r.jsx("span",{className:`font-mono-code tabular-nums ${s.dataGaps.length>0?"text-cc-warning":"text-cc-fg"}`,children:s.dataGaps.length}),s.avgPermissionResponseMs!==null&&r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"text-cc-muted",children:"Avg Perm Response"}),r.jsx("span",{className:"text-cc-fg font-mono-code tabular-nums",children:Rx(s.avgPermissionResponseMs)})]})]}),r.jsx("div",{className:"mt-2 space-y-0.5",children:s.patterns.map(a=>r.jsx("p",{className:`text-[9px] ${a.includes("No anomalies")?"text-cc-success":"text-cc-warning"}`,children:a},a))})]})]})}function JP(e){const t=Math.floor(e/1e3);if(t<60)return`${t}s`;const s=Math.floor(t/60);return s<60?`${s}m ${t%60}s`:`${Math.floor(s/60)}h ${s%60}m`}function o2(e){return new Date(e).toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit",second:"2-digit"})}const l2={claude:"text-[#5BA8A0]",codex:"text-blue-500",goose:"text-amber-500",aider:"text-purple-500",openhands:"text-rose-500",openclaw:"text-orange-500",opencode:"text-teal-500"};function QP({embedded:e=!1}){const[t,s]=w.useState(null),[n,a]=w.useState(!0),l=Y(d=>d.sessionNames),c=w.useCallback(()=>{se.getMonitorStats().then(s).catch(()=>{}).finally(()=>a(!1))},[]);return w.useEffect(()=>{c();const d=setInterval(c,3e3);return()=>clearInterval(d)},[c]),n?r.jsx("div",{className:"flex items-center justify-center h-64 text-cc-muted text-sm",children:"Loading monitor..."}):t?r.jsxs("div",{className:e?"px-4 py-6 max-w-5xl mx-auto":"p-6 max-w-5xl mx-auto",children:[r.jsxs("div",{className:"flex items-center justify-between mb-5",children:[r.jsxs("div",{children:[r.jsx("h1",{className:"text-lg font-semibold text-cc-fg",children:"Protocol Monitor"}),r.jsx("p",{className:"text-[12px] text-cc-muted mt-0.5",children:"Real-time WebSocket message flow and health metrics"})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"w-2 h-2 rounded-full bg-cc-success animate-breathing"}),r.jsxs("span",{className:"text-[11px] text-cc-muted font-mono-code",children:["Live · ",JP(t.uptime)]})]})]}),r.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3 mb-5",children:[r.jsx(Gd,{label:"Total Messages",value:t.totalMessages.toLocaleString()}),r.jsx(Gd,{label:"Messages/min",value:String(t.globalMessagesPerMinute),accent:t.globalMessagesPerMinute>0}),r.jsx(Gd,{label:"Active Sessions",value:String(t.activeSessions)}),r.jsx(Gd,{label:"Errors",value:String(t.totalErrors),error:t.totalErrors>0})]}),Object.keys(t.backendBreakdown).length>0&&r.jsxs("div",{className:"mb-5",children:[r.jsx("h2",{className:"text-[12px] font-semibold text-cc-fg mb-2",children:"Backend Breakdown"}),r.jsx("div",{className:"flex flex-wrap gap-2",children:Object.entries(t.backendBreakdown).map(([d,f])=>r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg border border-cc-border bg-cc-card",children:[r.jsx("span",{className:`text-[12px] font-semibold ${l2[d]||"text-cc-muted"}`,children:d}),r.jsxs("span",{className:"text-[11px] text-cc-fg font-mono-code tabular-nums",children:[f.messages," msgs"]}),f.errors>0&&r.jsxs("span",{className:"text-[10px] text-cc-error font-mono-code tabular-nums",children:[f.errors," err"]})]},d))})]}),Object.keys(t.messageTypeGlobal).length>0&&r.jsxs("div",{className:"mb-5",children:[r.jsx("h2",{className:"text-[12px] font-semibold text-cc-fg mb-2",children:"Message Types (5min window)"}),r.jsx("div",{className:"flex flex-wrap gap-1",children:Object.entries(t.messageTypeGlobal).sort(([,d],[,f])=>f-d).slice(0,20).map(([d,f])=>r.jsxs("span",{className:"text-[9px] font-mono-code px-1.5 py-0.5 rounded bg-cc-hover text-cc-muted",children:[d,": ",r.jsx("span",{className:"text-cc-fg tabular-nums",children:f})]},d))})]}),t.sessionStats.length>0&&r.jsxs("div",{className:"mb-5",children:[r.jsx("h2",{className:"text-[12px] font-semibold text-cc-fg mb-2",children:"Active Sessions"}),r.jsx("div",{className:"space-y-1.5",children:t.sessionStats.map(d=>{const f=l.get(d.sessionId)||d.sessionId.slice(0,8);return r.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 rounded-lg border border-cc-border bg-cc-card",children:[r.jsx("span",{className:`text-[10px] font-semibold px-1.5 py-0.5 rounded-full ${l2[d.backendType]||"text-cc-muted"} bg-current/10`,children:d.backendType}),r.jsx("span",{className:"text-[12px] font-medium text-cc-fg truncate flex-1",children:f}),r.jsxs("span",{className:"text-[10px] text-cc-muted font-mono-code tabular-nums",children:[d.messageCount," msgs"]}),r.jsxs("span",{className:"text-[10px] text-cc-muted font-mono-code tabular-nums",children:[d.messagesPerMinute,"/min"]}),d.errorCount>0&&r.jsxs("span",{className:"text-[10px] text-cc-error font-mono-code tabular-nums",children:[d.errorCount," err"]}),r.jsx("span",{className:"text-[10px] text-cc-muted/50 font-mono-code",children:o2(d.lastMessageAt)})]},d.sessionId)})})]}),t.recentDrifts.length>0&&r.jsxs("div",{children:[r.jsx("h2",{className:"text-[12px] font-semibold text-cc-error mb-2",children:"Protocol Drift Alerts"}),r.jsx("div",{className:"space-y-1",children:t.recentDrifts.map(d=>r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg border border-cc-error/20 bg-cc-error/[0.03]",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 text-cc-error shrink-0","aria-hidden":!0,children:r.jsx("path",{d:"M8.22 1.754a.25.25 0 00-.44 0L1.698 13.132a.25.25 0 00.22.368h12.164a.25.25 0 00.22-.368L8.22 1.754z"})}),r.jsx("span",{className:"text-[11px] font-medium text-cc-fg",children:d.backendType}),r.jsxs("span",{className:"text-[10px] text-cc-muted font-mono-code",children:[d.direction," ",d.messageType]}),r.jsx("span",{className:"text-[10px] text-cc-error/70 flex-1 truncate",children:d.details}),r.jsx("span",{className:"text-[9px] text-cc-muted/50 font-mono-code",children:o2(d.timestamp)})]},`${d.backendType}-${d.messageType}-${d.timestamp}`))})]}),t.activeSessions===0&&t.totalMessages===0&&r.jsxs("div",{className:"text-center py-12 text-cc-muted",children:[r.jsx("p",{className:"text-sm",children:"No activity yet"}),r.jsx("p",{className:"text-xs mt-1",children:"Start a session to see real-time protocol metrics"})]})]}):r.jsx("div",{className:"flex items-center justify-center h-64 text-cc-muted text-sm",children:"Monitor not available"})}function ZP(e,t){return e?"text-cc-error":t?"text-cc-primary":"text-cc-fg"}function Gd({label:e,value:t,accent:s=!1,error:n=!1}){return r.jsxs("div",{className:"rounded-xl border border-cc-border bg-cc-card px-4 py-3",children:[r.jsx("p",{className:"text-[10px] text-cc-muted uppercase tracking-wider mb-1",children:e}),r.jsx("p",{className:`text-xl font-bold font-mono-code tabular-nums ${ZP(n,s)}`,children:t})]})}const e9={help:"Show available commands and keyboard shortcuts",clear:"Clear conversation history and start fresh",compact:"Compact conversation to save context window space",cost:"Show token usage and cost for this session",doctor:"Check health of Claude Code installation",init:"Initialize a new CLAUDE.md project file",login:"Switch accounts or re-authenticate",logout:"Sign out of current account",memory:"View and edit CLAUDE.md memory files",model:"Switch the AI model for this session",permissions:"View and manage tool permissions",review:"Review recent changes made by Claude",status:"Show session status, model, and connection info","terminal-setup":"Configure terminal integration (Shift+Enter)",vim:"Toggle vim keybindings mode"};function t9({embedded:e=!1}){var F,G;const[t,s]=w.useState([]),[n,a]=w.useState([]),[l,c]=w.useState(!0),[d,f]=w.useState(""),[h,m]=w.useState(null),[g,b]=w.useState(""),[v,y]=w.useState(!1),S=Y(q=>q.currentSessionId),j=Y(q=>q.sessions),k=Y(q=>q.sdkSessions),E=S?((F=j.get(S))==null?void 0:F.cwd)||((G=k.find(q=>q.sessionId===S))==null?void 0:G.cwd):void 0,N=w.useCallback(()=>{se.discoverCommands(E).then(q=>{s(q.commands),a(q.skills)}).catch(()=>{}).finally(()=>c(!1))},[E]);w.useEffect(()=>{N()},[N]);async function B(q){if(h===q){m(null);return}m(q),y(!0);try{const R=await se.readCommand(q);b(R.content)}catch{b("Failed to read file")}y(!1)}const A=d.toLowerCase(),P=A?t.filter(q=>q.name.includes(A)||q.description.toLowerCase().includes(A)):t,K=A?n.filter(q=>q.slug.includes(A)||q.name.toLowerCase().includes(A)||q.description.toLowerCase().includes(A)):n,[X,Z]=w.useState([]);w.useEffect(()=>{se.getSlashCommands().then(q=>{Z(q.commands.map(R=>({name:R,description:e9[R]||""})))}).catch(()=>{})},[]);const I=A?X.filter(q=>q.name.includes(A)||q.description.toLowerCase().includes(A)):X,H=P.length+K.length+I.length;return r.jsxs("div",{className:e?"px-4 py-6 max-w-4xl mx-auto":"p-6 max-w-4xl mx-auto",children:[r.jsxs("div",{className:"flex items-center justify-between mb-5",children:[r.jsxs("div",{children:[r.jsx("h1",{className:"text-lg font-semibold text-cc-fg",children:"Commands & Skills"}),r.jsxs("p",{className:"text-[12px] text-cc-muted mt-0.5",children:["Slash commands from ",r.jsx("code",{className:"font-mono-code text-[10px] bg-cc-hover px-1 rounded",children:"~/.claude/commands/"})," and skills from ",r.jsx("code",{className:"font-mono-code text-[10px] bg-cc-hover px-1 rounded",children:"~/.claude/skills/"})]})]}),r.jsx("button",{onClick:N,className:"px-3 py-1.5 rounded-lg text-[12px] text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:"Refresh"})]}),r.jsx("div",{className:"mb-4",children:r.jsx("input",{value:d,onChange:q=>f(q.target.value),placeholder:"Search commands and skills...",className:"w-full h-9 px-3 rounded-lg border border-cc-border bg-cc-input-bg text-[13px] text-cc-fg placeholder:text-cc-muted/30 focus:outline-none focus:ring-2 focus:ring-cc-primary/20"})}),l&&r.jsx("p",{className:"text-cc-muted text-sm",children:"Discovering commands..."}),!l&&H===0&&r.jsxs("div",{className:"text-center py-12 text-cc-muted",children:[r.jsx("p",{className:"text-sm",children:"No commands or skills found"}),r.jsxs("p",{className:"text-xs mt-1",children:["Create ",r.jsx("code",{className:"font-mono-code bg-cc-hover px-1 rounded",children:"~/.claude/commands/my-command.md"})," to add a slash command"]})]}),I.length>0&&r.jsxs("div",{className:"mb-6",children:[r.jsxs("h2",{className:"text-[11px] font-semibold text-cc-muted uppercase tracking-wider mb-2",children:["Built-in Commands ",r.jsx("span",{className:"text-cc-muted/50 tabular-nums ml-1",children:I.length})]}),r.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-1.5",children:I.map(q=>r.jsxs("div",{className:"flex items-center gap-3 px-4 py-2.5 rounded-lg border border-cc-border bg-cc-card",children:[r.jsx("span",{className:"w-7 h-7 rounded-md bg-cc-muted/10 text-cc-muted flex items-center justify-center text-[13px] font-bold shrink-0",children:"/"}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("span",{className:"text-[12px] font-medium text-cc-fg font-mono-code",children:["/",q.name]}),r.jsx("p",{className:"text-[10px] text-cc-muted truncate",children:q.description})]})]},q.name))})]}),P.length>0&&r.jsxs("div",{className:"mb-6",children:[r.jsxs("h2",{className:"text-[11px] font-semibold text-cc-muted uppercase tracking-wider mb-2",children:["Custom Commands ",r.jsx("span",{className:"text-cc-muted/50 tabular-nums ml-1",children:P.length})]}),r.jsx("div",{className:"space-y-1.5",children:P.map(q=>r.jsxs("div",{children:[r.jsxs("button",{onClick:()=>B(q.path),className:`w-full flex items-center gap-3 px-4 py-2.5 rounded-lg border text-left transition-all cursor-pointer ${h===q.path?"border-cc-primary/30 bg-cc-primary/[0.03]":"border-cc-border bg-cc-card hover:shadow-panel"}`,children:[r.jsx("span",{className:"w-7 h-7 rounded-md bg-cc-primary/10 text-cc-primary flex items-center justify-center text-[13px] font-bold shrink-0",children:"/"}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("span",{className:"text-[13px] font-medium text-cc-fg font-mono-code",children:["/",q.name]}),r.jsx("span",{className:`text-[8px] font-semibold px-1.5 rounded-full ${q.source==="project"?"text-amber-500 bg-amber-500/10":"text-cc-muted bg-cc-hover"}`,children:q.source})]}),q.description&&r.jsx("p",{className:"text-[11px] text-cc-muted truncate mt-0.5",children:q.description})]}),r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:`w-3 h-3 text-cc-muted/40 transition-transform duration-150 shrink-0 ${h===q.path?"rotate-90":""}`,"aria-hidden":!0,children:r.jsx("path",{d:"M6 4l4 4-4 4V4z"})})]}),h===q.path&&r.jsx("div",{className:"ml-10 mt-1 mb-2",children:v?r.jsx("p",{className:"text-[11px] text-cc-muted py-2",children:"Loading..."}):r.jsx("pre",{className:"text-[11px] text-cc-code-fg bg-cc-code-bg rounded-lg p-3 overflow-x-auto max-h-64 overflow-y-auto font-mono-code leading-relaxed",children:g})})]},q.path))})]}),K.length>0&&r.jsxs("div",{children:[r.jsxs("h2",{className:"text-[11px] font-semibold text-cc-muted uppercase tracking-wider mb-2",children:["Skills ",r.jsx("span",{className:"text-cc-muted/50 tabular-nums ml-1",children:K.length})]}),r.jsx("div",{className:"space-y-1.5",children:K.map(q=>r.jsxs("div",{children:[r.jsxs("button",{onClick:()=>B(q.path),className:`w-full flex items-center gap-3 px-4 py-2.5 rounded-lg border text-left transition-all cursor-pointer ${h===q.path?"border-cc-primary/30 bg-cc-primary/[0.03]":"border-cc-border bg-cc-card hover:shadow-panel"}`,children:[r.jsx("span",{className:"w-7 h-7 rounded-md bg-cc-success/10 text-cc-success flex items-center justify-center shrink-0",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5","aria-hidden":!0,children:r.jsx("path",{d:"M8.22 1.754a.25.25 0 00-.44 0L1.698 13.132a.25.25 0 00.22.368h12.164a.25.25 0 00.22-.368L8.22 1.754z"})})}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("span",{className:"text-[13px] font-medium text-cc-fg",children:q.name}),q.description&&r.jsx("p",{className:"text-[11px] text-cc-muted truncate mt-0.5",children:q.description})]}),r.jsx("span",{className:"text-[9px] font-mono-code text-cc-muted/40 shrink-0",children:q.slug}),r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:`w-3 h-3 text-cc-muted/40 transition-transform duration-150 shrink-0 ${h===q.path?"rotate-90":""}`,"aria-hidden":!0,children:r.jsx("path",{d:"M6 4l4 4-4 4V4z"})})]}),h===q.path&&r.jsx("div",{className:"ml-10 mt-1 mb-2",children:v?r.jsx("p",{className:"text-[11px] text-cc-muted py-2",children:"Loading..."}):r.jsx("pre",{className:"text-[11px] text-cc-code-fg bg-cc-code-bg rounded-lg p-3 overflow-x-auto max-h-64 overflow-y-auto font-mono-code leading-relaxed",children:g})})]},q.path))})]})]})}const s9=["welcome","providers","workspace","tour","launch"];function n9(e){return s9.indexOf(e)}function r9(e,t){return e?"bg-cc-primary text-white":t?"bg-cc-primary/15 text-cc-primary ring-2 ring-cc-primary/30":"bg-cc-hover text-cc-muted/50"}function i9(e){return e==="subscription"?"Logged in":e==="oauth-token"?"Token set":e==="api-key"?"API key set":""}function a9({onComplete:e}){const[t,s]=w.useState("welcome"),[n,a]=w.useState(null),[l,c]=w.useState(""),[d,f]=w.useState(""),[h,m]=w.useState(""),[g,b]=w.useState(!1),[v,y]=w.useState(""),S=w.useRef(null),j=n9(t);w.useEffect(()=>{var B;(B=S.current)==null||B.focus()},[t]),w.useEffect(()=>{se.getProviderAuthStatus().then(a).catch(()=>{})},[t]);const k=w.useCallback(async()=>{try{await se.updateSettings({onboardingCompleted:!0})}catch{}e()},[e]);async function E(){b(!0),y("");try{const B={};l.trim()&&(B.claudeOAuthToken=l.trim()),d.trim()&&(B.openaiApiKey=d.trim()),Object.keys(B).length>0&&await se.updateSettings(B),s("workspace")}catch(B){y(B instanceof Error?B.message:"Failed to save")}finally{b(!1)}}function N(){se.getProviderAuthStatus().then(a).catch(()=>{})}return r.jsx("dialog",{ref:S,open:!0,"aria-label":"Campfire setup wizard",className:"fixed inset-0 z-50 flex items-center justify-center w-full h-full m-0 p-0 bg-black/50 backdrop-blur-md border-none outline-none",children:r.jsxs("div",{className:"w-full max-w-[520px] mx-5 bg-cc-card rounded-2xl shadow-float border border-cc-border/60 overflow-hidden animate-slide-up",children:[r.jsx(o9,{current:j,total:4}),r.jsxs("div",{className:"px-7 pb-7 pt-5",children:[t==="welcome"&&r.jsx(l9,{onNext:()=>s("providers"),onSkip:k}),t==="providers"&&r.jsx(c9,{authStatus:n,claudeToken:l,openaiKey:d,onClaudeTokenChange:c,onOpenaiKeyChange:f,saving:g,error:v,onSave:E,onSkip:()=>s("workspace"),onRefreshAuth:N}),t==="workspace"&&r.jsx(u9,{cwd:h,onCwdChange:m,onNext:()=>s("tour"),onSkip:()=>s("tour")}),t==="tour"&&r.jsx(h9,{onNext:()=>s("launch")}),t==="launch"&&r.jsx(f9,{cwd:h,onComplete:k})]})]})})}const c2=["Welcome","Providers","Workspace","Features"];function o9({current:e,total:t}){return e>=t?null:r.jsxs("output",{className:"block px-7 pt-6 pb-1","aria-label":`Step ${e+1} of ${t}: ${c2[e]}`,children:[r.jsx("div",{className:"flex items-center gap-1.5",children:Array.from({length:t},(s,n)=>{const a=n<e,l=n===e;return r.jsxs("div",{className:"flex items-center gap-1.5 flex-1",children:[r.jsx("div",{className:`w-6 h-6 rounded-full flex items-center justify-center text-[10px] font-semibold shrink-0 transition-all duration-300 ${r9(a,l)}`,children:a?r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3","aria-hidden":!0,children:r.jsx("path",{d:"M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"})}):n+1}),n<t-1&&r.jsx("div",{className:`flex-1 h-[2px] rounded-full transition-colors duration-300 ${n<e?"bg-cc-primary":"bg-cc-border"}`})]},n)})}),r.jsx("p",{className:"text-[10px] text-cc-muted mt-2 font-medium",children:c2[e]})]})}function l9({onNext:e,onSkip:t}){return r.jsxs("div",{className:"text-center",children:[r.jsx("div",{className:"w-16 h-16 mx-auto mb-5 rounded-2xl bg-gradient-to-br from-cc-primary/20 to-cc-primary/5 flex items-center justify-center border border-cc-primary/10",children:r.jsx("span",{className:"text-3xl",role:"img","aria-label":"Campfire",children:"🔥"})}),r.jsx("h1",{className:"text-[22px] font-bold text-cc-fg tracking-tight",children:"Welcome to Campfire"}),r.jsx("p",{className:"text-[14px] text-cc-muted mt-2 leading-relaxed max-w-[380px] mx-auto",children:"A unified web interface for AI coding agents. Run Claude, Codex, Goose, Aider and more from your browser."}),r.jsxs("div",{className:"mt-8 space-y-3",children:[r.jsx("button",{onClick:e,autoFocus:!0,className:"w-full h-11 rounded-xl bg-cc-primary text-white text-[14px] font-semibold hover:bg-cc-primary-hover active:scale-[0.98] transition-all cursor-pointer shadow-sm",children:"Get Started"}),r.jsx("button",{onClick:t,className:"w-full text-[12px] text-cc-muted/60 hover:text-cc-muted transition-colors cursor-pointer py-1",children:"Skip setup — I'll configure later in Settings"})]})]})}function c9({authStatus:e,claudeToken:t,openaiKey:s,onClaudeTokenChange:n,onOpenaiKeyChange:a,saving:l,error:c,onSave:d,onSkip:f,onRefreshAuth:h}){return r.jsxs("div",{children:[r.jsx("h2",{className:"text-[18px] font-bold text-cc-fg tracking-tight",children:"Connect Providers"}),r.jsx("p",{className:"text-[13px] text-cc-muted mt-1 mb-5",children:"Set up one or both. You can add more anytime in Settings."}),c&&r.jsxs("div",{className:"mb-4 flex items-center gap-2 px-3 py-2.5 rounded-xl bg-cc-error/8 border border-cc-error/15",role:"alert",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-4 h-4 text-cc-error shrink-0","aria-hidden":!0,children:r.jsx("path",{d:"M3.72 3.72a.75.75 0 011.06 0L8 6.94l3.22-3.22a.75.75 0 111.06 1.06L9.06 8l3.22 3.22a.75.75 0 11-1.06 1.06L8 9.06l-3.22 3.22a.75.75 0 01-1.06-1.06L6.94 8 3.72 4.78a.75.75 0 010-1.06z"})}),r.jsx("p",{className:"text-[12px] text-cc-error",children:c})]}),r.jsxs("div",{className:"space-y-3",children:[r.jsx(u2,{name:"Claude Code",description:"Anthropic's coding agent",accentColor:"bg-[#5BA8A0]",authenticated:(e==null?void 0:e.claude.authenticated)??!1,method:(e==null?void 0:e.claude.method)??null,loginCommand:"claude auth login",loginHint:"Signs in with your Claude Pro, Max, or Team subscription",tokenLabel:"OAuth token or API key",tokenPlaceholder:"sk-ant-... or paste from claude setup-token",tokenValue:t,onTokenChange:n,onRefresh:h}),r.jsx(u2,{name:"Codex",description:"OpenAI's coding agent",accentColor:"bg-blue-500",authenticated:(e==null?void 0:e.codex.authenticated)??!1,method:(e==null?void 0:e.codex.method)??null,loginCommand:"codex login",loginHint:"Signs in with your ChatGPT Plus or Pro subscription",tokenLabel:"OpenAI API key",tokenPlaceholder:"sk-...",tokenValue:s,onTokenChange:a,onRefresh:h})]}),r.jsxs("div",{className:"flex items-center gap-3 mt-6",children:[r.jsx("button",{onClick:d,disabled:l,className:"flex-1 h-11 rounded-xl bg-cc-primary text-white text-[14px] font-semibold hover:bg-cc-primary-hover active:scale-[0.98] transition-all cursor-pointer disabled:opacity-40 shadow-sm",children:l?"Saving...":"Continue"}),r.jsx("button",{onClick:f,className:"h-11 px-5 rounded-xl text-[13px] font-medium text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:"Skip"})]})]})}function u2({name:e,description:t,accentColor:s,authenticated:n,method:a,loginCommand:l,loginHint:c,tokenLabel:d,tokenPlaceholder:f,tokenValue:h,onTokenChange:m,onRefresh:g}){const[b,v]=w.useState(!1),[y,S]=w.useState(!1);function j(){navigator.clipboard.writeText(l).catch(()=>{}),S(!0),setTimeout(()=>S(!1),1500)}return r.jsxs("div",{className:`rounded-xl border transition-colors ${n?"border-cc-success/30 bg-cc-success/[0.03]":"border-cc-border hover:border-cc-border/80"}`,children:[r.jsxs("div",{className:"flex items-center gap-3 px-4 py-3",children:[r.jsx("div",{className:`w-8 h-8 rounded-lg ${s} flex items-center justify-center`,children:r.jsx("span",{className:"text-white text-sm font-bold",children:e.charAt(0)})}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("h3",{className:"text-[13px] font-semibold text-cc-fg",children:e}),r.jsx("p",{className:"text-[11px] text-cc-muted",children:t})]}),n&&r.jsxs("span",{className:"flex items-center gap-1.5 text-[11px] font-medium text-cc-success bg-cc-success/10 px-2.5 py-1 rounded-full",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3","aria-hidden":!0,children:r.jsx("path",{d:"M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"})}),i9(a)]})]}),!n&&r.jsxs("div",{className:"px-4 pb-4 space-y-3",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-[11px] text-cc-muted mb-1.5",children:"Run in your terminal:"}),r.jsxs("div",{className:"flex items-center bg-cc-code-bg rounded-lg border border-cc-border/30 overflow-hidden",children:[r.jsxs("div",{className:"flex-1 flex items-center gap-2 px-3 py-2.5 min-w-0",children:[r.jsx("span",{className:"text-cc-code-fg/40 text-[12px] font-mono-code select-none","aria-hidden":!0,children:"$"}),r.jsx("code",{className:"text-[12px] font-mono-code text-cc-code-fg truncate",children:l})]}),r.jsx("button",{onClick:j,className:"px-3 py-2.5 text-[10px] font-medium text-cc-code-fg/50 hover:text-cc-code-fg/80 hover:bg-white/5 transition-colors cursor-pointer border-l border-cc-border/20","aria-label":`Copy command: ${l}`,children:y?"Copied!":"Copy"})]}),r.jsx("p",{className:"text-[10px] text-cc-muted/70 mt-1.5",children:c})]}),r.jsxs("button",{onClick:g,className:"flex items-center gap-1.5 text-[11px] font-medium text-cc-primary hover:text-cc-primary-hover transition-colors cursor-pointer",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3","aria-hidden":!0,children:r.jsx("path",{d:"M1.705 8.005a.75.75 0 01.834.656 5.5 5.5 0 009.592 2.97l-1.204-1.204a.25.25 0 01.177-.427h3.646a.25.25 0 01.25.25v3.646a.25.25 0 01-.427.177l-1.38-1.38A7.002 7.002 0 011.05 8.84a.75.75 0 01.656-.834zM8 2.5a5.487 5.487 0 00-4.131 1.869l1.204 1.204A.25.25 0 014.896 6H1.25A.25.25 0 011 5.75V2.104a.25.25 0 01.427-.177l1.38 1.38A7.002 7.002 0 0114.95 7.16a.75.75 0 11-1.49.178A5.5 5.5 0 008 2.5z"})}),"I've logged in — check again"]}),r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("div",{className:"flex-1 h-px bg-cc-border/50"}),r.jsx("button",{onClick:()=>v(k=>!k),className:"text-[10px] text-cc-muted/50 hover:text-cc-muted transition-colors cursor-pointer shrink-0",children:b?"Hide API key":"Or use an API key"}),r.jsx("div",{className:"flex-1 h-px bg-cc-border/50"})]}),b&&r.jsxs("div",{children:[r.jsx("label",{htmlFor:`key-${e}`,className:"text-[11px] font-medium text-cc-muted block mb-1",children:d}),r.jsx("input",{id:`key-${e}`,type:"password",value:h,onChange:k=>m(k.target.value),placeholder:f,className:"w-full h-9 px-3 rounded-lg border border-cc-border bg-cc-input-bg text-[12px] text-cc-fg font-mono-code placeholder:text-cc-muted/30 focus:outline-none focus:ring-2 focus:ring-cc-primary/20 focus:border-cc-primary/40 transition-all"})]})]})]})}function u9({cwd:e,onCwdChange:t,onNext:s,onSkip:n}){return r.jsxs("div",{children:[r.jsx("h2",{className:"text-[18px] font-bold text-cc-fg tracking-tight",children:"Your Workspace"}),r.jsx("p",{className:"text-[13px] text-cc-muted mt-1 mb-5",children:"Set a default working directory for new sessions. You can always change this per session."}),r.jsxs("div",{className:"mb-6",children:[r.jsx("label",{htmlFor:"onboarding-cwd",className:"text-[12px] font-medium text-cc-fg block mb-2",children:"Project directory"}),r.jsxs("div",{className:"relative",children:[r.jsx("div",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-cc-muted/40","aria-hidden":!0,children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-4 h-4",children:r.jsx("path",{d:"M1.75 1A1.75 1.75 0 000 2.75v10.5C0 14.216.784 15 1.75 15h12.5A1.75 1.75 0 0016 13.25v-8.5A1.75 1.75 0 0014.25 3H7.5a.25.25 0 01-.2-.1l-.9-1.2C6.07 1.26 5.55 1 5 1H1.75z"})})}),r.jsx("input",{id:"onboarding-cwd",value:e,onChange:a=>t(a.target.value),placeholder:"/home/user/my-project",autoFocus:!0,className:"w-full h-11 pl-10 pr-3 rounded-xl border border-cc-border bg-cc-input-bg text-[13px] text-cc-fg font-mono-code placeholder:text-cc-muted/30 focus:outline-none focus:ring-2 focus:ring-cc-primary/20 focus:border-cc-primary/40 transition-all"})]}),r.jsxs("p",{className:"text-[11px] text-cc-muted/60 mt-2",children:["Use the absolute path to your project root, e.g. ",r.jsx("code",{className:"font-mono-code bg-cc-hover px-1 rounded text-[10px]",children:"~/projects/my-app"})]})]}),r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("button",{onClick:s,className:"flex-1 h-11 rounded-xl bg-cc-primary text-white text-[14px] font-semibold hover:bg-cc-primary-hover active:scale-[0.98] transition-all cursor-pointer shadow-sm",children:"Continue"}),r.jsx("button",{onClick:n,className:"h-11 px-5 rounded-xl text-[13px] font-medium text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:"Skip"})]})]})}const d9=[{icon:r.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"w-5 h-5",children:r.jsx("path",{d:"M20 12V8H6a2 2 0 01-2-2c0-1.1.9-2 2-2h12v4M20 12v4H6a2 2 0 00-2 2c0 1.1.9 2 2 2h12v-4M20 12H9",strokeLinecap:"round",strokeLinejoin:"round"})}),title:"Multi-Session",desc:"Run multiple agents in parallel across different projects and backends",color:"text-cc-primary bg-cc-primary/10"},{icon:r.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"w-5 h-5",children:r.jsx("path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z",strokeLinecap:"round",strokeLinejoin:"round"})}),title:"Permission Control",desc:"Approve or deny tool calls before they execute — full visibility and safety",color:"text-cc-success bg-cc-success/10"},{icon:r.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"w-5 h-5",children:r.jsx("path",{d:"M12 8V4H8M2 12h4M20 12h2M12 20v-4M4.93 4.93l2.83 2.83M16.24 16.24l2.83 2.83M4.93 19.07l2.83-2.83M16.24 7.76l2.83-2.83",strokeLinecap:"round"})}),title:"Agent Profiles",desc:"Create persistent agents with custom prompts, webhooks, and cron schedules",color:"text-amber-500 bg-amber-500/10"},{icon:r.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"w-5 h-5",children:r.jsx("path",{d:"M17 21v-2a4 4 0 00-4-4H5a4 4 0 00-4 4v2M9 11a4 4 0 100-8 4 4 0 000 8zM23 21v-2a4 4 0 00-3-3.87M16 3.13a4 4 0 010 7.75",strokeLinecap:"round",strokeLinejoin:"round"})}),title:"Collaboration",desc:"Share sessions with teammates and vote on permissions together",color:"text-purple-500 bg-purple-500/10"}];function h9({onNext:e}){return r.jsxs("div",{children:[r.jsx("h2",{className:"text-[18px] font-bold text-cc-fg tracking-tight",children:"What you can do"}),r.jsx("p",{className:"text-[13px] text-cc-muted mt-1 mb-5",children:"A quick look at Campfire's key capabilities."}),r.jsx("div",{className:"grid grid-cols-2 gap-3 mb-6",children:d9.map(t=>r.jsxs("div",{className:"rounded-xl border border-cc-border/50 p-4 hover:border-cc-border transition-colors",children:[r.jsx("div",{className:`w-9 h-9 rounded-lg ${t.color} flex items-center justify-center mb-3`,children:t.icon}),r.jsx("h3",{className:"text-[13px] font-semibold text-cc-fg",children:t.title}),r.jsx("p",{className:"text-[11px] text-cc-muted leading-relaxed mt-1",children:t.desc})]},t.title))}),r.jsx("button",{onClick:e,autoFocus:!0,className:"w-full h-11 rounded-xl bg-cc-primary text-white text-[14px] font-semibold hover:bg-cc-primary-hover active:scale-[0.98] transition-all cursor-pointer shadow-sm",children:"Let's Go"})]})}function f9({cwd:e,onComplete:t}){return r.jsxs("div",{className:"text-center py-4",children:[r.jsx("div",{className:"w-16 h-16 mx-auto mb-5 rounded-full bg-cc-success/10 flex items-center justify-center",children:r.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"w-8 h-8 text-cc-success","aria-hidden":!0,children:r.jsx("path",{d:"M20 6L9 17l-5-5",strokeLinecap:"round",strokeLinejoin:"round"})})}),r.jsx("h2",{className:"text-[22px] font-bold text-cc-fg tracking-tight",children:"You're all set!"}),r.jsx("p",{className:"text-[14px] text-cc-muted mt-2 max-w-[360px] mx-auto leading-relaxed",children:e?r.jsxs(r.Fragment,{children:["Your workspace is set to ",r.jsx("code",{className:"font-mono-code text-[12px] bg-cc-hover px-1.5 py-0.5 rounded",children:e})]}):"Start your first session from the home page"}),r.jsx("p",{className:"text-[12px] text-cc-muted/50 mt-2",children:"Providers and settings can be updated anytime."}),r.jsx("button",{onClick:t,autoFocus:!0,className:"w-full h-11 mt-8 rounded-xl bg-cc-primary text-white text-[14px] font-semibold hover:bg-cc-primary-hover active:scale-[0.98] transition-all cursor-pointer shadow-sm",children:"Open Campfire"})]})}const p9={installing:"Installing update...",restarting:"Restarting server...",waiting:"Waiting for server...",ready:"Update complete."};function m9(){const e=qh();return e?{Authorization:`Bearer ${e}`}:{}}function g9(e){const[t,s]=w.useState("installing"),n=w.useRef(null),a=w.useRef(!0);return w.useEffect(()=>(a.current=!0,()=>{a.current=!1,n.current&&clearTimeout(n.current)}),[]),w.useEffect(()=>{if(!e){s("installing");return}const l=setTimeout(()=>{a.current&&s("restarting")},3e3),c=setTimeout(()=>{a.current&&s("waiting"),d()},5e3);function d(){a.current&&fetch("/api/update-check",{headers:m9(),signal:AbortSignal.timeout(3e3)}).then(f=>{if(!f.ok)throw new Error("Server is not ready");return f.json()}).then(f=>{if(f.updateInProgress)throw new Error("Update is still running");a.current&&(s("ready"),setTimeout(()=>{a.current&&window.location.reload()},800))}).catch(()=>{n.current=setTimeout(d,1500)})}return()=>{clearTimeout(l),clearTimeout(c),n.current&&clearTimeout(n.current)}},[e]),t}function x9({active:e}){const t=g9(e);if(!e)return null;const s=t==="ready";return r.jsxs("div",{className:"fixed inset-0 z-[100] flex flex-col items-center justify-center bg-cc-bg text-cc-fg animate-[fadeSlideIn_0.15s_ease-out]",role:"status","aria-live":"polite","data-testid":"update-overlay",children:[r.jsxs("div",{className:"relative mb-7",children:[!s&&r.jsx("div",{className:"absolute inset-0 -m-4 rounded-full bg-cc-primary/10 animate-pulse"}),r.jsx("img",{src:"/logo.svg",alt:"Campfire",className:`relative z-10 h-20 w-20 transition-transform duration-500 ${s?"":"scale-110"}`}),!s&&r.jsx("div",{className:"absolute -inset-3 z-0",children:r.jsx("svg",{className:"h-full w-full animate-[spin_1.2s_linear_infinite]",viewBox:"0 0 100 100",children:r.jsx("circle",{cx:"50",cy:"50",r:"46",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeDasharray:"60 230",strokeLinecap:"round",className:"text-cc-primary/45"})})}),s&&r.jsx("div",{className:"absolute -inset-3 z-0 rounded-full border-2 border-cc-success/30"})]}),r.jsx("p",{className:`mb-2 text-sm font-medium ${s?"text-cc-success":"text-cc-fg"}`,children:p9[t]}),r.jsx("p",{className:"text-xs text-cc-muted",children:s?"Reloading...":"This page will refresh automatically"}),!s&&r.jsx("div",{className:"mt-6 flex gap-1.5",children:[0,1,2].map(n=>r.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-cc-primary/50",style:{animation:"pulse-dot 1.4s ease-in-out infinite",animationDelay:`${n*.2}s`}},n))}),r.jsx("div",{className:"absolute bottom-0 left-0 right-0 h-0.5 bg-cc-border/40",children:r.jsx("div",{className:"h-full bg-cc-primary/70 transition-all duration-1000",style:{width:s?"100%":"70%"}})})]})}const v9=[{id:"general",label:"General"},{id:"providers",label:"Providers"},{id:"api-keys",label:"API Keys"},{id:"memory",label:"Memory"},{id:"security",label:"Security"},{id:"notifications",label:"Notifications"},{id:"appearance",label:"Appearance"},{id:"updates",label:"Updates"}];function b9(e,t){return e?`${t} active session${t===1?"":"s"}`:"Anyone with the URL can access this instance"}function _9(e){return e!=null&&e.latestVersion?e.updateAvailable?`v${e.latestVersion} available`:"You're on the latest version":"Check for updates to see the latest version"}function y9(e){return e?"text-cc-success bg-cc-success/10":"text-cc-warning bg-cc-warning/10"}function Lh({enabled:e,onToggle:t,label:s}){return r.jsx("button",{type:"button",role:"switch","aria-checked":e,"aria-label":s,onClick:t,className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors duration-200 cursor-pointer shrink-0 ${e?"bg-cc-primary":"bg-cc-border"}`,children:r.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white shadow-sm transition-transform duration-200 ${e?"translate-x-[18px]":"translate-x-[3px]"}`})})}function ar({title:e,description:t,children:s}){return r.jsxs("div",{className:"bg-cc-card border border-cc-border/60 rounded-xl",children:[r.jsxs("div",{className:"px-5 py-4 border-b border-cc-border/40",children:[r.jsx("h3",{className:"text-[13px] font-semibold text-cc-fg",children:e}),t&&r.jsx("p",{className:"mt-0.5 text-[12px] text-cc-fg/60",children:t})]}),r.jsx("div",{className:"px-5 py-4",children:s})]})}function Bh({label:e,description:t,children:s}){return r.jsxs("div",{className:"flex items-center justify-between gap-4 py-3 first:pt-0 last:pb-0 border-b border-cc-border/20 last:border-0",children:[r.jsxs("div",{className:"min-w-0",children:[r.jsx("span",{className:"text-[13px] font-medium text-cc-fg",children:e}),t&&r.jsx("p",{className:"text-[11px] text-cc-fg/55 mt-0.5",children:t})]}),r.jsx("div",{className:"shrink-0",children:s})]})}function w9({telemetryEnabled:e,setTelemetryEnabled:t}){return r.jsxs(r.Fragment,{children:[r.jsx(ar,{title:"Telemetry",description:"Help improve Campfire with anonymous usage data",children:r.jsx(Bh,{label:"Usage analytics and crash reports",description:"Anonymous product analytics via PostHog. Browser Do Not Track is respected automatically.",children:r.jsx(Lh,{enabled:e,label:"Toggle telemetry",onToggle:()=>{const s=!e;RM(s),t(s)}})})}),r.jsx(ar,{title:"Environments",description:"Manage reusable environment profiles for sessions",children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("p",{className:"text-[12px] text-cc-fg/60",children:"Configure named sets of environment variables to use when creating sessions."}),r.jsx("button",{type:"button",onClick:()=>{globalThis.location.hash="#/environments"},className:"px-3.5 py-2 rounded-lg text-[12px] font-medium bg-cc-primary hover:bg-cc-primary-hover text-white transition-colors cursor-pointer shrink-0 ml-4",children:"Manage"})]})})]})}function S9({claudeOAuthToken:e,setClaudeOAuthToken:t,claudeConfigured:s,setClaudeConfigured:n,openaiApiKey:a,setOpenaiApiKey:l,openaiConfigured:c,setOpenaiConfigured:d,anthropicApiKey:f,setAnthropicApiKey:h,anthropicConfigured:m,setAnthropicConfigured:g,providerSaving:b,setProviderSaving:v,providerSaved:y,setProviderSaved:S,error:j,setError:k}){return r.jsxs("div",{className:"space-y-5",children:[r.jsx(ar,{title:"AI Provider Tokens",description:"Tokens are auto-injected into sessions for matching backends. Environment profiles take precedence.",children:r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[r.jsx("label",{htmlFor:"claude-oauth",className:"text-[12px] font-medium text-cc-fg",children:"Claude Code OAuth Token"}),r.jsx("span",{className:`text-[10px] font-medium px-1.5 rounded-full ${s?"text-cc-success bg-cc-success/10":"text-cc-muted bg-cc-hover"}`,children:s?"Configured":"Not set"})]}),r.jsxs("p",{className:"text-[11px] text-cc-muted mb-1.5",children:["Injected as ",r.jsx("code",{className:"font-mono-code text-[10px] bg-cc-hover px-1 rounded",children:"CLAUDE_CODE_OAUTH_TOKEN"})," for Claude sessions"]}),r.jsx("input",{id:"claude-oauth",type:"password",value:e,onChange:E=>t(E.target.value),placeholder:s?"•••••••••••• (configured)":"Paste token from claude setup-token",className:"w-full h-9 px-3 rounded-lg border border-cc-border bg-cc-input-bg text-[12px] text-cc-fg font-mono-code"})]}),r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[r.jsx("label",{htmlFor:"openai-key",className:"text-[12px] font-medium text-cc-fg",children:"OpenAI API Key"}),r.jsx("span",{className:`text-[10px] font-medium px-1.5 rounded-full ${c?"text-cc-success bg-cc-success/10":"text-cc-muted bg-cc-hover"}`,children:c?"Configured":"Not set"})]}),r.jsxs("p",{className:"text-[11px] text-cc-muted mb-1.5",children:["Injected as ",r.jsx("code",{className:"font-mono-code text-[10px] bg-cc-hover px-1 rounded",children:"OPENAI_API_KEY"})," for Codex sessions"]}),r.jsx("input",{id:"openai-key",type:"password",value:a,onChange:E=>l(E.target.value),placeholder:c?"•••••••••••• (configured)":"sk-...",className:"w-full h-9 px-3 rounded-lg border border-cc-border bg-cc-input-bg text-[12px] text-cc-fg font-mono-code"})]}),r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[r.jsx("label",{htmlFor:"anthropic-key",className:"text-[12px] font-medium text-cc-fg",children:"Anthropic API Key"}),r.jsx("span",{className:`text-[10px] font-medium px-1.5 rounded-full ${m?"text-cc-success bg-cc-success/10":"text-cc-muted bg-cc-hover"}`,children:m?"Configured":"Not set"})]}),r.jsxs("p",{className:"text-[11px] text-cc-muted mb-1.5",children:["Injected as ",r.jsx("code",{className:"font-mono-code text-[10px] bg-cc-hover px-1 rounded",children:"ANTHROPIC_API_KEY"})," for all sessions (Goose, Aider, etc.)"]}),r.jsx("input",{id:"anthropic-key",type:"password",value:f,onChange:E=>h(E.target.value),placeholder:m?"•••••••••••• (configured)":"sk-ant-api03-...",className:"w-full h-9 px-3 rounded-lg border border-cc-border bg-cc-input-bg text-[12px] text-cc-fg font-mono-code"})]})]})}),r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("button",{type:"button",onClick:async()=>{v(!0),k("");try{const E={};if(e.trim()&&(E.claudeOAuthToken=e.trim()),a.trim()&&(E.openaiApiKey=a.trim()),f.trim()&&(E.anthropicApiKey=f.trim()),Object.keys(E).length===0)return;const N=await se.updateSettings(E);n(N.claudeOAuthTokenConfigured??!1),d(N.openaiApiKeyConfigured??!1),g(N.anthropicApiKeyConfigured??!1),t(""),l(""),h(""),S(!0),setTimeout(()=>S(!1),1800)}catch(E){k(E instanceof Error?E.message:"Save failed")}finally{v(!1)}},disabled:b,className:"px-4 py-1.5 rounded-lg bg-cc-primary text-white text-[12px] font-medium hover:bg-cc-primary-hover transition-colors cursor-pointer disabled:opacity-40",children:b?"Saving...":"Save Providers"}),y&&r.jsx("span",{className:"text-[11px] text-cc-success",children:"Saved"}),j&&r.jsx("span",{className:"text-[11px] text-cc-error",children:j})]}),r.jsx("div",{className:"rounded-lg border border-cc-border/40 bg-cc-hover/30 px-4 py-3",children:r.jsxs("p",{className:"text-[11px] text-cc-muted leading-relaxed",children:["Provider tokens are automatically injected into new sessions for the matching backend. If an environment profile already sets the same variable, the profile value takes precedence. Tokens are stored in ",r.jsx("code",{className:"font-mono-code text-[10px] bg-cc-hover px-1 rounded",children:"~/.campfire/settings.json"}),"."]})})]})}function j9({openrouterApiKey:e,setOpenrouterApiKey:t,openrouterModel:s,setOpenrouterModel:n,configured:a,moltbookApiKey:l,setMoltbookApiKey:c,moltbookConfigured:d,loading:f,saving:h,error:m,saved:g,onSave:b}){return r.jsxs("form",{onSubmit:b,className:"space-y-5",children:[r.jsx(ar,{title:"OpenRouter",description:"Used for auto-naming sessions after the first turn",children:r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-[12px] font-medium text-cc-fg mb-1.5",htmlFor:"openrouter-key",children:"API Key"}),r.jsx("input",{id:"openrouter-key",type:"password",value:e,onChange:v=>t(v.target.value),placeholder:a?"Configured — enter a new key to replace":"sk-or-v1-...",className:"w-full px-3.5 py-2.5 text-[13px] bg-cc-bg border border-cc-border/60 rounded-lg text-cc-fg placeholder:text-cc-fg/40 focus:outline-none focus:border-cc-primary/60 focus:ring-1 focus:ring-cc-primary/20 transition-all"}),r.jsx("div",{className:"flex items-center gap-2 mt-2",children:a?r.jsxs("span",{className:"inline-flex items-center gap-1 text-[11px] text-cc-success font-medium",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3",children:r.jsx("path",{d:"M8 0a8 8 0 110 16A8 8 0 018 0zm3.78 4.97a.75.75 0 00-1.06 0L7 8.69 5.28 6.97a.75.75 0 00-1.06 1.06l2.25 2.25a.75.75 0 001.06 0l4.25-4.25a.75.75 0 000-1.06z"})}),"Configured"]}):r.jsx("span",{className:"text-[11px] text-cc-fg/50",children:"Not configured — auto-naming is disabled"})})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-[12px] font-medium text-cc-fg mb-1.5",htmlFor:"openrouter-model",children:"Model"}),r.jsx("input",{id:"openrouter-model",type:"text",value:s,onChange:v=>n(v.target.value),placeholder:"openrouter/free",className:"w-full px-3.5 py-2.5 text-[13px] bg-cc-bg border border-cc-border/60 rounded-lg text-cc-fg placeholder:text-cc-fg/40 focus:outline-none focus:border-cc-primary/60 focus:ring-1 focus:ring-cc-primary/20 transition-all"})]})]})}),r.jsx(ar,{title:"Moltbook",description:"Required to post gallery sessions to Moltbook",children:r.jsxs("div",{children:[r.jsx("label",{className:"block text-[12px] font-medium text-cc-fg mb-1.5",htmlFor:"moltbook-key",children:"API Key"}),r.jsx("input",{id:"moltbook-key",type:"password",value:l,onChange:v=>c(v.target.value),placeholder:d?"Configured — enter a new key to replace":"Paste your Moltbook API key",className:"w-full px-3.5 py-2.5 text-[13px] bg-cc-bg border border-cc-border/60 rounded-lg text-cc-fg placeholder:text-cc-fg/40 focus:outline-none focus:border-cc-primary/60 focus:ring-1 focus:ring-cc-primary/20 transition-all"}),r.jsx("div",{className:"flex items-center gap-2 mt-2",children:d?r.jsxs("span",{className:"inline-flex items-center gap-1 text-[11px] text-cc-success font-medium",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3",children:r.jsx("path",{d:"M8 0a8 8 0 110 16A8 8 0 018 0zm3.78 4.97a.75.75 0 00-1.06 0L7 8.69 5.28 6.97a.75.75 0 00-1.06 1.06l2.25 2.25a.75.75 0 001.06 0l4.25-4.25a.75.75 0 000-1.06z"})}),"Configured"]}):r.jsx("span",{className:"text-[11px] text-cc-fg/50",children:"Get a key at moltbook.com by registering an agent"})})]})}),r.jsxs("div",{className:"flex items-center justify-between bg-cc-card border border-cc-border/60 rounded-xl px-5 py-3.5",children:[r.jsxs("div",{className:"text-[12px]",children:[m&&r.jsx("span",{className:"text-cc-error",children:m}),g&&r.jsx("span",{className:"text-cc-success font-medium",children:"Settings saved successfully"}),!m&&!g&&r.jsx("span",{className:"text-cc-fg/50",children:f?"Loading...":"Changes are saved immediately"})]}),r.jsx("button",{type:"submit",disabled:h||f,className:`px-4 py-2 rounded-lg text-[13px] font-medium transition-all ${h||f?"bg-cc-hover text-cc-fg/40 cursor-not-allowed":"bg-cc-primary hover:bg-cc-primary-hover text-white shadow-sm cursor-pointer"}`,children:h?"Saving...":"Save API Keys"})]})]})}const Oh=[{key:"global",label:"Global",description:"Cross-repo conventions, user preferences, tool quirks"},{key:"repo",label:"Repository",description:"Architecture, conventions, distilled patterns per repo"},{key:"session",label:"Session",description:"Episodic fragments of one session (pre-consolidation)"},{key:"agent",label:"Agent",description:"Backend-specific behavior notes"}];function vg(e){var n;const t={},s={};for(const{key:a}of Oh){const l=e.decay[a]??Eh.decay[a];t[a]={halfLifeDays:l.halfLifeHours==null?"":String(l.halfLifeHours/24),reinforceMultiplier:String(l.reinforceMultiplier)},s[a]=String(((n=e.recallDepth)==null?void 0:n[a])??Eh.recallDepth[a])}return{decay:t,recallDepth:s}}function k9(e){const t={},s={};for(const{key:n,label:a}of Oh){const l=e.decay[n].halfLifeDays.trim();let c=null;if(l!==""){const h=Number(l);if(!Number.isFinite(h)||h<=0)return{error:`${a}: half-life must be a positive number of days (leave empty to never decay)`};c=Math.round(h*24)}const d=Number(e.decay[n].reinforceMultiplier);if(!Number.isFinite(d)||d<1)return{error:`${a}: reinforce multiplier must be a number ≥ 1`};const f=Number(e.recallDepth[n]);if(!Number.isInteger(f)||f<0)return{error:`${a}: recall depth must be a whole number ≥ 0`};t[n]={halfLifeHours:c,reinforceMultiplier:d},s[n]=f}return{settings:{decay:t,recallDepth:s}}}function C9({initial:e}){const[t,s]=w.useState(()=>vg(e)),[n,a]=w.useState(!1),[l,c]=w.useState(!1),[d,f]=w.useState("");w.useEffect(()=>{s(vg(e))},[e]);function h(b,v,y){s(S=>({...S,decay:{...S.decay,[b]:{...S.decay[b],[v]:y}}}))}function m(b,v){s(y=>({...y,recallDepth:{...y.recallDepth,[b]:v}}))}async function g(){f(""),c(!1);const{settings:b,error:v}=k9(t);if(!b){f(v||"Invalid memory settings");return}a(!0);try{const y=await se.updateSettings({memory:b});y.memory&&s(vg(y.memory)),c(!0),setTimeout(()=>c(!1),1800)}catch(y){f(y instanceof Error?y.message:"Save failed")}finally{a(!1)}}return r.jsxs("div",{className:"space-y-5",children:[r.jsx(ar,{title:"Memory Decay",description:"Per-namespace half-life for recalled memories. Leave half-life empty to never decay. Reinforcement extends the half-life each time a memory is actually used.",children:r.jsx("div",{className:"space-y-4",children:Oh.map(({key:b,label:v,description:y})=>r.jsxs("div",{className:"flex flex-wrap items-end gap-3 py-1 border-b border-cc-border/20 last:border-0 pb-3 last:pb-0",children:[r.jsxs("div",{className:"min-w-[160px] flex-1",children:[r.jsx("span",{className:"text-[13px] font-medium text-cc-fg",children:v}),r.jsx("p",{className:"text-[11px] text-cc-fg/55 mt-0.5",children:y})]}),r.jsxs("div",{children:[r.jsx("label",{htmlFor:`memory-halflife-${b}`,className:"block text-[11px] text-cc-fg/60 mb-1",children:"Half-life (days)"}),r.jsx("input",{id:`memory-halflife-${b}`,type:"number",min:"0",step:"1",value:t.decay[b].halfLifeDays,onChange:S=>h(b,"halfLifeDays",S.target.value),placeholder:"never",className:"w-24 h-9 px-3 rounded-lg border border-cc-border bg-cc-input-bg text-[12px] text-cc-fg font-mono-code"})]}),r.jsxs("div",{children:[r.jsx("label",{htmlFor:`memory-reinforce-${b}`,className:"block text-[11px] text-cc-fg/60 mb-1",children:"Reinforce ×"}),r.jsx("input",{id:`memory-reinforce-${b}`,type:"number",min:"1",step:"0.1",value:t.decay[b].reinforceMultiplier,onChange:S=>h(b,"reinforceMultiplier",S.target.value),className:"w-20 h-9 px-3 rounded-lg border border-cc-border bg-cc-input-bg text-[12px] text-cc-fg font-mono-code"})]})]},b))})}),r.jsx(ar,{title:"Recall Depth",description:"How many memories each namespace contributes when enriching a prompt with recalled context.",children:r.jsx("div",{className:"flex flex-wrap gap-4",children:Oh.map(({key:b,label:v})=>r.jsxs("div",{children:[r.jsx("label",{htmlFor:`memory-depth-${b}`,className:"block text-[11px] text-cc-fg/60 mb-1",children:v}),r.jsx("input",{id:`memory-depth-${b}`,type:"number",min:"0",step:"1",value:t.recallDepth[b],onChange:y=>m(b,y.target.value),className:"w-20 h-9 px-3 rounded-lg border border-cc-border bg-cc-input-bg text-[12px] text-cc-fg font-mono-code"})]},b))})}),r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("button",{type:"button",onClick:g,disabled:n,className:"px-4 py-1.5 rounded-lg bg-cc-primary text-white text-[12px] font-medium hover:bg-cc-primary-hover transition-colors cursor-pointer disabled:opacity-40",children:n?"Saving...":"Save Memory Settings"}),l&&r.jsx("span",{className:"text-[11px] text-cc-success",children:"Saved"}),d&&r.jsx("span",{className:"text-[11px] text-cc-error",children:d})]}),r.jsx("div",{className:"rounded-lg border border-cc-border/40 bg-cc-hover/30 px-4 py-3",children:r.jsxs("p",{className:"text-[11px] text-cc-muted leading-relaxed",children:["Pinned memories never decay regardless of half-life. Defaults: Global 90d, Repository 30d, Session 7d, Agent 60d. Settings are stored in ",r.jsx("code",{className:"font-mono-code text-[10px] bg-cc-hover px-1 rounded",children:"~/.campfire/settings.json"}),"."]})})]})}function N9({authEnabled:e,setAuthEnabled:t,authPassword:s,setAuthPassword:n,authSaving:a,setAuthSaving:l,authSaved:c,setAuthSaved:d,authError:f,setAuthError:h,authSessions:m}){return r.jsx("div",{className:"space-y-5",children:r.jsxs(ar,{title:"Authentication",description:"Protect your Campfire instance with a password. When enabled, all API and WebSocket connections require a valid session token.",children:[r.jsxs("div",{className:"flex items-center gap-3 mb-4 pb-4 border-b border-cc-border/30",children:[r.jsx("div",{className:`w-10 h-10 rounded-xl flex items-center justify-center ${e?"bg-cc-success/10":"bg-cc-hover"}`,children:r.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:`w-5 h-5 ${e?"text-cc-success":"text-cc-muted"}`,"aria-hidden":!0,children:r.jsx("path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z",strokeLinecap:"round",strokeLinejoin:"round"})})}),r.jsxs("div",{className:"flex-1",children:[r.jsxs("p",{className:"text-[13px] font-medium text-cc-fg",children:["Authentication is ",e?"enabled":"disabled"]}),r.jsx("p",{className:"text-[11px] text-cc-muted",children:b9(e,m)})]}),r.jsx("span",{className:`text-[10px] font-semibold px-2.5 py-1 rounded-full ${y9(e)}`,children:e?"Protected":"Open"})]}),f&&r.jsx("div",{className:"mb-3 px-3 py-2 rounded-lg bg-cc-error/8 border border-cc-error/15",role:"alert",children:r.jsx("p",{className:"text-[11px] text-cc-error",children:f})}),e?r.jsx(D9,{saving:a,onDisable:async()=>{l(!0),h("");try{await se.disableAuth(),t(!1),d(!0),setTimeout(()=>d(!1),2e3)}catch(g){h(g instanceof Error?g.message:"Failed to disable auth")}finally{l(!1)}}}):r.jsx(R9,{password:s,saving:a,onPasswordChange:n,onEnable:async()=>{l(!0),h("");try{await se.setupAuth(s);const{token:g}=await se.login(s);Oj(g),t(!0),n(""),d(!0),setTimeout(()=>d(!1),2e3)}catch(g){h(g instanceof Error?g.message:"Failed to enable auth")}finally{l(!1)}}}),c&&r.jsx("p",{className:"text-[11px] text-cc-success mt-2",children:"Saved"})]})})}function E9({notificationSound:e,toggleNotificationSound:t,notificationDesktop:s,setNotificationDesktop:n,notificationApiAvailable:a}){return r.jsxs(ar,{title:"Notification Preferences",description:"Control how Campfire alerts you",children:[r.jsx(Bh,{label:"Sound",description:"Play a notification sound when a permission request arrives",children:r.jsx(Lh,{enabled:e,label:"Toggle notification sound",onToggle:t})}),a&&r.jsx(Bh,{label:"Desktop Alerts",description:"Show native browser notifications for permission requests",children:r.jsx(Lh,{enabled:s,label:"Toggle desktop notifications",onToggle:async()=>{if(s)n(!1);else{if(Notification.permission!=="granted"&&await Notification.requestPermission()!=="granted")return;n(!0)}}})})]})}function M9({darkMode:e,toggleDarkMode:t}){return r.jsx(ar,{title:"Theme",description:"Choose your preferred color scheme",children:r.jsx(Bh,{label:"Dark Mode",description:"Switch between light and dark themes",children:r.jsx(Lh,{enabled:e,label:"Toggle dark mode",onToggle:t})})})}function T9({updateInfo:e,updateError:t,updateStatus:s,checkingUpdates:n,updatingApp:a,onCheckUpdates:l,onTriggerUpdate:c}){return r.jsx(ar,{title:"Software Updates",description:"Keep Campfire up to date",children:r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{className:"flex items-center gap-3 py-2",children:[r.jsx("div",{className:"w-10 h-10 rounded-xl bg-cc-primary/10 flex items-center justify-center shrink-0",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-5 h-5 text-cc-primary",children:r.jsx("path",{d:"M8 0a8 8 0 110 16A8 8 0 018 0zm0 1.5a6.5 6.5 0 100 13 6.5 6.5 0 000-13zM8 4a.75.75 0 01.75.75v3.5h2.5a.75.75 0 010 1.5h-3.25a.75.75 0 01-.75-.75v-4.25A.75.75 0 018 4z"})})}),r.jsxs("div",{children:[r.jsx("p",{className:"text-[13px] font-medium text-cc-fg",children:e?`v${e.currentVersion}`:"Loading..."}),r.jsx("p",{className:"text-[11px] text-cc-fg/55",children:_9(e)})]})]}),t&&r.jsx("div",{className:"px-3.5 py-2.5 rounded-lg bg-cc-error/8 border border-cc-error/15 text-[12px] text-cc-error",children:t}),s&&r.jsx("div",{className:"px-3.5 py-2.5 rounded-lg bg-cc-success/8 border border-cc-success/15 text-[12px] text-cc-success",children:s}),r.jsxs("div",{className:"flex items-center gap-2.5 pt-1",children:[r.jsx("button",{type:"button",onClick:l,disabled:n,className:`px-4 py-2 rounded-lg text-[13px] font-medium transition-all ${n?"bg-cc-hover text-cc-fg/40 cursor-not-allowed":"bg-cc-hover hover:bg-cc-active text-cc-fg cursor-pointer"}`,children:n?r.jsxs("span",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"w-3.5 h-3.5 border-2 border-cc-fg/20 border-t-cc-fg/60 rounded-full animate-spin"})," ","Checking..."]}):"Check for Updates"}),e!=null&&e.isServiceMode?r.jsx("button",{type:"button",onClick:c,disabled:a||e.updateInProgress||!e.updateAvailable,className:`px-4 py-2 rounded-lg text-[13px] font-medium transition-all ${a||e.updateInProgress||!e.updateAvailable?"bg-cc-hover text-cc-fg/40 cursor-not-allowed":"bg-cc-primary hover:bg-cc-primary-hover text-white shadow-sm cursor-pointer"}`,children:a||e.updateInProgress?"Updating...":"Update & Restart"}):r.jsxs("p",{className:"text-[11px] text-cc-fg/55 self-center",children:["Run ",r.jsx("code",{className:"font-mono-code bg-cc-code-bg px-1.5 py-0.5 rounded text-cc-code-fg text-[10px]",children:"the-campfire install"})," to enable one-click updates"]})]})]})})}function A9({embedded:e=!1}){const[t,s]=w.useState("general"),[n,a]=w.useState(""),[l,c]=w.useState("openrouter/free"),[d,f]=w.useState(!1),[h,m]=w.useState(""),[g,b]=w.useState(!1),[v,y]=w.useState(""),[S,j]=w.useState(!1),[k,E]=w.useState(""),[N,B]=w.useState(!1),[A,P]=w.useState(""),[K,X]=w.useState(!1),[Z,I]=w.useState(!1),[H,F]=w.useState(!1),[G,q]=w.useState(!0),[R,M]=w.useState(!1),[O,W]=w.useState(""),[U,D]=w.useState(!1),[$,z]=w.useState(!1),[T,ae]=w.useState(""),[be,ne]=w.useState(!1),[ve,Ae]=w.useState(!1),[De,ke]=w.useState(""),[Xe,Je]=w.useState(0),[$e,we]=w.useState(Eh),Ze=Y(ye=>ye.darkMode),ft=Y(ye=>ye.toggleDarkMode),mt=Y(ye=>ye.notificationSound),ss=Y(ye=>ye.toggleNotificationSound),Kt=Y(ye=>ye.notificationDesktop),Ft=Y(ye=>ye.setNotificationDesktop),Dt=Y(ye=>ye.updateInfo),Hs=Y(ye=>ye.setUpdateInfo),xs=Y(ye=>ye.setUpdateOverlayActive),_t=typeof Notification<"u",[lr,de]=w.useState(!1),[_e,Pe]=w.useState(!1),[qe,Ke]=w.useState(""),[Yt,Xt]=w.useState(""),[te,fe]=w.useState(Dj());w.useEffect(()=>{se.getSettings().then(ye=>{f(ye.openrouterApiKeyConfigured),c(ye.openrouterModel||"openrouter/free"),b(ye.moltbookApiKeyConfigured),j(ye.claudeOAuthTokenConfigured??!1),B(ye.openaiApiKeyConfigured??!1),X(ye.anthropicApiKeyConfigured??!1),we(ye.memory??Eh)}).catch(ye=>W(ye instanceof Error?ye.message:"Unknown error")).finally(()=>q(!1)),se.getAuthStatus().then(ye=>{z(ye.enabled),Je(ye.activeSessions)}).catch(()=>{})},[]);async function V(ye){ye.preventDefault(),M(!0),W(""),D(!1);try{const Mt=n.trim(),ns=h.trim(),rn={openrouterModel:l.trim()||"openrouter/free"};Mt&&(rn.openrouterApiKey=Mt),ns&&(rn.moltbookApiKey=ns);const Qn=await se.updateSettings(rn);f(Qn.openrouterApiKeyConfigured),b(Qn.moltbookApiKeyConfigured),a(""),m(""),D(!0),setTimeout(()=>D(!1),1800)}catch(Mt){W(Mt instanceof Error?Mt.message:"Unknown error")}finally{M(!1)}}async function le(){de(!0),Ke(""),Xt("");try{const ye=await se.forceCheckForUpdate();Hs(ye),ye.updateAvailable&&ye.latestVersion?Ke(`Update v${ye.latestVersion} is available.`):Ke("You are up to date.")}catch(ye){Xt(ye instanceof Error?ye.message:"Unknown error")}finally{de(!1)}}async function Ve(){Pe(!0),Ke(""),Xt("");try{const ye=await se.triggerUpdate();Ke(ye.message),xs(!0)}catch(ye){Xt(ye instanceof Error?ye.message:"Unknown error"),Pe(!1)}}return r.jsx("div",{className:`${e?"h-full":"h-[100dvh]"} bg-cc-bg text-cc-fg font-sans-ui antialiased overflow-y-auto`,children:r.jsxs("div",{className:"max-w-3xl mx-auto px-4 sm:px-8 py-6 sm:py-10",children:[r.jsxs("div",{className:"flex items-center gap-3 mb-1",children:[!e&&r.jsx("button",{onClick:()=>{globalThis.location.hash=""},className:"flex items-center justify-center w-8 h-8 rounded-lg text-cc-fg/60 hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer","aria-label":"Go back",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.8",className:"w-4 h-4",children:r.jsx("path",{d:"M10 3L5 8l5 5",strokeLinecap:"round",strokeLinejoin:"round"})})}),r.jsxs("div",{children:[r.jsx("p",{className:"text-[11px] text-cc-fg/50 font-medium",children:"Settings"}),r.jsx("h1",{className:"text-xl font-semibold text-cc-fg -mt-0.5",children:"Settings"})]})]}),r.jsx("div",{className:"mt-5 mb-6 border-b border-cc-border/40",children:r.jsx("nav",{className:"flex gap-0 -mb-px overflow-x-auto","aria-label":"Settings tabs",children:v9.map(ye=>r.jsx("button",{onClick:()=>s(ye.id),className:`px-4 py-2.5 text-[13px] font-medium whitespace-nowrap border-b-2 transition-colors cursor-pointer ${t===ye.id?"border-cc-primary text-cc-fg":"border-transparent text-cc-fg/55 hover:text-cc-fg hover:border-cc-border/60"}`,"aria-selected":t===ye.id,role:"tab",children:ye.label},ye.id))})}),r.jsxs("div",{className:"space-y-5",children:[t==="general"&&r.jsx(w9,{telemetryEnabled:te,setTelemetryEnabled:fe}),t==="providers"&&r.jsx(S9,{claudeOAuthToken:v,setClaudeOAuthToken:y,claudeConfigured:S,setClaudeConfigured:j,openaiApiKey:k,setOpenaiApiKey:E,openaiConfigured:N,setOpenaiConfigured:B,anthropicApiKey:A,setAnthropicApiKey:P,anthropicConfigured:K,setAnthropicConfigured:X,providerSaving:Z,setProviderSaving:I,providerSaved:H,setProviderSaved:F,error:O,setError:W}),t==="api-keys"&&r.jsx(j9,{openrouterApiKey:n,setOpenrouterApiKey:a,openrouterModel:l,setOpenrouterModel:c,configured:d,moltbookApiKey:h,setMoltbookApiKey:m,moltbookConfigured:g,loading:G,saving:R,error:O,saved:U,onSave:V}),t==="memory"&&r.jsx(C9,{initial:$e}),t==="security"&&r.jsx(N9,{authEnabled:$,setAuthEnabled:z,authPassword:T,setAuthPassword:ae,authSaving:be,setAuthSaving:ne,authSaved:ve,setAuthSaved:Ae,authError:De,setAuthError:ke,authSessions:Xe}),t==="notifications"&&r.jsx(E9,{notificationSound:mt,toggleNotificationSound:ss,notificationDesktop:Kt,setNotificationDesktop:Ft,notificationApiAvailable:_t}),t==="appearance"&&r.jsx(M9,{darkMode:Ze,toggleDarkMode:ft}),t==="updates"&&r.jsx(T9,{updateInfo:Dt,updateError:Yt,updateStatus:qe,checkingUpdates:lr,updatingApp:_e,onCheckUpdates:le,onTriggerUpdate:Ve})]})]})})}function R9({password:e,saving:t,onPasswordChange:s,onEnable:n}){return r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{children:[r.jsx("label",{htmlFor:"auth-password",className:"text-[12px] font-medium text-cc-fg block mb-1.5",children:"Set a password"}),r.jsx("input",{id:"auth-password",type:"password",value:e,onChange:a=>s(a.target.value),placeholder:"Minimum 4 characters",className:"w-full h-10 px-3 rounded-lg border border-cc-border bg-cc-input-bg text-[13px] text-cc-fg focus:outline-none focus:ring-2 focus:ring-cc-primary/20 focus:border-cc-primary/40"})]}),r.jsx("button",{type:"button",disabled:e.length<4||t,onClick:n,className:"w-full h-10 rounded-lg bg-cc-primary text-white text-[13px] font-medium hover:bg-cc-primary-hover transition-colors cursor-pointer disabled:opacity-40",children:t?"Enabling...":"Enable Authentication"})]})}function D9({saving:e,onDisable:t}){return r.jsxs("div",{className:"space-y-3",children:[r.jsx("div",{className:"rounded-lg border border-cc-border/40 bg-cc-hover/30 px-4 py-3",children:r.jsxs("p",{className:"text-[11px] text-cc-muted leading-relaxed",children:["All REST API requests require a ",r.jsx("code",{className:"font-mono-code text-[10px] bg-cc-hover px-1 rounded",children:"Bearer"})," token. All WebSocket connections require an ",r.jsx("code",{className:"font-mono-code text-[10px] bg-cc-hover px-1 rounded",children:"auth_token"})," parameter. CLI connections from localhost are allowed without a token."]})}),r.jsx("button",{type:"button",disabled:e,onClick:t,className:"w-full h-10 rounded-lg border border-cc-error/30 text-cc-error text-[13px] font-medium hover:bg-cc-error/5 transition-colors cursor-pointer disabled:opacity-40",children:e?"Disabling...":"Disable Authentication"})]})}const L9=w.lazy(()=>Xi(()=>Promise.resolve().then(()=>fu),void 0).then(e=>({default:e.CodeEditor})));function B9(e){const t=Date.now()-e,s=Math.floor(t/6e4);if(s<1)return"just now";if(s<60)return`${s}m ago`;const n=Math.floor(s/60);return n<24?`${n}h ago`:`${Math.floor(n/24)}d ago`}function O9(e){const t=e-Date.now();if(t<=0)return"now";const s=Math.floor(t/6e4);if(s<60)return`in ${s}m`;const n=Math.floor(s/60);return n<24?`in ${n}h`:`in ${Math.floor(n/24)}d`}function BC(e,t){if(!t)return"One-time";const s=e.trim().split(/\s+/);if(s.length!==5)return e;const[n,a,l,c,d]=s;if(e==="* * * * *")return"Every minute";if(a==="*"&&l==="*"&&c==="*"&&d==="*"&&n.startsWith("*/")){const f=parseInt(n.slice(2),10);return f===1?"Every minute":`Every ${f} minutes`}if(n==="0"&&l==="*"&&c==="*"&&d==="*"){if(a==="*")return"Every hour";if(a.startsWith("*/")){const f=parseInt(a.slice(2),10);return f===1?"Every hour":`Every ${f} hours`}}if(l==="*"&&c==="*"&&n!=="*"&&a!=="*"&&!a.includes("/")&&!a.includes(",")){const f=parseInt(a,10),h=parseInt(n,10);if(!isNaN(f)&&!isNaN(h)){const m=f>=12?"PM":"AM",g=f===0?12:f>12?f-12:f,b=h.toString().padStart(2,"0"),v=`${g}:${b} ${m}`;if(d==="*")return`Every day at ${v}`;if(d==="1-5")return`Weekdays at ${v}`;if(d==="0,6")return`Weekends at ${v}`}}return e}const bg={name:"",prompt:"",recurring:!0,schedule:"0 8 * * *",oneTimeDate:"",backendType:"claude",model:ri("claude"),cwd:""},z9=[{label:"Every hour",value:"0 * * * *"},{label:"Every day at 8am",value:"0 8 * * *"},{label:"Every 2 hours",value:"0 */2 * * *"},{label:"Weekdays at 9am",value:"0 9 * * 1-5"}];function P9({onClose:e,embedded:t=!1}){const[s,n]=w.useState([]),[a,l]=w.useState(!0),[c,d]=w.useState(""),[f,h]=w.useState(null),[m,g]=w.useState(bg),[b,v]=w.useState(bg),[y,S]=w.useState(!1),[j,k]=w.useState(!0),[E,N]=w.useState(new Set),B=w.useCallback(()=>{se.listCronJobs().then(n).catch(()=>{}).finally(()=>l(!1))},[]);w.useEffect(()=>{B();const M=setInterval(B,1e4);return()=>clearInterval(M)},[B]);async function A(){const M=b.name.trim(),O=b.prompt.trim();if(!M||!O)return;S(!0),d("");let W=b.schedule;!b.recurring&&b.oneTimeDate&&(W=new Date(b.oneTimeDate).toISOString());try{await se.createCronJob({name:M,prompt:O,schedule:W,recurring:b.recurring,backendType:b.backendType,model:b.backendType==="codex"?"":b.model.trim()||void 0,cwd:b.cwd.trim()||void 0}),v(bg),k(!0),B()}catch(U){d(U instanceof Error?U.message:String(U))}finally{S(!1)}}function P(M){h(M.id),g({name:M.name,prompt:M.prompt,recurring:M.recurring,schedule:M.schedule,oneTimeDate:"",backendType:M.backendType,model:M.model,cwd:M.cwd}),d("")}function K(){h(null),d("")}async function X(){if(!f)return;const M=m.name.trim(),O=m.prompt.trim();if(!M||!O)return;let W=m.schedule;!m.recurring&&m.oneTimeDate&&(W=new Date(m.oneTimeDate).toISOString());try{await se.updateCronJob(f,{name:M,prompt:O,schedule:W,recurring:m.recurring,backendType:m.backendType,model:m.backendType==="codex"?"":m.model.trim()||void 0,cwd:m.cwd.trim()||void 0}),h(null),d(""),B()}catch(U){d(U instanceof Error?U.message:String(U))}}async function Z(M){try{await se.deleteCronJob(M),f===M&&h(null),B()}catch(O){d(O instanceof Error?O.message:String(O))}}async function I(M){try{await se.toggleCronJob(M),B()}catch(O){d(O instanceof Error?O.message:String(O))}}async function H(M){N(O=>new Set(O).add(M));try{await se.runCronJob(M),B()}catch(O){d(O instanceof Error?O.message:String(O))}finally{N(O=>{const W=new Set(O);return W.delete(M),W})}}const F=c&&r.jsx("div",{className:"px-3 py-2 rounded-lg bg-cc-error/10 border border-cc-error/20 text-xs text-cc-error",children:c}),G=a?r.jsx("div",{className:"text-sm text-cc-muted text-center py-6",children:"Loading scheduled tasks..."}):s.length===0?r.jsx("div",{className:"text-sm text-cc-muted text-center py-6",children:"No scheduled tasks yet. Create one below."}):r.jsx("div",{className:"space-y-3",children:s.map(M=>r.jsxs("div",{className:"border border-cc-border rounded-lg overflow-hidden bg-cc-card",children:[r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5 bg-cc-card border-b border-cc-border",children:[r.jsx("span",{className:"text-sm font-medium text-cc-fg flex-1 truncate",children:M.name}),r.jsx("span",{className:`text-[9px] font-medium px-1.5 rounded-full leading-[16px] shrink-0 ${M.backendType==="codex"?"text-blue-500 bg-blue-500/10":"text-[#5BA8A0] bg-[#5BA8A0]/10"}`,children:M.backendType==="codex"?"Codex":"Claude"}),M.consecutiveFailures>0&&r.jsxs("span",{className:"text-[9px] font-medium px-1.5 rounded-full leading-[16px] shrink-0 text-cc-error bg-cc-error/10",children:[M.consecutiveFailures," fail",M.consecutiveFailures!==1?"s":""]}),r.jsx("button",{onClick:()=>I(M.id),className:`relative w-8 h-[18px] rounded-full transition-colors cursor-pointer shrink-0 ${M.enabled?"bg-cc-primary":"bg-cc-border"}`,title:M.enabled?"Disable":"Enable",children:r.jsx("span",{className:`absolute top-[2px] w-[14px] h-[14px] rounded-full bg-white transition-transform ${M.enabled?"left-[16px]":"left-[2px]"}`})}),f===M.id?r.jsx("button",{onClick:K,className:"text-xs text-cc-muted hover:text-cc-fg cursor-pointer",children:"Cancel"}):r.jsxs(r.Fragment,{children:[r.jsx("button",{onClick:()=>H(M.id),disabled:E.has(M.id),className:`text-xs cursor-pointer ${E.has(M.id)?"text-cc-muted cursor-not-allowed":"text-cc-primary hover:text-cc-primary-hover"}`,children:E.has(M.id)?"Running...":"Run Now"}),r.jsx("button",{onClick:()=>P(M),className:"text-xs text-cc-muted hover:text-cc-fg cursor-pointer",children:"Edit"}),r.jsx("button",{onClick:()=>Z(M.id),className:"text-xs text-cc-muted hover:text-cc-error cursor-pointer",children:"Delete"})]})]}),f===M.id&&r.jsxs("div",{className:"px-3 py-3 space-y-2.5",children:[r.jsx(d2,{form:m,onChange:g}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("button",{onClick:X,className:"px-3 py-2 text-xs font-medium bg-cc-primary hover:bg-cc-primary-hover text-white rounded-lg transition-colors cursor-pointer",children:"Save"}),r.jsx("button",{onClick:K,className:"px-3 py-2 text-xs font-medium text-cc-muted hover:text-cc-fg rounded-lg transition-colors cursor-pointer",children:"Cancel"})]})]}),f!==M.id&&r.jsxs("div",{className:"px-3 py-2.5 space-y-1.5",children:[r.jsx("div",{className:"text-xs text-cc-muted truncate",title:M.prompt,children:M.prompt}),r.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px] text-cc-muted",children:[r.jsx("span",{children:BC(M.schedule,M.recurring)}),M.nextRunAt!=null&&M.enabled&&r.jsxs("span",{children:["Next: ",O9(M.nextRunAt)]}),M.lastRunAt!=null&&r.jsxs("span",{className:"flex items-center gap-1",children:["Last: ",B9(M.lastRunAt),M.consecutiveFailures===0?r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 text-cc-success",children:r.jsx("path",{d:"M12.207 4.793a1 1 0 010 1.414l-5 5a1 1 0 01-1.414 0l-2.5-2.5a1 1 0 011.414-1.414L6.5 9.086l4.293-4.293a1 1 0 011.414 0z"})}):r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 text-cc-error",children:r.jsx("path",{d:"M4.646 4.646a.5.5 0 01.708 0L8 7.293l2.646-2.647a.5.5 0 01.708.708L8.707 8l2.647 2.646a.5.5 0 01-.708.708L8 8.707l-2.646 2.647a.5.5 0 01-.708-.708L7.293 8 4.646 5.354a.5.5 0 010-.708z"})})]}),M.totalRuns>0&&r.jsxs("span",{children:[M.totalRuns," run",M.totalRuns!==1?"s":""]}),M.cwd&&r.jsx("span",{className:"font-mono-code truncate max-w-[200px]",title:M.cwd,children:M.cwd})]})]})]},M.id))}),q=r.jsxs("div",{className:"border border-cc-border rounded-lg overflow-hidden bg-cc-card",children:[r.jsxs("button",{onClick:()=>k(!j),className:"w-full flex items-center gap-2 px-3 py-2.5 bg-cc-card border-b border-cc-border cursor-pointer hover:bg-cc-hover transition-colors",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",className:`w-3 h-3 text-cc-muted transition-transform ${j?"":"rotate-90"}`,children:r.jsx("path",{d:"M6 4l4 4-4 4",strokeLinecap:"round",strokeLinejoin:"round"})}),r.jsx("span",{className:"text-sm font-medium text-cc-fg",children:"New Scheduled Task"})]}),!j&&r.jsxs("div",{className:"px-3 py-3 space-y-2.5",children:[r.jsx(d2,{form:b,onChange:v}),r.jsx("div",{className:"text-[10px] text-cc-muted",children:"Scheduled tasks run with full autonomy (bypassPermissions)"}),r.jsx("button",{onClick:A,disabled:!b.name.trim()||!b.prompt.trim()||y,className:`px-3 py-2 text-xs font-medium rounded-lg transition-colors ${b.name.trim()&&b.prompt.trim()&&!y?"bg-cc-primary hover:bg-cc-primary-hover text-white cursor-pointer":"bg-cc-hover text-cc-muted cursor-not-allowed"}`,children:y?"Creating...":"Create"})]})]});if(t)return r.jsx("div",{className:"h-full bg-cc-bg overflow-y-auto",children:r.jsxs("div",{className:"max-w-5xl mx-auto px-4 sm:px-8 py-6 sm:py-10",children:[r.jsxs("div",{className:"mb-6",children:[r.jsx("h1",{className:"text-xl font-semibold text-cc-fg",children:"Scheduled Tasks"}),r.jsx("p",{className:"mt-1 text-sm text-cc-muted",children:"Run autonomous Claude Code or Codex sessions on a schedule."})]}),F,r.jsxs("div",{className:"mt-4 space-y-4",children:[r.jsxs("section",{className:"bg-cc-card border border-cc-border rounded-xl p-4 sm:p-5 space-y-3",children:[r.jsx("h2",{className:"text-sm font-semibold text-cc-fg",children:"Tasks"}),G]}),r.jsx("section",{className:"bg-cc-card border border-cc-border rounded-xl p-4 sm:p-5 space-y-3",children:q})]})]})});const R=r.jsxs("div",{className:"w-full max-w-2xl max-h-[90dvh] sm:max-h-[80dvh] mx-0 sm:mx-4 flex flex-col bg-cc-bg border border-cc-border rounded-t-xl sm:rounded-xl shadow-2xl overflow-hidden",onClick:M=>M.stopPropagation(),children:[r.jsxs("div",{className:"flex items-center justify-between px-4 sm:px-5 py-3 sm:py-4 border-b border-cc-border",children:[r.jsxs("div",{children:[r.jsx("h2",{className:"text-sm font-semibold text-cc-fg",children:"Scheduled Tasks"}),r.jsx("p",{className:"text-xs text-cc-muted mt-0.5",children:"Run autonomous Claude Code or Codex sessions on a schedule"})]}),e&&r.jsx("button",{onClick:e,className:"w-6 h-6 flex items-center justify-center rounded-md text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"w-3.5 h-3.5",children:r.jsx("path",{d:"M4 4l8 8M12 4l-8 8",strokeLinecap:"round"})})})]}),r.jsxs("div",{className:"flex-1 overflow-y-auto px-3 sm:px-5 py-3 sm:py-4 space-y-4",children:[F,G,q]})]});return rv.createPortal(r.jsx("div",{className:"fixed inset-0 z-50 flex items-end sm:items-center justify-center bg-black/50",onClick:e,children:R}),document.body)}function d2({form:e,onChange:t}){const s=g=>t({...e,...g}),[n,a]=w.useState(!1),l=w.useRef(null),[c,d]=w.useState(!1),f=Zh(e.backendType),h=f.find(g=>g.value===e.model)||f[0];w.useEffect(()=>{e.model||s({model:ri(e.backendType)})},[]),w.useEffect(()=>{if(!n)return;function g(b){l.current&&!l.current.contains(b.target)&&a(!1)}return document.addEventListener("pointerdown",g),()=>document.removeEventListener("pointerdown",g)},[n]);const m=e.cwd?e.cwd.split("/").pop()||e.cwd:"Select folder";return r.jsxs("div",{className:"space-y-2.5",children:[r.jsx("input",{type:"text",value:e.name,onChange:g=>s({name:g.target.value}),placeholder:"Task name (e.g. Daily test suite)",className:"w-full px-3 py-2 text-sm bg-cc-input-bg border border-cc-border rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:border-cc-primary/50"}),r.jsx("div",{children:r.jsx(w.Suspense,{fallback:r.jsx("div",{className:"h-[150px] rounded-xl border border-cc-border flex items-center justify-center text-cc-muted text-[12px]",children:"Loading editor..."}),children:r.jsx(L9,{value:e.prompt,onChange:g=>s({prompt:g}),language:"markdown",height:"150px",minimap:!1,wordWrap:!0,ariaLabel:"Cron job prompt editor"})})}),r.jsxs("div",{className:"space-y-2",children:[r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx("button",{onClick:()=>s({recurring:!0}),className:`px-2.5 py-1.5 text-xs font-medium rounded-lg transition-colors cursor-pointer ${e.recurring?"bg-cc-primary text-white":"bg-cc-hover text-cc-muted hover:text-cc-fg"}`,children:"Recurring"}),r.jsx("button",{onClick:()=>s({recurring:!1}),className:`px-2.5 py-1.5 text-xs font-medium rounded-lg transition-colors cursor-pointer ${e.recurring?"bg-cc-hover text-cc-muted hover:text-cc-fg":"bg-cc-primary text-white"}`,children:"One-time"})]}),e.recurring?r.jsxs("div",{className:"space-y-1.5",children:[r.jsx("div",{className:"flex flex-wrap gap-1.5",children:z9.map(g=>r.jsx("button",{onClick:()=>s({schedule:g.value}),className:`px-2 py-1 text-[10px] font-medium rounded-md transition-colors cursor-pointer ${e.schedule===g.value?"bg-cc-primary/20 text-cc-primary border border-cc-primary/30":"bg-cc-hover text-cc-muted hover:text-cc-fg border border-transparent"}`,children:g.label},g.value))}),r.jsx("input",{type:"text",value:e.schedule,onChange:g=>s({schedule:g.target.value}),placeholder:"Cron expression (e.g. 0 8 * * *)",className:"w-full px-3 py-2 text-sm font-mono-code bg-cc-input-bg border border-cc-border rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:border-cc-primary/50"}),r.jsx("div",{className:"text-[10px] text-cc-muted",children:BC(e.schedule,!0)})]}):r.jsx("input",{type:"datetime-local",value:e.oneTimeDate,onChange:g=>s({oneTimeDate:g.target.value}),className:"w-full px-3 py-2 text-sm bg-cc-input-bg border border-cc-border rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:border-cc-primary/50"})]}),r.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[r.jsx("button",{onClick:()=>{const g=["claude","codex","goose","aider","openhands","openclaw","opencode"],b=g.indexOf(e.backendType),v=g[(b+1)%g.length];s({backendType:v,model:ri(v)})},className:`px-2.5 py-1.5 text-xs font-medium rounded-lg transition-colors cursor-pointer ${e.backendType==="codex"?"bg-blue-500/15 text-blue-500 border border-blue-500/30":"bg-[#5BA8A0]/15 text-[#5BA8A0] border border-[#5BA8A0]/30"}`,children:e.backendType==="codex"?"Codex":"Claude Code"}),e.backendType==="codex"?r.jsx("div",{className:"flex items-center gap-1.5 px-2 py-1.5 text-xs text-cc-muted rounded-lg border border-cc-border",children:"Codex default"}):r.jsxs("div",{className:"relative",ref:l,children:[r.jsxs("button",{onClick:()=>a(!n),className:"flex items-center gap-1.5 px-2 py-1.5 text-xs text-cc-muted hover:text-cc-fg rounded-lg hover:bg-cc-hover transition-colors cursor-pointer border border-cc-border",children:[r.jsx("span",{children:h==null?void 0:h.icon}),r.jsx("span",{children:h==null?void 0:h.label}),r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 opacity-50",children:r.jsx("path",{d:"M4 6l4 4 4-4"})})]}),n&&r.jsx("div",{className:"absolute left-0 bottom-full mb-1 w-52 bg-cc-card border border-cc-border rounded-lg shadow-lg z-10 py-1",children:f.map(g=>r.jsxs("button",{onClick:()=>{s({model:g.value}),a(!1)},className:`w-full px-3 py-2 text-xs text-left hover:bg-cc-hover transition-colors cursor-pointer flex items-center gap-2 ${g.value===e.model?"text-cc-primary font-medium":"text-cc-fg"}`,children:[r.jsx("span",{children:g.icon}),g.label]},g.value))})]}),r.jsxs("button",{onClick:()=>d(!0),className:"flex items-center gap-1.5 px-2 py-1.5 text-xs text-cc-muted hover:text-cc-fg rounded-lg hover:bg-cc-hover transition-colors cursor-pointer border border-cc-border",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 opacity-60",children:r.jsx("path",{d:"M1 3.5A1.5 1.5 0 012.5 2h3.379a1.5 1.5 0 011.06.44l.622.621a.5.5 0 00.353.146H13.5A1.5 1.5 0 0115 4.707V12.5a1.5 1.5 0 01-1.5 1.5h-11A1.5 1.5 0 011 12.5v-9z"})}),r.jsx("span",{className:"max-w-[200px] truncate font-mono-code",children:m}),r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 opacity-50",children:r.jsx("path",{d:"M4 6l4 4 4-4"})})]}),c&&r.jsx(iv,{initialPath:e.cwd||"",onSelect:g=>s({cwd:g}),onClose:()=>d(!1)})]})]})}/**
|
|
234
234
|
* Copyright (c) 2014-2024 The xterm.js authors. All rights reserved.
|
|
235
235
|
* @license MIT
|
|
236
236
|
*
|
|
@@ -241,21 +241,21 @@ df.describe()`},toolUseId:"tb-11"}),r.jsx(mn,{name:"SendMessage",input:{type:"me
|
|
|
241
241
|
* Fabrice Bellard's javascript vt100 for jslinux:
|
|
242
242
|
* http://bellard.org/jslinux/
|
|
243
243
|
* Copyright (c) 2011 Fabrice Bellard
|
|
244
|
-
*/var OC=Object.defineProperty
|
|
244
|
+
*/var OC=Object.defineProperty,$9=Object.getOwnPropertyDescriptor,I9=(e,t)=>{for(var s in t)OC(e,s,{get:t[s],enumerable:!0})},ts=(e,t,s,n)=>{for(var a=n>1?void 0:n?$9(t,s):t,l=e.length-1,c;l>=0;l--)(c=e[l])&&(a=(n?c(t,s,a):c(a))||a);return n&&a&&OC(t,s,a),a},Re=(e,t)=>(s,n)=>t(s,n,e),h2="Terminal input",Dx={get:()=>h2,set:e=>h2=e},f2="Too much output to announce, navigate to rows manually to read",Lx={get:()=>f2,set:e=>f2=e};function F9(e){return e.replace(/\r?\n/g,"\r")}function H9(e,t){return t?"\x1B[200~"+e+"\x1B[201~":e}function U9(e,t){e.clipboardData&&e.clipboardData.setData("text/plain",t.selectionText),e.preventDefault()}function V9(e,t,s,n){if(e.stopPropagation(),e.clipboardData){let a=e.clipboardData.getData("text/plain");zC(a,t,s,n)}}function zC(e,t,s,n){e=F9(e),e=H9(e,s.decPrivateModes.bracketedPasteMode&&n.rawOptions.ignoreBracketedPasteMode!==!0),s.triggerDataEvent(e,!0),t.value=""}function PC(e,t,s){let n=s.getBoundingClientRect(),a=e.clientX-n.left-10,l=e.clientY-n.top-10;t.style.width="20px",t.style.height="20px",t.style.left=`${a}px`,t.style.top=`${l}px`,t.style.zIndex="1000",t.focus()}function p2(e,t,s,n,a){PC(e,t,s),a&&n.rightClickSelect(e),t.value=n.selectionText,t.select()}function Fi(e){return e>65535?(e-=65536,String.fromCharCode((e>>10)+55296)+String.fromCharCode(e%1024+56320)):String.fromCharCode(e)}function tf(e,t=0,s=e.length){let n="";for(let a=t;a<s;++a){let l=e[a];l>65535?(l-=65536,n+=String.fromCharCode((l>>10)+55296)+String.fromCharCode(l%1024+56320)):n+=String.fromCharCode(l)}return n}var W9=class{constructor(){this._interim=0}clear(){this._interim=0}decode(e,t){let s=e.length;if(!s)return 0;let n=0,a=0;if(this._interim){let l=e.charCodeAt(a++);56320<=l&&l<=57343?t[n++]=(this._interim-55296)*1024+l-56320+65536:(t[n++]=this._interim,t[n++]=l),this._interim=0}for(let l=a;l<s;++l){let c=e.charCodeAt(l);if(55296<=c&&c<=56319){if(++l>=s)return this._interim=c,n;let d=e.charCodeAt(l);56320<=d&&d<=57343?t[n++]=(c-55296)*1024+d-56320+65536:(t[n++]=c,t[n++]=d);continue}c!==65279&&(t[n++]=c)}return n}},q9=class{constructor(){this.interim=new Uint8Array(3)}clear(){this.interim.fill(0)}decode(e,t){let s=e.length;if(!s)return 0;let n=0,a,l,c,d,f=0,h=0;if(this.interim[0]){let b=!1,v=this.interim[0];v&=(v&224)===192?31:(v&240)===224?15:7;let y=0,S;for(;(S=this.interim[++y]&63)&&y<4;)v<<=6,v|=S;let j=(this.interim[0]&224)===192?2:(this.interim[0]&240)===224?3:4,k=j-y;for(;h<k;){if(h>=s)return 0;if(S=e[h++],(S&192)!==128){h--,b=!0;break}else this.interim[y++]=S,v<<=6,v|=S&63}b||(j===2?v<128?h--:t[n++]=v:j===3?v<2048||v>=55296&&v<=57343||v===65279||(t[n++]=v):v<65536||v>1114111||(t[n++]=v)),this.interim.fill(0)}let m=s-4,g=h;for(;g<s;){for(;g<m&&!((a=e[g])&128)&&!((l=e[g+1])&128)&&!((c=e[g+2])&128)&&!((d=e[g+3])&128);)t[n++]=a,t[n++]=l,t[n++]=c,t[n++]=d,g+=4;if(a=e[g++],a<128)t[n++]=a;else if((a&224)===192){if(g>=s)return this.interim[0]=a,n;if(l=e[g++],(l&192)!==128){g--;continue}if(f=(a&31)<<6|l&63,f<128){g--;continue}t[n++]=f}else if((a&240)===224){if(g>=s)return this.interim[0]=a,n;if(l=e[g++],(l&192)!==128){g--;continue}if(g>=s)return this.interim[0]=a,this.interim[1]=l,n;if(c=e[g++],(c&192)!==128){g--;continue}if(f=(a&15)<<12|(l&63)<<6|c&63,f<2048||f>=55296&&f<=57343||f===65279)continue;t[n++]=f}else if((a&248)===240){if(g>=s)return this.interim[0]=a,n;if(l=e[g++],(l&192)!==128){g--;continue}if(g>=s)return this.interim[0]=a,this.interim[1]=l,n;if(c=e[g++],(c&192)!==128){g--;continue}if(g>=s)return this.interim[0]=a,this.interim[1]=l,this.interim[2]=c,n;if(d=e[g++],(d&192)!==128){g--;continue}if(f=(a&7)<<18|(l&63)<<12|(c&63)<<6|d&63,f<65536||f>1114111)continue;t[n++]=f}}return n}},$C="",Vi=" ",pu=class IC{constructor(){this.fg=0,this.bg=0,this.extended=new zh}static toColorRGB(t){return[t>>>16&255,t>>>8&255,t&255]}static fromColorRGB(t){return(t[0]&255)<<16|(t[1]&255)<<8|t[2]&255}clone(){let t=new IC;return t.fg=this.fg,t.bg=this.bg,t.extended=this.extended.clone(),t}isInverse(){return this.fg&67108864}isBold(){return this.fg&134217728}isUnderline(){return this.hasExtendedAttrs()&&this.extended.underlineStyle!==0?1:this.fg&268435456}isBlink(){return this.fg&536870912}isInvisible(){return this.fg&1073741824}isItalic(){return this.bg&67108864}isDim(){return this.bg&134217728}isStrikethrough(){return this.fg&2147483648}isProtected(){return this.bg&536870912}isOverline(){return this.bg&1073741824}getFgColorMode(){return this.fg&50331648}getBgColorMode(){return this.bg&50331648}isFgRGB(){return(this.fg&50331648)===50331648}isBgRGB(){return(this.bg&50331648)===50331648}isFgPalette(){return(this.fg&50331648)===16777216||(this.fg&50331648)===33554432}isBgPalette(){return(this.bg&50331648)===16777216||(this.bg&50331648)===33554432}isFgDefault(){return(this.fg&50331648)===0}isBgDefault(){return(this.bg&50331648)===0}isAttributeDefault(){return this.fg===0&&this.bg===0}getFgColor(){switch(this.fg&50331648){case 16777216:case 33554432:return this.fg&255;case 50331648:return this.fg&16777215;default:return-1}}getBgColor(){switch(this.bg&50331648){case 16777216:case 33554432:return this.bg&255;case 50331648:return this.bg&16777215;default:return-1}}hasExtendedAttrs(){return this.bg&268435456}updateExtended(){this.extended.isEmpty()?this.bg&=-268435457:this.bg|=268435456}getUnderlineColor(){if(this.bg&268435456&&~this.extended.underlineColor)switch(this.extended.underlineColor&50331648){case 16777216:case 33554432:return this.extended.underlineColor&255;case 50331648:return this.extended.underlineColor&16777215;default:return this.getFgColor()}return this.getFgColor()}getUnderlineColorMode(){return this.bg&268435456&&~this.extended.underlineColor?this.extended.underlineColor&50331648:this.getFgColorMode()}isUnderlineColorRGB(){return this.bg&268435456&&~this.extended.underlineColor?(this.extended.underlineColor&50331648)===50331648:this.isFgRGB()}isUnderlineColorPalette(){return this.bg&268435456&&~this.extended.underlineColor?(this.extended.underlineColor&50331648)===16777216||(this.extended.underlineColor&50331648)===33554432:this.isFgPalette()}isUnderlineColorDefault(){return this.bg&268435456&&~this.extended.underlineColor?(this.extended.underlineColor&50331648)===0:this.isFgDefault()}getUnderlineStyle(){return this.fg&268435456?this.bg&268435456?this.extended.underlineStyle:1:0}getUnderlineVariantOffset(){return this.extended.underlineVariantOffset}},zh=class FC{constructor(t=0,s=0){this._ext=0,this._urlId=0,this._ext=t,this._urlId=s}get ext(){return this._urlId?this._ext&-469762049|this.underlineStyle<<26:this._ext}set ext(t){this._ext=t}get underlineStyle(){return this._urlId?5:(this._ext&469762048)>>26}set underlineStyle(t){this._ext&=-469762049,this._ext|=t<<26&469762048}get underlineColor(){return this._ext&67108863}set underlineColor(t){this._ext&=-67108864,this._ext|=t&67108863}get urlId(){return this._urlId}set urlId(t){this._urlId=t}get underlineVariantOffset(){let t=(this._ext&3758096384)>>29;return t<0?t^4294967288:t}set underlineVariantOffset(t){this._ext&=536870911,this._ext|=t<<29&3758096384}clone(){return new FC(this._ext,this._urlId)}isEmpty(){return this.underlineStyle===0&&this._urlId===0}},Jn=class HC extends pu{constructor(){super(...arguments),this.content=0,this.fg=0,this.bg=0,this.extended=new zh,this.combinedData=""}static fromCharData(t){let s=new HC;return s.setFromCharData(t),s}isCombined(){return this.content&2097152}getWidth(){return this.content>>22}getChars(){return this.content&2097152?this.combinedData:this.content&2097151?Fi(this.content&2097151):""}getCode(){return this.isCombined()?this.combinedData.charCodeAt(this.combinedData.length-1):this.content&2097151}setFromCharData(t){this.fg=t[0],this.bg=0;let s=!1;if(t[1].length>2)s=!0;else if(t[1].length===2){let n=t[1].charCodeAt(0);if(55296<=n&&n<=56319){let a=t[1].charCodeAt(1);56320<=a&&a<=57343?this.content=(n-55296)*1024+a-56320+65536|t[2]<<22:s=!0}else s=!0}else this.content=t[1].charCodeAt(0)|t[2]<<22;s&&(this.combinedData=t[1],this.content=2097152|t[2]<<22)}getAsCharData(){return[this.fg,this.getChars(),this.getWidth(),this.getCode()]}},m2="di$target",Bx="di$dependencies",_g=new Map;function G9(e){return e[Bx]||[]}function As(e){if(_g.has(e))return _g.get(e);let t=function(s,n,a){if(arguments.length!==3)throw new Error("@IServiceName-decorator can only be used to decorate a parameter");K9(t,s,a)};return t._id=e,_g.set(e,t),t}function K9(e,t,s){t[m2]===t?t[Bx].push({id:e,index:s}):(t[Bx]=[{id:e,index:s}],t[m2]=t)}var sn=As("BufferService"),UC=As("CoreMouseService"),Ba=As("CoreService"),Y9=As("CharsetService"),ov=As("InstantiationService"),VC=As("LogService"),nn=As("OptionsService"),WC=As("OscLinkService"),X9=As("UnicodeService"),mu=As("DecorationService"),Ox=class{constructor(e,t,s){this._bufferService=e,this._optionsService=t,this._oscLinkService=s}provideLinks(e,t){var m;let s=this._bufferService.buffer.lines.get(e-1);if(!s){t(void 0);return}let n=[],a=this._optionsService.rawOptions.linkHandler,l=new Jn,c=s.getTrimmedLength(),d=-1,f=-1,h=!1;for(let g=0;g<c;g++)if(!(f===-1&&!s.hasContent(g))){if(s.loadCell(g,l),l.hasExtendedAttrs()&&l.extended.urlId)if(f===-1){f=g,d=l.extended.urlId;continue}else h=l.extended.urlId!==d;else f!==-1&&(h=!0);if(h||f!==-1&&g===c-1){let b=(m=this._oscLinkService.getLinkData(d))==null?void 0:m.uri;if(b){let v={start:{x:f+1,y:e},end:{x:g+(!h&&g===c-1?1:0),y:e}},y=!1;if(!(a!=null&&a.allowNonHttpProtocols))try{let S=new URL(b);["http:","https:"].includes(S.protocol)||(y=!0)}catch{y=!0}y||n.push({text:b,range:v,activate:(S,j)=>a?a.activate(S,j,v):J9(S,j),hover:(S,j)=>{var k;return(k=a==null?void 0:a.hover)==null?void 0:k.call(a,S,j,v)},leave:(S,j)=>{var k;return(k=a==null?void 0:a.leave)==null?void 0:k.call(a,S,j,v)}})}h=!1,l.hasExtendedAttrs()&&l.extended.urlId?(f=g,d=l.extended.urlId):(f=-1,d=-1)}}t(n)}};Ox=ts([Re(0,sn),Re(1,nn),Re(2,WC)],Ox);function J9(e,t){if(confirm(`Do you want to navigate to ${t}?
|
|
245
245
|
|
|
246
|
-
WARNING: This link could potentially be dangerous`)){let s=window.open();if(s){try{s.opener=null}catch{}s.location.href=t}else console.warn("Opening link blocked as opener could not be cleared")}}var sf=As("CharSizeService"),ai=As("CoreBrowserService"),lv=As("MouseService"),oi=As("RenderService"),
|
|
246
|
+
WARNING: This link could potentially be dangerous`)){let s=window.open();if(s){try{s.opener=null}catch{}s.location.href=t}else console.warn("Opening link blocked as opener could not be cleared")}}var sf=As("CharSizeService"),ai=As("CoreBrowserService"),lv=As("MouseService"),oi=As("RenderService"),Q9=As("SelectionService"),qC=As("CharacterJoinerService"),tl=As("ThemeService"),GC=As("LinkProviderService"),Z9=class{constructor(){this.listeners=[],this.unexpectedErrorHandler=function(e){setTimeout(()=>{throw e.stack?g2.isErrorNoTelemetry(e)?new g2(e.message+`
|
|
247
247
|
|
|
248
248
|
`+e.stack):new Error(e.message+`
|
|
249
249
|
|
|
250
|
-
`+e.stack):e},0)}}addListener(e){return this.listeners.push(e),()=>{this._removeListener(e)}}emit(e){this.listeners.forEach(t=>{t(e)})}_removeListener(e){this.listeners.splice(this.listeners.indexOf(e),1)}setUnexpectedErrorHandler(e){this.unexpectedErrorHandler=e}getUnexpectedErrorHandler(){return this.unexpectedErrorHandler}onUnexpectedError(e){this.unexpectedErrorHandler(e),this.emit(e)}onUnexpectedExternalError(e){this.unexpectedErrorHandler(e)}},Z9=new Q9;function lh(e){e$(e)||Z9.onUnexpectedError(e)}var zx="Canceled";function e$(e){return e instanceof t$?!0:e instanceof Error&&e.name===zx&&e.message===zx}var t$=class extends Error{constructor(){super(zx),this.name=this.message}};function s$(e){return new Error(`Illegal argument: ${e}`)}var g2=class Px extends Error{constructor(t){super(t),this.name="CodeExpectedError"}static fromError(t){if(t instanceof Px)return t;let s=new Px;return s.message=t.message,s.stack=t.stack,s}static isErrorNoTelemetry(t){return t.name==="CodeExpectedError"}},$x=class KC extends Error{constructor(t){super(t||"An unexpected bug occurred."),Object.setPrototypeOf(this,KC.prototype)}};function Nn(e,t=0){return e[e.length-(1+t)]}var n$;(e=>{function t(l){return l<0}e.isLessThan=t;function s(l){return l<=0}e.isLessThanOrEqual=s;function n(l){return l>0}e.isGreaterThan=n;function a(l){return l===0}e.isNeitherLessOrGreaterThan=a,e.greaterThan=1,e.lessThan=-1,e.neitherLessOrGreaterThan=0})(n$||(n$={}));function r$(e,t){let s=this,n=!1,a;return function(){return n||(n=!0,t||(a=e.apply(s,arguments))),a}}var YC;(e=>{function t(B){return B&&typeof B=="object"&&typeof B[Symbol.iterator]=="function"}e.is=t;let s=Object.freeze([]);function n(){return s}e.empty=n;function*a(B){yield B}e.single=a;function l(B){return t(B)?B:a(B)}e.wrap=l;function c(B){return B||s}e.from=c;function*d(B){for(let A=B.length-1;A>=0;A--)yield B[A]}e.reverse=d;function f(B){return!B||B[Symbol.iterator]().next().done===!0}e.isEmpty=f;function h(B){return B[Symbol.iterator]().next().value}e.first=h;function m(B,A){let P=0;for(let K of B)if(A(K,P++))return!0;return!1}e.some=m;function g(B,A){for(let P of B)if(A(P))return P}e.find=g;function*b(B,A){for(let P of B)A(P)&&(yield P)}e.filter=b;function*v(B,A){let P=0;for(let K of B)yield A(K,P++)}e.map=v;function*y(B,A){let P=0;for(let K of B)yield*A(K,P++)}e.flatMap=y;function*S(...B){for(let A of B)yield*A}e.concat=S;function j(B,A,P){let K=P;for(let X of B)K=A(K,X);return K}e.reduce=j;function*k(B,A,P=B.length){for(A<0&&(A+=B.length),P<0?P+=B.length:P>B.length&&(P=B.length);A<P;A++)yield B[A]}e.slice=k;function E(B,A=Number.POSITIVE_INFINITY){let P=[];if(A===0)return[P,B];let K=B[Symbol.iterator]();for(let X=0;X<A;X++){let Z=K.next();if(Z.done)return[P,e.empty()];P.push(Z.value)}return[P,{[Symbol.iterator](){return K}}]}e.consume=E;async function N(B){let A=[];for await(let P of B)A.push(P);return Promise.resolve(A)}e.asyncToArray=N})(YC||(YC={}));function Ra(e){if(YC.is(e)){let t=[];for(let s of e)if(s)try{s.dispose()}catch(n){t.push(n)}if(t.length===1)throw t[0];if(t.length>1)throw new AggregateError(t,"Encountered errors while disposing of store");return Array.isArray(e)?[]:e}else if(e)return e.dispose(),e}function i$(...e){return Ut(()=>Ra(e))}function Ut(e){return{dispose:r$(()=>{e()})}}var XC=class JC{constructor(){this._toDispose=new Set,this._isDisposed=!1}dispose(){this._isDisposed||(this._isDisposed=!0,this.clear())}get isDisposed(){return this._isDisposed}clear(){if(this._toDispose.size!==0)try{Ra(this._toDispose)}finally{this._toDispose.clear()}}add(t){if(!t)return t;if(t===this)throw new Error("Cannot register a disposable on itself!");return this._isDisposed?JC.DISABLE_DISPOSED_WARNING||console.warn(new Error("Trying to add a disposable to a DisposableStore that has already been disposed of. The added object will be leaked!").stack):this._toDispose.add(t),t}delete(t){if(t){if(t===this)throw new Error("Cannot dispose a disposable on itself!");this._toDispose.delete(t),t.dispose()}}deleteAndLeak(t){t&&this._toDispose.has(t)&&(this._toDispose.delete(t),void 0)}};XC.DISABLE_DISPOSED_WARNING=!1;var Yi=XC,nt=class{constructor(){this._store=new Yi,this._store}dispose(){this._store.dispose()}_register(e){if(e===this)throw new Error("Cannot register a disposable on itself!");return this._store.add(e)}};nt.None=Object.freeze({dispose(){}});var Yo=class{constructor(){this._isDisposed=!1}get value(){return this._isDisposed?void 0:this._value}set value(e){var t;this._isDisposed||e===this._value||((t=this._value)==null||t.dispose(),this._value=e)}clear(){this.value=void 0}dispose(){var e;this._isDisposed=!0,(e=this._value)==null||e.dispose(),this._value=void 0}clearAndLeak(){let e=this._value;return this._value=void 0,e}},ti=typeof window=="object"?window:globalThis,Ix=class Fx{constructor(t){this.element=t,this.next=Fx.Undefined,this.prev=Fx.Undefined}};Ix.Undefined=new Ix(void 0);var Vt=Ix,x2=class{constructor(){this._first=Vt.Undefined,this._last=Vt.Undefined,this._size=0}get size(){return this._size}isEmpty(){return this._first===Vt.Undefined}clear(){let e=this._first;for(;e!==Vt.Undefined;){let t=e.next;e.prev=Vt.Undefined,e.next=Vt.Undefined,e=t}this._first=Vt.Undefined,this._last=Vt.Undefined,this._size=0}unshift(e){return this._insert(e,!1)}push(e){return this._insert(e,!0)}_insert(e,t){let s=new Vt(e);if(this._first===Vt.Undefined)this._first=s,this._last=s;else if(t){let a=this._last;this._last=s,s.prev=a,a.next=s}else{let a=this._first;this._first=s,s.next=a,a.prev=s}this._size+=1;let n=!1;return()=>{n||(n=!0,this._remove(s))}}shift(){if(this._first!==Vt.Undefined){let e=this._first.element;return this._remove(this._first),e}}pop(){if(this._last!==Vt.Undefined){let e=this._last.element;return this._remove(this._last),e}}_remove(e){if(e.prev!==Vt.Undefined&&e.next!==Vt.Undefined){let t=e.prev;t.next=e.next,e.next.prev=t}else e.prev===Vt.Undefined&&e.next===Vt.Undefined?(this._first=Vt.Undefined,this._last=Vt.Undefined):e.next===Vt.Undefined?(this._last=this._last.prev,this._last.next=Vt.Undefined):e.prev===Vt.Undefined&&(this._first=this._first.next,this._first.prev=Vt.Undefined);this._size-=1}*[Symbol.iterator](){let e=this._first;for(;e!==Vt.Undefined;)yield e.element,e=e.next}},a$=globalThis.performance&&typeof globalThis.performance.now=="function",o$=class QC{static create(t){return new QC(t)}constructor(t){this._now=a$&&t===!1?Date.now:globalThis.performance.now.bind(globalThis.performance),this._startTime=this._now(),this._stopTime=-1}stop(){this._stopTime=this._now()}reset(){this._startTime=this._now(),this._stopTime=-1}elapsed(){return this._stopTime!==-1?this._stopTime-this._startTime:this._now()-this._startTime}},Is;(e=>{e.None=()=>nt.None;function t(F,G){return g(F,()=>{},0,void 0,!0,void 0,G)}e.defer=t;function s(F){return(G,q=null,R)=>{let M=!1,O;return O=F(W=>{if(!M)return O?O.dispose():M=!0,G.call(q,W)},null,R),M&&O.dispose(),O}}e.once=s;function n(F,G,q){return h((R,M=null,O)=>F(W=>R.call(M,G(W)),null,O),q)}e.map=n;function a(F,G,q){return h((R,M=null,O)=>F(W=>{G(W),R.call(M,W)},null,O),q)}e.forEach=a;function l(F,G,q){return h((R,M=null,O)=>F(W=>G(W)&&R.call(M,W),null,O),q)}e.filter=l;function c(F){return F}e.signal=c;function d(...F){return(G,q=null,R)=>{let M=i$(...F.map(O=>O(W=>G.call(q,W))));return m(M,R)}}e.any=d;function f(F,G,q,R){let M=q;return n(F,O=>(M=G(M,O),M),R)}e.reduce=f;function h(F,G){let q,R={onWillAddFirstListener(){q=F(M.fire,M)},onDidRemoveLastListener(){q==null||q.dispose()}},M=new Ce(R);return G==null||G.add(M),M.event}function m(F,G){return G instanceof Array?G.push(F):G&&G.add(F),F}function g(F,G,q=100,R=!1,M=!1,O,W){let U,D,$,z=0,T,ae={leakWarningThreshold:O,onWillAddFirstListener(){U=F(ne=>{z++,D=G(D,ne),R&&!$&&(be.fire(D),D=void 0),T=()=>{let ve=D;D=void 0,$=void 0,(!R||z>1)&&be.fire(ve),z=0},typeof q=="number"?(clearTimeout($),$=setTimeout(T,q)):$===void 0&&($=0,queueMicrotask(T))})},onWillRemoveListener(){M&&z>0&&(T==null||T())},onDidRemoveLastListener(){T=void 0,U.dispose()}},be=new Ce(ae);return W==null||W.add(be),be.event}e.debounce=g;function b(F,G=0,q){return e.debounce(F,(R,M)=>R?(R.push(M),R):[M],G,void 0,!0,void 0,q)}e.accumulate=b;function v(F,G=(R,M)=>R===M,q){let R=!0,M;return l(F,O=>{let W=R||!G(O,M);return R=!1,M=O,W},q)}e.latch=v;function y(F,G,q){return[e.filter(F,G,q),e.filter(F,R=>!G(R),q)]}e.split=y;function S(F,G=!1,q=[],R){let M=q.slice(),O=F(D=>{M?M.push(D):U.fire(D)});R&&R.add(O);let W=()=>{M==null||M.forEach(D=>U.fire(D)),M=null},U=new Ce({onWillAddFirstListener(){O||(O=F(D=>U.fire(D)),R&&R.add(O))},onDidAddFirstListener(){M&&(G?setTimeout(W):W())},onDidRemoveLastListener(){O&&O.dispose(),O=null}});return R&&R.add(U),U.event}e.buffer=S;function j(F,G){return(q,R,M)=>{let O=G(new E);return F(function(W){let U=O.evaluate(W);U!==k&&q.call(R,U)},void 0,M)}}e.chain=j;let k=Symbol("HaltChainable");class E{constructor(){this.steps=[]}map(G){return this.steps.push(G),this}forEach(G){return this.steps.push(q=>(G(q),q)),this}filter(G){return this.steps.push(q=>G(q)?q:k),this}reduce(G,q){let R=q;return this.steps.push(M=>(R=G(R,M),R)),this}latch(G=(q,R)=>q===R){let q=!0,R;return this.steps.push(M=>{let O=q||!G(M,R);return q=!1,R=M,O?M:k}),this}evaluate(G){for(let q of this.steps)if(G=q(G),G===k)break;return G}}function N(F,G,q=R=>R){let R=(...U)=>W.fire(q(...U)),M=()=>F.on(G,R),O=()=>F.removeListener(G,R),W=new Ce({onWillAddFirstListener:M,onDidRemoveLastListener:O});return W.event}e.fromNodeEventEmitter=N;function B(F,G,q=R=>R){let R=(...U)=>W.fire(q(...U)),M=()=>F.addEventListener(G,R),O=()=>F.removeEventListener(G,R),W=new Ce({onWillAddFirstListener:M,onDidRemoveLastListener:O});return W.event}e.fromDOMEventEmitter=B;function A(F){return new Promise(G=>s(F)(G))}e.toPromise=A;function P(F){let G=new Ce;return F.then(q=>{G.fire(q)},()=>{G.fire(void 0)}).finally(()=>{G.dispose()}),G.event}e.fromPromise=P;function K(F,G){return F(q=>G.fire(q))}e.forward=K;function X(F,G,q){return G(q),F(R=>G(R))}e.runAndSubscribe=X;class Z{constructor(G,q){this._observable=G,this._counter=0,this._hasChanged=!1;let R={onWillAddFirstListener:()=>{G.addObserver(this)},onDidRemoveLastListener:()=>{G.removeObserver(this)}};this.emitter=new Ce(R),q&&q.add(this.emitter)}beginUpdate(G){this._counter++}handlePossibleChange(G){}handleChange(G,q){this._hasChanged=!0}endUpdate(G){this._counter--,this._counter===0&&(this._observable.reportChanges(),this._hasChanged&&(this._hasChanged=!1,this.emitter.fire(this._observable.get())))}}function I(F,G){return new Z(F,G).emitter.event}e.fromObservable=I;function H(F){return(G,q,R)=>{let M=0,O=!1,W={beginUpdate(){M++},endUpdate(){M--,M===0&&(F.reportChanges(),O&&(O=!1,G.call(q)))},handlePossibleChange(){},handleChange(){O=!0}};F.addObserver(W),F.reportChanges();let U={dispose(){F.removeObserver(W)}};return R instanceof Yi?R.add(U):Array.isArray(R)&&R.push(U),U}}e.fromObservableLight=H})(Is||(Is={}));var Hx=class Ux{constructor(t){this.listenerCount=0,this.invocationCount=0,this.elapsedOverall=0,this.durations=[],this.name=`${t}_${Ux._idPool++}`,Ux.all.add(this)}start(t){this._stopWatch=new o$,this.listenerCount=t}stop(){if(this._stopWatch){let t=this._stopWatch.elapsed();this.durations.push(t),this.elapsedOverall+=t,this.invocationCount+=1,this._stopWatch=void 0}}};Hx.all=new Set,Hx._idPool=0;var l$=Hx,c$=-1,ZC=class eN{constructor(t,s,n=(eN._idPool++).toString(16).padStart(3,"0")){this._errorHandler=t,this.threshold=s,this.name=n,this._warnCountdown=0}dispose(){var t;(t=this._stacks)==null||t.clear()}check(t,s){let n=this.threshold;if(n<=0||s<n)return;this._stacks||(this._stacks=new Map);let a=this._stacks.get(t.value)||0;if(this._stacks.set(t.value,a+1),this._warnCountdown-=1,this._warnCountdown<=0){this._warnCountdown=n*.5;let[l,c]=this.getMostFrequentStack(),d=`[${this.name}] potential listener LEAK detected, having ${s} listeners already. MOST frequent listener (${c}):`;console.warn(d),console.warn(l);let f=new h$(d,l);this._errorHandler(f)}return()=>{let l=this._stacks.get(t.value)||0;this._stacks.set(t.value,l-1)}}getMostFrequentStack(){if(!this._stacks)return;let t,s=0;for(let[n,a]of this._stacks)(!t||s<a)&&(t=[n,a],s=a);return t}};ZC._idPool=1;var u$=ZC,d$=class tN{constructor(t){this.value=t}static create(){let t=new Error;return new tN(t.stack??"")}print(){console.warn(this.value.split(`
|
|
250
|
+
`+e.stack):e},0)}}addListener(e){return this.listeners.push(e),()=>{this._removeListener(e)}}emit(e){this.listeners.forEach(t=>{t(e)})}_removeListener(e){this.listeners.splice(this.listeners.indexOf(e),1)}setUnexpectedErrorHandler(e){this.unexpectedErrorHandler=e}getUnexpectedErrorHandler(){return this.unexpectedErrorHandler}onUnexpectedError(e){this.unexpectedErrorHandler(e),this.emit(e)}onUnexpectedExternalError(e){this.unexpectedErrorHandler(e)}},e$=new Z9;function lh(e){t$(e)||e$.onUnexpectedError(e)}var zx="Canceled";function t$(e){return e instanceof s$?!0:e instanceof Error&&e.name===zx&&e.message===zx}var s$=class extends Error{constructor(){super(zx),this.name=this.message}};function n$(e){return new Error(`Illegal argument: ${e}`)}var g2=class Px extends Error{constructor(t){super(t),this.name="CodeExpectedError"}static fromError(t){if(t instanceof Px)return t;let s=new Px;return s.message=t.message,s.stack=t.stack,s}static isErrorNoTelemetry(t){return t.name==="CodeExpectedError"}},$x=class KC extends Error{constructor(t){super(t||"An unexpected bug occurred."),Object.setPrototypeOf(this,KC.prototype)}};function Nn(e,t=0){return e[e.length-(1+t)]}var r$;(e=>{function t(l){return l<0}e.isLessThan=t;function s(l){return l<=0}e.isLessThanOrEqual=s;function n(l){return l>0}e.isGreaterThan=n;function a(l){return l===0}e.isNeitherLessOrGreaterThan=a,e.greaterThan=1,e.lessThan=-1,e.neitherLessOrGreaterThan=0})(r$||(r$={}));function i$(e,t){let s=this,n=!1,a;return function(){return n||(n=!0,t||(a=e.apply(s,arguments))),a}}var YC;(e=>{function t(B){return B&&typeof B=="object"&&typeof B[Symbol.iterator]=="function"}e.is=t;let s=Object.freeze([]);function n(){return s}e.empty=n;function*a(B){yield B}e.single=a;function l(B){return t(B)?B:a(B)}e.wrap=l;function c(B){return B||s}e.from=c;function*d(B){for(let A=B.length-1;A>=0;A--)yield B[A]}e.reverse=d;function f(B){return!B||B[Symbol.iterator]().next().done===!0}e.isEmpty=f;function h(B){return B[Symbol.iterator]().next().value}e.first=h;function m(B,A){let P=0;for(let K of B)if(A(K,P++))return!0;return!1}e.some=m;function g(B,A){for(let P of B)if(A(P))return P}e.find=g;function*b(B,A){for(let P of B)A(P)&&(yield P)}e.filter=b;function*v(B,A){let P=0;for(let K of B)yield A(K,P++)}e.map=v;function*y(B,A){let P=0;for(let K of B)yield*A(K,P++)}e.flatMap=y;function*S(...B){for(let A of B)yield*A}e.concat=S;function j(B,A,P){let K=P;for(let X of B)K=A(K,X);return K}e.reduce=j;function*k(B,A,P=B.length){for(A<0&&(A+=B.length),P<0?P+=B.length:P>B.length&&(P=B.length);A<P;A++)yield B[A]}e.slice=k;function E(B,A=Number.POSITIVE_INFINITY){let P=[];if(A===0)return[P,B];let K=B[Symbol.iterator]();for(let X=0;X<A;X++){let Z=K.next();if(Z.done)return[P,e.empty()];P.push(Z.value)}return[P,{[Symbol.iterator](){return K}}]}e.consume=E;async function N(B){let A=[];for await(let P of B)A.push(P);return Promise.resolve(A)}e.asyncToArray=N})(YC||(YC={}));function Ra(e){if(YC.is(e)){let t=[];for(let s of e)if(s)try{s.dispose()}catch(n){t.push(n)}if(t.length===1)throw t[0];if(t.length>1)throw new AggregateError(t,"Encountered errors while disposing of store");return Array.isArray(e)?[]:e}else if(e)return e.dispose(),e}function a$(...e){return Ut(()=>Ra(e))}function Ut(e){return{dispose:i$(()=>{e()})}}var XC=class JC{constructor(){this._toDispose=new Set,this._isDisposed=!1}dispose(){this._isDisposed||(this._isDisposed=!0,this.clear())}get isDisposed(){return this._isDisposed}clear(){if(this._toDispose.size!==0)try{Ra(this._toDispose)}finally{this._toDispose.clear()}}add(t){if(!t)return t;if(t===this)throw new Error("Cannot register a disposable on itself!");return this._isDisposed?JC.DISABLE_DISPOSED_WARNING||console.warn(new Error("Trying to add a disposable to a DisposableStore that has already been disposed of. The added object will be leaked!").stack):this._toDispose.add(t),t}delete(t){if(t){if(t===this)throw new Error("Cannot dispose a disposable on itself!");this._toDispose.delete(t),t.dispose()}}deleteAndLeak(t){t&&this._toDispose.has(t)&&(this._toDispose.delete(t),void 0)}};XC.DISABLE_DISPOSED_WARNING=!1;var Yi=XC,nt=class{constructor(){this._store=new Yi,this._store}dispose(){this._store.dispose()}_register(e){if(e===this)throw new Error("Cannot register a disposable on itself!");return this._store.add(e)}};nt.None=Object.freeze({dispose(){}});var Yo=class{constructor(){this._isDisposed=!1}get value(){return this._isDisposed?void 0:this._value}set value(e){var t;this._isDisposed||e===this._value||((t=this._value)==null||t.dispose(),this._value=e)}clear(){this.value=void 0}dispose(){var e;this._isDisposed=!0,(e=this._value)==null||e.dispose(),this._value=void 0}clearAndLeak(){let e=this._value;return this._value=void 0,e}},ti=typeof window=="object"?window:globalThis,Ix=class Fx{constructor(t){this.element=t,this.next=Fx.Undefined,this.prev=Fx.Undefined}};Ix.Undefined=new Ix(void 0);var Vt=Ix,x2=class{constructor(){this._first=Vt.Undefined,this._last=Vt.Undefined,this._size=0}get size(){return this._size}isEmpty(){return this._first===Vt.Undefined}clear(){let e=this._first;for(;e!==Vt.Undefined;){let t=e.next;e.prev=Vt.Undefined,e.next=Vt.Undefined,e=t}this._first=Vt.Undefined,this._last=Vt.Undefined,this._size=0}unshift(e){return this._insert(e,!1)}push(e){return this._insert(e,!0)}_insert(e,t){let s=new Vt(e);if(this._first===Vt.Undefined)this._first=s,this._last=s;else if(t){let a=this._last;this._last=s,s.prev=a,a.next=s}else{let a=this._first;this._first=s,s.next=a,a.prev=s}this._size+=1;let n=!1;return()=>{n||(n=!0,this._remove(s))}}shift(){if(this._first!==Vt.Undefined){let e=this._first.element;return this._remove(this._first),e}}pop(){if(this._last!==Vt.Undefined){let e=this._last.element;return this._remove(this._last),e}}_remove(e){if(e.prev!==Vt.Undefined&&e.next!==Vt.Undefined){let t=e.prev;t.next=e.next,e.next.prev=t}else e.prev===Vt.Undefined&&e.next===Vt.Undefined?(this._first=Vt.Undefined,this._last=Vt.Undefined):e.next===Vt.Undefined?(this._last=this._last.prev,this._last.next=Vt.Undefined):e.prev===Vt.Undefined&&(this._first=this._first.next,this._first.prev=Vt.Undefined);this._size-=1}*[Symbol.iterator](){let e=this._first;for(;e!==Vt.Undefined;)yield e.element,e=e.next}},o$=globalThis.performance&&typeof globalThis.performance.now=="function",l$=class QC{static create(t){return new QC(t)}constructor(t){this._now=o$&&t===!1?Date.now:globalThis.performance.now.bind(globalThis.performance),this._startTime=this._now(),this._stopTime=-1}stop(){this._stopTime=this._now()}reset(){this._startTime=this._now(),this._stopTime=-1}elapsed(){return this._stopTime!==-1?this._stopTime-this._startTime:this._now()-this._startTime}},Is;(e=>{e.None=()=>nt.None;function t(F,G){return g(F,()=>{},0,void 0,!0,void 0,G)}e.defer=t;function s(F){return(G,q=null,R)=>{let M=!1,O;return O=F(W=>{if(!M)return O?O.dispose():M=!0,G.call(q,W)},null,R),M&&O.dispose(),O}}e.once=s;function n(F,G,q){return h((R,M=null,O)=>F(W=>R.call(M,G(W)),null,O),q)}e.map=n;function a(F,G,q){return h((R,M=null,O)=>F(W=>{G(W),R.call(M,W)},null,O),q)}e.forEach=a;function l(F,G,q){return h((R,M=null,O)=>F(W=>G(W)&&R.call(M,W),null,O),q)}e.filter=l;function c(F){return F}e.signal=c;function d(...F){return(G,q=null,R)=>{let M=a$(...F.map(O=>O(W=>G.call(q,W))));return m(M,R)}}e.any=d;function f(F,G,q,R){let M=q;return n(F,O=>(M=G(M,O),M),R)}e.reduce=f;function h(F,G){let q,R={onWillAddFirstListener(){q=F(M.fire,M)},onDidRemoveLastListener(){q==null||q.dispose()}},M=new Ce(R);return G==null||G.add(M),M.event}function m(F,G){return G instanceof Array?G.push(F):G&&G.add(F),F}function g(F,G,q=100,R=!1,M=!1,O,W){let U,D,$,z=0,T,ae={leakWarningThreshold:O,onWillAddFirstListener(){U=F(ne=>{z++,D=G(D,ne),R&&!$&&(be.fire(D),D=void 0),T=()=>{let ve=D;D=void 0,$=void 0,(!R||z>1)&&be.fire(ve),z=0},typeof q=="number"?(clearTimeout($),$=setTimeout(T,q)):$===void 0&&($=0,queueMicrotask(T))})},onWillRemoveListener(){M&&z>0&&(T==null||T())},onDidRemoveLastListener(){T=void 0,U.dispose()}},be=new Ce(ae);return W==null||W.add(be),be.event}e.debounce=g;function b(F,G=0,q){return e.debounce(F,(R,M)=>R?(R.push(M),R):[M],G,void 0,!0,void 0,q)}e.accumulate=b;function v(F,G=(R,M)=>R===M,q){let R=!0,M;return l(F,O=>{let W=R||!G(O,M);return R=!1,M=O,W},q)}e.latch=v;function y(F,G,q){return[e.filter(F,G,q),e.filter(F,R=>!G(R),q)]}e.split=y;function S(F,G=!1,q=[],R){let M=q.slice(),O=F(D=>{M?M.push(D):U.fire(D)});R&&R.add(O);let W=()=>{M==null||M.forEach(D=>U.fire(D)),M=null},U=new Ce({onWillAddFirstListener(){O||(O=F(D=>U.fire(D)),R&&R.add(O))},onDidAddFirstListener(){M&&(G?setTimeout(W):W())},onDidRemoveLastListener(){O&&O.dispose(),O=null}});return R&&R.add(U),U.event}e.buffer=S;function j(F,G){return(q,R,M)=>{let O=G(new E);return F(function(W){let U=O.evaluate(W);U!==k&&q.call(R,U)},void 0,M)}}e.chain=j;let k=Symbol("HaltChainable");class E{constructor(){this.steps=[]}map(G){return this.steps.push(G),this}forEach(G){return this.steps.push(q=>(G(q),q)),this}filter(G){return this.steps.push(q=>G(q)?q:k),this}reduce(G,q){let R=q;return this.steps.push(M=>(R=G(R,M),R)),this}latch(G=(q,R)=>q===R){let q=!0,R;return this.steps.push(M=>{let O=q||!G(M,R);return q=!1,R=M,O?M:k}),this}evaluate(G){for(let q of this.steps)if(G=q(G),G===k)break;return G}}function N(F,G,q=R=>R){let R=(...U)=>W.fire(q(...U)),M=()=>F.on(G,R),O=()=>F.removeListener(G,R),W=new Ce({onWillAddFirstListener:M,onDidRemoveLastListener:O});return W.event}e.fromNodeEventEmitter=N;function B(F,G,q=R=>R){let R=(...U)=>W.fire(q(...U)),M=()=>F.addEventListener(G,R),O=()=>F.removeEventListener(G,R),W=new Ce({onWillAddFirstListener:M,onDidRemoveLastListener:O});return W.event}e.fromDOMEventEmitter=B;function A(F){return new Promise(G=>s(F)(G))}e.toPromise=A;function P(F){let G=new Ce;return F.then(q=>{G.fire(q)},()=>{G.fire(void 0)}).finally(()=>{G.dispose()}),G.event}e.fromPromise=P;function K(F,G){return F(q=>G.fire(q))}e.forward=K;function X(F,G,q){return G(q),F(R=>G(R))}e.runAndSubscribe=X;class Z{constructor(G,q){this._observable=G,this._counter=0,this._hasChanged=!1;let R={onWillAddFirstListener:()=>{G.addObserver(this)},onDidRemoveLastListener:()=>{G.removeObserver(this)}};this.emitter=new Ce(R),q&&q.add(this.emitter)}beginUpdate(G){this._counter++}handlePossibleChange(G){}handleChange(G,q){this._hasChanged=!0}endUpdate(G){this._counter--,this._counter===0&&(this._observable.reportChanges(),this._hasChanged&&(this._hasChanged=!1,this.emitter.fire(this._observable.get())))}}function I(F,G){return new Z(F,G).emitter.event}e.fromObservable=I;function H(F){return(G,q,R)=>{let M=0,O=!1,W={beginUpdate(){M++},endUpdate(){M--,M===0&&(F.reportChanges(),O&&(O=!1,G.call(q)))},handlePossibleChange(){},handleChange(){O=!0}};F.addObserver(W),F.reportChanges();let U={dispose(){F.removeObserver(W)}};return R instanceof Yi?R.add(U):Array.isArray(R)&&R.push(U),U}}e.fromObservableLight=H})(Is||(Is={}));var Hx=class Ux{constructor(t){this.listenerCount=0,this.invocationCount=0,this.elapsedOverall=0,this.durations=[],this.name=`${t}_${Ux._idPool++}`,Ux.all.add(this)}start(t){this._stopWatch=new l$,this.listenerCount=t}stop(){if(this._stopWatch){let t=this._stopWatch.elapsed();this.durations.push(t),this.elapsedOverall+=t,this.invocationCount+=1,this._stopWatch=void 0}}};Hx.all=new Set,Hx._idPool=0;var c$=Hx,u$=-1,ZC=class eN{constructor(t,s,n=(eN._idPool++).toString(16).padStart(3,"0")){this._errorHandler=t,this.threshold=s,this.name=n,this._warnCountdown=0}dispose(){var t;(t=this._stacks)==null||t.clear()}check(t,s){let n=this.threshold;if(n<=0||s<n)return;this._stacks||(this._stacks=new Map);let a=this._stacks.get(t.value)||0;if(this._stacks.set(t.value,a+1),this._warnCountdown-=1,this._warnCountdown<=0){this._warnCountdown=n*.5;let[l,c]=this.getMostFrequentStack(),d=`[${this.name}] potential listener LEAK detected, having ${s} listeners already. MOST frequent listener (${c}):`;console.warn(d),console.warn(l);let f=new f$(d,l);this._errorHandler(f)}return()=>{let l=this._stacks.get(t.value)||0;this._stacks.set(t.value,l-1)}}getMostFrequentStack(){if(!this._stacks)return;let t,s=0;for(let[n,a]of this._stacks)(!t||s<a)&&(t=[n,a],s=a);return t}};ZC._idPool=1;var d$=ZC,h$=class tN{constructor(t){this.value=t}static create(){let t=new Error;return new tN(t.stack??"")}print(){console.warn(this.value.split(`
|
|
251
251
|
`).slice(2).join(`
|
|
252
|
-
`))}},h$=class extends Error{constructor(e,t){super(e),this.name="ListenerLeakError",this.stack=t}},f$=class extends Error{constructor(e,t){super(e),this.name="ListenerRefusalError",this.stack=t}},p$=0,yg=class{constructor(e){this.value=e,this.id=p$++}},m$=2,g$,Ce=class{constructor(e){var t,s,n,a;this._size=0,this._options=e,this._leakageMon=(t=this._options)!=null&&t.leakWarningThreshold?new u$((e==null?void 0:e.onListenerError)??lh,((s=this._options)==null?void 0:s.leakWarningThreshold)??c$):void 0,this._perfMon=(n=this._options)!=null&&n._profName?new l$(this._options._profName):void 0,this._deliveryQueue=(a=this._options)==null?void 0:a.deliveryQueue}dispose(){var e,t,s,n;this._disposed||(this._disposed=!0,((e=this._deliveryQueue)==null?void 0:e.current)===this&&this._deliveryQueue.reset(),this._listeners&&(this._listeners=void 0,this._size=0),(s=(t=this._options)==null?void 0:t.onDidRemoveLastListener)==null||s.call(t),(n=this._leakageMon)==null||n.dispose())}get event(){return this._event??(this._event=(e,t,s)=>{var c,d,f,h,m;if(this._leakageMon&&this._size>this._leakageMon.threshold**2){let g=`[${this._leakageMon.name}] REFUSES to accept new listeners because it exceeded its threshold by far (${this._size} vs ${this._leakageMon.threshold})`;console.warn(g);let b=this._leakageMon.getMostFrequentStack()??["UNKNOWN stack",-1],v=new f$(`${g}. HINT: Stack shows most frequent listener (${b[1]}-times)`,b[0]);return(((c=this._options)==null?void 0:c.onListenerError)||lh)(v),nt.None}if(this._disposed)return nt.None;t&&(e=e.bind(t));let n=new yg(e),a;this._leakageMon&&this._size>=Math.ceil(this._leakageMon.threshold*.2)&&(n.stack=d$.create(),a=this._leakageMon.check(n.stack,this._size+1)),this._listeners?this._listeners instanceof yg?(this._deliveryQueue??(this._deliveryQueue=new x$),this._listeners=[this._listeners,n]):this._listeners.push(n):((f=(d=this._options)==null?void 0:d.onWillAddFirstListener)==null||f.call(d,this),this._listeners=n,(m=(h=this._options)==null?void 0:h.onDidAddFirstListener)==null||m.call(h,this)),this._size++;let l=Ut(()=>{a==null||a(),this._removeListener(n)});return s instanceof Yi?s.add(l):Array.isArray(s)&&s.push(l),l}),this._event}_removeListener(e){var a,l,c,d;if((l=(a=this._options)==null?void 0:a.onWillRemoveListener)==null||l.call(a,this),!this._listeners)return;if(this._size===1){this._listeners=void 0,(d=(c=this._options)==null?void 0:c.onDidRemoveLastListener)==null||d.call(c,this),this._size=0;return}let t=this._listeners,s=t.indexOf(e);if(s===-1)throw console.log("disposed?",this._disposed),console.log("size?",this._size),console.log("arr?",JSON.stringify(this._listeners)),new Error("Attempted to dispose unknown listener");this._size--,t[s]=void 0;let n=this._deliveryQueue.current===this;if(this._size*m$<=t.length){let f=0;for(let h=0;h<t.length;h++)t[h]?t[f++]=t[h]:n&&(this._deliveryQueue.end--,f<this._deliveryQueue.i&&this._deliveryQueue.i--);t.length=f}}_deliver(e,t){var n;if(!e)return;let s=((n=this._options)==null?void 0:n.onListenerError)||lh;if(!s){e.value(t);return}try{e.value(t)}catch(a){s(a)}}_deliverQueue(e){let t=e.current._listeners;for(;e.i<e.end;)this._deliver(t[e.i++],e.value);e.reset()}fire(e){var t,s,n,a;if((t=this._deliveryQueue)!=null&&t.current&&(this._deliverQueue(this._deliveryQueue),(s=this._perfMon)==null||s.stop()),(n=this._perfMon)==null||n.start(this._size),this._listeners)if(this._listeners instanceof yg)this._deliver(this._listeners,e);else{let l=this._deliveryQueue;l.enqueue(this,e,this._listeners.length),this._deliverQueue(l)}(a=this._perfMon)==null||a.stop()}hasListeners(){return this._size>0}},x$=class{constructor(){this.i=-1,this.end=0}enqueue(e,t,s){this.i=0,this.end=s,this.current=e,this.value=t}reset(){this.i=this.end,this.current=void 0,this.value=void 0}},Vx=class{constructor(){this.mapWindowIdToZoomLevel=new Map,this._onDidChangeZoomLevel=new Ce,this.onDidChangeZoomLevel=this._onDidChangeZoomLevel.event,this.mapWindowIdToZoomFactor=new Map,this._onDidChangeFullscreen=new Ce,this.onDidChangeFullscreen=this._onDidChangeFullscreen.event,this.mapWindowIdToFullScreen=new Map}getZoomLevel(t){return this.mapWindowIdToZoomLevel.get(this.getWindowId(t))??0}setZoomLevel(t,s){if(this.getZoomLevel(s)===t)return;let n=this.getWindowId(s);this.mapWindowIdToZoomLevel.set(n,t),this._onDidChangeZoomLevel.fire(n)}getZoomFactor(t){return this.mapWindowIdToZoomFactor.get(this.getWindowId(t))??1}setZoomFactor(t,s){this.mapWindowIdToZoomFactor.set(this.getWindowId(s),t)}setFullscreen(t,s){if(this.isFullscreen(s)===t)return;let n=this.getWindowId(s);this.mapWindowIdToFullScreen.set(n,t),this._onDidChangeFullscreen.fire(n)}isFullscreen(t){return!!this.mapWindowIdToFullScreen.get(this.getWindowId(t))}getWindowId(t){return t.vscodeWindowId}};Vx.INSTANCE=new Vx;var cv=Vx;function v$(e,t,s){typeof t=="string"&&(t=e.matchMedia(t)),t.addEventListener("change",s)}cv.INSTANCE.onDidChangeZoomLevel;function b$(e){return cv.INSTANCE.getZoomFactor(e)}cv.INSTANCE.onDidChangeFullscreen;var sl=typeof navigator=="object"?navigator.userAgent:"",Wx=sl.indexOf("Firefox")>=0,_$=sl.indexOf("AppleWebKit")>=0,uv=sl.indexOf("Chrome")>=0,y$=!uv&&sl.indexOf("Safari")>=0;sl.indexOf("Electron/")>=0;sl.indexOf("Android")>=0;var wg=!1;if(typeof ti.matchMedia=="function"){let e=ti.matchMedia("(display-mode: standalone) or (display-mode: window-controls-overlay)"),t=ti.matchMedia("(display-mode: fullscreen)");wg=e.matches,v$(ti,e,({matches:s})=>{wg&&t.matches||(wg=s)})}var Po="en",qx=!1,Gx=!1,ch=!1,sN=!1,Kd,uh=Po,v2=Po,w$,nr,Ca=globalThis,zs,gS;typeof Ca.vscode<"u"&&typeof Ca.vscode.process<"u"?zs=Ca.vscode.process:typeof process<"u"&&typeof((gS=process==null?void 0:process.versions)==null?void 0:gS.node)=="string"&&(zs=process);var xS,S$=typeof((xS=zs==null?void 0:zs.versions)==null?void 0:xS.electron)=="string",j$=S$&&(zs==null?void 0:zs.type)==="renderer",vS;if(typeof zs=="object"){qx=zs.platform==="win32",Gx=zs.platform==="darwin",ch=zs.platform==="linux",ch&&zs.env.SNAP&&zs.env.SNAP_REVISION,zs.env.CI||zs.env.BUILD_ARTIFACTSTAGINGDIRECTORY,Kd=Po,uh=Po;let e=zs.env.VSCODE_NLS_CONFIG;if(e)try{let t=JSON.parse(e);Kd=t.userLocale,v2=t.osLocale,uh=t.resolvedLanguage||Po,w$=(vS=t.languagePack)==null?void 0:vS.translationsConfigFile}catch{}sN=!0}else typeof navigator=="object"&&!j$?(nr=navigator.userAgent,qx=nr.indexOf("Windows")>=0,Gx=nr.indexOf("Macintosh")>=0,(nr.indexOf("Macintosh")>=0||nr.indexOf("iPad")>=0||nr.indexOf("iPhone")>=0)&&navigator.maxTouchPoints&&navigator.maxTouchPoints>0,ch=nr.indexOf("Linux")>=0,(nr==null?void 0:nr.indexOf("Mobi"))>=0,uh=globalThis._VSCODE_NLS_LANGUAGE||Po,Kd=navigator.language.toLowerCase(),v2=Kd):console.error("Unable to resolve platform.");var nN=qx,Sr=Gx,k$=ch,b2=sN,Cr=nr,Oi=uh,C$;(e=>{function t(){return Oi}e.value=t;function s(){return Oi.length===2?Oi==="en":Oi.length>=3?Oi[0]==="e"&&Oi[1]==="n"&&Oi[2]==="-":!1}e.isDefaultVariant=s;function n(){return Oi==="en"}e.isDefault=n})(C$||(C$={}));var N$=typeof Ca.postMessage=="function"&&!Ca.importScripts;(()=>{if(N$){let e=[];Ca.addEventListener("message",s=>{if(s.data&&s.data.vscodeScheduleAsyncWork)for(let n=0,a=e.length;n<a;n++){let l=e[n];if(l.id===s.data.vscodeScheduleAsyncWork){e.splice(n,1),l.callback();return}}});let t=0;return s=>{let n=++t;e.push({id:n,callback:s}),Ca.postMessage({vscodeScheduleAsyncWork:n},"*")}}return e=>setTimeout(e)})();var E$=!!(Cr&&Cr.indexOf("Chrome")>=0);Cr&&Cr.indexOf("Firefox")>=0;!E$&&Cr&&Cr.indexOf("Safari")>=0;Cr&&Cr.indexOf("Edg/")>=0;Cr&&Cr.indexOf("Android")>=0;var Eo=typeof navigator=="object"?navigator:{};b2||document.queryCommandSupported&&document.queryCommandSupported("copy")||Eo&&Eo.clipboard&&Eo.clipboard.writeText,b2||Eo&&Eo.clipboard&&Eo.clipboard.readText;var dv=class{constructor(){this._keyCodeToStr=[],this._strToKeyCode=Object.create(null)}define(e,t){this._keyCodeToStr[e]=t,this._strToKeyCode[t.toLowerCase()]=e}keyCodeToStr(e){return this._keyCodeToStr[e]}strToKeyCode(e){return this._strToKeyCode[e.toLowerCase()]||0}},Sg=new dv,_2=new dv,y2=new dv,M$=new Array(230),rN;(e=>{function t(d){return Sg.keyCodeToStr(d)}e.toString=t;function s(d){return Sg.strToKeyCode(d)}e.fromString=s;function n(d){return _2.keyCodeToStr(d)}e.toUserSettingsUS=n;function a(d){return y2.keyCodeToStr(d)}e.toUserSettingsGeneral=a;function l(d){return _2.strToKeyCode(d)||y2.strToKeyCode(d)}e.fromUserSettings=l;function c(d){if(d>=98&&d<=113)return null;switch(d){case 16:return"Up";case 18:return"Down";case 15:return"Left";case 17:return"Right"}return Sg.keyCodeToStr(d)}e.toElectronAccelerator=c})(rN||(rN={}));var T$=class iN{constructor(t,s,n,a,l){this.ctrlKey=t,this.shiftKey=s,this.altKey=n,this.metaKey=a,this.keyCode=l}equals(t){return t instanceof iN&&this.ctrlKey===t.ctrlKey&&this.shiftKey===t.shiftKey&&this.altKey===t.altKey&&this.metaKey===t.metaKey&&this.keyCode===t.keyCode}getHashCode(){let t=this.ctrlKey?"1":"0",s=this.shiftKey?"1":"0",n=this.altKey?"1":"0",a=this.metaKey?"1":"0";return`K${t}${s}${n}${a}${this.keyCode}`}isModifierKey(){return this.keyCode===0||this.keyCode===5||this.keyCode===57||this.keyCode===6||this.keyCode===4}toKeybinding(){return new A$([this])}isDuplicateModifierCase(){return this.ctrlKey&&this.keyCode===5||this.shiftKey&&this.keyCode===4||this.altKey&&this.keyCode===6||this.metaKey&&this.keyCode===57}},A$=class{constructor(e){if(e.length===0)throw s$("chords");this.chords=e}getHashCode(){let e="";for(let t=0,s=this.chords.length;t<s;t++)t!==0&&(e+=";"),e+=this.chords[t].getHashCode();return e}equals(e){if(e===null||this.chords.length!==e.chords.length)return!1;for(let t=0;t<this.chords.length;t++)if(!this.chords[t].equals(e.chords[t]))return!1;return!0}};function R$(e){if(e.charCode){let s=String.fromCharCode(e.charCode).toUpperCase();return rN.fromString(s)}let t=e.keyCode;if(t===3)return 7;if(Wx)switch(t){case 59:return 85;case 60:if(k$)return 97;break;case 61:return 86;case 107:return 109;case 109:return 111;case 173:return 88;case 224:if(Sr)return 57;break}else if(_$&&(Sr&&t===93||!Sr&&t===92))return 57;return M$[t]||0}var D$=Sr?256:2048,L$=512,B$=1024,O$=Sr?2048:256,w2=class{constructor(e){var s;this._standardKeyboardEventBrand=!0;let t=e;this.browserEvent=t,this.target=t.target,this.ctrlKey=t.ctrlKey,this.shiftKey=t.shiftKey,this.altKey=t.altKey,this.metaKey=t.metaKey,this.altGraphKey=(s=t.getModifierState)==null?void 0:s.call(t,"AltGraph"),this.keyCode=R$(t),this.code=t.code,this.ctrlKey=this.ctrlKey||this.keyCode===5,this.altKey=this.altKey||this.keyCode===6,this.shiftKey=this.shiftKey||this.keyCode===4,this.metaKey=this.metaKey||this.keyCode===57,this._asKeybinding=this._computeKeybinding(),this._asKeyCodeChord=this._computeKeyCodeChord()}preventDefault(){this.browserEvent&&this.browserEvent.preventDefault&&this.browserEvent.preventDefault()}stopPropagation(){this.browserEvent&&this.browserEvent.stopPropagation&&this.browserEvent.stopPropagation()}toKeyCodeChord(){return this._asKeyCodeChord}equals(e){return this._asKeybinding===e}_computeKeybinding(){let e=0;this.keyCode!==5&&this.keyCode!==4&&this.keyCode!==6&&this.keyCode!==57&&(e=this.keyCode);let t=0;return this.ctrlKey&&(t|=D$),this.altKey&&(t|=L$),this.shiftKey&&(t|=B$),this.metaKey&&(t|=O$),t|=e,t}_computeKeyCodeChord(){let e=0;return this.keyCode!==5&&this.keyCode!==4&&this.keyCode!==6&&this.keyCode!==57&&(e=this.keyCode),new T$(this.ctrlKey,this.shiftKey,this.altKey,this.metaKey,e)}},S2=new WeakMap;function z$(e){if(!e.parent||e.parent===e)return null;try{let t=e.location,s=e.parent.location;if(t.origin!=="null"&&s.origin!=="null"&&t.origin!==s.origin)return null}catch{return null}return e.parent}var P$=class{static getSameOriginWindowChain(e){let t=S2.get(e);if(!t){t=[],S2.set(e,t);let s=e,n;do n=z$(s),n?t.push({window:new WeakRef(s),iframeElement:s.frameElement||null}):t.push({window:new WeakRef(s),iframeElement:null}),s=n;while(s)}return t.slice(0)}static getPositionOfChildWindowRelativeToAncestorWindow(e,t){if(!t||e===t)return{top:0,left:0};let s=0,n=0,a=this.getSameOriginWindowChain(e);for(let l of a){let c=l.window.deref();if(s+=(c==null?void 0:c.scrollY)??0,n+=(c==null?void 0:c.scrollX)??0,c===t||!l.iframeElement)break;let d=l.iframeElement.getBoundingClientRect();s+=d.top,n+=d.left}return{top:s,left:n}}},Yd=class{constructor(e,t){this.timestamp=Date.now(),this.browserEvent=t,this.leftButton=t.button===0,this.middleButton=t.button===1,this.rightButton=t.button===2,this.buttons=t.buttons,this.target=t.target,this.detail=t.detail||1,t.type==="dblclick"&&(this.detail=2),this.ctrlKey=t.ctrlKey,this.shiftKey=t.shiftKey,this.altKey=t.altKey,this.metaKey=t.metaKey,typeof t.pageX=="number"?(this.posx=t.pageX,this.posy=t.pageY):(this.posx=t.clientX+this.target.ownerDocument.body.scrollLeft+this.target.ownerDocument.documentElement.scrollLeft,this.posy=t.clientY+this.target.ownerDocument.body.scrollTop+this.target.ownerDocument.documentElement.scrollTop);let s=P$.getPositionOfChildWindowRelativeToAncestorWindow(e,t.view);this.posx-=s.left,this.posy-=s.top}preventDefault(){this.browserEvent.preventDefault()}stopPropagation(){this.browserEvent.stopPropagation()}},j2=class{constructor(e,t=0,s=0){var a;this.browserEvent=e||null,this.target=e?e.target||e.targetNode||e.srcElement:null,this.deltaY=s,this.deltaX=t;let n=!1;if(uv){let l=navigator.userAgent.match(/Chrome\/(\d+)/);n=(l?parseInt(l[1]):123)<=122}if(e){let l=e,c=e,d=((a=e.view)==null?void 0:a.devicePixelRatio)||1;if(typeof l.wheelDeltaY<"u")n?this.deltaY=l.wheelDeltaY/(120*d):this.deltaY=l.wheelDeltaY/120;else if(typeof c.VERTICAL_AXIS<"u"&&c.axis===c.VERTICAL_AXIS)this.deltaY=-c.detail/3;else if(e.type==="wheel"){let f=e;f.deltaMode===f.DOM_DELTA_LINE?Wx&&!Sr?this.deltaY=-e.deltaY/3:this.deltaY=-e.deltaY:this.deltaY=-e.deltaY/40}if(typeof l.wheelDeltaX<"u")y$&&nN?this.deltaX=-(l.wheelDeltaX/120):n?this.deltaX=l.wheelDeltaX/(120*d):this.deltaX=l.wheelDeltaX/120;else if(typeof c.HORIZONTAL_AXIS<"u"&&c.axis===c.HORIZONTAL_AXIS)this.deltaX=-e.detail/3;else if(e.type==="wheel"){let f=e;f.deltaMode===f.DOM_DELTA_LINE?Wx&&!Sr?this.deltaX=-e.deltaX/3:this.deltaX=-e.deltaX:this.deltaX=-e.deltaX/40}this.deltaY===0&&this.deltaX===0&&e.wheelDelta&&(n?this.deltaY=e.wheelDelta/(120*d):this.deltaY=e.wheelDelta/120)}}preventDefault(){var e;(e=this.browserEvent)==null||e.preventDefault()}stopPropagation(){var e;(e=this.browserEvent)==null||e.stopPropagation()}},aN=Object.freeze(function(e,t){let s=setTimeout(e.bind(t),0);return{dispose(){clearTimeout(s)}}}),$$;(e=>{function t(s){return s===e.None||s===e.Cancelled||s instanceof I$?!0:!s||typeof s!="object"?!1:typeof s.isCancellationRequested=="boolean"&&typeof s.onCancellationRequested=="function"}e.isCancellationToken=t,e.None=Object.freeze({isCancellationRequested:!1,onCancellationRequested:Is.None}),e.Cancelled=Object.freeze({isCancellationRequested:!0,onCancellationRequested:aN})})($$||($$={}));var I$=class{constructor(){this._isCancelled=!1,this._emitter=null}cancel(){this._isCancelled||(this._isCancelled=!0,this._emitter&&(this._emitter.fire(void 0),this.dispose()))}get isCancellationRequested(){return this._isCancelled}get onCancellationRequested(){return this._isCancelled?aN:(this._emitter||(this._emitter=new Ce),this._emitter.event)}dispose(){this._emitter&&(this._emitter.dispose(),this._emitter=null)}},hv=class{constructor(e,t){this._isDisposed=!1,this._token=-1,typeof e=="function"&&typeof t=="number"&&this.setIfNotSet(e,t)}dispose(){this.cancel(),this._isDisposed=!0}cancel(){this._token!==-1&&(clearTimeout(this._token),this._token=-1)}cancelAndSet(e,t){if(this._isDisposed)throw new $x("Calling 'cancelAndSet' on a disposed TimeoutTimer");this.cancel(),this._token=setTimeout(()=>{this._token=-1,e()},t)}setIfNotSet(e,t){if(this._isDisposed)throw new $x("Calling 'setIfNotSet' on a disposed TimeoutTimer");this._token===-1&&(this._token=setTimeout(()=>{this._token=-1,e()},t))}},F$=class{constructor(){this.disposable=void 0,this.isDisposed=!1}cancel(){var e;(e=this.disposable)==null||e.dispose(),this.disposable=void 0}cancelAndSet(e,t,s=globalThis){if(this.isDisposed)throw new $x("Calling 'cancelAndSet' on a disposed IntervalTimer");this.cancel();let n=s.setInterval(()=>{e()},t);this.disposable=Ut(()=>{s.clearInterval(n),this.disposable=void 0})}dispose(){this.cancel(),this.isDisposed=!0}},H$;(e=>{async function t(n){let a,l=await Promise.all(n.map(c=>c.then(d=>d,d=>{a||(a=d)})));if(typeof a<"u")throw a;return l}e.settled=t;function s(n){return new Promise(async(a,l)=>{try{await n(a,l)}catch(c){l(c)}})}e.withAsyncBody=s})(H$||(H$={}));var k2=class qn{static fromArray(t){return new qn(s=>{s.emitMany(t)})}static fromPromise(t){return new qn(async s=>{s.emitMany(await t)})}static fromPromises(t){return new qn(async s=>{await Promise.all(t.map(async n=>s.emitOne(await n)))})}static merge(t){return new qn(async s=>{await Promise.all(t.map(async n=>{for await(let a of n)s.emitOne(a)}))})}constructor(t,s){this._state=0,this._results=[],this._error=null,this._onReturn=s,this._onStateChanged=new Ce,queueMicrotask(async()=>{let n={emitOne:a=>this.emitOne(a),emitMany:a=>this.emitMany(a),reject:a=>this.reject(a)};try{await Promise.resolve(t(n)),this.resolve()}catch(a){this.reject(a)}finally{n.emitOne=void 0,n.emitMany=void 0,n.reject=void 0}})}[Symbol.asyncIterator](){let t=0;return{next:async()=>{do{if(this._state===2)throw this._error;if(t<this._results.length)return{done:!1,value:this._results[t++]};if(this._state===1)return{done:!0,value:void 0};await Is.toPromise(this._onStateChanged.event)}while(!0)},return:async()=>{var s;return(s=this._onReturn)==null||s.call(this),{done:!0,value:void 0}}}}static map(t,s){return new qn(async n=>{for await(let a of t)n.emitOne(s(a))})}map(t){return qn.map(this,t)}static filter(t,s){return new qn(async n=>{for await(let a of t)s(a)&&n.emitOne(a)})}filter(t){return qn.filter(this,t)}static coalesce(t){return qn.filter(t,s=>!!s)}coalesce(){return qn.coalesce(this)}static async toPromise(t){let s=[];for await(let n of t)s.push(n);return s}toPromise(){return qn.toPromise(this)}emitOne(t){this._state===0&&(this._results.push(t),this._onStateChanged.fire())}emitMany(t){this._state===0&&(this._results=this._results.concat(t),this._onStateChanged.fire())}resolve(){this._state===0&&(this._state=1,this._onStateChanged.fire())}reject(t){this._state===0&&(this._state=2,this._error=t,this._onStateChanged.fire())}};k2.EMPTY=k2.fromArray([]);var{getWindow:wr,getWindowId:U$,onDidRegisterWindow:V$}=(function(){let e=new Map,t={window:ti,disposables:new Yi};e.set(ti.vscodeWindowId,t);let s=new Ce,n=new Ce,a=new Ce;function l(c,d){return(typeof c=="number"?e.get(c):void 0)??(d?t:void 0)}return{onDidRegisterWindow:s.event,onWillUnregisterWindow:a.event,onDidUnregisterWindow:n.event,registerWindow(c){if(e.has(c.vscodeWindowId))return nt.None;let d=new Yi,f={window:c,disposables:d.add(new Yi)};return e.set(c.vscodeWindowId,f),d.add(Ut(()=>{e.delete(c.vscodeWindowId),n.fire(c)})),d.add(Ge(c,Cs.BEFORE_UNLOAD,()=>{a.fire(c)})),s.fire(f),d},getWindows(){return e.values()},getWindowsCount(){return e.size},getWindowId(c){return c.vscodeWindowId},hasWindow(c){return e.has(c)},getWindowById:l,getWindow(c){var h;let d=c;if((h=d==null?void 0:d.ownerDocument)!=null&&h.defaultView)return d.ownerDocument.defaultView.window;let f=c;return f!=null&&f.view?f.view.window:ti},getDocument(c){return wr(c).document}}})(),W$=class{constructor(e,t,s,n){this._node=e,this._type=t,this._handler=s,this._options=n||!1,this._node.addEventListener(this._type,this._handler,this._options)}dispose(){this._handler&&(this._node.removeEventListener(this._type,this._handler,this._options),this._node=null,this._handler=null)}};function Ge(e,t,s,n){return new W$(e,t,s,n)}var C2=function(e,t,s,n){return Ge(e,t,s,n)},fv,q$=class extends F${constructor(e){super(),this.defaultTarget=e&&wr(e)}cancelAndSet(e,t,s){return super.cancelAndSet(e,t,s??this.defaultTarget)}},N2=class{constructor(e,t=0){this._runner=e,this.priority=t,this._canceled=!1}dispose(){this._canceled=!0}execute(){if(!this._canceled)try{this._runner()}catch(e){lh(e)}}static sort(e,t){return t.priority-e.priority}};(function(){let e=new Map,t=new Map,s=new Map,n=new Map,a=l=>{s.set(l,!1);let c=e.get(l)??[];for(t.set(l,c),e.set(l,[]),n.set(l,!0);c.length>0;)c.sort(N2.sort),c.shift().execute();n.set(l,!1)};fv=(l,c,d=0)=>{let f=U$(l),h=new N2(c,d),m=e.get(f);return m||(m=[],e.set(f,m)),m.push(h),s.get(f)||(s.set(f,!0),l.requestAnimationFrame(()=>a(f))),h}})();function G$(e){let t=e.getBoundingClientRect(),s=wr(e);return{left:t.left+s.scrollX,top:t.top+s.scrollY,width:t.width,height:t.height}}var Cs={CLICK:"click",MOUSE_DOWN:"mousedown",MOUSE_OVER:"mouseover",MOUSE_LEAVE:"mouseleave",MOUSE_WHEEL:"wheel",POINTER_UP:"pointerup",POINTER_DOWN:"pointerdown",POINTER_MOVE:"pointermove",KEY_DOWN:"keydown",KEY_UP:"keyup",BEFORE_UNLOAD:"beforeunload",CHANGE:"change",FOCUS:"focus",BLUR:"blur",INPUT:"input"},K$=class{constructor(e){this.domNode=e,this._maxWidth="",this._width="",this._height="",this._top="",this._left="",this._bottom="",this._right="",this._paddingTop="",this._paddingLeft="",this._paddingBottom="",this._paddingRight="",this._fontFamily="",this._fontWeight="",this._fontSize="",this._fontStyle="",this._fontFeatureSettings="",this._fontVariationSettings="",this._textDecoration="",this._lineHeight="",this._letterSpacing="",this._className="",this._display="",this._position="",this._visibility="",this._color="",this._backgroundColor="",this._layerHint=!1,this._contain="none",this._boxShadow=""}setMaxWidth(e){let t=fn(e);this._maxWidth!==t&&(this._maxWidth=t,this.domNode.style.maxWidth=this._maxWidth)}setWidth(e){let t=fn(e);this._width!==t&&(this._width=t,this.domNode.style.width=this._width)}setHeight(e){let t=fn(e);this._height!==t&&(this._height=t,this.domNode.style.height=this._height)}setTop(e){let t=fn(e);this._top!==t&&(this._top=t,this.domNode.style.top=this._top)}setLeft(e){let t=fn(e);this._left!==t&&(this._left=t,this.domNode.style.left=this._left)}setBottom(e){let t=fn(e);this._bottom!==t&&(this._bottom=t,this.domNode.style.bottom=this._bottom)}setRight(e){let t=fn(e);this._right!==t&&(this._right=t,this.domNode.style.right=this._right)}setPaddingTop(e){let t=fn(e);this._paddingTop!==t&&(this._paddingTop=t,this.domNode.style.paddingTop=this._paddingTop)}setPaddingLeft(e){let t=fn(e);this._paddingLeft!==t&&(this._paddingLeft=t,this.domNode.style.paddingLeft=this._paddingLeft)}setPaddingBottom(e){let t=fn(e);this._paddingBottom!==t&&(this._paddingBottom=t,this.domNode.style.paddingBottom=this._paddingBottom)}setPaddingRight(e){let t=fn(e);this._paddingRight!==t&&(this._paddingRight=t,this.domNode.style.paddingRight=this._paddingRight)}setFontFamily(e){this._fontFamily!==e&&(this._fontFamily=e,this.domNode.style.fontFamily=this._fontFamily)}setFontWeight(e){this._fontWeight!==e&&(this._fontWeight=e,this.domNode.style.fontWeight=this._fontWeight)}setFontSize(e){let t=fn(e);this._fontSize!==t&&(this._fontSize=t,this.domNode.style.fontSize=this._fontSize)}setFontStyle(e){this._fontStyle!==e&&(this._fontStyle=e,this.domNode.style.fontStyle=this._fontStyle)}setFontFeatureSettings(e){this._fontFeatureSettings!==e&&(this._fontFeatureSettings=e,this.domNode.style.fontFeatureSettings=this._fontFeatureSettings)}setFontVariationSettings(e){this._fontVariationSettings!==e&&(this._fontVariationSettings=e,this.domNode.style.fontVariationSettings=this._fontVariationSettings)}setTextDecoration(e){this._textDecoration!==e&&(this._textDecoration=e,this.domNode.style.textDecoration=this._textDecoration)}setLineHeight(e){let t=fn(e);this._lineHeight!==t&&(this._lineHeight=t,this.domNode.style.lineHeight=this._lineHeight)}setLetterSpacing(e){let t=fn(e);this._letterSpacing!==t&&(this._letterSpacing=t,this.domNode.style.letterSpacing=this._letterSpacing)}setClassName(e){this._className!==e&&(this._className=e,this.domNode.className=this._className)}toggleClassName(e,t){this.domNode.classList.toggle(e,t),this._className=this.domNode.className}setDisplay(e){this._display!==e&&(this._display=e,this.domNode.style.display=this._display)}setPosition(e){this._position!==e&&(this._position=e,this.domNode.style.position=this._position)}setVisibility(e){this._visibility!==e&&(this._visibility=e,this.domNode.style.visibility=this._visibility)}setColor(e){this._color!==e&&(this._color=e,this.domNode.style.color=this._color)}setBackgroundColor(e){this._backgroundColor!==e&&(this._backgroundColor=e,this.domNode.style.backgroundColor=this._backgroundColor)}setLayerHinting(e){this._layerHint!==e&&(this._layerHint=e,this.domNode.style.transform=this._layerHint?"translate3d(0px, 0px, 0px)":"")}setBoxShadow(e){this._boxShadow!==e&&(this._boxShadow=e,this.domNode.style.boxShadow=e)}setContain(e){this._contain!==e&&(this._contain=e,this.domNode.style.contain=this._contain)}setAttribute(e,t){this.domNode.setAttribute(e,t)}removeAttribute(e){this.domNode.removeAttribute(e)}appendChild(e){this.domNode.appendChild(e.domNode)}removeChild(e){this.domNode.removeChild(e.domNode)}};function fn(e){return typeof e=="number"?`${e}px`:e}function Hc(e){return new K$(e)}var oN=class{constructor(){this._hooks=new Yi,this._pointerMoveCallback=null,this._onStopCallback=null}dispose(){this.stopMonitoring(!1),this._hooks.dispose()}stopMonitoring(e,t){if(!this.isMonitoring())return;this._hooks.clear(),this._pointerMoveCallback=null;let s=this._onStopCallback;this._onStopCallback=null,e&&s&&s(t)}isMonitoring(){return!!this._pointerMoveCallback}startMonitoring(e,t,s,n,a){this.isMonitoring()&&this.stopMonitoring(!1),this._pointerMoveCallback=n,this._onStopCallback=a;let l=e;try{e.setPointerCapture(t),this._hooks.add(Ut(()=>{try{e.releasePointerCapture(t)}catch{}}))}catch{l=wr(e)}this._hooks.add(Ge(l,Cs.POINTER_MOVE,c=>{if(c.buttons!==s){this.stopMonitoring(!0);return}c.preventDefault(),this._pointerMoveCallback(c)})),this._hooks.add(Ge(l,Cs.POINTER_UP,c=>this.stopMonitoring(!0)))}};function Y$(e,t,s){let n=null,a=null;if(typeof s.value=="function"?(n="value",a=s.value,a.length!==0&&console.warn("Memoize should only be used in functions with zero parameters")):typeof s.get=="function"&&(n="get",a=s.get),!a)throw new Error("not supported");let l=`$memoize$${t}`;s[n]=function(...c){return this.hasOwnProperty(l)||Object.defineProperty(this,l,{configurable:!1,enumerable:!1,writable:!1,value:a.apply(this,c)}),this[l]}}var gr;(e=>(e.Tap="-xterm-gesturetap",e.Change="-xterm-gesturechange",e.Start="-xterm-gesturestart",e.End="-xterm-gesturesend",e.Contextmenu="-xterm-gesturecontextmenu"))(gr||(gr={}));var Mc=class Vs extends nt{constructor(){super(),this.dispatched=!1,this.targets=new x2,this.ignoreTargets=new x2,this.activeTouches={},this.handle=null,this._lastSetTapCountTime=0,this._register(Is.runAndSubscribe(V$,({window:t,disposables:s})=>{s.add(Ge(t.document,"touchstart",n=>this.onTouchStart(n),{passive:!1})),s.add(Ge(t.document,"touchend",n=>this.onTouchEnd(t,n))),s.add(Ge(t.document,"touchmove",n=>this.onTouchMove(n),{passive:!1}))},{window:ti,disposables:this._store}))}static addTarget(t){if(!Vs.isTouchDevice())return nt.None;Vs.INSTANCE||(Vs.INSTANCE=new Vs);let s=Vs.INSTANCE.targets.push(t);return Ut(s)}static ignoreTarget(t){if(!Vs.isTouchDevice())return nt.None;Vs.INSTANCE||(Vs.INSTANCE=new Vs);let s=Vs.INSTANCE.ignoreTargets.push(t);return Ut(s)}static isTouchDevice(){return"ontouchstart"in ti||navigator.maxTouchPoints>0}dispose(){this.handle&&(this.handle.dispose(),this.handle=null),super.dispose()}onTouchStart(t){let s=Date.now();this.handle&&(this.handle.dispose(),this.handle=null);for(let n=0,a=t.targetTouches.length;n<a;n++){let l=t.targetTouches.item(n);this.activeTouches[l.identifier]={id:l.identifier,initialTarget:l.target,initialTimeStamp:s,initialPageX:l.pageX,initialPageY:l.pageY,rollingTimestamps:[s],rollingPageX:[l.pageX],rollingPageY:[l.pageY]};let c=this.newGestureEvent(gr.Start,l.target);c.pageX=l.pageX,c.pageY=l.pageY,this.dispatchEvent(c)}this.dispatched&&(t.preventDefault(),t.stopPropagation(),this.dispatched=!1)}onTouchEnd(t,s){let n=Date.now(),a=Object.keys(this.activeTouches).length;for(let l=0,c=s.changedTouches.length;l<c;l++){let d=s.changedTouches.item(l);if(!this.activeTouches.hasOwnProperty(String(d.identifier))){console.warn("move of an UNKNOWN touch",d);continue}let f=this.activeTouches[d.identifier],h=Date.now()-f.initialTimeStamp;if(h<Vs.HOLD_DELAY&&Math.abs(f.initialPageX-Nn(f.rollingPageX))<30&&Math.abs(f.initialPageY-Nn(f.rollingPageY))<30){let m=this.newGestureEvent(gr.Tap,f.initialTarget);m.pageX=Nn(f.rollingPageX),m.pageY=Nn(f.rollingPageY),this.dispatchEvent(m)}else if(h>=Vs.HOLD_DELAY&&Math.abs(f.initialPageX-Nn(f.rollingPageX))<30&&Math.abs(f.initialPageY-Nn(f.rollingPageY))<30){let m=this.newGestureEvent(gr.Contextmenu,f.initialTarget);m.pageX=Nn(f.rollingPageX),m.pageY=Nn(f.rollingPageY),this.dispatchEvent(m)}else if(a===1){let m=Nn(f.rollingPageX),g=Nn(f.rollingPageY),b=Nn(f.rollingTimestamps)-f.rollingTimestamps[0],v=m-f.rollingPageX[0],y=g-f.rollingPageY[0],S=[...this.targets].filter(j=>f.initialTarget instanceof Node&&j.contains(f.initialTarget));this.inertia(t,S,n,Math.abs(v)/b,v>0?1:-1,m,Math.abs(y)/b,y>0?1:-1,g)}this.dispatchEvent(this.newGestureEvent(gr.End,f.initialTarget)),delete this.activeTouches[d.identifier]}this.dispatched&&(s.preventDefault(),s.stopPropagation(),this.dispatched=!1)}newGestureEvent(t,s){let n=document.createEvent("CustomEvent");return n.initEvent(t,!1,!0),n.initialTarget=s,n.tapCount=0,n}dispatchEvent(t){if(t.type===gr.Tap){let s=new Date().getTime(),n=0;s-this._lastSetTapCountTime>Vs.CLEAR_TAP_COUNT_TIME?n=1:n=2,this._lastSetTapCountTime=s,t.tapCount=n}else(t.type===gr.Change||t.type===gr.Contextmenu)&&(this._lastSetTapCountTime=0);if(t.initialTarget instanceof Node){for(let n of this.ignoreTargets)if(n.contains(t.initialTarget))return;let s=[];for(let n of this.targets)if(n.contains(t.initialTarget)){let a=0,l=t.initialTarget;for(;l&&l!==n;)a++,l=l.parentElement;s.push([a,n])}s.sort((n,a)=>n[0]-a[0]);for(let[n,a]of s)a.dispatchEvent(t),this.dispatched=!0}}inertia(t,s,n,a,l,c,d,f,h){this.handle=fv(t,()=>{let m=Date.now(),g=m-n,b=0,v=0,y=!0;a+=Vs.SCROLL_FRICTION*g,d+=Vs.SCROLL_FRICTION*g,a>0&&(y=!1,b=l*a*g),d>0&&(y=!1,v=f*d*g);let S=this.newGestureEvent(gr.Change);S.translationX=b,S.translationY=v,s.forEach(j=>j.dispatchEvent(S)),y||this.inertia(t,s,m,a,l,c+b,d,f,h+v)})}onTouchMove(t){let s=Date.now();for(let n=0,a=t.changedTouches.length;n<a;n++){let l=t.changedTouches.item(n);if(!this.activeTouches.hasOwnProperty(String(l.identifier))){console.warn("end of an UNKNOWN touch",l);continue}let c=this.activeTouches[l.identifier],d=this.newGestureEvent(gr.Change,c.initialTarget);d.translationX=l.pageX-Nn(c.rollingPageX),d.translationY=l.pageY-Nn(c.rollingPageY),d.pageX=l.pageX,d.pageY=l.pageY,this.dispatchEvent(d),c.rollingPageX.length>3&&(c.rollingPageX.shift(),c.rollingPageY.shift(),c.rollingTimestamps.shift()),c.rollingPageX.push(l.pageX),c.rollingPageY.push(l.pageY),c.rollingTimestamps.push(s)}this.dispatched&&(t.preventDefault(),t.stopPropagation(),this.dispatched=!1)}};Mc.SCROLL_FRICTION=-.005,Mc.HOLD_DELAY=700,Mc.CLEAR_TAP_COUNT_TIME=400,ts([Y$],Mc,"isTouchDevice",1);var X$=Mc,pv=class extends nt{onclick(e,t){this._register(Ge(e,Cs.CLICK,s=>t(new Yd(wr(e),s))))}onmousedown(e,t){this._register(Ge(e,Cs.MOUSE_DOWN,s=>t(new Yd(wr(e),s))))}onmouseover(e,t){this._register(Ge(e,Cs.MOUSE_OVER,s=>t(new Yd(wr(e),s))))}onmouseleave(e,t){this._register(Ge(e,Cs.MOUSE_LEAVE,s=>t(new Yd(wr(e),s))))}onkeydown(e,t){this._register(Ge(e,Cs.KEY_DOWN,s=>t(new w2(s))))}onkeyup(e,t){this._register(Ge(e,Cs.KEY_UP,s=>t(new w2(s))))}oninput(e,t){this._register(Ge(e,Cs.INPUT,t))}onblur(e,t){this._register(Ge(e,Cs.BLUR,t))}onfocus(e,t){this._register(Ge(e,Cs.FOCUS,t))}onchange(e,t){this._register(Ge(e,Cs.CHANGE,t))}ignoreGesture(e){return X$.ignoreTarget(e)}},E2=11,J$=class extends pv{constructor(e){super(),this._onActivate=e.onActivate,this.bgDomNode=document.createElement("div"),this.bgDomNode.className="arrow-background",this.bgDomNode.style.position="absolute",this.bgDomNode.style.width=e.bgWidth+"px",this.bgDomNode.style.height=e.bgHeight+"px",typeof e.top<"u"&&(this.bgDomNode.style.top="0px"),typeof e.left<"u"&&(this.bgDomNode.style.left="0px"),typeof e.bottom<"u"&&(this.bgDomNode.style.bottom="0px"),typeof e.right<"u"&&(this.bgDomNode.style.right="0px"),this.domNode=document.createElement("div"),this.domNode.className=e.className,this.domNode.style.position="absolute",this.domNode.style.width=E2+"px",this.domNode.style.height=E2+"px",typeof e.top<"u"&&(this.domNode.style.top=e.top+"px"),typeof e.left<"u"&&(this.domNode.style.left=e.left+"px"),typeof e.bottom<"u"&&(this.domNode.style.bottom=e.bottom+"px"),typeof e.right<"u"&&(this.domNode.style.right=e.right+"px"),this._pointerMoveMonitor=this._register(new oN),this._register(C2(this.bgDomNode,Cs.POINTER_DOWN,t=>this._arrowPointerDown(t))),this._register(C2(this.domNode,Cs.POINTER_DOWN,t=>this._arrowPointerDown(t))),this._pointerdownRepeatTimer=this._register(new q$),this._pointerdownScheduleRepeatTimer=this._register(new hv)}_arrowPointerDown(e){if(!e.target||!(e.target instanceof Element))return;let t=()=>{this._pointerdownRepeatTimer.cancelAndSet(()=>this._onActivate(),1e3/24,wr(e))};this._onActivate(),this._pointerdownRepeatTimer.cancel(),this._pointerdownScheduleRepeatTimer.cancelAndSet(t,200),this._pointerMoveMonitor.startMonitoring(e.target,e.pointerId,e.buttons,s=>{},()=>{this._pointerdownRepeatTimer.cancel(),this._pointerdownScheduleRepeatTimer.cancel()}),e.preventDefault()}},Q$=class Kx{constructor(t,s,n,a,l,c,d){this._forceIntegerValues=t,this._scrollStateBrand=void 0,this._forceIntegerValues&&(s=s|0,n=n|0,a=a|0,l=l|0,c=c|0,d=d|0),this.rawScrollLeft=a,this.rawScrollTop=d,s<0&&(s=0),a+s>n&&(a=n-s),a<0&&(a=0),l<0&&(l=0),d+l>c&&(d=c-l),d<0&&(d=0),this.width=s,this.scrollWidth=n,this.scrollLeft=a,this.height=l,this.scrollHeight=c,this.scrollTop=d}equals(t){return this.rawScrollLeft===t.rawScrollLeft&&this.rawScrollTop===t.rawScrollTop&&this.width===t.width&&this.scrollWidth===t.scrollWidth&&this.scrollLeft===t.scrollLeft&&this.height===t.height&&this.scrollHeight===t.scrollHeight&&this.scrollTop===t.scrollTop}withScrollDimensions(t,s){return new Kx(this._forceIntegerValues,typeof t.width<"u"?t.width:this.width,typeof t.scrollWidth<"u"?t.scrollWidth:this.scrollWidth,s?this.rawScrollLeft:this.scrollLeft,typeof t.height<"u"?t.height:this.height,typeof t.scrollHeight<"u"?t.scrollHeight:this.scrollHeight,s?this.rawScrollTop:this.scrollTop)}withScrollPosition(t){return new Kx(this._forceIntegerValues,this.width,this.scrollWidth,typeof t.scrollLeft<"u"?t.scrollLeft:this.rawScrollLeft,this.height,this.scrollHeight,typeof t.scrollTop<"u"?t.scrollTop:this.rawScrollTop)}createScrollEvent(t,s){let n=this.width!==t.width,a=this.scrollWidth!==t.scrollWidth,l=this.scrollLeft!==t.scrollLeft,c=this.height!==t.height,d=this.scrollHeight!==t.scrollHeight,f=this.scrollTop!==t.scrollTop;return{inSmoothScrolling:s,oldWidth:t.width,oldScrollWidth:t.scrollWidth,oldScrollLeft:t.scrollLeft,width:this.width,scrollWidth:this.scrollWidth,scrollLeft:this.scrollLeft,oldHeight:t.height,oldScrollHeight:t.scrollHeight,oldScrollTop:t.scrollTop,height:this.height,scrollHeight:this.scrollHeight,scrollTop:this.scrollTop,widthChanged:n,scrollWidthChanged:a,scrollLeftChanged:l,heightChanged:c,scrollHeightChanged:d,scrollTopChanged:f}}},Z$=class extends nt{constructor(e){super(),this._scrollableBrand=void 0,this._onScroll=this._register(new Ce),this.onScroll=this._onScroll.event,this._smoothScrollDuration=e.smoothScrollDuration,this._scheduleAtNextAnimationFrame=e.scheduleAtNextAnimationFrame,this._state=new Q$(e.forceIntegerValues,0,0,0,0,0,0),this._smoothScrolling=null}dispose(){this._smoothScrolling&&(this._smoothScrolling.dispose(),this._smoothScrolling=null),super.dispose()}setSmoothScrollDuration(e){this._smoothScrollDuration=e}validateScrollPosition(e){return this._state.withScrollPosition(e)}getScrollDimensions(){return this._state}setScrollDimensions(e,t){var n;let s=this._state.withScrollDimensions(e,t);this._setState(s,!!this._smoothScrolling),(n=this._smoothScrolling)==null||n.acceptScrollDimensions(this._state)}getFutureScrollPosition(){return this._smoothScrolling?this._smoothScrolling.to:this._state}getCurrentScrollPosition(){return this._state}setScrollPositionNow(e){let t=this._state.withScrollPosition(e);this._smoothScrolling&&(this._smoothScrolling.dispose(),this._smoothScrolling=null),this._setState(t,!1)}setScrollPositionSmooth(e,t){if(this._smoothScrollDuration===0)return this.setScrollPositionNow(e);if(this._smoothScrolling){e={scrollLeft:typeof e.scrollLeft>"u"?this._smoothScrolling.to.scrollLeft:e.scrollLeft,scrollTop:typeof e.scrollTop>"u"?this._smoothScrolling.to.scrollTop:e.scrollTop};let s=this._state.withScrollPosition(e);if(this._smoothScrolling.to.scrollLeft===s.scrollLeft&&this._smoothScrolling.to.scrollTop===s.scrollTop)return;let n;t?n=new T2(this._smoothScrolling.from,s,this._smoothScrolling.startTime,this._smoothScrolling.duration):n=this._smoothScrolling.combine(this._state,s,this._smoothScrollDuration),this._smoothScrolling.dispose(),this._smoothScrolling=n}else{let s=this._state.withScrollPosition(e);this._smoothScrolling=T2.start(this._state,s,this._smoothScrollDuration)}this._smoothScrolling.animationFrameDisposable=this._scheduleAtNextAnimationFrame(()=>{this._smoothScrolling&&(this._smoothScrolling.animationFrameDisposable=null,this._performSmoothScrolling())})}hasPendingScrollAnimation(){return!!this._smoothScrolling}_performSmoothScrolling(){if(!this._smoothScrolling)return;let e=this._smoothScrolling.tick(),t=this._state.withScrollPosition(e);if(this._setState(t,!0),!!this._smoothScrolling){if(e.isDone){this._smoothScrolling.dispose(),this._smoothScrolling=null;return}this._smoothScrolling.animationFrameDisposable=this._scheduleAtNextAnimationFrame(()=>{this._smoothScrolling&&(this._smoothScrolling.animationFrameDisposable=null,this._performSmoothScrolling())})}}_setState(e,t){let s=this._state;s.equals(e)||(this._state=e,this._onScroll.fire(this._state.createScrollEvent(s,t)))}},M2=class{constructor(e,t,s){this.scrollLeft=e,this.scrollTop=t,this.isDone=s}};function jg(e,t){let s=t-e;return function(n){return e+s*sI(n)}}function eI(e,t,s){return function(n){return n<s?e(n/s):t((n-s)/(1-s))}}var T2=class Yx{constructor(t,s,n,a){this.from=t,this.to=s,this.duration=a,this.startTime=n,this.animationFrameDisposable=null,this._initAnimations()}_initAnimations(){this.scrollLeft=this._initAnimation(this.from.scrollLeft,this.to.scrollLeft,this.to.width),this.scrollTop=this._initAnimation(this.from.scrollTop,this.to.scrollTop,this.to.height)}_initAnimation(t,s,n){if(Math.abs(t-s)>2.5*n){let a,l;return t<s?(a=t+.75*n,l=s-.75*n):(a=t-.75*n,l=s+.75*n),eI(jg(t,a),jg(l,s),.33)}return jg(t,s)}dispose(){this.animationFrameDisposable!==null&&(this.animationFrameDisposable.dispose(),this.animationFrameDisposable=null)}acceptScrollDimensions(t){this.to=t.withScrollPosition(this.to),this._initAnimations()}tick(){return this._tick(Date.now())}_tick(t){let s=(t-this.startTime)/this.duration;if(s<1){let n=this.scrollLeft(s),a=this.scrollTop(s);return new M2(n,a,!1)}return new M2(this.to.scrollLeft,this.to.scrollTop,!0)}combine(t,s,n){return Yx.start(t,s,n)}static start(t,s,n){n=n+10;let a=Date.now()-10;return new Yx(t,s,a,n)}};function tI(e){return Math.pow(e,3)}function sI(e){return 1-tI(1-e)}var nI=class extends nt{constructor(e,t,s){super(),this._visibility=e,this._visibleClassName=t,this._invisibleClassName=s,this._domNode=null,this._isVisible=!1,this._isNeeded=!1,this._rawShouldBeVisible=!1,this._shouldBeVisible=!1,this._revealTimer=this._register(new hv)}setVisibility(e){this._visibility!==e&&(this._visibility=e,this._updateShouldBeVisible())}setShouldBeVisible(e){this._rawShouldBeVisible=e,this._updateShouldBeVisible()}_applyVisibilitySetting(){return this._visibility===2?!1:this._visibility===3?!0:this._rawShouldBeVisible}_updateShouldBeVisible(){let e=this._applyVisibilitySetting();this._shouldBeVisible!==e&&(this._shouldBeVisible=e,this.ensureVisibility())}setIsNeeded(e){this._isNeeded!==e&&(this._isNeeded=e,this.ensureVisibility())}setDomNode(e){this._domNode=e,this._domNode.setClassName(this._invisibleClassName),this.setShouldBeVisible(!1)}ensureVisibility(){if(!this._isNeeded){this._hide(!1);return}this._shouldBeVisible?this._reveal():this._hide(!0)}_reveal(){this._isVisible||(this._isVisible=!0,this._revealTimer.setIfNotSet(()=>{var e;(e=this._domNode)==null||e.setClassName(this._visibleClassName)},0))}_hide(e){var t;this._revealTimer.cancel(),this._isVisible&&(this._isVisible=!1,(t=this._domNode)==null||t.setClassName(this._invisibleClassName+(e?" fade":"")))}},rI=140,lN=class extends pv{constructor(e){super(),this._lazyRender=e.lazyRender,this._host=e.host,this._scrollable=e.scrollable,this._scrollByPage=e.scrollByPage,this._scrollbarState=e.scrollbarState,this._visibilityController=this._register(new nI(e.visibility,"visible scrollbar "+e.extraScrollbarClassName,"invisible scrollbar "+e.extraScrollbarClassName)),this._visibilityController.setIsNeeded(this._scrollbarState.isNeeded()),this._pointerMoveMonitor=this._register(new oN),this._shouldRender=!0,this.domNode=Hc(document.createElement("div")),this.domNode.setAttribute("role","presentation"),this.domNode.setAttribute("aria-hidden","true"),this._visibilityController.setDomNode(this.domNode),this.domNode.setPosition("absolute"),this._register(Ge(this.domNode.domNode,Cs.POINTER_DOWN,t=>this._domNodePointerDown(t)))}_createArrow(e){let t=this._register(new J$(e));this.domNode.domNode.appendChild(t.bgDomNode),this.domNode.domNode.appendChild(t.domNode)}_createSlider(e,t,s,n){this.slider=Hc(document.createElement("div")),this.slider.setClassName("slider"),this.slider.setPosition("absolute"),this.slider.setTop(e),this.slider.setLeft(t),typeof s=="number"&&this.slider.setWidth(s),typeof n=="number"&&this.slider.setHeight(n),this.slider.setLayerHinting(!0),this.slider.setContain("strict"),this.domNode.domNode.appendChild(this.slider.domNode),this._register(Ge(this.slider.domNode,Cs.POINTER_DOWN,a=>{a.button===0&&(a.preventDefault(),this._sliderPointerDown(a))})),this.onclick(this.slider.domNode,a=>{a.leftButton&&a.stopPropagation()})}_onElementSize(e){return this._scrollbarState.setVisibleSize(e)&&(this._visibilityController.setIsNeeded(this._scrollbarState.isNeeded()),this._shouldRender=!0,this._lazyRender||this.render()),this._shouldRender}_onElementScrollSize(e){return this._scrollbarState.setScrollSize(e)&&(this._visibilityController.setIsNeeded(this._scrollbarState.isNeeded()),this._shouldRender=!0,this._lazyRender||this.render()),this._shouldRender}_onElementScrollPosition(e){return this._scrollbarState.setScrollPosition(e)&&(this._visibilityController.setIsNeeded(this._scrollbarState.isNeeded()),this._shouldRender=!0,this._lazyRender||this.render()),this._shouldRender}beginReveal(){this._visibilityController.setShouldBeVisible(!0)}beginHide(){this._visibilityController.setShouldBeVisible(!1)}render(){this._shouldRender&&(this._shouldRender=!1,this._renderDomNode(this._scrollbarState.getRectangleLargeSize(),this._scrollbarState.getRectangleSmallSize()),this._updateSlider(this._scrollbarState.getSliderSize(),this._scrollbarState.getArrowSize()+this._scrollbarState.getSliderPosition()))}_domNodePointerDown(e){e.target===this.domNode.domNode&&this._onPointerDown(e)}delegatePointerDown(e){let t=this.domNode.domNode.getClientRects()[0].top,s=t+this._scrollbarState.getSliderPosition(),n=t+this._scrollbarState.getSliderPosition()+this._scrollbarState.getSliderSize(),a=this._sliderPointerPosition(e);s<=a&&a<=n?e.button===0&&(e.preventDefault(),this._sliderPointerDown(e)):this._onPointerDown(e)}_onPointerDown(e){let t,s;if(e.target===this.domNode.domNode&&typeof e.offsetX=="number"&&typeof e.offsetY=="number")t=e.offsetX,s=e.offsetY;else{let a=G$(this.domNode.domNode);t=e.pageX-a.left,s=e.pageY-a.top}let n=this._pointerDownRelativePosition(t,s);this._setDesiredScrollPositionNow(this._scrollByPage?this._scrollbarState.getDesiredScrollPositionFromOffsetPaged(n):this._scrollbarState.getDesiredScrollPositionFromOffset(n)),e.button===0&&(e.preventDefault(),this._sliderPointerDown(e))}_sliderPointerDown(e){if(!e.target||!(e.target instanceof Element))return;let t=this._sliderPointerPosition(e),s=this._sliderOrthogonalPointerPosition(e),n=this._scrollbarState.clone();this.slider.toggleClassName("active",!0),this._pointerMoveMonitor.startMonitoring(e.target,e.pointerId,e.buttons,a=>{let l=this._sliderOrthogonalPointerPosition(a),c=Math.abs(l-s);if(nN&&c>rI){this._setDesiredScrollPositionNow(n.getScrollPosition());return}let d=this._sliderPointerPosition(a)-t;this._setDesiredScrollPositionNow(n.getDesiredScrollPositionFromDelta(d))},()=>{this.slider.toggleClassName("active",!1),this._host.onDragEnd()}),this._host.onDragStart()}_setDesiredScrollPositionNow(e){let t={};this.writeScrollPosition(t,e),this._scrollable.setScrollPositionNow(t)}updateScrollbarSize(e){this._updateScrollbarSize(e),this._scrollbarState.setScrollbarSize(e),this._shouldRender=!0,this._lazyRender||this.render()}isNeeded(){return this._scrollbarState.isNeeded()}},cN=class Xx{constructor(t,s,n,a,l,c){this._scrollbarSize=Math.round(s),this._oppositeScrollbarSize=Math.round(n),this._arrowSize=Math.round(t),this._visibleSize=a,this._scrollSize=l,this._scrollPosition=c,this._computedAvailableSize=0,this._computedIsNeeded=!1,this._computedSliderSize=0,this._computedSliderRatio=0,this._computedSliderPosition=0,this._refreshComputedValues()}clone(){return new Xx(this._arrowSize,this._scrollbarSize,this._oppositeScrollbarSize,this._visibleSize,this._scrollSize,this._scrollPosition)}setVisibleSize(t){let s=Math.round(t);return this._visibleSize!==s?(this._visibleSize=s,this._refreshComputedValues(),!0):!1}setScrollSize(t){let s=Math.round(t);return this._scrollSize!==s?(this._scrollSize=s,this._refreshComputedValues(),!0):!1}setScrollPosition(t){let s=Math.round(t);return this._scrollPosition!==s?(this._scrollPosition=s,this._refreshComputedValues(),!0):!1}setScrollbarSize(t){this._scrollbarSize=Math.round(t)}setOppositeScrollbarSize(t){this._oppositeScrollbarSize=Math.round(t)}static _computeValues(t,s,n,a,l){let c=Math.max(0,n-t),d=Math.max(0,c-2*s),f=a>0&&a>n;if(!f)return{computedAvailableSize:Math.round(c),computedIsNeeded:f,computedSliderSize:Math.round(d),computedSliderRatio:0,computedSliderPosition:0};let h=Math.round(Math.max(20,Math.floor(n*d/a))),m=(d-h)/(a-n),g=l*m;return{computedAvailableSize:Math.round(c),computedIsNeeded:f,computedSliderSize:Math.round(h),computedSliderRatio:m,computedSliderPosition:Math.round(g)}}_refreshComputedValues(){let t=Xx._computeValues(this._oppositeScrollbarSize,this._arrowSize,this._visibleSize,this._scrollSize,this._scrollPosition);this._computedAvailableSize=t.computedAvailableSize,this._computedIsNeeded=t.computedIsNeeded,this._computedSliderSize=t.computedSliderSize,this._computedSliderRatio=t.computedSliderRatio,this._computedSliderPosition=t.computedSliderPosition}getArrowSize(){return this._arrowSize}getScrollPosition(){return this._scrollPosition}getRectangleLargeSize(){return this._computedAvailableSize}getRectangleSmallSize(){return this._scrollbarSize}isNeeded(){return this._computedIsNeeded}getSliderSize(){return this._computedSliderSize}getSliderPosition(){return this._computedSliderPosition}getDesiredScrollPositionFromOffset(t){if(!this._computedIsNeeded)return 0;let s=t-this._arrowSize-this._computedSliderSize/2;return Math.round(s/this._computedSliderRatio)}getDesiredScrollPositionFromOffsetPaged(t){if(!this._computedIsNeeded)return 0;let s=t-this._arrowSize,n=this._scrollPosition;return s<this._computedSliderPosition?n-=this._visibleSize:n+=this._visibleSize,n}getDesiredScrollPositionFromDelta(t){if(!this._computedIsNeeded)return 0;let s=this._computedSliderPosition+t;return Math.round(s/this._computedSliderRatio)}},iI=class extends lN{constructor(e,t,s){let n=e.getScrollDimensions(),a=e.getCurrentScrollPosition();if(super({lazyRender:t.lazyRender,host:s,scrollbarState:new cN(t.horizontalHasArrows?t.arrowSize:0,t.horizontal===2?0:t.horizontalScrollbarSize,t.vertical===2?0:t.verticalScrollbarSize,n.width,n.scrollWidth,a.scrollLeft),visibility:t.horizontal,extraScrollbarClassName:"horizontal",scrollable:e,scrollByPage:t.scrollByPage}),t.horizontalHasArrows)throw new Error("horizontalHasArrows is not supported in xterm.js");this._createSlider(Math.floor((t.horizontalScrollbarSize-t.horizontalSliderSize)/2),0,void 0,t.horizontalSliderSize)}_updateSlider(e,t){this.slider.setWidth(e),this.slider.setLeft(t)}_renderDomNode(e,t){this.domNode.setWidth(e),this.domNode.setHeight(t),this.domNode.setLeft(0),this.domNode.setBottom(0)}onDidScroll(e){return this._shouldRender=this._onElementScrollSize(e.scrollWidth)||this._shouldRender,this._shouldRender=this._onElementScrollPosition(e.scrollLeft)||this._shouldRender,this._shouldRender=this._onElementSize(e.width)||this._shouldRender,this._shouldRender}_pointerDownRelativePosition(e,t){return e}_sliderPointerPosition(e){return e.pageX}_sliderOrthogonalPointerPosition(e){return e.pageY}_updateScrollbarSize(e){this.slider.setHeight(e)}writeScrollPosition(e,t){e.scrollLeft=t}updateOptions(e){this.updateScrollbarSize(e.horizontal===2?0:e.horizontalScrollbarSize),this._scrollbarState.setOppositeScrollbarSize(e.vertical===2?0:e.verticalScrollbarSize),this._visibilityController.setVisibility(e.horizontal),this._scrollByPage=e.scrollByPage}},aI=class extends lN{constructor(e,t,s){let n=e.getScrollDimensions(),a=e.getCurrentScrollPosition();if(super({lazyRender:t.lazyRender,host:s,scrollbarState:new cN(t.verticalHasArrows?t.arrowSize:0,t.vertical===2?0:t.verticalScrollbarSize,0,n.height,n.scrollHeight,a.scrollTop),visibility:t.vertical,extraScrollbarClassName:"vertical",scrollable:e,scrollByPage:t.scrollByPage}),t.verticalHasArrows)throw new Error("horizontalHasArrows is not supported in xterm.js");this._createSlider(0,Math.floor((t.verticalScrollbarSize-t.verticalSliderSize)/2),t.verticalSliderSize,void 0)}_updateSlider(e,t){this.slider.setHeight(e),this.slider.setTop(t)}_renderDomNode(e,t){this.domNode.setWidth(t),this.domNode.setHeight(e),this.domNode.setRight(0),this.domNode.setTop(0)}onDidScroll(e){return this._shouldRender=this._onElementScrollSize(e.scrollHeight)||this._shouldRender,this._shouldRender=this._onElementScrollPosition(e.scrollTop)||this._shouldRender,this._shouldRender=this._onElementSize(e.height)||this._shouldRender,this._shouldRender}_pointerDownRelativePosition(e,t){return t}_sliderPointerPosition(e){return e.pageY}_sliderOrthogonalPointerPosition(e){return e.pageX}_updateScrollbarSize(e){this.slider.setWidth(e)}writeScrollPosition(e,t){e.scrollTop=t}updateOptions(e){this.updateScrollbarSize(e.vertical===2?0:e.verticalScrollbarSize),this._scrollbarState.setOppositeScrollbarSize(0),this._visibilityController.setVisibility(e.vertical),this._scrollByPage=e.scrollByPage}},oI=500,A2=50,lI=class{constructor(e,t,s){this.timestamp=e,this.deltaX=t,this.deltaY=s,this.score=0}},Jx=class{constructor(){this._capacity=5,this._memory=[],this._front=-1,this._rear=-1}isPhysicalMouseWheel(){if(this._front===-1&&this._rear===-1)return!1;let t=1,s=0,n=1,a=this._rear;do{let l=a===this._front?t:Math.pow(2,-n);if(t-=l,s+=this._memory[a].score*l,a===this._front)break;a=(this._capacity+a-1)%this._capacity,n++}while(!0);return s<=.5}acceptStandardWheelEvent(t){if(uv){let s=wr(t.browserEvent),n=b$(s);this.accept(Date.now(),t.deltaX*n,t.deltaY*n)}else this.accept(Date.now(),t.deltaX,t.deltaY)}accept(t,s,n){let a=null,l=new lI(t,s,n);this._front===-1&&this._rear===-1?(this._memory[0]=l,this._front=0,this._rear=0):(a=this._memory[this._rear],this._rear=(this._rear+1)%this._capacity,this._rear===this._front&&(this._front=(this._front+1)%this._capacity),this._memory[this._rear]=l),l.score=this._computeScore(l,a)}_computeScore(t,s){if(Math.abs(t.deltaX)>0&&Math.abs(t.deltaY)>0)return 1;let n=.5;if((!this._isAlmostInt(t.deltaX)||!this._isAlmostInt(t.deltaY))&&(n+=.25),s){let a=Math.abs(t.deltaX),l=Math.abs(t.deltaY),c=Math.abs(s.deltaX),d=Math.abs(s.deltaY),f=Math.max(Math.min(a,c),1),h=Math.max(Math.min(l,d),1),m=Math.max(a,c),g=Math.max(l,d);m%f===0&&g%h===0&&(n-=.5)}return Math.min(Math.max(n,0),1)}_isAlmostInt(t){return Math.abs(Math.round(t)-t)<.01}};Jx.INSTANCE=new Jx;var cI=Jx,uI=class extends pv{constructor(e,t,s){super(),this._onScroll=this._register(new Ce),this.onScroll=this._onScroll.event,this._onWillScroll=this._register(new Ce),this.onWillScroll=this._onWillScroll.event,this._options=hI(t),this._scrollable=s,this._register(this._scrollable.onScroll(a=>{this._onWillScroll.fire(a),this._onDidScroll(a),this._onScroll.fire(a)}));let n={onMouseWheel:a=>this._onMouseWheel(a),onDragStart:()=>this._onDragStart(),onDragEnd:()=>this._onDragEnd()};this._verticalScrollbar=this._register(new aI(this._scrollable,this._options,n)),this._horizontalScrollbar=this._register(new iI(this._scrollable,this._options,n)),this._domNode=document.createElement("div"),this._domNode.className="xterm-scrollable-element "+this._options.className,this._domNode.setAttribute("role","presentation"),this._domNode.style.position="relative",this._domNode.appendChild(e),this._domNode.appendChild(this._horizontalScrollbar.domNode.domNode),this._domNode.appendChild(this._verticalScrollbar.domNode.domNode),this._options.useShadows?(this._leftShadowDomNode=Hc(document.createElement("div")),this._leftShadowDomNode.setClassName("shadow"),this._domNode.appendChild(this._leftShadowDomNode.domNode),this._topShadowDomNode=Hc(document.createElement("div")),this._topShadowDomNode.setClassName("shadow"),this._domNode.appendChild(this._topShadowDomNode.domNode),this._topLeftShadowDomNode=Hc(document.createElement("div")),this._topLeftShadowDomNode.setClassName("shadow"),this._domNode.appendChild(this._topLeftShadowDomNode.domNode)):(this._leftShadowDomNode=null,this._topShadowDomNode=null,this._topLeftShadowDomNode=null),this._listenOnDomNode=this._options.listenOnDomNode||this._domNode,this._mouseWheelToDispose=[],this._setListeningToMouseWheel(this._options.handleMouseWheel),this.onmouseover(this._listenOnDomNode,a=>this._onMouseOver(a)),this.onmouseleave(this._listenOnDomNode,a=>this._onMouseLeave(a)),this._hideTimeout=this._register(new hv),this._isDragging=!1,this._mouseIsOver=!1,this._shouldRender=!0,this._revealOnScroll=!0}get options(){return this._options}dispose(){this._mouseWheelToDispose=Ra(this._mouseWheelToDispose),super.dispose()}getDomNode(){return this._domNode}getOverviewRulerLayoutInfo(){return{parent:this._domNode,insertBefore:this._verticalScrollbar.domNode.domNode}}delegateVerticalScrollbarPointerDown(e){this._verticalScrollbar.delegatePointerDown(e)}getScrollDimensions(){return this._scrollable.getScrollDimensions()}setScrollDimensions(e){this._scrollable.setScrollDimensions(e,!1)}updateClassName(e){this._options.className=e,Sr&&(this._options.className+=" mac"),this._domNode.className="xterm-scrollable-element "+this._options.className}updateOptions(e){typeof e.handleMouseWheel<"u"&&(this._options.handleMouseWheel=e.handleMouseWheel,this._setListeningToMouseWheel(this._options.handleMouseWheel)),typeof e.mouseWheelScrollSensitivity<"u"&&(this._options.mouseWheelScrollSensitivity=e.mouseWheelScrollSensitivity),typeof e.fastScrollSensitivity<"u"&&(this._options.fastScrollSensitivity=e.fastScrollSensitivity),typeof e.scrollPredominantAxis<"u"&&(this._options.scrollPredominantAxis=e.scrollPredominantAxis),typeof e.horizontal<"u"&&(this._options.horizontal=e.horizontal),typeof e.vertical<"u"&&(this._options.vertical=e.vertical),typeof e.horizontalScrollbarSize<"u"&&(this._options.horizontalScrollbarSize=e.horizontalScrollbarSize),typeof e.verticalScrollbarSize<"u"&&(this._options.verticalScrollbarSize=e.verticalScrollbarSize),typeof e.scrollByPage<"u"&&(this._options.scrollByPage=e.scrollByPage),this._horizontalScrollbar.updateOptions(this._options),this._verticalScrollbar.updateOptions(this._options),this._options.lazyRender||this._render()}setRevealOnScroll(e){this._revealOnScroll=e}delegateScrollFromMouseWheelEvent(e){this._onMouseWheel(new j2(e))}_setListeningToMouseWheel(e){if(this._mouseWheelToDispose.length>0!==e&&(this._mouseWheelToDispose=Ra(this._mouseWheelToDispose),e)){let t=s=>{this._onMouseWheel(new j2(s))};this._mouseWheelToDispose.push(Ge(this._listenOnDomNode,Cs.MOUSE_WHEEL,t,{passive:!1}))}}_onMouseWheel(e){var a;if((a=e.browserEvent)!=null&&a.defaultPrevented)return;let t=cI.INSTANCE;t.acceptStandardWheelEvent(e);let s=!1;if(e.deltaY||e.deltaX){let l=e.deltaY*this._options.mouseWheelScrollSensitivity,c=e.deltaX*this._options.mouseWheelScrollSensitivity;this._options.scrollPredominantAxis&&(this._options.scrollYToX&&c+l===0?c=l=0:Math.abs(l)>=Math.abs(c)?c=0:l=0),this._options.flipAxes&&([l,c]=[c,l]);let d=!Sr&&e.browserEvent&&e.browserEvent.shiftKey;(this._options.scrollYToX||d)&&!c&&(c=l,l=0),e.browserEvent&&e.browserEvent.altKey&&(c=c*this._options.fastScrollSensitivity,l=l*this._options.fastScrollSensitivity);let f=this._scrollable.getFutureScrollPosition(),h={};if(l){let m=A2*l,g=f.scrollTop-(m<0?Math.floor(m):Math.ceil(m));this._verticalScrollbar.writeScrollPosition(h,g)}if(c){let m=A2*c,g=f.scrollLeft-(m<0?Math.floor(m):Math.ceil(m));this._horizontalScrollbar.writeScrollPosition(h,g)}h=this._scrollable.validateScrollPosition(h),(f.scrollLeft!==h.scrollLeft||f.scrollTop!==h.scrollTop)&&(this._options.mouseWheelSmoothScroll&&t.isPhysicalMouseWheel()?this._scrollable.setScrollPositionSmooth(h):this._scrollable.setScrollPositionNow(h),s=!0)}let n=s;!n&&this._options.alwaysConsumeMouseWheel&&(n=!0),!n&&this._options.consumeMouseWheelIfScrollbarIsNeeded&&(this._verticalScrollbar.isNeeded()||this._horizontalScrollbar.isNeeded())&&(n=!0),n&&(e.preventDefault(),e.stopPropagation())}_onDidScroll(e){this._shouldRender=this._horizontalScrollbar.onDidScroll(e)||this._shouldRender,this._shouldRender=this._verticalScrollbar.onDidScroll(e)||this._shouldRender,this._options.useShadows&&(this._shouldRender=!0),this._revealOnScroll&&this._reveal(),this._options.lazyRender||this._render()}renderNow(){if(!this._options.lazyRender)throw new Error("Please use `lazyRender` together with `renderNow`!");this._render()}_render(){if(this._shouldRender&&(this._shouldRender=!1,this._horizontalScrollbar.render(),this._verticalScrollbar.render(),this._options.useShadows)){let e=this._scrollable.getCurrentScrollPosition(),t=e.scrollTop>0,s=e.scrollLeft>0,n=s?" left":"",a=t?" top":"",l=s||t?" top-left-corner":"";this._leftShadowDomNode.setClassName(`shadow${n}`),this._topShadowDomNode.setClassName(`shadow${a}`),this._topLeftShadowDomNode.setClassName(`shadow${l}${a}${n}`)}}_onDragStart(){this._isDragging=!0,this._reveal()}_onDragEnd(){this._isDragging=!1,this._hide()}_onMouseLeave(e){this._mouseIsOver=!1,this._hide()}_onMouseOver(e){this._mouseIsOver=!0,this._reveal()}_reveal(){this._verticalScrollbar.beginReveal(),this._horizontalScrollbar.beginReveal(),this._scheduleHide()}_hide(){!this._mouseIsOver&&!this._isDragging&&(this._verticalScrollbar.beginHide(),this._horizontalScrollbar.beginHide())}_scheduleHide(){!this._mouseIsOver&&!this._isDragging&&this._hideTimeout.cancelAndSet(()=>this._hide(),oI)}},dI=class extends uI{constructor(e,t,s){super(e,t,s)}setScrollPosition(e){e.reuseAnimation?this._scrollable.setScrollPositionSmooth(e,e.reuseAnimation):this._scrollable.setScrollPositionNow(e)}getScrollPosition(){return this._scrollable.getCurrentScrollPosition()}};function hI(e){let t={lazyRender:typeof e.lazyRender<"u"?e.lazyRender:!1,className:typeof e.className<"u"?e.className:"",useShadows:typeof e.useShadows<"u"?e.useShadows:!0,handleMouseWheel:typeof e.handleMouseWheel<"u"?e.handleMouseWheel:!0,flipAxes:typeof e.flipAxes<"u"?e.flipAxes:!1,consumeMouseWheelIfScrollbarIsNeeded:typeof e.consumeMouseWheelIfScrollbarIsNeeded<"u"?e.consumeMouseWheelIfScrollbarIsNeeded:!1,alwaysConsumeMouseWheel:typeof e.alwaysConsumeMouseWheel<"u"?e.alwaysConsumeMouseWheel:!1,scrollYToX:typeof e.scrollYToX<"u"?e.scrollYToX:!1,mouseWheelScrollSensitivity:typeof e.mouseWheelScrollSensitivity<"u"?e.mouseWheelScrollSensitivity:1,fastScrollSensitivity:typeof e.fastScrollSensitivity<"u"?e.fastScrollSensitivity:5,scrollPredominantAxis:typeof e.scrollPredominantAxis<"u"?e.scrollPredominantAxis:!0,mouseWheelSmoothScroll:typeof e.mouseWheelSmoothScroll<"u"?e.mouseWheelSmoothScroll:!0,arrowSize:typeof e.arrowSize<"u"?e.arrowSize:11,listenOnDomNode:typeof e.listenOnDomNode<"u"?e.listenOnDomNode:null,horizontal:typeof e.horizontal<"u"?e.horizontal:1,horizontalScrollbarSize:typeof e.horizontalScrollbarSize<"u"?e.horizontalScrollbarSize:10,horizontalSliderSize:typeof e.horizontalSliderSize<"u"?e.horizontalSliderSize:0,horizontalHasArrows:typeof e.horizontalHasArrows<"u"?e.horizontalHasArrows:!1,vertical:typeof e.vertical<"u"?e.vertical:1,verticalScrollbarSize:typeof e.verticalScrollbarSize<"u"?e.verticalScrollbarSize:10,verticalHasArrows:typeof e.verticalHasArrows<"u"?e.verticalHasArrows:!1,verticalSliderSize:typeof e.verticalSliderSize<"u"?e.verticalSliderSize:0,scrollByPage:typeof e.scrollByPage<"u"?e.scrollByPage:!1};return t.horizontalSliderSize=typeof e.horizontalSliderSize<"u"?e.horizontalSliderSize:t.horizontalScrollbarSize,t.verticalSliderSize=typeof e.verticalSliderSize<"u"?e.verticalSliderSize:t.verticalScrollbarSize,Sr&&(t.className+=" mac"),t}var Qx=class extends nt{constructor(e,t,s,n,a,l,c,d){super(),this._bufferService=s,this._optionsService=c,this._renderService=d,this._onRequestScrollLines=this._register(new Ce),this.onRequestScrollLines=this._onRequestScrollLines.event,this._isSyncing=!1,this._isHandlingScroll=!1,this._suppressOnScrollHandler=!1;let f=this._register(new Z$({forceIntegerValues:!1,smoothScrollDuration:this._optionsService.rawOptions.smoothScrollDuration,scheduleAtNextAnimationFrame:h=>fv(n.window,h)}));this._register(this._optionsService.onSpecificOptionChange("smoothScrollDuration",()=>{f.setSmoothScrollDuration(this._optionsService.rawOptions.smoothScrollDuration)})),this._scrollableElement=this._register(new dI(t,{vertical:1,horizontal:2,useShadows:!1,mouseWheelSmoothScroll:!0,...this._getChangeOptions()},f)),this._register(this._optionsService.onMultipleOptionChange(["scrollSensitivity","fastScrollSensitivity","overviewRuler"],()=>this._scrollableElement.updateOptions(this._getChangeOptions()))),this._register(a.onProtocolChange(h=>{this._scrollableElement.updateOptions({handleMouseWheel:!(h&16)})})),this._scrollableElement.setScrollDimensions({height:0,scrollHeight:0}),this._register(Is.runAndSubscribe(l.onChangeColors,()=>{this._scrollableElement.getDomNode().style.backgroundColor=l.colors.background.css})),e.appendChild(this._scrollableElement.getDomNode()),this._register(Ut(()=>this._scrollableElement.getDomNode().remove())),this._styleElement=n.mainDocument.createElement("style"),t.appendChild(this._styleElement),this._register(Ut(()=>this._styleElement.remove())),this._register(Is.runAndSubscribe(l.onChangeColors,()=>{this._styleElement.textContent=[".xterm .xterm-scrollable-element > .scrollbar > .slider {",` background: ${l.colors.scrollbarSliderBackground.css};`,"}",".xterm .xterm-scrollable-element > .scrollbar > .slider:hover {",` background: ${l.colors.scrollbarSliderHoverBackground.css};`,"}",".xterm .xterm-scrollable-element > .scrollbar > .slider.active {",` background: ${l.colors.scrollbarSliderActiveBackground.css};`,"}"].join(`
|
|
253
|
-
`)})),this._register(this._bufferService.onResize(()=>this.queueSync())),this._register(this._bufferService.buffers.onBufferActivate(()=>{this._latestYDisp=void 0,this.queueSync()})),this._register(this._bufferService.onScroll(()=>this._sync())),this._register(this._scrollableElement.onScroll(h=>this._handleScroll(h)))}scrollLines(e){let t=this._scrollableElement.getScrollPosition();this._scrollableElement.setScrollPosition({reuseAnimation:!0,scrollTop:t.scrollTop+e*this._renderService.dimensions.css.cell.height})}scrollToLine(e,t){t&&(this._latestYDisp=e),this._scrollableElement.setScrollPosition({reuseAnimation:!t,scrollTop:e*this._renderService.dimensions.css.cell.height})}_getChangeOptions(){var e;return{mouseWheelScrollSensitivity:this._optionsService.rawOptions.scrollSensitivity,fastScrollSensitivity:this._optionsService.rawOptions.fastScrollSensitivity,verticalScrollbarSize:((e=this._optionsService.rawOptions.overviewRuler)==null?void 0:e.width)||14}}queueSync(e){e!==void 0&&(this._latestYDisp=e),this._queuedAnimationFrame===void 0&&(this._queuedAnimationFrame=this._renderService.addRefreshCallback(()=>{this._queuedAnimationFrame=void 0,this._sync(this._latestYDisp)}))}_sync(e=this._bufferService.buffer.ydisp){!this._renderService||this._isSyncing||(this._isSyncing=!0,this._suppressOnScrollHandler=!0,this._scrollableElement.setScrollDimensions({height:this._renderService.dimensions.css.canvas.height,scrollHeight:this._renderService.dimensions.css.cell.height*this._bufferService.buffer.lines.length}),this._suppressOnScrollHandler=!1,e!==this._latestYDisp&&this._scrollableElement.setScrollPosition({scrollTop:e*this._renderService.dimensions.css.cell.height}),this._isSyncing=!1)}_handleScroll(e){if(!this._renderService||this._isHandlingScroll||this._suppressOnScrollHandler)return;this._isHandlingScroll=!0;let t=Math.round(e.scrollTop/this._renderService.dimensions.css.cell.height),s=t-this._bufferService.buffer.ydisp;s!==0&&(this._latestYDisp=t,this._onRequestScrollLines.fire(s)),this._isHandlingScroll=!1}};Qx=ts([Re(2,sn),Re(3,ai),Re(4,UC),Re(5,tl),Re(6,nn),Re(7,oi)],Qx);var Zx=class extends nt{constructor(e,t,s,n,a){super(),this._screenElement=e,this._bufferService=t,this._coreBrowserService=s,this._decorationService=n,this._renderService=a,this._decorationElements=new Map,this._altBufferIsActive=!1,this._dimensionsChanged=!1,this._container=document.createElement("div"),this._container.classList.add("xterm-decoration-container"),this._screenElement.appendChild(this._container),this._register(this._renderService.onRenderedViewportChange(()=>this._doRefreshDecorations())),this._register(this._renderService.onDimensionsChange(()=>{this._dimensionsChanged=!0,this._queueRefresh()})),this._register(this._coreBrowserService.onDprChange(()=>this._queueRefresh())),this._register(this._bufferService.buffers.onBufferActivate(()=>{this._altBufferIsActive=this._bufferService.buffer===this._bufferService.buffers.alt})),this._register(this._decorationService.onDecorationRegistered(()=>this._queueRefresh())),this._register(this._decorationService.onDecorationRemoved(l=>this._removeDecoration(l))),this._register(Ut(()=>{this._container.remove(),this._decorationElements.clear()}))}_queueRefresh(){this._animationFrame===void 0&&(this._animationFrame=this._renderService.addRefreshCallback(()=>{this._doRefreshDecorations(),this._animationFrame=void 0}))}_doRefreshDecorations(){for(let e of this._decorationService.decorations)this._renderDecoration(e);this._dimensionsChanged=!1}_renderDecoration(e){this._refreshStyle(e),this._dimensionsChanged&&this._refreshXPosition(e)}_createElement(e){var n;let t=this._coreBrowserService.mainDocument.createElement("div");t.classList.add("xterm-decoration"),t.classList.toggle("xterm-decoration-top-layer",((n=e==null?void 0:e.options)==null?void 0:n.layer)==="top"),t.style.width=`${Math.round((e.options.width||1)*this._renderService.dimensions.css.cell.width)}px`,t.style.height=`${(e.options.height||1)*this._renderService.dimensions.css.cell.height}px`,t.style.top=`${(e.marker.line-this._bufferService.buffers.active.ydisp)*this._renderService.dimensions.css.cell.height}px`,t.style.lineHeight=`${this._renderService.dimensions.css.cell.height}px`;let s=e.options.x??0;return s&&s>this._bufferService.cols&&(t.style.display="none"),this._refreshXPosition(e,t),t}_refreshStyle(e){let t=e.marker.line-this._bufferService.buffers.active.ydisp;if(t<0||t>=this._bufferService.rows)e.element&&(e.element.style.display="none",e.onRenderEmitter.fire(e.element));else{let s=this._decorationElements.get(e);s||(s=this._createElement(e),e.element=s,this._decorationElements.set(e,s),this._container.appendChild(s),e.onDispose(()=>{this._decorationElements.delete(e),s.remove()})),s.style.display=this._altBufferIsActive?"none":"block",this._altBufferIsActive||(s.style.width=`${Math.round((e.options.width||1)*this._renderService.dimensions.css.cell.width)}px`,s.style.height=`${(e.options.height||1)*this._renderService.dimensions.css.cell.height}px`,s.style.top=`${t*this._renderService.dimensions.css.cell.height}px`,s.style.lineHeight=`${this._renderService.dimensions.css.cell.height}px`),e.onRenderEmitter.fire(s)}}_refreshXPosition(e,t=e.element){if(!t)return;let s=e.options.x??0;(e.options.anchor||"left")==="right"?t.style.right=s?`${s*this._renderService.dimensions.css.cell.width}px`:"":t.style.left=s?`${s*this._renderService.dimensions.css.cell.width}px`:""}_removeDecoration(e){var t;(t=this._decorationElements.get(e))==null||t.remove(),this._decorationElements.delete(e),e.dispose()}};Zx=ts([Re(1,sn),Re(2,ai),Re(3,mu),Re(4,oi)],Zx);var fI=class{constructor(){this._zones=[],this._zonePool=[],this._zonePoolIndex=0,this._linePadding={full:0,left:0,center:0,right:0}}get zones(){return this._zonePool.length=Math.min(this._zonePool.length,this._zones.length),this._zones}clear(){this._zones.length=0,this._zonePoolIndex=0}addDecoration(e){if(e.options.overviewRulerOptions){for(let t of this._zones)if(t.color===e.options.overviewRulerOptions.color&&t.position===e.options.overviewRulerOptions.position){if(this._lineIntersectsZone(t,e.marker.line))return;if(this._lineAdjacentToZone(t,e.marker.line,e.options.overviewRulerOptions.position)){this._addLineToZone(t,e.marker.line);return}}if(this._zonePoolIndex<this._zonePool.length){this._zonePool[this._zonePoolIndex].color=e.options.overviewRulerOptions.color,this._zonePool[this._zonePoolIndex].position=e.options.overviewRulerOptions.position,this._zonePool[this._zonePoolIndex].startBufferLine=e.marker.line,this._zonePool[this._zonePoolIndex].endBufferLine=e.marker.line,this._zones.push(this._zonePool[this._zonePoolIndex++]);return}this._zones.push({color:e.options.overviewRulerOptions.color,position:e.options.overviewRulerOptions.position,startBufferLine:e.marker.line,endBufferLine:e.marker.line}),this._zonePool.push(this._zones[this._zones.length-1]),this._zonePoolIndex++}}setPadding(e){this._linePadding=e}_lineIntersectsZone(e,t){return t>=e.startBufferLine&&t<=e.endBufferLine}_lineAdjacentToZone(e,t,s){return t>=e.startBufferLine-this._linePadding[s||"full"]&&t<=e.endBufferLine+this._linePadding[s||"full"]}_addLineToZone(e,t){e.startBufferLine=Math.min(e.startBufferLine,t),e.endBufferLine=Math.max(e.endBufferLine,t)}},pr={full:0,left:0,center:0,right:0},zi={full:0,left:0,center:0,right:0},dc={full:0,left:0,center:0,right:0},Ph=class extends nt{constructor(e,t,s,n,a,l,c,d){var h;super(),this._viewportElement=e,this._screenElement=t,this._bufferService=s,this._decorationService=n,this._renderService=a,this._optionsService=l,this._themeService=c,this._coreBrowserService=d,this._colorZoneStore=new fI,this._shouldUpdateDimensions=!0,this._shouldUpdateAnchor=!0,this._lastKnownBufferLength=0,this._canvas=this._coreBrowserService.mainDocument.createElement("canvas"),this._canvas.classList.add("xterm-decoration-overview-ruler"),this._refreshCanvasDimensions(),(h=this._viewportElement.parentElement)==null||h.insertBefore(this._canvas,this._viewportElement),this._register(Ut(()=>{var m;return(m=this._canvas)==null?void 0:m.remove()}));let f=this._canvas.getContext("2d");if(f)this._ctx=f;else throw new Error("Ctx cannot be null");this._register(this._decorationService.onDecorationRegistered(()=>this._queueRefresh(void 0,!0))),this._register(this._decorationService.onDecorationRemoved(()=>this._queueRefresh(void 0,!0))),this._register(this._renderService.onRenderedViewportChange(()=>this._queueRefresh())),this._register(this._bufferService.buffers.onBufferActivate(()=>{this._canvas.style.display=this._bufferService.buffer===this._bufferService.buffers.alt?"none":"block"})),this._register(this._bufferService.onScroll(()=>{this._lastKnownBufferLength!==this._bufferService.buffers.normal.lines.length&&(this._refreshDrawHeightConstants(),this._refreshColorZonePadding())})),this._register(this._renderService.onRender(()=>{(!this._containerHeight||this._containerHeight!==this._screenElement.clientHeight)&&(this._queueRefresh(!0),this._containerHeight=this._screenElement.clientHeight)})),this._register(this._coreBrowserService.onDprChange(()=>this._queueRefresh(!0))),this._register(this._optionsService.onSpecificOptionChange("overviewRuler",()=>this._queueRefresh(!0))),this._register(this._themeService.onChangeColors(()=>this._queueRefresh())),this._queueRefresh(!0)}get _width(){var e;return((e=this._optionsService.options.overviewRuler)==null?void 0:e.width)||0}_refreshDrawConstants(){let e=Math.floor((this._canvas.width-1)/3),t=Math.ceil((this._canvas.width-1)/3);zi.full=this._canvas.width,zi.left=e,zi.center=t,zi.right=e,this._refreshDrawHeightConstants(),dc.full=1,dc.left=1,dc.center=1+zi.left,dc.right=1+zi.left+zi.center}_refreshDrawHeightConstants(){pr.full=Math.round(2*this._coreBrowserService.dpr);let e=this._canvas.height/this._bufferService.buffer.lines.length,t=Math.round(Math.max(Math.min(e,12),6)*this._coreBrowserService.dpr);pr.left=t,pr.center=t,pr.right=t}_refreshColorZonePadding(){this._colorZoneStore.setPadding({full:Math.floor(this._bufferService.buffers.active.lines.length/(this._canvas.height-1)*pr.full),left:Math.floor(this._bufferService.buffers.active.lines.length/(this._canvas.height-1)*pr.left),center:Math.floor(this._bufferService.buffers.active.lines.length/(this._canvas.height-1)*pr.center),right:Math.floor(this._bufferService.buffers.active.lines.length/(this._canvas.height-1)*pr.right)}),this._lastKnownBufferLength=this._bufferService.buffers.normal.lines.length}_refreshCanvasDimensions(){this._canvas.style.width=`${this._width}px`,this._canvas.width=Math.round(this._width*this._coreBrowserService.dpr),this._canvas.style.height=`${this._screenElement.clientHeight}px`,this._canvas.height=Math.round(this._screenElement.clientHeight*this._coreBrowserService.dpr),this._refreshDrawConstants(),this._refreshColorZonePadding()}_refreshDecorations(){this._shouldUpdateDimensions&&this._refreshCanvasDimensions(),this._ctx.clearRect(0,0,this._canvas.width,this._canvas.height),this._colorZoneStore.clear();for(let t of this._decorationService.decorations)this._colorZoneStore.addDecoration(t);this._ctx.lineWidth=1,this._renderRulerOutline();let e=this._colorZoneStore.zones;for(let t of e)t.position!=="full"&&this._renderColorZone(t);for(let t of e)t.position==="full"&&this._renderColorZone(t);this._shouldUpdateDimensions=!1,this._shouldUpdateAnchor=!1}_renderRulerOutline(){this._ctx.fillStyle=this._themeService.colors.overviewRulerBorder.css,this._ctx.fillRect(0,0,1,this._canvas.height),this._optionsService.rawOptions.overviewRuler.showTopBorder&&this._ctx.fillRect(1,0,this._canvas.width-1,1),this._optionsService.rawOptions.overviewRuler.showBottomBorder&&this._ctx.fillRect(1,this._canvas.height-1,this._canvas.width-1,this._canvas.height)}_renderColorZone(e){this._ctx.fillStyle=e.color,this._ctx.fillRect(dc[e.position||"full"],Math.round((this._canvas.height-1)*(e.startBufferLine/this._bufferService.buffers.active.lines.length)-pr[e.position||"full"]/2),zi[e.position||"full"],Math.round((this._canvas.height-1)*((e.endBufferLine-e.startBufferLine)/this._bufferService.buffers.active.lines.length)+pr[e.position||"full"]))}_queueRefresh(e,t){this._shouldUpdateDimensions=e||this._shouldUpdateDimensions,this._shouldUpdateAnchor=t||this._shouldUpdateAnchor,this._animationFrame===void 0&&(this._animationFrame=this._coreBrowserService.window.requestAnimationFrame(()=>{this._refreshDecorations(),this._animationFrame=void 0}))}};Ph=ts([Re(2,sn),Re(3,mu),Re(4,oi),Re(5,nn),Re(6,tl),Re(7,ai)],Ph);var xe;(e=>(e.NUL="\0",e.SOH="",e.STX="",e.ETX="",e.EOT="",e.ENQ="",e.ACK="",e.BEL="\x07",e.BS="\b",e.HT=" ",e.LF=`
|
|
254
|
-
`,e.VT="\v",e.FF="\f",e.CR="\r",e.SO="",e.SI="",e.DLE="",e.DC1="",e.DC2="",e.DC3="",e.DC4="",e.NAK="",e.SYN="",e.ETB="",e.CAN="",e.EM="",e.SUB="",e.ESC="\x1B",e.FS="",e.GS="",e.RS="",e.US="",e.SP=" ",e.DEL=""))(xe||(xe={}));var dh;(e=>(e.PAD="",e.HOP="",e.BPH="",e.NBH="",e.IND="",e.NEL="
",e.SSA="",e.ESA="",e.HTS="",e.HTJ="",e.VTS="",e.PLD="",e.PLU="",e.RI="",e.SS2="",e.SS3="",e.DCS="",e.PU1="",e.PU2="",e.STS="",e.CCH="",e.MW="",e.SPA="",e.EPA="",e.SOS="",e.SGCI="",e.SCI="",e.CSI="",e.ST="",e.OSC="",e.PM="",e.APC=""))(dh||(dh={}));var uN;(e=>e.ST=`${xe.ESC}\\`)(uN||(uN={}));var e0=class{constructor(e,t,s,n,a,l){this._textarea=e,this._compositionView=t,this._bufferService=s,this._optionsService=n,this._coreService=a,this._renderService=l,this._isComposing=!1,this._isSendingComposition=!1,this._compositionPosition={start:0,end:0},this._dataAlreadySent=""}get isComposing(){return this._isComposing}compositionstart(){this._isComposing=!0,this._compositionPosition.start=this._textarea.value.length,this._compositionView.textContent="",this._dataAlreadySent="",this._compositionView.classList.add("active")}compositionupdate(e){this._compositionView.textContent=e.data,this.updateCompositionElements(),setTimeout(()=>{this._compositionPosition.end=this._textarea.value.length},0)}compositionend(){this._finalizeComposition(!0)}keydown(e){if(this._isComposing||this._isSendingComposition){if(e.keyCode===20||e.keyCode===229||e.keyCode===16||e.keyCode===17||e.keyCode===18)return!1;this._finalizeComposition(!1)}return e.keyCode===229?(this._handleAnyTextareaChanges(),!1):!0}_finalizeComposition(e){if(this._compositionView.classList.remove("active"),this._isComposing=!1,e){let t={start:this._compositionPosition.start,end:this._compositionPosition.end};this._isSendingComposition=!0,setTimeout(()=>{if(this._isSendingComposition){this._isSendingComposition=!1;let s;t.start+=this._dataAlreadySent.length,this._isComposing?s=this._textarea.value.substring(t.start,this._compositionPosition.start):s=this._textarea.value.substring(t.start),s.length>0&&this._coreService.triggerDataEvent(s,!0)}},0)}else{this._isSendingComposition=!1;let t=this._textarea.value.substring(this._compositionPosition.start,this._compositionPosition.end);this._coreService.triggerDataEvent(t,!0)}}_handleAnyTextareaChanges(){let e=this._textarea.value;setTimeout(()=>{if(!this._isComposing){let t=this._textarea.value,s=t.replace(e,"");this._dataAlreadySent=s,t.length>e.length?this._coreService.triggerDataEvent(s,!0):t.length<e.length?this._coreService.triggerDataEvent(`${xe.DEL}`,!0):t.length===e.length&&t!==e&&this._coreService.triggerDataEvent(t,!0)}},0)}updateCompositionElements(e){if(this._isComposing){if(this._bufferService.buffer.isCursorInViewport){let t=Math.min(this._bufferService.buffer.x,this._bufferService.cols-1),s=this._renderService.dimensions.css.cell.height,n=this._bufferService.buffer.y*this._renderService.dimensions.css.cell.height,a=t*this._renderService.dimensions.css.cell.width;this._compositionView.style.left=a+"px",this._compositionView.style.top=n+"px",this._compositionView.style.height=s+"px",this._compositionView.style.lineHeight=s+"px",this._compositionView.style.fontFamily=this._optionsService.rawOptions.fontFamily,this._compositionView.style.fontSize=this._optionsService.rawOptions.fontSize+"px";let l=this._compositionView.getBoundingClientRect();this._textarea.style.left=a+"px",this._textarea.style.top=n+"px",this._textarea.style.width=Math.max(l.width,1)+"px",this._textarea.style.height=Math.max(l.height,1)+"px",this._textarea.style.lineHeight=l.height+"px"}e||setTimeout(()=>this.updateCompositionElements(!0),0)}}};e0=ts([Re(2,sn),Re(3,nn),Re(4,Ba),Re(5,oi)],e0);var Ns=0,Es=0,Ms=0,es=0,R2={css:"#00000000",rgba:0},ps;(e=>{function t(a,l,c,d){return d!==void 0?`#${_a(a)}${_a(l)}${_a(c)}${_a(d)}`:`#${_a(a)}${_a(l)}${_a(c)}`}e.toCss=t;function s(a,l,c,d=255){return(a<<24|l<<16|c<<8|d)>>>0}e.toRgba=s;function n(a,l,c,d){return{css:e.toCss(a,l,c,d),rgba:e.toRgba(a,l,c,d)}}e.toColor=n})(ps||(ps={}));var $t;(e=>{function t(f,h){if(es=(h.rgba&255)/255,es===1)return{css:h.css,rgba:h.rgba};let m=h.rgba>>24&255,g=h.rgba>>16&255,b=h.rgba>>8&255,v=f.rgba>>24&255,y=f.rgba>>16&255,S=f.rgba>>8&255;Ns=v+Math.round((m-v)*es),Es=y+Math.round((g-y)*es),Ms=S+Math.round((b-S)*es);let j=ps.toCss(Ns,Es,Ms),k=ps.toRgba(Ns,Es,Ms);return{css:j,rgba:k}}e.blend=t;function s(f){return(f.rgba&255)===255}e.isOpaque=s;function n(f,h,m){let g=hh.ensureContrastRatio(f.rgba,h.rgba,m);if(g)return ps.toColor(g>>24&255,g>>16&255,g>>8&255)}e.ensureContrastRatio=n;function a(f){let h=(f.rgba|255)>>>0;return[Ns,Es,Ms]=hh.toChannels(h),{css:ps.toCss(Ns,Es,Ms),rgba:h}}e.opaque=a;function l(f,h){return es=Math.round(h*255),[Ns,Es,Ms]=hh.toChannels(f.rgba),{css:ps.toCss(Ns,Es,Ms,es),rgba:ps.toRgba(Ns,Es,Ms,es)}}e.opacity=l;function c(f,h){return es=f.rgba&255,l(f,es*h/255)}e.multiplyOpacity=c;function d(f){return[f.rgba>>24&255,f.rgba>>16&255,f.rgba>>8&255]}e.toColorRGB=d})($t||($t={}));var Wt;(e=>{let t,s;try{let a=document.createElement("canvas");a.width=1,a.height=1;let l=a.getContext("2d",{willReadFrequently:!0});l&&(t=l,t.globalCompositeOperation="copy",s=t.createLinearGradient(0,0,1,1))}catch{}function n(a){if(a.match(/#[\da-f]{3,8}/i))switch(a.length){case 4:return Ns=parseInt(a.slice(1,2).repeat(2),16),Es=parseInt(a.slice(2,3).repeat(2),16),Ms=parseInt(a.slice(3,4).repeat(2),16),ps.toColor(Ns,Es,Ms);case 5:return Ns=parseInt(a.slice(1,2).repeat(2),16),Es=parseInt(a.slice(2,3).repeat(2),16),Ms=parseInt(a.slice(3,4).repeat(2),16),es=parseInt(a.slice(4,5).repeat(2),16),ps.toColor(Ns,Es,Ms,es);case 7:return{css:a,rgba:(parseInt(a.slice(1),16)<<8|255)>>>0};case 9:return{css:a,rgba:parseInt(a.slice(1),16)>>>0}}let l=a.match(/rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(,\s*(0|1|\d?\.(\d+))\s*)?\)/);if(l)return Ns=parseInt(l[1]),Es=parseInt(l[2]),Ms=parseInt(l[3]),es=Math.round((l[5]===void 0?1:parseFloat(l[5]))*255),ps.toColor(Ns,Es,Ms,es);if(!t||!s)throw new Error("css.toColor: Unsupported css format");if(t.fillStyle=s,t.fillStyle=a,typeof t.fillStyle!="string")throw new Error("css.toColor: Unsupported css format");if(t.fillRect(0,0,1,1),[Ns,Es,Ms,es]=t.getImageData(0,0,1,1).data,es!==255)throw new Error("css.toColor: Unsupported css format");return{rgba:ps.toRgba(Ns,Es,Ms,es),css:a}}e.toColor=n})(Wt||(Wt={}));var Qs;(e=>{function t(n){return s(n>>16&255,n>>8&255,n&255)}e.relativeLuminance=t;function s(n,a,l){let c=n/255,d=a/255,f=l/255,h=c<=.03928?c/12.92:Math.pow((c+.055)/1.055,2.4),m=d<=.03928?d/12.92:Math.pow((d+.055)/1.055,2.4),g=f<=.03928?f/12.92:Math.pow((f+.055)/1.055,2.4);return h*.2126+m*.7152+g*.0722}e.relativeLuminance2=s})(Qs||(Qs={}));var hh;(e=>{function t(c,d){if(es=(d&255)/255,es===1)return d;let f=d>>24&255,h=d>>16&255,m=d>>8&255,g=c>>24&255,b=c>>16&255,v=c>>8&255;return Ns=g+Math.round((f-g)*es),Es=b+Math.round((h-b)*es),Ms=v+Math.round((m-v)*es),ps.toRgba(Ns,Es,Ms)}e.blend=t;function s(c,d,f){let h=Qs.relativeLuminance(c>>8),m=Qs.relativeLuminance(d>>8);if(Yr(h,m)<f){if(m<h){let v=n(c,d,f),y=Yr(h,Qs.relativeLuminance(v>>8));if(y<f){let S=a(c,d,f),j=Yr(h,Qs.relativeLuminance(S>>8));return y>j?v:S}return v}let g=a(c,d,f),b=Yr(h,Qs.relativeLuminance(g>>8));if(b<f){let v=n(c,d,f),y=Yr(h,Qs.relativeLuminance(v>>8));return b>y?g:v}return g}}e.ensureContrastRatio=s;function n(c,d,f){let h=c>>24&255,m=c>>16&255,g=c>>8&255,b=d>>24&255,v=d>>16&255,y=d>>8&255,S=Yr(Qs.relativeLuminance2(b,v,y),Qs.relativeLuminance2(h,m,g));for(;S<f&&(b>0||v>0||y>0);)b-=Math.max(0,Math.ceil(b*.1)),v-=Math.max(0,Math.ceil(v*.1)),y-=Math.max(0,Math.ceil(y*.1)),S=Yr(Qs.relativeLuminance2(b,v,y),Qs.relativeLuminance2(h,m,g));return(b<<24|v<<16|y<<8|255)>>>0}e.reduceLuminance=n;function a(c,d,f){let h=c>>24&255,m=c>>16&255,g=c>>8&255,b=d>>24&255,v=d>>16&255,y=d>>8&255,S=Yr(Qs.relativeLuminance2(b,v,y),Qs.relativeLuminance2(h,m,g));for(;S<f&&(b<255||v<255||y<255);)b=Math.min(255,b+Math.ceil((255-b)*.1)),v=Math.min(255,v+Math.ceil((255-v)*.1)),y=Math.min(255,y+Math.ceil((255-y)*.1)),S=Yr(Qs.relativeLuminance2(b,v,y),Qs.relativeLuminance2(h,m,g));return(b<<24|v<<16|y<<8|255)>>>0}e.increaseLuminance=a;function l(c){return[c>>24&255,c>>16&255,c>>8&255,c&255]}e.toChannels=l})(hh||(hh={}));function _a(e){let t=e.toString(16);return t.length<2?"0"+t:t}function Yr(e,t){return e<t?(t+.05)/(e+.05):(e+.05)/(t+.05)}var pI=class extends pu{constructor(e,t,s){super(),this.content=0,this.combinedData="",this.fg=e.fg,this.bg=e.bg,this.combinedData=t,this._width=s}isCombined(){return 2097152}getWidth(){return this._width}getChars(){return this.combinedData}getCode(){return 2097151}setFromCharData(e){throw new Error("not implemented")}getAsCharData(){return[this.fg,this.getChars(),this.getWidth(),this.getCode()]}},$h=class{constructor(e){this._bufferService=e,this._characterJoiners=[],this._nextCharacterJoinerId=0,this._workCell=new Jn}register(e){let t={id:this._nextCharacterJoinerId++,handler:e};return this._characterJoiners.push(t),t.id}deregister(e){for(let t=0;t<this._characterJoiners.length;t++)if(this._characterJoiners[t].id===e)return this._characterJoiners.splice(t,1),!0;return!1}getJoinedCharacters(e){if(this._characterJoiners.length===0)return[];let t=this._bufferService.buffer.lines.get(e);if(!t||t.length===0)return[];let s=[],n=t.translateToString(!0),a=0,l=0,c=0,d=t.getFg(0),f=t.getBg(0);for(let h=0;h<t.getTrimmedLength();h++)if(t.loadCell(h,this._workCell),this._workCell.getWidth()!==0){if(this._workCell.fg!==d||this._workCell.bg!==f){if(h-a>1){let m=this._getJoinedRanges(n,c,l,t,a);for(let g=0;g<m.length;g++)s.push(m[g])}a=h,c=l,d=this._workCell.fg,f=this._workCell.bg}l+=this._workCell.getChars().length||Vi.length}if(this._bufferService.cols-a>1){let h=this._getJoinedRanges(n,c,l,t,a);for(let m=0;m<h.length;m++)s.push(h[m])}return s}_getJoinedRanges(e,t,s,n,a){let l=e.substring(t,s),c=[];try{c=this._characterJoiners[0].handler(l)}catch(d){console.error(d)}for(let d=1;d<this._characterJoiners.length;d++)try{let f=this._characterJoiners[d].handler(l);for(let h=0;h<f.length;h++)$h._mergeRanges(c,f[h])}catch(f){console.error(f)}return this._stringRangesToCellRanges(c,n,a),c}_stringRangesToCellRanges(e,t,s){let n=0,a=!1,l=0,c=e[n];if(c){for(let d=s;d<this._bufferService.cols;d++){let f=t.getWidth(d),h=t.getString(d).length||Vi.length;if(f!==0){if(!a&&c[0]<=l&&(c[0]=d,a=!0),c[1]<=l){if(c[1]=d,c=e[++n],!c)break;c[0]<=l?(c[0]=d,a=!0):a=!1}l+=h}}c&&(c[1]=this._bufferService.cols)}}static _mergeRanges(e,t){let s=!1;for(let n=0;n<e.length;n++){let a=e[n];if(s){if(t[1]<=a[0])return e[n-1][1]=t[1],e;if(t[1]<=a[1])return e[n-1][1]=Math.max(t[1],a[1]),e.splice(n,1),e;e.splice(n,1),n--}else{if(t[1]<=a[0])return e.splice(n,0,t),e;if(t[1]<=a[1])return a[0]=Math.min(t[0],a[0]),e;t[0]<a[1]&&(a[0]=Math.min(t[0],a[0]),s=!0);continue}}return s?e[e.length-1][1]=t[1]:e.push(t),e}};$h=ts([Re(0,sn)],$h);function mI(e){return 57508<=e&&e<=57558}function gI(e){return 9472<=e&&e<=9631}function xI(e){return mI(e)||gI(e)}function vI(){return{css:{canvas:Xd(),cell:Xd()},device:{canvas:Xd(),cell:Xd(),char:{width:0,height:0,left:0,top:0}}}}function Xd(){return{width:0,height:0}}var t0=class{constructor(e,t,s,n,a,l,c){this._document=e,this._characterJoinerService=t,this._optionsService=s,this._coreBrowserService=n,this._coreService=a,this._decorationService=l,this._themeService=c,this._workCell=new Jn,this._columnSelectMode=!1,this.defaultSpacing=0}handleSelectionChanged(e,t,s){this._selectionStart=e,this._selectionEnd=t,this._columnSelectMode=s}createRow(e,t,s,n,a,l,c,d,f,h,m){let g=[],b=this._characterJoinerService.getJoinedCharacters(t),v=this._themeService.colors,y=e.getNoBgTrimmedLength();s&&y<l+1&&(y=l+1);let S,j=0,k="",E=0,N=0,B=0,A=0,P=!1,K=0,X=!1,Z=0,I=0,H=[],F=h!==-1&&m!==-1;for(let G=0;G<y;G++){e.loadCell(G,this._workCell);let q=this._workCell.getWidth();if(q===0)continue;let R=!1,M=G>=I,O=G,W=this._workCell;if(b.length>0&&G===b[0][0]&&M){let $e=b.shift(),we=this._isCellInSelection($e[0],t);for(E=$e[0]+1;E<$e[1];E++)M&&(M=we===this._isCellInSelection(E,t));M&&(M=!s||l<$e[0]||l>=$e[1]),M?(R=!0,W=new pI(this._workCell,e.translateToString(!0,$e[0],$e[1]),$e[1]-$e[0]),O=$e[1]-1,q=W.getWidth()):I=$e[1]}let U=this._isCellInSelection(G,t),D=s&&G===l,$=F&&G>=h&&G<=m,z=!1;this._decorationService.forEachDecorationAtCell(G,t,void 0,$e=>{z=!0});let T=W.getChars()||Vi;if(T===" "&&(W.isUnderline()||W.isOverline())&&(T=" "),Z=q*d-f.get(T,W.isBold(),W.isItalic()),!S)S=this._document.createElement("span");else if(j&&(U&&X||!U&&!X&&W.bg===N)&&(U&&X&&v.selectionForeground||W.fg===B)&&W.extended.ext===A&&$===P&&Z===K&&!D&&!R&&!z&&M){W.isInvisible()?k+=Vi:k+=T,j++;continue}else j&&(S.textContent=k),S=this._document.createElement("span"),j=0,k="";if(N=W.bg,B=W.fg,A=W.extended.ext,P=$,K=Z,X=U,R&&l>=G&&l<=O&&(l=G),!this._coreService.isCursorHidden&&D&&this._coreService.isCursorInitialized){if(H.push("xterm-cursor"),this._coreBrowserService.isFocused)c&&H.push("xterm-cursor-blink"),H.push(n==="bar"?"xterm-cursor-bar":n==="underline"?"xterm-cursor-underline":"xterm-cursor-block");else if(a)switch(a){case"outline":H.push("xterm-cursor-outline");break;case"block":H.push("xterm-cursor-block");break;case"bar":H.push("xterm-cursor-bar");break;case"underline":H.push("xterm-cursor-underline");break}}if(W.isBold()&&H.push("xterm-bold"),W.isItalic()&&H.push("xterm-italic"),W.isDim()&&H.push("xterm-dim"),W.isInvisible()?k=Vi:k=W.getChars()||Vi,W.isUnderline()&&(H.push(`xterm-underline-${W.extended.underlineStyle}`),k===" "&&(k=" "),!W.isUnderlineColorDefault()))if(W.isUnderlineColorRGB())S.style.textDecorationColor=`rgb(${pu.toColorRGB(W.getUnderlineColor()).join(",")})`;else{let $e=W.getUnderlineColor();this._optionsService.rawOptions.drawBoldTextInBrightColors&&W.isBold()&&$e<8&&($e+=8),S.style.textDecorationColor=v.ansi[$e].css}W.isOverline()&&(H.push("xterm-overline"),k===" "&&(k=" ")),W.isStrikethrough()&&H.push("xterm-strikethrough"),$&&(S.style.textDecoration="underline");let ae=W.getFgColor(),be=W.getFgColorMode(),ne=W.getBgColor(),ve=W.getBgColorMode(),Ae=!!W.isInverse();if(Ae){let $e=ae;ae=ne,ne=$e;let we=be;be=ve,ve=we}let De,ke,Xe=!1;this._decorationService.forEachDecorationAtCell(G,t,void 0,$e=>{$e.options.layer!=="top"&&Xe||($e.backgroundColorRGB&&(ve=50331648,ne=$e.backgroundColorRGB.rgba>>8&16777215,De=$e.backgroundColorRGB),$e.foregroundColorRGB&&(be=50331648,ae=$e.foregroundColorRGB.rgba>>8&16777215,ke=$e.foregroundColorRGB),Xe=$e.options.layer==="top")}),!Xe&&U&&(De=this._coreBrowserService.isFocused?v.selectionBackgroundOpaque:v.selectionInactiveBackgroundOpaque,ne=De.rgba>>8&16777215,ve=50331648,Xe=!0,v.selectionForeground&&(be=50331648,ae=v.selectionForeground.rgba>>8&16777215,ke=v.selectionForeground)),Xe&&H.push("xterm-decoration-top");let Je;switch(ve){case 16777216:case 33554432:Je=v.ansi[ne],H.push(`xterm-bg-${ne}`);break;case 50331648:Je=ps.toColor(ne>>16,ne>>8&255,ne&255),this._addStyle(S,`background-color:#${D2((ne>>>0).toString(16),"0",6)}`);break;case 0:default:Ae?(Je=v.foreground,H.push("xterm-bg-257")):Je=v.background}switch(De||W.isDim()&&(De=$t.multiplyOpacity(Je,.5)),be){case 16777216:case 33554432:W.isBold()&&ae<8&&this._optionsService.rawOptions.drawBoldTextInBrightColors&&(ae+=8),this._applyMinimumContrast(S,Je,v.ansi[ae],W,De,void 0)||H.push(`xterm-fg-${ae}`);break;case 50331648:let $e=ps.toColor(ae>>16&255,ae>>8&255,ae&255);this._applyMinimumContrast(S,Je,$e,W,De,ke)||this._addStyle(S,`color:#${D2(ae.toString(16),"0",6)}`);break;case 0:default:this._applyMinimumContrast(S,Je,v.foreground,W,De,ke)||Ae&&H.push("xterm-fg-257")}H.length&&(S.className=H.join(" "),H.length=0),!D&&!R&&!z&&M?j++:S.textContent=k,Z!==this.defaultSpacing&&(S.style.letterSpacing=`${Z}px`),g.push(S),G=O}return S&&j&&(S.textContent=k),g}_applyMinimumContrast(e,t,s,n,a,l){if(this._optionsService.rawOptions.minimumContrastRatio===1||xI(n.getCode()))return!1;let c=this._getContrastCache(n),d;if(!a&&!l&&(d=c.getColor(t.rgba,s.rgba)),d===void 0){let f=this._optionsService.rawOptions.minimumContrastRatio/(n.isDim()?2:1);d=$t.ensureContrastRatio(a||t,l||s,f),c.setColor((a||t).rgba,(l||s).rgba,d??null)}return d?(this._addStyle(e,`color:${d.css}`),!0):!1}_getContrastCache(e){return e.isDim()?this._themeService.colors.halfContrastCache:this._themeService.colors.contrastCache}_addStyle(e,t){e.setAttribute("style",`${e.getAttribute("style")||""}${t};`)}_isCellInSelection(e,t){let s=this._selectionStart,n=this._selectionEnd;return!s||!n?!1:this._columnSelectMode?s[0]<=n[0]?e>=s[0]&&t>=s[1]&&e<n[0]&&t<=n[1]:e<s[0]&&t>=s[1]&&e>=n[0]&&t<=n[1]:t>s[1]&&t<n[1]||s[1]===n[1]&&t===s[1]&&e>=s[0]&&e<n[0]||s[1]<n[1]&&t===n[1]&&e<n[0]||s[1]<n[1]&&t===s[1]&&e>=s[0]}};t0=ts([Re(1,qC),Re(2,nn),Re(3,ai),Re(4,Ba),Re(5,mu),Re(6,tl)],t0);function D2(e,t,s){for(;e.length<s;)e=t+e;return e}var bI=class{constructor(e,t){this._flat=new Float32Array(256),this._font="",this._fontSize=0,this._weight="normal",this._weightBold="bold",this._measureElements=[],this._container=e.createElement("div"),this._container.classList.add("xterm-width-cache-measure-container"),this._container.setAttribute("aria-hidden","true"),this._container.style.whiteSpace="pre",this._container.style.fontKerning="none";let s=e.createElement("span");s.classList.add("xterm-char-measure-element");let n=e.createElement("span");n.classList.add("xterm-char-measure-element"),n.style.fontWeight="bold";let a=e.createElement("span");a.classList.add("xterm-char-measure-element"),a.style.fontStyle="italic";let l=e.createElement("span");l.classList.add("xterm-char-measure-element"),l.style.fontWeight="bold",l.style.fontStyle="italic",this._measureElements=[s,n,a,l],this._container.appendChild(s),this._container.appendChild(n),this._container.appendChild(a),this._container.appendChild(l),t.appendChild(this._container),this.clear()}dispose(){this._container.remove(),this._measureElements.length=0,this._holey=void 0}clear(){this._flat.fill(-9999),this._holey=new Map}setFont(e,t,s,n){e===this._font&&t===this._fontSize&&s===this._weight&&n===this._weightBold||(this._font=e,this._fontSize=t,this._weight=s,this._weightBold=n,this._container.style.fontFamily=this._font,this._container.style.fontSize=`${this._fontSize}px`,this._measureElements[0].style.fontWeight=`${s}`,this._measureElements[1].style.fontWeight=`${n}`,this._measureElements[2].style.fontWeight=`${s}`,this._measureElements[3].style.fontWeight=`${n}`,this.clear())}get(e,t,s){let n=0;if(!t&&!s&&e.length===1&&(n=e.charCodeAt(0))<256){if(this._flat[n]!==-9999)return this._flat[n];let c=this._measure(e,0);return c>0&&(this._flat[n]=c),c}let a=e;t&&(a+="B"),s&&(a+="I");let l=this._holey.get(a);if(l===void 0){let c=0;t&&(c|=1),s&&(c|=2),l=this._measure(e,c),l>0&&this._holey.set(a,l)}return l}_measure(e,t){let s=this._measureElements[t];return s.textContent=e.repeat(32),s.offsetWidth/32}},_I=class{constructor(){this.clear()}clear(){this.hasSelection=!1,this.columnSelectMode=!1,this.viewportStartRow=0,this.viewportEndRow=0,this.viewportCappedStartRow=0,this.viewportCappedEndRow=0,this.startCol=0,this.endCol=0,this.selectionStart=void 0,this.selectionEnd=void 0}update(e,t,s,n=!1){if(this.selectionStart=t,this.selectionEnd=s,!t||!s||t[0]===s[0]&&t[1]===s[1]){this.clear();return}let a=e.buffers.active.ydisp,l=t[1]-a,c=s[1]-a,d=Math.max(l,0),f=Math.min(c,e.rows-1);if(d>=e.rows||f<0){this.clear();return}this.hasSelection=!0,this.columnSelectMode=n,this.viewportStartRow=l,this.viewportEndRow=c,this.viewportCappedStartRow=d,this.viewportCappedEndRow=f,this.startCol=t[0],this.endCol=s[0]}isCellSelected(e,t,s){return this.hasSelection?(s-=e.buffer.active.viewportY,this.columnSelectMode?this.startCol<=this.endCol?t>=this.startCol&&s>=this.viewportCappedStartRow&&t<this.endCol&&s<=this.viewportCappedEndRow:t<this.startCol&&s>=this.viewportCappedStartRow&&t>=this.endCol&&s<=this.viewportCappedEndRow:s>this.viewportStartRow&&s<this.viewportEndRow||this.viewportStartRow===this.viewportEndRow&&s===this.viewportStartRow&&t>=this.startCol&&t<this.endCol||this.viewportStartRow<this.viewportEndRow&&s===this.viewportEndRow&&t<this.endCol||this.viewportStartRow<this.viewportEndRow&&s===this.viewportStartRow&&t>=this.startCol):!1}};function yI(){return new _I}var kg="xterm-dom-renderer-owner-",Wn="xterm-rows",Jd="xterm-fg-",L2="xterm-bg-",hc="xterm-focus",Qd="xterm-selection",wI=1,s0=class extends nt{constructor(e,t,s,n,a,l,c,d,f,h,m,g,b,v){super(),this._terminal=e,this._document=t,this._element=s,this._screenElement=n,this._viewportElement=a,this._helperContainer=l,this._linkifier2=c,this._charSizeService=f,this._optionsService=h,this._bufferService=m,this._coreService=g,this._coreBrowserService=b,this._themeService=v,this._terminalClass=wI++,this._rowElements=[],this._selectionRenderModel=yI(),this.onRequestRedraw=this._register(new Ce).event,this._rowContainer=this._document.createElement("div"),this._rowContainer.classList.add(Wn),this._rowContainer.style.lineHeight="normal",this._rowContainer.setAttribute("aria-hidden","true"),this._refreshRowElements(this._bufferService.cols,this._bufferService.rows),this._selectionContainer=this._document.createElement("div"),this._selectionContainer.classList.add(Qd),this._selectionContainer.setAttribute("aria-hidden","true"),this.dimensions=vI(),this._updateDimensions(),this._register(this._optionsService.onOptionChange(()=>this._handleOptionsChanged())),this._register(this._themeService.onChangeColors(y=>this._injectCss(y))),this._injectCss(this._themeService.colors),this._rowFactory=d.createInstance(t0,document),this._element.classList.add(kg+this._terminalClass),this._screenElement.appendChild(this._rowContainer),this._screenElement.appendChild(this._selectionContainer),this._register(this._linkifier2.onShowLinkUnderline(y=>this._handleLinkHover(y))),this._register(this._linkifier2.onHideLinkUnderline(y=>this._handleLinkLeave(y))),this._register(Ut(()=>{this._element.classList.remove(kg+this._terminalClass),this._rowContainer.remove(),this._selectionContainer.remove(),this._widthCache.dispose(),this._themeStyleElement.remove(),this._dimensionsStyleElement.remove()})),this._widthCache=new bI(this._document,this._helperContainer),this._widthCache.setFont(this._optionsService.rawOptions.fontFamily,this._optionsService.rawOptions.fontSize,this._optionsService.rawOptions.fontWeight,this._optionsService.rawOptions.fontWeightBold),this._setDefaultSpacing()}_updateDimensions(){let e=this._coreBrowserService.dpr;this.dimensions.device.char.width=this._charSizeService.width*e,this.dimensions.device.char.height=Math.ceil(this._charSizeService.height*e),this.dimensions.device.cell.width=this.dimensions.device.char.width+Math.round(this._optionsService.rawOptions.letterSpacing),this.dimensions.device.cell.height=Math.floor(this.dimensions.device.char.height*this._optionsService.rawOptions.lineHeight),this.dimensions.device.char.left=0,this.dimensions.device.char.top=0,this.dimensions.device.canvas.width=this.dimensions.device.cell.width*this._bufferService.cols,this.dimensions.device.canvas.height=this.dimensions.device.cell.height*this._bufferService.rows,this.dimensions.css.canvas.width=Math.round(this.dimensions.device.canvas.width/e),this.dimensions.css.canvas.height=Math.round(this.dimensions.device.canvas.height/e),this.dimensions.css.cell.width=this.dimensions.css.canvas.width/this._bufferService.cols,this.dimensions.css.cell.height=this.dimensions.css.canvas.height/this._bufferService.rows;for(let s of this._rowElements)s.style.width=`${this.dimensions.css.canvas.width}px`,s.style.height=`${this.dimensions.css.cell.height}px`,s.style.lineHeight=`${this.dimensions.css.cell.height}px`,s.style.overflow="hidden";this._dimensionsStyleElement||(this._dimensionsStyleElement=this._document.createElement("style"),this._screenElement.appendChild(this._dimensionsStyleElement));let t=`${this._terminalSelector} .${Wn} span { display: inline-block; height: 100%; vertical-align: top;}`;this._dimensionsStyleElement.textContent=t,this._selectionContainer.style.height=this._viewportElement.style.height,this._screenElement.style.width=`${this.dimensions.css.canvas.width}px`,this._screenElement.style.height=`${this.dimensions.css.canvas.height}px`}_injectCss(e){this._themeStyleElement||(this._themeStyleElement=this._document.createElement("style"),this._screenElement.appendChild(this._themeStyleElement));let t=`${this._terminalSelector} .${Wn} { pointer-events: none; color: ${e.foreground.css}; font-family: ${this._optionsService.rawOptions.fontFamily}; font-size: ${this._optionsService.rawOptions.fontSize}px; font-kerning: none; white-space: pre}`;t+=`${this._terminalSelector} .${Wn} .xterm-dim { color: ${$t.multiplyOpacity(e.foreground,.5).css};}`,t+=`${this._terminalSelector} span:not(.xterm-bold) { font-weight: ${this._optionsService.rawOptions.fontWeight};}${this._terminalSelector} span.xterm-bold { font-weight: ${this._optionsService.rawOptions.fontWeightBold};}${this._terminalSelector} span.xterm-italic { font-style: italic;}`;let s=`blink_underline_${this._terminalClass}`,n=`blink_bar_${this._terminalClass}`,a=`blink_block_${this._terminalClass}`;t+=`@keyframes ${s} { 50% { border-bottom-style: hidden; }}`,t+=`@keyframes ${n} { 50% { box-shadow: none; }}`,t+=`@keyframes ${a} { 0% { background-color: ${e.cursor.css}; color: ${e.cursorAccent.css}; } 50% { background-color: inherit; color: ${e.cursor.css}; }}`,t+=`${this._terminalSelector} .${Wn}.${hc} .xterm-cursor.xterm-cursor-blink.xterm-cursor-underline { animation: ${s} 1s step-end infinite;}${this._terminalSelector} .${Wn}.${hc} .xterm-cursor.xterm-cursor-blink.xterm-cursor-bar { animation: ${n} 1s step-end infinite;}${this._terminalSelector} .${Wn}.${hc} .xterm-cursor.xterm-cursor-blink.xterm-cursor-block { animation: ${a} 1s step-end infinite;}${this._terminalSelector} .${Wn} .xterm-cursor.xterm-cursor-block { background-color: ${e.cursor.css}; color: ${e.cursorAccent.css};}${this._terminalSelector} .${Wn} .xterm-cursor.xterm-cursor-block:not(.xterm-cursor-blink) { background-color: ${e.cursor.css} !important; color: ${e.cursorAccent.css} !important;}${this._terminalSelector} .${Wn} .xterm-cursor.xterm-cursor-outline { outline: 1px solid ${e.cursor.css}; outline-offset: -1px;}${this._terminalSelector} .${Wn} .xterm-cursor.xterm-cursor-bar { box-shadow: ${this._optionsService.rawOptions.cursorWidth}px 0 0 ${e.cursor.css} inset;}${this._terminalSelector} .${Wn} .xterm-cursor.xterm-cursor-underline { border-bottom: 1px ${e.cursor.css}; border-bottom-style: solid; height: calc(100% - 1px);}`,t+=`${this._terminalSelector} .${Qd} { position: absolute; top: 0; left: 0; z-index: 1; pointer-events: none;}${this._terminalSelector}.focus .${Qd} div { position: absolute; background-color: ${e.selectionBackgroundOpaque.css};}${this._terminalSelector} .${Qd} div { position: absolute; background-color: ${e.selectionInactiveBackgroundOpaque.css};}`;for(let[l,c]of e.ansi.entries())t+=`${this._terminalSelector} .${Jd}${l} { color: ${c.css}; }${this._terminalSelector} .${Jd}${l}.xterm-dim { color: ${$t.multiplyOpacity(c,.5).css}; }${this._terminalSelector} .${L2}${l} { background-color: ${c.css}; }`;t+=`${this._terminalSelector} .${Jd}257 { color: ${$t.opaque(e.background).css}; }${this._terminalSelector} .${Jd}257.xterm-dim { color: ${$t.multiplyOpacity($t.opaque(e.background),.5).css}; }${this._terminalSelector} .${L2}257 { background-color: ${e.foreground.css}; }`,this._themeStyleElement.textContent=t}_setDefaultSpacing(){let e=this.dimensions.css.cell.width-this._widthCache.get("W",!1,!1);this._rowContainer.style.letterSpacing=`${e}px`,this._rowFactory.defaultSpacing=e}handleDevicePixelRatioChange(){this._updateDimensions(),this._widthCache.clear(),this._setDefaultSpacing()}_refreshRowElements(e,t){for(let s=this._rowElements.length;s<=t;s++){let n=this._document.createElement("div");this._rowContainer.appendChild(n),this._rowElements.push(n)}for(;this._rowElements.length>t;)this._rowContainer.removeChild(this._rowElements.pop())}handleResize(e,t){this._refreshRowElements(e,t),this._updateDimensions(),this.handleSelectionChanged(this._selectionRenderModel.selectionStart,this._selectionRenderModel.selectionEnd,this._selectionRenderModel.columnSelectMode)}handleCharSizeChanged(){this._updateDimensions(),this._widthCache.clear(),this._setDefaultSpacing()}handleBlur(){this._rowContainer.classList.remove(hc),this.renderRows(0,this._bufferService.rows-1)}handleFocus(){this._rowContainer.classList.add(hc),this.renderRows(this._bufferService.buffer.y,this._bufferService.buffer.y)}handleSelectionChanged(e,t,s){if(this._selectionContainer.replaceChildren(),this._rowFactory.handleSelectionChanged(e,t,s),this.renderRows(0,this._bufferService.rows-1),!e||!t||(this._selectionRenderModel.update(this._terminal,e,t,s),!this._selectionRenderModel.hasSelection))return;let n=this._selectionRenderModel.viewportStartRow,a=this._selectionRenderModel.viewportEndRow,l=this._selectionRenderModel.viewportCappedStartRow,c=this._selectionRenderModel.viewportCappedEndRow,d=this._document.createDocumentFragment();if(s){let f=e[0]>t[0];d.appendChild(this._createSelectionElement(l,f?t[0]:e[0],f?e[0]:t[0],c-l+1))}else{let f=n===l?e[0]:0,h=l===a?t[0]:this._bufferService.cols;d.appendChild(this._createSelectionElement(l,f,h));let m=c-l-1;if(d.appendChild(this._createSelectionElement(l+1,0,this._bufferService.cols,m)),l!==c){let g=a===c?t[0]:this._bufferService.cols;d.appendChild(this._createSelectionElement(c,0,g))}}this._selectionContainer.appendChild(d)}_createSelectionElement(e,t,s,n=1){let a=this._document.createElement("div"),l=t*this.dimensions.css.cell.width,c=this.dimensions.css.cell.width*(s-t);return l+c>this.dimensions.css.canvas.width&&(c=this.dimensions.css.canvas.width-l),a.style.height=`${n*this.dimensions.css.cell.height}px`,a.style.top=`${e*this.dimensions.css.cell.height}px`,a.style.left=`${l}px`,a.style.width=`${c}px`,a}handleCursorMove(){}_handleOptionsChanged(){this._updateDimensions(),this._injectCss(this._themeService.colors),this._widthCache.setFont(this._optionsService.rawOptions.fontFamily,this._optionsService.rawOptions.fontSize,this._optionsService.rawOptions.fontWeight,this._optionsService.rawOptions.fontWeightBold),this._setDefaultSpacing()}clear(){for(let e of this._rowElements)e.replaceChildren()}renderRows(e,t){let s=this._bufferService.buffer,n=s.ybase+s.y,a=Math.min(s.x,this._bufferService.cols-1),l=this._coreService.decPrivateModes.cursorBlink??this._optionsService.rawOptions.cursorBlink,c=this._coreService.decPrivateModes.cursorStyle??this._optionsService.rawOptions.cursorStyle,d=this._optionsService.rawOptions.cursorInactiveStyle;for(let f=e;f<=t;f++){let h=f+s.ydisp,m=this._rowElements[f],g=s.lines.get(h);if(!m||!g)break;m.replaceChildren(...this._rowFactory.createRow(g,h,h===n,c,d,a,l,this.dimensions.css.cell.width,this._widthCache,-1,-1))}}get _terminalSelector(){return`.${kg}${this._terminalClass}`}_handleLinkHover(e){this._setCellUnderline(e.x1,e.x2,e.y1,e.y2,e.cols,!0)}_handleLinkLeave(e){this._setCellUnderline(e.x1,e.x2,e.y1,e.y2,e.cols,!1)}_setCellUnderline(e,t,s,n,a,l){s<0&&(e=0),n<0&&(t=0);let c=this._bufferService.rows-1;s=Math.max(Math.min(s,c),0),n=Math.max(Math.min(n,c),0),a=Math.min(a,this._bufferService.cols);let d=this._bufferService.buffer,f=d.ybase+d.y,h=Math.min(d.x,a-1),m=this._optionsService.rawOptions.cursorBlink,g=this._optionsService.rawOptions.cursorStyle,b=this._optionsService.rawOptions.cursorInactiveStyle;for(let v=s;v<=n;++v){let y=v+d.ydisp,S=this._rowElements[v],j=d.lines.get(y);if(!S||!j)break;S.replaceChildren(...this._rowFactory.createRow(j,y,y===f,g,b,h,m,this.dimensions.css.cell.width,this._widthCache,l?v===s?e:0:-1,l?(v===n?t:a)-1:-1))}}};s0=ts([Re(7,ov),Re(8,sf),Re(9,nn),Re(10,sn),Re(11,Ba),Re(12,ai),Re(13,tl)],s0);var n0=class extends nt{constructor(e,t,s){super(),this._optionsService=s,this.width=0,this.height=0,this._onCharSizeChange=this._register(new Ce),this.onCharSizeChange=this._onCharSizeChange.event;try{this._measureStrategy=this._register(new jI(this._optionsService))}catch{this._measureStrategy=this._register(new SI(e,t,this._optionsService))}this._register(this._optionsService.onMultipleOptionChange(["fontFamily","fontSize"],()=>this.measure()))}get hasValidSize(){return this.width>0&&this.height>0}measure(){let e=this._measureStrategy.measure();(e.width!==this.width||e.height!==this.height)&&(this.width=e.width,this.height=e.height,this._onCharSizeChange.fire())}};n0=ts([Re(2,nn)],n0);var dN=class extends nt{constructor(){super(...arguments),this._result={width:0,height:0}}_validateAndSet(e,t){e!==void 0&&e>0&&t!==void 0&&t>0&&(this._result.width=e,this._result.height=t)}},SI=class extends dN{constructor(e,t,s){super(),this._document=e,this._parentElement=t,this._optionsService=s,this._measureElement=this._document.createElement("span"),this._measureElement.classList.add("xterm-char-measure-element"),this._measureElement.textContent="W".repeat(32),this._measureElement.setAttribute("aria-hidden","true"),this._measureElement.style.whiteSpace="pre",this._measureElement.style.fontKerning="none",this._parentElement.appendChild(this._measureElement)}measure(){return this._measureElement.style.fontFamily=this._optionsService.rawOptions.fontFamily,this._measureElement.style.fontSize=`${this._optionsService.rawOptions.fontSize}px`,this._validateAndSet(Number(this._measureElement.offsetWidth)/32,Number(this._measureElement.offsetHeight)),this._result}},jI=class extends dN{constructor(e){super(),this._optionsService=e,this._canvas=new OffscreenCanvas(100,100),this._ctx=this._canvas.getContext("2d");let t=this._ctx.measureText("W");if(!("width"in t&&"fontBoundingBoxAscent"in t&&"fontBoundingBoxDescent"in t))throw new Error("Required font metrics not supported")}measure(){this._ctx.font=`${this._optionsService.rawOptions.fontSize}px ${this._optionsService.rawOptions.fontFamily}`;let e=this._ctx.measureText("W");return this._validateAndSet(e.width,e.fontBoundingBoxAscent+e.fontBoundingBoxDescent),this._result}},kI=class extends nt{constructor(e,t,s){super(),this._textarea=e,this._window=t,this.mainDocument=s,this._isFocused=!1,this._cachedIsFocused=void 0,this._screenDprMonitor=this._register(new CI(this._window)),this._onDprChange=this._register(new Ce),this.onDprChange=this._onDprChange.event,this._onWindowChange=this._register(new Ce),this.onWindowChange=this._onWindowChange.event,this._register(this.onWindowChange(n=>this._screenDprMonitor.setWindow(n))),this._register(Is.forward(this._screenDprMonitor.onDprChange,this._onDprChange)),this._register(Ge(this._textarea,"focus",()=>this._isFocused=!0)),this._register(Ge(this._textarea,"blur",()=>this._isFocused=!1))}get window(){return this._window}set window(e){this._window!==e&&(this._window=e,this._onWindowChange.fire(this._window))}get dpr(){return this.window.devicePixelRatio}get isFocused(){return this._cachedIsFocused===void 0&&(this._cachedIsFocused=this._isFocused&&this._textarea.ownerDocument.hasFocus(),queueMicrotask(()=>this._cachedIsFocused=void 0)),this._cachedIsFocused}},CI=class extends nt{constructor(e){super(),this._parentWindow=e,this._windowResizeListener=this._register(new Yo),this._onDprChange=this._register(new Ce),this.onDprChange=this._onDprChange.event,this._outerListener=()=>this._setDprAndFireIfDiffers(),this._currentDevicePixelRatio=this._parentWindow.devicePixelRatio,this._updateDpr(),this._setWindowResizeListener(),this._register(Ut(()=>this.clearListener()))}setWindow(e){this._parentWindow=e,this._setWindowResizeListener(),this._setDprAndFireIfDiffers()}_setWindowResizeListener(){this._windowResizeListener.value=Ge(this._parentWindow,"resize",()=>this._setDprAndFireIfDiffers())}_setDprAndFireIfDiffers(){this._parentWindow.devicePixelRatio!==this._currentDevicePixelRatio&&this._onDprChange.fire(this._parentWindow.devicePixelRatio),this._updateDpr()}_updateDpr(){var e;this._outerListener&&((e=this._resolutionMediaMatchList)==null||e.removeListener(this._outerListener),this._currentDevicePixelRatio=this._parentWindow.devicePixelRatio,this._resolutionMediaMatchList=this._parentWindow.matchMedia(`screen and (resolution: ${this._parentWindow.devicePixelRatio}dppx)`),this._resolutionMediaMatchList.addListener(this._outerListener))}clearListener(){!this._resolutionMediaMatchList||!this._outerListener||(this._resolutionMediaMatchList.removeListener(this._outerListener),this._resolutionMediaMatchList=void 0,this._outerListener=void 0)}},NI=class extends nt{constructor(){super(),this.linkProviders=[],this._register(Ut(()=>this.linkProviders.length=0))}registerLinkProvider(e){return this.linkProviders.push(e),{dispose:()=>{let t=this.linkProviders.indexOf(e);t!==-1&&this.linkProviders.splice(t,1)}}}};function mv(e,t,s){let n=s.getBoundingClientRect(),a=e.getComputedStyle(s),l=parseInt(a.getPropertyValue("padding-left")),c=parseInt(a.getPropertyValue("padding-top"));return[t.clientX-n.left-l,t.clientY-n.top-c]}function EI(e,t,s,n,a,l,c,d,f){if(!l)return;let h=mv(e,t,s);if(h)return h[0]=Math.ceil((h[0]+(f?c/2:0))/c),h[1]=Math.ceil(h[1]/d),h[0]=Math.min(Math.max(h[0],1),n+(f?1:0)),h[1]=Math.min(Math.max(h[1],1),a),h}var r0=class{constructor(e,t){this._renderService=e,this._charSizeService=t}getCoords(e,t,s,n,a){return EI(window,e,t,s,n,this._charSizeService.hasValidSize,this._renderService.dimensions.css.cell.width,this._renderService.dimensions.css.cell.height,a)}getMouseReportCoords(e,t){let s=mv(window,e,t);if(this._charSizeService.hasValidSize)return s[0]=Math.min(Math.max(s[0],0),this._renderService.dimensions.css.canvas.width-1),s[1]=Math.min(Math.max(s[1],0),this._renderService.dimensions.css.canvas.height-1),{col:Math.floor(s[0]/this._renderService.dimensions.css.cell.width),row:Math.floor(s[1]/this._renderService.dimensions.css.cell.height),x:Math.floor(s[0]),y:Math.floor(s[1])}}};r0=ts([Re(0,oi),Re(1,sf)],r0);var MI=class{constructor(e,t){this._renderCallback=e,this._coreBrowserService=t,this._refreshCallbacks=[]}dispose(){this._animationFrame&&(this._coreBrowserService.window.cancelAnimationFrame(this._animationFrame),this._animationFrame=void 0)}addRefreshCallback(e){return this._refreshCallbacks.push(e),this._animationFrame||(this._animationFrame=this._coreBrowserService.window.requestAnimationFrame(()=>this._innerRefresh())),this._animationFrame}refresh(e,t,s){this._rowCount=s,e=e!==void 0?e:0,t=t!==void 0?t:this._rowCount-1,this._rowStart=this._rowStart!==void 0?Math.min(this._rowStart,e):e,this._rowEnd=this._rowEnd!==void 0?Math.max(this._rowEnd,t):t,!this._animationFrame&&(this._animationFrame=this._coreBrowserService.window.requestAnimationFrame(()=>this._innerRefresh()))}_innerRefresh(){if(this._animationFrame=void 0,this._rowStart===void 0||this._rowEnd===void 0||this._rowCount===void 0){this._runRefreshCallbacks();return}let e=Math.max(this._rowStart,0),t=Math.min(this._rowEnd,this._rowCount-1);this._rowStart=void 0,this._rowEnd=void 0,this._renderCallback(e,t),this._runRefreshCallbacks()}_runRefreshCallbacks(){for(let e of this._refreshCallbacks)e(0);this._refreshCallbacks=[]}},hN={};$9(hN,{getSafariVersion:()=>AI,isChromeOS:()=>gN,isFirefox:()=>fN,isIpad:()=>RI,isIphone:()=>DI,isLegacyEdge:()=>TI,isLinux:()=>gv,isMac:()=>Ih,isNode:()=>nf,isSafari:()=>pN,isWindows:()=>mN});var nf=typeof process<"u"&&"title"in process,gu=nf?"node":navigator.userAgent,xu=nf?"node":navigator.platform,fN=gu.includes("Firefox"),TI=gu.includes("Edge"),pN=/^((?!chrome|android).)*safari/i.test(gu);function AI(){if(!pN)return 0;let e=gu.match(/Version\/(\d+)/);return e===null||e.length<2?0:parseInt(e[1])}var Ih=["Macintosh","MacIntel","MacPPC","Mac68K"].includes(xu),RI=xu==="iPad",DI=xu==="iPhone",mN=["Windows","Win16","Win32","WinCE"].includes(xu),gv=xu.indexOf("Linux")>=0,gN=/\bCrOS\b/.test(gu),xN=class{constructor(){this._tasks=[],this._i=0}enqueue(e){this._tasks.push(e),this._start()}flush(){for(;this._i<this._tasks.length;)this._tasks[this._i]()||this._i++;this.clear()}clear(){this._idleCallback&&(this._cancelCallback(this._idleCallback),this._idleCallback=void 0),this._i=0,this._tasks.length=0}_start(){this._idleCallback||(this._idleCallback=this._requestCallback(this._process.bind(this)))}_process(e){this._idleCallback=void 0;let t=0,s=0,n=e.timeRemaining(),a=0;for(;this._i<this._tasks.length;){if(t=performance.now(),this._tasks[this._i]()||this._i++,t=Math.max(1,performance.now()-t),s=Math.max(t,s),a=e.timeRemaining(),s*1.5>a){n-t<-20&&console.warn(`task queue exceeded allotted deadline by ${Math.abs(Math.round(n-t))}ms`),this._start();return}n=a}this.clear()}},LI=class extends xN{_requestCallback(e){return setTimeout(()=>e(this._createDeadline(16)))}_cancelCallback(e){clearTimeout(e)}_createDeadline(e){let t=performance.now()+e;return{timeRemaining:()=>Math.max(0,t-performance.now())}}},BI=class extends xN{_requestCallback(e){return requestIdleCallback(e)}_cancelCallback(e){cancelIdleCallback(e)}},Fh=!nf&&"requestIdleCallback"in window?BI:LI,OI=class{constructor(){this._queue=new Fh}set(e){this._queue.clear(),this._queue.enqueue(e)}flush(){this._queue.flush()}},i0=class extends nt{constructor(e,t,s,n,a,l,c,d,f){super(),this._rowCount=e,this._optionsService=s,this._charSizeService=n,this._coreService=a,this._coreBrowserService=d,this._renderer=this._register(new Yo),this._pausedResizeTask=new OI,this._observerDisposable=this._register(new Yo),this._isPaused=!1,this._needsFullRefresh=!1,this._isNextRenderRedrawOnly=!0,this._needsSelectionRefresh=!1,this._canvasWidth=0,this._canvasHeight=0,this._selectionState={start:void 0,end:void 0,columnSelectMode:!1},this._onDimensionsChange=this._register(new Ce),this.onDimensionsChange=this._onDimensionsChange.event,this._onRenderedViewportChange=this._register(new Ce),this.onRenderedViewportChange=this._onRenderedViewportChange.event,this._onRender=this._register(new Ce),this.onRender=this._onRender.event,this._onRefreshRequest=this._register(new Ce),this.onRefreshRequest=this._onRefreshRequest.event,this._renderDebouncer=new MI((h,m)=>this._renderRows(h,m),this._coreBrowserService),this._register(this._renderDebouncer),this._syncOutputHandler=new zI(this._coreBrowserService,this._coreService,()=>this._fullRefresh()),this._register(Ut(()=>this._syncOutputHandler.dispose())),this._register(this._coreBrowserService.onDprChange(()=>this.handleDevicePixelRatioChange())),this._register(c.onResize(()=>this._fullRefresh())),this._register(c.buffers.onBufferActivate(()=>{var h;return(h=this._renderer.value)==null?void 0:h.clear()})),this._register(this._optionsService.onOptionChange(()=>this._handleOptionsChanged())),this._register(this._charSizeService.onCharSizeChange(()=>this.handleCharSizeChanged())),this._register(l.onDecorationRegistered(()=>this._fullRefresh())),this._register(l.onDecorationRemoved(()=>this._fullRefresh())),this._register(this._optionsService.onMultipleOptionChange(["customGlyphs","drawBoldTextInBrightColors","letterSpacing","lineHeight","fontFamily","fontSize","fontWeight","fontWeightBold","minimumContrastRatio","rescaleOverlappingGlyphs"],()=>{this.clear(),this.handleResize(c.cols,c.rows),this._fullRefresh()})),this._register(this._optionsService.onMultipleOptionChange(["cursorBlink","cursorStyle"],()=>this.refreshRows(c.buffer.y,c.buffer.y,!0))),this._register(f.onChangeColors(()=>this._fullRefresh())),this._registerIntersectionObserver(this._coreBrowserService.window,t),this._register(this._coreBrowserService.onWindowChange(h=>this._registerIntersectionObserver(h,t)))}get dimensions(){return this._renderer.value.dimensions}_registerIntersectionObserver(e,t){if("IntersectionObserver"in e){let s=new e.IntersectionObserver(n=>this._handleIntersectionChange(n[n.length-1]),{threshold:0});s.observe(t),this._observerDisposable.value=Ut(()=>s.disconnect())}}_handleIntersectionChange(e){this._isPaused=e.isIntersecting===void 0?e.intersectionRatio===0:!e.isIntersecting,!this._isPaused&&!this._charSizeService.hasValidSize&&this._charSizeService.measure(),!this._isPaused&&this._needsFullRefresh&&(this._pausedResizeTask.flush(),this.refreshRows(0,this._rowCount-1),this._needsFullRefresh=!1)}refreshRows(e,t,s=!1){if(this._isPaused){this._needsFullRefresh=!0;return}if(this._coreService.decPrivateModes.synchronizedOutput){this._syncOutputHandler.bufferRows(e,t);return}let n=this._syncOutputHandler.flush();n&&(e=Math.min(e,n.start),t=Math.max(t,n.end)),s||(this._isNextRenderRedrawOnly=!1),this._renderDebouncer.refresh(e,t,this._rowCount)}_renderRows(e,t){if(this._renderer.value){if(this._coreService.decPrivateModes.synchronizedOutput){this._syncOutputHandler.bufferRows(e,t);return}e=Math.min(e,this._rowCount-1),t=Math.min(t,this._rowCount-1),this._renderer.value.renderRows(e,t),this._needsSelectionRefresh&&(this._renderer.value.handleSelectionChanged(this._selectionState.start,this._selectionState.end,this._selectionState.columnSelectMode),this._needsSelectionRefresh=!1),this._isNextRenderRedrawOnly||this._onRenderedViewportChange.fire({start:e,end:t}),this._onRender.fire({start:e,end:t}),this._isNextRenderRedrawOnly=!0}}resize(e,t){this._rowCount=t,this._fireOnCanvasResize()}_handleOptionsChanged(){this._renderer.value&&(this.refreshRows(0,this._rowCount-1),this._fireOnCanvasResize())}_fireOnCanvasResize(){this._renderer.value&&(this._renderer.value.dimensions.css.canvas.width===this._canvasWidth&&this._renderer.value.dimensions.css.canvas.height===this._canvasHeight||this._onDimensionsChange.fire(this._renderer.value.dimensions))}hasRenderer(){return!!this._renderer.value}setRenderer(e){this._renderer.value=e,this._renderer.value&&(this._renderer.value.onRequestRedraw(t=>this.refreshRows(t.start,t.end,!0)),this._needsSelectionRefresh=!0,this._fullRefresh())}addRefreshCallback(e){return this._renderDebouncer.addRefreshCallback(e)}_fullRefresh(){this._isPaused?this._needsFullRefresh=!0:this.refreshRows(0,this._rowCount-1)}clearTextureAtlas(){var e,t;this._renderer.value&&((t=(e=this._renderer.value).clearTextureAtlas)==null||t.call(e),this._fullRefresh())}handleDevicePixelRatioChange(){this._charSizeService.measure(),this._renderer.value&&(this._renderer.value.handleDevicePixelRatioChange(),this.refreshRows(0,this._rowCount-1))}handleResize(e,t){this._renderer.value&&(this._isPaused?this._pausedResizeTask.set(()=>{var s;return(s=this._renderer.value)==null?void 0:s.handleResize(e,t)}):this._renderer.value.handleResize(e,t),this._fullRefresh())}handleCharSizeChanged(){var e;(e=this._renderer.value)==null||e.handleCharSizeChanged()}handleBlur(){var e;(e=this._renderer.value)==null||e.handleBlur()}handleFocus(){var e;(e=this._renderer.value)==null||e.handleFocus()}handleSelectionChanged(e,t,s){var n;this._selectionState.start=e,this._selectionState.end=t,this._selectionState.columnSelectMode=s,(n=this._renderer.value)==null||n.handleSelectionChanged(e,t,s)}handleCursorMove(){var e;(e=this._renderer.value)==null||e.handleCursorMove()}clear(){var e;(e=this._renderer.value)==null||e.clear()}};i0=ts([Re(2,nn),Re(3,sf),Re(4,Ba),Re(5,mu),Re(6,sn),Re(7,ai),Re(8,tl)],i0);var zI=class{constructor(e,t,s){this._coreBrowserService=e,this._coreService=t,this._onTimeout=s,this._start=0,this._end=0,this._isBuffering=!1}bufferRows(e,t){this._isBuffering?(this._start=Math.min(this._start,e),this._end=Math.max(this._end,t)):(this._start=e,this._end=t,this._isBuffering=!0),this._timeout===void 0&&(this._timeout=this._coreBrowserService.window.setTimeout(()=>{this._timeout=void 0,this._coreService.decPrivateModes.synchronizedOutput=!1,this._onTimeout()},1e3))}flush(){if(this._timeout!==void 0&&(this._coreBrowserService.window.clearTimeout(this._timeout),this._timeout=void 0),!this._isBuffering)return;let e={start:this._start,end:this._end};return this._isBuffering=!1,e}dispose(){this._timeout!==void 0&&(this._coreBrowserService.window.clearTimeout(this._timeout),this._timeout=void 0)}};function PI(e,t,s,n){let a=s.buffer.x,l=s.buffer.y;if(!s.buffer.hasScrollback)return FI(a,l,e,t,s,n)+rf(l,t,s,n)+HI(a,l,e,t,s,n);let c;if(l===t)return c=a>e?"D":"C",tu(Math.abs(a-e),eu(c,n));c=l>t?"D":"C";let d=Math.abs(l-t),f=II(l>t?e:a,s)+(d-1)*s.cols+1+$I(l>t?a:e);return tu(f,eu(c,n))}function $I(e,t){return e-1}function II(e,t){return t.cols-e}function FI(e,t,s,n,a,l){return rf(t,n,a,l).length===0?"":tu(bN(e,t,e,t-Da(t,a),!1,a).length,eu("D",l))}function rf(e,t,s,n){let a=e-Da(e,s),l=t-Da(t,s),c=Math.abs(a-l)-UI(e,t,s);return tu(c,eu(vN(e,t),n))}function HI(e,t,s,n,a,l){let c;rf(t,n,a,l).length>0?c=n-Da(n,a):c=t;let d=n,f=VI(e,t,s,n,a,l);return tu(bN(e,c,s,d,f==="C",a).length,eu(f,l))}function UI(e,t,s){var c;let n=0,a=e-Da(e,s),l=t-Da(t,s);for(let d=0;d<Math.abs(a-l);d++){let f=vN(e,t)==="A"?-1:1;(c=s.buffer.lines.get(a+f*d))!=null&&c.isWrapped&&n++}return n}function Da(e,t){let s=0,n=t.buffer.lines.get(e),a=n==null?void 0:n.isWrapped;for(;a&&e>=0&&e<t.rows;)s++,n=t.buffer.lines.get(--e),a=n==null?void 0:n.isWrapped;return s}function VI(e,t,s,n,a,l){let c;return rf(s,n,a,l).length>0?c=n-Da(n,a):c=t,e<s&&c<=n||e>=s&&c<n?"C":"D"}function vN(e,t){return e>t?"A":"B"}function bN(e,t,s,n,a,l){let c=e,d=t,f="";for(;(c!==s||d!==n)&&d>=0&&d<l.buffer.lines.length;)c+=a?1:-1,a&&c>l.cols-1?(f+=l.buffer.translateBufferLineToString(d,!1,e,c),c=0,e=0,d++):!a&&c<0&&(f+=l.buffer.translateBufferLineToString(d,!1,0,e+1),c=l.cols-1,e=c,d--);return f+l.buffer.translateBufferLineToString(d,!1,e,c)}function eu(e,t){let s=t?"O":"[";return xe.ESC+s+e}function tu(e,t){e=Math.floor(e);let s="";for(let n=0;n<e;n++)s+=t;return s}var WI=class{constructor(e){this._bufferService=e,this.isSelectAllActive=!1,this.selectionStartLength=0}clearSelection(){this.selectionStart=void 0,this.selectionEnd=void 0,this.isSelectAllActive=!1,this.selectionStartLength=0}get finalSelectionStart(){return this.isSelectAllActive?[0,0]:!this.selectionEnd||!this.selectionStart?this.selectionStart:this.areSelectionValuesReversed()?this.selectionEnd:this.selectionStart}get finalSelectionEnd(){if(this.isSelectAllActive)return[this._bufferService.cols,this._bufferService.buffer.ybase+this._bufferService.rows-1];if(this.selectionStart){if(!this.selectionEnd||this.areSelectionValuesReversed()){let e=this.selectionStart[0]+this.selectionStartLength;return e>this._bufferService.cols?e%this._bufferService.cols===0?[this._bufferService.cols,this.selectionStart[1]+Math.floor(e/this._bufferService.cols)-1]:[e%this._bufferService.cols,this.selectionStart[1]+Math.floor(e/this._bufferService.cols)]:[e,this.selectionStart[1]]}if(this.selectionStartLength&&this.selectionEnd[1]===this.selectionStart[1]){let e=this.selectionStart[0]+this.selectionStartLength;return e>this._bufferService.cols?[e%this._bufferService.cols,this.selectionStart[1]+Math.floor(e/this._bufferService.cols)]:[Math.max(e,this.selectionEnd[0]),this.selectionEnd[1]]}return this.selectionEnd}}areSelectionValuesReversed(){let e=this.selectionStart,t=this.selectionEnd;return!e||!t?!1:e[1]>t[1]||e[1]===t[1]&&e[0]>t[0]}handleTrim(e){return this.selectionStart&&(this.selectionStart[1]-=e),this.selectionEnd&&(this.selectionEnd[1]-=e),this.selectionEnd&&this.selectionEnd[1]<0?(this.clearSelection(),!0):(this.selectionStart&&this.selectionStart[1]<0&&(this.selectionStart[1]=0),!1)}};function B2(e,t){if(e.start.y>e.end.y)throw new Error(`Buffer range end (${e.end.x}, ${e.end.y}) cannot be before start (${e.start.x}, ${e.start.y})`);return t*(e.end.y-e.start.y)+(e.end.x-e.start.x+1)}var Cg=50,qI=15,GI=50,KI=500,YI=" ",XI=new RegExp(YI,"g"),a0=class extends nt{constructor(e,t,s,n,a,l,c,d,f){super(),this._element=e,this._screenElement=t,this._linkifier=s,this._bufferService=n,this._coreService=a,this._mouseService=l,this._optionsService=c,this._renderService=d,this._coreBrowserService=f,this._dragScrollAmount=0,this._enabled=!0,this._workCell=new Jn,this._mouseDownTimeStamp=0,this._oldHasSelection=!1,this._oldSelectionStart=void 0,this._oldSelectionEnd=void 0,this._onLinuxMouseSelection=this._register(new Ce),this.onLinuxMouseSelection=this._onLinuxMouseSelection.event,this._onRedrawRequest=this._register(new Ce),this.onRequestRedraw=this._onRedrawRequest.event,this._onSelectionChange=this._register(new Ce),this.onSelectionChange=this._onSelectionChange.event,this._onRequestScrollLines=this._register(new Ce),this.onRequestScrollLines=this._onRequestScrollLines.event,this._mouseMoveListener=h=>this._handleMouseMove(h),this._mouseUpListener=h=>this._handleMouseUp(h),this._coreService.onUserInput(()=>{this.hasSelection&&this.clearSelection()}),this._trimListener=this._bufferService.buffer.lines.onTrim(h=>this._handleTrim(h)),this._register(this._bufferService.buffers.onBufferActivate(h=>this._handleBufferActivate(h))),this.enable(),this._model=new WI(this._bufferService),this._activeSelectionMode=0,this._register(Ut(()=>{this._removeMouseDownListeners()})),this._register(this._bufferService.onResize(h=>{h.rowsChanged&&this.clearSelection()}))}reset(){this.clearSelection()}disable(){this.clearSelection(),this._enabled=!1}enable(){this._enabled=!0}get selectionStart(){return this._model.finalSelectionStart}get selectionEnd(){return this._model.finalSelectionEnd}get hasSelection(){let e=this._model.finalSelectionStart,t=this._model.finalSelectionEnd;return!e||!t?!1:e[0]!==t[0]||e[1]!==t[1]}get selectionText(){let e=this._model.finalSelectionStart,t=this._model.finalSelectionEnd;if(!e||!t)return"";let s=this._bufferService.buffer,n=[];if(this._activeSelectionMode===3){if(e[0]===t[0])return"";let a=e[0]<t[0]?e[0]:t[0],l=e[0]<t[0]?t[0]:e[0];for(let c=e[1];c<=t[1];c++){let d=s.translateBufferLineToString(c,!0,a,l);n.push(d)}}else{let a=e[1]===t[1]?t[0]:void 0;n.push(s.translateBufferLineToString(e[1],!0,e[0],a));for(let l=e[1]+1;l<=t[1]-1;l++){let c=s.lines.get(l),d=s.translateBufferLineToString(l,!0);c!=null&&c.isWrapped?n[n.length-1]+=d:n.push(d)}if(e[1]!==t[1]){let l=s.lines.get(t[1]),c=s.translateBufferLineToString(t[1],!0,0,t[0]);l&&l.isWrapped?n[n.length-1]+=c:n.push(c)}}return n.map(a=>a.replace(XI," ")).join(mN?`\r
|
|
252
|
+
`))}},f$=class extends Error{constructor(e,t){super(e),this.name="ListenerLeakError",this.stack=t}},p$=class extends Error{constructor(e,t){super(e),this.name="ListenerRefusalError",this.stack=t}},m$=0,yg=class{constructor(e){this.value=e,this.id=m$++}},g$=2,x$,Ce=class{constructor(e){var t,s,n,a;this._size=0,this._options=e,this._leakageMon=(t=this._options)!=null&&t.leakWarningThreshold?new d$((e==null?void 0:e.onListenerError)??lh,((s=this._options)==null?void 0:s.leakWarningThreshold)??u$):void 0,this._perfMon=(n=this._options)!=null&&n._profName?new c$(this._options._profName):void 0,this._deliveryQueue=(a=this._options)==null?void 0:a.deliveryQueue}dispose(){var e,t,s,n;this._disposed||(this._disposed=!0,((e=this._deliveryQueue)==null?void 0:e.current)===this&&this._deliveryQueue.reset(),this._listeners&&(this._listeners=void 0,this._size=0),(s=(t=this._options)==null?void 0:t.onDidRemoveLastListener)==null||s.call(t),(n=this._leakageMon)==null||n.dispose())}get event(){return this._event??(this._event=(e,t,s)=>{var c,d,f,h,m;if(this._leakageMon&&this._size>this._leakageMon.threshold**2){let g=`[${this._leakageMon.name}] REFUSES to accept new listeners because it exceeded its threshold by far (${this._size} vs ${this._leakageMon.threshold})`;console.warn(g);let b=this._leakageMon.getMostFrequentStack()??["UNKNOWN stack",-1],v=new p$(`${g}. HINT: Stack shows most frequent listener (${b[1]}-times)`,b[0]);return(((c=this._options)==null?void 0:c.onListenerError)||lh)(v),nt.None}if(this._disposed)return nt.None;t&&(e=e.bind(t));let n=new yg(e),a;this._leakageMon&&this._size>=Math.ceil(this._leakageMon.threshold*.2)&&(n.stack=h$.create(),a=this._leakageMon.check(n.stack,this._size+1)),this._listeners?this._listeners instanceof yg?(this._deliveryQueue??(this._deliveryQueue=new v$),this._listeners=[this._listeners,n]):this._listeners.push(n):((f=(d=this._options)==null?void 0:d.onWillAddFirstListener)==null||f.call(d,this),this._listeners=n,(m=(h=this._options)==null?void 0:h.onDidAddFirstListener)==null||m.call(h,this)),this._size++;let l=Ut(()=>{a==null||a(),this._removeListener(n)});return s instanceof Yi?s.add(l):Array.isArray(s)&&s.push(l),l}),this._event}_removeListener(e){var a,l,c,d;if((l=(a=this._options)==null?void 0:a.onWillRemoveListener)==null||l.call(a,this),!this._listeners)return;if(this._size===1){this._listeners=void 0,(d=(c=this._options)==null?void 0:c.onDidRemoveLastListener)==null||d.call(c,this),this._size=0;return}let t=this._listeners,s=t.indexOf(e);if(s===-1)throw console.log("disposed?",this._disposed),console.log("size?",this._size),console.log("arr?",JSON.stringify(this._listeners)),new Error("Attempted to dispose unknown listener");this._size--,t[s]=void 0;let n=this._deliveryQueue.current===this;if(this._size*g$<=t.length){let f=0;for(let h=0;h<t.length;h++)t[h]?t[f++]=t[h]:n&&(this._deliveryQueue.end--,f<this._deliveryQueue.i&&this._deliveryQueue.i--);t.length=f}}_deliver(e,t){var n;if(!e)return;let s=((n=this._options)==null?void 0:n.onListenerError)||lh;if(!s){e.value(t);return}try{e.value(t)}catch(a){s(a)}}_deliverQueue(e){let t=e.current._listeners;for(;e.i<e.end;)this._deliver(t[e.i++],e.value);e.reset()}fire(e){var t,s,n,a;if((t=this._deliveryQueue)!=null&&t.current&&(this._deliverQueue(this._deliveryQueue),(s=this._perfMon)==null||s.stop()),(n=this._perfMon)==null||n.start(this._size),this._listeners)if(this._listeners instanceof yg)this._deliver(this._listeners,e);else{let l=this._deliveryQueue;l.enqueue(this,e,this._listeners.length),this._deliverQueue(l)}(a=this._perfMon)==null||a.stop()}hasListeners(){return this._size>0}},v$=class{constructor(){this.i=-1,this.end=0}enqueue(e,t,s){this.i=0,this.end=s,this.current=e,this.value=t}reset(){this.i=this.end,this.current=void 0,this.value=void 0}},Vx=class{constructor(){this.mapWindowIdToZoomLevel=new Map,this._onDidChangeZoomLevel=new Ce,this.onDidChangeZoomLevel=this._onDidChangeZoomLevel.event,this.mapWindowIdToZoomFactor=new Map,this._onDidChangeFullscreen=new Ce,this.onDidChangeFullscreen=this._onDidChangeFullscreen.event,this.mapWindowIdToFullScreen=new Map}getZoomLevel(t){return this.mapWindowIdToZoomLevel.get(this.getWindowId(t))??0}setZoomLevel(t,s){if(this.getZoomLevel(s)===t)return;let n=this.getWindowId(s);this.mapWindowIdToZoomLevel.set(n,t),this._onDidChangeZoomLevel.fire(n)}getZoomFactor(t){return this.mapWindowIdToZoomFactor.get(this.getWindowId(t))??1}setZoomFactor(t,s){this.mapWindowIdToZoomFactor.set(this.getWindowId(s),t)}setFullscreen(t,s){if(this.isFullscreen(s)===t)return;let n=this.getWindowId(s);this.mapWindowIdToFullScreen.set(n,t),this._onDidChangeFullscreen.fire(n)}isFullscreen(t){return!!this.mapWindowIdToFullScreen.get(this.getWindowId(t))}getWindowId(t){return t.vscodeWindowId}};Vx.INSTANCE=new Vx;var cv=Vx;function b$(e,t,s){typeof t=="string"&&(t=e.matchMedia(t)),t.addEventListener("change",s)}cv.INSTANCE.onDidChangeZoomLevel;function _$(e){return cv.INSTANCE.getZoomFactor(e)}cv.INSTANCE.onDidChangeFullscreen;var sl=typeof navigator=="object"?navigator.userAgent:"",Wx=sl.indexOf("Firefox")>=0,y$=sl.indexOf("AppleWebKit")>=0,uv=sl.indexOf("Chrome")>=0,w$=!uv&&sl.indexOf("Safari")>=0;sl.indexOf("Electron/")>=0;sl.indexOf("Android")>=0;var wg=!1;if(typeof ti.matchMedia=="function"){let e=ti.matchMedia("(display-mode: standalone) or (display-mode: window-controls-overlay)"),t=ti.matchMedia("(display-mode: fullscreen)");wg=e.matches,b$(ti,e,({matches:s})=>{wg&&t.matches||(wg=s)})}var Po="en",qx=!1,Gx=!1,ch=!1,sN=!1,Kd,uh=Po,v2=Po,S$,nr,Ca=globalThis,zs,gS;typeof Ca.vscode<"u"&&typeof Ca.vscode.process<"u"?zs=Ca.vscode.process:typeof process<"u"&&typeof((gS=process==null?void 0:process.versions)==null?void 0:gS.node)=="string"&&(zs=process);var xS,j$=typeof((xS=zs==null?void 0:zs.versions)==null?void 0:xS.electron)=="string",k$=j$&&(zs==null?void 0:zs.type)==="renderer",vS;if(typeof zs=="object"){qx=zs.platform==="win32",Gx=zs.platform==="darwin",ch=zs.platform==="linux",ch&&zs.env.SNAP&&zs.env.SNAP_REVISION,zs.env.CI||zs.env.BUILD_ARTIFACTSTAGINGDIRECTORY,Kd=Po,uh=Po;let e=zs.env.VSCODE_NLS_CONFIG;if(e)try{let t=JSON.parse(e);Kd=t.userLocale,v2=t.osLocale,uh=t.resolvedLanguage||Po,S$=(vS=t.languagePack)==null?void 0:vS.translationsConfigFile}catch{}sN=!0}else typeof navigator=="object"&&!k$?(nr=navigator.userAgent,qx=nr.indexOf("Windows")>=0,Gx=nr.indexOf("Macintosh")>=0,(nr.indexOf("Macintosh")>=0||nr.indexOf("iPad")>=0||nr.indexOf("iPhone")>=0)&&navigator.maxTouchPoints&&navigator.maxTouchPoints>0,ch=nr.indexOf("Linux")>=0,(nr==null?void 0:nr.indexOf("Mobi"))>=0,uh=globalThis._VSCODE_NLS_LANGUAGE||Po,Kd=navigator.language.toLowerCase(),v2=Kd):console.error("Unable to resolve platform.");var nN=qx,Sr=Gx,C$=ch,b2=sN,Cr=nr,Oi=uh,N$;(e=>{function t(){return Oi}e.value=t;function s(){return Oi.length===2?Oi==="en":Oi.length>=3?Oi[0]==="e"&&Oi[1]==="n"&&Oi[2]==="-":!1}e.isDefaultVariant=s;function n(){return Oi==="en"}e.isDefault=n})(N$||(N$={}));var E$=typeof Ca.postMessage=="function"&&!Ca.importScripts;(()=>{if(E$){let e=[];Ca.addEventListener("message",s=>{if(s.data&&s.data.vscodeScheduleAsyncWork)for(let n=0,a=e.length;n<a;n++){let l=e[n];if(l.id===s.data.vscodeScheduleAsyncWork){e.splice(n,1),l.callback();return}}});let t=0;return s=>{let n=++t;e.push({id:n,callback:s}),Ca.postMessage({vscodeScheduleAsyncWork:n},"*")}}return e=>setTimeout(e)})();var M$=!!(Cr&&Cr.indexOf("Chrome")>=0);Cr&&Cr.indexOf("Firefox")>=0;!M$&&Cr&&Cr.indexOf("Safari")>=0;Cr&&Cr.indexOf("Edg/")>=0;Cr&&Cr.indexOf("Android")>=0;var Eo=typeof navigator=="object"?navigator:{};b2||document.queryCommandSupported&&document.queryCommandSupported("copy")||Eo&&Eo.clipboard&&Eo.clipboard.writeText,b2||Eo&&Eo.clipboard&&Eo.clipboard.readText;var dv=class{constructor(){this._keyCodeToStr=[],this._strToKeyCode=Object.create(null)}define(e,t){this._keyCodeToStr[e]=t,this._strToKeyCode[t.toLowerCase()]=e}keyCodeToStr(e){return this._keyCodeToStr[e]}strToKeyCode(e){return this._strToKeyCode[e.toLowerCase()]||0}},Sg=new dv,_2=new dv,y2=new dv,T$=new Array(230),rN;(e=>{function t(d){return Sg.keyCodeToStr(d)}e.toString=t;function s(d){return Sg.strToKeyCode(d)}e.fromString=s;function n(d){return _2.keyCodeToStr(d)}e.toUserSettingsUS=n;function a(d){return y2.keyCodeToStr(d)}e.toUserSettingsGeneral=a;function l(d){return _2.strToKeyCode(d)||y2.strToKeyCode(d)}e.fromUserSettings=l;function c(d){if(d>=98&&d<=113)return null;switch(d){case 16:return"Up";case 18:return"Down";case 15:return"Left";case 17:return"Right"}return Sg.keyCodeToStr(d)}e.toElectronAccelerator=c})(rN||(rN={}));var A$=class iN{constructor(t,s,n,a,l){this.ctrlKey=t,this.shiftKey=s,this.altKey=n,this.metaKey=a,this.keyCode=l}equals(t){return t instanceof iN&&this.ctrlKey===t.ctrlKey&&this.shiftKey===t.shiftKey&&this.altKey===t.altKey&&this.metaKey===t.metaKey&&this.keyCode===t.keyCode}getHashCode(){let t=this.ctrlKey?"1":"0",s=this.shiftKey?"1":"0",n=this.altKey?"1":"0",a=this.metaKey?"1":"0";return`K${t}${s}${n}${a}${this.keyCode}`}isModifierKey(){return this.keyCode===0||this.keyCode===5||this.keyCode===57||this.keyCode===6||this.keyCode===4}toKeybinding(){return new R$([this])}isDuplicateModifierCase(){return this.ctrlKey&&this.keyCode===5||this.shiftKey&&this.keyCode===4||this.altKey&&this.keyCode===6||this.metaKey&&this.keyCode===57}},R$=class{constructor(e){if(e.length===0)throw n$("chords");this.chords=e}getHashCode(){let e="";for(let t=0,s=this.chords.length;t<s;t++)t!==0&&(e+=";"),e+=this.chords[t].getHashCode();return e}equals(e){if(e===null||this.chords.length!==e.chords.length)return!1;for(let t=0;t<this.chords.length;t++)if(!this.chords[t].equals(e.chords[t]))return!1;return!0}};function D$(e){if(e.charCode){let s=String.fromCharCode(e.charCode).toUpperCase();return rN.fromString(s)}let t=e.keyCode;if(t===3)return 7;if(Wx)switch(t){case 59:return 85;case 60:if(C$)return 97;break;case 61:return 86;case 107:return 109;case 109:return 111;case 173:return 88;case 224:if(Sr)return 57;break}else if(y$&&(Sr&&t===93||!Sr&&t===92))return 57;return T$[t]||0}var L$=Sr?256:2048,B$=512,O$=1024,z$=Sr?2048:256,w2=class{constructor(e){var s;this._standardKeyboardEventBrand=!0;let t=e;this.browserEvent=t,this.target=t.target,this.ctrlKey=t.ctrlKey,this.shiftKey=t.shiftKey,this.altKey=t.altKey,this.metaKey=t.metaKey,this.altGraphKey=(s=t.getModifierState)==null?void 0:s.call(t,"AltGraph"),this.keyCode=D$(t),this.code=t.code,this.ctrlKey=this.ctrlKey||this.keyCode===5,this.altKey=this.altKey||this.keyCode===6,this.shiftKey=this.shiftKey||this.keyCode===4,this.metaKey=this.metaKey||this.keyCode===57,this._asKeybinding=this._computeKeybinding(),this._asKeyCodeChord=this._computeKeyCodeChord()}preventDefault(){this.browserEvent&&this.browserEvent.preventDefault&&this.browserEvent.preventDefault()}stopPropagation(){this.browserEvent&&this.browserEvent.stopPropagation&&this.browserEvent.stopPropagation()}toKeyCodeChord(){return this._asKeyCodeChord}equals(e){return this._asKeybinding===e}_computeKeybinding(){let e=0;this.keyCode!==5&&this.keyCode!==4&&this.keyCode!==6&&this.keyCode!==57&&(e=this.keyCode);let t=0;return this.ctrlKey&&(t|=L$),this.altKey&&(t|=B$),this.shiftKey&&(t|=O$),this.metaKey&&(t|=z$),t|=e,t}_computeKeyCodeChord(){let e=0;return this.keyCode!==5&&this.keyCode!==4&&this.keyCode!==6&&this.keyCode!==57&&(e=this.keyCode),new A$(this.ctrlKey,this.shiftKey,this.altKey,this.metaKey,e)}},S2=new WeakMap;function P$(e){if(!e.parent||e.parent===e)return null;try{let t=e.location,s=e.parent.location;if(t.origin!=="null"&&s.origin!=="null"&&t.origin!==s.origin)return null}catch{return null}return e.parent}var $$=class{static getSameOriginWindowChain(e){let t=S2.get(e);if(!t){t=[],S2.set(e,t);let s=e,n;do n=P$(s),n?t.push({window:new WeakRef(s),iframeElement:s.frameElement||null}):t.push({window:new WeakRef(s),iframeElement:null}),s=n;while(s)}return t.slice(0)}static getPositionOfChildWindowRelativeToAncestorWindow(e,t){if(!t||e===t)return{top:0,left:0};let s=0,n=0,a=this.getSameOriginWindowChain(e);for(let l of a){let c=l.window.deref();if(s+=(c==null?void 0:c.scrollY)??0,n+=(c==null?void 0:c.scrollX)??0,c===t||!l.iframeElement)break;let d=l.iframeElement.getBoundingClientRect();s+=d.top,n+=d.left}return{top:s,left:n}}},Yd=class{constructor(e,t){this.timestamp=Date.now(),this.browserEvent=t,this.leftButton=t.button===0,this.middleButton=t.button===1,this.rightButton=t.button===2,this.buttons=t.buttons,this.target=t.target,this.detail=t.detail||1,t.type==="dblclick"&&(this.detail=2),this.ctrlKey=t.ctrlKey,this.shiftKey=t.shiftKey,this.altKey=t.altKey,this.metaKey=t.metaKey,typeof t.pageX=="number"?(this.posx=t.pageX,this.posy=t.pageY):(this.posx=t.clientX+this.target.ownerDocument.body.scrollLeft+this.target.ownerDocument.documentElement.scrollLeft,this.posy=t.clientY+this.target.ownerDocument.body.scrollTop+this.target.ownerDocument.documentElement.scrollTop);let s=$$.getPositionOfChildWindowRelativeToAncestorWindow(e,t.view);this.posx-=s.left,this.posy-=s.top}preventDefault(){this.browserEvent.preventDefault()}stopPropagation(){this.browserEvent.stopPropagation()}},j2=class{constructor(e,t=0,s=0){var a;this.browserEvent=e||null,this.target=e?e.target||e.targetNode||e.srcElement:null,this.deltaY=s,this.deltaX=t;let n=!1;if(uv){let l=navigator.userAgent.match(/Chrome\/(\d+)/);n=(l?parseInt(l[1]):123)<=122}if(e){let l=e,c=e,d=((a=e.view)==null?void 0:a.devicePixelRatio)||1;if(typeof l.wheelDeltaY<"u")n?this.deltaY=l.wheelDeltaY/(120*d):this.deltaY=l.wheelDeltaY/120;else if(typeof c.VERTICAL_AXIS<"u"&&c.axis===c.VERTICAL_AXIS)this.deltaY=-c.detail/3;else if(e.type==="wheel"){let f=e;f.deltaMode===f.DOM_DELTA_LINE?Wx&&!Sr?this.deltaY=-e.deltaY/3:this.deltaY=-e.deltaY:this.deltaY=-e.deltaY/40}if(typeof l.wheelDeltaX<"u")w$&&nN?this.deltaX=-(l.wheelDeltaX/120):n?this.deltaX=l.wheelDeltaX/(120*d):this.deltaX=l.wheelDeltaX/120;else if(typeof c.HORIZONTAL_AXIS<"u"&&c.axis===c.HORIZONTAL_AXIS)this.deltaX=-e.detail/3;else if(e.type==="wheel"){let f=e;f.deltaMode===f.DOM_DELTA_LINE?Wx&&!Sr?this.deltaX=-e.deltaX/3:this.deltaX=-e.deltaX:this.deltaX=-e.deltaX/40}this.deltaY===0&&this.deltaX===0&&e.wheelDelta&&(n?this.deltaY=e.wheelDelta/(120*d):this.deltaY=e.wheelDelta/120)}}preventDefault(){var e;(e=this.browserEvent)==null||e.preventDefault()}stopPropagation(){var e;(e=this.browserEvent)==null||e.stopPropagation()}},aN=Object.freeze(function(e,t){let s=setTimeout(e.bind(t),0);return{dispose(){clearTimeout(s)}}}),I$;(e=>{function t(s){return s===e.None||s===e.Cancelled||s instanceof F$?!0:!s||typeof s!="object"?!1:typeof s.isCancellationRequested=="boolean"&&typeof s.onCancellationRequested=="function"}e.isCancellationToken=t,e.None=Object.freeze({isCancellationRequested:!1,onCancellationRequested:Is.None}),e.Cancelled=Object.freeze({isCancellationRequested:!0,onCancellationRequested:aN})})(I$||(I$={}));var F$=class{constructor(){this._isCancelled=!1,this._emitter=null}cancel(){this._isCancelled||(this._isCancelled=!0,this._emitter&&(this._emitter.fire(void 0),this.dispose()))}get isCancellationRequested(){return this._isCancelled}get onCancellationRequested(){return this._isCancelled?aN:(this._emitter||(this._emitter=new Ce),this._emitter.event)}dispose(){this._emitter&&(this._emitter.dispose(),this._emitter=null)}},hv=class{constructor(e,t){this._isDisposed=!1,this._token=-1,typeof e=="function"&&typeof t=="number"&&this.setIfNotSet(e,t)}dispose(){this.cancel(),this._isDisposed=!0}cancel(){this._token!==-1&&(clearTimeout(this._token),this._token=-1)}cancelAndSet(e,t){if(this._isDisposed)throw new $x("Calling 'cancelAndSet' on a disposed TimeoutTimer");this.cancel(),this._token=setTimeout(()=>{this._token=-1,e()},t)}setIfNotSet(e,t){if(this._isDisposed)throw new $x("Calling 'setIfNotSet' on a disposed TimeoutTimer");this._token===-1&&(this._token=setTimeout(()=>{this._token=-1,e()},t))}},H$=class{constructor(){this.disposable=void 0,this.isDisposed=!1}cancel(){var e;(e=this.disposable)==null||e.dispose(),this.disposable=void 0}cancelAndSet(e,t,s=globalThis){if(this.isDisposed)throw new $x("Calling 'cancelAndSet' on a disposed IntervalTimer");this.cancel();let n=s.setInterval(()=>{e()},t);this.disposable=Ut(()=>{s.clearInterval(n),this.disposable=void 0})}dispose(){this.cancel(),this.isDisposed=!0}},U$;(e=>{async function t(n){let a,l=await Promise.all(n.map(c=>c.then(d=>d,d=>{a||(a=d)})));if(typeof a<"u")throw a;return l}e.settled=t;function s(n){return new Promise(async(a,l)=>{try{await n(a,l)}catch(c){l(c)}})}e.withAsyncBody=s})(U$||(U$={}));var k2=class qn{static fromArray(t){return new qn(s=>{s.emitMany(t)})}static fromPromise(t){return new qn(async s=>{s.emitMany(await t)})}static fromPromises(t){return new qn(async s=>{await Promise.all(t.map(async n=>s.emitOne(await n)))})}static merge(t){return new qn(async s=>{await Promise.all(t.map(async n=>{for await(let a of n)s.emitOne(a)}))})}constructor(t,s){this._state=0,this._results=[],this._error=null,this._onReturn=s,this._onStateChanged=new Ce,queueMicrotask(async()=>{let n={emitOne:a=>this.emitOne(a),emitMany:a=>this.emitMany(a),reject:a=>this.reject(a)};try{await Promise.resolve(t(n)),this.resolve()}catch(a){this.reject(a)}finally{n.emitOne=void 0,n.emitMany=void 0,n.reject=void 0}})}[Symbol.asyncIterator](){let t=0;return{next:async()=>{do{if(this._state===2)throw this._error;if(t<this._results.length)return{done:!1,value:this._results[t++]};if(this._state===1)return{done:!0,value:void 0};await Is.toPromise(this._onStateChanged.event)}while(!0)},return:async()=>{var s;return(s=this._onReturn)==null||s.call(this),{done:!0,value:void 0}}}}static map(t,s){return new qn(async n=>{for await(let a of t)n.emitOne(s(a))})}map(t){return qn.map(this,t)}static filter(t,s){return new qn(async n=>{for await(let a of t)s(a)&&n.emitOne(a)})}filter(t){return qn.filter(this,t)}static coalesce(t){return qn.filter(t,s=>!!s)}coalesce(){return qn.coalesce(this)}static async toPromise(t){let s=[];for await(let n of t)s.push(n);return s}toPromise(){return qn.toPromise(this)}emitOne(t){this._state===0&&(this._results.push(t),this._onStateChanged.fire())}emitMany(t){this._state===0&&(this._results=this._results.concat(t),this._onStateChanged.fire())}resolve(){this._state===0&&(this._state=1,this._onStateChanged.fire())}reject(t){this._state===0&&(this._state=2,this._error=t,this._onStateChanged.fire())}};k2.EMPTY=k2.fromArray([]);var{getWindow:wr,getWindowId:V$,onDidRegisterWindow:W$}=(function(){let e=new Map,t={window:ti,disposables:new Yi};e.set(ti.vscodeWindowId,t);let s=new Ce,n=new Ce,a=new Ce;function l(c,d){return(typeof c=="number"?e.get(c):void 0)??(d?t:void 0)}return{onDidRegisterWindow:s.event,onWillUnregisterWindow:a.event,onDidUnregisterWindow:n.event,registerWindow(c){if(e.has(c.vscodeWindowId))return nt.None;let d=new Yi,f={window:c,disposables:d.add(new Yi)};return e.set(c.vscodeWindowId,f),d.add(Ut(()=>{e.delete(c.vscodeWindowId),n.fire(c)})),d.add(Ge(c,Cs.BEFORE_UNLOAD,()=>{a.fire(c)})),s.fire(f),d},getWindows(){return e.values()},getWindowsCount(){return e.size},getWindowId(c){return c.vscodeWindowId},hasWindow(c){return e.has(c)},getWindowById:l,getWindow(c){var h;let d=c;if((h=d==null?void 0:d.ownerDocument)!=null&&h.defaultView)return d.ownerDocument.defaultView.window;let f=c;return f!=null&&f.view?f.view.window:ti},getDocument(c){return wr(c).document}}})(),q$=class{constructor(e,t,s,n){this._node=e,this._type=t,this._handler=s,this._options=n||!1,this._node.addEventListener(this._type,this._handler,this._options)}dispose(){this._handler&&(this._node.removeEventListener(this._type,this._handler,this._options),this._node=null,this._handler=null)}};function Ge(e,t,s,n){return new q$(e,t,s,n)}var C2=function(e,t,s,n){return Ge(e,t,s,n)},fv,G$=class extends H${constructor(e){super(),this.defaultTarget=e&&wr(e)}cancelAndSet(e,t,s){return super.cancelAndSet(e,t,s??this.defaultTarget)}},N2=class{constructor(e,t=0){this._runner=e,this.priority=t,this._canceled=!1}dispose(){this._canceled=!0}execute(){if(!this._canceled)try{this._runner()}catch(e){lh(e)}}static sort(e,t){return t.priority-e.priority}};(function(){let e=new Map,t=new Map,s=new Map,n=new Map,a=l=>{s.set(l,!1);let c=e.get(l)??[];for(t.set(l,c),e.set(l,[]),n.set(l,!0);c.length>0;)c.sort(N2.sort),c.shift().execute();n.set(l,!1)};fv=(l,c,d=0)=>{let f=V$(l),h=new N2(c,d),m=e.get(f);return m||(m=[],e.set(f,m)),m.push(h),s.get(f)||(s.set(f,!0),l.requestAnimationFrame(()=>a(f))),h}})();function K$(e){let t=e.getBoundingClientRect(),s=wr(e);return{left:t.left+s.scrollX,top:t.top+s.scrollY,width:t.width,height:t.height}}var Cs={CLICK:"click",MOUSE_DOWN:"mousedown",MOUSE_OVER:"mouseover",MOUSE_LEAVE:"mouseleave",MOUSE_WHEEL:"wheel",POINTER_UP:"pointerup",POINTER_DOWN:"pointerdown",POINTER_MOVE:"pointermove",KEY_DOWN:"keydown",KEY_UP:"keyup",BEFORE_UNLOAD:"beforeunload",CHANGE:"change",FOCUS:"focus",BLUR:"blur",INPUT:"input"},Y$=class{constructor(e){this.domNode=e,this._maxWidth="",this._width="",this._height="",this._top="",this._left="",this._bottom="",this._right="",this._paddingTop="",this._paddingLeft="",this._paddingBottom="",this._paddingRight="",this._fontFamily="",this._fontWeight="",this._fontSize="",this._fontStyle="",this._fontFeatureSettings="",this._fontVariationSettings="",this._textDecoration="",this._lineHeight="",this._letterSpacing="",this._className="",this._display="",this._position="",this._visibility="",this._color="",this._backgroundColor="",this._layerHint=!1,this._contain="none",this._boxShadow=""}setMaxWidth(e){let t=fn(e);this._maxWidth!==t&&(this._maxWidth=t,this.domNode.style.maxWidth=this._maxWidth)}setWidth(e){let t=fn(e);this._width!==t&&(this._width=t,this.domNode.style.width=this._width)}setHeight(e){let t=fn(e);this._height!==t&&(this._height=t,this.domNode.style.height=this._height)}setTop(e){let t=fn(e);this._top!==t&&(this._top=t,this.domNode.style.top=this._top)}setLeft(e){let t=fn(e);this._left!==t&&(this._left=t,this.domNode.style.left=this._left)}setBottom(e){let t=fn(e);this._bottom!==t&&(this._bottom=t,this.domNode.style.bottom=this._bottom)}setRight(e){let t=fn(e);this._right!==t&&(this._right=t,this.domNode.style.right=this._right)}setPaddingTop(e){let t=fn(e);this._paddingTop!==t&&(this._paddingTop=t,this.domNode.style.paddingTop=this._paddingTop)}setPaddingLeft(e){let t=fn(e);this._paddingLeft!==t&&(this._paddingLeft=t,this.domNode.style.paddingLeft=this._paddingLeft)}setPaddingBottom(e){let t=fn(e);this._paddingBottom!==t&&(this._paddingBottom=t,this.domNode.style.paddingBottom=this._paddingBottom)}setPaddingRight(e){let t=fn(e);this._paddingRight!==t&&(this._paddingRight=t,this.domNode.style.paddingRight=this._paddingRight)}setFontFamily(e){this._fontFamily!==e&&(this._fontFamily=e,this.domNode.style.fontFamily=this._fontFamily)}setFontWeight(e){this._fontWeight!==e&&(this._fontWeight=e,this.domNode.style.fontWeight=this._fontWeight)}setFontSize(e){let t=fn(e);this._fontSize!==t&&(this._fontSize=t,this.domNode.style.fontSize=this._fontSize)}setFontStyle(e){this._fontStyle!==e&&(this._fontStyle=e,this.domNode.style.fontStyle=this._fontStyle)}setFontFeatureSettings(e){this._fontFeatureSettings!==e&&(this._fontFeatureSettings=e,this.domNode.style.fontFeatureSettings=this._fontFeatureSettings)}setFontVariationSettings(e){this._fontVariationSettings!==e&&(this._fontVariationSettings=e,this.domNode.style.fontVariationSettings=this._fontVariationSettings)}setTextDecoration(e){this._textDecoration!==e&&(this._textDecoration=e,this.domNode.style.textDecoration=this._textDecoration)}setLineHeight(e){let t=fn(e);this._lineHeight!==t&&(this._lineHeight=t,this.domNode.style.lineHeight=this._lineHeight)}setLetterSpacing(e){let t=fn(e);this._letterSpacing!==t&&(this._letterSpacing=t,this.domNode.style.letterSpacing=this._letterSpacing)}setClassName(e){this._className!==e&&(this._className=e,this.domNode.className=this._className)}toggleClassName(e,t){this.domNode.classList.toggle(e,t),this._className=this.domNode.className}setDisplay(e){this._display!==e&&(this._display=e,this.domNode.style.display=this._display)}setPosition(e){this._position!==e&&(this._position=e,this.domNode.style.position=this._position)}setVisibility(e){this._visibility!==e&&(this._visibility=e,this.domNode.style.visibility=this._visibility)}setColor(e){this._color!==e&&(this._color=e,this.domNode.style.color=this._color)}setBackgroundColor(e){this._backgroundColor!==e&&(this._backgroundColor=e,this.domNode.style.backgroundColor=this._backgroundColor)}setLayerHinting(e){this._layerHint!==e&&(this._layerHint=e,this.domNode.style.transform=this._layerHint?"translate3d(0px, 0px, 0px)":"")}setBoxShadow(e){this._boxShadow!==e&&(this._boxShadow=e,this.domNode.style.boxShadow=e)}setContain(e){this._contain!==e&&(this._contain=e,this.domNode.style.contain=this._contain)}setAttribute(e,t){this.domNode.setAttribute(e,t)}removeAttribute(e){this.domNode.removeAttribute(e)}appendChild(e){this.domNode.appendChild(e.domNode)}removeChild(e){this.domNode.removeChild(e.domNode)}};function fn(e){return typeof e=="number"?`${e}px`:e}function Hc(e){return new Y$(e)}var oN=class{constructor(){this._hooks=new Yi,this._pointerMoveCallback=null,this._onStopCallback=null}dispose(){this.stopMonitoring(!1),this._hooks.dispose()}stopMonitoring(e,t){if(!this.isMonitoring())return;this._hooks.clear(),this._pointerMoveCallback=null;let s=this._onStopCallback;this._onStopCallback=null,e&&s&&s(t)}isMonitoring(){return!!this._pointerMoveCallback}startMonitoring(e,t,s,n,a){this.isMonitoring()&&this.stopMonitoring(!1),this._pointerMoveCallback=n,this._onStopCallback=a;let l=e;try{e.setPointerCapture(t),this._hooks.add(Ut(()=>{try{e.releasePointerCapture(t)}catch{}}))}catch{l=wr(e)}this._hooks.add(Ge(l,Cs.POINTER_MOVE,c=>{if(c.buttons!==s){this.stopMonitoring(!0);return}c.preventDefault(),this._pointerMoveCallback(c)})),this._hooks.add(Ge(l,Cs.POINTER_UP,c=>this.stopMonitoring(!0)))}};function X$(e,t,s){let n=null,a=null;if(typeof s.value=="function"?(n="value",a=s.value,a.length!==0&&console.warn("Memoize should only be used in functions with zero parameters")):typeof s.get=="function"&&(n="get",a=s.get),!a)throw new Error("not supported");let l=`$memoize$${t}`;s[n]=function(...c){return this.hasOwnProperty(l)||Object.defineProperty(this,l,{configurable:!1,enumerable:!1,writable:!1,value:a.apply(this,c)}),this[l]}}var gr;(e=>(e.Tap="-xterm-gesturetap",e.Change="-xterm-gesturechange",e.Start="-xterm-gesturestart",e.End="-xterm-gesturesend",e.Contextmenu="-xterm-gesturecontextmenu"))(gr||(gr={}));var Mc=class Vs extends nt{constructor(){super(),this.dispatched=!1,this.targets=new x2,this.ignoreTargets=new x2,this.activeTouches={},this.handle=null,this._lastSetTapCountTime=0,this._register(Is.runAndSubscribe(W$,({window:t,disposables:s})=>{s.add(Ge(t.document,"touchstart",n=>this.onTouchStart(n),{passive:!1})),s.add(Ge(t.document,"touchend",n=>this.onTouchEnd(t,n))),s.add(Ge(t.document,"touchmove",n=>this.onTouchMove(n),{passive:!1}))},{window:ti,disposables:this._store}))}static addTarget(t){if(!Vs.isTouchDevice())return nt.None;Vs.INSTANCE||(Vs.INSTANCE=new Vs);let s=Vs.INSTANCE.targets.push(t);return Ut(s)}static ignoreTarget(t){if(!Vs.isTouchDevice())return nt.None;Vs.INSTANCE||(Vs.INSTANCE=new Vs);let s=Vs.INSTANCE.ignoreTargets.push(t);return Ut(s)}static isTouchDevice(){return"ontouchstart"in ti||navigator.maxTouchPoints>0}dispose(){this.handle&&(this.handle.dispose(),this.handle=null),super.dispose()}onTouchStart(t){let s=Date.now();this.handle&&(this.handle.dispose(),this.handle=null);for(let n=0,a=t.targetTouches.length;n<a;n++){let l=t.targetTouches.item(n);this.activeTouches[l.identifier]={id:l.identifier,initialTarget:l.target,initialTimeStamp:s,initialPageX:l.pageX,initialPageY:l.pageY,rollingTimestamps:[s],rollingPageX:[l.pageX],rollingPageY:[l.pageY]};let c=this.newGestureEvent(gr.Start,l.target);c.pageX=l.pageX,c.pageY=l.pageY,this.dispatchEvent(c)}this.dispatched&&(t.preventDefault(),t.stopPropagation(),this.dispatched=!1)}onTouchEnd(t,s){let n=Date.now(),a=Object.keys(this.activeTouches).length;for(let l=0,c=s.changedTouches.length;l<c;l++){let d=s.changedTouches.item(l);if(!this.activeTouches.hasOwnProperty(String(d.identifier))){console.warn("move of an UNKNOWN touch",d);continue}let f=this.activeTouches[d.identifier],h=Date.now()-f.initialTimeStamp;if(h<Vs.HOLD_DELAY&&Math.abs(f.initialPageX-Nn(f.rollingPageX))<30&&Math.abs(f.initialPageY-Nn(f.rollingPageY))<30){let m=this.newGestureEvent(gr.Tap,f.initialTarget);m.pageX=Nn(f.rollingPageX),m.pageY=Nn(f.rollingPageY),this.dispatchEvent(m)}else if(h>=Vs.HOLD_DELAY&&Math.abs(f.initialPageX-Nn(f.rollingPageX))<30&&Math.abs(f.initialPageY-Nn(f.rollingPageY))<30){let m=this.newGestureEvent(gr.Contextmenu,f.initialTarget);m.pageX=Nn(f.rollingPageX),m.pageY=Nn(f.rollingPageY),this.dispatchEvent(m)}else if(a===1){let m=Nn(f.rollingPageX),g=Nn(f.rollingPageY),b=Nn(f.rollingTimestamps)-f.rollingTimestamps[0],v=m-f.rollingPageX[0],y=g-f.rollingPageY[0],S=[...this.targets].filter(j=>f.initialTarget instanceof Node&&j.contains(f.initialTarget));this.inertia(t,S,n,Math.abs(v)/b,v>0?1:-1,m,Math.abs(y)/b,y>0?1:-1,g)}this.dispatchEvent(this.newGestureEvent(gr.End,f.initialTarget)),delete this.activeTouches[d.identifier]}this.dispatched&&(s.preventDefault(),s.stopPropagation(),this.dispatched=!1)}newGestureEvent(t,s){let n=document.createEvent("CustomEvent");return n.initEvent(t,!1,!0),n.initialTarget=s,n.tapCount=0,n}dispatchEvent(t){if(t.type===gr.Tap){let s=new Date().getTime(),n=0;s-this._lastSetTapCountTime>Vs.CLEAR_TAP_COUNT_TIME?n=1:n=2,this._lastSetTapCountTime=s,t.tapCount=n}else(t.type===gr.Change||t.type===gr.Contextmenu)&&(this._lastSetTapCountTime=0);if(t.initialTarget instanceof Node){for(let n of this.ignoreTargets)if(n.contains(t.initialTarget))return;let s=[];for(let n of this.targets)if(n.contains(t.initialTarget)){let a=0,l=t.initialTarget;for(;l&&l!==n;)a++,l=l.parentElement;s.push([a,n])}s.sort((n,a)=>n[0]-a[0]);for(let[n,a]of s)a.dispatchEvent(t),this.dispatched=!0}}inertia(t,s,n,a,l,c,d,f,h){this.handle=fv(t,()=>{let m=Date.now(),g=m-n,b=0,v=0,y=!0;a+=Vs.SCROLL_FRICTION*g,d+=Vs.SCROLL_FRICTION*g,a>0&&(y=!1,b=l*a*g),d>0&&(y=!1,v=f*d*g);let S=this.newGestureEvent(gr.Change);S.translationX=b,S.translationY=v,s.forEach(j=>j.dispatchEvent(S)),y||this.inertia(t,s,m,a,l,c+b,d,f,h+v)})}onTouchMove(t){let s=Date.now();for(let n=0,a=t.changedTouches.length;n<a;n++){let l=t.changedTouches.item(n);if(!this.activeTouches.hasOwnProperty(String(l.identifier))){console.warn("end of an UNKNOWN touch",l);continue}let c=this.activeTouches[l.identifier],d=this.newGestureEvent(gr.Change,c.initialTarget);d.translationX=l.pageX-Nn(c.rollingPageX),d.translationY=l.pageY-Nn(c.rollingPageY),d.pageX=l.pageX,d.pageY=l.pageY,this.dispatchEvent(d),c.rollingPageX.length>3&&(c.rollingPageX.shift(),c.rollingPageY.shift(),c.rollingTimestamps.shift()),c.rollingPageX.push(l.pageX),c.rollingPageY.push(l.pageY),c.rollingTimestamps.push(s)}this.dispatched&&(t.preventDefault(),t.stopPropagation(),this.dispatched=!1)}};Mc.SCROLL_FRICTION=-.005,Mc.HOLD_DELAY=700,Mc.CLEAR_TAP_COUNT_TIME=400,ts([X$],Mc,"isTouchDevice",1);var J$=Mc,pv=class extends nt{onclick(e,t){this._register(Ge(e,Cs.CLICK,s=>t(new Yd(wr(e),s))))}onmousedown(e,t){this._register(Ge(e,Cs.MOUSE_DOWN,s=>t(new Yd(wr(e),s))))}onmouseover(e,t){this._register(Ge(e,Cs.MOUSE_OVER,s=>t(new Yd(wr(e),s))))}onmouseleave(e,t){this._register(Ge(e,Cs.MOUSE_LEAVE,s=>t(new Yd(wr(e),s))))}onkeydown(e,t){this._register(Ge(e,Cs.KEY_DOWN,s=>t(new w2(s))))}onkeyup(e,t){this._register(Ge(e,Cs.KEY_UP,s=>t(new w2(s))))}oninput(e,t){this._register(Ge(e,Cs.INPUT,t))}onblur(e,t){this._register(Ge(e,Cs.BLUR,t))}onfocus(e,t){this._register(Ge(e,Cs.FOCUS,t))}onchange(e,t){this._register(Ge(e,Cs.CHANGE,t))}ignoreGesture(e){return J$.ignoreTarget(e)}},E2=11,Q$=class extends pv{constructor(e){super(),this._onActivate=e.onActivate,this.bgDomNode=document.createElement("div"),this.bgDomNode.className="arrow-background",this.bgDomNode.style.position="absolute",this.bgDomNode.style.width=e.bgWidth+"px",this.bgDomNode.style.height=e.bgHeight+"px",typeof e.top<"u"&&(this.bgDomNode.style.top="0px"),typeof e.left<"u"&&(this.bgDomNode.style.left="0px"),typeof e.bottom<"u"&&(this.bgDomNode.style.bottom="0px"),typeof e.right<"u"&&(this.bgDomNode.style.right="0px"),this.domNode=document.createElement("div"),this.domNode.className=e.className,this.domNode.style.position="absolute",this.domNode.style.width=E2+"px",this.domNode.style.height=E2+"px",typeof e.top<"u"&&(this.domNode.style.top=e.top+"px"),typeof e.left<"u"&&(this.domNode.style.left=e.left+"px"),typeof e.bottom<"u"&&(this.domNode.style.bottom=e.bottom+"px"),typeof e.right<"u"&&(this.domNode.style.right=e.right+"px"),this._pointerMoveMonitor=this._register(new oN),this._register(C2(this.bgDomNode,Cs.POINTER_DOWN,t=>this._arrowPointerDown(t))),this._register(C2(this.domNode,Cs.POINTER_DOWN,t=>this._arrowPointerDown(t))),this._pointerdownRepeatTimer=this._register(new G$),this._pointerdownScheduleRepeatTimer=this._register(new hv)}_arrowPointerDown(e){if(!e.target||!(e.target instanceof Element))return;let t=()=>{this._pointerdownRepeatTimer.cancelAndSet(()=>this._onActivate(),1e3/24,wr(e))};this._onActivate(),this._pointerdownRepeatTimer.cancel(),this._pointerdownScheduleRepeatTimer.cancelAndSet(t,200),this._pointerMoveMonitor.startMonitoring(e.target,e.pointerId,e.buttons,s=>{},()=>{this._pointerdownRepeatTimer.cancel(),this._pointerdownScheduleRepeatTimer.cancel()}),e.preventDefault()}},Z$=class Kx{constructor(t,s,n,a,l,c,d){this._forceIntegerValues=t,this._scrollStateBrand=void 0,this._forceIntegerValues&&(s=s|0,n=n|0,a=a|0,l=l|0,c=c|0,d=d|0),this.rawScrollLeft=a,this.rawScrollTop=d,s<0&&(s=0),a+s>n&&(a=n-s),a<0&&(a=0),l<0&&(l=0),d+l>c&&(d=c-l),d<0&&(d=0),this.width=s,this.scrollWidth=n,this.scrollLeft=a,this.height=l,this.scrollHeight=c,this.scrollTop=d}equals(t){return this.rawScrollLeft===t.rawScrollLeft&&this.rawScrollTop===t.rawScrollTop&&this.width===t.width&&this.scrollWidth===t.scrollWidth&&this.scrollLeft===t.scrollLeft&&this.height===t.height&&this.scrollHeight===t.scrollHeight&&this.scrollTop===t.scrollTop}withScrollDimensions(t,s){return new Kx(this._forceIntegerValues,typeof t.width<"u"?t.width:this.width,typeof t.scrollWidth<"u"?t.scrollWidth:this.scrollWidth,s?this.rawScrollLeft:this.scrollLeft,typeof t.height<"u"?t.height:this.height,typeof t.scrollHeight<"u"?t.scrollHeight:this.scrollHeight,s?this.rawScrollTop:this.scrollTop)}withScrollPosition(t){return new Kx(this._forceIntegerValues,this.width,this.scrollWidth,typeof t.scrollLeft<"u"?t.scrollLeft:this.rawScrollLeft,this.height,this.scrollHeight,typeof t.scrollTop<"u"?t.scrollTop:this.rawScrollTop)}createScrollEvent(t,s){let n=this.width!==t.width,a=this.scrollWidth!==t.scrollWidth,l=this.scrollLeft!==t.scrollLeft,c=this.height!==t.height,d=this.scrollHeight!==t.scrollHeight,f=this.scrollTop!==t.scrollTop;return{inSmoothScrolling:s,oldWidth:t.width,oldScrollWidth:t.scrollWidth,oldScrollLeft:t.scrollLeft,width:this.width,scrollWidth:this.scrollWidth,scrollLeft:this.scrollLeft,oldHeight:t.height,oldScrollHeight:t.scrollHeight,oldScrollTop:t.scrollTop,height:this.height,scrollHeight:this.scrollHeight,scrollTop:this.scrollTop,widthChanged:n,scrollWidthChanged:a,scrollLeftChanged:l,heightChanged:c,scrollHeightChanged:d,scrollTopChanged:f}}},eI=class extends nt{constructor(e){super(),this._scrollableBrand=void 0,this._onScroll=this._register(new Ce),this.onScroll=this._onScroll.event,this._smoothScrollDuration=e.smoothScrollDuration,this._scheduleAtNextAnimationFrame=e.scheduleAtNextAnimationFrame,this._state=new Z$(e.forceIntegerValues,0,0,0,0,0,0),this._smoothScrolling=null}dispose(){this._smoothScrolling&&(this._smoothScrolling.dispose(),this._smoothScrolling=null),super.dispose()}setSmoothScrollDuration(e){this._smoothScrollDuration=e}validateScrollPosition(e){return this._state.withScrollPosition(e)}getScrollDimensions(){return this._state}setScrollDimensions(e,t){var n;let s=this._state.withScrollDimensions(e,t);this._setState(s,!!this._smoothScrolling),(n=this._smoothScrolling)==null||n.acceptScrollDimensions(this._state)}getFutureScrollPosition(){return this._smoothScrolling?this._smoothScrolling.to:this._state}getCurrentScrollPosition(){return this._state}setScrollPositionNow(e){let t=this._state.withScrollPosition(e);this._smoothScrolling&&(this._smoothScrolling.dispose(),this._smoothScrolling=null),this._setState(t,!1)}setScrollPositionSmooth(e,t){if(this._smoothScrollDuration===0)return this.setScrollPositionNow(e);if(this._smoothScrolling){e={scrollLeft:typeof e.scrollLeft>"u"?this._smoothScrolling.to.scrollLeft:e.scrollLeft,scrollTop:typeof e.scrollTop>"u"?this._smoothScrolling.to.scrollTop:e.scrollTop};let s=this._state.withScrollPosition(e);if(this._smoothScrolling.to.scrollLeft===s.scrollLeft&&this._smoothScrolling.to.scrollTop===s.scrollTop)return;let n;t?n=new T2(this._smoothScrolling.from,s,this._smoothScrolling.startTime,this._smoothScrolling.duration):n=this._smoothScrolling.combine(this._state,s,this._smoothScrollDuration),this._smoothScrolling.dispose(),this._smoothScrolling=n}else{let s=this._state.withScrollPosition(e);this._smoothScrolling=T2.start(this._state,s,this._smoothScrollDuration)}this._smoothScrolling.animationFrameDisposable=this._scheduleAtNextAnimationFrame(()=>{this._smoothScrolling&&(this._smoothScrolling.animationFrameDisposable=null,this._performSmoothScrolling())})}hasPendingScrollAnimation(){return!!this._smoothScrolling}_performSmoothScrolling(){if(!this._smoothScrolling)return;let e=this._smoothScrolling.tick(),t=this._state.withScrollPosition(e);if(this._setState(t,!0),!!this._smoothScrolling){if(e.isDone){this._smoothScrolling.dispose(),this._smoothScrolling=null;return}this._smoothScrolling.animationFrameDisposable=this._scheduleAtNextAnimationFrame(()=>{this._smoothScrolling&&(this._smoothScrolling.animationFrameDisposable=null,this._performSmoothScrolling())})}}_setState(e,t){let s=this._state;s.equals(e)||(this._state=e,this._onScroll.fire(this._state.createScrollEvent(s,t)))}},M2=class{constructor(e,t,s){this.scrollLeft=e,this.scrollTop=t,this.isDone=s}};function jg(e,t){let s=t-e;return function(n){return e+s*nI(n)}}function tI(e,t,s){return function(n){return n<s?e(n/s):t((n-s)/(1-s))}}var T2=class Yx{constructor(t,s,n,a){this.from=t,this.to=s,this.duration=a,this.startTime=n,this.animationFrameDisposable=null,this._initAnimations()}_initAnimations(){this.scrollLeft=this._initAnimation(this.from.scrollLeft,this.to.scrollLeft,this.to.width),this.scrollTop=this._initAnimation(this.from.scrollTop,this.to.scrollTop,this.to.height)}_initAnimation(t,s,n){if(Math.abs(t-s)>2.5*n){let a,l;return t<s?(a=t+.75*n,l=s-.75*n):(a=t-.75*n,l=s+.75*n),tI(jg(t,a),jg(l,s),.33)}return jg(t,s)}dispose(){this.animationFrameDisposable!==null&&(this.animationFrameDisposable.dispose(),this.animationFrameDisposable=null)}acceptScrollDimensions(t){this.to=t.withScrollPosition(this.to),this._initAnimations()}tick(){return this._tick(Date.now())}_tick(t){let s=(t-this.startTime)/this.duration;if(s<1){let n=this.scrollLeft(s),a=this.scrollTop(s);return new M2(n,a,!1)}return new M2(this.to.scrollLeft,this.to.scrollTop,!0)}combine(t,s,n){return Yx.start(t,s,n)}static start(t,s,n){n=n+10;let a=Date.now()-10;return new Yx(t,s,a,n)}};function sI(e){return Math.pow(e,3)}function nI(e){return 1-sI(1-e)}var rI=class extends nt{constructor(e,t,s){super(),this._visibility=e,this._visibleClassName=t,this._invisibleClassName=s,this._domNode=null,this._isVisible=!1,this._isNeeded=!1,this._rawShouldBeVisible=!1,this._shouldBeVisible=!1,this._revealTimer=this._register(new hv)}setVisibility(e){this._visibility!==e&&(this._visibility=e,this._updateShouldBeVisible())}setShouldBeVisible(e){this._rawShouldBeVisible=e,this._updateShouldBeVisible()}_applyVisibilitySetting(){return this._visibility===2?!1:this._visibility===3?!0:this._rawShouldBeVisible}_updateShouldBeVisible(){let e=this._applyVisibilitySetting();this._shouldBeVisible!==e&&(this._shouldBeVisible=e,this.ensureVisibility())}setIsNeeded(e){this._isNeeded!==e&&(this._isNeeded=e,this.ensureVisibility())}setDomNode(e){this._domNode=e,this._domNode.setClassName(this._invisibleClassName),this.setShouldBeVisible(!1)}ensureVisibility(){if(!this._isNeeded){this._hide(!1);return}this._shouldBeVisible?this._reveal():this._hide(!0)}_reveal(){this._isVisible||(this._isVisible=!0,this._revealTimer.setIfNotSet(()=>{var e;(e=this._domNode)==null||e.setClassName(this._visibleClassName)},0))}_hide(e){var t;this._revealTimer.cancel(),this._isVisible&&(this._isVisible=!1,(t=this._domNode)==null||t.setClassName(this._invisibleClassName+(e?" fade":"")))}},iI=140,lN=class extends pv{constructor(e){super(),this._lazyRender=e.lazyRender,this._host=e.host,this._scrollable=e.scrollable,this._scrollByPage=e.scrollByPage,this._scrollbarState=e.scrollbarState,this._visibilityController=this._register(new rI(e.visibility,"visible scrollbar "+e.extraScrollbarClassName,"invisible scrollbar "+e.extraScrollbarClassName)),this._visibilityController.setIsNeeded(this._scrollbarState.isNeeded()),this._pointerMoveMonitor=this._register(new oN),this._shouldRender=!0,this.domNode=Hc(document.createElement("div")),this.domNode.setAttribute("role","presentation"),this.domNode.setAttribute("aria-hidden","true"),this._visibilityController.setDomNode(this.domNode),this.domNode.setPosition("absolute"),this._register(Ge(this.domNode.domNode,Cs.POINTER_DOWN,t=>this._domNodePointerDown(t)))}_createArrow(e){let t=this._register(new Q$(e));this.domNode.domNode.appendChild(t.bgDomNode),this.domNode.domNode.appendChild(t.domNode)}_createSlider(e,t,s,n){this.slider=Hc(document.createElement("div")),this.slider.setClassName("slider"),this.slider.setPosition("absolute"),this.slider.setTop(e),this.slider.setLeft(t),typeof s=="number"&&this.slider.setWidth(s),typeof n=="number"&&this.slider.setHeight(n),this.slider.setLayerHinting(!0),this.slider.setContain("strict"),this.domNode.domNode.appendChild(this.slider.domNode),this._register(Ge(this.slider.domNode,Cs.POINTER_DOWN,a=>{a.button===0&&(a.preventDefault(),this._sliderPointerDown(a))})),this.onclick(this.slider.domNode,a=>{a.leftButton&&a.stopPropagation()})}_onElementSize(e){return this._scrollbarState.setVisibleSize(e)&&(this._visibilityController.setIsNeeded(this._scrollbarState.isNeeded()),this._shouldRender=!0,this._lazyRender||this.render()),this._shouldRender}_onElementScrollSize(e){return this._scrollbarState.setScrollSize(e)&&(this._visibilityController.setIsNeeded(this._scrollbarState.isNeeded()),this._shouldRender=!0,this._lazyRender||this.render()),this._shouldRender}_onElementScrollPosition(e){return this._scrollbarState.setScrollPosition(e)&&(this._visibilityController.setIsNeeded(this._scrollbarState.isNeeded()),this._shouldRender=!0,this._lazyRender||this.render()),this._shouldRender}beginReveal(){this._visibilityController.setShouldBeVisible(!0)}beginHide(){this._visibilityController.setShouldBeVisible(!1)}render(){this._shouldRender&&(this._shouldRender=!1,this._renderDomNode(this._scrollbarState.getRectangleLargeSize(),this._scrollbarState.getRectangleSmallSize()),this._updateSlider(this._scrollbarState.getSliderSize(),this._scrollbarState.getArrowSize()+this._scrollbarState.getSliderPosition()))}_domNodePointerDown(e){e.target===this.domNode.domNode&&this._onPointerDown(e)}delegatePointerDown(e){let t=this.domNode.domNode.getClientRects()[0].top,s=t+this._scrollbarState.getSliderPosition(),n=t+this._scrollbarState.getSliderPosition()+this._scrollbarState.getSliderSize(),a=this._sliderPointerPosition(e);s<=a&&a<=n?e.button===0&&(e.preventDefault(),this._sliderPointerDown(e)):this._onPointerDown(e)}_onPointerDown(e){let t,s;if(e.target===this.domNode.domNode&&typeof e.offsetX=="number"&&typeof e.offsetY=="number")t=e.offsetX,s=e.offsetY;else{let a=K$(this.domNode.domNode);t=e.pageX-a.left,s=e.pageY-a.top}let n=this._pointerDownRelativePosition(t,s);this._setDesiredScrollPositionNow(this._scrollByPage?this._scrollbarState.getDesiredScrollPositionFromOffsetPaged(n):this._scrollbarState.getDesiredScrollPositionFromOffset(n)),e.button===0&&(e.preventDefault(),this._sliderPointerDown(e))}_sliderPointerDown(e){if(!e.target||!(e.target instanceof Element))return;let t=this._sliderPointerPosition(e),s=this._sliderOrthogonalPointerPosition(e),n=this._scrollbarState.clone();this.slider.toggleClassName("active",!0),this._pointerMoveMonitor.startMonitoring(e.target,e.pointerId,e.buttons,a=>{let l=this._sliderOrthogonalPointerPosition(a),c=Math.abs(l-s);if(nN&&c>iI){this._setDesiredScrollPositionNow(n.getScrollPosition());return}let d=this._sliderPointerPosition(a)-t;this._setDesiredScrollPositionNow(n.getDesiredScrollPositionFromDelta(d))},()=>{this.slider.toggleClassName("active",!1),this._host.onDragEnd()}),this._host.onDragStart()}_setDesiredScrollPositionNow(e){let t={};this.writeScrollPosition(t,e),this._scrollable.setScrollPositionNow(t)}updateScrollbarSize(e){this._updateScrollbarSize(e),this._scrollbarState.setScrollbarSize(e),this._shouldRender=!0,this._lazyRender||this.render()}isNeeded(){return this._scrollbarState.isNeeded()}},cN=class Xx{constructor(t,s,n,a,l,c){this._scrollbarSize=Math.round(s),this._oppositeScrollbarSize=Math.round(n),this._arrowSize=Math.round(t),this._visibleSize=a,this._scrollSize=l,this._scrollPosition=c,this._computedAvailableSize=0,this._computedIsNeeded=!1,this._computedSliderSize=0,this._computedSliderRatio=0,this._computedSliderPosition=0,this._refreshComputedValues()}clone(){return new Xx(this._arrowSize,this._scrollbarSize,this._oppositeScrollbarSize,this._visibleSize,this._scrollSize,this._scrollPosition)}setVisibleSize(t){let s=Math.round(t);return this._visibleSize!==s?(this._visibleSize=s,this._refreshComputedValues(),!0):!1}setScrollSize(t){let s=Math.round(t);return this._scrollSize!==s?(this._scrollSize=s,this._refreshComputedValues(),!0):!1}setScrollPosition(t){let s=Math.round(t);return this._scrollPosition!==s?(this._scrollPosition=s,this._refreshComputedValues(),!0):!1}setScrollbarSize(t){this._scrollbarSize=Math.round(t)}setOppositeScrollbarSize(t){this._oppositeScrollbarSize=Math.round(t)}static _computeValues(t,s,n,a,l){let c=Math.max(0,n-t),d=Math.max(0,c-2*s),f=a>0&&a>n;if(!f)return{computedAvailableSize:Math.round(c),computedIsNeeded:f,computedSliderSize:Math.round(d),computedSliderRatio:0,computedSliderPosition:0};let h=Math.round(Math.max(20,Math.floor(n*d/a))),m=(d-h)/(a-n),g=l*m;return{computedAvailableSize:Math.round(c),computedIsNeeded:f,computedSliderSize:Math.round(h),computedSliderRatio:m,computedSliderPosition:Math.round(g)}}_refreshComputedValues(){let t=Xx._computeValues(this._oppositeScrollbarSize,this._arrowSize,this._visibleSize,this._scrollSize,this._scrollPosition);this._computedAvailableSize=t.computedAvailableSize,this._computedIsNeeded=t.computedIsNeeded,this._computedSliderSize=t.computedSliderSize,this._computedSliderRatio=t.computedSliderRatio,this._computedSliderPosition=t.computedSliderPosition}getArrowSize(){return this._arrowSize}getScrollPosition(){return this._scrollPosition}getRectangleLargeSize(){return this._computedAvailableSize}getRectangleSmallSize(){return this._scrollbarSize}isNeeded(){return this._computedIsNeeded}getSliderSize(){return this._computedSliderSize}getSliderPosition(){return this._computedSliderPosition}getDesiredScrollPositionFromOffset(t){if(!this._computedIsNeeded)return 0;let s=t-this._arrowSize-this._computedSliderSize/2;return Math.round(s/this._computedSliderRatio)}getDesiredScrollPositionFromOffsetPaged(t){if(!this._computedIsNeeded)return 0;let s=t-this._arrowSize,n=this._scrollPosition;return s<this._computedSliderPosition?n-=this._visibleSize:n+=this._visibleSize,n}getDesiredScrollPositionFromDelta(t){if(!this._computedIsNeeded)return 0;let s=this._computedSliderPosition+t;return Math.round(s/this._computedSliderRatio)}},aI=class extends lN{constructor(e,t,s){let n=e.getScrollDimensions(),a=e.getCurrentScrollPosition();if(super({lazyRender:t.lazyRender,host:s,scrollbarState:new cN(t.horizontalHasArrows?t.arrowSize:0,t.horizontal===2?0:t.horizontalScrollbarSize,t.vertical===2?0:t.verticalScrollbarSize,n.width,n.scrollWidth,a.scrollLeft),visibility:t.horizontal,extraScrollbarClassName:"horizontal",scrollable:e,scrollByPage:t.scrollByPage}),t.horizontalHasArrows)throw new Error("horizontalHasArrows is not supported in xterm.js");this._createSlider(Math.floor((t.horizontalScrollbarSize-t.horizontalSliderSize)/2),0,void 0,t.horizontalSliderSize)}_updateSlider(e,t){this.slider.setWidth(e),this.slider.setLeft(t)}_renderDomNode(e,t){this.domNode.setWidth(e),this.domNode.setHeight(t),this.domNode.setLeft(0),this.domNode.setBottom(0)}onDidScroll(e){return this._shouldRender=this._onElementScrollSize(e.scrollWidth)||this._shouldRender,this._shouldRender=this._onElementScrollPosition(e.scrollLeft)||this._shouldRender,this._shouldRender=this._onElementSize(e.width)||this._shouldRender,this._shouldRender}_pointerDownRelativePosition(e,t){return e}_sliderPointerPosition(e){return e.pageX}_sliderOrthogonalPointerPosition(e){return e.pageY}_updateScrollbarSize(e){this.slider.setHeight(e)}writeScrollPosition(e,t){e.scrollLeft=t}updateOptions(e){this.updateScrollbarSize(e.horizontal===2?0:e.horizontalScrollbarSize),this._scrollbarState.setOppositeScrollbarSize(e.vertical===2?0:e.verticalScrollbarSize),this._visibilityController.setVisibility(e.horizontal),this._scrollByPage=e.scrollByPage}},oI=class extends lN{constructor(e,t,s){let n=e.getScrollDimensions(),a=e.getCurrentScrollPosition();if(super({lazyRender:t.lazyRender,host:s,scrollbarState:new cN(t.verticalHasArrows?t.arrowSize:0,t.vertical===2?0:t.verticalScrollbarSize,0,n.height,n.scrollHeight,a.scrollTop),visibility:t.vertical,extraScrollbarClassName:"vertical",scrollable:e,scrollByPage:t.scrollByPage}),t.verticalHasArrows)throw new Error("horizontalHasArrows is not supported in xterm.js");this._createSlider(0,Math.floor((t.verticalScrollbarSize-t.verticalSliderSize)/2),t.verticalSliderSize,void 0)}_updateSlider(e,t){this.slider.setHeight(e),this.slider.setTop(t)}_renderDomNode(e,t){this.domNode.setWidth(t),this.domNode.setHeight(e),this.domNode.setRight(0),this.domNode.setTop(0)}onDidScroll(e){return this._shouldRender=this._onElementScrollSize(e.scrollHeight)||this._shouldRender,this._shouldRender=this._onElementScrollPosition(e.scrollTop)||this._shouldRender,this._shouldRender=this._onElementSize(e.height)||this._shouldRender,this._shouldRender}_pointerDownRelativePosition(e,t){return t}_sliderPointerPosition(e){return e.pageY}_sliderOrthogonalPointerPosition(e){return e.pageX}_updateScrollbarSize(e){this.slider.setWidth(e)}writeScrollPosition(e,t){e.scrollTop=t}updateOptions(e){this.updateScrollbarSize(e.vertical===2?0:e.verticalScrollbarSize),this._scrollbarState.setOppositeScrollbarSize(0),this._visibilityController.setVisibility(e.vertical),this._scrollByPage=e.scrollByPage}},lI=500,A2=50,cI=class{constructor(e,t,s){this.timestamp=e,this.deltaX=t,this.deltaY=s,this.score=0}},Jx=class{constructor(){this._capacity=5,this._memory=[],this._front=-1,this._rear=-1}isPhysicalMouseWheel(){if(this._front===-1&&this._rear===-1)return!1;let t=1,s=0,n=1,a=this._rear;do{let l=a===this._front?t:Math.pow(2,-n);if(t-=l,s+=this._memory[a].score*l,a===this._front)break;a=(this._capacity+a-1)%this._capacity,n++}while(!0);return s<=.5}acceptStandardWheelEvent(t){if(uv){let s=wr(t.browserEvent),n=_$(s);this.accept(Date.now(),t.deltaX*n,t.deltaY*n)}else this.accept(Date.now(),t.deltaX,t.deltaY)}accept(t,s,n){let a=null,l=new cI(t,s,n);this._front===-1&&this._rear===-1?(this._memory[0]=l,this._front=0,this._rear=0):(a=this._memory[this._rear],this._rear=(this._rear+1)%this._capacity,this._rear===this._front&&(this._front=(this._front+1)%this._capacity),this._memory[this._rear]=l),l.score=this._computeScore(l,a)}_computeScore(t,s){if(Math.abs(t.deltaX)>0&&Math.abs(t.deltaY)>0)return 1;let n=.5;if((!this._isAlmostInt(t.deltaX)||!this._isAlmostInt(t.deltaY))&&(n+=.25),s){let a=Math.abs(t.deltaX),l=Math.abs(t.deltaY),c=Math.abs(s.deltaX),d=Math.abs(s.deltaY),f=Math.max(Math.min(a,c),1),h=Math.max(Math.min(l,d),1),m=Math.max(a,c),g=Math.max(l,d);m%f===0&&g%h===0&&(n-=.5)}return Math.min(Math.max(n,0),1)}_isAlmostInt(t){return Math.abs(Math.round(t)-t)<.01}};Jx.INSTANCE=new Jx;var uI=Jx,dI=class extends pv{constructor(e,t,s){super(),this._onScroll=this._register(new Ce),this.onScroll=this._onScroll.event,this._onWillScroll=this._register(new Ce),this.onWillScroll=this._onWillScroll.event,this._options=fI(t),this._scrollable=s,this._register(this._scrollable.onScroll(a=>{this._onWillScroll.fire(a),this._onDidScroll(a),this._onScroll.fire(a)}));let n={onMouseWheel:a=>this._onMouseWheel(a),onDragStart:()=>this._onDragStart(),onDragEnd:()=>this._onDragEnd()};this._verticalScrollbar=this._register(new oI(this._scrollable,this._options,n)),this._horizontalScrollbar=this._register(new aI(this._scrollable,this._options,n)),this._domNode=document.createElement("div"),this._domNode.className="xterm-scrollable-element "+this._options.className,this._domNode.setAttribute("role","presentation"),this._domNode.style.position="relative",this._domNode.appendChild(e),this._domNode.appendChild(this._horizontalScrollbar.domNode.domNode),this._domNode.appendChild(this._verticalScrollbar.domNode.domNode),this._options.useShadows?(this._leftShadowDomNode=Hc(document.createElement("div")),this._leftShadowDomNode.setClassName("shadow"),this._domNode.appendChild(this._leftShadowDomNode.domNode),this._topShadowDomNode=Hc(document.createElement("div")),this._topShadowDomNode.setClassName("shadow"),this._domNode.appendChild(this._topShadowDomNode.domNode),this._topLeftShadowDomNode=Hc(document.createElement("div")),this._topLeftShadowDomNode.setClassName("shadow"),this._domNode.appendChild(this._topLeftShadowDomNode.domNode)):(this._leftShadowDomNode=null,this._topShadowDomNode=null,this._topLeftShadowDomNode=null),this._listenOnDomNode=this._options.listenOnDomNode||this._domNode,this._mouseWheelToDispose=[],this._setListeningToMouseWheel(this._options.handleMouseWheel),this.onmouseover(this._listenOnDomNode,a=>this._onMouseOver(a)),this.onmouseleave(this._listenOnDomNode,a=>this._onMouseLeave(a)),this._hideTimeout=this._register(new hv),this._isDragging=!1,this._mouseIsOver=!1,this._shouldRender=!0,this._revealOnScroll=!0}get options(){return this._options}dispose(){this._mouseWheelToDispose=Ra(this._mouseWheelToDispose),super.dispose()}getDomNode(){return this._domNode}getOverviewRulerLayoutInfo(){return{parent:this._domNode,insertBefore:this._verticalScrollbar.domNode.domNode}}delegateVerticalScrollbarPointerDown(e){this._verticalScrollbar.delegatePointerDown(e)}getScrollDimensions(){return this._scrollable.getScrollDimensions()}setScrollDimensions(e){this._scrollable.setScrollDimensions(e,!1)}updateClassName(e){this._options.className=e,Sr&&(this._options.className+=" mac"),this._domNode.className="xterm-scrollable-element "+this._options.className}updateOptions(e){typeof e.handleMouseWheel<"u"&&(this._options.handleMouseWheel=e.handleMouseWheel,this._setListeningToMouseWheel(this._options.handleMouseWheel)),typeof e.mouseWheelScrollSensitivity<"u"&&(this._options.mouseWheelScrollSensitivity=e.mouseWheelScrollSensitivity),typeof e.fastScrollSensitivity<"u"&&(this._options.fastScrollSensitivity=e.fastScrollSensitivity),typeof e.scrollPredominantAxis<"u"&&(this._options.scrollPredominantAxis=e.scrollPredominantAxis),typeof e.horizontal<"u"&&(this._options.horizontal=e.horizontal),typeof e.vertical<"u"&&(this._options.vertical=e.vertical),typeof e.horizontalScrollbarSize<"u"&&(this._options.horizontalScrollbarSize=e.horizontalScrollbarSize),typeof e.verticalScrollbarSize<"u"&&(this._options.verticalScrollbarSize=e.verticalScrollbarSize),typeof e.scrollByPage<"u"&&(this._options.scrollByPage=e.scrollByPage),this._horizontalScrollbar.updateOptions(this._options),this._verticalScrollbar.updateOptions(this._options),this._options.lazyRender||this._render()}setRevealOnScroll(e){this._revealOnScroll=e}delegateScrollFromMouseWheelEvent(e){this._onMouseWheel(new j2(e))}_setListeningToMouseWheel(e){if(this._mouseWheelToDispose.length>0!==e&&(this._mouseWheelToDispose=Ra(this._mouseWheelToDispose),e)){let t=s=>{this._onMouseWheel(new j2(s))};this._mouseWheelToDispose.push(Ge(this._listenOnDomNode,Cs.MOUSE_WHEEL,t,{passive:!1}))}}_onMouseWheel(e){var a;if((a=e.browserEvent)!=null&&a.defaultPrevented)return;let t=uI.INSTANCE;t.acceptStandardWheelEvent(e);let s=!1;if(e.deltaY||e.deltaX){let l=e.deltaY*this._options.mouseWheelScrollSensitivity,c=e.deltaX*this._options.mouseWheelScrollSensitivity;this._options.scrollPredominantAxis&&(this._options.scrollYToX&&c+l===0?c=l=0:Math.abs(l)>=Math.abs(c)?c=0:l=0),this._options.flipAxes&&([l,c]=[c,l]);let d=!Sr&&e.browserEvent&&e.browserEvent.shiftKey;(this._options.scrollYToX||d)&&!c&&(c=l,l=0),e.browserEvent&&e.browserEvent.altKey&&(c=c*this._options.fastScrollSensitivity,l=l*this._options.fastScrollSensitivity);let f=this._scrollable.getFutureScrollPosition(),h={};if(l){let m=A2*l,g=f.scrollTop-(m<0?Math.floor(m):Math.ceil(m));this._verticalScrollbar.writeScrollPosition(h,g)}if(c){let m=A2*c,g=f.scrollLeft-(m<0?Math.floor(m):Math.ceil(m));this._horizontalScrollbar.writeScrollPosition(h,g)}h=this._scrollable.validateScrollPosition(h),(f.scrollLeft!==h.scrollLeft||f.scrollTop!==h.scrollTop)&&(this._options.mouseWheelSmoothScroll&&t.isPhysicalMouseWheel()?this._scrollable.setScrollPositionSmooth(h):this._scrollable.setScrollPositionNow(h),s=!0)}let n=s;!n&&this._options.alwaysConsumeMouseWheel&&(n=!0),!n&&this._options.consumeMouseWheelIfScrollbarIsNeeded&&(this._verticalScrollbar.isNeeded()||this._horizontalScrollbar.isNeeded())&&(n=!0),n&&(e.preventDefault(),e.stopPropagation())}_onDidScroll(e){this._shouldRender=this._horizontalScrollbar.onDidScroll(e)||this._shouldRender,this._shouldRender=this._verticalScrollbar.onDidScroll(e)||this._shouldRender,this._options.useShadows&&(this._shouldRender=!0),this._revealOnScroll&&this._reveal(),this._options.lazyRender||this._render()}renderNow(){if(!this._options.lazyRender)throw new Error("Please use `lazyRender` together with `renderNow`!");this._render()}_render(){if(this._shouldRender&&(this._shouldRender=!1,this._horizontalScrollbar.render(),this._verticalScrollbar.render(),this._options.useShadows)){let e=this._scrollable.getCurrentScrollPosition(),t=e.scrollTop>0,s=e.scrollLeft>0,n=s?" left":"",a=t?" top":"",l=s||t?" top-left-corner":"";this._leftShadowDomNode.setClassName(`shadow${n}`),this._topShadowDomNode.setClassName(`shadow${a}`),this._topLeftShadowDomNode.setClassName(`shadow${l}${a}${n}`)}}_onDragStart(){this._isDragging=!0,this._reveal()}_onDragEnd(){this._isDragging=!1,this._hide()}_onMouseLeave(e){this._mouseIsOver=!1,this._hide()}_onMouseOver(e){this._mouseIsOver=!0,this._reveal()}_reveal(){this._verticalScrollbar.beginReveal(),this._horizontalScrollbar.beginReveal(),this._scheduleHide()}_hide(){!this._mouseIsOver&&!this._isDragging&&(this._verticalScrollbar.beginHide(),this._horizontalScrollbar.beginHide())}_scheduleHide(){!this._mouseIsOver&&!this._isDragging&&this._hideTimeout.cancelAndSet(()=>this._hide(),lI)}},hI=class extends dI{constructor(e,t,s){super(e,t,s)}setScrollPosition(e){e.reuseAnimation?this._scrollable.setScrollPositionSmooth(e,e.reuseAnimation):this._scrollable.setScrollPositionNow(e)}getScrollPosition(){return this._scrollable.getCurrentScrollPosition()}};function fI(e){let t={lazyRender:typeof e.lazyRender<"u"?e.lazyRender:!1,className:typeof e.className<"u"?e.className:"",useShadows:typeof e.useShadows<"u"?e.useShadows:!0,handleMouseWheel:typeof e.handleMouseWheel<"u"?e.handleMouseWheel:!0,flipAxes:typeof e.flipAxes<"u"?e.flipAxes:!1,consumeMouseWheelIfScrollbarIsNeeded:typeof e.consumeMouseWheelIfScrollbarIsNeeded<"u"?e.consumeMouseWheelIfScrollbarIsNeeded:!1,alwaysConsumeMouseWheel:typeof e.alwaysConsumeMouseWheel<"u"?e.alwaysConsumeMouseWheel:!1,scrollYToX:typeof e.scrollYToX<"u"?e.scrollYToX:!1,mouseWheelScrollSensitivity:typeof e.mouseWheelScrollSensitivity<"u"?e.mouseWheelScrollSensitivity:1,fastScrollSensitivity:typeof e.fastScrollSensitivity<"u"?e.fastScrollSensitivity:5,scrollPredominantAxis:typeof e.scrollPredominantAxis<"u"?e.scrollPredominantAxis:!0,mouseWheelSmoothScroll:typeof e.mouseWheelSmoothScroll<"u"?e.mouseWheelSmoothScroll:!0,arrowSize:typeof e.arrowSize<"u"?e.arrowSize:11,listenOnDomNode:typeof e.listenOnDomNode<"u"?e.listenOnDomNode:null,horizontal:typeof e.horizontal<"u"?e.horizontal:1,horizontalScrollbarSize:typeof e.horizontalScrollbarSize<"u"?e.horizontalScrollbarSize:10,horizontalSliderSize:typeof e.horizontalSliderSize<"u"?e.horizontalSliderSize:0,horizontalHasArrows:typeof e.horizontalHasArrows<"u"?e.horizontalHasArrows:!1,vertical:typeof e.vertical<"u"?e.vertical:1,verticalScrollbarSize:typeof e.verticalScrollbarSize<"u"?e.verticalScrollbarSize:10,verticalHasArrows:typeof e.verticalHasArrows<"u"?e.verticalHasArrows:!1,verticalSliderSize:typeof e.verticalSliderSize<"u"?e.verticalSliderSize:0,scrollByPage:typeof e.scrollByPage<"u"?e.scrollByPage:!1};return t.horizontalSliderSize=typeof e.horizontalSliderSize<"u"?e.horizontalSliderSize:t.horizontalScrollbarSize,t.verticalSliderSize=typeof e.verticalSliderSize<"u"?e.verticalSliderSize:t.verticalScrollbarSize,Sr&&(t.className+=" mac"),t}var Qx=class extends nt{constructor(e,t,s,n,a,l,c,d){super(),this._bufferService=s,this._optionsService=c,this._renderService=d,this._onRequestScrollLines=this._register(new Ce),this.onRequestScrollLines=this._onRequestScrollLines.event,this._isSyncing=!1,this._isHandlingScroll=!1,this._suppressOnScrollHandler=!1;let f=this._register(new eI({forceIntegerValues:!1,smoothScrollDuration:this._optionsService.rawOptions.smoothScrollDuration,scheduleAtNextAnimationFrame:h=>fv(n.window,h)}));this._register(this._optionsService.onSpecificOptionChange("smoothScrollDuration",()=>{f.setSmoothScrollDuration(this._optionsService.rawOptions.smoothScrollDuration)})),this._scrollableElement=this._register(new hI(t,{vertical:1,horizontal:2,useShadows:!1,mouseWheelSmoothScroll:!0,...this._getChangeOptions()},f)),this._register(this._optionsService.onMultipleOptionChange(["scrollSensitivity","fastScrollSensitivity","overviewRuler"],()=>this._scrollableElement.updateOptions(this._getChangeOptions()))),this._register(a.onProtocolChange(h=>{this._scrollableElement.updateOptions({handleMouseWheel:!(h&16)})})),this._scrollableElement.setScrollDimensions({height:0,scrollHeight:0}),this._register(Is.runAndSubscribe(l.onChangeColors,()=>{this._scrollableElement.getDomNode().style.backgroundColor=l.colors.background.css})),e.appendChild(this._scrollableElement.getDomNode()),this._register(Ut(()=>this._scrollableElement.getDomNode().remove())),this._styleElement=n.mainDocument.createElement("style"),t.appendChild(this._styleElement),this._register(Ut(()=>this._styleElement.remove())),this._register(Is.runAndSubscribe(l.onChangeColors,()=>{this._styleElement.textContent=[".xterm .xterm-scrollable-element > .scrollbar > .slider {",` background: ${l.colors.scrollbarSliderBackground.css};`,"}",".xterm .xterm-scrollable-element > .scrollbar > .slider:hover {",` background: ${l.colors.scrollbarSliderHoverBackground.css};`,"}",".xterm .xterm-scrollable-element > .scrollbar > .slider.active {",` background: ${l.colors.scrollbarSliderActiveBackground.css};`,"}"].join(`
|
|
253
|
+
`)})),this._register(this._bufferService.onResize(()=>this.queueSync())),this._register(this._bufferService.buffers.onBufferActivate(()=>{this._latestYDisp=void 0,this.queueSync()})),this._register(this._bufferService.onScroll(()=>this._sync())),this._register(this._scrollableElement.onScroll(h=>this._handleScroll(h)))}scrollLines(e){let t=this._scrollableElement.getScrollPosition();this._scrollableElement.setScrollPosition({reuseAnimation:!0,scrollTop:t.scrollTop+e*this._renderService.dimensions.css.cell.height})}scrollToLine(e,t){t&&(this._latestYDisp=e),this._scrollableElement.setScrollPosition({reuseAnimation:!t,scrollTop:e*this._renderService.dimensions.css.cell.height})}_getChangeOptions(){var e;return{mouseWheelScrollSensitivity:this._optionsService.rawOptions.scrollSensitivity,fastScrollSensitivity:this._optionsService.rawOptions.fastScrollSensitivity,verticalScrollbarSize:((e=this._optionsService.rawOptions.overviewRuler)==null?void 0:e.width)||14}}queueSync(e){e!==void 0&&(this._latestYDisp=e),this._queuedAnimationFrame===void 0&&(this._queuedAnimationFrame=this._renderService.addRefreshCallback(()=>{this._queuedAnimationFrame=void 0,this._sync(this._latestYDisp)}))}_sync(e=this._bufferService.buffer.ydisp){!this._renderService||this._isSyncing||(this._isSyncing=!0,this._suppressOnScrollHandler=!0,this._scrollableElement.setScrollDimensions({height:this._renderService.dimensions.css.canvas.height,scrollHeight:this._renderService.dimensions.css.cell.height*this._bufferService.buffer.lines.length}),this._suppressOnScrollHandler=!1,e!==this._latestYDisp&&this._scrollableElement.setScrollPosition({scrollTop:e*this._renderService.dimensions.css.cell.height}),this._isSyncing=!1)}_handleScroll(e){if(!this._renderService||this._isHandlingScroll||this._suppressOnScrollHandler)return;this._isHandlingScroll=!0;let t=Math.round(e.scrollTop/this._renderService.dimensions.css.cell.height),s=t-this._bufferService.buffer.ydisp;s!==0&&(this._latestYDisp=t,this._onRequestScrollLines.fire(s)),this._isHandlingScroll=!1}};Qx=ts([Re(2,sn),Re(3,ai),Re(4,UC),Re(5,tl),Re(6,nn),Re(7,oi)],Qx);var Zx=class extends nt{constructor(e,t,s,n,a){super(),this._screenElement=e,this._bufferService=t,this._coreBrowserService=s,this._decorationService=n,this._renderService=a,this._decorationElements=new Map,this._altBufferIsActive=!1,this._dimensionsChanged=!1,this._container=document.createElement("div"),this._container.classList.add("xterm-decoration-container"),this._screenElement.appendChild(this._container),this._register(this._renderService.onRenderedViewportChange(()=>this._doRefreshDecorations())),this._register(this._renderService.onDimensionsChange(()=>{this._dimensionsChanged=!0,this._queueRefresh()})),this._register(this._coreBrowserService.onDprChange(()=>this._queueRefresh())),this._register(this._bufferService.buffers.onBufferActivate(()=>{this._altBufferIsActive=this._bufferService.buffer===this._bufferService.buffers.alt})),this._register(this._decorationService.onDecorationRegistered(()=>this._queueRefresh())),this._register(this._decorationService.onDecorationRemoved(l=>this._removeDecoration(l))),this._register(Ut(()=>{this._container.remove(),this._decorationElements.clear()}))}_queueRefresh(){this._animationFrame===void 0&&(this._animationFrame=this._renderService.addRefreshCallback(()=>{this._doRefreshDecorations(),this._animationFrame=void 0}))}_doRefreshDecorations(){for(let e of this._decorationService.decorations)this._renderDecoration(e);this._dimensionsChanged=!1}_renderDecoration(e){this._refreshStyle(e),this._dimensionsChanged&&this._refreshXPosition(e)}_createElement(e){var n;let t=this._coreBrowserService.mainDocument.createElement("div");t.classList.add("xterm-decoration"),t.classList.toggle("xterm-decoration-top-layer",((n=e==null?void 0:e.options)==null?void 0:n.layer)==="top"),t.style.width=`${Math.round((e.options.width||1)*this._renderService.dimensions.css.cell.width)}px`,t.style.height=`${(e.options.height||1)*this._renderService.dimensions.css.cell.height}px`,t.style.top=`${(e.marker.line-this._bufferService.buffers.active.ydisp)*this._renderService.dimensions.css.cell.height}px`,t.style.lineHeight=`${this._renderService.dimensions.css.cell.height}px`;let s=e.options.x??0;return s&&s>this._bufferService.cols&&(t.style.display="none"),this._refreshXPosition(e,t),t}_refreshStyle(e){let t=e.marker.line-this._bufferService.buffers.active.ydisp;if(t<0||t>=this._bufferService.rows)e.element&&(e.element.style.display="none",e.onRenderEmitter.fire(e.element));else{let s=this._decorationElements.get(e);s||(s=this._createElement(e),e.element=s,this._decorationElements.set(e,s),this._container.appendChild(s),e.onDispose(()=>{this._decorationElements.delete(e),s.remove()})),s.style.display=this._altBufferIsActive?"none":"block",this._altBufferIsActive||(s.style.width=`${Math.round((e.options.width||1)*this._renderService.dimensions.css.cell.width)}px`,s.style.height=`${(e.options.height||1)*this._renderService.dimensions.css.cell.height}px`,s.style.top=`${t*this._renderService.dimensions.css.cell.height}px`,s.style.lineHeight=`${this._renderService.dimensions.css.cell.height}px`),e.onRenderEmitter.fire(s)}}_refreshXPosition(e,t=e.element){if(!t)return;let s=e.options.x??0;(e.options.anchor||"left")==="right"?t.style.right=s?`${s*this._renderService.dimensions.css.cell.width}px`:"":t.style.left=s?`${s*this._renderService.dimensions.css.cell.width}px`:""}_removeDecoration(e){var t;(t=this._decorationElements.get(e))==null||t.remove(),this._decorationElements.delete(e),e.dispose()}};Zx=ts([Re(1,sn),Re(2,ai),Re(3,mu),Re(4,oi)],Zx);var pI=class{constructor(){this._zones=[],this._zonePool=[],this._zonePoolIndex=0,this._linePadding={full:0,left:0,center:0,right:0}}get zones(){return this._zonePool.length=Math.min(this._zonePool.length,this._zones.length),this._zones}clear(){this._zones.length=0,this._zonePoolIndex=0}addDecoration(e){if(e.options.overviewRulerOptions){for(let t of this._zones)if(t.color===e.options.overviewRulerOptions.color&&t.position===e.options.overviewRulerOptions.position){if(this._lineIntersectsZone(t,e.marker.line))return;if(this._lineAdjacentToZone(t,e.marker.line,e.options.overviewRulerOptions.position)){this._addLineToZone(t,e.marker.line);return}}if(this._zonePoolIndex<this._zonePool.length){this._zonePool[this._zonePoolIndex].color=e.options.overviewRulerOptions.color,this._zonePool[this._zonePoolIndex].position=e.options.overviewRulerOptions.position,this._zonePool[this._zonePoolIndex].startBufferLine=e.marker.line,this._zonePool[this._zonePoolIndex].endBufferLine=e.marker.line,this._zones.push(this._zonePool[this._zonePoolIndex++]);return}this._zones.push({color:e.options.overviewRulerOptions.color,position:e.options.overviewRulerOptions.position,startBufferLine:e.marker.line,endBufferLine:e.marker.line}),this._zonePool.push(this._zones[this._zones.length-1]),this._zonePoolIndex++}}setPadding(e){this._linePadding=e}_lineIntersectsZone(e,t){return t>=e.startBufferLine&&t<=e.endBufferLine}_lineAdjacentToZone(e,t,s){return t>=e.startBufferLine-this._linePadding[s||"full"]&&t<=e.endBufferLine+this._linePadding[s||"full"]}_addLineToZone(e,t){e.startBufferLine=Math.min(e.startBufferLine,t),e.endBufferLine=Math.max(e.endBufferLine,t)}},pr={full:0,left:0,center:0,right:0},zi={full:0,left:0,center:0,right:0},dc={full:0,left:0,center:0,right:0},Ph=class extends nt{constructor(e,t,s,n,a,l,c,d){var h;super(),this._viewportElement=e,this._screenElement=t,this._bufferService=s,this._decorationService=n,this._renderService=a,this._optionsService=l,this._themeService=c,this._coreBrowserService=d,this._colorZoneStore=new pI,this._shouldUpdateDimensions=!0,this._shouldUpdateAnchor=!0,this._lastKnownBufferLength=0,this._canvas=this._coreBrowserService.mainDocument.createElement("canvas"),this._canvas.classList.add("xterm-decoration-overview-ruler"),this._refreshCanvasDimensions(),(h=this._viewportElement.parentElement)==null||h.insertBefore(this._canvas,this._viewportElement),this._register(Ut(()=>{var m;return(m=this._canvas)==null?void 0:m.remove()}));let f=this._canvas.getContext("2d");if(f)this._ctx=f;else throw new Error("Ctx cannot be null");this._register(this._decorationService.onDecorationRegistered(()=>this._queueRefresh(void 0,!0))),this._register(this._decorationService.onDecorationRemoved(()=>this._queueRefresh(void 0,!0))),this._register(this._renderService.onRenderedViewportChange(()=>this._queueRefresh())),this._register(this._bufferService.buffers.onBufferActivate(()=>{this._canvas.style.display=this._bufferService.buffer===this._bufferService.buffers.alt?"none":"block"})),this._register(this._bufferService.onScroll(()=>{this._lastKnownBufferLength!==this._bufferService.buffers.normal.lines.length&&(this._refreshDrawHeightConstants(),this._refreshColorZonePadding())})),this._register(this._renderService.onRender(()=>{(!this._containerHeight||this._containerHeight!==this._screenElement.clientHeight)&&(this._queueRefresh(!0),this._containerHeight=this._screenElement.clientHeight)})),this._register(this._coreBrowserService.onDprChange(()=>this._queueRefresh(!0))),this._register(this._optionsService.onSpecificOptionChange("overviewRuler",()=>this._queueRefresh(!0))),this._register(this._themeService.onChangeColors(()=>this._queueRefresh())),this._queueRefresh(!0)}get _width(){var e;return((e=this._optionsService.options.overviewRuler)==null?void 0:e.width)||0}_refreshDrawConstants(){let e=Math.floor((this._canvas.width-1)/3),t=Math.ceil((this._canvas.width-1)/3);zi.full=this._canvas.width,zi.left=e,zi.center=t,zi.right=e,this._refreshDrawHeightConstants(),dc.full=1,dc.left=1,dc.center=1+zi.left,dc.right=1+zi.left+zi.center}_refreshDrawHeightConstants(){pr.full=Math.round(2*this._coreBrowserService.dpr);let e=this._canvas.height/this._bufferService.buffer.lines.length,t=Math.round(Math.max(Math.min(e,12),6)*this._coreBrowserService.dpr);pr.left=t,pr.center=t,pr.right=t}_refreshColorZonePadding(){this._colorZoneStore.setPadding({full:Math.floor(this._bufferService.buffers.active.lines.length/(this._canvas.height-1)*pr.full),left:Math.floor(this._bufferService.buffers.active.lines.length/(this._canvas.height-1)*pr.left),center:Math.floor(this._bufferService.buffers.active.lines.length/(this._canvas.height-1)*pr.center),right:Math.floor(this._bufferService.buffers.active.lines.length/(this._canvas.height-1)*pr.right)}),this._lastKnownBufferLength=this._bufferService.buffers.normal.lines.length}_refreshCanvasDimensions(){this._canvas.style.width=`${this._width}px`,this._canvas.width=Math.round(this._width*this._coreBrowserService.dpr),this._canvas.style.height=`${this._screenElement.clientHeight}px`,this._canvas.height=Math.round(this._screenElement.clientHeight*this._coreBrowserService.dpr),this._refreshDrawConstants(),this._refreshColorZonePadding()}_refreshDecorations(){this._shouldUpdateDimensions&&this._refreshCanvasDimensions(),this._ctx.clearRect(0,0,this._canvas.width,this._canvas.height),this._colorZoneStore.clear();for(let t of this._decorationService.decorations)this._colorZoneStore.addDecoration(t);this._ctx.lineWidth=1,this._renderRulerOutline();let e=this._colorZoneStore.zones;for(let t of e)t.position!=="full"&&this._renderColorZone(t);for(let t of e)t.position==="full"&&this._renderColorZone(t);this._shouldUpdateDimensions=!1,this._shouldUpdateAnchor=!1}_renderRulerOutline(){this._ctx.fillStyle=this._themeService.colors.overviewRulerBorder.css,this._ctx.fillRect(0,0,1,this._canvas.height),this._optionsService.rawOptions.overviewRuler.showTopBorder&&this._ctx.fillRect(1,0,this._canvas.width-1,1),this._optionsService.rawOptions.overviewRuler.showBottomBorder&&this._ctx.fillRect(1,this._canvas.height-1,this._canvas.width-1,this._canvas.height)}_renderColorZone(e){this._ctx.fillStyle=e.color,this._ctx.fillRect(dc[e.position||"full"],Math.round((this._canvas.height-1)*(e.startBufferLine/this._bufferService.buffers.active.lines.length)-pr[e.position||"full"]/2),zi[e.position||"full"],Math.round((this._canvas.height-1)*((e.endBufferLine-e.startBufferLine)/this._bufferService.buffers.active.lines.length)+pr[e.position||"full"]))}_queueRefresh(e,t){this._shouldUpdateDimensions=e||this._shouldUpdateDimensions,this._shouldUpdateAnchor=t||this._shouldUpdateAnchor,this._animationFrame===void 0&&(this._animationFrame=this._coreBrowserService.window.requestAnimationFrame(()=>{this._refreshDecorations(),this._animationFrame=void 0}))}};Ph=ts([Re(2,sn),Re(3,mu),Re(4,oi),Re(5,nn),Re(6,tl),Re(7,ai)],Ph);var xe;(e=>(e.NUL="\0",e.SOH="",e.STX="",e.ETX="",e.EOT="",e.ENQ="",e.ACK="",e.BEL="\x07",e.BS="\b",e.HT=" ",e.LF=`
|
|
254
|
+
`,e.VT="\v",e.FF="\f",e.CR="\r",e.SO="",e.SI="",e.DLE="",e.DC1="",e.DC2="",e.DC3="",e.DC4="",e.NAK="",e.SYN="",e.ETB="",e.CAN="",e.EM="",e.SUB="",e.ESC="\x1B",e.FS="",e.GS="",e.RS="",e.US="",e.SP=" ",e.DEL=""))(xe||(xe={}));var dh;(e=>(e.PAD="",e.HOP="",e.BPH="",e.NBH="",e.IND="",e.NEL="
",e.SSA="",e.ESA="",e.HTS="",e.HTJ="",e.VTS="",e.PLD="",e.PLU="",e.RI="",e.SS2="",e.SS3="",e.DCS="",e.PU1="",e.PU2="",e.STS="",e.CCH="",e.MW="",e.SPA="",e.EPA="",e.SOS="",e.SGCI="",e.SCI="",e.CSI="",e.ST="",e.OSC="",e.PM="",e.APC=""))(dh||(dh={}));var uN;(e=>e.ST=`${xe.ESC}\\`)(uN||(uN={}));var e0=class{constructor(e,t,s,n,a,l){this._textarea=e,this._compositionView=t,this._bufferService=s,this._optionsService=n,this._coreService=a,this._renderService=l,this._isComposing=!1,this._isSendingComposition=!1,this._compositionPosition={start:0,end:0},this._dataAlreadySent=""}get isComposing(){return this._isComposing}compositionstart(){this._isComposing=!0,this._compositionPosition.start=this._textarea.value.length,this._compositionView.textContent="",this._dataAlreadySent="",this._compositionView.classList.add("active")}compositionupdate(e){this._compositionView.textContent=e.data,this.updateCompositionElements(),setTimeout(()=>{this._compositionPosition.end=this._textarea.value.length},0)}compositionend(){this._finalizeComposition(!0)}keydown(e){if(this._isComposing||this._isSendingComposition){if(e.keyCode===20||e.keyCode===229||e.keyCode===16||e.keyCode===17||e.keyCode===18)return!1;this._finalizeComposition(!1)}return e.keyCode===229?(this._handleAnyTextareaChanges(),!1):!0}_finalizeComposition(e){if(this._compositionView.classList.remove("active"),this._isComposing=!1,e){let t={start:this._compositionPosition.start,end:this._compositionPosition.end};this._isSendingComposition=!0,setTimeout(()=>{if(this._isSendingComposition){this._isSendingComposition=!1;let s;t.start+=this._dataAlreadySent.length,this._isComposing?s=this._textarea.value.substring(t.start,this._compositionPosition.start):s=this._textarea.value.substring(t.start),s.length>0&&this._coreService.triggerDataEvent(s,!0)}},0)}else{this._isSendingComposition=!1;let t=this._textarea.value.substring(this._compositionPosition.start,this._compositionPosition.end);this._coreService.triggerDataEvent(t,!0)}}_handleAnyTextareaChanges(){let e=this._textarea.value;setTimeout(()=>{if(!this._isComposing){let t=this._textarea.value,s=t.replace(e,"");this._dataAlreadySent=s,t.length>e.length?this._coreService.triggerDataEvent(s,!0):t.length<e.length?this._coreService.triggerDataEvent(`${xe.DEL}`,!0):t.length===e.length&&t!==e&&this._coreService.triggerDataEvent(t,!0)}},0)}updateCompositionElements(e){if(this._isComposing){if(this._bufferService.buffer.isCursorInViewport){let t=Math.min(this._bufferService.buffer.x,this._bufferService.cols-1),s=this._renderService.dimensions.css.cell.height,n=this._bufferService.buffer.y*this._renderService.dimensions.css.cell.height,a=t*this._renderService.dimensions.css.cell.width;this._compositionView.style.left=a+"px",this._compositionView.style.top=n+"px",this._compositionView.style.height=s+"px",this._compositionView.style.lineHeight=s+"px",this._compositionView.style.fontFamily=this._optionsService.rawOptions.fontFamily,this._compositionView.style.fontSize=this._optionsService.rawOptions.fontSize+"px";let l=this._compositionView.getBoundingClientRect();this._textarea.style.left=a+"px",this._textarea.style.top=n+"px",this._textarea.style.width=Math.max(l.width,1)+"px",this._textarea.style.height=Math.max(l.height,1)+"px",this._textarea.style.lineHeight=l.height+"px"}e||setTimeout(()=>this.updateCompositionElements(!0),0)}}};e0=ts([Re(2,sn),Re(3,nn),Re(4,Ba),Re(5,oi)],e0);var Ns=0,Es=0,Ms=0,es=0,R2={css:"#00000000",rgba:0},ps;(e=>{function t(a,l,c,d){return d!==void 0?`#${_a(a)}${_a(l)}${_a(c)}${_a(d)}`:`#${_a(a)}${_a(l)}${_a(c)}`}e.toCss=t;function s(a,l,c,d=255){return(a<<24|l<<16|c<<8|d)>>>0}e.toRgba=s;function n(a,l,c,d){return{css:e.toCss(a,l,c,d),rgba:e.toRgba(a,l,c,d)}}e.toColor=n})(ps||(ps={}));var $t;(e=>{function t(f,h){if(es=(h.rgba&255)/255,es===1)return{css:h.css,rgba:h.rgba};let m=h.rgba>>24&255,g=h.rgba>>16&255,b=h.rgba>>8&255,v=f.rgba>>24&255,y=f.rgba>>16&255,S=f.rgba>>8&255;Ns=v+Math.round((m-v)*es),Es=y+Math.round((g-y)*es),Ms=S+Math.round((b-S)*es);let j=ps.toCss(Ns,Es,Ms),k=ps.toRgba(Ns,Es,Ms);return{css:j,rgba:k}}e.blend=t;function s(f){return(f.rgba&255)===255}e.isOpaque=s;function n(f,h,m){let g=hh.ensureContrastRatio(f.rgba,h.rgba,m);if(g)return ps.toColor(g>>24&255,g>>16&255,g>>8&255)}e.ensureContrastRatio=n;function a(f){let h=(f.rgba|255)>>>0;return[Ns,Es,Ms]=hh.toChannels(h),{css:ps.toCss(Ns,Es,Ms),rgba:h}}e.opaque=a;function l(f,h){return es=Math.round(h*255),[Ns,Es,Ms]=hh.toChannels(f.rgba),{css:ps.toCss(Ns,Es,Ms,es),rgba:ps.toRgba(Ns,Es,Ms,es)}}e.opacity=l;function c(f,h){return es=f.rgba&255,l(f,es*h/255)}e.multiplyOpacity=c;function d(f){return[f.rgba>>24&255,f.rgba>>16&255,f.rgba>>8&255]}e.toColorRGB=d})($t||($t={}));var Wt;(e=>{let t,s;try{let a=document.createElement("canvas");a.width=1,a.height=1;let l=a.getContext("2d",{willReadFrequently:!0});l&&(t=l,t.globalCompositeOperation="copy",s=t.createLinearGradient(0,0,1,1))}catch{}function n(a){if(a.match(/#[\da-f]{3,8}/i))switch(a.length){case 4:return Ns=parseInt(a.slice(1,2).repeat(2),16),Es=parseInt(a.slice(2,3).repeat(2),16),Ms=parseInt(a.slice(3,4).repeat(2),16),ps.toColor(Ns,Es,Ms);case 5:return Ns=parseInt(a.slice(1,2).repeat(2),16),Es=parseInt(a.slice(2,3).repeat(2),16),Ms=parseInt(a.slice(3,4).repeat(2),16),es=parseInt(a.slice(4,5).repeat(2),16),ps.toColor(Ns,Es,Ms,es);case 7:return{css:a,rgba:(parseInt(a.slice(1),16)<<8|255)>>>0};case 9:return{css:a,rgba:parseInt(a.slice(1),16)>>>0}}let l=a.match(/rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(,\s*(0|1|\d?\.(\d+))\s*)?\)/);if(l)return Ns=parseInt(l[1]),Es=parseInt(l[2]),Ms=parseInt(l[3]),es=Math.round((l[5]===void 0?1:parseFloat(l[5]))*255),ps.toColor(Ns,Es,Ms,es);if(!t||!s)throw new Error("css.toColor: Unsupported css format");if(t.fillStyle=s,t.fillStyle=a,typeof t.fillStyle!="string")throw new Error("css.toColor: Unsupported css format");if(t.fillRect(0,0,1,1),[Ns,Es,Ms,es]=t.getImageData(0,0,1,1).data,es!==255)throw new Error("css.toColor: Unsupported css format");return{rgba:ps.toRgba(Ns,Es,Ms,es),css:a}}e.toColor=n})(Wt||(Wt={}));var Qs;(e=>{function t(n){return s(n>>16&255,n>>8&255,n&255)}e.relativeLuminance=t;function s(n,a,l){let c=n/255,d=a/255,f=l/255,h=c<=.03928?c/12.92:Math.pow((c+.055)/1.055,2.4),m=d<=.03928?d/12.92:Math.pow((d+.055)/1.055,2.4),g=f<=.03928?f/12.92:Math.pow((f+.055)/1.055,2.4);return h*.2126+m*.7152+g*.0722}e.relativeLuminance2=s})(Qs||(Qs={}));var hh;(e=>{function t(c,d){if(es=(d&255)/255,es===1)return d;let f=d>>24&255,h=d>>16&255,m=d>>8&255,g=c>>24&255,b=c>>16&255,v=c>>8&255;return Ns=g+Math.round((f-g)*es),Es=b+Math.round((h-b)*es),Ms=v+Math.round((m-v)*es),ps.toRgba(Ns,Es,Ms)}e.blend=t;function s(c,d,f){let h=Qs.relativeLuminance(c>>8),m=Qs.relativeLuminance(d>>8);if(Yr(h,m)<f){if(m<h){let v=n(c,d,f),y=Yr(h,Qs.relativeLuminance(v>>8));if(y<f){let S=a(c,d,f),j=Yr(h,Qs.relativeLuminance(S>>8));return y>j?v:S}return v}let g=a(c,d,f),b=Yr(h,Qs.relativeLuminance(g>>8));if(b<f){let v=n(c,d,f),y=Yr(h,Qs.relativeLuminance(v>>8));return b>y?g:v}return g}}e.ensureContrastRatio=s;function n(c,d,f){let h=c>>24&255,m=c>>16&255,g=c>>8&255,b=d>>24&255,v=d>>16&255,y=d>>8&255,S=Yr(Qs.relativeLuminance2(b,v,y),Qs.relativeLuminance2(h,m,g));for(;S<f&&(b>0||v>0||y>0);)b-=Math.max(0,Math.ceil(b*.1)),v-=Math.max(0,Math.ceil(v*.1)),y-=Math.max(0,Math.ceil(y*.1)),S=Yr(Qs.relativeLuminance2(b,v,y),Qs.relativeLuminance2(h,m,g));return(b<<24|v<<16|y<<8|255)>>>0}e.reduceLuminance=n;function a(c,d,f){let h=c>>24&255,m=c>>16&255,g=c>>8&255,b=d>>24&255,v=d>>16&255,y=d>>8&255,S=Yr(Qs.relativeLuminance2(b,v,y),Qs.relativeLuminance2(h,m,g));for(;S<f&&(b<255||v<255||y<255);)b=Math.min(255,b+Math.ceil((255-b)*.1)),v=Math.min(255,v+Math.ceil((255-v)*.1)),y=Math.min(255,y+Math.ceil((255-y)*.1)),S=Yr(Qs.relativeLuminance2(b,v,y),Qs.relativeLuminance2(h,m,g));return(b<<24|v<<16|y<<8|255)>>>0}e.increaseLuminance=a;function l(c){return[c>>24&255,c>>16&255,c>>8&255,c&255]}e.toChannels=l})(hh||(hh={}));function _a(e){let t=e.toString(16);return t.length<2?"0"+t:t}function Yr(e,t){return e<t?(t+.05)/(e+.05):(e+.05)/(t+.05)}var mI=class extends pu{constructor(e,t,s){super(),this.content=0,this.combinedData="",this.fg=e.fg,this.bg=e.bg,this.combinedData=t,this._width=s}isCombined(){return 2097152}getWidth(){return this._width}getChars(){return this.combinedData}getCode(){return 2097151}setFromCharData(e){throw new Error("not implemented")}getAsCharData(){return[this.fg,this.getChars(),this.getWidth(),this.getCode()]}},$h=class{constructor(e){this._bufferService=e,this._characterJoiners=[],this._nextCharacterJoinerId=0,this._workCell=new Jn}register(e){let t={id:this._nextCharacterJoinerId++,handler:e};return this._characterJoiners.push(t),t.id}deregister(e){for(let t=0;t<this._characterJoiners.length;t++)if(this._characterJoiners[t].id===e)return this._characterJoiners.splice(t,1),!0;return!1}getJoinedCharacters(e){if(this._characterJoiners.length===0)return[];let t=this._bufferService.buffer.lines.get(e);if(!t||t.length===0)return[];let s=[],n=t.translateToString(!0),a=0,l=0,c=0,d=t.getFg(0),f=t.getBg(0);for(let h=0;h<t.getTrimmedLength();h++)if(t.loadCell(h,this._workCell),this._workCell.getWidth()!==0){if(this._workCell.fg!==d||this._workCell.bg!==f){if(h-a>1){let m=this._getJoinedRanges(n,c,l,t,a);for(let g=0;g<m.length;g++)s.push(m[g])}a=h,c=l,d=this._workCell.fg,f=this._workCell.bg}l+=this._workCell.getChars().length||Vi.length}if(this._bufferService.cols-a>1){let h=this._getJoinedRanges(n,c,l,t,a);for(let m=0;m<h.length;m++)s.push(h[m])}return s}_getJoinedRanges(e,t,s,n,a){let l=e.substring(t,s),c=[];try{c=this._characterJoiners[0].handler(l)}catch(d){console.error(d)}for(let d=1;d<this._characterJoiners.length;d++)try{let f=this._characterJoiners[d].handler(l);for(let h=0;h<f.length;h++)$h._mergeRanges(c,f[h])}catch(f){console.error(f)}return this._stringRangesToCellRanges(c,n,a),c}_stringRangesToCellRanges(e,t,s){let n=0,a=!1,l=0,c=e[n];if(c){for(let d=s;d<this._bufferService.cols;d++){let f=t.getWidth(d),h=t.getString(d).length||Vi.length;if(f!==0){if(!a&&c[0]<=l&&(c[0]=d,a=!0),c[1]<=l){if(c[1]=d,c=e[++n],!c)break;c[0]<=l?(c[0]=d,a=!0):a=!1}l+=h}}c&&(c[1]=this._bufferService.cols)}}static _mergeRanges(e,t){let s=!1;for(let n=0;n<e.length;n++){let a=e[n];if(s){if(t[1]<=a[0])return e[n-1][1]=t[1],e;if(t[1]<=a[1])return e[n-1][1]=Math.max(t[1],a[1]),e.splice(n,1),e;e.splice(n,1),n--}else{if(t[1]<=a[0])return e.splice(n,0,t),e;if(t[1]<=a[1])return a[0]=Math.min(t[0],a[0]),e;t[0]<a[1]&&(a[0]=Math.min(t[0],a[0]),s=!0);continue}}return s?e[e.length-1][1]=t[1]:e.push(t),e}};$h=ts([Re(0,sn)],$h);function gI(e){return 57508<=e&&e<=57558}function xI(e){return 9472<=e&&e<=9631}function vI(e){return gI(e)||xI(e)}function bI(){return{css:{canvas:Xd(),cell:Xd()},device:{canvas:Xd(),cell:Xd(),char:{width:0,height:0,left:0,top:0}}}}function Xd(){return{width:0,height:0}}var t0=class{constructor(e,t,s,n,a,l,c){this._document=e,this._characterJoinerService=t,this._optionsService=s,this._coreBrowserService=n,this._coreService=a,this._decorationService=l,this._themeService=c,this._workCell=new Jn,this._columnSelectMode=!1,this.defaultSpacing=0}handleSelectionChanged(e,t,s){this._selectionStart=e,this._selectionEnd=t,this._columnSelectMode=s}createRow(e,t,s,n,a,l,c,d,f,h,m){let g=[],b=this._characterJoinerService.getJoinedCharacters(t),v=this._themeService.colors,y=e.getNoBgTrimmedLength();s&&y<l+1&&(y=l+1);let S,j=0,k="",E=0,N=0,B=0,A=0,P=!1,K=0,X=!1,Z=0,I=0,H=[],F=h!==-1&&m!==-1;for(let G=0;G<y;G++){e.loadCell(G,this._workCell);let q=this._workCell.getWidth();if(q===0)continue;let R=!1,M=G>=I,O=G,W=this._workCell;if(b.length>0&&G===b[0][0]&&M){let $e=b.shift(),we=this._isCellInSelection($e[0],t);for(E=$e[0]+1;E<$e[1];E++)M&&(M=we===this._isCellInSelection(E,t));M&&(M=!s||l<$e[0]||l>=$e[1]),M?(R=!0,W=new mI(this._workCell,e.translateToString(!0,$e[0],$e[1]),$e[1]-$e[0]),O=$e[1]-1,q=W.getWidth()):I=$e[1]}let U=this._isCellInSelection(G,t),D=s&&G===l,$=F&&G>=h&&G<=m,z=!1;this._decorationService.forEachDecorationAtCell(G,t,void 0,$e=>{z=!0});let T=W.getChars()||Vi;if(T===" "&&(W.isUnderline()||W.isOverline())&&(T=" "),Z=q*d-f.get(T,W.isBold(),W.isItalic()),!S)S=this._document.createElement("span");else if(j&&(U&&X||!U&&!X&&W.bg===N)&&(U&&X&&v.selectionForeground||W.fg===B)&&W.extended.ext===A&&$===P&&Z===K&&!D&&!R&&!z&&M){W.isInvisible()?k+=Vi:k+=T,j++;continue}else j&&(S.textContent=k),S=this._document.createElement("span"),j=0,k="";if(N=W.bg,B=W.fg,A=W.extended.ext,P=$,K=Z,X=U,R&&l>=G&&l<=O&&(l=G),!this._coreService.isCursorHidden&&D&&this._coreService.isCursorInitialized){if(H.push("xterm-cursor"),this._coreBrowserService.isFocused)c&&H.push("xterm-cursor-blink"),H.push(n==="bar"?"xterm-cursor-bar":n==="underline"?"xterm-cursor-underline":"xterm-cursor-block");else if(a)switch(a){case"outline":H.push("xterm-cursor-outline");break;case"block":H.push("xterm-cursor-block");break;case"bar":H.push("xterm-cursor-bar");break;case"underline":H.push("xterm-cursor-underline");break}}if(W.isBold()&&H.push("xterm-bold"),W.isItalic()&&H.push("xterm-italic"),W.isDim()&&H.push("xterm-dim"),W.isInvisible()?k=Vi:k=W.getChars()||Vi,W.isUnderline()&&(H.push(`xterm-underline-${W.extended.underlineStyle}`),k===" "&&(k=" "),!W.isUnderlineColorDefault()))if(W.isUnderlineColorRGB())S.style.textDecorationColor=`rgb(${pu.toColorRGB(W.getUnderlineColor()).join(",")})`;else{let $e=W.getUnderlineColor();this._optionsService.rawOptions.drawBoldTextInBrightColors&&W.isBold()&&$e<8&&($e+=8),S.style.textDecorationColor=v.ansi[$e].css}W.isOverline()&&(H.push("xterm-overline"),k===" "&&(k=" ")),W.isStrikethrough()&&H.push("xterm-strikethrough"),$&&(S.style.textDecoration="underline");let ae=W.getFgColor(),be=W.getFgColorMode(),ne=W.getBgColor(),ve=W.getBgColorMode(),Ae=!!W.isInverse();if(Ae){let $e=ae;ae=ne,ne=$e;let we=be;be=ve,ve=we}let De,ke,Xe=!1;this._decorationService.forEachDecorationAtCell(G,t,void 0,$e=>{$e.options.layer!=="top"&&Xe||($e.backgroundColorRGB&&(ve=50331648,ne=$e.backgroundColorRGB.rgba>>8&16777215,De=$e.backgroundColorRGB),$e.foregroundColorRGB&&(be=50331648,ae=$e.foregroundColorRGB.rgba>>8&16777215,ke=$e.foregroundColorRGB),Xe=$e.options.layer==="top")}),!Xe&&U&&(De=this._coreBrowserService.isFocused?v.selectionBackgroundOpaque:v.selectionInactiveBackgroundOpaque,ne=De.rgba>>8&16777215,ve=50331648,Xe=!0,v.selectionForeground&&(be=50331648,ae=v.selectionForeground.rgba>>8&16777215,ke=v.selectionForeground)),Xe&&H.push("xterm-decoration-top");let Je;switch(ve){case 16777216:case 33554432:Je=v.ansi[ne],H.push(`xterm-bg-${ne}`);break;case 50331648:Je=ps.toColor(ne>>16,ne>>8&255,ne&255),this._addStyle(S,`background-color:#${D2((ne>>>0).toString(16),"0",6)}`);break;case 0:default:Ae?(Je=v.foreground,H.push("xterm-bg-257")):Je=v.background}switch(De||W.isDim()&&(De=$t.multiplyOpacity(Je,.5)),be){case 16777216:case 33554432:W.isBold()&&ae<8&&this._optionsService.rawOptions.drawBoldTextInBrightColors&&(ae+=8),this._applyMinimumContrast(S,Je,v.ansi[ae],W,De,void 0)||H.push(`xterm-fg-${ae}`);break;case 50331648:let $e=ps.toColor(ae>>16&255,ae>>8&255,ae&255);this._applyMinimumContrast(S,Je,$e,W,De,ke)||this._addStyle(S,`color:#${D2(ae.toString(16),"0",6)}`);break;case 0:default:this._applyMinimumContrast(S,Je,v.foreground,W,De,ke)||Ae&&H.push("xterm-fg-257")}H.length&&(S.className=H.join(" "),H.length=0),!D&&!R&&!z&&M?j++:S.textContent=k,Z!==this.defaultSpacing&&(S.style.letterSpacing=`${Z}px`),g.push(S),G=O}return S&&j&&(S.textContent=k),g}_applyMinimumContrast(e,t,s,n,a,l){if(this._optionsService.rawOptions.minimumContrastRatio===1||vI(n.getCode()))return!1;let c=this._getContrastCache(n),d;if(!a&&!l&&(d=c.getColor(t.rgba,s.rgba)),d===void 0){let f=this._optionsService.rawOptions.minimumContrastRatio/(n.isDim()?2:1);d=$t.ensureContrastRatio(a||t,l||s,f),c.setColor((a||t).rgba,(l||s).rgba,d??null)}return d?(this._addStyle(e,`color:${d.css}`),!0):!1}_getContrastCache(e){return e.isDim()?this._themeService.colors.halfContrastCache:this._themeService.colors.contrastCache}_addStyle(e,t){e.setAttribute("style",`${e.getAttribute("style")||""}${t};`)}_isCellInSelection(e,t){let s=this._selectionStart,n=this._selectionEnd;return!s||!n?!1:this._columnSelectMode?s[0]<=n[0]?e>=s[0]&&t>=s[1]&&e<n[0]&&t<=n[1]:e<s[0]&&t>=s[1]&&e>=n[0]&&t<=n[1]:t>s[1]&&t<n[1]||s[1]===n[1]&&t===s[1]&&e>=s[0]&&e<n[0]||s[1]<n[1]&&t===n[1]&&e<n[0]||s[1]<n[1]&&t===s[1]&&e>=s[0]}};t0=ts([Re(1,qC),Re(2,nn),Re(3,ai),Re(4,Ba),Re(5,mu),Re(6,tl)],t0);function D2(e,t,s){for(;e.length<s;)e=t+e;return e}var _I=class{constructor(e,t){this._flat=new Float32Array(256),this._font="",this._fontSize=0,this._weight="normal",this._weightBold="bold",this._measureElements=[],this._container=e.createElement("div"),this._container.classList.add("xterm-width-cache-measure-container"),this._container.setAttribute("aria-hidden","true"),this._container.style.whiteSpace="pre",this._container.style.fontKerning="none";let s=e.createElement("span");s.classList.add("xterm-char-measure-element");let n=e.createElement("span");n.classList.add("xterm-char-measure-element"),n.style.fontWeight="bold";let a=e.createElement("span");a.classList.add("xterm-char-measure-element"),a.style.fontStyle="italic";let l=e.createElement("span");l.classList.add("xterm-char-measure-element"),l.style.fontWeight="bold",l.style.fontStyle="italic",this._measureElements=[s,n,a,l],this._container.appendChild(s),this._container.appendChild(n),this._container.appendChild(a),this._container.appendChild(l),t.appendChild(this._container),this.clear()}dispose(){this._container.remove(),this._measureElements.length=0,this._holey=void 0}clear(){this._flat.fill(-9999),this._holey=new Map}setFont(e,t,s,n){e===this._font&&t===this._fontSize&&s===this._weight&&n===this._weightBold||(this._font=e,this._fontSize=t,this._weight=s,this._weightBold=n,this._container.style.fontFamily=this._font,this._container.style.fontSize=`${this._fontSize}px`,this._measureElements[0].style.fontWeight=`${s}`,this._measureElements[1].style.fontWeight=`${n}`,this._measureElements[2].style.fontWeight=`${s}`,this._measureElements[3].style.fontWeight=`${n}`,this.clear())}get(e,t,s){let n=0;if(!t&&!s&&e.length===1&&(n=e.charCodeAt(0))<256){if(this._flat[n]!==-9999)return this._flat[n];let c=this._measure(e,0);return c>0&&(this._flat[n]=c),c}let a=e;t&&(a+="B"),s&&(a+="I");let l=this._holey.get(a);if(l===void 0){let c=0;t&&(c|=1),s&&(c|=2),l=this._measure(e,c),l>0&&this._holey.set(a,l)}return l}_measure(e,t){let s=this._measureElements[t];return s.textContent=e.repeat(32),s.offsetWidth/32}},yI=class{constructor(){this.clear()}clear(){this.hasSelection=!1,this.columnSelectMode=!1,this.viewportStartRow=0,this.viewportEndRow=0,this.viewportCappedStartRow=0,this.viewportCappedEndRow=0,this.startCol=0,this.endCol=0,this.selectionStart=void 0,this.selectionEnd=void 0}update(e,t,s,n=!1){if(this.selectionStart=t,this.selectionEnd=s,!t||!s||t[0]===s[0]&&t[1]===s[1]){this.clear();return}let a=e.buffers.active.ydisp,l=t[1]-a,c=s[1]-a,d=Math.max(l,0),f=Math.min(c,e.rows-1);if(d>=e.rows||f<0){this.clear();return}this.hasSelection=!0,this.columnSelectMode=n,this.viewportStartRow=l,this.viewportEndRow=c,this.viewportCappedStartRow=d,this.viewportCappedEndRow=f,this.startCol=t[0],this.endCol=s[0]}isCellSelected(e,t,s){return this.hasSelection?(s-=e.buffer.active.viewportY,this.columnSelectMode?this.startCol<=this.endCol?t>=this.startCol&&s>=this.viewportCappedStartRow&&t<this.endCol&&s<=this.viewportCappedEndRow:t<this.startCol&&s>=this.viewportCappedStartRow&&t>=this.endCol&&s<=this.viewportCappedEndRow:s>this.viewportStartRow&&s<this.viewportEndRow||this.viewportStartRow===this.viewportEndRow&&s===this.viewportStartRow&&t>=this.startCol&&t<this.endCol||this.viewportStartRow<this.viewportEndRow&&s===this.viewportEndRow&&t<this.endCol||this.viewportStartRow<this.viewportEndRow&&s===this.viewportStartRow&&t>=this.startCol):!1}};function wI(){return new yI}var kg="xterm-dom-renderer-owner-",Wn="xterm-rows",Jd="xterm-fg-",L2="xterm-bg-",hc="xterm-focus",Qd="xterm-selection",SI=1,s0=class extends nt{constructor(e,t,s,n,a,l,c,d,f,h,m,g,b,v){super(),this._terminal=e,this._document=t,this._element=s,this._screenElement=n,this._viewportElement=a,this._helperContainer=l,this._linkifier2=c,this._charSizeService=f,this._optionsService=h,this._bufferService=m,this._coreService=g,this._coreBrowserService=b,this._themeService=v,this._terminalClass=SI++,this._rowElements=[],this._selectionRenderModel=wI(),this.onRequestRedraw=this._register(new Ce).event,this._rowContainer=this._document.createElement("div"),this._rowContainer.classList.add(Wn),this._rowContainer.style.lineHeight="normal",this._rowContainer.setAttribute("aria-hidden","true"),this._refreshRowElements(this._bufferService.cols,this._bufferService.rows),this._selectionContainer=this._document.createElement("div"),this._selectionContainer.classList.add(Qd),this._selectionContainer.setAttribute("aria-hidden","true"),this.dimensions=bI(),this._updateDimensions(),this._register(this._optionsService.onOptionChange(()=>this._handleOptionsChanged())),this._register(this._themeService.onChangeColors(y=>this._injectCss(y))),this._injectCss(this._themeService.colors),this._rowFactory=d.createInstance(t0,document),this._element.classList.add(kg+this._terminalClass),this._screenElement.appendChild(this._rowContainer),this._screenElement.appendChild(this._selectionContainer),this._register(this._linkifier2.onShowLinkUnderline(y=>this._handleLinkHover(y))),this._register(this._linkifier2.onHideLinkUnderline(y=>this._handleLinkLeave(y))),this._register(Ut(()=>{this._element.classList.remove(kg+this._terminalClass),this._rowContainer.remove(),this._selectionContainer.remove(),this._widthCache.dispose(),this._themeStyleElement.remove(),this._dimensionsStyleElement.remove()})),this._widthCache=new _I(this._document,this._helperContainer),this._widthCache.setFont(this._optionsService.rawOptions.fontFamily,this._optionsService.rawOptions.fontSize,this._optionsService.rawOptions.fontWeight,this._optionsService.rawOptions.fontWeightBold),this._setDefaultSpacing()}_updateDimensions(){let e=this._coreBrowserService.dpr;this.dimensions.device.char.width=this._charSizeService.width*e,this.dimensions.device.char.height=Math.ceil(this._charSizeService.height*e),this.dimensions.device.cell.width=this.dimensions.device.char.width+Math.round(this._optionsService.rawOptions.letterSpacing),this.dimensions.device.cell.height=Math.floor(this.dimensions.device.char.height*this._optionsService.rawOptions.lineHeight),this.dimensions.device.char.left=0,this.dimensions.device.char.top=0,this.dimensions.device.canvas.width=this.dimensions.device.cell.width*this._bufferService.cols,this.dimensions.device.canvas.height=this.dimensions.device.cell.height*this._bufferService.rows,this.dimensions.css.canvas.width=Math.round(this.dimensions.device.canvas.width/e),this.dimensions.css.canvas.height=Math.round(this.dimensions.device.canvas.height/e),this.dimensions.css.cell.width=this.dimensions.css.canvas.width/this._bufferService.cols,this.dimensions.css.cell.height=this.dimensions.css.canvas.height/this._bufferService.rows;for(let s of this._rowElements)s.style.width=`${this.dimensions.css.canvas.width}px`,s.style.height=`${this.dimensions.css.cell.height}px`,s.style.lineHeight=`${this.dimensions.css.cell.height}px`,s.style.overflow="hidden";this._dimensionsStyleElement||(this._dimensionsStyleElement=this._document.createElement("style"),this._screenElement.appendChild(this._dimensionsStyleElement));let t=`${this._terminalSelector} .${Wn} span { display: inline-block; height: 100%; vertical-align: top;}`;this._dimensionsStyleElement.textContent=t,this._selectionContainer.style.height=this._viewportElement.style.height,this._screenElement.style.width=`${this.dimensions.css.canvas.width}px`,this._screenElement.style.height=`${this.dimensions.css.canvas.height}px`}_injectCss(e){this._themeStyleElement||(this._themeStyleElement=this._document.createElement("style"),this._screenElement.appendChild(this._themeStyleElement));let t=`${this._terminalSelector} .${Wn} { pointer-events: none; color: ${e.foreground.css}; font-family: ${this._optionsService.rawOptions.fontFamily}; font-size: ${this._optionsService.rawOptions.fontSize}px; font-kerning: none; white-space: pre}`;t+=`${this._terminalSelector} .${Wn} .xterm-dim { color: ${$t.multiplyOpacity(e.foreground,.5).css};}`,t+=`${this._terminalSelector} span:not(.xterm-bold) { font-weight: ${this._optionsService.rawOptions.fontWeight};}${this._terminalSelector} span.xterm-bold { font-weight: ${this._optionsService.rawOptions.fontWeightBold};}${this._terminalSelector} span.xterm-italic { font-style: italic;}`;let s=`blink_underline_${this._terminalClass}`,n=`blink_bar_${this._terminalClass}`,a=`blink_block_${this._terminalClass}`;t+=`@keyframes ${s} { 50% { border-bottom-style: hidden; }}`,t+=`@keyframes ${n} { 50% { box-shadow: none; }}`,t+=`@keyframes ${a} { 0% { background-color: ${e.cursor.css}; color: ${e.cursorAccent.css}; } 50% { background-color: inherit; color: ${e.cursor.css}; }}`,t+=`${this._terminalSelector} .${Wn}.${hc} .xterm-cursor.xterm-cursor-blink.xterm-cursor-underline { animation: ${s} 1s step-end infinite;}${this._terminalSelector} .${Wn}.${hc} .xterm-cursor.xterm-cursor-blink.xterm-cursor-bar { animation: ${n} 1s step-end infinite;}${this._terminalSelector} .${Wn}.${hc} .xterm-cursor.xterm-cursor-blink.xterm-cursor-block { animation: ${a} 1s step-end infinite;}${this._terminalSelector} .${Wn} .xterm-cursor.xterm-cursor-block { background-color: ${e.cursor.css}; color: ${e.cursorAccent.css};}${this._terminalSelector} .${Wn} .xterm-cursor.xterm-cursor-block:not(.xterm-cursor-blink) { background-color: ${e.cursor.css} !important; color: ${e.cursorAccent.css} !important;}${this._terminalSelector} .${Wn} .xterm-cursor.xterm-cursor-outline { outline: 1px solid ${e.cursor.css}; outline-offset: -1px;}${this._terminalSelector} .${Wn} .xterm-cursor.xterm-cursor-bar { box-shadow: ${this._optionsService.rawOptions.cursorWidth}px 0 0 ${e.cursor.css} inset;}${this._terminalSelector} .${Wn} .xterm-cursor.xterm-cursor-underline { border-bottom: 1px ${e.cursor.css}; border-bottom-style: solid; height: calc(100% - 1px);}`,t+=`${this._terminalSelector} .${Qd} { position: absolute; top: 0; left: 0; z-index: 1; pointer-events: none;}${this._terminalSelector}.focus .${Qd} div { position: absolute; background-color: ${e.selectionBackgroundOpaque.css};}${this._terminalSelector} .${Qd} div { position: absolute; background-color: ${e.selectionInactiveBackgroundOpaque.css};}`;for(let[l,c]of e.ansi.entries())t+=`${this._terminalSelector} .${Jd}${l} { color: ${c.css}; }${this._terminalSelector} .${Jd}${l}.xterm-dim { color: ${$t.multiplyOpacity(c,.5).css}; }${this._terminalSelector} .${L2}${l} { background-color: ${c.css}; }`;t+=`${this._terminalSelector} .${Jd}257 { color: ${$t.opaque(e.background).css}; }${this._terminalSelector} .${Jd}257.xterm-dim { color: ${$t.multiplyOpacity($t.opaque(e.background),.5).css}; }${this._terminalSelector} .${L2}257 { background-color: ${e.foreground.css}; }`,this._themeStyleElement.textContent=t}_setDefaultSpacing(){let e=this.dimensions.css.cell.width-this._widthCache.get("W",!1,!1);this._rowContainer.style.letterSpacing=`${e}px`,this._rowFactory.defaultSpacing=e}handleDevicePixelRatioChange(){this._updateDimensions(),this._widthCache.clear(),this._setDefaultSpacing()}_refreshRowElements(e,t){for(let s=this._rowElements.length;s<=t;s++){let n=this._document.createElement("div");this._rowContainer.appendChild(n),this._rowElements.push(n)}for(;this._rowElements.length>t;)this._rowContainer.removeChild(this._rowElements.pop())}handleResize(e,t){this._refreshRowElements(e,t),this._updateDimensions(),this.handleSelectionChanged(this._selectionRenderModel.selectionStart,this._selectionRenderModel.selectionEnd,this._selectionRenderModel.columnSelectMode)}handleCharSizeChanged(){this._updateDimensions(),this._widthCache.clear(),this._setDefaultSpacing()}handleBlur(){this._rowContainer.classList.remove(hc),this.renderRows(0,this._bufferService.rows-1)}handleFocus(){this._rowContainer.classList.add(hc),this.renderRows(this._bufferService.buffer.y,this._bufferService.buffer.y)}handleSelectionChanged(e,t,s){if(this._selectionContainer.replaceChildren(),this._rowFactory.handleSelectionChanged(e,t,s),this.renderRows(0,this._bufferService.rows-1),!e||!t||(this._selectionRenderModel.update(this._terminal,e,t,s),!this._selectionRenderModel.hasSelection))return;let n=this._selectionRenderModel.viewportStartRow,a=this._selectionRenderModel.viewportEndRow,l=this._selectionRenderModel.viewportCappedStartRow,c=this._selectionRenderModel.viewportCappedEndRow,d=this._document.createDocumentFragment();if(s){let f=e[0]>t[0];d.appendChild(this._createSelectionElement(l,f?t[0]:e[0],f?e[0]:t[0],c-l+1))}else{let f=n===l?e[0]:0,h=l===a?t[0]:this._bufferService.cols;d.appendChild(this._createSelectionElement(l,f,h));let m=c-l-1;if(d.appendChild(this._createSelectionElement(l+1,0,this._bufferService.cols,m)),l!==c){let g=a===c?t[0]:this._bufferService.cols;d.appendChild(this._createSelectionElement(c,0,g))}}this._selectionContainer.appendChild(d)}_createSelectionElement(e,t,s,n=1){let a=this._document.createElement("div"),l=t*this.dimensions.css.cell.width,c=this.dimensions.css.cell.width*(s-t);return l+c>this.dimensions.css.canvas.width&&(c=this.dimensions.css.canvas.width-l),a.style.height=`${n*this.dimensions.css.cell.height}px`,a.style.top=`${e*this.dimensions.css.cell.height}px`,a.style.left=`${l}px`,a.style.width=`${c}px`,a}handleCursorMove(){}_handleOptionsChanged(){this._updateDimensions(),this._injectCss(this._themeService.colors),this._widthCache.setFont(this._optionsService.rawOptions.fontFamily,this._optionsService.rawOptions.fontSize,this._optionsService.rawOptions.fontWeight,this._optionsService.rawOptions.fontWeightBold),this._setDefaultSpacing()}clear(){for(let e of this._rowElements)e.replaceChildren()}renderRows(e,t){let s=this._bufferService.buffer,n=s.ybase+s.y,a=Math.min(s.x,this._bufferService.cols-1),l=this._coreService.decPrivateModes.cursorBlink??this._optionsService.rawOptions.cursorBlink,c=this._coreService.decPrivateModes.cursorStyle??this._optionsService.rawOptions.cursorStyle,d=this._optionsService.rawOptions.cursorInactiveStyle;for(let f=e;f<=t;f++){let h=f+s.ydisp,m=this._rowElements[f],g=s.lines.get(h);if(!m||!g)break;m.replaceChildren(...this._rowFactory.createRow(g,h,h===n,c,d,a,l,this.dimensions.css.cell.width,this._widthCache,-1,-1))}}get _terminalSelector(){return`.${kg}${this._terminalClass}`}_handleLinkHover(e){this._setCellUnderline(e.x1,e.x2,e.y1,e.y2,e.cols,!0)}_handleLinkLeave(e){this._setCellUnderline(e.x1,e.x2,e.y1,e.y2,e.cols,!1)}_setCellUnderline(e,t,s,n,a,l){s<0&&(e=0),n<0&&(t=0);let c=this._bufferService.rows-1;s=Math.max(Math.min(s,c),0),n=Math.max(Math.min(n,c),0),a=Math.min(a,this._bufferService.cols);let d=this._bufferService.buffer,f=d.ybase+d.y,h=Math.min(d.x,a-1),m=this._optionsService.rawOptions.cursorBlink,g=this._optionsService.rawOptions.cursorStyle,b=this._optionsService.rawOptions.cursorInactiveStyle;for(let v=s;v<=n;++v){let y=v+d.ydisp,S=this._rowElements[v],j=d.lines.get(y);if(!S||!j)break;S.replaceChildren(...this._rowFactory.createRow(j,y,y===f,g,b,h,m,this.dimensions.css.cell.width,this._widthCache,l?v===s?e:0:-1,l?(v===n?t:a)-1:-1))}}};s0=ts([Re(7,ov),Re(8,sf),Re(9,nn),Re(10,sn),Re(11,Ba),Re(12,ai),Re(13,tl)],s0);var n0=class extends nt{constructor(e,t,s){super(),this._optionsService=s,this.width=0,this.height=0,this._onCharSizeChange=this._register(new Ce),this.onCharSizeChange=this._onCharSizeChange.event;try{this._measureStrategy=this._register(new kI(this._optionsService))}catch{this._measureStrategy=this._register(new jI(e,t,this._optionsService))}this._register(this._optionsService.onMultipleOptionChange(["fontFamily","fontSize"],()=>this.measure()))}get hasValidSize(){return this.width>0&&this.height>0}measure(){let e=this._measureStrategy.measure();(e.width!==this.width||e.height!==this.height)&&(this.width=e.width,this.height=e.height,this._onCharSizeChange.fire())}};n0=ts([Re(2,nn)],n0);var dN=class extends nt{constructor(){super(...arguments),this._result={width:0,height:0}}_validateAndSet(e,t){e!==void 0&&e>0&&t!==void 0&&t>0&&(this._result.width=e,this._result.height=t)}},jI=class extends dN{constructor(e,t,s){super(),this._document=e,this._parentElement=t,this._optionsService=s,this._measureElement=this._document.createElement("span"),this._measureElement.classList.add("xterm-char-measure-element"),this._measureElement.textContent="W".repeat(32),this._measureElement.setAttribute("aria-hidden","true"),this._measureElement.style.whiteSpace="pre",this._measureElement.style.fontKerning="none",this._parentElement.appendChild(this._measureElement)}measure(){return this._measureElement.style.fontFamily=this._optionsService.rawOptions.fontFamily,this._measureElement.style.fontSize=`${this._optionsService.rawOptions.fontSize}px`,this._validateAndSet(Number(this._measureElement.offsetWidth)/32,Number(this._measureElement.offsetHeight)),this._result}},kI=class extends dN{constructor(e){super(),this._optionsService=e,this._canvas=new OffscreenCanvas(100,100),this._ctx=this._canvas.getContext("2d");let t=this._ctx.measureText("W");if(!("width"in t&&"fontBoundingBoxAscent"in t&&"fontBoundingBoxDescent"in t))throw new Error("Required font metrics not supported")}measure(){this._ctx.font=`${this._optionsService.rawOptions.fontSize}px ${this._optionsService.rawOptions.fontFamily}`;let e=this._ctx.measureText("W");return this._validateAndSet(e.width,e.fontBoundingBoxAscent+e.fontBoundingBoxDescent),this._result}},CI=class extends nt{constructor(e,t,s){super(),this._textarea=e,this._window=t,this.mainDocument=s,this._isFocused=!1,this._cachedIsFocused=void 0,this._screenDprMonitor=this._register(new NI(this._window)),this._onDprChange=this._register(new Ce),this.onDprChange=this._onDprChange.event,this._onWindowChange=this._register(new Ce),this.onWindowChange=this._onWindowChange.event,this._register(this.onWindowChange(n=>this._screenDprMonitor.setWindow(n))),this._register(Is.forward(this._screenDprMonitor.onDprChange,this._onDprChange)),this._register(Ge(this._textarea,"focus",()=>this._isFocused=!0)),this._register(Ge(this._textarea,"blur",()=>this._isFocused=!1))}get window(){return this._window}set window(e){this._window!==e&&(this._window=e,this._onWindowChange.fire(this._window))}get dpr(){return this.window.devicePixelRatio}get isFocused(){return this._cachedIsFocused===void 0&&(this._cachedIsFocused=this._isFocused&&this._textarea.ownerDocument.hasFocus(),queueMicrotask(()=>this._cachedIsFocused=void 0)),this._cachedIsFocused}},NI=class extends nt{constructor(e){super(),this._parentWindow=e,this._windowResizeListener=this._register(new Yo),this._onDprChange=this._register(new Ce),this.onDprChange=this._onDprChange.event,this._outerListener=()=>this._setDprAndFireIfDiffers(),this._currentDevicePixelRatio=this._parentWindow.devicePixelRatio,this._updateDpr(),this._setWindowResizeListener(),this._register(Ut(()=>this.clearListener()))}setWindow(e){this._parentWindow=e,this._setWindowResizeListener(),this._setDprAndFireIfDiffers()}_setWindowResizeListener(){this._windowResizeListener.value=Ge(this._parentWindow,"resize",()=>this._setDprAndFireIfDiffers())}_setDprAndFireIfDiffers(){this._parentWindow.devicePixelRatio!==this._currentDevicePixelRatio&&this._onDprChange.fire(this._parentWindow.devicePixelRatio),this._updateDpr()}_updateDpr(){var e;this._outerListener&&((e=this._resolutionMediaMatchList)==null||e.removeListener(this._outerListener),this._currentDevicePixelRatio=this._parentWindow.devicePixelRatio,this._resolutionMediaMatchList=this._parentWindow.matchMedia(`screen and (resolution: ${this._parentWindow.devicePixelRatio}dppx)`),this._resolutionMediaMatchList.addListener(this._outerListener))}clearListener(){!this._resolutionMediaMatchList||!this._outerListener||(this._resolutionMediaMatchList.removeListener(this._outerListener),this._resolutionMediaMatchList=void 0,this._outerListener=void 0)}},EI=class extends nt{constructor(){super(),this.linkProviders=[],this._register(Ut(()=>this.linkProviders.length=0))}registerLinkProvider(e){return this.linkProviders.push(e),{dispose:()=>{let t=this.linkProviders.indexOf(e);t!==-1&&this.linkProviders.splice(t,1)}}}};function mv(e,t,s){let n=s.getBoundingClientRect(),a=e.getComputedStyle(s),l=parseInt(a.getPropertyValue("padding-left")),c=parseInt(a.getPropertyValue("padding-top"));return[t.clientX-n.left-l,t.clientY-n.top-c]}function MI(e,t,s,n,a,l,c,d,f){if(!l)return;let h=mv(e,t,s);if(h)return h[0]=Math.ceil((h[0]+(f?c/2:0))/c),h[1]=Math.ceil(h[1]/d),h[0]=Math.min(Math.max(h[0],1),n+(f?1:0)),h[1]=Math.min(Math.max(h[1],1),a),h}var r0=class{constructor(e,t){this._renderService=e,this._charSizeService=t}getCoords(e,t,s,n,a){return MI(window,e,t,s,n,this._charSizeService.hasValidSize,this._renderService.dimensions.css.cell.width,this._renderService.dimensions.css.cell.height,a)}getMouseReportCoords(e,t){let s=mv(window,e,t);if(this._charSizeService.hasValidSize)return s[0]=Math.min(Math.max(s[0],0),this._renderService.dimensions.css.canvas.width-1),s[1]=Math.min(Math.max(s[1],0),this._renderService.dimensions.css.canvas.height-1),{col:Math.floor(s[0]/this._renderService.dimensions.css.cell.width),row:Math.floor(s[1]/this._renderService.dimensions.css.cell.height),x:Math.floor(s[0]),y:Math.floor(s[1])}}};r0=ts([Re(0,oi),Re(1,sf)],r0);var TI=class{constructor(e,t){this._renderCallback=e,this._coreBrowserService=t,this._refreshCallbacks=[]}dispose(){this._animationFrame&&(this._coreBrowserService.window.cancelAnimationFrame(this._animationFrame),this._animationFrame=void 0)}addRefreshCallback(e){return this._refreshCallbacks.push(e),this._animationFrame||(this._animationFrame=this._coreBrowserService.window.requestAnimationFrame(()=>this._innerRefresh())),this._animationFrame}refresh(e,t,s){this._rowCount=s,e=e!==void 0?e:0,t=t!==void 0?t:this._rowCount-1,this._rowStart=this._rowStart!==void 0?Math.min(this._rowStart,e):e,this._rowEnd=this._rowEnd!==void 0?Math.max(this._rowEnd,t):t,!this._animationFrame&&(this._animationFrame=this._coreBrowserService.window.requestAnimationFrame(()=>this._innerRefresh()))}_innerRefresh(){if(this._animationFrame=void 0,this._rowStart===void 0||this._rowEnd===void 0||this._rowCount===void 0){this._runRefreshCallbacks();return}let e=Math.max(this._rowStart,0),t=Math.min(this._rowEnd,this._rowCount-1);this._rowStart=void 0,this._rowEnd=void 0,this._renderCallback(e,t),this._runRefreshCallbacks()}_runRefreshCallbacks(){for(let e of this._refreshCallbacks)e(0);this._refreshCallbacks=[]}},hN={};I9(hN,{getSafariVersion:()=>RI,isChromeOS:()=>gN,isFirefox:()=>fN,isIpad:()=>DI,isIphone:()=>LI,isLegacyEdge:()=>AI,isLinux:()=>gv,isMac:()=>Ih,isNode:()=>nf,isSafari:()=>pN,isWindows:()=>mN});var nf=typeof process<"u"&&"title"in process,gu=nf?"node":navigator.userAgent,xu=nf?"node":navigator.platform,fN=gu.includes("Firefox"),AI=gu.includes("Edge"),pN=/^((?!chrome|android).)*safari/i.test(gu);function RI(){if(!pN)return 0;let e=gu.match(/Version\/(\d+)/);return e===null||e.length<2?0:parseInt(e[1])}var Ih=["Macintosh","MacIntel","MacPPC","Mac68K"].includes(xu),DI=xu==="iPad",LI=xu==="iPhone",mN=["Windows","Win16","Win32","WinCE"].includes(xu),gv=xu.indexOf("Linux")>=0,gN=/\bCrOS\b/.test(gu),xN=class{constructor(){this._tasks=[],this._i=0}enqueue(e){this._tasks.push(e),this._start()}flush(){for(;this._i<this._tasks.length;)this._tasks[this._i]()||this._i++;this.clear()}clear(){this._idleCallback&&(this._cancelCallback(this._idleCallback),this._idleCallback=void 0),this._i=0,this._tasks.length=0}_start(){this._idleCallback||(this._idleCallback=this._requestCallback(this._process.bind(this)))}_process(e){this._idleCallback=void 0;let t=0,s=0,n=e.timeRemaining(),a=0;for(;this._i<this._tasks.length;){if(t=performance.now(),this._tasks[this._i]()||this._i++,t=Math.max(1,performance.now()-t),s=Math.max(t,s),a=e.timeRemaining(),s*1.5>a){n-t<-20&&console.warn(`task queue exceeded allotted deadline by ${Math.abs(Math.round(n-t))}ms`),this._start();return}n=a}this.clear()}},BI=class extends xN{_requestCallback(e){return setTimeout(()=>e(this._createDeadline(16)))}_cancelCallback(e){clearTimeout(e)}_createDeadline(e){let t=performance.now()+e;return{timeRemaining:()=>Math.max(0,t-performance.now())}}},OI=class extends xN{_requestCallback(e){return requestIdleCallback(e)}_cancelCallback(e){cancelIdleCallback(e)}},Fh=!nf&&"requestIdleCallback"in window?OI:BI,zI=class{constructor(){this._queue=new Fh}set(e){this._queue.clear(),this._queue.enqueue(e)}flush(){this._queue.flush()}},i0=class extends nt{constructor(e,t,s,n,a,l,c,d,f){super(),this._rowCount=e,this._optionsService=s,this._charSizeService=n,this._coreService=a,this._coreBrowserService=d,this._renderer=this._register(new Yo),this._pausedResizeTask=new zI,this._observerDisposable=this._register(new Yo),this._isPaused=!1,this._needsFullRefresh=!1,this._isNextRenderRedrawOnly=!0,this._needsSelectionRefresh=!1,this._canvasWidth=0,this._canvasHeight=0,this._selectionState={start:void 0,end:void 0,columnSelectMode:!1},this._onDimensionsChange=this._register(new Ce),this.onDimensionsChange=this._onDimensionsChange.event,this._onRenderedViewportChange=this._register(new Ce),this.onRenderedViewportChange=this._onRenderedViewportChange.event,this._onRender=this._register(new Ce),this.onRender=this._onRender.event,this._onRefreshRequest=this._register(new Ce),this.onRefreshRequest=this._onRefreshRequest.event,this._renderDebouncer=new TI((h,m)=>this._renderRows(h,m),this._coreBrowserService),this._register(this._renderDebouncer),this._syncOutputHandler=new PI(this._coreBrowserService,this._coreService,()=>this._fullRefresh()),this._register(Ut(()=>this._syncOutputHandler.dispose())),this._register(this._coreBrowserService.onDprChange(()=>this.handleDevicePixelRatioChange())),this._register(c.onResize(()=>this._fullRefresh())),this._register(c.buffers.onBufferActivate(()=>{var h;return(h=this._renderer.value)==null?void 0:h.clear()})),this._register(this._optionsService.onOptionChange(()=>this._handleOptionsChanged())),this._register(this._charSizeService.onCharSizeChange(()=>this.handleCharSizeChanged())),this._register(l.onDecorationRegistered(()=>this._fullRefresh())),this._register(l.onDecorationRemoved(()=>this._fullRefresh())),this._register(this._optionsService.onMultipleOptionChange(["customGlyphs","drawBoldTextInBrightColors","letterSpacing","lineHeight","fontFamily","fontSize","fontWeight","fontWeightBold","minimumContrastRatio","rescaleOverlappingGlyphs"],()=>{this.clear(),this.handleResize(c.cols,c.rows),this._fullRefresh()})),this._register(this._optionsService.onMultipleOptionChange(["cursorBlink","cursorStyle"],()=>this.refreshRows(c.buffer.y,c.buffer.y,!0))),this._register(f.onChangeColors(()=>this._fullRefresh())),this._registerIntersectionObserver(this._coreBrowserService.window,t),this._register(this._coreBrowserService.onWindowChange(h=>this._registerIntersectionObserver(h,t)))}get dimensions(){return this._renderer.value.dimensions}_registerIntersectionObserver(e,t){if("IntersectionObserver"in e){let s=new e.IntersectionObserver(n=>this._handleIntersectionChange(n[n.length-1]),{threshold:0});s.observe(t),this._observerDisposable.value=Ut(()=>s.disconnect())}}_handleIntersectionChange(e){this._isPaused=e.isIntersecting===void 0?e.intersectionRatio===0:!e.isIntersecting,!this._isPaused&&!this._charSizeService.hasValidSize&&this._charSizeService.measure(),!this._isPaused&&this._needsFullRefresh&&(this._pausedResizeTask.flush(),this.refreshRows(0,this._rowCount-1),this._needsFullRefresh=!1)}refreshRows(e,t,s=!1){if(this._isPaused){this._needsFullRefresh=!0;return}if(this._coreService.decPrivateModes.synchronizedOutput){this._syncOutputHandler.bufferRows(e,t);return}let n=this._syncOutputHandler.flush();n&&(e=Math.min(e,n.start),t=Math.max(t,n.end)),s||(this._isNextRenderRedrawOnly=!1),this._renderDebouncer.refresh(e,t,this._rowCount)}_renderRows(e,t){if(this._renderer.value){if(this._coreService.decPrivateModes.synchronizedOutput){this._syncOutputHandler.bufferRows(e,t);return}e=Math.min(e,this._rowCount-1),t=Math.min(t,this._rowCount-1),this._renderer.value.renderRows(e,t),this._needsSelectionRefresh&&(this._renderer.value.handleSelectionChanged(this._selectionState.start,this._selectionState.end,this._selectionState.columnSelectMode),this._needsSelectionRefresh=!1),this._isNextRenderRedrawOnly||this._onRenderedViewportChange.fire({start:e,end:t}),this._onRender.fire({start:e,end:t}),this._isNextRenderRedrawOnly=!0}}resize(e,t){this._rowCount=t,this._fireOnCanvasResize()}_handleOptionsChanged(){this._renderer.value&&(this.refreshRows(0,this._rowCount-1),this._fireOnCanvasResize())}_fireOnCanvasResize(){this._renderer.value&&(this._renderer.value.dimensions.css.canvas.width===this._canvasWidth&&this._renderer.value.dimensions.css.canvas.height===this._canvasHeight||this._onDimensionsChange.fire(this._renderer.value.dimensions))}hasRenderer(){return!!this._renderer.value}setRenderer(e){this._renderer.value=e,this._renderer.value&&(this._renderer.value.onRequestRedraw(t=>this.refreshRows(t.start,t.end,!0)),this._needsSelectionRefresh=!0,this._fullRefresh())}addRefreshCallback(e){return this._renderDebouncer.addRefreshCallback(e)}_fullRefresh(){this._isPaused?this._needsFullRefresh=!0:this.refreshRows(0,this._rowCount-1)}clearTextureAtlas(){var e,t;this._renderer.value&&((t=(e=this._renderer.value).clearTextureAtlas)==null||t.call(e),this._fullRefresh())}handleDevicePixelRatioChange(){this._charSizeService.measure(),this._renderer.value&&(this._renderer.value.handleDevicePixelRatioChange(),this.refreshRows(0,this._rowCount-1))}handleResize(e,t){this._renderer.value&&(this._isPaused?this._pausedResizeTask.set(()=>{var s;return(s=this._renderer.value)==null?void 0:s.handleResize(e,t)}):this._renderer.value.handleResize(e,t),this._fullRefresh())}handleCharSizeChanged(){var e;(e=this._renderer.value)==null||e.handleCharSizeChanged()}handleBlur(){var e;(e=this._renderer.value)==null||e.handleBlur()}handleFocus(){var e;(e=this._renderer.value)==null||e.handleFocus()}handleSelectionChanged(e,t,s){var n;this._selectionState.start=e,this._selectionState.end=t,this._selectionState.columnSelectMode=s,(n=this._renderer.value)==null||n.handleSelectionChanged(e,t,s)}handleCursorMove(){var e;(e=this._renderer.value)==null||e.handleCursorMove()}clear(){var e;(e=this._renderer.value)==null||e.clear()}};i0=ts([Re(2,nn),Re(3,sf),Re(4,Ba),Re(5,mu),Re(6,sn),Re(7,ai),Re(8,tl)],i0);var PI=class{constructor(e,t,s){this._coreBrowserService=e,this._coreService=t,this._onTimeout=s,this._start=0,this._end=0,this._isBuffering=!1}bufferRows(e,t){this._isBuffering?(this._start=Math.min(this._start,e),this._end=Math.max(this._end,t)):(this._start=e,this._end=t,this._isBuffering=!0),this._timeout===void 0&&(this._timeout=this._coreBrowserService.window.setTimeout(()=>{this._timeout=void 0,this._coreService.decPrivateModes.synchronizedOutput=!1,this._onTimeout()},1e3))}flush(){if(this._timeout!==void 0&&(this._coreBrowserService.window.clearTimeout(this._timeout),this._timeout=void 0),!this._isBuffering)return;let e={start:this._start,end:this._end};return this._isBuffering=!1,e}dispose(){this._timeout!==void 0&&(this._coreBrowserService.window.clearTimeout(this._timeout),this._timeout=void 0)}};function $I(e,t,s,n){let a=s.buffer.x,l=s.buffer.y;if(!s.buffer.hasScrollback)return HI(a,l,e,t,s,n)+rf(l,t,s,n)+UI(a,l,e,t,s,n);let c;if(l===t)return c=a>e?"D":"C",tu(Math.abs(a-e),eu(c,n));c=l>t?"D":"C";let d=Math.abs(l-t),f=FI(l>t?e:a,s)+(d-1)*s.cols+1+II(l>t?a:e);return tu(f,eu(c,n))}function II(e,t){return e-1}function FI(e,t){return t.cols-e}function HI(e,t,s,n,a,l){return rf(t,n,a,l).length===0?"":tu(bN(e,t,e,t-Da(t,a),!1,a).length,eu("D",l))}function rf(e,t,s,n){let a=e-Da(e,s),l=t-Da(t,s),c=Math.abs(a-l)-VI(e,t,s);return tu(c,eu(vN(e,t),n))}function UI(e,t,s,n,a,l){let c;rf(t,n,a,l).length>0?c=n-Da(n,a):c=t;let d=n,f=WI(e,t,s,n,a,l);return tu(bN(e,c,s,d,f==="C",a).length,eu(f,l))}function VI(e,t,s){var c;let n=0,a=e-Da(e,s),l=t-Da(t,s);for(let d=0;d<Math.abs(a-l);d++){let f=vN(e,t)==="A"?-1:1;(c=s.buffer.lines.get(a+f*d))!=null&&c.isWrapped&&n++}return n}function Da(e,t){let s=0,n=t.buffer.lines.get(e),a=n==null?void 0:n.isWrapped;for(;a&&e>=0&&e<t.rows;)s++,n=t.buffer.lines.get(--e),a=n==null?void 0:n.isWrapped;return s}function WI(e,t,s,n,a,l){let c;return rf(s,n,a,l).length>0?c=n-Da(n,a):c=t,e<s&&c<=n||e>=s&&c<n?"C":"D"}function vN(e,t){return e>t?"A":"B"}function bN(e,t,s,n,a,l){let c=e,d=t,f="";for(;(c!==s||d!==n)&&d>=0&&d<l.buffer.lines.length;)c+=a?1:-1,a&&c>l.cols-1?(f+=l.buffer.translateBufferLineToString(d,!1,e,c),c=0,e=0,d++):!a&&c<0&&(f+=l.buffer.translateBufferLineToString(d,!1,0,e+1),c=l.cols-1,e=c,d--);return f+l.buffer.translateBufferLineToString(d,!1,e,c)}function eu(e,t){let s=t?"O":"[";return xe.ESC+s+e}function tu(e,t){e=Math.floor(e);let s="";for(let n=0;n<e;n++)s+=t;return s}var qI=class{constructor(e){this._bufferService=e,this.isSelectAllActive=!1,this.selectionStartLength=0}clearSelection(){this.selectionStart=void 0,this.selectionEnd=void 0,this.isSelectAllActive=!1,this.selectionStartLength=0}get finalSelectionStart(){return this.isSelectAllActive?[0,0]:!this.selectionEnd||!this.selectionStart?this.selectionStart:this.areSelectionValuesReversed()?this.selectionEnd:this.selectionStart}get finalSelectionEnd(){if(this.isSelectAllActive)return[this._bufferService.cols,this._bufferService.buffer.ybase+this._bufferService.rows-1];if(this.selectionStart){if(!this.selectionEnd||this.areSelectionValuesReversed()){let e=this.selectionStart[0]+this.selectionStartLength;return e>this._bufferService.cols?e%this._bufferService.cols===0?[this._bufferService.cols,this.selectionStart[1]+Math.floor(e/this._bufferService.cols)-1]:[e%this._bufferService.cols,this.selectionStart[1]+Math.floor(e/this._bufferService.cols)]:[e,this.selectionStart[1]]}if(this.selectionStartLength&&this.selectionEnd[1]===this.selectionStart[1]){let e=this.selectionStart[0]+this.selectionStartLength;return e>this._bufferService.cols?[e%this._bufferService.cols,this.selectionStart[1]+Math.floor(e/this._bufferService.cols)]:[Math.max(e,this.selectionEnd[0]),this.selectionEnd[1]]}return this.selectionEnd}}areSelectionValuesReversed(){let e=this.selectionStart,t=this.selectionEnd;return!e||!t?!1:e[1]>t[1]||e[1]===t[1]&&e[0]>t[0]}handleTrim(e){return this.selectionStart&&(this.selectionStart[1]-=e),this.selectionEnd&&(this.selectionEnd[1]-=e),this.selectionEnd&&this.selectionEnd[1]<0?(this.clearSelection(),!0):(this.selectionStart&&this.selectionStart[1]<0&&(this.selectionStart[1]=0),!1)}};function B2(e,t){if(e.start.y>e.end.y)throw new Error(`Buffer range end (${e.end.x}, ${e.end.y}) cannot be before start (${e.start.x}, ${e.start.y})`);return t*(e.end.y-e.start.y)+(e.end.x-e.start.x+1)}var Cg=50,GI=15,KI=50,YI=500,XI=" ",JI=new RegExp(XI,"g"),a0=class extends nt{constructor(e,t,s,n,a,l,c,d,f){super(),this._element=e,this._screenElement=t,this._linkifier=s,this._bufferService=n,this._coreService=a,this._mouseService=l,this._optionsService=c,this._renderService=d,this._coreBrowserService=f,this._dragScrollAmount=0,this._enabled=!0,this._workCell=new Jn,this._mouseDownTimeStamp=0,this._oldHasSelection=!1,this._oldSelectionStart=void 0,this._oldSelectionEnd=void 0,this._onLinuxMouseSelection=this._register(new Ce),this.onLinuxMouseSelection=this._onLinuxMouseSelection.event,this._onRedrawRequest=this._register(new Ce),this.onRequestRedraw=this._onRedrawRequest.event,this._onSelectionChange=this._register(new Ce),this.onSelectionChange=this._onSelectionChange.event,this._onRequestScrollLines=this._register(new Ce),this.onRequestScrollLines=this._onRequestScrollLines.event,this._mouseMoveListener=h=>this._handleMouseMove(h),this._mouseUpListener=h=>this._handleMouseUp(h),this._coreService.onUserInput(()=>{this.hasSelection&&this.clearSelection()}),this._trimListener=this._bufferService.buffer.lines.onTrim(h=>this._handleTrim(h)),this._register(this._bufferService.buffers.onBufferActivate(h=>this._handleBufferActivate(h))),this.enable(),this._model=new qI(this._bufferService),this._activeSelectionMode=0,this._register(Ut(()=>{this._removeMouseDownListeners()})),this._register(this._bufferService.onResize(h=>{h.rowsChanged&&this.clearSelection()}))}reset(){this.clearSelection()}disable(){this.clearSelection(),this._enabled=!1}enable(){this._enabled=!0}get selectionStart(){return this._model.finalSelectionStart}get selectionEnd(){return this._model.finalSelectionEnd}get hasSelection(){let e=this._model.finalSelectionStart,t=this._model.finalSelectionEnd;return!e||!t?!1:e[0]!==t[0]||e[1]!==t[1]}get selectionText(){let e=this._model.finalSelectionStart,t=this._model.finalSelectionEnd;if(!e||!t)return"";let s=this._bufferService.buffer,n=[];if(this._activeSelectionMode===3){if(e[0]===t[0])return"";let a=e[0]<t[0]?e[0]:t[0],l=e[0]<t[0]?t[0]:e[0];for(let c=e[1];c<=t[1];c++){let d=s.translateBufferLineToString(c,!0,a,l);n.push(d)}}else{let a=e[1]===t[1]?t[0]:void 0;n.push(s.translateBufferLineToString(e[1],!0,e[0],a));for(let l=e[1]+1;l<=t[1]-1;l++){let c=s.lines.get(l),d=s.translateBufferLineToString(l,!0);c!=null&&c.isWrapped?n[n.length-1]+=d:n.push(d)}if(e[1]!==t[1]){let l=s.lines.get(t[1]),c=s.translateBufferLineToString(t[1],!0,0,t[0]);l&&l.isWrapped?n[n.length-1]+=c:n.push(c)}}return n.map(a=>a.replace(JI," ")).join(mN?`\r
|
|
255
255
|
`:`
|
|
256
|
-
`)}clearSelection(){this._model.clearSelection(),this._removeMouseDownListeners(),this.refresh(),this._onSelectionChange.fire()}refresh(e){this._refreshAnimationFrame||(this._refreshAnimationFrame=this._coreBrowserService.window.requestAnimationFrame(()=>this._refresh())),gv&&e&&this.selectionText.length&&this._onLinuxMouseSelection.fire(this.selectionText)}_refresh(){this._refreshAnimationFrame=void 0,this._onRedrawRequest.fire({start:this._model.finalSelectionStart,end:this._model.finalSelectionEnd,columnSelectMode:this._activeSelectionMode===3})}_isClickInSelection(e){let t=this._getMouseBufferCoords(e),s=this._model.finalSelectionStart,n=this._model.finalSelectionEnd;return!s||!n||!t?!1:this._areCoordsInSelection(t,s,n)}isCellInSelection(e,t){let s=this._model.finalSelectionStart,n=this._model.finalSelectionEnd;return!s||!n?!1:this._areCoordsInSelection([e,t],s,n)}_areCoordsInSelection(e,t,s){return e[1]>t[1]&&e[1]<s[1]||t[1]===s[1]&&e[1]===t[1]&&e[0]>=t[0]&&e[0]<s[0]||t[1]<s[1]&&e[1]===s[1]&&e[0]<s[0]||t[1]<s[1]&&e[1]===t[1]&&e[0]>=t[0]}_selectWordAtCursor(e,t){var a,l;let s=(l=(a=this._linkifier.currentLink)==null?void 0:a.link)==null?void 0:l.range;if(s)return this._model.selectionStart=[s.start.x-1,s.start.y-1],this._model.selectionStartLength=B2(s,this._bufferService.cols),this._model.selectionEnd=void 0,!0;let n=this._getMouseBufferCoords(e);return n?(this._selectWordAt(n,t),this._model.selectionEnd=void 0,!0):!1}selectAll(){this._model.isSelectAllActive=!0,this.refresh(),this._onSelectionChange.fire()}selectLines(e,t){this._model.clearSelection(),e=Math.max(e,0),t=Math.min(t,this._bufferService.buffer.lines.length-1),this._model.selectionStart=[0,e],this._model.selectionEnd=[this._bufferService.cols,t],this.refresh(),this._onSelectionChange.fire()}_handleTrim(e){this._model.handleTrim(e)&&this.refresh()}_getMouseBufferCoords(e){let t=this._mouseService.getCoords(e,this._screenElement,this._bufferService.cols,this._bufferService.rows,!0);if(t)return t[0]--,t[1]--,t[1]+=this._bufferService.buffer.ydisp,t}_getMouseEventScrollAmount(e){let t=mv(this._coreBrowserService.window,e,this._screenElement)[1],s=this._renderService.dimensions.css.canvas.height;return t>=0&&t<=s?0:(t>s&&(t-=s),t=Math.min(Math.max(t,-Cg),Cg),t/=Cg,t/Math.abs(t)+Math.round(t*(qI-1)))}shouldForceSelection(e){return Ih?e.altKey&&this._optionsService.rawOptions.macOptionClickForcesSelection:e.shiftKey}handleMouseDown(e){if(this._mouseDownTimeStamp=e.timeStamp,!(e.button===2&&this.hasSelection)&&e.button===0){if(!this._enabled){if(!this.shouldForceSelection(e))return;e.stopPropagation()}e.preventDefault(),this._dragScrollAmount=0,this._enabled&&e.shiftKey?this._handleIncrementalClick(e):e.detail===1?this._handleSingleClick(e):e.detail===2?this._handleDoubleClick(e):e.detail===3&&this._handleTripleClick(e),this._addMouseDownListeners(),this.refresh(!0)}}_addMouseDownListeners(){this._screenElement.ownerDocument&&(this._screenElement.ownerDocument.addEventListener("mousemove",this._mouseMoveListener),this._screenElement.ownerDocument.addEventListener("mouseup",this._mouseUpListener)),this._dragScrollIntervalTimer=this._coreBrowserService.window.setInterval(()=>this._dragScroll(),GI)}_removeMouseDownListeners(){this._screenElement.ownerDocument&&(this._screenElement.ownerDocument.removeEventListener("mousemove",this._mouseMoveListener),this._screenElement.ownerDocument.removeEventListener("mouseup",this._mouseUpListener)),this._coreBrowserService.window.clearInterval(this._dragScrollIntervalTimer),this._dragScrollIntervalTimer=void 0}_handleIncrementalClick(e){this._model.selectionStart&&(this._model.selectionEnd=this._getMouseBufferCoords(e))}_handleSingleClick(e){if(this._model.selectionStartLength=0,this._model.isSelectAllActive=!1,this._activeSelectionMode=this.shouldColumnSelect(e)?3:0,this._model.selectionStart=this._getMouseBufferCoords(e),!this._model.selectionStart)return;this._model.selectionEnd=void 0;let t=this._bufferService.buffer.lines.get(this._model.selectionStart[1]);t&&t.length!==this._model.selectionStart[0]&&t.hasWidth(this._model.selectionStart[0])===0&&this._model.selectionStart[0]++}_handleDoubleClick(e){this._selectWordAtCursor(e,!0)&&(this._activeSelectionMode=1)}_handleTripleClick(e){let t=this._getMouseBufferCoords(e);t&&(this._activeSelectionMode=2,this._selectLineAt(t[1]))}shouldColumnSelect(e){return e.altKey&&!(Ih&&this._optionsService.rawOptions.macOptionClickForcesSelection)}_handleMouseMove(e){if(e.stopImmediatePropagation(),!this._model.selectionStart)return;let t=this._model.selectionEnd?[this._model.selectionEnd[0],this._model.selectionEnd[1]]:null;if(this._model.selectionEnd=this._getMouseBufferCoords(e),!this._model.selectionEnd){this.refresh(!0);return}this._activeSelectionMode===2?this._model.selectionEnd[1]<this._model.selectionStart[1]?this._model.selectionEnd[0]=0:this._model.selectionEnd[0]=this._bufferService.cols:this._activeSelectionMode===1&&this._selectToWordAt(this._model.selectionEnd),this._dragScrollAmount=this._getMouseEventScrollAmount(e),this._activeSelectionMode!==3&&(this._dragScrollAmount>0?this._model.selectionEnd[0]=this._bufferService.cols:this._dragScrollAmount<0&&(this._model.selectionEnd[0]=0));let s=this._bufferService.buffer;if(this._model.selectionEnd[1]<s.lines.length){let n=s.lines.get(this._model.selectionEnd[1]);n&&n.hasWidth(this._model.selectionEnd[0])===0&&this._model.selectionEnd[0]<this._bufferService.cols&&this._model.selectionEnd[0]++}(!t||t[0]!==this._model.selectionEnd[0]||t[1]!==this._model.selectionEnd[1])&&this.refresh(!0)}_dragScroll(){if(!(!this._model.selectionEnd||!this._model.selectionStart)&&this._dragScrollAmount){this._onRequestScrollLines.fire({amount:this._dragScrollAmount,suppressScrollEvent:!1});let e=this._bufferService.buffer;this._dragScrollAmount>0?(this._activeSelectionMode!==3&&(this._model.selectionEnd[0]=this._bufferService.cols),this._model.selectionEnd[1]=Math.min(e.ydisp+this._bufferService.rows,e.lines.length-1)):(this._activeSelectionMode!==3&&(this._model.selectionEnd[0]=0),this._model.selectionEnd[1]=e.ydisp),this.refresh()}}_handleMouseUp(e){let t=e.timeStamp-this._mouseDownTimeStamp;if(this._removeMouseDownListeners(),this.selectionText.length<=1&&t<KI&&e.altKey&&this._optionsService.rawOptions.altClickMovesCursor){if(this._bufferService.buffer.ybase===this._bufferService.buffer.ydisp){let s=this._mouseService.getCoords(e,this._element,this._bufferService.cols,this._bufferService.rows,!1);if(s&&s[0]!==void 0&&s[1]!==void 0){let n=PI(s[0]-1,s[1]-1,this._bufferService,this._coreService.decPrivateModes.applicationCursorKeys);this._coreService.triggerDataEvent(n,!0)}}}else this._fireEventIfSelectionChanged()}_fireEventIfSelectionChanged(){let e=this._model.finalSelectionStart,t=this._model.finalSelectionEnd,s=!!e&&!!t&&(e[0]!==t[0]||e[1]!==t[1]);if(!s){this._oldHasSelection&&this._fireOnSelectionChange(e,t,s);return}!e||!t||(!this._oldSelectionStart||!this._oldSelectionEnd||e[0]!==this._oldSelectionStart[0]||e[1]!==this._oldSelectionStart[1]||t[0]!==this._oldSelectionEnd[0]||t[1]!==this._oldSelectionEnd[1])&&this._fireOnSelectionChange(e,t,s)}_fireOnSelectionChange(e,t,s){this._oldSelectionStart=e,this._oldSelectionEnd=t,this._oldHasSelection=s,this._onSelectionChange.fire()}_handleBufferActivate(e){this.clearSelection(),this._trimListener.dispose(),this._trimListener=e.activeBuffer.lines.onTrim(t=>this._handleTrim(t))}_convertViewportColToCharacterIndex(e,t){let s=t;for(let n=0;t>=n;n++){let a=e.loadCell(n,this._workCell).getChars().length;this._workCell.getWidth()===0?s--:a>1&&t!==n&&(s+=a-1)}return s}setSelection(e,t,s){this._model.clearSelection(),this._removeMouseDownListeners(),this._model.selectionStart=[e,t],this._model.selectionStartLength=s,this.refresh(),this._fireEventIfSelectionChanged()}rightClickSelect(e){this._isClickInSelection(e)||(this._selectWordAtCursor(e,!1)&&this.refresh(!0),this._fireEventIfSelectionChanged())}_getWordAt(e,t,s=!0,n=!0){if(e[0]>=this._bufferService.cols)return;let a=this._bufferService.buffer,l=a.lines.get(e[1]);if(!l)return;let c=a.translateBufferLineToString(e[1],!1),d=this._convertViewportColToCharacterIndex(l,e[0]),f=d,h=e[0]-d,m=0,g=0,b=0,v=0;if(c.charAt(d)===" "){for(;d>0&&c.charAt(d-1)===" ";)d--;for(;f<c.length&&c.charAt(f+1)===" ";)f++}else{let j=e[0],k=e[0];l.getWidth(j)===0&&(m++,j--),l.getWidth(k)===2&&(g++,k++);let E=l.getString(k).length;for(E>1&&(v+=E-1,f+=E-1);j>0&&d>0&&!this._isCharWordSeparator(l.loadCell(j-1,this._workCell));){l.loadCell(j-1,this._workCell);let N=this._workCell.getChars().length;this._workCell.getWidth()===0?(m++,j--):N>1&&(b+=N-1,d-=N-1),d--,j--}for(;k<l.length&&f+1<c.length&&!this._isCharWordSeparator(l.loadCell(k+1,this._workCell));){l.loadCell(k+1,this._workCell);let N=this._workCell.getChars().length;this._workCell.getWidth()===2?(g++,k++):N>1&&(v+=N-1,f+=N-1),f++,k++}}f++;let y=d+h-m+b,S=Math.min(this._bufferService.cols,f-d+m+g-b-v);if(!(!t&&c.slice(d,f).trim()==="")){if(s&&y===0&&l.getCodePoint(0)!==32){let j=a.lines.get(e[1]-1);if(j&&l.isWrapped&&j.getCodePoint(this._bufferService.cols-1)!==32){let k=this._getWordAt([this._bufferService.cols-1,e[1]-1],!1,!0,!1);if(k){let E=this._bufferService.cols-k.start;y-=E,S+=E}}}if(n&&y+S===this._bufferService.cols&&l.getCodePoint(this._bufferService.cols-1)!==32){let j=a.lines.get(e[1]+1);if(j!=null&&j.isWrapped&&j.getCodePoint(0)!==32){let k=this._getWordAt([0,e[1]+1],!1,!1,!0);k&&(S+=k.length)}}return{start:y,length:S}}}_selectWordAt(e,t){let s=this._getWordAt(e,t);if(s){for(;s.start<0;)s.start+=this._bufferService.cols,e[1]--;this._model.selectionStart=[s.start,e[1]],this._model.selectionStartLength=s.length}}_selectToWordAt(e){let t=this._getWordAt(e,!0);if(t){let s=e[1];for(;t.start<0;)t.start+=this._bufferService.cols,s--;if(!this._model.areSelectionValuesReversed())for(;t.start+t.length>this._bufferService.cols;)t.length-=this._bufferService.cols,s++;this._model.selectionEnd=[this._model.areSelectionValuesReversed()?t.start:t.start+t.length,s]}}_isCharWordSeparator(e){return e.getWidth()===0?!1:this._optionsService.rawOptions.wordSeparator.indexOf(e.getChars())>=0}_selectLineAt(e){let t=this._bufferService.buffer.getWrappedRangeForLine(e),s={start:{x:0,y:t.first},end:{x:this._bufferService.cols-1,y:t.last}};this._model.selectionStart=[0,t.first],this._model.selectionEnd=void 0,this._model.selectionStartLength=B2(s,this._bufferService.cols)}};a0=ts([Re(3,sn),Re(4,Ba),Re(5,lv),Re(6,nn),Re(7,oi),Re(8,ai)],a0);var O2=class{constructor(){this._data={}}set(e,t,s){this._data[e]||(this._data[e]={}),this._data[e][t]=s}get(e,t){return this._data[e]?this._data[e][t]:void 0}clear(){this._data={}}},z2=class{constructor(){this._color=new O2,this._css=new O2}setCss(e,t,s){this._css.set(e,t,s)}getCss(e,t){return this._css.get(e,t)}setColor(e,t,s){this._color.set(e,t,s)}getColor(e,t){return this._color.get(e,t)}clear(){this._color.clear(),this._css.clear()}},bs=Object.freeze((()=>{let e=[Wt.toColor("#2e3436"),Wt.toColor("#cc0000"),Wt.toColor("#4e9a06"),Wt.toColor("#c4a000"),Wt.toColor("#3465a4"),Wt.toColor("#75507b"),Wt.toColor("#06989a"),Wt.toColor("#d3d7cf"),Wt.toColor("#555753"),Wt.toColor("#ef2929"),Wt.toColor("#8ae234"),Wt.toColor("#fce94f"),Wt.toColor("#729fcf"),Wt.toColor("#ad7fa8"),Wt.toColor("#34e2e2"),Wt.toColor("#eeeeec")],t=[0,95,135,175,215,255];for(let s=0;s<216;s++){let n=t[s/36%6|0],a=t[s/6%6|0],l=t[s%6];e.push({css:ps.toCss(n,a,l),rgba:ps.toRgba(n,a,l)})}for(let s=0;s<24;s++){let n=8+s*10;e.push({css:ps.toCss(n,n,n),rgba:ps.toRgba(n,n,n)})}return e})()),wa=Wt.toColor("#ffffff"),Tc=Wt.toColor("#000000"),P2=Wt.toColor("#ffffff"),$2=Tc,fc={css:"rgba(255, 255, 255, 0.3)",rgba:4294967117},JI=wa,o0=class extends nt{constructor(e){super(),this._optionsService=e,this._contrastCache=new z2,this._halfContrastCache=new z2,this._onChangeColors=this._register(new Ce),this.onChangeColors=this._onChangeColors.event,this._colors={foreground:wa,background:Tc,cursor:P2,cursorAccent:$2,selectionForeground:void 0,selectionBackgroundTransparent:fc,selectionBackgroundOpaque:$t.blend(Tc,fc),selectionInactiveBackgroundTransparent:fc,selectionInactiveBackgroundOpaque:$t.blend(Tc,fc),scrollbarSliderBackground:$t.opacity(wa,.2),scrollbarSliderHoverBackground:$t.opacity(wa,.4),scrollbarSliderActiveBackground:$t.opacity(wa,.5),overviewRulerBorder:wa,ansi:bs.slice(),contrastCache:this._contrastCache,halfContrastCache:this._halfContrastCache},this._updateRestoreColors(),this._setTheme(this._optionsService.rawOptions.theme),this._register(this._optionsService.onSpecificOptionChange("minimumContrastRatio",()=>this._contrastCache.clear())),this._register(this._optionsService.onSpecificOptionChange("theme",()=>this._setTheme(this._optionsService.rawOptions.theme)))}get colors(){return this._colors}_setTheme(e={}){let t=this._colors;if(t.foreground=Et(e.foreground,wa),t.background=Et(e.background,Tc),t.cursor=$t.blend(t.background,Et(e.cursor,P2)),t.cursorAccent=$t.blend(t.background,Et(e.cursorAccent,$2)),t.selectionBackgroundTransparent=Et(e.selectionBackground,fc),t.selectionBackgroundOpaque=$t.blend(t.background,t.selectionBackgroundTransparent),t.selectionInactiveBackgroundTransparent=Et(e.selectionInactiveBackground,t.selectionBackgroundTransparent),t.selectionInactiveBackgroundOpaque=$t.blend(t.background,t.selectionInactiveBackgroundTransparent),t.selectionForeground=e.selectionForeground?Et(e.selectionForeground,R2):void 0,t.selectionForeground===R2&&(t.selectionForeground=void 0),$t.isOpaque(t.selectionBackgroundTransparent)&&(t.selectionBackgroundTransparent=$t.opacity(t.selectionBackgroundTransparent,.3)),$t.isOpaque(t.selectionInactiveBackgroundTransparent)&&(t.selectionInactiveBackgroundTransparent=$t.opacity(t.selectionInactiveBackgroundTransparent,.3)),t.scrollbarSliderBackground=Et(e.scrollbarSliderBackground,$t.opacity(t.foreground,.2)),t.scrollbarSliderHoverBackground=Et(e.scrollbarSliderHoverBackground,$t.opacity(t.foreground,.4)),t.scrollbarSliderActiveBackground=Et(e.scrollbarSliderActiveBackground,$t.opacity(t.foreground,.5)),t.overviewRulerBorder=Et(e.overviewRulerBorder,JI),t.ansi=bs.slice(),t.ansi[0]=Et(e.black,bs[0]),t.ansi[1]=Et(e.red,bs[1]),t.ansi[2]=Et(e.green,bs[2]),t.ansi[3]=Et(e.yellow,bs[3]),t.ansi[4]=Et(e.blue,bs[4]),t.ansi[5]=Et(e.magenta,bs[5]),t.ansi[6]=Et(e.cyan,bs[6]),t.ansi[7]=Et(e.white,bs[7]),t.ansi[8]=Et(e.brightBlack,bs[8]),t.ansi[9]=Et(e.brightRed,bs[9]),t.ansi[10]=Et(e.brightGreen,bs[10]),t.ansi[11]=Et(e.brightYellow,bs[11]),t.ansi[12]=Et(e.brightBlue,bs[12]),t.ansi[13]=Et(e.brightMagenta,bs[13]),t.ansi[14]=Et(e.brightCyan,bs[14]),t.ansi[15]=Et(e.brightWhite,bs[15]),e.extendedAnsi){let s=Math.min(t.ansi.length-16,e.extendedAnsi.length);for(let n=0;n<s;n++)t.ansi[n+16]=Et(e.extendedAnsi[n],bs[n+16])}this._contrastCache.clear(),this._halfContrastCache.clear(),this._updateRestoreColors(),this._onChangeColors.fire(this.colors)}restoreColor(e){this._restoreColor(e),this._onChangeColors.fire(this.colors)}_restoreColor(e){if(e===void 0){for(let t=0;t<this._restoreColors.ansi.length;++t)this._colors.ansi[t]=this._restoreColors.ansi[t];return}switch(e){case 256:this._colors.foreground=this._restoreColors.foreground;break;case 257:this._colors.background=this._restoreColors.background;break;case 258:this._colors.cursor=this._restoreColors.cursor;break;default:this._colors.ansi[e]=this._restoreColors.ansi[e]}}modifyColors(e){e(this._colors),this._onChangeColors.fire(this.colors)}_updateRestoreColors(){this._restoreColors={foreground:this._colors.foreground,background:this._colors.background,cursor:this._colors.cursor,ansi:this._colors.ansi.slice()}}};o0=ts([Re(0,nn)],o0);function Et(e,t){if(e!==void 0)try{return Wt.toColor(e)}catch{}return t}var QI=class{constructor(...e){this._entries=new Map;for(let[t,s]of e)this.set(t,s)}set(e,t){let s=this._entries.get(e);return this._entries.set(e,t),s}forEach(e){for(let[t,s]of this._entries.entries())e(t,s)}has(e){return this._entries.has(e)}get(e){return this._entries.get(e)}},ZI=class{constructor(){this._services=new QI,this._services.set(ov,this)}setService(e,t){this._services.set(e,t)}getService(e){return this._services.get(e)}createInstance(e,...t){let s=q9(e).sort((l,c)=>l.index-c.index),n=[];for(let l of s){let c=this._services.get(l.id);if(!c)throw new Error(`[createInstance] ${e.name} depends on UNKNOWN service ${l.id._id}.`);n.push(c)}let a=s.length>0?s[0].index:t.length;if(t.length!==a)throw new Error(`[createInstance] First service dependency of ${e.name} at position ${a+1} conflicts with ${t.length} static arguments`);return new e(...t,...n)}},eF={trace:0,debug:1,info:2,warn:3,error:4,off:5},tF="xterm.js: ",l0=class extends nt{constructor(e){super(),this._optionsService=e,this._logLevel=5,this._updateLogLevel(),this._register(this._optionsService.onSpecificOptionChange("logLevel",()=>this._updateLogLevel()))}get logLevel(){return this._logLevel}_updateLogLevel(){this._logLevel=eF[this._optionsService.rawOptions.logLevel]}_evalLazyOptionalParams(e){for(let t=0;t<e.length;t++)typeof e[t]=="function"&&(e[t]=e[t]())}_log(e,t,s){this._evalLazyOptionalParams(s),e.call(console,(this._optionsService.options.logger?"":tF)+t,...s)}trace(e,...t){var s;this._logLevel<=0&&this._log(((s=this._optionsService.options.logger)==null?void 0:s.trace.bind(this._optionsService.options.logger))??console.log,e,t)}debug(e,...t){var s;this._logLevel<=1&&this._log(((s=this._optionsService.options.logger)==null?void 0:s.debug.bind(this._optionsService.options.logger))??console.log,e,t)}info(e,...t){var s;this._logLevel<=2&&this._log(((s=this._optionsService.options.logger)==null?void 0:s.info.bind(this._optionsService.options.logger))??console.info,e,t)}warn(e,...t){var s;this._logLevel<=3&&this._log(((s=this._optionsService.options.logger)==null?void 0:s.warn.bind(this._optionsService.options.logger))??console.warn,e,t)}error(e,...t){var s;this._logLevel<=4&&this._log(((s=this._optionsService.options.logger)==null?void 0:s.error.bind(this._optionsService.options.logger))??console.error,e,t)}};l0=ts([Re(0,nn)],l0);var I2=class extends nt{constructor(e){super(),this._maxLength=e,this.onDeleteEmitter=this._register(new Ce),this.onDelete=this.onDeleteEmitter.event,this.onInsertEmitter=this._register(new Ce),this.onInsert=this.onInsertEmitter.event,this.onTrimEmitter=this._register(new Ce),this.onTrim=this.onTrimEmitter.event,this._array=new Array(this._maxLength),this._startIndex=0,this._length=0}get maxLength(){return this._maxLength}set maxLength(e){if(this._maxLength===e)return;let t=new Array(e);for(let s=0;s<Math.min(e,this.length);s++)t[s]=this._array[this._getCyclicIndex(s)];this._array=t,this._maxLength=e,this._startIndex=0}get length(){return this._length}set length(e){if(e>this._length)for(let t=this._length;t<e;t++)this._array[t]=void 0;this._length=e}get(e){return this._array[this._getCyclicIndex(e)]}set(e,t){this._array[this._getCyclicIndex(e)]=t}push(e){this._array[this._getCyclicIndex(this._length)]=e,this._length===this._maxLength?(this._startIndex=++this._startIndex%this._maxLength,this.onTrimEmitter.fire(1)):this._length++}recycle(){if(this._length!==this._maxLength)throw new Error("Can only recycle when the buffer is full");return this._startIndex=++this._startIndex%this._maxLength,this.onTrimEmitter.fire(1),this._array[this._getCyclicIndex(this._length-1)]}get isFull(){return this._length===this._maxLength}pop(){return this._array[this._getCyclicIndex(this._length---1)]}splice(e,t,...s){if(t){for(let n=e;n<this._length-t;n++)this._array[this._getCyclicIndex(n)]=this._array[this._getCyclicIndex(n+t)];this._length-=t,this.onDeleteEmitter.fire({index:e,amount:t})}for(let n=this._length-1;n>=e;n--)this._array[this._getCyclicIndex(n+s.length)]=this._array[this._getCyclicIndex(n)];for(let n=0;n<s.length;n++)this._array[this._getCyclicIndex(e+n)]=s[n];if(s.length&&this.onInsertEmitter.fire({index:e,amount:s.length}),this._length+s.length>this._maxLength){let n=this._length+s.length-this._maxLength;this._startIndex+=n,this._length=this._maxLength,this.onTrimEmitter.fire(n)}else this._length+=s.length}trimStart(e){e>this._length&&(e=this._length),this._startIndex+=e,this._length-=e,this.onTrimEmitter.fire(e)}shiftElements(e,t,s){if(!(t<=0)){if(e<0||e>=this._length)throw new Error("start argument out of range");if(e+s<0)throw new Error("Cannot shift elements in list beyond index 0");if(s>0){for(let a=t-1;a>=0;a--)this.set(e+a+s,this.get(e+a));let n=e+t+s-this._length;if(n>0)for(this._length+=n;this._length>this._maxLength;)this._length--,this._startIndex++,this.onTrimEmitter.fire(1)}else for(let n=0;n<t;n++)this.set(e+n+s,this.get(e+n))}}_getCyclicIndex(e){return(this._startIndex+e)%this._maxLength}},st=3,fs=Object.freeze(new pu),Zd=0,Ng=2,Ac=class _N{constructor(t,s,n=!1){this.isWrapped=n,this._combined={},this._extendedAttrs={},this._data=new Uint32Array(t*st);let a=s||Jn.fromCharData([0,$C,1,0]);for(let l=0;l<t;++l)this.setCell(l,a);this.length=t}get(t){let s=this._data[t*st+0],n=s&2097151;return[this._data[t*st+1],s&2097152?this._combined[t]:n?Fi(n):"",s>>22,s&2097152?this._combined[t].charCodeAt(this._combined[t].length-1):n]}set(t,s){this._data[t*st+1]=s[0],s[1].length>1?(this._combined[t]=s[1],this._data[t*st+0]=t|2097152|s[2]<<22):this._data[t*st+0]=s[1].charCodeAt(0)|s[2]<<22}getWidth(t){return this._data[t*st+0]>>22}hasWidth(t){return this._data[t*st+0]&12582912}getFg(t){return this._data[t*st+1]}getBg(t){return this._data[t*st+2]}hasContent(t){return this._data[t*st+0]&4194303}getCodePoint(t){let s=this._data[t*st+0];return s&2097152?this._combined[t].charCodeAt(this._combined[t].length-1):s&2097151}isCombined(t){return this._data[t*st+0]&2097152}getString(t){let s=this._data[t*st+0];return s&2097152?this._combined[t]:s&2097151?Fi(s&2097151):""}isProtected(t){return this._data[t*st+2]&536870912}loadCell(t,s){return Zd=t*st,s.content=this._data[Zd+0],s.fg=this._data[Zd+1],s.bg=this._data[Zd+2],s.content&2097152&&(s.combinedData=this._combined[t]),s.bg&268435456&&(s.extended=this._extendedAttrs[t]),s}setCell(t,s){s.content&2097152&&(this._combined[t]=s.combinedData),s.bg&268435456&&(this._extendedAttrs[t]=s.extended),this._data[t*st+0]=s.content,this._data[t*st+1]=s.fg,this._data[t*st+2]=s.bg}setCellFromCodepoint(t,s,n,a){a.bg&268435456&&(this._extendedAttrs[t]=a.extended),this._data[t*st+0]=s|n<<22,this._data[t*st+1]=a.fg,this._data[t*st+2]=a.bg}addCodepointToCell(t,s,n){let a=this._data[t*st+0];a&2097152?this._combined[t]+=Fi(s):a&2097151?(this._combined[t]=Fi(a&2097151)+Fi(s),a&=-2097152,a|=2097152):a=s|1<<22,n&&(a&=-12582913,a|=n<<22),this._data[t*st+0]=a}insertCells(t,s,n){if(t%=this.length,t&&this.getWidth(t-1)===2&&this.setCellFromCodepoint(t-1,0,1,n),s<this.length-t){let a=new Jn;for(let l=this.length-t-s-1;l>=0;--l)this.setCell(t+s+l,this.loadCell(t+l,a));for(let l=0;l<s;++l)this.setCell(t+l,n)}else for(let a=t;a<this.length;++a)this.setCell(a,n);this.getWidth(this.length-1)===2&&this.setCellFromCodepoint(this.length-1,0,1,n)}deleteCells(t,s,n){if(t%=this.length,s<this.length-t){let a=new Jn;for(let l=0;l<this.length-t-s;++l)this.setCell(t+l,this.loadCell(t+s+l,a));for(let l=this.length-s;l<this.length;++l)this.setCell(l,n)}else for(let a=t;a<this.length;++a)this.setCell(a,n);t&&this.getWidth(t-1)===2&&this.setCellFromCodepoint(t-1,0,1,n),this.getWidth(t)===0&&!this.hasContent(t)&&this.setCellFromCodepoint(t,0,1,n)}replaceCells(t,s,n,a=!1){if(a){for(t&&this.getWidth(t-1)===2&&!this.isProtected(t-1)&&this.setCellFromCodepoint(t-1,0,1,n),s<this.length&&this.getWidth(s-1)===2&&!this.isProtected(s)&&this.setCellFromCodepoint(s,0,1,n);t<s&&t<this.length;)this.isProtected(t)||this.setCell(t,n),t++;return}for(t&&this.getWidth(t-1)===2&&this.setCellFromCodepoint(t-1,0,1,n),s<this.length&&this.getWidth(s-1)===2&&this.setCellFromCodepoint(s,0,1,n);t<s&&t<this.length;)this.setCell(t++,n)}resize(t,s){if(t===this.length)return this._data.length*4*Ng<this._data.buffer.byteLength;let n=t*st;if(t>this.length){if(this._data.buffer.byteLength>=n*4)this._data=new Uint32Array(this._data.buffer,0,n);else{let a=new Uint32Array(n);a.set(this._data),this._data=a}for(let a=this.length;a<t;++a)this.setCell(a,s)}else{this._data=this._data.subarray(0,n);let a=Object.keys(this._combined);for(let c=0;c<a.length;c++){let d=parseInt(a[c],10);d>=t&&delete this._combined[d]}let l=Object.keys(this._extendedAttrs);for(let c=0;c<l.length;c++){let d=parseInt(l[c],10);d>=t&&delete this._extendedAttrs[d]}}return this.length=t,n*4*Ng<this._data.buffer.byteLength}cleanupMemory(){if(this._data.length*4*Ng<this._data.buffer.byteLength){let t=new Uint32Array(this._data.length);return t.set(this._data),this._data=t,1}return 0}fill(t,s=!1){if(s){for(let n=0;n<this.length;++n)this.isProtected(n)||this.setCell(n,t);return}this._combined={},this._extendedAttrs={};for(let n=0;n<this.length;++n)this.setCell(n,t)}copyFrom(t){this.length!==t.length?this._data=new Uint32Array(t._data):this._data.set(t._data),this.length=t.length,this._combined={};for(let s in t._combined)this._combined[s]=t._combined[s];this._extendedAttrs={};for(let s in t._extendedAttrs)this._extendedAttrs[s]=t._extendedAttrs[s];this.isWrapped=t.isWrapped}clone(){let t=new _N(0);t._data=new Uint32Array(this._data),t.length=this.length;for(let s in this._combined)t._combined[s]=this._combined[s];for(let s in this._extendedAttrs)t._extendedAttrs[s]=this._extendedAttrs[s];return t.isWrapped=this.isWrapped,t}getTrimmedLength(){for(let t=this.length-1;t>=0;--t)if(this._data[t*st+0]&4194303)return t+(this._data[t*st+0]>>22);return 0}getNoBgTrimmedLength(){for(let t=this.length-1;t>=0;--t)if(this._data[t*st+0]&4194303||this._data[t*st+2]&50331648)return t+(this._data[t*st+0]>>22);return 0}copyCellsFrom(t,s,n,a,l){let c=t._data;if(l)for(let f=a-1;f>=0;f--){for(let h=0;h<st;h++)this._data[(n+f)*st+h]=c[(s+f)*st+h];c[(s+f)*st+2]&268435456&&(this._extendedAttrs[n+f]=t._extendedAttrs[s+f])}else for(let f=0;f<a;f++){for(let h=0;h<st;h++)this._data[(n+f)*st+h]=c[(s+f)*st+h];c[(s+f)*st+2]&268435456&&(this._extendedAttrs[n+f]=t._extendedAttrs[s+f])}let d=Object.keys(t._combined);for(let f=0;f<d.length;f++){let h=parseInt(d[f],10);h>=s&&(this._combined[h-s+n]=t._combined[h])}}translateToString(t,s,n,a){s=s??0,n=n??this.length,t&&(n=Math.min(n,this.getTrimmedLength())),a&&(a.length=0);let l="";for(;s<n;){let c=this._data[s*st+0],d=c&2097151,f=c&2097152?this._combined[s]:d?Fi(d):Vi;if(l+=f,a)for(let h=0;h<f.length;++h)a.push(s);s+=c>>22||1}return a&&a.push(s),l}};function sF(e,t,s,n,a,l){let c=[];for(let d=0;d<e.length-1;d++){let f=d,h=e.get(++f);if(!h.isWrapped)continue;let m=[e.get(d)];for(;f<e.length&&h.isWrapped;)m.push(h),h=e.get(++f);if(!l&&n>=d&&n<f){d+=m.length-1;continue}let g=0,b=su(m,g,t),v=1,y=0;for(;v<m.length;){let j=su(m,v,t),k=j-y,E=s-b,N=Math.min(k,E);m[g].copyCellsFrom(m[v],y,b,N,!1),b+=N,b===s&&(g++,b=0),y+=N,y===j&&(v++,y=0),b===0&&g!==0&&m[g-1].getWidth(s-1)===2&&(m[g].copyCellsFrom(m[g-1],s-1,b++,1,!1),m[g-1].setCell(s-1,a))}m[g].replaceCells(b,s,a);let S=0;for(let j=m.length-1;j>0&&(j>g||m[j].getTrimmedLength()===0);j--)S++;S>0&&(c.push(d+m.length-S),c.push(S)),d+=m.length-1}return c}function nF(e,t){let s=[],n=0,a=t[n],l=0;for(let c=0;c<e.length;c++)if(a===c){let d=t[++n];e.onDeleteEmitter.fire({index:c-l,amount:d}),c+=d-1,l+=d,a=t[++n]}else s.push(c);return{layout:s,countRemoved:l}}function rF(e,t){let s=[];for(let n=0;n<t.length;n++)s.push(e.get(t[n]));for(let n=0;n<s.length;n++)e.set(n,s[n]);e.length=t.length}function iF(e,t,s){let n=[],a=e.map((f,h)=>su(e,h,t)).reduce((f,h)=>f+h),l=0,c=0,d=0;for(;d<a;){if(a-d<s){n.push(a-d);break}l+=s;let f=su(e,c,t);l>f&&(l-=f,c++);let h=e[c].getWidth(l-1)===2;h&&l--;let m=h?s-1:s;n.push(m),d+=m}return n}function su(e,t,s){if(t===e.length-1)return e[t].getTrimmedLength();let n=!e[t].hasContent(s-1)&&e[t].getWidth(s-1)===1,a=e[t+1].getWidth(0)===2;return n&&a?s-1:s}var yN=class wN{constructor(t){this.line=t,this.isDisposed=!1,this._disposables=[],this._id=wN._nextId++,this._onDispose=this.register(new Ce),this.onDispose=this._onDispose.event}get id(){return this._id}dispose(){this.isDisposed||(this.isDisposed=!0,this.line=-1,this._onDispose.fire(),Ra(this._disposables),this._disposables.length=0)}register(t){return this._disposables.push(t),t}};yN._nextId=1;var aF=yN,Ss={},Sa=Ss.B;Ss[0]={"`":"◆",a:"▒",b:"␉",c:"␌",d:"␍",e:"␊",f:"°",g:"±",h:"",i:"␋",j:"┘",k:"┐",l:"┌",m:"└",n:"┼",o:"⎺",p:"⎻",q:"─",r:"⎼",s:"⎽",t:"├",u:"┤",v:"┴",w:"┬",x:"│",y:"≤",z:"≥","{":"π","|":"≠","}":"£","~":"·"};Ss.A={"#":"£"};Ss.B=void 0;Ss[4]={"#":"£","@":"¾","[":"ij","\\":"½","]":"|","{":"¨","|":"f","}":"¼","~":"´"};Ss.C=Ss[5]={"[":"Ä","\\":"Ö","]":"Å","^":"Ü","`":"é","{":"ä","|":"ö","}":"å","~":"ü"};Ss.R={"#":"£","@":"à","[":"°","\\":"ç","]":"§","{":"é","|":"ù","}":"è","~":"¨"};Ss.Q={"@":"à","[":"â","\\":"ç","]":"ê","^":"î","`":"ô","{":"é","|":"ù","}":"è","~":"û"};Ss.K={"@":"§","[":"Ä","\\":"Ö","]":"Ü","{":"ä","|":"ö","}":"ü","~":"ß"};Ss.Y={"#":"£","@":"§","[":"°","\\":"ç","]":"é","`":"ù","{":"à","|":"ò","}":"è","~":"ì"};Ss.E=Ss[6]={"@":"Ä","[":"Æ","\\":"Ø","]":"Å","^":"Ü","`":"ä","{":"æ","|":"ø","}":"å","~":"ü"};Ss.Z={"#":"£","@":"§","[":"¡","\\":"Ñ","]":"¿","{":"°","|":"ñ","}":"ç"};Ss.H=Ss[7]={"@":"É","[":"Ä","\\":"Ö","]":"Å","^":"Ü","`":"é","{":"ä","|":"ö","}":"å","~":"ü"};Ss["="]={"#":"ù","@":"à","[":"é","\\":"ç","]":"ê","^":"î",_:"è","`":"ô","{":"ä","|":"ö","}":"ü","~":"û"};var F2=4294967295,H2=class{constructor(e,t,s){this._hasScrollback=e,this._optionsService=t,this._bufferService=s,this.ydisp=0,this.ybase=0,this.y=0,this.x=0,this.tabs={},this.savedY=0,this.savedX=0,this.savedCurAttrData=fs.clone(),this.savedCharset=Sa,this.markers=[],this._nullCell=Jn.fromCharData([0,$C,1,0]),this._whitespaceCell=Jn.fromCharData([0,Vi,1,32]),this._isClearing=!1,this._memoryCleanupQueue=new Fh,this._memoryCleanupPosition=0,this._cols=this._bufferService.cols,this._rows=this._bufferService.rows,this.lines=new I2(this._getCorrectBufferLength(this._rows)),this.scrollTop=0,this.scrollBottom=this._rows-1,this.setupTabStops()}getNullCell(e){return e?(this._nullCell.fg=e.fg,this._nullCell.bg=e.bg,this._nullCell.extended=e.extended):(this._nullCell.fg=0,this._nullCell.bg=0,this._nullCell.extended=new zh),this._nullCell}getWhitespaceCell(e){return e?(this._whitespaceCell.fg=e.fg,this._whitespaceCell.bg=e.bg,this._whitespaceCell.extended=e.extended):(this._whitespaceCell.fg=0,this._whitespaceCell.bg=0,this._whitespaceCell.extended=new zh),this._whitespaceCell}getBlankLine(e,t){return new Ac(this._bufferService.cols,this.getNullCell(e),t)}get hasScrollback(){return this._hasScrollback&&this.lines.maxLength>this._rows}get isCursorInViewport(){let e=this.ybase+this.y-this.ydisp;return e>=0&&e<this._rows}_getCorrectBufferLength(e){if(!this._hasScrollback)return e;let t=e+this._optionsService.rawOptions.scrollback;return t>F2?F2:t}fillViewportRows(e){if(this.lines.length===0){e===void 0&&(e=fs);let t=this._rows;for(;t--;)this.lines.push(this.getBlankLine(e))}}clear(){this.ydisp=0,this.ybase=0,this.y=0,this.x=0,this.lines=new I2(this._getCorrectBufferLength(this._rows)),this.scrollTop=0,this.scrollBottom=this._rows-1,this.setupTabStops()}resize(e,t){let s=this.getNullCell(fs),n=0,a=this._getCorrectBufferLength(t);if(a>this.lines.maxLength&&(this.lines.maxLength=a),this.lines.length>0){if(this._cols<e)for(let c=0;c<this.lines.length;c++)n+=+this.lines.get(c).resize(e,s);let l=0;if(this._rows<t)for(let c=this._rows;c<t;c++)this.lines.length<t+this.ybase&&(this._optionsService.rawOptions.windowsMode||this._optionsService.rawOptions.windowsPty.backend!==void 0||this._optionsService.rawOptions.windowsPty.buildNumber!==void 0?this.lines.push(new Ac(e,s)):this.ybase>0&&this.lines.length<=this.ybase+this.y+l+1?(this.ybase--,l++,this.ydisp>0&&this.ydisp--):this.lines.push(new Ac(e,s)));else for(let c=this._rows;c>t;c--)this.lines.length>t+this.ybase&&(this.lines.length>this.ybase+this.y+1?this.lines.pop():(this.ybase++,this.ydisp++));if(a<this.lines.maxLength){let c=this.lines.length-a;c>0&&(this.lines.trimStart(c),this.ybase=Math.max(this.ybase-c,0),this.ydisp=Math.max(this.ydisp-c,0),this.savedY=Math.max(this.savedY-c,0)),this.lines.maxLength=a}this.x=Math.min(this.x,e-1),this.y=Math.min(this.y,t-1),l&&(this.y+=l),this.savedX=Math.min(this.savedX,e-1),this.scrollTop=0}if(this.scrollBottom=t-1,this._isReflowEnabled&&(this._reflow(e,t),this._cols>e))for(let l=0;l<this.lines.length;l++)n+=+this.lines.get(l).resize(e,s);this._cols=e,this._rows=t,this._memoryCleanupQueue.clear(),n>.1*this.lines.length&&(this._memoryCleanupPosition=0,this._memoryCleanupQueue.enqueue(()=>this._batchedMemoryCleanup()))}_batchedMemoryCleanup(){let e=!0;this._memoryCleanupPosition>=this.lines.length&&(this._memoryCleanupPosition=0,e=!1);let t=0;for(;this._memoryCleanupPosition<this.lines.length;)if(t+=this.lines.get(this._memoryCleanupPosition++).cleanupMemory(),t>100)return!0;return e}get _isReflowEnabled(){let e=this._optionsService.rawOptions.windowsPty;return e&&e.buildNumber?this._hasScrollback&&e.backend==="conpty"&&e.buildNumber>=21376:this._hasScrollback&&!this._optionsService.rawOptions.windowsMode}_reflow(e,t){this._cols!==e&&(e>this._cols?this._reflowLarger(e,t):this._reflowSmaller(e,t))}_reflowLarger(e,t){let s=this._optionsService.rawOptions.reflowCursorLine,n=sF(this.lines,this._cols,e,this.ybase+this.y,this.getNullCell(fs),s);if(n.length>0){let a=nF(this.lines,n);rF(this.lines,a.layout),this._reflowLargerAdjustViewport(e,t,a.countRemoved)}}_reflowLargerAdjustViewport(e,t,s){let n=this.getNullCell(fs),a=s;for(;a-- >0;)this.ybase===0?(this.y>0&&this.y--,this.lines.length<t&&this.lines.push(new Ac(e,n))):(this.ydisp===this.ybase&&this.ydisp--,this.ybase--);this.savedY=Math.max(this.savedY-s,0)}_reflowSmaller(e,t){let s=this._optionsService.rawOptions.reflowCursorLine,n=this.getNullCell(fs),a=[],l=0;for(let c=this.lines.length-1;c>=0;c--){let d=this.lines.get(c);if(!d||!d.isWrapped&&d.getTrimmedLength()<=e)continue;let f=[d];for(;d.isWrapped&&c>0;)d=this.lines.get(--c),f.unshift(d);if(!s){let N=this.ybase+this.y;if(N>=c&&N<c+f.length)continue}let h=f[f.length-1].getTrimmedLength(),m=iF(f,this._cols,e),g=m.length-f.length,b;this.ybase===0&&this.y!==this.lines.length-1?b=Math.max(0,this.y-this.lines.maxLength+g):b=Math.max(0,this.lines.length-this.lines.maxLength+g);let v=[];for(let N=0;N<g;N++){let B=this.getBlankLine(fs,!0);v.push(B)}v.length>0&&(a.push({start:c+f.length+l,newLines:v}),l+=v.length),f.push(...v);let y=m.length-1,S=m[y];S===0&&(y--,S=m[y]);let j=f.length-g-1,k=h;for(;j>=0;){let N=Math.min(k,S);if(f[y]===void 0)break;if(f[y].copyCellsFrom(f[j],k-N,S-N,N,!0),S-=N,S===0&&(y--,S=m[y]),k-=N,k===0){j--;let B=Math.max(j,0);k=su(f,B,this._cols)}}for(let N=0;N<f.length;N++)m[N]<e&&f[N].setCell(m[N],n);let E=g-b;for(;E-- >0;)this.ybase===0?this.y<t-1?(this.y++,this.lines.pop()):(this.ybase++,this.ydisp++):this.ybase<Math.min(this.lines.maxLength,this.lines.length+l)-t&&(this.ybase===this.ydisp&&this.ydisp++,this.ybase++);this.savedY=Math.min(this.savedY+g,this.ybase+t-1)}if(a.length>0){let c=[],d=[];for(let S=0;S<this.lines.length;S++)d.push(this.lines.get(S));let f=this.lines.length,h=f-1,m=0,g=a[m];this.lines.length=Math.min(this.lines.maxLength,this.lines.length+l);let b=0;for(let S=Math.min(this.lines.maxLength-1,f+l-1);S>=0;S--)if(g&&g.start>h+b){for(let j=g.newLines.length-1;j>=0;j--)this.lines.set(S--,g.newLines[j]);S++,c.push({index:h+1,amount:g.newLines.length}),b+=g.newLines.length,g=a[++m]}else this.lines.set(S,d[h--]);let v=0;for(let S=c.length-1;S>=0;S--)c[S].index+=v,this.lines.onInsertEmitter.fire(c[S]),v+=c[S].amount;let y=Math.max(0,f+l-this.lines.maxLength);y>0&&this.lines.onTrimEmitter.fire(y)}}translateBufferLineToString(e,t,s=0,n){let a=this.lines.get(e);return a?a.translateToString(t,s,n):""}getWrappedRangeForLine(e){let t=e,s=e;for(;t>0&&this.lines.get(t).isWrapped;)t--;for(;s+1<this.lines.length&&this.lines.get(s+1).isWrapped;)s++;return{first:t,last:s}}setupTabStops(e){for(e!=null?this.tabs[e]||(e=this.prevStop(e)):(this.tabs={},e=0);e<this._cols;e+=this._optionsService.rawOptions.tabStopWidth)this.tabs[e]=!0}prevStop(e){for(e==null&&(e=this.x);!this.tabs[--e]&&e>0;);return e>=this._cols?this._cols-1:e<0?0:e}nextStop(e){for(e==null&&(e=this.x);!this.tabs[++e]&&e<this._cols;);return e>=this._cols?this._cols-1:e<0?0:e}clearMarkers(e){this._isClearing=!0;for(let t=0;t<this.markers.length;t++)this.markers[t].line===e&&(this.markers[t].dispose(),this.markers.splice(t--,1));this._isClearing=!1}clearAllMarkers(){this._isClearing=!0;for(let e=0;e<this.markers.length;e++)this.markers[e].dispose();this.markers.length=0,this._isClearing=!1}addMarker(e){let t=new aF(e);return this.markers.push(t),t.register(this.lines.onTrim(s=>{t.line-=s,t.line<0&&t.dispose()})),t.register(this.lines.onInsert(s=>{t.line>=s.index&&(t.line+=s.amount)})),t.register(this.lines.onDelete(s=>{t.line>=s.index&&t.line<s.index+s.amount&&t.dispose(),t.line>s.index&&(t.line-=s.amount)})),t.register(t.onDispose(()=>this._removeMarker(t))),t}_removeMarker(e){this._isClearing||this.markers.splice(this.markers.indexOf(e),1)}},oF=class extends nt{constructor(e,t){super(),this._optionsService=e,this._bufferService=t,this._onBufferActivate=this._register(new Ce),this.onBufferActivate=this._onBufferActivate.event,this.reset(),this._register(this._optionsService.onSpecificOptionChange("scrollback",()=>this.resize(this._bufferService.cols,this._bufferService.rows))),this._register(this._optionsService.onSpecificOptionChange("tabStopWidth",()=>this.setupTabStops()))}reset(){this._normal=new H2(!0,this._optionsService,this._bufferService),this._normal.fillViewportRows(),this._alt=new H2(!1,this._optionsService,this._bufferService),this._activeBuffer=this._normal,this._onBufferActivate.fire({activeBuffer:this._normal,inactiveBuffer:this._alt}),this.setupTabStops()}get alt(){return this._alt}get active(){return this._activeBuffer}get normal(){return this._normal}activateNormalBuffer(){this._activeBuffer!==this._normal&&(this._normal.x=this._alt.x,this._normal.y=this._alt.y,this._alt.clearAllMarkers(),this._alt.clear(),this._activeBuffer=this._normal,this._onBufferActivate.fire({activeBuffer:this._normal,inactiveBuffer:this._alt}))}activateAltBuffer(e){this._activeBuffer!==this._alt&&(this._alt.fillViewportRows(e),this._alt.x=this._normal.x,this._alt.y=this._normal.y,this._activeBuffer=this._alt,this._onBufferActivate.fire({activeBuffer:this._alt,inactiveBuffer:this._normal}))}resize(e,t){this._normal.resize(e,t),this._alt.resize(e,t),this.setupTabStops(e)}setupTabStops(e){this._normal.setupTabStops(e),this._alt.setupTabStops(e)}},SN=2,jN=1,c0=class extends nt{constructor(e){super(),this.isUserScrolling=!1,this._onResize=this._register(new Ce),this.onResize=this._onResize.event,this._onScroll=this._register(new Ce),this.onScroll=this._onScroll.event,this.cols=Math.max(e.rawOptions.cols||0,SN),this.rows=Math.max(e.rawOptions.rows||0,jN),this.buffers=this._register(new oF(e,this)),this._register(this.buffers.onBufferActivate(t=>{this._onScroll.fire(t.activeBuffer.ydisp)}))}get buffer(){return this.buffers.active}resize(e,t){let s=this.cols!==e,n=this.rows!==t;this.cols=e,this.rows=t,this.buffers.resize(e,t),this._onResize.fire({cols:e,rows:t,colsChanged:s,rowsChanged:n})}reset(){this.buffers.reset(),this.isUserScrolling=!1}scroll(e,t=!1){let s=this.buffer,n;n=this._cachedBlankLine,(!n||n.length!==this.cols||n.getFg(0)!==e.fg||n.getBg(0)!==e.bg)&&(n=s.getBlankLine(e,t),this._cachedBlankLine=n),n.isWrapped=t;let a=s.ybase+s.scrollTop,l=s.ybase+s.scrollBottom;if(s.scrollTop===0){let c=s.lines.isFull;l===s.lines.length-1?c?s.lines.recycle().copyFrom(n):s.lines.push(n.clone()):s.lines.splice(l+1,0,n.clone()),c?this.isUserScrolling&&(s.ydisp=Math.max(s.ydisp-1,0)):(s.ybase++,this.isUserScrolling||s.ydisp++)}else{let c=l-a+1;s.lines.shiftElements(a+1,c-1,-1),s.lines.set(l,n.clone())}this.isUserScrolling||(s.ydisp=s.ybase),this._onScroll.fire(s.ydisp)}scrollLines(e,t){let s=this.buffer;if(e<0){if(s.ydisp===0)return;this.isUserScrolling=!0}else e+s.ydisp>=s.ybase&&(this.isUserScrolling=!1);let n=s.ydisp;s.ydisp=Math.max(Math.min(s.ydisp+e,s.ybase),0),n!==s.ydisp&&(t||this._onScroll.fire(s.ydisp))}};c0=ts([Re(0,nn)],c0);var Mo={cols:80,rows:24,cursorBlink:!1,cursorStyle:"block",cursorWidth:1,cursorInactiveStyle:"outline",customGlyphs:!0,drawBoldTextInBrightColors:!0,documentOverride:null,fastScrollModifier:"alt",fastScrollSensitivity:5,fontFamily:"monospace",fontSize:15,fontWeight:"normal",fontWeightBold:"bold",ignoreBracketedPasteMode:!1,lineHeight:1,letterSpacing:0,linkHandler:null,logLevel:"info",logger:null,scrollback:1e3,scrollOnEraseInDisplay:!1,scrollOnUserInput:!0,scrollSensitivity:1,screenReaderMode:!1,smoothScrollDuration:0,macOptionIsMeta:!1,macOptionClickForcesSelection:!1,minimumContrastRatio:1,disableStdin:!1,allowProposedApi:!1,allowTransparency:!1,tabStopWidth:8,theme:{},reflowCursorLine:!1,rescaleOverlappingGlyphs:!1,rightClickSelectsWord:Ih,windowOptions:{},windowsMode:!1,windowsPty:{},wordSeparator:" ()[]{}',\"`",altClickMovesCursor:!0,convertEol:!1,termName:"xterm",cancelEvents:!1,overviewRuler:{}},lF=["normal","bold","100","200","300","400","500","600","700","800","900"],cF=class extends nt{constructor(e){super(),this._onOptionChange=this._register(new Ce),this.onOptionChange=this._onOptionChange.event;let t={...Mo};for(let s in e)if(s in t)try{let n=e[s];t[s]=this._sanitizeAndValidateOption(s,n)}catch(n){console.error(n)}this.rawOptions=t,this.options={...t},this._setupOptions(),this._register(Ut(()=>{this.rawOptions.linkHandler=null,this.rawOptions.documentOverride=null}))}onSpecificOptionChange(e,t){return this.onOptionChange(s=>{s===e&&t(this.rawOptions[e])})}onMultipleOptionChange(e,t){return this.onOptionChange(s=>{e.indexOf(s)!==-1&&t()})}_setupOptions(){let e=s=>{if(!(s in Mo))throw new Error(`No option with key "${s}"`);return this.rawOptions[s]},t=(s,n)=>{if(!(s in Mo))throw new Error(`No option with key "${s}"`);n=this._sanitizeAndValidateOption(s,n),this.rawOptions[s]!==n&&(this.rawOptions[s]=n,this._onOptionChange.fire(s))};for(let s in this.rawOptions){let n={get:e.bind(this,s),set:t.bind(this,s)};Object.defineProperty(this.options,s,n)}}_sanitizeAndValidateOption(e,t){switch(e){case"cursorStyle":if(t||(t=Mo[e]),!uF(t))throw new Error(`"${t}" is not a valid value for ${e}`);break;case"wordSeparator":t||(t=Mo[e]);break;case"fontWeight":case"fontWeightBold":if(typeof t=="number"&&1<=t&&t<=1e3)break;t=lF.includes(t)?t:Mo[e];break;case"cursorWidth":t=Math.floor(t);case"lineHeight":case"tabStopWidth":if(t<1)throw new Error(`${e} cannot be less than 1, value: ${t}`);break;case"minimumContrastRatio":t=Math.max(1,Math.min(21,Math.round(t*10)/10));break;case"scrollback":if(t=Math.min(t,4294967295),t<0)throw new Error(`${e} cannot be less than 0, value: ${t}`);break;case"fastScrollSensitivity":case"scrollSensitivity":if(t<=0)throw new Error(`${e} cannot be less than or equal to 0, value: ${t}`);break;case"rows":case"cols":if(!t&&t!==0)throw new Error(`${e} must be numeric, value: ${t}`);break;case"windowsPty":t=t??{};break}return t}};function uF(e){return e==="block"||e==="underline"||e==="bar"}function Rc(e,t=5){if(typeof e!="object")return e;let s=Array.isArray(e)?[]:{};for(let n in e)s[n]=t<=1?e[n]:e[n]&&Rc(e[n],t-1);return s}var U2=Object.freeze({insertMode:!1}),V2=Object.freeze({applicationCursorKeys:!1,applicationKeypad:!1,bracketedPasteMode:!1,cursorBlink:void 0,cursorStyle:void 0,origin:!1,reverseWraparound:!1,sendFocus:!1,synchronizedOutput:!1,wraparound:!0}),u0=class extends nt{constructor(e,t,s){super(),this._bufferService=e,this._logService=t,this._optionsService=s,this.isCursorInitialized=!1,this.isCursorHidden=!1,this._onData=this._register(new Ce),this.onData=this._onData.event,this._onUserInput=this._register(new Ce),this.onUserInput=this._onUserInput.event,this._onBinary=this._register(new Ce),this.onBinary=this._onBinary.event,this._onRequestScrollToBottom=this._register(new Ce),this.onRequestScrollToBottom=this._onRequestScrollToBottom.event,this.modes=Rc(U2),this.decPrivateModes=Rc(V2)}reset(){this.modes=Rc(U2),this.decPrivateModes=Rc(V2)}triggerDataEvent(e,t=!1){if(this._optionsService.rawOptions.disableStdin)return;let s=this._bufferService.buffer;t&&this._optionsService.rawOptions.scrollOnUserInput&&s.ybase!==s.ydisp&&this._onRequestScrollToBottom.fire(),t&&this._onUserInput.fire(),this._logService.debug(`sending data "${e}"`),this._logService.trace("sending data (codes)",()=>e.split("").map(n=>n.charCodeAt(0))),this._onData.fire(e)}triggerBinaryEvent(e){this._optionsService.rawOptions.disableStdin||(this._logService.debug(`sending binary "${e}"`),this._logService.trace("sending binary (codes)",()=>e.split("").map(t=>t.charCodeAt(0))),this._onBinary.fire(e))}};u0=ts([Re(0,sn),Re(1,VC),Re(2,nn)],u0);var W2={NONE:{events:0,restrict:()=>!1},X10:{events:1,restrict:e=>e.button===4||e.action!==1?!1:(e.ctrl=!1,e.alt=!1,e.shift=!1,!0)},VT200:{events:19,restrict:e=>e.action!==32},DRAG:{events:23,restrict:e=>!(e.action===32&&e.button===3)},ANY:{events:31,restrict:e=>!0}};function Eg(e,t){let s=(e.ctrl?16:0)|(e.shift?4:0)|(e.alt?8:0);return e.button===4?(s|=64,s|=e.action):(s|=e.button&3,e.button&4&&(s|=64),e.button&8&&(s|=128),e.action===32?s|=32:e.action===0&&!t&&(s|=3)),s}var Mg=String.fromCharCode,q2={DEFAULT:e=>{let t=[Eg(e,!1)+32,e.col+32,e.row+32];return t[0]>255||t[1]>255||t[2]>255?"":`\x1B[M${Mg(t[0])}${Mg(t[1])}${Mg(t[2])}`},SGR:e=>{let t=e.action===0&&e.button!==4?"m":"M";return`\x1B[<${Eg(e,!0)};${e.col};${e.row}${t}`},SGR_PIXELS:e=>{let t=e.action===0&&e.button!==4?"m":"M";return`\x1B[<${Eg(e,!0)};${e.x};${e.y}${t}`}},d0=class extends nt{constructor(e,t,s){super(),this._bufferService=e,this._coreService=t,this._optionsService=s,this._protocols={},this._encodings={},this._activeProtocol="",this._activeEncoding="",this._lastEvent=null,this._wheelPartialScroll=0,this._onProtocolChange=this._register(new Ce),this.onProtocolChange=this._onProtocolChange.event;for(let n of Object.keys(W2))this.addProtocol(n,W2[n]);for(let n of Object.keys(q2))this.addEncoding(n,q2[n]);this.reset()}addProtocol(e,t){this._protocols[e]=t}addEncoding(e,t){this._encodings[e]=t}get activeProtocol(){return this._activeProtocol}get areMouseEventsActive(){return this._protocols[this._activeProtocol].events!==0}set activeProtocol(e){if(!this._protocols[e])throw new Error(`unknown protocol "${e}"`);this._activeProtocol=e,this._onProtocolChange.fire(this._protocols[e].events)}get activeEncoding(){return this._activeEncoding}set activeEncoding(e){if(!this._encodings[e])throw new Error(`unknown encoding "${e}"`);this._activeEncoding=e}reset(){this.activeProtocol="NONE",this.activeEncoding="DEFAULT",this._lastEvent=null,this._wheelPartialScroll=0}consumeWheelEvent(e,t,s){if(e.deltaY===0||e.shiftKey||t===void 0||s===void 0)return 0;let n=t/s,a=this._applyScrollModifier(e.deltaY,e);return e.deltaMode===WheelEvent.DOM_DELTA_PIXEL?(a/=n+0,Math.abs(e.deltaY)<50&&(a*=.3),this._wheelPartialScroll+=a,a=Math.floor(Math.abs(this._wheelPartialScroll))*(this._wheelPartialScroll>0?1:-1),this._wheelPartialScroll%=1):e.deltaMode===WheelEvent.DOM_DELTA_PAGE&&(a*=this._bufferService.rows),a}_applyScrollModifier(e,t){return t.altKey||t.ctrlKey||t.shiftKey?e*this._optionsService.rawOptions.fastScrollSensitivity*this._optionsService.rawOptions.scrollSensitivity:e*this._optionsService.rawOptions.scrollSensitivity}triggerMouseEvent(e){if(e.col<0||e.col>=this._bufferService.cols||e.row<0||e.row>=this._bufferService.rows||e.button===4&&e.action===32||e.button===3&&e.action!==32||e.button!==4&&(e.action===2||e.action===3)||(e.col++,e.row++,e.action===32&&this._lastEvent&&this._equalEvents(this._lastEvent,e,this._activeEncoding==="SGR_PIXELS"))||!this._protocols[this._activeProtocol].restrict(e))return!1;let t=this._encodings[this._activeEncoding](e);return t&&(this._activeEncoding==="DEFAULT"?this._coreService.triggerBinaryEvent(t):this._coreService.triggerDataEvent(t,!0)),this._lastEvent=e,!0}explainEvents(e){return{down:!!(e&1),up:!!(e&2),drag:!!(e&4),move:!!(e&8),wheel:!!(e&16)}}_equalEvents(e,t,s){if(s){if(e.x!==t.x||e.y!==t.y)return!1}else if(e.col!==t.col||e.row!==t.row)return!1;return!(e.button!==t.button||e.action!==t.action||e.ctrl!==t.ctrl||e.alt!==t.alt||e.shift!==t.shift)}};d0=ts([Re(0,sn),Re(1,Ba),Re(2,nn)],d0);var Tg=[[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]],dF=[[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]],_s;function hF(e,t){let s=0,n=t.length-1,a;if(e<t[0][0]||e>t[n][1])return!1;for(;n>=s;)if(a=s+n>>1,e>t[a][1])s=a+1;else if(e<t[a][0])n=a-1;else return!0;return!1}var fF=class{constructor(){if(this.version="6",!_s){_s=new Uint8Array(65536),_s.fill(1),_s[0]=0,_s.fill(0,1,32),_s.fill(0,127,160),_s.fill(2,4352,4448),_s[9001]=2,_s[9002]=2,_s.fill(2,11904,42192),_s[12351]=1,_s.fill(2,44032,55204),_s.fill(2,63744,64256),_s.fill(2,65040,65050),_s.fill(2,65072,65136),_s.fill(2,65280,65377),_s.fill(2,65504,65511);for(let e=0;e<Tg.length;++e)_s.fill(0,Tg[e][0],Tg[e][1]+1)}}wcwidth(e){return e<32?0:e<127?1:e<65536?_s[e]:hF(e,dF)?0:e>=131072&&e<=196605||e>=196608&&e<=262141?2:1}charProperties(e,t){let s=this.wcwidth(e),n=s===0&&t!==0;if(n){let a=ja.extractWidth(t);a===0?n=!1:a>s&&(s=a)}return ja.createPropertyValue(0,s,n)}},ja=class fh{constructor(){this._providers=Object.create(null),this._active="",this._onChange=new Ce,this.onChange=this._onChange.event;let t=new fF;this.register(t),this._active=t.version,this._activeProvider=t}static extractShouldJoin(t){return(t&1)!==0}static extractWidth(t){return t>>1&3}static extractCharKind(t){return t>>3}static createPropertyValue(t,s,n=!1){return(t&16777215)<<3|(s&3)<<1|(n?1:0)}dispose(){this._onChange.dispose()}get versions(){return Object.keys(this._providers)}get activeVersion(){return this._active}set activeVersion(t){if(!this._providers[t])throw new Error(`unknown Unicode version "${t}"`);this._active=t,this._activeProvider=this._providers[t],this._onChange.fire(t)}register(t){this._providers[t.version]=t}wcwidth(t){return this._activeProvider.wcwidth(t)}getStringCellWidth(t){let s=0,n=0,a=t.length;for(let l=0;l<a;++l){let c=t.charCodeAt(l);if(55296<=c&&c<=56319){if(++l>=a)return s+this.wcwidth(c);let h=t.charCodeAt(l);56320<=h&&h<=57343?c=(c-55296)*1024+h-56320+65536:s+=this.wcwidth(h)}let d=this.charProperties(c,n),f=fh.extractWidth(d);fh.extractShouldJoin(d)&&(f-=fh.extractWidth(n)),s+=f,n=d}return s}charProperties(t,s){return this._activeProvider.charProperties(t,s)}},pF=class{constructor(){this.glevel=0,this._charsets=[]}reset(){this.charset=void 0,this._charsets=[],this.glevel=0}setgLevel(e){this.glevel=e,this.charset=this._charsets[e]}setgCharset(e,t){this._charsets[e]=t,this.glevel===e&&(this.charset=t)}};function G2(e){var n;let t=(n=e.buffer.lines.get(e.buffer.ybase+e.buffer.y-1))==null?void 0:n.get(e.cols-1),s=e.buffer.lines.get(e.buffer.ybase+e.buffer.y);s&&t&&(s.isWrapped=t[3]!==0&&t[3]!==32)}var pc=2147483647,mF=256,kN=class h0{constructor(t=32,s=32){if(this.maxLength=t,this.maxSubParamsLength=s,s>mF)throw new Error("maxSubParamsLength must not be greater than 256");this.params=new Int32Array(t),this.length=0,this._subParams=new Int32Array(s),this._subParamsLength=0,this._subParamsIdx=new Uint16Array(t),this._rejectDigits=!1,this._rejectSubDigits=!1,this._digitIsSub=!1}static fromArray(t){let s=new h0;if(!t.length)return s;for(let n=Array.isArray(t[0])?1:0;n<t.length;++n){let a=t[n];if(Array.isArray(a))for(let l=0;l<a.length;++l)s.addSubParam(a[l]);else s.addParam(a)}return s}clone(){let t=new h0(this.maxLength,this.maxSubParamsLength);return t.params.set(this.params),t.length=this.length,t._subParams.set(this._subParams),t._subParamsLength=this._subParamsLength,t._subParamsIdx.set(this._subParamsIdx),t._rejectDigits=this._rejectDigits,t._rejectSubDigits=this._rejectSubDigits,t._digitIsSub=this._digitIsSub,t}toArray(){let t=[];for(let s=0;s<this.length;++s){t.push(this.params[s]);let n=this._subParamsIdx[s]>>8,a=this._subParamsIdx[s]&255;a-n>0&&t.push(Array.prototype.slice.call(this._subParams,n,a))}return t}reset(){this.length=0,this._subParamsLength=0,this._rejectDigits=!1,this._rejectSubDigits=!1,this._digitIsSub=!1}addParam(t){if(this._digitIsSub=!1,this.length>=this.maxLength){this._rejectDigits=!0;return}if(t<-1)throw new Error("values lesser than -1 are not allowed");this._subParamsIdx[this.length]=this._subParamsLength<<8|this._subParamsLength,this.params[this.length++]=t>pc?pc:t}addSubParam(t){if(this._digitIsSub=!0,!!this.length){if(this._rejectDigits||this._subParamsLength>=this.maxSubParamsLength){this._rejectSubDigits=!0;return}if(t<-1)throw new Error("values lesser than -1 are not allowed");this._subParams[this._subParamsLength++]=t>pc?pc:t,this._subParamsIdx[this.length-1]++}}hasSubParams(t){return(this._subParamsIdx[t]&255)-(this._subParamsIdx[t]>>8)>0}getSubParams(t){let s=this._subParamsIdx[t]>>8,n=this._subParamsIdx[t]&255;return n-s>0?this._subParams.subarray(s,n):null}getSubParamsAll(){let t={};for(let s=0;s<this.length;++s){let n=this._subParamsIdx[s]>>8,a=this._subParamsIdx[s]&255;a-n>0&&(t[s]=this._subParams.slice(n,a))}return t}addDigit(t){let s;if(this._rejectDigits||!(s=this._digitIsSub?this._subParamsLength:this.length)||this._digitIsSub&&this._rejectSubDigits)return;let n=this._digitIsSub?this._subParams:this.params,a=n[s-1];n[s-1]=~a?Math.min(a*10+t,pc):t}},mc=[],gF=class{constructor(){this._state=0,this._active=mc,this._id=-1,this._handlers=Object.create(null),this._handlerFb=()=>{},this._stack={paused:!1,loopPosition:0,fallThrough:!1}}registerHandler(e,t){this._handlers[e]===void 0&&(this._handlers[e]=[]);let s=this._handlers[e];return s.push(t),{dispose:()=>{let n=s.indexOf(t);n!==-1&&s.splice(n,1)}}}clearHandler(e){this._handlers[e]&&delete this._handlers[e]}setHandlerFallback(e){this._handlerFb=e}dispose(){this._handlers=Object.create(null),this._handlerFb=()=>{},this._active=mc}reset(){if(this._state===2)for(let e=this._stack.paused?this._stack.loopPosition-1:this._active.length-1;e>=0;--e)this._active[e].end(!1);this._stack.paused=!1,this._active=mc,this._id=-1,this._state=0}_start(){if(this._active=this._handlers[this._id]||mc,!this._active.length)this._handlerFb(this._id,"START");else for(let e=this._active.length-1;e>=0;e--)this._active[e].start()}_put(e,t,s){if(!this._active.length)this._handlerFb(this._id,"PUT",tf(e,t,s));else for(let n=this._active.length-1;n>=0;n--)this._active[n].put(e,t,s)}start(){this.reset(),this._state=1}put(e,t,s){if(this._state!==3){if(this._state===1)for(;t<s;){let n=e[t++];if(n===59){this._state=2,this._start();break}if(n<48||57<n){this._state=3;return}this._id===-1&&(this._id=0),this._id=this._id*10+n-48}this._state===2&&s-t>0&&this._put(e,t,s)}}end(e,t=!0){if(this._state!==0){if(this._state!==3)if(this._state===1&&this._start(),!this._active.length)this._handlerFb(this._id,"END",e);else{let s=!1,n=this._active.length-1,a=!1;if(this._stack.paused&&(n=this._stack.loopPosition-1,s=t,a=this._stack.fallThrough,this._stack.paused=!1),!a&&s===!1){for(;n>=0&&(s=this._active[n].end(e),s!==!0);n--)if(s instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=n,this._stack.fallThrough=!1,s;n--}for(;n>=0;n--)if(s=this._active[n].end(!1),s instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=n,this._stack.fallThrough=!0,s}this._active=mc,this._id=-1,this._state=0}}},En=class{constructor(e){this._handler=e,this._data="",this._hitLimit=!1}start(){this._data="",this._hitLimit=!1}put(e,t,s){this._hitLimit||(this._data+=tf(e,t,s),this._data.length>1e7&&(this._data="",this._hitLimit=!0))}end(e){let t=!1;if(this._hitLimit)t=!1;else if(e&&(t=this._handler(this._data),t instanceof Promise))return t.then(s=>(this._data="",this._hitLimit=!1,s));return this._data="",this._hitLimit=!1,t}},gc=[],xF=class{constructor(){this._handlers=Object.create(null),this._active=gc,this._ident=0,this._handlerFb=()=>{},this._stack={paused:!1,loopPosition:0,fallThrough:!1}}dispose(){this._handlers=Object.create(null),this._handlerFb=()=>{},this._active=gc}registerHandler(e,t){this._handlers[e]===void 0&&(this._handlers[e]=[]);let s=this._handlers[e];return s.push(t),{dispose:()=>{let n=s.indexOf(t);n!==-1&&s.splice(n,1)}}}clearHandler(e){this._handlers[e]&&delete this._handlers[e]}setHandlerFallback(e){this._handlerFb=e}reset(){if(this._active.length)for(let e=this._stack.paused?this._stack.loopPosition-1:this._active.length-1;e>=0;--e)this._active[e].unhook(!1);this._stack.paused=!1,this._active=gc,this._ident=0}hook(e,t){if(this.reset(),this._ident=e,this._active=this._handlers[e]||gc,!this._active.length)this._handlerFb(this._ident,"HOOK",t);else for(let s=this._active.length-1;s>=0;s--)this._active[s].hook(t)}put(e,t,s){if(!this._active.length)this._handlerFb(this._ident,"PUT",tf(e,t,s));else for(let n=this._active.length-1;n>=0;n--)this._active[n].put(e,t,s)}unhook(e,t=!0){if(!this._active.length)this._handlerFb(this._ident,"UNHOOK",e);else{let s=!1,n=this._active.length-1,a=!1;if(this._stack.paused&&(n=this._stack.loopPosition-1,s=t,a=this._stack.fallThrough,this._stack.paused=!1),!a&&s===!1){for(;n>=0&&(s=this._active[n].unhook(e),s!==!0);n--)if(s instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=n,this._stack.fallThrough=!1,s;n--}for(;n>=0;n--)if(s=this._active[n].unhook(!1),s instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=n,this._stack.fallThrough=!0,s}this._active=gc,this._ident=0}},Dc=new kN;Dc.addParam(0);var K2=class{constructor(e){this._handler=e,this._data="",this._params=Dc,this._hitLimit=!1}hook(e){this._params=e.length>1||e.params[0]?e.clone():Dc,this._data="",this._hitLimit=!1}put(e,t,s){this._hitLimit||(this._data+=tf(e,t,s),this._data.length>1e7&&(this._data="",this._hitLimit=!0))}unhook(e){let t=!1;if(this._hitLimit)t=!1;else if(e&&(t=this._handler(this._data,this._params),t instanceof Promise))return t.then(s=>(this._params=Dc,this._data="",this._hitLimit=!1,s));return this._params=Dc,this._data="",this._hitLimit=!1,t}},vF=class{constructor(e){this.table=new Uint8Array(e)}setDefault(e,t){this.table.fill(e<<4|t)}add(e,t,s,n){this.table[t<<8|e]=s<<4|n}addMany(e,t,s,n){for(let a=0;a<e.length;a++)this.table[t<<8|e[a]]=s<<4|n}},Gn=160,bF=(function(){let e=new vF(4095),t=Array.apply(null,Array(256)).map((d,f)=>f),s=(d,f)=>t.slice(d,f),n=s(32,127),a=s(0,24);a.push(25),a.push.apply(a,s(28,32));let l=s(0,14),c;e.setDefault(1,0),e.addMany(n,0,2,0);for(c in l)e.addMany([24,26,153,154],c,3,0),e.addMany(s(128,144),c,3,0),e.addMany(s(144,152),c,3,0),e.add(156,c,0,0),e.add(27,c,11,1),e.add(157,c,4,8),e.addMany([152,158,159],c,0,7),e.add(155,c,11,3),e.add(144,c,11,9);return e.addMany(a,0,3,0),e.addMany(a,1,3,1),e.add(127,1,0,1),e.addMany(a,8,0,8),e.addMany(a,3,3,3),e.add(127,3,0,3),e.addMany(a,4,3,4),e.add(127,4,0,4),e.addMany(a,6,3,6),e.addMany(a,5,3,5),e.add(127,5,0,5),e.addMany(a,2,3,2),e.add(127,2,0,2),e.add(93,1,4,8),e.addMany(n,8,5,8),e.add(127,8,5,8),e.addMany([156,27,24,26,7],8,6,0),e.addMany(s(28,32),8,0,8),e.addMany([88,94,95],1,0,7),e.addMany(n,7,0,7),e.addMany(a,7,0,7),e.add(156,7,0,0),e.add(127,7,0,7),e.add(91,1,11,3),e.addMany(s(64,127),3,7,0),e.addMany(s(48,60),3,8,4),e.addMany([60,61,62,63],3,9,4),e.addMany(s(48,60),4,8,4),e.addMany(s(64,127),4,7,0),e.addMany([60,61,62,63],4,0,6),e.addMany(s(32,64),6,0,6),e.add(127,6,0,6),e.addMany(s(64,127),6,0,0),e.addMany(s(32,48),3,9,5),e.addMany(s(32,48),5,9,5),e.addMany(s(48,64),5,0,6),e.addMany(s(64,127),5,7,0),e.addMany(s(32,48),4,9,5),e.addMany(s(32,48),1,9,2),e.addMany(s(32,48),2,9,2),e.addMany(s(48,127),2,10,0),e.addMany(s(48,80),1,10,0),e.addMany(s(81,88),1,10,0),e.addMany([89,90,92],1,10,0),e.addMany(s(96,127),1,10,0),e.add(80,1,11,9),e.addMany(a,9,0,9),e.add(127,9,0,9),e.addMany(s(28,32),9,0,9),e.addMany(s(32,48),9,9,12),e.addMany(s(48,60),9,8,10),e.addMany([60,61,62,63],9,9,10),e.addMany(a,11,0,11),e.addMany(s(32,128),11,0,11),e.addMany(s(28,32),11,0,11),e.addMany(a,10,0,10),e.add(127,10,0,10),e.addMany(s(28,32),10,0,10),e.addMany(s(48,60),10,8,10),e.addMany([60,61,62,63],10,0,11),e.addMany(s(32,48),10,9,12),e.addMany(a,12,0,12),e.add(127,12,0,12),e.addMany(s(28,32),12,0,12),e.addMany(s(32,48),12,9,12),e.addMany(s(48,64),12,0,11),e.addMany(s(64,127),12,12,13),e.addMany(s(64,127),10,12,13),e.addMany(s(64,127),9,12,13),e.addMany(a,13,13,13),e.addMany(n,13,13,13),e.add(127,13,0,13),e.addMany([27,156,24,26],13,14,0),e.add(Gn,0,2,0),e.add(Gn,8,5,8),e.add(Gn,6,0,6),e.add(Gn,11,0,11),e.add(Gn,13,13,13),e})(),_F=class extends nt{constructor(e=bF){super(),this._transitions=e,this._parseStack={state:0,handlers:[],handlerPos:0,transition:0,chunkPos:0},this.initialState=0,this.currentState=this.initialState,this._params=new kN,this._params.addParam(0),this._collect=0,this.precedingJoinState=0,this._printHandlerFb=(t,s,n)=>{},this._executeHandlerFb=t=>{},this._csiHandlerFb=(t,s)=>{},this._escHandlerFb=t=>{},this._errorHandlerFb=t=>t,this._printHandler=this._printHandlerFb,this._executeHandlers=Object.create(null),this._csiHandlers=Object.create(null),this._escHandlers=Object.create(null),this._register(Ut(()=>{this._csiHandlers=Object.create(null),this._executeHandlers=Object.create(null),this._escHandlers=Object.create(null)})),this._oscParser=this._register(new gF),this._dcsParser=this._register(new xF),this._errorHandler=this._errorHandlerFb,this.registerEscHandler({final:"\\"},()=>!0)}_identifier(e,t=[64,126]){let s=0;if(e.prefix){if(e.prefix.length>1)throw new Error("only one byte as prefix supported");if(s=e.prefix.charCodeAt(0),s&&60>s||s>63)throw new Error("prefix must be in range 0x3c .. 0x3f")}if(e.intermediates){if(e.intermediates.length>2)throw new Error("only two bytes as intermediates are supported");for(let a=0;a<e.intermediates.length;++a){let l=e.intermediates.charCodeAt(a);if(32>l||l>47)throw new Error("intermediate must be in range 0x20 .. 0x2f");s<<=8,s|=l}}if(e.final.length!==1)throw new Error("final must be a single byte");let n=e.final.charCodeAt(0);if(t[0]>n||n>t[1])throw new Error(`final must be in range ${t[0]} .. ${t[1]}`);return s<<=8,s|=n,s}identToString(e){let t=[];for(;e;)t.push(String.fromCharCode(e&255)),e>>=8;return t.reverse().join("")}setPrintHandler(e){this._printHandler=e}clearPrintHandler(){this._printHandler=this._printHandlerFb}registerEscHandler(e,t){let s=this._identifier(e,[48,126]);this._escHandlers[s]===void 0&&(this._escHandlers[s]=[]);let n=this._escHandlers[s];return n.push(t),{dispose:()=>{let a=n.indexOf(t);a!==-1&&n.splice(a,1)}}}clearEscHandler(e){this._escHandlers[this._identifier(e,[48,126])]&&delete this._escHandlers[this._identifier(e,[48,126])]}setEscHandlerFallback(e){this._escHandlerFb=e}setExecuteHandler(e,t){this._executeHandlers[e.charCodeAt(0)]=t}clearExecuteHandler(e){this._executeHandlers[e.charCodeAt(0)]&&delete this._executeHandlers[e.charCodeAt(0)]}setExecuteHandlerFallback(e){this._executeHandlerFb=e}registerCsiHandler(e,t){let s=this._identifier(e);this._csiHandlers[s]===void 0&&(this._csiHandlers[s]=[]);let n=this._csiHandlers[s];return n.push(t),{dispose:()=>{let a=n.indexOf(t);a!==-1&&n.splice(a,1)}}}clearCsiHandler(e){this._csiHandlers[this._identifier(e)]&&delete this._csiHandlers[this._identifier(e)]}setCsiHandlerFallback(e){this._csiHandlerFb=e}registerDcsHandler(e,t){return this._dcsParser.registerHandler(this._identifier(e),t)}clearDcsHandler(e){this._dcsParser.clearHandler(this._identifier(e))}setDcsHandlerFallback(e){this._dcsParser.setHandlerFallback(e)}registerOscHandler(e,t){return this._oscParser.registerHandler(e,t)}clearOscHandler(e){this._oscParser.clearHandler(e)}setOscHandlerFallback(e){this._oscParser.setHandlerFallback(e)}setErrorHandler(e){this._errorHandler=e}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(e,t,s,n,a){this._parseStack.state=e,this._parseStack.handlers=t,this._parseStack.handlerPos=s,this._parseStack.transition=n,this._parseStack.chunkPos=a}parse(e,t,s){let n=0,a=0,l=0,c;if(this._parseStack.state)if(this._parseStack.state===2)this._parseStack.state=0,l=this._parseStack.chunkPos+1;else{if(s===void 0||this._parseStack.state===1)throw this._parseStack.state=1,new Error("improper continuation due to previous async handler, giving up parsing");let d=this._parseStack.handlers,f=this._parseStack.handlerPos-1;switch(this._parseStack.state){case 3:if(s===!1&&f>-1){for(;f>=0&&(c=d[f](this._params),c!==!0);f--)if(c instanceof Promise)return this._parseStack.handlerPos=f,c}this._parseStack.handlers=[];break;case 4:if(s===!1&&f>-1){for(;f>=0&&(c=d[f](),c!==!0);f--)if(c instanceof Promise)return this._parseStack.handlerPos=f,c}this._parseStack.handlers=[];break;case 6:if(n=e[this._parseStack.chunkPos],c=this._dcsParser.unhook(n!==24&&n!==26,s),c)return c;n===27&&(this._parseStack.transition|=1),this._params.reset(),this._params.addParam(0),this._collect=0;break;case 5:if(n=e[this._parseStack.chunkPos],c=this._oscParser.end(n!==24&&n!==26,s),c)return c;n===27&&(this._parseStack.transition|=1),this._params.reset(),this._params.addParam(0),this._collect=0;break}this._parseStack.state=0,l=this._parseStack.chunkPos+1,this.precedingJoinState=0,this.currentState=this._parseStack.transition&15}for(let d=l;d<t;++d){switch(n=e[d],a=this._transitions.table[this.currentState<<8|(n<160?n:Gn)],a>>4){case 2:for(let b=d+1;;++b){if(b>=t||(n=e[b])<32||n>126&&n<Gn){this._printHandler(e,d,b),d=b-1;break}if(++b>=t||(n=e[b])<32||n>126&&n<Gn){this._printHandler(e,d,b),d=b-1;break}if(++b>=t||(n=e[b])<32||n>126&&n<Gn){this._printHandler(e,d,b),d=b-1;break}if(++b>=t||(n=e[b])<32||n>126&&n<Gn){this._printHandler(e,d,b),d=b-1;break}}break;case 3:this._executeHandlers[n]?this._executeHandlers[n]():this._executeHandlerFb(n),this.precedingJoinState=0;break;case 0:break;case 1:if(this._errorHandler({position:d,code:n,currentState:this.currentState,collect:this._collect,params:this._params,abort:!1}).abort)return;break;case 7:let f=this._csiHandlers[this._collect<<8|n],h=f?f.length-1:-1;for(;h>=0&&(c=f[h](this._params),c!==!0);h--)if(c instanceof Promise)return this._preserveStack(3,f,h,a,d),c;h<0&&this._csiHandlerFb(this._collect<<8|n,this._params),this.precedingJoinState=0;break;case 8:do switch(n){case 59:this._params.addParam(0);break;case 58:this._params.addSubParam(-1);break;default:this._params.addDigit(n-48)}while(++d<t&&(n=e[d])>47&&n<60);d--;break;case 9:this._collect<<=8,this._collect|=n;break;case 10:let m=this._escHandlers[this._collect<<8|n],g=m?m.length-1:-1;for(;g>=0&&(c=m[g](),c!==!0);g--)if(c instanceof Promise)return this._preserveStack(4,m,g,a,d),c;g<0&&this._escHandlerFb(this._collect<<8|n),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|n,this._params);break;case 13:for(let b=d+1;;++b)if(b>=t||(n=e[b])===24||n===26||n===27||n>127&&n<Gn){this._dcsParser.put(e,d,b),d=b-1;break}break;case 14:if(c=this._dcsParser.unhook(n!==24&&n!==26),c)return this._preserveStack(6,[],0,a,d),c;n===27&&(a|=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 b=d+1;;b++)if(b>=t||(n=e[b])<32||n>127&&n<Gn){this._oscParser.put(e,d,b),d=b-1;break}break;case 6:if(c=this._oscParser.end(n!==24&&n!==26),c)return this._preserveStack(5,[],0,a,d),c;n===27&&(a|=1),this._params.reset(),this._params.addParam(0),this._collect=0,this.precedingJoinState=0;break}this.currentState=a&15}}},yF=/^([\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})$/,wF=/^[\da-f]+$/;function Y2(e){if(!e)return;let t=e.toLowerCase();if(t.indexOf("rgb:")===0){t=t.slice(4);let s=yF.exec(t);if(s){let n=s[1]?15:s[4]?255:s[7]?4095:65535;return[Math.round(parseInt(s[1]||s[4]||s[7]||s[10],16)/n*255),Math.round(parseInt(s[2]||s[5]||s[8]||s[11],16)/n*255),Math.round(parseInt(s[3]||s[6]||s[9]||s[12],16)/n*255)]}}else if(t.indexOf("#")===0&&(t=t.slice(1),wF.exec(t)&&[3,6,9,12].includes(t.length))){let s=t.length/3,n=[0,0,0];for(let a=0;a<3;++a){let l=parseInt(t.slice(s*a,s*a+s),16);n[a]=s===1?l<<4:s===2?l:s===3?l>>4:l>>8}return n}}function Ag(e,t){let s=e.toString(16),n=s.length<2?"0"+s:s;switch(t){case 4:return s[0];case 8:return n;case 12:return(n+n).slice(0,3);default:return n+n}}function SF(e,t=16){let[s,n,a]=e;return`rgb:${Ag(s,t)}/${Ag(n,t)}/${Ag(a,t)}`}var jF={"(":0,")":1,"*":2,"+":3,"-":1,".":2},Pi=131072,X2=10;function J2(e,t){if(e>24)return t.setWinLines||!1;switch(e){case 1:return!!t.restoreWin;case 2:return!!t.minimizeWin;case 3:return!!t.setWinPosition;case 4:return!!t.setWinSizePixels;case 5:return!!t.raiseWin;case 6:return!!t.lowerWin;case 7:return!!t.refreshWin;case 8:return!!t.setWinSizeChars;case 9:return!!t.maximizeWin;case 10:return!!t.fullscreenWin;case 11:return!!t.getWinState;case 13:return!!t.getWinPosition;case 14:return!!t.getWinSizePixels;case 15:return!!t.getScreenSizePixels;case 16:return!!t.getCellSizePixels;case 18:return!!t.getWinSizeChars;case 19:return!!t.getScreenSizeChars;case 20:return!!t.getIconTitle;case 21:return!!t.getWinTitle;case 22:return!!t.pushTitle;case 23:return!!t.popTitle;case 24:return!!t.setWinLines}return!1}var Q2=5e3,Z2=0,kF=class extends nt{constructor(e,t,s,n,a,l,c,d,f=new _F){super(),this._bufferService=e,this._charsetService=t,this._coreService=s,this._logService=n,this._optionsService=a,this._oscLinkService=l,this._coreMouseService=c,this._unicodeService=d,this._parser=f,this._parseBuffer=new Uint32Array(4096),this._stringDecoder=new V9,this._utf8Decoder=new W9,this._windowTitle="",this._iconName="",this._windowTitleStack=[],this._iconNameStack=[],this._curAttrData=fs.clone(),this._eraseAttrDataInternal=fs.clone(),this._onRequestBell=this._register(new Ce),this.onRequestBell=this._onRequestBell.event,this._onRequestRefreshRows=this._register(new Ce),this.onRequestRefreshRows=this._onRequestRefreshRows.event,this._onRequestReset=this._register(new Ce),this.onRequestReset=this._onRequestReset.event,this._onRequestSendFocus=this._register(new Ce),this.onRequestSendFocus=this._onRequestSendFocus.event,this._onRequestSyncScrollBar=this._register(new Ce),this.onRequestSyncScrollBar=this._onRequestSyncScrollBar.event,this._onRequestWindowsOptionsReport=this._register(new Ce),this.onRequestWindowsOptionsReport=this._onRequestWindowsOptionsReport.event,this._onA11yChar=this._register(new Ce),this.onA11yChar=this._onA11yChar.event,this._onA11yTab=this._register(new Ce),this.onA11yTab=this._onA11yTab.event,this._onCursorMove=this._register(new Ce),this.onCursorMove=this._onCursorMove.event,this._onLineFeed=this._register(new Ce),this.onLineFeed=this._onLineFeed.event,this._onScroll=this._register(new Ce),this.onScroll=this._onScroll.event,this._onTitleChange=this._register(new Ce),this.onTitleChange=this._onTitleChange.event,this._onColor=this._register(new Ce),this.onColor=this._onColor.event,this._parseStack={paused:!1,cursorStartX:0,cursorStartY:0,decodedLength:0,position:0},this._specialColors=[256,257,258],this._register(this._parser),this._dirtyRowTracker=new f0(this._bufferService),this._activeBuffer=this._bufferService.buffer,this._register(this._bufferService.buffers.onBufferActivate(h=>this._activeBuffer=h.activeBuffer)),this._parser.setCsiHandlerFallback((h,m)=>{this._logService.debug("Unknown CSI code: ",{identifier:this._parser.identToString(h),params:m.toArray()})}),this._parser.setEscHandlerFallback(h=>{this._logService.debug("Unknown ESC code: ",{identifier:this._parser.identToString(h)})}),this._parser.setExecuteHandlerFallback(h=>{this._logService.debug("Unknown EXECUTE code: ",{code:h})}),this._parser.setOscHandlerFallback((h,m,g)=>{this._logService.debug("Unknown OSC code: ",{identifier:h,action:m,data:g})}),this._parser.setDcsHandlerFallback((h,m,g)=>{m==="HOOK"&&(g=g.toArray()),this._logService.debug("Unknown DCS code: ",{identifier:this._parser.identToString(h),action:m,payload:g})}),this._parser.setPrintHandler((h,m,g)=>this.print(h,m,g)),this._parser.registerCsiHandler({final:"@"},h=>this.insertChars(h)),this._parser.registerCsiHandler({intermediates:" ",final:"@"},h=>this.scrollLeft(h)),this._parser.registerCsiHandler({final:"A"},h=>this.cursorUp(h)),this._parser.registerCsiHandler({intermediates:" ",final:"A"},h=>this.scrollRight(h)),this._parser.registerCsiHandler({final:"B"},h=>this.cursorDown(h)),this._parser.registerCsiHandler({final:"C"},h=>this.cursorForward(h)),this._parser.registerCsiHandler({final:"D"},h=>this.cursorBackward(h)),this._parser.registerCsiHandler({final:"E"},h=>this.cursorNextLine(h)),this._parser.registerCsiHandler({final:"F"},h=>this.cursorPrecedingLine(h)),this._parser.registerCsiHandler({final:"G"},h=>this.cursorCharAbsolute(h)),this._parser.registerCsiHandler({final:"H"},h=>this.cursorPosition(h)),this._parser.registerCsiHandler({final:"I"},h=>this.cursorForwardTab(h)),this._parser.registerCsiHandler({final:"J"},h=>this.eraseInDisplay(h,!1)),this._parser.registerCsiHandler({prefix:"?",final:"J"},h=>this.eraseInDisplay(h,!0)),this._parser.registerCsiHandler({final:"K"},h=>this.eraseInLine(h,!1)),this._parser.registerCsiHandler({prefix:"?",final:"K"},h=>this.eraseInLine(h,!0)),this._parser.registerCsiHandler({final:"L"},h=>this.insertLines(h)),this._parser.registerCsiHandler({final:"M"},h=>this.deleteLines(h)),this._parser.registerCsiHandler({final:"P"},h=>this.deleteChars(h)),this._parser.registerCsiHandler({final:"S"},h=>this.scrollUp(h)),this._parser.registerCsiHandler({final:"T"},h=>this.scrollDown(h)),this._parser.registerCsiHandler({final:"X"},h=>this.eraseChars(h)),this._parser.registerCsiHandler({final:"Z"},h=>this.cursorBackwardTab(h)),this._parser.registerCsiHandler({final:"`"},h=>this.charPosAbsolute(h)),this._parser.registerCsiHandler({final:"a"},h=>this.hPositionRelative(h)),this._parser.registerCsiHandler({final:"b"},h=>this.repeatPrecedingCharacter(h)),this._parser.registerCsiHandler({final:"c"},h=>this.sendDeviceAttributesPrimary(h)),this._parser.registerCsiHandler({prefix:">",final:"c"},h=>this.sendDeviceAttributesSecondary(h)),this._parser.registerCsiHandler({final:"d"},h=>this.linePosAbsolute(h)),this._parser.registerCsiHandler({final:"e"},h=>this.vPositionRelative(h)),this._parser.registerCsiHandler({final:"f"},h=>this.hVPosition(h)),this._parser.registerCsiHandler({final:"g"},h=>this.tabClear(h)),this._parser.registerCsiHandler({final:"h"},h=>this.setMode(h)),this._parser.registerCsiHandler({prefix:"?",final:"h"},h=>this.setModePrivate(h)),this._parser.registerCsiHandler({final:"l"},h=>this.resetMode(h)),this._parser.registerCsiHandler({prefix:"?",final:"l"},h=>this.resetModePrivate(h)),this._parser.registerCsiHandler({final:"m"},h=>this.charAttributes(h)),this._parser.registerCsiHandler({final:"n"},h=>this.deviceStatus(h)),this._parser.registerCsiHandler({prefix:"?",final:"n"},h=>this.deviceStatusPrivate(h)),this._parser.registerCsiHandler({intermediates:"!",final:"p"},h=>this.softReset(h)),this._parser.registerCsiHandler({intermediates:" ",final:"q"},h=>this.setCursorStyle(h)),this._parser.registerCsiHandler({final:"r"},h=>this.setScrollRegion(h)),this._parser.registerCsiHandler({final:"s"},h=>this.saveCursor(h)),this._parser.registerCsiHandler({final:"t"},h=>this.windowOptions(h)),this._parser.registerCsiHandler({final:"u"},h=>this.restoreCursor(h)),this._parser.registerCsiHandler({intermediates:"'",final:"}"},h=>this.insertColumns(h)),this._parser.registerCsiHandler({intermediates:"'",final:"~"},h=>this.deleteColumns(h)),this._parser.registerCsiHandler({intermediates:'"',final:"q"},h=>this.selectProtected(h)),this._parser.registerCsiHandler({intermediates:"$",final:"p"},h=>this.requestMode(h,!0)),this._parser.registerCsiHandler({prefix:"?",intermediates:"$",final:"p"},h=>this.requestMode(h,!1)),this._parser.setExecuteHandler(xe.BEL,()=>this.bell()),this._parser.setExecuteHandler(xe.LF,()=>this.lineFeed()),this._parser.setExecuteHandler(xe.VT,()=>this.lineFeed()),this._parser.setExecuteHandler(xe.FF,()=>this.lineFeed()),this._parser.setExecuteHandler(xe.CR,()=>this.carriageReturn()),this._parser.setExecuteHandler(xe.BS,()=>this.backspace()),this._parser.setExecuteHandler(xe.HT,()=>this.tab()),this._parser.setExecuteHandler(xe.SO,()=>this.shiftOut()),this._parser.setExecuteHandler(xe.SI,()=>this.shiftIn()),this._parser.setExecuteHandler(dh.IND,()=>this.index()),this._parser.setExecuteHandler(dh.NEL,()=>this.nextLine()),this._parser.setExecuteHandler(dh.HTS,()=>this.tabSet()),this._parser.registerOscHandler(0,new En(h=>(this.setTitle(h),this.setIconName(h),!0))),this._parser.registerOscHandler(1,new En(h=>this.setIconName(h))),this._parser.registerOscHandler(2,new En(h=>this.setTitle(h))),this._parser.registerOscHandler(4,new En(h=>this.setOrReportIndexedColor(h))),this._parser.registerOscHandler(8,new En(h=>this.setHyperlink(h))),this._parser.registerOscHandler(10,new En(h=>this.setOrReportFgColor(h))),this._parser.registerOscHandler(11,new En(h=>this.setOrReportBgColor(h))),this._parser.registerOscHandler(12,new En(h=>this.setOrReportCursorColor(h))),this._parser.registerOscHandler(104,new En(h=>this.restoreIndexedColor(h))),this._parser.registerOscHandler(110,new En(h=>this.restoreFgColor(h))),this._parser.registerOscHandler(111,new En(h=>this.restoreBgColor(h))),this._parser.registerOscHandler(112,new En(h=>this.restoreCursorColor(h))),this._parser.registerEscHandler({final:"7"},()=>this.saveCursor()),this._parser.registerEscHandler({final:"8"},()=>this.restoreCursor()),this._parser.registerEscHandler({final:"D"},()=>this.index()),this._parser.registerEscHandler({final:"E"},()=>this.nextLine()),this._parser.registerEscHandler({final:"H"},()=>this.tabSet()),this._parser.registerEscHandler({final:"M"},()=>this.reverseIndex()),this._parser.registerEscHandler({final:"="},()=>this.keypadApplicationMode()),this._parser.registerEscHandler({final:">"},()=>this.keypadNumericMode()),this._parser.registerEscHandler({final:"c"},()=>this.fullReset()),this._parser.registerEscHandler({final:"n"},()=>this.setgLevel(2)),this._parser.registerEscHandler({final:"o"},()=>this.setgLevel(3)),this._parser.registerEscHandler({final:"|"},()=>this.setgLevel(3)),this._parser.registerEscHandler({final:"}"},()=>this.setgLevel(2)),this._parser.registerEscHandler({final:"~"},()=>this.setgLevel(1)),this._parser.registerEscHandler({intermediates:"%",final:"@"},()=>this.selectDefaultCharset()),this._parser.registerEscHandler({intermediates:"%",final:"G"},()=>this.selectDefaultCharset());for(let h in Ss)this._parser.registerEscHandler({intermediates:"(",final:h},()=>this.selectCharset("("+h)),this._parser.registerEscHandler({intermediates:")",final:h},()=>this.selectCharset(")"+h)),this._parser.registerEscHandler({intermediates:"*",final:h},()=>this.selectCharset("*"+h)),this._parser.registerEscHandler({intermediates:"+",final:h},()=>this.selectCharset("+"+h)),this._parser.registerEscHandler({intermediates:"-",final:h},()=>this.selectCharset("-"+h)),this._parser.registerEscHandler({intermediates:".",final:h},()=>this.selectCharset("."+h)),this._parser.registerEscHandler({intermediates:"/",final:h},()=>this.selectCharset("/"+h));this._parser.registerEscHandler({intermediates:"#",final:"8"},()=>this.screenAlignmentPattern()),this._parser.setErrorHandler(h=>(this._logService.error("Parsing error: ",h),h)),this._parser.registerDcsHandler({intermediates:"$",final:"q"},new K2((h,m)=>this.requestStatusString(h,m)))}getAttrData(){return this._curAttrData}_preserveStack(e,t,s,n){this._parseStack.paused=!0,this._parseStack.cursorStartX=e,this._parseStack.cursorStartY=t,this._parseStack.decodedLength=s,this._parseStack.position=n}_logSlowResolvingAsync(e){this._logService.logLevel<=3&&Promise.race([e,new Promise((t,s)=>setTimeout(()=>s("#SLOW_TIMEOUT"),Q2))]).catch(t=>{if(t!=="#SLOW_TIMEOUT")throw t;console.warn(`async parser handler taking longer than ${Q2} ms`)})}_getCurrentLinkId(){return this._curAttrData.extended.urlId}parse(e,t){let s,n=this._activeBuffer.x,a=this._activeBuffer.y,l=0,c=this._parseStack.paused;if(c){if(s=this._parser.parse(this._parseBuffer,this._parseStack.decodedLength,t))return this._logSlowResolvingAsync(s),s;n=this._parseStack.cursorStartX,a=this._parseStack.cursorStartY,this._parseStack.paused=!1,e.length>Pi&&(l=this._parseStack.position+Pi)}if(this._logService.logLevel<=1&&this._logService.debug(`parsing data ${typeof e=="string"?` "${e}"`:` "${Array.prototype.map.call(e,h=>String.fromCharCode(h)).join("")}"`}`),this._logService.logLevel===0&&this._logService.trace("parsing data (codes)",typeof e=="string"?e.split("").map(h=>h.charCodeAt(0)):e),this._parseBuffer.length<e.length&&this._parseBuffer.length<Pi&&(this._parseBuffer=new Uint32Array(Math.min(e.length,Pi))),c||this._dirtyRowTracker.clearRange(),e.length>Pi)for(let h=l;h<e.length;h+=Pi){let m=h+Pi<e.length?h+Pi:e.length,g=typeof e=="string"?this._stringDecoder.decode(e.substring(h,m),this._parseBuffer):this._utf8Decoder.decode(e.subarray(h,m),this._parseBuffer);if(s=this._parser.parse(this._parseBuffer,g))return this._preserveStack(n,a,g,h),this._logSlowResolvingAsync(s),s}else if(!c){let h=typeof e=="string"?this._stringDecoder.decode(e,this._parseBuffer):this._utf8Decoder.decode(e,this._parseBuffer);if(s=this._parser.parse(this._parseBuffer,h))return this._preserveStack(n,a,h,0),this._logSlowResolvingAsync(s),s}(this._activeBuffer.x!==n||this._activeBuffer.y!==a)&&this._onCursorMove.fire();let d=this._dirtyRowTracker.end+(this._bufferService.buffer.ybase-this._bufferService.buffer.ydisp),f=this._dirtyRowTracker.start+(this._bufferService.buffer.ybase-this._bufferService.buffer.ydisp);f<this._bufferService.rows&&this._onRequestRefreshRows.fire({start:Math.min(f,this._bufferService.rows-1),end:Math.min(d,this._bufferService.rows-1)})}print(e,t,s){let n,a,l=this._charsetService.charset,c=this._optionsService.rawOptions.screenReaderMode,d=this._bufferService.cols,f=this._coreService.decPrivateModes.wraparound,h=this._coreService.modes.insertMode,m=this._curAttrData,g=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);this._dirtyRowTracker.markDirty(this._activeBuffer.y),this._activeBuffer.x&&s-t>0&&g.getWidth(this._activeBuffer.x-1)===2&&g.setCellFromCodepoint(this._activeBuffer.x-1,0,1,m);let b=this._parser.precedingJoinState;for(let v=t;v<s;++v){if(n=e[v],n<127&&l){let k=l[String.fromCharCode(n)];k&&(n=k.charCodeAt(0))}let y=this._unicodeService.charProperties(n,b);a=ja.extractWidth(y);let S=ja.extractShouldJoin(y),j=S?ja.extractWidth(b):0;if(b=y,c&&this._onA11yChar.fire(Fi(n)),this._getCurrentLinkId()&&this._oscLinkService.addLineToLink(this._getCurrentLinkId(),this._activeBuffer.ybase+this._activeBuffer.y),this._activeBuffer.x+a-j>d){if(f){let k=g,E=this._activeBuffer.x-j;for(this._activeBuffer.x=j,this._activeBuffer.y++,this._activeBuffer.y===this._activeBuffer.scrollBottom+1?(this._activeBuffer.y--,this._bufferService.scroll(this._eraseAttrData(),!0)):(this._activeBuffer.y>=this._bufferService.rows&&(this._activeBuffer.y=this._bufferService.rows-1),this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y).isWrapped=!0),g=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y),j>0&&g instanceof Ac&&g.copyCellsFrom(k,E,0,j,!1);E<d;)k.setCellFromCodepoint(E++,0,1,m)}else if(this._activeBuffer.x=d-1,a===2)continue}if(S&&this._activeBuffer.x){let k=g.getWidth(this._activeBuffer.x-1)?1:2;g.addCodepointToCell(this._activeBuffer.x-k,n,a);for(let E=a-j;--E>=0;)g.setCellFromCodepoint(this._activeBuffer.x++,0,0,m);continue}if(h&&(g.insertCells(this._activeBuffer.x,a-j,this._activeBuffer.getNullCell(m)),g.getWidth(d-1)===2&&g.setCellFromCodepoint(d-1,0,1,m)),g.setCellFromCodepoint(this._activeBuffer.x++,n,a,m),a>0)for(;--a;)g.setCellFromCodepoint(this._activeBuffer.x++,0,0,m)}this._parser.precedingJoinState=b,this._activeBuffer.x<d&&s-t>0&&g.getWidth(this._activeBuffer.x)===0&&!g.hasContent(this._activeBuffer.x)&&g.setCellFromCodepoint(this._activeBuffer.x,0,1,m),this._dirtyRowTracker.markDirty(this._activeBuffer.y)}registerCsiHandler(e,t){return e.final==="t"&&!e.prefix&&!e.intermediates?this._parser.registerCsiHandler(e,s=>J2(s.params[0],this._optionsService.rawOptions.windowOptions)?t(s):!0):this._parser.registerCsiHandler(e,t)}registerDcsHandler(e,t){return this._parser.registerDcsHandler(e,new K2(t))}registerEscHandler(e,t){return this._parser.registerEscHandler(e,t)}registerOscHandler(e,t){return this._parser.registerOscHandler(e,new En(t))}bell(){return this._onRequestBell.fire(),!0}lineFeed(){return this._dirtyRowTracker.markDirty(this._activeBuffer.y),this._optionsService.rawOptions.convertEol&&(this._activeBuffer.x=0),this._activeBuffer.y++,this._activeBuffer.y===this._activeBuffer.scrollBottom+1?(this._activeBuffer.y--,this._bufferService.scroll(this._eraseAttrData())):this._activeBuffer.y>=this._bufferService.rows?this._activeBuffer.y=this._bufferService.rows-1:this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y).isWrapped=!1,this._activeBuffer.x>=this._bufferService.cols&&this._activeBuffer.x--,this._dirtyRowTracker.markDirty(this._activeBuffer.y),this._onLineFeed.fire(),!0}carriageReturn(){return this._activeBuffer.x=0,!0}backspace(){var e;if(!this._coreService.decPrivateModes.reverseWraparound)return this._restrictCursor(),this._activeBuffer.x>0&&this._activeBuffer.x--,!0;if(this._restrictCursor(this._bufferService.cols),this._activeBuffer.x>0)this._activeBuffer.x--;else if(this._activeBuffer.x===0&&this._activeBuffer.y>this._activeBuffer.scrollTop&&this._activeBuffer.y<=this._activeBuffer.scrollBottom&&((e=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y))!=null&&e.isWrapped)){this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y).isWrapped=!1,this._activeBuffer.y--,this._activeBuffer.x=this._bufferService.cols-1;let t=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);t.hasWidth(this._activeBuffer.x)&&!t.hasContent(this._activeBuffer.x)&&this._activeBuffer.x--}return this._restrictCursor(),!0}tab(){if(this._activeBuffer.x>=this._bufferService.cols)return!0;let e=this._activeBuffer.x;return this._activeBuffer.x=this._activeBuffer.nextStop(),this._optionsService.rawOptions.screenReaderMode&&this._onA11yTab.fire(this._activeBuffer.x-e),!0}shiftOut(){return this._charsetService.setgLevel(1),!0}shiftIn(){return this._charsetService.setgLevel(0),!0}_restrictCursor(e=this._bufferService.cols-1){this._activeBuffer.x=Math.min(e,Math.max(0,this._activeBuffer.x)),this._activeBuffer.y=this._coreService.decPrivateModes.origin?Math.min(this._activeBuffer.scrollBottom,Math.max(this._activeBuffer.scrollTop,this._activeBuffer.y)):Math.min(this._bufferService.rows-1,Math.max(0,this._activeBuffer.y)),this._dirtyRowTracker.markDirty(this._activeBuffer.y)}_setCursor(e,t){this._dirtyRowTracker.markDirty(this._activeBuffer.y),this._coreService.decPrivateModes.origin?(this._activeBuffer.x=e,this._activeBuffer.y=this._activeBuffer.scrollTop+t):(this._activeBuffer.x=e,this._activeBuffer.y=t),this._restrictCursor(),this._dirtyRowTracker.markDirty(this._activeBuffer.y)}_moveCursor(e,t){this._restrictCursor(),this._setCursor(this._activeBuffer.x+e,this._activeBuffer.y+t)}cursorUp(e){let t=this._activeBuffer.y-this._activeBuffer.scrollTop;return t>=0?this._moveCursor(0,-Math.min(t,e.params[0]||1)):this._moveCursor(0,-(e.params[0]||1)),!0}cursorDown(e){let t=this._activeBuffer.scrollBottom-this._activeBuffer.y;return t>=0?this._moveCursor(0,Math.min(t,e.params[0]||1)):this._moveCursor(0,e.params[0]||1),!0}cursorForward(e){return this._moveCursor(e.params[0]||1,0),!0}cursorBackward(e){return this._moveCursor(-(e.params[0]||1),0),!0}cursorNextLine(e){return this.cursorDown(e),this._activeBuffer.x=0,!0}cursorPrecedingLine(e){return this.cursorUp(e),this._activeBuffer.x=0,!0}cursorCharAbsolute(e){return this._setCursor((e.params[0]||1)-1,this._activeBuffer.y),!0}cursorPosition(e){return this._setCursor(e.length>=2?(e.params[1]||1)-1:0,(e.params[0]||1)-1),!0}charPosAbsolute(e){return this._setCursor((e.params[0]||1)-1,this._activeBuffer.y),!0}hPositionRelative(e){return this._moveCursor(e.params[0]||1,0),!0}linePosAbsolute(e){return this._setCursor(this._activeBuffer.x,(e.params[0]||1)-1),!0}vPositionRelative(e){return this._moveCursor(0,e.params[0]||1),!0}hVPosition(e){return this.cursorPosition(e),!0}tabClear(e){let t=e.params[0];return t===0?delete this._activeBuffer.tabs[this._activeBuffer.x]:t===3&&(this._activeBuffer.tabs={}),!0}cursorForwardTab(e){if(this._activeBuffer.x>=this._bufferService.cols)return!0;let t=e.params[0]||1;for(;t--;)this._activeBuffer.x=this._activeBuffer.nextStop();return!0}cursorBackwardTab(e){if(this._activeBuffer.x>=this._bufferService.cols)return!0;let t=e.params[0]||1;for(;t--;)this._activeBuffer.x=this._activeBuffer.prevStop();return!0}selectProtected(e){let t=e.params[0];return t===1&&(this._curAttrData.bg|=536870912),(t===2||t===0)&&(this._curAttrData.bg&=-536870913),!0}_eraseInBufferLine(e,t,s,n=!1,a=!1){let l=this._activeBuffer.lines.get(this._activeBuffer.ybase+e);l.replaceCells(t,s,this._activeBuffer.getNullCell(this._eraseAttrData()),a),n&&(l.isWrapped=!1)}_resetBufferLine(e,t=!1){let s=this._activeBuffer.lines.get(this._activeBuffer.ybase+e);s&&(s.fill(this._activeBuffer.getNullCell(this._eraseAttrData()),t),this._bufferService.buffer.clearMarkers(this._activeBuffer.ybase+e),s.isWrapped=!1)}eraseInDisplay(e,t=!1){var n;this._restrictCursor(this._bufferService.cols);let s;switch(e.params[0]){case 0:for(s=this._activeBuffer.y,this._dirtyRowTracker.markDirty(s),this._eraseInBufferLine(s++,this._activeBuffer.x,this._bufferService.cols,this._activeBuffer.x===0,t);s<this._bufferService.rows;s++)this._resetBufferLine(s,t);this._dirtyRowTracker.markDirty(s);break;case 1:for(s=this._activeBuffer.y,this._dirtyRowTracker.markDirty(s),this._eraseInBufferLine(s,0,this._activeBuffer.x+1,!0,t),this._activeBuffer.x+1>=this._bufferService.cols&&(this._activeBuffer.lines.get(s+1).isWrapped=!1);s--;)this._resetBufferLine(s,t);this._dirtyRowTracker.markDirty(0);break;case 2:if(this._optionsService.rawOptions.scrollOnEraseInDisplay){for(s=this._bufferService.rows,this._dirtyRowTracker.markRangeDirty(0,s-1);s--&&!((n=this._activeBuffer.lines.get(this._activeBuffer.ybase+s))!=null&&n.getTrimmedLength()););for(;s>=0;s--)this._bufferService.scroll(this._eraseAttrData())}else{for(s=this._bufferService.rows,this._dirtyRowTracker.markDirty(s-1);s--;)this._resetBufferLine(s,t);this._dirtyRowTracker.markDirty(0)}break;case 3:let a=this._activeBuffer.lines.length-this._bufferService.rows;a>0&&(this._activeBuffer.lines.trimStart(a),this._activeBuffer.ybase=Math.max(this._activeBuffer.ybase-a,0),this._activeBuffer.ydisp=Math.max(this._activeBuffer.ydisp-a,0),this._onScroll.fire(0));break}return!0}eraseInLine(e,t=!1){switch(this._restrictCursor(this._bufferService.cols),e.params[0]){case 0:this._eraseInBufferLine(this._activeBuffer.y,this._activeBuffer.x,this._bufferService.cols,this._activeBuffer.x===0,t);break;case 1:this._eraseInBufferLine(this._activeBuffer.y,0,this._activeBuffer.x+1,!1,t);break;case 2:this._eraseInBufferLine(this._activeBuffer.y,0,this._bufferService.cols,!0,t);break}return this._dirtyRowTracker.markDirty(this._activeBuffer.y),!0}insertLines(e){this._restrictCursor();let t=e.params[0]||1;if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let s=this._activeBuffer.ybase+this._activeBuffer.y,n=this._bufferService.rows-1-this._activeBuffer.scrollBottom,a=this._bufferService.rows-1+this._activeBuffer.ybase-n+1;for(;t--;)this._activeBuffer.lines.splice(a-1,1),this._activeBuffer.lines.splice(s,0,this._activeBuffer.getBlankLine(this._eraseAttrData()));return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.y,this._activeBuffer.scrollBottom),this._activeBuffer.x=0,!0}deleteLines(e){this._restrictCursor();let t=e.params[0]||1;if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let s=this._activeBuffer.ybase+this._activeBuffer.y,n;for(n=this._bufferService.rows-1-this._activeBuffer.scrollBottom,n=this._bufferService.rows-1+this._activeBuffer.ybase-n;t--;)this._activeBuffer.lines.splice(s,1),this._activeBuffer.lines.splice(n,0,this._activeBuffer.getBlankLine(this._eraseAttrData()));return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.y,this._activeBuffer.scrollBottom),this._activeBuffer.x=0,!0}insertChars(e){this._restrictCursor();let t=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);return t&&(t.insertCells(this._activeBuffer.x,e.params[0]||1,this._activeBuffer.getNullCell(this._eraseAttrData())),this._dirtyRowTracker.markDirty(this._activeBuffer.y)),!0}deleteChars(e){this._restrictCursor();let t=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);return t&&(t.deleteCells(this._activeBuffer.x,e.params[0]||1,this._activeBuffer.getNullCell(this._eraseAttrData())),this._dirtyRowTracker.markDirty(this._activeBuffer.y)),!0}scrollUp(e){let t=e.params[0]||1;for(;t--;)this._activeBuffer.lines.splice(this._activeBuffer.ybase+this._activeBuffer.scrollTop,1),this._activeBuffer.lines.splice(this._activeBuffer.ybase+this._activeBuffer.scrollBottom,0,this._activeBuffer.getBlankLine(this._eraseAttrData()));return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}scrollDown(e){let t=e.params[0]||1;for(;t--;)this._activeBuffer.lines.splice(this._activeBuffer.ybase+this._activeBuffer.scrollBottom,1),this._activeBuffer.lines.splice(this._activeBuffer.ybase+this._activeBuffer.scrollTop,0,this._activeBuffer.getBlankLine(fs));return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}scrollLeft(e){if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let t=e.params[0]||1;for(let s=this._activeBuffer.scrollTop;s<=this._activeBuffer.scrollBottom;++s){let n=this._activeBuffer.lines.get(this._activeBuffer.ybase+s);n.deleteCells(0,t,this._activeBuffer.getNullCell(this._eraseAttrData())),n.isWrapped=!1}return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}scrollRight(e){if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let t=e.params[0]||1;for(let s=this._activeBuffer.scrollTop;s<=this._activeBuffer.scrollBottom;++s){let n=this._activeBuffer.lines.get(this._activeBuffer.ybase+s);n.insertCells(0,t,this._activeBuffer.getNullCell(this._eraseAttrData())),n.isWrapped=!1}return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}insertColumns(e){if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let t=e.params[0]||1;for(let s=this._activeBuffer.scrollTop;s<=this._activeBuffer.scrollBottom;++s){let n=this._activeBuffer.lines.get(this._activeBuffer.ybase+s);n.insertCells(this._activeBuffer.x,t,this._activeBuffer.getNullCell(this._eraseAttrData())),n.isWrapped=!1}return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}deleteColumns(e){if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let t=e.params[0]||1;for(let s=this._activeBuffer.scrollTop;s<=this._activeBuffer.scrollBottom;++s){let n=this._activeBuffer.lines.get(this._activeBuffer.ybase+s);n.deleteCells(this._activeBuffer.x,t,this._activeBuffer.getNullCell(this._eraseAttrData())),n.isWrapped=!1}return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}eraseChars(e){this._restrictCursor();let t=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);return t&&(t.replaceCells(this._activeBuffer.x,this._activeBuffer.x+(e.params[0]||1),this._activeBuffer.getNullCell(this._eraseAttrData())),this._dirtyRowTracker.markDirty(this._activeBuffer.y)),!0}repeatPrecedingCharacter(e){let t=this._parser.precedingJoinState;if(!t)return!0;let s=e.params[0]||1,n=ja.extractWidth(t),a=this._activeBuffer.x-n,l=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y).getString(a),c=new Uint32Array(l.length*s),d=0;for(let h=0;h<l.length;){let m=l.codePointAt(h)||0;c[d++]=m,h+=m>65535?2:1}let f=d;for(let h=1;h<s;++h)c.copyWithin(f,0,d),f+=d;return this.print(c,0,f),!0}sendDeviceAttributesPrimary(e){return e.params[0]>0||(this._is("xterm")||this._is("rxvt-unicode")||this._is("screen")?this._coreService.triggerDataEvent(xe.ESC+"[?1;2c"):this._is("linux")&&this._coreService.triggerDataEvent(xe.ESC+"[?6c")),!0}sendDeviceAttributesSecondary(e){return e.params[0]>0||(this._is("xterm")?this._coreService.triggerDataEvent(xe.ESC+"[>0;276;0c"):this._is("rxvt-unicode")?this._coreService.triggerDataEvent(xe.ESC+"[>85;95;0c"):this._is("linux")?this._coreService.triggerDataEvent(e.params[0]+"c"):this._is("screen")&&this._coreService.triggerDataEvent(xe.ESC+"[>83;40003;0c")),!0}_is(e){return(this._optionsService.rawOptions.termName+"").indexOf(e)===0}setMode(e){for(let t=0;t<e.length;t++)switch(e.params[t]){case 4:this._coreService.modes.insertMode=!0;break;case 20:this._optionsService.options.convertEol=!0;break}return!0}setModePrivate(e){for(let t=0;t<e.length;t++)switch(e.params[t]){case 1:this._coreService.decPrivateModes.applicationCursorKeys=!0;break;case 2:this._charsetService.setgCharset(0,Sa),this._charsetService.setgCharset(1,Sa),this._charsetService.setgCharset(2,Sa),this._charsetService.setgCharset(3,Sa);break;case 3:this._optionsService.rawOptions.windowOptions.setWinLines&&(this._bufferService.resize(132,this._bufferService.rows),this._onRequestReset.fire());break;case 6:this._coreService.decPrivateModes.origin=!0,this._setCursor(0,0);break;case 7:this._coreService.decPrivateModes.wraparound=!0;break;case 12:this._optionsService.options.cursorBlink=!0;break;case 45:this._coreService.decPrivateModes.reverseWraparound=!0;break;case 66:this._logService.debug("Serial port requested application keypad."),this._coreService.decPrivateModes.applicationKeypad=!0,this._onRequestSyncScrollBar.fire();break;case 9:this._coreMouseService.activeProtocol="X10";break;case 1e3:this._coreMouseService.activeProtocol="VT200";break;case 1002:this._coreMouseService.activeProtocol="DRAG";break;case 1003:this._coreMouseService.activeProtocol="ANY";break;case 1004:this._coreService.decPrivateModes.sendFocus=!0,this._onRequestSendFocus.fire();break;case 1005:this._logService.debug("DECSET 1005 not supported (see #2507)");break;case 1006:this._coreMouseService.activeEncoding="SGR";break;case 1015:this._logService.debug("DECSET 1015 not supported (see #2507)");break;case 1016:this._coreMouseService.activeEncoding="SGR_PIXELS";break;case 25:this._coreService.isCursorHidden=!1;break;case 1048:this.saveCursor();break;case 1049:this.saveCursor();case 47:case 1047:this._bufferService.buffers.activateAltBuffer(this._eraseAttrData()),this._coreService.isCursorInitialized=!0,this._onRequestRefreshRows.fire(void 0),this._onRequestSyncScrollBar.fire();break;case 2004:this._coreService.decPrivateModes.bracketedPasteMode=!0;break;case 2026:this._coreService.decPrivateModes.synchronizedOutput=!0;break}return!0}resetMode(e){for(let t=0;t<e.length;t++)switch(e.params[t]){case 4:this._coreService.modes.insertMode=!1;break;case 20:this._optionsService.options.convertEol=!1;break}return!0}resetModePrivate(e){for(let t=0;t<e.length;t++)switch(e.params[t]){case 1:this._coreService.decPrivateModes.applicationCursorKeys=!1;break;case 3:this._optionsService.rawOptions.windowOptions.setWinLines&&(this._bufferService.resize(80,this._bufferService.rows),this._onRequestReset.fire());break;case 6:this._coreService.decPrivateModes.origin=!1,this._setCursor(0,0);break;case 7:this._coreService.decPrivateModes.wraparound=!1;break;case 12:this._optionsService.options.cursorBlink=!1;break;case 45:this._coreService.decPrivateModes.reverseWraparound=!1;break;case 66:this._logService.debug("Switching back to normal keypad."),this._coreService.decPrivateModes.applicationKeypad=!1,this._onRequestSyncScrollBar.fire();break;case 9:case 1e3:case 1002:case 1003:this._coreMouseService.activeProtocol="NONE";break;case 1004:this._coreService.decPrivateModes.sendFocus=!1;break;case 1005:this._logService.debug("DECRST 1005 not supported (see #2507)");break;case 1006:this._coreMouseService.activeEncoding="DEFAULT";break;case 1015:this._logService.debug("DECRST 1015 not supported (see #2507)");break;case 1016:this._coreMouseService.activeEncoding="DEFAULT";break;case 25:this._coreService.isCursorHidden=!0;break;case 1048:this.restoreCursor();break;case 1049:case 47:case 1047:this._bufferService.buffers.activateNormalBuffer(),e.params[t]===1049&&this.restoreCursor(),this._coreService.isCursorInitialized=!0,this._onRequestRefreshRows.fire(void 0),this._onRequestSyncScrollBar.fire();break;case 2004:this._coreService.decPrivateModes.bracketedPasteMode=!1;break;case 2026:this._coreService.decPrivateModes.synchronizedOutput=!1,this._onRequestRefreshRows.fire(void 0);break}return!0}requestMode(e,t){(S=>(S[S.NOT_RECOGNIZED=0]="NOT_RECOGNIZED",S[S.SET=1]="SET",S[S.RESET=2]="RESET",S[S.PERMANENTLY_SET=3]="PERMANENTLY_SET",S[S.PERMANENTLY_RESET=4]="PERMANENTLY_RESET"))(void 0||(s={}));let n=this._coreService.decPrivateModes,{activeProtocol:a,activeEncoding:l}=this._coreMouseService,c=this._coreService,{buffers:d,cols:f}=this._bufferService,{active:h,alt:m}=d,g=this._optionsService.rawOptions,b=(S,j)=>(c.triggerDataEvent(`${xe.ESC}[${t?"":"?"}${S};${j}$y`),!0),v=S=>S?1:2,y=e.params[0];return t?y===2?b(y,4):y===4?b(y,v(c.modes.insertMode)):y===12?b(y,3):y===20?b(y,v(g.convertEol)):b(y,0):y===1?b(y,v(n.applicationCursorKeys)):y===3?b(y,g.windowOptions.setWinLines?f===80?2:f===132?1:0:0):y===6?b(y,v(n.origin)):y===7?b(y,v(n.wraparound)):y===8?b(y,3):y===9?b(y,v(a==="X10")):y===12?b(y,v(g.cursorBlink)):y===25?b(y,v(!c.isCursorHidden)):y===45?b(y,v(n.reverseWraparound)):y===66?b(y,v(n.applicationKeypad)):y===67?b(y,4):y===1e3?b(y,v(a==="VT200")):y===1002?b(y,v(a==="DRAG")):y===1003?b(y,v(a==="ANY")):y===1004?b(y,v(n.sendFocus)):y===1005?b(y,4):y===1006?b(y,v(l==="SGR")):y===1015?b(y,4):y===1016?b(y,v(l==="SGR_PIXELS")):y===1048?b(y,1):y===47||y===1047||y===1049?b(y,v(h===m)):y===2004?b(y,v(n.bracketedPasteMode)):y===2026?b(y,v(n.synchronizedOutput)):b(y,0)}_updateAttrColor(e,t,s,n,a){return t===2?(e|=50331648,e&=-16777216,e|=pu.fromColorRGB([s,n,a])):t===5&&(e&=-50331904,e|=33554432|s&255),e}_extractColor(e,t,s){let n=[0,0,-1,0,0,0],a=0,l=0;do{if(n[l+a]=e.params[t+l],e.hasSubParams(t+l)){let c=e.getSubParams(t+l),d=0;do n[1]===5&&(a=1),n[l+d+1+a]=c[d];while(++d<c.length&&d+l+1+a<n.length);break}if(n[1]===5&&l+a>=2||n[1]===2&&l+a>=5)break;n[1]&&(a=1)}while(++l+t<e.length&&l+a<n.length);for(let c=2;c<n.length;++c)n[c]===-1&&(n[c]=0);switch(n[0]){case 38:s.fg=this._updateAttrColor(s.fg,n[1],n[3],n[4],n[5]);break;case 48:s.bg=this._updateAttrColor(s.bg,n[1],n[3],n[4],n[5]);break;case 58:s.extended=s.extended.clone(),s.extended.underlineColor=this._updateAttrColor(s.extended.underlineColor,n[1],n[3],n[4],n[5])}return l}_processUnderline(e,t){t.extended=t.extended.clone(),(!~e||e>5)&&(e=1),t.extended.underlineStyle=e,t.fg|=268435456,e===0&&(t.fg&=-268435457),t.updateExtended()}_processSGR0(e){e.fg=fs.fg,e.bg=fs.bg,e.extended=e.extended.clone(),e.extended.underlineStyle=0,e.extended.underlineColor&=-67108864,e.updateExtended()}charAttributes(e){if(e.length===1&&e.params[0]===0)return this._processSGR0(this._curAttrData),!0;let t=e.length,s,n=this._curAttrData;for(let a=0;a<t;a++)s=e.params[a],s>=30&&s<=37?(n.fg&=-50331904,n.fg|=16777216|s-30):s>=40&&s<=47?(n.bg&=-50331904,n.bg|=16777216|s-40):s>=90&&s<=97?(n.fg&=-50331904,n.fg|=16777216|s-90|8):s>=100&&s<=107?(n.bg&=-50331904,n.bg|=16777216|s-100|8):s===0?this._processSGR0(n):s===1?n.fg|=134217728:s===3?n.bg|=67108864:s===4?(n.fg|=268435456,this._processUnderline(e.hasSubParams(a)?e.getSubParams(a)[0]:1,n)):s===5?n.fg|=536870912:s===7?n.fg|=67108864:s===8?n.fg|=1073741824:s===9?n.fg|=2147483648:s===2?n.bg|=134217728:s===21?this._processUnderline(2,n):s===22?(n.fg&=-134217729,n.bg&=-134217729):s===23?n.bg&=-67108865:s===24?(n.fg&=-268435457,this._processUnderline(0,n)):s===25?n.fg&=-536870913:s===27?n.fg&=-67108865:s===28?n.fg&=-1073741825:s===29?n.fg&=2147483647:s===39?(n.fg&=-67108864,n.fg|=fs.fg&16777215):s===49?(n.bg&=-67108864,n.bg|=fs.bg&16777215):s===38||s===48||s===58?a+=this._extractColor(e,a,n):s===53?n.bg|=1073741824:s===55?n.bg&=-1073741825:s===59?(n.extended=n.extended.clone(),n.extended.underlineColor=-1,n.updateExtended()):s===100?(n.fg&=-67108864,n.fg|=fs.fg&16777215,n.bg&=-67108864,n.bg|=fs.bg&16777215):this._logService.debug("Unknown SGR attribute: %d.",s);return!0}deviceStatus(e){switch(e.params[0]){case 5:this._coreService.triggerDataEvent(`${xe.ESC}[0n`);break;case 6:let t=this._activeBuffer.y+1,s=this._activeBuffer.x+1;this._coreService.triggerDataEvent(`${xe.ESC}[${t};${s}R`);break}return!0}deviceStatusPrivate(e){switch(e.params[0]){case 6:let t=this._activeBuffer.y+1,s=this._activeBuffer.x+1;this._coreService.triggerDataEvent(`${xe.ESC}[?${t};${s}R`);break}return!0}softReset(e){return this._coreService.isCursorHidden=!1,this._onRequestSyncScrollBar.fire(),this._activeBuffer.scrollTop=0,this._activeBuffer.scrollBottom=this._bufferService.rows-1,this._curAttrData=fs.clone(),this._coreService.reset(),this._charsetService.reset(),this._activeBuffer.savedX=0,this._activeBuffer.savedY=this._activeBuffer.ybase,this._activeBuffer.savedCurAttrData.fg=this._curAttrData.fg,this._activeBuffer.savedCurAttrData.bg=this._curAttrData.bg,this._activeBuffer.savedCharset=this._charsetService.charset,this._coreService.decPrivateModes.origin=!1,!0}setCursorStyle(e){let t=e.length===0?1:e.params[0];if(t===0)this._coreService.decPrivateModes.cursorStyle=void 0,this._coreService.decPrivateModes.cursorBlink=void 0;else{switch(t){case 1:case 2:this._coreService.decPrivateModes.cursorStyle="block";break;case 3:case 4:this._coreService.decPrivateModes.cursorStyle="underline";break;case 5:case 6:this._coreService.decPrivateModes.cursorStyle="bar";break}let s=t%2===1;this._coreService.decPrivateModes.cursorBlink=s}return!0}setScrollRegion(e){let t=e.params[0]||1,s;return(e.length<2||(s=e.params[1])>this._bufferService.rows||s===0)&&(s=this._bufferService.rows),s>t&&(this._activeBuffer.scrollTop=t-1,this._activeBuffer.scrollBottom=s-1,this._setCursor(0,0)),!0}windowOptions(e){if(!J2(e.params[0],this._optionsService.rawOptions.windowOptions))return!0;let t=e.length>1?e.params[1]:0;switch(e.params[0]){case 14:t!==2&&this._onRequestWindowsOptionsReport.fire(0);break;case 16:this._onRequestWindowsOptionsReport.fire(1);break;case 18:this._bufferService&&this._coreService.triggerDataEvent(`${xe.ESC}[8;${this._bufferService.rows};${this._bufferService.cols}t`);break;case 22:(t===0||t===2)&&(this._windowTitleStack.push(this._windowTitle),this._windowTitleStack.length>X2&&this._windowTitleStack.shift()),(t===0||t===1)&&(this._iconNameStack.push(this._iconName),this._iconNameStack.length>X2&&this._iconNameStack.shift());break;case 23:(t===0||t===2)&&this._windowTitleStack.length&&this.setTitle(this._windowTitleStack.pop()),(t===0||t===1)&&this._iconNameStack.length&&this.setIconName(this._iconNameStack.pop());break}return!0}saveCursor(e){return this._activeBuffer.savedX=this._activeBuffer.x,this._activeBuffer.savedY=this._activeBuffer.ybase+this._activeBuffer.y,this._activeBuffer.savedCurAttrData.fg=this._curAttrData.fg,this._activeBuffer.savedCurAttrData.bg=this._curAttrData.bg,this._activeBuffer.savedCharset=this._charsetService.charset,!0}restoreCursor(e){return this._activeBuffer.x=this._activeBuffer.savedX||0,this._activeBuffer.y=Math.max(this._activeBuffer.savedY-this._activeBuffer.ybase,0),this._curAttrData.fg=this._activeBuffer.savedCurAttrData.fg,this._curAttrData.bg=this._activeBuffer.savedCurAttrData.bg,this._charsetService.charset=this._savedCharset,this._activeBuffer.savedCharset&&(this._charsetService.charset=this._activeBuffer.savedCharset),this._restrictCursor(),!0}setTitle(e){return this._windowTitle=e,this._onTitleChange.fire(e),!0}setIconName(e){return this._iconName=e,!0}setOrReportIndexedColor(e){let t=[],s=e.split(";");for(;s.length>1;){let n=s.shift(),a=s.shift();if(/^\d+$/.exec(n)){let l=parseInt(n);if(eS(l))if(a==="?")t.push({type:0,index:l});else{let c=Y2(a);c&&t.push({type:1,index:l,color:c})}}}return t.length&&this._onColor.fire(t),!0}setHyperlink(e){let t=e.indexOf(";");if(t===-1)return!0;let s=e.slice(0,t).trim(),n=e.slice(t+1);return n?this._createHyperlink(s,n):s.trim()?!1:this._finishHyperlink()}_createHyperlink(e,t){this._getCurrentLinkId()&&this._finishHyperlink();let s=e.split(":"),n,a=s.findIndex(l=>l.startsWith("id="));return a!==-1&&(n=s[a].slice(3)||void 0),this._curAttrData.extended=this._curAttrData.extended.clone(),this._curAttrData.extended.urlId=this._oscLinkService.registerLink({id:n,uri:t}),this._curAttrData.updateExtended(),!0}_finishHyperlink(){return this._curAttrData.extended=this._curAttrData.extended.clone(),this._curAttrData.extended.urlId=0,this._curAttrData.updateExtended(),!0}_setOrReportSpecialColor(e,t){let s=e.split(";");for(let n=0;n<s.length&&!(t>=this._specialColors.length);++n,++t)if(s[n]==="?")this._onColor.fire([{type:0,index:this._specialColors[t]}]);else{let a=Y2(s[n]);a&&this._onColor.fire([{type:1,index:this._specialColors[t],color:a}])}return!0}setOrReportFgColor(e){return this._setOrReportSpecialColor(e,0)}setOrReportBgColor(e){return this._setOrReportSpecialColor(e,1)}setOrReportCursorColor(e){return this._setOrReportSpecialColor(e,2)}restoreIndexedColor(e){if(!e)return this._onColor.fire([{type:2}]),!0;let t=[],s=e.split(";");for(let n=0;n<s.length;++n)if(/^\d+$/.exec(s[n])){let a=parseInt(s[n]);eS(a)&&t.push({type:2,index:a})}return t.length&&this._onColor.fire(t),!0}restoreFgColor(e){return this._onColor.fire([{type:2,index:256}]),!0}restoreBgColor(e){return this._onColor.fire([{type:2,index:257}]),!0}restoreCursorColor(e){return this._onColor.fire([{type:2,index:258}]),!0}nextLine(){return this._activeBuffer.x=0,this.index(),!0}keypadApplicationMode(){return this._logService.debug("Serial port requested application keypad."),this._coreService.decPrivateModes.applicationKeypad=!0,this._onRequestSyncScrollBar.fire(),!0}keypadNumericMode(){return this._logService.debug("Switching back to normal keypad."),this._coreService.decPrivateModes.applicationKeypad=!1,this._onRequestSyncScrollBar.fire(),!0}selectDefaultCharset(){return this._charsetService.setgLevel(0),this._charsetService.setgCharset(0,Sa),!0}selectCharset(e){return e.length!==2?(this.selectDefaultCharset(),!0):(e[0]==="/"||this._charsetService.setgCharset(jF[e[0]],Ss[e[1]]||Sa),!0)}index(){return this._restrictCursor(),this._activeBuffer.y++,this._activeBuffer.y===this._activeBuffer.scrollBottom+1?(this._activeBuffer.y--,this._bufferService.scroll(this._eraseAttrData())):this._activeBuffer.y>=this._bufferService.rows&&(this._activeBuffer.y=this._bufferService.rows-1),this._restrictCursor(),!0}tabSet(){return this._activeBuffer.tabs[this._activeBuffer.x]=!0,!0}reverseIndex(){if(this._restrictCursor(),this._activeBuffer.y===this._activeBuffer.scrollTop){let e=this._activeBuffer.scrollBottom-this._activeBuffer.scrollTop;this._activeBuffer.lines.shiftElements(this._activeBuffer.ybase+this._activeBuffer.y,e,1),this._activeBuffer.lines.set(this._activeBuffer.ybase+this._activeBuffer.y,this._activeBuffer.getBlankLine(this._eraseAttrData())),this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom)}else this._activeBuffer.y--,this._restrictCursor();return!0}fullReset(){return this._parser.reset(),this._onRequestReset.fire(),!0}reset(){this._curAttrData=fs.clone(),this._eraseAttrDataInternal=fs.clone()}_eraseAttrData(){return this._eraseAttrDataInternal.bg&=-67108864,this._eraseAttrDataInternal.bg|=this._curAttrData.bg&67108863,this._eraseAttrDataInternal}setgLevel(e){return this._charsetService.setgLevel(e),!0}screenAlignmentPattern(){let e=new Jn;e.content=1<<22|69,e.fg=this._curAttrData.fg,e.bg=this._curAttrData.bg,this._setCursor(0,0);for(let t=0;t<this._bufferService.rows;++t){let s=this._activeBuffer.ybase+this._activeBuffer.y+t,n=this._activeBuffer.lines.get(s);n&&(n.fill(e),n.isWrapped=!1)}return this._dirtyRowTracker.markAllDirty(),this._setCursor(0,0),!0}requestStatusString(e,t){let s=c=>(this._coreService.triggerDataEvent(`${xe.ESC}${c}${xe.ESC}\\`),!0),n=this._bufferService.buffer,a=this._optionsService.rawOptions;return s(e==='"q'?`P1$r${this._curAttrData.isProtected()?1:0}"q`:e==='"p'?'P1$r61;1"p':e==="r"?`P1$r${n.scrollTop+1};${n.scrollBottom+1}r`:e==="m"?"P1$r0m":e===" q"?`P1$r${{block:2,underline:4,bar:6}[a.cursorStyle]-(a.cursorBlink?1:0)} q`:"P0$r")}markRangeDirty(e,t){this._dirtyRowTracker.markRangeDirty(e,t)}},f0=class{constructor(e){this._bufferService=e,this.clearRange()}clearRange(){this.start=this._bufferService.buffer.y,this.end=this._bufferService.buffer.y}markDirty(e){e<this.start?this.start=e:e>this.end&&(this.end=e)}markRangeDirty(e,t){e>t&&(Z2=e,e=t,t=Z2),e<this.start&&(this.start=e),t>this.end&&(this.end=t)}markAllDirty(){this.markRangeDirty(0,this._bufferService.rows-1)}};f0=ts([Re(0,sn)],f0);function eS(e){return 0<=e&&e<256}var CF=5e7,tS=12,NF=50,EF=class extends nt{constructor(e){super(),this._action=e,this._writeBuffer=[],this._callbacks=[],this._pendingData=0,this._bufferOffset=0,this._isSyncWriting=!1,this._syncCalls=0,this._didUserInput=!1,this._onWriteParsed=this._register(new Ce),this.onWriteParsed=this._onWriteParsed.event}handleUserInput(){this._didUserInput=!0}writeSync(e,t){if(t!==void 0&&this._syncCalls>t){this._syncCalls=0;return}if(this._pendingData+=e.length,this._writeBuffer.push(e),this._callbacks.push(void 0),this._syncCalls++,this._isSyncWriting)return;this._isSyncWriting=!0;let s;for(;s=this._writeBuffer.shift();){this._action(s);let n=this._callbacks.shift();n&&n()}this._pendingData=0,this._bufferOffset=2147483647,this._isSyncWriting=!1,this._syncCalls=0}write(e,t){if(this._pendingData>CF)throw new Error("write data discarded, use flow control to avoid losing data");if(!this._writeBuffer.length){if(this._bufferOffset=0,this._didUserInput){this._didUserInput=!1,this._pendingData+=e.length,this._writeBuffer.push(e),this._callbacks.push(t),this._innerWrite();return}setTimeout(()=>this._innerWrite())}this._pendingData+=e.length,this._writeBuffer.push(e),this._callbacks.push(t)}_innerWrite(e=0,t=!0){let s=e||performance.now();for(;this._writeBuffer.length>this._bufferOffset;){let n=this._writeBuffer[this._bufferOffset],a=this._action(n,t);if(a){let c=d=>performance.now()-s>=tS?setTimeout(()=>this._innerWrite(0,d)):this._innerWrite(s,d);a.catch(d=>(queueMicrotask(()=>{throw d}),Promise.resolve(!1))).then(c);return}let l=this._callbacks[this._bufferOffset];if(l&&l(),this._bufferOffset++,this._pendingData-=n.length,performance.now()-s>=tS)break}this._writeBuffer.length>this._bufferOffset?(this._bufferOffset>NF&&(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()}},p0=class{constructor(e){this._bufferService=e,this._nextId=1,this._entriesWithId=new Map,this._dataByLinkId=new Map}registerLink(e){let t=this._bufferService.buffer;if(e.id===void 0){let d=t.addMarker(t.ybase+t.y),f={data:e,id:this._nextId++,lines:[d]};return d.onDispose(()=>this._removeMarkerFromLink(f,d)),this._dataByLinkId.set(f.id,f),f.id}let s=e,n=this._getEntryIdKey(s),a=this._entriesWithId.get(n);if(a)return this.addLineToLink(a.id,t.ybase+t.y),a.id;let l=t.addMarker(t.ybase+t.y),c={id:this._nextId++,key:this._getEntryIdKey(s),data:s,lines:[l]};return l.onDispose(()=>this._removeMarkerFromLink(c,l)),this._entriesWithId.set(c.key,c),this._dataByLinkId.set(c.id,c),c.id}addLineToLink(e,t){let s=this._dataByLinkId.get(e);if(s&&s.lines.every(n=>n.line!==t)){let n=this._bufferService.buffer.addMarker(t);s.lines.push(n),n.onDispose(()=>this._removeMarkerFromLink(s,n))}}getLinkData(e){var t;return(t=this._dataByLinkId.get(e))==null?void 0:t.data}_getEntryIdKey(e){return`${e.id};;${e.uri}`}_removeMarkerFromLink(e,t){let s=e.lines.indexOf(t);s!==-1&&(e.lines.splice(s,1),e.lines.length===0&&(e.data.id!==void 0&&this._entriesWithId.delete(e.key),this._dataByLinkId.delete(e.id)))}};p0=ts([Re(0,sn)],p0);var sS=!1,MF=class extends nt{constructor(e){super(),this._windowsWrappingHeuristics=this._register(new Yo),this._onBinary=this._register(new Ce),this.onBinary=this._onBinary.event,this._onData=this._register(new Ce),this.onData=this._onData.event,this._onLineFeed=this._register(new Ce),this.onLineFeed=this._onLineFeed.event,this._onResize=this._register(new Ce),this.onResize=this._onResize.event,this._onWriteParsed=this._register(new Ce),this.onWriteParsed=this._onWriteParsed.event,this._onScroll=this._register(new Ce),this._instantiationService=new ZI,this.optionsService=this._register(new cF(e)),this._instantiationService.setService(nn,this.optionsService),this._bufferService=this._register(this._instantiationService.createInstance(c0)),this._instantiationService.setService(sn,this._bufferService),this._logService=this._register(this._instantiationService.createInstance(l0)),this._instantiationService.setService(VC,this._logService),this.coreService=this._register(this._instantiationService.createInstance(u0)),this._instantiationService.setService(Ba,this.coreService),this.coreMouseService=this._register(this._instantiationService.createInstance(d0)),this._instantiationService.setService(UC,this.coreMouseService),this.unicodeService=this._register(this._instantiationService.createInstance(ja)),this._instantiationService.setService(Y9,this.unicodeService),this._charsetService=this._instantiationService.createInstance(pF),this._instantiationService.setService(K9,this._charsetService),this._oscLinkService=this._instantiationService.createInstance(p0),this._instantiationService.setService(WC,this._oscLinkService),this._inputHandler=this._register(new kF(this._bufferService,this._charsetService,this.coreService,this._logService,this.optionsService,this._oscLinkService,this.coreMouseService,this.unicodeService)),this._register(Is.forward(this._inputHandler.onLineFeed,this._onLineFeed)),this._register(this._inputHandler),this._register(Is.forward(this._bufferService.onResize,this._onResize)),this._register(Is.forward(this.coreService.onData,this._onData)),this._register(Is.forward(this.coreService.onBinary,this._onBinary)),this._register(this.coreService.onRequestScrollToBottom(()=>this.scrollToBottom(!0))),this._register(this.coreService.onUserInput(()=>this._writeBuffer.handleUserInput())),this._register(this.optionsService.onMultipleOptionChange(["windowsMode","windowsPty"],()=>this._handleWindowsPtyOptionChange())),this._register(this._bufferService.onScroll(()=>{this._onScroll.fire({position:this._bufferService.buffer.ydisp}),this._inputHandler.markRangeDirty(this._bufferService.buffer.scrollTop,this._bufferService.buffer.scrollBottom)})),this._writeBuffer=this._register(new EF((t,s)=>this._inputHandler.parse(t,s))),this._register(Is.forward(this._writeBuffer.onWriteParsed,this._onWriteParsed))}get onScroll(){return this._onScrollApi||(this._onScrollApi=this._register(new Ce),this._onScroll.event(e=>{var t;(t=this._onScrollApi)==null||t.fire(e.position)})),this._onScrollApi.event}get cols(){return this._bufferService.cols}get rows(){return this._bufferService.rows}get buffers(){return this._bufferService.buffers}get options(){return this.optionsService.options}set options(e){for(let t in e)this.optionsService.options[t]=e[t]}write(e,t){this._writeBuffer.write(e,t)}writeSync(e,t){this._logService.logLevel<=3&&!sS&&(this._logService.warn("writeSync is unreliable and will be removed soon."),sS=!0),this._writeBuffer.writeSync(e,t)}input(e,t=!0){this.coreService.triggerDataEvent(e,t)}resize(e,t){isNaN(e)||isNaN(t)||(e=Math.max(e,SN),t=Math.max(t,jN),this._bufferService.resize(e,t))}scroll(e,t=!1){this._bufferService.scroll(e,t)}scrollLines(e,t){this._bufferService.scrollLines(e,t)}scrollPages(e){this.scrollLines(e*(this.rows-1))}scrollToTop(){this.scrollLines(-this._bufferService.buffer.ydisp)}scrollToBottom(e){this.scrollLines(this._bufferService.buffer.ybase-this._bufferService.buffer.ydisp)}scrollToLine(e){let t=e-this._bufferService.buffer.ydisp;t!==0&&this.scrollLines(t)}registerEscHandler(e,t){return this._inputHandler.registerEscHandler(e,t)}registerDcsHandler(e,t){return this._inputHandler.registerDcsHandler(e,t)}registerCsiHandler(e,t){return this._inputHandler.registerCsiHandler(e,t)}registerOscHandler(e,t){return this._inputHandler.registerOscHandler(e,t)}_setup(){this._handleWindowsPtyOptionChange()}reset(){this._inputHandler.reset(),this._bufferService.reset(),this._charsetService.reset(),this.coreService.reset(),this.coreMouseService.reset()}_handleWindowsPtyOptionChange(){let e=!1,t=this.optionsService.rawOptions.windowsPty;t&&t.buildNumber!==void 0&&t.buildNumber!==void 0?e=t.backend==="conpty"&&t.buildNumber<21376:this.optionsService.rawOptions.windowsMode&&(e=!0),e?this._enableWindowsWrappingHeuristics():this._windowsWrappingHeuristics.clear()}_enableWindowsWrappingHeuristics(){if(!this._windowsWrappingHeuristics.value){let e=[];e.push(this.onLineFeed(G2.bind(null,this._bufferService))),e.push(this.registerCsiHandler({final:"H"},()=>(G2(this._bufferService),!1))),this._windowsWrappingHeuristics.value=Ut(()=>{for(let t of e)t.dispose()})}}},TF={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:["'",'"']};function AF(e,t,s,n){var c;let a={type:0,cancel:!1,key:void 0},l=(e.shiftKey?1:0)|(e.altKey?2:0)|(e.ctrlKey?4:0)|(e.metaKey?8:0);switch(e.keyCode){case 0:e.key==="UIKeyInputUpArrow"?t?a.key=xe.ESC+"OA":a.key=xe.ESC+"[A":e.key==="UIKeyInputLeftArrow"?t?a.key=xe.ESC+"OD":a.key=xe.ESC+"[D":e.key==="UIKeyInputRightArrow"?t?a.key=xe.ESC+"OC":a.key=xe.ESC+"[C":e.key==="UIKeyInputDownArrow"&&(t?a.key=xe.ESC+"OB":a.key=xe.ESC+"[B");break;case 8:a.key=e.ctrlKey?"\b":xe.DEL,e.altKey&&(a.key=xe.ESC+a.key);break;case 9:if(e.shiftKey){a.key=xe.ESC+"[Z";break}a.key=xe.HT,a.cancel=!0;break;case 13:a.key=e.altKey?xe.ESC+xe.CR:xe.CR,a.cancel=!0;break;case 27:a.key=xe.ESC,e.altKey&&(a.key=xe.ESC+xe.ESC),a.cancel=!0;break;case 37:if(e.metaKey)break;l?a.key=xe.ESC+"[1;"+(l+1)+"D":t?a.key=xe.ESC+"OD":a.key=xe.ESC+"[D";break;case 39:if(e.metaKey)break;l?a.key=xe.ESC+"[1;"+(l+1)+"C":t?a.key=xe.ESC+"OC":a.key=xe.ESC+"[C";break;case 38:if(e.metaKey)break;l?a.key=xe.ESC+"[1;"+(l+1)+"A":t?a.key=xe.ESC+"OA":a.key=xe.ESC+"[A";break;case 40:if(e.metaKey)break;l?a.key=xe.ESC+"[1;"+(l+1)+"B":t?a.key=xe.ESC+"OB":a.key=xe.ESC+"[B";break;case 45:!e.shiftKey&&!e.ctrlKey&&(a.key=xe.ESC+"[2~");break;case 46:l?a.key=xe.ESC+"[3;"+(l+1)+"~":a.key=xe.ESC+"[3~";break;case 36:l?a.key=xe.ESC+"[1;"+(l+1)+"H":t?a.key=xe.ESC+"OH":a.key=xe.ESC+"[H";break;case 35:l?a.key=xe.ESC+"[1;"+(l+1)+"F":t?a.key=xe.ESC+"OF":a.key=xe.ESC+"[F";break;case 33:e.shiftKey?a.type=2:e.ctrlKey?a.key=xe.ESC+"[5;"+(l+1)+"~":a.key=xe.ESC+"[5~";break;case 34:e.shiftKey?a.type=3:e.ctrlKey?a.key=xe.ESC+"[6;"+(l+1)+"~":a.key=xe.ESC+"[6~";break;case 112:l?a.key=xe.ESC+"[1;"+(l+1)+"P":a.key=xe.ESC+"OP";break;case 113:l?a.key=xe.ESC+"[1;"+(l+1)+"Q":a.key=xe.ESC+"OQ";break;case 114:l?a.key=xe.ESC+"[1;"+(l+1)+"R":a.key=xe.ESC+"OR";break;case 115:l?a.key=xe.ESC+"[1;"+(l+1)+"S":a.key=xe.ESC+"OS";break;case 116:l?a.key=xe.ESC+"[15;"+(l+1)+"~":a.key=xe.ESC+"[15~";break;case 117:l?a.key=xe.ESC+"[17;"+(l+1)+"~":a.key=xe.ESC+"[17~";break;case 118:l?a.key=xe.ESC+"[18;"+(l+1)+"~":a.key=xe.ESC+"[18~";break;case 119:l?a.key=xe.ESC+"[19;"+(l+1)+"~":a.key=xe.ESC+"[19~";break;case 120:l?a.key=xe.ESC+"[20;"+(l+1)+"~":a.key=xe.ESC+"[20~";break;case 121:l?a.key=xe.ESC+"[21;"+(l+1)+"~":a.key=xe.ESC+"[21~";break;case 122:l?a.key=xe.ESC+"[23;"+(l+1)+"~":a.key=xe.ESC+"[23~";break;case 123:l?a.key=xe.ESC+"[24;"+(l+1)+"~":a.key=xe.ESC+"[24~";break;default:if(e.ctrlKey&&!e.shiftKey&&!e.altKey&&!e.metaKey)e.keyCode>=65&&e.keyCode<=90?a.key=String.fromCharCode(e.keyCode-64):e.keyCode===32?a.key=xe.NUL:e.keyCode>=51&&e.keyCode<=55?a.key=String.fromCharCode(e.keyCode-51+27):e.keyCode===56?a.key=xe.DEL:e.keyCode===219?a.key=xe.ESC:e.keyCode===220?a.key=xe.FS:e.keyCode===221&&(a.key=xe.GS);else if((!s||n)&&e.altKey&&!e.metaKey){let d=(c=TF[e.keyCode])==null?void 0:c[e.shiftKey?1:0];if(d)a.key=xe.ESC+d;else if(e.keyCode>=65&&e.keyCode<=90){let f=e.ctrlKey?e.keyCode-64:e.keyCode+32,h=String.fromCharCode(f);e.shiftKey&&(h=h.toUpperCase()),a.key=xe.ESC+h}else if(e.keyCode===32)a.key=xe.ESC+(e.ctrlKey?xe.NUL:" ");else if(e.key==="Dead"&&e.code.startsWith("Key")){let f=e.code.slice(3,4);e.shiftKey||(f=f.toLowerCase()),a.key=xe.ESC+f,a.cancel=!0}}else s&&!e.altKey&&!e.ctrlKey&&!e.shiftKey&&e.metaKey?e.keyCode===65&&(a.type=1):e.key&&!e.ctrlKey&&!e.altKey&&!e.metaKey&&e.keyCode>=48&&e.key.length===1?a.key=e.key:e.key&&e.ctrlKey&&(e.key==="_"&&(a.key=xe.US),e.key==="@"&&(a.key=xe.NUL));break}return a}var as=0,RF=class{constructor(e){this._getKey=e,this._array=[],this._insertedValues=[],this._flushInsertedTask=new Fh,this._isFlushingInserted=!1,this._deletedIndices=[],this._flushDeletedTask=new Fh,this._isFlushingDeleted=!1}clear(){this._array.length=0,this._insertedValues.length=0,this._flushInsertedTask.clear(),this._isFlushingInserted=!1,this._deletedIndices.length=0,this._flushDeletedTask.clear(),this._isFlushingDeleted=!1}insert(e){this._flushCleanupDeleted(),this._insertedValues.length===0&&this._flushInsertedTask.enqueue(()=>this._flushInserted()),this._insertedValues.push(e)}_flushInserted(){let e=this._insertedValues.sort((a,l)=>this._getKey(a)-this._getKey(l)),t=0,s=0,n=new Array(this._array.length+this._insertedValues.length);for(let a=0;a<n.length;a++)s>=this._array.length||this._getKey(e[t])<=this._getKey(this._array[s])?(n[a]=e[t],t++):n[a]=this._array[s++];this._array=n,this._insertedValues.length=0}_flushCleanupInserted(){!this._isFlushingInserted&&this._insertedValues.length>0&&this._flushInsertedTask.flush()}delete(e){if(this._flushCleanupInserted(),this._array.length===0)return!1;let t=this._getKey(e);if(t===void 0||(as=this._search(t),as===-1)||this._getKey(this._array[as])!==t)return!1;do if(this._array[as]===e)return this._deletedIndices.length===0&&this._flushDeletedTask.enqueue(()=>this._flushDeleted()),this._deletedIndices.push(as),!0;while(++as<this._array.length&&this._getKey(this._array[as])===t);return!1}_flushDeleted(){this._isFlushingDeleted=!0;let e=this._deletedIndices.sort((a,l)=>a-l),t=0,s=new Array(this._array.length-e.length),n=0;for(let a=0;a<this._array.length;a++)e[t]===a?t++:s[n++]=this._array[a];this._array=s,this._deletedIndices.length=0,this._isFlushingDeleted=!1}_flushCleanupDeleted(){!this._isFlushingDeleted&&this._deletedIndices.length>0&&this._flushDeletedTask.flush()}*getKeyIterator(e){if(this._flushCleanupInserted(),this._flushCleanupDeleted(),this._array.length!==0&&(as=this._search(e),!(as<0||as>=this._array.length)&&this._getKey(this._array[as])===e))do yield this._array[as];while(++as<this._array.length&&this._getKey(this._array[as])===e)}forEachByKey(e,t){if(this._flushCleanupInserted(),this._flushCleanupDeleted(),this._array.length!==0&&(as=this._search(e),!(as<0||as>=this._array.length)&&this._getKey(this._array[as])===e))do t(this._array[as]);while(++as<this._array.length&&this._getKey(this._array[as])===e)}values(){return this._flushCleanupInserted(),this._flushCleanupDeleted(),[...this._array].values()}_search(e){let t=0,s=this._array.length-1;for(;s>=t;){let n=t+s>>1,a=this._getKey(this._array[n]);if(a>e)s=n-1;else if(a<e)t=n+1;else{for(;n>0&&this._getKey(this._array[n-1])===e;)n--;return n}}return t}},Rg=0,nS=0,DF=class extends nt{constructor(){super(),this._decorations=new RF(e=>e==null?void 0:e.marker.line),this._onDecorationRegistered=this._register(new Ce),this.onDecorationRegistered=this._onDecorationRegistered.event,this._onDecorationRemoved=this._register(new Ce),this.onDecorationRemoved=this._onDecorationRemoved.event,this._register(Ut(()=>this.reset()))}get decorations(){return this._decorations.values()}registerDecoration(e){if(e.marker.isDisposed)return;let t=new LF(e);if(t){let s=t.marker.onDispose(()=>t.dispose()),n=t.onDispose(()=>{n.dispose(),t&&(this._decorations.delete(t)&&this._onDecorationRemoved.fire(t),s.dispose())});this._decorations.insert(t),this._onDecorationRegistered.fire(t)}return t}reset(){for(let e of this._decorations.values())e.dispose();this._decorations.clear()}*getDecorationsAtCell(e,t,s){let n=0,a=0;for(let l of this._decorations.getKeyIterator(t))n=l.options.x??0,a=n+(l.options.width??1),e>=n&&e<a&&(!s||(l.options.layer??"bottom")===s)&&(yield l)}forEachDecorationAtCell(e,t,s,n){this._decorations.forEachByKey(t,a=>{Rg=a.options.x??0,nS=Rg+(a.options.width??1),e>=Rg&&e<nS&&(!s||(a.options.layer??"bottom")===s)&&n(a)})}},LF=class extends Yi{constructor(e){super(),this.options=e,this.onRenderEmitter=this.add(new Ce),this.onRender=this.onRenderEmitter.event,this._onDispose=this.add(new Ce),this.onDispose=this._onDispose.event,this._cachedBg=null,this._cachedFg=null,this.marker=e.marker,this.options.overviewRulerOptions&&!this.options.overviewRulerOptions.position&&(this.options.overviewRulerOptions.position="full")}get backgroundColorRGB(){return this._cachedBg===null&&(this.options.backgroundColor?this._cachedBg=Wt.toColor(this.options.backgroundColor):this._cachedBg=void 0),this._cachedBg}get foregroundColorRGB(){return this._cachedFg===null&&(this.options.foregroundColor?this._cachedFg=Wt.toColor(this.options.foregroundColor):this._cachedFg=void 0),this._cachedFg}dispose(){this._onDispose.fire(),super.dispose()}},BF=1e3,OF=class{constructor(e,t=BF){this._renderCallback=e,this._debounceThresholdMS=t,this._lastRefreshMs=0,this._additionalRefreshRequested=!1}dispose(){this._refreshTimeoutID&&clearTimeout(this._refreshTimeoutID)}refresh(e,t,s){this._rowCount=s,e=e!==void 0?e:0,t=t!==void 0?t:this._rowCount-1,this._rowStart=this._rowStart!==void 0?Math.min(this._rowStart,e):e,this._rowEnd=this._rowEnd!==void 0?Math.max(this._rowEnd,t):t;let n=performance.now();if(n-this._lastRefreshMs>=this._debounceThresholdMS)this._lastRefreshMs=n,this._innerRefresh();else if(!this._additionalRefreshRequested){let a=n-this._lastRefreshMs,l=this._debounceThresholdMS-a;this._additionalRefreshRequested=!0,this._refreshTimeoutID=window.setTimeout(()=>{this._lastRefreshMs=performance.now(),this._innerRefresh(),this._additionalRefreshRequested=!1,this._refreshTimeoutID=void 0},l)}}_innerRefresh(){if(this._rowStart===void 0||this._rowEnd===void 0||this._rowCount===void 0)return;let e=Math.max(this._rowStart,0),t=Math.min(this._rowEnd,this._rowCount-1);this._rowStart=void 0,this._rowEnd=void 0,this._renderCallback(e,t)}},rS=20,Hh=class extends nt{constructor(e,t,s,n){super(),this._terminal=e,this._coreBrowserService=s,this._renderService=n,this._rowColumns=new WeakMap,this._liveRegionLineCount=0,this._charsToConsume=[],this._charsToAnnounce="";let a=this._coreBrowserService.mainDocument;this._accessibilityContainer=a.createElement("div"),this._accessibilityContainer.classList.add("xterm-accessibility"),this._rowContainer=a.createElement("div"),this._rowContainer.setAttribute("role","list"),this._rowContainer.classList.add("xterm-accessibility-tree"),this._rowElements=[];for(let l=0;l<this._terminal.rows;l++)this._rowElements[l]=this._createAccessibilityTreeNode(),this._rowContainer.appendChild(this._rowElements[l]);if(this._topBoundaryFocusListener=l=>this._handleBoundaryFocus(l,0),this._bottomBoundaryFocusListener=l=>this._handleBoundaryFocus(l,1),this._rowElements[0].addEventListener("focus",this._topBoundaryFocusListener),this._rowElements[this._rowElements.length-1].addEventListener("focus",this._bottomBoundaryFocusListener),this._accessibilityContainer.appendChild(this._rowContainer),this._liveRegion=a.createElement("div"),this._liveRegion.classList.add("live-region"),this._liveRegion.setAttribute("aria-live","assertive"),this._accessibilityContainer.appendChild(this._liveRegion),this._liveRegionDebouncer=this._register(new OF(this._renderRows.bind(this))),!this._terminal.element)throw new Error("Cannot enable accessibility before Terminal.open");this._terminal.element.insertAdjacentElement("afterbegin",this._accessibilityContainer),this._register(this._terminal.onResize(l=>this._handleResize(l.rows))),this._register(this._terminal.onRender(l=>this._refreshRows(l.start,l.end))),this._register(this._terminal.onScroll(()=>this._refreshRows())),this._register(this._terminal.onA11yChar(l=>this._handleChar(l))),this._register(this._terminal.onLineFeed(()=>this._handleChar(`
|
|
256
|
+
`)}clearSelection(){this._model.clearSelection(),this._removeMouseDownListeners(),this.refresh(),this._onSelectionChange.fire()}refresh(e){this._refreshAnimationFrame||(this._refreshAnimationFrame=this._coreBrowserService.window.requestAnimationFrame(()=>this._refresh())),gv&&e&&this.selectionText.length&&this._onLinuxMouseSelection.fire(this.selectionText)}_refresh(){this._refreshAnimationFrame=void 0,this._onRedrawRequest.fire({start:this._model.finalSelectionStart,end:this._model.finalSelectionEnd,columnSelectMode:this._activeSelectionMode===3})}_isClickInSelection(e){let t=this._getMouseBufferCoords(e),s=this._model.finalSelectionStart,n=this._model.finalSelectionEnd;return!s||!n||!t?!1:this._areCoordsInSelection(t,s,n)}isCellInSelection(e,t){let s=this._model.finalSelectionStart,n=this._model.finalSelectionEnd;return!s||!n?!1:this._areCoordsInSelection([e,t],s,n)}_areCoordsInSelection(e,t,s){return e[1]>t[1]&&e[1]<s[1]||t[1]===s[1]&&e[1]===t[1]&&e[0]>=t[0]&&e[0]<s[0]||t[1]<s[1]&&e[1]===s[1]&&e[0]<s[0]||t[1]<s[1]&&e[1]===t[1]&&e[0]>=t[0]}_selectWordAtCursor(e,t){var a,l;let s=(l=(a=this._linkifier.currentLink)==null?void 0:a.link)==null?void 0:l.range;if(s)return this._model.selectionStart=[s.start.x-1,s.start.y-1],this._model.selectionStartLength=B2(s,this._bufferService.cols),this._model.selectionEnd=void 0,!0;let n=this._getMouseBufferCoords(e);return n?(this._selectWordAt(n,t),this._model.selectionEnd=void 0,!0):!1}selectAll(){this._model.isSelectAllActive=!0,this.refresh(),this._onSelectionChange.fire()}selectLines(e,t){this._model.clearSelection(),e=Math.max(e,0),t=Math.min(t,this._bufferService.buffer.lines.length-1),this._model.selectionStart=[0,e],this._model.selectionEnd=[this._bufferService.cols,t],this.refresh(),this._onSelectionChange.fire()}_handleTrim(e){this._model.handleTrim(e)&&this.refresh()}_getMouseBufferCoords(e){let t=this._mouseService.getCoords(e,this._screenElement,this._bufferService.cols,this._bufferService.rows,!0);if(t)return t[0]--,t[1]--,t[1]+=this._bufferService.buffer.ydisp,t}_getMouseEventScrollAmount(e){let t=mv(this._coreBrowserService.window,e,this._screenElement)[1],s=this._renderService.dimensions.css.canvas.height;return t>=0&&t<=s?0:(t>s&&(t-=s),t=Math.min(Math.max(t,-Cg),Cg),t/=Cg,t/Math.abs(t)+Math.round(t*(GI-1)))}shouldForceSelection(e){return Ih?e.altKey&&this._optionsService.rawOptions.macOptionClickForcesSelection:e.shiftKey}handleMouseDown(e){if(this._mouseDownTimeStamp=e.timeStamp,!(e.button===2&&this.hasSelection)&&e.button===0){if(!this._enabled){if(!this.shouldForceSelection(e))return;e.stopPropagation()}e.preventDefault(),this._dragScrollAmount=0,this._enabled&&e.shiftKey?this._handleIncrementalClick(e):e.detail===1?this._handleSingleClick(e):e.detail===2?this._handleDoubleClick(e):e.detail===3&&this._handleTripleClick(e),this._addMouseDownListeners(),this.refresh(!0)}}_addMouseDownListeners(){this._screenElement.ownerDocument&&(this._screenElement.ownerDocument.addEventListener("mousemove",this._mouseMoveListener),this._screenElement.ownerDocument.addEventListener("mouseup",this._mouseUpListener)),this._dragScrollIntervalTimer=this._coreBrowserService.window.setInterval(()=>this._dragScroll(),KI)}_removeMouseDownListeners(){this._screenElement.ownerDocument&&(this._screenElement.ownerDocument.removeEventListener("mousemove",this._mouseMoveListener),this._screenElement.ownerDocument.removeEventListener("mouseup",this._mouseUpListener)),this._coreBrowserService.window.clearInterval(this._dragScrollIntervalTimer),this._dragScrollIntervalTimer=void 0}_handleIncrementalClick(e){this._model.selectionStart&&(this._model.selectionEnd=this._getMouseBufferCoords(e))}_handleSingleClick(e){if(this._model.selectionStartLength=0,this._model.isSelectAllActive=!1,this._activeSelectionMode=this.shouldColumnSelect(e)?3:0,this._model.selectionStart=this._getMouseBufferCoords(e),!this._model.selectionStart)return;this._model.selectionEnd=void 0;let t=this._bufferService.buffer.lines.get(this._model.selectionStart[1]);t&&t.length!==this._model.selectionStart[0]&&t.hasWidth(this._model.selectionStart[0])===0&&this._model.selectionStart[0]++}_handleDoubleClick(e){this._selectWordAtCursor(e,!0)&&(this._activeSelectionMode=1)}_handleTripleClick(e){let t=this._getMouseBufferCoords(e);t&&(this._activeSelectionMode=2,this._selectLineAt(t[1]))}shouldColumnSelect(e){return e.altKey&&!(Ih&&this._optionsService.rawOptions.macOptionClickForcesSelection)}_handleMouseMove(e){if(e.stopImmediatePropagation(),!this._model.selectionStart)return;let t=this._model.selectionEnd?[this._model.selectionEnd[0],this._model.selectionEnd[1]]:null;if(this._model.selectionEnd=this._getMouseBufferCoords(e),!this._model.selectionEnd){this.refresh(!0);return}this._activeSelectionMode===2?this._model.selectionEnd[1]<this._model.selectionStart[1]?this._model.selectionEnd[0]=0:this._model.selectionEnd[0]=this._bufferService.cols:this._activeSelectionMode===1&&this._selectToWordAt(this._model.selectionEnd),this._dragScrollAmount=this._getMouseEventScrollAmount(e),this._activeSelectionMode!==3&&(this._dragScrollAmount>0?this._model.selectionEnd[0]=this._bufferService.cols:this._dragScrollAmount<0&&(this._model.selectionEnd[0]=0));let s=this._bufferService.buffer;if(this._model.selectionEnd[1]<s.lines.length){let n=s.lines.get(this._model.selectionEnd[1]);n&&n.hasWidth(this._model.selectionEnd[0])===0&&this._model.selectionEnd[0]<this._bufferService.cols&&this._model.selectionEnd[0]++}(!t||t[0]!==this._model.selectionEnd[0]||t[1]!==this._model.selectionEnd[1])&&this.refresh(!0)}_dragScroll(){if(!(!this._model.selectionEnd||!this._model.selectionStart)&&this._dragScrollAmount){this._onRequestScrollLines.fire({amount:this._dragScrollAmount,suppressScrollEvent:!1});let e=this._bufferService.buffer;this._dragScrollAmount>0?(this._activeSelectionMode!==3&&(this._model.selectionEnd[0]=this._bufferService.cols),this._model.selectionEnd[1]=Math.min(e.ydisp+this._bufferService.rows,e.lines.length-1)):(this._activeSelectionMode!==3&&(this._model.selectionEnd[0]=0),this._model.selectionEnd[1]=e.ydisp),this.refresh()}}_handleMouseUp(e){let t=e.timeStamp-this._mouseDownTimeStamp;if(this._removeMouseDownListeners(),this.selectionText.length<=1&&t<YI&&e.altKey&&this._optionsService.rawOptions.altClickMovesCursor){if(this._bufferService.buffer.ybase===this._bufferService.buffer.ydisp){let s=this._mouseService.getCoords(e,this._element,this._bufferService.cols,this._bufferService.rows,!1);if(s&&s[0]!==void 0&&s[1]!==void 0){let n=$I(s[0]-1,s[1]-1,this._bufferService,this._coreService.decPrivateModes.applicationCursorKeys);this._coreService.triggerDataEvent(n,!0)}}}else this._fireEventIfSelectionChanged()}_fireEventIfSelectionChanged(){let e=this._model.finalSelectionStart,t=this._model.finalSelectionEnd,s=!!e&&!!t&&(e[0]!==t[0]||e[1]!==t[1]);if(!s){this._oldHasSelection&&this._fireOnSelectionChange(e,t,s);return}!e||!t||(!this._oldSelectionStart||!this._oldSelectionEnd||e[0]!==this._oldSelectionStart[0]||e[1]!==this._oldSelectionStart[1]||t[0]!==this._oldSelectionEnd[0]||t[1]!==this._oldSelectionEnd[1])&&this._fireOnSelectionChange(e,t,s)}_fireOnSelectionChange(e,t,s){this._oldSelectionStart=e,this._oldSelectionEnd=t,this._oldHasSelection=s,this._onSelectionChange.fire()}_handleBufferActivate(e){this.clearSelection(),this._trimListener.dispose(),this._trimListener=e.activeBuffer.lines.onTrim(t=>this._handleTrim(t))}_convertViewportColToCharacterIndex(e,t){let s=t;for(let n=0;t>=n;n++){let a=e.loadCell(n,this._workCell).getChars().length;this._workCell.getWidth()===0?s--:a>1&&t!==n&&(s+=a-1)}return s}setSelection(e,t,s){this._model.clearSelection(),this._removeMouseDownListeners(),this._model.selectionStart=[e,t],this._model.selectionStartLength=s,this.refresh(),this._fireEventIfSelectionChanged()}rightClickSelect(e){this._isClickInSelection(e)||(this._selectWordAtCursor(e,!1)&&this.refresh(!0),this._fireEventIfSelectionChanged())}_getWordAt(e,t,s=!0,n=!0){if(e[0]>=this._bufferService.cols)return;let a=this._bufferService.buffer,l=a.lines.get(e[1]);if(!l)return;let c=a.translateBufferLineToString(e[1],!1),d=this._convertViewportColToCharacterIndex(l,e[0]),f=d,h=e[0]-d,m=0,g=0,b=0,v=0;if(c.charAt(d)===" "){for(;d>0&&c.charAt(d-1)===" ";)d--;for(;f<c.length&&c.charAt(f+1)===" ";)f++}else{let j=e[0],k=e[0];l.getWidth(j)===0&&(m++,j--),l.getWidth(k)===2&&(g++,k++);let E=l.getString(k).length;for(E>1&&(v+=E-1,f+=E-1);j>0&&d>0&&!this._isCharWordSeparator(l.loadCell(j-1,this._workCell));){l.loadCell(j-1,this._workCell);let N=this._workCell.getChars().length;this._workCell.getWidth()===0?(m++,j--):N>1&&(b+=N-1,d-=N-1),d--,j--}for(;k<l.length&&f+1<c.length&&!this._isCharWordSeparator(l.loadCell(k+1,this._workCell));){l.loadCell(k+1,this._workCell);let N=this._workCell.getChars().length;this._workCell.getWidth()===2?(g++,k++):N>1&&(v+=N-1,f+=N-1),f++,k++}}f++;let y=d+h-m+b,S=Math.min(this._bufferService.cols,f-d+m+g-b-v);if(!(!t&&c.slice(d,f).trim()==="")){if(s&&y===0&&l.getCodePoint(0)!==32){let j=a.lines.get(e[1]-1);if(j&&l.isWrapped&&j.getCodePoint(this._bufferService.cols-1)!==32){let k=this._getWordAt([this._bufferService.cols-1,e[1]-1],!1,!0,!1);if(k){let E=this._bufferService.cols-k.start;y-=E,S+=E}}}if(n&&y+S===this._bufferService.cols&&l.getCodePoint(this._bufferService.cols-1)!==32){let j=a.lines.get(e[1]+1);if(j!=null&&j.isWrapped&&j.getCodePoint(0)!==32){let k=this._getWordAt([0,e[1]+1],!1,!1,!0);k&&(S+=k.length)}}return{start:y,length:S}}}_selectWordAt(e,t){let s=this._getWordAt(e,t);if(s){for(;s.start<0;)s.start+=this._bufferService.cols,e[1]--;this._model.selectionStart=[s.start,e[1]],this._model.selectionStartLength=s.length}}_selectToWordAt(e){let t=this._getWordAt(e,!0);if(t){let s=e[1];for(;t.start<0;)t.start+=this._bufferService.cols,s--;if(!this._model.areSelectionValuesReversed())for(;t.start+t.length>this._bufferService.cols;)t.length-=this._bufferService.cols,s++;this._model.selectionEnd=[this._model.areSelectionValuesReversed()?t.start:t.start+t.length,s]}}_isCharWordSeparator(e){return e.getWidth()===0?!1:this._optionsService.rawOptions.wordSeparator.indexOf(e.getChars())>=0}_selectLineAt(e){let t=this._bufferService.buffer.getWrappedRangeForLine(e),s={start:{x:0,y:t.first},end:{x:this._bufferService.cols-1,y:t.last}};this._model.selectionStart=[0,t.first],this._model.selectionEnd=void 0,this._model.selectionStartLength=B2(s,this._bufferService.cols)}};a0=ts([Re(3,sn),Re(4,Ba),Re(5,lv),Re(6,nn),Re(7,oi),Re(8,ai)],a0);var O2=class{constructor(){this._data={}}set(e,t,s){this._data[e]||(this._data[e]={}),this._data[e][t]=s}get(e,t){return this._data[e]?this._data[e][t]:void 0}clear(){this._data={}}},z2=class{constructor(){this._color=new O2,this._css=new O2}setCss(e,t,s){this._css.set(e,t,s)}getCss(e,t){return this._css.get(e,t)}setColor(e,t,s){this._color.set(e,t,s)}getColor(e,t){return this._color.get(e,t)}clear(){this._color.clear(),this._css.clear()}},bs=Object.freeze((()=>{let e=[Wt.toColor("#2e3436"),Wt.toColor("#cc0000"),Wt.toColor("#4e9a06"),Wt.toColor("#c4a000"),Wt.toColor("#3465a4"),Wt.toColor("#75507b"),Wt.toColor("#06989a"),Wt.toColor("#d3d7cf"),Wt.toColor("#555753"),Wt.toColor("#ef2929"),Wt.toColor("#8ae234"),Wt.toColor("#fce94f"),Wt.toColor("#729fcf"),Wt.toColor("#ad7fa8"),Wt.toColor("#34e2e2"),Wt.toColor("#eeeeec")],t=[0,95,135,175,215,255];for(let s=0;s<216;s++){let n=t[s/36%6|0],a=t[s/6%6|0],l=t[s%6];e.push({css:ps.toCss(n,a,l),rgba:ps.toRgba(n,a,l)})}for(let s=0;s<24;s++){let n=8+s*10;e.push({css:ps.toCss(n,n,n),rgba:ps.toRgba(n,n,n)})}return e})()),wa=Wt.toColor("#ffffff"),Tc=Wt.toColor("#000000"),P2=Wt.toColor("#ffffff"),$2=Tc,fc={css:"rgba(255, 255, 255, 0.3)",rgba:4294967117},QI=wa,o0=class extends nt{constructor(e){super(),this._optionsService=e,this._contrastCache=new z2,this._halfContrastCache=new z2,this._onChangeColors=this._register(new Ce),this.onChangeColors=this._onChangeColors.event,this._colors={foreground:wa,background:Tc,cursor:P2,cursorAccent:$2,selectionForeground:void 0,selectionBackgroundTransparent:fc,selectionBackgroundOpaque:$t.blend(Tc,fc),selectionInactiveBackgroundTransparent:fc,selectionInactiveBackgroundOpaque:$t.blend(Tc,fc),scrollbarSliderBackground:$t.opacity(wa,.2),scrollbarSliderHoverBackground:$t.opacity(wa,.4),scrollbarSliderActiveBackground:$t.opacity(wa,.5),overviewRulerBorder:wa,ansi:bs.slice(),contrastCache:this._contrastCache,halfContrastCache:this._halfContrastCache},this._updateRestoreColors(),this._setTheme(this._optionsService.rawOptions.theme),this._register(this._optionsService.onSpecificOptionChange("minimumContrastRatio",()=>this._contrastCache.clear())),this._register(this._optionsService.onSpecificOptionChange("theme",()=>this._setTheme(this._optionsService.rawOptions.theme)))}get colors(){return this._colors}_setTheme(e={}){let t=this._colors;if(t.foreground=Et(e.foreground,wa),t.background=Et(e.background,Tc),t.cursor=$t.blend(t.background,Et(e.cursor,P2)),t.cursorAccent=$t.blend(t.background,Et(e.cursorAccent,$2)),t.selectionBackgroundTransparent=Et(e.selectionBackground,fc),t.selectionBackgroundOpaque=$t.blend(t.background,t.selectionBackgroundTransparent),t.selectionInactiveBackgroundTransparent=Et(e.selectionInactiveBackground,t.selectionBackgroundTransparent),t.selectionInactiveBackgroundOpaque=$t.blend(t.background,t.selectionInactiveBackgroundTransparent),t.selectionForeground=e.selectionForeground?Et(e.selectionForeground,R2):void 0,t.selectionForeground===R2&&(t.selectionForeground=void 0),$t.isOpaque(t.selectionBackgroundTransparent)&&(t.selectionBackgroundTransparent=$t.opacity(t.selectionBackgroundTransparent,.3)),$t.isOpaque(t.selectionInactiveBackgroundTransparent)&&(t.selectionInactiveBackgroundTransparent=$t.opacity(t.selectionInactiveBackgroundTransparent,.3)),t.scrollbarSliderBackground=Et(e.scrollbarSliderBackground,$t.opacity(t.foreground,.2)),t.scrollbarSliderHoverBackground=Et(e.scrollbarSliderHoverBackground,$t.opacity(t.foreground,.4)),t.scrollbarSliderActiveBackground=Et(e.scrollbarSliderActiveBackground,$t.opacity(t.foreground,.5)),t.overviewRulerBorder=Et(e.overviewRulerBorder,QI),t.ansi=bs.slice(),t.ansi[0]=Et(e.black,bs[0]),t.ansi[1]=Et(e.red,bs[1]),t.ansi[2]=Et(e.green,bs[2]),t.ansi[3]=Et(e.yellow,bs[3]),t.ansi[4]=Et(e.blue,bs[4]),t.ansi[5]=Et(e.magenta,bs[5]),t.ansi[6]=Et(e.cyan,bs[6]),t.ansi[7]=Et(e.white,bs[7]),t.ansi[8]=Et(e.brightBlack,bs[8]),t.ansi[9]=Et(e.brightRed,bs[9]),t.ansi[10]=Et(e.brightGreen,bs[10]),t.ansi[11]=Et(e.brightYellow,bs[11]),t.ansi[12]=Et(e.brightBlue,bs[12]),t.ansi[13]=Et(e.brightMagenta,bs[13]),t.ansi[14]=Et(e.brightCyan,bs[14]),t.ansi[15]=Et(e.brightWhite,bs[15]),e.extendedAnsi){let s=Math.min(t.ansi.length-16,e.extendedAnsi.length);for(let n=0;n<s;n++)t.ansi[n+16]=Et(e.extendedAnsi[n],bs[n+16])}this._contrastCache.clear(),this._halfContrastCache.clear(),this._updateRestoreColors(),this._onChangeColors.fire(this.colors)}restoreColor(e){this._restoreColor(e),this._onChangeColors.fire(this.colors)}_restoreColor(e){if(e===void 0){for(let t=0;t<this._restoreColors.ansi.length;++t)this._colors.ansi[t]=this._restoreColors.ansi[t];return}switch(e){case 256:this._colors.foreground=this._restoreColors.foreground;break;case 257:this._colors.background=this._restoreColors.background;break;case 258:this._colors.cursor=this._restoreColors.cursor;break;default:this._colors.ansi[e]=this._restoreColors.ansi[e]}}modifyColors(e){e(this._colors),this._onChangeColors.fire(this.colors)}_updateRestoreColors(){this._restoreColors={foreground:this._colors.foreground,background:this._colors.background,cursor:this._colors.cursor,ansi:this._colors.ansi.slice()}}};o0=ts([Re(0,nn)],o0);function Et(e,t){if(e!==void 0)try{return Wt.toColor(e)}catch{}return t}var ZI=class{constructor(...e){this._entries=new Map;for(let[t,s]of e)this.set(t,s)}set(e,t){let s=this._entries.get(e);return this._entries.set(e,t),s}forEach(e){for(let[t,s]of this._entries.entries())e(t,s)}has(e){return this._entries.has(e)}get(e){return this._entries.get(e)}},eF=class{constructor(){this._services=new ZI,this._services.set(ov,this)}setService(e,t){this._services.set(e,t)}getService(e){return this._services.get(e)}createInstance(e,...t){let s=G9(e).sort((l,c)=>l.index-c.index),n=[];for(let l of s){let c=this._services.get(l.id);if(!c)throw new Error(`[createInstance] ${e.name} depends on UNKNOWN service ${l.id._id}.`);n.push(c)}let a=s.length>0?s[0].index:t.length;if(t.length!==a)throw new Error(`[createInstance] First service dependency of ${e.name} at position ${a+1} conflicts with ${t.length} static arguments`);return new e(...t,...n)}},tF={trace:0,debug:1,info:2,warn:3,error:4,off:5},sF="xterm.js: ",l0=class extends nt{constructor(e){super(),this._optionsService=e,this._logLevel=5,this._updateLogLevel(),this._register(this._optionsService.onSpecificOptionChange("logLevel",()=>this._updateLogLevel()))}get logLevel(){return this._logLevel}_updateLogLevel(){this._logLevel=tF[this._optionsService.rawOptions.logLevel]}_evalLazyOptionalParams(e){for(let t=0;t<e.length;t++)typeof e[t]=="function"&&(e[t]=e[t]())}_log(e,t,s){this._evalLazyOptionalParams(s),e.call(console,(this._optionsService.options.logger?"":sF)+t,...s)}trace(e,...t){var s;this._logLevel<=0&&this._log(((s=this._optionsService.options.logger)==null?void 0:s.trace.bind(this._optionsService.options.logger))??console.log,e,t)}debug(e,...t){var s;this._logLevel<=1&&this._log(((s=this._optionsService.options.logger)==null?void 0:s.debug.bind(this._optionsService.options.logger))??console.log,e,t)}info(e,...t){var s;this._logLevel<=2&&this._log(((s=this._optionsService.options.logger)==null?void 0:s.info.bind(this._optionsService.options.logger))??console.info,e,t)}warn(e,...t){var s;this._logLevel<=3&&this._log(((s=this._optionsService.options.logger)==null?void 0:s.warn.bind(this._optionsService.options.logger))??console.warn,e,t)}error(e,...t){var s;this._logLevel<=4&&this._log(((s=this._optionsService.options.logger)==null?void 0:s.error.bind(this._optionsService.options.logger))??console.error,e,t)}};l0=ts([Re(0,nn)],l0);var I2=class extends nt{constructor(e){super(),this._maxLength=e,this.onDeleteEmitter=this._register(new Ce),this.onDelete=this.onDeleteEmitter.event,this.onInsertEmitter=this._register(new Ce),this.onInsert=this.onInsertEmitter.event,this.onTrimEmitter=this._register(new Ce),this.onTrim=this.onTrimEmitter.event,this._array=new Array(this._maxLength),this._startIndex=0,this._length=0}get maxLength(){return this._maxLength}set maxLength(e){if(this._maxLength===e)return;let t=new Array(e);for(let s=0;s<Math.min(e,this.length);s++)t[s]=this._array[this._getCyclicIndex(s)];this._array=t,this._maxLength=e,this._startIndex=0}get length(){return this._length}set length(e){if(e>this._length)for(let t=this._length;t<e;t++)this._array[t]=void 0;this._length=e}get(e){return this._array[this._getCyclicIndex(e)]}set(e,t){this._array[this._getCyclicIndex(e)]=t}push(e){this._array[this._getCyclicIndex(this._length)]=e,this._length===this._maxLength?(this._startIndex=++this._startIndex%this._maxLength,this.onTrimEmitter.fire(1)):this._length++}recycle(){if(this._length!==this._maxLength)throw new Error("Can only recycle when the buffer is full");return this._startIndex=++this._startIndex%this._maxLength,this.onTrimEmitter.fire(1),this._array[this._getCyclicIndex(this._length-1)]}get isFull(){return this._length===this._maxLength}pop(){return this._array[this._getCyclicIndex(this._length---1)]}splice(e,t,...s){if(t){for(let n=e;n<this._length-t;n++)this._array[this._getCyclicIndex(n)]=this._array[this._getCyclicIndex(n+t)];this._length-=t,this.onDeleteEmitter.fire({index:e,amount:t})}for(let n=this._length-1;n>=e;n--)this._array[this._getCyclicIndex(n+s.length)]=this._array[this._getCyclicIndex(n)];for(let n=0;n<s.length;n++)this._array[this._getCyclicIndex(e+n)]=s[n];if(s.length&&this.onInsertEmitter.fire({index:e,amount:s.length}),this._length+s.length>this._maxLength){let n=this._length+s.length-this._maxLength;this._startIndex+=n,this._length=this._maxLength,this.onTrimEmitter.fire(n)}else this._length+=s.length}trimStart(e){e>this._length&&(e=this._length),this._startIndex+=e,this._length-=e,this.onTrimEmitter.fire(e)}shiftElements(e,t,s){if(!(t<=0)){if(e<0||e>=this._length)throw new Error("start argument out of range");if(e+s<0)throw new Error("Cannot shift elements in list beyond index 0");if(s>0){for(let a=t-1;a>=0;a--)this.set(e+a+s,this.get(e+a));let n=e+t+s-this._length;if(n>0)for(this._length+=n;this._length>this._maxLength;)this._length--,this._startIndex++,this.onTrimEmitter.fire(1)}else for(let n=0;n<t;n++)this.set(e+n+s,this.get(e+n))}}_getCyclicIndex(e){return(this._startIndex+e)%this._maxLength}},st=3,fs=Object.freeze(new pu),Zd=0,Ng=2,Ac=class _N{constructor(t,s,n=!1){this.isWrapped=n,this._combined={},this._extendedAttrs={},this._data=new Uint32Array(t*st);let a=s||Jn.fromCharData([0,$C,1,0]);for(let l=0;l<t;++l)this.setCell(l,a);this.length=t}get(t){let s=this._data[t*st+0],n=s&2097151;return[this._data[t*st+1],s&2097152?this._combined[t]:n?Fi(n):"",s>>22,s&2097152?this._combined[t].charCodeAt(this._combined[t].length-1):n]}set(t,s){this._data[t*st+1]=s[0],s[1].length>1?(this._combined[t]=s[1],this._data[t*st+0]=t|2097152|s[2]<<22):this._data[t*st+0]=s[1].charCodeAt(0)|s[2]<<22}getWidth(t){return this._data[t*st+0]>>22}hasWidth(t){return this._data[t*st+0]&12582912}getFg(t){return this._data[t*st+1]}getBg(t){return this._data[t*st+2]}hasContent(t){return this._data[t*st+0]&4194303}getCodePoint(t){let s=this._data[t*st+0];return s&2097152?this._combined[t].charCodeAt(this._combined[t].length-1):s&2097151}isCombined(t){return this._data[t*st+0]&2097152}getString(t){let s=this._data[t*st+0];return s&2097152?this._combined[t]:s&2097151?Fi(s&2097151):""}isProtected(t){return this._data[t*st+2]&536870912}loadCell(t,s){return Zd=t*st,s.content=this._data[Zd+0],s.fg=this._data[Zd+1],s.bg=this._data[Zd+2],s.content&2097152&&(s.combinedData=this._combined[t]),s.bg&268435456&&(s.extended=this._extendedAttrs[t]),s}setCell(t,s){s.content&2097152&&(this._combined[t]=s.combinedData),s.bg&268435456&&(this._extendedAttrs[t]=s.extended),this._data[t*st+0]=s.content,this._data[t*st+1]=s.fg,this._data[t*st+2]=s.bg}setCellFromCodepoint(t,s,n,a){a.bg&268435456&&(this._extendedAttrs[t]=a.extended),this._data[t*st+0]=s|n<<22,this._data[t*st+1]=a.fg,this._data[t*st+2]=a.bg}addCodepointToCell(t,s,n){let a=this._data[t*st+0];a&2097152?this._combined[t]+=Fi(s):a&2097151?(this._combined[t]=Fi(a&2097151)+Fi(s),a&=-2097152,a|=2097152):a=s|1<<22,n&&(a&=-12582913,a|=n<<22),this._data[t*st+0]=a}insertCells(t,s,n){if(t%=this.length,t&&this.getWidth(t-1)===2&&this.setCellFromCodepoint(t-1,0,1,n),s<this.length-t){let a=new Jn;for(let l=this.length-t-s-1;l>=0;--l)this.setCell(t+s+l,this.loadCell(t+l,a));for(let l=0;l<s;++l)this.setCell(t+l,n)}else for(let a=t;a<this.length;++a)this.setCell(a,n);this.getWidth(this.length-1)===2&&this.setCellFromCodepoint(this.length-1,0,1,n)}deleteCells(t,s,n){if(t%=this.length,s<this.length-t){let a=new Jn;for(let l=0;l<this.length-t-s;++l)this.setCell(t+l,this.loadCell(t+s+l,a));for(let l=this.length-s;l<this.length;++l)this.setCell(l,n)}else for(let a=t;a<this.length;++a)this.setCell(a,n);t&&this.getWidth(t-1)===2&&this.setCellFromCodepoint(t-1,0,1,n),this.getWidth(t)===0&&!this.hasContent(t)&&this.setCellFromCodepoint(t,0,1,n)}replaceCells(t,s,n,a=!1){if(a){for(t&&this.getWidth(t-1)===2&&!this.isProtected(t-1)&&this.setCellFromCodepoint(t-1,0,1,n),s<this.length&&this.getWidth(s-1)===2&&!this.isProtected(s)&&this.setCellFromCodepoint(s,0,1,n);t<s&&t<this.length;)this.isProtected(t)||this.setCell(t,n),t++;return}for(t&&this.getWidth(t-1)===2&&this.setCellFromCodepoint(t-1,0,1,n),s<this.length&&this.getWidth(s-1)===2&&this.setCellFromCodepoint(s,0,1,n);t<s&&t<this.length;)this.setCell(t++,n)}resize(t,s){if(t===this.length)return this._data.length*4*Ng<this._data.buffer.byteLength;let n=t*st;if(t>this.length){if(this._data.buffer.byteLength>=n*4)this._data=new Uint32Array(this._data.buffer,0,n);else{let a=new Uint32Array(n);a.set(this._data),this._data=a}for(let a=this.length;a<t;++a)this.setCell(a,s)}else{this._data=this._data.subarray(0,n);let a=Object.keys(this._combined);for(let c=0;c<a.length;c++){let d=parseInt(a[c],10);d>=t&&delete this._combined[d]}let l=Object.keys(this._extendedAttrs);for(let c=0;c<l.length;c++){let d=parseInt(l[c],10);d>=t&&delete this._extendedAttrs[d]}}return this.length=t,n*4*Ng<this._data.buffer.byteLength}cleanupMemory(){if(this._data.length*4*Ng<this._data.buffer.byteLength){let t=new Uint32Array(this._data.length);return t.set(this._data),this._data=t,1}return 0}fill(t,s=!1){if(s){for(let n=0;n<this.length;++n)this.isProtected(n)||this.setCell(n,t);return}this._combined={},this._extendedAttrs={};for(let n=0;n<this.length;++n)this.setCell(n,t)}copyFrom(t){this.length!==t.length?this._data=new Uint32Array(t._data):this._data.set(t._data),this.length=t.length,this._combined={};for(let s in t._combined)this._combined[s]=t._combined[s];this._extendedAttrs={};for(let s in t._extendedAttrs)this._extendedAttrs[s]=t._extendedAttrs[s];this.isWrapped=t.isWrapped}clone(){let t=new _N(0);t._data=new Uint32Array(this._data),t.length=this.length;for(let s in this._combined)t._combined[s]=this._combined[s];for(let s in this._extendedAttrs)t._extendedAttrs[s]=this._extendedAttrs[s];return t.isWrapped=this.isWrapped,t}getTrimmedLength(){for(let t=this.length-1;t>=0;--t)if(this._data[t*st+0]&4194303)return t+(this._data[t*st+0]>>22);return 0}getNoBgTrimmedLength(){for(let t=this.length-1;t>=0;--t)if(this._data[t*st+0]&4194303||this._data[t*st+2]&50331648)return t+(this._data[t*st+0]>>22);return 0}copyCellsFrom(t,s,n,a,l){let c=t._data;if(l)for(let f=a-1;f>=0;f--){for(let h=0;h<st;h++)this._data[(n+f)*st+h]=c[(s+f)*st+h];c[(s+f)*st+2]&268435456&&(this._extendedAttrs[n+f]=t._extendedAttrs[s+f])}else for(let f=0;f<a;f++){for(let h=0;h<st;h++)this._data[(n+f)*st+h]=c[(s+f)*st+h];c[(s+f)*st+2]&268435456&&(this._extendedAttrs[n+f]=t._extendedAttrs[s+f])}let d=Object.keys(t._combined);for(let f=0;f<d.length;f++){let h=parseInt(d[f],10);h>=s&&(this._combined[h-s+n]=t._combined[h])}}translateToString(t,s,n,a){s=s??0,n=n??this.length,t&&(n=Math.min(n,this.getTrimmedLength())),a&&(a.length=0);let l="";for(;s<n;){let c=this._data[s*st+0],d=c&2097151,f=c&2097152?this._combined[s]:d?Fi(d):Vi;if(l+=f,a)for(let h=0;h<f.length;++h)a.push(s);s+=c>>22||1}return a&&a.push(s),l}};function nF(e,t,s,n,a,l){let c=[];for(let d=0;d<e.length-1;d++){let f=d,h=e.get(++f);if(!h.isWrapped)continue;let m=[e.get(d)];for(;f<e.length&&h.isWrapped;)m.push(h),h=e.get(++f);if(!l&&n>=d&&n<f){d+=m.length-1;continue}let g=0,b=su(m,g,t),v=1,y=0;for(;v<m.length;){let j=su(m,v,t),k=j-y,E=s-b,N=Math.min(k,E);m[g].copyCellsFrom(m[v],y,b,N,!1),b+=N,b===s&&(g++,b=0),y+=N,y===j&&(v++,y=0),b===0&&g!==0&&m[g-1].getWidth(s-1)===2&&(m[g].copyCellsFrom(m[g-1],s-1,b++,1,!1),m[g-1].setCell(s-1,a))}m[g].replaceCells(b,s,a);let S=0;for(let j=m.length-1;j>0&&(j>g||m[j].getTrimmedLength()===0);j--)S++;S>0&&(c.push(d+m.length-S),c.push(S)),d+=m.length-1}return c}function rF(e,t){let s=[],n=0,a=t[n],l=0;for(let c=0;c<e.length;c++)if(a===c){let d=t[++n];e.onDeleteEmitter.fire({index:c-l,amount:d}),c+=d-1,l+=d,a=t[++n]}else s.push(c);return{layout:s,countRemoved:l}}function iF(e,t){let s=[];for(let n=0;n<t.length;n++)s.push(e.get(t[n]));for(let n=0;n<s.length;n++)e.set(n,s[n]);e.length=t.length}function aF(e,t,s){let n=[],a=e.map((f,h)=>su(e,h,t)).reduce((f,h)=>f+h),l=0,c=0,d=0;for(;d<a;){if(a-d<s){n.push(a-d);break}l+=s;let f=su(e,c,t);l>f&&(l-=f,c++);let h=e[c].getWidth(l-1)===2;h&&l--;let m=h?s-1:s;n.push(m),d+=m}return n}function su(e,t,s){if(t===e.length-1)return e[t].getTrimmedLength();let n=!e[t].hasContent(s-1)&&e[t].getWidth(s-1)===1,a=e[t+1].getWidth(0)===2;return n&&a?s-1:s}var yN=class wN{constructor(t){this.line=t,this.isDisposed=!1,this._disposables=[],this._id=wN._nextId++,this._onDispose=this.register(new Ce),this.onDispose=this._onDispose.event}get id(){return this._id}dispose(){this.isDisposed||(this.isDisposed=!0,this.line=-1,this._onDispose.fire(),Ra(this._disposables),this._disposables.length=0)}register(t){return this._disposables.push(t),t}};yN._nextId=1;var oF=yN,Ss={},Sa=Ss.B;Ss[0]={"`":"◆",a:"▒",b:"␉",c:"␌",d:"␍",e:"␊",f:"°",g:"±",h:"",i:"␋",j:"┘",k:"┐",l:"┌",m:"└",n:"┼",o:"⎺",p:"⎻",q:"─",r:"⎼",s:"⎽",t:"├",u:"┤",v:"┴",w:"┬",x:"│",y:"≤",z:"≥","{":"π","|":"≠","}":"£","~":"·"};Ss.A={"#":"£"};Ss.B=void 0;Ss[4]={"#":"£","@":"¾","[":"ij","\\":"½","]":"|","{":"¨","|":"f","}":"¼","~":"´"};Ss.C=Ss[5]={"[":"Ä","\\":"Ö","]":"Å","^":"Ü","`":"é","{":"ä","|":"ö","}":"å","~":"ü"};Ss.R={"#":"£","@":"à","[":"°","\\":"ç","]":"§","{":"é","|":"ù","}":"è","~":"¨"};Ss.Q={"@":"à","[":"â","\\":"ç","]":"ê","^":"î","`":"ô","{":"é","|":"ù","}":"è","~":"û"};Ss.K={"@":"§","[":"Ä","\\":"Ö","]":"Ü","{":"ä","|":"ö","}":"ü","~":"ß"};Ss.Y={"#":"£","@":"§","[":"°","\\":"ç","]":"é","`":"ù","{":"à","|":"ò","}":"è","~":"ì"};Ss.E=Ss[6]={"@":"Ä","[":"Æ","\\":"Ø","]":"Å","^":"Ü","`":"ä","{":"æ","|":"ø","}":"å","~":"ü"};Ss.Z={"#":"£","@":"§","[":"¡","\\":"Ñ","]":"¿","{":"°","|":"ñ","}":"ç"};Ss.H=Ss[7]={"@":"É","[":"Ä","\\":"Ö","]":"Å","^":"Ü","`":"é","{":"ä","|":"ö","}":"å","~":"ü"};Ss["="]={"#":"ù","@":"à","[":"é","\\":"ç","]":"ê","^":"î",_:"è","`":"ô","{":"ä","|":"ö","}":"ü","~":"û"};var F2=4294967295,H2=class{constructor(e,t,s){this._hasScrollback=e,this._optionsService=t,this._bufferService=s,this.ydisp=0,this.ybase=0,this.y=0,this.x=0,this.tabs={},this.savedY=0,this.savedX=0,this.savedCurAttrData=fs.clone(),this.savedCharset=Sa,this.markers=[],this._nullCell=Jn.fromCharData([0,$C,1,0]),this._whitespaceCell=Jn.fromCharData([0,Vi,1,32]),this._isClearing=!1,this._memoryCleanupQueue=new Fh,this._memoryCleanupPosition=0,this._cols=this._bufferService.cols,this._rows=this._bufferService.rows,this.lines=new I2(this._getCorrectBufferLength(this._rows)),this.scrollTop=0,this.scrollBottom=this._rows-1,this.setupTabStops()}getNullCell(e){return e?(this._nullCell.fg=e.fg,this._nullCell.bg=e.bg,this._nullCell.extended=e.extended):(this._nullCell.fg=0,this._nullCell.bg=0,this._nullCell.extended=new zh),this._nullCell}getWhitespaceCell(e){return e?(this._whitespaceCell.fg=e.fg,this._whitespaceCell.bg=e.bg,this._whitespaceCell.extended=e.extended):(this._whitespaceCell.fg=0,this._whitespaceCell.bg=0,this._whitespaceCell.extended=new zh),this._whitespaceCell}getBlankLine(e,t){return new Ac(this._bufferService.cols,this.getNullCell(e),t)}get hasScrollback(){return this._hasScrollback&&this.lines.maxLength>this._rows}get isCursorInViewport(){let e=this.ybase+this.y-this.ydisp;return e>=0&&e<this._rows}_getCorrectBufferLength(e){if(!this._hasScrollback)return e;let t=e+this._optionsService.rawOptions.scrollback;return t>F2?F2:t}fillViewportRows(e){if(this.lines.length===0){e===void 0&&(e=fs);let t=this._rows;for(;t--;)this.lines.push(this.getBlankLine(e))}}clear(){this.ydisp=0,this.ybase=0,this.y=0,this.x=0,this.lines=new I2(this._getCorrectBufferLength(this._rows)),this.scrollTop=0,this.scrollBottom=this._rows-1,this.setupTabStops()}resize(e,t){let s=this.getNullCell(fs),n=0,a=this._getCorrectBufferLength(t);if(a>this.lines.maxLength&&(this.lines.maxLength=a),this.lines.length>0){if(this._cols<e)for(let c=0;c<this.lines.length;c++)n+=+this.lines.get(c).resize(e,s);let l=0;if(this._rows<t)for(let c=this._rows;c<t;c++)this.lines.length<t+this.ybase&&(this._optionsService.rawOptions.windowsMode||this._optionsService.rawOptions.windowsPty.backend!==void 0||this._optionsService.rawOptions.windowsPty.buildNumber!==void 0?this.lines.push(new Ac(e,s)):this.ybase>0&&this.lines.length<=this.ybase+this.y+l+1?(this.ybase--,l++,this.ydisp>0&&this.ydisp--):this.lines.push(new Ac(e,s)));else for(let c=this._rows;c>t;c--)this.lines.length>t+this.ybase&&(this.lines.length>this.ybase+this.y+1?this.lines.pop():(this.ybase++,this.ydisp++));if(a<this.lines.maxLength){let c=this.lines.length-a;c>0&&(this.lines.trimStart(c),this.ybase=Math.max(this.ybase-c,0),this.ydisp=Math.max(this.ydisp-c,0),this.savedY=Math.max(this.savedY-c,0)),this.lines.maxLength=a}this.x=Math.min(this.x,e-1),this.y=Math.min(this.y,t-1),l&&(this.y+=l),this.savedX=Math.min(this.savedX,e-1),this.scrollTop=0}if(this.scrollBottom=t-1,this._isReflowEnabled&&(this._reflow(e,t),this._cols>e))for(let l=0;l<this.lines.length;l++)n+=+this.lines.get(l).resize(e,s);this._cols=e,this._rows=t,this._memoryCleanupQueue.clear(),n>.1*this.lines.length&&(this._memoryCleanupPosition=0,this._memoryCleanupQueue.enqueue(()=>this._batchedMemoryCleanup()))}_batchedMemoryCleanup(){let e=!0;this._memoryCleanupPosition>=this.lines.length&&(this._memoryCleanupPosition=0,e=!1);let t=0;for(;this._memoryCleanupPosition<this.lines.length;)if(t+=this.lines.get(this._memoryCleanupPosition++).cleanupMemory(),t>100)return!0;return e}get _isReflowEnabled(){let e=this._optionsService.rawOptions.windowsPty;return e&&e.buildNumber?this._hasScrollback&&e.backend==="conpty"&&e.buildNumber>=21376:this._hasScrollback&&!this._optionsService.rawOptions.windowsMode}_reflow(e,t){this._cols!==e&&(e>this._cols?this._reflowLarger(e,t):this._reflowSmaller(e,t))}_reflowLarger(e,t){let s=this._optionsService.rawOptions.reflowCursorLine,n=nF(this.lines,this._cols,e,this.ybase+this.y,this.getNullCell(fs),s);if(n.length>0){let a=rF(this.lines,n);iF(this.lines,a.layout),this._reflowLargerAdjustViewport(e,t,a.countRemoved)}}_reflowLargerAdjustViewport(e,t,s){let n=this.getNullCell(fs),a=s;for(;a-- >0;)this.ybase===0?(this.y>0&&this.y--,this.lines.length<t&&this.lines.push(new Ac(e,n))):(this.ydisp===this.ybase&&this.ydisp--,this.ybase--);this.savedY=Math.max(this.savedY-s,0)}_reflowSmaller(e,t){let s=this._optionsService.rawOptions.reflowCursorLine,n=this.getNullCell(fs),a=[],l=0;for(let c=this.lines.length-1;c>=0;c--){let d=this.lines.get(c);if(!d||!d.isWrapped&&d.getTrimmedLength()<=e)continue;let f=[d];for(;d.isWrapped&&c>0;)d=this.lines.get(--c),f.unshift(d);if(!s){let N=this.ybase+this.y;if(N>=c&&N<c+f.length)continue}let h=f[f.length-1].getTrimmedLength(),m=aF(f,this._cols,e),g=m.length-f.length,b;this.ybase===0&&this.y!==this.lines.length-1?b=Math.max(0,this.y-this.lines.maxLength+g):b=Math.max(0,this.lines.length-this.lines.maxLength+g);let v=[];for(let N=0;N<g;N++){let B=this.getBlankLine(fs,!0);v.push(B)}v.length>0&&(a.push({start:c+f.length+l,newLines:v}),l+=v.length),f.push(...v);let y=m.length-1,S=m[y];S===0&&(y--,S=m[y]);let j=f.length-g-1,k=h;for(;j>=0;){let N=Math.min(k,S);if(f[y]===void 0)break;if(f[y].copyCellsFrom(f[j],k-N,S-N,N,!0),S-=N,S===0&&(y--,S=m[y]),k-=N,k===0){j--;let B=Math.max(j,0);k=su(f,B,this._cols)}}for(let N=0;N<f.length;N++)m[N]<e&&f[N].setCell(m[N],n);let E=g-b;for(;E-- >0;)this.ybase===0?this.y<t-1?(this.y++,this.lines.pop()):(this.ybase++,this.ydisp++):this.ybase<Math.min(this.lines.maxLength,this.lines.length+l)-t&&(this.ybase===this.ydisp&&this.ydisp++,this.ybase++);this.savedY=Math.min(this.savedY+g,this.ybase+t-1)}if(a.length>0){let c=[],d=[];for(let S=0;S<this.lines.length;S++)d.push(this.lines.get(S));let f=this.lines.length,h=f-1,m=0,g=a[m];this.lines.length=Math.min(this.lines.maxLength,this.lines.length+l);let b=0;for(let S=Math.min(this.lines.maxLength-1,f+l-1);S>=0;S--)if(g&&g.start>h+b){for(let j=g.newLines.length-1;j>=0;j--)this.lines.set(S--,g.newLines[j]);S++,c.push({index:h+1,amount:g.newLines.length}),b+=g.newLines.length,g=a[++m]}else this.lines.set(S,d[h--]);let v=0;for(let S=c.length-1;S>=0;S--)c[S].index+=v,this.lines.onInsertEmitter.fire(c[S]),v+=c[S].amount;let y=Math.max(0,f+l-this.lines.maxLength);y>0&&this.lines.onTrimEmitter.fire(y)}}translateBufferLineToString(e,t,s=0,n){let a=this.lines.get(e);return a?a.translateToString(t,s,n):""}getWrappedRangeForLine(e){let t=e,s=e;for(;t>0&&this.lines.get(t).isWrapped;)t--;for(;s+1<this.lines.length&&this.lines.get(s+1).isWrapped;)s++;return{first:t,last:s}}setupTabStops(e){for(e!=null?this.tabs[e]||(e=this.prevStop(e)):(this.tabs={},e=0);e<this._cols;e+=this._optionsService.rawOptions.tabStopWidth)this.tabs[e]=!0}prevStop(e){for(e==null&&(e=this.x);!this.tabs[--e]&&e>0;);return e>=this._cols?this._cols-1:e<0?0:e}nextStop(e){for(e==null&&(e=this.x);!this.tabs[++e]&&e<this._cols;);return e>=this._cols?this._cols-1:e<0?0:e}clearMarkers(e){this._isClearing=!0;for(let t=0;t<this.markers.length;t++)this.markers[t].line===e&&(this.markers[t].dispose(),this.markers.splice(t--,1));this._isClearing=!1}clearAllMarkers(){this._isClearing=!0;for(let e=0;e<this.markers.length;e++)this.markers[e].dispose();this.markers.length=0,this._isClearing=!1}addMarker(e){let t=new oF(e);return this.markers.push(t),t.register(this.lines.onTrim(s=>{t.line-=s,t.line<0&&t.dispose()})),t.register(this.lines.onInsert(s=>{t.line>=s.index&&(t.line+=s.amount)})),t.register(this.lines.onDelete(s=>{t.line>=s.index&&t.line<s.index+s.amount&&t.dispose(),t.line>s.index&&(t.line-=s.amount)})),t.register(t.onDispose(()=>this._removeMarker(t))),t}_removeMarker(e){this._isClearing||this.markers.splice(this.markers.indexOf(e),1)}},lF=class extends nt{constructor(e,t){super(),this._optionsService=e,this._bufferService=t,this._onBufferActivate=this._register(new Ce),this.onBufferActivate=this._onBufferActivate.event,this.reset(),this._register(this._optionsService.onSpecificOptionChange("scrollback",()=>this.resize(this._bufferService.cols,this._bufferService.rows))),this._register(this._optionsService.onSpecificOptionChange("tabStopWidth",()=>this.setupTabStops()))}reset(){this._normal=new H2(!0,this._optionsService,this._bufferService),this._normal.fillViewportRows(),this._alt=new H2(!1,this._optionsService,this._bufferService),this._activeBuffer=this._normal,this._onBufferActivate.fire({activeBuffer:this._normal,inactiveBuffer:this._alt}),this.setupTabStops()}get alt(){return this._alt}get active(){return this._activeBuffer}get normal(){return this._normal}activateNormalBuffer(){this._activeBuffer!==this._normal&&(this._normal.x=this._alt.x,this._normal.y=this._alt.y,this._alt.clearAllMarkers(),this._alt.clear(),this._activeBuffer=this._normal,this._onBufferActivate.fire({activeBuffer:this._normal,inactiveBuffer:this._alt}))}activateAltBuffer(e){this._activeBuffer!==this._alt&&(this._alt.fillViewportRows(e),this._alt.x=this._normal.x,this._alt.y=this._normal.y,this._activeBuffer=this._alt,this._onBufferActivate.fire({activeBuffer:this._alt,inactiveBuffer:this._normal}))}resize(e,t){this._normal.resize(e,t),this._alt.resize(e,t),this.setupTabStops(e)}setupTabStops(e){this._normal.setupTabStops(e),this._alt.setupTabStops(e)}},SN=2,jN=1,c0=class extends nt{constructor(e){super(),this.isUserScrolling=!1,this._onResize=this._register(new Ce),this.onResize=this._onResize.event,this._onScroll=this._register(new Ce),this.onScroll=this._onScroll.event,this.cols=Math.max(e.rawOptions.cols||0,SN),this.rows=Math.max(e.rawOptions.rows||0,jN),this.buffers=this._register(new lF(e,this)),this._register(this.buffers.onBufferActivate(t=>{this._onScroll.fire(t.activeBuffer.ydisp)}))}get buffer(){return this.buffers.active}resize(e,t){let s=this.cols!==e,n=this.rows!==t;this.cols=e,this.rows=t,this.buffers.resize(e,t),this._onResize.fire({cols:e,rows:t,colsChanged:s,rowsChanged:n})}reset(){this.buffers.reset(),this.isUserScrolling=!1}scroll(e,t=!1){let s=this.buffer,n;n=this._cachedBlankLine,(!n||n.length!==this.cols||n.getFg(0)!==e.fg||n.getBg(0)!==e.bg)&&(n=s.getBlankLine(e,t),this._cachedBlankLine=n),n.isWrapped=t;let a=s.ybase+s.scrollTop,l=s.ybase+s.scrollBottom;if(s.scrollTop===0){let c=s.lines.isFull;l===s.lines.length-1?c?s.lines.recycle().copyFrom(n):s.lines.push(n.clone()):s.lines.splice(l+1,0,n.clone()),c?this.isUserScrolling&&(s.ydisp=Math.max(s.ydisp-1,0)):(s.ybase++,this.isUserScrolling||s.ydisp++)}else{let c=l-a+1;s.lines.shiftElements(a+1,c-1,-1),s.lines.set(l,n.clone())}this.isUserScrolling||(s.ydisp=s.ybase),this._onScroll.fire(s.ydisp)}scrollLines(e,t){let s=this.buffer;if(e<0){if(s.ydisp===0)return;this.isUserScrolling=!0}else e+s.ydisp>=s.ybase&&(this.isUserScrolling=!1);let n=s.ydisp;s.ydisp=Math.max(Math.min(s.ydisp+e,s.ybase),0),n!==s.ydisp&&(t||this._onScroll.fire(s.ydisp))}};c0=ts([Re(0,nn)],c0);var Mo={cols:80,rows:24,cursorBlink:!1,cursorStyle:"block",cursorWidth:1,cursorInactiveStyle:"outline",customGlyphs:!0,drawBoldTextInBrightColors:!0,documentOverride:null,fastScrollModifier:"alt",fastScrollSensitivity:5,fontFamily:"monospace",fontSize:15,fontWeight:"normal",fontWeightBold:"bold",ignoreBracketedPasteMode:!1,lineHeight:1,letterSpacing:0,linkHandler:null,logLevel:"info",logger:null,scrollback:1e3,scrollOnEraseInDisplay:!1,scrollOnUserInput:!0,scrollSensitivity:1,screenReaderMode:!1,smoothScrollDuration:0,macOptionIsMeta:!1,macOptionClickForcesSelection:!1,minimumContrastRatio:1,disableStdin:!1,allowProposedApi:!1,allowTransparency:!1,tabStopWidth:8,theme:{},reflowCursorLine:!1,rescaleOverlappingGlyphs:!1,rightClickSelectsWord:Ih,windowOptions:{},windowsMode:!1,windowsPty:{},wordSeparator:" ()[]{}',\"`",altClickMovesCursor:!0,convertEol:!1,termName:"xterm",cancelEvents:!1,overviewRuler:{}},cF=["normal","bold","100","200","300","400","500","600","700","800","900"],uF=class extends nt{constructor(e){super(),this._onOptionChange=this._register(new Ce),this.onOptionChange=this._onOptionChange.event;let t={...Mo};for(let s in e)if(s in t)try{let n=e[s];t[s]=this._sanitizeAndValidateOption(s,n)}catch(n){console.error(n)}this.rawOptions=t,this.options={...t},this._setupOptions(),this._register(Ut(()=>{this.rawOptions.linkHandler=null,this.rawOptions.documentOverride=null}))}onSpecificOptionChange(e,t){return this.onOptionChange(s=>{s===e&&t(this.rawOptions[e])})}onMultipleOptionChange(e,t){return this.onOptionChange(s=>{e.indexOf(s)!==-1&&t()})}_setupOptions(){let e=s=>{if(!(s in Mo))throw new Error(`No option with key "${s}"`);return this.rawOptions[s]},t=(s,n)=>{if(!(s in Mo))throw new Error(`No option with key "${s}"`);n=this._sanitizeAndValidateOption(s,n),this.rawOptions[s]!==n&&(this.rawOptions[s]=n,this._onOptionChange.fire(s))};for(let s in this.rawOptions){let n={get:e.bind(this,s),set:t.bind(this,s)};Object.defineProperty(this.options,s,n)}}_sanitizeAndValidateOption(e,t){switch(e){case"cursorStyle":if(t||(t=Mo[e]),!dF(t))throw new Error(`"${t}" is not a valid value for ${e}`);break;case"wordSeparator":t||(t=Mo[e]);break;case"fontWeight":case"fontWeightBold":if(typeof t=="number"&&1<=t&&t<=1e3)break;t=cF.includes(t)?t:Mo[e];break;case"cursorWidth":t=Math.floor(t);case"lineHeight":case"tabStopWidth":if(t<1)throw new Error(`${e} cannot be less than 1, value: ${t}`);break;case"minimumContrastRatio":t=Math.max(1,Math.min(21,Math.round(t*10)/10));break;case"scrollback":if(t=Math.min(t,4294967295),t<0)throw new Error(`${e} cannot be less than 0, value: ${t}`);break;case"fastScrollSensitivity":case"scrollSensitivity":if(t<=0)throw new Error(`${e} cannot be less than or equal to 0, value: ${t}`);break;case"rows":case"cols":if(!t&&t!==0)throw new Error(`${e} must be numeric, value: ${t}`);break;case"windowsPty":t=t??{};break}return t}};function dF(e){return e==="block"||e==="underline"||e==="bar"}function Rc(e,t=5){if(typeof e!="object")return e;let s=Array.isArray(e)?[]:{};for(let n in e)s[n]=t<=1?e[n]:e[n]&&Rc(e[n],t-1);return s}var U2=Object.freeze({insertMode:!1}),V2=Object.freeze({applicationCursorKeys:!1,applicationKeypad:!1,bracketedPasteMode:!1,cursorBlink:void 0,cursorStyle:void 0,origin:!1,reverseWraparound:!1,sendFocus:!1,synchronizedOutput:!1,wraparound:!0}),u0=class extends nt{constructor(e,t,s){super(),this._bufferService=e,this._logService=t,this._optionsService=s,this.isCursorInitialized=!1,this.isCursorHidden=!1,this._onData=this._register(new Ce),this.onData=this._onData.event,this._onUserInput=this._register(new Ce),this.onUserInput=this._onUserInput.event,this._onBinary=this._register(new Ce),this.onBinary=this._onBinary.event,this._onRequestScrollToBottom=this._register(new Ce),this.onRequestScrollToBottom=this._onRequestScrollToBottom.event,this.modes=Rc(U2),this.decPrivateModes=Rc(V2)}reset(){this.modes=Rc(U2),this.decPrivateModes=Rc(V2)}triggerDataEvent(e,t=!1){if(this._optionsService.rawOptions.disableStdin)return;let s=this._bufferService.buffer;t&&this._optionsService.rawOptions.scrollOnUserInput&&s.ybase!==s.ydisp&&this._onRequestScrollToBottom.fire(),t&&this._onUserInput.fire(),this._logService.debug(`sending data "${e}"`),this._logService.trace("sending data (codes)",()=>e.split("").map(n=>n.charCodeAt(0))),this._onData.fire(e)}triggerBinaryEvent(e){this._optionsService.rawOptions.disableStdin||(this._logService.debug(`sending binary "${e}"`),this._logService.trace("sending binary (codes)",()=>e.split("").map(t=>t.charCodeAt(0))),this._onBinary.fire(e))}};u0=ts([Re(0,sn),Re(1,VC),Re(2,nn)],u0);var W2={NONE:{events:0,restrict:()=>!1},X10:{events:1,restrict:e=>e.button===4||e.action!==1?!1:(e.ctrl=!1,e.alt=!1,e.shift=!1,!0)},VT200:{events:19,restrict:e=>e.action!==32},DRAG:{events:23,restrict:e=>!(e.action===32&&e.button===3)},ANY:{events:31,restrict:e=>!0}};function Eg(e,t){let s=(e.ctrl?16:0)|(e.shift?4:0)|(e.alt?8:0);return e.button===4?(s|=64,s|=e.action):(s|=e.button&3,e.button&4&&(s|=64),e.button&8&&(s|=128),e.action===32?s|=32:e.action===0&&!t&&(s|=3)),s}var Mg=String.fromCharCode,q2={DEFAULT:e=>{let t=[Eg(e,!1)+32,e.col+32,e.row+32];return t[0]>255||t[1]>255||t[2]>255?"":`\x1B[M${Mg(t[0])}${Mg(t[1])}${Mg(t[2])}`},SGR:e=>{let t=e.action===0&&e.button!==4?"m":"M";return`\x1B[<${Eg(e,!0)};${e.col};${e.row}${t}`},SGR_PIXELS:e=>{let t=e.action===0&&e.button!==4?"m":"M";return`\x1B[<${Eg(e,!0)};${e.x};${e.y}${t}`}},d0=class extends nt{constructor(e,t,s){super(),this._bufferService=e,this._coreService=t,this._optionsService=s,this._protocols={},this._encodings={},this._activeProtocol="",this._activeEncoding="",this._lastEvent=null,this._wheelPartialScroll=0,this._onProtocolChange=this._register(new Ce),this.onProtocolChange=this._onProtocolChange.event;for(let n of Object.keys(W2))this.addProtocol(n,W2[n]);for(let n of Object.keys(q2))this.addEncoding(n,q2[n]);this.reset()}addProtocol(e,t){this._protocols[e]=t}addEncoding(e,t){this._encodings[e]=t}get activeProtocol(){return this._activeProtocol}get areMouseEventsActive(){return this._protocols[this._activeProtocol].events!==0}set activeProtocol(e){if(!this._protocols[e])throw new Error(`unknown protocol "${e}"`);this._activeProtocol=e,this._onProtocolChange.fire(this._protocols[e].events)}get activeEncoding(){return this._activeEncoding}set activeEncoding(e){if(!this._encodings[e])throw new Error(`unknown encoding "${e}"`);this._activeEncoding=e}reset(){this.activeProtocol="NONE",this.activeEncoding="DEFAULT",this._lastEvent=null,this._wheelPartialScroll=0}consumeWheelEvent(e,t,s){if(e.deltaY===0||e.shiftKey||t===void 0||s===void 0)return 0;let n=t/s,a=this._applyScrollModifier(e.deltaY,e);return e.deltaMode===WheelEvent.DOM_DELTA_PIXEL?(a/=n+0,Math.abs(e.deltaY)<50&&(a*=.3),this._wheelPartialScroll+=a,a=Math.floor(Math.abs(this._wheelPartialScroll))*(this._wheelPartialScroll>0?1:-1),this._wheelPartialScroll%=1):e.deltaMode===WheelEvent.DOM_DELTA_PAGE&&(a*=this._bufferService.rows),a}_applyScrollModifier(e,t){return t.altKey||t.ctrlKey||t.shiftKey?e*this._optionsService.rawOptions.fastScrollSensitivity*this._optionsService.rawOptions.scrollSensitivity:e*this._optionsService.rawOptions.scrollSensitivity}triggerMouseEvent(e){if(e.col<0||e.col>=this._bufferService.cols||e.row<0||e.row>=this._bufferService.rows||e.button===4&&e.action===32||e.button===3&&e.action!==32||e.button!==4&&(e.action===2||e.action===3)||(e.col++,e.row++,e.action===32&&this._lastEvent&&this._equalEvents(this._lastEvent,e,this._activeEncoding==="SGR_PIXELS"))||!this._protocols[this._activeProtocol].restrict(e))return!1;let t=this._encodings[this._activeEncoding](e);return t&&(this._activeEncoding==="DEFAULT"?this._coreService.triggerBinaryEvent(t):this._coreService.triggerDataEvent(t,!0)),this._lastEvent=e,!0}explainEvents(e){return{down:!!(e&1),up:!!(e&2),drag:!!(e&4),move:!!(e&8),wheel:!!(e&16)}}_equalEvents(e,t,s){if(s){if(e.x!==t.x||e.y!==t.y)return!1}else if(e.col!==t.col||e.row!==t.row)return!1;return!(e.button!==t.button||e.action!==t.action||e.ctrl!==t.ctrl||e.alt!==t.alt||e.shift!==t.shift)}};d0=ts([Re(0,sn),Re(1,Ba),Re(2,nn)],d0);var Tg=[[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]],hF=[[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]],_s;function fF(e,t){let s=0,n=t.length-1,a;if(e<t[0][0]||e>t[n][1])return!1;for(;n>=s;)if(a=s+n>>1,e>t[a][1])s=a+1;else if(e<t[a][0])n=a-1;else return!0;return!1}var pF=class{constructor(){if(this.version="6",!_s){_s=new Uint8Array(65536),_s.fill(1),_s[0]=0,_s.fill(0,1,32),_s.fill(0,127,160),_s.fill(2,4352,4448),_s[9001]=2,_s[9002]=2,_s.fill(2,11904,42192),_s[12351]=1,_s.fill(2,44032,55204),_s.fill(2,63744,64256),_s.fill(2,65040,65050),_s.fill(2,65072,65136),_s.fill(2,65280,65377),_s.fill(2,65504,65511);for(let e=0;e<Tg.length;++e)_s.fill(0,Tg[e][0],Tg[e][1]+1)}}wcwidth(e){return e<32?0:e<127?1:e<65536?_s[e]:fF(e,hF)?0:e>=131072&&e<=196605||e>=196608&&e<=262141?2:1}charProperties(e,t){let s=this.wcwidth(e),n=s===0&&t!==0;if(n){let a=ja.extractWidth(t);a===0?n=!1:a>s&&(s=a)}return ja.createPropertyValue(0,s,n)}},ja=class fh{constructor(){this._providers=Object.create(null),this._active="",this._onChange=new Ce,this.onChange=this._onChange.event;let t=new pF;this.register(t),this._active=t.version,this._activeProvider=t}static extractShouldJoin(t){return(t&1)!==0}static extractWidth(t){return t>>1&3}static extractCharKind(t){return t>>3}static createPropertyValue(t,s,n=!1){return(t&16777215)<<3|(s&3)<<1|(n?1:0)}dispose(){this._onChange.dispose()}get versions(){return Object.keys(this._providers)}get activeVersion(){return this._active}set activeVersion(t){if(!this._providers[t])throw new Error(`unknown Unicode version "${t}"`);this._active=t,this._activeProvider=this._providers[t],this._onChange.fire(t)}register(t){this._providers[t.version]=t}wcwidth(t){return this._activeProvider.wcwidth(t)}getStringCellWidth(t){let s=0,n=0,a=t.length;for(let l=0;l<a;++l){let c=t.charCodeAt(l);if(55296<=c&&c<=56319){if(++l>=a)return s+this.wcwidth(c);let h=t.charCodeAt(l);56320<=h&&h<=57343?c=(c-55296)*1024+h-56320+65536:s+=this.wcwidth(h)}let d=this.charProperties(c,n),f=fh.extractWidth(d);fh.extractShouldJoin(d)&&(f-=fh.extractWidth(n)),s+=f,n=d}return s}charProperties(t,s){return this._activeProvider.charProperties(t,s)}},mF=class{constructor(){this.glevel=0,this._charsets=[]}reset(){this.charset=void 0,this._charsets=[],this.glevel=0}setgLevel(e){this.glevel=e,this.charset=this._charsets[e]}setgCharset(e,t){this._charsets[e]=t,this.glevel===e&&(this.charset=t)}};function G2(e){var n;let t=(n=e.buffer.lines.get(e.buffer.ybase+e.buffer.y-1))==null?void 0:n.get(e.cols-1),s=e.buffer.lines.get(e.buffer.ybase+e.buffer.y);s&&t&&(s.isWrapped=t[3]!==0&&t[3]!==32)}var pc=2147483647,gF=256,kN=class h0{constructor(t=32,s=32){if(this.maxLength=t,this.maxSubParamsLength=s,s>gF)throw new Error("maxSubParamsLength must not be greater than 256");this.params=new Int32Array(t),this.length=0,this._subParams=new Int32Array(s),this._subParamsLength=0,this._subParamsIdx=new Uint16Array(t),this._rejectDigits=!1,this._rejectSubDigits=!1,this._digitIsSub=!1}static fromArray(t){let s=new h0;if(!t.length)return s;for(let n=Array.isArray(t[0])?1:0;n<t.length;++n){let a=t[n];if(Array.isArray(a))for(let l=0;l<a.length;++l)s.addSubParam(a[l]);else s.addParam(a)}return s}clone(){let t=new h0(this.maxLength,this.maxSubParamsLength);return t.params.set(this.params),t.length=this.length,t._subParams.set(this._subParams),t._subParamsLength=this._subParamsLength,t._subParamsIdx.set(this._subParamsIdx),t._rejectDigits=this._rejectDigits,t._rejectSubDigits=this._rejectSubDigits,t._digitIsSub=this._digitIsSub,t}toArray(){let t=[];for(let s=0;s<this.length;++s){t.push(this.params[s]);let n=this._subParamsIdx[s]>>8,a=this._subParamsIdx[s]&255;a-n>0&&t.push(Array.prototype.slice.call(this._subParams,n,a))}return t}reset(){this.length=0,this._subParamsLength=0,this._rejectDigits=!1,this._rejectSubDigits=!1,this._digitIsSub=!1}addParam(t){if(this._digitIsSub=!1,this.length>=this.maxLength){this._rejectDigits=!0;return}if(t<-1)throw new Error("values lesser than -1 are not allowed");this._subParamsIdx[this.length]=this._subParamsLength<<8|this._subParamsLength,this.params[this.length++]=t>pc?pc:t}addSubParam(t){if(this._digitIsSub=!0,!!this.length){if(this._rejectDigits||this._subParamsLength>=this.maxSubParamsLength){this._rejectSubDigits=!0;return}if(t<-1)throw new Error("values lesser than -1 are not allowed");this._subParams[this._subParamsLength++]=t>pc?pc:t,this._subParamsIdx[this.length-1]++}}hasSubParams(t){return(this._subParamsIdx[t]&255)-(this._subParamsIdx[t]>>8)>0}getSubParams(t){let s=this._subParamsIdx[t]>>8,n=this._subParamsIdx[t]&255;return n-s>0?this._subParams.subarray(s,n):null}getSubParamsAll(){let t={};for(let s=0;s<this.length;++s){let n=this._subParamsIdx[s]>>8,a=this._subParamsIdx[s]&255;a-n>0&&(t[s]=this._subParams.slice(n,a))}return t}addDigit(t){let s;if(this._rejectDigits||!(s=this._digitIsSub?this._subParamsLength:this.length)||this._digitIsSub&&this._rejectSubDigits)return;let n=this._digitIsSub?this._subParams:this.params,a=n[s-1];n[s-1]=~a?Math.min(a*10+t,pc):t}},mc=[],xF=class{constructor(){this._state=0,this._active=mc,this._id=-1,this._handlers=Object.create(null),this._handlerFb=()=>{},this._stack={paused:!1,loopPosition:0,fallThrough:!1}}registerHandler(e,t){this._handlers[e]===void 0&&(this._handlers[e]=[]);let s=this._handlers[e];return s.push(t),{dispose:()=>{let n=s.indexOf(t);n!==-1&&s.splice(n,1)}}}clearHandler(e){this._handlers[e]&&delete this._handlers[e]}setHandlerFallback(e){this._handlerFb=e}dispose(){this._handlers=Object.create(null),this._handlerFb=()=>{},this._active=mc}reset(){if(this._state===2)for(let e=this._stack.paused?this._stack.loopPosition-1:this._active.length-1;e>=0;--e)this._active[e].end(!1);this._stack.paused=!1,this._active=mc,this._id=-1,this._state=0}_start(){if(this._active=this._handlers[this._id]||mc,!this._active.length)this._handlerFb(this._id,"START");else for(let e=this._active.length-1;e>=0;e--)this._active[e].start()}_put(e,t,s){if(!this._active.length)this._handlerFb(this._id,"PUT",tf(e,t,s));else for(let n=this._active.length-1;n>=0;n--)this._active[n].put(e,t,s)}start(){this.reset(),this._state=1}put(e,t,s){if(this._state!==3){if(this._state===1)for(;t<s;){let n=e[t++];if(n===59){this._state=2,this._start();break}if(n<48||57<n){this._state=3;return}this._id===-1&&(this._id=0),this._id=this._id*10+n-48}this._state===2&&s-t>0&&this._put(e,t,s)}}end(e,t=!0){if(this._state!==0){if(this._state!==3)if(this._state===1&&this._start(),!this._active.length)this._handlerFb(this._id,"END",e);else{let s=!1,n=this._active.length-1,a=!1;if(this._stack.paused&&(n=this._stack.loopPosition-1,s=t,a=this._stack.fallThrough,this._stack.paused=!1),!a&&s===!1){for(;n>=0&&(s=this._active[n].end(e),s!==!0);n--)if(s instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=n,this._stack.fallThrough=!1,s;n--}for(;n>=0;n--)if(s=this._active[n].end(!1),s instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=n,this._stack.fallThrough=!0,s}this._active=mc,this._id=-1,this._state=0}}},En=class{constructor(e){this._handler=e,this._data="",this._hitLimit=!1}start(){this._data="",this._hitLimit=!1}put(e,t,s){this._hitLimit||(this._data+=tf(e,t,s),this._data.length>1e7&&(this._data="",this._hitLimit=!0))}end(e){let t=!1;if(this._hitLimit)t=!1;else if(e&&(t=this._handler(this._data),t instanceof Promise))return t.then(s=>(this._data="",this._hitLimit=!1,s));return this._data="",this._hitLimit=!1,t}},gc=[],vF=class{constructor(){this._handlers=Object.create(null),this._active=gc,this._ident=0,this._handlerFb=()=>{},this._stack={paused:!1,loopPosition:0,fallThrough:!1}}dispose(){this._handlers=Object.create(null),this._handlerFb=()=>{},this._active=gc}registerHandler(e,t){this._handlers[e]===void 0&&(this._handlers[e]=[]);let s=this._handlers[e];return s.push(t),{dispose:()=>{let n=s.indexOf(t);n!==-1&&s.splice(n,1)}}}clearHandler(e){this._handlers[e]&&delete this._handlers[e]}setHandlerFallback(e){this._handlerFb=e}reset(){if(this._active.length)for(let e=this._stack.paused?this._stack.loopPosition-1:this._active.length-1;e>=0;--e)this._active[e].unhook(!1);this._stack.paused=!1,this._active=gc,this._ident=0}hook(e,t){if(this.reset(),this._ident=e,this._active=this._handlers[e]||gc,!this._active.length)this._handlerFb(this._ident,"HOOK",t);else for(let s=this._active.length-1;s>=0;s--)this._active[s].hook(t)}put(e,t,s){if(!this._active.length)this._handlerFb(this._ident,"PUT",tf(e,t,s));else for(let n=this._active.length-1;n>=0;n--)this._active[n].put(e,t,s)}unhook(e,t=!0){if(!this._active.length)this._handlerFb(this._ident,"UNHOOK",e);else{let s=!1,n=this._active.length-1,a=!1;if(this._stack.paused&&(n=this._stack.loopPosition-1,s=t,a=this._stack.fallThrough,this._stack.paused=!1),!a&&s===!1){for(;n>=0&&(s=this._active[n].unhook(e),s!==!0);n--)if(s instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=n,this._stack.fallThrough=!1,s;n--}for(;n>=0;n--)if(s=this._active[n].unhook(!1),s instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=n,this._stack.fallThrough=!0,s}this._active=gc,this._ident=0}},Dc=new kN;Dc.addParam(0);var K2=class{constructor(e){this._handler=e,this._data="",this._params=Dc,this._hitLimit=!1}hook(e){this._params=e.length>1||e.params[0]?e.clone():Dc,this._data="",this._hitLimit=!1}put(e,t,s){this._hitLimit||(this._data+=tf(e,t,s),this._data.length>1e7&&(this._data="",this._hitLimit=!0))}unhook(e){let t=!1;if(this._hitLimit)t=!1;else if(e&&(t=this._handler(this._data,this._params),t instanceof Promise))return t.then(s=>(this._params=Dc,this._data="",this._hitLimit=!1,s));return this._params=Dc,this._data="",this._hitLimit=!1,t}},bF=class{constructor(e){this.table=new Uint8Array(e)}setDefault(e,t){this.table.fill(e<<4|t)}add(e,t,s,n){this.table[t<<8|e]=s<<4|n}addMany(e,t,s,n){for(let a=0;a<e.length;a++)this.table[t<<8|e[a]]=s<<4|n}},Gn=160,_F=(function(){let e=new bF(4095),t=Array.apply(null,Array(256)).map((d,f)=>f),s=(d,f)=>t.slice(d,f),n=s(32,127),a=s(0,24);a.push(25),a.push.apply(a,s(28,32));let l=s(0,14),c;e.setDefault(1,0),e.addMany(n,0,2,0);for(c in l)e.addMany([24,26,153,154],c,3,0),e.addMany(s(128,144),c,3,0),e.addMany(s(144,152),c,3,0),e.add(156,c,0,0),e.add(27,c,11,1),e.add(157,c,4,8),e.addMany([152,158,159],c,0,7),e.add(155,c,11,3),e.add(144,c,11,9);return e.addMany(a,0,3,0),e.addMany(a,1,3,1),e.add(127,1,0,1),e.addMany(a,8,0,8),e.addMany(a,3,3,3),e.add(127,3,0,3),e.addMany(a,4,3,4),e.add(127,4,0,4),e.addMany(a,6,3,6),e.addMany(a,5,3,5),e.add(127,5,0,5),e.addMany(a,2,3,2),e.add(127,2,0,2),e.add(93,1,4,8),e.addMany(n,8,5,8),e.add(127,8,5,8),e.addMany([156,27,24,26,7],8,6,0),e.addMany(s(28,32),8,0,8),e.addMany([88,94,95],1,0,7),e.addMany(n,7,0,7),e.addMany(a,7,0,7),e.add(156,7,0,0),e.add(127,7,0,7),e.add(91,1,11,3),e.addMany(s(64,127),3,7,0),e.addMany(s(48,60),3,8,4),e.addMany([60,61,62,63],3,9,4),e.addMany(s(48,60),4,8,4),e.addMany(s(64,127),4,7,0),e.addMany([60,61,62,63],4,0,6),e.addMany(s(32,64),6,0,6),e.add(127,6,0,6),e.addMany(s(64,127),6,0,0),e.addMany(s(32,48),3,9,5),e.addMany(s(32,48),5,9,5),e.addMany(s(48,64),5,0,6),e.addMany(s(64,127),5,7,0),e.addMany(s(32,48),4,9,5),e.addMany(s(32,48),1,9,2),e.addMany(s(32,48),2,9,2),e.addMany(s(48,127),2,10,0),e.addMany(s(48,80),1,10,0),e.addMany(s(81,88),1,10,0),e.addMany([89,90,92],1,10,0),e.addMany(s(96,127),1,10,0),e.add(80,1,11,9),e.addMany(a,9,0,9),e.add(127,9,0,9),e.addMany(s(28,32),9,0,9),e.addMany(s(32,48),9,9,12),e.addMany(s(48,60),9,8,10),e.addMany([60,61,62,63],9,9,10),e.addMany(a,11,0,11),e.addMany(s(32,128),11,0,11),e.addMany(s(28,32),11,0,11),e.addMany(a,10,0,10),e.add(127,10,0,10),e.addMany(s(28,32),10,0,10),e.addMany(s(48,60),10,8,10),e.addMany([60,61,62,63],10,0,11),e.addMany(s(32,48),10,9,12),e.addMany(a,12,0,12),e.add(127,12,0,12),e.addMany(s(28,32),12,0,12),e.addMany(s(32,48),12,9,12),e.addMany(s(48,64),12,0,11),e.addMany(s(64,127),12,12,13),e.addMany(s(64,127),10,12,13),e.addMany(s(64,127),9,12,13),e.addMany(a,13,13,13),e.addMany(n,13,13,13),e.add(127,13,0,13),e.addMany([27,156,24,26],13,14,0),e.add(Gn,0,2,0),e.add(Gn,8,5,8),e.add(Gn,6,0,6),e.add(Gn,11,0,11),e.add(Gn,13,13,13),e})(),yF=class extends nt{constructor(e=_F){super(),this._transitions=e,this._parseStack={state:0,handlers:[],handlerPos:0,transition:0,chunkPos:0},this.initialState=0,this.currentState=this.initialState,this._params=new kN,this._params.addParam(0),this._collect=0,this.precedingJoinState=0,this._printHandlerFb=(t,s,n)=>{},this._executeHandlerFb=t=>{},this._csiHandlerFb=(t,s)=>{},this._escHandlerFb=t=>{},this._errorHandlerFb=t=>t,this._printHandler=this._printHandlerFb,this._executeHandlers=Object.create(null),this._csiHandlers=Object.create(null),this._escHandlers=Object.create(null),this._register(Ut(()=>{this._csiHandlers=Object.create(null),this._executeHandlers=Object.create(null),this._escHandlers=Object.create(null)})),this._oscParser=this._register(new xF),this._dcsParser=this._register(new vF),this._errorHandler=this._errorHandlerFb,this.registerEscHandler({final:"\\"},()=>!0)}_identifier(e,t=[64,126]){let s=0;if(e.prefix){if(e.prefix.length>1)throw new Error("only one byte as prefix supported");if(s=e.prefix.charCodeAt(0),s&&60>s||s>63)throw new Error("prefix must be in range 0x3c .. 0x3f")}if(e.intermediates){if(e.intermediates.length>2)throw new Error("only two bytes as intermediates are supported");for(let a=0;a<e.intermediates.length;++a){let l=e.intermediates.charCodeAt(a);if(32>l||l>47)throw new Error("intermediate must be in range 0x20 .. 0x2f");s<<=8,s|=l}}if(e.final.length!==1)throw new Error("final must be a single byte");let n=e.final.charCodeAt(0);if(t[0]>n||n>t[1])throw new Error(`final must be in range ${t[0]} .. ${t[1]}`);return s<<=8,s|=n,s}identToString(e){let t=[];for(;e;)t.push(String.fromCharCode(e&255)),e>>=8;return t.reverse().join("")}setPrintHandler(e){this._printHandler=e}clearPrintHandler(){this._printHandler=this._printHandlerFb}registerEscHandler(e,t){let s=this._identifier(e,[48,126]);this._escHandlers[s]===void 0&&(this._escHandlers[s]=[]);let n=this._escHandlers[s];return n.push(t),{dispose:()=>{let a=n.indexOf(t);a!==-1&&n.splice(a,1)}}}clearEscHandler(e){this._escHandlers[this._identifier(e,[48,126])]&&delete this._escHandlers[this._identifier(e,[48,126])]}setEscHandlerFallback(e){this._escHandlerFb=e}setExecuteHandler(e,t){this._executeHandlers[e.charCodeAt(0)]=t}clearExecuteHandler(e){this._executeHandlers[e.charCodeAt(0)]&&delete this._executeHandlers[e.charCodeAt(0)]}setExecuteHandlerFallback(e){this._executeHandlerFb=e}registerCsiHandler(e,t){let s=this._identifier(e);this._csiHandlers[s]===void 0&&(this._csiHandlers[s]=[]);let n=this._csiHandlers[s];return n.push(t),{dispose:()=>{let a=n.indexOf(t);a!==-1&&n.splice(a,1)}}}clearCsiHandler(e){this._csiHandlers[this._identifier(e)]&&delete this._csiHandlers[this._identifier(e)]}setCsiHandlerFallback(e){this._csiHandlerFb=e}registerDcsHandler(e,t){return this._dcsParser.registerHandler(this._identifier(e),t)}clearDcsHandler(e){this._dcsParser.clearHandler(this._identifier(e))}setDcsHandlerFallback(e){this._dcsParser.setHandlerFallback(e)}registerOscHandler(e,t){return this._oscParser.registerHandler(e,t)}clearOscHandler(e){this._oscParser.clearHandler(e)}setOscHandlerFallback(e){this._oscParser.setHandlerFallback(e)}setErrorHandler(e){this._errorHandler=e}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(e,t,s,n,a){this._parseStack.state=e,this._parseStack.handlers=t,this._parseStack.handlerPos=s,this._parseStack.transition=n,this._parseStack.chunkPos=a}parse(e,t,s){let n=0,a=0,l=0,c;if(this._parseStack.state)if(this._parseStack.state===2)this._parseStack.state=0,l=this._parseStack.chunkPos+1;else{if(s===void 0||this._parseStack.state===1)throw this._parseStack.state=1,new Error("improper continuation due to previous async handler, giving up parsing");let d=this._parseStack.handlers,f=this._parseStack.handlerPos-1;switch(this._parseStack.state){case 3:if(s===!1&&f>-1){for(;f>=0&&(c=d[f](this._params),c!==!0);f--)if(c instanceof Promise)return this._parseStack.handlerPos=f,c}this._parseStack.handlers=[];break;case 4:if(s===!1&&f>-1){for(;f>=0&&(c=d[f](),c!==!0);f--)if(c instanceof Promise)return this._parseStack.handlerPos=f,c}this._parseStack.handlers=[];break;case 6:if(n=e[this._parseStack.chunkPos],c=this._dcsParser.unhook(n!==24&&n!==26,s),c)return c;n===27&&(this._parseStack.transition|=1),this._params.reset(),this._params.addParam(0),this._collect=0;break;case 5:if(n=e[this._parseStack.chunkPos],c=this._oscParser.end(n!==24&&n!==26,s),c)return c;n===27&&(this._parseStack.transition|=1),this._params.reset(),this._params.addParam(0),this._collect=0;break}this._parseStack.state=0,l=this._parseStack.chunkPos+1,this.precedingJoinState=0,this.currentState=this._parseStack.transition&15}for(let d=l;d<t;++d){switch(n=e[d],a=this._transitions.table[this.currentState<<8|(n<160?n:Gn)],a>>4){case 2:for(let b=d+1;;++b){if(b>=t||(n=e[b])<32||n>126&&n<Gn){this._printHandler(e,d,b),d=b-1;break}if(++b>=t||(n=e[b])<32||n>126&&n<Gn){this._printHandler(e,d,b),d=b-1;break}if(++b>=t||(n=e[b])<32||n>126&&n<Gn){this._printHandler(e,d,b),d=b-1;break}if(++b>=t||(n=e[b])<32||n>126&&n<Gn){this._printHandler(e,d,b),d=b-1;break}}break;case 3:this._executeHandlers[n]?this._executeHandlers[n]():this._executeHandlerFb(n),this.precedingJoinState=0;break;case 0:break;case 1:if(this._errorHandler({position:d,code:n,currentState:this.currentState,collect:this._collect,params:this._params,abort:!1}).abort)return;break;case 7:let f=this._csiHandlers[this._collect<<8|n],h=f?f.length-1:-1;for(;h>=0&&(c=f[h](this._params),c!==!0);h--)if(c instanceof Promise)return this._preserveStack(3,f,h,a,d),c;h<0&&this._csiHandlerFb(this._collect<<8|n,this._params),this.precedingJoinState=0;break;case 8:do switch(n){case 59:this._params.addParam(0);break;case 58:this._params.addSubParam(-1);break;default:this._params.addDigit(n-48)}while(++d<t&&(n=e[d])>47&&n<60);d--;break;case 9:this._collect<<=8,this._collect|=n;break;case 10:let m=this._escHandlers[this._collect<<8|n],g=m?m.length-1:-1;for(;g>=0&&(c=m[g](),c!==!0);g--)if(c instanceof Promise)return this._preserveStack(4,m,g,a,d),c;g<0&&this._escHandlerFb(this._collect<<8|n),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|n,this._params);break;case 13:for(let b=d+1;;++b)if(b>=t||(n=e[b])===24||n===26||n===27||n>127&&n<Gn){this._dcsParser.put(e,d,b),d=b-1;break}break;case 14:if(c=this._dcsParser.unhook(n!==24&&n!==26),c)return this._preserveStack(6,[],0,a,d),c;n===27&&(a|=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 b=d+1;;b++)if(b>=t||(n=e[b])<32||n>127&&n<Gn){this._oscParser.put(e,d,b),d=b-1;break}break;case 6:if(c=this._oscParser.end(n!==24&&n!==26),c)return this._preserveStack(5,[],0,a,d),c;n===27&&(a|=1),this._params.reset(),this._params.addParam(0),this._collect=0,this.precedingJoinState=0;break}this.currentState=a&15}}},wF=/^([\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})$/,SF=/^[\da-f]+$/;function Y2(e){if(!e)return;let t=e.toLowerCase();if(t.indexOf("rgb:")===0){t=t.slice(4);let s=wF.exec(t);if(s){let n=s[1]?15:s[4]?255:s[7]?4095:65535;return[Math.round(parseInt(s[1]||s[4]||s[7]||s[10],16)/n*255),Math.round(parseInt(s[2]||s[5]||s[8]||s[11],16)/n*255),Math.round(parseInt(s[3]||s[6]||s[9]||s[12],16)/n*255)]}}else if(t.indexOf("#")===0&&(t=t.slice(1),SF.exec(t)&&[3,6,9,12].includes(t.length))){let s=t.length/3,n=[0,0,0];for(let a=0;a<3;++a){let l=parseInt(t.slice(s*a,s*a+s),16);n[a]=s===1?l<<4:s===2?l:s===3?l>>4:l>>8}return n}}function Ag(e,t){let s=e.toString(16),n=s.length<2?"0"+s:s;switch(t){case 4:return s[0];case 8:return n;case 12:return(n+n).slice(0,3);default:return n+n}}function jF(e,t=16){let[s,n,a]=e;return`rgb:${Ag(s,t)}/${Ag(n,t)}/${Ag(a,t)}`}var kF={"(":0,")":1,"*":2,"+":3,"-":1,".":2},Pi=131072,X2=10;function J2(e,t){if(e>24)return t.setWinLines||!1;switch(e){case 1:return!!t.restoreWin;case 2:return!!t.minimizeWin;case 3:return!!t.setWinPosition;case 4:return!!t.setWinSizePixels;case 5:return!!t.raiseWin;case 6:return!!t.lowerWin;case 7:return!!t.refreshWin;case 8:return!!t.setWinSizeChars;case 9:return!!t.maximizeWin;case 10:return!!t.fullscreenWin;case 11:return!!t.getWinState;case 13:return!!t.getWinPosition;case 14:return!!t.getWinSizePixels;case 15:return!!t.getScreenSizePixels;case 16:return!!t.getCellSizePixels;case 18:return!!t.getWinSizeChars;case 19:return!!t.getScreenSizeChars;case 20:return!!t.getIconTitle;case 21:return!!t.getWinTitle;case 22:return!!t.pushTitle;case 23:return!!t.popTitle;case 24:return!!t.setWinLines}return!1}var Q2=5e3,Z2=0,CF=class extends nt{constructor(e,t,s,n,a,l,c,d,f=new yF){super(),this._bufferService=e,this._charsetService=t,this._coreService=s,this._logService=n,this._optionsService=a,this._oscLinkService=l,this._coreMouseService=c,this._unicodeService=d,this._parser=f,this._parseBuffer=new Uint32Array(4096),this._stringDecoder=new W9,this._utf8Decoder=new q9,this._windowTitle="",this._iconName="",this._windowTitleStack=[],this._iconNameStack=[],this._curAttrData=fs.clone(),this._eraseAttrDataInternal=fs.clone(),this._onRequestBell=this._register(new Ce),this.onRequestBell=this._onRequestBell.event,this._onRequestRefreshRows=this._register(new Ce),this.onRequestRefreshRows=this._onRequestRefreshRows.event,this._onRequestReset=this._register(new Ce),this.onRequestReset=this._onRequestReset.event,this._onRequestSendFocus=this._register(new Ce),this.onRequestSendFocus=this._onRequestSendFocus.event,this._onRequestSyncScrollBar=this._register(new Ce),this.onRequestSyncScrollBar=this._onRequestSyncScrollBar.event,this._onRequestWindowsOptionsReport=this._register(new Ce),this.onRequestWindowsOptionsReport=this._onRequestWindowsOptionsReport.event,this._onA11yChar=this._register(new Ce),this.onA11yChar=this._onA11yChar.event,this._onA11yTab=this._register(new Ce),this.onA11yTab=this._onA11yTab.event,this._onCursorMove=this._register(new Ce),this.onCursorMove=this._onCursorMove.event,this._onLineFeed=this._register(new Ce),this.onLineFeed=this._onLineFeed.event,this._onScroll=this._register(new Ce),this.onScroll=this._onScroll.event,this._onTitleChange=this._register(new Ce),this.onTitleChange=this._onTitleChange.event,this._onColor=this._register(new Ce),this.onColor=this._onColor.event,this._parseStack={paused:!1,cursorStartX:0,cursorStartY:0,decodedLength:0,position:0},this._specialColors=[256,257,258],this._register(this._parser),this._dirtyRowTracker=new f0(this._bufferService),this._activeBuffer=this._bufferService.buffer,this._register(this._bufferService.buffers.onBufferActivate(h=>this._activeBuffer=h.activeBuffer)),this._parser.setCsiHandlerFallback((h,m)=>{this._logService.debug("Unknown CSI code: ",{identifier:this._parser.identToString(h),params:m.toArray()})}),this._parser.setEscHandlerFallback(h=>{this._logService.debug("Unknown ESC code: ",{identifier:this._parser.identToString(h)})}),this._parser.setExecuteHandlerFallback(h=>{this._logService.debug("Unknown EXECUTE code: ",{code:h})}),this._parser.setOscHandlerFallback((h,m,g)=>{this._logService.debug("Unknown OSC code: ",{identifier:h,action:m,data:g})}),this._parser.setDcsHandlerFallback((h,m,g)=>{m==="HOOK"&&(g=g.toArray()),this._logService.debug("Unknown DCS code: ",{identifier:this._parser.identToString(h),action:m,payload:g})}),this._parser.setPrintHandler((h,m,g)=>this.print(h,m,g)),this._parser.registerCsiHandler({final:"@"},h=>this.insertChars(h)),this._parser.registerCsiHandler({intermediates:" ",final:"@"},h=>this.scrollLeft(h)),this._parser.registerCsiHandler({final:"A"},h=>this.cursorUp(h)),this._parser.registerCsiHandler({intermediates:" ",final:"A"},h=>this.scrollRight(h)),this._parser.registerCsiHandler({final:"B"},h=>this.cursorDown(h)),this._parser.registerCsiHandler({final:"C"},h=>this.cursorForward(h)),this._parser.registerCsiHandler({final:"D"},h=>this.cursorBackward(h)),this._parser.registerCsiHandler({final:"E"},h=>this.cursorNextLine(h)),this._parser.registerCsiHandler({final:"F"},h=>this.cursorPrecedingLine(h)),this._parser.registerCsiHandler({final:"G"},h=>this.cursorCharAbsolute(h)),this._parser.registerCsiHandler({final:"H"},h=>this.cursorPosition(h)),this._parser.registerCsiHandler({final:"I"},h=>this.cursorForwardTab(h)),this._parser.registerCsiHandler({final:"J"},h=>this.eraseInDisplay(h,!1)),this._parser.registerCsiHandler({prefix:"?",final:"J"},h=>this.eraseInDisplay(h,!0)),this._parser.registerCsiHandler({final:"K"},h=>this.eraseInLine(h,!1)),this._parser.registerCsiHandler({prefix:"?",final:"K"},h=>this.eraseInLine(h,!0)),this._parser.registerCsiHandler({final:"L"},h=>this.insertLines(h)),this._parser.registerCsiHandler({final:"M"},h=>this.deleteLines(h)),this._parser.registerCsiHandler({final:"P"},h=>this.deleteChars(h)),this._parser.registerCsiHandler({final:"S"},h=>this.scrollUp(h)),this._parser.registerCsiHandler({final:"T"},h=>this.scrollDown(h)),this._parser.registerCsiHandler({final:"X"},h=>this.eraseChars(h)),this._parser.registerCsiHandler({final:"Z"},h=>this.cursorBackwardTab(h)),this._parser.registerCsiHandler({final:"`"},h=>this.charPosAbsolute(h)),this._parser.registerCsiHandler({final:"a"},h=>this.hPositionRelative(h)),this._parser.registerCsiHandler({final:"b"},h=>this.repeatPrecedingCharacter(h)),this._parser.registerCsiHandler({final:"c"},h=>this.sendDeviceAttributesPrimary(h)),this._parser.registerCsiHandler({prefix:">",final:"c"},h=>this.sendDeviceAttributesSecondary(h)),this._parser.registerCsiHandler({final:"d"},h=>this.linePosAbsolute(h)),this._parser.registerCsiHandler({final:"e"},h=>this.vPositionRelative(h)),this._parser.registerCsiHandler({final:"f"},h=>this.hVPosition(h)),this._parser.registerCsiHandler({final:"g"},h=>this.tabClear(h)),this._parser.registerCsiHandler({final:"h"},h=>this.setMode(h)),this._parser.registerCsiHandler({prefix:"?",final:"h"},h=>this.setModePrivate(h)),this._parser.registerCsiHandler({final:"l"},h=>this.resetMode(h)),this._parser.registerCsiHandler({prefix:"?",final:"l"},h=>this.resetModePrivate(h)),this._parser.registerCsiHandler({final:"m"},h=>this.charAttributes(h)),this._parser.registerCsiHandler({final:"n"},h=>this.deviceStatus(h)),this._parser.registerCsiHandler({prefix:"?",final:"n"},h=>this.deviceStatusPrivate(h)),this._parser.registerCsiHandler({intermediates:"!",final:"p"},h=>this.softReset(h)),this._parser.registerCsiHandler({intermediates:" ",final:"q"},h=>this.setCursorStyle(h)),this._parser.registerCsiHandler({final:"r"},h=>this.setScrollRegion(h)),this._parser.registerCsiHandler({final:"s"},h=>this.saveCursor(h)),this._parser.registerCsiHandler({final:"t"},h=>this.windowOptions(h)),this._parser.registerCsiHandler({final:"u"},h=>this.restoreCursor(h)),this._parser.registerCsiHandler({intermediates:"'",final:"}"},h=>this.insertColumns(h)),this._parser.registerCsiHandler({intermediates:"'",final:"~"},h=>this.deleteColumns(h)),this._parser.registerCsiHandler({intermediates:'"',final:"q"},h=>this.selectProtected(h)),this._parser.registerCsiHandler({intermediates:"$",final:"p"},h=>this.requestMode(h,!0)),this._parser.registerCsiHandler({prefix:"?",intermediates:"$",final:"p"},h=>this.requestMode(h,!1)),this._parser.setExecuteHandler(xe.BEL,()=>this.bell()),this._parser.setExecuteHandler(xe.LF,()=>this.lineFeed()),this._parser.setExecuteHandler(xe.VT,()=>this.lineFeed()),this._parser.setExecuteHandler(xe.FF,()=>this.lineFeed()),this._parser.setExecuteHandler(xe.CR,()=>this.carriageReturn()),this._parser.setExecuteHandler(xe.BS,()=>this.backspace()),this._parser.setExecuteHandler(xe.HT,()=>this.tab()),this._parser.setExecuteHandler(xe.SO,()=>this.shiftOut()),this._parser.setExecuteHandler(xe.SI,()=>this.shiftIn()),this._parser.setExecuteHandler(dh.IND,()=>this.index()),this._parser.setExecuteHandler(dh.NEL,()=>this.nextLine()),this._parser.setExecuteHandler(dh.HTS,()=>this.tabSet()),this._parser.registerOscHandler(0,new En(h=>(this.setTitle(h),this.setIconName(h),!0))),this._parser.registerOscHandler(1,new En(h=>this.setIconName(h))),this._parser.registerOscHandler(2,new En(h=>this.setTitle(h))),this._parser.registerOscHandler(4,new En(h=>this.setOrReportIndexedColor(h))),this._parser.registerOscHandler(8,new En(h=>this.setHyperlink(h))),this._parser.registerOscHandler(10,new En(h=>this.setOrReportFgColor(h))),this._parser.registerOscHandler(11,new En(h=>this.setOrReportBgColor(h))),this._parser.registerOscHandler(12,new En(h=>this.setOrReportCursorColor(h))),this._parser.registerOscHandler(104,new En(h=>this.restoreIndexedColor(h))),this._parser.registerOscHandler(110,new En(h=>this.restoreFgColor(h))),this._parser.registerOscHandler(111,new En(h=>this.restoreBgColor(h))),this._parser.registerOscHandler(112,new En(h=>this.restoreCursorColor(h))),this._parser.registerEscHandler({final:"7"},()=>this.saveCursor()),this._parser.registerEscHandler({final:"8"},()=>this.restoreCursor()),this._parser.registerEscHandler({final:"D"},()=>this.index()),this._parser.registerEscHandler({final:"E"},()=>this.nextLine()),this._parser.registerEscHandler({final:"H"},()=>this.tabSet()),this._parser.registerEscHandler({final:"M"},()=>this.reverseIndex()),this._parser.registerEscHandler({final:"="},()=>this.keypadApplicationMode()),this._parser.registerEscHandler({final:">"},()=>this.keypadNumericMode()),this._parser.registerEscHandler({final:"c"},()=>this.fullReset()),this._parser.registerEscHandler({final:"n"},()=>this.setgLevel(2)),this._parser.registerEscHandler({final:"o"},()=>this.setgLevel(3)),this._parser.registerEscHandler({final:"|"},()=>this.setgLevel(3)),this._parser.registerEscHandler({final:"}"},()=>this.setgLevel(2)),this._parser.registerEscHandler({final:"~"},()=>this.setgLevel(1)),this._parser.registerEscHandler({intermediates:"%",final:"@"},()=>this.selectDefaultCharset()),this._parser.registerEscHandler({intermediates:"%",final:"G"},()=>this.selectDefaultCharset());for(let h in Ss)this._parser.registerEscHandler({intermediates:"(",final:h},()=>this.selectCharset("("+h)),this._parser.registerEscHandler({intermediates:")",final:h},()=>this.selectCharset(")"+h)),this._parser.registerEscHandler({intermediates:"*",final:h},()=>this.selectCharset("*"+h)),this._parser.registerEscHandler({intermediates:"+",final:h},()=>this.selectCharset("+"+h)),this._parser.registerEscHandler({intermediates:"-",final:h},()=>this.selectCharset("-"+h)),this._parser.registerEscHandler({intermediates:".",final:h},()=>this.selectCharset("."+h)),this._parser.registerEscHandler({intermediates:"/",final:h},()=>this.selectCharset("/"+h));this._parser.registerEscHandler({intermediates:"#",final:"8"},()=>this.screenAlignmentPattern()),this._parser.setErrorHandler(h=>(this._logService.error("Parsing error: ",h),h)),this._parser.registerDcsHandler({intermediates:"$",final:"q"},new K2((h,m)=>this.requestStatusString(h,m)))}getAttrData(){return this._curAttrData}_preserveStack(e,t,s,n){this._parseStack.paused=!0,this._parseStack.cursorStartX=e,this._parseStack.cursorStartY=t,this._parseStack.decodedLength=s,this._parseStack.position=n}_logSlowResolvingAsync(e){this._logService.logLevel<=3&&Promise.race([e,new Promise((t,s)=>setTimeout(()=>s("#SLOW_TIMEOUT"),Q2))]).catch(t=>{if(t!=="#SLOW_TIMEOUT")throw t;console.warn(`async parser handler taking longer than ${Q2} ms`)})}_getCurrentLinkId(){return this._curAttrData.extended.urlId}parse(e,t){let s,n=this._activeBuffer.x,a=this._activeBuffer.y,l=0,c=this._parseStack.paused;if(c){if(s=this._parser.parse(this._parseBuffer,this._parseStack.decodedLength,t))return this._logSlowResolvingAsync(s),s;n=this._parseStack.cursorStartX,a=this._parseStack.cursorStartY,this._parseStack.paused=!1,e.length>Pi&&(l=this._parseStack.position+Pi)}if(this._logService.logLevel<=1&&this._logService.debug(`parsing data ${typeof e=="string"?` "${e}"`:` "${Array.prototype.map.call(e,h=>String.fromCharCode(h)).join("")}"`}`),this._logService.logLevel===0&&this._logService.trace("parsing data (codes)",typeof e=="string"?e.split("").map(h=>h.charCodeAt(0)):e),this._parseBuffer.length<e.length&&this._parseBuffer.length<Pi&&(this._parseBuffer=new Uint32Array(Math.min(e.length,Pi))),c||this._dirtyRowTracker.clearRange(),e.length>Pi)for(let h=l;h<e.length;h+=Pi){let m=h+Pi<e.length?h+Pi:e.length,g=typeof e=="string"?this._stringDecoder.decode(e.substring(h,m),this._parseBuffer):this._utf8Decoder.decode(e.subarray(h,m),this._parseBuffer);if(s=this._parser.parse(this._parseBuffer,g))return this._preserveStack(n,a,g,h),this._logSlowResolvingAsync(s),s}else if(!c){let h=typeof e=="string"?this._stringDecoder.decode(e,this._parseBuffer):this._utf8Decoder.decode(e,this._parseBuffer);if(s=this._parser.parse(this._parseBuffer,h))return this._preserveStack(n,a,h,0),this._logSlowResolvingAsync(s),s}(this._activeBuffer.x!==n||this._activeBuffer.y!==a)&&this._onCursorMove.fire();let d=this._dirtyRowTracker.end+(this._bufferService.buffer.ybase-this._bufferService.buffer.ydisp),f=this._dirtyRowTracker.start+(this._bufferService.buffer.ybase-this._bufferService.buffer.ydisp);f<this._bufferService.rows&&this._onRequestRefreshRows.fire({start:Math.min(f,this._bufferService.rows-1),end:Math.min(d,this._bufferService.rows-1)})}print(e,t,s){let n,a,l=this._charsetService.charset,c=this._optionsService.rawOptions.screenReaderMode,d=this._bufferService.cols,f=this._coreService.decPrivateModes.wraparound,h=this._coreService.modes.insertMode,m=this._curAttrData,g=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);this._dirtyRowTracker.markDirty(this._activeBuffer.y),this._activeBuffer.x&&s-t>0&&g.getWidth(this._activeBuffer.x-1)===2&&g.setCellFromCodepoint(this._activeBuffer.x-1,0,1,m);let b=this._parser.precedingJoinState;for(let v=t;v<s;++v){if(n=e[v],n<127&&l){let k=l[String.fromCharCode(n)];k&&(n=k.charCodeAt(0))}let y=this._unicodeService.charProperties(n,b);a=ja.extractWidth(y);let S=ja.extractShouldJoin(y),j=S?ja.extractWidth(b):0;if(b=y,c&&this._onA11yChar.fire(Fi(n)),this._getCurrentLinkId()&&this._oscLinkService.addLineToLink(this._getCurrentLinkId(),this._activeBuffer.ybase+this._activeBuffer.y),this._activeBuffer.x+a-j>d){if(f){let k=g,E=this._activeBuffer.x-j;for(this._activeBuffer.x=j,this._activeBuffer.y++,this._activeBuffer.y===this._activeBuffer.scrollBottom+1?(this._activeBuffer.y--,this._bufferService.scroll(this._eraseAttrData(),!0)):(this._activeBuffer.y>=this._bufferService.rows&&(this._activeBuffer.y=this._bufferService.rows-1),this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y).isWrapped=!0),g=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y),j>0&&g instanceof Ac&&g.copyCellsFrom(k,E,0,j,!1);E<d;)k.setCellFromCodepoint(E++,0,1,m)}else if(this._activeBuffer.x=d-1,a===2)continue}if(S&&this._activeBuffer.x){let k=g.getWidth(this._activeBuffer.x-1)?1:2;g.addCodepointToCell(this._activeBuffer.x-k,n,a);for(let E=a-j;--E>=0;)g.setCellFromCodepoint(this._activeBuffer.x++,0,0,m);continue}if(h&&(g.insertCells(this._activeBuffer.x,a-j,this._activeBuffer.getNullCell(m)),g.getWidth(d-1)===2&&g.setCellFromCodepoint(d-1,0,1,m)),g.setCellFromCodepoint(this._activeBuffer.x++,n,a,m),a>0)for(;--a;)g.setCellFromCodepoint(this._activeBuffer.x++,0,0,m)}this._parser.precedingJoinState=b,this._activeBuffer.x<d&&s-t>0&&g.getWidth(this._activeBuffer.x)===0&&!g.hasContent(this._activeBuffer.x)&&g.setCellFromCodepoint(this._activeBuffer.x,0,1,m),this._dirtyRowTracker.markDirty(this._activeBuffer.y)}registerCsiHandler(e,t){return e.final==="t"&&!e.prefix&&!e.intermediates?this._parser.registerCsiHandler(e,s=>J2(s.params[0],this._optionsService.rawOptions.windowOptions)?t(s):!0):this._parser.registerCsiHandler(e,t)}registerDcsHandler(e,t){return this._parser.registerDcsHandler(e,new K2(t))}registerEscHandler(e,t){return this._parser.registerEscHandler(e,t)}registerOscHandler(e,t){return this._parser.registerOscHandler(e,new En(t))}bell(){return this._onRequestBell.fire(),!0}lineFeed(){return this._dirtyRowTracker.markDirty(this._activeBuffer.y),this._optionsService.rawOptions.convertEol&&(this._activeBuffer.x=0),this._activeBuffer.y++,this._activeBuffer.y===this._activeBuffer.scrollBottom+1?(this._activeBuffer.y--,this._bufferService.scroll(this._eraseAttrData())):this._activeBuffer.y>=this._bufferService.rows?this._activeBuffer.y=this._bufferService.rows-1:this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y).isWrapped=!1,this._activeBuffer.x>=this._bufferService.cols&&this._activeBuffer.x--,this._dirtyRowTracker.markDirty(this._activeBuffer.y),this._onLineFeed.fire(),!0}carriageReturn(){return this._activeBuffer.x=0,!0}backspace(){var e;if(!this._coreService.decPrivateModes.reverseWraparound)return this._restrictCursor(),this._activeBuffer.x>0&&this._activeBuffer.x--,!0;if(this._restrictCursor(this._bufferService.cols),this._activeBuffer.x>0)this._activeBuffer.x--;else if(this._activeBuffer.x===0&&this._activeBuffer.y>this._activeBuffer.scrollTop&&this._activeBuffer.y<=this._activeBuffer.scrollBottom&&((e=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y))!=null&&e.isWrapped)){this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y).isWrapped=!1,this._activeBuffer.y--,this._activeBuffer.x=this._bufferService.cols-1;let t=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);t.hasWidth(this._activeBuffer.x)&&!t.hasContent(this._activeBuffer.x)&&this._activeBuffer.x--}return this._restrictCursor(),!0}tab(){if(this._activeBuffer.x>=this._bufferService.cols)return!0;let e=this._activeBuffer.x;return this._activeBuffer.x=this._activeBuffer.nextStop(),this._optionsService.rawOptions.screenReaderMode&&this._onA11yTab.fire(this._activeBuffer.x-e),!0}shiftOut(){return this._charsetService.setgLevel(1),!0}shiftIn(){return this._charsetService.setgLevel(0),!0}_restrictCursor(e=this._bufferService.cols-1){this._activeBuffer.x=Math.min(e,Math.max(0,this._activeBuffer.x)),this._activeBuffer.y=this._coreService.decPrivateModes.origin?Math.min(this._activeBuffer.scrollBottom,Math.max(this._activeBuffer.scrollTop,this._activeBuffer.y)):Math.min(this._bufferService.rows-1,Math.max(0,this._activeBuffer.y)),this._dirtyRowTracker.markDirty(this._activeBuffer.y)}_setCursor(e,t){this._dirtyRowTracker.markDirty(this._activeBuffer.y),this._coreService.decPrivateModes.origin?(this._activeBuffer.x=e,this._activeBuffer.y=this._activeBuffer.scrollTop+t):(this._activeBuffer.x=e,this._activeBuffer.y=t),this._restrictCursor(),this._dirtyRowTracker.markDirty(this._activeBuffer.y)}_moveCursor(e,t){this._restrictCursor(),this._setCursor(this._activeBuffer.x+e,this._activeBuffer.y+t)}cursorUp(e){let t=this._activeBuffer.y-this._activeBuffer.scrollTop;return t>=0?this._moveCursor(0,-Math.min(t,e.params[0]||1)):this._moveCursor(0,-(e.params[0]||1)),!0}cursorDown(e){let t=this._activeBuffer.scrollBottom-this._activeBuffer.y;return t>=0?this._moveCursor(0,Math.min(t,e.params[0]||1)):this._moveCursor(0,e.params[0]||1),!0}cursorForward(e){return this._moveCursor(e.params[0]||1,0),!0}cursorBackward(e){return this._moveCursor(-(e.params[0]||1),0),!0}cursorNextLine(e){return this.cursorDown(e),this._activeBuffer.x=0,!0}cursorPrecedingLine(e){return this.cursorUp(e),this._activeBuffer.x=0,!0}cursorCharAbsolute(e){return this._setCursor((e.params[0]||1)-1,this._activeBuffer.y),!0}cursorPosition(e){return this._setCursor(e.length>=2?(e.params[1]||1)-1:0,(e.params[0]||1)-1),!0}charPosAbsolute(e){return this._setCursor((e.params[0]||1)-1,this._activeBuffer.y),!0}hPositionRelative(e){return this._moveCursor(e.params[0]||1,0),!0}linePosAbsolute(e){return this._setCursor(this._activeBuffer.x,(e.params[0]||1)-1),!0}vPositionRelative(e){return this._moveCursor(0,e.params[0]||1),!0}hVPosition(e){return this.cursorPosition(e),!0}tabClear(e){let t=e.params[0];return t===0?delete this._activeBuffer.tabs[this._activeBuffer.x]:t===3&&(this._activeBuffer.tabs={}),!0}cursorForwardTab(e){if(this._activeBuffer.x>=this._bufferService.cols)return!0;let t=e.params[0]||1;for(;t--;)this._activeBuffer.x=this._activeBuffer.nextStop();return!0}cursorBackwardTab(e){if(this._activeBuffer.x>=this._bufferService.cols)return!0;let t=e.params[0]||1;for(;t--;)this._activeBuffer.x=this._activeBuffer.prevStop();return!0}selectProtected(e){let t=e.params[0];return t===1&&(this._curAttrData.bg|=536870912),(t===2||t===0)&&(this._curAttrData.bg&=-536870913),!0}_eraseInBufferLine(e,t,s,n=!1,a=!1){let l=this._activeBuffer.lines.get(this._activeBuffer.ybase+e);l.replaceCells(t,s,this._activeBuffer.getNullCell(this._eraseAttrData()),a),n&&(l.isWrapped=!1)}_resetBufferLine(e,t=!1){let s=this._activeBuffer.lines.get(this._activeBuffer.ybase+e);s&&(s.fill(this._activeBuffer.getNullCell(this._eraseAttrData()),t),this._bufferService.buffer.clearMarkers(this._activeBuffer.ybase+e),s.isWrapped=!1)}eraseInDisplay(e,t=!1){var n;this._restrictCursor(this._bufferService.cols);let s;switch(e.params[0]){case 0:for(s=this._activeBuffer.y,this._dirtyRowTracker.markDirty(s),this._eraseInBufferLine(s++,this._activeBuffer.x,this._bufferService.cols,this._activeBuffer.x===0,t);s<this._bufferService.rows;s++)this._resetBufferLine(s,t);this._dirtyRowTracker.markDirty(s);break;case 1:for(s=this._activeBuffer.y,this._dirtyRowTracker.markDirty(s),this._eraseInBufferLine(s,0,this._activeBuffer.x+1,!0,t),this._activeBuffer.x+1>=this._bufferService.cols&&(this._activeBuffer.lines.get(s+1).isWrapped=!1);s--;)this._resetBufferLine(s,t);this._dirtyRowTracker.markDirty(0);break;case 2:if(this._optionsService.rawOptions.scrollOnEraseInDisplay){for(s=this._bufferService.rows,this._dirtyRowTracker.markRangeDirty(0,s-1);s--&&!((n=this._activeBuffer.lines.get(this._activeBuffer.ybase+s))!=null&&n.getTrimmedLength()););for(;s>=0;s--)this._bufferService.scroll(this._eraseAttrData())}else{for(s=this._bufferService.rows,this._dirtyRowTracker.markDirty(s-1);s--;)this._resetBufferLine(s,t);this._dirtyRowTracker.markDirty(0)}break;case 3:let a=this._activeBuffer.lines.length-this._bufferService.rows;a>0&&(this._activeBuffer.lines.trimStart(a),this._activeBuffer.ybase=Math.max(this._activeBuffer.ybase-a,0),this._activeBuffer.ydisp=Math.max(this._activeBuffer.ydisp-a,0),this._onScroll.fire(0));break}return!0}eraseInLine(e,t=!1){switch(this._restrictCursor(this._bufferService.cols),e.params[0]){case 0:this._eraseInBufferLine(this._activeBuffer.y,this._activeBuffer.x,this._bufferService.cols,this._activeBuffer.x===0,t);break;case 1:this._eraseInBufferLine(this._activeBuffer.y,0,this._activeBuffer.x+1,!1,t);break;case 2:this._eraseInBufferLine(this._activeBuffer.y,0,this._bufferService.cols,!0,t);break}return this._dirtyRowTracker.markDirty(this._activeBuffer.y),!0}insertLines(e){this._restrictCursor();let t=e.params[0]||1;if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let s=this._activeBuffer.ybase+this._activeBuffer.y,n=this._bufferService.rows-1-this._activeBuffer.scrollBottom,a=this._bufferService.rows-1+this._activeBuffer.ybase-n+1;for(;t--;)this._activeBuffer.lines.splice(a-1,1),this._activeBuffer.lines.splice(s,0,this._activeBuffer.getBlankLine(this._eraseAttrData()));return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.y,this._activeBuffer.scrollBottom),this._activeBuffer.x=0,!0}deleteLines(e){this._restrictCursor();let t=e.params[0]||1;if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let s=this._activeBuffer.ybase+this._activeBuffer.y,n;for(n=this._bufferService.rows-1-this._activeBuffer.scrollBottom,n=this._bufferService.rows-1+this._activeBuffer.ybase-n;t--;)this._activeBuffer.lines.splice(s,1),this._activeBuffer.lines.splice(n,0,this._activeBuffer.getBlankLine(this._eraseAttrData()));return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.y,this._activeBuffer.scrollBottom),this._activeBuffer.x=0,!0}insertChars(e){this._restrictCursor();let t=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);return t&&(t.insertCells(this._activeBuffer.x,e.params[0]||1,this._activeBuffer.getNullCell(this._eraseAttrData())),this._dirtyRowTracker.markDirty(this._activeBuffer.y)),!0}deleteChars(e){this._restrictCursor();let t=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);return t&&(t.deleteCells(this._activeBuffer.x,e.params[0]||1,this._activeBuffer.getNullCell(this._eraseAttrData())),this._dirtyRowTracker.markDirty(this._activeBuffer.y)),!0}scrollUp(e){let t=e.params[0]||1;for(;t--;)this._activeBuffer.lines.splice(this._activeBuffer.ybase+this._activeBuffer.scrollTop,1),this._activeBuffer.lines.splice(this._activeBuffer.ybase+this._activeBuffer.scrollBottom,0,this._activeBuffer.getBlankLine(this._eraseAttrData()));return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}scrollDown(e){let t=e.params[0]||1;for(;t--;)this._activeBuffer.lines.splice(this._activeBuffer.ybase+this._activeBuffer.scrollBottom,1),this._activeBuffer.lines.splice(this._activeBuffer.ybase+this._activeBuffer.scrollTop,0,this._activeBuffer.getBlankLine(fs));return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}scrollLeft(e){if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let t=e.params[0]||1;for(let s=this._activeBuffer.scrollTop;s<=this._activeBuffer.scrollBottom;++s){let n=this._activeBuffer.lines.get(this._activeBuffer.ybase+s);n.deleteCells(0,t,this._activeBuffer.getNullCell(this._eraseAttrData())),n.isWrapped=!1}return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}scrollRight(e){if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let t=e.params[0]||1;for(let s=this._activeBuffer.scrollTop;s<=this._activeBuffer.scrollBottom;++s){let n=this._activeBuffer.lines.get(this._activeBuffer.ybase+s);n.insertCells(0,t,this._activeBuffer.getNullCell(this._eraseAttrData())),n.isWrapped=!1}return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}insertColumns(e){if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let t=e.params[0]||1;for(let s=this._activeBuffer.scrollTop;s<=this._activeBuffer.scrollBottom;++s){let n=this._activeBuffer.lines.get(this._activeBuffer.ybase+s);n.insertCells(this._activeBuffer.x,t,this._activeBuffer.getNullCell(this._eraseAttrData())),n.isWrapped=!1}return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}deleteColumns(e){if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let t=e.params[0]||1;for(let s=this._activeBuffer.scrollTop;s<=this._activeBuffer.scrollBottom;++s){let n=this._activeBuffer.lines.get(this._activeBuffer.ybase+s);n.deleteCells(this._activeBuffer.x,t,this._activeBuffer.getNullCell(this._eraseAttrData())),n.isWrapped=!1}return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}eraseChars(e){this._restrictCursor();let t=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);return t&&(t.replaceCells(this._activeBuffer.x,this._activeBuffer.x+(e.params[0]||1),this._activeBuffer.getNullCell(this._eraseAttrData())),this._dirtyRowTracker.markDirty(this._activeBuffer.y)),!0}repeatPrecedingCharacter(e){let t=this._parser.precedingJoinState;if(!t)return!0;let s=e.params[0]||1,n=ja.extractWidth(t),a=this._activeBuffer.x-n,l=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y).getString(a),c=new Uint32Array(l.length*s),d=0;for(let h=0;h<l.length;){let m=l.codePointAt(h)||0;c[d++]=m,h+=m>65535?2:1}let f=d;for(let h=1;h<s;++h)c.copyWithin(f,0,d),f+=d;return this.print(c,0,f),!0}sendDeviceAttributesPrimary(e){return e.params[0]>0||(this._is("xterm")||this._is("rxvt-unicode")||this._is("screen")?this._coreService.triggerDataEvent(xe.ESC+"[?1;2c"):this._is("linux")&&this._coreService.triggerDataEvent(xe.ESC+"[?6c")),!0}sendDeviceAttributesSecondary(e){return e.params[0]>0||(this._is("xterm")?this._coreService.triggerDataEvent(xe.ESC+"[>0;276;0c"):this._is("rxvt-unicode")?this._coreService.triggerDataEvent(xe.ESC+"[>85;95;0c"):this._is("linux")?this._coreService.triggerDataEvent(e.params[0]+"c"):this._is("screen")&&this._coreService.triggerDataEvent(xe.ESC+"[>83;40003;0c")),!0}_is(e){return(this._optionsService.rawOptions.termName+"").indexOf(e)===0}setMode(e){for(let t=0;t<e.length;t++)switch(e.params[t]){case 4:this._coreService.modes.insertMode=!0;break;case 20:this._optionsService.options.convertEol=!0;break}return!0}setModePrivate(e){for(let t=0;t<e.length;t++)switch(e.params[t]){case 1:this._coreService.decPrivateModes.applicationCursorKeys=!0;break;case 2:this._charsetService.setgCharset(0,Sa),this._charsetService.setgCharset(1,Sa),this._charsetService.setgCharset(2,Sa),this._charsetService.setgCharset(3,Sa);break;case 3:this._optionsService.rawOptions.windowOptions.setWinLines&&(this._bufferService.resize(132,this._bufferService.rows),this._onRequestReset.fire());break;case 6:this._coreService.decPrivateModes.origin=!0,this._setCursor(0,0);break;case 7:this._coreService.decPrivateModes.wraparound=!0;break;case 12:this._optionsService.options.cursorBlink=!0;break;case 45:this._coreService.decPrivateModes.reverseWraparound=!0;break;case 66:this._logService.debug("Serial port requested application keypad."),this._coreService.decPrivateModes.applicationKeypad=!0,this._onRequestSyncScrollBar.fire();break;case 9:this._coreMouseService.activeProtocol="X10";break;case 1e3:this._coreMouseService.activeProtocol="VT200";break;case 1002:this._coreMouseService.activeProtocol="DRAG";break;case 1003:this._coreMouseService.activeProtocol="ANY";break;case 1004:this._coreService.decPrivateModes.sendFocus=!0,this._onRequestSendFocus.fire();break;case 1005:this._logService.debug("DECSET 1005 not supported (see #2507)");break;case 1006:this._coreMouseService.activeEncoding="SGR";break;case 1015:this._logService.debug("DECSET 1015 not supported (see #2507)");break;case 1016:this._coreMouseService.activeEncoding="SGR_PIXELS";break;case 25:this._coreService.isCursorHidden=!1;break;case 1048:this.saveCursor();break;case 1049:this.saveCursor();case 47:case 1047:this._bufferService.buffers.activateAltBuffer(this._eraseAttrData()),this._coreService.isCursorInitialized=!0,this._onRequestRefreshRows.fire(void 0),this._onRequestSyncScrollBar.fire();break;case 2004:this._coreService.decPrivateModes.bracketedPasteMode=!0;break;case 2026:this._coreService.decPrivateModes.synchronizedOutput=!0;break}return!0}resetMode(e){for(let t=0;t<e.length;t++)switch(e.params[t]){case 4:this._coreService.modes.insertMode=!1;break;case 20:this._optionsService.options.convertEol=!1;break}return!0}resetModePrivate(e){for(let t=0;t<e.length;t++)switch(e.params[t]){case 1:this._coreService.decPrivateModes.applicationCursorKeys=!1;break;case 3:this._optionsService.rawOptions.windowOptions.setWinLines&&(this._bufferService.resize(80,this._bufferService.rows),this._onRequestReset.fire());break;case 6:this._coreService.decPrivateModes.origin=!1,this._setCursor(0,0);break;case 7:this._coreService.decPrivateModes.wraparound=!1;break;case 12:this._optionsService.options.cursorBlink=!1;break;case 45:this._coreService.decPrivateModes.reverseWraparound=!1;break;case 66:this._logService.debug("Switching back to normal keypad."),this._coreService.decPrivateModes.applicationKeypad=!1,this._onRequestSyncScrollBar.fire();break;case 9:case 1e3:case 1002:case 1003:this._coreMouseService.activeProtocol="NONE";break;case 1004:this._coreService.decPrivateModes.sendFocus=!1;break;case 1005:this._logService.debug("DECRST 1005 not supported (see #2507)");break;case 1006:this._coreMouseService.activeEncoding="DEFAULT";break;case 1015:this._logService.debug("DECRST 1015 not supported (see #2507)");break;case 1016:this._coreMouseService.activeEncoding="DEFAULT";break;case 25:this._coreService.isCursorHidden=!0;break;case 1048:this.restoreCursor();break;case 1049:case 47:case 1047:this._bufferService.buffers.activateNormalBuffer(),e.params[t]===1049&&this.restoreCursor(),this._coreService.isCursorInitialized=!0,this._onRequestRefreshRows.fire(void 0),this._onRequestSyncScrollBar.fire();break;case 2004:this._coreService.decPrivateModes.bracketedPasteMode=!1;break;case 2026:this._coreService.decPrivateModes.synchronizedOutput=!1,this._onRequestRefreshRows.fire(void 0);break}return!0}requestMode(e,t){(S=>(S[S.NOT_RECOGNIZED=0]="NOT_RECOGNIZED",S[S.SET=1]="SET",S[S.RESET=2]="RESET",S[S.PERMANENTLY_SET=3]="PERMANENTLY_SET",S[S.PERMANENTLY_RESET=4]="PERMANENTLY_RESET"))(void 0||(s={}));let n=this._coreService.decPrivateModes,{activeProtocol:a,activeEncoding:l}=this._coreMouseService,c=this._coreService,{buffers:d,cols:f}=this._bufferService,{active:h,alt:m}=d,g=this._optionsService.rawOptions,b=(S,j)=>(c.triggerDataEvent(`${xe.ESC}[${t?"":"?"}${S};${j}$y`),!0),v=S=>S?1:2,y=e.params[0];return t?y===2?b(y,4):y===4?b(y,v(c.modes.insertMode)):y===12?b(y,3):y===20?b(y,v(g.convertEol)):b(y,0):y===1?b(y,v(n.applicationCursorKeys)):y===3?b(y,g.windowOptions.setWinLines?f===80?2:f===132?1:0:0):y===6?b(y,v(n.origin)):y===7?b(y,v(n.wraparound)):y===8?b(y,3):y===9?b(y,v(a==="X10")):y===12?b(y,v(g.cursorBlink)):y===25?b(y,v(!c.isCursorHidden)):y===45?b(y,v(n.reverseWraparound)):y===66?b(y,v(n.applicationKeypad)):y===67?b(y,4):y===1e3?b(y,v(a==="VT200")):y===1002?b(y,v(a==="DRAG")):y===1003?b(y,v(a==="ANY")):y===1004?b(y,v(n.sendFocus)):y===1005?b(y,4):y===1006?b(y,v(l==="SGR")):y===1015?b(y,4):y===1016?b(y,v(l==="SGR_PIXELS")):y===1048?b(y,1):y===47||y===1047||y===1049?b(y,v(h===m)):y===2004?b(y,v(n.bracketedPasteMode)):y===2026?b(y,v(n.synchronizedOutput)):b(y,0)}_updateAttrColor(e,t,s,n,a){return t===2?(e|=50331648,e&=-16777216,e|=pu.fromColorRGB([s,n,a])):t===5&&(e&=-50331904,e|=33554432|s&255),e}_extractColor(e,t,s){let n=[0,0,-1,0,0,0],a=0,l=0;do{if(n[l+a]=e.params[t+l],e.hasSubParams(t+l)){let c=e.getSubParams(t+l),d=0;do n[1]===5&&(a=1),n[l+d+1+a]=c[d];while(++d<c.length&&d+l+1+a<n.length);break}if(n[1]===5&&l+a>=2||n[1]===2&&l+a>=5)break;n[1]&&(a=1)}while(++l+t<e.length&&l+a<n.length);for(let c=2;c<n.length;++c)n[c]===-1&&(n[c]=0);switch(n[0]){case 38:s.fg=this._updateAttrColor(s.fg,n[1],n[3],n[4],n[5]);break;case 48:s.bg=this._updateAttrColor(s.bg,n[1],n[3],n[4],n[5]);break;case 58:s.extended=s.extended.clone(),s.extended.underlineColor=this._updateAttrColor(s.extended.underlineColor,n[1],n[3],n[4],n[5])}return l}_processUnderline(e,t){t.extended=t.extended.clone(),(!~e||e>5)&&(e=1),t.extended.underlineStyle=e,t.fg|=268435456,e===0&&(t.fg&=-268435457),t.updateExtended()}_processSGR0(e){e.fg=fs.fg,e.bg=fs.bg,e.extended=e.extended.clone(),e.extended.underlineStyle=0,e.extended.underlineColor&=-67108864,e.updateExtended()}charAttributes(e){if(e.length===1&&e.params[0]===0)return this._processSGR0(this._curAttrData),!0;let t=e.length,s,n=this._curAttrData;for(let a=0;a<t;a++)s=e.params[a],s>=30&&s<=37?(n.fg&=-50331904,n.fg|=16777216|s-30):s>=40&&s<=47?(n.bg&=-50331904,n.bg|=16777216|s-40):s>=90&&s<=97?(n.fg&=-50331904,n.fg|=16777216|s-90|8):s>=100&&s<=107?(n.bg&=-50331904,n.bg|=16777216|s-100|8):s===0?this._processSGR0(n):s===1?n.fg|=134217728:s===3?n.bg|=67108864:s===4?(n.fg|=268435456,this._processUnderline(e.hasSubParams(a)?e.getSubParams(a)[0]:1,n)):s===5?n.fg|=536870912:s===7?n.fg|=67108864:s===8?n.fg|=1073741824:s===9?n.fg|=2147483648:s===2?n.bg|=134217728:s===21?this._processUnderline(2,n):s===22?(n.fg&=-134217729,n.bg&=-134217729):s===23?n.bg&=-67108865:s===24?(n.fg&=-268435457,this._processUnderline(0,n)):s===25?n.fg&=-536870913:s===27?n.fg&=-67108865:s===28?n.fg&=-1073741825:s===29?n.fg&=2147483647:s===39?(n.fg&=-67108864,n.fg|=fs.fg&16777215):s===49?(n.bg&=-67108864,n.bg|=fs.bg&16777215):s===38||s===48||s===58?a+=this._extractColor(e,a,n):s===53?n.bg|=1073741824:s===55?n.bg&=-1073741825:s===59?(n.extended=n.extended.clone(),n.extended.underlineColor=-1,n.updateExtended()):s===100?(n.fg&=-67108864,n.fg|=fs.fg&16777215,n.bg&=-67108864,n.bg|=fs.bg&16777215):this._logService.debug("Unknown SGR attribute: %d.",s);return!0}deviceStatus(e){switch(e.params[0]){case 5:this._coreService.triggerDataEvent(`${xe.ESC}[0n`);break;case 6:let t=this._activeBuffer.y+1,s=this._activeBuffer.x+1;this._coreService.triggerDataEvent(`${xe.ESC}[${t};${s}R`);break}return!0}deviceStatusPrivate(e){switch(e.params[0]){case 6:let t=this._activeBuffer.y+1,s=this._activeBuffer.x+1;this._coreService.triggerDataEvent(`${xe.ESC}[?${t};${s}R`);break}return!0}softReset(e){return this._coreService.isCursorHidden=!1,this._onRequestSyncScrollBar.fire(),this._activeBuffer.scrollTop=0,this._activeBuffer.scrollBottom=this._bufferService.rows-1,this._curAttrData=fs.clone(),this._coreService.reset(),this._charsetService.reset(),this._activeBuffer.savedX=0,this._activeBuffer.savedY=this._activeBuffer.ybase,this._activeBuffer.savedCurAttrData.fg=this._curAttrData.fg,this._activeBuffer.savedCurAttrData.bg=this._curAttrData.bg,this._activeBuffer.savedCharset=this._charsetService.charset,this._coreService.decPrivateModes.origin=!1,!0}setCursorStyle(e){let t=e.length===0?1:e.params[0];if(t===0)this._coreService.decPrivateModes.cursorStyle=void 0,this._coreService.decPrivateModes.cursorBlink=void 0;else{switch(t){case 1:case 2:this._coreService.decPrivateModes.cursorStyle="block";break;case 3:case 4:this._coreService.decPrivateModes.cursorStyle="underline";break;case 5:case 6:this._coreService.decPrivateModes.cursorStyle="bar";break}let s=t%2===1;this._coreService.decPrivateModes.cursorBlink=s}return!0}setScrollRegion(e){let t=e.params[0]||1,s;return(e.length<2||(s=e.params[1])>this._bufferService.rows||s===0)&&(s=this._bufferService.rows),s>t&&(this._activeBuffer.scrollTop=t-1,this._activeBuffer.scrollBottom=s-1,this._setCursor(0,0)),!0}windowOptions(e){if(!J2(e.params[0],this._optionsService.rawOptions.windowOptions))return!0;let t=e.length>1?e.params[1]:0;switch(e.params[0]){case 14:t!==2&&this._onRequestWindowsOptionsReport.fire(0);break;case 16:this._onRequestWindowsOptionsReport.fire(1);break;case 18:this._bufferService&&this._coreService.triggerDataEvent(`${xe.ESC}[8;${this._bufferService.rows};${this._bufferService.cols}t`);break;case 22:(t===0||t===2)&&(this._windowTitleStack.push(this._windowTitle),this._windowTitleStack.length>X2&&this._windowTitleStack.shift()),(t===0||t===1)&&(this._iconNameStack.push(this._iconName),this._iconNameStack.length>X2&&this._iconNameStack.shift());break;case 23:(t===0||t===2)&&this._windowTitleStack.length&&this.setTitle(this._windowTitleStack.pop()),(t===0||t===1)&&this._iconNameStack.length&&this.setIconName(this._iconNameStack.pop());break}return!0}saveCursor(e){return this._activeBuffer.savedX=this._activeBuffer.x,this._activeBuffer.savedY=this._activeBuffer.ybase+this._activeBuffer.y,this._activeBuffer.savedCurAttrData.fg=this._curAttrData.fg,this._activeBuffer.savedCurAttrData.bg=this._curAttrData.bg,this._activeBuffer.savedCharset=this._charsetService.charset,!0}restoreCursor(e){return this._activeBuffer.x=this._activeBuffer.savedX||0,this._activeBuffer.y=Math.max(this._activeBuffer.savedY-this._activeBuffer.ybase,0),this._curAttrData.fg=this._activeBuffer.savedCurAttrData.fg,this._curAttrData.bg=this._activeBuffer.savedCurAttrData.bg,this._charsetService.charset=this._savedCharset,this._activeBuffer.savedCharset&&(this._charsetService.charset=this._activeBuffer.savedCharset),this._restrictCursor(),!0}setTitle(e){return this._windowTitle=e,this._onTitleChange.fire(e),!0}setIconName(e){return this._iconName=e,!0}setOrReportIndexedColor(e){let t=[],s=e.split(";");for(;s.length>1;){let n=s.shift(),a=s.shift();if(/^\d+$/.exec(n)){let l=parseInt(n);if(eS(l))if(a==="?")t.push({type:0,index:l});else{let c=Y2(a);c&&t.push({type:1,index:l,color:c})}}}return t.length&&this._onColor.fire(t),!0}setHyperlink(e){let t=e.indexOf(";");if(t===-1)return!0;let s=e.slice(0,t).trim(),n=e.slice(t+1);return n?this._createHyperlink(s,n):s.trim()?!1:this._finishHyperlink()}_createHyperlink(e,t){this._getCurrentLinkId()&&this._finishHyperlink();let s=e.split(":"),n,a=s.findIndex(l=>l.startsWith("id="));return a!==-1&&(n=s[a].slice(3)||void 0),this._curAttrData.extended=this._curAttrData.extended.clone(),this._curAttrData.extended.urlId=this._oscLinkService.registerLink({id:n,uri:t}),this._curAttrData.updateExtended(),!0}_finishHyperlink(){return this._curAttrData.extended=this._curAttrData.extended.clone(),this._curAttrData.extended.urlId=0,this._curAttrData.updateExtended(),!0}_setOrReportSpecialColor(e,t){let s=e.split(";");for(let n=0;n<s.length&&!(t>=this._specialColors.length);++n,++t)if(s[n]==="?")this._onColor.fire([{type:0,index:this._specialColors[t]}]);else{let a=Y2(s[n]);a&&this._onColor.fire([{type:1,index:this._specialColors[t],color:a}])}return!0}setOrReportFgColor(e){return this._setOrReportSpecialColor(e,0)}setOrReportBgColor(e){return this._setOrReportSpecialColor(e,1)}setOrReportCursorColor(e){return this._setOrReportSpecialColor(e,2)}restoreIndexedColor(e){if(!e)return this._onColor.fire([{type:2}]),!0;let t=[],s=e.split(";");for(let n=0;n<s.length;++n)if(/^\d+$/.exec(s[n])){let a=parseInt(s[n]);eS(a)&&t.push({type:2,index:a})}return t.length&&this._onColor.fire(t),!0}restoreFgColor(e){return this._onColor.fire([{type:2,index:256}]),!0}restoreBgColor(e){return this._onColor.fire([{type:2,index:257}]),!0}restoreCursorColor(e){return this._onColor.fire([{type:2,index:258}]),!0}nextLine(){return this._activeBuffer.x=0,this.index(),!0}keypadApplicationMode(){return this._logService.debug("Serial port requested application keypad."),this._coreService.decPrivateModes.applicationKeypad=!0,this._onRequestSyncScrollBar.fire(),!0}keypadNumericMode(){return this._logService.debug("Switching back to normal keypad."),this._coreService.decPrivateModes.applicationKeypad=!1,this._onRequestSyncScrollBar.fire(),!0}selectDefaultCharset(){return this._charsetService.setgLevel(0),this._charsetService.setgCharset(0,Sa),!0}selectCharset(e){return e.length!==2?(this.selectDefaultCharset(),!0):(e[0]==="/"||this._charsetService.setgCharset(kF[e[0]],Ss[e[1]]||Sa),!0)}index(){return this._restrictCursor(),this._activeBuffer.y++,this._activeBuffer.y===this._activeBuffer.scrollBottom+1?(this._activeBuffer.y--,this._bufferService.scroll(this._eraseAttrData())):this._activeBuffer.y>=this._bufferService.rows&&(this._activeBuffer.y=this._bufferService.rows-1),this._restrictCursor(),!0}tabSet(){return this._activeBuffer.tabs[this._activeBuffer.x]=!0,!0}reverseIndex(){if(this._restrictCursor(),this._activeBuffer.y===this._activeBuffer.scrollTop){let e=this._activeBuffer.scrollBottom-this._activeBuffer.scrollTop;this._activeBuffer.lines.shiftElements(this._activeBuffer.ybase+this._activeBuffer.y,e,1),this._activeBuffer.lines.set(this._activeBuffer.ybase+this._activeBuffer.y,this._activeBuffer.getBlankLine(this._eraseAttrData())),this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom)}else this._activeBuffer.y--,this._restrictCursor();return!0}fullReset(){return this._parser.reset(),this._onRequestReset.fire(),!0}reset(){this._curAttrData=fs.clone(),this._eraseAttrDataInternal=fs.clone()}_eraseAttrData(){return this._eraseAttrDataInternal.bg&=-67108864,this._eraseAttrDataInternal.bg|=this._curAttrData.bg&67108863,this._eraseAttrDataInternal}setgLevel(e){return this._charsetService.setgLevel(e),!0}screenAlignmentPattern(){let e=new Jn;e.content=1<<22|69,e.fg=this._curAttrData.fg,e.bg=this._curAttrData.bg,this._setCursor(0,0);for(let t=0;t<this._bufferService.rows;++t){let s=this._activeBuffer.ybase+this._activeBuffer.y+t,n=this._activeBuffer.lines.get(s);n&&(n.fill(e),n.isWrapped=!1)}return this._dirtyRowTracker.markAllDirty(),this._setCursor(0,0),!0}requestStatusString(e,t){let s=c=>(this._coreService.triggerDataEvent(`${xe.ESC}${c}${xe.ESC}\\`),!0),n=this._bufferService.buffer,a=this._optionsService.rawOptions;return s(e==='"q'?`P1$r${this._curAttrData.isProtected()?1:0}"q`:e==='"p'?'P1$r61;1"p':e==="r"?`P1$r${n.scrollTop+1};${n.scrollBottom+1}r`:e==="m"?"P1$r0m":e===" q"?`P1$r${{block:2,underline:4,bar:6}[a.cursorStyle]-(a.cursorBlink?1:0)} q`:"P0$r")}markRangeDirty(e,t){this._dirtyRowTracker.markRangeDirty(e,t)}},f0=class{constructor(e){this._bufferService=e,this.clearRange()}clearRange(){this.start=this._bufferService.buffer.y,this.end=this._bufferService.buffer.y}markDirty(e){e<this.start?this.start=e:e>this.end&&(this.end=e)}markRangeDirty(e,t){e>t&&(Z2=e,e=t,t=Z2),e<this.start&&(this.start=e),t>this.end&&(this.end=t)}markAllDirty(){this.markRangeDirty(0,this._bufferService.rows-1)}};f0=ts([Re(0,sn)],f0);function eS(e){return 0<=e&&e<256}var NF=5e7,tS=12,EF=50,MF=class extends nt{constructor(e){super(),this._action=e,this._writeBuffer=[],this._callbacks=[],this._pendingData=0,this._bufferOffset=0,this._isSyncWriting=!1,this._syncCalls=0,this._didUserInput=!1,this._onWriteParsed=this._register(new Ce),this.onWriteParsed=this._onWriteParsed.event}handleUserInput(){this._didUserInput=!0}writeSync(e,t){if(t!==void 0&&this._syncCalls>t){this._syncCalls=0;return}if(this._pendingData+=e.length,this._writeBuffer.push(e),this._callbacks.push(void 0),this._syncCalls++,this._isSyncWriting)return;this._isSyncWriting=!0;let s;for(;s=this._writeBuffer.shift();){this._action(s);let n=this._callbacks.shift();n&&n()}this._pendingData=0,this._bufferOffset=2147483647,this._isSyncWriting=!1,this._syncCalls=0}write(e,t){if(this._pendingData>NF)throw new Error("write data discarded, use flow control to avoid losing data");if(!this._writeBuffer.length){if(this._bufferOffset=0,this._didUserInput){this._didUserInput=!1,this._pendingData+=e.length,this._writeBuffer.push(e),this._callbacks.push(t),this._innerWrite();return}setTimeout(()=>this._innerWrite())}this._pendingData+=e.length,this._writeBuffer.push(e),this._callbacks.push(t)}_innerWrite(e=0,t=!0){let s=e||performance.now();for(;this._writeBuffer.length>this._bufferOffset;){let n=this._writeBuffer[this._bufferOffset],a=this._action(n,t);if(a){let c=d=>performance.now()-s>=tS?setTimeout(()=>this._innerWrite(0,d)):this._innerWrite(s,d);a.catch(d=>(queueMicrotask(()=>{throw d}),Promise.resolve(!1))).then(c);return}let l=this._callbacks[this._bufferOffset];if(l&&l(),this._bufferOffset++,this._pendingData-=n.length,performance.now()-s>=tS)break}this._writeBuffer.length>this._bufferOffset?(this._bufferOffset>EF&&(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()}},p0=class{constructor(e){this._bufferService=e,this._nextId=1,this._entriesWithId=new Map,this._dataByLinkId=new Map}registerLink(e){let t=this._bufferService.buffer;if(e.id===void 0){let d=t.addMarker(t.ybase+t.y),f={data:e,id:this._nextId++,lines:[d]};return d.onDispose(()=>this._removeMarkerFromLink(f,d)),this._dataByLinkId.set(f.id,f),f.id}let s=e,n=this._getEntryIdKey(s),a=this._entriesWithId.get(n);if(a)return this.addLineToLink(a.id,t.ybase+t.y),a.id;let l=t.addMarker(t.ybase+t.y),c={id:this._nextId++,key:this._getEntryIdKey(s),data:s,lines:[l]};return l.onDispose(()=>this._removeMarkerFromLink(c,l)),this._entriesWithId.set(c.key,c),this._dataByLinkId.set(c.id,c),c.id}addLineToLink(e,t){let s=this._dataByLinkId.get(e);if(s&&s.lines.every(n=>n.line!==t)){let n=this._bufferService.buffer.addMarker(t);s.lines.push(n),n.onDispose(()=>this._removeMarkerFromLink(s,n))}}getLinkData(e){var t;return(t=this._dataByLinkId.get(e))==null?void 0:t.data}_getEntryIdKey(e){return`${e.id};;${e.uri}`}_removeMarkerFromLink(e,t){let s=e.lines.indexOf(t);s!==-1&&(e.lines.splice(s,1),e.lines.length===0&&(e.data.id!==void 0&&this._entriesWithId.delete(e.key),this._dataByLinkId.delete(e.id)))}};p0=ts([Re(0,sn)],p0);var sS=!1,TF=class extends nt{constructor(e){super(),this._windowsWrappingHeuristics=this._register(new Yo),this._onBinary=this._register(new Ce),this.onBinary=this._onBinary.event,this._onData=this._register(new Ce),this.onData=this._onData.event,this._onLineFeed=this._register(new Ce),this.onLineFeed=this._onLineFeed.event,this._onResize=this._register(new Ce),this.onResize=this._onResize.event,this._onWriteParsed=this._register(new Ce),this.onWriteParsed=this._onWriteParsed.event,this._onScroll=this._register(new Ce),this._instantiationService=new eF,this.optionsService=this._register(new uF(e)),this._instantiationService.setService(nn,this.optionsService),this._bufferService=this._register(this._instantiationService.createInstance(c0)),this._instantiationService.setService(sn,this._bufferService),this._logService=this._register(this._instantiationService.createInstance(l0)),this._instantiationService.setService(VC,this._logService),this.coreService=this._register(this._instantiationService.createInstance(u0)),this._instantiationService.setService(Ba,this.coreService),this.coreMouseService=this._register(this._instantiationService.createInstance(d0)),this._instantiationService.setService(UC,this.coreMouseService),this.unicodeService=this._register(this._instantiationService.createInstance(ja)),this._instantiationService.setService(X9,this.unicodeService),this._charsetService=this._instantiationService.createInstance(mF),this._instantiationService.setService(Y9,this._charsetService),this._oscLinkService=this._instantiationService.createInstance(p0),this._instantiationService.setService(WC,this._oscLinkService),this._inputHandler=this._register(new CF(this._bufferService,this._charsetService,this.coreService,this._logService,this.optionsService,this._oscLinkService,this.coreMouseService,this.unicodeService)),this._register(Is.forward(this._inputHandler.onLineFeed,this._onLineFeed)),this._register(this._inputHandler),this._register(Is.forward(this._bufferService.onResize,this._onResize)),this._register(Is.forward(this.coreService.onData,this._onData)),this._register(Is.forward(this.coreService.onBinary,this._onBinary)),this._register(this.coreService.onRequestScrollToBottom(()=>this.scrollToBottom(!0))),this._register(this.coreService.onUserInput(()=>this._writeBuffer.handleUserInput())),this._register(this.optionsService.onMultipleOptionChange(["windowsMode","windowsPty"],()=>this._handleWindowsPtyOptionChange())),this._register(this._bufferService.onScroll(()=>{this._onScroll.fire({position:this._bufferService.buffer.ydisp}),this._inputHandler.markRangeDirty(this._bufferService.buffer.scrollTop,this._bufferService.buffer.scrollBottom)})),this._writeBuffer=this._register(new MF((t,s)=>this._inputHandler.parse(t,s))),this._register(Is.forward(this._writeBuffer.onWriteParsed,this._onWriteParsed))}get onScroll(){return this._onScrollApi||(this._onScrollApi=this._register(new Ce),this._onScroll.event(e=>{var t;(t=this._onScrollApi)==null||t.fire(e.position)})),this._onScrollApi.event}get cols(){return this._bufferService.cols}get rows(){return this._bufferService.rows}get buffers(){return this._bufferService.buffers}get options(){return this.optionsService.options}set options(e){for(let t in e)this.optionsService.options[t]=e[t]}write(e,t){this._writeBuffer.write(e,t)}writeSync(e,t){this._logService.logLevel<=3&&!sS&&(this._logService.warn("writeSync is unreliable and will be removed soon."),sS=!0),this._writeBuffer.writeSync(e,t)}input(e,t=!0){this.coreService.triggerDataEvent(e,t)}resize(e,t){isNaN(e)||isNaN(t)||(e=Math.max(e,SN),t=Math.max(t,jN),this._bufferService.resize(e,t))}scroll(e,t=!1){this._bufferService.scroll(e,t)}scrollLines(e,t){this._bufferService.scrollLines(e,t)}scrollPages(e){this.scrollLines(e*(this.rows-1))}scrollToTop(){this.scrollLines(-this._bufferService.buffer.ydisp)}scrollToBottom(e){this.scrollLines(this._bufferService.buffer.ybase-this._bufferService.buffer.ydisp)}scrollToLine(e){let t=e-this._bufferService.buffer.ydisp;t!==0&&this.scrollLines(t)}registerEscHandler(e,t){return this._inputHandler.registerEscHandler(e,t)}registerDcsHandler(e,t){return this._inputHandler.registerDcsHandler(e,t)}registerCsiHandler(e,t){return this._inputHandler.registerCsiHandler(e,t)}registerOscHandler(e,t){return this._inputHandler.registerOscHandler(e,t)}_setup(){this._handleWindowsPtyOptionChange()}reset(){this._inputHandler.reset(),this._bufferService.reset(),this._charsetService.reset(),this.coreService.reset(),this.coreMouseService.reset()}_handleWindowsPtyOptionChange(){let e=!1,t=this.optionsService.rawOptions.windowsPty;t&&t.buildNumber!==void 0&&t.buildNumber!==void 0?e=t.backend==="conpty"&&t.buildNumber<21376:this.optionsService.rawOptions.windowsMode&&(e=!0),e?this._enableWindowsWrappingHeuristics():this._windowsWrappingHeuristics.clear()}_enableWindowsWrappingHeuristics(){if(!this._windowsWrappingHeuristics.value){let e=[];e.push(this.onLineFeed(G2.bind(null,this._bufferService))),e.push(this.registerCsiHandler({final:"H"},()=>(G2(this._bufferService),!1))),this._windowsWrappingHeuristics.value=Ut(()=>{for(let t of e)t.dispose()})}}},AF={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:["'",'"']};function RF(e,t,s,n){var c;let a={type:0,cancel:!1,key:void 0},l=(e.shiftKey?1:0)|(e.altKey?2:0)|(e.ctrlKey?4:0)|(e.metaKey?8:0);switch(e.keyCode){case 0:e.key==="UIKeyInputUpArrow"?t?a.key=xe.ESC+"OA":a.key=xe.ESC+"[A":e.key==="UIKeyInputLeftArrow"?t?a.key=xe.ESC+"OD":a.key=xe.ESC+"[D":e.key==="UIKeyInputRightArrow"?t?a.key=xe.ESC+"OC":a.key=xe.ESC+"[C":e.key==="UIKeyInputDownArrow"&&(t?a.key=xe.ESC+"OB":a.key=xe.ESC+"[B");break;case 8:a.key=e.ctrlKey?"\b":xe.DEL,e.altKey&&(a.key=xe.ESC+a.key);break;case 9:if(e.shiftKey){a.key=xe.ESC+"[Z";break}a.key=xe.HT,a.cancel=!0;break;case 13:a.key=e.altKey?xe.ESC+xe.CR:xe.CR,a.cancel=!0;break;case 27:a.key=xe.ESC,e.altKey&&(a.key=xe.ESC+xe.ESC),a.cancel=!0;break;case 37:if(e.metaKey)break;l?a.key=xe.ESC+"[1;"+(l+1)+"D":t?a.key=xe.ESC+"OD":a.key=xe.ESC+"[D";break;case 39:if(e.metaKey)break;l?a.key=xe.ESC+"[1;"+(l+1)+"C":t?a.key=xe.ESC+"OC":a.key=xe.ESC+"[C";break;case 38:if(e.metaKey)break;l?a.key=xe.ESC+"[1;"+(l+1)+"A":t?a.key=xe.ESC+"OA":a.key=xe.ESC+"[A";break;case 40:if(e.metaKey)break;l?a.key=xe.ESC+"[1;"+(l+1)+"B":t?a.key=xe.ESC+"OB":a.key=xe.ESC+"[B";break;case 45:!e.shiftKey&&!e.ctrlKey&&(a.key=xe.ESC+"[2~");break;case 46:l?a.key=xe.ESC+"[3;"+(l+1)+"~":a.key=xe.ESC+"[3~";break;case 36:l?a.key=xe.ESC+"[1;"+(l+1)+"H":t?a.key=xe.ESC+"OH":a.key=xe.ESC+"[H";break;case 35:l?a.key=xe.ESC+"[1;"+(l+1)+"F":t?a.key=xe.ESC+"OF":a.key=xe.ESC+"[F";break;case 33:e.shiftKey?a.type=2:e.ctrlKey?a.key=xe.ESC+"[5;"+(l+1)+"~":a.key=xe.ESC+"[5~";break;case 34:e.shiftKey?a.type=3:e.ctrlKey?a.key=xe.ESC+"[6;"+(l+1)+"~":a.key=xe.ESC+"[6~";break;case 112:l?a.key=xe.ESC+"[1;"+(l+1)+"P":a.key=xe.ESC+"OP";break;case 113:l?a.key=xe.ESC+"[1;"+(l+1)+"Q":a.key=xe.ESC+"OQ";break;case 114:l?a.key=xe.ESC+"[1;"+(l+1)+"R":a.key=xe.ESC+"OR";break;case 115:l?a.key=xe.ESC+"[1;"+(l+1)+"S":a.key=xe.ESC+"OS";break;case 116:l?a.key=xe.ESC+"[15;"+(l+1)+"~":a.key=xe.ESC+"[15~";break;case 117:l?a.key=xe.ESC+"[17;"+(l+1)+"~":a.key=xe.ESC+"[17~";break;case 118:l?a.key=xe.ESC+"[18;"+(l+1)+"~":a.key=xe.ESC+"[18~";break;case 119:l?a.key=xe.ESC+"[19;"+(l+1)+"~":a.key=xe.ESC+"[19~";break;case 120:l?a.key=xe.ESC+"[20;"+(l+1)+"~":a.key=xe.ESC+"[20~";break;case 121:l?a.key=xe.ESC+"[21;"+(l+1)+"~":a.key=xe.ESC+"[21~";break;case 122:l?a.key=xe.ESC+"[23;"+(l+1)+"~":a.key=xe.ESC+"[23~";break;case 123:l?a.key=xe.ESC+"[24;"+(l+1)+"~":a.key=xe.ESC+"[24~";break;default:if(e.ctrlKey&&!e.shiftKey&&!e.altKey&&!e.metaKey)e.keyCode>=65&&e.keyCode<=90?a.key=String.fromCharCode(e.keyCode-64):e.keyCode===32?a.key=xe.NUL:e.keyCode>=51&&e.keyCode<=55?a.key=String.fromCharCode(e.keyCode-51+27):e.keyCode===56?a.key=xe.DEL:e.keyCode===219?a.key=xe.ESC:e.keyCode===220?a.key=xe.FS:e.keyCode===221&&(a.key=xe.GS);else if((!s||n)&&e.altKey&&!e.metaKey){let d=(c=AF[e.keyCode])==null?void 0:c[e.shiftKey?1:0];if(d)a.key=xe.ESC+d;else if(e.keyCode>=65&&e.keyCode<=90){let f=e.ctrlKey?e.keyCode-64:e.keyCode+32,h=String.fromCharCode(f);e.shiftKey&&(h=h.toUpperCase()),a.key=xe.ESC+h}else if(e.keyCode===32)a.key=xe.ESC+(e.ctrlKey?xe.NUL:" ");else if(e.key==="Dead"&&e.code.startsWith("Key")){let f=e.code.slice(3,4);e.shiftKey||(f=f.toLowerCase()),a.key=xe.ESC+f,a.cancel=!0}}else s&&!e.altKey&&!e.ctrlKey&&!e.shiftKey&&e.metaKey?e.keyCode===65&&(a.type=1):e.key&&!e.ctrlKey&&!e.altKey&&!e.metaKey&&e.keyCode>=48&&e.key.length===1?a.key=e.key:e.key&&e.ctrlKey&&(e.key==="_"&&(a.key=xe.US),e.key==="@"&&(a.key=xe.NUL));break}return a}var as=0,DF=class{constructor(e){this._getKey=e,this._array=[],this._insertedValues=[],this._flushInsertedTask=new Fh,this._isFlushingInserted=!1,this._deletedIndices=[],this._flushDeletedTask=new Fh,this._isFlushingDeleted=!1}clear(){this._array.length=0,this._insertedValues.length=0,this._flushInsertedTask.clear(),this._isFlushingInserted=!1,this._deletedIndices.length=0,this._flushDeletedTask.clear(),this._isFlushingDeleted=!1}insert(e){this._flushCleanupDeleted(),this._insertedValues.length===0&&this._flushInsertedTask.enqueue(()=>this._flushInserted()),this._insertedValues.push(e)}_flushInserted(){let e=this._insertedValues.sort((a,l)=>this._getKey(a)-this._getKey(l)),t=0,s=0,n=new Array(this._array.length+this._insertedValues.length);for(let a=0;a<n.length;a++)s>=this._array.length||this._getKey(e[t])<=this._getKey(this._array[s])?(n[a]=e[t],t++):n[a]=this._array[s++];this._array=n,this._insertedValues.length=0}_flushCleanupInserted(){!this._isFlushingInserted&&this._insertedValues.length>0&&this._flushInsertedTask.flush()}delete(e){if(this._flushCleanupInserted(),this._array.length===0)return!1;let t=this._getKey(e);if(t===void 0||(as=this._search(t),as===-1)||this._getKey(this._array[as])!==t)return!1;do if(this._array[as]===e)return this._deletedIndices.length===0&&this._flushDeletedTask.enqueue(()=>this._flushDeleted()),this._deletedIndices.push(as),!0;while(++as<this._array.length&&this._getKey(this._array[as])===t);return!1}_flushDeleted(){this._isFlushingDeleted=!0;let e=this._deletedIndices.sort((a,l)=>a-l),t=0,s=new Array(this._array.length-e.length),n=0;for(let a=0;a<this._array.length;a++)e[t]===a?t++:s[n++]=this._array[a];this._array=s,this._deletedIndices.length=0,this._isFlushingDeleted=!1}_flushCleanupDeleted(){!this._isFlushingDeleted&&this._deletedIndices.length>0&&this._flushDeletedTask.flush()}*getKeyIterator(e){if(this._flushCleanupInserted(),this._flushCleanupDeleted(),this._array.length!==0&&(as=this._search(e),!(as<0||as>=this._array.length)&&this._getKey(this._array[as])===e))do yield this._array[as];while(++as<this._array.length&&this._getKey(this._array[as])===e)}forEachByKey(e,t){if(this._flushCleanupInserted(),this._flushCleanupDeleted(),this._array.length!==0&&(as=this._search(e),!(as<0||as>=this._array.length)&&this._getKey(this._array[as])===e))do t(this._array[as]);while(++as<this._array.length&&this._getKey(this._array[as])===e)}values(){return this._flushCleanupInserted(),this._flushCleanupDeleted(),[...this._array].values()}_search(e){let t=0,s=this._array.length-1;for(;s>=t;){let n=t+s>>1,a=this._getKey(this._array[n]);if(a>e)s=n-1;else if(a<e)t=n+1;else{for(;n>0&&this._getKey(this._array[n-1])===e;)n--;return n}}return t}},Rg=0,nS=0,LF=class extends nt{constructor(){super(),this._decorations=new DF(e=>e==null?void 0:e.marker.line),this._onDecorationRegistered=this._register(new Ce),this.onDecorationRegistered=this._onDecorationRegistered.event,this._onDecorationRemoved=this._register(new Ce),this.onDecorationRemoved=this._onDecorationRemoved.event,this._register(Ut(()=>this.reset()))}get decorations(){return this._decorations.values()}registerDecoration(e){if(e.marker.isDisposed)return;let t=new BF(e);if(t){let s=t.marker.onDispose(()=>t.dispose()),n=t.onDispose(()=>{n.dispose(),t&&(this._decorations.delete(t)&&this._onDecorationRemoved.fire(t),s.dispose())});this._decorations.insert(t),this._onDecorationRegistered.fire(t)}return t}reset(){for(let e of this._decorations.values())e.dispose();this._decorations.clear()}*getDecorationsAtCell(e,t,s){let n=0,a=0;for(let l of this._decorations.getKeyIterator(t))n=l.options.x??0,a=n+(l.options.width??1),e>=n&&e<a&&(!s||(l.options.layer??"bottom")===s)&&(yield l)}forEachDecorationAtCell(e,t,s,n){this._decorations.forEachByKey(t,a=>{Rg=a.options.x??0,nS=Rg+(a.options.width??1),e>=Rg&&e<nS&&(!s||(a.options.layer??"bottom")===s)&&n(a)})}},BF=class extends Yi{constructor(e){super(),this.options=e,this.onRenderEmitter=this.add(new Ce),this.onRender=this.onRenderEmitter.event,this._onDispose=this.add(new Ce),this.onDispose=this._onDispose.event,this._cachedBg=null,this._cachedFg=null,this.marker=e.marker,this.options.overviewRulerOptions&&!this.options.overviewRulerOptions.position&&(this.options.overviewRulerOptions.position="full")}get backgroundColorRGB(){return this._cachedBg===null&&(this.options.backgroundColor?this._cachedBg=Wt.toColor(this.options.backgroundColor):this._cachedBg=void 0),this._cachedBg}get foregroundColorRGB(){return this._cachedFg===null&&(this.options.foregroundColor?this._cachedFg=Wt.toColor(this.options.foregroundColor):this._cachedFg=void 0),this._cachedFg}dispose(){this._onDispose.fire(),super.dispose()}},OF=1e3,zF=class{constructor(e,t=OF){this._renderCallback=e,this._debounceThresholdMS=t,this._lastRefreshMs=0,this._additionalRefreshRequested=!1}dispose(){this._refreshTimeoutID&&clearTimeout(this._refreshTimeoutID)}refresh(e,t,s){this._rowCount=s,e=e!==void 0?e:0,t=t!==void 0?t:this._rowCount-1,this._rowStart=this._rowStart!==void 0?Math.min(this._rowStart,e):e,this._rowEnd=this._rowEnd!==void 0?Math.max(this._rowEnd,t):t;let n=performance.now();if(n-this._lastRefreshMs>=this._debounceThresholdMS)this._lastRefreshMs=n,this._innerRefresh();else if(!this._additionalRefreshRequested){let a=n-this._lastRefreshMs,l=this._debounceThresholdMS-a;this._additionalRefreshRequested=!0,this._refreshTimeoutID=window.setTimeout(()=>{this._lastRefreshMs=performance.now(),this._innerRefresh(),this._additionalRefreshRequested=!1,this._refreshTimeoutID=void 0},l)}}_innerRefresh(){if(this._rowStart===void 0||this._rowEnd===void 0||this._rowCount===void 0)return;let e=Math.max(this._rowStart,0),t=Math.min(this._rowEnd,this._rowCount-1);this._rowStart=void 0,this._rowEnd=void 0,this._renderCallback(e,t)}},rS=20,Hh=class extends nt{constructor(e,t,s,n){super(),this._terminal=e,this._coreBrowserService=s,this._renderService=n,this._rowColumns=new WeakMap,this._liveRegionLineCount=0,this._charsToConsume=[],this._charsToAnnounce="";let a=this._coreBrowserService.mainDocument;this._accessibilityContainer=a.createElement("div"),this._accessibilityContainer.classList.add("xterm-accessibility"),this._rowContainer=a.createElement("div"),this._rowContainer.setAttribute("role","list"),this._rowContainer.classList.add("xterm-accessibility-tree"),this._rowElements=[];for(let l=0;l<this._terminal.rows;l++)this._rowElements[l]=this._createAccessibilityTreeNode(),this._rowContainer.appendChild(this._rowElements[l]);if(this._topBoundaryFocusListener=l=>this._handleBoundaryFocus(l,0),this._bottomBoundaryFocusListener=l=>this._handleBoundaryFocus(l,1),this._rowElements[0].addEventListener("focus",this._topBoundaryFocusListener),this._rowElements[this._rowElements.length-1].addEventListener("focus",this._bottomBoundaryFocusListener),this._accessibilityContainer.appendChild(this._rowContainer),this._liveRegion=a.createElement("div"),this._liveRegion.classList.add("live-region"),this._liveRegion.setAttribute("aria-live","assertive"),this._accessibilityContainer.appendChild(this._liveRegion),this._liveRegionDebouncer=this._register(new zF(this._renderRows.bind(this))),!this._terminal.element)throw new Error("Cannot enable accessibility before Terminal.open");this._terminal.element.insertAdjacentElement("afterbegin",this._accessibilityContainer),this._register(this._terminal.onResize(l=>this._handleResize(l.rows))),this._register(this._terminal.onRender(l=>this._refreshRows(l.start,l.end))),this._register(this._terminal.onScroll(()=>this._refreshRows())),this._register(this._terminal.onA11yChar(l=>this._handleChar(l))),this._register(this._terminal.onLineFeed(()=>this._handleChar(`
|
|
257
257
|
`))),this._register(this._terminal.onA11yTab(l=>this._handleTab(l))),this._register(this._terminal.onKey(l=>this._handleKey(l.key))),this._register(this._terminal.onBlur(()=>this._clearLiveRegion())),this._register(this._renderService.onDimensionsChange(()=>this._refreshRowsDimensions())),this._register(Ge(a,"selectionchange",()=>this._handleSelectionChange())),this._register(this._coreBrowserService.onDprChange(()=>this._refreshRowsDimensions())),this._refreshRowsDimensions(),this._refreshRows(),this._register(Ut(()=>{this._accessibilityContainer.remove(),this._rowElements.length=0}))}_handleTab(e){for(let t=0;t<e;t++)this._handleChar(" ")}_handleChar(e){this._liveRegionLineCount<rS+1&&(this._charsToConsume.length>0?this._charsToConsume.shift()!==e&&(this._charsToAnnounce+=e):this._charsToAnnounce+=e,e===`
|
|
258
|
-
`&&(this._liveRegionLineCount++,this._liveRegionLineCount===rS+1&&(this._liveRegion.textContent+=Lx.get())))}_clearLiveRegion(){this._liveRegion.textContent="",this._liveRegionLineCount=0}_handleKey(e){this._clearLiveRegion(),new RegExp("\\p{Control}","u").test(e)||this._charsToConsume.push(e)}_refreshRows(e,t){this._liveRegionDebouncer.refresh(e,t,this._terminal.rows)}_renderRows(e,t){let s=this._terminal.buffer,n=s.lines.length.toString();for(let a=e;a<=t;a++){let l=s.lines.get(s.ydisp+a),c=[],d=(l==null?void 0:l.translateToString(!0,void 0,void 0,c))||"",f=(s.ydisp+a+1).toString(),h=this._rowElements[a];h&&(d.length===0?(h.textContent=" ",this._rowColumns.set(h,[0,1])):(h.textContent=d,this._rowColumns.set(h,c)),h.setAttribute("aria-posinset",f),h.setAttribute("aria-setsize",n),this._alignRowWidth(h))}this._announceCharacters()}_announceCharacters(){this._charsToAnnounce.length!==0&&(this._liveRegion.textContent+=this._charsToAnnounce,this._charsToAnnounce="")}_handleBoundaryFocus(e,t){let s=e.target,n=this._rowElements[t===0?1:this._rowElements.length-2],a=s.getAttribute("aria-posinset"),l=t===0?"1":`${this._terminal.buffer.lines.length}`;if(a===l||e.relatedTarget!==n)return;let c,d;if(t===0?(c=s,d=this._rowElements.pop(),this._rowContainer.removeChild(d)):(c=this._rowElements.shift(),d=s,this._rowContainer.removeChild(c)),c.removeEventListener("focus",this._topBoundaryFocusListener),d.removeEventListener("focus",this._bottomBoundaryFocusListener),t===0){let f=this._createAccessibilityTreeNode();this._rowElements.unshift(f),this._rowContainer.insertAdjacentElement("afterbegin",f)}else{let f=this._createAccessibilityTreeNode();this._rowElements.push(f),this._rowContainer.appendChild(f)}this._rowElements[0].addEventListener("focus",this._topBoundaryFocusListener),this._rowElements[this._rowElements.length-1].addEventListener("focus",this._bottomBoundaryFocusListener),this._terminal.scrollLines(t===0?-1:1),this._rowElements[t===0?1:this._rowElements.length-2].focus(),e.preventDefault(),e.stopImmediatePropagation()}_handleSelectionChange(){var d;if(this._rowElements.length===0)return;let e=this._coreBrowserService.mainDocument.getSelection();if(!e)return;if(e.isCollapsed){this._rowContainer.contains(e.anchorNode)&&this._terminal.clearSelection();return}if(!e.anchorNode||!e.focusNode){console.error("anchorNode and/or focusNode are null");return}let t={node:e.anchorNode,offset:e.anchorOffset},s={node:e.focusNode,offset:e.focusOffset};if((t.node.compareDocumentPosition(s.node)&Node.DOCUMENT_POSITION_PRECEDING||t.node===s.node&&t.offset>s.offset)&&([t,s]=[s,t]),t.node.compareDocumentPosition(this._rowElements[0])&(Node.DOCUMENT_POSITION_CONTAINED_BY|Node.DOCUMENT_POSITION_FOLLOWING)&&(t={node:this._rowElements[0].childNodes[0],offset:0}),!this._rowContainer.contains(t.node))return;let n=this._rowElements.slice(-1)[0];if(s.node.compareDocumentPosition(n)&(Node.DOCUMENT_POSITION_CONTAINED_BY|Node.DOCUMENT_POSITION_PRECEDING)&&(s={node:n,offset:((d=n.textContent)==null?void 0:d.length)??0}),!this._rowContainer.contains(s.node))return;let a=({node:f,offset:h})=>{let m=f instanceof Text?f.parentNode:f,g=parseInt(m==null?void 0:m.getAttribute("aria-posinset"),10)-1;if(isNaN(g))return console.warn("row is invalid. Race condition?"),null;let b=this._rowColumns.get(m);if(!b)return console.warn("columns is null. Race condition?"),null;let v=h<b.length?b[h]:b.slice(-1)[0]+1;return v>=this._terminal.cols&&(++g,v=0),{row:g,column:v}},l=a(t),c=a(s);if(!(!l||!c)){if(l.row>c.row||l.row===c.row&&l.column>=c.column)throw new Error("invalid range");this._terminal.select(l.column,l.row,(c.row-l.row)*this._terminal.cols-l.column+c.column)}}_handleResize(e){this._rowElements[this._rowElements.length-1].removeEventListener("focus",this._bottomBoundaryFocusListener);for(let t=this._rowContainer.children.length;t<this._terminal.rows;t++)this._rowElements[t]=this._createAccessibilityTreeNode(),this._rowContainer.appendChild(this._rowElements[t]);for(;this._rowElements.length>e;)this._rowContainer.removeChild(this._rowElements.pop());this._rowElements[this._rowElements.length-1].addEventListener("focus",this._bottomBoundaryFocusListener),this._refreshRowsDimensions()}_createAccessibilityTreeNode(){let e=this._coreBrowserService.mainDocument.createElement("div");return e.setAttribute("role","listitem"),e.tabIndex=-1,this._refreshRowDimensions(e),e}_refreshRowsDimensions(){if(this._renderService.dimensions.css.cell.height){Object.assign(this._accessibilityContainer.style,{width:`${this._renderService.dimensions.css.canvas.width}px`,fontSize:`${this._terminal.options.fontSize}px`}),this._rowElements.length!==this._terminal.rows&&this._handleResize(this._terminal.rows);for(let e=0;e<this._terminal.rows;e++)this._refreshRowDimensions(this._rowElements[e]),this._alignRowWidth(this._rowElements[e])}}_refreshRowDimensions(e){e.style.height=`${this._renderService.dimensions.css.cell.height}px`}_alignRowWidth(e){var a,l;e.style.transform="";let t=e.getBoundingClientRect().width,s=(l=(a=this._rowColumns.get(e))==null?void 0:a.slice(-1))==null?void 0:l[0];if(!s)return;let n=s*this._renderService.dimensions.css.cell.width;e.style.transform=`scaleX(${n/t})`}};Hh=ts([Re(1,ov),Re(2,ai),Re(3,oi)],Hh);var m0=class extends nt{constructor(e,t,s,n,a){super(),this._element=e,this._mouseService=t,this._renderService=s,this._bufferService=n,this._linkProviderService=a,this._linkCacheDisposables=[],this._isMouseOut=!0,this._wasResized=!1,this._activeLine=-1,this._onShowLinkUnderline=this._register(new Ce),this.onShowLinkUnderline=this._onShowLinkUnderline.event,this._onHideLinkUnderline=this._register(new Ce),this.onHideLinkUnderline=this._onHideLinkUnderline.event,this._register(Ut(()=>{var l;Ra(this._linkCacheDisposables),this._linkCacheDisposables.length=0,this._lastMouseEvent=void 0,(l=this._activeProviderReplies)==null||l.clear()})),this._register(this._bufferService.onResize(()=>{this._clearCurrentLink(),this._wasResized=!0})),this._register(Ge(this._element,"mouseleave",()=>{this._isMouseOut=!0,this._clearCurrentLink()})),this._register(Ge(this._element,"mousemove",this._handleMouseMove.bind(this))),this._register(Ge(this._element,"mousedown",this._handleMouseDown.bind(this))),this._register(Ge(this._element,"mouseup",this._handleMouseUp.bind(this)))}get currentLink(){return this._currentLink}_handleMouseMove(e){this._lastMouseEvent=e;let t=this._positionFromMouseEvent(e,this._element,this._mouseService);if(!t)return;this._isMouseOut=!1;let s=e.composedPath();for(let n=0;n<s.length;n++){let a=s[n];if(a.classList.contains("xterm"))break;if(a.classList.contains("xterm-hover"))return}(!this._lastBufferCell||t.x!==this._lastBufferCell.x||t.y!==this._lastBufferCell.y)&&(this._handleHover(t),this._lastBufferCell=t)}_handleHover(e){if(this._activeLine!==e.y||this._wasResized){this._clearCurrentLink(),this._askForLink(e,!1),this._wasResized=!1;return}this._currentLink&&this._linkAtPosition(this._currentLink.link,e)||(this._clearCurrentLink(),this._askForLink(e,!0))}_askForLink(e,t){var n,a;(!this._activeProviderReplies||!t)&&((n=this._activeProviderReplies)==null||n.forEach(l=>{l==null||l.forEach(c=>{c.link.dispose&&c.link.dispose()})}),this._activeProviderReplies=new Map,this._activeLine=e.y);let s=!1;for(let[l,c]of this._linkProviderService.linkProviders.entries())t?(a=this._activeProviderReplies)!=null&&a.get(l)&&(s=this._checkLinkProviderResult(l,e,s)):c.provideLinks(e.y,d=>{var h,m;if(this._isMouseOut)return;let f=d==null?void 0:d.map(g=>({link:g}));(h=this._activeProviderReplies)==null||h.set(l,f),s=this._checkLinkProviderResult(l,e,s),((m=this._activeProviderReplies)==null?void 0:m.size)===this._linkProviderService.linkProviders.length&&this._removeIntersectingLinks(e.y,this._activeProviderReplies)})}_removeIntersectingLinks(e,t){let s=new Set;for(let n=0;n<t.size;n++){let a=t.get(n);if(a)for(let l=0;l<a.length;l++){let c=a[l],d=c.link.range.start.y<e?0:c.link.range.start.x,f=c.link.range.end.y>e?this._bufferService.cols:c.link.range.end.x;for(let h=d;h<=f;h++){if(s.has(h)){a.splice(l--,1);break}s.add(h)}}}}_checkLinkProviderResult(e,t,s){var l;if(!this._activeProviderReplies)return s;let n=this._activeProviderReplies.get(e),a=!1;for(let c=0;c<e;c++)(!this._activeProviderReplies.has(c)||this._activeProviderReplies.get(c))&&(a=!0);if(!a&&n){let c=n.find(d=>this._linkAtPosition(d.link,t));c&&(s=!0,this._handleNewLink(c))}if(this._activeProviderReplies.size===this._linkProviderService.linkProviders.length&&!s)for(let c=0;c<this._activeProviderReplies.size;c++){let d=(l=this._activeProviderReplies.get(c))==null?void 0:l.find(f=>this._linkAtPosition(f.link,t));if(d){s=!0,this._handleNewLink(d);break}}return s}_handleMouseDown(){this._mouseDownLink=this._currentLink}_handleMouseUp(e){if(!this._currentLink)return;let t=this._positionFromMouseEvent(e,this._element,this._mouseService);t&&this._mouseDownLink&&zF(this._mouseDownLink.link,this._currentLink.link)&&this._linkAtPosition(this._currentLink.link,t)&&this._currentLink.link.activate(e,this._currentLink.link.text)}_clearCurrentLink(e,t){!this._currentLink||!this._lastMouseEvent||(!e||!t||this._currentLink.link.range.start.y>=e&&this._currentLink.link.range.end.y<=t)&&(this._linkLeave(this._element,this._currentLink.link,this._lastMouseEvent),this._currentLink=void 0,Ra(this._linkCacheDisposables),this._linkCacheDisposables.length=0)}_handleNewLink(e){if(!this._lastMouseEvent)return;let t=this._positionFromMouseEvent(this._lastMouseEvent,this._element,this._mouseService);t&&this._linkAtPosition(e.link,t)&&(this._currentLink=e,this._currentLink.state={decorations:{underline:e.link.decorations===void 0?!0:e.link.decorations.underline,pointerCursor:e.link.decorations===void 0?!0:e.link.decorations.pointerCursor},isHovered:!0},this._linkHover(this._element,e.link,this._lastMouseEvent),e.link.decorations={},Object.defineProperties(e.link.decorations,{pointerCursor:{get:()=>{var s,n;return(n=(s=this._currentLink)==null?void 0:s.state)==null?void 0:n.decorations.pointerCursor},set:s=>{var n;(n=this._currentLink)!=null&&n.state&&this._currentLink.state.decorations.pointerCursor!==s&&(this._currentLink.state.decorations.pointerCursor=s,this._currentLink.state.isHovered&&this._element.classList.toggle("xterm-cursor-pointer",s))}},underline:{get:()=>{var s,n;return(n=(s=this._currentLink)==null?void 0:s.state)==null?void 0:n.decorations.underline},set:s=>{var n,a,l;(n=this._currentLink)!=null&&n.state&&((l=(a=this._currentLink)==null?void 0:a.state)==null?void 0:l.decorations.underline)!==s&&(this._currentLink.state.decorations.underline=s,this._currentLink.state.isHovered&&this._fireUnderlineEvent(e.link,s))}}}),this._linkCacheDisposables.push(this._renderService.onRenderedViewportChange(s=>{if(!this._currentLink)return;let n=s.start===0?0:s.start+1+this._bufferService.buffer.ydisp,a=this._bufferService.buffer.ydisp+1+s.end;if(this._currentLink.link.range.start.y>=n&&this._currentLink.link.range.end.y<=a&&(this._clearCurrentLink(n,a),this._lastMouseEvent)){let l=this._positionFromMouseEvent(this._lastMouseEvent,this._element,this._mouseService);l&&this._askForLink(l,!1)}})))}_linkHover(e,t,s){var n;(n=this._currentLink)!=null&&n.state&&(this._currentLink.state.isHovered=!0,this._currentLink.state.decorations.underline&&this._fireUnderlineEvent(t,!0),this._currentLink.state.decorations.pointerCursor&&e.classList.add("xterm-cursor-pointer")),t.hover&&t.hover(s,t.text)}_fireUnderlineEvent(e,t){let s=e.range,n=this._bufferService.buffer.ydisp,a=this._createLinkUnderlineEvent(s.start.x-1,s.start.y-n-1,s.end.x,s.end.y-n-1,void 0);(t?this._onShowLinkUnderline:this._onHideLinkUnderline).fire(a)}_linkLeave(e,t,s){var n;(n=this._currentLink)!=null&&n.state&&(this._currentLink.state.isHovered=!1,this._currentLink.state.decorations.underline&&this._fireUnderlineEvent(t,!1),this._currentLink.state.decorations.pointerCursor&&e.classList.remove("xterm-cursor-pointer")),t.leave&&t.leave(s,t.text)}_linkAtPosition(e,t){let s=e.range.start.y*this._bufferService.cols+e.range.start.x,n=e.range.end.y*this._bufferService.cols+e.range.end.x,a=t.y*this._bufferService.cols+t.x;return s<=a&&a<=n}_positionFromMouseEvent(e,t,s){let n=s.getCoords(e,t,this._bufferService.cols,this._bufferService.rows);if(n)return{x:n[0],y:n[1]+this._bufferService.buffer.ydisp}}_createLinkUnderlineEvent(e,t,s,n,a){return{x1:e,y1:t,x2:s,y2:n,cols:this._bufferService.cols,fg:a}}};m0=ts([Re(1,lv),Re(2,oi),Re(3,sn),Re(4,GC)],m0);function zF(e,t){return e.text===t.text&&e.range.start.x===t.range.start.x&&e.range.start.y===t.range.start.y&&e.range.end.x===t.range.end.x&&e.range.end.y===t.range.end.y}var PF=class extends MF{constructor(e={}){super(e),this._linkifier=this._register(new Yo),this.browser=hN,this._keyDownHandled=!1,this._keyDownSeen=!1,this._keyPressHandled=!1,this._unprocessedDeadKey=!1,this._accessibilityManager=this._register(new Yo),this._onCursorMove=this._register(new Ce),this.onCursorMove=this._onCursorMove.event,this._onKey=this._register(new Ce),this.onKey=this._onKey.event,this._onRender=this._register(new Ce),this.onRender=this._onRender.event,this._onSelectionChange=this._register(new Ce),this.onSelectionChange=this._onSelectionChange.event,this._onTitleChange=this._register(new Ce),this.onTitleChange=this._onTitleChange.event,this._onBell=this._register(new Ce),this.onBell=this._onBell.event,this._onFocus=this._register(new Ce),this._onBlur=this._register(new Ce),this._onA11yCharEmitter=this._register(new Ce),this._onA11yTabEmitter=this._register(new Ce),this._onWillOpen=this._register(new Ce),this._setup(),this._decorationService=this._instantiationService.createInstance(DF),this._instantiationService.setService(mu,this._decorationService),this._linkProviderService=this._instantiationService.createInstance(NI),this._instantiationService.setService(GC,this._linkProviderService),this._linkProviderService.registerLinkProvider(this._instantiationService.createInstance(Ox)),this._register(this._inputHandler.onRequestBell(()=>this._onBell.fire())),this._register(this._inputHandler.onRequestRefreshRows(t=>this.refresh((t==null?void 0:t.start)??0,(t==null?void 0:t.end)??this.rows-1))),this._register(this._inputHandler.onRequestSendFocus(()=>this._reportFocus())),this._register(this._inputHandler.onRequestReset(()=>this.reset())),this._register(this._inputHandler.onRequestWindowsOptionsReport(t=>this._reportWindowsOptions(t))),this._register(this._inputHandler.onColor(t=>this._handleColorEvent(t))),this._register(Is.forward(this._inputHandler.onCursorMove,this._onCursorMove)),this._register(Is.forward(this._inputHandler.onTitleChange,this._onTitleChange)),this._register(Is.forward(this._inputHandler.onA11yChar,this._onA11yCharEmitter)),this._register(Is.forward(this._inputHandler.onA11yTab,this._onA11yTabEmitter)),this._register(this._bufferService.onResize(t=>this._afterResize(t.cols,t.rows))),this._register(Ut(()=>{var t,s;this._customKeyEventHandler=void 0,(s=(t=this.element)==null?void 0:t.parentNode)==null||s.removeChild(this.element)}))}get linkifier(){return this._linkifier.value}get onFocus(){return this._onFocus.event}get onBlur(){return this._onBlur.event}get onA11yChar(){return this._onA11yCharEmitter.event}get onA11yTab(){return this._onA11yTabEmitter.event}get onWillOpen(){return this._onWillOpen.event}_handleColorEvent(e){if(this._themeService)for(let t of e){let s,n="";switch(t.index){case 256:s="foreground",n="10";break;case 257:s="background",n="11";break;case 258:s="cursor",n="12";break;default:s="ansi",n="4;"+t.index}switch(t.type){case 0:let a=$t.toColorRGB(s==="ansi"?this._themeService.colors.ansi[t.index]:this._themeService.colors[s]);this.coreService.triggerDataEvent(`${xe.ESC}]${n};${SF(a)}${uN.ST}`);break;case 1:if(s==="ansi")this._themeService.modifyColors(l=>l.ansi[t.index]=ps.toColor(...t.color));else{let l=s;this._themeService.modifyColors(c=>c[l]=ps.toColor(...t.color))}break;case 2:this._themeService.restoreColor(t.index);break}}}_setup(){super._setup(),this._customKeyEventHandler=void 0}get buffer(){return this.buffers.active}focus(){this.textarea&&this.textarea.focus({preventScroll:!0})}_handleScreenReaderModeOptionChange(e){e?!this._accessibilityManager.value&&this._renderService&&(this._accessibilityManager.value=this._instantiationService.createInstance(Hh,this)):this._accessibilityManager.clear()}_handleTextAreaFocus(e){this.coreService.decPrivateModes.sendFocus&&this.coreService.triggerDataEvent(xe.ESC+"[I"),this.element.classList.add("focus"),this._showCursor(),this._onFocus.fire()}blur(){var e;return(e=this.textarea)==null?void 0:e.blur()}_handleTextAreaBlur(){this.textarea.value="",this.refresh(this.buffer.y,this.buffer.y),this.coreService.decPrivateModes.sendFocus&&this.coreService.triggerDataEvent(xe.ESC+"[O"),this.element.classList.remove("focus"),this._onBlur.fire()}_syncTextArea(){if(!this.textarea||!this.buffer.isCursorInViewport||this._compositionHelper.isComposing||!this._renderService)return;let e=this.buffer.ybase+this.buffer.y,t=this.buffer.lines.get(e);if(!t)return;let s=Math.min(this.buffer.x,this.cols-1),n=this._renderService.dimensions.css.cell.height,a=t.getWidth(s),l=this._renderService.dimensions.css.cell.width*a,c=this.buffer.y*this._renderService.dimensions.css.cell.height,d=s*this._renderService.dimensions.css.cell.width;this.textarea.style.left=d+"px",this.textarea.style.top=c+"px",this.textarea.style.width=l+"px",this.textarea.style.height=n+"px",this.textarea.style.lineHeight=n+"px",this.textarea.style.zIndex="-5"}_initGlobal(){this._bindKeys(),this._register(Ge(this.element,"copy",t=>{this.hasSelection()&&H9(t,this._selectionService)}));let e=t=>U9(t,this.textarea,this.coreService,this.optionsService);this._register(Ge(this.textarea,"paste",e)),this._register(Ge(this.element,"paste",e)),fN?this._register(Ge(this.element,"mousedown",t=>{t.button===2&&p2(t,this.textarea,this.screenElement,this._selectionService,this.options.rightClickSelectsWord)})):this._register(Ge(this.element,"contextmenu",t=>{p2(t,this.textarea,this.screenElement,this._selectionService,this.options.rightClickSelectsWord)})),gv&&this._register(Ge(this.element,"auxclick",t=>{t.button===1&&PC(t,this.textarea,this.screenElement)}))}_bindKeys(){this._register(Ge(this.textarea,"keyup",e=>this._keyUp(e),!0)),this._register(Ge(this.textarea,"keydown",e=>this._keyDown(e),!0)),this._register(Ge(this.textarea,"keypress",e=>this._keyPress(e),!0)),this._register(Ge(this.textarea,"compositionstart",()=>this._compositionHelper.compositionstart())),this._register(Ge(this.textarea,"compositionupdate",e=>this._compositionHelper.compositionupdate(e))),this._register(Ge(this.textarea,"compositionend",()=>this._compositionHelper.compositionend())),this._register(Ge(this.textarea,"input",e=>this._inputEvent(e),!0)),this._register(this.onRender(()=>this._compositionHelper.updateCompositionElements()))}open(e){var a;if(!e)throw new Error("Terminal requires a parent element.");if(e.isConnected||this._logService.debug("Terminal.open was called on an element that was not attached to the DOM"),((a=this.element)==null?void 0:a.ownerDocument.defaultView)&&this._coreBrowserService){this.element.ownerDocument.defaultView!==this._coreBrowserService.window&&(this._coreBrowserService.window=this.element.ownerDocument.defaultView);return}this._document=e.ownerDocument,this.options.documentOverride&&this.options.documentOverride instanceof Document&&(this._document=this.optionsService.rawOptions.documentOverride),this.element=this._document.createElement("div"),this.element.dir="ltr",this.element.classList.add("terminal"),this.element.classList.add("xterm"),e.appendChild(this.element);let t=this._document.createDocumentFragment();this._viewportElement=this._document.createElement("div"),this._viewportElement.classList.add("xterm-viewport"),t.appendChild(this._viewportElement),this.screenElement=this._document.createElement("div"),this.screenElement.classList.add("xterm-screen"),this._register(Ge(this.screenElement,"mousemove",l=>this.updateCursorStyle(l))),this._helperContainer=this._document.createElement("div"),this._helperContainer.classList.add("xterm-helpers"),this.screenElement.appendChild(this._helperContainer),t.appendChild(this.screenElement);let s=this.textarea=this._document.createElement("textarea");this.textarea.classList.add("xterm-helper-textarea"),this.textarea.setAttribute("aria-label",Dx.get()),gN||this.textarea.setAttribute("aria-multiline","false"),this.textarea.setAttribute("autocorrect","off"),this.textarea.setAttribute("autocapitalize","off"),this.textarea.setAttribute("spellcheck","false"),this.textarea.tabIndex=0,this._register(this.optionsService.onSpecificOptionChange("disableStdin",()=>s.readOnly=this.optionsService.rawOptions.disableStdin)),this.textarea.readOnly=this.optionsService.rawOptions.disableStdin,this._coreBrowserService=this._register(this._instantiationService.createInstance(kI,this.textarea,e.ownerDocument.defaultView??window,this._document??typeof window<"u"?window.document:null)),this._instantiationService.setService(ai,this._coreBrowserService),this._register(Ge(this.textarea,"focus",l=>this._handleTextAreaFocus(l))),this._register(Ge(this.textarea,"blur",()=>this._handleTextAreaBlur())),this._helperContainer.appendChild(this.textarea),this._charSizeService=this._instantiationService.createInstance(n0,this._document,this._helperContainer),this._instantiationService.setService(sf,this._charSizeService),this._themeService=this._instantiationService.createInstance(o0),this._instantiationService.setService(tl,this._themeService),this._characterJoinerService=this._instantiationService.createInstance($h),this._instantiationService.setService(qC,this._characterJoinerService),this._renderService=this._register(this._instantiationService.createInstance(i0,this.rows,this.screenElement)),this._instantiationService.setService(oi,this._renderService),this._register(this._renderService.onRenderedViewportChange(l=>this._onRender.fire(l))),this.onResize(l=>this._renderService.resize(l.cols,l.rows)),this._compositionView=this._document.createElement("div"),this._compositionView.classList.add("composition-view"),this._compositionHelper=this._instantiationService.createInstance(e0,this.textarea,this._compositionView),this._helperContainer.appendChild(this._compositionView),this._mouseService=this._instantiationService.createInstance(r0),this._instantiationService.setService(lv,this._mouseService);let n=this._linkifier.value=this._register(this._instantiationService.createInstance(m0,this.screenElement));this.element.appendChild(t);try{this._onWillOpen.fire(this.element)}catch{}this._renderService.hasRenderer()||this._renderService.setRenderer(this._createRenderer()),this._register(this.onCursorMove(()=>{this._renderService.handleCursorMove(),this._syncTextArea()})),this._register(this.onResize(()=>this._renderService.handleResize(this.cols,this.rows))),this._register(this.onBlur(()=>this._renderService.handleBlur())),this._register(this.onFocus(()=>this._renderService.handleFocus())),this._viewport=this._register(this._instantiationService.createInstance(Qx,this.element,this.screenElement)),this._register(this._viewport.onRequestScrollLines(l=>{super.scrollLines(l,!1),this.refresh(0,this.rows-1)})),this._selectionService=this._register(this._instantiationService.createInstance(a0,this.element,this.screenElement,n)),this._instantiationService.setService(J9,this._selectionService),this._register(this._selectionService.onRequestScrollLines(l=>this.scrollLines(l.amount,l.suppressScrollEvent))),this._register(this._selectionService.onSelectionChange(()=>this._onSelectionChange.fire())),this._register(this._selectionService.onRequestRedraw(l=>this._renderService.handleSelectionChanged(l.start,l.end,l.columnSelectMode))),this._register(this._selectionService.onLinuxMouseSelection(l=>{this.textarea.value=l,this.textarea.focus(),this.textarea.select()})),this._register(Is.any(this._onScroll.event,this._inputHandler.onScroll)(()=>{var l;this._selectionService.refresh(),(l=this._viewport)==null||l.queueSync()})),this._register(this._instantiationService.createInstance(Zx,this.screenElement)),this._register(Ge(this.element,"mousedown",l=>this._selectionService.handleMouseDown(l))),this.coreMouseService.areMouseEventsActive?(this._selectionService.disable(),this.element.classList.add("enable-mouse-events")):this._selectionService.enable(),this.options.screenReaderMode&&(this._accessibilityManager.value=this._instantiationService.createInstance(Hh,this)),this._register(this.optionsService.onSpecificOptionChange("screenReaderMode",l=>this._handleScreenReaderModeOptionChange(l))),this.options.overviewRuler.width&&(this._overviewRulerRenderer=this._register(this._instantiationService.createInstance(Ph,this._viewportElement,this.screenElement))),this.optionsService.onSpecificOptionChange("overviewRuler",l=>{!this._overviewRulerRenderer&&l&&this._viewportElement&&this.screenElement&&(this._overviewRulerRenderer=this._register(this._instantiationService.createInstance(Ph,this._viewportElement,this.screenElement)))}),this._charSizeService.measure(),this.refresh(0,this.rows-1),this._initGlobal(),this.bindMouse()}_createRenderer(){return this._instantiationService.createInstance(s0,this,this._document,this.element,this.screenElement,this._viewportElement,this._helperContainer,this.linkifier)}bindMouse(){let e=this,t=this.element;function s(l){var h,m,g,b,v;let c=e._mouseService.getMouseReportCoords(l,e.screenElement);if(!c)return!1;let d,f;switch(l.overrideType||l.type){case"mousemove":f=32,l.buttons===void 0?(d=3,l.button!==void 0&&(d=l.button<3?l.button:3)):d=l.buttons&1?0:l.buttons&4?1:l.buttons&2?2:3;break;case"mouseup":f=0,d=l.button<3?l.button:3;break;case"mousedown":f=1,d=l.button<3?l.button:3;break;case"wheel":if(e._customWheelEventHandler&&e._customWheelEventHandler(l)===!1)return!1;let y=l.deltaY;if(y===0||e.coreMouseService.consumeWheelEvent(l,(b=(g=(m=(h=e._renderService)==null?void 0:h.dimensions)==null?void 0:m.device)==null?void 0:g.cell)==null?void 0:b.height,(v=e._coreBrowserService)==null?void 0:v.dpr)===0)return!1;f=y<0?0:1,d=4;break;default:return!1}return f===void 0||d===void 0||d>4?!1:e.coreMouseService.triggerMouseEvent({col:c.col,row:c.row,x:c.x,y:c.y,button:d,action:f,ctrl:l.ctrlKey,alt:l.altKey,shift:l.shiftKey})}let n={mouseup:null,wheel:null,mousedrag:null,mousemove:null},a={mouseup:l=>(s(l),l.buttons||(this._document.removeEventListener("mouseup",n.mouseup),n.mousedrag&&this._document.removeEventListener("mousemove",n.mousedrag)),this.cancel(l)),wheel:l=>(s(l),this.cancel(l,!0)),mousedrag:l=>{l.buttons&&s(l)},mousemove:l=>{l.buttons||s(l)}};this._register(this.coreMouseService.onProtocolChange(l=>{l?(this.optionsService.rawOptions.logLevel==="debug"&&this._logService.debug("Binding to mouse events:",this.coreMouseService.explainEvents(l)),this.element.classList.add("enable-mouse-events"),this._selectionService.disable()):(this._logService.debug("Unbinding from mouse events."),this.element.classList.remove("enable-mouse-events"),this._selectionService.enable()),l&8?n.mousemove||(t.addEventListener("mousemove",a.mousemove),n.mousemove=a.mousemove):(t.removeEventListener("mousemove",n.mousemove),n.mousemove=null),l&16?n.wheel||(t.addEventListener("wheel",a.wheel,{passive:!1}),n.wheel=a.wheel):(t.removeEventListener("wheel",n.wheel),n.wheel=null),l&2?n.mouseup||(n.mouseup=a.mouseup):(this._document.removeEventListener("mouseup",n.mouseup),n.mouseup=null),l&4?n.mousedrag||(n.mousedrag=a.mousedrag):(this._document.removeEventListener("mousemove",n.mousedrag),n.mousedrag=null)})),this.coreMouseService.activeProtocol=this.coreMouseService.activeProtocol,this._register(Ge(t,"mousedown",l=>{if(l.preventDefault(),this.focus(),!(!this.coreMouseService.areMouseEventsActive||this._selectionService.shouldForceSelection(l)))return s(l),n.mouseup&&this._document.addEventListener("mouseup",n.mouseup),n.mousedrag&&this._document.addEventListener("mousemove",n.mousedrag),this.cancel(l)})),this._register(Ge(t,"wheel",l=>{var c,d,f,h,m;if(!n.wheel){if(this._customWheelEventHandler&&this._customWheelEventHandler(l)===!1)return!1;if(!this.buffer.hasScrollback){if(l.deltaY===0)return!1;if(e.coreMouseService.consumeWheelEvent(l,(h=(f=(d=(c=e._renderService)==null?void 0:c.dimensions)==null?void 0:d.device)==null?void 0:f.cell)==null?void 0:h.height,(m=e._coreBrowserService)==null?void 0:m.dpr)===0)return this.cancel(l,!0);let g=xe.ESC+(this.coreService.decPrivateModes.applicationCursorKeys?"O":"[")+(l.deltaY<0?"A":"B");return this.coreService.triggerDataEvent(g,!0),this.cancel(l,!0)}}},{passive:!1}))}refresh(e,t){var s;(s=this._renderService)==null||s.refreshRows(e,t)}updateCursorStyle(e){var t;(t=this._selectionService)!=null&&t.shouldColumnSelect(e)?this.element.classList.add("column-select"):this.element.classList.remove("column-select")}_showCursor(){this.coreService.isCursorInitialized||(this.coreService.isCursorInitialized=!0,this.refresh(this.buffer.y,this.buffer.y))}scrollLines(e,t){this._viewport?this._viewport.scrollLines(e):super.scrollLines(e,t),this.refresh(0,this.rows-1)}scrollPages(e){this.scrollLines(e*(this.rows-1))}scrollToTop(){this.scrollLines(-this._bufferService.buffer.ydisp)}scrollToBottom(e){e&&this._viewport?this._viewport.scrollToLine(this.buffer.ybase,!0):this.scrollLines(this._bufferService.buffer.ybase-this._bufferService.buffer.ydisp)}scrollToLine(e){let t=e-this._bufferService.buffer.ydisp;t!==0&&this.scrollLines(t)}paste(e){zC(e,this.textarea,this.coreService,this.optionsService)}attachCustomKeyEventHandler(e){this._customKeyEventHandler=e}attachCustomWheelEventHandler(e){this._customWheelEventHandler=e}registerLinkProvider(e){return this._linkProviderService.registerLinkProvider(e)}registerCharacterJoiner(e){if(!this._characterJoinerService)throw new Error("Terminal must be opened first");let t=this._characterJoinerService.register(e);return this.refresh(0,this.rows-1),t}deregisterCharacterJoiner(e){if(!this._characterJoinerService)throw new Error("Terminal must be opened first");this._characterJoinerService.deregister(e)&&this.refresh(0,this.rows-1)}get markers(){return this.buffer.markers}registerMarker(e){return this.buffer.addMarker(this.buffer.ybase+this.buffer.y+e)}registerDecoration(e){return this._decorationService.registerDecoration(e)}hasSelection(){return this._selectionService?this._selectionService.hasSelection:!1}select(e,t,s){this._selectionService.setSelection(e,t,s)}getSelection(){return this._selectionService?this._selectionService.selectionText:""}getSelectionPosition(){if(!(!this._selectionService||!this._selectionService.hasSelection))return{start:{x:this._selectionService.selectionStart[0],y:this._selectionService.selectionStart[1]},end:{x:this._selectionService.selectionEnd[0],y:this._selectionService.selectionEnd[1]}}}clearSelection(){var e;(e=this._selectionService)==null||e.clearSelection()}selectAll(){var e;(e=this._selectionService)==null||e.selectAll()}selectLines(e,t){var s;(s=this._selectionService)==null||s.selectLines(e,t)}_keyDown(e){if(this._keyDownHandled=!1,this._keyDownSeen=!0,this._customKeyEventHandler&&this._customKeyEventHandler(e)===!1)return!1;let t=this.browser.isMac&&this.options.macOptionIsMeta&&e.altKey;if(!t&&!this._compositionHelper.keydown(e))return this.options.scrollOnUserInput&&this.buffer.ybase!==this.buffer.ydisp&&this.scrollToBottom(!0),!1;!t&&(e.key==="Dead"||e.key==="AltGraph")&&(this._unprocessedDeadKey=!0);let s=AF(e,this.coreService.decPrivateModes.applicationCursorKeys,this.browser.isMac,this.options.macOptionIsMeta);if(this.updateCursorStyle(e),s.type===3||s.type===2){let n=this.rows-1;return this.scrollLines(s.type===2?-n:n),this.cancel(e,!0)}if(s.type===1&&this.selectAll(),this._isThirdLevelShift(this.browser,e)||(s.cancel&&this.cancel(e,!0),!s.key)||e.key&&!e.ctrlKey&&!e.altKey&&!e.metaKey&&e.key.length===1&&e.key.charCodeAt(0)>=65&&e.key.charCodeAt(0)<=90)return!0;if(this._unprocessedDeadKey)return this._unprocessedDeadKey=!1,!0;if((s.key===xe.ETX||s.key===xe.CR)&&(this.textarea.value=""),this._onKey.fire({key:s.key,domEvent:e}),this._showCursor(),this.coreService.triggerDataEvent(s.key,!0),!this.optionsService.rawOptions.screenReaderMode||e.altKey||e.ctrlKey)return this.cancel(e,!0);this._keyDownHandled=!0}_isThirdLevelShift(e,t){let s=e.isMac&&!this.options.macOptionIsMeta&&t.altKey&&!t.ctrlKey&&!t.metaKey||e.isWindows&&t.altKey&&t.ctrlKey&&!t.metaKey||e.isWindows&&t.getModifierState("AltGraph");return t.type==="keypress"?s:s&&(!t.keyCode||t.keyCode>47)}_keyUp(e){this._keyDownSeen=!1,!(this._customKeyEventHandler&&this._customKeyEventHandler(e)===!1)&&($F(e)||this.focus(),this.updateCursorStyle(e),this._keyPressHandled=!1)}_keyPress(e){let t;if(this._keyPressHandled=!1,this._keyDownHandled||this._customKeyEventHandler&&this._customKeyEventHandler(e)===!1)return!1;if(this.cancel(e),e.charCode)t=e.charCode;else if(e.which===null||e.which===void 0)t=e.keyCode;else if(e.which!==0&&e.charCode!==0)t=e.which;else return!1;return!t||(e.altKey||e.ctrlKey||e.metaKey)&&!this._isThirdLevelShift(this.browser,e)?!1:(t=String.fromCharCode(t),this._onKey.fire({key:t,domEvent:e}),this._showCursor(),this.coreService.triggerDataEvent(t,!0),this._keyPressHandled=!0,this._unprocessedDeadKey=!1,!0)}_inputEvent(e){if(e.data&&e.inputType==="insertText"&&(!e.composed||!this._keyDownSeen)&&!this.optionsService.rawOptions.screenReaderMode){if(this._keyPressHandled)return!1;this._unprocessedDeadKey=!1;let t=e.data;return this.coreService.triggerDataEvent(t,!0),this.cancel(e),!0}return!1}resize(e,t){if(e===this.cols&&t===this.rows){this._charSizeService&&!this._charSizeService.hasValidSize&&this._charSizeService.measure();return}super.resize(e,t)}_afterResize(e,t){var s;(s=this._charSizeService)==null||s.measure()}clear(){if(!(this.buffer.ybase===0&&this.buffer.y===0)){this.buffer.clearAllMarkers(),this.buffer.lines.set(0,this.buffer.lines.get(this.buffer.ybase+this.buffer.y)),this.buffer.lines.length=1,this.buffer.ydisp=0,this.buffer.ybase=0,this.buffer.y=0;for(let e=1;e<this.rows;e++)this.buffer.lines.push(this.buffer.getBlankLine(fs));this._onScroll.fire({position:this.buffer.ydisp}),this.refresh(0,this.rows-1)}}reset(){var t;this.options.rows=this.rows,this.options.cols=this.cols;let e=this._customKeyEventHandler;this._setup(),super.reset(),(t=this._selectionService)==null||t.reset(),this._decorationService.reset(),this._customKeyEventHandler=e,this.refresh(0,this.rows-1)}clearTextureAtlas(){var e;(e=this._renderService)==null||e.clearTextureAtlas()}_reportFocus(){var e;(e=this.element)!=null&&e.classList.contains("focus")?this.coreService.triggerDataEvent(xe.ESC+"[I"):this.coreService.triggerDataEvent(xe.ESC+"[O")}_reportWindowsOptions(e){if(this._renderService)switch(e){case 0:let t=this._renderService.dimensions.css.canvas.width.toFixed(0),s=this._renderService.dimensions.css.canvas.height.toFixed(0);this.coreService.triggerDataEvent(`${xe.ESC}[4;${s};${t}t`);break;case 1:let n=this._renderService.dimensions.css.cell.width.toFixed(0),a=this._renderService.dimensions.css.cell.height.toFixed(0);this.coreService.triggerDataEvent(`${xe.ESC}[6;${a};${n}t`);break}}cancel(e,t){if(!(!this.options.cancelEvents&&!t))return e.preventDefault(),e.stopPropagation(),!1}};function $F(e){return e.keyCode===16||e.keyCode===17||e.keyCode===18}var IF=class{constructor(){this._addons=[]}dispose(){for(let e=this._addons.length-1;e>=0;e--)this._addons[e].instance.dispose()}loadAddon(e,t){let s={instance:t,dispose:t.dispose,isDisposed:!1};this._addons.push(s),t.dispose=()=>this._wrappedAddonDispose(s),t.activate(e)}_wrappedAddonDispose(e){if(e.isDisposed)return;let t=-1;for(let s=0;s<this._addons.length;s++)if(this._addons[s]===e){t=s;break}if(t===-1)throw new Error("Could not dispose an addon that has not been loaded");e.isDisposed=!0,e.dispose.apply(e.instance),this._addons.splice(t,1)}},FF=class{constructor(e){this._line=e}get isWrapped(){return this._line.isWrapped}get length(){return this._line.length}getCell(e,t){if(!(e<0||e>=this._line.length))return t?(this._line.loadCell(e,t),t):this._line.loadCell(e,new Jn)}translateToString(e,t,s){return this._line.translateToString(e,t,s)}},iS=class{constructor(e,t){this._buffer=e,this.type=t}init(e){return this._buffer=e,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(e){let t=this._buffer.lines.get(e);if(t)return new FF(t)}getNullCell(){return new Jn}},HF=class extends nt{constructor(e){super(),this._core=e,this._onBufferChange=this._register(new Ce),this.onBufferChange=this._onBufferChange.event,this._normal=new iS(this._core.buffers.normal,"normal"),this._alternate=new iS(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)}},UF=class{constructor(e){this._core=e}registerCsiHandler(e,t){return this._core.registerCsiHandler(e,s=>t(s.toArray()))}addCsiHandler(e,t){return this.registerCsiHandler(e,t)}registerDcsHandler(e,t){return this._core.registerDcsHandler(e,(s,n)=>t(s,n.toArray()))}addDcsHandler(e,t){return this.registerDcsHandler(e,t)}registerEscHandler(e,t){return this._core.registerEscHandler(e,t)}addEscHandler(e,t){return this.registerEscHandler(e,t)}registerOscHandler(e,t){return this._core.registerOscHandler(e,t)}addOscHandler(e,t){return this.registerOscHandler(e,t)}},VF=class{constructor(e){this._core=e}register(e){this._core.unicodeService.register(e)}get versions(){return this._core.unicodeService.versions}get activeVersion(){return this._core.unicodeService.activeVersion}set activeVersion(e){this._core.unicodeService.activeVersion=e}},WF=["cols","rows"],mr=0,qF=class extends nt{constructor(e){super(),this._core=this._register(new PF(e)),this._addonManager=this._register(new IF),this._publicOptions={...this._core.options};let t=n=>this._core.options[n],s=(n,a)=>{this._checkReadonlyOptions(n),this._core.options[n]=a};for(let n in this._core.options){let a={get:t.bind(this,n),set:s.bind(this,n)};Object.defineProperty(this._publicOptions,n,a)}}_checkReadonlyOptions(e){if(WF.includes(e))throw new Error(`Option "${e}" 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 UF(this._core)),this._parser}get unicode(){return this._checkProposedApi(),new VF(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 HF(this._core))),this._buffer}get markers(){return this._checkProposedApi(),this._core.markers}get modes(){let e=this._core.coreService.decPrivateModes,t="none";switch(this._core.coreMouseService.activeProtocol){case"X10":t="x10";break;case"VT200":t="vt200";break;case"DRAG":t="drag";break;case"ANY":t="any";break}return{applicationCursorKeysMode:e.applicationCursorKeys,applicationKeypadMode:e.applicationKeypad,bracketedPasteMode:e.bracketedPasteMode,insertMode:this._core.coreService.modes.insertMode,mouseTrackingMode:t,originMode:e.origin,reverseWraparoundMode:e.reverseWraparound,sendFocusMode:e.sendFocus,synchronizedOutputMode:e.synchronizedOutput,wraparoundMode:e.wraparound}}get options(){return this._publicOptions}set options(e){for(let t in e)this._publicOptions[t]=e[t]}blur(){this._core.blur()}focus(){this._core.focus()}input(e,t=!0){this._core.input(e,t)}resize(e,t){this._verifyIntegers(e,t),this._core.resize(e,t)}open(e){this._core.open(e)}attachCustomKeyEventHandler(e){this._core.attachCustomKeyEventHandler(e)}attachCustomWheelEventHandler(e){this._core.attachCustomWheelEventHandler(e)}registerLinkProvider(e){return this._core.registerLinkProvider(e)}registerCharacterJoiner(e){return this._checkProposedApi(),this._core.registerCharacterJoiner(e)}deregisterCharacterJoiner(e){this._checkProposedApi(),this._core.deregisterCharacterJoiner(e)}registerMarker(e=0){return this._verifyIntegers(e),this._core.registerMarker(e)}registerDecoration(e){return this._checkProposedApi(),this._verifyPositiveIntegers(e.x??0,e.width??0,e.height??0),this._core.registerDecoration(e)}hasSelection(){return this._core.hasSelection()}select(e,t,s){this._verifyIntegers(e,t,s),this._core.select(e,t,s)}getSelection(){return this._core.getSelection()}getSelectionPosition(){return this._core.getSelectionPosition()}clearSelection(){this._core.clearSelection()}selectAll(){this._core.selectAll()}selectLines(e,t){this._verifyIntegers(e,t),this._core.selectLines(e,t)}dispose(){super.dispose()}scrollLines(e){this._verifyIntegers(e),this._core.scrollLines(e)}scrollPages(e){this._verifyIntegers(e),this._core.scrollPages(e)}scrollToTop(){this._core.scrollToTop()}scrollToBottom(){this._core.scrollToBottom()}scrollToLine(e){this._verifyIntegers(e),this._core.scrollToLine(e)}clear(){this._core.clear()}write(e,t){this._core.write(e,t)}writeln(e,t){this._core.write(e),this._core.write(`\r
|
|
258
|
+
`&&(this._liveRegionLineCount++,this._liveRegionLineCount===rS+1&&(this._liveRegion.textContent+=Lx.get())))}_clearLiveRegion(){this._liveRegion.textContent="",this._liveRegionLineCount=0}_handleKey(e){this._clearLiveRegion(),new RegExp("\\p{Control}","u").test(e)||this._charsToConsume.push(e)}_refreshRows(e,t){this._liveRegionDebouncer.refresh(e,t,this._terminal.rows)}_renderRows(e,t){let s=this._terminal.buffer,n=s.lines.length.toString();for(let a=e;a<=t;a++){let l=s.lines.get(s.ydisp+a),c=[],d=(l==null?void 0:l.translateToString(!0,void 0,void 0,c))||"",f=(s.ydisp+a+1).toString(),h=this._rowElements[a];h&&(d.length===0?(h.textContent=" ",this._rowColumns.set(h,[0,1])):(h.textContent=d,this._rowColumns.set(h,c)),h.setAttribute("aria-posinset",f),h.setAttribute("aria-setsize",n),this._alignRowWidth(h))}this._announceCharacters()}_announceCharacters(){this._charsToAnnounce.length!==0&&(this._liveRegion.textContent+=this._charsToAnnounce,this._charsToAnnounce="")}_handleBoundaryFocus(e,t){let s=e.target,n=this._rowElements[t===0?1:this._rowElements.length-2],a=s.getAttribute("aria-posinset"),l=t===0?"1":`${this._terminal.buffer.lines.length}`;if(a===l||e.relatedTarget!==n)return;let c,d;if(t===0?(c=s,d=this._rowElements.pop(),this._rowContainer.removeChild(d)):(c=this._rowElements.shift(),d=s,this._rowContainer.removeChild(c)),c.removeEventListener("focus",this._topBoundaryFocusListener),d.removeEventListener("focus",this._bottomBoundaryFocusListener),t===0){let f=this._createAccessibilityTreeNode();this._rowElements.unshift(f),this._rowContainer.insertAdjacentElement("afterbegin",f)}else{let f=this._createAccessibilityTreeNode();this._rowElements.push(f),this._rowContainer.appendChild(f)}this._rowElements[0].addEventListener("focus",this._topBoundaryFocusListener),this._rowElements[this._rowElements.length-1].addEventListener("focus",this._bottomBoundaryFocusListener),this._terminal.scrollLines(t===0?-1:1),this._rowElements[t===0?1:this._rowElements.length-2].focus(),e.preventDefault(),e.stopImmediatePropagation()}_handleSelectionChange(){var d;if(this._rowElements.length===0)return;let e=this._coreBrowserService.mainDocument.getSelection();if(!e)return;if(e.isCollapsed){this._rowContainer.contains(e.anchorNode)&&this._terminal.clearSelection();return}if(!e.anchorNode||!e.focusNode){console.error("anchorNode and/or focusNode are null");return}let t={node:e.anchorNode,offset:e.anchorOffset},s={node:e.focusNode,offset:e.focusOffset};if((t.node.compareDocumentPosition(s.node)&Node.DOCUMENT_POSITION_PRECEDING||t.node===s.node&&t.offset>s.offset)&&([t,s]=[s,t]),t.node.compareDocumentPosition(this._rowElements[0])&(Node.DOCUMENT_POSITION_CONTAINED_BY|Node.DOCUMENT_POSITION_FOLLOWING)&&(t={node:this._rowElements[0].childNodes[0],offset:0}),!this._rowContainer.contains(t.node))return;let n=this._rowElements.slice(-1)[0];if(s.node.compareDocumentPosition(n)&(Node.DOCUMENT_POSITION_CONTAINED_BY|Node.DOCUMENT_POSITION_PRECEDING)&&(s={node:n,offset:((d=n.textContent)==null?void 0:d.length)??0}),!this._rowContainer.contains(s.node))return;let a=({node:f,offset:h})=>{let m=f instanceof Text?f.parentNode:f,g=parseInt(m==null?void 0:m.getAttribute("aria-posinset"),10)-1;if(isNaN(g))return console.warn("row is invalid. Race condition?"),null;let b=this._rowColumns.get(m);if(!b)return console.warn("columns is null. Race condition?"),null;let v=h<b.length?b[h]:b.slice(-1)[0]+1;return v>=this._terminal.cols&&(++g,v=0),{row:g,column:v}},l=a(t),c=a(s);if(!(!l||!c)){if(l.row>c.row||l.row===c.row&&l.column>=c.column)throw new Error("invalid range");this._terminal.select(l.column,l.row,(c.row-l.row)*this._terminal.cols-l.column+c.column)}}_handleResize(e){this._rowElements[this._rowElements.length-1].removeEventListener("focus",this._bottomBoundaryFocusListener);for(let t=this._rowContainer.children.length;t<this._terminal.rows;t++)this._rowElements[t]=this._createAccessibilityTreeNode(),this._rowContainer.appendChild(this._rowElements[t]);for(;this._rowElements.length>e;)this._rowContainer.removeChild(this._rowElements.pop());this._rowElements[this._rowElements.length-1].addEventListener("focus",this._bottomBoundaryFocusListener),this._refreshRowsDimensions()}_createAccessibilityTreeNode(){let e=this._coreBrowserService.mainDocument.createElement("div");return e.setAttribute("role","listitem"),e.tabIndex=-1,this._refreshRowDimensions(e),e}_refreshRowsDimensions(){if(this._renderService.dimensions.css.cell.height){Object.assign(this._accessibilityContainer.style,{width:`${this._renderService.dimensions.css.canvas.width}px`,fontSize:`${this._terminal.options.fontSize}px`}),this._rowElements.length!==this._terminal.rows&&this._handleResize(this._terminal.rows);for(let e=0;e<this._terminal.rows;e++)this._refreshRowDimensions(this._rowElements[e]),this._alignRowWidth(this._rowElements[e])}}_refreshRowDimensions(e){e.style.height=`${this._renderService.dimensions.css.cell.height}px`}_alignRowWidth(e){var a,l;e.style.transform="";let t=e.getBoundingClientRect().width,s=(l=(a=this._rowColumns.get(e))==null?void 0:a.slice(-1))==null?void 0:l[0];if(!s)return;let n=s*this._renderService.dimensions.css.cell.width;e.style.transform=`scaleX(${n/t})`}};Hh=ts([Re(1,ov),Re(2,ai),Re(3,oi)],Hh);var m0=class extends nt{constructor(e,t,s,n,a){super(),this._element=e,this._mouseService=t,this._renderService=s,this._bufferService=n,this._linkProviderService=a,this._linkCacheDisposables=[],this._isMouseOut=!0,this._wasResized=!1,this._activeLine=-1,this._onShowLinkUnderline=this._register(new Ce),this.onShowLinkUnderline=this._onShowLinkUnderline.event,this._onHideLinkUnderline=this._register(new Ce),this.onHideLinkUnderline=this._onHideLinkUnderline.event,this._register(Ut(()=>{var l;Ra(this._linkCacheDisposables),this._linkCacheDisposables.length=0,this._lastMouseEvent=void 0,(l=this._activeProviderReplies)==null||l.clear()})),this._register(this._bufferService.onResize(()=>{this._clearCurrentLink(),this._wasResized=!0})),this._register(Ge(this._element,"mouseleave",()=>{this._isMouseOut=!0,this._clearCurrentLink()})),this._register(Ge(this._element,"mousemove",this._handleMouseMove.bind(this))),this._register(Ge(this._element,"mousedown",this._handleMouseDown.bind(this))),this._register(Ge(this._element,"mouseup",this._handleMouseUp.bind(this)))}get currentLink(){return this._currentLink}_handleMouseMove(e){this._lastMouseEvent=e;let t=this._positionFromMouseEvent(e,this._element,this._mouseService);if(!t)return;this._isMouseOut=!1;let s=e.composedPath();for(let n=0;n<s.length;n++){let a=s[n];if(a.classList.contains("xterm"))break;if(a.classList.contains("xterm-hover"))return}(!this._lastBufferCell||t.x!==this._lastBufferCell.x||t.y!==this._lastBufferCell.y)&&(this._handleHover(t),this._lastBufferCell=t)}_handleHover(e){if(this._activeLine!==e.y||this._wasResized){this._clearCurrentLink(),this._askForLink(e,!1),this._wasResized=!1;return}this._currentLink&&this._linkAtPosition(this._currentLink.link,e)||(this._clearCurrentLink(),this._askForLink(e,!0))}_askForLink(e,t){var n,a;(!this._activeProviderReplies||!t)&&((n=this._activeProviderReplies)==null||n.forEach(l=>{l==null||l.forEach(c=>{c.link.dispose&&c.link.dispose()})}),this._activeProviderReplies=new Map,this._activeLine=e.y);let s=!1;for(let[l,c]of this._linkProviderService.linkProviders.entries())t?(a=this._activeProviderReplies)!=null&&a.get(l)&&(s=this._checkLinkProviderResult(l,e,s)):c.provideLinks(e.y,d=>{var h,m;if(this._isMouseOut)return;let f=d==null?void 0:d.map(g=>({link:g}));(h=this._activeProviderReplies)==null||h.set(l,f),s=this._checkLinkProviderResult(l,e,s),((m=this._activeProviderReplies)==null?void 0:m.size)===this._linkProviderService.linkProviders.length&&this._removeIntersectingLinks(e.y,this._activeProviderReplies)})}_removeIntersectingLinks(e,t){let s=new Set;for(let n=0;n<t.size;n++){let a=t.get(n);if(a)for(let l=0;l<a.length;l++){let c=a[l],d=c.link.range.start.y<e?0:c.link.range.start.x,f=c.link.range.end.y>e?this._bufferService.cols:c.link.range.end.x;for(let h=d;h<=f;h++){if(s.has(h)){a.splice(l--,1);break}s.add(h)}}}}_checkLinkProviderResult(e,t,s){var l;if(!this._activeProviderReplies)return s;let n=this._activeProviderReplies.get(e),a=!1;for(let c=0;c<e;c++)(!this._activeProviderReplies.has(c)||this._activeProviderReplies.get(c))&&(a=!0);if(!a&&n){let c=n.find(d=>this._linkAtPosition(d.link,t));c&&(s=!0,this._handleNewLink(c))}if(this._activeProviderReplies.size===this._linkProviderService.linkProviders.length&&!s)for(let c=0;c<this._activeProviderReplies.size;c++){let d=(l=this._activeProviderReplies.get(c))==null?void 0:l.find(f=>this._linkAtPosition(f.link,t));if(d){s=!0,this._handleNewLink(d);break}}return s}_handleMouseDown(){this._mouseDownLink=this._currentLink}_handleMouseUp(e){if(!this._currentLink)return;let t=this._positionFromMouseEvent(e,this._element,this._mouseService);t&&this._mouseDownLink&&PF(this._mouseDownLink.link,this._currentLink.link)&&this._linkAtPosition(this._currentLink.link,t)&&this._currentLink.link.activate(e,this._currentLink.link.text)}_clearCurrentLink(e,t){!this._currentLink||!this._lastMouseEvent||(!e||!t||this._currentLink.link.range.start.y>=e&&this._currentLink.link.range.end.y<=t)&&(this._linkLeave(this._element,this._currentLink.link,this._lastMouseEvent),this._currentLink=void 0,Ra(this._linkCacheDisposables),this._linkCacheDisposables.length=0)}_handleNewLink(e){if(!this._lastMouseEvent)return;let t=this._positionFromMouseEvent(this._lastMouseEvent,this._element,this._mouseService);t&&this._linkAtPosition(e.link,t)&&(this._currentLink=e,this._currentLink.state={decorations:{underline:e.link.decorations===void 0?!0:e.link.decorations.underline,pointerCursor:e.link.decorations===void 0?!0:e.link.decorations.pointerCursor},isHovered:!0},this._linkHover(this._element,e.link,this._lastMouseEvent),e.link.decorations={},Object.defineProperties(e.link.decorations,{pointerCursor:{get:()=>{var s,n;return(n=(s=this._currentLink)==null?void 0:s.state)==null?void 0:n.decorations.pointerCursor},set:s=>{var n;(n=this._currentLink)!=null&&n.state&&this._currentLink.state.decorations.pointerCursor!==s&&(this._currentLink.state.decorations.pointerCursor=s,this._currentLink.state.isHovered&&this._element.classList.toggle("xterm-cursor-pointer",s))}},underline:{get:()=>{var s,n;return(n=(s=this._currentLink)==null?void 0:s.state)==null?void 0:n.decorations.underline},set:s=>{var n,a,l;(n=this._currentLink)!=null&&n.state&&((l=(a=this._currentLink)==null?void 0:a.state)==null?void 0:l.decorations.underline)!==s&&(this._currentLink.state.decorations.underline=s,this._currentLink.state.isHovered&&this._fireUnderlineEvent(e.link,s))}}}),this._linkCacheDisposables.push(this._renderService.onRenderedViewportChange(s=>{if(!this._currentLink)return;let n=s.start===0?0:s.start+1+this._bufferService.buffer.ydisp,a=this._bufferService.buffer.ydisp+1+s.end;if(this._currentLink.link.range.start.y>=n&&this._currentLink.link.range.end.y<=a&&(this._clearCurrentLink(n,a),this._lastMouseEvent)){let l=this._positionFromMouseEvent(this._lastMouseEvent,this._element,this._mouseService);l&&this._askForLink(l,!1)}})))}_linkHover(e,t,s){var n;(n=this._currentLink)!=null&&n.state&&(this._currentLink.state.isHovered=!0,this._currentLink.state.decorations.underline&&this._fireUnderlineEvent(t,!0),this._currentLink.state.decorations.pointerCursor&&e.classList.add("xterm-cursor-pointer")),t.hover&&t.hover(s,t.text)}_fireUnderlineEvent(e,t){let s=e.range,n=this._bufferService.buffer.ydisp,a=this._createLinkUnderlineEvent(s.start.x-1,s.start.y-n-1,s.end.x,s.end.y-n-1,void 0);(t?this._onShowLinkUnderline:this._onHideLinkUnderline).fire(a)}_linkLeave(e,t,s){var n;(n=this._currentLink)!=null&&n.state&&(this._currentLink.state.isHovered=!1,this._currentLink.state.decorations.underline&&this._fireUnderlineEvent(t,!1),this._currentLink.state.decorations.pointerCursor&&e.classList.remove("xterm-cursor-pointer")),t.leave&&t.leave(s,t.text)}_linkAtPosition(e,t){let s=e.range.start.y*this._bufferService.cols+e.range.start.x,n=e.range.end.y*this._bufferService.cols+e.range.end.x,a=t.y*this._bufferService.cols+t.x;return s<=a&&a<=n}_positionFromMouseEvent(e,t,s){let n=s.getCoords(e,t,this._bufferService.cols,this._bufferService.rows);if(n)return{x:n[0],y:n[1]+this._bufferService.buffer.ydisp}}_createLinkUnderlineEvent(e,t,s,n,a){return{x1:e,y1:t,x2:s,y2:n,cols:this._bufferService.cols,fg:a}}};m0=ts([Re(1,lv),Re(2,oi),Re(3,sn),Re(4,GC)],m0);function PF(e,t){return e.text===t.text&&e.range.start.x===t.range.start.x&&e.range.start.y===t.range.start.y&&e.range.end.x===t.range.end.x&&e.range.end.y===t.range.end.y}var $F=class extends TF{constructor(e={}){super(e),this._linkifier=this._register(new Yo),this.browser=hN,this._keyDownHandled=!1,this._keyDownSeen=!1,this._keyPressHandled=!1,this._unprocessedDeadKey=!1,this._accessibilityManager=this._register(new Yo),this._onCursorMove=this._register(new Ce),this.onCursorMove=this._onCursorMove.event,this._onKey=this._register(new Ce),this.onKey=this._onKey.event,this._onRender=this._register(new Ce),this.onRender=this._onRender.event,this._onSelectionChange=this._register(new Ce),this.onSelectionChange=this._onSelectionChange.event,this._onTitleChange=this._register(new Ce),this.onTitleChange=this._onTitleChange.event,this._onBell=this._register(new Ce),this.onBell=this._onBell.event,this._onFocus=this._register(new Ce),this._onBlur=this._register(new Ce),this._onA11yCharEmitter=this._register(new Ce),this._onA11yTabEmitter=this._register(new Ce),this._onWillOpen=this._register(new Ce),this._setup(),this._decorationService=this._instantiationService.createInstance(LF),this._instantiationService.setService(mu,this._decorationService),this._linkProviderService=this._instantiationService.createInstance(EI),this._instantiationService.setService(GC,this._linkProviderService),this._linkProviderService.registerLinkProvider(this._instantiationService.createInstance(Ox)),this._register(this._inputHandler.onRequestBell(()=>this._onBell.fire())),this._register(this._inputHandler.onRequestRefreshRows(t=>this.refresh((t==null?void 0:t.start)??0,(t==null?void 0:t.end)??this.rows-1))),this._register(this._inputHandler.onRequestSendFocus(()=>this._reportFocus())),this._register(this._inputHandler.onRequestReset(()=>this.reset())),this._register(this._inputHandler.onRequestWindowsOptionsReport(t=>this._reportWindowsOptions(t))),this._register(this._inputHandler.onColor(t=>this._handleColorEvent(t))),this._register(Is.forward(this._inputHandler.onCursorMove,this._onCursorMove)),this._register(Is.forward(this._inputHandler.onTitleChange,this._onTitleChange)),this._register(Is.forward(this._inputHandler.onA11yChar,this._onA11yCharEmitter)),this._register(Is.forward(this._inputHandler.onA11yTab,this._onA11yTabEmitter)),this._register(this._bufferService.onResize(t=>this._afterResize(t.cols,t.rows))),this._register(Ut(()=>{var t,s;this._customKeyEventHandler=void 0,(s=(t=this.element)==null?void 0:t.parentNode)==null||s.removeChild(this.element)}))}get linkifier(){return this._linkifier.value}get onFocus(){return this._onFocus.event}get onBlur(){return this._onBlur.event}get onA11yChar(){return this._onA11yCharEmitter.event}get onA11yTab(){return this._onA11yTabEmitter.event}get onWillOpen(){return this._onWillOpen.event}_handleColorEvent(e){if(this._themeService)for(let t of e){let s,n="";switch(t.index){case 256:s="foreground",n="10";break;case 257:s="background",n="11";break;case 258:s="cursor",n="12";break;default:s="ansi",n="4;"+t.index}switch(t.type){case 0:let a=$t.toColorRGB(s==="ansi"?this._themeService.colors.ansi[t.index]:this._themeService.colors[s]);this.coreService.triggerDataEvent(`${xe.ESC}]${n};${jF(a)}${uN.ST}`);break;case 1:if(s==="ansi")this._themeService.modifyColors(l=>l.ansi[t.index]=ps.toColor(...t.color));else{let l=s;this._themeService.modifyColors(c=>c[l]=ps.toColor(...t.color))}break;case 2:this._themeService.restoreColor(t.index);break}}}_setup(){super._setup(),this._customKeyEventHandler=void 0}get buffer(){return this.buffers.active}focus(){this.textarea&&this.textarea.focus({preventScroll:!0})}_handleScreenReaderModeOptionChange(e){e?!this._accessibilityManager.value&&this._renderService&&(this._accessibilityManager.value=this._instantiationService.createInstance(Hh,this)):this._accessibilityManager.clear()}_handleTextAreaFocus(e){this.coreService.decPrivateModes.sendFocus&&this.coreService.triggerDataEvent(xe.ESC+"[I"),this.element.classList.add("focus"),this._showCursor(),this._onFocus.fire()}blur(){var e;return(e=this.textarea)==null?void 0:e.blur()}_handleTextAreaBlur(){this.textarea.value="",this.refresh(this.buffer.y,this.buffer.y),this.coreService.decPrivateModes.sendFocus&&this.coreService.triggerDataEvent(xe.ESC+"[O"),this.element.classList.remove("focus"),this._onBlur.fire()}_syncTextArea(){if(!this.textarea||!this.buffer.isCursorInViewport||this._compositionHelper.isComposing||!this._renderService)return;let e=this.buffer.ybase+this.buffer.y,t=this.buffer.lines.get(e);if(!t)return;let s=Math.min(this.buffer.x,this.cols-1),n=this._renderService.dimensions.css.cell.height,a=t.getWidth(s),l=this._renderService.dimensions.css.cell.width*a,c=this.buffer.y*this._renderService.dimensions.css.cell.height,d=s*this._renderService.dimensions.css.cell.width;this.textarea.style.left=d+"px",this.textarea.style.top=c+"px",this.textarea.style.width=l+"px",this.textarea.style.height=n+"px",this.textarea.style.lineHeight=n+"px",this.textarea.style.zIndex="-5"}_initGlobal(){this._bindKeys(),this._register(Ge(this.element,"copy",t=>{this.hasSelection()&&U9(t,this._selectionService)}));let e=t=>V9(t,this.textarea,this.coreService,this.optionsService);this._register(Ge(this.textarea,"paste",e)),this._register(Ge(this.element,"paste",e)),fN?this._register(Ge(this.element,"mousedown",t=>{t.button===2&&p2(t,this.textarea,this.screenElement,this._selectionService,this.options.rightClickSelectsWord)})):this._register(Ge(this.element,"contextmenu",t=>{p2(t,this.textarea,this.screenElement,this._selectionService,this.options.rightClickSelectsWord)})),gv&&this._register(Ge(this.element,"auxclick",t=>{t.button===1&&PC(t,this.textarea,this.screenElement)}))}_bindKeys(){this._register(Ge(this.textarea,"keyup",e=>this._keyUp(e),!0)),this._register(Ge(this.textarea,"keydown",e=>this._keyDown(e),!0)),this._register(Ge(this.textarea,"keypress",e=>this._keyPress(e),!0)),this._register(Ge(this.textarea,"compositionstart",()=>this._compositionHelper.compositionstart())),this._register(Ge(this.textarea,"compositionupdate",e=>this._compositionHelper.compositionupdate(e))),this._register(Ge(this.textarea,"compositionend",()=>this._compositionHelper.compositionend())),this._register(Ge(this.textarea,"input",e=>this._inputEvent(e),!0)),this._register(this.onRender(()=>this._compositionHelper.updateCompositionElements()))}open(e){var a;if(!e)throw new Error("Terminal requires a parent element.");if(e.isConnected||this._logService.debug("Terminal.open was called on an element that was not attached to the DOM"),((a=this.element)==null?void 0:a.ownerDocument.defaultView)&&this._coreBrowserService){this.element.ownerDocument.defaultView!==this._coreBrowserService.window&&(this._coreBrowserService.window=this.element.ownerDocument.defaultView);return}this._document=e.ownerDocument,this.options.documentOverride&&this.options.documentOverride instanceof Document&&(this._document=this.optionsService.rawOptions.documentOverride),this.element=this._document.createElement("div"),this.element.dir="ltr",this.element.classList.add("terminal"),this.element.classList.add("xterm"),e.appendChild(this.element);let t=this._document.createDocumentFragment();this._viewportElement=this._document.createElement("div"),this._viewportElement.classList.add("xterm-viewport"),t.appendChild(this._viewportElement),this.screenElement=this._document.createElement("div"),this.screenElement.classList.add("xterm-screen"),this._register(Ge(this.screenElement,"mousemove",l=>this.updateCursorStyle(l))),this._helperContainer=this._document.createElement("div"),this._helperContainer.classList.add("xterm-helpers"),this.screenElement.appendChild(this._helperContainer),t.appendChild(this.screenElement);let s=this.textarea=this._document.createElement("textarea");this.textarea.classList.add("xterm-helper-textarea"),this.textarea.setAttribute("aria-label",Dx.get()),gN||this.textarea.setAttribute("aria-multiline","false"),this.textarea.setAttribute("autocorrect","off"),this.textarea.setAttribute("autocapitalize","off"),this.textarea.setAttribute("spellcheck","false"),this.textarea.tabIndex=0,this._register(this.optionsService.onSpecificOptionChange("disableStdin",()=>s.readOnly=this.optionsService.rawOptions.disableStdin)),this.textarea.readOnly=this.optionsService.rawOptions.disableStdin,this._coreBrowserService=this._register(this._instantiationService.createInstance(CI,this.textarea,e.ownerDocument.defaultView??window,this._document??typeof window<"u"?window.document:null)),this._instantiationService.setService(ai,this._coreBrowserService),this._register(Ge(this.textarea,"focus",l=>this._handleTextAreaFocus(l))),this._register(Ge(this.textarea,"blur",()=>this._handleTextAreaBlur())),this._helperContainer.appendChild(this.textarea),this._charSizeService=this._instantiationService.createInstance(n0,this._document,this._helperContainer),this._instantiationService.setService(sf,this._charSizeService),this._themeService=this._instantiationService.createInstance(o0),this._instantiationService.setService(tl,this._themeService),this._characterJoinerService=this._instantiationService.createInstance($h),this._instantiationService.setService(qC,this._characterJoinerService),this._renderService=this._register(this._instantiationService.createInstance(i0,this.rows,this.screenElement)),this._instantiationService.setService(oi,this._renderService),this._register(this._renderService.onRenderedViewportChange(l=>this._onRender.fire(l))),this.onResize(l=>this._renderService.resize(l.cols,l.rows)),this._compositionView=this._document.createElement("div"),this._compositionView.classList.add("composition-view"),this._compositionHelper=this._instantiationService.createInstance(e0,this.textarea,this._compositionView),this._helperContainer.appendChild(this._compositionView),this._mouseService=this._instantiationService.createInstance(r0),this._instantiationService.setService(lv,this._mouseService);let n=this._linkifier.value=this._register(this._instantiationService.createInstance(m0,this.screenElement));this.element.appendChild(t);try{this._onWillOpen.fire(this.element)}catch{}this._renderService.hasRenderer()||this._renderService.setRenderer(this._createRenderer()),this._register(this.onCursorMove(()=>{this._renderService.handleCursorMove(),this._syncTextArea()})),this._register(this.onResize(()=>this._renderService.handleResize(this.cols,this.rows))),this._register(this.onBlur(()=>this._renderService.handleBlur())),this._register(this.onFocus(()=>this._renderService.handleFocus())),this._viewport=this._register(this._instantiationService.createInstance(Qx,this.element,this.screenElement)),this._register(this._viewport.onRequestScrollLines(l=>{super.scrollLines(l,!1),this.refresh(0,this.rows-1)})),this._selectionService=this._register(this._instantiationService.createInstance(a0,this.element,this.screenElement,n)),this._instantiationService.setService(Q9,this._selectionService),this._register(this._selectionService.onRequestScrollLines(l=>this.scrollLines(l.amount,l.suppressScrollEvent))),this._register(this._selectionService.onSelectionChange(()=>this._onSelectionChange.fire())),this._register(this._selectionService.onRequestRedraw(l=>this._renderService.handleSelectionChanged(l.start,l.end,l.columnSelectMode))),this._register(this._selectionService.onLinuxMouseSelection(l=>{this.textarea.value=l,this.textarea.focus(),this.textarea.select()})),this._register(Is.any(this._onScroll.event,this._inputHandler.onScroll)(()=>{var l;this._selectionService.refresh(),(l=this._viewport)==null||l.queueSync()})),this._register(this._instantiationService.createInstance(Zx,this.screenElement)),this._register(Ge(this.element,"mousedown",l=>this._selectionService.handleMouseDown(l))),this.coreMouseService.areMouseEventsActive?(this._selectionService.disable(),this.element.classList.add("enable-mouse-events")):this._selectionService.enable(),this.options.screenReaderMode&&(this._accessibilityManager.value=this._instantiationService.createInstance(Hh,this)),this._register(this.optionsService.onSpecificOptionChange("screenReaderMode",l=>this._handleScreenReaderModeOptionChange(l))),this.options.overviewRuler.width&&(this._overviewRulerRenderer=this._register(this._instantiationService.createInstance(Ph,this._viewportElement,this.screenElement))),this.optionsService.onSpecificOptionChange("overviewRuler",l=>{!this._overviewRulerRenderer&&l&&this._viewportElement&&this.screenElement&&(this._overviewRulerRenderer=this._register(this._instantiationService.createInstance(Ph,this._viewportElement,this.screenElement)))}),this._charSizeService.measure(),this.refresh(0,this.rows-1),this._initGlobal(),this.bindMouse()}_createRenderer(){return this._instantiationService.createInstance(s0,this,this._document,this.element,this.screenElement,this._viewportElement,this._helperContainer,this.linkifier)}bindMouse(){let e=this,t=this.element;function s(l){var h,m,g,b,v;let c=e._mouseService.getMouseReportCoords(l,e.screenElement);if(!c)return!1;let d,f;switch(l.overrideType||l.type){case"mousemove":f=32,l.buttons===void 0?(d=3,l.button!==void 0&&(d=l.button<3?l.button:3)):d=l.buttons&1?0:l.buttons&4?1:l.buttons&2?2:3;break;case"mouseup":f=0,d=l.button<3?l.button:3;break;case"mousedown":f=1,d=l.button<3?l.button:3;break;case"wheel":if(e._customWheelEventHandler&&e._customWheelEventHandler(l)===!1)return!1;let y=l.deltaY;if(y===0||e.coreMouseService.consumeWheelEvent(l,(b=(g=(m=(h=e._renderService)==null?void 0:h.dimensions)==null?void 0:m.device)==null?void 0:g.cell)==null?void 0:b.height,(v=e._coreBrowserService)==null?void 0:v.dpr)===0)return!1;f=y<0?0:1,d=4;break;default:return!1}return f===void 0||d===void 0||d>4?!1:e.coreMouseService.triggerMouseEvent({col:c.col,row:c.row,x:c.x,y:c.y,button:d,action:f,ctrl:l.ctrlKey,alt:l.altKey,shift:l.shiftKey})}let n={mouseup:null,wheel:null,mousedrag:null,mousemove:null},a={mouseup:l=>(s(l),l.buttons||(this._document.removeEventListener("mouseup",n.mouseup),n.mousedrag&&this._document.removeEventListener("mousemove",n.mousedrag)),this.cancel(l)),wheel:l=>(s(l),this.cancel(l,!0)),mousedrag:l=>{l.buttons&&s(l)},mousemove:l=>{l.buttons||s(l)}};this._register(this.coreMouseService.onProtocolChange(l=>{l?(this.optionsService.rawOptions.logLevel==="debug"&&this._logService.debug("Binding to mouse events:",this.coreMouseService.explainEvents(l)),this.element.classList.add("enable-mouse-events"),this._selectionService.disable()):(this._logService.debug("Unbinding from mouse events."),this.element.classList.remove("enable-mouse-events"),this._selectionService.enable()),l&8?n.mousemove||(t.addEventListener("mousemove",a.mousemove),n.mousemove=a.mousemove):(t.removeEventListener("mousemove",n.mousemove),n.mousemove=null),l&16?n.wheel||(t.addEventListener("wheel",a.wheel,{passive:!1}),n.wheel=a.wheel):(t.removeEventListener("wheel",n.wheel),n.wheel=null),l&2?n.mouseup||(n.mouseup=a.mouseup):(this._document.removeEventListener("mouseup",n.mouseup),n.mouseup=null),l&4?n.mousedrag||(n.mousedrag=a.mousedrag):(this._document.removeEventListener("mousemove",n.mousedrag),n.mousedrag=null)})),this.coreMouseService.activeProtocol=this.coreMouseService.activeProtocol,this._register(Ge(t,"mousedown",l=>{if(l.preventDefault(),this.focus(),!(!this.coreMouseService.areMouseEventsActive||this._selectionService.shouldForceSelection(l)))return s(l),n.mouseup&&this._document.addEventListener("mouseup",n.mouseup),n.mousedrag&&this._document.addEventListener("mousemove",n.mousedrag),this.cancel(l)})),this._register(Ge(t,"wheel",l=>{var c,d,f,h,m;if(!n.wheel){if(this._customWheelEventHandler&&this._customWheelEventHandler(l)===!1)return!1;if(!this.buffer.hasScrollback){if(l.deltaY===0)return!1;if(e.coreMouseService.consumeWheelEvent(l,(h=(f=(d=(c=e._renderService)==null?void 0:c.dimensions)==null?void 0:d.device)==null?void 0:f.cell)==null?void 0:h.height,(m=e._coreBrowserService)==null?void 0:m.dpr)===0)return this.cancel(l,!0);let g=xe.ESC+(this.coreService.decPrivateModes.applicationCursorKeys?"O":"[")+(l.deltaY<0?"A":"B");return this.coreService.triggerDataEvent(g,!0),this.cancel(l,!0)}}},{passive:!1}))}refresh(e,t){var s;(s=this._renderService)==null||s.refreshRows(e,t)}updateCursorStyle(e){var t;(t=this._selectionService)!=null&&t.shouldColumnSelect(e)?this.element.classList.add("column-select"):this.element.classList.remove("column-select")}_showCursor(){this.coreService.isCursorInitialized||(this.coreService.isCursorInitialized=!0,this.refresh(this.buffer.y,this.buffer.y))}scrollLines(e,t){this._viewport?this._viewport.scrollLines(e):super.scrollLines(e,t),this.refresh(0,this.rows-1)}scrollPages(e){this.scrollLines(e*(this.rows-1))}scrollToTop(){this.scrollLines(-this._bufferService.buffer.ydisp)}scrollToBottom(e){e&&this._viewport?this._viewport.scrollToLine(this.buffer.ybase,!0):this.scrollLines(this._bufferService.buffer.ybase-this._bufferService.buffer.ydisp)}scrollToLine(e){let t=e-this._bufferService.buffer.ydisp;t!==0&&this.scrollLines(t)}paste(e){zC(e,this.textarea,this.coreService,this.optionsService)}attachCustomKeyEventHandler(e){this._customKeyEventHandler=e}attachCustomWheelEventHandler(e){this._customWheelEventHandler=e}registerLinkProvider(e){return this._linkProviderService.registerLinkProvider(e)}registerCharacterJoiner(e){if(!this._characterJoinerService)throw new Error("Terminal must be opened first");let t=this._characterJoinerService.register(e);return this.refresh(0,this.rows-1),t}deregisterCharacterJoiner(e){if(!this._characterJoinerService)throw new Error("Terminal must be opened first");this._characterJoinerService.deregister(e)&&this.refresh(0,this.rows-1)}get markers(){return this.buffer.markers}registerMarker(e){return this.buffer.addMarker(this.buffer.ybase+this.buffer.y+e)}registerDecoration(e){return this._decorationService.registerDecoration(e)}hasSelection(){return this._selectionService?this._selectionService.hasSelection:!1}select(e,t,s){this._selectionService.setSelection(e,t,s)}getSelection(){return this._selectionService?this._selectionService.selectionText:""}getSelectionPosition(){if(!(!this._selectionService||!this._selectionService.hasSelection))return{start:{x:this._selectionService.selectionStart[0],y:this._selectionService.selectionStart[1]},end:{x:this._selectionService.selectionEnd[0],y:this._selectionService.selectionEnd[1]}}}clearSelection(){var e;(e=this._selectionService)==null||e.clearSelection()}selectAll(){var e;(e=this._selectionService)==null||e.selectAll()}selectLines(e,t){var s;(s=this._selectionService)==null||s.selectLines(e,t)}_keyDown(e){if(this._keyDownHandled=!1,this._keyDownSeen=!0,this._customKeyEventHandler&&this._customKeyEventHandler(e)===!1)return!1;let t=this.browser.isMac&&this.options.macOptionIsMeta&&e.altKey;if(!t&&!this._compositionHelper.keydown(e))return this.options.scrollOnUserInput&&this.buffer.ybase!==this.buffer.ydisp&&this.scrollToBottom(!0),!1;!t&&(e.key==="Dead"||e.key==="AltGraph")&&(this._unprocessedDeadKey=!0);let s=RF(e,this.coreService.decPrivateModes.applicationCursorKeys,this.browser.isMac,this.options.macOptionIsMeta);if(this.updateCursorStyle(e),s.type===3||s.type===2){let n=this.rows-1;return this.scrollLines(s.type===2?-n:n),this.cancel(e,!0)}if(s.type===1&&this.selectAll(),this._isThirdLevelShift(this.browser,e)||(s.cancel&&this.cancel(e,!0),!s.key)||e.key&&!e.ctrlKey&&!e.altKey&&!e.metaKey&&e.key.length===1&&e.key.charCodeAt(0)>=65&&e.key.charCodeAt(0)<=90)return!0;if(this._unprocessedDeadKey)return this._unprocessedDeadKey=!1,!0;if((s.key===xe.ETX||s.key===xe.CR)&&(this.textarea.value=""),this._onKey.fire({key:s.key,domEvent:e}),this._showCursor(),this.coreService.triggerDataEvent(s.key,!0),!this.optionsService.rawOptions.screenReaderMode||e.altKey||e.ctrlKey)return this.cancel(e,!0);this._keyDownHandled=!0}_isThirdLevelShift(e,t){let s=e.isMac&&!this.options.macOptionIsMeta&&t.altKey&&!t.ctrlKey&&!t.metaKey||e.isWindows&&t.altKey&&t.ctrlKey&&!t.metaKey||e.isWindows&&t.getModifierState("AltGraph");return t.type==="keypress"?s:s&&(!t.keyCode||t.keyCode>47)}_keyUp(e){this._keyDownSeen=!1,!(this._customKeyEventHandler&&this._customKeyEventHandler(e)===!1)&&(IF(e)||this.focus(),this.updateCursorStyle(e),this._keyPressHandled=!1)}_keyPress(e){let t;if(this._keyPressHandled=!1,this._keyDownHandled||this._customKeyEventHandler&&this._customKeyEventHandler(e)===!1)return!1;if(this.cancel(e),e.charCode)t=e.charCode;else if(e.which===null||e.which===void 0)t=e.keyCode;else if(e.which!==0&&e.charCode!==0)t=e.which;else return!1;return!t||(e.altKey||e.ctrlKey||e.metaKey)&&!this._isThirdLevelShift(this.browser,e)?!1:(t=String.fromCharCode(t),this._onKey.fire({key:t,domEvent:e}),this._showCursor(),this.coreService.triggerDataEvent(t,!0),this._keyPressHandled=!0,this._unprocessedDeadKey=!1,!0)}_inputEvent(e){if(e.data&&e.inputType==="insertText"&&(!e.composed||!this._keyDownSeen)&&!this.optionsService.rawOptions.screenReaderMode){if(this._keyPressHandled)return!1;this._unprocessedDeadKey=!1;let t=e.data;return this.coreService.triggerDataEvent(t,!0),this.cancel(e),!0}return!1}resize(e,t){if(e===this.cols&&t===this.rows){this._charSizeService&&!this._charSizeService.hasValidSize&&this._charSizeService.measure();return}super.resize(e,t)}_afterResize(e,t){var s;(s=this._charSizeService)==null||s.measure()}clear(){if(!(this.buffer.ybase===0&&this.buffer.y===0)){this.buffer.clearAllMarkers(),this.buffer.lines.set(0,this.buffer.lines.get(this.buffer.ybase+this.buffer.y)),this.buffer.lines.length=1,this.buffer.ydisp=0,this.buffer.ybase=0,this.buffer.y=0;for(let e=1;e<this.rows;e++)this.buffer.lines.push(this.buffer.getBlankLine(fs));this._onScroll.fire({position:this.buffer.ydisp}),this.refresh(0,this.rows-1)}}reset(){var t;this.options.rows=this.rows,this.options.cols=this.cols;let e=this._customKeyEventHandler;this._setup(),super.reset(),(t=this._selectionService)==null||t.reset(),this._decorationService.reset(),this._customKeyEventHandler=e,this.refresh(0,this.rows-1)}clearTextureAtlas(){var e;(e=this._renderService)==null||e.clearTextureAtlas()}_reportFocus(){var e;(e=this.element)!=null&&e.classList.contains("focus")?this.coreService.triggerDataEvent(xe.ESC+"[I"):this.coreService.triggerDataEvent(xe.ESC+"[O")}_reportWindowsOptions(e){if(this._renderService)switch(e){case 0:let t=this._renderService.dimensions.css.canvas.width.toFixed(0),s=this._renderService.dimensions.css.canvas.height.toFixed(0);this.coreService.triggerDataEvent(`${xe.ESC}[4;${s};${t}t`);break;case 1:let n=this._renderService.dimensions.css.cell.width.toFixed(0),a=this._renderService.dimensions.css.cell.height.toFixed(0);this.coreService.triggerDataEvent(`${xe.ESC}[6;${a};${n}t`);break}}cancel(e,t){if(!(!this.options.cancelEvents&&!t))return e.preventDefault(),e.stopPropagation(),!1}};function IF(e){return e.keyCode===16||e.keyCode===17||e.keyCode===18}var FF=class{constructor(){this._addons=[]}dispose(){for(let e=this._addons.length-1;e>=0;e--)this._addons[e].instance.dispose()}loadAddon(e,t){let s={instance:t,dispose:t.dispose,isDisposed:!1};this._addons.push(s),t.dispose=()=>this._wrappedAddonDispose(s),t.activate(e)}_wrappedAddonDispose(e){if(e.isDisposed)return;let t=-1;for(let s=0;s<this._addons.length;s++)if(this._addons[s]===e){t=s;break}if(t===-1)throw new Error("Could not dispose an addon that has not been loaded");e.isDisposed=!0,e.dispose.apply(e.instance),this._addons.splice(t,1)}},HF=class{constructor(e){this._line=e}get isWrapped(){return this._line.isWrapped}get length(){return this._line.length}getCell(e,t){if(!(e<0||e>=this._line.length))return t?(this._line.loadCell(e,t),t):this._line.loadCell(e,new Jn)}translateToString(e,t,s){return this._line.translateToString(e,t,s)}},iS=class{constructor(e,t){this._buffer=e,this.type=t}init(e){return this._buffer=e,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(e){let t=this._buffer.lines.get(e);if(t)return new HF(t)}getNullCell(){return new Jn}},UF=class extends nt{constructor(e){super(),this._core=e,this._onBufferChange=this._register(new Ce),this.onBufferChange=this._onBufferChange.event,this._normal=new iS(this._core.buffers.normal,"normal"),this._alternate=new iS(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)}},VF=class{constructor(e){this._core=e}registerCsiHandler(e,t){return this._core.registerCsiHandler(e,s=>t(s.toArray()))}addCsiHandler(e,t){return this.registerCsiHandler(e,t)}registerDcsHandler(e,t){return this._core.registerDcsHandler(e,(s,n)=>t(s,n.toArray()))}addDcsHandler(e,t){return this.registerDcsHandler(e,t)}registerEscHandler(e,t){return this._core.registerEscHandler(e,t)}addEscHandler(e,t){return this.registerEscHandler(e,t)}registerOscHandler(e,t){return this._core.registerOscHandler(e,t)}addOscHandler(e,t){return this.registerOscHandler(e,t)}},WF=class{constructor(e){this._core=e}register(e){this._core.unicodeService.register(e)}get versions(){return this._core.unicodeService.versions}get activeVersion(){return this._core.unicodeService.activeVersion}set activeVersion(e){this._core.unicodeService.activeVersion=e}},qF=["cols","rows"],mr=0,GF=class extends nt{constructor(e){super(),this._core=this._register(new $F(e)),this._addonManager=this._register(new FF),this._publicOptions={...this._core.options};let t=n=>this._core.options[n],s=(n,a)=>{this._checkReadonlyOptions(n),this._core.options[n]=a};for(let n in this._core.options){let a={get:t.bind(this,n),set:s.bind(this,n)};Object.defineProperty(this._publicOptions,n,a)}}_checkReadonlyOptions(e){if(qF.includes(e))throw new Error(`Option "${e}" 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 VF(this._core)),this._parser}get unicode(){return this._checkProposedApi(),new WF(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 UF(this._core))),this._buffer}get markers(){return this._checkProposedApi(),this._core.markers}get modes(){let e=this._core.coreService.decPrivateModes,t="none";switch(this._core.coreMouseService.activeProtocol){case"X10":t="x10";break;case"VT200":t="vt200";break;case"DRAG":t="drag";break;case"ANY":t="any";break}return{applicationCursorKeysMode:e.applicationCursorKeys,applicationKeypadMode:e.applicationKeypad,bracketedPasteMode:e.bracketedPasteMode,insertMode:this._core.coreService.modes.insertMode,mouseTrackingMode:t,originMode:e.origin,reverseWraparoundMode:e.reverseWraparound,sendFocusMode:e.sendFocus,synchronizedOutputMode:e.synchronizedOutput,wraparoundMode:e.wraparound}}get options(){return this._publicOptions}set options(e){for(let t in e)this._publicOptions[t]=e[t]}blur(){this._core.blur()}focus(){this._core.focus()}input(e,t=!0){this._core.input(e,t)}resize(e,t){this._verifyIntegers(e,t),this._core.resize(e,t)}open(e){this._core.open(e)}attachCustomKeyEventHandler(e){this._core.attachCustomKeyEventHandler(e)}attachCustomWheelEventHandler(e){this._core.attachCustomWheelEventHandler(e)}registerLinkProvider(e){return this._core.registerLinkProvider(e)}registerCharacterJoiner(e){return this._checkProposedApi(),this._core.registerCharacterJoiner(e)}deregisterCharacterJoiner(e){this._checkProposedApi(),this._core.deregisterCharacterJoiner(e)}registerMarker(e=0){return this._verifyIntegers(e),this._core.registerMarker(e)}registerDecoration(e){return this._checkProposedApi(),this._verifyPositiveIntegers(e.x??0,e.width??0,e.height??0),this._core.registerDecoration(e)}hasSelection(){return this._core.hasSelection()}select(e,t,s){this._verifyIntegers(e,t,s),this._core.select(e,t,s)}getSelection(){return this._core.getSelection()}getSelectionPosition(){return this._core.getSelectionPosition()}clearSelection(){this._core.clearSelection()}selectAll(){this._core.selectAll()}selectLines(e,t){this._verifyIntegers(e,t),this._core.selectLines(e,t)}dispose(){super.dispose()}scrollLines(e){this._verifyIntegers(e),this._core.scrollLines(e)}scrollPages(e){this._verifyIntegers(e),this._core.scrollPages(e)}scrollToTop(){this._core.scrollToTop()}scrollToBottom(){this._core.scrollToBottom()}scrollToLine(e){this._verifyIntegers(e),this._core.scrollToLine(e)}clear(){this._core.clear()}write(e,t){this._core.write(e,t)}writeln(e,t){this._core.write(e),this._core.write(`\r
|
|
259
259
|
`,t)}paste(e){this._core.paste(e)}refresh(e,t){this._verifyIntegers(e,t),this._core.refresh(e,t)}reset(){this._core.reset()}clearTextureAtlas(){this._core.clearTextureAtlas()}loadAddon(e){this._addonManager.loadAddon(this,e)}static get strings(){return{get promptLabel(){return Dx.get()},set promptLabel(e){Dx.set(e)},get tooMuchOutput(){return Lx.get()},set tooMuchOutput(e){Lx.set(e)}}}_verifyIntegers(...e){for(mr of e)if(mr===1/0||isNaN(mr)||mr%1!==0)throw new Error("This API only accepts integers")}_verifyPositiveIntegers(...e){for(mr of e)if(mr&&(mr===1/0||isNaN(mr)||mr%1!==0||mr<0))throw new Error("This API only accepts positive integers")}};/**
|
|
260
260
|
* Copyright (c) 2014-2024 The xterm.js authors. All rights reserved.
|
|
261
261
|
* @license MIT
|
|
@@ -267,18 +267,18 @@ WARNING: This link could potentially be dangerous`)){let s=window.open();if(s){t
|
|
|
267
267
|
* Fabrice Bellard's javascript vt100 for jslinux:
|
|
268
268
|
* http://bellard.org/jslinux/
|
|
269
269
|
* Copyright (c) 2011 Fabrice Bellard
|
|
270
|
-
*/var
|
|
270
|
+
*/var KF=2,YF=1,XF=class{activate(e){this._terminal=e}dispose(){}fit(){let e=this.proposeDimensions();if(!e||!this._terminal||isNaN(e.cols)||isNaN(e.rows))return;let t=this._terminal._core;(this._terminal.rows!==e.rows||this._terminal.cols!==e.cols)&&(t._renderService.clear(),this._terminal.resize(e.cols,e.rows))}proposeDimensions(){var g;if(!this._terminal||!this._terminal.element||!this._terminal.element.parentElement)return;let e=this._terminal._core._renderService.dimensions;if(e.css.cell.width===0||e.css.cell.height===0)return;let t=this._terminal.options.scrollback===0?0:((g=this._terminal.options.overviewRuler)==null?void 0:g.width)||14,s=window.getComputedStyle(this._terminal.element.parentElement),n=parseInt(s.getPropertyValue("height")),a=Math.max(0,parseInt(s.getPropertyValue("width"))),l=window.getComputedStyle(this._terminal.element),c={top:parseInt(l.getPropertyValue("padding-top")),bottom:parseInt(l.getPropertyValue("padding-bottom")),right:parseInt(l.getPropertyValue("padding-right")),left:parseInt(l.getPropertyValue("padding-left"))},d=c.top+c.bottom,f=c.right+c.left,h=n-d,m=a-f-t;return{cols:Math.max(KF,Math.floor(m/e.css.cell.width)),rows:Math.max(YF,Math.floor(h/e.css.cell.height))}}};let Ts=null,Lc=null,Bc=null,Ii=null;function JF(e,t,s,n,a){CN();const c=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/ws/terminal/${e}`;Lc=t,Bc=s,Ii=n??null,Ts=new WebSocket(c),Ts.binaryType="arraybuffer",Ts.onopen=()=>{a==null||a()},Ts.onmessage=d=>{if(d.data instanceof ArrayBuffer)Lc==null||Lc(new Uint8Array(d.data));else try{const f=JSON.parse(d.data);f.type==="exit"&&(Bc==null||Bc(f.exitCode))}catch{}},Ts.onerror=()=>{Ii==null||Ii("Terminal WebSocket connection error")},Ts.onclose=d=>{d.wasClean||Ii==null||Ii("Terminal connection lost")}}function aS(e){(Ts==null?void 0:Ts.readyState)===WebSocket.OPEN&&Ts.send(JSON.stringify({type:"input",data:e}))}function oS(e,t){(Ts==null?void 0:Ts.readyState)===WebSocket.OPEN&&Ts.send(JSON.stringify({type:"resize",cols:e,rows:t}))}function CN(){Ts==null||Ts.close(),Ts=null,Lc=null,Bc=null,Ii=null}function lS(e){return{background:e?"#141413":"#1e1e1e",foreground:"#d4d4d4",cursor:"#d4d4d4",selectionBackground:"rgba(255, 255, 255, 0.2)"}}function QF({cwd:e,onClose:t,embedded:s=!1,initialCommand:n}){const a=w.useRef(null),l=w.useRef(null),c=w.useRef(null),d=Y(h=>h.darkMode);w.useEffect(()=>{if(!a.current)return;let h=!1;const m=new GF({cursorBlink:!0,fontSize:13,fontFamily:"'SF Mono', 'Monaco', 'Menlo', 'Courier New', monospace",theme:lS(Y.getState().darkMode)}),g=new XF;m.loadAddon(g),m.open(a.current),l.current=m,c.current=g,se.spawnTerminal(e,m.cols,m.rows).then(({terminalId:S})=>{h||(Y.getState().setTerminalId(S),JF(S,j=>m.write(j),j=>{m.writeln(`\r
|
|
271
271
|
[Process exited with code ${j}]`)},j=>{m.writeln(`\r
|
|
272
272
|
[${j}]`)},()=>{g.fit(),oS(m.cols,m.rows),n&&setTimeout(()=>aS(n+`
|
|
273
273
|
`),300)}))}).catch(S=>{h||m.writeln(`\r
|
|
274
|
-
[Failed to start terminal: ${S.message}]`)});const b=m.onData(S=>aS(S)),v=a.current,y=new ResizeObserver(()=>{g.fit(),oS(m.cols,m.rows)});return y.observe(v),()=>{h=!0,y.disconnect(),b.dispose(),CN(),m.dispose(),l.current=null,c.current=null,se.killTerminal().catch(()=>{})}},[e,n]),w.useEffect(()=>{l.current&&(l.current.options.theme=lS(d))},[d]);const f=r.jsxs("div",{className:`flex flex-col rounded-xl shadow-2xl overflow-hidden border border-cc-border ${s?"h-full":"w-[90vw] max-w-4xl h-[70vh]"}`,style:{background:d?"#141413":"#1e1e1e"},onClick:h=>h.stopPropagation(),children:[r.jsxs("div",{className:"flex items-center justify-between px-4 py-2 border-b border-cc-border bg-cc-sidebar shrink-0",children:[r.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-4 h-4 text-cc-muted shrink-0",children:r.jsx("path",{d:"M2 3a1 1 0 011-1h10a1 1 0 011 1v10a1 1 0 01-1 1H3a1 1 0 01-1-1V3zm2 1.5l3 2.5-3 2.5V4.5zM8.5 10h3v1h-3v-1z"})}),r.jsx("span",{className:"text-xs text-cc-muted font-mono-code truncate",children:e})]}),t&&r.jsx("button",{onClick:t,className:"w-6 h-6 flex items-center justify-center rounded-md text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer shrink-0",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"w-3.5 h-3.5",children:r.jsx("path",{d:"M4 4l8 8M12 4l-8 8",strokeLinecap:"round"})})})]}),r.jsx("div",{ref:a,className:"flex-1 min-h-0 p-1"})]});return s?r.jsx("div",{className:"h-full",children:f}):r.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",children:f})}function QF(){const e=Y(n=>n.terminalCwd),[t,s]=w.useState(!1);return r.jsxs("div",{className:"h-full bg-cc-bg overflow-y-auto",children:[r.jsxs("div",{className:"max-w-5xl mx-auto px-4 sm:px-8 py-6 sm:py-10 h-full flex flex-col",children:[r.jsxs("div",{className:"flex items-start justify-between gap-3 mb-6 shrink-0",children:[r.jsxs("div",{children:[r.jsx("h1",{className:"text-xl font-semibold text-cc-fg",children:"Terminal"}),r.jsx("p",{className:"mt-1 text-sm text-cc-muted",children:"Run shell commands in a project folder without leaving Campfire."})]}),r.jsx("button",{type:"button",onClick:()=>s(!0),className:"px-3 py-2 rounded-lg text-sm font-medium bg-cc-primary hover:bg-cc-primary-hover text-white transition-colors cursor-pointer whitespace-nowrap",children:e?"Change Folder":"Choose Folder"})]}),r.jsx("div",{className:"flex-1 min-h-[420px]",children:e?r.jsx(JF,{cwd:e,embedded:!0}):r.jsx("div",{className:"h-full bg-cc-card border border-cc-border rounded-xl p-6 sm:p-8 flex items-center justify-center text-center",children:r.jsxs("div",{className:"max-w-md",children:[r.jsx("h2",{className:"text-lg font-semibold text-cc-fg mb-2",children:"No terminal started yet"}),r.jsx("p",{className:"text-sm text-cc-muted",children:"Choose a folder to start a terminal session. You can switch folders anytime."})]})})})]}),t&&r.jsx(iv,{initialPath:e||"",onSelect:n=>{Y.getState().openTerminal(n),window.location.hash="#/terminal",s(!1)},onClose:()=>s(!1)})]})}let ZF=0;function cS(){return`replay-${++ZF}`}function eH(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function uS(e,t){var s;if(e.type==="user_message")return{id:e.id||cS(),role:"user",content:e.content||"",timestamp:e.timestamp||0};if(e.type==="assistant"){const n=e.message;return n?{id:n.id||cS(),role:"assistant",content:eH(n.content||[]),contentBlocks:n.content,timestamp:e.timestamp||0,parentToolUseId:e.parent_tool_use_id,model:n.model,stopReason:n.stop_reason}:null}if(e.type==="result"){const n=e.data;if(n!=null&&n.is_error&&((s=n.errors)!=null&&s.length))return{id:`replay-error-${t}`,role:"system",content:`Error: ${n.errors.join(", ")}`,timestamp:0}}return null}function dS(e){const t=[];let s="",n=null;for(let a=0;a<e.length;a++){const l=e[a];if(l.type==="stream_event"){const d=l.event;if((d==null?void 0:d.type)==="message_start"){if(s&&n){const f=t.find(h=>h.id===n);f&&(f.content=s)}s="",n=null}else if((d==null?void 0:d.type)==="content_block_delta"){const f=d.delta;(f==null?void 0:f.type)==="text_delta"&&f.text&&(s+=f.text)}continue}if(l.type==="assistant"){const d=uS(l,a);d&&(!d.content&&s&&(d.content=s),n=d.id,t.push(d)),s="";continue}if(s&&n){const d=t.find(f=>f.id===n);d&&!d.content&&(d.content=s),s="",n=null}const c=uS(l,a);c&&t.push(c)}if(s&&n){const a=t.find(l=>l.id===n);a&&!a.content&&(a.content=s)}return t}const tH=[1,2,4,8];function hS({filename:e,sessionId:t}){const s=Y(O=>O.replaySpeed),n=Y(O=>O.replayState),a=Y(O=>O.replaySessionId),l=Y(O=>O.setReplaySpeed),c=Y(O=>O.setReplayState),d=Y(O=>O.setReplaySessionId),f=Y(O=>O.setMessages),h=w.useRef([]),m=w.useRef([]),g=w.useRef(0),b=w.useRef(null),[v,y]=w.useState(!0),[S,j]=w.useState(null),[k,E]=w.useState(!1),[N,B]=w.useState(null),[A,P]=w.useState(0),[K,X]=w.useState(0);w.useEffect(()=>{const O=`replay-${Math.random().toString(36).slice(2,10)}`;return d(O),f(O,[]),c("idle"),()=>{d(null),c("idle"),f(O,[])}},[d,f,c]),w.useEffect(()=>{let O=!1;async function W(){y(!0),j(null);try{if(e){const U=await se.getRecording(e);if(O)return;B(U.header);const D=dS(U.messages),$=U.timestamps,z=$.length>1?$.length/Math.max(D.length,1):1;m.current=D.map((T,ae)=>$[Math.min(Math.round(ae*z),$.length-1)]||0),h.current=D,P(D.length)}else if(t){const U=await se.getSessionHistory(t);if(O)return;U.state&&B({session_id:t,backend_type:U.state.backend_type||"unknown",started_at:U.state.started_at||Date.now(),cwd:U.state.cwd||""});const D=dS(U.messages);h.current=D,P(D.length)}}catch(U){O||j(U.message||"Failed to load replay data")}finally{O||y(!1)}}return W(),()=>{O=!0}},[e,t]),w.useEffect(()=>()=>{b.current&&clearTimeout(b.current)},[]);const Z=w.useCallback(O=>{const W=m.current;if(W.length>1&&O>0&&O<W.length){const U=W[O]-W[O-1];return Math.min(U,3e3)/s}return 300/s},[s]),I=w.useCallback(()=>{if(!a)return;const O=g.current;if(O>=h.current.length){c("ended");return}const W=h.current.slice(0,O+1);f(a,W),g.current=O+1,X(O+1),O+1<h.current.length?b.current=setTimeout(I,Z(O+1)):c("ended")},[a,f,c,Z]),H=w.useCallback(()=>{!a||h.current.length===0||(c("playing"),g.current>=h.current.length&&(g.current=0,X(0),f(a,[])),b.current=setTimeout(I,Z(g.current)))},[a,c,f,I,Z]),F=w.useCallback(()=>{c("paused"),b.current&&(clearTimeout(b.current),b.current=null)},[c]),G=w.useCallback(()=>{b.current&&(clearTimeout(b.current),b.current=null),c("idle"),g.current=0,X(0),a&&f(a,[])},[c,f,a]),q=w.useCallback(O=>{if(!a)return;b.current&&(clearTimeout(b.current),b.current=null);const W=Math.max(0,Math.min(O,h.current.length));g.current=W,X(W),f(a,h.current.slice(0,W)),W>=h.current.length?c("ended"):n==="playing"?b.current=setTimeout(I,Z(W)):c("paused")},[a,f,c,n,I,Z]);w.useEffect(()=>{n==="playing"&&b.current&&(clearTimeout(b.current),b.current=setTimeout(I,Z(g.current)))},[s]);const R=w.useCallback(()=>{var U;const O=e?`#/replay/${e}`:`#/replay/session/${t}`,W=`${window.location.origin}/${O}`;if((U=navigator.clipboard)!=null&&U.writeText)navigator.clipboard.writeText(W);else{const D=document.createElement("textarea");D.value=W,D.style.position="fixed",D.style.opacity="0",document.body.appendChild(D),D.select(),document.execCommand("copy"),document.body.removeChild(D)}E(!0),setTimeout(()=>E(!1),2e3)},[e,t]),M=w.useCallback(()=>{window.location.hash=""},[]);return v?r.jsx("div",{className:"flex items-center justify-center h-full text-cc-text-secondary",children:r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("svg",{className:"animate-spin h-5 w-5",viewBox:"0 0 24 24",fill:"none",children:[r.jsx("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4",className:"opacity-25"}),r.jsx("path",{d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z",fill:"currentColor",className:"opacity-75"})]}),"Loading replay..."]})}):S?r.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-4 text-cc-text-secondary",children:[r.jsxs("p",{className:"text-red-400",children:["Failed to load replay: ",S]}),r.jsx("button",{onClick:M,className:"px-4 py-2 bg-cc-border rounded hover:bg-cc-hover transition-colors",children:"Go Back"})]}):!v&&A===0?r.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-4 text-cc-muted",children:[r.jsx("p",{className:"text-sm",children:"This recording contains no playable messages."}),r.jsx("p",{className:"text-xs text-cc-muted/60",children:"It may be a reconnect or initialization-only recording."}),r.jsx("button",{onClick:M,className:"px-4 py-2 bg-cc-border rounded hover:bg-cc-hover transition-colors text-sm",children:"Go Back"})]}):r.jsxs("div",{className:"flex flex-col h-full bg-cc-bg",children:[r.jsxs("div",{className:"flex items-center justify-between px-4 py-2 border-b border-cc-border bg-cc-card",children:[r.jsxs("div",{className:"flex items-center gap-3 text-sm text-cc-muted",children:[r.jsxs("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M14.752 11.168l-3.197-2.132A1 1 0 0010 9.87v4.263a1 1 0 001.555.832l3.197-2.132a1 1 0 000-1.664z"}),r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})]}),r.jsx("span",{className:"font-medium text-cc-fg",children:"Session Replay"}),N&&r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"text-xs px-2 py-0.5 rounded bg-cc-hover text-cc-muted",children:N.backend_type}),r.jsxs("span",{className:"text-xs",children:[N.session_id.slice(0,8),"..."]})]})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("button",{onClick:R,className:`p-1.5 rounded hover:bg-cc-hover transition-colors ${k?"text-cc-success":"text-cc-muted"}`,title:k?"Copied!":"Copy replay link",children:k?r.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}):r.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8.684 13.342C8.886 12.938 9 12.482 9 12c0-.482-.114-.938-.316-1.342m0 2.684a3 3 0 110-2.684m0 2.684l6.632 3.316m-6.632-6l6.632-3.316m0 0a3 3 0 105.367-2.684 3 3 0 00-5.367 2.684zm0 9.316a3 3 0 105.368 2.684 3 3 0 00-5.368-2.684z"})})}),r.jsx("button",{onClick:M,className:"p-1.5 rounded hover:bg-cc-hover transition-colors text-cc-muted",title:"Close replay",children:r.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),r.jsx("div",{className:"border-b border-cc-border bg-cc-card px-4 py-2",children:r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("button",{onClick:n==="playing"?F:H,className:"w-8 h-8 flex items-center justify-center rounded-lg bg-cc-primary text-white hover:bg-cc-primary-hover transition-colors cursor-pointer",title:n==="playing"?"Pause":"Play",children:n==="playing"?r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:r.jsx("path",{d:"M5.5 3.5A1.5 1.5 0 017 5v6a1.5 1.5 0 01-3 0V5a1.5 1.5 0 011.5-1.5zm5 0A1.5 1.5 0 0112 5v6a1.5 1.5 0 01-3 0V5a1.5 1.5 0 011.5-1.5z"})}):r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:r.jsx("path",{d:"M4.5 3.5A.5.5 0 015.22 3l7 4.5a.5.5 0 010 .86l-7 4.5A.5.5 0 014.5 12.5v-9z"})})}),r.jsx("button",{onClick:G,className:"w-8 h-8 flex items-center justify-center rounded-lg text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",title:"Reset",children:r.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})})}),r.jsx("div",{className:"flex-1 h-1.5 bg-cc-hover rounded-full overflow-hidden cursor-pointer",onClick:O=>{const W=O.currentTarget.getBoundingClientRect(),U=(O.clientX-W.left)/W.width;q(Math.round(U*A))},children:r.jsx("div",{className:"h-full bg-cc-primary rounded-full transition-all",style:{width:`${A>0?K/A*100:0}%`}})}),r.jsxs("span",{className:"text-[10px] text-cc-muted tabular-nums",children:[K,"/",A]}),r.jsx("div",{className:"flex items-center gap-1",children:tH.map(O=>r.jsxs("button",{onClick:()=>l(O),className:`px-2 py-1 text-[10px] font-medium rounded transition-colors cursor-pointer ${s===O?"bg-cc-primary text-white":"bg-cc-hover text-cc-muted hover:text-cc-fg"}`,children:[O,"x"]},O))}),r.jsx("span",{className:`text-[10px] px-2 py-0.5 rounded font-medium ${n==="playing"?"bg-green-500/20 text-green-400":n==="paused"?"bg-yellow-500/20 text-yellow-400":"bg-cc-hover text-cc-muted"}`,children:n==="playing"?"Playing":n==="paused"?"Paused":n==="ended"?"Ended":"Ready"})]})}),r.jsx("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden",children:a&&r.jsx(ev,{sessionId:a})})]})}function sH({embedded:e=!1,prefillSessionId:t,prefillName:s}){const[n,a]=w.useState([]),[l,c]=w.useState(!0),[d,f]=w.useState(""),[h,m]=w.useState(""),[g,b]=w.useState(!1),[v,y]=w.useState(""),[S,j]=w.useState("votes"),[k,E]=w.useState("desc"),[N,B]=w.useState(!1),[A,P]=w.useState(null),[K,X]=w.useState(!1),[Z,I]=w.useState(!!t),[H,F]=w.useState({sessionId:t||"",name:s||"",description:"",tags:""}),[G,q]=w.useState(!1),R=w.useCallback(()=>{const ne={};h&&(ne.backend=h),g&&(ne.featured=!0),v.trim()&&(ne.tags=v.split(",").map(ve=>ve.trim()).filter(Boolean)),S&&(ne.sortBy=S),k&&(ne.sortOrder=k),se.listGalleryEntries(ne).then(a).catch(ve=>f(ve instanceof Error?ve.message:String(ve))).finally(()=>c(!1))},[h,g,v,S,k]);w.useEffect(()=>{R();const ne=setInterval(R,15e3);return()=>clearInterval(ne)},[R]),w.useEffect(()=>{se.getClawHubStatus().then(ne=>B(ne.available)).catch(()=>{}),se.getMoltbookStatus().then(ne=>X(ne.available)).catch(()=>{})},[]);async function M(ne,ve){a(Ae=>Ae.map(De=>De.id===ne?{...De,votes:De.votes+ve}:De));try{const{votes:Ae}=await se.voteGalleryEntry(ne,ve);a(De=>De.map(ke=>ke.id===ne?{...ke,votes:Ae}:ke))}catch{R()}}async function O(ne){try{await se.deleteGalleryEntry(ne),R()}catch(ve){f(ve instanceof Error?ve.message:String(ve))}}async function W(ne){try{await se.featureGalleryEntry(ne),R()}catch(ve){f(ve instanceof Error?ve.message:String(ve))}}async function U(ne){if(!A){P(ne),f("");try{const ve=await se.exportToClawHub(ne);ve.ok?(f(`Exported to ClawHub: ${ve.output||"success"}`),setTimeout(()=>f(""),5e3)):f(`ClawHub export failed: ${ve.error}`)}catch(ve){f(ve instanceof Error?ve.message:String(ve))}finally{P(null)}}}async function D(ne){f("");try{const ve=await se.postToMoltbook(ne);if(ve.ok){const Ae=ve.postUrl?` — ${ve.postUrl}`:"";f(`Posted to Moltbook${Ae}`),setTimeout(()=>f(""),5e3)}else f(`Moltbook post failed: ${ve.error}`)}catch(ve){f(ve instanceof Error?ve.message:String(ve))}}async function $(ne){var ve;f("");try{const Ae=await se.createPublicReplayLink(ne),De=`${window.location.origin}/${Ae.url}`;if((ve=navigator.clipboard)!=null&&ve.writeText)await navigator.clipboard.writeText(De),f("Public replay link copied to clipboard");else{const ke=document.createElement("textarea");ke.value=De,ke.style.position="fixed",ke.style.opacity="0",document.body.appendChild(ke),ke.select(),document.execCommand("copy"),document.body.removeChild(ke),f("Public replay link copied to clipboard")}setTimeout(()=>f(""),3e3)}catch(Ae){f(Ae instanceof Error?Ae.message:String(Ae))}}async function z(){const ne=H.name.trim(),ve=H.sessionId.trim();if(!(!ne||!ve)){q(!0),f("");try{await se.createGalleryEntry({sessionId:ve,name:ne,description:H.description.trim(),tags:H.tags.split(",").map(Ae=>Ae.trim()).filter(Boolean)}),F({sessionId:"",name:"",description:"",tags:""}),I(!1),R()}catch(Ae){f(Ae instanceof Error?Ae.message:String(Ae))}finally{q(!1)}}}const T=n.reduce((ne,ve)=>ne+ve.votes,0),ae=n.filter(ne=>ne.featured).length,be=r.jsxs("div",{className:"max-w-3xl mx-auto px-4 sm:px-8 py-6 sm:py-10 font-sans-ui antialiased",children:[r.jsxs("div",{className:"flex items-center gap-3 mb-1",children:[r.jsx("button",{onClick:()=>{window.location.hash=""},className:"flex items-center justify-center w-8 h-8 rounded-lg text-cc-fg/60 hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer","aria-label":"Go back",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.8",className:"w-4 h-4",children:r.jsx("path",{d:"M10 3L5 8l5 5",strokeLinecap:"round",strokeLinejoin:"round"})})}),r.jsxs("div",{className:"flex-1",children:[r.jsx("p",{className:"text-[11px] text-cc-fg/50 font-medium",children:"Data"}),r.jsx("h1",{className:"text-xl font-semibold text-cc-fg -mt-0.5",children:"Session Gallery"})]}),r.jsx("button",{onClick:()=>{I(!Z)},className:`flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-[12px] font-medium transition-all cursor-pointer ${Z?"bg-cc-hover text-cc-fg":"bg-cc-primary hover:bg-cc-primary-hover text-white shadow-sm"}`,children:Z?r.jsxs(r.Fragment,{children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"w-3 h-3",children:r.jsx("path",{d:"M4 4l8 8M12 4l-8 8",strokeLinecap:"round"})}),"Cancel"]}):r.jsxs(r.Fragment,{children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:"w-3 h-3",children:r.jsx("path",{d:"M8 3v10M3 8h10"})}),"Publish"]})})]}),r.jsx("p",{className:"text-[13px] text-cc-fg/55 mb-5 ml-11",children:"Showcase your best AI coding sessions. Vote, feature, and share."}),r.jsxs("div",{className:"flex items-center gap-4 mb-5 ml-11",children:[r.jsxs("div",{className:"flex items-center gap-1.5 text-[12px]",children:[r.jsx("span",{className:"text-cc-fg/40",children:"Entries"}),r.jsx("span",{className:"font-semibold text-cc-fg",children:n.length})]}),r.jsx("div",{className:"w-px h-3.5 bg-cc-border/40"}),r.jsxs("div",{className:"flex items-center gap-1.5 text-[12px]",children:[r.jsx("span",{className:"text-cc-fg/40",children:"Total Votes"}),r.jsx("span",{className:"font-semibold text-cc-fg",children:T})]}),ae>0&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"w-px h-3.5 bg-cc-border/40"}),r.jsxs("div",{className:"flex items-center gap-1.5 text-[12px]",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 text-amber-500",children:r.jsx("path",{d:"M8 1.5l2.09 4.26 4.66.68-3.38 3.28.8 4.64L8 12.17l-4.17 2.19.8-4.64-3.38-3.28 4.66-.68L8 1.5z"})}),r.jsx("span",{className:"font-semibold text-cc-fg",children:ae})]})]})]}),d&&r.jsxs("div",{className:"mb-4 px-4 py-3 rounded-xl bg-cc-error/8 border border-cc-error/15 text-[12px] text-cc-error flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-4 h-4 shrink-0",children:r.jsx("path",{d:"M8 1a7 7 0 110 14A7 7 0 018 1zm0 3a.75.75 0 00-.75.75v3.5a.75.75 0 001.5 0v-3.5A.75.75 0 008 4zm0 7a1 1 0 100-2 1 1 0 000 2z"})}),d]}),r.jsx("button",{onClick:()=>f(""),className:"text-cc-error/70 hover:text-cc-error text-[11px] font-medium cursor-pointer shrink-0 ml-3",children:"Dismiss"})]}),Z&&r.jsxs("div",{className:"mb-5 rounded-xl border border-cc-primary/30 bg-cc-card shadow-sm ring-1 ring-cc-primary/10 overflow-hidden",children:[r.jsxs("div",{className:"px-5 py-4 border-b border-cc-border/30",children:[r.jsx("h3",{className:"text-[13px] font-semibold text-cc-fg",children:"Add to Gallery"}),r.jsx("p",{className:"text-[11px] text-cc-fg/50 mt-0.5",children:"Publish a session to the gallery for others to see."})]}),r.jsxs("div",{className:"px-5 py-4 space-y-3",children:[r.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-[11px] font-medium text-cc-fg/70 mb-1.5",htmlFor:"gallery-session-id",children:"Session ID"}),r.jsx("input",{id:"gallery-session-id",type:"text",value:H.sessionId,onChange:ne=>F({...H,sessionId:ne.target.value}),placeholder:"Paste session ID",className:"w-full px-3.5 py-2.5 text-[12px] font-mono-code bg-cc-bg border border-cc-border/60 rounded-lg text-cc-fg placeholder:text-cc-fg/35 focus:outline-none focus:border-cc-primary/60 focus:ring-1 focus:ring-cc-primary/20 transition-all"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-[11px] font-medium text-cc-fg/70 mb-1.5",htmlFor:"gallery-name",children:"Name"}),r.jsx("input",{id:"gallery-name",type:"text",value:H.name,onChange:ne=>F({...H,name:ne.target.value}),placeholder:"e.g. Auth Refactor",className:"w-full px-3.5 py-2.5 text-[13px] bg-cc-bg border border-cc-border/60 rounded-lg text-cc-fg placeholder:text-cc-fg/35 focus:outline-none focus:border-cc-primary/60 focus:ring-1 focus:ring-cc-primary/20 transition-all"})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-[11px] font-medium text-cc-fg/70 mb-1.5",htmlFor:"gallery-desc",children:"Description"}),r.jsx("textarea",{id:"gallery-desc",value:H.description,onChange:ne=>F({...H,description:ne.target.value}),placeholder:"What makes this session interesting? (optional)",rows:2,className:"w-full px-3.5 py-2.5 text-[13px] bg-cc-bg border border-cc-border/60 rounded-lg text-cc-fg placeholder:text-cc-fg/35 focus:outline-none focus:border-cc-primary/60 focus:ring-1 focus:ring-cc-primary/20 transition-all resize-y"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-[11px] font-medium text-cc-fg/70 mb-1.5",htmlFor:"gallery-tags",children:"Tags"}),r.jsx("input",{id:"gallery-tags",type:"text",value:H.tags,onChange:ne=>F({...H,tags:ne.target.value}),placeholder:"auth, refactor, bug-fix (comma-separated)",className:"w-full px-3.5 py-2.5 text-[13px] bg-cc-bg border border-cc-border/60 rounded-lg text-cc-fg placeholder:text-cc-fg/35 focus:outline-none focus:border-cc-primary/60 focus:ring-1 focus:ring-cc-primary/20 transition-all"})]}),r.jsx("div",{className:"flex justify-end pt-1",children:r.jsx("button",{onClick:z,disabled:!H.name.trim()||!H.sessionId.trim()||G,className:`px-4 py-2 rounded-lg text-[12px] font-medium transition-all ${H.name.trim()&&H.sessionId.trim()&&!G?"bg-cc-primary hover:bg-cc-primary-hover text-white shadow-sm cursor-pointer":"bg-cc-hover text-cc-fg/35 cursor-not-allowed"}`,children:G?r.jsxs("span",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"w-3 h-3 border-2 border-white/30 border-t-white rounded-full animate-spin"}),"Publishing..."]}):"Publish to Gallery"})})]})]}),r.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-5",children:[r.jsxs("select",{value:h,onChange:ne=>m(ne.target.value),className:"px-3 py-2 text-[12px] bg-cc-bg border border-cc-border/60 rounded-lg text-cc-fg focus:outline-none focus:border-cc-primary/60 focus:ring-1 focus:ring-cc-primary/20 cursor-pointer transition-all","aria-label":"Filter by backend",children:[r.jsx("option",{value:"",children:"All Backends"}),r.jsx("option",{value:"claude",children:"Claude"}),r.jsx("option",{value:"codex",children:"Codex"}),r.jsx("option",{value:"goose",children:"Goose"}),r.jsx("option",{value:"aider",children:"Aider"}),r.jsx("option",{value:"openhands",children:"OpenHands"}),r.jsx("option",{value:"openclaw",children:"OpenClaw"})]}),r.jsxs("select",{value:S,onChange:ne=>j(ne.target.value),className:"px-3 py-2 text-[12px] bg-cc-bg border border-cc-border/60 rounded-lg text-cc-fg focus:outline-none focus:border-cc-primary/60 focus:ring-1 focus:ring-cc-primary/20 cursor-pointer transition-all","aria-label":"Sort by",children:[r.jsx("option",{value:"votes",children:"Sort by Votes"}),r.jsx("option",{value:"recent",children:"Sort by Recent"}),r.jsx("option",{value:"cost",children:"Sort by Cost"}),r.jsx("option",{value:"duration",children:"Sort by Duration"})]}),r.jsx("button",{onClick:()=>E(ne=>ne==="desc"?"asc":"desc"),className:"px-3 py-2 text-[12px] bg-cc-bg border border-cc-border/60 rounded-lg text-cc-fg/60 hover:text-cc-fg transition-all cursor-pointer",title:k==="desc"?"Descending":"Ascending","aria-label":`Sort order: ${k}`,children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:`w-3.5 h-3.5 transition-transform ${k==="asc"?"rotate-180":""}`,children:r.jsx("path",{d:"M3.5 3a.5.5 0 01.5.5v8.793l2.146-2.147a.5.5 0 01.708.708l-3 3a.5.5 0 01-.708 0l-3-3a.5.5 0 11.708-.708L3 12.293V3.5a.5.5 0 01.5-.5zM7 4.5a.5.5 0 01.5-.5h5a.5.5 0 010 1h-5a.5.5 0 01-.5-.5zM7.5 7a.5.5 0 000 1h3.5a.5.5 0 000-1H7.5zm0 3a.5.5 0 000 1h2a.5.5 0 000-1h-2z"})})}),r.jsxs("button",{onClick:()=>b(!g),className:`flex items-center gap-1.5 px-3 py-2 text-[12px] font-medium rounded-lg transition-all cursor-pointer border ${g?"bg-amber-500/10 text-amber-600 border-amber-500/25":"bg-cc-bg text-cc-fg/50 border-cc-border/60 hover:text-cc-fg hover:border-cc-border"}`,"aria-pressed":g,children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3",children:r.jsx("path",{d:"M8 1.5l2.09 4.26 4.66.68-3.38 3.28.8 4.64L8 12.17l-4.17 2.19.8-4.64-3.38-3.28 4.66-.68L8 1.5z"})}),"Featured"]}),r.jsx("div",{className:"flex-1 min-w-[120px]",children:r.jsx("input",{type:"text",value:v,onChange:ne=>y(ne.target.value),placeholder:"Filter by tags...",className:"w-full px-3 py-2 text-[12px] bg-cc-bg border border-cc-border/60 rounded-lg text-cc-fg placeholder:text-cc-fg/35 focus:outline-none focus:border-cc-primary/60 focus:ring-1 focus:ring-cc-primary/20 transition-all","aria-label":"Filter by tags"})})]}),l?r.jsxs("div",{className:"flex flex-col items-center justify-center py-16",children:[r.jsx("span",{className:"w-6 h-6 border-2 border-cc-fg/10 border-t-cc-fg/50 rounded-full animate-spin mb-3"}),r.jsx("p",{className:"text-[12px] text-cc-fg/50",children:"Loading gallery..."})]}):n.length===0?r.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center",children:[r.jsx("div",{className:"w-14 h-14 rounded-2xl bg-cc-hover/70 flex items-center justify-center mb-4",children:r.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"w-7 h-7 text-cc-fg/30",children:[r.jsx("path",{d:"M2 7l10-5 10 5-10 5-10-5z",strokeLinecap:"round",strokeLinejoin:"round"}),r.jsx("path",{d:"M2 12l10 5 10-5",strokeLinecap:"round",strokeLinejoin:"round"}),r.jsx("path",{d:"M2 17l10 5 10-5",strokeLinecap:"round",strokeLinejoin:"round"})]})}),r.jsx("h3",{className:"text-[14px] font-semibold text-cc-fg mb-1",children:"No gallery entries yet"}),r.jsx("p",{className:"text-[12px] text-cc-fg/50 max-w-xs",children:"Publish your best sessions to showcase them. Vote on entries to surface the most interesting ones."}),!Z&&r.jsx("button",{onClick:()=>I(!0),className:"mt-4 px-4 py-2 rounded-lg text-[12px] font-medium bg-cc-primary hover:bg-cc-primary-hover text-white shadow-sm transition-colors cursor-pointer",children:"Publish First Entry"})]}):r.jsx("div",{className:"space-y-3",children:n.map(ne=>r.jsx(oh,{entry:ne,onVote:M,onDelete:O,onFeature:W,onExportClawHub:U,clawHubAvailable:N,onPostMoltbook:D,moltbookAvailable:K,onCreatePublicLink:$},ne.id))})]});return e?r.jsx("div",{className:"h-full bg-cc-bg overflow-y-auto text-cc-fg",children:be}):r.jsx("div",{className:"h-full bg-cc-bg overflow-y-auto text-cc-fg",children:be})}const nH=[{value:"session.created",label:"Session Created"},{value:"session.completed",label:"Session Completed"},{value:"session.failed",label:"Session Failed"},{value:"permission.requested",label:"Permission Requested"},{value:"permission.resolved",label:"Permission Resolved"},{value:"turn.completed",label:"Turn Completed"},{value:"cost.threshold",label:"Cost Threshold"}];function rH(e){const t=Date.now()-e,s=Math.floor(t/6e4);if(s<1)return"just now";if(s<60)return`${s}m ago`;const n=Math.floor(s/60);return n<24?`${n}h ago`:`${Math.floor(n/24)}d ago`}const Dg={name:"",url:"",events:["session.completed"],secret:"",format:"generic",backendFilter:"",cwdFilter:""};function iH({onClose:e,embedded:t=!1}){const[s,n]=w.useState([]),[a,l]=w.useState(!0),[c,d]=w.useState(""),[f,h]=w.useState(null),[m,g]=w.useState(Dg),[b,v]=w.useState(Dg),[y,S]=w.useState(!1),[j,k]=w.useState(!0),[E,N]=w.useState(new Set),[B,A]=w.useState(new Map),P=w.useCallback(()=>{se.listWebhooks().then(n).catch(()=>{}).finally(()=>l(!1))},[]);w.useEffect(()=>{P();const O=setInterval(P,15e3);return()=>clearInterval(O)},[P]);async function K(){const O=b.name.trim(),W=b.url.trim();if(!(!O||!W||b.events.length===0)){S(!0),d("");try{const U={};b.backendFilter&&(U.backendType=b.backendFilter),b.cwdFilter.trim()&&(U.cwd=b.cwdFilter.trim()),await se.createWebhook({name:O,url:W,events:b.events,secret:b.secret.trim()||void 0,format:b.format||void 0,sessionFilter:Object.keys(U).length>0?U:void 0}),v(Dg),k(!0),P()}catch(U){d(U instanceof Error?U.message:String(U))}finally{S(!1)}}}function X(O){var W,U;h(O.id),g({name:O.name,url:O.url,events:[...O.events],secret:O.secret||"",format:O.format||"generic",backendFilter:((W=O.sessionFilter)==null?void 0:W.backendType)||"",cwdFilter:((U=O.sessionFilter)==null?void 0:U.cwd)||""}),d("")}function Z(){h(null),d("")}async function I(){if(!f)return;const O=m.name.trim(),W=m.url.trim();if(!(!O||!W||m.events.length===0))try{const U={};m.backendFilter&&(U.backendType=m.backendFilter),m.cwdFilter.trim()&&(U.cwd=m.cwdFilter.trim()),await se.updateWebhook(f,{name:O,url:W,events:m.events,secret:m.secret.trim()||void 0,format:m.format||void 0,sessionFilter:Object.keys(U).length>0?U:void 0}),h(null),d(""),P()}catch(U){d(U instanceof Error?U.message:String(U))}}async function H(O){try{await se.deleteWebhook(O),f===O&&h(null),P()}catch(W){d(W instanceof Error?W.message:String(W))}}async function F(O){try{await se.toggleWebhook(O),P()}catch(W){d(W instanceof Error?W.message:String(W))}}async function G(O){N(W=>new Set(W).add(O)),A(W=>{const U=new Map(W);return U.delete(O),U});try{const W=await se.testWebhook(O);A(U=>new Map(U).set(O,W.ok)),P()}catch{A(W=>new Map(W).set(O,!1))}finally{N(W=>{const U=new Set(W);return U.delete(O),U})}}const q=c&&r.jsx("div",{className:"px-3 py-2 rounded-lg bg-cc-error/10 border border-cc-error/20 text-xs text-cc-error",children:c}),R=a?r.jsx("div",{className:"text-sm text-cc-muted text-center py-6",children:"Loading webhooks..."}):s.length===0?r.jsx("div",{className:"text-sm text-cc-muted text-center py-6",children:"No webhooks configured. Create one below."}):r.jsx("div",{className:"space-y-3",children:s.map(O=>{var W,U;return r.jsxs("div",{className:"border border-cc-border rounded-lg overflow-hidden bg-cc-card",children:[r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5 bg-cc-card border-b border-cc-border",children:[r.jsx("span",{className:"text-sm font-medium text-cc-fg flex-1 truncate",children:O.name}),O.totalDeliveries>0&&r.jsxs("span",{className:`text-[9px] font-medium px-1.5 rounded-full leading-[16px] shrink-0 ${O.failedDeliveries>0?"text-cc-error bg-cc-error/10":"text-cc-success bg-cc-success/10"}`,children:[O.totalDeliveries-O.failedDeliveries,"/",O.totalDeliveries]}),r.jsx("button",{onClick:()=>F(O.id),className:`relative w-8 h-[18px] rounded-full transition-colors cursor-pointer shrink-0 ${O.enabled?"bg-cc-primary":"bg-cc-border"}`,title:O.enabled?"Disable":"Enable",children:r.jsx("span",{className:`absolute top-[2px] w-[14px] h-[14px] rounded-full bg-white transition-transform ${O.enabled?"left-[16px]":"left-[2px]"}`})}),f===O.id?r.jsx("button",{onClick:Z,className:"text-xs text-cc-muted hover:text-cc-fg cursor-pointer",children:"Cancel"}):r.jsxs(r.Fragment,{children:[r.jsx("button",{onClick:()=>G(O.id),disabled:E.has(O.id),className:`text-xs cursor-pointer ${E.has(O.id)?"text-cc-muted cursor-not-allowed":"text-cc-primary hover:text-cc-primary-hover"}`,children:E.has(O.id)?"Testing...":"Test"}),B.has(O.id)&&r.jsx("span",{className:`text-[10px] ${B.get(O.id)?"text-cc-success":"text-cc-error"}`,children:B.get(O.id)?"OK":"Failed"}),r.jsx("button",{onClick:()=>X(O),className:"text-xs text-cc-muted hover:text-cc-fg cursor-pointer",children:"Edit"}),r.jsx("button",{onClick:()=>H(O.id),className:"text-xs text-cc-muted hover:text-cc-error cursor-pointer",children:"Delete"})]})]}),f===O.id&&r.jsxs("div",{className:"px-3 py-3 space-y-2.5",children:[r.jsx(fS,{form:m,onChange:g}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("button",{onClick:I,className:"px-3 py-2 text-xs font-medium bg-cc-primary hover:bg-cc-primary-hover text-white rounded-lg transition-colors cursor-pointer",children:"Save"}),r.jsx("button",{onClick:Z,className:"px-3 py-2 text-xs font-medium text-cc-muted hover:text-cc-fg rounded-lg transition-colors cursor-pointer",children:"Cancel"})]})]}),f!==O.id&&r.jsxs("div",{className:"px-3 py-2.5 space-y-1.5",children:[r.jsx("div",{className:"text-xs text-cc-muted font-mono-code truncate",title:O.url,children:O.url}),r.jsx("div",{className:"flex flex-wrap items-center gap-1.5",children:O.events.map(D=>r.jsx("span",{className:"text-[9px] font-medium px-1.5 py-0.5 rounded-full bg-cc-hover text-cc-muted",children:D},D))}),r.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px] text-cc-muted",children:[O.secret&&r.jsxs("span",{className:"flex items-center gap-1",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3",children:r.jsx("path",{d:"M8 1a3.5 3.5 0 00-3.5 3.5V7H4a1 1 0 00-1 1v5a1 1 0 001 1h8a1 1 0 001-1V8a1 1 0 00-1-1h-.5V4.5A3.5 3.5 0 008 1zm2 6H6V4.5a2 2 0 114 0V7z"})}),"Signed"]}),O.lastDeliveryAt&&r.jsxs("span",{className:"flex items-center gap-1",children:["Last: ",rH(O.lastDeliveryAt),O.lastDeliverySuccess?r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 text-cc-success",children:r.jsx("path",{d:"M12.207 4.793a1 1 0 010 1.414l-5 5a1 1 0 01-1.414 0l-2.5-2.5a1 1 0 011.414-1.414L6.5 9.086l4.293-4.293a1 1 0 011.414 0z"})}):r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 text-cc-error",children:r.jsx("path",{d:"M4.646 4.646a.5.5 0 01.708 0L8 7.293l2.646-2.647a.5.5 0 01.708.708L8.707 8l2.647 2.646a.5.5 0 01-.708.708L8 8.707l-2.646 2.647a.5.5 0 01-.708-.708L7.293 8 4.646 5.354a.5.5 0 010-.708z"})})]}),((W=O.sessionFilter)==null?void 0:W.backendType)&&r.jsxs("span",{children:["Filter: ",O.sessionFilter.backendType]}),((U=O.sessionFilter)==null?void 0:U.cwd)&&r.jsx("span",{className:"font-mono-code truncate max-w-[200px]",title:O.sessionFilter.cwd,children:O.sessionFilter.cwd})]})]})]},O.id)})}),M=r.jsxs("div",{className:"border border-cc-border rounded-lg overflow-hidden bg-cc-card",children:[r.jsxs("button",{onClick:()=>k(!j),className:"w-full flex items-center gap-2 px-3 py-2.5 bg-cc-card border-b border-cc-border cursor-pointer hover:bg-cc-hover transition-colors",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",className:`w-3 h-3 text-cc-muted transition-transform ${j?"":"rotate-90"}`,children:r.jsx("path",{d:"M6 4l4 4-4 4",strokeLinecap:"round",strokeLinejoin:"round"})}),r.jsx("span",{className:"text-sm font-medium text-cc-fg",children:"New Webhook"})]}),!j&&r.jsxs("div",{className:"px-3 py-3 space-y-2.5",children:[r.jsx(fS,{form:b,onChange:v}),r.jsx("button",{onClick:K,disabled:!b.name.trim()||!b.url.trim()||b.events.length===0||y,className:`px-3 py-2 text-xs font-medium rounded-lg transition-colors ${b.name.trim()&&b.url.trim()&&b.events.length>0&&!y?"bg-cc-primary hover:bg-cc-primary-hover text-white cursor-pointer":"bg-cc-hover text-cc-muted cursor-not-allowed"}`,children:y?"Creating...":"Create"})]})]});return t?r.jsx("div",{className:"h-full bg-cc-bg overflow-y-auto",children:r.jsxs("div",{className:"max-w-5xl mx-auto px-4 sm:px-8 py-6 sm:py-10",children:[r.jsxs("div",{className:"mb-6",children:[r.jsx("h1",{className:"text-xl font-semibold text-cc-fg",children:"Webhooks"}),r.jsx("p",{className:"mt-1 text-sm text-cc-muted",children:"Receive HTTP notifications when session events occur."})]}),q,r.jsxs("div",{className:"mt-4 space-y-4",children:[r.jsxs("section",{className:"bg-cc-card border border-cc-border rounded-xl p-4 sm:p-5 space-y-3",children:[r.jsx("h2",{className:"text-sm font-semibold text-cc-fg",children:"Configured Webhooks"}),R]}),r.jsx("section",{className:"bg-cc-card border border-cc-border rounded-xl p-4 sm:p-5 space-y-3",children:M})]})]})}):null}function fS({form:e,onChange:t}){const s=a=>t({...e,...a});function n(a){const l=e.events.includes(a)?e.events.filter(c=>c!==a):[...e.events,a];s({events:l})}return r.jsxs("div",{className:"space-y-2.5",children:[r.jsx("input",{type:"text",value:e.name,onChange:a=>s({name:a.target.value}),placeholder:"Webhook name (e.g. Slack notifications)",className:"w-full px-3 py-2 text-sm bg-cc-input-bg border border-cc-border rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:border-cc-primary/50"}),r.jsx("input",{type:"text",value:e.url,onChange:a=>s({url:a.target.value}),placeholder:"https://hooks.slack.com/services/...",className:"w-full px-3 py-2 text-sm font-mono-code bg-cc-input-bg border border-cc-border rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:border-cc-primary/50"}),r.jsxs("div",{children:[r.jsx("div",{className:"text-[11px] font-medium text-cc-muted mb-1.5",children:"Payload Format"}),r.jsx("div",{className:"flex gap-1.5",children:[{value:"generic",label:"Generic"},{value:"slack",label:"Slack"},{value:"openclaw",label:"OpenClaw"}].map(a=>r.jsx("button",{onClick:()=>s({format:a.value}),className:`px-2 py-1 text-[10px] font-medium rounded-md transition-colors cursor-pointer ${e.format===a.value?"bg-cc-primary/20 text-cc-primary border border-cc-primary/30":"bg-cc-hover text-cc-muted hover:text-cc-fg border border-transparent"}`,children:a.label},a.value))}),e.format==="openclaw"&&r.jsx("div",{className:"mt-1 text-[10px] text-cc-muted",children:"Posts to OpenClaw /hooks/agent endpoint. Use the signing secret field for the Bearer token."})]}),r.jsxs("div",{children:[r.jsx("div",{className:"text-[11px] font-medium text-cc-muted mb-1.5",children:"Events"}),r.jsx("div",{className:"flex flex-wrap gap-1.5",children:nH.map(a=>r.jsx("button",{onClick:()=>n(a.value),className:`px-2 py-1 text-[10px] font-medium rounded-md transition-colors cursor-pointer ${e.events.includes(a.value)?"bg-cc-primary/20 text-cc-primary border border-cc-primary/30":"bg-cc-hover text-cc-muted hover:text-cc-fg border border-transparent"}`,children:a.label},a.value))})]}),r.jsx("input",{type:"password",value:e.secret,onChange:a=>s({secret:a.target.value}),placeholder:"Signing secret (optional, for HMAC-SHA256)",className:"w-full px-3 py-2 text-sm bg-cc-input-bg border border-cc-border rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:border-cc-primary/50"}),r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsxs("select",{value:e.backendFilter,onChange:a=>s({backendFilter:a.target.value}),className:"px-2 py-1.5 text-xs bg-cc-input-bg border border-cc-border rounded-lg text-cc-fg focus:outline-none focus:border-cc-primary/50",children:[r.jsx("option",{value:"",children:"All backends"}),r.jsx("option",{value:"claude",children:"Claude Code"}),r.jsx("option",{value:"codex",children:"Codex"}),r.jsx("option",{value:"goose",children:"Goose"}),r.jsx("option",{value:"aider",children:"Aider"}),r.jsx("option",{value:"openhands",children:"OpenHands"}),r.jsx("option",{value:"openclaw",children:"OpenClaw"})]}),r.jsx("input",{type:"text",value:e.cwdFilter,onChange:a=>s({cwdFilter:a.target.value}),placeholder:"Filter by path prefix (optional)",className:"flex-1 px-2 py-1.5 text-xs font-mono-code bg-cc-input-bg border border-cc-border rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:border-cc-primary/50"})]})]})}function aH(e){const t=Date.now()-e,s=Math.floor(t/6e4);if(s<1)return"just now";if(s<60)return`${s}m ago`;const n=Math.floor(s/60);return n<24?`${n}h ago`:`${Math.floor(n/24)}d ago`}const oH={stdio:"stdio",websocket:"WebSocket",http:"HTTP"};function lH({embedded:e=!1}){const[t,s]=w.useState([]),[n,a]=w.useState(!0),[l,c]=w.useState(""),[d,f]=w.useState(""),[h,m]=w.useState(!1),[g,b]=w.useState(new Set),v=w.useCallback(()=>{se.listAdapters().then(s).catch(()=>{}).finally(()=>a(!1))},[]);w.useEffect(()=>{v();const N=setInterval(v,3e4);return()=>clearInterval(N)},[v]);async function y(){const N=d.trim();if(N){m(!0),c("");try{await se.installAdapter(N),f(""),v()}catch(B){c(B instanceof Error?B.message:String(B))}finally{m(!1)}}}async function S(N){b(B=>new Set(B).add(N));try{await se.uninstallAdapter(N),v()}catch(B){c(B instanceof Error?B.message:String(B))}finally{b(B=>{const A=new Set(B);return A.delete(N),A})}}const j=l&&r.jsx("div",{className:"px-3 py-2 rounded-lg bg-cc-error/10 border border-cc-error/20 text-xs text-cc-error",children:l}),k=n?r.jsx("div",{className:"text-sm text-cc-muted text-center py-6",children:"Loading adapters..."}):t.length===0?r.jsx("div",{className:"text-sm text-cc-muted text-center py-6",children:"No community adapters installed. Install one below."}):r.jsx("div",{className:"space-y-3",children:t.map(N=>{const B=N.metadata;return r.jsxs("div",{className:"border border-cc-border rounded-lg overflow-hidden bg-cc-card",children:[r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5 bg-cc-card border-b border-cc-border",children:[r.jsx("span",{className:"text-sm font-medium text-cc-fg flex-1 truncate",children:B.displayName}),r.jsxs("span",{className:"text-[9px] font-medium px-1.5 rounded-full leading-[16px] shrink-0 text-cc-muted bg-cc-hover",children:["v",B.version]}),r.jsx("span",{className:"text-[9px] font-medium px-1.5 rounded-full leading-[16px] shrink-0 text-blue-500 bg-blue-500/10",children:oH[B.protocol]||B.protocol}),r.jsx("button",{onClick:()=>S(B.name),disabled:g.has(B.name),className:`text-xs cursor-pointer ${g.has(B.name)?"text-cc-muted cursor-not-allowed":"text-cc-muted hover:text-cc-error"}`,children:g.has(B.name)?"Removing...":"Uninstall"})]}),r.jsxs("div",{className:"px-3 py-2.5 space-y-1.5",children:[B.description&&r.jsx("div",{className:"text-xs text-cc-muted",children:B.description}),r.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px] text-cc-muted",children:[r.jsx("span",{className:"font-mono-code",children:B.name}),r.jsxs("span",{children:[B.models.length," model",B.models.length!==1?"s":""]}),B.binaryName&&r.jsx("span",{className:"font-mono-code",children:B.binaryName}),B.author&&r.jsxs("span",{children:["by ",B.author]}),r.jsxs("span",{children:["Installed ",aH(N.installedAt)]}),r.jsx("span",{className:"font-mono-code",children:N.npmPackage})]}),B.models.length>1&&r.jsx("div",{className:"flex flex-wrap gap-1",children:B.models.map(A=>r.jsx("span",{className:"text-[9px] font-medium px-1.5 py-0.5 rounded-full bg-cc-hover text-cc-muted",children:A.label},A.value))})]})]},B.name)})}),E=r.jsxs("div",{className:"space-y-2.5",children:[r.jsx("div",{className:"text-[11px] font-medium text-cc-muted",children:"Install a community adapter from npm"}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"text",value:d,onChange:N=>f(N.target.value),onKeyDown:N=>N.key==="Enter"&&y(),placeholder:"@campfire/example-adapter",className:"flex-1 px-3 py-2 text-sm font-mono-code bg-cc-input-bg border border-cc-border rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:border-cc-primary/50"}),r.jsx("button",{onClick:y,disabled:!d.trim()||h,className:`px-3 py-2 text-xs font-medium rounded-lg transition-colors ${d.trim()&&!h?"bg-cc-primary hover:bg-cc-primary-hover text-white cursor-pointer":"bg-cc-hover text-cc-muted cursor-not-allowed"}`,children:h?"Installing...":"Install"})]}),r.jsx("div",{className:"text-[10px] text-cc-muted",children:'Adapters must declare a "campfireAdapter" field in their package.json'})]});return e?r.jsx("div",{className:"h-full bg-cc-bg overflow-y-auto",children:r.jsxs("div",{className:"max-w-5xl mx-auto px-4 sm:px-8 py-6 sm:py-10",children:[r.jsxs("div",{className:"mb-6",children:[r.jsx("h1",{className:"text-xl font-semibold text-cc-fg",children:"Adapters"}),r.jsx("p",{className:"mt-1 text-sm text-cc-muted",children:"Install and manage community agent adapters."})]}),j,r.jsxs("div",{className:"mt-4 space-y-4",children:[r.jsxs("section",{className:"bg-cc-card border border-cc-border rounded-xl p-4 sm:p-5 space-y-3",children:[r.jsx("h2",{className:"text-sm font-semibold text-cc-fg",children:"Installed Adapters"}),k]}),r.jsxs("section",{className:"bg-cc-card border border-cc-border rounded-xl p-4 sm:p-5 space-y-3",children:[r.jsx("h2",{className:"text-sm font-semibold text-cc-fg",children:"Install Adapter"}),E]})]})]})}):null}function cH({onClose:e,embedded:t=!1}){const[s,n]=w.useState(null),[a,l]=w.useState(""),[c,d]=w.useState([]),[f,h]=w.useState(!1),[m,g]=w.useState(null),[b,v]=w.useState(new Map),[y,S]=w.useState("");w.useEffect(()=>{se.getClawHubStatus().then(N=>n(N.available)).catch(()=>n(!1))},[]);const j=w.useCallback(async()=>{if(a.trim()){h(!0),S("");try{const N=await se.searchClawHub(a.trim());d(N)}catch(N){S(N instanceof Error?N.message:String(N))}finally{h(!1)}}},[a]);async function k(N){g(N),v(B=>{const A=new Map(B);return A.delete(N),A});try{const B=await se.installClawHubSkill(N);v(A=>new Map(A).set(N,B.ok))}catch{v(B=>new Map(B).set(N,!1))}finally{g(null)}}if(s===null)return r.jsx("div",{className:"text-sm text-cc-muted text-center py-10",children:"Checking ClawHub availability..."});if(!s)return r.jsx("div",{className:"h-full bg-cc-bg overflow-y-auto",children:r.jsxs("div",{className:"max-w-5xl mx-auto px-4 sm:px-8 py-6 sm:py-10",children:[r.jsx("h1",{className:"text-xl font-semibold text-cc-fg",children:"ClawHub Skills"}),r.jsxs("div",{className:"mt-4 p-6 bg-cc-card border border-cc-border rounded-xl text-center",children:[r.jsxs("p",{className:"text-sm text-cc-muted mb-3",children:["The ",r.jsx("code",{className:"text-cc-fg bg-cc-hover px-1 rounded",children:"clawhub"})," CLI is not installed."]}),r.jsxs("p",{className:"text-xs text-cc-muted",children:["Install it with: ",r.jsx("code",{className:"text-cc-fg bg-cc-hover px-1 rounded",children:"npm install -g clawhub"})]})]})]})});const E=r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"mb-6",children:[r.jsx("h1",{className:"text-xl font-semibold text-cc-fg",children:"ClawHub Skills"}),r.jsx("p",{className:"mt-1 text-sm text-cc-muted",children:"Browse and install skills from the OpenClaw skill marketplace."})]}),y&&r.jsx("div",{className:"mb-4 px-3 py-2 rounded-lg bg-cc-error/10 border border-cc-error/20 text-xs text-cc-error",children:y}),r.jsxs("div",{className:"flex gap-2 mb-4",children:[r.jsx("input",{type:"text",value:a,onChange:N=>l(N.target.value),onKeyDown:N=>N.key==="Enter"&&j(),placeholder:"Search skills (e.g. 'code review', 'email', 'slack')",className:"flex-1 px-3 py-2 text-sm bg-cc-input-bg border border-cc-border rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:border-cc-primary/50"}),r.jsx("button",{onClick:j,disabled:f||!a.trim(),className:`px-4 py-2 text-sm font-medium rounded-lg transition-colors ${!f&&a.trim()?"bg-cc-primary hover:bg-cc-primary-hover text-white cursor-pointer":"bg-cc-hover text-cc-muted cursor-not-allowed"}`,children:f?"Searching...":"Search"})]}),c.length>0?r.jsx("div",{className:"space-y-3",children:c.map(N=>r.jsx("div",{className:"border border-cc-border rounded-lg overflow-hidden bg-cc-card",children:r.jsxs("div",{className:"flex items-center gap-3 px-4 py-3",children:[r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-sm font-medium text-cc-fg",children:N.name}),r.jsxs("span",{className:"text-[10px] text-cc-muted bg-cc-hover px-1.5 py-0.5 rounded",children:["v",N.version]})]}),r.jsx("p",{className:"text-xs text-cc-muted mt-0.5 truncate",children:N.description}),r.jsxs("div",{className:"flex items-center gap-3 mt-1 text-[10px] text-cc-muted",children:[N.author&&r.jsxs("span",{children:["by ",N.author]}),N.downloads!==void 0&&r.jsxs("span",{children:[N.downloads.toLocaleString()," downloads"]})]})]}),r.jsx("button",{onClick:()=>k(N.name),disabled:m===N.name,className:`shrink-0 px-3 py-1.5 text-xs font-medium rounded-lg transition-colors ${m===N.name?"bg-cc-hover text-cc-muted cursor-not-allowed":b.get(N.name)===!0?"bg-cc-success/20 text-cc-success cursor-default":b.get(N.name)===!1?"bg-cc-error/20 text-cc-error cursor-pointer":"bg-cc-primary/20 text-cc-primary hover:bg-cc-primary/30 cursor-pointer"}`,children:m===N.name?"Installing...":b.get(N.name)===!0?"Installed":b.get(N.name)===!1?"Failed — Retry":"Install"})]})},N.name))}):!f&&a?r.jsxs("div",{className:"text-sm text-cc-muted text-center py-8",children:["No skills found for “",a,"”"]}):f?null:r.jsx("div",{className:"text-sm text-cc-muted text-center py-8",children:"Enter a search term to browse ClawHub skills."})]});return t?r.jsx("div",{className:"h-full bg-cc-bg overflow-y-auto",children:r.jsx("div",{className:"max-w-5xl mx-auto px-4 sm:px-8 py-6 sm:py-10",children:E})}):null}const uH=w.lazy(()=>Xi(()=>Promise.resolve().then(()=>fu),void 0).then(e=>({default:e.CodeEditor})));function NN(e){const t=Date.now()-e,s=Math.floor(t/6e4);if(s<1)return"just now";if(s<60)return`${s}m ago`;const n=Math.floor(s/60);return n<24?`${n}h ago`:`${Math.floor(n/24)}d ago`}function dH(e){const t=e-Date.now();if(t<=0)return"now";const s=Math.floor(t/6e4);if(s<60)return`in ${s}m`;const n=Math.floor(s/60);return n<24?`in ${n}h`:`in ${Math.floor(n/24)}d`}const hH={claude:"text-[#5BA8A0] bg-[#5BA8A0]/10",codex:"text-blue-500 bg-blue-500/10",goose:"text-amber-500 bg-amber-500/10",aider:"text-purple-500 bg-purple-500/10",openhands:"text-rose-500 bg-rose-500/10",openclaw:"text-orange-500 bg-orange-500/10",opencode:"text-teal-500 bg-teal-500/10"},fH=[{value:"claude",label:"Claude"},{value:"codex",label:"Codex"},{value:"goose",label:"Goose"},{value:"aider",label:"Aider"},{value:"openhands",label:"OpenHands"},{value:"openclaw",label:"OpenClaw"},{value:"opencode",label:"OpenCode"}],pS={name:"",description:"",icon:"🤖",backendType:"claude",model:ri("claude"),permissionMode:Qc("claude"),cwd:"",prompt:"",envSlug:"",webhookEnabled:!1,scheduleEnabled:!1,scheduleExpression:"0 8 * * *",scheduleRecurring:!0,codexInternetAccess:!1},pH=[{label:"Every hour",value:"0 * * * *"},{label:"Daily at 8am",value:"0 8 * * *"},{label:"Every 2 hours",value:"0 */2 * * *"},{label:"Weekdays at 9am",value:"0 9 * * 1-5"}],mH=["🤖","🔥","⚡","🚀","🧪","🔧","📋","🔍","🎯","📦"];function gH({embedded:e=!1}){var $;const[t,s]=w.useState([]),[n,a]=w.useState(!0),[l,c]=w.useState(""),[d,f]=w.useState(!1),[h,m]=w.useState(null),[g,b]=w.useState(pS),[v,y]=w.useState(!1),[S,j]=w.useState(null),[k,E]=w.useState(""),[N,B]=w.useState(null),[A,P]=w.useState([]),[K,X]=w.useState("all"),[Z,I]=w.useState([]),H=w.useCallback(()=>{se.listAgents().then(s).catch(()=>{}).finally(()=>a(!1))},[]);w.useEffect(()=>{H(),se.listEnvs().then(I).catch(()=>{});const z=setInterval(H,1e4);return()=>clearInterval(z)},[H]),w.useEffect(()=>{N&&se.getAgentExecutions(N).then(P).catch(()=>P([]))},[N]);function F(){m(null),b(pS),f(!0),c("")}function G(z){var T,ae,be,ne,ve,Ae,De,ke;m(z.id),b({name:z.name,description:z.description,icon:z.icon||"🤖",backendType:z.backendType,model:z.model,permissionMode:z.permissionMode,cwd:z.cwd,prompt:z.prompt,envSlug:z.envSlug||"",webhookEnabled:((ae=(T=z.triggers)==null?void 0:T.webhook)==null?void 0:ae.enabled)||!1,scheduleEnabled:((ne=(be=z.triggers)==null?void 0:be.schedule)==null?void 0:ne.enabled)||!1,scheduleExpression:((Ae=(ve=z.triggers)==null?void 0:ve.schedule)==null?void 0:Ae.expression)||"0 8 * * *",scheduleRecurring:((ke=(De=z.triggers)==null?void 0:De.schedule)==null?void 0:ke.recurring)??!0,codexInternetAccess:z.codexInternetAccess||!1}),f(!0),c("")}async function q(){if(!g.name.trim()||!g.prompt.trim()||!g.cwd.trim()){c("Name, prompt, and working directory are required");return}y(!0),c("");const z={name:g.name,description:g.description,icon:g.icon,backendType:g.backendType,model:g.backendType==="codex"?"":g.model,permissionMode:g.permissionMode,cwd:g.cwd,prompt:g.prompt,envSlug:g.envSlug||void 0,codexInternetAccess:g.backendType==="codex"?g.codexInternetAccess:void 0,triggers:{webhook:{enabled:g.webhookEnabled},schedule:g.scheduleEnabled?{enabled:!0,expression:g.scheduleExpression,recurring:g.scheduleRecurring}:{enabled:!1,expression:"",recurring:!0}}};try{h?await se.updateAgentProfile(h,z):await se.createAgent(z),f(!1),m(null),H()}catch(T){c(T instanceof Error?T.message:"Unknown error")}finally{y(!1)}}async function R(z){try{await se.deleteAgent(z),H()}catch{}}async function M(z){try{await se.toggleAgent(z),H()}catch{}}async function O(z){if(z.prompt.includes("{{input}}"))j(z),E("");else try{await se.runAgent(z.id),H()}catch{}}async function W(){if(S)try{await se.runAgent(S.id,k),j(null),H()}catch{}}const U=t.filter(z=>{var T,ae,be,ne;return K==="enabled"?z.enabled:K==="scheduled"?(ae=(T=z.triggers)==null?void 0:T.schedule)==null?void 0:ae.enabled:K==="webhook"?(ne=(be=z.triggers)==null?void 0:be.webhook)==null?void 0:ne.enabled:!0}),D={all:t.length,enabled:t.filter(z=>z.enabled).length,scheduled:t.filter(z=>{var T,ae;return(ae=(T=z.triggers)==null?void 0:T.schedule)==null?void 0:ae.enabled}).length,webhook:t.filter(z=>{var T,ae;return(ae=(T=z.triggers)==null?void 0:T.webhook)==null?void 0:ae.enabled}).length};return r.jsxs("div",{className:e?"px-4 py-6 max-w-4xl mx-auto":"p-6 max-w-4xl mx-auto",children:[r.jsxs("div",{className:"flex items-center justify-between mb-6",children:[r.jsxs("div",{children:[r.jsx("h1",{className:"text-lg font-semibold text-cc-fg",children:"Agents"}),r.jsx("p",{className:"text-[12px] text-cc-muted mt-0.5",children:"Persistent agent profiles with automated triggers"})]}),r.jsx("button",{onClick:F,className:"px-3 py-1.5 rounded-lg bg-cc-primary text-white text-[12px] font-medium hover:bg-cc-primary-hover transition-colors cursor-pointer",children:"+ Create Agent"})]}),r.jsx("div",{className:"flex gap-1 mb-4",children:["all","enabled","scheduled","webhook"].map(z=>r.jsxs("button",{onClick:()=>X(z),className:`px-2.5 py-1 rounded-md text-[11px] font-medium transition-colors cursor-pointer ${K===z?"bg-cc-primary/10 text-cc-primary":"text-cc-muted hover:text-cc-fg hover:bg-cc-hover"}`,children:[z.charAt(0).toUpperCase()+z.slice(1),r.jsx("span",{className:"ml-1 text-[10px] opacity-60 tabular-nums",children:D[z]})]},z))}),n&&r.jsx("p",{className:"text-cc-muted text-sm",children:"Loading..."}),!n&&U.length===0&&r.jsxs("div",{className:"text-center py-12 text-cc-muted",children:[r.jsx("p",{className:"text-sm",children:"No agents yet"}),r.jsx("p",{className:"text-xs mt-1",children:"Create your first agent to automate tasks across any backend"})]}),r.jsx("div",{className:"space-y-2",children:U.map(z=>r.jsxs("div",{children:[r.jsx(_H,{agent:z,onEdit:()=>G(z),onDelete:()=>R(z.id),onToggle:()=>M(z.id),onRun:()=>O(z),expanded:N===z.id,onExpand:()=>B(N===z.id?null:z.id)}),N===z.id&&r.jsxs("div",{className:"ml-8 mt-1 mb-3 space-y-1",children:[A.length===0&&r.jsx("p",{className:"text-[11px] text-cc-muted",children:"No executions yet"}),A.slice(0,10).map(T=>r.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-cc-muted px-2 py-1 rounded bg-cc-hover/50",children:[r.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${xH(T)}`}),r.jsx("span",{className:"font-mono-code",children:T.trigger}),r.jsx("span",{className:"flex-1 truncate",children:T.input?`"${T.input.slice(0,40)}"`:""}),r.jsx("span",{className:"font-mono-code tabular-nums",children:NN(T.startedAt)}),T.error&&r.jsx("span",{className:"text-cc-error truncate max-w-[120px]",children:T.error})]},T.executionId))]})]},z.id))}),d&&r.jsx("dialog",{open:!0,className:"fixed inset-0 z-50 flex items-center justify-center bg-black/30 backdrop-blur-sm w-full h-full m-0 p-0 border-none",children:r.jsxs("div",{className:"w-full max-w-lg max-h-[85vh] overflow-y-auto bg-cc-card border border-cc-border rounded-xl shadow-float p-5 m-auto",children:[r.jsx("h2",{className:"text-sm font-semibold text-cc-fg mb-4",children:h?"Edit Agent":"Create Agent"}),l&&r.jsx("p",{className:"text-[11px] text-cc-error mb-3 bg-cc-error/5 px-3 py-1.5 rounded",children:l}),r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{className:"flex gap-2",children:[r.jsx("select",{value:g.icon,onChange:z=>b({...g,icon:z.target.value}),className:"w-12 h-9 rounded-lg border border-cc-border bg-cc-input-bg text-center text-base cursor-pointer",children:mH.map(z=>r.jsx("option",{value:z,children:z},z))}),r.jsx("input",{value:g.name,onChange:z=>b({...g,name:z.target.value}),placeholder:"Agent name",className:"flex-1 h-9 px-3 rounded-lg border border-cc-border bg-cc-input-bg text-[13px] text-cc-fg"})]}),r.jsx("input",{value:g.description,onChange:z=>b({...g,description:z.target.value}),placeholder:"Short description (optional)",className:"w-full h-9 px-3 rounded-lg border border-cc-border bg-cc-input-bg text-[13px] text-cc-fg"}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("select",{value:g.backendType,onChange:z=>{const T=z.target.value;b({...g,backendType:T,model:ri(T),permissionMode:Qc(T)})},className:"h-9 px-2 rounded-lg border border-cc-border bg-cc-input-bg text-[12px] text-cc-fg cursor-pointer",children:fH.map(z=>r.jsx("option",{value:z.value,children:z.label},z.value))}),g.backendType==="codex"?r.jsx("div",{className:"flex-1 h-9 px-2 rounded-lg border border-cc-border bg-cc-input-bg text-[12px] text-cc-muted flex items-center",children:"Codex default"}):r.jsx("select",{value:g.model,onChange:z=>b({...g,model:z.target.value}),className:"flex-1 h-9 px-2 rounded-lg border border-cc-border bg-cc-input-bg text-[12px] text-cc-fg cursor-pointer",children:Zh(g.backendType).map(z=>r.jsx("option",{value:z.value,children:z.label},z.value))})]}),r.jsx("select",{value:g.permissionMode,onChange:z=>b({...g,permissionMode:z.target.value}),className:"w-full h-9 px-2 rounded-lg border border-cc-border bg-cc-input-bg text-[12px] text-cc-fg cursor-pointer",children:Ex(g.backendType).map(z=>r.jsx("option",{value:z.value,children:z.label},z.value))}),r.jsx("input",{value:g.cwd,onChange:z=>b({...g,cwd:z.target.value}),placeholder:"Working directory (absolute path)",className:"w-full h-9 px-3 rounded-lg border border-cc-border bg-cc-input-bg text-[13px] text-cc-fg font-mono-code"}),r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[r.jsx("label",{htmlFor:"agent-env-select",className:"text-[11px] text-cc-muted font-medium",children:"Environment"}),g.backendType==="codex"&&!g.envSlug&&r.jsx("span",{className:"text-[9px] text-cc-warning font-medium px-1.5 rounded-full bg-cc-warning/10",children:"Codex requires OPENAI_API_KEY"})]}),r.jsxs("select",{id:"agent-env-select",value:g.envSlug,onChange:z=>b({...g,envSlug:z.target.value}),className:`w-full h-9 px-2 rounded-lg border bg-cc-input-bg text-[12px] text-cc-fg cursor-pointer ${g.backendType==="codex"&&!g.envSlug?"border-cc-warning/50":"border-cc-border"}`,children:[r.jsx("option",{value:"",children:"No environment profile"}),Z.map(z=>r.jsxs("option",{value:z.slug,children:[z.name," (",Object.keys(z.variables).length," vars)"]},z.slug))]}),g.envSlug&&Z.length>0&&r.jsx("div",{className:"mt-1.5 flex flex-wrap gap-1",children:Object.keys((($=Z.find(z=>z.slug===g.envSlug))==null?void 0:$.variables)||{}).map(z=>r.jsx("span",{className:"text-[9px] font-mono-code px-1.5 py-0.5 rounded bg-cc-hover text-cc-muted",children:z},z))})]}),r.jsxs("div",{children:[r.jsx("label",{className:"text-[11px] font-medium text-cc-muted block mb-1",children:"Prompt"}),r.jsx(w.Suspense,{fallback:r.jsx("div",{className:"h-[180px] rounded-xl border border-cc-border flex items-center justify-center text-cc-muted text-[12px]",children:"Loading editor..."}),children:r.jsx(uH,{value:g.prompt,onChange:z=>b({...g,prompt:z}),language:"markdown",height:"180px",minimap:!1,wordWrap:!0,ariaLabel:"Agent prompt editor. Use {{input}} as a placeholder for trigger input."})})]}),g.backendType==="codex"&&r.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:g.codexInternetAccess,onChange:z=>b({...g,codexInternetAccess:z.target.checked}),className:"rounded"}),r.jsx("span",{className:"text-[12px] text-cc-fg",children:"Enable internet access (Codex)"})]}),r.jsxs("div",{className:"border border-cc-border/50 rounded-lg p-3 space-y-2.5",children:[r.jsx("span",{className:"text-[11px] font-semibold text-cc-muted uppercase tracking-wider",children:"Triggers"}),r.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:g.webhookEnabled,onChange:z=>b({...g,webhookEnabled:z.target.checked}),className:"rounded"}),r.jsx("span",{className:"text-[12px] text-cc-fg",children:"Webhook"})]}),r.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:g.scheduleEnabled,onChange:z=>b({...g,scheduleEnabled:z.target.checked}),className:"rounded"}),r.jsx("span",{className:"text-[12px] text-cc-fg",children:"Schedule"})]}),g.scheduleEnabled&&r.jsxs("div",{className:"ml-5 space-y-2",children:[r.jsx("div",{className:"flex gap-1.5 flex-wrap",children:pH.map(z=>r.jsx("button",{type:"button",onClick:()=>b({...g,scheduleExpression:z.value}),className:`px-2 py-0.5 rounded text-[10px] transition-colors cursor-pointer ${g.scheduleExpression===z.value?"bg-cc-primary/10 text-cc-primary":"bg-cc-hover text-cc-muted hover:text-cc-fg"}`,children:z.label},z.value))}),r.jsx("input",{value:g.scheduleExpression,onChange:z=>b({...g,scheduleExpression:z.target.value}),placeholder:"Cron expression",className:"w-full h-8 px-2 rounded border border-cc-border bg-cc-input-bg text-[12px] text-cc-fg font-mono-code"})]})]})]}),r.jsxs("div",{className:"flex justify-end gap-2 mt-5",children:[r.jsx("button",{onClick:()=>f(!1),className:"px-3 py-1.5 rounded-lg text-[12px] text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:"Cancel"}),r.jsx("button",{onClick:q,disabled:v,className:"px-4 py-1.5 rounded-lg bg-cc-primary text-white text-[12px] font-medium hover:bg-cc-primary-hover transition-colors cursor-pointer disabled:opacity-40",children:vH(v,h)})]})]})}),S&&r.jsx("dialog",{open:!0,className:"fixed inset-0 z-50 flex items-center justify-center bg-black/30 backdrop-blur-sm w-full h-full m-0 p-0 border-none",children:r.jsxs("div",{className:"w-full max-w-md bg-cc-card border border-cc-border rounded-xl shadow-float p-5 m-auto",children:[r.jsxs("h2",{className:"text-sm font-semibold text-cc-fg mb-1",children:["Run ",S.name]}),r.jsxs("p",{className:"text-[11px] text-cc-muted mb-3",children:["This agent uses ","{{input}}"," in its prompt. Provide the input below."]}),r.jsx("textarea",{value:k,onChange:z=>E(z.target.value),placeholder:"Enter input...",rows:4,className:"w-full px-3 py-2 rounded-lg border border-cc-border bg-cc-input-bg text-[13px] text-cc-fg resize-y",autoFocus:!0}),r.jsxs("div",{className:"flex justify-end gap-2 mt-3",children:[r.jsx("button",{onClick:()=>j(null),className:"px-3 py-1.5 rounded-lg text-[12px] text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:"Cancel"}),r.jsx("button",{onClick:W,className:"px-4 py-1.5 rounded-lg bg-cc-primary text-white text-[12px] font-medium hover:bg-cc-primary-hover transition-colors cursor-pointer",children:"Run"})]})]})})]})}function xH(e){return e.success===!1?"bg-cc-error":e.completedAt?"bg-cc-success":"bg-cc-primary animate-breathing"}function vH(e,t){return e?"Saving...":t?"Update":"Create"}function bH(e){return e.isRunning?"bg-cc-primary animate-breathing":e.enabled?"bg-cc-success":"bg-cc-muted/40"}function _H({agent:e,onEdit:t,onDelete:s,onToggle:n,onRun:a,expanded:l,onExpand:c}){var f,h,m,g;const d=hH[e.backendType]||"text-cc-muted bg-cc-hover";return r.jsx("div",{className:`border rounded-lg transition-all ${e.enabled?"border-cc-border bg-cc-card hover:shadow-panel":"border-cc-border/50 bg-cc-card/60 opacity-70"}`,children:r.jsxs("div",{className:"flex items-center gap-3 px-3 py-2.5",children:[r.jsxs("button",{onClick:c,className:"relative text-lg shrink-0 cursor-pointer",title:"Show executions",children:[e.icon||"🤖",r.jsx("span",{className:`absolute -bottom-0.5 -right-0.5 w-2 h-2 rounded-full border border-cc-card ${bH(e)}`})]}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:"text-[13px] font-medium text-cc-fg truncate",children:e.name}),r.jsx("span",{className:`text-[9px] font-medium px-1.5 rounded-full leading-[16px] ${d}`,children:e.backendType}),e.isRunning&&r.jsx("span",{className:"text-[9px] text-cc-primary font-mono-code",children:"running"})]}),r.jsxs("div",{className:"flex items-center gap-2 mt-0.5 text-[10px] text-cc-muted",children:[e.description&&r.jsx("span",{className:"truncate max-w-[200px]",children:e.description}),((h=(f=e.triggers)==null?void 0:f.schedule)==null?void 0:h.enabled)&&r.jsx("span",{className:"font-mono-code",children:"scheduled"}),((g=(m=e.triggers)==null?void 0:m.webhook)==null?void 0:g.enabled)&&r.jsx("span",{className:"font-mono-code",children:"webhook"}),e.totalRuns>0&&r.jsxs("span",{className:"tabular-nums",children:[e.totalRuns," runs"]}),e.lastRunAt!=null&&r.jsx("span",{className:"tabular-nums",children:NN(e.lastRunAt)}),e.nextRunAt!=null&&r.jsxs("span",{className:"tabular-nums",children:["next ",dH(e.nextRunAt)]})]})]}),r.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[r.jsx("button",{onClick:a,title:"Run now",className:"p-1.5 rounded-md hover:bg-cc-hover transition-colors cursor-pointer text-cc-primary",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:r.jsx("path",{d:"M4 2l10 6-10 6V2z"})})}),r.jsx("button",{onClick:n,title:e.enabled?"Disable":"Enable",className:"p-1.5 rounded-md hover:bg-cc-hover transition-colors cursor-pointer text-cc-muted",children:e.enabled?r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 text-cc-success",children:r.jsx("path",{d:"M8 2a6 6 0 100 12A6 6 0 008 2zm3.22 4.78l-4 4a.75.75 0 01-1.06 0l-2-2a.75.75 0 011.06-1.06L6.5 9l3.47-3.47a.75.75 0 011.06 1.06z"})}):r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:r.jsx("path",{d:"M8 2a6 6 0 100 12A6 6 0 008 2zm0 1.5a4.5 4.5 0 110 9 4.5 4.5 0 010-9z"})})}),r.jsx("button",{onClick:t,title:"Edit",className:"p-1.5 rounded-md hover:bg-cc-hover transition-colors cursor-pointer text-cc-muted",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:r.jsx("path",{d:"M11.013 1.427a1.75 1.75 0 012.474 0l1.086 1.086a1.75 1.75 0 010 2.474l-8.61 8.61c-.21.21-.47.364-.756.445l-3.251.93a.75.75 0 01-.927-.928l.929-3.25a1.75 1.75 0 01.445-.758l8.61-8.61z"})})}),r.jsx("button",{onClick:s,title:"Delete",className:"p-1.5 rounded-md hover:bg-cc-hover transition-colors cursor-pointer text-cc-muted hover:text-cc-error",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:r.jsx("path",{d:"M6.5 1.75a.25.25 0 01.25-.25h2.5a.25.25 0 01.25.25V3h-3V1.75zM11 3V1.75A1.75 1.75 0 009.25 0h-2.5A1.75 1.75 0 005 1.75V3H2.75a.75.75 0 000 1.5h.928l.856 10.268A1.75 1.75 0 006.282 16h3.436a1.75 1.75 0 001.748-1.632l.856-10.268h.928a.75.75 0 000-1.5H11z"})})})]})]})})}function yH(e){return e===0?"$0":e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}function wH(e){if(e<6e4)return`${Math.round(e/1e3)}s`;const t=Math.floor(e/6e4);return t<60?`${t}m`:`${Math.floor(t/60)}h ${t%60}m`}let SH=0;function mS(){return`public-replay-${++SH}`}function jH(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function kH(e,t){var s;if(e.type==="user_message")return{id:e.id||mS(),role:"user",content:e.content||"",timestamp:e.timestamp||0};if(e.type==="assistant"){const n=e.message;return n?{id:n.id||mS(),role:"assistant",content:jH(n.content||[]),contentBlocks:n.content,timestamp:e.timestamp||0,parentToolUseId:e.parent_tool_use_id,model:n.model,stopReason:n.stop_reason}:null}if(e.type==="result"){const n=e.data;if(n!=null&&n.is_error&&((s=n.errors)!=null&&s.length))return{id:`replay-error-${t}`,role:"system",content:`Error: ${n.errors.join(", ")}`,timestamp:0}}return null}function CH({token:e}){const[t,s]=w.useState(null),[n,a]=w.useState(""),[l,c]=w.useState(!0),[d,f]=w.useState(0),[h,m]=w.useState(!1),[g,b]=w.useState(1),v=w.useRef(null),y=`public-replay-${e}`,S=Y(N=>N.setMessages);w.useEffect(()=>{se.getPublicReplay(e).then(N=>{const A=N.messages.map((P,K)=>kH(P,K)).filter(P=>P!==null);s({messages:A,gallery:N.gallery})}).catch(N=>a(N instanceof Error?N.message:String(N))).finally(()=>c(!1))},[e]),w.useEffect(()=>{if(!t)return;const N=t.messages.slice(0,d);S(y,N)},[t,d,y,S]),w.useEffect(()=>{if(!(!h||!t))return v.current=setInterval(()=>{f(N=>N>=t.messages.length?(m(!1),N):N+1)},300/g),()=>{v.current&&clearInterval(v.current)}},[h,g,t]);const j=w.useCallback(()=>{t&&(d>=t.messages.length?(f(0),m(!0)):m(N=>!N))},[t,d]);if(l)return r.jsx("div",{className:"h-full bg-cc-bg flex items-center justify-center",children:r.jsx("span",{className:"text-sm text-cc-muted",children:"Loading replay..."})});if(n)return r.jsx("div",{className:"h-full bg-cc-bg flex items-center justify-center",children:r.jsxs("div",{className:"text-center",children:[r.jsx("p",{className:"text-sm text-cc-error",children:n}),r.jsx("p",{className:"text-xs text-cc-muted mt-2",children:"This replay link may have expired or is invalid."})]})});if(!t)return null;const k=t.gallery,E=t.messages.length>0?d/t.messages.length*100:0;return r.jsxs("div",{className:"h-full bg-cc-bg flex flex-col",children:[r.jsx("div",{className:"border-b border-cc-border bg-cc-card px-4 py-3",children:r.jsxs("div",{className:"max-w-5xl mx-auto",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("span",{className:"text-lg font-semibold text-cc-fg",children:(k==null?void 0:k.name)||"Session Replay"}),r.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full bg-cc-hover text-cc-muted font-medium",children:"Public Replay"})]}),k&&r.jsxs("div",{className:"flex flex-wrap items-center gap-3 mt-1.5 text-xs text-cc-muted",children:[k.backendType&&r.jsx("span",{className:"font-medium px-1.5 rounded-full bg-cc-hover",children:k.backendType}),k.model&&r.jsx("span",{children:k.model}),k.totalCostUsd!=null&&k.totalCostUsd>0&&r.jsx("span",{children:yH(k.totalCostUsd)}),k.numTurns!=null&&k.numTurns>0&&r.jsxs("span",{children:[k.numTurns," turns"]}),k.durationMs!=null&&k.durationMs>0&&r.jsx("span",{children:wH(k.durationMs)}),k.tags&&k.tags.length>0&&r.jsx("span",{children:k.tags.join(", ")})]}),(k==null?void 0:k.description)&&r.jsx("p",{className:"text-xs text-cc-muted mt-1",children:k.description})]})}),r.jsx("div",{className:"border-b border-cc-border bg-cc-card px-4 py-2",children:r.jsxs("div",{className:"max-w-5xl mx-auto flex items-center gap-3",children:[r.jsx("button",{onClick:j,className:"w-8 h-8 flex items-center justify-center rounded-lg bg-cc-primary text-white hover:bg-cc-primary-hover transition-colors cursor-pointer",children:h?r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:r.jsx("path",{d:"M5.5 3.5A1.5 1.5 0 017 5v6a1.5 1.5 0 01-3 0V5a1.5 1.5 0 011.5-1.5zm5 0A1.5 1.5 0 0112 5v6a1.5 1.5 0 01-3 0V5a1.5 1.5 0 011.5-1.5z"})}):r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:r.jsx("path",{d:"M4.5 3.5A.5.5 0 015.22 3l7 4.5a.5.5 0 010 .86l-7 4.5A.5.5 0 014.5 12.5v-9z"})})}),r.jsx("div",{className:"flex-1 h-1.5 bg-cc-hover rounded-full overflow-hidden cursor-pointer",onClick:N=>{const B=N.currentTarget.getBoundingClientRect(),A=(N.clientX-B.left)/B.width;f(Math.round(A*t.messages.length))},children:r.jsx("div",{className:"h-full bg-cc-primary rounded-full transition-all",style:{width:`${E}%`}})}),r.jsxs("span",{className:"text-[10px] text-cc-muted tabular-nums",children:[d,"/",t.messages.length]}),r.jsxs("button",{onClick:()=>b(N=>N>=8?1:N*2),className:"px-2 py-1 text-[10px] font-medium bg-cc-hover rounded text-cc-muted hover:text-cc-fg transition-colors cursor-pointer",children:[g,"x"]})]})}),r.jsx("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden",children:r.jsx(ev,{sessionId:y})})]})}const Lg={name:"",content:"",scope:"global",projectPath:""};function NH({embedded:e}){const[t,s]=w.useState([]),[n,a]=w.useState(!0),[l,c]=w.useState(null),[d,f]=w.useState(""),[h,m]=w.useState(!1),[g,b]=w.useState(null),[v,y]=w.useState(Lg),[S,j]=w.useState(!1),[k,E]=w.useState(null),N=w.useCallback(async()=>{a(!0),c(null);try{const I=await se.listPrompts();s(I)}catch{c("Failed to load prompts.")}finally{a(!1)}},[]);w.useEffect(()=>{N()},[N]);const B=t.filter(I=>!d||I.name.toLowerCase().includes(d.toLowerCase())||I.content.toLowerCase().includes(d.toLowerCase()));function A(){b(null),y(Lg),E(null),m(!0)}function P(I){b(I.id),y({name:I.name,content:I.content,scope:I.scope,projectPath:I.projectPath??""}),E(null),m(!0)}function K(){m(!1),b(null),y(Lg),E(null)}async function X(){if(!v.name.trim()||!v.content.trim()){E("Name and content are required.");return}j(!0),E(null);try{g?await se.updatePrompt(g,{name:v.name.trim(),content:v.content.trim(),scope:v.scope,projectPath:v.scope==="project"&&v.projectPath.trim()||void 0}):await se.createPrompt({name:v.name.trim(),content:v.content.trim(),scope:v.scope,projectPath:v.scope==="project"&&v.projectPath.trim()||void 0}),K(),await N()}catch{E("Failed to save prompt.")}finally{j(!1)}}async function Z(I){if(confirm("Delete this prompt?"))try{await se.deletePrompt(I),s(H=>H.filter(F=>F.id!==I))}catch{c("Failed to delete prompt.")}}return r.jsx("div",{className:"flex-1 overflow-y-auto p-6",children:r.jsxs("div",{className:"max-w-2xl mx-auto",children:[r.jsxs("div",{className:"flex items-center justify-between mb-6",children:[r.jsxs("div",{children:[r.jsx("h2",{className:"text-xl font-semibold text-cc-fg",children:"Prompt Library"}),r.jsx("p",{className:"text-sm text-cc-muted mt-0.5",children:"Save reusable prompts and insert them with @ in the composer."})]}),r.jsx("button",{onClick:A,className:"px-3 py-1.5 rounded-lg bg-cc-primary text-white text-sm font-medium hover:bg-cc-primary-hover transition-colors cursor-pointer",children:"+ New Prompt"})]}),r.jsx("div",{className:"mb-4",children:r.jsx("input",{type:"text",value:d,onChange:I=>f(I.target.value),placeholder:"Search prompts...",className:"w-full px-3 py-2 rounded-lg border border-cc-border bg-cc-input-bg text-cc-fg text-sm focus:outline-none focus:border-cc-primary/50"})}),h&&r.jsxs("div",{className:"mb-6 p-4 rounded-lg border border-cc-border bg-cc-card",children:[r.jsx("h3",{className:"text-sm font-medium text-cc-fg mb-3",children:g?"Edit Prompt":"New Prompt"}),r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-xs text-cc-muted mb-1",children:"Name"}),r.jsx("input",{type:"text",value:v.name,onChange:I=>y(H=>({...H,name:I.target.value})),placeholder:"e.g. Code review checklist",className:"w-full px-3 py-1.5 rounded-lg border border-cc-border bg-cc-input-bg text-cc-fg text-sm focus:outline-none focus:border-cc-primary/50"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-xs text-cc-muted mb-1",children:"Content"}),r.jsx("textarea",{value:v.content,onChange:I=>y(H=>({...H,content:I.target.value})),placeholder:"The prompt text...",rows:5,className:"w-full px-3 py-1.5 rounded-lg border border-cc-border bg-cc-input-bg text-cc-fg text-sm font-mono-code resize-y focus:outline-none focus:border-cc-primary/50"})]}),r.jsxs("div",{className:"flex gap-4",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-xs text-cc-muted mb-1",children:"Scope"}),r.jsxs("select",{value:v.scope,onChange:I=>y(H=>({...H,scope:I.target.value})),className:"px-2 py-1.5 rounded-lg border border-cc-border bg-cc-input-bg text-cc-fg text-sm focus:outline-none focus:border-cc-primary/50",children:[r.jsx("option",{value:"global",children:"Global"}),r.jsx("option",{value:"project",children:"Project"})]})]}),v.scope==="project"&&r.jsxs("div",{className:"flex-1",children:[r.jsx("label",{className:"block text-xs text-cc-muted mb-1",children:"Project path"}),r.jsx("input",{type:"text",value:v.projectPath,onChange:I=>y(H=>({...H,projectPath:I.target.value})),placeholder:"/home/user/my-project",className:"w-full px-3 py-1.5 rounded-lg border border-cc-border bg-cc-input-bg text-cc-fg text-sm font-mono-code focus:outline-none focus:border-cc-primary/50"})]})]}),k&&r.jsx("p",{className:"text-xs text-cc-error",children:k}),r.jsxs("div",{className:"flex gap-2 justify-end",children:[r.jsx("button",{onClick:K,className:"px-3 py-1.5 rounded-lg border border-cc-border text-cc-muted text-sm hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:"Cancel"}),r.jsx("button",{onClick:X,disabled:S,className:`px-3 py-1.5 rounded-lg text-sm font-medium transition-colors cursor-pointer ${S?"bg-cc-hover text-cc-muted cursor-not-allowed":"bg-cc-primary text-white hover:bg-cc-primary-hover"}`,children:S?"Saving...":"Save"})]})]})]}),n?r.jsx("div",{className:"text-sm text-cc-muted",children:"Loading..."}):l?r.jsx("div",{className:"text-sm text-cc-error",children:l}):B.length===0?r.jsx("div",{className:"text-center py-12 text-cc-muted",children:d?r.jsxs("p",{className:"text-sm",children:['No prompts match "',d,'"']}):r.jsxs(r.Fragment,{children:[r.jsx("p",{className:"text-sm mb-2",children:"No prompts yet."}),r.jsx("button",{onClick:A,className:"text-sm text-cc-primary hover:text-cc-primary-hover transition-colors cursor-pointer",children:"Create your first prompt"})]})}):r.jsx("div",{className:"space-y-2",children:B.map(I=>r.jsx("div",{className:"p-4 rounded-lg border border-cc-border bg-cc-card group",children:r.jsxs("div",{className:"flex items-start justify-between gap-2",children:[r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-sm font-medium text-cc-fg",children:I.name}),r.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded-full bg-cc-hover text-cc-muted border border-cc-border capitalize",children:I.scope})]}),I.scope==="project"&&I.projectPath&&r.jsx("p",{className:"text-xs text-cc-muted font-mono-code mt-0.5",children:I.projectPath}),r.jsx("p",{className:"text-xs text-cc-muted mt-1 line-clamp-2 whitespace-pre-line",children:I.content})]}),r.jsxs("div",{className:"flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity shrink-0",children:[r.jsx("button",{onClick:()=>P(I),className:"px-2 py-1 rounded text-xs text-cc-muted hover:text-cc-fg transition-colors cursor-pointer",children:"Edit"}),r.jsx("button",{onClick:()=>Z(I.id),className:"px-2 py-1 rounded text-xs text-cc-error hover:text-cc-error/80 transition-colors cursor-pointer",children:"Delete"})]})]})},I.id))})]})})}function EN({className:e}){return r.jsxs("svg",{viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",className:e,children:[r.jsx("circle",{cx:"12",cy:"12",r:"10",fill:"currentColor"}),r.jsx("path",{d:"M7.2 15.2l6.6-6.6",stroke:"white",strokeWidth:"2",strokeLinecap:"round"}),r.jsx("circle",{cx:"16.4",cy:"8.8",r:"1.8",fill:"white"})]})}function MN(e){window.location.hash=e}function EH({embedded:e}){const[t,s]=w.useState(!1),[n,a]=w.useState(!0);w.useEffect(()=>{se.getSettings().then(c=>{c.linearApiKeyConfigured?se.getLinearConnection().then(d=>s(d.connected)).catch(()=>s(!1)).finally(()=>a(!1)):a(!1)}).catch(()=>{a(!1)})},[]);const l=[{id:"linear",name:"Linear",description:"Browse issues and auto-generate branch names from Linear tickets.",icon:r.jsx(EN,{className:"w-8 h-8 text-[#5E6AD2]"}),route:"#/integrations/linear",connected:t,checking:n}];return r.jsx("div",{className:"flex-1 overflow-y-auto p-6",children:r.jsxs("div",{className:"max-w-2xl mx-auto",children:[r.jsx("h2",{className:"text-xl font-semibold text-cc-fg mb-2",children:"Integrations"}),r.jsx("p",{className:"text-sm text-cc-fg-muted mb-6",children:"Connect external services to enhance your sessions."}),r.jsx("div",{className:"grid gap-4",children:l.map(c=>r.jsxs("button",{onClick:()=>MN(c.route),className:"flex items-center gap-4 p-4 rounded-lg border border-cc-border bg-cc-bg-subtle hover:bg-cc-bg-hover text-left transition-colors group",children:[r.jsx("div",{className:"shrink-0",children:c.icon}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-sm font-medium text-cc-fg",children:c.name}),c.checking?r.jsx("span",{className:"text-xs text-cc-fg-muted",children:"checking…"}):c.connected?r.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded-full bg-green-500/10 text-green-400 border border-green-500/20",children:"Connected"}):r.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded-full bg-cc-fg-muted/10 text-cc-fg-muted border border-cc-border",children:"Not connected"})]}),r.jsx("p",{className:"text-xs text-cc-fg-muted mt-0.5",children:c.description})]}),r.jsx("div",{className:"text-cc-fg-muted group-hover:text-cc-fg transition-colors",children:"→"})]},c.id))})]})})}function MH({embedded:e}){const[t,s]=w.useState(""),[n,a]=w.useState(null),[l,c]=w.useState(!1),[d,f]=w.useState(!1),[h,m]=w.useState(null),[g,b]=w.useState(!1);w.useEffect(()=>{se.getSettings().then(j=>{j.linearApiKeyConfigured&&v()}).catch(()=>{})},[]);async function v(){f(!0),m(null);try{const j=await se.getLinearConnection();a(j)}catch{a({connected:!1}),m("Could not connect to Linear. Check your API key.")}finally{f(!1)}}async function y(){if(t.trim()){c(!0),m(null);try{await se.updateSettings({linearApiKey:t.trim()}),s(""),b(!0),setTimeout(()=>b(!1),2e3),await v()}catch{m("Failed to save API key.")}finally{c(!1)}}}async function S(){c(!0),m(null);try{await se.updateSettings({linearApiKey:""}),a(null)}catch{m("Failed to disconnect.")}finally{c(!1)}}return r.jsx("div",{className:"flex-1 overflow-y-auto p-6",children:r.jsxs("div",{className:"max-w-xl mx-auto",children:[r.jsx("div",{className:"flex items-center gap-3 mb-6",children:r.jsx("button",{onClick:()=>MN("#/integrations"),className:"text-cc-fg-muted hover:text-cc-fg transition-colors text-sm",children:"← Integrations"})}),r.jsxs("div",{className:"flex items-center gap-3 mb-6",children:[r.jsx(EN,{className:"w-8 h-8 text-[#5E6AD2]"}),r.jsxs("div",{children:[r.jsx("h2",{className:"text-lg font-semibold text-cc-fg",children:"Linear"}),r.jsx("p",{className:"text-sm text-cc-fg-muted",children:"Connect your Linear workspace to browse issues"})]})]}),(n==null?void 0:n.connected)&&n.viewer&&r.jsx("div",{className:"mb-6 p-4 rounded-lg border border-green-500/20 bg-green-500/5",children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsxs("p",{className:"text-sm font-medium text-cc-fg",children:["Connected as ",r.jsx("span",{className:"text-green-400",children:n.viewer.name})]}),r.jsx("p",{className:"text-xs text-cc-fg-muted",children:n.viewer.email}),n.teams&&n.teams.length>0&&r.jsxs("p",{className:"text-xs text-cc-fg-muted mt-1",children:["Teams: ",n.teams.map(j=>j.name).join(", ")]})]}),r.jsx("button",{onClick:S,disabled:l,className:"text-xs text-red-400 hover:text-red-300 transition-colors disabled:opacity-50",children:"Disconnect"})]})}),!(n!=null&&n.connected)&&r.jsxs("div",{className:"mb-6",children:[r.jsx("label",{className:"block text-sm font-medium text-cc-fg mb-2",children:"Linear API Key"}),r.jsxs("p",{className:"text-xs text-cc-fg-muted mb-3",children:["Create a personal API key at"," ",r.jsx("span",{className:"font-mono text-cc-accent",children:"linear.app/settings/api"})]}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{type:"password",value:t,onChange:j=>s(j.target.value),onKeyDown:j=>{j.key==="Enter"&&y()},placeholder:"lin_api_...",className:"flex-1 px-3 py-2 rounded-md border border-cc-border bg-cc-input text-cc-fg text-sm font-mono focus:outline-none focus:ring-1 focus:ring-cc-accent"}),r.jsx("button",{onClick:y,disabled:l||!t.trim(),className:"px-4 py-2 rounded-md bg-cc-accent text-white text-sm font-medium hover:bg-cc-accent/90 disabled:opacity-50 transition-colors",children:l?"Saving…":g?"Saved!":"Connect"})]})]}),!n&&!d&&r.jsx("button",{onClick:v,className:"text-sm text-cc-accent hover:text-cc-accent/80 transition-colors",children:"Check connection"}),d&&r.jsx("p",{className:"text-sm text-cc-fg-muted",children:"Checking connection…"}),h&&r.jsx("p",{className:"text-sm text-red-400 mt-2",children:h}),r.jsxs("div",{className:"mt-8 p-4 rounded-lg border border-cc-border bg-cc-bg-subtle",children:[r.jsx("h3",{className:"text-sm font-medium text-cc-fg mb-2",children:"What this enables"}),r.jsxs("ul",{className:"text-xs text-cc-fg-muted space-y-1 list-disc list-inside",children:[r.jsx("li",{children:"Browse and search Linear issues when creating sessions"}),r.jsx("li",{children:"Auto-generate branch names from issue titles"}),r.jsx("li",{children:"Inject issue context as startup prompt for the agent"})]})]})]})})}function TH(){const e=Y(A=>A.currentSessionId),[t,s]=w.useState([]),[n,a]=w.useState([]),[l,c]=w.useState(null),[d,f]=w.useState(!1),[h,m]=w.useState("fragments"),[g,b]=w.useState(""),[v,y]=w.useState("");w.useEffect(()=>{e&&S()},[e]);async function S(){if(e){f(!0);try{const A=await se.getSessionMemory(e);s(A.fragments||[]),a(A.consolidated||[])}catch(A){console.error("[MemoryPanel] Failed to load memory:",A)}finally{f(!1)}try{const A=await se.getMemoryOverview(e);c(A)}catch(A){console.error("[MemoryPanel] Failed to load memory overview:",A),c(null)}}}async function j(A){const P=!A.pinned;s(K=>K.map(X=>X.id===A.id?{...X,pinned:P}:X));try{await se.pinMemory(A.id,P)}catch(K){console.error("[MemoryPanel] Failed to toggle pin:",K),s(X=>X.map(Z=>Z.id===A.id?{...Z,pinned:!P}:Z))}}async function k(){if(!(!e||!g.trim())){f(!0);try{const A=await se.queryMemory(e,g,20);s(A.results||[]),a(A.consolidated||[])}catch(A){console.error("[MemoryPanel] Failed to query memory:",A)}finally{f(!1)}}}async function E(){if(e){f(!0);try{await se.consolidateMemory(e),await S()}catch(A){console.error("[MemoryPanel] Failed to consolidate memory:",A)}finally{f(!1)}}}const N=Array.from(new Set(t.flatMap(A=>A.tags))).sort(),B=v?t.filter(A=>A.tags.includes(v)):t;return e?r.jsxs("div",{className:"flex flex-col h-full bg-cc-bg",children:[r.jsxs("div",{className:"shrink-0 px-4 py-3 border-b border-cc-border",children:[r.jsxs("div",{className:"flex items-center justify-between mb-3",children:[r.jsx("h2",{className:"text-sm font-semibold text-cc-fg",children:"Semantic Memory"}),r.jsx("button",{onClick:E,disabled:d,className:"px-2 py-1 text-xs font-medium text-cc-primary hover:bg-cc-active rounded cursor-pointer disabled:opacity-50",children:d?"Consolidating...":"Consolidate"})]}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{type:"text",value:g,onChange:A=>b(A.target.value),onKeyDown:A=>A.key==="Enter"&&k(),placeholder:"Search memory...",className:"flex-1 px-3 py-1.5 text-sm bg-cc-card border border-cc-border rounded-lg text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-primary"}),r.jsx("button",{onClick:k,className:"px-3 py-1.5 text-sm font-medium text-white bg-cc-primary hover:bg-cc-primary/90 rounded-lg cursor-pointer",children:"Search"})]}),r.jsxs("div",{className:"flex items-center gap-1 mt-3 bg-cc-hover rounded-lg p-0.5",children:[r.jsxs("button",{onClick:()=>m("fragments"),className:`flex-1 px-3 py-1 text-xs font-medium rounded-md transition-colors cursor-pointer ${h==="fragments"?"bg-cc-card text-cc-fg shadow-sm":"text-cc-muted hover:text-cc-fg"}`,children:["Fragments (",B.length,")"]}),r.jsxs("button",{onClick:()=>m("consolidated"),className:`flex-1 px-3 py-1 text-xs font-medium rounded-md transition-colors cursor-pointer ${h==="consolidated"?"bg-cc-card text-cc-fg shadow-sm":"text-cc-muted hover:text-cc-fg"}`,children:["Consolidated (",n.length,")"]})]})]}),r.jsxs("div",{className:"flex-1 overflow-y-auto",children:[l&&l.namespaces.length>0&&r.jsxs("div",{className:"px-4 pt-4",children:[r.jsx("h3",{className:"text-[10px] uppercase tracking-[0.15em] text-cc-muted/60 font-mono mb-2",children:"Namespaces"}),r.jsx("div",{className:"space-y-2",children:l.namespaces.map(A=>{const P=Math.round(Math.max(0,Math.min(1,A.avgWeight))*100);return r.jsxs("div",{className:"p-2.5 bg-cc-card border border-cc-border rounded-lg",children:[r.jsxs("div",{className:"flex items-center justify-between gap-2 mb-1.5",children:[r.jsx("span",{className:"text-[11px] font-mono text-cc-fg truncate",title:A.namespace,children:A.namespace}),r.jsxs("span",{className:"text-[10px] text-cc-muted font-mono shrink-0",children:[A.count," ",A.count===1?"item":"items",A.pinnedCount>0&&` · ${A.pinnedCount} pinned`]})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("div",{className:"flex-1 h-1.5 rounded-full bg-cc-hover overflow-hidden",children:r.jsx("div",{"data-testid":`ns-weight-${A.namespace}`,className:"h-full rounded-full bg-cc-primary/50",style:{width:`${P}%`}})}),r.jsxs("span",{className:"text-[10px] text-cc-muted/60 font-mono tabular-nums shrink-0",children:[P,"% avg weight"]})]})]},A.namespace)})})]}),h==="fragments"&&r.jsxs("div",{className:"p-4 space-y-3",children:[N.length>0&&r.jsxs("div",{className:"flex flex-wrap gap-1.5 pb-2 border-b border-cc-border",children:[r.jsx("button",{onClick:()=>y(""),className:`px-2 py-0.5 text-xs rounded cursor-pointer ${v?"bg-cc-hover text-cc-muted hover:text-cc-fg":"bg-cc-primary text-white"}`,children:"All"}),N.map(A=>r.jsx("button",{onClick:()=>y(A),className:`px-2 py-0.5 text-xs rounded cursor-pointer ${v===A?"bg-cc-primary text-white":"bg-cc-hover text-cc-muted hover:text-cc-fg"}`,children:A},A))]}),B.length===0?r.jsx("div",{className:"text-center py-8 text-cc-muted text-sm",children:d?"Loading...":"No memory fragments yet"}):B.map(A=>r.jsxs("div",{className:"p-3 bg-cc-card border border-cc-border rounded-lg",children:[r.jsxs("div",{className:"flex items-start justify-between mb-2",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:`px-1.5 py-0.5 text-[10px] font-medium rounded ${A.type==="observation"?"bg-blue-500/20 text-blue-400":A.type==="hypothesis"?"bg-purple-500/20 text-purple-400":A.type==="decision"?"bg-green-500/20 text-green-400":"bg-yellow-500/20 text-yellow-400"}`,children:A.type}),r.jsx("span",{className:"text-xs text-cc-muted",children:new Date(A.timestamp).toLocaleString()})]}),r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsxs("span",{className:"text-xs text-cc-muted font-mono",children:[(A.confidence*100).toFixed(0),"%"]}),r.jsx("button",{onClick:()=>j(A),"aria-label":A.pinned?"Unpin memory":"Pin memory",title:A.pinned?"Unpin — resume decay":"Pin — never decays",className:`w-5 h-5 flex items-center justify-center rounded cursor-pointer transition-colors ${A.pinned?"text-cc-primary bg-cc-primary/10 hover:bg-cc-primary/20":"text-cc-muted/40 hover:text-cc-fg hover:bg-cc-hover"}`,children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3",children:r.jsx("path",{d:"M9.5 1.5l5 5-1.5 1.5-.75-.25L9.5 10.5l.25 2.75L8.5 14.5 5.75 11.75 2.5 15l-1-1 3.25-3.25L2 8l1.25-1.25L6 7l2.75-2.75-.25-.75L9.5 1.5z"})})})]})]}),r.jsx("p",{className:"text-sm text-cc-fg mb-2",children:A.content}),A.tags.length>0&&r.jsx("div",{className:"flex flex-wrap gap-1",children:A.tags.map(P=>r.jsxs("span",{className:"px-1.5 py-0.5 text-[10px] bg-cc-hover text-cc-muted rounded",children:["#",P]},P))}),A.gitContext.files.length>0&&r.jsxs("div",{className:"mt-2 text-xs text-cc-muted font-mono",children:[A.gitContext.files.slice(0,2).join(", "),A.gitContext.files.length>2&&` +${A.gitContext.files.length-2} more`]})]},A.id))]}),h==="consolidated"&&r.jsx("div",{className:"p-4 space-y-3",children:n.length===0?r.jsx("div",{className:"text-center py-8 text-cc-muted text-sm",children:d?"Loading...":"No consolidated knowledge yet"}):n.map(A=>{var K;const P=(K=l==null?void 0:l.knowledge.find(X=>X.id===A.id))==null?void 0:K.synthesisMethod;return r.jsxs("div",{className:"p-3 bg-cc-card border border-cc-border rounded-lg",children:[r.jsxs("div",{className:"flex items-start justify-between mb-2",children:[r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsxs("span",{className:"px-2 py-1 text-xs font-semibold bg-cc-primary/20 text-cc-primary rounded",children:["#",A.tag]}),P==="concat"&&r.jsx("span",{className:"px-1.5 py-0.5 text-[10px] bg-cc-hover text-cc-muted rounded font-mono",title:"Concatenated without LLM distillation (no OpenRouter key configured)",children:"concat"})]}),r.jsxs("span",{className:"text-xs text-cc-muted",children:["Updated ",new Date(A.lastUpdated).toLocaleDateString()]})]}),r.jsx("p",{className:"text-sm text-cc-fg mb-2",children:A.summary}),r.jsxs("div",{className:"text-xs text-cc-muted",children:["Synthesized from ",A.sourceFragments.length," fragments"," · ","Confidence: ",(A.confidence*100).toFixed(0),"%"]})]},A.id)})})]})]}):r.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-cc-muted",children:[r.jsx("svg",{className:"w-16 h-16 mb-4 opacity-20",viewBox:"0 0 24 24",fill:"currentColor",children:r.jsx("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z"})}),r.jsx("p",{className:"text-sm",children:"No session selected"}),r.jsx("p",{className:"text-xs text-cc-muted mt-1",children:"Select a session to view its semantic memory"})]})}function AH(){const e=Y(k=>k.sdkSessions),[t,s]=w.useState([]),[n,a]=w.useState(""),[l,c]=w.useState([]),[d,f]=w.useState(null),[h,m]=w.useState(!1),[g,b]=w.useState(!1);w.useEffect(()=>{v()},[]);async function v(){b(!0);try{const k=await se.getCapabilities();s(k.sessions||[]),c(k.sessions.map(E=>E.sessionId))}catch(k){console.error("[TaskRouterPage] Failed to load capabilities:",k)}finally{b(!1)}}async function y(){if(!(!n.trim()||l.length===0)){m(!0),f(null);try{const k=await se.routeTask({taskDescription:n,availableSessions:l});f(k)}catch(k){console.error("[TaskRouterPage] Failed to route task:",k)}finally{m(!1)}}}function S(k){c(E=>E.includes(k)?E.filter(N=>N!==k):[...E,k])}function j(k){const E=e.find(N=>N.sessionId===k);return(E==null?void 0:E.name)||`Session ${k.slice(0,8)}`}return r.jsxs("div",{className:"flex h-full bg-cc-bg",children:[r.jsx("div",{className:"w-1/2 border-r border-cc-border overflow-y-auto",children:r.jsxs("div",{className:"p-6 space-y-6",children:[r.jsxs("div",{children:[r.jsx("h1",{className:"text-lg font-semibold text-cc-fg",children:"Task Router"}),r.jsx("p",{className:"text-sm text-cc-muted mt-1",children:"Route complex tasks to the best-suited agent based on capabilities and historical performance"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-cc-fg mb-2",children:"Task Description"}),r.jsx("textarea",{value:n,onChange:k=>a(k.target.value),placeholder:"Describe the task you want to route... e.g., 'Refactor auth module to use JWT tokens with TypeScript strict mode'",className:"w-full px-3 py-2 text-sm bg-cc-card border border-cc-border rounded-lg text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-primary resize-none",rows:4})]}),r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsxs("label",{className:"text-sm font-medium text-cc-fg",children:["Available Sessions (",l.length,"/",t.length,")"]}),r.jsx("button",{onClick:()=>c(l.length===t.length?[]:t.map(k=>k.sessionId)),className:"text-xs text-cc-primary hover:underline cursor-pointer",children:l.length===t.length?"Deselect All":"Select All"})]}),g?r.jsx("div",{className:"text-sm text-cc-muted",children:"Loading capabilities..."}):t.length===0?r.jsx("div",{className:"text-sm text-cc-muted",children:"No active sessions with capabilities reported"}):r.jsx("div",{className:"space-y-2",children:t.map(k=>r.jsx("div",{onClick:()=>S(k.sessionId),className:`p-3 border rounded-lg cursor-pointer transition-colors ${l.includes(k.sessionId)?"bg-cc-active border-cc-primary":"bg-cc-card border-cc-border hover:border-cc-primary/50"}`,children:r.jsxs("div",{className:"flex items-start justify-between",children:[r.jsxs("div",{className:"flex-1",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[r.jsx("span",{className:"text-sm font-medium text-cc-fg",children:j(k.sessionId)}),r.jsx("span",{className:"px-1.5 py-0.5 text-[10px] bg-cc-hover text-cc-muted rounded",children:k.backendType})]}),k.strengths.length>0&&r.jsx("div",{className:"flex flex-wrap gap-1 mt-1",children:k.strengths.slice(0,5).map(E=>r.jsx("span",{className:"px-1.5 py-0.5 text-[10px] bg-green-500/20 text-green-400 rounded",children:E},E))})]}),r.jsxs("div",{className:"text-xs text-cc-muted text-right",children:[r.jsxs("div",{children:[k.availableTools.length," tools"]}),r.jsxs("div",{children:[k.contextUsedPercent.toFixed(0),"% context"]})]})]})},k.sessionId))})]}),r.jsx("button",{onClick:y,disabled:!n.trim()||l.length===0||h,className:"w-full px-4 py-2 text-sm font-medium text-white bg-cc-primary hover:bg-cc-primary/90 rounded-lg cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed",children:h?"Routing...":"Route Task"})]})}),r.jsx("div",{className:"w-1/2 overflow-y-auto",children:d?r.jsxs("div",{className:"p-6 space-y-4",children:[r.jsxs("div",{children:[r.jsx("h2",{className:"text-base font-semibold text-cc-fg",children:"Routing Result"}),r.jsx("p",{className:"text-sm text-cc-muted mt-1",children:"Best agent for this task"})]}),r.jsxs("div",{className:"p-4 bg-cc-card border-2 border-cc-primary rounded-lg",children:[r.jsxs("div",{className:"flex items-start justify-between mb-2",children:[r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("svg",{className:"w-5 h-5 text-cc-primary",fill:"currentColor",viewBox:"0 0 20 20",children:r.jsx("path",{d:"M9.049 2.927c.3-.921 1.603-.921 1.902 0l1.07 3.292a1 1 0 00.95.69h3.462c.969 0 1.371 1.24.588 1.81l-2.8 2.034a1 1 0 00-.364 1.118l1.07 3.292c.3.921-.755 1.688-1.54 1.118l-2.8-2.034a1 1 0 00-1.175 0l-2.8 2.034c-.784.57-1.838-.197-1.539-1.118l1.07-3.292a1 1 0 00-.364-1.118L2.98 8.72c-.783-.57-.38-1.81.588-1.81h3.461a1 1 0 00.951-.69l1.07-3.292z"})}),r.jsx("span",{className:"text-base font-semibold text-cc-fg",children:j(d.sessionId)})]}),r.jsx("span",{className:"px-2 py-0.5 text-xs bg-cc-hover text-cc-muted rounded inline-block mt-1",children:d.backendType})]}),r.jsxs("div",{className:"text-right",children:[r.jsxs("div",{className:"text-2xl font-bold text-cc-primary",children:[(d.confidence*100).toFixed(0),"%"]}),r.jsx("div",{className:"text-xs text-cc-muted",children:"confidence"})]})]}),r.jsxs("div",{className:"mt-3 p-3 bg-cc-bg rounded border border-cc-border",children:[r.jsx("div",{className:"text-xs font-semibold text-cc-muted mb-1",children:"Reasoning:"}),r.jsx("p",{className:"text-sm text-cc-fg",children:d.reasoning})]})]}),d.alternatives.length>0&&r.jsxs("div",{children:[r.jsx("h3",{className:"text-sm font-medium text-cc-fg mb-2",children:"Alternative Options"}),r.jsx("div",{className:"space-y-2",children:d.alternatives.map((k,E)=>r.jsx("div",{className:"p-3 bg-cc-card border border-cc-border rounded-lg",children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-sm text-cc-fg",children:j(k.sessionId)}),r.jsx("span",{className:"px-1.5 py-0.5 text-[10px] bg-cc-hover text-cc-muted rounded",children:k.backendType})]}),r.jsxs("span",{className:"text-sm font-semibold text-cc-muted",children:[(k.confidence*100).toFixed(0),"%"]})]})},E))})]})]}):r.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-cc-muted",children:[r.jsx("svg",{className:"w-16 h-16 mb-4 opacity-20",fill:"currentColor",viewBox:"0 0 20 20",children:r.jsx("path",{fillRule:"evenodd",d:"M11.3 1.046A1 1 0 0112 2v5h4a1 1 0 01.82 1.573l-7 10A1 1 0 018 18v-5H4a1 1 0 01-.82-1.573l7-10a1 1 0 011.12-.38z",clipRule:"evenodd"})}),r.jsx("p",{className:"text-sm",children:"No routing result yet"}),r.jsx("p",{className:"text-xs text-cc-muted mt-1",children:"Describe a task and route it to see recommendations"})]})})]})}function RH(){const e=Y(S=>S.currentSessionId),[t,s]=w.useState([]),[n,a]=w.useState(null),[l,c]=w.useState(!1),[d,f]=w.useState("stream"),[h,m]=w.useState("");w.useEffect(()=>{if(!e)return;g();const S=setInterval(g,5e3);return()=>clearInterval(S)},[e]);async function g(){if(e){c(!0);try{const[S,j]=await Promise.all([se.getContextStream(e),se.getConsensusState(e)]);s(S.fragments||[]),a(j)}catch(S){console.error("[CollectiveMindPanel] Failed to load context:",S)}finally{c(!1)}}}if(!e)return r.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-cc-muted",children:[r.jsx("svg",{className:"w-16 h-16 mb-4 opacity-20",viewBox:"0 0 24 24",fill:"currentColor",children:r.jsx("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z"})}),r.jsx("p",{className:"text-sm",children:"No session selected"}),r.jsx("p",{className:"text-xs text-cc-muted mt-1",children:"Select a session to view its collective reasoning"})]});const b=Array.from(new Set(t.map(S=>S.type))).sort(),y=[...h?t.filter(S=>S.type===h):t].sort((S,j)=>j.timestamp-S.timestamp);return r.jsxs("div",{className:"flex flex-col h-full bg-cc-bg",children:[r.jsxs("div",{className:"shrink-0 px-4 py-3 border-b border-cc-border",children:[r.jsx("h2",{className:"text-sm font-semibold text-cc-fg mb-3",children:"Collective Mind"}),r.jsxs("div",{className:"flex items-center gap-1 bg-cc-hover rounded-lg p-0.5",children:[r.jsxs("button",{onClick:()=>f("stream"),className:`flex-1 px-3 py-1 text-xs font-medium rounded-md transition-colors cursor-pointer ${d==="stream"?"bg-cc-card text-cc-fg shadow-sm":"text-cc-muted hover:text-cc-fg"}`,children:["Thought Stream (",t.length,")"]}),r.jsx("button",{onClick:()=>f("consensus"),className:`flex-1 px-3 py-1 text-xs font-medium rounded-md transition-colors cursor-pointer ${d==="consensus"?"bg-cc-card text-cc-fg shadow-sm":"text-cc-muted hover:text-cc-fg"}`,children:"Consensus"})]})]}),r.jsxs("div",{className:"flex-1 overflow-y-auto",children:[d==="stream"&&r.jsxs("div",{className:"p-4 space-y-3",children:[b.length>0&&r.jsxs("div",{className:"flex flex-wrap gap-1.5 pb-2 border-b border-cc-border",children:[r.jsx("button",{onClick:()=>m(""),className:`px-2 py-0.5 text-xs rounded cursor-pointer ${h?"bg-cc-hover text-cc-muted hover:text-cc-fg":"bg-cc-primary text-white"}`,children:"All"}),b.map(S=>r.jsx("button",{onClick:()=>m(S),className:`px-2 py-0.5 text-xs rounded cursor-pointer ${h===S?"bg-cc-primary text-white":"bg-cc-hover text-cc-muted hover:text-cc-fg"}`,children:S},S))]}),y.length===0?r.jsx("div",{className:"text-center py-8 text-cc-muted text-sm",children:l?"Loading...":"No thoughts in the stream yet"}):r.jsx("div",{className:"space-y-3",children:y.map(S=>r.jsxs("div",{className:`p-3 rounded-lg border ${S.consensusScore>.7?"bg-green-500/5 border-green-500/30":S.isControversial?"bg-orange-500/5 border-orange-500/30":"bg-cc-card border-cc-border"}`,children:[r.jsxs("div",{className:"flex items-start justify-between mb-2",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("div",{className:`w-2 h-2 rounded-full ${S.isHuman?"bg-blue-400":"bg-purple-400"}`}),r.jsxs("span",{className:"text-xs text-cc-muted",children:[S.isHuman?"Human":"Agent"," · ",S.agentId.slice(0,8)]}),r.jsx("span",{className:`px-1.5 py-0.5 text-[10px] font-medium rounded ${S.type==="thought"?"bg-purple-500/20 text-purple-400":S.type==="observation"?"bg-blue-500/20 text-blue-400":S.type==="plan"?"bg-green-500/20 text-green-400":S.type==="question"?"bg-yellow-500/20 text-yellow-400":S.type==="answer"?"bg-teal-500/20 text-teal-400":S.type==="insight"?"bg-pink-500/20 text-pink-400":"bg-red-500/20 text-red-400"}`,children:S.type}),r.jsx("span",{className:"text-xs text-cc-muted",children:new Date(S.timestamp).toLocaleTimeString()})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[S.consensusScore>0&&r.jsxs("span",{className:"text-xs text-cc-muted font-mono",children:[(S.consensusScore*100).toFixed(0),"% agree"]}),S.isControversial&&r.jsx("span",{className:"text-xs text-orange-400",children:"⚠ Controversial"})]})]}),r.jsx("p",{className:"text-sm text-cc-fg mb-2",children:S.content}),S.semanticLinks.length>0&&r.jsx("div",{className:"flex flex-wrap gap-1 mt-2",children:S.semanticLinks.map((j,k)=>r.jsxs("span",{className:`px-1.5 py-0.5 text-[10px] rounded ${j.relation==="agrees_with"?"bg-green-500/20 text-green-400":j.relation==="disagrees_with"?"bg-red-500/20 text-red-400":j.relation==="builds_on"?"bg-blue-500/20 text-blue-400":j.relation==="contradicts"?"bg-orange-500/20 text-orange-400":"bg-yellow-500/20 text-yellow-400"}`,children:[j.relation.replace("_"," ")," #",j.targetFragmentId.slice(0,6)]},k))}),S.parentId&&r.jsxs("div",{className:"mt-2 text-xs text-cc-muted",children:["↳ Reply to #",S.parentId.slice(0,8)]})]},S.fragmentId))})]}),d==="consensus"&&r.jsx("div",{className:"p-4 space-y-4",children:n?r.jsxs(r.Fragment,{children:[n.consensusPoints.length>0&&r.jsxs("div",{children:[r.jsxs("h3",{className:"text-sm font-semibold text-cc-fg mb-2 flex items-center gap-2",children:[r.jsx("span",{className:"w-2 h-2 rounded-full bg-green-400"}),"Consensus Points (",n.consensusPoints.length,")"]}),r.jsx("div",{className:"space-y-2",children:n.consensusPoints.map(S=>{const j=t.find(k=>k.fragmentId===S);return j?r.jsxs("div",{className:"p-2 bg-green-500/5 border border-green-500/30 rounded text-sm",children:[r.jsx("div",{className:"text-cc-fg",children:j.content}),r.jsxs("div",{className:"text-xs text-cc-muted mt-1",children:[(j.consensusScore*100).toFixed(0),"% agreement"]})]},S):null})})]}),n.disagreements.length>0&&r.jsxs("div",{children:[r.jsxs("h3",{className:"text-sm font-semibold text-cc-fg mb-2 flex items-center gap-2",children:[r.jsx("span",{className:"w-2 h-2 rounded-full bg-orange-400"}),"Disagreements (",n.disagreements.length,")"]}),r.jsx("div",{className:"space-y-2",children:n.disagreements.map((S,j)=>r.jsxs("div",{className:"p-3 bg-orange-500/5 border border-orange-500/30 rounded",children:[r.jsx("div",{className:"text-sm font-medium text-cc-fg mb-1",children:S.topic}),r.jsx("div",{className:"text-sm text-cc-muted mb-2",children:S.summary}),r.jsxs("div",{className:"text-xs text-cc-muted",children:[S.fragmentIds.length," conflicting thoughts"]})]},j))})]}),n.openQuestions.length>0&&r.jsxs("div",{children:[r.jsxs("h3",{className:"text-sm font-semibold text-cc-fg mb-2 flex items-center gap-2",children:[r.jsx("span",{className:"w-2 h-2 rounded-full bg-yellow-400"}),"Open Questions (",n.openQuestions.length,")"]}),r.jsx("div",{className:"space-y-2",children:n.openQuestions.map(S=>{const j=t.find(k=>k.fragmentId===S);return j?r.jsxs("div",{className:"p-2 bg-yellow-500/5 border border-yellow-500/30 rounded text-sm",children:[r.jsx("div",{className:"text-cc-fg",children:j.content}),r.jsxs("div",{className:"text-xs text-cc-muted mt-1",children:["Asked by ",j.isHuman?"human":"agent"," · No answers yet"]})]},S):null})})]}),n.consensusPoints.length===0&&n.disagreements.length===0&&n.openQuestions.length===0&&r.jsx("div",{className:"text-center py-8 text-cc-muted text-sm",children:"No consensus data available yet"})]}):r.jsx("div",{className:"text-center py-8 text-cc-muted text-sm",children:l?"Loading...":"No consensus data yet"})})]})]})}function g0(e){if(e<1e3)return`${e}ms`;const t=Math.floor(e/1e3);return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`}function x0(e){return e===0?"$0":e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}const v0={pending:"text-cc-muted",running:"text-cc-primary",completed:"text-cc-success",failed:"text-cc-error",cancelled:"text-cc-warning",skipped:"text-cc-muted/50"},DH={pending:"bg-cc-muted/30",running:"bg-cc-primary animate-pulse",completed:"bg-cc-success",failed:"bg-cc-error",cancelled:"bg-cc-warning",skipped:"bg-cc-muted/20"};function LH({stage:e,index:t,onChange:s,onRemove:n}){return r.jsxs("div",{className:"border border-cc-border rounded-lg p-3 space-y-2",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("span",{className:"text-[11px] font-mono-code text-cc-muted",children:["Stage ",t+1]}),r.jsx("button",{onClick:n,className:"text-[10px] text-cc-error hover:text-cc-error/80 transition-colors",children:"Remove"})]}),r.jsx("input",{type:"text",value:e.name,onChange:a=>s({...e,name:a.target.value}),placeholder:"Stage name (e.g. Implement feature)",className:"w-full px-2.5 py-1.5 text-[12px] bg-cc-input-bg border border-cc-border rounded-md text-cc-fg placeholder:text-cc-muted/40 focus:outline-none focus:border-cc-muted/30"}),r.jsx("textarea",{value:e.prompt,onChange:a=>s({...e,prompt:a.target.value}),placeholder:"Prompt for this stage...",rows:3,className:"w-full px-2.5 py-1.5 text-[12px] bg-cc-input-bg border border-cc-border rounded-md text-cc-fg placeholder:text-cc-muted/40 focus:outline-none focus:border-cc-muted/30 resize-none font-mono-code"}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("select",{value:e.backend,onChange:a=>s({...e,backend:a.target.value}),className:"px-2 py-1 text-[11px] bg-cc-input-bg border border-cc-border rounded-md text-cc-fg focus:outline-none",children:[r.jsx("option",{value:"claude",children:"Claude Code"}),r.jsx("option",{value:"codex",children:"Codex"}),r.jsx("option",{value:"goose",children:"Goose"}),r.jsx("option",{value:"aider",children:"Aider"})]}),r.jsxs("label",{className:"flex items-center gap-1.5 text-[11px] text-cc-muted cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:e.inheritContext??!0,onChange:a=>s({...e,inheritContext:a.target.checked}),className:"rounded"}),"Pass context from previous stage"]})]})]})}function BH({onSave:e,onCancel:t}){const[s,n]=w.useState(""),[a,l]=w.useState(""),[c,d]=w.useState(""),[f,h]=w.useState([{name:"Implement",prompt:"",backend:"claude",inheritContext:!1},{name:"Test",prompt:"Run the test suite and fix any failures.",backend:"claude",inheritContext:!0},{name:"Review",prompt:"Review the changes for code quality, security, and best practices.",backend:"claude",inheritContext:!0}]),[m,g]=w.useState(!1);w.useEffect(()=>{se.getHome().then(y=>d(y.cwd)).catch(()=>{})},[]);const b=()=>{h([...f,{name:"",prompt:"",backend:"claude",inheritContext:!0}])},v=async()=>{if(!(!s.trim()||!c.trim()||f.length===0)){g(!0);try{const y=await se.createPipeline({name:s.trim(),description:a.trim()||void 0,cwd:c,stages:f});e(y)}catch(y){console.error("Failed to create pipeline:",y)}g(!1)}};return r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("h2",{className:"text-[14px] font-semibold text-cc-fg",children:"Create Pipeline"}),r.jsx("button",{onClick:t,className:"text-[11px] text-cc-muted hover:text-cc-fg transition-colors",children:"Cancel"})]}),r.jsxs("div",{className:"space-y-3",children:[r.jsx("input",{type:"text",value:s,onChange:y=>n(y.target.value),placeholder:"Pipeline name",className:"w-full px-3 py-2 text-[13px] bg-cc-input-bg border border-cc-border rounded-lg text-cc-fg placeholder:text-cc-muted/40 focus:outline-none focus:border-cc-muted/30"}),r.jsx("input",{type:"text",value:a,onChange:y=>l(y.target.value),placeholder:"Description (optional)",className:"w-full px-3 py-2 text-[13px] bg-cc-input-bg border border-cc-border rounded-lg text-cc-fg placeholder:text-cc-muted/40 focus:outline-none focus:border-cc-muted/30"}),r.jsx("input",{type:"text",value:c,onChange:y=>d(y.target.value),placeholder:"Working directory",className:"w-full px-3 py-2 text-[13px] bg-cc-input-bg border border-cc-border rounded-lg text-cc-fg placeholder:text-cc-muted/40 focus:outline-none focus:border-cc-muted/30 font-mono-code"})]}),r.jsxs("div",{className:"space-y-2",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-[12px] font-medium text-cc-fg",children:"Stages"}),r.jsx("button",{onClick:b,className:"text-[11px] text-cc-primary hover:text-cc-primary-hover transition-colors",children:"+ Add Stage"})]}),f.map((y,S)=>r.jsx(LH,{stage:y,index:S,onChange:j=>{const k=[...f];k[S]=j,h(k)},onRemove:()=>h(f.filter((j,k)=>k!==S))},S))]}),r.jsx("button",{onClick:v,disabled:m||!s.trim()||!c.trim()||f.length===0,className:"w-full py-2 rounded-lg text-[13px] font-medium transition-colors bg-cc-fg text-cc-bg hover:opacity-80 disabled:opacity-30 disabled:cursor-not-allowed",children:m?"Creating...":"Create Pipeline"})]})}function OH({runId:e,onBack:t}){const[s,n]=w.useState(null),a=w.useCallback(async()=>{try{const l=await se.getRun(e);return n(l),l.status==="running"||l.status==="pending"}catch{return!1}},[e]);return w.useEffect(()=>{let l=!0;const c=async()=>{const d=await a();l&&d&&setTimeout(c,2e3)};return c(),()=>{l=!1}},[a]),s?r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("button",{onClick:t,className:"text-[11px] text-cc-muted hover:text-cc-fg transition-colors flex items-center gap-1",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3",children:r.jsx("path",{d:"M7.78 12.53a.75.75 0 01-1.06 0L2.47 8.28a.75.75 0 010-1.06l4.25-4.25a.75.75 0 011.06 1.06L4.81 7h7.44a.75.75 0 010 1.5H4.81l2.97 2.97a.75.75 0 010 1.06z"})}),"Back"]}),r.jsx("span",{className:`text-[11px] font-mono-code ${v0[s.status]}`,children:s.status})]}),r.jsxs("div",{children:[r.jsx("h3",{className:"text-[14px] font-semibold text-cc-fg",children:s.pipelineName}),r.jsxs("div",{className:"flex items-center gap-3 mt-1 text-[11px] text-cc-muted font-mono-code",children:[r.jsx("span",{children:g0(s.totalDurationMs)}),r.jsx("span",{children:x0(s.totalCostUsd)})]})]}),r.jsx("div",{className:"space-y-0",children:s.stageResults.map((l,c)=>r.jsxs("div",{className:"flex items-start gap-3 relative",children:[c<s.stageResults.length-1&&r.jsx("div",{className:"absolute left-[7px] top-[18px] bottom-0 w-px bg-cc-border"}),r.jsx("div",{className:`w-[15px] h-[15px] rounded-full border-2 border-cc-bg shrink-0 mt-0.5 ${DH[l.status]}`}),r.jsxs("div",{className:"flex-1 pb-4",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("span",{className:"text-[12px] font-medium text-cc-fg",children:["Stage ",c+1]}),r.jsxs("span",{className:`text-[10px] font-mono-code ${v0[l.status]}`,children:[l.status,l.durationMs?` · ${g0(l.durationMs)}`:"",l.costUsd?` · ${x0(l.costUsd)}`:""]})]}),l.sessionId&&r.jsx("a",{href:`#/?session=${l.sessionId}`,className:"text-[10px] text-cc-primary hover:text-cc-primary-hover font-mono-code mt-0.5 inline-block",children:"View session"}),l.error&&r.jsx("p",{className:"text-[10px] text-cc-error mt-1 font-mono-code",children:l.error}),l.outputSummary&&r.jsx("p",{className:"text-[10px] text-cc-muted mt-1 line-clamp-2",children:l.outputSummary})]})]},l.stageId))}),s.status==="running"&&r.jsx("button",{onClick:async()=>{await se.cancelRun(s.id),a()},className:"w-full py-2 rounded-lg text-[12px] bg-cc-error/10 text-cc-error hover:bg-cc-error/20 transition-colors",children:"Cancel Run"})]}):r.jsx("div",{className:"text-[13px] text-cc-muted p-6 text-center",children:"Loading run..."})}function zH(){const[e,t]=w.useState("list"),[s,n]=w.useState([]),[a,l]=w.useState([]),[c,d]=w.useState(null),[f,h]=w.useState(!0),m=w.useCallback(async()=>{try{const[g,b]=await Promise.all([se.listPipelines(),se.listRuns()]);n(g),l(b)}catch{}h(!1)},[]);return w.useEffect(()=>{m()},[m]),e==="create"?r.jsx("div",{className:"flex-1 overflow-y-auto p-6",children:r.jsx("div",{className:"max-w-2xl mx-auto",children:r.jsx(BH,{onSave:()=>{m(),t("list")},onCancel:()=>t("list")})})}):e==="run-view"&&c?r.jsx("div",{className:"flex-1 overflow-y-auto p-6",children:r.jsx("div",{className:"max-w-2xl mx-auto",children:r.jsx(OH,{runId:c,onBack:()=>{t("list"),m()}})})}):r.jsx("div",{className:"flex-1 overflow-y-auto p-6",children:r.jsxs("div",{className:"max-w-2xl mx-auto space-y-6",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("h1",{className:"text-[16px] font-semibold text-cc-fg",children:"Orchestrator"}),r.jsx("p",{className:"text-[12px] text-cc-muted mt-0.5",children:"Chain multiple AI sessions into multi-stage pipelines"})]}),r.jsx("button",{onClick:()=>t("create"),className:"px-3 py-1.5 rounded-lg text-[12px] font-medium bg-cc-fg text-cc-bg hover:opacity-80 transition-colors",children:"New Pipeline"})]}),f?r.jsx("div",{className:"text-center py-8 text-[13px] text-cc-muted",children:"Loading..."}):r.jsxs(r.Fragment,{children:[s.length===0?r.jsxs("div",{className:"text-center py-12 border border-dashed border-cc-border rounded-lg",children:[r.jsx("p",{className:"text-[13px] text-cc-muted",children:"No pipelines yet"}),r.jsx("p",{className:"text-[11px] text-cc-muted/60 mt-1",children:"Create a pipeline to chain AI sessions into multi-stage workflows"})]}):r.jsxs("div",{className:"space-y-2",children:[r.jsx("h2",{className:"text-[12px] text-cc-muted uppercase tracking-wider font-medium",children:"Pipelines"}),s.map(g=>r.jsx("div",{className:"border border-cc-border rounded-lg p-3 hover:bg-cc-hover/30 transition-colors",children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("span",{className:"text-[13px] font-medium text-cc-fg",children:g.name}),g.description&&r.jsx("p",{className:"text-[11px] text-cc-muted mt-0.5",children:g.description}),r.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[r.jsxs("span",{className:"text-[10px] text-cc-muted/60 font-mono-code",children:[g.stages.length," stages"]}),r.jsx("span",{className:"text-[10px] text-cc-muted/60 font-mono-code",children:g.cwd})]})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("button",{onClick:async()=>{try{const b=await se.runPipeline(g.id);d(b.id),t("run-view")}catch(b){console.error("Failed to run pipeline:",b)}},className:"px-2.5 py-1 rounded-md text-[11px] bg-cc-primary/10 text-cc-primary hover:bg-cc-primary/20 transition-colors",children:"Run"}),r.jsx("button",{onClick:async()=>{await se.deletePipeline(g.id),m()},className:"px-2 py-1 rounded-md text-[11px] text-cc-muted hover:text-cc-error transition-colors",children:"Delete"})]})]})},g.id))]}),a.length>0&&r.jsxs("div",{className:"space-y-2",children:[r.jsx("h2",{className:"text-[12px] text-cc-muted uppercase tracking-wider font-medium",children:"Recent Runs"}),a.slice(0,10).map(g=>r.jsxs("button",{onClick:()=>{d(g.id),t("run-view")},className:"w-full border border-cc-border rounded-lg p-3 hover:bg-cc-hover/30 transition-colors text-left",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-[12px] font-medium text-cc-fg",children:g.pipelineName}),r.jsx("span",{className:`text-[10px] font-mono-code ${v0[g.status]}`,children:g.status})]}),r.jsxs("div",{className:"flex items-center gap-3 mt-1 text-[10px] text-cc-muted font-mono-code",children:[r.jsx("span",{children:g0(g.totalDurationMs)}),r.jsx("span",{children:x0(g.totalCostUsd)}),r.jsxs("span",{children:[g.stageResults.filter(b=>b.status==="completed").length,"/",g.stageResults.length," stages"]}),r.jsx("span",{children:new Date(g.startedAt).toLocaleDateString()})]})]},g.id))]})]})]})})}function PH(e){if(!e)return"-";const t=Math.round(e/1e3);return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`}function $H(e){return e?e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`:"$0"}function IH(e){return e==="completed"?"text-cc-success":e==="failed"||e==="timeout"?"text-cc-error":e==="running"?"text-cc-primary":"text-cc-muted"}function FH({race:e,onUpdate:t}){const s=Y(h=>h.setCurrentSession),[n,a]=w.useState(new Map),[l,c]=w.useState(null),d=async h=>{const m=await se.pickRaceWinner(e.raceId,h);t(m)},f=async h=>{c(h.id);try{const m=await se.getRaceEntryDiff(e.raceId,h.id);a(g=>new Map(g).set(h.id,m.diff||""))}finally{c(null)}};return r.jsx("div",{className:"grid grid-cols-1 xl:grid-cols-3 gap-3",children:e.entries.map(h=>{var m,g,b,v,y,S;return r.jsxs("div",{className:"rounded-lg border border-cc-border bg-cc-card overflow-hidden",children:[r.jsxs("div",{className:"px-3 py-2.5 border-b border-cc-border/50 flex items-center justify-between",children:[r.jsxs("div",{className:"min-w-0",children:[r.jsx("div",{className:"text-[13px] font-semibold text-cc-fg truncate",children:h.backendType}),r.jsx("div",{className:`text-[10px] uppercase font-mono-code ${IH(h.status)}`,children:h.status})]}),r.jsx("button",{disabled:h.status!=="completed"||e.winnerId===h.sessionId,onClick:()=>void d(h.sessionId),className:"px-2 py-1 rounded-md text-[11px] bg-cc-fg text-cc-bg disabled:opacity-30 disabled:cursor-not-allowed",children:e.winnerId===h.sessionId?"Selected":"Merge"})]}),r.jsxs("div",{className:"px-3 py-2.5 grid grid-cols-2 gap-2 text-[11px]",children:[r.jsx(eh,{label:"Time",value:PH((m=h.metrics)==null?void 0:m.wallClockMs)}),r.jsx(eh,{label:"Cost",value:$H((g=h.metrics)==null?void 0:g.costUsd)}),r.jsx(eh,{label:"Files",value:String(((b=h.metrics)==null?void 0:b.filesChanged)??0)}),r.jsx(eh,{label:"Lines",value:`+${((v=h.metrics)==null?void 0:v.linesAdded)??0} -${((y=h.metrics)==null?void 0:y.linesRemoved)??0}`})]}),r.jsxs("div",{className:"px-3 pb-3",children:[r.jsx("div",{className:"text-[10px] text-cc-muted uppercase tracking-wider mb-1",children:"Summary"}),r.jsx("p",{className:"min-h-20 max-h-40 overflow-auto rounded-md bg-cc-bg/60 px-2 py-1.5 text-[11px] text-cc-muted whitespace-pre-wrap",children:h.error||h.outputSummary||(h.status==="skipped"?"Skipped — an earlier cascade entry succeeded.":"No output yet.")})]}),r.jsxs("div",{className:"px-3 pb-3",children:[r.jsxs("div",{className:"flex items-center justify-between mb-1",children:[r.jsx("div",{className:"text-[10px] text-cc-muted uppercase tracking-wider",children:"Diff"}),r.jsx("button",{onClick:()=>void f(h),className:"text-[10px] text-cc-primary hover:text-cc-primary-hover",children:l===h.id?"Loading...":"Load"})]}),n.has(h.id)?n.get(h.id)?r.jsx("div",{className:"max-h-72 overflow-auto rounded-md border border-cc-border/50",children:r.jsx(yr,{unifiedDiff:n.get(h.id),fileName:h.branch,mode:"compact"})}):r.jsx("p",{className:"rounded-md bg-cc-bg/60 px-2 py-1.5 text-[11px] text-cc-muted",children:"No diff for this entry."}):r.jsx("p",{className:"rounded-md bg-cc-bg/60 px-2 py-1.5 text-[11px] text-cc-muted",children:(S=h.filesChanged)!=null&&S.length?`${h.filesChanged.length} changed files`:"No changed files recorded yet."})]}),r.jsxs("button",{onClick:()=>{s(h.sessionId),kr(h.sessionId),window.location.hash=""},className:"w-full border-t border-cc-border/50 px-3 py-2 text-left text-[11px] text-cc-muted hover:text-cc-fg hover:bg-cc-hover",children:["Open session ",h.sessionId.slice(0,8)]})]},h.id)})})}function eh({label:e,value:t}){return r.jsxs("div",{className:"rounded-md bg-cc-bg/60 px-2 py-1.5",children:[r.jsx("div",{className:"text-[9px] text-cc-muted uppercase tracking-wider",children:e}),r.jsx("div",{className:"text-[12px] text-cc-fg font-mono-code",children:t})]})}const HH=[{id:"claude",label:"Claude"},{id:"codex",label:"Codex"},{id:"goose",label:"Goose"},{id:"aider",label:"Aider"},{id:"openhands",label:"OpenHands"}];function UH(){var I;const e=typeof window<"u"?(I=window.location.hash.match(/^#\/races\/([^/?#]+)/))==null?void 0:I[1]:void 0,[t,s]=w.useState([]),[n,a]=w.useState(e?decodeURIComponent(e):null),[l,c]=w.useState(""),[d,f]=w.useState(""),[h,m]=w.useState(["claude","codex"]),[g,b]=w.useState(!1),[v,y]=w.useState([]),[S,j]=w.useState(()=>{try{return localStorage.getItem("cc-selected-env")||""}catch{return""}}),[k,E]=w.useState(null),[N,B]=w.useState(!1),A=w.useMemo(()=>t.find(H=>H.raceId===n)||t[0]||null,[t,n]),P=w.useCallback(async()=>{const H=await se.listRaces();s(H),!n&&H[0]&&a(e?decodeURIComponent(e):H[0].raceId)},[n]);w.useEffect(()=>{se.getHome().then(async H=>{try{const F=await se.getRepoInfo(H.cwd);c(F.repoRoot)}catch{c(H.cwd)}}).catch(()=>{}),se.listEnvs().then(y).catch(()=>{}),P()},[P]),w.useEffect(()=>{if(!((A==null?void 0:A.status)==="running"))return;const F=setInterval(()=>void P(),2e3);return()=>clearInterval(F)},[P,A==null?void 0:A.status]);const K=H=>{m(F=>F.includes(H)?F.filter(G=>G!==H):[...F,H])},X=async()=>{E(null),B(!0);try{const H=await se.createRace({prompt:d,repoRoot:l,backends:h,envSlug:S||void 0,cascade:g||void 0});s(F=>[H,...F]),a(H.raceId),window.location.hash=`#/races/${encodeURIComponent(H.raceId)}`,f("")}catch(H){E(H instanceof Error?H.message:String(H))}finally{B(!1)}},Z=async H=>{const F=await se.cancelRace(H);s(G=>G.map(q=>q.raceId===F.raceId?F:q))};return r.jsx("div",{className:"h-full overflow-auto bg-cc-bg",children:r.jsxs("div",{className:"max-w-6xl mx-auto p-4 space-y-4",children:[r.jsx("div",{className:"flex items-center justify-between",children:r.jsxs("div",{children:[r.jsx("h1",{className:"text-[18px] font-semibold text-cc-fg",children:"Agent Races"}),r.jsx("p",{className:"text-[12px] text-cc-muted",children:"Run the same task in isolated worktrees and compare the results."})]})}),r.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-[360px_1fr] gap-4",children:[r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{className:"rounded-lg border border-cc-border bg-cc-card p-3 space-y-3",children:[r.jsx("input",{value:l,onChange:H=>c(H.target.value),placeholder:"Repository root",className:"w-full px-2.5 py-2 rounded-md border border-cc-border bg-cc-input-bg text-[12px] text-cc-fg font-mono-code"}),r.jsx("textarea",{value:d,onChange:H=>f(H.target.value),placeholder:"Task prompt",rows:5,className:"w-full px-2.5 py-2 rounded-md border border-cc-border bg-cc-input-bg text-[12px] text-cc-fg resize-none"}),r.jsx("div",{className:"grid grid-cols-2 gap-2",children:HH.map(H=>r.jsxs("label",{className:"flex items-center gap-2 rounded-md border border-cc-border px-2 py-1.5 text-[11px] text-cc-fg",children:[r.jsx("input",{type:"checkbox",checked:h.includes(H.id),onChange:()=>K(H.id)}),H.label]},H.id))}),r.jsxs("label",{className:"flex items-start gap-2 rounded-md border border-cc-border px-2 py-1.5 text-[11px] text-cc-fg",children:[r.jsx("input",{type:"checkbox",checked:g,onChange:()=>b(H=>!H),className:"mt-0.5"}),r.jsxs("span",{children:["Cost cascade — run backends in order, stop at first success",r.jsx("span",{className:"block text-[10px] text-cc-muted",children:"List cheapest first; failures and empty patches escalate to the next backend."})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-[10px] font-semibold text-cc-muted/60 uppercase tracking-wider mb-1.5",htmlFor:"race-env-select",children:"Environment"}),r.jsxs("div",{className:"flex gap-1",children:[r.jsxs("select",{id:"race-env-select",value:S,onChange:H=>{j(H.target.value);try{localStorage.setItem("cc-selected-env",H.target.value)}catch{}},onFocus:()=>{se.listEnvs().then(y).catch(()=>{})},className:"flex-1 min-w-0 px-2.5 py-2 rounded-md border border-cc-border bg-cc-input-bg text-[12px] text-cc-fg focus:outline-none focus:border-cc-primary/50 cursor-pointer",children:[r.jsx("option",{value:"",children:"No environment"}),v.map(H=>r.jsxs("option",{value:H.slug,children:[H.name," (",Object.keys(H.variables).length," vars)"]},H.slug))]}),r.jsx("button",{type:"button",onClick:()=>{window.location.hash="#/environments"},"aria-label":"Manage environments",className:"px-2.5 py-2 rounded-md border border-cc-border bg-cc-input-bg text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer shrink-0",children:r.jsxs("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3",children:[r.jsx("path",{d:"M8 4.754a3.246 3.246 0 100 6.492 3.246 3.246 0 000-6.492zM5.754 8a2.246 2.246 0 114.492 0 2.246 2.246 0 01-4.492 0z"}),r.jsx("path",{d:"M9.796 1.343c-.527-1.79-3.065-1.79-3.592 0a1.843 1.843 0 01-2.739 1.049c-1.547-.966-3.317.803-2.35 2.35a1.843 1.843 0 01-1.049 2.74c-1.79.526-1.79 3.064 0 3.59a1.843 1.843 0 011.049 2.74c-.966 1.547.803 3.317 2.35 2.35a1.843 1.843 0 012.74 1.049c.526 1.79 3.064 1.79 3.59 0a1.843 1.843 0 012.74-1.049c1.547.966 3.317-.803 2.35-2.35a1.843 1.843 0 011.049-2.74c1.79-.526 1.79-3.064 0-3.59a1.843 1.843 0 01-1.049-2.74c.966-1.547-.803-3.317-2.35-2.35a1.843 1.843 0 01-2.74-1.049z"})]})})]})]}),k&&r.jsx("div",{className:"text-[11px] text-cc-error",children:k}),r.jsx("button",{onClick:()=>void X(),disabled:N||!d.trim()||!l.trim()||h.length<2,className:"w-full rounded-md bg-cc-fg text-cc-bg px-3 py-2 text-[12px] font-medium disabled:opacity-30 disabled:cursor-not-allowed",children:N?"Starting...":"Start Race"})]}),r.jsxs("div",{className:"rounded-lg border border-cc-border bg-cc-card overflow-hidden",children:[t.map(H=>r.jsxs("button",{onClick:()=>{a(H.raceId),window.location.hash=`#/races/${encodeURIComponent(H.raceId)}`},className:`w-full text-left px-3 py-2 border-b border-cc-border/40 hover:bg-cc-hover ${(A==null?void 0:A.raceId)===H.raceId?"bg-cc-hover":""}`,children:[r.jsx("div",{className:"text-[12px] text-cc-fg truncate",children:H.prompt}),r.jsxs("div",{className:"text-[10px] text-cc-muted uppercase font-mono-code",children:[H.status," / ",H.entries.length," agents",H.cascade?" / cascade":""]})]},H.raceId)),t.length===0&&r.jsx("div",{className:"px-3 py-5 text-[12px] text-cc-muted",children:"No races yet."})]})]}),r.jsx("div",{className:"space-y-3",children:A?r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"rounded-lg border border-cc-border bg-cc-card p-3 flex items-center justify-between gap-3",children:[r.jsxs("div",{className:"min-w-0",children:[r.jsx("div",{className:"text-[13px] font-semibold text-cc-fg truncate",children:A.prompt}),r.jsxs("div",{className:"text-[10px] text-cc-muted font-mono-code uppercase",children:[A.status," on ",A.baseBranch,A.cascade?" / cascade":""]})]}),A.status==="running"&&r.jsx("button",{onClick:()=>void Z(A.raceId),className:"px-2 py-1 rounded-md text-[11px] text-cc-error border border-cc-error/40",children:"Cancel"})]}),r.jsx(FH,{race:A,onUpdate:H=>s(F=>F.map(G=>G.raceId===H.raceId?H:G))})]}):r.jsx("div",{className:"rounded-lg border border-cc-border bg-cc-card p-6 text-[12px] text-cc-muted",children:"Start a race to compare agents."})})]})]})})}const VH={pending:{label:"To Do",emptyText:"No pending tasks",dotColor:"bg-cc-muted/40",headerColor:"text-cc-muted"},in_progress:{label:"In Progress",emptyText:"Nothing in progress",dotColor:"bg-cc-primary animate-pulse",headerColor:"text-cc-primary"},completed:{label:"Done",emptyText:"Nothing completed yet",dotColor:"bg-cc-success",headerColor:"text-cc-success"}};function WH({task:e}){const t=e.blockedBy&&e.blockedBy.length>0;return r.jsxs("div",{className:`p-3 rounded-lg border transition-colors ${t?"border-cc-border/50 bg-cc-hover/30 opacity-60":"border-cc-border bg-cc-card hover:border-cc-muted/20"}`,children:[r.jsx("div",{className:"flex items-start gap-2",children:r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-[12px] font-medium text-cc-fg leading-tight",children:e.subject}),e.description&&e.description!==e.subject&&r.jsx("p",{className:"text-[10px] text-cc-muted mt-1 line-clamp-2 leading-relaxed",children:e.description})]})}),r.jsxs("div",{className:"flex items-center gap-2 mt-2 flex-wrap",children:[e.owner&&r.jsx("span",{className:"text-[9px] font-mono-code px-1.5 py-0.5 rounded bg-cc-hover text-cc-muted",children:e.owner}),e.activeForm&&e.status==="in_progress"&&r.jsx("span",{className:"text-[9px] font-mono-code px-1.5 py-0.5 rounded bg-cc-primary/10 text-cc-primary",children:e.activeForm}),t&&r.jsx("span",{className:"text-[9px] font-mono-code px-1.5 py-0.5 rounded bg-cc-warning/10 text-cc-warning",children:"blocked"}),r.jsxs("span",{className:"text-[9px] font-mono-code text-cc-muted/40 ml-auto",children:["#",e.id]})]})]})}function Bg({column:e,tasks:t}){const s=VH[e];return r.jsxs("div",{className:"flex-1 min-w-[250px] max-w-[400px]",children:[r.jsxs("div",{className:"flex items-center gap-2 px-1 pb-3 border-b border-cc-border",children:[r.jsx("div",{className:`w-2 h-2 rounded-full ${s.dotColor}`}),r.jsx("span",{className:`text-[12px] font-semibold ${s.headerColor}`,children:s.label}),r.jsx("span",{className:"text-[10px] text-cc-muted/50 font-mono-code tabular-nums ml-auto",children:t.length})]}),r.jsx("div",{className:"space-y-2 pt-3 min-h-[100px]",children:t.length===0?r.jsx("div",{className:"text-[11px] text-cc-muted/40 italic text-center py-6",children:s.emptyText}):t.map(n=>r.jsx(WH,{task:n},n.id))})]})}function qH(){var f;const e=Y(h=>h.currentSessionId),t=Y(h=>h.sessionTasks),s=Y(h=>h.sessionNames),n=Y(h=>h.sdkSessions),{grouped:a,totalCount:l,sessionId:c}=w.useMemo(()=>{const h=[],m=[],g=[],b=e?[[e,t.get(e)||[]]]:Array.from(t.entries());for(const[,v]of b)for(const y of v)y.status==="completed"?g.push(y):y.status==="in_progress"?m.push(y):h.push(y);return{grouped:{pending:h,in_progress:m,completed:g},totalCount:h.length+m.length+g.length,sessionId:e}},[t,e]),d=c?s.get(c)||((f=n.find(h=>h.sessionId===c))==null?void 0:f.name)||c.slice(0,8):null;return r.jsx("div",{className:"flex-1 overflow-y-auto p-6",children:r.jsxs("div",{className:"max-w-5xl mx-auto space-y-6",children:[r.jsxs("div",{children:[r.jsx("h1",{className:"text-[16px] font-semibold text-cc-fg",children:"Task Board"}),r.jsx("p",{className:"text-[12px] text-cc-muted mt-0.5",children:d?`Tasks from session: ${d}`:"Tasks extracted from agent tool calls (TodoWrite, TaskCreate)"})]}),l===0?r.jsxs("div",{className:"text-center py-16 border border-dashed border-cc-border rounded-lg",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-8 h-8 mx-auto text-cc-muted/20 mb-3",children:r.jsx("path",{d:"M1.5 3.25a2.25 2.25 0 013-2.122V1A2.5 2.5 0 017 3.5H3.25a.75.75 0 010-1.5h3.06A1 1 0 005.5 1.5h-1a.75.75 0 01-.75-.75.75.75 0 00-1.5 0v.5h-.5a.25.25 0 00-.25.25zm13 0v.5a.25.25 0 01-.25.25H8V1h.75a.75.75 0 01.75.75.75.75 0 001.5 0h-1a1 1 0 00-.81.5h3.06a.75.75 0 010 1.5H9A2.5 2.5 0 0111.5 1v.128a2.25 2.25 0 013 2.122zM1.5 5v8.25c0 .966.784 1.75 1.75 1.75h9.5A1.75 1.75 0 0014.5 13.25V5h-13z"})}),r.jsx("p",{className:"text-[13px] text-cc-muted",children:"No tasks yet"}),r.jsx("p",{className:"text-[11px] text-cc-muted/60 mt-1",children:"Tasks appear here when agents use TodoWrite or TaskCreate tools"})]}):r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"flex items-center gap-4 text-[11px] font-mono-code",children:[r.jsxs("span",{className:"text-cc-muted",children:[a.completed.length,"/",l," complete"]}),a.in_progress.length>0&&r.jsxs("span",{className:"text-cc-primary",children:[a.in_progress.length," in progress"]}),r.jsx("div",{className:"flex-1 h-1 rounded-full bg-cc-hover overflow-hidden max-w-[200px]",children:r.jsx("div",{className:"h-full rounded-full bg-cc-success transition-all duration-500",style:{width:`${a.completed.length/l*100}%`}})})]}),r.jsxs("div",{className:"flex gap-4 overflow-x-auto pb-4",children:[r.jsx(Bg,{column:"pending",tasks:a.pending}),r.jsx(Bg,{column:"in_progress",tasks:a.in_progress}),r.jsx(Bg,{column:"completed",tasks:a.completed})]})]})]})})}function GH({embedded:e}){const[t,s]=w.useState([]),[n,a]=w.useState(!0),[l,c]=w.useState(""),[d,f]=w.useState(null),[h,m]=w.useState({}),[g,b]=w.useState(null);w.useEffect(()=>{v()},[]);async function v(){a(!0),c("");try{const E=await se.listPlugins();s(E)}catch(E){c(E instanceof Error?E.message:"Failed to load plugins")}finally{a(!1)}}async function y(E){b(E.id);try{const N=await se.togglePlugin(E.id,!E.disabledInCampfire);s(B=>B.map(A=>A.id===E.id?{...A,disabledInCampfire:N.disabled}:A))}catch(N){c(N instanceof Error?N.message:"Failed to toggle plugin")}finally{b(null)}}async function S(E,N){const B=`${E}:${N}`;if(!h[B])try{const{content:A}=await se.readSkillContent(E,N);m(P=>({...P,[B]:A}))}catch{m(A=>({...A,[B]:"Failed to load skill content."}))}}const j=t.reduce((E,N)=>E+N.skills.length,0),k=t.reduce((E,N)=>E+N.commands.length,0);return r.jsxs("div",{className:"h-full flex flex-col ",children:[r.jsx("div",{className:"shrink-0 px-4 py-3 border-b border-cc-border",children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("h2",{className:"text-sm font-medium text-cc-fg",children:"Skills & Plugins"}),r.jsxs("p",{className:"text-[11px] text-cc-muted mt-0.5",children:[t.length," plugin",t.length!==1?"s":""," installed",j>0&&` · ${j} skill${j!==1?"s":""}`,k>0&&` · ${k} command${k!==1?"s":""}`]})]}),r.jsx("button",{onClick:v,disabled:n,className:"px-2.5 py-1 text-[11px] font-mono-code text-cc-muted hover:text-cc-fg rounded-md hover:bg-cc-hover transition-colors cursor-pointer",children:n?"Loading...":"Refresh"})]})}),r.jsxs("div",{className:"flex-1 overflow-y-auto p-4 space-y-3",children:[l&&r.jsx("div",{className:"px-3 py-2 rounded-lg bg-cc-error/5 border border-cc-error/20 text-xs text-cc-error",children:l}),n&&t.length===0&&r.jsxs("div",{className:"flex items-center justify-center py-12 text-cc-muted text-xs",children:[r.jsx("span",{className:"w-4 h-4 border-2 border-cc-muted/30 border-t-cc-muted rounded-full animate-spin mr-2"}),"Loading plugins..."]}),!n&&t.length===0&&!l&&r.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-cc-muted",children:[r.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",className:"w-8 h-8 opacity-30 mb-2",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z"})}),r.jsx("p",{className:"text-xs",children:"No plugins installed."}),r.jsxs("p",{className:"text-[11px] mt-1 opacity-70",children:["Install plugins via ",r.jsx("code",{className:"font-mono-code bg-cc-hover px-1 rounded",children:"/install-plugin"})," in Claude Code."]})]}),t.map(E=>r.jsxs("div",{className:`rounded-lg border transition-colors ${E.blocked?"border-cc-error/20 bg-cc-error/5":E.disabledInCampfire?"border-cc-border bg-cc-hover/50 opacity-60":"border-cc-border bg-cc-card"}`,children:[r.jsxs("div",{className:"px-3 py-2.5 flex items-start gap-3",children:[r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("button",{onClick:()=>f(d===E.id?null:E.id),className:"text-xs font-medium text-cc-fg hover:text-cc-primary transition-colors cursor-pointer truncate",children:E.name}),r.jsx("span",{className:"text-[10px] font-mono-code text-cc-muted bg-cc-hover px-1.5 py-0.5 rounded shrink-0",children:E.marketplace}),E.blocked&&r.jsx("span",{className:"text-[10px] font-mono-code text-cc-error bg-cc-error/10 px-1.5 py-0.5 rounded shrink-0",children:"blocked"})]}),E.description&&r.jsx("p",{className:"text-[11px] text-cc-muted mt-0.5 line-clamp-2",children:E.description}),r.jsxs("div",{className:"flex items-center gap-3 mt-1.5 text-[10px] text-cc-muted",children:[E.author&&r.jsxs("span",{children:["by ",E.author]}),r.jsxs("span",{children:["v",E.version]}),E.skills.length>0&&r.jsxs("span",{children:[E.skills.length," skill",E.skills.length!==1?"s":""]}),E.commands.length>0&&r.jsxs("span",{children:[E.commands.length," cmd",E.commands.length!==1?"s":""]})]})]}),r.jsx("button",{onClick:()=>y(E),disabled:g===E.id||E.blocked,className:`shrink-0 px-2.5 py-1 text-[11px] font-medium rounded-md transition-colors cursor-pointer disabled:opacity-50 ${E.disabledInCampfire?"bg-cc-hover text-cc-muted hover:text-cc-fg":"bg-cc-primary/15 text-cc-primary hover:bg-cc-primary/25"}`,children:g===E.id?"...":E.disabledInCampfire?"Enable":"Disable"})]}),d===E.id&&r.jsxs("div",{className:"border-t border-cc-border px-3 py-2.5 space-y-2",children:[E.skills.length>0&&r.jsxs("div",{children:[r.jsx("h4",{className:"text-[10px] font-mono-code text-cc-muted uppercase tracking-wider mb-1",children:"Skills"}),E.skills.map(N=>{const B=`${E.id}:${N.name}`;return r.jsxs("div",{className:"mb-1.5",children:[r.jsx("button",{onClick:()=>S(E.id,N.name),className:"text-[11px] font-mono-code text-cc-fg hover:text-cc-primary transition-colors cursor-pointer",children:N.name}),N.description&&r.jsx("p",{className:"text-[10px] text-cc-muted ml-2",children:N.description}),h[B]&&r.jsx("pre",{className:"mt-1 p-2 rounded bg-cc-code-bg text-cc-code-fg text-[10px] font-mono-code overflow-x-auto max-h-48 overflow-y-auto",children:h[B]})]},N.name)})]}),E.commands.length>0&&r.jsxs("div",{children:[r.jsx("h4",{className:"text-[10px] font-mono-code text-cc-muted uppercase tracking-wider mb-1",children:"Commands"}),E.commands.map(N=>r.jsxs("div",{className:"text-[11px] font-mono-code text-cc-fg",children:["/",N.name]},N.name))]}),r.jsx("div",{className:"text-[10px] font-mono-code text-cc-muted pt-1 border-t border-cc-border truncate",title:E.installPath,children:E.installPath})]})]},E.id))]})]})}function KH(){return w.useSyncExternalStore(e=>(window.addEventListener("hashchange",e),()=>window.removeEventListener("hashchange",e)),()=>window.location.hash)}function YH(){const[e,t]=w.useState(!1),[s,n]=w.useState(!1),[a,l]=w.useState(!1);w.useEffect(()=>{se.getAuthStatus().then(ke=>{ke.enabled&&!ke.isLoggedIn&&(qh()&&BM(),n(!0)),t(!0)}).catch(()=>{t(!0)})},[]),w.useEffect(()=>{se.getSettings().then(ke=>{ke.onboardingCompleted||l(!0)}).catch(()=>{})},[]);const c=Y(ke=>ke.darkMode),d=Y(ke=>ke.currentSessionId),f=Y(ke=>{const Xe=ke.currentSessionId;return Xe?(ke.myRole.get(Xe)??null)==="spectator":!1}),h=Y(ke=>{const Xe=ke.currentSessionId;return Xe&&(ke.myRole.get(Xe)??null)==="spectator"?!1:ke.sidebarOpen}),m=Y(ke=>ke.taskPanelOpen),g=Y(ke=>ke.homeResetKey),b=Y(ke=>ke.activeTab),v=Y(ke=>ke.updateOverlayActive),y=KH(),S=y==="#/settings",j=y==="#/terminal",k=y==="#/environments",E=y==="#/scheduled",N=y==="#/hub",B=y==="#/monitor",A=y==="#/commands",P=y==="#/gallery"||y.startsWith("#/gallery?"),K=P&&new URLSearchParams(y.replace(/^#\/gallery\??/,"")).get("session")||void 0,X=Y(ke=>{var Xe,Je;if(K)return((Xe=ke.sessionNames)==null?void 0:Xe.get(K))||((Je=ke.sdkSessions.find($e=>$e.sessionId===K))==null?void 0:Je.name)||void 0}),Z=y==="#/webhooks",I=y==="#/adapters",H=y==="#/clawhub",F=y==="#/agents",G=y==="#/prompts",q=y==="#/integrations",R=y==="#/integrations/linear",M=y==="#/memory",O=y==="#/router",W=y==="#/collective",U=y==="#/orchestrator",D=y==="#/races"||y.startsWith("#/races/"),$=y==="#/kanban",z=y==="#/skills",T=y.match(/^#\/replay\/(?!session\/)(.+)$/),ae=y.match(/^#\/replay\/session\/(.+)$/),be=!!T||!!ae,ne=y.match(/^#\/public-replay\/(.+)$/),ve=!!ne,Ae=!S&&!j&&!k&&!E&&!P&&!Z&&!I&&!H&&!F&&!G&&!q&&!R&&!M&&!O&&!W&&!U&&!D&&!$&&!z&&!be&&!ve&&!N&&!B&&!A;w.useEffect(()=>{LM(y||"#/")},[y]),w.useEffect(()=>{document.documentElement.classList.toggle("dark",c)},[c]);const De=y.startsWith("#/join/");return De&&ih(!0),w.useEffect(()=>{f&&!Ae&&!De&&(window.location.hash="")},[f,Ae,De]),w.useEffect(()=>{const ke=y.match(/^#\/join\/(.+)$/);if(!ke)return;const Xe=ke[1];se.joinSession(Xe).then(Je=>{Je.token&&$j(Je.token,Je.session_id),qo(Je.session_id),Y.getState().setCurrentSession(Je.session_id),kr(Je.session_id),ih(!1),window.location.hash=""}).catch(()=>{console.warn(`[App] Invalid invite token: ${Xe}`),ih(!1),window.location.hash=""})},[y]),w.useEffect(()=>{const ke=Y.getState().currentSessionId;ke&&kr(ke)},[]),w.useEffect(()=>{if(!e||s)return;const ke=()=>{se.checkForUpdate().then(Je=>Y.getState().setUpdateInfo(Je)).catch(()=>{})};ke();const Xe=setInterval(ke,300*1e3);return()=>clearInterval(Xe)},[e,s]),e?s?r.jsx(YM,{onLogin:()=>n(!1)}):y==="#/playground"?r.jsx(CP,{}):r.jsxs("div",{className:"h-[100dvh] flex font-sans-ui bg-cc-bg text-cc-fg antialiased text-[12.5px] leading-normal",children:[h&&!f&&r.jsx("div",{className:"fixed inset-0 bg-black/30 z-30 md:hidden",onClick:()=>Y.getState().setSidebarOpen(!1)}),!f&&r.jsx("div",{className:`
|
|
274
|
+
[Failed to start terminal: ${S.message}]`)});const b=m.onData(S=>aS(S)),v=a.current,y=new ResizeObserver(()=>{g.fit(),oS(m.cols,m.rows)});return y.observe(v),()=>{h=!0,y.disconnect(),b.dispose(),CN(),m.dispose(),l.current=null,c.current=null,se.killTerminal().catch(()=>{})}},[e,n]),w.useEffect(()=>{l.current&&(l.current.options.theme=lS(d))},[d]);const f=r.jsxs("div",{className:`flex flex-col rounded-xl shadow-2xl overflow-hidden border border-cc-border ${s?"h-full":"w-[90vw] max-w-4xl h-[70vh]"}`,style:{background:d?"#141413":"#1e1e1e"},onClick:h=>h.stopPropagation(),children:[r.jsxs("div",{className:"flex items-center justify-between px-4 py-2 border-b border-cc-border bg-cc-sidebar shrink-0",children:[r.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-4 h-4 text-cc-muted shrink-0",children:r.jsx("path",{d:"M2 3a1 1 0 011-1h10a1 1 0 011 1v10a1 1 0 01-1 1H3a1 1 0 01-1-1V3zm2 1.5l3 2.5-3 2.5V4.5zM8.5 10h3v1h-3v-1z"})}),r.jsx("span",{className:"text-xs text-cc-muted font-mono-code truncate",children:e})]}),t&&r.jsx("button",{onClick:t,className:"w-6 h-6 flex items-center justify-center rounded-md text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer shrink-0",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"w-3.5 h-3.5",children:r.jsx("path",{d:"M4 4l8 8M12 4l-8 8",strokeLinecap:"round"})})})]}),r.jsx("div",{ref:a,className:"flex-1 min-h-0 p-1"})]});return s?r.jsx("div",{className:"h-full",children:f}):r.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",children:f})}function ZF(){const e=Y(n=>n.terminalCwd),[t,s]=w.useState(!1);return r.jsxs("div",{className:"h-full bg-cc-bg overflow-y-auto",children:[r.jsxs("div",{className:"max-w-5xl mx-auto px-4 sm:px-8 py-6 sm:py-10 h-full flex flex-col",children:[r.jsxs("div",{className:"flex items-start justify-between gap-3 mb-6 shrink-0",children:[r.jsxs("div",{children:[r.jsx("h1",{className:"text-xl font-semibold text-cc-fg",children:"Terminal"}),r.jsx("p",{className:"mt-1 text-sm text-cc-muted",children:"Run shell commands in a project folder without leaving Campfire."})]}),r.jsx("button",{type:"button",onClick:()=>s(!0),className:"px-3 py-2 rounded-lg text-sm font-medium bg-cc-primary hover:bg-cc-primary-hover text-white transition-colors cursor-pointer whitespace-nowrap",children:e?"Change Folder":"Choose Folder"})]}),r.jsx("div",{className:"flex-1 min-h-[420px]",children:e?r.jsx(QF,{cwd:e,embedded:!0}):r.jsx("div",{className:"h-full bg-cc-card border border-cc-border rounded-xl p-6 sm:p-8 flex items-center justify-center text-center",children:r.jsxs("div",{className:"max-w-md",children:[r.jsx("h2",{className:"text-lg font-semibold text-cc-fg mb-2",children:"No terminal started yet"}),r.jsx("p",{className:"text-sm text-cc-muted",children:"Choose a folder to start a terminal session. You can switch folders anytime."})]})})})]}),t&&r.jsx(iv,{initialPath:e||"",onSelect:n=>{Y.getState().openTerminal(n),window.location.hash="#/terminal",s(!1)},onClose:()=>s(!1)})]})}let eH=0;function cS(){return`replay-${++eH}`}function tH(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function uS(e,t){var s;if(e.type==="user_message")return{id:e.id||cS(),role:"user",content:e.content||"",timestamp:e.timestamp||0};if(e.type==="assistant"){const n=e.message;return n?{id:n.id||cS(),role:"assistant",content:tH(n.content||[]),contentBlocks:n.content,timestamp:e.timestamp||0,parentToolUseId:e.parent_tool_use_id,model:n.model,stopReason:n.stop_reason}:null}if(e.type==="result"){const n=e.data;if(n!=null&&n.is_error&&((s=n.errors)!=null&&s.length))return{id:`replay-error-${t}`,role:"system",content:`Error: ${n.errors.join(", ")}`,timestamp:0}}return null}function dS(e){const t=[];let s="",n=null;for(let a=0;a<e.length;a++){const l=e[a];if(l.type==="stream_event"){const d=l.event;if((d==null?void 0:d.type)==="message_start"){if(s&&n){const f=t.find(h=>h.id===n);f&&(f.content=s)}s="",n=null}else if((d==null?void 0:d.type)==="content_block_delta"){const f=d.delta;(f==null?void 0:f.type)==="text_delta"&&f.text&&(s+=f.text)}continue}if(l.type==="assistant"){const d=uS(l,a);d&&(!d.content&&s&&(d.content=s),n=d.id,t.push(d)),s="";continue}if(s&&n){const d=t.find(f=>f.id===n);d&&!d.content&&(d.content=s),s="",n=null}const c=uS(l,a);c&&t.push(c)}if(s&&n){const a=t.find(l=>l.id===n);a&&!a.content&&(a.content=s)}return t}const sH=[1,2,4,8];function hS({filename:e,sessionId:t}){const s=Y(O=>O.replaySpeed),n=Y(O=>O.replayState),a=Y(O=>O.replaySessionId),l=Y(O=>O.setReplaySpeed),c=Y(O=>O.setReplayState),d=Y(O=>O.setReplaySessionId),f=Y(O=>O.setMessages),h=w.useRef([]),m=w.useRef([]),g=w.useRef(0),b=w.useRef(null),[v,y]=w.useState(!0),[S,j]=w.useState(null),[k,E]=w.useState(!1),[N,B]=w.useState(null),[A,P]=w.useState(0),[K,X]=w.useState(0);w.useEffect(()=>{const O=`replay-${Math.random().toString(36).slice(2,10)}`;return d(O),f(O,[]),c("idle"),()=>{d(null),c("idle"),f(O,[])}},[d,f,c]),w.useEffect(()=>{let O=!1;async function W(){y(!0),j(null);try{if(e){const U=await se.getRecording(e);if(O)return;B(U.header);const D=dS(U.messages),$=U.timestamps,z=$.length>1?$.length/Math.max(D.length,1):1;m.current=D.map((T,ae)=>$[Math.min(Math.round(ae*z),$.length-1)]||0),h.current=D,P(D.length)}else if(t){const U=await se.getSessionHistory(t);if(O)return;U.state&&B({session_id:t,backend_type:U.state.backend_type||"unknown",started_at:U.state.started_at||Date.now(),cwd:U.state.cwd||""});const D=dS(U.messages);h.current=D,P(D.length)}}catch(U){O||j(U.message||"Failed to load replay data")}finally{O||y(!1)}}return W(),()=>{O=!0}},[e,t]),w.useEffect(()=>()=>{b.current&&clearTimeout(b.current)},[]);const Z=w.useCallback(O=>{const W=m.current;if(W.length>1&&O>0&&O<W.length){const U=W[O]-W[O-1];return Math.min(U,3e3)/s}return 300/s},[s]),I=w.useCallback(()=>{if(!a)return;const O=g.current;if(O>=h.current.length){c("ended");return}const W=h.current.slice(0,O+1);f(a,W),g.current=O+1,X(O+1),O+1<h.current.length?b.current=setTimeout(I,Z(O+1)):c("ended")},[a,f,c,Z]),H=w.useCallback(()=>{!a||h.current.length===0||(c("playing"),g.current>=h.current.length&&(g.current=0,X(0),f(a,[])),b.current=setTimeout(I,Z(g.current)))},[a,c,f,I,Z]),F=w.useCallback(()=>{c("paused"),b.current&&(clearTimeout(b.current),b.current=null)},[c]),G=w.useCallback(()=>{b.current&&(clearTimeout(b.current),b.current=null),c("idle"),g.current=0,X(0),a&&f(a,[])},[c,f,a]),q=w.useCallback(O=>{if(!a)return;b.current&&(clearTimeout(b.current),b.current=null);const W=Math.max(0,Math.min(O,h.current.length));g.current=W,X(W),f(a,h.current.slice(0,W)),W>=h.current.length?c("ended"):n==="playing"?b.current=setTimeout(I,Z(W)):c("paused")},[a,f,c,n,I,Z]);w.useEffect(()=>{n==="playing"&&b.current&&(clearTimeout(b.current),b.current=setTimeout(I,Z(g.current)))},[s]);const R=w.useCallback(()=>{var U;const O=e?`#/replay/${e}`:`#/replay/session/${t}`,W=`${window.location.origin}/${O}`;if((U=navigator.clipboard)!=null&&U.writeText)navigator.clipboard.writeText(W);else{const D=document.createElement("textarea");D.value=W,D.style.position="fixed",D.style.opacity="0",document.body.appendChild(D),D.select(),document.execCommand("copy"),document.body.removeChild(D)}E(!0),setTimeout(()=>E(!1),2e3)},[e,t]),M=w.useCallback(()=>{window.location.hash=""},[]);return v?r.jsx("div",{className:"flex items-center justify-center h-full text-cc-text-secondary",children:r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("svg",{className:"animate-spin h-5 w-5",viewBox:"0 0 24 24",fill:"none",children:[r.jsx("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4",className:"opacity-25"}),r.jsx("path",{d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z",fill:"currentColor",className:"opacity-75"})]}),"Loading replay..."]})}):S?r.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-4 text-cc-text-secondary",children:[r.jsxs("p",{className:"text-red-400",children:["Failed to load replay: ",S]}),r.jsx("button",{onClick:M,className:"px-4 py-2 bg-cc-border rounded hover:bg-cc-hover transition-colors",children:"Go Back"})]}):!v&&A===0?r.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-4 text-cc-muted",children:[r.jsx("p",{className:"text-sm",children:"This recording contains no playable messages."}),r.jsx("p",{className:"text-xs text-cc-muted/60",children:"It may be a reconnect or initialization-only recording."}),r.jsx("button",{onClick:M,className:"px-4 py-2 bg-cc-border rounded hover:bg-cc-hover transition-colors text-sm",children:"Go Back"})]}):r.jsxs("div",{className:"flex flex-col h-full bg-cc-bg",children:[r.jsxs("div",{className:"flex items-center justify-between px-4 py-2 border-b border-cc-border bg-cc-card",children:[r.jsxs("div",{className:"flex items-center gap-3 text-sm text-cc-muted",children:[r.jsxs("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M14.752 11.168l-3.197-2.132A1 1 0 0010 9.87v4.263a1 1 0 001.555.832l3.197-2.132a1 1 0 000-1.664z"}),r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})]}),r.jsx("span",{className:"font-medium text-cc-fg",children:"Session Replay"}),N&&r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"text-xs px-2 py-0.5 rounded bg-cc-hover text-cc-muted",children:N.backend_type}),r.jsxs("span",{className:"text-xs",children:[N.session_id.slice(0,8),"..."]})]})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("button",{onClick:R,className:`p-1.5 rounded hover:bg-cc-hover transition-colors ${k?"text-cc-success":"text-cc-muted"}`,title:k?"Copied!":"Copy replay link",children:k?r.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}):r.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8.684 13.342C8.886 12.938 9 12.482 9 12c0-.482-.114-.938-.316-1.342m0 2.684a3 3 0 110-2.684m0 2.684l6.632 3.316m-6.632-6l6.632-3.316m0 0a3 3 0 105.367-2.684 3 3 0 00-5.367 2.684zm0 9.316a3 3 0 105.368 2.684 3 3 0 00-5.368-2.684z"})})}),r.jsx("button",{onClick:M,className:"p-1.5 rounded hover:bg-cc-hover transition-colors text-cc-muted",title:"Close replay",children:r.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),r.jsx("div",{className:"border-b border-cc-border bg-cc-card px-4 py-2",children:r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("button",{onClick:n==="playing"?F:H,className:"w-8 h-8 flex items-center justify-center rounded-lg bg-cc-primary text-white hover:bg-cc-primary-hover transition-colors cursor-pointer",title:n==="playing"?"Pause":"Play",children:n==="playing"?r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:r.jsx("path",{d:"M5.5 3.5A1.5 1.5 0 017 5v6a1.5 1.5 0 01-3 0V5a1.5 1.5 0 011.5-1.5zm5 0A1.5 1.5 0 0112 5v6a1.5 1.5 0 01-3 0V5a1.5 1.5 0 011.5-1.5z"})}):r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:r.jsx("path",{d:"M4.5 3.5A.5.5 0 015.22 3l7 4.5a.5.5 0 010 .86l-7 4.5A.5.5 0 014.5 12.5v-9z"})})}),r.jsx("button",{onClick:G,className:"w-8 h-8 flex items-center justify-center rounded-lg text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",title:"Reset",children:r.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})})}),r.jsx("div",{className:"flex-1 h-1.5 bg-cc-hover rounded-full overflow-hidden cursor-pointer",onClick:O=>{const W=O.currentTarget.getBoundingClientRect(),U=(O.clientX-W.left)/W.width;q(Math.round(U*A))},children:r.jsx("div",{className:"h-full bg-cc-primary rounded-full transition-all",style:{width:`${A>0?K/A*100:0}%`}})}),r.jsxs("span",{className:"text-[10px] text-cc-muted tabular-nums",children:[K,"/",A]}),r.jsx("div",{className:"flex items-center gap-1",children:sH.map(O=>r.jsxs("button",{onClick:()=>l(O),className:`px-2 py-1 text-[10px] font-medium rounded transition-colors cursor-pointer ${s===O?"bg-cc-primary text-white":"bg-cc-hover text-cc-muted hover:text-cc-fg"}`,children:[O,"x"]},O))}),r.jsx("span",{className:`text-[10px] px-2 py-0.5 rounded font-medium ${n==="playing"?"bg-green-500/20 text-green-400":n==="paused"?"bg-yellow-500/20 text-yellow-400":"bg-cc-hover text-cc-muted"}`,children:n==="playing"?"Playing":n==="paused"?"Paused":n==="ended"?"Ended":"Ready"})]})}),r.jsx("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden",children:a&&r.jsx(ev,{sessionId:a})})]})}function nH({embedded:e=!1,prefillSessionId:t,prefillName:s}){const[n,a]=w.useState([]),[l,c]=w.useState(!0),[d,f]=w.useState(""),[h,m]=w.useState(""),[g,b]=w.useState(!1),[v,y]=w.useState(""),[S,j]=w.useState("votes"),[k,E]=w.useState("desc"),[N,B]=w.useState(!1),[A,P]=w.useState(null),[K,X]=w.useState(!1),[Z,I]=w.useState(!!t),[H,F]=w.useState({sessionId:t||"",name:s||"",description:"",tags:""}),[G,q]=w.useState(!1),R=w.useCallback(()=>{const ne={};h&&(ne.backend=h),g&&(ne.featured=!0),v.trim()&&(ne.tags=v.split(",").map(ve=>ve.trim()).filter(Boolean)),S&&(ne.sortBy=S),k&&(ne.sortOrder=k),se.listGalleryEntries(ne).then(a).catch(ve=>f(ve instanceof Error?ve.message:String(ve))).finally(()=>c(!1))},[h,g,v,S,k]);w.useEffect(()=>{R();const ne=setInterval(R,15e3);return()=>clearInterval(ne)},[R]),w.useEffect(()=>{se.getClawHubStatus().then(ne=>B(ne.available)).catch(()=>{}),se.getMoltbookStatus().then(ne=>X(ne.available)).catch(()=>{})},[]);async function M(ne,ve){a(Ae=>Ae.map(De=>De.id===ne?{...De,votes:De.votes+ve}:De));try{const{votes:Ae}=await se.voteGalleryEntry(ne,ve);a(De=>De.map(ke=>ke.id===ne?{...ke,votes:Ae}:ke))}catch{R()}}async function O(ne){try{await se.deleteGalleryEntry(ne),R()}catch(ve){f(ve instanceof Error?ve.message:String(ve))}}async function W(ne){try{await se.featureGalleryEntry(ne),R()}catch(ve){f(ve instanceof Error?ve.message:String(ve))}}async function U(ne){if(!A){P(ne),f("");try{const ve=await se.exportToClawHub(ne);ve.ok?(f(`Exported to ClawHub: ${ve.output||"success"}`),setTimeout(()=>f(""),5e3)):f(`ClawHub export failed: ${ve.error}`)}catch(ve){f(ve instanceof Error?ve.message:String(ve))}finally{P(null)}}}async function D(ne){f("");try{const ve=await se.postToMoltbook(ne);if(ve.ok){const Ae=ve.postUrl?` — ${ve.postUrl}`:"";f(`Posted to Moltbook${Ae}`),setTimeout(()=>f(""),5e3)}else f(`Moltbook post failed: ${ve.error}`)}catch(ve){f(ve instanceof Error?ve.message:String(ve))}}async function $(ne){var ve;f("");try{const Ae=await se.createPublicReplayLink(ne),De=`${window.location.origin}/${Ae.url}`;if((ve=navigator.clipboard)!=null&&ve.writeText)await navigator.clipboard.writeText(De),f("Public replay link copied to clipboard");else{const ke=document.createElement("textarea");ke.value=De,ke.style.position="fixed",ke.style.opacity="0",document.body.appendChild(ke),ke.select(),document.execCommand("copy"),document.body.removeChild(ke),f("Public replay link copied to clipboard")}setTimeout(()=>f(""),3e3)}catch(Ae){f(Ae instanceof Error?Ae.message:String(Ae))}}async function z(){const ne=H.name.trim(),ve=H.sessionId.trim();if(!(!ne||!ve)){q(!0),f("");try{await se.createGalleryEntry({sessionId:ve,name:ne,description:H.description.trim(),tags:H.tags.split(",").map(Ae=>Ae.trim()).filter(Boolean)}),F({sessionId:"",name:"",description:"",tags:""}),I(!1),R()}catch(Ae){f(Ae instanceof Error?Ae.message:String(Ae))}finally{q(!1)}}}const T=n.reduce((ne,ve)=>ne+ve.votes,0),ae=n.filter(ne=>ne.featured).length,be=r.jsxs("div",{className:"max-w-3xl mx-auto px-4 sm:px-8 py-6 sm:py-10 font-sans-ui antialiased",children:[r.jsxs("div",{className:"flex items-center gap-3 mb-1",children:[r.jsx("button",{onClick:()=>{window.location.hash=""},className:"flex items-center justify-center w-8 h-8 rounded-lg text-cc-fg/60 hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer","aria-label":"Go back",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.8",className:"w-4 h-4",children:r.jsx("path",{d:"M10 3L5 8l5 5",strokeLinecap:"round",strokeLinejoin:"round"})})}),r.jsxs("div",{className:"flex-1",children:[r.jsx("p",{className:"text-[11px] text-cc-fg/50 font-medium",children:"Data"}),r.jsx("h1",{className:"text-xl font-semibold text-cc-fg -mt-0.5",children:"Session Gallery"})]}),r.jsx("button",{onClick:()=>{I(!Z)},className:`flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-[12px] font-medium transition-all cursor-pointer ${Z?"bg-cc-hover text-cc-fg":"bg-cc-primary hover:bg-cc-primary-hover text-white shadow-sm"}`,children:Z?r.jsxs(r.Fragment,{children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"w-3 h-3",children:r.jsx("path",{d:"M4 4l8 8M12 4l-8 8",strokeLinecap:"round"})}),"Cancel"]}):r.jsxs(r.Fragment,{children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:"w-3 h-3",children:r.jsx("path",{d:"M8 3v10M3 8h10"})}),"Publish"]})})]}),r.jsx("p",{className:"text-[13px] text-cc-fg/55 mb-5 ml-11",children:"Showcase your best AI coding sessions. Vote, feature, and share."}),r.jsxs("div",{className:"flex items-center gap-4 mb-5 ml-11",children:[r.jsxs("div",{className:"flex items-center gap-1.5 text-[12px]",children:[r.jsx("span",{className:"text-cc-fg/40",children:"Entries"}),r.jsx("span",{className:"font-semibold text-cc-fg",children:n.length})]}),r.jsx("div",{className:"w-px h-3.5 bg-cc-border/40"}),r.jsxs("div",{className:"flex items-center gap-1.5 text-[12px]",children:[r.jsx("span",{className:"text-cc-fg/40",children:"Total Votes"}),r.jsx("span",{className:"font-semibold text-cc-fg",children:T})]}),ae>0&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"w-px h-3.5 bg-cc-border/40"}),r.jsxs("div",{className:"flex items-center gap-1.5 text-[12px]",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 text-amber-500",children:r.jsx("path",{d:"M8 1.5l2.09 4.26 4.66.68-3.38 3.28.8 4.64L8 12.17l-4.17 2.19.8-4.64-3.38-3.28 4.66-.68L8 1.5z"})}),r.jsx("span",{className:"font-semibold text-cc-fg",children:ae})]})]})]}),d&&r.jsxs("div",{className:"mb-4 px-4 py-3 rounded-xl bg-cc-error/8 border border-cc-error/15 text-[12px] text-cc-error flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-4 h-4 shrink-0",children:r.jsx("path",{d:"M8 1a7 7 0 110 14A7 7 0 018 1zm0 3a.75.75 0 00-.75.75v3.5a.75.75 0 001.5 0v-3.5A.75.75 0 008 4zm0 7a1 1 0 100-2 1 1 0 000 2z"})}),d]}),r.jsx("button",{onClick:()=>f(""),className:"text-cc-error/70 hover:text-cc-error text-[11px] font-medium cursor-pointer shrink-0 ml-3",children:"Dismiss"})]}),Z&&r.jsxs("div",{className:"mb-5 rounded-xl border border-cc-primary/30 bg-cc-card shadow-sm ring-1 ring-cc-primary/10 overflow-hidden",children:[r.jsxs("div",{className:"px-5 py-4 border-b border-cc-border/30",children:[r.jsx("h3",{className:"text-[13px] font-semibold text-cc-fg",children:"Add to Gallery"}),r.jsx("p",{className:"text-[11px] text-cc-fg/50 mt-0.5",children:"Publish a session to the gallery for others to see."})]}),r.jsxs("div",{className:"px-5 py-4 space-y-3",children:[r.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-[11px] font-medium text-cc-fg/70 mb-1.5",htmlFor:"gallery-session-id",children:"Session ID"}),r.jsx("input",{id:"gallery-session-id",type:"text",value:H.sessionId,onChange:ne=>F({...H,sessionId:ne.target.value}),placeholder:"Paste session ID",className:"w-full px-3.5 py-2.5 text-[12px] font-mono-code bg-cc-bg border border-cc-border/60 rounded-lg text-cc-fg placeholder:text-cc-fg/35 focus:outline-none focus:border-cc-primary/60 focus:ring-1 focus:ring-cc-primary/20 transition-all"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-[11px] font-medium text-cc-fg/70 mb-1.5",htmlFor:"gallery-name",children:"Name"}),r.jsx("input",{id:"gallery-name",type:"text",value:H.name,onChange:ne=>F({...H,name:ne.target.value}),placeholder:"e.g. Auth Refactor",className:"w-full px-3.5 py-2.5 text-[13px] bg-cc-bg border border-cc-border/60 rounded-lg text-cc-fg placeholder:text-cc-fg/35 focus:outline-none focus:border-cc-primary/60 focus:ring-1 focus:ring-cc-primary/20 transition-all"})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-[11px] font-medium text-cc-fg/70 mb-1.5",htmlFor:"gallery-desc",children:"Description"}),r.jsx("textarea",{id:"gallery-desc",value:H.description,onChange:ne=>F({...H,description:ne.target.value}),placeholder:"What makes this session interesting? (optional)",rows:2,className:"w-full px-3.5 py-2.5 text-[13px] bg-cc-bg border border-cc-border/60 rounded-lg text-cc-fg placeholder:text-cc-fg/35 focus:outline-none focus:border-cc-primary/60 focus:ring-1 focus:ring-cc-primary/20 transition-all resize-y"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-[11px] font-medium text-cc-fg/70 mb-1.5",htmlFor:"gallery-tags",children:"Tags"}),r.jsx("input",{id:"gallery-tags",type:"text",value:H.tags,onChange:ne=>F({...H,tags:ne.target.value}),placeholder:"auth, refactor, bug-fix (comma-separated)",className:"w-full px-3.5 py-2.5 text-[13px] bg-cc-bg border border-cc-border/60 rounded-lg text-cc-fg placeholder:text-cc-fg/35 focus:outline-none focus:border-cc-primary/60 focus:ring-1 focus:ring-cc-primary/20 transition-all"})]}),r.jsx("div",{className:"flex justify-end pt-1",children:r.jsx("button",{onClick:z,disabled:!H.name.trim()||!H.sessionId.trim()||G,className:`px-4 py-2 rounded-lg text-[12px] font-medium transition-all ${H.name.trim()&&H.sessionId.trim()&&!G?"bg-cc-primary hover:bg-cc-primary-hover text-white shadow-sm cursor-pointer":"bg-cc-hover text-cc-fg/35 cursor-not-allowed"}`,children:G?r.jsxs("span",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"w-3 h-3 border-2 border-white/30 border-t-white rounded-full animate-spin"}),"Publishing..."]}):"Publish to Gallery"})})]})]}),r.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-5",children:[r.jsxs("select",{value:h,onChange:ne=>m(ne.target.value),className:"px-3 py-2 text-[12px] bg-cc-bg border border-cc-border/60 rounded-lg text-cc-fg focus:outline-none focus:border-cc-primary/60 focus:ring-1 focus:ring-cc-primary/20 cursor-pointer transition-all","aria-label":"Filter by backend",children:[r.jsx("option",{value:"",children:"All Backends"}),r.jsx("option",{value:"claude",children:"Claude"}),r.jsx("option",{value:"codex",children:"Codex"}),r.jsx("option",{value:"goose",children:"Goose"}),r.jsx("option",{value:"aider",children:"Aider"}),r.jsx("option",{value:"openhands",children:"OpenHands"}),r.jsx("option",{value:"openclaw",children:"OpenClaw"})]}),r.jsxs("select",{value:S,onChange:ne=>j(ne.target.value),className:"px-3 py-2 text-[12px] bg-cc-bg border border-cc-border/60 rounded-lg text-cc-fg focus:outline-none focus:border-cc-primary/60 focus:ring-1 focus:ring-cc-primary/20 cursor-pointer transition-all","aria-label":"Sort by",children:[r.jsx("option",{value:"votes",children:"Sort by Votes"}),r.jsx("option",{value:"recent",children:"Sort by Recent"}),r.jsx("option",{value:"cost",children:"Sort by Cost"}),r.jsx("option",{value:"duration",children:"Sort by Duration"})]}),r.jsx("button",{onClick:()=>E(ne=>ne==="desc"?"asc":"desc"),className:"px-3 py-2 text-[12px] bg-cc-bg border border-cc-border/60 rounded-lg text-cc-fg/60 hover:text-cc-fg transition-all cursor-pointer",title:k==="desc"?"Descending":"Ascending","aria-label":`Sort order: ${k}`,children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:`w-3.5 h-3.5 transition-transform ${k==="asc"?"rotate-180":""}`,children:r.jsx("path",{d:"M3.5 3a.5.5 0 01.5.5v8.793l2.146-2.147a.5.5 0 01.708.708l-3 3a.5.5 0 01-.708 0l-3-3a.5.5 0 11.708-.708L3 12.293V3.5a.5.5 0 01.5-.5zM7 4.5a.5.5 0 01.5-.5h5a.5.5 0 010 1h-5a.5.5 0 01-.5-.5zM7.5 7a.5.5 0 000 1h3.5a.5.5 0 000-1H7.5zm0 3a.5.5 0 000 1h2a.5.5 0 000-1h-2z"})})}),r.jsxs("button",{onClick:()=>b(!g),className:`flex items-center gap-1.5 px-3 py-2 text-[12px] font-medium rounded-lg transition-all cursor-pointer border ${g?"bg-amber-500/10 text-amber-600 border-amber-500/25":"bg-cc-bg text-cc-fg/50 border-cc-border/60 hover:text-cc-fg hover:border-cc-border"}`,"aria-pressed":g,children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3",children:r.jsx("path",{d:"M8 1.5l2.09 4.26 4.66.68-3.38 3.28.8 4.64L8 12.17l-4.17 2.19.8-4.64-3.38-3.28 4.66-.68L8 1.5z"})}),"Featured"]}),r.jsx("div",{className:"flex-1 min-w-[120px]",children:r.jsx("input",{type:"text",value:v,onChange:ne=>y(ne.target.value),placeholder:"Filter by tags...",className:"w-full px-3 py-2 text-[12px] bg-cc-bg border border-cc-border/60 rounded-lg text-cc-fg placeholder:text-cc-fg/35 focus:outline-none focus:border-cc-primary/60 focus:ring-1 focus:ring-cc-primary/20 transition-all","aria-label":"Filter by tags"})})]}),l?r.jsxs("div",{className:"flex flex-col items-center justify-center py-16",children:[r.jsx("span",{className:"w-6 h-6 border-2 border-cc-fg/10 border-t-cc-fg/50 rounded-full animate-spin mb-3"}),r.jsx("p",{className:"text-[12px] text-cc-fg/50",children:"Loading gallery..."})]}):n.length===0?r.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center",children:[r.jsx("div",{className:"w-14 h-14 rounded-2xl bg-cc-hover/70 flex items-center justify-center mb-4",children:r.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"w-7 h-7 text-cc-fg/30",children:[r.jsx("path",{d:"M2 7l10-5 10 5-10 5-10-5z",strokeLinecap:"round",strokeLinejoin:"round"}),r.jsx("path",{d:"M2 12l10 5 10-5",strokeLinecap:"round",strokeLinejoin:"round"}),r.jsx("path",{d:"M2 17l10 5 10-5",strokeLinecap:"round",strokeLinejoin:"round"})]})}),r.jsx("h3",{className:"text-[14px] font-semibold text-cc-fg mb-1",children:"No gallery entries yet"}),r.jsx("p",{className:"text-[12px] text-cc-fg/50 max-w-xs",children:"Publish your best sessions to showcase them. Vote on entries to surface the most interesting ones."}),!Z&&r.jsx("button",{onClick:()=>I(!0),className:"mt-4 px-4 py-2 rounded-lg text-[12px] font-medium bg-cc-primary hover:bg-cc-primary-hover text-white shadow-sm transition-colors cursor-pointer",children:"Publish First Entry"})]}):r.jsx("div",{className:"space-y-3",children:n.map(ne=>r.jsx(oh,{entry:ne,onVote:M,onDelete:O,onFeature:W,onExportClawHub:U,clawHubAvailable:N,onPostMoltbook:D,moltbookAvailable:K,onCreatePublicLink:$},ne.id))})]});return e?r.jsx("div",{className:"h-full bg-cc-bg overflow-y-auto text-cc-fg",children:be}):r.jsx("div",{className:"h-full bg-cc-bg overflow-y-auto text-cc-fg",children:be})}const rH=[{value:"session.created",label:"Session Created"},{value:"session.completed",label:"Session Completed"},{value:"session.failed",label:"Session Failed"},{value:"permission.requested",label:"Permission Requested"},{value:"permission.resolved",label:"Permission Resolved"},{value:"turn.completed",label:"Turn Completed"},{value:"cost.threshold",label:"Cost Threshold"}];function iH(e){const t=Date.now()-e,s=Math.floor(t/6e4);if(s<1)return"just now";if(s<60)return`${s}m ago`;const n=Math.floor(s/60);return n<24?`${n}h ago`:`${Math.floor(n/24)}d ago`}const Dg={name:"",url:"",events:["session.completed"],secret:"",format:"generic",backendFilter:"",cwdFilter:""};function aH({onClose:e,embedded:t=!1}){const[s,n]=w.useState([]),[a,l]=w.useState(!0),[c,d]=w.useState(""),[f,h]=w.useState(null),[m,g]=w.useState(Dg),[b,v]=w.useState(Dg),[y,S]=w.useState(!1),[j,k]=w.useState(!0),[E,N]=w.useState(new Set),[B,A]=w.useState(new Map),P=w.useCallback(()=>{se.listWebhooks().then(n).catch(()=>{}).finally(()=>l(!1))},[]);w.useEffect(()=>{P();const O=setInterval(P,15e3);return()=>clearInterval(O)},[P]);async function K(){const O=b.name.trim(),W=b.url.trim();if(!(!O||!W||b.events.length===0)){S(!0),d("");try{const U={};b.backendFilter&&(U.backendType=b.backendFilter),b.cwdFilter.trim()&&(U.cwd=b.cwdFilter.trim()),await se.createWebhook({name:O,url:W,events:b.events,secret:b.secret.trim()||void 0,format:b.format||void 0,sessionFilter:Object.keys(U).length>0?U:void 0}),v(Dg),k(!0),P()}catch(U){d(U instanceof Error?U.message:String(U))}finally{S(!1)}}}function X(O){var W,U;h(O.id),g({name:O.name,url:O.url,events:[...O.events],secret:O.secret||"",format:O.format||"generic",backendFilter:((W=O.sessionFilter)==null?void 0:W.backendType)||"",cwdFilter:((U=O.sessionFilter)==null?void 0:U.cwd)||""}),d("")}function Z(){h(null),d("")}async function I(){if(!f)return;const O=m.name.trim(),W=m.url.trim();if(!(!O||!W||m.events.length===0))try{const U={};m.backendFilter&&(U.backendType=m.backendFilter),m.cwdFilter.trim()&&(U.cwd=m.cwdFilter.trim()),await se.updateWebhook(f,{name:O,url:W,events:m.events,secret:m.secret.trim()||void 0,format:m.format||void 0,sessionFilter:Object.keys(U).length>0?U:void 0}),h(null),d(""),P()}catch(U){d(U instanceof Error?U.message:String(U))}}async function H(O){try{await se.deleteWebhook(O),f===O&&h(null),P()}catch(W){d(W instanceof Error?W.message:String(W))}}async function F(O){try{await se.toggleWebhook(O),P()}catch(W){d(W instanceof Error?W.message:String(W))}}async function G(O){N(W=>new Set(W).add(O)),A(W=>{const U=new Map(W);return U.delete(O),U});try{const W=await se.testWebhook(O);A(U=>new Map(U).set(O,W.ok)),P()}catch{A(W=>new Map(W).set(O,!1))}finally{N(W=>{const U=new Set(W);return U.delete(O),U})}}const q=c&&r.jsx("div",{className:"px-3 py-2 rounded-lg bg-cc-error/10 border border-cc-error/20 text-xs text-cc-error",children:c}),R=a?r.jsx("div",{className:"text-sm text-cc-muted text-center py-6",children:"Loading webhooks..."}):s.length===0?r.jsx("div",{className:"text-sm text-cc-muted text-center py-6",children:"No webhooks configured. Create one below."}):r.jsx("div",{className:"space-y-3",children:s.map(O=>{var W,U;return r.jsxs("div",{className:"border border-cc-border rounded-lg overflow-hidden bg-cc-card",children:[r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5 bg-cc-card border-b border-cc-border",children:[r.jsx("span",{className:"text-sm font-medium text-cc-fg flex-1 truncate",children:O.name}),O.totalDeliveries>0&&r.jsxs("span",{className:`text-[9px] font-medium px-1.5 rounded-full leading-[16px] shrink-0 ${O.failedDeliveries>0?"text-cc-error bg-cc-error/10":"text-cc-success bg-cc-success/10"}`,children:[O.totalDeliveries-O.failedDeliveries,"/",O.totalDeliveries]}),r.jsx("button",{onClick:()=>F(O.id),className:`relative w-8 h-[18px] rounded-full transition-colors cursor-pointer shrink-0 ${O.enabled?"bg-cc-primary":"bg-cc-border"}`,title:O.enabled?"Disable":"Enable",children:r.jsx("span",{className:`absolute top-[2px] w-[14px] h-[14px] rounded-full bg-white transition-transform ${O.enabled?"left-[16px]":"left-[2px]"}`})}),f===O.id?r.jsx("button",{onClick:Z,className:"text-xs text-cc-muted hover:text-cc-fg cursor-pointer",children:"Cancel"}):r.jsxs(r.Fragment,{children:[r.jsx("button",{onClick:()=>G(O.id),disabled:E.has(O.id),className:`text-xs cursor-pointer ${E.has(O.id)?"text-cc-muted cursor-not-allowed":"text-cc-primary hover:text-cc-primary-hover"}`,children:E.has(O.id)?"Testing...":"Test"}),B.has(O.id)&&r.jsx("span",{className:`text-[10px] ${B.get(O.id)?"text-cc-success":"text-cc-error"}`,children:B.get(O.id)?"OK":"Failed"}),r.jsx("button",{onClick:()=>X(O),className:"text-xs text-cc-muted hover:text-cc-fg cursor-pointer",children:"Edit"}),r.jsx("button",{onClick:()=>H(O.id),className:"text-xs text-cc-muted hover:text-cc-error cursor-pointer",children:"Delete"})]})]}),f===O.id&&r.jsxs("div",{className:"px-3 py-3 space-y-2.5",children:[r.jsx(fS,{form:m,onChange:g}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("button",{onClick:I,className:"px-3 py-2 text-xs font-medium bg-cc-primary hover:bg-cc-primary-hover text-white rounded-lg transition-colors cursor-pointer",children:"Save"}),r.jsx("button",{onClick:Z,className:"px-3 py-2 text-xs font-medium text-cc-muted hover:text-cc-fg rounded-lg transition-colors cursor-pointer",children:"Cancel"})]})]}),f!==O.id&&r.jsxs("div",{className:"px-3 py-2.5 space-y-1.5",children:[r.jsx("div",{className:"text-xs text-cc-muted font-mono-code truncate",title:O.url,children:O.url}),r.jsx("div",{className:"flex flex-wrap items-center gap-1.5",children:O.events.map(D=>r.jsx("span",{className:"text-[9px] font-medium px-1.5 py-0.5 rounded-full bg-cc-hover text-cc-muted",children:D},D))}),r.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px] text-cc-muted",children:[O.secret&&r.jsxs("span",{className:"flex items-center gap-1",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3",children:r.jsx("path",{d:"M8 1a3.5 3.5 0 00-3.5 3.5V7H4a1 1 0 00-1 1v5a1 1 0 001 1h8a1 1 0 001-1V8a1 1 0 00-1-1h-.5V4.5A3.5 3.5 0 008 1zm2 6H6V4.5a2 2 0 114 0V7z"})}),"Signed"]}),O.lastDeliveryAt&&r.jsxs("span",{className:"flex items-center gap-1",children:["Last: ",iH(O.lastDeliveryAt),O.lastDeliverySuccess?r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 text-cc-success",children:r.jsx("path",{d:"M12.207 4.793a1 1 0 010 1.414l-5 5a1 1 0 01-1.414 0l-2.5-2.5a1 1 0 011.414-1.414L6.5 9.086l4.293-4.293a1 1 0 011.414 0z"})}):r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 text-cc-error",children:r.jsx("path",{d:"M4.646 4.646a.5.5 0 01.708 0L8 7.293l2.646-2.647a.5.5 0 01.708.708L8.707 8l2.647 2.646a.5.5 0 01-.708.708L8 8.707l-2.646 2.647a.5.5 0 01-.708-.708L7.293 8 4.646 5.354a.5.5 0 010-.708z"})})]}),((W=O.sessionFilter)==null?void 0:W.backendType)&&r.jsxs("span",{children:["Filter: ",O.sessionFilter.backendType]}),((U=O.sessionFilter)==null?void 0:U.cwd)&&r.jsx("span",{className:"font-mono-code truncate max-w-[200px]",title:O.sessionFilter.cwd,children:O.sessionFilter.cwd})]})]})]},O.id)})}),M=r.jsxs("div",{className:"border border-cc-border rounded-lg overflow-hidden bg-cc-card",children:[r.jsxs("button",{onClick:()=>k(!j),className:"w-full flex items-center gap-2 px-3 py-2.5 bg-cc-card border-b border-cc-border cursor-pointer hover:bg-cc-hover transition-colors",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",className:`w-3 h-3 text-cc-muted transition-transform ${j?"":"rotate-90"}`,children:r.jsx("path",{d:"M6 4l4 4-4 4",strokeLinecap:"round",strokeLinejoin:"round"})}),r.jsx("span",{className:"text-sm font-medium text-cc-fg",children:"New Webhook"})]}),!j&&r.jsxs("div",{className:"px-3 py-3 space-y-2.5",children:[r.jsx(fS,{form:b,onChange:v}),r.jsx("button",{onClick:K,disabled:!b.name.trim()||!b.url.trim()||b.events.length===0||y,className:`px-3 py-2 text-xs font-medium rounded-lg transition-colors ${b.name.trim()&&b.url.trim()&&b.events.length>0&&!y?"bg-cc-primary hover:bg-cc-primary-hover text-white cursor-pointer":"bg-cc-hover text-cc-muted cursor-not-allowed"}`,children:y?"Creating...":"Create"})]})]});return t?r.jsx("div",{className:"h-full bg-cc-bg overflow-y-auto",children:r.jsxs("div",{className:"max-w-5xl mx-auto px-4 sm:px-8 py-6 sm:py-10",children:[r.jsxs("div",{className:"mb-6",children:[r.jsx("h1",{className:"text-xl font-semibold text-cc-fg",children:"Webhooks"}),r.jsx("p",{className:"mt-1 text-sm text-cc-muted",children:"Receive HTTP notifications when session events occur."})]}),q,r.jsxs("div",{className:"mt-4 space-y-4",children:[r.jsxs("section",{className:"bg-cc-card border border-cc-border rounded-xl p-4 sm:p-5 space-y-3",children:[r.jsx("h2",{className:"text-sm font-semibold text-cc-fg",children:"Configured Webhooks"}),R]}),r.jsx("section",{className:"bg-cc-card border border-cc-border rounded-xl p-4 sm:p-5 space-y-3",children:M})]})]})}):null}function fS({form:e,onChange:t}){const s=a=>t({...e,...a});function n(a){const l=e.events.includes(a)?e.events.filter(c=>c!==a):[...e.events,a];s({events:l})}return r.jsxs("div",{className:"space-y-2.5",children:[r.jsx("input",{type:"text",value:e.name,onChange:a=>s({name:a.target.value}),placeholder:"Webhook name (e.g. Slack notifications)",className:"w-full px-3 py-2 text-sm bg-cc-input-bg border border-cc-border rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:border-cc-primary/50"}),r.jsx("input",{type:"text",value:e.url,onChange:a=>s({url:a.target.value}),placeholder:"https://hooks.slack.com/services/...",className:"w-full px-3 py-2 text-sm font-mono-code bg-cc-input-bg border border-cc-border rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:border-cc-primary/50"}),r.jsxs("div",{children:[r.jsx("div",{className:"text-[11px] font-medium text-cc-muted mb-1.5",children:"Payload Format"}),r.jsx("div",{className:"flex gap-1.5",children:[{value:"generic",label:"Generic"},{value:"slack",label:"Slack"},{value:"openclaw",label:"OpenClaw"}].map(a=>r.jsx("button",{onClick:()=>s({format:a.value}),className:`px-2 py-1 text-[10px] font-medium rounded-md transition-colors cursor-pointer ${e.format===a.value?"bg-cc-primary/20 text-cc-primary border border-cc-primary/30":"bg-cc-hover text-cc-muted hover:text-cc-fg border border-transparent"}`,children:a.label},a.value))}),e.format==="openclaw"&&r.jsx("div",{className:"mt-1 text-[10px] text-cc-muted",children:"Posts to OpenClaw /hooks/agent endpoint. Use the signing secret field for the Bearer token."})]}),r.jsxs("div",{children:[r.jsx("div",{className:"text-[11px] font-medium text-cc-muted mb-1.5",children:"Events"}),r.jsx("div",{className:"flex flex-wrap gap-1.5",children:rH.map(a=>r.jsx("button",{onClick:()=>n(a.value),className:`px-2 py-1 text-[10px] font-medium rounded-md transition-colors cursor-pointer ${e.events.includes(a.value)?"bg-cc-primary/20 text-cc-primary border border-cc-primary/30":"bg-cc-hover text-cc-muted hover:text-cc-fg border border-transparent"}`,children:a.label},a.value))})]}),r.jsx("input",{type:"password",value:e.secret,onChange:a=>s({secret:a.target.value}),placeholder:"Signing secret (optional, for HMAC-SHA256)",className:"w-full px-3 py-2 text-sm bg-cc-input-bg border border-cc-border rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:border-cc-primary/50"}),r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsxs("select",{value:e.backendFilter,onChange:a=>s({backendFilter:a.target.value}),className:"px-2 py-1.5 text-xs bg-cc-input-bg border border-cc-border rounded-lg text-cc-fg focus:outline-none focus:border-cc-primary/50",children:[r.jsx("option",{value:"",children:"All backends"}),r.jsx("option",{value:"claude",children:"Claude Code"}),r.jsx("option",{value:"codex",children:"Codex"}),r.jsx("option",{value:"goose",children:"Goose"}),r.jsx("option",{value:"aider",children:"Aider"}),r.jsx("option",{value:"openhands",children:"OpenHands"}),r.jsx("option",{value:"openclaw",children:"OpenClaw"})]}),r.jsx("input",{type:"text",value:e.cwdFilter,onChange:a=>s({cwdFilter:a.target.value}),placeholder:"Filter by path prefix (optional)",className:"flex-1 px-2 py-1.5 text-xs font-mono-code bg-cc-input-bg border border-cc-border rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:border-cc-primary/50"})]})]})}function oH(e){const t=Date.now()-e,s=Math.floor(t/6e4);if(s<1)return"just now";if(s<60)return`${s}m ago`;const n=Math.floor(s/60);return n<24?`${n}h ago`:`${Math.floor(n/24)}d ago`}const lH={stdio:"stdio",websocket:"WebSocket",http:"HTTP"};function cH({embedded:e=!1}){const[t,s]=w.useState([]),[n,a]=w.useState(!0),[l,c]=w.useState(""),[d,f]=w.useState(""),[h,m]=w.useState(!1),[g,b]=w.useState(new Set),v=w.useCallback(()=>{se.listAdapters().then(s).catch(()=>{}).finally(()=>a(!1))},[]);w.useEffect(()=>{v();const N=setInterval(v,3e4);return()=>clearInterval(N)},[v]);async function y(){const N=d.trim();if(N){m(!0),c("");try{await se.installAdapter(N),f(""),v()}catch(B){c(B instanceof Error?B.message:String(B))}finally{m(!1)}}}async function S(N){b(B=>new Set(B).add(N));try{await se.uninstallAdapter(N),v()}catch(B){c(B instanceof Error?B.message:String(B))}finally{b(B=>{const A=new Set(B);return A.delete(N),A})}}const j=l&&r.jsx("div",{className:"px-3 py-2 rounded-lg bg-cc-error/10 border border-cc-error/20 text-xs text-cc-error",children:l}),k=n?r.jsx("div",{className:"text-sm text-cc-muted text-center py-6",children:"Loading adapters..."}):t.length===0?r.jsx("div",{className:"text-sm text-cc-muted text-center py-6",children:"No community adapters installed. Install one below."}):r.jsx("div",{className:"space-y-3",children:t.map(N=>{const B=N.metadata;return r.jsxs("div",{className:"border border-cc-border rounded-lg overflow-hidden bg-cc-card",children:[r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5 bg-cc-card border-b border-cc-border",children:[r.jsx("span",{className:"text-sm font-medium text-cc-fg flex-1 truncate",children:B.displayName}),r.jsxs("span",{className:"text-[9px] font-medium px-1.5 rounded-full leading-[16px] shrink-0 text-cc-muted bg-cc-hover",children:["v",B.version]}),r.jsx("span",{className:"text-[9px] font-medium px-1.5 rounded-full leading-[16px] shrink-0 text-blue-500 bg-blue-500/10",children:lH[B.protocol]||B.protocol}),r.jsx("button",{onClick:()=>S(B.name),disabled:g.has(B.name),className:`text-xs cursor-pointer ${g.has(B.name)?"text-cc-muted cursor-not-allowed":"text-cc-muted hover:text-cc-error"}`,children:g.has(B.name)?"Removing...":"Uninstall"})]}),r.jsxs("div",{className:"px-3 py-2.5 space-y-1.5",children:[B.description&&r.jsx("div",{className:"text-xs text-cc-muted",children:B.description}),r.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px] text-cc-muted",children:[r.jsx("span",{className:"font-mono-code",children:B.name}),r.jsxs("span",{children:[B.models.length," model",B.models.length!==1?"s":""]}),B.binaryName&&r.jsx("span",{className:"font-mono-code",children:B.binaryName}),B.author&&r.jsxs("span",{children:["by ",B.author]}),r.jsxs("span",{children:["Installed ",oH(N.installedAt)]}),r.jsx("span",{className:"font-mono-code",children:N.npmPackage})]}),B.models.length>1&&r.jsx("div",{className:"flex flex-wrap gap-1",children:B.models.map(A=>r.jsx("span",{className:"text-[9px] font-medium px-1.5 py-0.5 rounded-full bg-cc-hover text-cc-muted",children:A.label},A.value))})]})]},B.name)})}),E=r.jsxs("div",{className:"space-y-2.5",children:[r.jsx("div",{className:"text-[11px] font-medium text-cc-muted",children:"Install a community adapter from npm"}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"text",value:d,onChange:N=>f(N.target.value),onKeyDown:N=>N.key==="Enter"&&y(),placeholder:"@campfire/example-adapter",className:"flex-1 px-3 py-2 text-sm font-mono-code bg-cc-input-bg border border-cc-border rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:border-cc-primary/50"}),r.jsx("button",{onClick:y,disabled:!d.trim()||h,className:`px-3 py-2 text-xs font-medium rounded-lg transition-colors ${d.trim()&&!h?"bg-cc-primary hover:bg-cc-primary-hover text-white cursor-pointer":"bg-cc-hover text-cc-muted cursor-not-allowed"}`,children:h?"Installing...":"Install"})]}),r.jsx("div",{className:"text-[10px] text-cc-muted",children:'Adapters must declare a "campfireAdapter" field in their package.json'})]});return e?r.jsx("div",{className:"h-full bg-cc-bg overflow-y-auto",children:r.jsxs("div",{className:"max-w-5xl mx-auto px-4 sm:px-8 py-6 sm:py-10",children:[r.jsxs("div",{className:"mb-6",children:[r.jsx("h1",{className:"text-xl font-semibold text-cc-fg",children:"Adapters"}),r.jsx("p",{className:"mt-1 text-sm text-cc-muted",children:"Install and manage community agent adapters."})]}),j,r.jsxs("div",{className:"mt-4 space-y-4",children:[r.jsxs("section",{className:"bg-cc-card border border-cc-border rounded-xl p-4 sm:p-5 space-y-3",children:[r.jsx("h2",{className:"text-sm font-semibold text-cc-fg",children:"Installed Adapters"}),k]}),r.jsxs("section",{className:"bg-cc-card border border-cc-border rounded-xl p-4 sm:p-5 space-y-3",children:[r.jsx("h2",{className:"text-sm font-semibold text-cc-fg",children:"Install Adapter"}),E]})]})]})}):null}function uH({onClose:e,embedded:t=!1}){const[s,n]=w.useState(null),[a,l]=w.useState(""),[c,d]=w.useState([]),[f,h]=w.useState(!1),[m,g]=w.useState(null),[b,v]=w.useState(new Map),[y,S]=w.useState("");w.useEffect(()=>{se.getClawHubStatus().then(N=>n(N.available)).catch(()=>n(!1))},[]);const j=w.useCallback(async()=>{if(a.trim()){h(!0),S("");try{const N=await se.searchClawHub(a.trim());d(N)}catch(N){S(N instanceof Error?N.message:String(N))}finally{h(!1)}}},[a]);async function k(N){g(N),v(B=>{const A=new Map(B);return A.delete(N),A});try{const B=await se.installClawHubSkill(N);v(A=>new Map(A).set(N,B.ok))}catch{v(B=>new Map(B).set(N,!1))}finally{g(null)}}if(s===null)return r.jsx("div",{className:"text-sm text-cc-muted text-center py-10",children:"Checking ClawHub availability..."});if(!s)return r.jsx("div",{className:"h-full bg-cc-bg overflow-y-auto",children:r.jsxs("div",{className:"max-w-5xl mx-auto px-4 sm:px-8 py-6 sm:py-10",children:[r.jsx("h1",{className:"text-xl font-semibold text-cc-fg",children:"ClawHub Skills"}),r.jsxs("div",{className:"mt-4 p-6 bg-cc-card border border-cc-border rounded-xl text-center",children:[r.jsxs("p",{className:"text-sm text-cc-muted mb-3",children:["The ",r.jsx("code",{className:"text-cc-fg bg-cc-hover px-1 rounded",children:"clawhub"})," CLI is not installed."]}),r.jsxs("p",{className:"text-xs text-cc-muted",children:["Install it with: ",r.jsx("code",{className:"text-cc-fg bg-cc-hover px-1 rounded",children:"npm install -g clawhub"})]})]})]})});const E=r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"mb-6",children:[r.jsx("h1",{className:"text-xl font-semibold text-cc-fg",children:"ClawHub Skills"}),r.jsx("p",{className:"mt-1 text-sm text-cc-muted",children:"Browse and install skills from the OpenClaw skill marketplace."})]}),y&&r.jsx("div",{className:"mb-4 px-3 py-2 rounded-lg bg-cc-error/10 border border-cc-error/20 text-xs text-cc-error",children:y}),r.jsxs("div",{className:"flex gap-2 mb-4",children:[r.jsx("input",{type:"text",value:a,onChange:N=>l(N.target.value),onKeyDown:N=>N.key==="Enter"&&j(),placeholder:"Search skills (e.g. 'code review', 'email', 'slack')",className:"flex-1 px-3 py-2 text-sm bg-cc-input-bg border border-cc-border rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:border-cc-primary/50"}),r.jsx("button",{onClick:j,disabled:f||!a.trim(),className:`px-4 py-2 text-sm font-medium rounded-lg transition-colors ${!f&&a.trim()?"bg-cc-primary hover:bg-cc-primary-hover text-white cursor-pointer":"bg-cc-hover text-cc-muted cursor-not-allowed"}`,children:f?"Searching...":"Search"})]}),c.length>0?r.jsx("div",{className:"space-y-3",children:c.map(N=>r.jsx("div",{className:"border border-cc-border rounded-lg overflow-hidden bg-cc-card",children:r.jsxs("div",{className:"flex items-center gap-3 px-4 py-3",children:[r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-sm font-medium text-cc-fg",children:N.name}),r.jsxs("span",{className:"text-[10px] text-cc-muted bg-cc-hover px-1.5 py-0.5 rounded",children:["v",N.version]})]}),r.jsx("p",{className:"text-xs text-cc-muted mt-0.5 truncate",children:N.description}),r.jsxs("div",{className:"flex items-center gap-3 mt-1 text-[10px] text-cc-muted",children:[N.author&&r.jsxs("span",{children:["by ",N.author]}),N.downloads!==void 0&&r.jsxs("span",{children:[N.downloads.toLocaleString()," downloads"]})]})]}),r.jsx("button",{onClick:()=>k(N.name),disabled:m===N.name,className:`shrink-0 px-3 py-1.5 text-xs font-medium rounded-lg transition-colors ${m===N.name?"bg-cc-hover text-cc-muted cursor-not-allowed":b.get(N.name)===!0?"bg-cc-success/20 text-cc-success cursor-default":b.get(N.name)===!1?"bg-cc-error/20 text-cc-error cursor-pointer":"bg-cc-primary/20 text-cc-primary hover:bg-cc-primary/30 cursor-pointer"}`,children:m===N.name?"Installing...":b.get(N.name)===!0?"Installed":b.get(N.name)===!1?"Failed — Retry":"Install"})]})},N.name))}):!f&&a?r.jsxs("div",{className:"text-sm text-cc-muted text-center py-8",children:["No skills found for “",a,"”"]}):f?null:r.jsx("div",{className:"text-sm text-cc-muted text-center py-8",children:"Enter a search term to browse ClawHub skills."})]});return t?r.jsx("div",{className:"h-full bg-cc-bg overflow-y-auto",children:r.jsx("div",{className:"max-w-5xl mx-auto px-4 sm:px-8 py-6 sm:py-10",children:E})}):null}const dH=w.lazy(()=>Xi(()=>Promise.resolve().then(()=>fu),void 0).then(e=>({default:e.CodeEditor})));function NN(e){const t=Date.now()-e,s=Math.floor(t/6e4);if(s<1)return"just now";if(s<60)return`${s}m ago`;const n=Math.floor(s/60);return n<24?`${n}h ago`:`${Math.floor(n/24)}d ago`}function hH(e){const t=e-Date.now();if(t<=0)return"now";const s=Math.floor(t/6e4);if(s<60)return`in ${s}m`;const n=Math.floor(s/60);return n<24?`in ${n}h`:`in ${Math.floor(n/24)}d`}const fH={claude:"text-[#5BA8A0] bg-[#5BA8A0]/10",codex:"text-blue-500 bg-blue-500/10",goose:"text-amber-500 bg-amber-500/10",aider:"text-purple-500 bg-purple-500/10",openhands:"text-rose-500 bg-rose-500/10",openclaw:"text-orange-500 bg-orange-500/10",opencode:"text-teal-500 bg-teal-500/10"},pH=[{value:"claude",label:"Claude"},{value:"codex",label:"Codex"},{value:"goose",label:"Goose"},{value:"aider",label:"Aider"},{value:"openhands",label:"OpenHands"},{value:"openclaw",label:"OpenClaw"},{value:"opencode",label:"OpenCode"}],pS={name:"",description:"",icon:"🤖",backendType:"claude",model:ri("claude"),permissionMode:Qc("claude"),cwd:"",prompt:"",envSlug:"",webhookEnabled:!1,scheduleEnabled:!1,scheduleExpression:"0 8 * * *",scheduleRecurring:!0,codexInternetAccess:!1},mH=[{label:"Every hour",value:"0 * * * *"},{label:"Daily at 8am",value:"0 8 * * *"},{label:"Every 2 hours",value:"0 */2 * * *"},{label:"Weekdays at 9am",value:"0 9 * * 1-5"}],gH=["🤖","🔥","⚡","🚀","🧪","🔧","📋","🔍","🎯","📦"];function xH({embedded:e=!1}){var $;const[t,s]=w.useState([]),[n,a]=w.useState(!0),[l,c]=w.useState(""),[d,f]=w.useState(!1),[h,m]=w.useState(null),[g,b]=w.useState(pS),[v,y]=w.useState(!1),[S,j]=w.useState(null),[k,E]=w.useState(""),[N,B]=w.useState(null),[A,P]=w.useState([]),[K,X]=w.useState("all"),[Z,I]=w.useState([]),H=w.useCallback(()=>{se.listAgents().then(s).catch(()=>{}).finally(()=>a(!1))},[]);w.useEffect(()=>{H(),se.listEnvs().then(I).catch(()=>{});const z=setInterval(H,1e4);return()=>clearInterval(z)},[H]),w.useEffect(()=>{N&&se.getAgentExecutions(N).then(P).catch(()=>P([]))},[N]);function F(){m(null),b(pS),f(!0),c("")}function G(z){var T,ae,be,ne,ve,Ae,De,ke;m(z.id),b({name:z.name,description:z.description,icon:z.icon||"🤖",backendType:z.backendType,model:z.model,permissionMode:z.permissionMode,cwd:z.cwd,prompt:z.prompt,envSlug:z.envSlug||"",webhookEnabled:((ae=(T=z.triggers)==null?void 0:T.webhook)==null?void 0:ae.enabled)||!1,scheduleEnabled:((ne=(be=z.triggers)==null?void 0:be.schedule)==null?void 0:ne.enabled)||!1,scheduleExpression:((Ae=(ve=z.triggers)==null?void 0:ve.schedule)==null?void 0:Ae.expression)||"0 8 * * *",scheduleRecurring:((ke=(De=z.triggers)==null?void 0:De.schedule)==null?void 0:ke.recurring)??!0,codexInternetAccess:z.codexInternetAccess||!1}),f(!0),c("")}async function q(){if(!g.name.trim()||!g.prompt.trim()||!g.cwd.trim()){c("Name, prompt, and working directory are required");return}y(!0),c("");const z={name:g.name,description:g.description,icon:g.icon,backendType:g.backendType,model:g.backendType==="codex"?"":g.model,permissionMode:g.permissionMode,cwd:g.cwd,prompt:g.prompt,envSlug:g.envSlug||void 0,codexInternetAccess:g.backendType==="codex"?g.codexInternetAccess:void 0,triggers:{webhook:{enabled:g.webhookEnabled},schedule:g.scheduleEnabled?{enabled:!0,expression:g.scheduleExpression,recurring:g.scheduleRecurring}:{enabled:!1,expression:"",recurring:!0}}};try{h?await se.updateAgentProfile(h,z):await se.createAgent(z),f(!1),m(null),H()}catch(T){c(T instanceof Error?T.message:"Unknown error")}finally{y(!1)}}async function R(z){try{await se.deleteAgent(z),H()}catch{}}async function M(z){try{await se.toggleAgent(z),H()}catch{}}async function O(z){if(z.prompt.includes("{{input}}"))j(z),E("");else try{await se.runAgent(z.id),H()}catch{}}async function W(){if(S)try{await se.runAgent(S.id,k),j(null),H()}catch{}}const U=t.filter(z=>{var T,ae,be,ne;return K==="enabled"?z.enabled:K==="scheduled"?(ae=(T=z.triggers)==null?void 0:T.schedule)==null?void 0:ae.enabled:K==="webhook"?(ne=(be=z.triggers)==null?void 0:be.webhook)==null?void 0:ne.enabled:!0}),D={all:t.length,enabled:t.filter(z=>z.enabled).length,scheduled:t.filter(z=>{var T,ae;return(ae=(T=z.triggers)==null?void 0:T.schedule)==null?void 0:ae.enabled}).length,webhook:t.filter(z=>{var T,ae;return(ae=(T=z.triggers)==null?void 0:T.webhook)==null?void 0:ae.enabled}).length};return r.jsxs("div",{className:e?"px-4 py-6 max-w-4xl mx-auto":"p-6 max-w-4xl mx-auto",children:[r.jsxs("div",{className:"flex items-center justify-between mb-6",children:[r.jsxs("div",{children:[r.jsx("h1",{className:"text-lg font-semibold text-cc-fg",children:"Agents"}),r.jsx("p",{className:"text-[12px] text-cc-muted mt-0.5",children:"Persistent agent profiles with automated triggers"})]}),r.jsx("button",{onClick:F,className:"px-3 py-1.5 rounded-lg bg-cc-primary text-white text-[12px] font-medium hover:bg-cc-primary-hover transition-colors cursor-pointer",children:"+ Create Agent"})]}),r.jsx("div",{className:"flex gap-1 mb-4",children:["all","enabled","scheduled","webhook"].map(z=>r.jsxs("button",{onClick:()=>X(z),className:`px-2.5 py-1 rounded-md text-[11px] font-medium transition-colors cursor-pointer ${K===z?"bg-cc-primary/10 text-cc-primary":"text-cc-muted hover:text-cc-fg hover:bg-cc-hover"}`,children:[z.charAt(0).toUpperCase()+z.slice(1),r.jsx("span",{className:"ml-1 text-[10px] opacity-60 tabular-nums",children:D[z]})]},z))}),n&&r.jsx("p",{className:"text-cc-muted text-sm",children:"Loading..."}),!n&&U.length===0&&r.jsxs("div",{className:"text-center py-12 text-cc-muted",children:[r.jsx("p",{className:"text-sm",children:"No agents yet"}),r.jsx("p",{className:"text-xs mt-1",children:"Create your first agent to automate tasks across any backend"})]}),r.jsx("div",{className:"space-y-2",children:U.map(z=>r.jsxs("div",{children:[r.jsx(yH,{agent:z,onEdit:()=>G(z),onDelete:()=>R(z.id),onToggle:()=>M(z.id),onRun:()=>O(z),expanded:N===z.id,onExpand:()=>B(N===z.id?null:z.id)}),N===z.id&&r.jsxs("div",{className:"ml-8 mt-1 mb-3 space-y-1",children:[A.length===0&&r.jsx("p",{className:"text-[11px] text-cc-muted",children:"No executions yet"}),A.slice(0,10).map(T=>r.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-cc-muted px-2 py-1 rounded bg-cc-hover/50",children:[r.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${vH(T)}`}),r.jsx("span",{className:"font-mono-code",children:T.trigger}),r.jsx("span",{className:"flex-1 truncate",children:T.input?`"${T.input.slice(0,40)}"`:""}),r.jsx("span",{className:"font-mono-code tabular-nums",children:NN(T.startedAt)}),T.error&&r.jsx("span",{className:"text-cc-error truncate max-w-[120px]",children:T.error})]},T.executionId))]})]},z.id))}),d&&r.jsx("dialog",{open:!0,className:"fixed inset-0 z-50 flex items-center justify-center bg-black/30 backdrop-blur-sm w-full h-full m-0 p-0 border-none",children:r.jsxs("div",{className:"w-full max-w-lg max-h-[85vh] overflow-y-auto bg-cc-card border border-cc-border rounded-xl shadow-float p-5 m-auto",children:[r.jsx("h2",{className:"text-sm font-semibold text-cc-fg mb-4",children:h?"Edit Agent":"Create Agent"}),l&&r.jsx("p",{className:"text-[11px] text-cc-error mb-3 bg-cc-error/5 px-3 py-1.5 rounded",children:l}),r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{className:"flex gap-2",children:[r.jsx("select",{value:g.icon,onChange:z=>b({...g,icon:z.target.value}),className:"w-12 h-9 rounded-lg border border-cc-border bg-cc-input-bg text-center text-base cursor-pointer",children:gH.map(z=>r.jsx("option",{value:z,children:z},z))}),r.jsx("input",{value:g.name,onChange:z=>b({...g,name:z.target.value}),placeholder:"Agent name",className:"flex-1 h-9 px-3 rounded-lg border border-cc-border bg-cc-input-bg text-[13px] text-cc-fg"})]}),r.jsx("input",{value:g.description,onChange:z=>b({...g,description:z.target.value}),placeholder:"Short description (optional)",className:"w-full h-9 px-3 rounded-lg border border-cc-border bg-cc-input-bg text-[13px] text-cc-fg"}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("select",{value:g.backendType,onChange:z=>{const T=z.target.value;b({...g,backendType:T,model:ri(T),permissionMode:Qc(T)})},className:"h-9 px-2 rounded-lg border border-cc-border bg-cc-input-bg text-[12px] text-cc-fg cursor-pointer",children:pH.map(z=>r.jsx("option",{value:z.value,children:z.label},z.value))}),g.backendType==="codex"?r.jsx("div",{className:"flex-1 h-9 px-2 rounded-lg border border-cc-border bg-cc-input-bg text-[12px] text-cc-muted flex items-center",children:"Codex default"}):r.jsx("select",{value:g.model,onChange:z=>b({...g,model:z.target.value}),className:"flex-1 h-9 px-2 rounded-lg border border-cc-border bg-cc-input-bg text-[12px] text-cc-fg cursor-pointer",children:Zh(g.backendType).map(z=>r.jsx("option",{value:z.value,children:z.label},z.value))})]}),r.jsx("select",{value:g.permissionMode,onChange:z=>b({...g,permissionMode:z.target.value}),className:"w-full h-9 px-2 rounded-lg border border-cc-border bg-cc-input-bg text-[12px] text-cc-fg cursor-pointer",children:Ex(g.backendType).map(z=>r.jsx("option",{value:z.value,children:z.label},z.value))}),r.jsx("input",{value:g.cwd,onChange:z=>b({...g,cwd:z.target.value}),placeholder:"Working directory (absolute path)",className:"w-full h-9 px-3 rounded-lg border border-cc-border bg-cc-input-bg text-[13px] text-cc-fg font-mono-code"}),r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[r.jsx("label",{htmlFor:"agent-env-select",className:"text-[11px] text-cc-muted font-medium",children:"Environment"}),g.backendType==="codex"&&!g.envSlug&&r.jsx("span",{className:"text-[9px] text-cc-warning font-medium px-1.5 rounded-full bg-cc-warning/10",children:"Codex requires OPENAI_API_KEY"})]}),r.jsxs("select",{id:"agent-env-select",value:g.envSlug,onChange:z=>b({...g,envSlug:z.target.value}),className:`w-full h-9 px-2 rounded-lg border bg-cc-input-bg text-[12px] text-cc-fg cursor-pointer ${g.backendType==="codex"&&!g.envSlug?"border-cc-warning/50":"border-cc-border"}`,children:[r.jsx("option",{value:"",children:"No environment profile"}),Z.map(z=>r.jsxs("option",{value:z.slug,children:[z.name," (",Object.keys(z.variables).length," vars)"]},z.slug))]}),g.envSlug&&Z.length>0&&r.jsx("div",{className:"mt-1.5 flex flex-wrap gap-1",children:Object.keys((($=Z.find(z=>z.slug===g.envSlug))==null?void 0:$.variables)||{}).map(z=>r.jsx("span",{className:"text-[9px] font-mono-code px-1.5 py-0.5 rounded bg-cc-hover text-cc-muted",children:z},z))})]}),r.jsxs("div",{children:[r.jsx("label",{className:"text-[11px] font-medium text-cc-muted block mb-1",children:"Prompt"}),r.jsx(w.Suspense,{fallback:r.jsx("div",{className:"h-[180px] rounded-xl border border-cc-border flex items-center justify-center text-cc-muted text-[12px]",children:"Loading editor..."}),children:r.jsx(dH,{value:g.prompt,onChange:z=>b({...g,prompt:z}),language:"markdown",height:"180px",minimap:!1,wordWrap:!0,ariaLabel:"Agent prompt editor. Use {{input}} as a placeholder for trigger input."})})]}),g.backendType==="codex"&&r.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:g.codexInternetAccess,onChange:z=>b({...g,codexInternetAccess:z.target.checked}),className:"rounded"}),r.jsx("span",{className:"text-[12px] text-cc-fg",children:"Enable internet access (Codex)"})]}),r.jsxs("div",{className:"border border-cc-border/50 rounded-lg p-3 space-y-2.5",children:[r.jsx("span",{className:"text-[11px] font-semibold text-cc-muted uppercase tracking-wider",children:"Triggers"}),r.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:g.webhookEnabled,onChange:z=>b({...g,webhookEnabled:z.target.checked}),className:"rounded"}),r.jsx("span",{className:"text-[12px] text-cc-fg",children:"Webhook"})]}),r.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:g.scheduleEnabled,onChange:z=>b({...g,scheduleEnabled:z.target.checked}),className:"rounded"}),r.jsx("span",{className:"text-[12px] text-cc-fg",children:"Schedule"})]}),g.scheduleEnabled&&r.jsxs("div",{className:"ml-5 space-y-2",children:[r.jsx("div",{className:"flex gap-1.5 flex-wrap",children:mH.map(z=>r.jsx("button",{type:"button",onClick:()=>b({...g,scheduleExpression:z.value}),className:`px-2 py-0.5 rounded text-[10px] transition-colors cursor-pointer ${g.scheduleExpression===z.value?"bg-cc-primary/10 text-cc-primary":"bg-cc-hover text-cc-muted hover:text-cc-fg"}`,children:z.label},z.value))}),r.jsx("input",{value:g.scheduleExpression,onChange:z=>b({...g,scheduleExpression:z.target.value}),placeholder:"Cron expression",className:"w-full h-8 px-2 rounded border border-cc-border bg-cc-input-bg text-[12px] text-cc-fg font-mono-code"})]})]})]}),r.jsxs("div",{className:"flex justify-end gap-2 mt-5",children:[r.jsx("button",{onClick:()=>f(!1),className:"px-3 py-1.5 rounded-lg text-[12px] text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:"Cancel"}),r.jsx("button",{onClick:q,disabled:v,className:"px-4 py-1.5 rounded-lg bg-cc-primary text-white text-[12px] font-medium hover:bg-cc-primary-hover transition-colors cursor-pointer disabled:opacity-40",children:bH(v,h)})]})]})}),S&&r.jsx("dialog",{open:!0,className:"fixed inset-0 z-50 flex items-center justify-center bg-black/30 backdrop-blur-sm w-full h-full m-0 p-0 border-none",children:r.jsxs("div",{className:"w-full max-w-md bg-cc-card border border-cc-border rounded-xl shadow-float p-5 m-auto",children:[r.jsxs("h2",{className:"text-sm font-semibold text-cc-fg mb-1",children:["Run ",S.name]}),r.jsxs("p",{className:"text-[11px] text-cc-muted mb-3",children:["This agent uses ","{{input}}"," in its prompt. Provide the input below."]}),r.jsx("textarea",{value:k,onChange:z=>E(z.target.value),placeholder:"Enter input...",rows:4,className:"w-full px-3 py-2 rounded-lg border border-cc-border bg-cc-input-bg text-[13px] text-cc-fg resize-y",autoFocus:!0}),r.jsxs("div",{className:"flex justify-end gap-2 mt-3",children:[r.jsx("button",{onClick:()=>j(null),className:"px-3 py-1.5 rounded-lg text-[12px] text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:"Cancel"}),r.jsx("button",{onClick:W,className:"px-4 py-1.5 rounded-lg bg-cc-primary text-white text-[12px] font-medium hover:bg-cc-primary-hover transition-colors cursor-pointer",children:"Run"})]})]})})]})}function vH(e){return e.success===!1?"bg-cc-error":e.completedAt?"bg-cc-success":"bg-cc-primary animate-breathing"}function bH(e,t){return e?"Saving...":t?"Update":"Create"}function _H(e){return e.isRunning?"bg-cc-primary animate-breathing":e.enabled?"bg-cc-success":"bg-cc-muted/40"}function yH({agent:e,onEdit:t,onDelete:s,onToggle:n,onRun:a,expanded:l,onExpand:c}){var f,h,m,g;const d=fH[e.backendType]||"text-cc-muted bg-cc-hover";return r.jsx("div",{className:`border rounded-lg transition-all ${e.enabled?"border-cc-border bg-cc-card hover:shadow-panel":"border-cc-border/50 bg-cc-card/60 opacity-70"}`,children:r.jsxs("div",{className:"flex items-center gap-3 px-3 py-2.5",children:[r.jsxs("button",{onClick:c,className:"relative text-lg shrink-0 cursor-pointer",title:"Show executions",children:[e.icon||"🤖",r.jsx("span",{className:`absolute -bottom-0.5 -right-0.5 w-2 h-2 rounded-full border border-cc-card ${_H(e)}`})]}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:"text-[13px] font-medium text-cc-fg truncate",children:e.name}),r.jsx("span",{className:`text-[9px] font-medium px-1.5 rounded-full leading-[16px] ${d}`,children:e.backendType}),e.isRunning&&r.jsx("span",{className:"text-[9px] text-cc-primary font-mono-code",children:"running"})]}),r.jsxs("div",{className:"flex items-center gap-2 mt-0.5 text-[10px] text-cc-muted",children:[e.description&&r.jsx("span",{className:"truncate max-w-[200px]",children:e.description}),((h=(f=e.triggers)==null?void 0:f.schedule)==null?void 0:h.enabled)&&r.jsx("span",{className:"font-mono-code",children:"scheduled"}),((g=(m=e.triggers)==null?void 0:m.webhook)==null?void 0:g.enabled)&&r.jsx("span",{className:"font-mono-code",children:"webhook"}),e.totalRuns>0&&r.jsxs("span",{className:"tabular-nums",children:[e.totalRuns," runs"]}),e.lastRunAt!=null&&r.jsx("span",{className:"tabular-nums",children:NN(e.lastRunAt)}),e.nextRunAt!=null&&r.jsxs("span",{className:"tabular-nums",children:["next ",hH(e.nextRunAt)]})]})]}),r.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[r.jsx("button",{onClick:a,title:"Run now",className:"p-1.5 rounded-md hover:bg-cc-hover transition-colors cursor-pointer text-cc-primary",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:r.jsx("path",{d:"M4 2l10 6-10 6V2z"})})}),r.jsx("button",{onClick:n,title:e.enabled?"Disable":"Enable",className:"p-1.5 rounded-md hover:bg-cc-hover transition-colors cursor-pointer text-cc-muted",children:e.enabled?r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 text-cc-success",children:r.jsx("path",{d:"M8 2a6 6 0 100 12A6 6 0 008 2zm3.22 4.78l-4 4a.75.75 0 01-1.06 0l-2-2a.75.75 0 011.06-1.06L6.5 9l3.47-3.47a.75.75 0 011.06 1.06z"})}):r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:r.jsx("path",{d:"M8 2a6 6 0 100 12A6 6 0 008 2zm0 1.5a4.5 4.5 0 110 9 4.5 4.5 0 010-9z"})})}),r.jsx("button",{onClick:t,title:"Edit",className:"p-1.5 rounded-md hover:bg-cc-hover transition-colors cursor-pointer text-cc-muted",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:r.jsx("path",{d:"M11.013 1.427a1.75 1.75 0 012.474 0l1.086 1.086a1.75 1.75 0 010 2.474l-8.61 8.61c-.21.21-.47.364-.756.445l-3.251.93a.75.75 0 01-.927-.928l.929-3.25a1.75 1.75 0 01.445-.758l8.61-8.61z"})})}),r.jsx("button",{onClick:s,title:"Delete",className:"p-1.5 rounded-md hover:bg-cc-hover transition-colors cursor-pointer text-cc-muted hover:text-cc-error",children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:r.jsx("path",{d:"M6.5 1.75a.25.25 0 01.25-.25h2.5a.25.25 0 01.25.25V3h-3V1.75zM11 3V1.75A1.75 1.75 0 009.25 0h-2.5A1.75 1.75 0 005 1.75V3H2.75a.75.75 0 000 1.5h.928l.856 10.268A1.75 1.75 0 006.282 16h3.436a1.75 1.75 0 001.748-1.632l.856-10.268h.928a.75.75 0 000-1.5H11z"})})})]})]})})}function wH(e){return e===0?"$0":e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}function SH(e){if(e<6e4)return`${Math.round(e/1e3)}s`;const t=Math.floor(e/6e4);return t<60?`${t}m`:`${Math.floor(t/60)}h ${t%60}m`}let jH=0;function mS(){return`public-replay-${++jH}`}function kH(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function CH(e,t){var s;if(e.type==="user_message")return{id:e.id||mS(),role:"user",content:e.content||"",timestamp:e.timestamp||0};if(e.type==="assistant"){const n=e.message;return n?{id:n.id||mS(),role:"assistant",content:kH(n.content||[]),contentBlocks:n.content,timestamp:e.timestamp||0,parentToolUseId:e.parent_tool_use_id,model:n.model,stopReason:n.stop_reason}:null}if(e.type==="result"){const n=e.data;if(n!=null&&n.is_error&&((s=n.errors)!=null&&s.length))return{id:`replay-error-${t}`,role:"system",content:`Error: ${n.errors.join(", ")}`,timestamp:0}}return null}function NH({token:e}){const[t,s]=w.useState(null),[n,a]=w.useState(""),[l,c]=w.useState(!0),[d,f]=w.useState(0),[h,m]=w.useState(!1),[g,b]=w.useState(1),v=w.useRef(null),y=`public-replay-${e}`,S=Y(N=>N.setMessages);w.useEffect(()=>{se.getPublicReplay(e).then(N=>{const A=N.messages.map((P,K)=>CH(P,K)).filter(P=>P!==null);s({messages:A,gallery:N.gallery})}).catch(N=>a(N instanceof Error?N.message:String(N))).finally(()=>c(!1))},[e]),w.useEffect(()=>{if(!t)return;const N=t.messages.slice(0,d);S(y,N)},[t,d,y,S]),w.useEffect(()=>{if(!(!h||!t))return v.current=setInterval(()=>{f(N=>N>=t.messages.length?(m(!1),N):N+1)},300/g),()=>{v.current&&clearInterval(v.current)}},[h,g,t]);const j=w.useCallback(()=>{t&&(d>=t.messages.length?(f(0),m(!0)):m(N=>!N))},[t,d]);if(l)return r.jsx("div",{className:"h-full bg-cc-bg flex items-center justify-center",children:r.jsx("span",{className:"text-sm text-cc-muted",children:"Loading replay..."})});if(n)return r.jsx("div",{className:"h-full bg-cc-bg flex items-center justify-center",children:r.jsxs("div",{className:"text-center",children:[r.jsx("p",{className:"text-sm text-cc-error",children:n}),r.jsx("p",{className:"text-xs text-cc-muted mt-2",children:"This replay link may have expired or is invalid."})]})});if(!t)return null;const k=t.gallery,E=t.messages.length>0?d/t.messages.length*100:0;return r.jsxs("div",{className:"h-full bg-cc-bg flex flex-col",children:[r.jsx("div",{className:"border-b border-cc-border bg-cc-card px-4 py-3",children:r.jsxs("div",{className:"max-w-5xl mx-auto",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("span",{className:"text-lg font-semibold text-cc-fg",children:(k==null?void 0:k.name)||"Session Replay"}),r.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full bg-cc-hover text-cc-muted font-medium",children:"Public Replay"})]}),k&&r.jsxs("div",{className:"flex flex-wrap items-center gap-3 mt-1.5 text-xs text-cc-muted",children:[k.backendType&&r.jsx("span",{className:"font-medium px-1.5 rounded-full bg-cc-hover",children:k.backendType}),k.model&&r.jsx("span",{children:k.model}),k.totalCostUsd!=null&&k.totalCostUsd>0&&r.jsx("span",{children:wH(k.totalCostUsd)}),k.numTurns!=null&&k.numTurns>0&&r.jsxs("span",{children:[k.numTurns," turns"]}),k.durationMs!=null&&k.durationMs>0&&r.jsx("span",{children:SH(k.durationMs)}),k.tags&&k.tags.length>0&&r.jsx("span",{children:k.tags.join(", ")})]}),(k==null?void 0:k.description)&&r.jsx("p",{className:"text-xs text-cc-muted mt-1",children:k.description})]})}),r.jsx("div",{className:"border-b border-cc-border bg-cc-card px-4 py-2",children:r.jsxs("div",{className:"max-w-5xl mx-auto flex items-center gap-3",children:[r.jsx("button",{onClick:j,className:"w-8 h-8 flex items-center justify-center rounded-lg bg-cc-primary text-white hover:bg-cc-primary-hover transition-colors cursor-pointer",children:h?r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:r.jsx("path",{d:"M5.5 3.5A1.5 1.5 0 017 5v6a1.5 1.5 0 01-3 0V5a1.5 1.5 0 011.5-1.5zm5 0A1.5 1.5 0 0112 5v6a1.5 1.5 0 01-3 0V5a1.5 1.5 0 011.5-1.5z"})}):r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:r.jsx("path",{d:"M4.5 3.5A.5.5 0 015.22 3l7 4.5a.5.5 0 010 .86l-7 4.5A.5.5 0 014.5 12.5v-9z"})})}),r.jsx("div",{className:"flex-1 h-1.5 bg-cc-hover rounded-full overflow-hidden cursor-pointer",onClick:N=>{const B=N.currentTarget.getBoundingClientRect(),A=(N.clientX-B.left)/B.width;f(Math.round(A*t.messages.length))},children:r.jsx("div",{className:"h-full bg-cc-primary rounded-full transition-all",style:{width:`${E}%`}})}),r.jsxs("span",{className:"text-[10px] text-cc-muted tabular-nums",children:[d,"/",t.messages.length]}),r.jsxs("button",{onClick:()=>b(N=>N>=8?1:N*2),className:"px-2 py-1 text-[10px] font-medium bg-cc-hover rounded text-cc-muted hover:text-cc-fg transition-colors cursor-pointer",children:[g,"x"]})]})}),r.jsx("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden",children:r.jsx(ev,{sessionId:y})})]})}const Lg={name:"",content:"",scope:"global",projectPath:""};function EH({embedded:e}){const[t,s]=w.useState([]),[n,a]=w.useState(!0),[l,c]=w.useState(null),[d,f]=w.useState(""),[h,m]=w.useState(!1),[g,b]=w.useState(null),[v,y]=w.useState(Lg),[S,j]=w.useState(!1),[k,E]=w.useState(null),N=w.useCallback(async()=>{a(!0),c(null);try{const I=await se.listPrompts();s(I)}catch{c("Failed to load prompts.")}finally{a(!1)}},[]);w.useEffect(()=>{N()},[N]);const B=t.filter(I=>!d||I.name.toLowerCase().includes(d.toLowerCase())||I.content.toLowerCase().includes(d.toLowerCase()));function A(){b(null),y(Lg),E(null),m(!0)}function P(I){b(I.id),y({name:I.name,content:I.content,scope:I.scope,projectPath:I.projectPath??""}),E(null),m(!0)}function K(){m(!1),b(null),y(Lg),E(null)}async function X(){if(!v.name.trim()||!v.content.trim()){E("Name and content are required.");return}j(!0),E(null);try{g?await se.updatePrompt(g,{name:v.name.trim(),content:v.content.trim(),scope:v.scope,projectPath:v.scope==="project"&&v.projectPath.trim()||void 0}):await se.createPrompt({name:v.name.trim(),content:v.content.trim(),scope:v.scope,projectPath:v.scope==="project"&&v.projectPath.trim()||void 0}),K(),await N()}catch{E("Failed to save prompt.")}finally{j(!1)}}async function Z(I){if(confirm("Delete this prompt?"))try{await se.deletePrompt(I),s(H=>H.filter(F=>F.id!==I))}catch{c("Failed to delete prompt.")}}return r.jsx("div",{className:"flex-1 overflow-y-auto p-6",children:r.jsxs("div",{className:"max-w-2xl mx-auto",children:[r.jsxs("div",{className:"flex items-center justify-between mb-6",children:[r.jsxs("div",{children:[r.jsx("h2",{className:"text-xl font-semibold text-cc-fg",children:"Prompt Library"}),r.jsx("p",{className:"text-sm text-cc-muted mt-0.5",children:"Save reusable prompts and insert them with @ in the composer."})]}),r.jsx("button",{onClick:A,className:"px-3 py-1.5 rounded-lg bg-cc-primary text-white text-sm font-medium hover:bg-cc-primary-hover transition-colors cursor-pointer",children:"+ New Prompt"})]}),r.jsx("div",{className:"mb-4",children:r.jsx("input",{type:"text",value:d,onChange:I=>f(I.target.value),placeholder:"Search prompts...",className:"w-full px-3 py-2 rounded-lg border border-cc-border bg-cc-input-bg text-cc-fg text-sm focus:outline-none focus:border-cc-primary/50"})}),h&&r.jsxs("div",{className:"mb-6 p-4 rounded-lg border border-cc-border bg-cc-card",children:[r.jsx("h3",{className:"text-sm font-medium text-cc-fg mb-3",children:g?"Edit Prompt":"New Prompt"}),r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-xs text-cc-muted mb-1",children:"Name"}),r.jsx("input",{type:"text",value:v.name,onChange:I=>y(H=>({...H,name:I.target.value})),placeholder:"e.g. Code review checklist",className:"w-full px-3 py-1.5 rounded-lg border border-cc-border bg-cc-input-bg text-cc-fg text-sm focus:outline-none focus:border-cc-primary/50"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-xs text-cc-muted mb-1",children:"Content"}),r.jsx("textarea",{value:v.content,onChange:I=>y(H=>({...H,content:I.target.value})),placeholder:"The prompt text...",rows:5,className:"w-full px-3 py-1.5 rounded-lg border border-cc-border bg-cc-input-bg text-cc-fg text-sm font-mono-code resize-y focus:outline-none focus:border-cc-primary/50"})]}),r.jsxs("div",{className:"flex gap-4",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-xs text-cc-muted mb-1",children:"Scope"}),r.jsxs("select",{value:v.scope,onChange:I=>y(H=>({...H,scope:I.target.value})),className:"px-2 py-1.5 rounded-lg border border-cc-border bg-cc-input-bg text-cc-fg text-sm focus:outline-none focus:border-cc-primary/50",children:[r.jsx("option",{value:"global",children:"Global"}),r.jsx("option",{value:"project",children:"Project"})]})]}),v.scope==="project"&&r.jsxs("div",{className:"flex-1",children:[r.jsx("label",{className:"block text-xs text-cc-muted mb-1",children:"Project path"}),r.jsx("input",{type:"text",value:v.projectPath,onChange:I=>y(H=>({...H,projectPath:I.target.value})),placeholder:"/home/user/my-project",className:"w-full px-3 py-1.5 rounded-lg border border-cc-border bg-cc-input-bg text-cc-fg text-sm font-mono-code focus:outline-none focus:border-cc-primary/50"})]})]}),k&&r.jsx("p",{className:"text-xs text-cc-error",children:k}),r.jsxs("div",{className:"flex gap-2 justify-end",children:[r.jsx("button",{onClick:K,className:"px-3 py-1.5 rounded-lg border border-cc-border text-cc-muted text-sm hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:"Cancel"}),r.jsx("button",{onClick:X,disabled:S,className:`px-3 py-1.5 rounded-lg text-sm font-medium transition-colors cursor-pointer ${S?"bg-cc-hover text-cc-muted cursor-not-allowed":"bg-cc-primary text-white hover:bg-cc-primary-hover"}`,children:S?"Saving...":"Save"})]})]})]}),n?r.jsx("div",{className:"text-sm text-cc-muted",children:"Loading..."}):l?r.jsx("div",{className:"text-sm text-cc-error",children:l}):B.length===0?r.jsx("div",{className:"text-center py-12 text-cc-muted",children:d?r.jsxs("p",{className:"text-sm",children:['No prompts match "',d,'"']}):r.jsxs(r.Fragment,{children:[r.jsx("p",{className:"text-sm mb-2",children:"No prompts yet."}),r.jsx("button",{onClick:A,className:"text-sm text-cc-primary hover:text-cc-primary-hover transition-colors cursor-pointer",children:"Create your first prompt"})]})}):r.jsx("div",{className:"space-y-2",children:B.map(I=>r.jsx("div",{className:"p-4 rounded-lg border border-cc-border bg-cc-card group",children:r.jsxs("div",{className:"flex items-start justify-between gap-2",children:[r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-sm font-medium text-cc-fg",children:I.name}),r.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded-full bg-cc-hover text-cc-muted border border-cc-border capitalize",children:I.scope})]}),I.scope==="project"&&I.projectPath&&r.jsx("p",{className:"text-xs text-cc-muted font-mono-code mt-0.5",children:I.projectPath}),r.jsx("p",{className:"text-xs text-cc-muted mt-1 line-clamp-2 whitespace-pre-line",children:I.content})]}),r.jsxs("div",{className:"flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity shrink-0",children:[r.jsx("button",{onClick:()=>P(I),className:"px-2 py-1 rounded text-xs text-cc-muted hover:text-cc-fg transition-colors cursor-pointer",children:"Edit"}),r.jsx("button",{onClick:()=>Z(I.id),className:"px-2 py-1 rounded text-xs text-cc-error hover:text-cc-error/80 transition-colors cursor-pointer",children:"Delete"})]})]})},I.id))})]})})}function EN({className:e}){return r.jsxs("svg",{viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",className:e,children:[r.jsx("circle",{cx:"12",cy:"12",r:"10",fill:"currentColor"}),r.jsx("path",{d:"M7.2 15.2l6.6-6.6",stroke:"white",strokeWidth:"2",strokeLinecap:"round"}),r.jsx("circle",{cx:"16.4",cy:"8.8",r:"1.8",fill:"white"})]})}function MN(e){window.location.hash=e}function MH({embedded:e}){const[t,s]=w.useState(!1),[n,a]=w.useState(!0);w.useEffect(()=>{se.getSettings().then(c=>{c.linearApiKeyConfigured?se.getLinearConnection().then(d=>s(d.connected)).catch(()=>s(!1)).finally(()=>a(!1)):a(!1)}).catch(()=>{a(!1)})},[]);const l=[{id:"linear",name:"Linear",description:"Browse issues and auto-generate branch names from Linear tickets.",icon:r.jsx(EN,{className:"w-8 h-8 text-[#5E6AD2]"}),route:"#/integrations/linear",connected:t,checking:n}];return r.jsx("div",{className:"flex-1 overflow-y-auto p-6",children:r.jsxs("div",{className:"max-w-2xl mx-auto",children:[r.jsx("h2",{className:"text-xl font-semibold text-cc-fg mb-2",children:"Integrations"}),r.jsx("p",{className:"text-sm text-cc-fg-muted mb-6",children:"Connect external services to enhance your sessions."}),r.jsx("div",{className:"grid gap-4",children:l.map(c=>r.jsxs("button",{onClick:()=>MN(c.route),className:"flex items-center gap-4 p-4 rounded-lg border border-cc-border bg-cc-bg-subtle hover:bg-cc-bg-hover text-left transition-colors group",children:[r.jsx("div",{className:"shrink-0",children:c.icon}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-sm font-medium text-cc-fg",children:c.name}),c.checking?r.jsx("span",{className:"text-xs text-cc-fg-muted",children:"checking…"}):c.connected?r.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded-full bg-green-500/10 text-green-400 border border-green-500/20",children:"Connected"}):r.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded-full bg-cc-fg-muted/10 text-cc-fg-muted border border-cc-border",children:"Not connected"})]}),r.jsx("p",{className:"text-xs text-cc-fg-muted mt-0.5",children:c.description})]}),r.jsx("div",{className:"text-cc-fg-muted group-hover:text-cc-fg transition-colors",children:"→"})]},c.id))})]})})}function TH({embedded:e}){const[t,s]=w.useState(""),[n,a]=w.useState(null),[l,c]=w.useState(!1),[d,f]=w.useState(!1),[h,m]=w.useState(null),[g,b]=w.useState(!1);w.useEffect(()=>{se.getSettings().then(j=>{j.linearApiKeyConfigured&&v()}).catch(()=>{})},[]);async function v(){f(!0),m(null);try{const j=await se.getLinearConnection();a(j)}catch{a({connected:!1}),m("Could not connect to Linear. Check your API key.")}finally{f(!1)}}async function y(){if(t.trim()){c(!0),m(null);try{await se.updateSettings({linearApiKey:t.trim()}),s(""),b(!0),setTimeout(()=>b(!1),2e3),await v()}catch{m("Failed to save API key.")}finally{c(!1)}}}async function S(){c(!0),m(null);try{await se.updateSettings({linearApiKey:""}),a(null)}catch{m("Failed to disconnect.")}finally{c(!1)}}return r.jsx("div",{className:"flex-1 overflow-y-auto p-6",children:r.jsxs("div",{className:"max-w-xl mx-auto",children:[r.jsx("div",{className:"flex items-center gap-3 mb-6",children:r.jsx("button",{onClick:()=>MN("#/integrations"),className:"text-cc-fg-muted hover:text-cc-fg transition-colors text-sm",children:"← Integrations"})}),r.jsxs("div",{className:"flex items-center gap-3 mb-6",children:[r.jsx(EN,{className:"w-8 h-8 text-[#5E6AD2]"}),r.jsxs("div",{children:[r.jsx("h2",{className:"text-lg font-semibold text-cc-fg",children:"Linear"}),r.jsx("p",{className:"text-sm text-cc-fg-muted",children:"Connect your Linear workspace to browse issues"})]})]}),(n==null?void 0:n.connected)&&n.viewer&&r.jsx("div",{className:"mb-6 p-4 rounded-lg border border-green-500/20 bg-green-500/5",children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsxs("p",{className:"text-sm font-medium text-cc-fg",children:["Connected as ",r.jsx("span",{className:"text-green-400",children:n.viewer.name})]}),r.jsx("p",{className:"text-xs text-cc-fg-muted",children:n.viewer.email}),n.teams&&n.teams.length>0&&r.jsxs("p",{className:"text-xs text-cc-fg-muted mt-1",children:["Teams: ",n.teams.map(j=>j.name).join(", ")]})]}),r.jsx("button",{onClick:S,disabled:l,className:"text-xs text-red-400 hover:text-red-300 transition-colors disabled:opacity-50",children:"Disconnect"})]})}),!(n!=null&&n.connected)&&r.jsxs("div",{className:"mb-6",children:[r.jsx("label",{className:"block text-sm font-medium text-cc-fg mb-2",children:"Linear API Key"}),r.jsxs("p",{className:"text-xs text-cc-fg-muted mb-3",children:["Create a personal API key at"," ",r.jsx("span",{className:"font-mono text-cc-accent",children:"linear.app/settings/api"})]}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{type:"password",value:t,onChange:j=>s(j.target.value),onKeyDown:j=>{j.key==="Enter"&&y()},placeholder:"lin_api_...",className:"flex-1 px-3 py-2 rounded-md border border-cc-border bg-cc-input text-cc-fg text-sm font-mono focus:outline-none focus:ring-1 focus:ring-cc-accent"}),r.jsx("button",{onClick:y,disabled:l||!t.trim(),className:"px-4 py-2 rounded-md bg-cc-accent text-white text-sm font-medium hover:bg-cc-accent/90 disabled:opacity-50 transition-colors",children:l?"Saving…":g?"Saved!":"Connect"})]})]}),!n&&!d&&r.jsx("button",{onClick:v,className:"text-sm text-cc-accent hover:text-cc-accent/80 transition-colors",children:"Check connection"}),d&&r.jsx("p",{className:"text-sm text-cc-fg-muted",children:"Checking connection…"}),h&&r.jsx("p",{className:"text-sm text-red-400 mt-2",children:h}),r.jsxs("div",{className:"mt-8 p-4 rounded-lg border border-cc-border bg-cc-bg-subtle",children:[r.jsx("h3",{className:"text-sm font-medium text-cc-fg mb-2",children:"What this enables"}),r.jsxs("ul",{className:"text-xs text-cc-fg-muted space-y-1 list-disc list-inside",children:[r.jsx("li",{children:"Browse and search Linear issues when creating sessions"}),r.jsx("li",{children:"Auto-generate branch names from issue titles"}),r.jsx("li",{children:"Inject issue context as startup prompt for the agent"})]})]})]})})}function AH(){const e=Y(A=>A.currentSessionId),[t,s]=w.useState([]),[n,a]=w.useState([]),[l,c]=w.useState(null),[d,f]=w.useState(!1),[h,m]=w.useState("fragments"),[g,b]=w.useState(""),[v,y]=w.useState("");w.useEffect(()=>{e&&S()},[e]);async function S(){if(e){f(!0);try{const A=await se.getSessionMemory(e);s(A.fragments||[]),a(A.consolidated||[])}catch(A){console.error("[MemoryPanel] Failed to load memory:",A)}finally{f(!1)}try{const A=await se.getMemoryOverview(e);c(A)}catch(A){console.error("[MemoryPanel] Failed to load memory overview:",A),c(null)}}}async function j(A){const P=!A.pinned;s(K=>K.map(X=>X.id===A.id?{...X,pinned:P}:X));try{await se.pinMemory(A.id,P)}catch(K){console.error("[MemoryPanel] Failed to toggle pin:",K),s(X=>X.map(Z=>Z.id===A.id?{...Z,pinned:!P}:Z))}}async function k(){if(!(!e||!g.trim())){f(!0);try{const A=await se.queryMemory(e,g,20);s(A.results||[]),a(A.consolidated||[])}catch(A){console.error("[MemoryPanel] Failed to query memory:",A)}finally{f(!1)}}}async function E(){if(e){f(!0);try{await se.consolidateMemory(e),await S()}catch(A){console.error("[MemoryPanel] Failed to consolidate memory:",A)}finally{f(!1)}}}const N=Array.from(new Set(t.flatMap(A=>A.tags))).sort(),B=v?t.filter(A=>A.tags.includes(v)):t;return e?r.jsxs("div",{className:"flex flex-col h-full bg-cc-bg",children:[r.jsxs("div",{className:"shrink-0 px-4 py-3 border-b border-cc-border",children:[r.jsxs("div",{className:"flex items-center justify-between mb-3",children:[r.jsx("h2",{className:"text-sm font-semibold text-cc-fg",children:"Semantic Memory"}),r.jsx("button",{onClick:E,disabled:d,className:"px-2 py-1 text-xs font-medium text-cc-primary hover:bg-cc-active rounded cursor-pointer disabled:opacity-50",children:d?"Consolidating...":"Consolidate"})]}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{type:"text",value:g,onChange:A=>b(A.target.value),onKeyDown:A=>A.key==="Enter"&&k(),placeholder:"Search memory...",className:"flex-1 px-3 py-1.5 text-sm bg-cc-card border border-cc-border rounded-lg text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-primary"}),r.jsx("button",{onClick:k,className:"px-3 py-1.5 text-sm font-medium text-white bg-cc-primary hover:bg-cc-primary/90 rounded-lg cursor-pointer",children:"Search"})]}),r.jsxs("div",{className:"flex items-center gap-1 mt-3 bg-cc-hover rounded-lg p-0.5",children:[r.jsxs("button",{onClick:()=>m("fragments"),className:`flex-1 px-3 py-1 text-xs font-medium rounded-md transition-colors cursor-pointer ${h==="fragments"?"bg-cc-card text-cc-fg shadow-sm":"text-cc-muted hover:text-cc-fg"}`,children:["Fragments (",B.length,")"]}),r.jsxs("button",{onClick:()=>m("consolidated"),className:`flex-1 px-3 py-1 text-xs font-medium rounded-md transition-colors cursor-pointer ${h==="consolidated"?"bg-cc-card text-cc-fg shadow-sm":"text-cc-muted hover:text-cc-fg"}`,children:["Consolidated (",n.length,")"]})]})]}),r.jsxs("div",{className:"flex-1 overflow-y-auto",children:[l&&l.namespaces.length>0&&r.jsxs("div",{className:"px-4 pt-4",children:[r.jsx("h3",{className:"text-[10px] uppercase tracking-[0.15em] text-cc-muted/60 font-mono mb-2",children:"Namespaces"}),r.jsx("div",{className:"space-y-2",children:l.namespaces.map(A=>{const P=Math.round(Math.max(0,Math.min(1,A.avgWeight))*100);return r.jsxs("div",{className:"p-2.5 bg-cc-card border border-cc-border rounded-lg",children:[r.jsxs("div",{className:"flex items-center justify-between gap-2 mb-1.5",children:[r.jsx("span",{className:"text-[11px] font-mono text-cc-fg truncate",title:A.namespace,children:A.namespace}),r.jsxs("span",{className:"text-[10px] text-cc-muted font-mono shrink-0",children:[A.count," ",A.count===1?"item":"items",A.pinnedCount>0&&` · ${A.pinnedCount} pinned`]})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("div",{className:"flex-1 h-1.5 rounded-full bg-cc-hover overflow-hidden",children:r.jsx("div",{"data-testid":`ns-weight-${A.namespace}`,className:"h-full rounded-full bg-cc-primary/50",style:{width:`${P}%`}})}),r.jsxs("span",{className:"text-[10px] text-cc-muted/60 font-mono tabular-nums shrink-0",children:[P,"% avg weight"]})]})]},A.namespace)})})]}),h==="fragments"&&r.jsxs("div",{className:"p-4 space-y-3",children:[N.length>0&&r.jsxs("div",{className:"flex flex-wrap gap-1.5 pb-2 border-b border-cc-border",children:[r.jsx("button",{onClick:()=>y(""),className:`px-2 py-0.5 text-xs rounded cursor-pointer ${v?"bg-cc-hover text-cc-muted hover:text-cc-fg":"bg-cc-primary text-white"}`,children:"All"}),N.map(A=>r.jsx("button",{onClick:()=>y(A),className:`px-2 py-0.5 text-xs rounded cursor-pointer ${v===A?"bg-cc-primary text-white":"bg-cc-hover text-cc-muted hover:text-cc-fg"}`,children:A},A))]}),B.length===0?r.jsx("div",{className:"text-center py-8 text-cc-muted text-sm",children:d?"Loading...":"No memory fragments yet"}):B.map(A=>r.jsxs("div",{className:"p-3 bg-cc-card border border-cc-border rounded-lg",children:[r.jsxs("div",{className:"flex items-start justify-between mb-2",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:`px-1.5 py-0.5 text-[10px] font-medium rounded ${A.type==="observation"?"bg-blue-500/20 text-blue-400":A.type==="hypothesis"?"bg-purple-500/20 text-purple-400":A.type==="decision"?"bg-green-500/20 text-green-400":"bg-yellow-500/20 text-yellow-400"}`,children:A.type}),r.jsx("span",{className:"text-xs text-cc-muted",children:new Date(A.timestamp).toLocaleString()})]}),r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsxs("span",{className:"text-xs text-cc-muted font-mono",children:[(A.confidence*100).toFixed(0),"%"]}),r.jsx("button",{onClick:()=>j(A),"aria-label":A.pinned?"Unpin memory":"Pin memory",title:A.pinned?"Unpin — resume decay":"Pin — never decays",className:`w-5 h-5 flex items-center justify-center rounded cursor-pointer transition-colors ${A.pinned?"text-cc-primary bg-cc-primary/10 hover:bg-cc-primary/20":"text-cc-muted/40 hover:text-cc-fg hover:bg-cc-hover"}`,children:r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3",children:r.jsx("path",{d:"M9.5 1.5l5 5-1.5 1.5-.75-.25L9.5 10.5l.25 2.75L8.5 14.5 5.75 11.75 2.5 15l-1-1 3.25-3.25L2 8l1.25-1.25L6 7l2.75-2.75-.25-.75L9.5 1.5z"})})})]})]}),r.jsx("p",{className:"text-sm text-cc-fg mb-2",children:A.content}),A.tags.length>0&&r.jsx("div",{className:"flex flex-wrap gap-1",children:A.tags.map(P=>r.jsxs("span",{className:"px-1.5 py-0.5 text-[10px] bg-cc-hover text-cc-muted rounded",children:["#",P]},P))}),A.gitContext.files.length>0&&r.jsxs("div",{className:"mt-2 text-xs text-cc-muted font-mono",children:[A.gitContext.files.slice(0,2).join(", "),A.gitContext.files.length>2&&` +${A.gitContext.files.length-2} more`]})]},A.id))]}),h==="consolidated"&&r.jsx("div",{className:"p-4 space-y-3",children:n.length===0?r.jsx("div",{className:"text-center py-8 text-cc-muted text-sm",children:d?"Loading...":"No consolidated knowledge yet"}):n.map(A=>{var K;const P=(K=l==null?void 0:l.knowledge.find(X=>X.id===A.id))==null?void 0:K.synthesisMethod;return r.jsxs("div",{className:"p-3 bg-cc-card border border-cc-border rounded-lg",children:[r.jsxs("div",{className:"flex items-start justify-between mb-2",children:[r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsxs("span",{className:"px-2 py-1 text-xs font-semibold bg-cc-primary/20 text-cc-primary rounded",children:["#",A.tag]}),P==="concat"&&r.jsx("span",{className:"px-1.5 py-0.5 text-[10px] bg-cc-hover text-cc-muted rounded font-mono",title:"Concatenated without LLM distillation (no OpenRouter key configured)",children:"concat"})]}),r.jsxs("span",{className:"text-xs text-cc-muted",children:["Updated ",new Date(A.lastUpdated).toLocaleDateString()]})]}),r.jsx("p",{className:"text-sm text-cc-fg mb-2",children:A.summary}),r.jsxs("div",{className:"text-xs text-cc-muted",children:["Synthesized from ",A.sourceFragments.length," fragments"," · ","Confidence: ",(A.confidence*100).toFixed(0),"%"]})]},A.id)})})]})]}):r.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-cc-muted",children:[r.jsx("svg",{className:"w-16 h-16 mb-4 opacity-20",viewBox:"0 0 24 24",fill:"currentColor",children:r.jsx("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z"})}),r.jsx("p",{className:"text-sm",children:"No session selected"}),r.jsx("p",{className:"text-xs text-cc-muted mt-1",children:"Select a session to view its semantic memory"})]})}function RH(){const e=Y(k=>k.sdkSessions),[t,s]=w.useState([]),[n,a]=w.useState(""),[l,c]=w.useState([]),[d,f]=w.useState(null),[h,m]=w.useState(!1),[g,b]=w.useState(!1);w.useEffect(()=>{v()},[]);async function v(){b(!0);try{const k=await se.getCapabilities();s(k.sessions||[]),c(k.sessions.map(E=>E.sessionId))}catch(k){console.error("[TaskRouterPage] Failed to load capabilities:",k)}finally{b(!1)}}async function y(){if(!(!n.trim()||l.length===0)){m(!0),f(null);try{const k=await se.routeTask({taskDescription:n,availableSessions:l});f(k)}catch(k){console.error("[TaskRouterPage] Failed to route task:",k)}finally{m(!1)}}}function S(k){c(E=>E.includes(k)?E.filter(N=>N!==k):[...E,k])}function j(k){const E=e.find(N=>N.sessionId===k);return(E==null?void 0:E.name)||`Session ${k.slice(0,8)}`}return r.jsxs("div",{className:"flex h-full bg-cc-bg",children:[r.jsx("div",{className:"w-1/2 border-r border-cc-border overflow-y-auto",children:r.jsxs("div",{className:"p-6 space-y-6",children:[r.jsxs("div",{children:[r.jsx("h1",{className:"text-lg font-semibold text-cc-fg",children:"Task Router"}),r.jsx("p",{className:"text-sm text-cc-muted mt-1",children:"Route complex tasks to the best-suited agent based on capabilities and historical performance"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-cc-fg mb-2",children:"Task Description"}),r.jsx("textarea",{value:n,onChange:k=>a(k.target.value),placeholder:"Describe the task you want to route... e.g., 'Refactor auth module to use JWT tokens with TypeScript strict mode'",className:"w-full px-3 py-2 text-sm bg-cc-card border border-cc-border rounded-lg text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-primary resize-none",rows:4})]}),r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsxs("label",{className:"text-sm font-medium text-cc-fg",children:["Available Sessions (",l.length,"/",t.length,")"]}),r.jsx("button",{onClick:()=>c(l.length===t.length?[]:t.map(k=>k.sessionId)),className:"text-xs text-cc-primary hover:underline cursor-pointer",children:l.length===t.length?"Deselect All":"Select All"})]}),g?r.jsx("div",{className:"text-sm text-cc-muted",children:"Loading capabilities..."}):t.length===0?r.jsx("div",{className:"text-sm text-cc-muted",children:"No active sessions with capabilities reported"}):r.jsx("div",{className:"space-y-2",children:t.map(k=>r.jsx("div",{onClick:()=>S(k.sessionId),className:`p-3 border rounded-lg cursor-pointer transition-colors ${l.includes(k.sessionId)?"bg-cc-active border-cc-primary":"bg-cc-card border-cc-border hover:border-cc-primary/50"}`,children:r.jsxs("div",{className:"flex items-start justify-between",children:[r.jsxs("div",{className:"flex-1",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[r.jsx("span",{className:"text-sm font-medium text-cc-fg",children:j(k.sessionId)}),r.jsx("span",{className:"px-1.5 py-0.5 text-[10px] bg-cc-hover text-cc-muted rounded",children:k.backendType})]}),k.strengths.length>0&&r.jsx("div",{className:"flex flex-wrap gap-1 mt-1",children:k.strengths.slice(0,5).map(E=>r.jsx("span",{className:"px-1.5 py-0.5 text-[10px] bg-green-500/20 text-green-400 rounded",children:E},E))})]}),r.jsxs("div",{className:"text-xs text-cc-muted text-right",children:[r.jsxs("div",{children:[k.availableTools.length," tools"]}),r.jsxs("div",{children:[k.contextUsedPercent.toFixed(0),"% context"]})]})]})},k.sessionId))})]}),r.jsx("button",{onClick:y,disabled:!n.trim()||l.length===0||h,className:"w-full px-4 py-2 text-sm font-medium text-white bg-cc-primary hover:bg-cc-primary/90 rounded-lg cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed",children:h?"Routing...":"Route Task"})]})}),r.jsx("div",{className:"w-1/2 overflow-y-auto",children:d?r.jsxs("div",{className:"p-6 space-y-4",children:[r.jsxs("div",{children:[r.jsx("h2",{className:"text-base font-semibold text-cc-fg",children:"Routing Result"}),r.jsx("p",{className:"text-sm text-cc-muted mt-1",children:"Best agent for this task"})]}),r.jsxs("div",{className:"p-4 bg-cc-card border-2 border-cc-primary rounded-lg",children:[r.jsxs("div",{className:"flex items-start justify-between mb-2",children:[r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("svg",{className:"w-5 h-5 text-cc-primary",fill:"currentColor",viewBox:"0 0 20 20",children:r.jsx("path",{d:"M9.049 2.927c.3-.921 1.603-.921 1.902 0l1.07 3.292a1 1 0 00.95.69h3.462c.969 0 1.371 1.24.588 1.81l-2.8 2.034a1 1 0 00-.364 1.118l1.07 3.292c.3.921-.755 1.688-1.54 1.118l-2.8-2.034a1 1 0 00-1.175 0l-2.8 2.034c-.784.57-1.838-.197-1.539-1.118l1.07-3.292a1 1 0 00-.364-1.118L2.98 8.72c-.783-.57-.38-1.81.588-1.81h3.461a1 1 0 00.951-.69l1.07-3.292z"})}),r.jsx("span",{className:"text-base font-semibold text-cc-fg",children:j(d.sessionId)})]}),r.jsx("span",{className:"px-2 py-0.5 text-xs bg-cc-hover text-cc-muted rounded inline-block mt-1",children:d.backendType})]}),r.jsxs("div",{className:"text-right",children:[r.jsxs("div",{className:"text-2xl font-bold text-cc-primary",children:[(d.confidence*100).toFixed(0),"%"]}),r.jsx("div",{className:"text-xs text-cc-muted",children:"confidence"})]})]}),r.jsxs("div",{className:"mt-3 p-3 bg-cc-bg rounded border border-cc-border",children:[r.jsx("div",{className:"text-xs font-semibold text-cc-muted mb-1",children:"Reasoning:"}),r.jsx("p",{className:"text-sm text-cc-fg",children:d.reasoning})]})]}),d.alternatives.length>0&&r.jsxs("div",{children:[r.jsx("h3",{className:"text-sm font-medium text-cc-fg mb-2",children:"Alternative Options"}),r.jsx("div",{className:"space-y-2",children:d.alternatives.map((k,E)=>r.jsx("div",{className:"p-3 bg-cc-card border border-cc-border rounded-lg",children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-sm text-cc-fg",children:j(k.sessionId)}),r.jsx("span",{className:"px-1.5 py-0.5 text-[10px] bg-cc-hover text-cc-muted rounded",children:k.backendType})]}),r.jsxs("span",{className:"text-sm font-semibold text-cc-muted",children:[(k.confidence*100).toFixed(0),"%"]})]})},E))})]})]}):r.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-cc-muted",children:[r.jsx("svg",{className:"w-16 h-16 mb-4 opacity-20",fill:"currentColor",viewBox:"0 0 20 20",children:r.jsx("path",{fillRule:"evenodd",d:"M11.3 1.046A1 1 0 0112 2v5h4a1 1 0 01.82 1.573l-7 10A1 1 0 018 18v-5H4a1 1 0 01-.82-1.573l7-10a1 1 0 011.12-.38z",clipRule:"evenodd"})}),r.jsx("p",{className:"text-sm",children:"No routing result yet"}),r.jsx("p",{className:"text-xs text-cc-muted mt-1",children:"Describe a task and route it to see recommendations"})]})})]})}function DH(){const e=Y(S=>S.currentSessionId),[t,s]=w.useState([]),[n,a]=w.useState(null),[l,c]=w.useState(!1),[d,f]=w.useState("stream"),[h,m]=w.useState("");w.useEffect(()=>{if(!e)return;g();const S=setInterval(g,5e3);return()=>clearInterval(S)},[e]);async function g(){if(e){c(!0);try{const[S,j]=await Promise.all([se.getContextStream(e),se.getConsensusState(e)]);s(S.fragments||[]),a(j)}catch(S){console.error("[CollectiveMindPanel] Failed to load context:",S)}finally{c(!1)}}}if(!e)return r.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-cc-muted",children:[r.jsx("svg",{className:"w-16 h-16 mb-4 opacity-20",viewBox:"0 0 24 24",fill:"currentColor",children:r.jsx("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z"})}),r.jsx("p",{className:"text-sm",children:"No session selected"}),r.jsx("p",{className:"text-xs text-cc-muted mt-1",children:"Select a session to view its collective reasoning"})]});const b=Array.from(new Set(t.map(S=>S.type))).sort(),y=[...h?t.filter(S=>S.type===h):t].sort((S,j)=>j.timestamp-S.timestamp);return r.jsxs("div",{className:"flex flex-col h-full bg-cc-bg",children:[r.jsxs("div",{className:"shrink-0 px-4 py-3 border-b border-cc-border",children:[r.jsx("h2",{className:"text-sm font-semibold text-cc-fg mb-3",children:"Collective Mind"}),r.jsxs("div",{className:"flex items-center gap-1 bg-cc-hover rounded-lg p-0.5",children:[r.jsxs("button",{onClick:()=>f("stream"),className:`flex-1 px-3 py-1 text-xs font-medium rounded-md transition-colors cursor-pointer ${d==="stream"?"bg-cc-card text-cc-fg shadow-sm":"text-cc-muted hover:text-cc-fg"}`,children:["Thought Stream (",t.length,")"]}),r.jsx("button",{onClick:()=>f("consensus"),className:`flex-1 px-3 py-1 text-xs font-medium rounded-md transition-colors cursor-pointer ${d==="consensus"?"bg-cc-card text-cc-fg shadow-sm":"text-cc-muted hover:text-cc-fg"}`,children:"Consensus"})]})]}),r.jsxs("div",{className:"flex-1 overflow-y-auto",children:[d==="stream"&&r.jsxs("div",{className:"p-4 space-y-3",children:[b.length>0&&r.jsxs("div",{className:"flex flex-wrap gap-1.5 pb-2 border-b border-cc-border",children:[r.jsx("button",{onClick:()=>m(""),className:`px-2 py-0.5 text-xs rounded cursor-pointer ${h?"bg-cc-hover text-cc-muted hover:text-cc-fg":"bg-cc-primary text-white"}`,children:"All"}),b.map(S=>r.jsx("button",{onClick:()=>m(S),className:`px-2 py-0.5 text-xs rounded cursor-pointer ${h===S?"bg-cc-primary text-white":"bg-cc-hover text-cc-muted hover:text-cc-fg"}`,children:S},S))]}),y.length===0?r.jsx("div",{className:"text-center py-8 text-cc-muted text-sm",children:l?"Loading...":"No thoughts in the stream yet"}):r.jsx("div",{className:"space-y-3",children:y.map(S=>r.jsxs("div",{className:`p-3 rounded-lg border ${S.consensusScore>.7?"bg-green-500/5 border-green-500/30":S.isControversial?"bg-orange-500/5 border-orange-500/30":"bg-cc-card border-cc-border"}`,children:[r.jsxs("div",{className:"flex items-start justify-between mb-2",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("div",{className:`w-2 h-2 rounded-full ${S.isHuman?"bg-blue-400":"bg-purple-400"}`}),r.jsxs("span",{className:"text-xs text-cc-muted",children:[S.isHuman?"Human":"Agent"," · ",S.agentId.slice(0,8)]}),r.jsx("span",{className:`px-1.5 py-0.5 text-[10px] font-medium rounded ${S.type==="thought"?"bg-purple-500/20 text-purple-400":S.type==="observation"?"bg-blue-500/20 text-blue-400":S.type==="plan"?"bg-green-500/20 text-green-400":S.type==="question"?"bg-yellow-500/20 text-yellow-400":S.type==="answer"?"bg-teal-500/20 text-teal-400":S.type==="insight"?"bg-pink-500/20 text-pink-400":"bg-red-500/20 text-red-400"}`,children:S.type}),r.jsx("span",{className:"text-xs text-cc-muted",children:new Date(S.timestamp).toLocaleTimeString()})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[S.consensusScore>0&&r.jsxs("span",{className:"text-xs text-cc-muted font-mono",children:[(S.consensusScore*100).toFixed(0),"% agree"]}),S.isControversial&&r.jsx("span",{className:"text-xs text-orange-400",children:"⚠ Controversial"})]})]}),r.jsx("p",{className:"text-sm text-cc-fg mb-2",children:S.content}),S.semanticLinks.length>0&&r.jsx("div",{className:"flex flex-wrap gap-1 mt-2",children:S.semanticLinks.map((j,k)=>r.jsxs("span",{className:`px-1.5 py-0.5 text-[10px] rounded ${j.relation==="agrees_with"?"bg-green-500/20 text-green-400":j.relation==="disagrees_with"?"bg-red-500/20 text-red-400":j.relation==="builds_on"?"bg-blue-500/20 text-blue-400":j.relation==="contradicts"?"bg-orange-500/20 text-orange-400":"bg-yellow-500/20 text-yellow-400"}`,children:[j.relation.replace("_"," ")," #",j.targetFragmentId.slice(0,6)]},k))}),S.parentId&&r.jsxs("div",{className:"mt-2 text-xs text-cc-muted",children:["↳ Reply to #",S.parentId.slice(0,8)]})]},S.fragmentId))})]}),d==="consensus"&&r.jsx("div",{className:"p-4 space-y-4",children:n?r.jsxs(r.Fragment,{children:[n.consensusPoints.length>0&&r.jsxs("div",{children:[r.jsxs("h3",{className:"text-sm font-semibold text-cc-fg mb-2 flex items-center gap-2",children:[r.jsx("span",{className:"w-2 h-2 rounded-full bg-green-400"}),"Consensus Points (",n.consensusPoints.length,")"]}),r.jsx("div",{className:"space-y-2",children:n.consensusPoints.map(S=>{const j=t.find(k=>k.fragmentId===S);return j?r.jsxs("div",{className:"p-2 bg-green-500/5 border border-green-500/30 rounded text-sm",children:[r.jsx("div",{className:"text-cc-fg",children:j.content}),r.jsxs("div",{className:"text-xs text-cc-muted mt-1",children:[(j.consensusScore*100).toFixed(0),"% agreement"]})]},S):null})})]}),n.disagreements.length>0&&r.jsxs("div",{children:[r.jsxs("h3",{className:"text-sm font-semibold text-cc-fg mb-2 flex items-center gap-2",children:[r.jsx("span",{className:"w-2 h-2 rounded-full bg-orange-400"}),"Disagreements (",n.disagreements.length,")"]}),r.jsx("div",{className:"space-y-2",children:n.disagreements.map((S,j)=>r.jsxs("div",{className:"p-3 bg-orange-500/5 border border-orange-500/30 rounded",children:[r.jsx("div",{className:"text-sm font-medium text-cc-fg mb-1",children:S.topic}),r.jsx("div",{className:"text-sm text-cc-muted mb-2",children:S.summary}),r.jsxs("div",{className:"text-xs text-cc-muted",children:[S.fragmentIds.length," conflicting thoughts"]})]},j))})]}),n.openQuestions.length>0&&r.jsxs("div",{children:[r.jsxs("h3",{className:"text-sm font-semibold text-cc-fg mb-2 flex items-center gap-2",children:[r.jsx("span",{className:"w-2 h-2 rounded-full bg-yellow-400"}),"Open Questions (",n.openQuestions.length,")"]}),r.jsx("div",{className:"space-y-2",children:n.openQuestions.map(S=>{const j=t.find(k=>k.fragmentId===S);return j?r.jsxs("div",{className:"p-2 bg-yellow-500/5 border border-yellow-500/30 rounded text-sm",children:[r.jsx("div",{className:"text-cc-fg",children:j.content}),r.jsxs("div",{className:"text-xs text-cc-muted mt-1",children:["Asked by ",j.isHuman?"human":"agent"," · No answers yet"]})]},S):null})})]}),n.consensusPoints.length===0&&n.disagreements.length===0&&n.openQuestions.length===0&&r.jsx("div",{className:"text-center py-8 text-cc-muted text-sm",children:"No consensus data available yet"})]}):r.jsx("div",{className:"text-center py-8 text-cc-muted text-sm",children:l?"Loading...":"No consensus data yet"})})]})]})}function g0(e){if(e<1e3)return`${e}ms`;const t=Math.floor(e/1e3);return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`}function x0(e){return e===0?"$0":e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}const v0={pending:"text-cc-muted",running:"text-cc-primary",completed:"text-cc-success",failed:"text-cc-error",cancelled:"text-cc-warning",skipped:"text-cc-muted/50"},LH={pending:"bg-cc-muted/30",running:"bg-cc-primary animate-pulse",completed:"bg-cc-success",failed:"bg-cc-error",cancelled:"bg-cc-warning",skipped:"bg-cc-muted/20"};function BH({stage:e,index:t,onChange:s,onRemove:n}){return r.jsxs("div",{className:"border border-cc-border rounded-lg p-3 space-y-2",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("span",{className:"text-[11px] font-mono-code text-cc-muted",children:["Stage ",t+1]}),r.jsx("button",{onClick:n,className:"text-[10px] text-cc-error hover:text-cc-error/80 transition-colors",children:"Remove"})]}),r.jsx("input",{type:"text",value:e.name,onChange:a=>s({...e,name:a.target.value}),placeholder:"Stage name (e.g. Implement feature)",className:"w-full px-2.5 py-1.5 text-[12px] bg-cc-input-bg border border-cc-border rounded-md text-cc-fg placeholder:text-cc-muted/40 focus:outline-none focus:border-cc-muted/30"}),r.jsx("textarea",{value:e.prompt,onChange:a=>s({...e,prompt:a.target.value}),placeholder:"Prompt for this stage...",rows:3,className:"w-full px-2.5 py-1.5 text-[12px] bg-cc-input-bg border border-cc-border rounded-md text-cc-fg placeholder:text-cc-muted/40 focus:outline-none focus:border-cc-muted/30 resize-none font-mono-code"}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("select",{value:e.backend,onChange:a=>s({...e,backend:a.target.value}),className:"px-2 py-1 text-[11px] bg-cc-input-bg border border-cc-border rounded-md text-cc-fg focus:outline-none",children:[r.jsx("option",{value:"claude",children:"Claude Code"}),r.jsx("option",{value:"codex",children:"Codex"}),r.jsx("option",{value:"goose",children:"Goose"}),r.jsx("option",{value:"aider",children:"Aider"})]}),r.jsxs("label",{className:"flex items-center gap-1.5 text-[11px] text-cc-muted cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:e.inheritContext??!0,onChange:a=>s({...e,inheritContext:a.target.checked}),className:"rounded"}),"Pass context from previous stage"]})]})]})}function OH({onSave:e,onCancel:t}){const[s,n]=w.useState(""),[a,l]=w.useState(""),[c,d]=w.useState(""),[f,h]=w.useState([{name:"Implement",prompt:"",backend:"claude",inheritContext:!1},{name:"Test",prompt:"Run the test suite and fix any failures.",backend:"claude",inheritContext:!0},{name:"Review",prompt:"Review the changes for code quality, security, and best practices.",backend:"claude",inheritContext:!0}]),[m,g]=w.useState(!1);w.useEffect(()=>{se.getHome().then(y=>d(y.cwd)).catch(()=>{})},[]);const b=()=>{h([...f,{name:"",prompt:"",backend:"claude",inheritContext:!0}])},v=async()=>{if(!(!s.trim()||!c.trim()||f.length===0)){g(!0);try{const y=await se.createPipeline({name:s.trim(),description:a.trim()||void 0,cwd:c,stages:f});e(y)}catch(y){console.error("Failed to create pipeline:",y)}g(!1)}};return r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("h2",{className:"text-[14px] font-semibold text-cc-fg",children:"Create Pipeline"}),r.jsx("button",{onClick:t,className:"text-[11px] text-cc-muted hover:text-cc-fg transition-colors",children:"Cancel"})]}),r.jsxs("div",{className:"space-y-3",children:[r.jsx("input",{type:"text",value:s,onChange:y=>n(y.target.value),placeholder:"Pipeline name",className:"w-full px-3 py-2 text-[13px] bg-cc-input-bg border border-cc-border rounded-lg text-cc-fg placeholder:text-cc-muted/40 focus:outline-none focus:border-cc-muted/30"}),r.jsx("input",{type:"text",value:a,onChange:y=>l(y.target.value),placeholder:"Description (optional)",className:"w-full px-3 py-2 text-[13px] bg-cc-input-bg border border-cc-border rounded-lg text-cc-fg placeholder:text-cc-muted/40 focus:outline-none focus:border-cc-muted/30"}),r.jsx("input",{type:"text",value:c,onChange:y=>d(y.target.value),placeholder:"Working directory",className:"w-full px-3 py-2 text-[13px] bg-cc-input-bg border border-cc-border rounded-lg text-cc-fg placeholder:text-cc-muted/40 focus:outline-none focus:border-cc-muted/30 font-mono-code"})]}),r.jsxs("div",{className:"space-y-2",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-[12px] font-medium text-cc-fg",children:"Stages"}),r.jsx("button",{onClick:b,className:"text-[11px] text-cc-primary hover:text-cc-primary-hover transition-colors",children:"+ Add Stage"})]}),f.map((y,S)=>r.jsx(BH,{stage:y,index:S,onChange:j=>{const k=[...f];k[S]=j,h(k)},onRemove:()=>h(f.filter((j,k)=>k!==S))},S))]}),r.jsx("button",{onClick:v,disabled:m||!s.trim()||!c.trim()||f.length===0,className:"w-full py-2 rounded-lg text-[13px] font-medium transition-colors bg-cc-fg text-cc-bg hover:opacity-80 disabled:opacity-30 disabled:cursor-not-allowed",children:m?"Creating...":"Create Pipeline"})]})}function zH({runId:e,onBack:t}){const[s,n]=w.useState(null),a=w.useCallback(async()=>{try{const l=await se.getRun(e);return n(l),l.status==="running"||l.status==="pending"}catch{return!1}},[e]);return w.useEffect(()=>{let l=!0;const c=async()=>{const d=await a();l&&d&&setTimeout(c,2e3)};return c(),()=>{l=!1}},[a]),s?r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("button",{onClick:t,className:"text-[11px] text-cc-muted hover:text-cc-fg transition-colors flex items-center gap-1",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3",children:r.jsx("path",{d:"M7.78 12.53a.75.75 0 01-1.06 0L2.47 8.28a.75.75 0 010-1.06l4.25-4.25a.75.75 0 011.06 1.06L4.81 7h7.44a.75.75 0 010 1.5H4.81l2.97 2.97a.75.75 0 010 1.06z"})}),"Back"]}),r.jsx("span",{className:`text-[11px] font-mono-code ${v0[s.status]}`,children:s.status})]}),r.jsxs("div",{children:[r.jsx("h3",{className:"text-[14px] font-semibold text-cc-fg",children:s.pipelineName}),r.jsxs("div",{className:"flex items-center gap-3 mt-1 text-[11px] text-cc-muted font-mono-code",children:[r.jsx("span",{children:g0(s.totalDurationMs)}),r.jsx("span",{children:x0(s.totalCostUsd)})]})]}),r.jsx("div",{className:"space-y-0",children:s.stageResults.map((l,c)=>r.jsxs("div",{className:"flex items-start gap-3 relative",children:[c<s.stageResults.length-1&&r.jsx("div",{className:"absolute left-[7px] top-[18px] bottom-0 w-px bg-cc-border"}),r.jsx("div",{className:`w-[15px] h-[15px] rounded-full border-2 border-cc-bg shrink-0 mt-0.5 ${LH[l.status]}`}),r.jsxs("div",{className:"flex-1 pb-4",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("span",{className:"text-[12px] font-medium text-cc-fg",children:["Stage ",c+1]}),r.jsxs("span",{className:`text-[10px] font-mono-code ${v0[l.status]}`,children:[l.status,l.durationMs?` · ${g0(l.durationMs)}`:"",l.costUsd?` · ${x0(l.costUsd)}`:""]})]}),l.sessionId&&r.jsx("a",{href:`#/?session=${l.sessionId}`,className:"text-[10px] text-cc-primary hover:text-cc-primary-hover font-mono-code mt-0.5 inline-block",children:"View session"}),l.error&&r.jsx("p",{className:"text-[10px] text-cc-error mt-1 font-mono-code",children:l.error}),l.outputSummary&&r.jsx("p",{className:"text-[10px] text-cc-muted mt-1 line-clamp-2",children:l.outputSummary})]})]},l.stageId))}),s.status==="running"&&r.jsx("button",{onClick:async()=>{await se.cancelRun(s.id),a()},className:"w-full py-2 rounded-lg text-[12px] bg-cc-error/10 text-cc-error hover:bg-cc-error/20 transition-colors",children:"Cancel Run"})]}):r.jsx("div",{className:"text-[13px] text-cc-muted p-6 text-center",children:"Loading run..."})}function PH(){const[e,t]=w.useState("list"),[s,n]=w.useState([]),[a,l]=w.useState([]),[c,d]=w.useState(null),[f,h]=w.useState(!0),m=w.useCallback(async()=>{try{const[g,b]=await Promise.all([se.listPipelines(),se.listRuns()]);n(g),l(b)}catch{}h(!1)},[]);return w.useEffect(()=>{m()},[m]),e==="create"?r.jsx("div",{className:"flex-1 overflow-y-auto p-6",children:r.jsx("div",{className:"max-w-2xl mx-auto",children:r.jsx(OH,{onSave:()=>{m(),t("list")},onCancel:()=>t("list")})})}):e==="run-view"&&c?r.jsx("div",{className:"flex-1 overflow-y-auto p-6",children:r.jsx("div",{className:"max-w-2xl mx-auto",children:r.jsx(zH,{runId:c,onBack:()=>{t("list"),m()}})})}):r.jsx("div",{className:"flex-1 overflow-y-auto p-6",children:r.jsxs("div",{className:"max-w-2xl mx-auto space-y-6",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("h1",{className:"text-[16px] font-semibold text-cc-fg",children:"Orchestrator"}),r.jsx("p",{className:"text-[12px] text-cc-muted mt-0.5",children:"Chain multiple AI sessions into multi-stage pipelines"})]}),r.jsx("button",{onClick:()=>t("create"),className:"px-3 py-1.5 rounded-lg text-[12px] font-medium bg-cc-fg text-cc-bg hover:opacity-80 transition-colors",children:"New Pipeline"})]}),f?r.jsx("div",{className:"text-center py-8 text-[13px] text-cc-muted",children:"Loading..."}):r.jsxs(r.Fragment,{children:[s.length===0?r.jsxs("div",{className:"text-center py-12 border border-dashed border-cc-border rounded-lg",children:[r.jsx("p",{className:"text-[13px] text-cc-muted",children:"No pipelines yet"}),r.jsx("p",{className:"text-[11px] text-cc-muted/60 mt-1",children:"Create a pipeline to chain AI sessions into multi-stage workflows"})]}):r.jsxs("div",{className:"space-y-2",children:[r.jsx("h2",{className:"text-[12px] text-cc-muted uppercase tracking-wider font-medium",children:"Pipelines"}),s.map(g=>r.jsx("div",{className:"border border-cc-border rounded-lg p-3 hover:bg-cc-hover/30 transition-colors",children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("span",{className:"text-[13px] font-medium text-cc-fg",children:g.name}),g.description&&r.jsx("p",{className:"text-[11px] text-cc-muted mt-0.5",children:g.description}),r.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[r.jsxs("span",{className:"text-[10px] text-cc-muted/60 font-mono-code",children:[g.stages.length," stages"]}),r.jsx("span",{className:"text-[10px] text-cc-muted/60 font-mono-code",children:g.cwd})]})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("button",{onClick:async()=>{try{const b=await se.runPipeline(g.id);d(b.id),t("run-view")}catch(b){console.error("Failed to run pipeline:",b)}},className:"px-2.5 py-1 rounded-md text-[11px] bg-cc-primary/10 text-cc-primary hover:bg-cc-primary/20 transition-colors",children:"Run"}),r.jsx("button",{onClick:async()=>{await se.deletePipeline(g.id),m()},className:"px-2 py-1 rounded-md text-[11px] text-cc-muted hover:text-cc-error transition-colors",children:"Delete"})]})]})},g.id))]}),a.length>0&&r.jsxs("div",{className:"space-y-2",children:[r.jsx("h2",{className:"text-[12px] text-cc-muted uppercase tracking-wider font-medium",children:"Recent Runs"}),a.slice(0,10).map(g=>r.jsxs("button",{onClick:()=>{d(g.id),t("run-view")},className:"w-full border border-cc-border rounded-lg p-3 hover:bg-cc-hover/30 transition-colors text-left",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-[12px] font-medium text-cc-fg",children:g.pipelineName}),r.jsx("span",{className:`text-[10px] font-mono-code ${v0[g.status]}`,children:g.status})]}),r.jsxs("div",{className:"flex items-center gap-3 mt-1 text-[10px] text-cc-muted font-mono-code",children:[r.jsx("span",{children:g0(g.totalDurationMs)}),r.jsx("span",{children:x0(g.totalCostUsd)}),r.jsxs("span",{children:[g.stageResults.filter(b=>b.status==="completed").length,"/",g.stageResults.length," stages"]}),r.jsx("span",{children:new Date(g.startedAt).toLocaleDateString()})]})]},g.id))]})]})]})})}function $H(e){if(!e)return"-";const t=Math.round(e/1e3);return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`}function IH(e){return e?e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`:"$0"}function FH(e){return e==="completed"?"text-cc-success":e==="failed"||e==="timeout"?"text-cc-error":e==="running"?"text-cc-primary":"text-cc-muted"}function HH({race:e,onUpdate:t}){const s=Y(h=>h.setCurrentSession),[n,a]=w.useState(new Map),[l,c]=w.useState(null),d=async h=>{const m=await se.pickRaceWinner(e.raceId,h);t(m)},f=async h=>{c(h.id);try{const m=await se.getRaceEntryDiff(e.raceId,h.id);a(g=>new Map(g).set(h.id,m.diff||""))}finally{c(null)}};return r.jsx("div",{className:"grid grid-cols-1 xl:grid-cols-3 gap-3",children:e.entries.map(h=>{var m,g,b,v,y,S;return r.jsxs("div",{className:"rounded-lg border border-cc-border bg-cc-card overflow-hidden",children:[r.jsxs("div",{className:"px-3 py-2.5 border-b border-cc-border/50 flex items-center justify-between",children:[r.jsxs("div",{className:"min-w-0",children:[r.jsx("div",{className:"text-[13px] font-semibold text-cc-fg truncate",children:h.backendType}),r.jsx("div",{className:`text-[10px] uppercase font-mono-code ${FH(h.status)}`,children:h.status})]}),r.jsx("button",{disabled:h.status!=="completed"||e.winnerId===h.sessionId,onClick:()=>void d(h.sessionId),className:"px-2 py-1 rounded-md text-[11px] bg-cc-fg text-cc-bg disabled:opacity-30 disabled:cursor-not-allowed",children:e.winnerId===h.sessionId?"Selected":"Merge"})]}),r.jsxs("div",{className:"px-3 py-2.5 grid grid-cols-2 gap-2 text-[11px]",children:[r.jsx(eh,{label:"Time",value:$H((m=h.metrics)==null?void 0:m.wallClockMs)}),r.jsx(eh,{label:"Cost",value:IH((g=h.metrics)==null?void 0:g.costUsd)}),r.jsx(eh,{label:"Files",value:String(((b=h.metrics)==null?void 0:b.filesChanged)??0)}),r.jsx(eh,{label:"Lines",value:`+${((v=h.metrics)==null?void 0:v.linesAdded)??0} -${((y=h.metrics)==null?void 0:y.linesRemoved)??0}`})]}),r.jsxs("div",{className:"px-3 pb-3",children:[r.jsx("div",{className:"text-[10px] text-cc-muted uppercase tracking-wider mb-1",children:"Summary"}),r.jsx("p",{className:"min-h-20 max-h-40 overflow-auto rounded-md bg-cc-bg/60 px-2 py-1.5 text-[11px] text-cc-muted whitespace-pre-wrap",children:h.error||h.outputSummary||(h.status==="skipped"?"Skipped — an earlier cascade entry succeeded.":"No output yet.")})]}),r.jsxs("div",{className:"px-3 pb-3",children:[r.jsxs("div",{className:"flex items-center justify-between mb-1",children:[r.jsx("div",{className:"text-[10px] text-cc-muted uppercase tracking-wider",children:"Diff"}),r.jsx("button",{onClick:()=>void f(h),className:"text-[10px] text-cc-primary hover:text-cc-primary-hover",children:l===h.id?"Loading...":"Load"})]}),n.has(h.id)?n.get(h.id)?r.jsx("div",{className:"max-h-72 overflow-auto rounded-md border border-cc-border/50",children:r.jsx(yr,{unifiedDiff:n.get(h.id),fileName:h.branch,mode:"compact"})}):r.jsx("p",{className:"rounded-md bg-cc-bg/60 px-2 py-1.5 text-[11px] text-cc-muted",children:"No diff for this entry."}):r.jsx("p",{className:"rounded-md bg-cc-bg/60 px-2 py-1.5 text-[11px] text-cc-muted",children:(S=h.filesChanged)!=null&&S.length?`${h.filesChanged.length} changed files`:"No changed files recorded yet."})]}),r.jsxs("button",{onClick:()=>{s(h.sessionId),kr(h.sessionId),window.location.hash=""},className:"w-full border-t border-cc-border/50 px-3 py-2 text-left text-[11px] text-cc-muted hover:text-cc-fg hover:bg-cc-hover",children:["Open session ",h.sessionId.slice(0,8)]})]},h.id)})})}function eh({label:e,value:t}){return r.jsxs("div",{className:"rounded-md bg-cc-bg/60 px-2 py-1.5",children:[r.jsx("div",{className:"text-[9px] text-cc-muted uppercase tracking-wider",children:e}),r.jsx("div",{className:"text-[12px] text-cc-fg font-mono-code",children:t})]})}const UH=[{id:"claude",label:"Claude"},{id:"codex",label:"Codex"},{id:"goose",label:"Goose"},{id:"aider",label:"Aider"},{id:"openhands",label:"OpenHands"}];function VH(){var I;const e=typeof window<"u"?(I=window.location.hash.match(/^#\/races\/([^/?#]+)/))==null?void 0:I[1]:void 0,[t,s]=w.useState([]),[n,a]=w.useState(e?decodeURIComponent(e):null),[l,c]=w.useState(""),[d,f]=w.useState(""),[h,m]=w.useState(["claude","codex"]),[g,b]=w.useState(!1),[v,y]=w.useState([]),[S,j]=w.useState(()=>{try{return localStorage.getItem("cc-selected-env")||""}catch{return""}}),[k,E]=w.useState(null),[N,B]=w.useState(!1),A=w.useMemo(()=>t.find(H=>H.raceId===n)||t[0]||null,[t,n]),P=w.useCallback(async()=>{const H=await se.listRaces();s(H),!n&&H[0]&&a(e?decodeURIComponent(e):H[0].raceId)},[n]);w.useEffect(()=>{se.getHome().then(async H=>{try{const F=await se.getRepoInfo(H.cwd);c(F.repoRoot)}catch{c(H.cwd)}}).catch(()=>{}),se.listEnvs().then(y).catch(()=>{}),P()},[P]),w.useEffect(()=>{if(!((A==null?void 0:A.status)==="running"))return;const F=setInterval(()=>void P(),2e3);return()=>clearInterval(F)},[P,A==null?void 0:A.status]);const K=H=>{m(F=>F.includes(H)?F.filter(G=>G!==H):[...F,H])},X=async()=>{E(null),B(!0);try{const H=await se.createRace({prompt:d,repoRoot:l,backends:h,envSlug:S||void 0,cascade:g||void 0});s(F=>[H,...F]),a(H.raceId),window.location.hash=`#/races/${encodeURIComponent(H.raceId)}`,f("")}catch(H){E(H instanceof Error?H.message:String(H))}finally{B(!1)}},Z=async H=>{const F=await se.cancelRace(H);s(G=>G.map(q=>q.raceId===F.raceId?F:q))};return r.jsx("div",{className:"h-full overflow-auto bg-cc-bg",children:r.jsxs("div",{className:"max-w-6xl mx-auto p-4 space-y-4",children:[r.jsx("div",{className:"flex items-center justify-between",children:r.jsxs("div",{children:[r.jsx("h1",{className:"text-[18px] font-semibold text-cc-fg",children:"Agent Races"}),r.jsx("p",{className:"text-[12px] text-cc-muted",children:"Run the same task in isolated worktrees and compare the results."})]})}),r.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-[360px_1fr] gap-4",children:[r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{className:"rounded-lg border border-cc-border bg-cc-card p-3 space-y-3",children:[r.jsx("input",{value:l,onChange:H=>c(H.target.value),placeholder:"Repository root",className:"w-full px-2.5 py-2 rounded-md border border-cc-border bg-cc-input-bg text-[12px] text-cc-fg font-mono-code"}),r.jsx("textarea",{value:d,onChange:H=>f(H.target.value),placeholder:"Task prompt",rows:5,className:"w-full px-2.5 py-2 rounded-md border border-cc-border bg-cc-input-bg text-[12px] text-cc-fg resize-none"}),r.jsx("div",{className:"grid grid-cols-2 gap-2",children:UH.map(H=>r.jsxs("label",{className:"flex items-center gap-2 rounded-md border border-cc-border px-2 py-1.5 text-[11px] text-cc-fg",children:[r.jsx("input",{type:"checkbox",checked:h.includes(H.id),onChange:()=>K(H.id)}),H.label]},H.id))}),r.jsxs("label",{className:"flex items-start gap-2 rounded-md border border-cc-border px-2 py-1.5 text-[11px] text-cc-fg",children:[r.jsx("input",{type:"checkbox",checked:g,onChange:()=>b(H=>!H),className:"mt-0.5"}),r.jsxs("span",{children:["Cost cascade — run backends in order, stop at first success",r.jsx("span",{className:"block text-[10px] text-cc-muted",children:"List cheapest first; failures and empty patches escalate to the next backend."})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-[10px] font-semibold text-cc-muted/60 uppercase tracking-wider mb-1.5",htmlFor:"race-env-select",children:"Environment"}),r.jsxs("div",{className:"flex gap-1",children:[r.jsxs("select",{id:"race-env-select",value:S,onChange:H=>{j(H.target.value);try{localStorage.setItem("cc-selected-env",H.target.value)}catch{}},onFocus:()=>{se.listEnvs().then(y).catch(()=>{})},className:"flex-1 min-w-0 px-2.5 py-2 rounded-md border border-cc-border bg-cc-input-bg text-[12px] text-cc-fg focus:outline-none focus:border-cc-primary/50 cursor-pointer",children:[r.jsx("option",{value:"",children:"No environment"}),v.map(H=>r.jsxs("option",{value:H.slug,children:[H.name," (",Object.keys(H.variables).length," vars)"]},H.slug))]}),r.jsx("button",{type:"button",onClick:()=>{window.location.hash="#/environments"},"aria-label":"Manage environments",className:"px-2.5 py-2 rounded-md border border-cc-border bg-cc-input-bg text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer shrink-0",children:r.jsxs("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3",children:[r.jsx("path",{d:"M8 4.754a3.246 3.246 0 100 6.492 3.246 3.246 0 000-6.492zM5.754 8a2.246 2.246 0 114.492 0 2.246 2.246 0 01-4.492 0z"}),r.jsx("path",{d:"M9.796 1.343c-.527-1.79-3.065-1.79-3.592 0a1.843 1.843 0 01-2.739 1.049c-1.547-.966-3.317.803-2.35 2.35a1.843 1.843 0 01-1.049 2.74c-1.79.526-1.79 3.064 0 3.59a1.843 1.843 0 011.049 2.74c-.966 1.547.803 3.317 2.35 2.35a1.843 1.843 0 012.74 1.049c.526 1.79 3.064 1.79 3.59 0a1.843 1.843 0 012.74-1.049c1.547.966 3.317-.803 2.35-2.35a1.843 1.843 0 011.049-2.74c1.79-.526 1.79-3.064 0-3.59a1.843 1.843 0 01-1.049-2.74c.966-1.547-.803-3.317-2.35-2.35a1.843 1.843 0 01-2.74-1.049z"})]})})]})]}),k&&r.jsx("div",{className:"text-[11px] text-cc-error",children:k}),r.jsx("button",{onClick:()=>void X(),disabled:N||!d.trim()||!l.trim()||h.length<2,className:"w-full rounded-md bg-cc-fg text-cc-bg px-3 py-2 text-[12px] font-medium disabled:opacity-30 disabled:cursor-not-allowed",children:N?"Starting...":"Start Race"})]}),r.jsxs("div",{className:"rounded-lg border border-cc-border bg-cc-card overflow-hidden",children:[t.map(H=>r.jsxs("button",{onClick:()=>{a(H.raceId),window.location.hash=`#/races/${encodeURIComponent(H.raceId)}`},className:`w-full text-left px-3 py-2 border-b border-cc-border/40 hover:bg-cc-hover ${(A==null?void 0:A.raceId)===H.raceId?"bg-cc-hover":""}`,children:[r.jsx("div",{className:"text-[12px] text-cc-fg truncate",children:H.prompt}),r.jsxs("div",{className:"text-[10px] text-cc-muted uppercase font-mono-code",children:[H.status," / ",H.entries.length," agents",H.cascade?" / cascade":""]})]},H.raceId)),t.length===0&&r.jsx("div",{className:"px-3 py-5 text-[12px] text-cc-muted",children:"No races yet."})]})]}),r.jsx("div",{className:"space-y-3",children:A?r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"rounded-lg border border-cc-border bg-cc-card p-3 flex items-center justify-between gap-3",children:[r.jsxs("div",{className:"min-w-0",children:[r.jsx("div",{className:"text-[13px] font-semibold text-cc-fg truncate",children:A.prompt}),r.jsxs("div",{className:"text-[10px] text-cc-muted font-mono-code uppercase",children:[A.status," on ",A.baseBranch,A.cascade?" / cascade":""]})]}),A.status==="running"&&r.jsx("button",{onClick:()=>void Z(A.raceId),className:"px-2 py-1 rounded-md text-[11px] text-cc-error border border-cc-error/40",children:"Cancel"})]}),r.jsx(HH,{race:A,onUpdate:H=>s(F=>F.map(G=>G.raceId===H.raceId?H:G))})]}):r.jsx("div",{className:"rounded-lg border border-cc-border bg-cc-card p-6 text-[12px] text-cc-muted",children:"Start a race to compare agents."})})]})]})})}const WH={pending:{label:"To Do",emptyText:"No pending tasks",dotColor:"bg-cc-muted/40",headerColor:"text-cc-muted"},in_progress:{label:"In Progress",emptyText:"Nothing in progress",dotColor:"bg-cc-primary animate-pulse",headerColor:"text-cc-primary"},completed:{label:"Done",emptyText:"Nothing completed yet",dotColor:"bg-cc-success",headerColor:"text-cc-success"}};function qH({task:e}){const t=e.blockedBy&&e.blockedBy.length>0;return r.jsxs("div",{className:`p-3 rounded-lg border transition-colors ${t?"border-cc-border/50 bg-cc-hover/30 opacity-60":"border-cc-border bg-cc-card hover:border-cc-muted/20"}`,children:[r.jsx("div",{className:"flex items-start gap-2",children:r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-[12px] font-medium text-cc-fg leading-tight",children:e.subject}),e.description&&e.description!==e.subject&&r.jsx("p",{className:"text-[10px] text-cc-muted mt-1 line-clamp-2 leading-relaxed",children:e.description})]})}),r.jsxs("div",{className:"flex items-center gap-2 mt-2 flex-wrap",children:[e.owner&&r.jsx("span",{className:"text-[9px] font-mono-code px-1.5 py-0.5 rounded bg-cc-hover text-cc-muted",children:e.owner}),e.activeForm&&e.status==="in_progress"&&r.jsx("span",{className:"text-[9px] font-mono-code px-1.5 py-0.5 rounded bg-cc-primary/10 text-cc-primary",children:e.activeForm}),t&&r.jsx("span",{className:"text-[9px] font-mono-code px-1.5 py-0.5 rounded bg-cc-warning/10 text-cc-warning",children:"blocked"}),r.jsxs("span",{className:"text-[9px] font-mono-code text-cc-muted/40 ml-auto",children:["#",e.id]})]})]})}function Bg({column:e,tasks:t}){const s=WH[e];return r.jsxs("div",{className:"flex-1 min-w-[250px] max-w-[400px]",children:[r.jsxs("div",{className:"flex items-center gap-2 px-1 pb-3 border-b border-cc-border",children:[r.jsx("div",{className:`w-2 h-2 rounded-full ${s.dotColor}`}),r.jsx("span",{className:`text-[12px] font-semibold ${s.headerColor}`,children:s.label}),r.jsx("span",{className:"text-[10px] text-cc-muted/50 font-mono-code tabular-nums ml-auto",children:t.length})]}),r.jsx("div",{className:"space-y-2 pt-3 min-h-[100px]",children:t.length===0?r.jsx("div",{className:"text-[11px] text-cc-muted/40 italic text-center py-6",children:s.emptyText}):t.map(n=>r.jsx(qH,{task:n},n.id))})]})}function GH(){var f;const e=Y(h=>h.currentSessionId),t=Y(h=>h.sessionTasks),s=Y(h=>h.sessionNames),n=Y(h=>h.sdkSessions),{grouped:a,totalCount:l,sessionId:c}=w.useMemo(()=>{const h=[],m=[],g=[],b=e?[[e,t.get(e)||[]]]:Array.from(t.entries());for(const[,v]of b)for(const y of v)y.status==="completed"?g.push(y):y.status==="in_progress"?m.push(y):h.push(y);return{grouped:{pending:h,in_progress:m,completed:g},totalCount:h.length+m.length+g.length,sessionId:e}},[t,e]),d=c?s.get(c)||((f=n.find(h=>h.sessionId===c))==null?void 0:f.name)||c.slice(0,8):null;return r.jsx("div",{className:"flex-1 overflow-y-auto p-6",children:r.jsxs("div",{className:"max-w-5xl mx-auto space-y-6",children:[r.jsxs("div",{children:[r.jsx("h1",{className:"text-[16px] font-semibold text-cc-fg",children:"Task Board"}),r.jsx("p",{className:"text-[12px] text-cc-muted mt-0.5",children:d?`Tasks from session: ${d}`:"Tasks extracted from agent tool calls (TodoWrite, TaskCreate)"})]}),l===0?r.jsxs("div",{className:"text-center py-16 border border-dashed border-cc-border rounded-lg",children:[r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-8 h-8 mx-auto text-cc-muted/20 mb-3",children:r.jsx("path",{d:"M1.5 3.25a2.25 2.25 0 013-2.122V1A2.5 2.5 0 017 3.5H3.25a.75.75 0 010-1.5h3.06A1 1 0 005.5 1.5h-1a.75.75 0 01-.75-.75.75.75 0 00-1.5 0v.5h-.5a.25.25 0 00-.25.25zm13 0v.5a.25.25 0 01-.25.25H8V1h.75a.75.75 0 01.75.75.75.75 0 001.5 0h-1a1 1 0 00-.81.5h3.06a.75.75 0 010 1.5H9A2.5 2.5 0 0111.5 1v.128a2.25 2.25 0 013 2.122zM1.5 5v8.25c0 .966.784 1.75 1.75 1.75h9.5A1.75 1.75 0 0014.5 13.25V5h-13z"})}),r.jsx("p",{className:"text-[13px] text-cc-muted",children:"No tasks yet"}),r.jsx("p",{className:"text-[11px] text-cc-muted/60 mt-1",children:"Tasks appear here when agents use TodoWrite or TaskCreate tools"})]}):r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"flex items-center gap-4 text-[11px] font-mono-code",children:[r.jsxs("span",{className:"text-cc-muted",children:[a.completed.length,"/",l," complete"]}),a.in_progress.length>0&&r.jsxs("span",{className:"text-cc-primary",children:[a.in_progress.length," in progress"]}),r.jsx("div",{className:"flex-1 h-1 rounded-full bg-cc-hover overflow-hidden max-w-[200px]",children:r.jsx("div",{className:"h-full rounded-full bg-cc-success transition-all duration-500",style:{width:`${a.completed.length/l*100}%`}})})]}),r.jsxs("div",{className:"flex gap-4 overflow-x-auto pb-4",children:[r.jsx(Bg,{column:"pending",tasks:a.pending}),r.jsx(Bg,{column:"in_progress",tasks:a.in_progress}),r.jsx(Bg,{column:"completed",tasks:a.completed})]})]})]})})}function KH({embedded:e}){const[t,s]=w.useState([]),[n,a]=w.useState(!0),[l,c]=w.useState(""),[d,f]=w.useState(null),[h,m]=w.useState({}),[g,b]=w.useState(null);w.useEffect(()=>{v()},[]);async function v(){a(!0),c("");try{const E=await se.listPlugins();s(E)}catch(E){c(E instanceof Error?E.message:"Failed to load plugins")}finally{a(!1)}}async function y(E){b(E.id);try{const N=await se.togglePlugin(E.id,!E.disabledInCampfire);s(B=>B.map(A=>A.id===E.id?{...A,disabledInCampfire:N.disabled}:A))}catch(N){c(N instanceof Error?N.message:"Failed to toggle plugin")}finally{b(null)}}async function S(E,N){const B=`${E}:${N}`;if(!h[B])try{const{content:A}=await se.readSkillContent(E,N);m(P=>({...P,[B]:A}))}catch{m(A=>({...A,[B]:"Failed to load skill content."}))}}const j=t.reduce((E,N)=>E+N.skills.length,0),k=t.reduce((E,N)=>E+N.commands.length,0);return r.jsxs("div",{className:"h-full flex flex-col ",children:[r.jsx("div",{className:"shrink-0 px-4 py-3 border-b border-cc-border",children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("h2",{className:"text-sm font-medium text-cc-fg",children:"Skills & Plugins"}),r.jsxs("p",{className:"text-[11px] text-cc-muted mt-0.5",children:[t.length," plugin",t.length!==1?"s":""," installed",j>0&&` · ${j} skill${j!==1?"s":""}`,k>0&&` · ${k} command${k!==1?"s":""}`]})]}),r.jsx("button",{onClick:v,disabled:n,className:"px-2.5 py-1 text-[11px] font-mono-code text-cc-muted hover:text-cc-fg rounded-md hover:bg-cc-hover transition-colors cursor-pointer",children:n?"Loading...":"Refresh"})]})}),r.jsxs("div",{className:"flex-1 overflow-y-auto p-4 space-y-3",children:[l&&r.jsx("div",{className:"px-3 py-2 rounded-lg bg-cc-error/5 border border-cc-error/20 text-xs text-cc-error",children:l}),n&&t.length===0&&r.jsxs("div",{className:"flex items-center justify-center py-12 text-cc-muted text-xs",children:[r.jsx("span",{className:"w-4 h-4 border-2 border-cc-muted/30 border-t-cc-muted rounded-full animate-spin mr-2"}),"Loading plugins..."]}),!n&&t.length===0&&!l&&r.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-cc-muted",children:[r.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",className:"w-8 h-8 opacity-30 mb-2",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z"})}),r.jsx("p",{className:"text-xs",children:"No plugins installed."}),r.jsxs("p",{className:"text-[11px] mt-1 opacity-70",children:["Install plugins via ",r.jsx("code",{className:"font-mono-code bg-cc-hover px-1 rounded",children:"/install-plugin"})," in Claude Code."]})]}),t.map(E=>r.jsxs("div",{className:`rounded-lg border transition-colors ${E.blocked?"border-cc-error/20 bg-cc-error/5":E.disabledInCampfire?"border-cc-border bg-cc-hover/50 opacity-60":"border-cc-border bg-cc-card"}`,children:[r.jsxs("div",{className:"px-3 py-2.5 flex items-start gap-3",children:[r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("button",{onClick:()=>f(d===E.id?null:E.id),className:"text-xs font-medium text-cc-fg hover:text-cc-primary transition-colors cursor-pointer truncate",children:E.name}),r.jsx("span",{className:"text-[10px] font-mono-code text-cc-muted bg-cc-hover px-1.5 py-0.5 rounded shrink-0",children:E.marketplace}),E.blocked&&r.jsx("span",{className:"text-[10px] font-mono-code text-cc-error bg-cc-error/10 px-1.5 py-0.5 rounded shrink-0",children:"blocked"})]}),E.description&&r.jsx("p",{className:"text-[11px] text-cc-muted mt-0.5 line-clamp-2",children:E.description}),r.jsxs("div",{className:"flex items-center gap-3 mt-1.5 text-[10px] text-cc-muted",children:[E.author&&r.jsxs("span",{children:["by ",E.author]}),r.jsxs("span",{children:["v",E.version]}),E.skills.length>0&&r.jsxs("span",{children:[E.skills.length," skill",E.skills.length!==1?"s":""]}),E.commands.length>0&&r.jsxs("span",{children:[E.commands.length," cmd",E.commands.length!==1?"s":""]})]})]}),r.jsx("button",{onClick:()=>y(E),disabled:g===E.id||E.blocked,className:`shrink-0 px-2.5 py-1 text-[11px] font-medium rounded-md transition-colors cursor-pointer disabled:opacity-50 ${E.disabledInCampfire?"bg-cc-hover text-cc-muted hover:text-cc-fg":"bg-cc-primary/15 text-cc-primary hover:bg-cc-primary/25"}`,children:g===E.id?"...":E.disabledInCampfire?"Enable":"Disable"})]}),d===E.id&&r.jsxs("div",{className:"border-t border-cc-border px-3 py-2.5 space-y-2",children:[E.skills.length>0&&r.jsxs("div",{children:[r.jsx("h4",{className:"text-[10px] font-mono-code text-cc-muted uppercase tracking-wider mb-1",children:"Skills"}),E.skills.map(N=>{const B=`${E.id}:${N.name}`;return r.jsxs("div",{className:"mb-1.5",children:[r.jsx("button",{onClick:()=>S(E.id,N.name),className:"text-[11px] font-mono-code text-cc-fg hover:text-cc-primary transition-colors cursor-pointer",children:N.name}),N.description&&r.jsx("p",{className:"text-[10px] text-cc-muted ml-2",children:N.description}),h[B]&&r.jsx("pre",{className:"mt-1 p-2 rounded bg-cc-code-bg text-cc-code-fg text-[10px] font-mono-code overflow-x-auto max-h-48 overflow-y-auto",children:h[B]})]},N.name)})]}),E.commands.length>0&&r.jsxs("div",{children:[r.jsx("h4",{className:"text-[10px] font-mono-code text-cc-muted uppercase tracking-wider mb-1",children:"Commands"}),E.commands.map(N=>r.jsxs("div",{className:"text-[11px] font-mono-code text-cc-fg",children:["/",N.name]},N.name))]}),r.jsx("div",{className:"text-[10px] font-mono-code text-cc-muted pt-1 border-t border-cc-border truncate",title:E.installPath,children:E.installPath})]})]},E.id))]})]})}function YH(){return w.useSyncExternalStore(e=>(window.addEventListener("hashchange",e),()=>window.removeEventListener("hashchange",e)),()=>window.location.hash)}function XH(){const[e,t]=w.useState(!1),[s,n]=w.useState(!1),[a,l]=w.useState(!1);w.useEffect(()=>{se.getAuthStatus().then(ke=>{ke.enabled&&!ke.isLoggedIn&&(qh()&&BM(),n(!0)),t(!0)}).catch(()=>{t(!0)})},[]),w.useEffect(()=>{se.getSettings().then(ke=>{ke.onboardingCompleted||l(!0)}).catch(()=>{})},[]);const c=Y(ke=>ke.darkMode),d=Y(ke=>ke.currentSessionId),f=Y(ke=>{const Xe=ke.currentSessionId;return Xe?(ke.myRole.get(Xe)??null)==="spectator":!1}),h=Y(ke=>{const Xe=ke.currentSessionId;return Xe&&(ke.myRole.get(Xe)??null)==="spectator"?!1:ke.sidebarOpen}),m=Y(ke=>ke.taskPanelOpen),g=Y(ke=>ke.homeResetKey),b=Y(ke=>ke.activeTab),v=Y(ke=>ke.updateOverlayActive),y=YH(),S=y==="#/settings",j=y==="#/terminal",k=y==="#/environments",E=y==="#/scheduled",N=y==="#/hub",B=y==="#/monitor",A=y==="#/commands",P=y==="#/gallery"||y.startsWith("#/gallery?"),K=P&&new URLSearchParams(y.replace(/^#\/gallery\??/,"")).get("session")||void 0,X=Y(ke=>{var Xe,Je;if(K)return((Xe=ke.sessionNames)==null?void 0:Xe.get(K))||((Je=ke.sdkSessions.find($e=>$e.sessionId===K))==null?void 0:Je.name)||void 0}),Z=y==="#/webhooks",I=y==="#/adapters",H=y==="#/clawhub",F=y==="#/agents",G=y==="#/prompts",q=y==="#/integrations",R=y==="#/integrations/linear",M=y==="#/memory",O=y==="#/router",W=y==="#/collective",U=y==="#/orchestrator",D=y==="#/races"||y.startsWith("#/races/"),$=y==="#/kanban",z=y==="#/skills",T=y.match(/^#\/replay\/(?!session\/)(.+)$/),ae=y.match(/^#\/replay\/session\/(.+)$/),be=!!T||!!ae,ne=y.match(/^#\/public-replay\/(.+)$/),ve=!!ne,Ae=!S&&!j&&!k&&!E&&!P&&!Z&&!I&&!H&&!F&&!G&&!q&&!R&&!M&&!O&&!W&&!U&&!D&&!$&&!z&&!be&&!ve&&!N&&!B&&!A;w.useEffect(()=>{LM(y||"#/")},[y]),w.useEffect(()=>{document.documentElement.classList.toggle("dark",c)},[c]);const De=y.startsWith("#/join/");return De&&ih(!0),w.useEffect(()=>{f&&!Ae&&!De&&(window.location.hash="")},[f,Ae,De]),w.useEffect(()=>{const ke=y.match(/^#\/join\/(.+)$/);if(!ke)return;const Xe=ke[1];se.joinSession(Xe).then(Je=>{Je.token&&$j(Je.token,Je.session_id),qo(Je.session_id),Y.getState().setCurrentSession(Je.session_id),kr(Je.session_id),ih(!1),window.location.hash=""}).catch(()=>{console.warn(`[App] Invalid invite token: ${Xe}`),ih(!1),window.location.hash=""})},[y]),w.useEffect(()=>{const ke=Y.getState().currentSessionId;ke&&kr(ke)},[]),w.useEffect(()=>{if(!e||s)return;const ke=()=>{se.checkForUpdate().then(Je=>Y.getState().setUpdateInfo(Je)).catch(()=>{})};ke();const Xe=setInterval(ke,300*1e3);return()=>clearInterval(Xe)},[e,s]),e?s?r.jsx(YM,{onLogin:()=>n(!1)}):y==="#/playground"?r.jsx(NP,{}):r.jsxs("div",{className:"h-[100dvh] flex font-sans-ui bg-cc-bg text-cc-fg antialiased text-[12.5px] leading-normal",children:[h&&!f&&r.jsx("div",{className:"fixed inset-0 bg-black/30 z-30 md:hidden",onClick:()=>Y.getState().setSidebarOpen(!1)}),!f&&r.jsx("div",{className:`
|
|
275
275
|
fixed md:relative z-40 md:z-auto
|
|
276
276
|
h-full shrink-0 transition-all duration-150 ease-out
|
|
277
277
|
${h?"w-[232px] translate-x-0":"w-0 -translate-x-full md:w-0 md:-translate-x-full"}
|
|
278
278
|
overflow-hidden
|
|
279
|
-
`,children:r.jsx(sT,{})}),r.jsxs("div",{className:"flex-1 flex flex-col min-w-0 overflow-hidden",children:[r.jsx(ZB,{}),r.jsx(DC,{}),r.jsxs("div",{className:"flex-1 overflow-hidden relative",children:[S&&r.jsx("div",{className:"absolute inset-0",children:r.jsx(
|
|
279
|
+
`,children:r.jsx(sT,{})}),r.jsxs("div",{className:"flex-1 flex flex-col min-w-0 overflow-hidden",children:[r.jsx(ZB,{}),r.jsx(DC,{}),r.jsxs("div",{className:"flex-1 overflow-hidden relative",children:[S&&r.jsx("div",{className:"absolute inset-0",children:r.jsx(A9,{embedded:!0})}),j&&r.jsx("div",{className:"absolute inset-0",children:r.jsx(ZF,{})}),k&&r.jsx("div",{className:"absolute inset-0",children:r.jsx(bC,{embedded:!0})}),E&&r.jsx("div",{className:"absolute inset-0",children:r.jsx(P9,{embedded:!0})}),P&&r.jsx("div",{className:"absolute inset-0",children:r.jsx(nH,{embedded:!0,prefillSessionId:K,prefillName:X})}),N&&r.jsx("div",{className:"absolute inset-0 overflow-y-auto",children:r.jsx(KP,{embedded:!0})}),B&&r.jsx("div",{className:"absolute inset-0 overflow-y-auto",children:r.jsx(QP,{embedded:!0})}),A&&r.jsx("div",{className:"absolute inset-0 overflow-y-auto",children:r.jsx(t9,{embedded:!0})}),Z&&r.jsx("div",{className:"absolute inset-0",children:r.jsx(aH,{embedded:!0})}),I&&r.jsx("div",{className:"absolute inset-0",children:r.jsx(cH,{embedded:!0})}),H&&r.jsx("div",{className:"absolute inset-0",children:r.jsx(uH,{embedded:!0})}),F&&r.jsx("div",{className:"absolute inset-0",children:r.jsx(xH,{embedded:!0})}),G&&r.jsx("div",{className:"absolute inset-0",children:r.jsx(EH,{embedded:!0})}),q&&r.jsx("div",{className:"absolute inset-0",children:r.jsx(MH,{embedded:!0})}),R&&r.jsx("div",{className:"absolute inset-0",children:r.jsx(TH,{embedded:!0})}),M&&r.jsx("div",{className:"absolute inset-0",children:r.jsx(AH,{})}),O&&r.jsx("div",{className:"absolute inset-0",children:r.jsx(RH,{})}),W&&r.jsx("div",{className:"absolute inset-0",children:r.jsx(DH,{})}),U&&r.jsx("div",{className:"absolute inset-0",children:r.jsx(PH,{})}),D&&r.jsx("div",{className:"absolute inset-0",children:r.jsx(VH,{})}),$&&r.jsx("div",{className:"absolute inset-0",children:r.jsx(GH,{})}),z&&r.jsx("div",{className:"absolute inset-0",children:r.jsx(KH,{embedded:!0})}),ve&&ne&&r.jsx("div",{className:"absolute inset-0",children:r.jsx(NH,{token:ne[1]})}),be&&r.jsx("div",{className:"absolute inset-0",children:ae?r.jsx(hS,{sessionId:ae[1]},`session-${ae[1]}`):T?r.jsx(hS,{filename:T[1]},`file-${T[1]}`):null}),Ae&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:`absolute inset-0 ${b==="chat"||!d?"":"hidden"}`,children:d?r.jsx(mC,{sessionId:d}):r.jsx(oO,{},g)}),d&&b==="diff"&&r.jsx("div",{className:"absolute inset-0",children:r.jsx(Gz,{sessionId:d})}),d&&b==="files"&&r.jsx("div",{className:"absolute inset-0",children:r.jsx(Xz,{sessionId:d})})]})]})]}),d&&Ae&&r.jsxs(r.Fragment,{children:[m&&r.jsx("div",{className:"fixed inset-0 bg-black/20 backdrop-blur-sm z-30 lg:hidden",onClick:()=>Y.getState().setTaskPanelOpen(!1)}),r.jsx("div",{className:`
|
|
280
280
|
fixed lg:relative z-40 lg:z-auto right-0 top-0
|
|
281
281
|
h-full shrink-0 transition-all duration-150 ease-out
|
|
282
282
|
${m?"w-[264px] translate-x-0":"w-0 translate-x-full lg:w-0 lg:translate-x-full"}
|
|
283
283
|
overflow-hidden
|
|
284
|
-
`,children:r.jsx(MO,{sessionId:d})})]}),r.jsx(
|
|
284
|
+
`,children:r.jsx(MO,{sessionId:d})})]}),r.jsx(FP,{}),a&&r.jsx(a9,{onComplete:()=>l(!1)}),r.jsx(x9,{active:v})]}):r.jsx("div",{className:"h-[100dvh] flex items-center justify-center bg-cc-bg text-cc-fg text-[12px] text-cc-muted",children:"Loading..."})}class JH extends w.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t,s){console.error("[AppErrorBoundary] Runtime error:",t),console.error("[AppErrorBoundary] Component stack:",s.componentStack),Bj(t,{source:"react_error_boundary",componentStack:s.componentStack})}render(){return this.state.hasError?r.jsx("div",{className:"h-[100dvh] flex items-center justify-center bg-cc-bg text-cc-fg px-4",children:r.jsxs("div",{className:"max-w-md w-full rounded-xl border border-cc-border bg-cc-card p-5 shadow-sm",children:[r.jsx("h1",{className:"text-base font-semibold",children:"A runtime error occurred"}),r.jsx("p",{className:"text-sm text-cc-muted mt-2",children:"Reload the page to recover. The error has been reported."}),r.jsx("button",{type:"button",onClick:()=>window.location.reload(),className:"mt-4 inline-flex items-center rounded-md bg-cc-primary px-3 py-1.5 text-sm text-white hover:bg-cc-primary-hover cursor-pointer",children:"Reload"})]})}):this.props.children}}DM();"serviceWorker"in navigator&&window.addEventListener("load",()=>{navigator.serviceWorker.register("/sw.js").catch(e=>{console.warn("[SW] Registration failed:",e)})});Y4.createRoot(document.getElementById("root")).render(r.jsx(w.StrictMode,{children:r.jsx(JH,{children:r.jsx(XH,{})})}));export{Xi as _,QH as a,b0 as g,r as j,w as r};
|