@jait/gateway 0.1.380 → 0.1.381
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/providers/provider-auth.d.ts.map +1 -1
- package/dist/providers/provider-auth.js +54 -1
- package/dist/providers/provider-auth.js.map +1 -1
- package/dist/routes/jobs.d.ts.map +1 -1
- package/dist/routes/jobs.js +18 -4
- package/dist/routes/jobs.js.map +1 -1
- package/dist/scheduler/service.d.ts.map +1 -1
- package/dist/scheduler/service.js +49 -7
- package/dist/scheduler/service.js.map +1 -1
- package/dist/tools/thread-tools.d.ts +2 -0
- package/dist/tools/thread-tools.d.ts.map +1 -1
- package/dist/tools/thread-tools.js +36 -6
- package/dist/tools/thread-tools.js.map +1 -1
- package/package.json +1 -1
- package/web-dist/assets/{_basePickBy-DlY6CeqD.js → _basePickBy-CHUjTV_c.js} +1 -1
- package/web-dist/assets/{_baseUniq-BM8xrkS5.js → _baseUniq-B-02Lwa9.js} +1 -1
- package/web-dist/assets/{arc-3pQqK4o6.js → arc-BKcM4oDj.js} +1 -1
- package/web-dist/assets/{architectureDiagram-2XIMDMQ5-BKEzask_.js → architectureDiagram-2XIMDMQ5-BIDXNoiY.js} +1 -1
- package/web-dist/assets/{blockDiagram-WCTKOSBZ-huyIlJ4Q.js → blockDiagram-WCTKOSBZ-CjBsnr-_.js} +1 -1
- package/web-dist/assets/{c4Diagram-IC4MRINW-DqEVikGd.js → c4Diagram-IC4MRINW-Lt0KRsHd.js} +1 -1
- package/web-dist/assets/channel-C0bD5C4X.js +1 -0
- package/web-dist/assets/{chunk-4BX2VUAB-BoKJ-OJG.js → chunk-4BX2VUAB-DjnLbicH.js} +1 -1
- package/web-dist/assets/{chunk-55IACEB6-C1E3Hnor.js → chunk-55IACEB6-DzO5SJt9.js} +1 -1
- package/web-dist/assets/{chunk-FMBD7UC4-CB3TMWs8.js → chunk-FMBD7UC4-BltclHUo.js} +1 -1
- package/web-dist/assets/{chunk-JSJVCQXG-O1g0G2B3.js → chunk-JSJVCQXG-CPSCU-9s.js} +1 -1
- package/web-dist/assets/{chunk-KX2RTZJC-3q7HiCg8.js → chunk-KX2RTZJC-BBk32qia.js} +1 -1
- package/web-dist/assets/{chunk-NQ4KR5QH-BmntKVLZ.js → chunk-NQ4KR5QH-B0KDqhO3.js} +1 -1
- package/web-dist/assets/{chunk-QZHKN3VN-Ctg5vohq.js → chunk-QZHKN3VN-BYs0tOXD.js} +1 -1
- package/web-dist/assets/{chunk-WL4C6EOR-CeK_Twd5.js → chunk-WL4C6EOR-CTPalueS.js} +1 -1
- package/web-dist/assets/classDiagram-VBA2DB6C-CT2UTCXP.js +1 -0
- package/web-dist/assets/classDiagram-v2-RAHNMMFH-CT2UTCXP.js +1 -0
- package/web-dist/assets/clone-W1vABNWN.js +1 -0
- package/web-dist/assets/{cose-bilkent-S5V4N54A-DTR6N3FU.js → cose-bilkent-S5V4N54A-BFqo2c_p.js} +1 -1
- package/web-dist/assets/{dagre-KLK3FWXG-CSs4hfDC.js → dagre-KLK3FWXG-7WdfgINc.js} +1 -1
- package/web-dist/assets/{diagram-E7M64L7V-iozf4B30.js → diagram-E7M64L7V-CQaCvBl-.js} +1 -1
- package/web-dist/assets/{diagram-IFDJBPK2-tIS3y3uK.js → diagram-IFDJBPK2-_L618fQZ.js} +1 -1
- package/web-dist/assets/{diagram-P4PSJMXO-B5KsRwYD.js → diagram-P4PSJMXO-B_gM15l_.js} +1 -1
- package/web-dist/assets/{erDiagram-INFDFZHY-Bc-b8bkq.js → erDiagram-INFDFZHY-BWQk9Tsq.js} +1 -1
- package/web-dist/assets/{flowDiagram-PKNHOUZH-BTWC8anG.js → flowDiagram-PKNHOUZH-B4pKU7sd.js} +1 -1
- package/web-dist/assets/{ganttDiagram-A5KZAMGK-BdQVRyBp.js → ganttDiagram-A5KZAMGK-Bhfq6RFf.js} +1 -1
- package/web-dist/assets/{gitGraphDiagram-K3NZZRJ6-BL5ffxCV.js → gitGraphDiagram-K3NZZRJ6-BMR8lvIa.js} +1 -1
- package/web-dist/assets/{graph-DGee0M43.js → graph-XYo57W3X.js} +1 -1
- package/web-dist/assets/{index-BEjGqXlS.js → index-XqFB4-D8.js} +6 -6
- package/web-dist/assets/{infoDiagram-LFFYTUFH-XnlnRPxm.js → infoDiagram-LFFYTUFH-DrcBifIP.js} +1 -1
- package/web-dist/assets/{ishikawaDiagram-PHBUUO56-Cve42QAE.js → ishikawaDiagram-PHBUUO56-BFeaIwGD.js} +1 -1
- package/web-dist/assets/{journeyDiagram-4ABVD52K-BcNXy0Zj.js → journeyDiagram-4ABVD52K-JVV9TD7u.js} +1 -1
- package/web-dist/assets/{kanban-definition-K7BYSVSG-DnIhxK4h.js → kanban-definition-K7BYSVSG-D7DnNg8n.js} +1 -1
- package/web-dist/assets/{layout-CQxaRMz6.js → layout-BbzKGDyk.js} +1 -1
- package/web-dist/assets/{linear-NENy4pgz.js → linear-Cxp9t_hB.js} +1 -1
- package/web-dist/assets/{mindmap-definition-YRQLILUH-DppE3Ia8.js → mindmap-definition-YRQLILUH-D2_cqLtF.js} +1 -1
- package/web-dist/assets/{pieDiagram-SKSYHLDU-CZwDZ5T7.js → pieDiagram-SKSYHLDU-B1IN3_f2.js} +1 -1
- package/web-dist/assets/{quadrantDiagram-337W2JSQ-BWVA0ytP.js → quadrantDiagram-337W2JSQ-Gm2nfs3x.js} +1 -1
- package/web-dist/assets/{requirementDiagram-Z7DCOOCP-BKE5Vkjv.js → requirementDiagram-Z7DCOOCP-Bi_1ThwE.js} +1 -1
- package/web-dist/assets/{sankeyDiagram-WA2Y5GQK-CoPnr-XS.js → sankeyDiagram-WA2Y5GQK-DSoZooYN.js} +1 -1
- package/web-dist/assets/{sequenceDiagram-2WXFIKYE-iQth4L4Z.js → sequenceDiagram-2WXFIKYE-DAvtPEnh.js} +1 -1
- package/web-dist/assets/{stateDiagram-RAJIS63D-DGGowJY6.js → stateDiagram-RAJIS63D-D2tt0Z7v.js} +1 -1
- package/web-dist/assets/stateDiagram-v2-FVOUBMTO-C8N71UT0.js +1 -0
- package/web-dist/assets/{timeline-definition-YZTLITO2-C47XcFVb.js → timeline-definition-YZTLITO2-Bdg4h4NS.js} +1 -1
- package/web-dist/assets/{treemap-KZPCXAKY-Cry7J0EH.js → treemap-KZPCXAKY-CgH_7ZXL.js} +1 -1
- package/web-dist/assets/{vennDiagram-LZ73GAT5-BViN0u4c.js → vennDiagram-LZ73GAT5-Vv1-4U-6.js} +1 -1
- package/web-dist/assets/{xychartDiagram-JWTSCODW-CjcWOYXS.js → xychartDiagram-JWTSCODW-DnW1f2io.js} +1 -1
- package/web-dist/index.html +1 -1
- package/web-dist/assets/channel-BJN4J4A3.js +0 -1
- package/web-dist/assets/classDiagram-VBA2DB6C-BhqDIh6I.js +0 -1
- package/web-dist/assets/classDiagram-v2-RAHNMMFH-BhqDIh6I.js +0 -1
- package/web-dist/assets/clone-CVX5G_9i.js +0 -1
- package/web-dist/assets/stateDiagram-v2-FVOUBMTO-D-vaL8Uf.js +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./angular-html-DA-rfuFy.js","./html-pp8916En.js","./javascript-wDzz0qaB.js","./css-CLj8gQPS.js","./angular-ts-BrjP3tb8.js","./scss-D5BDwBP9.js","./astro-HNnZUWAn.js","./json-Cp-IABpG.js","./typescript-BPQ3VLAy.js","./postcss-CXtECtnM.js","./tsx-COt5Ahok.js","./blade-BjGOyj-B.js","./html-derivative-DlHx6ybY.js","./xml-sdJ4AIDG.js","./java-CylS5w8V.js","./sql-BLtJtn59.js","./coffee-Ch7k5sss.js","./cpp-CofmeUqb.js","./regexp-CDVJQ6XC.js","./glsl-DplSGwfg.js","./c-BIGW1oBm.js","./graphql-ChdNCCLP.js","./jsx-g9-lgVsj.js","./haml-D5jkg6IW.js","./handlebars-BpdQsYii.js","./yaml-Buea-lGh.js","./http-jrhK8wxY.js","./shellscript-Yzrsuije.js","./hurl-irOxFIW8.js","./csv-fuZLfV_i.js","./jinja-f2NsQr07.js","./jison-wvAkD_A8.js","./julia-CxzCAyBv.js","./python-B6aJPvgy.js","./r-Dspwwk_N.js","./marko-DjSrsDqO.js","./less-B1dDrJ26.js","./mdc-DTYItulj.js","./markdown-Cvjx9yec.js","./php-R6g_5hLQ.js","./pug-DKIMFp6K.js","./svelte-Cy7k_4gC.js","./ts-tags-DQrlYJgV.js","./vue-D2xRrEX4.js","./vue-html-AaS7Mt5G.js","./vue-vine-BoDAl6tE.js","./stylus-BEDo0Tqx.js","./dagre-KLK3FWXG-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./angular-html-DA-rfuFy.js","./html-pp8916En.js","./javascript-wDzz0qaB.js","./css-CLj8gQPS.js","./angular-ts-BrjP3tb8.js","./scss-D5BDwBP9.js","./astro-HNnZUWAn.js","./json-Cp-IABpG.js","./typescript-BPQ3VLAy.js","./postcss-CXtECtnM.js","./tsx-COt5Ahok.js","./blade-BjGOyj-B.js","./html-derivative-DlHx6ybY.js","./xml-sdJ4AIDG.js","./java-CylS5w8V.js","./sql-BLtJtn59.js","./coffee-Ch7k5sss.js","./cpp-CofmeUqb.js","./regexp-CDVJQ6XC.js","./glsl-DplSGwfg.js","./c-BIGW1oBm.js","./graphql-ChdNCCLP.js","./jsx-g9-lgVsj.js","./haml-D5jkg6IW.js","./handlebars-BpdQsYii.js","./yaml-Buea-lGh.js","./http-jrhK8wxY.js","./shellscript-Yzrsuije.js","./hurl-irOxFIW8.js","./csv-fuZLfV_i.js","./jinja-f2NsQr07.js","./jison-wvAkD_A8.js","./julia-CxzCAyBv.js","./python-B6aJPvgy.js","./r-Dspwwk_N.js","./marko-DjSrsDqO.js","./less-B1dDrJ26.js","./mdc-DTYItulj.js","./markdown-Cvjx9yec.js","./php-R6g_5hLQ.js","./pug-DKIMFp6K.js","./svelte-Cy7k_4gC.js","./ts-tags-DQrlYJgV.js","./vue-D2xRrEX4.js","./vue-html-AaS7Mt5G.js","./vue-vine-BoDAl6tE.js","./stylus-BEDo0Tqx.js","./dagre-KLK3FWXG-7WdfgINc.js","./graph-XYo57W3X.js","./_baseUniq-B-02Lwa9.js","./layout-BbzKGDyk.js","./_basePickBy-CHUjTV_c.js","./clone-W1vABNWN.js","./cose-bilkent-S5V4N54A-BFqo2c_p.js","./cytoscape.esm-BQaXIfA_.js","./c4Diagram-IC4MRINW-Lt0KRsHd.js","./chunk-JSJVCQXG-CPSCU-9s.js","./flowDiagram-PKNHOUZH-B4pKU7sd.js","./chunk-FMBD7UC4-BltclHUo.js","./chunk-55IACEB6-DzO5SJt9.js","./chunk-KX2RTZJC-BBk32qia.js","./channel-C0bD5C4X.js","./erDiagram-INFDFZHY-BWQk9Tsq.js","./gitGraphDiagram-K3NZZRJ6-BMR8lvIa.js","./chunk-4BX2VUAB-DjnLbicH.js","./chunk-QZHKN3VN-BYs0tOXD.js","./treemap-KZPCXAKY-CgH_7ZXL.js","./ganttDiagram-A5KZAMGK-Bhfq6RFf.js","./linear-Cxp9t_hB.js","./defaultLocale-DX6XiGOO.js","./infoDiagram-LFFYTUFH-DrcBifIP.js","./pieDiagram-SKSYHLDU-B1IN3_f2.js","./arc-BKcM4oDj.js","./quadrantDiagram-337W2JSQ-Gm2nfs3x.js","./xychartDiagram-JWTSCODW-DnW1f2io.js","./requirementDiagram-Z7DCOOCP-Bi_1ThwE.js","./sequenceDiagram-2WXFIKYE-DAvtPEnh.js","./classDiagram-VBA2DB6C-CT2UTCXP.js","./chunk-WL4C6EOR-CTPalueS.js","./classDiagram-v2-RAHNMMFH-CT2UTCXP.js","./stateDiagram-RAJIS63D-D2tt0Z7v.js","./chunk-NQ4KR5QH-B0KDqhO3.js","./stateDiagram-v2-FVOUBMTO-C8N71UT0.js","./journeyDiagram-4ABVD52K-JVV9TD7u.js","./timeline-definition-YZTLITO2-Bdg4h4NS.js","./mindmap-definition-YRQLILUH-D2_cqLtF.js","./kanban-definition-K7BYSVSG-D7DnNg8n.js","./diagram-P4PSJMXO-B_gM15l_.js","./diagram-IFDJBPK2-_L618fQZ.js","./blockDiagram-WCTKOSBZ-CjBsnr-_.js","./architectureDiagram-2XIMDMQ5-BIDXNoiY.js","./diagram-E7M64L7V-CQaCvBl-.js"])))=>i.map(i=>d[i]);
|
|
2
2
|
var _he=Object.defineProperty;var whe=(e,r,n)=>r in e?_he(e,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[r]=n;var ze=(e,r,n)=>whe(e,typeof r!="symbol"?r+"":r,n);function She(e,r){for(var n=0;n<r.length;n++){const i=r[n];if(typeof i!="string"&&!Array.isArray(i)){for(const s in i)if(s!=="default"&&!(s in e)){const o=Object.getOwnPropertyDescriptor(i,s);o&&Object.defineProperty(e,s,o.get?o:{enumerable:!0,get:()=>i[s]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}(function(){const r=document.createElement("link").relList;if(r&&r.supports&&r.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))i(s);new MutationObserver(s=>{for(const o of s)if(o.type==="childList")for(const a of o.addedNodes)a.tagName==="LINK"&&a.rel==="modulepreload"&&i(a)}).observe(document,{childList:!0,subtree:!0});function n(s){const o={};return s.integrity&&(o.integrity=s.integrity),s.referrerPolicy&&(o.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?o.credentials="include":s.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function i(s){if(s.ep)return;s.ep=!0;const o=n(s);fetch(s.href,o)}})();function z0(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function S1t(e){if(Object.prototype.hasOwnProperty.call(e,"__esModule"))return e;var r=e.default;if(typeof r=="function"){var n=function i(){return this instanceof i?Reflect.construct(r,arguments,this.constructor):r.apply(this,arguments)};n.prototype=r.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach(function(i){var s=Object.getOwnPropertyDescriptor(e,i);Object.defineProperty(n,i,s.get?s:{enumerable:!0,get:function(){return e[i]}})}),n}var aN={exports:{}},Zx={};/**
|
|
3
3
|
* @license React
|
|
4
4
|
* react-jsx-runtime.production.js
|
|
@@ -1121,8 +1121,8 @@ Please report this to https://github.com/markedjs/marked.`,r){let s="<p>An error
|
|
|
1121
1121
|
node : x:${e.x} y:${e.y} w:${e.width} h:${e.height}`);const i=e.x,s=e.y,o=Math.abs(i-n.x),a=e.width/2;let l=n.x<r.x?a-o:a+o;const d=e.height/2,u=Math.abs(r.y-n.y),f=Math.abs(r.x-n.x);if(Math.abs(s-r.y)*a>Math.abs(i-r.x)*d){let p=n.y<r.y?r.y-d-s:s-d-r.y;l=f*p/u;const g={x:n.x<r.x?n.x+l:n.x-f+l,y:n.y<r.y?n.y+u-p:n.y-u+p};return l===0&&(g.x=r.x,g.y=r.y),f===0&&(g.x=r.x),u===0&&(g.y=r.y),St.debug(`abc89 top/bottom calc, Q ${u}, q ${p}, R ${f}, r ${l}`,g),g}else{n.x<r.x?l=r.x-a-i:l=i-a-r.x;let p=u*l/f,g=n.x<r.x?n.x+f-l:n.x-f+l,v=n.y<r.y?n.y+p:n.y-p;return St.debug(`sides calc abc89, Q ${u}, q ${p}, R ${f}, r ${l}`,{_x:g,_y:v}),l===0&&(g=r.x,v=r.y),f===0&&(g=r.x),u===0&&(v=r.y),{x:g,y:v}}},"intersection"),NF=X((e,r)=>{St.warn("abc88 cutPathAtIntersect",e,r);let n=[],i=e[0],s=!1;return e.forEach(o=>{if(St.info("abc88 checking point",o,r),!cVe(r,o)&&!s){const a=uVe(r,i,o);St.debug("abc88 inside",o,i,a),St.debug("abc88 intersection",a,r);let l=!1;n.forEach(d=>{l=l||d.x===a.x&&d.y===a.y}),n.some(d=>d.x===a.x&&d.y===a.y)?St.warn("abc88 no intersect",a,n):n.push(a),s=!0}else St.warn("abc88 outside",o,i),i=o,s||n.push(o)}),St.debug("returning points",n),n},"cutPathAtIntersect");function xse(e){const r=[],n=[];for(let i=1;i<e.length-1;i++){const s=e[i-1],o=e[i],a=e[i+1];(s.x===o.x&&o.y===a.y&&Math.abs(o.x-a.x)>5&&Math.abs(o.y-s.y)>5||s.y===o.y&&o.x===a.x&&Math.abs(o.x-s.x)>5&&Math.abs(o.y-a.y)>5)&&(r.push(o),n.push(i))}return{cornerPoints:r,cornerPointPositions:n}}X(xse,"extractCornerPoints");var TF=X(function(e,r,n){const i=r.x-e.x,s=r.y-e.y,o=Math.sqrt(i*i+s*s),a=n/o;return{x:r.x-a*i,y:r.y-a*s}},"findAdjacentPoint"),dVe=X(function(e){const{cornerPointPositions:r}=xse(e),n=[];for(let i=0;i<e.length;i++)if(r.includes(i)){const s=e[i-1],o=e[i+1],a=e[i],l=TF(s,a,5),d=TF(o,a,5),u=d.x-l.x,f=d.y-l.y;n.push(l);const p=Math.sqrt(2)*2;let g={x:a.x,y:a.y};if(Math.abs(o.x-s.x)>10&&Math.abs(o.y-s.y)>=10){St.debug("Corner point fixing",Math.abs(o.x-s.x),Math.abs(o.y-s.y));const v=5;a.x===l.x?g={x:u<0?l.x-v+p:l.x+v-p,y:f<0?l.y-p:l.y+p}:g={x:u<0?l.x-p:l.x+p,y:f<0?l.y-v+p:l.y+v-p}}else St.debug("Corner point skipping fixing",Math.abs(o.x-s.x),Math.abs(o.y-s.y));n.push(g,d)}else n.push(e[i]);return n},"fixCorners"),hVe=X((e,r,n)=>{const i=e-r-n,s=2,o=2,a=s+o,l=Math.floor(i/a),d=Array(l).fill(`${s} ${o}`).join(" ");return`0 ${r} ${d} ${n}`},"generateDashArray"),fVe=X(function(e,r,n,i,s,o,a,l=!1){var P;const{handDrawnSeed:d}=ii();let u=r.points,f=!1;const p=s;var g=o;const v=[];for(const F in r.cssCompiledStyles)xne(F)||v.push(r.cssCompiledStyles[F]);St.debug("UIO intersect check",r.points,g.x,p.x),g.intersect&&p.intersect&&!l&&(u=u.slice(1,r.points.length-1),u.unshift(p.intersect(u[0])),St.debug("Last point UIO",r.start,"-->",r.end,u[u.length-1],g,g.intersect(u[u.length-1])),u.push(g.intersect(u[u.length-1])));const b=btoa(JSON.stringify(u));r.toCluster&&(St.info("to cluster abc88",n.get(r.toCluster)),u=NF(r.points,n.get(r.toCluster).node),f=!0),r.fromCluster&&(St.debug("from cluster abc88",n.get(r.fromCluster),JSON.stringify(u,null,2)),u=NF(u.reverse(),n.get(r.fromCluster).node).reverse(),f=!0);let _=u.filter(F=>!Number.isNaN(F.y));const k=oVe(r.curve);k!=="rounded"&&(_=dVe(_));let w=R_;switch(k){case"linear":w=R_;break;case"basis":w=IA;break;case"cardinal":w=Qee;break;case"bumpX":w=Kee;break;case"bumpY":w=Yee;break;case"catmullRom":w=tte;break;case"monotoneX":w=ate;break;case"monotoneY":w=lte;break;case"natural":w=ute;break;case"step":w=dte;break;case"stepAfter":w=fte;break;case"stepBefore":w=hte;break;case"rounded":w=R_;break;default:w=IA}const{x:C,y:j}=cze(r),N=BIe().x(C).y(j).curve(w);let A;switch(r.thickness){case"normal":A="edge-thickness-normal";break;case"thick":A="edge-thickness-thick";break;case"invisible":A="edge-thickness-invisible";break;default:A="edge-thickness-normal"}switch(r.pattern){case"solid":A+=" edge-pattern-solid";break;case"dotted":A+=" edge-pattern-dotted";break;case"dashed":A+=" edge-pattern-dashed";break;default:A+=" edge-pattern-solid"}let E,R=k==="rounded"?bse(_se(_,r),5):N(_);const L=Array.isArray(r.style)?r.style:[r.style];let z=L.find(F=>F==null?void 0:F.startsWith("stroke:")),$="";r.animate&&($="edge-animation-fast"),r.animation&&($="edge-animation-"+r.animation);let W=!1;if(r.look==="handDrawn"){const F=wr.svg(e);Object.assign([],_);const V=F.path(R,{roughness:.3,seed:d});A+=" transition",E=Fr(V).select("path").attr("id",r.id).attr("class"," "+A+(r.classes?" "+r.classes:"")+($?" "+$:"")).attr("style",L?L.reduce((H,U)=>H+";"+U,""):"");let Y=E.attr("d");E.attr("d",Y),e.node().appendChild(E.node())}else{const F=v.join(";"),V=L?L.reduce((ee,te)=>ee+te+";",""):"",Y=(F?F+";"+V+";":V)+";"+(L?L.reduce((ee,te)=>ee+";"+te,""):"");E=e.append("path").attr("d",R).attr("id",r.id).attr("class"," "+A+(r.classes?" "+r.classes:"")+($?" "+$:"")).attr("style",Y),z=(P=Y.match(/stroke:([^;]+)/))==null?void 0:P[1],W=r.animate===!0||!!r.animation||F.includes("animation");const H=E.node(),U=typeof H.getTotalLength=="function"?H.getTotalLength():0,Q=Wz[r.arrowTypeStart]||0,q=Wz[r.arrowTypeEnd]||0;if(r.look==="neo"&&!W){const te=`stroke-dasharray: ${r.pattern==="dotted"||r.pattern==="dashed"?hVe(U,Q,q):`0 ${Q} ${U-Q-q} ${q}`}; stroke-dashoffset: 0;`;E.attr("style",te+E.attr("style"))}}E.attr("data-edge",!0),E.attr("data-et","edge"),E.attr("data-id",r.id),E.attr("data-points",b),r.showPoints&&_.forEach(F=>{e.append("circle").style("stroke","red").style("fill","red").attr("r",1).attr("cx",F.x).attr("cy",F.y)});let B="";(ii().flowchart.arrowMarkerAbsolute||ii().state.arrowMarkerAbsolute)&&(B=window.location.protocol+"//"+window.location.host+window.location.pathname+window.location.search,B=B.replace(/\(/g,"\\(").replace(/\)/g,"\\)")),St.info("arrowTypeStart",r.arrowTypeStart),St.info("arrowTypeEnd",r.arrowTypeEnd),iVe(E,r,B,a,i,z);const K=Math.floor(u.length/2),M=u[K];ld.isLabelCoordinateInPath(M,E.attr("d"))||(f=!0);let I={};return f&&(I.updatedPath=u),I.originalPath=r.points,I},"insertEdge");function bse(e,r){if(e.length<2)return"";let n="";const i=e.length,s=1e-5;for(let o=0;o<i;o++){const a=e[o],l=e[o-1],d=e[o+1];if(o===0)n+=`M${a.x},${a.y}`;else if(o===i-1)n+=`L${a.x},${a.y}`;else{const u=a.x-l.x,f=a.y-l.y,p=d.x-a.x,g=d.y-a.y,v=Math.hypot(u,f),b=Math.hypot(p,g);if(v<s||b<s){n+=`L${a.x},${a.y}`;continue}const _=u/v,k=f/v,w=p/b,C=g/b,j=_*w+k*C,N=Math.max(-1,Math.min(1,j)),A=Math.acos(N);if(A<s||Math.abs(Math.PI-A)<s){n+=`L${a.x},${a.y}`;continue}const E=Math.min(r/Math.sin(A/2),v/2,b/2),R=a.x-_*E,L=a.y-k*E,z=a.x+w*E,$=a.y+C*E;n+=`L${R},${L}`,n+=`Q${a.x},${a.y} ${z},${$}`}}return n}X(bse,"generateRoundedPath");function hO(e,r){if(!e||!r)return{angle:0,deltaX:0,deltaY:0};const n=r.x-e.x,i=r.y-e.y;return{angle:Math.atan2(i,n),deltaX:n,deltaY:i}}X(hO,"calculateDeltaAndAngle");function _se(e,r){const n=e.map(s=>({...s}));if(e.length>=2&&Na[r.arrowTypeStart]){const s=Na[r.arrowTypeStart],o=e[0],a=e[1],{angle:l}=hO(o,a),d=s*Math.cos(l),u=s*Math.sin(l);n[0].x=o.x+d,n[0].y=o.y+u}const i=e.length;if(i>=2&&Na[r.arrowTypeEnd]){const s=Na[r.arrowTypeEnd],o=e[i-1],a=e[i-2],{angle:l}=hO(a,o),d=s*Math.cos(l),u=s*Math.sin(l);n[i-1].x=o.x-d,n[i-1].y=o.y-u}return n}X(_se,"applyMarkerOffsetsToPoints");var pVe=X((e,r,n,i)=>{r.forEach(s=>{AVe[s](e,n,i)})},"insertMarkers"),mVe=X((e,r,n)=>{St.trace("Making markers for ",n),e.append("defs").append("marker").attr("id",n+"_"+r+"-extensionStart").attr("class","marker extension "+r).attr("refX",18).attr("refY",7).attr("markerWidth",190).attr("markerHeight",240).attr("orient","auto").append("path").attr("d","M 1,7 L18,13 V 1 Z"),e.append("defs").append("marker").attr("id",n+"_"+r+"-extensionEnd").attr("class","marker extension "+r).attr("refX",1).attr("refY",7).attr("markerWidth",20).attr("markerHeight",28).attr("orient","auto").append("path").attr("d","M 1,1 V 13 L18,7 Z")},"extension"),gVe=X((e,r,n)=>{e.append("defs").append("marker").attr("id",n+"_"+r+"-compositionStart").attr("class","marker composition "+r).attr("refX",18).attr("refY",7).attr("markerWidth",190).attr("markerHeight",240).attr("orient","auto").append("path").attr("d","M 18,7 L9,13 L1,7 L9,1 Z"),e.append("defs").append("marker").attr("id",n+"_"+r+"-compositionEnd").attr("class","marker composition "+r).attr("refX",1).attr("refY",7).attr("markerWidth",20).attr("markerHeight",28).attr("orient","auto").append("path").attr("d","M 18,7 L9,13 L1,7 L9,1 Z")},"composition"),yVe=X((e,r,n)=>{e.append("defs").append("marker").attr("id",n+"_"+r+"-aggregationStart").attr("class","marker aggregation "+r).attr("refX",18).attr("refY",7).attr("markerWidth",190).attr("markerHeight",240).attr("orient","auto").append("path").attr("d","M 18,7 L9,13 L1,7 L9,1 Z"),e.append("defs").append("marker").attr("id",n+"_"+r+"-aggregationEnd").attr("class","marker aggregation "+r).attr("refX",1).attr("refY",7).attr("markerWidth",20).attr("markerHeight",28).attr("orient","auto").append("path").attr("d","M 18,7 L9,13 L1,7 L9,1 Z")},"aggregation"),vVe=X((e,r,n)=>{e.append("defs").append("marker").attr("id",n+"_"+r+"-dependencyStart").attr("class","marker dependency "+r).attr("refX",6).attr("refY",7).attr("markerWidth",190).attr("markerHeight",240).attr("orient","auto").append("path").attr("d","M 5,7 L9,13 L1,7 L9,1 Z"),e.append("defs").append("marker").attr("id",n+"_"+r+"-dependencyEnd").attr("class","marker dependency "+r).attr("refX",13).attr("refY",7).attr("markerWidth",20).attr("markerHeight",28).attr("orient","auto").append("path").attr("d","M 18,7 L9,13 L14,7 L9,1 Z")},"dependency"),xVe=X((e,r,n)=>{e.append("defs").append("marker").attr("id",n+"_"+r+"-lollipopStart").attr("class","marker lollipop "+r).attr("refX",13).attr("refY",7).attr("markerWidth",190).attr("markerHeight",240).attr("orient","auto").append("circle").attr("fill","transparent").attr("cx",7).attr("cy",7).attr("r",6),e.append("defs").append("marker").attr("id",n+"_"+r+"-lollipopEnd").attr("class","marker lollipop "+r).attr("refX",1).attr("refY",7).attr("markerWidth",190).attr("markerHeight",240).attr("orient","auto").append("circle").attr("fill","transparent").attr("cx",7).attr("cy",7).attr("r",6)},"lollipop"),bVe=X((e,r,n)=>{e.append("marker").attr("id",n+"_"+r+"-pointEnd").attr("class","marker "+r).attr("viewBox","0 0 10 10").attr("refX",5).attr("refY",5).attr("markerUnits","userSpaceOnUse").attr("markerWidth",8).attr("markerHeight",8).attr("orient","auto").append("path").attr("d","M 0 0 L 10 5 L 0 10 z").attr("class","arrowMarkerPath").style("stroke-width",1).style("stroke-dasharray","1,0"),e.append("marker").attr("id",n+"_"+r+"-pointStart").attr("class","marker "+r).attr("viewBox","0 0 10 10").attr("refX",4.5).attr("refY",5).attr("markerUnits","userSpaceOnUse").attr("markerWidth",8).attr("markerHeight",8).attr("orient","auto").append("path").attr("d","M 0 5 L 10 10 L 10 0 z").attr("class","arrowMarkerPath").style("stroke-width",1).style("stroke-dasharray","1,0")},"point"),_Ve=X((e,r,n)=>{e.append("marker").attr("id",n+"_"+r+"-circleEnd").attr("class","marker "+r).attr("viewBox","0 0 10 10").attr("refX",11).attr("refY",5).attr("markerUnits","userSpaceOnUse").attr("markerWidth",11).attr("markerHeight",11).attr("orient","auto").append("circle").attr("cx","5").attr("cy","5").attr("r","5").attr("class","arrowMarkerPath").style("stroke-width",1).style("stroke-dasharray","1,0"),e.append("marker").attr("id",n+"_"+r+"-circleStart").attr("class","marker "+r).attr("viewBox","0 0 10 10").attr("refX",-1).attr("refY",5).attr("markerUnits","userSpaceOnUse").attr("markerWidth",11).attr("markerHeight",11).attr("orient","auto").append("circle").attr("cx","5").attr("cy","5").attr("r","5").attr("class","arrowMarkerPath").style("stroke-width",1).style("stroke-dasharray","1,0")},"circle"),wVe=X((e,r,n)=>{e.append("marker").attr("id",n+"_"+r+"-crossEnd").attr("class","marker cross "+r).attr("viewBox","0 0 11 11").attr("refX",12).attr("refY",5.2).attr("markerUnits","userSpaceOnUse").attr("markerWidth",11).attr("markerHeight",11).attr("orient","auto").append("path").attr("d","M 1,1 l 9,9 M 10,1 l -9,9").attr("class","arrowMarkerPath").style("stroke-width",2).style("stroke-dasharray","1,0"),e.append("marker").attr("id",n+"_"+r+"-crossStart").attr("class","marker cross "+r).attr("viewBox","0 0 11 11").attr("refX",-1).attr("refY",5.2).attr("markerUnits","userSpaceOnUse").attr("markerWidth",11).attr("markerHeight",11).attr("orient","auto").append("path").attr("d","M 1,1 l 9,9 M 10,1 l -9,9").attr("class","arrowMarkerPath").style("stroke-width",2).style("stroke-dasharray","1,0")},"cross"),SVe=X((e,r,n)=>{e.append("defs").append("marker").attr("id",n+"_"+r+"-barbEnd").attr("refX",19).attr("refY",7).attr("markerWidth",20).attr("markerHeight",14).attr("markerUnits","userSpaceOnUse").attr("orient","auto").append("path").attr("d","M 19,7 L9,13 L14,7 L9,1 Z")},"barb"),kVe=X((e,r,n)=>{e.append("defs").append("marker").attr("id",n+"_"+r+"-onlyOneStart").attr("class","marker onlyOne "+r).attr("refX",0).attr("refY",9).attr("markerWidth",18).attr("markerHeight",18).attr("orient","auto").append("path").attr("d","M9,0 L9,18 M15,0 L15,18"),e.append("defs").append("marker").attr("id",n+"_"+r+"-onlyOneEnd").attr("class","marker onlyOne "+r).attr("refX",18).attr("refY",9).attr("markerWidth",18).attr("markerHeight",18).attr("orient","auto").append("path").attr("d","M3,0 L3,18 M9,0 L9,18")},"only_one"),CVe=X((e,r,n)=>{const i=e.append("defs").append("marker").attr("id",n+"_"+r+"-zeroOrOneStart").attr("class","marker zeroOrOne "+r).attr("refX",0).attr("refY",9).attr("markerWidth",30).attr("markerHeight",18).attr("orient","auto");i.append("circle").attr("fill","white").attr("cx",21).attr("cy",9).attr("r",6),i.append("path").attr("d","M9,0 L9,18");const s=e.append("defs").append("marker").attr("id",n+"_"+r+"-zeroOrOneEnd").attr("class","marker zeroOrOne "+r).attr("refX",30).attr("refY",9).attr("markerWidth",30).attr("markerHeight",18).attr("orient","auto");s.append("circle").attr("fill","white").attr("cx",9).attr("cy",9).attr("r",6),s.append("path").attr("d","M21,0 L21,18")},"zero_or_one"),jVe=X((e,r,n)=>{e.append("defs").append("marker").attr("id",n+"_"+r+"-oneOrMoreStart").attr("class","marker oneOrMore "+r).attr("refX",18).attr("refY",18).attr("markerWidth",45).attr("markerHeight",36).attr("orient","auto").append("path").attr("d","M0,18 Q 18,0 36,18 Q 18,36 0,18 M42,9 L42,27"),e.append("defs").append("marker").attr("id",n+"_"+r+"-oneOrMoreEnd").attr("class","marker oneOrMore "+r).attr("refX",27).attr("refY",18).attr("markerWidth",45).attr("markerHeight",36).attr("orient","auto").append("path").attr("d","M3,9 L3,27 M9,18 Q27,0 45,18 Q27,36 9,18")},"one_or_more"),NVe=X((e,r,n)=>{const i=e.append("defs").append("marker").attr("id",n+"_"+r+"-zeroOrMoreStart").attr("class","marker zeroOrMore "+r).attr("refX",18).attr("refY",18).attr("markerWidth",57).attr("markerHeight",36).attr("orient","auto");i.append("circle").attr("fill","white").attr("cx",48).attr("cy",18).attr("r",6),i.append("path").attr("d","M0,18 Q18,0 36,18 Q18,36 0,18");const s=e.append("defs").append("marker").attr("id",n+"_"+r+"-zeroOrMoreEnd").attr("class","marker zeroOrMore "+r).attr("refX",39).attr("refY",18).attr("markerWidth",57).attr("markerHeight",36).attr("orient","auto");s.append("circle").attr("fill","white").attr("cx",9).attr("cy",18).attr("r",6),s.append("path").attr("d","M21,18 Q39,0 57,18 Q39,36 21,18")},"zero_or_more"),TVe=X((e,r,n)=>{e.append("defs").append("marker").attr("id",n+"_"+r+"-requirement_arrowEnd").attr("refX",20).attr("refY",10).attr("markerWidth",20).attr("markerHeight",20).attr("orient","auto").append("path").attr("d",`M0,0
|
|
1122
1122
|
L20,10
|
|
1123
1123
|
M20,10
|
|
1124
|
-
L0,20`)},"requirement_arrow"),EVe=X((e,r,n)=>{const i=e.append("defs").append("marker").attr("id",n+"_"+r+"-requirement_containsStart").attr("refX",0).attr("refY",10).attr("markerWidth",20).attr("markerHeight",20).attr("orient","auto").append("g");i.append("circle").attr("cx",10).attr("cy",10).attr("r",9).attr("fill","none"),i.append("line").attr("x1",1).attr("x2",19).attr("y1",10).attr("y2",10),i.append("line").attr("y1",1).attr("y2",19).attr("x1",10).attr("x2",10)},"requirement_contains"),AVe={extension:mVe,composition:gVe,aggregation:yVe,dependency:vVe,lollipop:xVe,point:bVe,circle:_Ve,cross:wVe,barb:SVe,only_one:kVe,zero_or_one:CVe,one_or_more:jVe,zero_or_more:NVe,requirement_arrow:TVe,requirement_contains:EVe},OVe=pVe,RVe={common:kS,getConfig:Ma,insertCluster:IUe,insertEdge:fVe,insertEdgeLabel:aVe,insertMarkers:OVe,insertNode:vse,interpolateToCurve:NM,labelHelper:qr,log:St,positionEdgeLabel:lVe},V2={},wse=X(e=>{for(const r of e)V2[r.name]=r},"registerLayoutLoaders"),MVe=X(()=>{wse([{name:"dagre",loader:X(async()=>await Ke(()=>import("./dagre-KLK3FWXG-
|
|
1125
|
-
`);const i=tBe(r),s=i.append("g");i.attr("viewBox","0 0 2412 512"),pee(i,100,512,!0),s.append("path").attr("class","error-icon").attr("d","m411.313,123.313c6.25-6.25 6.25-16.375 0-22.625s-16.375-6.25-22.625,0l-32,32-9.375,9.375-20.688-20.688c-12.484-12.5-32.766-12.5-45.25,0l-16,16c-1.261,1.261-2.304,2.648-3.31,4.051-21.739-8.561-45.324-13.426-70.065-13.426-105.867,0-192,86.133-192,192s86.133,192 192,192 192-86.133 192-192c0-24.741-4.864-48.327-13.426-70.065 1.402-1.007 2.79-2.049 4.051-3.31l16-16c12.5-12.492 12.5-32.758 0-45.25l-20.688-20.688 9.375-9.375 32.001-31.999zm-219.313,100.687c-52.938,0-96,43.063-96,96 0,8.836-7.164,16-16,16s-16-7.164-16-16c0-70.578 57.422-128 128-128 8.836,0 16,7.164 16,16s-7.164,16-16,16z"),s.append("path").attr("class","error-icon").attr("d","m459.02,148.98c-6.25-6.25-16.375-6.25-22.625,0s-6.25,16.375 0,22.625l16,16c3.125,3.125 7.219,4.688 11.313,4.688 4.094,0 8.188-1.563 11.313-4.688 6.25-6.25 6.25-16.375 0-22.625l-16.001-16z"),s.append("path").attr("class","error-icon").attr("d","m340.395,75.605c3.125,3.125 7.219,4.688 11.313,4.688 4.094,0 8.188-1.563 11.313-4.688 6.25-6.25 6.25-16.375 0-22.625l-16-16c-6.25-6.25-16.375-6.25-22.625,0s-6.25,16.375 0,22.625l15.999,16z"),s.append("path").attr("class","error-icon").attr("d","m400,64c8.844,0 16-7.164 16-16v-32c0-8.836-7.156-16-16-16-8.844,0-16,7.164-16,16v32c0,8.836 7.156,16 16,16z"),s.append("path").attr("class","error-icon").attr("d","m496,96.586h-32c-8.844,0-16,7.164-16,16 0,8.836 7.156,16 16,16h32c8.844,0 16-7.164 16-16 0-8.836-7.156-16-16-16z"),s.append("path").attr("class","error-icon").attr("d","m436.98,75.605c3.125,3.125 7.219,4.688 11.313,4.688 4.094,0 8.188-1.563 11.313-4.688l32-32c6.25-6.25 6.25-16.375 0-22.625s-16.375-6.25-22.625,0l-32,32c-6.251,6.25-6.251,16.375-0.001,22.625z"),s.append("text").attr("class","error-text").attr("x",1440).attr("y",250).attr("font-size","150px").style("text-anchor","middle").text("Syntax error in text"),s.append("text").attr("class","error-text").attr("x",1250).attr("y",400).attr("font-size","100px").style("text-anchor","middle").text(`mermaid version ${n}`)},"draw"),zse={draw:oGe},aGe=zse,lGe={db:{},renderer:zse,parser:{parse:X(()=>{},"parse")}},cGe=lGe,Fse="flowchart-elk",uGe=X((e,r={})=>{var n;return/^\s*flowchart-elk/.test(e)||/^\s*(flowchart|graph)/.test(e)&&((n=r==null?void 0:r.flowchart)==null?void 0:n.defaultRenderer)==="elk"?(r.layout="elk",!0):!1},"detector"),dGe=X(async()=>{const{diagram:e}=await Ke(async()=>{const{diagram:r}=await import("./flowDiagram-PKNHOUZH-
|
|
1124
|
+
L0,20`)},"requirement_arrow"),EVe=X((e,r,n)=>{const i=e.append("defs").append("marker").attr("id",n+"_"+r+"-requirement_containsStart").attr("refX",0).attr("refY",10).attr("markerWidth",20).attr("markerHeight",20).attr("orient","auto").append("g");i.append("circle").attr("cx",10).attr("cy",10).attr("r",9).attr("fill","none"),i.append("line").attr("x1",1).attr("x2",19).attr("y1",10).attr("y2",10),i.append("line").attr("y1",1).attr("y2",19).attr("x1",10).attr("x2",10)},"requirement_contains"),AVe={extension:mVe,composition:gVe,aggregation:yVe,dependency:vVe,lollipop:xVe,point:bVe,circle:_Ve,cross:wVe,barb:SVe,only_one:kVe,zero_or_one:CVe,one_or_more:jVe,zero_or_more:NVe,requirement_arrow:TVe,requirement_contains:EVe},OVe=pVe,RVe={common:kS,getConfig:Ma,insertCluster:IUe,insertEdge:fVe,insertEdgeLabel:aVe,insertMarkers:OVe,insertNode:vse,interpolateToCurve:NM,labelHelper:qr,log:St,positionEdgeLabel:lVe},V2={},wse=X(e=>{for(const r of e)V2[r.name]=r},"registerLayoutLoaders"),MVe=X(()=>{wse([{name:"dagre",loader:X(async()=>await Ke(()=>import("./dagre-KLK3FWXG-7WdfgINc.js"),__vite__mapDeps([47,48,49,50,51,52]),import.meta.url),"loader")},{name:"cose-bilkent",loader:X(async()=>await Ke(()=>import("./cose-bilkent-S5V4N54A-BFqo2c_p.js"),__vite__mapDeps([53,54]),import.meta.url),"loader")}])},"registerDefaultLayoutLoaders");MVe();var uvt=X(async(e,r)=>{if(!(e.layoutAlgorithm in V2))throw new Error(`Unknown layout algorithm: ${e.layoutAlgorithm}`);const n=V2[e.layoutAlgorithm];return(await n.loader()).render(e,r,RVe,{algorithm:n.algorithm})},"render"),dvt=X((e="",{fallback:r="dagre"}={})=>{if(e in V2)return e;if(r in V2)return St.warn(`Layout algorithm ${e} is not registered. Using ${r} as fallback.`),r;throw new Error(`Both layout algorithms ${e} and ${r} are not registered.`)},"getRegisteredLayoutAlgorithm"),PVe=Jre(Object.keys,Object),LVe=Object.prototype,$Ve=LVe.hasOwnProperty;function DVe(e){if(!qj(e))return PVe(e);var r=[];for(var n in Object(e))$Ve.call(e,n)&&n!="constructor"&&r.push(n);return r}var fO=J0(Ad,"DataView"),pO=J0(Ad,"Promise"),mO=J0(Ad,"Set"),gO=J0(Ad,"WeakMap"),EF="[object Map]",IVe="[object Object]",AF="[object Promise]",OF="[object Set]",RF="[object WeakMap]",MF="[object DataView]",BVe=Z0(fO),zVe=Z0(W2),FVe=Z0(pO),HVe=Z0(mO),WVe=Z0(gO),Yg=X0;(fO&&Yg(new fO(new ArrayBuffer(1)))!=MF||W2&&Yg(new W2)!=EF||pO&&Yg(pO.resolve())!=AF||mO&&Yg(new mO)!=OF||gO&&Yg(new gO)!=RF)&&(Yg=function(e){var r=X0(e),n=r==IVe?e.constructor:void 0,i=n?Z0(n):"";if(i)switch(i){case BVe:return MF;case zVe:return EF;case FVe:return AF;case HVe:return OF;case WVe:return RF}return r});var UVe="[object Map]",VVe="[object Set]",qVe=Object.prototype,GVe=qVe.hasOwnProperty;function PF(e){if(e==null)return!0;if(Gj(e)&&(H5(e)||typeof e=="string"||typeof e.splice=="function"||CM(e)||jM(e)||F5(e)))return!e.length;var r=Yg(e);if(r==UVe||r==VVe)return!e.size;if(qj(e))return!DVe(e).length;for(var n in e)if(GVe.call(e,n))return!1;return!0}var Sse="c4",KVe=X(e=>/^\s*C4Context|C4Container|C4Component|C4Dynamic|C4Deployment/.test(e),"detector"),YVe=X(async()=>{const{diagram:e}=await Ke(async()=>{const{diagram:r}=await import("./c4Diagram-IC4MRINW-Lt0KRsHd.js");return{diagram:r}},__vite__mapDeps([55,56]),import.meta.url);return{id:Sse,diagram:e}},"loader"),XVe={id:Sse,detector:KVe,loader:YVe},ZVe=XVe,kse="flowchart",JVe=X((e,r)=>{var n,i;return((n=r==null?void 0:r.flowchart)==null?void 0:n.defaultRenderer)==="dagre-wrapper"||((i=r==null?void 0:r.flowchart)==null?void 0:i.defaultRenderer)==="elk"?!1:/^\s*graph/.test(e)},"detector"),QVe=X(async()=>{const{diagram:e}=await Ke(async()=>{const{diagram:r}=await import("./flowDiagram-PKNHOUZH-B4pKU7sd.js");return{diagram:r}},__vite__mapDeps([57,58,56,59,60,61]),import.meta.url);return{id:kse,diagram:e}},"loader"),eqe={id:kse,detector:JVe,loader:QVe},tqe=eqe,Cse="flowchart-v2",rqe=X((e,r)=>{var n,i,s;return((n=r==null?void 0:r.flowchart)==null?void 0:n.defaultRenderer)==="dagre-d3"?!1:(((i=r==null?void 0:r.flowchart)==null?void 0:i.defaultRenderer)==="elk"&&(r.layout="elk"),/^\s*graph/.test(e)&&((s=r==null?void 0:r.flowchart)==null?void 0:s.defaultRenderer)==="dagre-wrapper"?!0:/^\s*flowchart/.test(e))},"detector"),nqe=X(async()=>{const{diagram:e}=await Ke(async()=>{const{diagram:r}=await import("./flowDiagram-PKNHOUZH-B4pKU7sd.js");return{diagram:r}},__vite__mapDeps([57,58,56,59,60,61]),import.meta.url);return{id:Cse,diagram:e}},"loader"),iqe={id:Cse,detector:rqe,loader:nqe},sqe=iqe,jse="er",oqe=X(e=>/^\s*erDiagram/.test(e),"detector"),aqe=X(async()=>{const{diagram:e}=await Ke(async()=>{const{diagram:r}=await import("./erDiagram-INFDFZHY-BWQk9Tsq.js");return{diagram:r}},__vite__mapDeps([62,59,60,61]),import.meta.url);return{id:jse,diagram:e}},"loader"),lqe={id:jse,detector:oqe,loader:aqe},cqe=lqe,Nse="gitGraph",uqe=X(e=>/^\s*gitGraph/.test(e),"detector"),dqe=X(async()=>{const{diagram:e}=await Ke(async()=>{const{diagram:r}=await import("./gitGraphDiagram-K3NZZRJ6-BMR8lvIa.js");return{diagram:r}},__vite__mapDeps([63,64,65,66,49,51,52]),import.meta.url);return{id:Nse,diagram:e}},"loader"),hqe={id:Nse,detector:uqe,loader:dqe},fqe=hqe,Tse="gantt",pqe=X(e=>/^\s*gantt/.test(e),"detector"),mqe=X(async()=>{const{diagram:e}=await Ke(async()=>{const{diagram:r}=await import("./ganttDiagram-A5KZAMGK-Bhfq6RFf.js");return{diagram:r}},__vite__mapDeps([67,68,69]),import.meta.url);return{id:Tse,diagram:e}},"loader"),gqe={id:Tse,detector:pqe,loader:mqe},yqe=gqe,Ese="info",vqe=X(e=>/^\s*info/.test(e),"detector"),xqe=X(async()=>{const{diagram:e}=await Ke(async()=>{const{diagram:r}=await import("./infoDiagram-LFFYTUFH-DrcBifIP.js");return{diagram:r}},__vite__mapDeps([70,66,49,51,52]),import.meta.url);return{id:Ese,diagram:e}},"loader"),bqe={id:Ese,detector:vqe,loader:xqe},Ase="pie",_qe=X(e=>/^\s*pie/.test(e),"detector"),wqe=X(async()=>{const{diagram:e}=await Ke(async()=>{const{diagram:r}=await import("./pieDiagram-SKSYHLDU-B1IN3_f2.js");return{diagram:r}},__vite__mapDeps([71,64,66,49,51,52,72]),import.meta.url);return{id:Ase,diagram:e}},"loader"),Sqe={id:Ase,detector:_qe,loader:wqe},Ose="quadrantChart",kqe=X(e=>/^\s*quadrantChart/.test(e),"detector"),Cqe=X(async()=>{const{diagram:e}=await Ke(async()=>{const{diagram:r}=await import("./quadrantDiagram-337W2JSQ-Gm2nfs3x.js");return{diagram:r}},__vite__mapDeps([73,68,69]),import.meta.url);return{id:Ose,diagram:e}},"loader"),jqe={id:Ose,detector:kqe,loader:Cqe},Nqe=jqe,Rse="xychart",Tqe=X(e=>/^\s*xychart(-beta)?/.test(e),"detector"),Eqe=X(async()=>{const{diagram:e}=await Ke(async()=>{const{diagram:r}=await import("./xychartDiagram-JWTSCODW-DnW1f2io.js");return{diagram:r}},__vite__mapDeps([74,68,69]),import.meta.url);return{id:Rse,diagram:e}},"loader"),Aqe={id:Rse,detector:Tqe,loader:Eqe},Oqe=Aqe,Mse="requirement",Rqe=X(e=>/^\s*requirement(Diagram)?/.test(e),"detector"),Mqe=X(async()=>{const{diagram:e}=await Ke(async()=>{const{diagram:r}=await import("./requirementDiagram-Z7DCOOCP-Bi_1ThwE.js");return{diagram:r}},__vite__mapDeps([75,59,60]),import.meta.url);return{id:Mse,diagram:e}},"loader"),Pqe={id:Mse,detector:Rqe,loader:Mqe},Lqe=Pqe,Pse="sequence",$qe=X(e=>/^\s*sequenceDiagram/.test(e),"detector"),Dqe=X(async()=>{const{diagram:e}=await Ke(async()=>{const{diagram:r}=await import("./sequenceDiagram-2WXFIKYE-DAvtPEnh.js");return{diagram:r}},__vite__mapDeps([76,56,65]),import.meta.url);return{id:Pse,diagram:e}},"loader"),Iqe={id:Pse,detector:$qe,loader:Dqe},Bqe=Iqe,Lse="class",zqe=X((e,r)=>{var n;return((n=r==null?void 0:r.class)==null?void 0:n.defaultRenderer)==="dagre-wrapper"?!1:/^\s*classDiagram/.test(e)},"detector"),Fqe=X(async()=>{const{diagram:e}=await Ke(async()=>{const{diagram:r}=await import("./classDiagram-VBA2DB6C-CT2UTCXP.js");return{diagram:r}},__vite__mapDeps([77,78,58,56,59,60]),import.meta.url);return{id:Lse,diagram:e}},"loader"),Hqe={id:Lse,detector:zqe,loader:Fqe},Wqe=Hqe,$se="classDiagram",Uqe=X((e,r)=>{var n;return/^\s*classDiagram/.test(e)&&((n=r==null?void 0:r.class)==null?void 0:n.defaultRenderer)==="dagre-wrapper"?!0:/^\s*classDiagram-v2/.test(e)},"detector"),Vqe=X(async()=>{const{diagram:e}=await Ke(async()=>{const{diagram:r}=await import("./classDiagram-v2-RAHNMMFH-CT2UTCXP.js");return{diagram:r}},__vite__mapDeps([79,78,58,56,59,60]),import.meta.url);return{id:$se,diagram:e}},"loader"),qqe={id:$se,detector:Uqe,loader:Vqe},Gqe=qqe,Dse="state",Kqe=X((e,r)=>{var n;return((n=r==null?void 0:r.state)==null?void 0:n.defaultRenderer)==="dagre-wrapper"?!1:/^\s*stateDiagram/.test(e)},"detector"),Yqe=X(async()=>{const{diagram:e}=await Ke(async()=>{const{diagram:r}=await import("./stateDiagram-RAJIS63D-D2tt0Z7v.js");return{diagram:r}},__vite__mapDeps([80,81,59,60,48,49,50,51]),import.meta.url);return{id:Dse,diagram:e}},"loader"),Xqe={id:Dse,detector:Kqe,loader:Yqe},Zqe=Xqe,Ise="stateDiagram",Jqe=X((e,r)=>{var n;return!!(/^\s*stateDiagram-v2/.test(e)||/^\s*stateDiagram/.test(e)&&((n=r==null?void 0:r.state)==null?void 0:n.defaultRenderer)==="dagre-wrapper")},"detector"),Qqe=X(async()=>{const{diagram:e}=await Ke(async()=>{const{diagram:r}=await import("./stateDiagram-v2-FVOUBMTO-C8N71UT0.js");return{diagram:r}},__vite__mapDeps([82,81,59,60]),import.meta.url);return{id:Ise,diagram:e}},"loader"),eGe={id:Ise,detector:Jqe,loader:Qqe},tGe=eGe,Bse="journey",rGe=X(e=>/^\s*journey/.test(e),"detector"),nGe=X(async()=>{const{diagram:e}=await Ke(async()=>{const{diagram:r}=await import("./journeyDiagram-4ABVD52K-JVV9TD7u.js");return{diagram:r}},__vite__mapDeps([83,58,56,72]),import.meta.url);return{id:Bse,diagram:e}},"loader"),iGe={id:Bse,detector:rGe,loader:nGe},sGe=iGe,oGe=X((e,r,n)=>{St.debug(`rendering svg for syntax error
|
|
1125
|
+
`);const i=tBe(r),s=i.append("g");i.attr("viewBox","0 0 2412 512"),pee(i,100,512,!0),s.append("path").attr("class","error-icon").attr("d","m411.313,123.313c6.25-6.25 6.25-16.375 0-22.625s-16.375-6.25-22.625,0l-32,32-9.375,9.375-20.688-20.688c-12.484-12.5-32.766-12.5-45.25,0l-16,16c-1.261,1.261-2.304,2.648-3.31,4.051-21.739-8.561-45.324-13.426-70.065-13.426-105.867,0-192,86.133-192,192s86.133,192 192,192 192-86.133 192-192c0-24.741-4.864-48.327-13.426-70.065 1.402-1.007 2.79-2.049 4.051-3.31l16-16c12.5-12.492 12.5-32.758 0-45.25l-20.688-20.688 9.375-9.375 32.001-31.999zm-219.313,100.687c-52.938,0-96,43.063-96,96 0,8.836-7.164,16-16,16s-16-7.164-16-16c0-70.578 57.422-128 128-128 8.836,0 16,7.164 16,16s-7.164,16-16,16z"),s.append("path").attr("class","error-icon").attr("d","m459.02,148.98c-6.25-6.25-16.375-6.25-22.625,0s-6.25,16.375 0,22.625l16,16c3.125,3.125 7.219,4.688 11.313,4.688 4.094,0 8.188-1.563 11.313-4.688 6.25-6.25 6.25-16.375 0-22.625l-16.001-16z"),s.append("path").attr("class","error-icon").attr("d","m340.395,75.605c3.125,3.125 7.219,4.688 11.313,4.688 4.094,0 8.188-1.563 11.313-4.688 6.25-6.25 6.25-16.375 0-22.625l-16-16c-6.25-6.25-16.375-6.25-22.625,0s-6.25,16.375 0,22.625l15.999,16z"),s.append("path").attr("class","error-icon").attr("d","m400,64c8.844,0 16-7.164 16-16v-32c0-8.836-7.156-16-16-16-8.844,0-16,7.164-16,16v32c0,8.836 7.156,16 16,16z"),s.append("path").attr("class","error-icon").attr("d","m496,96.586h-32c-8.844,0-16,7.164-16,16 0,8.836 7.156,16 16,16h32c8.844,0 16-7.164 16-16 0-8.836-7.156-16-16-16z"),s.append("path").attr("class","error-icon").attr("d","m436.98,75.605c3.125,3.125 7.219,4.688 11.313,4.688 4.094,0 8.188-1.563 11.313-4.688l32-32c6.25-6.25 6.25-16.375 0-22.625s-16.375-6.25-22.625,0l-32,32c-6.251,6.25-6.251,16.375-0.001,22.625z"),s.append("text").attr("class","error-text").attr("x",1440).attr("y",250).attr("font-size","150px").style("text-anchor","middle").text("Syntax error in text"),s.append("text").attr("class","error-text").attr("x",1250).attr("y",400).attr("font-size","100px").style("text-anchor","middle").text(`mermaid version ${n}`)},"draw"),zse={draw:oGe},aGe=zse,lGe={db:{},renderer:zse,parser:{parse:X(()=>{},"parse")}},cGe=lGe,Fse="flowchart-elk",uGe=X((e,r={})=>{var n;return/^\s*flowchart-elk/.test(e)||/^\s*(flowchart|graph)/.test(e)&&((n=r==null?void 0:r.flowchart)==null?void 0:n.defaultRenderer)==="elk"?(r.layout="elk",!0):!1},"detector"),dGe=X(async()=>{const{diagram:e}=await Ke(async()=>{const{diagram:r}=await import("./flowDiagram-PKNHOUZH-B4pKU7sd.js");return{diagram:r}},__vite__mapDeps([57,58,56,59,60,61]),import.meta.url);return{id:Fse,diagram:e}},"loader"),hGe={id:Fse,detector:uGe,loader:dGe},fGe=hGe,Hse="timeline",pGe=X(e=>/^\s*timeline/.test(e),"detector"),mGe=X(async()=>{const{diagram:e}=await Ke(async()=>{const{diagram:r}=await import("./timeline-definition-YZTLITO2-Bdg4h4NS.js");return{diagram:r}},__vite__mapDeps([84,72]),import.meta.url);return{id:Hse,diagram:e}},"loader"),gGe={id:Hse,detector:pGe,loader:mGe},yGe=gGe,Wse="mindmap",vGe=X(e=>/^\s*mindmap/.test(e),"detector"),xGe=X(async()=>{const{diagram:e}=await Ke(async()=>{const{diagram:r}=await import("./mindmap-definition-YRQLILUH-D2_cqLtF.js");return{diagram:r}},__vite__mapDeps([85,59,60]),import.meta.url);return{id:Wse,diagram:e}},"loader"),bGe={id:Wse,detector:vGe,loader:xGe},_Ge=bGe,Use="kanban",wGe=X(e=>/^\s*kanban/.test(e),"detector"),SGe=X(async()=>{const{diagram:e}=await Ke(async()=>{const{diagram:r}=await import("./kanban-definition-K7BYSVSG-D7DnNg8n.js");return{diagram:r}},__vite__mapDeps([86,58]),import.meta.url);return{id:Use,diagram:e}},"loader"),kGe={id:Use,detector:wGe,loader:SGe},CGe=kGe,Vse="sankey",jGe=X(e=>/^\s*sankey(-beta)?/.test(e),"detector"),NGe=X(async()=>{const{diagram:e}=await Ke(async()=>{const{diagram:r}=await import("./sankeyDiagram-WA2Y5GQK-DSoZooYN.js");return{diagram:r}},[],import.meta.url);return{id:Vse,diagram:e}},"loader"),TGe={id:Vse,detector:jGe,loader:NGe},EGe=TGe,qse="packet",AGe=X(e=>/^\s*packet(-beta)?/.test(e),"detector"),OGe=X(async()=>{const{diagram:e}=await Ke(async()=>{const{diagram:r}=await import("./diagram-P4PSJMXO-B_gM15l_.js");return{diagram:r}},__vite__mapDeps([87,64,66,49,51,52]),import.meta.url);return{id:qse,diagram:e}},"loader"),RGe={id:qse,detector:AGe,loader:OGe},Gse="radar",MGe=X(e=>/^\s*radar-beta/.test(e),"detector"),PGe=X(async()=>{const{diagram:e}=await Ke(async()=>{const{diagram:r}=await import("./diagram-IFDJBPK2-_L618fQZ.js");return{diagram:r}},__vite__mapDeps([88,64,66,49,51,52]),import.meta.url);return{id:Gse,diagram:e}},"loader"),LGe={id:Gse,detector:MGe,loader:PGe},Kse="block",$Ge=X(e=>/^\s*block(-beta)?/.test(e),"detector"),DGe=X(async()=>{const{diagram:e}=await Ke(async()=>{const{diagram:r}=await import("./blockDiagram-WCTKOSBZ-CjBsnr-_.js");return{diagram:r}},__vite__mapDeps([89,58,52,49,48,61]),import.meta.url);return{id:Kse,diagram:e}},"loader"),IGe={id:Kse,detector:$Ge,loader:DGe},BGe=IGe,Yse="architecture",zGe=X(e=>/^\s*architecture/.test(e),"detector"),FGe=X(async()=>{const{diagram:e}=await Ke(async()=>{const{diagram:r}=await import("./architectureDiagram-2XIMDMQ5-BIDXNoiY.js");return{diagram:r}},__vite__mapDeps([90,64,66,49,51,52,54]),import.meta.url);return{id:Yse,diagram:e}},"loader"),HGe={id:Yse,detector:zGe,loader:FGe},WGe=HGe,Xse="ishikawa",UGe=X(e=>/^\s*ishikawa(-beta)?\b/i.test(e),"detector"),VGe=X(async()=>{const{diagram:e}=await Ke(async()=>{const{diagram:r}=await import("./ishikawaDiagram-PHBUUO56-BFeaIwGD.js");return{diagram:r}},[],import.meta.url);return{id:Xse,diagram:e}},"loader"),qGe={id:Xse,detector:UGe,loader:VGe},Zse="venn",GGe=X(e=>/^\s*venn-beta/.test(e),"detector"),KGe=X(async()=>{const{diagram:e}=await Ke(async()=>{const{diagram:r}=await import("./vennDiagram-LZ73GAT5-Vv1-4U-6.js");return{diagram:r}},[],import.meta.url);return{id:Zse,diagram:e}},"loader"),YGe={id:Zse,detector:GGe,loader:KGe},XGe=YGe,Jse="treemap",ZGe=X(e=>/^\s*treemap/.test(e),"detector"),JGe=X(async()=>{const{diagram:e}=await Ke(async()=>{const{diagram:r}=await import("./diagram-E7M64L7V-CQaCvBl-.js");return{diagram:r}},__vite__mapDeps([91,60,64,66,49,51,52,69]),import.meta.url);return{id:Jse,diagram:e}},"loader"),QGe={id:Jse,detector:ZGe,loader:JGe},LF=!1,t6=X(()=>{LF||(LF=!0,S5("error",cGe,e=>e.toLowerCase().trim()==="error"),S5("---",{db:{clear:X(()=>{},"clear")},styles:{},renderer:{draw:X(()=>{},"draw")},parser:{parse:X(()=>{throw new Error("Diagrams beginning with --- are not valid. If you were trying to use a YAML front-matter, please ensure that you've correctly opened and closed the YAML front-matter with un-indented `---` blocks")},"parse")},init:X(()=>null,"init")},e=>e.toLowerCase().trimStart().startsWith("---")),SA(fGe,_Ge,WGe),SA(ZVe,CGe,Gqe,Wqe,cqe,yqe,bqe,Sqe,Lqe,Bqe,sqe,tqe,yGe,fqe,tGe,Zqe,sGe,Nqe,EGe,RGe,Oqe,BGe,LGe,qGe,QGe,XGe))},"addDiagrams"),eKe=X(async()=>{St.debug("Loading registered diagrams");const r=(await Promise.allSettled(Object.entries(j0).map(async([n,{detector:i,loader:s}])=>{if(s)try{NA(n)}catch{try{const{diagram:o,id:a}=await s();S5(a,o,i)}catch(o){throw St.error(`Failed to load external diagram with key ${n}. Removing from detectors.`),delete j0[n],o}}}))).filter(n=>n.status==="rejected");if(r.length>0){St.error(`Failed to load ${r.length} external diagrams`);for(const n of r)St.error(n);throw new Error(`Failed to load ${r.length} external diagrams`)}},"loadRegisteredDiagrams"),tKe="graphics-document document";function Qse(e,r){e.attr("role",tKe),r!==""&&e.attr("aria-roledescription",r)}X(Qse,"setA11yDiagramInfo");function eoe(e,r,n,i){if(e.insert!==void 0){if(n){const s=`chart-desc-${i}`;e.attr("aria-describedby",s),e.insert("desc",":first-child").attr("id",s).text(n)}if(r){const s=`chart-title-${i}`;e.attr("aria-labelledby",s),e.insert("title",":first-child").attr("id",s).text(r)}}}X(eoe,"addSVGa11yTitleDescription");var y0,yO=(y0=class{constructor(r,n,i,s,o){this.type=r,this.text=n,this.db=i,this.parser=s,this.renderer=o}static async fromText(r,n={}){var u,f;const i=Ma(),s=K9(r,i);r=iWe(r)+`
|
|
1126
1126
|
`;try{NA(s)}catch{const p=qMe(s);if(!p)throw new eee(`Diagram ${s} not found.`);const{id:g,diagram:v}=await p();S5(g,v)}const{db:o,parser:a,renderer:l,init:d}=NA(s);return a.parser&&(a.parser.yy=o),(u=o.clear)==null||u.call(o),d==null||d(i),n.title&&((f=o.setDiagramTitle)==null||f.call(o,n.title)),await a.parse(r),new y0(s,r,o,a,l)}async render(r,n){await this.renderer.draw(this.text,r,n,this)}getParser(){return this.parser}getType(){return this.type}},X(y0,"Diagram"),y0),$F=[],rKe=X(()=>{$F.forEach(e=>{e()}),$F=[]},"attachFunctions"),nKe=X(e=>e.replace(/^\s*%%(?!{)[^\n]+\n?/gm,"").trimStart(),"cleanupComments");function toe(e){const r=e.match(QQ);if(!r)return{text:e,metadata:{}};let n=lze(r[1],{schema:aze})??{};n=typeof n=="object"&&!Array.isArray(n)?n:{};const i={};return n.displayMode&&(i.displayMode=n.displayMode.toString()),n.title&&(i.title=n.title.toString()),n.config&&(i.config=n.config),{text:e.slice(r[0].length),metadata:i}}X(toe,"extractFrontMatter");var iKe=X(e=>e.replace(/\r\n?/g,`
|
|
1127
1127
|
`).replace(/<(\w+)([^>]*)>/g,(r,n,i)=>"<"+n+i.replace(/="([^"]*)"/g,"='$1'")+">"),"cleanupText"),sKe=X(e=>{const{text:r,metadata:n}=toe(e),{displayMode:i,title:s,config:o={}}=n;return i&&(o.gantt||(o.gantt={}),o.gantt.displayMode=i),{title:s,config:o,text:r}},"processFrontmatter"),oKe=X(e=>{const r=ld.detectInit(e)??{},n=ld.detectDirective(e,"wrap");return Array.isArray(n)?r.wrap=n.some(({type:i})=>i==="wrap"):(n==null?void 0:n.type)==="wrap"&&(r.wrap=!0),{text:VHe(e),directive:r}},"processDirectives");function KM(e){const r=iKe(e),n=sKe(r),i=oKe(n.text),s=RM(n.config,i.directive);return e=nKe(i.text),{code:e,title:n.title,config:s}}X(KM,"preprocessDiagram");function roe(e){const r=new TextEncoder().encode(e),n=Array.from(r,i=>String.fromCodePoint(i)).join("");return btoa(n)}X(roe,"toBase64");var aKe=5e4,lKe="graph TB;a[Maximum text size in diagram exceeded];style a fill:#faa",cKe="sandbox",uKe="loose",dKe="http://www.w3.org/2000/svg",hKe="http://www.w3.org/1999/xlink",fKe="http://www.w3.org/1999/xhtml",pKe="100%",mKe="100%",gKe="border:0;margin:0;",yKe="margin:0",vKe="allow-top-navigation-by-user-activation allow-popups",xKe='The "iframe" tag is not supported by your browser.',bKe=["foreignobject"],_Ke=["dominant-baseline"];function YM(e){const r=KM(e);return _5(),lPe(r.config??{}),r}X(YM,"processAndSetConfigs");async function noe(e,r){t6();try{const{code:n,config:i}=YM(e);return{diagramType:(await soe(n)).type,config:i}}catch(n){if(r!=null&&r.suppressErrors)return!1;throw n}}X(noe,"parse");var DF=X((e,r,n=[])=>`
|
|
1128
1128
|
.${e} ${r} { ${n.join(" !important; ")} !important; }`,"cssImportantStyles"),wKe=X((e,r=new Map)=>{let n="";if(e.themeCSS!==void 0&&(n+=`
|
|
@@ -1140,7 +1140,7 @@ ${e.themeCSS}`),e.fontFamily!==void 0&&(n+=`
|
|
|
1140
1140
|
.diff-hunk-accepted { opacity: 0.55; }
|
|
1141
1141
|
.diff-hunk-rejected { opacity: 0.3; text-decoration: line-through; }
|
|
1142
1142
|
.diff-hunk-active { outline: 1px solid rgba(99, 102, 241, 0.5); outline-offset: -1px; }
|
|
1143
|
-
`})]})}const oYe="/noVNC/vnc_lite.html";function n4(e){const r=e==null?void 0:e.trim();return r||null}function UF(e){return e==null||Number.isNaN(e)?null:Math.min(9,Math.max(0,Math.trunc(e)))}function aYe(e){const r=n4(e);return!!(r&&/^wss?:\/\//i.test(r))}function lYe(e){const r=n4(e);return!!(r&&/\/(?:noVNC\/)?vnc(?:_lite)?\.html(?:[?#].*)?$/i.test(r))}function cYe(e){return/(?:^|\/)vnc_lite\.html(?:[?#].*)?$/i.test(e)}function uYe(e){const r=n4(e.viewerUrl)??oYe,n=n4(e.websocketUrl);if(!n)return r;const
|
|
1143
|
+
`})]})}const oYe="/noVNC/vnc_lite.html";function n4(e){const r=e==null?void 0:e.trim();return r||null}function UF(e){return e==null||Number.isNaN(e)?null:Math.min(9,Math.max(0,Math.trunc(e)))}function aYe(e){const r=n4(e);return!!(r&&/^wss?:\/\//i.test(r))}function lYe(e){const r=n4(e);return!!(r&&/\/(?:noVNC\/)?vnc(?:_lite)?\.html(?:[?#].*)?$/i.test(r))}function cYe(e){return/(?:^|\/)vnc_lite\.html(?:[?#].*)?$/i.test(e)}function uYe(e){const r=n4(e.viewerUrl)??oYe,n=n4(e.websocketUrl);if(!n)return r;const[i=r,s=""]=r.split("#"),o=cYe(i),a=i.indexOf("?"),l=a>=0?i.slice(0,a):i,d=a>=0?i.slice(a+1):"",u=new URLSearchParams(o?d:s);u.set("autoconnect","true"),u.set("path",n),e.viewOnly!=null&&u.set("view_only",e.viewOnly?"1":"0"),e.shared!=null&&u.set("shared",e.shared?"1":"0"),e.reconnect!=null&&u.set("reconnect",e.reconnect?"1":"0"),e.reconnectDelayMs!=null&&u.set("reconnect_delay",String(Math.max(0,Math.trunc(e.reconnectDelayMs)))),e.resize&&u.set("resize",e.resize),e.scaleViewport!=null&&u.set("scale",e.scaleViewport?"1":"0");const f=UF(e.quality);f!=null&&u.set("quality",String(f));const p=UF(e.compression);return p!=null&&u.set("compression",String(p)),e.bell!=null&&u.set("bell",e.bell?"1":"0"),o?`${l}?${u.toString()}`:`${i}#${u.toString()}`}function dYe(e,r={}){const n=e==null?void 0:e.trim();return n?aYe(n)?VF(uYe({...r,websocketUrl:n})):lYe(n)?hYe(VF(n),r):n:null}function VF(e){return e.startsWith("/")?`${$n()}${e}`:e}function hYe(e,r){if(/vnc_lite\.html/i.test(e)){const o=e.includes("?")?"&":"?";return/[?&]scale=/i.test(e)?e:`${e}${o}scale=true`}const[n=e,i=""]=e.split("#"),s=new URLSearchParams(i);return s.has("autoconnect")||s.set("autoconnect","true"),s.has("resize")||s.set("resize",r.resize??"scale"),s.has("scale")||s.set("scale",r.scaleViewport!=null?r.scaleViewport?"1":"0":"1"),s.has("show_dot")||s.set("show_dot","true"),s.has("bell")||s.set("bell","0"),`${n}#${s.toString()}`}function fYe({source:e,viewerUrl:r,websocketUrl:n,viewOnly:i,shared:s,reconnect:o,reconnectDelayMs:a,resize:l,scaleViewport:d,quality:u,compression:f,bell:p,title:g="Remote session",className:v="h-full w-full bg-white",overlay:b,onLoad:_}){const k=dYe(e,{viewerUrl:r,websocketUrl:n,viewOnly:i,shared:s,reconnect:o,reconnectDelayMs:a,resize:l,scaleViewport:d,quality:u,compression:f,bell:p});return k?c.jsx(pYe,{overlay:b,children:c.jsx("iframe",{src:k,title:g,className:v,sandbox:"allow-forms allow-modals allow-pointer-lock allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads",onLoad:_},k)}):c.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center text-sm text-muted-foreground",children:"No remote session source available."})}const qF=.25,GF=5;function pYe({children:e,overlay:r,controls:n}){const[i,s]=y.useState(1),[o,a]=y.useState({x:0,y:0}),[l,d]=y.useState(!1),[u,f]=y.useState(!1),[p,g]=y.useState(!0),v=y.useRef({x:0,y:0}),b=y.useRef(null),_=y.useRef(null),k=y.useRef(i),w=y.useRef(o);k.current=i,w.current=o,y.useEffect(()=>{const M=()=>g(!0);return window.addEventListener("focus",M),()=>window.removeEventListener("focus",M)},[]);const C=y.useCallback((M,I,P,F)=>{var ge;const V=(ge=b.current)==null?void 0:ge.getBoundingClientRect();if(!V)return!1;const Y=P-V.left,H=F-V.top;if(Y<0||H<0||Y>V.width||H>V.height)return!1;const Q=1-M*(I===1?16:1)*.002,q=Math.max(.5,Math.min(2,Q)),ee=k.current,te=Math.min(GF,Math.max(qF,ee*q));if(te===ee)return!0;const ue=te/ee,fe=w.current,re=Y-ue*(Y-fe.x),ie=H-ue*(H-fe.y);return k.current=te,w.current={x:re,y:ie},s(te),a({x:re,y:ie}),!0},[]);y.useEffect(()=>{const M=I=>{!I.ctrlKey&&!I.metaKey||C(I.deltaY,I.deltaMode,I.clientX,I.clientY)&&(I.preventDefault(),I.stopPropagation())};return document.addEventListener("wheel",M,{passive:!1,capture:!0}),()=>document.removeEventListener("wheel",M,{capture:!0})},[C]),y.useEffect(()=>{const M=_.current;if(!M)return;const I=P=>{P.ctrlKey||P.metaKey||(P.preventDefault(),C(P.deltaY,P.deltaMode,P.clientX,P.clientY))};return M.addEventListener("wheel",I,{passive:!1}),()=>M.removeEventListener("wheel",I)},[C]);const j=y.useCallback(M=>{if(M.button===1){M.preventDefault(),M.stopPropagation(),d(!0),v.current={x:M.clientX,y:M.clientY},M.target.setPointerCapture(M.pointerId);return}g(!1)},[]),N=y.useCallback(M=>{if(!l)return;M.preventDefault();const I=M.clientX-v.current.x,P=M.clientY-v.current.y;v.current={x:M.clientX,y:M.clientY},a(F=>{const V={x:F.x+I,y:F.y+P};return w.current=V,V})},[l]),A=y.useCallback(M=>{M.button===1&&d(!1)},[]),E=y.useCallback(M=>{M.preventDefault(),s(1),a({x:0,y:0}),k.current=1,w.current={x:0,y:0}},[]),R=y.useCallback(()=>{l||g(!0)},[l]),L=i!==1||o.x!==0||o.y!==0,z=y.useCallback(()=>{var Q;const M=(Q=b.current)==null?void 0:Q.getBoundingClientRect(),I=M?M.width/2:0,P=M?M.height/2:0,F=k.current,V=Math.min(GF,F*1.2),Y=V/F,H=w.current,U={x:I-Y*(I-H.x),y:P-Y*(P-H.y)};k.current=V,w.current=U,s(V),a(U)},[]),$=y.useCallback(()=>{var Q;const M=(Q=b.current)==null?void 0:Q.getBoundingClientRect(),I=M?M.width/2:0,P=M?M.height/2:0,F=k.current,V=Math.max(qF,F/1.2),Y=V/F,H=w.current,U={x:I-Y*(I-H.x),y:P-Y*(P-H.y)};k.current=V,w.current=U,s(V),a(U)},[]),W=y.useCallback(()=>{s(1),a({x:0,y:0}),k.current=1,w.current={x:0,y:0}},[]),B=y.useCallback(()=>{g(M=>!M)},[]),K=y.useCallback(()=>{f(M=>!M)},[]);return c.jsxs("div",{ref:b,className:"relative h-full overflow-hidden",onPointerLeave:R,children:[c.jsx("div",{style:{transform:`translate(${o.x}px, ${o.y}px) scale(${i})`,transformOrigin:"0 0",width:"100%",height:"100%",willChange:L?"transform":void 0},children:e}),c.jsx("div",{ref:_,className:"absolute inset-0 z-10",style:{pointerEvents:p||l?"auto":"none",cursor:l?"grabbing":p?"default":void 0},onPointerDown:j,onPointerMove:N,onPointerUp:A,onDoubleClick:E}),c.jsxs("div",{className:"absolute left-2 top-2 z-20 flex items-start gap-2",children:[c.jsxs("div",{className:"pointer-events-auto flex items-start gap-2",children:[c.jsx("button",{type:"button",className:"flex h-7 w-7 items-center justify-center rounded-full bg-background/90 text-muted-foreground shadow backdrop-blur-sm transition-colors hover:bg-background",onClick:K,"aria-expanded":u,"aria-label":u?"Hide pan and zoom help":"Show pan and zoom help",title:u?"Hide pan and zoom help":"Show pan and zoom help",children:c.jsx(aK,{className:"h-3.5 w-3.5"})}),u?c.jsx("div",{className:"max-w-[260px] rounded-xl bg-background/90 px-3 py-2 text-xs text-muted-foreground shadow backdrop-blur-sm",children:"Scroll to zoom. Middle-drag to pan. Click the preview to interact."}):null]}),r?c.jsx("div",{className:"rounded bg-background/90 px-2 py-1 text-xs text-muted-foreground shadow",children:r}):null]}),n?c.jsx("div",{className:"absolute right-2 top-2 z-20",children:n}):null,c.jsxs("div",{className:"absolute bottom-2 right-2 z-20 flex items-center gap-0.5 rounded bg-background/90 px-1.5 py-1 text-xs text-muted-foreground shadow",children:[c.jsx("button",{type:"button",className:`rounded px-1.5 py-0.5 ${p?"bg-primary/15 text-primary":"hover:bg-muted"}`,onClick:B,title:p?"Switch to interact mode (click VNC)":"Switch to navigate mode (scroll to zoom)",children:p?"🔍 Navigate":"👆 Interact"}),c.jsx("span",{className:"mx-0.5 text-border",children:"│"}),c.jsx("button",{type:"button",className:"rounded px-1 hover:bg-muted",onClick:$,title:"Zoom out",children:"−"}),c.jsxs("span",{className:"min-w-[3ch] text-center tabular-nums",children:[Math.round(i*100),"%"]}),c.jsx("button",{type:"button",className:"rounded px-1 hover:bg-muted",onClick:z,title:"Zoom in",children:"+"}),L?c.jsx("button",{type:"button",className:"ml-0.5 rounded px-1 hover:bg-muted",onClick:W,title:"Reset view (double-click)",children:"↺"}):null]})]})}function Eoe({path:e,language:r,value:n,originalContent:i,theme:s,readOnly:o,onChange:a,onApplyReview:l,onReferenceSelection:d}){const u=y.useRef(null),f=y.useRef(null),[p,g]=y.useState([]),[v,b]=y.useState([]),[_,k]=y.useState(!1),w=i!=null&&i!==n;y.useEffect(()=>{if(!w||i==null){g([]);return}g(Noe(i,n))},[w,i,n]);const C=y.useCallback(()=>{const L=u.current;if(!L||p.length===0){b([]);return}const z=L.getScrollTop(),W=L.getLayoutInfo().height,B=p.flatMap(K=>{if(K.state!=="undecided")return[];const M=SO(K),I=L.getTopForLineNumber(M)-z+2;return!Number.isFinite(I)||I<-28||I>W?[]:[{hunkIndex:K.index,top:I}]});b(B)},[p]),j=y.useMemo(()=>p.filter(L=>L.state==="undecided").length,[p]),N=p.length>0&&j===0,A=y.useCallback(async()=>{if(!(!N||i==null||!l)){k(!0);try{const L=Toe(i.split(`
|
|
1144
1144
|
`),n.split(`
|
|
1145
1145
|
`),p);await l(L)}finally{k(!1)}}},[N,p,l,i,n]);y.useEffect(()=>{if(!N||!l)return;const L=window.setTimeout(()=>{A()},600);return()=>window.clearTimeout(L)},[N,l,A]),y.useEffect(()=>{C()},[C]);const E=y.useCallback((L,z)=>{g($=>$.map((W,B)=>B===L?{...W,state:z}:W))},[]),R=y.useCallback(()=>{var K,M;const L=u.current,z=(K=L==null?void 0:L.getModel)==null?void 0:K.call(L),$=(M=L==null?void 0:L.getSelection)==null?void 0:M.call(L);if(!L||!z||!$||$.isEmpty()){f.current=null;return}const W=z.getValueInRange($).trim();if(!W){f.current=null;return}const B=`${$.startLineNumber}:${$.endLineNumber}:${W}`;f.current!==B&&(f.current=B,d==null||d(W,$.startLineNumber,$.endLineNumber))},[d]);return c.jsxs("div",{className:"relative h-full",children:[c.jsx(Oj,{height:"100%",beforeMount:C0,theme:s,path:e,language:r,value:n,onChange:a,onMount:L=>{u.current=L;const z=[L.onDidScrollChange(()=>C()),L.onDidLayoutChange(()=>C()),L.onDidContentSizeChange(()=>C()),L.onMouseUp(()=>window.setTimeout(R,0)),L.onKeyUp(()=>window.setTimeout(R,0))];window.setTimeout(C,0),L.__jaitReviewDisposables=z},options:{readOnly:o,minimap:{enabled:!1},fontSize:13,automaticLayout:!0}},e),v.length>0&&!o&&c.jsx("div",{className:"pointer-events-none absolute inset-0 z-20",children:v.map(({hunkIndex:L,top:z})=>{const $=p[L];return!$||$.state!=="undecided"?null:c.jsxs("div",{className:"pointer-events-auto absolute right-3 flex items-center gap-1 rounded-md border bg-background/95 p-1 shadow-md backdrop-blur-sm",style:{top:z},children:[c.jsxs(_e,{size:"sm",variant:"ghost",className:"h-7 px-2 text-xs text-green-600 hover:bg-green-500/10 hover:text-green-500",onClick:()=>E(L,"accepted"),children:[c.jsx(hs,{className:"mr-1 h-3 w-3"}),"Keep"]}),c.jsxs(_e,{size:"sm",variant:"ghost",className:"h-7 px-2 text-xs text-red-600 hover:bg-red-500/10 hover:text-red-500",onClick:()=>E(L,"rejected"),children:[c.jsx(vh,{className:"mr-1 h-3 w-3"}),"Undo"]})]},`review-${L}`)})}),w&&!o&&c.jsxs("div",{className:"absolute bottom-3 left-1/2 z-20 flex -translate-x-1/2 items-center gap-2 rounded-full border bg-background/95 px-3 py-1.5 text-xs shadow-md backdrop-blur-sm",children:[c.jsxs("span",{className:"font-medium",children:[j," pending"]}),N&&c.jsx("span",{className:"text-muted-foreground",children:_?"Applying...":"Applying review..."})]})]})}const mYe="jait:detached-workspace-tab:";function eP(e){return`${mYe}${e}`}function gYe(e){localStorage.setItem(eP(e.id),JSON.stringify(e))}function KF(e){const r=localStorage.getItem(eP(e));if(!r)return null;try{return JSON.parse(r)}catch{return null}}function yYe(e){localStorage.removeItem(eP(e))}const vYe=new Set([".git","node_modules","dist","build",".next",".turbo",".idea",".vscode"]);async function xYe(e,r,n,i,s=vYe){const o=r.trim().toLowerCase();if(!o||n<1)return[];const a=[],l=1024*1024,d=(f,p)=>{const g=p.split(`
|
|
1146
1146
|
`);for(let v=0;v<g.length;v+=1){if(i!=null&&i.aborted||a.length>=n)return;const b=g[v]??"";b.toLowerCase().includes(o)&&a.push({file:f,line:v+1,content:b.trim()})}},u=async(f,p)=>{if(i!=null&&i.aborted||a.length>=n)return!0;try{for await(const g of f.values()){if(i!=null&&i.aborted||a.length>=n)return!0;const v=g.name;if(v.startsWith(".")||s.has(v))continue;const b=p?`${p}/${v}`:v;if(g.kind==="directory"){if(await u(g,b))return!0;continue}try{const _=await g.getFile();if(_.size>l)continue;const k=await _.text();if(k.includes("\0"))continue;d(b,k)}catch{}}}catch{}return(i==null?void 0:i.aborted)===!0||a.length>=n};return await u(e,""),a}function kO(e){return e!=null&&e.hasUpstream?(e.aheadCount??0)>0||(e.behindCount??0)>0:!1}function bYe(e,r){return e>0?!0:((r==null?void 0:r.aheadCount)??0)>0}function _Ye(e,r){return e>0?"commit":kO(r)?"sync":"commit"}function wYe({showTree:e,showEditor:r,panelSize:n,treeSize:i,maxCollapsed:s}){const o=!e&&!r?0:e?r?n:i:Math.max(n-i,300);return s?{width:"100%",maxWidth:"100%"}:{width:o,maxWidth:"70vw"}}function SYe(e,r){return e.length+r.length}function Ll(e,r="ms"){if(e==null||!Number.isFinite(e))return"n/a";if(r==="ms")return`${Math.round(e)} ms`;if(r==="bytes"){if(e>=1024*1024)return`${(e/(1024*1024)).toFixed(1)} MB`;if(e>=1024)return`${(e/1024).toFixed(1)} KB`}return r==="count"?`${Math.round(e)}`:String(e)}function Aoe({metrics:e}){var r,n,i,s,o,a,l,d,u,f,p,g,v,b,_;return e?c.jsxs("div",{className:"space-y-2",children:[c.jsxs("div",{className:"rounded border bg-muted/30 p-2",children:[c.jsx("div",{className:"font-medium text-foreground",children:e.title||"(untitled)"}),c.jsx("div",{className:"mt-1 break-all text-muted-foreground",children:c.jsx("code",{children:e.url})}),c.jsxs("div",{className:"mt-1 text-xs text-muted-foreground",children:["Sampled ",new Date(e.sampledAt).toLocaleTimeString()]})]}),c.jsxs("div",{className:"grid gap-2 md:grid-cols-3",children:[c.jsxs("div",{className:"rounded border p-2",children:[c.jsx("div",{className:"font-medium text-foreground",children:"Web Vitals"}),c.jsxs("div",{className:"mt-1 space-y-1 text-muted-foreground",children:[c.jsxs("div",{children:["LCP: ",Ll((r=e.webVitals)==null?void 0:r.lcpMs,"ms")]}),c.jsxs("div",{children:["CLS: ",((n=e.webVitals)==null?void 0:n.cls)!=null?e.webVitals.cls.toFixed(3):"n/a"]}),c.jsxs("div",{children:["INP: ",Ll((i=e.webVitals)==null?void 0:i.inpMs,"ms")]})]})]}),c.jsxs("div",{className:"rounded border p-2",children:[c.jsx("div",{className:"font-medium text-foreground",children:"Load"}),c.jsxs("div",{className:"mt-1 space-y-1 text-muted-foreground",children:[c.jsxs("div",{children:["DOMContentLoaded: ",Ll((s=e.navigation)==null?void 0:s.domContentLoadedMs,"ms")]}),c.jsxs("div",{children:["Load: ",Ll((o=e.navigation)==null?void 0:o.loadMs,"ms")]}),c.jsxs("div",{children:["FCP: ",Ll((a=e.paint)==null?void 0:a.firstContentfulPaintMs,"ms")]})]})]}),c.jsxs("div",{className:"rounded border p-2",children:[c.jsx("div",{className:"font-medium text-foreground",children:"Memory"}),c.jsxs("div",{className:"mt-1 space-y-1 text-muted-foreground",children:[c.jsxs("div",{children:["Used JS heap: ",Ll((l=e.memory)==null?void 0:l.usedJsHeapSize,"bytes")]}),c.jsxs("div",{children:["Total JS heap: ",Ll((d=e.memory)==null?void 0:d.totalJsHeapSize,"bytes")]}),c.jsxs("div",{children:["Heap limit: ",Ll((u=e.memory)==null?void 0:u.jsHeapSizeLimit,"bytes")]})]})]})]}),c.jsxs("div",{className:"rounded border p-2",children:[c.jsx("div",{className:"font-medium text-foreground",children:"Resources"}),c.jsxs("div",{className:"mt-1 grid gap-1 text-muted-foreground md:grid-cols-3",children:[c.jsxs("div",{children:["Total: ",Ll((f=e.resources)==null?void 0:f.total,"count")]}),c.jsxs("div",{children:["Scripts: ",Ll((p=e.resources)==null?void 0:p.scripts,"count")]}),c.jsxs("div",{children:["Stylesheets: ",Ll((g=e.resources)==null?void 0:g.stylesheets,"count")]}),c.jsxs("div",{children:["Images: ",Ll((v=e.resources)==null?void 0:v.images,"count")]}),c.jsxs("div",{children:["Fonts: ",Ll((b=e.resources)==null?void 0:b.fonts,"count")]}),c.jsxs("div",{children:["Largest transfer: ",Ll((_=e.resources)==null?void 0:_.largestTransferSize,"bytes")]})]})]})]}):c.jsx("div",{className:"text-muted-foreground",children:"No preview metrics available yet."})}function kYe({inspectState:e,loading:r=!1,error:n=null,onInsertElementReference:i}){var s,o,a,l,d,u,f,p;return n?c.jsx("div",{className:"rounded border border-destructive/30 bg-destructive/5 px-2 py-1.5 text-destructive",children:n}):r?c.jsx("div",{className:"text-muted-foreground",children:"Inspecting preview…"}):e!=null&&e.captureSuppressed?c.jsx("div",{className:"rounded border border-amber-500/30 bg-amber-500/5 px-2 py-1.5 text-amber-700",children:e.suppressionReason??"Preview inspection is currently suppressed."}):e?c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"rounded border bg-muted/30 p-2",children:[c.jsx("div",{className:"font-medium text-foreground",children:((s=e.page)==null?void 0:s.title)||"(untitled)"}),c.jsx("div",{className:"mt-1 break-all text-muted-foreground",children:c.jsx("code",{children:e.url??((o=e.page)==null?void 0:o.url)??"Unknown URL"})})]}),c.jsxs("div",{className:"rounded border p-2",children:[c.jsx("div",{className:"font-medium text-foreground",children:"Active Element"}),(a=e.page)!=null&&a.activeElement?c.jsxs("div",{className:"mt-1 space-y-1 text-muted-foreground",children:[c.jsx("div",{children:[e.page.activeElement.role??e.page.activeElement.tagName??"element",e.page.activeElement.name].filter(Boolean).join(" - ")}),e.page.activeElement.selector?c.jsx("div",{children:c.jsx("code",{children:e.page.activeElement.selector})}):null,e.page.activeElement.selector&&i?c.jsx(_e,{type:"button",variant:"outline",size:"sm",className:"mt-2 h-7 px-2 text-xs",onClick:()=>i(e.page.activeElement),children:"Insert Into Chat"}):null]}):c.jsx("div",{className:"mt-1 text-muted-foreground",children:"No active input detected."})]}),c.jsxs("div",{className:"rounded border p-2",children:[c.jsx("div",{className:"font-medium text-foreground",children:"Dialogs"}),(d=(l=e.page)==null?void 0:l.dialogs)!=null&&d.length?c.jsx("div",{className:"mt-1 space-y-1 text-muted-foreground",children:e.page.dialogs.map((g,v)=>c.jsxs("div",{className:"rounded bg-muted/40 px-2 py-1",children:[c.jsx("div",{children:g.title||g.name||g.role||"dialog"}),g.selector?c.jsx("div",{children:c.jsx("code",{children:g.selector})}):null]},`${g.selector??g.title??v}`))}):c.jsx("div",{className:"mt-1 text-muted-foreground",children:"No visible dialogs detected."})]}),c.jsxs("div",{className:"rounded border p-2",children:[c.jsx("div",{className:"font-medium text-foreground",children:"Obstruction"}),(u=e.page)!=null&&u.obstruction?c.jsxs("div",{className:"mt-1 space-y-1 text-muted-foreground",children:[c.jsxs("div",{children:["Modal: ",e.page.obstruction.hasModal?"yes":"no"," · Dialogs: ",e.page.obstruction.dialogCount]}),e.page.obstruction.activeDialogTitle?c.jsxs("div",{children:["Active dialog: ",e.page.obstruction.activeDialogTitle]}):null,e.page.obstruction.notes.map((g,v)=>c.jsx("div",{children:g},`${g}:${v}`))]}):c.jsx("div",{className:"mt-1 text-muted-foreground",children:"No obstruction diagnostics available."})]}),e.target?c.jsxs("div",{className:"rounded border p-2",children:[c.jsx("div",{className:"font-medium text-foreground",children:"Selector Diagnosis"}),c.jsxs("div",{className:"mt-1 space-y-1 text-muted-foreground",children:[c.jsx("div",{children:c.jsx("code",{children:e.target.selector})}),c.jsxs("div",{children:["Found: ",e.target.found?"yes":"no"]}),e.target.obscured!=null?c.jsxs("div",{children:["Obscured: ",e.target.obscured?"yes":"no"]}):null,e.target.offscreen!=null?c.jsxs("div",{children:["Offscreen: ",e.target.offscreen?"yes":"no"]}):null,e.target.dialogTitle?c.jsxs("div",{children:["Dialog: ",e.target.dialogTitle]}):null,e.target.obstructionReason?c.jsx("div",{children:e.target.obstructionReason}):null,e.target.interceptedBy?c.jsxs("div",{children:["Intercepted by ",e.target.interceptedBy.role??e.target.interceptedBy.tagName??"element",e.target.interceptedBy.selector?` (${e.target.interceptedBy.selector})`:""]}):null,e.target.selector&&i?c.jsx(_e,{type:"button",variant:"outline",size:"sm",className:"mt-2 h-7 px-2 text-xs",onClick:()=>i(e.target),children:"Insert Into Chat"}):null]})]}):null,c.jsxs("div",{className:"rounded border p-2",children:[c.jsx("div",{className:"font-medium text-foreground",children:"Interactive Elements"}),(p=(f=e.page)==null?void 0:f.elements)!=null&&p.length?c.jsx("div",{className:"mt-2 space-y-2",children:e.page.elements.map((g,v)=>{const b=[g.role??g.tagName??"element",g.name||g.text].filter(Boolean).join(" - ");return c.jsxs("div",{className:"rounded bg-muted/40 px-2 py-1.5 text-muted-foreground",children:[c.jsx("div",{className:"font-medium text-foreground",children:b||"Unnamed element"}),g.selector?c.jsx("div",{className:"mt-1 break-all",children:c.jsx("code",{children:g.selector})}):null,g.placeholder?c.jsxs("div",{className:"mt-1",children:["Placeholder: ",g.placeholder]}):null,g.value?c.jsxs("div",{className:"mt-1",children:["Value: ",g.value]}):null,c.jsxs("div",{className:"mt-1 text-2xs",children:[g.disabled?"Disabled":"Enabled",g.active?" · Active":""]}),g.selector&&i?c.jsx(_e,{type:"button",variant:"outline",size:"sm",className:"mt-2 h-7 px-2 text-xs",onClick:()=>i(g),children:"Insert Into Chat"}):null]},`${g.selector??b??"element"}:${v}`)})}):c.jsx("div",{className:"mt-1 text-muted-foreground",children:"No interactive elements captured."})]}),c.jsxs("div",{className:"rounded border p-2",children:[c.jsx("div",{className:"font-medium text-foreground",children:"Metrics"}),c.jsx("div",{className:"mt-2",children:c.jsx(Aoe,{metrics:e.metrics})})]})]}):c.jsx("div",{className:"text-muted-foreground",children:"No inspection data available yet."})}function Sk(e){var r;return e.length>0?((r=e[e.length-1])==null?void 0:r.id)??null:null}function CYe(e){const r=e==null?void 0:e.trim();return r?`${r}::managed-preview`:null}function kk(e,r){var n,i,s,o;return e===r?!0:!e||!r?!1:e.id===r.id&&e.status===r.status&&e.mode===r.mode&&e.target===r.target&&e.command===r.command&&e.port===r.port&&e.url===r.url&&e.browserId===r.browserId&&e.processId===r.processId&&e.containerId===r.containerId&&(((n=e.remoteBrowser)==null?void 0:n.containerName)??null)===(((i=r.remoteBrowser)==null?void 0:i.containerName)??null)&&(((s=e.remoteBrowser)==null?void 0:s.novncUrl)??null)===(((o=r.remoteBrowser)==null?void 0:o.novncUrl)??null)&&e.lastError===r.lastError&&e.updatedAt===r.updatedAt&&e.logs.length===r.logs.length&&Sk(e.logs)===Sk(r.logs)&&e.browserEvents.length===r.browserEvents.length&&Sk(e.browserEvents)===Sk(r.browserEvents)}const CO=new Set;function jYe(e){return CO.add(e),()=>{CO.delete(e)}}function NYe(e){for(const r of CO)r(e)}const L_=new Set(["node_modules",".git",".hg",".svn","dist","build","out",".next",".nuxt",".output",".cache","__pycache__",".tox",".venv","venv","env",".idea",".vscode",".DS_Store","coverage",".turbo",".parcel-cache","target"]);function ka(e){var i;const r=(i=e.split(".").pop())==null?void 0:i.toLowerCase();return r?{ts:"typescript",tsx:"typescript",js:"javascript",jsx:"javascript",json:"json",md:"markdown",css:"css",scss:"scss",less:"less",html:"html",py:"python",yml:"yaml",yaml:"yaml",rs:"rust",go:"go",java:"java",c:"c",cpp:"cpp",h:"c",hpp:"cpp",sh:"shell",bash:"shell",zsh:"shell",sql:"sql",xml:"xml",toml:"toml",ini:"ini",dockerfile:"dockerfile",graphql:"graphql"}[r]??"plaintext":"plaintext"}function $_(e){return ka(e)}const Ooe="jait.git.autofetch",TYe="jait.git.autofetchPeriod",YF=180;function EYe(){if(typeof window>"u")return!1;const e=window.localStorage.getItem(Ooe);return e==="true"?!0:e==="all"?"all":!1}function AYe(){if(typeof window>"u")return YF;const e=window.localStorage.getItem(TYe),r=e?Number.parseInt(e,10):Number.NaN;return!Number.isFinite(r)||r<10?YF:r}function XF(e){return e==="all"?"Auto-fetch: all remotes":e===!0?"Auto-fetch: default remote":"Auto-fetch: off"}const ZF=25;async function Ck(e,r){const n=[],i=[];for await(const s of e.values()){const o=s.name,a=r?`${r}/${o}`:o;if(s.kind==="directory"){if(L_.has(o))continue;n.push({kind:"dir",name:o,path:a,handle:s,children:null})}else i.push({kind:"file",name:o,path:a,handle:s})}return n.sort((s,o)=>s.name.localeCompare(o.name)),i.sort((s,o)=>s.name.localeCompare(o.name)),[...n,...i]}async function t1(e){const r=await e.getFile();return r.size>2*1024*1024?"// File too large to preview":r.text()}function to(e){return e.replace(/\\/g,"/").replace(/\/+$/,"")}function JF(e,r){const n=to(e),i=to(r);return i===n||i.startsWith(`${n}/`)}const Ta=$n();async function ru(e,r){let n=`${Ta}/api/workspace/list?path=${encodeURIComponent(e)}`;r&&(n+=`&surfaceId=${encodeURIComponent(r)}`);const i=await fetch(n);if(!i.ok)throw new Error(`Failed to list directory: ${i.statusText}`);const s=await i.json(),o=[],a=[];for(const l of s.entries){const d=l.endsWith("/"),u=d?l.slice(0,-1):l;if(L_.has(u))continue;const f=e.replace(/[\\/]$/,"")+"/"+u;d?o.push({kind:"dir",name:u,path:f,handle:null,children:null}):a.push({kind:"file",name:u,path:f,handle:null})}return o.sort((l,d)=>l.name.localeCompare(d.name)),a.sort((l,d)=>l.name.localeCompare(d.name)),[...o,...a]}async function Xu(e,r){let n=`${Ta}/api/workspace/read?path=${encodeURIComponent(e)}`;r&&(n+=`&surfaceId=${encodeURIComponent(r)}`);const i=await fetch(n);if(!i.ok)throw new Error(`Failed to read file: ${i.statusText}`);const s=await i.json();return s.size>2*1024*1024?"// File too large to preview":s.content}async function OYe(e,r,n){const i=await fetch(`${Ta}/api/workspace/write`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e,content:r,surfaceId:n})});if(!i.ok){const s=await i.json().catch(()=>({}));throw new Error(s.message||`Failed to write file: ${i.statusText}`)}}async function RYe(e,r){let n=`${Ta}/api/workspace/backup?path=${encodeURIComponent(e)}`;r&&(n+=`&surfaceId=${encodeURIComponent(r)}`);const i=await fetch(n);return i.ok?(await i.json()).originalContent:null}async function QF(e,r){let n=`${Ta}/api/workspace/stat?path=${encodeURIComponent(e)}`;r&&(n+=`&surfaceId=${encodeURIComponent(r)}`);try{const i=await fetch(n);return i.ok?(await i.json()).modified??null:null}catch{return null}}const MYe={A:"text-green-500",M:"text-yellow-500",D:"text-red-500",R:"text-blue-500","?":"text-green-400"},jO={A:"Added",M:"Modified",D:"Deleted",R:"Renamed","?":"Untracked"},jk=16;function o_({status:e,className:r=""}){const n=e==="?"?"U":e;return c.jsx("span",{className:`text-2xs font-bold leading-none shrink-0 ${MYe[e]??"text-muted-foreground"} ${r}`,title:jO[e]??e,children:n})}function PYe(e){const r=new Set;for(const n of e.keys()){const i=n.replace(/\\/g,"/").split("/");for(let s=1;s<i.length;s++)r.add(i.slice(0,s).join("/"))}return r}function LYe(e,r){if(r.size===0)return!1;const n=e.replace(/\\/g,"/");let i=0;for(;;){const s=n.indexOf("/",i);if(s===-1)break;const o=n.slice(s+1);if(o&&r.has(o))return!0;i=s+1}return r.has(n)}function $Ye(e){const r=new Map;for(const[n,i]of e){r.set(n,i);const s=n.replace(/\\/g,"/");s!==n&&r.set(s,i)}return r}function eH(e){const r={children:[]};for(const i of e){const s=i.path.replace(/\\/g,"/"),o=s.split("/").filter(Boolean);if(o.length===0)continue;let a=r;for(let l=0;l<o.length;l++){const d=o[l],u=o.slice(0,l+1).join("/");if(l===o.length-1){a.children.push({kind:"file",name:d,path:s,entry:i});continue}let p=a.children.find(g=>g.kind==="dir"&&g.path===u);p||(p={kind:"dir",name:d,path:u,children:[]},a.children.push(p)),a=p}}const n=i=>[...i].sort((s,o)=>s.kind!==o.kind?s.kind==="dir"?-1:1:s.name.localeCompare(o.name)).map(s=>s.kind==="dir"?{...s,children:n(s.children)}:s);return n(r.children)}function Roe(e){const r=[];for(const n of e){if(n.kind==="file"){r.push(n.path);continue}r.push(...Roe(n.children))}return r}const tl=io;function Nk(e){return!!(e&&e.type==="file"&&e.id.startsWith("file:"))}function r1(e){if(e.type==="architecture")return e.label||"Architecture";if(e.type==="preview")return e.label||"Preview";if(e.type!=="diff")return e.label;const r=e.label||(e.path.split(/[\\/]/).pop()??e.path);return`${r} <-> ${r}`}function Cb(e){return e?{Authorization:`Bearer ${e}`,"Content-Type":"application/json"}:{"Content-Type":"application/json"}}function tH(e){const r=e==null?void 0:e.trim();return r||"Live Preview"}function Tk(e){const r=e==null?void 0:e.trim();return r?/^wss?:\/\//i.test(r)?r:/\/(?:noVNC\/)?vnc(?:_lite)?\.html(?:[?#].*)?$/i.test(r)?r.startsWith("/")?`${Ta}${r}`:r:null:null}function rH(e){const r=(e==null?void 0:e.trim())||"";return r&&r!=="__preview__"?r:null}function Ek(e,r){var n;if(e instanceof HTMLElement&&(n=e.hasPointerCapture)!=null&&n.call(e,r))try{e.releasePointerCapture(r)}catch{}}function nH(e,r,n,i="horizontal",s,o){const a=(o==null?void 0:o.snapCollapse)??!1,l=(o==null?void 0:o.snapMaxCollapse)??!1,d=(o==null?void 0:o.snapMaxSize)??n,[u,f]=y.useState(()=>{if(!s||typeof window>"u")return e;const B=window.localStorage.getItem(s),K=B?Number.parseInt(B,10):Number.NaN;return Number.isFinite(K)?Math.min(n,Math.max(r,K)):e}),[p,g]=y.useState(!1),[v,b]=y.useState(!1),_=y.useRef(e),k=y.useRef(!1),[w,C]=y.useState(!1),j=y.useRef(null),N=y.useRef(null),A=-1,E=-2;y.useEffect(()=>{!p&&!v&&u>=r&&(_.current=u)},[u,p,v,r]),y.useEffect(()=>{!p&&!v&&f(B=>Math.min(n,Math.max(r,B)))},[r,n,p,v]);const R=y.useRef(null);y.useEffect(()=>()=>{var B;(B=R.current)==null||B.call(R),j.current!==null&&window.cancelAnimationFrame(j.current)},[]);const L=y.useCallback(()=>{const B=Math.min(n,Math.max(r,_.current));f(B),g(!1),b(!1)},[r,n]),z=y.useCallback(()=>{p||(_.current=u,g(!0),b(!1),f(0))},[p,u]),$=y.useCallback(B=>{B!==null&&(B===A?(g(!0),b(!1),f(0)):B===E?(b(!0),g(!1),f(d)):(g(!1),b(!1),f(B)))},[d]),W=y.useCallback(B=>{var ee,te;B.preventDefault(),k.current=!0,C(!0);const K=B.pointerId,M=B.currentTarget;(ee=R.current)==null||ee.call(R),(te=M.setPointerCapture)==null||te.call(M,K);const I=i==="horizontal"?B.clientX:B.clientY,P=p?0:v?d:u,F=r/2,V=n+(d-n)/2,Y=ue=>{if(!k.current)return;const re=(i==="horizontal"?ue.clientX:ue.clientY)-I,ie=P+re;a&&ie<F?N.current=A:l&&ie>V?N.current=E:N.current=Math.min(n,Math.max(r,ie)),j.current===null&&(j.current=window.requestAnimationFrame(()=>{j.current=null,$(N.current)}))},H=()=>{var ue,fe;k.current=!1,C(!1),(ue=M.hasPointerCapture)!=null&&ue.call(M,K)&&((fe=M.releasePointerCapture)==null||fe.call(M,K)),j.current!==null&&(window.cancelAnimationFrame(j.current),j.current=null),N.current!==null&&($(N.current),N.current=null),document.removeEventListener("pointermove",Y),document.removeEventListener("pointerup",U),document.removeEventListener("pointercancel",U),M.removeEventListener("lostpointercapture",Q),window.removeEventListener("blur",q),document.body.style.cursor="",document.body.style.userSelect="",R.current=null},U=()=>{H()},Q=()=>{H()},q=()=>{H()};document.body.style.cursor=i==="horizontal"?"col-resize":"row-resize",document.body.style.userSelect="none",R.current=H,document.addEventListener("pointermove",Y),document.addEventListener("pointerup",U),document.addEventListener("pointercancel",U),M.addEventListener("lostpointercapture",Q),window.addEventListener("blur",q)},[u,r,n,i,a,l,d,p,v,$]);return y.useEffect(()=>{!s||typeof window>"u"||!p&&!v&&window.localStorage.setItem(s,String(u))},[u,s,p,v]),{size:u,collapsed:p,maxCollapsed:v,onPointerDown:W,isDragging:w,restore:L,collapse:z}}function n1({text:e,query:r}){if(!r)return c.jsx(c.Fragment,{children:e});const n=e.toLowerCase(),i=r.toLowerCase(),s=[];let o=0,a=n.indexOf(i,o);for(;a!==-1;)a>o&&s.push(e.slice(o,a)),s.push(c.jsx("span",{className:"bg-yellow-300/40 dark:bg-yellow-500/30 text-foreground rounded-sm px-px",children:e.slice(a,a+r.length)},a)),o=a+r.length,a=n.indexOf(i,o);return o<e.length&&s.push(e.slice(o)),c.jsx(c.Fragment,{children:s})}const iH=y.memo(function e({node:r,depth:n,activeFilePath:i,expandedDirs:s,onToggleDir:o,onSelectFile:a,onContextFile:l,onTreeContextMenu:d,onMoveNode:u,onMobilePointerStart:f,isMobile:p,normStatusMap:g,dirChangesSet:v,mobileDragTargetPath:b}){var L;const _=p?6+n*12:8+n*14,[k,w]=y.useState(!1),C=y.useCallback(z=>{const $=z.getBoundingClientRect();d(r,$.right-8,$.bottom+4)},[r,d]),j=y.useCallback(z=>{z.stopPropagation(),z.pointerType!=="mouse"&&(z.preventDefault(),C(z.currentTarget))},[C]),N=y.useCallback(z=>{z.preventDefault(),z.stopPropagation(),C(z.currentTarget)},[C]);if(r.kind==="dir"){const z=s.has(r.path),$=r.childrenLoading,W=v?LYe(r.path,v):!1;return c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:`group flex items-center gap-1.5 rounded px-1 cursor-pointer hover:bg-muted active:bg-muted ${p?"py-2 text-sm":"py-1 [font-size:0.9rem]"} ${k||b===r.path?"bg-primary/15 ring-1 ring-primary/40":""}`,style:{paddingLeft:_},"data-tree-path":r.path,"data-tree-drop-dir":r.path,onClick:()=>o(r),onContextMenu:B=>{B.preventDefault(),B.stopPropagation(),d(r,B.clientX,B.clientY)},onPointerDown:B=>f==null?void 0:f(r,B),onDragOver:B=>{B.dataTransfer.types.includes("text/jait-tree-node")&&(B.preventDefault(),B.dataTransfer.dropEffect="move",w(!0))},onDragEnter:B=>{B.dataTransfer.types.includes("text/jait-tree-node")&&(B.preventDefault(),w(!0))},onDragLeave:()=>w(!1),onDrop:B=>{w(!1);const K=B.dataTransfer.getData("text/jait-tree-node");if(!K)return;B.preventDefault(),B.stopPropagation();const M=JSON.parse(K);M.path!==r.path&&u(M.path,r.path)},draggable:!p,onDragStart:B=>{const K=JSON.stringify({path:r.path,name:r.name,kind:"dir"});B.dataTransfer.setData("text/jait-tree-node",K),B.dataTransfer.setData("text/jait-file",JSON.stringify({path:r.path,name:r.name})),B.dataTransfer.effectAllowed="copyMove"},children:[$?c.jsx(ir,{className:`${p?"h-4 w-4":"h-3 w-3"} shrink-0 text-muted-foreground animate-spin`}):c.jsx(ao,{className:`${p?"h-4 w-4":"h-3 w-3"} shrink-0 text-muted-foreground transition-transform duration-150 ${z?"rotate-90":""}`}),c.jsx(Sj,{name:r.name,open:z,className:`${p?"h-4 w-4":"h-3.5 w-3.5"} shrink-0`}),c.jsx("span",{className:`truncate flex-1 ${W?"text-yellow-600 dark:text-yellow-400":""}`,children:r.name}),W&&c.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-yellow-500 shrink-0",title:"Contains modified files"}),p&&c.jsx("button",{type:"button",className:"rounded p-2 hover:bg-background touch-manipulation",onPointerDown:j,onClick:N,title:"More actions",children:c.jsx(HC,{className:"h-3.5 w-3.5"})}),!p&&c.jsx("button",{type:"button",className:"opacity-0 group-hover:opacity-100 p-0.5 rounded hover:bg-background",onClick:B=>{B.stopPropagation(),l(r)},title:"Add to chat",children:c.jsx(Ro,{className:"h-3 w-3"})})]}),z&&((L=r.children)==null?void 0:L.map(B=>c.jsx(e,{node:B,depth:n+1,activeFilePath:i,expandedDirs:s,onToggleDir:o,onSelectFile:a,onContextFile:l,onTreeContextMenu:d,onMoveNode:u,onMobilePointerStart:f,isMobile:p,normStatusMap:g,dirChangesSet:v,mobileDragTargetPath:b},B.path)))]})}const A=i===r.path,E=r.path.replace(/\\/g,"/"),R=(g==null?void 0:g.get(r.name))??(g==null?void 0:g.get(r.path))??(g==null?void 0:g.get(E));return c.jsxs("div",{className:`group flex items-center gap-1.5 rounded px-1 cursor-pointer ${p?"py-2 text-sm":"py-1 [font-size:0.9rem]"} ${A?"bg-primary/15 text-foreground":"hover:bg-muted active:bg-muted"}`,style:{paddingLeft:_+(p?12:14)},"data-tree-path":r.path,onClick:()=>a(r),onContextMenu:z=>{z.preventDefault(),z.stopPropagation(),d(r,z.clientX,z.clientY)},onPointerDown:z=>f==null?void 0:f(r,z),draggable:!p,onDragStart:z=>{z.dataTransfer.setData("text/jait-file",JSON.stringify({path:r.path,name:r.name})),z.dataTransfer.setData("text/jait-tree-node",JSON.stringify({path:r.path,name:r.name,kind:"file"})),z.dataTransfer.effectAllowed="copyMove"},children:[c.jsx(jo,{filename:r.name,className:`${p?"h-4 w-4":"h-3.5 w-3.5"}`}),c.jsx("span",{className:`truncate flex-1 ${R==="D"?"line-through text-muted-foreground":""}`,title:r.path,children:r.name}),R&&c.jsx(o_,{status:R}),p?c.jsx("button",{type:"button",className:"rounded p-2 hover:bg-background touch-manipulation",onPointerDown:j,onClick:N,title:"More actions",children:c.jsx(HC,{className:"h-3.5 w-3.5"})}):c.jsx("button",{type:"button",className:"opacity-0 group-hover:opacity-100 p-0.5 rounded hover:bg-background",onClick:z=>{z.stopPropagation(),l(r)},title:"Add to chat",children:c.jsx(Ro,{className:"h-3 w-3"})})]})}),sH=y.forwardRef(function({files:r,activeFileId:n,onActiveFileChange:i,onFileDrop:s,onReferenceFile:o,onReferenceSelection:a,onAvailableFilesChange:l,autoOpenRemotePath:d,surfaceId:u,isMobile:f,showTree:p=!0,showEditor:g=!0,onToggleTree:v,onToggleEditor:b,onReferencePreviewElement:_,treeTab:k,onTreeTabChange:w,changedPaths:C,fsWatcherVersion:j,sourceControlRefreshSignal:N,savedTabsState:A,stateReady:E,onTabsStateChange:R,onApplyDiff:L,provider:z,cliModel:$,previewRequest:W,onPreviewOpenChange:B,previewSessionId:K,previewToken:M,previewWorkspaceRoot:I,previewInitialTarget:P,architectureDiagram:F,architectureGenerating:V,architectureRequest:Y,onArchitectureOpenChange:H,onGenerateArchitecture:U,onArchitectureRenderResult:Q,onCollapsedChange:q,onMaxCollapsedChange:ee,restoreRef:te},ue){var Ga,ya,Uo,Tl,_p,sc,fn,Lu,qc,Ii,$u;const fe=U0(),re=joe(),ie=Aj(),ge=y.useRef(null),[le,et]=y.useState(null),Xe=y.useRef(null),De=304,de=320,Qe=200,Ie=typeof window<"u"?window.innerWidth:1200,Oe=Math.max(400,Ie-De-de),qe=Math.max(Oe,Ie-De),kt=Math.round((Ie-De)*(4/6)),vt=nH(kt,400,Oe,"horizontal","workspacePanelWidth",{snapCollapse:!0,snapMaxCollapse:!0,snapMaxSize:qe});y.useLayoutEffect(()=>{q==null||q(vt.collapsed)},[vt.collapsed,q]),y.useLayoutEffect(()=>{ee==null||ee(vt.maxCollapsed)},[vt.maxCollapsed,ee]),y.useEffect(()=>{te&&(te.current=vt.restore)},[te,vt.restore]);const Me=Math.max(240,vt.size-Qe),nt=nH(260,240,Me,"horizontal","workspaceTreePaneWidth",{snapCollapse:!0}),[Je,Ot]=y.useState([]),[be,Re]=y.useState(()=>new Set),[ke,$e]=y.useState(null),[ct,gt]=y.useState(null),[at,ut]=y.useState("plaintext"),[Ht,Fe]=y.useState(null),[Ye,Pt]=y.useState(!1),ot=y.useRef(null),[Yt,tt]=y.useState(0),Ge=y.useCallback(()=>tt(G=>G+1),[]),[It,jt]=y.useState(!1),[Se,$t]=y.useState(null),[Et,yt]=y.useState(!1),[mr,Er]=y.useState([]),pn=y.useRef(0),$r=y.useMemo(()=>{if(!Se)return new Map;const G=new Map;for(const se of Se.index.files)G.set(se.path,se.status??"M");for(const se of Se.workingTree.files)G.set(se.path,se.status??"M");return G},[Se]),it=y.useMemo(()=>PYe($r),[$r]),Rt=y.useMemo(()=>$Ye($r),[$r]),[Lr,ft]=y.useState("files"),fr=k??Lr,Lt=y.useCallback(G=>{ft(G),w==null||w(G)},[w]);y.useEffect(()=>{k&&ft(k)},[k]);const[Un,dt]=y.useState("list"),[ur,jn]=y.useState(new Set),[Or,Gt]=y.useState(null),[ar,Do]=y.useState(!1),[or,xe]=y.useState(""),[_t,rr]=y.useState(!1),[Wt,Ce]=y.useState(!1),[Be,Nt]=y.useState(null),[pr,lr]=y.useState(()=>EYe()),[Wr]=y.useState(()=>AYe()),sr=y.useRef(Wt),Qr=y.useRef(Et),[Ct,Xt]=y.useState([]),[nr,bn]=y.useState(null),Ee=y.useMemo(()=>Ct.find(G=>G.id===nr)??null,[Ct,nr]),In=Nk(Ee),Ws=!!Ee,Mc=p&&!It&&!vt.collapsed&&!nt.collapsed,uo=(g||It)&&!vt.collapsed,ra=y.useCallback(()=>{!g&&b&&b()},[b,g]);y.useEffect(()=>{Ee||jt(!1)},[Ee]);const[Us,Yl]=y.useState(null),[Gn,Ui]=y.useState(null),[Zt,hn]=y.useState(null),[is,Hh]=y.useState(null),Od=y.useRef(null),[_s,ho]=y.useState(null),[Pc,Lc]=y.useState(""),[ai,Vs]=y.useState(null),[Wh,na]=y.useState(""),[en,fo]=y.useState(null),[Ai,ia]=y.useState(null),$i=y.useRef(null),Xl=y.useRef(null),xl=y.useRef(null),po=y.useRef(null),$c=y.useRef(!1),mo=y.useCallback(()=>$c.current?($c.current=!1,!0):!1,[]),bl=y.useCallback(()=>{Xl.current!==null&&(window.clearTimeout(Xl.current),Xl.current=null),xl.current!==null&&(window.clearTimeout(xl.current),xl.current=null)},[]),[ss,fs]=y.useState(""),[qs,Rd]=y.useState("files"),[Bn,os]=y.useState(null),[ws,Dc]=y.useState(!1),ps=y.useRef(null),[At,Io]=y.useState(null),[_l,sg]=y.useState((P==null?void 0:P.trim())||""),[Zl,sp]=y.useState(""),[wl,Md]=y.useState(""),[Uh,Nu]=y.useState(null),[sy,op]=y.useState(null),[Ms,as]=y.useState(!1),[Dt,Jl]=y.useState(!1),[Yv,Vh]=y.useState(!1),[pi,qh]=y.useState("controls"),[Ps,Pd]=y.useState(null),[Ld,sa]=y.useState(""),[oa,og]=y.useState(!1),[Xv,ag]=y.useState(null),Bo=y.useRef(null),Tt=y.useRef(null),cn=y.useMemo(()=>Ct.find(G=>G.type==="preview")??null,[Ct]),go=y.useMemo(()=>(At==null?void 0:At.browserEvents.filter(G=>G.type==="console"))??[],[At]),za=y.useMemo(()=>(At==null?void 0:At.browserEvents.filter(G=>G.type==="pageerror"||G.type==="requestfailed"||G.type==="response"&&(G.status??0)>=400))??[],[At]),Vi=CYe(K),lg=y.useMemo(()=>{var G;return((G=At==null?void 0:At.remoteBrowser)==null?void 0:G.novncUrl)??(cn==null?void 0:cn.previewSrc)??Tk(At==null?void 0:At.url)??Tk(cn==null?void 0:cn.previewTarget)??null},[cn==null?void 0:cn.previewSrc,cn==null?void 0:cn.previewTarget,(Ga=At==null?void 0:At.remoteBrowser)==null?void 0:Ga.novncUrl,At==null?void 0:At.url]),oy=y.useRef(null),Gh=y.useRef(!1),aa=y.useRef(!1),Ic=y.useRef(""),$d=y.useRef(null),ap=y.useRef(null),Bc=y.useCallback((G,se=!1)=>{const ne=Ct.find(ae=>ae.type==="preview")??null,pe=G(ne);Xt(ae=>{const Pe=ae.findIndex(Ae=>Ae.type==="preview");if(!pe)return Pe<0?ae:ae.filter(Ae=>Ae.type!=="preview");if(Pe>=0){const Ae=ae[Pe];if(Ae.label===pe.label&&Ae.previewTarget===pe.previewTarget&&Ae.previewSrc===pe.previewSrc&&Ae.path===pe.path)return ae;const He=[...ae];return He[Pe]=pe,He}return[...ae,pe]}),se&&pe&&(bn(pe.id),Gt(null),$e(null),gt(null),Fe(pe.previewTarget??pe.path),ut("plaintext"),i(""))},[i,Ct]),Kh=y.useCallback(async G=>{if(Vi&&M)try{await fetch(`${Ta}/api/preview/stop`,{method:"POST",headers:Cb(M),body:JSON.stringify({sessionId:Vi})})}catch{}Io(null),as(!1),Jl(!1),Nu(null),G&&Bc(se=>se?{...se,label:se.previewTarget||"Preview",previewSrc:null,previewMode:null}:{id:"preview",type:"preview",path:"__preview__",label:"Preview",previewSrc:null,previewMode:null})},[Vi,M,Bc]),Dd=y.useCallback(async()=>{if(!Vi||!M)return null;try{const G=await fetch(`${Ta}/api/preview/session/${Vi}`,{headers:Cb(M)});if(!G.ok)return Io(null),null;const se=await G.json();return Io(ne=>kk(ne,se.session)?ne:se.session),se.session}catch{return null}},[Vi,M]),Gs=y.useCallback(async G=>{if(!Vi||!M)return null;og(!0),ag(null);try{const se=new URLSearchParams;G!=null&&G.trim()&&se.set("selector",G.trim());const ne=await fetch(`${Ta}/api/preview/inspect/${Vi}${se.size?`?${se.toString()}`:""}`,{headers:Cb(M)}),pe=await ne.json().catch(()=>({}));if(!ne.ok)throw new Error(pe.error||"Failed to inspect preview");if(pe.suppressed){const ae={status:(At==null?void 0:At.status)??"ready",url:(At==null?void 0:At.url)??null,page:null,snapshot:null,target:null,captureSuppressed:!0,suppressionReason:pe.reason};return Pd(ae),ae}return Pd(pe.inspect??null),pe.inspect??null}catch(se){return ag(se instanceof Error?se.message:"Failed to inspect preview"),null}finally{og(!1)}},[Vi,At==null?void 0:At.status,At==null?void 0:At.url,M]);y.useEffect(()=>{if(!nr)return;const G=Xe.current;if(!G)return;const se=G.querySelector(`[data-tab-id="${CSS.escape(nr)}"]`);if(!se)return;const{scrollLeft:ne,clientWidth:pe}=G,ae=se.offsetLeft,Pe=ae+se.offsetWidth;ae<ne?G.scrollLeft=ae:Pe>ne+pe&&(G.scrollLeft=Pe-pe)},[nr,Ct.length]),y.useEffect(()=>{const G=P==null?void 0:P.trim();G&&sg(G)},[P]),y.useEffect(()=>{Dd()},[Dd]),y.useEffect(()=>{if(Vi)return jYe(G=>{G.sessionId===Vi&&Io(se=>kk(se,G)?se:G)})},[Vi]),y.useEffect(()=>{var G;pi==="logs"&&((G=Bo.current)==null||G.scrollIntoView({behavior:"smooth"}))},[pi,At==null?void 0:At.logs.length]),y.useEffect(()=>{var G;pi==="console"&&((G=Tt.current)==null||G.scrollIntoView({behavior:"smooth"}))},[pi,go.length]),y.useEffect(()=>{pi==="inspect"&&(!cn&&!At||Gs(Ld))},[cn,Gs,At,Ld,pi]),y.useEffect(()=>{At&&Bc(G=>{var ne;if(!G)return G;const se=At.target??G.previewTarget;return{...G,label:tH(se??At.url),previewTarget:se,previewSrc:((ne=At.remoteBrowser)==null?void 0:ne.novncUrl)??Tk(At.url??se),previewMode:"managed"}})},[At,Bc]),y.useEffect(()=>{if(!le||!A||A.remoteRoot!==le||oy.current===le||(oy.current=le,aa.current=A.activePreview===!0,A.activePreview&&bn("preview"),A.tabs.length===0))return;let G=!1;return Gh.current=!0,(async()=>{var Pe;const ne=[];for(const Ae of A.tabs)try{const He=await Xu(Ae.path,u);if(G)return;ne.push({id:`file:${Ae.path}`,type:"file",path:Ae.path,label:Ae.label||(Ae.path.split("/").pop()??Ae.path),content:He,savedContent:He,language:ka(Ae.path)})}catch{}if(G||ne.length===0)return;Xt(Ae=>{const He=new Set(Ae.map(zt=>zt.id)),Bt=ne.filter(zt=>!He.has(zt.id));return Bt.length>0?[...Ae,...Bt]:Ae});const pe=A.activePath?`file:${A.activePath}`:null,ae=pe&&ne.some(Ae=>Ae.id===pe)?pe:((Pe=ne[ne.length-1])==null?void 0:Pe.id)??null;if(ae&&!A.activePreview){const Ae=ne.find(He=>He.id===ae);bn(ae),Ae&&($e(Ae.path),Fe(Ae.path),ut(Ae.language??"plaintext"),gt(Ae.content??null),i(""))}})().finally(()=>{Gh.current=!1}),()=>{G=!0,Gh.current=!1}},[le,A,u,i]),y.useEffect(()=>{if(!R||Gh.current||!E)return;const G=Ct.some(He=>He.type==="preview");if(aa.current){if(!G||nr!=="preview")return;aa.current=!1}if(!le){Ic.current!==""&&(Ic.current="",R(null));return}const se=Ct.filter(He=>He.type==="file"&&He.id.startsWith("file:")).map(He=>({path:He.path,label:He.label})),ne=Ee&&Ee.type==="file"&&Ee.id.startsWith("file:")?Ee.path:null,pe=Ct.find(He=>He.type==="preview")??null,ae=nr==="preview"&&!!rH(pe==null?void 0:pe.previewTarget),Pe={remoteRoot:le,tabs:se,activePath:ne,activePreview:ae},Ae=JSON.stringify(Pe);Ae!==Ic.current&&(Ic.current=Ae,R(Pe))},[Ct,Ee,nr,le,E,R]);const Fa=y.useRef("");y.useEffect(()=>{if(!B)return;const G=Ct.find(ae=>ae.type==="preview")??null,se=G!==null,ne=rH(G==null?void 0:G.previewTarget),pe=`${se}:${ne??""}`;pe!==Fa.current&&(Fa.current=pe,B({open:se,target:ne}))},[Ct,B]),y.useEffect(()=>{H&&H(Ct.some(G=>G.type==="architecture"))},[Ct,H]),y.useEffect(()=>{if(!Gn)return;const G=()=>Ui(null);return window.addEventListener("pointerdown",G),()=>window.removeEventListener("pointerdown",G)},[Gn]);const Jr=y.useCallback(async()=>{if(!le)return;const G=++pn.current;yt(!0);try{const[se,ne]=await Promise.all([tl.status(le),tl.fileDiffs(le).catch(()=>[])]);G===pn.current&&($t(se),Er(ne))}catch{G===pn.current&&($t(null),Er([]))}finally{G===pn.current&&yt(!1)}},[le]),li=y.useCallback(G=>{lr(G),!(typeof window>"u")&&window.localStorage.setItem(Ooe,G===!1?"false":G==="all"?"all":"true")},[]),rt=y.useCallback(G=>{li(G==="all"?"all":G==="true")},[li]);y.useEffect(()=>{sr.current=Wt},[Wt]),y.useEffect(()=>{Qr.current=Et},[Et]),y.useEffect(()=>{le&&Jr()},[le,j,Jr]);const Ql=y.useRef(N??0);y.useEffect(()=>{N!=null&&N!==Ql.current&&(Ql.current=N,le&&Jr())},[N,le,Jr]),y.useEffect(()=>{if(!le||pr===!1)return;let G=!1,se=null;const ne=async()=>{for(;!G;){const ae=typeof document<"u"&&document.visibilityState==="visible"&&document.hasFocus();if(!sr.current&&!Qr.current&&ae)return!0;await new Promise(Pe=>{se=window.setTimeout(Pe,1e3)})}return!1};return(async()=>{for(;!G;){if(!await ne()||G)return;try{await tl.fetch(le,pr==="all"),await Jr()}catch{}if(G)return;await new Promise(Pe=>{se=window.setTimeout(Pe,Wr*1e3)})}})(),()=>{G=!0,se!==null&&window.clearTimeout(se)}},[le,pr,Wr,Jr]);const zo=y.useRef(new Set);y.useEffect(()=>{if(!(C!=null&&C.length)){zo.current=new Set;return}const G=zo.current,se=C.filter(ne=>!G.has(ne));if(zo.current=new Set(C),se.length!==0){Ge();for(const ne of se){const pe=Ct.find(ae=>ae.type==="file"&&to(ae.path)===to(ne));pe&&Eu(pe.id,pe.path)}le&&Jr()}},[C]);const Tu=y.useRef(j??0);y.useEffect(()=>{if(j==null||j===Tu.current)return;Tu.current=j,(ne=>{for(const pe of ne)pe.kind==="dir"&&pe.children&&be.has(pe.path)&&(pe.children=null)})(Je),Ge(),(async()=>{const ne=[...be];for(const pe of ne){const ae=Ae=>{for(const He of Ae){if(He.kind==="dir"&&He.path===pe)return He;if(He.kind==="dir"&&He.children){const Bt=ae(He.children);if(Bt)return Bt}}return null},Pe=ae(Je);if(Pe&&Pe.children===null){const Ae=Pe.handle?await Ck(Pe.handle,Pe.path):await ru(Pe.path,u);Pe.children=Ae}}Ge()})().catch(()=>{}),ke&&le&&Xu(ke,u).then(ne=>{gt(ne),Xt(pe=>pe.map(ae=>ae.id!==`file:${ke}`||ae.isDirty?ae:{...ae,content:ne,savedContent:ne,saveError:null}))}).catch(()=>{})},[j]),y.useEffect(()=>{if(!ke||!le)return;const G=Ae=>Ae.replace(/\\/g,"/"),se=G(le).replace(/\/$/,""),ne=G(ke);if(!ne.startsWith(se+"/"))return;const pe=ne.slice(se.length+1).split("/");if(pe.length<2){requestAnimationFrame(()=>{const Ae=document.querySelector(`[data-tree-path="${CSS.escape(ke)}"]`);Ae==null||Ae.scrollIntoView({block:"nearest",behavior:"smooth"})});return}const ae=pe.slice(0,-1);let Pe=!1;return(async()=>{let Ae=se,He=Je;const Bt=[];for(const zt of ae){Ae=Ae+"/"+zt;const Jt=He.find(Sr=>Sr.kind==="dir"&&G(Sr.path)===Ae);if(!Jt)break;if(Bt.push(Jt.path),Jt.children===null){Jt.childrenLoading=!0,Ge();const Sr=await ru(Jt.path,u);if(Pe)return;Jt.children=Sr,Jt.childrenLoading=!1,Ge()}He=Jt.children}Pe||(Bt.length&&Re(zt=>{const Jt=new Set(zt);for(const Sr of Bt)Jt.add(Sr);return Jt}),requestAnimationFrame(()=>{const zt=document.querySelector(`[data-tree-path="${CSS.escape(ke)}"]`);zt==null||zt.scrollIntoView({block:"nearest",behavior:"smooth"})}))})(),()=>{Pe=!0}},[ke]);const Fo=y.useRef(null);y.useEffect(()=>{Fo.current=null},[ke]),y.useEffect(()=>{if(!ke||!le)return;const G=ke,se=u;let ne=!1;Fo.current||QF(G,se).then(ae=>{!ne&&ae&&(Fo.current=ae)});const pe=setInterval(async()=>{if(ne||typeof document<"u"&&document.hidden)return;const ae=await QF(G,se);if(!(ne||!ae))if(Fo.current&&ae!==Fo.current){Fo.current=ae,Ge();try{const Pe=await Xu(G,se);ne||(gt(Pe),Xt(Ae=>Ae.map(He=>He.id!==`file:${G}`||He.isDirty?He:{...He,content:Pe,savedContent:Pe,saveError:null})))}catch{}}else Fo.current||(Fo.current=ae)},2e3);return()=>{ne=!0,clearInterval(pe)}},[ke,le,u]),y.useEffect(()=>{if(!l)return;const G=[],se=ne=>{for(const pe of ne)pe.kind==="file"?G.push({path:pe.path,name:pe.name,kind:"file"}):pe.kind==="dir"&&(G.push({path:pe.path,name:pe.name,kind:"dir"}),pe.children&&se(pe.children))};se(Je);for(const ne of r)G.some(pe=>pe.path===ne.path)||G.push({path:ne.path,name:ne.name});l(G)},[Je,Yt,r,l]);const Yh=y.useMemo(()=>r.find(G=>G.id===n)??null,[r,n]),Sl=y.useCallback(G=>{const se=ne=>{for(const pe of ne){if(pe.kind==="file"&&pe.path===G)return pe;if(pe.kind==="dir"&&pe.children){const ae=se(pe.children);if(ae)return ae}}return null};return se(Je)},[Je]),zc=y.useCallback((G,se)=>{Xt(ne=>ne.map(pe=>pe.id===G?{...pe,content:se,modifiedContent:se,savedContent:se,isDirty:!1,isSaving:!1,saveError:null}:pe))},[]),lp=y.useCallback((G,se)=>{Xt(ne=>ne.map(pe=>pe.id===G?{...pe,originalContent:se,modifiedContent:pe.content??pe.modifiedContent??null}:pe))},[]),Eu=y.useCallback(async(G,se)=>{if(!u)return;const ne=await RYe(se,u).catch(()=>null);lp(G,ne)},[lp,u]),cg=y.useCallback((G,se)=>{Xt(ne=>ne.map(pe=>{if(pe.id!==G||!Nk(pe))return pe;const ae=se??"",Pe=pe.savedContent??"";return{...pe,content:ae,modifiedContent:ae,isDirty:ae!==Pe,saveError:null}})),nr===G&&ke&>(se??"")},[ke,nr]),cp=y.useCallback(async G=>{const se=Ct.find(pe=>pe.id===G);if(!se||!Nk(se))return;const ne=se.content??"";Xt(pe=>pe.map(ae=>ae.id===G?{...ae,isSaving:!0,saveError:null}:ae));try{if(le)await OYe(se.path,ne,u);else{const pe=Sl(se.path);if(!(pe!=null&&pe.handle))throw new Error("Local file handle is unavailable");const ae=await pe.handle.createWritable();await ae.write(ne),await ae.close()}Xt(pe=>pe.map(ae=>ae.id===G?{...ae,content:ne,savedContent:ne,isDirty:!1,isSaving:!1,saveError:null}:ae)),nr===G&>(ne),Ge(),le&&Jr()}catch(pe){const ae=pe instanceof Error?pe.message:"Failed to save file";Xt(Pe=>Pe.map(Ae=>Ae.id===G?{...Ae,isSaving:!1,saveError:ae}:Ae))}},[nr,Ge,Jr,Sl,Ct,le,u]);y.useEffect(()=>{const G=se=>{!(se.metaKey||se.ctrlKey)||se.key.toLowerCase()!=="s"||!In||!nr||(se.preventDefault(),cp(nr))};return window.addEventListener("keydown",G),()=>window.removeEventListener("keydown",G)},[In,nr,cp]);const Di=(Ee==null?void 0:Ee.type)==="file"?{path:Ee.path,language:Ee.language??"plaintext",content:Ee.content??""}:ke?{path:Ht??"",language:at,content:ct??""}:Yh?{path:Yh.path,language:Yh.language,content:Yh.content}:null,up=()=>c.jsxs("div",{className:"absolute inset-y-0 right-0 z-20 flex w-full max-w-[360px] flex-col border-l bg-background/95 shadow-2xl backdrop-blur",children:[c.jsxs("div",{className:"flex items-center gap-2 border-b px-3 py-2 shrink-0",children:[c.jsxs("div",{className:"min-w-0 flex-1 overflow-hidden",children:[c.jsxs("div",{className:"flex items-center gap-2 whitespace-nowrap overflow-hidden",children:[c.jsx(kN,{className:"h-4 w-4 text-muted-foreground shrink-0"}),c.jsx("span",{className:"text-sm font-medium truncate",children:"Preview Controls"}),At&&c.jsx("span",{className:"rounded bg-muted px-2 py-0.5 text-2xs uppercase tracking-wide text-muted-foreground",children:At.status})]}),cn!=null&&cn.label?c.jsx("div",{className:"truncate text-xs text-muted-foreground",title:cn.label,children:cn.label}):null]}),c.jsx("button",{type:"button",className:"rounded p-1.5 text-muted-foreground hover:bg-muted hover:text-foreground",onClick:()=>Vh(!1),title:"Hide preview controls",children:c.jsx(Jn,{className:"h-3.5 w-3.5"})})]}),c.jsx("div",{className:"flex items-center gap-1 border-b px-2 py-1.5 text-xs",children:["controls","inspect","logs","console","issues","metrics"].map(G=>c.jsx("button",{type:"button",className:`rounded px-2 py-1 transition-colors ${pi===G?"bg-muted text-foreground":"text-muted-foreground hover:text-foreground"}`,onClick:()=>qh(G),children:G==="controls"?"Controls":G==="inspect"?"Inspect":G==="logs"?"Logs":G==="console"?`Console${go.length?` (${go.length})`:""}`:G==="issues"?`Issues${za.length?` (${za.length})`:""}`:"Metrics"},G))}),pi==="controls"?c.jsxs("div",{className:"flex-1 space-y-3 overflow-auto p-3",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(Hn,{value:_l,onChange:G=>sg(G.target.value),placeholder:"Optional target override such as 3000 or http://127.0.0.1:3000/",className:"h-8"}),c.jsx(Hn,{value:Zl,onChange:G=>sp(G.target.value),placeholder:"Optional command override",className:"h-8",disabled:!I}),c.jsx(Hn,{value:wl,onChange:G=>Md(G.target.value),placeholder:"Preferred port",className:"h-8",disabled:!I}),c.jsxs(_e,{type:"button",size:"sm",className:"h-8 w-full",onClick:pp,disabled:Ms,children:[c.jsx(F4,{className:"mr-1 h-3 w-3"}),"Start Live Preview"]})]}),c.jsxs("div",{className:"flex flex-wrap gap-2",children:[c.jsxs(_e,{type:"button",variant:"ghost",size:"sm",className:"h-8 px-2 text-xs",onClick:jl,children:[c.jsx(Zo,{className:"mr-1 h-3 w-3"}),"Refresh"]}),At&&c.jsxs(c.Fragment,{children:[c.jsxs(_e,{type:"button",variant:"ghost",size:"sm",className:"h-8 px-2 text-xs",onClick:()=>{da()},disabled:Ms,children:[c.jsx(Zo,{className:"mr-1 h-3 w-3"}),"Restart"]}),c.jsxs(_e,{type:"button",variant:"ghost",size:"sm",className:"h-8 px-2 text-xs",onClick:()=>{Hd()},disabled:Ms,children:[c.jsx(U1,{className:"mr-1 h-3 w-3"}),"Stop"]})]}),Ho&&c.jsx("a",{href:Ho,target:"_blank",rel:"noreferrer",className:"inline-flex",children:c.jsxs(_e,{type:"button",variant:"ghost",size:"sm",className:"h-8 px-2 text-xs",children:[c.jsx(Uf,{className:"mr-1 h-3 w-3"}),"Open"]})})]}),I?c.jsxs("div",{className:"rounded border bg-muted/30 px-2 py-1.5 text-xs text-muted-foreground",children:["Workspace: ",c.jsx("code",{children:I})]}):null,At!=null&&At.remoteBrowser?c.jsxs("div",{className:"rounded border bg-muted/30 px-2 py-1.5 text-xs text-muted-foreground",children:["Live view: ",c.jsx("code",{children:At.remoteBrowser.novncUrl})]}):null,At!=null&&At.lastError?c.jsxs("div",{className:"flex items-start gap-2 rounded border border-destructive/30 bg-destructive/5 px-2 py-1.5 text-xs text-destructive",children:[c.jsx(Oa,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),c.jsx("span",{children:At.lastError})]}):null,Uh?c.jsxs("div",{className:"flex items-start gap-2 rounded border border-destructive/30 bg-destructive/5 px-2 py-1.5 text-xs text-destructive",children:[c.jsx(Oa,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),c.jsx("span",{children:Uh})]}):null,sy?c.jsxs("div",{className:"flex items-start gap-2 rounded border border-amber-500/30 bg-amber-500/5 px-2 py-1.5 text-xs text-amber-700",children:[c.jsx(Oa,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),c.jsx("span",{children:sy})]}):null]}):pi==="inspect"?c.jsxs("div",{className:"flex-1 space-y-3 overflow-auto p-3 text-xs",children:[c.jsxs("div",{className:"flex gap-2",children:[c.jsx(Hn,{value:Ld,onChange:G=>sa(G.target.value),placeholder:"Optional selector to diagnose",className:"h-8"}),c.jsxs(_e,{type:"button",variant:"ghost",size:"sm",className:"h-8 px-2 text-xs",onClick:()=>{Gs(Ld)},disabled:oa,children:[c.jsx(Vl,{className:"mr-1 h-3 w-3"}),"Diagnose"]})]}),c.jsx(kYe,{inspectState:Ps,loading:oa,error:Xv,onInsertElementReference:_})]}):pi==="logs"?c.jsxs("div",{className:"flex-1 overflow-auto bg-zinc-950 px-3 py-2 font-mono text-xs text-zinc-100",children:[At!=null&&At.logs.length?At.logs.map(G=>c.jsxs("div",{className:"mb-1 whitespace-pre-wrap break-words",children:[c.jsxs("span",{className:G.stream==="stderr"?"text-red-400":G.stream==="system"?"text-sky-300":"text-zinc-100",children:["[",G.stream,"]"]})," ",G.text]},G.id)):c.jsx("div",{className:"text-zinc-400",children:"No preview logs yet."}),c.jsx("div",{ref:Bo})]}):pi==="console"?c.jsxs("div",{className:"flex-1 overflow-auto bg-zinc-950 px-3 py-2 font-mono text-xs text-zinc-100",children:[go.length?go.map(G=>c.jsxs("div",{className:"mb-1 whitespace-pre-wrap break-words",children:[c.jsxs("span",{className:G.level==="error"?"text-red-400":G.level==="warning"||G.level==="warn"?"text-yellow-400":G.level==="info"?"text-sky-300":"text-zinc-300",children:["[",G.level??"log","]"]})," ",G.text]},G.id)):c.jsx("div",{className:"text-zinc-400",children:"No console messages yet."}),c.jsx("div",{ref:Tt})]}):pi==="metrics"?c.jsx("div",{className:"flex-1 overflow-auto p-3 text-xs",children:c.jsx(Aoe,{metrics:At==null?void 0:At.metrics})}):c.jsx("div",{className:"flex-1 overflow-auto p-3 text-xs",children:za.length?za.map(G=>c.jsxs("div",{className:"mb-2 rounded border bg-background px-2 py-1.5",children:[c.jsxs("div",{className:"font-medium",children:[G.type,G.status?` (${G.status})`:"",G.level?` · ${G.level}`:""]}),G.text?c.jsx("div",{className:"mt-0.5 whitespace-pre-wrap break-words text-muted-foreground",children:G.text}):null,G.url?c.jsxs("div",{className:"mt-0.5 break-all text-xs text-muted-foreground",children:[G.method?`${G.method} `:"",G.url]}):null]},G.id)):c.jsx("div",{className:"flex h-full items-center justify-center text-sm text-muted-foreground",children:"No browser issues captured yet."})})]}),ay=G=>c.jsxs("div",{className:"relative h-full bg-muted/5 overflow-hidden",children:[Dt&&c.jsx("div",{className:"absolute inset-x-0 top-0 z-10 h-1 overflow-hidden bg-transparent",children:c.jsx("div",{className:"h-full w-full animate-pulse bg-primary/80"})}),lg?c.jsx(fYe,{source:lg,title:(Ee==null?void 0:Ee.label)??"Live preview",className:"h-full w-full bg-white",onLoad:()=>Jl(!1)},`${lg}:${(Ee==null?void 0:Ee.version)??0}`):(At==null?void 0:At.status)==="starting"?c.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center text-sm text-muted-foreground",children:"Starting preview session…"}):(At==null?void 0:At.status)==="ready"?c.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 px-6 text-center text-sm text-muted-foreground",children:[c.jsx("p",{children:"Preview is running but the VNC viewer could not connect."}),c.jsxs("p",{className:"text-xs",children:["Check that Docker is running and the ",c.jsx("code",{children:"jait/sandbox-browser"})," image is available."]})]}):c.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center text-sm text-muted-foreground",children:G}),Yv&&up()]}),ly=y.useCallback(async G=>{let se=G;if(!se){if(typeof window>"u")return;const pe=window;if(!pe.showDirectoryPicker){window.alert("Directory picker is not supported in this browser.");return}try{se=await pe.showDirectoryPicker()}catch{return}}const ne=await Ck(se,"");ge.current=se,et(null),Ot(ne),Re(new Set),$e(null),gt(null)},[]),dp=y.useCallback(async G=>{try{const se=await ru(G,u);ge.current=null,et(G),Ot(se),Re(new Set),$e(null),gt(null)}catch(se){console.error("Failed to open remote workspace:",se)}},[u]);y.useEffect(()=>{if(!d){le&&et(null);return}le===d&&Je.length>0||dp(d)},[d,dp,Je.length]);const hp=y.useCallback(async G=>{const se=Ae=>{for(const He of Ae){if(He.kind==="file"&&He.path===G)return He;if(He.kind==="dir"&&He.children){const Bt=se(He.children);if(Bt)return Bt}}return null},ne=se(Je);if(ne)try{const Ae=ne.handle?await t1(ne.handle):await Xu(ne.path,u);return{id:ne.path,name:ne.name,path:ne.path,content:Ae,language:ka(ne.path)}}catch{return null}if(le)try{const Ae=await Xu(G,u),He=G.split("/").pop()??G;return{id:G,name:He,path:G,content:Ae,language:ka(G)}}catch{return null}const pe=ge.current;if(!pe)return null;const ae=G.split("/");let Pe=pe;try{for(let zt=0;zt<ae.length-1;zt++)Pe=await Pe.getDirectoryHandle(ae[zt]);const Ae=await Pe.getFileHandle(ae[ae.length-1]),He=await t1(Ae),Bt=ae[ae.length-1];return{id:G,name:Bt,path:G,content:He,language:ka(G)}}catch{return null}},[Je,le,u]),mn=y.useCallback(async G=>{const se=to(G),ne=[],pe=async(Sr,Dr)=>{try{const Ci=Dr?await t1(Dr):await Xu(Sr,u);return{id:Sr,name:Sr.split("/").pop()??Sr,path:Sr,content:Ci,language:ka(Sr)}}catch{return null}},ae=async(Sr,Dr)=>{for await(const Ci of Sr.values()){if(ne.length>=ZF)return;const Ys=Ci.name,oc=Dr?`${Dr}/${Ys}`:Ys;if(Ci.kind==="directory"){if(L_.has(Ys))continue;await ae(Ci,oc);continue}const Gc=await pe(oc,Ci);Gc&&ne.push(Gc)}},Pe=async Sr=>{const Dr=await ru(Sr,u);for(const Ci of Dr){if(ne.length>=ZF)return;if(Ci.kind==="dir"){await Pe(Ci.path);continue}const Ys=await pe(Ci.path);Ys&&ne.push(Ys)}},Ae=Sr=>{for(const Dr of Sr){if(to(Dr.path)===se)return Dr;if(Dr.kind==="dir"&&Dr.children){const Ci=Ae(Dr.children);if(Ci)return Ci}}return null},He=Ae(Je);if((He==null?void 0:He.kind)==="file"){const Sr=await pe(He.path,He.handle);return Sr?[Sr]:[]}if((He==null?void 0:He.kind)==="dir")return He.handle?await ae(He.handle,He.path):await Pe(He.path),ne;const Bt=await hp(se);if(Bt)return[Bt];if(le){try{await Pe(se)}catch{return[]}return ne}const zt=ge.current;if(!zt)return[];const Jt=se.split("/").filter(Boolean);try{let Sr=zt;for(const Dr of Jt)Sr=await Sr.getDirectoryHandle(Dr);return await ae(Sr,se),ne}catch{return[]}},[hp,Je,le,u]),Ss=y.useCallback(async(G,se,ne)=>{if(!G)return[];const pe=[],ae=G.toLowerCase(),Pe=He=>{for(const Bt of He){if(ne!=null&&ne.aborted||pe.length>=se)return;Bt.name.toLowerCase().includes(ae)&&pe.push({path:Bt.path,name:Bt.name,kind:Bt.kind==="dir"?"dir":"file"}),Bt.kind==="dir"&&Bt.children&&Pe(Bt.children)}};if(Pe(Je),pe.length>=se||ne!=null&&ne.aborted)return pe;const Ae=ge.current;if(Ae&&!le){const He=async(Bt,zt)=>{if(ne!=null&&ne.aborted)return!0;try{for await(const Jt of Bt.values()){if(ne!=null&&ne.aborted||pe.length>=se)return!0;const Sr=Jt.name,Dr=zt?`${zt}/${Sr}`:Sr;if(Jt.kind==="directory"){if(L_.has(Sr))continue;if(Sr.toLowerCase().includes(ae)&&!pe.some(Ys=>Ys.path===Dr)&&(pe.push({path:Dr,name:Sr,kind:"dir"}),pe.length>=se)||await He(Jt,Dr))return!0}else if(Sr.toLowerCase().includes(ae)&&!pe.some(Ci=>Ci.path===Dr)&&(pe.push({path:Dr,name:Sr,kind:"file"}),pe.length>=se))return!0}}catch{}return!1};await He(Ae,"")}return pe},[Je,le]),ec=y.useCallback(async(G,se,ne)=>{if(!G.trim())return[];const pe=ge.current;return!pe||le?[]:xYe(pe,G,se,ne,L_)},[le]),kl=y.useCallback(async G=>{const se=to(G);ra();const ne=le?to(le):null,pe=ne&&(se===ne||se.startsWith(`${ne}/`))?se.slice(ne.length).replace(/^\/+/,"").split("/").filter(Boolean):se.split("/").filter(Boolean);if(pe.length===0)return!1;let ae=Je,Pe=ne??"";const Ae=[];for(const zt of pe.slice(0,-1)){Pe=Pe?`${Pe}/${zt}`:zt;const Jt=ae.find(Sr=>Sr.kind==="dir"&&to(Sr.path)===Pe);if(!Jt)return!1;Jt.children===null&&(Jt.childrenLoading=!0,Ge(),Jt.children=Jt.handle?await Ck(Jt.handle,Jt.path):await ru(Jt.path,u),Jt.childrenLoading=!1,Ge()),Ae.push(Pe),ae=Jt.children??[]}Ae.length>0&&Re(zt=>{const Jt=new Set(zt);for(const Sr of Ae)Jt.add(Sr);return Jt});const He=ae.find(zt=>zt.kind==="file"&&to(zt.path)===se);if(!He)return!1;const Bt=`file:${He.path}`;Xt(zt=>{if(zt.find(Dr=>Dr.id===Bt))return zt;const Sr={id:Bt,type:"file",path:He.path,label:He.name,content:null,savedContent:null,language:ka(He.path)};return[...zt,Sr]}),bn(Bt),i(""),$e(He.path),Fe(He.path),ut(ka(He.path)),Pt(!0);try{const zt=He.handle?await t1(He.handle):await Xu(He.path,u);gt(zt),zc(Bt,zt),Eu(Bt,He.path)}catch{gt("// Failed to read file"),zc(Bt,"// Failed to read file")}return Pt(!1),!0},[Ge,ra,Je,Eu,i,le,zc,u]),fp=y.useCallback(async G=>{if(be.has(G.path)){Re(ne=>{const pe=new Set(ne);return pe.delete(G.path),pe});return}if(G.children===null){G.childrenLoading=!0,Ge();const ne=G.handle?await Ck(G.handle,G.path):await ru(G.path,u);G.children=ne,G.childrenLoading=!1,Ge()}Re(ne=>{const pe=new Set(ne);return pe.add(G.path),pe})},[be,Ge,u]),Xh=y.useCallback(G=>{mo()||fp(G)},[mo,fp]),la=y.useCallback(async G=>{ra();const se=`file:${G.path}`;Xt(ne=>{if(ne.find(Pe=>Pe.id===se))return ne;const ae={id:se,type:"file",path:G.path,label:G.name,content:null,savedContent:null,language:ka(G.path)};return[...ne,ae]}),bn(se),i(""),$e(G.path),Fe(G.path),ut(ka(G.path)),Pt(!0);try{const ne=G.handle?await t1(G.handle):await Xu(G.path,u);gt(ne),zc(se,ne),Eu(se,G.path)}catch{gt("// Failed to read file"),zc(se,"// Failed to read file")}Pt(!1)},[ra,Eu,i,zc,u]),Fc=y.useCallback(G=>{mo()||la(G)},[mo,la]),Zh=y.useCallback(async G=>{if(G.kind==="dir"){o({id:G.path,name:G.name.endsWith("/")?G.name:`${G.name}/`,path:G.path,content:"",language:"plaintext"});return}try{const se=G.handle?await t1(G.handle):await Xu(G.path,u);o({id:G.path,name:G.name,path:G.path,content:se,language:ka(G.path)})}catch{}},[o,u]),ca=y.useCallback((G,se,ne)=>{Hh(null),hn({node:G,x:se,y:ne})},[]);y.useLayoutEffect(()=>{if(!Zt){Hh(null);return}const G=()=>{const se=Od.current;if(!se)return;const ne=se.getBoundingClientRect(),pe=8,ae=Math.max(pe,Math.min(Zt.x,window.innerWidth-ne.width-pe)),Pe=Math.max(pe,Math.min(Zt.y,window.innerHeight-ne.height-pe));Hh(Ae=>Ae&&Ae.left===ae&&Ae.top===Pe?Ae:{left:ae,top:Pe})};return G(),window.addEventListener("resize",G),()=>window.removeEventListener("resize",G)},[Zt]),y.useEffect(()=>{if(!Zt)return;const G=()=>hn(null);return window.addEventListener("pointerdown",G),()=>window.removeEventListener("pointerdown",G)},[Zt]);const Id=y.useCallback(async(G,se)=>{if(!le)return;const ne=to(G),pe=to(se),ae=to(le);if(!(!ne||!pe||ne===pe)&&!JF(ne,pe))try{if(!(await fetch(`${Ta}/api/workspace/move`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({srcPath:ne,destDir:pe,surfaceId:u})})).ok)throw new Error("Move failed");const Ae=(Jt,Sr)=>{for(const Dr of Jt){if(Dr.kind==="dir"&&Dr.path===Sr)return Dr;if(Dr.kind==="dir"&&Dr.children){const Ci=Ae(Dr.children,Sr);if(Ci)return Ci}}return null},He=pe===ae?null:Ae(Je,pe);He&&(He.children=null,be.has(He.path)&&(He.children=await ru(He.path,u)));const Bt=ne.includes("/")?ne.slice(0,ne.lastIndexOf("/")):ae,zt=Bt===ae?null:Ae(Je,Bt);zt&&(zt.children=null,be.has(zt.path)&&(zt.children=await ru(zt.path,u))),(Bt===ae||pe===ae)&&Ot(await ru(le,u)),Ge(),Jr()}catch{}},[le,u,Je,be,Ge,Jr]),Bd=y.useCallback((G,se)=>{var Pe,Ae;if(!f||!le||se.pointerType==="mouse")return;const ne=se.target;if(ne!=null&&ne.closest("button"))return;bl(),(Ae=(Pe=se.currentTarget).setPointerCapture)==null||Ae.call(Pe,se.pointerId),po.current=se.currentTarget;const pe=se.currentTarget.getBoundingClientRect(),ae={node:G,pointerId:se.pointerId,startX:se.clientX,startY:se.clientY,x:se.clientX,y:se.clientY,ready:!1,active:!1,dropDir:null};$i.current=ae,ia(ae),Xl.current=window.setTimeout(()=>{ia(He=>{if(!He||He.pointerId!==se.pointerId)return He;const Bt={...He,ready:!0};return $i.current=Bt,Bt}),Xl.current=null},180),xl.current=window.setTimeout(()=>{const He=$i.current;!He||He.pointerId!==se.pointerId||He.active||($c.current=!0,bl(),Ek(po.current,se.pointerId),po.current=null,$i.current=null,ia(null),ca(G,pe.right-8,pe.top+12))},350)},[bl,ca,f,le]);y.useEffect(()=>{if(!Ai||!le)return;const G=(Pe,Ae)=>{var Jt;const He=document.elementFromPoint(Pe,Ae),Bt=He==null?void 0:He.closest("[data-tree-drop-dir], [data-tree-drop-root]");let zt=null;return(Bt==null?void 0:Bt.dataset.treeDropRoot)==="true"?zt=le:Bt!=null&&Bt.dataset.treeDropDir&&(zt=Bt.dataset.treeDropDir),zt&&JF(((Jt=$i.current)==null?void 0:Jt.node.path)??"",zt)&&(zt=null),zt},se=Pe=>{const Ae=$i.current;if(!Ae||Pe.pointerId!==Ae.pointerId)return;const He=Pe.clientX-Ae.startX,Bt=Pe.clientY-Ae.startY,zt=Math.hypot(He,Bt);if(!Ae.ready){zt>12&&(bl(),Ek(po.current,Pe.pointerId),po.current=null,$i.current=null,ia(null));return}const Jt=Ae.active||zt>=10;Jt&&xl.current!==null&&(window.clearTimeout(xl.current),xl.current=null);const Sr=Jt?G(Pe.clientX,Pe.clientY):null;Jt&&Pe.cancelable&&Pe.preventDefault();const Dr={...Ae,x:Pe.clientX,y:Pe.clientY,active:Jt,dropDir:Sr};$i.current=Dr,ia(Dr)},ne=Pe=>{const Ae=$i.current;!Ae||Ae.pointerId!==Pe||(bl(),Ek(po.current,Pe),po.current=null,Ae.active&&($c.current=!0,Ae.dropDir&&Id(Ae.node.path,Ae.dropDir)),$i.current=null,ia(null))},pe=Pe=>ne(Pe.pointerId),ae=Pe=>ne(Pe.pointerId);return window.addEventListener("pointermove",se,{passive:!1}),window.addEventListener("pointerup",pe),window.addEventListener("pointercancel",ae),()=>{var Ae;bl();const Pe=(Ae=$i.current)==null?void 0:Ae.pointerId;Pe!=null&&Ek(po.current,Pe),po.current=null,window.removeEventListener("pointermove",se),window.removeEventListener("pointerup",pe),window.removeEventListener("pointercancel",ae)}},[bl,Ai,le,Id]);const Jh=y.useCallback(async G=>{if(!(!le||!await fe({title:G.kind==="dir"?"Delete folder":"Delete file",description:`Delete "${G.name}"${G.kind==="dir"?" and all its contents":""}?`,confirmLabel:"Delete",variant:"destructive"})))try{if(await fetch(`${Ta}/api/workspace/delete`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:G.path,isDirectory:G.kind==="dir",surfaceId:u})}),G.kind==="file"){const ae=`file:${G.path}`;Xt(Pe=>Pe.filter(Ae=>Ae.id!==ae))}Ge();const ne=G.path.includes("/")?G.path.slice(0,G.path.lastIndexOf("/")):le,pe=ae=>{for(const Pe of ae){if(Pe.kind==="dir"&&Pe.path===ne)return Pe.children=null,!0;if(Pe.kind==="dir"&&Pe.children&&pe(Pe.children))return!0}return!1};pe(Je)||Ot(await ru(le,u)),Ge(),Jr()}catch{}},[fe,le,u,Ge,Je,Jr]),ua=y.useCallback(async()=>{if(!le||!_s||!Pc.trim()){ho(null);return}const G=Pc.trim();if(G===_s.name){ho(null);return}try{if(!(await fetch(`${Ta}/api/workspace/rename`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:_s.path,newName:G,surfaceId:u})})).ok)throw new Error("Rename failed");const ne=`file:${_s.path}`;Xt(Pe=>Pe.filter(Ae=>Ae.id!==ne));const pe=_s.path.includes("/")?_s.path.slice(0,_s.path.lastIndexOf("/")):le,ae=Pe=>{for(const Ae of Pe){if(Ae.kind==="dir"&&Ae.path===pe)return Ae.children=null,!0;if(Ae.kind==="dir"&&Ae.children&&ae(Ae.children))return!0}return!1};ae(Je)||Ot(await ru(le,u)),Ge(),Jr()}catch{}ho(null)},[le,_s,Pc,u,Ge,Je,Jr]),mi=y.useCallback(async()=>{if(!le||!ai||!Wh.trim()){Vs(null);return}const G=Wh.trim(),se=`${ai.parentDir}/${G}`;try{const ne=ai.kind==="dir"?"create-directory":"create-file";if(!(await fetch(`${Ta}/api/workspace/${ne}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:se,surfaceId:u})})).ok)throw new Error("Create failed");const ae=ai.parentDir,Pe=Ae=>{for(const He of Ae){if(He.kind==="dir"&&He.path===ae)return He.children=null,!0;if(He.kind==="dir"&&He.children&&Pe(He.children))return!0}return!1};Pe(Je)||Ot(await ru(le,u)),Ge(),Re(Ae=>{const He=new Set(Ae);return He.add(ae),He}),Jr()}catch{}Vs(null)},[le,ai,Wh,u,Ge,Je,Jr]),yo=y.useCallback(async(G,se)=>{var ne;if((ne=ps.current)==null||ne.abort(),!G.trim()){os(null),Dc(!1);return}if(le){const pe=new AbortController;ps.current=pe,Dc(!0);try{let ae=`${Ta}/api/workspace/search?query=${encodeURIComponent(G)}&mode=${se}&limit=50`;u&&(ae+=`&surfaceId=${encodeURIComponent(u)}`);const Pe=await fetch(ae,{signal:pe.signal});if(!Pe.ok)throw new Error("Search failed");const Ae=await Pe.json();pe.signal.aborted||os(Ae)}catch(ae){(ae==null?void 0:ae.name)!=="AbortError"&&os(se==="content"?{matches:[]}:{files:[]})}finally{pe.signal.aborted||Dc(!1)}}else if(se==="files"){Dc(!0);const pe=new AbortController;ps.current=pe;try{const ae=await Ss(G,50,pe.signal);pe.signal.aborted||os({files:ae})}catch{}pe.signal.aborted||Dc(!1)}else{Dc(!0);const pe=new AbortController;ps.current=pe;try{const ae=await ec(G,50,pe.signal);pe.signal.aborted||os({matches:ae})}catch{}pe.signal.aborted||Dc(!1)}},[le,u,Ss,ec]),Ha=y.useRef(null);y.useEffect(()=>(Ha.current&&clearTimeout(Ha.current),Ha.current=setTimeout(()=>{yo(ss,qs)},250),()=>{Ha.current&&clearTimeout(Ha.current)}),[ss,qs,yo]);const Cl=y.useCallback(G=>{navigator.clipboard.writeText(G.path)},[]),tc=y.useCallback(G=>{if(!le)return void navigator.clipboard.writeText(G.path);const se=G.path.replace(/\\/g,"/").replace(le.replace(/\\/g,"/"),"").replace(/^\/+/,"");navigator.clipboard.writeText(se)},[le]),zd=y.useCallback(async G=>{if(!le)return;const se=`git-diff:${G}`;Do(!0);try{const ne=to(G),pe=to(le),ae=ne===pe?"":ne.startsWith(`${pe}/`)?ne.slice(pe.length+1):ne,Pe=Bt=>Bt.find(zt=>{const Jt=to(zt.path);return Jt===ne||Jt===ae||ne.endsWith(`/${Jt}`)||Jt.endsWith(`/${ae}`)});let Ae=Pe(mr);if(!Ae){const Bt=await tl.fileDiffs(le).catch(()=>[]);Bt.length>0&&(Er(Bt),Ae=Pe(Bt))}const He=(Bt,zt)=>{Gt(zt),Xt(Jt=>{const Sr=Jt.findIndex(Ys=>Ys.id===se);if(Sr===-1)return[...Jt,Bt];const Dr=Jt[Sr],Ci=[...Jt];return Ci[Sr]={...Dr,...Bt,version:(Dr.version??0)+1},Ci}),bn(se),$e(null),gt(null),Fe(Bt.path),ut(Bt.language??"plaintext"),!g&&b&&b()};if(Ae){const Bt=G.split("/").pop()??G,zt={id:se,type:"diff",path:G,label:Bt,diffMode:"git",language:ka(G),originalContent:Ae.original,modifiedContent:Ae.modified,diffEntry:Ae};He(zt,Ae)}else{const Bt=ae?`${pe}/${ae}`:ne;let zt="";try{zt=await Xu(Bt,u)}catch{try{zt=await Xu(ne,u)}catch{zt=""}}const Jt=G.split("/").pop()??G,Sr={id:se,type:"diff",path:Bt,label:Jt,diffMode:"git",language:ka(G),originalContent:zt,modifiedContent:zt};He(Sr,null)}}catch{}Do(!1)},[b,le,g,u,mr]),Au=y.useCallback(async({path:G,originalContent:se,modifiedContent:ne,language:pe})=>{const ae=`review-diff:${G}`,Pe=G.split(/[\\/]/).pop()??G,Ae={id:ae,type:"diff",path:G,label:Pe,version:1,diffMode:"review",language:pe??ka(G),originalContent:se,modifiedContent:ne};return Xt(He=>He.find(zt=>zt.id===ae)?He.map(zt=>zt.id===ae?{...zt,...Ae,version:(zt.version??0)+1}:zt):[...He,Ae]),bn(ae),Gt(null),$e(null),gt(null),Fe(G),ut(pe??ka(G)),!0},[]),qi=y.useCallback(G=>{var ne;const se=(G==null?void 0:G.trim())??"";if(At){const pe=((ne=At.target)==null?void 0:ne.trim())??"";se&&pe&&se===pe||Kh(!1)}return sg(se||_l),Nu(null),op(null),Jl(!1),qh("controls"),Bc(pe=>({id:"preview",type:"preview",path:se||"__preview__",label:tH(se),previewTarget:se||void 0,previewSrc:(pe==null?void 0:pe.previewSrc)??Tk(se),previewMode:null}),!0),!0},[At,_l,Kh,Bc]),ks=y.useCallback(()=>{const G="architecture",se={id:G,type:"architecture",path:"__architecture__",label:"Architecture"};Xt(ne=>ne.find(ae=>ae.id===G)?ne.map(ae=>ae.id===G?{...ae,...se}:ae):[...ne,se]),bn(G),Gt(null),$e(null),gt(null),Fe("__architecture__"),ut("plaintext"),i("")},[i]),Fd=y.useCallback(()=>{Xt(G=>{const se=G.findIndex(ae=>ae.type==="architecture");if(se<0)return G;const ne=G[se],pe=G.filter(ae=>ae.id!==(ne==null?void 0:ne.id));if((ne==null?void 0:ne.id)===nr){const ae=pe[Math.min(se,pe.length-1)],Pe=(ae==null?void 0:ae.id)??null;setTimeout(()=>{bn(Pe),Pe?(ae==null?void 0:ae.type)==="file"?($e(ae.path),gt(ae.content??null),ut(ae.language??"plaintext"),Fe(ae.path),Gt(null)):(ae==null?void 0:ae.type)==="preview"?($e(null),gt(null),ut("plaintext"),Fe(ae.previewTarget??ae.path),Gt(null)):(ae==null?void 0:ae.type)==="architecture"?($e(null),gt(null),ut("plaintext"),Fe("__architecture__"),Gt(null)):(ae==null?void 0:ae.type)==="diff"&&Gt(ae.diffMode==="git"?ae.diffEntry??null:null):($e(null),gt(null),Gt(null))},0)}return pe})},[nr]),cy=y.useCallback(()=>{Vh(!1),Xt(G=>{const se=G.findIndex(ae=>ae.type==="preview");if(se<0)return G;const ne=G[se],pe=G.filter(ae=>ae.id!==(ne==null?void 0:ne.id));if((ne==null?void 0:ne.id)===nr){const ae=pe[Math.min(se,pe.length-1)],Pe=(ae==null?void 0:ae.id)??null;setTimeout(()=>{bn(Pe),Pe?(ae==null?void 0:ae.type)==="file"?($e(ae.path),gt(ae.content??null),ut(ae.language??"plaintext"),Fe(ae.path),Gt(null)):(ae==null?void 0:ae.type)==="preview"?($e(null),gt(null),ut("plaintext"),Fe(ae.previewTarget??ae.path),Gt(null)):(ae==null?void 0:ae.type)==="architecture"?($e(null),gt(null),ut("plaintext"),Fe("__architecture__"),Gt(null)):(ae==null?void 0:ae.type)==="diff"&&Gt(ae.diffMode==="git"?ae.diffEntry??null:null):($e(null),gt(null),Gt(null))},0)}return pe}),B==null||B({open:!1,target:null})},[nr,B]),jl=y.useCallback(()=>{Jl(!0),Dd(),Xt(G=>G.map(se=>se.type==="preview"?{...se,version:(se.version??0)+1}:se))},[Dd]),Wa=y.useCallback(async({target:G,command:se,port:ne,resetTab:pe=!0})=>{if(!Vi||!M){Nu("Login is required to start a live preview session.");return}as(!0),Nu(null),op(null),Jl(!0),pe&&qi(null);try{const ae=await fetch(`${Ta}/api/preview/start`,{method:"POST",headers:Cb(M),body:JSON.stringify({sessionId:Vi,workspaceRoot:I,target:(G==null?void 0:G.trim())||null,command:(se==null?void 0:se.trim())||null,port:typeof ne=="number"?ne:null})}),Pe=await ae.json().catch(()=>({}));if(!ae.ok||!Pe.session)throw new Error(Pe.error||"Failed to start preview");Io(Ae=>kk(Ae,Pe.session??null)?Ae:Pe.session??null),qh("controls")}catch(ae){Nu(ae instanceof Error?ae.message:"Failed to start preview"),Jl(!1)}finally{as(!1)}},[Vi,qi,M,I]),pp=y.useCallback(()=>{const G=_l.trim();Wa({target:G||null,command:Zl.trim()||null,port:wl.trim()?Number.parseInt(wl.trim(),10):null})},[Zl,_l,wl,Wa]),da=y.useCallback(async()=>{if(!(!Vi||!M)){as(!0),Nu(null),Jl(!0);try{const G=await fetch(`${Ta}/api/preview/restart`,{method:"POST",headers:Cb(M),body:JSON.stringify({sessionId:Vi})}),se=await G.json().catch(()=>({}));if(!G.ok||!se.session)throw new Error(se.error||"Failed to restart preview");Io(ne=>kk(ne,se.session??null)?ne:se.session??null)}catch(G){Nu(G instanceof Error?G.message:"Failed to restart preview"),Jl(!1)}finally{as(!1)}}},[Vi,M]),Hd=y.useCallback(async()=>{as(!0),await Kh(!0)},[Kh]),Ho=((ya=At==null?void 0:At.remoteBrowser)==null?void 0:ya.novncUrl)??(At==null?void 0:At.url)??(cn==null?void 0:cn.previewTarget)??null;y.useImperativeHandle(ue,()=>({openDirectory:ly,openRemoteWorkspace:dp,openFileByPath:kl,readFileByPath:hp,readReferencePath:mn,openReviewDiff:Au,openPreviewTarget:qi,closePreviewTarget:cy,refreshPreviewTarget:jl,openArchitectureTab:ks,closeArchitectureTab:Fd,searchFiles:Ss}),[ly,dp,kl,hp,mn,Au,qi,cy,jl,ks,Fd,Ss]),y.useEffect(()=>{var pe,ae;if(!W||$d.current===W.key)return;$d.current=W.key,qi(W.target);const G=((pe=W.target)==null?void 0:pe.trim())||"";if(!G||!Vi||!M)return;const se=((ae=At==null?void 0:At.target)==null?void 0:ae.trim())||"",ne=At==null?void 0:At.status;se===G&&(ne==="starting"||ne==="ready")||Wa({target:G,resetTab:!1})},[Vi,qi,At==null?void 0:At.status,At==null?void 0:At.target,W,M,Wa]),y.useEffect(()=>{Y&&ap.current!==Y.key&&(ap.current=Y.key,ks())},[Y,ks]);const Ua=y.useCallback(async G=>{if(!(!le||Wt)){Ce(!0),Nt(null);try{await tl.runStackedAction(le,G,{commitMessage:or.trim()||void 0}),xe(""),Gt(null),Xt(se=>se.filter(pe=>pe.type!=="diff")),bn(se=>{var pe;const ne=Ct.filter(ae=>ae.type!=="diff");return se&&ne.some(ae=>ae.id===se)?se:((pe=ne[ne.length-1])==null?void 0:pe.id)??null}),await Jr()}catch(se){Nt(se instanceof Error?se.message:"Git action failed")}Ce(!1)}},[le,Wt,or,Jr,Ct]),mp=y.useCallback(async()=>{if(!(!le||Wt)){Ce(!0),Nt(null);try{await tl.pull(le),await Jr(),Ge()}catch(G){Nt(G instanceof Error?G.message:"Pull failed")}Ce(!1)}},[le,Wt,Jr,Ge]),ha=y.useCallback(async()=>{if(!(!le||Wt)){Ce(!0),Nt(null);try{await tl.sync(le),await Jr(),Ge()}catch(G){Nt(G instanceof Error?G.message:"Sync failed")}Ce(!1)}},[le,Wt,Jr,Ge]),Ou=y.useCallback(async()=>{const G=new Set([...(Se==null?void 0:Se.index.files.map(se=>se.path))??[],...(Se==null?void 0:Se.workingTree.files.map(se=>se.path))??[]]).size;if(!(!le||Wt||G===0)){Ce(!0),Nt(null);try{await tl.discard(le),fo(null),Gt(null),Xt(se=>se.filter(ne=>ne.type!=="diff")),await Jr(),Ge()}catch(se){Nt(se instanceof Error?se.message:"Discard failed")}Ce(!1)}},[le,Wt,Se,Jr,Ge]),Wd=y.useCallback(async G=>{if(!(!le||Wt)){Ce(!0),Nt(null);try{await tl.discard(le,[G]),fo(null);const se=`git-diff:${G}`;Xt(ne=>ne.filter(pe=>pe.id!==se)),(Or==null?void 0:Or.path)===G&&Gt(null),await Jr(),Ge()}catch(se){Nt(se instanceof Error?se.message:"Discard failed")}Ce(!1)}},[le,Wt,Or,Jr,Ge]),Hc=y.useCallback(async G=>{if(!le||Wt||G.length===0)return;const se=[...new Set(G)];Ce(!0),Nt(null);try{await tl.discard(le,se),fo(null),Xt(ne=>ne.filter(pe=>pe.type!=="diff"||!se.includes(pe.path))),Or!=null&&Or.path&&se.includes(Or.path)&&Gt(null),await Jr(),Ge()}catch(ne){Nt(ne instanceof Error?ne.message:"Discard failed")}Ce(!1)},[le,Wt,Or,Jr,Ge]),Nl=y.useCallback(async G=>{if(!(!le||Wt||G.length===0))try{await tl.stage(le,[...new Set(G)]),await Jr()}catch{}},[le,Wt,Jr]),Ru=y.useCallback(async G=>{await Nl([G])},[Nl]),rc=y.useCallback(async G=>{if(!(!le||Wt||G.length===0))try{await tl.unstage(le,[...new Set(G)]),await Jr()}catch{}},[le,Wt,Jr]),uy=y.useCallback(async G=>{await rc([G])},[rc]),vo=y.useCallback(async()=>{if(!(!le||Wt||((Se==null?void 0:Se.workingTree.files.length)??0)===0))try{await tl.stage(le),await Jr()}catch{}},[le,Wt,Se,Jr]),nc=y.useCallback(async()=>{if(!(!le||Wt||((Se==null?void 0:Se.index.files.length)??0)===0))try{await tl.unstage(le),await Jr()}catch{}},[le,Wt,Se,Jr]),fa=y.useCallback(G=>{const se=r.find(pe=>pe.id===G);if(!se)return;ra();const ne=`ext:${G}`;Xt(pe=>{if(pe.find(Ae=>Ae.id===ne))return pe;const Pe={id:ne,type:"file",path:se.path,label:se.name,content:se.content,savedContent:se.content,language:se.language};return[...pe,Pe]}),bn(ne),$e(null),gt(null),i(G)},[ra,i,r]),xo=y.useCallback((G,se)=>{const ne=Ct.find(pe=>pe.id===G)??null;(ne==null?void 0:ne.type)==="preview"&&!(se!=null&&se.preserveManagedPreview)&&Vh(!1),Xt(pe=>{const ae=pe.findIndex(Ae=>Ae.id===G);if(ae<0)return pe;const Pe=pe.filter(Ae=>Ae.id!==G);if(G===nr){const Ae=Pe[Math.min(ae,Pe.length-1)],He=(Ae==null?void 0:Ae.id)??null;setTimeout(()=>{bn(He),He?(Ae==null?void 0:Ae.type)==="file"?($e(Ae.path),gt(Ae.content??null),ut(Ae.language??"plaintext"),Fe(Ae.path),Gt(null)):(Ae==null?void 0:Ae.type)==="preview"?($e(null),gt(null),ut("plaintext"),Fe(Ae.previewTarget??Ae.path),Gt(null)):(Ae==null?void 0:Ae.type)==="diff"&&Gt(Ae.diffMode==="git"?Ae.diffEntry??null:null):($e(null),gt(null),Gt(null))},0)}return Pe})},[nr,Ct]),Wc=y.useCallback(async G=>{var Ae,He;const se=Ct.find(Bt=>Bt.id===G)??null;if(!se||se.type==="preview")return!1;const ne=`detached-${se.id}-${Date.now()}`,pe={id:ne,title:se.label||r1(se),theme:re,surfaceId:u,tab:{id:se.id,type:se.type,path:se.path,label:se.label,language:se.language,content:se.content??null,originalContent:se.originalContent??null,modifiedContent:se.modifiedContent??null,diffMode:se.diffMode,previewTarget:se.previewTarget,previewSrc:se.previewSrc??null,previewMode:se.previewMode??null},architectureDiagram:se.type==="architecture"?F??null:null,architectureGenerating:se.type==="architecture"?V:!1,createdAt:Date.now()};gYe(pe);const ae=`${window.location.origin}${window.location.pathname}?detachedWorkspaceTab=${encodeURIComponent(ne)}`;let Pe=!1;try{if((Ae=window.jaitDesktop)!=null&&Ae.openWorkspaceWindow){const Bt=await window.jaitDesktop.openWorkspaceWindow({url:ae,title:se.label||r1(se)});Pe=!!(Bt!=null&&Bt.ok)}else{const Bt=window.open(ae,`jait-detached-${se.id}`,"popup=yes,width=1280,height=860,resizable=yes,scrollbars=yes");Pe=!!Bt,(He=Bt==null?void 0:Bt.focus)==null||He.call(Bt)}}catch{Pe=!1}return Pe?(xo(G,{preserveManagedPreview:!0}),!0):!1},[F,V,xo,Ct,re,u]),Uc=y.useCallback((G,se)=>{Yl(null);const ne=G.clientX<=jk||G.clientY<=jk||G.clientX>=window.innerWidth-jk||G.clientY>=window.innerHeight-jk,pe=G.dataTransfer.dropEffect==="none"&&(G.clientX===0||G.clientY===0);!ne&&!pe||Wc(se)},[Wc]),gp=y.useCallback(G=>{const se=Ct.find(ne=>ne.id===G);se&&(bn(G),se.type==="file"?($e(se.path),gt(se.content??null),ut(se.language??"plaintext"),Fe(se.path),Gt(null),i(se.id.startsWith("ext:")?se.id.slice(4):"")):se.type==="preview"?($e(null),gt(null),ut("plaintext"),Fe(se.previewTarget??se.path),Gt(null),i("")):se.type==="architecture"?($e(null),gt(null),ut("plaintext"),Fe("__architecture__"),Gt(null),i("")):se.type==="diff"&&Gt(se.diffMode==="git"?se.diffEntry??null:null))},[Ct,i]),Ks=y.useCallback(()=>{Xt([]),bn(null),$e(null),gt(null),Gt(null),Ui(null)},[]),Wo=y.useCallback(G=>{Xt(se=>se.filter(ne=>ne.id===G)),bn(G),Ui(null)},[]),Mu=y.useCallback(G=>{Xt(se=>{const ne=se.findIndex(pe=>pe.id===G);return ne<0?se:se.slice(0,ne+1)}),Ui(null)},[]),bo=y.useCallback((G,se)=>{G!==se&&Xt(ne=>{const pe=ne.findIndex(He=>He.id===G),ae=ne.findIndex(He=>He.id===se);if(pe<0||ae<0||pe===ae)return ne;const Pe=[...ne],[Ae]=Pe.splice(pe,1);return Pe.splice(ae,0,Ae),Pe})},[]),pa=Je.length>0,Va=r.length>0,[ic,ms]=y.useState("files");y.useEffect(()=>{f&&(p&&k==="files"?ms("files"):p&&k==="git"?ms("git"):g&&!p&&ms("editor"))},[f,k,p,g]),y.useEffect(()=>{f&&g&&(Ee==null?void 0:Ee.type)==="diff"&&ms("editor")},[Ee==null?void 0:Ee.id,Ee==null?void 0:Ee.type,f,g]);const zn=(Se==null?void 0:Se.index.files)??[],ki=y.useMemo(()=>{const G=(Se==null?void 0:Se.workingTree.files)??[];if(mr.length===0)return G;const se=new Map(G.map(ae=>[to(ae.path),ae])),ne=new Set,pe=mr.map(ae=>{const Pe=to(ae.path),Ae=se.get(Pe);return ne.add(Pe),Ae??{path:ae.path,insertions:0,deletions:0,status:ae.status}});for(const ae of G){const Pe=to(ae.path);ne.has(Pe)||pe.push(ae)}return pe},[Se==null?void 0:Se.workingTree.files,mr]),_o=y.useMemo(()=>eH(zn.map(G=>({path:G.path,status:G.status,insertions:G.insertions,deletions:G.deletions}))),[zn]),ma=y.useMemo(()=>eH(ki.map(G=>({path:G.path,status:G.status,insertions:G.insertions,deletions:G.deletions}))),[ki]),Pn=y.useMemo(()=>SYe(zn,ki),[zn,ki]),qa=y.useCallback(async()=>{if(!(!le||Pn===0||_t||Wt)){rr(!0),Nt(null);try{const{message:G}=await tl.generateCommitMessage(le,z,$);G&&xe(G)}catch(G){Nt(G instanceof Error?G.message:"Failed to generate commit message")}rr(!1)}},[le,Pn,_t,Wt,z,$]),Qh=Pn>0&&!_t&&!Wt,yp=Gn?Ct.findIndex(G=>G.id===Gn.tabId):-1,ug=!Wt&&(Pn>0||kO(Se)),dg=!Wt&&Pn>0,ve=!Wt&&bYe(Pn,Se),Vn=!Wt&&kO(Se),Kr=_Ye(Pn,Se),Ls=(G=!1)=>c.jsxs("div",{className:"ml-auto inline-flex items-center rounded-md border border-input bg-background/90 p-0.5 shadow-sm",children:[c.jsx("button",{type:"button",className:We("inline-flex items-center justify-center rounded-sm text-muted-foreground transition-colors hover:text-foreground",G?"h-7 w-7":"h-6 w-6",Un==="list"&&"bg-accent text-accent-foreground shadow-sm"),onClick:()=>dt("list"),title:"List view","aria-label":"List view","aria-pressed":Un==="list",children:c.jsx(F0e,{className:"h-3.5 w-3.5"})}),c.jsx("button",{type:"button",className:We("inline-flex items-center justify-center rounded-sm text-muted-foreground transition-colors hover:text-foreground",G?"h-7 w-7":"h-6 w-6",Un==="tree"&&"bg-accent text-accent-foreground shadow-sm"),onClick:()=>dt("tree"),title:"Tree view","aria-label":"Tree view","aria-pressed":Un==="tree",children:c.jsx(iD,{className:"h-3.5 w-3.5"})})]}),ci=(G=!1)=>c.jsxs("div",{className:"flex items-center gap-1.5",children:[c.jsxs(_e,{size:"sm",className:We(G?"h-8 rounded-md px-2.5 text-xs":"h-6 gap-1 rounded-r-none px-1.5 text-xs"),onClick:()=>{if(Kr==="sync"){ha();return}Ua("commit")},disabled:!ug,title:Kr==="sync"?`Synchronize changes with Git${Se?` (Behind ${Se.behindCount}, Ahead ${Se.aheadCount})`:""}`:"Commit all changes (Ctrl+Enter)",children:[Wt?c.jsx(ir,{className:"h-3 w-3 animate-spin"}):Kr==="sync"?c.jsx(Zo,{className:"h-3 w-3"}):c.jsx(sD,{className:"h-3 w-3"}),Kr==="sync"?"Sync":"Commit"]}),c.jsxs(mu,{children:[c.jsx(gu,{asChild:!0,children:c.jsx(_e,{variant:G?"secondary":"default",size:"sm",className:We(G?"h-8 rounded-md px-2":"h-6 rounded-l-none border-l border-primary-foreground/20 px-1.5"),disabled:Wt,title:"More commit actions","aria-label":"More commit actions",children:c.jsx(hl,{className:"h-3.5 w-3.5"})})}),c.jsxs(kc,{align:"start",className:"w-44",children:[c.jsxs(Wi,{onSelect:()=>{Ua("commit")},className:"gap-2",disabled:!dg,children:[c.jsx(sD,{className:"h-3.5 w-3.5"}),"Commit"]}),c.jsxs(Wi,{onSelect:()=>{Ua("commit_push")},className:"gap-2",disabled:!ve,children:[c.jsx(Gge,{className:"h-3.5 w-3.5"}),"Commit & Push"]}),c.jsxs(Wi,{onSelect:()=>{ha()},className:"gap-2",disabled:!Vn,children:[c.jsx(Zo,{className:"h-3.5 w-3.5"}),"Sync Changes"]})]})]})]}),Ud=y.useCallback(G=>{jn(se=>{const ne=new Set(se);return ne.has(G)?ne.delete(G):ne.add(G),ne})},[]);y.useEffect(()=>{$i.current=Ai},[Ai]);const wo=y.useCallback((G,se,ne=!1)=>c.jsxs("span",{className:`flex shrink-0 items-center justify-end gap-0.5 ${ne?"opacity-100":"opacity-0 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100"}`,children:[se==="stage"?c.jsx("button",{type:"button",className:"rounded p-0.5 text-muted-foreground hover:bg-background hover:text-foreground",onClick:pe=>{pe.stopPropagation(),Ru(G)},title:"Stage file (git add)",children:c.jsx(Ro,{className:"h-3 w-3"})}):c.jsx("button",{type:"button",className:"rounded p-0.5 text-muted-foreground hover:bg-background hover:text-foreground",onClick:pe=>{pe.stopPropagation(),uy(G)},title:"Unstage file",children:c.jsx(rC,{className:"h-3 w-3"})}),c.jsx("button",{type:"button",className:"rounded p-0.5 text-muted-foreground hover:bg-background hover:text-red-500",onClick:pe=>{pe.stopPropagation(),fo(ae=>(ae==null?void 0:ae.kind)==="file"&&ae.path===G?null:{kind:"file",path:G})},title:"Discard changes",children:c.jsx(vh,{className:"h-3 w-3"})})]}),[Ru,uy]),vp=y.useCallback((G,se,ne,pe=!1)=>{if(se.length===0)return null;const ae=[...new Set(se)];return c.jsxs("span",{className:`flex shrink-0 items-center justify-end gap-0.5 ${pe?"opacity-100":"opacity-0 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100"}`,children:[ne==="stage"?c.jsx("button",{type:"button",className:"rounded p-0.5 text-muted-foreground hover:bg-background hover:text-foreground",onClick:Pe=>{Pe.stopPropagation(),Nl(ae)},title:"Stage folder",children:c.jsx(Ro,{className:"h-3 w-3"})}):c.jsx("button",{type:"button",className:"rounded p-0.5 text-muted-foreground hover:bg-background hover:text-foreground",onClick:Pe=>{Pe.stopPropagation(),rc(ae)},title:"Unstage folder",children:c.jsx(rC,{className:"h-3 w-3"})}),c.jsx("button",{type:"button",className:"rounded p-0.5 text-muted-foreground hover:bg-background hover:text-red-500",onClick:Pe=>{Pe.stopPropagation(),fo(Ae=>(Ae==null?void 0:Ae.kind)==="folder"&&Ae.path===G?null:{kind:"folder",path:G,paths:ae})},title:"Discard changes in folder",children:c.jsx(vh,{className:"h-3 w-3"})})]})},[Nl,rc]),Pu=y.useCallback((G,se=!1)=>We("group w-full rounded-md text-left transition-colors",se?"text-sm":"text-xs",G?"bg-accent text-accent-foreground":"hover:bg-accent/60 hover:text-accent-foreground"),[]),Vc=y.useCallback((G,se,ne=!1,pe=0)=>G.map(ae=>{if(ae.kind==="dir"){const zt=!ur.has(ae.path),Jt=Roe(ae.children);return c.jsxs("div",{children:[c.jsxs("div",{className:We(Pu(!1,ne),"grid grid-cols-[minmax(0,1fr)_auto] items-center gap-1.5 px-2 py-1.5"),style:{paddingLeft:8+pe*14},children:[c.jsxs("button",{type:"button",className:"flex min-w-0 items-center gap-1.5 text-left",onClick:()=>Ud(ae.path),children:[c.jsx(ao,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground transition-transform ${zt?"rotate-90":""}`}),c.jsx(Sj,{name:ae.name,open:zt,className:"h-3.5 w-3.5 shrink-0"}),c.jsx("span",{className:"truncate",children:ae.name})]}),vp(ae.path,Jt,se,ne)]}),(en==null?void 0:en.kind)==="folder"&&en.path===ae.path&&c.jsxs("div",{className:"ml-6 mt-1 flex items-center gap-1 rounded border border-red-500/30 bg-red-500/5 px-2 py-1 text-2xs",children:[c.jsxs("span",{className:"flex-1 text-red-500",children:["Discard changes in ",ae.name,"?"]}),c.jsx(_e,{size:"sm",variant:"destructive",className:"h-5 px-1.5 text-2xs",onClick:()=>void Hc(en.paths),disabled:Wt,children:"Discard"}),c.jsx(_e,{size:"sm",variant:"ghost",className:"h-5 px-1.5 text-2xs",onClick:()=>fo(null),disabled:Wt,children:"Cancel"})]}),zt?Vc(ae.children,se,ne,pe+1):null]},`${se}:dir:${ae.path}`)}const Pe=ae.entry.status??"M",Ae=ae.name,He=ae.path.includes("/")?ae.path.slice(0,ae.path.lastIndexOf("/")):"",Bt=(Or==null?void 0:Or.path)===ae.path;return c.jsxs("div",{children:[c.jsxs("button",{type:"button",className:We(Pu(Bt,ne),"grid grid-cols-[auto_minmax(0,1fr)_auto_auto] items-center gap-1.5 px-2 py-1.5"),style:{paddingLeft:22+pe*14},onClick:()=>{zd(ae.path),ne&&ms("editor")},title:`${ae.path} — ${jO[Pe]??Pe}`,children:[c.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[c.jsx(o_,{status:Pe,className:ne?"text-2xs":void 0}),c.jsx(jo,{filename:Ae,className:`${ne?"h-4 w-4":"h-3.5 w-3.5"} shrink-0`})]}),c.jsxs("div",{className:"flex min-w-0 items-baseline gap-1.5 overflow-hidden",children:[c.jsx("span",{className:`truncate ${Pe==="D"?"line-through text-muted-foreground":""}`,children:Ae}),He?c.jsx("span",{className:"truncate text-2xs text-muted-foreground",children:He}):null]}),c.jsxs("span",{className:"w-16 shrink-0 text-right text-2xs text-muted-foreground",children:[ae.entry.insertions>0&&c.jsxs("span",{className:"text-green-500",children:["+",ae.entry.insertions]}),ae.entry.deletions>0&&c.jsxs("span",{className:"ml-0.5 text-red-500",children:["-",ae.entry.deletions]})]}),wo(ae.path,se,ne)]}),(en==null?void 0:en.kind)==="file"&&en.path===ae.path&&c.jsxs("div",{className:"ml-6 mt-1 flex items-center gap-1 rounded border border-red-500/30 bg-red-500/5 px-2 py-1 text-2xs",children:[c.jsxs("span",{className:"flex-1 text-red-500",children:["Discard changes in ",Ae,"?"]}),c.jsx(_e,{size:"sm",variant:"destructive",className:"h-5 px-1.5 text-2xs",onClick:()=>void Wd(ae.path),disabled:Wt,children:"Discard"}),c.jsx(_e,{size:"sm",variant:"ghost",className:"h-5 px-1.5 text-2xs",onClick:()=>fo(null),disabled:Wt,children:"Cancel"})]})]},`${se}:file:${ae.path}`)}),[ur,en,Pu,Wt,Wd,Hc,zd,wo,vp,Ud,Or==null?void 0:Or.path]),ga=y.useCallback((G,se,ne,pe,ae,Pe=!1)=>{if(se.length===0)return null;const Ae=We("rounded p-0.5 text-muted-foreground transition-[background-color,color,opacity] hover:bg-background",Pe?"opacity-100":"opacity-0 group-hover:opacity-100 group-focus-within:opacity-100");return c.jsxs("div",{className:"mt-1",children:[c.jsxs("div",{className:"group flex items-center justify-between gap-2 px-2 py-1 text-2xs font-medium uppercase tracking-wider text-muted-foreground",children:[c.jsxs("div",{children:[G," (",se.length,")",c.jsxs("span",{className:"ml-1 normal-case tracking-normal",children:[c.jsxs("span",{className:"text-green-500",children:["+",pe.insertions]})," ",c.jsxs("span",{className:"text-red-500",children:["-",pe.deletions]})]})]}),c.jsx("div",{className:We("flex items-center gap-1 transition-opacity",Pe?"opacity-100":"opacity-0 group-hover:opacity-100 group-focus-within:opacity-100"),children:ae==="stage"?c.jsxs(c.Fragment,{children:[c.jsx("button",{type:"button",className:We(Ae,"text-red-600 hover:text-red-700 disabled:pointer-events-none disabled:opacity-40 dark:text-red-400"),onClick:()=>fo({kind:"all"}),disabled:Wt||se.length===0,title:"Discard all changes","aria-label":"Discard all changes",children:c.jsx(vh,{className:"h-3 w-3"})}),c.jsx("button",{type:"button",className:We(Ae,"hover:text-foreground disabled:pointer-events-none disabled:opacity-40"),onClick:()=>void vo(),disabled:Wt||se.length===0,title:"Stage all changes","aria-label":"Stage all changes",children:c.jsx(Ro,{className:"h-3 w-3"})})]}):c.jsxs(c.Fragment,{children:[c.jsx("button",{type:"button",className:We(Ae,"text-red-600 hover:text-red-700 disabled:pointer-events-none disabled:opacity-40 dark:text-red-400"),onClick:()=>fo({kind:"all"}),disabled:Wt||Pn===0,title:"Discard all changes","aria-label":"Discard all changes",children:c.jsx(vh,{className:"h-3 w-3"})}),c.jsx("button",{type:"button",className:We(Ae,"hover:text-foreground disabled:pointer-events-none disabled:opacity-40"),onClick:()=>void nc(),disabled:Wt||se.length===0,title:"Unstage all files","aria-label":"Unstage all files",children:c.jsx(rC,{className:"h-3 w-3"})})]})})]}),(en==null?void 0:en.kind)==="all"&&Pn>0&&c.jsxs("div",{className:"mx-2 mb-1 flex items-center gap-1 rounded border border-red-500/30 bg-red-500/5 px-2 py-1 text-2xs",children:[c.jsx("span",{className:"flex-1 text-red-500",children:"Discard all changes?"}),c.jsx(_e,{size:"sm",variant:"destructive",className:"h-5 px-1.5 text-2xs",onClick:()=>void Ou(),disabled:Wt,children:"Discard"}),c.jsx(_e,{size:"sm",variant:"ghost",className:"h-5 px-1.5 text-2xs",onClick:()=>fo(null),disabled:Wt,children:"Cancel"})]}),c.jsx("div",{className:"mt-1 space-y-1",children:Un==="tree"?Vc(ne,ae,Pe):se.map(He=>{const Bt=He.status??"M",zt=He.path.split("/").pop()??He.path,Jt=He.path.includes("/")?He.path.slice(0,He.path.lastIndexOf("/")):"",Sr=(Or==null?void 0:Or.path)===He.path;return c.jsxs("div",{children:[c.jsxs("div",{className:We(Pu(Sr,Pe),"grid w-full cursor-pointer grid-cols-[auto_minmax(0,1fr)_auto_auto] items-center gap-1.5 px-2 py-1.5"),draggable:!Pe,onClick:()=>{zd(He.path),Pe&&ms("editor")},onDragStart:Dr=>{Pe||(Dr.dataTransfer.effectAllowed="copy",Dr.dataTransfer.setData("text/jait-file",JSON.stringify({path:He.path,name:zt})))},title:`${He.path} — ${jO[Bt]??Bt}`,children:[c.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[c.jsx(o_,{status:Bt,className:Pe?"text-2xs":void 0}),c.jsx(jo,{filename:zt,className:`${Pe?"h-4 w-4":"h-3.5 w-3.5"} shrink-0`})]}),c.jsxs("div",{className:"flex min-w-0 items-baseline gap-1.5 overflow-hidden",children:[c.jsx("span",{className:`truncate ${Bt==="D"?"line-through text-muted-foreground":""}`,children:zt}),Jt?c.jsx("span",{className:"truncate text-2xs text-muted-foreground",children:Jt}):null]}),c.jsxs("span",{className:"w-16 shrink-0 text-right text-2xs text-muted-foreground",children:[He.insertions>0&&c.jsxs("span",{className:"text-green-500",children:["+",He.insertions]}),He.deletions>0&&c.jsxs("span",{className:"ml-0.5 text-red-500",children:["-",He.deletions]})]}),wo(He.path,ae,Pe)]}),(en==null?void 0:en.kind)==="file"&&en.path===He.path&&c.jsxs("div",{className:"ml-6 mt-1 flex items-center gap-1 rounded border border-red-500/30 bg-red-500/5 px-2 py-1 text-2xs",children:[c.jsxs("span",{className:"flex-1 text-red-500",children:["Discard changes in ",zt,"?"]}),c.jsx(_e,{size:"sm",variant:"destructive",className:"h-5 px-1.5 text-2xs",onClick:()=>void Wd(He.path),disabled:Wt,children:"Discard"}),c.jsx(_e,{size:"sm",variant:"ghost",className:"h-5 px-1.5 text-2xs",onClick:()=>fo(null),disabled:Wt,children:"Cancel"})]})]},`${ae}:${He.path}`)})})]})},[Pn,en==null?void 0:en.kind,(en==null?void 0:en.kind)==="file"||(en==null?void 0:en.kind)==="folder"?en.path:null,Pu,Wt,Ou,Wd,zd,vo,nc,wo,Vc,Or==null?void 0:Or.path,Un]),xp=y.useCallback(async G=>{mo()||(await la(G),f&&ms("editor"))},[mo,la,f]),Vd=y.useCallback(G=>{fa(G),f&&ms("editor")},[fa,f]),bp=y.useCallback((G,se,ne,pe)=>{const ae=se.trim();if(!ae){ot.current=null;return}const Pe=`${G.path}:${ne}:${pe}:${ae}`;ot.current!==Pe&&(ot.current=Pe,a==null||a(G,ae,ne,pe))},[a]);if(f){const G=(ic==="files"||ic==="git")&&!p?"editor":ic==="editor"&&!g?"files":ic,se=ne=>{ms(ne)};return!p&&!g?null:c.jsxs("div",{className:"flex flex-col h-full min-h-0",children:[g&&c.jsxs("div",{"data-testid":"mobile-workspace-tabbar",className:"flex items-center h-[35px] border-b bg-muted/30 shrink-0 px-1 gap-0.5",children:[g&&(Ct.length>0?c.jsxs(mu,{onOpenChange:ne=>{ne&&se("editor")},children:[c.jsx(gu,{asChild:!0,children:c.jsxs("button",{className:`flex items-center gap-1 px-2.5 py-1 rounded text-xs font-medium transition-colors min-w-0 ${G==="editor"?"bg-background text-foreground shadow-sm":"text-muted-foreground"}`,children:[c.jsx("span",{className:"shrink-0",children:"Editor"}),Ct.length>1&&c.jsx("span",{className:"rounded-full bg-primary/15 px-1.5 text-2xs font-bold leading-tight text-primary",children:Ct.length}),(Ee??Di)&&c.jsxs("span",{className:"truncate text-2xs text-muted-foreground max-w-[120px]",children:["—"," ",Ee?r1(Ee):Di==null?void 0:Di.path.split("/").pop()]})]})}),c.jsxs(kc,{align:"start",className:"w-[min(20rem,calc(100vw-1rem))]",children:[c.jsx(t0,{children:"Open tabs"}),Ct.map(ne=>{const pe=ne.id===nr;return c.jsxs(Wi,{disabled:pe,onSelect:()=>{pe||(gp(ne.id),se("editor"))},className:We("gap-2",pe&&"bg-muted/55 text-muted-foreground"),children:[ne.type==="diff"&&ne.diffMode==="git"&&ne.diffEntry?c.jsx(o_,{status:ne.diffEntry.status,className:"text-2xs"}):ne.type==="architecture"?c.jsx(G_,{className:"h-3.5 w-3.5 shrink-0"}):ne.type==="preview"?c.jsx(_i,{className:"h-3.5 w-3.5 shrink-0"}):c.jsx(jo,{filename:ne.path,className:"h-3.5 w-3.5 shrink-0"}),c.jsx("span",{className:"min-w-0 flex-1 truncate",children:r1(ne)}),pe&&c.jsx("span",{className:"text-2xs font-medium text-muted-foreground/90",children:"Current"})]},ne.id)}),Ee&&c.jsxs(c.Fragment,{children:[c.jsx(rd,{}),c.jsxs(Wi,{onSelect:()=>xo(Ee.id),className:"gap-2 text-red-600 focus:text-red-600 dark:text-red-400 dark:focus:text-red-400",children:[c.jsx(Jn,{className:"h-3.5 w-3.5 shrink-0"}),c.jsx("span",{className:"truncate",children:"Close current tab"})]})]})]})]}):c.jsxs("button",{className:`flex items-center gap-1 px-2.5 py-1 rounded text-xs font-medium transition-colors ${G==="editor"?"bg-background text-foreground shadow-sm":"text-muted-foreground"}`,onClick:()=>se("editor"),children:["Editor",Di&&c.jsxs("span",{className:"text-2xs text-muted-foreground truncate max-w-[120px]",children:["—"," ",Di.path.split("/").pop()]})]})),G==="editor"&&(Ee==null?void 0:Ee.type)==="preview"&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"flex-1"}),c.jsx("button",{type:"button",onClick:jl,className:"flex items-center text-xs text-muted-foreground hover:text-foreground px-1.5 shrink-0",title:"Refresh preview",children:c.jsx(Zo,{className:"h-3 w-3"})}),c.jsx("button",{type:"button",onClick:()=>Vh(ne=>!ne),className:"flex items-center text-xs text-muted-foreground hover:text-foreground px-1.5 shrink-0",title:"Preview controls",children:c.jsx(kN,{className:"h-3 w-3"})})]})]}),G==="files"&&p&&c.jsxs(c.Fragment,{children:[!k&&c.jsx("div",{className:"flex items-center justify-end h-7 px-2 shrink-0 border-b bg-muted/10",children:v&&c.jsx("button",{onClick:v,className:"flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors rounded px-1.5 py-0.5 hover:bg-muted",children:c.jsx(mh,{className:"h-3 w-3"})})}),c.jsxs("div",{className:"flex items-center gap-1 px-1.5 py-1 border-b shrink-0",children:[c.jsx(Vl,{className:"h-3 w-3 text-muted-foreground shrink-0"}),c.jsx("input",{type:"text",placeholder:qs==="content"?"Search in files…":"Search file names…",value:ss,onChange:ne=>fs(ne.target.value),className:"min-w-0 flex-1 h-7 bg-transparent text-sm outline-none placeholder:text-muted-foreground/60"}),ss&&c.jsx("button",{onClick:()=>{fs(""),os(null)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground",children:c.jsx(Jn,{className:"h-3.5 w-3.5"})}),c.jsx("button",{onClick:()=>Rd(ne=>ne==="files"?"content":"files"),className:`px-1.5 h-6 rounded text-2xs font-medium shrink-0 ${qs==="content"?"bg-primary/20 text-primary":"text-muted-foreground hover:bg-muted"}`,title:qs==="files"?"Switch to content search":"Switch to filename search",children:qs==="files"?"Name":"Content"})]}),ss.trim()?c.jsx(gh,{className:"flex-1 min-h-0",children:c.jsxs("div",{className:"p-1",children:[ws&&c.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-2 text-sm text-muted-foreground",children:[c.jsx(ir,{className:"h-3.5 w-3.5 animate-spin"})," Searching…"]}),!ws&&(Bn==null?void 0:Bn.files)&&Bn.files.length>0&&Bn.files.map(ne=>c.jsxs("div",{className:"flex items-center gap-1.5 rounded px-1 py-2 cursor-pointer text-sm hover:bg-muted active:bg-muted",style:{paddingLeft:8},onClick:()=>{const pe=le?`${le.replace(/\\/g,"/")}/${ne.path}`:ne.path;kl(pe),f&&ms("editor"),fs(""),os(null)},children:[c.jsx(jo,{filename:ne.name,className:"h-4 w-4 shrink-0"}),c.jsx("span",{className:"truncate flex-1",title:ne.path,children:c.jsx(n1,{text:ne.path,query:ss})})]},ne.path)),!ws&&(Bn==null?void 0:Bn.matches)&&Bn.matches.length>0&&Bn.matches.map((ne,pe)=>c.jsxs("div",{className:"flex flex-col gap-0 rounded px-1 py-2 cursor-pointer text-sm hover:bg-muted active:bg-muted",style:{paddingLeft:8},onClick:()=>{const ae=le?`${le.replace(/\\/g,"/")}/${ne.file}`:ne.file;kl(ae),f&&ms("editor"),fs(""),os(null)},children:[c.jsxs("div",{className:"flex items-center gap-1",children:[c.jsx(jo,{filename:ne.file.split("/").pop()||ne.file,className:"h-4 w-4 shrink-0"}),c.jsx("span",{className:"truncate text-foreground",title:ne.file,children:c.jsx(n1,{text:ne.file,query:ss})}),c.jsxs("span",{className:"text-muted-foreground shrink-0",children:[":",ne.line]})]}),c.jsx("span",{className:"truncate text-muted-foreground pl-6",children:c.jsx(n1,{text:ne.content,query:ss})})]},`${ne.file}:${ne.line}:${pe}`)),!ws&&Bn&&!((Uo=Bn.files)!=null&&Uo.length)&&!((Tl=Bn.matches)!=null&&Tl.length)&&c.jsx("div",{className:"text-sm text-muted-foreground px-2 py-2",children:"No results found."})]})}):c.jsx(gh,{className:"flex-1 min-h-0",children:c.jsxs("div",{className:"p-1",children:[pa&&Je.map(ne=>c.jsx(iH,{node:ne,depth:0,activeFilePath:ke,expandedDirs:be,onToggleDir:Xh,onSelectFile:xp,onContextFile:Zh,onTreeContextMenu:ca,onMoveNode:Id,onMobilePointerStart:Bd,isMobile:!0,normStatusMap:Rt,dirChangesSet:it,mobileDragTargetPath:(Ai==null?void 0:Ai.dropDir)??null},ne.path)),Va&&c.jsxs(c.Fragment,{children:[pa&&c.jsx("div",{className:"text-xs uppercase tracking-wider text-muted-foreground px-2 pt-3 pb-1 font-medium",children:"Dropped files"}),r.map(ne=>c.jsxs("div",{onClick:()=>Vd(ne.id),className:`group flex items-center gap-1.5 rounded px-1 py-2 cursor-pointer text-sm ${!ke&&n===ne.id?"bg-primary/15 text-foreground":"hover:bg-muted active:bg-muted"}`,style:{paddingLeft:18},children:[c.jsx(jo,{filename:ne.name,className:"h-4 w-4"}),c.jsx("span",{className:"truncate flex-1",title:ne.path,children:ne.path})]},ne.id))]}),!pa&&!Va&&c.jsx("div",{className:"p-3 flex flex-col items-center gap-2",children:c.jsx("p",{className:"text-sm text-muted-foreground text-center",children:"No files loaded yet. The workspace opens automatically when the agent works with files."})})]})})]}),G==="git"&&p&&c.jsxs("div",{className:"flex-1 flex flex-col min-h-0",children:[c.jsxs("div",{className:"flex items-center gap-1.5 h-7 px-2 border-b bg-muted/10 shrink-0",children:[(Se==null?void 0:Se.branch)&&c.jsxs("span",{className:"text-xs text-muted-foreground truncate flex-1",children:[c.jsx(u0,{className:"h-3 w-3 inline mr-0.5 -mt-px"}),Se.branch]}),le&&c.jsxs("select",{className:"h-6 rounded border bg-background px-1.5 text-2xs text-muted-foreground",value:String(pr),onChange:ne=>rt(ne.target.value),title:`${XF(pr)}. Interval: ${Wr}s`,children:[c.jsx("option",{value:"false",children:"Auto-fetch off"}),c.jsx("option",{value:"true",children:"Auto-fetch origin"}),c.jsx("option",{value:"all",children:"Auto-fetch all"})]}),c.jsx("button",{className:"p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground",onClick:Jr,disabled:Et,children:c.jsx(Zo,{className:`h-3.5 w-3.5 ${Et?"animate-spin":""}`})}),Se!=null&&Se.behindCount?c.jsxs("button",{className:"relative p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground",onClick:mp,disabled:Wt,title:`Pull ${Se.behindCount} commit${Se.behindCount>1?"s":""}`,children:[c.jsx(Em,{className:"h-3.5 w-3.5"}),c.jsx("span",{className:"absolute -right-1 -top-1 min-w-[14px] rounded-full bg-primary px-1 text-2xs font-semibold leading-[14px] text-primary-foreground",children:Se.behindCount})]}):null,Se!=null&&Se.aheadCount?c.jsxs("button",{className:"relative p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground",onClick:()=>Ua("commit_push"),disabled:Wt,title:`Push ${Se.aheadCount} commit${Se.aheadCount>1?"s":""}`,children:[c.jsx(dD,{className:"h-3.5 w-3.5"}),c.jsx("span",{className:"absolute -right-1 -top-1 min-w-[14px] rounded-full bg-primary px-1 text-2xs font-semibold leading-[14px] text-primary-foreground",children:Se.aheadCount})]}):null]}),le&&Se&&c.jsxs("div",{className:"px-2 py-2 border-b bg-muted/5 shrink-0 space-y-2",children:[c.jsxs("div",{className:"relative",children:[c.jsx("textarea",{className:"w-full text-sm bg-background border rounded px-2 py-1.5 pr-8 resize-none placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50",rows:2,placeholder:"Commit message",value:or,onChange:ne=>xe(ne.target.value),disabled:Wt||_t}),c.jsx("button",{className:"absolute top-1.5 right-1.5 p-0.5 rounded text-muted-foreground hover:text-primary transition-colors disabled:opacity-40 disabled:cursor-not-allowed",onClick:qa,disabled:!Qh,title:"Generate commit message with AI",children:_t?c.jsx(ir,{className:"h-3.5 w-3.5 animate-spin"}):c.jsx(Y_,{className:"h-3.5 w-3.5"})})]}),c.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[ci(!0),Ls(!0)]}),Be&&c.jsx("div",{className:"text-xs text-red-500",children:Be})]}),c.jsxs(gh,{className:"flex-1 min-h-0",children:[Et&&!Se&&c.jsxs("div",{className:"flex items-center justify-center gap-2 p-4 text-sm text-muted-foreground",children:[c.jsx(ir,{className:"h-4 w-4 animate-spin"}),"Loading..."]}),Se&&Pn===0&&c.jsx("div",{className:"p-4 text-sm text-muted-foreground text-center",children:"No changes detected."}),Se&&Pn>0&&c.jsxs("div",{className:"p-1",children:[c.jsxs("div",{className:"text-xs text-muted-foreground px-2 py-1.5 font-medium",children:["Source Control (",Pn,")",c.jsxs("span",{className:"ml-1",children:[c.jsxs("span",{className:"text-green-500",children:["+",Se.index.insertions+Se.workingTree.insertions]})," ",c.jsxs("span",{className:"text-red-500",children:["-",Se.index.deletions+Se.workingTree.deletions]})]})]}),ga("Staged",zn,_o,Se.index,"unstage",!0),ga("Changes",ki,ma,Se.workingTree,"stage",!0)]}),!le&&c.jsx("div",{className:"p-4 text-sm text-muted-foreground text-center",children:"Open a workspace to see git changes."})]})]}),G==="editor"&&g&&c.jsx("div",{className:"flex-1 flex flex-col min-h-0",children:c.jsx("div",{className:"flex-1 min-h-0 overflow-auto",children:ar?c.jsxs("div",{className:"h-full flex items-center justify-center text-sm text-muted-foreground gap-2",children:[c.jsx(ir,{className:"h-4 w-4 animate-spin"}),"Loading diff..."]}):(Ee==null?void 0:Ee.type)==="diff"&&Ee.diffMode==="review"?c.jsx(WF,{filePath:Ee.path,originalContent:Ee.originalContent??"",modifiedContent:Ee.modifiedContent??"",language:Ee.language??"plaintext",onClose:()=>xo(Ee.id),onApply:ne=>{L==null||L(Ee.path,ne)}}):(Ee==null?void 0:Ee.type)==="diff"&&Ee.diffMode==="git"?c.jsx(O2,{className:"h-full",editorClassName:"h-full",original:Ee.originalContent??((_p=Ee.diffEntry)==null?void 0:_p.original)??"",modified:Ee.modifiedContent??((sc=Ee.diffEntry)==null?void 0:sc.modified)??"",language:Ee.language??"plaintext",modelKey:`${Ee.id}:${Ee.version??0}`,renderSideBySide:!1,options:{minimap:{enabled:!1},lineNumbers:"on",wordWrap:"on",scrollBeyondLastLine:!1}},`${Ee.id}:${Ee.version??0}`):(Ee==null?void 0:Ee.type)==="preview"?ay("Open or start a preview from the side controls."):(Ee==null?void 0:Ee.type)==="architecture"?c.jsx(_O,{diagram:F??null,isGenerating:V,onGenerate:U,onRegenerate:U,theme:re,onRenderResult:Q}):Ye?c.jsxs("div",{className:"h-full flex items-center justify-center text-sm text-muted-foreground gap-2",children:[c.jsx(ir,{className:"h-4 w-4 animate-spin"}),"Loading..."]}):(Ee==null?void 0:Ee.type)==="file"&&Ee.content?c.jsx("pre",{className:"text-xs leading-relaxed p-2 font-mono whitespace-pre overflow-x-auto text-foreground",children:c.jsx("code",{children:Ee.content})}):Di?c.jsx("pre",{className:"text-xs leading-relaxed p-2 font-mono whitespace-pre overflow-x-auto text-foreground",children:c.jsx("code",{children:Di.content})}):c.jsx("div",{className:"h-full flex items-center justify-center text-xs text-muted-foreground px-4 text-center",children:"Tap a file in the Files tab to view it here."})})}),Zt&&c.jsx("div",{className:"fixed inset-0 z-50",onPointerDown:()=>hn(null),children:c.jsxs("div",{ref:Od,className:"ui-panel-surface absolute max-h-[70vh] w-48 overflow-auto rounded-lg border p-1 shadow-lg",style:is?{left:is.left,top:is.top}:{opacity:0,left:Zt.x,top:Zt.y},onPointerDown:ne=>ne.stopPropagation(),children:[c.jsx("div",{className:"px-2 py-1.5 text-xs font-medium text-muted-foreground truncate",children:Zt.node.name}),c.jsxs("button",{className:"ui-menu-item",onClick:()=>{Zh(Zt.node),hn(null)},children:[c.jsx(Ro,{className:"h-3 w-3"}),"Add to Chat"]}),Zt.node.kind==="file"&&c.jsx("button",{className:"ui-menu-item",onClick:()=>{const ne=Zt.node;la(ne),hn(null)},children:"Open"}),c.jsx("div",{className:"my-1 h-px bg-border"}),c.jsxs("button",{className:"ui-menu-item",onClick:()=>{const ne=Zt.node.kind==="dir"?Zt.node.path:Zt.node.path.includes("/")?Zt.node.path.slice(0,Zt.node.path.lastIndexOf("/")):le??"";Vs({parentDir:ne,kind:"file"}),na(""),hn(null)},children:[c.jsx(eC,{className:"h-3 w-3"}),"New File"]}),c.jsxs("button",{className:"ui-menu-item",onClick:()=>{const ne=Zt.node.kind==="dir"?Zt.node.path:Zt.node.path.includes("/")?Zt.node.path.slice(0,Zt.node.path.lastIndexOf("/")):le??"";Vs({parentDir:ne,kind:"dir"}),na(""),hn(null)},children:[c.jsx(wN,{className:"h-3 w-3"}),"New Folder"]}),c.jsx("div",{className:"my-1 h-px bg-border"}),c.jsxs("button",{className:"ui-menu-item",onClick:()=>{ho({path:Zt.node.path,name:Zt.node.name,kind:Zt.node.kind==="dir"?"dir":"file"}),Lc(Zt.node.name),hn(null)},children:[c.jsx(SN,{className:"h-3 w-3"}),"Rename"]}),c.jsxs("button",{className:"ui-menu-item text-red-500 hover:text-red-600",onClick:()=>{Jh(Zt.node),hn(null)},children:[c.jsx(Sh,{className:"h-3 w-3"}),"Delete"]}),c.jsx("div",{className:"my-1 h-px bg-border"}),c.jsxs("button",{className:"ui-menu-item",onClick:()=>{Cl(Zt.node),hn(null)},children:[c.jsx(wc,{className:"h-3 w-3"}),"Copy Path"]}),c.jsxs("button",{className:"ui-menu-item",onClick:()=>{tc(Zt.node),hn(null)},children:[c.jsx(wc,{className:"h-3 w-3"}),"Copy Relative Path"]})]})}),_s&&c.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/30",onPointerDown:()=>ho(null),children:c.jsxs("div",{className:"ui-panel-surface min-w-[280px] max-w-[calc(100vw-2rem)] p-4",onPointerDown:ne=>ne.stopPropagation(),children:[c.jsxs("div",{className:"mb-2 text-sm font-medium",children:["Rename “",_s.name,"”"]}),c.jsx(Hn,{className:"h-10 text-sm",autoFocus:!0,value:Pc,onChange:ne=>Lc(ne.target.value),onKeyDown:ne=>{ne.key==="Enter"&&ua(),ne.key==="Escape"&&ho(null)}}),c.jsxs("div",{className:"mt-3 flex justify-end gap-1.5",children:[c.jsx(_e,{variant:"ghost",size:"sm",className:"h-8 rounded-md px-3 text-xs",onClick:()=>ho(null),children:"Cancel"}),c.jsx(_e,{size:"sm",className:"h-8 rounded-md px-3 text-xs",onClick:()=>void ua(),children:"Rename"})]})]})}),ai&&c.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/30",onPointerDown:()=>Vs(null),children:c.jsxs("div",{className:"ui-panel-surface min-w-[280px] max-w-[calc(100vw-2rem)] p-4",onPointerDown:ne=>ne.stopPropagation(),children:[c.jsxs("div",{className:"mb-2 text-sm font-medium",children:["New ",ai.kind==="dir"?"Folder":"File"]}),c.jsx(Hn,{className:"h-10 text-sm",autoFocus:!0,placeholder:ai.kind==="dir"?"folder-name":"filename.ext",value:Wh,onChange:ne=>na(ne.target.value),onKeyDown:ne=>{ne.key==="Enter"&&mi(),ne.key==="Escape"&&Vs(null)}}),c.jsxs("div",{className:"mt-3 flex justify-end gap-1.5",children:[c.jsx(_e,{variant:"ghost",size:"sm",className:"h-8 rounded-md px-3 text-xs",onClick:()=>Vs(null),children:"Cancel"}),c.jsx(_e,{size:"sm",className:"h-8 rounded-md px-3 text-xs",onClick:()=>void mi(),children:"Create"})]})]})})]})}return c.jsxs("aside",{className:We("bg-muted/20 flex min-h-0",vt.maxCollapsed?"flex-1":"shrink-0",It?"z-30 border-r shadow-2xl":!vt.maxCollapsed&&g&&"border-r"),style:wYe({showTree:p,showEditor:g,panelSize:vt.size,treeSize:nt.size,maxCollapsed:vt.maxCollapsed}),children:[p&&!It&&!vt.collapsed&&c.jsx("div",{className:"border-r bg-background transition-colors flex flex-col shrink-0 overflow-hidden",style:{width:nt.collapsed?0:nt.size},children:Mc&&c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"flex items-center h-[35px] border-b bg-muted/20 shrink-0 px-1 gap-0.5 overflow-hidden",children:[c.jsxs("button",{className:`flex h-7 items-center gap-1 px-2 rounded text-xs font-medium transition-colors whitespace-nowrap shrink-0 ${fr==="files"?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,onClick:()=>{Lt("files"),Gt(null)},children:[c.jsx(wh,{className:"h-3 w-3 shrink-0"}),"Files"]}),c.jsxs("button",{className:`flex h-7 items-center gap-1 px-2 rounded text-xs font-medium transition-colors whitespace-nowrap shrink-0 ${fr==="git"?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,onClick:()=>{Lt("git"),Gt(null)},children:[c.jsx(u0,{className:"h-3 w-3 shrink-0"}),"Source Control",Pn>0&&c.jsx("span",{className:"ml-0.5 text-2xs bg-primary/20 text-primary rounded-full px-1.5 leading-tight font-bold",children:Pn})]}),c.jsx("div",{className:"flex-1"}),c.jsx("button",{onClick:()=>nt.collapse(),className:"flex h-7 items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors rounded px-1 hover:bg-muted",children:c.jsx(mh,{className:"h-3 w-3"})})]}),fr==="files"&&c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"flex items-center gap-1 px-1.5 py-1 border-b shrink-0",children:[c.jsx(Vl,{className:"h-3 w-3 text-muted-foreground shrink-0"}),c.jsx("input",{type:"text",placeholder:qs==="content"?"Search in files…":"Search file names…",value:ss,onChange:G=>fs(G.target.value),className:"min-w-0 flex-1 h-6 bg-transparent [font-size:0.9rem] outline-none placeholder:text-muted-foreground/60"}),ss&&c.jsx("button",{onClick:()=>{fs(""),os(null)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground",children:c.jsx(Jn,{className:"h-3 w-3"})}),c.jsx("button",{onClick:()=>Rd(G=>G==="files"?"content":"files"),className:`px-1.5 h-5 rounded text-2xs font-medium shrink-0 ${qs==="content"?"bg-primary/20 text-primary":"text-muted-foreground hover:bg-muted"}`,title:qs==="files"?"Switch to content search":"Switch to filename search",children:qs==="files"?"Name":"Content"})]}),ss.trim()?c.jsx(gh,{className:"flex-1 min-h-0",children:c.jsxs("div",{className:"p-1",children:[ws&&c.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-2 text-xs text-muted-foreground",children:[c.jsx(ir,{className:"h-3 w-3 animate-spin"})," Searching…"]}),!ws&&(Bn==null?void 0:Bn.files)&&Bn.files.length>0&&Bn.files.map(G=>c.jsxs("div",{className:"flex items-center gap-1 rounded px-1 py-1 cursor-pointer text-xs hover:bg-muted",style:{paddingLeft:8},onClick:()=>{const se=le?`${le.replace(/\\/g,"/")}/${G.path}`:G.path;kl(se),fs(""),os(null)},children:[c.jsx(jo,{filename:G.name,className:"h-3.5 w-3.5 shrink-0"}),c.jsx("span",{className:"truncate flex-1",title:G.path,children:c.jsx(n1,{text:G.path,query:ss})})]},G.path)),!ws&&(Bn==null?void 0:Bn.matches)&&Bn.matches.length>0&&Bn.matches.map((G,se)=>c.jsxs("div",{className:"flex flex-col gap-0 rounded px-1 py-1 cursor-pointer text-xs hover:bg-muted",style:{paddingLeft:8},onClick:()=>{const ne=le?`${le.replace(/\\/g,"/")}/${G.file}`:G.file;kl(ne),fs(""),os(null)},children:[c.jsxs("div",{className:"flex items-center gap-1",children:[c.jsx(jo,{filename:G.file.split("/").pop()||G.file,className:"h-3.5 w-3.5 shrink-0"}),c.jsx("span",{className:"truncate text-foreground",title:G.file,children:c.jsx(n1,{text:G.file,query:ss})}),c.jsxs("span",{className:"text-muted-foreground shrink-0",children:[":",G.line]})]}),c.jsx("span",{className:"truncate text-muted-foreground pl-5",children:c.jsx(n1,{text:G.content,query:ss})})]},`${G.file}:${G.line}:${se}`)),!ws&&Bn&&!((fn=Bn.files)!=null&&fn.length)&&!((Lu=Bn.matches)!=null&&Lu.length)&&c.jsx("div",{className:"text-xs text-muted-foreground px-2 py-2",children:"No results found."})]})}):c.jsx(gh,{className:"flex-1 min-h-0",children:c.jsxs("div",{className:"p-1",children:[pa&&Je.map(G=>c.jsx(iH,{node:G,depth:0,activeFilePath:ke,expandedDirs:be,onToggleDir:Xh,onSelectFile:Fc,onContextFile:Zh,onTreeContextMenu:ca,onMoveNode:Id,normStatusMap:Rt,dirChangesSet:it,mobileDragTargetPath:(Ai==null?void 0:Ai.dropDir)??null},G.path)),Va&&c.jsxs(c.Fragment,{children:[pa&&c.jsx("div",{className:"text-2xs uppercase tracking-wider text-muted-foreground px-2 pt-3 pb-1 font-medium",children:"Dropped files"}),r.map(G=>c.jsxs("div",{onClick:()=>fa(G.id),onContextMenu:se=>{se.preventDefault(),o(G)},className:`group flex items-center gap-1 rounded px-1 py-1 cursor-pointer text-xs ${!ke&&n===G.id?"bg-primary/15 text-foreground":"hover:bg-muted"}`,style:{paddingLeft:22},children:[c.jsx(jo,{filename:G.name,className:"h-3.5 w-3.5"}),c.jsx("span",{className:"truncate flex-1",title:G.path,children:G.path}),c.jsx("button",{type:"button",className:"opacity-0 group-hover:opacity-100 p-0.5 rounded hover:bg-background",onClick:se=>{se.stopPropagation(),o(G)},title:"Add to chat",children:c.jsx(Ro,{className:"h-3 w-3"})})]},G.id))]}),!pa&&!Va&&c.jsx("div",{className:"p-3 flex flex-col items-center gap-2",children:c.jsx("p",{className:"text-xs text-muted-foreground",children:"No files loaded yet. The workspace opens automatically when the agent works with files."})})]})})]}),fr==="git"&&c.jsxs("div",{className:"flex-1 min-h-0 flex flex-col",children:[c.jsxs("div",{className:"flex h-[35px] items-center gap-1.5 px-2 border-b bg-muted/10 shrink-0 min-w-0",children:[(Se==null?void 0:Se.branch)&&c.jsxs("span",{className:"ui-caption truncate flex-1 min-w-0",title:Se.branch,children:[c.jsx(u0,{className:"h-3 w-3 inline mr-0.5 -mt-px"}),Se.branch]}),!(Se!=null&&Se.branch)&&c.jsx("span",{className:"ui-caption flex-1 min-w-0",children:"No repo"}),le&&c.jsxs("select",{className:"h-7 rounded-md border border-input bg-background/90 px-2 text-xs text-muted-foreground shadow-sm shrink-0",value:String(pr),onChange:G=>rt(G.target.value),title:`${XF(pr)}. Interval: ${Wr}s`,children:[c.jsx("option",{value:"false",children:"Auto-fetch off"}),c.jsx("option",{value:"true",children:"Auto-fetch origin"}),c.jsx("option",{value:"all",children:"Auto-fetch all"})]}),c.jsx("button",{className:"ui-inline-action p-1",onClick:Jr,disabled:Et,title:"Refresh git status",children:c.jsx(Zo,{className:`h-3 w-3 ${Et?"animate-spin":""}`})}),Se!=null&&Se.behindCount?c.jsxs("button",{className:"relative ui-inline-action p-1",onClick:mp,disabled:Wt,title:`Pull ${Se.behindCount} commit${Se.behindCount>1?"s":""}`,children:[c.jsx(Em,{className:"h-3 w-3"}),c.jsx("span",{className:"absolute -right-1 -top-1 min-w-[14px] rounded-full bg-primary px-1 text-2xs font-semibold leading-[14px] text-primary-foreground",children:Se.behindCount})]}):null,Se!=null&&Se.aheadCount?c.jsxs("button",{className:"relative ui-inline-action p-1",onClick:()=>Ua("commit_push"),disabled:Wt,title:`Push ${Se.aheadCount} commit${Se.aheadCount>1?"s":""}`,children:[c.jsx(dD,{className:"h-3 w-3"}),c.jsx("span",{className:"absolute -right-1 -top-1 min-w-[14px] rounded-full bg-primary px-1 text-2xs font-semibold leading-[14px] text-primary-foreground",children:Se.aheadCount})]}):null]}),le&&Se&&c.jsxs("div",{className:"px-2 py-1.5 border-b bg-muted/5 shrink-0 space-y-1.5",children:[c.jsxs("div",{className:"relative",children:[c.jsx(r4,{className:"min-h-[68px] resize-none pr-9 text-sm",rows:2,placeholder:"Commit message",value:or,onChange:G=>xe(G.target.value),onKeyDown:G=>{G.key==="Enter"&&(G.ctrlKey||G.metaKey)&&(G.preventDefault(),Kr==="sync"?ha():Pn>0&&Ua("commit"))},disabled:Wt||_t}),c.jsx("button",{className:"absolute top-2 right-2 rounded-md p-1 text-muted-foreground transition-colors hover:bg-accent hover:text-primary disabled:cursor-not-allowed disabled:opacity-40",onClick:qa,disabled:!Qh,title:"Generate commit message with AI",children:_t?c.jsx(ir,{className:"h-3 w-3 animate-spin"}):c.jsx(Y_,{className:"h-3 w-3"})})]}),c.jsxs("div",{className:"flex items-center gap-1 flex-wrap min-w-0",children:[ci(),Ls()]}),Be&&c.jsx("div",{className:"ui-caption px-0.5 text-red-500",children:Be})]}),c.jsxs(gh,{className:"flex-1 min-h-0",children:[Et&&!Se&&c.jsxs("div",{className:"flex items-center justify-center gap-2 p-4 text-xs text-muted-foreground",children:[c.jsx(ir,{className:"h-3 w-3 animate-spin"}),"Loading..."]}),Se&&Pn===0&&c.jsx("div",{className:"p-3 text-xs text-muted-foreground text-center",children:"No changes detected."}),Se&&Pn>0&&c.jsxs("div",{className:"p-1",children:[c.jsxs("div",{className:"ui-eyebrow px-2 py-1",children:["Source Control (",Pn,")",c.jsxs("span",{className:"normal-case tracking-normal ml-1",children:[c.jsxs("span",{className:"text-green-500",children:["+",Se.index.insertions+Se.workingTree.insertions]})," ",c.jsxs("span",{className:"text-red-500",children:["-",Se.index.deletions+Se.workingTree.deletions]})]})]}),ga("Staged",zn,_o,Se.index,"unstage"),ga("Changes",ki,ma,Se.workingTree,"stage")]}),!le&&c.jsx("div",{className:"p-3 text-xs text-muted-foreground text-center",children:"Open a workspace to see git changes."})]})]})]})}),p&&!It&&!vt.collapsed&&uo&&c.jsx("div",{className:"relative w-2 -mx-0.5 shrink-0 cursor-col-resize touch-none sash-handle",onPointerDown:nt.onPointerDown,onDoubleClick:nt.collapsed?()=>nt.restore():void 0,children:c.jsx("div",{className:`absolute inset-y-0 left-1/2 w-px -translate-x-1/2 transition-[background-color] duration-100 ease-out ${nt.isDragging?"bg-primary/50":"bg-border/60"}`})}),uo&&c.jsxs("div",{className:It?"absolute inset-0 z-20 flex flex-col bg-background":"flex-1 min-w-0 min-h-0 flex flex-col",children:[c.jsxs("div",{className:"flex items-center h-[35px] bg-[var(--tab-bg,hsl(var(--muted)/0.3))] border-b shrink-0 min-w-0",children:[!Mc&&(p||v)&&c.jsx("button",{onClick:()=>{nt.collapsed?nt.restore():v&&v()},className:"flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors rounded px-1.5 py-0.5 hover:bg-muted shrink-0 ml-1",title:"Show Files",children:c.jsx(iD,{className:"h-3 w-3"})}),c.jsx("div",{ref:Xe,className:"flex items-center flex-1 min-w-0 overflow-x-auto scrollbar-none",onWheel:G=>{G.deltaY!==0&&(G.preventDefault(),Xe.current&&(Xe.current.scrollLeft+=G.deltaY))},children:Ct.map(G=>{const se=G.id===nr,ne=G.type==="diff"&&G.diffMode==="git"&&G.diffEntry?G.diffEntry.status:void 0,pe=G.type!=="preview";return c.jsxs("div",{"data-tab-id":G.id,className:`group relative flex items-center gap-1.5 h-[35px] px-3 border-r border-border/40 cursor-pointer shrink-0 text-xs select-none transition-colors ${se?"bg-background text-foreground":"text-muted-foreground hover:bg-muted/50"}`,onClick:()=>gp(G.id),onContextMenu:ae=>{ae.preventDefault(),Ui({tabId:G.id,x:ae.clientX,y:ae.clientY})},onMouseDown:ae=>{ae.button===1&&(ae.preventDefault(),xo(G.id))},draggable:pe,onDragStart:ae=>{if(!pe){ae.preventDefault();return}Yl(G.id),ae.dataTransfer.effectAllowed=G.type==="file"?"copyMove":"move",ae.dataTransfer.setData("text/jait-tab",G.id),G.type==="file"&&ae.dataTransfer.setData("text/jait-file",JSON.stringify({path:G.path,name:G.label}))},onDragEnd:ae=>{pe&&Uc(ae,G.id)},onDragOver:ae=>{!Us||Us===G.id||(ae.preventDefault(),ae.dataTransfer.dropEffect="move")},onDrop:ae=>{ae.preventDefault();const Pe=ae.dataTransfer.getData("text/jait-tab")||Us;Pe&&(bo(Pe,G.id),Yl(null))},onDragEnter:ae=>{!Us||Us===G.id||(ae.preventDefault(),bo(Us,G.id))},title:G.path,children:[se&&c.jsx("div",{className:"absolute bottom-0 left-0 right-0 h-[2px] bg-primary"}),Us===G.id&&c.jsx("div",{className:"absolute inset-0 border border-primary/60 pointer-events-none"}),ne?c.jsx(o_,{status:ne,className:"text-2xs"}):G.type==="architecture"?c.jsx(G_,{className:"h-3.5 w-3.5 shrink-0"}):G.type==="preview"?c.jsx(_i,{className:"h-3.5 w-3.5 shrink-0"}):c.jsx(jo,{filename:G.path,className:"h-3.5 w-3.5 shrink-0"}),G.isDirty&&c.jsx("span",{className:"shrink-0 text-2xs leading-none text-primary",children:"*"}),c.jsx("span",{className:"truncate max-w-[220px]",children:r1(G)}),c.jsx("button",{className:`p-0.5 rounded-sm hover:bg-foreground/10 shrink-0 transition-opacity ${se?"opacity-50 hover:opacity-100":"opacity-0 group-hover:opacity-50 hover:!opacity-100"}`,onClick:ae=>{ae.stopPropagation(),xo(G.id)},title:"Close (Middle-click)",children:c.jsx(Jn,{className:"h-3 w-3"})})]},G.id)})}),(In||(Ee==null?void 0:Ee.type)==="preview"||b||Ws)&&c.jsxs("div",{className:"flex items-center shrink-0",children:[Ws&&c.jsx("button",{onClick:()=>jt(G=>!G),className:"flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors rounded px-1.5 py-0.5 hover:bg-muted shrink-0",title:It?"Restore tab size":"Maximize active tab",children:It?c.jsx(TR,{className:"h-3 w-3"}):c.jsx(r0e,{className:"h-3 w-3"})}),In&&c.jsx("button",{onClick:()=>{nr&&cp(nr)},className:"flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors rounded px-1.5 py-0.5 hover:bg-muted shrink-0",title:Ee!=null&&Ee.isSaving?"Saving...":"Save file (Ctrl/Cmd+S)",disabled:Ee==null?void 0:Ee.isSaving,children:c.jsx(AR,{className:`h-3 w-3 ${Ee!=null&&Ee.isSaving?"animate-pulse":""}`})}),(Ee==null?void 0:Ee.type)==="preview"&&c.jsxs(c.Fragment,{children:[c.jsx("button",{onClick:jl,className:"flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors rounded px-1.5 py-0.5 hover:bg-muted shrink-0",title:"Refresh preview",children:c.jsx(Zo,{className:"h-3 w-3"})}),c.jsx("button",{onClick:()=>Vh(G=>!G),className:"flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors rounded px-1.5 py-0.5 hover:bg-muted shrink-0",title:"Preview controls",children:c.jsx(kN,{className:"h-3 w-3"})})]}),b&&!vt.collapsed&&!vt.maxCollapsed&&c.jsx("button",{onClick:b,className:"flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors rounded px-1.5 py-0.5 hover:bg-muted shrink-0 mx-1",children:c.jsx(mh,{className:"h-3 w-3"})}),vt.maxCollapsed&&c.jsx("button",{onClick:vt.restore,className:"flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors rounded px-1.5 py-0.5 hover:bg-muted shrink-0",title:"Show Chat",children:c.jsx(Sm,{className:"h-3 w-3"})})]})]}),In&&(Ee==null?void 0:Ee.saveError)&&c.jsx("div",{className:"border-b bg-destructive/5 px-3 py-1 text-xs text-destructive shrink-0",children:Ee.saveError}),c.jsx("div",{className:"flex-1 min-h-0",children:ar?c.jsxs("div",{className:"h-full flex items-center justify-center text-sm text-muted-foreground gap-2",children:[c.jsx(ir,{className:"h-4 w-4 animate-spin"}),"Loading diff..."]}):(Ee==null?void 0:Ee.type)==="diff"&&Ee.diffMode==="review"?c.jsx(WF,{filePath:Ee.path,originalContent:Ee.originalContent??"",modifiedContent:Ee.modifiedContent??"",language:Ee.language??"plaintext",onClose:()=>xo(Ee.id),onApply:G=>{L==null||L(Ee.path,G)}}):(Ee==null?void 0:Ee.type)==="diff"&&Ee.diffMode==="git"?c.jsx(O2,{className:"h-full",editorClassName:"h-full",original:Ee.originalContent??((qc=Ee.diffEntry)==null?void 0:qc.original)??"",modified:Ee.modifiedContent??((Ii=Ee.diffEntry)==null?void 0:Ii.modified)??"",language:Ee.language??ka(Ee.path),modelKey:`${Ee.id}:${Ee.version??0}`,renderSideBySide:!f,options:{minimap:{enabled:!1}}},`${Ee.id}:${Ee.version??0}`):(Ee==null?void 0:Ee.type)==="preview"?ay("Open or start a preview from the side controls."):(Ee==null?void 0:Ee.type)==="architecture"?c.jsx(_O,{diagram:F??null,isGenerating:V,onGenerate:U,onRegenerate:U,theme:re,onRenderResult:Q}):Ye&&(Ee==null?void 0:Ee.id)===nr?c.jsxs("div",{className:"h-full flex items-center justify-center text-sm text-muted-foreground gap-2",children:[c.jsx(ir,{className:"h-4 w-4 animate-spin"}),"Loading..."]}):(Ee==null?void 0:Ee.type)==="file"?c.jsx(Eoe,{path:Ee.path,language:Ee.language??"plaintext",value:Ee.content??"",originalContent:Ee.originalContent,theme:ie,readOnly:!Nk(Ee),onChange:G=>cg(Ee.id,G),onReferenceSelection:(G,se,ne)=>bp({id:Ee.id,name:r1(Ee),path:Ee.path,content:Ee.content??"",language:Ee.language??"plaintext"},G,se,ne),onApplyReview:async G=>{await(L==null?void 0:L(Ee.path,G)),Xt(se=>se.map(ne=>ne.id===Ee.id?{...ne,content:G,modifiedContent:G,savedContent:G,originalContent:null,isDirty:!1}:ne))}},Ee.id):Di?c.jsx(Oj,{height:"100%",beforeMount:C0,theme:ie,path:Di.path,language:Di.language,value:Di.content,onMount:G=>{const se=()=>{var Ae,He;const ne=(Ae=G.getModel)==null?void 0:Ae.call(G),pe=(He=G.getSelection)==null?void 0:He.call(G);if(!ne||!pe||pe.isEmpty()){ot.current=null;return}const ae=ne.getValueInRange(pe).trim();if(!ae){ot.current=null;return}const Pe=`${Di.path}:${pe.startLineNumber}:${pe.endLineNumber}:${ae}`;ot.current!==Pe&&(ot.current=Pe,a==null||a({id:Di.path,name:Di.path.split("/").pop()??Di.path,path:Di.path,content:Di.content,language:Di.language},ae,pe.startLineNumber,pe.endLineNumber))};G.onMouseUp(()=>window.setTimeout(se,0)),G.onKeyUp(()=>window.setTimeout(se,0))},options:{readOnly:!0,minimap:{enabled:!1},fontSize:13,automaticLayout:!0}}):c.jsx("div",{className:"h-full flex items-center justify-center text-sm text-muted-foreground text-center",children:"Open a file from the explorer to preview it here."})})]}),(Ai==null?void 0:Ai.active)&&c.jsxs("div",{className:"pointer-events-none fixed z-50 rounded-md border bg-background/95 px-2 py-1 text-xs shadow-lg",style:{left:Ai.x+12,top:Ai.y+12},children:["Move ",Ai.node.name]}),Gn&&c.jsxs("div",{className:"ui-panel-surface fixed z-50 min-w-[170px] py-1",style:{left:Gn.x,top:Gn.y},onPointerDown:G=>G.stopPropagation(),children:[c.jsx("button",{className:"ui-menu-item",onClick:()=>xo(Gn.tabId),children:"Close"}),c.jsx("button",{className:"ui-menu-item",disabled:(($u=Ct.find(G=>G.id===Gn.tabId))==null?void 0:$u.type)==="preview",onClick:()=>{Wc(Gn.tabId)},children:"Move to New Window"}),c.jsx("button",{className:"ui-menu-item",disabled:Ct.length<=1,onClick:()=>Wo(Gn.tabId),children:"Close Others"}),c.jsx("button",{className:"ui-menu-item",disabled:yp<0||yp>=Ct.length-1,onClick:()=>Mu(Gn.tabId),children:"Close to the Right"}),c.jsx("div",{className:"my-1 h-px bg-border"}),c.jsx("button",{className:"ui-menu-item",disabled:Ct.length===0,onClick:Ks,children:"Close All"})]}),Zt&&(f?c.jsxs("div",{className:"fixed inset-0 z-50",onPointerDown:()=>hn(null),children:[c.jsx("div",{className:"absolute inset-0 bg-black/30"}),c.jsxs("div",{ref:Od,className:"ui-panel-surface absolute inset-x-3 bottom-3 max-h-[70vh] overflow-auto rounded-2xl p-2",onPointerDown:G=>G.stopPropagation(),children:[c.jsx("div",{className:"px-3 py-2 text-xs font-medium uppercase tracking-[0.08em] text-muted-foreground",children:Zt.node.name}),c.jsxs("button",{className:"ui-menu-item",onClick:()=>{Zh(Zt.node),hn(null)},children:[c.jsx(Ro,{className:"h-3 w-3"}),"Add to Chat"]}),Zt.node.kind==="file"&&c.jsx("button",{className:"ui-menu-item",onClick:()=>{const G=Zt.node;la(G),hn(null)},children:"Open"}),c.jsx("div",{className:"my-1 h-px bg-border"}),c.jsxs("button",{className:"ui-menu-item",onClick:()=>{const G=Zt.node.kind==="dir"?Zt.node.path:Zt.node.path.includes("/")?Zt.node.path.slice(0,Zt.node.path.lastIndexOf("/")):le??"";Vs({parentDir:G,kind:"file"}),na(""),hn(null)},children:[c.jsx(eC,{className:"h-3 w-3"}),"New File"]}),c.jsxs("button",{className:"ui-menu-item",onClick:()=>{const G=Zt.node.kind==="dir"?Zt.node.path:Zt.node.path.includes("/")?Zt.node.path.slice(0,Zt.node.path.lastIndexOf("/")):le??"";Vs({parentDir:G,kind:"dir"}),na(""),hn(null)},children:[c.jsx(wN,{className:"h-3 w-3"}),"New Folder"]}),c.jsx("div",{className:"my-1 h-px bg-border"}),c.jsxs("button",{className:"ui-menu-item",onClick:()=>{ho({path:Zt.node.path,name:Zt.node.name,kind:Zt.node.kind==="dir"?"dir":"file"}),Lc(Zt.node.name),hn(null)},children:[c.jsx(SN,{className:"h-3 w-3"}),"Rename"]}),c.jsxs("button",{className:"ui-menu-item text-red-500 hover:text-red-600",onClick:()=>{Jh(Zt.node),hn(null)},children:[c.jsx(Sh,{className:"h-3 w-3"}),"Delete"]}),c.jsx("div",{className:"my-1 h-px bg-border"}),c.jsxs("button",{className:"ui-menu-item",onClick:()=>{Cl(Zt.node),hn(null)},children:[c.jsx(wc,{className:"h-3 w-3"}),"Copy Path"]}),c.jsxs("button",{className:"ui-menu-item",onClick:()=>{tc(Zt.node),hn(null)},children:[c.jsx(wc,{className:"h-3 w-3"}),"Copy Relative Path"]})]})]}):c.jsxs("div",{ref:Od,className:"ui-panel-surface fixed z-50 min-w-[180px] py-1",style:{left:(is==null?void 0:is.left)??Zt.x,top:(is==null?void 0:is.top)??Zt.y,visibility:is?"visible":"hidden"},onPointerDown:G=>G.stopPropagation(),children:[c.jsxs("button",{className:"ui-menu-item",onClick:()=>{Zh(Zt.node),hn(null)},children:[c.jsx(Ro,{className:"h-3 w-3"}),"Add to Chat"]}),Zt.node.kind==="file"&&c.jsx("button",{className:"ui-menu-item",onClick:()=>{const G=Zt.node;la(G),hn(null)},children:"Open"}),c.jsx("div",{className:"my-1 h-px bg-border"}),c.jsxs("button",{className:"ui-menu-item",onClick:()=>{const G=Zt.node.kind==="dir"?Zt.node.path:Zt.node.path.includes("/")?Zt.node.path.slice(0,Zt.node.path.lastIndexOf("/")):le??"";Vs({parentDir:G,kind:"file"}),na(""),hn(null)},children:[c.jsx(eC,{className:"h-3 w-3"}),"New File"]}),c.jsxs("button",{className:"ui-menu-item",onClick:()=>{const G=Zt.node.kind==="dir"?Zt.node.path:Zt.node.path.includes("/")?Zt.node.path.slice(0,Zt.node.path.lastIndexOf("/")):le??"";Vs({parentDir:G,kind:"dir"}),na(""),hn(null)},children:[c.jsx(wN,{className:"h-3 w-3"}),"New Folder"]}),c.jsx("div",{className:"my-1 h-px bg-border"}),c.jsxs("button",{className:"ui-menu-item",onClick:()=>{ho({path:Zt.node.path,name:Zt.node.name,kind:Zt.node.kind==="dir"?"dir":"file"}),Lc(Zt.node.name),hn(null)},children:[c.jsx(SN,{className:"h-3 w-3"}),"Rename"]}),c.jsxs("button",{className:"ui-menu-item text-red-500 hover:text-red-600",onClick:()=>{Jh(Zt.node),hn(null)},children:[c.jsx(Sh,{className:"h-3 w-3"}),"Delete"]}),c.jsx("div",{className:"my-1 h-px bg-border"}),c.jsxs("button",{className:"ui-menu-item",onClick:()=>{Cl(Zt.node),hn(null)},children:[c.jsx(wc,{className:"h-3 w-3"}),"Copy Path"]}),c.jsxs("button",{className:"ui-menu-item",onClick:()=>{tc(Zt.node),hn(null)},children:[c.jsx(wc,{className:"h-3 w-3"}),"Copy Relative Path"]})]})),_s&&c.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/30",onPointerDown:()=>ho(null),children:c.jsxs("div",{className:"ui-panel-surface min-w-[320px] p-4",onPointerDown:G=>G.stopPropagation(),children:[c.jsxs("div",{className:"mb-2 text-sm font-medium",children:['Rename "',_s.name,'"']}),c.jsx(Hn,{className:"h-10 text-sm",autoFocus:!0,value:Pc,onChange:G=>Lc(G.target.value),onKeyDown:G=>{G.key==="Enter"&&ua(),G.key==="Escape"&&ho(null)}}),c.jsxs("div",{className:"mt-3 flex justify-end gap-1.5",children:[c.jsx(_e,{variant:"ghost",size:"sm",className:"h-8 rounded-md px-3 text-xs",onClick:()=>ho(null),children:"Cancel"}),c.jsx(_e,{size:"sm",className:"h-8 rounded-md px-3 text-xs",onClick:()=>void ua(),children:"Rename"})]})]})}),ai&&c.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/30",onPointerDown:()=>Vs(null),children:c.jsxs("div",{className:"ui-panel-surface min-w-[320px] p-4",onPointerDown:G=>G.stopPropagation(),children:[c.jsxs("div",{className:"mb-2 text-sm font-medium",children:["New ",ai.kind==="dir"?"Folder":"File"]}),c.jsx(Hn,{className:"h-10 text-sm",autoFocus:!0,placeholder:ai.kind==="dir"?"folder-name":"filename.ext",value:Wh,onChange:G=>na(G.target.value),onKeyDown:G=>{G.key==="Enter"&&mi(),G.key==="Escape"&&Vs(null)}}),c.jsxs("div",{className:"mt-3 flex justify-end gap-1.5",children:[c.jsx(_e,{variant:"ghost",size:"sm",className:"h-8 rounded-md px-3 text-xs",onClick:()=>Vs(null),children:"Cancel"}),c.jsx(_e,{size:"sm",className:"h-8 rounded-md px-3 text-xs",onClick:()=>void mi(),children:"Create"})]})]})}),g&&c.jsxs("div",{className:`${It&&!vt.collapsed?"absolute right-0 inset-y-0 w-2 z-30":vt.collapsed?"absolute left-0 inset-y-0 w-2 z-30":"relative w-2 -mx-0.5 shrink-0"} cursor-col-resize touch-none sash-handle`,onPointerDown:vt.onPointerDown,onDoubleClick:vt.collapsed||vt.maxCollapsed?vt.restore:void 0,children:[c.jsx("div",{className:`absolute inset-y-0 left-1/2 w-px -translate-x-1/2 transition-[background-color] duration-100 ease-out ${vt.isDragging?"bg-primary/50":"bg-border/60"}`}),c.jsx("style",{children:`.sash-handle:hover > div { background-color: hsl(var(--primary) / 0.4) !important; transition-delay: 300ms; }
|
|
@@ -1157,7 +1157,7 @@ ${e.themeCSS}`),e.fontFamily!==void 0&&(n+=`
|
|
|
1157
1157
|
`),n=(u=r.find(p=>p.startsWith("URL: ")))==null?void 0:u.replace("URL: ","").trim(),i=(f=r.find(p=>p.startsWith("Title: ")))==null?void 0:f.replace("Title: ","").trim(),s=r.findIndex(p=>p.trim()==="Interactive elements:"),o=s>=0?r.slice(0,s):r,a=o.findIndex(p=>p.trim()==="Text:"),l=a>=0?o.slice(a+1).join(`
|
|
1158
1158
|
`).trim():"",d=s>=0?r.slice(s+1).map(p=>p.trim()).filter(Boolean):[];return c.jsxs("div",{className:"space-y-2 rounded-md border bg-muted/20 p-3 text-xs",children:[c.jsxs("div",{children:[c.jsx("div",{className:"font-semibold text-foreground/90",children:"Browser snapshot"}),i?c.jsx("div",{className:"text-muted-foreground",children:i}):null,n?c.jsx("div",{className:"font-mono text-xs break-all",children:n}):null]}),c.jsxs("div",{children:[c.jsx("div",{className:"mb-1 text-xs uppercase tracking-wide text-muted-foreground",children:"Text"}),c.jsx("pre",{className:"max-h-40 overflow-auto whitespace-pre-wrap rounded bg-background p-2 font-mono text-xs leading-5",children:l||"(no textual content)"})]}),c.jsxs("div",{children:[c.jsx("div",{className:"mb-1 text-xs uppercase tracking-wide text-muted-foreground",children:"Interactive elements"}),d.length?c.jsx("ul",{className:"max-h-40 space-y-1 overflow-auto rounded bg-background p-2 font-mono text-xs",children:d.map((p,g)=>c.jsx("li",{className:"break-all",children:p},`${p}-${g}`))}):c.jsx("div",{className:"rounded bg-background p-2 text-muted-foreground",children:"No interactive elements found."})]})]})}function dXe({path:e}){const[r,n]=y.useState(!1),[i,s]=y.useState(!1),o=e.trim(),a=Moe(o)??`${$n()}/api/browser/screenshot?path=${encodeURIComponent(o)}`;return c.jsxs("div",{className:"space-y-2 rounded-md bg-muted/30 p-3 text-xs",children:[c.jsxs("div",{className:"text-xs text-muted-foreground",children:["Screenshot path: ",c.jsx("span",{className:"font-mono break-all",children:o})]}),c.jsxs("div",{className:"group relative overflow-hidden rounded-md bg-background/90 ring-1 ring-inset ring-border/35",children:[c.jsx("img",{src:a,alt:"Browser screenshot",className:"max-h-80 w-full cursor-pointer object-contain transition-opacity group-hover:opacity-80",onLoad:()=>n(!0),onError:()=>n(!1),onClick:()=>r&&s(!0)}),r&&c.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center opacity-0 transition-opacity group-hover:opacity-100",children:c.jsx("span",{className:"rounded-full bg-black/60 px-3 py-1.5 text-xs font-medium text-white",children:"Click to expand"})})]}),!r&&c.jsx("div",{className:"rounded bg-background p-2 text-muted-foreground",children:"Preview unavailable in browser. Open the screenshot path directly from the host environment."}),i&&c.jsx(Td,{open:!0,onOpenChange:l=>!l&&s(!1),children:c.jsx(ku,{className:"max-w-[90vw] max-h-[90vh] p-2",showCloseButton:!0,children:c.jsx("img",{src:a,alt:"Browser screenshot",className:"max-h-[85vh] w-full object-contain"})})})]})}function NC(e){var i;const r=typeof e.args.terminalId=="string"?e.args.terminalId:null;if(r)return r;const n=(i=e.result)==null?void 0:i.data;if(n&&typeof n=="object"){const s=n,o=typeof s.terminalId=="string"?s.terminalId:null;if(o)return o;const a=typeof s.id=="string"?s.id:null;if(a)return a;const l=typeof s.surfaceId=="string"?s.surfaceId:null;if(l)return l}return null}function hXe(e){var n;const r=Ba(e.tool);if(r==="surfaces.start"){if(e.args.type==="terminal")return NC(e)!==null;const i=(n=e.result)==null?void 0:n.data;return i&&typeof i=="object"&&i.type==="terminal"?NC(e)!==null:!1}return r==="execute"||r.startsWith("terminal.")?NC(e)!==null:!1}function Hoe(e){if(!e)return null;const r=e.match(/"command"\s*:\s*"((?:[^"\\]|\\.)*)/);return r?r[1].replace(/\\n/g,`
|
|
1159
1159
|
`).replace(/\\t/g," ").replace(/\\"/g,'"').replace(/\\\\/g,"\\"):null}function cu(e,r){if(!e)return null;const n=r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),i=new RegExp(`"${n}"\\s*:\\s*"((?:[^"\\\\]|\\\\.)*)`),s=e.match(i);return s?s[1].replace(/\\n/g,`
|
|
1160
|
-
`).replace(/\\t/g," ").replace(/\\"/g,'"').replace(/\\\\/g,"\\"):null}function Woe(e){if(!e)return null;const r=cu(e,"url")??cu(e,"uri")??cu(e,"href")??cu(e,"query")??cu(e,"q");if(r)return zf(r)??r;const n=cu(e,"type"),i=cu(e,"action");return n==="webSearch"||i==="webSearch"?"web search":n==="fetch"||i==="fetch"?"website":null}function fXe({tool:e,streamingArgs:r}){const n=Ba(e),i=Ioe[n],s=n.startsWith("terminal."),o=s?Hoe(r):null,a=n==="web"||n==="web.search"||n==="web.fetch"||n==="browser.search"||n==="browser.fetch",l=a?Woe(r):null;return i&&s&&o?c.jsxs("span",{className:"inline-flex max-w-full min-w-0 items-center gap-1.5 text-foreground",children:[c.jsx("span",{className:"shrink-0 text-xs text-emerald-500 dark:text-emerald-400 font-mono",children:"$"}),c.jsx("code",{className:"min-w-0 truncate text-xs font-mono",children:o}),c.jsx("span",{className:"inline-block w-1 h-3.5 bg-blue-400 animate-pulse ml-0.5 align-text-bottom"})]}):i&&a&&l?c.jsxs("span",{className:"inline-flex max-w-full min-w-0 items-center gap-1.5 text-foreground",children:[c.jsxs("span",{children:[i.label,":"]}),c.jsx("code",{className:"min-w-0 truncate text-xs font-mono",children:l}),c.jsx("span",{className:"inline-block w-1 h-3.5 bg-blue-400 animate-pulse ml-0.5 align-text-bottom"})]}):i?c.jsxs("span",{className:"text-blue-400",children:[i.label,c.jsx("span",{className:"inline-block w-1 h-3 bg-blue-400 animate-pulse ml-1 align-text-bottom"})]}):e?c.jsxs("span",{className:"text-blue-400",children:[c.jsx("code",{className:"text-xs font-mono",children:e}),c.jsx("span",{className:"inline-block w-1 h-3 bg-blue-400 animate-pulse ml-0.5 align-text-bottom"})]}):c.jsx("span",{className:"text-muted-foreground",children:"Preparing..."})}function pXe({tool:e,streamingArgs:r,scrollRef:n}){const i=Ba(e),s=i.startsWith("terminal."),o=s?Hoe(r):null,a=i==="web"||i==="web.search"||i==="web.fetch"||i==="browser.search"||i==="browser.fetch",l=a?Woe(r):null;if(s&&o)return c.jsxs("pre",{ref:n,className:We("text-xs font-mono leading-5 rounded-md px-3 py-2 overflow-x-auto max-h-64 overflow-y-auto whitespace-pre-wrap break-all","bg-muted/40 text-foreground"),children:[c.jsx("span",{className:"text-emerald-400",children:"$ "}),o,c.jsx("span",{className:"inline-block w-1.5 h-3.5 bg-blue-400 animate-pulse ml-0.5 align-text-bottom"})]});if(a&&l){const d=i==="web.search"||i==="browser.search"?"Searching":"Fetching";return c.jsx("div",{className:We("rounded-md border px-3 py-2 text-xs","bg-muted/40 text-foreground"),children:c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(ir,{className:"h-3 w-3 animate-spin text-blue-400"}),c.jsxs("span",{children:[d," ",l,"..."]})]})})}if(i==="memory.save"){const d=cu(r,"scope")??"memory",u=cu(r,"content");return c.jsxs("div",{className:We("rounded-md border px-3 py-2 text-xs","bg-muted/40 text-foreground"),children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(ir,{className:"h-3 w-3 animate-spin text-blue-400"}),c.jsxs("span",{children:["Saving memory (",d,")..."]})]}),u?c.jsxs("div",{className:"mt-1 opacity-80",children:['"',cd(u,120),'"']}):null]})}if(i==="cron.add"){const d=cu(r,"name"),u=cu(r,"cron"),f=cu(r,"toolName");return c.jsxs("div",{className:We("rounded-md border px-3 py-2 text-xs","bg-muted/40 text-foreground"),children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(ir,{className:"h-3 w-3 animate-spin text-blue-400"}),c.jsxs("span",{children:["Creating cron job",d?`: ${d}`:"..."]})]}),(u||f)&&c.jsxs("div",{className:"mt-1 opacity-80",children:[u?`schedule ${u}`:"",u&&f?" • ":"",f?`tool ${f}`:""]})]})}return r?c.jsxs("pre",{ref:n,className:We("text-xs font-mono leading-5 rounded-md px-3 py-2 overflow-x-auto max-h-36 overflow-y-auto whitespace-pre-wrap break-all","bg-muted/40 text-muted-foreground"),children:[r,c.jsx("span",{className:"inline-block w-1.5 h-3.5 bg-blue-400 animate-pulse ml-0.5 align-text-bottom"})]}):c.jsx("div",{className:We("rounded-md border px-3 py-2 text-xs","bg-muted/40 text-foreground"),children:c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(ir,{className:"h-3 w-3 animate-spin text-blue-400"}),c.jsx("span",{children:"Preparing..."})]})})}function Uoe(e){const r=new Map,n=new Set,i=new Map(e.map(s=>[s.callId,s]));for(const s of e){if(!s.parentCallId||!i.has(s.parentCallId))continue;const o=r.get(s.parentCallId)??[];r.set(s.parentCallId,[...o,s]),n.add(s.callId)}for(let s=0;s<e.length;s++){const o=e[s];if(Ba(o.tool)!=="agent")continue;const a=[];for(let l=s+1;l<e.length;l++){const d=e[l];if(n.has(d.callId))continue;const u=o.status==="running"||o.status==="pending",f=o.completedAt!=null&&d.startedAt<=o.completedAt;if(u||f)a.push(d),n.add(d.callId);else break}if(a.length>0){const l=r.get(o.callId)??[];r.set(o.callId,[...l,...a])}}return{childMap:r,parentSet:n}}function Voe(e){return e==="browserScreenshot"}function qoe(e){var o,a;const r=Ba(e.tool),n=(o=e.result)!=null&&o.data&&typeof e.result.data=="object"?e.result.data:void 0,i=yu(r,e.args,n),s=$oe(r,i,n,(a=e.result)==null?void 0:a.message);return Voe(Doe({tool:r,args:i,status:e.status,displayOutput:Foe(e.result,r)||e.streamingOutput||"",snapshotText:typeof(n==null?void 0:n.snapshot)=="string"?n.snapshot:null,screenshotPath:s}))}function mXe({path:e,onOpenDiff:r,disabled:n}){const i=rP(e),s=!!r&&!n,o=c.jsxs(c.Fragment,{children:[c.jsx(jo,{filename:i,className:"h-3.5 w-3.5 shrink-0"}),c.jsx("span",{className:"max-w-[220px] truncate",children:i})]});return s?c.jsx("span",{role:"button",tabIndex:0,className:"inline-flex max-w-full items-center gap-1.5 rounded-md border border-border/70 bg-muted/45 px-2 py-1 text-xs font-medium leading-none text-foreground transition-colors hover:bg-muted cursor-pointer",title:`Open diff for ${e}`,onClick:a=>{a.preventDefault(),a.stopPropagation(),r(e)},onKeyDown:a=>{(a.key==="Enter"||a.key===" ")&&(a.preventDefault(),a.stopPropagation(),r(e))},children:o}):c.jsx("span",{className:"inline-flex max-w-full items-center gap-1.5 rounded-md border border-border/70 bg-muted/45 px-2 py-1 text-xs font-medium leading-none text-foreground",title:e,children:o})}function gXe({call:e,childCalls:r,onOpenTerminal:n,onOpenDiff:i,hideTopConnector:s=!1,hideBottomConnector:o=!1}){var ge,le,et,Xe,De,de,Qe,Ie,Oe;const a=qoe(e),[l,d]=y.useState(e.status==="running"||e.status==="pending"||a),[u,f]=y.useState(()=>Date.now()),p=y.useRef(e.status),g=Ba(e.tool),v=(ge=e.result)!=null&&ge.data&&typeof e.result.data=="object"?e.result.data:void 0,b=yu(g,e.args,v),_=g==="mcp-tool"?tP(b,v):null,k=_?GYe(_.title):null,w=Boe(g),C=(k==null?void 0:k.icon)??w.icon,j=(k==null?void 0:k.color)??w.color,N=QYe(g,b,v,(le=e.result)==null?void 0:le.message),A=TO(g,b),R=Foe(e.result,g)||e.streamingOutput||"",L=typeof(v==null?void 0:v.snapshot)=="string"?v.snapshot:null,z=$oe(g,b,v,(et=e.result)==null?void 0:et.message),$=g.startsWith("terminal.")||g==="execute",W=lXe(e),B=hXe(e),K=B?NC(e):null,M=oXe(g,b),I=e.status==="pending",P=((De=NO(g,b,v,(Xe=e.result)==null?void 0:Xe.message))==null?void 0:De.trim())??"",F=!!P&&XYe(g),V=aH(R),Y=aH(e.streamingArgs),H=Doe({tool:g,args:b,status:e.status,displayOutput:R,snapshotText:L,screenshotPath:z}),U=Voe(H),Q=H==="terminal"?!0:H!=="none"&&!U,q=e.status==="pending"||e.status==="running"?ir:e.status==="success"?ql:Ah,ee=e.status==="pending"?"text-blue-400":e.status==="running"?"text-muted-foreground":e.status==="success"?"text-green-500":"text-red-500";y.useEffect(()=>{const qe=p.current;!U&&(qe==="running"||qe==="pending")&&e.status!=="running"&&e.status!=="pending"&&d(!1),(e.status==="pending"||e.status==="running"||U)&&d(!0),p.current=e.status},[e.status,U]),y.useEffect(()=>{var qe;g!=="web"&&g!=="web.search"&&g!=="web.fetch"&&g!=="browser.search"&&g!=="browser.fetch"||console.debug("[tool-call-card:web]",{tool:e.tool,normalizedTool:g,callId:e.callId,status:e.status,rawArgs:e.args,normalizedArgs:b,resultMessage:(qe=e.result)==null?void 0:qe.message,resultData:v,streamingArgs:e.streamingArgs})},[e.args,e.callId,(de=e.result)==null?void 0:de.message,e.status,e.streamingArgs,e.tool,b,g,v]),y.useEffect(()=>{if(e.status!=="running"&&e.status!=="pending")return;const qe=window.setInterval(()=>f(Date.now()),250);return()=>window.clearInterval(qe)},[e.status]);const te=qYe(g,b,v,(Qe=e.result)==null?void 0:Qe.message),fe=e.status==="running"||e.status==="pending"?te.running:te.done,re=c.jsxs(c.Fragment,{children:[c.jsx(q,{className:We("h-4 w-4 shrink-0",ee,(e.status==="running"||e.status==="pending")&&"animate-spin")}),c.jsx("span",{className:"flex-1 truncate text-[13px] font-medium text-muted-foreground",children:I?c.jsx(fXe,{tool:e.tool,streamingArgs:e.streamingArgs}):$?c.jsxs("span",{className:"inline-flex max-w-full min-w-0 items-center gap-1.5 text-foreground",children:[c.jsx("span",{className:"shrink-0 text-xs text-emerald-500 dark:text-emerald-400 font-mono",children:"$"}),c.jsx("code",{className:"min-w-0 truncate text-xs font-mono",title:N,children:N})]}):F?c.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center gap-2",children:[c.jsxs("span",{children:[fe,":"]}),c.jsx(mXe,{path:P,onOpenDiff:i,disabled:e.status!=="success"})]}):_&&(_.title||_.details)?c.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center gap-2",children:[c.jsxs("span",{children:[fe,":"]}),c.jsxs("span",{className:"min-w-0 truncate",children:[_.title?c.jsx("code",{className:"text-[11px] font-mono",children:_.title}):null,_.title&&_.details?c.jsx("span",{className:"text-muted-foreground",children:" • "}):null,_.details?c.jsx("span",{className:"text-xs text-muted-foreground",children:_.details}):null]})]}):c.jsxs("span",{children:[fe,": ",c.jsx("code",{className:"text-[11px] font-mono",children:N})]})}),c.jsx("span",{className:"text-xs text-muted-foreground/60 tabular-nums shrink-0",children:c.jsx(AO,{startedAt:e.startedAt,completedAt:e.completedAt,now:u})}),A&&c.jsx("span",{className:"rounded border border-blue-500/25 bg-blue-500/10 px-1.5 py-0.5 text-2xs font-semibold tabular-nums text-blue-500 shrink-0",children:A}),W&&c.jsx("span",{className:We("rounded border px-1.5 py-0.5 text-2xs font-semibold uppercase tracking-wide shrink-0",W.className),children:W.label})]}),ie=H==="pending"?c.jsx(pXe,{tool:e.tool,streamingArgs:e.streamingArgs,scrollRef:Y}):H==="terminal"?c.jsxs("pre",{ref:V,className:We("text-xs font-mono leading-5 rounded-md px-3 py-2 overflow-x-auto max-h-64 overflow-y-auto whitespace-pre-wrap break-all","bg-muted/40 text-foreground",e.result&&!e.result.ok&&"text-red-500 dark:text-red-400"),children:[!R&&e.status!=="running"&&c.jsxs("span",{className:"text-muted-foreground",children:[c.jsx("span",{className:"text-emerald-500 dark:text-emerald-400",children:"$ "}),N]}),R,e.status==="running"&&!R&&c.jsx("span",{className:"text-muted-foreground",children:"Running..."}),e.status==="running"&&c.jsx("span",{className:"inline-block w-1.5 h-3.5 bg-foreground animate-pulse ml-0.5 align-text-bottom"})]}):H==="browserSnapshot"?c.jsx(uXe,{snapshot:L}):H==="browserScreenshot"?c.jsx(dXe,{path:z}):H==="subagent"?r&&r.length>0?c.jsxs("div",{className:"rounded-lg border border-purple-500/20 bg-purple-500/[0.03] text-xs",children:[(e.status==="running"||e.status==="pending")&&r.length>0&&c.jsxs("div",{className:"flex items-center justify-end gap-2 border-b border-purple-500/15 px-3 py-2 text-xs text-muted-foreground",children:[c.jsx(ir,{className:"h-3 w-3 animate-spin text-purple-500"}),c.jsxs("span",{children:[r.length," tool",r.length!==1?"s":""]})]}),(e.status==="running"||e.status==="pending")&&r.length===0&&c.jsx("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:"Agent is working..."}),c.jsx("div",{className:"divide-y divide-border/30",children:r.map(qe=>c.jsx(Ff,{call:qe,onOpenTerminal:n,onOpenDiff:i},qe.callId))}),((Ie=e.result)==null?void 0:Ie.message)&&(e.status==="success"||e.status==="error")&&c.jsxs("div",{className:"border-t border-purple-500/15 px-3 py-2",children:[c.jsx("div",{className:"mb-1 text-xs font-medium text-muted-foreground",children:"Result"}),c.jsx("pre",{className:"max-h-48 overflow-auto whitespace-pre-wrap rounded bg-background/60 p-2 font-mono text-xs leading-5",children:e.result.message})]})]}):c.jsx(cXe,{data:v??{},message:(Oe=e.result)==null?void 0:Oe.message,status:e.status}):H==="editDiff"?c.jsx(DYe,{filePath:String(b.path??""),oldText:g==="file.patch"||g==="edit"&&b.search!=null?String(b.search??""):void 0,newText:g==="file.patch"||g==="edit"&&b.replace!=null?String(b.replace??""):void 0,writtenContent:g==="file.write"||g==="edit"&&b.content!=null?String(b.content??""):void 0,isNewFile:g==="file.write"}):H==="output"?c.jsxs("pre",{className:We("text-xs font-mono leading-5 rounded-md px-3 py-2 overflow-x-auto max-h-64 overflow-y-auto whitespace-pre-wrap break-all","bg-muted/40 text-foreground",e.result&&!e.result.ok&&"text-red-500 dark:text-red-400"),children:[R,e.status==="running"&&c.jsx("span",{className:"inline-block w-1.5 h-3.5 bg-foreground animate-pulse ml-0.5 align-text-bottom"})]}):H==="runningHint"?c.jsxs("div",{className:We("rounded-md border px-3 py-2 text-xs","bg-muted/40 text-foreground"),children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(ir,{className:"h-3 w-3 animate-spin"}),c.jsx("span",{children:M})]}),c.jsxs("div",{className:"mt-1 text-xs opacity-75",children:["Elapsed: ",c.jsx(AO,{startedAt:e.startedAt,completedAt:e.completedAt,now:u})]})]}):null;return c.jsxs(gS,{open:Q?l:!1,onOpenChange:d,children:[c.jsxs("div",{className:"relative pl-7",children:[!s&&c.jsx("span",{className:"absolute left-[10.5px] top-0 h-6 w-px bg-border/60",style:{maskImage:"linear-gradient(to bottom, transparent 0 22px, #000 22px 100%)"},"aria-hidden":"true"}),!o&&c.jsx("span",{className:"absolute left-[10.5px] top-0 bottom-0 w-px bg-border/60",style:{maskImage:"linear-gradient(to bottom, #000 0 5px, transparent 5px 23px, #000 23px 100%)"},"aria-hidden":"true"}),o&&!s&&c.jsx("span",{className:"absolute left-[10.5px] top-0 bottom-0 w-px bg-border/60",style:{maskImage:"linear-gradient(to bottom, #000 0 5px, transparent 5px 100%)"},"aria-hidden":"true"}),c.jsx("div",{className:"absolute left-[5px] top-[9px] z-10 flex h-3 w-3 items-center justify-center",children:c.jsx(C,{className:We("h-3 w-3 shrink-0",j)})}),c.jsx("div",{className:"group pb-1",children:c.jsxs("div",{className:"flex items-center gap-2 rounded-sm px-1 py-1.5 transition-colors hover:bg-muted/20",children:[Q?c.jsxs(yS,{className:"flex min-w-0 flex-1 items-center gap-2 text-left",children:[c.jsx(ao,{className:We("h-3 w-3 shrink-0 text-muted-foreground transition-transform duration-200",l&&"rotate-90")}),re]}):c.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 text-left",children:[c.jsx("span",{className:"h-3 w-3 shrink-0"}),re]}),B&&n&&c.jsxs(un,{children:[c.jsx(dn,{asChild:!0,children:c.jsx(_e,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0",onClick:qe=>{qe.preventDefault(),qe.stopPropagation(),n(K)},children:c.jsx(Uf,{className:"h-3.5 w-3.5"})})}),c.jsx(on,{side:"top",children:"Open terminal"})]}),H==="editDiff"&&i&&e.status==="success"&&P&&c.jsxs(un,{children:[c.jsx(dn,{asChild:!0,children:c.jsx(_e,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0",onClick:qe=>{qe.preventDefault(),qe.stopPropagation(),i(P)},children:c.jsx(Uf,{className:"h-3.5 w-3.5"})})}),c.jsx(on,{side:"top",children:"Open diff in editor"})]})]})})]}),Q&&c.jsx(vS,{children:c.jsx("div",{className:"ml-7 mr-3 mb-2 border-l border-border/40 pl-4",children:ie})}),U&&c.jsx("div",{className:"ml-7 mr-3 mb-2 border-l border-border/40 pl-4",children:ie})]})}const Ff=y.memo(gXe);Ff.displayName="ToolCallCard";const Goe=3,R1=6;function yXe(e,r){if(!r||e.some(qoe))return!1;const n=e.filter(i=>i.status!=="running"&&i.status!=="pending");return n.length>=Goe&&n.length===e.length}function vXe({calls:e,collapsible:r,onOpenTerminal:n,onOpenDiff:i}){const[s,o]=y.useState(!1),[a,l]=y.useState(()=>!yXe(e,r)),d=y.useRef(!1),{childMap:u,parentSet:f}=y.useMemo(()=>Uoe(e),[e]),p=y.useMemo(()=>e.filter(L=>!f.has(L.callId)),[e,f]),g=p.filter(L=>L.status==="running"||L.status==="pending"),v=p.filter(L=>L.status!=="running"&&L.status!=="pending"),b=g.length===0&&v.length>0,_=r&&b&&v.length>=Goe;if(y.useEffect(()=>{_&&!d.current&&l(!1),d.current=b},[b,_]),e.length===0)return null;const k=v.filter(L=>L.status==="success").length,w=v.filter(L=>L.status==="error").length,C=zoe(v);if(_&&!a)return c.jsx("div",{className:"my-2",children:c.jsxs("button",{type:"button",onClick:()=>l(!0),className:"flex w-full items-center gap-2 rounded-md px-2 py-2 text-xs text-muted-foreground transition-colors hover:bg-muted/35",children:[c.jsx(ao,{className:"h-3.5 w-3.5 shrink-0"}),c.jsx(C,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),c.jsx("span",{className:"font-medium",children:EO(v)}),k>0&&c.jsxs("span",{className:"inline-flex items-center gap-0.5 text-green-500",children:[c.jsx(ql,{className:"h-3 w-3"})," ",k]}),w>0&&c.jsxs("span",{className:"inline-flex items-center gap-0.5 text-red-500",children:[c.jsx(Ah,{className:"h-3 w-3"})," ",w]})]})});const j=!s&&v.length>R1,N=j?v.length-R1:0,A=j?v.slice(-R1):v,E=j?v.slice(0,N).filter(L=>L.status==="success").length:0,R=N-E;return c.jsxs("div",{className:"my-2",children:[_&&c.jsxs("button",{type:"button",onClick:()=>l(!1),className:"mb-1 flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-xs text-muted-foreground transition-colors hover:bg-muted/35",children:[c.jsx(ao,{className:"h-3 w-3 rotate-90 transition-transform"}),c.jsxs("span",{children:["Collapse ",EO(v)]})]}),j&&c.jsxs("button",{type:"button",onClick:()=>o(!0),className:"mb-1 flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-xs text-muted-foreground transition-colors hover:bg-muted/35",children:[c.jsx(ao,{className:"h-3 w-3"}),c.jsxs("span",{children:[N," earlier tool call",N!==1?"s":"",E>0&&c.jsxs("span",{className:"text-green-500 ml-1",children:["(",E," passed)"]}),R>0&&c.jsxs("span",{className:"text-red-500 ml-1",children:["(",R," failed)"]})]})]}),s&&v.slice(0,N).map((L,z,$)=>c.jsx(Ff,{call:L,childCalls:u.get(L.callId),onOpenTerminal:n,onOpenDiff:i,hideTopConnector:z===0,hideBottomConnector:z===$.length-1&&A.length===0&&g.length===0},L.callId)),A.map((L,z)=>c.jsx(Ff,{call:L,childCalls:u.get(L.callId),onOpenTerminal:n,onOpenDiff:i,hideTopConnector:s?!1:z===0,hideBottomConnector:z===A.length-1&&g.length===0},L.callId)),g.map((L,z)=>c.jsx(Ff,{call:L,childCalls:u.get(L.callId),onOpenTerminal:n,onOpenDiff:i,hideTopConnector:v.length===0&&z===0,hideBottomConnector:z===g.length-1},L.callId))]})}function Koe(e,r){if(e===r)return!0;if(e.length!==r.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==r[n])return!1;return!0}const OO=y.memo(vXe,(e,r)=>e.onOpenTerminal===r.onOpenTerminal&&e.onOpenDiff===r.onOpenDiff&&e.collapsible===r.collapsible&&Koe(e.calls,r.calls));OO.displayName="ToolCallGroup";function cH(e,r){return r?!1:e.length>0&&e.every(n=>n.status!=="running"&&n.status!=="pending")}function xXe({provider:e,calls:r,isStreaming:n,onOpenTerminal:i,onOpenDiff:s}){const[o,a]=y.useState(()=>!cH(r,n)),[l,d]=y.useState(!1),[u,f]=y.useState(()=>Date.now()),p=y.useRef(!cH(r,n)),g=!!n||r.some(B=>B.status==="running"||B.status==="pending"),v=r.filter(B=>B.status==="success").length,b=r.filter(B=>B.status==="error").length,_=r.length>0?Math.min(...r.map(B=>B.startedAt)):Date.now(),k=!g&&r.length>0?Math.max(...r.map(B=>B.completedAt??B.startedAt)):void 0,w=zoe(r),{childMap:C,parentSet:j}=y.useMemo(()=>Uoe(r),[r]),N=y.useMemo(()=>r.filter(B=>!j.has(B.callId)),[r,j]),A=N.filter(B=>B.status==="running"||B.status==="pending"),E=N.filter(B=>B.status!=="running"&&B.status!=="pending"),R=!l&&E.length>R1,L=R?E.length-R1:0,z=R?E.slice(-R1):E,$=R?E.slice(0,L).filter(B=>B.status==="success").length:0,W=L-$;return y.useEffect(()=>{p.current&&!g&&r.length>0&&a(!1),p.current=g},[g,r.length]),y.useEffect(()=>{if(!g)return;const B=window.setInterval(()=>f(Date.now()),250);return()=>window.clearInterval(B)},[g]),r.length===0?null:c.jsx(gS,{open:o,onOpenChange:a,children:c.jsxs("div",{className:"my-2",children:[c.jsxs(yS,{className:"flex w-full items-center gap-2 rounded-md px-2 py-2 text-left transition-colors hover:bg-muted/35",children:[c.jsx(ao,{className:We("h-3.5 w-3.5 shrink-0 text-muted-foreground transition-transform duration-200",o&&"rotate-90")}),g?c.jsx(ir,{className:"h-4 w-4 shrink-0 text-muted-foreground animate-spin"}):c.jsx(w,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),c.jsx("span",{className:"text-sm font-medium text-foreground truncate",children:EO(r)}),c.jsxs("div",{className:"flex items-center gap-2 ml-auto text-xs text-muted-foreground tabular-nums shrink-0",children:[!g&&b>0&&c.jsxs("span",{className:"text-red-500",children:[b," failed"]}),c.jsx(AO,{startedAt:_,completedAt:k,now:u})]}),!g&&b===0&&v>0&&c.jsx(ql,{className:"h-3.5 w-3.5 shrink-0 text-green-500"}),!g&&b>0&&c.jsx(Ah,{className:"h-3.5 w-3.5 shrink-0 text-red-500"})]}),c.jsx(vS,{children:c.jsxs("div",{className:"mt-1",children:[R&&c.jsxs("button",{type:"button",onClick:()=>d(!0),className:"mb-1 flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-xs text-muted-foreground transition-colors hover:bg-muted/35",children:[c.jsx(ao,{className:"h-3 w-3"}),c.jsxs("span",{children:[L," earlier tool call",L!==1?"s":"",$>0&&c.jsxs("span",{className:"text-green-500 ml-1",children:["(",$," passed)"]}),W>0&&c.jsxs("span",{className:"text-red-500 ml-1",children:["(",W," failed)"]})]})]}),l&&E.slice(0,L).map((B,K,M)=>c.jsx(Ff,{call:B,childCalls:C.get(B.callId),onOpenTerminal:i,onOpenDiff:s,hideTopConnector:K===0,hideBottomConnector:K===M.length-1&&z.length===0&&A.length===0},B.callId)),z.map((B,K)=>c.jsx(Ff,{call:B,childCalls:C.get(B.callId),onOpenTerminal:i,onOpenDiff:s,hideTopConnector:l?!1:K===0,hideBottomConnector:K===z.length-1&&A.length===0},B.callId)),A.map((B,K)=>c.jsx(Ff,{call:B,childCalls:C.get(B.callId),onOpenTerminal:i,onOpenDiff:s,hideTopConnector:E.length===0&&K===0,hideBottomConnector:K===A.length-1},B.callId))]})})]})})}const RO=y.memo(xXe,(e,r)=>e.provider===r.provider&&e.isStreaming===r.isStreaming&&e.onOpenTerminal===r.onOpenTerminal&&e.onOpenDiff===r.onOpenDiff&&Koe(e.calls,r.calls));RO.displayName="AgentToolCallWrapper";function uH(e){switch(e){case"system":return"border-red-500/35 bg-red-500/10 text-red-700 dark:text-red-300";case"user":return"border-blue-500/35 bg-blue-500/10 text-blue-700 dark:text-blue-300";case"assistant":return"border-emerald-500/35 bg-emerald-500/10 text-emerald-700 dark:text-emerald-300";case"tool":return"border-amber-500/35 bg-amber-500/10 text-amber-700 dark:text-amber-300";default:return"border-border bg-muted text-muted-foreground"}}function Hf(e){if(e==null)return"";if(typeof e=="string")return e;if(typeof e=="number"||typeof e=="boolean")return String(e);try{return JSON.stringify(e,null,2)}catch{return String(e)}}function bXe(e){return"content"in e?Hf(e.content):Hf(e)}function _Xe(e){return(Array.isArray(e.tool_calls)?e.tool_calls:Array.isArray(e.toolCalls)?e.toolCalls:[]).map((n,i)=>{const s=n&&typeof n=="object"?n:{},o=s.function&&typeof s.function=="object"?s.function:{};return{id:Hf(s.id||s.call_id||s.tool_call_id||`tool-call-${i+1}`),name:Hf(o.name||s.name||s.tool||"tool"),args:Hf(o.arguments||s.arguments||s.args||{})}})}function wXe(e,r){const n=e&&typeof e=="object"?e:{},i=n.function&&typeof n.function=="object"?n.function:{};return{name:Hf(i.name||n.name||`tool_${r+1}`),description:typeof i.description=="string"?i.description:typeof n.description=="string"?n.description:void 0,raw:e}}function Yoe(e){return e<1e3?`${e}ms`:`${(e/1e3).toFixed(1)}s`}function vm(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function dH({badge:e,meta:r,preview:n,children:i,tone:s="default",defaultOpen:o=!1,onOpenChange:a}){const[l,d]=y.useState(o);return c.jsx(gS,{open:l,onOpenChange:u=>{d(u),a==null||a()},children:c.jsxs("div",{className:We("rounded-md border p-3",s==="assistant"?"border-emerald-500/25 bg-emerald-500/10":"border-border/80 bg-background"),children:[c.jsxs("div",{className:"flex items-start gap-2",children:[c.jsxs(yS,{className:"mt-0.5 rounded-sm p-0.5 text-muted-foreground transition-colors hover:bg-background/70 hover:text-foreground",children:[c.jsx(ao,{className:We("h-4 w-4 transition-transform",l&&"rotate-90")}),c.jsx("span",{className:"sr-only",children:l?"Collapse section":"Expand section"})]}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[e,r]}),n?c.jsx("div",{className:"mt-1 text-xs text-muted-foreground/70",children:n}):null]})]}),c.jsx(vS,{className:"pl-6",children:c.jsx("div",{className:"pt-3",children:i})})]})})}function SXe({flow:e}){const r=e.rounds;if(!r.some(p=>p.metrics))return null;let i=0,s=0,o=0,a=0,l,d=0,u=0;for(const p of r){const g=p.metrics;g&&(i+=g.durationMs,g.promptTokens&&(s+=g.promptTokens),g.completionTokens&&(o+=g.completionTokens),g.totalTokens&&(a+=g.totalTokens),g.tokensPerSecond&&g.completionTokens&&(d+=g.tokensPerSecond*g.completionTokens,u+=g.completionTokens),g.contextUsage&&(l=g.contextUsage))}const f=u>0?Math.round(d/u*10)/10:void 0;return c.jsxs("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-4",children:[c.jsxs("div",{className:"rounded-md border border-border bg-muted/30 px-2.5 py-2",children:[c.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[c.jsx(Xm,{className:"h-3 w-3"}),"Total Duration"]}),c.jsx("div",{className:"mt-0.5 text-sm font-semibold text-foreground",children:Yoe(i)}),c.jsxs("div",{className:"text-xs text-muted-foreground",children:[r.length," round",r.length!==1?"s":""]})]}),c.jsxs("div",{className:"rounded-md border border-border bg-muted/30 px-2.5 py-2",children:[c.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[c.jsx(A8,{className:"h-3 w-3"}),"Tokens"]}),c.jsx("div",{className:"mt-0.5 text-sm font-semibold text-foreground",children:a>0?vm(a):s+o>0?vm(s+o):"—"}),c.jsxs("div",{className:"text-xs text-muted-foreground",children:[s>0?`${vm(s)} in`:"",s>0&&o>0?" · ":"",o>0?`${vm(o)} out`:"",s===0&&o===0?"estimated":""]})]}),c.jsxs("div",{className:"rounded-md border border-border bg-muted/30 px-2.5 py-2",children:[c.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[c.jsx(fK,{className:"h-3 w-3"}),"Speed"]}),c.jsx("div",{className:"mt-0.5 text-sm font-semibold text-foreground",children:f?`${f} tok/s`:"—"}),c.jsx("div",{className:"text-xs text-muted-foreground",children:"completion tokens/sec"})]}),c.jsxs("div",{className:"rounded-md border border-border bg-muted/30 px-2.5 py-2",children:[c.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[c.jsx(Zge,{className:"h-3 w-3"}),"Context Window"]}),l?c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"mt-0.5 text-sm font-semibold text-foreground",children:[Math.round(l.ratio*100),"%"]}),c.jsxs("div",{className:"text-xs text-muted-foreground",children:[vm(l.total)," / ",vm(l.limit)," tokens",l.pruned?" (pruned)":""]})]}):c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"mt-0.5 text-sm font-semibold text-foreground",children:"—"}),c.jsx("div",{className:"text-xs text-muted-foreground",children:"no data"})]})]})]})}function kXe({metrics:e}){return e?c.jsxs("div",{className:"mt-2 flex flex-wrap gap-x-3 gap-y-1 text-xs text-muted-foreground",children:[c.jsx("span",{title:"LLM request duration",children:Yoe(e.durationMs)}),e.promptTokens!=null&&c.jsxs("span",{title:"Prompt tokens",children:[vm(e.promptTokens)," prompt"]}),e.completionTokens!=null&&c.jsxs("span",{title:"Completion tokens",children:[vm(e.completionTokens)," completion"]}),e.tokensPerSecond!=null&&c.jsxs("span",{title:"Completion tokens per second",className:"font-medium text-foreground/80",children:[e.tokensPerSecond," tok/s"]}),e.contextUsage&&c.jsxs("span",{title:"Context window utilisation",children:["ctx ",Math.round(e.contextUsage.ratio*100),"%",e.contextUsage.pruned?" (pruned)":""]})]}):null}function CXe(e,r){const n=[];if(!e)return r?[{id:"assistant-response",kind:"response",content:r}]:n;e.rounds.some(i=>i.metrics)&&n.push({id:"summary",kind:"summary",flow:e});for(const i of e.rounds){const s=Array.isArray(i.messages)?i.messages:[],o=Array.isArray(i.tools)?i.tools.map(wXe):[];n.push({id:`round-${i.round}`,kind:"round",round:i,messageCount:s.length,toolCount:o.length}),s.forEach((a,l)=>{const d=a&&typeof a=="object"?a:{content:a};n.push({id:`round-${i.round}-message-${l}`,kind:"message",roundNumber:i.round,index:l,role:Hf(d.role||"message"),content:bXe(d),raw:a,toolCalls:_Xe(d)})}),o.length>0&&n.push({id:`round-${i.round}-tools`,kind:"tools",roundNumber:i.round,tools:o})}return r&&n.push({id:"assistant-response",kind:"response",content:r}),n}function jXe({row:e,onExpandChange:r}){if(e.kind==="summary")return c.jsx(SXe,{flow:e.flow});if(e.kind==="round")return c.jsxs("div",{className:"min-w-0 overflow-hidden rounded-md border border-border bg-background px-3 py-2",children:[c.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[c.jsxs("span",{className:"rounded-md bg-foreground px-2 py-1 text-xs font-semibold text-background",children:["Round ",e.round.round]}),c.jsx("span",{className:"min-w-0 break-words text-xs text-muted-foreground",children:e.round.model}),c.jsx("span",{className:"min-w-0 break-words text-xs text-muted-foreground",children:new Date(e.round.createdAt).toLocaleString()})]}),c.jsxs("div",{className:"mt-2 flex min-w-0 flex-wrap gap-2 text-xs text-muted-foreground",children:[c.jsxs("span",{children:[e.messageCount," messages sent"]}),c.jsxs("span",{children:[e.toolCount," tool schemas available"]}),e.round.tool_choice?c.jsxs("span",{className:"min-w-0 break-words",children:["tool_choice: ",e.round.tool_choice]}):null]}),c.jsx(kXe,{metrics:e.round.metrics})]});if(e.kind==="tools")return c.jsxs("div",{className:"relative ml-2 sm:ml-4 border-l border-border pl-2 sm:pl-4",children:[c.jsx("div",{className:"absolute -left-1.5 top-3 h-3 w-3 rounded-full border border-border bg-background"}),c.jsxs("div",{className:"rounded-md border border-border/80 bg-muted/25 p-3",children:[c.jsxs("div",{className:"mb-2 flex items-center gap-2 text-xs font-medium text-foreground",children:[c.jsx(OR,{className:"h-3.5 w-3.5"}),"Tools offered to model in round ",e.roundNumber]}),c.jsx("div",{className:"grid gap-2 sm:grid-cols-2",children:e.tools.map(i=>c.jsxs("details",{className:"rounded-md border border-border/70 bg-background/70 p-2",children:[c.jsx("summary",{className:"cursor-pointer text-xs font-medium text-foreground",children:i.name}),i.description?c.jsx("p",{className:"mt-1 text-xs leading-relaxed text-muted-foreground",children:i.description}):null,c.jsx("pre",{className:"mt-2 max-h-40 overflow-auto whitespace-pre-wrap break-words rounded bg-muted/40 p-2 font-mono text-xs leading-5",children:Hf(i.raw)})]},i.name))})]})]});if(e.kind==="response")return c.jsxs("div",{className:"relative ml-2 sm:ml-4 border-l border-border pl-2 sm:pl-4",children:[c.jsx("div",{className:"absolute -left-1.5 top-3 h-3 w-3 rounded-full border border-emerald-500/40 bg-background"}),c.jsx(dH,{tone:"assistant",defaultOpen:!1,onOpenChange:r,badge:c.jsx("span",{className:We("rounded-md border px-2 py-0.5 text-xs font-semibold",uH("assistant")),children:"assistant response"}),meta:c.jsx("span",{className:"text-xs text-muted-foreground",children:"rendered chat answer"}),preview:c.jsx("span",{className:"block truncate",children:e.content||"(empty response)"}),children:c.jsx("pre",{className:"max-h-72 overflow-auto whitespace-pre-wrap break-words rounded-md bg-background/70 p-3 font-mono text-xs leading-5 text-foreground [overflow-wrap:anywhere]",children:e.content||"(empty response)"})})]});const n=e.content?e.content.length>80?e.content.slice(0,80)+"...":e.content:"(empty content)";return c.jsxs("div",{className:"relative ml-2 sm:ml-4 border-l border-border pl-2 sm:pl-4",children:[c.jsx("div",{className:"absolute -left-1.5 top-3 h-3 w-3 rounded-full border border-border bg-background"}),c.jsxs(dH,{defaultOpen:!1,onOpenChange:r,badge:c.jsx("span",{className:We("rounded-md border px-2 py-0.5 text-xs font-semibold",uH(e.role)),children:e.role}),meta:c.jsxs(c.Fragment,{children:[c.jsxs("span",{className:"text-xs text-muted-foreground",children:["round ",e.roundNumber," / message ",e.index+1]}),e.toolCalls.length>0?c.jsxs("span",{className:"text-xs text-amber-600 dark:text-amber-400",children:[e.toolCalls.length," tool call",e.toolCalls.length!==1?"s":""]}):null]}),preview:c.jsx("span",{className:"block truncate",children:n}),children:[c.jsx("pre",{className:"max-h-72 overflow-auto whitespace-pre-wrap break-words rounded-md bg-muted/35 p-3 font-mono text-xs leading-5 text-foreground [overflow-wrap:anywhere]",children:e.content||"(empty content)"}),e.toolCalls.length>0?c.jsx("div",{className:"mt-3 space-y-2",children:e.toolCalls.map(i=>c.jsxs("details",{className:"rounded-md border border-amber-500/25 bg-amber-500/10 p-2",children:[c.jsxs("summary",{className:"cursor-pointer text-xs font-medium text-amber-800 dark:text-amber-200",children:["Tool call: ",i.name," ",c.jsxs("span",{className:"font-normal text-muted-foreground",children:["(",i.id,")"]})]}),c.jsx("pre",{className:"mt-2 max-h-48 overflow-auto whitespace-pre-wrap break-words rounded bg-background/70 p-2 font-mono text-xs leading-5",children:i.args||"{}"})]},i.id))}):null,c.jsxs("details",{className:"mt-2",children:[c.jsx("summary",{className:"cursor-pointer text-xs text-muted-foreground",children:"Raw message JSON"}),c.jsx("pre",{className:"mt-2 max-h-48 overflow-auto whitespace-pre-wrap break-words rounded bg-muted/35 p-2 font-mono text-xs leading-5",children:Hf(e.raw)})]})]})]})}function NXe({open:e,onOpenChange:r,contextFlow:n,responseContent:i}){const[s,o]=y.useState("trace"),[a,l]=y.useState(!1),d=y.useRef(null),u=y.useMemo(()=>CXe(n,i),[n,i]),f=y.useMemo(()=>n?JSON.stringify(n,null,2):"",[n]),p=JR({count:u.length,getScrollElement:()=>d.current,estimateSize:b=>{const _=u[b];return _?_.kind==="summary"?110:_.kind==="round"?120:_.kind==="tools"?Math.min(420,110+_.tools.length*72):_.kind==="response"?72:52:120},overscan:5,enabled:e&&s==="trace"});y.useEffect(()=>{if(!e||s!=="trace")return;const b=window.requestAnimationFrame(()=>{p.measure()});return()=>window.cancelAnimationFrame(b)},[e,s,u.length,p]);const g=async()=>{f&&(await navigator.clipboard.writeText(f),l(!0),window.setTimeout(()=>l(!1),1200))},v=()=>{window.requestAnimationFrame(()=>{p.measure()})};return c.jsx(Td,{open:e,onOpenChange:r,children:c.jsxs(ku,{showCloseButton:!1,className:"grid h-[95vh] max-w-[min(1200px,96vw)] grid-rows-[auto_minmax(0,1fr)] overflow-hidden p-0 sm:h-[85vh]",children:[c.jsx(wd,{className:"border-b px-3 py-2",children:c.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[c.jsx(_u,{className:"shrink-0 text-sm font-semibold",children:"LLM Context Flow"}),c.jsx($m,{className:"min-w-0 flex-1 truncate text-xs",children:n?`${n.provider}${n.model?` / ${n.model}`:""} · ${n.rounds.length} round${n.rounds.length===1?"":"s"}`:"No context snapshot available"}),c.jsxs("div",{className:"-my-1 ml-auto flex shrink-0 items-center gap-1 p-1",children:[c.jsx(_e,{type:"button",variant:s==="trace"?"default":"outline",size:"sm",className:"h-7 px-2 text-xs",onClick:()=>o("trace"),children:"Trace"}),c.jsx(_e,{type:"button",variant:s==="raw"?"default":"outline",size:"sm",className:"h-7 px-2 text-xs",onClick:()=>o("raw"),children:"Raw"}),c.jsxs(_e,{type:"button",variant:"outline",size:"sm",className:"h-7 px-2 text-xs",onClick:g,disabled:!f,children:[a?c.jsx(hs,{className:"h-3 w-3 sm:mr-1"}):c.jsx(wc,{className:"h-3 w-3 sm:mr-1"}),c.jsx("span",{className:"hidden sm:inline",children:a?"Copied":"Copy"}),c.jsx("span",{className:"sr-only",children:a?"Copied":"Copy raw trace"})]}),c.jsxs(YG,{className:"ml-1 rounded-sm p-1 opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",children:[c.jsx(Jn,{className:"h-4 w-4"}),c.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}),s==="trace"?c.jsxs("div",{className:"min-h-0 px-3 pb-3 pt-2",children:[n!=null&&n.note?c.jsx("p",{className:"mb-2 rounded-md border border-border/70 bg-muted/40 px-2.5 py-1.5 text-xs text-muted-foreground",children:n.note}):null,u.length>0?c.jsx("div",{ref:d,className:"h-full min-h-0 overflow-auto pr-2",children:c.jsx("div",{className:"relative w-full",style:{height:`${p.getTotalSize()}px`},children:p.getVirtualItems().map(b=>{const _=u[b.index];return _?c.jsx("div",{"data-index":b.index,ref:p.measureElement,className:"absolute left-0 top-0 w-full pb-3",style:{transform:`translateY(${b.start}px)`},children:c.jsx(jXe,{row:_,onExpandChange:v})},_.id):null})})}):c.jsxs("div",{className:"flex h-full items-center justify-center rounded-md border border-dashed border-border text-sm text-muted-foreground",children:[c.jsx(Sm,{className:"mr-2 h-4 w-4"}),"No context snapshot is available for this message."]})]}):c.jsx("div",{className:"min-h-0 overflow-auto px-3 pb-3 pt-2",children:c.jsx("pre",{className:"min-h-full whitespace-pre-wrap break-words rounded-md border border-border/70 bg-muted/35 p-3 font-mono text-xs leading-relaxed text-foreground [overflow-wrap:anywhere]",children:f||"No context snapshot is available for this message."})})]})})}const MO=/^[A-Za-z]:[\\/]/,TXe=/^\//;function hH(e){return e.replace(/\\/g,"/").replace(/\/+$/,"")}function EXe(e){return MO.test(e)||TXe.test(e)}function AXe(e,r){const n=e.replace(/\\/g,"/");if(!n||n==="/")return!1;if(/^L\d+(?:C\d+)?$/i.test(r))return!0;const i=n.split("/").pop()??"";return/\.[A-Za-z0-9]+$/.test(i)}function OXe(e){if(!e)return null;const r=e.trim();if(!r)return null;let n=r,i="";try{const l=new URL(r);if(l.protocol==="http:"||l.protocol==="https:"){if(n=l.pathname,i=l.hash.startsWith("#")?l.hash.slice(1):l.hash,!AXe(n,i))return null}else{const d=r.indexOf("#");d>=0&&(n=r.slice(0,d),i=r.slice(d+1))}}catch{const l=r.indexOf("#");l>=0&&(n=r.slice(0,l),i=r.slice(l+1))}const s=decodeURIComponent(n);if(!EXe(s))return null;const o={path:s},a=i.match(/^L(\d+)(?:C(\d+))?$/i);return a&&(o.line=Number.parseInt(a[1],10),a[2]&&(o.column=Number.parseInt(a[2],10))),o}function fH(e,r){if(!r)return!1;const n=hH(e),i=hH(r);if(!n||!i)return!1;const s=MO.test(n)?n.toLowerCase():n,o=MO.test(i)?i.toLowerCase():i;return s===o||s.startsWith(`${o}/`)}const RXe=3;function pH(e,r){return!!(e&&e!=="jait"&&r.length>=RXe)}const mH=/<pre[^>]*><code>([\s\S]*)<\/code><\/pre>/;function gH(){return c.jsx("span",{className:"inline-flex items-center gap-1",children:[0,1,2].map(e=>c.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-current animate-pulse",style:{animationDelay:`${e*160}ms`}},e))})}function MXe(e){const r=e.toLowerCase();return!r||r==="text"||r==="plain"?"txt":r==="shell"||r==="sh"?"bash":r}function PXe({code:e,language:r,className:n}){const[i,s]=y.useState(null);return y.useEffect(()=>{let o=!1;const a=setTimeout(()=>{(async()=>{var f,p;const d=document.documentElement.classList.contains("dark")?"github-dark":"github-light",u=MXe(r);try{const g=await XI(e,{lang:u,theme:d});if(o)return;s(((f=g.match(mH))==null?void 0:f[1])??null)}catch{try{const g=await XI(e,{lang:"txt",theme:d});if(o)return;s(((p=g.match(mH))==null?void 0:p[1])??null)}catch{o||s(null)}}})()},150);return()=>{o=!0,clearTimeout(a)}},[e,r]),i?c.jsx("code",{className:We(n,"whitespace-pre"),dangerouslySetInnerHTML:{__html:i}}):c.jsx("code",{className:We(n,"whitespace-pre"),children:e})}function Xoe(e){return"prose dark:prose-invert max-w-none break-words [overflow-wrap:anywhere] prose-pre:bg-muted prose-pre:border prose-pre:max-w-full prose-pre:overflow-x-auto prose-code:before:content-none prose-code:after:content-none prose-p:leading-relaxed [font-size:0.9rem]"}function LXe(e){const r=e.replace(/\\/g,"/"),n=r.split("/");return n[n.length-1]??r}function $Xe({href:e,target:r,onOpenPath:n}){const i=LXe(r.path),s=r.line?`L${r.line}${r.column?`:${r.column}`:""}`:null;return c.jsxs("a",{href:e,className:We("not-prose inline-flex max-w-full items-center gap-1.5 rounded-md border border-border/70 bg-muted/45 px-2 py-1 align-middle text-xs font-medium leading-none text-foreground no-underline transition-colors hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"),title:r.path,onClick:o=>{o.preventDefault(),n(r.path,r.line,r.column)},children:[c.jsx(jo,{filename:i,className:"h-3.5 w-3.5 shrink-0"}),c.jsx("span",{className:"max-w-[220px] truncate",children:i}),s?c.jsx("span",{className:"shrink-0 rounded bg-background/80 px-1 py-0.5 text-2xs text-muted-foreground",children:s}):null]})}function Zoe(e){return{pre:({children:r})=>c.jsx(c.Fragment,{children:r}),code:({node:r,className:n,children:i,ref:s,...o})=>{var l,d;if(!(((l=r==null?void 0:r.position)==null?void 0:l.start.line)===((d=r==null?void 0:r.position)==null?void 0:d.end.line)&&!n)){const u=typeof n=="string"&&n.replace(/^language-/,"").split(" ")[0]||"text",f=String(i??"").replace(/\n$/,"");return c.jsxs(hEe,{code:f,language:u,children:[c.jsxs(fEe,{children:[c.jsx(pEe,{children:c.jsx(mEe,{children:u})}),c.jsx(gEe,{children:c.jsx(yEe,{})})]}),c.jsx("div",{className:"overflow-x-auto px-3 py-2 text-sm",children:c.jsx(PXe,{code:f,language:u,className:n})})]})}return c.jsx("code",{className:We("not-prose inline-flex max-w-full items-baseline rounded-md border border-border/70 bg-muted/45 px-2 py-1 align-middle font-mono text-xs font-medium leading-[1.2] text-foreground","shadow-[inset_0_1px_0_hsl(var(--background)/0.55)]"),...o,children:c.jsx("span",{className:"max-w-[32rem] truncate sm:max-w-[40rem]",children:i})})},a:({href:r,ref:n,...i})=>{if(!e)return c.jsx("a",{href:r,...i,children:i.children});const s=OXe(r);return s?c.jsx($Xe,{href:r,target:s,onOpenPath:e}):c.jsx("a",{href:r,...i,children:i.children})},img:({src:r,alt:n,ref:i,...s})=>{const o=typeof r=="string"?Moe(r):null;return o?c.jsx("a",{href:o,target:"_blank",rel:"noreferrer",className:"not-prose block overflow-hidden rounded-xl border border-border/60 bg-muted/20 no-underline",children:c.jsx("img",{src:o,alt:n??"Chat image",loading:"lazy",className:"max-h-[28rem] w-full object-contain bg-background/80",...s})}):c.jsx("span",{className:"inline-flex rounded-md border border-dashed border-border/70 px-2 py-1 text-xs text-muted-foreground",children:"image unavailable"})}}}function DXe({content:e,compact:r,onOpenPath:n}){const i=y.useMemo(()=>Zoe(n),[n]);return c.jsx("div",{className:Xoe(),children:c.jsx(GZ,{remarkPlugins:[KZ],components:i,children:e})})}function IXe({content:e,compact:r,onOpenPath:n}){const i=y.useMemo(()=>Zoe(n),[n]),s=({blockMatch:a})=>c.jsx(GZ,{remarkPlugins:[KZ],components:i,children:a.output}),{blockMatches:o}=Q5e({llmOutput:e,blocks:[],fallbackBlock:{component:s,lookBack:H5e()},isStreamFinished:!1});return c.jsx("div",{className:Xoe(),children:o.map((a,l)=>{const d=a.block.component;return c.jsx(d,{blockMatch:a},l)})})}const PO=y.memo(function({content:r,compact:n,isStreaming:i,preferLlmUi:s,onOpenPath:o}){return s&&i?c.jsx(IXe,{content:r,compact:n,onOpenPath:o}):c.jsx(DXe,{content:r,compact:n,onOpenPath:o})});PO.displayName="AssistantMarkdown";function BXe({messageId:e,messageIndex:r,messageFromEnd:n,role:i,content:s,contextFlow:o,displayContent:a,referencedFiles:l,displaySegments:d,attachments:u,thinking:f,thinkingDuration:p,toolCalls:g,segments:v,isStreaming:b,compact:_,preferLlmUi:k,provider:w,onOpenTerminal:C,onEditMessage:j,editComposer:N,onOpenPath:A,onOpenDiff:E}){const R=i==="user",{userDisplayText:L,userDisplaySegments:z}=y.useMemo(()=>{if(!R)return{userDisplayText:s,userDisplaySegments:[]};if(d!=null&&d.length)return{userDisplayText:X1(d),userDisplaySegments:d};if(a){const $e=h5(a,l);return{userDisplayText:a,userDisplaySegments:$e}}const ke=IJ(s);return{userDisplayText:ke.text,userDisplaySegments:ke.displaySegments}},[R,s,a,l,d]),[$,W]=y.useState(!1),[B,K]=y.useState(!1),[M,I]=y.useState(!1),[P,F]=y.useState(!1),[V,Y]=y.useState(!1),[H,U]=y.useState(!1),[Q,q]=y.useState(""),[ee,te]=y.useState([]),[ue,fe]=y.useState(null),[re,ie]=y.useState(null),ge=y.useMemo(()=>{if(!R)return[];const ke=As(re??z).flatMap($e=>$e.type==="image"?[{name:$e.name,mimeType:$e.mimeType,data:$e.data,preview:`data:${$e.mimeType};base64,${$e.data}`}]:[]);return ke.length>0?ke:u??[]},[u,R,re,z]),le=y.useRef(null),et=y.useRef(null),Xe=y.useRef(null);y.useEffect(()=>()=>{le.current!==null&&window.clearTimeout(le.current)},[]),y.useEffect(()=>{M||(q(L),te(z))},[M,z,L]),y.useEffect(()=>{if(!re&&ue==null)return;const ke=ue===L,$e=re===z||JSON.stringify(re??[])===JSON.stringify(z);ke&&$e&&(fe(null),ie(null))},[re,ue,z,L]),y.useEffect(()=>{var $e;if(!M){F(!1);return}const ke=window.requestAnimationFrame(()=>{F(!0)});return($e=Xe.current)==null||$e.focus(),()=>window.cancelAnimationFrame(ke)},[M]);const De=()=>{var $e;const ke=[];if(g&&g.length>0)for(const ct of g){const gt=ct.tool.replace(/_/g,"."),at=Object.entries(ct.args).filter(([,Fe])=>Fe!=null&&Fe!=="").map(([Fe,Ye])=>`${Fe}: ${typeof Ye=="string"?Ye:JSON.stringify(Ye)}`).join(", "),ut=ct.status==="success"?"✓":ct.status==="error"?"✗":"…",Ht=ct.completedAt&&ct.startedAt?`${((ct.completedAt-ct.startedAt)/1e3).toFixed(1)}s`:"";if(ke.push(`[${ut} ${gt}] ${at}`),($e=ct.result)!=null&&$e.message){const Fe=ct.result.message.length>500?ct.result.message.slice(0,500)+"…":ct.result.message;ke.push(Fe)}Ht&&ke.push(`Duration: ${Ht}`),ke.push("")}return s&&ke.push(R?BJ(z)||L:s),ke.join(`
|
|
1160
|
+
`).replace(/\\t/g," ").replace(/\\"/g,'"').replace(/\\\\/g,"\\"):null}function Woe(e){if(!e)return null;const r=cu(e,"url")??cu(e,"uri")??cu(e,"href")??cu(e,"query")??cu(e,"q");if(r)return zf(r)??r;const n=cu(e,"type"),i=cu(e,"action");return n==="webSearch"||i==="webSearch"?"web search":n==="fetch"||i==="fetch"?"website":null}function fXe({tool:e,streamingArgs:r}){const n=Ba(e),i=Ioe[n],s=n.startsWith("terminal."),o=s?Hoe(r):null,a=n==="web"||n==="web.search"||n==="web.fetch"||n==="browser.search"||n==="browser.fetch",l=a?Woe(r):null;return i&&s&&o?c.jsxs("span",{className:"inline-flex max-w-full min-w-0 items-center gap-1.5 text-foreground",children:[c.jsx("span",{className:"shrink-0 text-xs text-emerald-500 dark:text-emerald-400 font-mono",children:"$"}),c.jsx("code",{className:"min-w-0 truncate text-xs font-mono",children:o}),c.jsx("span",{className:"inline-block w-1 h-3.5 bg-blue-400 animate-pulse ml-0.5 align-text-bottom"})]}):i&&a&&l?c.jsxs("span",{className:"inline-flex max-w-full min-w-0 items-center gap-1.5 text-foreground",children:[c.jsxs("span",{children:[i.label,":"]}),c.jsx("code",{className:"min-w-0 truncate text-xs font-mono",children:l}),c.jsx("span",{className:"inline-block w-1 h-3.5 bg-blue-400 animate-pulse ml-0.5 align-text-bottom"})]}):i?c.jsxs("span",{className:"text-blue-400",children:[i.label,c.jsx("span",{className:"inline-block w-1 h-3 bg-blue-400 animate-pulse ml-1 align-text-bottom"})]}):e?c.jsxs("span",{className:"text-blue-400",children:[c.jsx("code",{className:"text-xs font-mono",children:e}),c.jsx("span",{className:"inline-block w-1 h-3 bg-blue-400 animate-pulse ml-0.5 align-text-bottom"})]}):c.jsx("span",{className:"text-muted-foreground",children:"Preparing..."})}function pXe({tool:e,streamingArgs:r,scrollRef:n}){const i=Ba(e),s=i.startsWith("terminal."),o=s?Hoe(r):null,a=i==="web"||i==="web.search"||i==="web.fetch"||i==="browser.search"||i==="browser.fetch",l=a?Woe(r):null;if(s&&o)return c.jsxs("pre",{ref:n,className:We("text-xs font-mono leading-5 rounded-md px-3 py-2 overflow-x-auto max-h-64 overflow-y-auto whitespace-pre-wrap break-all","bg-muted/40 text-foreground"),children:[c.jsx("span",{className:"text-emerald-400",children:"$ "}),o,c.jsx("span",{className:"inline-block w-1.5 h-3.5 bg-blue-400 animate-pulse ml-0.5 align-text-bottom"})]});if(a&&l){const d=i==="web.search"||i==="browser.search"?"Searching":"Fetching";return c.jsx("div",{className:We("rounded-md border px-3 py-2 text-xs","bg-muted/40 text-foreground"),children:c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(ir,{className:"h-3 w-3 animate-spin text-blue-400"}),c.jsxs("span",{children:[d," ",l,"..."]})]})})}if(i==="memory.save"){const d=cu(r,"scope")??"memory",u=cu(r,"content");return c.jsxs("div",{className:We("rounded-md border px-3 py-2 text-xs","bg-muted/40 text-foreground"),children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(ir,{className:"h-3 w-3 animate-spin text-blue-400"}),c.jsxs("span",{children:["Saving memory (",d,")..."]})]}),u?c.jsxs("div",{className:"mt-1 opacity-80",children:['"',cd(u,120),'"']}):null]})}if(i==="cron.add"){const d=cu(r,"name"),u=cu(r,"cron"),f=cu(r,"toolName");return c.jsxs("div",{className:We("rounded-md border px-3 py-2 text-xs","bg-muted/40 text-foreground"),children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(ir,{className:"h-3 w-3 animate-spin text-blue-400"}),c.jsxs("span",{children:["Creating cron job",d?`: ${d}`:"..."]})]}),(u||f)&&c.jsxs("div",{className:"mt-1 opacity-80",children:[u?`schedule ${u}`:"",u&&f?" • ":"",f?`tool ${f}`:""]})]})}return r?c.jsxs("pre",{ref:n,className:We("text-xs font-mono leading-5 rounded-md px-3 py-2 overflow-x-auto max-h-36 overflow-y-auto whitespace-pre-wrap break-all","bg-muted/40 text-muted-foreground"),children:[r,c.jsx("span",{className:"inline-block w-1.5 h-3.5 bg-blue-400 animate-pulse ml-0.5 align-text-bottom"})]}):c.jsx("div",{className:We("rounded-md border px-3 py-2 text-xs","bg-muted/40 text-foreground"),children:c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(ir,{className:"h-3 w-3 animate-spin text-blue-400"}),c.jsx("span",{children:"Preparing..."})]})})}function Uoe(e){const r=new Map,n=new Set,i=new Map(e.map(s=>[s.callId,s]));for(const s of e){if(!s.parentCallId||!i.has(s.parentCallId))continue;const o=r.get(s.parentCallId)??[];r.set(s.parentCallId,[...o,s]),n.add(s.callId)}for(let s=0;s<e.length;s++){const o=e[s];if(Ba(o.tool)!=="agent")continue;const a=[];for(let l=s+1;l<e.length;l++){const d=e[l];if(n.has(d.callId))continue;const u=o.status==="running"||o.status==="pending",f=o.completedAt!=null&&d.startedAt<=o.completedAt;if(u||f)a.push(d),n.add(d.callId);else break}if(a.length>0){const l=r.get(o.callId)??[];r.set(o.callId,[...l,...a])}}return{childMap:r,parentSet:n}}function Voe(e){return e==="browserScreenshot"}function qoe(e){var o,a;const r=Ba(e.tool),n=(o=e.result)!=null&&o.data&&typeof e.result.data=="object"?e.result.data:void 0,i=yu(r,e.args,n),s=$oe(r,i,n,(a=e.result)==null?void 0:a.message);return Voe(Doe({tool:r,args:i,status:e.status,displayOutput:Foe(e.result,r)||e.streamingOutput||"",snapshotText:typeof(n==null?void 0:n.snapshot)=="string"?n.snapshot:null,screenshotPath:s}))}function mXe({path:e,onOpenDiff:r,disabled:n}){const i=rP(e),s=!!r&&!n,o=c.jsxs(c.Fragment,{children:[c.jsx(jo,{filename:i,className:"h-3.5 w-3.5 shrink-0"}),c.jsx("span",{className:"max-w-[220px] truncate",children:i})]});return s?c.jsx("span",{role:"button",tabIndex:0,className:"inline-flex max-w-full items-center gap-1.5 rounded-md border border-border/70 bg-muted/45 px-2 py-1 text-xs font-medium leading-none text-foreground transition-colors hover:bg-muted cursor-pointer",title:`Open diff for ${e}`,onClick:a=>{a.preventDefault(),a.stopPropagation(),r(e)},onKeyDown:a=>{(a.key==="Enter"||a.key===" ")&&(a.preventDefault(),a.stopPropagation(),r(e))},children:o}):c.jsx("span",{className:"inline-flex max-w-full items-center gap-1.5 rounded-md border border-border/70 bg-muted/45 px-2 py-1 text-xs font-medium leading-none text-foreground",title:e,children:o})}function gXe({call:e,childCalls:r,onOpenTerminal:n,onOpenDiff:i,hideTopConnector:s=!1,hideBottomConnector:o=!1}){var ge,le,et,Xe,De,de,Qe,Ie,Oe;const a=qoe(e),[l,d]=y.useState(e.status==="running"||e.status==="pending"||a),[u,f]=y.useState(()=>Date.now()),p=y.useRef(e.status),g=Ba(e.tool),v=(ge=e.result)!=null&&ge.data&&typeof e.result.data=="object"?e.result.data:void 0,b=yu(g,e.args,v),_=g==="mcp-tool"?tP(b,v):null,k=_?GYe(_.title):null,w=Boe(g),C=(k==null?void 0:k.icon)??w.icon,j=(k==null?void 0:k.color)??w.color,N=QYe(g,b,v,(le=e.result)==null?void 0:le.message),A=TO(g,b),R=Foe(e.result,g)||e.streamingOutput||"",L=typeof(v==null?void 0:v.snapshot)=="string"?v.snapshot:null,z=$oe(g,b,v,(et=e.result)==null?void 0:et.message),$=g.startsWith("terminal.")||g==="execute",W=lXe(e),B=hXe(e),K=B?NC(e):null,M=oXe(g,b),I=e.status==="pending",P=((De=NO(g,b,v,(Xe=e.result)==null?void 0:Xe.message))==null?void 0:De.trim())??"",F=!!P&&XYe(g),V=aH(R),Y=aH(e.streamingArgs),H=Doe({tool:g,args:b,status:e.status,displayOutput:R,snapshotText:L,screenshotPath:z}),U=Voe(H),Q=H==="terminal"?!0:H!=="none"&&!U,q=e.status==="pending"||e.status==="running"?ir:e.status==="success"?ql:Ah,ee=e.status==="pending"?"text-blue-400":e.status==="running"?"text-muted-foreground":e.status==="success"?"text-green-500":"text-red-500";y.useEffect(()=>{const qe=p.current;!U&&(qe==="running"||qe==="pending")&&e.status!=="running"&&e.status!=="pending"&&d(!1),(e.status==="pending"||e.status==="running"||U)&&d(!0),p.current=e.status},[e.status,U]),y.useEffect(()=>{var qe;g!=="web"&&g!=="web.search"&&g!=="web.fetch"&&g!=="browser.search"&&g!=="browser.fetch"||console.debug("[tool-call-card:web]",{tool:e.tool,normalizedTool:g,callId:e.callId,status:e.status,rawArgs:e.args,normalizedArgs:b,resultMessage:(qe=e.result)==null?void 0:qe.message,resultData:v,streamingArgs:e.streamingArgs})},[e.args,e.callId,(de=e.result)==null?void 0:de.message,e.status,e.streamingArgs,e.tool,b,g,v]),y.useEffect(()=>{if(e.status!=="running"&&e.status!=="pending")return;const qe=window.setInterval(()=>f(Date.now()),250);return()=>window.clearInterval(qe)},[e.status]);const te=qYe(g,b,v,(Qe=e.result)==null?void 0:Qe.message),fe=e.status==="running"||e.status==="pending"?te.running:te.done,re=c.jsxs(c.Fragment,{children:[c.jsx(q,{className:We("h-4 w-4 shrink-0",ee,(e.status==="running"||e.status==="pending")&&"animate-spin")}),c.jsx("span",{className:"flex-1 truncate text-[13px] font-medium text-muted-foreground",children:I?c.jsx(fXe,{tool:e.tool,streamingArgs:e.streamingArgs}):$?c.jsxs("span",{className:"inline-flex max-w-full min-w-0 items-center gap-1.5 text-foreground",children:[c.jsx("span",{className:"shrink-0 text-xs text-emerald-500 dark:text-emerald-400 font-mono",children:"$"}),c.jsx("code",{className:"min-w-0 truncate text-xs font-mono",title:N,children:N})]}):F?c.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center gap-2",children:[c.jsxs("span",{children:[fe,":"]}),c.jsx(mXe,{path:P,onOpenDiff:i,disabled:e.status!=="success"})]}):_&&(_.title||_.details)?c.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center gap-2",children:[c.jsxs("span",{children:[fe,":"]}),c.jsxs("span",{className:"min-w-0 truncate",children:[_.title?c.jsx("code",{className:"text-[11px] font-mono",children:_.title}):null,_.title&&_.details?c.jsx("span",{className:"text-muted-foreground",children:" • "}):null,_.details?c.jsx("span",{className:"text-xs text-muted-foreground",children:_.details}):null]})]}):c.jsxs("span",{children:[fe,": ",c.jsx("code",{className:"text-[11px] font-mono",children:N})]})}),c.jsx("span",{className:"text-xs text-muted-foreground/60 tabular-nums shrink-0",children:c.jsx(AO,{startedAt:e.startedAt,completedAt:e.completedAt,now:u})}),A&&c.jsx("span",{className:"rounded border border-blue-500/25 bg-blue-500/10 px-1.5 py-0.5 text-2xs font-semibold tabular-nums text-blue-500 shrink-0",children:A}),W&&c.jsx("span",{className:We("rounded border px-1.5 py-0.5 text-2xs font-semibold uppercase tracking-wide shrink-0",W.className),children:W.label})]}),ie=H==="pending"?c.jsx(pXe,{tool:e.tool,streamingArgs:e.streamingArgs,scrollRef:Y}):H==="terminal"?c.jsxs("pre",{ref:V,className:We("text-xs font-mono leading-5 rounded-md px-3 py-2 overflow-x-auto max-h-64 overflow-y-auto whitespace-pre-wrap break-all","bg-muted/40 text-foreground",e.result&&!e.result.ok&&"text-red-500 dark:text-red-400"),children:[!R&&e.status!=="running"&&c.jsxs("span",{className:"text-muted-foreground",children:[c.jsx("span",{className:"text-emerald-500 dark:text-emerald-400",children:"$ "}),N]}),R,e.status==="running"&&!R&&c.jsx("span",{className:"text-muted-foreground",children:"Running..."}),e.status==="running"&&c.jsx("span",{className:"inline-block w-1.5 h-3.5 bg-foreground animate-pulse ml-0.5 align-text-bottom"})]}):H==="browserSnapshot"?c.jsx(uXe,{snapshot:L}):H==="browserScreenshot"?c.jsx(dXe,{path:z}):H==="subagent"?r&&r.length>0?c.jsxs("div",{className:"rounded-lg border border-purple-500/20 bg-purple-500/[0.03] text-xs",children:[(e.status==="running"||e.status==="pending")&&r.length>0&&c.jsxs("div",{className:"flex items-center justify-end gap-2 border-b border-purple-500/15 px-3 py-2 text-xs text-muted-foreground",children:[c.jsx(ir,{className:"h-3 w-3 animate-spin text-purple-500"}),c.jsxs("span",{children:[r.length," tool",r.length!==1?"s":""]})]}),(e.status==="running"||e.status==="pending")&&r.length===0&&c.jsx("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:"Agent is working..."}),c.jsx("div",{className:"divide-y divide-border/30",children:r.map(qe=>c.jsx(Ff,{call:qe,onOpenTerminal:n,onOpenDiff:i},qe.callId))}),((Ie=e.result)==null?void 0:Ie.message)&&(e.status==="success"||e.status==="error")&&c.jsxs("div",{className:"border-t border-purple-500/15 px-3 py-2",children:[c.jsx("div",{className:"mb-1 text-xs font-medium text-muted-foreground",children:"Result"}),c.jsx("pre",{className:"max-h-48 overflow-auto whitespace-pre-wrap rounded bg-background/60 p-2 font-mono text-xs leading-5",children:e.result.message})]})]}):c.jsx(cXe,{data:v??{},message:(Oe=e.result)==null?void 0:Oe.message,status:e.status}):H==="editDiff"?c.jsx(DYe,{filePath:String(b.path??""),oldText:g==="file.patch"||g==="edit"&&b.search!=null?String(b.search??""):void 0,newText:g==="file.patch"||g==="edit"&&b.replace!=null?String(b.replace??""):void 0,writtenContent:g==="file.write"||g==="edit"&&b.content!=null?String(b.content??""):void 0,isNewFile:g==="file.write"}):H==="output"?c.jsxs("pre",{className:We("text-xs font-mono leading-5 rounded-md px-3 py-2 overflow-x-auto max-h-64 overflow-y-auto whitespace-pre-wrap break-all","bg-muted/40 text-foreground",e.result&&!e.result.ok&&"text-red-500 dark:text-red-400"),children:[R,e.status==="running"&&c.jsx("span",{className:"inline-block w-1.5 h-3.5 bg-foreground animate-pulse ml-0.5 align-text-bottom"})]}):H==="runningHint"?c.jsxs("div",{className:We("rounded-md border px-3 py-2 text-xs","bg-muted/40 text-foreground"),children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(ir,{className:"h-3 w-3 animate-spin"}),c.jsx("span",{children:M})]}),c.jsxs("div",{className:"mt-1 text-xs opacity-75",children:["Elapsed: ",c.jsx(AO,{startedAt:e.startedAt,completedAt:e.completedAt,now:u})]})]}):null;return c.jsxs(gS,{open:Q?l:!1,onOpenChange:d,children:[c.jsxs("div",{className:"relative pl-7",children:[!s&&c.jsx("span",{className:"absolute left-[10.5px] top-0 h-6 w-px bg-border/60",style:{maskImage:"linear-gradient(to bottom, transparent 0 22px, #000 22px 100%)"},"aria-hidden":"true"}),!o&&c.jsx("span",{className:"absolute left-[10.5px] top-0 bottom-0 w-px bg-border/60",style:{maskImage:"linear-gradient(to bottom, #000 0 5px, transparent 5px 23px, #000 23px 100%)"},"aria-hidden":"true"}),o&&!s&&c.jsx("span",{className:"absolute left-[10.5px] top-0 bottom-0 w-px bg-border/60",style:{maskImage:"linear-gradient(to bottom, #000 0 5px, transparent 5px 100%)"},"aria-hidden":"true"}),c.jsx("div",{className:"absolute left-[5px] top-[9px] z-10 flex h-3 w-3 items-center justify-center",children:c.jsx(C,{className:We("h-3 w-3 shrink-0",j)})}),c.jsx("div",{className:"group pb-1",children:c.jsxs("div",{className:"flex items-center gap-2 rounded-sm px-1 py-1.5 transition-colors hover:bg-muted/20",children:[Q?c.jsxs(yS,{className:"flex min-w-0 flex-1 items-center gap-2 text-left",children:[c.jsx(ao,{className:We("h-3 w-3 shrink-0 text-muted-foreground transition-transform duration-200",l&&"rotate-90")}),re]}):c.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 text-left",children:[c.jsx("span",{className:"h-3 w-3 shrink-0"}),re]}),B&&n&&c.jsxs(un,{children:[c.jsx(dn,{asChild:!0,children:c.jsx(_e,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0",onClick:qe=>{qe.preventDefault(),qe.stopPropagation(),n(K)},children:c.jsx(Uf,{className:"h-3.5 w-3.5"})})}),c.jsx(on,{side:"top",children:"Open terminal"})]}),H==="editDiff"&&i&&e.status==="success"&&P&&c.jsxs(un,{children:[c.jsx(dn,{asChild:!0,children:c.jsx(_e,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0",onClick:qe=>{qe.preventDefault(),qe.stopPropagation(),i(P)},children:c.jsx(Uf,{className:"h-3.5 w-3.5"})})}),c.jsx(on,{side:"top",children:"Open diff in editor"})]})]})})]}),Q&&c.jsx(vS,{children:c.jsx("div",{className:"ml-7 mr-3 mb-2 border-l border-border/40 pl-4",children:ie})}),U&&c.jsx("div",{className:"ml-7 mr-3 mb-2 border-l border-border/40 pl-4",children:ie})]})}const Ff=y.memo(gXe);Ff.displayName="ToolCallCard";const Goe=3,R1=6;function yXe(e,r){if(!r||e.some(qoe))return!1;const n=e.filter(i=>i.status!=="running"&&i.status!=="pending");return n.length>=Goe&&n.length===e.length}function vXe({calls:e,collapsible:r,onOpenTerminal:n,onOpenDiff:i}){const[s,o]=y.useState(!1),[a,l]=y.useState(()=>!yXe(e,r)),d=y.useRef(!1),{childMap:u,parentSet:f}=y.useMemo(()=>Uoe(e),[e]),p=y.useMemo(()=>e.filter(L=>!f.has(L.callId)),[e,f]),g=p.filter(L=>L.status==="running"||L.status==="pending"),v=p.filter(L=>L.status!=="running"&&L.status!=="pending"),b=g.length===0&&v.length>0,_=r&&b&&v.length>=Goe;if(y.useEffect(()=>{_&&!d.current&&l(!1),d.current=b},[b,_]),e.length===0)return null;const k=v.filter(L=>L.status==="success").length,w=v.filter(L=>L.status==="error").length,C=zoe(v);if(_&&!a)return c.jsx("div",{className:"my-2",children:c.jsxs("button",{type:"button",onClick:()=>l(!0),className:"flex w-full items-center gap-2 rounded-md px-2 py-2 text-xs text-muted-foreground transition-colors hover:bg-muted/35",children:[c.jsx(ao,{className:"h-3.5 w-3.5 shrink-0"}),c.jsx(C,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),c.jsx("span",{className:"font-medium",children:EO(v)}),k>0&&c.jsxs("span",{className:"inline-flex items-center gap-0.5 text-green-500",children:[c.jsx(ql,{className:"h-3 w-3"})," ",k]}),w>0&&c.jsxs("span",{className:"inline-flex items-center gap-0.5 text-red-500",children:[c.jsx(Ah,{className:"h-3 w-3"})," ",w]})]})});const j=!s&&v.length>R1,N=j?v.length-R1:0,A=j?v.slice(-R1):v,E=j?v.slice(0,N).filter(L=>L.status==="success").length:0,R=N-E;return c.jsxs("div",{className:"my-2",children:[_&&c.jsxs("button",{type:"button",onClick:()=>l(!1),className:"mb-1 flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-xs text-muted-foreground transition-colors hover:bg-muted/35",children:[c.jsx(ao,{className:"h-3 w-3 rotate-90 transition-transform"}),c.jsxs("span",{children:["Collapse ",EO(v)]})]}),j&&c.jsxs("button",{type:"button",onClick:()=>o(!0),className:"mb-1 flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-xs text-muted-foreground transition-colors hover:bg-muted/35",children:[c.jsx(ao,{className:"h-3 w-3"}),c.jsxs("span",{children:[N," earlier tool call",N!==1?"s":"",E>0&&c.jsxs("span",{className:"text-green-500 ml-1",children:["(",E," passed)"]}),R>0&&c.jsxs("span",{className:"text-red-500 ml-1",children:["(",R," failed)"]})]})]}),s&&v.slice(0,N).map((L,z,$)=>c.jsx(Ff,{call:L,childCalls:u.get(L.callId),onOpenTerminal:n,onOpenDiff:i,hideTopConnector:z===0,hideBottomConnector:z===$.length-1&&A.length===0&&g.length===0},L.callId)),A.map((L,z)=>c.jsx(Ff,{call:L,childCalls:u.get(L.callId),onOpenTerminal:n,onOpenDiff:i,hideTopConnector:s?!1:z===0,hideBottomConnector:z===A.length-1&&g.length===0},L.callId)),g.map((L,z)=>c.jsx(Ff,{call:L,childCalls:u.get(L.callId),onOpenTerminal:n,onOpenDiff:i,hideTopConnector:v.length===0&&z===0,hideBottomConnector:z===g.length-1},L.callId))]})}function Koe(e,r){if(e===r)return!0;if(e.length!==r.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==r[n])return!1;return!0}const OO=y.memo(vXe,(e,r)=>e.onOpenTerminal===r.onOpenTerminal&&e.onOpenDiff===r.onOpenDiff&&e.collapsible===r.collapsible&&Koe(e.calls,r.calls));OO.displayName="ToolCallGroup";function cH(e,r){return r?!1:e.length>0&&e.every(n=>n.status!=="running"&&n.status!=="pending")}function xXe({provider:e,calls:r,isStreaming:n,onOpenTerminal:i,onOpenDiff:s}){const[o,a]=y.useState(()=>!cH(r,n)),[l,d]=y.useState(!1),[u,f]=y.useState(()=>Date.now()),p=y.useRef(!cH(r,n)),g=!!n||r.some(B=>B.status==="running"||B.status==="pending"),v=r.filter(B=>B.status==="success").length,b=r.filter(B=>B.status==="error").length,_=r.length>0?Math.min(...r.map(B=>B.startedAt)):Date.now(),k=!g&&r.length>0?Math.max(...r.map(B=>B.completedAt??B.startedAt)):void 0,w=zoe(r),{childMap:C,parentSet:j}=y.useMemo(()=>Uoe(r),[r]),N=y.useMemo(()=>r.filter(B=>!j.has(B.callId)),[r,j]),A=N.filter(B=>B.status==="running"||B.status==="pending"),E=N.filter(B=>B.status!=="running"&&B.status!=="pending"),R=!l&&E.length>R1,L=R?E.length-R1:0,z=R?E.slice(-R1):E,$=R?E.slice(0,L).filter(B=>B.status==="success").length:0,W=L-$;return y.useEffect(()=>{p.current&&!g&&r.length>0&&a(!1),p.current=g},[g,r.length]),y.useEffect(()=>{if(!g)return;const B=window.setInterval(()=>f(Date.now()),250);return()=>window.clearInterval(B)},[g]),r.length===0?null:c.jsx(gS,{open:o,onOpenChange:a,children:c.jsxs("div",{className:"my-2",children:[c.jsxs(yS,{className:"flex w-full items-center gap-2 rounded-md px-2 py-2 text-left transition-colors hover:bg-muted/35",children:[c.jsx(ao,{className:We("h-3.5 w-3.5 shrink-0 text-muted-foreground transition-transform duration-200",o&&"rotate-90")}),g?c.jsx(ir,{className:"h-4 w-4 shrink-0 text-muted-foreground animate-spin"}):c.jsx(w,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),c.jsx("span",{className:"text-sm font-medium text-foreground truncate",children:EO(r)}),c.jsxs("div",{className:"flex items-center gap-2 ml-auto text-xs text-muted-foreground tabular-nums shrink-0",children:[!g&&b>0&&c.jsxs("span",{className:"text-red-500",children:[b," failed"]}),c.jsx(AO,{startedAt:_,completedAt:k,now:u})]}),!g&&b===0&&v>0&&c.jsx(ql,{className:"h-3.5 w-3.5 shrink-0 text-green-500"}),!g&&b>0&&c.jsx(Ah,{className:"h-3.5 w-3.5 shrink-0 text-red-500"})]}),c.jsx(vS,{children:c.jsxs("div",{className:"mt-1",children:[R&&c.jsxs("button",{type:"button",onClick:()=>d(!0),className:"mb-1 flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-xs text-muted-foreground transition-colors hover:bg-muted/35",children:[c.jsx(ao,{className:"h-3 w-3"}),c.jsxs("span",{children:[L," earlier tool call",L!==1?"s":"",$>0&&c.jsxs("span",{className:"text-green-500 ml-1",children:["(",$," passed)"]}),W>0&&c.jsxs("span",{className:"text-red-500 ml-1",children:["(",W," failed)"]})]})]}),l&&E.slice(0,L).map((B,K,M)=>c.jsx(Ff,{call:B,childCalls:C.get(B.callId),onOpenTerminal:i,onOpenDiff:s,hideTopConnector:K===0,hideBottomConnector:K===M.length-1&&z.length===0&&A.length===0},B.callId)),z.map((B,K)=>c.jsx(Ff,{call:B,childCalls:C.get(B.callId),onOpenTerminal:i,onOpenDiff:s,hideTopConnector:l?!1:K===0,hideBottomConnector:K===z.length-1&&A.length===0},B.callId)),A.map((B,K)=>c.jsx(Ff,{call:B,childCalls:C.get(B.callId),onOpenTerminal:i,onOpenDiff:s,hideTopConnector:E.length===0&&K===0,hideBottomConnector:K===A.length-1},B.callId))]})})]})})}const RO=y.memo(xXe,(e,r)=>e.provider===r.provider&&e.isStreaming===r.isStreaming&&e.onOpenTerminal===r.onOpenTerminal&&e.onOpenDiff===r.onOpenDiff&&Koe(e.calls,r.calls));RO.displayName="AgentToolCallWrapper";function uH(e){switch(e){case"system":return"border-red-500/35 bg-red-500/10 text-red-700 dark:text-red-300";case"user":return"border-blue-500/35 bg-blue-500/10 text-blue-700 dark:text-blue-300";case"assistant":return"border-emerald-500/35 bg-emerald-500/10 text-emerald-700 dark:text-emerald-300";case"tool":return"border-amber-500/35 bg-amber-500/10 text-amber-700 dark:text-amber-300";default:return"border-border bg-muted text-muted-foreground"}}function Hf(e){if(e==null)return"";if(typeof e=="string")return e;if(typeof e=="number"||typeof e=="boolean")return String(e);try{return JSON.stringify(e,null,2)}catch{return String(e)}}function bXe(e){return"content"in e?Hf(e.content):Hf(e)}function _Xe(e){return(Array.isArray(e.tool_calls)?e.tool_calls:Array.isArray(e.toolCalls)?e.toolCalls:[]).map((n,i)=>{const s=n&&typeof n=="object"?n:{},o=s.function&&typeof s.function=="object"?s.function:{};return{id:Hf(s.id||s.call_id||s.tool_call_id||`tool-call-${i+1}`),name:Hf(o.name||s.name||s.tool||"tool"),args:Hf(o.arguments||s.arguments||s.args||{})}})}function wXe(e,r){const n=e&&typeof e=="object"?e:{},i=n.function&&typeof n.function=="object"?n.function:{};return{name:Hf(i.name||n.name||`tool_${r+1}`),description:typeof i.description=="string"?i.description:typeof n.description=="string"?n.description:void 0,raw:e}}function Yoe(e){return e<1e3?`${e}ms`:`${(e/1e3).toFixed(1)}s`}function vm(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function dH({badge:e,meta:r,preview:n,children:i,tone:s="default",defaultOpen:o=!1,onOpenChange:a}){const[l,d]=y.useState(o);return c.jsx(gS,{open:l,onOpenChange:u=>{d(u),a==null||a()},children:c.jsxs("div",{className:We("rounded-md border p-3",s==="assistant"?"border-emerald-500/25 bg-emerald-500/10":"border-border/80 bg-background"),children:[c.jsxs("div",{className:"flex items-start gap-2",children:[c.jsxs(yS,{className:"mt-0.5 rounded-sm p-0.5 text-muted-foreground transition-colors hover:bg-background/70 hover:text-foreground",children:[c.jsx(ao,{className:We("h-4 w-4 transition-transform",l&&"rotate-90")}),c.jsx("span",{className:"sr-only",children:l?"Collapse section":"Expand section"})]}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[e,r]}),n?c.jsx("div",{className:"mt-1 text-xs text-muted-foreground/70",children:n}):null]})]}),c.jsx(vS,{className:"pl-6",children:c.jsx("div",{className:"pt-3",children:i})})]})})}function SXe({flow:e}){const r=e.rounds;if(!r.some(p=>p.metrics))return null;let i=0,s=0,o=0,a=0,l,d=0,u=0;for(const p of r){const g=p.metrics;g&&(i+=g.durationMs,g.promptTokens&&(s+=g.promptTokens),g.completionTokens&&(o+=g.completionTokens),g.totalTokens&&(a+=g.totalTokens),g.tokensPerSecond&&g.completionTokens&&(d+=g.tokensPerSecond*g.completionTokens,u+=g.completionTokens),g.contextUsage&&(l=g.contextUsage))}const f=u>0?Math.round(d/u*10)/10:void 0;return c.jsxs("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-4",children:[c.jsxs("div",{className:"rounded-md border border-border bg-muted/30 px-2.5 py-2",children:[c.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[c.jsx(Xm,{className:"h-3 w-3"}),"Total Duration"]}),c.jsx("div",{className:"mt-0.5 text-sm font-semibold text-foreground",children:Yoe(i)}),c.jsxs("div",{className:"text-xs text-muted-foreground",children:[r.length," round",r.length!==1?"s":""]})]}),c.jsxs("div",{className:"rounded-md border border-border bg-muted/30 px-2.5 py-2",children:[c.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[c.jsx(A8,{className:"h-3 w-3"}),"Tokens"]}),c.jsx("div",{className:"mt-0.5 text-sm font-semibold text-foreground",children:a>0?vm(a):s+o>0?vm(s+o):"—"}),c.jsxs("div",{className:"text-xs text-muted-foreground",children:[s>0?`${vm(s)} in`:"",s>0&&o>0?" · ":"",o>0?`${vm(o)} out`:"",s===0&&o===0?"estimated":""]})]}),c.jsxs("div",{className:"rounded-md border border-border bg-muted/30 px-2.5 py-2",children:[c.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[c.jsx(fK,{className:"h-3 w-3"}),"Speed"]}),c.jsx("div",{className:"mt-0.5 text-sm font-semibold text-foreground",children:f?`${f} tok/s`:"—"}),c.jsx("div",{className:"text-xs text-muted-foreground",children:"completion tokens/sec"})]}),c.jsxs("div",{className:"rounded-md border border-border bg-muted/30 px-2.5 py-2",children:[c.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[c.jsx(Zge,{className:"h-3 w-3"}),"Context Window"]}),l?c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"mt-0.5 text-sm font-semibold text-foreground",children:[Math.round(l.ratio*100),"%"]}),c.jsxs("div",{className:"text-xs text-muted-foreground",children:[vm(l.total)," / ",vm(l.limit)," tokens",l.pruned?" (pruned)":""]})]}):c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"mt-0.5 text-sm font-semibold text-foreground",children:"—"}),c.jsx("div",{className:"text-xs text-muted-foreground",children:"no data"})]})]})]})}function kXe({metrics:e}){return e?c.jsxs("div",{className:"mt-2 flex flex-wrap gap-x-3 gap-y-1 text-xs text-muted-foreground",children:[c.jsx("span",{title:"LLM request duration",children:Yoe(e.durationMs)}),e.promptTokens!=null&&c.jsxs("span",{title:"Prompt tokens",children:[vm(e.promptTokens)," prompt"]}),e.completionTokens!=null&&c.jsxs("span",{title:"Completion tokens",children:[vm(e.completionTokens)," completion"]}),e.tokensPerSecond!=null&&c.jsxs("span",{title:"Completion tokens per second",className:"font-medium text-foreground/80",children:[e.tokensPerSecond," tok/s"]}),e.contextUsage&&c.jsxs("span",{title:"Context window utilisation",children:["ctx ",Math.round(e.contextUsage.ratio*100),"%",e.contextUsage.pruned?" (pruned)":""]})]}):null}function CXe(e,r){const n=[];if(!e)return r?[{id:"assistant-response",kind:"response",content:r}]:n;e.rounds.some(i=>i.metrics)&&n.push({id:"summary",kind:"summary",flow:e});for(const i of e.rounds){const s=Array.isArray(i.messages)?i.messages:[],o=Array.isArray(i.tools)?i.tools.map(wXe):[];n.push({id:`round-${i.round}`,kind:"round",round:i,messageCount:s.length,toolCount:o.length}),s.forEach((a,l)=>{const d=a&&typeof a=="object"?a:{content:a};n.push({id:`round-${i.round}-message-${l}`,kind:"message",roundNumber:i.round,index:l,role:Hf(d.role||"message"),content:bXe(d),raw:a,toolCalls:_Xe(d)})}),o.length>0&&n.push({id:`round-${i.round}-tools`,kind:"tools",roundNumber:i.round,tools:o})}return r&&n.push({id:"assistant-response",kind:"response",content:r}),n}function jXe({row:e,onExpandChange:r}){if(e.kind==="summary")return c.jsx(SXe,{flow:e.flow});if(e.kind==="round")return c.jsxs("div",{className:"min-w-0 overflow-hidden rounded-md border border-border bg-background px-3 py-2",children:[c.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[c.jsxs("span",{className:"rounded-md bg-foreground px-2 py-1 text-xs font-semibold text-background",children:["Round ",e.round.round]}),c.jsx("span",{className:"min-w-0 break-words text-xs text-muted-foreground",children:e.round.model}),c.jsx("span",{className:"min-w-0 break-words text-xs text-muted-foreground",children:new Date(e.round.createdAt).toLocaleString()})]}),c.jsxs("div",{className:"mt-2 flex min-w-0 flex-wrap gap-2 text-xs text-muted-foreground",children:[c.jsxs("span",{children:[e.messageCount," messages sent"]}),c.jsxs("span",{children:[e.toolCount," tool schemas available"]}),e.round.tool_choice?c.jsxs("span",{className:"min-w-0 break-words",children:["tool_choice: ",e.round.tool_choice]}):null]}),c.jsx(kXe,{metrics:e.round.metrics})]});if(e.kind==="tools")return c.jsxs("div",{className:"relative ml-2 sm:ml-4 border-l border-border pl-2 sm:pl-4",children:[c.jsx("div",{className:"absolute -left-1.5 top-3 h-3 w-3 rounded-full border border-border bg-background"}),c.jsxs("div",{className:"rounded-md border border-border/80 bg-muted/25 p-3",children:[c.jsxs("div",{className:"mb-2 flex items-center gap-2 text-xs font-medium text-foreground",children:[c.jsx(OR,{className:"h-3.5 w-3.5"}),"Tools offered to model in round ",e.roundNumber]}),c.jsx("div",{className:"grid gap-2 sm:grid-cols-2",children:e.tools.map(i=>c.jsxs("details",{className:"rounded-md border border-border/70 bg-background/70 p-2",children:[c.jsx("summary",{className:"cursor-pointer text-xs font-medium text-foreground",children:i.name}),i.description?c.jsx("p",{className:"mt-1 text-xs leading-relaxed text-muted-foreground",children:i.description}):null,c.jsx("pre",{className:"mt-2 max-h-40 overflow-auto whitespace-pre-wrap break-words rounded bg-muted/40 p-2 font-mono text-xs leading-5",children:Hf(i.raw)})]},i.name))})]})]});if(e.kind==="response")return c.jsxs("div",{className:"relative ml-2 sm:ml-4 border-l border-border pl-2 sm:pl-4",children:[c.jsx("div",{className:"absolute -left-1.5 top-3 h-3 w-3 rounded-full border border-emerald-500/40 bg-background"}),c.jsx(dH,{tone:"assistant",defaultOpen:!1,onOpenChange:r,badge:c.jsx("span",{className:We("rounded-md border px-2 py-0.5 text-xs font-semibold",uH("assistant")),children:"assistant response"}),meta:c.jsx("span",{className:"text-xs text-muted-foreground",children:"rendered chat answer"}),preview:c.jsx("span",{className:"block truncate",children:e.content||"(empty response)"}),children:c.jsx("pre",{className:"max-h-72 overflow-auto whitespace-pre-wrap break-words rounded-md bg-background/70 p-3 font-mono text-xs leading-5 text-foreground [overflow-wrap:anywhere]",children:e.content||"(empty response)"})})]});const n=e.content?e.content.length>80?e.content.slice(0,80)+"...":e.content:"(empty content)";return c.jsxs("div",{className:"relative ml-2 sm:ml-4 border-l border-border pl-2 sm:pl-4",children:[c.jsx("div",{className:"absolute -left-1.5 top-3 h-3 w-3 rounded-full border border-border bg-background"}),c.jsxs(dH,{defaultOpen:!1,onOpenChange:r,badge:c.jsx("span",{className:We("rounded-md border px-2 py-0.5 text-xs font-semibold",uH(e.role)),children:e.role}),meta:c.jsxs(c.Fragment,{children:[c.jsxs("span",{className:"text-xs text-muted-foreground",children:["round ",e.roundNumber," / message ",e.index+1]}),e.toolCalls.length>0?c.jsxs("span",{className:"text-xs text-amber-600 dark:text-amber-400",children:[e.toolCalls.length," tool call",e.toolCalls.length!==1?"s":""]}):null]}),preview:c.jsx("span",{className:"block truncate",children:n}),children:[c.jsx("pre",{className:"max-h-72 overflow-auto whitespace-pre-wrap break-words rounded-md bg-muted/35 p-3 font-mono text-xs leading-5 text-foreground [overflow-wrap:anywhere]",children:e.content||"(empty content)"}),e.toolCalls.length>0?c.jsx("div",{className:"mt-3 space-y-2",children:e.toolCalls.map(i=>c.jsxs("details",{className:"rounded-md border border-amber-500/25 bg-amber-500/10 p-2",children:[c.jsxs("summary",{className:"cursor-pointer text-xs font-medium text-amber-800 dark:text-amber-200",children:["Tool call: ",i.name," ",c.jsxs("span",{className:"font-normal text-muted-foreground",children:["(",i.id,")"]})]}),c.jsx("pre",{className:"mt-2 max-h-48 overflow-auto whitespace-pre-wrap break-words rounded bg-background/70 p-2 font-mono text-xs leading-5",children:i.args||"{}"})]},i.id))}):null,c.jsxs("details",{className:"mt-2",children:[c.jsx("summary",{className:"cursor-pointer text-xs text-muted-foreground",children:"Raw message JSON"}),c.jsx("pre",{className:"mt-2 max-h-48 overflow-auto whitespace-pre-wrap break-words rounded bg-muted/35 p-2 font-mono text-xs leading-5",children:Hf(e.raw)})]})]})]})}function NXe({open:e,onOpenChange:r,contextFlow:n,responseContent:i}){const[s,o]=y.useState("trace"),[a,l]=y.useState(!1),d=y.useRef(null),u=y.useMemo(()=>CXe(n,i),[n,i]),f=y.useMemo(()=>n?JSON.stringify(n,null,2):"",[n]),p=JR({count:u.length,getScrollElement:()=>d.current,estimateSize:b=>{const _=u[b];return _?_.kind==="summary"?110:_.kind==="round"?120:_.kind==="tools"?Math.min(420,110+_.tools.length*72):_.kind==="response"?72:52:120},overscan:5,enabled:e&&s==="trace"});y.useEffect(()=>{if(!e||s!=="trace")return;const b=window.requestAnimationFrame(()=>{p.measure()});return()=>window.cancelAnimationFrame(b)},[e,s,u.length,p]);const g=async()=>{f&&(await navigator.clipboard.writeText(f),l(!0),window.setTimeout(()=>l(!1),1200))},v=()=>{window.requestAnimationFrame(()=>{p.measure()})};return c.jsx(Td,{open:e,onOpenChange:r,children:c.jsxs(ku,{showCloseButton:!1,className:"grid h-[95vh] max-w-[min(1200px,96vw)] grid-rows-[auto_minmax(0,1fr)] overflow-hidden p-0 sm:h-[85vh]",children:[c.jsx(wd,{className:"border-b px-3 py-2",children:c.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[c.jsx(_u,{className:"shrink-0 text-sm font-semibold",children:"LLM Context Flow"}),c.jsx($m,{className:"min-w-0 flex-1 truncate text-xs",children:n?`${n.provider}${n.model?` / ${n.model}`:""} · ${n.rounds.length} round${n.rounds.length===1?"":"s"}`:"No context snapshot available"}),c.jsxs("div",{className:"-my-1 ml-auto flex shrink-0 items-center gap-1 p-1",children:[c.jsx(_e,{type:"button",variant:s==="trace"?"default":"outline",size:"sm",className:"h-7 px-2 text-xs",onClick:()=>o("trace"),children:"Trace"}),c.jsx(_e,{type:"button",variant:s==="raw"?"default":"outline",size:"sm",className:"h-7 px-2 text-xs",onClick:()=>o("raw"),children:"Raw"}),c.jsxs(_e,{type:"button",variant:"outline",size:"sm",className:"h-7 px-2 text-xs",onClick:g,disabled:!f,children:[a?c.jsx(hs,{className:"h-3 w-3 sm:mr-1"}):c.jsx(wc,{className:"h-3 w-3 sm:mr-1"}),c.jsx("span",{className:"hidden sm:inline",children:a?"Copied":"Copy"}),c.jsx("span",{className:"sr-only",children:a?"Copied":"Copy raw trace"})]}),c.jsxs(YG,{className:"ml-1 rounded-sm p-1 opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",children:[c.jsx(Jn,{className:"h-4 w-4"}),c.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}),s==="trace"?c.jsxs("div",{className:"min-h-0 px-3 pb-3 pt-2",children:[n!=null&&n.note?c.jsx("p",{className:"mb-2 rounded-md border border-border/70 bg-muted/40 px-2.5 py-1.5 text-xs text-muted-foreground",children:n.note}):null,u.length>0?c.jsx("div",{ref:d,className:"h-full min-h-0 overflow-auto pr-2",children:c.jsx("div",{className:"relative w-full",style:{height:`${p.getTotalSize()}px`},children:p.getVirtualItems().map(b=>{const _=u[b.index];return _?c.jsx("div",{"data-index":b.index,ref:p.measureElement,className:"absolute left-0 top-0 w-full pb-3",style:{transform:`translateY(${b.start}px)`},children:c.jsx(jXe,{row:_,onExpandChange:v})},_.id):null})})}):c.jsxs("div",{className:"flex h-full items-center justify-center rounded-md border border-dashed border-border text-sm text-muted-foreground",children:[c.jsx(Sm,{className:"mr-2 h-4 w-4"}),"No context snapshot is available for this message."]})]}):c.jsx("div",{className:"min-h-0 overflow-auto px-3 pb-3 pt-2",children:c.jsx("pre",{className:"min-h-full whitespace-pre-wrap break-words rounded-md border border-border/70 bg-muted/35 p-3 font-mono text-xs leading-relaxed text-foreground [overflow-wrap:anywhere]",children:f||"No context snapshot is available for this message."})})]})})}const MO=/^[A-Za-z]:[\\/]/,TXe=/^\//;function hH(e){return e.replace(/\\/g,"/").replace(/\/+$/,"")}function EXe(e){return MO.test(e)||TXe.test(e)}function AXe(e,r){const n=e.replace(/\\/g,"/");if(!n||n==="/")return!1;if(/^L\d+(?:C\d+)?$/i.test(r))return!0;const i=n.split("/").pop()??"";return/\.[A-Za-z0-9]+$/.test(i)}function OXe(e){if(!e)return null;const r=e.trim();if(!r)return null;let n=r,i="";try{const l=new URL(r);if(l.protocol==="http:"||l.protocol==="https:"){if(n=l.pathname,i=l.hash.startsWith("#")?l.hash.slice(1):l.hash,!AXe(n,i))return null}else{const d=r.indexOf("#");d>=0&&(n=r.slice(0,d),i=r.slice(d+1))}}catch{const l=r.indexOf("#");l>=0&&(n=r.slice(0,l),i=r.slice(l+1))}let s;try{s=decodeURIComponent(n)}catch{return null}if(!EXe(s))return null;const o={path:s},a=i.match(/^L(\d+)(?:C(\d+))?$/i);return a&&(o.line=Number.parseInt(a[1],10),a[2]&&(o.column=Number.parseInt(a[2],10))),o}function fH(e,r){if(!r)return!1;const n=hH(e),i=hH(r);if(!n||!i)return!1;const s=MO.test(n)?n.toLowerCase():n,o=MO.test(i)?i.toLowerCase():i;return s===o||s.startsWith(`${o}/`)}const RXe=3;function pH(e,r){return!!(e&&e!=="jait"&&r.length>=RXe)}const mH=/<pre[^>]*><code>([\s\S]*)<\/code><\/pre>/;function gH(){return c.jsx("span",{className:"inline-flex items-center gap-1",children:[0,1,2].map(e=>c.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-current animate-pulse",style:{animationDelay:`${e*160}ms`}},e))})}function MXe(e){const r=e.toLowerCase();return!r||r==="text"||r==="plain"?"txt":r==="shell"||r==="sh"?"bash":r}function PXe({code:e,language:r,className:n}){const[i,s]=y.useState(null);return y.useEffect(()=>{let o=!1;const a=setTimeout(()=>{(async()=>{var f,p;const d=document.documentElement.classList.contains("dark")?"github-dark":"github-light",u=MXe(r);try{const g=await XI(e,{lang:u,theme:d});if(o)return;s(((f=g.match(mH))==null?void 0:f[1])??null)}catch{try{const g=await XI(e,{lang:"txt",theme:d});if(o)return;s(((p=g.match(mH))==null?void 0:p[1])??null)}catch{o||s(null)}}})()},150);return()=>{o=!0,clearTimeout(a)}},[e,r]),i?c.jsx("code",{className:We(n,"whitespace-pre"),dangerouslySetInnerHTML:{__html:i}}):c.jsx("code",{className:We(n,"whitespace-pre"),children:e})}function Xoe(e){return"prose dark:prose-invert max-w-none break-words [overflow-wrap:anywhere] prose-pre:bg-muted prose-pre:border prose-pre:max-w-full prose-pre:overflow-x-auto prose-code:before:content-none prose-code:after:content-none prose-p:leading-relaxed [font-size:0.9rem]"}function LXe(e){const r=e.replace(/\\/g,"/"),n=r.split("/");return n[n.length-1]??r}function $Xe({href:e,target:r,onOpenPath:n}){const i=LXe(r.path),s=r.line?`L${r.line}${r.column?`:${r.column}`:""}`:null;return c.jsxs("a",{href:e,className:We("not-prose inline-flex max-w-full items-center gap-1.5 rounded-md border border-border/70 bg-muted/45 px-2 py-1 align-middle text-xs font-medium leading-none text-foreground no-underline transition-colors hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"),title:r.path,onClick:o=>{o.preventDefault(),n(r.path,r.line,r.column)},children:[c.jsx(jo,{filename:i,className:"h-3.5 w-3.5 shrink-0"}),c.jsx("span",{className:"max-w-[220px] truncate",children:i}),s?c.jsx("span",{className:"shrink-0 rounded bg-background/80 px-1 py-0.5 text-2xs text-muted-foreground",children:s}):null]})}function Zoe(e){return{pre:({children:r})=>c.jsx(c.Fragment,{children:r}),code:({node:r,className:n,children:i,ref:s,...o})=>{var l,d;if(!(((l=r==null?void 0:r.position)==null?void 0:l.start.line)===((d=r==null?void 0:r.position)==null?void 0:d.end.line)&&!n)){const u=typeof n=="string"&&n.replace(/^language-/,"").split(" ")[0]||"text",f=String(i??"").replace(/\n$/,"");return c.jsxs(hEe,{code:f,language:u,children:[c.jsxs(fEe,{children:[c.jsx(pEe,{children:c.jsx(mEe,{children:u})}),c.jsx(gEe,{children:c.jsx(yEe,{})})]}),c.jsx("div",{className:"overflow-x-auto px-3 py-2 text-sm",children:c.jsx(PXe,{code:f,language:u,className:n})})]})}return c.jsx("code",{className:We("not-prose inline-flex max-w-full items-baseline rounded-md border border-border/70 bg-muted/45 px-2 py-1 align-middle font-mono text-xs font-medium leading-[1.2] text-foreground","shadow-[inset_0_1px_0_hsl(var(--background)/0.55)]"),...o,children:c.jsx("span",{className:"max-w-[32rem] truncate sm:max-w-[40rem]",children:i})})},a:({href:r,ref:n,...i})=>{if(!e)return c.jsx("a",{href:r,...i,children:i.children});const s=OXe(r);return s?c.jsx($Xe,{href:r,target:s,onOpenPath:e}):c.jsx("a",{href:r,...i,children:i.children})},img:({src:r,alt:n,ref:i,...s})=>{const o=typeof r=="string"?Moe(r):null;return o?c.jsx("a",{href:o,target:"_blank",rel:"noreferrer",className:"not-prose block overflow-hidden rounded-xl border border-border/60 bg-muted/20 no-underline",children:c.jsx("img",{src:o,alt:n??"Chat image",loading:"lazy",className:"max-h-[28rem] w-full object-contain bg-background/80",...s})}):c.jsx("span",{className:"inline-flex rounded-md border border-dashed border-border/70 px-2 py-1 text-xs text-muted-foreground",children:"image unavailable"})}}}function DXe({content:e,compact:r,onOpenPath:n}){const i=y.useMemo(()=>Zoe(n),[n]);return c.jsx("div",{className:Xoe(),children:c.jsx(GZ,{remarkPlugins:[KZ],components:i,children:e})})}function IXe({content:e,compact:r,onOpenPath:n}){const i=y.useMemo(()=>Zoe(n),[n]),s=({blockMatch:a})=>c.jsx(GZ,{remarkPlugins:[KZ],components:i,children:a.output}),{blockMatches:o}=Q5e({llmOutput:e,blocks:[],fallbackBlock:{component:s,lookBack:H5e()},isStreamFinished:!1});return c.jsx("div",{className:Xoe(),children:o.map((a,l)=>{const d=a.block.component;return c.jsx(d,{blockMatch:a},l)})})}const PO=y.memo(function({content:r,compact:n,isStreaming:i,preferLlmUi:s,onOpenPath:o}){return s&&i?c.jsx(IXe,{content:r,compact:n,onOpenPath:o}):c.jsx(DXe,{content:r,compact:n,onOpenPath:o})});PO.displayName="AssistantMarkdown";function BXe({messageId:e,messageIndex:r,messageFromEnd:n,role:i,content:s,contextFlow:o,displayContent:a,referencedFiles:l,displaySegments:d,attachments:u,thinking:f,thinkingDuration:p,toolCalls:g,segments:v,isStreaming:b,compact:_,preferLlmUi:k,provider:w,onOpenTerminal:C,onEditMessage:j,editComposer:N,onOpenPath:A,onOpenDiff:E}){const R=i==="user",{userDisplayText:L,userDisplaySegments:z}=y.useMemo(()=>{if(!R)return{userDisplayText:s,userDisplaySegments:[]};if(d!=null&&d.length)return{userDisplayText:X1(d),userDisplaySegments:d};if(a){const $e=h5(a,l);return{userDisplayText:a,userDisplaySegments:$e}}const ke=IJ(s);return{userDisplayText:ke.text,userDisplaySegments:ke.displaySegments}},[R,s,a,l,d]),[$,W]=y.useState(!1),[B,K]=y.useState(!1),[M,I]=y.useState(!1),[P,F]=y.useState(!1),[V,Y]=y.useState(!1),[H,U]=y.useState(!1),[Q,q]=y.useState(""),[ee,te]=y.useState([]),[ue,fe]=y.useState(null),[re,ie]=y.useState(null),ge=y.useMemo(()=>{if(!R)return[];const ke=As(re??z).flatMap($e=>$e.type==="image"?[{name:$e.name,mimeType:$e.mimeType,data:$e.data,preview:`data:${$e.mimeType};base64,${$e.data}`}]:[]);return ke.length>0?ke:u??[]},[u,R,re,z]),le=y.useRef(null),et=y.useRef(null),Xe=y.useRef(null);y.useEffect(()=>()=>{le.current!==null&&window.clearTimeout(le.current)},[]),y.useEffect(()=>{M||(q(L),te(z))},[M,z,L]),y.useEffect(()=>{if(!re&&ue==null)return;const ke=ue===L,$e=re===z||JSON.stringify(re??[])===JSON.stringify(z);ke&&$e&&(fe(null),ie(null))},[re,ue,z,L]),y.useEffect(()=>{var $e;if(!M){F(!1);return}const ke=window.requestAnimationFrame(()=>{F(!0)});return($e=Xe.current)==null||$e.focus(),()=>window.cancelAnimationFrame(ke)},[M]);const De=()=>{var $e;const ke=[];if(g&&g.length>0)for(const ct of g){const gt=ct.tool.replace(/_/g,"."),at=Object.entries(ct.args).filter(([,Fe])=>Fe!=null&&Fe!=="").map(([Fe,Ye])=>`${Fe}: ${typeof Ye=="string"?Ye:JSON.stringify(Ye)}`).join(", "),ut=ct.status==="success"?"✓":ct.status==="error"?"✗":"…",Ht=ct.completedAt&&ct.startedAt?`${((ct.completedAt-ct.startedAt)/1e3).toFixed(1)}s`:"";if(ke.push(`[${ut} ${gt}] ${at}`),($e=ct.result)!=null&&$e.message){const Fe=ct.result.message.length>500?ct.result.message.slice(0,500)+"…":ct.result.message;ke.push(Fe)}Ht&&ke.push(`Duration: ${Ht}`),ke.push("")}return s&&ke.push(R?BJ(z)||L:s),ke.join(`
|
|
1161
1161
|
`).trim()},de=async()=>{const ke=De();if(!ke)return;const $e=R?zJ(z):null;try{$e&&typeof ClipboardItem<"u"&&navigator.clipboard.write?await navigator.clipboard.write([new ClipboardItem({"text/plain":new Blob([ke],{type:"text/plain"}),[d5]:new Blob([$e],{type:d5})})]):await navigator.clipboard.writeText(ke)}catch{const ct=document.createElement("textarea");ct.value=ke,ct.style.position="fixed",ct.style.opacity="0",document.body.appendChild(ct),ct.focus(),ct.select(),document.execCommand("copy"),document.body.removeChild(ct)}W(!0),le.current!==null&&window.clearTimeout(le.current),le.current=window.setTimeout(()=>W(!1),1200)},Qe=R&&!!e&&!!j,Ie=Qe,Oe=b&&!f&&!s.trim(),qe=R||!b,kt=y.useCallback(()=>{!Qe||V||(q(L),te(z),I(!0))},[Qe,V,z,L]),vt=y.useCallback(()=>{q(L),te(z),I(!1)},[z,L]),Me=()=>{var $e;!Qe||M||typeof window<"u"&&($e=window.getSelection())!=null&&$e.toString().trim()||kt()},nt=y.useCallback(async(ke,$e)=>{if(!Qe||!e||!j||V)return;const ct=VEe(ke??Q,$e??ee);if(ct){fe(ct.text),ie(ct.displaySegments),I(!1),Y(!0);try{await j(e,ct.text,r,n,{referencedFiles:ct.referencedFiles,displaySegments:ct.displaySegments})}catch(gt){throw fe(null),ie(null),I(!0),gt}finally{Y(!1)}}},[Qe,Q,ee,V,e,n,r,j]),Je=async(ke,$e)=>{if(!Qe||!e||!j)return;const ct=ke.trim();ct&&await j(e,ct,r,n,{referencedFiles:($e??z).filter(gt=>gt.type==="file").map(gt=>({path:gt.path,name:gt.name})),displaySegments:$e??z})},Ot=async()=>{if(Ie){K(!0);try{await Je(L,z)}finally{K(!1)}}},be=ke=>M||!qe||!s?null:c.jsx("div",{className:We("absolute z-10 rounded-full border border-border/70 bg-background p-1","right-1 bottom-[.25rem]","opacity-0 transition-opacity group-hover/message:opacity-100 focus-within:opacity-100","touch-device:opacity-80",$&&"opacity-100"),children:c.jsxs(xEe,{children:[Qe?c.jsx(nk,{onClick:kt,"aria-label":"Edit message",tooltip:"Edit message",className:"h-6 w-6",children:c.jsx(ER,{className:"h-3.5 w-3.5"})}):null,Ie?c.jsx(nk,{onClick:$e=>{$e.preventDefault(),$e.stopPropagation(),Ot()},disabled:B,"aria-label":"Retry from this message",tooltip:"Retry from this message",className:"h-6 w-6",children:c.jsx(uK,{className:We("h-3.5 w-3.5",B&&"animate-spin")})}):null,!R&&o?c.jsx(nk,{onClick:$e=>{$e.preventDefault(),$e.stopPropagation(),U(!0)},"aria-label":"View LLM context",tooltip:"View LLM context",className:"h-6 w-6",children:c.jsx(Ef,{className:"h-3.5 w-3.5"})}):null,c.jsx(nk,{onClick:de,"aria-label":$?"Copied":"Copy message",tooltip:$?"Copied":"Copy message",className:"h-6 w-6",children:$?c.jsx(hs,{className:"h-3.5 w-3.5"}):c.jsx(wc,{className:"h-3.5 w-3.5"})})]})}),Re=R?null:be();return c.jsxs(c.Fragment,{children:[c.jsx(vEe,{from:i,className:We(_?"py-2":"py-4"),children:c.jsxs("div",{className:We("min-w-0 max-w-[85%] space-y-2",R&&"order-1"),children:[!R&&f&&c.jsx(BEe,{content:f,isStreaming:!!b&&!s,duration:p}),!R&&v&&v.length>0?c.jsxs("div",{className:"relative min-w-0 max-w-full select-text break-words [overflow-wrap:anywhere]",children:[v.map((ke,$e)=>{if(ke.type==="toolGroup"){const ct=(g??[]).filter(at=>ke.callIds.includes(at.callId)),gt=v.slice($e+1).some(at=>at.type==="text"&&typeof at.content=="string"&&at.content.trim());return ct.length>0?pH(w,ct)?c.jsx(RO,{provider:w,calls:ct,isStreaming:!!b&&$e===v.length-1,onOpenTerminal:C,onOpenDiff:E},`tg-${$e}`):c.jsx(OO,{calls:ct,collapsible:gt,onOpenTerminal:C,onOpenDiff:E},`tg-${$e}`):null}return typeof ke.content=="string"&&ke.content.trim()?c.jsx(aT,{"data-message-from":"assistant",className:"max-w-full bg-card/78",children:c.jsx(PO,{content:ke.content,compact:_,isStreaming:!!b&&$e===v.length-1,preferLlmUi:k,onOpenPath:A})},`ts-${$e}`):null}),b&&!s&&!v.some(ke=>ke.type==="text"&&typeof ke.content=="string"&&ke.content.trim())&&c.jsx("div",{className:"flex items-center gap-3 px-1 py-1 text-sm text-muted-foreground",children:c.jsx(gH,{})}),Re]}):c.jsxs(c.Fragment,{children:[g&&g.length>0&&(pH(w,g)?c.jsx(RO,{provider:w,calls:g,isStreaming:b,onOpenTerminal:C,onOpenDiff:E}):c.jsx(OO,{calls:g,collapsible:w!=="jait",onOpenTerminal:C,onOpenDiff:E})),s?R?M?c.jsx("div",{className:"w-full max-w-3xl",onClick:ke=>ke.stopPropagation(),children:c.jsx("div",{className:We("space-y-3 origin-bottom transition-all duration-150 ease-out",P?"translate-y-0 opacity-100":"translate-y-2 opacity-0"),children:c.jsx(Zb,{ref:Xe,draftStateKey:`edit:${e??"user-message"}`,value:Q,segments:ee,onChange:ke=>{var $e;q(ke),te((($e=Xe.current)==null?void 0:$e.getSegments())??[])},onSubmit:(ke,$e,ct)=>{const gt=ct??[],at=X1(gt)||Q;te(gt),nt(at,gt)},disabled:V,controlsDisabled:V,placeholder:"Edit message...",onVoiceInput:N==null?void 0:N.onVoiceInput,voiceRecording:N==null?void 0:N.voiceRecording,voiceLevels:N==null?void 0:N.voiceLevels,voiceTranscribing:N==null?void 0:N.voiceTranscribing,onVoiceStop:N==null?void 0:N.onVoiceStop,mode:N==null?void 0:N.mode,onModeChange:N==null?void 0:N.onModeChange,provider:N==null?void 0:N.provider,onProviderChange:N==null?void 0:N.onProviderChange,responseStyle:N==null?void 0:N.responseStyle,onResponseStyleChange:N==null?void 0:N.onResponseStyleChange,providerRuntimeMode:N==null?void 0:N.providerRuntimeMode,onProviderRuntimeModeChange:N==null?void 0:N.onProviderRuntimeModeChange,cliModel:N==null?void 0:N.cliModel,onCliModelChange:N==null?void 0:N.onCliModelChange,sessionInfo:N==null?void 0:N.sessionInfo,workspaceNodeId:N==null?void 0:N.workspaceNodeId,availableFiles:(N==null?void 0:N.availableFiles)??Z1(z),onSearchFiles:N==null?void 0:N.onSearchFiles,workspaceOpen:(N==null?void 0:N.workspaceOpen)??Z1(z).length>0,footerTrailingContent:c.jsx(_e,{type:"button",variant:"ghost",size:"icon",className:"h-8 w-8 shrink-0 rounded-lg",onClick:vt,disabled:V,"aria-label":"Cancel editing message",title:"Cancel editing",children:c.jsx(Jn,{className:"h-3.5 w-3.5"})}),className:"rounded-lg border-primary/20 bg-primary/[0.08] dark:!bg-primary/[0.08] shadow-none [&_.text-muted-foreground]:text-muted-foreground [&>div]:!bg-transparent [&_[contenteditable='true']]:!bg-transparent"},`edit-${e??"user-message"}`)})}):c.jsxs("div",{className:"relative w-fit max-w-full",children:[c.jsx(aT,{ref:et,"data-message-from":"user",className:We("min-w-0 rounded-lg bg-muted px-4 py-3 break-words [overflow-wrap:anywhere]",Qe&&!M&&"cursor-text transition-colors hover:bg-muted/80","leading-relaxed [font-size:0.9rem]"),onClick:Me,title:Qe&&!M?"Click to edit message":void 0,children:c.jsxs("div",{className:"min-w-0 space-y-3",children:[c.jsx("div",{className:"min-w-0 whitespace-pre-wrap break-words [overflow-wrap:anywhere]",children:(re??z).length>0?(re??z).map((ke,$e)=>ke.type==="text"?c.jsx("span",{children:ke.text},`text-${$e}`):ke.type==="file"?c.jsxs("span",{className:"mx-[2px] inline-flex items-center gap-1.5 rounded-md border border-border/70 bg-muted/45 px-2 py-1 text-xs font-medium leading-none text-foreground align-middle select-none",title:ke.path,children:[c.jsx(jo,{filename:ke.name,className:"h-3.5 w-3.5 shrink-0"}),c.jsx("span",{className:"max-w-[180px] truncate",children:ke.lineRange?`${ke.name}:${o2(ke.lineRange).replace(/^lines? /,"")}`:ke.name})]},`${ke.path}-${$e}`):ke.type==="workspace"?c.jsxs("span",{className:"mx-[2px] inline-flex items-center gap-1.5 rounded-md border border-border/70 bg-muted/45 px-2 py-1 text-xs font-medium leading-none text-foreground align-middle select-none",title:ke.path,children:[c.jsx(Sj,{name:ke.name,className:"h-3.5 w-3.5 shrink-0"}),c.jsx("span",{className:"max-w-[180px] truncate",children:ke.name})]},`${ke.path}-${$e}`):ke.type==="terminal"?c.jsxs("span",{className:"mx-[2px] inline-flex items-center gap-1.5 rounded-md border border-border/70 bg-muted/45 px-2 py-1 text-xs font-medium leading-none text-foreground align-middle select-none",title:ke.workspaceRoot?`${ke.terminalId} · ${ke.workspaceRoot}`:ke.terminalId,children:[c.jsx("span",{className:"inline-flex h-3.5 w-3.5 items-center justify-center rounded-sm bg-muted-foreground/15 text-2xs font-bold uppercase text-muted-foreground",children:"T"}),c.jsx("span",{className:"max-w-[180px] truncate",children:ke.lineRange?`${ke.name}:${o2(ke.lineRange).replace(/^lines? /,"")}`:ke.name})]},`${ke.terminalId}-${$e}`):null):ue??L}),ge.length>0&&c.jsx("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2",children:ge.map((ke,$e)=>{const ct=ke.preview??`data:${ke.mimeType};base64,${ke.data}`;return c.jsxs(Td,{children:[c.jsx(v1e,{asChild:!0,children:c.jsxs("button",{type:"button",className:"group block overflow-hidden rounded-lg border border-primary/10 bg-background/65 text-left transition-colors hover:border-primary/25 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:ring-offset-background","aria-label":`Expand image ${ke.name}`,children:[c.jsxs("span",{className:"relative block",children:[c.jsx("img",{src:ct,alt:ke.name,className:"max-h-72 w-full object-cover transition-opacity group-hover:opacity-85"}),c.jsx("span",{className:"pointer-events-none absolute inset-0 flex items-center justify-center opacity-0 transition-opacity group-hover:opacity-100",children:c.jsx("span",{className:"rounded-full bg-black/65 px-3 py-1.5 text-xs font-medium text-white",children:"Click to expand"})})]}),c.jsx("span",{className:"block truncate border-t border-border/60 px-2 py-1 text-xs text-muted-foreground",children:ke.name})]})}),c.jsxs(ku,{className:"max-h-[92vh] max-w-[96vw] gap-2 overflow-hidden p-2",showCloseButton:!0,children:[c.jsx(_u,{className:"mr-8 truncate px-1 text-sm font-medium",children:ke.name}),c.jsx("img",{src:ct,alt:ke.name,className:"max-h-[82vh] w-full object-contain"})]})]},`${ke.name}-${$e}`)})})]})}),be()]}):c.jsxs("div",{className:"relative min-w-0 max-w-full break-words [overflow-wrap:anywhere]",children:[c.jsx(aT,{"data-message-from":"assistant",className:"min-w-0 max-w-full break-words [overflow-wrap:anywhere]",children:c.jsx(PO,{content:s,compact:_,isStreaming:b,preferLlmUi:k,onOpenPath:A})}),Re]}):Oe?c.jsx("div",{className:"flex items-center gap-3 px-1 py-1 text-sm text-muted-foreground",children:c.jsx(gH,{})}):null]})]})}),c.jsx(NXe,{open:H,onOpenChange:U,contextFlow:o,responseContent:s})]})}const LO=y.memo(BXe,(e,r)=>{const{messageFromEnd:n,messageIndex:i,...s}=e,{messageFromEnd:o,messageIndex:a,...l}=r,d=Object.keys(l);return d.length===Object.keys(s).length&&d.every(u=>Object.is(s[u],l[u]))});LO.displayName="Message";function zXe(e,r){return!e||e==="gateway"?!1:!r.has(e)}function yH(e){const r=new Date(e),i=new Date().getTime()-r.getTime();return i<6e4?"just now":i<36e5?`${Math.floor(i/6e4)}m ago`:i<864e5?`${Math.floor(i/36e5)}h ago`:r.toLocaleDateString()}function FXe({platform:e}){switch(e){case"windows":case"macos":case"linux":return c.jsx(Ra,{className:"h-2.5 w-2.5"});case"android":case"ios":return c.jsx(W4,{className:"h-2.5 w-2.5"});default:return c.jsx(_i,{className:"h-2.5 w-2.5"})}}function HXe({workspaces:e,personalSessions:r=[],activeWorkspaceId:n,activeSessionId:i,loading:s=!1,hasMoreWorkspaces:o=!1,showFewerWorkspaces:a=!1,onSelectWorkspace:l,onSelectPersonalSession:d,onNewPersonalSession:u,onCreateWorkspace:f,onRemoveWorkspace:p,onChangeDirectory:g,onShowMore:v,onShowFewer:b,sessionInfo:_,nodes:k=[]}){const w=y.useMemo(()=>new Set(k.filter(C=>!C.isGateway).map(C=>C.id)),[k]);return c.jsxs("div",{className:"flex flex-col h-full",children:[c.jsxs("div",{className:"flex h-[35px] shrink-0 items-center justify-between px-3 border-b",children:[c.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"Chats & Workspaces"}),c.jsxs(un,{children:[c.jsx(dn,{asChild:!0,children:c.jsx(_e,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:f,children:c.jsx(Ro,{className:"h-3.5 w-3.5"})})}),c.jsx(on,{side:"right",children:"New workspace"})]})]}),s?c.jsx("div",{className:"flex flex-1 items-center justify-center",children:c.jsx(ir,{className:"h-4 w-4 animate-spin text-muted-foreground"})}):c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"flex max-h-[50%] min-h-0 shrink-0 flex-col border-b",children:[c.jsx("div",{className:"flex h-7 shrink-0 items-center justify-between px-3",children:c.jsx("span",{className:"text-2xs font-medium text-muted-foreground",children:"Workspaces"})}),c.jsx(gh,{className:"min-h-0 flex-1",children:c.jsxs("div",{className:"space-y-0.5 px-1.5 pb-1.5",children:[e.length===0&&c.jsxs("p",{className:"text-xs text-muted-foreground text-center py-4",children:["No workspaces yet.",c.jsx("br",{}),c.jsx("button",{onClick:f,className:"underline underline-offset-2 hover:text-foreground mt-1 inline-block",children:"Choose workspace folder"})]}),e.map(C=>{const j=C.id===n,N=C.nodeId&&C.nodeId!=="gateway"?k.find(E=>E.id===C.nodeId):null,A=zXe(C.nodeId,w);return c.jsxs("div",{className:`group grid w-full grid-cols-[auto,minmax(0,1fr),auto] items-start gap-1.5 px-1.5 py-1.5 text-sm transition-colors ${A||j?"cursor-default":"cursor-pointer"} ${j?"rounded-md bg-secondary/70":A?"opacity-50":"hover:rounded-md hover:bg-muted/40"}`,draggable:!!C.rootPath,onDragStart:E=>{if(!C.rootPath){E.preventDefault();return}E.dataTransfer.effectAllowed="copy",E.dataTransfer.setData(MQ,JSON.stringify(SRe(C.rootPath,C.title||void 0)))},onClick:()=>{!A&&!j&&l(C.id)},children:[j?c.jsx(wh,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-primary"}):c.jsx(CR,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}),c.jsxs("div",{className:"min-w-0 overflow-hidden",children:[c.jsx("div",{className:"truncate text-xs font-medium",children:C.title||"Untitled Workspace"}),c.jsxs("div",{className:"flex min-w-0 items-center gap-1 overflow-hidden text-2xs text-muted-foreground",children:[c.jsx("span",{className:"min-w-0 truncate",children:C.rootPath||"No folder linked"}),c.jsx("span",{className:"shrink-0",children:"·"}),c.jsx("span",{className:"shrink-0",children:yH(C.lastActiveAt)})]}),A&&c.jsxs("div",{className:"mt-0.5 flex items-center gap-1 text-2xs text-orange-500",children:[c.jsx(c1e,{className:"h-2.5 w-2.5 shrink-0"}),c.jsx("span",{className:"truncate",children:"Node offline"})]}),N&&!A&&c.jsx("div",{className:"mt-0.5 flex min-w-0 items-center gap-1 text-2xs",children:c.jsxs("span",{className:"inline-flex max-w-full items-center gap-0.5 rounded bg-muted px-1 py-0.5 text-muted-foreground",children:[c.jsx(FXe,{platform:N.platform}),c.jsx("span",{className:"truncate max-w-[80px]",children:N.name})]})}),j&&_&&c.jsxs("div",{className:"mt-0.5 flex min-w-0 items-center gap-1 text-2xs text-blue-500",children:[c.jsx("span",{className:"truncate",children:_.provider}),c.jsx("span",{className:"shrink-0 text-muted-foreground",children:"·"}),c.jsx(Ra,{className:"h-2.5 w-2.5 shrink-0"}),c.jsx("span",{className:"truncate",children:_.isRemote&&_.remoteNode?_.remoteNode.nodeName:"Gateway"})]})]}),c.jsxs("div",{className:"flex shrink-0 self-start gap-0.5",children:[c.jsxs(un,{children:[c.jsx(dn,{asChild:!0,children:c.jsx(_e,{variant:"ghost",size:"icon","aria-label":"Change directory",className:"h-5.5 w-5.5 shrink-0 opacity-100 text-muted-foreground transition-opacity hover:text-foreground sm:opacity-0 sm:group-hover:opacity-100",onClick:E=>{E.stopPropagation(),g(C.id)},children:c.jsx(g0e,{className:"h-3 w-3"})})}),c.jsx(on,{side:"right",children:"Change directory"})]}),c.jsxs(un,{children:[c.jsx(dn,{asChild:!0,children:c.jsx(_e,{variant:"ghost",size:"icon","aria-label":"Archive workspace",className:"h-5.5 w-5.5 shrink-0 opacity-100 text-muted-foreground transition-opacity hover:text-destructive sm:opacity-0 sm:group-hover:opacity-100",onClick:E=>{E.stopPropagation(),p(C.id)},children:c.jsx(ZG,{className:"h-3 w-3"})})}),c.jsx(on,{side:"right",children:"Archive workspace"})]})]})]},C.id)}),o&&v&&c.jsx("button",{className:"w-full px-2 py-2 text-left text-xs text-muted-foreground transition-colors hover:text-foreground",onClick:v,children:"Show more workspaces"}),a&&b&&c.jsx("button",{className:"w-full px-2 py-2 text-left text-xs text-muted-foreground transition-colors hover:text-foreground",onClick:b,children:"Show fewer workspaces"})]})})]}),c.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[c.jsxs("div",{className:"flex h-7 shrink-0 items-center justify-between px-3",children:[c.jsx("span",{className:"text-2xs font-medium text-muted-foreground",children:"Personal chats"}),u&&c.jsxs(un,{children:[c.jsx(dn,{asChild:!0,children:c.jsx(_e,{variant:"ghost",size:"icon",className:"h-5 w-5",onClick:u,children:c.jsx(Ro,{className:"h-3 w-3"})})}),c.jsx(on,{side:"right",children:"New personal chat"})]})]}),c.jsx(gh,{className:"min-h-0 flex-1",children:c.jsxs("div",{className:"space-y-0.5 px-1.5 pb-1.5",children:[r.length===0&&c.jsxs("p",{className:"text-xs text-muted-foreground text-center py-4",children:["No personal chats yet.",u&&c.jsxs(c.Fragment,{children:[c.jsx("br",{}),c.jsx("button",{onClick:u,className:"underline underline-offset-2 hover:text-foreground mt-1 inline-block",children:"Start a chat"})]})]}),r.map(C=>{const j=n===null&&C.id===i;return c.jsxs("div",{className:`group flex items-center gap-1.5 rounded-md px-1.5 py-1 transition-colors text-sm ${j?"bg-secondary/70 cursor-default":"cursor-pointer hover:bg-muted/40"}`,onClick:()=>{!j&&d&&d(C.id)},children:[c.jsx(Sm,{className:`h-3.5 w-3.5 shrink-0 ${j?"text-primary":"text-muted-foreground"}`}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsx("div",{className:"truncate text-xs font-medium",children:C.name||"Personal chat"}),c.jsx("div",{className:"text-2xs text-muted-foreground",children:yH(C.lastActiveAt??C.createdAt)})]})]},C.id)})]})})]})]})]})}function WXe(e){const r=new Date(e),i=new Date().getTime()-r.getTime();return i<6e4?"just now":i<36e5?`${Math.floor(i/6e4)}m ago`:i<864e5?`${Math.floor(i/36e5)}h ago`:r.toLocaleDateString()}function UXe({sessions:e,activeSessionId:r,workspaceTitle:n,onSelectSession:i,onNewSession:s,onOpenChange:o,showTitle:a=!0,triggerLabel:l=null}){const[d,u]=y.useState(!1),f=e.find(g=>g.id===r)??e[0]??null,p=g=>{u(g),o==null||o(g)};return c.jsxs("div",{className:a?"flex min-w-0 flex-1 items-center justify-between gap-1.5":"flex items-center gap-1.5",children:[a?c.jsx("span",{className:"min-w-0 truncate text-sm font-semibold leading-tight",children:f!=null&&f.name&&f.name!=="New Chat"?f.name:""}):null,c.jsxs(mu,{open:d,onOpenChange:p,children:[c.jsxs(un,{children:[c.jsx(dn,{asChild:!0,children:c.jsx(gu,{asChild:!0,children:c.jsxs(_e,{variant:"ghost",size:l?"sm":"icon",className:l?"h-7 shrink-0 rounded-md px-2 text-xs text-muted-foreground hover:text-foreground":"h-6 w-6 shrink-0 rounded-md text-muted-foreground hover:text-foreground",children:[c.jsx(iK,{className:"h-3.5 w-3.5"}),l?c.jsx("span",{children:l}):null]})})}),c.jsx(on,{side:"bottom",children:l??"Sessions"})]}),c.jsxs(kc,{align:"start",className:"w-[min(28rem,calc(100vw-1rem))] p-0",children:[c.jsxs("div",{className:"flex items-center justify-between border-b px-3 py-2",children:[c.jsxs("div",{children:[c.jsx("div",{className:"text-sm font-medium",children:"Sessions"}),c.jsx("div",{className:"text-xs text-muted-foreground",children:n||"Current workspace"})]}),c.jsxs(_e,{variant:"ghost",size:"sm",className:"h-7 px-2 text-xs",onClick:()=>{s(),u(!1)},children:[c.jsx(X0e,{className:"mr-1 h-3 w-3"}),"New chat"]})]}),c.jsx("div",{className:"max-h-[min(28rem,70vh)] overflow-y-auto p-2",children:e.length===0?c.jsx("div",{className:"px-3 py-6 text-center text-sm text-muted-foreground",children:"No sessions yet."}):c.jsx("div",{className:"space-y-0.5",children:e.map(g=>{const v=g.id===r;return c.jsxs("button",{type:"button",className:`flex w-full items-start gap-2 rounded-md px-3 py-2 text-left transition-colors ${v?"bg-secondary text-secondary-foreground":"hover:bg-muted/50"}`,onClick:()=>{i(g.id),u(!1)},children:[v?c.jsx(hs,{className:"mt-0.5 h-3 w-3 shrink-0 text-primary"}):c.jsx("span",{className:"mt-1 h-2 w-2 shrink-0 rounded-full bg-muted-foreground/50"}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsxs("div",{className:"flex items-center gap-1.5",children:[c.jsx("span",{className:"truncate text-xs font-medium",children:g.name||"Untitled"}),g.status==="archived"&&c.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full border px-1.5 py-0 text-2xs text-muted-foreground",children:[c.jsx(ZG,{className:"h-2.5 w-2.5"}),"Archived"]})]}),c.jsx("div",{className:"text-2xs text-muted-foreground",children:WXe(g.lastActiveAt)})]})]},g.id)})})})]})]})]})}function VXe({suggestions:e,onSelect:r,className:n}){return c.jsx("div",{className:We("flex flex-wrap gap-2 justify-center",n),children:e.map(i=>c.jsx("button",{onClick:()=>r(i),className:"px-4 py-2 text-sm rounded-full border bg-background text-muted-foreground hover:bg-accent hover:text-accent-foreground transition-colors",children:i},i))})}const qXe=$4("inline-flex items-center rounded-md border px-2 py-0.5 text-xs font-medium leading-4 transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground shadow hover:bg-primary/80",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground shadow hover:bg-destructive/80",outline:"text-foreground",success:"border-transparent bg-green-500/15 text-green-700 dark:text-green-400",warning:"border-transparent bg-yellow-500/15 text-yellow-700 dark:text-yellow-400"}},defaultVariants:{variant:"default"}});function rn({className:e,variant:r,...n}){return c.jsx("div",{className:We(qXe({variant:r}),e),...n})}const En=y.forwardRef(({className:e,...r},n)=>c.jsx("div",{ref:n,className:We("rounded-xl border border-border/70 bg-card text-card-foreground shadow-sm",e),...r}));En.displayName="Card";const Joe=y.forwardRef(({className:e,...r},n)=>c.jsx("div",{ref:n,className:We("flex flex-col space-y-1.5 p-6",e),...r}));Joe.displayName="CardHeader";const Qoe=y.forwardRef(({className:e,...r},n)=>c.jsx("h3",{ref:n,className:We("font-semibold leading-none tracking-tight",e),...r}));Qoe.displayName="CardTitle";const GXe=y.forwardRef(({className:e,...r},n)=>c.jsx("p",{ref:n,className:We("text-sm text-muted-foreground",e),...r}));GXe.displayName="CardDescription";const eae=y.forwardRef(({className:e,...r},n)=>c.jsx("div",{ref:n,className:We("p-6 pt-0",e),...r}));eae.displayName="CardContent";const KXe=y.forwardRef(({className:e,...r},n)=>c.jsx("div",{ref:n,className:We("flex items-center p-6 pt-0",e),...r}));KXe.displayName="CardFooter";const YXe={pending:{icon:Xm,label:"Pending",color:"text-muted-foreground"},approved:{icon:ir,label:"Running",color:"text-blue-500"},rejected:{icon:Jn,label:"Rejected",color:"text-destructive"},executed:{icon:ql,label:"Done",color:"text-green-500"},failed:{icon:Oa,label:"Failed",color:"text-destructive"}};function XXe({action:e,expanded:r,onToggle:n}){const i=YXe[e.status],s=i.icon;return c.jsxs("div",{className:"border rounded-md",children:[c.jsxs("button",{type:"button",className:"flex items-center gap-3 w-full px-3 py-2.5 text-left hover:bg-muted/50 transition-colors",onClick:n,children:[c.jsx(s,{className:We("h-4 w-4 shrink-0",i.color,e.status==="approved"&&"animate-spin")}),c.jsxs("span",{className:"flex-1 min-w-0",children:[c.jsx("span",{className:"font-mono text-sm font-medium",children:e.tool}),c.jsxs("span",{className:"text-xs text-muted-foreground ml-2",children:["Step ",e.order+1]})]}),c.jsx(rn,{variant:"outline",className:"text-2xs px-1.5 py-0",children:i.label}),r?c.jsx(hl,{className:"h-4 w-4 text-muted-foreground"}):c.jsx(ao,{className:"h-4 w-4 text-muted-foreground"})]}),r&&c.jsxs("div",{className:"px-3 pb-3 pt-1 border-t bg-muted/30",children:[c.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:e.description}),c.jsx("pre",{className:"text-xs bg-background rounded p-2 overflow-x-auto max-h-48",children:JSON.stringify(e.args,null,2)}),e.result&&c.jsx("div",{className:We("mt-2 text-xs rounded p-2",e.result.ok?"bg-green-500/10 text-green-700 dark:text-green-400":"bg-destructive/10 text-destructive"),children:e.result.message})]})]})}function ZXe({plan:e,onApprove:r,onReject:n,isExecuting:i,className:s}){const[o,a]=y.useState(new Set),l=g=>{a(v=>{const b=new Set(v);return b.has(g)?b.delete(g):b.add(g),b})},d=e.actions.filter(g=>g.status==="pending").length,u=e.actions.filter(g=>g.status==="executed").length,f=e.actions.filter(g=>g.status==="failed").length,p=d===0;return c.jsxs(En,{className:We("p-4 space-y-3",s),children:[c.jsxs("div",{className:"flex items-start justify-between gap-3",children:[c.jsxs("div",{children:[c.jsxs("h3",{className:"text-sm font-medium flex items-center gap-2",children:[c.jsx(JXe,{className:"h-4 w-4"}),"Plan",c.jsxs(rn,{variant:"secondary",className:"text-2xs px-1.5 py-0",children:[e.actions.length," step",e.actions.length!==1?"s":""]})]}),c.jsx("p",{className:"text-xs text-muted-foreground mt-1 line-clamp-2",children:e.summary})]}),p&&c.jsx(rn,{variant:f>0?"destructive":"success",className:"shrink-0",children:f>0?`${f} failed`:"Complete"})]}),c.jsx("div",{className:"space-y-1.5",children:e.actions.map(g=>c.jsx(XXe,{action:g,expanded:o.has(g.id),onToggle:()=>l(g.id)},g.id))}),d>0&&c.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[c.jsx(_e,{size:"sm",onClick:()=>r(),disabled:i,children:i?c.jsxs(c.Fragment,{children:[c.jsx(ir,{className:"h-3.5 w-3.5 mr-1.5 animate-spin"}),"Executing..."]}):c.jsxs(c.Fragment,{children:[c.jsx(F4,{className:"h-3.5 w-3.5 mr-1.5"}),"Execute all (",d,")"]})}),c.jsxs(_e,{size:"sm",variant:"outline",onClick:n,disabled:i,children:[c.jsx(Jn,{className:"h-3.5 w-3.5 mr-1.5"}),"Reject"]})]}),p&&!i&&c.jsxs("p",{className:"text-xs text-muted-foreground",children:[u>0&&`${u} action${u!==1?"s":""} executed.`,f>0&&` ${f} failed.`]})]})}function JXe({className:e}){return c.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:e,children:[c.jsx("rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1"}),c.jsx("path",{d:"M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2"}),c.jsx("path",{d:"M12 11h4"}),c.jsx("path",{d:"M12 16h4"}),c.jsx("path",{d:"M8 11h.01"}),c.jsx("path",{d:"M8 16h.01"})]})}function QXe(e){return e.find(r=>r.status==="in-progress")??null}function tae(e){return e.length>0&&e.every(r=>r.status==="completed")}function eZe(e){const r=QXe(e),n=tae(e);return{headerLabel:r?r.title:n?"All tasks completed":"Tasks",showHeaderSpinner:!!r,showHeaderCompleted:!r&&n}}function aE({items:e,className:r,onClear:n}){const[i,s]=y.useState(!1),o=y.useMemo(()=>tae(e),[e]),a=y.useMemo(()=>eZe(e),[e]);if(e.length===0)return null;const l=e.filter(g=>g.status==="completed").length,d=e.length,u=d>0?Math.round(l/d*100):0,f=i?"Tasks":a.headerLabel,p=o?"bg-green-500":"bg-primary";return c.jsxs("div",{className:We("rounded-lg border bg-muted/30 p-3 space-y-2",r),children:[c.jsxs("button",{type:"button",onClick:()=>s(g=>!g),className:"flex items-center gap-2 w-full text-left",children:[c.jsx(hl,{className:We("h-3 w-3 shrink-0 text-muted-foreground transition-transform duration-200",!i&&"-rotate-90")}),!i&&a.showHeaderSpinner&&c.jsx(ir,{className:"h-3.5 w-3.5 shrink-0 text-primary animate-spin"}),!i&&a.showHeaderCompleted&&c.jsx(ql,{className:"h-3.5 w-3.5 shrink-0 text-green-500"}),c.jsx("span",{className:"min-w-0 truncate text-xs font-medium text-foreground",children:f}),c.jsx("div",{className:"flex-1 h-1.5 rounded-full bg-muted overflow-hidden",children:c.jsx("div",{className:We("h-full rounded-full transition-all duration-300",p),style:{width:`${u}%`}})}),c.jsxs("span",{className:"text-2xs text-muted-foreground tabular-nums",children:[l,"/",d]}),n&&c.jsx("button",{type:"button",onClick:g=>{g.stopPropagation(),n()},className:"shrink-0 p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors",title:"Clear todo list",children:c.jsx(Jn,{className:"h-3 w-3"})})]}),i&&c.jsx("div",{className:"space-y-1",children:e.map(g=>c.jsxs("div",{className:We("flex items-start gap-2 text-xs py-0.5",g.status==="completed"&&"text-muted-foreground"),children:[g.status==="completed"?c.jsx(ql,{className:"h-3.5 w-3.5 shrink-0 mt-0.5 text-green-500"}):g.status==="in-progress"?c.jsx(ir,{className:"h-3.5 w-3.5 shrink-0 mt-0.5 text-primary animate-spin"}):c.jsx(zge,{className:"h-3.5 w-3.5 shrink-0 mt-0.5 text-muted-foreground/50"}),c.jsx("span",{className:We("flex-1 min-w-0",g.status==="completed"&&"line-through"),children:g.title})]},g.id))})]})}function tZe({files:e,onAccept:r,onReject:n,onAcceptAll:i,onRejectAll:s,onFileClick:o,className:a}){const l=y.useRef(null),[d,u]=y.useState(!1);if(y.useEffect(()=>{const p=l.current;if(!p||typeof ResizeObserver>"u")return;const g=()=>{u(p.clientWidth<560)};g();const v=new ResizeObserver(()=>g());return v.observe(p),()=>v.disconnect()},[]),e.length===0)return null;const f=e.filter(p=>p.state==="undecided").length;return c.jsxs("div",{ref:l,className:We("overflow-hidden rounded-lg border bg-muted/30",a),children:[c.jsxs("div",{className:"flex items-center justify-between gap-2 border-b bg-muted/20 px-3 py-2",children:[c.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[c.jsx(Bl,{className:"h-3.5 w-3.5 text-muted-foreground"}),c.jsxs("span",{className:"truncate text-xs font-medium",children:["Files changed (",e.length,")"]}),f>0&&c.jsxs("span",{className:"shrink-0 text-2xs text-amber-500 dark:text-amber-400",children:[f," pending"]})]}),f>0&&c.jsxs("div",{className:"ml-auto flex shrink-0 items-center gap-1",children:[c.jsxs(_e,{size:d?"icon":"sm",variant:"ghost",className:We("h-6 shrink-0 text-xs",d?"w-6 p-0":"px-2"),onClick:i,title:"Keep all","aria-label":"Keep all",children:[c.jsx(hs,{className:We("h-3 w-3 shrink-0",!d&&"mr-1")}),!d&&"Keep all"]}),c.jsxs(_e,{size:d?"icon":"sm",variant:"ghost",className:We("h-6 shrink-0 text-xs",d?"w-6 p-0":"px-2"),onClick:s,title:"Undo all","aria-label":"Undo all",children:[c.jsx(vh,{className:We("h-3 w-3 shrink-0",!d&&"mr-1")}),!d&&"Undo all"]})]})]}),c.jsx("div",{className:"divide-y",children:e.map(p=>c.jsxs("div",{className:We("flex items-center gap-2 px-3 py-1.5 text-xs",p.state==="accepted"&&"bg-green-500/5",p.state==="rejected"&&"bg-red-500/5 text-muted-foreground"),children:[c.jsx(jo,{filename:p.name,className:"h-3.5 w-3.5 shrink-0"}),c.jsx("button",{type:"button",className:We("min-w-0 flex-1 truncate text-left hover:underline cursor-pointer",p.state==="rejected"&&"line-through"),title:`Review diff for ${p.path}`,onClick:()=>o==null?void 0:o(p.path),children:p.path}),p.state==="undecided"&&c.jsxs("div",{className:"ml-auto flex items-center gap-0.5 shrink-0",children:[c.jsx("button",{type:"button",className:"p-1 rounded hover:bg-primary/10 text-primary transition-colors",onClick:()=>o==null?void 0:o(p.path),title:"Review changes",children:c.jsx(Uf,{className:"h-3 w-3"})}),c.jsx("button",{type:"button",className:"p-1 rounded hover:bg-green-500/20 text-green-600 dark:text-green-400 transition-colors",onClick:()=>r==null?void 0:r(p.path),title:"Keep all changes",children:c.jsx(hs,{className:"h-3 w-3"})}),c.jsx("button",{type:"button",className:"p-1 rounded hover:bg-red-500/20 text-red-600 dark:text-red-400 transition-colors",onClick:()=>n==null?void 0:n(p.path),title:"Undo all changes",children:c.jsx(vh,{className:"h-3 w-3"})})]}),p.state==="accepted"&&c.jsx("span",{className:"text-2xs text-green-600 dark:text-green-400 shrink-0",children:"Kept"}),p.state==="rejected"&&c.jsx("span",{className:"text-2xs text-red-500 shrink-0",children:"Undone"})]},p.path))})]})}function rZe(e,r,n,i){const s=e.findIndex(d=>d.id===r);if(s<0)return e;const o=[...e],[a]=o.splice(s,1);if(!a)return e;if(n==null)return o.push(a),o;const l=o.findIndex(d=>d.id===n);return l<0?e:(o.splice(l+(i==="after"?1:0),0,a),o)}function nZe({item:e,index:r}){return c.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-border/40 bg-background px-3 py-2 text-sm shadow-2xl ring-1 ring-primary/10",children:[c.jsx("div",{className:"mt-0.5 shrink-0 rounded p-0.5 text-muted-foreground",children:r===0?c.jsx(jR,{className:"h-3.5 w-3.5 text-primary"}):c.jsx(ao,{className:"h-3.5 w-3.5 text-muted-foreground"})}),c.jsx("div",{className:"mt-0.5 shrink-0 rounded p-0.5 text-muted-foreground",children:c.jsx(nK,{className:"h-3.5 w-3.5"})}),c.jsxs("div",{className:"min-w-0 flex-1",children:[r===0?c.jsx("span",{className:"mb-0.5 block text-2xs font-medium uppercase tracking-wider text-primary/70",children:"Next"}):c.jsxs("span",{className:"mb-0.5 block text-2xs font-medium uppercase tracking-wider text-muted-foreground",children:["Queued #",r+1]}),c.jsx("span",{className:"whitespace-pre-wrap break-words text-foreground",children:e.displayContent??e.content})]})]})}function iZe({item:e,index:r,onRemove:n,onEdit:i,onReorder:s,onSendToParallelThread:o,dragActive:a,dropBefore:l,dropAfter:d,onDragStart:u}){const[f,p]=y.useState(!1),[g,v]=y.useState(!0),[b,_]=y.useState(e.displayContent??e.content),k=y.useRef(null),w=f||!a;y.useEffect(()=>{if(f){const A=k.current;A&&(A.focus(),A.setSelectionRange(A.value.length,A.value.length))}},[f]),y.useEffect(()=>{f||_(e.displayContent??e.content)},[e.content,e.displayContent,f]);const C=y.useCallback(()=>{const A=b.trim(),E=e.displayContent??e.content;A&&A!==E&&(i==null||i(e.id,A)),p(!1)},[b,e.content,e.displayContent,e.id,i]),j=y.useCallback(()=>{_(e.displayContent??e.content),p(!1)},[e.content,e.displayContent]),N=y.useCallback(A=>{A.key==="Enter"&&!A.shiftKey?(A.preventDefault(),C()):A.key==="Escape"&&j()},[C,j]);return c.jsxs(c.Fragment,{children:[l&&c.jsx("div",{className:"relative h-0",children:c.jsx("div",{className:"absolute inset-x-2 -top-px h-0.5 rounded-full bg-primary shadow-[0_0_0_1px_hsl(var(--background))]"})}),c.jsxs("div",{"data-queue-id":e.id,className:We("group flex cursor-grab touch-none items-start gap-2 rounded-lg border border-border/40 bg-muted/50 px-3 py-2 text-sm transition-all duration-150 ease-out hover:bg-muted/70 active:cursor-grabbing",a&&"border-dashed border-primary/35 bg-primary/5 opacity-0"),onPointerDown:A=>{f||!s||A.target.closest('button, textarea, input, a, [data-no-drag="true"]')||u==null||u(e.id,A)},children:[c.jsx("button",{type:"button","data-no-drag":"true",className:"mt-0.5 shrink-0 rounded p-0.5 text-muted-foreground hover:bg-foreground/10 hover:text-foreground transition-colors",onClick:()=>v(A=>!A),"aria-label":g?"Expand queued message":"Collapse queued message",title:g?"Expand queued message":"Collapse queued message",children:g?c.jsx(ao,{className:"h-3.5 w-3.5"}):r===0?c.jsx(jR,{className:"h-3.5 w-3.5 text-primary"}):c.jsx(hl,{className:"h-3.5 w-3.5 text-muted-foreground"})}),s&&!f&&c.jsx("div",{className:"mt-0.5 shrink-0 rounded p-0.5 text-muted-foreground cursor-grab active:cursor-grabbing touch-none",title:"Drag to reorder","aria-label":"Drag to reorder",children:c.jsx(nK,{className:"h-3.5 w-3.5"})}),c.jsxs("div",{className:"flex-1 min-w-0",children:[r===0&&!f&&c.jsx("span",{className:"text-2xs font-medium uppercase tracking-wider text-primary/70 block mb-0.5",children:"Next"}),r>0&&!f&&c.jsxs("span",{className:"text-2xs font-medium uppercase tracking-wider text-muted-foreground block mb-0.5",children:["Queued #",r+1]}),f?c.jsx("textarea",{ref:k,value:b,onChange:A=>_(A.target.value),onKeyDown:N,onBlur:C,rows:Math.min(b.split(`
|
|
1162
1162
|
`).length,5),className:"w-full resize-none rounded border border-primary/30 bg-background px-2 py-1 text-sm outline-none focus:border-primary focus:ring-1 focus:ring-primary/20"}):g?c.jsx("span",{className:"block truncate text-foreground",children:e.displayContent??e.content}):c.jsx("span",{className:"whitespace-pre-wrap break-words text-foreground",children:e.displayContent??e.content})]}),c.jsx("div",{className:We("mt-0.5 flex shrink-0 items-center gap-0.5 transition-opacity",w?"opacity-0 group-hover:opacity-100":"opacity-0"),children:f?c.jsxs(c.Fragment,{children:[c.jsx("button",{type:"button","data-no-drag":"true",className:"p-1 rounded hover:bg-primary/10 text-primary transition-colors",onClick:C,title:"Save",children:c.jsx(hs,{className:"h-3.5 w-3.5"})}),c.jsx("button",{type:"button","data-no-drag":"true",className:"p-1 rounded hover:bg-foreground/10 text-muted-foreground transition-colors",onClick:j,title:"Cancel",children:c.jsx(Jn,{className:"h-3.5 w-3.5"})})]}):c.jsxs(c.Fragment,{children:[i&&c.jsx("button",{type:"button","data-no-drag":"true",className:"p-1 rounded hover:bg-foreground/10 text-muted-foreground transition-colors",onClick:()=>p(!0),title:"Edit message",children:c.jsx(ER,{className:"h-3 w-3"})}),o&&c.jsx("button",{type:"button","data-no-drag":"true",className:"p-1 rounded hover:bg-primary/10 text-muted-foreground hover:text-primary transition-colors",onClick:()=>o(e.id),title:"Send to parallel thread",children:c.jsx(u0,{className:"h-3 w-3"})}),c.jsx("button",{type:"button","data-no-drag":"true",className:"p-1 rounded hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors",onClick:()=>n==null?void 0:n(e.id),title:"Remove from queue",children:c.jsx(Jn,{className:"h-3.5 w-3.5"})})]})})]}),d&&c.jsx("div",{className:"relative h-0",children:c.jsx("div",{className:"absolute inset-x-2 -top-px h-0.5 rounded-full bg-primary shadow-[0_0_0_1px_hsl(var(--background))]"})})]})}function vH({items:e,onRemove:r,onEdit:n,onReorder:i,onSendToParallelThread:s,className:o}){const a=y.useRef(null),l=y.useRef(null),[d,u]=y.useState(null),[f,p]=y.useState(null),[g,v]=y.useState(null);y.useEffect(()=>{if(d&&!e.some(C=>C.id===d)){u(null),p(null),v(null);return}f!=null&&f.targetId&&!e.some(C=>C.id===f.targetId)&&p(d?{targetId:d,placement:"before"}:null)},[d,f,e]),y.useEffect(()=>{var R;if(!d||!g)return;document.body.style.cursor="grabbing",document.body.style.userSelect="none",document.body.style.touchAction="none";const C=(L,z)=>{var K,M;const $=Array.from(((K=a.current)==null?void 0:K.querySelectorAll("[data-queue-id]"))??[]);if($.length===0){p(null);return}const W=$.filter(I=>I.dataset.queueId&&I.dataset.queueId!==d);if(W.length===0){p({targetId:null,placement:"after"});return}for(const I of W){const P=I.dataset.queueId;if(!P)continue;const F=I.getBoundingClientRect(),V=F.top+F.height/2;if(z<V){p({targetId:P,placement:"before"});return}}const B=((M=W[W.length-1])==null?void 0:M.dataset.queueId)??null;p(B?{targetId:B,placement:"after"}:{targetId:null,placement:"after"})},j=L=>{L.pointerId===g.pointerId&&(v(z=>z&&{...z,x:L.clientX,y:L.clientY}),C(L.clientX,L.clientY))},N=L=>{var $,W;if(L&&L.pointerId!==g.pointerId)return;d&&f&&f.targetId!==d&&(i==null||i(d,f.targetId,f.placement));const z=l.current;($=z==null?void 0:z.hasPointerCapture)!=null&&$.call(z,g.pointerId)&&((W=z.releasePointerCapture)==null||W.call(z,g.pointerId)),l.current=null,u(null),p(null),v(null)},A=()=>{N()},E=()=>{N()};return window.addEventListener("pointermove",j),window.addEventListener("pointerup",N),window.addEventListener("pointercancel",N),window.addEventListener("blur",E),(R=l.current)==null||R.addEventListener("lostpointercapture",A),()=>{var L;document.body.style.cursor="",document.body.style.userSelect="",document.body.style.touchAction="",window.removeEventListener("pointermove",j),window.removeEventListener("pointerup",N),window.removeEventListener("pointercancel",N),window.removeEventListener("blur",E),(L=l.current)==null||L.removeEventListener("lostpointercapture",A)}},[g,d,f,i]);const b=y.useCallback((C,j)=>{var E;if(!i||j.button!==0&&j.pointerType!=="touch"&&j.pointerType!=="pen")return;j.preventDefault();const N=j.currentTarget.closest("[data-queue-id]");if(!N)return;l.current=N,(E=N.setPointerCapture)==null||E.call(N,j.pointerId);const A=N.getBoundingClientRect();u(C),p({targetId:C,placement:"before"}),v({id:C,pointerId:j.pointerId,x:j.clientX,y:j.clientY,offsetX:j.clientX-A.left,offsetY:j.clientY-A.top,width:A.width,height:A.height})},[i]);if(e.length===0)return null;const _=d&&f&&(f.targetId!==d||f.placement==="after")?rZe(e,d,f.targetId,f.placement):e,k=g?_.findIndex(C=>C.id===g.id):-1,w=k>=0?_[k]:null;return c.jsxs("div",{ref:a,className:We("space-y-1.5",o),children:[c.jsx("div",{className:"flex items-center gap-1.5 px-0.5",children:c.jsxs("span",{className:"text-xs font-medium text-muted-foreground",children:[e.length," queued message",e.length!==1?"s":""]})}),_.map((C,j)=>c.jsx(iZe,{item:C,index:j,onRemove:r,onEdit:n,onReorder:i,onSendToParallelThread:s,dragActive:d===C.id,dropBefore:!!(d&&(f==null?void 0:f.targetId)===C.id&&f.placement==="before"&&d!==C.id),dropAfter:!!(d&&(f==null?void 0:f.targetId)===C.id&&f.placement==="after"&&d!==C.id),onDragStart:b},C.id)),g&&w&&c.jsx("div",{className:"pointer-events-none fixed z-50",style:{left:`${g.x-g.offsetX}px`,top:`${g.y-g.offsetY}px`,width:`${g.width}px`,minHeight:`${g.height}px`},children:c.jsx("div",{className:"scale-[1.01] opacity-95",children:c.jsx(nZe,{item:w,index:k})})})]})}function sZe({usage:e}){if(!e||e.limit<=0)return null;const r=Math.round(e.ratio*100),n=y.useMemo(()=>{if(!e||e.total===0)return[];const k=e.total;return[{label:"System",tokens:e.system,pct:Math.round(e.system/k*100),color:"var(--ctx-system)"},{label:"History",tokens:e.history,pct:Math.round(e.history/k*100),color:"var(--ctx-history)"},{label:"Tool Results",tokens:e.toolResults,pct:Math.round(e.toolResults/k*100),color:"var(--ctx-tool-results)"},{label:"Tools",tokens:e.tools,pct:Math.round(e.tools/k*100),color:"var(--ctx-tools)"}].filter(w=>w.tokens>0)},[e]),i=22,s=3,o=(i-s)/2,a=2*Math.PI*o,l=y.useMemo(()=>{if(!e||e.limit<=0)return[];const k=[];let w=0;for(const C of n){const N=C.tokens/e.limit*a;k.push({offset:w,length:N,color:C.color}),w+=N}return k},[n,e,a]),d=r>=90?"text-red-500":r>=75?"text-amber-500":"text-emerald-500",u=k=>k>=1e3?`${(k/1e3).toFixed(1)}k`:String(k),[f,p]=y.useState(!1),[g,v]=y.useState(!1),b=y.useCallback(()=>p(k=>!k),[]),_=y.useCallback(k=>{v(k),!k&&!f&&p(!1)},[f]);return c.jsxs(un,{open:f||g,onOpenChange:_,children:[c.jsx(dn,{asChild:!0,children:c.jsxs("button",{type:"button",onClick:b,className:"flex items-center gap-1.5 px-1.5 py-1 rounded-md hover:bg-muted/50 cursor-pointer transition-colors",children:[c.jsxs("svg",{width:i,height:i,viewBox:`0 0 ${i} ${i}`,className:`-rotate-90 ${d}`,children:[c.jsx("circle",{cx:i/2,cy:i/2,r:o,fill:"none",stroke:"currentColor",strokeWidth:s,opacity:.15}),l.map((k,w)=>c.jsx("circle",{cx:i/2,cy:i/2,r:o,fill:"none",stroke:k.color,strokeWidth:s,strokeDasharray:`${k.length} ${a-k.length}`,strokeDashoffset:-k.offset,strokeLinecap:"round",opacity:.85},w))]}),c.jsxs("span",{className:"text-2xs tabular-nums text-muted-foreground",children:[r,"%"]})]})}),c.jsx(on,{side:"bottom",className:"max-w-[220px] bg-popover text-popover-foreground border shadow-md",onPointerDownOutside:()=>p(!1),children:c.jsxs("div",{className:"space-y-1.5",children:[c.jsxs("div",{className:"flex items-center justify-between text-xs font-medium",children:[c.jsx("span",{children:"Context Window"}),c.jsxs("span",{className:"tabular-nums",children:[u(e.total)," / ",u(e.limit)]})]}),c.jsx("div",{className:"w-full h-1.5 rounded-full bg-muted overflow-hidden",children:c.jsx("div",{className:`h-full rounded-full transition-all ${r>=90?"bg-red-500":r>=75?"bg-amber-500":"bg-emerald-500"}`,style:{width:`${Math.min(r,100)}%`}})}),c.jsx("div",{className:"space-y-0.5",children:n.map(k=>c.jsxs("div",{className:"flex items-center justify-between text-xs",children:[c.jsxs("div",{className:"flex items-center gap-1.5",children:[c.jsx("span",{className:"inline-block w-2 h-2 rounded-full",style:{backgroundColor:k.color}}),c.jsx("span",{className:"text-muted-foreground",children:k.label})]}),c.jsxs("span",{className:"tabular-nums text-muted-foreground",children:[k.pct,"%"]})]},k.label))}),e.pruned&&c.jsx("div",{className:"text-2xs text-amber-500 pt-0.5 border-t border-border",children:"Old messages pruned to fit context"})]})})]})}const f1=$n(),oZe=Y0();function aZe(e){const[r,n]=y.useState([]),i=y.useCallback(async()=>{try{const l=e?`${f1}/api/consent/pending/${e}`:`${f1}/api/consent/pending`,u=await(await fetch(l)).json();n(u.requests)}catch{}},[e]);y.useEffect(()=>{const l=new WebSocket(oZe);return l.onmessage=d=>{try{const u=JSON.parse(d.data);if(u.type==="consent.required"){const f=u.payload;(!e||f.sessionId===e)&&n(p=>[...p,f])}if(u.type==="consent.resolved"){const f=u.payload;n(p=>p.filter(g=>g.id!==f.requestId))}}catch{}},l.onopen=()=>i(),()=>l.close()},[i,e]);const s=y.useCallback(async l=>{try{await fetch(`${f1}/api/consent/${l}/approve`,{method:"POST"}),n(d=>d.filter(u=>u.id!==l))}catch{}},[]),o=y.useCallback(async(l,d)=>{try{await fetch(`${f1}/api/consent/${l}/reject`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({reason:d})}),n(u=>u.filter(f=>f.id!==l))}catch{}},[]),a=y.useCallback(async(l,d)=>{try{const f=await(await fetch(`${f1}/api/consent/pending/${l}/approve-all`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({reason:d})})).json(),p=new Set(f.requestIds??[]);return p.size>0?n(g=>g.filter(v=>!p.has(v.id))):n(g=>g.filter(v=>v.sessionId!==l)),!0}catch{return!1}},[]);return{queue:r,approve:s,reject:o,approveAllForSession:a,refresh:i}}function lZe(){const[e,r]=y.useState(null),n=y.useCallback(async()=>{try{const s=await(await fetch(`${f1}/api/consent/policy`)).json();r(s)}catch{r(null)}},[]);return y.useEffect(()=>{n()},[n]),{policy:e,refresh:n}}function xH({risk:e}){const r={low:"bg-green-500/10 text-green-600 dark:text-green-400",medium:"bg-yellow-500/10 text-yellow-600 dark:text-yellow-400",high:"bg-red-500/10 text-red-600 dark:text-red-400"},i={low:H4,medium:hK,high:M8}[e];return c.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium ${r[e]}`,children:[c.jsx(i,{className:"h-3 w-3"}),e]})}function bH({level:e}){const r={none:"bg-emerald-500/10 text-emerald-600 dark:text-emerald-400",once:"bg-blue-500/10 text-blue-600 dark:text-blue-400",always:"bg-amber-500/10 text-amber-700 dark:text-amber-300",dangerous:"bg-red-500/10 text-red-600 dark:text-red-400"};return c.jsx("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium ${r[e]}`,children:e})}function _H({expiresAt:e}){const[r,n]=y.useState("");return y.useEffect(()=>{const i=()=>{const o=new Date(e).getTime()-Date.now();if(o<=0){n("expired");return}const a=Math.ceil(o/1e3);a>60?n(`${Math.ceil(a/60)}m`):n(`${a}s`)};i();const s=setInterval(i,1e3);return()=>clearInterval(s)},[e]),c.jsxs("span",{className:"inline-flex items-center gap-1 text-xs text-muted-foreground",children:[c.jsx(Xm,{className:"h-3 w-3"}),r]})}function wH({toolName:e}){return e.startsWith("terminal.")?c.jsx(Mo,{className:"h-4 w-4"}):e.startsWith("file.")?c.jsx(Bl,{className:"h-4 w-4"}):c.jsx(aK,{className:"h-4 w-4"})}function cZe({preview:e,toolName:r}){const n=e.command,i=e.path,s=e.content;return n?c.jsxs("div",{className:"rounded-md bg-muted p-3 font-mono text-xs leading-relaxed overflow-x-auto",children:[c.jsx("span",{className:"text-muted-foreground",children:"$ "}),n]}):i?c.jsxs("div",{className:"rounded-md bg-muted p-3 text-xs leading-relaxed overflow-x-auto",children:[c.jsxs("div",{className:"text-muted-foreground mb-1",children:[r,": ",i]}),s&&c.jsx("pre",{className:"font-mono whitespace-pre-wrap",children:s.length>500?s.slice(0,500)+"...":s})]}):c.jsx("div",{className:"rounded-md bg-muted p-3 font-mono text-xs leading-relaxed overflow-x-auto",children:JSON.stringify(e,null,2)})}function uZe({request:e,onApprove:r,onReject:n,compact:i=!1}){const[s,o]=y.useState(!1),a=async()=>{o(!0),r(e.id)},l=async()=>{o(!0),n(e.id)};return i?c.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 rounded-lg border bg-card",children:[c.jsx(wH,{toolName:e.toolName}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"text-xs font-medium truncate",children:e.toolName}),c.jsx(xH,{risk:e.risk}),c.jsx(bH,{level:e.policy.consentLevel}),c.jsx(_H,{expiresAt:e.expiresAt})]}),c.jsx("p",{className:"text-xs text-muted-foreground truncate",children:e.summary})]}),c.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[c.jsxs("button",{onClick:a,disabled:s,className:"inline-flex items-center gap-1 px-2.5 py-1 rounded-md text-xs font-medium bg-green-500/10 text-green-600 dark:text-green-400 hover:bg-green-500/20 disabled:opacity-50 transition-colors",children:[c.jsx(cD,{className:"h-3 w-3"}),"Approve"]}),c.jsxs("button",{onClick:l,disabled:s,className:"inline-flex items-center gap-1 px-2.5 py-1 rounded-md text-xs font-medium bg-red-500/10 text-red-600 dark:text-red-400 hover:bg-red-500/20 disabled:opacity-50 transition-colors",children:[c.jsx(M8,{className:"h-3 w-3"}),"Reject"]})]})]}):c.jsxs("div",{className:"rounded-lg border bg-card shadow-sm overflow-hidden",children:[c.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b bg-muted/30",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(wH,{toolName:e.toolName}),c.jsx("span",{className:"text-sm font-medium",children:e.toolName}),c.jsx(xH,{risk:e.risk}),c.jsx(bH,{level:e.policy.consentLevel})]}),c.jsx(_H,{expiresAt:e.expiresAt})]}),c.jsxs("div",{className:"p-4 space-y-3",children:[c.jsx("p",{className:"text-sm text-foreground",children:e.summary}),c.jsxs("div",{className:"space-y-1",children:[c.jsx("p",{className:"text-xs text-muted-foreground",children:e.policy.description}),!e.policy.knownTool&&c.jsx("p",{className:"text-xs text-red-600 dark:text-red-400",children:"Unknown tool: blocked behind dangerous consent until added to the active profile."})]}),c.jsx(cZe,{preview:e.preview,toolName:e.toolName})]}),c.jsxs("div",{className:"flex items-center justify-end gap-2 px-4 py-3 border-t bg-muted/20",children:[c.jsxs("button",{onClick:l,disabled:s,className:"inline-flex items-center gap-1.5 px-4 py-2 rounded-md text-xs font-medium bg-red-500/10 text-red-600 dark:text-red-400 hover:bg-red-500/20 disabled:opacity-50 transition-colors",children:[c.jsx(M8,{className:"h-3.5 w-3.5"}),"Reject"]}),c.jsxs("button",{onClick:a,disabled:s,className:"inline-flex items-center gap-1.5 px-4 py-2 rounded-md text-xs font-medium bg-green-500/10 text-green-600 dark:text-green-400 hover:bg-green-500/20 disabled:opacity-50 transition-colors",children:[c.jsx(cD,{className:"h-3.5 w-3.5"}),"Approve"]})]})]})}function dZe({status:e}){const r={running:{icon:ir,label:"Running",color:"bg-blue-500/10 text-blue-600 dark:text-blue-400"},"awaiting-approval":{icon:hK,label:"Awaiting Approval",color:"bg-yellow-500/10 text-yellow-600 dark:text-yellow-400"},"needs-input":{icon:Xm,label:"Needs Input",color:"bg-orange-500/10 text-orange-600 dark:text-orange-400"},completed:{icon:ql,label:"Completed",color:"bg-green-500/10 text-green-600 dark:text-green-400"},failed:{icon:Ah,label:"Failed",color:"bg-red-500/10 text-red-600 dark:text-red-400"}},{icon:n,label:i,color:s}=r[e];return c.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium ${s}`,children:[c.jsx(n,{className:`h-3 w-3 ${e==="running"?"animate-spin":""}`}),i]})}function hZe({className:e="",compact:r=!1,sessionId:n,onApproveAllEnabled:i}){const{queue:s,approve:o,reject:a,approveAllForSession:l}=aZe(n),{policy:d}=lZe(),[u,f]=y.useState(!1),p=y.useMemo(()=>n?s.filter(v=>v.sessionId===n):s,[s,n]),g=async()=>{if(!n||u)return;f(!0),await l(n)&&(i==null||i()),f(!1)};return p.length===0?null:c.jsxs("div",{className:`space-y-2 ${e}`,children:[c.jsxs("div",{className:"flex items-center justify-between px-1",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(dZe,{status:"awaiting-approval"}),c.jsxs("div",{className:"flex flex-col",children:[c.jsxs("span",{className:"text-xs text-muted-foreground",children:[p.length," pending ",p.length===1?"request":"requests"]}),d&&c.jsxs("span",{className:"text-xs text-muted-foreground",children:["Profile: ",c.jsx("span",{className:"font-medium text-foreground",children:d.activeProfileName??"custom"})," ","• ",d.toolCount," configured tools • unknown tools require dangerous consent"]})]})]}),n&&p.length>0&&c.jsx("button",{onClick:g,disabled:u,className:"text-xs text-green-600 hover:text-green-500 dark:text-green-400 dark:hover:text-green-300 disabled:opacity-50 disabled:cursor-not-allowed",children:u?"Approving...":"Approve all in this session"})]}),c.jsx("div",{className:"space-y-2",children:p.map(v=>c.jsx(uZe,{request:v,onApprove:o,onReject:a,compact:r},v.id))})]})}const SH=5e3;let fZe=0,b1=[],i4=new Set;function lE(e,r){b1.push({id:fZe++,ts:Date.now(),type:e,raw:r}),b1.length>SH&&(b1=b1.slice(-SH)),i4.forEach(n=>n())}function pZe(){b1=[],i4.forEach(e=>e())}function mZe(){const[,e]=y.useState(0);return y.useEffect(()=>{const r=()=>e(n=>n+1);return i4.add(r),()=>{i4.delete(r)}},[]),b1}const gZe={request:"text-orange-400",token:"text-gray-400",tool_call_delta:"text-blue-400",tool_start:"text-yellow-400",tool_output:"text-green-400",tool_result:"text-emerald-400",thinking:"text-purple-400",done:"text-gray-500",error:"text-red-400"},cE=20;function yZe({onClose:e}){const r=mZe(),n=y.useRef(null),[i,s]=y.useState(!0),[o,a]=y.useState(""),[l,d]=y.useState(!1),[u,f]=y.useState(new Set),p=y.useCallback(k=>{f(w=>{const C=new Set(w);return C.has(k)?C.delete(k):C.add(k),C})},[]),g=o?r.filter(k=>k.type.includes(o)||k.raw.includes(o)):r,v=JR({count:g.length,getScrollElement:()=>n.current,estimateSize:()=>cE,overscan:30}),b=()=>{const k=g.map(w=>`${new Date(w.ts).toISOString().slice(11,23)} ${w.type} ${w.raw}`).join(`
|
|
1163
1163
|
`);navigator.clipboard.writeText(k),d(!0),setTimeout(()=>d(!1),1500)};y.useEffect(()=>{i&&g.length>0&&v.scrollToIndex(g.length-1,{align:"end"})},[g.length,i]);const _=y.useCallback(()=>{const k=n.current;if(!k)return;const w=k.scrollHeight-k.scrollTop-k.clientHeight<40;s(w)},[]);return c.jsxs("div",{className:"flex flex-col h-full bg-[#0d1117] text-[#c9d1d9] text-xs font-mono",children:[c.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 border-b border-zinc-700/60 shrink-0",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"text-xs font-semibold text-zinc-400 uppercase tracking-wider",children:"SSE Debug"}),c.jsxs("span",{className:"text-2xs text-zinc-500",children:[g.length,"/",r.length]})]}),c.jsxs("div",{className:"flex items-center gap-1",children:[c.jsx("input",{type:"text",placeholder:"Filter...",value:o,onChange:k=>a(k.target.value),className:"h-5 w-28 px-1.5 text-2xs rounded bg-zinc-800 border border-zinc-700 text-zinc-300 placeholder-zinc-500 focus:outline-none focus:border-blue-500"}),c.jsx(_e,{variant:"ghost",size:"icon",className:"h-5 w-5",onClick:b,title:"Copy all events",children:l?c.jsx(hs,{className:"h-3 w-3 text-green-400"}):c.jsx(wc,{className:"h-3 w-3"})}),c.jsx(_e,{variant:"ghost",size:"icon",className:"h-5 w-5",onClick:pZe,children:c.jsx(Sh,{className:"h-3 w-3"})}),c.jsx(_e,{variant:"ghost",size:"icon",className:"h-5 w-5",onClick:e,children:c.jsx(Jn,{className:"h-3 w-3"})})]})]}),c.jsx("div",{ref:n,onScroll:_,className:"flex-1 overflow-y-auto overflow-x-hidden",children:c.jsx("div",{style:{height:`${v.getTotalSize()}px`,position:"relative",width:"100%"},children:v.getVirtualItems().map(k=>{const w=g[k.index],C=new Date(w.ts).toISOString().slice(11,23),j=gZe[w.type]??"text-zinc-400",N=w.raw.length>120,A=u.has(w.id),E=N&&!A?w.raw.slice(0,120)+"…":w.raw;return c.jsxs("div",{"data-index":k.index,ref:v.measureElement,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${k.start}px)`},className:We("flex gap-2 px-2 hover:bg-zinc-800/50 leading-tight cursor-pointer select-none",A?"items-start py-1 bg-zinc-800/30":"items-center"),onClick:()=>p(w.id),children:[c.jsx("span",{className:"text-zinc-600 shrink-0 w-20",style:{minHeight:cE},children:C}),c.jsx("span",{className:We("shrink-0 w-28 text-right",j),style:{minHeight:cE},children:w.type}),c.jsxs("span",{className:We("text-zinc-400 min-w-0",A?"break-all whitespace-pre-wrap":"truncate"),children:[E,N&&!A&&c.jsx("span",{className:"text-zinc-600 ml-1",children:"▸"})]})]},w.id)})})}),!i&&c.jsx("div",{className:"absolute bottom-2 right-4",children:c.jsx(_e,{variant:"outline",size:"icon",className:"h-6 w-6 rounded-full bg-zinc-800 border-zinc-600",onClick:()=>{s(!0),v.scrollToIndex(g.length-1,{align:"end"})},children:c.jsx(JG,{className:"h-3 w-3"})})})]})}function vZe(e,r=[]){let n=[];function i(o,a){const l=y.createContext(a),d=n.length;n=[...n,a];const u=p=>{var w;const{scope:g,children:v,...b}=p,_=((w=g==null?void 0:g[e])==null?void 0:w[d])||l,k=y.useMemo(()=>b,Object.values(b));return c.jsx(_.Provider,{value:k,children:v})};u.displayName=o+"Provider";function f(p,g){var _;const v=((_=g==null?void 0:g[e])==null?void 0:_[d])||l,b=y.useContext(v);if(b)return b;if(a!==void 0)return a;throw new Error(`\`${p}\` must be used within \`${o}\``)}return[u,f]}const s=()=>{const o=n.map(a=>y.createContext(a));return function(l){const d=(l==null?void 0:l[e])||o;return y.useMemo(()=>({[`__scope${e}`]:{...l,[e]:d}}),[l,d])}};return s.scopeName=e,[i,xZe(s,...r)]}function xZe(...e){const r=e[0];if(e.length===1)return r;const n=()=>{const i=e.map(s=>({useScope:s(),scopeName:s.scopeName}));return function(o){const a=i.reduce((l,{useScope:d,scopeName:u})=>{const p=d(o)[`__scope${u}`];return{...l,...p}},{});return y.useMemo(()=>({[`__scope${r.scopeName}`]:a}),[a])}};return n.scopeName=r.scopeName,n}function rae(e){const r=y.useRef({value:e,previous:e});return y.useMemo(()=>(r.current.value!==e&&(r.current.previous=r.current.value,r.current.value=e),r.current.previous),[e])}function bZe(e){const r=_Ze(e),n=y.forwardRef((i,s)=>{const{children:o,...a}=i,l=y.Children.toArray(o),d=l.find(SZe);if(d){const u=d.props.children,f=l.map(p=>p===d?y.Children.count(u)>1?y.Children.only(null):y.isValidElement(u)?u.props.children:null:p);return c.jsx(r,{...a,ref:s,children:y.isValidElement(u)?y.cloneElement(u,void 0,f):null})}return c.jsx(r,{...a,ref:s,children:o})});return n.displayName=`${e}.Slot`,n}function _Ze(e){const r=y.forwardRef((n,i)=>{const{children:s,...o}=n;if(y.isValidElement(s)){const a=CZe(s),l=kZe(o,s.props);return s.type!==y.Fragment&&(l.ref=i?xs(i,a):a),y.cloneElement(s,l)}return y.Children.count(s)>1?y.Children.only(null):null});return r.displayName=`${e}.SlotClone`,r}var wZe=Symbol("radix.slottable");function SZe(e){return y.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===wZe}function kZe(e,r){const n={...r};for(const i in r){const s=e[i],o=r[i];/^on[A-Z]/.test(i)?s&&o?n[i]=(...l)=>{const d=o(...l);return s(...l),d}:s&&(n[i]=s):i==="style"?n[i]={...s,...o}:i==="className"&&(n[i]=[s,o].filter(Boolean).join(" "))}return{...e,...n}}function CZe(e){var i,s;let r=(i=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:i.get,n=r&&"isReactWarning"in r&&r.isReactWarning;return n?e.ref:(r=(s=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:s.get,n=r&&"isReactWarning"in r&&r.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}var jZe=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],nae=jZe.reduce((e,r)=>{const n=bZe(`Primitive.${r}`),i=y.forwardRef((s,o)=>{const{asChild:a,...l}=s,d=a?n:r;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),c.jsx(d,{...l,ref:o})});return i.displayName=`Primitive.${r}`,{...e,[r]:i}},{}),s6="Switch",[NZe]=vZe(s6),[TZe,EZe]=NZe(s6),iae=y.forwardRef((e,r)=>{const{__scopeSwitch:n,name:i,checked:s,defaultChecked:o,required:a,disabled:l,value:d="on",onCheckedChange:u,form:f,...p}=e,[g,v]=y.useState(null),b=xn(r,j=>v(j)),_=y.useRef(!1),k=g?f||!!g.closest("form"):!0,[w,C]=Eh({prop:s,defaultProp:o??!1,onChange:u,caller:s6});return c.jsxs(TZe,{scope:n,checked:w,disabled:l,children:[c.jsx(nae.button,{type:"button",role:"switch","aria-checked":w,"aria-required":a,"data-state":lae(w),"data-disabled":l?"":void 0,disabled:l,value:d,...p,ref:b,onClick:tr(e.onClick,j=>{C(N=>!N),k&&(_.current=j.isPropagationStopped(),_.current||j.stopPropagation())})}),k&&c.jsx(aae,{control:g,bubbles:!_.current,name:i,value:d,checked:w,required:a,disabled:l,form:f,style:{transform:"translateX(-100%)"}})]})});iae.displayName=s6;var sae="SwitchThumb",oae=y.forwardRef((e,r)=>{const{__scopeSwitch:n,...i}=e,s=EZe(sae,n);return c.jsx(nae.span,{"data-state":lae(s.checked),"data-disabled":s.disabled?"":void 0,...i,ref:r})});oae.displayName=sae;var AZe="SwitchBubbleInput",aae=y.forwardRef(({__scopeSwitch:e,control:r,checked:n,bubbles:i=!0,...s},o)=>{const a=y.useRef(null),l=xn(a,o),d=rae(n),u=IK(r);return y.useEffect(()=>{const f=a.current;if(!f)return;const p=window.HTMLInputElement.prototype,v=Object.getOwnPropertyDescriptor(p,"checked").set;if(d!==n&&v){const b=new Event("click",{bubbles:i});v.call(f,n),f.dispatchEvent(b)}},[d,n,i]),c.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...s,tabIndex:-1,ref:l,style:{...s.style,...u,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});aae.displayName=AZe;function lae(e){return e?"checked":"unchecked"}var cae=iae,OZe=oae;const Yf=y.forwardRef(({className:e,...r},n)=>c.jsx(cae,{className:We("peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",e),...r,ref:n,children:c.jsx(OZe,{className:We("pointer-events-none block h-4 w-4 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0")})}));Yf.displayName=cae.displayName;var LS="Ollama",RZe=.6,MZe=.1,uae="#fff",PZe=uae,LZe="#000",$Ze=.75;function q2(e){"@babel/helpers - typeof";return q2=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(r){return typeof r}:function(r){return r&&typeof Symbol=="function"&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r},q2(e)}var DZe=["size","style"];function kH(e,r){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);r&&(i=i.filter(function(s){return Object.getOwnPropertyDescriptor(e,s).enumerable})),n.push.apply(n,i)}return n}function uE(e){for(var r=1;r<arguments.length;r++){var n=arguments[r]!=null?arguments[r]:{};r%2?kH(Object(n),!0).forEach(function(i){IZe(e,i,n[i])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):kH(Object(n)).forEach(function(i){Object.defineProperty(e,i,Object.getOwnPropertyDescriptor(n,i))})}return e}function IZe(e,r,n){return r=BZe(r),r in e?Object.defineProperty(e,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[r]=n,e}function BZe(e){var r=zZe(e,"string");return q2(r)=="symbol"?r:String(r)}function zZe(e,r){if(q2(e)!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var i=n.call(e,r);if(q2(i)!="object")return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return(r==="string"?String:Number)(e)}function FZe(e,r){if(e==null)return{};var n=HZe(e,r),i,s;if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(s=0;s<o.length;s++)i=o[s],!(r.indexOf(i)>=0)&&Object.prototype.propertyIsEnumerable.call(e,i)&&(n[i]=e[i])}return n}function HZe(e,r){if(e==null)return{};var n={},i=Object.keys(e),s,o;for(o=0;o<i.length;o++)s=i[o],!(r.indexOf(s)>=0)&&(n[s]=e[s]);return n}var nP=y.memo(function(e){var r=e.size,n=r===void 0?"1em":r,i=e.style,s=FZe(e,DZe);return c.jsxs("svg",uE(uE({fill:"currentColor",fillRule:"evenodd",height:n,style:uE({flex:"none",lineHeight:1},i),viewBox:"0 0 24 24",width:n,xmlns:"http://www.w3.org/2000/svg"},s),{},{children:[c.jsx("title",{children:LS}),c.jsx("path",{d:"M7.905 1.09c.216.085.411.225.588.41.295.306.544.744.734 1.263.191.522.315 1.1.362 1.68a5.054 5.054 0 012.049-.636l.051-.004c.87-.07 1.73.087 2.48.474.101.053.2.11.297.17.05-.569.172-1.134.36-1.644.19-.52.439-.957.733-1.264a1.67 1.67 0 01.589-.41c.257-.1.53-.118.796-.042.401.114.745.368 1.016.737.248.337.434.769.561 1.287.23.934.27 2.163.115 3.645l.053.04.026.019c.757.576 1.284 1.397 1.563 2.35.435 1.487.216 3.155-.534 4.088l-.018.021.002.003c.417.762.67 1.567.724 2.4l.002.03c.064 1.065-.2 2.137-.814 3.19l-.007.01.01.024c.472 1.157.62 2.322.438 3.486l-.006.039a.651.651 0 01-.747.536.648.648 0 01-.54-.742c.167-1.033.01-2.069-.48-3.123a.643.643 0 01.04-.617l.004-.006c.604-.924.854-1.83.8-2.72-.046-.779-.325-1.544-.8-2.273a.644.644 0 01.18-.886l.009-.006c.243-.159.467-.565.58-1.12a4.229 4.229 0 00-.095-1.974c-.205-.7-.58-1.284-1.105-1.683-.595-.454-1.383-.673-2.38-.61a.653.653 0 01-.632-.371c-.314-.665-.772-1.141-1.343-1.436a3.288 3.288 0 00-1.772-.332c-1.245.099-2.343.801-2.67 1.686a.652.652 0 01-.61.425c-1.067.002-1.893.252-2.497.703-.522.39-.878.935-1.066 1.588a4.07 4.07 0 00-.068 1.886c.112.558.331 1.02.582 1.269l.008.007c.212.207.257.53.109.785-.36.622-.629 1.549-.673 2.44-.05 1.018.186 1.902.719 2.536l.016.019a.643.643 0 01.095.69c-.576 1.236-.753 2.252-.562 3.052a.652.652 0 01-1.269.298c-.243-1.018-.078-2.184.473-3.498l.014-.035-.008-.012a4.339 4.339 0 01-.598-1.309l-.005-.019a5.764 5.764 0 01-.177-1.785c.044-.91.278-1.842.622-2.59l.012-.026-.002-.002c-.293-.418-.51-.953-.63-1.545l-.005-.024a5.352 5.352 0 01.093-2.49c.262-.915.777-1.701 1.536-2.269.06-.045.123-.09.186-.132-.159-1.493-.119-2.73.112-3.67.127-.518.314-.95.562-1.287.27-.368.614-.622 1.015-.737.266-.076.54-.059.797.042zm4.116 9.09c.936 0 1.8.313 2.446.855.63.527 1.005 1.235 1.005 1.94 0 .888-.406 1.58-1.133 2.022-.62.375-1.451.557-2.403.557-1.009 0-1.871-.259-2.493-.734-.617-.47-.963-1.13-.963-1.845 0-.707.398-1.417 1.056-1.946.668-.537 1.55-.849 2.485-.849zm0 .896a3.07 3.07 0 00-1.916.65c-.461.37-.722.835-.722 1.25 0 .428.21.829.61 1.134.455.347 1.124.548 1.943.548.799 0 1.473-.147 1.932-.426.463-.28.7-.686.7-1.257 0-.423-.246-.89-.683-1.256-.484-.405-1.14-.643-1.864-.643zm.662 1.21l.004.004c.12.151.095.37-.056.49l-.292.23v.446a.375.375 0 01-.376.373.375.375 0 01-.376-.373v-.46l-.271-.218a.347.347 0 01-.052-.49.353.353 0 01.494-.051l.215.172.22-.174a.353.353 0 01.49.051zm-5.04-1.919c.478 0 .867.39.867.871a.87.87 0 01-.868.871.87.87 0 01-.867-.87.87.87 0 01.867-.872zm8.706 0c.48 0 .868.39.868.871a.87.87 0 01-.868.871.87.87 0 01-.867-.87.87.87 0 01.867-.872zM7.44 2.3l-.003.002a.659.659 0 00-.285.238l-.005.006c-.138.189-.258.467-.348.832-.17.692-.216 1.631-.124 2.782.43-.128.899-.208 1.404-.237l.01-.001.019-.034c.046-.082.095-.161.148-.239.123-.771.022-1.692-.253-2.444-.134-.364-.297-.65-.453-.813a.628.628 0 00-.107-.09L7.44 2.3zm9.174.04l-.002.001a.628.628 0 00-.107.09c-.156.163-.32.45-.453.814-.29.794-.387 1.776-.23 2.572l.058.097.008.014h.03a5.184 5.184 0 011.466.212c.086-1.124.038-2.043-.128-2.722-.09-.365-.21-.643-.349-.832l-.004-.006a.659.659 0 00-.285-.239h-.004z"})]}))});function G2(e){"@babel/helpers - typeof";return G2=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(r){return typeof r}:function(r){return r&&typeof Symbol=="function"&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r},G2(e)}function CH(e,r){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);r&&(i=i.filter(function(s){return Object.getOwnPropertyDescriptor(e,s).enumerable})),n.push.apply(n,i)}return n}function WZe(e){for(var r=1;r<arguments.length;r++){var n=arguments[r]!=null?arguments[r]:{};r%2?CH(Object(n),!0).forEach(function(i){UZe(e,i,n[i])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):CH(Object(n)).forEach(function(i){Object.defineProperty(e,i,Object.getOwnPropertyDescriptor(n,i))})}return e}function UZe(e,r,n){return r=VZe(r),r in e?Object.defineProperty(e,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[r]=n,e}function VZe(e){var r=qZe(e,"string");return G2(r)=="symbol"?r:String(r)}function qZe(e,r){if(G2(e)!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var i=n.call(e,r);if(G2(i)!="object")return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return(r==="string"?String:Number)(e)}function GZe(e){if(e==null)throw new TypeError("Cannot destructure "+e)}var KZe=y.memo(function(e){var r=Object.assign({},(GZe(e),e));return c.jsx(pl,WZe({Icon:nP,"aria-label":LS,background:PZe,color:LZe,iconMultiple:$Ze},r))});function K2(e){"@babel/helpers - typeof";return K2=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(r){return typeof r}:function(r){return r&&typeof Symbol=="function"&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r},K2(e)}var YZe=["size","style"];function jH(e,r){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);r&&(i=i.filter(function(s){return Object.getOwnPropertyDescriptor(e,s).enumerable})),n.push.apply(n,i)}return n}function dE(e){for(var r=1;r<arguments.length;r++){var n=arguments[r]!=null?arguments[r]:{};r%2?jH(Object(n),!0).forEach(function(i){XZe(e,i,n[i])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):jH(Object(n)).forEach(function(i){Object.defineProperty(e,i,Object.getOwnPropertyDescriptor(n,i))})}return e}function XZe(e,r,n){return r=ZZe(r),r in e?Object.defineProperty(e,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[r]=n,e}function ZZe(e){var r=JZe(e,"string");return K2(r)=="symbol"?r:String(r)}function JZe(e,r){if(K2(e)!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var i=n.call(e,r);if(K2(i)!="object")return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return(r==="string"?String:Number)(e)}function QZe(e,r){if(e==null)return{};var n=eJe(e,r),i,s;if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(s=0;s<o.length;s++)i=o[s],!(r.indexOf(i)>=0)&&Object.prototype.propertyIsEnumerable.call(e,i)&&(n[i]=e[i])}return n}function eJe(e,r){if(e==null)return{};var n={},i=Object.keys(e),s,o;for(o=0;o<i.length;o++)s=i[o],!(r.indexOf(s)>=0)&&(n[s]=e[s]);return n}var dae=y.memo(function(e){var r=e.size,n=r===void 0?"1em":r,i=e.style,s=QZe(e,YZe);return c.jsxs("svg",dE(dE({fill:"currentColor",fillRule:"evenodd",height:n,style:dE({flex:"none",lineHeight:1},i),viewBox:"0 0 87 24",xmlns:"http://www.w3.org/2000/svg"},s),{},{children:[c.jsx("title",{children:LS}),c.jsx("path",{d:"M11.333 2c-2.959 0-5.272.943-6.94 2.884C2.78 6.717 2 9.09 2 12.027c0 2.911.78 5.283 2.394 7.116C6.06 21.03 8.374 22 11.333 22c2.931 0 5.244-.943 6.939-2.83 1.614-1.806 2.42-4.178 2.42-7.143s-.806-5.364-2.42-7.17C16.577 2.943 14.264 2 11.332 2zm0 2.776c1.99 0 3.523.62 4.599 1.914 1.049 1.294 1.587 3.073 1.587 5.337s-.538 4.016-1.587 5.283c-1.076 1.267-2.609 1.914-4.6 1.914-1.99 0-3.55-.674-4.625-1.995-1.05-1.294-1.56-3.019-1.56-5.202 0-2.21.51-3.935 1.56-5.23 1.102-1.347 2.636-2.02 4.626-2.02zM22.979 2v19.623h3.066V2h-3.066zm6.159 0v19.623h3.066V2h-3.066zm12.21 5.31c-1.775 0-3.173.296-4.195.943-1.21.701-1.964 1.833-2.26 3.37l3.04.242c.161-.728.564-1.267 1.156-1.617.511-.323 1.184-.458 2.044-.458 1.99 0 2.986.89 2.986 2.722v.54l-3.04.08c-2.044.054-3.63.485-4.76 1.294-1.237.835-1.829 2.048-1.829 3.612 0 1.159.43 2.102 1.29 2.857.835.728 1.964 1.105 3.417 1.105 1.21 0 2.259-.216 3.146-.62.78-.377 1.453-.89 1.99-1.59v1.833h2.852v-8.895c0-1.698-.43-2.992-1.291-3.882-.969-1.024-2.502-1.536-4.546-1.536zm2.77 7.951v.701c0 1.078-.43 1.968-1.237 2.669-.806.674-1.802 1.024-2.985 1.024-.672 0-1.21-.189-1.64-.512-.431-.324-.62-.728-.62-1.213 0-1.614 1.129-2.473 3.41-2.58l3.073-.089zM56.572 7.31c-1.344 0-2.609.593-3.765 1.806V7.687H49.74v13.936h3.066v-8.356c0-.917.269-1.725.807-2.372.538-.7 1.237-1.024 2.125-1.024 1.828 0 2.743 1.05 2.743 3.18v8.572h3.066v-8.518c0-1.024.242-1.806.78-2.372.511-.593 1.13-.862 1.883-.862 1.075 0 1.829.242 2.313.754.457.486.699 1.294.699 2.4v8.598h3.066v-9.138c0-1.536-.484-2.776-1.398-3.746-.969-.97-2.152-1.429-3.578-1.429-.941 0-1.72.162-2.34.485-.699.324-1.371.917-2.017 1.78-.887-1.51-2.34-2.265-4.384-2.265zm22.593 0c-1.775 0-3.174.296-4.196.943-1.21.701-1.963 1.833-2.26 3.37l3.04.242c.161-.728.565-1.267 1.156-1.617.511-.323 1.184-.458 2.044-.458 1.99 0 2.986.89 2.986 2.722v.54l-3.04.08c-2.043.054-3.63.485-4.76 1.294-1.237.835-1.829 2.048-1.829 3.612 0 1.159.43 2.102 1.291 2.857.834.728 1.964 1.105 3.416 1.105 1.21 0 2.26-.216 3.147-.62.78-.377 1.452-.89 1.99-1.59v1.833H85v-8.895c0-1.698-.43-2.992-1.291-3.882-.968-1.024-2.501-1.536-4.545-1.536zm2.77 7.951v.701c0 1.078-.43 1.968-1.237 2.669-.807.674-1.802 1.024-2.986 1.024-.672 0-1.21-.189-1.64-.512-.43-.324-.619-.728-.619-1.213 0-1.614 1.128-2.473 3.41-2.58l3.072-.089z"})]}))});function Y2(e){"@babel/helpers - typeof";return Y2=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(r){return typeof r}:function(r){return r&&typeof Symbol=="function"&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r},Y2(e)}function NH(e,r){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);r&&(i=i.filter(function(s){return Object.getOwnPropertyDescriptor(e,s).enumerable})),n.push.apply(n,i)}return n}function tJe(e){for(var r=1;r<arguments.length;r++){var n=arguments[r]!=null?arguments[r]:{};r%2?NH(Object(n),!0).forEach(function(i){rJe(e,i,n[i])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):NH(Object(n)).forEach(function(i){Object.defineProperty(e,i,Object.getOwnPropertyDescriptor(n,i))})}return e}function rJe(e,r,n){return r=nJe(r),r in e?Object.defineProperty(e,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[r]=n,e}function nJe(e){var r=iJe(e,"string");return Y2(r)=="symbol"?r:String(r)}function iJe(e,r){if(Y2(e)!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var i=n.call(e,r);if(Y2(i)!="object")return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return(r==="string"?String:Number)(e)}function sJe(e){if(e==null)throw new TypeError("Cannot destructure "+e)}var oJe=y.memo(function(e){var r=Object.assign({},(sJe(e),e));return c.jsx(ml,tJe({Icon:nP,Text:dae,"aria-label":LS,spaceMultiple:MZe,textMultiple:RZe},r))}),ey=nP;ey.Text=dae;ey.Combine=oJe;ey.Avatar=KZe;ey.colorPrimary=uae;ey.title=LS;var M0="Qwen",aJe=.7,lJe=.2,hae="#615ced",cJe="linear-gradient(to right, #6336E7, #6F69F7)",uJe=hae,dJe="#fff",hJe=.75;function X2(e){"@babel/helpers - typeof";return X2=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(r){return typeof r}:function(r){return r&&typeof Symbol=="function"&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r},X2(e)}var fJe=["size","style"];function TH(e,r){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);r&&(i=i.filter(function(s){return Object.getOwnPropertyDescriptor(e,s).enumerable})),n.push.apply(n,i)}return n}function hE(e){for(var r=1;r<arguments.length;r++){var n=arguments[r]!=null?arguments[r]:{};r%2?TH(Object(n),!0).forEach(function(i){pJe(e,i,n[i])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):TH(Object(n)).forEach(function(i){Object.defineProperty(e,i,Object.getOwnPropertyDescriptor(n,i))})}return e}function pJe(e,r,n){return r=mJe(r),r in e?Object.defineProperty(e,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[r]=n,e}function mJe(e){var r=gJe(e,"string");return X2(r)=="symbol"?r:String(r)}function gJe(e,r){if(X2(e)!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var i=n.call(e,r);if(X2(i)!="object")return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return(r==="string"?String:Number)(e)}function yJe(e,r){if(e==null)return{};var n=vJe(e,r),i,s;if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(s=0;s<o.length;s++)i=o[s],!(r.indexOf(i)>=0)&&Object.prototype.propertyIsEnumerable.call(e,i)&&(n[i]=e[i])}return n}function vJe(e,r){if(e==null)return{};var n={},i=Object.keys(e),s,o;for(o=0;o<i.length;o++)s=i[o],!(r.indexOf(s)>=0)&&(n[s]=e[s]);return n}var iP=y.memo(function(e){var r=e.size,n=r===void 0?"1em":r,i=e.style,s=yJe(e,fJe);return c.jsxs("svg",hE(hE({fill:"currentColor",fillRule:"evenodd",height:n,style:hE({flex:"none",lineHeight:1},i),viewBox:"0 0 24 24",width:n,xmlns:"http://www.w3.org/2000/svg"},s),{},{children:[c.jsx("title",{children:M0}),c.jsx("path",{d:"M12.604 1.34c.393.69.784 1.382 1.174 2.075a.18.18 0 00.157.091h5.552c.174 0 .322.11.446.327l1.454 2.57c.19.337.24.478.024.837-.26.43-.513.864-.76 1.3l-.367.658c-.106.196-.223.28-.04.512l2.652 4.637c.172.301.111.494-.043.77-.437.785-.882 1.564-1.335 2.34-.159.272-.352.375-.68.37-.777-.016-1.552-.01-2.327.016a.099.099 0 00-.081.05 575.097 575.097 0 01-2.705 4.74c-.169.293-.38.363-.725.364-.997.003-2.002.004-3.017.002a.537.537 0 01-.465-.271l-1.335-2.323a.09.09 0 00-.083-.049H4.982c-.285.03-.553-.001-.805-.092l-1.603-2.77a.543.543 0 01-.002-.54l1.207-2.12a.198.198 0 000-.197 550.951 550.951 0 01-1.875-3.272l-.79-1.395c-.16-.31-.173-.496.095-.965.465-.813.927-1.625 1.387-2.436.132-.234.304-.334.584-.335a338.3 338.3 0 012.589-.001.124.124 0 00.107-.063l2.806-4.895a.488.488 0 01.422-.246c.524-.001 1.053 0 1.583-.006L11.704 1c.341-.003.724.032.9.34zm-3.432.403a.06.06 0 00-.052.03L6.254 6.788a.157.157 0 01-.135.078H3.253c-.056 0-.07.025-.041.074l5.81 10.156c.025.042.013.062-.034.063l-2.795.015a.218.218 0 00-.2.116l-1.32 2.31c-.044.078-.021.118.068.118l5.716.008c.046 0 .08.02.104.061l1.403 2.454c.046.081.092.082.139 0l5.006-8.76.783-1.382a.055.055 0 01.096 0l1.424 2.53a.122.122 0 00.107.062l2.763-.02a.04.04 0 00.035-.02.041.041 0 000-.04l-2.9-5.086a.108.108 0 010-.113l.293-.507 1.12-1.977c.024-.041.012-.062-.035-.062H9.2c-.059 0-.073-.026-.043-.077l1.434-2.505a.107.107 0 000-.114L9.225 1.774a.06.06 0 00-.053-.031zm6.29 8.02c.046 0 .058.02.034.06l-.832 1.465-2.613 4.585a.056.056 0 01-.05.029.058.058 0 01-.05-.029L8.498 9.841c-.02-.034-.01-.052.028-.054l.216-.012 6.722-.012z"})]}))});function Z2(e){"@babel/helpers - typeof";return Z2=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(r){return typeof r}:function(r){return r&&typeof Symbol=="function"&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r},Z2(e)}function EH(e,r){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);r&&(i=i.filter(function(s){return Object.getOwnPropertyDescriptor(e,s).enumerable})),n.push.apply(n,i)}return n}function xJe(e){for(var r=1;r<arguments.length;r++){var n=arguments[r]!=null?arguments[r]:{};r%2?EH(Object(n),!0).forEach(function(i){bJe(e,i,n[i])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):EH(Object(n)).forEach(function(i){Object.defineProperty(e,i,Object.getOwnPropertyDescriptor(n,i))})}return e}function bJe(e,r,n){return r=_Je(r),r in e?Object.defineProperty(e,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[r]=n,e}function _Je(e){var r=wJe(e,"string");return Z2(r)=="symbol"?r:String(r)}function wJe(e,r){if(Z2(e)!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var i=n.call(e,r);if(Z2(i)!="object")return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return(r==="string"?String:Number)(e)}function SJe(e){if(e==null)throw new TypeError("Cannot destructure "+e)}var kJe=y.memo(function(e){var r=Object.assign({},(SJe(e),e));return c.jsx(pl,xJe({Icon:iP,"aria-label":M0,background:uJe,color:dJe,iconMultiple:hJe},r))});function J2(e){"@babel/helpers - typeof";return J2=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(r){return typeof r}:function(r){return r&&typeof Symbol=="function"&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r},J2(e)}var CJe=["size","style"];function AH(e,r){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);r&&(i=i.filter(function(s){return Object.getOwnPropertyDescriptor(e,s).enumerable})),n.push.apply(n,i)}return n}function fE(e){for(var r=1;r<arguments.length;r++){var n=arguments[r]!=null?arguments[r]:{};r%2?AH(Object(n),!0).forEach(function(i){jJe(e,i,n[i])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):AH(Object(n)).forEach(function(i){Object.defineProperty(e,i,Object.getOwnPropertyDescriptor(n,i))})}return e}function jJe(e,r,n){return r=NJe(r),r in e?Object.defineProperty(e,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[r]=n,e}function NJe(e){var r=TJe(e,"string");return J2(r)=="symbol"?r:String(r)}function TJe(e,r){if(J2(e)!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var i=n.call(e,r);if(J2(i)!="object")return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return(r==="string"?String:Number)(e)}function EJe(e,r){if(e==null)return{};var n=AJe(e,r),i,s;if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(s=0;s<o.length;s++)i=o[s],!(r.indexOf(i)>=0)&&Object.prototype.propertyIsEnumerable.call(e,i)&&(n[i]=e[i])}return n}function AJe(e,r){if(e==null)return{};var n={},i=Object.keys(e),s,o;for(o=0;o<i.length;o++)s=i[o],!(r.indexOf(s)>=0)&&(n[s]=e[s]);return n}var fae=y.memo(function(e){var r=e.size,n=r===void 0?"1em":r,i=e.style,s=EJe(e,CJe),o=lOe(M0),a=o.id,l=o.fill;return c.jsxs("svg",fE(fE({height:n,style:fE({flex:"none",lineHeight:1},i),viewBox:"0 0 24 24",width:n,xmlns:"http://www.w3.org/2000/svg"},s),{},{children:[c.jsx("title",{children:M0}),c.jsx("path",{d:"M12.604 1.34c.393.69.784 1.382 1.174 2.075a.18.18 0 00.157.091h5.552c.174 0 .322.11.446.327l1.454 2.57c.19.337.24.478.024.837-.26.43-.513.864-.76 1.3l-.367.658c-.106.196-.223.28-.04.512l2.652 4.637c.172.301.111.494-.043.77-.437.785-.882 1.564-1.335 2.34-.159.272-.352.375-.68.37-.777-.016-1.552-.01-2.327.016a.099.099 0 00-.081.05 575.097 575.097 0 01-2.705 4.74c-.169.293-.38.363-.725.364-.997.003-2.002.004-3.017.002a.537.537 0 01-.465-.271l-1.335-2.323a.09.09 0 00-.083-.049H4.982c-.285.03-.553-.001-.805-.092l-1.603-2.77a.543.543 0 01-.002-.54l1.207-2.12a.198.198 0 000-.197 550.951 550.951 0 01-1.875-3.272l-.79-1.395c-.16-.31-.173-.496.095-.965.465-.813.927-1.625 1.387-2.436.132-.234.304-.334.584-.335a338.3 338.3 0 012.589-.001.124.124 0 00.107-.063l2.806-4.895a.488.488 0 01.422-.246c.524-.001 1.053 0 1.583-.006L11.704 1c.341-.003.724.032.9.34zm-3.432.403a.06.06 0 00-.052.03L6.254 6.788a.157.157 0 01-.135.078H3.253c-.056 0-.07.025-.041.074l5.81 10.156c.025.042.013.062-.034.063l-2.795.015a.218.218 0 00-.2.116l-1.32 2.31c-.044.078-.021.118.068.118l5.716.008c.046 0 .08.02.104.061l1.403 2.454c.046.081.092.082.139 0l5.006-8.76.783-1.382a.055.055 0 01.096 0l1.424 2.53a.122.122 0 00.107.062l2.763-.02a.04.04 0 00.035-.02.041.041 0 000-.04l-2.9-5.086a.108.108 0 010-.113l.293-.507 1.12-1.977c.024-.041.012-.062-.035-.062H9.2c-.059 0-.073-.026-.043-.077l1.434-2.505a.107.107 0 000-.114L9.225 1.774a.06.06 0 00-.053-.031zm6.29 8.02c.046 0 .058.02.034.06l-.832 1.465-2.613 4.585a.056.056 0 01-.05.029.058.058 0 01-.05-.029L8.498 9.841c-.02-.034-.01-.052.028-.054l.216-.012 6.722-.012z",fill:l,fillRule:"nonzero"}),c.jsx("defs",{children:c.jsxs("linearGradient",{id:a,x1:"0%",x2:"100%",y1:"0%",y2:"0%",children:[c.jsx("stop",{offset:"0%",stopColor:"#6336E7",stopOpacity:".84"}),c.jsx("stop",{offset:"100%",stopColor:"#6F69F7",stopOpacity:".84"})]})})]}))});function Q2(e){"@babel/helpers - typeof";return Q2=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(r){return typeof r}:function(r){return r&&typeof Symbol=="function"&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r},Q2(e)}var OJe=["size","style"];function OH(e,r){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);r&&(i=i.filter(function(s){return Object.getOwnPropertyDescriptor(e,s).enumerable})),n.push.apply(n,i)}return n}function pE(e){for(var r=1;r<arguments.length;r++){var n=arguments[r]!=null?arguments[r]:{};r%2?OH(Object(n),!0).forEach(function(i){RJe(e,i,n[i])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):OH(Object(n)).forEach(function(i){Object.defineProperty(e,i,Object.getOwnPropertyDescriptor(n,i))})}return e}function RJe(e,r,n){return r=MJe(r),r in e?Object.defineProperty(e,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[r]=n,e}function MJe(e){var r=PJe(e,"string");return Q2(r)=="symbol"?r:String(r)}function PJe(e,r){if(Q2(e)!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var i=n.call(e,r);if(Q2(i)!="object")return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return(r==="string"?String:Number)(e)}function LJe(e,r){if(e==null)return{};var n=$Je(e,r),i,s;if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(s=0;s<o.length;s++)i=o[s],!(r.indexOf(i)>=0)&&Object.prototype.propertyIsEnumerable.call(e,i)&&(n[i]=e[i])}return n}function $Je(e,r){if(e==null)return{};var n={},i=Object.keys(e),s,o;for(o=0;o<i.length;o++)s=i[o],!(r.indexOf(s)>=0)&&(n[s]=e[s]);return n}var pae=y.memo(function(e){var r=e.size,n=r===void 0?"1em":r,i=e.style,s=LJe(e,OJe);return c.jsxs("svg",pE(pE({fill:"currentColor",fillRule:"evenodd",height:n,style:pE({flex:"none",lineHeight:1},i),viewBox:"0 0 75 24",xmlns:"http://www.w3.org/2000/svg"},s),{},{children:[c.jsx("title",{children:M0}),c.jsx("path",{d:"M11.425 14.13h3.642l1.529 1.795a7.89 7.89 0 002.166-2.832 8.36 8.36 0 00.771-3.562c0-2.03-.624-3.664-1.874-4.905-1.24-1.25-2.884-1.874-4.931-1.874-1.028 0-1.99.186-2.885.558A6.99 6.99 0 007.45 4.932 8.576 8.576 0 005.656 7.67a8.354 8.354 0 00-.625 3.19c0 2.003.611 3.643 1.834 4.919 1.223 1.276 2.779 1.914 4.666 1.914.39 0 .793-.031 1.21-.093.425-.062.868-.16 1.329-.293l-2.645-3.177zM18.07 22l-2.127-2.46c-.753.293-1.48.51-2.18.652a9.84 9.84 0 01-2.073.226c-2.97 0-5.326-.85-7.072-2.552C2.873 16.164 2 13.865 2 10.966c0-1.577.28-3.052.837-4.426a10.148 10.148 0 012.406-3.576A10.427 10.427 0 018.713.758C10.025.253 11.429 0 12.927 0c2.915 0 5.25.86 7.005 2.579 1.755 1.72 2.632 4.01 2.632 6.872 0 1.764-.354 3.399-1.063 4.905a10.156 10.156 0 01-3.031 3.776L21.714 22H18.07zm5.743-14.675h2.884l2.047 6.433.054.16c.248.789.38 1.373.399 1.755.097-.302.221-.62.372-.958.16-.345.354-.713.585-1.103l4.227-7.218 2.06 7.43c.08.275.146.559.2.851.053.293.097.63.133 1.01.132-.372.265-.708.398-1.01.142-.3.28-.562.412-.784l3.816-6.567h3.243L36.097 20.71l-2.127-7.045a8.683 8.683 0 01-.213-.798 17.846 17.846 0 01-.146-.97 69.17 69.17 0 01-.519 1.063c-.15.302-.265.514-.345.638l-4.28 7.112-4.653-13.385zm24.392 4.785h6.5c-.026-.85-.292-1.52-.797-2.007-.496-.497-1.166-.745-2.008-.745-.957 0-1.768.248-2.432.745-.665.496-1.086 1.165-1.263 2.007zm6.34 3.948l2.061 1.608c-.735.966-1.533 1.67-2.392 2.114-.86.443-1.848.665-2.965.665-1.87 0-3.38-.563-4.533-1.689-1.152-1.134-1.728-2.623-1.728-4.466 0-2.162.66-3.935 1.98-5.317 1.33-1.391 3.018-2.087 5.066-2.087 1.71 0 3.07.532 4.08 1.595 1.02 1.055 1.53 2.473 1.53 4.254 0 .15-.01.345-.027.585-.01.23-.027.51-.054.837h-9.61c0 1.143.288 2.056.864 2.738.576.674 1.342 1.01 2.3 1.01.664 0 1.293-.159 1.887-.478a4.633 4.633 0 001.542-1.369zm14.317 3.868l.957-7.244c.018-.133.031-.27.04-.412.009-.151.013-.368.013-.652 0-.824-.2-1.453-.598-1.887-.399-.444-.98-.665-1.741-.665-1.188 0-2.118.385-2.792 1.156-.673.763-1.112 1.937-1.316 3.523l-.797 6.181H59.77l1.661-12.601h2.752l-.213 1.515c.727-.664 1.476-1.156 2.247-1.475a6.5 6.5 0 012.486-.479c1.293 0 2.3.341 3.017 1.024.727.673 1.09 1.622 1.09 2.845 0 .31-.018.673-.053 1.09-.036.407-.089.886-.16 1.435l-.877 6.647h-2.858z"})]}))});function ew(e){"@babel/helpers - typeof";return ew=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(r){return typeof r}:function(r){return r&&typeof Symbol=="function"&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r},ew(e)}var DJe=["type","extraStyle"];function RH(e,r){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);r&&(i=i.filter(function(s){return Object.getOwnPropertyDescriptor(e,s).enumerable})),n.push.apply(n,i)}return n}function MH(e){for(var r=1;r<arguments.length;r++){var n=arguments[r]!=null?arguments[r]:{};r%2?RH(Object(n),!0).forEach(function(i){IJe(e,i,n[i])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):RH(Object(n)).forEach(function(i){Object.defineProperty(e,i,Object.getOwnPropertyDescriptor(n,i))})}return e}function IJe(e,r,n){return r=BJe(r),r in e?Object.defineProperty(e,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[r]=n,e}function BJe(e){var r=zJe(e,"string");return ew(r)=="symbol"?r:String(r)}function zJe(e,r){if(ew(e)!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var i=n.call(e,r);if(ew(i)!="object")return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return(r==="string"?String:Number)(e)}function FJe(e,r){if(e==null)return{};var n=HJe(e,r),i,s;if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(s=0;s<o.length;s++)i=o[s],!(r.indexOf(i)>=0)&&Object.prototype.propertyIsEnumerable.call(e,i)&&(n[i]=e[i])}return n}function HJe(e,r){if(e==null)return{};var n={},i=Object.keys(e),s,o;for(o=0;o<i.length;o++)s=i[o],!(r.indexOf(s)>=0)&&(n[s]=e[s]);return n}var WJe=y.memo(function(e){var r=e.type,n=r===void 0?"mono":r,i=e.extraStyle,s=FJe(e,DJe),o=n==="color"?fae:iP;return c.jsx(ml,MH({Icon:o,Text:pae,"aria-label":M0,extraStyle:MH({fontWeight:500},i),spaceMultiple:lJe,textMultiple:aJe},s))}),pd=iP;pd.Color=fae;pd.Text=pae;pd.Combine=WJe;pd.Avatar=kJe;pd.colorPrimary=hae;pd.colorGradient=cJe;pd.title=M0;var Ph="Meta",UJe=.75,VJe=.2,qJe="#1d65c1",mae="linear-gradient(45deg, #007FF8, #0668E1, #007FF8)",GJe=mae,KJe="#fff",YJe=.75;function tw(e){"@babel/helpers - typeof";return tw=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(r){return typeof r}:function(r){return r&&typeof Symbol=="function"&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r},tw(e)}var XJe=["size","style"];function PH(e,r){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);r&&(i=i.filter(function(s){return Object.getOwnPropertyDescriptor(e,s).enumerable})),n.push.apply(n,i)}return n}function mE(e){for(var r=1;r<arguments.length;r++){var n=arguments[r]!=null?arguments[r]:{};r%2?PH(Object(n),!0).forEach(function(i){ZJe(e,i,n[i])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):PH(Object(n)).forEach(function(i){Object.defineProperty(e,i,Object.getOwnPropertyDescriptor(n,i))})}return e}function ZJe(e,r,n){return r=JJe(r),r in e?Object.defineProperty(e,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[r]=n,e}function JJe(e){var r=QJe(e,"string");return tw(r)=="symbol"?r:String(r)}function QJe(e,r){if(tw(e)!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var i=n.call(e,r);if(tw(i)!="object")return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return(r==="string"?String:Number)(e)}function eQe(e,r){if(e==null)return{};var n=tQe(e,r),i,s;if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(s=0;s<o.length;s++)i=o[s],!(r.indexOf(i)>=0)&&Object.prototype.propertyIsEnumerable.call(e,i)&&(n[i]=e[i])}return n}function tQe(e,r){if(e==null)return{};var n={},i=Object.keys(e),s,o;for(o=0;o<i.length;o++)s=i[o],!(r.indexOf(s)>=0)&&(n[s]=e[s]);return n}var sP=y.memo(function(e){var r=e.size,n=r===void 0?"1em":r,i=e.style,s=eQe(e,XJe);return c.jsxs("svg",mE(mE({fill:"currentColor",fillRule:"evenodd",height:n,style:mE({flex:"none",lineHeight:1},i),viewBox:"0 0 24 24",width:n,xmlns:"http://www.w3.org/2000/svg"},s),{},{children:[c.jsx("title",{children:Ph}),c.jsx("path",{d:"M6.897 4c1.915 0 3.516.932 5.43 3.376l.282-.373c.19-.246.383-.484.58-.71l.313-.35C14.588 4.788 15.792 4 17.225 4c1.273 0 2.469.557 3.491 1.516l.218.213c1.73 1.765 2.917 4.71 3.053 8.026l.011.392.002.25c0 1.501-.28 2.759-.818 3.7l-.14.23-.108.153c-.301.42-.664.758-1.086 1.009l-.265.142-.087.04a3.493 3.493 0 01-.302.118 4.117 4.117 0 01-1.33.208c-.524 0-.996-.067-1.438-.215-.614-.204-1.163-.56-1.726-1.116l-.227-.235c-.753-.812-1.534-1.976-2.493-3.586l-1.43-2.41-.544-.895-1.766 3.13-.343.592C7.597 19.156 6.227 20 4.356 20c-1.21 0-2.205-.42-2.936-1.182l-.168-.184c-.484-.573-.837-1.311-1.043-2.189l-.067-.32a8.69 8.69 0 01-.136-1.288L0 14.468c.002-.745.06-1.49.174-2.23l.1-.573c.298-1.53.828-2.958 1.536-4.157l.209-.34c1.177-1.83 2.789-3.053 4.615-3.16L6.897 4zm-.033 2.615l-.201.01c-.83.083-1.606.673-2.252 1.577l-.138.199-.01.018c-.67 1.017-1.185 2.378-1.456 3.845l-.004.022a12.591 12.591 0 00-.207 2.254l.002.188c.004.18.017.36.04.54l.043.291c.092.503.257.908.486 1.208l.117.137c.303.323.698.492 1.17.492 1.1 0 1.796-.676 3.696-3.641l2.175-3.4.454-.701-.139-.198C9.11 7.3 8.084 6.616 6.864 6.616zm10.196-.552l-.176.007c-.635.048-1.223.359-1.82.933l-.196.198c-.439.462-.887 1.064-1.367 1.807l.266.398c.18.274.362.56.55.858l.293.475 1.396 2.335.695 1.114c.583.926 1.03 1.6 1.408 2.082l.213.262c.282.326.529.54.777.673l.102.05c.227.1.457.138.718.138.176.002.35-.023.518-.073.338-.104.61-.32.813-.637l.095-.163.077-.162c.194-.459.29-1.06.29-1.785l-.006-.449c-.08-2.871-.938-5.372-2.2-6.798l-.176-.189c-.67-.683-1.444-1.074-2.27-1.074z"})]}))});function rw(e){"@babel/helpers - typeof";return rw=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(r){return typeof r}:function(r){return r&&typeof Symbol=="function"&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r},rw(e)}function LH(e,r){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);r&&(i=i.filter(function(s){return Object.getOwnPropertyDescriptor(e,s).enumerable})),n.push.apply(n,i)}return n}function rQe(e){for(var r=1;r<arguments.length;r++){var n=arguments[r]!=null?arguments[r]:{};r%2?LH(Object(n),!0).forEach(function(i){nQe(e,i,n[i])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):LH(Object(n)).forEach(function(i){Object.defineProperty(e,i,Object.getOwnPropertyDescriptor(n,i))})}return e}function nQe(e,r,n){return r=iQe(r),r in e?Object.defineProperty(e,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[r]=n,e}function iQe(e){var r=sQe(e,"string");return rw(r)=="symbol"?r:String(r)}function sQe(e,r){if(rw(e)!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var i=n.call(e,r);if(rw(i)!="object")return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return(r==="string"?String:Number)(e)}function oQe(e){if(e==null)throw new TypeError("Cannot destructure "+e)}var aQe=y.memo(function(e){var r=Object.assign({},(oQe(e),e));return c.jsx(pl,rQe({Icon:sP,"aria-label":Ph,background:GJe,color:KJe,iconMultiple:YJe},r))});function nw(e){"@babel/helpers - typeof";return nw=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(r){return typeof r}:function(r){return r&&typeof Symbol=="function"&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r},nw(e)}var lQe=["size","style"];function $H(e,r){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);r&&(i=i.filter(function(s){return Object.getOwnPropertyDescriptor(e,s).enumerable})),n.push.apply(n,i)}return n}function gE(e){for(var r=1;r<arguments.length;r++){var n=arguments[r]!=null?arguments[r]:{};r%2?$H(Object(n),!0).forEach(function(i){cQe(e,i,n[i])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):$H(Object(n)).forEach(function(i){Object.defineProperty(e,i,Object.getOwnPropertyDescriptor(n,i))})}return e}function cQe(e,r,n){return r=uQe(r),r in e?Object.defineProperty(e,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[r]=n,e}function uQe(e){var r=dQe(e,"string");return nw(r)=="symbol"?r:String(r)}function dQe(e,r){if(nw(e)!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var i=n.call(e,r);if(nw(i)!="object")return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return(r==="string"?String:Number)(e)}function hQe(e,r){return gQe(e)||mQe(e,r)||pQe(e,r)||fQe()}function fQe(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
@@ -1265,7 +1265,7 @@ WARNING: This link could potentially be dangerous`)){let n=window.open();if(n){t
|
|
|
1265
1265
|
`);Er=Lt.pop()||"";for(const Un of Lt)if(Un.startsWith("data: "))try{const dt=JSON.parse(Un.slice(6));if(lE(String(dt.type??"unknown"),Un.slice(6)),dt.type==="thinking")$t||($t=Date.now()),Se+=dt.content,Lr({thinking:Se});else if(dt.type==="token")$t&&!Et&&(Et=Math.round((Date.now()-$t)/1e3)),jt+=dt.content,$r(dt.content),Lr({content:jt,thinkingDuration:Et,segments:[...mr]});else if(dt.type==="tool_call_delta"){const ur=dt.call_id,jn=dt.name_delta||"",Or=dt.args_delta||"",Gt=yt.findIndex(ar=>ar.callId===ur);Gt!==-1?yt[Gt]={...yt[Gt],tool:yt[Gt].tool+jn,streamingArgs:(yt[Gt].streamingArgs??"")+Or}:(yt.push({callId:ur,parentCallId:dt.parent_call_id,tool:jn,args:{},status:"pending",streamingArgs:Or,startedAt:Date.now()}),it(ur)),Lr({toolCalls:[...yt],segments:[...mr]},{immediate:!0})}else if(dt.type==="tool_start"){const ur=dt.call_id,jn=yt.findIndex(Or=>Or.callId===ur);jn!==-1?yt[jn]={...yt[jn],tool:dt.tool,args:dt.args??{},parentCallId:dt.parent_call_id,status:"running",streamingArgs:void 0}:(yt.push({callId:ur,parentCallId:dt.parent_call_id,tool:dt.tool,args:dt.args??{},status:"running",startedAt:Date.now()}),it(ur)),Lr({toolCalls:[...yt],segments:[...mr]},{immediate:!0})}else if(dt.type==="tool_output"){const ur=yt.findIndex(jn=>jn.callId===dt.call_id);ur!==-1&&(yt[ur]={...yt[ur],streamingOutput:(yt[ur].streamingOutput??"")+dt.content},Lr({toolCalls:[...yt]},{immediate:!0}))}else if(dt.type==="tool_result"){const ur=yt.findIndex(jn=>jn.callId===dt.call_id);if(ur!==-1&&(yt[ur]={...yt[ur],parentCallId:yt[ur].parentCallId??dt.parent_call_id,status:dt.ok?"success":"error",result:{ok:dt.ok,message:dt.message,data:dt.data},completedAt:Date.now()},Lr({toolCalls:[...yt]},{immediate:!0}),dt.ok)){const jn=yt[ur],Or=jn.tool.replace("_",".");if(Or==="file.write"||Or==="file.patch"||Or==="edit"){const Gt=dt.data&&typeof dt.data=="object"?dt.data:void 0,ar=NO(Or,jn.args??{},Gt,dt.message)??"";if(ar){const Do=ar.split("/").pop()??ar;p(or=>or.some(xe=>xe.path===ar)?or:[...or,{path:ar,name:Do,state:"undecided"}])}}}}else if(dt.type==="plan_complete"){const ur={plan_id:dt.plan_id,summary:dt.summary,actions:dt.actions??[]};l(ur)}else if(dt.type==="mode_notice"){const ur=`
|
|
1266
1266
|
|
|
1267
1267
|
*${dt.message}*`;jt+=ur,$r(ur),Lr({content:jt,segments:[...mr]})}else if(dt.type==="todo_list"){const ur=dt.items;u(ur)}else if(dt.type==="context_usage")w(dt);else if(dt.type==="context_flow")Lr({contextFlow:{provider:String(dt.provider??"jait"),model:typeof dt.model=="string"?dt.model:void 0,rounds:Array.isArray(dt.rounds)?dt.rounds:[]}},{immediate:!0});else if(dt.type==="provider_fallback")j({provider:"jait",workspacePath:"",isRemote:!1});else if(dt.type==="session_info")j({provider:dt.provider,workspacePath:dt.workspacePath,isRemote:dt.isRemote,remoteNode:dt.remoteNode});else if(dt.type==="file_changed"){const ur=dt.path,jn=dt.name;p(Or=>Or.find(ar=>ar.path===ur)?Or:[...Or,{path:ur,name:jn,state:"undecided"}])}else if(dt.type==="done"){if(pn=!0,Rt(),$t&&!Et&&(Et=Math.round((Date.now()-$t)/1e3)),!$e()){const ur=jt.length===0&&Se.length===0&&yt.length===0;o(jn=>({...jn,promptCount:dt.prompt_count,remainingPrompts:dt.remaining_prompts,isLoading:!1,hitMaxRounds:!!dt.hit_max_rounds,messages:ur?jn.messages.filter(Or=>Or.id!==Ot):jn.messages.map(Or=>Or.id===Ot?{...Or,content:jt,thinking:Se||void 0,thinkingDuration:Et,toolCalls:yt.length>0?yt:void 0,segments:mr.length>0?mr:void 0}:Or)}))}return N.current===Re&&(N.current=null),R.current===Je&&(R.current=null),_(ur=>ur+1),"sent"}else if(dt.type==="error")throw new Error(dt.message)}catch(dt){if(!(dt instanceof SyntaxError))throw dt}}if(Rt(),!pn&&!$e()){$t&&!Et&&(Et=Math.round((Date.now()-$t)/1e3));const ft=jt.length===0&&Se.length===0&&yt.length===0;o(fr=>({...fr,isLoading:!1,messages:ft?fr.messages.filter(Lt=>Lt.id!==Ot):fr.messages.map(Lt=>Lt.id===Ot?{...Lt,content:jt,thinking:Se||void 0,thinkingDuration:Et,toolCalls:yt.length>0?yt:void 0,segments:mr.length>0?mr:void 0}:Lt)})),_(fr=>fr+1)}}catch(ot){if(gt!==null&&(window.cancelAnimationFrame(gt),gt=null),ct=null,ot instanceof Error&&ot.name==="AbortError")return N.current===Re&&(N.current=null),R.current===Je&&(R.current=null),$e()||o(Yt=>({...Yt,isLoading:!1,messages:Yt.messages.filter(tt=>Oe.queued?tt.id!==Ot&&tt.id!==be.id:!(tt.id===Ot&&!tt.content&&!tt.thinking&&(!tt.toolCalls||tt.toolCalls.length===0))).map(tt=>{var Ge;return(Ge=tt.toolCalls)!=null&&Ge.some(It=>It.status==="running")?{...tt,toolCalls:tt.toolCalls.map(It=>It.status==="running"?{...It,status:"error",result:{ok:!1,message:"Cancelled"},completedAt:Date.now()}:It)}:tt})})),"aborted";if(N.current===Re&&(N.current=null),R.current===Je&&(R.current=null),!$e()){const Yt=NV(ot);o(tt=>({...tt,isLoading:!1,error:Yt?z7:ot instanceof Error?ot.message:"An error occurred",messages:tt.messages.filter(Ge=>Oe.queued?Ge.id!==Ot&&Ge.id!==be.id:!(Ge.id===Ot&&!Ge.content&&!Ge.thinking&&(!Ge.toolCalls||Ge.toolCalls.length===0)))})),Yt&&Je&&window.setTimeout(()=>{A.current===Je&&K()},250)}return"retry"}return N.current===Re&&(N.current=null),R.current===Je&&(R.current=null),"sent"},[r,n,e]),P=y.useCallback(Ie=>{const Oe={id:`q-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,...Ie,queuedAt:Date.now()};v(qe=>[...qe,Oe])},[]),F=y.useCallback(Ie=>{v(Oe=>Oe.filter(qe=>qe.id!==Ie))},[]),V=y.useCallback((Ie,Oe)=>{const qe=Oe.trim();qe&&v(kt=>kt.map(vt=>vt.id===Ie?{...vt,content:qe,displayContent:qe,referencedFiles:void 0,displaySegments:void 0}:vt))},[]),Y=y.useCallback((Ie,Oe,qe)=>{v(kt=>{const vt=kt.findIndex(Ot=>Ot.id===Ie);if(vt<0)return kt;const Me=[...kt],[nt]=Me.splice(vt,1);if(!nt)return kt;if(Oe==null)return Me.push(nt),Me;const Je=Me.findIndex(Ot=>Ot.id===Oe);return Je<0?kt:(Me.splice(Je+(qe==="after"?1:0),0,nt),Me)})},[]),H=y.useCallback(Ie=>{v(Ie)},[]);y.useEffect(()=>{const Ie=()=>{TV({sessionId:e,isLoading:s.isLoading,isLoadingHistory:s.isLoadingHistory,messageCount:s.messages.length,error:s.error})&&(R.current===e&&N.current||K())},Oe=()=>{document.hidden||Ie()};return document.addEventListener("visibilitychange",Oe),()=>document.removeEventListener("visibilitychange",Oe)},[s.error,s.isLoading,s.isLoadingHistory,K,e,s.messages.length]),y.useEffect(()=>{if(typeof window>"u")return;const Ie=()=>{TV({sessionId:e,isLoading:s.isLoading,isLoadingHistory:s.isLoadingHistory,messageCount:s.messages.length,error:s.error})&&(R.current===e&&N.current||K())},Oe=()=>{Ie()};return window.addEventListener("focus",Oe),window.addEventListener("pageshow",Oe),window.addEventListener("online",Oe),()=>{window.removeEventListener("focus",Oe),window.removeEventListener("pageshow",Oe),window.removeEventListener("online",Oe)}},[s.isLoading,s.isLoadingHistory,s.messages.length,K,e]);const U=y.useRef(null),Q=y.useCallback(Ie=>{U.current=Ie},[]),q=y.useCallback(Ie=>{p(Oe=>{var kt;const qe=Ie(Oe);return(kt=U.current)==null||kt.call(U,qe),qe})},[]),ee=y.useCallback(async Ie=>{q(Oe=>Oe.map(qe=>qe.path===Ie?{...qe,state:"accepted"}:qe));try{const Oe={"Content-Type":"application/json"};r&&(Oe.Authorization=`Bearer ${r}`),await fetch(`${Zu}/api/workspace/apply-diff`,{method:"POST",headers:Oe,body:JSON.stringify({path:Ie,content:null,...i?{surfaceId:i}:{}})})}catch{}},[r,q,i]),te=y.useCallback(async Ie=>{let Oe=!1;try{const qe={"Content-Type":"application/json"};r&&(qe.Authorization=`Bearer ${r}`),Oe=(await fetch(`${Zu}/api/workspace/undo`,{method:"POST",headers:qe,body:JSON.stringify({path:Ie,...i?{surfaceId:i}:{}})})).ok}catch{Oe=!1}Oe&&q(qe=>qe.map(kt=>kt.path===Ie?{...kt,state:"rejected"}:kt))},[r,q,i]),ue=y.useCallback(()=>{q(Ie=>Ie.map(Oe=>Oe.state==="undecided"?{...Oe,state:"accepted"}:Oe))},[q]),fe=y.useCallback(async()=>{const Ie=f.filter(Oe=>Oe.state==="undecided").map(Oe=>Oe.path);if(Ie.length>0){let Oe=new Set;try{const qe={"Content-Type":"application/json"};r&&(qe.Authorization=`Bearer ${r}`);const kt=await fetch(`${Zu}/api/workspace/undo-all`,{method:"POST",headers:qe,body:JSON.stringify({paths:Ie,...i?{surfaceId:i}:{}})});if(kt.ok){const vt=await kt.json();Oe=new Set((vt.results??[]).filter(Me=>Me.restored).map(Me=>Me.path))}}catch{}if(Oe.size===0)return;q(qe=>qe.map(kt=>kt.state==="undecided"&&Oe.has(kt.path)?{...kt,state:"rejected"}:kt));return}},[r,f,q,i]);y.useEffect(()=>{if(f.length===0||!f.every(qe=>qe.state!=="undecided"))return;const Oe=setTimeout(()=>q(()=>[]),1200);return()=>clearTimeout(Oe)},[f,q]);const re=y.useCallback(()=>{var Oe,qe;L.current+=1;const Ie=A.current;Ie&&fetch(`${Zu}/api/sessions/${Ie}/cancel`,{method:"POST",headers:d8(r)}).catch(()=>{}),(Oe=N.current)==null||Oe.abort(),N.current=null,R.current=null,(qe=E.current)==null||qe.abort(),E.current=null,o(kt=>({...kt,isLoading:!1,messages:kt.messages.map(vt=>{var Me;return(Me=vt.toolCalls)!=null&&Me.some(nt=>nt.status==="running")?{...vt,toolCalls:vt.toolCalls.map(nt=>nt.status==="running"?{...nt,status:"error",result:{ok:!1,message:"Cancelled"},completedAt:Date.now()}:nt)}:vt})}))},[r]),ie=y.useCallback(()=>{o({messages:[],isLoading:!1,isLoadingHistory:!1,promptCount:0,remainingPrompts:null,error:null,hitMaxRounds:!1}),u([]),q(()=>[]),v([])},[q]),ge=y.useCallback((Ie={})=>(o(Oe=>({...Oe,hitMaxRounds:!1})),I("Continue from where you left off.",Ie)),[I]),le=y.useCallback(async(Ie,Oe,qe,kt,vt={})=>{var ke,$e;const{token:Me,sessionId:nt,onLoginRequired:Je}=vt,Ot=Me??r,be=Je??n,Re=nt??e;if(!(!Re||!Oe.trim()||z.current)){z.current=!0;try{const ct={"Content-Type":"application/json"};Ot&&(ct.Authorization=`Bearer ${Ot}`);const gt=()=>fetch(`${Zu}/api/sessions/${Re}/restart-from`,{method:"POST",headers:ct,body:JSON.stringify({messageId:Ie,messageIndex:qe,messageFromEnd:kt})}),at=Ye=>new Promise(Pt=>window.setTimeout(Pt,Ye)),ut=async()=>{for(let Ye=0;Ye<32;Ye+=1){const Pt=await fetch(`${Zu}/api/sessions/${Re}/messages?limit=1`,{headers:ct}).catch(()=>null);if(Pt!=null&&Pt.ok&&!(await Pt.json().catch(()=>({}))).streaming)return!0;await at(250)}return!1};L.current+=1,(ke=N.current)==null||ke.abort(),($e=E.current)==null||$e.abort(),E.current=null,await fetch(`${Zu}/api/sessions/${Re}/cancel`,{method:"POST",headers:d8(Ot)}).catch(()=>null),await ut();let Ht=await gt();if(Ht.status===409&&(await ut(),Ht=await gt()),Ht.status===401){(await Ht.json().catch(()=>({}))).detail==="login_required"&&(be==null||be());return}if(!Ht.ok){const Ye=await Ht.text().catch(()=>"");throw new Error(Ye||`HTTP ${Ht.status}`)}const Fe=await Ht.json();o(Ye=>({...Ye,messages:Fe.messages??[],isLoading:!1,error:null})),await I(Oe.trim(),{token:Ot,sessionId:Re,mode:vt.mode,provider:vt.provider,model:vt.model,displayContent:vt.displayContent??Oe.trim(),referencedFiles:vt.referencedFiles,displaySegments:vt.displaySegments,onLoginRequired:be})}catch(ct){o(gt=>({...gt,isLoading:!1,error:ct instanceof Error?ct.message:"Failed to restart from message"}))}finally{z.current=!1}}},[r,n,e,I]),et=y.useCallback(async Ie=>{var kt;const Oe=A.current;if(!Oe||!a)return;const qe={"Content-Type":"application/json"};r&&(qe.Authorization=`Bearer ${r}`);try{const vt=await fetch(`${Zu}/api/sessions/${Oe}/plan/execute`,{method:"POST",headers:qe,body:JSON.stringify(Ie?{action_ids:Ie}:{})});if(!vt.ok)throw new Error(`HTTP ${vt.status}`);const Me=(kt=vt.body)==null?void 0:kt.getReader();if(!Me)throw new Error("No response body");const nt=new TextDecoder;let Je="";for(;;){const{done:Ot,value:be}=await Me.read();if(Ot)break;Je+=nt.decode(be,{stream:!0});const Re=Je.split(`
|
|
1268
|
-
`);Je=Re.pop()||"";for(const ke of Re)if(ke.startsWith("data: "))try{const $e=JSON.parse(ke.slice(6));$e.type==="plan_action_start"?l(ct=>ct?{...ct,actions:ct.actions.map(gt=>gt.id===$e.action_id?{...gt,status:"approved"}:gt)}:null):$e.type==="plan_action_result"?l(ct=>ct?{...ct,actions:ct.actions.map(gt=>gt.id===$e.action_id?{...gt,status:$e.ok?"executed":"failed",result:{ok:$e.ok,message:$e.message,data:$e.data}}:gt)}:null):$e.type==="plan_execution_complete"&&setTimeout(()=>l(null),2e3)}catch{}}}catch(vt){o(Me=>({...Me,error:vt instanceof Error?vt.message:"Plan execution failed"}))}},[r,a]),Xe=y.useCallback(async()=>{const Ie=A.current;if(!Ie||!a)return;const Oe={"Content-Type":"application/json"};r&&(Oe.Authorization=`Bearer ${r}`);try{await fetch(`${Zu}/api/sessions/${Ie}/plan/reject`,{method:"POST",headers:Oe}),l(null)}catch{l(null)}},[r,a]),De=y.useCallback((Ie,Oe)=>{p(qe=>qe.some(kt=>kt.path===Ie)?qe:[...qe,{path:Ie,name:Oe,state:"undecided"}])},[]),de=!!(e&&e!==A.current),Qe=s.isLoadingHistory||de;return{messages:de?[]:s.messages,isLoading:s.isLoading,isLoadingHistory:Qe,remainingPrompts:s.remainingPrompts,error:s.error,hitMaxRounds:s.hitMaxRounds,pendingPlan:a,todoList:d,changedFiles:f,messageQueue:g,completionCount:b,contextUsage:k,sessionInfo:C,sendMessage:I,restartFromMessage:le,cancelRequest:re,clearMessages:ie,continueChat:ge,executePlan:et,rejectPlan:Xe,enqueueMessage:P,dequeueMessage:F,updateQueueItem:V,reorderQueueItem:Y,setMessageQueueState:H,acceptFile:ee,rejectFile:te,acceptAllFiles:ue,rejectAllFiles:fe,setTodoList:u,addChangedFile:De,setChangedFiles:p,setOnChangedFilesSync:Q,refreshMessages:M}}function rpt(){const[e,r]=y.useState(null),[n,i]=y.useState(null),[s,o]=y.useState(null),[a,l]=y.useState(!0);return y.useEffect(()=>{let d=!1;return fetch(`${$n()}/health`).then(u=>u.json()).then(u=>{d||(r(u.provider??null),i(u.model??null),o(u.ollamaUrl??null))}).catch(()=>{}).finally(()=>{d||l(!1)}),()=>{d=!0}},[]),{provider:e,model:n,ollamaUrl:s,loading:a}}const rl=$n(),Hk=10;function Dl(e){return e?{Authorization:`Bearer ${e}`}:{}}function npt(e,r){const[n,i]=y.useState([]),[s,o]=y.useState([]),[a,l]=y.useState({}),[d,u]=y.useState(null),[f,p]=y.useState(null),[g,v]=y.useState(Hk),[b,_]=y.useState(!1),[k,w]=y.useState(!0),C=y.useMemo(()=>n.find(Y=>Y.id===d)??null,[n,d]),j=y.useCallback(async()=>{if(!e){i([]),o([]),l({}),u(null),p(null),_(!1);return}w(!0);try{const[Y,H,U]=await Promise.all([fetch(`${rl}/api/workspaces?status=active&limit=${g}`,{headers:Dl(e)}),fetch(`${rl}/api/sessions?status=active&limit=100`,{headers:Dl(e)}),fetch(`${rl}/api/workspaces/last-active`,{headers:Dl(e)})]);(Y.status===401||H.status===401||U.status===401)&&(r==null||r());let Q=[],q=[];if(Y.ok){const ee=await Y.json();Q=ee.workspaces,i(Q),l(te=>Object.fromEntries(Object.entries(te).filter(([ue])=>Q.some(fe=>fe.id===ue)))),_(!!ee.hasMore)}if(H.ok&&(q=(await H.json()).sessions.filter(te=>!te.workspaceId),o(q)),U.ok){const ee=await U.json();u(te=>{var ue,fe;return te&&Q.some(re=>re.id===te)?te:ee.session&&!ee.session.workspaceId?null:((ue=ee.workspace)==null?void 0:ue.id)??((fe=Q[0])==null?void 0:fe.id)??null}),p(te=>{var ue,fe,re,ie;return te&&Q.some(ge=>ge.sessions.some(le=>le.id===te))||te&&q.some(ge=>ge.id===te)?te:((ue=ee.session)==null?void 0:ue.id)??((fe=q[0])==null?void 0:fe.id)??((ie=(re=Q[0])==null?void 0:re.sessions[0])==null?void 0:ie.id)??null})}}catch(Y){console.error("Failed to fetch workspaces:",Y)}finally{w(!1)}},[r,e,g]),N=y.useCallback(async(Y={})=>{if(!e)return r==null||r(),null;try{const H=await fetch(`${rl}/api/workspaces`,{method:"POST",headers:{...Dl(e),"Content-Type":"application/json"},body:JSON.stringify({title:Y.title,rootPath:Y.rootPath,nodeId:Y.nodeId})});if(H.status===401)return r==null||r(),null;if(!H.ok)return null;const U=await H.json();let Q;return i(q=>{const ee=q.find(ue=>ue.id===U.id);Q={...U,sessions:U.sessions??(ee==null?void 0:ee.sessions)??[]};const te=q.filter(ue=>ue.id!==Q.id);return[Q,...te].slice(0,g)}),u(Q.id),p(null),Q}catch(H){return console.error("Failed to create workspace:",H),null}},[r,e,g]),A=y.useCallback(async(Y,H)=>{if(!e)return r==null||r(),null;const U=Y===void 0?d:Y;try{const Q=U?`${rl}/api/workspaces/${U}/sessions`:`${rl}/api/sessions`,q=await fetch(Q,{method:"POST",headers:{...Dl(e),"Content-Type":"application/json"},body:JSON.stringify({name:H})});if(q.status===401)return r==null||r(),null;if(!q.ok)return null;const ee=await q.json();return U?i(te=>te.map(ue=>ue.id===U?{...ue,lastActiveAt:ee.lastActiveAt,sessions:[ee,...ue.sessions]}:ue)):o(te=>[ee,...te.filter(ue=>ue.id!==ee.id)]),u(U??null),p(ee.id),ee}catch(Q){return console.error("Failed to create session:",Q),null}},[d,r,e]),E=y.useCallback((Y,H)=>{e&&fetch(`${rl}/api/workspaces/select`,{method:"POST",headers:{...Dl(e),"Content-Type":"application/json"},body:JSON.stringify({workspaceId:Y,sessionId:H})}).catch(()=>{})},[e]),R=y.useCallback(Y=>{u(Y),p(H=>{var q;const U=n.find(ee=>ee.id===Y);if(!U)return null;if(H&&U.sessions.some(ee=>ee.id===H))return H;const Q=((q=U.sessions[0])==null?void 0:q.id)??null;return E(Y,Q??H),Q})},[E,n]),L=y.useCallback((Y,H)=>{u(Y),p(H),E(Y,H)},[E]),z=y.useCallback(async Y=>{if(!e){r==null||r();return}try{if((await fetch(`${rl}/api/sessions/${Y}/archive`,{method:"POST",headers:Dl(e)})).status===401){r==null||r();return}await j()}catch(H){console.error("Failed to archive session:",H)}},[j,r,e]),$=y.useCallback(async Y=>{if(!e)return r==null||r(),[];try{const H=await fetch(`${rl}/api/workspaces/${Y}/sessions?status=archived`,{headers:Dl(e)});if(H.status===401)return r==null||r(),[];if(!H.ok)return[];const U=await H.json();return l(Q=>({...Q,[Y]:U.sessions})),U.sessions}catch(H){return console.error("Failed to fetch archived sessions:",H),[]}},[r,e]),W=y.useCallback(async(Y,H)=>{if(!e)return r==null||r(),null;try{const U=await fetch(`${rl}/api/workspaces/${Y}`,{method:"PATCH",headers:{...Dl(e),"Content-Type":"application/json"},body:JSON.stringify(H)});if(U.status===401)return r==null||r(),null;if(!U.ok)return null;const Q=await U.json(),q={...Q,sessions:Q.sessions??[]};return i(ee=>ee.map(te=>te.id===Y?{...te,...q}:te)),q}catch(U){return console.error("Failed to update workspace:",U),null}},[r,e]),B=y.useCallback(async Y=>{var H,U,Q;if(!e)return r==null||r(),!1;try{const q=await fetch(`${rl}/api/workspaces/${Y}`,{method:"DELETE",headers:Dl(e)});if(q.status===401)return r==null||r(),!1;if(!q.ok)return!1;const ee=n.filter(te=>te.id!==Y);return i(ee),d===Y&&(u(((H=ee[0])==null?void 0:H.id)??null),p(((Q=(U=ee[0])==null?void 0:U.sessions[0])==null?void 0:Q.id)??null)),l(te=>{const ue={...te};return delete ue[Y],ue}),!0}catch(q){return console.error("Failed to archive workspace:",q),!1}},[d,r,e,n]),K=y.useCallback(async()=>{if(!e)return r==null||r(),0;try{const Y=await fetch(`${rl}/api/workspaces/archived`,{method:"DELETE",headers:Dl(e)});return Y.status===401?(r==null||r(),0):Y.ok?(await Y.json()).removed:0}catch(Y){return console.error("Failed to clear archived workspaces:",Y),0}},[r,e]),M=y.useCallback(async()=>{if(!e)return[];try{const Y=await fetch(`${rl}/api/workspaces/archived`,{headers:Dl(e)});return Y.ok?(await Y.json()).workspaces:[]}catch{return[]}},[e]),I=y.useCallback(async Y=>{if(!e)return r==null||r(),!1;try{const H=await fetch(`${rl}/api/workspaces/${Y}/restore`,{method:"POST",headers:Dl(e)});if(H.status===401)return r==null||r(),!1;if(!H.ok)return!1;const U=await H.json();return i(Q=>Q.some(q=>q.id===U.id)?Q:[{...U,sessions:U.sessions??[]},...Q]),!0}catch(H){return console.error("Failed to restore workspace:",H),!1}},[r,e]),P=y.useCallback(async(Y,H)=>{if(!e)return r==null||r(),null;try{const U=await fetch(`${rl}/api/sessions/${Y}`,{method:"PATCH",headers:{...Dl(e),"Content-Type":"application/json"},body:JSON.stringify({name:H})});if(U.status===401)return r==null||r(),null;if(!U.ok)return null;const Q=await U.json();return i(q=>q.map(ee=>({...ee,sessions:ee.sessions.map(te=>te.id===Y?{...te,name:Q.name}:te)}))),o(q=>q.map(ee=>ee.id===Y?{...ee,name:Q.name}:ee)),l(q=>Object.fromEntries(Object.entries(q).map(([ee,te])=>[ee,te.map(ue=>ue.id===Y?{...ue,name:Q.name}:ue)]))),Q}catch(U){return console.error("Failed to rename session:",U),null}},[r,e]),F=y.useCallback(()=>{v(Y=>Y+Hk)},[]),V=y.useCallback(()=>{v(Hk)},[]);return y.useEffect(()=>{j()},[j]),{workspaces:n,personalSessions:s,archivedSessionsByWorkspace:a,activeWorkspace:C,activeWorkspaceId:d,activeSessionId:f,loading:k,hasMoreWorkspaces:b,fetchWorkspaces:j,createWorkspace:N,updateWorkspace:W,createSession:A,switchWorkspace:R,switchSession:L,archiveSession:z,fetchArchivedSessions:$,removeWorkspace:B,clearArchivedWorkspaces:K,fetchArchivedWorkspaces:M,restoreWorkspace:I,renameSession:P,showMoreWorkspaces:F,showFewerWorkspaces:V,workspaceListLimit:Hk}}const ipt=["terminal","browser","screen-share","screen-capture","voice","file-system","os-control","clipboard","notification"],spt=1,Wk={status:"disconnected",micActive:!1,assistantSpeaking:!1,userTranscript:"",assistantTranscript:""};var Qn;(function(e){e.assertEqual=s=>{};function r(s){}e.assertIs=r;function n(s){throw new Error}e.assertNever=n,e.arrayToEnum=s=>{const o={};for(const a of s)o[a]=a;return o},e.getValidEnumValues=s=>{const o=e.objectKeys(s).filter(l=>typeof s[s[l]]!="number"),a={};for(const l of o)a[l]=s[l];return e.objectValues(a)},e.objectValues=s=>e.objectKeys(s).map(function(o){return s[o]}),e.objectKeys=typeof Object.keys=="function"?s=>Object.keys(s):s=>{const o=[];for(const a in s)Object.prototype.hasOwnProperty.call(s,a)&&o.push(a);return o},e.find=(s,o)=>{for(const a of s)if(o(a))return a},e.isInteger=typeof Number.isInteger=="function"?s=>Number.isInteger(s):s=>typeof s=="number"&&Number.isFinite(s)&&Math.floor(s)===s;function i(s,o=" | "){return s.map(a=>typeof a=="string"?`'${a}'`:a).join(o)}e.joinValues=i,e.jsonStringifyReplacer=(s,o)=>typeof o=="bigint"?o.toString():o})(Qn||(Qn={}));var AV;(function(e){e.mergeShapes=(r,n)=>({...r,...n})})(AV||(AV={}));const kr=Qn.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),_m=e=>{switch(typeof e){case"undefined":return kr.undefined;case"string":return kr.string;case"number":return Number.isNaN(e)?kr.nan:kr.number;case"boolean":return kr.boolean;case"function":return kr.function;case"bigint":return kr.bigint;case"symbol":return kr.symbol;case"object":return Array.isArray(e)?kr.array:e===null?kr.null:e.then&&typeof e.then=="function"&&e.catch&&typeof e.catch=="function"?kr.promise:typeof Map<"u"&&e instanceof Map?kr.map:typeof Set<"u"&&e instanceof Set?kr.set:typeof Date<"u"&&e instanceof Date?kr.date:kr.object;default:return kr.unknown}},Vt=Qn.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]);class Xf extends Error{get errors(){return this.issues}constructor(r){super(),this.issues=[],this.addIssue=i=>{this.issues=[...this.issues,i]},this.addIssues=(i=[])=>{this.issues=[...this.issues,...i]};const n=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,n):this.__proto__=n,this.name="ZodError",this.issues=r}format(r){const n=r||function(o){return o.message},i={_errors:[]},s=o=>{for(const a of o.issues)if(a.code==="invalid_union")a.unionErrors.map(s);else if(a.code==="invalid_return_type")s(a.returnTypeError);else if(a.code==="invalid_arguments")s(a.argumentsError);else if(a.path.length===0)i._errors.push(n(a));else{let l=i,d=0;for(;d<a.path.length;){const u=a.path[d];d===a.path.length-1?(l[u]=l[u]||{_errors:[]},l[u]._errors.push(n(a))):l[u]=l[u]||{_errors:[]},l=l[u],d++}}};return s(this),i}static assert(r){if(!(r instanceof Xf))throw new Error(`Not a ZodError: ${r}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,Qn.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(r=n=>n.message){const n={},i=[];for(const s of this.issues)if(s.path.length>0){const o=s.path[0];n[o]=n[o]||[],n[o].push(r(s))}else i.push(r(s));return{formErrors:i,fieldErrors:n}}get formErrors(){return this.flatten()}}Xf.create=e=>new Xf(e);const F7=(e,r)=>{let n;switch(e.code){case Vt.invalid_type:e.received===kr.undefined?n="Required":n=`Expected ${e.expected}, received ${e.received}`;break;case Vt.invalid_literal:n=`Invalid literal value, expected ${JSON.stringify(e.expected,Qn.jsonStringifyReplacer)}`;break;case Vt.unrecognized_keys:n=`Unrecognized key(s) in object: ${Qn.joinValues(e.keys,", ")}`;break;case Vt.invalid_union:n="Invalid input";break;case Vt.invalid_union_discriminator:n=`Invalid discriminator value. Expected ${Qn.joinValues(e.options)}`;break;case Vt.invalid_enum_value:n=`Invalid enum value. Expected ${Qn.joinValues(e.options)}, received '${e.received}'`;break;case Vt.invalid_arguments:n="Invalid function arguments";break;case Vt.invalid_return_type:n="Invalid function return type";break;case Vt.invalid_date:n="Invalid date";break;case Vt.invalid_string:typeof e.validation=="object"?"includes"in e.validation?(n=`Invalid input: must include "${e.validation.includes}"`,typeof e.validation.position=="number"&&(n=`${n} at one or more positions greater than or equal to ${e.validation.position}`)):"startsWith"in e.validation?n=`Invalid input: must start with "${e.validation.startsWith}"`:"endsWith"in e.validation?n=`Invalid input: must end with "${e.validation.endsWith}"`:Qn.assertNever(e.validation):e.validation!=="regex"?n=`Invalid ${e.validation}`:n="Invalid";break;case Vt.too_small:e.type==="array"?n=`Array must contain ${e.exact?"exactly":e.inclusive?"at least":"more than"} ${e.minimum} element(s)`:e.type==="string"?n=`String must contain ${e.exact?"exactly":e.inclusive?"at least":"over"} ${e.minimum} character(s)`:e.type==="number"?n=`Number must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${e.minimum}`:e.type==="bigint"?n=`Number must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${e.minimum}`:e.type==="date"?n=`Date must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(e.minimum))}`:n="Invalid input";break;case Vt.too_big:e.type==="array"?n=`Array must contain ${e.exact?"exactly":e.inclusive?"at most":"less than"} ${e.maximum} element(s)`:e.type==="string"?n=`String must contain ${e.exact?"exactly":e.inclusive?"at most":"under"} ${e.maximum} character(s)`:e.type==="number"?n=`Number must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`:e.type==="bigint"?n=`BigInt must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`:e.type==="date"?n=`Date must be ${e.exact?"exactly":e.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(e.maximum))}`:n="Invalid input";break;case Vt.custom:n="Invalid input";break;case Vt.invalid_intersection_types:n="Intersection results could not be merged";break;case Vt.not_multiple_of:n=`Number must be a multiple of ${e.multipleOf}`;break;case Vt.not_finite:n="Number must be finite";break;default:n=r.defaultError,Qn.assertNever(e)}return{message:n}};let opt=F7;function apt(){return opt}const lpt=e=>{const{data:r,path:n,errorMaps:i,issueData:s}=e,o=[...n,...s.path||[]],a={...s,path:o};if(s.message!==void 0)return{...s,path:o,message:s.message};let l="";const d=i.filter(u=>!!u).slice().reverse();for(const u of d)l=u(a,{data:r,defaultError:l}).message;return{...s,path:o,message:l}};function dr(e,r){const n=apt(),i=lpt({issueData:r,data:e.data,path:e.path,errorMaps:[e.common.contextualErrorMap,e.schemaErrorMap,n,n===F7?void 0:F7].filter(s=>!!s)});e.common.issues.push(i)}class Oc{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(r,n){const i=[];for(const s of n){if(s.status==="aborted")return an;s.status==="dirty"&&r.dirty(),i.push(s.value)}return{status:r.value,value:i}}static async mergeObjectAsync(r,n){const i=[];for(const s of n){const o=await s.key,a=await s.value;i.push({key:o,value:a})}return Oc.mergeObjectSync(r,i)}static mergeObjectSync(r,n){const i={};for(const s of n){const{key:o,value:a}=s;if(o.status==="aborted"||a.status==="aborted")return an;o.status==="dirty"&&r.dirty(),a.status==="dirty"&&r.dirty(),o.value!=="__proto__"&&(typeof a.value<"u"||s.alwaysSet)&&(i[o.value]=a.value)}return{status:r.value,value:i}}}const an=Object.freeze({status:"aborted"}),y_=e=>({status:"dirty",value:e}),ju=e=>({status:"valid",value:e}),OV=e=>e.status==="aborted",RV=e=>e.status==="dirty",fv=e=>e.status==="valid",w4=e=>typeof Promise<"u"&&e instanceof Promise;var Ar;(function(e){e.errToObj=r=>typeof r=="string"?{message:r}:r||{},e.toString=r=>typeof r=="string"?r:r==null?void 0:r.message})(Ar||(Ar={}));class Vm{constructor(r,n,i,s){this._cachedPath=[],this.parent=r,this.data=n,this._path=i,this._key=s}get path(){return this._cachedPath.length||(Array.isArray(this._key)?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}const MV=(e,r)=>{if(fv(r))return{success:!0,data:r.value};if(!e.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const n=new Xf(e.common.issues);return this._error=n,this._error}}};function Cn(e){if(!e)return{};const{errorMap:r,invalid_type_error:n,required_error:i,description:s}=e;if(r&&(n||i))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return r?{errorMap:r,description:s}:{errorMap:(a,l)=>{const{message:d}=e;return a.code==="invalid_enum_value"?{message:d??l.defaultError}:typeof l.data>"u"?{message:d??i??l.defaultError}:a.code!=="invalid_type"?{message:l.defaultError}:{message:d??n??l.defaultError}},description:s}}class qn{get description(){return this._def.description}_getType(r){return _m(r.data)}_getOrReturnCtx(r,n){return n||{common:r.parent.common,data:r.data,parsedType:_m(r.data),schemaErrorMap:this._def.errorMap,path:r.path,parent:r.parent}}_processInputParams(r){return{status:new Oc,ctx:{common:r.parent.common,data:r.data,parsedType:_m(r.data),schemaErrorMap:this._def.errorMap,path:r.path,parent:r.parent}}}_parseSync(r){const n=this._parse(r);if(w4(n))throw new Error("Synchronous parse encountered promise.");return n}_parseAsync(r){const n=this._parse(r);return Promise.resolve(n)}parse(r,n){const i=this.safeParse(r,n);if(i.success)return i.data;throw i.error}safeParse(r,n){const i={common:{issues:[],async:(n==null?void 0:n.async)??!1,contextualErrorMap:n==null?void 0:n.errorMap},path:(n==null?void 0:n.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:r,parsedType:_m(r)},s=this._parseSync({data:r,path:i.path,parent:i});return MV(i,s)}"~validate"(r){var i,s;const n={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:r,parsedType:_m(r)};if(!this["~standard"].async)try{const o=this._parseSync({data:r,path:[],parent:n});return fv(o)?{value:o.value}:{issues:n.common.issues}}catch(o){(s=(i=o==null?void 0:o.message)==null?void 0:i.toLowerCase())!=null&&s.includes("encountered")&&(this["~standard"].async=!0),n.common={issues:[],async:!0}}return this._parseAsync({data:r,path:[],parent:n}).then(o=>fv(o)?{value:o.value}:{issues:n.common.issues})}async parseAsync(r,n){const i=await this.safeParseAsync(r,n);if(i.success)return i.data;throw i.error}async safeParseAsync(r,n){const i={common:{issues:[],contextualErrorMap:n==null?void 0:n.errorMap,async:!0},path:(n==null?void 0:n.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:r,parsedType:_m(r)},s=this._parse({data:r,path:i.path,parent:i}),o=await(w4(s)?s:Promise.resolve(s));return MV(i,o)}refine(r,n){const i=s=>typeof n=="string"||typeof n>"u"?{message:n}:typeof n=="function"?n(s):n;return this._refinement((s,o)=>{const a=r(s),l=()=>o.addIssue({code:Vt.custom,...i(s)});return typeof Promise<"u"&&a instanceof Promise?a.then(d=>d?!0:(l(),!1)):a?!0:(l(),!1)})}refinement(r,n){return this._refinement((i,s)=>r(i)?!0:(s.addIssue(typeof n=="function"?n(i,s):n),!1))}_refinement(r){return new gv({schema:this,typeName:ln.ZodEffects,effect:{type:"refinement",refinement:r}})}superRefine(r){return this._refinement(r)}constructor(r){this.spa=this.safeParseAsync,this._def=r,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:n=>this["~validate"](n)}}optional(){return Lm.create(this,this._def)}nullable(){return yv.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return Nh.create(this)}promise(){return j4.create(this,this._def)}or(r){return k4.create([this,r],this._def)}and(r){return C4.create(this,r,this._def)}transform(r){return new gv({...Cn(this._def),schema:this,typeName:ln.ZodEffects,effect:{type:"transform",transform:r}})}default(r){const n=typeof r=="function"?r:()=>r;return new U7({...Cn(this._def),innerType:this,defaultValue:n,typeName:ln.ZodDefault})}brand(){return new Opt({typeName:ln.ZodBranded,type:this,...Cn(this._def)})}catch(r){const n=typeof r=="function"?r:()=>r;return new V7({...Cn(this._def),innerType:this,catchValue:n,typeName:ln.ZodCatch})}describe(r){const n=this.constructor;return new n({...this._def,description:r})}pipe(r){return IP.create(this,r)}readonly(){return q7.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const cpt=/^c[^\s-]{8,}$/i,upt=/^[0-9a-z]+$/,dpt=/^[0-9A-HJKMNP-TV-Z]{26}$/i,hpt=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,fpt=/^[a-z0-9_-]{21}$/i,ppt=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,mpt=/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,gpt=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,ypt="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let h8;const vpt=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,xpt=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,bpt=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,_pt=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,wpt=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,Spt=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,tue="((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))",kpt=new RegExp(`^${tue}$`);function rue(e){let r="[0-5]\\d";e.precision?r=`${r}\\.\\d{${e.precision}}`:e.precision==null&&(r=`${r}(\\.\\d+)?`);const n=e.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${r})${n}`}function Cpt(e){return new RegExp(`^${rue(e)}$`)}function jpt(e){let r=`${tue}T${rue(e)}`;const n=[];return n.push(e.local?"Z?":"Z"),e.offset&&n.push("([+-]\\d{2}:?\\d{2})"),r=`${r}(${n.join("|")})`,new RegExp(`^${r}$`)}function Npt(e,r){return!!((r==="v4"||!r)&&vpt.test(e)||(r==="v6"||!r)&&bpt.test(e))}function Tpt(e,r){if(!ppt.test(e))return!1;try{const[n]=e.split(".");if(!n)return!1;const i=n.replace(/-/g,"+").replace(/_/g,"/").padEnd(n.length+(4-n.length%4)%4,"="),s=JSON.parse(atob(i));return!(typeof s!="object"||s===null||"typ"in s&&(s==null?void 0:s.typ)!=="JWT"||!s.alg||r&&s.alg!==r)}catch{return!1}}function Ept(e,r){return!!((r==="v4"||!r)&&xpt.test(e)||(r==="v6"||!r)&&_pt.test(e))}class Nm extends qn{_parse(r){if(this._def.coerce&&(r.data=String(r.data)),this._getType(r)!==kr.string){const o=this._getOrReturnCtx(r);return dr(o,{code:Vt.invalid_type,expected:kr.string,received:o.parsedType}),an}const i=new Oc;let s;for(const o of this._def.checks)if(o.kind==="min")r.data.length<o.value&&(s=this._getOrReturnCtx(r,s),dr(s,{code:Vt.too_small,minimum:o.value,type:"string",inclusive:!0,exact:!1,message:o.message}),i.dirty());else if(o.kind==="max")r.data.length>o.value&&(s=this._getOrReturnCtx(r,s),dr(s,{code:Vt.too_big,maximum:o.value,type:"string",inclusive:!0,exact:!1,message:o.message}),i.dirty());else if(o.kind==="length"){const a=r.data.length>o.value,l=r.data.length<o.value;(a||l)&&(s=this._getOrReturnCtx(r,s),a?dr(s,{code:Vt.too_big,maximum:o.value,type:"string",inclusive:!0,exact:!0,message:o.message}):l&&dr(s,{code:Vt.too_small,minimum:o.value,type:"string",inclusive:!0,exact:!0,message:o.message}),i.dirty())}else if(o.kind==="email")gpt.test(r.data)||(s=this._getOrReturnCtx(r,s),dr(s,{validation:"email",code:Vt.invalid_string,message:o.message}),i.dirty());else if(o.kind==="emoji")h8||(h8=new RegExp(ypt,"u")),h8.test(r.data)||(s=this._getOrReturnCtx(r,s),dr(s,{validation:"emoji",code:Vt.invalid_string,message:o.message}),i.dirty());else if(o.kind==="uuid")hpt.test(r.data)||(s=this._getOrReturnCtx(r,s),dr(s,{validation:"uuid",code:Vt.invalid_string,message:o.message}),i.dirty());else if(o.kind==="nanoid")fpt.test(r.data)||(s=this._getOrReturnCtx(r,s),dr(s,{validation:"nanoid",code:Vt.invalid_string,message:o.message}),i.dirty());else if(o.kind==="cuid")cpt.test(r.data)||(s=this._getOrReturnCtx(r,s),dr(s,{validation:"cuid",code:Vt.invalid_string,message:o.message}),i.dirty());else if(o.kind==="cuid2")upt.test(r.data)||(s=this._getOrReturnCtx(r,s),dr(s,{validation:"cuid2",code:Vt.invalid_string,message:o.message}),i.dirty());else if(o.kind==="ulid")dpt.test(r.data)||(s=this._getOrReturnCtx(r,s),dr(s,{validation:"ulid",code:Vt.invalid_string,message:o.message}),i.dirty());else if(o.kind==="url")try{new URL(r.data)}catch{s=this._getOrReturnCtx(r,s),dr(s,{validation:"url",code:Vt.invalid_string,message:o.message}),i.dirty()}else o.kind==="regex"?(o.regex.lastIndex=0,o.regex.test(r.data)||(s=this._getOrReturnCtx(r,s),dr(s,{validation:"regex",code:Vt.invalid_string,message:o.message}),i.dirty())):o.kind==="trim"?r.data=r.data.trim():o.kind==="includes"?r.data.includes(o.value,o.position)||(s=this._getOrReturnCtx(r,s),dr(s,{code:Vt.invalid_string,validation:{includes:o.value,position:o.position},message:o.message}),i.dirty()):o.kind==="toLowerCase"?r.data=r.data.toLowerCase():o.kind==="toUpperCase"?r.data=r.data.toUpperCase():o.kind==="startsWith"?r.data.startsWith(o.value)||(s=this._getOrReturnCtx(r,s),dr(s,{code:Vt.invalid_string,validation:{startsWith:o.value},message:o.message}),i.dirty()):o.kind==="endsWith"?r.data.endsWith(o.value)||(s=this._getOrReturnCtx(r,s),dr(s,{code:Vt.invalid_string,validation:{endsWith:o.value},message:o.message}),i.dirty()):o.kind==="datetime"?jpt(o).test(r.data)||(s=this._getOrReturnCtx(r,s),dr(s,{code:Vt.invalid_string,validation:"datetime",message:o.message}),i.dirty()):o.kind==="date"?kpt.test(r.data)||(s=this._getOrReturnCtx(r,s),dr(s,{code:Vt.invalid_string,validation:"date",message:o.message}),i.dirty()):o.kind==="time"?Cpt(o).test(r.data)||(s=this._getOrReturnCtx(r,s),dr(s,{code:Vt.invalid_string,validation:"time",message:o.message}),i.dirty()):o.kind==="duration"?mpt.test(r.data)||(s=this._getOrReturnCtx(r,s),dr(s,{validation:"duration",code:Vt.invalid_string,message:o.message}),i.dirty()):o.kind==="ip"?Npt(r.data,o.version)||(s=this._getOrReturnCtx(r,s),dr(s,{validation:"ip",code:Vt.invalid_string,message:o.message}),i.dirty()):o.kind==="jwt"?Tpt(r.data,o.alg)||(s=this._getOrReturnCtx(r,s),dr(s,{validation:"jwt",code:Vt.invalid_string,message:o.message}),i.dirty()):o.kind==="cidr"?Ept(r.data,o.version)||(s=this._getOrReturnCtx(r,s),dr(s,{validation:"cidr",code:Vt.invalid_string,message:o.message}),i.dirty()):o.kind==="base64"?wpt.test(r.data)||(s=this._getOrReturnCtx(r,s),dr(s,{validation:"base64",code:Vt.invalid_string,message:o.message}),i.dirty()):o.kind==="base64url"?Spt.test(r.data)||(s=this._getOrReturnCtx(r,s),dr(s,{validation:"base64url",code:Vt.invalid_string,message:o.message}),i.dirty()):Qn.assertNever(o);return{status:i.value,value:r.data}}_regex(r,n,i){return this.refinement(s=>r.test(s),{validation:n,code:Vt.invalid_string,...Ar.errToObj(i)})}_addCheck(r){return new Nm({...this._def,checks:[...this._def.checks,r]})}email(r){return this._addCheck({kind:"email",...Ar.errToObj(r)})}url(r){return this._addCheck({kind:"url",...Ar.errToObj(r)})}emoji(r){return this._addCheck({kind:"emoji",...Ar.errToObj(r)})}uuid(r){return this._addCheck({kind:"uuid",...Ar.errToObj(r)})}nanoid(r){return this._addCheck({kind:"nanoid",...Ar.errToObj(r)})}cuid(r){return this._addCheck({kind:"cuid",...Ar.errToObj(r)})}cuid2(r){return this._addCheck({kind:"cuid2",...Ar.errToObj(r)})}ulid(r){return this._addCheck({kind:"ulid",...Ar.errToObj(r)})}base64(r){return this._addCheck({kind:"base64",...Ar.errToObj(r)})}base64url(r){return this._addCheck({kind:"base64url",...Ar.errToObj(r)})}jwt(r){return this._addCheck({kind:"jwt",...Ar.errToObj(r)})}ip(r){return this._addCheck({kind:"ip",...Ar.errToObj(r)})}cidr(r){return this._addCheck({kind:"cidr",...Ar.errToObj(r)})}datetime(r){return typeof r=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:r}):this._addCheck({kind:"datetime",precision:typeof(r==null?void 0:r.precision)>"u"?null:r==null?void 0:r.precision,offset:(r==null?void 0:r.offset)??!1,local:(r==null?void 0:r.local)??!1,...Ar.errToObj(r==null?void 0:r.message)})}date(r){return this._addCheck({kind:"date",message:r})}time(r){return typeof r=="string"?this._addCheck({kind:"time",precision:null,message:r}):this._addCheck({kind:"time",precision:typeof(r==null?void 0:r.precision)>"u"?null:r==null?void 0:r.precision,...Ar.errToObj(r==null?void 0:r.message)})}duration(r){return this._addCheck({kind:"duration",...Ar.errToObj(r)})}regex(r,n){return this._addCheck({kind:"regex",regex:r,...Ar.errToObj(n)})}includes(r,n){return this._addCheck({kind:"includes",value:r,position:n==null?void 0:n.position,...Ar.errToObj(n==null?void 0:n.message)})}startsWith(r,n){return this._addCheck({kind:"startsWith",value:r,...Ar.errToObj(n)})}endsWith(r,n){return this._addCheck({kind:"endsWith",value:r,...Ar.errToObj(n)})}min(r,n){return this._addCheck({kind:"min",value:r,...Ar.errToObj(n)})}max(r,n){return this._addCheck({kind:"max",value:r,...Ar.errToObj(n)})}length(r,n){return this._addCheck({kind:"length",value:r,...Ar.errToObj(n)})}nonempty(r){return this.min(1,Ar.errToObj(r))}trim(){return new Nm({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new Nm({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new Nm({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(r=>r.kind==="datetime")}get isDate(){return!!this._def.checks.find(r=>r.kind==="date")}get isTime(){return!!this._def.checks.find(r=>r.kind==="time")}get isDuration(){return!!this._def.checks.find(r=>r.kind==="duration")}get isEmail(){return!!this._def.checks.find(r=>r.kind==="email")}get isURL(){return!!this._def.checks.find(r=>r.kind==="url")}get isEmoji(){return!!this._def.checks.find(r=>r.kind==="emoji")}get isUUID(){return!!this._def.checks.find(r=>r.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(r=>r.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(r=>r.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(r=>r.kind==="cuid2")}get isULID(){return!!this._def.checks.find(r=>r.kind==="ulid")}get isIP(){return!!this._def.checks.find(r=>r.kind==="ip")}get isCIDR(){return!!this._def.checks.find(r=>r.kind==="cidr")}get isBase64(){return!!this._def.checks.find(r=>r.kind==="base64")}get isBase64url(){return!!this._def.checks.find(r=>r.kind==="base64url")}get minLength(){let r=null;for(const n of this._def.checks)n.kind==="min"&&(r===null||n.value>r)&&(r=n.value);return r}get maxLength(){let r=null;for(const n of this._def.checks)n.kind==="max"&&(r===null||n.value<r)&&(r=n.value);return r}}Nm.create=e=>new Nm({checks:[],typeName:ln.ZodString,coerce:(e==null?void 0:e.coerce)??!1,...Cn(e)});function Apt(e,r){const n=(e.toString().split(".")[1]||"").length,i=(r.toString().split(".")[1]||"").length,s=n>i?n:i,o=Number.parseInt(e.toFixed(s).replace(".","")),a=Number.parseInt(r.toFixed(s).replace(".",""));return o%a/10**s}class pv extends qn{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(r){if(this._def.coerce&&(r.data=Number(r.data)),this._getType(r)!==kr.number){const o=this._getOrReturnCtx(r);return dr(o,{code:Vt.invalid_type,expected:kr.number,received:o.parsedType}),an}let i;const s=new Oc;for(const o of this._def.checks)o.kind==="int"?Qn.isInteger(r.data)||(i=this._getOrReturnCtx(r,i),dr(i,{code:Vt.invalid_type,expected:"integer",received:"float",message:o.message}),s.dirty()):o.kind==="min"?(o.inclusive?r.data<o.value:r.data<=o.value)&&(i=this._getOrReturnCtx(r,i),dr(i,{code:Vt.too_small,minimum:o.value,type:"number",inclusive:o.inclusive,exact:!1,message:o.message}),s.dirty()):o.kind==="max"?(o.inclusive?r.data>o.value:r.data>=o.value)&&(i=this._getOrReturnCtx(r,i),dr(i,{code:Vt.too_big,maximum:o.value,type:"number",inclusive:o.inclusive,exact:!1,message:o.message}),s.dirty()):o.kind==="multipleOf"?Apt(r.data,o.value)!==0&&(i=this._getOrReturnCtx(r,i),dr(i,{code:Vt.not_multiple_of,multipleOf:o.value,message:o.message}),s.dirty()):o.kind==="finite"?Number.isFinite(r.data)||(i=this._getOrReturnCtx(r,i),dr(i,{code:Vt.not_finite,message:o.message}),s.dirty()):Qn.assertNever(o);return{status:s.value,value:r.data}}gte(r,n){return this.setLimit("min",r,!0,Ar.toString(n))}gt(r,n){return this.setLimit("min",r,!1,Ar.toString(n))}lte(r,n){return this.setLimit("max",r,!0,Ar.toString(n))}lt(r,n){return this.setLimit("max",r,!1,Ar.toString(n))}setLimit(r,n,i,s){return new pv({...this._def,checks:[...this._def.checks,{kind:r,value:n,inclusive:i,message:Ar.toString(s)}]})}_addCheck(r){return new pv({...this._def,checks:[...this._def.checks,r]})}int(r){return this._addCheck({kind:"int",message:Ar.toString(r)})}positive(r){return this._addCheck({kind:"min",value:0,inclusive:!1,message:Ar.toString(r)})}negative(r){return this._addCheck({kind:"max",value:0,inclusive:!1,message:Ar.toString(r)})}nonpositive(r){return this._addCheck({kind:"max",value:0,inclusive:!0,message:Ar.toString(r)})}nonnegative(r){return this._addCheck({kind:"min",value:0,inclusive:!0,message:Ar.toString(r)})}multipleOf(r,n){return this._addCheck({kind:"multipleOf",value:r,message:Ar.toString(n)})}finite(r){return this._addCheck({kind:"finite",message:Ar.toString(r)})}safe(r){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:Ar.toString(r)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:Ar.toString(r)})}get minValue(){let r=null;for(const n of this._def.checks)n.kind==="min"&&(r===null||n.value>r)&&(r=n.value);return r}get maxValue(){let r=null;for(const n of this._def.checks)n.kind==="max"&&(r===null||n.value<r)&&(r=n.value);return r}get isInt(){return!!this._def.checks.find(r=>r.kind==="int"||r.kind==="multipleOf"&&Qn.isInteger(r.value))}get isFinite(){let r=null,n=null;for(const i of this._def.checks){if(i.kind==="finite"||i.kind==="int"||i.kind==="multipleOf")return!0;i.kind==="min"?(n===null||i.value>n)&&(n=i.value):i.kind==="max"&&(r===null||i.value<r)&&(r=i.value)}return Number.isFinite(n)&&Number.isFinite(r)}}pv.create=e=>new pv({checks:[],typeName:ln.ZodNumber,coerce:(e==null?void 0:e.coerce)||!1,...Cn(e)});class Kw extends qn{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(r){if(this._def.coerce)try{r.data=BigInt(r.data)}catch{return this._getInvalidInput(r)}if(this._getType(r)!==kr.bigint)return this._getInvalidInput(r);let i;const s=new Oc;for(const o of this._def.checks)o.kind==="min"?(o.inclusive?r.data<o.value:r.data<=o.value)&&(i=this._getOrReturnCtx(r,i),dr(i,{code:Vt.too_small,type:"bigint",minimum:o.value,inclusive:o.inclusive,message:o.message}),s.dirty()):o.kind==="max"?(o.inclusive?r.data>o.value:r.data>=o.value)&&(i=this._getOrReturnCtx(r,i),dr(i,{code:Vt.too_big,type:"bigint",maximum:o.value,inclusive:o.inclusive,message:o.message}),s.dirty()):o.kind==="multipleOf"?r.data%o.value!==BigInt(0)&&(i=this._getOrReturnCtx(r,i),dr(i,{code:Vt.not_multiple_of,multipleOf:o.value,message:o.message}),s.dirty()):Qn.assertNever(o);return{status:s.value,value:r.data}}_getInvalidInput(r){const n=this._getOrReturnCtx(r);return dr(n,{code:Vt.invalid_type,expected:kr.bigint,received:n.parsedType}),an}gte(r,n){return this.setLimit("min",r,!0,Ar.toString(n))}gt(r,n){return this.setLimit("min",r,!1,Ar.toString(n))}lte(r,n){return this.setLimit("max",r,!0,Ar.toString(n))}lt(r,n){return this.setLimit("max",r,!1,Ar.toString(n))}setLimit(r,n,i,s){return new Kw({...this._def,checks:[...this._def.checks,{kind:r,value:n,inclusive:i,message:Ar.toString(s)}]})}_addCheck(r){return new Kw({...this._def,checks:[...this._def.checks,r]})}positive(r){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:Ar.toString(r)})}negative(r){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:Ar.toString(r)})}nonpositive(r){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:Ar.toString(r)})}nonnegative(r){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:Ar.toString(r)})}multipleOf(r,n){return this._addCheck({kind:"multipleOf",value:r,message:Ar.toString(n)})}get minValue(){let r=null;for(const n of this._def.checks)n.kind==="min"&&(r===null||n.value>r)&&(r=n.value);return r}get maxValue(){let r=null;for(const n of this._def.checks)n.kind==="max"&&(r===null||n.value<r)&&(r=n.value);return r}}Kw.create=e=>new Kw({checks:[],typeName:ln.ZodBigInt,coerce:(e==null?void 0:e.coerce)??!1,...Cn(e)});class H7 extends qn{_parse(r){if(this._def.coerce&&(r.data=!!r.data),this._getType(r)!==kr.boolean){const i=this._getOrReturnCtx(r);return dr(i,{code:Vt.invalid_type,expected:kr.boolean,received:i.parsedType}),an}return ju(r.data)}}H7.create=e=>new H7({typeName:ln.ZodBoolean,coerce:(e==null?void 0:e.coerce)||!1,...Cn(e)});class S4 extends qn{_parse(r){if(this._def.coerce&&(r.data=new Date(r.data)),this._getType(r)!==kr.date){const o=this._getOrReturnCtx(r);return dr(o,{code:Vt.invalid_type,expected:kr.date,received:o.parsedType}),an}if(Number.isNaN(r.data.getTime())){const o=this._getOrReturnCtx(r);return dr(o,{code:Vt.invalid_date}),an}const i=new Oc;let s;for(const o of this._def.checks)o.kind==="min"?r.data.getTime()<o.value&&(s=this._getOrReturnCtx(r,s),dr(s,{code:Vt.too_small,message:o.message,inclusive:!0,exact:!1,minimum:o.value,type:"date"}),i.dirty()):o.kind==="max"?r.data.getTime()>o.value&&(s=this._getOrReturnCtx(r,s),dr(s,{code:Vt.too_big,message:o.message,inclusive:!0,exact:!1,maximum:o.value,type:"date"}),i.dirty()):Qn.assertNever(o);return{status:i.value,value:new Date(r.data.getTime())}}_addCheck(r){return new S4({...this._def,checks:[...this._def.checks,r]})}min(r,n){return this._addCheck({kind:"min",value:r.getTime(),message:Ar.toString(n)})}max(r,n){return this._addCheck({kind:"max",value:r.getTime(),message:Ar.toString(n)})}get minDate(){let r=null;for(const n of this._def.checks)n.kind==="min"&&(r===null||n.value>r)&&(r=n.value);return r!=null?new Date(r):null}get maxDate(){let r=null;for(const n of this._def.checks)n.kind==="max"&&(r===null||n.value<r)&&(r=n.value);return r!=null?new Date(r):null}}S4.create=e=>new S4({checks:[],coerce:(e==null?void 0:e.coerce)||!1,typeName:ln.ZodDate,...Cn(e)});class PV extends qn{_parse(r){if(this._getType(r)!==kr.symbol){const i=this._getOrReturnCtx(r);return dr(i,{code:Vt.invalid_type,expected:kr.symbol,received:i.parsedType}),an}return ju(r.data)}}PV.create=e=>new PV({typeName:ln.ZodSymbol,...Cn(e)});class LV extends qn{_parse(r){if(this._getType(r)!==kr.undefined){const i=this._getOrReturnCtx(r);return dr(i,{code:Vt.invalid_type,expected:kr.undefined,received:i.parsedType}),an}return ju(r.data)}}LV.create=e=>new LV({typeName:ln.ZodUndefined,...Cn(e)});class $V extends qn{_parse(r){if(this._getType(r)!==kr.null){const i=this._getOrReturnCtx(r);return dr(i,{code:Vt.invalid_type,expected:kr.null,received:i.parsedType}),an}return ju(r.data)}}$V.create=e=>new $V({typeName:ln.ZodNull,...Cn(e)});class DV extends qn{constructor(){super(...arguments),this._any=!0}_parse(r){return ju(r.data)}}DV.create=e=>new DV({typeName:ln.ZodAny,...Cn(e)});class IV extends qn{constructor(){super(...arguments),this._unknown=!0}_parse(r){return ju(r.data)}}IV.create=e=>new IV({typeName:ln.ZodUnknown,...Cn(e)});class qm extends qn{_parse(r){const n=this._getOrReturnCtx(r);return dr(n,{code:Vt.invalid_type,expected:kr.never,received:n.parsedType}),an}}qm.create=e=>new qm({typeName:ln.ZodNever,...Cn(e)});class BV extends qn{_parse(r){if(this._getType(r)!==kr.undefined){const i=this._getOrReturnCtx(r);return dr(i,{code:Vt.invalid_type,expected:kr.void,received:i.parsedType}),an}return ju(r.data)}}BV.create=e=>new BV({typeName:ln.ZodVoid,...Cn(e)});class Nh extends qn{_parse(r){const{ctx:n,status:i}=this._processInputParams(r),s=this._def;if(n.parsedType!==kr.array)return dr(n,{code:Vt.invalid_type,expected:kr.array,received:n.parsedType}),an;if(s.exactLength!==null){const a=n.data.length>s.exactLength.value,l=n.data.length<s.exactLength.value;(a||l)&&(dr(n,{code:a?Vt.too_big:Vt.too_small,minimum:l?s.exactLength.value:void 0,maximum:a?s.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:s.exactLength.message}),i.dirty())}if(s.minLength!==null&&n.data.length<s.minLength.value&&(dr(n,{code:Vt.too_small,minimum:s.minLength.value,type:"array",inclusive:!0,exact:!1,message:s.minLength.message}),i.dirty()),s.maxLength!==null&&n.data.length>s.maxLength.value&&(dr(n,{code:Vt.too_big,maximum:s.maxLength.value,type:"array",inclusive:!0,exact:!1,message:s.maxLength.message}),i.dirty()),n.common.async)return Promise.all([...n.data].map((a,l)=>s.type._parseAsync(new Vm(n,a,n.path,l)))).then(a=>Oc.mergeArray(i,a));const o=[...n.data].map((a,l)=>s.type._parseSync(new Vm(n,a,n.path,l)));return Oc.mergeArray(i,o)}get element(){return this._def.type}min(r,n){return new Nh({...this._def,minLength:{value:r,message:Ar.toString(n)}})}max(r,n){return new Nh({...this._def,maxLength:{value:r,message:Ar.toString(n)}})}length(r,n){return new Nh({...this._def,exactLength:{value:r,message:Ar.toString(n)}})}nonempty(r){return this.min(1,r)}}Nh.create=(e,r)=>new Nh({type:e,minLength:null,maxLength:null,exactLength:null,typeName:ln.ZodArray,...Cn(r)});function g1(e){if(e instanceof Bs){const r={};for(const n in e.shape){const i=e.shape[n];r[n]=Lm.create(g1(i))}return new Bs({...e._def,shape:()=>r})}else return e instanceof Nh?new Nh({...e._def,type:g1(e.element)}):e instanceof Lm?Lm.create(g1(e.unwrap())):e instanceof yv?yv.create(g1(e.unwrap())):e instanceof I0?I0.create(e.items.map(r=>g1(r))):e}class Bs extends qn{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;const r=this._def.shape(),n=Qn.objectKeys(r);return this._cached={shape:r,keys:n},this._cached}_parse(r){if(this._getType(r)!==kr.object){const u=this._getOrReturnCtx(r);return dr(u,{code:Vt.invalid_type,expected:kr.object,received:u.parsedType}),an}const{status:i,ctx:s}=this._processInputParams(r),{shape:o,keys:a}=this._getCached(),l=[];if(!(this._def.catchall instanceof qm&&this._def.unknownKeys==="strip"))for(const u in s.data)a.includes(u)||l.push(u);const d=[];for(const u of a){const f=o[u],p=s.data[u];d.push({key:{status:"valid",value:u},value:f._parse(new Vm(s,p,s.path,u)),alwaysSet:u in s.data})}if(this._def.catchall instanceof qm){const u=this._def.unknownKeys;if(u==="passthrough")for(const f of l)d.push({key:{status:"valid",value:f},value:{status:"valid",value:s.data[f]}});else if(u==="strict")l.length>0&&(dr(s,{code:Vt.unrecognized_keys,keys:l}),i.dirty());else if(u!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const u=this._def.catchall;for(const f of l){const p=s.data[f];d.push({key:{status:"valid",value:f},value:u._parse(new Vm(s,p,s.path,f)),alwaysSet:f in s.data})}}return s.common.async?Promise.resolve().then(async()=>{const u=[];for(const f of d){const p=await f.key,g=await f.value;u.push({key:p,value:g,alwaysSet:f.alwaysSet})}return u}).then(u=>Oc.mergeObjectSync(i,u)):Oc.mergeObjectSync(i,d)}get shape(){return this._def.shape()}strict(r){return Ar.errToObj,new Bs({...this._def,unknownKeys:"strict",...r!==void 0?{errorMap:(n,i)=>{var o,a;const s=((a=(o=this._def).errorMap)==null?void 0:a.call(o,n,i).message)??i.defaultError;return n.code==="unrecognized_keys"?{message:Ar.errToObj(r).message??s}:{message:s}}}:{}})}strip(){return new Bs({...this._def,unknownKeys:"strip"})}passthrough(){return new Bs({...this._def,unknownKeys:"passthrough"})}extend(r){return new Bs({...this._def,shape:()=>({...this._def.shape(),...r})})}merge(r){return new Bs({unknownKeys:r._def.unknownKeys,catchall:r._def.catchall,shape:()=>({...this._def.shape(),...r._def.shape()}),typeName:ln.ZodObject})}setKey(r,n){return this.augment({[r]:n})}catchall(r){return new Bs({...this._def,catchall:r})}pick(r){const n={};for(const i of Qn.objectKeys(r))r[i]&&this.shape[i]&&(n[i]=this.shape[i]);return new Bs({...this._def,shape:()=>n})}omit(r){const n={};for(const i of Qn.objectKeys(this.shape))r[i]||(n[i]=this.shape[i]);return new Bs({...this._def,shape:()=>n})}deepPartial(){return g1(this)}partial(r){const n={};for(const i of Qn.objectKeys(this.shape)){const s=this.shape[i];r&&!r[i]?n[i]=s:n[i]=s.optional()}return new Bs({...this._def,shape:()=>n})}required(r){const n={};for(const i of Qn.objectKeys(this.shape))if(r&&!r[i])n[i]=this.shape[i];else{let o=this.shape[i];for(;o instanceof Lm;)o=o._def.innerType;n[i]=o}return new Bs({...this._def,shape:()=>n})}keyof(){return nue(Qn.objectKeys(this.shape))}}Bs.create=(e,r)=>new Bs({shape:()=>e,unknownKeys:"strip",catchall:qm.create(),typeName:ln.ZodObject,...Cn(r)});Bs.strictCreate=(e,r)=>new Bs({shape:()=>e,unknownKeys:"strict",catchall:qm.create(),typeName:ln.ZodObject,...Cn(r)});Bs.lazycreate=(e,r)=>new Bs({shape:e,unknownKeys:"strip",catchall:qm.create(),typeName:ln.ZodObject,...Cn(r)});class k4 extends qn{_parse(r){const{ctx:n}=this._processInputParams(r),i=this._def.options;function s(o){for(const l of o)if(l.result.status==="valid")return l.result;for(const l of o)if(l.result.status==="dirty")return n.common.issues.push(...l.ctx.common.issues),l.result;const a=o.map(l=>new Xf(l.ctx.common.issues));return dr(n,{code:Vt.invalid_union,unionErrors:a}),an}if(n.common.async)return Promise.all(i.map(async o=>{const a={...n,common:{...n.common,issues:[]},parent:null};return{result:await o._parseAsync({data:n.data,path:n.path,parent:a}),ctx:a}})).then(s);{let o;const a=[];for(const d of i){const u={...n,common:{...n.common,issues:[]},parent:null},f=d._parseSync({data:n.data,path:n.path,parent:u});if(f.status==="valid")return f;f.status==="dirty"&&!o&&(o={result:f,ctx:u}),u.common.issues.length&&a.push(u.common.issues)}if(o)return n.common.issues.push(...o.ctx.common.issues),o.result;const l=a.map(d=>new Xf(d));return dr(n,{code:Vt.invalid_union,unionErrors:l}),an}}get options(){return this._def.options}}k4.create=(e,r)=>new k4({options:e,typeName:ln.ZodUnion,...Cn(r)});function W7(e,r){const n=_m(e),i=_m(r);if(e===r)return{valid:!0,data:e};if(n===kr.object&&i===kr.object){const s=Qn.objectKeys(r),o=Qn.objectKeys(e).filter(l=>s.indexOf(l)!==-1),a={...e,...r};for(const l of o){const d=W7(e[l],r[l]);if(!d.valid)return{valid:!1};a[l]=d.data}return{valid:!0,data:a}}else if(n===kr.array&&i===kr.array){if(e.length!==r.length)return{valid:!1};const s=[];for(let o=0;o<e.length;o++){const a=e[o],l=r[o],d=W7(a,l);if(!d.valid)return{valid:!1};s.push(d.data)}return{valid:!0,data:s}}else return n===kr.date&&i===kr.date&&+e==+r?{valid:!0,data:e}:{valid:!1}}class C4 extends qn{_parse(r){const{status:n,ctx:i}=this._processInputParams(r),s=(o,a)=>{if(OV(o)||OV(a))return an;const l=W7(o.value,a.value);return l.valid?((RV(o)||RV(a))&&n.dirty(),{status:n.value,value:l.data}):(dr(i,{code:Vt.invalid_intersection_types}),an)};return i.common.async?Promise.all([this._def.left._parseAsync({data:i.data,path:i.path,parent:i}),this._def.right._parseAsync({data:i.data,path:i.path,parent:i})]).then(([o,a])=>s(o,a)):s(this._def.left._parseSync({data:i.data,path:i.path,parent:i}),this._def.right._parseSync({data:i.data,path:i.path,parent:i}))}}C4.create=(e,r,n)=>new C4({left:e,right:r,typeName:ln.ZodIntersection,...Cn(n)});class I0 extends qn{_parse(r){const{status:n,ctx:i}=this._processInputParams(r);if(i.parsedType!==kr.array)return dr(i,{code:Vt.invalid_type,expected:kr.array,received:i.parsedType}),an;if(i.data.length<this._def.items.length)return dr(i,{code:Vt.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),an;!this._def.rest&&i.data.length>this._def.items.length&&(dr(i,{code:Vt.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),n.dirty());const o=[...i.data].map((a,l)=>{const d=this._def.items[l]||this._def.rest;return d?d._parse(new Vm(i,a,i.path,l)):null}).filter(a=>!!a);return i.common.async?Promise.all(o).then(a=>Oc.mergeArray(n,a)):Oc.mergeArray(n,o)}get items(){return this._def.items}rest(r){return new I0({...this._def,rest:r})}}I0.create=(e,r)=>{if(!Array.isArray(e))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new I0({items:e,typeName:ln.ZodTuple,rest:null,...Cn(r)})};class zV extends qn{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(r){const{status:n,ctx:i}=this._processInputParams(r);if(i.parsedType!==kr.map)return dr(i,{code:Vt.invalid_type,expected:kr.map,received:i.parsedType}),an;const s=this._def.keyType,o=this._def.valueType,a=[...i.data.entries()].map(([l,d],u)=>({key:s._parse(new Vm(i,l,i.path,[u,"key"])),value:o._parse(new Vm(i,d,i.path,[u,"value"]))}));if(i.common.async){const l=new Map;return Promise.resolve().then(async()=>{for(const d of a){const u=await d.key,f=await d.value;if(u.status==="aborted"||f.status==="aborted")return an;(u.status==="dirty"||f.status==="dirty")&&n.dirty(),l.set(u.value,f.value)}return{status:n.value,value:l}})}else{const l=new Map;for(const d of a){const u=d.key,f=d.value;if(u.status==="aborted"||f.status==="aborted")return an;(u.status==="dirty"||f.status==="dirty")&&n.dirty(),l.set(u.value,f.value)}return{status:n.value,value:l}}}}zV.create=(e,r,n)=>new zV({valueType:r,keyType:e,typeName:ln.ZodMap,...Cn(n)});class Yw extends qn{_parse(r){const{status:n,ctx:i}=this._processInputParams(r);if(i.parsedType!==kr.set)return dr(i,{code:Vt.invalid_type,expected:kr.set,received:i.parsedType}),an;const s=this._def;s.minSize!==null&&i.data.size<s.minSize.value&&(dr(i,{code:Vt.too_small,minimum:s.minSize.value,type:"set",inclusive:!0,exact:!1,message:s.minSize.message}),n.dirty()),s.maxSize!==null&&i.data.size>s.maxSize.value&&(dr(i,{code:Vt.too_big,maximum:s.maxSize.value,type:"set",inclusive:!0,exact:!1,message:s.maxSize.message}),n.dirty());const o=this._def.valueType;function a(d){const u=new Set;for(const f of d){if(f.status==="aborted")return an;f.status==="dirty"&&n.dirty(),u.add(f.value)}return{status:n.value,value:u}}const l=[...i.data.values()].map((d,u)=>o._parse(new Vm(i,d,i.path,u)));return i.common.async?Promise.all(l).then(d=>a(d)):a(l)}min(r,n){return new Yw({...this._def,minSize:{value:r,message:Ar.toString(n)}})}max(r,n){return new Yw({...this._def,maxSize:{value:r,message:Ar.toString(n)}})}size(r,n){return this.min(r,n).max(r,n)}nonempty(r){return this.min(1,r)}}Yw.create=(e,r)=>new Yw({valueType:e,minSize:null,maxSize:null,typeName:ln.ZodSet,...Cn(r)});class FV extends qn{get schema(){return this._def.getter()}_parse(r){const{ctx:n}=this._processInputParams(r);return this._def.getter()._parse({data:n.data,path:n.path,parent:n})}}FV.create=(e,r)=>new FV({getter:e,typeName:ln.ZodLazy,...Cn(r)});class HV extends qn{_parse(r){if(r.data!==this._def.value){const n=this._getOrReturnCtx(r);return dr(n,{received:n.data,code:Vt.invalid_literal,expected:this._def.value}),an}return{status:"valid",value:r.data}}get value(){return this._def.value}}HV.create=(e,r)=>new HV({value:e,typeName:ln.ZodLiteral,...Cn(r)});function nue(e,r){return new mv({values:e,typeName:ln.ZodEnum,...Cn(r)})}class mv extends qn{_parse(r){if(typeof r.data!="string"){const n=this._getOrReturnCtx(r),i=this._def.values;return dr(n,{expected:Qn.joinValues(i),received:n.parsedType,code:Vt.invalid_type}),an}if(this._cache||(this._cache=new Set(this._def.values)),!this._cache.has(r.data)){const n=this._getOrReturnCtx(r),i=this._def.values;return dr(n,{received:n.data,code:Vt.invalid_enum_value,options:i}),an}return ju(r.data)}get options(){return this._def.values}get enum(){const r={};for(const n of this._def.values)r[n]=n;return r}get Values(){const r={};for(const n of this._def.values)r[n]=n;return r}get Enum(){const r={};for(const n of this._def.values)r[n]=n;return r}extract(r,n=this._def){return mv.create(r,{...this._def,...n})}exclude(r,n=this._def){return mv.create(this.options.filter(i=>!r.includes(i)),{...this._def,...n})}}mv.create=nue;class WV extends qn{_parse(r){const n=Qn.getValidEnumValues(this._def.values),i=this._getOrReturnCtx(r);if(i.parsedType!==kr.string&&i.parsedType!==kr.number){const s=Qn.objectValues(n);return dr(i,{expected:Qn.joinValues(s),received:i.parsedType,code:Vt.invalid_type}),an}if(this._cache||(this._cache=new Set(Qn.getValidEnumValues(this._def.values))),!this._cache.has(r.data)){const s=Qn.objectValues(n);return dr(i,{received:i.data,code:Vt.invalid_enum_value,options:s}),an}return ju(r.data)}get enum(){return this._def.values}}WV.create=(e,r)=>new WV({values:e,typeName:ln.ZodNativeEnum,...Cn(r)});class j4 extends qn{unwrap(){return this._def.type}_parse(r){const{ctx:n}=this._processInputParams(r);if(n.parsedType!==kr.promise&&n.common.async===!1)return dr(n,{code:Vt.invalid_type,expected:kr.promise,received:n.parsedType}),an;const i=n.parsedType===kr.promise?n.data:Promise.resolve(n.data);return ju(i.then(s=>this._def.type.parseAsync(s,{path:n.path,errorMap:n.common.contextualErrorMap})))}}j4.create=(e,r)=>new j4({type:e,typeName:ln.ZodPromise,...Cn(r)});class gv extends qn{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===ln.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(r){const{status:n,ctx:i}=this._processInputParams(r),s=this._def.effect||null,o={addIssue:a=>{dr(i,a),a.fatal?n.abort():n.dirty()},get path(){return i.path}};if(o.addIssue=o.addIssue.bind(o),s.type==="preprocess"){const a=s.transform(i.data,o);if(i.common.async)return Promise.resolve(a).then(async l=>{if(n.value==="aborted")return an;const d=await this._def.schema._parseAsync({data:l,path:i.path,parent:i});return d.status==="aborted"?an:d.status==="dirty"||n.value==="dirty"?y_(d.value):d});{if(n.value==="aborted")return an;const l=this._def.schema._parseSync({data:a,path:i.path,parent:i});return l.status==="aborted"?an:l.status==="dirty"||n.value==="dirty"?y_(l.value):l}}if(s.type==="refinement"){const a=l=>{const d=s.refinement(l,o);if(i.common.async)return Promise.resolve(d);if(d instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return l};if(i.common.async===!1){const l=this._def.schema._parseSync({data:i.data,path:i.path,parent:i});return l.status==="aborted"?an:(l.status==="dirty"&&n.dirty(),a(l.value),{status:n.value,value:l.value})}else return this._def.schema._parseAsync({data:i.data,path:i.path,parent:i}).then(l=>l.status==="aborted"?an:(l.status==="dirty"&&n.dirty(),a(l.value).then(()=>({status:n.value,value:l.value}))))}if(s.type==="transform")if(i.common.async===!1){const a=this._def.schema._parseSync({data:i.data,path:i.path,parent:i});if(!fv(a))return an;const l=s.transform(a.value,o);if(l instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:n.value,value:l}}else return this._def.schema._parseAsync({data:i.data,path:i.path,parent:i}).then(a=>fv(a)?Promise.resolve(s.transform(a.value,o)).then(l=>({status:n.value,value:l})):an);Qn.assertNever(s)}}gv.create=(e,r,n)=>new gv({schema:e,typeName:ln.ZodEffects,effect:r,...Cn(n)});gv.createWithPreprocess=(e,r,n)=>new gv({schema:r,effect:{type:"preprocess",transform:e},typeName:ln.ZodEffects,...Cn(n)});class Lm extends qn{_parse(r){return this._getType(r)===kr.undefined?ju(void 0):this._def.innerType._parse(r)}unwrap(){return this._def.innerType}}Lm.create=(e,r)=>new Lm({innerType:e,typeName:ln.ZodOptional,...Cn(r)});class yv extends qn{_parse(r){return this._getType(r)===kr.null?ju(null):this._def.innerType._parse(r)}unwrap(){return this._def.innerType}}yv.create=(e,r)=>new yv({innerType:e,typeName:ln.ZodNullable,...Cn(r)});class U7 extends qn{_parse(r){const{ctx:n}=this._processInputParams(r);let i=n.data;return n.parsedType===kr.undefined&&(i=this._def.defaultValue()),this._def.innerType._parse({data:i,path:n.path,parent:n})}removeDefault(){return this._def.innerType}}U7.create=(e,r)=>new U7({innerType:e,typeName:ln.ZodDefault,defaultValue:typeof r.default=="function"?r.default:()=>r.default,...Cn(r)});class V7 extends qn{_parse(r){const{ctx:n}=this._processInputParams(r),i={...n,common:{...n.common,issues:[]}},s=this._def.innerType._parse({data:i.data,path:i.path,parent:{...i}});return w4(s)?s.then(o=>({status:"valid",value:o.status==="valid"?o.value:this._def.catchValue({get error(){return new Xf(i.common.issues)},input:i.data})})):{status:"valid",value:s.status==="valid"?s.value:this._def.catchValue({get error(){return new Xf(i.common.issues)},input:i.data})}}removeCatch(){return this._def.innerType}}V7.create=(e,r)=>new V7({innerType:e,typeName:ln.ZodCatch,catchValue:typeof r.catch=="function"?r.catch:()=>r.catch,...Cn(r)});class UV extends qn{_parse(r){if(this._getType(r)!==kr.nan){const i=this._getOrReturnCtx(r);return dr(i,{code:Vt.invalid_type,expected:kr.nan,received:i.parsedType}),an}return{status:"valid",value:r.data}}}UV.create=e=>new UV({typeName:ln.ZodNaN,...Cn(e)});class Opt extends qn{_parse(r){const{ctx:n}=this._processInputParams(r),i=n.data;return this._def.type._parse({data:i,path:n.path,parent:n})}unwrap(){return this._def.type}}class IP extends qn{_parse(r){const{status:n,ctx:i}=this._processInputParams(r);if(i.common.async)return(async()=>{const o=await this._def.in._parseAsync({data:i.data,path:i.path,parent:i});return o.status==="aborted"?an:o.status==="dirty"?(n.dirty(),y_(o.value)):this._def.out._parseAsync({data:o.value,path:i.path,parent:i})})();{const s=this._def.in._parseSync({data:i.data,path:i.path,parent:i});return s.status==="aborted"?an:s.status==="dirty"?(n.dirty(),{status:"dirty",value:s.value}):this._def.out._parseSync({data:s.value,path:i.path,parent:i})}}static create(r,n){return new IP({in:r,out:n,typeName:ln.ZodPipeline})}}class q7 extends qn{_parse(r){const n=this._def.innerType._parse(r),i=s=>(fv(s)&&(s.value=Object.freeze(s.value)),s);return w4(n)?n.then(s=>i(s)):i(n)}unwrap(){return this._def.innerType}}q7.create=(e,r)=>new q7({innerType:e,typeName:ln.ZodReadonly,...Cn(r)});var ln;(function(e){e.ZodString="ZodString",e.ZodNumber="ZodNumber",e.ZodNaN="ZodNaN",e.ZodBigInt="ZodBigInt",e.ZodBoolean="ZodBoolean",e.ZodDate="ZodDate",e.ZodSymbol="ZodSymbol",e.ZodUndefined="ZodUndefined",e.ZodNull="ZodNull",e.ZodAny="ZodAny",e.ZodUnknown="ZodUnknown",e.ZodNever="ZodNever",e.ZodVoid="ZodVoid",e.ZodArray="ZodArray",e.ZodObject="ZodObject",e.ZodUnion="ZodUnion",e.ZodDiscriminatedUnion="ZodDiscriminatedUnion",e.ZodIntersection="ZodIntersection",e.ZodTuple="ZodTuple",e.ZodRecord="ZodRecord",e.ZodMap="ZodMap",e.ZodSet="ZodSet",e.ZodFunction="ZodFunction",e.ZodLazy="ZodLazy",e.ZodLiteral="ZodLiteral",e.ZodEnum="ZodEnum",e.ZodEffects="ZodEffects",e.ZodNativeEnum="ZodNativeEnum",e.ZodOptional="ZodOptional",e.ZodNullable="ZodNullable",e.ZodDefault="ZodDefault",e.ZodCatch="ZodCatch",e.ZodPromise="ZodPromise",e.ZodBranded="ZodBranded",e.ZodPipeline="ZodPipeline",e.ZodReadonly="ZodReadonly"})(ln||(ln={}));const Si=Nm.create,v_=pv.create,y1=H7.create;qm.create;const Rpt=Nh.create,Zf=Bs.create;k4.create;C4.create;I0.create;const VS=mv.create;j4.create;Lm.create;yv.create;const Mpt=VS(ipt),Ppt=Zf({supportsStreaming:y1(),supportsInput:y1(),supportsSnapshot:y1(),supportsRecording:y1(),requiresConsent:y1(),maxConcurrent:v_().int().positive()});Zf({id:Si(),type:Mpt,status:VS(["connected","disconnected","error"]),capabilities:Ppt,deviceId:Si(),connectedAt:Si().nullable()});Zf({workspaceId:Si().optional(),name:Si().max(200).optional(),workspacePath:Si().optional()});Zf({id:Si(),workspaceId:Si().nullable(),name:Si().nullable(),workspacePath:Si().nullable(),status:VS(["active","archived","deleted"]),createdAt:Si(),lastActiveAt:Si(),metadata:Si().nullable()});const Lpt=VS(["pending","approved","executing","executed","completed","failed","reverted"]);Zf({action_id:Si(),status:Lpt,surface:Si(),device_id:Si().optional(),preview:Zf({command:Si().optional(),description:Si(),side_effects:Rpt(Si())}).optional(),consent_url:Si().url().optional(),expires_at:Si().datetime().optional()});Zf({id:Si(),role:VS(["user","assistant","system","tool"]),content:Si(),timestamp:Si().datetime(),sessionId:Si()});Zf({content:Si().min(1).max(1e5),sessionId:Si().uuid()});Zf({version:Si(),uptime:v_(),sessions:v_().int(),surfaces:v_().int(),devices:v_().int(),healthy:y1()});function $pt(e){let r=0;for(let n=0;n<e.length;n++)r=Math.imul(31,r)+e.charCodeAt(n)|0;return r}function Dpt(e){const r=e.title.trim(),n=e.body.trim();return!r&&!n?null:{...e,title:r||n,body:r?n:""}}async function G7(e){var s,o,a,l,d;const r=Dpt(e);if(!r)return;const n={level:"info",includeToast:!0,...r},i=(o=(s=window.Capacitor)==null?void 0:s.Plugins)==null?void 0:o.LocalNotifications;if((a=window.jaitDesktop)!=null&&a.notify)await window.jaitDesktop.notify({title:n.title,body:n.body});else if(i)try{const u=await((l=i.requestPermissions)==null?void 0:l.call(i));if((u==null?void 0:u.display)==="granted")await((d=i.schedule)==null?void 0:d.call(i,{notifications:[{id:Math.abs($pt(n.id)),title:n.title,body:n.body,schedule:{at:new Date}}]}));else throw new Error("notification permission denied")}catch{"Notification"in window&&(Notification.permission==="granted"?new Notification(n.title,{body:n.body,tag:n.id}):Notification.permission!=="denied"&&await Notification.requestPermission()==="granted"&&new Notification(n.title,{body:n.body,tag:n.id}))}else"Notification"in window&&(Notification.permission==="granted"?new Notification(n.title,{body:n.body,tag:n.id}):Notification.permission!=="denied"&&await Notification.requestPermission()==="granted"&&new Notification(n.title,{body:n.body,tag:n.id}));n.includeToast&&(n.level==="error"?fi.error:n.level==="warning"?fi.warning:n.level==="success"?fi.success:fi.info)(n.title,{description:n.body})}const Ipt=Y0();function VV(){const e=To(),r=navigator.userAgent;return e==="electron"?`Desktop (${navigator.platform})`:e==="capacitor"?"Mobile":r.includes("Chrome")?`Chrome (${navigator.platform})`:r.includes("Firefox")?`Firefox (${navigator.platform})`:r.includes("Safari")?`Safari (${navigator.platform})`:`Browser (${navigator.platform})`}function qV(){var r;const e=To();if(e==="capacitor")return"android";if(e==="electron"){const n=((r=navigator.platform)==null?void 0:r.toLowerCase())??"";return n.includes("win")?"windows":n.includes("mac")?"macos":"linux"}return"web"}function Bpt(){const e=To();return e==="electron"||e==="capacitor"}function zpt(e){const{listeners:r,sessionId:n,token:i,onStateSync:s,onFullState:o,onMessageComplete:a,onThreadEvent:l,onFsChanges:d,onConnectionStateChange:u,onPreviewSessionEvent:f}=e,p=y.useRef(r);p.current=r;const g=y.useRef(s);g.current=s;const v=y.useRef(o);v.current=o;const b=y.useRef(a);b.current=a;const _=y.useRef(l);_.current=l;const k=y.useRef(f);k.current=f;const w=y.useRef(d);w.current=d;const C=y.useRef(u);C.current=u;const j=y.useRef(null),N=y.useRef(null),A=y.useRef(!0),E=y.useRef(!1),R=y.useRef(i);R.current=i;const L=y.useRef(n);L.current=n;const z=y.useRef([]),$=y.useCallback(q=>{for(;z.current.length>0&&q.readyState===WebSocket.OPEN;){const ee=z.current.shift();q.send(ee)}},[]),W=y.useCallback((q,ee)=>{!ee||q.readyState!==WebSocket.OPEN||(q.send(JSON.stringify({type:"subscribe",sessionId:ee})),N.current=ee)},[]),B=y.useCallback(async q=>{await G7({id:q.id,title:q.title,body:q.body,level:q.level,includeToast:!0})},[]),K=y.useCallback(q=>{var ee,te,ue,fe,re;try{const ie=JSON.parse(q.data);if(ie.type==="ui.command"){const ge=ie.payload,le=p.current[ge.command];le&&le(ge.data)}else if(ie.type==="ui.state-sync"){const ge=ie.payload;ge!=null&&ge.key&&g.current&&g.current(ge.key,ge.value??null)}else if(ie.type==="ui.full-state"){const ge=ie.payload;ge&&v.current&&v.current(ge)}else if(ie.type==="message.complete")(ee=b.current)==null||ee.call(b);else if(ie.type==="fs.changes"){const ge=ie.payload;(te=w.current)==null||te.call(w,ge)}else if(ie.type==="fs.browse-request")P(ie.payload);else if(ie.type==="fs.roots-request")F(ie.payload);else if(ie.type==="fs.op-request")V(ie.payload);else if(ie.type==="provider.op-request")Y(ie.payload);else if(ie.type==="tool.op-request")H(ie.payload);else if(ie.type==="notification")B(ie.payload);else if(ie.type.startsWith("thread.")||ie.type.startsWith("repo.")||ie.type.startsWith("plan.")||ie.type.startsWith("fs.node-")||ie.type.startsWith("node."))(ue=_.current)==null||ue.call(_,ie.type,ie.payload);else if(ie.type==="preview.session"){const ge=(fe=ie.payload)==null?void 0:fe.session;ge&&((re=k.current)==null||re.call(k,ge))}}catch{}},[]),M=y.useCallback(async q=>{const ee="@capacitor/filesystem",{Filesystem:te,Directory:ue}=await import(ee);let fe,re=q;q==="~"||q==="/storage"||q==="/"?(fe=ue.ExternalStorage,re=""):q.startsWith("/storage/emulated/0")&&(fe=ue.ExternalStorage,re=q.replace("/storage/emulated/0","").replace(/^\//,""));const ie=await te.readdir({path:re||"",...fe?{directory:fe}:{}}),ge=fe===ue.ExternalStorage?"/storage/emulated/0"+(re?"/"+re:""):q,le=[];for(const De of ie.files)De.name.startsWith(".")||le.push({name:De.name,path:ge+"/"+De.name,type:De.type==="directory"?"dir":"file"});le.sort((De,de)=>De.type!==de.type?De.type==="dir"?-1:1:De.name.localeCompare(de.name));const et=ge.replace(/\/+$/,"").split("/"),Xe=et.length>3?et.slice(0,-1).join("/"):null;return{path:ge,parent:Xe,entries:le}},[]),I=y.useCallback(async()=>[{name:"Internal Storage",path:"/storage/emulated/0",type:"dir"},{name:"Documents",path:"/storage/emulated/0/Documents",type:"dir"},{name:"Downloads",path:"/storage/emulated/0/Download",type:"dir"},{name:"Home",path:"/storage/emulated/0",type:"dir"}],[]),P=y.useCallback(async q=>{var fe;const ee=j.current;if(!ee||ee.readyState!==WebSocket.OPEN)return;const{requestId:te,path:ue}=q;try{let re;const ie=To();if(ie==="electron"&&((fe=window.jaitDesktop)!=null&&fe.browsePath))re=await window.jaitDesktop.browsePath(ue);else if(ie==="capacitor")re=await M(ue);else throw new Error("Local filesystem browsing not supported on this platform");ee.send(JSON.stringify({type:"fs.browse-response",payload:{requestId:te,path:re.path,parent:re.parent,entries:re.entries}}))}catch(re){ee.send(JSON.stringify({type:"fs.browse-response",payload:{requestId:te,error:re instanceof Error?re.message:"Browse failed"}}))}},[M]),F=y.useCallback(async q=>{var ue;const ee=j.current;if(!ee||ee.readyState!==WebSocket.OPEN)return;const{requestId:te}=q;try{let fe;const re=To();if(re==="electron"&&((ue=window.jaitDesktop)!=null&&ue.getRoots))fe=(await window.jaitDesktop.getRoots()).roots;else if(re==="capacitor")fe=await I();else throw new Error("Local filesystem browsing not supported on this platform");ee.send(JSON.stringify({type:"fs.roots-response",payload:{requestId:te,roots:fe}}))}catch(fe){ee.send(JSON.stringify({type:"fs.roots-response",payload:{requestId:te,error:fe instanceof Error?fe.message:"Roots request failed"}}))}},[I]),V=y.useCallback(async q=>{var re;const ee=j.current;if(!ee||ee.readyState!==WebSocket.OPEN)return;const{requestId:te,op:ue,...fe}=q;try{const ie=To();if(ie==="electron"&&((re=window.jaitDesktop)!=null&&re.fsOp)){const ge=await window.jaitDesktop.fsOp(ue,fe);ee.send(JSON.stringify({type:"fs.op-response",payload:{requestId:te,result:ge}}))}else throw ie==="capacitor"?new Error("Full filesystem operations not yet supported on mobile"):new Error("Filesystem operations not supported on this platform")}catch(ie){ee.send(JSON.stringify({type:"fs.op-response",payload:{requestId:te,error:ie instanceof Error?ie.message:"Filesystem operation failed"}}))}},[]),Y=y.useCallback(async q=>{var re;const ee=j.current;if(!ee||ee.readyState!==WebSocket.OPEN)return;const{requestId:te,op:ue,...fe}=q;try{if(To()==="electron"&&((re=window.jaitDesktop)!=null&&re.providerOp)){const ge=await window.jaitDesktop.providerOp(ue,fe);ee.send(JSON.stringify({type:"provider.op-response",payload:{requestId:te,result:ge}}))}else throw new Error("Provider operations not supported on this platform")}catch(ie){ee.send(JSON.stringify({type:"provider.op-response",payload:{requestId:te,error:ie instanceof Error?ie.message:"Provider operation failed"}}))}},[]),H=y.useCallback(async q=>{var ge;const ee=j.current;if(!ee||ee.readyState!==WebSocket.OPEN)return;const{requestId:te,tool:ue,args:fe,sessionId:re,workspaceRoot:ie}=q;try{if(To()==="electron"&&((ge=window.jaitDesktop)!=null&&ge.toolOp)){const et=await window.jaitDesktop.toolOp(ue,fe,{sessionId:re,workspaceRoot:ie});ee.send(JSON.stringify({type:"tool.op-response",payload:{requestId:te,result:et}}))}else throw new Error("Tool execution not supported on this platform")}catch(le){ee.send(JSON.stringify({type:"tool.op-response",payload:{requestId:te,error:le instanceof Error?le.message:"Tool execution failed"}}))}},[]);y.useEffect(()=>{var ge;if(!i)return;A.current=!0;let q=null,ee=!1;const te=()=>{q&&(clearTimeout(q),q=null)},ue=()=>{const le=j.current;le&&(le.onclose=null,le.close(),j.current=null,N.current=null)},fe=()=>{if(!A.current||typeof document<"u"&&document.hidden)return;const le=new WebSocket(`${Ipt}?token=${R.current??"dev"}`);j.current=le,le.onopen=()=>{var De;const et=E.current;E.current=!0,(De=C.current)==null||De.call(C,{connected:!0,reconnected:et}),le.send(JSON.stringify({type:"resource.subscribe",payload:{resource:"root:/nodes"}})),le.send(JSON.stringify({type:"resource.subscribe",payload:{resource:"root:/threads"}})),le.send(JSON.stringify({type:"resource.subscribe",payload:{resource:"root:/surfaces"}})),le.send(JSON.stringify({type:"resource.subscribe",payload:{resource:"root:/browser"}}));const Xe=L.current;Xe&&W(le,Xe),$(le),Bpt()&&Dft().then(async de=>{var qe;let Qe=[];if(To()==="electron"&&((qe=window.jaitDesktop)!=null&&qe.detectProviders))try{Qe=await window.jaitDesktop.detectProviders()}catch{}const Ie=JSON.stringify({type:"node.hello",payload:{id:de,name:VV(),platform:qV(),role:To()==="electron"?"desktop":"mobile",protocolVersion:spt,capabilities:{providers:Qe,surfaces:["filesystem"],tools:[],screenShare:!0,voice:!1,preview:!1}}});le.readyState===WebSocket.OPEN&&le.send(Ie);const Oe=JSON.stringify({type:"fs.register-node",payload:{id:de,name:VV(),platform:qV(),providers:Qe}});le.readyState===WebSocket.OPEN&&le.send(Oe)})},le.onmessage=K,le.onclose=()=>{var et;j.current=null,N.current=null,(et=C.current)==null||et.call(C,{connected:!1,reconnected:!1}),A.current&&!ee&&(q=setTimeout(fe,1e3))},le.onerror=()=>{}},re=()=>{const le=typeof document<"u"&&document.hidden;if(ee=le,le){te(),ue();return}j.current||fe()};fe(),typeof document<"u"&&document.addEventListener("visibilitychange",re);const ie=(le,et)=>{if((et==null?void 0:et.type)==="provider.event-from-child"){const Xe=j.current;Xe&&Xe.readyState===WebSocket.OPEN&&Xe.send(JSON.stringify({type:"provider.event",payload:{sessionId:et.sessionId,event:et.notification}}))}};return To()==="electron"&&((ge=window.jaitDesktop)!=null&&ge.onGatewayEvent)&&window.jaitDesktop.onGatewayEvent(ie),()=>{var le;A.current=!1,te(),typeof document<"u"&&document.removeEventListener("visibilitychange",re),To()==="electron"&&((le=window.jaitDesktop)!=null&&le.removeGatewayEventListener)&&window.jaitDesktop.removeGatewayEventListener(),ue()}},[i]),y.useEffect(()=>{const q=j.current;q&&q.readyState===WebSocket.OPEN&&n!==N.current&&W(q,n??null),L.current=n??null},[n,W]);const U=y.useCallback((q,ee,te)=>{const ue=JSON.stringify({type:"ui.state",payload:{sessionId:te??"",key:q,value:ee}}),fe=j.current;fe&&fe.readyState===WebSocket.OPEN?fe.send(ue):z.current.push(ue)},[]),Q=y.useCallback((q,ee)=>{const te=JSON.stringify({type:"architecture.render-result",payload:{requestId:q,ok:ee.ok,...ee.ok?{}:{error:ee.error}}}),ue=j.current;ue&&ue.readyState===WebSocket.OPEN?ue.send(te):z.current.push(te)},[]);return{sendUIState:U,sendArchitectureRenderResult:Q}}const Fpt=$n();function Hpt(e){return{"Content-Type":"application/json",Authorization:`Bearer ${e}`}}const Uk=new Map;function iue(e,r,n,i){const s=`${e}:${r}`;let o=Uk.get(s);return o||(o={keys:new Set,callbacks:new Map,token:i},Uk.set(s,o),queueMicrotask(()=>{const a=Uk.get(s);if(!a)return;Uk.delete(s);const l=[...a.keys].join(",");fetch(`${Fpt}/api/${e}/${r}/state?keys=${encodeURIComponent(l)}`,{headers:Hpt(a.token)}).then(d=>d.ok?d.json():null).then(d=>{for(const[u,f]of a.callbacks){const p=(d==null?void 0:d[u])??null;for(const g of f)g.resolve(p)}}).catch(d=>{for(const u of a.callbacks.values())for(const f of u)f.reject(d)})})),o.keys.add(n),new Promise((a,l)=>{let d=o.callbacks.get(n);d||(d=[],o.callbacks.set(n,d)),d.push({resolve:a,reject:l})})}const Wpt=$n();function Upt(e){const r={"Content-Type":"application/json"};return e&&(r.Authorization=`Bearer ${e}`),r}function Vpt(e,r,n){return{method:"PATCH",headers:Upt(e),body:JSON.stringify({[r]:n})}}function qpt(e,r){return e===r}function Ju(e,r,n){const[i,s]=y.useState(null),[o,a]=y.useState(!1),l=y.useRef(null),d=y.useRef(null),u=y.useRef(0);y.useEffect(()=>{if(!e||!n){s(null);return}s(null),d.current=null;let p=!1;const g=u.current;return a(!0),iue("sessions",e,r,n).then(v=>{p||qpt(g,u.current)&&(s(v),d.current=v)}).catch(()=>{p||s(null)}).finally(()=>{p||a(!1)}),()=>{p=!0}},[e,r,n]);const f=y.useCallback(p=>{u.current+=1,s(p),d.current=p,!(!e||!n)&&(l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{fetch(`${Wpt}/api/sessions/${e}/state`,{...Vpt(n,r,d.current)}).catch(()=>{})},300))},[e,r,n]);return y.useEffect(()=>()=>{l.current&&clearTimeout(l.current)},[]),[i,f,o]}const Gpt=$n();function Kpt(e){const r={"Content-Type":"application/json"};return e&&(r.Authorization=`Bearer ${e}`),r}function Ypt(e,r,n,i){return{method:"PATCH",headers:Kpt(e),body:JSON.stringify({[r]:n}),keepalive:(i==null?void 0:i.immediate)===!0}}function Xpt(e,r,n){const[i,s]=y.useState(null),[o,a]=y.useState(!1),l=y.useRef(null),d=y.useRef(null);y.useEffect(()=>{if(!e||!n){s(null);return}s(null);let f=!1;return a(!0),iue("workspaces",e,r,n).then(p=>{if(f)return;const g=p;s(g),d.current=g}).catch(()=>{f||s(null)}).finally(()=>{f||a(!1)}),()=>{f=!0}},[e,r,n]);const u=y.useCallback((f,p)=>{if(s(f),d.current=f,!e||!n)return;l.current&&clearTimeout(l.current);const g=()=>{fetch(`${Gpt}/api/workspaces/${e}/state`,{...Ypt(n,r,d.current,p)}).catch(()=>{})};if(p!=null&&p.immediate){g();return}l.current=setTimeout(()=>{g()},300)},[e,r,n]);return y.useEffect(()=>()=>{l.current&&clearTimeout(l.current)},[]),[i,u,o]}const K7="jait:selected-repo-id";function Y7(e){if(e&&typeof e=="object"&&!Array.isArray(e)){const r=e;return{repoId:typeof r.repoId=="string"&&r.repoId.trim()?r.repoId.trim():null,localPath:typeof r.localPath=="string"&&r.localPath.trim()?r.localPath.trim():null}}return typeof e=="string"?{repoId:e.trim()||null,localPath:null}:{repoId:null,localPath:null}}function Zpt(e){try{return Y7(JSON.parse(e))}catch{}return Y7(e)}function BP(){var e;if(typeof window>"u")return{repoId:null,localPath:null};try{const r=(e=window.localStorage.getItem(K7))==null?void 0:e.trim();return r?Zpt(r):{repoId:null,localPath:null}}catch{return{repoId:null,localPath:null}}}function Jpt(){return BP().repoId}function Qpt(e,r){if(!(typeof window>"u"))try{e?window.localStorage.setItem(K7,JSON.stringify({repoId:e,localPath:(r==null?void 0:r.trim())||null})):window.localStorage.removeItem(K7)}catch{}}function sue(e,r=BP()){var n;return r.repoId&&e.some(i=>i.id===r.repoId)?r.repoId:r.localPath?((n=e.find(i=>i.localPath===r.localPath))==null?void 0:n.id)??null:null}function emt(e,r,n=BP()){var s;if(e.length===0)return r;const i=sue(e,n);return(!r||e.every(o=>o.id!==r))&&i?i:r?e.every(o=>o.id!==r)?((s=e[0])==null?void 0:s.id)??null:r:e[0].id}function Wb(e){return{id:e.id,name:e.name,defaultBranch:e.defaultBranch,localPath:e.localPath,deviceId:e.deviceId,forgeUrl:e.forgeUrl,githubUrl:e.githubUrl,source:"local"}}function N4(e){return e.replace(/\\/g,"/").replace(/\/+$/,"")}function tmt(e){const n=N4(e).split("/").filter(Boolean);return n[n.length-1]??e}function rmt(e){var n;const r=e.match(/^\[([^\]]+)\]/);return((n=r==null?void 0:r[1])==null?void 0:n.trim())||null}function oue(e){if(!e)return null;const n=N4(e).split("/").filter(Boolean),i=n.lastIndexOf("worktrees");return i===-1?null:n[i+1]??null}function v6(e){return rmt(e.title)??oue(e.workingDirectory)??(e.workingDirectory?tmt(e.workingDirectory):null)}function X7(e,r){var l,d;const n=r.name.trim().toLowerCase(),i=(l=v6(e))==null?void 0:l.toLowerCase(),s=e.workingDirectory?N4(e.workingDirectory):null,o=N4(r.localPath);if(s&&(s===o||s.startsWith(`${o}/`)))return!0;const a=(d=oue(e.workingDirectory))==null?void 0:d.toLowerCase();return a&&a===n?!0:i===n}function nmt(e,r){const n=[],i=new Set;for(const s of e){if(r.some(l=>X7(s,l)))continue;const o=v6(s),a=o==null?void 0:o.trim().toLowerCase();!o||!a||i.has(a)||(n.push({id:`shared:${a}`,name:o,defaultBranch:"main",localPath:s.workingDirectory??o,source:"shared"}),i.add(a))}return n}function imt(e){return e==="jait"||e==="codex"||e==="claude-code"?e:null}function smt(e){const r=new Set;for(const n of e){const i=imt(n);i&&r.add(i)}return[...r]}function omt(e,r){const{localDeviceId:n,localProviders:i,remoteProviders:s,providersLoaded:o}=r;if(!e.deviceId)return{hostType:"gateway",locationLabel:"Gateway",online:!0,loading:!1,availableProviders:i.filter(u=>u.available).map(u=>u.id)};const a=s.find(u=>u.nodeId===e.deviceId),l=e.deviceId===n?"This device":(a==null?void 0:a.nodeName)??"Desktop app",d=!!a;return{hostType:"device",locationLabel:l,online:d,loading:!d&&!o,availableProviders:smt((a==null?void 0:a.providers)??[])}}function GV(e,r){return e.githubUrl?`Couldn't reach ${r.locationLabel}.`:r.hostType==="device"&&!r.online?`${r.locationLabel==="This device"?"This desktop app":r.locationLabel} is offline and no GitHub URL is configured for gateway fallback. Reconnect it or pick a connected repo/device.`:"No GitHub URL is configured for this repo, so the gateway cannot clone it as a fallback."}function amt(e,r){return e!=null&&e.state?e.state:r==="creating"||r==="open"||r==="closed"||r==="merged"?r:null}const f8=10;function lmt(e){const n=e.replace(/\\/g,"/").split("/").filter(Boolean);return n[n.length-1]??e}function cmt(){return`jait/${Math.random().toString(16).slice(2,10)}`}function Z7(e){return[...e].sort((r,n)=>new Date(r.createdAt).getTime()-new Date(n.createdAt).getTime())}function umt(e,r){if(r.length===0)return e;const n=new Map(e.map(i=>[i.id,i]));for(const i of r)n.set(i.id,i);return Z7([...n.values()])}function KV(e){for(let r=e.length-1;r>=0;r--){const n=e[r];if(n.kind==="todo"&&n.payload&&typeof n.payload=="object"&&"items"in n.payload)return n.payload.items}return[]}function Ub(e){return e.filter(r=>r.role!=="gateway").map(r=>({nodeId:r.id,nodeName:r.name,platform:r.platform,providers:r.capabilities.providers}))}function dmt(e=!0){const r=U0(),n=y.useMemo(()=>LP(),[]),[i,s]=y.useState([]),[o,a]=y.useState(()=>Jpt()),[l,d]=y.useState(!1),[u,f]=y.useState([]),[p,g]=y.useState(f8),[v,b]=y.useState(!1),[_,k]=y.useState(null),[w,C]=y.useState([]),[j,N]=y.useState({}),[A,E]=y.useState(!0),[R,L]=y.useState([]),[z,$]=y.useState([]),[W,B]=y.useState([]),[K,M]=y.useState(!1),[I,P]=y.useState(!1),[F,V]=y.useState(!1),[Y,H]=y.useState(null),U=y.useRef(new Map),[Q,q]=y.useState([]),ee=y.useRef(null),te=y.useRef(new Map),ue=y.useRef(new Set),fe=y.useMemo(()=>nmt(u,i),[u,i]),re=y.useMemo(()=>[...i,...fe],[i,fe]),ie=y.useMemo(()=>re.find(at=>at.id===o)??null,[re,o]),ge=y.useMemo(()=>u.find(at=>at.id===_)??null,[u,_]),le=ge?ge.id in j?j[ge.id]:ge.prState:null,et=y.useCallback(at=>re.find(ut=>X7(at,ut))??null,[re]),Xe=y.useMemo(()=>ge!=null&&ge.kind==="delivery"&&ie!=null&&(ge.status==="completed"||!!ge.prUrl||le==="creating"||le==="open"),[ge,ie,le]);y.useEffect(()=>{if(!e)return;const at=emt(re,o);at!==o&&a(at)},[re,o,e]),y.useEffect(()=>{e&&Qpt(o,(ie==null?void 0:ie.localPath)??null)},[e,o,ie]),y.useEffect(()=>{if(!e||!ge)return;const at=et(ge);at&&at.id!==o&&a(at.id)},[e,et,o,ge]);const De=y.useCallback(async()=>{if(h0()){M(!0);try{const[at,ut,Ht]=await Promise.all([Yr.listThreadsPage({limit:p}),Yr.listProviders(),Yr.listRepos()]);f(at.threads),b(at.hasMore),L(ut.providers),$(W.length>0?Ub(W):ut.remoteProviders),P(!0),s(Ht.map(Wb)),H(null)}catch(at){H(at instanceof Error?at.message:"Failed to fetch data")}finally{M(!1)}}},[p]),de=y.useCallback(async()=>{if(h0())try{const[at,ut]=await Promise.all([Yr.listProvidersFresh(),Yr.listRepos()]);L(at.providers),$(W.length>0?Ub(W):at.remoteProviders),s(ut.map(Wb))}catch{}},[W]),Qe=y.useCallback(at=>omt(at,{localDeviceId:n,localProviders:R,remoteProviders:z,providersLoaded:I}),[n,R,z,I]);y.useEffect(()=>{e&&De()},[De,e]);const Ie=y.useRef(_);Ie.current=_;const Oe=y.useCallback((at,ut)=>{var Ht;switch(at){case"thread.created":{const Fe=ut.thread;Fe&&f(Ye=>Ye.some(Pt=>Pt.id===Fe.id)?Ye:[Fe,...Ye]);break}case"thread.updated":{const Fe=ut;if(Array.isArray(Fe==null?void 0:Fe.threads)){f(Fe.threads);break}const Ye=ut.thread;Ye&&f(Pt=>Pt.map(ot=>ot.id===Ye.id?Ye:ot));break}case"thread.deleted":{const Fe=ut.threadId;Fe&&(te.current.delete(Fe),f(Ye=>Ye.filter(Pt=>Pt.id!==Fe)),Ie.current===Fe&&k(null));break}case"thread.status":{const Fe=ut.threadId,Ye=ut.status,Pt=ut.thread;Fe&&Ye&&f(ot=>Pt?ot.some(tt=>tt.id===Fe)?ot.map(tt=>tt.id===Fe?Pt:tt):[Pt,...ot]:ot.map(Yt=>Yt.id===Fe?{...Yt,status:Ye,error:Ye==="running"||Ye==="completed"?ut.error??null:ut.error??Yt.error}:Yt));break}case"thread.activity":{const Fe=ut.threadId,Ye=ut.activity;if(Fe&&Ye){const Pt=umt(te.current.get(Fe)??[],[Ye]);if(te.current.set(Fe,Pt),Fe===Ie.current&&C(Pt),Ye.kind==="todo"&&Ye.payload&&typeof Ye.payload=="object"&&"items"in Ye.payload){const ot=Ye.payload.items;U.current.set(Fe,ot),Fe===Ie.current&&q(ot)}}break}case"repo.created":{const Fe=ut.repo;Fe&&s(Ye=>Ye.some(Pt=>Pt.id===Fe.id)?Ye:[Wb(Fe),...Ye]);break}case"repo.updated":{const Fe=ut.repo;Fe&&s(Ye=>Ye.map(Pt=>Pt.id===Fe.id?Wb(Fe):Pt));break}case"repo.deleted":{const Fe=ut.repoId;Fe&&(s(Ye=>Ye.filter(Pt=>Pt.id!==Fe)),a(Ye=>Ye===Fe?null:Ye));break}case"fs.node-registered":case"fs.node-disconnected":{de();break}case"node.registry":{const Fe=ut,Ye=(Fe==null?void 0:Fe.nodes)??[];B(Ye),$(Ub(Ye)),P(!0);break}case"node.updated":{const Fe=ut;if(!Fe)break;B(Ye=>{const Pt=Ye.some(ot=>ot.id===Fe.id)?Ye.map(ot=>ot.id===Fe.id?Fe:ot):[...Ye,Fe];return $(Ub(Pt)),Pt}),P(!0);break}case"node.disconnected":{const Fe=ut.nodeId??((Ht=ut.node)==null?void 0:Ht.id);if(!Fe)break;B(Ye=>{const Pt=Ye.filter(ot=>ot.id!==Fe);return $(Ub(Pt)),Pt}),P(!0);break}}},[]);y.useEffect(()=>{if(!e||!_){C([]),q([]),V(!1);return}const at=te.current.get(_);at?(C(at),q(U.current.get(_)??KV(at)),V(!1)):(C([]),q([]),V(!0));let ut=!1;return(async()=>{if(h0())try{const Fe=await Yr.getActivities(_);if(!ut){const Ye=Z7(Fe);te.current.set(_,Ye),C(Ye);const Pt=KV(Ye);U.current.set(_,Pt),q(Pt)}}catch{}finally{ut||V(!1)}})(),()=>{ut=!0}},[_,e]);const qe=y.useCallback(async at=>{if(!ue.current.has(at)){ue.current.add(at);try{const[ut,Ht]=await Promise.all([Yr.getThread(at).catch(()=>null),Yr.getActivities(at).catch(()=>[])]);ut&&f(Ye=>Ye.some(ot=>ot.id===ut.id)?Ye.map(ot=>ot.id===ut.id?ut:ot):[ut,...Ye]);const Fe=Z7(Ht);te.current.set(at,Fe),at===Ie.current&&C(Fe)}finally{ue.current.delete(at)}}},[]);y.useEffect(()=>{var at;e&&((at=ee.current)==null||at.scrollIntoView({behavior:"smooth"}))},[w,e]);const kt=y.useMemo(()=>ie?u.filter(at=>X7(at,ie)).sort((at,ut)=>new Date(ut.updatedAt).getTime()-new Date(at.updatedAt).getTime()):[],[u,ie]),vt=y.useRef(0),Me=10;y.useEffect(()=>{if(!e||!ie){N({});return}const at=++vt.current,ut=ie.localPath,Ht=kt.filter(Pt=>Pt.kind==="delivery"&&typeof Pt.branch=="string"&&Pt.branch.length>0).slice(0,Me),Fe=async()=>{if(Ht.length===0){at===vt.current&&N({});return}const Pt=Ht.filter(Ge=>Ge.prState!=="merged"&&Ge.prState!=="closed"),ot=[];for(const Ge of Pt){if(at!==vt.current)return;try{const It=Ge.workingDirectory??ut,jt=await io.status(It,Ge.branch??void 0),Se=amt(jt.pr,Ge.prState);if(jt.ghAvailable&&jt.pr&&(Ge.prUrl!==jt.pr.url||Ge.prState!==jt.pr.state||Ge.prNumber!==jt.pr.number||Ge.prBaseBranch!==(jt.pr.baseBranch??null)))try{await Yr.updateThread(Ge.id,{prUrl:jt.pr.url,prNumber:jt.pr.number,prTitle:jt.pr.title??null,prBaseBranch:jt.pr.baseBranch??null,prState:jt.pr.state})}catch{}ot.push({threadId:Ge.id,prState:Se,ghAvailable:jt.ghAvailable})}catch{}}if(at!==vt.current)return;const Yt={};let tt=!1;for(const Ge of ot)Yt[Ge.threadId]=Ge.prState,Ge.ghAvailable&&(tt=!0);for(const Ge of Ht)!(Ge.id in Yt)&&(Ge.prState==="merged"||Ge.prState==="closed")&&(Yt[Ge.id]=Ge.prState);E(tt),N(Yt)};Fe();const Ye=setInterval(()=>{vt.current===at&&Fe()},6e4);return()=>clearInterval(Ye)},[e,kt,ie]);const nt=y.useCallback(async(at,ut)=>{const Ht=ut&&ut!=="gateway"?ut:void 0,Fe=i.find(ot=>ot.localPath===at);if(Fe){a(Fe.id);const ot={},Yt=Ht??"";if((Fe.deviceId??"")!==Yt&&(ot.deviceId=Yt),!Fe.githubUrl)try{const tt=await io.status(at);tt.remoteUrl&&(ot.githubUrl=tt.remoteUrl)}catch{}if(Object.keys(ot).length>0)try{await Yr.updateRepo(Fe.id,ot)}catch{}return}let Ye="main",Pt;try{const ot=await io.status(at);ot.branch&&(Ye=ot.branch),ot.remoteUrl&&(Pt=ot.remoteUrl)}catch{}try{const ot=await Yr.createRepo({name:lmt(at),defaultBranch:Ye,localPath:at,deviceId:Ht,githubUrl:Pt}),Yt=Wb(ot);s(tt=>tt.some(Ge=>Ge.id===Yt.id)?tt:[Yt,...tt]),a(Yt.id),H(null)}catch(ot){H(ot instanceof Error?ot.message:"Failed to create repository")}},[i]),Je=y.useCallback(async at=>{try{await Yr.deleteRepo(at)}catch{}s(ut=>ut.filter(Ht=>Ht.id!==at)),o===at&&a(null)},[o]),Ot=y.useCallback(async(at,ut,Ht="jait",Fe="full-access",Ye,Pt={})=>{if(!ut.trim())return;const ot=at?u.find(tt=>tt.id===at)??null:ge,Yt=ot?et(ot):ie;if(ot&&ot.providerSessionId&&ot.status!=="running")f(tt=>tt.map(Ge=>Ge.id===ot.id?{...Ge,status:"running",error:null,completedAt:null}:Ge)),await Yr.sendTurn(ot.id,{message:ut,...Pt}),qe(ot.id),De();else{if(ot&&ot.status==="running")return;if(ot&&(ot.status==="idle"||ot.status==="completed"||ot.status==="error"||ot.status==="interrupted"))try{f(Ge=>Ge.map(It=>It.id===ot.id?{...It,status:"running",error:null,completedAt:null}:It));const tt=await Yr.startThread(ot.id,{message:ut,...Pt});f(Ge=>Ge.map(It=>It.id===tt.id?tt:It)),qe(tt.id),De()}catch(tt){if(tt.code==="NODE_OFFLINE"&&Yt){const It=Yt.githubUrl;if(It&&await r({title:"Run on gateway instead?",description:"The desktop app is not connected. Clone the repo to the gateway and run the thread there?",confirmLabel:"Clone and run"})){const jt=await Yr.startThread(ot.id,{message:ut,cloneToGateway:!0,repoUrl:It,...Pt});f(Se=>Se.map($t=>$t.id===jt.id?jt:$t)),qe(jt.id),De()}else It||H(GV(Yt,Qe(Yt)))}else throw tt}else{if(!Yt)return;at||k(null);const tt=Yt;(async()=>{var Ge,It;try{const jt=cmt();let Se;try{Se=(await io.createWorktree(tt.localPath,tt.defaultBranch,jt)).path}catch{try{await io.createBranch(tt.localPath,jt,tt.defaultBranch)}catch{}}const $t=await Yr.createThread({title:`[${tt.name}] Generating title…`,providerId:Ht,runtimeMode:Fe,...Ye?{model:Ye}:{},kind:"delivery",workingDirectory:Se??tt.localPath,branch:jt});try{await Yr.startThread($t.id,{message:ut,titleTask:((Ge=Pt.displayContent)==null?void 0:Ge.trim())||ut,titlePrefix:`[${tt.name}] `,...Pt}),qe($t.id)}catch(Et){if(Et.code==="NODE_OFFLINE"){const mr=tt.githubUrl;mr&&await r({title:"Run on gateway instead?",description:"The desktop app is not connected. Clone the repo to the gateway and run the thread there?",confirmLabel:"Clone and run"})?(await Yr.startThread($t.id,{message:ut,titleTask:((It=Pt.displayContent)==null?void 0:It.trim())||ut,titlePrefix:`[${tt.name}] `,cloneToGateway:!0,repoUrl:mr,...Pt}),qe($t.id)):mr||H(GV(tt,Qe(tt)));return}throw Et}}catch(jt){H(jt instanceof Error?jt.message:"Failed to create thread")}})()}}},[r,Qe,et,qe,De,ie,ge,u]),be=y.useCallback(async(at,ut="jait",Ht="full-access",Fe,Ye)=>{await Ot((ge==null?void 0:ge.id)??null,at,ut,Ht,Fe,Ye)},[ge==null?void 0:ge.id,Ot]),Re=y.useCallback(async(at,ut,Ht="jait",Fe="full-access",Ye,Pt)=>{await Ot(at,ut,Ht,Fe,Ye,Pt)},[Ot]),ke=y.useCallback(async at=>{try{await Yr.stopThread(at),De()}catch(ut){H(ut instanceof Error?ut.message:"Failed to stop thread")}},[De]),$e=y.useCallback(async at=>{try{await Yr.deleteThread(at),f(ut=>ut.filter(Ht=>Ht.id!==at)),_===at&&k(null)}catch(ut){H(ut instanceof Error?ut.message:"Failed to delete thread")}},[_]),ct=y.useCallback(()=>{M(!0),g(at=>at+f8)},[]),gt=y.useCallback(()=>{g(f8)},[]);return{repositories:re,selectedRepoId:o,setSelectedRepoId:a,selectedRepo:ie,folderPickerOpen:l,setFolderPickerOpen:d,handleFolderSelected:nt,removeRepository:Je,threads:u,hasMoreThreads:v,threadListLimit:p,showMoreThreads:ct,showFewerThreads:gt,repoThreads:kt,selectedThreadId:_,setSelectedThreadId:k,selectedThread:ge,getRepositoryForThread:et,threadPrStates:j,ghAvailable:A,activities:w,loadingActivities:F,activityEndRef:ee,selectedThreadTodos:Q,providers:R,remoteProviders:z,loading:K,error:Y,setError:H,creating:!1,showGitActions:Xe,getRuntimeInfoForRepository:Qe,refresh:De,handleSend:be,handleSendToThread:Re,handleStop:ke,handleDelete:$e,handleThreadEvent:Oe}}const YV=[{value:"developer",label:"Developer",icon:Gb,description:"Chat with the AI assistant — ask, plan, and execute"},{value:"manager",label:"Manager",icon:P8,description:"Automation — delegate tasks to agent threads on repos"}];function hmt({mode:e,onChange:r,disabled:n,className:i,compact:s=!1}){const o=YV.findIndex(l=>l.value===e),a=o>=0?o:0;return c.jsxs("div",{role:"tablist","aria-label":"View mode",className:We("relative inline-grid h-8 grid-cols-2 rounded-lg bg-muted/40 p-0.5",s?"border-0":"border border-border/70","shadow-sm transition-colors",n&&"pointer-events-none opacity-50",i),children:[c.jsx("div",{"aria-hidden":"true",className:We("absolute inset-y-0.5 left-0.5 w-[calc(50%-2px)] rounded-md bg-background shadow-sm","transition-transform duration-200 ease-out"),style:{transform:`translateX(${a*100}%)`}}),YV.map(l=>{const d=l.icon,u=e===l.value;return c.jsxs("button",{type:"button",role:"tab","aria-selected":u,"aria-label":l.label,title:`${l.label}: ${l.description}`,disabled:n,onClick:()=>r(l.value),className:We("relative z-10 flex min-w-0 items-center justify-center gap-1.5 rounded-md px-2 text-xs font-medium","transition-colors duration-200 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",u?"text-foreground":"text-muted-foreground hover:text-foreground",s?"w-9":"min-w-[5.75rem]"),children:[c.jsx(d,{className:"h-3.5 w-3.5 shrink-0"}),!s&&c.jsx("span",{children:l.label})]},l.value)})]})}const fmt=8e3,pmt=["hey jait","jait","hey jade","jade","hey jayit","jayit","hey gate","gate","hey jate","jate","hey jay","jay","hey date","date","hey jake","jake","hey jet","jet","hey jayt","jayt","hey jayed","jayed","hey jaid","jaid","hey jayett","jayett","hey jit","jit","hey jai","jai","hey dschaid","dschaid","hey tscheit","tscheit","hey dscheit","dscheit","hey tschait","tschait","hey jeid","jeid","hey jäd","jäd","hey tschäd","tschäd","hey scheide","hey scheid","hey jäit","jäit"];function aue(e){const r=e.toLowerCase().replace(/^(hey|hej|he)\s+/,"").replace(/[^a-zäöüß]/g,"").trim();return r.length<2||r.length>8?!1:!!(["jait","jade","jate","gate","jay","jai","jet","jake","jayed","jaid","jayit","jayt","jayett","jit","dschaid","tscheit","dscheit","tschait","jeid","jäd","tschäd","jäit","scheid","scheide"].includes(r)||/^(j|g|dj|dsch|tsch|sch)/.test(r)&&/(t|d|te|de|ed)$/.test(r))}function mmt(e){const{enabled:r,lang:n,wakePhrases:i,onCommand:s,onWakeWordDetected:o,onListeningTimeout:a}=e,[l,d]=y.useState(!1),[u,f]=y.useState(!1),[p,g]=y.useState(""),v=y.useRef(null),b=y.useRef(!1),_=y.useRef(null),k=y.useRef(r),w=y.useRef(!1),C=y.useRef(s);C.current=s;const j=y.useRef(o);j.current=o;const N=y.useRef(a);N.current=a,k.current=r;const A=i??pmt,E=y.useRef(A);E.current=A;const R=typeof window<"u"&&("SpeechRecognition"in window||"webkitSpeechRecognition"in window),L=y.useCallback(()=>{_.current&&(clearTimeout(_.current),_.current=null)},[]),z=y.useCallback(()=>{b.current=!1,f(!1),g(""),L()},[L]),$=y.useCallback(()=>{b.current=!0,f(!0),g(""),L(),_.current=setTimeout(()=>{var W;b.current&&(z(),(W=N.current)==null||W.call(N))},fmt)},[L,z]);return y.useEffect(()=>{if(!r||!R){v.current&&(w.current=!0,v.current.abort(),v.current=null,d(!1),z());return}const W=window.SpeechRecognition??window.webkitSpeechRecognition;if(!W)return;const B=new W;B.continuous=!0,B.interimResults=!0,B.maxAlternatives=1,B.lang=n??navigator.language??"en-US",v.current=B,w.current=!1,B.onstart=()=>{console.debug('[useWakeWord] SpeechRecognition started — say "Hey Jait" to activate'),d(!0)},B.onresult=K=>{var M,I,P;for(let F=K.resultIndex;F<K.results.length;F++){const V=K.results[F],Y=((I=(M=V[0])==null?void 0:M.transcript)==null?void 0:I.trim())??"",H=V.isFinal;if(Y&&console.debug(`[useWakeWord] ${H?"FINAL":"interim"}: "${Y}"`),b.current)if(H&&Y){const U=XV(Y,E.current);U&&C.current(U),z()}else g(Y);else{const U=Y.toLowerCase(),Q=E.current.some(te=>U.includes(te.toLowerCase())),q=!Q&&Y.split(/\s+/).some(te=>aue(te)),ee=Q||q;if(ee&&H){console.debug(`[useWakeWord] Wake word DETECTED in: "${Y}"`);const te=XV(Y,E.current);(P=j.current)==null||P.call(j),te?C.current(te):$()}else ee&&g(Y)}}},B.onerror=K=>{if(!(K.error==="no-speech"||K.error==="aborted")){if(K.error==="not-allowed"){console.warn("[useWakeWord] Microphone permission denied — disabling wake word"),w.current=!0;return}console.warn("[useWakeWord] SpeechRecognition error:",K.error)}},B.onend=()=>{d(!1),k.current&&!w.current&&setTimeout(()=>{if(!(!k.current||w.current))try{B.start()}catch{}},300)};try{B.start()}catch{}return()=>{w.current=!0,B.abort(),v.current=null,d(!1),z()}},[r,R,n,$,z]),{isRunning:l,isListening:u,isSupported:R,interimTranscript:p}}function XV(e,r){var a,l;let n=e.trim();const i=n.toLowerCase(),s=[...r].sort((d,u)=>u.length-d.length);let o=!1;for(const d of s){const u=i.indexOf(d.toLowerCase());if(u!==-1){n=(n.slice(0,u)+n.slice(u+d.length)).trim(),o=!0;break}}if(!o){const d=n.split(/\s+/);let u=0;(((a=d[0])==null?void 0:a.toLowerCase())==="hey"||((l=d[0])==null?void 0:l.toLowerCase())==="hej")&&(u=1),d[u]&&aue(d[u])&&(n=d.slice(u+1).join(" "))}return n.replace(/^[,;:!?\s]+/,"").trim()}const Vk=24e3,gmt=`${window.location.protocol}//${window.location.hostname}:${window.location.port}`;function ymt(){return`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}`}function vmt(e){const r=new Int16Array(e.length);for(let n=0;n<e.length;n++){const i=Math.max(-1,Math.min(1,e[n]));r[n]=i<0?i*32768:i*32767}return r.buffer}function xmt(e){const r=new Int16Array(e),n=new Float32Array(r.length);for(let i=0;i<r.length;i++)n[i]=r[i]/32768;return n}function ZV(e){const r=new Uint8Array(e),n=32768,i=[];for(let s=0;s<r.length;s+=n)i.push(String.fromCharCode.apply(null,r.subarray(s,s+n)));return btoa(i.join(""))}function bmt(e){const r=atob(e),n=r.length,i=new Uint8Array(n);for(let s=0;s<n;s++)i[s]=r.charCodeAt(s);return i.buffer}const _mt=`
|
|
1268
|
+
`);Je=Re.pop()||"";for(const ke of Re)if(ke.startsWith("data: "))try{const $e=JSON.parse(ke.slice(6));$e.type==="plan_action_start"?l(ct=>ct?{...ct,actions:ct.actions.map(gt=>gt.id===$e.action_id?{...gt,status:"approved"}:gt)}:null):$e.type==="plan_action_result"?l(ct=>ct?{...ct,actions:ct.actions.map(gt=>gt.id===$e.action_id?{...gt,status:$e.ok?"executed":"failed",result:{ok:$e.ok,message:$e.message,data:$e.data}}:gt)}:null):$e.type==="plan_execution_complete"&&setTimeout(()=>l(null),2e3)}catch{}}}catch(vt){o(Me=>({...Me,error:vt instanceof Error?vt.message:"Plan execution failed"}))}},[r,a]),Xe=y.useCallback(async()=>{const Ie=A.current;if(!Ie||!a)return;const Oe={"Content-Type":"application/json"};r&&(Oe.Authorization=`Bearer ${r}`);try{await fetch(`${Zu}/api/sessions/${Ie}/plan/reject`,{method:"POST",headers:Oe}),l(null)}catch{l(null)}},[r,a]),De=y.useCallback((Ie,Oe)=>{p(qe=>qe.some(kt=>kt.path===Ie)?qe:[...qe,{path:Ie,name:Oe,state:"undecided"}])},[]),de=!!(e&&e!==A.current),Qe=s.isLoadingHistory||de;return{messages:de?[]:s.messages,isLoading:s.isLoading,isLoadingHistory:Qe,remainingPrompts:s.remainingPrompts,error:s.error,hitMaxRounds:s.hitMaxRounds,pendingPlan:a,todoList:d,changedFiles:f,messageQueue:g,completionCount:b,contextUsage:k,sessionInfo:C,sendMessage:I,restartFromMessage:le,cancelRequest:re,clearMessages:ie,continueChat:ge,executePlan:et,rejectPlan:Xe,enqueueMessage:P,dequeueMessage:F,updateQueueItem:V,reorderQueueItem:Y,setMessageQueueState:H,acceptFile:ee,rejectFile:te,acceptAllFiles:ue,rejectAllFiles:fe,setTodoList:u,addChangedFile:De,setChangedFiles:p,setOnChangedFilesSync:Q,refreshMessages:M}}function rpt(){const[e,r]=y.useState(null),[n,i]=y.useState(null),[s,o]=y.useState(null),[a,l]=y.useState(!0);return y.useEffect(()=>{let d=!1;return fetch(`${$n()}/health`).then(u=>u.json()).then(u=>{d||(r(u.provider??null),i(u.model??null),o(u.ollamaUrl??null))}).catch(()=>{}).finally(()=>{d||l(!1)}),()=>{d=!0}},[]),{provider:e,model:n,ollamaUrl:s,loading:a}}const rl=$n(),Hk=10;function Dl(e){return e?{Authorization:`Bearer ${e}`}:{}}function npt(e,r){const[n,i]=y.useState([]),[s,o]=y.useState([]),[a,l]=y.useState({}),[d,u]=y.useState(null),[f,p]=y.useState(null),[g,v]=y.useState(Hk),[b,_]=y.useState(!1),[k,w]=y.useState(!0),C=y.useMemo(()=>n.find(Y=>Y.id===d)??null,[n,d]),j=y.useCallback(async()=>{if(!e){i([]),o([]),l({}),u(null),p(null),_(!1);return}w(!0);try{const[Y,H,U]=await Promise.all([fetch(`${rl}/api/workspaces?status=active&limit=${g}`,{headers:Dl(e)}),fetch(`${rl}/api/sessions?status=active&limit=100`,{headers:Dl(e)}),fetch(`${rl}/api/workspaces/last-active`,{headers:Dl(e)})]);(Y.status===401||H.status===401||U.status===401)&&(r==null||r());let Q=[],q=[];if(Y.ok){const ee=await Y.json();Q=ee.workspaces,i(Q),l(te=>Object.fromEntries(Object.entries(te).filter(([ue])=>Q.some(fe=>fe.id===ue)))),_(!!ee.hasMore)}if(H.ok&&(q=(await H.json()).sessions.filter(te=>!te.workspaceId),o(q)),U.ok){const ee=await U.json();u(te=>{var ue,fe;return te&&Q.some(re=>re.id===te)?te:ee.session&&!ee.session.workspaceId?null:((ue=ee.workspace)==null?void 0:ue.id)??((fe=Q[0])==null?void 0:fe.id)??null}),p(te=>{var ue,fe,re,ie;return te&&Q.some(ge=>ge.sessions.some(le=>le.id===te))||te&&q.some(ge=>ge.id===te)?te:((ue=ee.session)==null?void 0:ue.id)??((fe=q[0])==null?void 0:fe.id)??((ie=(re=Q[0])==null?void 0:re.sessions[0])==null?void 0:ie.id)??null})}}catch(Y){console.error("Failed to fetch workspaces:",Y)}finally{w(!1)}},[r,e,g]),N=y.useCallback(async(Y={})=>{if(!e)return r==null||r(),null;try{const H=await fetch(`${rl}/api/workspaces`,{method:"POST",headers:{...Dl(e),"Content-Type":"application/json"},body:JSON.stringify({title:Y.title,rootPath:Y.rootPath,nodeId:Y.nodeId})});if(H.status===401)return r==null||r(),null;if(!H.ok)return null;const U=await H.json();let Q;return i(q=>{const ee=q.find(ue=>ue.id===U.id);Q={...U,sessions:U.sessions??(ee==null?void 0:ee.sessions)??[]};const te=q.filter(ue=>ue.id!==Q.id);return[Q,...te].slice(0,g)}),u(Q.id),p(null),Q}catch(H){return console.error("Failed to create workspace:",H),null}},[r,e,g]),A=y.useCallback(async(Y,H)=>{if(!e)return r==null||r(),null;const U=Y===void 0?d:Y;try{const Q=U?`${rl}/api/workspaces/${U}/sessions`:`${rl}/api/sessions`,q=await fetch(Q,{method:"POST",headers:{...Dl(e),"Content-Type":"application/json"},body:JSON.stringify({name:H})});if(q.status===401)return r==null||r(),null;if(!q.ok)return null;const ee=await q.json();return U?i(te=>te.map(ue=>ue.id===U?{...ue,lastActiveAt:ee.lastActiveAt,sessions:[ee,...ue.sessions]}:ue)):o(te=>[ee,...te.filter(ue=>ue.id!==ee.id)]),u(U??null),p(ee.id),ee}catch(Q){return console.error("Failed to create session:",Q),null}},[d,r,e]),E=y.useCallback((Y,H)=>{e&&fetch(`${rl}/api/workspaces/select`,{method:"POST",headers:{...Dl(e),"Content-Type":"application/json"},body:JSON.stringify({workspaceId:Y,sessionId:H})}).catch(()=>{})},[e]),R=y.useCallback(Y=>{u(Y),p(H=>{var q;const U=n.find(ee=>ee.id===Y);if(!U)return null;if(H&&U.sessions.some(ee=>ee.id===H))return H;const Q=((q=U.sessions[0])==null?void 0:q.id)??null;return E(Y,Q??H),Q})},[E,n]),L=y.useCallback((Y,H)=>{u(Y),p(H),E(Y,H)},[E]),z=y.useCallback(async Y=>{if(!e){r==null||r();return}try{if((await fetch(`${rl}/api/sessions/${Y}/archive`,{method:"POST",headers:Dl(e)})).status===401){r==null||r();return}await j()}catch(H){console.error("Failed to archive session:",H)}},[j,r,e]),$=y.useCallback(async Y=>{if(!e)return r==null||r(),[];try{const H=await fetch(`${rl}/api/workspaces/${Y}/sessions?status=archived`,{headers:Dl(e)});if(H.status===401)return r==null||r(),[];if(!H.ok)return[];const U=await H.json();return l(Q=>({...Q,[Y]:U.sessions})),U.sessions}catch(H){return console.error("Failed to fetch archived sessions:",H),[]}},[r,e]),W=y.useCallback(async(Y,H)=>{if(!e)return r==null||r(),null;try{const U=await fetch(`${rl}/api/workspaces/${Y}`,{method:"PATCH",headers:{...Dl(e),"Content-Type":"application/json"},body:JSON.stringify(H)});if(U.status===401)return r==null||r(),null;if(!U.ok)return null;const Q=await U.json(),q={...Q,sessions:Q.sessions??[]};return i(ee=>ee.map(te=>te.id===Y?{...te,...q}:te)),q}catch(U){return console.error("Failed to update workspace:",U),null}},[r,e]),B=y.useCallback(async Y=>{var H,U,Q;if(!e)return r==null||r(),!1;try{const q=await fetch(`${rl}/api/workspaces/${Y}`,{method:"DELETE",headers:Dl(e)});if(q.status===401)return r==null||r(),!1;if(!q.ok)return!1;const ee=n.filter(te=>te.id!==Y);return i(ee),d===Y&&(u(((H=ee[0])==null?void 0:H.id)??null),p(((Q=(U=ee[0])==null?void 0:U.sessions[0])==null?void 0:Q.id)??null)),l(te=>{const ue={...te};return delete ue[Y],ue}),!0}catch(q){return console.error("Failed to archive workspace:",q),!1}},[d,r,e,n]),K=y.useCallback(async()=>{if(!e)return r==null||r(),0;try{const Y=await fetch(`${rl}/api/workspaces/archived`,{method:"DELETE",headers:Dl(e)});return Y.status===401?(r==null||r(),0):Y.ok?(await Y.json()).removed:0}catch(Y){return console.error("Failed to clear archived workspaces:",Y),0}},[r,e]),M=y.useCallback(async()=>{if(!e)return[];try{const Y=await fetch(`${rl}/api/workspaces/archived`,{headers:Dl(e)});return Y.ok?(await Y.json()).workspaces:[]}catch{return[]}},[e]),I=y.useCallback(async Y=>{if(!e)return r==null||r(),!1;try{const H=await fetch(`${rl}/api/workspaces/${Y}/restore`,{method:"POST",headers:Dl(e)});if(H.status===401)return r==null||r(),!1;if(!H.ok)return!1;const U=await H.json();return i(Q=>Q.some(q=>q.id===U.id)?Q:[{...U,sessions:U.sessions??[]},...Q]),!0}catch(H){return console.error("Failed to restore workspace:",H),!1}},[r,e]),P=y.useCallback(async(Y,H)=>{if(!e)return r==null||r(),null;try{const U=await fetch(`${rl}/api/sessions/${Y}`,{method:"PATCH",headers:{...Dl(e),"Content-Type":"application/json"},body:JSON.stringify({name:H})});if(U.status===401)return r==null||r(),null;if(!U.ok)return null;const Q=await U.json();return i(q=>q.map(ee=>({...ee,sessions:ee.sessions.map(te=>te.id===Y?{...te,name:Q.name}:te)}))),o(q=>q.map(ee=>ee.id===Y?{...ee,name:Q.name}:ee)),l(q=>Object.fromEntries(Object.entries(q).map(([ee,te])=>[ee,te.map(ue=>ue.id===Y?{...ue,name:Q.name}:ue)]))),Q}catch(U){return console.error("Failed to rename session:",U),null}},[r,e]),F=y.useCallback(()=>{v(Y=>Y+Hk)},[]),V=y.useCallback(()=>{v(Hk)},[]);return y.useEffect(()=>{j()},[j]),{workspaces:n,personalSessions:s,archivedSessionsByWorkspace:a,activeWorkspace:C,activeWorkspaceId:d,activeSessionId:f,loading:k,hasMoreWorkspaces:b,fetchWorkspaces:j,createWorkspace:N,updateWorkspace:W,createSession:A,switchWorkspace:R,switchSession:L,archiveSession:z,fetchArchivedSessions:$,removeWorkspace:B,clearArchivedWorkspaces:K,fetchArchivedWorkspaces:M,restoreWorkspace:I,renameSession:P,showMoreWorkspaces:F,showFewerWorkspaces:V,workspaceListLimit:Hk}}const ipt=["terminal","browser","screen-share","screen-capture","voice","file-system","os-control","clipboard","notification"],spt=1,Wk={status:"disconnected",micActive:!1,assistantSpeaking:!1,userTranscript:"",assistantTranscript:""};var Qn;(function(e){e.assertEqual=s=>{};function r(s){}e.assertIs=r;function n(s){throw new Error}e.assertNever=n,e.arrayToEnum=s=>{const o={};for(const a of s)o[a]=a;return o},e.getValidEnumValues=s=>{const o=e.objectKeys(s).filter(l=>typeof s[s[l]]!="number"),a={};for(const l of o)a[l]=s[l];return e.objectValues(a)},e.objectValues=s=>e.objectKeys(s).map(function(o){return s[o]}),e.objectKeys=typeof Object.keys=="function"?s=>Object.keys(s):s=>{const o=[];for(const a in s)Object.prototype.hasOwnProperty.call(s,a)&&o.push(a);return o},e.find=(s,o)=>{for(const a of s)if(o(a))return a},e.isInteger=typeof Number.isInteger=="function"?s=>Number.isInteger(s):s=>typeof s=="number"&&Number.isFinite(s)&&Math.floor(s)===s;function i(s,o=" | "){return s.map(a=>typeof a=="string"?`'${a}'`:a).join(o)}e.joinValues=i,e.jsonStringifyReplacer=(s,o)=>typeof o=="bigint"?o.toString():o})(Qn||(Qn={}));var AV;(function(e){e.mergeShapes=(r,n)=>({...r,...n})})(AV||(AV={}));const kr=Qn.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),_m=e=>{switch(typeof e){case"undefined":return kr.undefined;case"string":return kr.string;case"number":return Number.isNaN(e)?kr.nan:kr.number;case"boolean":return kr.boolean;case"function":return kr.function;case"bigint":return kr.bigint;case"symbol":return kr.symbol;case"object":return Array.isArray(e)?kr.array:e===null?kr.null:e.then&&typeof e.then=="function"&&e.catch&&typeof e.catch=="function"?kr.promise:typeof Map<"u"&&e instanceof Map?kr.map:typeof Set<"u"&&e instanceof Set?kr.set:typeof Date<"u"&&e instanceof Date?kr.date:kr.object;default:return kr.unknown}},Vt=Qn.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]);class Xf extends Error{get errors(){return this.issues}constructor(r){super(),this.issues=[],this.addIssue=i=>{this.issues=[...this.issues,i]},this.addIssues=(i=[])=>{this.issues=[...this.issues,...i]};const n=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,n):this.__proto__=n,this.name="ZodError",this.issues=r}format(r){const n=r||function(o){return o.message},i={_errors:[]},s=o=>{for(const a of o.issues)if(a.code==="invalid_union")a.unionErrors.map(s);else if(a.code==="invalid_return_type")s(a.returnTypeError);else if(a.code==="invalid_arguments")s(a.argumentsError);else if(a.path.length===0)i._errors.push(n(a));else{let l=i,d=0;for(;d<a.path.length;){const u=a.path[d];d===a.path.length-1?(l[u]=l[u]||{_errors:[]},l[u]._errors.push(n(a))):l[u]=l[u]||{_errors:[]},l=l[u],d++}}};return s(this),i}static assert(r){if(!(r instanceof Xf))throw new Error(`Not a ZodError: ${r}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,Qn.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(r=n=>n.message){const n={},i=[];for(const s of this.issues)if(s.path.length>0){const o=s.path[0];n[o]=n[o]||[],n[o].push(r(s))}else i.push(r(s));return{formErrors:i,fieldErrors:n}}get formErrors(){return this.flatten()}}Xf.create=e=>new Xf(e);const F7=(e,r)=>{let n;switch(e.code){case Vt.invalid_type:e.received===kr.undefined?n="Required":n=`Expected ${e.expected}, received ${e.received}`;break;case Vt.invalid_literal:n=`Invalid literal value, expected ${JSON.stringify(e.expected,Qn.jsonStringifyReplacer)}`;break;case Vt.unrecognized_keys:n=`Unrecognized key(s) in object: ${Qn.joinValues(e.keys,", ")}`;break;case Vt.invalid_union:n="Invalid input";break;case Vt.invalid_union_discriminator:n=`Invalid discriminator value. Expected ${Qn.joinValues(e.options)}`;break;case Vt.invalid_enum_value:n=`Invalid enum value. Expected ${Qn.joinValues(e.options)}, received '${e.received}'`;break;case Vt.invalid_arguments:n="Invalid function arguments";break;case Vt.invalid_return_type:n="Invalid function return type";break;case Vt.invalid_date:n="Invalid date";break;case Vt.invalid_string:typeof e.validation=="object"?"includes"in e.validation?(n=`Invalid input: must include "${e.validation.includes}"`,typeof e.validation.position=="number"&&(n=`${n} at one or more positions greater than or equal to ${e.validation.position}`)):"startsWith"in e.validation?n=`Invalid input: must start with "${e.validation.startsWith}"`:"endsWith"in e.validation?n=`Invalid input: must end with "${e.validation.endsWith}"`:Qn.assertNever(e.validation):e.validation!=="regex"?n=`Invalid ${e.validation}`:n="Invalid";break;case Vt.too_small:e.type==="array"?n=`Array must contain ${e.exact?"exactly":e.inclusive?"at least":"more than"} ${e.minimum} element(s)`:e.type==="string"?n=`String must contain ${e.exact?"exactly":e.inclusive?"at least":"over"} ${e.minimum} character(s)`:e.type==="number"?n=`Number must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${e.minimum}`:e.type==="bigint"?n=`Number must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${e.minimum}`:e.type==="date"?n=`Date must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(e.minimum))}`:n="Invalid input";break;case Vt.too_big:e.type==="array"?n=`Array must contain ${e.exact?"exactly":e.inclusive?"at most":"less than"} ${e.maximum} element(s)`:e.type==="string"?n=`String must contain ${e.exact?"exactly":e.inclusive?"at most":"under"} ${e.maximum} character(s)`:e.type==="number"?n=`Number must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`:e.type==="bigint"?n=`BigInt must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`:e.type==="date"?n=`Date must be ${e.exact?"exactly":e.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(e.maximum))}`:n="Invalid input";break;case Vt.custom:n="Invalid input";break;case Vt.invalid_intersection_types:n="Intersection results could not be merged";break;case Vt.not_multiple_of:n=`Number must be a multiple of ${e.multipleOf}`;break;case Vt.not_finite:n="Number must be finite";break;default:n=r.defaultError,Qn.assertNever(e)}return{message:n}};let opt=F7;function apt(){return opt}const lpt=e=>{const{data:r,path:n,errorMaps:i,issueData:s}=e,o=[...n,...s.path||[]],a={...s,path:o};if(s.message!==void 0)return{...s,path:o,message:s.message};let l="";const d=i.filter(u=>!!u).slice().reverse();for(const u of d)l=u(a,{data:r,defaultError:l}).message;return{...s,path:o,message:l}};function dr(e,r){const n=apt(),i=lpt({issueData:r,data:e.data,path:e.path,errorMaps:[e.common.contextualErrorMap,e.schemaErrorMap,n,n===F7?void 0:F7].filter(s=>!!s)});e.common.issues.push(i)}class Oc{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(r,n){const i=[];for(const s of n){if(s.status==="aborted")return an;s.status==="dirty"&&r.dirty(),i.push(s.value)}return{status:r.value,value:i}}static async mergeObjectAsync(r,n){const i=[];for(const s of n){const o=await s.key,a=await s.value;i.push({key:o,value:a})}return Oc.mergeObjectSync(r,i)}static mergeObjectSync(r,n){const i={};for(const s of n){const{key:o,value:a}=s;if(o.status==="aborted"||a.status==="aborted")return an;o.status==="dirty"&&r.dirty(),a.status==="dirty"&&r.dirty(),o.value!=="__proto__"&&(typeof a.value<"u"||s.alwaysSet)&&(i[o.value]=a.value)}return{status:r.value,value:i}}}const an=Object.freeze({status:"aborted"}),y_=e=>({status:"dirty",value:e}),ju=e=>({status:"valid",value:e}),OV=e=>e.status==="aborted",RV=e=>e.status==="dirty",fv=e=>e.status==="valid",w4=e=>typeof Promise<"u"&&e instanceof Promise;var Ar;(function(e){e.errToObj=r=>typeof r=="string"?{message:r}:r||{},e.toString=r=>typeof r=="string"?r:r==null?void 0:r.message})(Ar||(Ar={}));class Vm{constructor(r,n,i,s){this._cachedPath=[],this.parent=r,this.data=n,this._path=i,this._key=s}get path(){return this._cachedPath.length||(Array.isArray(this._key)?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}const MV=(e,r)=>{if(fv(r))return{success:!0,data:r.value};if(!e.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const n=new Xf(e.common.issues);return this._error=n,this._error}}};function Cn(e){if(!e)return{};const{errorMap:r,invalid_type_error:n,required_error:i,description:s}=e;if(r&&(n||i))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return r?{errorMap:r,description:s}:{errorMap:(a,l)=>{const{message:d}=e;return a.code==="invalid_enum_value"?{message:d??l.defaultError}:typeof l.data>"u"?{message:d??i??l.defaultError}:a.code!=="invalid_type"?{message:l.defaultError}:{message:d??n??l.defaultError}},description:s}}class qn{get description(){return this._def.description}_getType(r){return _m(r.data)}_getOrReturnCtx(r,n){return n||{common:r.parent.common,data:r.data,parsedType:_m(r.data),schemaErrorMap:this._def.errorMap,path:r.path,parent:r.parent}}_processInputParams(r){return{status:new Oc,ctx:{common:r.parent.common,data:r.data,parsedType:_m(r.data),schemaErrorMap:this._def.errorMap,path:r.path,parent:r.parent}}}_parseSync(r){const n=this._parse(r);if(w4(n))throw new Error("Synchronous parse encountered promise.");return n}_parseAsync(r){const n=this._parse(r);return Promise.resolve(n)}parse(r,n){const i=this.safeParse(r,n);if(i.success)return i.data;throw i.error}safeParse(r,n){const i={common:{issues:[],async:(n==null?void 0:n.async)??!1,contextualErrorMap:n==null?void 0:n.errorMap},path:(n==null?void 0:n.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:r,parsedType:_m(r)},s=this._parseSync({data:r,path:i.path,parent:i});return MV(i,s)}"~validate"(r){var i,s;const n={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:r,parsedType:_m(r)};if(!this["~standard"].async)try{const o=this._parseSync({data:r,path:[],parent:n});return fv(o)?{value:o.value}:{issues:n.common.issues}}catch(o){(s=(i=o==null?void 0:o.message)==null?void 0:i.toLowerCase())!=null&&s.includes("encountered")&&(this["~standard"].async=!0),n.common={issues:[],async:!0}}return this._parseAsync({data:r,path:[],parent:n}).then(o=>fv(o)?{value:o.value}:{issues:n.common.issues})}async parseAsync(r,n){const i=await this.safeParseAsync(r,n);if(i.success)return i.data;throw i.error}async safeParseAsync(r,n){const i={common:{issues:[],contextualErrorMap:n==null?void 0:n.errorMap,async:!0},path:(n==null?void 0:n.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:r,parsedType:_m(r)},s=this._parse({data:r,path:i.path,parent:i}),o=await(w4(s)?s:Promise.resolve(s));return MV(i,o)}refine(r,n){const i=s=>typeof n=="string"||typeof n>"u"?{message:n}:typeof n=="function"?n(s):n;return this._refinement((s,o)=>{const a=r(s),l=()=>o.addIssue({code:Vt.custom,...i(s)});return typeof Promise<"u"&&a instanceof Promise?a.then(d=>d?!0:(l(),!1)):a?!0:(l(),!1)})}refinement(r,n){return this._refinement((i,s)=>r(i)?!0:(s.addIssue(typeof n=="function"?n(i,s):n),!1))}_refinement(r){return new gv({schema:this,typeName:ln.ZodEffects,effect:{type:"refinement",refinement:r}})}superRefine(r){return this._refinement(r)}constructor(r){this.spa=this.safeParseAsync,this._def=r,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:n=>this["~validate"](n)}}optional(){return Lm.create(this,this._def)}nullable(){return yv.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return Nh.create(this)}promise(){return j4.create(this,this._def)}or(r){return k4.create([this,r],this._def)}and(r){return C4.create(this,r,this._def)}transform(r){return new gv({...Cn(this._def),schema:this,typeName:ln.ZodEffects,effect:{type:"transform",transform:r}})}default(r){const n=typeof r=="function"?r:()=>r;return new U7({...Cn(this._def),innerType:this,defaultValue:n,typeName:ln.ZodDefault})}brand(){return new Opt({typeName:ln.ZodBranded,type:this,...Cn(this._def)})}catch(r){const n=typeof r=="function"?r:()=>r;return new V7({...Cn(this._def),innerType:this,catchValue:n,typeName:ln.ZodCatch})}describe(r){const n=this.constructor;return new n({...this._def,description:r})}pipe(r){return IP.create(this,r)}readonly(){return q7.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const cpt=/^c[^\s-]{8,}$/i,upt=/^[0-9a-z]+$/,dpt=/^[0-9A-HJKMNP-TV-Z]{26}$/i,hpt=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,fpt=/^[a-z0-9_-]{21}$/i,ppt=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,mpt=/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,gpt=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,ypt="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let h8;const vpt=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,xpt=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,bpt=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,_pt=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,wpt=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,Spt=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,tue="((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))",kpt=new RegExp(`^${tue}$`);function rue(e){let r="[0-5]\\d";e.precision?r=`${r}\\.\\d{${e.precision}}`:e.precision==null&&(r=`${r}(\\.\\d+)?`);const n=e.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${r})${n}`}function Cpt(e){return new RegExp(`^${rue(e)}$`)}function jpt(e){let r=`${tue}T${rue(e)}`;const n=[];return n.push(e.local?"Z?":"Z"),e.offset&&n.push("([+-]\\d{2}:?\\d{2})"),r=`${r}(${n.join("|")})`,new RegExp(`^${r}$`)}function Npt(e,r){return!!((r==="v4"||!r)&&vpt.test(e)||(r==="v6"||!r)&&bpt.test(e))}function Tpt(e,r){if(!ppt.test(e))return!1;try{const[n]=e.split(".");if(!n)return!1;const i=n.replace(/-/g,"+").replace(/_/g,"/").padEnd(n.length+(4-n.length%4)%4,"="),s=JSON.parse(atob(i));return!(typeof s!="object"||s===null||"typ"in s&&(s==null?void 0:s.typ)!=="JWT"||!s.alg||r&&s.alg!==r)}catch{return!1}}function Ept(e,r){return!!((r==="v4"||!r)&&xpt.test(e)||(r==="v6"||!r)&&_pt.test(e))}class Nm extends qn{_parse(r){if(this._def.coerce&&(r.data=String(r.data)),this._getType(r)!==kr.string){const o=this._getOrReturnCtx(r);return dr(o,{code:Vt.invalid_type,expected:kr.string,received:o.parsedType}),an}const i=new Oc;let s;for(const o of this._def.checks)if(o.kind==="min")r.data.length<o.value&&(s=this._getOrReturnCtx(r,s),dr(s,{code:Vt.too_small,minimum:o.value,type:"string",inclusive:!0,exact:!1,message:o.message}),i.dirty());else if(o.kind==="max")r.data.length>o.value&&(s=this._getOrReturnCtx(r,s),dr(s,{code:Vt.too_big,maximum:o.value,type:"string",inclusive:!0,exact:!1,message:o.message}),i.dirty());else if(o.kind==="length"){const a=r.data.length>o.value,l=r.data.length<o.value;(a||l)&&(s=this._getOrReturnCtx(r,s),a?dr(s,{code:Vt.too_big,maximum:o.value,type:"string",inclusive:!0,exact:!0,message:o.message}):l&&dr(s,{code:Vt.too_small,minimum:o.value,type:"string",inclusive:!0,exact:!0,message:o.message}),i.dirty())}else if(o.kind==="email")gpt.test(r.data)||(s=this._getOrReturnCtx(r,s),dr(s,{validation:"email",code:Vt.invalid_string,message:o.message}),i.dirty());else if(o.kind==="emoji")h8||(h8=new RegExp(ypt,"u")),h8.test(r.data)||(s=this._getOrReturnCtx(r,s),dr(s,{validation:"emoji",code:Vt.invalid_string,message:o.message}),i.dirty());else if(o.kind==="uuid")hpt.test(r.data)||(s=this._getOrReturnCtx(r,s),dr(s,{validation:"uuid",code:Vt.invalid_string,message:o.message}),i.dirty());else if(o.kind==="nanoid")fpt.test(r.data)||(s=this._getOrReturnCtx(r,s),dr(s,{validation:"nanoid",code:Vt.invalid_string,message:o.message}),i.dirty());else if(o.kind==="cuid")cpt.test(r.data)||(s=this._getOrReturnCtx(r,s),dr(s,{validation:"cuid",code:Vt.invalid_string,message:o.message}),i.dirty());else if(o.kind==="cuid2")upt.test(r.data)||(s=this._getOrReturnCtx(r,s),dr(s,{validation:"cuid2",code:Vt.invalid_string,message:o.message}),i.dirty());else if(o.kind==="ulid")dpt.test(r.data)||(s=this._getOrReturnCtx(r,s),dr(s,{validation:"ulid",code:Vt.invalid_string,message:o.message}),i.dirty());else if(o.kind==="url")try{new URL(r.data)}catch{s=this._getOrReturnCtx(r,s),dr(s,{validation:"url",code:Vt.invalid_string,message:o.message}),i.dirty()}else o.kind==="regex"?(o.regex.lastIndex=0,o.regex.test(r.data)||(s=this._getOrReturnCtx(r,s),dr(s,{validation:"regex",code:Vt.invalid_string,message:o.message}),i.dirty())):o.kind==="trim"?r.data=r.data.trim():o.kind==="includes"?r.data.includes(o.value,o.position)||(s=this._getOrReturnCtx(r,s),dr(s,{code:Vt.invalid_string,validation:{includes:o.value,position:o.position},message:o.message}),i.dirty()):o.kind==="toLowerCase"?r.data=r.data.toLowerCase():o.kind==="toUpperCase"?r.data=r.data.toUpperCase():o.kind==="startsWith"?r.data.startsWith(o.value)||(s=this._getOrReturnCtx(r,s),dr(s,{code:Vt.invalid_string,validation:{startsWith:o.value},message:o.message}),i.dirty()):o.kind==="endsWith"?r.data.endsWith(o.value)||(s=this._getOrReturnCtx(r,s),dr(s,{code:Vt.invalid_string,validation:{endsWith:o.value},message:o.message}),i.dirty()):o.kind==="datetime"?jpt(o).test(r.data)||(s=this._getOrReturnCtx(r,s),dr(s,{code:Vt.invalid_string,validation:"datetime",message:o.message}),i.dirty()):o.kind==="date"?kpt.test(r.data)||(s=this._getOrReturnCtx(r,s),dr(s,{code:Vt.invalid_string,validation:"date",message:o.message}),i.dirty()):o.kind==="time"?Cpt(o).test(r.data)||(s=this._getOrReturnCtx(r,s),dr(s,{code:Vt.invalid_string,validation:"time",message:o.message}),i.dirty()):o.kind==="duration"?mpt.test(r.data)||(s=this._getOrReturnCtx(r,s),dr(s,{validation:"duration",code:Vt.invalid_string,message:o.message}),i.dirty()):o.kind==="ip"?Npt(r.data,o.version)||(s=this._getOrReturnCtx(r,s),dr(s,{validation:"ip",code:Vt.invalid_string,message:o.message}),i.dirty()):o.kind==="jwt"?Tpt(r.data,o.alg)||(s=this._getOrReturnCtx(r,s),dr(s,{validation:"jwt",code:Vt.invalid_string,message:o.message}),i.dirty()):o.kind==="cidr"?Ept(r.data,o.version)||(s=this._getOrReturnCtx(r,s),dr(s,{validation:"cidr",code:Vt.invalid_string,message:o.message}),i.dirty()):o.kind==="base64"?wpt.test(r.data)||(s=this._getOrReturnCtx(r,s),dr(s,{validation:"base64",code:Vt.invalid_string,message:o.message}),i.dirty()):o.kind==="base64url"?Spt.test(r.data)||(s=this._getOrReturnCtx(r,s),dr(s,{validation:"base64url",code:Vt.invalid_string,message:o.message}),i.dirty()):Qn.assertNever(o);return{status:i.value,value:r.data}}_regex(r,n,i){return this.refinement(s=>r.test(s),{validation:n,code:Vt.invalid_string,...Ar.errToObj(i)})}_addCheck(r){return new Nm({...this._def,checks:[...this._def.checks,r]})}email(r){return this._addCheck({kind:"email",...Ar.errToObj(r)})}url(r){return this._addCheck({kind:"url",...Ar.errToObj(r)})}emoji(r){return this._addCheck({kind:"emoji",...Ar.errToObj(r)})}uuid(r){return this._addCheck({kind:"uuid",...Ar.errToObj(r)})}nanoid(r){return this._addCheck({kind:"nanoid",...Ar.errToObj(r)})}cuid(r){return this._addCheck({kind:"cuid",...Ar.errToObj(r)})}cuid2(r){return this._addCheck({kind:"cuid2",...Ar.errToObj(r)})}ulid(r){return this._addCheck({kind:"ulid",...Ar.errToObj(r)})}base64(r){return this._addCheck({kind:"base64",...Ar.errToObj(r)})}base64url(r){return this._addCheck({kind:"base64url",...Ar.errToObj(r)})}jwt(r){return this._addCheck({kind:"jwt",...Ar.errToObj(r)})}ip(r){return this._addCheck({kind:"ip",...Ar.errToObj(r)})}cidr(r){return this._addCheck({kind:"cidr",...Ar.errToObj(r)})}datetime(r){return typeof r=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:r}):this._addCheck({kind:"datetime",precision:typeof(r==null?void 0:r.precision)>"u"?null:r==null?void 0:r.precision,offset:(r==null?void 0:r.offset)??!1,local:(r==null?void 0:r.local)??!1,...Ar.errToObj(r==null?void 0:r.message)})}date(r){return this._addCheck({kind:"date",message:r})}time(r){return typeof r=="string"?this._addCheck({kind:"time",precision:null,message:r}):this._addCheck({kind:"time",precision:typeof(r==null?void 0:r.precision)>"u"?null:r==null?void 0:r.precision,...Ar.errToObj(r==null?void 0:r.message)})}duration(r){return this._addCheck({kind:"duration",...Ar.errToObj(r)})}regex(r,n){return this._addCheck({kind:"regex",regex:r,...Ar.errToObj(n)})}includes(r,n){return this._addCheck({kind:"includes",value:r,position:n==null?void 0:n.position,...Ar.errToObj(n==null?void 0:n.message)})}startsWith(r,n){return this._addCheck({kind:"startsWith",value:r,...Ar.errToObj(n)})}endsWith(r,n){return this._addCheck({kind:"endsWith",value:r,...Ar.errToObj(n)})}min(r,n){return this._addCheck({kind:"min",value:r,...Ar.errToObj(n)})}max(r,n){return this._addCheck({kind:"max",value:r,...Ar.errToObj(n)})}length(r,n){return this._addCheck({kind:"length",value:r,...Ar.errToObj(n)})}nonempty(r){return this.min(1,Ar.errToObj(r))}trim(){return new Nm({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new Nm({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new Nm({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(r=>r.kind==="datetime")}get isDate(){return!!this._def.checks.find(r=>r.kind==="date")}get isTime(){return!!this._def.checks.find(r=>r.kind==="time")}get isDuration(){return!!this._def.checks.find(r=>r.kind==="duration")}get isEmail(){return!!this._def.checks.find(r=>r.kind==="email")}get isURL(){return!!this._def.checks.find(r=>r.kind==="url")}get isEmoji(){return!!this._def.checks.find(r=>r.kind==="emoji")}get isUUID(){return!!this._def.checks.find(r=>r.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(r=>r.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(r=>r.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(r=>r.kind==="cuid2")}get isULID(){return!!this._def.checks.find(r=>r.kind==="ulid")}get isIP(){return!!this._def.checks.find(r=>r.kind==="ip")}get isCIDR(){return!!this._def.checks.find(r=>r.kind==="cidr")}get isBase64(){return!!this._def.checks.find(r=>r.kind==="base64")}get isBase64url(){return!!this._def.checks.find(r=>r.kind==="base64url")}get minLength(){let r=null;for(const n of this._def.checks)n.kind==="min"&&(r===null||n.value>r)&&(r=n.value);return r}get maxLength(){let r=null;for(const n of this._def.checks)n.kind==="max"&&(r===null||n.value<r)&&(r=n.value);return r}}Nm.create=e=>new Nm({checks:[],typeName:ln.ZodString,coerce:(e==null?void 0:e.coerce)??!1,...Cn(e)});function Apt(e,r){const n=(e.toString().split(".")[1]||"").length,i=(r.toString().split(".")[1]||"").length,s=n>i?n:i,o=Number.parseInt(e.toFixed(s).replace(".","")),a=Number.parseInt(r.toFixed(s).replace(".",""));return o%a/10**s}class pv extends qn{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(r){if(this._def.coerce&&(r.data=Number(r.data)),this._getType(r)!==kr.number){const o=this._getOrReturnCtx(r);return dr(o,{code:Vt.invalid_type,expected:kr.number,received:o.parsedType}),an}let i;const s=new Oc;for(const o of this._def.checks)o.kind==="int"?Qn.isInteger(r.data)||(i=this._getOrReturnCtx(r,i),dr(i,{code:Vt.invalid_type,expected:"integer",received:"float",message:o.message}),s.dirty()):o.kind==="min"?(o.inclusive?r.data<o.value:r.data<=o.value)&&(i=this._getOrReturnCtx(r,i),dr(i,{code:Vt.too_small,minimum:o.value,type:"number",inclusive:o.inclusive,exact:!1,message:o.message}),s.dirty()):o.kind==="max"?(o.inclusive?r.data>o.value:r.data>=o.value)&&(i=this._getOrReturnCtx(r,i),dr(i,{code:Vt.too_big,maximum:o.value,type:"number",inclusive:o.inclusive,exact:!1,message:o.message}),s.dirty()):o.kind==="multipleOf"?Apt(r.data,o.value)!==0&&(i=this._getOrReturnCtx(r,i),dr(i,{code:Vt.not_multiple_of,multipleOf:o.value,message:o.message}),s.dirty()):o.kind==="finite"?Number.isFinite(r.data)||(i=this._getOrReturnCtx(r,i),dr(i,{code:Vt.not_finite,message:o.message}),s.dirty()):Qn.assertNever(o);return{status:s.value,value:r.data}}gte(r,n){return this.setLimit("min",r,!0,Ar.toString(n))}gt(r,n){return this.setLimit("min",r,!1,Ar.toString(n))}lte(r,n){return this.setLimit("max",r,!0,Ar.toString(n))}lt(r,n){return this.setLimit("max",r,!1,Ar.toString(n))}setLimit(r,n,i,s){return new pv({...this._def,checks:[...this._def.checks,{kind:r,value:n,inclusive:i,message:Ar.toString(s)}]})}_addCheck(r){return new pv({...this._def,checks:[...this._def.checks,r]})}int(r){return this._addCheck({kind:"int",message:Ar.toString(r)})}positive(r){return this._addCheck({kind:"min",value:0,inclusive:!1,message:Ar.toString(r)})}negative(r){return this._addCheck({kind:"max",value:0,inclusive:!1,message:Ar.toString(r)})}nonpositive(r){return this._addCheck({kind:"max",value:0,inclusive:!0,message:Ar.toString(r)})}nonnegative(r){return this._addCheck({kind:"min",value:0,inclusive:!0,message:Ar.toString(r)})}multipleOf(r,n){return this._addCheck({kind:"multipleOf",value:r,message:Ar.toString(n)})}finite(r){return this._addCheck({kind:"finite",message:Ar.toString(r)})}safe(r){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:Ar.toString(r)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:Ar.toString(r)})}get minValue(){let r=null;for(const n of this._def.checks)n.kind==="min"&&(r===null||n.value>r)&&(r=n.value);return r}get maxValue(){let r=null;for(const n of this._def.checks)n.kind==="max"&&(r===null||n.value<r)&&(r=n.value);return r}get isInt(){return!!this._def.checks.find(r=>r.kind==="int"||r.kind==="multipleOf"&&Qn.isInteger(r.value))}get isFinite(){let r=null,n=null;for(const i of this._def.checks){if(i.kind==="finite"||i.kind==="int"||i.kind==="multipleOf")return!0;i.kind==="min"?(n===null||i.value>n)&&(n=i.value):i.kind==="max"&&(r===null||i.value<r)&&(r=i.value)}return Number.isFinite(n)&&Number.isFinite(r)}}pv.create=e=>new pv({checks:[],typeName:ln.ZodNumber,coerce:(e==null?void 0:e.coerce)||!1,...Cn(e)});class Kw extends qn{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(r){if(this._def.coerce)try{r.data=BigInt(r.data)}catch{return this._getInvalidInput(r)}if(this._getType(r)!==kr.bigint)return this._getInvalidInput(r);let i;const s=new Oc;for(const o of this._def.checks)o.kind==="min"?(o.inclusive?r.data<o.value:r.data<=o.value)&&(i=this._getOrReturnCtx(r,i),dr(i,{code:Vt.too_small,type:"bigint",minimum:o.value,inclusive:o.inclusive,message:o.message}),s.dirty()):o.kind==="max"?(o.inclusive?r.data>o.value:r.data>=o.value)&&(i=this._getOrReturnCtx(r,i),dr(i,{code:Vt.too_big,type:"bigint",maximum:o.value,inclusive:o.inclusive,message:o.message}),s.dirty()):o.kind==="multipleOf"?r.data%o.value!==BigInt(0)&&(i=this._getOrReturnCtx(r,i),dr(i,{code:Vt.not_multiple_of,multipleOf:o.value,message:o.message}),s.dirty()):Qn.assertNever(o);return{status:s.value,value:r.data}}_getInvalidInput(r){const n=this._getOrReturnCtx(r);return dr(n,{code:Vt.invalid_type,expected:kr.bigint,received:n.parsedType}),an}gte(r,n){return this.setLimit("min",r,!0,Ar.toString(n))}gt(r,n){return this.setLimit("min",r,!1,Ar.toString(n))}lte(r,n){return this.setLimit("max",r,!0,Ar.toString(n))}lt(r,n){return this.setLimit("max",r,!1,Ar.toString(n))}setLimit(r,n,i,s){return new Kw({...this._def,checks:[...this._def.checks,{kind:r,value:n,inclusive:i,message:Ar.toString(s)}]})}_addCheck(r){return new Kw({...this._def,checks:[...this._def.checks,r]})}positive(r){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:Ar.toString(r)})}negative(r){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:Ar.toString(r)})}nonpositive(r){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:Ar.toString(r)})}nonnegative(r){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:Ar.toString(r)})}multipleOf(r,n){return this._addCheck({kind:"multipleOf",value:r,message:Ar.toString(n)})}get minValue(){let r=null;for(const n of this._def.checks)n.kind==="min"&&(r===null||n.value>r)&&(r=n.value);return r}get maxValue(){let r=null;for(const n of this._def.checks)n.kind==="max"&&(r===null||n.value<r)&&(r=n.value);return r}}Kw.create=e=>new Kw({checks:[],typeName:ln.ZodBigInt,coerce:(e==null?void 0:e.coerce)??!1,...Cn(e)});class H7 extends qn{_parse(r){if(this._def.coerce&&(r.data=!!r.data),this._getType(r)!==kr.boolean){const i=this._getOrReturnCtx(r);return dr(i,{code:Vt.invalid_type,expected:kr.boolean,received:i.parsedType}),an}return ju(r.data)}}H7.create=e=>new H7({typeName:ln.ZodBoolean,coerce:(e==null?void 0:e.coerce)||!1,...Cn(e)});class S4 extends qn{_parse(r){if(this._def.coerce&&(r.data=new Date(r.data)),this._getType(r)!==kr.date){const o=this._getOrReturnCtx(r);return dr(o,{code:Vt.invalid_type,expected:kr.date,received:o.parsedType}),an}if(Number.isNaN(r.data.getTime())){const o=this._getOrReturnCtx(r);return dr(o,{code:Vt.invalid_date}),an}const i=new Oc;let s;for(const o of this._def.checks)o.kind==="min"?r.data.getTime()<o.value&&(s=this._getOrReturnCtx(r,s),dr(s,{code:Vt.too_small,message:o.message,inclusive:!0,exact:!1,minimum:o.value,type:"date"}),i.dirty()):o.kind==="max"?r.data.getTime()>o.value&&(s=this._getOrReturnCtx(r,s),dr(s,{code:Vt.too_big,message:o.message,inclusive:!0,exact:!1,maximum:o.value,type:"date"}),i.dirty()):Qn.assertNever(o);return{status:i.value,value:new Date(r.data.getTime())}}_addCheck(r){return new S4({...this._def,checks:[...this._def.checks,r]})}min(r,n){return this._addCheck({kind:"min",value:r.getTime(),message:Ar.toString(n)})}max(r,n){return this._addCheck({kind:"max",value:r.getTime(),message:Ar.toString(n)})}get minDate(){let r=null;for(const n of this._def.checks)n.kind==="min"&&(r===null||n.value>r)&&(r=n.value);return r!=null?new Date(r):null}get maxDate(){let r=null;for(const n of this._def.checks)n.kind==="max"&&(r===null||n.value<r)&&(r=n.value);return r!=null?new Date(r):null}}S4.create=e=>new S4({checks:[],coerce:(e==null?void 0:e.coerce)||!1,typeName:ln.ZodDate,...Cn(e)});class PV extends qn{_parse(r){if(this._getType(r)!==kr.symbol){const i=this._getOrReturnCtx(r);return dr(i,{code:Vt.invalid_type,expected:kr.symbol,received:i.parsedType}),an}return ju(r.data)}}PV.create=e=>new PV({typeName:ln.ZodSymbol,...Cn(e)});class LV extends qn{_parse(r){if(this._getType(r)!==kr.undefined){const i=this._getOrReturnCtx(r);return dr(i,{code:Vt.invalid_type,expected:kr.undefined,received:i.parsedType}),an}return ju(r.data)}}LV.create=e=>new LV({typeName:ln.ZodUndefined,...Cn(e)});class $V extends qn{_parse(r){if(this._getType(r)!==kr.null){const i=this._getOrReturnCtx(r);return dr(i,{code:Vt.invalid_type,expected:kr.null,received:i.parsedType}),an}return ju(r.data)}}$V.create=e=>new $V({typeName:ln.ZodNull,...Cn(e)});class DV extends qn{constructor(){super(...arguments),this._any=!0}_parse(r){return ju(r.data)}}DV.create=e=>new DV({typeName:ln.ZodAny,...Cn(e)});class IV extends qn{constructor(){super(...arguments),this._unknown=!0}_parse(r){return ju(r.data)}}IV.create=e=>new IV({typeName:ln.ZodUnknown,...Cn(e)});class qm extends qn{_parse(r){const n=this._getOrReturnCtx(r);return dr(n,{code:Vt.invalid_type,expected:kr.never,received:n.parsedType}),an}}qm.create=e=>new qm({typeName:ln.ZodNever,...Cn(e)});class BV extends qn{_parse(r){if(this._getType(r)!==kr.undefined){const i=this._getOrReturnCtx(r);return dr(i,{code:Vt.invalid_type,expected:kr.void,received:i.parsedType}),an}return ju(r.data)}}BV.create=e=>new BV({typeName:ln.ZodVoid,...Cn(e)});class Nh extends qn{_parse(r){const{ctx:n,status:i}=this._processInputParams(r),s=this._def;if(n.parsedType!==kr.array)return dr(n,{code:Vt.invalid_type,expected:kr.array,received:n.parsedType}),an;if(s.exactLength!==null){const a=n.data.length>s.exactLength.value,l=n.data.length<s.exactLength.value;(a||l)&&(dr(n,{code:a?Vt.too_big:Vt.too_small,minimum:l?s.exactLength.value:void 0,maximum:a?s.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:s.exactLength.message}),i.dirty())}if(s.minLength!==null&&n.data.length<s.minLength.value&&(dr(n,{code:Vt.too_small,minimum:s.minLength.value,type:"array",inclusive:!0,exact:!1,message:s.minLength.message}),i.dirty()),s.maxLength!==null&&n.data.length>s.maxLength.value&&(dr(n,{code:Vt.too_big,maximum:s.maxLength.value,type:"array",inclusive:!0,exact:!1,message:s.maxLength.message}),i.dirty()),n.common.async)return Promise.all([...n.data].map((a,l)=>s.type._parseAsync(new Vm(n,a,n.path,l)))).then(a=>Oc.mergeArray(i,a));const o=[...n.data].map((a,l)=>s.type._parseSync(new Vm(n,a,n.path,l)));return Oc.mergeArray(i,o)}get element(){return this._def.type}min(r,n){return new Nh({...this._def,minLength:{value:r,message:Ar.toString(n)}})}max(r,n){return new Nh({...this._def,maxLength:{value:r,message:Ar.toString(n)}})}length(r,n){return new Nh({...this._def,exactLength:{value:r,message:Ar.toString(n)}})}nonempty(r){return this.min(1,r)}}Nh.create=(e,r)=>new Nh({type:e,minLength:null,maxLength:null,exactLength:null,typeName:ln.ZodArray,...Cn(r)});function g1(e){if(e instanceof Bs){const r={};for(const n in e.shape){const i=e.shape[n];r[n]=Lm.create(g1(i))}return new Bs({...e._def,shape:()=>r})}else return e instanceof Nh?new Nh({...e._def,type:g1(e.element)}):e instanceof Lm?Lm.create(g1(e.unwrap())):e instanceof yv?yv.create(g1(e.unwrap())):e instanceof I0?I0.create(e.items.map(r=>g1(r))):e}class Bs extends qn{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;const r=this._def.shape(),n=Qn.objectKeys(r);return this._cached={shape:r,keys:n},this._cached}_parse(r){if(this._getType(r)!==kr.object){const u=this._getOrReturnCtx(r);return dr(u,{code:Vt.invalid_type,expected:kr.object,received:u.parsedType}),an}const{status:i,ctx:s}=this._processInputParams(r),{shape:o,keys:a}=this._getCached(),l=[];if(!(this._def.catchall instanceof qm&&this._def.unknownKeys==="strip"))for(const u in s.data)a.includes(u)||l.push(u);const d=[];for(const u of a){const f=o[u],p=s.data[u];d.push({key:{status:"valid",value:u},value:f._parse(new Vm(s,p,s.path,u)),alwaysSet:u in s.data})}if(this._def.catchall instanceof qm){const u=this._def.unknownKeys;if(u==="passthrough")for(const f of l)d.push({key:{status:"valid",value:f},value:{status:"valid",value:s.data[f]}});else if(u==="strict")l.length>0&&(dr(s,{code:Vt.unrecognized_keys,keys:l}),i.dirty());else if(u!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const u=this._def.catchall;for(const f of l){const p=s.data[f];d.push({key:{status:"valid",value:f},value:u._parse(new Vm(s,p,s.path,f)),alwaysSet:f in s.data})}}return s.common.async?Promise.resolve().then(async()=>{const u=[];for(const f of d){const p=await f.key,g=await f.value;u.push({key:p,value:g,alwaysSet:f.alwaysSet})}return u}).then(u=>Oc.mergeObjectSync(i,u)):Oc.mergeObjectSync(i,d)}get shape(){return this._def.shape()}strict(r){return Ar.errToObj,new Bs({...this._def,unknownKeys:"strict",...r!==void 0?{errorMap:(n,i)=>{var o,a;const s=((a=(o=this._def).errorMap)==null?void 0:a.call(o,n,i).message)??i.defaultError;return n.code==="unrecognized_keys"?{message:Ar.errToObj(r).message??s}:{message:s}}}:{}})}strip(){return new Bs({...this._def,unknownKeys:"strip"})}passthrough(){return new Bs({...this._def,unknownKeys:"passthrough"})}extend(r){return new Bs({...this._def,shape:()=>({...this._def.shape(),...r})})}merge(r){return new Bs({unknownKeys:r._def.unknownKeys,catchall:r._def.catchall,shape:()=>({...this._def.shape(),...r._def.shape()}),typeName:ln.ZodObject})}setKey(r,n){return this.augment({[r]:n})}catchall(r){return new Bs({...this._def,catchall:r})}pick(r){const n={};for(const i of Qn.objectKeys(r))r[i]&&this.shape[i]&&(n[i]=this.shape[i]);return new Bs({...this._def,shape:()=>n})}omit(r){const n={};for(const i of Qn.objectKeys(this.shape))r[i]||(n[i]=this.shape[i]);return new Bs({...this._def,shape:()=>n})}deepPartial(){return g1(this)}partial(r){const n={};for(const i of Qn.objectKeys(this.shape)){const s=this.shape[i];r&&!r[i]?n[i]=s:n[i]=s.optional()}return new Bs({...this._def,shape:()=>n})}required(r){const n={};for(const i of Qn.objectKeys(this.shape))if(r&&!r[i])n[i]=this.shape[i];else{let o=this.shape[i];for(;o instanceof Lm;)o=o._def.innerType;n[i]=o}return new Bs({...this._def,shape:()=>n})}keyof(){return nue(Qn.objectKeys(this.shape))}}Bs.create=(e,r)=>new Bs({shape:()=>e,unknownKeys:"strip",catchall:qm.create(),typeName:ln.ZodObject,...Cn(r)});Bs.strictCreate=(e,r)=>new Bs({shape:()=>e,unknownKeys:"strict",catchall:qm.create(),typeName:ln.ZodObject,...Cn(r)});Bs.lazycreate=(e,r)=>new Bs({shape:e,unknownKeys:"strip",catchall:qm.create(),typeName:ln.ZodObject,...Cn(r)});class k4 extends qn{_parse(r){const{ctx:n}=this._processInputParams(r),i=this._def.options;function s(o){for(const l of o)if(l.result.status==="valid")return l.result;for(const l of o)if(l.result.status==="dirty")return n.common.issues.push(...l.ctx.common.issues),l.result;const a=o.map(l=>new Xf(l.ctx.common.issues));return dr(n,{code:Vt.invalid_union,unionErrors:a}),an}if(n.common.async)return Promise.all(i.map(async o=>{const a={...n,common:{...n.common,issues:[]},parent:null};return{result:await o._parseAsync({data:n.data,path:n.path,parent:a}),ctx:a}})).then(s);{let o;const a=[];for(const d of i){const u={...n,common:{...n.common,issues:[]},parent:null},f=d._parseSync({data:n.data,path:n.path,parent:u});if(f.status==="valid")return f;f.status==="dirty"&&!o&&(o={result:f,ctx:u}),u.common.issues.length&&a.push(u.common.issues)}if(o)return n.common.issues.push(...o.ctx.common.issues),o.result;const l=a.map(d=>new Xf(d));return dr(n,{code:Vt.invalid_union,unionErrors:l}),an}}get options(){return this._def.options}}k4.create=(e,r)=>new k4({options:e,typeName:ln.ZodUnion,...Cn(r)});function W7(e,r){const n=_m(e),i=_m(r);if(e===r)return{valid:!0,data:e};if(n===kr.object&&i===kr.object){const s=Qn.objectKeys(r),o=Qn.objectKeys(e).filter(l=>s.indexOf(l)!==-1),a={...e,...r};for(const l of o){const d=W7(e[l],r[l]);if(!d.valid)return{valid:!1};a[l]=d.data}return{valid:!0,data:a}}else if(n===kr.array&&i===kr.array){if(e.length!==r.length)return{valid:!1};const s=[];for(let o=0;o<e.length;o++){const a=e[o],l=r[o],d=W7(a,l);if(!d.valid)return{valid:!1};s.push(d.data)}return{valid:!0,data:s}}else return n===kr.date&&i===kr.date&&+e==+r?{valid:!0,data:e}:{valid:!1}}class C4 extends qn{_parse(r){const{status:n,ctx:i}=this._processInputParams(r),s=(o,a)=>{if(OV(o)||OV(a))return an;const l=W7(o.value,a.value);return l.valid?((RV(o)||RV(a))&&n.dirty(),{status:n.value,value:l.data}):(dr(i,{code:Vt.invalid_intersection_types}),an)};return i.common.async?Promise.all([this._def.left._parseAsync({data:i.data,path:i.path,parent:i}),this._def.right._parseAsync({data:i.data,path:i.path,parent:i})]).then(([o,a])=>s(o,a)):s(this._def.left._parseSync({data:i.data,path:i.path,parent:i}),this._def.right._parseSync({data:i.data,path:i.path,parent:i}))}}C4.create=(e,r,n)=>new C4({left:e,right:r,typeName:ln.ZodIntersection,...Cn(n)});class I0 extends qn{_parse(r){const{status:n,ctx:i}=this._processInputParams(r);if(i.parsedType!==kr.array)return dr(i,{code:Vt.invalid_type,expected:kr.array,received:i.parsedType}),an;if(i.data.length<this._def.items.length)return dr(i,{code:Vt.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),an;!this._def.rest&&i.data.length>this._def.items.length&&(dr(i,{code:Vt.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),n.dirty());const o=[...i.data].map((a,l)=>{const d=this._def.items[l]||this._def.rest;return d?d._parse(new Vm(i,a,i.path,l)):null}).filter(a=>!!a);return i.common.async?Promise.all(o).then(a=>Oc.mergeArray(n,a)):Oc.mergeArray(n,o)}get items(){return this._def.items}rest(r){return new I0({...this._def,rest:r})}}I0.create=(e,r)=>{if(!Array.isArray(e))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new I0({items:e,typeName:ln.ZodTuple,rest:null,...Cn(r)})};class zV extends qn{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(r){const{status:n,ctx:i}=this._processInputParams(r);if(i.parsedType!==kr.map)return dr(i,{code:Vt.invalid_type,expected:kr.map,received:i.parsedType}),an;const s=this._def.keyType,o=this._def.valueType,a=[...i.data.entries()].map(([l,d],u)=>({key:s._parse(new Vm(i,l,i.path,[u,"key"])),value:o._parse(new Vm(i,d,i.path,[u,"value"]))}));if(i.common.async){const l=new Map;return Promise.resolve().then(async()=>{for(const d of a){const u=await d.key,f=await d.value;if(u.status==="aborted"||f.status==="aborted")return an;(u.status==="dirty"||f.status==="dirty")&&n.dirty(),l.set(u.value,f.value)}return{status:n.value,value:l}})}else{const l=new Map;for(const d of a){const u=d.key,f=d.value;if(u.status==="aborted"||f.status==="aborted")return an;(u.status==="dirty"||f.status==="dirty")&&n.dirty(),l.set(u.value,f.value)}return{status:n.value,value:l}}}}zV.create=(e,r,n)=>new zV({valueType:r,keyType:e,typeName:ln.ZodMap,...Cn(n)});class Yw extends qn{_parse(r){const{status:n,ctx:i}=this._processInputParams(r);if(i.parsedType!==kr.set)return dr(i,{code:Vt.invalid_type,expected:kr.set,received:i.parsedType}),an;const s=this._def;s.minSize!==null&&i.data.size<s.minSize.value&&(dr(i,{code:Vt.too_small,minimum:s.minSize.value,type:"set",inclusive:!0,exact:!1,message:s.minSize.message}),n.dirty()),s.maxSize!==null&&i.data.size>s.maxSize.value&&(dr(i,{code:Vt.too_big,maximum:s.maxSize.value,type:"set",inclusive:!0,exact:!1,message:s.maxSize.message}),n.dirty());const o=this._def.valueType;function a(d){const u=new Set;for(const f of d){if(f.status==="aborted")return an;f.status==="dirty"&&n.dirty(),u.add(f.value)}return{status:n.value,value:u}}const l=[...i.data.values()].map((d,u)=>o._parse(new Vm(i,d,i.path,u)));return i.common.async?Promise.all(l).then(d=>a(d)):a(l)}min(r,n){return new Yw({...this._def,minSize:{value:r,message:Ar.toString(n)}})}max(r,n){return new Yw({...this._def,maxSize:{value:r,message:Ar.toString(n)}})}size(r,n){return this.min(r,n).max(r,n)}nonempty(r){return this.min(1,r)}}Yw.create=(e,r)=>new Yw({valueType:e,minSize:null,maxSize:null,typeName:ln.ZodSet,...Cn(r)});class FV extends qn{get schema(){return this._def.getter()}_parse(r){const{ctx:n}=this._processInputParams(r);return this._def.getter()._parse({data:n.data,path:n.path,parent:n})}}FV.create=(e,r)=>new FV({getter:e,typeName:ln.ZodLazy,...Cn(r)});class HV extends qn{_parse(r){if(r.data!==this._def.value){const n=this._getOrReturnCtx(r);return dr(n,{received:n.data,code:Vt.invalid_literal,expected:this._def.value}),an}return{status:"valid",value:r.data}}get value(){return this._def.value}}HV.create=(e,r)=>new HV({value:e,typeName:ln.ZodLiteral,...Cn(r)});function nue(e,r){return new mv({values:e,typeName:ln.ZodEnum,...Cn(r)})}class mv extends qn{_parse(r){if(typeof r.data!="string"){const n=this._getOrReturnCtx(r),i=this._def.values;return dr(n,{expected:Qn.joinValues(i),received:n.parsedType,code:Vt.invalid_type}),an}if(this._cache||(this._cache=new Set(this._def.values)),!this._cache.has(r.data)){const n=this._getOrReturnCtx(r),i=this._def.values;return dr(n,{received:n.data,code:Vt.invalid_enum_value,options:i}),an}return ju(r.data)}get options(){return this._def.values}get enum(){const r={};for(const n of this._def.values)r[n]=n;return r}get Values(){const r={};for(const n of this._def.values)r[n]=n;return r}get Enum(){const r={};for(const n of this._def.values)r[n]=n;return r}extract(r,n=this._def){return mv.create(r,{...this._def,...n})}exclude(r,n=this._def){return mv.create(this.options.filter(i=>!r.includes(i)),{...this._def,...n})}}mv.create=nue;class WV extends qn{_parse(r){const n=Qn.getValidEnumValues(this._def.values),i=this._getOrReturnCtx(r);if(i.parsedType!==kr.string&&i.parsedType!==kr.number){const s=Qn.objectValues(n);return dr(i,{expected:Qn.joinValues(s),received:i.parsedType,code:Vt.invalid_type}),an}if(this._cache||(this._cache=new Set(Qn.getValidEnumValues(this._def.values))),!this._cache.has(r.data)){const s=Qn.objectValues(n);return dr(i,{received:i.data,code:Vt.invalid_enum_value,options:s}),an}return ju(r.data)}get enum(){return this._def.values}}WV.create=(e,r)=>new WV({values:e,typeName:ln.ZodNativeEnum,...Cn(r)});class j4 extends qn{unwrap(){return this._def.type}_parse(r){const{ctx:n}=this._processInputParams(r);if(n.parsedType!==kr.promise&&n.common.async===!1)return dr(n,{code:Vt.invalid_type,expected:kr.promise,received:n.parsedType}),an;const i=n.parsedType===kr.promise?n.data:Promise.resolve(n.data);return ju(i.then(s=>this._def.type.parseAsync(s,{path:n.path,errorMap:n.common.contextualErrorMap})))}}j4.create=(e,r)=>new j4({type:e,typeName:ln.ZodPromise,...Cn(r)});class gv extends qn{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===ln.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(r){const{status:n,ctx:i}=this._processInputParams(r),s=this._def.effect||null,o={addIssue:a=>{dr(i,a),a.fatal?n.abort():n.dirty()},get path(){return i.path}};if(o.addIssue=o.addIssue.bind(o),s.type==="preprocess"){const a=s.transform(i.data,o);if(i.common.async)return Promise.resolve(a).then(async l=>{if(n.value==="aborted")return an;const d=await this._def.schema._parseAsync({data:l,path:i.path,parent:i});return d.status==="aborted"?an:d.status==="dirty"||n.value==="dirty"?y_(d.value):d});{if(n.value==="aborted")return an;const l=this._def.schema._parseSync({data:a,path:i.path,parent:i});return l.status==="aborted"?an:l.status==="dirty"||n.value==="dirty"?y_(l.value):l}}if(s.type==="refinement"){const a=l=>{const d=s.refinement(l,o);if(i.common.async)return Promise.resolve(d);if(d instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return l};if(i.common.async===!1){const l=this._def.schema._parseSync({data:i.data,path:i.path,parent:i});return l.status==="aborted"?an:(l.status==="dirty"&&n.dirty(),a(l.value),{status:n.value,value:l.value})}else return this._def.schema._parseAsync({data:i.data,path:i.path,parent:i}).then(l=>l.status==="aborted"?an:(l.status==="dirty"&&n.dirty(),a(l.value).then(()=>({status:n.value,value:l.value}))))}if(s.type==="transform")if(i.common.async===!1){const a=this._def.schema._parseSync({data:i.data,path:i.path,parent:i});if(!fv(a))return an;const l=s.transform(a.value,o);if(l instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:n.value,value:l}}else return this._def.schema._parseAsync({data:i.data,path:i.path,parent:i}).then(a=>fv(a)?Promise.resolve(s.transform(a.value,o)).then(l=>({status:n.value,value:l})):an);Qn.assertNever(s)}}gv.create=(e,r,n)=>new gv({schema:e,typeName:ln.ZodEffects,effect:r,...Cn(n)});gv.createWithPreprocess=(e,r,n)=>new gv({schema:r,effect:{type:"preprocess",transform:e},typeName:ln.ZodEffects,...Cn(n)});class Lm extends qn{_parse(r){return this._getType(r)===kr.undefined?ju(void 0):this._def.innerType._parse(r)}unwrap(){return this._def.innerType}}Lm.create=(e,r)=>new Lm({innerType:e,typeName:ln.ZodOptional,...Cn(r)});class yv extends qn{_parse(r){return this._getType(r)===kr.null?ju(null):this._def.innerType._parse(r)}unwrap(){return this._def.innerType}}yv.create=(e,r)=>new yv({innerType:e,typeName:ln.ZodNullable,...Cn(r)});class U7 extends qn{_parse(r){const{ctx:n}=this._processInputParams(r);let i=n.data;return n.parsedType===kr.undefined&&(i=this._def.defaultValue()),this._def.innerType._parse({data:i,path:n.path,parent:n})}removeDefault(){return this._def.innerType}}U7.create=(e,r)=>new U7({innerType:e,typeName:ln.ZodDefault,defaultValue:typeof r.default=="function"?r.default:()=>r.default,...Cn(r)});class V7 extends qn{_parse(r){const{ctx:n}=this._processInputParams(r),i={...n,common:{...n.common,issues:[]}},s=this._def.innerType._parse({data:i.data,path:i.path,parent:{...i}});return w4(s)?s.then(o=>({status:"valid",value:o.status==="valid"?o.value:this._def.catchValue({get error(){return new Xf(i.common.issues)},input:i.data})})):{status:"valid",value:s.status==="valid"?s.value:this._def.catchValue({get error(){return new Xf(i.common.issues)},input:i.data})}}removeCatch(){return this._def.innerType}}V7.create=(e,r)=>new V7({innerType:e,typeName:ln.ZodCatch,catchValue:typeof r.catch=="function"?r.catch:()=>r.catch,...Cn(r)});class UV extends qn{_parse(r){if(this._getType(r)!==kr.nan){const i=this._getOrReturnCtx(r);return dr(i,{code:Vt.invalid_type,expected:kr.nan,received:i.parsedType}),an}return{status:"valid",value:r.data}}}UV.create=e=>new UV({typeName:ln.ZodNaN,...Cn(e)});class Opt extends qn{_parse(r){const{ctx:n}=this._processInputParams(r),i=n.data;return this._def.type._parse({data:i,path:n.path,parent:n})}unwrap(){return this._def.type}}class IP extends qn{_parse(r){const{status:n,ctx:i}=this._processInputParams(r);if(i.common.async)return(async()=>{const o=await this._def.in._parseAsync({data:i.data,path:i.path,parent:i});return o.status==="aborted"?an:o.status==="dirty"?(n.dirty(),y_(o.value)):this._def.out._parseAsync({data:o.value,path:i.path,parent:i})})();{const s=this._def.in._parseSync({data:i.data,path:i.path,parent:i});return s.status==="aborted"?an:s.status==="dirty"?(n.dirty(),{status:"dirty",value:s.value}):this._def.out._parseSync({data:s.value,path:i.path,parent:i})}}static create(r,n){return new IP({in:r,out:n,typeName:ln.ZodPipeline})}}class q7 extends qn{_parse(r){const n=this._def.innerType._parse(r),i=s=>(fv(s)&&(s.value=Object.freeze(s.value)),s);return w4(n)?n.then(s=>i(s)):i(n)}unwrap(){return this._def.innerType}}q7.create=(e,r)=>new q7({innerType:e,typeName:ln.ZodReadonly,...Cn(r)});var ln;(function(e){e.ZodString="ZodString",e.ZodNumber="ZodNumber",e.ZodNaN="ZodNaN",e.ZodBigInt="ZodBigInt",e.ZodBoolean="ZodBoolean",e.ZodDate="ZodDate",e.ZodSymbol="ZodSymbol",e.ZodUndefined="ZodUndefined",e.ZodNull="ZodNull",e.ZodAny="ZodAny",e.ZodUnknown="ZodUnknown",e.ZodNever="ZodNever",e.ZodVoid="ZodVoid",e.ZodArray="ZodArray",e.ZodObject="ZodObject",e.ZodUnion="ZodUnion",e.ZodDiscriminatedUnion="ZodDiscriminatedUnion",e.ZodIntersection="ZodIntersection",e.ZodTuple="ZodTuple",e.ZodRecord="ZodRecord",e.ZodMap="ZodMap",e.ZodSet="ZodSet",e.ZodFunction="ZodFunction",e.ZodLazy="ZodLazy",e.ZodLiteral="ZodLiteral",e.ZodEnum="ZodEnum",e.ZodEffects="ZodEffects",e.ZodNativeEnum="ZodNativeEnum",e.ZodOptional="ZodOptional",e.ZodNullable="ZodNullable",e.ZodDefault="ZodDefault",e.ZodCatch="ZodCatch",e.ZodPromise="ZodPromise",e.ZodBranded="ZodBranded",e.ZodPipeline="ZodPipeline",e.ZodReadonly="ZodReadonly"})(ln||(ln={}));const Si=Nm.create,v_=pv.create,y1=H7.create;qm.create;const Rpt=Nh.create,Zf=Bs.create;k4.create;C4.create;I0.create;const VS=mv.create;j4.create;Lm.create;yv.create;const Mpt=VS(ipt),Ppt=Zf({supportsStreaming:y1(),supportsInput:y1(),supportsSnapshot:y1(),supportsRecording:y1(),requiresConsent:y1(),maxConcurrent:v_().int().positive()});Zf({id:Si(),type:Mpt,status:VS(["connected","disconnected","error"]),capabilities:Ppt,deviceId:Si(),connectedAt:Si().nullable()});Zf({workspaceId:Si().optional(),name:Si().max(200).optional(),workspacePath:Si().optional()});Zf({id:Si(),workspaceId:Si().nullable(),name:Si().nullable(),workspacePath:Si().nullable(),status:VS(["active","archived","deleted"]),createdAt:Si(),lastActiveAt:Si(),metadata:Si().nullable()});const Lpt=VS(["pending","approved","executing","executed","completed","failed","reverted"]);Zf({action_id:Si(),status:Lpt,surface:Si(),device_id:Si().optional(),preview:Zf({command:Si().optional(),description:Si(),side_effects:Rpt(Si())}).optional(),consent_url:Si().url().optional(),expires_at:Si().datetime().optional()});Zf({id:Si(),role:VS(["user","assistant","system","tool"]),content:Si(),timestamp:Si().datetime(),sessionId:Si()});Zf({content:Si().min(1).max(1e5),sessionId:Si().uuid()});Zf({version:Si(),uptime:v_(),sessions:v_().int(),surfaces:v_().int(),devices:v_().int(),healthy:y1()});function $pt(e){let r=0;for(let n=0;n<e.length;n++)r=Math.imul(31,r)+e.charCodeAt(n)|0;return r}function Dpt(e){const r=e.title.trim(),n=e.body.trim();return!r&&!n?null:{...e,title:r||n,body:r?n:""}}async function G7(e){var s,o,a,l,d;const r=Dpt(e);if(!r)return;const n={level:"info",includeToast:!0,...r},i=(o=(s=window.Capacitor)==null?void 0:s.Plugins)==null?void 0:o.LocalNotifications;if((a=window.jaitDesktop)!=null&&a.notify)await window.jaitDesktop.notify({title:n.title,body:n.body});else if(i)try{const u=await((l=i.requestPermissions)==null?void 0:l.call(i));if((u==null?void 0:u.display)==="granted")await((d=i.schedule)==null?void 0:d.call(i,{notifications:[{id:Math.abs($pt(n.id)),title:n.title,body:n.body,schedule:{at:new Date}}]}));else throw new Error("notification permission denied")}catch{"Notification"in window&&(Notification.permission==="granted"?new Notification(n.title,{body:n.body,tag:n.id}):Notification.permission!=="denied"&&await Notification.requestPermission()==="granted"&&new Notification(n.title,{body:n.body,tag:n.id}))}else"Notification"in window&&(Notification.permission==="granted"?new Notification(n.title,{body:n.body,tag:n.id}):Notification.permission!=="denied"&&await Notification.requestPermission()==="granted"&&new Notification(n.title,{body:n.body,tag:n.id}));n.includeToast&&(n.level==="error"?fi.error:n.level==="warning"?fi.warning:n.level==="success"?fi.success:fi.info)(n.title,{description:n.body})}const Ipt=Y0();function VV(){const e=To(),r=navigator.userAgent;return e==="electron"?`Desktop (${navigator.platform})`:e==="capacitor"?"Mobile":r.includes("Chrome")?`Chrome (${navigator.platform})`:r.includes("Firefox")?`Firefox (${navigator.platform})`:r.includes("Safari")?`Safari (${navigator.platform})`:`Browser (${navigator.platform})`}function qV(){var r;const e=To();if(e==="capacitor")return"android";if(e==="electron"){const n=((r=navigator.platform)==null?void 0:r.toLowerCase())??"";return n.includes("win")?"windows":n.includes("mac")?"macos":"linux"}return"web"}function Bpt(){const e=To();return e==="electron"||e==="capacitor"}function zpt(e){const{listeners:r,sessionId:n,token:i,onStateSync:s,onFullState:o,onMessageComplete:a,onThreadEvent:l,onFsChanges:d,onConnectionStateChange:u,onPreviewSessionEvent:f}=e,p=y.useRef(r);p.current=r;const g=y.useRef(s);g.current=s;const v=y.useRef(o);v.current=o;const b=y.useRef(a);b.current=a;const _=y.useRef(l);_.current=l;const k=y.useRef(f);k.current=f;const w=y.useRef(d);w.current=d;const C=y.useRef(u);C.current=u;const j=y.useRef(null),N=y.useRef(null),A=y.useRef(!0),E=y.useRef(!1),R=y.useRef(i);R.current=i;const L=y.useRef(n);L.current=n;const z=y.useRef([]),$=y.useCallback(q=>{for(;z.current.length>0&&q.readyState===WebSocket.OPEN;){const ee=z.current.shift();q.send(ee)}},[]),W=y.useCallback((q,ee)=>{!ee||q.readyState!==WebSocket.OPEN||(q.send(JSON.stringify({type:"subscribe",sessionId:ee})),N.current=ee)},[]),B=y.useCallback(async q=>{await G7({id:q.id,title:q.title,body:q.body,level:q.level,includeToast:!0})},[]),K=y.useCallback(q=>{var ee,te,ue,fe,re;try{const ie=JSON.parse(q.data);if(ie.type==="ui.command"){const ge=ie.payload,le=p.current[ge.command];le&&le(ge.data)}else if(ie.type==="ui.state-sync"){const ge=ie.payload;ge!=null&&ge.key&&g.current&&g.current(ge.key,ge.value??null)}else if(ie.type==="ui.full-state"){const ge=ie.payload;ge&&v.current&&v.current(ge)}else if(ie.type==="message.complete")(ee=b.current)==null||ee.call(b);else if(ie.type==="fs.changes"){const ge=ie.payload;(te=w.current)==null||te.call(w,ge)}else if(ie.type==="fs.browse-request")P(ie.payload);else if(ie.type==="fs.roots-request")F(ie.payload);else if(ie.type==="fs.op-request")V(ie.payload);else if(ie.type==="provider.op-request")Y(ie.payload);else if(ie.type==="tool.op-request")H(ie.payload);else if(ie.type==="notification")B(ie.payload);else if(ie.type.startsWith("thread.")||ie.type.startsWith("repo.")||ie.type.startsWith("plan.")||ie.type.startsWith("fs.node-")||ie.type.startsWith("node."))(ue=_.current)==null||ue.call(_,ie.type,ie.payload);else if(ie.type==="preview.session"){const ge=(fe=ie.payload)==null?void 0:fe.session;ge&&((re=k.current)==null||re.call(k,ge))}}catch{}},[]),M=y.useCallback(async q=>{const ee="@capacitor/filesystem",{Filesystem:te,Directory:ue}=await import(ee);let fe,re=q;q==="~"||q==="/storage"||q==="/"?(fe=ue.ExternalStorage,re=""):q.startsWith("/storage/emulated/0")&&(fe=ue.ExternalStorage,re=q.replace("/storage/emulated/0","").replace(/^\//,""));const ie=await te.readdir({path:re||"",...fe?{directory:fe}:{}}),ge=fe===ue.ExternalStorage?"/storage/emulated/0"+(re?"/"+re:""):q,le=[];for(const De of ie.files)De.name.startsWith(".")||le.push({name:De.name,path:ge+"/"+De.name,type:De.type==="directory"?"dir":"file"});le.sort((De,de)=>De.type!==de.type?De.type==="dir"?-1:1:De.name.localeCompare(de.name));const et=ge.replace(/\/+$/,"").split("/"),Xe=et.length>3?et.slice(0,-1).join("/"):null;return{path:ge,parent:Xe,entries:le}},[]),I=y.useCallback(async()=>[{name:"Internal Storage",path:"/storage/emulated/0",type:"dir"},{name:"Documents",path:"/storage/emulated/0/Documents",type:"dir"},{name:"Downloads",path:"/storage/emulated/0/Download",type:"dir"},{name:"Home",path:"/storage/emulated/0",type:"dir"}],[]),P=y.useCallback(async q=>{var fe;const ee=j.current;if(!ee||ee.readyState!==WebSocket.OPEN)return;const{requestId:te,path:ue}=q;try{let re;const ie=To();if(ie==="electron"&&((fe=window.jaitDesktop)!=null&&fe.browsePath))re=await window.jaitDesktop.browsePath(ue);else if(ie==="capacitor")re=await M(ue);else throw new Error("Local filesystem browsing not supported on this platform");ee.send(JSON.stringify({type:"fs.browse-response",payload:{requestId:te,path:re.path,parent:re.parent,entries:re.entries}}))}catch(re){ee.send(JSON.stringify({type:"fs.browse-response",payload:{requestId:te,error:re instanceof Error?re.message:"Browse failed"}}))}},[M]),F=y.useCallback(async q=>{var ue;const ee=j.current;if(!ee||ee.readyState!==WebSocket.OPEN)return;const{requestId:te}=q;try{let fe;const re=To();if(re==="electron"&&((ue=window.jaitDesktop)!=null&&ue.getRoots))fe=(await window.jaitDesktop.getRoots()).roots;else if(re==="capacitor")fe=await I();else throw new Error("Local filesystem browsing not supported on this platform");ee.send(JSON.stringify({type:"fs.roots-response",payload:{requestId:te,roots:fe}}))}catch(fe){ee.send(JSON.stringify({type:"fs.roots-response",payload:{requestId:te,error:fe instanceof Error?fe.message:"Roots request failed"}}))}},[I]),V=y.useCallback(async q=>{var re;const ee=j.current;if(!ee||ee.readyState!==WebSocket.OPEN)return;const{requestId:te,op:ue,...fe}=q;try{const ie=To();if(ie==="electron"&&((re=window.jaitDesktop)!=null&&re.fsOp)){const ge=await window.jaitDesktop.fsOp(ue,fe);ee.send(JSON.stringify({type:"fs.op-response",payload:{requestId:te,result:ge}}))}else throw ie==="capacitor"?new Error("Full filesystem operations not yet supported on mobile"):new Error("Filesystem operations not supported on this platform")}catch(ie){ee.send(JSON.stringify({type:"fs.op-response",payload:{requestId:te,error:ie instanceof Error?ie.message:"Filesystem operation failed"}}))}},[]),Y=y.useCallback(async q=>{var re;const ee=j.current;if(!ee||ee.readyState!==WebSocket.OPEN)return;const{requestId:te,op:ue,...fe}=q;try{if(To()==="electron"&&((re=window.jaitDesktop)!=null&&re.providerOp)){const ge=await window.jaitDesktop.providerOp(ue,fe);ee.send(JSON.stringify({type:"provider.op-response",payload:{requestId:te,result:ge}}))}else throw new Error("Provider operations not supported on this platform")}catch(ie){ee.send(JSON.stringify({type:"provider.op-response",payload:{requestId:te,error:ie instanceof Error?ie.message:"Provider operation failed"}}))}},[]),H=y.useCallback(async q=>{var ge;const ee=j.current;if(!ee||ee.readyState!==WebSocket.OPEN)return;const{requestId:te,tool:ue,args:fe,sessionId:re,workspaceRoot:ie}=q;try{if(To()==="electron"&&((ge=window.jaitDesktop)!=null&&ge.toolOp)){const et=await window.jaitDesktop.toolOp(ue,fe,{sessionId:re,workspaceRoot:ie});ee.send(JSON.stringify({type:"tool.op-response",payload:{requestId:te,result:et}}))}else throw new Error("Tool execution not supported on this platform")}catch(le){ee.send(JSON.stringify({type:"tool.op-response",payload:{requestId:te,error:le instanceof Error?le.message:"Tool execution failed"}}))}},[]);y.useEffect(()=>{var ge;if(!i)return;A.current=!0;let q=null,ee=!1;const te=()=>{q&&(clearTimeout(q),q=null)},ue=()=>{const le=j.current;le&&(le.onclose=null,le.close(),j.current=null,N.current=null)},fe=()=>{if(!A.current||typeof document<"u"&&document.hidden)return;const le=new WebSocket(`${Ipt}?token=${R.current??"dev"}`);j.current=le,le.onopen=()=>{var De;const et=E.current;E.current=!0,(De=C.current)==null||De.call(C,{connected:!0,reconnected:et}),le.send(JSON.stringify({type:"resource.subscribe",payload:{resource:"root:/nodes"}})),le.send(JSON.stringify({type:"resource.subscribe",payload:{resource:"root:/threads"}})),le.send(JSON.stringify({type:"resource.subscribe",payload:{resource:"root:/surfaces"}})),le.send(JSON.stringify({type:"resource.subscribe",payload:{resource:"root:/browser"}}));const Xe=L.current;Xe&&W(le,Xe),$(le),Bpt()&&Dft().then(async de=>{var qe;let Qe=[];if(To()==="electron"&&((qe=window.jaitDesktop)!=null&&qe.detectProviders))try{Qe=await window.jaitDesktop.detectProviders()}catch{}const Ie=JSON.stringify({type:"node.hello",payload:{id:de,name:VV(),platform:qV(),role:To()==="electron"?"desktop":"mobile",protocolVersion:spt,capabilities:{providers:Qe,surfaces:["filesystem"],tools:[],screenShare:!0,voice:!1,preview:!1}}});le.readyState===WebSocket.OPEN&&le.send(Ie);const Oe=JSON.stringify({type:"fs.register-node",payload:{id:de,name:VV(),platform:qV(),providers:Qe}});le.readyState===WebSocket.OPEN&&le.send(Oe)})},le.onmessage=K,le.onclose=()=>{var et;j.current=null,N.current=null,(et=C.current)==null||et.call(C,{connected:!1,reconnected:!1}),A.current&&!ee&&(q=setTimeout(fe,1e3))},le.onerror=()=>{}},re=()=>{const le=typeof document<"u"&&document.hidden;if(ee=le,le){te(),ue();return}j.current||fe()};fe(),typeof document<"u"&&document.addEventListener("visibilitychange",re);const ie=(le,et)=>{if((et==null?void 0:et.type)==="provider.event-from-child"){const Xe=j.current;Xe&&Xe.readyState===WebSocket.OPEN&&Xe.send(JSON.stringify({type:"provider.event",payload:{sessionId:et.sessionId,event:et.notification}}))}};return To()==="electron"&&((ge=window.jaitDesktop)!=null&&ge.onGatewayEvent)&&window.jaitDesktop.onGatewayEvent(ie),()=>{var le;A.current=!1,te(),typeof document<"u"&&document.removeEventListener("visibilitychange",re),To()==="electron"&&((le=window.jaitDesktop)!=null&&le.removeGatewayEventListener)&&window.jaitDesktop.removeGatewayEventListener(),ue()}},[i]),y.useEffect(()=>{const q=j.current;q&&q.readyState===WebSocket.OPEN&&n!==N.current&&W(q,n??null),L.current=n??null},[n,W]);const U=y.useCallback((q,ee,te)=>{const ue=JSON.stringify({type:"ui.state",payload:{sessionId:te??"",key:q,value:ee}}),fe=j.current;fe&&fe.readyState===WebSocket.OPEN?fe.send(ue):z.current.push(ue)},[]),Q=y.useCallback((q,ee)=>{const te=JSON.stringify({type:"architecture.render-result",payload:{requestId:q,ok:ee.ok,...ee.ok?{}:{error:ee.error}}}),ue=j.current;ue&&ue.readyState===WebSocket.OPEN?ue.send(te):z.current.push(te)},[]);return{sendUIState:U,sendArchitectureRenderResult:Q}}const Fpt=$n();function Hpt(e){return{"Content-Type":"application/json",Authorization:`Bearer ${e}`}}const Uk=new Map;function iue(e,r,n,i){const s=`${e}:${r}`;let o=Uk.get(s);return o||(o={keys:new Set,callbacks:new Map,token:i},Uk.set(s,o),queueMicrotask(()=>{const a=Uk.get(s);if(!a)return;Uk.delete(s);const l=[...a.keys].join(",");fetch(`${Fpt}/api/${e}/${r}/state?keys=${encodeURIComponent(l)}`,{headers:Hpt(a.token)}).then(d=>d.ok?d.json():null).then(d=>{for(const[u,f]of a.callbacks){const p=(d==null?void 0:d[u])??null;for(const g of f)g.resolve(p)}}).catch(d=>{for(const u of a.callbacks.values())for(const f of u)f.reject(d)})})),o.keys.add(n),new Promise((a,l)=>{let d=o.callbacks.get(n);d||(d=[],o.callbacks.set(n,d)),d.push({resolve:a,reject:l})})}const Wpt=$n();function Upt(e){const r={"Content-Type":"application/json"};return e&&(r.Authorization=`Bearer ${e}`),r}function Vpt(e,r,n){return{method:"PATCH",headers:Upt(e),body:JSON.stringify({[r]:n})}}function qpt(e,r){return e===r}function Ju(e,r,n){const[i,s]=y.useState(null),[o,a]=y.useState(!1),l=y.useRef(null),d=y.useRef(null),u=y.useRef(0);y.useEffect(()=>{if(!e||!n){s(null);return}s(null),d.current=null;let p=!1;const g=u.current;return a(!0),iue("sessions",e,r,n).then(v=>{p||qpt(g,u.current)&&(s(v),d.current=v)}).catch(()=>{p||s(null)}).finally(()=>{p||a(!1)}),()=>{p=!0}},[e,r,n]);const f=y.useCallback(p=>{u.current+=1,s(p),d.current=p,!(!e||!n)&&(l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{fetch(`${Wpt}/api/sessions/${e}/state`,{...Vpt(n,r,d.current)}).catch(()=>{})},300))},[e,r,n]);return y.useEffect(()=>()=>{l.current&&clearTimeout(l.current)},[]),[i,f,o]}const Gpt=$n();function Kpt(e){const r={"Content-Type":"application/json"};return e&&(r.Authorization=`Bearer ${e}`),r}function Ypt(e,r,n,i){return{method:"PATCH",headers:Kpt(e),body:JSON.stringify({[r]:n}),keepalive:(i==null?void 0:i.immediate)===!0}}function Xpt(e,r,n){const[i,s]=y.useState(null),[o,a]=y.useState(!1),l=y.useRef(null),d=y.useRef(null);y.useEffect(()=>{if(!e||!n){s(null);return}s(null);let f=!1;return a(!0),iue("workspaces",e,r,n).then(p=>{if(f)return;const g=p;s(g),d.current=g}).catch(()=>{f||s(null)}).finally(()=>{f||a(!1)}),()=>{f=!0}},[e,r,n]);const u=y.useCallback((f,p)=>{if(s(f),d.current=f,!e||!n)return;l.current&&clearTimeout(l.current);const g=()=>{fetch(`${Gpt}/api/workspaces/${e}/state`,{...Ypt(n,r,d.current,p)}).catch(()=>{})};if(p!=null&&p.immediate){g();return}l.current=setTimeout(()=>{g()},300)},[e,r,n]);return y.useEffect(()=>()=>{l.current&&clearTimeout(l.current)},[]),[i,u,o]}const K7="jait:selected-repo-id";function Y7(e){if(e&&typeof e=="object"&&!Array.isArray(e)){const r=e;return{repoId:typeof r.repoId=="string"&&r.repoId.trim()?r.repoId.trim():null,localPath:typeof r.localPath=="string"&&r.localPath.trim()?r.localPath.trim():null}}return typeof e=="string"?{repoId:e.trim()||null,localPath:null}:{repoId:null,localPath:null}}function Zpt(e){try{return Y7(JSON.parse(e))}catch{}return Y7(e)}function BP(){var e;if(typeof window>"u")return{repoId:null,localPath:null};try{const r=(e=window.localStorage.getItem(K7))==null?void 0:e.trim();return r?Zpt(r):{repoId:null,localPath:null}}catch{return{repoId:null,localPath:null}}}function Jpt(){return BP().repoId}function Qpt(e,r){if(!(typeof window>"u"))try{const n=(e==null?void 0:e.trim())||null;n?window.localStorage.setItem(K7,JSON.stringify({repoId:n,localPath:(r==null?void 0:r.trim())||null})):window.localStorage.removeItem(K7)}catch{}}function sue(e,r=BP()){var n;return r.repoId&&e.some(i=>i.id===r.repoId)?r.repoId:r.localPath?((n=e.find(i=>i.localPath===r.localPath))==null?void 0:n.id)??null:null}function emt(e,r,n=BP()){var s;if(e.length===0)return r;const i=sue(e,n);return(!r||e.every(o=>o.id!==r))&&i?i:r?e.every(o=>o.id!==r)?((s=e[0])==null?void 0:s.id)??null:r:e[0].id}function Wb(e){return{id:e.id,name:e.name,defaultBranch:e.defaultBranch,localPath:e.localPath,deviceId:e.deviceId,forgeUrl:e.forgeUrl,githubUrl:e.githubUrl,source:"local"}}function N4(e){return e.replace(/\\/g,"/").replace(/\/+$/,"")}function tmt(e){const n=N4(e).split("/").filter(Boolean);return n[n.length-1]??e}function rmt(e){var n;const r=e.match(/^\[([^\]]+)\]/);return((n=r==null?void 0:r[1])==null?void 0:n.trim())||null}function oue(e){if(!e)return null;const n=N4(e).split("/").filter(Boolean),i=n.lastIndexOf("worktrees");return i===-1?null:n[i+1]??null}function v6(e){return rmt(e.title)??oue(e.workingDirectory)??(e.workingDirectory?tmt(e.workingDirectory):null)}function X7(e,r){var l,d;const n=r.name.trim().toLowerCase(),i=(l=v6(e))==null?void 0:l.toLowerCase(),s=e.workingDirectory?N4(e.workingDirectory):null,o=N4(r.localPath);if(s&&(s===o||s.startsWith(`${o}/`)))return!0;const a=(d=oue(e.workingDirectory))==null?void 0:d.toLowerCase();return a&&a===n?!0:i===n}function nmt(e,r){const n=[],i=new Set;for(const s of e){if(r.some(l=>X7(s,l)))continue;const o=v6(s),a=o==null?void 0:o.trim().toLowerCase();!o||!a||i.has(a)||(n.push({id:`shared:${a}`,name:o,defaultBranch:"main",localPath:s.workingDirectory??o,source:"shared"}),i.add(a))}return n}function imt(e){return e==="jait"||e==="codex"||e==="claude-code"?e:null}function smt(e){const r=new Set;for(const n of e){const i=imt(n);i&&r.add(i)}return[...r]}function omt(e,r){const{localDeviceId:n,localProviders:i,remoteProviders:s,providersLoaded:o}=r;if(!e.deviceId)return{hostType:"gateway",locationLabel:"Gateway",online:!0,loading:!1,availableProviders:i.filter(u=>u.available).map(u=>u.id)};const a=s.find(u=>u.nodeId===e.deviceId),l=e.deviceId===n?"This device":(a==null?void 0:a.nodeName)??"Desktop app",d=!!a;return{hostType:"device",locationLabel:l,online:d,loading:!d&&!o,availableProviders:smt((a==null?void 0:a.providers)??[])}}function GV(e,r){return e.githubUrl?`Couldn't reach ${r.locationLabel}.`:r.hostType==="device"&&!r.online?`${r.locationLabel==="This device"?"This desktop app":r.locationLabel} is offline and no GitHub URL is configured for gateway fallback. Reconnect it or pick a connected repo/device.`:"No GitHub URL is configured for this repo, so the gateway cannot clone it as a fallback."}function amt(e,r){return e!=null&&e.state?e.state:r==="creating"||r==="open"||r==="closed"||r==="merged"?r:null}const f8=10;function lmt(e){const n=e.replace(/\\/g,"/").split("/").filter(Boolean);return n[n.length-1]??e}function cmt(){return`jait/${Math.random().toString(16).slice(2,10)}`}function Z7(e){return[...e].sort((r,n)=>new Date(r.createdAt).getTime()-new Date(n.createdAt).getTime())}function umt(e,r){if(r.length===0)return e;const n=new Map(e.map(i=>[i.id,i]));for(const i of r)n.set(i.id,i);return Z7([...n.values()])}function KV(e){for(let r=e.length-1;r>=0;r--){const n=e[r];if(n.kind==="todo"&&n.payload&&typeof n.payload=="object"&&"items"in n.payload)return n.payload.items}return[]}function Ub(e){return e.filter(r=>r.role!=="gateway").map(r=>({nodeId:r.id,nodeName:r.name,platform:r.platform,providers:r.capabilities.providers}))}function dmt(e=!0){const r=U0(),n=y.useMemo(()=>LP(),[]),[i,s]=y.useState([]),[o,a]=y.useState(()=>Jpt()),[l,d]=y.useState(!1),[u,f]=y.useState([]),[p,g]=y.useState(f8),[v,b]=y.useState(!1),[_,k]=y.useState(null),[w,C]=y.useState([]),[j,N]=y.useState({}),[A,E]=y.useState(!0),[R,L]=y.useState([]),[z,$]=y.useState([]),[W,B]=y.useState([]),[K,M]=y.useState(!1),[I,P]=y.useState(!1),[F,V]=y.useState(!1),[Y,H]=y.useState(null),U=y.useRef(new Map),[Q,q]=y.useState([]),ee=y.useRef(null),te=y.useRef(new Map),ue=y.useRef(new Set),fe=y.useMemo(()=>nmt(u,i),[u,i]),re=y.useMemo(()=>[...i,...fe],[i,fe]),ie=y.useMemo(()=>re.find(at=>at.id===o)??null,[re,o]),ge=y.useMemo(()=>u.find(at=>at.id===_)??null,[u,_]),le=ge?ge.id in j?j[ge.id]:ge.prState:null,et=y.useCallback(at=>re.find(ut=>X7(at,ut))??null,[re]),Xe=y.useMemo(()=>ge!=null&&ge.kind==="delivery"&&ie!=null&&(ge.status==="completed"||!!ge.prUrl||le==="creating"||le==="open"),[ge,ie,le]);y.useEffect(()=>{if(!e)return;const at=emt(re,o);at!==o&&a(at)},[re,o,e]),y.useEffect(()=>{e&&Qpt(o,(ie==null?void 0:ie.localPath)??null)},[e,o,ie]),y.useEffect(()=>{if(!e||!ge)return;const at=et(ge);at&&at.id!==o&&a(at.id)},[e,et,o,ge]);const De=y.useCallback(async()=>{if(h0()){M(!0);try{const[at,ut,Ht]=await Promise.all([Yr.listThreadsPage({limit:p}),Yr.listProviders(),Yr.listRepos()]);f(at.threads),b(at.hasMore),L(ut.providers),$(W.length>0?Ub(W):ut.remoteProviders),P(!0),s(Ht.map(Wb)),H(null)}catch(at){H(at instanceof Error?at.message:"Failed to fetch data")}finally{M(!1)}}},[p]),de=y.useCallback(async()=>{if(h0())try{const[at,ut]=await Promise.all([Yr.listProvidersFresh(),Yr.listRepos()]);L(at.providers),$(W.length>0?Ub(W):at.remoteProviders),s(ut.map(Wb))}catch{}},[W]),Qe=y.useCallback(at=>omt(at,{localDeviceId:n,localProviders:R,remoteProviders:z,providersLoaded:I}),[n,R,z,I]);y.useEffect(()=>{e&&De()},[De,e]);const Ie=y.useRef(_);Ie.current=_;const Oe=y.useCallback((at,ut)=>{var Ht;switch(at){case"thread.created":{const Fe=ut.thread;Fe&&f(Ye=>Ye.some(Pt=>Pt.id===Fe.id)?Ye:[Fe,...Ye]);break}case"thread.updated":{const Fe=ut;if(Array.isArray(Fe==null?void 0:Fe.threads)){f(Fe.threads);break}const Ye=ut.thread;Ye&&f(Pt=>Pt.map(ot=>ot.id===Ye.id?Ye:ot));break}case"thread.deleted":{const Fe=ut.threadId;Fe&&(te.current.delete(Fe),f(Ye=>Ye.filter(Pt=>Pt.id!==Fe)),Ie.current===Fe&&k(null));break}case"thread.status":{const Fe=ut.threadId,Ye=ut.status,Pt=ut.thread;Fe&&Ye&&f(ot=>Pt?ot.some(tt=>tt.id===Fe)?ot.map(tt=>tt.id===Fe?Pt:tt):[Pt,...ot]:ot.map(Yt=>Yt.id===Fe?{...Yt,status:Ye,error:Ye==="running"||Ye==="completed"?ut.error??null:ut.error??Yt.error}:Yt));break}case"thread.activity":{const Fe=ut.threadId,Ye=ut.activity;if(Fe&&Ye){const Pt=umt(te.current.get(Fe)??[],[Ye]);if(te.current.set(Fe,Pt),Fe===Ie.current&&C(Pt),Ye.kind==="todo"&&Ye.payload&&typeof Ye.payload=="object"&&"items"in Ye.payload){const ot=Ye.payload.items;U.current.set(Fe,ot),Fe===Ie.current&&q(ot)}}break}case"repo.created":{const Fe=ut.repo;Fe&&s(Ye=>Ye.some(Pt=>Pt.id===Fe.id)?Ye:[Wb(Fe),...Ye]);break}case"repo.updated":{const Fe=ut.repo;Fe&&s(Ye=>Ye.map(Pt=>Pt.id===Fe.id?Wb(Fe):Pt));break}case"repo.deleted":{const Fe=ut.repoId;Fe&&(s(Ye=>Ye.filter(Pt=>Pt.id!==Fe)),a(Ye=>Ye===Fe?null:Ye));break}case"fs.node-registered":case"fs.node-disconnected":{de();break}case"node.registry":{const Fe=ut,Ye=(Fe==null?void 0:Fe.nodes)??[];B(Ye),$(Ub(Ye)),P(!0);break}case"node.updated":{const Fe=ut;if(!Fe)break;B(Ye=>{const Pt=Ye.some(ot=>ot.id===Fe.id)?Ye.map(ot=>ot.id===Fe.id?Fe:ot):[...Ye,Fe];return $(Ub(Pt)),Pt}),P(!0);break}case"node.disconnected":{const Fe=ut.nodeId??((Ht=ut.node)==null?void 0:Ht.id);if(!Fe)break;B(Ye=>{const Pt=Ye.filter(ot=>ot.id!==Fe);return $(Ub(Pt)),Pt}),P(!0);break}}},[]);y.useEffect(()=>{if(!e||!_){C([]),q([]),V(!1);return}const at=te.current.get(_);at?(C(at),q(U.current.get(_)??KV(at)),V(!1)):(C([]),q([]),V(!0));let ut=!1;return(async()=>{if(h0())try{const Fe=await Yr.getActivities(_);if(!ut){const Ye=Z7(Fe);te.current.set(_,Ye),C(Ye);const Pt=KV(Ye);U.current.set(_,Pt),q(Pt)}}catch{}finally{ut||V(!1)}})(),()=>{ut=!0}},[_,e]);const qe=y.useCallback(async at=>{if(!ue.current.has(at)){ue.current.add(at);try{const[ut,Ht]=await Promise.all([Yr.getThread(at).catch(()=>null),Yr.getActivities(at).catch(()=>[])]);ut&&f(Ye=>Ye.some(ot=>ot.id===ut.id)?Ye.map(ot=>ot.id===ut.id?ut:ot):[ut,...Ye]);const Fe=Z7(Ht);te.current.set(at,Fe),at===Ie.current&&C(Fe)}finally{ue.current.delete(at)}}},[]);y.useEffect(()=>{var at;e&&((at=ee.current)==null||at.scrollIntoView({behavior:"smooth"}))},[w,e]);const kt=y.useMemo(()=>ie?u.filter(at=>X7(at,ie)).sort((at,ut)=>new Date(ut.updatedAt).getTime()-new Date(at.updatedAt).getTime()):[],[u,ie]),vt=y.useRef(0),Me=10;y.useEffect(()=>{if(!e||!ie){N({});return}const at=++vt.current,ut=ie.localPath,Ht=kt.filter(Pt=>Pt.kind==="delivery"&&typeof Pt.branch=="string"&&Pt.branch.length>0).slice(0,Me),Fe=async()=>{if(Ht.length===0){at===vt.current&&N({});return}const Pt=Ht.filter(Ge=>Ge.prState!=="merged"&&Ge.prState!=="closed"),ot=[];for(const Ge of Pt){if(at!==vt.current)return;try{const It=Ge.workingDirectory??ut,jt=await io.status(It,Ge.branch??void 0),Se=amt(jt.pr,Ge.prState);if(jt.ghAvailable&&jt.pr&&(Ge.prUrl!==jt.pr.url||Ge.prState!==jt.pr.state||Ge.prNumber!==jt.pr.number||Ge.prBaseBranch!==(jt.pr.baseBranch??null)))try{await Yr.updateThread(Ge.id,{prUrl:jt.pr.url,prNumber:jt.pr.number,prTitle:jt.pr.title??null,prBaseBranch:jt.pr.baseBranch??null,prState:jt.pr.state})}catch{}ot.push({threadId:Ge.id,prState:Se,ghAvailable:jt.ghAvailable})}catch{}}if(at!==vt.current)return;const Yt={};let tt=!1;for(const Ge of ot)Yt[Ge.threadId]=Ge.prState,Ge.ghAvailable&&(tt=!0);for(const Ge of Ht)!(Ge.id in Yt)&&(Ge.prState==="merged"||Ge.prState==="closed")&&(Yt[Ge.id]=Ge.prState);E(tt),N(Yt)};Fe();const Ye=setInterval(()=>{vt.current===at&&Fe()},6e4);return()=>clearInterval(Ye)},[e,kt,ie]);const nt=y.useCallback(async(at,ut)=>{const Ht=ut&&ut!=="gateway"?ut:void 0,Fe=i.find(ot=>ot.localPath===at);if(Fe){a(Fe.id);const ot={},Yt=Ht??"";if((Fe.deviceId??"")!==Yt&&(ot.deviceId=Yt),!Fe.githubUrl)try{const tt=await io.status(at);tt.remoteUrl&&(ot.githubUrl=tt.remoteUrl)}catch{}if(Object.keys(ot).length>0)try{await Yr.updateRepo(Fe.id,ot)}catch{}return}let Ye="main",Pt;try{const ot=await io.status(at);ot.branch&&(Ye=ot.branch),ot.remoteUrl&&(Pt=ot.remoteUrl)}catch{}try{const ot=await Yr.createRepo({name:lmt(at),defaultBranch:Ye,localPath:at,deviceId:Ht,githubUrl:Pt}),Yt=Wb(ot);s(tt=>tt.some(Ge=>Ge.id===Yt.id)?tt:[Yt,...tt]),a(Yt.id),H(null)}catch(ot){H(ot instanceof Error?ot.message:"Failed to create repository")}},[i]),Je=y.useCallback(async at=>{try{await Yr.deleteRepo(at)}catch{}s(ut=>ut.filter(Ht=>Ht.id!==at)),o===at&&a(null)},[o]),Ot=y.useCallback(async(at,ut,Ht="jait",Fe="full-access",Ye,Pt={})=>{if(!ut.trim())return;const ot=at?u.find(tt=>tt.id===at)??null:ge,Yt=ot?et(ot):ie;if(ot&&ot.providerSessionId&&ot.status!=="running")f(tt=>tt.map(Ge=>Ge.id===ot.id?{...Ge,status:"running",error:null,completedAt:null}:Ge)),await Yr.sendTurn(ot.id,{message:ut,...Pt}),qe(ot.id),De();else{if(ot&&ot.status==="running")return;if(ot&&(ot.status==="idle"||ot.status==="completed"||ot.status==="error"||ot.status==="interrupted"))try{f(Ge=>Ge.map(It=>It.id===ot.id?{...It,status:"running",error:null,completedAt:null}:It));const tt=await Yr.startThread(ot.id,{message:ut,...Pt});f(Ge=>Ge.map(It=>It.id===tt.id?tt:It)),qe(tt.id),De()}catch(tt){if(tt.code==="NODE_OFFLINE"&&Yt){const It=Yt.githubUrl;if(It&&await r({title:"Run on gateway instead?",description:"The desktop app is not connected. Clone the repo to the gateway and run the thread there?",confirmLabel:"Clone and run"})){const jt=await Yr.startThread(ot.id,{message:ut,cloneToGateway:!0,repoUrl:It,...Pt});f(Se=>Se.map($t=>$t.id===jt.id?jt:$t)),qe(jt.id),De()}else It||H(GV(Yt,Qe(Yt)))}else throw tt}else{if(!Yt)return;at||k(null);const tt=Yt;(async()=>{var Ge,It;try{const jt=cmt();let Se;try{Se=(await io.createWorktree(tt.localPath,tt.defaultBranch,jt)).path}catch{try{await io.createBranch(tt.localPath,jt,tt.defaultBranch)}catch{}}const $t=await Yr.createThread({title:`[${tt.name}] Generating title…`,providerId:Ht,runtimeMode:Fe,...Ye?{model:Ye}:{},kind:"delivery",workingDirectory:Se??tt.localPath,branch:jt});try{await Yr.startThread($t.id,{message:ut,titleTask:((Ge=Pt.displayContent)==null?void 0:Ge.trim())||ut,titlePrefix:`[${tt.name}] `,...Pt}),qe($t.id)}catch(Et){if(Et.code==="NODE_OFFLINE"){const mr=tt.githubUrl;mr&&await r({title:"Run on gateway instead?",description:"The desktop app is not connected. Clone the repo to the gateway and run the thread there?",confirmLabel:"Clone and run"})?(await Yr.startThread($t.id,{message:ut,titleTask:((It=Pt.displayContent)==null?void 0:It.trim())||ut,titlePrefix:`[${tt.name}] `,cloneToGateway:!0,repoUrl:mr,...Pt}),qe($t.id)):mr||H(GV(tt,Qe(tt)));return}throw Et}}catch(jt){H(jt instanceof Error?jt.message:"Failed to create thread")}})()}}},[r,Qe,et,qe,De,ie,ge,u]),be=y.useCallback(async(at,ut="jait",Ht="full-access",Fe,Ye)=>{await Ot((ge==null?void 0:ge.id)??null,at,ut,Ht,Fe,Ye)},[ge==null?void 0:ge.id,Ot]),Re=y.useCallback(async(at,ut,Ht="jait",Fe="full-access",Ye,Pt)=>{await Ot(at,ut,Ht,Fe,Ye,Pt)},[Ot]),ke=y.useCallback(async at=>{try{await Yr.stopThread(at),De()}catch(ut){H(ut instanceof Error?ut.message:"Failed to stop thread")}},[De]),$e=y.useCallback(async at=>{try{await Yr.deleteThread(at),f(ut=>ut.filter(Ht=>Ht.id!==at)),_===at&&k(null)}catch(ut){H(ut instanceof Error?ut.message:"Failed to delete thread")}},[_]),ct=y.useCallback(()=>{M(!0),g(at=>at+f8)},[]),gt=y.useCallback(()=>{g(f8)},[]);return{repositories:re,selectedRepoId:o,setSelectedRepoId:a,selectedRepo:ie,folderPickerOpen:l,setFolderPickerOpen:d,handleFolderSelected:nt,removeRepository:Je,threads:u,hasMoreThreads:v,threadListLimit:p,showMoreThreads:ct,showFewerThreads:gt,repoThreads:kt,selectedThreadId:_,setSelectedThreadId:k,selectedThread:ge,getRepositoryForThread:et,threadPrStates:j,ghAvailable:A,activities:w,loadingActivities:F,activityEndRef:ee,selectedThreadTodos:Q,providers:R,remoteProviders:z,loading:K,error:Y,setError:H,creating:!1,showGitActions:Xe,getRuntimeInfoForRepository:Qe,refresh:De,handleSend:be,handleSendToThread:Re,handleStop:ke,handleDelete:$e,handleThreadEvent:Oe}}const YV=[{value:"developer",label:"Developer",icon:Gb,description:"Chat with the AI assistant — ask, plan, and execute"},{value:"manager",label:"Manager",icon:P8,description:"Automation — delegate tasks to agent threads on repos"}];function hmt({mode:e,onChange:r,disabled:n,className:i,compact:s=!1}){const o=YV.findIndex(l=>l.value===e),a=o>=0?o:0;return c.jsxs("div",{role:"tablist","aria-label":"View mode",className:We("relative inline-grid h-8 grid-cols-2 rounded-lg bg-muted/40 p-0.5",s?"border-0":"border border-border/70","shadow-sm transition-colors",n&&"pointer-events-none opacity-50",i),children:[c.jsx("div",{"aria-hidden":"true",className:We("absolute inset-y-0.5 left-0.5 w-[calc(50%-2px)] rounded-md bg-background shadow-sm","transition-transform duration-200 ease-out"),style:{transform:`translateX(${a*100}%)`}}),YV.map(l=>{const d=l.icon,u=e===l.value;return c.jsxs("button",{type:"button",role:"tab","aria-selected":u,"aria-label":l.label,title:`${l.label}: ${l.description}`,disabled:n,onClick:()=>r(l.value),className:We("relative z-10 flex min-w-0 items-center justify-center gap-1.5 rounded-md px-2 text-xs font-medium","transition-colors duration-200 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",u?"text-foreground":"text-muted-foreground hover:text-foreground",s?"w-9":"min-w-[5.75rem]"),children:[c.jsx(d,{className:"h-3.5 w-3.5 shrink-0"}),!s&&c.jsx("span",{children:l.label})]},l.value)})]})}const fmt=8e3,pmt=["hey jait","jait","hey jade","jade","hey jayit","jayit","hey gate","gate","hey jate","jate","hey jay","jay","hey date","date","hey jake","jake","hey jet","jet","hey jayt","jayt","hey jayed","jayed","hey jaid","jaid","hey jayett","jayett","hey jit","jit","hey jai","jai","hey dschaid","dschaid","hey tscheit","tscheit","hey dscheit","dscheit","hey tschait","tschait","hey jeid","jeid","hey jäd","jäd","hey tschäd","tschäd","hey scheide","hey scheid","hey jäit","jäit"];function aue(e){const r=e.toLowerCase().replace(/^(hey|hej|he)\s+/,"").replace(/[^a-zäöüß]/g,"").trim();return r.length<2||r.length>8?!1:!!(["jait","jade","jate","gate","jay","jai","jet","jake","jayed","jaid","jayit","jayt","jayett","jit","dschaid","tscheit","dscheit","tschait","jeid","jäd","tschäd","jäit","scheid","scheide"].includes(r)||/^(j|g|dj|dsch|tsch|sch)/.test(r)&&/(t|d|te|de|ed)$/.test(r))}function mmt(e){const{enabled:r,lang:n,wakePhrases:i,onCommand:s,onWakeWordDetected:o,onListeningTimeout:a}=e,[l,d]=y.useState(!1),[u,f]=y.useState(!1),[p,g]=y.useState(""),v=y.useRef(null),b=y.useRef(!1),_=y.useRef(null),k=y.useRef(r),w=y.useRef(!1),C=y.useRef(s);C.current=s;const j=y.useRef(o);j.current=o;const N=y.useRef(a);N.current=a,k.current=r;const A=i??pmt,E=y.useRef(A);E.current=A;const R=typeof window<"u"&&("SpeechRecognition"in window||"webkitSpeechRecognition"in window),L=y.useCallback(()=>{_.current&&(clearTimeout(_.current),_.current=null)},[]),z=y.useCallback(()=>{b.current=!1,f(!1),g(""),L()},[L]),$=y.useCallback(()=>{b.current=!0,f(!0),g(""),L(),_.current=setTimeout(()=>{var W;b.current&&(z(),(W=N.current)==null||W.call(N))},fmt)},[L,z]);return y.useEffect(()=>{if(!r||!R){v.current&&(w.current=!0,v.current.abort(),v.current=null,d(!1),z());return}const W=window.SpeechRecognition??window.webkitSpeechRecognition;if(!W)return;const B=new W;B.continuous=!0,B.interimResults=!0,B.maxAlternatives=1,B.lang=n??navigator.language??"en-US",v.current=B,w.current=!1,B.onstart=()=>{console.debug('[useWakeWord] SpeechRecognition started — say "Hey Jait" to activate'),d(!0)},B.onresult=K=>{var M,I,P;for(let F=K.resultIndex;F<K.results.length;F++){const V=K.results[F],Y=((I=(M=V[0])==null?void 0:M.transcript)==null?void 0:I.trim())??"",H=V.isFinal;if(Y&&console.debug(`[useWakeWord] ${H?"FINAL":"interim"}: "${Y}"`),b.current)if(H&&Y){const U=XV(Y,E.current);U&&C.current(U),z()}else g(Y);else{const U=Y.toLowerCase(),Q=E.current.some(te=>U.includes(te.toLowerCase())),q=!Q&&Y.split(/\s+/).some(te=>aue(te)),ee=Q||q;if(ee&&H){console.debug(`[useWakeWord] Wake word DETECTED in: "${Y}"`);const te=XV(Y,E.current);(P=j.current)==null||P.call(j),te?C.current(te):$()}else ee&&g(Y)}}},B.onerror=K=>{if(!(K.error==="no-speech"||K.error==="aborted")){if(K.error==="not-allowed"){console.warn("[useWakeWord] Microphone permission denied — disabling wake word"),w.current=!0;return}console.warn("[useWakeWord] SpeechRecognition error:",K.error)}},B.onend=()=>{d(!1),k.current&&!w.current&&setTimeout(()=>{if(!(!k.current||w.current))try{B.start()}catch{}},300)};try{B.start()}catch{}return()=>{w.current=!0,B.abort(),v.current=null,d(!1),z()}},[r,R,n,$,z]),{isRunning:l,isListening:u,isSupported:R,interimTranscript:p}}function XV(e,r){var a,l;let n=e.trim();const i=n.toLowerCase(),s=[...r].sort((d,u)=>u.length-d.length);let o=!1;for(const d of s){const u=i.indexOf(d.toLowerCase());if(u!==-1){n=(n.slice(0,u)+n.slice(u+d.length)).trim(),o=!0;break}}if(!o){const d=n.split(/\s+/);let u=0;(((a=d[0])==null?void 0:a.toLowerCase())==="hey"||((l=d[0])==null?void 0:l.toLowerCase())==="hej")&&(u=1),d[u]&&aue(d[u])&&(n=d.slice(u+1).join(" "))}return n.replace(/^[,;:!?\s]+/,"").trim()}const Vk=24e3,gmt=`${window.location.protocol}//${window.location.hostname}:${window.location.port}`;function ymt(){return`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}`}function vmt(e){const r=new Int16Array(e.length);for(let n=0;n<e.length;n++){const i=Math.max(-1,Math.min(1,e[n]));r[n]=i<0?i*32768:i*32767}return r.buffer}function xmt(e){const r=new Int16Array(e),n=new Float32Array(r.length);for(let i=0;i<r.length;i++)n[i]=r[i]/32768;return n}function ZV(e){const r=new Uint8Array(e),n=32768,i=[];for(let s=0;s<r.length;s+=n)i.push(String.fromCharCode.apply(null,r.subarray(s,s+n)));return btoa(i.join(""))}function bmt(e){const r=atob(e),n=r.length,i=new Uint8Array(n);for(let s=0;s<n;s++)i[s]=r.charCodeAt(s);return i.buffer}const _mt=`
|
|
1269
1269
|
class PcmCaptureProcessor extends AudioWorkletProcessor {
|
|
1270
1270
|
constructor() {
|
|
1271
1271
|
super();
|