loopat 0.1.54 → 0.1.55

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.
Files changed (33) hide show
  1. package/package.json +1 -1
  2. package/server/src/git-host.ts +5 -1
  3. package/server/src/github.ts +21 -0
  4. package/server/src/loops.ts +14 -0
  5. package/web/dist/assets/{Editor-BN7Q5g4N.js → Editor-onKcF7Hk.js} +1 -1
  6. package/web/dist/assets/{Markdown-DvFvJx3d.js → Markdown-TRpyMaSJ.js} +1 -1
  7. package/web/dist/assets/{MilkdownEditor-DsqsnlSK.js → MilkdownEditor-CPzvRlCr.js} +1 -1
  8. package/web/dist/assets/{architectureDiagram-3BPJPVTR-BiL4yrd-.js → architectureDiagram-3BPJPVTR-BqWvl6_Z.js} +1 -1
  9. package/web/dist/assets/{chunk-727SXJPM-DB5VAPjb.js → chunk-727SXJPM-DgAepYue.js} +1 -1
  10. package/web/dist/assets/{chunk-AQP2D5EJ-zKFdEFYM.js → chunk-AQP2D5EJ-DSPZ2zOm.js} +1 -1
  11. package/web/dist/assets/{classDiagram-4FO5ZUOK-DGIJJBY5.js → classDiagram-4FO5ZUOK-CRIzZW-i.js} +1 -1
  12. package/web/dist/assets/{classDiagram-v2-Q7XG4LA2-BdsZBmZ_.js → classDiagram-v2-Q7XG4LA2-CWOJ0KP_.js} +1 -1
  13. package/web/dist/assets/{diagram-2AECGRRQ-DE80i5fc.js → diagram-2AECGRRQ-aYV3991Q.js} +1 -1
  14. package/web/dist/assets/{diagram-5GNKFQAL-Egr34zuZ.js → diagram-5GNKFQAL-430D0ULK.js} +1 -1
  15. package/web/dist/assets/{diagram-LMA3HP47-f9ekzEBK.js → diagram-LMA3HP47-B_1CjDrM.js} +1 -1
  16. package/web/dist/assets/{diagram-OG6HWLK6-CJhcoTKU.js → diagram-OG6HWLK6-DS7uDEpu.js} +1 -1
  17. package/web/dist/assets/{erDiagram-TEJ5UH35-CYNgf9or.js → erDiagram-TEJ5UH35-KifhsjrY.js} +1 -1
  18. package/web/dist/assets/{flowDiagram-I6XJVG4X-BXTQ7QRg.js → flowDiagram-I6XJVG4X-CUF2AkfX.js} +1 -1
  19. package/web/dist/assets/{index-BbAx7IhR.js → index-B60_8DVa.js} +6 -6
  20. package/web/dist/assets/{infoDiagram-5YYISTIA-Be0OcURm.js → infoDiagram-5YYISTIA-BWBMucTX.js} +1 -1
  21. package/web/dist/assets/{ishikawaDiagram-YF4QCWOH-BFyPbPqD.js → ishikawaDiagram-YF4QCWOH-B08GNYsG.js} +1 -1
  22. package/web/dist/assets/{kanban-definition-UN3LZRKU-C5BAKIQX.js → kanban-definition-UN3LZRKU-B5M0uLn9.js} +1 -1
  23. package/web/dist/assets/{mindmap-definition-RKZ34NQL-DqgCcW-r.js → mindmap-definition-RKZ34NQL-BcWz14bu.js} +1 -1
  24. package/web/dist/assets/{pieDiagram-4H26LBE5-BP9tC1HT.js → pieDiagram-4H26LBE5-BeDVs-my.js} +1 -1
  25. package/web/dist/assets/{requirementDiagram-4Y6WPE33-B_O_cEpd.js → requirementDiagram-4Y6WPE33-AQfIOy53.js} +1 -1
  26. package/web/dist/assets/{sequenceDiagram-3UESZ5HK-DBBZS2WD.js → sequenceDiagram-3UESZ5HK--egU0Cm3.js} +1 -1
  27. package/web/dist/assets/{stateDiagram-AJRCARHV-BaH2s_og.js → stateDiagram-AJRCARHV-CbyXuf3R.js} +1 -1
  28. package/web/dist/assets/{stateDiagram-v2-BHNVJYJU-Ryor5k_i.js → stateDiagram-v2-BHNVJYJU-CeJTs4x0.js} +1 -1
  29. package/web/dist/assets/{timeline-definition-PNZ67QCA-BNvy_0DN.js → timeline-definition-PNZ67QCA-DvSJjt5p.js} +1 -1
  30. package/web/dist/assets/{vennDiagram-CIIHVFJN-D5RSWRYm.js → vennDiagram-CIIHVFJN-BFBGrdGc.js} +1 -1
  31. package/web/dist/assets/{wardleyDiagram-YWT4CUSO-5PntQ1A_.js → wardleyDiagram-YWT4CUSO-9QmHh5AB.js} +1 -1
  32. package/web/dist/assets/{xychartDiagram-2RQKCTM6-B_1m_ITe.js → xychartDiagram-2RQKCTM6-DwH6-8zP.js} +1 -1
  33. package/web/dist/index.html +1 -1
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/dagre-BM42HDAG-CZ5AtThh.js","assets/chunk-CSCIHK7Q-KZCheCnJ.js","assets/src-BTV4tisa.js","assets/chunk-62oNxeRG.js","assets/chunk-O5CBEL6O-Bg6sZtyT.js","assets/chunk-5ZQYHXKU-DAcci771.js","assets/dist-Qo4xPaJL.js","assets/dagre-DtjYhTY3.js","assets/graphlib-CVvj2XkR.js","assets/isObject-6BN_nwjc.js","assets/now-CfACN9Ld.js","assets/chunk-3OPIFGDE-CPRLtc-k.js","assets/chunk-L5ZTLDWV-4FtjsXMJ.js","assets/chunk-NZK2D7GU-OE2TAhC6.js","assets/rough.esm-DEh6Frf9.js","assets/chunk-BSJP7CBP-DF8jhsUx.js","assets/chunk-KSCS5N6A-Cc-HIfIs.js","assets/line-C1hQ6Yic.js","assets/path-DNPd7Py7.js","assets/array-CwG8vNfn.js","assets/cose-bilkent-S5V4N54A-CWucooZw.js","assets/cytoscape.esm-fMM2C9dj.js","assets/c4Diagram-AAUBKEIU-CzsNYAS-.js","assets/chunk-ND2GUHAM-CLZCc4eF.js","assets/flowDiagram-I6XJVG4X-BXTQ7QRg.js","assets/channel-BadMOAUe.js","assets/chunk-2J33WTMH-jzikTe5Z.js","assets/chunk-55IACEB6-DUDG-guT.js","assets/chunk-FMBD7UC4-BruiH2nG.js","assets/erDiagram-TEJ5UH35-CYNgf9or.js","assets/gitGraphDiagram-PVQCEYII-D8BksuAg.js","assets/mermaid-parser.core-B4wi-4x8.js","assets/chunk-4EGX6M5U-BgefWETD.js","assets/chunk-NNHCCRGN-DHWtWlDY.js","assets/chunk-5DO6E6H7-CXaGVrrt.js","assets/chunk-BR22UD5L-D9r29Y8a.js","assets/chunk-FHYWG6QK-5gBLDG6p.js","assets/chunk-MPE355IW-RWzERmdt.js","assets/chunk-MZUSXYTE-Xjzy1goZ.js","assets/chunk-N66VUXT2-7wnXYZTH.js","assets/chunk-PUPMXCY4-C1dr9z9P.js","assets/chunk-UIBZB4QT-DBYf6fSv.js","assets/chunk-WCWK7LTN-DpJdbsk3.js","assets/chunk-4BX2VUAB-C4VZq7p9.js","assets/chunk-QZHKN3VN-DxLqo3gI.js","assets/ganttDiagram-6RSMTGT7-9CPIXrRu.js","assets/linear-BTFE1p_D.js","assets/defaultLocale-Dda4OpKy.js","assets/init-D6KNwrax.js","assets/infoDiagram-5YYISTIA-Be0OcURm.js","assets/pieDiagram-4H26LBE5-BP9tC1HT.js","assets/ordinal-SeL1F7Yj.js","assets/arc-JSCNOeGh.js","assets/quadrantDiagram-W4KKPZXB-BBjjuCms.js","assets/xychartDiagram-2RQKCTM6-B_1m_ITe.js","assets/requirementDiagram-4Y6WPE33-B_O_cEpd.js","assets/sequenceDiagram-3UESZ5HK-DBBZS2WD.js","assets/classDiagram-4FO5ZUOK-DGIJJBY5.js","assets/chunk-727SXJPM-DB5VAPjb.js","assets/classDiagram-v2-Q7XG4LA2-BdsZBmZ_.js","assets/stateDiagram-AJRCARHV-BaH2s_og.js","assets/chunk-AQP2D5EJ-zKFdEFYM.js","assets/stateDiagram-v2-BHNVJYJU-Ryor5k_i.js","assets/journeyDiagram-JHISSGLW-DR1RevaB.js","assets/timeline-definition-PNZ67QCA-BNvy_0DN.js","assets/mindmap-definition-RKZ34NQL-DqgCcW-r.js","assets/kanban-definition-UN3LZRKU-C5BAKIQX.js","assets/sankeyDiagram-5OEKKPKP-Cv_l_I0A.js","assets/diagram-LMA3HP47-f9ekzEBK.js","assets/diagram-2AECGRRQ-DE80i5fc.js","assets/blockDiagram-GPEHLZMM-BlIpPvY3.js","assets/diagram-5GNKFQAL-Egr34zuZ.js","assets/architectureDiagram-3BPJPVTR-BiL4yrd-.js","assets/diagram-KO2AKTUF-CvajPPQL.js","assets/ishikawaDiagram-YF4QCWOH-BFyPbPqD.js","assets/vennDiagram-CIIHVFJN-D5RSWRYm.js","assets/diagram-OG6HWLK6-CJhcoTKU.js","assets/wardleyDiagram-YWT4CUSO-5PntQ1A_.js","assets/Editor-BN7Q5g4N.js","assets/CodeEditor-ROIg2ylA.js","assets/jsx-runtime-ZP0XCtgh.js","assets/w3c-keyname-BoNxyEq0.js","assets/Terminal-DQxchB0u.js","assets/Terminal-BrP-ENHg.css","assets/Markdown-DvFvJx3d.js","assets/lib-B1ZjR0ui.js","assets/MilkdownEditor-DsqsnlSK.js"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/dagre-BM42HDAG-CZ5AtThh.js","assets/chunk-CSCIHK7Q-KZCheCnJ.js","assets/src-BTV4tisa.js","assets/chunk-62oNxeRG.js","assets/chunk-O5CBEL6O-Bg6sZtyT.js","assets/chunk-5ZQYHXKU-DAcci771.js","assets/dist-Qo4xPaJL.js","assets/dagre-DtjYhTY3.js","assets/graphlib-CVvj2XkR.js","assets/isObject-6BN_nwjc.js","assets/now-CfACN9Ld.js","assets/chunk-3OPIFGDE-CPRLtc-k.js","assets/chunk-L5ZTLDWV-4FtjsXMJ.js","assets/chunk-NZK2D7GU-OE2TAhC6.js","assets/rough.esm-DEh6Frf9.js","assets/chunk-BSJP7CBP-DF8jhsUx.js","assets/chunk-KSCS5N6A-Cc-HIfIs.js","assets/line-C1hQ6Yic.js","assets/path-DNPd7Py7.js","assets/array-CwG8vNfn.js","assets/cose-bilkent-S5V4N54A-CWucooZw.js","assets/cytoscape.esm-fMM2C9dj.js","assets/c4Diagram-AAUBKEIU-CzsNYAS-.js","assets/chunk-ND2GUHAM-CLZCc4eF.js","assets/flowDiagram-I6XJVG4X-CUF2AkfX.js","assets/channel-BadMOAUe.js","assets/chunk-2J33WTMH-jzikTe5Z.js","assets/chunk-55IACEB6-DUDG-guT.js","assets/chunk-FMBD7UC4-BruiH2nG.js","assets/erDiagram-TEJ5UH35-KifhsjrY.js","assets/gitGraphDiagram-PVQCEYII-D8BksuAg.js","assets/mermaid-parser.core-B4wi-4x8.js","assets/chunk-4EGX6M5U-BgefWETD.js","assets/chunk-NNHCCRGN-DHWtWlDY.js","assets/chunk-5DO6E6H7-CXaGVrrt.js","assets/chunk-BR22UD5L-D9r29Y8a.js","assets/chunk-FHYWG6QK-5gBLDG6p.js","assets/chunk-MPE355IW-RWzERmdt.js","assets/chunk-MZUSXYTE-Xjzy1goZ.js","assets/chunk-N66VUXT2-7wnXYZTH.js","assets/chunk-PUPMXCY4-C1dr9z9P.js","assets/chunk-UIBZB4QT-DBYf6fSv.js","assets/chunk-WCWK7LTN-DpJdbsk3.js","assets/chunk-4BX2VUAB-C4VZq7p9.js","assets/chunk-QZHKN3VN-DxLqo3gI.js","assets/ganttDiagram-6RSMTGT7-9CPIXrRu.js","assets/linear-BTFE1p_D.js","assets/defaultLocale-Dda4OpKy.js","assets/init-D6KNwrax.js","assets/infoDiagram-5YYISTIA-BWBMucTX.js","assets/pieDiagram-4H26LBE5-BeDVs-my.js","assets/ordinal-SeL1F7Yj.js","assets/arc-JSCNOeGh.js","assets/quadrantDiagram-W4KKPZXB-BBjjuCms.js","assets/xychartDiagram-2RQKCTM6-DwH6-8zP.js","assets/requirementDiagram-4Y6WPE33-AQfIOy53.js","assets/sequenceDiagram-3UESZ5HK--egU0Cm3.js","assets/classDiagram-4FO5ZUOK-CRIzZW-i.js","assets/chunk-727SXJPM-DgAepYue.js","assets/classDiagram-v2-Q7XG4LA2-CWOJ0KP_.js","assets/stateDiagram-AJRCARHV-CbyXuf3R.js","assets/chunk-AQP2D5EJ-DSPZ2zOm.js","assets/stateDiagram-v2-BHNVJYJU-CeJTs4x0.js","assets/journeyDiagram-JHISSGLW-DR1RevaB.js","assets/timeline-definition-PNZ67QCA-DvSJjt5p.js","assets/mindmap-definition-RKZ34NQL-BcWz14bu.js","assets/kanban-definition-UN3LZRKU-B5M0uLn9.js","assets/sankeyDiagram-5OEKKPKP-Cv_l_I0A.js","assets/diagram-LMA3HP47-B_1CjDrM.js","assets/diagram-2AECGRRQ-aYV3991Q.js","assets/blockDiagram-GPEHLZMM-BlIpPvY3.js","assets/diagram-5GNKFQAL-430D0ULK.js","assets/architectureDiagram-3BPJPVTR-BqWvl6_Z.js","assets/diagram-KO2AKTUF-CvajPPQL.js","assets/ishikawaDiagram-YF4QCWOH-B08GNYsG.js","assets/vennDiagram-CIIHVFJN-BFBGrdGc.js","assets/diagram-OG6HWLK6-DS7uDEpu.js","assets/wardleyDiagram-YWT4CUSO-9QmHh5AB.js","assets/Editor-onKcF7Hk.js","assets/CodeEditor-ROIg2ylA.js","assets/jsx-runtime-ZP0XCtgh.js","assets/w3c-keyname-BoNxyEq0.js","assets/Terminal-DQxchB0u.js","assets/Terminal-BrP-ENHg.css","assets/Markdown-TRpyMaSJ.js","assets/lib-B1ZjR0ui.js","assets/MilkdownEditor-CPzvRlCr.js"])))=>i.map(i=>d[i]);
2
2
  import{i as e,n as t,t as n}from"./chunk-62oNxeRG.js";import{n as r,t as i}from"./jsx-runtime-ZP0XCtgh.js";import{C as a,E as o,I as s,L as c,N as l,P as u,Q as d,S as f,T as p,V as m,W as h,X as g,Z as _,_ as v,b as y,c as b,g as x,l as S,m as C,n as w,ot as T,p as E,q as D,r as O,s as k,st as A,t as ee,u as j,x as te}from"./chunk-CSCIHK7Q-KZCheCnJ.js";import{C as M,S as ne,_ as N,b as re,c as ie,d as ae,f as oe,g as se,l as ce,m as le,o as ue,p as de,t as fe,u as pe,v as me,x as he,y as ge}from"./lib-B1ZjR0ui.js";import{t as _e}from"./katex-SDxE4_FN.js";import{_ as ve,g as ye,h as P,p as be}from"./src-BTV4tisa.js";import{S as xe,a as Se,d as Ce,f as we,g as Te,h as Ee,i as De,o as Oe,v as ke,x as Ae,y as je}from"./chunk-5ZQYHXKU-DAcci771.js";import"./chunk-BSJP7CBP-DF8jhsUx.js";import"./chunk-L5ZTLDWV-4FtjsXMJ.js";import"./chunk-NZK2D7GU-OE2TAhC6.js";import{i as Me,o as Ne}from"./chunk-O5CBEL6O-Bg6sZtyT.js";import{a as Pe,i as Fe,s as Ie}from"./chunk-3OPIFGDE-CPRLtc-k.js";import{a as Le,i as Re,n as ze,r as Be}from"./chunk-KSCS5N6A-Cc-HIfIs.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),e.crossOrigin===`use-credentials`?t.credentials=`include`:e.crossOrigin===`anonymous`?t.credentials=`omit`:t.credentials=`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var Ve=n((e=>{function t(e,t){var n=e.length;e.push(t);a:for(;0<n;){var r=n-1>>>1,a=e[r];if(0<i(a,t))e[r]=t,e[n]=a,n=r;else break a}}function n(e){return e.length===0?null:e[0]}function r(e){if(e.length===0)return null;var t=e[0],n=e.pop();if(n!==t){e[0]=n;a:for(var r=0,a=e.length,o=a>>>1;r<o;){var s=2*(r+1)-1,c=e[s],l=s+1,u=e[l];if(0>i(c,n))l<a&&0>i(u,c)?(e[r]=u,e[l]=n,r=l):(e[r]=c,e[s]=n,r=s);else if(l<a&&0>i(u,n))e[r]=u,e[l]=n,r=l;else break a}}return t}function i(e,t){var n=e.sortIndex-t.sortIndex;return n===0?e.id-t.id:n}if(e.unstable_now=void 0,typeof performance==`object`&&typeof performance.now==`function`){var a=performance;e.unstable_now=function(){return a.now()}}else{var o=Date,s=o.now();e.unstable_now=function(){return o.now()-s}}var c=[],l=[],u=1,d=null,f=3,p=!1,m=!1,h=!1,g=!1,_=typeof setTimeout==`function`?setTimeout:null,v=typeof clearTimeout==`function`?clearTimeout:null,y=typeof setImmediate<`u`?setImmediate:null;function b(e){for(var i=n(l);i!==null;){if(i.callback===null)r(l);else if(i.startTime<=e)r(l),i.sortIndex=i.expirationTime,t(c,i);else break;i=n(l)}}function x(e){if(h=!1,b(e),!m)if(n(c)!==null)m=!0,S||(S=!0,O());else{var t=n(l);t!==null&&ee(x,t.startTime-e)}}var S=!1,C=-1,w=5,T=-1;function E(){return g?!0:!(e.unstable_now()-T<w)}function D(){if(g=!1,S){var t=e.unstable_now();T=t;var i=!0;try{a:{m=!1,h&&(h=!1,v(C),C=-1),p=!0;var a=f;try{b:{for(b(t),d=n(c);d!==null&&!(d.expirationTime>t&&E());){var o=d.callback;if(typeof o==`function`){d.callback=null,f=d.priorityLevel;var s=o(d.expirationTime<=t);if(t=e.unstable_now(),typeof s==`function`){d.callback=s,b(t),i=!0;break b}d===n(c)&&r(c),b(t)}else r(c);d=n(c)}if(d!==null)i=!0;else{var u=n(l);u!==null&&ee(x,u.startTime-t),i=!1}}break a}finally{d=null,f=a,p=!1}i=void 0}}finally{i?O():S=!1}}}var O;if(typeof y==`function`)O=function(){y(D)};else if(typeof MessageChannel<`u`){var k=new MessageChannel,A=k.port2;k.port1.onmessage=D,O=function(){A.postMessage(null)}}else O=function(){_(D,0)};function ee(t,n){C=_(function(){t(e.unstable_now())},n)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(e){e.callback=null},e.unstable_forceFrameRate=function(e){0>e||125<e?console.error(`forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported`):w=0<e?Math.floor(1e3/e):5},e.unstable_getCurrentPriorityLevel=function(){return f},e.unstable_next=function(e){switch(f){case 1:case 2:case 3:var t=3;break;default:t=f}var n=f;f=t;try{return e()}finally{f=n}},e.unstable_requestPaint=function(){g=!0},e.unstable_runWithPriority=function(e,t){switch(e){case 1:case 2:case 3:case 4:case 5:break;default:e=3}var n=f;f=e;try{return t()}finally{f=n}},e.unstable_scheduleCallback=function(r,i,a){var o=e.unstable_now();switch(typeof a==`object`&&a?(a=a.delay,a=typeof a==`number`&&0<a?o+a:o):a=o,r){case 1:var s=-1;break;case 2:s=250;break;case 5:s=1073741823;break;case 4:s=1e4;break;default:s=5e3}return s=a+s,r={id:u++,callback:i,priorityLevel:r,startTime:a,expirationTime:s,sortIndex:-1},a>o?(r.sortIndex=a,t(l,r),n(c)===null&&r===n(l)&&(h?(v(C),C=-1):h=!0,ee(x,a-o))):(r.sortIndex=s,t(c,r),m||p||(m=!0,S||(S=!0,O()))),r},e.unstable_shouldYield=E,e.unstable_wrapCallback=function(e){var t=f;return function(){var n=f;f=t;try{return e.apply(this,arguments)}finally{f=n}}}})),He=n(((e,t)=>{t.exports=Ve()})),Ue=n((e=>{var t=r();function n(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function i(){}var a={d:{f:i,r:function(){throw Error(n(522))},D:i,C:i,L:i,m:i,X:i,S:i,M:i},p:0,findDOMNode:null},o=Symbol.for(`react.portal`);function s(e,t,n){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:o,key:r==null?null:``+r,children:e,containerInfo:t,implementation:n}}var c=t.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;function l(e,t){if(e===`font`)return``;if(typeof t==`string`)return t===`use-credentials`?t:``}e.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=a,e.createPortal=function(e,t){var r=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!t||t.nodeType!==1&&t.nodeType!==9&&t.nodeType!==11)throw Error(n(299));return s(e,t,null,r)},e.flushSync=function(e){var t=c.T,n=a.p;try{if(c.T=null,a.p=2,e)return e()}finally{c.T=t,a.p=n,a.d.f()}},e.preconnect=function(e,t){typeof e==`string`&&(t?(t=t.crossOrigin,t=typeof t==`string`?t===`use-credentials`?t:``:void 0):t=null,a.d.C(e,t))},e.prefetchDNS=function(e){typeof e==`string`&&a.d.D(e)},e.preinit=function(e,t){if(typeof e==`string`&&t&&typeof t.as==`string`){var n=t.as,r=l(n,t.crossOrigin),i=typeof t.integrity==`string`?t.integrity:void 0,o=typeof t.fetchPriority==`string`?t.fetchPriority:void 0;n===`style`?a.d.S(e,typeof t.precedence==`string`?t.precedence:void 0,{crossOrigin:r,integrity:i,fetchPriority:o}):n===`script`&&a.d.X(e,{crossOrigin:r,integrity:i,fetchPriority:o,nonce:typeof t.nonce==`string`?t.nonce:void 0})}},e.preinitModule=function(e,t){if(typeof e==`string`)if(typeof t==`object`&&t){if(t.as==null||t.as===`script`){var n=l(t.as,t.crossOrigin);a.d.M(e,{crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0})}}else t??a.d.M(e)},e.preload=function(e,t){if(typeof e==`string`&&typeof t==`object`&&t&&typeof t.as==`string`){var n=t.as,r=l(n,t.crossOrigin);a.d.L(e,n,{crossOrigin:r,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0,type:typeof t.type==`string`?t.type:void 0,fetchPriority:typeof t.fetchPriority==`string`?t.fetchPriority:void 0,referrerPolicy:typeof t.referrerPolicy==`string`?t.referrerPolicy:void 0,imageSrcSet:typeof t.imageSrcSet==`string`?t.imageSrcSet:void 0,imageSizes:typeof t.imageSizes==`string`?t.imageSizes:void 0,media:typeof t.media==`string`?t.media:void 0})}},e.preloadModule=function(e,t){if(typeof e==`string`)if(t){var n=l(t.as,t.crossOrigin);a.d.m(e,{as:typeof t.as==`string`&&t.as!==`script`?t.as:void 0,crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0})}else a.d.m(e)},e.requestFormReset=function(e){a.d.r(e)},e.unstable_batchedUpdates=function(e,t){return e(t)},e.useFormState=function(e,t,n){return c.H.useFormState(e,t,n)},e.useFormStatus=function(){return c.H.useHostTransitionStatus()},e.version=`19.2.6`})),We=n(((e,t)=>{function n(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>`u`||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!=`function`))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(n)}catch(e){console.error(e)}}n(),t.exports=Ue()})),Ge=n((e=>{var t=He(),n=r(),i=We();function a(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function o(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function s(e){var t=e,n=e;if(e.alternate)for(;t.return;)t=t.return;else{e=t;do t=e,t.flags&4098&&(n=t.return),e=t.return;while(e)}return t.tag===3?n:null}function c(e){if(e.tag===13){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function l(e){if(e.tag===31){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function u(e){if(s(e)!==e)throw Error(a(188))}function d(e){var t=e.alternate;if(!t){if(t=s(e),t===null)throw Error(a(188));return t===e?e:null}for(var n=e,r=t;;){var i=n.return;if(i===null)break;var o=i.alternate;if(o===null){if(r=i.return,r!==null){n=r;continue}break}if(i.child===o.child){for(o=i.child;o;){if(o===n)return u(i),e;if(o===r)return u(i),t;o=o.sibling}throw Error(a(188))}if(n.return!==r.return)n=i,r=o;else{for(var c=!1,l=i.child;l;){if(l===n){c=!0,n=i,r=o;break}if(l===r){c=!0,r=i,n=o;break}l=l.sibling}if(!c){for(l=o.child;l;){if(l===n){c=!0,n=o,r=i;break}if(l===r){c=!0,r=o,n=i;break}l=l.sibling}if(!c)throw Error(a(189))}}if(n.alternate!==r)throw Error(a(190))}if(n.tag!==3)throw Error(a(188));return n.stateNode.current===n?e:t}function f(e){var t=e.tag;if(t===5||t===26||t===27||t===6)return e;for(e=e.child;e!==null;){if(t=f(e),t!==null)return t;e=e.sibling}return null}var p=Object.assign,m=Symbol.for(`react.element`),h=Symbol.for(`react.transitional.element`),g=Symbol.for(`react.portal`),_=Symbol.for(`react.fragment`),v=Symbol.for(`react.strict_mode`),y=Symbol.for(`react.profiler`),b=Symbol.for(`react.consumer`),x=Symbol.for(`react.context`),S=Symbol.for(`react.forward_ref`),C=Symbol.for(`react.suspense`),w=Symbol.for(`react.suspense_list`),T=Symbol.for(`react.memo`),E=Symbol.for(`react.lazy`),D=Symbol.for(`react.activity`),O=Symbol.for(`react.memo_cache_sentinel`),k=Symbol.iterator;function A(e){return typeof e!=`object`||!e?null:(e=k&&e[k]||e[`@@iterator`],typeof e==`function`?e:null)}var ee=Symbol.for(`react.client.reference`);function j(e){if(e==null)return null;if(typeof e==`function`)return e.$$typeof===ee?null:e.displayName||e.name||null;if(typeof e==`string`)return e;switch(e){case _:return`Fragment`;case y:return`Profiler`;case v:return`StrictMode`;case C:return`Suspense`;case w:return`SuspenseList`;case D:return`Activity`}if(typeof e==`object`)switch(e.$$typeof){case g:return`Portal`;case x:return e.displayName||`Context`;case b:return(e._context.displayName||`Context`)+`.Consumer`;case S:var t=e.render;return e=e.displayName,e||=(e=t.displayName||t.name||``,e===``?`ForwardRef`:`ForwardRef(`+e+`)`),e;case T:return t=e.displayName||null,t===null?j(e.type)||`Memo`:t;case E:t=e._payload,e=e._init;try{return j(e(t))}catch{}}return null}var te=Array.isArray,M=n.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,ne=i.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,N={pending:!1,data:null,method:null,action:null},re=[],ie=-1;function ae(e){return{current:e}}function oe(e){0>ie||(e.current=re[ie],re[ie]=null,ie--)}function se(e,t){ie++,re[ie]=e.current,e.current=t}var ce=ae(null),le=ae(null),ue=ae(null),de=ae(null);function fe(e,t){switch(se(ue,t),se(le,e),se(ce,null),t.nodeType){case 9:case 11:e=(e=t.documentElement)&&(e=e.namespaceURI)?rf(e):0;break;default:if(e=t.tagName,t=t.namespaceURI)t=rf(t),e=af(t,e);else switch(e){case`svg`:e=1;break;case`math`:e=2;break;default:e=0}}oe(ce),se(ce,e)}function pe(){oe(ce),oe(le),oe(ue)}function me(e){e.memoizedState!==null&&se(de,e);var t=ce.current,n=af(t,e.type);t!==n&&(se(le,e),se(ce,n))}function he(e){le.current===e&&(oe(ce),oe(le)),de.current===e&&(oe(de),pp._currentValue=N)}var ge,_e;function ve(e){if(ge===void 0)try{throw Error()}catch(e){var t=e.stack.trim().match(/\n( *(at )?)/);ge=t&&t[1]||``,_e=-1<e.stack.indexOf(`
3
3
  at`)?` (<anonymous>)`:-1<e.stack.indexOf(`@`)?`@unknown:0:0`:``}return`
4
4
  `+ge+e+_e}var ye=!1;function P(e,t){if(!e||ye)return``;ye=!0;var n=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{var r={DetermineComponentFrameRoot:function(){try{if(t){var n=function(){throw Error()};if(Object.defineProperty(n.prototype,`props`,{set:function(){throw Error()}}),typeof Reflect==`object`&&Reflect.construct){try{Reflect.construct(n,[])}catch(e){var r=e}Reflect.construct(e,[],n)}else{try{n.call()}catch(e){r=e}e.call(n.prototype)}}else{try{throw Error()}catch(e){r=e}(n=e())&&typeof n.catch==`function`&&n.catch(function(){})}}catch(e){if(e&&r&&typeof e.stack==`string`)return[e.stack,r.stack]}return[null,null]}};r.DetermineComponentFrameRoot.displayName=`DetermineComponentFrameRoot`;var i=Object.getOwnPropertyDescriptor(r.DetermineComponentFrameRoot,`name`);i&&i.configurable&&Object.defineProperty(r.DetermineComponentFrameRoot,`name`,{value:`DetermineComponentFrameRoot`});var a=r.DetermineComponentFrameRoot(),o=a[0],s=a[1];if(o&&s){var c=o.split(`
@@ -53,7 +53,7 @@ Please change the parent <Route path="${e}"> to <Route path="${e===`/`?`*`:`${e}
53
53
 
54
54
  If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component.
55
55
 
56
- For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return F.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},Nl=`DialogDescriptionWarning`,Pl=({contentRef:e,descriptionId:t})=>{let n=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${jl(Nl).contentName}}.`;return F.useEffect(()=>{let r=e.current?.getAttribute(`aria-describedby`);t&&r&&(document.getElementById(t)||console.warn(n))},[n,e,t]),null},Fl=ol,Il=fl,Ll=ml,Rl=vl,zl=Cl,Bl=Tl,Vl=Dl;function Hl(e){let[t,n]=F.useState(void 0);return ko(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});let t=new ResizeObserver(t=>{if(!Array.isArray(t)||!t.length)return;let r=t[0],i,a;if(`borderBoxSize`in r){let e=r.borderBoxSize,t=Array.isArray(e)?e[0]:e;i=t.inlineSize,a=t.blockSize}else i=e.offsetWidth,a=e.offsetHeight;n({width:i,height:a})});return t.observe(e,{box:`border-box`}),()=>t.unobserve(e)}else n(void 0)},[e]),t}var Ul=[`top`,`right`,`bottom`,`left`],Wl=Math.min,Gl=Math.max,Kl=Math.round,ql=Math.floor,Jl=e=>({x:e,y:e}),Yl={left:`right`,right:`left`,bottom:`top`,top:`bottom`};function Xl(e,t,n){return Gl(e,Wl(t,n))}function Zl(e,t){return typeof e==`function`?e(t):e}function Ql(e){return e.split(`-`)[0]}function $l(e){return e.split(`-`)[1]}function eu(e){return e===`x`?`y`:`x`}function tu(e){return e===`y`?`height`:`width`}function nu(e){let t=e[0];return t===`t`||t===`b`?`y`:`x`}function ru(e){return eu(nu(e))}function iu(e,t,n){n===void 0&&(n=!1);let r=$l(e),i=ru(e),a=tu(i),o=i===`x`?r===(n?`end`:`start`)?`right`:`left`:r===`start`?`bottom`:`top`;return t.reference[a]>t.floating[a]&&(o=pu(o)),[o,pu(o)]}function au(e){let t=pu(e);return[ou(e),t,ou(t)]}function ou(e){return e.includes(`start`)?e.replace(`start`,`end`):e.replace(`end`,`start`)}var su=[`left`,`right`],cu=[`right`,`left`],lu=[`top`,`bottom`],uu=[`bottom`,`top`];function du(e,t,n){switch(e){case`top`:case`bottom`:return n?t?cu:su:t?su:cu;case`left`:case`right`:return t?lu:uu;default:return[]}}function fu(e,t,n,r){let i=$l(e),a=du(Ql(e),n===`start`,r);return i&&(a=a.map(e=>e+`-`+i),t&&(a=a.concat(a.map(ou)))),a}function pu(e){let t=Ql(e);return Yl[t]+e.slice(t.length)}function mu(e){return{top:0,right:0,bottom:0,left:0,...e}}function hu(e){return typeof e==`number`?{top:e,right:e,bottom:e,left:e}:mu(e)}function gu(e){let{x:t,y:n,width:r,height:i}=e;return{width:r,height:i,top:n,left:t,right:t+r,bottom:n+i,x:t,y:n}}function _u(e,t,n){let{reference:r,floating:i}=e,a=nu(t),o=ru(t),s=tu(o),c=Ql(t),l=a===`y`,u=r.x+r.width/2-i.width/2,d=r.y+r.height/2-i.height/2,f=r[s]/2-i[s]/2,p;switch(c){case`top`:p={x:u,y:r.y-i.height};break;case`bottom`:p={x:u,y:r.y+r.height};break;case`right`:p={x:r.x+r.width,y:d};break;case`left`:p={x:r.x-i.width,y:d};break;default:p={x:r.x,y:r.y}}switch($l(t)){case`start`:p[o]-=f*(n&&l?-1:1);break;case`end`:p[o]+=f*(n&&l?-1:1);break}return p}async function vu(e,t){t===void 0&&(t={});let{x:n,y:r,platform:i,rects:a,elements:o,strategy:s}=e,{boundary:c=`clippingAncestors`,rootBoundary:l=`viewport`,elementContext:u=`floating`,altBoundary:d=!1,padding:f=0}=Zl(t,e),p=hu(f),m=o[d?u===`floating`?`reference`:`floating`:u],h=gu(await i.getClippingRect({element:await(i.isElement==null?void 0:i.isElement(m))??!0?m:m.contextElement||await(i.getDocumentElement==null?void 0:i.getDocumentElement(o.floating)),boundary:c,rootBoundary:l,strategy:s})),g=u===`floating`?{x:n,y:r,width:a.floating.width,height:a.floating.height}:a.reference,_=await(i.getOffsetParent==null?void 0:i.getOffsetParent(o.floating)),v=await(i.isElement==null?void 0:i.isElement(_))&&await(i.getScale==null?void 0:i.getScale(_))||{x:1,y:1},y=gu(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({elements:o,rect:g,offsetParent:_,strategy:s}):g);return{top:(h.top-y.top+p.top)/v.y,bottom:(y.bottom-h.bottom+p.bottom)/v.y,left:(h.left-y.left+p.left)/v.x,right:(y.right-h.right+p.right)/v.x}}var yu=50,bu=async(e,t,n)=>{let{placement:r=`bottom`,strategy:i=`absolute`,middleware:a=[],platform:o}=n,s=o.detectOverflow?o:{...o,detectOverflow:vu},c=await(o.isRTL==null?void 0:o.isRTL(t)),l=await o.getElementRects({reference:e,floating:t,strategy:i}),{x:u,y:d}=_u(l,r,c),f=r,p=0,m={};for(let n=0;n<a.length;n++){let h=a[n];if(!h)continue;let{name:g,fn:_}=h,{x:v,y,data:b,reset:x}=await _({x:u,y:d,initialPlacement:r,placement:f,strategy:i,middlewareData:m,rects:l,platform:s,elements:{reference:e,floating:t}});u=v??u,d=y??d,m[g]={...m[g],...b},x&&p<yu&&(p++,typeof x==`object`&&(x.placement&&(f=x.placement),x.rects&&(l=x.rects===!0?await o.getElementRects({reference:e,floating:t,strategy:i}):x.rects),{x:u,y:d}=_u(l,f,c)),n=-1)}return{x:u,y:d,placement:f,strategy:i,middlewareData:m}},xu=e=>({name:`arrow`,options:e,async fn(t){let{x:n,y:r,placement:i,rects:a,platform:o,elements:s,middlewareData:c}=t,{element:l,padding:u=0}=Zl(e,t)||{};if(l==null)return{};let d=hu(u),f={x:n,y:r},p=ru(i),m=tu(p),h=await o.getDimensions(l),g=p===`y`,_=g?`top`:`left`,v=g?`bottom`:`right`,y=g?`clientHeight`:`clientWidth`,b=a.reference[m]+a.reference[p]-f[p]-a.floating[m],x=f[p]-a.reference[p],S=await(o.getOffsetParent==null?void 0:o.getOffsetParent(l)),C=S?S[y]:0;(!C||!await(o.isElement==null?void 0:o.isElement(S)))&&(C=s.floating[y]||a.floating[m]);let w=b/2-x/2,T=C/2-h[m]/2-1,E=Wl(d[_],T),D=Wl(d[v],T),O=E,k=C-h[m]-D,A=C/2-h[m]/2+w,ee=Xl(O,A,k),j=!c.arrow&&$l(i)!=null&&A!==ee&&a.reference[m]/2-(A<O?E:D)-h[m]/2<0,te=j?A<O?A-O:A-k:0;return{[p]:f[p]+te,data:{[p]:ee,centerOffset:A-ee-te,...j&&{alignmentOffset:te}},reset:j}}}),Su=function(e){return e===void 0&&(e={}),{name:`flip`,options:e,async fn(t){var n;let{placement:r,middlewareData:i,rects:a,initialPlacement:o,platform:s,elements:c}=t,{mainAxis:l=!0,crossAxis:u=!0,fallbackPlacements:d,fallbackStrategy:f=`bestFit`,fallbackAxisSideDirection:p=`none`,flipAlignment:m=!0,...h}=Zl(e,t);if((n=i.arrow)!=null&&n.alignmentOffset)return{};let g=Ql(r),_=nu(o),v=Ql(o)===o,y=await(s.isRTL==null?void 0:s.isRTL(c.floating)),b=d||(v||!m?[pu(o)]:au(o)),x=p!==`none`;!d&&x&&b.push(...fu(o,m,p,y));let S=[o,...b],C=await s.detectOverflow(t,h),w=[],T=i.flip?.overflows||[];if(l&&w.push(C[g]),u){let e=iu(r,a,y);w.push(C[e[0]],C[e[1]])}if(T=[...T,{placement:r,overflows:w}],!w.every(e=>e<=0)){let e=(i.flip?.index||0)+1,t=S[e];if(t&&(!(u===`alignment`&&_!==nu(t))||T.every(e=>nu(e.placement)===_?e.overflows[0]>0:!0)))return{data:{index:e,overflows:T},reset:{placement:t}};let n=T.filter(e=>e.overflows[0]<=0).sort((e,t)=>e.overflows[1]-t.overflows[1])[0]?.placement;if(!n)switch(f){case`bestFit`:{let e=T.filter(e=>{if(x){let t=nu(e.placement);return t===_||t===`y`}return!0}).map(e=>[e.placement,e.overflows.filter(e=>e>0).reduce((e,t)=>e+t,0)]).sort((e,t)=>e[1]-t[1])[0]?.[0];e&&(n=e);break}case`initialPlacement`:n=o;break}if(r!==n)return{reset:{placement:n}}}return{}}}};function Cu(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function wu(e){return Ul.some(t=>e[t]>=0)}var Tu=function(e){return e===void 0&&(e={}),{name:`hide`,options:e,async fn(t){let{rects:n,platform:r}=t,{strategy:i=`referenceHidden`,...a}=Zl(e,t);switch(i){case`referenceHidden`:{let e=Cu(await r.detectOverflow(t,{...a,elementContext:`reference`}),n.reference);return{data:{referenceHiddenOffsets:e,referenceHidden:wu(e)}}}case`escaped`:{let e=Cu(await r.detectOverflow(t,{...a,altBoundary:!0}),n.floating);return{data:{escapedOffsets:e,escaped:wu(e)}}}default:return{}}}}},Eu=new Set([`left`,`top`]);async function Du(e,t){let{placement:n,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=Ql(n),s=$l(n),c=nu(n)===`y`,l=Eu.has(o)?-1:1,u=a&&c?-1:1,d=Zl(t,e),{mainAxis:f,crossAxis:p,alignmentAxis:m}=typeof d==`number`?{mainAxis:d,crossAxis:0,alignmentAxis:null}:{mainAxis:d.mainAxis||0,crossAxis:d.crossAxis||0,alignmentAxis:d.alignmentAxis};return s&&typeof m==`number`&&(p=s===`end`?m*-1:m),c?{x:p*u,y:f*l}:{x:f*l,y:p*u}}var Ou=function(e){return e===void 0&&(e=0),{name:`offset`,options:e,async fn(t){var n;let{x:r,y:i,placement:a,middlewareData:o}=t,s=await Du(t,e);return a===o.offset?.placement&&(n=o.arrow)!=null&&n.alignmentOffset?{}:{x:r+s.x,y:i+s.y,data:{...s,placement:a}}}}},ku=function(e){return e===void 0&&(e={}),{name:`shift`,options:e,async fn(t){let{x:n,y:r,placement:i,platform:a}=t,{mainAxis:o=!0,crossAxis:s=!1,limiter:c={fn:e=>{let{x:t,y:n}=e;return{x:t,y:n}}},...l}=Zl(e,t),u={x:n,y:r},d=await a.detectOverflow(t,l),f=nu(Ql(i)),p=eu(f),m=u[p],h=u[f];if(o){let e=p===`y`?`top`:`left`,t=p===`y`?`bottom`:`right`,n=m+d[e],r=m-d[t];m=Xl(n,m,r)}if(s){let e=f===`y`?`top`:`left`,t=f===`y`?`bottom`:`right`,n=h+d[e],r=h-d[t];h=Xl(n,h,r)}let g=c.fn({...t,[p]:m,[f]:h});return{...g,data:{x:g.x-n,y:g.y-r,enabled:{[p]:o,[f]:s}}}}}},Au=function(e){return e===void 0&&(e={}),{options:e,fn(t){let{x:n,y:r,placement:i,rects:a,middlewareData:o}=t,{offset:s=0,mainAxis:c=!0,crossAxis:l=!0}=Zl(e,t),u={x:n,y:r},d=nu(i),f=eu(d),p=u[f],m=u[d],h=Zl(s,t),g=typeof h==`number`?{mainAxis:h,crossAxis:0}:{mainAxis:0,crossAxis:0,...h};if(c){let e=f===`y`?`height`:`width`,t=a.reference[f]-a.floating[e]+g.mainAxis,n=a.reference[f]+a.reference[e]-g.mainAxis;p<t?p=t:p>n&&(p=n)}if(l){let e=f===`y`?`width`:`height`,t=Eu.has(Ql(i)),n=a.reference[d]-a.floating[e]+(t&&o.offset?.[d]||0)+(t?0:g.crossAxis),r=a.reference[d]+a.reference[e]+(t?0:o.offset?.[d]||0)-(t?g.crossAxis:0);m<n?m=n:m>r&&(m=r)}return{[f]:p,[d]:m}}}},ju=function(e){return e===void 0&&(e={}),{name:`size`,options:e,async fn(t){var n,r;let{placement:i,rects:a,platform:o,elements:s}=t,{apply:c=()=>{},...l}=Zl(e,t),u=await o.detectOverflow(t,l),d=Ql(i),f=$l(i),p=nu(i)===`y`,{width:m,height:h}=a.floating,g,_;d===`top`||d===`bottom`?(g=d,_=f===(await(o.isRTL==null?void 0:o.isRTL(s.floating))?`start`:`end`)?`left`:`right`):(_=d,g=f===`end`?`top`:`bottom`);let v=h-u.top-u.bottom,y=m-u.left-u.right,b=Wl(h-u[g],v),x=Wl(m-u[_],y),S=!t.middlewareData.shift,C=b,w=x;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(w=y),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(C=v),S&&!f){let e=Gl(u.left,0),t=Gl(u.right,0),n=Gl(u.top,0),r=Gl(u.bottom,0);p?w=m-2*(e!==0||t!==0?e+t:Gl(u.left,u.right)):C=h-2*(n!==0||r!==0?n+r:Gl(u.top,u.bottom))}await c({...t,availableWidth:w,availableHeight:C});let T=await o.getDimensions(s.floating);return m!==T.width||h!==T.height?{reset:{rects:!0}}:{}}}};function Mu(){return typeof window<`u`}function Nu(e){return Iu(e)?(e.nodeName||``).toLowerCase():`#document`}function Pu(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function Fu(e){return((Iu(e)?e.ownerDocument:e.document)||window.document)?.documentElement}function Iu(e){return Mu()?e instanceof Node||e instanceof Pu(e).Node:!1}function Lu(e){return Mu()?e instanceof Element||e instanceof Pu(e).Element:!1}function Ru(e){return Mu()?e instanceof HTMLElement||e instanceof Pu(e).HTMLElement:!1}function zu(e){return!Mu()||typeof ShadowRoot>`u`?!1:e instanceof ShadowRoot||e instanceof Pu(e).ShadowRoot}function Bu(e){let{overflow:t,overflowX:n,overflowY:r,display:i}=Zu(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!==`inline`&&i!==`contents`}function Vu(e){return/^(table|td|th)$/.test(Nu(e))}function Hu(e){try{if(e.matches(`:popover-open`))return!0}catch{}try{return e.matches(`:modal`)}catch{return!1}}var Uu=/transform|translate|scale|rotate|perspective|filter/,Wu=/paint|layout|strict|content/,Gu=e=>!!e&&e!==`none`,Ku;function qu(e){let t=Lu(e)?Zu(e):e;return Gu(t.transform)||Gu(t.translate)||Gu(t.scale)||Gu(t.rotate)||Gu(t.perspective)||!Yu()&&(Gu(t.backdropFilter)||Gu(t.filter))||Uu.test(t.willChange||``)||Wu.test(t.contain||``)}function Ju(e){let t=$u(e);for(;Ru(t)&&!Xu(t);){if(qu(t))return t;if(Hu(t))return null;t=$u(t)}return null}function Yu(){return Ku??=typeof CSS<`u`&&CSS.supports&&CSS.supports(`-webkit-backdrop-filter`,`none`),Ku}function Xu(e){return/^(html|body|#document)$/.test(Nu(e))}function Zu(e){return Pu(e).getComputedStyle(e)}function Qu(e){return Lu(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function $u(e){if(Nu(e)===`html`)return e;let t=e.assignedSlot||e.parentNode||zu(e)&&e.host||Fu(e);return zu(t)?t.host:t}function ed(e){let t=$u(e);return Xu(t)?e.ownerDocument?e.ownerDocument.body:e.body:Ru(t)&&Bu(t)?t:ed(t)}function td(e,t,n){t===void 0&&(t=[]),n===void 0&&(n=!0);let r=ed(e),i=r===e.ownerDocument?.body,a=Pu(r);if(i){let e=nd(a);return t.concat(a,a.visualViewport||[],Bu(r)?r:[],e&&n?td(e):[])}else return t.concat(r,td(r,[],n))}function nd(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function rd(e){let t=Zu(e),n=parseFloat(t.width)||0,r=parseFloat(t.height)||0,i=Ru(e),a=i?e.offsetWidth:n,o=i?e.offsetHeight:r,s=Kl(n)!==a||Kl(r)!==o;return s&&(n=a,r=o),{width:n,height:r,$:s}}function id(e){return Lu(e)?e:e.contextElement}function ad(e){let t=id(e);if(!Ru(t))return Jl(1);let n=t.getBoundingClientRect(),{width:r,height:i,$:a}=rd(t),o=(a?Kl(n.width):n.width)/r,s=(a?Kl(n.height):n.height)/i;return(!o||!Number.isFinite(o))&&(o=1),(!s||!Number.isFinite(s))&&(s=1),{x:o,y:s}}var od=Jl(0);function sd(e){let t=Pu(e);return!Yu()||!t.visualViewport?od:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function cd(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Pu(e)?!1:t}function ld(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);let i=e.getBoundingClientRect(),a=id(e),o=Jl(1);t&&(r?Lu(r)&&(o=ad(r)):o=ad(e));let s=cd(a,n,r)?sd(a):Jl(0),c=(i.left+s.x)/o.x,l=(i.top+s.y)/o.y,u=i.width/o.x,d=i.height/o.y;if(a){let e=Pu(a),t=r&&Lu(r)?Pu(r):r,n=e,i=nd(n);for(;i&&r&&t!==n;){let e=ad(i),t=i.getBoundingClientRect(),r=Zu(i),a=t.left+(i.clientLeft+parseFloat(r.paddingLeft))*e.x,o=t.top+(i.clientTop+parseFloat(r.paddingTop))*e.y;c*=e.x,l*=e.y,u*=e.x,d*=e.y,c+=a,l+=o,n=Pu(i),i=nd(n)}}return gu({width:u,height:d,x:c,y:l})}function ud(e,t){let n=Qu(e).scrollLeft;return t?t.left+n:ld(Fu(e)).left+n}function dd(e,t){let n=e.getBoundingClientRect();return{x:n.left+t.scrollLeft-ud(e,n),y:n.top+t.scrollTop}}function fd(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e,a=i===`fixed`,o=Fu(r),s=t?Hu(t.floating):!1;if(r===o||s&&a)return n;let c={scrollLeft:0,scrollTop:0},l=Jl(1),u=Jl(0),d=Ru(r);if((d||!d&&!a)&&((Nu(r)!==`body`||Bu(o))&&(c=Qu(r)),d)){let e=ld(r);l=ad(r),u.x=e.x+r.clientLeft,u.y=e.y+r.clientTop}let f=o&&!d&&!a?dd(o,c):Jl(0);return{width:n.width*l.x,height:n.height*l.y,x:n.x*l.x-c.scrollLeft*l.x+u.x+f.x,y:n.y*l.y-c.scrollTop*l.y+u.y+f.y}}function pd(e){return Array.from(e.getClientRects())}function md(e){let t=Fu(e),n=Qu(e),r=e.ownerDocument.body,i=Gl(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),a=Gl(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight),o=-n.scrollLeft+ud(e),s=-n.scrollTop;return Zu(r).direction===`rtl`&&(o+=Gl(t.clientWidth,r.clientWidth)-i),{width:i,height:a,x:o,y:s}}var hd=25;function gd(e,t){let n=Pu(e),r=Fu(e),i=n.visualViewport,a=r.clientWidth,o=r.clientHeight,s=0,c=0;if(i){a=i.width,o=i.height;let e=Yu();(!e||e&&t===`fixed`)&&(s=i.offsetLeft,c=i.offsetTop)}let l=ud(r);if(l<=0){let e=r.ownerDocument,t=e.body,n=getComputedStyle(t),i=e.compatMode===`CSS1Compat`&&parseFloat(n.marginLeft)+parseFloat(n.marginRight)||0,o=Math.abs(r.clientWidth-t.clientWidth-i);o<=hd&&(a-=o)}else l<=hd&&(a+=l);return{width:a,height:o,x:s,y:c}}function _d(e,t){let n=ld(e,!0,t===`fixed`),r=n.top+e.clientTop,i=n.left+e.clientLeft,a=Ru(e)?ad(e):Jl(1);return{width:e.clientWidth*a.x,height:e.clientHeight*a.y,x:i*a.x,y:r*a.y}}function vd(e,t,n){let r;if(t===`viewport`)r=gd(e,n);else if(t===`document`)r=md(Fu(e));else if(Lu(t))r=_d(t,n);else{let n=sd(e);r={x:t.x-n.x,y:t.y-n.y,width:t.width,height:t.height}}return gu(r)}function yd(e,t){let n=$u(e);return n===t||!Lu(n)||Xu(n)?!1:Zu(n).position===`fixed`||yd(n,t)}function bd(e,t){let n=t.get(e);if(n)return n;let r=td(e,[],!1).filter(e=>Lu(e)&&Nu(e)!==`body`),i=null,a=Zu(e).position===`fixed`,o=a?$u(e):e;for(;Lu(o)&&!Xu(o);){let t=Zu(o),n=qu(o);!n&&t.position===`fixed`&&(i=null),(a?!n&&!i:!n&&t.position===`static`&&i&&(i.position===`absolute`||i.position===`fixed`)||Bu(o)&&!n&&yd(e,o))?r=r.filter(e=>e!==o):i=t,o=$u(o)}return t.set(e,r),r}function xd(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e,a=[...n===`clippingAncestors`?Hu(t)?[]:bd(t,this._c):[].concat(n),r],o=vd(t,a[0],i),s=o.top,c=o.right,l=o.bottom,u=o.left;for(let e=1;e<a.length;e++){let n=vd(t,a[e],i);s=Gl(n.top,s),c=Wl(n.right,c),l=Wl(n.bottom,l),u=Gl(n.left,u)}return{width:c-u,height:l-s,x:u,y:s}}function Sd(e){let{width:t,height:n}=rd(e);return{width:t,height:n}}function Cd(e,t,n){let r=Ru(t),i=Fu(t),a=n===`fixed`,o=ld(e,!0,a,t),s={scrollLeft:0,scrollTop:0},c=Jl(0);function l(){c.x=ud(i)}if(r||!r&&!a)if((Nu(t)!==`body`||Bu(i))&&(s=Qu(t)),r){let e=ld(t,!0,a,t);c.x=e.x+t.clientLeft,c.y=e.y+t.clientTop}else i&&l();a&&!r&&i&&l();let u=i&&!r&&!a?dd(i,s):Jl(0);return{x:o.left+s.scrollLeft-c.x-u.x,y:o.top+s.scrollTop-c.y-u.y,width:o.width,height:o.height}}function wd(e){return Zu(e).position===`static`}function Td(e,t){if(!Ru(e)||Zu(e).position===`fixed`)return null;if(t)return t(e);let n=e.offsetParent;return Fu(e)===n&&(n=n.ownerDocument.body),n}function Ed(e,t){let n=Pu(e);if(Hu(e))return n;if(!Ru(e)){let t=$u(e);for(;t&&!Xu(t);){if(Lu(t)&&!wd(t))return t;t=$u(t)}return n}let r=Td(e,t);for(;r&&Vu(r)&&wd(r);)r=Td(r,t);return r&&Xu(r)&&wd(r)&&!qu(r)?n:r||Ju(e)||n}var Dd=async function(e){let t=this.getOffsetParent||Ed,n=this.getDimensions,r=await n(e.floating);return{reference:Cd(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function Od(e){return Zu(e).direction===`rtl`}var kd={convertOffsetParentRelativeRectToViewportRelativeRect:fd,getDocumentElement:Fu,getClippingRect:xd,getOffsetParent:Ed,getElementRects:Dd,getClientRects:pd,getDimensions:Sd,getScale:ad,isElement:Lu,isRTL:Od};function Ad(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function jd(e,t){let n=null,r,i=Fu(e);function a(){var e;clearTimeout(r),(e=n)==null||e.disconnect(),n=null}function o(s,c){s===void 0&&(s=!1),c===void 0&&(c=1),a();let l=e.getBoundingClientRect(),{left:u,top:d,width:f,height:p}=l;if(s||t(),!f||!p)return;let m=ql(d),h=ql(i.clientWidth-(u+f)),g=ql(i.clientHeight-(d+p)),_=ql(u),v={rootMargin:-m+`px `+-h+`px `+-g+`px `+-_+`px`,threshold:Gl(0,Wl(1,c))||1},y=!0;function b(t){let n=t[0].intersectionRatio;if(n!==c){if(!y)return o();n?o(!1,n):r=setTimeout(()=>{o(!1,1e-7)},1e3)}n===1&&!Ad(l,e.getBoundingClientRect())&&o(),y=!1}try{n=new IntersectionObserver(b,{...v,root:i.ownerDocument})}catch{n=new IntersectionObserver(b,v)}n.observe(e)}return o(!0),a}function Md(e,t,n,r){r===void 0&&(r={});let{ancestorScroll:i=!0,ancestorResize:a=!0,elementResize:o=typeof ResizeObserver==`function`,layoutShift:s=typeof IntersectionObserver==`function`,animationFrame:c=!1}=r,l=id(e),u=i||a?[...l?td(l):[],...t?td(t):[]]:[];u.forEach(e=>{i&&e.addEventListener(`scroll`,n,{passive:!0}),a&&e.addEventListener(`resize`,n)});let d=l&&s?jd(l,n):null,f=-1,p=null;o&&(p=new ResizeObserver(e=>{let[r]=e;r&&r.target===l&&p&&t&&(p.unobserve(t),cancelAnimationFrame(f),f=requestAnimationFrame(()=>{var e;(e=p)==null||e.observe(t)})),n()}),l&&!c&&p.observe(l),t&&p.observe(t));let m,h=c?ld(e):null;c&&g();function g(){let t=ld(e);h&&!Ad(h,t)&&n(),h=t,m=requestAnimationFrame(g)}return n(),()=>{var e;u.forEach(e=>{i&&e.removeEventListener(`scroll`,n),a&&e.removeEventListener(`resize`,n)}),d?.(),(e=p)==null||e.disconnect(),p=null,c&&cancelAnimationFrame(m)}}var Nd=Ou,Pd=ku,Fd=Su,Id=ju,Ld=Tu,Rd=xu,zd=Au,Bd=(e,t,n)=>{let r=new Map,i={platform:kd,...n},a={...i.platform,_c:r};return bu(e,t,{...i,platform:a})},Vd=typeof document<`u`?F.useLayoutEffect:function(){};function Hd(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e==`function`&&e.toString()===t.toString())return!0;let n,r,i;if(e&&t&&typeof e==`object`){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(r=n;r--!==0;)if(!Hd(e[r],t[r]))return!1;return!0}if(i=Object.keys(e),n=i.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(t,i[r]))return!1;for(r=n;r--!==0;){let n=i[r];if(!(n===`_owner`&&e.$$typeof)&&!Hd(e[n],t[n]))return!1}return!0}return e!==e&&t!==t}function Ud(e){return typeof window>`u`?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Wd(e,t){let n=Ud(e);return Math.round(t*n)/n}function Gd(e){let t=F.useRef(e);return Vd(()=>{t.current=e}),t}function Kd(e){e===void 0&&(e={});let{placement:t=`bottom`,strategy:n=`absolute`,middleware:r=[],platform:i,elements:{reference:a,floating:o}={},transform:s=!0,whileElementsMounted:c,open:l}=e,[u,d]=F.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[f,p]=F.useState(r);Hd(f,r)||p(r);let[m,h]=F.useState(null),[g,_]=F.useState(null),v=F.useCallback(e=>{e!==S.current&&(S.current=e,h(e))},[]),y=F.useCallback(e=>{e!==C.current&&(C.current=e,_(e))},[]),b=a||m,x=o||g,S=F.useRef(null),C=F.useRef(null),w=F.useRef(u),T=c!=null,E=Gd(c),D=Gd(i),O=Gd(l),k=F.useCallback(()=>{if(!S.current||!C.current)return;let e={placement:t,strategy:n,middleware:f};D.current&&(e.platform=D.current),Bd(S.current,C.current,e).then(e=>{let t={...e,isPositioned:O.current!==!1};A.current&&!Hd(w.current,t)&&(w.current=t,vo.flushSync(()=>{d(t)}))})},[f,t,n,D,O]);Vd(()=>{l===!1&&w.current.isPositioned&&(w.current.isPositioned=!1,d(e=>({...e,isPositioned:!1})))},[l]);let A=F.useRef(!1);Vd(()=>(A.current=!0,()=>{A.current=!1}),[]),Vd(()=>{if(b&&(S.current=b),x&&(C.current=x),b&&x){if(E.current)return E.current(b,x,k);k()}},[b,x,k,E,T]);let ee=F.useMemo(()=>({reference:S,floating:C,setReference:v,setFloating:y}),[v,y]),j=F.useMemo(()=>({reference:b,floating:x}),[b,x]),te=F.useMemo(()=>{let e={position:n,left:0,top:0};if(!j.floating)return e;let t=Wd(j.floating,u.x),r=Wd(j.floating,u.y);return s?{...e,transform:`translate(`+t+`px, `+r+`px)`,...Ud(j.floating)>=1.5&&{willChange:`transform`}}:{position:n,left:t,top:r}},[n,s,j.floating,u.x,u.y]);return F.useMemo(()=>({...u,update:k,refs:ee,elements:j,floatingStyles:te}),[u,k,ee,j,te])}var qd=e=>{function t(e){return{}.hasOwnProperty.call(e,`current`)}return{name:`arrow`,options:e,fn(n){let{element:r,padding:i}=typeof e==`function`?e(n):e;return r&&t(r)?r.current==null?{}:Rd({element:r.current,padding:i}).fn(n):r?Rd({element:r,padding:i}).fn(n):{}}}},Jd=(e,t)=>{let n=Nd(e);return{name:n.name,fn:n.fn,options:[e,t]}},Yd=(e,t)=>{let n=Pd(e);return{name:n.name,fn:n.fn,options:[e,t]}},Xd=(e,t)=>({fn:zd(e).fn,options:[e,t]}),Zd=(e,t)=>{let n=Fd(e);return{name:n.name,fn:n.fn,options:[e,t]}},Qd=(e,t)=>{let n=Id(e);return{name:n.name,fn:n.fn,options:[e,t]}},$d=(e,t)=>{let n=Ld(e);return{name:n.name,fn:n.fn,options:[e,t]}},ef=(e,t)=>{let n=qd(e);return{name:n.name,fn:n.fn,options:[e,t]}},tf=`Arrow`,nf=F.forwardRef((e,t)=>{let{children:n,width:r=10,height:i=5,...a}=e;return(0,L.jsx)(yo.svg,{...a,ref:t,width:r,height:i,viewBox:`0 0 30 10`,preserveAspectRatio:`none`,children:e.asChild?n:(0,L.jsx)(`polygon`,{points:`0,0 30,0 15,10`})})});nf.displayName=tf;var rf=nf,af=`Popper`,[of,sf]=Eo(af),[cf,lf]=of(af),uf=e=>{let{__scopePopper:t,children:n}=e,[r,i]=F.useState(null);return(0,L.jsx)(cf,{scope:t,anchor:r,onAnchorChange:i,children:n})};uf.displayName=af;var df=`PopperAnchor`,ff=F.forwardRef((e,t)=>{let{__scopePopper:n,virtualRef:r,...i}=e,a=lf(df,n),o=F.useRef(null),s=co(t,o),c=F.useRef(null);return F.useEffect(()=>{let e=c.current;c.current=r?.current||o.current,e!==c.current&&a.onAnchorChange(c.current)}),r?null:(0,L.jsx)(yo.div,{...i,ref:s})});ff.displayName=df;var pf=`PopperContent`,[mf,hf]=of(pf),gf=F.forwardRef((e,t)=>{let{__scopePopper:n,side:r=`bottom`,sideOffset:i=0,align:a=`center`,alignOffset:o=0,arrowPadding:s=0,avoidCollisions:c=!0,collisionBoundary:l=[],collisionPadding:u=0,sticky:d=`partial`,hideWhenDetached:f=!1,updatePositionStrategy:p=`optimized`,onPlaced:m,...h}=e,g=lf(pf,n),[_,v]=F.useState(null),y=co(t,e=>v(e)),[b,x]=F.useState(null),S=Hl(b),C=S?.width??0,w=S?.height??0,T=r+(a===`center`?``:`-`+a),E=typeof u==`number`?u:{top:0,right:0,bottom:0,left:0,...u},D=Array.isArray(l)?l:[l],O=D.length>0,k={padding:E,boundary:D.filter(bf),altBoundary:O},{refs:A,floatingStyles:ee,placement:j,isPositioned:te,middlewareData:M}=Kd({strategy:`fixed`,placement:T,whileElementsMounted:(...e)=>Md(...e,{animationFrame:p===`always`}),elements:{reference:g.anchor},middleware:[Jd({mainAxis:i+w,alignmentAxis:o}),c&&Yd({mainAxis:!0,crossAxis:!1,limiter:d===`partial`?Xd():void 0,...k}),c&&Zd({...k}),Qd({...k,apply:({elements:e,rects:t,availableWidth:n,availableHeight:r})=>{let{width:i,height:a}=t.reference,o=e.floating.style;o.setProperty(`--radix-popper-available-width`,`${n}px`),o.setProperty(`--radix-popper-available-height`,`${r}px`),o.setProperty(`--radix-popper-anchor-width`,`${i}px`),o.setProperty(`--radix-popper-anchor-height`,`${a}px`)}}),b&&ef({element:b,padding:s}),xf({arrowWidth:C,arrowHeight:w}),f&&$d({strategy:`referenceHidden`,...k})]}),[ne,N]=Sf(j),re=ts(m);ko(()=>{te&&re?.()},[te,re]);let ie=M.arrow?.x,ae=M.arrow?.y,oe=M.arrow?.centerOffset!==0,[se,ce]=F.useState();return ko(()=>{_&&ce(window.getComputedStyle(_).zIndex)},[_]),(0,L.jsx)(`div`,{ref:A.setFloating,"data-radix-popper-content-wrapper":``,style:{...ee,transform:te?ee.transform:`translate(0, -200%)`,minWidth:`max-content`,zIndex:se,"--radix-popper-transform-origin":[M.transformOrigin?.x,M.transformOrigin?.y].join(` `),...M.hide?.referenceHidden&&{visibility:`hidden`,pointerEvents:`none`}},dir:e.dir,children:(0,L.jsx)(mf,{scope:n,placedSide:ne,onArrowChange:x,arrowX:ie,arrowY:ae,shouldHideArrow:oe,children:(0,L.jsx)(yo.div,{"data-side":ne,"data-align":N,...h,ref:y,style:{...h.style,animation:te?void 0:`none`}})})})});gf.displayName=pf;var _f=`PopperArrow`,vf={top:`bottom`,right:`left`,bottom:`top`,left:`right`},yf=F.forwardRef(function(e,t){let{__scopePopper:n,...r}=e,i=hf(_f,n),a=vf[i.placedSide];return(0,L.jsx)(`span`,{ref:i.onArrowChange,style:{position:`absolute`,left:i.arrowX,top:i.arrowY,[a]:0,transformOrigin:{top:``,right:`0 0`,bottom:`center 0`,left:`100% 0`}[i.placedSide],transform:{top:`translateY(100%)`,right:`translateY(50%) rotate(90deg) translateX(-50%)`,bottom:`rotate(180deg)`,left:`translateY(50%) rotate(-90deg) translateX(50%)`}[i.placedSide],visibility:i.shouldHideArrow?`hidden`:void 0},children:(0,L.jsx)(rf,{...r,ref:t,style:{...r.style,display:`block`}})})});yf.displayName=_f;function bf(e){return e!==null}var xf=e=>({name:`transformOrigin`,options:e,fn(t){let{placement:n,rects:r,middlewareData:i}=t,a=i.arrow?.centerOffset!==0,o=a?0:e.arrowWidth,s=a?0:e.arrowHeight,[c,l]=Sf(n),u={start:`0%`,center:`50%`,end:`100%`}[l],d=(i.arrow?.x??0)+o/2,f=(i.arrow?.y??0)+s/2,p=``,m=``;return c===`bottom`?(p=a?u:`${d}px`,m=`${-s}px`):c===`top`?(p=a?u:`${d}px`,m=`${r.floating.height+s}px`):c===`right`?(p=`${-s}px`,m=a?u:`${f}px`):c===`left`&&(p=`${r.floating.width+s}px`,m=a?u:`${f}px`),{data:{x:p,y:m}}}});function Sf(e){let[t,n=`center`]=e.split(`-`);return[t,n]}var Cf=uf,wf=ff,Tf=gf,Ef=yf,Df=`Popover`,[Of,kf]=Eo(Df,[sf]),Af=sf(),[jf,Mf]=Of(Df),Nf=e=>{let{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:a,modal:o=!1}=e,s=Af(t),c=F.useRef(null),[l,u]=F.useState(!1),[d,f]=jo({prop:r,defaultProp:i??!1,onChange:a,caller:Df});return(0,L.jsx)(Cf,{...s,children:(0,L.jsx)(jf,{scope:t,contentId:Vo(),triggerRef:c,open:d,onOpenChange:f,onOpenToggle:F.useCallback(()=>f(e=>!e),[f]),hasCustomAnchor:l,onCustomAnchorAdd:F.useCallback(()=>u(!0),[]),onCustomAnchorRemove:F.useCallback(()=>u(!1),[]),modal:o,children:n})})};Nf.displayName=Df;var Pf=`PopoverAnchor`,Ff=F.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=Mf(Pf,n),a=Af(n),{onCustomAnchorAdd:o,onCustomAnchorRemove:s}=i;return F.useEffect(()=>(o(),()=>s()),[o,s]),(0,L.jsx)(wf,{...a,...r,ref:t})});Ff.displayName=Pf;var If=`PopoverTrigger`,Lf=F.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=Mf(If,n),a=Af(n),o=co(t,i.triggerRef),s=(0,L.jsx)(yo.button,{type:`button`,"aria-haspopup":`dialog`,"aria-expanded":i.open,"aria-controls":i.contentId,"data-state":Qf(i.open),...r,ref:o,onClick:Oo(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?s:(0,L.jsx)(wf,{asChild:!0,...a,children:s})});Lf.displayName=If;var Rf=`PopoverPortal`,[zf,Bf]=Of(Rf,{forceMount:void 0}),Vf=e=>{let{__scopePopover:t,forceMount:n,children:r,container:i}=e,a=Mf(Rf,t);return(0,L.jsx)(zf,{scope:t,forceMount:n,children:(0,L.jsx)(Fo,{present:n||a.open,children:(0,L.jsx)(Ns,{asChild:!0,container:i,children:r})})})};Vf.displayName=Rf;var Hf=`PopoverContent`,Uf=F.forwardRef((e,t)=>{let n=Bf(Hf,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,a=Mf(Hf,e.__scopePopover);return(0,L.jsx)(Fo,{present:r||a.open,children:a.modal?(0,L.jsx)(Gf,{...i,ref:t}):(0,L.jsx)(Kf,{...i,ref:t})})});Uf.displayName=Hf;var Wf=lo(`PopoverContent.RemoveScroll`),Gf=F.forwardRef((e,t)=>{let n=Mf(Hf,e.__scopePopover),r=F.useRef(null),i=co(t,r),a=F.useRef(!1);return F.useEffect(()=>{let e=r.current;if(e)return el(e)},[]),(0,L.jsx)(Gc,{as:Wf,allowPinchZoom:!0,children:(0,L.jsx)(qf,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Oo(e.onCloseAutoFocus,e=>{e.preventDefault(),a.current||n.triggerRef.current?.focus()}),onPointerDownOutside:Oo(e.onPointerDownOutside,e=>{let t=e.detail.originalEvent,n=t.button===0&&t.ctrlKey===!0;a.current=t.button===2||n},{checkForDefaultPrevented:!1}),onFocusOutside:Oo(e.onFocusOutside,e=>e.preventDefault(),{checkForDefaultPrevented:!1})})})}),Kf=F.forwardRef((e,t)=>{let n=Mf(Hf,e.__scopePopover),r=F.useRef(!1),i=F.useRef(!1);return(0,L.jsx)(qf,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:t=>{e.onCloseAutoFocus?.(t),t.defaultPrevented||(r.current||n.triggerRef.current?.focus(),t.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:t=>{e.onInteractOutside?.(t),t.defaultPrevented||(r.current=!0,t.detail.originalEvent.type===`pointerdown`&&(i.current=!0));let a=t.target;n.triggerRef.current?.contains(a)&&t.preventDefault(),t.detail.originalEvent.type===`focusin`&&i.current&&t.preventDefault()}})}),qf=F.forwardRef((e,t)=>{let{__scopePopover:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:a,disableOutsidePointerEvents:o,onEscapeKeyDown:s,onPointerDownOutside:c,onFocusOutside:l,onInteractOutside:u,...d}=e,f=Mf(Hf,n),p=Af(n);return Fs(),(0,L.jsx)(bs,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:a,children:(0,L.jsx)(ls,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:u,onEscapeKeyDown:s,onPointerDownOutside:c,onFocusOutside:l,onDismiss:()=>f.onOpenChange(!1),children:(0,L.jsx)(Tf,{"data-state":Qf(f.open),role:`dialog`,id:f.contentId,...p,...d,ref:t,style:{...d.style,"--radix-popover-content-transform-origin":`var(--radix-popper-transform-origin)`,"--radix-popover-content-available-width":`var(--radix-popper-available-width)`,"--radix-popover-content-available-height":`var(--radix-popper-available-height)`,"--radix-popover-trigger-width":`var(--radix-popper-anchor-width)`,"--radix-popover-trigger-height":`var(--radix-popper-anchor-height)`}})})})}),Jf=`PopoverClose`,Yf=F.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=Mf(Jf,n);return(0,L.jsx)(yo.button,{type:`button`,...r,ref:t,onClick:Oo(e.onClick,()=>i.onOpenChange(!1))})});Yf.displayName=Jf;var Xf=`PopoverArrow`,Zf=F.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=Af(n);return(0,L.jsx)(Ef,{...i,...r,ref:t})});Zf.displayName=Xf;function Qf(e){return e?`open`:`closed`}var $f=Nf,ep=Lf,tp=Vf,np=Uf,rp=Yf,[ip,eee]=Eo(`Tooltip`,[sf]),ap=sf(),op=`TooltipProvider`,sp=700,cp=`tooltip.open`,[lp,up]=ip(op),dp=e=>{let{__scopeTooltip:t,delayDuration:n=sp,skipDelayDuration:r=300,disableHoverableContent:i=!1,children:a}=e,o=F.useRef(!0),s=F.useRef(!1),c=F.useRef(0);return F.useEffect(()=>{let e=c.current;return()=>window.clearTimeout(e)},[]),(0,L.jsx)(lp,{scope:t,isOpenDelayedRef:o,delayDuration:n,onOpen:F.useCallback(()=>{window.clearTimeout(c.current),o.current=!1},[]),onClose:F.useCallback(()=>{window.clearTimeout(c.current),c.current=window.setTimeout(()=>o.current=!0,r)},[r]),isPointerInTransitRef:s,onPointerInTransitChange:F.useCallback(e=>{s.current=e},[]),disableHoverableContent:i,children:a})};dp.displayName=op;var fp=`Tooltip`,[pp,mp]=ip(fp),hp=e=>{let{__scopeTooltip:t,children:n,open:r,defaultOpen:i,onOpenChange:a,disableHoverableContent:o,delayDuration:s}=e,c=up(fp,e.__scopeTooltip),l=ap(t),[u,d]=F.useState(null),f=Vo(),p=F.useRef(0),m=o??c.disableHoverableContent,h=s??c.delayDuration,g=F.useRef(!1),[_,v]=jo({prop:r,defaultProp:i??!1,onChange:e=>{e?(c.onOpen(),document.dispatchEvent(new CustomEvent(cp))):c.onClose(),a?.(e)},caller:fp}),y=F.useMemo(()=>_?g.current?`delayed-open`:`instant-open`:`closed`,[_]),b=F.useCallback(()=>{window.clearTimeout(p.current),p.current=0,g.current=!1,v(!0)},[v]),x=F.useCallback(()=>{window.clearTimeout(p.current),p.current=0,v(!1)},[v]),S=F.useCallback(()=>{window.clearTimeout(p.current),p.current=window.setTimeout(()=>{g.current=!0,v(!0),p.current=0},h)},[h,v]);return F.useEffect(()=>()=>{p.current&&=(window.clearTimeout(p.current),0)},[]),(0,L.jsx)(Cf,{...l,children:(0,L.jsx)(pp,{scope:t,contentId:f,open:_,stateAttribute:y,trigger:u,onTriggerChange:d,onTriggerEnter:F.useCallback(()=>{c.isOpenDelayedRef.current?S():b()},[c.isOpenDelayedRef,S,b]),onTriggerLeave:F.useCallback(()=>{m?x():(window.clearTimeout(p.current),p.current=0)},[x,m]),onOpen:b,onClose:x,disableHoverableContent:m,children:n})})};hp.displayName=fp;var gp=`TooltipTrigger`,_p=F.forwardRef((e,t)=>{let{__scopeTooltip:n,...r}=e,i=mp(gp,n),a=up(gp,n),o=ap(n),s=co(t,F.useRef(null),i.onTriggerChange),c=F.useRef(!1),l=F.useRef(!1),u=F.useCallback(()=>c.current=!1,[]);return F.useEffect(()=>()=>document.removeEventListener(`pointerup`,u),[u]),(0,L.jsx)(wf,{asChild:!0,...o,children:(0,L.jsx)(yo.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...r,ref:s,onPointerMove:Oo(e.onPointerMove,e=>{e.pointerType!==`touch`&&!l.current&&!a.isPointerInTransitRef.current&&(i.onTriggerEnter(),l.current=!0)}),onPointerLeave:Oo(e.onPointerLeave,()=>{i.onTriggerLeave(),l.current=!1}),onPointerDown:Oo(e.onPointerDown,()=>{i.open&&i.onClose(),c.current=!0,document.addEventListener(`pointerup`,u,{once:!0})}),onFocus:Oo(e.onFocus,()=>{c.current||i.onOpen()}),onBlur:Oo(e.onBlur,i.onClose),onClick:Oo(e.onClick,i.onClose)})})});_p.displayName=gp;var vp=`TooltipPortal`,[yp,bp]=ip(vp,{forceMount:void 0}),xp=e=>{let{__scopeTooltip:t,forceMount:n,children:r,container:i}=e,a=mp(vp,t);return(0,L.jsx)(yp,{scope:t,forceMount:n,children:(0,L.jsx)(Fo,{present:n||a.open,children:(0,L.jsx)(Ns,{asChild:!0,container:i,children:r})})})};xp.displayName=vp;var Sp=`TooltipContent`,Cp=F.forwardRef((e,t)=>{let n=bp(Sp,e.__scopeTooltip),{forceMount:r=n.forceMount,side:i=`top`,...a}=e,o=mp(Sp,e.__scopeTooltip);return(0,L.jsx)(Fo,{present:r||o.open,children:o.disableHoverableContent?(0,L.jsx)(Op,{side:i,...a,ref:t}):(0,L.jsx)(wp,{side:i,...a,ref:t})})}),wp=F.forwardRef((e,t)=>{let n=mp(Sp,e.__scopeTooltip),r=up(Sp,e.__scopeTooltip),i=F.useRef(null),a=co(t,i),[o,s]=F.useState(null),{trigger:c,onClose:l}=n,u=i.current,{onPointerInTransitChange:d}=r,f=F.useCallback(()=>{s(null),d(!1)},[d]),p=F.useCallback((e,t)=>{let n=e.currentTarget,r={x:e.clientX,y:e.clientY},i=Mp(r,jp(r,n.getBoundingClientRect())),a=Np(t.getBoundingClientRect());s(Fp([...i,...a])),d(!0)},[d]);return F.useEffect(()=>()=>f(),[f]),F.useEffect(()=>{if(c&&u){let e=e=>p(e,u),t=e=>p(e,c);return c.addEventListener(`pointerleave`,e),u.addEventListener(`pointerleave`,t),()=>{c.removeEventListener(`pointerleave`,e),u.removeEventListener(`pointerleave`,t)}}},[c,u,p,f]),F.useEffect(()=>{if(o){let e=e=>{let t=e.target,n={x:e.clientX,y:e.clientY},r=c?.contains(t)||u?.contains(t),i=!Pp(n,o);r?f():i&&(f(),l())};return document.addEventListener(`pointermove`,e),()=>document.removeEventListener(`pointermove`,e)}},[c,u,o,l,f]),(0,L.jsx)(Op,{...e,ref:a})}),[Tp,Ep]=ip(fp,{isInside:!1}),Dp=mo(`TooltipContent`),Op=F.forwardRef((e,t)=>{let{__scopeTooltip:n,children:r,"aria-label":i,onEscapeKeyDown:a,onPointerDownOutside:o,...s}=e,c=mp(Sp,n),l=ap(n),{onClose:u}=c;return F.useEffect(()=>(document.addEventListener(cp,u),()=>document.removeEventListener(cp,u)),[u]),F.useEffect(()=>{if(c.trigger){let e=e=>{e.target?.contains(c.trigger)&&u()};return window.addEventListener(`scroll`,e,{capture:!0}),()=>window.removeEventListener(`scroll`,e,{capture:!0})}},[c.trigger,u]),(0,L.jsx)(ls,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:a,onPointerDownOutside:o,onFocusOutside:e=>e.preventDefault(),onDismiss:u,children:(0,L.jsxs)(Tf,{"data-state":c.stateAttribute,...l,...s,ref:t,style:{...s.style,"--radix-tooltip-content-transform-origin":`var(--radix-popper-transform-origin)`,"--radix-tooltip-content-available-width":`var(--radix-popper-available-width)`,"--radix-tooltip-content-available-height":`var(--radix-popper-available-height)`,"--radix-tooltip-trigger-width":`var(--radix-popper-anchor-width)`,"--radix-tooltip-trigger-height":`var(--radix-popper-anchor-height)`},children:[(0,L.jsx)(Dp,{children:r}),(0,L.jsx)(Tp,{scope:n,isInside:!0,children:(0,L.jsx)(wo,{id:c.contentId,role:`tooltip`,children:i||r})})]})})});Cp.displayName=Sp;var kp=`TooltipArrow`,Ap=F.forwardRef((e,t)=>{let{__scopeTooltip:n,...r}=e,i=ap(n);return Ep(kp,n).isInside?null:(0,L.jsx)(Ef,{...i,...r,ref:t})});Ap.displayName=kp;function jp(e,t){let n=Math.abs(t.top-e.y),r=Math.abs(t.bottom-e.y),i=Math.abs(t.right-e.x),a=Math.abs(t.left-e.x);switch(Math.min(n,r,i,a)){case a:return`left`;case i:return`right`;case n:return`top`;case r:return`bottom`;default:throw Error(`unreachable`)}}function Mp(e,t,n=5){let r=[];switch(t){case`top`:r.push({x:e.x-n,y:e.y+n},{x:e.x+n,y:e.y+n});break;case`bottom`:r.push({x:e.x-n,y:e.y-n},{x:e.x+n,y:e.y-n});break;case`left`:r.push({x:e.x+n,y:e.y-n},{x:e.x+n,y:e.y+n});break;case`right`:r.push({x:e.x-n,y:e.y-n},{x:e.x-n,y:e.y+n});break}return r}function Np(e){let{top:t,right:n,bottom:r,left:i}=e;return[{x:i,y:t},{x:n,y:t},{x:n,y:r},{x:i,y:r}]}function Pp(e,t){let{x:n,y:r}=e,i=!1;for(let e=0,a=t.length-1;e<t.length;a=e++){let o=t[e],s=t[a],c=o.x,l=o.y,u=s.x,d=s.y;l>r!=d>r&&n<(u-c)*(r-l)/(d-l)+c&&(i=!i)}return i}function Fp(e){let t=e.slice();return t.sort((e,t)=>e.x<t.x?-1:e.x>t.x?1:e.y<t.y?-1:+(e.y>t.y)),Ip(t)}function Ip(e){if(e.length<=1)return e.slice();let t=[];for(let n=0;n<e.length;n++){let r=e[n];for(;t.length>=2;){let e=t[t.length-1],n=t[t.length-2];if((e.x-n.x)*(r.y-n.y)>=(e.y-n.y)*(r.x-n.x))t.pop();else break}t.push(r)}t.pop();let n=[];for(let t=e.length-1;t>=0;t--){let r=e[t];for(;n.length>=2;){let e=n[n.length-1],t=n[n.length-2];if((e.x-t.x)*(r.y-t.y)>=(e.y-t.y)*(r.x-t.x))n.pop();else break}n.push(r)}return n.pop(),t.length===1&&n.length===1&&t[0].x===n[0].x&&t[0].y===n[0].y?t:t.concat(n)}var Lp=dp,Rp=hp,zp=_p,Bp=xp,Vp=Cp,Hp=Ap,Up=Ke();function Wp(e){var t,n,r=``;if(typeof e==`string`||typeof e==`number`)r+=e;else if(typeof e==`object`)if(Array.isArray(e)){var i=e.length;for(t=0;t<i;t++)e[t]&&(n=Wp(e[t]))&&(r&&(r+=` `),r+=n)}else for(n in e)e[n]&&(r&&(r+=` `),r+=n);return r}function Gp(){for(var e,t,n=0,r=``,i=arguments.length;n<i;n++)(e=arguments[n])&&(t=Wp(e))&&(r&&(r+=` `),r+=t);return r}var Kp=(e,t)=>{let n=Array(e.length+t.length);for(let t=0;t<e.length;t++)n[t]=e[t];for(let r=0;r<t.length;r++)n[e.length+r]=t[r];return n},qp=(e,t)=>({classGroupId:e,validator:t}),Jp=(e=new Map,t=null,n)=>({nextPart:e,validators:t,classGroupId:n}),Yp=`-`,Xp=[],Zp=`arbitrary..`,Qp=e=>{let t=tm(e),{conflictingClassGroups:n,conflictingClassGroupModifiers:r}=e;return{getClassGroupId:e=>{if(e.startsWith(`[`)&&e.endsWith(`]`))return em(e);let n=e.split(Yp);return $p(n,+(n[0]===``&&n.length>1),t)},getConflictingClassGroupIds:(e,t)=>{if(t){let t=r[e],i=n[e];return t?i?Kp(i,t):t:i||Xp}return n[e]||Xp}}},$p=(e,t,n)=>{if(e.length-t===0)return n.classGroupId;let r=e[t],i=n.nextPart.get(r);if(i){let n=$p(e,t+1,i);if(n)return n}let a=n.validators;if(a===null)return;let o=t===0?e.join(Yp):e.slice(t).join(Yp),s=a.length;for(let e=0;e<s;e++){let t=a[e];if(t.validator(o))return t.classGroupId}},em=e=>e.slice(1,-1).indexOf(`:`)===-1?void 0:(()=>{let t=e.slice(1,-1),n=t.indexOf(`:`),r=t.slice(0,n);return r?Zp+r:void 0})(),tm=e=>{let{theme:t,classGroups:n}=e;return nm(n,t)},nm=(e,t)=>{let n=Jp();for(let r in e){let i=e[r];rm(i,n,r,t)}return n},rm=(e,t,n,r)=>{let i=e.length;for(let a=0;a<i;a++){let i=e[a];im(i,t,n,r)}},im=(e,t,n,r)=>{if(typeof e==`string`){am(e,t,n);return}if(typeof e==`function`){om(e,t,n,r);return}sm(e,t,n,r)},am=(e,t,n)=>{let r=e===``?t:cm(t,e);r.classGroupId=n},om=(e,t,n,r)=>{if(tee(e)){rm(e(r),t,n,r);return}t.validators===null&&(t.validators=[]),t.validators.push(qp(n,e))},sm=(e,t,n,r)=>{let i=Object.entries(e),a=i.length;for(let e=0;e<a;e++){let[a,o]=i[e];rm(o,cm(t,a),n,r)}},cm=(e,t)=>{let n=e,r=t.split(Yp),i=r.length;for(let e=0;e<i;e++){let t=r[e],i=n.nextPart.get(t);i||(i=Jp(),n.nextPart.set(t,i)),n=i}return n},tee=e=>`isThemeGetter`in e&&e.isThemeGetter===!0,nee=e=>{if(e<1)return{get:()=>void 0,set:()=>{}};let t=0,n=Object.create(null),r=Object.create(null),i=(i,a)=>{n[i]=a,t++,t>e&&(t=0,r=n,n=Object.create(null))};return{get(e){let t=n[e];if(t!==void 0)return t;if((t=r[e])!==void 0)return i(e,t),t},set(e,t){e in n?n[e]=t:i(e,t)}}},lm=`!`,um=`:`,ree=[],dm=(e,t,n,r,i)=>({modifiers:e,hasImportantModifier:t,baseClassName:n,maybePostfixModifierPosition:r,isExternal:i}),iee=e=>{let{prefix:t,experimentalParseClassName:n}=e,r=e=>{let t=[],n=0,r=0,i=0,a,o=e.length;for(let s=0;s<o;s++){let o=e[s];if(n===0&&r===0){if(o===um){t.push(e.slice(i,s)),i=s+1;continue}if(o===`/`){a=s;continue}}o===`[`?n++:o===`]`?n--:o===`(`?r++:o===`)`&&r--}let s=t.length===0?e:e.slice(i),c=s,l=!1;s.endsWith(lm)?(c=s.slice(0,-1),l=!0):s.startsWith(lm)&&(c=s.slice(1),l=!0);let u=a&&a>i?a-i:void 0;return dm(t,l,c,u)};if(t){let e=t+um,n=r;r=t=>t.startsWith(e)?n(t.slice(e.length)):dm(ree,!1,t,void 0,!0)}if(n){let e=r;r=t=>n({className:t,parseClassName:e})}return r},aee=e=>{let t=new Map;return e.orderSensitiveModifiers.forEach((e,n)=>{t.set(e,1e6+n)}),e=>{let n=[],r=[];for(let i=0;i<e.length;i++){let a=e[i],o=a[0]===`[`,s=t.has(a);o||s?(r.length>0&&(r.sort(),n.push(...r),r=[]),n.push(a)):r.push(a)}return r.length>0&&(r.sort(),n.push(...r)),n}},oee=e=>({cache:nee(e.cacheSize),parseClassName:iee(e),sortModifiers:aee(e),...Qp(e)}),fm=/\s+/,pm=(e,t)=>{let{parseClassName:n,getClassGroupId:r,getConflictingClassGroupIds:i,sortModifiers:a}=t,o=[],s=e.trim().split(fm),c=``;for(let e=s.length-1;e>=0;--e){let t=s[e],{isExternal:l,modifiers:u,hasImportantModifier:d,baseClassName:f,maybePostfixModifierPosition:p}=n(t);if(l){c=t+(c.length>0?` `+c:c);continue}let m=!!p,h=r(m?f.substring(0,p):f);if(!h){if(!m){c=t+(c.length>0?` `+c:c);continue}if(h=r(f),!h){c=t+(c.length>0?` `+c:c);continue}m=!1}let g=u.length===0?``:u.length===1?u[0]:a(u).join(`:`),_=d?g+lm:g,v=_+h;if(o.indexOf(v)>-1)continue;o.push(v);let y=i(h,m);for(let e=0;e<y.length;++e){let t=y[e];o.push(_+t)}c=t+(c.length>0?` `+c:c)}return c},mm=(...e)=>{let t=0,n,r,i=``;for(;t<e.length;)(n=e[t++])&&(r=hm(n))&&(i&&(i+=` `),i+=r);return i},hm=e=>{if(typeof e==`string`)return e;let t,n=``;for(let r=0;r<e.length;r++)e[r]&&(t=hm(e[r]))&&(n&&(n+=` `),n+=t);return n},gm=(e,...t)=>{let n,r,i,a,o=o=>(n=oee(t.reduce((e,t)=>t(e),e())),r=n.cache.get,i=n.cache.set,a=s,s(o)),s=e=>{let t=r(e);if(t)return t;let a=pm(e,n);return i(e,a),a};return a=o,(...e)=>a(mm(...e))},_m=[],vm=e=>{let t=t=>t[e]||_m;return t.isThemeGetter=!0,t},ym=/^\[(?:(\w[\w-]*):)?(.+)\]$/i,bm=/^\((?:(\w[\w-]*):)?(.+)\)$/i,xm=/^\d+(?:\.\d+)?\/\d+(?:\.\d+)?$/,Sm=/^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/,Cm=/\d+(%|px|r?em|[sdl]?v([hwib]|min|max)|pt|pc|in|cm|mm|cap|ch|ex|r?lh|cq(w|h|i|b|min|max))|\b(calc|min|max|clamp)\(.+\)|^0$/,wm=/^(rgba?|hsla?|hwb|(ok)?(lab|lch)|color-mix)\(.+\)$/,Tm=/^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/,Em=/^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/,Dm=e=>xm.test(e),Om=e=>!!e&&!Number.isNaN(Number(e)),km=e=>!!e&&Number.isInteger(Number(e)),Am=e=>e.endsWith(`%`)&&Om(e.slice(0,-1)),jm=e=>Sm.test(e),Mm=()=>!0,Nm=e=>Cm.test(e)&&!wm.test(e),Pm=()=>!1,Fm=e=>Tm.test(e),Im=e=>Em.test(e),Lm=e=>!zm(e)&&!Wm(e),Rm=e=>Qm(e,nh,Pm),zm=e=>ym.test(e),Bm=e=>Qm(e,rh,Nm),Vm=e=>Qm(e,ih,Om),see=e=>Qm(e,oh,Mm),cee=e=>Qm(e,ah,Pm),Hm=e=>Qm(e,eh,Pm),lee=e=>Qm(e,th,Im),Um=e=>Qm(e,sh,Fm),Wm=e=>bm.test(e),Gm=e=>$m(e,rh),Km=e=>$m(e,ah),qm=e=>$m(e,eh),Jm=e=>$m(e,nh),Ym=e=>$m(e,th),Xm=e=>$m(e,sh,!0),Zm=e=>$m(e,oh,!0),Qm=(e,t,n)=>{let r=ym.exec(e);return r?r[1]?t(r[1]):n(r[2]):!1},$m=(e,t,n=!1)=>{let r=bm.exec(e);return r?r[1]?t(r[1]):n:!1},eh=e=>e===`position`||e===`percentage`,th=e=>e===`image`||e===`url`,nh=e=>e===`length`||e===`size`||e===`bg-size`,rh=e=>e===`length`,ih=e=>e===`number`,ah=e=>e===`family-name`,oh=e=>e===`number`||e===`weight`,sh=e=>e===`shadow`,ch=gm(()=>{let e=vm(`color`),t=vm(`font`),n=vm(`text`),r=vm(`font-weight`),i=vm(`tracking`),a=vm(`leading`),o=vm(`breakpoint`),s=vm(`container`),c=vm(`spacing`),l=vm(`radius`),u=vm(`shadow`),d=vm(`inset-shadow`),f=vm(`text-shadow`),p=vm(`drop-shadow`),m=vm(`blur`),h=vm(`perspective`),g=vm(`aspect`),_=vm(`ease`),v=vm(`animate`),y=()=>[`auto`,`avoid`,`all`,`avoid-page`,`page`,`left`,`right`,`column`],b=()=>[`center`,`top`,`bottom`,`left`,`right`,`top-left`,`left-top`,`top-right`,`right-top`,`bottom-right`,`right-bottom`,`bottom-left`,`left-bottom`],x=()=>[...b(),Wm,zm],S=()=>[`auto`,`hidden`,`clip`,`visible`,`scroll`],C=()=>[`auto`,`contain`,`none`],w=()=>[Wm,zm,c],T=()=>[Dm,`full`,`auto`,...w()],E=()=>[km,`none`,`subgrid`,Wm,zm],D=()=>[`auto`,{span:[`full`,km,Wm,zm]},km,Wm,zm],O=()=>[km,`auto`,Wm,zm],k=()=>[`auto`,`min`,`max`,`fr`,Wm,zm],A=()=>[`start`,`end`,`center`,`between`,`around`,`evenly`,`stretch`,`baseline`,`center-safe`,`end-safe`],ee=()=>[`start`,`end`,`center`,`stretch`,`center-safe`,`end-safe`],j=()=>[`auto`,...w()],te=()=>[Dm,`auto`,`full`,`dvw`,`dvh`,`lvw`,`lvh`,`svw`,`svh`,`min`,`max`,`fit`,...w()],M=()=>[Dm,`screen`,`full`,`dvw`,`lvw`,`svw`,`min`,`max`,`fit`,...w()],ne=()=>[Dm,`screen`,`full`,`lh`,`dvh`,`lvh`,`svh`,`min`,`max`,`fit`,...w()],N=()=>[e,Wm,zm],re=()=>[...b(),qm,Hm,{position:[Wm,zm]}],ie=()=>[`no-repeat`,{repeat:[``,`x`,`y`,`space`,`round`]}],ae=()=>[`auto`,`cover`,`contain`,Jm,Rm,{size:[Wm,zm]}],oe=()=>[Am,Gm,Bm],se=()=>[``,`none`,`full`,l,Wm,zm],ce=()=>[``,Om,Gm,Bm],le=()=>[`solid`,`dashed`,`dotted`,`double`],ue=()=>[`normal`,`multiply`,`screen`,`overlay`,`darken`,`lighten`,`color-dodge`,`color-burn`,`hard-light`,`soft-light`,`difference`,`exclusion`,`hue`,`saturation`,`color`,`luminosity`],de=()=>[Om,Am,qm,Hm],fe=()=>[``,`none`,m,Wm,zm],pe=()=>[`none`,Om,Wm,zm],me=()=>[`none`,Om,Wm,zm],he=()=>[Om,Wm,zm],ge=()=>[Dm,`full`,...w()];return{cacheSize:500,theme:{animate:[`spin`,`ping`,`pulse`,`bounce`],aspect:[`video`],blur:[jm],breakpoint:[jm],color:[Mm],container:[jm],"drop-shadow":[jm],ease:[`in`,`out`,`in-out`],font:[Lm],"font-weight":[`thin`,`extralight`,`light`,`normal`,`medium`,`semibold`,`bold`,`extrabold`,`black`],"inset-shadow":[jm],leading:[`none`,`tight`,`snug`,`normal`,`relaxed`,`loose`],perspective:[`dramatic`,`near`,`normal`,`midrange`,`distant`,`none`],radius:[jm],shadow:[jm],spacing:[`px`,Om],text:[jm],"text-shadow":[jm],tracking:[`tighter`,`tight`,`normal`,`wide`,`wider`,`widest`]},classGroups:{aspect:[{aspect:[`auto`,`square`,Dm,zm,Wm,g]}],container:[`container`],columns:[{columns:[Om,zm,Wm,s]}],"break-after":[{"break-after":y()}],"break-before":[{"break-before":y()}],"break-inside":[{"break-inside":[`auto`,`avoid`,`avoid-page`,`avoid-column`]}],"box-decoration":[{"box-decoration":[`slice`,`clone`]}],box:[{box:[`border`,`content`]}],display:[`block`,`inline-block`,`inline`,`flex`,`inline-flex`,`table`,`inline-table`,`table-caption`,`table-cell`,`table-column`,`table-column-group`,`table-footer-group`,`table-header-group`,`table-row-group`,`table-row`,`flow-root`,`grid`,`inline-grid`,`contents`,`list-item`,`hidden`],sr:[`sr-only`,`not-sr-only`],float:[{float:[`right`,`left`,`none`,`start`,`end`]}],clear:[{clear:[`left`,`right`,`both`,`none`,`start`,`end`]}],isolation:[`isolate`,`isolation-auto`],"object-fit":[{object:[`contain`,`cover`,`fill`,`none`,`scale-down`]}],"object-position":[{object:x()}],overflow:[{overflow:S()}],"overflow-x":[{"overflow-x":S()}],"overflow-y":[{"overflow-y":S()}],overscroll:[{overscroll:C()}],"overscroll-x":[{"overscroll-x":C()}],"overscroll-y":[{"overscroll-y":C()}],position:[`static`,`fixed`,`absolute`,`relative`,`sticky`],inset:[{inset:T()}],"inset-x":[{"inset-x":T()}],"inset-y":[{"inset-y":T()}],start:[{"inset-s":T(),start:T()}],end:[{"inset-e":T(),end:T()}],"inset-bs":[{"inset-bs":T()}],"inset-be":[{"inset-be":T()}],top:[{top:T()}],right:[{right:T()}],bottom:[{bottom:T()}],left:[{left:T()}],visibility:[`visible`,`invisible`,`collapse`],z:[{z:[km,`auto`,Wm,zm]}],basis:[{basis:[Dm,`full`,`auto`,s,...w()]}],"flex-direction":[{flex:[`row`,`row-reverse`,`col`,`col-reverse`]}],"flex-wrap":[{flex:[`nowrap`,`wrap`,`wrap-reverse`]}],flex:[{flex:[Om,Dm,`auto`,`initial`,`none`,zm]}],grow:[{grow:[``,Om,Wm,zm]}],shrink:[{shrink:[``,Om,Wm,zm]}],order:[{order:[km,`first`,`last`,`none`,Wm,zm]}],"grid-cols":[{"grid-cols":E()}],"col-start-end":[{col:D()}],"col-start":[{"col-start":O()}],"col-end":[{"col-end":O()}],"grid-rows":[{"grid-rows":E()}],"row-start-end":[{row:D()}],"row-start":[{"row-start":O()}],"row-end":[{"row-end":O()}],"grid-flow":[{"grid-flow":[`row`,`col`,`dense`,`row-dense`,`col-dense`]}],"auto-cols":[{"auto-cols":k()}],"auto-rows":[{"auto-rows":k()}],gap:[{gap:w()}],"gap-x":[{"gap-x":w()}],"gap-y":[{"gap-y":w()}],"justify-content":[{justify:[...A(),`normal`]}],"justify-items":[{"justify-items":[...ee(),`normal`]}],"justify-self":[{"justify-self":[`auto`,...ee()]}],"align-content":[{content:[`normal`,...A()]}],"align-items":[{items:[...ee(),{baseline:[``,`last`]}]}],"align-self":[{self:[`auto`,...ee(),{baseline:[``,`last`]}]}],"place-content":[{"place-content":A()}],"place-items":[{"place-items":[...ee(),`baseline`]}],"place-self":[{"place-self":[`auto`,...ee()]}],p:[{p:w()}],px:[{px:w()}],py:[{py:w()}],ps:[{ps:w()}],pe:[{pe:w()}],pbs:[{pbs:w()}],pbe:[{pbe:w()}],pt:[{pt:w()}],pr:[{pr:w()}],pb:[{pb:w()}],pl:[{pl:w()}],m:[{m:j()}],mx:[{mx:j()}],my:[{my:j()}],ms:[{ms:j()}],me:[{me:j()}],mbs:[{mbs:j()}],mbe:[{mbe:j()}],mt:[{mt:j()}],mr:[{mr:j()}],mb:[{mb:j()}],ml:[{ml:j()}],"space-x":[{"space-x":w()}],"space-x-reverse":[`space-x-reverse`],"space-y":[{"space-y":w()}],"space-y-reverse":[`space-y-reverse`],size:[{size:te()}],"inline-size":[{inline:[`auto`,...M()]}],"min-inline-size":[{"min-inline":[`auto`,...M()]}],"max-inline-size":[{"max-inline":[`none`,...M()]}],"block-size":[{block:[`auto`,...ne()]}],"min-block-size":[{"min-block":[`auto`,...ne()]}],"max-block-size":[{"max-block":[`none`,...ne()]}],w:[{w:[s,`screen`,...te()]}],"min-w":[{"min-w":[s,`screen`,`none`,...te()]}],"max-w":[{"max-w":[s,`screen`,`none`,`prose`,{screen:[o]},...te()]}],h:[{h:[`screen`,`lh`,...te()]}],"min-h":[{"min-h":[`screen`,`lh`,`none`,...te()]}],"max-h":[{"max-h":[`screen`,`lh`,...te()]}],"font-size":[{text:[`base`,n,Gm,Bm]}],"font-smoothing":[`antialiased`,`subpixel-antialiased`],"font-style":[`italic`,`not-italic`],"font-weight":[{font:[r,Zm,see]}],"font-stretch":[{"font-stretch":[`ultra-condensed`,`extra-condensed`,`condensed`,`semi-condensed`,`normal`,`semi-expanded`,`expanded`,`extra-expanded`,`ultra-expanded`,Am,zm]}],"font-family":[{font:[Km,cee,t]}],"font-features":[{"font-features":[zm]}],"fvn-normal":[`normal-nums`],"fvn-ordinal":[`ordinal`],"fvn-slashed-zero":[`slashed-zero`],"fvn-figure":[`lining-nums`,`oldstyle-nums`],"fvn-spacing":[`proportional-nums`,`tabular-nums`],"fvn-fraction":[`diagonal-fractions`,`stacked-fractions`],tracking:[{tracking:[i,Wm,zm]}],"line-clamp":[{"line-clamp":[Om,`none`,Wm,Vm]}],leading:[{leading:[a,...w()]}],"list-image":[{"list-image":[`none`,Wm,zm]}],"list-style-position":[{list:[`inside`,`outside`]}],"list-style-type":[{list:[`disc`,`decimal`,`none`,Wm,zm]}],"text-alignment":[{text:[`left`,`center`,`right`,`justify`,`start`,`end`]}],"placeholder-color":[{placeholder:N()}],"text-color":[{text:N()}],"text-decoration":[`underline`,`overline`,`line-through`,`no-underline`],"text-decoration-style":[{decoration:[...le(),`wavy`]}],"text-decoration-thickness":[{decoration:[Om,`from-font`,`auto`,Wm,Bm]}],"text-decoration-color":[{decoration:N()}],"underline-offset":[{"underline-offset":[Om,`auto`,Wm,zm]}],"text-transform":[`uppercase`,`lowercase`,`capitalize`,`normal-case`],"text-overflow":[`truncate`,`text-ellipsis`,`text-clip`],"text-wrap":[{text:[`wrap`,`nowrap`,`balance`,`pretty`]}],indent:[{indent:w()}],"vertical-align":[{align:[`baseline`,`top`,`middle`,`bottom`,`text-top`,`text-bottom`,`sub`,`super`,Wm,zm]}],whitespace:[{whitespace:[`normal`,`nowrap`,`pre`,`pre-line`,`pre-wrap`,`break-spaces`]}],break:[{break:[`normal`,`words`,`all`,`keep`]}],wrap:[{wrap:[`break-word`,`anywhere`,`normal`]}],hyphens:[{hyphens:[`none`,`manual`,`auto`]}],content:[{content:[`none`,Wm,zm]}],"bg-attachment":[{bg:[`fixed`,`local`,`scroll`]}],"bg-clip":[{"bg-clip":[`border`,`padding`,`content`,`text`]}],"bg-origin":[{"bg-origin":[`border`,`padding`,`content`]}],"bg-position":[{bg:re()}],"bg-repeat":[{bg:ie()}],"bg-size":[{bg:ae()}],"bg-image":[{bg:[`none`,{linear:[{to:[`t`,`tr`,`r`,`br`,`b`,`bl`,`l`,`tl`]},km,Wm,zm],radial:[``,Wm,zm],conic:[km,Wm,zm]},Ym,lee]}],"bg-color":[{bg:N()}],"gradient-from-pos":[{from:oe()}],"gradient-via-pos":[{via:oe()}],"gradient-to-pos":[{to:oe()}],"gradient-from":[{from:N()}],"gradient-via":[{via:N()}],"gradient-to":[{to:N()}],rounded:[{rounded:se()}],"rounded-s":[{"rounded-s":se()}],"rounded-e":[{"rounded-e":se()}],"rounded-t":[{"rounded-t":se()}],"rounded-r":[{"rounded-r":se()}],"rounded-b":[{"rounded-b":se()}],"rounded-l":[{"rounded-l":se()}],"rounded-ss":[{"rounded-ss":se()}],"rounded-se":[{"rounded-se":se()}],"rounded-ee":[{"rounded-ee":se()}],"rounded-es":[{"rounded-es":se()}],"rounded-tl":[{"rounded-tl":se()}],"rounded-tr":[{"rounded-tr":se()}],"rounded-br":[{"rounded-br":se()}],"rounded-bl":[{"rounded-bl":se()}],"border-w":[{border:ce()}],"border-w-x":[{"border-x":ce()}],"border-w-y":[{"border-y":ce()}],"border-w-s":[{"border-s":ce()}],"border-w-e":[{"border-e":ce()}],"border-w-bs":[{"border-bs":ce()}],"border-w-be":[{"border-be":ce()}],"border-w-t":[{"border-t":ce()}],"border-w-r":[{"border-r":ce()}],"border-w-b":[{"border-b":ce()}],"border-w-l":[{"border-l":ce()}],"divide-x":[{"divide-x":ce()}],"divide-x-reverse":[`divide-x-reverse`],"divide-y":[{"divide-y":ce()}],"divide-y-reverse":[`divide-y-reverse`],"border-style":[{border:[...le(),`hidden`,`none`]}],"divide-style":[{divide:[...le(),`hidden`,`none`]}],"border-color":[{border:N()}],"border-color-x":[{"border-x":N()}],"border-color-y":[{"border-y":N()}],"border-color-s":[{"border-s":N()}],"border-color-e":[{"border-e":N()}],"border-color-bs":[{"border-bs":N()}],"border-color-be":[{"border-be":N()}],"border-color-t":[{"border-t":N()}],"border-color-r":[{"border-r":N()}],"border-color-b":[{"border-b":N()}],"border-color-l":[{"border-l":N()}],"divide-color":[{divide:N()}],"outline-style":[{outline:[...le(),`none`,`hidden`]}],"outline-offset":[{"outline-offset":[Om,Wm,zm]}],"outline-w":[{outline:[``,Om,Gm,Bm]}],"outline-color":[{outline:N()}],shadow:[{shadow:[``,`none`,u,Xm,Um]}],"shadow-color":[{shadow:N()}],"inset-shadow":[{"inset-shadow":[`none`,d,Xm,Um]}],"inset-shadow-color":[{"inset-shadow":N()}],"ring-w":[{ring:ce()}],"ring-w-inset":[`ring-inset`],"ring-color":[{ring:N()}],"ring-offset-w":[{"ring-offset":[Om,Bm]}],"ring-offset-color":[{"ring-offset":N()}],"inset-ring-w":[{"inset-ring":ce()}],"inset-ring-color":[{"inset-ring":N()}],"text-shadow":[{"text-shadow":[`none`,f,Xm,Um]}],"text-shadow-color":[{"text-shadow":N()}],opacity:[{opacity:[Om,Wm,zm]}],"mix-blend":[{"mix-blend":[...ue(),`plus-darker`,`plus-lighter`]}],"bg-blend":[{"bg-blend":ue()}],"mask-clip":[{"mask-clip":[`border`,`padding`,`content`,`fill`,`stroke`,`view`]},`mask-no-clip`],"mask-composite":[{mask:[`add`,`subtract`,`intersect`,`exclude`]}],"mask-image-linear-pos":[{"mask-linear":[Om]}],"mask-image-linear-from-pos":[{"mask-linear-from":de()}],"mask-image-linear-to-pos":[{"mask-linear-to":de()}],"mask-image-linear-from-color":[{"mask-linear-from":N()}],"mask-image-linear-to-color":[{"mask-linear-to":N()}],"mask-image-t-from-pos":[{"mask-t-from":de()}],"mask-image-t-to-pos":[{"mask-t-to":de()}],"mask-image-t-from-color":[{"mask-t-from":N()}],"mask-image-t-to-color":[{"mask-t-to":N()}],"mask-image-r-from-pos":[{"mask-r-from":de()}],"mask-image-r-to-pos":[{"mask-r-to":de()}],"mask-image-r-from-color":[{"mask-r-from":N()}],"mask-image-r-to-color":[{"mask-r-to":N()}],"mask-image-b-from-pos":[{"mask-b-from":de()}],"mask-image-b-to-pos":[{"mask-b-to":de()}],"mask-image-b-from-color":[{"mask-b-from":N()}],"mask-image-b-to-color":[{"mask-b-to":N()}],"mask-image-l-from-pos":[{"mask-l-from":de()}],"mask-image-l-to-pos":[{"mask-l-to":de()}],"mask-image-l-from-color":[{"mask-l-from":N()}],"mask-image-l-to-color":[{"mask-l-to":N()}],"mask-image-x-from-pos":[{"mask-x-from":de()}],"mask-image-x-to-pos":[{"mask-x-to":de()}],"mask-image-x-from-color":[{"mask-x-from":N()}],"mask-image-x-to-color":[{"mask-x-to":N()}],"mask-image-y-from-pos":[{"mask-y-from":de()}],"mask-image-y-to-pos":[{"mask-y-to":de()}],"mask-image-y-from-color":[{"mask-y-from":N()}],"mask-image-y-to-color":[{"mask-y-to":N()}],"mask-image-radial":[{"mask-radial":[Wm,zm]}],"mask-image-radial-from-pos":[{"mask-radial-from":de()}],"mask-image-radial-to-pos":[{"mask-radial-to":de()}],"mask-image-radial-from-color":[{"mask-radial-from":N()}],"mask-image-radial-to-color":[{"mask-radial-to":N()}],"mask-image-radial-shape":[{"mask-radial":[`circle`,`ellipse`]}],"mask-image-radial-size":[{"mask-radial":[{closest:[`side`,`corner`],farthest:[`side`,`corner`]}]}],"mask-image-radial-pos":[{"mask-radial-at":b()}],"mask-image-conic-pos":[{"mask-conic":[Om]}],"mask-image-conic-from-pos":[{"mask-conic-from":de()}],"mask-image-conic-to-pos":[{"mask-conic-to":de()}],"mask-image-conic-from-color":[{"mask-conic-from":N()}],"mask-image-conic-to-color":[{"mask-conic-to":N()}],"mask-mode":[{mask:[`alpha`,`luminance`,`match`]}],"mask-origin":[{"mask-origin":[`border`,`padding`,`content`,`fill`,`stroke`,`view`]}],"mask-position":[{mask:re()}],"mask-repeat":[{mask:ie()}],"mask-size":[{mask:ae()}],"mask-type":[{"mask-type":[`alpha`,`luminance`]}],"mask-image":[{mask:[`none`,Wm,zm]}],filter:[{filter:[``,`none`,Wm,zm]}],blur:[{blur:fe()}],brightness:[{brightness:[Om,Wm,zm]}],contrast:[{contrast:[Om,Wm,zm]}],"drop-shadow":[{"drop-shadow":[``,`none`,p,Xm,Um]}],"drop-shadow-color":[{"drop-shadow":N()}],grayscale:[{grayscale:[``,Om,Wm,zm]}],"hue-rotate":[{"hue-rotate":[Om,Wm,zm]}],invert:[{invert:[``,Om,Wm,zm]}],saturate:[{saturate:[Om,Wm,zm]}],sepia:[{sepia:[``,Om,Wm,zm]}],"backdrop-filter":[{"backdrop-filter":[``,`none`,Wm,zm]}],"backdrop-blur":[{"backdrop-blur":fe()}],"backdrop-brightness":[{"backdrop-brightness":[Om,Wm,zm]}],"backdrop-contrast":[{"backdrop-contrast":[Om,Wm,zm]}],"backdrop-grayscale":[{"backdrop-grayscale":[``,Om,Wm,zm]}],"backdrop-hue-rotate":[{"backdrop-hue-rotate":[Om,Wm,zm]}],"backdrop-invert":[{"backdrop-invert":[``,Om,Wm,zm]}],"backdrop-opacity":[{"backdrop-opacity":[Om,Wm,zm]}],"backdrop-saturate":[{"backdrop-saturate":[Om,Wm,zm]}],"backdrop-sepia":[{"backdrop-sepia":[``,Om,Wm,zm]}],"border-collapse":[{border:[`collapse`,`separate`]}],"border-spacing":[{"border-spacing":w()}],"border-spacing-x":[{"border-spacing-x":w()}],"border-spacing-y":[{"border-spacing-y":w()}],"table-layout":[{table:[`auto`,`fixed`]}],caption:[{caption:[`top`,`bottom`]}],transition:[{transition:[``,`all`,`colors`,`opacity`,`shadow`,`transform`,`none`,Wm,zm]}],"transition-behavior":[{transition:[`normal`,`discrete`]}],duration:[{duration:[Om,`initial`,Wm,zm]}],ease:[{ease:[`linear`,`initial`,_,Wm,zm]}],delay:[{delay:[Om,Wm,zm]}],animate:[{animate:[`none`,v,Wm,zm]}],backface:[{backface:[`hidden`,`visible`]}],perspective:[{perspective:[h,Wm,zm]}],"perspective-origin":[{"perspective-origin":x()}],rotate:[{rotate:pe()}],"rotate-x":[{"rotate-x":pe()}],"rotate-y":[{"rotate-y":pe()}],"rotate-z":[{"rotate-z":pe()}],scale:[{scale:me()}],"scale-x":[{"scale-x":me()}],"scale-y":[{"scale-y":me()}],"scale-z":[{"scale-z":me()}],"scale-3d":[`scale-3d`],skew:[{skew:he()}],"skew-x":[{"skew-x":he()}],"skew-y":[{"skew-y":he()}],transform:[{transform:[Wm,zm,``,`none`,`gpu`,`cpu`]}],"transform-origin":[{origin:x()}],"transform-style":[{transform:[`3d`,`flat`]}],translate:[{translate:ge()}],"translate-x":[{"translate-x":ge()}],"translate-y":[{"translate-y":ge()}],"translate-z":[{"translate-z":ge()}],"translate-none":[`translate-none`],accent:[{accent:N()}],appearance:[{appearance:[`none`,`auto`]}],"caret-color":[{caret:N()}],"color-scheme":[{scheme:[`normal`,`dark`,`light`,`light-dark`,`only-dark`,`only-light`]}],cursor:[{cursor:[`auto`,`default`,`pointer`,`wait`,`text`,`move`,`help`,`not-allowed`,`none`,`context-menu`,`progress`,`cell`,`crosshair`,`vertical-text`,`alias`,`copy`,`no-drop`,`grab`,`grabbing`,`all-scroll`,`col-resize`,`row-resize`,`n-resize`,`e-resize`,`s-resize`,`w-resize`,`ne-resize`,`nw-resize`,`se-resize`,`sw-resize`,`ew-resize`,`ns-resize`,`nesw-resize`,`nwse-resize`,`zoom-in`,`zoom-out`,Wm,zm]}],"field-sizing":[{"field-sizing":[`fixed`,`content`]}],"pointer-events":[{"pointer-events":[`auto`,`none`]}],resize:[{resize:[`none`,``,`y`,`x`]}],"scroll-behavior":[{scroll:[`auto`,`smooth`]}],"scroll-m":[{"scroll-m":w()}],"scroll-mx":[{"scroll-mx":w()}],"scroll-my":[{"scroll-my":w()}],"scroll-ms":[{"scroll-ms":w()}],"scroll-me":[{"scroll-me":w()}],"scroll-mbs":[{"scroll-mbs":w()}],"scroll-mbe":[{"scroll-mbe":w()}],"scroll-mt":[{"scroll-mt":w()}],"scroll-mr":[{"scroll-mr":w()}],"scroll-mb":[{"scroll-mb":w()}],"scroll-ml":[{"scroll-ml":w()}],"scroll-p":[{"scroll-p":w()}],"scroll-px":[{"scroll-px":w()}],"scroll-py":[{"scroll-py":w()}],"scroll-ps":[{"scroll-ps":w()}],"scroll-pe":[{"scroll-pe":w()}],"scroll-pbs":[{"scroll-pbs":w()}],"scroll-pbe":[{"scroll-pbe":w()}],"scroll-pt":[{"scroll-pt":w()}],"scroll-pr":[{"scroll-pr":w()}],"scroll-pb":[{"scroll-pb":w()}],"scroll-pl":[{"scroll-pl":w()}],"snap-align":[{snap:[`start`,`end`,`center`,`align-none`]}],"snap-stop":[{snap:[`normal`,`always`]}],"snap-type":[{snap:[`none`,`x`,`y`,`both`]}],"snap-strictness":[{snap:[`mandatory`,`proximity`]}],touch:[{touch:[`auto`,`none`,`manipulation`]}],"touch-x":[{"touch-pan":[`x`,`left`,`right`]}],"touch-y":[{"touch-pan":[`y`,`up`,`down`]}],"touch-pz":[`touch-pinch-zoom`],select:[{select:[`none`,`text`,`all`,`auto`]}],"will-change":[{"will-change":[`auto`,`scroll`,`contents`,`transform`,Wm,zm]}],fill:[{fill:[`none`,...N()]}],"stroke-w":[{stroke:[Om,Gm,Bm,Vm]}],stroke:[{stroke:[`none`,...N()]}],"forced-color-adjust":[{"forced-color-adjust":[`auto`,`none`]}]},conflictingClassGroups:{overflow:[`overflow-x`,`overflow-y`],overscroll:[`overscroll-x`,`overscroll-y`],inset:[`inset-x`,`inset-y`,`inset-bs`,`inset-be`,`start`,`end`,`top`,`right`,`bottom`,`left`],"inset-x":[`right`,`left`],"inset-y":[`top`,`bottom`],flex:[`basis`,`grow`,`shrink`],gap:[`gap-x`,`gap-y`],p:[`px`,`py`,`ps`,`pe`,`pbs`,`pbe`,`pt`,`pr`,`pb`,`pl`],px:[`pr`,`pl`],py:[`pt`,`pb`],m:[`mx`,`my`,`ms`,`me`,`mbs`,`mbe`,`mt`,`mr`,`mb`,`ml`],mx:[`mr`,`ml`],my:[`mt`,`mb`],size:[`w`,`h`],"font-size":[`leading`],"fvn-normal":[`fvn-ordinal`,`fvn-slashed-zero`,`fvn-figure`,`fvn-spacing`,`fvn-fraction`],"fvn-ordinal":[`fvn-normal`],"fvn-slashed-zero":[`fvn-normal`],"fvn-figure":[`fvn-normal`],"fvn-spacing":[`fvn-normal`],"fvn-fraction":[`fvn-normal`],"line-clamp":[`display`,`overflow`],rounded:[`rounded-s`,`rounded-e`,`rounded-t`,`rounded-r`,`rounded-b`,`rounded-l`,`rounded-ss`,`rounded-se`,`rounded-ee`,`rounded-es`,`rounded-tl`,`rounded-tr`,`rounded-br`,`rounded-bl`],"rounded-s":[`rounded-ss`,`rounded-es`],"rounded-e":[`rounded-se`,`rounded-ee`],"rounded-t":[`rounded-tl`,`rounded-tr`],"rounded-r":[`rounded-tr`,`rounded-br`],"rounded-b":[`rounded-br`,`rounded-bl`],"rounded-l":[`rounded-tl`,`rounded-bl`],"border-spacing":[`border-spacing-x`,`border-spacing-y`],"border-w":[`border-w-x`,`border-w-y`,`border-w-s`,`border-w-e`,`border-w-bs`,`border-w-be`,`border-w-t`,`border-w-r`,`border-w-b`,`border-w-l`],"border-w-x":[`border-w-r`,`border-w-l`],"border-w-y":[`border-w-t`,`border-w-b`],"border-color":[`border-color-x`,`border-color-y`,`border-color-s`,`border-color-e`,`border-color-bs`,`border-color-be`,`border-color-t`,`border-color-r`,`border-color-b`,`border-color-l`],"border-color-x":[`border-color-r`,`border-color-l`],"border-color-y":[`border-color-t`,`border-color-b`],translate:[`translate-x`,`translate-y`,`translate-none`],"translate-none":[`translate`,`translate-x`,`translate-y`,`translate-z`],"scroll-m":[`scroll-mx`,`scroll-my`,`scroll-ms`,`scroll-me`,`scroll-mbs`,`scroll-mbe`,`scroll-mt`,`scroll-mr`,`scroll-mb`,`scroll-ml`],"scroll-mx":[`scroll-mr`,`scroll-ml`],"scroll-my":[`scroll-mt`,`scroll-mb`],"scroll-p":[`scroll-px`,`scroll-py`,`scroll-ps`,`scroll-pe`,`scroll-pbs`,`scroll-pbe`,`scroll-pt`,`scroll-pr`,`scroll-pb`,`scroll-pl`],"scroll-px":[`scroll-pr`,`scroll-pl`],"scroll-py":[`scroll-pt`,`scroll-pb`],touch:[`touch-x`,`touch-y`,`touch-pz`],"touch-x":[`touch`],"touch-y":[`touch`],"touch-pz":[`touch`]},conflictingClassGroupModifiers:{"font-size":[`leading`]},orderSensitiveModifiers:[`*`,`**`,`after`,`backdrop`,`before`,`details-content`,`file`,`first-letter`,`first-line`,`marker`,`placeholder`,`selection`]}});function lh(...e){return ch(Gp(e))}function uh({delayDuration:e=0,...t}){return(0,L.jsx)(Lp,{"data-slot":`tooltip-provider`,delayDuration:e,...t})}function dh({...e}){return(0,L.jsx)(Rp,{"data-slot":`tooltip`,...e})}function fh({...e}){return(0,L.jsx)(zp,{"data-slot":`tooltip-trigger`,...e})}function ph({className:e,sideOffset:t=4,children:n,...r}){return(0,L.jsx)(Bp,{children:(0,L.jsxs)(Vp,{"data-slot":`tooltip-content`,sideOffset:t,className:lh(`z-50 overflow-hidden rounded-md bg-gray-900 px-3 py-1.5 text-xs text-gray-100 shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2`,e),...r,children:[n,(0,L.jsx)(Hp,{className:`fill-gray-900`})]})})}var R=(e,t)=>fetch(e,{credentials:`include`,...t}),mh=null;function hh(){return mh||=R(`/api/health`).then(e=>e.json()).then(e=>typeof e?.workspace==`string`?e.workspace:`loopat`).catch(()=>`loopat`),mh}async function gh(){let e=await R(`/api/auth/me`);return e.ok?(await e.json()).user??null:null}async function _h(e,t){let n=await R(`/api/auth/login`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({username:e,password:t})}),r=await n.json().catch(()=>({}));return n.ok?{user:r.user}:{error:r.error??`login failed (${n.status})`}}async function vh(e){let t=await R(`/api/auth/register`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(e)}),n=await t.json().catch(()=>({}));return t.ok?{user:n.user,publicKey:n.publicKey,personalRepo:n.personalRepo??null,needsImport:!!n.needsImport}:{error:n.error??`register failed (${t.status})`}}async function yh(e){let t=await R(`/api/personal/repos`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({token:e})}),n=await t.json().catch(()=>({}));return t.ok?{ok:n.ok!==!1,repos:Array.isArray(n.repos)?n.repos:[],login:n.login,error:n.error}:{ok:!1,repos:[],error:n?.error??`request failed`}}async function bh(){let e=await R(`/api/personal/status`);return e.ok?await e.json():null}async function xh(){let e=await R(`/api/onboarding`);return e.ok?await e.json():null}async function Sh(e){let t=await R(`/api/onboarding/submit`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({values:e})}),n=await t.json().catch(()=>({}));return t.ok?n:{error:n.error??`submit failed (${t.status})`}}async function Ch(){let e=await R(`/api/onboarding/device/start`,{method:`POST`}),t=await e.json().catch(()=>({}));return e.ok?t:{error:t.error??`device start failed (${e.status})`}}async function wh(e){return await(await R(`/api/onboarding/device/poll`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({device_code:e})})).json().catch(()=>({status:`error`,error:`poll failed`}))}async function Th(e){let t=await R(`/api/personal/crypt-key`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({password:e})}),n=await t.json().catch(()=>({}));return t.ok?typeof n.cryptKey==`string`?{ok:!0,cryptKey:n.cryptKey}:{ok:!1,error:`missing cryptKey in response`}:{ok:!1,error:n.error??`request failed (${t.status})`,wrongPassword:t.status===403}}async function Eh(e,t=!1){let n=await R(`/api/personal/delete`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({password:e,force:t})}),r=await n.json().catch(()=>({}));return n.ok?{ok:!0,synced:r.synced,dataLost:r.dataLost}:{ok:!1,error:r.error??`delete failed (${n.status})`,wrongPassword:n.status===403,syncFailed:r.syncFailed,uncommitted:r.uncommitted,unpushed:r.unpushed,hasRemote:r.hasRemote}}async function Dh(e){let t=await R(`/api/personal/pull`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({force:e?.force??!1})}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0,message:n.message}:{ok:!1,error:n.error??`pull failed (${t.status})`,conflict:n.conflict,files:n.files,needsStash:n.needsStash}}async function Oh(){let e=await R(`/api/personal/push`,{method:`POST`}),t=await e.json().catch(()=>({}));return e.ok?{ok:!0,message:t.message}:{ok:!1,error:t.error??`push failed (${e.status})`,conflict:t.conflict,files:t.files,needsPull:t.needsPull}}async function kh(e,t){let n={};e&&(n.repoUrl=e),t&&(n.cryptKey=t);let r=await R(`/api/personal/import`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(n)}),i=await r.json().catch(()=>({}));return r.ok?{ok:!0,autoInitialized:!!i.autoInitialized,cryptKey:typeof i.cryptKey==`string`?i.cryptKey:null}:{ok:!1,error:i.error??`import failed (${r.status})`,needsCryptKey:!!i.needsCryptKey,notClean:!!i.notClean,secretsExposed:!!i.secretsExposed,exposedFiles:Array.isArray(i.exposedFiles)?i.exposedFiles:[]}}async function Ah(e,t,n,r){let i={token:e};t&&(i.repoName=t),n&&(i.cryptKey=n),r&&(i.baseUrl=r);let a=await R(`/api/personal/github`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(i)}),o=await a.json().catch(()=>({}));return a.ok?{ok:!0,repo:typeof o.repo==`string`?o.repo:void 0,created:!!o.created,autoInitialized:!!o.autoInitialized,cryptKey:typeof o.cryptKey==`string`?o.cryptKey:null}:{ok:!1,error:o.error??`github setup failed (${a.status})`,needsCryptKey:!!o.needsCryptKey}}async function jh(){await R(`/api/auth/logout`,{method:`POST`}).catch(()=>{})}async function uee(e=`active`){let t=await R(`/api/loops`+(e===`all`?`?archived=all`:e===`archived`?`?archived=true`:``));return t.ok?(await t.json()).loops:[]}async function dee(e){if(e.knowledgeRw||e.mountAllLoops){let t={title:e.title,repo:e.repo,profiles:e.profiles,vault:e.vault};return e.knowledgeRw&&(t.knowledge_rw=!0),e.mountAllLoops&&(t.mount_all_loops=!0),await(await R(`/api/loops`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(t)})).json()}let t=await R(`/api/v1/loops`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({title:e.title,profiles:e.profiles,vault:e.vault,repo:e.repo})});if(!t.ok)throw Error(`createLoop failed (${t.status})`);let n=await t.json();return{id:n.id.startsWith(`loop_`)?n.id.slice(5):n.id,title:n.title,createdAt:n.created_at,createdBy:n.created_by,archived:n.archived,repo:n.repo??void 0,config:{profiles:n.profiles,vault:n.vault}}}async function Mh(){let e=await R(`/api/profiles`);return e.ok?(await e.json()).profiles??[]:[]}async function fee(){let e=await R(`/api/personal/default-profiles`);if(!e.ok)return[];let t=await e.json();return Array.isArray(t.default_profiles)?t.default_profiles:[]}async function pee(e){let t=await R(`/api/loop-stats?profiles=${encodeURIComponent(e.join(`,`))}`);return t.ok?await t.json():null}async function mee(){let e=await R(`/api/vaults`);if(!e.ok)return[];let t=await e.json();return Array.isArray(t.vaults)?t.vaults:[]}async function Nh(e){return(await R(`/api/loops/${e}/viewed`,{method:`POST`})).ok}async function hee(e,t){let n=await R(`/api/loops/${e}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify({archived:t})});return n.ok?await n.json():null}async function gee(e,t){let n=await R(`/api/loops/${e}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify({public:t})});return n.ok?await n.json():null}async function _ee(e,t){let n=await R(`/api/loops/${e}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify({title:t})});return n.ok?await n.json():null}async function vee(e){let t=await R(`/api/loops/${e}/request-drive`,{method:`POST`});return t.ok?await t.json():null}async function yee(e){let t=await R(`/api/loops/${e}/drive`,{method:`POST`});return t.ok?await t.json():null}async function bee(e){let t=await R(`/api/loops/${e}/distill`,{method:`POST`});return t.ok?await t.json():null}async function xee(e){let t=await R(`/api/loops/${e}`);return t.ok?await t.json():null}async function See(e){let t=await R(`/api/loops/${e}/strip-thinking`,{method:`POST`});return t.ok?await t.json():{stripped:0,sessionsTouched:0}}async function Ph(e,t=``){return(await(await R(`/api/loops/${e}/files?path=${encodeURIComponent(t)}`)).json()).entries??[]}async function Fh(e,t=``){return(await(await R(`/api/loops/${e}/files/tree?path=${encodeURIComponent(t)}`)).json()).entries??[]}async function Ih(e,t){let n=await R(`/api/loops/${e}/file?path=${encodeURIComponent(t)}`);return n.ok?await n.json():null}async function Lh(e,t,n){return(await R(`/api/loops/${e}/file?path=${encodeURIComponent(t)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({content:n})})).ok}async function Rh(e,t){return(await R(`/api/loops/${e}/file?path=${encodeURIComponent(t)}`,{method:`DELETE`})).ok}async function zh(e,t){return(await R(`/api/loops/${e}/folder`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({path:t})})).ok}async function Bh(e,t){let n=new FormData;n.append(`file`,t);let r=await R(`/api/loops/${e}/upload`,{method:`POST`,body:n}),i=await r.json().catch(()=>({}));return r.ok?{ok:!0,path:i.path}:{ok:!1,error:i.error??`upload failed`}}async function Vh(e){let t=await R(`/api/loops/${e}/context`);return t.ok?(await t.json()).mounts??[]:[]}async function Hh(e,t=``){let n=await R(`/api/workspace/files?vault=${e}&path=${encodeURIComponent(t)}`);return n.ok?(await n.json()).entries??[]:[]}async function Uh(e){let t=await R(`/api/workspace/files?vault=${e}&flat=1`);return t.ok?(await t.json()).entries??[]:[]}async function Wh(e,t){let n=await R(`/api/workspace/file?vault=${e}&path=${encodeURIComponent(t)}`);return n.ok?await n.json():null}async function Gh(e,t,n){return await(await R(`/api/workspace/file?vault=${e}&path=${encodeURIComponent(t)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({content:n})})).json()}async function Kh(){let e=await R(`/api/notes/save`,{method:`POST`}),t=await e.json().catch(()=>({}));return e.ok?{ok:!0,message:t.message}:{ok:!1,conflict:t.conflict,files:t.files,needsPull:t.needsPull,error:t.error??`save failed (${e.status})`}}async function qh(){let e=await(await R(`/api/notes/behind`)).json().catch(()=>({}));return typeof e.behind==`number`?e.behind:0}async function Jh(){let e=await(await R(`/api/notes/refresh`,{method:`POST`})).json().catch(()=>({}));return{ok:!!e.ok,diverged:e.diverged,error:e.error}}async function Yh(e,t){return await(await R(`/api/workspace/file?vault=${e}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({path:t})})).json()}async function Xh(e,t){return await(await R(`/api/workspace/folder?vault=${e}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({path:t})})).json()}async function Zh(e,t){return await(await R(`/api/workspace/file?vault=${e}&path=${encodeURIComponent(t)}`,{method:`DELETE`})).json()}async function Qh(e,t){let n=await R(`/api/workspace/backlinks?vault=${e}&path=${encodeURIComponent(t)}`);return n.ok?(await n.json()).backlinks??[]:[]}async function $h(){let e=await R(`/api/context/repos`);return e.ok?{repos:(await e.json()).repos??[]}:{repos:[]}}async function eg(e){let t=await R(`/api/context/repos`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(e)}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0}:{ok:!1,error:n.error??`http ${t.status}`}}async function tg(e){let t=await R(`/api/loops/${e}/chat-history`);return t.ok?(await t.json()).map(e=>e.text):[]}async function ng(e,t){await R(`/api/loops/${e}/chat-history`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:t})})}function rg(e){return typeof e==`string`?`/api/sync/${e}`:`/api/sync/repos/${encodeURIComponent(e.repo)}`}async function ig(e){let t=await R(`${rg(e)}/status`);return t.ok?await t.json():null}async function ag(e){let t=await R(`${rg(e)}/pull`,{method:`POST`}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0,message:n.message}:{ok:!1,error:n.error??`http ${t.status}`}}async function og(e){let t=await R(`${rg(e)}/push`,{method:`POST`}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0,message:n.message}:{ok:!1,error:n.error??`http ${t.status}`}}async function sg(e=`default`){let t=await R(`/api/kanban/${encodeURIComponent(e)}`);return t.ok?(await t.json()).columns:[]}async function cg(e,t,n){let r=await R(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/cards`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(n)}),i=await r.json().catch(()=>({}));return r.ok?{cid:i.cid}:{error:i.error??`add failed`}}async function lg(e,t,n){return(await R(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/cards/${encodeURIComponent(n)}/toggle`,{method:`PATCH`})).ok}async function ug(e,t,n,r){return(await R(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/cards/${encodeURIComponent(n)}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify(r)})).ok}async function dg(e,t,n,r){return(await R(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/cards/${encodeURIComponent(n)}/block`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({block:r})})).ok}async function fg(e,t,n){return(await R(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/cards/${encodeURIComponent(n)}`,{method:`DELETE`})).ok}async function pg(e,t,n,r,i){return(await R(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/cards/${encodeURIComponent(n)}/move`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({toFile:r,toIndex:i})})).ok}async function mg(e,t,n){return(await R(`/api/kanban/columns/${encodeURIComponent(e)}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({filename:t,title:n})})).ok}async function hg(){let e=await R(`/api/kanban/boards`);return e.ok?(await e.json()).boards:[`default`]}async function Cee(e){return(await R(`/api/kanban/boards`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:e})})).ok}async function wee(e,t){return(await R(`/api/kanban/boards/${encodeURIComponent(e)}/rename`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({name:t})})).ok}async function Tee(e=`default`){let t=await R(`/api/kanban/config/${encodeURIComponent(e)}`);return t.ok?(await t.json()).columns:[]}async function Eee(e,t){return(await R(`/api/kanban/config/${encodeURIComponent(e)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({columns:t})})).ok}async function Dee(e,t,n){return(await R(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/rename`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({toFile:n})})).ok}async function Oee(e,t){return(await R(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,{method:`DELETE`})).ok}async function kee(e,t,n){return(await R(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/color`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({color:n})})).ok}async function Aee(e,t,n){return(await R(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/reorder`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({cids:n})})).ok}async function jee(e,t,n){let r=await R(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/cards/${encodeURIComponent(n)}/assign-driver`,{method:`POST`});return r.ok?await r.json():{ok:!1}}async function Mee(e,t,n,r){return(await R(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/cards/${encodeURIComponent(n)}/link-loop`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({loopId:r})})).ok}async function Nee(){let e=await R(`/api/topics`);return e.ok?(await e.json()).topics:[]}async function gg(){let e=await R(`/api/providers`);return e.ok?await e.json():{providers:{},default:``}}async function _g(e,t,n,r,i){let a={baseUrl:e,model:n};t?a.apiKey=t:r&&i&&(a.provider=r,a.source=i);let o=await R(`/api/providers/test`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(a)}),s=await o.json().catch(()=>({}));return o.ok?s:{ok:!1,error:s.error??`test failed (${o.status})`}}async function vg(){let e=await R(`/api/version`);return e.ok?await e.json():{branch:`unknown`,commit:`unknown`}}async function yg(){let e=await R(`/api/admin/system`);return e.ok?await e.json():null}async function bg(){return await(await R(`/api/admin/system/check`,{method:`POST`})).json()}async function xg(){return await(await R(`/api/admin/system/pull`,{method:`POST`})).json()}function Sg(){return{commit:`7e50d9f3655c904b587f9a6b02400df343fe7ef0`,time:`2026-06-05T15:46:17.365Z`}}async function Cg(e){let t=await R(`/api/loops/${e}/git-status`);return t.ok?await t.json():{unstaged:[],staged:[]}}async function wg(e,t,n){let r=await R(`/api/loops/${e}/git-diff?path=${encodeURIComponent(t)}&staged=${n?`1`:`0`}`);return r.ok?(await r.json()).diff??null:null}async function Tg(e,t,n=!1){return(await R(`/api/loops/${e}/git-stage`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({files:t,unstage:n})})).ok}async function Eg(e,t){return(await R(`/api/loops/${e}/git-discard`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({file:t})})).ok}async function Dg(e,t){let n=await R(`/api/loops/${e}/git-commit`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({message:t})}),r=await n.json().catch(()=>({}));return n.ok?{ok:!0}:{ok:!1,error:r.error??`commit failed`}}async function Og(e,t=50){let n=await R(`/api/loops/${e}/git-log?limit=${t}`);return n.ok?(await n.json()).commits??[]:[]}async function kg(){let e=await R(`/api/settings/personal/disk`);return e.ok?await e.json():null}async function Ag(e){let t=await R(`/api/settings/personal/disk`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(e)}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0}:{ok:!1,error:n.error??`save failed (${t.status})`}}async function jg(e,t,n=`default`){let r=await R(`/api/settings/personal/value`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:e,value:t,vault:n})}),i=await r.json().catch(()=>({}));return r.ok?{ok:!0}:{ok:!1,error:i.error??`write failed (${r.status})`}}async function Mg(){return await(await R(`/api/settings/workspace`)).json()}async function Ng(e){return(await R(`/api/settings/workspace`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(e)})).ok}async function Pg(){let e=await R(`/api/settings/token-usage/daily`);return e.ok?await e.json():{}}async function Fg(){let e=await R(`/api/settings/token-usage/loops`);return e.ok?await e.json():[]}async function Ig(){let e=await R(`/api/admin/presets`);return e.ok?await e.json():{providerPresets:[],miseToolPresets:[]}}async function Lg(e){return(await R(`/api/admin/presets`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(e)})).ok}async function Rg(){let e=await R(`/api/admin/users`);return e.ok?(await e.json()).users??[]:[]}async function zg(e){let t=await R(`/api/admin/users/${encodeURIComponent(e)}/activate`,{method:`POST`}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0}:{ok:!1,error:n.error??`activate failed (${t.status})`}}async function Bg(e,t){let n=await R(`/api/admin/users/${encodeURIComponent(e)}/role`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({role:t})}),r=await n.json().catch(()=>({}));return n.ok?{ok:!0}:{ok:!1,error:r.error??`role change failed (${n.status})`}}async function Vg(e){let t=await R(`/api/admin/users/${encodeURIComponent(e)}`,{method:`DELETE`}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0}:{ok:!1,error:n.error??`delete failed (${t.status})`}}async function Hg(){let e=await R(`/api/serve/config`);return e.ok?await e.json():{serveEnabled:!0,domain:`nip.io`,ip:`127.0.0.1`,baseUrl:`.127.0.0.1.nip.io`,withPort:!1,https:!1,displayPort:7788,serveDynamicEnabled:!1,serveDynamicDomain:``,serveDynamicPortRange:`10000-20000`,serveDynamicUdpEnabled:!1,serveDynamicStaticEnabled:!1,serveEphemeralEnabled:!1,serveEphemeralDomain:``}}async function Ug(e){let t=await R(`/api/loops/${e}/share/current-port`);return t.ok?await t.json():{port:null}}async function Wg(e){return(await R(`/api/serve/config`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(e)})).ok}async function Gg(){let e=await R(`/api/serve/available-port`);return e.ok?await e.json():{port:null,error:`request failed`}}async function Kg(e,t){let n=await R(`/api/serve/check-port?port=${e}&loopId=${t||``}`);return n.ok?await n.json():{available:!1,reason:`request failed`}}async function qg(e,t){let n=new URLSearchParams({alias:e});t&&n.set(`loopId`,t);let r=await R(`/api/serve/alias-check?${n}`);return r.ok?await r.json():{available:!1,reason:`check failed`}}async function Jg(){let e=await R(`/api/chat/conversations`);return e.ok?(await e.json()).conversations??[]:[]}async function Yg(){let e=await R(`/api/chat/users`);return e.ok?(await e.json()).users??[]:[]}async function Xg(e,t){let n=await R(`/api/chat/channels`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:e,topic:t})}),r=await n.json().catch(()=>({}));return n.ok?{conv:r.conv}:{error:r.error??`create failed (${n.status})`}}async function Zg(e){let t=await R(`/api/chat/channels/${encodeURIComponent(e)}`,{method:`DELETE`}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0}:{ok:!1,error:n.error??`delete failed (${t.status})`}}async function Qg(e){let t=await R(`/api/chat/dm/${encodeURIComponent(e)}`,{method:`POST`}),n=await t.json().catch(()=>({}));return t.ok?{conv:n.conv}:{error:n.error??`open DM failed (${t.status})`}}async function $g(e,t={}){let n=new URLSearchParams;t.before&&n.set(`before`,String(t.before)),t.limit&&n.set(`limit`,String(t.limit));let r=await R(`/api/chat/conversations/${encodeURIComponent(e)}/messages?${n.toString()}`);return r.ok?(await r.json()).messages??[]:[]}async function e_(e){let t=await R(`/api/chat/threads/${e}`);return t.ok?await t.json():null}async function t_(e,t,n=null){let r=await R(`/api/chat/conversations/${encodeURIComponent(e)}/messages`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(n==null?{text:t}:{text:t,parentId:n})}),i=await r.json().catch(()=>({}));return r.ok?{message:i.message}:{error:i.error??`send failed (${r.status})`}}async function n_(e,t){return(await R(`/api/chat/conversations/${encodeURIComponent(e)}/read`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({lastReadId:t})})).ok}async function r_(e,t){let n=await R(`/api/chat/threads/${e}/spawn-loop`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(t?{title:t}:{})}),r=await n.json().catch(()=>({}));return n.ok?{loopId:r.loopId,seedPrompt:r.seedPrompt,messageCount:r.messageCount}:{error:r.error??`spawn failed (${n.status})`}}async function i_(e,t,n){let r=await R(`/api/mcp-setup/parse`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({server:e,pastedUrl:t,loopId:n})}),i=await r.json().catch(()=>({}));return r.ok?{ok:!0,set:i.set??[]}:{ok:!1,error:i.error??`failed (${r.status})`}}async function a_(){let e=await R(`/api/a2a`);return e.ok?await e.json():null}async function o_(e){return(await R(`/api/a2a`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(e)})).ok}async function s_(){let e=await R(`/api/a2a/key`,{method:`POST`});return e.ok?(await e.json().catch(()=>({}))).token??null:null}async function c_(e){let t=await R(`/api/mcp-servers${e?`?loopId=${encodeURIComponent(e)}`:``}`);return t.ok?await t.json():{servers:[]}}async function l_(e,t){let n=await R(`/api/mcp-auth/start`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({serverName:e,loopId:t})}),r=await n.json().catch(()=>({}));return n.ok?{authorizationUrl:r.authorizationUrl}:{error:r.error??`start failed`}}async function u_(e){return(await R(`/api/envs/${encodeURIComponent(e)}`,{method:`DELETE`})).ok}async function d_(e){let t=await R(`/api/loops/${encodeURIComponent(e)}/restart-session`,{method:`POST`}),n=await t.json().catch(()=>({}));return t.ok?{restarted:!!n.restarted}:{restarted:!1,error:n.error??`restart failed (${t.status})`}}async function f_(){let e=await R(`/api/tiers`);return e.ok?await e.json():null}async function p_(e,t){let n=await R(`/api/tiers/${encodeURIComponent(e)}/settings`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(t)}),r=await n.json().catch(()=>({}));return n.ok?{ok:!0}:{ok:!1,error:r.error??`save failed (${n.status})`}}async function m_(e){let t=await R(`/api/tiers/${encodeURIComponent(e)}/mise-config`);return t.ok?await t.json():{content:``,exists:!1,error:`fetch failed (${t.status})`}}async function h_(e,t){let n=await R(`/api/tiers/${encodeURIComponent(e)}/mise-config`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({content:t})}),r=await n.json().catch(()=>({}));return n.ok?{ok:!0}:{ok:!1,error:r.error??`save failed (${n.status})`}}async function g_(){let e=await R(`/api/plugins/available`);return e.ok?(await e.json()).plugins??[]:[]}async function __(){let e=await R(`/api/plugins/browse`);return e.ok?(await e.json()).plugins??[]:[]}async function v_(){let e=await R(`/api/marketplaces`);return e.ok?(await e.json()).marketplaces??[]:[]}async function y_(){let e=await R(`/api/plugins/refresh`,{method:`POST`}),t=await e.json().catch(()=>({}));return e.ok?{ok:!0,added:t.added}:{ok:!1,error:t.error??`refresh failed (${e.status})`}}async function b_(e){let t=await R(`/api/admin/profiles`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:e})}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0}:{ok:!1,error:n.error??`create failed (${t.status})`}}async function x_(e){let t=await R(`/api/admin/profiles/${encodeURIComponent(e)}`,{method:`DELETE`}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0}:{ok:!1,error:n.error??`delete failed (${t.status})`}}async function S_(){let e=await R(`/api/v1/me/tokens`);return e.ok?(await e.json().catch(()=>({tokens:[]}))).tokens??[]:[]}async function C_(e){let t=await R(`/api/v1/me/tokens`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({label:e})});return t.ok?await t.json().catch(()=>null):null}async function w_(e){return(await R(`/api/v1/me/tokens/${encodeURIComponent(e)}`,{method:`DELETE`})).ok}function T_(){let[e,t]=(0,F.useState)([]),[n,r]=(0,F.useState)(!0),[i,a]=(0,F.useState)(!1),[o,s]=(0,F.useState)(!1),[c,l]=(0,F.useState)(``),[u,d]=(0,F.useState)(null),[f,p]=(0,F.useState)(null),[m,h]=(0,F.useState)(!0),g=(0,F.useCallback)(async()=>{r(!0),t(await uee(i?`all`:`active`)),r(!1)},[i]);(0,F.useEffect)(()=>{let e=!1;return gh().then(t=>{e||(p(t),h(!1))}),()=>{e=!0}},[]),(0,F.useEffect)(()=>{g()},[i,f]);let _=(0,F.useCallback)(async e=>{let n=await dee(e);return t(e=>[n,...e]),n},[]),v=(0,F.useCallback)(async(e,n)=>{let r=await hee(e,n);r&&t(t=>!i&&r.archived?t.filter(t=>t.id!==e):t.map(t=>t.id===e?r:t))},[i]),y=(0,F.useCallback)(async(e,n)=>{let r=await gee(e,n);r&&t(t=>t.map(t=>t.id===e?r:t))},[]),b=(0,F.useCallback)(async(e,n)=>{let r=await _ee(e,n);return r?(t(t=>t.map(t=>t.id===e?r:t)),r):null},[]),x=(0,F.useCallback)(async e=>{let n=await vee(e);n&&t(t=>t.map(t=>t.id===e?n:t))},[]),S=(0,F.useCallback)(async e=>{let n=await yee(e);n&&t(t=>t.map(t=>t.id===e?n:t))},[]),C=(0,F.useCallback)(async(e,t)=>{let n=await _h(e,t);return n.user&&p(n.user),{error:n.error}},[]),w=(0,F.useCallback)(async e=>{let t=await vh(e);return t.user&&t.user.status===`active`&&p(t.user),{error:t.error,user:t.user,publicKey:t.publicKey,personalRepo:t.personalRepo,needsImport:t.needsImport}},[]),T=(0,F.useCallback)(async()=>{await jh(),p(null)},[]);return{loops:e,loopsLoading:n,showArchived:i,setShowArchived:a,refresh:g,createLoop:_,setLoopArchived:v,setLoopPublic:y,setLoopTitle:b,requestDrive:x,takeDrive:S,newLoopDialogOpen:o,newLoopDialogTitle:c,kanbanCreateCtx:u,setNewLoopDialogOpen:(0,F.useCallback)((e,t,n)=>{s(e),l(t??``),d(n??null)},[]),currentUser:f,authLoading:m,login:C,register:w,logout:T}}var E_=(0,F.createContext)(null);function D_(){let e=(0,F.useContext)(E_);if(!e)throw Error(`useWorkspace outside provider`);return e}function O_({onClose:e,onCreate:t,initialTitle:n}){let[r,i]=(0,F.useState)(n??``),[a,o]=(0,F.useState)(``),[s,c]=(0,F.useState)(new Set),[l,u]=(0,F.useState)([]),[d,f]=(0,F.useState)(`default`),[p,m]=(0,F.useState)([]),[h,g]=(0,F.useState)([]),[_,v]=(0,F.useState)([]),[y,b]=(0,F.useState)(null),[x,S]=(0,F.useState)(!1),[C,w]=(0,F.useState)(!1),T=(0,F.useRef)(null);(0,F.useEffect)(()=>{$h().then(e=>m(e.repos)),Promise.all([Mh(),fee()]).then(([e,t])=>{g(e),u(t);let n=new Set(e.map(e=>e.name));c(new Set(t.filter(e=>n.has(e)&&e!==`base`)))}),mee().then(e=>{v(e),e.includes(`default`)?f(`default`):e.length>0&&f(e[0])}),T.current?.focus()},[]);function E(){let e=new Set(h.map(e=>e.name));c(new Set(l.filter(t=>e.has(t)&&t!==`base`)))}(0,F.useEffect)(()=>{S(!0);let e=setTimeout(()=>{pee([...s]).then(b).finally(()=>S(!1))},120);return()=>clearTimeout(e)},[s]);let D=(()=>{let e=new Set(l.filter(e=>e!==`base`));if(e.size!==s.size)return!0;for(let t of e)if(!s.has(t))return!0;return!1})(),O=h.find(e=>e.name===`base`),k=h.filter(e=>e.name!==`base`);function A(e){c(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}return(0,L.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/30 flex items-end sm:items-center justify-center`,onClick:e,children:(0,L.jsxs)(`div`,{className:`w-full sm:max-w-[480px] sm:mx-4 bg-white rounded-t-xl sm:rounded-md shadow-xl border border-gray-200 flex flex-col h-dvh sm:h-auto sm:max-h-[85vh]`,onClick:e=>e.stopPropagation(),children:[(0,L.jsxs)(`div`,{className:`shrink-0 px-4 sm:px-5 pt-4 sm:pt-5 pb-3 border-b border-gray-100 flex items-center justify-between`,children:[(0,L.jsx)(`div`,{className:`text-base font-semibold text-gray-900`,children:`New loop`}),(0,L.jsx)(`button`,{type:`button`,onClick:e,className:`sm:hidden w-8 h-8 flex items-center justify-center rounded-full text-gray-400 hover:text-gray-600 hover:bg-gray-100 -mr-1`,"aria-label":`close`,children:(0,L.jsx)(`svg`,{width:`18`,height:`18`,viewBox:`0 0 18 18`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,children:(0,L.jsx)(`path`,{d:`M4 4l10 10M14 4L4 14`})})})]}),(0,L.jsxs)(`form`,{id:`new-loop-form`,onSubmit:async e=>{if(e.preventDefault(),!C){w(!0);try{await t({title:r.trim()||`untitled`,repo:a||void 0,profiles:s.size>0?[...s]:void 0,vault:d||void 0})}finally{w(!1)}}},className:`flex-1 min-h-0 overflow-y-auto px-4 sm:px-5 py-4 flex flex-col gap-4`,children:[(0,L.jsx)(k_,{label:`Name`,hint:`Optional — defaults to 'untitled'.`,children:(0,L.jsx)(`input`,{ref:T,type:`text`,value:r,onChange:e=>i(e.target.value),placeholder:`refactor-gateway`,className:`w-full px-3 py-2.5 sm:py-1.5 text-base sm:text-sm border border-gray-300 rounded outline-none focus:border-gray-500`})}),(0,L.jsxs)(k_,{label:`Repo`,hint:`Sets the workdir. Optional — leave (none) for an empty workdir.`,children:[(0,L.jsxs)(`select`,{value:a,onChange:e=>o(e.target.value),className:`w-full px-3 py-2.5 sm:py-1.5 text-base sm:text-sm border border-gray-300 rounded outline-none focus:border-gray-500 bg-white`,children:[(0,L.jsx)(`option`,{value:``,children:`(none — empty workdir)`}),p.map(e=>(0,L.jsxs)(`option`,{value:e.name,children:[e.name,e.git?` · ${e.git}`:``]},e.name))]}),p.length===0&&(0,L.jsx)(`div`,{className:`text-[11px] text-gray-400 mt-1`,children:`No repos in the roster. Add them on the Context → Repos page.`})]}),(0,L.jsxs)(k_,{label:`Profiles`,hint:`Each profile contributes plugins + a CLAUDE.md fragment. Empty = base + personal only.`,children:[(0,L.jsxs)(`div`,{className:`border border-gray-300 rounded p-2 max-h-44 overflow-y-auto bg-white flex flex-col gap-1`,children:[O&&(0,L.jsxs)(`label`,{className:`flex items-start gap-2 px-1.5 py-1 rounded text-sm text-gray-500 cursor-not-allowed bg-gray-50`,children:[(0,L.jsx)(`input`,{type:`checkbox`,checked:!0,disabled:!0,className:`mt-0.5`}),(0,L.jsxs)(`span`,{className:`flex-1`,children:[(0,L.jsx)(`span`,{className:`font-medium`,children:`base`}),(0,L.jsx)(`span`,{className:`ml-1 text-[11px] text-gray-400`,children:`(always on)`}),O.description&&(0,L.jsx)(`span`,{className:`block text-[11px] text-gray-400 mt-0.5`,children:O.description})]})]}),k.map(e=>{let t=s.has(e.name),n=l.includes(e.name);return(0,L.jsxs)(`label`,{className:`flex items-start gap-2 px-1.5 py-1 rounded text-sm cursor-pointer hover:bg-gray-50 ${t?`bg-blue-50`:``}`,children:[(0,L.jsx)(`input`,{type:`checkbox`,checked:t,onChange:()=>A(e.name),className:`mt-0.5`}),(0,L.jsxs)(`span`,{className:`flex-1`,children:[(0,L.jsx)(`span`,{className:`font-medium text-gray-900`,children:e.name}),n&&(0,L.jsx)(`span`,{className:`ml-1.5 px-1 py-px text-[10px] rounded bg-gray-200 text-gray-600`,title:`In your default_profiles (personal config)`,children:`default`}),e.description&&(0,L.jsx)(`span`,{className:`block text-[11px] text-gray-500 mt-0.5`,children:e.description})]})]},e.name)}),k.length===0&&!O&&(0,L.jsxs)(`div`,{className:`text-[11px] text-gray-400 p-1.5`,children:[`No profiles yet. Add them under`,` `,(0,L.jsx)(`code`,{className:`bg-gray-100 px-1 rounded`,children:`knowledge/.loopat/profiles/<name>/.claude/`}),` `,`in your knowledge repo.`]})]}),(0,L.jsxs)(`div`,{className:`flex items-center justify-between mt-1`,children:[(0,L.jsx)(`span`,{className:`text-[11px] text-gray-500`,children:s.size>0?`Selected: ${[...s].join(`, `)}`:`No profiles selected (base + personal only)`}),D&&l.length>0&&(0,L.jsx)(`button`,{type:`button`,onClick:E,className:`text-[11px] text-gray-500 hover:text-gray-900 underline`,title:`Restore default_profiles from your personal config`,children:`reset to defaults`})]}),(0,L.jsx)(`div`,{className:`mt-1.5 px-1.5 py-1 text-[11px] text-gray-600 bg-gray-50 border border-gray-200 rounded`,children:x&&!y?(0,L.jsx)(`span`,{className:`text-gray-400`,children:`computing…`}):y?(0,L.jsxs)(`span`,{title:`Totals across team + selected profiles + their plugins (deduped by name)`,children:[(0,L.jsxs)(`span`,{className:y.plugins>0?``:`text-gray-400`,children:[y.plugins,` plugins`]}),(0,L.jsx)(`span`,{className:`mx-1 text-gray-300`,children:`·`}),(0,L.jsxs)(`span`,{className:y.skills>0?``:`text-gray-400`,children:[y.skills,` skills`]}),(0,L.jsx)(`span`,{className:`mx-1 text-gray-300`,children:`·`}),(0,L.jsxs)(`span`,{className:y.agents>0?``:`text-gray-400`,children:[y.agents,` agents`]}),(0,L.jsx)(`span`,{className:`mx-1 text-gray-300`,children:`·`}),(0,L.jsxs)(`span`,{className:y.hooks>0?``:`text-gray-400`,children:[y.hooks,` hooks`]}),(0,L.jsx)(`span`,{className:`mx-1 text-gray-300`,children:`·`}),(0,L.jsxs)(`span`,{className:y.mcpServers>0?``:`text-gray-400`,children:[y.mcpServers,` MCP servers`]}),(0,L.jsx)(`span`,{className:`mx-1 text-gray-300`,children:`·`}),(0,L.jsxs)(`span`,{className:y.toolchain>0?``:`text-gray-400`,title:`mise.toml [tools] entries, deduped across team + selected profiles`,children:[y.toolchain,` toolchain`]}),x&&(0,L.jsx)(`span`,{className:`ml-1.5 text-gray-400`,children:`·`}),x&&(0,L.jsx)(`span`,{className:`ml-1 text-gray-400`,children:`updating…`})]}):(0,L.jsx)(`span`,{className:`text-gray-400`,children:`—`})})]}),(0,L.jsxs)(k_,{label:`Vault`,hint:`Which credential set to inject. Only this vault is visible inside the loop.`,children:[(0,L.jsxs)(`select`,{value:d,onChange:e=>f(e.target.value),className:`w-full px-3 py-2.5 sm:py-1.5 text-base sm:text-sm border border-gray-300 rounded outline-none focus:border-gray-500 bg-white`,children:[_.length===0&&(0,L.jsx)(`option`,{value:`default`,children:`default`}),_.map(e=>(0,L.jsx)(`option`,{value:e,children:e},e))]}),_.length===0&&(0,L.jsxs)(`div`,{className:`text-[11px] text-gray-400 mt-1`,children:[`No vaults yet — using default. Create more under`,` `,(0,L.jsx)(`code`,{className:`bg-gray-100 px-1 rounded`,children:`personal/.loopat/vaults/<name>/`}),` `,`to isolate prod / test credentials.`]})]})]}),(0,L.jsxs)(`div`,{className:`shrink-0 px-4 sm:px-5 py-3 border-t border-gray-100 flex justify-end gap-3`,children:[(0,L.jsx)(`button`,{type:`button`,onClick:e,className:`px-4 h-11 sm:h-8 text-sm rounded text-gray-700 hover:bg-gray-100 active:bg-gray-200`,children:`cancel`}),(0,L.jsx)(`button`,{type:`submit`,form:`new-loop-form`,disabled:C,className:`px-6 h-11 sm:h-8 text-sm rounded bg-gray-900 text-white hover:bg-gray-700 active:bg-gray-800 disabled:opacity-50 font-medium`,children:C?`creating…`:`create`})]})]})})}function k_({label:e,hint:t,children:n}){return(0,L.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,L.jsx)(`span`,{className:`text-xs text-gray-700 font-medium`,children:e}),n,t&&(0,L.jsx)(`span`,{className:`text-[11px] text-gray-400`,children:t})]})}var A_=e=>typeof e==`boolean`?`${e}`:e===0?`0`:e,j_=Gp,M_=((e,t)=>n=>{if(t?.variants==null)return j_(e,n?.class,n?.className);let{variants:r,defaultVariants:i}=t,a=Object.keys(r).map(e=>{let t=n?.[e],a=i?.[e];if(t===null)return null;let o=A_(t)||A_(a);return r[e][o]}),o=n&&Object.entries(n).reduce((e,t)=>{let[n,r]=t;return r===void 0||(e[n]=r),e},{});return j_(e,a,t?.compoundVariants?.reduce((e,t)=>{let{class:n,className:r,...a}=t;return Object.entries(a).every(e=>{let[t,n]=e;return Array.isArray(n)?n.includes({...i,...o}[t]):{...i,...o}[t]===n})?[...e,n,r]:e},[]),n?.class,n?.className)})(`inline-flex shrink-0 items-center justify-center gap-2 rounded-md text-sm font-medium whitespace-nowrap transition-all outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,{variants:{variant:{default:`bg-primary text-primary-foreground hover:bg-primary/90`,destructive:`bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:bg-destructive/60 dark:focus-visible:ring-destructive/40`,outline:`border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50`,secondary:`bg-secondary text-secondary-foreground hover:bg-secondary/80`,ghost:`hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50`,link:`text-primary underline-offset-4 hover:underline`},size:{default:`h-9 px-4 py-2 has-[>svg]:px-3`,xs:`h-6 gap-1 rounded-md px-2 text-xs has-[>svg]:px-1.5 [&_svg:not([class*='size-'])]:size-3`,sm:`h-8 gap-1.5 rounded-md px-3 has-[>svg]:px-2.5`,lg:`h-10 rounded-md px-6 has-[>svg]:px-4`,icon:`size-9`,"icon-xs":`size-6 rounded-md [&_svg:not([class*='size-'])]:size-3`,"icon-sm":`size-8`,"icon-lg":`size-10`}},defaultVariants:{variant:`default`,size:`default`}});function N_({className:e,variant:t=`default`,size:n=`default`,asChild:r=!1,...i}){return(0,L.jsx)(r?uo:`button`,{"data-slot":`button`,"data-variant":t,"data-size":n,className:lh(M_({variant:t,size:n,className:e})),...i})}function P_({...e}){return(0,L.jsx)(Fl,{"data-slot":`dialog`,...e})}function F_({...e}){return(0,L.jsx)(Il,{"data-slot":`dialog-portal`,...e})}function I_({className:e,...t}){return(0,L.jsx)(Ll,{"data-slot":`dialog-overlay`,className:lh(`fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0`,e),...t})}function L_({className:e,children:t,showCloseButton:n=!0,...r}){return(0,L.jsxs)(F_,{"data-slot":`dialog-portal`,children:[(0,L.jsx)(I_,{}),(0,L.jsxs)(Rl,{"data-slot":`dialog-content`,className:lh(`fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border bg-white p-6 shadow-lg duration-200 outline-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 sm:max-w-lg`,e),...r,children:[t,n&&(0,L.jsxs)(Vl,{"data-slot":`dialog-close`,className:`absolute top-4 right-4 rounded-xs opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,children:[(0,L.jsx)(Jn,{}),(0,L.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]})}function R_({className:e,...t}){return(0,L.jsx)(`div`,{"data-slot":`dialog-header`,className:lh(`flex flex-col gap-2 text-center sm:text-left`,e),...t})}function z_({className:e,...t}){return(0,L.jsx)(zl,{"data-slot":`dialog-title`,className:lh(`text-lg leading-none font-semibold`,e),...t})}function Pee({className:e,...t}){return(0,L.jsx)(Bl,{"data-slot":`dialog-description`,className:lh(`text-sm text-muted-foreground`,e),...t})}function Fee({open:e,onClose:t}){let[n,r]=(0,F.useState)({branch:`…`,commit:`…`}),i=Sg();return(0,F.useEffect)(()=>{e&&vg().then(e=>r(e))},[e]),(0,L.jsx)(P_,{open:e,onOpenChange:e=>!e&&t(),children:(0,L.jsxs)(L_,{className:`sm:max-w-sm bg-white`,children:[(0,L.jsx)(R_,{children:(0,L.jsxs)(z_,{className:`text-center`,children:[(0,L.jsx)(`img`,{src:`/logo.png`,alt:`loopat`,className:`w-full max-w-[240px] mx-auto mb-2`}),`loopat`]})}),(0,L.jsxs)(`div`,{className:`space-y-3 text-sm`,children:[(0,L.jsxs)(`div`,{className:`bg-gray-50 rounded-lg p-3`,children:[(0,L.jsx)(`div`,{className:`text-gray-400 text-xs mb-1`,children:`Server`}),(0,L.jsxs)(`div`,{className:`font-mono text-gray-700`,children:[n.branch,`@`,n.commit.slice(0,7)]})]}),(0,L.jsxs)(`div`,{className:`bg-gray-50 rounded-lg p-3`,children:[(0,L.jsx)(`div`,{className:`text-gray-400 text-xs mb-1`,children:`Build`}),(0,L.jsx)(`div`,{className:`font-mono text-gray-700`,children:i.commit.slice(0,7)}),(0,L.jsx)(`div`,{className:`font-mono text-gray-400 text-xs mt-0.5`,children:new Date(i.time).toLocaleString()})]})]})]})})}function B_(e){let t=[];for(let n of e.effectTasks)try{n()}catch(e){t.push(e)}if(t.length>0){if(t.length===1)throw t[0];for(let e of t)console.error(e);throw AggregateError(t,`Errors during commit`)}}function V_(e){let t=[];for(let n of e.cells)if(n?.type===`effect`&&(n.deps=null,n.cleanup))try{n.cleanup?.()}catch(e){t.push(e)}finally{n.cleanup=void 0}if(t.length>0){if(t.length===1)throw t[0];for(let e of t)console.error(e);throw AggregateError(t,`Errors during cleanup`)}}var H_=typeof process<`u`&&!1,U_=null;function Iee(e,t){e.currentIndex=0;let n=U_;U_=e;try{if(t(),e.isFirstRender=!1,e.cells.length!==e.currentIndex)throw Error(`Rendered ${e.currentIndex} hooks but expected ${e.cells.length}. Hooks must be called in the exact same order in every render.`)}finally{U_=n}}function W_(){if(!U_)throw Error(`No resource fiber available`);return U_}function Lee(e){return H_?U_?.devStrictMode?U_.isFirstRender?`child`:`root`:e?`root`:null:null}function Ree(e,t){let n=e[G_];if(!n)throw Error(`ResourceElement.type is not a valid Resource`);return n(t)}var G_=Symbol(`fnSymbol`);function K_(e,t,n=void 0,r=Lee(!1)){return{type:e,root:t,markDirty:n,devStrictMode:r,cells:[],currentIndex:0,renderContext:void 0,isFirstRender:!0,isMounted:!1,isNeverMounted:!0}}function q_(e){if(!e.isMounted)throw Error(`Tried to unmount a fiber that is already unmounted`);e.isMounted=!1,V_(e)}function J_(e,t){let n={effectTasks:[],props:t,output:void 0};return Iee(e,()=>{e.renderContext=n;try{n.output=Ree(e.type,t)}finally{e.renderContext=void 0}}),n}function Y_(e,t){e.isMounted=!0,H_&&e.isNeverMounted&&e.devStrictMode===`root`&&(e.isNeverMounted=!1,B_(t),V_(e)),e.isNeverMounted=!1,B_(t)}var X_=e=>({version:0,committedVersion:0,dispatchUpdate:e,changelog:[],dirtyCells:[]}),Z_=e=>{for(let t of e.dirtyCells)t.dirty=!1,t.queue.clear(),t.current=t.workInProgress;e.committedVersion=e.version,e.changelog.length=0,e.dirtyCells.length=0},Q_=(e,t)=>{let n=e.version>t;if(e.version=t,n){for(let t of e.dirtyCells)t.dirty=!1,t.queue.clear(),t.workInProgress=t.current;if(e.dirtyCells.length=0,t===e.committedVersion)e.changelog.length=0;else{if(e.committedVersion>t)throw Error(`Version is less than committed version`);for(;e.committedVersion+e.changelog.length>t;)e.changelog.pop();e.changelog.forEach(e=>e()),Z_(e)}}},$_=(e,t)=>{t.dirty||(t.dirty=!0,e.markDirty?.(),e.root.dirtyCells.push(t))},zee=()=>{if(!H_)return null;let e=(0,F.useRef)(0),t=e.current===0;return(0,F.useState)(()=>e.current++),e.current===2?t?`child`:`root`:null};function ev(e){let t=(0,F.useMemo)(()=>X_(e=>r(e)),[]),[n,r]=(0,F.useReducer)((e,n)=>(Q_(t,e),e+ +!!n()),0);Q_(t,n);let i=zee(),a=(0,F.useMemo)(()=>(e.key,K_(e.type,t,void 0,i)),[e.type,e.key,t,i]),o=J_(a,e.props);return(0,F.useLayoutEffect)(()=>()=>q_(a),[a]),(0,F.useLayoutEffect)(()=>{Z_(t),Y_(a,o)}),o.output}function tv(e){let t=e=>({type:t,props:e});return t[G_]=e,t}function nv(e,t){return{...t,key:e}}var rv=(e,t)=>{let n=W_(),r=n.currentIndex++;if(!n.isFirstRender&&r>=n.cells.length)throw Error(`Rendered more hooks than during the previous render. Hooks must be called in the exact same order in every render.`);let i=n.cells[r];if(i||(i=t(),n.cells[r]=i),i.type!==e)throw Error(`Hook order changed between renders`);return i},iv=e=>{W_().renderContext.effectTasks.push(e)},av=(e,t)=>{if(e.renderContext)throw Error(`Resource updated during render`);if(e.isNeverMounted)throw Error(`Resource updated before mount`);e.root.dispatchUpdate(()=>{let n=t();return n?(n(),e.root.changelog.push(n),!0):!1})};function ov(e,t,n,r){let i=rv(`reducer`,()=>{let t=W_(),a=r?r(n):n;return H_&&t.devStrictMode&&r&&r(n),{type:`reducer`,queue:new Set,dirty:!1,workInProgress:a,current:a,reducer:e,dispatch:n=>{let r={action:n,hasEagerState:!1,eagerState:void 0};av(t,()=>t.root.dirtyCells.length===0&&!r.hasEagerState&&(r.eagerState=e(i.workInProgress,n),r.hasEagerState=!0,Object.is(i.current,r.eagerState))?null:()=>{$_(t,i),i.queue.add(r)})}}}),a=W_(),o=e===i.reducer;i.reducer=e;for(let t of i.queue)(!t.hasEagerState||!o)&&(t.eagerState=e(i.workInProgress,t.action),t.hasEagerState=!0),H_&&a.devStrictMode&&e(i.workInProgress,t.action),i.workInProgress=t.eagerState;if(i.queue.clear(),t){let e=t(i.workInProgress);Object.is(e,i.workInProgress)||($_(a,i),i.workInProgress=e)}return[i.workInProgress,i.dispatch]}function sv(e,t,n){return ov(e,void 0,t,n)}function cv(e,t,n,r){return ov(e,t,n,r)}var lv=(e,t)=>typeof t==`function`?t(e):t,uv=e=>typeof e==`function`?e():e;function dv(e){return sv(lv,e,uv)}var fv=(e,t)=>{if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!Object.is(e[n],t[n]))return!1;return!0},pv=()=>({type:`effect`,cleanup:void 0,deps:null});function mv(e,t){let n=rv(`effect`,pv);if(!(t&&n.deps&&fv(n.deps,t))){if(n.deps!==null&&!!t!=!!n.deps)throw Error(`tapEffect called with and without dependencies across re-renders`);iv(()=>{let r=[];try{n.cleanup?.()}catch(e){r.push(e)}finally{n.cleanup=void 0}try{let t=e();if(t!==void 0&&typeof t!=`function`)throw Error(`An effect function must either return a cleanup function or nothing. Received: ${typeof t}`);n.cleanup=t}catch(e){r.push(e)}if(n.deps=t,r.length>0){if(r.length===1)throw r[0];for(let e of r)console.error(e);throw AggregateError(r,`Errors during commit`)}})}}function hv(e){let[t]=dv(()=>({current:e}));return t}function gv(e,t){let[n]=dv(e);return n}var _v=()=>{throw Error(`Memo reducer should not be called`)},vv=(e,t)=>{let n=W_(),[r]=cv(_v,r=>{if(r&&fv(r.deps,t))return r;let i=e();return H_&&n.devStrictMode&&e(),{value:i,deps:t}},null);return r.value},yv=(e,t)=>vv(()=>e,t);function bv(e){let t=hv(e);mv(()=>{t.current=e});let n=W_();return yv(((...e)=>{if(H_&&n.renderContext)throw Error(`tapEffectEvent cannot be called during render`);return t.current(...e)}),[n])}function xv(e,t){let n=W_(),r=hv(0),i=vv(()=>(e.key,K_(e.type,n.root,()=>{r.current++,n.markDirty?.()})),[e.type,e.key,n]),a=t?vv(()=>J_(i,e.props),[i,...t,r.current]):J_(i,e.props);return mv(()=>()=>q_(i),[i]),mv(()=>{Y_(i,a)},[i,a]),a.output}function Sv(e,t){let n=hv(0),r=n.current,i=gv(W_,[]),a=gv(()=>()=>{n.current++,i.markDirty?.()},[]),o=gv(()=>new Map,[]),s=t?yv(e,t):e,c=vv(()=>{let e=s(),t=new Set,n=[],r=0;for(let s=0;s<e.length;s++){let c=e[s],l=c.key;if(l===void 0)throw Error(`tapResources did not provide a key for array at index ${s}`);if(t.has(l))throw Error(`Duplicate key ${l} in tapResources`);t.add(l);let u=o.get(l);if(!u){let e=K_(c.type,i.root,a),t=J_(e,c.props);u={fiber:e,next:t},r++,o.set(l,u),n.push(t.output)}else if(u.fiber.type!==c.type){let e=K_(c.type,i.root,a),t=J_(e,c.props);u.next=[e,t],n.push(t.output)}else u.next=J_(u.fiber,c.props),n.push(u.next.output)}if(o.size>n.length-r)for(let e of o.keys())t.has(e)||(o.get(e).next=`delete`);return n},[s,r]);return mv(()=>()=>{for(let e of o.keys()){let t=o.get(e).fiber;q_(t)}},[]),mv(()=>{for(let[e,t]of o.entries())t.next===`delete`?(t.fiber.isMounted&&q_(t.fiber),o.delete(e)):Array.isArray(t.next)?(q_(t.fiber),t.fiber=t.next[0],Y_(t.fiber,t.next[1])):Y_(t.fiber,t.next)},[c]),c}var Cv=50,wv={schedulers:new Set([]),isScheduled:!1},Tv=class{_task;_isDirty=!1;constructor(e){this._task=e}get isDirty(){return this._isDirty}markDirty(){this._isDirty=!0,wv.schedulers.add(this),Ev()}runTask(){this._isDirty=!1,this._task()}},Ev=()=>{wv.isScheduled||(wv.isScheduled=!0,Ov())},Dv=()=>{try{let e=[],t=0;for(let n of wv.schedulers)if(wv.schedulers.delete(n),n.isDirty){if(t++,t>Cv)throw Error(`Maximum update depth exceeded. This can happen when a resource repeatedly calls setState inside tapEffect.`);try{n.runTask()}catch(t){e.push(t)}}if(e.length>0){if(e.length===1)throw e[0];for(let t of e)console.error(t);throw AggregateError(e,`Errors occurred during flushSync`)}}finally{wv.schedulers.clear(),wv.isScheduled=!1}},Ov=(()=>{if(typeof MessageChannel<`u`){let e=new MessageChannel;return e.port1.onmessage=Dv,()=>e.port2.postMessage(null)}return()=>setTimeout(Dv,0)})(),kv=e=>{let t=wv;wv={schedulers:new Set([]),isScheduled:!0};try{let t=e();return Dv(),t}finally{wv=t}},Av=e=>{let t=gv(()=>new Tv(()=>l(null)),[]),n=gv(()=>[],[]),r=vv(()=>(e.key,K_(e.type,X_(e=>{!t.isDirty&&!e()||(n.push(e),t.markDirty())}))),[e.type,e.key]);Q_(r.root,r.root.committedVersion);let i=J_(r,e.props),a=hv(!1),o=hv(e.props),s=hv(i.output),c=gv(()=>new Set,[]),l=bv(e=>{if(e===null&&(Q_(r.root,2),Q_(r.root,1),n.forEach(e=>{H_&&r.devStrictMode&&e(),e()}),H_&&r.devStrictMode&&J_(r,o.current),e=J_(r,o.current)),t.isDirty)throw Error(`Scheduler is dirty, this should never happen`);Z_(r.root),n.length=0,a.current&&Y_(r,e),!(t.isDirty||s.current===e.output)&&(s.current=e.output,c.forEach(e=>e()))});return mv(()=>(a.current=!0,()=>{a.current=!1,q_(r)}),[r]),mv(()=>{o.current=i.props,Z_(r.root),Y_(r,i),!(t.isDirty||s.current===i.output)&&(s.current=i.output,c.forEach(e=>e()))}),vv(()=>({getValue:()=>s.current,subscribe:e=>(c.add(e),()=>c.delete(e))}),[])},jv=Symbol(`tap.Context`),Mv=e=>({[jv]:e}),Nv=(e,t,n)=>{let r=e[jv];e[jv]=t;try{return n()}finally{e[jv]=r}},Pv=e=>e[jv],Fv=Symbol(`assistant-ui.store.clientIndex`),Iv=e=>e[Fv],Lv=Mv([]),Rv=()=>Pv(Lv),zv=(e,t)=>{let n=Rv();return Nv(Lv,vv(()=>[...n,e],[n,e]),t)},Bv=new Set([`$$typeof`,`nodeType`,`then`]),Vv=(e,t)=>{if(e===Symbol.toStringTag)return t;if(typeof e!=`symbol`){if(e===`toJSON`)return()=>t;if(!Bv.has(e))return!1}},Hv=class{getOwnPropertyDescriptor(e,t){let n=this.get(e,t);if(n!==void 0)return{value:n,writable:!1,enumerable:!0,configurable:!1}}set(){return!1}setPrototypeOf(){return!1}defineProperty(){return!1}deleteProperty(){return!1}preventExtensions(){return!1}},Uv=e=>{let t=tv(e);return e=>{let n=t(e);return e.key===void 0?n:nv(e.key,n)}},Wv=Symbol(`assistant-ui.store.getValue`),Gv=e=>{let t=e[Wv];if(!t)throw Error(`Client scope contains a non-client resource. Ensure your Derived get() returns a client created with tapClientResource(), not a plain resource.`);return t.getState?.()},Kv=new Map;function qv(e){let t=Kv.get(e);return t||(t=function(...t){if(!this||typeof this!=`object`)throw Error(`Method "${String(e)}" called without proper context. This may indicate the function was called incorrectly.`);let n=this[Wv];if(!n)throw Error(`Method "${String(e)}" called on invalid client proxy. Ensure you are calling this method on a valid client instance.`);let r=n[e];if(!r)throw Error(`Method "${String(e)}" is not implemented.`);if(typeof r!=`function`)throw Error(`"${String(e)}" is not a function.`);return r(...t)},Kv.set(e,t)),t}var Jv=class extends Hv{outputRef;index;boundFns;cachedReceiver;constructor(e,t){super(),this.outputRef=e,this.index=t}get(e,t,n){if(t===Wv)return this.outputRef.current;if(t===Fv)return this.index;let r=Vv(t,`ClientProxy`);if(r!==!1)return r;let i=this.outputRef.current[t];if(typeof i==`function`){this.cachedReceiver!==n&&(this.boundFns=new Map,this.cachedReceiver=n);let e=this.boundFns.get(t);return e||(e=qv(t).bind(n),this.boundFns.set(t,e)),e}return i}ownKeys(){return Object.keys(this.outputRef.current)}has(e,t){return t===Wv||t===Fv?!0:t in this.outputRef.current}},Yv=Uv(e=>{let t=hv(null),n=Rv().length,r=vv(()=>new Proxy({},new Jv(t,n)),[n]),i=zv(r,()=>xv(e));return t.current||=i,mv(()=>{t.current=i}),{methods:r,state:i.getState?.(),key:e.key}}),Xv=e=>xv(Yv(e)),Zv=Symbol(`assistant-ui.store.proxiedAssistantState`),Qv=e=>e===`on`||e===`subscribe`||typeof e==`symbol`,$v=e=>{class t extends Hv{get(t,n){let r=Vv(n,`AssistantState`);if(r!==!1)return r;let i=n;if(!Qv(i))return Gv(e[i]())}ownKeys(){return Object.keys(e).filter(e=>!Qv(e))}has(t,n){return!Qv(n)&&n in e}}return new Proxy({},new t)},ey=e=>e[Zv],ty=()=>()=>{},ny=e=>{let t=(()=>{throw Error(e)});return t.source=null,t.query=null,t},ry=new Proxy({},new class extends Hv{get(e,t){if(t===`subscribe`||t===`on`)return ty;if(t===Zv)return iy;let n=Vv(t,`DefaultAssistantClient`);return n===!1?ny(`You are using a component or hook that requires an AuiProvider. Wrap your component in an <AuiProvider> component.`):n}ownKeys(){return[`subscribe`,`on`,Zv]}has(e,t){return t===`subscribe`||t===`on`||t===Zv}}),iy=$v(ry),ay=()=>new Proxy({},{get(e,t){let n=Vv(t,`AssistantClient`);return n===!1?ny(`The current scope does not have a "${String(t)}" property.`):n}}),oy=(0,F.createContext)(ry),sy=()=>(0,F.useContext)(oy),cy=({value:e,children:t})=>(0,L.jsx)(oy.Provider,{value:e,children:t}),ly=tv(e=>null),uy=Symbol(`assistant-ui.transform-scopes`);function dy(e,t){let n=e;if(n[uy])throw Error(`transformScopes is already attached to this resource`);n[uy]=t}function fy(e){return e[uy]}function py(e,t){let n={...e},r=new Set,i=!0;for(;i;){i=!1;for(let e of Object.values(n)){if(e.type===ly||r.has(e.type))continue;r.add(e.type);let a=fy(e.type);if(a){a(n,t),i=!0;break}}}let a={},o={};for(let[e,t]of Object.entries(n))t.type===ly?o[e]=t:a[e]=t;return{rootClients:a,derivedClients:o}}var my=e=>vv(()=>e,[...Object.entries(e).flat()]),hy=(e,t)=>{let{rootClients:n,derivedClients:r}=py(e,t);return{rootClients:my(n),derivedClients:my(r)}},gy=e=>typeof e==`string`?{scope:e.split(`.`)[0],event:e}:{scope:e.scope,event:e.event},_y=tv(()=>gv(()=>{let e=new Map,t=new Set,n=new Set;return{on(n,r){let i=r;if(n===`*`)return t.add(i),()=>t.delete(i);let a=e.get(n);return a||(a=new Set,e.set(n,a)),a.add(i),()=>{a.delete(i),a.size===0&&e.delete(n)}},emit(n,r,i){let a=e.get(n);!a&&t.size===0||queueMicrotask(()=>{let e=[];if(a)for(let t of a)try{t(r,i)}catch(t){e.push(t)}if(t.size>0){let a={event:n,payload:r};for(let n of t)try{n(a,i)}catch(t){e.push(t)}}if(e.length>0){if(e.length===1)throw e[0];for(let t of e)console.error(t);throw AggregateError(e,`Errors occurred during event emission`)}})},subscribe(e){return n.add(e),()=>n.delete(e)},notifySubscribers(){for(let e of n)try{e()}catch(e){console.error(`NotificationManager: subscriber callback error`,e)}}}},[])),vy=Mv(null),yy=(e,t)=>Nv(vy,e,t),by=()=>{let e=Pv(vy);if(!e)throw Error(`AssistantTapContext is not available`);return e},xy=()=>by().clientRef,Sy=()=>{let{emit:e}=by(),t=Rv();return bv((n,r)=>{e(n,r,t)})},Cy=e=>vv(()=>e,e),wy=tv(({element:e,emit:t,clientRef:n})=>{let{methods:r,state:i}=yy({clientRef:n,emit:t},()=>Xv(e));return vv(()=>({state:i,methods:r}),[r,i])}),Ty=tv(({element:e,notifications:t,clientRef:n,name:r})=>{let i=Av(wy({element:e,emit:t.emit,clientRef:n}));return mv(()=>i.subscribe(t.notifySubscribers),[i,t]),vv(()=>{let e=()=>i.getValue().methods;return Object.defineProperties(e,{source:{value:`root`,writable:!1},query:{value:{},writable:!1},name:{value:r,configurable:!0}}),e},[i,r])}),Ey=tv(()=>vv(()=>({clients:[],subscribe:void 0,on:void 0}),[])),Dy=tv(({clients:e,clientRef:t})=>{let n=xv(_y());mv(()=>t.parent.subscribe(n.notifySubscribers),[t,n]);let r=Cy(Sv(()=>Object.keys(e).map(r=>nv(r,Ty({element:e[r],notifications:n,clientRef:t,name:r}))),[e,n,t]));return vv(()=>({clients:r,subscribe:n.subscribe,on:function(e,r){if(!this)throw Error(`const { on } = useAui() is not supported. Use aui.on() instead.`);let{scope:i,event:a}=gy(e);if(i!==`*`&&this[i].source===null)throw Error(`Scope "${i}" is not available. Use { scope: "*", event: "${a}" } to listen globally.`);let o=n.on(a,(e,t)=>{if(i===`*`){r(e);return}let n=this[i]();n===t[Iv(n)]&&r(e)});if(i!==`*`&&t.parent[i].source===null)return o;let s=t.parent.on(e,r);return()=>{o(),s()}}}),[r,n,t])}),Oy=(e,t,n)=>{if(`source`in e&&`query`in e)return e;if(n.dep===e)return n.meta;let r=e.getMeta(t.current);return n.meta=r,n.dep=e,r},ky=tv(({element:e,clientRef:t,name:n})=>{let r=bv(()=>e.props);return vv(()=>{let e=()=>r().get(t.current),i={};return Object.defineProperties(e,{source:{get:()=>Oy(r(),t,i).source},query:{get:()=>Oy(r(),t,i).query},name:{value:n,configurable:!0}}),e},[t,n])}),Ay=tv(({clients:e,clientRef:t})=>Cy(Sv(()=>Object.keys(e).map(n=>nv(n,ky({element:e[n],clientRef:t,name:n}))),[e,t]))),jy=tv(({parent:e,clients:t})=>{let{rootClients:n,derivedClients:r}=hy(t,e),i=hv({parent:e,current:null}).current;mv(()=>{i.current=s});let a=xv(Object.keys(n).length>0?Dy({clients:n,clientRef:i}):Ey()),o=xv(Ay({clients:r,clientRef:i})),s=vv(()=>{let t=e===ry?ay():e,n=Object.create(t);Object.assign(n,{subscribe:a.subscribe??e.subscribe,on:a.on??e.on,[Zv]:$v(n)});for(let e of a.clients)n[e.name]=e;for(let e of o)n[e.name]=e;return n},[e,a,o]);return i.current===null&&(i.current=s),s});function My(e,{parent:t}={parent:sy()}){if(e)return ev(jy({parent:t??ry,clients:e}));if(t===null)throw Error(`received null parent, this usage is not allowed`);return t}var Ny=e=>{let t=My(),n=ey(t),r=(0,F.useSyncExternalStore)(t.subscribe,()=>e(n),()=>e(n));if(r===n)throw Error(`You tried to return the entire AssistantState. This is not supported due to technical limitations.`);return(0,F.useDebugValue)(r),r},Bee=F.createContext(!0);function Py(){throw Error(`A function wrapped in useEffectEvent can't be called during rendering.`)}var Vee=`use`in F.default?()=>{try{return F.use(Bee)}catch{return!1}}:()=>!1;function Hee(e){let t=F.useRef(Py);return F.useInsertionEffect(()=>{t.current=e},[e]),(...e)=>{Vee()&&Py();let n=t.current;return n(...e)}}var Fy=(e,t)=>{let n=My(),r=Hee(t),{scope:i,event:a}=gy(e);(0,F.useEffect)(()=>n.on({scope:i,event:a},r),[n,i,a,r])},Uee=e=>{let t=My(),n=(0,F.useRef)(!1),r=n.current?null:e(t);return Ny(()=>n.current?e(t):r),()=>(n.current=!0,e(t))},Wee=Object.freeze({});function Iy({getItemState:e,children:t}){return Gee(t(Uee(e)))}var Gee=e=>{let t=typeof e==`object`&&e&&`type`in e?e:null,n=t?.type,r=t?.key;return(0,F.useMemo)(()=>t,[n,r,typeof t?.props==`object`&&t.props!=null&&Object.entries(t.props).length===0?Wee:t?.props])??e},Ly=({children:e,condition:t})=>Ny(t)?e:null;Ly.displayName=`AuiIf`;var Kee=Uv(e=>{if(e.key===void 0)throw Error(`tapClientResource: Element has no key`);return xv(Yv(e))});function Ry(e,t){let n=Sv(()=>e().map(e=>Kee(e)),t),r=vv(()=>Object.keys(n),[n]),i=vv(()=>n.reduce((e,t,n)=>(e[t.key]=n,e),{}),[n]);return{state:vv(()=>n.map(e=>e.state),[n]),get:e=>{if(`index`in e){if(e.index<0||e.index>=r.length)throw Error(`tapClientLookup: Index ${e.index} out of bounds (length: ${r.length})`);return n[e.index].methods}let t=i[e.key];if(t===void 0)throw Error(`tapClientLookup: Key "${e.key}" not found`);return n[t].methods}}}var zy=e=>{let t,n=new Set,r=(e,r)=>{let i=typeof e==`function`?e(t):e;if(!Object.is(i,t)){let e=t;t=r??(typeof i!=`object`||!i)?i:Object.assign({},t,i),n.forEach(n=>n(t,e))}},i=()=>t,a={setState:r,getState:i,getInitialState:()=>o,subscribe:e=>(n.add(e),()=>n.delete(e))},o=t=e(r,i,a);return a},qee=(e=>e?zy(e):zy),Jee=e=>e;function Yee(e,t=Jee){let n=F.useSyncExternalStore(e.subscribe,F.useCallback(()=>t(e.getState()),[e,t]),F.useCallback(()=>t(e.getInitialState()),[e,t]));return F.useDebugValue(n),n}var By=e=>{let t=qee(e),n=e=>Yee(t,e);return Object.assign(n,t),n},Vy=(e=>e?By(e):By),Xee=n(((e,t)=>{var n=typeof Buffer<`u`,r=/"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/,i=/"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;function a(e,t,a){a==null&&typeof t==`object`&&t&&(a=t,t=void 0),n&&Buffer.isBuffer(e)&&(e=e.toString()),e&&e.charCodeAt(0)===65279&&(e=e.slice(1));let s=JSON.parse(e,t);if(typeof s!=`object`||!s)return s;let c=a&&a.protoAction||`error`,l=a&&a.constructorAction||`error`;if(c===`ignore`&&l===`ignore`)return s;if(c!==`ignore`&&l!==`ignore`){if(r.test(e)===!1&&i.test(e)===!1)return s}else if(c!==`ignore`&&l===`ignore`){if(r.test(e)===!1)return s}else if(i.test(e)===!1)return s;return o(s,{protoAction:c,constructorAction:l,safe:a&&a.safe})}function o(e,{protoAction:t=`error`,constructorAction:n=`error`,safe:r}={}){let i=[e];for(;i.length;){let e=i;i=[];for(let a of e){if(t!==`ignore`&&Object.prototype.hasOwnProperty.call(a,`__proto__`)){if(r===!0)return null;if(t===`error`)throw SyntaxError(`Object contains forbidden prototype property`);delete a.__proto__}if(n!==`ignore`&&Object.prototype.hasOwnProperty.call(a,`constructor`)&&a.constructor!==null&&typeof a.constructor==`object`&&Object.prototype.hasOwnProperty.call(a.constructor,`prototype`)){if(r===!0)return null;if(n===`error`)throw SyntaxError(`Object contains forbidden prototype property`);delete a.constructor}for(let e in a){let t=a[e];t&&typeof t==`object`&&i.push(t)}}}return e}function s(e,t,n){let{stackTraceLimit:r}=Error;Error.stackTraceLimit=0;try{return a(e,t,n)}finally{Error.stackTraceLimit=r}}function c(e,t){let{stackTraceLimit:n}=Error;Error.stackTraceLimit=0;try{return a(e,t,{safe:!0})}catch{return}finally{Error.stackTraceLimit=n}}t.exports=s,t.exports.default=s,t.exports.parse=s,t.exports.safeParse=c,t.exports.scan=o}));function Zee(e){let t=[`ROOT`],n=-1,r=null,i=[],a;function o(){a!==void 0&&(i.push(JSON.parse(`"${a}"`)),a=void 0)}function s(e,i,a){switch(e){case`"`:n=i,t.pop(),t.push(a),t.push(`INSIDE_STRING`),o();break;case`f`:case`t`:case`n`:n=i,r=i,t.pop(),t.push(a),t.push(`INSIDE_LITERAL`);break;case`-`:t.pop(),t.push(a),t.push(`INSIDE_NUMBER`),o();break;case`0`:case`1`:case`2`:case`3`:case`4`:case`5`:case`6`:case`7`:case`8`:case`9`:n=i,t.pop(),t.push(a),t.push(`INSIDE_NUMBER`),o();break;case`{`:n=i,t.pop(),t.push(a),t.push(`INSIDE_OBJECT_START`),o();break;case`[`:n=i,t.pop(),t.push(a),t.push(`INSIDE_ARRAY_START`),o();break}}function c(e,r){switch(e){case`,`:t.pop(),t.push(`INSIDE_OBJECT_AFTER_COMMA`);break;case`}`:n=r,t.pop(),a=i.pop();break}}function l(e,r){switch(e){case`,`:t.pop(),t.push(`INSIDE_ARRAY_AFTER_COMMA`),a=(Number(a)+1).toString();break;case`]`:n=r,t.pop(),a=i.pop();break}}for(let o=0;o<e.length;o++){let u=e[o];switch(t[t.length-1]){case`ROOT`:s(u,o,`FINISH`);break;case`INSIDE_OBJECT_START`:switch(u){case`"`:t.pop(),t.push(`INSIDE_OBJECT_KEY`),a=``;break;case`}`:n=o,t.pop(),a=i.pop();break}break;case`INSIDE_OBJECT_AFTER_COMMA`:switch(u){case`"`:t.pop(),t.push(`INSIDE_OBJECT_KEY`),a=``;break}break;case`INSIDE_OBJECT_KEY`:switch(u){case`"`:t.pop(),t.push(`INSIDE_OBJECT_AFTER_KEY`);break;case`\\`:t.push(`INSIDE_STRING_ESCAPE`),a+=u;break;default:a+=u;break}break;case`INSIDE_OBJECT_AFTER_KEY`:switch(u){case`:`:t.pop(),t.push(`INSIDE_OBJECT_BEFORE_VALUE`);break}break;case`INSIDE_OBJECT_BEFORE_VALUE`:s(u,o,`INSIDE_OBJECT_AFTER_VALUE`);break;case`INSIDE_OBJECT_AFTER_VALUE`:c(u,o);break;case`INSIDE_STRING`:switch(u){case`"`:t.pop(),n=o,a=i.pop();break;case`\\`:t.push(`INSIDE_STRING_ESCAPE`);break;default:n=o}break;case`INSIDE_ARRAY_START`:switch(u){case`]`:n=o,t.pop(),a=i.pop();break;default:n=o,a=`0`,s(u,o,`INSIDE_ARRAY_AFTER_VALUE`);break}break;case`INSIDE_ARRAY_AFTER_VALUE`:switch(u){case`,`:t.pop(),t.push(`INSIDE_ARRAY_AFTER_COMMA`),a=(Number(a)+1).toString();break;case`]`:n=o,t.pop(),a=i.pop();break;default:n=o;break}break;case`INSIDE_ARRAY_AFTER_COMMA`:s(u,o,`INSIDE_ARRAY_AFTER_VALUE`);break;case`INSIDE_STRING_ESCAPE`:t.pop(),t[t.length-1]===`INSIDE_STRING`?n=o:t[t.length-1]===`INSIDE_OBJECT_KEY`&&(a+=u);break;case`INSIDE_NUMBER`:switch(u){case`0`:case`1`:case`2`:case`3`:case`4`:case`5`:case`6`:case`7`:case`8`:case`9`:n=o;break;case`e`:case`E`:case`-`:case`.`:break;case`,`:t.pop(),a=i.pop(),t[t.length-1]===`INSIDE_ARRAY_AFTER_VALUE`&&l(u,o),t[t.length-1]===`INSIDE_OBJECT_AFTER_VALUE`&&c(u,o);break;case`}`:t.pop(),a=i.pop(),t[t.length-1]===`INSIDE_OBJECT_AFTER_VALUE`&&c(u,o);break;case`]`:t.pop(),a=i.pop(),t[t.length-1]===`INSIDE_ARRAY_AFTER_VALUE`&&l(u,o);break;default:t.pop(),a=i.pop();break}break;case`INSIDE_LITERAL`:{let i=e.substring(r,o+1);!`false`.startsWith(i)&&!`true`.startsWith(i)&&!`null`.startsWith(i)?(t.pop(),t[t.length-1]===`INSIDE_OBJECT_AFTER_VALUE`?c(u,o):t[t.length-1]===`INSIDE_ARRAY_AFTER_VALUE`&&l(u,o)):n=o;break}}}let u=e.slice(0,n+1);for(let n=t.length-1;n>=0;n--)switch(t[n]){case`INSIDE_STRING`:u+=`"`;break;case`INSIDE_OBJECT_KEY`:case`INSIDE_OBJECT_AFTER_KEY`:case`INSIDE_OBJECT_AFTER_COMMA`:case`INSIDE_OBJECT_START`:case`INSIDE_OBJECT_BEFORE_VALUE`:case`INSIDE_OBJECT_AFTER_VALUE`:u+=`}`;break;case`INSIDE_ARRAY_START`:case`INSIDE_ARRAY_AFTER_COMMA`:case`INSIDE_ARRAY_AFTER_VALUE`:u+=`]`;break;case`INSIDE_LITERAL`:{let t=e.substring(r,e.length);`true`.startsWith(t)?u+=`true`.slice(t.length):`false`.startsWith(t)?u+=`false`.slice(t.length):`null`.startsWith(t)&&(u+=`null`.slice(t.length))}}return[u,i]}var Hy=e(Xee(),1),Uy=Symbol(`aui.parse-partial-json-object.meta`),Qee=e=>e?.[Uy],Wy=e=>{if(e.length===0)return{[Uy]:{state:`partial`,partialPath:[]}};try{let t=Hy.default.parse(e);if(typeof t!=`object`||!t)throw Error(`argsText is expected to be an object`);return t[Uy]={state:`complete`,partialPath:[]},t}catch{try{let[t,n]=Zee(e),r=Hy.default.parse(t);if(typeof r!=`object`||!r)throw Error(`argsText is expected to be an object`);return r[Uy]={state:`partial`,partialPath:n},r}catch{return}}},Gy=(e,t,n)=>{if(typeof e!=`object`||!e)return t.state;if(t.state===`complete`)return`complete`;if(n.length===0)return t.state;let[r,...i]=n;if(!Object.hasOwn(e,r))return`partial`;let[a,...o]=t.partialPath;if(r!==a)return`complete`;let s=e[r];return Gy(s,{state:`partial`,partialPath:o},i)},Ky=(e,t)=>{let n=Qee(e);if(!n)throw Error(`unable to determine object state`);return Gy(e,n,t.map(String))};async function*$ee(){let e=this.getReader();try{for(;;){let{done:t,value:n}=await e.read();if(t)break;yield n}}finally{e.releaseLock()}}function qy(e){return e[Symbol.asyncIterator]??=$ee,e}var Jy=()=>{let e,t,n=new Promise((n,r)=>{e=n,t=r});if(!e||!t)throw Error(`Failed to create promise`);return{promise:n,resolve:e,reject:t}},ete=()=>{let e=[],t=!1,n,r,i=i=>{i.promise||=i.reader.read().then(({done:a,value:o})=>{i.promise=void 0,a?(e.splice(e.indexOf(i),1),t&&e.length===0&&n.close()):n.enqueue(o),r?.resolve(),r=void 0}).catch(t=>{console.error(t),e.forEach(e=>{e.reader.cancel()}),e.length=0,n.error(t),r?.reject(t),r=void 0})};return{readable:new ReadableStream({start(e){n=e},pull(){return r=Jy(),e.forEach(e=>{i(e)}),r.promise},cancel(){e.forEach(e=>{e.reader.cancel()}),e.length=0}}),isSealed(){return t},seal(){t=!0,e.length===0&&n.close()},addStream(n){if(t)throw Error(`Cannot add streams after the run callback has settled.`);let r={reader:n.getReader()};e.push(r),i(r)},enqueue(e){this.addStream(new ReadableStream({start(t){t.enqueue(e),t.close()}}))}}},Yy=class{_controller;_isClosed=!1;constructor(e){this._controller=e}append(e){return this._controller.enqueue({type:`text-delta`,path:[],textDelta:e}),this}close(){this._isClosed||(this._isClosed=!0,this._controller.enqueue({type:`part-finish`,path:[]}),this._controller.close())}},Xy=e=>new ReadableStream({start(t){return e.start?.(new Yy(t))},pull(t){return e.pull?.(new Yy(t))},cancel(t){return e.cancel?.(t)}}),Zy=()=>{let e;return[Xy({start(t){e=t}}),e]},Qy=class{_controller;_isClosed=!1;_mergeTask;constructor(e){this._controller=e;let t=Xy({start:e=>{this._argsTextController=e}}),n=!1;this._mergeTask=t.pipeTo(new WritableStream({write:e=>{switch(e.type){case`text-delta`:n=!0,this._controller.enqueue(e);break;case`part-finish`:n||this._controller.enqueue({type:`text-delta`,textDelta:`{}`,path:[]}),this._controller.enqueue({type:`tool-call-args-text-finish`,path:[]});break;default:throw Error(`Unexpected chunk type: ${e.type}`)}}}))}get argsText(){return this._argsTextController}_argsTextController;async setResponse(e){this._argsTextController.close(),await Promise.resolve(),this._controller.enqueue({type:`result`,path:[],...e.artifact===void 0?{}:{artifact:e.artifact},result:e.result,isError:e.isError??!1,...e.modelContent===void 0?{}:{modelContent:e.modelContent},...e.messages===void 0?{}:{messages:e.messages}})}async close(){this._isClosed||(this._isClosed=!0,this._argsTextController.close(),await this._mergeTask,this._controller.enqueue({type:`part-finish`,path:[]}),this._controller.close())}},$y=e=>new ReadableStream({start(t){return e.start?.(new Qy(t))},pull(t){return e.pull?.(new Qy(t))},cancel(t){return e.cancel?.(t)}}),eb=()=>{let e;return[$y({start(t){e=t}}),e]},tb=class{value=-1;up(){return++this.value}},nb=class extends TransformStream{constructor(e){super({transform(t,n){n.enqueue({...t,path:[e,...t.path]})}})}};TransformStream;var rb=class extends TransformStream{constructor(e){let t=new tb,n=new Map;super({transform(r,i){r.type===`part-start`&&r.path.length===0&&n.set(t.up(),e.up());let[a,...o]=r.path;if(a===void 0){i.enqueue(r);return}let s=n.get(a);if(s===void 0)throw Error(`Path not found`);i.enqueue({...r,path:[s,...o]})}})}},ib=class extends TransformStream{constructor(e){super();let t=e(super.readable);Object.defineProperty(this,`readable`,{value:t,writable:!1})}},ab=class extends TransformStream{constructor(){let e=[];super({transform(t,n){if(t.type===`part-start`){if(t.path.length!==0){n.error(Error(`Nested parts are not supported`));return}e.push(t.part),n.enqueue(t);return}if(t.type===`text-delta`||t.type===`result`||t.type===`part-finish`||t.type===`tool-call-args-text-finish`){if(t.path.length!==1){n.error(Error(`${t.type} chunks must have a path of length 1`));return}let r=t.path[0];if(r<0||r>=e.length){n.error(Error(`Invalid path index: ${r}`));return}let i=e[r];n.enqueue({...t,meta:i});return}n.enqueue(t)}})}},ob=(e,t=21)=>(n=t)=>{let r=``,i=n|0;for(;i--;)r+=e[Math.random()*e.length|0];return r},sb=ob(`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`,7),cb=class e{_state;_parentId;constructor(e){this._state=e||{merger:ete(),contentCounter:new tb}}get __internal_isClosed(){return this._state.merger.isSealed()}__internal_getReadable(){return this._state.merger.readable}__internal_subscribeToClose(e){this._state.closeSubscriber=e}_addPart(e,t){this._state.append&&(this._state.append.controller.close(),this._state.append=void 0),this.enqueue({type:`part-start`,part:e,path:[]}),this._state.merger.addStream(t.pipeThrough(new nb(this._state.contentCounter.value)))}merge(e){this._state.merger.addStream(e.pipeThrough(new rb(this._state.contentCounter)))}appendText(e){this._state.append?.kind!==`text`&&(this._state.append={kind:`text`,controller:this.addTextPart()}),this._state.append.controller.append(e)}appendReasoning(e){this._state.append?.kind!==`reasoning`&&(this._state.append={kind:`reasoning`,controller:this.addReasoningPart()}),this._state.append.controller.append(e)}addTextPart(){let[e,t]=Zy();return this._addPart({type:`text`},e),t}addReasoningPart(){let[e,t]=Zy();return this._addPart({type:`reasoning`},e),t}addToolCallPart(e){let t=typeof e==`string`?{toolName:e}:e,n=t.toolName,r=t.toolCallId??sb(),[i,a]=eb();return this._addPart({type:`tool-call`,toolName:n,toolCallId:r,...this._parentId&&{parentId:this._parentId}},i),t.argsText!==void 0&&(a.argsText.append(t.argsText),a.argsText.close()),t.args!==void 0&&(a.argsText.append(JSON.stringify(t.args)),a.argsText.close()),t.response!==void 0&&a.setResponse(t.response),a}_finishedPartStream(){return new ReadableStream({start(e){e.enqueue({type:`part-finish`,path:[]}),e.close()}})}_withParentIdOption(e){return this._parentId?{...e,parentId:this._parentId}:e}appendSource(e){this._addPart(this._withParentIdOption(e),this._finishedPartStream())}appendFile(e){this._addPart(this._withParentIdOption(e),this._finishedPartStream())}appendData(e){this._addPart(this._withParentIdOption(e),this._finishedPartStream())}enqueue(e){this._state.merger.enqueue(e),e.type===`part-start`&&e.path.length===0&&this._state.contentCounter.up()}withParentId(t){let n=new e(this._state);return n._parentId=t,n}close(){this._state.append?.controller?.close(),this._state.merger.seal(),this._state.closeSubscriber?.()}};function lb(e){let t=new cb;return(async()=>{try{await e(t)}catch(e){throw t.__internal_isClosed||t.enqueue({type:`error`,path:[],error:String(e)}),e}finally{t.__internal_isClosed||t.close()}})(),t.__internal_getReadable()}function ub(){let{resolve:e,promise:t}=Jy(),n;return[lb(r=>(n=r,n.__internal_subscribeToClose(e),t)),n]}var db=tv(e=>({getState:()=>e})),fb=tv(e=>{let[t]=dv(()=>({suggestions:(e??[]).map(e=>typeof e==`string`?{title:e,label:``,prompt:e}:{title:e.title,label:e.label,prompt:e.prompt})})),n=Ry(()=>t.suggestions.map((e,t)=>nv(t,db(e))),[t.suggestions]);return{getState:()=>t,suggestion:({index:e})=>n.get({index:e})}}),pb=Object.freeze({type:`complete`}),mb=tv(({parts:e,getMessagePart:t})=>{let[n,r]=dv(!0),i=vv(()=>e[e.length-1]?.status??pb,[e]),a=vv(()=>({parts:e,collapsed:n,status:i}),[e,n,i]);return{getState:()=>a,setCollapsed:r,part:t}}),hb=e=>Array.from(e).map(e=>e.getModelContext()).sort((e,t)=>(t.priority??0)-(e.priority??0)).reduce((e,t)=>{if(t.system&&(e.system?e.system+=`\n\n${t.system}`:e.system=t.system),t.tools)for(let[n,r]of Object.entries(t.tools)){let t=e.tools?.[n];if(t&&t!==r)throw Error(`You tried to define a tool with the name ${n}, but it already exists.`);e.tools||={},e.tools[n]=r}return t.config&&(e.config={...e.config,...t.config}),t.callSettings&&(e.callSettings={...e.callSettings,...t.callSettings}),e},{}),gb=class{_providers=new Set;getModelContext(){return hb(this._providers)}registerModelContextProvider(e){this._providers.add(e);let t=e.subscribe?.(()=>{this.notifySubscribers()});return this.notifySubscribers(),()=>{this._providers.delete(e),t?.(),this.notifySubscribers()}}_subscribers=new Set;notifySubscribers(){for(let e of this._subscribers)e()}subscribe(e){return this._subscribers.add(e),()=>this._subscribers.delete(e)}},_b=1,vb=tv(()=>{let[e]=dv(()=>({version:_b+1})),t=vv(()=>new gb,[]);return{getState:()=>e,getModelContext:()=>t.getModelContext(),subscribe:e=>t.subscribe(e),register:e=>t.registerModelContextProvider(e)}}),yb=tv(({toolkit:e,mcpApp:t})=>{let n=Sv(()=>t?[nv(`mcpApp`,t)]:[],[t])[0],[r,i]=dv(()=>({tools:{}})),a=vv(()=>({tools:r.tools,mcpApp:n}),[r,n]),o=xy(),s=yv((e,t)=>(i(n=>({tools:{...n.tools,[e]:[...n.tools[e]??[],t]}})),()=>{i(n=>({tools:{...n.tools,[e]:n.tools[e]?.filter(e=>e!==t)??[]}}))}),[]);return mv(()=>{if(!e)return;let t=[];for(let[n,r]of Object.entries(e))r.render&&t.push(s(n,r.render));let n=Object.entries(e).reduce((e,[t,n])=>{let{render:r,...i}=n;return e[t]=i,e},{});return t.push(o.current.modelContext().register({getModelContext:()=>({tools:n})})),()=>{t.forEach(e=>e())}},[e,s,o]),{getState:()=>a,setToolUI:s}});dy(yb,(e,t)=>{!e.modelContext&&t.modelContext.source===null&&(e.modelContext=vb())});var bb=tv(()=>{let[e,t]=dv(()=>({renderers:{},fallbacks:[]}));return{getState:()=>e,setDataUI:yv((e,n)=>(t(t=>({...t,renderers:{...t.renderers,[e]:[...t.renderers[e]??[],n]}})),()=>{t(t=>({...t,renderers:{...t.renderers,[e]:t.renderers[e]?.filter(e=>e!==n)??[]}}))}),[]),setFallbackDataUI:yv(e=>(t(t=>({...t,fallbacks:[...t.fallbacks,e]})),()=>{t(t=>({...t,fallbacks:t.fallbacks.filter(t=>t!==e)}))}),[])}}),xb=Symbol.for(`aui.tool-response`),Sb=class e{get[xb](){return!0}artifact;result;isError;modelContent;messages;constructor(e){e.artifact!==void 0&&(this.artifact=e.artifact),this.result=e.result,this.isError=e.isError??!1,e.modelContent!==void 0&&(this.modelContent=e.modelContent),e.messages!==void 0&&(this.messages=e.messages)}static[Symbol.hasInstance](e){return typeof e==`object`&&!!e&&xb in e}static toResponse(t){return t instanceof e?t:new e({result:t===void 0?`<no result>`:t})}};function Cb(e,t,n){try{let r=e();if(typeof r==`object`&&r&&`then`in r)return r.then(t,n);t(r)}catch(e){n(e)}}function wb(e,t){let n=e;for(let e of t){if(n==null)return;n=n[e]}return n}var Tb=class{resolve;reject;disposed=!1;fieldPath;constructor(e,t,n){this.resolve=e,this.reject=t,this.fieldPath=n}update(e){if(!this.disposed)try{if(Ky(e,this.fieldPath)===`complete`){let t=wb(e,this.fieldPath);t!==void 0&&(this.resolve(t),this.dispose())}}catch(e){this.reject(e),this.dispose()}}dispose(){this.disposed=!0}},Eb=class{controller;disposed=!1;fieldPath;constructor(e,t){this.controller=e,this.fieldPath=t}update(e){if(!this.disposed)try{let t=wb(e,this.fieldPath);t!==void 0&&this.controller.enqueue(t),Ky(e,this.fieldPath)===`complete`&&(this.controller.close(),this.dispose())}catch(e){this.controller.error(e),this.dispose()}}dispose(){this.disposed=!0}},Db=class{controller;disposed=!1;fieldPath;lastValue=void 0;constructor(e,t){this.controller=e,this.fieldPath=t}update(e){if(!this.disposed)try{let t=wb(e,this.fieldPath);if(t!==void 0&&typeof t==`string`){let e=t.substring(this.lastValue?.length||0);this.lastValue=t,this.controller.enqueue(e)}Ky(e,this.fieldPath)===`complete`&&(this.controller.close(),this.dispose())}catch(e){this.controller.error(e),this.dispose()}}dispose(){this.disposed=!0}},Ob=class{controller;disposed=!1;fieldPath;processedIndexes=new Set;constructor(e,t){this.controller=e,this.fieldPath=t}update(e){if(!this.disposed)try{let t=wb(e,this.fieldPath);if(!Array.isArray(t))return;for(let n=0;n<t.length;n++)this.processedIndexes.has(n)||Ky(e,[...this.fieldPath,n])===`complete`&&(this.controller.enqueue(t[n]),this.processedIndexes.add(n));Ky(e,this.fieldPath)===`complete`&&(this.controller.close(),this.dispose())}catch(e){this.controller.error(e),this.dispose()}}dispose(){this.disposed=!0}},kb=class{argTextDeltas;handles=new Set;args=Wy(``);constructor(e){this.argTextDeltas=e,this.processStream()}async processStream(){try{let e=``,t=this.argTextDeltas.getReader();for(;;){let{value:n,done:r}=await t.read();if(r)break;e+=n;let i=Wy(e);if(i!==void 0){this.args=i;for(let e of this.handles)e.update(i)}}}catch(e){console.error(`Error processing argument stream:`,e);for(let e of this.handles)e.dispose()}}get(...e){return new Promise((t,n)=>{let r=new Tb(t,n,e);if(this.args&&Ky(this.args,e)===`complete`){let n=wb(this.args,e);if(n!==void 0){t(n);return}}this.handles.add(r),r.update(this.args)})}streamValues(...e){let t=e;return qy(new ReadableStream({start:e=>{let n=new Eb(e,t);this.handles.add(n),n.update(this.args)},cancel:()=>{for(let e of this.handles)if(e instanceof Eb){e.dispose(),this.handles.delete(e);break}}}))}streamText(...e){let t=e;return qy(new ReadableStream({start:e=>{let n=new Db(e,t);this.handles.add(n),n.update(this.args)},cancel:()=>{for(let e of this.handles)if(e instanceof Db){e.dispose(),this.handles.delete(e);break}}}))}forEach(...e){let t=e;return qy(new ReadableStream({start:e=>{let n=new Ob(e,t);this.handles.add(n),n.update(this.args)},cancel:()=>{for(let e of this.handles)if(e instanceof Ob){e.dispose(),this.handles.delete(e);break}}}))}},Ab=class{promise;constructor(e){this.promise=e}get(){return this.promise}},jb=class{args;response;writable;resolve;argsText=``;constructor(){let e=new TransformStream;this.writable=e.writable,this.args=new kb(e.readable);let{promise:t,resolve:n}=Jy();this.resolve=n,this.response=new Ab(t)}async appendArgsTextDelta(e){let t=this.writable.getWriter();try{await t.write(e)}catch(e){console.warn(e)}finally{t.releaseLock()}this.argsText+=e}setResponse(e){this.resolve(e)}result={get:async()=>(await this.response.get()).result}},Mb=class extends ib{constructor(e){let t=new Map,n=new Map;super(r=>{let i=new TransformStream({transform(r,i){switch((r.type!==`part-finish`||r.meta.type!==`tool-call`)&&i.enqueue(r),r.type){case`part-start`:if(r.part.type===`tool-call`){let t=new jb;n.set(r.part.toolCallId,t),e.streamCall({reader:t,toolCallId:r.part.toolCallId,toolName:r.part.toolName})}break;case`text-delta`:if(r.meta.type===`tool-call`){let e=r.meta.toolCallId,t=n.get(e);if(!t)throw Error(`No controller found for tool call`);t.appendArgsTextDelta(r.textDelta)}break;case`result`:{if(r.meta.type!==`tool-call`)break;let{toolCallId:e}=r.meta,t=n.get(e);if(!t)throw Error(`No controller found for tool call`);t.setResponse(new Sb({result:r.result,artifact:r.artifact,isError:r.isError,modelContent:r.modelContent}));break}case`tool-call-args-text-finish`:{if(r.meta.type!==`tool-call`)break;let{toolCallId:a,toolName:o}=r.meta,s=n.get(a);if(!s)throw Error(`No controller found for tool call`);let c=!1,l=Cb(()=>{let t;try{t=Hy.default.parse(s.argsText)}catch(e){throw Error(`Function parameter parsing failed. ${JSON.stringify(e.message)}`)}let n=e.execute({toolCallId:a,toolName:o,args:t});return n!==void 0&&(c=!0,e.onExecutionStart?.(a,o)),n},t=>{if(c&&e.onExecutionEnd?.(a,o),t===void 0)return;let n=new Sb({artifact:t.artifact,result:t.result,isError:t.isError,messages:t.messages,modelContent:t.modelContent});s.setResponse(n),i.enqueue({type:`result`,path:r.path,...n})},t=>{c&&e.onExecutionEnd?.(a,o);let n=new Sb({result:String(t),isError:!0});s.setResponse(n),i.enqueue({type:`result`,path:r.path,...n})});l&&t.set(a,l);break}case`part-finish`:{if(r.meta.type!==`tool-call`)break;let{toolCallId:e}=r.meta,a=t.get(e);a?a.then(()=>{t.delete(e),n.delete(e),i.enqueue(r)}):i.enqueue(r)}}},async flush(){await Promise.all(t.values())}});return r.pipeThrough(new ab).pipeThrough(i)})}},Nb=e=>typeof e==`object`&&!!e&&`~standard`in e&&e[`~standard`].version===1;function Pb(e,t,n,r){let i=e?.[n.toolName];return i?.execute?(async e=>{if(t.aborted)return new Sb({result:`Tool execution was cancelled.`,isError:!0});let a=e;if(Nb(i.parameters)){let e=i.parameters[`~standard`].validate(n.args);e instanceof Promise&&(e=await e),e.issues&&(a=i.experimental_onSchemaValidationError??(()=>{throw Error(`Function parameter validation failed. ${JSON.stringify(e.issues)}`)}))}let o=new Promise(e=>{let n=()=>{queueMicrotask(()=>{queueMicrotask(()=>{e(new Sb({result:`Tool execution was cancelled.`,isError:!0}))})})};t.aborted?n():t.addEventListener(`abort`,n,{once:!0})}),s=(async()=>{let e=await a(n.args,{toolCallId:n.toolCallId,abortSignal:t,human:e=>r(n.toolCallId,e)}),o=Sb.toResponse(e);if(i.toModelOutput&&!o.isError&&o.modelContent===void 0)try{let e=await i.toModelOutput({toolCallId:n.toolCallId,input:n.args,output:o.result});return new Sb({result:o.result,artifact:o.artifact,isError:o.isError,messages:o.messages,modelContent:e})}catch(e){console.warn(`[assistant-stream] tool "${n.toolName}" toModelOutput threw; falling back to default projection.`,e)}return o})();return Promise.race([s,o])})(i.execute):void 0}function Fb(e,t,n,r,i){e?.[r.toolName]?.streamCall?.(n,{toolCallId:r.toolCallId,abortSignal:t,human:e=>i(r.toolCallId,e)})}function Ib(e,t,n,r){let i=typeof e==`function`?e:()=>e,a=typeof t==`function`?t:()=>t;return new Mb({execute:e=>Pb(i(),a(),e,n),streamCall:({reader:e,...t})=>Fb(i(),a(),e,t,n),onExecutionStart:r?.onExecutionStart,onExecutionEnd:r?.onExecutionEnd})}var Lb=e=>{let[,t]=dv(e.getState);return mv(()=>(t(e.getState()),e.subscribe(()=>{t(e.getState())})),[e]),e.getState()},Rb=tv(({runtime:e})=>{let t=Lb(e);return{getState:()=>t,remove:e.remove,__internal_getRuntime:()=>e}}),zb=tv(({runtime:e})=>{let t=Lb(e);return{getState:()=>t,addToolResult:t=>e.addToolResult(t),resumeToolCall:t=>e.resumeToolCall(t),__internal_getRuntime:()=>e}}),Bb=tv(({runtime:e,index:t})=>xv(Rb({runtime:vv(()=>e.getAttachmentByIndex(t),[e,t])}))),Vb=tv(({threadIdRef:e,messageIdRef:t,runtime:n})=>{let r=Lb(n),i=Sy();mv(()=>{let r=[];for(let a of[`send`,`attachmentAdd`]){let o=n.unstable_on(a,()=>{i(`composer.${a}`,{threadId:e.current,...t&&{messageId:t.current}})});r.push(o)}return r.push(n.unstable_on(`attachmentAddError`,n=>{i(`composer.attachmentAddError`,{threadId:e.current,...t&&{messageId:t.current},...n.attachmentId&&{attachmentId:n.attachmentId},reason:n.reason,message:n.message})})),()=>{for(let e of r)e()}},[n,i,e,t]);let a=Ry(()=>r.attachments.map((e,t)=>nv(e.id,Bb({runtime:n,index:t}))),[r.attachments,n]),o=vv(()=>({text:r.text,role:r.role,attachments:a.state,runConfig:r.runConfig,isEditing:r.isEditing,canCancel:r.canCancel,canSend:r.canSend,attachmentAccept:r.attachmentAccept,isEmpty:r.isEmpty,type:r.type??`thread`,dictation:r.dictation,quote:r.quote,queue:[]}),[r,a.state]);return{getState:()=>o,setText:n.setText,setRole:n.setRole,setRunConfig:n.setRunConfig,addAttachment:n.addAttachment,reset:n.reset,clearAttachments:n.clearAttachments,send:n.send,cancel:n.cancel,beginEdit:n.beginEdit??(()=>{throw Error(`beginEdit is not supported in this runtime`)}),startDictation:n.startDictation,stopDictation:n.stopDictation,setQuote:n.setQuote,attachment:e=>`id`in e?a.get({key:e.id}):a.get(e),queueItem:()=>{throw Error(`Queue is not supported in this runtime`)},__internal_getRuntime:()=>n}}),Hb=tv(({runtime:e,index:t})=>xv(Rb({runtime:vv(()=>e.getAttachmentByIndex(t),[e,t])}))),Ub=tv(({runtime:e,index:t})=>xv(zb({runtime:vv(()=>e.getMessagePartByIndex(t),[e,t])}))),Wb=tv(({runtime:e,threadIdRef:t})=>{let n=Lb(e),[r,i]=dv(!1),[a,o]=dv(!1),s=vv(()=>({get current(){return e.getState().id}}),[e]),c=Xv(Vb({runtime:e.composer,threadIdRef:t,messageIdRef:s})),l=Ry(()=>n.content.map((t,n)=>nv(`toolCallId`in t&&t.toolCallId!=null?`toolCallId-${t.toolCallId}`:`index-${n}`,Ub({runtime:e,index:n}))),[n.content,e]),u=Ry(()=>(n.attachments??[]).map((t,n)=>nv(t.id,Hb({runtime:e,index:n}))),[n.attachments,e]),d=vv(()=>({...n,parts:l.state,composer:c.state,isCopied:r,isHovering:a}),[n,l.state,c.state,r,a]);return{getState:()=>d,composer:()=>c.methods,reload:t=>e.reload(t),speak:()=>e.speak(),stopSpeaking:()=>e.stopSpeaking(),submitFeedback:t=>e.submitFeedback(t),switchToBranch:t=>e.switchToBranch(t),getCopyText:()=>e.unstable_getCopyText(),part:e=>`index`in e?l.get({index:e.index}):l.get({key:`toolCallId-${e.toolCallId}`}),attachment:e=>`id`in e?u.get({key:e.id}):u.get(e),setIsCopied:i,setIsHovering:o,__internal_getRuntime:()=>e}}),Gb=tv(({runtime:e,id:t,threadIdRef:n})=>xv(Wb({runtime:vv(()=>e.getMessageById(t),[e,t]),threadIdRef:n}))),Kb=tv(({runtime:e})=>{let t=Lb(e),n=Sy();mv(()=>{let t=[];for(let r of[`runStart`,`runEnd`,`initialize`,`modelContextUpdate`]){let i=e.unstable_on(r,()=>{let t=e.getState()?.threadId||`unknown`;n(`thread.${r}`,{threadId:t})});t.push(i)}return()=>{for(let e of t)e()}},[e,n]);let r=vv(()=>({get current(){return e.getState().threadId}}),[e]),i=Xv(Vb({runtime:e.composer,threadIdRef:r})),a=Ry(()=>t.messages.map(t=>nv(t.id,Gb({runtime:e,id:t.id,threadIdRef:r}))),[t.messages,e,r]),o=vv(()=>({isEmpty:a.state.length===0&&!t.isLoading,isDisabled:t.isDisabled,isLoading:t.isLoading,isRunning:t.isRunning,capabilities:t.capabilities,state:t.state,suggestions:t.suggestions,extras:t.extras,speech:t.speech,voice:t.voice,composer:i.state,messages:a.state}),[t,a,i.state]);return{getState:()=>o,composer:()=>i.methods,append:e.append,startRun:e.startRun,resumeRun:e.resumeRun,cancelRun:e.cancelRun,getModelContext:e.getModelContext,export:e.export,import:e.import,reset:e.reset,stopSpeaking:e.stopSpeaking,connectVoice:e.connectVoice,disconnectVoice:e.disconnectVoice,getVoiceVolume:e.getVoiceVolume,subscribeVoiceVolume:e.subscribeVoiceVolume,muteVoice:e.muteVoice,unmuteVoice:e.unmuteVoice,message:e=>`id`in e?a.get({key:e.id}):a.get(e),__internal_getRuntime:()=>e}}),qb=tv(({runtime:e})=>{let t=Lb(e),n=Sy();return mv(()=>{let t=[];for(let r of[`switchedTo`,`switchedAway`]){let i=e.unstable_on(r,()=>{n(`threadListItem.${r}`,{threadId:e.getState().id})});t.push(i)}return()=>{for(let e of t)e()}},[e,n]),{getState:()=>t,switchTo:e.switchTo,rename:e.rename,archive:e.archive,unarchive:e.unarchive,delete:e.delete,generateTitle:e.generateTitle,initialize:e.initialize,detach:e.detach,__internal_getRuntime:()=>e}}),Jb=tv(({runtime:e,id:t})=>xv(qb({runtime:vv(()=>e.getItemById(t),[e,t])}))),Yb=tv(({runtime:e,__internal_assistantRuntime:t})=>{let n=Lb(e),r=Xv(Kb({runtime:e.main})),i=Ry(()=>Object.keys(n.threadItems).map(t=>nv(t,Jb({runtime:e,id:t}))),[n.threadItems,e]),a=vv(()=>({mainThreadId:n.mainThreadId,newThreadId:n.newThreadId??null,isLoading:n.isLoading,isLoadingMore:n.isLoadingMore,hasMore:n.hasMore,threadIds:n.threadIds,archivedThreadIds:n.archivedThreadIds,threadItems:i.state,main:r.state}),[n,i.state,r.state]);return{getState:()=>a,thread:()=>r.methods,item:e=>{if(e===`main`)return i.get({key:a.mainThreadId});if(`id`in e)return i.get({key:e.id});let{index:t,archived:n=!1}=e,r=n?a.archivedThreadIds[t]:a.threadIds[t];return i.get({key:r})},switchToThread:async t=>{await e.switchToThread(t)},switchToNewThread:async()=>{await e.switchToNewThread()},getLoadThreadsPromise:()=>e.getLoadThreadsPromise(),reload:()=>e.reload(),loadMore:()=>e.loadMore(),__internal_getAssistantRuntime:()=>t}}),Xb=tv(e=>{let t=xy();return mv(()=>e.registerModelContextProvider(t.current.modelContext()),[e,t]),xv(Yb({runtime:e.threads,__internal_assistantRuntime:e}))}),Zb=(e,t)=>{e.thread??=ly({source:`threads`,query:{type:`main`},get:e=>e.threads().thread(`main`)}),e.threadListItem??=ly({source:`threads`,query:{type:`main`},get:e=>e.threads().item(`main`)}),e.composer??=ly({source:`thread`,query:{},get:e=>e.threads().thread(`main`).composer()}),!e.modelContext&&t.modelContext.source===null&&(e.modelContext=vb()),!e.suggestions&&t.suggestions.source===null&&(e.suggestions=fb())},Qb=({index:e,children:t})=>(0,L.jsx)(cy,{value:My({message:ly({source:`thread`,query:{type:`index`,index:e},get:t=>t.thread().message({index:e})}),composer:ly({source:`message`,query:{},get:t=>t.thread().message({index:e}).composer()})}),children:t}),$b=({index:e,children:t})=>(0,L.jsx)(cy,{value:My({part:ly({source:`message`,query:{type:`index`,index:e},get:t=>t.message().part({index:e})})}),children:t}),ex=tv(({text:e,isRunning:t})=>{let n=vv(()=>({type:`text`,text:e,status:t?{type:`running`}:{type:`complete`}}),[e,t]);return{getState:()=>n,addToolResult:()=>{throw Error(`Not supported`)},resumeToolCall:()=>{throw Error(`Not supported`)}}}),tx=({text:e,isRunning:t=!1,children:n})=>(0,L.jsx)(cy,{value:My({part:ex({text:e,isRunning:t})}),children:n}),nx=({startIndex:e,endIndex:t,children:n})=>{let r=Ny(e=>e.message.parts).slice(e,t+1),i=My();return(0,L.jsx)(cy,{value:My({chainOfThought:mb({parts:r,getMessagePart:({index:t})=>{if(t<0||t>=r.length)throw Error(`ChainOfThought part index ${t} is out of bounds (0..${r.length-1})`);return i.message().part({index:e+t})}})}),children:n})},rx=Symbol(`skip-update`);function ix(e,t){if(e===void 0&&t===void 0)return!0;if(e===void 0||t===void 0)return!1;for(let n of Object.keys(e)){let r=e[n],i=t[n];if(!Object.is(r,i))return!1}return!0}var ax=class{_subscribers=new Set;subscribe(e){return this._subscribers.add(e),()=>this._subscribers.delete(e)}waitForUpdate(){return new Promise(e=>{let t=this.subscribe(()=>{t(),e()})})}_notifySubscribers(){let e=[];for(let t of this._subscribers)try{t()}catch(t){e.push(t)}if(e.length>0){if(e.length===1)throw e[0];for(let t of e)console.error(t);throw AggregateError(e)}}},ox=class{_subscriptions=new Set;_connection;get isConnected(){return!!this._connection}notifySubscribers(e){for(let t of this._subscriptions)t(e)}_updateConnection(){if(this._subscriptions.size>0){if(this._connection)return;this._connection=this._connect()}else this._connection?.(),this._connection=void 0}subscribe(e){return this._subscriptions.add(e),this._updateConnection(),()=>{this._subscriptions.delete(e),this._updateConnection()}}},sx=class extends ox{binding;get path(){return this.binding.path}constructor(e){super(),this.binding=e;let t=e.getState();if(t===rx)throw Error(`Entry not available in the store`);this._previousState=t}_previousState;getState=()=>(this.isConnected||this._syncState(),this._previousState);_syncState(){let e=this.binding.getState();return e===rx||ix(e,this._previousState)?!1:(this._previousState=e,!0)}_connect(){return this.binding.subscribe(()=>{this._syncState()&&this.notifySubscribers()})}},cx=class extends ox{binding;get path(){return this.binding.path}constructor(e){super(),this.binding=e}_previousStateDirty=!0;_previousState;getState=()=>{if(!this.isConnected||this._previousStateDirty){let e=this.binding.getState();e!==rx&&(this._previousState=e),this._previousStateDirty=!1}if(this._previousState===void 0)throw Error(`Entry not available in the store`);return this._previousState};_connect(){return this.binding.subscribe(()=>{this._previousStateDirty=!0,this.notifySubscribers()})}},lx=class extends ox{binding;get path(){return this.binding.path}constructor(e){super(),this.binding=e}getState(){return this.binding.getState()}outerSubscribe(e){return this.binding.subscribe(e)}_connect(){let e=()=>{this.notifySubscribers()},t=this.binding.getState(),n=t?.subscribe(e),r=this.outerSubscribe(()=>{let r=this.binding.getState();r!==t&&(t=r,n?.(),n=r?.subscribe(e),e())});return()=>{r?.(),n?.()}}},ux=class extends ox{config;constructor(e){super(),this.config=e}getState(){return this.config.binding.getState()}outerSubscribe(e){return this.config.binding.subscribe(e)}_connect(){let e=e=>{this.notifySubscribers(e)},t=this.config.binding.getState(),n=t?.unstable_on(this.config.event,e),r=this.outerSubscribe(()=>{let r=this.config.binding.getState();r!==t&&(t=r,n?.(),n=r?.unstable_on(this.config.event,e))});return()=>{r?.(),n?.()}}},dx=class{_contextProvider=new gb;registerModelContextProvider(e){return this._contextProvider.registerModelContextProvider(e)}getModelContextProvider(){return this._contextProvider}},fx=e=>e.content.filter(e=>e.type===`text`).map(e=>e.text).join(`
56
+ For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return F.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},Nl=`DialogDescriptionWarning`,Pl=({contentRef:e,descriptionId:t})=>{let n=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${jl(Nl).contentName}}.`;return F.useEffect(()=>{let r=e.current?.getAttribute(`aria-describedby`);t&&r&&(document.getElementById(t)||console.warn(n))},[n,e,t]),null},Fl=ol,Il=fl,Ll=ml,Rl=vl,zl=Cl,Bl=Tl,Vl=Dl;function Hl(e){let[t,n]=F.useState(void 0);return ko(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});let t=new ResizeObserver(t=>{if(!Array.isArray(t)||!t.length)return;let r=t[0],i,a;if(`borderBoxSize`in r){let e=r.borderBoxSize,t=Array.isArray(e)?e[0]:e;i=t.inlineSize,a=t.blockSize}else i=e.offsetWidth,a=e.offsetHeight;n({width:i,height:a})});return t.observe(e,{box:`border-box`}),()=>t.unobserve(e)}else n(void 0)},[e]),t}var Ul=[`top`,`right`,`bottom`,`left`],Wl=Math.min,Gl=Math.max,Kl=Math.round,ql=Math.floor,Jl=e=>({x:e,y:e}),Yl={left:`right`,right:`left`,bottom:`top`,top:`bottom`};function Xl(e,t,n){return Gl(e,Wl(t,n))}function Zl(e,t){return typeof e==`function`?e(t):e}function Ql(e){return e.split(`-`)[0]}function $l(e){return e.split(`-`)[1]}function eu(e){return e===`x`?`y`:`x`}function tu(e){return e===`y`?`height`:`width`}function nu(e){let t=e[0];return t===`t`||t===`b`?`y`:`x`}function ru(e){return eu(nu(e))}function iu(e,t,n){n===void 0&&(n=!1);let r=$l(e),i=ru(e),a=tu(i),o=i===`x`?r===(n?`end`:`start`)?`right`:`left`:r===`start`?`bottom`:`top`;return t.reference[a]>t.floating[a]&&(o=pu(o)),[o,pu(o)]}function au(e){let t=pu(e);return[ou(e),t,ou(t)]}function ou(e){return e.includes(`start`)?e.replace(`start`,`end`):e.replace(`end`,`start`)}var su=[`left`,`right`],cu=[`right`,`left`],lu=[`top`,`bottom`],uu=[`bottom`,`top`];function du(e,t,n){switch(e){case`top`:case`bottom`:return n?t?cu:su:t?su:cu;case`left`:case`right`:return t?lu:uu;default:return[]}}function fu(e,t,n,r){let i=$l(e),a=du(Ql(e),n===`start`,r);return i&&(a=a.map(e=>e+`-`+i),t&&(a=a.concat(a.map(ou)))),a}function pu(e){let t=Ql(e);return Yl[t]+e.slice(t.length)}function mu(e){return{top:0,right:0,bottom:0,left:0,...e}}function hu(e){return typeof e==`number`?{top:e,right:e,bottom:e,left:e}:mu(e)}function gu(e){let{x:t,y:n,width:r,height:i}=e;return{width:r,height:i,top:n,left:t,right:t+r,bottom:n+i,x:t,y:n}}function _u(e,t,n){let{reference:r,floating:i}=e,a=nu(t),o=ru(t),s=tu(o),c=Ql(t),l=a===`y`,u=r.x+r.width/2-i.width/2,d=r.y+r.height/2-i.height/2,f=r[s]/2-i[s]/2,p;switch(c){case`top`:p={x:u,y:r.y-i.height};break;case`bottom`:p={x:u,y:r.y+r.height};break;case`right`:p={x:r.x+r.width,y:d};break;case`left`:p={x:r.x-i.width,y:d};break;default:p={x:r.x,y:r.y}}switch($l(t)){case`start`:p[o]-=f*(n&&l?-1:1);break;case`end`:p[o]+=f*(n&&l?-1:1);break}return p}async function vu(e,t){t===void 0&&(t={});let{x:n,y:r,platform:i,rects:a,elements:o,strategy:s}=e,{boundary:c=`clippingAncestors`,rootBoundary:l=`viewport`,elementContext:u=`floating`,altBoundary:d=!1,padding:f=0}=Zl(t,e),p=hu(f),m=o[d?u===`floating`?`reference`:`floating`:u],h=gu(await i.getClippingRect({element:await(i.isElement==null?void 0:i.isElement(m))??!0?m:m.contextElement||await(i.getDocumentElement==null?void 0:i.getDocumentElement(o.floating)),boundary:c,rootBoundary:l,strategy:s})),g=u===`floating`?{x:n,y:r,width:a.floating.width,height:a.floating.height}:a.reference,_=await(i.getOffsetParent==null?void 0:i.getOffsetParent(o.floating)),v=await(i.isElement==null?void 0:i.isElement(_))&&await(i.getScale==null?void 0:i.getScale(_))||{x:1,y:1},y=gu(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({elements:o,rect:g,offsetParent:_,strategy:s}):g);return{top:(h.top-y.top+p.top)/v.y,bottom:(y.bottom-h.bottom+p.bottom)/v.y,left:(h.left-y.left+p.left)/v.x,right:(y.right-h.right+p.right)/v.x}}var yu=50,bu=async(e,t,n)=>{let{placement:r=`bottom`,strategy:i=`absolute`,middleware:a=[],platform:o}=n,s=o.detectOverflow?o:{...o,detectOverflow:vu},c=await(o.isRTL==null?void 0:o.isRTL(t)),l=await o.getElementRects({reference:e,floating:t,strategy:i}),{x:u,y:d}=_u(l,r,c),f=r,p=0,m={};for(let n=0;n<a.length;n++){let h=a[n];if(!h)continue;let{name:g,fn:_}=h,{x:v,y,data:b,reset:x}=await _({x:u,y:d,initialPlacement:r,placement:f,strategy:i,middlewareData:m,rects:l,platform:s,elements:{reference:e,floating:t}});u=v??u,d=y??d,m[g]={...m[g],...b},x&&p<yu&&(p++,typeof x==`object`&&(x.placement&&(f=x.placement),x.rects&&(l=x.rects===!0?await o.getElementRects({reference:e,floating:t,strategy:i}):x.rects),{x:u,y:d}=_u(l,f,c)),n=-1)}return{x:u,y:d,placement:f,strategy:i,middlewareData:m}},xu=e=>({name:`arrow`,options:e,async fn(t){let{x:n,y:r,placement:i,rects:a,platform:o,elements:s,middlewareData:c}=t,{element:l,padding:u=0}=Zl(e,t)||{};if(l==null)return{};let d=hu(u),f={x:n,y:r},p=ru(i),m=tu(p),h=await o.getDimensions(l),g=p===`y`,_=g?`top`:`left`,v=g?`bottom`:`right`,y=g?`clientHeight`:`clientWidth`,b=a.reference[m]+a.reference[p]-f[p]-a.floating[m],x=f[p]-a.reference[p],S=await(o.getOffsetParent==null?void 0:o.getOffsetParent(l)),C=S?S[y]:0;(!C||!await(o.isElement==null?void 0:o.isElement(S)))&&(C=s.floating[y]||a.floating[m]);let w=b/2-x/2,T=C/2-h[m]/2-1,E=Wl(d[_],T),D=Wl(d[v],T),O=E,k=C-h[m]-D,A=C/2-h[m]/2+w,ee=Xl(O,A,k),j=!c.arrow&&$l(i)!=null&&A!==ee&&a.reference[m]/2-(A<O?E:D)-h[m]/2<0,te=j?A<O?A-O:A-k:0;return{[p]:f[p]+te,data:{[p]:ee,centerOffset:A-ee-te,...j&&{alignmentOffset:te}},reset:j}}}),Su=function(e){return e===void 0&&(e={}),{name:`flip`,options:e,async fn(t){var n;let{placement:r,middlewareData:i,rects:a,initialPlacement:o,platform:s,elements:c}=t,{mainAxis:l=!0,crossAxis:u=!0,fallbackPlacements:d,fallbackStrategy:f=`bestFit`,fallbackAxisSideDirection:p=`none`,flipAlignment:m=!0,...h}=Zl(e,t);if((n=i.arrow)!=null&&n.alignmentOffset)return{};let g=Ql(r),_=nu(o),v=Ql(o)===o,y=await(s.isRTL==null?void 0:s.isRTL(c.floating)),b=d||(v||!m?[pu(o)]:au(o)),x=p!==`none`;!d&&x&&b.push(...fu(o,m,p,y));let S=[o,...b],C=await s.detectOverflow(t,h),w=[],T=i.flip?.overflows||[];if(l&&w.push(C[g]),u){let e=iu(r,a,y);w.push(C[e[0]],C[e[1]])}if(T=[...T,{placement:r,overflows:w}],!w.every(e=>e<=0)){let e=(i.flip?.index||0)+1,t=S[e];if(t&&(!(u===`alignment`&&_!==nu(t))||T.every(e=>nu(e.placement)===_?e.overflows[0]>0:!0)))return{data:{index:e,overflows:T},reset:{placement:t}};let n=T.filter(e=>e.overflows[0]<=0).sort((e,t)=>e.overflows[1]-t.overflows[1])[0]?.placement;if(!n)switch(f){case`bestFit`:{let e=T.filter(e=>{if(x){let t=nu(e.placement);return t===_||t===`y`}return!0}).map(e=>[e.placement,e.overflows.filter(e=>e>0).reduce((e,t)=>e+t,0)]).sort((e,t)=>e[1]-t[1])[0]?.[0];e&&(n=e);break}case`initialPlacement`:n=o;break}if(r!==n)return{reset:{placement:n}}}return{}}}};function Cu(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function wu(e){return Ul.some(t=>e[t]>=0)}var Tu=function(e){return e===void 0&&(e={}),{name:`hide`,options:e,async fn(t){let{rects:n,platform:r}=t,{strategy:i=`referenceHidden`,...a}=Zl(e,t);switch(i){case`referenceHidden`:{let e=Cu(await r.detectOverflow(t,{...a,elementContext:`reference`}),n.reference);return{data:{referenceHiddenOffsets:e,referenceHidden:wu(e)}}}case`escaped`:{let e=Cu(await r.detectOverflow(t,{...a,altBoundary:!0}),n.floating);return{data:{escapedOffsets:e,escaped:wu(e)}}}default:return{}}}}},Eu=new Set([`left`,`top`]);async function Du(e,t){let{placement:n,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=Ql(n),s=$l(n),c=nu(n)===`y`,l=Eu.has(o)?-1:1,u=a&&c?-1:1,d=Zl(t,e),{mainAxis:f,crossAxis:p,alignmentAxis:m}=typeof d==`number`?{mainAxis:d,crossAxis:0,alignmentAxis:null}:{mainAxis:d.mainAxis||0,crossAxis:d.crossAxis||0,alignmentAxis:d.alignmentAxis};return s&&typeof m==`number`&&(p=s===`end`?m*-1:m),c?{x:p*u,y:f*l}:{x:f*l,y:p*u}}var Ou=function(e){return e===void 0&&(e=0),{name:`offset`,options:e,async fn(t){var n;let{x:r,y:i,placement:a,middlewareData:o}=t,s=await Du(t,e);return a===o.offset?.placement&&(n=o.arrow)!=null&&n.alignmentOffset?{}:{x:r+s.x,y:i+s.y,data:{...s,placement:a}}}}},ku=function(e){return e===void 0&&(e={}),{name:`shift`,options:e,async fn(t){let{x:n,y:r,placement:i,platform:a}=t,{mainAxis:o=!0,crossAxis:s=!1,limiter:c={fn:e=>{let{x:t,y:n}=e;return{x:t,y:n}}},...l}=Zl(e,t),u={x:n,y:r},d=await a.detectOverflow(t,l),f=nu(Ql(i)),p=eu(f),m=u[p],h=u[f];if(o){let e=p===`y`?`top`:`left`,t=p===`y`?`bottom`:`right`,n=m+d[e],r=m-d[t];m=Xl(n,m,r)}if(s){let e=f===`y`?`top`:`left`,t=f===`y`?`bottom`:`right`,n=h+d[e],r=h-d[t];h=Xl(n,h,r)}let g=c.fn({...t,[p]:m,[f]:h});return{...g,data:{x:g.x-n,y:g.y-r,enabled:{[p]:o,[f]:s}}}}}},Au=function(e){return e===void 0&&(e={}),{options:e,fn(t){let{x:n,y:r,placement:i,rects:a,middlewareData:o}=t,{offset:s=0,mainAxis:c=!0,crossAxis:l=!0}=Zl(e,t),u={x:n,y:r},d=nu(i),f=eu(d),p=u[f],m=u[d],h=Zl(s,t),g=typeof h==`number`?{mainAxis:h,crossAxis:0}:{mainAxis:0,crossAxis:0,...h};if(c){let e=f===`y`?`height`:`width`,t=a.reference[f]-a.floating[e]+g.mainAxis,n=a.reference[f]+a.reference[e]-g.mainAxis;p<t?p=t:p>n&&(p=n)}if(l){let e=f===`y`?`width`:`height`,t=Eu.has(Ql(i)),n=a.reference[d]-a.floating[e]+(t&&o.offset?.[d]||0)+(t?0:g.crossAxis),r=a.reference[d]+a.reference[e]+(t?0:o.offset?.[d]||0)-(t?g.crossAxis:0);m<n?m=n:m>r&&(m=r)}return{[f]:p,[d]:m}}}},ju=function(e){return e===void 0&&(e={}),{name:`size`,options:e,async fn(t){var n,r;let{placement:i,rects:a,platform:o,elements:s}=t,{apply:c=()=>{},...l}=Zl(e,t),u=await o.detectOverflow(t,l),d=Ql(i),f=$l(i),p=nu(i)===`y`,{width:m,height:h}=a.floating,g,_;d===`top`||d===`bottom`?(g=d,_=f===(await(o.isRTL==null?void 0:o.isRTL(s.floating))?`start`:`end`)?`left`:`right`):(_=d,g=f===`end`?`top`:`bottom`);let v=h-u.top-u.bottom,y=m-u.left-u.right,b=Wl(h-u[g],v),x=Wl(m-u[_],y),S=!t.middlewareData.shift,C=b,w=x;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(w=y),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(C=v),S&&!f){let e=Gl(u.left,0),t=Gl(u.right,0),n=Gl(u.top,0),r=Gl(u.bottom,0);p?w=m-2*(e!==0||t!==0?e+t:Gl(u.left,u.right)):C=h-2*(n!==0||r!==0?n+r:Gl(u.top,u.bottom))}await c({...t,availableWidth:w,availableHeight:C});let T=await o.getDimensions(s.floating);return m!==T.width||h!==T.height?{reset:{rects:!0}}:{}}}};function Mu(){return typeof window<`u`}function Nu(e){return Iu(e)?(e.nodeName||``).toLowerCase():`#document`}function Pu(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function Fu(e){return((Iu(e)?e.ownerDocument:e.document)||window.document)?.documentElement}function Iu(e){return Mu()?e instanceof Node||e instanceof Pu(e).Node:!1}function Lu(e){return Mu()?e instanceof Element||e instanceof Pu(e).Element:!1}function Ru(e){return Mu()?e instanceof HTMLElement||e instanceof Pu(e).HTMLElement:!1}function zu(e){return!Mu()||typeof ShadowRoot>`u`?!1:e instanceof ShadowRoot||e instanceof Pu(e).ShadowRoot}function Bu(e){let{overflow:t,overflowX:n,overflowY:r,display:i}=Zu(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!==`inline`&&i!==`contents`}function Vu(e){return/^(table|td|th)$/.test(Nu(e))}function Hu(e){try{if(e.matches(`:popover-open`))return!0}catch{}try{return e.matches(`:modal`)}catch{return!1}}var Uu=/transform|translate|scale|rotate|perspective|filter/,Wu=/paint|layout|strict|content/,Gu=e=>!!e&&e!==`none`,Ku;function qu(e){let t=Lu(e)?Zu(e):e;return Gu(t.transform)||Gu(t.translate)||Gu(t.scale)||Gu(t.rotate)||Gu(t.perspective)||!Yu()&&(Gu(t.backdropFilter)||Gu(t.filter))||Uu.test(t.willChange||``)||Wu.test(t.contain||``)}function Ju(e){let t=$u(e);for(;Ru(t)&&!Xu(t);){if(qu(t))return t;if(Hu(t))return null;t=$u(t)}return null}function Yu(){return Ku??=typeof CSS<`u`&&CSS.supports&&CSS.supports(`-webkit-backdrop-filter`,`none`),Ku}function Xu(e){return/^(html|body|#document)$/.test(Nu(e))}function Zu(e){return Pu(e).getComputedStyle(e)}function Qu(e){return Lu(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function $u(e){if(Nu(e)===`html`)return e;let t=e.assignedSlot||e.parentNode||zu(e)&&e.host||Fu(e);return zu(t)?t.host:t}function ed(e){let t=$u(e);return Xu(t)?e.ownerDocument?e.ownerDocument.body:e.body:Ru(t)&&Bu(t)?t:ed(t)}function td(e,t,n){t===void 0&&(t=[]),n===void 0&&(n=!0);let r=ed(e),i=r===e.ownerDocument?.body,a=Pu(r);if(i){let e=nd(a);return t.concat(a,a.visualViewport||[],Bu(r)?r:[],e&&n?td(e):[])}else return t.concat(r,td(r,[],n))}function nd(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function rd(e){let t=Zu(e),n=parseFloat(t.width)||0,r=parseFloat(t.height)||0,i=Ru(e),a=i?e.offsetWidth:n,o=i?e.offsetHeight:r,s=Kl(n)!==a||Kl(r)!==o;return s&&(n=a,r=o),{width:n,height:r,$:s}}function id(e){return Lu(e)?e:e.contextElement}function ad(e){let t=id(e);if(!Ru(t))return Jl(1);let n=t.getBoundingClientRect(),{width:r,height:i,$:a}=rd(t),o=(a?Kl(n.width):n.width)/r,s=(a?Kl(n.height):n.height)/i;return(!o||!Number.isFinite(o))&&(o=1),(!s||!Number.isFinite(s))&&(s=1),{x:o,y:s}}var od=Jl(0);function sd(e){let t=Pu(e);return!Yu()||!t.visualViewport?od:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function cd(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Pu(e)?!1:t}function ld(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);let i=e.getBoundingClientRect(),a=id(e),o=Jl(1);t&&(r?Lu(r)&&(o=ad(r)):o=ad(e));let s=cd(a,n,r)?sd(a):Jl(0),c=(i.left+s.x)/o.x,l=(i.top+s.y)/o.y,u=i.width/o.x,d=i.height/o.y;if(a){let e=Pu(a),t=r&&Lu(r)?Pu(r):r,n=e,i=nd(n);for(;i&&r&&t!==n;){let e=ad(i),t=i.getBoundingClientRect(),r=Zu(i),a=t.left+(i.clientLeft+parseFloat(r.paddingLeft))*e.x,o=t.top+(i.clientTop+parseFloat(r.paddingTop))*e.y;c*=e.x,l*=e.y,u*=e.x,d*=e.y,c+=a,l+=o,n=Pu(i),i=nd(n)}}return gu({width:u,height:d,x:c,y:l})}function ud(e,t){let n=Qu(e).scrollLeft;return t?t.left+n:ld(Fu(e)).left+n}function dd(e,t){let n=e.getBoundingClientRect();return{x:n.left+t.scrollLeft-ud(e,n),y:n.top+t.scrollTop}}function fd(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e,a=i===`fixed`,o=Fu(r),s=t?Hu(t.floating):!1;if(r===o||s&&a)return n;let c={scrollLeft:0,scrollTop:0},l=Jl(1),u=Jl(0),d=Ru(r);if((d||!d&&!a)&&((Nu(r)!==`body`||Bu(o))&&(c=Qu(r)),d)){let e=ld(r);l=ad(r),u.x=e.x+r.clientLeft,u.y=e.y+r.clientTop}let f=o&&!d&&!a?dd(o,c):Jl(0);return{width:n.width*l.x,height:n.height*l.y,x:n.x*l.x-c.scrollLeft*l.x+u.x+f.x,y:n.y*l.y-c.scrollTop*l.y+u.y+f.y}}function pd(e){return Array.from(e.getClientRects())}function md(e){let t=Fu(e),n=Qu(e),r=e.ownerDocument.body,i=Gl(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),a=Gl(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight),o=-n.scrollLeft+ud(e),s=-n.scrollTop;return Zu(r).direction===`rtl`&&(o+=Gl(t.clientWidth,r.clientWidth)-i),{width:i,height:a,x:o,y:s}}var hd=25;function gd(e,t){let n=Pu(e),r=Fu(e),i=n.visualViewport,a=r.clientWidth,o=r.clientHeight,s=0,c=0;if(i){a=i.width,o=i.height;let e=Yu();(!e||e&&t===`fixed`)&&(s=i.offsetLeft,c=i.offsetTop)}let l=ud(r);if(l<=0){let e=r.ownerDocument,t=e.body,n=getComputedStyle(t),i=e.compatMode===`CSS1Compat`&&parseFloat(n.marginLeft)+parseFloat(n.marginRight)||0,o=Math.abs(r.clientWidth-t.clientWidth-i);o<=hd&&(a-=o)}else l<=hd&&(a+=l);return{width:a,height:o,x:s,y:c}}function _d(e,t){let n=ld(e,!0,t===`fixed`),r=n.top+e.clientTop,i=n.left+e.clientLeft,a=Ru(e)?ad(e):Jl(1);return{width:e.clientWidth*a.x,height:e.clientHeight*a.y,x:i*a.x,y:r*a.y}}function vd(e,t,n){let r;if(t===`viewport`)r=gd(e,n);else if(t===`document`)r=md(Fu(e));else if(Lu(t))r=_d(t,n);else{let n=sd(e);r={x:t.x-n.x,y:t.y-n.y,width:t.width,height:t.height}}return gu(r)}function yd(e,t){let n=$u(e);return n===t||!Lu(n)||Xu(n)?!1:Zu(n).position===`fixed`||yd(n,t)}function bd(e,t){let n=t.get(e);if(n)return n;let r=td(e,[],!1).filter(e=>Lu(e)&&Nu(e)!==`body`),i=null,a=Zu(e).position===`fixed`,o=a?$u(e):e;for(;Lu(o)&&!Xu(o);){let t=Zu(o),n=qu(o);!n&&t.position===`fixed`&&(i=null),(a?!n&&!i:!n&&t.position===`static`&&i&&(i.position===`absolute`||i.position===`fixed`)||Bu(o)&&!n&&yd(e,o))?r=r.filter(e=>e!==o):i=t,o=$u(o)}return t.set(e,r),r}function xd(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e,a=[...n===`clippingAncestors`?Hu(t)?[]:bd(t,this._c):[].concat(n),r],o=vd(t,a[0],i),s=o.top,c=o.right,l=o.bottom,u=o.left;for(let e=1;e<a.length;e++){let n=vd(t,a[e],i);s=Gl(n.top,s),c=Wl(n.right,c),l=Wl(n.bottom,l),u=Gl(n.left,u)}return{width:c-u,height:l-s,x:u,y:s}}function Sd(e){let{width:t,height:n}=rd(e);return{width:t,height:n}}function Cd(e,t,n){let r=Ru(t),i=Fu(t),a=n===`fixed`,o=ld(e,!0,a,t),s={scrollLeft:0,scrollTop:0},c=Jl(0);function l(){c.x=ud(i)}if(r||!r&&!a)if((Nu(t)!==`body`||Bu(i))&&(s=Qu(t)),r){let e=ld(t,!0,a,t);c.x=e.x+t.clientLeft,c.y=e.y+t.clientTop}else i&&l();a&&!r&&i&&l();let u=i&&!r&&!a?dd(i,s):Jl(0);return{x:o.left+s.scrollLeft-c.x-u.x,y:o.top+s.scrollTop-c.y-u.y,width:o.width,height:o.height}}function wd(e){return Zu(e).position===`static`}function Td(e,t){if(!Ru(e)||Zu(e).position===`fixed`)return null;if(t)return t(e);let n=e.offsetParent;return Fu(e)===n&&(n=n.ownerDocument.body),n}function Ed(e,t){let n=Pu(e);if(Hu(e))return n;if(!Ru(e)){let t=$u(e);for(;t&&!Xu(t);){if(Lu(t)&&!wd(t))return t;t=$u(t)}return n}let r=Td(e,t);for(;r&&Vu(r)&&wd(r);)r=Td(r,t);return r&&Xu(r)&&wd(r)&&!qu(r)?n:r||Ju(e)||n}var Dd=async function(e){let t=this.getOffsetParent||Ed,n=this.getDimensions,r=await n(e.floating);return{reference:Cd(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function Od(e){return Zu(e).direction===`rtl`}var kd={convertOffsetParentRelativeRectToViewportRelativeRect:fd,getDocumentElement:Fu,getClippingRect:xd,getOffsetParent:Ed,getElementRects:Dd,getClientRects:pd,getDimensions:Sd,getScale:ad,isElement:Lu,isRTL:Od};function Ad(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function jd(e,t){let n=null,r,i=Fu(e);function a(){var e;clearTimeout(r),(e=n)==null||e.disconnect(),n=null}function o(s,c){s===void 0&&(s=!1),c===void 0&&(c=1),a();let l=e.getBoundingClientRect(),{left:u,top:d,width:f,height:p}=l;if(s||t(),!f||!p)return;let m=ql(d),h=ql(i.clientWidth-(u+f)),g=ql(i.clientHeight-(d+p)),_=ql(u),v={rootMargin:-m+`px `+-h+`px `+-g+`px `+-_+`px`,threshold:Gl(0,Wl(1,c))||1},y=!0;function b(t){let n=t[0].intersectionRatio;if(n!==c){if(!y)return o();n?o(!1,n):r=setTimeout(()=>{o(!1,1e-7)},1e3)}n===1&&!Ad(l,e.getBoundingClientRect())&&o(),y=!1}try{n=new IntersectionObserver(b,{...v,root:i.ownerDocument})}catch{n=new IntersectionObserver(b,v)}n.observe(e)}return o(!0),a}function Md(e,t,n,r){r===void 0&&(r={});let{ancestorScroll:i=!0,ancestorResize:a=!0,elementResize:o=typeof ResizeObserver==`function`,layoutShift:s=typeof IntersectionObserver==`function`,animationFrame:c=!1}=r,l=id(e),u=i||a?[...l?td(l):[],...t?td(t):[]]:[];u.forEach(e=>{i&&e.addEventListener(`scroll`,n,{passive:!0}),a&&e.addEventListener(`resize`,n)});let d=l&&s?jd(l,n):null,f=-1,p=null;o&&(p=new ResizeObserver(e=>{let[r]=e;r&&r.target===l&&p&&t&&(p.unobserve(t),cancelAnimationFrame(f),f=requestAnimationFrame(()=>{var e;(e=p)==null||e.observe(t)})),n()}),l&&!c&&p.observe(l),t&&p.observe(t));let m,h=c?ld(e):null;c&&g();function g(){let t=ld(e);h&&!Ad(h,t)&&n(),h=t,m=requestAnimationFrame(g)}return n(),()=>{var e;u.forEach(e=>{i&&e.removeEventListener(`scroll`,n),a&&e.removeEventListener(`resize`,n)}),d?.(),(e=p)==null||e.disconnect(),p=null,c&&cancelAnimationFrame(m)}}var Nd=Ou,Pd=ku,Fd=Su,Id=ju,Ld=Tu,Rd=xu,zd=Au,Bd=(e,t,n)=>{let r=new Map,i={platform:kd,...n},a={...i.platform,_c:r};return bu(e,t,{...i,platform:a})},Vd=typeof document<`u`?F.useLayoutEffect:function(){};function Hd(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e==`function`&&e.toString()===t.toString())return!0;let n,r,i;if(e&&t&&typeof e==`object`){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(r=n;r--!==0;)if(!Hd(e[r],t[r]))return!1;return!0}if(i=Object.keys(e),n=i.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(t,i[r]))return!1;for(r=n;r--!==0;){let n=i[r];if(!(n===`_owner`&&e.$$typeof)&&!Hd(e[n],t[n]))return!1}return!0}return e!==e&&t!==t}function Ud(e){return typeof window>`u`?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Wd(e,t){let n=Ud(e);return Math.round(t*n)/n}function Gd(e){let t=F.useRef(e);return Vd(()=>{t.current=e}),t}function Kd(e){e===void 0&&(e={});let{placement:t=`bottom`,strategy:n=`absolute`,middleware:r=[],platform:i,elements:{reference:a,floating:o}={},transform:s=!0,whileElementsMounted:c,open:l}=e,[u,d]=F.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[f,p]=F.useState(r);Hd(f,r)||p(r);let[m,h]=F.useState(null),[g,_]=F.useState(null),v=F.useCallback(e=>{e!==S.current&&(S.current=e,h(e))},[]),y=F.useCallback(e=>{e!==C.current&&(C.current=e,_(e))},[]),b=a||m,x=o||g,S=F.useRef(null),C=F.useRef(null),w=F.useRef(u),T=c!=null,E=Gd(c),D=Gd(i),O=Gd(l),k=F.useCallback(()=>{if(!S.current||!C.current)return;let e={placement:t,strategy:n,middleware:f};D.current&&(e.platform=D.current),Bd(S.current,C.current,e).then(e=>{let t={...e,isPositioned:O.current!==!1};A.current&&!Hd(w.current,t)&&(w.current=t,vo.flushSync(()=>{d(t)}))})},[f,t,n,D,O]);Vd(()=>{l===!1&&w.current.isPositioned&&(w.current.isPositioned=!1,d(e=>({...e,isPositioned:!1})))},[l]);let A=F.useRef(!1);Vd(()=>(A.current=!0,()=>{A.current=!1}),[]),Vd(()=>{if(b&&(S.current=b),x&&(C.current=x),b&&x){if(E.current)return E.current(b,x,k);k()}},[b,x,k,E,T]);let ee=F.useMemo(()=>({reference:S,floating:C,setReference:v,setFloating:y}),[v,y]),j=F.useMemo(()=>({reference:b,floating:x}),[b,x]),te=F.useMemo(()=>{let e={position:n,left:0,top:0};if(!j.floating)return e;let t=Wd(j.floating,u.x),r=Wd(j.floating,u.y);return s?{...e,transform:`translate(`+t+`px, `+r+`px)`,...Ud(j.floating)>=1.5&&{willChange:`transform`}}:{position:n,left:t,top:r}},[n,s,j.floating,u.x,u.y]);return F.useMemo(()=>({...u,update:k,refs:ee,elements:j,floatingStyles:te}),[u,k,ee,j,te])}var qd=e=>{function t(e){return{}.hasOwnProperty.call(e,`current`)}return{name:`arrow`,options:e,fn(n){let{element:r,padding:i}=typeof e==`function`?e(n):e;return r&&t(r)?r.current==null?{}:Rd({element:r.current,padding:i}).fn(n):r?Rd({element:r,padding:i}).fn(n):{}}}},Jd=(e,t)=>{let n=Nd(e);return{name:n.name,fn:n.fn,options:[e,t]}},Yd=(e,t)=>{let n=Pd(e);return{name:n.name,fn:n.fn,options:[e,t]}},Xd=(e,t)=>({fn:zd(e).fn,options:[e,t]}),Zd=(e,t)=>{let n=Fd(e);return{name:n.name,fn:n.fn,options:[e,t]}},Qd=(e,t)=>{let n=Id(e);return{name:n.name,fn:n.fn,options:[e,t]}},$d=(e,t)=>{let n=Ld(e);return{name:n.name,fn:n.fn,options:[e,t]}},ef=(e,t)=>{let n=qd(e);return{name:n.name,fn:n.fn,options:[e,t]}},tf=`Arrow`,nf=F.forwardRef((e,t)=>{let{children:n,width:r=10,height:i=5,...a}=e;return(0,L.jsx)(yo.svg,{...a,ref:t,width:r,height:i,viewBox:`0 0 30 10`,preserveAspectRatio:`none`,children:e.asChild?n:(0,L.jsx)(`polygon`,{points:`0,0 30,0 15,10`})})});nf.displayName=tf;var rf=nf,af=`Popper`,[of,sf]=Eo(af),[cf,lf]=of(af),uf=e=>{let{__scopePopper:t,children:n}=e,[r,i]=F.useState(null);return(0,L.jsx)(cf,{scope:t,anchor:r,onAnchorChange:i,children:n})};uf.displayName=af;var df=`PopperAnchor`,ff=F.forwardRef((e,t)=>{let{__scopePopper:n,virtualRef:r,...i}=e,a=lf(df,n),o=F.useRef(null),s=co(t,o),c=F.useRef(null);return F.useEffect(()=>{let e=c.current;c.current=r?.current||o.current,e!==c.current&&a.onAnchorChange(c.current)}),r?null:(0,L.jsx)(yo.div,{...i,ref:s})});ff.displayName=df;var pf=`PopperContent`,[mf,hf]=of(pf),gf=F.forwardRef((e,t)=>{let{__scopePopper:n,side:r=`bottom`,sideOffset:i=0,align:a=`center`,alignOffset:o=0,arrowPadding:s=0,avoidCollisions:c=!0,collisionBoundary:l=[],collisionPadding:u=0,sticky:d=`partial`,hideWhenDetached:f=!1,updatePositionStrategy:p=`optimized`,onPlaced:m,...h}=e,g=lf(pf,n),[_,v]=F.useState(null),y=co(t,e=>v(e)),[b,x]=F.useState(null),S=Hl(b),C=S?.width??0,w=S?.height??0,T=r+(a===`center`?``:`-`+a),E=typeof u==`number`?u:{top:0,right:0,bottom:0,left:0,...u},D=Array.isArray(l)?l:[l],O=D.length>0,k={padding:E,boundary:D.filter(bf),altBoundary:O},{refs:A,floatingStyles:ee,placement:j,isPositioned:te,middlewareData:M}=Kd({strategy:`fixed`,placement:T,whileElementsMounted:(...e)=>Md(...e,{animationFrame:p===`always`}),elements:{reference:g.anchor},middleware:[Jd({mainAxis:i+w,alignmentAxis:o}),c&&Yd({mainAxis:!0,crossAxis:!1,limiter:d===`partial`?Xd():void 0,...k}),c&&Zd({...k}),Qd({...k,apply:({elements:e,rects:t,availableWidth:n,availableHeight:r})=>{let{width:i,height:a}=t.reference,o=e.floating.style;o.setProperty(`--radix-popper-available-width`,`${n}px`),o.setProperty(`--radix-popper-available-height`,`${r}px`),o.setProperty(`--radix-popper-anchor-width`,`${i}px`),o.setProperty(`--radix-popper-anchor-height`,`${a}px`)}}),b&&ef({element:b,padding:s}),xf({arrowWidth:C,arrowHeight:w}),f&&$d({strategy:`referenceHidden`,...k})]}),[ne,N]=Sf(j),re=ts(m);ko(()=>{te&&re?.()},[te,re]);let ie=M.arrow?.x,ae=M.arrow?.y,oe=M.arrow?.centerOffset!==0,[se,ce]=F.useState();return ko(()=>{_&&ce(window.getComputedStyle(_).zIndex)},[_]),(0,L.jsx)(`div`,{ref:A.setFloating,"data-radix-popper-content-wrapper":``,style:{...ee,transform:te?ee.transform:`translate(0, -200%)`,minWidth:`max-content`,zIndex:se,"--radix-popper-transform-origin":[M.transformOrigin?.x,M.transformOrigin?.y].join(` `),...M.hide?.referenceHidden&&{visibility:`hidden`,pointerEvents:`none`}},dir:e.dir,children:(0,L.jsx)(mf,{scope:n,placedSide:ne,onArrowChange:x,arrowX:ie,arrowY:ae,shouldHideArrow:oe,children:(0,L.jsx)(yo.div,{"data-side":ne,"data-align":N,...h,ref:y,style:{...h.style,animation:te?void 0:`none`}})})})});gf.displayName=pf;var _f=`PopperArrow`,vf={top:`bottom`,right:`left`,bottom:`top`,left:`right`},yf=F.forwardRef(function(e,t){let{__scopePopper:n,...r}=e,i=hf(_f,n),a=vf[i.placedSide];return(0,L.jsx)(`span`,{ref:i.onArrowChange,style:{position:`absolute`,left:i.arrowX,top:i.arrowY,[a]:0,transformOrigin:{top:``,right:`0 0`,bottom:`center 0`,left:`100% 0`}[i.placedSide],transform:{top:`translateY(100%)`,right:`translateY(50%) rotate(90deg) translateX(-50%)`,bottom:`rotate(180deg)`,left:`translateY(50%) rotate(-90deg) translateX(50%)`}[i.placedSide],visibility:i.shouldHideArrow?`hidden`:void 0},children:(0,L.jsx)(rf,{...r,ref:t,style:{...r.style,display:`block`}})})});yf.displayName=_f;function bf(e){return e!==null}var xf=e=>({name:`transformOrigin`,options:e,fn(t){let{placement:n,rects:r,middlewareData:i}=t,a=i.arrow?.centerOffset!==0,o=a?0:e.arrowWidth,s=a?0:e.arrowHeight,[c,l]=Sf(n),u={start:`0%`,center:`50%`,end:`100%`}[l],d=(i.arrow?.x??0)+o/2,f=(i.arrow?.y??0)+s/2,p=``,m=``;return c===`bottom`?(p=a?u:`${d}px`,m=`${-s}px`):c===`top`?(p=a?u:`${d}px`,m=`${r.floating.height+s}px`):c===`right`?(p=`${-s}px`,m=a?u:`${f}px`):c===`left`&&(p=`${r.floating.width+s}px`,m=a?u:`${f}px`),{data:{x:p,y:m}}}});function Sf(e){let[t,n=`center`]=e.split(`-`);return[t,n]}var Cf=uf,wf=ff,Tf=gf,Ef=yf,Df=`Popover`,[Of,kf]=Eo(Df,[sf]),Af=sf(),[jf,Mf]=Of(Df),Nf=e=>{let{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:a,modal:o=!1}=e,s=Af(t),c=F.useRef(null),[l,u]=F.useState(!1),[d,f]=jo({prop:r,defaultProp:i??!1,onChange:a,caller:Df});return(0,L.jsx)(Cf,{...s,children:(0,L.jsx)(jf,{scope:t,contentId:Vo(),triggerRef:c,open:d,onOpenChange:f,onOpenToggle:F.useCallback(()=>f(e=>!e),[f]),hasCustomAnchor:l,onCustomAnchorAdd:F.useCallback(()=>u(!0),[]),onCustomAnchorRemove:F.useCallback(()=>u(!1),[]),modal:o,children:n})})};Nf.displayName=Df;var Pf=`PopoverAnchor`,Ff=F.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=Mf(Pf,n),a=Af(n),{onCustomAnchorAdd:o,onCustomAnchorRemove:s}=i;return F.useEffect(()=>(o(),()=>s()),[o,s]),(0,L.jsx)(wf,{...a,...r,ref:t})});Ff.displayName=Pf;var If=`PopoverTrigger`,Lf=F.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=Mf(If,n),a=Af(n),o=co(t,i.triggerRef),s=(0,L.jsx)(yo.button,{type:`button`,"aria-haspopup":`dialog`,"aria-expanded":i.open,"aria-controls":i.contentId,"data-state":Qf(i.open),...r,ref:o,onClick:Oo(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?s:(0,L.jsx)(wf,{asChild:!0,...a,children:s})});Lf.displayName=If;var Rf=`PopoverPortal`,[zf,Bf]=Of(Rf,{forceMount:void 0}),Vf=e=>{let{__scopePopover:t,forceMount:n,children:r,container:i}=e,a=Mf(Rf,t);return(0,L.jsx)(zf,{scope:t,forceMount:n,children:(0,L.jsx)(Fo,{present:n||a.open,children:(0,L.jsx)(Ns,{asChild:!0,container:i,children:r})})})};Vf.displayName=Rf;var Hf=`PopoverContent`,Uf=F.forwardRef((e,t)=>{let n=Bf(Hf,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,a=Mf(Hf,e.__scopePopover);return(0,L.jsx)(Fo,{present:r||a.open,children:a.modal?(0,L.jsx)(Gf,{...i,ref:t}):(0,L.jsx)(Kf,{...i,ref:t})})});Uf.displayName=Hf;var Wf=lo(`PopoverContent.RemoveScroll`),Gf=F.forwardRef((e,t)=>{let n=Mf(Hf,e.__scopePopover),r=F.useRef(null),i=co(t,r),a=F.useRef(!1);return F.useEffect(()=>{let e=r.current;if(e)return el(e)},[]),(0,L.jsx)(Gc,{as:Wf,allowPinchZoom:!0,children:(0,L.jsx)(qf,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Oo(e.onCloseAutoFocus,e=>{e.preventDefault(),a.current||n.triggerRef.current?.focus()}),onPointerDownOutside:Oo(e.onPointerDownOutside,e=>{let t=e.detail.originalEvent,n=t.button===0&&t.ctrlKey===!0;a.current=t.button===2||n},{checkForDefaultPrevented:!1}),onFocusOutside:Oo(e.onFocusOutside,e=>e.preventDefault(),{checkForDefaultPrevented:!1})})})}),Kf=F.forwardRef((e,t)=>{let n=Mf(Hf,e.__scopePopover),r=F.useRef(!1),i=F.useRef(!1);return(0,L.jsx)(qf,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:t=>{e.onCloseAutoFocus?.(t),t.defaultPrevented||(r.current||n.triggerRef.current?.focus(),t.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:t=>{e.onInteractOutside?.(t),t.defaultPrevented||(r.current=!0,t.detail.originalEvent.type===`pointerdown`&&(i.current=!0));let a=t.target;n.triggerRef.current?.contains(a)&&t.preventDefault(),t.detail.originalEvent.type===`focusin`&&i.current&&t.preventDefault()}})}),qf=F.forwardRef((e,t)=>{let{__scopePopover:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:a,disableOutsidePointerEvents:o,onEscapeKeyDown:s,onPointerDownOutside:c,onFocusOutside:l,onInteractOutside:u,...d}=e,f=Mf(Hf,n),p=Af(n);return Fs(),(0,L.jsx)(bs,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:a,children:(0,L.jsx)(ls,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:u,onEscapeKeyDown:s,onPointerDownOutside:c,onFocusOutside:l,onDismiss:()=>f.onOpenChange(!1),children:(0,L.jsx)(Tf,{"data-state":Qf(f.open),role:`dialog`,id:f.contentId,...p,...d,ref:t,style:{...d.style,"--radix-popover-content-transform-origin":`var(--radix-popper-transform-origin)`,"--radix-popover-content-available-width":`var(--radix-popper-available-width)`,"--radix-popover-content-available-height":`var(--radix-popper-available-height)`,"--radix-popover-trigger-width":`var(--radix-popper-anchor-width)`,"--radix-popover-trigger-height":`var(--radix-popper-anchor-height)`}})})})}),Jf=`PopoverClose`,Yf=F.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=Mf(Jf,n);return(0,L.jsx)(yo.button,{type:`button`,...r,ref:t,onClick:Oo(e.onClick,()=>i.onOpenChange(!1))})});Yf.displayName=Jf;var Xf=`PopoverArrow`,Zf=F.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=Af(n);return(0,L.jsx)(Ef,{...i,...r,ref:t})});Zf.displayName=Xf;function Qf(e){return e?`open`:`closed`}var $f=Nf,ep=Lf,tp=Vf,np=Uf,rp=Yf,[ip,eee]=Eo(`Tooltip`,[sf]),ap=sf(),op=`TooltipProvider`,sp=700,cp=`tooltip.open`,[lp,up]=ip(op),dp=e=>{let{__scopeTooltip:t,delayDuration:n=sp,skipDelayDuration:r=300,disableHoverableContent:i=!1,children:a}=e,o=F.useRef(!0),s=F.useRef(!1),c=F.useRef(0);return F.useEffect(()=>{let e=c.current;return()=>window.clearTimeout(e)},[]),(0,L.jsx)(lp,{scope:t,isOpenDelayedRef:o,delayDuration:n,onOpen:F.useCallback(()=>{window.clearTimeout(c.current),o.current=!1},[]),onClose:F.useCallback(()=>{window.clearTimeout(c.current),c.current=window.setTimeout(()=>o.current=!0,r)},[r]),isPointerInTransitRef:s,onPointerInTransitChange:F.useCallback(e=>{s.current=e},[]),disableHoverableContent:i,children:a})};dp.displayName=op;var fp=`Tooltip`,[pp,mp]=ip(fp),hp=e=>{let{__scopeTooltip:t,children:n,open:r,defaultOpen:i,onOpenChange:a,disableHoverableContent:o,delayDuration:s}=e,c=up(fp,e.__scopeTooltip),l=ap(t),[u,d]=F.useState(null),f=Vo(),p=F.useRef(0),m=o??c.disableHoverableContent,h=s??c.delayDuration,g=F.useRef(!1),[_,v]=jo({prop:r,defaultProp:i??!1,onChange:e=>{e?(c.onOpen(),document.dispatchEvent(new CustomEvent(cp))):c.onClose(),a?.(e)},caller:fp}),y=F.useMemo(()=>_?g.current?`delayed-open`:`instant-open`:`closed`,[_]),b=F.useCallback(()=>{window.clearTimeout(p.current),p.current=0,g.current=!1,v(!0)},[v]),x=F.useCallback(()=>{window.clearTimeout(p.current),p.current=0,v(!1)},[v]),S=F.useCallback(()=>{window.clearTimeout(p.current),p.current=window.setTimeout(()=>{g.current=!0,v(!0),p.current=0},h)},[h,v]);return F.useEffect(()=>()=>{p.current&&=(window.clearTimeout(p.current),0)},[]),(0,L.jsx)(Cf,{...l,children:(0,L.jsx)(pp,{scope:t,contentId:f,open:_,stateAttribute:y,trigger:u,onTriggerChange:d,onTriggerEnter:F.useCallback(()=>{c.isOpenDelayedRef.current?S():b()},[c.isOpenDelayedRef,S,b]),onTriggerLeave:F.useCallback(()=>{m?x():(window.clearTimeout(p.current),p.current=0)},[x,m]),onOpen:b,onClose:x,disableHoverableContent:m,children:n})})};hp.displayName=fp;var gp=`TooltipTrigger`,_p=F.forwardRef((e,t)=>{let{__scopeTooltip:n,...r}=e,i=mp(gp,n),a=up(gp,n),o=ap(n),s=co(t,F.useRef(null),i.onTriggerChange),c=F.useRef(!1),l=F.useRef(!1),u=F.useCallback(()=>c.current=!1,[]);return F.useEffect(()=>()=>document.removeEventListener(`pointerup`,u),[u]),(0,L.jsx)(wf,{asChild:!0,...o,children:(0,L.jsx)(yo.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...r,ref:s,onPointerMove:Oo(e.onPointerMove,e=>{e.pointerType!==`touch`&&!l.current&&!a.isPointerInTransitRef.current&&(i.onTriggerEnter(),l.current=!0)}),onPointerLeave:Oo(e.onPointerLeave,()=>{i.onTriggerLeave(),l.current=!1}),onPointerDown:Oo(e.onPointerDown,()=>{i.open&&i.onClose(),c.current=!0,document.addEventListener(`pointerup`,u,{once:!0})}),onFocus:Oo(e.onFocus,()=>{c.current||i.onOpen()}),onBlur:Oo(e.onBlur,i.onClose),onClick:Oo(e.onClick,i.onClose)})})});_p.displayName=gp;var vp=`TooltipPortal`,[yp,bp]=ip(vp,{forceMount:void 0}),xp=e=>{let{__scopeTooltip:t,forceMount:n,children:r,container:i}=e,a=mp(vp,t);return(0,L.jsx)(yp,{scope:t,forceMount:n,children:(0,L.jsx)(Fo,{present:n||a.open,children:(0,L.jsx)(Ns,{asChild:!0,container:i,children:r})})})};xp.displayName=vp;var Sp=`TooltipContent`,Cp=F.forwardRef((e,t)=>{let n=bp(Sp,e.__scopeTooltip),{forceMount:r=n.forceMount,side:i=`top`,...a}=e,o=mp(Sp,e.__scopeTooltip);return(0,L.jsx)(Fo,{present:r||o.open,children:o.disableHoverableContent?(0,L.jsx)(Op,{side:i,...a,ref:t}):(0,L.jsx)(wp,{side:i,...a,ref:t})})}),wp=F.forwardRef((e,t)=>{let n=mp(Sp,e.__scopeTooltip),r=up(Sp,e.__scopeTooltip),i=F.useRef(null),a=co(t,i),[o,s]=F.useState(null),{trigger:c,onClose:l}=n,u=i.current,{onPointerInTransitChange:d}=r,f=F.useCallback(()=>{s(null),d(!1)},[d]),p=F.useCallback((e,t)=>{let n=e.currentTarget,r={x:e.clientX,y:e.clientY},i=Mp(r,jp(r,n.getBoundingClientRect())),a=Np(t.getBoundingClientRect());s(Fp([...i,...a])),d(!0)},[d]);return F.useEffect(()=>()=>f(),[f]),F.useEffect(()=>{if(c&&u){let e=e=>p(e,u),t=e=>p(e,c);return c.addEventListener(`pointerleave`,e),u.addEventListener(`pointerleave`,t),()=>{c.removeEventListener(`pointerleave`,e),u.removeEventListener(`pointerleave`,t)}}},[c,u,p,f]),F.useEffect(()=>{if(o){let e=e=>{let t=e.target,n={x:e.clientX,y:e.clientY},r=c?.contains(t)||u?.contains(t),i=!Pp(n,o);r?f():i&&(f(),l())};return document.addEventListener(`pointermove`,e),()=>document.removeEventListener(`pointermove`,e)}},[c,u,o,l,f]),(0,L.jsx)(Op,{...e,ref:a})}),[Tp,Ep]=ip(fp,{isInside:!1}),Dp=mo(`TooltipContent`),Op=F.forwardRef((e,t)=>{let{__scopeTooltip:n,children:r,"aria-label":i,onEscapeKeyDown:a,onPointerDownOutside:o,...s}=e,c=mp(Sp,n),l=ap(n),{onClose:u}=c;return F.useEffect(()=>(document.addEventListener(cp,u),()=>document.removeEventListener(cp,u)),[u]),F.useEffect(()=>{if(c.trigger){let e=e=>{e.target?.contains(c.trigger)&&u()};return window.addEventListener(`scroll`,e,{capture:!0}),()=>window.removeEventListener(`scroll`,e,{capture:!0})}},[c.trigger,u]),(0,L.jsx)(ls,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:a,onPointerDownOutside:o,onFocusOutside:e=>e.preventDefault(),onDismiss:u,children:(0,L.jsxs)(Tf,{"data-state":c.stateAttribute,...l,...s,ref:t,style:{...s.style,"--radix-tooltip-content-transform-origin":`var(--radix-popper-transform-origin)`,"--radix-tooltip-content-available-width":`var(--radix-popper-available-width)`,"--radix-tooltip-content-available-height":`var(--radix-popper-available-height)`,"--radix-tooltip-trigger-width":`var(--radix-popper-anchor-width)`,"--radix-tooltip-trigger-height":`var(--radix-popper-anchor-height)`},children:[(0,L.jsx)(Dp,{children:r}),(0,L.jsx)(Tp,{scope:n,isInside:!0,children:(0,L.jsx)(wo,{id:c.contentId,role:`tooltip`,children:i||r})})]})})});Cp.displayName=Sp;var kp=`TooltipArrow`,Ap=F.forwardRef((e,t)=>{let{__scopeTooltip:n,...r}=e,i=ap(n);return Ep(kp,n).isInside?null:(0,L.jsx)(Ef,{...i,...r,ref:t})});Ap.displayName=kp;function jp(e,t){let n=Math.abs(t.top-e.y),r=Math.abs(t.bottom-e.y),i=Math.abs(t.right-e.x),a=Math.abs(t.left-e.x);switch(Math.min(n,r,i,a)){case a:return`left`;case i:return`right`;case n:return`top`;case r:return`bottom`;default:throw Error(`unreachable`)}}function Mp(e,t,n=5){let r=[];switch(t){case`top`:r.push({x:e.x-n,y:e.y+n},{x:e.x+n,y:e.y+n});break;case`bottom`:r.push({x:e.x-n,y:e.y-n},{x:e.x+n,y:e.y-n});break;case`left`:r.push({x:e.x+n,y:e.y-n},{x:e.x+n,y:e.y+n});break;case`right`:r.push({x:e.x-n,y:e.y-n},{x:e.x-n,y:e.y+n});break}return r}function Np(e){let{top:t,right:n,bottom:r,left:i}=e;return[{x:i,y:t},{x:n,y:t},{x:n,y:r},{x:i,y:r}]}function Pp(e,t){let{x:n,y:r}=e,i=!1;for(let e=0,a=t.length-1;e<t.length;a=e++){let o=t[e],s=t[a],c=o.x,l=o.y,u=s.x,d=s.y;l>r!=d>r&&n<(u-c)*(r-l)/(d-l)+c&&(i=!i)}return i}function Fp(e){let t=e.slice();return t.sort((e,t)=>e.x<t.x?-1:e.x>t.x?1:e.y<t.y?-1:+(e.y>t.y)),Ip(t)}function Ip(e){if(e.length<=1)return e.slice();let t=[];for(let n=0;n<e.length;n++){let r=e[n];for(;t.length>=2;){let e=t[t.length-1],n=t[t.length-2];if((e.x-n.x)*(r.y-n.y)>=(e.y-n.y)*(r.x-n.x))t.pop();else break}t.push(r)}t.pop();let n=[];for(let t=e.length-1;t>=0;t--){let r=e[t];for(;n.length>=2;){let e=n[n.length-1],t=n[n.length-2];if((e.x-t.x)*(r.y-t.y)>=(e.y-t.y)*(r.x-t.x))n.pop();else break}n.push(r)}return n.pop(),t.length===1&&n.length===1&&t[0].x===n[0].x&&t[0].y===n[0].y?t:t.concat(n)}var Lp=dp,Rp=hp,zp=_p,Bp=xp,Vp=Cp,Hp=Ap,Up=Ke();function Wp(e){var t,n,r=``;if(typeof e==`string`||typeof e==`number`)r+=e;else if(typeof e==`object`)if(Array.isArray(e)){var i=e.length;for(t=0;t<i;t++)e[t]&&(n=Wp(e[t]))&&(r&&(r+=` `),r+=n)}else for(n in e)e[n]&&(r&&(r+=` `),r+=n);return r}function Gp(){for(var e,t,n=0,r=``,i=arguments.length;n<i;n++)(e=arguments[n])&&(t=Wp(e))&&(r&&(r+=` `),r+=t);return r}var Kp=(e,t)=>{let n=Array(e.length+t.length);for(let t=0;t<e.length;t++)n[t]=e[t];for(let r=0;r<t.length;r++)n[e.length+r]=t[r];return n},qp=(e,t)=>({classGroupId:e,validator:t}),Jp=(e=new Map,t=null,n)=>({nextPart:e,validators:t,classGroupId:n}),Yp=`-`,Xp=[],Zp=`arbitrary..`,Qp=e=>{let t=tm(e),{conflictingClassGroups:n,conflictingClassGroupModifiers:r}=e;return{getClassGroupId:e=>{if(e.startsWith(`[`)&&e.endsWith(`]`))return em(e);let n=e.split(Yp);return $p(n,+(n[0]===``&&n.length>1),t)},getConflictingClassGroupIds:(e,t)=>{if(t){let t=r[e],i=n[e];return t?i?Kp(i,t):t:i||Xp}return n[e]||Xp}}},$p=(e,t,n)=>{if(e.length-t===0)return n.classGroupId;let r=e[t],i=n.nextPart.get(r);if(i){let n=$p(e,t+1,i);if(n)return n}let a=n.validators;if(a===null)return;let o=t===0?e.join(Yp):e.slice(t).join(Yp),s=a.length;for(let e=0;e<s;e++){let t=a[e];if(t.validator(o))return t.classGroupId}},em=e=>e.slice(1,-1).indexOf(`:`)===-1?void 0:(()=>{let t=e.slice(1,-1),n=t.indexOf(`:`),r=t.slice(0,n);return r?Zp+r:void 0})(),tm=e=>{let{theme:t,classGroups:n}=e;return nm(n,t)},nm=(e,t)=>{let n=Jp();for(let r in e){let i=e[r];rm(i,n,r,t)}return n},rm=(e,t,n,r)=>{let i=e.length;for(let a=0;a<i;a++){let i=e[a];im(i,t,n,r)}},im=(e,t,n,r)=>{if(typeof e==`string`){am(e,t,n);return}if(typeof e==`function`){om(e,t,n,r);return}sm(e,t,n,r)},am=(e,t,n)=>{let r=e===``?t:cm(t,e);r.classGroupId=n},om=(e,t,n,r)=>{if(tee(e)){rm(e(r),t,n,r);return}t.validators===null&&(t.validators=[]),t.validators.push(qp(n,e))},sm=(e,t,n,r)=>{let i=Object.entries(e),a=i.length;for(let e=0;e<a;e++){let[a,o]=i[e];rm(o,cm(t,a),n,r)}},cm=(e,t)=>{let n=e,r=t.split(Yp),i=r.length;for(let e=0;e<i;e++){let t=r[e],i=n.nextPart.get(t);i||(i=Jp(),n.nextPart.set(t,i)),n=i}return n},tee=e=>`isThemeGetter`in e&&e.isThemeGetter===!0,nee=e=>{if(e<1)return{get:()=>void 0,set:()=>{}};let t=0,n=Object.create(null),r=Object.create(null),i=(i,a)=>{n[i]=a,t++,t>e&&(t=0,r=n,n=Object.create(null))};return{get(e){let t=n[e];if(t!==void 0)return t;if((t=r[e])!==void 0)return i(e,t),t},set(e,t){e in n?n[e]=t:i(e,t)}}},lm=`!`,um=`:`,ree=[],dm=(e,t,n,r,i)=>({modifiers:e,hasImportantModifier:t,baseClassName:n,maybePostfixModifierPosition:r,isExternal:i}),iee=e=>{let{prefix:t,experimentalParseClassName:n}=e,r=e=>{let t=[],n=0,r=0,i=0,a,o=e.length;for(let s=0;s<o;s++){let o=e[s];if(n===0&&r===0){if(o===um){t.push(e.slice(i,s)),i=s+1;continue}if(o===`/`){a=s;continue}}o===`[`?n++:o===`]`?n--:o===`(`?r++:o===`)`&&r--}let s=t.length===0?e:e.slice(i),c=s,l=!1;s.endsWith(lm)?(c=s.slice(0,-1),l=!0):s.startsWith(lm)&&(c=s.slice(1),l=!0);let u=a&&a>i?a-i:void 0;return dm(t,l,c,u)};if(t){let e=t+um,n=r;r=t=>t.startsWith(e)?n(t.slice(e.length)):dm(ree,!1,t,void 0,!0)}if(n){let e=r;r=t=>n({className:t,parseClassName:e})}return r},aee=e=>{let t=new Map;return e.orderSensitiveModifiers.forEach((e,n)=>{t.set(e,1e6+n)}),e=>{let n=[],r=[];for(let i=0;i<e.length;i++){let a=e[i],o=a[0]===`[`,s=t.has(a);o||s?(r.length>0&&(r.sort(),n.push(...r),r=[]),n.push(a)):r.push(a)}return r.length>0&&(r.sort(),n.push(...r)),n}},oee=e=>({cache:nee(e.cacheSize),parseClassName:iee(e),sortModifiers:aee(e),...Qp(e)}),fm=/\s+/,pm=(e,t)=>{let{parseClassName:n,getClassGroupId:r,getConflictingClassGroupIds:i,sortModifiers:a}=t,o=[],s=e.trim().split(fm),c=``;for(let e=s.length-1;e>=0;--e){let t=s[e],{isExternal:l,modifiers:u,hasImportantModifier:d,baseClassName:f,maybePostfixModifierPosition:p}=n(t);if(l){c=t+(c.length>0?` `+c:c);continue}let m=!!p,h=r(m?f.substring(0,p):f);if(!h){if(!m){c=t+(c.length>0?` `+c:c);continue}if(h=r(f),!h){c=t+(c.length>0?` `+c:c);continue}m=!1}let g=u.length===0?``:u.length===1?u[0]:a(u).join(`:`),_=d?g+lm:g,v=_+h;if(o.indexOf(v)>-1)continue;o.push(v);let y=i(h,m);for(let e=0;e<y.length;++e){let t=y[e];o.push(_+t)}c=t+(c.length>0?` `+c:c)}return c},mm=(...e)=>{let t=0,n,r,i=``;for(;t<e.length;)(n=e[t++])&&(r=hm(n))&&(i&&(i+=` `),i+=r);return i},hm=e=>{if(typeof e==`string`)return e;let t,n=``;for(let r=0;r<e.length;r++)e[r]&&(t=hm(e[r]))&&(n&&(n+=` `),n+=t);return n},gm=(e,...t)=>{let n,r,i,a,o=o=>(n=oee(t.reduce((e,t)=>t(e),e())),r=n.cache.get,i=n.cache.set,a=s,s(o)),s=e=>{let t=r(e);if(t)return t;let a=pm(e,n);return i(e,a),a};return a=o,(...e)=>a(mm(...e))},_m=[],vm=e=>{let t=t=>t[e]||_m;return t.isThemeGetter=!0,t},ym=/^\[(?:(\w[\w-]*):)?(.+)\]$/i,bm=/^\((?:(\w[\w-]*):)?(.+)\)$/i,xm=/^\d+(?:\.\d+)?\/\d+(?:\.\d+)?$/,Sm=/^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/,Cm=/\d+(%|px|r?em|[sdl]?v([hwib]|min|max)|pt|pc|in|cm|mm|cap|ch|ex|r?lh|cq(w|h|i|b|min|max))|\b(calc|min|max|clamp)\(.+\)|^0$/,wm=/^(rgba?|hsla?|hwb|(ok)?(lab|lch)|color-mix)\(.+\)$/,Tm=/^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/,Em=/^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/,Dm=e=>xm.test(e),Om=e=>!!e&&!Number.isNaN(Number(e)),km=e=>!!e&&Number.isInteger(Number(e)),Am=e=>e.endsWith(`%`)&&Om(e.slice(0,-1)),jm=e=>Sm.test(e),Mm=()=>!0,Nm=e=>Cm.test(e)&&!wm.test(e),Pm=()=>!1,Fm=e=>Tm.test(e),Im=e=>Em.test(e),Lm=e=>!zm(e)&&!Wm(e),Rm=e=>Qm(e,nh,Pm),zm=e=>ym.test(e),Bm=e=>Qm(e,rh,Nm),Vm=e=>Qm(e,ih,Om),see=e=>Qm(e,oh,Mm),cee=e=>Qm(e,ah,Pm),Hm=e=>Qm(e,eh,Pm),lee=e=>Qm(e,th,Im),Um=e=>Qm(e,sh,Fm),Wm=e=>bm.test(e),Gm=e=>$m(e,rh),Km=e=>$m(e,ah),qm=e=>$m(e,eh),Jm=e=>$m(e,nh),Ym=e=>$m(e,th),Xm=e=>$m(e,sh,!0),Zm=e=>$m(e,oh,!0),Qm=(e,t,n)=>{let r=ym.exec(e);return r?r[1]?t(r[1]):n(r[2]):!1},$m=(e,t,n=!1)=>{let r=bm.exec(e);return r?r[1]?t(r[1]):n:!1},eh=e=>e===`position`||e===`percentage`,th=e=>e===`image`||e===`url`,nh=e=>e===`length`||e===`size`||e===`bg-size`,rh=e=>e===`length`,ih=e=>e===`number`,ah=e=>e===`family-name`,oh=e=>e===`number`||e===`weight`,sh=e=>e===`shadow`,ch=gm(()=>{let e=vm(`color`),t=vm(`font`),n=vm(`text`),r=vm(`font-weight`),i=vm(`tracking`),a=vm(`leading`),o=vm(`breakpoint`),s=vm(`container`),c=vm(`spacing`),l=vm(`radius`),u=vm(`shadow`),d=vm(`inset-shadow`),f=vm(`text-shadow`),p=vm(`drop-shadow`),m=vm(`blur`),h=vm(`perspective`),g=vm(`aspect`),_=vm(`ease`),v=vm(`animate`),y=()=>[`auto`,`avoid`,`all`,`avoid-page`,`page`,`left`,`right`,`column`],b=()=>[`center`,`top`,`bottom`,`left`,`right`,`top-left`,`left-top`,`top-right`,`right-top`,`bottom-right`,`right-bottom`,`bottom-left`,`left-bottom`],x=()=>[...b(),Wm,zm],S=()=>[`auto`,`hidden`,`clip`,`visible`,`scroll`],C=()=>[`auto`,`contain`,`none`],w=()=>[Wm,zm,c],T=()=>[Dm,`full`,`auto`,...w()],E=()=>[km,`none`,`subgrid`,Wm,zm],D=()=>[`auto`,{span:[`full`,km,Wm,zm]},km,Wm,zm],O=()=>[km,`auto`,Wm,zm],k=()=>[`auto`,`min`,`max`,`fr`,Wm,zm],A=()=>[`start`,`end`,`center`,`between`,`around`,`evenly`,`stretch`,`baseline`,`center-safe`,`end-safe`],ee=()=>[`start`,`end`,`center`,`stretch`,`center-safe`,`end-safe`],j=()=>[`auto`,...w()],te=()=>[Dm,`auto`,`full`,`dvw`,`dvh`,`lvw`,`lvh`,`svw`,`svh`,`min`,`max`,`fit`,...w()],M=()=>[Dm,`screen`,`full`,`dvw`,`lvw`,`svw`,`min`,`max`,`fit`,...w()],ne=()=>[Dm,`screen`,`full`,`lh`,`dvh`,`lvh`,`svh`,`min`,`max`,`fit`,...w()],N=()=>[e,Wm,zm],re=()=>[...b(),qm,Hm,{position:[Wm,zm]}],ie=()=>[`no-repeat`,{repeat:[``,`x`,`y`,`space`,`round`]}],ae=()=>[`auto`,`cover`,`contain`,Jm,Rm,{size:[Wm,zm]}],oe=()=>[Am,Gm,Bm],se=()=>[``,`none`,`full`,l,Wm,zm],ce=()=>[``,Om,Gm,Bm],le=()=>[`solid`,`dashed`,`dotted`,`double`],ue=()=>[`normal`,`multiply`,`screen`,`overlay`,`darken`,`lighten`,`color-dodge`,`color-burn`,`hard-light`,`soft-light`,`difference`,`exclusion`,`hue`,`saturation`,`color`,`luminosity`],de=()=>[Om,Am,qm,Hm],fe=()=>[``,`none`,m,Wm,zm],pe=()=>[`none`,Om,Wm,zm],me=()=>[`none`,Om,Wm,zm],he=()=>[Om,Wm,zm],ge=()=>[Dm,`full`,...w()];return{cacheSize:500,theme:{animate:[`spin`,`ping`,`pulse`,`bounce`],aspect:[`video`],blur:[jm],breakpoint:[jm],color:[Mm],container:[jm],"drop-shadow":[jm],ease:[`in`,`out`,`in-out`],font:[Lm],"font-weight":[`thin`,`extralight`,`light`,`normal`,`medium`,`semibold`,`bold`,`extrabold`,`black`],"inset-shadow":[jm],leading:[`none`,`tight`,`snug`,`normal`,`relaxed`,`loose`],perspective:[`dramatic`,`near`,`normal`,`midrange`,`distant`,`none`],radius:[jm],shadow:[jm],spacing:[`px`,Om],text:[jm],"text-shadow":[jm],tracking:[`tighter`,`tight`,`normal`,`wide`,`wider`,`widest`]},classGroups:{aspect:[{aspect:[`auto`,`square`,Dm,zm,Wm,g]}],container:[`container`],columns:[{columns:[Om,zm,Wm,s]}],"break-after":[{"break-after":y()}],"break-before":[{"break-before":y()}],"break-inside":[{"break-inside":[`auto`,`avoid`,`avoid-page`,`avoid-column`]}],"box-decoration":[{"box-decoration":[`slice`,`clone`]}],box:[{box:[`border`,`content`]}],display:[`block`,`inline-block`,`inline`,`flex`,`inline-flex`,`table`,`inline-table`,`table-caption`,`table-cell`,`table-column`,`table-column-group`,`table-footer-group`,`table-header-group`,`table-row-group`,`table-row`,`flow-root`,`grid`,`inline-grid`,`contents`,`list-item`,`hidden`],sr:[`sr-only`,`not-sr-only`],float:[{float:[`right`,`left`,`none`,`start`,`end`]}],clear:[{clear:[`left`,`right`,`both`,`none`,`start`,`end`]}],isolation:[`isolate`,`isolation-auto`],"object-fit":[{object:[`contain`,`cover`,`fill`,`none`,`scale-down`]}],"object-position":[{object:x()}],overflow:[{overflow:S()}],"overflow-x":[{"overflow-x":S()}],"overflow-y":[{"overflow-y":S()}],overscroll:[{overscroll:C()}],"overscroll-x":[{"overscroll-x":C()}],"overscroll-y":[{"overscroll-y":C()}],position:[`static`,`fixed`,`absolute`,`relative`,`sticky`],inset:[{inset:T()}],"inset-x":[{"inset-x":T()}],"inset-y":[{"inset-y":T()}],start:[{"inset-s":T(),start:T()}],end:[{"inset-e":T(),end:T()}],"inset-bs":[{"inset-bs":T()}],"inset-be":[{"inset-be":T()}],top:[{top:T()}],right:[{right:T()}],bottom:[{bottom:T()}],left:[{left:T()}],visibility:[`visible`,`invisible`,`collapse`],z:[{z:[km,`auto`,Wm,zm]}],basis:[{basis:[Dm,`full`,`auto`,s,...w()]}],"flex-direction":[{flex:[`row`,`row-reverse`,`col`,`col-reverse`]}],"flex-wrap":[{flex:[`nowrap`,`wrap`,`wrap-reverse`]}],flex:[{flex:[Om,Dm,`auto`,`initial`,`none`,zm]}],grow:[{grow:[``,Om,Wm,zm]}],shrink:[{shrink:[``,Om,Wm,zm]}],order:[{order:[km,`first`,`last`,`none`,Wm,zm]}],"grid-cols":[{"grid-cols":E()}],"col-start-end":[{col:D()}],"col-start":[{"col-start":O()}],"col-end":[{"col-end":O()}],"grid-rows":[{"grid-rows":E()}],"row-start-end":[{row:D()}],"row-start":[{"row-start":O()}],"row-end":[{"row-end":O()}],"grid-flow":[{"grid-flow":[`row`,`col`,`dense`,`row-dense`,`col-dense`]}],"auto-cols":[{"auto-cols":k()}],"auto-rows":[{"auto-rows":k()}],gap:[{gap:w()}],"gap-x":[{"gap-x":w()}],"gap-y":[{"gap-y":w()}],"justify-content":[{justify:[...A(),`normal`]}],"justify-items":[{"justify-items":[...ee(),`normal`]}],"justify-self":[{"justify-self":[`auto`,...ee()]}],"align-content":[{content:[`normal`,...A()]}],"align-items":[{items:[...ee(),{baseline:[``,`last`]}]}],"align-self":[{self:[`auto`,...ee(),{baseline:[``,`last`]}]}],"place-content":[{"place-content":A()}],"place-items":[{"place-items":[...ee(),`baseline`]}],"place-self":[{"place-self":[`auto`,...ee()]}],p:[{p:w()}],px:[{px:w()}],py:[{py:w()}],ps:[{ps:w()}],pe:[{pe:w()}],pbs:[{pbs:w()}],pbe:[{pbe:w()}],pt:[{pt:w()}],pr:[{pr:w()}],pb:[{pb:w()}],pl:[{pl:w()}],m:[{m:j()}],mx:[{mx:j()}],my:[{my:j()}],ms:[{ms:j()}],me:[{me:j()}],mbs:[{mbs:j()}],mbe:[{mbe:j()}],mt:[{mt:j()}],mr:[{mr:j()}],mb:[{mb:j()}],ml:[{ml:j()}],"space-x":[{"space-x":w()}],"space-x-reverse":[`space-x-reverse`],"space-y":[{"space-y":w()}],"space-y-reverse":[`space-y-reverse`],size:[{size:te()}],"inline-size":[{inline:[`auto`,...M()]}],"min-inline-size":[{"min-inline":[`auto`,...M()]}],"max-inline-size":[{"max-inline":[`none`,...M()]}],"block-size":[{block:[`auto`,...ne()]}],"min-block-size":[{"min-block":[`auto`,...ne()]}],"max-block-size":[{"max-block":[`none`,...ne()]}],w:[{w:[s,`screen`,...te()]}],"min-w":[{"min-w":[s,`screen`,`none`,...te()]}],"max-w":[{"max-w":[s,`screen`,`none`,`prose`,{screen:[o]},...te()]}],h:[{h:[`screen`,`lh`,...te()]}],"min-h":[{"min-h":[`screen`,`lh`,`none`,...te()]}],"max-h":[{"max-h":[`screen`,`lh`,...te()]}],"font-size":[{text:[`base`,n,Gm,Bm]}],"font-smoothing":[`antialiased`,`subpixel-antialiased`],"font-style":[`italic`,`not-italic`],"font-weight":[{font:[r,Zm,see]}],"font-stretch":[{"font-stretch":[`ultra-condensed`,`extra-condensed`,`condensed`,`semi-condensed`,`normal`,`semi-expanded`,`expanded`,`extra-expanded`,`ultra-expanded`,Am,zm]}],"font-family":[{font:[Km,cee,t]}],"font-features":[{"font-features":[zm]}],"fvn-normal":[`normal-nums`],"fvn-ordinal":[`ordinal`],"fvn-slashed-zero":[`slashed-zero`],"fvn-figure":[`lining-nums`,`oldstyle-nums`],"fvn-spacing":[`proportional-nums`,`tabular-nums`],"fvn-fraction":[`diagonal-fractions`,`stacked-fractions`],tracking:[{tracking:[i,Wm,zm]}],"line-clamp":[{"line-clamp":[Om,`none`,Wm,Vm]}],leading:[{leading:[a,...w()]}],"list-image":[{"list-image":[`none`,Wm,zm]}],"list-style-position":[{list:[`inside`,`outside`]}],"list-style-type":[{list:[`disc`,`decimal`,`none`,Wm,zm]}],"text-alignment":[{text:[`left`,`center`,`right`,`justify`,`start`,`end`]}],"placeholder-color":[{placeholder:N()}],"text-color":[{text:N()}],"text-decoration":[`underline`,`overline`,`line-through`,`no-underline`],"text-decoration-style":[{decoration:[...le(),`wavy`]}],"text-decoration-thickness":[{decoration:[Om,`from-font`,`auto`,Wm,Bm]}],"text-decoration-color":[{decoration:N()}],"underline-offset":[{"underline-offset":[Om,`auto`,Wm,zm]}],"text-transform":[`uppercase`,`lowercase`,`capitalize`,`normal-case`],"text-overflow":[`truncate`,`text-ellipsis`,`text-clip`],"text-wrap":[{text:[`wrap`,`nowrap`,`balance`,`pretty`]}],indent:[{indent:w()}],"vertical-align":[{align:[`baseline`,`top`,`middle`,`bottom`,`text-top`,`text-bottom`,`sub`,`super`,Wm,zm]}],whitespace:[{whitespace:[`normal`,`nowrap`,`pre`,`pre-line`,`pre-wrap`,`break-spaces`]}],break:[{break:[`normal`,`words`,`all`,`keep`]}],wrap:[{wrap:[`break-word`,`anywhere`,`normal`]}],hyphens:[{hyphens:[`none`,`manual`,`auto`]}],content:[{content:[`none`,Wm,zm]}],"bg-attachment":[{bg:[`fixed`,`local`,`scroll`]}],"bg-clip":[{"bg-clip":[`border`,`padding`,`content`,`text`]}],"bg-origin":[{"bg-origin":[`border`,`padding`,`content`]}],"bg-position":[{bg:re()}],"bg-repeat":[{bg:ie()}],"bg-size":[{bg:ae()}],"bg-image":[{bg:[`none`,{linear:[{to:[`t`,`tr`,`r`,`br`,`b`,`bl`,`l`,`tl`]},km,Wm,zm],radial:[``,Wm,zm],conic:[km,Wm,zm]},Ym,lee]}],"bg-color":[{bg:N()}],"gradient-from-pos":[{from:oe()}],"gradient-via-pos":[{via:oe()}],"gradient-to-pos":[{to:oe()}],"gradient-from":[{from:N()}],"gradient-via":[{via:N()}],"gradient-to":[{to:N()}],rounded:[{rounded:se()}],"rounded-s":[{"rounded-s":se()}],"rounded-e":[{"rounded-e":se()}],"rounded-t":[{"rounded-t":se()}],"rounded-r":[{"rounded-r":se()}],"rounded-b":[{"rounded-b":se()}],"rounded-l":[{"rounded-l":se()}],"rounded-ss":[{"rounded-ss":se()}],"rounded-se":[{"rounded-se":se()}],"rounded-ee":[{"rounded-ee":se()}],"rounded-es":[{"rounded-es":se()}],"rounded-tl":[{"rounded-tl":se()}],"rounded-tr":[{"rounded-tr":se()}],"rounded-br":[{"rounded-br":se()}],"rounded-bl":[{"rounded-bl":se()}],"border-w":[{border:ce()}],"border-w-x":[{"border-x":ce()}],"border-w-y":[{"border-y":ce()}],"border-w-s":[{"border-s":ce()}],"border-w-e":[{"border-e":ce()}],"border-w-bs":[{"border-bs":ce()}],"border-w-be":[{"border-be":ce()}],"border-w-t":[{"border-t":ce()}],"border-w-r":[{"border-r":ce()}],"border-w-b":[{"border-b":ce()}],"border-w-l":[{"border-l":ce()}],"divide-x":[{"divide-x":ce()}],"divide-x-reverse":[`divide-x-reverse`],"divide-y":[{"divide-y":ce()}],"divide-y-reverse":[`divide-y-reverse`],"border-style":[{border:[...le(),`hidden`,`none`]}],"divide-style":[{divide:[...le(),`hidden`,`none`]}],"border-color":[{border:N()}],"border-color-x":[{"border-x":N()}],"border-color-y":[{"border-y":N()}],"border-color-s":[{"border-s":N()}],"border-color-e":[{"border-e":N()}],"border-color-bs":[{"border-bs":N()}],"border-color-be":[{"border-be":N()}],"border-color-t":[{"border-t":N()}],"border-color-r":[{"border-r":N()}],"border-color-b":[{"border-b":N()}],"border-color-l":[{"border-l":N()}],"divide-color":[{divide:N()}],"outline-style":[{outline:[...le(),`none`,`hidden`]}],"outline-offset":[{"outline-offset":[Om,Wm,zm]}],"outline-w":[{outline:[``,Om,Gm,Bm]}],"outline-color":[{outline:N()}],shadow:[{shadow:[``,`none`,u,Xm,Um]}],"shadow-color":[{shadow:N()}],"inset-shadow":[{"inset-shadow":[`none`,d,Xm,Um]}],"inset-shadow-color":[{"inset-shadow":N()}],"ring-w":[{ring:ce()}],"ring-w-inset":[`ring-inset`],"ring-color":[{ring:N()}],"ring-offset-w":[{"ring-offset":[Om,Bm]}],"ring-offset-color":[{"ring-offset":N()}],"inset-ring-w":[{"inset-ring":ce()}],"inset-ring-color":[{"inset-ring":N()}],"text-shadow":[{"text-shadow":[`none`,f,Xm,Um]}],"text-shadow-color":[{"text-shadow":N()}],opacity:[{opacity:[Om,Wm,zm]}],"mix-blend":[{"mix-blend":[...ue(),`plus-darker`,`plus-lighter`]}],"bg-blend":[{"bg-blend":ue()}],"mask-clip":[{"mask-clip":[`border`,`padding`,`content`,`fill`,`stroke`,`view`]},`mask-no-clip`],"mask-composite":[{mask:[`add`,`subtract`,`intersect`,`exclude`]}],"mask-image-linear-pos":[{"mask-linear":[Om]}],"mask-image-linear-from-pos":[{"mask-linear-from":de()}],"mask-image-linear-to-pos":[{"mask-linear-to":de()}],"mask-image-linear-from-color":[{"mask-linear-from":N()}],"mask-image-linear-to-color":[{"mask-linear-to":N()}],"mask-image-t-from-pos":[{"mask-t-from":de()}],"mask-image-t-to-pos":[{"mask-t-to":de()}],"mask-image-t-from-color":[{"mask-t-from":N()}],"mask-image-t-to-color":[{"mask-t-to":N()}],"mask-image-r-from-pos":[{"mask-r-from":de()}],"mask-image-r-to-pos":[{"mask-r-to":de()}],"mask-image-r-from-color":[{"mask-r-from":N()}],"mask-image-r-to-color":[{"mask-r-to":N()}],"mask-image-b-from-pos":[{"mask-b-from":de()}],"mask-image-b-to-pos":[{"mask-b-to":de()}],"mask-image-b-from-color":[{"mask-b-from":N()}],"mask-image-b-to-color":[{"mask-b-to":N()}],"mask-image-l-from-pos":[{"mask-l-from":de()}],"mask-image-l-to-pos":[{"mask-l-to":de()}],"mask-image-l-from-color":[{"mask-l-from":N()}],"mask-image-l-to-color":[{"mask-l-to":N()}],"mask-image-x-from-pos":[{"mask-x-from":de()}],"mask-image-x-to-pos":[{"mask-x-to":de()}],"mask-image-x-from-color":[{"mask-x-from":N()}],"mask-image-x-to-color":[{"mask-x-to":N()}],"mask-image-y-from-pos":[{"mask-y-from":de()}],"mask-image-y-to-pos":[{"mask-y-to":de()}],"mask-image-y-from-color":[{"mask-y-from":N()}],"mask-image-y-to-color":[{"mask-y-to":N()}],"mask-image-radial":[{"mask-radial":[Wm,zm]}],"mask-image-radial-from-pos":[{"mask-radial-from":de()}],"mask-image-radial-to-pos":[{"mask-radial-to":de()}],"mask-image-radial-from-color":[{"mask-radial-from":N()}],"mask-image-radial-to-color":[{"mask-radial-to":N()}],"mask-image-radial-shape":[{"mask-radial":[`circle`,`ellipse`]}],"mask-image-radial-size":[{"mask-radial":[{closest:[`side`,`corner`],farthest:[`side`,`corner`]}]}],"mask-image-radial-pos":[{"mask-radial-at":b()}],"mask-image-conic-pos":[{"mask-conic":[Om]}],"mask-image-conic-from-pos":[{"mask-conic-from":de()}],"mask-image-conic-to-pos":[{"mask-conic-to":de()}],"mask-image-conic-from-color":[{"mask-conic-from":N()}],"mask-image-conic-to-color":[{"mask-conic-to":N()}],"mask-mode":[{mask:[`alpha`,`luminance`,`match`]}],"mask-origin":[{"mask-origin":[`border`,`padding`,`content`,`fill`,`stroke`,`view`]}],"mask-position":[{mask:re()}],"mask-repeat":[{mask:ie()}],"mask-size":[{mask:ae()}],"mask-type":[{"mask-type":[`alpha`,`luminance`]}],"mask-image":[{mask:[`none`,Wm,zm]}],filter:[{filter:[``,`none`,Wm,zm]}],blur:[{blur:fe()}],brightness:[{brightness:[Om,Wm,zm]}],contrast:[{contrast:[Om,Wm,zm]}],"drop-shadow":[{"drop-shadow":[``,`none`,p,Xm,Um]}],"drop-shadow-color":[{"drop-shadow":N()}],grayscale:[{grayscale:[``,Om,Wm,zm]}],"hue-rotate":[{"hue-rotate":[Om,Wm,zm]}],invert:[{invert:[``,Om,Wm,zm]}],saturate:[{saturate:[Om,Wm,zm]}],sepia:[{sepia:[``,Om,Wm,zm]}],"backdrop-filter":[{"backdrop-filter":[``,`none`,Wm,zm]}],"backdrop-blur":[{"backdrop-blur":fe()}],"backdrop-brightness":[{"backdrop-brightness":[Om,Wm,zm]}],"backdrop-contrast":[{"backdrop-contrast":[Om,Wm,zm]}],"backdrop-grayscale":[{"backdrop-grayscale":[``,Om,Wm,zm]}],"backdrop-hue-rotate":[{"backdrop-hue-rotate":[Om,Wm,zm]}],"backdrop-invert":[{"backdrop-invert":[``,Om,Wm,zm]}],"backdrop-opacity":[{"backdrop-opacity":[Om,Wm,zm]}],"backdrop-saturate":[{"backdrop-saturate":[Om,Wm,zm]}],"backdrop-sepia":[{"backdrop-sepia":[``,Om,Wm,zm]}],"border-collapse":[{border:[`collapse`,`separate`]}],"border-spacing":[{"border-spacing":w()}],"border-spacing-x":[{"border-spacing-x":w()}],"border-spacing-y":[{"border-spacing-y":w()}],"table-layout":[{table:[`auto`,`fixed`]}],caption:[{caption:[`top`,`bottom`]}],transition:[{transition:[``,`all`,`colors`,`opacity`,`shadow`,`transform`,`none`,Wm,zm]}],"transition-behavior":[{transition:[`normal`,`discrete`]}],duration:[{duration:[Om,`initial`,Wm,zm]}],ease:[{ease:[`linear`,`initial`,_,Wm,zm]}],delay:[{delay:[Om,Wm,zm]}],animate:[{animate:[`none`,v,Wm,zm]}],backface:[{backface:[`hidden`,`visible`]}],perspective:[{perspective:[h,Wm,zm]}],"perspective-origin":[{"perspective-origin":x()}],rotate:[{rotate:pe()}],"rotate-x":[{"rotate-x":pe()}],"rotate-y":[{"rotate-y":pe()}],"rotate-z":[{"rotate-z":pe()}],scale:[{scale:me()}],"scale-x":[{"scale-x":me()}],"scale-y":[{"scale-y":me()}],"scale-z":[{"scale-z":me()}],"scale-3d":[`scale-3d`],skew:[{skew:he()}],"skew-x":[{"skew-x":he()}],"skew-y":[{"skew-y":he()}],transform:[{transform:[Wm,zm,``,`none`,`gpu`,`cpu`]}],"transform-origin":[{origin:x()}],"transform-style":[{transform:[`3d`,`flat`]}],translate:[{translate:ge()}],"translate-x":[{"translate-x":ge()}],"translate-y":[{"translate-y":ge()}],"translate-z":[{"translate-z":ge()}],"translate-none":[`translate-none`],accent:[{accent:N()}],appearance:[{appearance:[`none`,`auto`]}],"caret-color":[{caret:N()}],"color-scheme":[{scheme:[`normal`,`dark`,`light`,`light-dark`,`only-dark`,`only-light`]}],cursor:[{cursor:[`auto`,`default`,`pointer`,`wait`,`text`,`move`,`help`,`not-allowed`,`none`,`context-menu`,`progress`,`cell`,`crosshair`,`vertical-text`,`alias`,`copy`,`no-drop`,`grab`,`grabbing`,`all-scroll`,`col-resize`,`row-resize`,`n-resize`,`e-resize`,`s-resize`,`w-resize`,`ne-resize`,`nw-resize`,`se-resize`,`sw-resize`,`ew-resize`,`ns-resize`,`nesw-resize`,`nwse-resize`,`zoom-in`,`zoom-out`,Wm,zm]}],"field-sizing":[{"field-sizing":[`fixed`,`content`]}],"pointer-events":[{"pointer-events":[`auto`,`none`]}],resize:[{resize:[`none`,``,`y`,`x`]}],"scroll-behavior":[{scroll:[`auto`,`smooth`]}],"scroll-m":[{"scroll-m":w()}],"scroll-mx":[{"scroll-mx":w()}],"scroll-my":[{"scroll-my":w()}],"scroll-ms":[{"scroll-ms":w()}],"scroll-me":[{"scroll-me":w()}],"scroll-mbs":[{"scroll-mbs":w()}],"scroll-mbe":[{"scroll-mbe":w()}],"scroll-mt":[{"scroll-mt":w()}],"scroll-mr":[{"scroll-mr":w()}],"scroll-mb":[{"scroll-mb":w()}],"scroll-ml":[{"scroll-ml":w()}],"scroll-p":[{"scroll-p":w()}],"scroll-px":[{"scroll-px":w()}],"scroll-py":[{"scroll-py":w()}],"scroll-ps":[{"scroll-ps":w()}],"scroll-pe":[{"scroll-pe":w()}],"scroll-pbs":[{"scroll-pbs":w()}],"scroll-pbe":[{"scroll-pbe":w()}],"scroll-pt":[{"scroll-pt":w()}],"scroll-pr":[{"scroll-pr":w()}],"scroll-pb":[{"scroll-pb":w()}],"scroll-pl":[{"scroll-pl":w()}],"snap-align":[{snap:[`start`,`end`,`center`,`align-none`]}],"snap-stop":[{snap:[`normal`,`always`]}],"snap-type":[{snap:[`none`,`x`,`y`,`both`]}],"snap-strictness":[{snap:[`mandatory`,`proximity`]}],touch:[{touch:[`auto`,`none`,`manipulation`]}],"touch-x":[{"touch-pan":[`x`,`left`,`right`]}],"touch-y":[{"touch-pan":[`y`,`up`,`down`]}],"touch-pz":[`touch-pinch-zoom`],select:[{select:[`none`,`text`,`all`,`auto`]}],"will-change":[{"will-change":[`auto`,`scroll`,`contents`,`transform`,Wm,zm]}],fill:[{fill:[`none`,...N()]}],"stroke-w":[{stroke:[Om,Gm,Bm,Vm]}],stroke:[{stroke:[`none`,...N()]}],"forced-color-adjust":[{"forced-color-adjust":[`auto`,`none`]}]},conflictingClassGroups:{overflow:[`overflow-x`,`overflow-y`],overscroll:[`overscroll-x`,`overscroll-y`],inset:[`inset-x`,`inset-y`,`inset-bs`,`inset-be`,`start`,`end`,`top`,`right`,`bottom`,`left`],"inset-x":[`right`,`left`],"inset-y":[`top`,`bottom`],flex:[`basis`,`grow`,`shrink`],gap:[`gap-x`,`gap-y`],p:[`px`,`py`,`ps`,`pe`,`pbs`,`pbe`,`pt`,`pr`,`pb`,`pl`],px:[`pr`,`pl`],py:[`pt`,`pb`],m:[`mx`,`my`,`ms`,`me`,`mbs`,`mbe`,`mt`,`mr`,`mb`,`ml`],mx:[`mr`,`ml`],my:[`mt`,`mb`],size:[`w`,`h`],"font-size":[`leading`],"fvn-normal":[`fvn-ordinal`,`fvn-slashed-zero`,`fvn-figure`,`fvn-spacing`,`fvn-fraction`],"fvn-ordinal":[`fvn-normal`],"fvn-slashed-zero":[`fvn-normal`],"fvn-figure":[`fvn-normal`],"fvn-spacing":[`fvn-normal`],"fvn-fraction":[`fvn-normal`],"line-clamp":[`display`,`overflow`],rounded:[`rounded-s`,`rounded-e`,`rounded-t`,`rounded-r`,`rounded-b`,`rounded-l`,`rounded-ss`,`rounded-se`,`rounded-ee`,`rounded-es`,`rounded-tl`,`rounded-tr`,`rounded-br`,`rounded-bl`],"rounded-s":[`rounded-ss`,`rounded-es`],"rounded-e":[`rounded-se`,`rounded-ee`],"rounded-t":[`rounded-tl`,`rounded-tr`],"rounded-r":[`rounded-tr`,`rounded-br`],"rounded-b":[`rounded-br`,`rounded-bl`],"rounded-l":[`rounded-tl`,`rounded-bl`],"border-spacing":[`border-spacing-x`,`border-spacing-y`],"border-w":[`border-w-x`,`border-w-y`,`border-w-s`,`border-w-e`,`border-w-bs`,`border-w-be`,`border-w-t`,`border-w-r`,`border-w-b`,`border-w-l`],"border-w-x":[`border-w-r`,`border-w-l`],"border-w-y":[`border-w-t`,`border-w-b`],"border-color":[`border-color-x`,`border-color-y`,`border-color-s`,`border-color-e`,`border-color-bs`,`border-color-be`,`border-color-t`,`border-color-r`,`border-color-b`,`border-color-l`],"border-color-x":[`border-color-r`,`border-color-l`],"border-color-y":[`border-color-t`,`border-color-b`],translate:[`translate-x`,`translate-y`,`translate-none`],"translate-none":[`translate`,`translate-x`,`translate-y`,`translate-z`],"scroll-m":[`scroll-mx`,`scroll-my`,`scroll-ms`,`scroll-me`,`scroll-mbs`,`scroll-mbe`,`scroll-mt`,`scroll-mr`,`scroll-mb`,`scroll-ml`],"scroll-mx":[`scroll-mr`,`scroll-ml`],"scroll-my":[`scroll-mt`,`scroll-mb`],"scroll-p":[`scroll-px`,`scroll-py`,`scroll-ps`,`scroll-pe`,`scroll-pbs`,`scroll-pbe`,`scroll-pt`,`scroll-pr`,`scroll-pb`,`scroll-pl`],"scroll-px":[`scroll-pr`,`scroll-pl`],"scroll-py":[`scroll-pt`,`scroll-pb`],touch:[`touch-x`,`touch-y`,`touch-pz`],"touch-x":[`touch`],"touch-y":[`touch`],"touch-pz":[`touch`]},conflictingClassGroupModifiers:{"font-size":[`leading`]},orderSensitiveModifiers:[`*`,`**`,`after`,`backdrop`,`before`,`details-content`,`file`,`first-letter`,`first-line`,`marker`,`placeholder`,`selection`]}});function lh(...e){return ch(Gp(e))}function uh({delayDuration:e=0,...t}){return(0,L.jsx)(Lp,{"data-slot":`tooltip-provider`,delayDuration:e,...t})}function dh({...e}){return(0,L.jsx)(Rp,{"data-slot":`tooltip`,...e})}function fh({...e}){return(0,L.jsx)(zp,{"data-slot":`tooltip-trigger`,...e})}function ph({className:e,sideOffset:t=4,children:n,...r}){return(0,L.jsx)(Bp,{children:(0,L.jsxs)(Vp,{"data-slot":`tooltip-content`,sideOffset:t,className:lh(`z-50 overflow-hidden rounded-md bg-gray-900 px-3 py-1.5 text-xs text-gray-100 shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2`,e),...r,children:[n,(0,L.jsx)(Hp,{className:`fill-gray-900`})]})})}var R=(e,t)=>fetch(e,{credentials:`include`,...t}),mh=null;function hh(){return mh||=R(`/api/health`).then(e=>e.json()).then(e=>typeof e?.workspace==`string`?e.workspace:`loopat`).catch(()=>`loopat`),mh}async function gh(){let e=await R(`/api/auth/me`);return e.ok?(await e.json()).user??null:null}async function _h(e,t){let n=await R(`/api/auth/login`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({username:e,password:t})}),r=await n.json().catch(()=>({}));return n.ok?{user:r.user}:{error:r.error??`login failed (${n.status})`}}async function vh(e){let t=await R(`/api/auth/register`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(e)}),n=await t.json().catch(()=>({}));return t.ok?{user:n.user,publicKey:n.publicKey,personalRepo:n.personalRepo??null,needsImport:!!n.needsImport}:{error:n.error??`register failed (${t.status})`}}async function yh(e){let t=await R(`/api/personal/repos`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({token:e})}),n=await t.json().catch(()=>({}));return t.ok?{ok:n.ok!==!1,repos:Array.isArray(n.repos)?n.repos:[],login:n.login,error:n.error}:{ok:!1,repos:[],error:n?.error??`request failed`}}async function bh(){let e=await R(`/api/personal/status`);return e.ok?await e.json():null}async function xh(){let e=await R(`/api/onboarding`);return e.ok?await e.json():null}async function Sh(e){let t=await R(`/api/onboarding/submit`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({values:e})}),n=await t.json().catch(()=>({}));return t.ok?n:{error:n.error??`submit failed (${t.status})`}}async function Ch(){let e=await R(`/api/onboarding/device/start`,{method:`POST`}),t=await e.json().catch(()=>({}));return e.ok?t:{error:t.error??`device start failed (${e.status})`}}async function wh(e){return await(await R(`/api/onboarding/device/poll`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({device_code:e})})).json().catch(()=>({status:`error`,error:`poll failed`}))}async function Th(e){let t=await R(`/api/personal/crypt-key`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({password:e})}),n=await t.json().catch(()=>({}));return t.ok?typeof n.cryptKey==`string`?{ok:!0,cryptKey:n.cryptKey}:{ok:!1,error:`missing cryptKey in response`}:{ok:!1,error:n.error??`request failed (${t.status})`,wrongPassword:t.status===403}}async function Eh(e,t=!1){let n=await R(`/api/personal/delete`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({password:e,force:t})}),r=await n.json().catch(()=>({}));return n.ok?{ok:!0,synced:r.synced,dataLost:r.dataLost}:{ok:!1,error:r.error??`delete failed (${n.status})`,wrongPassword:n.status===403,syncFailed:r.syncFailed,uncommitted:r.uncommitted,unpushed:r.unpushed,hasRemote:r.hasRemote}}async function Dh(e){let t=await R(`/api/personal/pull`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({force:e?.force??!1})}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0,message:n.message}:{ok:!1,error:n.error??`pull failed (${t.status})`,conflict:n.conflict,files:n.files,needsStash:n.needsStash}}async function Oh(){let e=await R(`/api/personal/push`,{method:`POST`}),t=await e.json().catch(()=>({}));return e.ok?{ok:!0,message:t.message}:{ok:!1,error:t.error??`push failed (${e.status})`,conflict:t.conflict,files:t.files,needsPull:t.needsPull}}async function kh(e,t){let n={};e&&(n.repoUrl=e),t&&(n.cryptKey=t);let r=await R(`/api/personal/import`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(n)}),i=await r.json().catch(()=>({}));return r.ok?{ok:!0,autoInitialized:!!i.autoInitialized,cryptKey:typeof i.cryptKey==`string`?i.cryptKey:null}:{ok:!1,error:i.error??`import failed (${r.status})`,needsCryptKey:!!i.needsCryptKey,notClean:!!i.notClean,secretsExposed:!!i.secretsExposed,exposedFiles:Array.isArray(i.exposedFiles)?i.exposedFiles:[]}}async function Ah(e,t,n,r){let i={token:e};t&&(i.repoName=t),n&&(i.cryptKey=n),r&&(i.baseUrl=r);let a=await R(`/api/personal/github`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(i)}),o=await a.json().catch(()=>({}));return a.ok?{ok:!0,repo:typeof o.repo==`string`?o.repo:void 0,created:!!o.created,autoInitialized:!!o.autoInitialized,cryptKey:typeof o.cryptKey==`string`?o.cryptKey:null}:{ok:!1,error:o.error??`github setup failed (${a.status})`,needsCryptKey:!!o.needsCryptKey}}async function jh(){await R(`/api/auth/logout`,{method:`POST`}).catch(()=>{})}async function uee(e=`active`){let t=await R(`/api/loops`+(e===`all`?`?archived=all`:e===`archived`?`?archived=true`:``));return t.ok?(await t.json()).loops:[]}async function dee(e){if(e.knowledgeRw||e.mountAllLoops){let t={title:e.title,repo:e.repo,profiles:e.profiles,vault:e.vault};return e.knowledgeRw&&(t.knowledge_rw=!0),e.mountAllLoops&&(t.mount_all_loops=!0),await(await R(`/api/loops`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(t)})).json()}let t=await R(`/api/v1/loops`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({title:e.title,profiles:e.profiles,vault:e.vault,repo:e.repo})});if(!t.ok)throw Error(`createLoop failed (${t.status})`);let n=await t.json();return{id:n.id.startsWith(`loop_`)?n.id.slice(5):n.id,title:n.title,createdAt:n.created_at,createdBy:n.created_by,archived:n.archived,repo:n.repo??void 0,config:{profiles:n.profiles,vault:n.vault}}}async function Mh(){let e=await R(`/api/profiles`);return e.ok?(await e.json()).profiles??[]:[]}async function fee(){let e=await R(`/api/personal/default-profiles`);if(!e.ok)return[];let t=await e.json();return Array.isArray(t.default_profiles)?t.default_profiles:[]}async function pee(e){let t=await R(`/api/loop-stats?profiles=${encodeURIComponent(e.join(`,`))}`);return t.ok?await t.json():null}async function mee(){let e=await R(`/api/vaults`);if(!e.ok)return[];let t=await e.json();return Array.isArray(t.vaults)?t.vaults:[]}async function Nh(e){return(await R(`/api/loops/${e}/viewed`,{method:`POST`})).ok}async function hee(e,t){let n=await R(`/api/loops/${e}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify({archived:t})});return n.ok?await n.json():null}async function gee(e,t){let n=await R(`/api/loops/${e}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify({public:t})});return n.ok?await n.json():null}async function _ee(e,t){let n=await R(`/api/loops/${e}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify({title:t})});return n.ok?await n.json():null}async function vee(e){let t=await R(`/api/loops/${e}/request-drive`,{method:`POST`});return t.ok?await t.json():null}async function yee(e){let t=await R(`/api/loops/${e}/drive`,{method:`POST`});return t.ok?await t.json():null}async function bee(e){let t=await R(`/api/loops/${e}/distill`,{method:`POST`});return t.ok?await t.json():null}async function xee(e){let t=await R(`/api/loops/${e}`);return t.ok?await t.json():null}async function See(e){let t=await R(`/api/loops/${e}/strip-thinking`,{method:`POST`});return t.ok?await t.json():{stripped:0,sessionsTouched:0}}async function Ph(e,t=``){return(await(await R(`/api/loops/${e}/files?path=${encodeURIComponent(t)}`)).json()).entries??[]}async function Fh(e,t=``){return(await(await R(`/api/loops/${e}/files/tree?path=${encodeURIComponent(t)}`)).json()).entries??[]}async function Ih(e,t){let n=await R(`/api/loops/${e}/file?path=${encodeURIComponent(t)}`);return n.ok?await n.json():null}async function Lh(e,t,n){return(await R(`/api/loops/${e}/file?path=${encodeURIComponent(t)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({content:n})})).ok}async function Rh(e,t){return(await R(`/api/loops/${e}/file?path=${encodeURIComponent(t)}`,{method:`DELETE`})).ok}async function zh(e,t){return(await R(`/api/loops/${e}/folder`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({path:t})})).ok}async function Bh(e,t){let n=new FormData;n.append(`file`,t);let r=await R(`/api/loops/${e}/upload`,{method:`POST`,body:n}),i=await r.json().catch(()=>({}));return r.ok?{ok:!0,path:i.path}:{ok:!1,error:i.error??`upload failed`}}async function Vh(e){let t=await R(`/api/loops/${e}/context`);return t.ok?(await t.json()).mounts??[]:[]}async function Hh(e,t=``){let n=await R(`/api/workspace/files?vault=${e}&path=${encodeURIComponent(t)}`);return n.ok?(await n.json()).entries??[]:[]}async function Uh(e){let t=await R(`/api/workspace/files?vault=${e}&flat=1`);return t.ok?(await t.json()).entries??[]:[]}async function Wh(e,t){let n=await R(`/api/workspace/file?vault=${e}&path=${encodeURIComponent(t)}`);return n.ok?await n.json():null}async function Gh(e,t,n){return await(await R(`/api/workspace/file?vault=${e}&path=${encodeURIComponent(t)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({content:n})})).json()}async function Kh(){let e=await R(`/api/notes/save`,{method:`POST`}),t=await e.json().catch(()=>({}));return e.ok?{ok:!0,message:t.message}:{ok:!1,conflict:t.conflict,files:t.files,needsPull:t.needsPull,error:t.error??`save failed (${e.status})`}}async function qh(){let e=await(await R(`/api/notes/behind`)).json().catch(()=>({}));return typeof e.behind==`number`?e.behind:0}async function Jh(){let e=await(await R(`/api/notes/refresh`,{method:`POST`})).json().catch(()=>({}));return{ok:!!e.ok,diverged:e.diverged,error:e.error}}async function Yh(e,t){return await(await R(`/api/workspace/file?vault=${e}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({path:t})})).json()}async function Xh(e,t){return await(await R(`/api/workspace/folder?vault=${e}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({path:t})})).json()}async function Zh(e,t){return await(await R(`/api/workspace/file?vault=${e}&path=${encodeURIComponent(t)}`,{method:`DELETE`})).json()}async function Qh(e,t){let n=await R(`/api/workspace/backlinks?vault=${e}&path=${encodeURIComponent(t)}`);return n.ok?(await n.json()).backlinks??[]:[]}async function $h(){let e=await R(`/api/context/repos`);return e.ok?{repos:(await e.json()).repos??[]}:{repos:[]}}async function eg(e){let t=await R(`/api/context/repos`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(e)}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0}:{ok:!1,error:n.error??`http ${t.status}`}}async function tg(e){let t=await R(`/api/loops/${e}/chat-history`);return t.ok?(await t.json()).map(e=>e.text):[]}async function ng(e,t){await R(`/api/loops/${e}/chat-history`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:t})})}function rg(e){return typeof e==`string`?`/api/sync/${e}`:`/api/sync/repos/${encodeURIComponent(e.repo)}`}async function ig(e){let t=await R(`${rg(e)}/status`);return t.ok?await t.json():null}async function ag(e){let t=await R(`${rg(e)}/pull`,{method:`POST`}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0,message:n.message}:{ok:!1,error:n.error??`http ${t.status}`}}async function og(e){let t=await R(`${rg(e)}/push`,{method:`POST`}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0,message:n.message}:{ok:!1,error:n.error??`http ${t.status}`}}async function sg(e=`default`){let t=await R(`/api/kanban/${encodeURIComponent(e)}`);return t.ok?(await t.json()).columns:[]}async function cg(e,t,n){let r=await R(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/cards`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(n)}),i=await r.json().catch(()=>({}));return r.ok?{cid:i.cid}:{error:i.error??`add failed`}}async function lg(e,t,n){return(await R(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/cards/${encodeURIComponent(n)}/toggle`,{method:`PATCH`})).ok}async function ug(e,t,n,r){return(await R(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/cards/${encodeURIComponent(n)}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify(r)})).ok}async function dg(e,t,n,r){return(await R(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/cards/${encodeURIComponent(n)}/block`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({block:r})})).ok}async function fg(e,t,n){return(await R(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/cards/${encodeURIComponent(n)}`,{method:`DELETE`})).ok}async function pg(e,t,n,r,i){return(await R(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/cards/${encodeURIComponent(n)}/move`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({toFile:r,toIndex:i})})).ok}async function mg(e,t,n){return(await R(`/api/kanban/columns/${encodeURIComponent(e)}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({filename:t,title:n})})).ok}async function hg(){let e=await R(`/api/kanban/boards`);return e.ok?(await e.json()).boards:[`default`]}async function Cee(e){return(await R(`/api/kanban/boards`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:e})})).ok}async function wee(e,t){return(await R(`/api/kanban/boards/${encodeURIComponent(e)}/rename`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({name:t})})).ok}async function Tee(e=`default`){let t=await R(`/api/kanban/config/${encodeURIComponent(e)}`);return t.ok?(await t.json()).columns:[]}async function Eee(e,t){return(await R(`/api/kanban/config/${encodeURIComponent(e)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({columns:t})})).ok}async function Dee(e,t,n){return(await R(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/rename`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({toFile:n})})).ok}async function Oee(e,t){return(await R(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,{method:`DELETE`})).ok}async function kee(e,t,n){return(await R(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/color`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({color:n})})).ok}async function Aee(e,t,n){return(await R(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/reorder`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({cids:n})})).ok}async function jee(e,t,n){let r=await R(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/cards/${encodeURIComponent(n)}/assign-driver`,{method:`POST`});return r.ok?await r.json():{ok:!1}}async function Mee(e,t,n,r){return(await R(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/cards/${encodeURIComponent(n)}/link-loop`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({loopId:r})})).ok}async function Nee(){let e=await R(`/api/topics`);return e.ok?(await e.json()).topics:[]}async function gg(){let e=await R(`/api/providers`);return e.ok?await e.json():{providers:{},default:``}}async function _g(e,t,n,r,i){let a={baseUrl:e,model:n};t?a.apiKey=t:r&&i&&(a.provider=r,a.source=i);let o=await R(`/api/providers/test`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(a)}),s=await o.json().catch(()=>({}));return o.ok?s:{ok:!1,error:s.error??`test failed (${o.status})`}}async function vg(){let e=await R(`/api/version`);return e.ok?await e.json():{branch:`unknown`,commit:`unknown`}}async function yg(){let e=await R(`/api/admin/system`);return e.ok?await e.json():null}async function bg(){return await(await R(`/api/admin/system/check`,{method:`POST`})).json()}async function xg(){return await(await R(`/api/admin/system/pull`,{method:`POST`})).json()}function Sg(){return{commit:`00984ab7c6251649086ff1a13d88a20b10405a9f`,time:`2026-06-05T16:38:08.892Z`}}async function Cg(e){let t=await R(`/api/loops/${e}/git-status`);return t.ok?await t.json():{unstaged:[],staged:[]}}async function wg(e,t,n){let r=await R(`/api/loops/${e}/git-diff?path=${encodeURIComponent(t)}&staged=${n?`1`:`0`}`);return r.ok?(await r.json()).diff??null:null}async function Tg(e,t,n=!1){return(await R(`/api/loops/${e}/git-stage`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({files:t,unstage:n})})).ok}async function Eg(e,t){return(await R(`/api/loops/${e}/git-discard`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({file:t})})).ok}async function Dg(e,t){let n=await R(`/api/loops/${e}/git-commit`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({message:t})}),r=await n.json().catch(()=>({}));return n.ok?{ok:!0}:{ok:!1,error:r.error??`commit failed`}}async function Og(e,t=50){let n=await R(`/api/loops/${e}/git-log?limit=${t}`);return n.ok?(await n.json()).commits??[]:[]}async function kg(){let e=await R(`/api/settings/personal/disk`);return e.ok?await e.json():null}async function Ag(e){let t=await R(`/api/settings/personal/disk`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(e)}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0}:{ok:!1,error:n.error??`save failed (${t.status})`}}async function jg(e,t,n=`default`){let r=await R(`/api/settings/personal/value`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:e,value:t,vault:n})}),i=await r.json().catch(()=>({}));return r.ok?{ok:!0}:{ok:!1,error:i.error??`write failed (${r.status})`}}async function Mg(){return await(await R(`/api/settings/workspace`)).json()}async function Ng(e){return(await R(`/api/settings/workspace`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(e)})).ok}async function Pg(){let e=await R(`/api/settings/token-usage/daily`);return e.ok?await e.json():{}}async function Fg(){let e=await R(`/api/settings/token-usage/loops`);return e.ok?await e.json():[]}async function Ig(){let e=await R(`/api/admin/presets`);return e.ok?await e.json():{providerPresets:[],miseToolPresets:[]}}async function Lg(e){return(await R(`/api/admin/presets`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(e)})).ok}async function Rg(){let e=await R(`/api/admin/users`);return e.ok?(await e.json()).users??[]:[]}async function zg(e){let t=await R(`/api/admin/users/${encodeURIComponent(e)}/activate`,{method:`POST`}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0}:{ok:!1,error:n.error??`activate failed (${t.status})`}}async function Bg(e,t){let n=await R(`/api/admin/users/${encodeURIComponent(e)}/role`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({role:t})}),r=await n.json().catch(()=>({}));return n.ok?{ok:!0}:{ok:!1,error:r.error??`role change failed (${n.status})`}}async function Vg(e){let t=await R(`/api/admin/users/${encodeURIComponent(e)}`,{method:`DELETE`}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0}:{ok:!1,error:n.error??`delete failed (${t.status})`}}async function Hg(){let e=await R(`/api/serve/config`);return e.ok?await e.json():{serveEnabled:!0,domain:`nip.io`,ip:`127.0.0.1`,baseUrl:`.127.0.0.1.nip.io`,withPort:!1,https:!1,displayPort:7788,serveDynamicEnabled:!1,serveDynamicDomain:``,serveDynamicPortRange:`10000-20000`,serveDynamicUdpEnabled:!1,serveDynamicStaticEnabled:!1,serveEphemeralEnabled:!1,serveEphemeralDomain:``}}async function Ug(e){let t=await R(`/api/loops/${e}/share/current-port`);return t.ok?await t.json():{port:null}}async function Wg(e){return(await R(`/api/serve/config`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(e)})).ok}async function Gg(){let e=await R(`/api/serve/available-port`);return e.ok?await e.json():{port:null,error:`request failed`}}async function Kg(e,t){let n=await R(`/api/serve/check-port?port=${e}&loopId=${t||``}`);return n.ok?await n.json():{available:!1,reason:`request failed`}}async function qg(e,t){let n=new URLSearchParams({alias:e});t&&n.set(`loopId`,t);let r=await R(`/api/serve/alias-check?${n}`);return r.ok?await r.json():{available:!1,reason:`check failed`}}async function Jg(){let e=await R(`/api/chat/conversations`);return e.ok?(await e.json()).conversations??[]:[]}async function Yg(){let e=await R(`/api/chat/users`);return e.ok?(await e.json()).users??[]:[]}async function Xg(e,t){let n=await R(`/api/chat/channels`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:e,topic:t})}),r=await n.json().catch(()=>({}));return n.ok?{conv:r.conv}:{error:r.error??`create failed (${n.status})`}}async function Zg(e){let t=await R(`/api/chat/channels/${encodeURIComponent(e)}`,{method:`DELETE`}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0}:{ok:!1,error:n.error??`delete failed (${t.status})`}}async function Qg(e){let t=await R(`/api/chat/dm/${encodeURIComponent(e)}`,{method:`POST`}),n=await t.json().catch(()=>({}));return t.ok?{conv:n.conv}:{error:n.error??`open DM failed (${t.status})`}}async function $g(e,t={}){let n=new URLSearchParams;t.before&&n.set(`before`,String(t.before)),t.limit&&n.set(`limit`,String(t.limit));let r=await R(`/api/chat/conversations/${encodeURIComponent(e)}/messages?${n.toString()}`);return r.ok?(await r.json()).messages??[]:[]}async function e_(e){let t=await R(`/api/chat/threads/${e}`);return t.ok?await t.json():null}async function t_(e,t,n=null){let r=await R(`/api/chat/conversations/${encodeURIComponent(e)}/messages`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(n==null?{text:t}:{text:t,parentId:n})}),i=await r.json().catch(()=>({}));return r.ok?{message:i.message}:{error:i.error??`send failed (${r.status})`}}async function n_(e,t){return(await R(`/api/chat/conversations/${encodeURIComponent(e)}/read`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({lastReadId:t})})).ok}async function r_(e,t){let n=await R(`/api/chat/threads/${e}/spawn-loop`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(t?{title:t}:{})}),r=await n.json().catch(()=>({}));return n.ok?{loopId:r.loopId,seedPrompt:r.seedPrompt,messageCount:r.messageCount}:{error:r.error??`spawn failed (${n.status})`}}async function i_(e,t,n){let r=await R(`/api/mcp-setup/parse`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({server:e,pastedUrl:t,loopId:n})}),i=await r.json().catch(()=>({}));return r.ok?{ok:!0,set:i.set??[]}:{ok:!1,error:i.error??`failed (${r.status})`}}async function a_(){let e=await R(`/api/a2a`);return e.ok?await e.json():null}async function o_(e){return(await R(`/api/a2a`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(e)})).ok}async function s_(){let e=await R(`/api/a2a/key`,{method:`POST`});return e.ok?(await e.json().catch(()=>({}))).token??null:null}async function c_(e){let t=await R(`/api/mcp-servers${e?`?loopId=${encodeURIComponent(e)}`:``}`);return t.ok?await t.json():{servers:[]}}async function l_(e,t){let n=await R(`/api/mcp-auth/start`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({serverName:e,loopId:t})}),r=await n.json().catch(()=>({}));return n.ok?{authorizationUrl:r.authorizationUrl}:{error:r.error??`start failed`}}async function u_(e){return(await R(`/api/envs/${encodeURIComponent(e)}`,{method:`DELETE`})).ok}async function d_(e){let t=await R(`/api/loops/${encodeURIComponent(e)}/restart-session`,{method:`POST`}),n=await t.json().catch(()=>({}));return t.ok?{restarted:!!n.restarted}:{restarted:!1,error:n.error??`restart failed (${t.status})`}}async function f_(){let e=await R(`/api/tiers`);return e.ok?await e.json():null}async function p_(e,t){let n=await R(`/api/tiers/${encodeURIComponent(e)}/settings`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(t)}),r=await n.json().catch(()=>({}));return n.ok?{ok:!0}:{ok:!1,error:r.error??`save failed (${n.status})`}}async function m_(e){let t=await R(`/api/tiers/${encodeURIComponent(e)}/mise-config`);return t.ok?await t.json():{content:``,exists:!1,error:`fetch failed (${t.status})`}}async function h_(e,t){let n=await R(`/api/tiers/${encodeURIComponent(e)}/mise-config`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({content:t})}),r=await n.json().catch(()=>({}));return n.ok?{ok:!0}:{ok:!1,error:r.error??`save failed (${n.status})`}}async function g_(){let e=await R(`/api/plugins/available`);return e.ok?(await e.json()).plugins??[]:[]}async function __(){let e=await R(`/api/plugins/browse`);return e.ok?(await e.json()).plugins??[]:[]}async function v_(){let e=await R(`/api/marketplaces`);return e.ok?(await e.json()).marketplaces??[]:[]}async function y_(){let e=await R(`/api/plugins/refresh`,{method:`POST`}),t=await e.json().catch(()=>({}));return e.ok?{ok:!0,added:t.added}:{ok:!1,error:t.error??`refresh failed (${e.status})`}}async function b_(e){let t=await R(`/api/admin/profiles`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:e})}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0}:{ok:!1,error:n.error??`create failed (${t.status})`}}async function x_(e){let t=await R(`/api/admin/profiles/${encodeURIComponent(e)}`,{method:`DELETE`}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0}:{ok:!1,error:n.error??`delete failed (${t.status})`}}async function S_(){let e=await R(`/api/v1/me/tokens`);return e.ok?(await e.json().catch(()=>({tokens:[]}))).tokens??[]:[]}async function C_(e){let t=await R(`/api/v1/me/tokens`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({label:e})});return t.ok?await t.json().catch(()=>null):null}async function w_(e){return(await R(`/api/v1/me/tokens/${encodeURIComponent(e)}`,{method:`DELETE`})).ok}function T_(){let[e,t]=(0,F.useState)([]),[n,r]=(0,F.useState)(!0),[i,a]=(0,F.useState)(!1),[o,s]=(0,F.useState)(!1),[c,l]=(0,F.useState)(``),[u,d]=(0,F.useState)(null),[f,p]=(0,F.useState)(null),[m,h]=(0,F.useState)(!0),g=(0,F.useCallback)(async()=>{r(!0),t(await uee(i?`all`:`active`)),r(!1)},[i]);(0,F.useEffect)(()=>{let e=!1;return gh().then(t=>{e||(p(t),h(!1))}),()=>{e=!0}},[]),(0,F.useEffect)(()=>{g()},[i,f]);let _=(0,F.useCallback)(async e=>{let n=await dee(e);return t(e=>[n,...e]),n},[]),v=(0,F.useCallback)(async(e,n)=>{let r=await hee(e,n);r&&t(t=>!i&&r.archived?t.filter(t=>t.id!==e):t.map(t=>t.id===e?r:t))},[i]),y=(0,F.useCallback)(async(e,n)=>{let r=await gee(e,n);r&&t(t=>t.map(t=>t.id===e?r:t))},[]),b=(0,F.useCallback)(async(e,n)=>{let r=await _ee(e,n);return r?(t(t=>t.map(t=>t.id===e?r:t)),r):null},[]),x=(0,F.useCallback)(async e=>{let n=await vee(e);n&&t(t=>t.map(t=>t.id===e?n:t))},[]),S=(0,F.useCallback)(async e=>{let n=await yee(e);n&&t(t=>t.map(t=>t.id===e?n:t))},[]),C=(0,F.useCallback)(async(e,t)=>{let n=await _h(e,t);return n.user&&p(n.user),{error:n.error}},[]),w=(0,F.useCallback)(async e=>{let t=await vh(e);return t.user&&t.user.status===`active`&&p(t.user),{error:t.error,user:t.user,publicKey:t.publicKey,personalRepo:t.personalRepo,needsImport:t.needsImport}},[]),T=(0,F.useCallback)(async()=>{await jh(),p(null)},[]);return{loops:e,loopsLoading:n,showArchived:i,setShowArchived:a,refresh:g,createLoop:_,setLoopArchived:v,setLoopPublic:y,setLoopTitle:b,requestDrive:x,takeDrive:S,newLoopDialogOpen:o,newLoopDialogTitle:c,kanbanCreateCtx:u,setNewLoopDialogOpen:(0,F.useCallback)((e,t,n)=>{s(e),l(t??``),d(n??null)},[]),currentUser:f,authLoading:m,login:C,register:w,logout:T}}var E_=(0,F.createContext)(null);function D_(){let e=(0,F.useContext)(E_);if(!e)throw Error(`useWorkspace outside provider`);return e}function O_({onClose:e,onCreate:t,initialTitle:n}){let[r,i]=(0,F.useState)(n??``),[a,o]=(0,F.useState)(``),[s,c]=(0,F.useState)(new Set),[l,u]=(0,F.useState)([]),[d,f]=(0,F.useState)(`default`),[p,m]=(0,F.useState)([]),[h,g]=(0,F.useState)([]),[_,v]=(0,F.useState)([]),[y,b]=(0,F.useState)(null),[x,S]=(0,F.useState)(!1),[C,w]=(0,F.useState)(!1),T=(0,F.useRef)(null);(0,F.useEffect)(()=>{$h().then(e=>m(e.repos)),Promise.all([Mh(),fee()]).then(([e,t])=>{g(e),u(t);let n=new Set(e.map(e=>e.name));c(new Set(t.filter(e=>n.has(e)&&e!==`base`)))}),mee().then(e=>{v(e),e.includes(`default`)?f(`default`):e.length>0&&f(e[0])}),T.current?.focus()},[]);function E(){let e=new Set(h.map(e=>e.name));c(new Set(l.filter(t=>e.has(t)&&t!==`base`)))}(0,F.useEffect)(()=>{S(!0);let e=setTimeout(()=>{pee([...s]).then(b).finally(()=>S(!1))},120);return()=>clearTimeout(e)},[s]);let D=(()=>{let e=new Set(l.filter(e=>e!==`base`));if(e.size!==s.size)return!0;for(let t of e)if(!s.has(t))return!0;return!1})(),O=h.find(e=>e.name===`base`),k=h.filter(e=>e.name!==`base`);function A(e){c(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}return(0,L.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/30 flex items-end sm:items-center justify-center`,onClick:e,children:(0,L.jsxs)(`div`,{className:`w-full sm:max-w-[480px] sm:mx-4 bg-white rounded-t-xl sm:rounded-md shadow-xl border border-gray-200 flex flex-col h-dvh sm:h-auto sm:max-h-[85vh]`,onClick:e=>e.stopPropagation(),children:[(0,L.jsxs)(`div`,{className:`shrink-0 px-4 sm:px-5 pt-4 sm:pt-5 pb-3 border-b border-gray-100 flex items-center justify-between`,children:[(0,L.jsx)(`div`,{className:`text-base font-semibold text-gray-900`,children:`New loop`}),(0,L.jsx)(`button`,{type:`button`,onClick:e,className:`sm:hidden w-8 h-8 flex items-center justify-center rounded-full text-gray-400 hover:text-gray-600 hover:bg-gray-100 -mr-1`,"aria-label":`close`,children:(0,L.jsx)(`svg`,{width:`18`,height:`18`,viewBox:`0 0 18 18`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,children:(0,L.jsx)(`path`,{d:`M4 4l10 10M14 4L4 14`})})})]}),(0,L.jsxs)(`form`,{id:`new-loop-form`,onSubmit:async e=>{if(e.preventDefault(),!C){w(!0);try{await t({title:r.trim()||`untitled`,repo:a||void 0,profiles:s.size>0?[...s]:void 0,vault:d||void 0})}finally{w(!1)}}},className:`flex-1 min-h-0 overflow-y-auto px-4 sm:px-5 py-4 flex flex-col gap-4`,children:[(0,L.jsx)(k_,{label:`Name`,hint:`Optional — defaults to 'untitled'.`,children:(0,L.jsx)(`input`,{ref:T,type:`text`,value:r,onChange:e=>i(e.target.value),placeholder:`refactor-gateway`,className:`w-full px-3 py-2.5 sm:py-1.5 text-base sm:text-sm border border-gray-300 rounded outline-none focus:border-gray-500`})}),(0,L.jsxs)(k_,{label:`Repo`,hint:`Sets the workdir. Optional — leave (none) for an empty workdir.`,children:[(0,L.jsxs)(`select`,{value:a,onChange:e=>o(e.target.value),className:`w-full px-3 py-2.5 sm:py-1.5 text-base sm:text-sm border border-gray-300 rounded outline-none focus:border-gray-500 bg-white`,children:[(0,L.jsx)(`option`,{value:``,children:`(none — empty workdir)`}),p.map(e=>(0,L.jsxs)(`option`,{value:e.name,children:[e.name,e.git?` · ${e.git}`:``]},e.name))]}),p.length===0&&(0,L.jsx)(`div`,{className:`text-[11px] text-gray-400 mt-1`,children:`No repos in the roster. Add them on the Context → Repos page.`})]}),(0,L.jsxs)(k_,{label:`Profiles`,hint:`Each profile contributes plugins + a CLAUDE.md fragment. Empty = base + personal only.`,children:[(0,L.jsxs)(`div`,{className:`border border-gray-300 rounded p-2 max-h-44 overflow-y-auto bg-white flex flex-col gap-1`,children:[O&&(0,L.jsxs)(`label`,{className:`flex items-start gap-2 px-1.5 py-1 rounded text-sm text-gray-500 cursor-not-allowed bg-gray-50`,children:[(0,L.jsx)(`input`,{type:`checkbox`,checked:!0,disabled:!0,className:`mt-0.5`}),(0,L.jsxs)(`span`,{className:`flex-1`,children:[(0,L.jsx)(`span`,{className:`font-medium`,children:`base`}),(0,L.jsx)(`span`,{className:`ml-1 text-[11px] text-gray-400`,children:`(always on)`}),O.description&&(0,L.jsx)(`span`,{className:`block text-[11px] text-gray-400 mt-0.5`,children:O.description})]})]}),k.map(e=>{let t=s.has(e.name),n=l.includes(e.name);return(0,L.jsxs)(`label`,{className:`flex items-start gap-2 px-1.5 py-1 rounded text-sm cursor-pointer hover:bg-gray-50 ${t?`bg-blue-50`:``}`,children:[(0,L.jsx)(`input`,{type:`checkbox`,checked:t,onChange:()=>A(e.name),className:`mt-0.5`}),(0,L.jsxs)(`span`,{className:`flex-1`,children:[(0,L.jsx)(`span`,{className:`font-medium text-gray-900`,children:e.name}),n&&(0,L.jsx)(`span`,{className:`ml-1.5 px-1 py-px text-[10px] rounded bg-gray-200 text-gray-600`,title:`In your default_profiles (personal config)`,children:`default`}),e.description&&(0,L.jsx)(`span`,{className:`block text-[11px] text-gray-500 mt-0.5`,children:e.description})]})]},e.name)}),k.length===0&&!O&&(0,L.jsxs)(`div`,{className:`text-[11px] text-gray-400 p-1.5`,children:[`No profiles yet. Add them under`,` `,(0,L.jsx)(`code`,{className:`bg-gray-100 px-1 rounded`,children:`knowledge/.loopat/profiles/<name>/.claude/`}),` `,`in your knowledge repo.`]})]}),(0,L.jsxs)(`div`,{className:`flex items-center justify-between mt-1`,children:[(0,L.jsx)(`span`,{className:`text-[11px] text-gray-500`,children:s.size>0?`Selected: ${[...s].join(`, `)}`:`No profiles selected (base + personal only)`}),D&&l.length>0&&(0,L.jsx)(`button`,{type:`button`,onClick:E,className:`text-[11px] text-gray-500 hover:text-gray-900 underline`,title:`Restore default_profiles from your personal config`,children:`reset to defaults`})]}),(0,L.jsx)(`div`,{className:`mt-1.5 px-1.5 py-1 text-[11px] text-gray-600 bg-gray-50 border border-gray-200 rounded`,children:x&&!y?(0,L.jsx)(`span`,{className:`text-gray-400`,children:`computing…`}):y?(0,L.jsxs)(`span`,{title:`Totals across team + selected profiles + their plugins (deduped by name)`,children:[(0,L.jsxs)(`span`,{className:y.plugins>0?``:`text-gray-400`,children:[y.plugins,` plugins`]}),(0,L.jsx)(`span`,{className:`mx-1 text-gray-300`,children:`·`}),(0,L.jsxs)(`span`,{className:y.skills>0?``:`text-gray-400`,children:[y.skills,` skills`]}),(0,L.jsx)(`span`,{className:`mx-1 text-gray-300`,children:`·`}),(0,L.jsxs)(`span`,{className:y.agents>0?``:`text-gray-400`,children:[y.agents,` agents`]}),(0,L.jsx)(`span`,{className:`mx-1 text-gray-300`,children:`·`}),(0,L.jsxs)(`span`,{className:y.hooks>0?``:`text-gray-400`,children:[y.hooks,` hooks`]}),(0,L.jsx)(`span`,{className:`mx-1 text-gray-300`,children:`·`}),(0,L.jsxs)(`span`,{className:y.mcpServers>0?``:`text-gray-400`,children:[y.mcpServers,` MCP servers`]}),(0,L.jsx)(`span`,{className:`mx-1 text-gray-300`,children:`·`}),(0,L.jsxs)(`span`,{className:y.toolchain>0?``:`text-gray-400`,title:`mise.toml [tools] entries, deduped across team + selected profiles`,children:[y.toolchain,` toolchain`]}),x&&(0,L.jsx)(`span`,{className:`ml-1.5 text-gray-400`,children:`·`}),x&&(0,L.jsx)(`span`,{className:`ml-1 text-gray-400`,children:`updating…`})]}):(0,L.jsx)(`span`,{className:`text-gray-400`,children:`—`})})]}),(0,L.jsxs)(k_,{label:`Vault`,hint:`Which credential set to inject. Only this vault is visible inside the loop.`,children:[(0,L.jsxs)(`select`,{value:d,onChange:e=>f(e.target.value),className:`w-full px-3 py-2.5 sm:py-1.5 text-base sm:text-sm border border-gray-300 rounded outline-none focus:border-gray-500 bg-white`,children:[_.length===0&&(0,L.jsx)(`option`,{value:`default`,children:`default`}),_.map(e=>(0,L.jsx)(`option`,{value:e,children:e},e))]}),_.length===0&&(0,L.jsxs)(`div`,{className:`text-[11px] text-gray-400 mt-1`,children:[`No vaults yet — using default. Create more under`,` `,(0,L.jsx)(`code`,{className:`bg-gray-100 px-1 rounded`,children:`personal/.loopat/vaults/<name>/`}),` `,`to isolate prod / test credentials.`]})]})]}),(0,L.jsxs)(`div`,{className:`shrink-0 px-4 sm:px-5 py-3 border-t border-gray-100 flex justify-end gap-3`,children:[(0,L.jsx)(`button`,{type:`button`,onClick:e,className:`px-4 h-11 sm:h-8 text-sm rounded text-gray-700 hover:bg-gray-100 active:bg-gray-200`,children:`cancel`}),(0,L.jsx)(`button`,{type:`submit`,form:`new-loop-form`,disabled:C,className:`px-6 h-11 sm:h-8 text-sm rounded bg-gray-900 text-white hover:bg-gray-700 active:bg-gray-800 disabled:opacity-50 font-medium`,children:C?`creating…`:`create`})]})]})})}function k_({label:e,hint:t,children:n}){return(0,L.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,L.jsx)(`span`,{className:`text-xs text-gray-700 font-medium`,children:e}),n,t&&(0,L.jsx)(`span`,{className:`text-[11px] text-gray-400`,children:t})]})}var A_=e=>typeof e==`boolean`?`${e}`:e===0?`0`:e,j_=Gp,M_=((e,t)=>n=>{if(t?.variants==null)return j_(e,n?.class,n?.className);let{variants:r,defaultVariants:i}=t,a=Object.keys(r).map(e=>{let t=n?.[e],a=i?.[e];if(t===null)return null;let o=A_(t)||A_(a);return r[e][o]}),o=n&&Object.entries(n).reduce((e,t)=>{let[n,r]=t;return r===void 0||(e[n]=r),e},{});return j_(e,a,t?.compoundVariants?.reduce((e,t)=>{let{class:n,className:r,...a}=t;return Object.entries(a).every(e=>{let[t,n]=e;return Array.isArray(n)?n.includes({...i,...o}[t]):{...i,...o}[t]===n})?[...e,n,r]:e},[]),n?.class,n?.className)})(`inline-flex shrink-0 items-center justify-center gap-2 rounded-md text-sm font-medium whitespace-nowrap transition-all outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,{variants:{variant:{default:`bg-primary text-primary-foreground hover:bg-primary/90`,destructive:`bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:bg-destructive/60 dark:focus-visible:ring-destructive/40`,outline:`border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50`,secondary:`bg-secondary text-secondary-foreground hover:bg-secondary/80`,ghost:`hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50`,link:`text-primary underline-offset-4 hover:underline`},size:{default:`h-9 px-4 py-2 has-[>svg]:px-3`,xs:`h-6 gap-1 rounded-md px-2 text-xs has-[>svg]:px-1.5 [&_svg:not([class*='size-'])]:size-3`,sm:`h-8 gap-1.5 rounded-md px-3 has-[>svg]:px-2.5`,lg:`h-10 rounded-md px-6 has-[>svg]:px-4`,icon:`size-9`,"icon-xs":`size-6 rounded-md [&_svg:not([class*='size-'])]:size-3`,"icon-sm":`size-8`,"icon-lg":`size-10`}},defaultVariants:{variant:`default`,size:`default`}});function N_({className:e,variant:t=`default`,size:n=`default`,asChild:r=!1,...i}){return(0,L.jsx)(r?uo:`button`,{"data-slot":`button`,"data-variant":t,"data-size":n,className:lh(M_({variant:t,size:n,className:e})),...i})}function P_({...e}){return(0,L.jsx)(Fl,{"data-slot":`dialog`,...e})}function F_({...e}){return(0,L.jsx)(Il,{"data-slot":`dialog-portal`,...e})}function I_({className:e,...t}){return(0,L.jsx)(Ll,{"data-slot":`dialog-overlay`,className:lh(`fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0`,e),...t})}function L_({className:e,children:t,showCloseButton:n=!0,...r}){return(0,L.jsxs)(F_,{"data-slot":`dialog-portal`,children:[(0,L.jsx)(I_,{}),(0,L.jsxs)(Rl,{"data-slot":`dialog-content`,className:lh(`fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border bg-white p-6 shadow-lg duration-200 outline-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 sm:max-w-lg`,e),...r,children:[t,n&&(0,L.jsxs)(Vl,{"data-slot":`dialog-close`,className:`absolute top-4 right-4 rounded-xs opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,children:[(0,L.jsx)(Jn,{}),(0,L.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]})}function R_({className:e,...t}){return(0,L.jsx)(`div`,{"data-slot":`dialog-header`,className:lh(`flex flex-col gap-2 text-center sm:text-left`,e),...t})}function z_({className:e,...t}){return(0,L.jsx)(zl,{"data-slot":`dialog-title`,className:lh(`text-lg leading-none font-semibold`,e),...t})}function Pee({className:e,...t}){return(0,L.jsx)(Bl,{"data-slot":`dialog-description`,className:lh(`text-sm text-muted-foreground`,e),...t})}function Fee({open:e,onClose:t}){let[n,r]=(0,F.useState)({branch:`…`,commit:`…`}),i=Sg();return(0,F.useEffect)(()=>{e&&vg().then(e=>r(e))},[e]),(0,L.jsx)(P_,{open:e,onOpenChange:e=>!e&&t(),children:(0,L.jsxs)(L_,{className:`sm:max-w-sm bg-white`,children:[(0,L.jsx)(R_,{children:(0,L.jsxs)(z_,{className:`text-center`,children:[(0,L.jsx)(`img`,{src:`/logo.png`,alt:`loopat`,className:`w-full max-w-[240px] mx-auto mb-2`}),`loopat`]})}),(0,L.jsxs)(`div`,{className:`space-y-3 text-sm`,children:[(0,L.jsxs)(`div`,{className:`bg-gray-50 rounded-lg p-3`,children:[(0,L.jsx)(`div`,{className:`text-gray-400 text-xs mb-1`,children:`Server`}),(0,L.jsxs)(`div`,{className:`font-mono text-gray-700`,children:[n.branch,`@`,n.commit.slice(0,7)]})]}),(0,L.jsxs)(`div`,{className:`bg-gray-50 rounded-lg p-3`,children:[(0,L.jsx)(`div`,{className:`text-gray-400 text-xs mb-1`,children:`Build`}),(0,L.jsx)(`div`,{className:`font-mono text-gray-700`,children:i.commit.slice(0,7)}),(0,L.jsx)(`div`,{className:`font-mono text-gray-400 text-xs mt-0.5`,children:new Date(i.time).toLocaleString()})]})]})]})})}function B_(e){let t=[];for(let n of e.effectTasks)try{n()}catch(e){t.push(e)}if(t.length>0){if(t.length===1)throw t[0];for(let e of t)console.error(e);throw AggregateError(t,`Errors during commit`)}}function V_(e){let t=[];for(let n of e.cells)if(n?.type===`effect`&&(n.deps=null,n.cleanup))try{n.cleanup?.()}catch(e){t.push(e)}finally{n.cleanup=void 0}if(t.length>0){if(t.length===1)throw t[0];for(let e of t)console.error(e);throw AggregateError(t,`Errors during cleanup`)}}var H_=typeof process<`u`&&!1,U_=null;function Iee(e,t){e.currentIndex=0;let n=U_;U_=e;try{if(t(),e.isFirstRender=!1,e.cells.length!==e.currentIndex)throw Error(`Rendered ${e.currentIndex} hooks but expected ${e.cells.length}. Hooks must be called in the exact same order in every render.`)}finally{U_=n}}function W_(){if(!U_)throw Error(`No resource fiber available`);return U_}function Lee(e){return H_?U_?.devStrictMode?U_.isFirstRender?`child`:`root`:e?`root`:null:null}function Ree(e,t){let n=e[G_];if(!n)throw Error(`ResourceElement.type is not a valid Resource`);return n(t)}var G_=Symbol(`fnSymbol`);function K_(e,t,n=void 0,r=Lee(!1)){return{type:e,root:t,markDirty:n,devStrictMode:r,cells:[],currentIndex:0,renderContext:void 0,isFirstRender:!0,isMounted:!1,isNeverMounted:!0}}function q_(e){if(!e.isMounted)throw Error(`Tried to unmount a fiber that is already unmounted`);e.isMounted=!1,V_(e)}function J_(e,t){let n={effectTasks:[],props:t,output:void 0};return Iee(e,()=>{e.renderContext=n;try{n.output=Ree(e.type,t)}finally{e.renderContext=void 0}}),n}function Y_(e,t){e.isMounted=!0,H_&&e.isNeverMounted&&e.devStrictMode===`root`&&(e.isNeverMounted=!1,B_(t),V_(e)),e.isNeverMounted=!1,B_(t)}var X_=e=>({version:0,committedVersion:0,dispatchUpdate:e,changelog:[],dirtyCells:[]}),Z_=e=>{for(let t of e.dirtyCells)t.dirty=!1,t.queue.clear(),t.current=t.workInProgress;e.committedVersion=e.version,e.changelog.length=0,e.dirtyCells.length=0},Q_=(e,t)=>{let n=e.version>t;if(e.version=t,n){for(let t of e.dirtyCells)t.dirty=!1,t.queue.clear(),t.workInProgress=t.current;if(e.dirtyCells.length=0,t===e.committedVersion)e.changelog.length=0;else{if(e.committedVersion>t)throw Error(`Version is less than committed version`);for(;e.committedVersion+e.changelog.length>t;)e.changelog.pop();e.changelog.forEach(e=>e()),Z_(e)}}},$_=(e,t)=>{t.dirty||(t.dirty=!0,e.markDirty?.(),e.root.dirtyCells.push(t))},zee=()=>{if(!H_)return null;let e=(0,F.useRef)(0),t=e.current===0;return(0,F.useState)(()=>e.current++),e.current===2?t?`child`:`root`:null};function ev(e){let t=(0,F.useMemo)(()=>X_(e=>r(e)),[]),[n,r]=(0,F.useReducer)((e,n)=>(Q_(t,e),e+ +!!n()),0);Q_(t,n);let i=zee(),a=(0,F.useMemo)(()=>(e.key,K_(e.type,t,void 0,i)),[e.type,e.key,t,i]),o=J_(a,e.props);return(0,F.useLayoutEffect)(()=>()=>q_(a),[a]),(0,F.useLayoutEffect)(()=>{Z_(t),Y_(a,o)}),o.output}function tv(e){let t=e=>({type:t,props:e});return t[G_]=e,t}function nv(e,t){return{...t,key:e}}var rv=(e,t)=>{let n=W_(),r=n.currentIndex++;if(!n.isFirstRender&&r>=n.cells.length)throw Error(`Rendered more hooks than during the previous render. Hooks must be called in the exact same order in every render.`);let i=n.cells[r];if(i||(i=t(),n.cells[r]=i),i.type!==e)throw Error(`Hook order changed between renders`);return i},iv=e=>{W_().renderContext.effectTasks.push(e)},av=(e,t)=>{if(e.renderContext)throw Error(`Resource updated during render`);if(e.isNeverMounted)throw Error(`Resource updated before mount`);e.root.dispatchUpdate(()=>{let n=t();return n?(n(),e.root.changelog.push(n),!0):!1})};function ov(e,t,n,r){let i=rv(`reducer`,()=>{let t=W_(),a=r?r(n):n;return H_&&t.devStrictMode&&r&&r(n),{type:`reducer`,queue:new Set,dirty:!1,workInProgress:a,current:a,reducer:e,dispatch:n=>{let r={action:n,hasEagerState:!1,eagerState:void 0};av(t,()=>t.root.dirtyCells.length===0&&!r.hasEagerState&&(r.eagerState=e(i.workInProgress,n),r.hasEagerState=!0,Object.is(i.current,r.eagerState))?null:()=>{$_(t,i),i.queue.add(r)})}}}),a=W_(),o=e===i.reducer;i.reducer=e;for(let t of i.queue)(!t.hasEagerState||!o)&&(t.eagerState=e(i.workInProgress,t.action),t.hasEagerState=!0),H_&&a.devStrictMode&&e(i.workInProgress,t.action),i.workInProgress=t.eagerState;if(i.queue.clear(),t){let e=t(i.workInProgress);Object.is(e,i.workInProgress)||($_(a,i),i.workInProgress=e)}return[i.workInProgress,i.dispatch]}function sv(e,t,n){return ov(e,void 0,t,n)}function cv(e,t,n,r){return ov(e,t,n,r)}var lv=(e,t)=>typeof t==`function`?t(e):t,uv=e=>typeof e==`function`?e():e;function dv(e){return sv(lv,e,uv)}var fv=(e,t)=>{if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!Object.is(e[n],t[n]))return!1;return!0},pv=()=>({type:`effect`,cleanup:void 0,deps:null});function mv(e,t){let n=rv(`effect`,pv);if(!(t&&n.deps&&fv(n.deps,t))){if(n.deps!==null&&!!t!=!!n.deps)throw Error(`tapEffect called with and without dependencies across re-renders`);iv(()=>{let r=[];try{n.cleanup?.()}catch(e){r.push(e)}finally{n.cleanup=void 0}try{let t=e();if(t!==void 0&&typeof t!=`function`)throw Error(`An effect function must either return a cleanup function or nothing. Received: ${typeof t}`);n.cleanup=t}catch(e){r.push(e)}if(n.deps=t,r.length>0){if(r.length===1)throw r[0];for(let e of r)console.error(e);throw AggregateError(r,`Errors during commit`)}})}}function hv(e){let[t]=dv(()=>({current:e}));return t}function gv(e,t){let[n]=dv(e);return n}var _v=()=>{throw Error(`Memo reducer should not be called`)},vv=(e,t)=>{let n=W_(),[r]=cv(_v,r=>{if(r&&fv(r.deps,t))return r;let i=e();return H_&&n.devStrictMode&&e(),{value:i,deps:t}},null);return r.value},yv=(e,t)=>vv(()=>e,t);function bv(e){let t=hv(e);mv(()=>{t.current=e});let n=W_();return yv(((...e)=>{if(H_&&n.renderContext)throw Error(`tapEffectEvent cannot be called during render`);return t.current(...e)}),[n])}function xv(e,t){let n=W_(),r=hv(0),i=vv(()=>(e.key,K_(e.type,n.root,()=>{r.current++,n.markDirty?.()})),[e.type,e.key,n]),a=t?vv(()=>J_(i,e.props),[i,...t,r.current]):J_(i,e.props);return mv(()=>()=>q_(i),[i]),mv(()=>{Y_(i,a)},[i,a]),a.output}function Sv(e,t){let n=hv(0),r=n.current,i=gv(W_,[]),a=gv(()=>()=>{n.current++,i.markDirty?.()},[]),o=gv(()=>new Map,[]),s=t?yv(e,t):e,c=vv(()=>{let e=s(),t=new Set,n=[],r=0;for(let s=0;s<e.length;s++){let c=e[s],l=c.key;if(l===void 0)throw Error(`tapResources did not provide a key for array at index ${s}`);if(t.has(l))throw Error(`Duplicate key ${l} in tapResources`);t.add(l);let u=o.get(l);if(!u){let e=K_(c.type,i.root,a),t=J_(e,c.props);u={fiber:e,next:t},r++,o.set(l,u),n.push(t.output)}else if(u.fiber.type!==c.type){let e=K_(c.type,i.root,a),t=J_(e,c.props);u.next=[e,t],n.push(t.output)}else u.next=J_(u.fiber,c.props),n.push(u.next.output)}if(o.size>n.length-r)for(let e of o.keys())t.has(e)||(o.get(e).next=`delete`);return n},[s,r]);return mv(()=>()=>{for(let e of o.keys()){let t=o.get(e).fiber;q_(t)}},[]),mv(()=>{for(let[e,t]of o.entries())t.next===`delete`?(t.fiber.isMounted&&q_(t.fiber),o.delete(e)):Array.isArray(t.next)?(q_(t.fiber),t.fiber=t.next[0],Y_(t.fiber,t.next[1])):Y_(t.fiber,t.next)},[c]),c}var Cv=50,wv={schedulers:new Set([]),isScheduled:!1},Tv=class{_task;_isDirty=!1;constructor(e){this._task=e}get isDirty(){return this._isDirty}markDirty(){this._isDirty=!0,wv.schedulers.add(this),Ev()}runTask(){this._isDirty=!1,this._task()}},Ev=()=>{wv.isScheduled||(wv.isScheduled=!0,Ov())},Dv=()=>{try{let e=[],t=0;for(let n of wv.schedulers)if(wv.schedulers.delete(n),n.isDirty){if(t++,t>Cv)throw Error(`Maximum update depth exceeded. This can happen when a resource repeatedly calls setState inside tapEffect.`);try{n.runTask()}catch(t){e.push(t)}}if(e.length>0){if(e.length===1)throw e[0];for(let t of e)console.error(t);throw AggregateError(e,`Errors occurred during flushSync`)}}finally{wv.schedulers.clear(),wv.isScheduled=!1}},Ov=(()=>{if(typeof MessageChannel<`u`){let e=new MessageChannel;return e.port1.onmessage=Dv,()=>e.port2.postMessage(null)}return()=>setTimeout(Dv,0)})(),kv=e=>{let t=wv;wv={schedulers:new Set([]),isScheduled:!0};try{let t=e();return Dv(),t}finally{wv=t}},Av=e=>{let t=gv(()=>new Tv(()=>l(null)),[]),n=gv(()=>[],[]),r=vv(()=>(e.key,K_(e.type,X_(e=>{!t.isDirty&&!e()||(n.push(e),t.markDirty())}))),[e.type,e.key]);Q_(r.root,r.root.committedVersion);let i=J_(r,e.props),a=hv(!1),o=hv(e.props),s=hv(i.output),c=gv(()=>new Set,[]),l=bv(e=>{if(e===null&&(Q_(r.root,2),Q_(r.root,1),n.forEach(e=>{H_&&r.devStrictMode&&e(),e()}),H_&&r.devStrictMode&&J_(r,o.current),e=J_(r,o.current)),t.isDirty)throw Error(`Scheduler is dirty, this should never happen`);Z_(r.root),n.length=0,a.current&&Y_(r,e),!(t.isDirty||s.current===e.output)&&(s.current=e.output,c.forEach(e=>e()))});return mv(()=>(a.current=!0,()=>{a.current=!1,q_(r)}),[r]),mv(()=>{o.current=i.props,Z_(r.root),Y_(r,i),!(t.isDirty||s.current===i.output)&&(s.current=i.output,c.forEach(e=>e()))}),vv(()=>({getValue:()=>s.current,subscribe:e=>(c.add(e),()=>c.delete(e))}),[])},jv=Symbol(`tap.Context`),Mv=e=>({[jv]:e}),Nv=(e,t,n)=>{let r=e[jv];e[jv]=t;try{return n()}finally{e[jv]=r}},Pv=e=>e[jv],Fv=Symbol(`assistant-ui.store.clientIndex`),Iv=e=>e[Fv],Lv=Mv([]),Rv=()=>Pv(Lv),zv=(e,t)=>{let n=Rv();return Nv(Lv,vv(()=>[...n,e],[n,e]),t)},Bv=new Set([`$$typeof`,`nodeType`,`then`]),Vv=(e,t)=>{if(e===Symbol.toStringTag)return t;if(typeof e!=`symbol`){if(e===`toJSON`)return()=>t;if(!Bv.has(e))return!1}},Hv=class{getOwnPropertyDescriptor(e,t){let n=this.get(e,t);if(n!==void 0)return{value:n,writable:!1,enumerable:!0,configurable:!1}}set(){return!1}setPrototypeOf(){return!1}defineProperty(){return!1}deleteProperty(){return!1}preventExtensions(){return!1}},Uv=e=>{let t=tv(e);return e=>{let n=t(e);return e.key===void 0?n:nv(e.key,n)}},Wv=Symbol(`assistant-ui.store.getValue`),Gv=e=>{let t=e[Wv];if(!t)throw Error(`Client scope contains a non-client resource. Ensure your Derived get() returns a client created with tapClientResource(), not a plain resource.`);return t.getState?.()},Kv=new Map;function qv(e){let t=Kv.get(e);return t||(t=function(...t){if(!this||typeof this!=`object`)throw Error(`Method "${String(e)}" called without proper context. This may indicate the function was called incorrectly.`);let n=this[Wv];if(!n)throw Error(`Method "${String(e)}" called on invalid client proxy. Ensure you are calling this method on a valid client instance.`);let r=n[e];if(!r)throw Error(`Method "${String(e)}" is not implemented.`);if(typeof r!=`function`)throw Error(`"${String(e)}" is not a function.`);return r(...t)},Kv.set(e,t)),t}var Jv=class extends Hv{outputRef;index;boundFns;cachedReceiver;constructor(e,t){super(),this.outputRef=e,this.index=t}get(e,t,n){if(t===Wv)return this.outputRef.current;if(t===Fv)return this.index;let r=Vv(t,`ClientProxy`);if(r!==!1)return r;let i=this.outputRef.current[t];if(typeof i==`function`){this.cachedReceiver!==n&&(this.boundFns=new Map,this.cachedReceiver=n);let e=this.boundFns.get(t);return e||(e=qv(t).bind(n),this.boundFns.set(t,e)),e}return i}ownKeys(){return Object.keys(this.outputRef.current)}has(e,t){return t===Wv||t===Fv?!0:t in this.outputRef.current}},Yv=Uv(e=>{let t=hv(null),n=Rv().length,r=vv(()=>new Proxy({},new Jv(t,n)),[n]),i=zv(r,()=>xv(e));return t.current||=i,mv(()=>{t.current=i}),{methods:r,state:i.getState?.(),key:e.key}}),Xv=e=>xv(Yv(e)),Zv=Symbol(`assistant-ui.store.proxiedAssistantState`),Qv=e=>e===`on`||e===`subscribe`||typeof e==`symbol`,$v=e=>{class t extends Hv{get(t,n){let r=Vv(n,`AssistantState`);if(r!==!1)return r;let i=n;if(!Qv(i))return Gv(e[i]())}ownKeys(){return Object.keys(e).filter(e=>!Qv(e))}has(t,n){return!Qv(n)&&n in e}}return new Proxy({},new t)},ey=e=>e[Zv],ty=()=>()=>{},ny=e=>{let t=(()=>{throw Error(e)});return t.source=null,t.query=null,t},ry=new Proxy({},new class extends Hv{get(e,t){if(t===`subscribe`||t===`on`)return ty;if(t===Zv)return iy;let n=Vv(t,`DefaultAssistantClient`);return n===!1?ny(`You are using a component or hook that requires an AuiProvider. Wrap your component in an <AuiProvider> component.`):n}ownKeys(){return[`subscribe`,`on`,Zv]}has(e,t){return t===`subscribe`||t===`on`||t===Zv}}),iy=$v(ry),ay=()=>new Proxy({},{get(e,t){let n=Vv(t,`AssistantClient`);return n===!1?ny(`The current scope does not have a "${String(t)}" property.`):n}}),oy=(0,F.createContext)(ry),sy=()=>(0,F.useContext)(oy),cy=({value:e,children:t})=>(0,L.jsx)(oy.Provider,{value:e,children:t}),ly=tv(e=>null),uy=Symbol(`assistant-ui.transform-scopes`);function dy(e,t){let n=e;if(n[uy])throw Error(`transformScopes is already attached to this resource`);n[uy]=t}function fy(e){return e[uy]}function py(e,t){let n={...e},r=new Set,i=!0;for(;i;){i=!1;for(let e of Object.values(n)){if(e.type===ly||r.has(e.type))continue;r.add(e.type);let a=fy(e.type);if(a){a(n,t),i=!0;break}}}let a={},o={};for(let[e,t]of Object.entries(n))t.type===ly?o[e]=t:a[e]=t;return{rootClients:a,derivedClients:o}}var my=e=>vv(()=>e,[...Object.entries(e).flat()]),hy=(e,t)=>{let{rootClients:n,derivedClients:r}=py(e,t);return{rootClients:my(n),derivedClients:my(r)}},gy=e=>typeof e==`string`?{scope:e.split(`.`)[0],event:e}:{scope:e.scope,event:e.event},_y=tv(()=>gv(()=>{let e=new Map,t=new Set,n=new Set;return{on(n,r){let i=r;if(n===`*`)return t.add(i),()=>t.delete(i);let a=e.get(n);return a||(a=new Set,e.set(n,a)),a.add(i),()=>{a.delete(i),a.size===0&&e.delete(n)}},emit(n,r,i){let a=e.get(n);!a&&t.size===0||queueMicrotask(()=>{let e=[];if(a)for(let t of a)try{t(r,i)}catch(t){e.push(t)}if(t.size>0){let a={event:n,payload:r};for(let n of t)try{n(a,i)}catch(t){e.push(t)}}if(e.length>0){if(e.length===1)throw e[0];for(let t of e)console.error(t);throw AggregateError(e,`Errors occurred during event emission`)}})},subscribe(e){return n.add(e),()=>n.delete(e)},notifySubscribers(){for(let e of n)try{e()}catch(e){console.error(`NotificationManager: subscriber callback error`,e)}}}},[])),vy=Mv(null),yy=(e,t)=>Nv(vy,e,t),by=()=>{let e=Pv(vy);if(!e)throw Error(`AssistantTapContext is not available`);return e},xy=()=>by().clientRef,Sy=()=>{let{emit:e}=by(),t=Rv();return bv((n,r)=>{e(n,r,t)})},Cy=e=>vv(()=>e,e),wy=tv(({element:e,emit:t,clientRef:n})=>{let{methods:r,state:i}=yy({clientRef:n,emit:t},()=>Xv(e));return vv(()=>({state:i,methods:r}),[r,i])}),Ty=tv(({element:e,notifications:t,clientRef:n,name:r})=>{let i=Av(wy({element:e,emit:t.emit,clientRef:n}));return mv(()=>i.subscribe(t.notifySubscribers),[i,t]),vv(()=>{let e=()=>i.getValue().methods;return Object.defineProperties(e,{source:{value:`root`,writable:!1},query:{value:{},writable:!1},name:{value:r,configurable:!0}}),e},[i,r])}),Ey=tv(()=>vv(()=>({clients:[],subscribe:void 0,on:void 0}),[])),Dy=tv(({clients:e,clientRef:t})=>{let n=xv(_y());mv(()=>t.parent.subscribe(n.notifySubscribers),[t,n]);let r=Cy(Sv(()=>Object.keys(e).map(r=>nv(r,Ty({element:e[r],notifications:n,clientRef:t,name:r}))),[e,n,t]));return vv(()=>({clients:r,subscribe:n.subscribe,on:function(e,r){if(!this)throw Error(`const { on } = useAui() is not supported. Use aui.on() instead.`);let{scope:i,event:a}=gy(e);if(i!==`*`&&this[i].source===null)throw Error(`Scope "${i}" is not available. Use { scope: "*", event: "${a}" } to listen globally.`);let o=n.on(a,(e,t)=>{if(i===`*`){r(e);return}let n=this[i]();n===t[Iv(n)]&&r(e)});if(i!==`*`&&t.parent[i].source===null)return o;let s=t.parent.on(e,r);return()=>{o(),s()}}}),[r,n,t])}),Oy=(e,t,n)=>{if(`source`in e&&`query`in e)return e;if(n.dep===e)return n.meta;let r=e.getMeta(t.current);return n.meta=r,n.dep=e,r},ky=tv(({element:e,clientRef:t,name:n})=>{let r=bv(()=>e.props);return vv(()=>{let e=()=>r().get(t.current),i={};return Object.defineProperties(e,{source:{get:()=>Oy(r(),t,i).source},query:{get:()=>Oy(r(),t,i).query},name:{value:n,configurable:!0}}),e},[t,n])}),Ay=tv(({clients:e,clientRef:t})=>Cy(Sv(()=>Object.keys(e).map(n=>nv(n,ky({element:e[n],clientRef:t,name:n}))),[e,t]))),jy=tv(({parent:e,clients:t})=>{let{rootClients:n,derivedClients:r}=hy(t,e),i=hv({parent:e,current:null}).current;mv(()=>{i.current=s});let a=xv(Object.keys(n).length>0?Dy({clients:n,clientRef:i}):Ey()),o=xv(Ay({clients:r,clientRef:i})),s=vv(()=>{let t=e===ry?ay():e,n=Object.create(t);Object.assign(n,{subscribe:a.subscribe??e.subscribe,on:a.on??e.on,[Zv]:$v(n)});for(let e of a.clients)n[e.name]=e;for(let e of o)n[e.name]=e;return n},[e,a,o]);return i.current===null&&(i.current=s),s});function My(e,{parent:t}={parent:sy()}){if(e)return ev(jy({parent:t??ry,clients:e}));if(t===null)throw Error(`received null parent, this usage is not allowed`);return t}var Ny=e=>{let t=My(),n=ey(t),r=(0,F.useSyncExternalStore)(t.subscribe,()=>e(n),()=>e(n));if(r===n)throw Error(`You tried to return the entire AssistantState. This is not supported due to technical limitations.`);return(0,F.useDebugValue)(r),r},Bee=F.createContext(!0);function Py(){throw Error(`A function wrapped in useEffectEvent can't be called during rendering.`)}var Vee=`use`in F.default?()=>{try{return F.use(Bee)}catch{return!1}}:()=>!1;function Hee(e){let t=F.useRef(Py);return F.useInsertionEffect(()=>{t.current=e},[e]),(...e)=>{Vee()&&Py();let n=t.current;return n(...e)}}var Fy=(e,t)=>{let n=My(),r=Hee(t),{scope:i,event:a}=gy(e);(0,F.useEffect)(()=>n.on({scope:i,event:a},r),[n,i,a,r])},Uee=e=>{let t=My(),n=(0,F.useRef)(!1),r=n.current?null:e(t);return Ny(()=>n.current?e(t):r),()=>(n.current=!0,e(t))},Wee=Object.freeze({});function Iy({getItemState:e,children:t}){return Gee(t(Uee(e)))}var Gee=e=>{let t=typeof e==`object`&&e&&`type`in e?e:null,n=t?.type,r=t?.key;return(0,F.useMemo)(()=>t,[n,r,typeof t?.props==`object`&&t.props!=null&&Object.entries(t.props).length===0?Wee:t?.props])??e},Ly=({children:e,condition:t})=>Ny(t)?e:null;Ly.displayName=`AuiIf`;var Kee=Uv(e=>{if(e.key===void 0)throw Error(`tapClientResource: Element has no key`);return xv(Yv(e))});function Ry(e,t){let n=Sv(()=>e().map(e=>Kee(e)),t),r=vv(()=>Object.keys(n),[n]),i=vv(()=>n.reduce((e,t,n)=>(e[t.key]=n,e),{}),[n]);return{state:vv(()=>n.map(e=>e.state),[n]),get:e=>{if(`index`in e){if(e.index<0||e.index>=r.length)throw Error(`tapClientLookup: Index ${e.index} out of bounds (length: ${r.length})`);return n[e.index].methods}let t=i[e.key];if(t===void 0)throw Error(`tapClientLookup: Key "${e.key}" not found`);return n[t].methods}}}var zy=e=>{let t,n=new Set,r=(e,r)=>{let i=typeof e==`function`?e(t):e;if(!Object.is(i,t)){let e=t;t=r??(typeof i!=`object`||!i)?i:Object.assign({},t,i),n.forEach(n=>n(t,e))}},i=()=>t,a={setState:r,getState:i,getInitialState:()=>o,subscribe:e=>(n.add(e),()=>n.delete(e))},o=t=e(r,i,a);return a},qee=(e=>e?zy(e):zy),Jee=e=>e;function Yee(e,t=Jee){let n=F.useSyncExternalStore(e.subscribe,F.useCallback(()=>t(e.getState()),[e,t]),F.useCallback(()=>t(e.getInitialState()),[e,t]));return F.useDebugValue(n),n}var By=e=>{let t=qee(e),n=e=>Yee(t,e);return Object.assign(n,t),n},Vy=(e=>e?By(e):By),Xee=n(((e,t)=>{var n=typeof Buffer<`u`,r=/"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/,i=/"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;function a(e,t,a){a==null&&typeof t==`object`&&t&&(a=t,t=void 0),n&&Buffer.isBuffer(e)&&(e=e.toString()),e&&e.charCodeAt(0)===65279&&(e=e.slice(1));let s=JSON.parse(e,t);if(typeof s!=`object`||!s)return s;let c=a&&a.protoAction||`error`,l=a&&a.constructorAction||`error`;if(c===`ignore`&&l===`ignore`)return s;if(c!==`ignore`&&l!==`ignore`){if(r.test(e)===!1&&i.test(e)===!1)return s}else if(c!==`ignore`&&l===`ignore`){if(r.test(e)===!1)return s}else if(i.test(e)===!1)return s;return o(s,{protoAction:c,constructorAction:l,safe:a&&a.safe})}function o(e,{protoAction:t=`error`,constructorAction:n=`error`,safe:r}={}){let i=[e];for(;i.length;){let e=i;i=[];for(let a of e){if(t!==`ignore`&&Object.prototype.hasOwnProperty.call(a,`__proto__`)){if(r===!0)return null;if(t===`error`)throw SyntaxError(`Object contains forbidden prototype property`);delete a.__proto__}if(n!==`ignore`&&Object.prototype.hasOwnProperty.call(a,`constructor`)&&a.constructor!==null&&typeof a.constructor==`object`&&Object.prototype.hasOwnProperty.call(a.constructor,`prototype`)){if(r===!0)return null;if(n===`error`)throw SyntaxError(`Object contains forbidden prototype property`);delete a.constructor}for(let e in a){let t=a[e];t&&typeof t==`object`&&i.push(t)}}}return e}function s(e,t,n){let{stackTraceLimit:r}=Error;Error.stackTraceLimit=0;try{return a(e,t,n)}finally{Error.stackTraceLimit=r}}function c(e,t){let{stackTraceLimit:n}=Error;Error.stackTraceLimit=0;try{return a(e,t,{safe:!0})}catch{return}finally{Error.stackTraceLimit=n}}t.exports=s,t.exports.default=s,t.exports.parse=s,t.exports.safeParse=c,t.exports.scan=o}));function Zee(e){let t=[`ROOT`],n=-1,r=null,i=[],a;function o(){a!==void 0&&(i.push(JSON.parse(`"${a}"`)),a=void 0)}function s(e,i,a){switch(e){case`"`:n=i,t.pop(),t.push(a),t.push(`INSIDE_STRING`),o();break;case`f`:case`t`:case`n`:n=i,r=i,t.pop(),t.push(a),t.push(`INSIDE_LITERAL`);break;case`-`:t.pop(),t.push(a),t.push(`INSIDE_NUMBER`),o();break;case`0`:case`1`:case`2`:case`3`:case`4`:case`5`:case`6`:case`7`:case`8`:case`9`:n=i,t.pop(),t.push(a),t.push(`INSIDE_NUMBER`),o();break;case`{`:n=i,t.pop(),t.push(a),t.push(`INSIDE_OBJECT_START`),o();break;case`[`:n=i,t.pop(),t.push(a),t.push(`INSIDE_ARRAY_START`),o();break}}function c(e,r){switch(e){case`,`:t.pop(),t.push(`INSIDE_OBJECT_AFTER_COMMA`);break;case`}`:n=r,t.pop(),a=i.pop();break}}function l(e,r){switch(e){case`,`:t.pop(),t.push(`INSIDE_ARRAY_AFTER_COMMA`),a=(Number(a)+1).toString();break;case`]`:n=r,t.pop(),a=i.pop();break}}for(let o=0;o<e.length;o++){let u=e[o];switch(t[t.length-1]){case`ROOT`:s(u,o,`FINISH`);break;case`INSIDE_OBJECT_START`:switch(u){case`"`:t.pop(),t.push(`INSIDE_OBJECT_KEY`),a=``;break;case`}`:n=o,t.pop(),a=i.pop();break}break;case`INSIDE_OBJECT_AFTER_COMMA`:switch(u){case`"`:t.pop(),t.push(`INSIDE_OBJECT_KEY`),a=``;break}break;case`INSIDE_OBJECT_KEY`:switch(u){case`"`:t.pop(),t.push(`INSIDE_OBJECT_AFTER_KEY`);break;case`\\`:t.push(`INSIDE_STRING_ESCAPE`),a+=u;break;default:a+=u;break}break;case`INSIDE_OBJECT_AFTER_KEY`:switch(u){case`:`:t.pop(),t.push(`INSIDE_OBJECT_BEFORE_VALUE`);break}break;case`INSIDE_OBJECT_BEFORE_VALUE`:s(u,o,`INSIDE_OBJECT_AFTER_VALUE`);break;case`INSIDE_OBJECT_AFTER_VALUE`:c(u,o);break;case`INSIDE_STRING`:switch(u){case`"`:t.pop(),n=o,a=i.pop();break;case`\\`:t.push(`INSIDE_STRING_ESCAPE`);break;default:n=o}break;case`INSIDE_ARRAY_START`:switch(u){case`]`:n=o,t.pop(),a=i.pop();break;default:n=o,a=`0`,s(u,o,`INSIDE_ARRAY_AFTER_VALUE`);break}break;case`INSIDE_ARRAY_AFTER_VALUE`:switch(u){case`,`:t.pop(),t.push(`INSIDE_ARRAY_AFTER_COMMA`),a=(Number(a)+1).toString();break;case`]`:n=o,t.pop(),a=i.pop();break;default:n=o;break}break;case`INSIDE_ARRAY_AFTER_COMMA`:s(u,o,`INSIDE_ARRAY_AFTER_VALUE`);break;case`INSIDE_STRING_ESCAPE`:t.pop(),t[t.length-1]===`INSIDE_STRING`?n=o:t[t.length-1]===`INSIDE_OBJECT_KEY`&&(a+=u);break;case`INSIDE_NUMBER`:switch(u){case`0`:case`1`:case`2`:case`3`:case`4`:case`5`:case`6`:case`7`:case`8`:case`9`:n=o;break;case`e`:case`E`:case`-`:case`.`:break;case`,`:t.pop(),a=i.pop(),t[t.length-1]===`INSIDE_ARRAY_AFTER_VALUE`&&l(u,o),t[t.length-1]===`INSIDE_OBJECT_AFTER_VALUE`&&c(u,o);break;case`}`:t.pop(),a=i.pop(),t[t.length-1]===`INSIDE_OBJECT_AFTER_VALUE`&&c(u,o);break;case`]`:t.pop(),a=i.pop(),t[t.length-1]===`INSIDE_ARRAY_AFTER_VALUE`&&l(u,o);break;default:t.pop(),a=i.pop();break}break;case`INSIDE_LITERAL`:{let i=e.substring(r,o+1);!`false`.startsWith(i)&&!`true`.startsWith(i)&&!`null`.startsWith(i)?(t.pop(),t[t.length-1]===`INSIDE_OBJECT_AFTER_VALUE`?c(u,o):t[t.length-1]===`INSIDE_ARRAY_AFTER_VALUE`&&l(u,o)):n=o;break}}}let u=e.slice(0,n+1);for(let n=t.length-1;n>=0;n--)switch(t[n]){case`INSIDE_STRING`:u+=`"`;break;case`INSIDE_OBJECT_KEY`:case`INSIDE_OBJECT_AFTER_KEY`:case`INSIDE_OBJECT_AFTER_COMMA`:case`INSIDE_OBJECT_START`:case`INSIDE_OBJECT_BEFORE_VALUE`:case`INSIDE_OBJECT_AFTER_VALUE`:u+=`}`;break;case`INSIDE_ARRAY_START`:case`INSIDE_ARRAY_AFTER_COMMA`:case`INSIDE_ARRAY_AFTER_VALUE`:u+=`]`;break;case`INSIDE_LITERAL`:{let t=e.substring(r,e.length);`true`.startsWith(t)?u+=`true`.slice(t.length):`false`.startsWith(t)?u+=`false`.slice(t.length):`null`.startsWith(t)&&(u+=`null`.slice(t.length))}}return[u,i]}var Hy=e(Xee(),1),Uy=Symbol(`aui.parse-partial-json-object.meta`),Qee=e=>e?.[Uy],Wy=e=>{if(e.length===0)return{[Uy]:{state:`partial`,partialPath:[]}};try{let t=Hy.default.parse(e);if(typeof t!=`object`||!t)throw Error(`argsText is expected to be an object`);return t[Uy]={state:`complete`,partialPath:[]},t}catch{try{let[t,n]=Zee(e),r=Hy.default.parse(t);if(typeof r!=`object`||!r)throw Error(`argsText is expected to be an object`);return r[Uy]={state:`partial`,partialPath:n},r}catch{return}}},Gy=(e,t,n)=>{if(typeof e!=`object`||!e)return t.state;if(t.state===`complete`)return`complete`;if(n.length===0)return t.state;let[r,...i]=n;if(!Object.hasOwn(e,r))return`partial`;let[a,...o]=t.partialPath;if(r!==a)return`complete`;let s=e[r];return Gy(s,{state:`partial`,partialPath:o},i)},Ky=(e,t)=>{let n=Qee(e);if(!n)throw Error(`unable to determine object state`);return Gy(e,n,t.map(String))};async function*$ee(){let e=this.getReader();try{for(;;){let{done:t,value:n}=await e.read();if(t)break;yield n}}finally{e.releaseLock()}}function qy(e){return e[Symbol.asyncIterator]??=$ee,e}var Jy=()=>{let e,t,n=new Promise((n,r)=>{e=n,t=r});if(!e||!t)throw Error(`Failed to create promise`);return{promise:n,resolve:e,reject:t}},ete=()=>{let e=[],t=!1,n,r,i=i=>{i.promise||=i.reader.read().then(({done:a,value:o})=>{i.promise=void 0,a?(e.splice(e.indexOf(i),1),t&&e.length===0&&n.close()):n.enqueue(o),r?.resolve(),r=void 0}).catch(t=>{console.error(t),e.forEach(e=>{e.reader.cancel()}),e.length=0,n.error(t),r?.reject(t),r=void 0})};return{readable:new ReadableStream({start(e){n=e},pull(){return r=Jy(),e.forEach(e=>{i(e)}),r.promise},cancel(){e.forEach(e=>{e.reader.cancel()}),e.length=0}}),isSealed(){return t},seal(){t=!0,e.length===0&&n.close()},addStream(n){if(t)throw Error(`Cannot add streams after the run callback has settled.`);let r={reader:n.getReader()};e.push(r),i(r)},enqueue(e){this.addStream(new ReadableStream({start(t){t.enqueue(e),t.close()}}))}}},Yy=class{_controller;_isClosed=!1;constructor(e){this._controller=e}append(e){return this._controller.enqueue({type:`text-delta`,path:[],textDelta:e}),this}close(){this._isClosed||(this._isClosed=!0,this._controller.enqueue({type:`part-finish`,path:[]}),this._controller.close())}},Xy=e=>new ReadableStream({start(t){return e.start?.(new Yy(t))},pull(t){return e.pull?.(new Yy(t))},cancel(t){return e.cancel?.(t)}}),Zy=()=>{let e;return[Xy({start(t){e=t}}),e]},Qy=class{_controller;_isClosed=!1;_mergeTask;constructor(e){this._controller=e;let t=Xy({start:e=>{this._argsTextController=e}}),n=!1;this._mergeTask=t.pipeTo(new WritableStream({write:e=>{switch(e.type){case`text-delta`:n=!0,this._controller.enqueue(e);break;case`part-finish`:n||this._controller.enqueue({type:`text-delta`,textDelta:`{}`,path:[]}),this._controller.enqueue({type:`tool-call-args-text-finish`,path:[]});break;default:throw Error(`Unexpected chunk type: ${e.type}`)}}}))}get argsText(){return this._argsTextController}_argsTextController;async setResponse(e){this._argsTextController.close(),await Promise.resolve(),this._controller.enqueue({type:`result`,path:[],...e.artifact===void 0?{}:{artifact:e.artifact},result:e.result,isError:e.isError??!1,...e.modelContent===void 0?{}:{modelContent:e.modelContent},...e.messages===void 0?{}:{messages:e.messages}})}async close(){this._isClosed||(this._isClosed=!0,this._argsTextController.close(),await this._mergeTask,this._controller.enqueue({type:`part-finish`,path:[]}),this._controller.close())}},$y=e=>new ReadableStream({start(t){return e.start?.(new Qy(t))},pull(t){return e.pull?.(new Qy(t))},cancel(t){return e.cancel?.(t)}}),eb=()=>{let e;return[$y({start(t){e=t}}),e]},tb=class{value=-1;up(){return++this.value}},nb=class extends TransformStream{constructor(e){super({transform(t,n){n.enqueue({...t,path:[e,...t.path]})}})}};TransformStream;var rb=class extends TransformStream{constructor(e){let t=new tb,n=new Map;super({transform(r,i){r.type===`part-start`&&r.path.length===0&&n.set(t.up(),e.up());let[a,...o]=r.path;if(a===void 0){i.enqueue(r);return}let s=n.get(a);if(s===void 0)throw Error(`Path not found`);i.enqueue({...r,path:[s,...o]})}})}},ib=class extends TransformStream{constructor(e){super();let t=e(super.readable);Object.defineProperty(this,`readable`,{value:t,writable:!1})}},ab=class extends TransformStream{constructor(){let e=[];super({transform(t,n){if(t.type===`part-start`){if(t.path.length!==0){n.error(Error(`Nested parts are not supported`));return}e.push(t.part),n.enqueue(t);return}if(t.type===`text-delta`||t.type===`result`||t.type===`part-finish`||t.type===`tool-call-args-text-finish`){if(t.path.length!==1){n.error(Error(`${t.type} chunks must have a path of length 1`));return}let r=t.path[0];if(r<0||r>=e.length){n.error(Error(`Invalid path index: ${r}`));return}let i=e[r];n.enqueue({...t,meta:i});return}n.enqueue(t)}})}},ob=(e,t=21)=>(n=t)=>{let r=``,i=n|0;for(;i--;)r+=e[Math.random()*e.length|0];return r},sb=ob(`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`,7),cb=class e{_state;_parentId;constructor(e){this._state=e||{merger:ete(),contentCounter:new tb}}get __internal_isClosed(){return this._state.merger.isSealed()}__internal_getReadable(){return this._state.merger.readable}__internal_subscribeToClose(e){this._state.closeSubscriber=e}_addPart(e,t){this._state.append&&(this._state.append.controller.close(),this._state.append=void 0),this.enqueue({type:`part-start`,part:e,path:[]}),this._state.merger.addStream(t.pipeThrough(new nb(this._state.contentCounter.value)))}merge(e){this._state.merger.addStream(e.pipeThrough(new rb(this._state.contentCounter)))}appendText(e){this._state.append?.kind!==`text`&&(this._state.append={kind:`text`,controller:this.addTextPart()}),this._state.append.controller.append(e)}appendReasoning(e){this._state.append?.kind!==`reasoning`&&(this._state.append={kind:`reasoning`,controller:this.addReasoningPart()}),this._state.append.controller.append(e)}addTextPart(){let[e,t]=Zy();return this._addPart({type:`text`},e),t}addReasoningPart(){let[e,t]=Zy();return this._addPart({type:`reasoning`},e),t}addToolCallPart(e){let t=typeof e==`string`?{toolName:e}:e,n=t.toolName,r=t.toolCallId??sb(),[i,a]=eb();return this._addPart({type:`tool-call`,toolName:n,toolCallId:r,...this._parentId&&{parentId:this._parentId}},i),t.argsText!==void 0&&(a.argsText.append(t.argsText),a.argsText.close()),t.args!==void 0&&(a.argsText.append(JSON.stringify(t.args)),a.argsText.close()),t.response!==void 0&&a.setResponse(t.response),a}_finishedPartStream(){return new ReadableStream({start(e){e.enqueue({type:`part-finish`,path:[]}),e.close()}})}_withParentIdOption(e){return this._parentId?{...e,parentId:this._parentId}:e}appendSource(e){this._addPart(this._withParentIdOption(e),this._finishedPartStream())}appendFile(e){this._addPart(this._withParentIdOption(e),this._finishedPartStream())}appendData(e){this._addPart(this._withParentIdOption(e),this._finishedPartStream())}enqueue(e){this._state.merger.enqueue(e),e.type===`part-start`&&e.path.length===0&&this._state.contentCounter.up()}withParentId(t){let n=new e(this._state);return n._parentId=t,n}close(){this._state.append?.controller?.close(),this._state.merger.seal(),this._state.closeSubscriber?.()}};function lb(e){let t=new cb;return(async()=>{try{await e(t)}catch(e){throw t.__internal_isClosed||t.enqueue({type:`error`,path:[],error:String(e)}),e}finally{t.__internal_isClosed||t.close()}})(),t.__internal_getReadable()}function ub(){let{resolve:e,promise:t}=Jy(),n;return[lb(r=>(n=r,n.__internal_subscribeToClose(e),t)),n]}var db=tv(e=>({getState:()=>e})),fb=tv(e=>{let[t]=dv(()=>({suggestions:(e??[]).map(e=>typeof e==`string`?{title:e,label:``,prompt:e}:{title:e.title,label:e.label,prompt:e.prompt})})),n=Ry(()=>t.suggestions.map((e,t)=>nv(t,db(e))),[t.suggestions]);return{getState:()=>t,suggestion:({index:e})=>n.get({index:e})}}),pb=Object.freeze({type:`complete`}),mb=tv(({parts:e,getMessagePart:t})=>{let[n,r]=dv(!0),i=vv(()=>e[e.length-1]?.status??pb,[e]),a=vv(()=>({parts:e,collapsed:n,status:i}),[e,n,i]);return{getState:()=>a,setCollapsed:r,part:t}}),hb=e=>Array.from(e).map(e=>e.getModelContext()).sort((e,t)=>(t.priority??0)-(e.priority??0)).reduce((e,t)=>{if(t.system&&(e.system?e.system+=`\n\n${t.system}`:e.system=t.system),t.tools)for(let[n,r]of Object.entries(t.tools)){let t=e.tools?.[n];if(t&&t!==r)throw Error(`You tried to define a tool with the name ${n}, but it already exists.`);e.tools||={},e.tools[n]=r}return t.config&&(e.config={...e.config,...t.config}),t.callSettings&&(e.callSettings={...e.callSettings,...t.callSettings}),e},{}),gb=class{_providers=new Set;getModelContext(){return hb(this._providers)}registerModelContextProvider(e){this._providers.add(e);let t=e.subscribe?.(()=>{this.notifySubscribers()});return this.notifySubscribers(),()=>{this._providers.delete(e),t?.(),this.notifySubscribers()}}_subscribers=new Set;notifySubscribers(){for(let e of this._subscribers)e()}subscribe(e){return this._subscribers.add(e),()=>this._subscribers.delete(e)}},_b=1,vb=tv(()=>{let[e]=dv(()=>({version:_b+1})),t=vv(()=>new gb,[]);return{getState:()=>e,getModelContext:()=>t.getModelContext(),subscribe:e=>t.subscribe(e),register:e=>t.registerModelContextProvider(e)}}),yb=tv(({toolkit:e,mcpApp:t})=>{let n=Sv(()=>t?[nv(`mcpApp`,t)]:[],[t])[0],[r,i]=dv(()=>({tools:{}})),a=vv(()=>({tools:r.tools,mcpApp:n}),[r,n]),o=xy(),s=yv((e,t)=>(i(n=>({tools:{...n.tools,[e]:[...n.tools[e]??[],t]}})),()=>{i(n=>({tools:{...n.tools,[e]:n.tools[e]?.filter(e=>e!==t)??[]}}))}),[]);return mv(()=>{if(!e)return;let t=[];for(let[n,r]of Object.entries(e))r.render&&t.push(s(n,r.render));let n=Object.entries(e).reduce((e,[t,n])=>{let{render:r,...i}=n;return e[t]=i,e},{});return t.push(o.current.modelContext().register({getModelContext:()=>({tools:n})})),()=>{t.forEach(e=>e())}},[e,s,o]),{getState:()=>a,setToolUI:s}});dy(yb,(e,t)=>{!e.modelContext&&t.modelContext.source===null&&(e.modelContext=vb())});var bb=tv(()=>{let[e,t]=dv(()=>({renderers:{},fallbacks:[]}));return{getState:()=>e,setDataUI:yv((e,n)=>(t(t=>({...t,renderers:{...t.renderers,[e]:[...t.renderers[e]??[],n]}})),()=>{t(t=>({...t,renderers:{...t.renderers,[e]:t.renderers[e]?.filter(e=>e!==n)??[]}}))}),[]),setFallbackDataUI:yv(e=>(t(t=>({...t,fallbacks:[...t.fallbacks,e]})),()=>{t(t=>({...t,fallbacks:t.fallbacks.filter(t=>t!==e)}))}),[])}}),xb=Symbol.for(`aui.tool-response`),Sb=class e{get[xb](){return!0}artifact;result;isError;modelContent;messages;constructor(e){e.artifact!==void 0&&(this.artifact=e.artifact),this.result=e.result,this.isError=e.isError??!1,e.modelContent!==void 0&&(this.modelContent=e.modelContent),e.messages!==void 0&&(this.messages=e.messages)}static[Symbol.hasInstance](e){return typeof e==`object`&&!!e&&xb in e}static toResponse(t){return t instanceof e?t:new e({result:t===void 0?`<no result>`:t})}};function Cb(e,t,n){try{let r=e();if(typeof r==`object`&&r&&`then`in r)return r.then(t,n);t(r)}catch(e){n(e)}}function wb(e,t){let n=e;for(let e of t){if(n==null)return;n=n[e]}return n}var Tb=class{resolve;reject;disposed=!1;fieldPath;constructor(e,t,n){this.resolve=e,this.reject=t,this.fieldPath=n}update(e){if(!this.disposed)try{if(Ky(e,this.fieldPath)===`complete`){let t=wb(e,this.fieldPath);t!==void 0&&(this.resolve(t),this.dispose())}}catch(e){this.reject(e),this.dispose()}}dispose(){this.disposed=!0}},Eb=class{controller;disposed=!1;fieldPath;constructor(e,t){this.controller=e,this.fieldPath=t}update(e){if(!this.disposed)try{let t=wb(e,this.fieldPath);t!==void 0&&this.controller.enqueue(t),Ky(e,this.fieldPath)===`complete`&&(this.controller.close(),this.dispose())}catch(e){this.controller.error(e),this.dispose()}}dispose(){this.disposed=!0}},Db=class{controller;disposed=!1;fieldPath;lastValue=void 0;constructor(e,t){this.controller=e,this.fieldPath=t}update(e){if(!this.disposed)try{let t=wb(e,this.fieldPath);if(t!==void 0&&typeof t==`string`){let e=t.substring(this.lastValue?.length||0);this.lastValue=t,this.controller.enqueue(e)}Ky(e,this.fieldPath)===`complete`&&(this.controller.close(),this.dispose())}catch(e){this.controller.error(e),this.dispose()}}dispose(){this.disposed=!0}},Ob=class{controller;disposed=!1;fieldPath;processedIndexes=new Set;constructor(e,t){this.controller=e,this.fieldPath=t}update(e){if(!this.disposed)try{let t=wb(e,this.fieldPath);if(!Array.isArray(t))return;for(let n=0;n<t.length;n++)this.processedIndexes.has(n)||Ky(e,[...this.fieldPath,n])===`complete`&&(this.controller.enqueue(t[n]),this.processedIndexes.add(n));Ky(e,this.fieldPath)===`complete`&&(this.controller.close(),this.dispose())}catch(e){this.controller.error(e),this.dispose()}}dispose(){this.disposed=!0}},kb=class{argTextDeltas;handles=new Set;args=Wy(``);constructor(e){this.argTextDeltas=e,this.processStream()}async processStream(){try{let e=``,t=this.argTextDeltas.getReader();for(;;){let{value:n,done:r}=await t.read();if(r)break;e+=n;let i=Wy(e);if(i!==void 0){this.args=i;for(let e of this.handles)e.update(i)}}}catch(e){console.error(`Error processing argument stream:`,e);for(let e of this.handles)e.dispose()}}get(...e){return new Promise((t,n)=>{let r=new Tb(t,n,e);if(this.args&&Ky(this.args,e)===`complete`){let n=wb(this.args,e);if(n!==void 0){t(n);return}}this.handles.add(r),r.update(this.args)})}streamValues(...e){let t=e;return qy(new ReadableStream({start:e=>{let n=new Eb(e,t);this.handles.add(n),n.update(this.args)},cancel:()=>{for(let e of this.handles)if(e instanceof Eb){e.dispose(),this.handles.delete(e);break}}}))}streamText(...e){let t=e;return qy(new ReadableStream({start:e=>{let n=new Db(e,t);this.handles.add(n),n.update(this.args)},cancel:()=>{for(let e of this.handles)if(e instanceof Db){e.dispose(),this.handles.delete(e);break}}}))}forEach(...e){let t=e;return qy(new ReadableStream({start:e=>{let n=new Ob(e,t);this.handles.add(n),n.update(this.args)},cancel:()=>{for(let e of this.handles)if(e instanceof Ob){e.dispose(),this.handles.delete(e);break}}}))}},Ab=class{promise;constructor(e){this.promise=e}get(){return this.promise}},jb=class{args;response;writable;resolve;argsText=``;constructor(){let e=new TransformStream;this.writable=e.writable,this.args=new kb(e.readable);let{promise:t,resolve:n}=Jy();this.resolve=n,this.response=new Ab(t)}async appendArgsTextDelta(e){let t=this.writable.getWriter();try{await t.write(e)}catch(e){console.warn(e)}finally{t.releaseLock()}this.argsText+=e}setResponse(e){this.resolve(e)}result={get:async()=>(await this.response.get()).result}},Mb=class extends ib{constructor(e){let t=new Map,n=new Map;super(r=>{let i=new TransformStream({transform(r,i){switch((r.type!==`part-finish`||r.meta.type!==`tool-call`)&&i.enqueue(r),r.type){case`part-start`:if(r.part.type===`tool-call`){let t=new jb;n.set(r.part.toolCallId,t),e.streamCall({reader:t,toolCallId:r.part.toolCallId,toolName:r.part.toolName})}break;case`text-delta`:if(r.meta.type===`tool-call`){let e=r.meta.toolCallId,t=n.get(e);if(!t)throw Error(`No controller found for tool call`);t.appendArgsTextDelta(r.textDelta)}break;case`result`:{if(r.meta.type!==`tool-call`)break;let{toolCallId:e}=r.meta,t=n.get(e);if(!t)throw Error(`No controller found for tool call`);t.setResponse(new Sb({result:r.result,artifact:r.artifact,isError:r.isError,modelContent:r.modelContent}));break}case`tool-call-args-text-finish`:{if(r.meta.type!==`tool-call`)break;let{toolCallId:a,toolName:o}=r.meta,s=n.get(a);if(!s)throw Error(`No controller found for tool call`);let c=!1,l=Cb(()=>{let t;try{t=Hy.default.parse(s.argsText)}catch(e){throw Error(`Function parameter parsing failed. ${JSON.stringify(e.message)}`)}let n=e.execute({toolCallId:a,toolName:o,args:t});return n!==void 0&&(c=!0,e.onExecutionStart?.(a,o)),n},t=>{if(c&&e.onExecutionEnd?.(a,o),t===void 0)return;let n=new Sb({artifact:t.artifact,result:t.result,isError:t.isError,messages:t.messages,modelContent:t.modelContent});s.setResponse(n),i.enqueue({type:`result`,path:r.path,...n})},t=>{c&&e.onExecutionEnd?.(a,o);let n=new Sb({result:String(t),isError:!0});s.setResponse(n),i.enqueue({type:`result`,path:r.path,...n})});l&&t.set(a,l);break}case`part-finish`:{if(r.meta.type!==`tool-call`)break;let{toolCallId:e}=r.meta,a=t.get(e);a?a.then(()=>{t.delete(e),n.delete(e),i.enqueue(r)}):i.enqueue(r)}}},async flush(){await Promise.all(t.values())}});return r.pipeThrough(new ab).pipeThrough(i)})}},Nb=e=>typeof e==`object`&&!!e&&`~standard`in e&&e[`~standard`].version===1;function Pb(e,t,n,r){let i=e?.[n.toolName];return i?.execute?(async e=>{if(t.aborted)return new Sb({result:`Tool execution was cancelled.`,isError:!0});let a=e;if(Nb(i.parameters)){let e=i.parameters[`~standard`].validate(n.args);e instanceof Promise&&(e=await e),e.issues&&(a=i.experimental_onSchemaValidationError??(()=>{throw Error(`Function parameter validation failed. ${JSON.stringify(e.issues)}`)}))}let o=new Promise(e=>{let n=()=>{queueMicrotask(()=>{queueMicrotask(()=>{e(new Sb({result:`Tool execution was cancelled.`,isError:!0}))})})};t.aborted?n():t.addEventListener(`abort`,n,{once:!0})}),s=(async()=>{let e=await a(n.args,{toolCallId:n.toolCallId,abortSignal:t,human:e=>r(n.toolCallId,e)}),o=Sb.toResponse(e);if(i.toModelOutput&&!o.isError&&o.modelContent===void 0)try{let e=await i.toModelOutput({toolCallId:n.toolCallId,input:n.args,output:o.result});return new Sb({result:o.result,artifact:o.artifact,isError:o.isError,messages:o.messages,modelContent:e})}catch(e){console.warn(`[assistant-stream] tool "${n.toolName}" toModelOutput threw; falling back to default projection.`,e)}return o})();return Promise.race([s,o])})(i.execute):void 0}function Fb(e,t,n,r,i){e?.[r.toolName]?.streamCall?.(n,{toolCallId:r.toolCallId,abortSignal:t,human:e=>i(r.toolCallId,e)})}function Ib(e,t,n,r){let i=typeof e==`function`?e:()=>e,a=typeof t==`function`?t:()=>t;return new Mb({execute:e=>Pb(i(),a(),e,n),streamCall:({reader:e,...t})=>Fb(i(),a(),e,t,n),onExecutionStart:r?.onExecutionStart,onExecutionEnd:r?.onExecutionEnd})}var Lb=e=>{let[,t]=dv(e.getState);return mv(()=>(t(e.getState()),e.subscribe(()=>{t(e.getState())})),[e]),e.getState()},Rb=tv(({runtime:e})=>{let t=Lb(e);return{getState:()=>t,remove:e.remove,__internal_getRuntime:()=>e}}),zb=tv(({runtime:e})=>{let t=Lb(e);return{getState:()=>t,addToolResult:t=>e.addToolResult(t),resumeToolCall:t=>e.resumeToolCall(t),__internal_getRuntime:()=>e}}),Bb=tv(({runtime:e,index:t})=>xv(Rb({runtime:vv(()=>e.getAttachmentByIndex(t),[e,t])}))),Vb=tv(({threadIdRef:e,messageIdRef:t,runtime:n})=>{let r=Lb(n),i=Sy();mv(()=>{let r=[];for(let a of[`send`,`attachmentAdd`]){let o=n.unstable_on(a,()=>{i(`composer.${a}`,{threadId:e.current,...t&&{messageId:t.current}})});r.push(o)}return r.push(n.unstable_on(`attachmentAddError`,n=>{i(`composer.attachmentAddError`,{threadId:e.current,...t&&{messageId:t.current},...n.attachmentId&&{attachmentId:n.attachmentId},reason:n.reason,message:n.message})})),()=>{for(let e of r)e()}},[n,i,e,t]);let a=Ry(()=>r.attachments.map((e,t)=>nv(e.id,Bb({runtime:n,index:t}))),[r.attachments,n]),o=vv(()=>({text:r.text,role:r.role,attachments:a.state,runConfig:r.runConfig,isEditing:r.isEditing,canCancel:r.canCancel,canSend:r.canSend,attachmentAccept:r.attachmentAccept,isEmpty:r.isEmpty,type:r.type??`thread`,dictation:r.dictation,quote:r.quote,queue:[]}),[r,a.state]);return{getState:()=>o,setText:n.setText,setRole:n.setRole,setRunConfig:n.setRunConfig,addAttachment:n.addAttachment,reset:n.reset,clearAttachments:n.clearAttachments,send:n.send,cancel:n.cancel,beginEdit:n.beginEdit??(()=>{throw Error(`beginEdit is not supported in this runtime`)}),startDictation:n.startDictation,stopDictation:n.stopDictation,setQuote:n.setQuote,attachment:e=>`id`in e?a.get({key:e.id}):a.get(e),queueItem:()=>{throw Error(`Queue is not supported in this runtime`)},__internal_getRuntime:()=>n}}),Hb=tv(({runtime:e,index:t})=>xv(Rb({runtime:vv(()=>e.getAttachmentByIndex(t),[e,t])}))),Ub=tv(({runtime:e,index:t})=>xv(zb({runtime:vv(()=>e.getMessagePartByIndex(t),[e,t])}))),Wb=tv(({runtime:e,threadIdRef:t})=>{let n=Lb(e),[r,i]=dv(!1),[a,o]=dv(!1),s=vv(()=>({get current(){return e.getState().id}}),[e]),c=Xv(Vb({runtime:e.composer,threadIdRef:t,messageIdRef:s})),l=Ry(()=>n.content.map((t,n)=>nv(`toolCallId`in t&&t.toolCallId!=null?`toolCallId-${t.toolCallId}`:`index-${n}`,Ub({runtime:e,index:n}))),[n.content,e]),u=Ry(()=>(n.attachments??[]).map((t,n)=>nv(t.id,Hb({runtime:e,index:n}))),[n.attachments,e]),d=vv(()=>({...n,parts:l.state,composer:c.state,isCopied:r,isHovering:a}),[n,l.state,c.state,r,a]);return{getState:()=>d,composer:()=>c.methods,reload:t=>e.reload(t),speak:()=>e.speak(),stopSpeaking:()=>e.stopSpeaking(),submitFeedback:t=>e.submitFeedback(t),switchToBranch:t=>e.switchToBranch(t),getCopyText:()=>e.unstable_getCopyText(),part:e=>`index`in e?l.get({index:e.index}):l.get({key:`toolCallId-${e.toolCallId}`}),attachment:e=>`id`in e?u.get({key:e.id}):u.get(e),setIsCopied:i,setIsHovering:o,__internal_getRuntime:()=>e}}),Gb=tv(({runtime:e,id:t,threadIdRef:n})=>xv(Wb({runtime:vv(()=>e.getMessageById(t),[e,t]),threadIdRef:n}))),Kb=tv(({runtime:e})=>{let t=Lb(e),n=Sy();mv(()=>{let t=[];for(let r of[`runStart`,`runEnd`,`initialize`,`modelContextUpdate`]){let i=e.unstable_on(r,()=>{let t=e.getState()?.threadId||`unknown`;n(`thread.${r}`,{threadId:t})});t.push(i)}return()=>{for(let e of t)e()}},[e,n]);let r=vv(()=>({get current(){return e.getState().threadId}}),[e]),i=Xv(Vb({runtime:e.composer,threadIdRef:r})),a=Ry(()=>t.messages.map(t=>nv(t.id,Gb({runtime:e,id:t.id,threadIdRef:r}))),[t.messages,e,r]),o=vv(()=>({isEmpty:a.state.length===0&&!t.isLoading,isDisabled:t.isDisabled,isLoading:t.isLoading,isRunning:t.isRunning,capabilities:t.capabilities,state:t.state,suggestions:t.suggestions,extras:t.extras,speech:t.speech,voice:t.voice,composer:i.state,messages:a.state}),[t,a,i.state]);return{getState:()=>o,composer:()=>i.methods,append:e.append,startRun:e.startRun,resumeRun:e.resumeRun,cancelRun:e.cancelRun,getModelContext:e.getModelContext,export:e.export,import:e.import,reset:e.reset,stopSpeaking:e.stopSpeaking,connectVoice:e.connectVoice,disconnectVoice:e.disconnectVoice,getVoiceVolume:e.getVoiceVolume,subscribeVoiceVolume:e.subscribeVoiceVolume,muteVoice:e.muteVoice,unmuteVoice:e.unmuteVoice,message:e=>`id`in e?a.get({key:e.id}):a.get(e),__internal_getRuntime:()=>e}}),qb=tv(({runtime:e})=>{let t=Lb(e),n=Sy();return mv(()=>{let t=[];for(let r of[`switchedTo`,`switchedAway`]){let i=e.unstable_on(r,()=>{n(`threadListItem.${r}`,{threadId:e.getState().id})});t.push(i)}return()=>{for(let e of t)e()}},[e,n]),{getState:()=>t,switchTo:e.switchTo,rename:e.rename,archive:e.archive,unarchive:e.unarchive,delete:e.delete,generateTitle:e.generateTitle,initialize:e.initialize,detach:e.detach,__internal_getRuntime:()=>e}}),Jb=tv(({runtime:e,id:t})=>xv(qb({runtime:vv(()=>e.getItemById(t),[e,t])}))),Yb=tv(({runtime:e,__internal_assistantRuntime:t})=>{let n=Lb(e),r=Xv(Kb({runtime:e.main})),i=Ry(()=>Object.keys(n.threadItems).map(t=>nv(t,Jb({runtime:e,id:t}))),[n.threadItems,e]),a=vv(()=>({mainThreadId:n.mainThreadId,newThreadId:n.newThreadId??null,isLoading:n.isLoading,isLoadingMore:n.isLoadingMore,hasMore:n.hasMore,threadIds:n.threadIds,archivedThreadIds:n.archivedThreadIds,threadItems:i.state,main:r.state}),[n,i.state,r.state]);return{getState:()=>a,thread:()=>r.methods,item:e=>{if(e===`main`)return i.get({key:a.mainThreadId});if(`id`in e)return i.get({key:e.id});let{index:t,archived:n=!1}=e,r=n?a.archivedThreadIds[t]:a.threadIds[t];return i.get({key:r})},switchToThread:async t=>{await e.switchToThread(t)},switchToNewThread:async()=>{await e.switchToNewThread()},getLoadThreadsPromise:()=>e.getLoadThreadsPromise(),reload:()=>e.reload(),loadMore:()=>e.loadMore(),__internal_getAssistantRuntime:()=>t}}),Xb=tv(e=>{let t=xy();return mv(()=>e.registerModelContextProvider(t.current.modelContext()),[e,t]),xv(Yb({runtime:e.threads,__internal_assistantRuntime:e}))}),Zb=(e,t)=>{e.thread??=ly({source:`threads`,query:{type:`main`},get:e=>e.threads().thread(`main`)}),e.threadListItem??=ly({source:`threads`,query:{type:`main`},get:e=>e.threads().item(`main`)}),e.composer??=ly({source:`thread`,query:{},get:e=>e.threads().thread(`main`).composer()}),!e.modelContext&&t.modelContext.source===null&&(e.modelContext=vb()),!e.suggestions&&t.suggestions.source===null&&(e.suggestions=fb())},Qb=({index:e,children:t})=>(0,L.jsx)(cy,{value:My({message:ly({source:`thread`,query:{type:`index`,index:e},get:t=>t.thread().message({index:e})}),composer:ly({source:`message`,query:{},get:t=>t.thread().message({index:e}).composer()})}),children:t}),$b=({index:e,children:t})=>(0,L.jsx)(cy,{value:My({part:ly({source:`message`,query:{type:`index`,index:e},get:t=>t.message().part({index:e})})}),children:t}),ex=tv(({text:e,isRunning:t})=>{let n=vv(()=>({type:`text`,text:e,status:t?{type:`running`}:{type:`complete`}}),[e,t]);return{getState:()=>n,addToolResult:()=>{throw Error(`Not supported`)},resumeToolCall:()=>{throw Error(`Not supported`)}}}),tx=({text:e,isRunning:t=!1,children:n})=>(0,L.jsx)(cy,{value:My({part:ex({text:e,isRunning:t})}),children:n}),nx=({startIndex:e,endIndex:t,children:n})=>{let r=Ny(e=>e.message.parts).slice(e,t+1),i=My();return(0,L.jsx)(cy,{value:My({chainOfThought:mb({parts:r,getMessagePart:({index:t})=>{if(t<0||t>=r.length)throw Error(`ChainOfThought part index ${t} is out of bounds (0..${r.length-1})`);return i.message().part({index:e+t})}})}),children:n})},rx=Symbol(`skip-update`);function ix(e,t){if(e===void 0&&t===void 0)return!0;if(e===void 0||t===void 0)return!1;for(let n of Object.keys(e)){let r=e[n],i=t[n];if(!Object.is(r,i))return!1}return!0}var ax=class{_subscribers=new Set;subscribe(e){return this._subscribers.add(e),()=>this._subscribers.delete(e)}waitForUpdate(){return new Promise(e=>{let t=this.subscribe(()=>{t(),e()})})}_notifySubscribers(){let e=[];for(let t of this._subscribers)try{t()}catch(t){e.push(t)}if(e.length>0){if(e.length===1)throw e[0];for(let t of e)console.error(t);throw AggregateError(e)}}},ox=class{_subscriptions=new Set;_connection;get isConnected(){return!!this._connection}notifySubscribers(e){for(let t of this._subscriptions)t(e)}_updateConnection(){if(this._subscriptions.size>0){if(this._connection)return;this._connection=this._connect()}else this._connection?.(),this._connection=void 0}subscribe(e){return this._subscriptions.add(e),this._updateConnection(),()=>{this._subscriptions.delete(e),this._updateConnection()}}},sx=class extends ox{binding;get path(){return this.binding.path}constructor(e){super(),this.binding=e;let t=e.getState();if(t===rx)throw Error(`Entry not available in the store`);this._previousState=t}_previousState;getState=()=>(this.isConnected||this._syncState(),this._previousState);_syncState(){let e=this.binding.getState();return e===rx||ix(e,this._previousState)?!1:(this._previousState=e,!0)}_connect(){return this.binding.subscribe(()=>{this._syncState()&&this.notifySubscribers()})}},cx=class extends ox{binding;get path(){return this.binding.path}constructor(e){super(),this.binding=e}_previousStateDirty=!0;_previousState;getState=()=>{if(!this.isConnected||this._previousStateDirty){let e=this.binding.getState();e!==rx&&(this._previousState=e),this._previousStateDirty=!1}if(this._previousState===void 0)throw Error(`Entry not available in the store`);return this._previousState};_connect(){return this.binding.subscribe(()=>{this._previousStateDirty=!0,this.notifySubscribers()})}},lx=class extends ox{binding;get path(){return this.binding.path}constructor(e){super(),this.binding=e}getState(){return this.binding.getState()}outerSubscribe(e){return this.binding.subscribe(e)}_connect(){let e=()=>{this.notifySubscribers()},t=this.binding.getState(),n=t?.subscribe(e),r=this.outerSubscribe(()=>{let r=this.binding.getState();r!==t&&(t=r,n?.(),n=r?.subscribe(e),e())});return()=>{r?.(),n?.()}}},ux=class extends ox{config;constructor(e){super(),this.config=e}getState(){return this.config.binding.getState()}outerSubscribe(e){return this.config.binding.subscribe(e)}_connect(){let e=e=>{this.notifySubscribers(e)},t=this.config.binding.getState(),n=t?.unstable_on(this.config.event,e),r=this.outerSubscribe(()=>{let r=this.config.binding.getState();r!==t&&(t=r,n?.(),n=r?.unstable_on(this.config.event,e))});return()=>{r?.(),n?.()}}},dx=class{_contextProvider=new gb;registerModelContextProvider(e){return this._contextProvider.registerModelContextProvider(e)}getModelContextProvider(){return this._contextProvider}},fx=e=>e.content.filter(e=>e.type===`text`).map(e=>e.text).join(`
57
57
 
58
58
  `),px=ob(`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`,7),mx=`__optimistic__`,hx=()=>`${mx}${px()}`,gx=Symbol(`autoStatus`),_x=Object.freeze(Object.assign({type:`running`},{[gx]:!0})),vx=Object.freeze(Object.assign({type:`complete`,reason:`unknown`},{[gx]:!0})),yx=Object.freeze(Object.assign({type:`requires-action`,reason:`tool-calls`},{[gx]:!0})),bx=Object.freeze(Object.assign({type:`requires-action`,reason:`interrupt`},{[gx]:!0})),xx=e=>e[gx]===!0,Sx=(e,t,n,r,i)=>e&&i?Object.assign({type:`incomplete`,reason:`error`,error:i},{[gx]:!0}):e&&t?_x:n?bx:r?yx:vx,Cx=(e,t)=>{if(e.startsWith(`data-`))return{type:`data`,name:e.substring(5),data:t}},wx=(e,t,n)=>{let{role:r,id:i,createdAt:a,attachments:o,status:s,metadata:c}=e,l={id:i??t,createdAt:a??new Date},u=typeof e.content==`string`?[{type:`text`,text:e.content}]:e.content,d=({image:e,...t})=>e.match(/^data:image\/(png|jpeg|jpg|gif|webp);base64,(.*)$/)?{...t,image:e}:(console.warn(`Invalid image data format detected`),null);if(r!==`user`&&o?.length)throw Error(`attachments are only supported for user messages`);if(r!==`assistant`&&s)throw Error(`status is only supported for assistant messages`);if(r!==`assistant`&&c?.steps)throw Error(`metadata.steps is only supported for assistant messages`);switch(r){case`assistant`:return{...l,role:r,content:u.map(e=>{let t=e.type;switch(t){case`text`:case`reasoning`:return e.text.trim().length===0?null:e;case`file`:case`source`:return e;case`image`:return d(e);case`data`:return e;case`tool-call`:{let{parentId:t,messages:n,...r}=e,i={...r,toolCallId:e.toolCallId??`tool-${px()}`,...t!==void 0&&{parentId:t},...n!==void 0&&{messages:n}};return e.args?{...i,args:e.args,argsText:e.argsText??JSON.stringify(e.args)}:{...i,args:Wy(e.argsText??``)??{},argsText:e.argsText??``}}default:{let n=Cx(t,e.data);if(n)return n;throw Error(`Unsupported assistant message part type: ${t}`)}}}).filter(e=>!!e),status:s??n,metadata:{unstable_state:c?.unstable_state??null,unstable_annotations:c?.unstable_annotations??[],unstable_data:c?.unstable_data??[],custom:c?.custom??{},steps:c?.steps??[],...c?.timing&&{timing:c.timing},...c?.submittedFeedback&&{submittedFeedback:c.submittedFeedback}}};case`user`:return{...l,role:r,content:u.map(e=>{let t=e.type;switch(t){case`text`:case`image`:case`audio`:case`file`:case`data`:return e;default:{let n=Cx(t,e.data);if(n)return n;throw Error(`Unsupported user message part type: ${t}`)}}}),attachments:(o??[]).map(e=>({...e,content:e.content.map(e=>Cx(e.type,e.data)??e)})),metadata:{custom:c?.custom??{}}};case`system`:if(u.length!==1||u[0].type!==`text`)throw Error(`System messages must have exactly one text message part.`);return{...l,role:r,content:u,metadata:{custom:c?.custom??{}}};default:throw Error(`Unknown message role: ${r}`)}},Tx={fromArray:e=>{let t=e.map(e=>wx(e,px(),Sx(!1,!1,!1,!1,void 0)));return{messages:t.map((e,n)=>({parentId:n>0?t[n-1].id:null,message:e}))}},fromBranchableArray:(e,t)=>{let n=Sx(!1,!1,!1,!1,void 0);return{...t?.headId===void 0?void 0:{headId:t.headId},messages:e.map(({message:e,parentId:t})=>{if(!e.id)throw Error(`ExportedMessageRepository.fromBranchableArray: Each message must have an 'id' field set.`);return{parentId:t,message:wx(e,e.id,n)}})}}},Ex=e=>e.next?Ex(e.next):`current`in e?e:null,Dx=class{func;_value=null;constructor(e){this.func=e}get value(){return this._value===null&&(this._value=this.func()),this._value}dirty(){this._value=null}},Ox=class{messages=new Map;head=null;root={children:[],next:null};updateLevels(e,t){e.level=t;for(let n of e.children){let e=this.messages.get(n);e&&this.updateLevels(e,t+1)}}performOp(e,t,n){let r=t.prev??this.root,i=e??this.root;if(!(n===`relink`&&r===i)){if(n!==`link`&&(r.children=r.children.filter(e=>e!==t.current.id),r.next===t)){let e=r.children.at(-1),t=e?this.messages.get(e):null;if(t===void 0)throw Error(`MessageRepository(performOp/cut): Fallback sibling message not found. This is likely an internal bug in assistant-ui.`);r.next=t}if(n!==`cut`){for(let n=e;n;n=n.prev)if(n.current.id===t.current.id)throw Error(`MessageRepository(performOp/link): A message with the same id already exists in the parent tree. This error occurs if the same message id is found multiple times. This is likely an internal bug in assistant-ui.`);i.children=[...i.children,t.current.id],(Ex(t)===this.head||i.next===null)&&(i.next=t),t.prev=e;let n=e?e.level+1:0;this.updateLevels(t,n)}}}_messages=new Dx(()=>{let e=Array((this.head?.level??-1)+1);for(let t=this.head;t;t=t.prev)e[t.level]=t.current;return e});get headId(){return this.head?.current.id??null}getMessages(e){if(e===void 0||e===this.head?.current.id)return this._messages.value;let t=this.messages.get(e);if(!t)throw Error(`MessageRepository(getMessages): Head message not found. This is likely an internal bug in assistant-ui.`);let n=Array(t.level+1);for(let e=t;e;e=e.prev)n[e.level]=e.current;return n}addOrUpdateMessage(e,t){let n=this.messages.get(t.id),r=e?this.messages.get(e):null;if(r===void 0)throw Error(`MessageRepository(addOrUpdateMessage): Parent message not found. This is likely an internal bug in assistant-ui.`);if(n){n.current=t,this.performOp(r,n,`relink`),this._messages.dirty();return}let i={prev:r,current:t,next:null,children:[],level:r?r.level+1:0};this.messages.set(t.id,i),this.performOp(r,i,`link`),this.head===r&&(this.head=i),this._messages.dirty()}getMessage(e){let t=this.messages.get(e);if(!t)throw Error(`MessageRepository(updateMessage): Message not found. This is likely an internal bug in assistant-ui.`);return{parentId:t.prev?.current.id??null,message:t.current,index:t.level}}appendOptimisticMessage(e,t){let n;do n=hx();while(this.messages.has(n));return this.addOrUpdateMessage(e,wx(t,n,{type:`running`})),n}deleteMessage(e,t){let n=this.messages.get(e);if(!n)throw Error(`MessageRepository(deleteMessage): Message not found. This is likely an internal bug in assistant-ui.`);let r=t===void 0?n.prev:t===null?null:this.messages.get(t);if(r===void 0)throw Error(`MessageRepository(deleteMessage): Replacement not found. This is likely an internal bug in assistant-ui.`);for(let e of n.children){let t=this.messages.get(e);if(!t)throw Error(`MessageRepository(deleteMessage): Child message not found. This is likely an internal bug in assistant-ui.`);this.performOp(r,t,`relink`)}this.performOp(null,n,`cut`),this.messages.delete(e),this.head===n&&(this.head=Ex(r??this.root)),this._messages.dirty()}getBranches(e){let t=this.messages.get(e);if(!t)throw Error(`MessageRepository(getBranches): Message not found. This is likely an internal bug in assistant-ui.`);let{children:n}=t.prev??this.root;return n}switchToBranch(e){let t=this.messages.get(e);if(!t)throw Error(`MessageRepository(switchToBranch): Branch not found. This is likely an internal bug in assistant-ui.`);let n=t.prev??this.root;n.next=t,this.head=Ex(t),this._messages.dirty()}resetHead(e){if(e===null){this.clear();return}let t=this.messages.get(e);if(!t)throw Error(`MessageRepository(resetHead): Branch not found. This is likely an internal bug in assistant-ui.`);if(t.children.length>0){let e=t=>{for(let n of t.children){let t=this.messages.get(n);t&&(e(t),this.messages.delete(n))}};e(t),t.children=[],t.next=null}this.head=t;for(let e=t;e;e=e.prev)e.prev?e.prev.next=e:this.root.next=e;this._messages.dirty()}clear(){this.messages.clear(),this.head=null,this.root={children:[],next:null},this._messages.dirty()}export(){let e=[];for(let[,t]of this.messages)e.push({message:t.current,parentId:t.prev?.current.id??null});return{headId:this.head?.current.id??null,messages:e}}import({headId:e,messages:t}){for(let{message:e,parentId:n}of t)this.addOrUpdateMessage(n,e);this.resetHead(e??t.at(-1)?.message.id??null)}};function kx(e,t){if(t===`*`)return!0;let n=t.split(`,`).map(e=>e.trim().toLowerCase()),r=`.${e.name.split(`.`).pop().toLowerCase()}`,i=e.type.toLowerCase();for(let e of n){if(e.startsWith(`.`)&&e===r||e.includes(`/`)&&e===i)return!0;if(e.endsWith(`/*`)){let t=e.split(`/`)[0];if(i.startsWith(`${t}/`))return!0}}return!1}function Ax(e,t){return e.length===t.length?e.every((e,n)=>e.id===t[n].id):!1}function jx(e){let t=px();return e.type===`image`?{id:t,type:`image`,name:e.filename??`image`,content:[e],status:{type:`complete`}}:e.type===`file`?{id:t,type:`document`,name:e.filename??`document`,contentType:e.mimeType,content:[e],status:{type:`complete`}}:e.type===`audio`?{id:t,type:`audio`,name:`audio.${e.audio.format}`,contentType:`audio/${e.audio.format}`,content:[e],status:{type:`complete`}}:{id:t,type:`data`,name:e.name,content:[e],status:{type:`complete`}}}function Mx(e){let t=[];for(let n of e)n.type!==`text`&&t.push(jx(n));return t}var Nx=e=>e.status.type===`complete`,Px=class extends ax{isEditing=!0;get attachmentAccept(){return this.getAttachmentAdapter()?.accept??`*`}_attachments=[];get attachments(){return this._attachments}setAttachments(e){this._attachments=e,this._notifySubscribers()}get isEmpty(){return!this.text.trim()&&!this.attachments.length}_text=``;get text(){return this._text}_role=`user`;get role(){return this._role}_runConfig={};get runConfig(){return this._runConfig}_quote=void 0;get quote(){return this._quote}setQuote(e){this._quote!==e&&(this._quote=e,this._notifySubscribers())}setText(e){if(this._text!==e){if(this._text=e,this._dictation){this._dictationBaseText=e,this._currentInterimText=``;let{status:t,inputDisabled:n}=this._dictation;this._dictation=n?{status:t,inputDisabled:n}:{status:t}}this._notifySubscribers()}}setRole(e){this._role!==e&&(this._role=e,this._notifySubscribers())}setRunConfig(e){this._runConfig!==e&&(this._runConfig=e,this._notifySubscribers())}_emptyTextAndAttachments(){this._attachments=[],this._text=``,this._notifySubscribers()}async _onClearAttachments(){let e=this.getAttachmentAdapter();if(e){let t=this._attachments.filter(e=>!Nx(e));await Promise.all(t.map(t=>e.remove(t)))}}async reset(){if(this._attachments.length===0&&this._text===``&&this._role===`user`&&Object.keys(this._runConfig).length===0&&this._quote===void 0)return;this._role=`user`,this._runConfig={},this._quote=void 0;let e=this._onClearAttachments();this._emptyTextAndAttachments(),await e}async clearAttachments(){let e=this._onClearAttachments();this.setAttachments([]),await e}async send(e){if(!this.canSend)return;this._dictationSession&&(this._dictationSession.cancel(),this._cleanupDictation());let t=this.getAttachmentAdapter(),n=this.attachments.length>0?Promise.all(this.attachments.map(async e=>{if(Nx(e))return e;if(!t)throw Error(`Attachments are not supported`);return await t.send(e)})):[],r=this.text,i=this._quote;this._quote=void 0,this._emptyTextAndAttachments();let a={createdAt:new Date,role:this.role,content:r?[{type:`text`,text:r}]:[],attachments:await n,runConfig:this.runConfig,metadata:{custom:{...i?{quote:i}:{}}}};this.handleSend(a,e),this._notifyEventSubscribers(`send`,{})}cancel(){this.handleCancel()}async addAttachment(e){if(!(e instanceof File)){let t=this.getAttachmentAdapter();if(t&&!kx({name:e.name,type:e.contentType??``},t.accept)){let n=`File type ${e.contentType||`unknown`} is not accepted. Accepted types: ${t.accept}`,r=Error(n);throw this._safeEmitAttachmentAddError(`not-accepted`,n,void 0,r),r}let n={id:e.id??px(),type:e.type??`document`,name:e.name,contentType:e.contentType,content:e.content,status:{type:`complete`}};this._attachments=[...this._attachments,n],this._notifySubscribers(),this._notifyEventSubscribers(`attachmentAdd`,{});return}let t=e=>{let t=this._attachments.findIndex(t=>t.id===e.id);t===-1?this._attachments=[...this._attachments,e]:this._attachments=[...this._attachments.slice(0,t),e,...this._attachments.slice(t+1)],this._notifySubscribers()},n=this.getAttachmentAdapter();if(!n){let e=`Attachments are not supported`,t=Error(e);throw this._safeEmitAttachmentAddError(`no-adapter`,e,void 0,t),t}if(!kx({name:e.name,type:e.type},n.accept)){let t=`File type ${e.type||`unknown`} is not accepted. Accepted types: ${n.accept}`,r=Error(t);throw this._safeEmitAttachmentAddError(`not-accepted`,t,void 0,r),r}let r;try{let i=n.add({file:e});if(Symbol.asyncIterator in i)for await(let e of i)r=e,t(e);else r=await i,t(r)}catch(e){throw r&&t({...r,status:{type:`incomplete`,reason:`error`}}),this._safeEmitAttachmentAddError(`adapter-error`,e instanceof Error?e.message:String(e),r?.id,e instanceof Error?e:void 0),e}r?.status.type===`incomplete`&&r.status.reason===`error`?this._safeEmitAttachmentAddError(`adapter-error`,`Attachment upload did not complete successfully.`,r?.id):this._notifyEventSubscribers(`attachmentAdd`,{})}_safeEmitAttachmentAddError(e,t,n,r){try{this._notifyEventSubscribers(`attachmentAddError`,{reason:e,message:t,...n!==void 0&&{attachmentId:n},...r!==void 0&&{error:r}})}catch(e){console.error(`[assistant-ui] attachmentAddError subscriber threw:`,e)}}async removeAttachment(e){let t=this._attachments.findIndex(t=>t.id===e);if(t===-1)throw Error(`Attachment not found`);let n=this._attachments[t];if(!Nx(n)){let e=this.getAttachmentAdapter();if(!e)throw Error(`Attachments are not supported`);await e.remove(n)}this._attachments=this._attachments.filter(t=>t.id!==e),this._notifySubscribers()}_dictation;_dictationSession;_dictationUnsubscribes=[];_dictationBaseText=``;_currentInterimText=``;_dictationSessionIdCounter=0;_activeDictationSessionId;_isCleaningDictation=!1;get dictation(){return this._dictation}_isActiveSession(e,t){return this._activeDictationSessionId===e&&this._dictationSession===t}startDictation(){let e=this.getDictationAdapter();if(!e)throw Error(`Dictation adapter not configured`);if(this._dictationSession){for(let e of this._dictationUnsubscribes)e();this._dictationUnsubscribes=[],this._dictationSession.stop().catch(()=>{}),this._dictationSession=void 0}let t=e.disableInputDuringDictation??!1;this._dictationBaseText=this._text,this._currentInterimText=``;let n=e.listen();this._dictationSession=n;let r=++this._dictationSessionIdCounter;this._activeDictationSessionId=r,this._dictation={status:n.status,inputDisabled:t},this._notifySubscribers();let i=n.onSpeech(e=>{if(!this._isActiveSession(r,n))return;let t=e.isFinal!==!1,i=this._dictationBaseText&&!this._dictationBaseText.endsWith(` `)&&e.transcript?` `:``;if(t){if(this._dictationBaseText=this._dictationBaseText+i+e.transcript,this._currentInterimText=``,this._text=this._dictationBaseText,this._dictation){let{transcript:e,...t}=this._dictation;this._dictation=t}this._notifySubscribers()}else this._currentInterimText=i+e.transcript,this._text=this._dictationBaseText+this._currentInterimText,this._dictation&&={...this._dictation,transcript:e.transcript},this._notifySubscribers()});this._dictationUnsubscribes.push(i);let a=n.onSpeechStart(()=>{this._isActiveSession(r,n)&&(this._dictation={status:{type:`running`},inputDisabled:t,...this._dictation?.transcript&&{transcript:this._dictation.transcript}},this._notifySubscribers())});this._dictationUnsubscribes.push(a);let o=n.onSpeechEnd(()=>{this._cleanupDictation({sessionId:r})});this._dictationUnsubscribes.push(o);let s=setInterval(()=>{this._isActiveSession(r,n)&&n.status.type===`ended`&&this._cleanupDictation({sessionId:r})},100);this._dictationUnsubscribes.push(()=>clearInterval(s))}stopDictation(){if(!this._dictationSession)return;let e=this._dictationSession,t=this._activeDictationSessionId;e.stop().finally(()=>{this._cleanupDictation({sessionId:t})})}_cleanupDictation(e){if(!(e?.sessionId!==void 0&&e.sessionId!==this._activeDictationSessionId||this._isCleaningDictation)){this._isCleaningDictation=!0;try{for(let e of this._dictationUnsubscribes)e();this._dictationUnsubscribes=[],this._dictationSession=void 0,this._activeDictationSessionId=void 0,this._dictation=void 0,this._dictationBaseText=``,this._currentInterimText=``,this._notifySubscribers()}finally{this._isCleaningDictation=!1}}}_eventSubscribers=new Map;_notifyEventSubscribers(e,t){let n=this._eventSubscribers.get(e);if(n)for(let e of n)e(t)}unstable_on(e,t){let n=t,r=this._eventSubscribers.get(e);return r||(r=new Set,this._eventSubscribers.set(e,r)),r.add(n),()=>{this._eventSubscribers.get(e)?.delete(n)}}},Fx=class extends Px{runtime;_canCancel=!1;get canCancel(){return this._canCancel}get canSend(){return!this.isEmpty&&!this.runtime.isSendDisabled}getAttachmentAdapter(){return this.runtime.adapters?.attachments}getDictationAdapter(){return this.runtime.adapters?.dictation}constructor(e){super(),this.runtime=e,this.connect()}connect(){let e=this.runtime.isSendDisabled;return this.runtime.subscribe(()=>{let t=!1;this.canCancel!==this.runtime.capabilities.cancel&&(this._canCancel=this.runtime.capabilities.cancel,t=!0),e!==this.runtime.isSendDisabled&&(e=this.runtime.isSendDisabled,t=!0),t&&this._notifySubscribers()})}async handleSend(e,t){this.runtime.append({...e,parentId:this.runtime.messages.at(-1)?.id??null,sourceId:null,startRun:t?.startRun})}async handleCancel(){this.runtime.cancelRun()}},Ix=class extends Px{runtime;endEditCallback;get canCancel(){return!0}get canSend(){return!this.isEmpty}getAttachmentAdapter(){return this.runtime.adapters?.attachments}getDictationAdapter(){return this.runtime.adapters?.dictation}_previousText;_previousAttachments;_nonTextPassthrough;_parentId;_sourceId;constructor(e,t,{parentId:n,message:r}){super(),this.runtime=e,this.endEditCallback=t,this._parentId=n,this._sourceId=r.id,this._previousText=fx(r),this.setText(this._previousText),this.setRole(r.role),r.role===`user`?(this._previousAttachments=[...r.attachments??[],...Mx(r.content)],this._nonTextPassthrough=[]):(this._previousAttachments=r.attachments??[],this._nonTextPassthrough=r.content.filter(e=>e.type!==`text`)),this.setAttachments(this._previousAttachments),this.setRunConfig({...e.composer.runConfig})}get parentId(){return this._parentId}get sourceId(){return this._sourceId}async handleSend(e,t){let n=fx(e),r=!Ax(e.attachments??[],this._previousAttachments);if(n!==this._previousText||r||t?.startRun){let n=this._nonTextPassthrough.length>0?[...e.content,...this._nonTextPassthrough]:e.content;this.runtime.append({...e,content:n,parentId:this._parentId,sourceId:this._sourceId,startRun:t?.startRun})}this.handleCancel()}handleCancel(){this.endEditCallback(),this._notifySubscribers()}},Lx=class{_contextProvider;_subscriptions=new Set;_isInitialized=!1;repository=new Ox;_voiceMessages=[];_voiceGeneration=0;_cachedMergedMessages=null;_cachedVoiceGeneration=-1;_cachedMergedBase=null;_markVoiceMessagesDirty(){this._voiceGeneration++,this._cachedMergedMessages=null}_getBaseMessages(){return this.repository.getMessages()}get messages(){if(this._voiceMessages.length===0)return this._getBaseMessages();let e=this._getBaseMessages();return(this._cachedVoiceGeneration!==this._voiceGeneration||this._cachedMergedBase!==e)&&(this._cachedMergedMessages=[...e,...this._voiceMessages],this._cachedVoiceGeneration=this._voiceGeneration,this._cachedMergedBase=e),this._cachedMergedMessages}get state(){let e;for(let t of this.messages)t.role===`assistant`&&(e=t);return e?.metadata.unstable_state??null}composer=new Fx(this);constructor(e){this._contextProvider=e}getModelContext(){return this._contextProvider.getModelContext()}_editComposers=new Map;getEditComposer(e){return this._editComposers.get(e)}beginEdit(e){if(this._editComposers.has(e))throw Error(`Edit already in progress`);this._editComposers.set(e,new Ix(this,()=>this._editComposers.delete(e),this.repository.getMessage(e))),this._notifySubscribers()}getMessageById(e){try{return this.repository.getMessage(e)}catch{let t=this.repository.getMessages(),n=this._voiceMessages.findIndex(t=>t.id===e);return n===-1?void 0:{parentId:n>0?this._voiceMessages[n-1].id:t.at(-1)?.id??null,message:this._voiceMessages[n],index:t.length+n}}}getBranches(e){return this._voiceMessages.some(t=>t.id===e)?[]:this.repository.getBranches(e)}switchToBranch(e){this.repository.switchToBranch(e),this._notifySubscribers()}_notifySubscribers(){for(let e of this._subscriptions)e()}_notifyEventSubscribers(e,t){let n=this._eventSubscribers.get(e);if(n)for(let e of n)e(t)}subscribe(e){return this._subscriptions.add(e),()=>this._subscriptions.delete(e)}submitFeedback({messageId:e,type:t}){let n=this.adapters?.feedback;if(!n)throw Error(`Feedback adapter not configured`);let{message:r,parentId:i}=this.repository.getMessage(e);if(n.submit({message:r,type:t}),r.role===`assistant`){let e={...r,metadata:{...r.metadata,submittedFeedback:{type:t}}};this.repository.addOrUpdateMessage(i,e)}this._notifySubscribers()}_stopSpeaking;speech;speak(e){let t=this.adapters?.speech;if(!t)throw Error(`Speech adapter not configured`);let{message:n}=this.repository.getMessage(e);this._stopSpeaking?.();let r=t.speak(fx(n)),i=r.subscribe(()=>{r.status.type===`ended`?(this._stopSpeaking=void 0,this.speech=void 0):this.speech={messageId:e,status:r.status},this._notifySubscribers()});this.speech={messageId:e,status:r.status},this._notifySubscribers(),this._stopSpeaking=()=>{r.cancel(),i(),this.speech=void 0,this._stopSpeaking=void 0}}stopSpeaking(){if(!this._stopSpeaking)throw Error(`No message is being spoken`);this._stopSpeaking(),this._notifySubscribers()}_voiceSession;_voiceUnsubs=[];voice;_voiceVolume=0;_voiceVolumeSubscribers=new Set;getVoiceVolume=()=>this._voiceVolume;subscribeVoiceVolume=e=>(this._voiceVolumeSubscribers.add(e),()=>this._voiceVolumeSubscribers.delete(e));connectVoice(){let e=this.adapters?.voice;if(!e)throw Error(`Voice adapter not configured`);this.disconnectVoice();let t=e.connect({});this._voiceSession=t;let n=[],r=`listening`;this.voice={status:t.status,isMuted:t.isMuted,mode:r},this._voiceVolume=0,this._notifySubscribers(),n.push(t.onStatusChange(e=>{e.type===`ended`?(this._finishVoiceAssistantMessage(),this._voiceSession=void 0,this.voice=void 0):this.voice={status:e,isMuted:t.isMuted,mode:r},this._notifySubscribers()})),n.push(t.onModeChange(e=>{r=e,this.voice&&(this.voice={...this.voice,mode:e},this._notifySubscribers())})),n.push(t.onVolumeChange(e=>{this._voiceVolume=e;for(let e of this._voiceVolumeSubscribers)e()})),n.push(t.onTranscript(e=>{this._handleVoiceTranscript(e)})),this._voiceUnsubs=n}_currentAssistantMsg=null;_handleVoiceTranscript(e){if(this.ensureInitialized(),e.role===`user`)this._finishVoiceAssistantMessage(),this._currentAssistantMsg=null,e.isFinal&&(this._voiceMessages.push({id:px(),role:`user`,content:[{type:`text`,text:e.text}],metadata:{custom:{}},createdAt:new Date,status:{type:`complete`,reason:`unknown`},attachments:[]}),this._markVoiceMessagesDirty(),this._notifySubscribers());else{if(!this._currentAssistantMsg)this._currentAssistantMsg={id:px(),role:`assistant`,content:[{type:`text`,text:e.text}],metadata:{unstable_state:this.state,unstable_annotations:[],unstable_data:[],steps:[],custom:{}},status:{type:`running`},createdAt:new Date},this._voiceMessages.push(this._currentAssistantMsg);else{let t=this._voiceMessages.indexOf(this._currentAssistantMsg);if(t===-1)return;let n={...this._currentAssistantMsg,content:[{type:`text`,text:e.text}],...e.isFinal?{status:{type:`complete`,reason:`stop`}}:{}};this._voiceMessages[t]=n,this._currentAssistantMsg=n}e.isFinal&&(this._currentAssistantMsg=null),this._markVoiceMessagesDirty(),this._notifySubscribers()}}_finishVoiceAssistantMessage(){let e=this._voiceMessages.at(-1);if(e?.role===`assistant`&&e.status.type===`running`){let t=this._voiceMessages.length-1;this._voiceMessages[t]={...e,status:{type:`complete`,reason:`stop`}},this._markVoiceMessagesDirty(),this._notifySubscribers()}}disconnectVoice(){this._finishVoiceAssistantMessage(),this._currentAssistantMsg=null;for(let e of this._voiceUnsubs)e();this._voiceUnsubs=[],this._voiceSession?.disconnect(),this._voiceSession=void 0,this.voice=void 0,this._voiceVolume=0;for(let e of this._voiceVolumeSubscribers)e();this._voiceMessages=[],this._markVoiceMessagesDirty(),this._notifySubscribers()}muteVoice(){if(!this._voiceSession)throw Error(`No active voice session`);this._voiceSession.mute(),this.voice={...this.voice,isMuted:!0},this._notifySubscribers()}unmuteVoice(){if(!this._voiceSession)throw Error(`No active voice session`);this._voiceSession.unmute(),this.voice={...this.voice,isMuted:!1},this._notifySubscribers()}ensureInitialized(){this._isInitialized||(this._isInitialized=!0,this._notifyEventSubscribers(`initialize`,{}))}export(){return this.repository.export()}import(e){this.ensureInitialized(),this.repository.clear(),this.repository.import(e),this._notifySubscribers()}reset(e){this.import(Tx.fromArray(e??[]))}_eventSubscribers=new Map;unstable_on(e,t){let n=t;if(e===`modelContextUpdate`)return this._contextProvider.subscribe?.(()=>n({}))??(()=>{});let r=this._eventSubscribers.get(e);return r||(r=new Set,this._eventSubscribers.set(e,r)),r.add(n),()=>{this._eventSubscribers.get(e)?.delete(n)}}},Rx=class{_core;_threadListBinding;get path(){return this._core.path}constructor(e,t){this._core=e,this._threadListBinding=t,this.__internal_bindMethods()}__internal_bindMethods(){this.switchTo=this.switchTo.bind(this),this.rename=this.rename.bind(this),this.archive=this.archive.bind(this),this.unarchive=this.unarchive.bind(this),this.delete=this.delete.bind(this),this.initialize=this.initialize.bind(this),this.generateTitle=this.generateTitle.bind(this),this.subscribe=this.subscribe.bind(this),this.unstable_on=this.unstable_on.bind(this),this.getState=this.getState.bind(this),this.detach=this.detach.bind(this)}getState(){return this._core.getState()}switchTo(){let e=this._core.getState();return this._threadListBinding.switchToThread(e.id)}rename(e){let t=this._core.getState();return this._threadListBinding.rename(t.id,e)}archive(){let e=this._core.getState();return this._threadListBinding.archive(e.id)}unarchive(){let e=this._core.getState();return this._threadListBinding.unarchive(e.id)}delete(){let e=this._core.getState();return this._threadListBinding.delete(e.id)}initialize(){let e=this._core.getState();return this._threadListBinding.initialize(e.id)}generateTitle(){let e=this._core.getState();return this._threadListBinding.generateTitle(e.id)}unstable_on(e,t){let n=this._core.getState().isMain,r=this._core.getState().id;return this.subscribe(()=>{let i=this._core.getState(),a=i.isMain,o=i.id;n===a&&r===o||(n=a,r=o,!(e===`switchedTo`&&!a)&&(e===`switchedAway`&&a||t({})))})}subscribe(e){return this._core.subscribe(e)}detach(){let e=this._core.getState();this._threadListBinding.detach(e.id)}__internal_getRuntime(){return this}},zx=Symbol(`innerMessage`),Bx=Symbol(`innerMessages`),Vx=[],Hx=(e,t)=>{zx in e||(e[zx]=t)},Ux=e=>{let t=`messages`in e?e.messages:e,n=t[Bx]||t[zx];return n?Array.isArray(n)?n:(t[Bx]=[n],t[Bx]):Vx},Wx=class{_core;get path(){return this._core.path}constructor(e){this._core=e,this.__internal_bindMethods()}__internal_bindMethods(){this.getState=this.getState.bind(this),this.remove=this.remove.bind(this),this.subscribe=this.subscribe.bind(this)}getState(){return this._core.getState()}subscribe(e){return this._core.subscribe(e)}},Gx=class extends Wx{_composerApi;constructor(e,t){super(e),this._composerApi=t}remove(){let e=this._composerApi.getState();if(!e)throw Error(`Composer is not available`);return e.removeAttachment(this.getState().id)}},Kx=class extends Gx{get source(){return`thread-composer`}},qx=class extends Gx{get source(){return`edit-composer`}},Jx=class extends Wx{get source(){return`message`}remove(){throw Error(`Message attachments cannot be removed`)}},Yx=Object.freeze([]),Xx=Object.freeze({}),Zx=e=>Object.freeze({type:`thread`,isEditing:e?.isEditing??!1,canCancel:e?.canCancel??!1,canSend:e?.canSend??!1,isEmpty:e?.isEmpty??!0,attachments:e?.attachments??Yx,text:e?.text??``,role:e?.role??`user`,runConfig:e?.runConfig??Xx,attachmentAccept:e?.attachmentAccept??``,dictation:e?.dictation,quote:e?.quote,value:e?.text??``}),Qx=e=>Object.freeze({type:`edit`,isEditing:e?.isEditing??!1,canCancel:e?.canCancel??!1,canSend:e?.canSend??!1,isEmpty:e?.isEmpty??!0,text:e?.text??``,role:e?.role??`user`,attachments:e?.attachments??Yx,runConfig:e?.runConfig??Xx,attachmentAccept:e?.attachmentAccept??``,dictation:e?.dictation,quote:e?.quote,parentId:e?.parentId??null,sourceId:e?.sourceId??null,value:e?.text??``}),$x=class{_core;get path(){return this._core.path}constructor(e){this._core=e}__internal_bindMethods(){this.setText=this.setText.bind(this),this.setRunConfig=this.setRunConfig.bind(this),this.getState=this.getState.bind(this),this.subscribe=this.subscribe.bind(this),this.addAttachment=this.addAttachment.bind(this),this.reset=this.reset.bind(this),this.clearAttachments=this.clearAttachments.bind(this),this.send=this.send.bind(this),this.cancel=this.cancel.bind(this),this.setRole=this.setRole.bind(this),this.getAttachmentByIndex=this.getAttachmentByIndex.bind(this),this.startDictation=this.startDictation.bind(this),this.stopDictation=this.stopDictation.bind(this),this.setQuote=this.setQuote.bind(this),this.unstable_on=this.unstable_on.bind(this)}setText(e){let t=this._core.getState();if(!t)throw Error(`Composer is not available`);t.setText(e)}setRunConfig(e){let t=this._core.getState();if(!t)throw Error(`Composer is not available`);t.setRunConfig(e)}addAttachment(e){let t=this._core.getState();if(!t)throw Error(`Composer is not available`);return t.addAttachment(e)}reset(){let e=this._core.getState();if(!e)throw Error(`Composer is not available`);return e.reset()}clearAttachments(){let e=this._core.getState();if(!e)throw Error(`Composer is not available`);return e.clearAttachments()}send(e){let t=this._core.getState();if(!t)throw Error(`Composer is not available`);t.send(e)}cancel(){let e=this._core.getState();if(!e)throw Error(`Composer is not available`);e.cancel()}setRole(e){let t=this._core.getState();if(!t)throw Error(`Composer is not available`);t.setRole(e)}startDictation(){let e=this._core.getState();if(!e)throw Error(`Composer is not available`);e.startDictation()}stopDictation(){let e=this._core.getState();if(!e)throw Error(`Composer is not available`);e.stopDictation()}setQuote(e){let t=this._core.getState();if(!t)throw Error(`Composer is not available`);t.setQuote(e)}subscribe(e){return this._core.subscribe(e)}_eventSubscriptionSubjects=new Map;unstable_on(e,t){let n=this._eventSubscriptionSubjects.get(e);return n||(n=new ux({event:e,binding:this._core}),this._eventSubscriptionSubjects.set(e,n)),n.subscribe(t)}},eS=class extends $x{get path(){return this._core.path}get type(){return`thread`}_getState;constructor(e){let t=new cx({path:e.path,getState:()=>Zx(e.getState()),subscribe:t=>e.subscribe(t)});super({path:e.path,getState:()=>e.getState(),subscribe:e=>t.subscribe(e)}),this._getState=t.getState.bind(t),this.__internal_bindMethods()}getState(){return this._getState()}getAttachmentByIndex(e){return new Kx(new sx({path:{...this.path,attachmentSource:`thread-composer`,attachmentSelector:{type:`index`,index:e},ref:`${this.path.ref}.attachments[${e}]`},getState:()=>{let t=this.getState().attachments[e];return t?{...t,source:`thread-composer`}:rx},subscribe:e=>this._core.subscribe(e)}),this._core)}},tS=class extends $x{_beginEdit;get path(){return this._core.path}get type(){return`edit`}_getState;constructor(e,t){let n=new cx({path:e.path,getState:()=>Qx(e.getState()),subscribe:t=>e.subscribe(t)});super({path:e.path,getState:()=>e.getState(),subscribe:e=>n.subscribe(e)}),this._beginEdit=t,this._getState=n.getState.bind(n),this.__internal_bindMethods()}__internal_bindMethods(){super.__internal_bindMethods(),this.beginEdit=this.beginEdit.bind(this)}getState(){return this._getState()}beginEdit(){this._beginEdit()}getAttachmentByIndex(e){return new qx(new sx({path:{...this.path,attachmentSource:`edit-composer`,attachmentSelector:{type:`index`,index:e},ref:`${this.path.ref}.attachments[${e}]`},getState:()=>{let t=this.getState().attachments[e];return t?{...t,source:`edit-composer`}:rx},subscribe:e=>this._core.subscribe(e)}),this._core)}},nS=class{contentBinding;messageApi;threadApi;get path(){return this.contentBinding.path}constructor(e,t,n){this.contentBinding=e,this.messageApi=t,this.threadApi=n,this.__internal_bindMethods()}__internal_bindMethods(){this.addToolResult=this.addToolResult.bind(this),this.resumeToolCall=this.resumeToolCall.bind(this),this.getState=this.getState.bind(this),this.subscribe=this.subscribe.bind(this)}getState(){return this.contentBinding.getState()}addToolResult(e){let t=this.contentBinding.getState();if(!t)throw Error(`Message part is not available`);if(t.type!==`tool-call`)throw Error(`Tried to add tool result to non-tool message part`);if(!this.messageApi)throw Error(`Message API is not available. This is likely a bug in assistant-ui.`);if(!this.threadApi)throw Error(`Thread API is not available`);let n=this.messageApi.getState();if(!n)throw Error(`Message is not available`);let r=t.toolName,i=t.toolCallId,a=Sb.toResponse(e);this.threadApi.getState().addToolResult({messageId:n.id,toolName:r,toolCallId:i,result:a.result,artifact:a.artifact,isError:a.isError})}resumeToolCall(e){let t=this.contentBinding.getState();if(!t)throw Error(`Message part is not available`);if(t.type!==`tool-call`)throw Error(`Tried to resume tool call on non-tool message part`);if(!this.threadApi)throw Error(`Thread API is not available`);let n=t.toolCallId;this.threadApi.getState().resumeToolCall({toolCallId:n,payload:e})}subscribe(e){return this.contentBinding.subscribe(e)}},rS=Object.freeze({type:`complete`}),iS=(e,t,n)=>{if(e.role!==`assistant`)return rS;if(n.type===`tool-call`)return n.result?rS:e.status;let r=t===Math.max(0,e.content.length-1);return e.status.type===`requires-action`?rS:r?e.status:rS},aS=(e,t)=>{let n=e.content[t];if(!n)return rx;let r=iS(e,t,n);return Object.freeze({...n,[zx]:n[zx],status:r})},oS=class{_core;_threadBinding;get path(){return this._core.path}constructor(e,t){this._core=e,this._threadBinding=t,this.composer=new tS(new lx({path:{...this.path,ref:`${this.path.ref}${this.path.ref}.composer`,composerSource:`edit`},getState:this._getEditComposerRuntimeCore,subscribe:e=>this._threadBinding.subscribe(e)}),()=>this._threadBinding.getState().beginEdit(this._core.getState().id)),this.__internal_bindMethods()}__internal_bindMethods(){this.reload=this.reload.bind(this),this.getState=this.getState.bind(this),this.subscribe=this.subscribe.bind(this),this.getMessagePartByIndex=this.getMessagePartByIndex.bind(this),this.getMessagePartByToolCallId=this.getMessagePartByToolCallId.bind(this),this.getAttachmentByIndex=this.getAttachmentByIndex.bind(this),this.unstable_getCopyText=this.unstable_getCopyText.bind(this),this.speak=this.speak.bind(this),this.stopSpeaking=this.stopSpeaking.bind(this),this.submitFeedback=this.submitFeedback.bind(this),this.switchToBranch=this.switchToBranch.bind(this)}composer;_getEditComposerRuntimeCore=()=>this._threadBinding.getState().getEditComposer(this._core.getState().id);getState(){return this._core.getState()}reload(e={}){let t=this._getEditComposerRuntimeCore(),n=t??this._threadBinding.getState().composer,r=t??n,{runConfig:i=r.runConfig}=e,a=this._core.getState();if(a.role!==`assistant`)throw Error(`Can only reload assistant messages`);this._threadBinding.getState().startRun({parentId:a.parentId,sourceId:a.id,runConfig:i})}speak(){let e=this._core.getState();return this._threadBinding.getState().speak(e.id)}stopSpeaking(){let e=this._core.getState();if(this._threadBinding.getState().speech?.messageId===e.id)this._threadBinding.getState().stopSpeaking();else throw Error(`Message is not being spoken`)}submitFeedback({type:e}){let t=this._core.getState();this._threadBinding.getState().submitFeedback({messageId:t.id,type:e})}switchToBranch({position:e,branchId:t}){let n=this._core.getState();if(t&&e)throw Error(`May not specify both branchId and position`);if(!t&&!e)throw Error(`Must specify either branchId or position`);let r=this._threadBinding.getState().getBranches(n.id),i=t;if(e===`previous`?i=r[n.branchNumber-2]:e===`next`&&(i=r[n.branchNumber]),!i)throw Error(`Branch not found`);this._threadBinding.getState().switchToBranch(i)}unstable_getCopyText(){return fx(this.getState())}subscribe(e){return this._core.subscribe(e)}getMessagePartByIndex(e){if(e<0)throw Error(`Message part index must be >= 0`);return new nS(new sx({path:{...this.path,ref:`${this.path.ref}${this.path.ref}.content[${e}]`,messagePartSelector:{type:`index`,index:e}},getState:()=>aS(this.getState(),e),subscribe:e=>this._core.subscribe(e)}),this._core,this._threadBinding)}getMessagePartByToolCallId(e){return new nS(new sx({path:{...this.path,ref:this.path.ref+`${this.path.ref}.content[toolCallId=${JSON.stringify(e)}]`,messagePartSelector:{type:`toolCallId`,toolCallId:e}},getState:()=>{let t=this._core.getState(),n=t.content.findIndex(t=>t.type===`tool-call`&&t.toolCallId===e);return n===-1?rx:aS(t,n)},subscribe:e=>this._core.subscribe(e)}),this._core,this._threadBinding)}getAttachmentByIndex(e){return new Jx(new sx({path:{...this.path,ref:`${this.path.ref}${this.path.ref}.attachments[${e}]`,attachmentSource:`message`,attachmentSelector:{type:`index`,index:e}},getState:()=>{let t=this.getState().attachments?.[e];return t?{...t,source:`message`}:rx},subscribe:e=>this._core.subscribe(e)}))}},sS=e=>({parentId:e.parentId??null,sourceId:e.sourceId??null,runConfig:e.runConfig??{},...e.stream?{stream:e.stream}:{}}),cS=e=>({parentId:e.parentId??null,sourceId:e.sourceId??null,runConfig:e.runConfig??{}}),lS=(e,t)=>typeof t==`string`?{createdAt:new Date,parentId:e.at(-1)?.id??null,sourceId:null,runConfig:{},role:`user`,content:[{type:`text`,text:t}],attachments:[],metadata:{custom:{}}}:{createdAt:t.createdAt??new Date,parentId:t.parentId??e.at(-1)?.id??null,sourceId:t.sourceId??null,role:t.role??`user`,content:t.content,attachments:t.attachments??[],metadata:t.metadata??{custom:{}},runConfig:t.runConfig??{},startRun:t.startRun},uS=(e,t)=>{let n=e.messages.at(-1);return Object.freeze({threadId:t.id,metadata:t,capabilities:e.capabilities,isDisabled:e.isDisabled,isLoading:e.isLoading,isRunning:e.isRunning??(n?.role===`assistant`?n.status.type===`running`:!1),messages:e.messages,state:e.state,suggestions:e.suggestions,extras:e.extras,speech:e.speech,voice:e.voice})},dS=class{get path(){return this._threadBinding.path}get __internal_threadBinding(){return this._threadBinding}_threadBinding;constructor(e,t){let n=new sx({path:e.path,getState:()=>uS(e.getState(),t.getState()),subscribe:n=>{let r=e.subscribe(n),i=t.subscribe(n);return()=>{r(),i()}}});this._threadBinding={path:e.path,getState:()=>e.getState(),getStateState:()=>n.getState(),outerSubscribe:t=>e.outerSubscribe(t),subscribe:t=>e.subscribe(t)},this.composer=new eS(new lx({path:{...this.path,ref:`${this.path.ref}.composer`,composerSource:`thread`},getState:()=>this._threadBinding.getState().composer,subscribe:e=>this._threadBinding.subscribe(e)})),this.__internal_bindMethods()}__internal_bindMethods(){this.append=this.append.bind(this),this.resumeRun=this.resumeRun.bind(this),this.importExternalState=this.importExternalState.bind(this),this.exportExternalState=this.exportExternalState.bind(this),this.startRun=this.startRun.bind(this),this.cancelRun=this.cancelRun.bind(this),this.stopSpeaking=this.stopSpeaking.bind(this),this.connectVoice=this.connectVoice.bind(this),this.disconnectVoice=this.disconnectVoice.bind(this),this.muteVoice=this.muteVoice.bind(this),this.unmuteVoice=this.unmuteVoice.bind(this),this.getVoiceVolume=this.getVoiceVolume.bind(this),this.subscribeVoiceVolume=this.subscribeVoiceVolume.bind(this),this.export=this.export.bind(this),this.import=this.import.bind(this),this.reset=this.reset.bind(this),this.getMessageByIndex=this.getMessageByIndex.bind(this),this.getMessageById=this.getMessageById.bind(this),this.subscribe=this.subscribe.bind(this),this.unstable_on=this.unstable_on.bind(this),this.getModelContext=this.getModelContext.bind(this),this.getState=this.getState.bind(this)}composer;getState(){return this._threadBinding.getStateState()}append(e){this._threadBinding.getState().append(lS(this._threadBinding.getState().messages,e))}subscribe(e){return this._threadBinding.subscribe(e)}getModelContext(){return this._threadBinding.getState().getModelContext()}startRun(e){return this._threadBinding.getState().startRun(cS(e))}resumeRun(e){return this._threadBinding.getState().resumeRun(sS(e))}exportExternalState(){return this._threadBinding.getState().exportExternalState()}importExternalState(e){this._threadBinding.getState().importExternalState(e)}cancelRun(){this._threadBinding.getState().cancelRun()}stopSpeaking(){return this._threadBinding.getState().stopSpeaking()}connectVoice(){this._threadBinding.getState().connectVoice()}disconnectVoice(){this._threadBinding.getState().disconnectVoice()}getVoiceVolume(){return this._threadBinding.getState().getVoiceVolume()}subscribeVoiceVolume(e){return this._threadBinding.getState().subscribeVoiceVolume(e)}muteVoice(){this._threadBinding.getState().muteVoice()}unmuteVoice(){this._threadBinding.getState().unmuteVoice()}export(){return this._threadBinding.getState().export()}import(e){this._threadBinding.getState().import(e)}reset(e){this._threadBinding.getState().reset(e)}getMessageByIndex(e){if(e<0)throw Error(`Message index must be >= 0`);return this._getMessageRuntime({...this.path,ref:`${this.path.ref}.messages[${e}]`,messageSelector:{type:`index`,index:e}},()=>{let t=this._threadBinding.getState().messages,n=t[e];if(n)return{message:n,parentId:t[e-1]?.id??null,index:e}})}getMessageById(e){return this._getMessageRuntime({...this.path,ref:`${this.path.ref}.messages[messageId=${JSON.stringify(e)}]`,messageSelector:{type:`messageId`,messageId:e}},()=>this._threadBinding.getState().getMessageById(e))}_getMessageRuntime(e,t){return new oS(new sx({path:e,getState:()=>{let{message:e,parentId:n,index:r}=t()??{},{messages:i,speech:a}=this._threadBinding.getState();if(!e||n===void 0||r===void 0)return rx;let o=this._threadBinding.getState().getBranches(e.id);return{...e,[zx]:e[zx],index:r,isLast:i.at(-1)?.id===e.id,parentId:n,branchNumber:o.indexOf(e.id)+1,branchCount:o.length,speech:a?.messageId===e.id?a:void 0}},subscribe:e=>this._threadBinding.subscribe(e)}),this._threadBinding)}_eventSubscriptionSubjects=new Map;unstable_on(e,t){let n=this._eventSubscriptionSubjects.get(e);return n||(n=new ux({event:e,binding:this._threadBinding}),this._eventSubscriptionSubjects.set(e,n)),n.subscribe(t)}},fS=Promise.resolve(),pS=e=>({mainThreadId:e.mainThreadId,newThreadId:e.newThreadId,threadIds:e.threadIds,archivedThreadIds:e.archivedThreadIds,isLoading:e.isLoading,isLoadingMore:e.isLoadingMore??!1,hasMore:e.hasMore??!1,threadItems:e.threadItems}),mS=(e,t)=>{if(t===void 0)return rx;let n=e.getItemById(t);return n?{id:n.id,remoteId:n.remoteId,externalId:n.externalId,title:n.title,status:n.status,custom:n.custom,isMain:n.id===e.mainThreadId}:rx},hS=class{_core;_runtimeFactory;_getState;constructor(e,t=dS){this._core=e,this._runtimeFactory=t;let n=new cx({path:{},getState:()=>pS(e),subscribe:t=>e.subscribe(t)});this._getState=n.getState.bind(n),this._mainThreadListItemRuntime=new Rx(new sx({path:{ref:`threadItems[main]`,threadSelector:{type:`main`}},getState:()=>mS(this._core,this._core.mainThreadId),subscribe:e=>this._core.subscribe(e)}),this._core),this.main=new t(new lx({path:{ref:`threads.main`,threadSelector:{type:`main`}},getState:()=>e.getMainThreadRuntimeCore(),subscribe:t=>e.subscribe(t)}),this._mainThreadListItemRuntime),this.__internal_bindMethods()}__internal_bindMethods(){this.switchToThread=this.switchToThread.bind(this),this.switchToNewThread=this.switchToNewThread.bind(this),this.getLoadThreadsPromise=this.getLoadThreadsPromise.bind(this),this.reload=this.reload.bind(this),this.loadMore=this.loadMore.bind(this),this.getState=this.getState.bind(this),this.subscribe=this.subscribe.bind(this),this.getById=this.getById.bind(this),this.getItemById=this.getItemById.bind(this),this.getItemByIndex=this.getItemByIndex.bind(this),this.getArchivedItemByIndex=this.getArchivedItemByIndex.bind(this)}switchToThread(e){return this._core.switchToThread(e)}switchToNewThread(){return this._core.switchToNewThread()}getLoadThreadsPromise(){return this._core.getLoadThreadsPromise()}reload(){return this._core.reload?.()??fS}loadMore(){return this._core.loadMore?.()??fS}getState(){return this._getState()}subscribe(e){return this._core.subscribe(e)}_mainThreadListItemRuntime;main;get mainItem(){return this._mainThreadListItemRuntime}getById(e){return new this._runtimeFactory(new lx({path:{ref:`threads[threadId=${JSON.stringify(e)}]`,threadSelector:{type:`threadId`,threadId:e}},getState:()=>this._core.getThreadRuntimeCore(e),subscribe:e=>this._core.subscribe(e)}),this.mainItem)}getItemByIndex(e){return new Rx(new sx({path:{ref:`threadItems[${e}]`,threadSelector:{type:`index`,index:e}},getState:()=>mS(this._core,this._core.threadIds[e]),subscribe:e=>this._core.subscribe(e)}),this._core)}getArchivedItemByIndex(e){return new Rx(new sx({path:{ref:`archivedThreadItems[${e}]`,threadSelector:{type:`archiveIndex`,index:e}},getState:()=>mS(this._core,this._core.archivedThreadIds[e]),subscribe:e=>this._core.subscribe(e)}),this._core)}getItemById(e){return new Rx(new sx({path:{ref:`threadItems[threadId=${e}]`,threadSelector:{type:`threadId`,threadId:e}},getState:()=>mS(this._core,e),subscribe:e=>this._core.subscribe(e)}),this._core)}},gS=class{_core;threads;_thread;constructor(e){this._core=e,this.threads=new hS(e.threads),this._thread=this.threads.main,this.__internal_bindMethods()}__internal_bindMethods(){this.registerModelContextProvider=this.registerModelContextProvider.bind(this)}get thread(){return this._thread}registerModelContextProvider(e){return this._core.registerModelContextProvider(e)}},_S=tv(e=>xv(Xb(e)));dy(_S,(e,t)=>{Zb(e,t),!e.tools&&t.tools.source===null&&(e.tools=yb({})),!e.dataRenderers&&t.dataRenderers.source===null&&(e.dataRenderers=bb())});var vS=(0,F.createContext)(null),yS=()=>(0,F.useContext)(vS);function bS(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function xS(e,t=0){return t>100?!1:e===null||typeof e==`string`||typeof e==`boolean`?!0:typeof e==`number`?!Number.isNaN(e)&&Number.isFinite(e):Array.isArray(e)?e.every(e=>xS(e,t+1)):bS(e)?Object.entries(e).every(([e,n])=>typeof e==`string`&&xS(n,t+1)):!1}var SS=100,CS=(e,t,n)=>{if(e===t)return!0;if(n>SS||e==null||t==null)return!1;if(Array.isArray(e))return!Array.isArray(t)||e.length!==t.length?!1:e.every((e,r)=>CS(e,t[r],n+1));if(Array.isArray(t)||!bS(e)||!bS(t))return!1;let r=Object.keys(e),i=Object.keys(t);return r.length===i.length?r.every(r=>Object.hasOwn(t,r)&&CS(e[r],t[r],n+1)):!1},wS=(e,t)=>!xS(e)||!xS(t)?!1:CS(e,t,0),TS=e=>{try{return JSON.parse(e),!0}catch{return!1}},ES=e=>{try{return JSON.parse(e)}catch{return}},DS=(e,t)=>{let n=ES(e),r=ES(t);return n===void 0||r===void 0?!1:wS(n,r)};function OS({state:e,getTools:t,onResult:n,setToolStatuses:r}){let i=(0,F.useRef)({}),a=(0,F.useRef)(new Map),o=(0,F.useRef)(new AbortController),s=(0,F.useRef)(0),c=(0,F.useRef)(new Set),l=(0,F.useRef)([]),u=(0,F.useRef)(new Map),d=(0,F.useRef)(new Set),f=(0,F.useRef)(0),p=e=>u.current.get(e)??e,m=e=>d.current.has(e)?(d.current.delete(e),u.current.delete(e),!0):!1,h=()=>{let e=t();if(e)return Object.fromEntries(Object.entries(e).map(([e,t])=>{let n=t.execute,r=t.streamCall,i=t.toModelOutput;return[e,{...t,...n!==void 0&&{execute:(...[e,t])=>n(e,{...t,toolCallId:p(t.toolCallId)})},...r!==void 0&&{streamCall:(...[e,t])=>r(e,{...t,toolCallId:p(t.toolCallId)})},...i!==void 0&&{toModelOutput:e=>i({...e,toolCallId:p(e.toolCallId)})}}]}))},[g]=(0,F.useState)(()=>{let[e,t]=ub(),f=Ib(h,()=>o.current?.signal??new AbortController().signal,(e,t)=>{let n=p(e);return new Promise((e,i)=>{let o=a.current.get(n);o&&o.reject(Error(`Human input request was superseded by a new request`)),a.current.set(n,{resolve:e,reject:i}),r(e=>({...e,[n]:{type:`interrupt`,payload:{type:`human`,payload:t}}}))})},{onExecutionStart:e=>{if(d.current.has(e))return;c.current.add(e);let t=p(e);s.current++,r(e=>({...e,[t]:{type:`executing`}}))},onExecutionEnd:e=>{let t=c.current.delete(e);if(d.current.has(e)){t&&(s.current--,s.current===0&&(l.current.forEach(e=>e()),l.current=[]));return}if(!t)return;let n=p(e);s.current--,r(e=>{let t={...e};return delete t[n],t}),s.current===0&&(l.current.forEach(e=>e()),l.current=[])}});return e.pipeThrough(f).pipeThrough(new ab).pipeTo(new WritableStream({write(e){if(e.type===`result`){if(m(e.meta.toolCallId))return;let t=p(e.meta.toolCallId);if(t!==e.meta.toolCallId&&u.current.delete(e.meta.toolCallId),i.current[t]?.hasResult)return;n({type:`add-tool-result`,toolCallId:t,toolName:e.meta.toolName,result:e.result,isError:e.isError,...e.artifact!==void 0&&{artifact:e.artifact},...e.modelContent!==void 0&&{modelContent:e.modelContent}})}}})),t}),_=(0,F.useRef)(new Set),v=(0,F.useRef)(!0);(0,F.useEffect)(()=>{let n=({controller:e,streamToolCallId:t})=>({argsText:``,hasResult:!1,argsComplete:!1,streamToolCallId:t,controller:e}),r=(e,t)=>(i.current[e]=t,t),a=(e,t,n)=>r(e,{...t,...n}),o=e=>{let n=t()?.[e];return n?.execute!==void 0||n?.streamCall!==void 0},s=({toolName:t,argsText:n,hasResult:r})=>r?!0:(o(t)||!e.isRunning)&&TS(n),l=({toolCallId:e,toolName:t,state:i})=>{d.current.add(i.streamToolCallId),i.controller.argsText.close();let a=`${e}:rewrite:${f.current++}`;return u.current.set(a,e),r(e,{...n({controller:g.addToolCallPart({toolName:t,toolCallId:a}),streamToolCallId:a}),hasResult:i.hasResult})},p=e=>{e.forEach(e=>{e.content.forEach(e=>{if(e.type===`tool-call`){if(v.current)_.current.add(e.toolCallId);else{if(_.current.has(e.toolCallId))return;let t=i.current[e.toolCallId];if(!t){if(e.result!==void 0){e.messages&&p(e.messages);return}u.current.set(e.toolCallId,e.toolCallId);let i=g.addToolCallPart({toolName:e.toolName,toolCallId:e.toolCallId});t=r(e.toolCallId,n({controller:i,streamToolCallId:e.toolCallId}))}if(e.argsText!==t.argsText){let n=!0;if(t.argsComplete)DS(t.argsText,e.argsText)&&(t=a(e.toolCallId,t,{argsText:e.argsText}),n=!1),n&&(!t.hasResult&&!c.current.has(t.streamToolCallId)||(t=a(e.toolCallId,t,{argsText:e.argsText}),n=!1)),n&&(t=l({toolCallId:e.toolCallId,toolName:e.toolName,state:t}));else if(!e.argsText.startsWith(t.argsText)){if(TS(t.argsText)&&TS(e.argsText)&&DS(t.argsText,e.argsText)){let r=s({toolName:e.toolName,argsText:e.argsText,hasResult:e.result!==void 0});r&&t.controller.argsText.close(),t=a(e.toolCallId,t,{argsText:e.argsText,argsComplete:r}),n=!1}n&&(t=l({toolCallId:e.toolCallId,toolName:e.toolName,state:t}))}if(n){let n=e.argsText.slice(t.argsText.length);t.controller.argsText.append(n);let r=s({toolName:e.toolName,argsText:e.argsText,hasResult:e.result!==void 0});r&&t.controller.argsText.close(),t=a(e.toolCallId,t,{argsText:e.argsText,argsComplete:r})}}t.argsComplete||s({toolName:e.toolName,argsText:e.argsText,hasResult:e.result!==void 0})&&(t.controller.argsText.close(),t=a(e.toolCallId,t,{argsText:e.argsText,argsComplete:!0})),e.result!==void 0&&!t.hasResult&&(a(e.toolCallId,t,{hasResult:!0,argsComplete:!0}),t.controller.setResponse(new Sb({result:e.result,artifact:e.artifact,isError:e.isError,...e.modelContent===void 0?{}:{modelContent:e.modelContent}})),t.controller.close())}e.messages&&p(e.messages)}})})};p(e.messages),v.current&&=!1},[e,g,t]);let y=()=>(a.current.forEach(({reject:e})=>{e(Error(`Tool execution aborted`))}),a.current.clear(),o.current.abort(),o.current=new AbortController,s.current===0?Promise.resolve():new Promise(e=>{l.current.push(e)}));return{reset:()=>{v.current=!0,_.current.clear(),i.current={},y().finally(()=>{c.current.clear(),u.current.clear(),d.current.clear(),f.current=0})},abort:y,resume:(e,t)=>{let n=a.current.get(e);if(n)a.current.delete(e),r(t=>({...t,[e]:{type:`executing`}})),n.resolve(t);else throw Error(`Tool call ${e} is not waiting for human input`)}}}var kS=Object.freeze([]),AS=`DEFAULT_THREAD_ID`,jS=Object.freeze([AS]),MS=Object.freeze({id:AS,remoteId:void 0,externalId:void 0,status:`regular`}),NS=Promise.resolve(),PS=Object.freeze({[AS]:MS}),FS=class{threadFactory;_mainThreadId=AS;_threads=jS;_archivedThreads=kS;_threadData=PS;adapter={};get isLoading(){return this.adapter.isLoading??!1}get newThreadId(){}get threadIds(){return this._threads}get archivedThreadIds(){return this._archivedThreads}get threadItems(){return this._threadData}getLoadThreadsPromise(){return NS}_mainThread;get mainThreadId(){return this._mainThreadId}constructor(e={},t){this.threadFactory=t,this.__internal_setAdapter(e,!0)}getMainThreadRuntimeCore(){return this._mainThread}getThreadRuntimeCore(){throw Error(`Method not implemented.`)}getItemById(e){return this._threadData[e]}__internal_setAdapter(e,t=!1){let n=this.adapter;this.adapter=e;let r=e.threadId??AS,i=e.threads??kS,a=e.archivedThreads??kS,o=n.threadId??AS,s=n.threads??kS,c=n.archivedThreads??kS;!t&&o===r&&s===i&&c===a||((s!==i||c!==a||o!==r)&&(this._threadData={...PS,...Object.fromEntries(e.threads?.map(e=>[e.id,{...e,remoteId:e.remoteId,externalId:e.externalId,status:`regular`}])??[]),...Object.fromEntries(e.archivedThreads?.map(e=>[e.id,{...e,remoteId:e.remoteId,externalId:e.externalId,status:`archived`}])??[])}),s!==i&&(this._threads=this.adapter.threads?.map(e=>e.id)??kS),c!==a&&(this._archivedThreads=this.adapter.archivedThreads?.map(e=>e.id)??kS),(t||o!==r)&&(this._mainThreadId=r,this._mainThread=this.threadFactory()),this._threadData[this._mainThreadId]||(this._threadData={...this._threadData,[this._mainThreadId]:{id:this._mainThreadId,remoteId:void 0,externalId:void 0,status:`regular`}}),this._notifySubscribers())}async switchToThread(e){if(this._mainThreadId===e)return;let t=this.adapter.onSwitchToThread;if(!t)throw Error(`External store adapter does not support switching to thread`);await t(e)}async switchToNewThread(){let e=this.adapter.onSwitchToNewThread;if(!e)throw Error(`External store adapter does not support switching to new thread`);await e()}async rename(e,t){let n=this.adapter.onRename;if(!n)throw Error(`External store adapter does not support renaming`);await n(e,t)}async detach(){}async archive(e){let t=this.adapter.onArchive;if(!t)throw Error(`External store adapter does not support archiving`);await t(e)}async unarchive(e){let t=this.adapter.onUnarchive;if(!t)throw Error(`External store adapter does not support unarchiving`);await t(e)}async delete(e){let t=this.adapter.onDelete;if(!t)throw Error(`External store adapter does not support deleting`);await t(e)}initialize(e){return Promise.resolve({remoteId:e,externalId:void 0})}generateTitle(){throw Error(`Method not implemented.`)}_subscriptions=new Set;subscribe(e){return this._subscriptions.add(e),()=>this._subscriptions.delete(e)}_notifySubscribers(){for(let e of this._subscriptions)e()}},IS=class{cache=new WeakMap;convertMessages(e,t){return e.map((e,n)=>{let r=t(this.cache.get(e),e,n);return this.cache.set(e,r),r})}},LS=Object.freeze([]),RS=(e,t)=>{let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(let r of n)if(e[r]!==t[r])return!1;return!0},zS=(e,t)=>e&&t[t.length-1]?.role!==`assistant`,BS=class extends Lx{_assistantOptimisticId=null;_capabilities={switchToBranch:!1,switchBranchDuringRun:!1,edit:!1,reload:!1,cancel:!1,unstable_copy:!1,speech:!1,dictation:!1,voice:!1,attachments:!1,feedback:!1,queue:!1};get capabilities(){return this._capabilities}_messages;isDisabled;isSendDisabled;get isLoading(){return this._store.isLoading??!1}get isRunning(){return this._store.isRunning}_getBaseMessages(){return this._messages}get state(){return this._store.state??super.state}get adapters(){return this._store.adapters}suggestions=[];extras=void 0;_converter=new IS;_store;beginEdit(e){if(!this._store.onEdit)throw Error(`Runtime does not support editing.`);super.beginEdit(e)}constructor(e,t){super(e),this.__internal_setAdapter(t)}__internal_setAdapter(e){if(this._store===e)return;let t=e.isRunning??!1;this.isDisabled=e.isDisabled??!1,this.isSendDisabled=e.isSendDisabled??!1;let n=this._store;this._store=e,this.extras!==e.extras&&(this.extras=e.extras);let r=e.suggestions??LS;RS(this.suggestions,r)||(this.suggestions=r);let i={switchToBranch:this._store.setMessages!==void 0,switchBranchDuringRun:!1,edit:this._store.onEdit!==void 0,reload:this._store.onReload!==void 0,cancel:this._store.onCancel!==void 0,speech:this._store.adapters?.speech!==void 0,dictation:this._store.adapters?.dictation!==void 0,voice:this._store.adapters?.voice!==void 0,unstable_copy:this._store.unstable_capabilities?.copy!==!1,attachments:!!this._store.adapters?.attachments,feedback:!!this._store.adapters?.feedback,queue:!1};RS(this._capabilities,i)||(this._capabilities=i);let a;if(e.messageRepository){if(n&&n.isRunning===e.isRunning&&n.messageRepository===e.messageRepository){this._notifySubscribers();return}this.repository.clear(),this._assistantOptimisticId=null,this.repository.import(e.messageRepository),a=this.repository.getMessages()}else if(e.messages){if(n){if(n.convertMessage!==e.convertMessage)this._converter=new IS;else if(n.isRunning===e.isRunning&&n.messages===e.messages){this._notifySubscribers();return}}a=e.convertMessage?this._converter.convertMessages(e.messages,(n,r,i)=>{if(!e.convertMessage)return r;let a=Sx(i===(e.messages?.length??0)-1,t,!1,!1,void 0);if(n&&(n.role!==`assistant`||!xx(n.status)||n.status===a))return n;let o=wx(e.convertMessage(r,i),i.toString(),a);return Hx(o,r),o}):e.messages;for(let e=0;e<a.length;e++){let t=a[e],n=a[e-1];this.repository.addOrUpdateMessage(n?.id??null,t)}}else throw Error(`ExternalStoreAdapter must provide either 'messages' or 'messageRepository'`);a.length>0&&this.ensureInitialized(),(n?.isRunning??!1)!==(e.isRunning??!1)&&(e.isRunning?this._notifyEventSubscribers(`runStart`,{}):this._notifyEventSubscribers(`runEnd`,{})),this._assistantOptimisticId&&=(this.repository.deleteMessage(this._assistantOptimisticId),null),zS(t,a)&&(this._assistantOptimisticId=this.repository.appendOptimisticMessage(a.at(-1)?.id??null,{role:`assistant`,content:[]})),this.repository.resetHead(this._assistantOptimisticId??a.at(-1)?.id??null),this._messages=this.repository.getMessages(),this._notifySubscribers()}switchToBranch(e){if(!this._store.setMessages)throw Error(`Runtime does not support switching branches.`);this._store.isRunning||(this.repository.switchToBranch(e),this.updateMessages(this.repository.getMessages()))}async append(e){if(e.parentId!==(this.messages.at(-1)?.id??null)){if(!this._store.onEdit)throw Error(`Runtime does not support editing messages.`);await this._store.onEdit(e)}else await this._store.onNew(e)}async startRun(e){if(!this._store.onReload)throw Error(`Runtime does not support reloading messages.`);await this._store.onReload(e.parentId,e)}async resumeRun(e){if(!this._store.onResume)throw Error(`Runtime does not support resuming runs.`);await this._store.onResume(e)}exportExternalState(){if(!this._store.onExportExternalState)throw Error(`Runtime does not support exporting external states.`);return this._store.onExportExternalState()}importExternalState(e){if(!this._store.onLoadExternalState)throw Error(`Runtime does not support importing external states.`);this._store.onLoadExternalState(e)}cancelRun(){if(!this._store.onCancel)throw Error(`Runtime does not support cancelling runs.`);this._store.onCancel(),this._assistantOptimisticId&&=(this.repository.deleteMessage(this._assistantOptimisticId),null);let e=this.repository.getMessages(),t=e[e.length-1];t?.role===`user`&&t.id===e.at(-1)?.id?(this.repository.deleteMessage(t.id),this.composer.text.trim()||this.composer.setText(fx(t)),e=this.repository.getMessages()):this._notifySubscribers(),setTimeout(()=>{this.updateMessages(e)},0)}addToolResult(e){if(!this._store.onAddToolResult&&!this._store.onAddToolResult)throw Error(`Runtime does not support tool results.`);this._store.onAddToolResult?.(e)}resumeToolCall(e){if(!this._store.onResumeToolCall)throw Error(`Runtime does not support resuming tool calls.`);this._store.onResumeToolCall(e)}reset(e){let t=new Ox;t.import(Tx.fromArray(e??[])),this.updateMessages(t.getMessages())}import(e){this._assistantOptimisticId=null,super.import(e),this._store.onImport&&this._store.onImport(this.repository.getMessages())}updateMessages=e=>{this._store.convertMessage===void 0?this._store.setMessages?.(e):this._store.setMessages?.(e.flatMap(Ux))}},VS=e=>e.adapters?.threadList??{},HS=class extends dx{threads;constructor(e){super(),this.threads=new FS(VS(e),()=>new BS(this._contextProvider,e))}setAdapter(e){this.threads.__internal_setAdapter(VS(e)),this.threads.getMainThreadRuntimeCore().__internal_setAdapter(e)}},US=e=>{let[t]=(0,F.useState)(()=>new HS(e));(0,F.useEffect)(()=>{t.setAdapter(e)});let{modelContext:n}=yS()??{};return(0,F.useEffect)(()=>{if(n)return t.registerModelContextProvider(n)},[n,t]),(0,F.useMemo)(()=>new gS(t),[t])},WS=e=>e._core?.RenderComponent,GS=(0,F.memo)(({runtime:e,aui:t=null,children:n})=>{let r=My({threads:_S(e)},{parent:t}),i=WS(e);return(0,L.jsxs)(cy,{value:r,children:[i&&(0,L.jsx)(i,{}),n]})}),KS=(e,t)=>e.Message===t.Message&&e.EditComposer===t.EditComposer&&e.UserEditComposer===t.UserEditComposer&&e.AssistantEditComposer===t.AssistantEditComposer&&e.SystemEditComposer===t.SystemEditComposer&&e.UserMessage===t.UserMessage&&e.AssistantMessage===t.AssistantMessage&&e.SystemMessage===t.SystemMessage,qS=()=>null,JS=(e,t,n)=>{switch(t){case`user`:return n?e.UserEditComposer??e.EditComposer??e.UserMessage??e.Message:e.UserMessage??e.Message;case`assistant`:return n?e.AssistantEditComposer??e.EditComposer??e.AssistantMessage??e.Message:e.AssistantMessage??e.Message;case`system`:return n?e.SystemEditComposer??e.EditComposer??e.SystemMessage??e.Message:e.SystemMessage??e.Message??qS;default:throw Error(`Unknown message role: ${t}`)}},YS=({components:e})=>(0,L.jsx)(JS(e,Ny(e=>e.message.role),Ny(e=>e.message.composer.isEditing)),{}),XS=(0,F.memo)(({index:e,components:t})=>(0,L.jsx)(Qb,{index:e,children:(0,L.jsx)(YS,{components:t})}),(e,t)=>e.index===t.index&&KS(e.components,t.components));XS.displayName=`ThreadPrimitive.MessageByIndex`;var ZS=({children:e})=>{let t=Ny(e=>e.thread.messages.length);return(0,F.useMemo)(()=>t===0?null:Array.from({length:t},(t,n)=>(0,L.jsx)(Qb,{index:n,children:(0,L.jsx)(Iy,{getItemState:e=>e.thread().message({index:n}).getState(),children:t=>e({get message(){return t()}})})},n)),[t,e])},QS=({components:e,children:t})=>e?(0,L.jsx)(ZS,{children:()=>(0,L.jsx)(YS,{components:e})}):(0,L.jsx)(ZS,{children:t});QS.displayName=`ThreadPrimitive.Messages`;var $S=(0,F.memo)(QS,(e,t)=>e.children||t.children?e.children===t.children:KS(e.components,t.components)),eC=e=>{let t=e.message.metadata;if(!(!t||typeof t!=`object`))return t.custom?.quote},tC=`ui://`,nC=e=>!!e?.startsWith(tC),rC=e=>Symbol.iterator in e,iC=e=>`entries`in e,aC=(e,t)=>{let n=e instanceof Map?e:new Map(e.entries()),r=t instanceof Map?t:new Map(t.entries());if(n.size!==r.size)return!1;for(let[e,t]of n)if(!r.has(e)||!Object.is(t,r.get(e)))return!1;return!0},oC=(e,t)=>{let n=e[Symbol.iterator](),r=t[Symbol.iterator](),i=n.next(),a=r.next();for(;!i.done&&!a.done;){if(!Object.is(i.value,a.value))return!1;i=n.next(),a=r.next()}return!!i.done&&!!a.done};function sC(e,t){return Object.is(e,t)?!0:typeof e!=`object`||!e||typeof t!=`object`||!t||Object.getPrototypeOf(e)!==Object.getPrototypeOf(t)?!1:rC(e)&&rC(t)?iC(e)&&iC(t)?aC(e,t):oC(e,t):aC({entries:()=>Object.entries(e)},{entries:()=>Object.entries(t)})}function cC(e){let t=F.useRef(void 0);return n=>{let r=e(n);return sC(t.current,r)?t.current:t.current=r}}var lC=e=>{let t=-1;return{startGroup:e=>{t===-1&&(t=e)},endGroup:(n,r)=>{t!==-1&&(r.push({type:e,startIndex:t,endIndex:n}),t=-1)},finalize:(n,r)=>{t!==-1&&r.push({type:e,startIndex:t,endIndex:n})}}},uC=(e,t)=>{let n=[];if(t){let t=lC(`chainOfThoughtGroup`);for(let r=0;r<e.length;r++){let i=e[r];i===`tool-call`||i===`reasoning`?t.startGroup(r):(t.endGroup(r-1,n),n.push({type:`single`,index:r}))}t.finalize(e.length-1,n)}else{let t=lC(`toolGroup`),r=lC(`reasoningGroup`);for(let i=0;i<e.length;i++){let a=e[i];a===`tool-call`?(r.endGroup(i-1,n),t.startGroup(i)):a===`reasoning`?(t.endGroup(i-1,n),r.startGroup(i)):(t.endGroup(i-1,n),r.endGroup(i-1,n),n.push({type:`single`,index:i}))}t.finalize(e.length-1,n),r.finalize(e.length-1,n)}return n},dC=e=>{let t=Ny(cC(e=>e.message.parts.map(e=>e.type)));return(0,F.useMemo)(()=>t.length===0?[]:uC(t,e),[t,e])},fC=({Fallback:e,...t})=>{let n=Ny(n=>{let r=n.tools.tools[t.toolName]??e;return Array.isArray(r)?r[0]??e:r});return n?(0,L.jsx)(n,{...t}):null},pC=(e,t,n)=>e.renderers[t]?.[0]||(e.fallbacks[0]??n),mC=({Fallback:e,...t})=>{let n=Ny(n=>pC(n.dataRenderers,t.name,e));return n?(0,L.jsx)(n,{...t}):null},hC={Text:()=>null,Reasoning:()=>null,Source:()=>null,Image:()=>null,File:()=>null,Unstable_Audio:()=>null,ToolGroup:({children:e})=>e,ReasoningGroup:({children:e})=>e},gC=({components:{Text:e=hC.Text,Reasoning:t=hC.Reasoning,Image:n=hC.Image,Source:r=hC.Source,File:i=hC.File,Unstable_Audio:a=hC.Unstable_Audio,tools:o={},data:s}={}})=>{let c=My(),l=Ny(e=>e.part),u=l.type;if(u===`tool-call`){let e=c.part().addToolResult,t=c.part().resumeToolCall;if(`Override`in o)return(0,L.jsx)(o.Override,{...l,addResult:e,resume:t});let n=o.by_name?.[l.toolName]??o.Fallback;return(0,L.jsx)(fC,{...l,Fallback:n,addResult:e,resume:t})}if(l.status?.type===`requires-action`)throw Error(`Encountered unexpected requires-action status`);switch(u){case`text`:return(0,L.jsx)(e,{...l});case`reasoning`:return(0,L.jsx)(t,{...l});case`source`:return(0,L.jsx)(r,{...l});case`image`:return(0,L.jsx)(n,{...l});case`file`:return(0,L.jsx)(i,{...l});case`audio`:return(0,L.jsx)(a,{...l});case`data`:{let e=s?.by_name?.[l.name]??s?.Fallback;return(0,L.jsx)(mC,{...l,Fallback:e})}default:return console.warn(`Unknown message part type: ${u}`),null}},_C=(0,F.memo)(({index:e,components:t})=>(0,L.jsx)($b,{index:e,children:(0,L.jsx)(gC,{components:t})}),(e,t)=>e.index===t.index&&e.components?.Text===t.components?.Text&&e.components?.Reasoning===t.components?.Reasoning&&e.components?.Source===t.components?.Source&&e.components?.Image===t.components?.Image&&e.components?.File===t.components?.File&&e.components?.Unstable_Audio===t.components?.Unstable_Audio&&e.components?.tools===t.components?.tools&&e.components?.data===t.components?.data&&e.components?.ToolGroup===t.components?.ToolGroup&&e.components?.ReasoningGroup===t.components?.ReasoningGroup);_C.displayName=`MessagePrimitive.PartByIndex`;var vC=({status:e,component:t})=>(0,L.jsx)(tx,{text:``,isRunning:e.type===`running`,children:(0,L.jsx)(t,{type:`text`,text:``,status:e})}),yC=Object.freeze({type:`complete`}),bC=Object.freeze({type:`running`}),xC=(0,F.memo)(({components:e})=>{let t=Ny(e=>e.message.status??yC);return e?.Empty?(0,L.jsx)(e.Empty,{status:t}):t.type===`running`?(0,L.jsx)(vC,{status:t,component:e?.Text??hC.Text}):null},(e,t)=>e.components?.Empty===t.components?.Empty&&e.components?.Text===t.components?.Text),SC=(0,F.memo)(({components:e,enabled:t})=>Ny(e=>{if(!t||e.message.parts.length===0)return!1;let n=e.message.parts[e.message.parts.length-1];return n?.type!==`text`&&n?.type!==`reasoning`})?(0,L.jsx)(xC,{components:e}):null,(e,t)=>e.enabled===t.enabled&&e.components?.Empty===t.components?.Empty&&e.components?.Text===t.components?.Text),CC=(0,F.memo)(({Quote:e})=>{let t=Ny(eC);return t?(0,L.jsx)(e,{text:t.text,messageId:t.messageId}):null});function wC(e,t){let n=e.tools[t.toolName];return(Array.isArray(n)?n[0]??null:n??null)||(nC(t.mcp?.app?.resourceUri)&&e.mcpApp?e.mcpApp.render:null)}var TC=()=>{let e=My(),t=Ny(e=>e.part),n=Ny(e=>e.part.type===`tool-call`?wC(e.tools,e.part):null);return!n||t.type!==`tool-call`?null:(0,L.jsx)(n,{...t,addResult:e.part().addToolResult,resume:e.part().resumeToolCall})},EC=()=>{let e=Ny(e=>e.part),t=Ny(e=>e.part.type===`data`?pC(e.dataRenderers,e.part.name,void 0)??null:null);return!t||e.type!==`data`?null:(0,L.jsx)(t,{...e})},DC=()=>{let e=Ny(e=>e.part.type);return e===`tool-call`?(0,L.jsx)(TC,{}):e===`data`?(0,L.jsx)(EC,{}):null},OC=Object.freeze({type:`text`,text:``,status:bC}),kC=({index:e,children:t})=>{let n=My(),r=Ny(e=>e.dataRenderers);return(0,L.jsx)($b,{index:e,children:(0,L.jsx)(Iy,{getItemState:t=>t.message().part({index:e}).getState(),children:i=>t({get part(){let t=i();if(t.type===`tool-call`){let r=wC(n.tools().getState(),t)!==null,i=n.message().part({index:e});return{...t,toolUI:r?(0,L.jsx)(TC,{}):null,addResult:i.addToolResult,resume:i.resumeToolCall}}if(t.type===`data`){let e=pC(r,t.name,void 0)!==void 0;return{...t,dataRendererUI:e?(0,L.jsx)(EC,{}):null}}return t}})})})},AC=({children:e})=>{let t=Ny(e=>e.message.parts.length),n=Ny(e=>(e.message.status?.type??`complete`)===`running`);return t===0?t===0&&n?(0,L.jsx)(tx,{text:``,isRunning:!0,children:e({part:OC})}):null:(0,L.jsx)(L.Fragment,{children:Array.from({length:t},(t,n)=>(0,L.jsx)(kC,{index:n,children:t=>e(t)??(0,L.jsx)(DC,{})},n))})},jC=({components:e,unstable_showEmptyOnNonTextEnd:t=!0,children:n})=>n?(0,L.jsx)(AC,{children:n}):(0,L.jsx)(MC,{components:e,unstable_showEmptyOnNonTextEnd:t});jC.displayName=`MessagePrimitive.Parts`;var MC=({components:e,unstable_showEmptyOnNonTextEnd:t})=>{let n=Ny(e=>e.message.parts.length),r=dC(!!e?.ChainOfThought),i=(0,F.useMemo)(()=>n===0?(0,L.jsx)(xC,{components:e}):r.map(t=>{if(t.type===`single`)return(0,L.jsx)(_C,{index:t.index,components:e},t.index);if(t.type===`chainOfThoughtGroup`){let n=e?.ChainOfThought;return n?(0,L.jsx)(nx,{startIndex:t.startIndex,endIndex:t.endIndex,children:(0,L.jsx)(n,{})},`chainOfThought-${t.startIndex}`):null}else if(t.type===`toolGroup`)return(0,L.jsx)(e?.ToolGroup??hC.ToolGroup,{startIndex:t.startIndex,endIndex:t.endIndex,children:Array.from({length:t.endIndex-t.startIndex+1},(n,r)=>(0,L.jsx)(_C,{index:t.startIndex+r,components:e},r))},`tool-${t.startIndex}`);else return(0,L.jsx)(e?.ReasoningGroup??hC.ReasoningGroup,{startIndex:t.startIndex,endIndex:t.endIndex,children:Array.from({length:t.endIndex-t.startIndex+1},(n,r)=>(0,L.jsx)(_C,{index:t.startIndex+r,components:e},r))},`reasoning-${t.startIndex}`)}),[r,e,n]);return(0,L.jsxs)(L.Fragment,{children:[e?.Quote&&(0,L.jsx)(CC,{Quote:e.Quote}),i,(0,L.jsx)(SC,{components:e,enabled:t})]})},NC=Object.freeze([]),PC=e=>e==null?NC:typeof e==`string`?[e]:e,FC=e=>{let t=e.nextChildIdx++;return e.nodeKey===``?String(t):`${e.nodeKey}.${t}`},IC=e=>{let t={key:``,nodeKey:``,indices:[],children:[],nextChildIdx:0},n=[t],r=()=>{let e=n.pop();n[n.length-1].children.push({type:`group`,key:e.key,nodeKey:e.nodeKey,indices:e.indices,children:e.children})};for(let t=0;t<e.length;t++){let i=e[t],a=0;for(;a<n.length-1&&a<i.length&&n[a+1].key===i[a];)a++;for(;n.length-1>a;)r();for(;n.length-1<i.length;){let e=n[n.length-1];n.push({key:i[n.length-1],nodeKey:FC(e),indices:[],children:[],nextChildIdx:0})}let o=n[n.length-1];o.children.push({type:`part`,index:t,nodeKey:FC(o)});for(let e=1;e<n.length;e++)n[e].indices.push(t)}for(;n.length>1;)r();return t.children},LC=Object.freeze({type:`complete`}),RC=()=>{throw Error("MessagePrimitive.GroupedParts: rendered `children` under a leaf part. `children` is only meaningful for `group-…` cases — add a matching case for the part type or return `null` to skip it.")},zC=(e,t,n)=>{if(e.type===`part`)return(0,L.jsx)(kC,{index:e.index,children:({part:e})=>n({part:e,children:(0,L.jsx)(RC,{})})},e.nodeKey);let r=t[e.indices.at(-1)]?.status??LC;return(0,L.jsx)(F.Fragment,{children:n({part:{type:e.key,status:r,indices:e.indices},children:(0,L.jsx)(L.Fragment,{children:e.children.map(e=>zC(e,t,n))})})},e.nodeKey)},BC=({groupBy:e,children:t})=>{let n=Ny(cC(e=>e.message.parts));return(0,L.jsx)(L.Fragment,{children:(0,F.useMemo)(()=>IC(n.map((t,r)=>PC(e(t,r,n)))),[n,e]).map(e=>zC(e,n,t))})};BC.displayName=`MessagePrimitive.GroupedParts`;var VC=()=>{let e=My(),t=Ny(e=>!e.composer.canSend||e.thread.isRunning&&!e.thread.capabilities.queue);return{send:(0,F.useCallback)(t=>{e.composer().send(t)},[e]),disabled:t}},HC=()=>{let e=My(),t=Ny(e=>!e.composer.canCancel);return{cancel:(0,F.useCallback)(()=>{e.composer().cancel()},[e]),disabled:t}},UC=e=>{let{cloud:t,initialMessages:n,maxSteps:r,adapters:i,unstable_humanToolNames:a,...o}=e;return{localRuntimeOptions:{cloud:t,initialMessages:n,maxSteps:r,adapters:i,unstable_humanToolNames:a},otherOptions:o}},WC=e=>{let t=new Map,n=()=>{let n=0;for(let e of t.values())n+=e;e(n)};return{register:()=>{let e=Symbol();return t.set(e,0),{setHeight:r=>{t.get(e)!==r&&(t.set(e,r),n())},unregister:()=>{t.delete(e),n()}}}}},GC=(e={})=>{let t=new Set,n=WC(e=>{a.setState({height:{...a.getState().height,viewport:e}})}),r=WC(e=>{a.setState({height:{...a.getState().height,inset:e}})}),i=(e,t)=>(a.setState({element:{...a.getState().element,[e]:t}}),()=>{a.getState().element[e]===t&&a.setState({element:{...a.getState().element,[e]:null}})}),a=Vy(()=>({isAtBottom:!0,scrollToBottom:({behavior:e=`auto`}={})=>{for(let n of t)n({behavior:e})},onScrollToBottom:e=>(t.add(e),()=>{t.delete(e)}),turnAnchor:e.turnAnchor??`bottom`,topAnchorMessageClamp:{tallerThan:e.topAnchorMessageClamp?.tallerThan??`10em`,visibleHeight:e.topAnchorMessageClamp?.visibleHeight??`6em`},height:{viewport:0,inset:0},element:{viewport:null,anchor:null,target:null},targetConfig:null,topAnchorTurn:null,registerViewport:n.register,registerContentInset:r.register,registerViewportElement:e=>i(`viewport`,e),registerAnchorElement:e=>i(`anchor`,e),registerAnchorTargetElement:(e,t)=>(a.setState({element:{...a.getState().element,target:e},targetConfig:e&&t?t:null}),()=>{a.getState().element.target===e&&a.setState({element:{...a.getState().element,target:null},targetConfig:null})}),setTopAnchorTurn:e=>{a.setState({topAnchorTurn:e})}}));return a};function KC(e,t){function n(n){let r=(0,F.useContext)(e);if(!n?.optional&&!r)throw Error(`This component must be used within ${t}.`);return r}return n}function qC(e,t){function n(n){let r=e(n);return r?r[t]:null}function r(e){let t=!1,r;typeof e==`function`?r=e:e&&typeof e==`object`&&(t=!!e.optional,r=e.selector);let i=n({optional:t});return i?r?i(r):i():null}return{[t]:r,[`${t}Store`]:n}}var JC=(0,F.createContext)(null),{useThreadViewport:YC,useThreadViewportStore:XC}=qC(KC(JC,`ThreadPrimitive.Viewport`),`useThreadViewport`),ZC=e=>e,QC=e=>{let t=XC({optional:!0}),[n]=(0,F.useState)(()=>GC(e));return(0,F.useEffect)(()=>t?.getState().onScrollToBottom(()=>{n.getState().scrollToBottom()}),[t,n]),(0,F.useEffect)(()=>{if(t)return n.subscribe(e=>{t.getState().isAtBottom!==e.isAtBottom&&ZC(t).setState({isAtBottom:e.isAtBottom})})},[n,t]),n},$C=({children:e,options:t={}})=>{let n=QC(t),[r]=(0,F.useState)(()=>({useThreadViewport:n}));return(0,L.jsx)(JC.Provider,{value:r,children:e})},ew=()=>((0,F.useEffect)(()=>{},[My()]),null),tw=(0,F.memo)(({children:e,aui:t,runtime:n})=>(0,L.jsxs)(GS,{runtime:n,aui:t??null,children:[(0,L.jsx)(ew,{}),(0,L.jsx)($C,{children:e})]}));function nw(e){let t=My(),n=Ny(()=>t.composer.source?t.composer().__internal_getRuntime?.()??null:null);if(!n&&!e?.optional)throw Error(`ComposerRuntime is not available`);return n}var rw=Symbol.for(`react.lazy`),iw=F.use;function aw(e){return typeof e==`object`&&!!e&&`then`in e}function ow(e){return typeof e==`object`&&!!e&&`$$typeof`in e&&e.$$typeof===rw&&`_payload`in e&&aw(e._payload)}function sw(e){let t=cw(e),n=F.forwardRef((e,n)=>{let{children:r,...i}=e;ow(r)&&typeof iw==`function`&&(r=iw(r._payload));let a=F.Children.toArray(r),o=a.find(uw);if(o){let e=o.props.children,r=a.map(t=>t===o?F.Children.count(e)>1?F.Children.only(null):F.isValidElement(e)?e.props.children:null:t);return(0,L.jsx)(t,{...i,ref:n,children:F.isValidElement(e)?F.cloneElement(e,void 0,r):null})}return(0,L.jsx)(t,{...i,ref:n,children:r})});return n.displayName=`${e}.Slot`,n}function cw(e){let t=F.forwardRef((e,t)=>{let{children:n,...r}=e;if(ow(n)&&typeof iw==`function`&&(n=iw(n._payload)),F.isValidElement(n)){let e=fw(n),i=dw(r,n.props);return n.type!==F.Fragment&&(i.ref=t?so(t,e):e),F.cloneElement(n,i)}return F.Children.count(n)>1?F.Children.only(null):null});return t.displayName=`${e}.SlotClone`,t}var lw=Symbol(`radix.slottable`);function uw(e){return F.isValidElement(e)&&typeof e.type==`function`&&`__radixId`in e.type&&e.type.__radixId===lw}function dw(e,t){let n={...t};for(let r in t){let i=e[r],a=t[r];/^on[A-Z]/.test(r)?i&&a?n[r]=(...e)=>{let t=a(...e);return i(...e),t}:i&&(n[r]=i):r===`style`?n[r]={...i,...a}:r===`className`&&(n[r]=[i,a].filter(Boolean).join(` `))}return{...e,...n}}function fw(e){let t=Object.getOwnPropertyDescriptor(e.props,`ref`)?.get,n=t&&`isReactWarning`in t&&t.isReactWarning;return n?e.ref:(t=Object.getOwnPropertyDescriptor(e,`ref`)?.get,n=t&&`isReactWarning`in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}var pw=[`a`,`button`,`div`,`form`,`h2`,`h3`,`img`,`input`,`label`,`li`,`nav`,`ol`,`p`,`select`,`span`,`svg`,`ul`].reduce((e,t)=>{let n=sw(`Primitive.${t}`),r=F.forwardRef((e,r)=>{let{asChild:i,...a}=e,o=i?n:t;return typeof window<`u`&&(window[Symbol.for(`radix-ui`)]=!0),(0,L.jsx)(o,{...a,ref:r})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{}),mw=[`a`,`button`,`div`,`form`,`h2`,`h3`,`img`,`input`,`label`,`li`,`nav`,`ol`,`p`,`select`,`span`,`svg`,`ul`];function hw(e){let t=(0,F.forwardRef)(({render:t,asChild:n,children:r,...i},a)=>{let o=e;if(t&&(0,F.isValidElement)(t)){let e=r===void 0?t.props.children:r;return(0,L.jsx)(o,{...i,asChild:!0,ref:a,children:(0,F.cloneElement)(t,void 0,e)})}return(0,L.jsx)(o,{...i,asChild:n,ref:a,children:r})});return t.displayName=typeof e==`string`?e:e.displayName??e.name??`Component`,t}function gw(e){let t=pw[e],n=hw(t);return n.displayName=`Primitive.${e}`,n}var _w=mw.reduce((e,t)=>(e[t]=gw(t),e),{}),vw=(e,t,n=[])=>{let r=(0,F.forwardRef)((e,r)=>{let i={},a={};Object.keys(e).forEach(t=>{n.includes(t)?i[t]=e[t]:a[t]=e[t]});let o=t(i)??void 0;return(0,L.jsx)(_w.button,{...a,type:`button`,ref:r,disabled:a.disabled||!o,onClick:Oo(a.onClick,o)})});return r.displayName=e,r},yw=()=>{let{disabled:e,send:t}=VC(),n=(0,F.useCallback)(()=>t(),[t]);return e?null:n},bw=vw(`ComposerPrimitive.Send`,yw),xw=(0,F.forwardRef)(({onSubmit:e,...t},n)=>{let r=yw(),i=e=>{e.preventDefault(),r&&r()};return(0,L.jsx)(_w.form,{...t,ref:n,onSubmit:Oo(e,i)})});xw.displayName=`ComposerPrimitive.Root`;function Sw(){return Sw=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},Sw.apply(null,arguments)}function Cw(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}var ww=F.useLayoutEffect,Tw=function(e){var t=F.useRef(e);return ww(function(){t.current=e}),t},Ew=function(e,t){if(typeof e==`function`){e(t);return}e.current=t},Dw=function(e,t){var n=F.useRef();return F.useCallback(function(r){e.current=r,n.current&&Ew(n.current,null),n.current=t,t&&Ew(t,r)},[t])},Ow={"min-height":`0`,"max-height":`none`,height:`0`,visibility:`hidden`,overflow:`hidden`,position:`absolute`,"z-index":`-1000`,top:`0`,right:`0`,display:`block`},kw=function(e){Object.keys(Ow).forEach(function(t){e.style.setProperty(t,Ow[t],`important`)})},Aw=null,jw=function(e,t){var n=e.scrollHeight;return t.sizingStyle.boxSizing===`border-box`?n+t.borderSize:n-t.paddingSize};function tte(e,t,n,r){n===void 0&&(n=1),r===void 0&&(r=1/0),Aw||(Aw=document.createElement(`textarea`),Aw.setAttribute(`tabindex`,`-1`),Aw.setAttribute(`aria-hidden`,`true`),kw(Aw)),Aw.parentNode===null&&document.body.appendChild(Aw);var i=e.paddingSize,a=e.borderSize,o=e.sizingStyle,s=o.boxSizing;Object.keys(o).forEach(function(e){var t=e;Aw.style[t]=o[t]}),kw(Aw),Aw.value=t;var c=jw(Aw,e);Aw.value=t,c=jw(Aw,e),Aw.value=`x`;var l=Aw.scrollHeight-i,u=l*n;s===`border-box`&&(u=u+i+a),c=Math.max(u,c);var d=l*r;return s===`border-box`&&(d=d+i+a),c=Math.min(d,c),[c,l]}var Mw=function(){},nte=function(e,t){return e.reduce(function(e,n){return e[n]=t[n],e},{})},rte=[`borderBottomWidth`,`borderLeftWidth`,`borderRightWidth`,`borderTopWidth`,`boxSizing`,`fontFamily`,`fontSize`,`fontStyle`,`fontWeight`,`letterSpacing`,`lineHeight`,`paddingBottom`,`paddingLeft`,`paddingRight`,`paddingTop`,`tabSize`,`textIndent`,`textRendering`,`textTransform`,`width`,`wordBreak`,`wordSpacing`,`scrollbarGutter`],ite=!!document.documentElement.currentStyle,ate=function(e){var t=window.getComputedStyle(e);if(t===null)return null;var n=nte(rte,t),r=n.boxSizing;return r===``?null:(ite&&r===`border-box`&&(n.width=parseFloat(n.width)+parseFloat(n.borderRightWidth)+parseFloat(n.borderLeftWidth)+parseFloat(n.paddingRight)+parseFloat(n.paddingLeft)+`px`),{sizingStyle:n,paddingSize:parseFloat(n.paddingBottom)+parseFloat(n.paddingTop),borderSize:parseFloat(n.borderBottomWidth)+parseFloat(n.borderTopWidth)})};function Nw(e,t,n){var r=Tw(n);F.useLayoutEffect(function(){var n=function(e){return r.current(e)};if(e)return e.addEventListener(t,n),function(){return e.removeEventListener(t,n)}},[])}var ote=function(e,t){Nw(document.body,`reset`,function(n){e.current.form===n.target&&t(n)})},ste=function(e){Nw(window,`resize`,e)},cte=function(e){Nw(document.fonts,`loadingdone`,e)},lte=[`cacheMeasurements`,`maxRows`,`minRows`,`onChange`,`onHeightChange`],ute=F.forwardRef(function(e,t){var n=e.cacheMeasurements,r=e.maxRows,i=e.minRows,a=e.onChange,o=a===void 0?Mw:a,s=e.onHeightChange,c=s===void 0?Mw:s,l=Cw(e,lte),u=l.value!==void 0,d=F.useRef(null),f=Dw(d,t),p=F.useRef(0),m=F.useRef(),h=function(){var e=d.current,t=n&&m.current?m.current:ate(e);if(t){m.current=t;var a=tte(t,e.value||e.placeholder||`x`,i,r),o=a[0],s=a[1];p.current!==o&&(p.current=o,e.style.setProperty(`height`,o+`px`,`important`),c(o,{rowHeight:s}))}};return F.useLayoutEffect(h),ote(d,function(){if(!u){var e=d.current.value;requestAnimationFrame(function(){var t=d.current;t&&e!==t.value&&h()})}}),ste(h),cte(h),F.createElement(`textarea`,Sw({},l,{onChange:function(e){u||h(),o(e)},ref:f}))}),Pw=e=>{let t=ts(e),n=YC(e=>e.onScrollToBottom);(0,F.useEffect)(()=>n(t),[n,t])},Fw=(0,F.createContext)(null),Iw=()=>(0,F.useContext)(Fw),dte=({children:e})=>{let t=(0,F.useRef)(new Map),n=(0,F.useRef)([]),r=(0,F.useCallback)(()=>{let e=Array.from(t.current.entries());e.sort((e,t)=>t[1]-e[1]),n.current=e.map(([e])=>e)},[]),i=(0,F.useCallback)((e,n)=>{let i=n?.priority??0;return t.current.set(e,i),r(),()=>{t.current.delete(e),r()}},[r]),a=(0,F.useCallback)(()=>n.current,[]),o=(0,F.useMemo)(()=>({register:i,getPlugins:a}),[i,a]);return(0,L.jsx)(Fw.Provider,{value:o,children:e})},Lw=(0,F.createContext)(null),fte=(0,F.createContext)(null),pte=()=>(0,F.useContext)(Lw),mte=()=>()=>{},Rw=()=>null,hte=()=>{let e=pte();return(0,F.useSyncExternalStore)(e?e.subscribeAria:mte,e?e.getActiveAria:Rw,e?e.getActiveAria:Rw)};function zw(){let e=(0,F.useRef)(new Set);return{notify:(0,F.useCallback)(()=>{for(let t of e.current)t()},[]),subscribe:(0,F.useCallback)(t=>(e.current.add(t),()=>{e.current.delete(t)}),[])}}var Bw=({children:e})=>{let t=(0,F.useRef)(new Map),n=(0,F.useRef)(new Set),{notify:r,subscribe:i}=zw(),a=(0,F.useCallback)(e=>{let{char:i}=e;if(t.current.has(i))return()=>{};let a=new Map(t.current);a.set(i,e),t.current=a,r();for(let t of n.current)t.added(e);return()=>{let e=new Map(t.current);e.delete(i),t.current=e,r();for(let e of n.current)e.removed(i)}},[r]),o=(0,F.useCallback)(()=>t.current,[]),s=(0,F.useCallback)(e=>(n.current.add(e),()=>{n.current.delete(e)}),[]),c=(0,F.useRef)(null),l=(0,F.useRef)(null),{notify:u,subscribe:d}=zw(),f=(0,F.useCallback)((e,t)=>{if(t===null){if(l.current!==e)return;c.current=null,l.current=null,u();return}let n=c.current;l.current===e&&n!==null&&n.popoverId===t.popoverId&&n.highlightedItemId===t.highlightedItemId||(c.current=t,l.current=e,u())},[u]),p=(0,F.useCallback)(()=>c.current,[]),m=(0,F.useMemo)(()=>({register:a,getTriggers:o,subscribe:i,subscribeLifecycle:s,getActiveAria:p,subscribeAria:d}),[a,o,i,s,p,d]),h=(0,F.useMemo)(()=>({setActiveAria:f}),[f]);return(0,L.jsx)(Lw.Provider,{value:m,children:(0,L.jsx)(fte.Provider,{value:h,children:e})})},gte=({children:e})=>Iw()?(0,L.jsx)(Bw,{children:e}):(0,L.jsx)(dte,{children:(0,L.jsx)(Bw,{children:e})});gte.displayName=`ComposerPrimitive.TriggerPopoverRoot`;var Vw=(0,F.forwardRef)(({autoFocus:e=!1,asChild:t,render:n,disabled:r,onChange:i,onKeyDown:a,onPaste:o,onSelect:s,submitOnEnter:c,submitMode:l,cancelOnEscape:u=!0,unstable_focusOnRunStart:d=!0,unstable_focusOnScrollToBottom:f=!0,unstable_focusOnThreadSwitched:p=!0,addAttachmentOnPaste:m=!0,...h},g)=>{let _=My(),v=Iw(),y=hte(),b=l??(c===!1?`none`:`enter`),x=Ny(e=>e.composer.isEditing?e.composer.text:``),S=Ny(e=>e.thread.isDisabled||e.composer.dictation?.inputDisabled)||r,C=(0,F.useRef)(null),w=co(g,C),T=(0,F.useRef)(!1);ns(e=>{if(!C.current?.contains(e.target))return;if(v){for(let t of v.getPlugins())if(t.handleKeyDown(e))return}if(!u)return;let t=_.composer();t.getState().canCancel&&(t.cancel(),e.preventDefault())});let E=e=>{if(!S&&!e.nativeEvent.isComposing){if(v){for(let t of v.getPlugins())if(t.handleKeyDown(e))return}if(e.key===`Enter`){let t=_.thread().getState(),n=t.capabilities.queue;if(e.shiftKey&&(e.ctrlKey||e.metaKey)&&n&&b!==`none`&&_.composer().getState().canSend){e.preventDefault(),_.composer().send({steer:!0});return}if(e.shiftKey||t.isRunning&&!n)return;let r=!1;b===`ctrlEnter`?r=e.ctrlKey||e.metaKey:b===`enter`&&(r=!0),r&&(e.preventDefault(),C.current?.closest(`form`)?.requestSubmit())}}},D=async e=>{if(!m)return;let t=_.thread().getState().capabilities,n=Array.from(e.clipboardData?.files||[]);if(t.attachments&&n.length>0)try{e.preventDefault(),await Promise.all(n.map(e=>_.composer().addAttachment(e)))}catch(e){console.error(`Error adding attachment:`,e)}},O=e&&!S,k=(0,F.useCallback)(()=>{let e=C.current;!e||!O||(e.focus({preventScroll:!0}),e.setSelectionRange(e.value.length,e.value.length))},[O]);(0,F.useEffect)(()=>k(),[k]),Pw(()=>{_.composer().getState().type===`thread`&&f&&k()}),(0,F.useEffect)(()=>{if(!(_.composer().getState().type!==`thread`||!d))return _.on(`thread.runStart`,k)},[d,k,_]),(0,F.useEffect)(()=>{if(!(_.composer().getState().type!==`thread`||!p))return _.on(`threadListItem.switchedTo`,k)},[p,k,_]);let A=y?{"aria-controls":y.popoverId,"aria-expanded":!0,"aria-haspopup":`listbox`,"aria-activedescendant":y.highlightedItemId}:{},ee={name:`input`,value:x,...h,...A,ref:w,disabled:S,onChange:Oo(i,e=>{if(!_.composer().getState().isEditing)return;let t=e.nativeEvent.isComposing===!0;T.current&&!t&&(T.current=!1);let n=t||T.current;if(kv(()=>{_.composer().setText(e.target.value)}),n)return;let r=e.target.selectionStart??e.target.value.length;if(v)for(let e of v.getPlugins())e.setCursorPosition(r)}),onKeyDown:Oo(a,E),onCompositionStart:Oo(h.onCompositionStart,()=>{T.current=!0}),onCompositionEnd:Oo(h.onCompositionEnd,e=>{if(T.current=!1,!_.composer().getState().isEditing)return;let t=e.target;kv(()=>{_.composer().setText(t.value)});let n=t.selectionStart??t.value.length;if(v)for(let e of v.getPlugins())e.setCursorPosition(n)}),onSelect:Oo(s,e=>{if(T.current)return;let t=e.target,n=t.selectionStart??t.value.length;if(v)for(let e of v.getPlugins())e.setCursorPosition(n)}),onPaste:Oo(o,D)};if(n&&(0,F.isValidElement)(n)){let e=h.children===void 0?n.props.children:h.children;return(0,L.jsx)(uo,{...ee,children:(0,F.cloneElement)(n,void 0,e)})}return(0,L.jsx)(t?uo:ute,{...ee})});Vw.displayName=`ComposerPrimitive.Input`;var _te=vw(`ComposerPrimitive.Cancel`,()=>{let{disabled:e,cancel:t}=HC();return e?null:t}),Hw=()=>Ny(e=>{if(e.part.type!==`text`&&e.part.type!==`reasoning`)throw Error(`MessagePartText can only be used inside text or reasoning message parts.`);return e.part}),Uw=(0,F.createContext)(null),vte=e=>({useSmoothStatus:Vy(()=>e)}),yte=({children:e})=>{let t=Ww({optional:!0}),n=My(),[r]=(0,F.useState)(()=>vte(n.part().getState().status));return t?e:(0,L.jsx)(Uw.Provider,{value:r,children:e})},bte=e=>{let t=(0,F.forwardRef)((t,n)=>(0,L.jsx)(yte,{children:(0,L.jsx)(e,{...t,ref:n})}));return t.displayName=e.displayName,t};function Ww(e){let t=(0,F.useContext)(Uw);if(!e?.optional&&!t)throw Error(`This component must be used within a SmoothContextProvider.`);return t}var{useSmoothStatus:xte,useSmoothStatusStore:Ste}=qC(Ww,`useSmoothStatus`),Cte=class{currentText;setText;animationFrameId=null;lastUpdateTime=Date.now();targetText=``;constructor(e,t){this.currentText=e,this.setText=t}start(){this.animationFrameId===null&&(this.lastUpdateTime=Date.now(),this.animate())}stop(){this.animationFrameId!==null&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null)}animate=()=>{let e=Date.now(),t=e-this.lastUpdateTime,n=this.targetText.length-this.currentText.length,r=Math.min(5,250/n),i=0;for(;t>=r&&i<n;)i++,t-=r;i===n?this.animationFrameId=null:this.animationFrameId=requestAnimationFrame(this.animate),i!==0&&(this.currentText=this.targetText.slice(0,this.currentText.length+i),this.lastUpdateTime=e-t,this.setText(this.currentText))}},Gw=Object.freeze({type:`running`}),Kw=(e,t=!1)=>{let{text:n}=e,r=Ny(e=>e.message.id),i=(0,F.useRef)(r),[a,o]=(0,F.useState)(e.status.type===`running`?``:n),s=Ste({optional:!0}),c=ts(t=>{if(o(t),s){let n=a!==t||e.status.type===`running`?Gw:e.status;ZC(s).setState(n,!0)}});(0,F.useEffect)(()=>{if(s){let r=t&&(a!==n||e.status.type===`running`)?Gw:e.status;ZC(s).setState(r,!0)}},[s,t,n,a,e.status]);let[l]=(0,F.useState)(new Cte(a,c));return(0,F.useEffect)(()=>{if(!t){l.stop();return}if(i.current!==r||!n.startsWith(l.targetText)){i.current=r,e.status.type===`running`?(c(``),l.currentText=``,l.targetText=n,l.start()):(c(n),l.currentText=n,l.targetText=n,l.stop());return}l.targetText=n,l.start()},[c,l,r,t,n,e.status.type]),(0,F.useEffect)(()=>()=>{l.stop()},[l]),(0,F.useMemo)(()=>t?{type:`text`,text:a,status:n===a?e.status:Gw}:e,[t,a,e,n])},qw=(0,F.forwardRef)(({smooth:e=!0,component:t=`span`,...n},r)=>{let{text:i,status:a}=Kw(Hw(),e);return(0,L.jsx)(t,{"data-status":a.type,...n,ref:r,children:i})});qw.displayName=`MessagePartPrimitive.Text`;var wte=()=>Ny(e=>{if(e.part.type!==`image`)throw Error(`MessagePartImage can only be used inside image message parts.`);return e.part}),Jw=(0,F.forwardRef)((e,t)=>{let{image:n}=wte();return(0,L.jsx)(_w.img,{src:n,...e,ref:t})});Jw.displayName=`MessagePartPrimitive.Image`;var Yw=({children:e})=>Ny(e=>e.part.status.type===`running`)?e:null;Yw.displayName=`MessagePartPrimitive.InProgress`;var Xw=e=>{let t=(0,F.useRef)(void 0);return(0,F.useCallback)(n=>{t.current&&=(t.current(),void 0),n&&(t.current=e(n))},[e])},Zw=(e,t)=>{let n=e.trim().match(/^(\d+(?:\.\d+)?|\.\d+)(em|px|rem)$/);if(!n)return 1/0;let r=Number(n[1]),i=n[2];return i===`px`?r:i===`em`?r*(parseFloat(getComputedStyle(t).fontSize)||16):i===`rem`?r*(parseFloat(getComputedStyle(document.documentElement).fontSize)||16):1/0},Tte=e=>e.dataset.messageId,Ete=()=>{let e=document.createElement(`div`);return e.dataset.auiTopAnchorReserve=``,e.style.height=`0px`,e.style.flexShrink=`0`,e.style.pointerEvents=`none`,e.setAttribute(`aria-hidden`,`true`),e},Qw=(e,t)=>{let n=`${t}px`;return e.style.height===n?!1:(e.style.height=n,!0)},Dte=e=>{let t=window.devicePixelRatio||1;return Math.round(e*t)/t},$w=()=>{let e=My(),t=Ny(()=>e.message());return Xw((0,F.useCallback)(e=>{let n=()=>{t.setIsHovering(!0)},r=()=>{t.setIsHovering(!1)};return e.addEventListener(`mouseenter`,n),e.addEventListener(`mouseleave`,r),e.matches(`:hover`)&&queueMicrotask(()=>t.setIsHovering(!0)),()=>{e.removeEventListener(`mouseenter`,n),e.removeEventListener(`mouseleave`,r),t.setIsHovering(!1)}},[t]))},Ote=()=>{let e=YC(e=>e.topAnchorTurn?.anchorId);return Ny(t=>t.message.role===`user`&&t.message.index>0&&t.message.index===t.thread.messages.length-2&&t.thread.messages.at(-1)?.role===`assistant`&&(t.message.id===e||t.thread.isRunning))},kte=()=>{let e=YC(e=>e.topAnchorTurn?.targetId);return Ny(t=>t.message.isLast&&t.message.role===`assistant`&&t.message.index>=1&&t.thread.messages.at(t.message.index-1)?.role===`user`&&(t.message.id===e||t.thread.isRunning))},Ate=(e,t)=>Xw((0,F.useCallback)(n=>{if(e)return t.getState().registerAnchorElement(n)},[e,t])),jte=({active:e,threadViewportStore:t})=>Xw((0,F.useCallback)(n=>{if(!e)return;let r=t.getState(),i=r.topAnchorMessageClamp;return r.registerAnchorTargetElement(n,{tallerThan:Zw(i.tallerThan,n),visibleHeight:Zw(i.visibleHeight,n)})},[e,t])),Mte=({forwardedRef:e,...t})=>{let n=co(e,$w()),r=Ny(e=>e.message.id);return(0,L.jsx)(_w.div,{...t,ref:n,"data-message-id":r})},Nte=({forwardedRef:e,threadViewportStore:t,...n})=>{let r=$w(),i=Ote(),a=kte(),o=co(e,r,Ate(i,t),jte({active:a,threadViewportStore:t})),s=Ny(e=>e.message.id);return(0,L.jsx)(_w.div,{...n,ref:o,"data-message-id":s,"data-aui-top-anchor-user":i?``:void 0,"data-aui-top-anchor-target":a?``:void 0})},eT=(0,F.forwardRef)((e,t)=>{let n=XC();return n.getState().turnAnchor===`top`?(0,L.jsx)(Nte,{...e,forwardedRef:t,threadViewportStore:n}):(0,L.jsx)(Mte,{...e,forwardedRef:t})});eT.displayName=`MessagePrimitive.Root`;var tT={...hC,Text:()=>(0,L.jsxs)(`p`,{style:{whiteSpace:`pre-line`},children:[(0,L.jsx)(qw,{}),(0,L.jsx)(Yw,{children:(0,L.jsx)(`span`,{style:{fontFamily:`revert`},children:` ●`})})]}),Image:()=>(0,L.jsx)(Jw,{})},nT=e=>{if(`children`in e)return(0,L.jsx)(jC,{children:e.children});let{components:t,...n}=e;return(0,L.jsx)(jC,{components:t?{Text:t.Text??tT.Text,Image:t.Image??tT.Image,Reasoning:t.Reasoning??hC.Reasoning,Source:t.Source??hC.Source,File:t.File??hC.File,Unstable_Audio:t.Unstable_Audio??hC.Unstable_Audio,...`ChainOfThought`in t?{ChainOfThought:t.ChainOfThought}:{tools:t.tools,data:t.data,ToolGroup:t.ToolGroup??hC.ToolGroup,ReasoningGroup:t.ReasoningGroup??hC.ReasoningGroup},Empty:t.Empty,Quote:t.Quote}:tT,...n})};nT.displayName=`MessagePrimitive.Parts`;var rT=(0,F.forwardRef)((e,t)=>(0,L.jsx)(_w.div,{...e,ref:t}));rT.displayName=`ThreadPrimitive.Root`;var Pte=e=>{let t=ts(e);return Xw((0,F.useCallback)(e=>{let n=new ResizeObserver(()=>{t()}),r=new MutationObserver(e=>{e.some(e=>e.type!==`attributes`||e.attributeName!==`style`)&&t()});return n.observe(e),r.observe(e,{childList:!0,subtree:!0,attributes:!0,characterData:!0}),()=>{n.disconnect(),r.disconnect()}},[t]))},Fte=({autoScroll:e,scrollToBottomOnRunStart:t=!0,scrollToBottomOnInitialize:n=!0,scrollToBottomOnThreadSwitch:r=!0})=>{let i=(0,F.useRef)(null),a=XC();e===void 0&&(e=a.getState().turnAnchor!==`top`);let o=(0,F.useRef)(0),s=(0,F.useRef)(null),c=(0,F.useCallback)(e=>{let t=i.current;t&&(s.current=e,t.scrollTo({top:t.scrollHeight,behavior:e}))},[]),l=(0,F.useCallback)(()=>{let e=a.getState();return e.turnAnchor===`top`&&e.element.viewport===i.current&&e.element.anchor!==null},[a]),u=()=>{let e=i.current;if(!e)return;let t=a.getState().isAtBottom,n=Math.abs(e.scrollHeight-e.scrollTop-e.clientHeight)<1||e.scrollHeight<=e.clientHeight;!n&&o.current<e.scrollTop||(n&&(s.current=null),(n||s.current===null)&&n!==t&&ZC(a).setState({isAtBottom:n})),o.current=e.scrollTop},d=Pte(()=>{let t=s.current;t&&l()?s.current=null:t?c(t):e&&a.getState().isAtBottom&&c(`instant`),u()}),f=Xw(e=>(e.addEventListener(`scroll`,u),()=>{e.removeEventListener(`scroll`,u)}));return Pw(({behavior:e})=>{c(e)}),Fy(`thread.runStart`,()=>{t&&a.getState().turnAnchor!==`top`&&(s.current=`auto`,requestAnimationFrame(()=>{c(`auto`)}))}),Fy(`thread.initialize`,()=>{n&&(s.current=`instant`,requestAnimationFrame(()=>{c(`instant`)}))}),Fy(`threadListItem.switchedTo`,()=>{r&&(s.current=`instant`,requestAnimationFrame(()=>{c(`instant`)}))}),co(d,f,i)},Ite=(e,t)=>Xw((0,F.useCallback)(n=>{if(!e)return;let r=e(),i=()=>{let e=t?t(n):n.offsetHeight;r.setHeight(e)},a=new ResizeObserver(i);return a.observe(n),i(),()=>{a.disconnect(),r.unregister()}},[e,t])),iT=e=>{let t=0,n=e;for(;n;)t+=n.offsetTop,n=n.offsetParent;return t},Lte=(e,t)=>{let n=0,r=e;for(;r&&r!==t;)n+=r.offsetTop,r=r.offsetParent;return r===t?n:iT(e)-iT(t)},aT=({viewport:e,anchor:t,tallerThan:n,visibleHeight:r})=>{let i=Lte(t,e),a=t.offsetHeight;return i+Math.max(0,a-(a<=n?a:r))},Rte=({scrollHeight:e,...t})=>{let{viewport:n}=t,r=aT(t)+n.clientHeight;return Math.max(0,r-e)},zte=({viewport:e,reserve:t,...n})=>Rte({viewport:e,...n,scrollHeight:e.scrollHeight-t.offsetHeight}),Bte=e=>{let t=new ResizeObserver(e),n=new MutationObserver(e),r=null,i=null,a=null,o=()=>{t.disconnect(),n.disconnect(),r=null,i=null,a=null};return{target:(e,s,c)=>{r===e&&i===s&&a===c||(o(),t.observe(e),t.observe(s),t.observe(c),n.observe(c,{childList:!0,subtree:!0,characterData:!0}),r=e,i=s,a=c)},disconnect:o}},Vte=e=>{let t=null;return{schedule:()=>{t===null&&(t=requestAnimationFrame(()=>{t=null,e()}))},cancel:()=>{t!==null&&(cancelAnimationFrame(t),t=null)}}},Hte=e=>{let t=null,n;function r(){let r=e.getState(),{viewport:o,anchor:s,target:c}=r.element,l=r.targetConfig;if(r.turnAnchor!==`top`||!o||!s||!c||!l){a.disconnect(),t&&(Qw(t,0),t.remove());return}if(t??=Ete(),(t.parentElement!==c.parentElement||t.previousElementSibling!==c)&&c.after(t),a.target(o,s,c),Qw(t,zte({viewport:o,anchor:s,reserve:t,...l}))){i.schedule();return}let u=Tte(s);if(u!==void 0&&n===u)return;let d=Dte(aT({viewport:o,anchor:s,...l}));Math.abs(o.scrollTop-d)>1&&o.scrollTo({top:d,behavior:`smooth`}),u!==void 0&&(n=u)}let i=Vte(r),a=Bte(i.schedule);i.schedule();let o=e.subscribe(i.schedule);return()=>{i.cancel(),o(),a.disconnect(),t?.remove()}},Ute=e=>{let t=XC();(0,F.useLayoutEffect)(()=>{if(e)return Hte(t)},[e,t])},oT=({isRunning:e,messages:t})=>{if(!e)return null;let n=t.at(-1),r=t.at(-2);return r?.role!==`user`||n?.role!==`assistant`?null:{anchorId:r.id,targetId:n.id}},Wte=e=>oT(e)?.anchorId,Gte=e=>oT(e)?.targetId,Kte=()=>Ite(YC(e=>e.registerViewport),(0,F.useCallback)(e=>e.clientHeight,[])),qte=()=>Xw(YC(e=>e.registerViewportElement)),Jte=e=>{let t=XC(),n=Ny(t=>{if(e)return Wte(t.thread)}),r=Ny(t=>{if(e)return Gte(t.thread)}),i=(0,F.useMemo)(()=>!n||!r?null:{anchorId:n,targetId:r},[n,r]);(0,F.useLayoutEffect)(()=>{if(!i)return;let e=t.getState(),n=e.topAnchorTurn;n?.anchorId===i.anchorId&&n.targetId===i.targetId||e.setTopAnchorTurn(i)},[i,t]);let a=(0,F.useCallback)(()=>{t.getState().setTopAnchorTurn(null)},[t]);Fy(`thread.initialize`,a),Fy(`threadListItem.switchedTo`,a)},sT=(0,F.forwardRef)(({autoScroll:e,scrollToBottomOnRunStart:t,scrollToBottomOnInitialize:n,scrollToBottomOnThreadSwitch:r,children:i,...a},o)=>{let s=Fte({autoScroll:e,scrollToBottomOnRunStart:t,scrollToBottomOnInitialize:n,scrollToBottomOnThreadSwitch:r}),c=Kte(),l=qte(),u=XC().getState().turnAnchor===`top`;Jte(u),Ute(u);let d=co(o,s,c,l);return(0,L.jsx)(_w.div,{...a,ref:d,children:i})});sT.displayName=`ThreadPrimitive.ViewportScrollable`;var cT=(0,F.forwardRef)(({turnAnchor:e,topAnchorMessageClamp:t,...n},r)=>(0,L.jsx)($C,{options:{turnAnchor:e,topAnchorMessageClamp:t},children:(0,L.jsx)(sT,{...n,ref:r})}));cT.displayName=`ThreadPrimitive.Viewport`;var Yte=t({AssistantRuntimeImpl:()=>gS,BaseAssistantRuntimeCore:()=>dx,CompositeContextProvider:()=>gb,DefaultThreadComposerRuntimeCore:()=>Fx,MessageRepository:()=>Ox,ThreadRuntimeImpl:()=>dS,fromThreadMessageLike:()=>wx,generateId:()=>px,getAutoStatus:()=>Sx,splitLocalRuntimeOptions:()=>UC,useComposerInputPluginRegistryOptional:()=>Iw,useSmooth:()=>Kw,useSmoothStatus:()=>xte,useToolInvocations:()=>OS,withSmoothContextProvider:()=>bte});function Xte(e,t){let n=getComputedStyle(e);return t*parseFloat(n.fontSize)}function Zte(e,t){let n=getComputedStyle(e.ownerDocument.body);return t*parseFloat(n.fontSize)}function Qte(e){return e/100*window.innerHeight}function $te(e){return e/100*window.innerWidth}function ene(e){switch(typeof e){case`number`:return[e,`px`];case`string`:{let t=parseFloat(e);return e.endsWith(`%`)?[t,`%`]:e.endsWith(`px`)?[t,`px`]:e.endsWith(`rem`)?[t,`rem`]:e.endsWith(`em`)?[t,`em`]:e.endsWith(`vh`)?[t,`vh`]:e.endsWith(`vw`)?[t,`vw`]:[t,`%`]}}}function lT({groupSize:e,panelElement:t,styleProp:n}){let r,[i,a]=ene(n);switch(a){case`%`:r=i/100*e;break;case`px`:r=i;break;case`rem`:r=Zte(t,i);break;case`em`:r=Xte(t,i);break;case`vh`:r=Qte(i);break;case`vw`:r=$te(i);break}return r}function uT(e){return parseFloat(e.toFixed(3))}function dT({group:e}){let{orientation:t,panels:n}=e;return n.reduce((e,n)=>(e+=t===`horizontal`?n.element.offsetWidth:n.element.offsetHeight,e),0)}function fT(e){let{panels:t}=e,n=dT({group:e});return n===0?t.map(e=>({groupResizeBehavior:e.panelConstraints.groupResizeBehavior,collapsedSize:0,collapsible:e.panelConstraints.collapsible===!0,defaultSize:void 0,disabled:e.panelConstraints.disabled,minSize:0,maxSize:100,panelId:e.id})):t.map(e=>{let{element:t,panelConstraints:r}=e,i=0;r.collapsedSize!==void 0&&(i=uT(lT({groupSize:n,panelElement:t,styleProp:r.collapsedSize})/n*100));let a;r.defaultSize!==void 0&&(a=uT(lT({groupSize:n,panelElement:t,styleProp:r.defaultSize})/n*100));let o=0;r.minSize!==void 0&&(o=uT(lT({groupSize:n,panelElement:t,styleProp:r.minSize})/n*100));let s=100;return r.maxSize!==void 0&&(s=uT(lT({groupSize:n,panelElement:t,styleProp:r.maxSize})/n*100)),{groupResizeBehavior:r.groupResizeBehavior,collapsedSize:i,collapsible:r.collapsible===!0,defaultSize:a,disabled:r.disabled,minSize:o,maxSize:s,panelId:e.id}})}function pT(e,t=`Assertion error`){if(!e)throw Error(t)}function mT(e,t){return Array.from(t).sort(e===`horizontal`?tne:nne)}function tne(e,t){let n=e.element.offsetLeft-t.element.offsetLeft;return n===0?e.element.offsetWidth-t.element.offsetWidth:n}function nne(e,t){let n=e.element.offsetTop-t.element.offsetTop;return n===0?e.element.offsetHeight-t.element.offsetHeight:n}function hT(e){return typeof e==`object`&&!!e&&`nodeType`in e&&e.nodeType===Node.ELEMENT_NODE}function gT(e,t){return{x:e.x>=t.left&&e.x<=t.right?0:Math.min(Math.abs(e.x-t.left),Math.abs(e.x-t.right)),y:e.y>=t.top&&e.y<=t.bottom?0:Math.min(Math.abs(e.y-t.top),Math.abs(e.y-t.bottom))}}function rne({orientation:e,rects:t,targetRect:n}){let r={x:n.x+n.width/2,y:n.y+n.height/2},i,a=Number.MAX_VALUE;for(let n of t){let{x:t,y:o}=gT(r,n),s=e===`horizontal`?t:o;s<a&&(a=s,i=n)}return pT(i,`No rect found`),i}var _T;function ine(){return _T===void 0&&(_T=typeof matchMedia==`function`?!!matchMedia(`(pointer:coarse)`).matches:!1),_T}function vT(e){let{element:t,orientation:n,panels:r,separators:i}=e,a=mT(n,Array.from(t.children).filter(hT).map(e=>({element:e}))).map(({element:e})=>e),o=[],s=!1,c=!1,l=-1,u=-1,d=0,f,p=[];{let e=-1;for(let t of a)t.hasAttribute(`data-panel`)&&(e++,t.hasAttribute(`data-disabled`)||(d++,l===-1&&(l=e),u=e))}if(d>1){let t=-1;for(let d of a)if(d.hasAttribute(`data-panel`)){t++;let i=r.find(e=>e.element===d);if(i){if(f){let r=f.element.getBoundingClientRect(),a=d.getBoundingClientRect(),m;if(c){let e=n===`horizontal`?new DOMRect(r.right,r.top,0,r.height):new DOMRect(r.left,r.bottom,r.width,0),t=n===`horizontal`?new DOMRect(a.left,a.top,0,a.height):new DOMRect(a.left,a.top,a.width,0);switch(p.length){case 0:m=[e,t];break;case 1:{let i=p[0];m=[i,rne({orientation:n,rects:[r,a],targetRect:i.element.getBoundingClientRect()})===r?t:e];break}default:m=p;break}}else m=p.length?p:[n===`horizontal`?new DOMRect(r.right,a.top,a.left-r.right,a.height):new DOMRect(a.left,r.bottom,a.width,a.top-r.bottom)];for(let n of m){let r=`width`in n?n:n.element.getBoundingClientRect(),a=ine()?e.resizeTargetMinimumSize.coarse:e.resizeTargetMinimumSize.fine;if(r.width<a){let e=a-r.width;r=new DOMRect(r.x-e/2,r.y,r.width+e,r.height)}if(r.height<a){let e=a-r.height;r=new DOMRect(r.x,r.y-e/2,r.width,r.height+e)}!s&&!(t<=l||t>u)&&o.push({group:e,groupSize:dT({group:e}),panels:[f,i],separator:`width`in n?void 0:n,rect:r}),s=!1}}c=!1,f=i,p=[]}}else if(d.hasAttribute(`data-separator`)){d.ariaDisabled!==null&&(s=!0);let e=i.find(e=>e.element===d);e?p.push(e):(f=void 0,p=[])}else c=!0}return o}var yT=class{#e={};addListener(e,t){let n=this.#e[e];return n===void 0?this.#e[e]=[t]:n.includes(t)||n.push(t),()=>{this.removeListener(e,t)}}emit(e,t){let n=this.#e[e];if(n!==void 0)if(n.length===1)n[0].call(null,t);else{let e=!1,r=null,i=Array.from(n);for(let n=0;n<i.length;n++){let a=i[n];try{a.call(null,t)}catch(t){r===null&&(e=!0,r=t)}}if(e)throw r}}removeAllListeners(){this.#e={}}removeListener(e,t){let n=this.#e[e];if(n!==void 0){let e=n.indexOf(t);e>=0&&n.splice(e,1)}}},bT=new Map,xT=new yT;function ST(e){bT=new Map(bT),bT.delete(e)}function CT(e,t){for(let[t]of bT)if(t.id===e)return t}function wT(e,t){for(let[t,n]of bT)if(t.id===e)return n;if(t)throw Error(`Could not find data for Group with id ${e}`)}function TT(){return bT}function ET(e,t){return xT.addListener(`groupChange`,n=>{n.group.id===e&&t(n)})}function DT(e,t){let n=bT.get(e);bT=new Map(bT),bT.set(e,t),xT.emit(`groupChange`,{group:e,prev:n,next:t})}function OT(e,t,n){let r,i={x:1/0,y:1/0};for(let a of t){let t=gT(n,a.rect);switch(e){case`horizontal`:t.x<=i.x&&(r=a,i=t);break;case`vertical`:t.y<=i.y&&(r=a,i=t);break}}return r?{distance:i,hitRegion:r}:void 0}function kT(e){return typeof e==`object`&&!!e&&`nodeType`in e&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE}function AT(e,t){if(e===t)throw Error(`Cannot compare node with itself`);let n={a:IT(e),b:IT(t)},r;for(;n.a.at(-1)===n.b.at(-1);)r=n.a.pop(),n.b.pop();pT(r,`Stacking order can only be calculated for elements with a common ancestor`);let i={a:FT(PT(n.a)),b:FT(PT(n.b))};if(i.a===i.b){let e=r.childNodes,t={a:n.a.at(-1),b:n.b.at(-1)},i=e.length;for(;i--;){let n=e[i];if(n===t.a)return 1;if(n===t.b)return-1}}return Math.sign(i.a-i.b)}var jT=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function MT(e){let t=getComputedStyle(LT(e)??e).display;return t===`flex`||t===`inline-flex`}function NT(e){let t=getComputedStyle(e);return!!(t.position===`fixed`||t.zIndex!==`auto`&&(t.position!==`static`||MT(e))||+t.opacity<1||`transform`in t&&t.transform!==`none`||`webkitTransform`in t&&t.webkitTransform!==`none`||`mixBlendMode`in t&&t.mixBlendMode!==`normal`||`filter`in t&&t.filter!==`none`||`webkitFilter`in t&&t.webkitFilter!==`none`||`isolation`in t&&t.isolation===`isolate`||jT.test(t.willChange)||t.webkitOverflowScrolling===`touch`)}function PT(e){let t=e.length;for(;t--;){let n=e[t];if(pT(n,`Missing node`),NT(n))return n}return null}function FT(e){return e&&Number(getComputedStyle(e).zIndex)||0}function IT(e){let t=[];for(;e;)t.push(e),e=LT(e);return t}function LT(e){let{parentNode:t}=e;return kT(t)?t.host:t}function RT(e,t){return e.x<t.x+t.width&&e.x+e.width>t.x&&e.y<t.y+t.height&&e.y+e.height>t.y}function zT({groupElement:e,hitRegion:t,pointerEventTarget:n}){if(!hT(n)||n.contains(e)||e.contains(n))return!0;if(AT(n,e)>0){let r=n;for(;r;){if(r.contains(e))return!0;if(RT(r.getBoundingClientRect(),t))return!1;r=r.parentElement}}return!0}function BT(e,t){let n=[];return t.forEach((t,r)=>{if(r.disabled)return;let i=vT(r),a=OT(r.orientation,i,{x:e.clientX,y:e.clientY});a&&a.distance.x<=0&&a.distance.y<=0&&zT({groupElement:r.element,hitRegion:a.hitRegion.rect,pointerEventTarget:e.target})&&n.push(a.hitRegion)}),n}function VT(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!=t[n])return!1;return!0}function HT(e,t,n=0){return Math.abs(uT(e)-uT(t))<=n}function UT(e,t){return HT(e,t)?0:e>t?1:-1}function WT({overrideDisabledPanels:e,panelConstraints:t,prevSize:n,size:r}){let{collapsedSize:i=0,collapsible:a,disabled:o,maxSize:s=100,minSize:c=0}=t;if(o&&!e)return n;if(UT(r,c)<0)if(a){let e=(i+c)/2;r=UT(r,e)<0?i:c}else r=c;return r=Math.min(s,r),r=uT(r),r}function GT({delta:e,initialLayout:t,panelConstraints:n,pivotIndices:r,prevLayout:i,trigger:a}){if(HT(e,0))return t;let o=a===`imperative-api`,s=Object.values(t),c=Object.values(i),l=[...s],[u,d]=r;pT(u!=null,`Invalid first pivot index`),pT(d!=null,`Invalid second pivot index`);let f=0;switch(a){case`keyboard`:{let t=e<0?d:u,r=n[t];pT(r,`Panel constraints not found for index ${t}`);let{collapsedSize:i=0,collapsible:a,minSize:o=0}=r;if(a){let n=s[t];if(pT(n!=null,`Previous layout not found for panel index ${t}`),HT(n,i)){let t=o-n;UT(t,Math.abs(e))>0&&(e=e<0?0-t:t)}}}{let t=e<0?u:d,r=n[t];pT(r,`No panel constraints found for index ${t}`);let{collapsedSize:i=0,collapsible:a,minSize:o=0}=r;if(a){let n=s[t];if(pT(n!=null,`Previous layout not found for panel index ${t}`),HT(n,o)){let t=n-i;UT(t,Math.abs(e))>0&&(e=e<0?0-t:t)}}}break;default:{let t=e<0?d:u,r=n[t];pT(r,`Panel constraints not found for index ${t}`);let i=s[t],{collapsible:a,collapsedSize:o,minSize:c}=r;if(a&&UT(i,c)<0)if(e>0){let t=c-o,n=t/2;UT(i+e,c)<0&&(e=UT(e,n)<=0?0:t)}else{let t=c-o,n=100-t/2;UT(i-e,c)<0&&(e=UT(100+e,n)>0?0:-t)}break}}{let t=e<0?1:-1,r=e<0?d:u,i=0;for(;;){let e=s[r];pT(e!=null,`Previous layout not found for panel index ${r}`);let a=WT({overrideDisabledPanels:o,panelConstraints:n[r],prevSize:e,size:100})-e;if(i+=a,r+=t,r<0||r>=n.length)break}let a=Math.min(Math.abs(e),Math.abs(i));e=e<0?0-a:a}{let t=e<0?u:d;for(;t>=0&&t<n.length;){let r=Math.abs(e)-Math.abs(f),i=s[t];pT(i!=null,`Previous layout not found for panel index ${t}`);let a=i-r,c=WT({overrideDisabledPanels:o,panelConstraints:n[t],prevSize:i,size:a});if(!HT(i,c)&&(f+=i-c,l[t]=c,f.toFixed(3).localeCompare(Math.abs(e).toFixed(3),void 0,{numeric:!0})>=0))break;e<0?t--:t++}}if(VT(c,l))return i;{let t=e<0?d:u,r=s[t];pT(r!=null,`Previous layout not found for panel index ${t}`);let i=r+f,a=WT({overrideDisabledPanels:o,panelConstraints:n[t],prevSize:r,size:i});if(l[t]=a,!HT(a,i)){let t=i-a,r=e<0?d:u;for(;r>=0&&r<n.length;){let i=l[r];pT(i!=null,`Previous layout not found for panel index ${r}`);let a=i+t,s=WT({overrideDisabledPanels:o,panelConstraints:n[r],prevSize:i,size:a});if(HT(i,s)||(t-=s-i,l[r]=s),HT(t,0))break;e>0?r--:r++}}}if(!HT(Object.values(l).reduce((e,t)=>t+e,0),100,.1))return i;let p=Object.keys(i);return l.reduce((e,t,n)=>(e[p[n]]=t,e),{})}function KT(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(let n in e)if(t[n]===void 0||UT(e[n],t[n])!==0)return!1;return!0}function qT({layout:e,panelConstraints:t}){let n=Object.values(e),r=[...n],i=r.reduce((e,t)=>e+t,0);if(r.length!==t.length)throw Error(`Invalid ${t.length} panel layout: ${r.map(e=>`${e}%`).join(`, `)}`);if(!HT(i,100)&&r.length>0)for(let e=0;e<t.length;e++){let t=r[e];pT(t!=null,`No layout data found for index ${e}`),r[e]=100/i*t}let a=0;for(let e=0;e<t.length;e++){let i=n[e];pT(i!=null,`No layout data found for index ${e}`);let o=r[e];pT(o!=null,`No layout data found for index ${e}`);let s=WT({overrideDisabledPanels:!0,panelConstraints:t[e],prevSize:i,size:o});o!=s&&(a+=o-s,r[e]=s)}if(!HT(a,0))for(let e=0;e<t.length;e++){let n=r[e];pT(n!=null,`No layout data found for index ${e}`);let i=n+a,o=WT({overrideDisabledPanels:!0,panelConstraints:t[e],prevSize:n,size:i});if(n!==o&&(a-=o-n,r[e]=o,HT(a,0)))break}let o=Object.keys(e);return r.reduce((e,t,n)=>(e[o[n]]=t,e),{})}function JT({groupId:e,panelId:t}){let n=()=>{let t=TT();for(let[n,{defaultLayoutDeferred:r,derivedPanelConstraints:i,layout:a,groupSize:o,separatorToPanels:s}]of t)if(n.id===e)return{defaultLayoutDeferred:r,derivedPanelConstraints:i,group:n,groupSize:o,layout:a,separatorToPanels:s};throw Error(`Group ${e} not found`)},r=()=>{let e=n().derivedPanelConstraints.find(e=>e.panelId===t);if(e!==void 0)return e;throw Error(`Panel constraints not found for Panel ${t}`)},i=()=>{let e=n().group.panels.find(e=>e.id===t);if(e!==void 0)return e;throw Error(`Layout not found for Panel ${t}`)},a=()=>{let e=n().layout[t];if(e!==void 0)return e;throw Error(`Layout not found for Panel ${t}`)},o=({nextSize:e,panels:n,prevLayout:r,derivedPanelConstraints:i})=>{let o=a(),s=n.findIndex(e=>e.id===t),c=s===0,l=s===n.length-1;if(l&&e<o&&(c||n.slice(0,s).every((e,t)=>{let n=i[t];return n?.collapsible&&HT(n.collapsedSize,r[n.panelId])}))){let e=n.slice(0,s).reduce((e,t)=>e+r[t.id],0);return{...r,[t]:uT(100-e)}}return GT({delta:l?o-e:e-o,initialLayout:r,panelConstraints:i,pivotIndices:l?[s-1,s]:[s,s+1],prevLayout:r,trigger:`imperative-api`})},s=e=>{if(e===a())return;let{defaultLayoutDeferred:t,derivedPanelConstraints:r,group:i,groupSize:s,layout:c,separatorToPanels:l}=n(),u=qT({layout:o({nextSize:e,panels:i.panels,prevLayout:c,derivedPanelConstraints:r}),panelConstraints:r});KT(c,u)||DT(i,{defaultLayoutDeferred:t,derivedPanelConstraints:r,groupSize:s,layout:u,separatorToPanels:l})};return{collapse:()=>{let{collapsible:e,collapsedSize:t}=r(),{mutableValues:n}=i(),o=a();e&&o!==t&&(n.expandToSize=o,s(t))},expand:()=>{let{collapsible:e,collapsedSize:t,minSize:n}=r(),{mutableValues:o}=i(),c=a();if(e&&c===t){let e=o.expandToSize??n;e===0&&(e=1),s(e)}},getSize:()=>{let{group:e}=n(),t=a(),{element:r}=i();return{asPercentage:t,inPixels:e.orientation===`horizontal`?r.offsetWidth:r.offsetHeight}},isCollapsed:()=>{let{collapsible:e,collapsedSize:t}=r(),n=a();return e&&HT(t,n)},resize:e=>{let{group:t}=n(),{element:r}=i(),a=dT({group:t});s(uT(lT({groupSize:a,panelElement:r,styleProp:e})/a*100))}}}function YT(e){e.defaultPrevented||BT(e,TT()).forEach(t=>{if(t.separator&&!t.separator.disableDoubleClick){let n=t.panels.find(e=>e.panelConstraints.defaultSize!==void 0);if(n){let r=n.panelConstraints.defaultSize,i=JT({groupId:t.group.id,panelId:n.id});i&&r!==void 0&&(i.resize(r),e.preventDefault())}}})}function XT(e){let t=TT();for(let[n]of t)if(n.separators.some(t=>t.element===e))return n;throw Error(`Could not find parent Group for separator element`)}function ZT({groupId:e}){let t=()=>{let t=TT();for(let[n,r]of t)if(n.id===e)return{group:n,...r};throw Error(`Could not find Group with id "${e}"`)};return{getLayout(){let{defaultLayoutDeferred:e,layout:n}=t();return e?{}:n},setLayout(e){let{defaultLayoutDeferred:n,derivedPanelConstraints:r,group:i,groupSize:a,layout:o,separatorToPanels:s}=t(),c=qT({layout:e,panelConstraints:r});return n?o:(KT(o,c)||DT(i,{defaultLayoutDeferred:n,derivedPanelConstraints:r,groupSize:a,layout:c,separatorToPanels:s}),c)}}}function QT(e,t){let n=XT(e),r=wT(n.id,!0),i=n.separators.find(t=>t.element===e);pT(i,`Matching separator not found`);let a=r.separatorToPanels.get(i);pT(a,`Matching panels not found`);let o=a.map(e=>n.panels.indexOf(e)),s=ZT({groupId:n.id}).getLayout(),c=qT({layout:GT({delta:t,initialLayout:s,panelConstraints:r.derivedPanelConstraints,pivotIndices:o,prevLayout:s,trigger:`keyboard`}),panelConstraints:r.derivedPanelConstraints});KT(s,c)||DT(n,{defaultLayoutDeferred:r.defaultLayoutDeferred,derivedPanelConstraints:r.derivedPanelConstraints,groupSize:r.groupSize,layout:c,separatorToPanels:r.separatorToPanels})}function $T(e){if(e.defaultPrevented)return;let t=e.currentTarget,n=XT(t);if(!n.disabled)switch(e.key){case`ArrowDown`:e.preventDefault(),n.orientation===`vertical`&&QT(t,5);break;case`ArrowLeft`:e.preventDefault(),n.orientation===`horizontal`&&QT(t,-5);break;case`ArrowRight`:e.preventDefault(),n.orientation===`horizontal`&&QT(t,5);break;case`ArrowUp`:e.preventDefault(),n.orientation===`vertical`&&QT(t,-5);break;case`End`:e.preventDefault(),QT(t,100);break;case`Enter`:{e.preventDefault();let n=XT(t),{derivedPanelConstraints:r,layout:i,separatorToPanels:a}=wT(n.id,!0),o=n.separators.find(e=>e.element===t);pT(o,`Matching separator not found`);let s=a.get(o);pT(s,`Matching panels not found`);let c=s[0],l=r.find(e=>e.panelId===c.id);if(pT(l,`Panel metadata not found`),l.collapsible){let e=i[c.id];QT(t,(l.collapsedSize===e?n.mutableState.expandedPanelSizes[c.id]??l.minSize:l.collapsedSize)-e)}break}case`F6`:{e.preventDefault();let n=XT(t).separators.map(e=>e.element),r=Array.from(n).findIndex(t=>t===e.currentTarget);pT(r!==null,`Index not found`),n[e.shiftKey?r>0?r-1:n.length-1:r+1<n.length?r+1:0].focus({preventScroll:!0});break}case`Home`:e.preventDefault(),QT(t,-100);break}}var eE={cursorFlags:0,state:`inactive`},tE=new yT;function nE(){return eE}function rE(e){return tE.addListener(`change`,e)}function iE(e){let t=eE,n={...eE};n.cursorFlags=e,eE=n,tE.emit(`change`,{prev:t,next:n})}function aE(e){let t=eE;eE=e,tE.emit(`change`,{prev:t,next:e})}function oE(e){if(e.defaultPrevented||e.pointerType===`mouse`&&e.button>0)return;let t=TT(),n=BT(e,t),r=new Map,i=!1;n.forEach(e=>{e.separator&&(i||(i=!0,e.separator.element.focus({focusVisible:!1,preventScroll:!0})));let n=t.get(e.group);n&&r.set(e.group,n.layout)}),aE({cursorFlags:0,hitRegions:n,initialLayoutMap:r,pointerDownAtPoint:{x:e.clientX,y:e.clientY},state:`active`}),n.length&&e.preventDefault()}var sE=e=>e,cE=()=>{},lE=1,uE=2,dE=4,fE=8,pE=3,mE=12,hE;function gE(){return hE===void 0&&(hE=!1,typeof window<`u`&&(window.navigator.userAgent.includes(`Chrome`)||window.navigator.userAgent.includes(`Firefox`))&&(hE=!0)),hE}function _E({cursorFlags:e,groups:t,state:n}){let r=0,i=0;switch(n){case`active`:case`hover`:t.forEach(e=>{if(!e.mutableState.disableCursor)switch(e.orientation){case`horizontal`:r++;break;case`vertical`:i++;break}})}if(!(r===0&&i===0)){switch(n){case`active`:if(e&&gE()){let t=(e&lE)!==0,n=(e&uE)!==0,r=(e&dE)!==0,i=(e&fE)!==0;if(t)return r?`se-resize`:i?`ne-resize`:`e-resize`;if(n)return r?`sw-resize`:i?`nw-resize`:`w-resize`;if(r)return`s-resize`;if(i)return`n-resize`}break}return gE()?r>0&&i>0?`move`:r>0?`ew-resize`:`ns-resize`:r>0&&i>0?`grab`:r>0?`col-resize`:`row-resize`}}var vE=new WeakMap;function yE(e){if(e.defaultView===null||e.defaultView===void 0)return;let{prevStyle:t,styleSheet:n}=vE.get(e)??{};n===void 0&&(n=new e.defaultView.CSSStyleSheet,e.adoptedStyleSheets&&(Object.isExtensible(e.adoptedStyleSheets)?e.adoptedStyleSheets.push(n):e.adoptedStyleSheets=[...e.adoptedStyleSheets,n]));let r=nE();switch(r.state){case`active`:case`hover`:{let e=_E({cursorFlags:r.cursorFlags,groups:r.hitRegions.map(e=>e.group),state:r.state}),i=`*, *:hover {cursor: ${e} !important; }`;if(t===i)return;t=i,e?n.cssRules.length===0?n.insertRule(i):n.replaceSync(i):n.cssRules.length===1&&n.deleteRule(0);break}case`inactive`:t=void 0,n.cssRules.length===1&&n.deleteRule(0);break}vE.set(e,{prevStyle:t,styleSheet:n})}function bE({document:e,event:t,hitRegions:n,initialLayoutMap:r,mountedGroups:i,pointerDownAtPoint:a,prevCursorFlags:o}){let s=0;n.forEach(e=>{let{group:n,groupSize:o}=e,{orientation:c,panels:l}=n,{disableCursor:u}=n.mutableState,d=0;d=a?c===`horizontal`?(t.clientX-a.x)/o*100:(t.clientY-a.y)/o*100:c===`horizontal`?t.clientX<0?-100:100:t.clientY<0?-100:100;let f=r.get(n),p=i.get(n);if(!f||!p)return;let{defaultLayoutDeferred:m,derivedPanelConstraints:h,groupSize:g,layout:_,separatorToPanels:v}=p;if(h&&_&&v){let t=GT({delta:d,initialLayout:f,panelConstraints:h,pivotIndices:e.panels.map(e=>l.indexOf(e)),prevLayout:_,trigger:`mouse-or-touch`});if(KT(t,_)){if(d!==0&&!u)switch(c){case`horizontal`:s|=d<0?lE:uE;break;case`vertical`:s|=d<0?dE:fE;break}}else DT(e.group,{defaultLayoutDeferred:m,derivedPanelConstraints:h,groupSize:g,layout:t,separatorToPanels:v})}});let c=0;t.movementX===0?c|=o&pE:c|=s&pE,t.movementY===0?c|=o&mE:c|=s&mE,iE(c),yE(e)}function xE(e){let t=TT(),n=nE();switch(n.state){case`active`:bE({document:e.currentTarget,event:e,hitRegions:n.hitRegions,initialLayoutMap:n.initialLayoutMap,mountedGroups:t,prevCursorFlags:n.cursorFlags})}}function SE(e){if(e.defaultPrevented)return;let t=nE(),n=TT();switch(t.state){case`active`:if(e.buttons===0){aE({cursorFlags:0,state:`inactive`}),t.hitRegions.forEach(e=>{let t=wT(e.group.id,!0);DT(e.group,t)});return}for(let n of t.hitRegions)if(n.separator){let{element:t}=n.separator;t.hasPointerCapture?.(e.pointerId)||t.setPointerCapture?.(e.pointerId)}bE({document:e.currentTarget,event:e,hitRegions:t.hitRegions,initialLayoutMap:t.initialLayoutMap,mountedGroups:n,pointerDownAtPoint:t.pointerDownAtPoint,prevCursorFlags:t.cursorFlags});break;default:{let r=BT(e,n);r.length===0?t.state!==`inactive`&&aE({cursorFlags:0,state:`inactive`}):aE({cursorFlags:0,hitRegions:r,state:`hover`}),yE(e.currentTarget);break}}}function CE(e){if(e.relatedTarget instanceof HTMLIFrameElement)switch(nE().state){case`hover`:aE({cursorFlags:0,state:`inactive`})}}function wE(e){if(e.defaultPrevented||e.pointerType===`mouse`&&e.button>0)return;let t=nE();switch(t.state){case`active`:aE({cursorFlags:0,state:`inactive`}),t.hitRegions.length>0&&(yE(e.currentTarget),t.hitRegions.forEach(e=>{let t=wT(e.group.id,!0);DT(e.group,t)}),e.preventDefault())}}function TE(e){let t=0,n=0,r={};for(let i of e)if(i.defaultSize!==void 0){t++;let e=uT(i.defaultSize);n+=e,r[i.panelId]=e}else r[i.panelId]=void 0;let i=e.length-t;if(i!==0){let t=uT((100-n)/i);for(let n of e)n.defaultSize===void 0&&(r[n.panelId]=t)}return r}function EE(e,t,n){if(!n[0])return;let r=e.panels.find(e=>e.element===t);if(!r||!r.onResize)return;let i=dT({group:e}),a=e.orientation===`horizontal`?r.element.offsetWidth:r.element.offsetHeight,o=r.mutableValues.prevSize,s={asPercentage:uT(a/i*100),inPixels:a};r.mutableValues.prevSize=s,r.onResize(s,r.id,o)}function DE(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(let n in e)if(e[n]!==t[n])return!1;return!0}function OE({group:e,nextGroupSize:t,prevGroupSize:n,prevLayout:r}){if(n<=0||t<=0||n===t)return r;let i=0,a=0,o=!1,s=new Map,c=[];for(let l of e.panels){let e=r[l.id]??0;switch(l.panelConstraints.groupResizeBehavior){case`preserve-pixel-size`:{o=!0;let r=uT(e/100*n/t*100);s.set(l.id,r),i+=r;break}default:c.push(l.id),a+=e;break}}if(!o||c.length===0)return r;let l=100-i,u={...r};if(s.forEach((e,t)=>{u[t]=e}),a>0)for(let e of c)u[e]=uT((r[e]??0)/a*l);else{let e=uT(l/c.length);for(let t of c)u[t]=e}return u}function kE(e,t){let n=e.map(e=>e.id),r=Object.keys(t);if(n.length!==r.length)return!1;for(let e of n)if(!r.includes(e))return!1;return!0}var AE=new Map;function jE(e){let t=!0;pT(e.element.ownerDocument.defaultView,`Cannot register an unmounted Group`);let n=e.element.ownerDocument.defaultView.ResizeObserver,r=new Set,i=new Set,a=new n(n=>{for(let r of n){let{borderBoxSize:n,target:i}=r;if(i===e.element){if(t){let t=dT({group:e});if(t===0)return;let n=wT(e.id);if(!n)return;let r=fT(e),i=n.defaultLayoutDeferred?TE(r):n.layout,a=qT({layout:OE({group:e,nextGroupSize:t,prevGroupSize:n.groupSize,prevLayout:i}),panelConstraints:r});if(!n.defaultLayoutDeferred&&KT(n.layout,a)&&DE(n.derivedPanelConstraints,r)&&n.groupSize===t)return;DT(e,{defaultLayoutDeferred:!1,derivedPanelConstraints:r,groupSize:t,layout:a,separatorToPanels:n.separatorToPanels})}}else EE(e,i,n)}});a.observe(e.element),e.panels.forEach(e=>{pT(!r.has(e.id),`Panel ids must be unique; id "${e.id}" was used more than once`),r.add(e.id),e.onResize&&a.observe(e.element)});let o=dT({group:e}),s=fT(e),c=e.panels.map(({id:e})=>e).join(`,`),l=e.mutableState.defaultLayout;l&&(kE(e.panels,l)||(l=void 0));let u=qT({layout:e.mutableState.layouts[c]??l??TE(s),panelConstraints:s}),d=e.element.ownerDocument;AE.set(d,(AE.get(d)??0)+1);let f=new Map;return vT(e).forEach(e=>{e.separator&&f.set(e.separator,e.panels)}),DT(e,{defaultLayoutDeferred:o===0,derivedPanelConstraints:s,groupSize:o,layout:u,separatorToPanels:f}),e.separators.forEach(e=>{pT(!i.has(e.id),`Separator ids must be unique; id "${e.id}" was used more than once`),i.add(e.id),e.element.addEventListener(`keydown`,$T)}),AE.get(d)===1&&(d.addEventListener(`dblclick`,YT,!0),d.addEventListener(`pointerdown`,oE,!0),d.addEventListener(`pointerleave`,xE),d.addEventListener(`pointermove`,SE),d.addEventListener(`pointerout`,CE),d.addEventListener(`pointerup`,wE,!0)),function(){t=!1,AE.set(d,Math.max(0,(AE.get(d)??0)-1)),ST(e),e.separators.forEach(e=>{e.element.removeEventListener(`keydown`,$T)}),AE.get(d)||(d.removeEventListener(`dblclick`,YT,!0),d.removeEventListener(`pointerdown`,oE,!0),d.removeEventListener(`pointerleave`,xE),d.removeEventListener(`pointermove`,SE),d.removeEventListener(`pointerout`,CE),d.removeEventListener(`pointerup`,wE,!0)),a.disconnect()}}function ME(){let[e,t]=(0,F.useState)({});return[e,(0,F.useCallback)(()=>t({}),[])]}function NE(e){let t=(0,F.useId)();return`${e??t}`}var PE=typeof window<`u`?F.useLayoutEffect:F.useEffect;function FE(e){let t=(0,F.useRef)(e);return PE(()=>{t.current=e},[e]),(0,F.useCallback)((...e)=>t.current?.(...e),[t])}function IE(...e){return FE(t=>{e.forEach(e=>{if(e)switch(typeof e){case`function`:e(t);break;case`object`:e.current=t;break}})})}function LE(e){let t=(0,F.useRef)({...e});return PE(()=>{for(let n in e)t.current[n]=e[n]},[e]),t.current}var RE=(0,F.createContext)(null);function zE(e,t){let n=(0,F.useRef)({getLayout:()=>({}),setLayout:sE});(0,F.useImperativeHandle)(t,()=>n.current,[]),PE(()=>{Object.assign(n.current,ZT({groupId:e}))})}function BE({children:e,className:t,defaultLayout:n,disableCursor:r,disabled:i,elementRef:a,groupRef:o,id:s,onLayoutChange:c,onLayoutChanged:l,orientation:u=`horizontal`,resizeTargetMinimumSize:d={coarse:20,fine:10},style:f,...p}){let m=(0,F.useRef)({onLayoutChange:{},onLayoutChanged:{}}),h=FE(e=>{KT(m.current.onLayoutChange,e)||(m.current.onLayoutChange=e,c?.(e))}),g=FE(e=>{KT(m.current.onLayoutChanged,e)||(m.current.onLayoutChanged=e,l?.(e))}),_=NE(s),v=(0,F.useRef)(null),[y,b]=ME(),x=(0,F.useRef)({lastExpandedPanelSizes:{},layouts:{},panels:[],resizeTargetMinimumSize:d,separators:[]}),S=IE(v,a);zE(_,o);let C=FE((e,t)=>{let r=nE(),i=CT(e),a=wT(e);if(a){let e=!1;switch(r.state){case`active`:e=r.hitRegions.some(e=>e.group===i);break}return{flexGrow:a.layout[t]??1,pointerEvents:e?`none`:void 0}}if(n?.[t])return{flexGrow:n?.[t]}}),w=LE({defaultLayout:n,disableCursor:r}),T=(0,F.useMemo)(()=>({get disableCursor(){return!!w.disableCursor},getPanelStyles:C,id:_,orientation:u,registerPanel:e=>{let t=x.current;return t.panels=mT(u,[...t.panels,e]),b(),()=>{t.panels=t.panels.filter(t=>t!==e),b()}},registerSeparator:e=>{let t=x.current;return t.separators=mT(u,[...t.separators,e]),b(),()=>{t.separators=t.separators.filter(t=>t!==e),b()}},updatePanelProps:(e,{disabled:t})=>{let n=x.current.panels.find(t=>t.id===e);n&&(n.panelConstraints.disabled=t);let r=CT(_),i=wT(_);r&&i&&DT(r,{...i,derivedPanelConstraints:fT(r)})},updateSeparatorProps:(e,{disabled:t,disableDoubleClick:n})=>{let r=x.current.separators.find(t=>t.id===e);r&&(r.disabled=t,r.disableDoubleClick=n)}}),[C,_,b,u,w]),E=(0,F.useRef)(null);return PE(()=>{let e=v.current;if(e===null)return;let t=x.current,n;if(w.defaultLayout!==void 0&&Object.keys(w.defaultLayout).length===t.panels.length){n={};for(let e of t.panels){let t=w.defaultLayout[e.id];t!==void 0&&(n[e.id]=t)}}let r={disabled:!!i,element:e,id:_,mutableState:{defaultLayout:n,disableCursor:!!w.disableCursor,expandedPanelSizes:x.current.lastExpandedPanelSizes,layouts:x.current.layouts},orientation:u,panels:t.panels,resizeTargetMinimumSize:t.resizeTargetMinimumSize,separators:t.separators};E.current=r;let a=jE(r),{defaultLayoutDeferred:o,derivedPanelConstraints:s,layout:c}=wT(r.id,!0);!o&&s.length>0&&(h(c),g(c));let l=ET(_,e=>{let{defaultLayoutDeferred:t,derivedPanelConstraints:n,layout:i}=e.next;if(t||n.length===0)return;let a=r.panels.map(({id:e})=>e).join(`,`);r.mutableState.layouts[a]=i,n.forEach(t=>{if(t.collapsible){let{layout:n}=e.prev??{};if(n){let e=HT(t.collapsedSize,i[t.panelId]),a=HT(t.collapsedSize,n[t.panelId]);e&&!a&&(r.mutableState.expandedPanelSizes[t.panelId]=n[t.panelId])}}});let o=nE().state!==`active`;h(i),o&&g(i)});return()=>{E.current=null,a(),l()}},[i,_,g,h,u,y,w]),(0,F.useEffect)(()=>{let e=E.current;e&&(e.mutableState.defaultLayout=n,e.mutableState.disableCursor=!!r)}),(0,L.jsx)(RE.Provider,{value:T,children:(0,L.jsx)(`div`,{...p,className:t,"data-group":!0,"data-testid":_,id:_,ref:S,style:{height:`100%`,width:`100%`,overflow:`hidden`,...f,display:`flex`,flexDirection:u===`horizontal`?`row`:`column`,flexWrap:`nowrap`,touchAction:u===`horizontal`?`pan-y`:`pan-x`},children:e})})}BE.displayName=`Group`;function VE(){let e=(0,F.useContext)(RE);return pT(e,`Group Context not found; did you render a Panel or Separator outside of a Group?`),e}function HE(e,t){let{id:n}=VE(),r=(0,F.useRef)({collapse:cE,expand:cE,getSize:()=>({asPercentage:0,inPixels:0}),isCollapsed:()=>!1,resize:cE});(0,F.useImperativeHandle)(t,()=>r.current,[]),PE(()=>{Object.assign(r.current,JT({groupId:n,panelId:e}))})}function UE({children:e,className:t,collapsedSize:n=`0%`,collapsible:r=!1,defaultSize:i,disabled:a,elementRef:o,groupResizeBehavior:s=`preserve-relative-size`,id:c,maxSize:l=`100%`,minSize:u=`0%`,onResize:d,panelRef:f,style:p,...m}){let h=!!c,g=NE(c),_=LE({disabled:a}),v=(0,F.useRef)(null),y=IE(v,o),{getPanelStyles:b,id:x,orientation:S,registerPanel:C,updatePanelProps:w}=VE(),T=d!==null,E=FE((e,t,n)=>{d?.(e,c,n)});PE(()=>{let e=v.current;if(e!==null)return C({element:e,id:g,idIsStable:h,mutableValues:{expandToSize:void 0,prevSize:void 0},onResize:T?E:void 0,panelConstraints:{groupResizeBehavior:s,collapsedSize:n,collapsible:r,defaultSize:i,disabled:_.disabled,maxSize:l,minSize:u}})},[s,n,r,i,T,g,h,l,u,E,C,_]),(0,F.useEffect)(()=>{w(g,{disabled:a})},[a,g,w]),HE(g,f);let D=()=>{let e=b(x,g);if(e)return JSON.stringify(e)},O=(0,F.useSyncExternalStore)(e=>ET(x,e),D,D),k;return k=O?JSON.parse(O):i===void 0?{flexGrow:1}:{flexGrow:void 0,flexShrink:void 0,flexBasis:i},(0,L.jsx)(`div`,{...m,"data-disabled":a||void 0,"data-panel":!0,"data-testid":g,id:g,ref:y,style:{...WE,display:`flex`,flexBasis:0,flexShrink:1,overflow:`visible`,...k},children:(0,L.jsx)(`div`,{className:t,style:{maxHeight:`100%`,maxWidth:`100%`,flexGrow:1,overflow:`auto`,...p,touchAction:S===`horizontal`?`pan-y`:`pan-x`},children:e})})}UE.displayName=`Panel`;var WE={minHeight:0,maxHeight:`100%`,height:`auto`,minWidth:0,maxWidth:`100%`,width:`auto`,border:`none`,borderWidth:0,padding:0,margin:0};function GE({layout:e,panelConstraints:t,panelId:n,panelIndex:r}){let i,a,o=e[n],s=t.find(e=>e.panelId===n);if(s){let c=s.maxSize,l=s.collapsible?s.collapsedSize:s.minSize,u=[r,r+1];a=qT({layout:GT({delta:l-o,initialLayout:e,panelConstraints:t,pivotIndices:u,prevLayout:e}),panelConstraints:t})[n],i=qT({layout:GT({delta:c-o,initialLayout:e,panelConstraints:t,pivotIndices:u,prevLayout:e}),panelConstraints:t})[n]}return{valueControls:n,valueMax:i,valueMin:a,valueNow:o}}function KE({children:e,className:t,disabled:n,disableDoubleClick:r,elementRef:i,id:a,style:o,...s}){let c=NE(a),l=LE({disabled:n,disableDoubleClick:r}),[u,d]=(0,F.useState)({}),[f,p]=(0,F.useState)(`inactive`),[m,h]=(0,F.useState)(!1),g=(0,F.useRef)(null),_=IE(g,i),{disableCursor:v,id:y,orientation:b,registerSeparator:x,updateSeparatorProps:S}=VE(),C=b===`horizontal`?`vertical`:`horizontal`;PE(()=>{let e=g.current;if(e!==null){let t={disabled:l.disabled,disableDoubleClick:l.disableDoubleClick,element:e,id:c},n=x(t),r=rE(e=>{p(e.next.state!==`inactive`&&e.next.hitRegions.some(e=>e.separator===t)?e.next.state:`inactive`)}),i=ET(y,e=>{let{derivedPanelConstraints:n,layout:r,separatorToPanels:i}=e.next,a=i.get(t);if(a){let e=a[0],t=a.indexOf(e);d(GE({layout:r,panelConstraints:n,panelId:e.id,panelIndex:t}))}});return()=>{r(),i(),n()}}},[y,c,x,l]),(0,F.useEffect)(()=>{S(c,{disabled:n,disableDoubleClick:r})},[n,r,c,S]);let w;n&&!v&&(w=`not-allowed`);let T;if(n)T=`disabled`;else switch(f){case`active`:T=`active`;break;default:T=m?`focus`:f}return(0,L.jsx)(`div`,{...s,"aria-controls":u.valueControls,"aria-disabled":n||void 0,"aria-orientation":C,"aria-valuemax":u.valueMax,"aria-valuemin":u.valueMin,"aria-valuenow":u.valueNow,children:e,className:t,"data-separator":T,"data-testid":c,id:c,onBlur:()=>h(!1),onFocus:()=>h(!0),ref:_,role:`separator`,style:{flexBasis:`auto`,cursor:w,...o,flexGrow:0,flexShrink:0,touchAction:`none`},tabIndex:n?void 0:0})}KE.displayName=`Separator`;var qE=class e extends Error{constructor(t,n){var r=`KaTeX parse error: `+t,i,a,o=n&&n.loc;if(o&&o.start<=o.end){var s=o.lexer.input;i=o.start,a=o.end,i===s.length?r+=` at end of input: `:r+=` at position `+(i+1)+`: `;var c=s.slice(i,a).replace(/[^]/g,`$&̲`),l=i>15?`…`+s.slice(i-15,i):s.slice(0,i),u=a+15<s.length?s.slice(a,a+15)+`…`:s.slice(a);r+=l+c+u}super(r),this.name=`ParseError`,this.position=void 0,this.length=void 0,this.rawMessage=void 0,Object.setPrototypeOf(this,e.prototype),this.position=i,i!=null&&a!=null&&(this.length=a-i),this.rawMessage=t}},JE=/([A-Z])/g,YE=e=>e.replace(JE,`-$1`).toLowerCase(),XE={"&":`&amp;`,">":`&gt;`,"<":`&lt;`,'"':`&quot;`,"'":`&#x27;`},ZE=/[&><"']/g,QE=e=>String(e).replace(ZE,e=>XE[e]),$E=e=>e.type===`ordgroup`||e.type===`color`?e.body.length===1?$E(e.body[0]):e:e.type===`font`?$E(e.body):e,eD=new Set([`mathord`,`textord`,`atom`]),tD=e=>eD.has($E(e).type),nD=e=>{var t=/^[\x00-\x20]*([^\\/#?]*?)(:|&#0*58|&#x0*3a|&colon)/i.exec(e);return t?t[2]!==`:`||!/^[a-zA-Z][a-zA-Z0-9+\-.]*$/.test(t[1])?null:t[1].toLowerCase():`_relative`},rD={displayMode:{type:`boolean`,description:`Render math in display mode, which puts the math in display style (so \\int and \\sum are large, for example), and centers the math on the page on its own line.`,cli:`-d, --display-mode`},output:{type:{enum:[`htmlAndMathml`,`html`,`mathml`]},description:`Determines the markup language of the output.`,cli:`-F, --format <type>`},leqno:{type:`boolean`,description:`Render display math in leqno style (left-justified tags).`},fleqn:{type:`boolean`,description:`Render display math flush left.`},throwOnError:{type:`boolean`,default:!0,cli:`-t, --no-throw-on-error`,cliDescription:`Render errors (in the color given by --error-color) instead of throwing a ParseError exception when encountering an error.`},errorColor:{type:`string`,default:`#cc0000`,cli:`-c, --error-color <color>`,cliDescription:`A color string given in the format 'rgb' or 'rrggbb' (no #). This option determines the color of errors rendered by the -t option.`,cliProcessor:e=>`#`+e},macros:{type:`object`,cli:`-m, --macro <def>`,cliDescription:`Define custom macro of the form '\\foo:expansion' (use multiple -m arguments for multiple macros).`,cliDefault:[],cliProcessor:(e,t)=>(t.push(e),t)},minRuleThickness:{type:`number`,description:"Specifies a minimum thickness, in ems, for fraction lines, `\\sqrt` top lines, `{array}` vertical lines, `\\hline`, `\\hdashline`, `\\underline`, `\\overline`, and the borders of `\\fbox`, `\\boxed`, and `\\fcolorbox`.",processor:e=>Math.max(0,e),cli:`--min-rule-thickness <size>`,cliProcessor:parseFloat},colorIsTextColor:{type:`boolean`,description:`Makes \\color behave like LaTeX's 2-argument \\textcolor, instead of LaTeX's one-argument \\color mode change.`,cli:`-b, --color-is-text-color`},strict:{type:[{enum:[`warn`,`ignore`,`error`]},`boolean`,`function`],description:`Turn on strict / LaTeX faithfulness mode, which throws an error if the input uses features that are not supported by LaTeX.`,cli:`-S, --strict`,cliDefault:!1},trust:{type:[`boolean`,`function`],description:`Trust the input, enabling all HTML features such as \\url.`,cli:`-T, --trust`},maxSize:{type:`number`,default:1/0,description:`If non-zero, all user-specified sizes, e.g. in \\rule{500em}{500em}, will be capped to maxSize ems. Otherwise, elements and spaces can be arbitrarily large`,processor:e=>Math.max(0,e),cli:`-s, --max-size <n>`,cliProcessor:parseInt},maxExpand:{type:`number`,default:1e3,description:`Limit the number of macro expansions to the specified number, to prevent e.g. infinite macro loops. If set to Infinity, the macro expander will try to fully expand as in LaTeX.`,processor:e=>Math.max(0,e),cli:`-e, --max-expand <n>`,cliProcessor:e=>e===`Infinity`?1/0:parseInt(e)},globalGroup:{type:`boolean`,cli:!1}};function ane(e){if(typeof e!=`string`)return e.enum[0];switch(e){case`boolean`:return!1;case`string`:return``;case`number`:return 0;case`object`:return{};default:throw Error(`Unexpected schema type; settings must declare an explicit default.`)}}function one(e){return e.default===void 0?ane(Array.isArray(e.type)?e.type[0]:e.type):e.default}function sne(e,t,n,r){var i=n[t];e[t]=i===void 0?one(r):r.processor?r.processor(i):i}var iD=class{constructor(e){e===void 0&&(e={}),this.displayMode=void 0,this.output=void 0,this.leqno=void 0,this.fleqn=void 0,this.throwOnError=void 0,this.errorColor=void 0,this.macros=void 0,this.minRuleThickness=void 0,this.colorIsTextColor=void 0,this.strict=void 0,this.trust=void 0,this.maxSize=void 0,this.maxExpand=void 0,this.globalGroup=void 0,e||={};for(var t of Object.keys(rD)){var n=rD[t];n&&sne(this,t,e,n)}}reportNonstrict(e,t,n){var r=this.strict;if(typeof r==`function`&&(r=r(e,t,n)),!(!r||r===`ignore`)){if(r===!0||r===`error`)throw new qE(`LaTeX-incompatible input and strict mode is set to 'error': `+(t+` [`+e+`]`),n);r===`warn`?typeof console<`u`&&console.warn(`LaTeX-incompatible input and strict mode is set to 'warn': `+(t+` [`+e+`]`)):typeof console<`u`&&console.warn(`LaTeX-incompatible input and strict mode is set to `+(`unrecognized '`+r+`': `+t+` [`+e+`]`))}}useStrictBehavior(e,t,n){var r=this.strict;if(typeof r==`function`)try{r=r(e,t,n)}catch{r=`error`}return!r||r===`ignore`?!1:r===!0||r===`error`?!0:r===`warn`?(typeof console<`u`&&console.warn(`LaTeX-incompatible input and strict mode is set to 'warn': `+(t+` [`+e+`]`)),!1):(typeof console<`u`&&console.warn(`LaTeX-incompatible input and strict mode is set to `+(`unrecognized '`+r+`': `+t+` [`+e+`]`)),!1)}isTrusted(e){if(`url`in e&&e.url&&!e.protocol){var t=nD(e.url);if(t==null)return!1;e.protocol=t}return!!(typeof this.trust==`function`?this.trust(e):this.trust)}},aD=class{constructor(e,t,n){this.id=void 0,this.size=void 0,this.cramped=void 0,this.id=e,this.size=t,this.cramped=n}sup(){return mD[cne[this.id]]}sub(){return mD[lne[this.id]]}fracNum(){return mD[une[this.id]]}fracDen(){return mD[hD[this.id]]}cramp(){return mD[gD[this.id]]}text(){return mD[_D[this.id]]}isTight(){return this.size>=2}},oD=0,sD=1,cD=2,lD=3,uD=4,dD=5,fD=6,pD=7,mD=[new aD(oD,0,!1),new aD(sD,0,!0),new aD(cD,1,!1),new aD(lD,1,!0),new aD(uD,2,!1),new aD(dD,2,!0),new aD(fD,3,!1),new aD(pD,3,!0)],cne=[uD,dD,uD,dD,fD,pD,fD,pD],lne=[dD,dD,dD,dD,pD,pD,pD,pD],une=[cD,lD,uD,dD,fD,pD,fD,pD],hD=[lD,lD,dD,dD,pD,pD,pD,pD],gD=[sD,sD,lD,lD,dD,dD,pD,pD],_D=[oD,sD,cD,lD,cD,lD,cD,lD],vD={DISPLAY:mD[oD],TEXT:mD[cD],SCRIPT:mD[uD],SCRIPTSCRIPT:mD[fD]},yD=[{name:`latin`,blocks:[[256,591],[768,879]]},{name:`cyrillic`,blocks:[[1024,1279]]},{name:`armenian`,blocks:[[1328,1423]]},{name:`brahmic`,blocks:[[2304,4255]]},{name:`georgian`,blocks:[[4256,4351]]},{name:`cjk`,blocks:[[12288,12543],[19968,40879],[65280,65376]]},{name:`hangul`,blocks:[[44032,55215]]}];function bD(e){for(var t=0;t<yD.length;t++)for(var n=yD[t],r=0;r<n.blocks.length;r++){var i=n.blocks[r];if(e>=i[0]&&e<=i[1])return n.name}return null}var xD=[];yD.forEach(e=>e.blocks.forEach(e=>xD.push(...e)));function SD(e){for(var t=0;t<xD.length;t+=2)if(e>=xD[t]&&e<=xD[t+1])return!0;return!1}var CD=e=>e+` `+e,wD=80,TD=function(e,t){return`M95,`+(622+e+t)+`
59
59
  c-2.7,0,-7.17,-2.7,-13.5,-8c-5.8,-5.3,-9.5,-10,-9.5,-14
@@ -364,8 +364,8 @@ l0,-`+(t+144)+`c-2,-159.3,-10,-310.7,-24,-454c-53.3,-528,-210,-949.7,
364
364
  `+e.slice(i,a),i=a+1),o=s;return c+=`
365
365
  `,e.length-i>t&&o>i?c+=e.slice(i,o)+`
366
366
  `+e.slice(o+1):c+=e.slice(i),c.slice(1)}P(CK,`foldLine`);function wK(e){for(var t=``,n=0,r,i=0;i<e.length;n>=65536?i+=2:i++)n=dK(e,i),r=JG[n],!r&&oK(n)?(t+=e[i],n>=65536&&(t+=e[i+1])):t+=r||QG(n);return t}P(wK,`escapeString`);function TK(e,t,n){var r=``,i=e.tag,a,o,s;for(a=0,o=n.length;a<o;a+=1)s=n[a],e.replacer&&(s=e.replacer.call(n,String(a),s)),(AK(e,t,s,!1,!1)||s===void 0&&AK(e,t,null,!1,!1))&&(r!==``&&(r+=`,`+(e.condenseFlow?``:` `)),r+=e.dump);e.tag=i,e.dump=`[`+r+`]`}P(TK,`writeFlowSequence`);function EK(e,t,n,r){var i=``,a=e.tag,o,s,c;for(o=0,s=n.length;o<s;o+=1)c=n[o],e.replacer&&(c=e.replacer.call(n,String(o),c)),(AK(e,t+1,c,!0,!0,!1,!0)||c===void 0&&AK(e,t+1,null,!0,!0,!1,!0))&&((!r||i!==``)&&(i+=rK(e,t)),e.dump&&TG===e.dump.charCodeAt(0)?i+=`-`:i+=`- `,i+=e.dump);e.tag=a,e.dump=i||`[]`}P(EK,`writeBlockSequence`);function DK(e,t,n){var r=``,i=e.tag,a=Object.keys(n),o,s,c,l,u;for(o=0,s=a.length;o<s;o+=1)u=``,r!==``&&(u+=`, `),e.condenseFlow&&(u+=`"`),c=a[o],l=n[c],e.replacer&&(l=e.replacer.call(n,c,l)),AK(e,t,c,!1,!1)&&(e.dump.length>1024&&(u+=`? `),u+=e.dump+(e.condenseFlow?`"`:``)+`:`+(e.condenseFlow?``:` `),AK(e,t,l,!1,!1)&&(u+=e.dump,r+=u));e.tag=i,e.dump=`{`+r+`}`}P(DK,`writeFlowMapping`);function OK(e,t,n,r){var i=``,a=e.tag,o=Object.keys(n),s,c,l,u,d,f;if(e.sortKeys===!0)o.sort();else if(typeof e.sortKeys==`function`)o.sort(e.sortKeys);else if(e.sortKeys)throw new cU(`sortKeys must be a boolean or a function`);for(s=0,c=o.length;s<c;s+=1)f=``,(!r||i!==``)&&(f+=rK(e,t)),l=o[s],u=n[l],e.replacer&&(u=e.replacer.call(n,l,u)),AK(e,t+1,l,!0,!0,!0)&&(d=e.tag!==null&&e.tag!==`?`||e.dump&&e.dump.length>1024,d&&(e.dump&&TG===e.dump.charCodeAt(0)?f+=`?`:f+=`? `),f+=e.dump,d&&(f+=rK(e,t)),AK(e,t+1,u,!0,d)&&(e.dump&&TG===e.dump.charCodeAt(0)?f+=`:`:f+=`: `,f+=e.dump,i+=f));e.tag=a,e.dump=i||`{}`}P(OK,`writeBlockMapping`);function kK(e,t,n){var r,i=n?e.explicitTypes:e.implicitTypes,a,o,s,c;for(a=0,o=i.length;a<o;a+=1)if(s=i[a],(s.instanceOf||s.predicate)&&(!s.instanceOf||typeof t==`object`&&t instanceof s.instanceOf)&&(!s.predicate||s.predicate(t))){if(n?s.multi&&s.representName?e.tag=s.representName(t):e.tag=s.tag:e.tag=`?`,s.represent){if(c=e.styleMap[s.tag]||s.defaultStyle,xG.call(s.represent)===`[object Function]`)r=s.represent(t,c);else if(SG.call(s.represent,c))r=s.represent[c](t,c);else throw new cU(`!<`+s.tag+`> tag resolver accepts not "`+c+`" style`);e.dump=r}return!0}return!1}P(kK,`detectType`);function AK(e,t,n,r,i,a,o){e.tag=null,e.dump=n,kK(e,n,!1)||kK(e,n,!0);var s=xG.call(e.dump),c=r,l;r&&=e.flowLevel<0||e.flowLevel>t;var u=s===`[object Object]`||s===`[object Array]`,d,f;if(u&&(d=e.duplicates.indexOf(n),f=d!==-1),(e.tag!==null&&e.tag!==`?`||f||e.indent!==2&&t>0)&&(i=!1),f&&e.usedDuplicates[d])e.dump=`*ref_`+d;else{if(u&&f&&!e.usedDuplicates[d]&&(e.usedDuplicates[d]=!0),s===`[object Object]`)r&&Object.keys(e.dump).length!==0?(OK(e,t,e.dump,i),f&&(e.dump=`&ref_`+d+e.dump)):(DK(e,t,e.dump),f&&(e.dump=`&ref_`+d+` `+e.dump));else if(s===`[object Array]`)r&&e.dump.length!==0?(e.noArrayIndent&&!o&&t>0?EK(e,t-1,e.dump,i):EK(e,t,e.dump,i),f&&(e.dump=`&ref_`+d+e.dump)):(TK(e,t,e.dump),f&&(e.dump=`&ref_`+d+` `+e.dump));else if(s===`[object String]`)e.tag!==`?`&&yK(e,e.dump,t,a,c);else if(s===`[object Undefined]`)return!1;else{if(e.skipInvalid)return!1;throw new cU(`unacceptable kind of an object to dump `+s)}e.tag!==null&&e.tag!==`?`&&(l=encodeURI(e.tag[0]===`!`?e.tag.slice(1):e.tag).replace(/!/g,`%21`),l=e.tag[0]===`!`?`!`+l:l.slice(0,18)===`tag:yaml.org,2002:`?`!!`+l.slice(18):`!<`+l+`>`,e.dump=l+` `+e.dump)}return!0}P(AK,`writeNode`);function jK(e,t){var n=[],r=[],i,a;for(MK(e,n,r),i=0,a=r.length;i<a;i+=1)t.duplicates.push(n[r[i]]);t.usedDuplicates=Array(a)}P(jK,`getDuplicateReferences`);function MK(e,t,n){var r,i,a;if(typeof e==`object`&&e)if(i=t.indexOf(e),i!==-1)n.indexOf(i)===-1&&n.push(i);else if(t.push(e),Array.isArray(e))for(i=0,a=e.length;i<a;i+=1)MK(e[i],t,n);else for(r=Object.keys(e),i=0,a=r.length;i<a;i+=1)MK(e[r[i]],t,n)}P(MK,`inspectNode`);function NK(e,t){t||={};var n=new tK(t);n.noRefs||jK(e,n);var r=e;return n.replacer&&(r=n.replacer.call({"":r},``,r)),AK(n,0,r,!0,!0)?n.dump+`
367
- `:``}P(NK,`dump$1`);var PK={dump:NK};function FK(e,t){return function(){throw Error(`Function yaml.`+e+` is removed in js-yaml 4. Use yaml.`+t+` instead, which is now safe by default.`)}}P(FK,`renamed`);var IK=WU,LK=bG.load;bG.loadAll,PK.dump;function RK(e){let t=e?.constructor;return e===(typeof t==`function`?t.prototype:Object.prototype)}function zK(e){if(e==null)return!0;if(Ae(e))return typeof e.splice!=`function`&&typeof e!=`string`&&!xe(e)&&!ke(e)&&!je(e)?!1:e.length===0;if(typeof e==`object`){if(e instanceof Map||e instanceof Set)return e.size===0;let t=Object.keys(e);return RK(e)?t.filter(e=>e!==`constructor`).length===0:t.length===0}return!0}var BK={common:k,getConfig:y,insertCluster:Fe,insertEdge:ze,insertEdgeLabel:Be,insertMarkers:Re,insertNode:Pe,interpolateToCurve:Ce,labelHelper:Ie,log:ye,positionEdgeLabel:Le},VK={},HK=P(e=>{for(let t of e)VK[t.name]=t},`registerLayoutLoaders`);P(()=>{HK([{name:`dagre`,loader:P(async()=>await A(()=>import(`./dagre-BM42HDAG-CZ5AtThh.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19])),`loader`)},{name:`cose-bilkent`,loader:P(async()=>await A(()=>import(`./cose-bilkent-S5V4N54A-CWucooZw.js`),__vite__mapDeps([20,3,21,2])),`loader`)}])},`registerDefaultLayoutLoaders`)();var UK=P(async(e,t)=>{if(!(e.layoutAlgorithm in VK))throw Error(`Unknown layout algorithm: ${e.layoutAlgorithm}`);if(e.diagramId)for(let t of e.nodes){let n=t.domId||t.id;t.domId=`${e.diagramId}-${n}`}let n=VK[e.layoutAlgorithm],r=await n.loader(),{theme:i,themeVariables:a}=e.config,{useGradient:o,gradientStart:s,gradientStop:c}=a,l=t.attr(`id`);if(t.append(`defs`).append(`filter`).attr(`id`,`${l}-drop-shadow`).attr(`height`,`130%`).attr(`width`,`130%`).append(`feDropShadow`).attr(`dx`,`4`).attr(`dy`,`4`).attr(`stdDeviation`,0).attr(`flood-opacity`,`0.06`).attr(`flood-color`,`${i?.includes(`dark`)?`#FFFFFF`:`#000000`}`),t.append(`defs`).append(`filter`).attr(`id`,`${l}-drop-shadow-small`).attr(`height`,`150%`).attr(`width`,`150%`).append(`feDropShadow`).attr(`dx`,`2`).attr(`dy`,`2`).attr(`stdDeviation`,0).attr(`flood-opacity`,`0.06`).attr(`flood-color`,`${i?.includes(`dark`)?`#FFFFFF`:`#000000`}`),o){let e=t.append(`linearGradient`).attr(`id`,t.attr(`id`)+`-gradient`).attr(`gradientUnits`,`objectBoundingBox`).attr(`x1`,`0%`).attr(`y1`,`0%`).attr(`x2`,`100%`).attr(`y2`,`0%`);e.append(`svg:stop`).attr(`offset`,`0%`).attr(`stop-color`,s).attr(`stop-opacity`,1),e.append(`svg:stop`).attr(`offset`,`100%`).attr(`stop-color`,c).attr(`stop-opacity`,1)}return r.render(e,t,BK,{algorithm:n.algorithm})},`render`),WK=P((e=``,{fallback:t=`dagre`}={})=>{if(e in VK)return e;if(t in VK)return ye.warn(`Layout algorithm ${e} is not registered. Using ${t} as fallback.`),t;throw Error(`Both layout algorithms ${e} and ${t} are not registered.`)},`getRegisteredLayoutAlgorithm`),GK=`comm`,KK=`rule`,qK=`decl`,JK=`@import`,YK=`@namespace`,XK=`@keyframes`,ZK=`@layer`,QK=Math.abs,$K=String.fromCharCode;function eq(e){return e.trim()}function tq(e,t,n){return e.replace(t,n)}function nq(e,t){return e.charCodeAt(t)|0}function rq(e,t,n){return e.slice(t,n)}function iq(e){return e.length}function aq(e){return e.length}function oq(e,t){return t.push(e),e}var sq=1,cq=1,lq=0,uq=0,dq=0,fq=``;function pq(e,t,n,r,i,a,o,s){return{value:e,root:t,parent:n,type:r,props:i,children:a,line:sq,column:cq,length:o,return:``,siblings:s}}function mq(){return dq}function hq(){return dq=uq>0?nq(fq,--uq):0,cq--,dq===10&&(cq=1,sq--),dq}function gq(){return dq=uq<lq?nq(fq,uq++):0,cq++,dq===10&&(cq=1,sq++),dq}function _q(){return nq(fq,uq)}function vq(){return uq}function yq(e,t){return rq(fq,e,t)}function bq(e){switch(e){case 0:case 9:case 10:case 13:case 32:return 5;case 33:case 43:case 44:case 47:case 62:case 64:case 126:case 59:case 123:case 125:return 4;case 58:return 3;case 34:case 39:case 40:case 91:return 2;case 41:case 93:return 1}return 0}function xq(e){return sq=cq=1,lq=iq(fq=e),uq=0,[]}function Sq(e){return fq=``,e}function Cq(e){return eq(yq(uq-1,Eq(e===91?e+2:e===40?e+1:e)))}function wq(e){for(;(dq=_q())&&dq<33;)gq();return bq(e)>2||bq(dq)>3?``:` `}function Tq(e,t){for(;--t&&gq()&&!(dq<48||dq>102||dq>57&&dq<65||dq>70&&dq<97););return yq(e,vq()+(t<6&&_q()==32&&gq()==32))}function Eq(e){for(;gq();)switch(dq){case e:return uq;case 34:case 39:e!==34&&e!==39&&Eq(dq);break;case 40:e===41&&Eq(e);break;case 92:gq();break}return uq}function Dq(e,t){for(;gq()&&e+dq!==57&&!(e+dq===84&&_q()===47););return`/*`+yq(t,uq-1)+`*`+$K(e===47?e:gq())}function Oq(e){for(;!bq(_q());)gq();return yq(e,uq)}function kq(e){return Sq(Aq(``,null,null,null,[``],e=xq(e),0,[0],e))}function Aq(e,t,n,r,i,a,o,s,c){for(var l=0,u=0,d=o,f=0,p=0,m=0,h=1,g=1,_=1,v=0,y=0,b=``,x=i,S=a,C=r,w=b;g;)switch(m=y,y=gq()){case 40:m!=108&&nq(w,d-1)==58?(v++,w+=`(`):w+=Cq(y);break;case 41:v--,w+=`)`;break;case 34:case 39:case 91:w+=Cq(y);break;case 9:case 10:case 13:case 32:if(v>0){w+=$K(y);break}w+=wq(m);break;case 92:w+=Tq(vq()-1,7);continue;case 47:switch(_q()){case 42:case 47:oq(Mq(Dq(gq(),vq()),t,n,c),c),(bq(m||1)==5||bq(_q()||1)==5)&&iq(w)&&rq(w,-1,void 0)!==` `&&(w+=` `);break;default:w+=`/`}break;case 123*h:s[l++]=iq(w)*_;case 125*h:case 59:case 0:if(v>0&&y){w+=$K(y);break}switch(y){case 0:case 125:g=0;case 59+u:_==-1&&(w=tq(w,/\f/g,``)),p>0&&(iq(w)-d||h===0)&&oq(p>32?Nq(w+`;`,r,n,d-1,c):Nq(tq(w,` `,``)+`;`,r,n,d-2,c),c);break;case 59:w+=`;`;default:if(oq(C=jq(w,t,n,l,u,i,s,b,x=[],S=[],d,a),a),y===123)if(u===0)Aq(w,t,C,C,x,a,d,s,S);else{switch(f){case 99:if(nq(w,3)===110)break;case 108:if(nq(w,2)===97)break;default:u=0;case 100:case 109:case 115:}u?Aq(e,C,C,r&&oq(jq(e,C,C,0,0,i,s,b,i,x=[],d,S),S),i,S,d,s,r?x:S):Aq(w,C,C,C,[``],S,0,s,S)}}l=u=p=0,h=_=1,b=w=``,d=o;break;case 58:d=1+iq(w),p=m;default:if(h<1){if(y==123)--h;else if(y==125&&h++==0&&hq()==125)continue}switch(w+=$K(y),y*h){case 38:_=u>0?1:(w+=`\f`,-1);break;case 44:if(v>0)break;s[l++]=(iq(w)-1)*_,_=1;break;case 64:_q()===45&&(w+=Cq(gq())),f=_q(),u=d=iq(b=w+=Oq(vq())),y++;break;case 45:m===45&&iq(w)==2&&(h=0)}}return a}function jq(e,t,n,r,i,a,o,s,c,l,u,d){for(var f=i-1,p=i===0?a:[``],m=aq(p),h=0,g=0,_=0;h<r;++h)for(var v=0,y=rq(e,f+1,f=QK(g=o[h])),b=e;v<m;++v)(b=eq(g>0?p[v]+` `+y:tq(y,/&\f/g,p[v])))&&(c[_++]=b);return pq(e,t,n,i===0?KK:s,c,l,u,d)}function Mq(e,t,n,r){return pq(e,t,n,GK,$K(mq()),rq(e,2,-2),0,r)}function Nq(e,t,n,r,i){return pq(e,t,n,qK,rq(e,0,r),rq(e,r+1,-1),r,i)}function Pq(e,t){for(var n=``,r=0;r<e.length;r++)n+=t(e[r],r,e,t)||``;return n}function Fq(e,t,n,r){switch(e.type){case ZK:if(e.children.length)break;case JK:case YK:case qK:return e.return=e.return||e.value;case GK:return``;case XK:return e.return=e.value+`{`+Pq(e.children,r)+`}`;case KK:if(!iq(e.value=e.props.join(`,`)))return``}return iq(n=Pq(e.children,r))?e.return=e.value+`{`+n+`}`:``}function Iq(e){var t=aq(e);return function(n,r,i,a){for(var o=``,s=0;s<t;s++)o+=e[s](n,r,i,a)||``;return o}}var Lq=`c4`,Rq={id:Lq,detector:P(e=>/^\s*C4Context|C4Container|C4Component|C4Dynamic|C4Deployment/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./c4Diagram-AAUBKEIU-CzsNYAS-.js`);return{diagram:e}},__vite__mapDeps([22,1,2,3,6,5,23]));return{id:Lq,diagram:e}},`loader`)},zq=`flowchart`,Bq={id:zq,detector:P((e,t)=>t?.flowchart?.defaultRenderer===`dagre-wrapper`||t?.flowchart?.defaultRenderer===`elk`?!1:/^\s*graph/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./flowDiagram-I6XJVG4X-BXTQ7QRg.js`);return{diagram:e}},__vite__mapDeps([24,1,2,3,4,5,6,25,26,11,12,13,14,27,15,28,16,17,18,19,23]));return{id:zq,diagram:e}},`loader`)},Vq=`flowchart-v2`,Hq={id:Vq,detector:P((e,t)=>t?.flowchart?.defaultRenderer===`dagre-d3`?!1:(t?.flowchart?.defaultRenderer===`elk`&&(t.layout=`elk`),/^\s*graph/.test(e)&&t?.flowchart?.defaultRenderer===`dagre-wrapper`?!0:/^\s*flowchart/.test(e)),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./flowDiagram-I6XJVG4X-BXTQ7QRg.js`);return{diagram:e}},__vite__mapDeps([24,1,2,3,4,5,6,25,26,11,12,13,14,27,15,28,16,17,18,19,23]));return{id:Vq,diagram:e}},`loader`)},Uq=`er`,Wq={id:Uq,detector:P(e=>/^\s*erDiagram/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./erDiagram-TEJ5UH35-CYNgf9or.js`);return{diagram:e}},__vite__mapDeps([29,1,2,3,4,5,6,25,26,11,12,13,14,27,15,16,17,18,19]));return{id:Uq,diagram:e}},`loader`)},Gq=`gitGraph`,Kq={id:Gq,detector:P(e=>/^\s*gitGraph/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./gitGraphDiagram-PVQCEYII-D8BksuAg.js`);return{diagram:e}},__vite__mapDeps([30,1,2,3,31,32,33,34,35,36,37,38,39,40,41,42,5,6,43,44]));return{id:Gq,diagram:e}},`loader`)},qq=`gantt`,Jq={id:qq,detector:P(e=>/^\s*gantt/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./ganttDiagram-6RSMTGT7-9CPIXrRu.js`);return{diagram:e}},__vite__mapDeps([45,3,1,2,6,46,47,48,5]));return{id:qq,diagram:e}},`loader`)},Yq=`info`,Xq={id:Yq,detector:P(e=>/^\s*info/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./infoDiagram-5YYISTIA-Be0OcURm.js`);return{diagram:e}},__vite__mapDeps([49,1,2,3,31,32,33,34,35,36,37,38,39,40,41,42]));return{id:Yq,diagram:e}},`loader`)},Zq=`pie`,Qq={id:Zq,detector:P(e=>/^\s*pie/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./pieDiagram-4H26LBE5-BP9tC1HT.js`);return{diagram:e}},__vite__mapDeps([50,1,2,3,6,31,32,33,34,35,36,37,38,39,40,41,42,18,51,48,52,19,5,43]));return{id:Zq,diagram:e}},`loader`)},$q=`quadrantChart`,eJ={id:$q,detector:P(e=>/^\s*quadrantChart/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./quadrantDiagram-W4KKPZXB-BBjjuCms.js`);return{diagram:e}},__vite__mapDeps([53,1,2,3,46,47,48]));return{id:$q,diagram:e}},`loader`)},tJ=`xychart`,nJ={id:tJ,detector:P(e=>/^\s*xychart(-beta)?/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./xychartDiagram-2RQKCTM6-B_1m_ITe.js`);return{diagram:e}},__vite__mapDeps([54,1,2,3,4,5,6,46,47,48,51,17,18,19]));return{id:tJ,diagram:e}},`loader`)},rJ=`requirement`,iJ={id:rJ,detector:P(e=>/^\s*requirement(Diagram)?/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./requirementDiagram-4Y6WPE33-B_O_cEpd.js`);return{diagram:e}},__vite__mapDeps([55,1,2,3,4,5,6,26,11,12,13,14,27,15,16,17,18,19]));return{id:rJ,diagram:e}},`loader`)},aJ=`sequence`,oJ={id:aJ,detector:P(e=>/^\s*sequenceDiagram/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./sequenceDiagram-3UESZ5HK-DBBZS2WD.js`);return{diagram:e}},__vite__mapDeps([56,1,2,3,6,5,23,44]));return{id:aJ,diagram:e}},`loader`)},sJ=`class`,cJ={id:sJ,detector:P((e,t)=>t?.class?.defaultRenderer===`dagre-wrapper`?!1:/^\s*classDiagram/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./classDiagram-4FO5ZUOK-DGIJJBY5.js`);return{diagram:e}},__vite__mapDeps([57,1,2,3,4,5,6,26,11,12,13,14,27,58,28,23,15,16,17,18,19]));return{id:sJ,diagram:e}},`loader`)},lJ=`classDiagram`,uJ={id:lJ,detector:P((e,t)=>/^\s*classDiagram/.test(e)&&t?.class?.defaultRenderer===`dagre-wrapper`?!0:/^\s*classDiagram-v2/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./classDiagram-v2-Q7XG4LA2-BdsZBmZ_.js`);return{diagram:e}},__vite__mapDeps([59,1,2,3,4,5,6,26,11,12,13,14,27,58,28,23,15,16,17,18,19]));return{id:lJ,diagram:e}},`loader`)},dJ=`state`,fJ={id:dJ,detector:P((e,t)=>t?.state?.defaultRenderer===`dagre-wrapper`?!1:/^\s*stateDiagram/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./stateDiagram-AJRCARHV-BaH2s_og.js`);return{diagram:e}},__vite__mapDeps([60,1,2,3,4,5,6,17,18,19,7,8,9,10,26,11,12,13,14,27,61,15,16]));return{id:dJ,diagram:e}},`loader`)},pJ=`stateDiagram`,mJ={id:pJ,detector:P((e,t)=>!!(/^\s*stateDiagram-v2/.test(e)||/^\s*stateDiagram/.test(e)&&t?.state?.defaultRenderer===`dagre-wrapper`),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./stateDiagram-v2-BHNVJYJU-Ryor5k_i.js`);return{diagram:e}},__vite__mapDeps([62,1,2,3,4,5,6,26,11,12,13,14,27,61,15,16,17,18,19]));return{id:pJ,diagram:e}},`loader`)},hJ=`journey`,gJ={id:hJ,detector:P(e=>/^\s*journey/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./journeyDiagram-JHISSGLW-DR1RevaB.js`);return{diagram:e}},__vite__mapDeps([63,1,2,3,52,6,18,28,23]));return{id:hJ,diagram:e}},`loader`)},_J={draw:P((e,t,n)=>{ye.debug(`rendering svg for syntax error
368
- `);let r=QH(t),i=r.append(`g`);r.attr(`viewBox`,`0 0 2412 512`),b(r,100,512,!0),i.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`),i.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`),i.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`),i.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`),i.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`),i.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`),i.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`),i.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`)},vJ=_J,yJ={db:{},renderer:_J,parser:{parse:P(()=>{},`parse`)}},bJ=`flowchart-elk`,xJ={id:bJ,detector:P((e,t={})=>/^\s*flowchart-elk/.test(e)||/^\s*(flowchart|graph)/.test(e)&&t?.flowchart?.defaultRenderer===`elk`?(t.layout=`elk`,!0):!1,`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./flowDiagram-I6XJVG4X-BXTQ7QRg.js`);return{diagram:e}},__vite__mapDeps([24,1,2,3,4,5,6,25,26,11,12,13,14,27,15,28,16,17,18,19,23]));return{id:bJ,diagram:e}},`loader`)},SJ=`timeline`,CJ={id:SJ,detector:P(e=>/^\s*timeline/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./timeline-definition-PNZ67QCA-BNvy_0DN.js`);return{diagram:e}},__vite__mapDeps([64,1,2,3,52,6,18,5]));return{id:SJ,diagram:e}},`loader`)},wJ=`mindmap`,TJ={id:wJ,detector:P(e=>/^\s*mindmap/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./mindmap-definition-RKZ34NQL-DqgCcW-r.js`);return{diagram:e}},__vite__mapDeps([65,1,2,3,4,5,6,26,11,12,13,14,27,15,16,17,18,19]));return{id:wJ,diagram:e}},`loader`)},EJ=`kanban`,DJ={id:EJ,detector:P(e=>/^\s*kanban/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./kanban-definition-UN3LZRKU-C5BAKIQX.js`);return{diagram:e}},__vite__mapDeps([66,1,2,3,4,5,6,11,12,13,14,28]));return{id:EJ,diagram:e}},`loader`)},OJ=`sankey`,kJ={id:OJ,detector:P(e=>/^\s*sankey(-beta)?/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./sankeyDiagram-5OEKKPKP-Cv_l_I0A.js`);return{diagram:e}},__vite__mapDeps([67,1,2,3,51,48]));return{id:OJ,diagram:e}},`loader`)},AJ=`packet`,jJ={id:AJ,detector:P(e=>/^\s*packet(-beta)?/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./diagram-LMA3HP47-f9ekzEBK.js`);return{diagram:e}},__vite__mapDeps([68,1,2,3,31,32,33,34,35,36,37,38,39,40,41,42,5,6,43]));return{id:AJ,diagram:e}},`loader`)},MJ=`radar`,NJ={id:MJ,detector:P(e=>/^\s*radar-beta/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./diagram-2AECGRRQ-DE80i5fc.js`);return{diagram:e}},__vite__mapDeps([69,1,2,3,31,32,33,34,35,36,37,38,39,40,41,42,5,6,43]));return{id:MJ,diagram:e}},`loader`)},PJ=`block`,FJ={id:PJ,detector:P(e=>/^\s*block(-beta)?/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./blockDiagram-GPEHLZMM-BlIpPvY3.js`);return{diagram:e}},__vite__mapDeps([70,1,2,3,4,5,6,17,18,19,8,9,25,15,28,12]));return{id:PJ,diagram:e}},`loader`)},IJ=`treeView`,LJ={id:IJ,detector:P(e=>/^\s*treeView-beta/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./diagram-5GNKFQAL-Egr34zuZ.js`);return{diagram:e}},__vite__mapDeps([71,1,2,3,31,32,33,34,35,36,37,38,39,40,41,42,5,6,43,44]));return{id:IJ,diagram:e}},`loader`)},RJ=`architecture`,zJ={id:RJ,detector:P(e=>/^\s*architecture/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./architectureDiagram-3BPJPVTR-BiL4yrd-.js`);return{diagram:e}},__vite__mapDeps([72,3,1,2,4,5,6,31,32,33,34,35,36,37,38,39,40,41,42,21,43]));return{id:RJ,diagram:e}},`loader`)},BJ=`eventmodeling`,VJ={id:BJ,detector:P(e=>/^\s*eventmodeling/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./diagram-KO2AKTUF-CvajPPQL.js`);return{diagram:e}},__vite__mapDeps([73,1,2,3,33,31,32,34,35,36,37,38,39,40,41,42,5,6,43]));return{id:BJ,diagram:e}},`loader`)},HJ=`ishikawa`,UJ={id:HJ,detector:P(e=>/^\s*ishikawa(-beta)?\b/i.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./ishikawaDiagram-YF4QCWOH-BFyPbPqD.js`);return{diagram:e}},__vite__mapDeps([74,1,2,3,5,6,14]));return{id:HJ,diagram:e}},`loader`)},WJ=`venn`,GJ={id:WJ,detector:P(e=>/^\s*venn-beta/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./vennDiagram-CIIHVFJN-D5RSWRYm.js`);return{diagram:e}},__vite__mapDeps([75,1,2,3,5,6,14]));return{id:WJ,diagram:e}},`loader`)},KJ=`treemap`,qJ={id:KJ,detector:P(e=>/^\s*treemap/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./diagram-OG6HWLK6-CJhcoTKU.js`);return{diagram:e}},__vite__mapDeps([76,1,2,3,31,32,33,34,35,36,37,38,39,40,41,42,47,51,48,5,6,26,43,13]));return{id:KJ,diagram:e}},`loader`)},JJ=`wardley-beta`,YJ={id:JJ,detector:P(e=>/^\s*wardley-beta/i.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./wardleyDiagram-YWT4CUSO-5PntQ1A_.js`);return{diagram:e}},__vite__mapDeps([77,1,2,3,31,32,33,34,35,36,37,38,39,40,41,42,5,6,43]));return{id:JJ,diagram:e}},`loader`)},XJ=!1,ZJ=P(()=>{XJ||(XJ=!0,l(`error`,yJ,e=>e.toLowerCase().trim()===`error`),l(`---`,{db:{clear:P(()=>{},`clear`)},styles:{},renderer:{draw:P(()=>{},`draw`)},parser:{parse:P(()=>{throw 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:P(()=>null,`init`)},e=>e.toLowerCase().trimStart().startsWith(`---`)),u(xJ,TJ,zJ),u(Rq,DJ,uJ,cJ,Wq,Jq,Xq,Qq,iJ,oJ,Hq,Bq,CJ,Kq,mJ,fJ,gJ,eJ,kJ,jJ,nJ,FJ,VJ,LJ,NJ,UJ,qJ,GJ,YJ))},`addDiagrams`),QJ=P(async()=>{ye.debug(`Loading registered diagrams`);let e=(await Promise.allSettled(Object.entries(C).map(async([e,{detector:t,loader:n}])=>{if(n)try{f(e)}catch{try{let{diagram:e,id:r}=await n();l(r,e,t)}catch(t){throw ye.error(`Failed to load external diagram with key ${e}. Removing from detectors.`),delete C[e],t}}}))).filter(e=>e.status===`rejected`);if(e.length>0){ye.error(`Failed to load ${e.length} external diagrams`);for(let t of e)ye.error(t);throw Error(`Failed to load ${e.length} external diagrams`)}},`loadRegisteredDiagrams`),$J=`graphics-document document`;function eY(e,t){e.attr(`role`,$J),t!==``&&e.attr(`aria-roledescription`,t)}P(eY,`setA11yDiagramInfo`);function tY(e,t,n,r){if(e.insert!==void 0){if(n){let t=`chart-desc-${r}`;e.attr(`aria-describedby`,t),e.insert(`desc`,`:first-child`).attr(`id`,t).text(n)}if(t){let n=`chart-title-${r}`;e.attr(`aria-labelledby`,n),e.insert(`title`,`:first-child`).attr(`id`,n).text(t)}}}P(tY,`addSVGa11yTitleDescription`);var nY=class e{constructor(e,t,n,r,i){this.type=e,this.text=t,this.db=n,this.parser=r,this.renderer=i}static{P(this,`Diagram`)}static async fromText(t,n={}){let r=y(),i=E(t,r);t=Oe(t)+`
367
+ `:``}P(NK,`dump$1`);var PK={dump:NK};function FK(e,t){return function(){throw Error(`Function yaml.`+e+` is removed in js-yaml 4. Use yaml.`+t+` instead, which is now safe by default.`)}}P(FK,`renamed`);var IK=WU,LK=bG.load;bG.loadAll,PK.dump;function RK(e){let t=e?.constructor;return e===(typeof t==`function`?t.prototype:Object.prototype)}function zK(e){if(e==null)return!0;if(Ae(e))return typeof e.splice!=`function`&&typeof e!=`string`&&!xe(e)&&!ke(e)&&!je(e)?!1:e.length===0;if(typeof e==`object`){if(e instanceof Map||e instanceof Set)return e.size===0;let t=Object.keys(e);return RK(e)?t.filter(e=>e!==`constructor`).length===0:t.length===0}return!0}var BK={common:k,getConfig:y,insertCluster:Fe,insertEdge:ze,insertEdgeLabel:Be,insertMarkers:Re,insertNode:Pe,interpolateToCurve:Ce,labelHelper:Ie,log:ye,positionEdgeLabel:Le},VK={},HK=P(e=>{for(let t of e)VK[t.name]=t},`registerLayoutLoaders`);P(()=>{HK([{name:`dagre`,loader:P(async()=>await A(()=>import(`./dagre-BM42HDAG-CZ5AtThh.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19])),`loader`)},{name:`cose-bilkent`,loader:P(async()=>await A(()=>import(`./cose-bilkent-S5V4N54A-CWucooZw.js`),__vite__mapDeps([20,3,21,2])),`loader`)}])},`registerDefaultLayoutLoaders`)();var UK=P(async(e,t)=>{if(!(e.layoutAlgorithm in VK))throw Error(`Unknown layout algorithm: ${e.layoutAlgorithm}`);if(e.diagramId)for(let t of e.nodes){let n=t.domId||t.id;t.domId=`${e.diagramId}-${n}`}let n=VK[e.layoutAlgorithm],r=await n.loader(),{theme:i,themeVariables:a}=e.config,{useGradient:o,gradientStart:s,gradientStop:c}=a,l=t.attr(`id`);if(t.append(`defs`).append(`filter`).attr(`id`,`${l}-drop-shadow`).attr(`height`,`130%`).attr(`width`,`130%`).append(`feDropShadow`).attr(`dx`,`4`).attr(`dy`,`4`).attr(`stdDeviation`,0).attr(`flood-opacity`,`0.06`).attr(`flood-color`,`${i?.includes(`dark`)?`#FFFFFF`:`#000000`}`),t.append(`defs`).append(`filter`).attr(`id`,`${l}-drop-shadow-small`).attr(`height`,`150%`).attr(`width`,`150%`).append(`feDropShadow`).attr(`dx`,`2`).attr(`dy`,`2`).attr(`stdDeviation`,0).attr(`flood-opacity`,`0.06`).attr(`flood-color`,`${i?.includes(`dark`)?`#FFFFFF`:`#000000`}`),o){let e=t.append(`linearGradient`).attr(`id`,t.attr(`id`)+`-gradient`).attr(`gradientUnits`,`objectBoundingBox`).attr(`x1`,`0%`).attr(`y1`,`0%`).attr(`x2`,`100%`).attr(`y2`,`0%`);e.append(`svg:stop`).attr(`offset`,`0%`).attr(`stop-color`,s).attr(`stop-opacity`,1),e.append(`svg:stop`).attr(`offset`,`100%`).attr(`stop-color`,c).attr(`stop-opacity`,1)}return r.render(e,t,BK,{algorithm:n.algorithm})},`render`),WK=P((e=``,{fallback:t=`dagre`}={})=>{if(e in VK)return e;if(t in VK)return ye.warn(`Layout algorithm ${e} is not registered. Using ${t} as fallback.`),t;throw Error(`Both layout algorithms ${e} and ${t} are not registered.`)},`getRegisteredLayoutAlgorithm`),GK=`comm`,KK=`rule`,qK=`decl`,JK=`@import`,YK=`@namespace`,XK=`@keyframes`,ZK=`@layer`,QK=Math.abs,$K=String.fromCharCode;function eq(e){return e.trim()}function tq(e,t,n){return e.replace(t,n)}function nq(e,t){return e.charCodeAt(t)|0}function rq(e,t,n){return e.slice(t,n)}function iq(e){return e.length}function aq(e){return e.length}function oq(e,t){return t.push(e),e}var sq=1,cq=1,lq=0,uq=0,dq=0,fq=``;function pq(e,t,n,r,i,a,o,s){return{value:e,root:t,parent:n,type:r,props:i,children:a,line:sq,column:cq,length:o,return:``,siblings:s}}function mq(){return dq}function hq(){return dq=uq>0?nq(fq,--uq):0,cq--,dq===10&&(cq=1,sq--),dq}function gq(){return dq=uq<lq?nq(fq,uq++):0,cq++,dq===10&&(cq=1,sq++),dq}function _q(){return nq(fq,uq)}function vq(){return uq}function yq(e,t){return rq(fq,e,t)}function bq(e){switch(e){case 0:case 9:case 10:case 13:case 32:return 5;case 33:case 43:case 44:case 47:case 62:case 64:case 126:case 59:case 123:case 125:return 4;case 58:return 3;case 34:case 39:case 40:case 91:return 2;case 41:case 93:return 1}return 0}function xq(e){return sq=cq=1,lq=iq(fq=e),uq=0,[]}function Sq(e){return fq=``,e}function Cq(e){return eq(yq(uq-1,Eq(e===91?e+2:e===40?e+1:e)))}function wq(e){for(;(dq=_q())&&dq<33;)gq();return bq(e)>2||bq(dq)>3?``:` `}function Tq(e,t){for(;--t&&gq()&&!(dq<48||dq>102||dq>57&&dq<65||dq>70&&dq<97););return yq(e,vq()+(t<6&&_q()==32&&gq()==32))}function Eq(e){for(;gq();)switch(dq){case e:return uq;case 34:case 39:e!==34&&e!==39&&Eq(dq);break;case 40:e===41&&Eq(e);break;case 92:gq();break}return uq}function Dq(e,t){for(;gq()&&e+dq!==57&&!(e+dq===84&&_q()===47););return`/*`+yq(t,uq-1)+`*`+$K(e===47?e:gq())}function Oq(e){for(;!bq(_q());)gq();return yq(e,uq)}function kq(e){return Sq(Aq(``,null,null,null,[``],e=xq(e),0,[0],e))}function Aq(e,t,n,r,i,a,o,s,c){for(var l=0,u=0,d=o,f=0,p=0,m=0,h=1,g=1,_=1,v=0,y=0,b=``,x=i,S=a,C=r,w=b;g;)switch(m=y,y=gq()){case 40:m!=108&&nq(w,d-1)==58?(v++,w+=`(`):w+=Cq(y);break;case 41:v--,w+=`)`;break;case 34:case 39:case 91:w+=Cq(y);break;case 9:case 10:case 13:case 32:if(v>0){w+=$K(y);break}w+=wq(m);break;case 92:w+=Tq(vq()-1,7);continue;case 47:switch(_q()){case 42:case 47:oq(Mq(Dq(gq(),vq()),t,n,c),c),(bq(m||1)==5||bq(_q()||1)==5)&&iq(w)&&rq(w,-1,void 0)!==` `&&(w+=` `);break;default:w+=`/`}break;case 123*h:s[l++]=iq(w)*_;case 125*h:case 59:case 0:if(v>0&&y){w+=$K(y);break}switch(y){case 0:case 125:g=0;case 59+u:_==-1&&(w=tq(w,/\f/g,``)),p>0&&(iq(w)-d||h===0)&&oq(p>32?Nq(w+`;`,r,n,d-1,c):Nq(tq(w,` `,``)+`;`,r,n,d-2,c),c);break;case 59:w+=`;`;default:if(oq(C=jq(w,t,n,l,u,i,s,b,x=[],S=[],d,a),a),y===123)if(u===0)Aq(w,t,C,C,x,a,d,s,S);else{switch(f){case 99:if(nq(w,3)===110)break;case 108:if(nq(w,2)===97)break;default:u=0;case 100:case 109:case 115:}u?Aq(e,C,C,r&&oq(jq(e,C,C,0,0,i,s,b,i,x=[],d,S),S),i,S,d,s,r?x:S):Aq(w,C,C,C,[``],S,0,s,S)}}l=u=p=0,h=_=1,b=w=``,d=o;break;case 58:d=1+iq(w),p=m;default:if(h<1){if(y==123)--h;else if(y==125&&h++==0&&hq()==125)continue}switch(w+=$K(y),y*h){case 38:_=u>0?1:(w+=`\f`,-1);break;case 44:if(v>0)break;s[l++]=(iq(w)-1)*_,_=1;break;case 64:_q()===45&&(w+=Cq(gq())),f=_q(),u=d=iq(b=w+=Oq(vq())),y++;break;case 45:m===45&&iq(w)==2&&(h=0)}}return a}function jq(e,t,n,r,i,a,o,s,c,l,u,d){for(var f=i-1,p=i===0?a:[``],m=aq(p),h=0,g=0,_=0;h<r;++h)for(var v=0,y=rq(e,f+1,f=QK(g=o[h])),b=e;v<m;++v)(b=eq(g>0?p[v]+` `+y:tq(y,/&\f/g,p[v])))&&(c[_++]=b);return pq(e,t,n,i===0?KK:s,c,l,u,d)}function Mq(e,t,n,r){return pq(e,t,n,GK,$K(mq()),rq(e,2,-2),0,r)}function Nq(e,t,n,r,i){return pq(e,t,n,qK,rq(e,0,r),rq(e,r+1,-1),r,i)}function Pq(e,t){for(var n=``,r=0;r<e.length;r++)n+=t(e[r],r,e,t)||``;return n}function Fq(e,t,n,r){switch(e.type){case ZK:if(e.children.length)break;case JK:case YK:case qK:return e.return=e.return||e.value;case GK:return``;case XK:return e.return=e.value+`{`+Pq(e.children,r)+`}`;case KK:if(!iq(e.value=e.props.join(`,`)))return``}return iq(n=Pq(e.children,r))?e.return=e.value+`{`+n+`}`:``}function Iq(e){var t=aq(e);return function(n,r,i,a){for(var o=``,s=0;s<t;s++)o+=e[s](n,r,i,a)||``;return o}}var Lq=`c4`,Rq={id:Lq,detector:P(e=>/^\s*C4Context|C4Container|C4Component|C4Dynamic|C4Deployment/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./c4Diagram-AAUBKEIU-CzsNYAS-.js`);return{diagram:e}},__vite__mapDeps([22,1,2,3,6,5,23]));return{id:Lq,diagram:e}},`loader`)},zq=`flowchart`,Bq={id:zq,detector:P((e,t)=>t?.flowchart?.defaultRenderer===`dagre-wrapper`||t?.flowchart?.defaultRenderer===`elk`?!1:/^\s*graph/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./flowDiagram-I6XJVG4X-CUF2AkfX.js`);return{diagram:e}},__vite__mapDeps([24,1,2,3,4,5,6,25,26,11,12,13,14,27,15,28,16,17,18,19,23]));return{id:zq,diagram:e}},`loader`)},Vq=`flowchart-v2`,Hq={id:Vq,detector:P((e,t)=>t?.flowchart?.defaultRenderer===`dagre-d3`?!1:(t?.flowchart?.defaultRenderer===`elk`&&(t.layout=`elk`),/^\s*graph/.test(e)&&t?.flowchart?.defaultRenderer===`dagre-wrapper`?!0:/^\s*flowchart/.test(e)),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./flowDiagram-I6XJVG4X-CUF2AkfX.js`);return{diagram:e}},__vite__mapDeps([24,1,2,3,4,5,6,25,26,11,12,13,14,27,15,28,16,17,18,19,23]));return{id:Vq,diagram:e}},`loader`)},Uq=`er`,Wq={id:Uq,detector:P(e=>/^\s*erDiagram/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./erDiagram-TEJ5UH35-KifhsjrY.js`);return{diagram:e}},__vite__mapDeps([29,1,2,3,4,5,6,25,26,11,12,13,14,27,15,16,17,18,19]));return{id:Uq,diagram:e}},`loader`)},Gq=`gitGraph`,Kq={id:Gq,detector:P(e=>/^\s*gitGraph/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./gitGraphDiagram-PVQCEYII-D8BksuAg.js`);return{diagram:e}},__vite__mapDeps([30,1,2,3,31,32,33,34,35,36,37,38,39,40,41,42,5,6,43,44]));return{id:Gq,diagram:e}},`loader`)},qq=`gantt`,Jq={id:qq,detector:P(e=>/^\s*gantt/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./ganttDiagram-6RSMTGT7-9CPIXrRu.js`);return{diagram:e}},__vite__mapDeps([45,3,1,2,6,46,47,48,5]));return{id:qq,diagram:e}},`loader`)},Yq=`info`,Xq={id:Yq,detector:P(e=>/^\s*info/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./infoDiagram-5YYISTIA-BWBMucTX.js`);return{diagram:e}},__vite__mapDeps([49,1,2,3,31,32,33,34,35,36,37,38,39,40,41,42]));return{id:Yq,diagram:e}},`loader`)},Zq=`pie`,Qq={id:Zq,detector:P(e=>/^\s*pie/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./pieDiagram-4H26LBE5-BeDVs-my.js`);return{diagram:e}},__vite__mapDeps([50,1,2,3,6,31,32,33,34,35,36,37,38,39,40,41,42,18,51,48,52,19,5,43]));return{id:Zq,diagram:e}},`loader`)},$q=`quadrantChart`,eJ={id:$q,detector:P(e=>/^\s*quadrantChart/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./quadrantDiagram-W4KKPZXB-BBjjuCms.js`);return{diagram:e}},__vite__mapDeps([53,1,2,3,46,47,48]));return{id:$q,diagram:e}},`loader`)},tJ=`xychart`,nJ={id:tJ,detector:P(e=>/^\s*xychart(-beta)?/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./xychartDiagram-2RQKCTM6-DwH6-8zP.js`);return{diagram:e}},__vite__mapDeps([54,1,2,3,4,5,6,46,47,48,51,17,18,19]));return{id:tJ,diagram:e}},`loader`)},rJ=`requirement`,iJ={id:rJ,detector:P(e=>/^\s*requirement(Diagram)?/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./requirementDiagram-4Y6WPE33-AQfIOy53.js`);return{diagram:e}},__vite__mapDeps([55,1,2,3,4,5,6,26,11,12,13,14,27,15,16,17,18,19]));return{id:rJ,diagram:e}},`loader`)},aJ=`sequence`,oJ={id:aJ,detector:P(e=>/^\s*sequenceDiagram/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./sequenceDiagram-3UESZ5HK--egU0Cm3.js`);return{diagram:e}},__vite__mapDeps([56,1,2,3,6,5,23,44]));return{id:aJ,diagram:e}},`loader`)},sJ=`class`,cJ={id:sJ,detector:P((e,t)=>t?.class?.defaultRenderer===`dagre-wrapper`?!1:/^\s*classDiagram/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./classDiagram-4FO5ZUOK-CRIzZW-i.js`);return{diagram:e}},__vite__mapDeps([57,1,2,3,4,5,6,26,11,12,13,14,27,58,28,23,15,16,17,18,19]));return{id:sJ,diagram:e}},`loader`)},lJ=`classDiagram`,uJ={id:lJ,detector:P((e,t)=>/^\s*classDiagram/.test(e)&&t?.class?.defaultRenderer===`dagre-wrapper`?!0:/^\s*classDiagram-v2/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./classDiagram-v2-Q7XG4LA2-CWOJ0KP_.js`);return{diagram:e}},__vite__mapDeps([59,1,2,3,4,5,6,26,11,12,13,14,27,58,28,23,15,16,17,18,19]));return{id:lJ,diagram:e}},`loader`)},dJ=`state`,fJ={id:dJ,detector:P((e,t)=>t?.state?.defaultRenderer===`dagre-wrapper`?!1:/^\s*stateDiagram/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./stateDiagram-AJRCARHV-CbyXuf3R.js`);return{diagram:e}},__vite__mapDeps([60,1,2,3,4,5,6,17,18,19,7,8,9,10,26,11,12,13,14,27,61,15,16]));return{id:dJ,diagram:e}},`loader`)},pJ=`stateDiagram`,mJ={id:pJ,detector:P((e,t)=>!!(/^\s*stateDiagram-v2/.test(e)||/^\s*stateDiagram/.test(e)&&t?.state?.defaultRenderer===`dagre-wrapper`),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./stateDiagram-v2-BHNVJYJU-CeJTs4x0.js`);return{diagram:e}},__vite__mapDeps([62,1,2,3,4,5,6,26,11,12,13,14,27,61,15,16,17,18,19]));return{id:pJ,diagram:e}},`loader`)},hJ=`journey`,gJ={id:hJ,detector:P(e=>/^\s*journey/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./journeyDiagram-JHISSGLW-DR1RevaB.js`);return{diagram:e}},__vite__mapDeps([63,1,2,3,52,6,18,28,23]));return{id:hJ,diagram:e}},`loader`)},_J={draw:P((e,t,n)=>{ye.debug(`rendering svg for syntax error
368
+ `);let r=QH(t),i=r.append(`g`);r.attr(`viewBox`,`0 0 2412 512`),b(r,100,512,!0),i.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`),i.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`),i.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`),i.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`),i.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`),i.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`),i.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`),i.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`)},vJ=_J,yJ={db:{},renderer:_J,parser:{parse:P(()=>{},`parse`)}},bJ=`flowchart-elk`,xJ={id:bJ,detector:P((e,t={})=>/^\s*flowchart-elk/.test(e)||/^\s*(flowchart|graph)/.test(e)&&t?.flowchart?.defaultRenderer===`elk`?(t.layout=`elk`,!0):!1,`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./flowDiagram-I6XJVG4X-CUF2AkfX.js`);return{diagram:e}},__vite__mapDeps([24,1,2,3,4,5,6,25,26,11,12,13,14,27,15,28,16,17,18,19,23]));return{id:bJ,diagram:e}},`loader`)},SJ=`timeline`,CJ={id:SJ,detector:P(e=>/^\s*timeline/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./timeline-definition-PNZ67QCA-DvSJjt5p.js`);return{diagram:e}},__vite__mapDeps([64,1,2,3,52,6,18,5]));return{id:SJ,diagram:e}},`loader`)},wJ=`mindmap`,TJ={id:wJ,detector:P(e=>/^\s*mindmap/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./mindmap-definition-RKZ34NQL-BcWz14bu.js`);return{diagram:e}},__vite__mapDeps([65,1,2,3,4,5,6,26,11,12,13,14,27,15,16,17,18,19]));return{id:wJ,diagram:e}},`loader`)},EJ=`kanban`,DJ={id:EJ,detector:P(e=>/^\s*kanban/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./kanban-definition-UN3LZRKU-B5M0uLn9.js`);return{diagram:e}},__vite__mapDeps([66,1,2,3,4,5,6,11,12,13,14,28]));return{id:EJ,diagram:e}},`loader`)},OJ=`sankey`,kJ={id:OJ,detector:P(e=>/^\s*sankey(-beta)?/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./sankeyDiagram-5OEKKPKP-Cv_l_I0A.js`);return{diagram:e}},__vite__mapDeps([67,1,2,3,51,48]));return{id:OJ,diagram:e}},`loader`)},AJ=`packet`,jJ={id:AJ,detector:P(e=>/^\s*packet(-beta)?/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./diagram-LMA3HP47-B_1CjDrM.js`);return{diagram:e}},__vite__mapDeps([68,1,2,3,31,32,33,34,35,36,37,38,39,40,41,42,5,6,43]));return{id:AJ,diagram:e}},`loader`)},MJ=`radar`,NJ={id:MJ,detector:P(e=>/^\s*radar-beta/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./diagram-2AECGRRQ-aYV3991Q.js`);return{diagram:e}},__vite__mapDeps([69,1,2,3,31,32,33,34,35,36,37,38,39,40,41,42,5,6,43]));return{id:MJ,diagram:e}},`loader`)},PJ=`block`,FJ={id:PJ,detector:P(e=>/^\s*block(-beta)?/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./blockDiagram-GPEHLZMM-BlIpPvY3.js`);return{diagram:e}},__vite__mapDeps([70,1,2,3,4,5,6,17,18,19,8,9,25,15,28,12]));return{id:PJ,diagram:e}},`loader`)},IJ=`treeView`,LJ={id:IJ,detector:P(e=>/^\s*treeView-beta/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./diagram-5GNKFQAL-430D0ULK.js`);return{diagram:e}},__vite__mapDeps([71,1,2,3,31,32,33,34,35,36,37,38,39,40,41,42,5,6,43,44]));return{id:IJ,diagram:e}},`loader`)},RJ=`architecture`,zJ={id:RJ,detector:P(e=>/^\s*architecture/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./architectureDiagram-3BPJPVTR-BqWvl6_Z.js`);return{diagram:e}},__vite__mapDeps([72,3,1,2,4,5,6,31,32,33,34,35,36,37,38,39,40,41,42,21,43]));return{id:RJ,diagram:e}},`loader`)},BJ=`eventmodeling`,VJ={id:BJ,detector:P(e=>/^\s*eventmodeling/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./diagram-KO2AKTUF-CvajPPQL.js`);return{diagram:e}},__vite__mapDeps([73,1,2,3,33,31,32,34,35,36,37,38,39,40,41,42,5,6,43]));return{id:BJ,diagram:e}},`loader`)},HJ=`ishikawa`,UJ={id:HJ,detector:P(e=>/^\s*ishikawa(-beta)?\b/i.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./ishikawaDiagram-YF4QCWOH-B08GNYsG.js`);return{diagram:e}},__vite__mapDeps([74,1,2,3,5,6,14]));return{id:HJ,diagram:e}},`loader`)},WJ=`venn`,GJ={id:WJ,detector:P(e=>/^\s*venn-beta/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./vennDiagram-CIIHVFJN-BFBGrdGc.js`);return{diagram:e}},__vite__mapDeps([75,1,2,3,5,6,14]));return{id:WJ,diagram:e}},`loader`)},KJ=`treemap`,qJ={id:KJ,detector:P(e=>/^\s*treemap/.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./diagram-OG6HWLK6-DS7uDEpu.js`);return{diagram:e}},__vite__mapDeps([76,1,2,3,31,32,33,34,35,36,37,38,39,40,41,42,47,51,48,5,6,26,43,13]));return{id:KJ,diagram:e}},`loader`)},JJ=`wardley-beta`,YJ={id:JJ,detector:P(e=>/^\s*wardley-beta/i.test(e),`detector`),loader:P(async()=>{let{diagram:e}=await A(async()=>{let{diagram:e}=await import(`./wardleyDiagram-YWT4CUSO-9QmHh5AB.js`);return{diagram:e}},__vite__mapDeps([77,1,2,3,31,32,33,34,35,36,37,38,39,40,41,42,5,6,43]));return{id:JJ,diagram:e}},`loader`)},XJ=!1,ZJ=P(()=>{XJ||(XJ=!0,l(`error`,yJ,e=>e.toLowerCase().trim()===`error`),l(`---`,{db:{clear:P(()=>{},`clear`)},styles:{},renderer:{draw:P(()=>{},`draw`)},parser:{parse:P(()=>{throw 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:P(()=>null,`init`)},e=>e.toLowerCase().trimStart().startsWith(`---`)),u(xJ,TJ,zJ),u(Rq,DJ,uJ,cJ,Wq,Jq,Xq,Qq,iJ,oJ,Hq,Bq,CJ,Kq,mJ,fJ,gJ,eJ,kJ,jJ,nJ,FJ,VJ,LJ,NJ,UJ,qJ,GJ,YJ))},`addDiagrams`),QJ=P(async()=>{ye.debug(`Loading registered diagrams`);let e=(await Promise.allSettled(Object.entries(C).map(async([e,{detector:t,loader:n}])=>{if(n)try{f(e)}catch{try{let{diagram:e,id:r}=await n();l(r,e,t)}catch(t){throw ye.error(`Failed to load external diagram with key ${e}. Removing from detectors.`),delete C[e],t}}}))).filter(e=>e.status===`rejected`);if(e.length>0){ye.error(`Failed to load ${e.length} external diagrams`);for(let t of e)ye.error(t);throw Error(`Failed to load ${e.length} external diagrams`)}},`loadRegisteredDiagrams`),$J=`graphics-document document`;function eY(e,t){e.attr(`role`,$J),t!==``&&e.attr(`aria-roledescription`,t)}P(eY,`setA11yDiagramInfo`);function tY(e,t,n,r){if(e.insert!==void 0){if(n){let t=`chart-desc-${r}`;e.attr(`aria-describedby`,t),e.insert(`desc`,`:first-child`).attr(`id`,t).text(n)}if(t){let n=`chart-title-${r}`;e.attr(`aria-labelledby`,n),e.insert(`title`,`:first-child`).attr(`id`,n).text(t)}}}P(tY,`addSVGa11yTitleDescription`);var nY=class e{constructor(e,t,n,r,i){this.type=e,this.text=t,this.db=n,this.parser=r,this.renderer=i}static{P(this,`Diagram`)}static async fromText(t,n={}){let r=y(),i=E(t,r);t=Oe(t)+`
369
369
  `;try{f(i)}catch{let e=a(i);if(!e)throw new ee(`Diagram ${i} not found.`);let{id:t,diagram:n}=await e();l(t,n)}let{db:o,parser:s,renderer:c,init:u}=f(i);return s.parser&&(s.parser.yy=o),o.clear?.(),u?.(r),n.title&&o.setDiagramTitle?.(n.title),await s.parse(t),new e(i,t,o,s,c)}async render(e,t){await this.renderer.draw(this.text,e,t,this)}getParser(){return this.parser}getType(){return this.type}},rY=[],iY=P(()=>{rY.forEach(e=>{e()}),rY=[]},`attachFunctions`),aY=P(e=>e.replace(/^\s*%%(?!{)[^\n]+\n?/gm,``).trimStart(),`cleanupComments`);function oY(e){let t=e.match(v);if(!t)return{text:e,metadata:{}};let n=LK(t[1],{schema:IK})??{};n=typeof n==`object`&&!Array.isArray(n)?n:{};let r={};return n.displayMode&&(r.displayMode=n.displayMode.toString()),n.title&&(r.title=n.title.toString()),n.config&&(r.config=n.config),{text:e.slice(t[0].length),metadata:r}}P(oY,`extractFrontMatter`);var sY=P(e=>e.replace(/\r\n?/g,`
370
370
  `).replace(/<(\w+)([^>]*)>/g,(e,t,n)=>`<`+t+n.replace(/="([^"]*)"/g,`='$1'`)+`>`),`cleanupText`),cY=P(e=>{let{text:t,metadata:n}=oY(e),{displayMode:r,title:i,config:a={}}=n;return r&&(a.gantt||={},a.gantt.displayMode=r),{title:i,config:a,text:t}},`processFrontmatter`),lY=P(e=>{let t=Te.detectInit(e)??{},n=Te.detectDirective(e,`wrap`);return Array.isArray(n)?t.wrap=n.some(({type:e})=>e===`wrap`):n?.type===`wrap`&&(t.wrap=!0),{text:Ee(e),directive:t}},`processDirectives`);function uY(e){let t=cY(sY(e)),n=lY(t.text),r=De(t.config,n.directive);return e=aY(n.text),{code:e,title:t.title,config:r}}P(uY,`preprocessDiagram`);function dY(e){let t=new TextEncoder().encode(e),n=Array.from(t,e=>String.fromCodePoint(e)).join(``);return btoa(n)}P(dY,`toBase64`);var fY=5e4,pY=`graph TB;a[Maximum text size in diagram exceeded];style a fill:#faa`,mY=`sandbox`,hY=`loose`,gY=`http://www.w3.org/2000/svg`,_Y=`http://www.w3.org/1999/xlink`,vY=`http://www.w3.org/1999/xhtml`,yY=`100%`,bY=`100%`,xY=`border:0;margin:0;`,SY=`margin:0`,CY=`allow-top-navigation-by-user-activation allow-popups`,wY=`The "iframe" tag is not supported by your browser.`,TY=[`foreignobject`],EY=[`dominant-baseline`];function DY(e){let t=uY(e);return s(),w(t.config??{}),t}P(DY,`processAndSetConfigs`);async function OY(e,t){ZJ();try{let{code:t,config:n}=DY(e);return{diagramType:(await BY(t)).type,config:n}}catch(e){if(t?.suppressErrors)return!1;throw e}}P(OY,`parse`);var kY=P((e,t,n=[])=>`.${e} ${t} ${c(`{ ${n.join(` !important; `)} !important; }`)}`,`cssImportantStyles`),AY=P((e,t=new Map)=>{let n=new CSSStyleSheet;if(e.fontFamily!==void 0&&n.insertRule(`:root { --mermaid-font-family: ${e.fontFamily}}`,n.cssRules.length),e.altFontFamily!==void 0&&n.insertRule(`:root { --mermaid-alt-font-family: ${e.altFontFamily}}`,n.cssRules.length),t instanceof Map){let r=p(e)?[`> *`,`span`]:[`rect`,`polygon`,`ellipse`,`circle`,`path`];t.forEach(e=>{zK(e.styles)||r.forEach(t=>{n.insertRule(kY(e.id,t,e.styles),n.cssRules.length)}),zK(e.textStyles)||n.insertRule(kY(e.id,`tspan`,(e?.textStyles||[]).map(e=>e.replace(`color`,`fill`))),n.cssRules.length)})}let r=``;if(e.themeCSS!==void 0)if(typeof n.replaceSync==`function`){let t=new CSSStyleSheet;t.replaceSync(e.themeCSS),r=S(t)+`
371
371
  `}else r+=`${e.themeCSS}
@@ -394,7 +394,7 @@ https://github.com/highlightjs/highlight.js/issues/2277`),i=e,r=t),n===void 0&&(
394
394
  `),r=(0,F.useMemo)(()=>{try{if(t)return u6.highlight(e,{language:t,ignoreIllegals:!0}).value;{let t=u6.highlightAuto(e);if(t.language)return t.value}}catch{}return null},[e,t]);return(0,L.jsx)(`div`,{className:`overflow-hidden rounded-md font-mono text-xs leading-5`,style:{border:`1px solid var(--cm-code-border)`,backgroundColor:`var(--cm-code-bg)`},children:(0,L.jsx)(`div`,{className:`max-h-80 overflow-auto`,children:r?(0,L.jsxs)(`div`,{className:`flex`,children:[(0,L.jsx)(`div`,{className:`shrink-0 text-right text-[9px] select-none`,style:{color:`var(--cm-gutter)`,borderRight:`1px solid var(--cm-border)`,minWidth:`3rem`},children:n.map((e,t)=>(0,L.jsx)(`div`,{className:`pr-3 py-px`,children:t+1},t))}),(0,L.jsx)(`pre`,{className:`flex-1 pl-2 py-px whitespace-pre-wrap break-all`,dangerouslySetInnerHTML:{__html:r}})]}):n.map((e,t)=>(0,L.jsxs)(`div`,{className:`flex`,children:[(0,L.jsx)(`span`,{className:`w-12 shrink-0 text-right pr-3 py-px text-[9px] select-none border-r`,style:{color:`var(--cm-gutter)`,borderColor:`var(--cm-border)`},children:t+1}),(0,L.jsx)(`span`,{className:`pl-2 py-px whitespace-pre-wrap break-all`,style:{color:`var(--cm-text)`},children:e})]},t))})})}function Q6({command:e,output:t}){return(0,L.jsxs)(`div`,{className:`overflow-hidden rounded-md bg-[#0d1117] border border-gray-700 text-xs`,children:[e&&(0,L.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-gray-700/50 px-3 py-1.5 text-green-400 font-mono`,children:[(0,L.jsx)(`span`,{className:`select-none text-gray-500 text-[10px]`,children:`$`}),(0,L.jsx)(`span`,{className:`whitespace-pre-wrap break-all font-medium`,children:e})]}),t!==void 0&&(0,L.jsx)(`pre`,{className:`max-h-64 overflow-auto px-3 py-2 text-gray-300 whitespace-pre-wrap font-mono leading-relaxed`,children:t||(0,L.jsx)(`span`,{className:`text-gray-500 italic`,children:`(no output)`})})]})}function $6({toolName:e,args:t,result:n,status:r=`complete`,elapsedSeconds:i,taskState:a,toolCallId:o}){let s=B6(e),c=s.icon,l=H6(e,t),[u,d]=(0,F.useState)(!1),f=r===`complete`,p=r===`running`,m=r===`requires-action`,h=z6[r],g=f6(),{permissionPrompt:_,answerPermission:v,openFile:y}=D6(),b=m||_?.toolUseId===o,x=u||b,S=R6(p,i),C=f&&n?U6(n):null,w=C!==null,T=e===`Bash`,E=e===`TodoWrite`,D=e===`Agent`||e===`Task`,O=e===`Write`,k=e===`Edit`||e===`ApplyPatch`,A=Object.keys(t).length>0,ee=t.content??``,j=t.old_string??``,te=t.new_string??``,M=k&&j&&te,ne=V6(t.file_path||t.filePath||``),N=!!(y&&ne&&f),re=(0,F.useMemo)(()=>{let e=ne.includes(`.`)?ne.split(`.`).pop()?.toLowerCase()??``:``;return{js:`javascript`,jsx:`javascript`,ts:`typescript`,tsx:`typescript`,py:`python`,rs:`rust`,go:`go`,rb:`ruby`,swift:`swift`,java:`java`,c:`c`,cpp:`cpp`,cs:`csharp`,kt:`kotlin`,json:`json`,yaml:`yaml`,yml:`yaml`,toml:`ini`,xml:`xml`,html:`xml`,htm:`xml`,svg:`xml`,css:`css`,scss:`scss`,less:`less`,sql:`sql`,sh:`bash`,bash:`bash`,zsh:`bash`,fish:`bash`,md:`markdown`,dockerfile:`dockerfile`,proto:`protobuf`,php:`php`,lua:`lua`,r:`r`,scala:`scala`}[e]||(e&&e.length<=5?e:``)},[ne]),ie=E?Array.isArray(t.todos)?t.todos:[]:null,ae=x?null:O&&ee?J6(ee,200):k&&(w||M)?{type:`edit`,oldStr:j,newStr:te,diff:C}:null;return(0,L.jsxs)(j0,{open:x,onOpenChange:d,className:lh(`group/tool my-1.5 overflow-hidden rounded-lg border border-gray-100 bg-gray-50/60 border-l-[3px]`,s.borderClass,p&&`animate-pulse`),children:[(0,L.jsxs)(M0,{className:`flex w-full flex-col text-left text-sm transition-colors hover:bg-gray-50`,children:[(0,L.jsxs)(`div`,{className:`flex w-full items-center gap-1.5 md:gap-2 px-2 md:px-3 py-1.5`,children:[(0,L.jsx)(c,{className:`h-3.5 w-3.5 shrink-0 text-gray-400`}),(0,L.jsx)(`span`,{className:`font-medium text-gray-700 text-xs`,children:e}),l&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`span`,{className:`text-gray-300`,children:`·`}),(0,L.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-[11px] text-gray-500`,children:l})]}),b?(0,L.jsx)(`span`,{className:`ml-auto shrink-0 rounded px-1.5 py-px text-[10px] font-medium bg-amber-100 text-amber-700`,children:`Action needed`}):p?(0,L.jsx)(`span`,{className:`ml-auto shrink-0 rounded px-1.5 py-px text-[10px] font-medium tabular-nums bg-sky-100 text-sky-700`,children:L6(S)}):(0,L.jsx)(`span`,{className:lh(`ml-auto shrink-0 rounded px-1.5 py-px text-[10px] font-medium`,h.className),children:h.label}),(0,L.jsx)(ht,{className:lh(`h-3.5 w-3.5 shrink-0 text-gray-300 transition-transform`,u&&`rotate-180`)})]}),ae&&(0,L.jsx)(`div`,{className:`border-t border-gray-100 px-2 md:px-3 py-1.5`,children:typeof ae==`string`?(0,L.jsx)(`pre`,{className:`font-mono text-[10px] leading-relaxed text-gray-500 whitespace-pre-wrap break-all line-clamp-3`,children:ae}):ae.type===`edit`?ae.diff&&n?(0,L.jsx)(K6,{text:n,lang:re,maxLines:8}):(0,L.jsx)(`div`,{className:`opacity-70`,children:(0,L.jsx)(X6,{oldStr:ae.oldStr,newStr:ae.newStr,maxLen:20,lang:re})}):null})]}),(0,L.jsx)(N0,{className:lh(`overflow-hidden`,`data-[state=open]:animate-collapsible-down`,`data-[state=closed]:animate-collapsible-up`),children:(0,L.jsxs)(`div`,{className:lh(`border-t border-gray-100 px-2 md:px-3 py-2`,g&&`max-h-[60vh] overflow-y-auto`),children:[b&&_&&(0,L.jsx)(I6,{toolName:_.toolName,title:_.title,displayName:_.displayName,onAllow:()=>v(_.toolUseId,!0),onDeny:()=>v(_.toolUseId,!1)}),N&&(0,L.jsxs)(`button`,{type:`button`,onClick:()=>y(ne),className:`inline-flex items-center gap-1 mb-2 px-2 py-1 rounded text-[11px] border border-gray-200 bg-white hover:bg-gray-50 text-gray-600 hover:text-gray-900 transition-colors`,children:[(0,L.jsx)(Mt,{className:`h-3 w-3`}),`Open in Editor`]}),O&&f&&ee&&(0,L.jsx)(q6,{content:ee,lang:re}),k&&f&&w&&n&&(0,L.jsx)(K6,{text:n,lang:re}),k&&f&&!w&&M&&(0,L.jsx)(X6,{oldStr:j,newStr:te,lang:re}),T&&(l||n!==void 0)&&(0,L.jsx)(Q6,{command:l,output:n}),E&&ie&&ie.length>0&&(0,L.jsx)(m6,{todos:ie}),D&&(0,L.jsx)(P6,{args:t,result:n,status:r,taskState:a,elapsedSeconds:S,toolCallId:o}),!O&&!T&&!E&&!D&&!(k&&(w||M))&&n!==void 0&&(0,L.jsx)(Z6,{text:typeof n==`string`?n:JSON.stringify(n,null,2),lang:re}),p&&!b&&!n&&!A&&!D&&!(E&&ie&&ie.length>0)&&(0,L.jsxs)(`div`,{className:`flex items-center gap-2 py-1 text-xs text-gray-400`,children:[(0,L.jsx)(an,{className:`h-3 w-3 animate-spin`}),`Working...`]}),r===`incomplete`&&(0,L.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-red-500`,children:[(0,L.jsx)(Ct,{className:`h-3.5 w-3.5`}),`Tool call failed`]})]})})]})}var e8=class extends F.Component{constructor(e){super(e),this.state={error:null}}static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){console.error(`[ErrorBoundary:`+this.props.name+`]`,e.message,e.stack,t)}render(){return this.state.error?(0,L.jsxs)(`div`,{className:`rounded border border-red-200 bg-red-50 p-3 text-xs text-red-700`,children:[(0,L.jsxs)(`b`,{children:[`Error in `,this.props.name,`:`]}),` `,this.state.error.message]}):this.props.children}};function t8(e){if(!e)return``;let t=e.match(/(\d{13})/);return t?new Date(parseInt(t[1],10)).toLocaleTimeString():``}function n8(e){let t=[`Tokens: ${(e.input+e.output).toLocaleString()} ↑${e.input.toLocaleString()} ↓${e.output.toLocaleString()}`];return e.ttftMs!=null&&t.push(`TTFT ${(e.ttftMs/1e3).toFixed(1)}s`),t.push(`${(e.totalMs/1e3).toFixed(1)}s`),t.join(` · `)}function r8({content:e}){let t=e.trim();if(!(t.startsWith(`{`)||t.startsWith(`[`))||!(t.endsWith(`}`)||t.endsWith(`]`)))return null;try{let e=JSON.parse(t),n=JSON.stringify(e,null,2);return(0,L.jsxs)(`div`,{className:`my-2`,children:[(0,L.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 text-sm text-gray-500`,children:[(0,L.jsx)(`svg`,{className:`h-4 w-4`,fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,children:(0,L.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M7 21h10a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v14a2 2 0 002 2z`})}),(0,L.jsx)(`span`,{className:`font-medium`,children:`JSON`})]}),(0,L.jsx)(`div`,{className:`overflow-hidden rounded-lg border border-gray-600/30 bg-gray-900`,children:(0,L.jsx)(`pre`,{className:`overflow-x-auto p-4`,children:(0,L.jsx)(`code`,{className:`block whitespace-pre font-mono text-sm text-gray-200`,children:n})})})]})}catch{return null}}function i8(e){let t=!1,n=!1;for(let r of e)r?.type===`tool-call`&&(n=!0,r?.status?.type===`running`&&(t=!0));return t?`blink-green`:n?`green`:`gray`}function a8(){let e=Ny(e=>e.message.id),{toolProgressMap:t,taskMap:n,thinkingOpen:r,setThinkingOpen:i,retryLastUser:a,turnStatsByMessageId:o}=D6(),s=Ny(e=>e.message.content),c=Ny(e=>{let t=e.message.content;return Array.isArray(t)?t.filter(e=>e.type===`text`).map(e=>e.text??``).join(``):``}),l=Ny(e=>e.message.status?.type===`running`),u=Ny(e=>e.message.isLast),d=!l&&u&&!c.startsWith("```bash"),f=t8(e),p=o.get(e);if(!(Array.isArray(s)&&s.some(e=>e?.type===`text`&&(e.text??``).length>0||e?.type===`tool-call`||e?.type===`reasoning`||e?.type===`image`||e?.type===`file`)))return null;let m=Array.isArray(s)?i8(s):`gray`,h=(Array.isArray(s)?s.find(e=>e?.type===`text`||e?.type===`tool-call`):null)?.type===`text`?`top-[6px]`:`top-[17px]`,g=(0,L.jsx)(BC,{groupBy:e=>e.type===`reasoning`?[`group-pillRow`,`group-chainOfThought`,`group-reasoning`]:e.type===`tool-call`?[`group-pillRow`,`group-toolCalls`]:null,children:({part:e,children:a})=>{switch(e.type){case`group-pillRow`:return(0,L.jsx)(`div`,{className:`my-0.5 flex flex-wrap items-center gap-1`,children:a});case`group-chainOfThought`:return(0,L.jsx)(`div`,{"data-slot":`chain-of-thought`,className:`contents`,children:a});case`group-toolCalls`:return(0,L.jsx)(`div`,{className:`w-full space-y-1`,children:a});case`group-reasoning`:{let t=e.status.type===`running`,n=e.indices?.reduce((e,t)=>e+(s[t]?.text?.length??0),0)??0,o=n>0?`Thinking · ${n.toLocaleString()} chars`:`Thinking`;return(0,L.jsxs)(j0,{open:t?!0:r,onOpenChange:i,className:`group/think my-1 w-full overflow-hidden rounded-md border border-gray-100 bg-gray-50/50`,children:[(0,L.jsxs)(M0,{className:`flex w-full items-center gap-1.5 px-2 py-1 text-left text-xs transition-colors hover:bg-gray-100/50`,children:[(0,L.jsx)(ft,{className:`h-3 w-3 shrink-0 text-gray-400`}),(0,L.jsx)(`span`,{className:`text-gray-400`,children:o}),t&&(0,L.jsx)(`span`,{className:`shrink-0 rounded px-1 py-px text-[10px] font-medium text-gray-400`,children:`thinking`}),(0,L.jsx)(ht,{className:lh(`ml-auto h-3 w-3 shrink-0 text-gray-300 transition-transform`,(t||r)&&`rotate-180`)})]}),(0,L.jsx)(N0,{className:lh(`overflow-hidden`,`data-[state=open]:animate-collapsible-down`,`data-[state=closed]:animate-collapsible-up`),children:(0,L.jsx)(`div`,{className:`border-t border-gray-100 px-3 py-2`,children:(0,L.jsx)(`div`,{className:`max-h-64 overflow-y-auto text-[12px] text-gray-500 leading-relaxed`,children:a})})})]})}case`text`:{let e=r8({content:c});return e?(0,L.jsx)(`div`,{children:e}):(0,L.jsx)(y0,{})}case`reasoning`:return(0,L.jsx)(y0,{});case`tool-call`:{let r=e.args??{},i=e.result,a=e.status?.type??`complete`,o=e.toolCallId,s=e.toolName??`Unknown`,c=o?t.get(o):void 0,l=o?Array.from(n.values()).find(e=>e.tool_use_id===o):void 0;return(0,L.jsx)(e8,{name:`ToolRenderer:`+s,children:(0,L.jsx)($6,{toolName:s,args:r,result:i,status:a,elapsedSeconds:c?.elapsed_time_seconds,taskState:l,toolCallId:o})})}default:return null}}});return(0,L.jsxs)(eT,{"data-role":`assistant`,className:`group relative pl-6 md:pl-8`,children:[(0,L.jsx)(`div`,{className:`absolute left-[5px] -top-2 -bottom-2 w-[2px] bg-gray-200`}),(0,L.jsx)(`div`,{className:lh(`absolute left-[3px] z-10 h-[6px] w-[6px] rounded-full`,h,m===`gray`&&`bg-gray-300`,m===`green`&&`bg-green-500`,m===`blink-green`&&`animate-[blink-green_2s_ease-in-out_infinite]`)}),(0,L.jsx)(`div`,{className:`w-full text-[13px] md:text-sm text-gray-700`,children:g}),(f||d||p)&&(0,L.jsxs)(`div`,{className:`mt-1 flex items-center gap-2 text-[11px] text-gray-400`,children:[f&&(0,L.jsx)(`span`,{children:f}),d&&(0,L.jsx)(`button`,{type:`button`,onClick:a,"data-copy-ignore":``,"aria-label":`Retry`,className:`inline-flex h-5 w-5 items-center justify-center rounded text-gray-400 transition-all hover:bg-gray-100 hover:text-gray-600 select-none opacity-0 group-hover:opacity-100 focus-visible:opacity-100`,children:(0,L.jsx)(Cn,{className:`h-3 w-3`})}),p&&(0,L.jsx)(`span`,{className:`ml-auto tabular-nums select-none`,children:n8(p)})]})]})}var o8=[`Thinking`,`Processing`,`Analyzing`,`Working`,`Computing`,`Reasoning`];function s8(e){let t=Math.floor(e/60),n=e%60;return t<1?`${n}s`:`${t}m ${n}s`}function c8(e){return e<0&&(e=0),e<1e3?String(Math.round(e)):e<1e6?`${(e/1e3).toFixed(1)}k`:`${(e/1e6).toFixed(1)}M`}function l8({isLoading:e,getTokenCount:t,getWaitingForResponse:n}){let{thinkingBudget:r,turnGeneration:i,turnStartedAt:a}=D6(),[o,s]=(0,F.useState)(0),[c,l]=(0,F.useState)(0),[u,d]=(0,F.useState)(``);if((0,F.useEffect)(()=>{if(!e){s(0),l(0),d(``);return}let t=a??Date.now(),n=setInterval(()=>{s(Math.floor((Date.now()-t)/1e3))},250),r=setInterval(()=>{d(e=>e.length>=3?``:e+`.`)},400);return()=>{clearInterval(n),clearInterval(r)}},[e,i,a]),(0,F.useEffect)(()=>{if(!e)return;let n,r=()=>{let e=t();l(t=>{if(Math.abs(e-t)<.5)return e;let n=e-t,r=Math.max(1,Math.ceil(Math.abs(n)/8));return t+Math.sign(n)*Math.min(r,Math.abs(n))}),n=requestAnimationFrame(r)};return n=requestAnimationFrame(r),()=>cancelAnimationFrame(n)},[e,t]),!e)return null;let f=o8[Math.floor(o/3)%o8.length],p=n()?`↑`:`↓`,m=r===null?null:r>=32e3?`think-hard`:r>=16e3?`think`:null;return(0,L.jsxs)(`div`,{className:`relative mb-1.5 pl-6 md:pl-8`,children:[(0,L.jsx)(`div`,{className:`absolute left-[3px] top-1/2 -translate-y-1/2 z-10 h-[6px] w-[6px] animate-[morph_2s_ease-in-out_infinite] bg-blue-500 shadow-[0_0_6px_rgba(59,130,246,0.4)]`}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2 md:gap-3 text-xs text-gray-500 py-1`,children:[(0,L.jsxs)(`span`,{className:`font-medium text-gray-600`,children:[f,(0,L.jsx)(`span`,{className:`inline-block w-4 tabular-nums`,children:u})]}),m&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`span`,{className:`text-gray-300`,children:`·`}),(0,L.jsx)(`span`,{className:`rounded bg-blue-50 px-1.5 py-0.5 text-[10px] font-medium text-blue-600`,children:m})]}),(0,L.jsx)(`span`,{className:`tabular-nums text-gray-500 ml-auto mr-1`,children:s8(o)}),(0,L.jsxs)(`span`,{className:`tabular-nums text-gray-600 font-medium`,children:[p,c8(c),` tk`]})]})]})}function u8({...e}){return(0,L.jsx)($f,{"data-slot":`popover`,...e})}function d8({...e}){return(0,L.jsx)(ep,{"data-slot":`popover-trigger`,...e})}function f8({className:e,align:t=`center`,sideOffset:n=8,children:r,...i}){return(0,L.jsx)(tp,{children:(0,L.jsx)(np,{"data-slot":`popover-content`,align:t,sideOffset:n,className:lh(`z-50 w-72 rounded-xl border border-gray-200 bg-white p-0 shadow-xl outline-none`,`data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95`,`data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95`,`data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2`,`data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2`,e),...i,children:r})})}function p8({...e}){return(0,L.jsx)(rp,{"data-slot":`popover-close`,...e})}var m8=[{id:`bypassPermissions`,label:`YOLO`,description:`Sandboxed — safe to proceed freely`,icon:Yn,color:`text-green-600`,activeBg:`bg-green-50`,activeBorder:`border-green-200`,activeHover:`hover:bg-green-100`},{id:`auto`,label:`Auto`,description:`Fully automatic, minimal prompts`,icon:Nn,color:`text-amber-600`,activeBg:`bg-amber-50`,activeBorder:`border-amber-200`,activeHover:`hover:bg-amber-100`},{id:`dontAsk`,label:`Don't Ask`,description:`Skip most confirmations`,icon:Pt,color:`text-blue-600`,activeBg:`bg-blue-50`,activeBorder:`border-blue-200`,activeHover:`hover:bg-blue-100`},{id:`acceptEdits`,label:`Accept Edits`,description:`Auto-approve file edits, ask for rest`,icon:vn,color:`text-yellow-600`,activeBg:`bg-yellow-50`,activeBorder:`border-yellow-200`,activeHover:`hover:bg-yellow-100`},{id:`plan`,label:`Plan`,description:`Plan first, then implement step by step`,icon:Tt,color:`text-purple-600`,activeBg:`bg-purple-50`,activeBorder:`border-purple-200`,activeHover:`hover:bg-purple-100`},{id:`default`,label:`Default`,description:`Ask before each edit (safest)`,icon:jn,color:`text-gray-600`,activeBg:`bg-gray-50`,activeBorder:`border-gray-200`,activeHover:`hover:bg-gray-100`}];function Jre({mode:e,onChange:t,className:n=``}){let[r,i]=(0,F.useState)(!1),a=m8.find(t=>t.id===e)??m8[0],o=a.icon;return(0,L.jsxs)(u8,{open:r,onOpenChange:i,children:[(0,L.jsx)(d8,{asChild:!0,children:(0,L.jsxs)(`button`,{type:`button`,className:lh(`flex h-8 items-center gap-1 rounded-lg border px-1.5 text-[10px] transition-all`,e===`bypassPermissions`?`border-gray-200 bg-gray-50 text-gray-500 hover:bg-gray-100`:`${a.activeBorder} ${a.activeBg} ${a.color} ${a.activeHover}`,n),title:`Mode: ${a.label}`,"aria-label":`Select permission mode`,children:[(0,L.jsx)(o,{className:lh(`h-3 w-3`,a.color)}),(0,L.jsx)(`span`,{className:`hidden font-medium sm:inline`,children:a.label})]})}),(0,L.jsxs)(f8,{className:`w-56`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between border-b border-gray-200 p-3`,children:[(0,L.jsx)(`h3`,{className:`text-sm font-semibold text-gray-900`,children:`Permission Mode`}),(0,L.jsx)(p8,{asChild:!0,children:(0,L.jsx)(`button`,{type:`button`,className:`rounded p-1 hover:bg-gray-100`,"aria-label":`Close`,children:(0,L.jsx)(Jn,{className:`h-4 w-4 text-gray-500`})})})]}),(0,L.jsx)(`div`,{className:`py-1`,children:m8.map(n=>{let r=n.icon,a=n.id===e;return(0,L.jsx)(`button`,{type:`button`,onClick:()=>{t(n.id),i(!1)},className:lh(`w-full px-4 py-2.5 text-left transition-colors hover:bg-gray-50`,a&&`bg-gray-50`),children:(0,L.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,L.jsx)(r,{className:lh(`h-4 w-4`,n.color)}),(0,L.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,L.jsx)(`span`,{className:lh(`text-sm font-medium`,a?`text-gray-900`:`text-gray-700`),children:n.label}),a&&(0,L.jsx)(`span`,{className:`rounded bg-blue-100 px-1.5 py-0.5 text-[9px] text-blue-700`,children:`Active`})]}),(0,L.jsx)(`p`,{className:`text-xs text-gray-500`,children:n.description})]})]})},n.id)})})]})]})}function Yre(){let{provider:e,selectProvider:t,thinkingBlockCount:n,loopId:r}=D6(),[i,a]=(0,F.useState)(null),[o,s]=(0,F.useState)(!1),[c,l]=(0,F.useState)(``),[u,d]=(0,F.useState)(0),f=(0,F.useRef)(null),p=(0,F.useRef)(null);(0,F.useEffect)(()=>{gg().then(a)},[]);let m=e?.name||`default`,h=e?.model||``,g=(0,F.useMemo)(()=>{if(!i)return[];let e=[];for(let[t,n]of Object.entries(i.providers))if(!(n.enabled===!1||!n.hasKey))for(let r of n.models??[]){if(r.enabled===!1)continue;let i=c.toLowerCase().trim();i&&!r.id.toLowerCase().includes(i)&&!t.toLowerCase().includes(i)||e.push({provName:t,modelId:r.id,source:n.source})}return e},[i,c]);(0,F.useEffect)(()=>{d(0)},[c,o]),(0,F.useEffect)(()=>{p.current&&p.current.children[u]?.scrollIntoView({block:`nearest`})},[u]),(0,F.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&e.key===`k`&&(e.preventDefault(),s(e=>!e)),e.key===`Escape`&&o&&s(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[o]);let _=(0,F.useMemo)(()=>{let e=new Map;return g.forEach((t,n)=>{let r=e.get(t.provName)??{source:t.source,models:[]};r.models.push({modelId:t.modelId,idx:n}),e.set(t.provName,r)}),e},[g]),v=e=>e.toLowerCase().startsWith(`claude`),y=(0,F.useCallback)(async e=>{if(s(!1),!(e.provName===m&&e.modelId===h)){if(v(h)!==v(e.modelId)&&n>0&&r){let e=`Switching between Claude and non-Claude models makes the ${n} existing thinking block${n===1?``:`s`} in this conversation fail signature validation.\n\nClick OK to remove them from the AI's context (chat history stays). Cancel to keep the current provider.`;if(!window.confirm(e))return;await See(r)}t(e.provName,e.source,e.modelId)}},[m,h,n,r,t]);return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`button`,{type:`button`,onClick:()=>s(!0),className:`flex items-center gap-1 rounded-md border border-gray-200 bg-gray-50 px-1.5 py-0.5 text-[10px] text-gray-500 hover:bg-gray-100 transition-colors`,title:`Select model (Ctrl+K)`,"aria-label":`Select model`,children:[(0,L.jsx)(kt,{className:`h-3 w-3`}),(0,L.jsx)(`span`,{className:`font-medium text-gray-700 truncate max-w-16 md:max-w-24`,children:m}),h&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`span`,{className:`hidden md:inline text-gray-400`,children:`/`}),(0,L.jsx)(`span`,{className:`hidden md:inline font-mono truncate max-w-20`,children:h})]}),(0,L.jsx)(ht,{className:`h-2.5 w-2.5 text-gray-400`})]}),o&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/20`,onClick:()=>s(!1)}),(0,L.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-start justify-center pt-[15vh]`,onClick:()=>s(!1),children:(0,L.jsxs)(`div`,{className:`w-[480px] max-h-[60vh] bg-white rounded-xl shadow-2xl border border-gray-200 flex flex-col overflow-hidden`,onClick:e=>e.stopPropagation(),onKeyDown:e=>{e.key===`ArrowDown`?(e.preventDefault(),d(e=>Math.min(e+1,g.length-1))):e.key===`ArrowUp`?(e.preventDefault(),d(e=>Math.max(e-1,0))):e.key===`Enter`?(e.preventDefault(),g[u]&&y(g[u])):e.key===`Escape`&&s(!1)},children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-3 border-b border-gray-200 shrink-0`,children:[(0,L.jsx)(En,{className:`h-4 w-4 text-gray-400 shrink-0`}),(0,L.jsx)(`input`,{ref:f,autoFocus:!0,type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:`Search models...`,className:`flex-1 text-sm outline-none text-gray-900 placeholder:text-gray-400`}),(0,L.jsx)(`kbd`,{className:`hidden sm:inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] bg-gray-100 text-gray-400 font-mono`,children:`esc`})]}),(0,L.jsxs)(`div`,{ref:p,className:`flex-1 overflow-y-auto py-2`,role:`listbox`,children:[Array.from(_.entries()).map(([e,t])=>(0,L.jsxs)(`div`,{className:`mb-1`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-1.5 px-4 py-1`,children:[(0,L.jsx)(`span`,{className:`text-[11px] font-medium text-gray-500`,children:e}),(0,L.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 rounded px-1 py-0 text-[8px] font-medium ${t.source===`personal`?`bg-violet-100 text-violet-600`:`bg-gray-100 text-gray-400`}`,children:[t.source===`personal`?(0,L.jsx)(Gn,{className:`h-2 w-2`}):(0,L.jsx)(qt,{className:`h-2 w-2`}),t.source]})]}),t.models.map(t=>{let n=t.idx===u,r=e===m&&t.modelId===h;return(0,L.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":n,onClick:()=>y(g[t.idx]),onMouseEnter:()=>d(t.idx),className:`w-full px-6 py-1.5 text-left flex items-center gap-2 transition-colors ${n?`bg-blue-50`:``}`,children:[(0,L.jsx)(`span`,{className:`font-mono text-[12px] flex-1 truncate ${r?`text-blue-700 font-medium`:n?`text-gray-900`:`text-gray-600`}`,children:t.modelId}),r&&(0,L.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-blue-500 shrink-0`})]},t.modelId)})]},e)),g.length===0&&(0,L.jsx)(`div`,{className:`px-4 py-8 text-center text-sm text-gray-400`,children:c?`No models match your search`:`No models available`})]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-4 px-4 py-2 border-t border-gray-100 text-[10px] text-gray-400 shrink-0`,children:[(0,L.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,L.jsx)(ct,{className:`h-3 w-3`}),(0,L.jsx)(at,{className:`h-3 w-3`}),`navigate`]}),(0,L.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,L.jsx)(Ot,{className:`h-3 w-3`}),`select`]}),(0,L.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,L.jsx)(`kbd`,{className:`px-1 py-0.5 rounded bg-gray-100 font-mono text-[9px]`,children:`esc`}),`close`]})]})]})})]})]})}function Xre({onPick:e}){let{availableSlashCommands:t}=D6(),[n,r]=(0,F.useState)(!1),[i,a]=(0,F.useState)(``),[o,s]=(0,F.useState)(0),c=(0,F.useMemo)(()=>{let e=new Map;for(let n of t){let t=n.name.indexOf(`:`);if(t<0)continue;let r=n.name.slice(0,t),i=n.name.slice(t+1),a=e.get(r)??{plugin:r,skills:[]};a.skills.push({name:i,description:n.description}),e.set(r,a)}return[...e.values()].sort((e,t)=>e.plugin.localeCompare(t.plugin))},[t]),l=(0,F.useMemo)(()=>c.reduce((e,t)=>e+t.skills.length,0),[c]),u=(0,F.useMemo)(()=>{let e=i.toLowerCase().trim(),t=[];for(let n of c)for(let r of n.skills)e&&!`${n.plugin}:${r.name}`.toLowerCase().includes(e)&&!r.description.toLowerCase().includes(e)||t.push({plugin:n.plugin,skill:r.name,description:r.description});return t},[c,i]);if((0,F.useEffect)(()=>{s(0)},[i,n]),(0,F.useEffect)(()=>{if(!n)return;let e=e=>{e.key===`Escape`&&r(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]),l===0)return null;let d=(t,n)=>{r(!1),e(`/${t}:${n} `)};return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`button`,{type:`button`,onClick:()=>r(!0),className:`flex items-center gap-1 rounded-md border border-gray-200 bg-gray-50 px-1.5 py-0.5 text-[10px] text-gray-500 hover:bg-gray-100 transition-colors`,title:`${l} plugin skill${l===1?``:`s`} available`,"aria-label":`Show plugins`,children:[(0,L.jsx)(`span`,{className:`text-sm leading-none`,"aria-hidden":`true`,children:`🧩`}),(0,L.jsx)(`span`,{className:`font-medium text-gray-700`,children:l})]}),n&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/20`,onClick:()=>r(!1)}),(0,L.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-start justify-center pt-[15vh]`,onClick:()=>r(!1),children:(0,L.jsxs)(`div`,{className:`w-[560px] max-h-[60vh] bg-white rounded-xl shadow-2xl border border-gray-200 flex flex-col overflow-hidden`,onClick:e=>e.stopPropagation(),onKeyDown:e=>{if(e.key===`ArrowDown`)e.preventDefault(),s(e=>Math.min(e+1,u.length-1));else if(e.key===`ArrowUp`)e.preventDefault(),s(e=>Math.max(e-1,0));else if(e.key===`Enter`){e.preventDefault();let t=u[o];t&&d(t.plugin,t.skill)}},children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-3 border-b border-gray-200 shrink-0`,children:[(0,L.jsx)(En,{className:`h-4 w-4 text-gray-400 shrink-0`}),(0,L.jsx)(`input`,{autoFocus:!0,type:`text`,value:i,onChange:e=>a(e.target.value),placeholder:`Search plugins...`,className:`flex-1 text-sm outline-none text-gray-900 placeholder:text-gray-400`}),(0,L.jsxs)(`span`,{className:`text-[10px] text-gray-400`,children:[u.length,` / `,l]}),(0,L.jsx)(`kbd`,{className:`hidden sm:inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] bg-gray-100 text-gray-400 font-mono`,children:`esc`})]}),(0,L.jsxs)(`div`,{className:`flex-1 overflow-y-auto py-2`,role:`listbox`,children:[(()=>{let e=new Map;return u.forEach((t,n)=>{let r=e.get(t.plugin)??[];r.push({skill:t.skill,description:t.description,idx:n}),e.set(t.plugin,r)}),Array.from(e.entries()).map(([e,t])=>(0,L.jsxs)(`div`,{className:`mb-1`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-1.5 px-4 py-1`,children:[(0,L.jsx)(`span`,{className:`text-xs leading-none`,"aria-hidden":`true`,children:`🧩`}),(0,L.jsx)(`span`,{className:`text-[11px] font-medium text-gray-500`,children:e})]}),t.map(({skill:t,description:n,idx:r})=>{let i=r===o;return(0,L.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":i,onClick:()=>d(e,t),onMouseEnter:()=>s(r),className:`w-full px-6 py-1.5 text-left flex flex-col gap-0.5 transition-colors ${i?`bg-blue-50`:``}`,children:[(0,L.jsxs)(`span`,{className:`font-mono text-[12px] text-gray-900`,children:[`/`,e,`:`,t]}),n&&(0,L.jsx)(`span`,{className:`text-[11px] text-gray-500 line-clamp-2`,children:n})]},t)})]},e))})(),u.length===0&&(0,L.jsx)(`div`,{className:`px-4 py-8 text-center text-sm text-gray-400`,children:i?`No skills match your search`:`No plugins available`})]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-4 px-4 py-2 border-t border-gray-100 text-[10px] text-gray-400 shrink-0`,children:[(0,L.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,L.jsx)(ct,{className:`h-3 w-3`}),(0,L.jsx)(at,{className:`h-3 w-3`}),`navigate`]}),(0,L.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,L.jsx)(Ot,{className:`h-3 w-3`}),`insert`]}),(0,L.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,L.jsx)(`kbd`,{className:`px-1 py-0.5 rounded bg-gray-100 font-mono text-[9px]`,children:`esc`}),`close`]})]})]})})]})]})}function h8({onClose:e,loopId:t}){let[n,r]=(0,F.useState)([]),[i,a]=(0,F.useState)(!0),[o,s]=(0,F.useState)(null),[c,l]=(0,F.useState)(null),[u,d]=(0,F.useState)(null),f=(0,F.useCallback)(async()=>{a(!0),r((await c_(t)).servers),a(!1)},[t]);(0,F.useEffect)(()=>{f()},[f]);let p=async e=>{if(o)return;s(e),l(null);let n=await l_(e,t);if(s(null),n.error||!n.authorizationUrl){l(n.error??`start failed`);return}window.location.href=n.authorizationUrl},m=async e=>{o||(s(e),await u_(e),s(null),f())},h=async(e,n)=>{let r=await i_(e,n,t);return r.ok?(await f(),null):r.error};return(0,L.jsxs)(`div`,{className:`text-sm`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-gray-200`,children:[(0,L.jsx)(`div`,{className:`text-[13px] font-medium text-gray-700`,children:`MCP servers`}),(0,L.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,L.jsx)(`button`,{onClick:f,className:`p-1 text-gray-400 hover:text-gray-700 rounded`,title:`reload`,children:(0,L.jsx)(Sn,{size:12,className:i?`animate-spin`:``})}),(0,L.jsx)(`button`,{onClick:e,className:`p-1 text-gray-400 hover:text-gray-700 rounded`,title:`close`,children:(0,L.jsx)(Jn,{size:14})})]})]}),c&&(0,L.jsx)(`div`,{className:`mx-3 mt-3 rounded px-3 py-2 text-[12px] bg-red-50 text-red-800 border border-red-200`,children:c}),u&&(0,L.jsx)(`div`,{className:`mx-3 mt-3 rounded px-3 py-2 text-[12px] bg-blue-50 text-blue-800 border border-blue-200`,children:u}),(0,L.jsx)(`div`,{className:`max-h-[60vh] overflow-y-auto`,children:i&&n.length===0?(0,L.jsx)(`div`,{className:`px-3 py-4 text-[12px] text-gray-400`,children:`loading…`}):n.length===0?(0,L.jsxs)(`div`,{className:`px-3 py-4 text-[12px] text-gray-400 italic`,children:[`No MCP servers in this loop's merged settings.json. Add servers to team/personal/profile `,(0,L.jsx)(`code`,{className:`bg-gray-100 px-1 rounded font-mono text-[11px]`,children:`settings.json`}),`'s`,(0,L.jsx)(`code`,{className:`bg-gray-100 px-1 rounded font-mono text-[11px]`,children:`mcpServers`}),`.`]}):n.map(e=>(0,L.jsx)(Zre,{server:e,busy:o===e.name||e.authTokenEnv!==null&&o===e.authTokenEnv,onConnect:()=>p(e.name),onForget:e.authTokenEnv?()=>m(e.authTokenEnv):void 0,onParseSetup:t=>h(e.name,t)},e.name))}),(0,L.jsx)(`div`,{className:`border-t border-gray-200 px-3 py-2 flex items-center justify-end text-[11px]`,children:(0,L.jsxs)(`button`,{onClick:async()=>{d(null);let e=await d_(t);e.error?l(e.error):d(e.restarted?`Loop SDK session restarted. Send a message to re-spawn with new MCP tokens.`:`No active SDK session — next message will spawn fresh.`)},className:`text-gray-600 hover:text-gray-900 flex items-center gap-1`,title:`Restart the SDK session so newly-connected MCPs take effect. Conversation history is preserved.`,children:[(0,L.jsx)(wn,{size:10}),` Reload session`]})})]})}function Zre({server:e,busy:t,onConnect:n,onForget:r,onParseSetup:i}){let a=e.type===`http`||e.type===`sse`,o=a&&e.oauthSupport===`dcr`&&!!e.authTokenEnv,s=!!e.setupResource,[c,l]=(0,F.useState)(!1),[u,d]=(0,F.useState)(``),[f,p]=(0,F.useState)(!1),[m,h]=(0,F.useState)(null);return(0,L.jsxs)(`div`,{className:`border-b border-gray-50 last:border-0`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-1.5 hover:bg-gray-50`,children:[(0,L.jsx)(`span`,{className:`text-[14px] text-gray-300 leading-none`,children:e.authed?`●`:o?`○`:`·`}),(0,L.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,L.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,L.jsx)(`span`,{className:`font-medium text-gray-700 text-[13px]`,children:e.name}),(0,L.jsx)(`span`,{className:`text-[10px] text-gray-400 uppercase`,children:e.type})]}),e.url&&(0,L.jsx)(`div`,{className:`text-[11px] text-gray-400 font-mono truncate`,children:e.url})]}),(0,L.jsxs)(`div`,{className:`shrink-0 flex items-center gap-1`,children:[e.authed&&(0,L.jsxs)(`span`,{className:`text-[11px] text-green-700 inline-flex items-center gap-1`,children:[(0,L.jsx)(mt,{size:11}),` authed`]}),o&&(0,L.jsxs)(`button`,{onClick:n,disabled:t,className:`inline-flex items-center gap-1 text-[11px] px-2 h-6 rounded ${e.authed?`text-gray-600 hover:bg-gray-100 border border-gray-200`:`text-amber-700 bg-amber-50 hover:bg-amber-100 border border-amber-200`} disabled:opacity-50`,title:e.authed?`Re-run OAuth and overwrite the existing token`:`Run OAuth to obtain a token`,children:[e.authed?(0,L.jsx)(tn,{size:10}):(0,L.jsx)(Vn,{size:10}),t?`…`:e.authed?`re-auth`:`auth`]}),e.authed&&r&&(0,L.jsxs)(`button`,{onClick:r,disabled:t,className:`inline-flex items-center gap-1 text-[11px] px-1.5 h-6 rounded text-gray-500 hover:text-gray-900 hover:bg-gray-100 disabled:opacity-50`,title:`Delete the env file backing this server's token`,children:[(0,L.jsx)(Un,{size:10}),` forget`]}),s&&(0,L.jsxs)(`button`,{onClick:()=>l(e=>!e),className:`inline-flex items-center gap-1 text-[11px] px-2 h-6 rounded ${e.authed?`text-gray-600 hover:bg-gray-100 border border-gray-200`:`text-amber-700 bg-amber-50 hover:bg-amber-100 border border-amber-200`}`,title:`Paste your MCP URL from the provider's page to set this server's secrets`,children:[(0,L.jsx)($t,{size:10}),e.authed?`re-setup`:`setup`]}),!s&&!o&&!e.authed&&a&&(e.oauthSupport===`manual`?(0,L.jsx)(`span`,{className:`text-[11px] text-gray-500 italic`,title:`This provider requires admin to register an OAuth app (no DCR). Loopat doesn't support manual client_id setup.`,children:`manual setup`}):e.oauthSupport===`none`?(0,L.jsx)(`span`,{className:`text-[11px] text-gray-400`,title:`No OAuth metadata — server is public or uses non-OAuth auth (e.g. API key).`,children:`no oauth`}):e.oauthSupport===`unreachable`?(0,L.jsx)(`span`,{className:`text-[11px] text-red-500`,title:`Probe failed — server unreachable or returned malformed metadata.`,children:`unreachable`}):e.authTokenEnv===null?(0,L.jsx)(`span`,{className:`text-[11px] text-gray-400 italic`,title:"No Bearer ${VAR} template in Authorization header — loopat can't determine which env to write.",children:`no bearer template`}):null),!a&&(0,L.jsx)(`span`,{className:`text-[11px] text-gray-400`,children:`stdio`})]})]}),c&&s&&(0,L.jsxs)(`div`,{className:`px-3 pb-2.5 pt-0.5 bg-gray-50/60`,children:[(0,L.jsxs)(`div`,{className:`text-[11px] text-gray-500 mb-1.5`,children:[`到`,` `,(0,L.jsxs)(`a`,{href:e.setupResource,target:`_blank`,rel:`noreferrer`,className:`text-blue-600 hover:text-blue-800 inline-flex items-center gap-0.5`,children:[`这个页面 `,(0,L.jsx)(Mt,{size:9})]}),` `,`复制你的 MCP URL,粘贴到下面 —— 会自动解析出`,` `,(e.requiredEnvs??[]).join(`、`)||`所需密钥`,` 并存进你的 vault。`]}),(0,L.jsx)(`textarea`,{value:u,onChange:e=>d(e.target.value),placeholder:`https://…?key=…`,rows:2,spellCheck:!1,className:`w-full px-2 py-1 rounded border border-gray-300 text-[11px] font-mono focus:outline-none focus:border-gray-500 resize-none`}),m&&(0,L.jsx)(`div`,{className:`text-[11px] text-red-600 mt-1`,children:m}),(0,L.jsxs)(`div`,{className:`mt-1.5 flex items-center gap-2`,children:[(0,L.jsx)(`button`,{onClick:async()=>{p(!0),h(null);let e=await i(u.trim());p(!1),e?h(e):(l(!1),d(``))},disabled:!u.trim()||f,className:`text-[11px] px-2.5 h-6 rounded bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-40`,children:f?`解析中…`:`解析并保存`}),(0,L.jsx)(`button`,{onClick:()=>{l(!1),d(``),h(null)},className:`text-[11px] text-gray-500 hover:text-gray-800`,children:`取消`})]})]})]})}var g8=[{id:`think`,name:`Think`,description:`Extended thinking (16k token budget)`,icon:ft,group:`quick`,action:`command`,prefix:``,commandKey:`setMaxThinkingTokens`,tokens:16e3},{id:`think-hard`,name:`Think Hard`,description:`Deep thinking (32k token budget)`,icon:Yn,group:`quick`,action:`command`,prefix:``,commandKey:`setMaxThinkingTokens`,tokens:32e3},{id:`ultrathink`,name:`Ultrathink`,description:`Maximum thinking (no budget limit)`,icon:Nn,group:`quick`,action:`command`,prefix:``,commandKey:`setMaxThinkingTokens`,tokens:null},{id:`plan`,name:`Permission`,description:`Cycle permission mode`,icon:Tn,group:`quick`,action:`toggle`,prefix:``,toggleKey:`permissionMode`},{id:`goal`,name:`Goal`,description:`Set goal (/goal <text>), mark done (/goal done), clear (/goal clear)`,icon:Ln,group:`quick`,action:`agent`,prefix:``},{id:`usage`,name:`Context Usage`,description:`Show context window token usage`,icon:pt,group:`quick`,action:`command`,prefix:``,commandKey:`getContextUsage`},{id:`clear`,name:`Clear Context`,description:`Reset AI conversation (history kept)`,icon:jt,group:`quick`,action:`command`,prefix:``,commandKey:`clearContext`},{id:`mcp`,name:`MCP Servers`,description:`Show MCP servers + tools available to this loop`,icon:mn,group:`quick`,action:`command`,prefix:``,commandKey:`openMcpPanel`}],Qre=[{id:`quick`,label:`Quick actions`},{id:`plugin`,label:`Plugin commands`},{id:`skill`,label:`Skills`}],$re=new Set(g8.map(e=>e.id));function eie(){let e=Ny(e=>e.composer.text),t=nw(),{permissionMode:n,setPermissionMode:r,clearContext:i,setMaxThinkingTokens:a,getContextUsage:o,availableSlashCommands:s,suppressSlashRef:c,loopId:l}=D6(),[u,d]=(0,F.useState)(!1),[f,p]=(0,F.useState)(0),[m,h]=(0,F.useState)(``),[g,_]=(0,F.useState)(!1),v=(0,F.useRef)(null),y=(0,F.useMemo)(()=>{let e=s.filter(e=>!$re.has(e.name)).map(e=>{let t=e.name.includes(`:`),n=t?e.name.split(`:`,1)[0]:void 0;return{id:e.name,name:e.name,description:e.description||(t?`from ${n} plugin`:`skill`),icon:t?xn:Rn,group:t?`plugin`:`skill`,action:`agent`,prefix:``,pluginName:n}});return[...g8,...e]},[s]),b=typeof e==`string`?e.trimStart():e,x=typeof b==`string`&&b.startsWith(`/`)&&!b.includes(` `);x&&c.current&&(x=!1);let S=x?b.slice(1).toLowerCase():``,C=(0,F.useMemo)(()=>y.filter(e=>!S||e.id.toLowerCase().includes(S)||e.name.toLowerCase().includes(S)),[y,S]),w=(0,F.useMemo)(()=>{let e={quick:0,plugin:1,skill:2};return[...C].sort((t,n)=>t.group===n.group?t.group===`plugin`&&t.pluginName!==n.pluginName?(t.pluginName??``).localeCompare(n.pluginName??``):t.id.localeCompare(n.id):e[t.group]-e[n.group])},[C]),T=(0,F.useMemo)(()=>{let e=new Map;for(let t of w){let n=e.get(t.group)??[];n.push(t),e.set(t.group,n)}return e},[w]);(0,F.useEffect)(()=>{x?(d(!0),h(S),p(0)):d(!1)},[x,S]);let E=(0,F.useCallback)(e=>{if(e.action===`toggle`&&e.toggleKey===`permissionMode`){let e=[`bypassPermissions`,`auto`,`dontAsk`,`acceptEdits`,`plan`,`default`],i=e[(e.indexOf(n)+1)%e.length];r(i),t.setText(``)}else e.action===`command`?e.commandKey===`clearContext`?(i(),t.setText(``)):e.commandKey===`setMaxThinkingTokens`?(a(e.tokens??null),t.setText(``)):e.commandKey===`getContextUsage`?(o(),t.setText(``)):e.commandKey===`openMcpPanel`&&(_(!0),t.setText(``)):e.action===`agent`&&t.setText(`/${e.id} `);d(!1)},[t,n,r,i,a,o]);(0,F.useEffect)(()=>{if(!u)return;let e=e=>{e.key===`ArrowDown`?(e.preventDefault(),e.stopImmediatePropagation(),p(e=>Math.min(e+1,w.length-1))):e.key===`ArrowUp`?(e.preventDefault(),e.stopImmediatePropagation(),p(e=>Math.max(e-1,0))):e.key===`Enter`&&w.length>0?(e.preventDefault(),e.stopImmediatePropagation(),E(w[f])):e.key===`Escape`&&(e.preventDefault(),e.stopImmediatePropagation(),t.setText(``))};return window.addEventListener(`keydown`,e,{capture:!0}),()=>window.removeEventListener(`keydown`,e,{capture:!0})},[u,w,f,t,E]),(0,F.useEffect)(()=>{if(!v.current)return;let e=v.current.querySelector(`[data-slash-idx="${f}"]`);e&&e.scrollIntoView({block:`nearest`})},[f]);let D=-1;return g&&(!u||w.length===0)?(0,L.jsx)(`div`,{className:`relative`,children:(0,L.jsx)(`div`,{className:`absolute bottom-0 left-0 mb-1 w-[28rem] rounded-lg border border-gray-200 bg-white shadow-lg z-20`,children:(0,L.jsx)(h8,{onClose:()=>_(!1),loopId:l})})}):!u||w.length===0?null:(0,L.jsxs)(`div`,{className:`relative`,children:[g&&(0,L.jsx)(`div`,{className:`absolute bottom-0 left-0 mb-1 w-[28rem] rounded-lg border border-gray-200 bg-white shadow-lg z-30`,children:(0,L.jsx)(h8,{onClose:()=>_(!1),loopId:l})}),(0,L.jsx)(`div`,{className:`absolute bottom-0 left-0 mb-1 w-72 rounded-lg border border-gray-200 bg-white shadow-lg z-20`,children:(0,L.jsx)(`div`,{ref:v,className:`max-h-72 overflow-y-auto py-1`,children:Qre.map(e=>{let t=T.get(e.id);return!t||t.length===0?null:(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`div`,{className:`px-3 pt-2 pb-1`,children:(0,L.jsx)(`p`,{className:`text-[10px] font-medium text-gray-400 uppercase tracking-wider`,children:e.label})}),t.map(e=>{D+=1;let t=D,r=e.icon,i=t===f,a=e.toggleKey===`permissionMode`&&n!==`bypassPermissions`||e.isActive;return(0,L.jsxs)(`button`,{type:`button`,"data-slash-idx":t,onMouseEnter:()=>p(t),onMouseDown:t=>{t.preventDefault(),E(e)},className:`w-full flex items-center gap-2.5 px-3 py-1.5 text-left transition-colors ${i?`bg-blue-50`:`hover:bg-gray-50`}`,children:[(0,L.jsx)(r,{className:`h-4 w-4 flex-shrink-0 ${a?`text-blue-600`:`text-gray-400`}`}),(0,L.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,L.jsxs)(`span`,{className:`text-sm font-medium text-gray-700`,children:[`/`,e.id]}),e.action===`toggle`&&a&&(0,L.jsx)(`span`,{className:`rounded bg-blue-100 px-1 py-0.5 text-[9px] text-blue-600`,children:`ON`})]}),(0,L.jsx)(`p`,{className:`text-xs text-gray-500 truncate`,children:e.description})]})]},e.id)})]},e.id)})})})]})}function tie({used:e,total:t}){if(!t||t<=0)return null;let n=Math.min(100,e/t*100),r=2*Math.PI*10,i=r-n/100*r;return(0,L.jsxs)(dh,{children:[(0,L.jsx)(fh,{asChild:!0,children:(0,L.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs text-gray-500`,children:[(0,L.jsxs)(`svg`,{width:`24`,height:`24`,viewBox:`0 0 24 24`,className:`-rotate-90 transform`,children:[(0,L.jsx)(`circle`,{cx:`12`,cy:`12`,r:10,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,className:`text-gray-300`}),(0,L.jsx)(`circle`,{cx:`12`,cy:`12`,r:10,fill:`none`,stroke:n<50?`var(--color-blue-500)`:n<75?`var(--color-amber-500)`:`var(--color-red-500)`,strokeWidth:`2`,strokeDasharray:r,strokeDashoffset:i,strokeLinecap:`round`})]}),(0,L.jsxs)(`span`,{children:[n.toFixed(0),`%`]})]})}),(0,L.jsx)(ph,{children:(0,L.jsx)(`div`,{className:`text-xs`,children:(0,L.jsxs)(`p`,{children:[e.toLocaleString(),` / `,t.toLocaleString(),` tokens`]})})})]})}function nie({loopId:e,onPick:t,onClose:n}){let[r,i]=(0,F.useState)([]),[a,o]=(0,F.useState)([]),[s,c]=(0,F.useState)(!0),[l,u]=(0,F.useState)(``),[d,f]=(0,F.useState)(0),[p,m]=(0,F.useState)(new Set),[h,g]=(0,F.useState)({}),_=(0,F.useRef)(null),v=(0,F.useRef)(null);(0,F.useEffect)(()=>{c(!0),Promise.all([Ph(e,`workdir`).catch(()=>[]),Fh(e,`workdir`).catch(()=>[])]).then(([e,t])=>{i(e),o(t),c(!1)})},[e]);let y=l.trim().length>0,b=(0,F.useMemo)(()=>{let e=l.trim().toLowerCase();return e?a.filter(t=>t.type===`file`&&(t.path.toLowerCase().includes(e)||t.name.toLowerCase().includes(e))):[]},[a,l]),x=(0,F.useMemo)(()=>{if(y)return[];let e=[];function t(n,r){for(let i of n)e.push({entry:i,depth:r}),i.type===`dir`&&p.has(i.path)&&h[i.path]&&t(h[i.path],r+1)}return t(r,0),e},[r,y,p,h]);(0,F.useEffect)(()=>{f(0)},[l]),(0,F.useEffect)(()=>{v.current&&v.current.children[d]?.scrollIntoView({block:`nearest`})},[d]);let S=(0,F.useCallback)(async t=>{if(p.has(t.path))m(e=>{let n=new Set(e);return n.delete(t.path),n});else{if(!h[t.path]){let n=await Ph(e,t.path).catch(()=>[]);g(e=>({...e,[t.path]:n}))}m(e=>new Set(e).add(t.path))}},[p,h,e]),C=(0,F.useCallback)(e=>{if(e.type===`dir`){S(e);return}t(e.path)},[S,t]);return(0,vo.createPortal)((0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/20`,onClick:n}),(0,L.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-start justify-center pt-[15vh]`,onClick:n,children:(0,L.jsxs)(`div`,{className:`w-[420px] max-w-[calc(100vw-2rem)] max-h-[60vh] bg-white rounded-xl shadow-2xl border border-gray-200 flex flex-col overflow-hidden`,onClick:e=>e.stopPropagation(),onKeyDown:e=>{if(e.key===`Escape`){e.preventDefault(),n();return}if(y)e.key===`ArrowDown`?(e.preventDefault(),f(e=>Math.min(e+1,b.length-1))):e.key===`ArrowUp`?(e.preventDefault(),f(e=>Math.max(e-1,0))):e.key===`Enter`&&(e.preventDefault(),b[d]&&t(b[d].path));else if(e.key===`ArrowDown`)e.preventDefault(),f(e=>Math.min(e+1,x.length-1));else if(e.key===`ArrowUp`)e.preventDefault(),f(e=>Math.max(e-1,0));else if(e.key===`ArrowRight`||e.key===`ArrowLeft`){e.preventDefault();let t=x[d];if(!t||t.entry.type!==`dir`)return;let n=p.has(t.entry.path);(e.key===`ArrowRight`&&!n||e.key===`ArrowLeft`&&n)&&S(t.entry)}else e.key===`Enter`&&(e.preventDefault(),x[d]&&C(x[d].entry))},children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-3 border-b border-gray-200 shrink-0`,children:[(0,L.jsx)(En,{className:`h-4 w-4 text-gray-400 shrink-0`}),(0,L.jsx)(`input`,{ref:_,autoFocus:!0,type:`text`,value:l,onChange:e=>u(e.target.value),placeholder:`Search files...`,className:`flex-1 text-sm outline-none text-gray-900 placeholder:text-gray-400`})]}),(0,L.jsx)(`div`,{ref:v,className:`flex-1 overflow-y-auto py-2`,role:`listbox`,children:s?(0,L.jsx)(`div`,{className:`px-4 py-8 text-center text-sm text-gray-400`,children:`Loading...`}):y?b.length===0?(0,L.jsx)(`div`,{className:`px-4 py-8 text-center text-sm text-gray-400`,children:`No files match your search`}):b.map((e,n)=>(0,L.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":n===d,onClick:()=>t(e.path),onMouseEnter:()=>f(n),className:lh(`w-full px-6 py-1.5 text-left flex items-center gap-2 transition-colors text-[12px]`,n===d&&`bg-blue-50`),children:[(0,L.jsx)(Rt,{size:12,className:`text-blue-400 shrink-0`}),(0,L.jsx)(`span`,{className:`truncate font-mono text-gray-700`,children:e.path})]},e.path)):r.length===0?(0,L.jsx)(`div`,{className:`px-4 py-8 text-center text-sm text-gray-400`,children:`No files found`}):x.map(({entry:e,depth:t},n)=>{let r=e.type===`dir`,i=p.has(e.path);return(0,L.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":n===d,onClick:()=>C(e),onMouseEnter:()=>f(n),className:lh(`w-full text-left flex items-center gap-1.5 px-2 py-1 text-[12px] transition-colors`,n===d&&`bg-blue-50`),style:{paddingLeft:12+t*16},children:[r?(0,L.jsxs)(L.Fragment,{children:[i?(0,L.jsx)(ht,{size:11,className:`text-gray-300 shrink-0`}):(0,L.jsx)(gt,{size:11,className:`text-gray-300 shrink-0`}),(0,L.jsx)(Ht,{size:13,className:`text-amber-500 shrink-0`})]}):(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`span`,{className:`w-[11px] shrink-0`}),(0,L.jsx)(Rt,{size:13,className:`text-blue-400 shrink-0`})]}),(0,L.jsx)(`span`,{className:`truncate`,children:e.name})]},e.path)})}),(0,L.jsxs)(`div`,{className:`flex items-center gap-4 px-4 py-2 border-t border-gray-100 text-[10px] text-gray-400 shrink-0`,children:[(0,L.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,L.jsx)(ct,{className:`h-3 w-3`}),(0,L.jsx)(at,{className:`h-3 w-3`}),`navigate`]}),(0,L.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,L.jsx)(Ot,{className:`h-3 w-3`}),`select`]}),(0,L.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,L.jsx)(`kbd`,{className:`px-1 py-0.5 rounded bg-gray-100 font-mono text-[9px]`,children:`esc`}),`close`]})]})]})})]}),document.body)}var rie=2e5,_8=500;function iie({pickedFile:e,editorSelection:t}){let n=Ny(e=>e.thread.isRunning),r=Ny(e=>typeof e.composer.text==`string`&&e.composer.text.trim().length>0),i=Ny(e=>e.composer.text),{provider:a,permissionMode:o,setPermissionMode:s,enqueueMessage:c,queue:l,clearQueue:u,removeFromQueue:d,loopId:f,contextTokens:p,cumulativeTokens:m,getStreamingTokenCount:h,getWaitingForResponse:g,suppressSlashRef:_,goal:v,setGoal:y,goalStatus:b,completeGoal:x,backgroundTasks:S}=D6(),C=a?.contextWindow??rie,w=My(),[T,E]=(0,F.useState)(!1),[D,O]=(0,F.useState)([]),[k,A]=(0,F.useState)(!1),ee=[...T&&e?[e]:[],...D],j=()=>E(e=>!e),te=e=>{O(t=>t.includes(e)?t:[...t,e]),A(!1)},M=e=>{O(t=>t.filter(t=>t!==e))},ne=e=>{let t=e.lastIndexOf(`/`);return t>=0?e.slice(t+1):e},N=(0,F.useRef)(``),re=(0,F.useRef)([]),[ie,ae]=(0,F.useState)(!1);(0,F.useEffect)(()=>{let n=!1;async function r(){if(ee.length===0){N.current=``,re.current=[];return}ae(!0);let r=[],i=[];for(let a of ee){if(n)return;try{let n=await Ih(f,a);if(n&&n.content){let o=a.includes(`.`)?a.split(`.`).pop()??``:``,s=a===e?t:null,c=n.content,l=a;if(s){let e=n.content.split(`
395
395
  `),t=Math.max(0,s.from-1),r=Math.min(e.length,s.to);c=e.slice(t,r).join(`
396
396
  `),l=`${a} (${s.from}-${s.to})`}let u=c.replace(/```/g,"``​`");r.push(`\n# File: ${l}\n\`\`\`${o}\n${u}\n\`\`\`\n`),i.push({path:l,content:c})}}catch{}}n||(N.current=r.join(``),re.current=i,ae(!1))}return r(),()=>{n=!0}},[ee.join(`,`),f,e,t?.from,t?.to]);let oe=e=>{let t=N.current;return t?`${t}\n${e}`:e},[se,ce]=(0,F.useState)([]),[le,ue]=(0,F.useState)(-1),de=(0,F.useRef)(``),fe=(0,F.useRef)(``);fe.current=typeof i==`string`?i:``,(0,F.useEffect)(()=>{f&&tg(f).then(e=>{ce(e),ue(-1)})},[f]);let pe=e=>{if(!e.trim()||!f)return;let t=e.trim();ce(e=>{if(e[e.length-1]===t)return e;let n=[...e,t];return n.length>_8&&n.splice(0,n.length-_8),n}),ue(-1),ng(f,t).catch(()=>{})},me=()=>{let e=typeof i==`string`?i.trim():``;if(e){if(pe(e),N.current)try{sessionStorage.setItem(`loopat:pendingFileContext`,N.current)}catch{}c(oe(e)),w.composer().setText(``)}};return(0,L.jsxs)(xw,{className:`relative flex w-full flex-col`,onSubmit:()=>{let e=fe.current.trim();if(e&&(pe(e),N.current))try{sessionStorage.setItem(`loopat:pendingFileContext`,N.current)}catch{}},children:[(0,L.jsx)(l8,{isLoading:n,getTokenCount:h,getWaitingForResponse:g}),l.length>0&&(0,L.jsx)(`div`,{className:`mb-1.5 space-y-1 px-2`,children:l.map((e,t)=>(0,L.jsxs)(`div`,{className:`flex items-center justify-between gap-2 bg-gray-50 border border-gray-200 rounded-md px-2.5 py-1.5`,children:[(0,L.jsxs)(`span`,{className:`text-xs text-gray-600 line-clamp-3 break-words whitespace-pre-wrap min-w-0`,children:[(0,L.jsxs)(`span`,{className:`text-gray-400 mr-1.5 shrink-0`,children:[t+1,`.`]}),e]}),(0,L.jsx)(`button`,{onClick:()=>d(t),className:`text-gray-400 hover:text-gray-600 shrink-0 p-0.5 rounded hover:bg-gray-100 transition-colors`,title:`Remove from queue`,children:(0,L.jsx)(Jn,{className:`h-3.5 w-3.5`})})]},t))}),ee.length>0&&(0,L.jsxs)(`div`,{className:`flex items-center gap-1.5 px-1 mb-1 flex-wrap`,children:[ee.map(n=>(0,L.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-blue-200 bg-blue-50 px-2 py-0.5 text-[11px] text-blue-700`,children:[(0,L.jsx)(Rt,{size:11,className:`shrink-0`}),(0,L.jsx)(`span`,{className:`truncate max-w-[160px]`,children:ne(n)}),n!==e&&(0,L.jsx)(`button`,{onClick:()=>M(n),className:`ml-0.5 hover:text-blue-900`,children:(0,L.jsx)(Jn,{size:11})}),n===e&&T&&(0,L.jsx)(`span`,{className:`text-[9px] text-blue-400 ml-0.5`,children:t?`(${t.from}-${t.to})`:`editor`})]},n)),ie&&(0,L.jsx)(`span`,{className:`text-[10px] text-gray-400`,children:`loading...`})]}),v&&(0,L.jsxs)(`div`,{className:`mb-1.5 flex items-center gap-2 px-2 py-1.5 rounded-lg border group ${b===`completed`?`border-green-200 bg-green-50`:`border-amber-200 bg-amber-50`}`,children:[b===`completed`?(0,L.jsx)(xt,{className:`h-3.5 w-3.5 text-green-600 shrink-0`}):(0,L.jsx)(Ln,{className:`h-3.5 w-3.5 text-amber-600 shrink-0`}),(0,L.jsx)(`span`,{className:`text-xs font-medium truncate flex-1 min-w-0 ${b===`completed`?`text-green-800 line-through`:`text-amber-800`}`,children:v}),b===`active`&&(0,L.jsx)(`button`,{onClick:()=>x?.(),className:`shrink-0 px-1.5 py-0.5 rounded text-[10px] font-medium text-amber-700 hover:bg-amber-200 opacity-0 group-hover:opacity-100 transition-opacity`,title:`Mark goal as complete`,children:`Done`}),(0,L.jsx)(`button`,{onClick:()=>y?.(null),className:`shrink-0 p-0.5 rounded hover:bg-amber-200/50 opacity-0 group-hover:opacity-100 transition-opacity`,title:`Clear goal`,children:(0,L.jsx)(Jn,{className:`h-3 w-3 ${b===`completed`?`text-green-500`:`text-amber-600`}`})})]}),(0,L.jsxs)(`div`,{"data-slot":`composer-shell`,className:`flex w-full flex-col gap-2 rounded-2xl border border-gray-200 bg-white p-2.5 shadow-sm`,children:[(0,L.jsx)(eie,{}),(0,L.jsx)(Vw,{placeholder:`Send a message...`,className:`max-h-32 min-h-10 w-full resize-none bg-transparent px-1.5 py-1 text-sm text-gray-900 outline-none placeholder:text-gray-400`,rows:1,autoFocus:!0,"aria-label":`Message input`,onKeyDown:e=>{if(!(e.nativeEvent.isComposing||e.keyCode===229)){if(e.key===`c`&&e.ctrlKey&&!e.altKey&&!e.metaKey&&!e.shiftKey&&!/windows/i.test(navigator.userAgent)){let t=e.target;if(t.selectionStart===t.selectionEnd&&fe.current.trim().length>0){e.preventDefault(),w.composer().setText(``);return}}if(e.key!==`ArrowUp`&&e.key!==`ArrowDown`&&(_.current=!1),e.key===`Enter`&&!e.nativeEvent.isComposing&&!e.shiftKey&&n){e.preventDefault(),me();return}if(e.key===`ArrowUp`&&!e.shiftKey&&!e.altKey&&!e.metaKey&&!e.ctrlKey){if(se.length===0)return;if(e.preventDefault(),_.current=!0,le===-1)de.current=fe.current,ue(se.length-1),w.composer().setText(se[se.length-1]);else if(le>0){let e=le-1;ue(e),w.composer().setText(se[e])}return}if(e.key===`ArrowDown`&&!e.shiftKey&&!e.altKey&&!e.metaKey&&!e.ctrlKey){if(le===-1)return;if(e.preventDefault(),_.current=!0,le<se.length-1){let e=le+1;ue(e),w.composer().setText(se[e])}else ue(-1),w.composer().setText(de.current);return}}}}),(0,L.jsxs)(`div`,{className:`flex items-center justify-between gap-0.5 border-t border-gray-100 pt-2 overflow-hidden`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-0.5 min-w-0`,children:[(0,L.jsx)(tie,{used:Math.min(p,C),total:C}),(0,L.jsx)(Yre,{}),(0,L.jsx)(Xre,{onPick:e=>{let t=fe.current,n=t.length===0||t.endsWith(` `)?`${t}${e}`:`${t} ${e}`;w.composer().setText(n)}}),e&&(0,L.jsxs)(`button`,{type:`button`,onClick:j,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] transition-colors ${T?`bg-blue-50 text-blue-600 border border-blue-200`:`text-gray-400 hover:text-gray-600 hover:bg-gray-100`}`,title:T?`Remove editor file from context`:`Include editor file in context`,children:[(0,L.jsx)(Rt,{size:12}),ne(e)]}),(0,L.jsx)(`button`,{type:`button`,onClick:()=>A(e=>!e),className:`inline-flex items-center justify-center rounded-md border border-gray-200 bg-gray-50 w-[21px] h-[21px] mt-px text-gray-500 hover:bg-gray-100 transition-colors`,title:`Add file to context`,children:(0,L.jsx)(Lt,{size:12})}),k&&(0,L.jsx)(nie,{loopId:f,onPick:te,onClose:()=>A(!1)})]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-1 sm:gap-2 shrink-0`,children:[(0,L.jsx)(Jre,{mode:o,onChange:s}),r&&(n?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(N_,{type:`button`,variant:`default`,size:`icon`,onClick:()=>{me(),S()},className:`h-8 w-8 rounded-lg bg-sky-500 hover:bg-sky-600 text-white`,"aria-label":`Send now (background agents)`,title:`立即发送(后台暂停 agents)`,children:(0,L.jsx)(Yn,{className:`h-4 w-4`})}),(0,L.jsx)(N_,{type:`button`,variant:`default`,size:`icon`,onClick:me,className:`h-8 w-8 rounded-lg bg-amber-500 hover:bg-amber-600 text-white`,"aria-label":`Enqueue message`,title:`Enqueue message`,children:(0,L.jsx)(rn,{className:`h-4 w-4`})})]}):(0,L.jsx)(bw,{asChild:!0,children:(0,L.jsx)(N_,{type:`button`,variant:`default`,size:`icon`,className:`h-8 w-8 rounded-lg bg-gray-800 hover:bg-gray-900 text-white`,"aria-label":`Send message`,children:(0,L.jsx)(ct,{className:`h-4 w-4`})})})),(0,L.jsx)(Ly,{condition:e=>e.thread.isRunning,children:(0,L.jsx)(_te,{asChild:!0,children:(0,L.jsx)(N_,{type:`button`,variant:`default`,size:`icon`,className:`h-8 w-8 rounded-lg bg-red-500 hover:bg-red-600 text-white`,"aria-label":`Stop generating`,children:(0,L.jsx)(Pn,{className:`h-3 w-3 fill-current`})})})})]})]})]})]})}function aie({questions:e,toolUseId:t,onAnswers:n,onDismiss:r,disabled:i=!1}){let[a,o]=(0,F.useState)({}),[s,c]=(0,F.useState)({}),[l,u]=(0,F.useState)(!1),[d,f]=(0,F.useState)(0),p=Array.isArray(e)?e.filter(e=>e!=null&&typeof e.question==`string`&&e.question.length>0&&Array.isArray(e.options)):[];if(p.length===0)return null;let m=(e,t)=>{i||l||(c(t=>{if(!t[e])return t;let n={...t};return delete n[e],n}),o(n=>({...n,[e]:t})))},h=(e,t)=>{i||l||(c(t=>{if(!t[e])return t;let n={...t};return delete n[e],n}),o(n=>{let r=(n[e]??``).split(`,`).filter(Boolean),i=r.indexOf(t);return i>=0?r.splice(i,1):r.push(t),{...n,[e]:r.join(`,`)}}))},g=(e,t)=>{i||l||(c(n=>({...n,[e]:t})),o(t=>{if(!t[e])return t;let n={...t};return delete n[e],n}))},_=e=>s[e.question]?.trim()||a[e.question]||``,v=p.every(e=>{let t=_(e);return t!==void 0&&t!==``}),y=e=>{let t=_(e);return t!==void 0&&t!==``},b=()=>{if(!v||!t||!n||l)return;u(!0);let e={};for(let t of p)e[t.question]=_(t);n(t,e)},x=()=>{i||l||(u(!0),r?.(t||``))},S=()=>{f(e=>Math.min(e+1,p.length-1))},C=(e,t)=>e.header?e.header:`Question ${t+1}`,w=p[d],T=a[w.question]??``,E=new Set(T.split(`,`).filter(Boolean)),D=Array.isArray(w.options)?w.options:[],O=s[w.question]??``;return(0,L.jsxs)(`div`,{className:`space-y-3`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] text-violet-600 font-medium`,children:[(0,L.jsx)(St,{className:`h-3.5 w-3.5`}),(0,L.jsx)(`span`,{children:p.length>1?`Question ${d+1} of ${p.length}`:`Question`})]}),(0,L.jsx)(`button`,{type:`button`,onClick:x,disabled:i||l,className:`flex items-center justify-center h-5 w-5 rounded text-gray-400 hover:text-gray-600 hover:bg-gray-100 transition-colors`,children:(0,L.jsx)(Jn,{className:`h-3.5 w-3.5`})})]}),p.length>1&&(0,L.jsx)(`div`,{className:`flex gap-1 border-b border-gray-200`,children:p.map((e,t)=>{let n=y(e);return(0,L.jsxs)(`button`,{type:`button`,disabled:i||l,onClick:()=>f(t),className:lh(`flex items-center gap-1 px-2.5 py-1.5 text-[11px] font-medium transition-colors border-b-2 -mb-[1px] whitespace-nowrap`,t===d?`border-violet-500 text-violet-700`:`border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300`,(i||l)&&`cursor-default opacity-70`),children:[n&&(0,L.jsx)(mt,{className:`h-3 w-3 text-emerald-500`}),C(e,t)]},t)})}),(0,L.jsxs)(`div`,{className:`overflow-y-auto max-h-[260px] space-y-1.5`,children:[w.header&&(0,L.jsx)(`div`,{className:`text-[10px] font-medium uppercase tracking-wide text-gray-400`,children:w.header}),(0,L.jsx)(`p`,{className:`text-[12px] text-gray-800 font-medium`,children:w.question}),(0,L.jsx)(`div`,{className:`space-y-1`,children:D.map((e,t)=>{let n=typeof e?.label==`string`?e.label:``,r=typeof e?.description==`string`?e.description:``;if(!n)return null;let a=w.multiSelect?E.has(n):T===n;return(0,L.jsx)(`button`,{type:`button`,disabled:i||l,onClick:()=>w.multiSelect?h(w.question,n):m(w.question,n),className:lh(`w-full text-left px-3 py-2 rounded-md border text-[12px] transition-colors`,a?`border-violet-400 bg-violet-50 text-violet-900`:`border-gray-200 bg-white text-gray-700 hover:border-gray-300 hover:bg-gray-50`,(i||l)&&`cursor-default opacity-70`),children:(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[w.multiSelect?(0,L.jsx)(`span`,{className:lh(`h-3.5 w-3.5 rounded border flex-shrink-0 flex items-center justify-center`,a?`border-violet-500 bg-violet-500`:`border-gray-300`),children:a&&(0,L.jsx)(`svg`,{className:`h-2.5 w-2.5 text-white`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,L.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:3,d:`M5 13l4 4L19 7`})})}):(0,L.jsx)(`span`,{className:lh(`h-3.5 w-3.5 rounded-full border flex-shrink-0`,a?`border-violet-500 bg-violet-500`:`border-gray-300`),children:a&&(0,L.jsx)(`span`,{className:`block h-1.5 w-1.5 rounded-full bg-white m-0.5`})}),(0,L.jsx)(`span`,{children:n}),r&&(0,L.jsxs)(`span`,{className:`text-[10px] text-gray-400`,children:[`— `,r]})]})},t)})}),(0,L.jsx)(`input`,{type:`text`,value:O,onChange:e=>g(w.question,e.target.value),placeholder:`Or type your own answer...`,disabled:i||l,className:lh(`w-full px-3 py-1.5 rounded-md border text-[12px] outline-none transition-colors`,O?`border-violet-300 bg-violet-50/50 text-violet-900 placeholder:text-violet-300`:`border-gray-200 bg-white text-gray-700 placeholder:text-gray-300 hover:border-gray-300 focus:border-violet-300`,(i||l)&&`cursor-default opacity-70`)})]}),!l&&(0,L.jsxs)(`div`,{className:`flex items-center justify-between pt-1`,children:[p.length>1&&d<p.length-1?(0,L.jsxs)(`button`,{type:`button`,disabled:i,onClick:S,className:`inline-flex items-center gap-1 rounded-lg px-3 py-1.5 text-[11px] font-medium text-gray-500 hover:text-gray-700 hover:bg-gray-100 transition-colors`,children:[`Next`,(0,L.jsx)(gt,{className:`h-3 w-3`})]}):(0,L.jsx)(`div`,{}),(0,L.jsxs)(`button`,{type:`button`,disabled:!v||i,onClick:b,className:lh(`inline-flex items-center gap-1.5 rounded-lg px-3 py-1.5 text-xs font-medium transition-colors`,v?`bg-gray-900 text-white hover:bg-gray-800`:`bg-gray-100 text-gray-400 cursor-not-allowed`),children:[(0,L.jsx)(Dn,{className:`h-3 w-3`}),`Submit`]})]}),l&&(0,L.jsx)(`p`,{className:`text-[11px] text-emerald-600 font-medium text-right`,children:`Submitted`})]})}var oie=()=>(0,L.jsxs)(`div`,{className:`my-auto flex grow flex-col items-center justify-center gap-3`,children:[(0,L.jsx)(`div`,{className:`h-5 w-5 animate-spin rounded-full border-2 border-gray-300 border-t-gray-600`}),(0,L.jsx)(`p`,{className:`text-sm text-gray-400`,children:`Loading history…`})]}),v8=`loopat:composer:drafts`;function sie(e){try{let t=localStorage.getItem(v8);return t?JSON.parse(t)[e]??null:null}catch{return null}}function y8(e,t){try{let n=localStorage.getItem(v8),r=n?JSON.parse(n):{};t.trim()?r[e]=t:delete r[e],localStorage.setItem(v8,JSON.stringify(r))}catch{}}function b8({archived:e=!1,onUnarchive:t,readOnly:n=!1,repo:r,branch:i,title:a,driver:o,driverHistory:s,rfdRequestedAt:c,rfdRequestedBy:l,onTakeDrive:u,pickedFile:d,editorSelection:f}={}){let{questions:p,sendAnswers:m,loadingHistory:h,loopId:g,hasHistory:_,showHistory:v,toggleShowHistory:y,hasOlderMessages:b,loadMoreMessages:x,thinkingBudget:S,setMaxThinkingTokens:C}=D6(),[w,T]=(0,F.useState)(`normal`),E=Ny(e=>e.thread.isEmpty&&!e.thread.isRunning)&&!h,D=(0,F.useRef)(null),O=(0,F.useRef)(null),[k,A]=(0,F.useState)(!1),ee=(0,F.useCallback)(()=>{let e=O.current;e&&e.scrollTo({top:e.scrollHeight,behavior:`smooth`})},[]),j=(0,F.useRef)(_);j.current=_;let te=(0,F.useRef)(v);te.current=v;let M=(0,F.useRef)(b);M.current=b;let[ne,N]=(0,F.useState)(!1),re=(0,F.useRef)({oldScrollTop:0,oldScrollHeight:0,active:!1}),ie=(0,F.useCallback)(()=>{let e=O.current;e&&(re.current={oldScrollTop:e.scrollTop,oldScrollHeight:e.scrollHeight,active:!0}),y()},[y]),ae=(0,F.useRef)({oldScrollTop:0,oldScrollHeight:0,active:!1}),oe=(0,F.useCallback)(()=>{let e=O.current;e&&(ae.current={oldScrollTop:e.scrollTop,oldScrollHeight:e.scrollHeight,active:!0}),ce(!0),x()},[x]),[se,ce]=(0,F.useState)(!1),le=(0,F.useRef)(!1);le.current=se;let ue=nw(),de=Ny(e=>e.composer.text),fe=(0,F.useRef)(de);fe.current=de,(0,F.useEffect)(()=>{let e=sie(g);e&&ue.setText(e)},[]),(0,F.useEffect)(()=>()=>{y8(g,fe.current)},[g]),(0,F.useEffect)(()=>{if(!de)return;let e=setTimeout(()=>{y8(g,de)},300);return()=>clearTimeout(e)},[de,g]);let[pe,me]=(0,F.useState)(de);(0,F.useEffect)(()=>{pe&&!de&&y8(g,``),me(de)},[de,g]);let he=(0,F.useRef)(null),ge=(0,F.useRef)(!1),_e=(0,F.useRef)(h);_e.current=h;let ve=(0,F.useRef)(h);(0,F.useEffect)(()=>{let e=D.current,t=e?.parentElement;if(!e||!t)return;O.current=t;let n=()=>t.scrollTop+t.clientHeight>=t.scrollHeight-120,r=!1,i=null,a=e=>{e.deltaY<0&&(r=!0,i&&clearTimeout(i),i=setTimeout(()=>{i=null,n()&&(r=!1)},200))},o=()=>{!i&&n()?r=!1:n()||(r=!0),A(t.scrollTop+t.clientHeight<t.scrollHeight-200),N(t.scrollTop<20&&j.current),t.scrollTop<40&&M.current&&!le.current&&oe()};t.addEventListener(`scroll`,o,{passive:!0}),t.addEventListener(`wheel`,a,{passive:!0});let s=null,c=!1,l=()=>{if(ge.current&&r||c||!ge.current&&t.scrollHeight<=t.clientHeight+10)return;let e=t.style.scrollBehavior;t.style.scrollBehavior=`auto`,t.scrollTop=t.scrollHeight,t.style.scrollBehavior=e,ge.current||(_e.current||(ge.current=!0),r=!1),c=!0,requestAnimationFrame(()=>{setTimeout(()=>{c=!1},120)})};l();let u=new ResizeObserver(()=>{s||_e.current||c||(s=setTimeout(()=>{s=null,l()},80))});return u.observe(e),()=>{u.disconnect(),s&&clearTimeout(s),i&&clearTimeout(i),t.removeEventListener(`scroll`,o),t.removeEventListener(`wheel`,a)}},[]),(0,F.useEffect)(()=>{if(ve.current&&!h){let e=O.current;if(e){let t=e.style.scrollBehavior;e.style.scrollBehavior=`auto`,e.scrollTop=e.scrollHeight,e.style.scrollBehavior=t,ge.current=!0}}ve.current=h},[h]),(0,F.useEffect)(()=>{if(!re.current.active)return;let e=O.current;if(!e)return;let{oldScrollTop:t,oldScrollHeight:n}=re.current;re.current.active=!1,requestAnimationFrame(()=>{e.scrollTop=t+(e.scrollHeight-n)})},[v]),(0,F.useEffect)(()=>{if(!ae.current.active)return;let e=O.current;if(!e)return;let{oldScrollTop:t,oldScrollHeight:n}=ae.current;ae.current.active=!1,requestAnimationFrame(()=>{e.scrollTop=t+(e.scrollHeight-n)})},[b]),(0,F.useEffect)(()=>{if(!se)return;let e=setTimeout(()=>ce(!1),200);return()=>clearTimeout(e)},[se,b]);let ye=p.size>0?Array.from(p.entries()):[];return(0,L.jsxs)(rT,{className:`flex h-full flex-col bg-white relative`,style:{"--thread-max-width":`44rem`},children:[(0,L.jsx)(cT,{turnAnchor:`top`,className:E?`hidden`:`relative flex-1 overflow-x-auto overflow-y-scroll scroll-smooth`,children:(0,L.jsxs)(`div`,{ref:D,className:`mx-auto flex w-full min-h-full flex-col px-2 md:px-3 pt-3 md:pt-4`,children:[h&&(0,L.jsx)(oie,{}),ne&&(0,L.jsx)(`div`,{className:`flex justify-center pb-2`,children:(0,L.jsx)(`button`,{type:`button`,onClick:ie,className:`rounded-full border border-gray-200 bg-white px-4 py-1.5 text-xs text-gray-500 hover:text-gray-700 hover:border-gray-300 shadow-sm transition-colors`,children:v?`Collapse earlier messages`:`View earlier messages`})}),se&&(0,L.jsx)(`div`,{className:`flex justify-center py-2`,children:(0,L.jsx)(`span`,{className:`inline-block h-4 w-4 animate-spin rounded-full border-2 border-gray-300 border-t-gray-500`})}),(s??[]).length>1&&(0,L.jsx)(`div`,{className:`flex flex-col gap-1 pb-2`,children:(s??[]).slice(1).map(e=>(0,L.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] text-gray-500`,children:[(0,L.jsx)(`div`,{className:`flex-1 h-px bg-gray-200`}),(0,L.jsxs)(`span`,{className:`text-gray-600`,children:[(0,L.jsx)(`span`,{className:`text-amber-600`,children:`▸`}),` `,`driving by `,(0,L.jsx)(`span`,{className:`text-gray-900 font-medium`,children:e.driver}),` since `,new Date(e.since).toLocaleString()]}),(0,L.jsx)(`div`,{className:`flex-1 h-px bg-gray-200`})]},e.since))}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-2 pb-1`,children:[(0,L.jsx)($S,{children:({message:e})=>e.role===`user`?(0,L.jsx)(A0,{}):(0,L.jsx)(a8,{})}),(0,L.jsx)(`div`,{ref:he}),ye.length>0&&(0,L.jsx)(e8,{name:`QuestionsPanel`,children:(0,L.jsx)(`div`,{className:`space-y-3 w-full pt-2`,children:ye.map(([e,t])=>Array.isArray(t)&&t.length>0?(0,L.jsx)(`div`,{className:`rounded-lg border border-violet-100 bg-violet-50/30 p-4 shadow-sm`,children:(0,L.jsx)(aie,{questions:t,toolUseId:e,onAnswers:m,onDismiss:e=>m(e,{})})},e):null)})})]})]})}),(0,L.jsx)(`div`,{className:E?`flex-1 flex items-center justify-center px-2 md:px-3 pb-3 md:pb-6`:`shrink-0 z-10 bg-gradient-to-t from-white via-white to-transparent px-2 md:px-3 pt-1 md:pt-2 pb-3 md:pb-6`,children:(0,L.jsxs)(`div`,{className:E?`w-full max-w-[36rem]`:``,children:[E&&(0,L.jsxs)(`div`,{className:`mb-4 space-y-2 px-4`,children:[(0,L.jsxs)(`div`,{className:`flex items-baseline gap-3`,children:[a&&(0,L.jsx)(`h1`,{className:`text-xl font-semibold text-gray-800`,children:a}),o&&(0,L.jsxs)(`span`,{className:`text-xs text-gray-400`,children:[`driver: `,o]})]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-3 text-xs text-gray-400`,children:[r&&(0,L.jsxs)(`span`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,L.jsx)(Gt,{className:`h-3.5 w-3.5 shrink-0 text-gray-400`}),(0,L.jsxs)(`span`,{className:`font-mono truncate`,children:[r,i?(0,L.jsxs)(`span`,{className:`text-gray-300`,children:[` · `,i]}):``]})]}),(0,L.jsx)(`span`,{className:`ml-auto flex gap-0.5`,children:[{label:`Normal`,tokens:null,mode:`normal`},{label:`Think`,tokens:16e3,mode:`think`},{label:`Hard`,tokens:32e3,mode:`hard`},{label:`Ultrathink`,tokens:null,mode:`ultra`}].map(e=>(0,L.jsx)(`button`,{type:`button`,onClick:()=>{T(e.mode===`normal`?`normal`:e.mode===`ultra`?`ultra`:`normal`),C(e.tokens)},className:`px-1.5 py-0.5 text-[11px] rounded transition-colors `+((e.mode===`normal`?S===null&&w===`normal`:e.mode===`ultra`?S===null&&w===`ultra`:S===e.tokens)?`bg-gray-200 text-gray-700 font-medium`:`text-gray-400 hover:text-gray-600 hover:bg-gray-100`),children:e.label},e.label))})]})]}),e?(0,L.jsxs)(`div`,{className:`mx-3 md:mx-5 mb-3 rounded-lg border border-amber-300 bg-amber-50 px-3 py-2 flex items-center gap-2 text-[12px] text-amber-800`,children:[(0,L.jsx)(`span`,{children:`📦`}),(0,L.jsx)(`span`,{className:`flex-1`,children:`This loop is archived (read-only).`}),t&&(0,L.jsx)(`button`,{type:`button`,onClick:t,className:`rounded border border-amber-300 bg-white px-2 py-0.5 text-[11px] font-medium text-amber-900 hover:bg-amber-100`,children:`Unarchive`})]}):c?(0,L.jsxs)(`div`,{className:`mx-3 md:mx-5 mb-3 rounded-lg border border-amber-300 bg-amber-50 px-3 py-2 flex items-center gap-2 text-[12px] text-amber-800`,children:[(0,L.jsx)(`span`,{children:`✋`}),(0,L.jsxs)(`span`,{className:`flex-1`,children:[`Released for drive`,l?` by ${l}`:``,` — no one can write until someone takes over.`]}),u&&(0,L.jsx)(`button`,{type:`button`,onClick:u,className:`rounded bg-amber-500 px-2 py-0.5 text-[11px] font-medium text-white hover:bg-amber-600`,children:`Drive`})]}):n?null:(0,L.jsx)(iie,{pickedFile:d,editorSelection:f})]})}),k&&(0,L.jsx)(`button`,{type:`button`,onClick:ee,className:`absolute bottom-40 right-4 z-20 flex h-7 w-7 items-center justify-center rounded-full bg-white border border-gray-200 shadow-sm text-gray-400 hover:text-gray-600 hover:border-gray-300 transition-all`,"aria-label":`Scroll to bottom`,children:(0,L.jsx)(at,{className:`h-3.5 w-3.5`})})]})}function cie(){let{id:e}=xi(),[t,n]=(0,F.useState)(null);return(0,F.useEffect)(()=>{if(!e)return;let t=!1;return(async()=>{let r=await xee(e);t||n(r??`unauthorized`)})(),()=>{t=!0}},[e]),(0,F.useEffect)(()=>{t&&typeof t==`object`&&(document.title=`${t.title} · shared`)},[t]),e?t===null?(0,L.jsx)(uie,{}):t===`unauthorized`?(0,L.jsx)(x8,{reason:`this loop is private or does not exist`}):(0,L.jsx)(lie,{meta:t}):(0,L.jsx)(x8,{reason:`missing loop id`})}function lie({meta:e}){let{runtime:t,connected:n,reconnecting:r,extra:i}=k6(e.id,``);return(0,L.jsxs)(`div`,{className:`h-full w-full flex flex-col bg-white text-gray-900`,children:[(0,L.jsxs)(`header`,{className:`h-12 shrink-0 border-b border-gray-200 bg-white flex items-center px-3 md:px-5 gap-2`,children:[(0,L.jsx)(`span`,{className:`text-lg leading-none`,children:`🧶`}),(0,L.jsx)(`span`,{className:`text-[14px] font-medium text-gray-900 truncate`,children:e.title}),(0,L.jsx)(`span`,{className:`text-[11px] px-1.5 py-0.5 rounded bg-emerald-50 text-emerald-800 border border-emerald-200`,children:`view only`}),(0,L.jsx)(`div`,{className:`flex-1`}),(0,L.jsx)(`span`,{className:`text-[11px] `+(n?`text-emerald-600`:r?`text-amber-500`:`text-red-500`),title:n?`connected`:r?`reconnecting…`:`disconnected`,children:`●`})]}),(0,L.jsx)(`main`,{className:`flex-1 min-h-0`,children:(0,L.jsx)(O6,{extra:i,children:(0,L.jsx)(tw,{runtime:t,children:(0,L.jsx)(b8,{readOnly:!0})})})})]})}function uie(){return(0,L.jsx)(`div`,{className:`h-full w-full flex items-center justify-center text-gray-400 text-sm`,children:`loading…`})}function x8({reason:e}){return(0,L.jsxs)(`div`,{className:`h-full w-full flex flex-col items-center justify-center text-gray-500 gap-2 px-4 text-center`,children:[(0,L.jsx)(`span`,{className:`text-lg`,children:`🧶`}),(0,L.jsx)(`div`,{className:`text-sm`,children:`Loop unavailable`}),(0,L.jsx)(`div`,{className:`text-xs text-gray-400`,children:e})]})}function S8(e){let[t,n]=(0,F.useState)({}),r=(0,F.useRef)(null);return(0,F.useEffect)(()=>{if(e.length===0)return;let t=location.protocol===`https:`?`wss:`:`ws:`,i=new WebSocket(`${t}//${location.host}/ws/loop-status`);return r.current=i,i.onopen=()=>{i.send(JSON.stringify({type:`subscribe`,ids:e}))},i.onmessage=e=>{try{let t=JSON.parse(e.data);(t.type===`init`||t.type===`update`)&&n(e=>({...e,...t.data}))}catch{}},()=>{i&&(i.readyState===WebSocket.CONNECTING?(i.onopen=()=>i.close(),i.onmessage=null,i.onclose=null,i.onerror=null):(i.onclose=null,i.onerror=null,i.close())),r.current=null}},[e.join(`,`)]),t}function C8({currentId:e,onSelect:t}){let n=D_(),r=_i(),[i,a]=(0,F.useState)(`mine`),[o,s]=(0,F.useState)(``),c=f6(),l=S8((0,F.useMemo)(()=>n.loops.map(e=>e.id),[n.loops])),u=n.currentUser?.id,d=(0,F.useMemo)(()=>{let e=o.toLowerCase().trim();return n.loops.filter(t=>{let n=t.driver??t.createdBy;return!(i===`mine`&&t.createdBy!==u&&n!==u||i===`rfd`&&!t.rfdRequestedAt||e&&!t.title.toLowerCase().includes(e)&&!t.id.toLowerCase().includes(e))})},[n.loops,i,u,o]),f=e=>{Nh(e),t?t(e):r(`/loop/${e}`)};return(0,L.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,L.jsxs)(`div`,{className:`px-3 pt-3 pb-2 space-y-2`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-1`,children:[[`mine`,`all`,`rfd`].map(e=>(0,L.jsx)(`button`,{type:`button`,onClick:()=>a(e),className:i===e?e===`rfd`?`px-2 h-6 rounded text-[11px] flex items-center gap-1 bg-amber-600 text-white`:`px-2 h-6 rounded text-[11px] bg-gray-900 text-white`:e===`rfd`?`px-2 h-6 rounded text-[11px] flex items-center gap-1 text-amber-700 hover:bg-amber-50`:`px-2 h-6 rounded text-[11px] text-gray-500 hover:bg-gray-100`,children:e===`mine`?`mine`:e===`all`?`all`:`RFD`},e)),(0,L.jsx)(`span`,{className:`text-[11px] text-gray-400 ml-auto pr-1`,children:d.length}),(0,L.jsx)(`button`,{type:`button`,onClick:()=>n.setShowArchived(!n.showArchived),className:n.showArchived?`w-6 h-6 flex items-center justify-center text-gray-700 bg-gray-100 rounded`:`w-6 h-6 flex items-center justify-center text-gray-400 hover:text-gray-700 hover:bg-gray-100 rounded`,title:n.showArchived?`hide archived`:`show archived`,children:(0,L.jsx)(it,{size:13})})]}),(0,L.jsx)(`input`,{type:`text`,name:`loop-search`,value:o,onChange:e=>s(e.target.value),placeholder:`search loops…`,className:`w-full h-7 rounded px-2 text-[12px] bg-gray-100 border border-transparent focus:border-gray-300 focus:bg-white focus:outline-none text-gray-600 placeholder-gray-400`})]}),(0,L.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-auto py-1`,children:[d.map(t=>{let r=e===t.id,i=t.archived===!0,a=n.currentUser?.id===t.createdBy,o=l[t.id],s=o?.status===`Done`||o?.status===`Ready`,u=o!==void 0&&!s;return(0,L.jsxs)(`div`,{className:`group/row relative flex items-stretch `+(r?`bg-gray-100`:`hover:bg-gray-50`),children:[(0,L.jsxs)(`button`,{type:`button`,onClick:()=>f(t.id),className:`flex-1 min-w-0 px-3 py-1.5 flex items-center gap-2 text-left `+(i?`opacity-60`:``),children:[(0,L.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full shrink-0 mt-0.5 `+(i?`bg-gray-400`:u?`bg-blue-500 animate-pulse`:s&&!o?.viewed?`bg-yellow-500`:s?`bg-emerald-500`:`bg-gray-300`)}),(0,L.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,L.jsxs)(`div`,{className:`text-[13px] text-gray-900 truncate flex items-center gap-1.5`,children:[i&&(0,L.jsx)(it,{size:10,className:`text-gray-400 shrink-0`}),t.rfdRequestedAt&&(0,L.jsx)(`span`,{className:`shrink-0 text-[9px] px-1 rounded bg-amber-100 text-amber-800 font-medium tracking-wide`,children:`RFD`}),(0,L.jsx)(`span`,{className:`truncate`,children:t.title}),o&&(0,L.jsx)(`span`,{className:`shrink-0 text-[10px] font-medium `+(u?`text-blue-500`:s?`text-emerald-500`:`text-gray-400`),children:o.status})]}),(0,L.jsxs)(`div`,{className:`text-[11px] text-gray-500 truncate flex items-center gap-1 mt-0.5`,children:[(0,L.jsx)(`span`,{children:t.driver??t.createdBy}),(0,L.jsx)(`span`,{className:`text-gray-300`,children:`·`}),(0,L.jsx)(`span`,{className:`font-mono text-[10px] text-gray-400`,children:t.id.slice(0,6)})]})]})]}),(0,L.jsx)(`button`,{type:`button`,disabled:!a,onClick:e=>{e.stopPropagation(),a&&n.setLoopArchived(t.id,!i)},className:(c?`opacity-100`:`opacity-0 group-hover/row:opacity-100`)+` transition-opacity w-7 flex items-center justify-center `+(a?`text-gray-400 hover:text-gray-700`:`text-gray-300 cursor-not-allowed`),title:a?i?`unarchive`:`archive (hide + read-only)`:`only ${t.createdBy} can ${i?`unarchive`:`archive`} this loop`,children:i?(0,L.jsx)(rt,{size:13}):(0,L.jsx)(it,{size:13})})]},t.id)}),d.length===0&&(0,L.jsx)(`div`,{className:`px-3 py-4 text-[12px] text-gray-400 italic`,children:`no loops · click "+ New Loop"`})]})]})}var w8=`loopat:tree:expanded:`;function T8(e){try{let t=localStorage.getItem(w8+e);return t?new Set(JSON.parse(t)):new Set}catch{return new Set}}function die(e,t){try{localStorage.setItem(w8+e,JSON.stringify([...t]))}catch{}}function E8({treeId:e,entries:t,onPick:n,picked:r,onLoadChildren:i,getContextActions:a,onAction:o,depthOffset:s=0,renderNode:c,nodeClassName:l,reloadKey:u}){return(0,L.jsx)(L.Fragment,{children:t.map(t=>(0,L.jsx)(D8,{treeId:e,entry:t,depth:s,onPick:n,picked:r,onLoadChildren:i,getContextActions:a,onAction:o,renderNode:c,nodeClassName:l,reloadKey:u},t.path))})}function D8({treeId:e,entry:t,depth:n,onPick:r,picked:i,onLoadChildren:a,getContextActions:o,onAction:s,renderNode:c,nodeClassName:l,reloadKey:u}){let[d,f]=(0,F.useState)(()=>T8(e).has(t.path)),[p,m]=(0,F.useState)(null),[h,g]=(0,F.useState)(!1),[_,v]=(0,F.useState)(null),y=(0,F.useCallback)(()=>{let n=T8(e);n.has(t.path)?n.delete(t.path):n.add(t.path),die(e,n),f(e=>!e)},[e,t.path]),b=(0,F.useRef)(u);(0,F.useEffect)(()=>{b.current!==u&&(m(null),b.current=u)},[u]),(0,F.useEffect)(()=>{!d||p!==null||t.type===`dir`&&(g(!0),a(t.path).then(m).finally(()=>g(!1)))},[d,t.path,a,p]);let x=e=>{e.preventDefault(),e.stopPropagation(),v({x:e.clientX,y:e.clientY})},S=8+n*12;if(t.type===`dir`)return c?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`div`,{onContextMenu:x,children:c(t,n,d,y)}),d&&p&&(0,L.jsx)(L.Fragment,{children:p.map(t=>(0,L.jsx)(D8,{treeId:e,entry:t,depth:n+1,onPick:r,picked:i,onLoadChildren:a,getContextActions:o,onAction:s,renderNode:c,nodeClassName:l,reloadKey:u},t.path))}),_&&(0,L.jsx)(O8,{x:_.x,y:_.y,items:o(t).filter(e=>!e.hidden),onAction:e=>s(e,t),onClose:()=>v(null)})]}):(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`div`,{onContextMenu:x,children:(0,L.jsxs)(`button`,{type:`button`,onClick:y,className:l?l(t,n,d,!1):`w-full py-1 flex items-center gap-1.5 hover:bg-gray-50 text-left group`,style:{paddingLeft:S,paddingRight:8},children:[(0,L.jsx)(`span`,{className:`text-gray-500 w-3`,children:d?`▾`:`▸`}),(0,L.jsx)(`span`,{className:`text-gray-500`,children:d?(0,L.jsx)(Ht,{size:13}):(0,L.jsx)(Wt,{size:13})}),(0,L.jsx)(`span`,{className:`text-[13px] text-gray-900 truncate`,children:t.name})]})}),h&&(0,L.jsx)(`div`,{className:`text-[12px] text-gray-400 italic`,style:{paddingLeft:S+12},children:`...`}),d&&p&&(0,L.jsxs)(L.Fragment,{children:[p.map(t=>(0,L.jsx)(D8,{treeId:e,entry:t,depth:n+1,onPick:r,picked:i,onLoadChildren:a,getContextActions:o,onAction:s,renderNode:c,nodeClassName:l,reloadKey:u},t.path)),p.length===0&&(0,L.jsx)(`div`,{className:`text-[12px] text-gray-400 italic py-1`,style:{paddingLeft:S+12},children:`(empty)`})]}),_&&(0,L.jsx)(O8,{x:_.x,y:_.y,items:o(t).filter(e=>!e.hidden),onAction:e=>s(e,t),onClose:()=>v(null)})]});let C=i===t.path;return c?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`div`,{onContextMenu:x,onClick:()=>r(t.path),children:c(t,n,!1,()=>{})}),_&&(0,L.jsx)(O8,{x:_.x,y:_.y,items:o(t).filter(e=>!e.hidden),onAction:e=>s(e,t),onClose:()=>v(null)})]}):(0,L.jsx)(L.Fragment,{children:(0,L.jsxs)(`div`,{className:`relative`,onContextMenu:x,children:[(0,L.jsxs)(`button`,{type:`button`,onClick:()=>r(t.path),className:l?l(t,n,!1,C):`w-full py-1 flex items-center gap-2 text-left `+(C?`bg-gray-100`:`hover:bg-gray-50`),style:{paddingLeft:S,paddingRight:8},children:[(0,L.jsx)(`span`,{className:`w-3 text-gray-400`,children:(0,L.jsx)(zt,{size:13})}),(0,L.jsx)(`span`,{className:`text-[13px] text-gray-900 flex-1 min-w-0 truncate`,children:t.name})]}),_&&(0,L.jsx)(O8,{x:_.x,y:_.y,items:o(t).filter(e=>!e.hidden),onAction:e=>s(e,t),onClose:()=>v(null)})]})})}function O8({x:e,y:t,items:n,onAction:r,onClose:i}){return(0,F.useEffect)(()=>{let e=e=>{e.target?.closest(`[data-context-menu]`)||i()},t=e=>{e.key===`Escape`&&i()};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[i]),(0,vo.createPortal)((0,L.jsx)(`div`,{"data-context-menu":!0,className:`fixed z-[9999] bg-white border border-gray-200 rounded-lg shadow-lg py-1 text-[12px] min-w-[140px]`,style:{left:e,top:t},onContextMenu:e=>e.preventDefault(),children:n.map(e=>(0,L.jsxs)(`button`,{onClick:()=>{r(e.action),i()},className:`w-full px-3 py-1.5 flex items-center gap-2 text-left hover:bg-gray-50 `+(e.danger?`text-red-600 hover:bg-red-50`:`text-gray-700`),children:[e.icon,e.label]},e.action))}),document.body)}var fie=[{name:`context`,section:`context`,emoji:`🧷`,hint:`knowledge / notes / personal`},{name:`workdir`,section:`workdir`,emoji:`▣`}];function pie({loopId:e,onPick:t,picked:n}){let[r,i]=(0,F.useState)(0),a=(0,F.useRef)(null),[o,s]=(0,F.useState)(``),[c,l]=(0,F.useState)(null),[u,d]=(0,F.useState)(``),f=(0,F.useCallback)(e=>{s(e??`workdir`),a.current?.click()},[]),p=async t=>{let n=t.target.files?.[0];if(!n)return;let r=await Bh(e,n);r.ok||alert(`upload failed: ${r.error}`),i(e=>e+1),a.current&&(a.current.value=``),s(``)},m=async()=>{if(!c||!u.trim()){l(null);return}let t=c.path+`/`+u.trim(),n=!1;if(n=c.type===`file`?await Lh(e,t,``):await zh(e,t),!n){alert(`create failed`),l(null);return}l(null),d(``),i(e=>e+1)},h=(0,F.useCallback)((t,n)=>{if(t===`upload`)f(n.path);else if(t===`new-file`||t===`new-folder`)l({type:t===`new-file`?`file`:`folder`,path:n.path}),d(``);else if(t===`delete`){if(!confirm(`Delete "${n.name}"?`))return;Rh(e,n.path).then(e=>{if(!e){alert(`delete failed`);return}i(e=>e+1)})}},[f,e]),g=(0,F.useCallback)(e=>e.type===`dir`?[{label:`Upload here`,icon:(0,L.jsx)(Wn,{size:12}),action:`upload`},{label:`New file`,icon:(0,L.jsx)(Lt,{size:12}),action:`new-file`},{label:`New folder`,icon:(0,L.jsx)(Ut,{size:12}),action:`new-folder`},{label:`Delete`,icon:(0,L.jsx)(Bn,{size:12}),action:`delete`,danger:!0}]:[{label:`View`,icon:(0,L.jsx)(Nt,{size:12}),action:`view`},{label:`Delete`,icon:(0,L.jsx)(Bn,{size:12}),action:`delete`,danger:!0}],[]);return(0,F.useCallback)(t=>Ph(e,t).then(e=>e),[e]),(0,L.jsxs)(`aside`,{className:`flex-1 min-h-0 overflow-auto py-2 text-[13px]`,children:[(0,L.jsx)(`input`,{ref:a,type:`file`,className:`hidden`,onChange:p}),fie.map(a=>(0,L.jsx)(mie,{loopId:e,name:a.name,section:a.section,emoji:a.emoji,hint:a.hint,onPick:t,picked:n,onUpload:()=>f(a.name),onReload:()=>i(e=>e+1),reloadKey:r,getContextActions:g,onAction:h,treeId:`loop-${e}`},a.name+r)),c&&(0,L.jsx)(hie,{depth:1,type:c.type,value:u,onChange:d,onSubmit:m,onCancel:()=>l(null)})]})}function mie({loopId:e,name:t,section:n,emoji:r,hint:i,onPick:a,picked:o,onUpload:s,onReload:c,reloadKey:l,getContextActions:u,onAction:d,treeId:f}){let[p,m]=(0,F.useState)(!0),h=n===`context`?`w-full py-1.5 flex items-center gap-1.5 bg-cyan-50/50 hover:bg-cyan-50 text-left border-y border-cyan-100/70`:`w-full py-1.5 flex items-center gap-1.5 bg-emerald-50/40 hover:bg-emerald-50 text-left border-y border-emerald-100/70`,g=(0,F.useCallback)(t=>Ph(e,t).then(e=>e),[e]);return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`button`,{type:`button`,onClick:()=>m(e=>!e),className:h,style:{paddingLeft:`0.5rem`,paddingRight:`0.5rem`},children:[(0,L.jsx)(`span`,{className:`text-gray-500`,children:p?`▾`:`▸`}),(0,L.jsx)(`span`,{className:`text-[12px]`,children:r}),(0,L.jsx)(`span`,{className:`text-[11px] uppercase tracking-wider font-semibold text-gray-700`,children:t}),i&&(0,L.jsx)(`span`,{className:`text-[10px] text-gray-500 italic ml-1`,children:i}),n===`workdir`&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`div`,{className:`flex-1`}),(0,L.jsx)(`span`,{onClick:e=>{e.stopPropagation(),s()},className:`text-gray-400 hover:text-gray-700 px-1 rounded hover:bg-emerald-100/50 flex items-center gap-0.5`,title:`upload file`,children:(0,L.jsx)(Wn,{size:12})})]})]}),p&&(0,L.jsx)(E8,{treeId:`${f}-${t}`,entries:[{name:t,path:t,type:`dir`}],onPick:a,picked:o,onLoadChildren:g,getContextActions:u,onAction:d,depthOffset:1,reloadKey:l})]})}function hie({depth:e,type:t,value:n,onChange:r,onSubmit:i,onCancel:a}){let o=(0,F.useRef)(null);return(0,F.useEffect)(()=>{o.current?.focus()},[]),(0,L.jsxs)(`div`,{className:`flex items-center gap-1 py-0.5`,style:{paddingLeft:8+e*12},children:[(0,L.jsx)(`span`,{className:`text-gray-400`,children:t===`file`?`📄`:`📁`}),(0,L.jsx)(`input`,{ref:o,value:n,onChange:e=>r(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&i(),e.key===`Escape`&&a()},placeholder:t===`file`?`filename.txt`:`folder-name`,className:`flex-1 px-1.5 py-0.5 text-[12px] border border-gray-300 rounded outline-none focus:border-gray-900`}),(0,L.jsx)(`button`,{onClick:i,className:`text-[10px] text-emerald-600 hover:text-emerald-800 px-1`,children:`✓`}),(0,L.jsx)(`button`,{onClick:a,className:`text-[10px] text-gray-400 hover:text-gray-600 px-1`,children:`✕`})]})}function gie(e){let t=e.split(`
397
- `),n=``,r=[],i=null,a=0,o=0;for(let e of t){if(e.startsWith(`diff `)){n=e;continue}if(e.startsWith(`+++ `)||e.startsWith(`--- `))continue;let t=e.match(/^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@(.*)$/);if(t){i&&r.push(i),a=parseInt(t[1],10),o=parseInt(t[3],10),i={header:e,lines:[]};continue}i&&(e.startsWith(`+`)?(i.lines.push({type:`add`,oldNum:null,newNum:o,text:e.slice(1)}),o++):e.startsWith(`-`)?(i.lines.push({type:`del`,oldNum:a,newNum:null,text:e.slice(1)}),a++):(i.lines.push({type:`ctx`,oldNum:a,newNum:o,text:e.startsWith(` `)?e.slice(1):e}),a++,o++))}return i&&r.push(i),{fileHeader:n,hunks:r}}function _ie({filePath:e,diff:t,loading:n,onClose:r}){let i=null;if(t)try{i=gie(t)}catch{}return(0,L.jsx)(P_,{open:!0,onOpenChange:e=>{e||r()},children:(0,L.jsxs)(L_,{className:`sm:max-w-4xl max-h-[85vh] flex flex-col bg-white p-0 gap-0`,showCloseButton:!1,children:[(0,L.jsxs)(`div`,{className:`px-4 py-2.5 border-b border-gray-200 shrink-0 flex items-center gap-2`,children:[(0,L.jsx)(`span`,{className:`text-sm font-mono text-gray-900 truncate flex-1`,children:e}),(0,L.jsx)(`button`,{onClick:r,className:`text-gray-400 hover:text-gray-700 text-sm leading-none`,children:`✕`})]}),(0,L.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto`,children:n?(0,L.jsxs)(`div`,{className:`flex items-center justify-center py-16 text-gray-400 gap-2`,children:[(0,L.jsx)(an,{className:`animate-spin`,size:16}),(0,L.jsx)(`span`,{className:`text-sm`,children:`loading diff...`})]}):i?(0,L.jsx)(`div`,{className:`text-xs font-mono leading-5`,children:i.hunks.map((e,t)=>(0,L.jsxs)(`div`,{className:`border-b border-gray-100 last:border-b-0`,children:[(0,L.jsx)(`div`,{className:`px-4 py-1 bg-blue-50/60 text-blue-700 border-b border-blue-100 sticky top-0`,children:e.header}),e.lines.map((e,t)=>{let n=e.type===`add`,r=e.type===`del`;return(0,L.jsxs)(`div`,{className:`flex `+(n?`bg-emerald-50`:r?`bg-red-50`:``),children:[(0,L.jsx)(`span`,{className:`w-14 shrink-0 text-right pr-3 py-px text-gray-300 select-none border-r border-gray-200 bg-gray-50`,children:e.oldNum??``}),(0,L.jsx)(`span`,{className:`w-14 shrink-0 text-right pr-3 py-px select-none border-r border-gray-200 `+(n?`bg-emerald-100/70 text-emerald-700`:r?`bg-red-100/70 text-red-500`:`text-gray-300 bg-gray-50`),children:e.newNum??``}),(0,L.jsxs)(`span`,{className:`pl-3 py-px whitespace-pre-wrap break-all flex-1 `+(n?`text-emerald-800`:r?`text-red-700`:`text-gray-700`),children:[(0,L.jsx)(`span`,{className:`select-none`,children:n?`+`:r?`−`:` `}),e.text]})]},t)})]},t))}):(0,L.jsx)(`div`,{className:`py-16 text-center text-sm text-gray-400`,children:`empty diff`})})]})})}var vie={A:{label:`A`,color:`text-emerald-600`},M:{label:`M`,color:`text-amber-600`},D:{label:`D`,color:`text-red-600`},R:{label:`R`,color:`text-purple-600`},"?":{label:`?`,color:`text-gray-400`}};function yie({loopId:e,onClose:t,onPickFile:n}){let[r,i]=(0,F.useState)(null),[a,o]=(0,F.useState)(!1),[s,c]=(0,F.useState)(!0),[l,u]=(0,F.useState)(!0),[d,f]=(0,F.useState)(null),[p,m]=(0,F.useState)(``),[h,g]=(0,F.useState)(``),[_,v]=(0,F.useState)(!1),[y,b]=(0,F.useState)(null),[x,S]=(0,F.useState)([]),[C,w]=(0,F.useState)(!1),[T,E]=(0,F.useState)(!0),D=(0,F.useCallback)(async()=>{o(!0),f(null);try{i(await Cg(e))}catch{f(`Failed to load git status`)}finally{o(!1)}},[e]),O=(0,F.useCallback)(async()=>{w(!0);try{S(await Og(e,50))}catch{}finally{w(!1)}},[e]);(0,F.useEffect)(()=>{D(),O()},[D,O]);let k=async()=>{r?.unstaged.length&&await Tg(e,r.unstaged.map(e=>e.path))&&D()},A=async()=>{r?.staged.length&&await Tg(e,r.staged.map(e=>e.path),!0)&&D()},ee=async t=>{await Tg(e,[t])&&D()},j=async t=>{await Tg(e,[t],!0)&&D()},te=async t=>{await Eg(e,t)&&D()},M=async()=>{if(!h.trim())return;v(!0),b(null);let t=await Dg(e,h.trim());v(!1),t.ok?(g(``),D(),O()):b(t.error??`Commit failed`)},ne=p.trim().toLowerCase(),N=r?r.unstaged.filter(e=>!ne||e.path.toLowerCase().includes(ne)):[],re=r?r.staged.filter(e=>!ne||e.path.toLowerCase().includes(ne)):[],ie=!r||r.unstaged.length===0&&r.staged.length===0;return(0,L.jsxs)(`aside`,{className:`w-full h-full min-w-0 bg-white flex flex-col`,children:[(0,L.jsxs)(`header`,{className:`px-3 h-8 shrink-0 border-b border-gray-200 flex items-center gap-1 text-[11px] text-gray-500`,children:[(0,L.jsx)(`span`,{className:`tracking-wide`,children:`Git Changes`}),(0,L.jsx)(`div`,{className:`flex-1`}),(0,L.jsx)(`button`,{onClick:()=>{D(),O()},className:`text-gray-500 hover:text-gray-900 px-1 rounded hover:bg-gray-100`,title:`refresh`,children:(0,L.jsx)(wn,{size:13,className:a||C?`animate-spin`:``})}),(0,L.jsx)(`button`,{className:`text-gray-500 hover:text-gray-900 px-1 rounded hover:bg-gray-100`,onClick:t,title:`close`,children:`✕`})]}),(0,L.jsxs)(`div`,{className:`px-3 py-2 border-b border-gray-100`,children:[(0,L.jsx)(`textarea`,{placeholder:`Commit message...`,value:h,onChange:e=>{g(e.target.value),b(null)},rows:2,className:`w-full px-2 py-1.5 text-[12px] border border-gray-200 rounded outline-none focus:border-gray-300 placeholder:text-gray-300 resize-none mb-1.5`}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsxs)(`button`,{onClick:M,disabled:_||!h.trim(),className:`flex-1 flex items-center justify-center gap-1 px-2 py-1 text-[11px] rounded bg-blue-600 text-white hover:bg-blue-700 disabled:opacity-40 disabled:cursor-not-allowed`,children:[(0,L.jsx)(Kt,{size:12}),_?`Committing...`:`Commit`]}),r&&r.staged.length>0&&(0,L.jsxs)(`span`,{className:`text-[10px] text-gray-400`,children:[r.staged.length,` staged`]})]}),y&&(0,L.jsx)(`div`,{className:`mt-1 text-[10px] text-red-500`,children:y})]}),(0,L.jsx)(`div`,{className:`px-3 py-2 border-b border-gray-100`,children:(0,L.jsx)(`input`,{type:`text`,placeholder:`Filter files...`,value:p,onChange:e=>m(e.target.value),className:`w-full px-2 py-1 text-[12px] border border-gray-200 rounded outline-none focus:border-gray-300 placeholder:text-gray-300`})}),(0,L.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-auto text-[13px]`,children:[(0,L.jsxs)(`div`,{className:`overflow-auto py-2`,children:[a&&!r&&(0,L.jsx)(`div`,{className:`px-5 py-4 text-[12px] text-gray-400 italic`,children:`loading git status...`}),d&&(0,L.jsx)(`div`,{className:`px-5 py-4 text-[12px] text-red-500`,children:d}),ie&&!a&&(0,L.jsx)(`div`,{className:`px-5 py-4 text-[12px] text-gray-400 italic`,children:`no changes`}),N.length>0&&(0,L.jsx)(k8,{title:`Unstaged Changes`,count:N.length,open:s,onToggle:()=>c(e=>!e),bulkAction:{label:`Stage all`,icon:(0,L.jsx)(bn,{size:12}),onClick:k},children:N.map(t=>(0,L.jsx)(A8,{file:t,loopId:e,staged:!1,onStage:()=>ee(t.path),onUnstage:()=>j(t.path),onDiscard:()=>te(t.path),onEdit:e=>n(e),onRefresh:D},t.path))}),re.length>0&&(0,L.jsx)(k8,{title:`Staged Changes`,count:re.length,open:l,onToggle:()=>u(e=>!e),bulkAction:{label:`Unstage all`,icon:(0,L.jsx)(fn,{size:12}),onClick:A},children:re.map(t=>(0,L.jsx)(A8,{file:t,loopId:e,staged:!0,onStage:()=>ee(t.path),onUnstage:()=>j(t.path),onDiscard:()=>te(t.path),onEdit:e=>n(e),onRefresh:D},t.path))})]}),(0,L.jsxs)(`div`,{className:`border-t border-gray-200`,children:[(0,L.jsxs)(`div`,{role:`button`,tabIndex:0,onClick:()=>E(e=>!e),onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&E(e=>!e)},className:`w-full px-3 py-1.5 flex items-center gap-1.5 hover:bg-gray-50 text-left cursor-pointer select-none`,children:[(0,L.jsx)(`span`,{className:`text-gray-500`,children:T?`▾`:`▸`}),(0,L.jsx)(Gt,{size:12,className:`text-gray-500`}),(0,L.jsx)(`span`,{className:`text-[11px] uppercase tracking-wide text-gray-500`,children:`History`}),(0,L.jsxs)(`span`,{className:`text-[11px] text-gray-400`,children:[`(`,x.length,`)`]})]}),T&&(0,L.jsx)(`div`,{className:`px-2 pb-2 max-h-64 overflow-auto`,children:C?(0,L.jsx)(`div`,{className:`px-3 py-3 text-[11px] text-gray-400 italic`,children:`loading history...`}):x.length===0?(0,L.jsx)(`div`,{className:`px-3 py-3 text-[11px] text-gray-400 italic`,children:`no commits`}):(0,L.jsx)(bie,{commits:x})})]})]})]})}function bie({commits:e}){let t=[`bg-blue-500`,`bg-emerald-500`,`bg-purple-500`,`bg-amber-500`,`bg-pink-500`,`bg-cyan-500`],n=new Map,r=0,i=e=>(n.has(e)||(n.set(e,t[r%t.length]),r++),n.get(e));return(0,L.jsx)(`div`,{className:`space-y-0`,children:e.map((t,n)=>{let r=t.branch??t.branches[0]??null,a=r?i(r):`bg-gray-400`,o=n===0,s=new Date(t.date).toLocaleDateString(void 0,{month:`short`,day:`numeric`}),c=new Date(t.date).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`});return(0,L.jsxs)(`div`,{className:`group/graph-row flex items-start gap-2 py-0.5 px-1.5 rounded hover:bg-gray-100 cursor-default text-[11px]`,title:`${t.subject}\n${t.author} · ${s} ${c}`,children:[(0,L.jsxs)(`div`,{className:`flex flex-col items-center shrink-0`,children:[(0,L.jsx)(`div`,{className:`w-2.5 h-2.5 rounded-full ${a} ring-2 ring-white ${o?`ring-blue-300`:``}`}),n<e.length-1&&(0,L.jsx)(`div`,{className:`w-0.5 h-10 ${a} opacity-10`})]}),(0,L.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,L.jsx)(`span`,{className:`font-mono text-[10px] text-gray-400 truncate`,children:t.shortHash}),o&&(0,L.jsx)(`span`,{className:`text-[9px] px-1 py-0 rounded bg-blue-100 text-blue-700 font-medium`,children:`HEAD`}),t.branches.slice(0,2).map(e=>(0,L.jsx)(`span`,{className:`text-[9px] px-1 py-0 rounded bg-emerald-100 text-emerald-700 font-medium truncate max-w-[60px]`,children:e},e)),t.tags.map(e=>(0,L.jsx)(`span`,{className:`text-[9px] px-1 py-0 rounded bg-purple-100 text-purple-700 font-medium`,children:e},e))]}),(0,L.jsx)(`div`,{className:`text-gray-700 truncate`,children:t.subject}),(0,L.jsxs)(`div`,{className:`text-gray-400 text-[10px]`,children:[t.author,` · `,s]})]})]},t.hash)})})}function k8({title:e,count:t,open:n,onToggle:r,bulkAction:i,children:a}){return(0,L.jsxs)(`div`,{className:`mb-2`,children:[(0,L.jsxs)(`div`,{role:`button`,tabIndex:0,onClick:r,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&r()},className:`w-full px-3 py-1.5 flex items-center gap-1.5 hover:bg-gray-50 text-left group/section cursor-pointer select-none`,children:[(0,L.jsx)(`span`,{className:`text-gray-500`,children:n?`▾`:`▸`}),(0,L.jsx)(`span`,{className:`text-[11px] uppercase tracking-wide text-gray-500`,children:e}),(0,L.jsxs)(`span`,{className:`text-[11px] text-gray-400`,children:[`(`,t,`)`]}),(0,L.jsx)(`div`,{className:`flex-1`}),(0,L.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),i.onClick()},className:`opacity-100 sm:opacity-0 sm:group-hover/section:opacity-100 transition-opacity px-1 py-0.5 rounded hover:bg-gray-200 text-gray-500 hover:text-gray-900 flex items-center gap-0.5`,title:i.label,children:i.icon})]}),n&&(0,L.jsx)(`div`,{children:a})]})}function A8({file:e,loopId:t,staged:n,onStage:r,onUnstage:i,onDiscard:a,onEdit:o,onRefresh:s}){let[c,l]=(0,F.useState)(!1),[u,d]=(0,F.useState)(null),[f,p]=(0,F.useState)(!1),[m,h]=(0,F.useState)(!1),[g,_]=(0,F.useState)(null),v=(0,F.useRef)(null);(0,F.useEffect)(()=>{let e=e=>{v.current&&!v.current.contains(e.target)&&_(null)};if(g)return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[g]);let y=async()=>{e.isBinary||(l(!0),u===null&&(p(!0),d(await wg(t,e.path,n)??``),p(!1)))},b=e=>{e.preventDefault(),_({x:e.clientX,y:e.clientY})},x=`workdir/${e.path}`,S=[{label:`Open in Editor`,icon:(0,L.jsx)(yn,{size:12}),onClick:()=>{o(x),_(null)}},{label:`View Diff`,icon:(0,L.jsx)(En,{size:12}),onClick:()=>{y(),_(null)}},{separator:!0,label:``,onClick:()=>{}},n?{label:`Unstage`,icon:(0,L.jsx)(fn,{size:12}),onClick:()=>{i(),_(null)}}:{label:`Stage`,icon:(0,L.jsx)(bn,{size:12}),onClick:()=>{r(),_(null)}},!n&&{label:`Discard Changes`,icon:(0,L.jsx)(Hn,{size:12}),onClick:()=>{h(!0),_(null)},danger:!0}].filter(Boolean),C=vie[e.status]??{label:e.status,color:`text-gray-500`},w=e.path.lastIndexOf(`/`),T=w>=0?e.path.slice(w+1):e.path,E=w>=0?e.path.slice(0,w+1):null;return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`div`,{className:`group/row relative flex items-center gap-2 px-3 py-1.5 hover:bg-gray-50`,onContextMenu:b,children:[(0,L.jsx)(`span`,{className:`w-5 text-center text-[11px] font-mono font-semibold ${C.color}`,children:C.label}),(0,L.jsxs)(`span`,{className:`flex-1 min-w-0 truncate text-[13px] font-mono`,children:[(0,L.jsx)(`span`,{className:`text-gray-900`,children:T}),E&&(0,L.jsx)(`span`,{className:`text-gray-400 ml-0.5`,children:E})]}),!e.isBinary&&(e.additions>0||e.deletions>0)&&(0,L.jsxs)(`span`,{className:`text-[11px] font-mono flex items-center gap-0.5 shrink-0`,children:[(0,L.jsxs)(`span`,{className:`text-emerald-600`,children:[`+`,e.additions]}),(0,L.jsxs)(`span`,{className:`text-red-500`,children:[`-`,e.deletions]})]}),(0,L.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 opacity-100 sm:opacity-0 sm:group-hover/row:opacity-100 transition-opacity shrink-0`,children:[(0,L.jsx)(`button`,{type:`button`,onClick:()=>o(x),className:`w-5 h-5 flex items-center justify-center text-gray-400 hover:text-blue-600 rounded`,title:`edit file`,children:(0,L.jsx)(yn,{size:13})}),n&&(0,L.jsx)(`button`,{type:`button`,onClick:y,className:`w-5 h-5 flex items-center justify-center text-gray-400 hover:text-gray-700 rounded`,title:`view diff`,disabled:e.isBinary,children:(0,L.jsx)(En,{size:13})}),n?(0,L.jsx)(`button`,{type:`button`,onClick:i,className:`w-5 h-5 flex items-center justify-center text-gray-400 hover:text-amber-600 rounded`,title:`unstage`,children:(0,L.jsx)(fn,{size:13})}):(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`button`,{type:`button`,onClick:()=>h(!0),className:`w-5 h-5 flex items-center justify-center text-gray-400 hover:text-red-500 rounded`,title:`discard changes`,children:(0,L.jsx)(Hn,{size:13})}),(0,L.jsx)(`button`,{type:`button`,onClick:r,className:`w-5 h-5 flex items-center justify-center text-gray-400 hover:text-emerald-600 rounded`,title:`stage`,children:(0,L.jsx)(bn,{size:13})})]})]})]}),g&&(0,L.jsx)(`div`,{ref:v,className:`fixed z-50 min-w-[160px] py-1 bg-white border border-gray-200 rounded-md shadow-lg text-[12px]`,style:{left:g.x,top:g.y},children:S.map((e,t)=>e.separator?(0,L.jsx)(`div`,{className:`my-1 border-t border-gray-100`},t):(0,L.jsxs)(`button`,{onClick:e.onClick,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left hover:bg-gray-100 ${e.danger?`text-red-600`:`text-gray-700`}`,children:[e.icon,(0,L.jsx)(`span`,{children:e.label})]},t))}),c&&(0,L.jsx)(_ie,{filePath:e.path,diff:u,loading:f,onClose:()=>l(!1)}),m&&(0,L.jsx)(P_,{open:!0,onOpenChange:e=>{e||h(!1)},children:(0,L.jsxs)(L_,{className:`sm:max-w-sm bg-white p-5 gap-4`,showCloseButton:!1,children:[(0,L.jsx)(R_,{children:(0,L.jsx)(z_,{className:`text-sm`,children:`Discard changes`})}),(0,L.jsx)(`p`,{className:`text-[13px] text-gray-600 break-all font-mono`,children:e.path}),(0,L.jsx)(`p`,{className:`text-[12px] text-gray-500`,children:e.status===`?`?`This file is untracked and will be deleted.`:`This will permanently discard all changes to this file. This action cannot be undone.`}),(0,L.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,L.jsx)(`button`,{onClick:()=>h(!1),className:`px-3 py-1.5 text-xs rounded bg-gray-100 text-gray-700 hover:bg-gray-200`,children:`Cancel`}),(0,L.jsx)(`button`,{onClick:()=>{h(!1),a()},className:`px-3 py-1.5 text-xs rounded bg-red-600 text-white hover:bg-red-700`,children:`Discard`})]})]})})]})}function j8(e){return e.shareMode===`ephemeral`?`ephemeral`:e.shareExternalPort?`direct`:`standard`}function xie({loop:e,open:t,onClose:n,onSaved:r}){let[i,a]=(0,F.useState)(null),[o,s]=(0,F.useState)(e.shareEnabled??!1),[c,l]=(0,F.useState)(e.shareMode===`ephemeral`?`ephemeral`:e.shareExternalPort?`direct`:e.shareMode??`static`),[u,d]=(0,F.useState)(e.shareAlias??``),[f,p]=(0,F.useState)(e.sharePort??3e3),[m,h]=(0,F.useState)(e.shareExternalPort??1e4),[g,_]=(0,F.useState)(e.shareProtocol??`tcp`),[v,y]=(0,F.useState)(null),[b,x]=(0,F.useState)(``),[S,C]=(0,F.useState)(!1),[w,T]=(0,F.useState)(!1),[E,D]=(0,F.useState)(!1),[O,k]=(0,F.useState)(``),[A,ee]=(0,F.useState)(!1),[j,te]=(0,F.useState)(``),[M,ne]=(0,F.useState)(``),[N,re]=(0,F.useState)(j8(e)),[ie,ae]=(0,F.useState)(null),oe=e.id.slice(0,8),se=!!(i&&i.serveEnabled),ce=!!(i&&i.serveDynamicEnabled),le=!!(i&&i.serveEphemeralEnabled),ue=[se,ce,le].filter(Boolean).length>1,de=se&&!ce&&!le,fe=!se&&ce&&!le,pe=!se&&!ce&&le;(0,F.useEffect)(()=>{t&&(Hg().then(a),s(e.shareEnabled??!1),l(e.shareMode===`ephemeral`?`ephemeral`:e.shareExternalPort?`direct`:e.shareMode??`static`),d(e.shareAlias??``),p(e.sharePort??3e3),h(e.shareExternalPort??1e4),_(e.shareProtocol??`tcp`),re(j8(e)),y(null),x(``),k(``),ae(null))},[t,e]),(0,F.useEffect)(()=>{if(!t||!(pe||ue&&N===`ephemeral`)||!e.shareEnabled||e.shareMode!==`ephemeral`)return;let n=!1,r=async()=>{let t=await Ug(e.id);n||ae(t.port)};r();let i=setInterval(r,3e3);return()=>{n=!0,clearInterval(i)}},[t,N,pe,ue,e.id,e.shareEnabled,e.shareMode]),(0,F.useEffect)(()=>{!t||!i||i.serveDynamicEnabled&&(e.shareEnabled&&e.shareExternalPort||!e.shareEnabled&&!e.shareExternalPort&&Gg().then(e=>{e.port&&h(e.port)}))},[t,i,e.shareEnabled,e.shareExternalPort]),(0,F.useEffect)(()=>{t&&qg(oe,e.id).then(e=>{e.available?D(!1):(D(!0),x(`ID "${oe}" is already in use. Please set an alias.`))})},[t,oe,e.id]),(0,F.useEffect)(()=>{if(!u||!t){y(null),x(``);return}let n=setTimeout(async()=>{let t=await qg(u,e.id);y(t.available),x(t.reason??``)},300);return()=>clearTimeout(n)},[u,t,e.id]);let me=u||oe,he=i?.https?`https`:`http`,ge=i?.withPort?`:${i.displayPort}`:``,_e=i?`${he}://${me}${i.baseUrl}${ge}`:``,ve=i?.serveDynamicDomain||i?.ip||`<host-ip>`,ye=g===`static`?`http://${ve}:${m}`:`tcp://${ve}:${m}`,P=i?.serveEphemeralDomain||i?.ip||`<host-ip>`,be=ie?`${g===`udp`?`udp`:`tcp`}://${P}:${ie}`:`(no active port — save & wait for container restart)`,xe=fe||ue&&N===`direct`&&ce&&!pe,Se=pe||ue&&N===`ephemeral`,Ce=Se?be:xe?ye:_e;(0,F.useEffect)(()=>{if(!t||!xe)return;let n=setTimeout(async()=>{ee(!0);let t=await Kg(m,e.id);ee(!1),t.available?k(``):k(t.reason??`Port unavailable`)},400);return()=>clearTimeout(n)},[m,t,c,e.id]);let we=async()=>{if(T(!0),xe){let t=await Kg(m,e.id);if(!t.available){k(t.reason??`Port unavailable`),T(!1);return}}let t={shareEnabled:o};o?Se?(t.shareMode=`ephemeral`,t.sharePort=f,t.shareProtocol=g===`static`?`tcp`:g,t.shareAlias=void 0,t.shareExternalPort=void 0):xe?(t.shareMode=`port`,t.sharePort=f,t.shareExternalPort=m,t.shareProtocol=g,t.shareAlias=void 0):(t.shareMode=c,t.shareAlias=u.trim()||void 0,c===`port`&&(t.sharePort=f),t.shareExternalPort=void 0,t.shareProtocol=void 0):(t.shareMode=void 0,t.shareAlias=void 0,t.sharePort=void 0);let i=await fetch(`/api/loops/${e.id}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify(t)});if(T(!1),i.ok)te(`Saved`),await r?.(),setTimeout(()=>{te(``),n()},800);else try{ne((await i.json()).error??`Save failed (${i.status})`)}catch{ne(`Save failed (${i.status})`)}},Te=async()=>{try{await navigator.clipboard.writeText(Ce),C(!0),setTimeout(()=>C(!1),1500)}catch{window.prompt(`Copy this URL:`,Ce)}},Ee=!w&&!O&&!A&&(Se?f>=1&&f<=65535:(!xe||m>=1024)&&(!xe||f>=1||g===`static`)&&(xe||c!==`port`||!E||u.trim().length>0)&&(xe||c!==`port`||f>=1024));return i?(0,L.jsx)(P_,{open:t,onOpenChange:e=>{e||n()},children:(0,L.jsxs)(L_,{className:`sm:max-w-md bg-white max-h-[85vh] overflow-y-auto`,children:[(0,L.jsxs)(R_,{children:[(0,L.jsxs)(z_,{className:`flex items-center gap-2 text-sm`,children:[(0,L.jsx)(qt,{size:16}),`Share Artifact`]}),(0,L.jsx)(Pee,{className:`sr-only`,children:`Share this artifact via a public URL.`})]}),(0,L.jsxs)(`div`,{className:`space-y-4 text-[13px]`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,L.jsx)(`span`,{className:`text-sm text-gray-700`,children:`Enable sharing`}),(0,L.jsx)(`button`,{onClick:()=>s(!o),className:`w-10 h-5 rounded-full transition-colors ${o?`bg-blue-600`:`bg-gray-300`}`,children:(0,L.jsx)(`div`,{className:`w-4 h-4 rounded-full bg-white shadow transition-transform ${o?`translate-x-5`:`translate-x-0.5`}`})})]}),o&&(0,L.jsxs)(L.Fragment,{children:[ue&&(0,L.jsxs)(`div`,{className:`flex gap-1.5 border-b border-gray-200 pb-2`,children:[se&&(0,L.jsx)(`button`,{onClick:()=>{re(`standard`),l(`static`)},className:`px-3 py-1 text-xs rounded-t ${N===`standard`?`bg-blue-50 text-blue-700 font-medium`:`text-gray-500 hover:text-gray-700`}`,children:`Subdomain`}),ce&&(0,L.jsx)(`button`,{onClick:()=>{re(`direct`),l(`direct`)},className:`px-3 py-1 text-xs rounded-t ${N===`direct`?`bg-blue-50 text-blue-700 font-medium`:`text-gray-500 hover:text-gray-700`}`,children:`Direct Port`}),le&&(0,L.jsx)(`button`,{onClick:()=>{re(`ephemeral`),l(`ephemeral`)},className:`px-3 py-1 text-xs rounded-t ${N===`ephemeral`?`bg-blue-50 text-blue-700 font-medium`:`text-gray-500 hover:text-gray-700`}`,children:`Ephemeral`})]}),(de||ue&&N===`standard`)&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:`Share mode`}),(0,L.jsxs)(`div`,{className:`grid grid-cols-2 gap-1.5 mt-1`,children:[(0,L.jsx)(`button`,{onClick:()=>l(`static`),className:`px-2 py-1.5 text-xs rounded border ${c===`static`?`bg-blue-50 border-blue-300 text-blue-700`:`border-gray-200 text-gray-600`}`,children:`Static files`}),(0,L.jsx)(`button`,{onClick:()=>l(`port`),className:`px-2 py-1.5 text-xs rounded border ${c===`port`?`bg-blue-50 border-blue-300 text-blue-700`:`border-gray-200 text-gray-600`}`,children:`Port proxy`})]})]}),(0,L.jsxs)(`div`,{children:[(0,L.jsxs)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:[`Alias `,E?(0,L.jsx)(`span`,{className:`text-red-500`,children:`(required)`}):`(optional)`]}),(0,L.jsx)(`input`,{value:u,onChange:e=>d(e.target.value.toLowerCase().replace(/[^a-z0-9-]/g,``)),className:`w-full mt-1 px-2 py-1.5 text-sm border rounded outline-none focus:border-gray-300 ${E?`border-red-300 bg-red-50`:`border-gray-200`}`,placeholder:E?`Set an alias to resolve conflict`:`my-project`}),E&&(0,L.jsxs)(`span`,{className:`text-[11px] text-red-500 mt-0.5 flex items-center gap-1`,children:[(0,L.jsx)(bt,{size:11}),` `,b||`ID "${oe}" is already in use`]}),!E&&v===!0&&(0,L.jsx)(`span`,{className:`text-[11px] text-emerald-600 mt-0.5`,children:`Available`}),!E&&v===!1&&(0,L.jsxs)(`span`,{className:`text-[11px] text-red-500 mt-0.5 flex items-center gap-1`,children:[(0,L.jsx)(bt,{size:11}),` `,b||`Already in use`]})]}),c===`port`&&(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:`Port (1024-65535)`}),(0,L.jsx)(`input`,{type:`number`,min:1024,max:65535,value:f,onChange:e=>p(parseInt(e.target.value,10)||3e3),className:`w-full mt-1 px-2 py-1.5 text-sm border border-gray-200 rounded outline-none focus:border-gray-300`})]})]}),Se&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:`Container port`}),(0,L.jsx)(`input`,{type:`number`,min:1,max:65535,value:f,onChange:e=>p(parseInt(e.target.value,10)||3e3),className:`w-full mt-1 px-2 py-1.5 text-sm border border-gray-200 rounded outline-none focus:border-gray-300`}),(0,L.jsx)(`p`,{className:`text-[10px] text-gray-400 mt-0.5`,children:`The port your app listens on inside the sandbox`})]}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:`Protocol`}),(0,L.jsxs)(`div`,{className:`flex gap-1.5 mt-1`,children:[(0,L.jsx)(`button`,{onClick:()=>_(`tcp`),className:`flex-1 px-2 py-1.5 text-xs rounded border ${g===`tcp`?`bg-blue-50 border-blue-300 text-blue-700`:`border-gray-200 text-gray-600`}`,children:`TCP`}),(0,L.jsx)(`button`,{onClick:()=>_(`udp`),className:`flex-1 px-2 py-1.5 text-xs rounded border ${g===`udp`?`bg-blue-50 border-blue-300 text-blue-700`:`border-gray-200 text-gray-600`}`,children:`UDP`})]})]}),(0,L.jsxs)(`div`,{children:[(0,L.jsxs)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider flex items-center gap-1.5`,children:[`Current host port`,(0,L.jsx)(Sn,{size:10,className:`text-gray-300`})]}),(0,L.jsx)(`div`,{className:`mt-1 px-2 py-1.5 text-sm bg-gray-50 rounded text-gray-700`,children:ie==null?(0,L.jsx)(`span`,{className:`text-gray-400 text-xs`,children:e.shareEnabled&&e.shareMode===`ephemeral`?`(container starting / not running)`:`(save to start — port assigned by kernel on restart)`}):(0,L.jsx)(`span`,{className:`font-mono`,children:ie})}),(0,L.jsxs)(`p`,{className:`text-[10px] text-amber-600 mt-1 flex items-center gap-1`,children:[(0,L.jsx)(bt,{size:10}),` Changes on every loop restart. Saving also restarts the container.`]})]})]}),(fe||ue&&N===`direct`&&!Se)&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:`External port`}),(0,L.jsxs)(`div`,{className:`flex gap-1.5 mt-1`,children:[(0,L.jsx)(`input`,{type:`number`,min:1024,max:65535,value:m,onChange:e=>h(parseInt(e.target.value,10)||1e4),className:`flex-1 px-2 py-1.5 text-sm border border-gray-200 rounded outline-none focus:border-gray-300`,placeholder:`10000`}),(0,L.jsx)(`button`,{onClick:async()=>{let e=await Gg();e.port&&h(e.port)},className:`px-2 py-1.5 rounded border border-gray-200 hover:bg-gray-100 text-gray-500`,title:`Pick a random available port`,children:(0,L.jsx)(Mn,{size:14})})]}),(0,L.jsx)(`p`,{className:`text-[10px] text-gray-400 mt-0.5`,children:`The public port clients connect to`}),A&&(0,L.jsx)(`span`,{className:`text-[11px] text-gray-400 mt-0.5`,children:`Checking availability…`}),O&&(0,L.jsxs)(`span`,{className:`text-[11px] text-red-500 mt-0.5 flex items-center gap-1`,children:[(0,L.jsx)(bt,{size:11}),` `,O]}),!A&&!O&&(0,L.jsx)(`span`,{className:`text-[11px] text-emerald-600 mt-0.5`,children:`Available`})]}),g!==`static`&&(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:`Container port`}),(0,L.jsx)(`input`,{type:`number`,min:1,max:65535,value:f,onChange:e=>p(parseInt(e.target.value,10)||3e3),className:`w-full mt-1 px-2 py-1.5 text-sm border border-gray-200 rounded outline-none focus:border-gray-300`}),(0,L.jsx)(`p`,{className:`text-[10px] text-gray-400 mt-0.5`,children:`The port your app listens on inside the sandbox`})]}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:`Protocol`}),(0,L.jsxs)(`div`,{className:`flex gap-1.5 mt-1`,children:[(0,L.jsx)(`button`,{onClick:()=>_(`tcp`),className:`flex-1 px-2 py-1.5 text-xs rounded border ${g===`tcp`?`bg-blue-50 border-blue-300 text-blue-700`:`border-gray-200 text-gray-600`}`,children:`TCP`}),i.serveDynamicUdpEnabled&&(0,L.jsx)(`button`,{onClick:()=>_(`udp`),className:`flex-1 px-2 py-1.5 text-xs rounded border ${g===`udp`?`bg-blue-50 border-blue-300 text-blue-700`:`border-gray-200 text-gray-600`}`,children:`UDP`}),i.serveDynamicStaticEnabled&&(0,L.jsx)(`button`,{onClick:()=>_(`static`),className:`flex-1 px-2 py-1.5 text-xs rounded border ${g===`static`?`bg-blue-50 border-blue-300 text-blue-700`:`border-gray-200 text-gray-600`}`,children:`Static`})]})]})]}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:`Access URL`}),(0,L.jsxs)(`div`,{className:`flex gap-2 mt-1`,children:[(0,L.jsx)(`code`,{className:`flex-1 px-2 py-1.5 text-xs bg-gray-50 rounded text-gray-700 truncate`,children:Ce}),(0,L.jsx)(`button`,{onClick:Te,className:`px-2 py-1.5 rounded hover:bg-gray-100 text-gray-500`,title:`Copy URL`,children:S?(0,L.jsx)(mt,{size:14,className:`text-emerald-600`}):(0,L.jsx)(Dt,{size:14})})]}),(0,L.jsx)(`p`,{className:`text-[10px] text-gray-400 mt-1`,children:xe?`Direct TCP/UDP access — no domain needed`:`Domain suffix configured in Settings → Workspace → Workspace Serve`})]})]}),(0,L.jsxs)(`div`,{className:`flex items-center justify-end gap-2 pt-2`,children:[M&&(0,L.jsx)(`span`,{className:`text-xs text-red-500`,children:M}),j&&(0,L.jsxs)(`span`,{className:`text-xs text-emerald-600 flex items-center gap-1`,children:[(0,L.jsx)(mt,{size:12}),` `,j]}),(0,L.jsx)(`button`,{onClick:n,className:`px-3 py-1.5 text-xs rounded bg-gray-100 text-gray-700 hover:bg-gray-200`,children:`Cancel`}),(0,L.jsx)(`button`,{onClick:we,disabled:!Ee,className:`px-3 py-1.5 text-xs rounded bg-blue-600 text-white hover:bg-blue-700 disabled:opacity-40`,children:w?`Saving...`:`Save`})]})]})]})}):null}var Sie=(0,F.lazy)(()=>A(()=>import(`./Editor-BN7Q5g4N.js`).then(e=>({default:e.Editor})),__vite__mapDeps([78,3,79,80,81]))),Cie=(0,F.lazy)(()=>A(()=>import(`./Terminal-DQxchB0u.js`).then(e=>({default:e.Terminal})),__vite__mapDeps([82,3,80,83])));function wie(){let{id:e}=xi(),t=D_();if(!e)return(0,L.jsx)(Gi,{to:`/loop`,replace:!0});if(!t.currentUser)return(0,L.jsx)(cie,{});let n=t.loops.find(t=>t.id===e);return t.loopsLoading?null:n?(0,L.jsxs)(`div`,{className:`h-full w-full flex min-h-0`,children:[(0,L.jsx)(Tie,{currentId:e}),(0,L.jsx)(Eie,{meta:n},e)]}):(0,L.jsx)(Gi,{to:`/loop`,replace:!0})}function Tie({currentId:e}){let t=_i(),[n,r]=(0,F.useState)(()=>localStorage.getItem(`loopat:loopsList:collapsed`)===`1`),i=f6(),a=e=>{r(e),localStorage.setItem(`loopat:loopsList:collapsed`,e?`1`:`0`)},o=(0,L.jsxs)(`aside`,{className:`w-60 shrink-0 border-r border-gray-200 bg-white flex flex-col h-full`,children:[(0,L.jsx)(`div`,{className:`px-2 pt-1.5 border-b border-gray-200 flex items-center justify-end`,children:(0,L.jsx)(`button`,{type:`button`,onClick:()=>a(!0),className:`w-6 h-6 flex items-center justify-center text-gray-400 hover:text-gray-700 hover:bg-gray-100 rounded`,title:`collapse sidebar`,children:(0,L.jsx)(gn,{size:14})})}),(0,L.jsx)(C8,{currentId:e,onSelect:e=>{t(`/loop/${e}`),i&&a(!0)}})]});return n?(0,L.jsx)(`aside`,{className:`w-9 shrink-0 border-r border-gray-200 bg-white flex flex-col items-center pt-2`,children:(0,L.jsx)(`button`,{type:`button`,onClick:()=>a(!1),className:`w-7 h-7 flex items-center justify-center text-gray-500 hover:text-gray-900 hover:bg-gray-100 rounded`,title:`expand sidebar`,children:(0,L.jsx)(_n,{size:16})})}):i?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`aside`,{className:`w-9 shrink-0 border-r border-gray-200 bg-white flex flex-col items-center pt-2`,children:(0,L.jsx)(`button`,{type:`button`,onClick:()=>a(!0),className:`w-7 h-7 flex items-center justify-center text-gray-500 hover:text-gray-900 hover:bg-gray-100 rounded`,title:`collapse sidebar`,children:(0,L.jsx)(gn,{size:16})})}),(0,L.jsxs)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>a(!0),children:[(0,L.jsx)(`div`,{className:`absolute inset-0 bg-black/30`}),(0,L.jsx)(`div`,{className:`absolute left-0 top-0 bottom-0 w-64 max-w-[80vw] shadow-xl`,onClick:e=>e.stopPropagation(),children:o})]})]}):o}function Eie({meta:e}){let t=D_(),n=f6(),[r,i]=(0,F.useState)([]),[a,o]=(0,F.useState)(null),[s,c]=(0,F.useState)(null),[l,u]=(0,F.useState)([]),[d,f]=(0,F.useState)(!1),[p,m]=(0,F.useState)(null);(0,F.useEffect)(()=>{Hg().then(m)},[]);let[h,g]=(0,F.useState)(null),_=e=>{c(e),g(null),i(e=>e.includes(`editor`)?e:[...e,`editor`])},{runtime:v,connected:y,reconnecting:b,running:x,viewers:S,extra:C,queue:w,onClearQueue:T}=k6(e.id,t.currentUser?.id??``,_),E=S8((0,F.useMemo)(()=>[e.id],[e.id])),D=E[e.id]?.phase===`preparing`,O=E[e.id]?.status;(0,F.useEffect)(()=>{Vh(e.id).then(u),Nh(e.id),t.currentUser?.id&&localStorage.setItem(`loopat:lastLoop:${t.currentUser.id}`,e.id)},[e.id]);let k=pi(),A=_i(),ee=k.state?.kickoff;(0,F.useEffect)(()=>{!ee||!y||(C.enqueueMessage(ee),A(k.pathname,{replace:!0,state:null}))},[ee,y]);let j=e=>{i(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},te=e=>{i(t=>t.includes(e)?t.filter(t=>t!==e):[e])},M=e=>{i(t=>t.filter(t=>t!==e)),o(t=>t===e?null:t)},ne=r.length>0,N=r.filter(e=>e===`editor`||e===`terminal`),re=r.filter(e=>e!==`editor`&&e!==`terminal`),ie=N.length>0,ae=re.length>0,[oe,se]=(0,F.useState)(()=>{let e=parseInt(localStorage.getItem(`loopat:chatPct`)||``,10);return!isNaN(e)&&e>=10&&e<=90?e:55}),[ce,le]=(0,F.useState)(()=>{let e=parseInt(localStorage.getItem(`loopat:otherPct`)||``,10);return!isNaN(e)&&e>=5&&e<=50?e:18});(0,F.useEffect)(()=>{if(!ae){let e=parseInt(localStorage.getItem(`loopat:otherPct`)||``,10);!isNaN(e)&&e>=5&&e<=50&&le(e)}if(!ie&&!ae){let e=parseInt(localStorage.getItem(`loopat:chatPct`)||``,10);!isNaN(e)&&e>=10&&e<=90&&se(e)}},[ie,ae]);let ue=e=>{!isNaN(e.chat)&&e.chat>0&&localStorage.setItem(`loopat:chatPct`,String(Math.round(e.chat))),!isNaN(e.otherCol)&&e.otherCol>0&&localStorage.setItem(`loopat:otherPct`,String(Math.round(e.otherCol)))},de=n=>{let r=a===n;return(0,L.jsx)(Mie,{loopId:e.id,meta:e,mode:n,onClose:()=>M(n),pickedFile:s,onPickFile:_,currentUserId:t.currentUser?.id??``,isFullscreen:r,onToggleFullscreen:()=>o(r?null:n),onEditorSelection:g},n)};return(0,L.jsxs)(`div`,{className:`flex-1 min-w-0 min-h-0 flex flex-col`,children:[(0,L.jsx)(Die,{meta:e,mounts:l,connected:y,reconnecting:b,running:x,viewers:S,queue:w,onClearQueue:T,openPanels:r,toggleMode:j,onShareWork:()=>f(!0),showShareButton:!p||p.serveEnabled||p.serveDynamicEnabled||p.serveEphemeralEnabled}),e.contextWarnings&&e.contextWarnings.length>0&&(0,L.jsxs)(`div`,{className:`shrink-0 border-b border-amber-200 bg-amber-50 px-4 py-2 text-[12px] text-amber-800 leading-relaxed`,children:[(0,L.jsx)(`span`,{className:`font-semibold`,children:`⚠ Context not fully loaded.`}),` `,`This loop's knowledge/notes couldn't be cloned — it runs with an empty context until the access is fixed (check the key has access to the repo):`,(0,L.jsx)(`ul`,{className:`mt-1 ml-4 list-disc`,children:e.contextWarnings.map((e,t)=>(0,L.jsx)(`li`,{className:`font-mono text-[11px] break-all`,children:e},t))})]}),(0,L.jsxs)(`div`,{className:`relative flex-1 min-h-0 flex flex-col`,children:[D&&(0,L.jsx)(Aie,{detail:O}),n?(0,L.jsx)(`div`,{className:`flex-1 min-h-0`,children:(0,L.jsx)(O6,{extra:C,children:(0,L.jsx)(tw,{runtime:v,children:(0,L.jsx)(b8,{archived:e.archived===!0,onUnarchive:()=>t.setLoopArchived(e.id,!1),repo:e.repo,branch:e.branch,title:e.title,driver:e.driver??e.createdBy,driverHistory:e.driverHistory,rfdRequestedAt:e.rfdRequestedAt,rfdRequestedBy:e.rfdRequestedBy,onTakeDrive:()=>t.takeDrive(e.id),pickedFile:s,editorSelection:h})})})}):ne?(0,L.jsxs)(BE,{orientation:`horizontal`,className:`flex-1 min-w-0 min-h-0`,onLayoutChange:ue,children:[(0,L.jsx)(UE,{id:`chat`,minSize:20,defaultSize:oe,className:`flex flex-col min-h-0 min-w-0`,children:(0,L.jsx)(O6,{extra:C,children:(0,L.jsx)(tw,{runtime:v,children:(0,L.jsx)(b8,{archived:e.archived===!0,onUnarchive:()=>t.setLoopArchived(e.id,!1),repo:e.repo,branch:e.branch,title:e.title,driver:e.driver??e.createdBy,driverHistory:e.driverHistory,rfdRequestedAt:e.rfdRequestedAt,rfdRequestedBy:e.rfdRequestedBy,onTakeDrive:()=>t.takeDrive(e.id),pickedFile:s,editorSelection:h})})})}),(ie||ae)&&(0,L.jsx)(KE,{className:`relative w-4 -mx-1.5 cursor-col-resize group flex items-center justify-center after:absolute after:inset-y-0 after:left-1/2 after:w-px after:-translate-x-1/2 after:bg-gray-200 after:transition-colors hover:after:bg-blue-400`,children:(0,L.jsx)(`div`,{className:`absolute top-1/2 -translate-y-1/2 h-8 w-1.5 rounded-full bg-gray-300 group-hover:bg-blue-400 transition-colors`})}),ie&&(0,L.jsx)(UE,{id:`editorCol`,minSize:15,defaultSize:30,className:`flex flex-col min-h-0 min-w-0`,children:N.length>1?(0,L.jsx)(BE,{orientation:`vertical`,className:`flex-1 min-h-0`,children:N.map((e,t)=>(0,L.jsxs)(F.Fragment,{children:[t>0&&(0,L.jsx)(KE,{className:`relative h-4 -my-1.5 cursor-row-resize group flex items-center justify-center after:absolute after:left-0 after:right-0 after:top-1/2 after:h-px after:-translate-y-1/2 after:bg-gray-200 after:transition-colors hover:after:bg-blue-400`,children:(0,L.jsx)(`div`,{className:`absolute left-1/2 -translate-x-1/2 w-8 h-1.5 rounded-full bg-gray-300 group-hover:bg-blue-400 transition-colors`})}),(0,L.jsx)(UE,{id:e,minSize:10,defaultSize:100/N.length,className:`flex flex-col min-h-0 min-w-0`,children:de(e)})]},e))}):de(N[0])}),ie&&ae&&(0,L.jsx)(KE,{className:`relative w-4 -mx-1.5 cursor-col-resize group flex items-center justify-center after:absolute after:inset-y-0 after:left-1/2 after:w-px after:-translate-x-1/2 after:bg-gray-200 after:transition-colors hover:after:bg-blue-400`,children:(0,L.jsx)(`div`,{className:`absolute top-1/2 -translate-y-1/2 h-8 w-1.5 rounded-full bg-gray-300 group-hover:bg-blue-400 transition-colors`})}),ae&&(0,L.jsx)(UE,{id:`otherCol`,minSize:15,defaultSize:ce,className:`flex flex-col min-h-0 min-w-0`,children:re.length>1?(0,L.jsx)(BE,{orientation:`vertical`,className:`flex-1 min-h-0`,children:re.map((e,t)=>(0,L.jsxs)(F.Fragment,{children:[t>0&&(0,L.jsx)(KE,{className:`relative h-4 -my-1.5 cursor-row-resize group flex items-center justify-center after:absolute after:left-0 after:right-0 after:top-1/2 after:h-px after:-translate-y-1/2 after:bg-gray-200 after:transition-colors hover:after:bg-blue-400`,children:(0,L.jsx)(`div`,{className:`absolute left-1/2 -translate-x-1/2 w-8 h-1.5 rounded-full bg-gray-300 group-hover:bg-blue-400 transition-colors`})}),(0,L.jsx)(UE,{id:e,minSize:10,defaultSize:100/re.length,className:`flex flex-col min-h-0 min-w-0`,children:de(e)})]},e))}):de(re[0])})]}):(0,L.jsx)(`div`,{className:`flex-1 min-h-0`,children:(0,L.jsx)(O6,{extra:C,children:(0,L.jsx)(tw,{runtime:v,children:(0,L.jsx)(b8,{archived:e.archived===!0,onUnarchive:()=>t.setLoopArchived(e.id,!1),repo:e.repo,branch:e.branch,title:e.title,driver:e.driver??e.createdBy,driverHistory:e.driverHistory,rfdRequestedAt:e.rfdRequestedAt,rfdRequestedBy:e.rfdRequestedBy,onTakeDrive:()=>t.takeDrive(e.id),pickedFile:s,editorSelection:h})})})})]}),ne&&n&&r.map(e=>(0,L.jsx)(F.Fragment,{children:de(e)},e)),n&&(0,L.jsx)(`div`,{className:`fixed bottom-0 left-0 z-30 w-9 flex flex-col items-center gap-0.5 pb-2`,children:[`terminal`,`editor`,`workdir`,`git`].map(e=>(0,L.jsx)(`button`,{type:`button`,onClick:()=>te(e),className:`w-7 h-7 flex items-center justify-center rounded text-xs ${r.includes(e)?`bg-gray-200 text-gray-900`:`text-gray-400 hover:text-gray-700 hover:bg-gray-100`}`,title:e,children:e===`terminal`?`▷`:e===`editor`?`✎`:e===`workdir`?`▤`:`⑂`},e))}),(0,L.jsx)(xie,{loop:e,open:d,onClose:()=>f(!1),onSaved:async()=>{await t.refresh()}})]})}function Die({meta:e,mounts:t,connected:n,reconnecting:r,running:i,viewers:a,queue:o,onClearQueue:s,openPanels:c,toggleMode:l,onShareWork:u,showShareButton:d}){let f=f6(),p=_i(),m=D_(),[h,g]=(0,F.useState)(f),[_,v]=(0,F.useState)(!1),[y,b]=(0,F.useState)(!1),[x,S]=(0,F.useState)(e.title),C=m.currentUser?.id===e.createdBy,w=async()=>{if(!_){v(!0);try{let t=await bee(e.id);t&&p(`/loop/${t.id}`)}finally{v(!1)}}},T=async()=>{let t=x.trim();if(!t||t===e.title){b(!1),S(e.title);return}b(!1),await m.setLoopTitle(e.id,t)||S(e.title)},E=(e,t)=>(0,L.jsx)(`button`,{className:c.includes(t)?`px-2 py-0.5 rounded bg-gray-100 text-gray-900`:`px-2 py-0.5 rounded text-gray-500 hover:text-gray-900 hover:bg-gray-50`,onClick:()=>l(t),children:e},t);return(0,L.jsxs)(`header`,{className:`group/header px-3 md:px-5 shrink-0 border-b border-gray-200 `+(h?`py-1.5`:`pt-3 pb-2`),children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,L.jsx)(`button`,{type:`button`,onClick:()=>g(e=>!e),className:`text-gray-400 hover:text-gray-700 -ml-1 p-0.5 rounded hover:bg-gray-100`,title:h?`expand header`:`collapse header`,children:(0,L.jsx)(ht,{size:14,className:`transition-transform `+(h?`-rotate-90`:``)})}),y?(0,L.jsx)(`input`,{type:`text`,value:x,autoFocus:!0,onChange:e=>S(e.target.value),onKeyDown:t=>{t.key===`Enter`&&!t.nativeEvent.isComposing?(t.preventDefault(),T()):t.key===`Escape`&&(t.preventDefault(),b(!1),S(e.title))},onBlur:T,maxLength:200,className:`text-[14px] md:text-[15px] font-medium text-gray-900 bg-white border border-blue-400 rounded px-1 py-0 outline-none min-w-[120px]`}):(0,L.jsx)(`span`,{className:`text-[14px] md:text-[15px] font-medium text-gray-900 `+(C?`cursor-pointer hover:bg-gray-100 rounded px-1 -mx-1`:``),onClick:()=>{C&&(S(e.title),b(!0))},title:C?`click to rename`:void 0,children:e.title}),(0,L.jsxs)(`span`,{className:`text-xs text-gray-500`,children:[`driver: `,(0,L.jsx)(`span`,{className:`text-gray-900`,children:e.driver??e.createdBy})]}),e.rfdRequestedAt&&(0,L.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-amber-100 text-amber-800 border border-amber-200 font-medium tracking-wide`,title:`released for drive by ${e.rfdRequestedBy??`?`} at ${e.rfdRequestedAt}`,children:`RFD`}),!n&&r&&(0,L.jsx)(`span`,{className:`text-[11px] text-amber-600`,children:`reconnecting…`}),i&&(0,L.jsx)(`span`,{className:`text-[11px] text-blue-600`,children:`running`}),a>1&&(0,L.jsxs)(`span`,{title:`people watching`,className:`text-[11px] px-1.5 py-0.5 rounded bg-emerald-50 text-emerald-800 border border-emerald-200`,children:[`👥 `,a]}),(0,L.jsx)(`div`,{className:`flex-1`}),(0,L.jsxs)(`button`,{type:`button`,onClick:w,disabled:_,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] border bg-white text-violet-700 border-violet-300 hover:bg-violet-50 disabled:opacity-50`,title:`Spawn a child loop seeded with this loop's conversation, for sedimenting reusable insights into knowledge/`,children:[(0,L.jsx)(Bt,{size:11}),_?`Distilling…`:`Distill`]}),d!==!1&&(0,L.jsxs)(`button`,{onClick:u,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] border ${e.shareEnabled?`bg-blue-50 text-blue-700 border-blue-200 hover:bg-blue-100`:`bg-white text-gray-700 border-gray-300 hover:bg-gray-100`}`,title:`Share workspace artifact (static files or port forward)`,children:[(0,L.jsx)(qt,{size:11}),`Share Artifact`]}),(0,L.jsx)(kie,{meta:e}),(0,L.jsx)(Oie,{meta:e})]}),!h&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`div`,{className:`text-xs text-gray-500 mt-1.5 flex items-center gap-2 flex-wrap`,children:[(0,L.jsxs)(`span`,{className:`font-mono`,children:[`~/.loopat/loops/`,e.id.slice(0,8),`/workdir`]}),(0,L.jsx)(`span`,{children:`·`}),(0,L.jsx)(`span`,{children:`main`}),a>0&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`span`,{children:`·`}),(0,L.jsxs)(`span`,{children:[a,` viewing`]})]}),(0,L.jsx)(`div`,{className:`flex-1`}),(0,L.jsxs)(`div`,{className:`flex items-center gap-1 text-[11px]`,children:[E(`ℹ info`,`info`),E(`▤ workdir`,`workdir`),E(`✎ editor`,`editor`),E(`▷ terminal`,`terminal`),(0,L.jsx)(`button`,{className:c.includes(`git`)?`px-2 py-0.5 rounded bg-gray-100 text-gray-900`:`px-2 py-0.5 rounded text-gray-500 hover:text-gray-900 hover:bg-gray-50`,onClick:()=>l(`git`),title:`git changes`,children:(0,L.jsx)(Gt,{size:14})})]})]}),(0,L.jsxs)(`div`,{className:`mt-2 flex items-center gap-1.5 flex-wrap text-[11px]`,children:[(0,L.jsx)(`span`,{className:`text-gray-400`,children:`context:`}),t.map(e=>(0,L.jsx)(M8,{label:e.name,value:e.name===`knowledge`?`ro`:`rw`},e.path))]}),e.config?.profiles&&e.config.profiles.length>0&&(0,L.jsx)(jie,{profiles:e.config.profiles}),(0,L.jsxs)(`div`,{className:`mt-1 flex items-center gap-1.5 flex-wrap text-[11px]`,children:[(0,L.jsx)(`span`,{className:`text-gray-400`,children:`vault:`}),(0,L.jsx)(M8,{label:e.config?.vault??`default`,value:`loaded`})]})]})]})}function Oie({meta:e}){let t=D_(),[n,r]=(0,F.useState)(!1),[i,a]=(0,F.useState)(!1),o=t.currentUser?.id===e.createdBy,s=e.public===!0;if(!t.currentUser)return null;let c=`${location.origin}/loop/${e.id}`;return o?(0,L.jsxs)(`div`,{className:`inline-flex items-center gap-1`,children:[s&&(0,L.jsxs)(`button`,{type:`button`,onClick:async()=>{try{await navigator.clipboard.writeText(c),r(!0),setTimeout(()=>r(!1),1500)}catch{}},title:c,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] text-gray-600 hover:bg-gray-100`,children:[n?(0,L.jsx)(mt,{size:11}):(0,L.jsx)(Dt,{size:11}),(0,L.jsx)(`span`,{className:`hidden md:inline`,children:n?`copied`:`copy link`})]}),(0,L.jsxs)(`button`,{type:`button`,onClick:async()=>{if(!(!o||i)){a(!0);try{await t.setLoopPublic(e.id,!s)}finally{a(!1)}}},disabled:i,title:s?`stop sharing`:`share publicly (anyone with the link can view)`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] border disabled:opacity-50 `+(s?`bg-emerald-50 text-emerald-800 border-emerald-200 hover:bg-emerald-100`:`bg-white text-gray-700 border-gray-300 hover:bg-gray-100`),children:[s?(0,L.jsx)(qt,{size:11}):(0,L.jsx)(on,{size:11}),s?`shared`:`share`]})]}):(0,L.jsxs)(`span`,{title:s?`this loop is shared publicly`:`this loop is private`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] `+(s?`bg-emerald-50 text-emerald-800 border border-emerald-200`:`bg-gray-100 text-gray-600`),children:[s?(0,L.jsx)(qt,{size:11}):(0,L.jsx)(on,{size:11}),s?`public`:`private`]})}function kie({meta:e}){let t=D_(),[n,r]=(0,F.useState)(!1);if(!t.currentUser)return null;let i=e.driver??e.createdBy,a=t.currentUser.id===i;return e.rfdRequestedAt?(0,L.jsxs)(`button`,{type:`button`,disabled:n,onClick:async()=>{r(!0);try{await t.takeDrive(e.id)}finally{r(!1)}},title:`released for drive by ${e.rfdRequestedBy??`?`} — click to take over`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] border bg-amber-500 text-white border-amber-600 hover:bg-amber-600 disabled:opacity-50`,children:[(0,L.jsx)(Jt,{size:11}),`Drive`]}):a?(0,L.jsxs)(`button`,{type:`button`,disabled:n,onClick:async()=>{if(window.confirm(`Request For Drive: this will tear down the sandbox and release the loop so anyone else can take over. Continue?`)){r(!0);try{await t.requestDrive(e.id)}finally{r(!1)}}},title:`Release this loop so someone else can drive it`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] border bg-white text-amber-700 border-amber-300 hover:bg-amber-50 disabled:opacity-50`,children:[(0,L.jsx)(Jt,{size:11}),`Request For Drive`]}):null}function Aie({detail:e}){return(0,L.jsx)(`div`,{className:`absolute inset-0 z-30 flex items-center justify-center bg-white/70 backdrop-blur-sm`,children:(0,L.jsxs)(`div`,{className:`max-w-md mx-6 px-6 py-5 rounded-xl border border-blue-200 bg-white shadow-lg text-center`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-center gap-2 mb-2`,children:[(0,L.jsx)(`span`,{className:`inline-block w-4 h-4 rounded-full border-2 border-blue-500 border-t-transparent animate-spin`}),(0,L.jsx)(`span`,{className:`text-sm font-medium text-gray-900`,children:`Preparing this loop’s sandbox…`})]}),(0,L.jsxs)(`p`,{className:`text-[12px] text-gray-600 leading-relaxed`,children:[`Installing the toolchain from `,(0,L.jsx)(`code`,{className:`font-mono text-[11px] bg-gray-100 px-1 rounded`,children:`mise.toml`}),`. Terminal and chat are paused until tools are ready — this only happens the first time.`]}),e&&e!==`Ready`&&(0,L.jsx)(`p`,{className:`mt-2 text-[11px] font-mono text-blue-700 break-words`,children:e})]})})}function M8({label:e,value:t,title:n}){return(0,L.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded bg-gray-100 text-[11px]`,title:n,children:[(0,L.jsxs)(`span`,{className:`text-gray-500`,children:[e,`:`]}),(0,L.jsx)(`span`,{className:`text-gray-900 font-medium`,children:t})]})}function jie({profiles:e}){let[t,n]=(0,F.useState)({});return(0,F.useEffect)(()=>{let e=!1;return Mh().then(t=>{if(e)return;let r={};for(let e of t)e.description&&(r[e.name]=e.description);n(r)}).catch(()=>{}),()=>{e=!0}},[]),(0,L.jsxs)(`div`,{className:`mt-1 flex items-center gap-1.5 flex-wrap text-[11px]`,children:[(0,L.jsx)(`span`,{className:`text-gray-400`,children:`profiles:`}),e.map(e=>(0,L.jsx)(M8,{label:e,value:`active`,title:t[e]},e))]})}function Mie({loopId:e,meta:t,mode:n,onClose:r,pickedFile:i,onPickFile:a,currentUserId:o,isFullscreen:s,onToggleFullscreen:c,onEditorSelection:l}){let u=f6(),[d,f]=(0,F.useState)(()=>{let e=localStorage.getItem(`loopat:mobilePanelPct`);return e?Math.max(20,Math.min(95,parseInt(e)||55)):55}),p=(0,F.useRef)(null),m=e=>{localStorage.setItem(`loopat:mobilePanelPct`,String(e))},h=e=>{if(p.current={startY:e,startPct:d},s){let t=Math.round(e/window.innerHeight*100),n=Math.max(20,Math.min(95,t));f(n),m(n),c?.()}},g=e=>{if(!p.current)return;let t=e-p.current.startY,n=Math.round(t/window.innerHeight*100),r=Math.max(20,Math.min(95,p.current.startPct+n));f(r),m(r)},_=()=>{p.current=null},v=e=>{e.preventDefault(),e.stopPropagation(),h(e.touches[0].clientY)},y=e=>{e.preventDefault(),g(e.touches[0].clientY)},b=e=>{e.preventDefault(),_()},x=e=>{e.pointerType!==`touch`&&(e.preventDefault(),e.target.setPointerCapture(e.pointerId),h(e.clientY))},S=e=>{e.pointerType===`touch`||!p.current||g(e.clientY)},C=e=>{e.pointerType!==`touch`&&_()},w=(0,L.jsxs)(`aside`,{className:`flex-1 min-w-0 bg-white flex flex-col`,children:[(0,L.jsxs)(`header`,{className:`px-3 h-8 shrink-0 border-b border-gray-200 flex items-center gap-1 text-[11px] text-gray-500`,children:[(0,L.jsx)(`span`,{className:`capitalize`,children:n}),n===`editor`&&(0,L.jsx)(`span`,{className:`ml-2 truncate text-gray-700`,children:i||`(no file)`}),(0,L.jsx)(`div`,{className:`flex-1`}),(n===`editor`||n===`terminal`)&&(0,L.jsx)(`button`,{className:`text-gray-400 hover:text-gray-700 px-1 rounded hover:bg-gray-100`,onClick:c,title:s?`restore`:`maximize`,children:s?(0,L.jsx)(dn,{size:13}):(0,L.jsx)(cn,{size:13})}),(0,L.jsx)(`button`,{className:`text-gray-500 hover:text-gray-900 px-1 rounded hover:bg-gray-100`,onClick:r,title:`close panel`,children:`✕`})]}),n===`info`&&(0,L.jsx)(Nie,{meta:t}),n===`workdir`&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(pie,{loopId:e,onPick:a,picked:i}),(0,L.jsxs)(`div`,{className:`border-t border-gray-200 px-3 py-2 text-[11px] text-gray-500`,children:[`⑂ `,(0,L.jsx)(`span`,{className:`text-gray-900`,children:`main`})]})]}),(0,L.jsxs)(F.Suspense,{fallback:(0,L.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-gray-400 text-sm`,children:`Loading...`}),children:[n===`editor`&&(0,L.jsx)(Sie,{loopId:e,path:i,onSelectionChange:l}),n===`terminal`&&(0,L.jsx)(`div`,{className:`flex-1 min-h-0 bg-[#1a1c20] overflow-hidden`,children:(0,L.jsx)(Cie,{loopId:e,currentUserId:o})}),n===`git`&&(0,L.jsx)(yie,{loopId:e,onClose:r,onPickFile:a})]})]});return u?(0,L.jsxs)(`div`,{className:`fixed inset-x-0 top-0 z-40 bg-white rounded-b-xl shadow-xl pointer-events-auto overflow-hidden`,style:{height:s?`100vh`:`${d}vh`},children:[(0,L.jsx)(`div`,{className:`absolute inset-0 bottom-7 overflow-y-auto flex flex-col`,children:w}),(0,L.jsx)(`div`,{className:`absolute inset-x-0 bottom-0 h-7 z-10 flex items-center justify-center cursor-row-resize active:bg-gray-50 rounded-b-xl`,style:{touchAction:`none`},onTouchStart:v,onTouchMove:y,onTouchEnd:b,onPointerDown:x,onPointerMove:S,onPointerUp:C,children:(0,L.jsx)(`div`,{className:`w-8 h-1 rounded-full bg-gray-300`})})]}):s?(0,vo.createPortal)((0,L.jsx)(`div`,{className:`fixed inset-0 z-50 flex flex-col`,children:w}),document.body):w}function Nie({meta:e}){let t=D_().currentUser?.id===e.createdBy;return(0,L.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-auto px-5 py-4 text-[13px] text-gray-900`,children:[(0,L.jsxs)(N8,{label:`basics`,children:[(0,L.jsx)(P8,{label:`title`,value:e.title}),(0,L.jsx)(P8,{label:`created`,value:new Date(e.createdAt).toLocaleString()}),(0,L.jsx)(P8,{label:`status`,value:`active`}),(0,L.jsx)(P8,{label:`driver`,value:t?`${e.createdBy} (you)`:e.createdBy}),(0,L.jsx)(P8,{label:`sharing`,value:e.public?`public — /loop/${e.id.slice(0,8)}…`:`private`})]}),(0,L.jsxs)(N8,{label:`workdir`,children:[(0,L.jsx)(P8,{label:`id`,value:e.id,mono:!0}),(0,L.jsx)(P8,{label:`path`,value:`~/.loopat/loops/${e.id.slice(0,8)}/workdir`,mono:!0}),(0,L.jsx)(P8,{label:`branch`,value:`main`,mono:!0})]}),(0,L.jsxs)(N8,{label:`context`,children:[(0,L.jsx)(P8,{label:`knowledge`,value:`all (ro)`}),(0,L.jsx)(P8,{label:`notes`,value:`all (rw)`}),(0,L.jsx)(P8,{label:`personal`,value:`${e.createdBy} (rw)`})]})]})}function N8({label:e,children:t}){return(0,L.jsxs)(`section`,{className:`mb-5`,children:[(0,L.jsx)(`h3`,{className:`text-[11px] uppercase tracking-wide text-gray-400 mb-2`,children:e}),(0,L.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:t})]})}function P8({label:e,value:t,mono:n=!1}){return(0,L.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,L.jsx)(`span`,{className:`text-[11px] text-gray-500 w-24 shrink-0`,children:e}),(0,L.jsx)(`span`,{className:n?`font-mono text-[12px] text-gray-800 truncate`:`text-[13px] text-gray-900 truncate`,children:t})]})}function F8({name:e,onClick:t,onEdit:n,size:r=`sm`}){return(0,L.jsxs)(`span`,{className:`relative inline-flex items-center group/chip`,children:[(0,L.jsxs)(`button`,{type:`button`,onClick:t,className:`inline-flex items-center rounded-full bg-sky-50 text-sky-700 border border-sky-200 hover:bg-sky-100 transition-colors font-mono `+(r===`md`?`px-2 py-0.5 text-[12px]`:`px-1.5 py-0.5 text-[10px]`),title:`#${e}`,children:[`#`,e]}),n&&(0,L.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),n()},className:`absolute -top-1 -right-1 z-10 w-4 h-4 rounded-full bg-white border border-gray-300 hover:border-red-400 hover:text-red-500 text-[9px] text-gray-400 opacity-0 group-hover/chip:opacity-100 transition-opacity flex items-center justify-center shadow-sm`,title:`Remove tag`,children:`×`})]})}function Pie(){let{name:e}=xi(),t=decodeURIComponent(e??``),n=_i(),[r,i]=(0,F.useState)(null),[a,o]=(0,F.useState)(!0);return(0,F.useEffect)(()=>{let e=!1;return Nee().then(n=>{e||(i(n.find(e=>e.name===t.toLowerCase())??null),o(!1))}),()=>{e=!0}},[t]),(0,L.jsxs)(`div`,{className:`flex flex-col h-full w-full bg-white`,children:[(0,L.jsxs)(`header`,{className:`h-10 shrink-0 flex items-center gap-3 px-6 border-b border-gray-200`,children:[(0,L.jsx)(`button`,{type:`button`,onClick:()=>n(-1),className:`text-[11px] text-gray-500 hover:text-gray-900`,children:`← back`}),(0,L.jsx)(F8,{name:t,size:`md`}),(0,L.jsx)(`div`,{className:`flex-1`})]}),(0,L.jsx)(`main`,{className:`flex-1 min-w-0 flex flex-col overflow-auto`,children:(0,L.jsx)(`div`,{className:`px-4 md:px-8 py-4 md:py-8 mx-auto w-full max-w-[760px] flex flex-col gap-5`,children:a?(0,L.jsx)(`div`,{className:`text-[12px] text-gray-400 italic`,children:`loading…`}):!r||r.loops.length===0?(0,L.jsxs)(`div`,{className:`text-[12px] text-gray-400 italic`,children:[`no entities tagged with `,(0,L.jsxs)(`code`,{children:[`#`,t]})]}):(0,L.jsxs)(`section`,{children:[(0,L.jsxs)(`div`,{className:`text-[12px] uppercase tracking-wider text-gray-500 mb-2 px-1`,children:[`Loops (`,r.loops.length,`)`]}),(0,L.jsx)(`div`,{className:`flex flex-col gap-1`,children:r.loops.map(e=>(0,L.jsxs)(`button`,{type:`button`,onClick:()=>n(`/loop/${e.id}`),className:`w-full text-left px-3 py-2 rounded border border-gray-200 hover:border-gray-400 hover:bg-gray-50 text-[13px] text-gray-900`,children:[e.title,(0,L.jsx)(`span`,{className:`ml-2 text-[10px] font-mono text-gray-400`,children:e.id.slice(0,6)})]},e.id))})]})})})]})}var I8=(0,F.lazy)(()=>A(()=>import(`./CodeEditor-ROIg2ylA.js`).then(e=>({default:e.CodeEditor})),__vite__mapDeps([79,3,80,81]))),L8=(0,F.lazy)(()=>A(()=>import(`./Markdown-DvFvJx3d.js`).then(e=>({default:e.Markdown})),__vite__mapDeps([84,3,85,80]))),Fie=(0,F.lazy)(()=>A(()=>import(`./MilkdownEditor-DsqsnlSK.js`).then(e=>({default:e.MilkdownEditor})),__vite__mapDeps([86,3,85,9,10,80,81]))),Iie=[{id:`knowledge`,label:`Knowledge`},{id:`notes`,label:`Notes`},{id:`personal`,label:`Personal`},{id:`repos`,label:`Repos`}],Lie=new Set([`knowledge`,`notes`,`personal`,`repos`]);function Rie(){let{sub:e}=xi(),[t]=Ya(),n=Lie.has(e)?e:`knowledge`,r=t.get(`file`)||void 0,i=t.get(`edit`)===`1`;return(0,L.jsxs)(`div`,{className:`flex flex-col h-full w-full`,children:[(0,L.jsx)(`nav`,{className:`flex items-center gap-1 px-3 h-9 shrink-0 border-b border-gray-200 bg-white`,children:Iie.map(e=>(0,L.jsx)(Ha,{to:`/context/${e.id}`,className:({isActive:e})=>e?`h-7 px-2.5 rounded flex items-center gap-1.5 text-xs bg-gray-100 text-gray-900`:`h-7 px-2.5 rounded flex items-center gap-1.5 text-xs text-gray-500 hover:bg-gray-50 hover:text-gray-900`,children:(0,L.jsx)(`span`,{children:e.label})},e.id))}),(0,L.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0`,children:n===`repos`?(0,L.jsx)(Jie,{}):(0,L.jsx)(Hie,{vault:n,initialFile:r,initialEditing:i},n)})]})}var zie={knowledge:`workspace's distilled materials`,notes:`workspace · public`,personal:`yours · private`,repos:`registered code repos`};function Bie({resource:e,canPush:t=!0}){let[n,r]=(0,F.useState)(null),[i,a]=(0,F.useState)(null),[o,s]=(0,F.useState)(null),c=(0,F.useCallback)(async()=>{a(`status`),r(await ig(e)),a(null)},[e]);(0,F.useEffect)(()=>{c()},[c]);let l=async()=>{a(`pull`),s(null);let t=await ag(e);a(null),s(t.ok?{ok:!0,text:t.message??`pulled`}:{ok:!1,text:t.error??`pull failed`}),t.ok&&c()},u=async()=>{a(`push`),s(null);let t=await og(e);a(null),s(t.ok?{ok:!0,text:t.message??`pushed`}:{ok:!1,text:t.error??`push failed`}),t.ok&&c()},d=n?.ahead??0,f=n?.behind??0,p=n&&!n.hasRemote;return(0,L.jsxs)(`div`,{className:`px-3 py-1.5 border-t border-gray-200 flex flex-col gap-1 text-[11px]`,children:[(0,L.jsx)(`div`,{className:`flex items-center gap-2`,children:p?(0,L.jsx)(`span`,{className:`text-gray-400`,children:`no remote`}):(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`span`,{className:d>0?`text-emerald-700`:`text-gray-400`,title:`unpushed commits`,children:[`↑`,d]}),(0,L.jsxs)(`span`,{className:f>0?`text-amber-700`:`text-gray-400`,title:`unpulled commits`,children:[`↓`,f]}),n&&n.uncommitted>0&&(0,L.jsxs)(`span`,{className:`text-red-600`,title:`uncommitted changes in primary`,children:[`! `,n.uncommitted]}),(0,L.jsx)(`button`,{onClick:()=>void c(),disabled:i!==null,className:`ml-auto text-gray-400 hover:text-gray-700 disabled:opacity-50`,title:`refresh status`,children:`↻`})]})}),!p&&(0,L.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,L.jsx)(`button`,{onClick:l,disabled:i!==null||f===0,className:`px-1.5 h-5 rounded border border-gray-200 hover:bg-gray-100 text-gray-700 disabled:opacity-40 disabled:cursor-not-allowed`,children:i===`pull`?`pulling…`:`pull`}),t&&(0,L.jsx)(`button`,{onClick:u,disabled:i!==null||d===0,className:`px-1.5 h-5 rounded border border-gray-200 hover:bg-gray-100 text-gray-700 disabled:opacity-40 disabled:cursor-not-allowed`,children:i===`push`?`pushing…`:`push`}),o&&(0,L.jsx)(`span`,{className:`truncate flex-1 min-w-0 `+(o.ok?`text-emerald-700`:`text-red-600`),title:o.text,children:o.text})]})]})}function Vie({onRefreshed:e}){let[t,n]=(0,F.useState)(0),[r,i]=(0,F.useState)(!1),[a,o]=(0,F.useState)(null),s=(0,F.useRef)(e);s.current=e;let c=(0,F.useCallback)(async()=>{i(!0),o(null);let e=await Jh();i(!1),e.ok?(n(0),s.current()):e.diverged?o(`你有未保存的编辑,先保存再刷新`):o(e.error??`refresh failed`)},[]);return(0,F.useEffect)(()=>{c()},[c]),(0,F.useEffect)(()=>{let e=()=>qh().then(n).catch(()=>{});e();let t=setInterval(e,5e3);return()=>clearInterval(t)},[]),(0,L.jsxs)(`div`,{className:`px-3 py-2 border-t border-gray-200 flex flex-col gap-1.5 text-[11px]`,children:[t>0?(0,L.jsxs)(`div`,{className:`flex items-center justify-between gap-2 bg-amber-50 border border-amber-200 rounded px-2 py-1 text-amber-800`,children:[(0,L.jsxs)(`span`,{children:[`远端已更新 `,t,` 个改动`]}),(0,L.jsx)(`button`,{type:`button`,onClick:c,disabled:r,className:`px-2 py-0.5 rounded bg-amber-600 text-white hover:bg-amber-700 disabled:opacity-50`,children:r?`刷新中…`:`刷新`})]}):(0,L.jsxs)(`div`,{className:`flex items-center justify-between gap-2 text-gray-400`,children:[(0,L.jsx)(`span`,{children:`已是最新`}),(0,L.jsx)(`button`,{type:`button`,onClick:c,disabled:r,className:`text-gray-500 hover:text-gray-900 underline disabled:opacity-50`,children:r?`刷新中…`:`刷新`})]}),a&&(0,L.jsx)(`div`,{className:`text-amber-700`,children:a})]})}function Hie({vault:e,initialFile:t,initialEditing:n}){let[r,i]=(0,F.useState)([]),[a,o]=(0,F.useState)([]),[s,c]=(0,F.useState)(t??null),[l,u]=Ya();(0,F.useEffect)(()=>{(l.get(`file`)??null)!==s&&u(s?{file:s}:{},{replace:!0})},[s,l,u]);let[d,f]=(0,F.useState)(0),[p,m]=(0,F.useState)(!1),[h,g]=(0,F.useState)(``),[_,v]=(0,F.useState)(!1),[y,b]=(0,F.useState)(null),[x,S]=(0,F.useState)(``),C=f6(),w=(0,F.useRef)(!1);if(!w.current&&t){w.current=!0;let n=`vault-${e}`,r=t.includes(`/`)?t.substring(0,t.lastIndexOf(`/`)):``;if(r)try{let e=`loopat:tree:expanded:`+n,t=localStorage.getItem(e),i=t?JSON.parse(t):[];for(let e=r;e;e=e.includes(`/`)?e.substring(0,e.lastIndexOf(`/`)):``)i.includes(e)||i.push(e);localStorage.setItem(e,JSON.stringify(i))}catch{}}(0,F.useEffect)(()=>{Hh(e).then(e=>{i(e),c(t=>{if(t)return t;let n=e.find(e=>e.type===`file`&&e.path.endsWith(`.md`));return n?n.path:null})}),Uh(e).then(o),g(``)},[e,d]),(0,F.useEffect)(()=>{let t=!1,n=()=>{t||f(e=>e+1)};return e===`knowledge`?ag(`knowledge`).then(e=>{e.ok&&(e.message??``).toLowerCase()!==`already up to date`&&n()}):e===`notes`?qh().then(e=>{e>0&&Jh().then(e=>{e.ok&&n()})}):e===`personal`&&Dh().then(e=>{e.ok&&(e.files?.length??0)>0&&n()}),()=>{t=!0}},[e]);let T=async t=>{let n=await Yh(e,t);n.ok?(m(!1),f(e=>e+1),c(t)):alert(`failed: ${n.error}`)},E=async()=>{if(!y||!x.trim()){b(null);return}let t=y.path+`/`+x.trim();if(y.type===`file`){let n=await Yh(e,t);if(!n.ok){alert(`create failed: ${n.error}`);return}}else{let n=await Xh(e,t);if(!n.ok){alert(`create failed: ${n.error}`);return}}b(null),S(``),f(e=>e+1)},D=(0,F.useCallback)((t,n)=>{if(t===`view`)c(n.path);else if(t===`new-file`||t===`new-folder`)b({type:t===`new-file`?`file`:`folder`,path:n.path}),S(``);else if(t===`delete`){if(!confirm(`Delete "${n.name}"?`))return;Zh(e,n.path).then(e=>{e.ok?(c(e=>e===n.path?null:e),f(e=>e+1)):alert(`delete failed: ${e.error}`)})}},[e]),O=(0,F.useCallback)(t=>R8(e,t.path)?[]:t.type===`dir`?[{label:`New file`,icon:(0,L.jsx)(Lt,{size:12}),action:`new-file`},{label:`New folder`,icon:(0,L.jsx)(Ut,{size:12}),action:`new-folder`},{label:`Delete`,icon:(0,L.jsx)(Bn,{size:12}),action:`delete`,danger:!0}]:z8(e,t.path)?[]:[{label:`View`,icon:(0,L.jsx)(Nt,{size:12}),action:`view`},{label:`Delete`,icon:(0,L.jsx)(Bn,{size:12}),action:`delete`,danger:!0}],[e]),k=(0,F.useCallback)(t=>Hh(e,t).then(e=>e),[e]),A=(0,F.useCallback)((t,n,r,i)=>{if(t.type===`dir`)return R8(e,t.path)?`w-full py-1.5 flex items-center gap-1.5 bg-amber-50/40 hover:bg-amber-50 text-left border-y border-amber-200/60 mt-1`:`w-full py-1 flex items-center gap-1 hover:bg-gray-50 text-left`;let a=z8(e,t.path);return`w-full py-1 flex items-center gap-2 text-left `+(i?`bg-gray-100`:a?`hover:bg-amber-50/50`:`hover:bg-gray-50`)},[e]),ee=h.trim().toLowerCase(),j=ee.length>0,te=j?a.filter(e=>e.path.toLowerCase().includes(ee)).slice(0,60):[],M=(0,L.jsxs)(`aside`,{className:`w-64 shrink-0 border-r border-gray-200 bg-white flex flex-col h-full`,children:[(0,L.jsxs)(`div`,{className:`px-3 h-9 flex items-center gap-1 border-b border-gray-200`,children:[C&&(0,L.jsx)(`button`,{onClick:()=>v(!1),className:`text-gray-500 hover:text-gray-900 px-1 rounded hover:bg-gray-100 mr-1`,title:`close sidebar`,children:(0,L.jsx)(gn,{size:14})}),(0,L.jsx)(Uie,{}),(0,L.jsx)(`input`,{type:`text`,value:h,onChange:e=>g(e.target.value),placeholder:`search files…`,className:`flex-1 min-w-0 bg-transparent outline-none text-[12px] text-gray-700 placeholder:text-gray-400`}),(0,L.jsx)(`button`,{onClick:()=>m(!0),className:`text-gray-500 hover:text-gray-900 px-1.5 rounded hover:bg-gray-100 text-xs`,title:`new file`,children:`+`}),(0,L.jsx)(`button`,{onClick:()=>f(e=>e+1),className:`text-gray-500 hover:text-gray-900 px-1.5 rounded hover:bg-gray-100 text-xs`,title:`refresh`,children:`↻`})]}),(0,L.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto py-2`,children:j?te.length===0?(0,L.jsx)(`div`,{className:`px-3 py-4 text-[12px] text-gray-400 italic`,children:`no matches`}):te.map(e=>(0,L.jsxs)(`button`,{type:`button`,onClick:()=>{c(e.path),C&&v(!1)},className:`w-full px-3 py-1.5 flex items-center gap-2 text-left `+(s===e.path?`bg-gray-100`:`hover:bg-gray-50`),title:e.path,children:[(0,L.jsx)(`span`,{className:`text-gray-500`,children:`📄`}),(0,L.jsx)(`span`,{className:`flex-1 min-w-0 truncate text-[13px] text-gray-900`,children:e.path})]},e.path)):(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(E8,{treeId:`vault-${e}`,entries:r,onPick:e=>{c(e),C&&v(!1)},picked:s,onLoadChildren:k,getContextActions:O,onAction:D,nodeClassName:A,reloadKey:d}),r.length===0&&(0,L.jsx)(`div`,{className:`px-3 py-4 text-[12px] text-gray-400 italic`,children:`empty · click + 创建第一个文件`})]})}),(0,L.jsx)(`div`,{className:`px-3 h-9 border-t border-gray-200 flex items-center text-[11px] text-gray-500`,children:zie[e]}),e===`knowledge`&&(0,L.jsx)(Bie,{resource:e}),e===`notes`&&(0,L.jsx)(Vie,{onRefreshed:()=>f(e=>e+1)})]});return(0,L.jsxs)(`div`,{className:`flex h-full w-full`,children:[C?(0,L.jsx)(L.Fragment,{children:_?(0,L.jsxs)(`div`,{className:`fixed inset-0 z-30`,onClick:()=>v(!1),children:[(0,L.jsx)(`div`,{className:`absolute inset-0 bg-black/30`}),(0,L.jsx)(`div`,{className:`absolute left-0 top-0 bottom-0 w-64 max-w-[80vw] shadow-xl`,onClick:e=>e.stopPropagation(),children:M})]}):(0,L.jsx)(`aside`,{className:`w-9 shrink-0 border-r border-gray-200 bg-white flex flex-col items-center pt-2`,children:(0,L.jsx)(`button`,{type:`button`,onClick:()=>v(!0),className:`w-7 h-7 flex items-center justify-center text-gray-500 hover:text-gray-900 hover:bg-gray-100 rounded`,title:`open file tree`,children:(0,L.jsx)(_n,{size:16})})})}):M,(0,L.jsx)(`main`,{className:`flex-1 min-w-0 flex flex-col bg-white min-h-0`,children:s?(0,L.jsx)(Kie,{vault:e,path:s,onSelect:c,onSaved:()=>f(e=>e+1),initialEditing:n}):(0,L.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-[13px] text-gray-400 italic`,children:`选一个文件,或点 + 新建`})}),p&&(0,L.jsx)(qie,{vault:e,onClose:()=>m(!1),onCreate:T}),y&&(0,L.jsx)(Wie,{type:y.type,parentPath:y.path,value:x,onChange:S,onSubmit:E,onCancel:()=>b(null)})]})}function Uie(){return(0,L.jsx)(`svg`,{viewBox:`0 0 16 16`,width:`14`,height:`14`,className:`text-gray-400 shrink-0`,children:(0,L.jsx)(`path`,{fill:`none`,stroke:`currentColor`,strokeWidth:`1.4`,strokeLinecap:`round`,d:`M11 11l3 3M7 12.5a5.5 5.5 0 1 1 0-11 5.5 5.5 0 0 1 0 11z`})})}function R8(e,t){return e!==`personal`||!t.startsWith(`.loopat/vaults/`)?!1:t.slice(15).length>0}function z8(e,t){return e!==`personal`||!t.startsWith(`.loopat/vaults/`)?!1:t.slice(15).includes(`/`)}function Wie({type:e,parentPath:t,value:n,onChange:r,onSubmit:i,onCancel:a}){return(0,L.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/30 flex items-center justify-center`,onClick:a,children:(0,L.jsxs)(`div`,{className:`w-full max-w-[420px] mx-4 bg-white rounded-md shadow-xl border border-gray-200 p-4 md:p-5`,onClick:e=>e.stopPropagation(),children:[(0,L.jsxs)(`div`,{className:`text-base font-semibold text-gray-900 mb-3`,children:[e===`file`?`New file`:`New folder`,` in `,(0,L.jsx)(`span`,{className:`font-mono text-[13px]`,children:t||`root`})]}),(0,L.jsx)(`input`,{autoFocus:!0,type:`text`,value:n,onChange:e=>r(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&i(),e.key===`Escape`&&a()},placeholder:e===`file`?`filename.md`:`folder-name`,className:`w-full px-3 py-2 text-sm border border-gray-300 rounded outline-none focus:border-gray-500 font-mono`}),(0,L.jsxs)(`div`,{className:`flex justify-end gap-2 mt-4`,children:[(0,L.jsx)(`button`,{onClick:a,className:`px-3 h-8 text-sm rounded text-gray-700 hover:bg-gray-100`,children:`cancel`}),(0,L.jsx)(`button`,{onClick:()=>n.trim()&&i(),disabled:!n.trim(),className:`px-3 h-8 text-sm rounded bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-50`,children:`create`})]})]})})}function Gie(e){return/(^|\/)secrets\//.test(e)||e===`secrets`}function Kie({vault:e,path:t,onSelect:n,onSaved:r,initialEditing:i}){let a=D_(),o=_i(),[s,c]=(0,F.useState)(``),[l,u]=(0,F.useState)(``),[d,f]=(0,F.useState)(i??!1),[p,m]=(0,F.useState)(!1),[h,g]=(0,F.useState)([]),[_,v]=(0,F.useState)(null),[y,b]=(0,F.useState)(!1),[x,S]=(0,F.useState)(!1),[C,w]=(0,F.useState)(!1),[T,E]=(0,F.useState)(!1),D=f6(),O=(0,F.useRef)(i);(0,F.useEffect)(()=>{O.current?O.current=!1:f(!1),S(!1),v(null),w(!1),E(!1),Wh(e,t).then(e=>{let t=e?.content??``;c(t),u(t),E(!!e?.secret)}),Qh(e,t).then(g)},[e,t]);let k=Gie(t)||T,A=t.endsWith(`.md`),ee=e!==`knowledge`,j=!k,te=e===`notes`&&!k,M=k?l.length>0:l!==s,ne=(0,F.useCallback)(async()=>{if(!(!M||p)){m(!0);try{let n=await Gh(e,t,l);if(n.ok){if(k?(c(``),u(``)):c(l),v(n.commit??null),f(!1),r(),Qh(e,t).then(g),e===`notes`){let e=await Kh();e.ok||(e.conflict?alert(`Saved locally, but it conflicts with the remote (${(e.files??[]).join(`, `)}). Your edit is kept — resolve by taking the remote, or in a loop.`):alert(`Saved locally, but push to remote failed: ${e.error??`unknown`}`))}else if(e===`personal`){let e=await Oh();e.ok||(e.conflict?alert(`Saved locally, but it conflicts with the remote (${(e.files??[]).join(`, `)}). Your edit is kept — pull first (re-open Personal) or resolve in a loop.`):alert(`Saved locally, but push to remote failed: ${e.error??`unknown`}`))}}else alert(`save failed: ${n.error}`)}finally{m(!1)}}},[e,t,l,M,p,r,k]),N=()=>{f(!0),A&&S(!0)},re=()=>{u(s),f(!1)},ie=async()=>{o(`/loop/${(await a.createLoop({title:`edit ${e}/${t}`})).id}`)},ae=async()=>{o(`/loop/${(await a.createLoop({title:`distill ${t} → knowledge`,knowledgeRw:!0})).id}`)},oe=e=>{n([t.replace(/[^/]+$/,``)+e+`.md`,e+`.md`,e][0].replace(/^\//,``))};return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`header`,{className:`px-3 md:px-5 h-10 shrink-0 border-b border-gray-200 flex items-center justify-between`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2 text-[13px] min-w-0`,children:[(0,L.jsx)(`span`,{className:`text-gray-500 shrink-0`,children:k?`🔒`:`📄`}),(0,L.jsx)(`span`,{className:`font-mono text-[12px] text-gray-500 truncate`,children:t}),_&&!M&&!d&&(0,L.jsxs)(`span`,{className:`hidden md:inline text-[10px] text-emerald-700 font-mono`,children:[`commit `,_]})]}),(0,L.jsx)(`div`,{className:`flex items-center gap-1 md:gap-2 text-xs text-gray-500`,children:d?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`button`,{onClick:re,className:`px-2.5 h-7 rounded text-xs text-gray-600 hover:bg-gray-100`,children:`cancel`}),(0,L.jsx)(`button`,{onClick:ne,disabled:!M||p,className:`px-2.5 h-7 rounded text-xs bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-50`,children:p?`saving…`:`save`})]}):(0,L.jsxs)(L.Fragment,{children:[te&&(0,L.jsxs)(`button`,{onClick:ae,className:`px-2.5 h-7 rounded text-xs bg-amber-100 text-amber-900 hover:bg-amber-200 flex items-center gap-1`,title:`open a loop to distill this notes file into knowledge`,children:[(0,L.jsx)(`span`,{children:`↑`}),(0,L.jsx)(`span`,{children:`distill`})]}),j&&(0,L.jsxs)(`button`,{onClick:ie,className:te?`px-2.5 h-7 rounded text-xs border border-gray-200 hover:bg-gray-100 text-gray-900 flex items-center gap-1`:`px-2.5 h-7 rounded text-xs bg-gray-900 text-white hover:bg-gray-700 flex items-center gap-1`,title:`open a new loop with AI assist for this file`,children:[(0,L.jsx)(`span`,{children:`↻`}),(0,L.jsx)(`span`,{children:`edit by loop`})]}),ee&&(0,L.jsx)(`button`,{onClick:N,className:`px-2.5 h-7 rounded text-xs border border-gray-200 hover:bg-gray-100 text-gray-900`,title:`direct edit (fastpath)`,children:`edit`}),D&&A&&(0,L.jsxs)(`button`,{onClick:()=>b(e=>!e),className:`px-2.5 h-7 rounded text-xs border ${y?`bg-gray-900 text-white`:`border-gray-200 hover:bg-gray-100 text-gray-900`}`,title:`toggle backlinks`,children:[`⇄ `,h.length]})]})})]}),d?k?(0,L.jsxs)(`div`,{className:C?`fixed inset-0 z-50 bg-white flex flex-col`:`flex-1 min-h-0 min-w-0 flex flex-col`,children:[(0,L.jsxs)(`div`,{className:`px-3 h-7 shrink-0 border-b border-gray-200 flex items-center gap-2 text-[11px] text-gray-500`,children:[(0,L.jsx)(`span`,{className:`text-amber-700`,children:`🔒`}),(0,L.jsx)(`span`,{children:`new value · saved encrypted`}),(0,L.jsx)(`div`,{className:`flex-1`}),(0,L.jsx)(`button`,{onClick:()=>w(!C),className:`text-gray-400 hover:text-gray-700 px-1 rounded hover:bg-gray-100`,title:C?`restore`:`maximize`,children:C?(0,L.jsx)(dn,{size:13}):(0,L.jsx)(cn,{size:13})})]}),(0,L.jsx)(`div`,{className:`flex-1 min-h-0 relative`,children:(0,L.jsx)(F.Suspense,{fallback:(0,L.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-gray-400 text-sm`,children:`Loading editor...`}),children:(0,L.jsx)(I8,{path:t,value:l,onChange:u})})})]}):A&&!x?(0,L.jsxs)(`div`,{className:C?`fixed inset-0 z-50 bg-white flex flex-col md:flex-row`:`flex-1 min-h-0 min-w-0 flex flex-col md:flex-row`,children:[(0,L.jsxs)(`div`,{className:`flex-1 min-w-0 min-h-0 border-r border-gray-200 flex flex-col`,children:[(0,L.jsxs)(`div`,{className:`px-3 h-7 shrink-0 border-b border-gray-200 flex items-center gap-2 text-[11px] text-gray-500`,children:[(0,L.jsx)(`span`,{children:`source · markdown`}),(0,L.jsx)(`button`,{type:`button`,onClick:()=>S(!0),className:`px-2 h-5 rounded text-[10px] bg-gray-100 hover:bg-gray-200 text-gray-600`,title:`Switch to WYSIWYG editor`,children:`wysiwyg`}),(0,L.jsx)(`div`,{className:`flex-1`}),(0,L.jsx)(`button`,{onClick:()=>w(!C),className:`text-gray-400 hover:text-gray-700 px-1 rounded hover:bg-gray-100`,title:C?`restore`:`maximize`,children:C?(0,L.jsx)(dn,{size:13}):(0,L.jsx)(cn,{size:13})})]}),(0,L.jsx)(`div`,{className:`flex-1 min-h-0 relative`,children:(0,L.jsx)(F.Suspense,{fallback:(0,L.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-gray-400 text-sm`,children:`Loading editor...`}),children:(0,L.jsx)(I8,{path:t,value:l,onChange:u})})})]}),(0,L.jsxs)(`div`,{className:`flex-1 min-w-0 min-h-0 flex flex-col`,children:[(0,L.jsx)(`div`,{className:`px-3 h-7 shrink-0 border-b border-gray-200 flex items-center text-[11px] text-gray-500`,children:`preview`}),(0,L.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto px-6 py-4`,children:(0,L.jsx)(`div`,{className:`max-w-[760px]`,children:(0,L.jsx)(F.Suspense,{fallback:(0,L.jsx)(`div`,{className:`text-gray-400 text-sm`,children:`Loading preview...`}),children:(0,L.jsx)(L8,{text:l,onWikilink:oe})})})})]})]}):A?(0,L.jsxs)(`div`,{className:C?`fixed inset-0 z-50 bg-white flex flex-col`:`flex-1 min-h-0 min-w-0 flex flex-col`,children:[(0,L.jsxs)(`div`,{className:`px-3 h-7 shrink-0 border-b border-gray-200 flex items-center gap-2 text-[11px] text-gray-500`,children:[(0,L.jsx)(`span`,{children:`wysiwyg · milkdown`}),(0,L.jsx)(`button`,{type:`button`,onClick:()=>S(!1),className:`px-2 h-5 rounded text-[10px] bg-gray-100 hover:bg-gray-200 text-gray-600`,title:`Switch to source editor`,children:`source`}),(0,L.jsx)(`div`,{className:`flex-1`}),(0,L.jsx)(`button`,{onClick:()=>w(!C),className:`text-gray-400 hover:text-gray-700 px-1 rounded hover:bg-gray-100`,title:C?`restore`:`maximize`,children:C?(0,L.jsx)(dn,{size:13}):(0,L.jsx)(cn,{size:13})})]}),(0,L.jsx)(`div`,{className:`flex-1 min-h-0 relative`,children:(0,L.jsx)(F.Suspense,{fallback:(0,L.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-gray-400 text-sm`,children:`Loading editor...`}),children:(0,L.jsx)(Fie,{value:l,onChange:u})})})]}):(0,L.jsxs)(`div`,{className:C?`fixed inset-0 z-50 bg-white flex flex-col`:`flex-1 min-h-0 min-w-0 flex flex-col`,children:[(0,L.jsxs)(`div`,{className:`px-3 h-7 shrink-0 border-b border-gray-200 flex items-center gap-2 text-[11px] text-gray-500`,children:[(0,L.jsxs)(`span`,{children:[`source · `,t.includes(`.`)?t.split(`.`).pop():`text`]}),t.endsWith(`.json`)&&(0,L.jsx)(`button`,{type:`button`,onClick:()=>{try{u(JSON.stringify(JSON.parse(l),null,2))}catch(e){alert(`Invalid JSON: `+(e?.message??`parse error`))}},className:`px-2 h-5 rounded text-[10px] bg-gray-100 hover:bg-gray-200 text-gray-600`,title:`Format JSON`,children:`format`}),(0,L.jsx)(`div`,{className:`flex-1`}),(0,L.jsx)(`button`,{onClick:()=>w(!C),className:`text-gray-400 hover:text-gray-700 px-1 rounded hover:bg-gray-100`,title:C?`restore`:`maximize`,children:C?(0,L.jsx)(dn,{size:13}):(0,L.jsx)(cn,{size:13})})]}),(0,L.jsx)(`div`,{className:`flex-1 min-h-0 relative`,children:(0,L.jsx)(F.Suspense,{fallback:(0,L.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-gray-400 text-sm`,children:`Loading editor...`}),children:(0,L.jsx)(I8,{path:t,value:l,onChange:u})})})]}):(0,L.jsxs)(`div`,{className:`flex flex-1 min-h-0 min-w-0 overflow-hidden`,children:[(0,L.jsx)(`article`,{className:`flex-1 min-h-0 overflow-auto px-4 md:px-8 py-4 md:py-6`,children:(0,L.jsx)(`div`,{className:`max-w-[760px]`,children:k?(0,L.jsxs)(`div`,{className:`font-sans text-[13px] text-gray-600 leading-relaxed`,children:[(0,L.jsx)(`div`,{className:`inline-flex items-center gap-1.5 px-2 py-1 rounded bg-amber-50 border border-amber-200 text-amber-800 text-[12px] font-medium`,children:`encrypted · value hidden by design`}),(0,L.jsxs)(`div`,{className:`mt-3 text-[12px] text-gray-500`,children:[`Click `,(0,L.jsx)(`b`,{children:`edit`}),` to overwrite. The current value is never returned by the server, so editing means typing a new replacement — there is no decrypt-and-view.`]})]}):A?(0,L.jsx)(F.Suspense,{fallback:(0,L.jsx)(`div`,{className:`text-gray-400 text-sm`,children:`Loading...`}),children:(0,L.jsx)(L8,{text:s,onWikilink:oe})}):(0,L.jsx)(`pre`,{className:`font-mono text-[12.5px] leading-relaxed whitespace-pre-wrap text-gray-900`,children:s||(0,L.jsx)(`span`,{className:`text-gray-400 italic`,children:`(empty)`})})})}),A&&!D&&(0,L.jsxs)(`aside`,{className:`w-64 shrink-0 border-l border-gray-200 bg-gray-50 overflow-auto`,children:[(0,L.jsxs)(`div`,{className:`px-3 h-9 flex items-center border-b border-gray-200`,children:[(0,L.jsx)(`span`,{className:`text-[11px] text-gray-500`,children:`Backlinks`}),(0,L.jsx)(`span`,{className:`ml-auto text-[11px] text-gray-500`,children:h.length})]}),h.length===0?(0,L.jsx)(`div`,{className:`px-3 py-4 text-xs text-gray-500`,children:`No documents link here yet.`}):(0,L.jsx)(`ul`,{className:`py-2`,children:h.map(e=>(0,L.jsx)(`li`,{children:(0,L.jsxs)(`button`,{type:`button`,onClick:()=>n(e.path),className:`w-full px-3 py-2 text-left hover:bg-gray-100`,children:[(0,L.jsx)(`div`,{className:`text-xs font-medium text-gray-900 truncate`,children:e.path}),(0,L.jsx)(`div`,{className:`text-[11px] text-gray-500 mt-0.5 leading-snug line-clamp-2`,children:e.preview})]})},e.path))})]}),D&&A&&y&&(0,L.jsxs)(`div`,{className:`fixed inset-0 z-30`,onClick:()=>b(!1),children:[(0,L.jsx)(`div`,{className:`absolute inset-0 bg-black/30`}),(0,L.jsxs)(`div`,{className:`absolute right-0 top-0 bottom-0 w-64 max-w-[80vw] bg-gray-50 border-l border-gray-200 shadow-xl overflow-auto`,onClick:e=>e.stopPropagation(),children:[(0,L.jsxs)(`div`,{className:`px-3 h-9 flex items-center border-b border-gray-200`,children:[(0,L.jsx)(`span`,{className:`text-[11px] text-gray-500`,children:`Backlinks`}),(0,L.jsx)(`span`,{className:`ml-auto text-[11px] text-gray-500`,children:h.length}),(0,L.jsx)(`button`,{onClick:()=>b(!1),className:`ml-2 text-gray-400 hover:text-gray-700 px-1`,title:`close backlinks`,children:`✕`})]}),h.length===0?(0,L.jsx)(`div`,{className:`px-3 py-4 text-xs text-gray-500`,children:`No documents link here yet.`}):(0,L.jsx)(`ul`,{className:`py-2`,children:h.map(e=>(0,L.jsx)(`li`,{children:(0,L.jsxs)(`button`,{type:`button`,onClick:()=>{n(e.path),b(!1)},className:`w-full px-3 py-2 text-left hover:bg-gray-100`,children:[(0,L.jsx)(`div`,{className:`text-xs font-medium text-gray-900 truncate`,children:e.path}),(0,L.jsx)(`div`,{className:`text-[11px] text-gray-500 mt-0.5 leading-snug line-clamp-2`,children:e.preview})]})},e.path))})]})]})]})]})}function qie({vault:e,onClose:t,onCreate:n}){let[r,i]=(0,F.useState)(``);return(0,L.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/30 flex items-center justify-center`,onClick:t,children:(0,L.jsxs)(`div`,{className:`w-full max-w-[420px] mx-4 bg-white rounded-md shadow-xl border border-gray-200 p-4 md:p-5`,onClick:e=>e.stopPropagation(),children:[(0,L.jsxs)(`div`,{className:`text-base font-semibold text-gray-900 mb-3`,children:[`new file in `,e,`/`]}),(0,L.jsx)(`input`,{autoFocus:!0,type:`text`,value:r,onChange:e=>i(e.target.value),placeholder:`loopat/new-doc.md`,className:`w-full px-3 py-2 text-sm border border-gray-300 rounded outline-none focus:border-gray-500 font-mono`}),(0,L.jsx)(`div`,{className:`text-[11px] text-gray-400 mt-1`,children:`relative path. directories created as needed.`}),(0,L.jsxs)(`div`,{className:`flex justify-end gap-2 mt-4`,children:[(0,L.jsx)(`button`,{onClick:t,className:`px-3 h-8 text-sm rounded text-gray-700 hover:bg-gray-100`,children:`cancel`}),(0,L.jsx)(`button`,{onClick:()=>r.trim()&&n(r.trim()),disabled:!r.trim(),className:`px-3 h-8 text-sm rounded bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-50`,children:`create`})]})]})})}function Jie(){let[e,t]=(0,F.useState)(null),[n,r]=(0,F.useState)([]),[i,a]=(0,F.useState)(!1),[o,s]=(0,F.useState)(null),c=(0,F.useCallback)(async()=>{let e=await $h();t(e),r(e.repos)},[]);(0,F.useEffect)(()=>{c()},[c]);let l=e!==null&&JSON.stringify(n)!==JSON.stringify(e.repos),u=()=>r(e=>[...e,{name:``,git:``}]),d=(e,t,n)=>r(r=>r.map((r,i)=>i===e?{...r,[t]:n}:r)),f=e=>r(t=>t.filter((t,n)=>n!==e));return e?(0,L.jsx)(`article`,{className:`flex-1 min-w-0 overflow-auto p-5`,children:(0,L.jsxs)(`div`,{className:`max-w-2xl flex flex-col gap-5`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`h2`,{className:`text-sm font-semibold text-gray-900`,children:`Repo roster`}),(0,L.jsxs)(`p`,{className:`text-[12px] text-gray-500 leading-relaxed mt-1`,children:[`Personal — saved straight to your own`,` `,(0,L.jsx)(`code`,{className:`bg-gray-100 px-1 rounded text-[11px]`,children:`.loopat/config.json`}),`. Repos are cloned on demand when a loop selects one.`]})]}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,L.jsx)(`span`,{className:`text-[12px] font-medium text-gray-700`,children:`repos`}),n.length===0&&(0,L.jsx)(`div`,{className:`text-[12px] text-gray-400`,children:`No repos yet.`}),n.map((e,t)=>(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(`input`,{value:e.name,onChange:e=>d(t,`name`,e.target.value),placeholder:`name`,className:`w-40 px-2 py-1.5 text-sm border border-gray-300 rounded outline-none focus:border-gray-500`}),(0,L.jsx)(`input`,{value:e.git,onChange:e=>d(t,`git`,e.target.value),placeholder:`git@…/repo.git`,className:`flex-1 px-2 py-1.5 text-sm font-mono border border-gray-300 rounded outline-none focus:border-gray-500`}),(0,L.jsx)(`button`,{type:`button`,onClick:()=>f(t),className:`px-2 py-1.5 text-gray-400 hover:text-red-600`,title:`remove`,children:`✕`})]},t)),(0,L.jsx)(`button`,{type:`button`,onClick:u,className:`self-start text-[12px] text-gray-600 hover:text-gray-900 border border-gray-200 rounded px-2 py-1`,children:`+ add repo`})]}),o&&(0,L.jsx)(`div`,{className:`text-[12px] rounded px-2 py-1.5 border ${o.ok?`text-emerald-700 bg-emerald-50 border-emerald-200`:`text-red-700 bg-red-50 border-red-200`}`,children:o.text}),(0,L.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,L.jsx)(`button`,{type:`button`,onClick:async()=>{a(!0),s(null);let e=await eg({repos:n.map(e=>({name:e.name.trim(),git:e.git.trim()})).filter(e=>e.name&&e.git)});a(!1),e.ok?(s({ok:!0,text:`Saved.`}),await c()):s({ok:!1,text:`Save failed: `+(e.error??``)})},disabled:!l||i,className:`px-3 h-9 text-sm rounded bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-40`,children:i?`Saving…`:`Save`}),l&&(0,L.jsx)(`span`,{className:`text-[11px] text-amber-600`,children:`unsaved changes`})]})]})}):(0,L.jsx)(`div`,{className:`p-6 text-sm text-gray-400`,children:`loading…`})}function Yie(){var e=[...arguments];return(0,F.useMemo)(()=>t=>{e.forEach(e=>e(t))},e)}var B8=typeof window<`u`&&window.document!==void 0&&window.document.createElement!==void 0;function V8(e){let t=Object.prototype.toString.call(e);return t===`[object Window]`||t===`[object global]`}function H8(e){return`nodeType`in e}function U8(e){return e?V8(e)?e:H8(e)?e.ownerDocument?.defaultView??window:window:window}function W8(e){let{Document:t}=U8(e);return e instanceof t}function G8(e){return V8(e)?!1:e instanceof U8(e).HTMLElement}function K8(e){return e instanceof U8(e).SVGElement}function q8(e){return e?V8(e)?e.document:H8(e)?W8(e)?e:G8(e)||K8(e)?e.ownerDocument:document:document:document}var J8=B8?F.useLayoutEffect:F.useEffect;function Y8(e){let t=(0,F.useRef)(e);return J8(()=>{t.current=e}),(0,F.useCallback)(function(){var e=[...arguments];return t.current==null?void 0:t.current(...e)},[])}function Xie(){let e=(0,F.useRef)(null);return[(0,F.useCallback)((t,n)=>{e.current=setInterval(t,n)},[]),(0,F.useCallback)(()=>{e.current!==null&&(clearInterval(e.current),e.current=null)},[])]}function X8(e,t){t===void 0&&(t=[e]);let n=(0,F.useRef)(e);return J8(()=>{n.current!==e&&(n.current=e)},t),n}function Z8(e,t){let n=(0,F.useRef)();return(0,F.useMemo)(()=>{let t=e(n.current);return n.current=t,t},[...t])}function Q8(e){let t=Y8(e),n=(0,F.useRef)(null);return[n,(0,F.useCallback)(e=>{e!==n.current&&t?.(e,n.current),n.current=e},[])]}function $8(e){let t=(0,F.useRef)();return(0,F.useEffect)(()=>{t.current=e},[e]),t.current}var e5={};function t5(e,t){return(0,F.useMemo)(()=>{if(t)return t;let n=e5[e]==null?0:e5[e]+1;return e5[e]=n,e+`-`+n},[e,t])}function n5(e){return function(t){return[...arguments].slice(1).reduce((t,n)=>{let r=Object.entries(n);for(let[n,i]of r){let r=t[n];r!=null&&(t[n]=r+e*i)}return t},{...t})}}var r5=n5(1),i5=n5(-1);function Zie(e){return`clientX`in e&&`clientY`in e}function a5(e){if(!e)return!1;let{KeyboardEvent:t}=U8(e.target);return t&&e instanceof t}function Qie(e){if(!e)return!1;let{TouchEvent:t}=U8(e.target);return t&&e instanceof t}function o5(e){if(Qie(e)){if(e.touches&&e.touches.length){let{clientX:t,clientY:n}=e.touches[0];return{x:t,y:n}}else if(e.changedTouches&&e.changedTouches.length){let{clientX:t,clientY:n}=e.changedTouches[0];return{x:t,y:n}}}return Zie(e)?{x:e.clientX,y:e.clientY}:null}var s5=Object.freeze({Translate:{toString(e){if(!e)return;let{x:t,y:n}=e;return`translate3d(`+(t?Math.round(t):0)+`px, `+(n?Math.round(n):0)+`px, 0)`}},Scale:{toString(e){if(!e)return;let{scaleX:t,scaleY:n}=e;return`scaleX(`+t+`) scaleY(`+n+`)`}},Transform:{toString(e){if(e)return[s5.Translate.toString(e),s5.Scale.toString(e)].join(` `)}},Transition:{toString(e){let{property:t,duration:n,easing:r}=e;return t+` `+n+`ms `+r}}}),c5=`a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]`;function $ie(e){return e.matches(c5)?e:e.querySelector(c5)}var eae={display:`none`};function tae(e){let{id:t,value:n}=e;return F.createElement(`div`,{id:t,style:eae},n)}function nae(e){let{id:t,announcement:n,ariaLiveType:r=`assertive`}=e;return F.createElement(`div`,{id:t,style:{position:`fixed`,top:0,left:0,width:1,height:1,margin:-1,border:0,padding:0,overflow:`hidden`,clip:`rect(0 0 0 0)`,clipPath:`inset(100%)`,whiteSpace:`nowrap`},role:`status`,"aria-live":r,"aria-atomic":!0},n)}function rae(){let[e,t]=(0,F.useState)(``);return{announce:(0,F.useCallback)(e=>{e!=null&&t(e)},[]),announcement:e}}var l5=(0,F.createContext)(null);function iae(e){let t=(0,F.useContext)(l5);(0,F.useEffect)(()=>{if(!t)throw Error(`useDndMonitor must be used within a children of <DndContext>`);return t(e)},[e,t])}function aae(){let[e]=(0,F.useState)(()=>new Set),t=(0,F.useCallback)(t=>(e.add(t),()=>e.delete(t)),[e]);return[(0,F.useCallback)(t=>{let{type:n,event:r}=t;e.forEach(e=>e[n]?.call(e,r))},[e]),t]}var oae={draggable:`
397
+ `),n=``,r=[],i=null,a=0,o=0;for(let e of t){if(e.startsWith(`diff `)){n=e;continue}if(e.startsWith(`+++ `)||e.startsWith(`--- `))continue;let t=e.match(/^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@(.*)$/);if(t){i&&r.push(i),a=parseInt(t[1],10),o=parseInt(t[3],10),i={header:e,lines:[]};continue}i&&(e.startsWith(`+`)?(i.lines.push({type:`add`,oldNum:null,newNum:o,text:e.slice(1)}),o++):e.startsWith(`-`)?(i.lines.push({type:`del`,oldNum:a,newNum:null,text:e.slice(1)}),a++):(i.lines.push({type:`ctx`,oldNum:a,newNum:o,text:e.startsWith(` `)?e.slice(1):e}),a++,o++))}return i&&r.push(i),{fileHeader:n,hunks:r}}function _ie({filePath:e,diff:t,loading:n,onClose:r}){let i=null;if(t)try{i=gie(t)}catch{}return(0,L.jsx)(P_,{open:!0,onOpenChange:e=>{e||r()},children:(0,L.jsxs)(L_,{className:`sm:max-w-4xl max-h-[85vh] flex flex-col bg-white p-0 gap-0`,showCloseButton:!1,children:[(0,L.jsxs)(`div`,{className:`px-4 py-2.5 border-b border-gray-200 shrink-0 flex items-center gap-2`,children:[(0,L.jsx)(`span`,{className:`text-sm font-mono text-gray-900 truncate flex-1`,children:e}),(0,L.jsx)(`button`,{onClick:r,className:`text-gray-400 hover:text-gray-700 text-sm leading-none`,children:`✕`})]}),(0,L.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto`,children:n?(0,L.jsxs)(`div`,{className:`flex items-center justify-center py-16 text-gray-400 gap-2`,children:[(0,L.jsx)(an,{className:`animate-spin`,size:16}),(0,L.jsx)(`span`,{className:`text-sm`,children:`loading diff...`})]}):i?(0,L.jsx)(`div`,{className:`text-xs font-mono leading-5`,children:i.hunks.map((e,t)=>(0,L.jsxs)(`div`,{className:`border-b border-gray-100 last:border-b-0`,children:[(0,L.jsx)(`div`,{className:`px-4 py-1 bg-blue-50/60 text-blue-700 border-b border-blue-100 sticky top-0`,children:e.header}),e.lines.map((e,t)=>{let n=e.type===`add`,r=e.type===`del`;return(0,L.jsxs)(`div`,{className:`flex `+(n?`bg-emerald-50`:r?`bg-red-50`:``),children:[(0,L.jsx)(`span`,{className:`w-14 shrink-0 text-right pr-3 py-px text-gray-300 select-none border-r border-gray-200 bg-gray-50`,children:e.oldNum??``}),(0,L.jsx)(`span`,{className:`w-14 shrink-0 text-right pr-3 py-px select-none border-r border-gray-200 `+(n?`bg-emerald-100/70 text-emerald-700`:r?`bg-red-100/70 text-red-500`:`text-gray-300 bg-gray-50`),children:e.newNum??``}),(0,L.jsxs)(`span`,{className:`pl-3 py-px whitespace-pre-wrap break-all flex-1 `+(n?`text-emerald-800`:r?`text-red-700`:`text-gray-700`),children:[(0,L.jsx)(`span`,{className:`select-none`,children:n?`+`:r?`−`:` `}),e.text]})]},t)})]},t))}):(0,L.jsx)(`div`,{className:`py-16 text-center text-sm text-gray-400`,children:`empty diff`})})]})})}var vie={A:{label:`A`,color:`text-emerald-600`},M:{label:`M`,color:`text-amber-600`},D:{label:`D`,color:`text-red-600`},R:{label:`R`,color:`text-purple-600`},"?":{label:`?`,color:`text-gray-400`}};function yie({loopId:e,onClose:t,onPickFile:n}){let[r,i]=(0,F.useState)(null),[a,o]=(0,F.useState)(!1),[s,c]=(0,F.useState)(!0),[l,u]=(0,F.useState)(!0),[d,f]=(0,F.useState)(null),[p,m]=(0,F.useState)(``),[h,g]=(0,F.useState)(``),[_,v]=(0,F.useState)(!1),[y,b]=(0,F.useState)(null),[x,S]=(0,F.useState)([]),[C,w]=(0,F.useState)(!1),[T,E]=(0,F.useState)(!0),D=(0,F.useCallback)(async()=>{o(!0),f(null);try{i(await Cg(e))}catch{f(`Failed to load git status`)}finally{o(!1)}},[e]),O=(0,F.useCallback)(async()=>{w(!0);try{S(await Og(e,50))}catch{}finally{w(!1)}},[e]);(0,F.useEffect)(()=>{D(),O()},[D,O]);let k=async()=>{r?.unstaged.length&&await Tg(e,r.unstaged.map(e=>e.path))&&D()},A=async()=>{r?.staged.length&&await Tg(e,r.staged.map(e=>e.path),!0)&&D()},ee=async t=>{await Tg(e,[t])&&D()},j=async t=>{await Tg(e,[t],!0)&&D()},te=async t=>{await Eg(e,t)&&D()},M=async()=>{if(!h.trim())return;v(!0),b(null);let t=await Dg(e,h.trim());v(!1),t.ok?(g(``),D(),O()):b(t.error??`Commit failed`)},ne=p.trim().toLowerCase(),N=r?r.unstaged.filter(e=>!ne||e.path.toLowerCase().includes(ne)):[],re=r?r.staged.filter(e=>!ne||e.path.toLowerCase().includes(ne)):[],ie=!r||r.unstaged.length===0&&r.staged.length===0;return(0,L.jsxs)(`aside`,{className:`w-full h-full min-w-0 bg-white flex flex-col`,children:[(0,L.jsxs)(`header`,{className:`px-3 h-8 shrink-0 border-b border-gray-200 flex items-center gap-1 text-[11px] text-gray-500`,children:[(0,L.jsx)(`span`,{className:`tracking-wide`,children:`Git Changes`}),(0,L.jsx)(`div`,{className:`flex-1`}),(0,L.jsx)(`button`,{onClick:()=>{D(),O()},className:`text-gray-500 hover:text-gray-900 px-1 rounded hover:bg-gray-100`,title:`refresh`,children:(0,L.jsx)(wn,{size:13,className:a||C?`animate-spin`:``})}),(0,L.jsx)(`button`,{className:`text-gray-500 hover:text-gray-900 px-1 rounded hover:bg-gray-100`,onClick:t,title:`close`,children:`✕`})]}),(0,L.jsxs)(`div`,{className:`px-3 py-2 border-b border-gray-100`,children:[(0,L.jsx)(`textarea`,{placeholder:`Commit message...`,value:h,onChange:e=>{g(e.target.value),b(null)},rows:2,className:`w-full px-2 py-1.5 text-[12px] border border-gray-200 rounded outline-none focus:border-gray-300 placeholder:text-gray-300 resize-none mb-1.5`}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsxs)(`button`,{onClick:M,disabled:_||!h.trim(),className:`flex-1 flex items-center justify-center gap-1 px-2 py-1 text-[11px] rounded bg-blue-600 text-white hover:bg-blue-700 disabled:opacity-40 disabled:cursor-not-allowed`,children:[(0,L.jsx)(Kt,{size:12}),_?`Committing...`:`Commit`]}),r&&r.staged.length>0&&(0,L.jsxs)(`span`,{className:`text-[10px] text-gray-400`,children:[r.staged.length,` staged`]})]}),y&&(0,L.jsx)(`div`,{className:`mt-1 text-[10px] text-red-500`,children:y})]}),(0,L.jsx)(`div`,{className:`px-3 py-2 border-b border-gray-100`,children:(0,L.jsx)(`input`,{type:`text`,placeholder:`Filter files...`,value:p,onChange:e=>m(e.target.value),className:`w-full px-2 py-1 text-[12px] border border-gray-200 rounded outline-none focus:border-gray-300 placeholder:text-gray-300`})}),(0,L.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-auto text-[13px]`,children:[(0,L.jsxs)(`div`,{className:`overflow-auto py-2`,children:[a&&!r&&(0,L.jsx)(`div`,{className:`px-5 py-4 text-[12px] text-gray-400 italic`,children:`loading git status...`}),d&&(0,L.jsx)(`div`,{className:`px-5 py-4 text-[12px] text-red-500`,children:d}),ie&&!a&&(0,L.jsx)(`div`,{className:`px-5 py-4 text-[12px] text-gray-400 italic`,children:`no changes`}),N.length>0&&(0,L.jsx)(k8,{title:`Unstaged Changes`,count:N.length,open:s,onToggle:()=>c(e=>!e),bulkAction:{label:`Stage all`,icon:(0,L.jsx)(bn,{size:12}),onClick:k},children:N.map(t=>(0,L.jsx)(A8,{file:t,loopId:e,staged:!1,onStage:()=>ee(t.path),onUnstage:()=>j(t.path),onDiscard:()=>te(t.path),onEdit:e=>n(e),onRefresh:D},t.path))}),re.length>0&&(0,L.jsx)(k8,{title:`Staged Changes`,count:re.length,open:l,onToggle:()=>u(e=>!e),bulkAction:{label:`Unstage all`,icon:(0,L.jsx)(fn,{size:12}),onClick:A},children:re.map(t=>(0,L.jsx)(A8,{file:t,loopId:e,staged:!0,onStage:()=>ee(t.path),onUnstage:()=>j(t.path),onDiscard:()=>te(t.path),onEdit:e=>n(e),onRefresh:D},t.path))})]}),(0,L.jsxs)(`div`,{className:`border-t border-gray-200`,children:[(0,L.jsxs)(`div`,{role:`button`,tabIndex:0,onClick:()=>E(e=>!e),onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&E(e=>!e)},className:`w-full px-3 py-1.5 flex items-center gap-1.5 hover:bg-gray-50 text-left cursor-pointer select-none`,children:[(0,L.jsx)(`span`,{className:`text-gray-500`,children:T?`▾`:`▸`}),(0,L.jsx)(Gt,{size:12,className:`text-gray-500`}),(0,L.jsx)(`span`,{className:`text-[11px] uppercase tracking-wide text-gray-500`,children:`History`}),(0,L.jsxs)(`span`,{className:`text-[11px] text-gray-400`,children:[`(`,x.length,`)`]})]}),T&&(0,L.jsx)(`div`,{className:`px-2 pb-2 max-h-64 overflow-auto`,children:C?(0,L.jsx)(`div`,{className:`px-3 py-3 text-[11px] text-gray-400 italic`,children:`loading history...`}):x.length===0?(0,L.jsx)(`div`,{className:`px-3 py-3 text-[11px] text-gray-400 italic`,children:`no commits`}):(0,L.jsx)(bie,{commits:x})})]})]})]})}function bie({commits:e}){let t=[`bg-blue-500`,`bg-emerald-500`,`bg-purple-500`,`bg-amber-500`,`bg-pink-500`,`bg-cyan-500`],n=new Map,r=0,i=e=>(n.has(e)||(n.set(e,t[r%t.length]),r++),n.get(e));return(0,L.jsx)(`div`,{className:`space-y-0`,children:e.map((t,n)=>{let r=t.branch??t.branches[0]??null,a=r?i(r):`bg-gray-400`,o=n===0,s=new Date(t.date).toLocaleDateString(void 0,{month:`short`,day:`numeric`}),c=new Date(t.date).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`});return(0,L.jsxs)(`div`,{className:`group/graph-row flex items-start gap-2 py-0.5 px-1.5 rounded hover:bg-gray-100 cursor-default text-[11px]`,title:`${t.subject}\n${t.author} · ${s} ${c}`,children:[(0,L.jsxs)(`div`,{className:`flex flex-col items-center shrink-0`,children:[(0,L.jsx)(`div`,{className:`w-2.5 h-2.5 rounded-full ${a} ring-2 ring-white ${o?`ring-blue-300`:``}`}),n<e.length-1&&(0,L.jsx)(`div`,{className:`w-0.5 h-10 ${a} opacity-10`})]}),(0,L.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,L.jsx)(`span`,{className:`font-mono text-[10px] text-gray-400 truncate`,children:t.shortHash}),o&&(0,L.jsx)(`span`,{className:`text-[9px] px-1 py-0 rounded bg-blue-100 text-blue-700 font-medium`,children:`HEAD`}),t.branches.slice(0,2).map(e=>(0,L.jsx)(`span`,{className:`text-[9px] px-1 py-0 rounded bg-emerald-100 text-emerald-700 font-medium truncate max-w-[60px]`,children:e},e)),t.tags.map(e=>(0,L.jsx)(`span`,{className:`text-[9px] px-1 py-0 rounded bg-purple-100 text-purple-700 font-medium`,children:e},e))]}),(0,L.jsx)(`div`,{className:`text-gray-700 truncate`,children:t.subject}),(0,L.jsxs)(`div`,{className:`text-gray-400 text-[10px]`,children:[t.author,` · `,s]})]})]},t.hash)})})}function k8({title:e,count:t,open:n,onToggle:r,bulkAction:i,children:a}){return(0,L.jsxs)(`div`,{className:`mb-2`,children:[(0,L.jsxs)(`div`,{role:`button`,tabIndex:0,onClick:r,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&r()},className:`w-full px-3 py-1.5 flex items-center gap-1.5 hover:bg-gray-50 text-left group/section cursor-pointer select-none`,children:[(0,L.jsx)(`span`,{className:`text-gray-500`,children:n?`▾`:`▸`}),(0,L.jsx)(`span`,{className:`text-[11px] uppercase tracking-wide text-gray-500`,children:e}),(0,L.jsxs)(`span`,{className:`text-[11px] text-gray-400`,children:[`(`,t,`)`]}),(0,L.jsx)(`div`,{className:`flex-1`}),(0,L.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),i.onClick()},className:`opacity-100 sm:opacity-0 sm:group-hover/section:opacity-100 transition-opacity px-1 py-0.5 rounded hover:bg-gray-200 text-gray-500 hover:text-gray-900 flex items-center gap-0.5`,title:i.label,children:i.icon})]}),n&&(0,L.jsx)(`div`,{children:a})]})}function A8({file:e,loopId:t,staged:n,onStage:r,onUnstage:i,onDiscard:a,onEdit:o,onRefresh:s}){let[c,l]=(0,F.useState)(!1),[u,d]=(0,F.useState)(null),[f,p]=(0,F.useState)(!1),[m,h]=(0,F.useState)(!1),[g,_]=(0,F.useState)(null),v=(0,F.useRef)(null);(0,F.useEffect)(()=>{let e=e=>{v.current&&!v.current.contains(e.target)&&_(null)};if(g)return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[g]);let y=async()=>{e.isBinary||(l(!0),u===null&&(p(!0),d(await wg(t,e.path,n)??``),p(!1)))},b=e=>{e.preventDefault(),_({x:e.clientX,y:e.clientY})},x=`workdir/${e.path}`,S=[{label:`Open in Editor`,icon:(0,L.jsx)(yn,{size:12}),onClick:()=>{o(x),_(null)}},{label:`View Diff`,icon:(0,L.jsx)(En,{size:12}),onClick:()=>{y(),_(null)}},{separator:!0,label:``,onClick:()=>{}},n?{label:`Unstage`,icon:(0,L.jsx)(fn,{size:12}),onClick:()=>{i(),_(null)}}:{label:`Stage`,icon:(0,L.jsx)(bn,{size:12}),onClick:()=>{r(),_(null)}},!n&&{label:`Discard Changes`,icon:(0,L.jsx)(Hn,{size:12}),onClick:()=>{h(!0),_(null)},danger:!0}].filter(Boolean),C=vie[e.status]??{label:e.status,color:`text-gray-500`},w=e.path.lastIndexOf(`/`),T=w>=0?e.path.slice(w+1):e.path,E=w>=0?e.path.slice(0,w+1):null;return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`div`,{className:`group/row relative flex items-center gap-2 px-3 py-1.5 hover:bg-gray-50`,onContextMenu:b,children:[(0,L.jsx)(`span`,{className:`w-5 text-center text-[11px] font-mono font-semibold ${C.color}`,children:C.label}),(0,L.jsxs)(`span`,{className:`flex-1 min-w-0 truncate text-[13px] font-mono`,children:[(0,L.jsx)(`span`,{className:`text-gray-900`,children:T}),E&&(0,L.jsx)(`span`,{className:`text-gray-400 ml-0.5`,children:E})]}),!e.isBinary&&(e.additions>0||e.deletions>0)&&(0,L.jsxs)(`span`,{className:`text-[11px] font-mono flex items-center gap-0.5 shrink-0`,children:[(0,L.jsxs)(`span`,{className:`text-emerald-600`,children:[`+`,e.additions]}),(0,L.jsxs)(`span`,{className:`text-red-500`,children:[`-`,e.deletions]})]}),(0,L.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 opacity-100 sm:opacity-0 sm:group-hover/row:opacity-100 transition-opacity shrink-0`,children:[(0,L.jsx)(`button`,{type:`button`,onClick:()=>o(x),className:`w-5 h-5 flex items-center justify-center text-gray-400 hover:text-blue-600 rounded`,title:`edit file`,children:(0,L.jsx)(yn,{size:13})}),n&&(0,L.jsx)(`button`,{type:`button`,onClick:y,className:`w-5 h-5 flex items-center justify-center text-gray-400 hover:text-gray-700 rounded`,title:`view diff`,disabled:e.isBinary,children:(0,L.jsx)(En,{size:13})}),n?(0,L.jsx)(`button`,{type:`button`,onClick:i,className:`w-5 h-5 flex items-center justify-center text-gray-400 hover:text-amber-600 rounded`,title:`unstage`,children:(0,L.jsx)(fn,{size:13})}):(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`button`,{type:`button`,onClick:()=>h(!0),className:`w-5 h-5 flex items-center justify-center text-gray-400 hover:text-red-500 rounded`,title:`discard changes`,children:(0,L.jsx)(Hn,{size:13})}),(0,L.jsx)(`button`,{type:`button`,onClick:r,className:`w-5 h-5 flex items-center justify-center text-gray-400 hover:text-emerald-600 rounded`,title:`stage`,children:(0,L.jsx)(bn,{size:13})})]})]})]}),g&&(0,L.jsx)(`div`,{ref:v,className:`fixed z-50 min-w-[160px] py-1 bg-white border border-gray-200 rounded-md shadow-lg text-[12px]`,style:{left:g.x,top:g.y},children:S.map((e,t)=>e.separator?(0,L.jsx)(`div`,{className:`my-1 border-t border-gray-100`},t):(0,L.jsxs)(`button`,{onClick:e.onClick,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left hover:bg-gray-100 ${e.danger?`text-red-600`:`text-gray-700`}`,children:[e.icon,(0,L.jsx)(`span`,{children:e.label})]},t))}),c&&(0,L.jsx)(_ie,{filePath:e.path,diff:u,loading:f,onClose:()=>l(!1)}),m&&(0,L.jsx)(P_,{open:!0,onOpenChange:e=>{e||h(!1)},children:(0,L.jsxs)(L_,{className:`sm:max-w-sm bg-white p-5 gap-4`,showCloseButton:!1,children:[(0,L.jsx)(R_,{children:(0,L.jsx)(z_,{className:`text-sm`,children:`Discard changes`})}),(0,L.jsx)(`p`,{className:`text-[13px] text-gray-600 break-all font-mono`,children:e.path}),(0,L.jsx)(`p`,{className:`text-[12px] text-gray-500`,children:e.status===`?`?`This file is untracked and will be deleted.`:`This will permanently discard all changes to this file. This action cannot be undone.`}),(0,L.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,L.jsx)(`button`,{onClick:()=>h(!1),className:`px-3 py-1.5 text-xs rounded bg-gray-100 text-gray-700 hover:bg-gray-200`,children:`Cancel`}),(0,L.jsx)(`button`,{onClick:()=>{h(!1),a()},className:`px-3 py-1.5 text-xs rounded bg-red-600 text-white hover:bg-red-700`,children:`Discard`})]})]})})]})}function j8(e){return e.shareMode===`ephemeral`?`ephemeral`:e.shareExternalPort?`direct`:`standard`}function xie({loop:e,open:t,onClose:n,onSaved:r}){let[i,a]=(0,F.useState)(null),[o,s]=(0,F.useState)(e.shareEnabled??!1),[c,l]=(0,F.useState)(e.shareMode===`ephemeral`?`ephemeral`:e.shareExternalPort?`direct`:e.shareMode??`static`),[u,d]=(0,F.useState)(e.shareAlias??``),[f,p]=(0,F.useState)(e.sharePort??3e3),[m,h]=(0,F.useState)(e.shareExternalPort??1e4),[g,_]=(0,F.useState)(e.shareProtocol??`tcp`),[v,y]=(0,F.useState)(null),[b,x]=(0,F.useState)(``),[S,C]=(0,F.useState)(!1),[w,T]=(0,F.useState)(!1),[E,D]=(0,F.useState)(!1),[O,k]=(0,F.useState)(``),[A,ee]=(0,F.useState)(!1),[j,te]=(0,F.useState)(``),[M,ne]=(0,F.useState)(``),[N,re]=(0,F.useState)(j8(e)),[ie,ae]=(0,F.useState)(null),oe=e.id.slice(0,8),se=!!(i&&i.serveEnabled),ce=!!(i&&i.serveDynamicEnabled),le=!!(i&&i.serveEphemeralEnabled),ue=[se,ce,le].filter(Boolean).length>1,de=se&&!ce&&!le,fe=!se&&ce&&!le,pe=!se&&!ce&&le;(0,F.useEffect)(()=>{t&&(Hg().then(a),s(e.shareEnabled??!1),l(e.shareMode===`ephemeral`?`ephemeral`:e.shareExternalPort?`direct`:e.shareMode??`static`),d(e.shareAlias??``),p(e.sharePort??3e3),h(e.shareExternalPort??1e4),_(e.shareProtocol??`tcp`),re(j8(e)),y(null),x(``),k(``),ae(null))},[t,e]),(0,F.useEffect)(()=>{if(!t||!(pe||ue&&N===`ephemeral`)||!e.shareEnabled||e.shareMode!==`ephemeral`)return;let n=!1,r=async()=>{let t=await Ug(e.id);n||ae(t.port)};r();let i=setInterval(r,3e3);return()=>{n=!0,clearInterval(i)}},[t,N,pe,ue,e.id,e.shareEnabled,e.shareMode]),(0,F.useEffect)(()=>{!t||!i||i.serveDynamicEnabled&&(e.shareEnabled&&e.shareExternalPort||!e.shareEnabled&&!e.shareExternalPort&&Gg().then(e=>{e.port&&h(e.port)}))},[t,i,e.shareEnabled,e.shareExternalPort]),(0,F.useEffect)(()=>{t&&qg(oe,e.id).then(e=>{e.available?D(!1):(D(!0),x(`ID "${oe}" is already in use. Please set an alias.`))})},[t,oe,e.id]),(0,F.useEffect)(()=>{if(!u||!t){y(null),x(``);return}let n=setTimeout(async()=>{let t=await qg(u,e.id);y(t.available),x(t.reason??``)},300);return()=>clearTimeout(n)},[u,t,e.id]);let me=u||oe,he=i?.https?`https`:`http`,ge=i?.withPort?`:${i.displayPort}`:``,_e=i?`${he}://${me}${i.baseUrl}${ge}`:``,ve=i?.serveDynamicDomain||i?.ip||`<host-ip>`,ye=g===`static`?`http://${ve}:${m}`:`tcp://${ve}:${m}`,P=i?.serveEphemeralDomain||i?.ip||`<host-ip>`,be=ie?`${g===`udp`?`udp`:`tcp`}://${P}:${ie}`:`(no active port — save & wait for container restart)`,xe=fe||ue&&N===`direct`&&ce&&!pe,Se=pe||ue&&N===`ephemeral`,Ce=Se?be:xe?ye:_e;(0,F.useEffect)(()=>{if(!t||!xe)return;let n=setTimeout(async()=>{ee(!0);let t=await Kg(m,e.id);ee(!1),t.available?k(``):k(t.reason??`Port unavailable`)},400);return()=>clearTimeout(n)},[m,t,c,e.id]);let we=async()=>{if(T(!0),xe){let t=await Kg(m,e.id);if(!t.available){k(t.reason??`Port unavailable`),T(!1);return}}let t={shareEnabled:o};o?Se?(t.shareMode=`ephemeral`,t.sharePort=f,t.shareProtocol=g===`static`?`tcp`:g,t.shareAlias=void 0,t.shareExternalPort=void 0):xe?(t.shareMode=`port`,t.sharePort=f,t.shareExternalPort=m,t.shareProtocol=g,t.shareAlias=void 0):(t.shareMode=c,t.shareAlias=u.trim()||void 0,c===`port`&&(t.sharePort=f),t.shareExternalPort=void 0,t.shareProtocol=void 0):(t.shareMode=void 0,t.shareAlias=void 0,t.sharePort=void 0);let i=await fetch(`/api/loops/${e.id}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify(t)});if(T(!1),i.ok)te(`Saved`),await r?.(),setTimeout(()=>{te(``),n()},800);else try{ne((await i.json()).error??`Save failed (${i.status})`)}catch{ne(`Save failed (${i.status})`)}},Te=async()=>{try{await navigator.clipboard.writeText(Ce),C(!0),setTimeout(()=>C(!1),1500)}catch{window.prompt(`Copy this URL:`,Ce)}},Ee=!w&&!O&&!A&&(Se?f>=1&&f<=65535:(!xe||m>=1024)&&(!xe||f>=1||g===`static`)&&(xe||c!==`port`||!E||u.trim().length>0)&&(xe||c!==`port`||f>=1024));return i?(0,L.jsx)(P_,{open:t,onOpenChange:e=>{e||n()},children:(0,L.jsxs)(L_,{className:`sm:max-w-md bg-white max-h-[85vh] overflow-y-auto`,children:[(0,L.jsxs)(R_,{children:[(0,L.jsxs)(z_,{className:`flex items-center gap-2 text-sm`,children:[(0,L.jsx)(qt,{size:16}),`Share Artifact`]}),(0,L.jsx)(Pee,{className:`sr-only`,children:`Share this artifact via a public URL.`})]}),(0,L.jsxs)(`div`,{className:`space-y-4 text-[13px]`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,L.jsx)(`span`,{className:`text-sm text-gray-700`,children:`Enable sharing`}),(0,L.jsx)(`button`,{onClick:()=>s(!o),className:`w-10 h-5 rounded-full transition-colors ${o?`bg-blue-600`:`bg-gray-300`}`,children:(0,L.jsx)(`div`,{className:`w-4 h-4 rounded-full bg-white shadow transition-transform ${o?`translate-x-5`:`translate-x-0.5`}`})})]}),o&&(0,L.jsxs)(L.Fragment,{children:[ue&&(0,L.jsxs)(`div`,{className:`flex gap-1.5 border-b border-gray-200 pb-2`,children:[se&&(0,L.jsx)(`button`,{onClick:()=>{re(`standard`),l(`static`)},className:`px-3 py-1 text-xs rounded-t ${N===`standard`?`bg-blue-50 text-blue-700 font-medium`:`text-gray-500 hover:text-gray-700`}`,children:`Subdomain`}),ce&&(0,L.jsx)(`button`,{onClick:()=>{re(`direct`),l(`direct`)},className:`px-3 py-1 text-xs rounded-t ${N===`direct`?`bg-blue-50 text-blue-700 font-medium`:`text-gray-500 hover:text-gray-700`}`,children:`Direct Port`}),le&&(0,L.jsx)(`button`,{onClick:()=>{re(`ephemeral`),l(`ephemeral`)},className:`px-3 py-1 text-xs rounded-t ${N===`ephemeral`?`bg-blue-50 text-blue-700 font-medium`:`text-gray-500 hover:text-gray-700`}`,children:`Ephemeral`})]}),(de||ue&&N===`standard`)&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:`Share mode`}),(0,L.jsxs)(`div`,{className:`grid grid-cols-2 gap-1.5 mt-1`,children:[(0,L.jsx)(`button`,{onClick:()=>l(`static`),className:`px-2 py-1.5 text-xs rounded border ${c===`static`?`bg-blue-50 border-blue-300 text-blue-700`:`border-gray-200 text-gray-600`}`,children:`Static files`}),(0,L.jsx)(`button`,{onClick:()=>l(`port`),className:`px-2 py-1.5 text-xs rounded border ${c===`port`?`bg-blue-50 border-blue-300 text-blue-700`:`border-gray-200 text-gray-600`}`,children:`Port proxy`})]})]}),(0,L.jsxs)(`div`,{children:[(0,L.jsxs)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:[`Alias `,E?(0,L.jsx)(`span`,{className:`text-red-500`,children:`(required)`}):`(optional)`]}),(0,L.jsx)(`input`,{value:u,onChange:e=>d(e.target.value.toLowerCase().replace(/[^a-z0-9-]/g,``)),className:`w-full mt-1 px-2 py-1.5 text-sm border rounded outline-none focus:border-gray-300 ${E?`border-red-300 bg-red-50`:`border-gray-200`}`,placeholder:E?`Set an alias to resolve conflict`:`my-project`}),E&&(0,L.jsxs)(`span`,{className:`text-[11px] text-red-500 mt-0.5 flex items-center gap-1`,children:[(0,L.jsx)(bt,{size:11}),` `,b||`ID "${oe}" is already in use`]}),!E&&v===!0&&(0,L.jsx)(`span`,{className:`text-[11px] text-emerald-600 mt-0.5`,children:`Available`}),!E&&v===!1&&(0,L.jsxs)(`span`,{className:`text-[11px] text-red-500 mt-0.5 flex items-center gap-1`,children:[(0,L.jsx)(bt,{size:11}),` `,b||`Already in use`]})]}),c===`port`&&(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:`Port (1024-65535)`}),(0,L.jsx)(`input`,{type:`number`,min:1024,max:65535,value:f,onChange:e=>p(parseInt(e.target.value,10)||3e3),className:`w-full mt-1 px-2 py-1.5 text-sm border border-gray-200 rounded outline-none focus:border-gray-300`})]})]}),Se&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:`Container port`}),(0,L.jsx)(`input`,{type:`number`,min:1,max:65535,value:f,onChange:e=>p(parseInt(e.target.value,10)||3e3),className:`w-full mt-1 px-2 py-1.5 text-sm border border-gray-200 rounded outline-none focus:border-gray-300`}),(0,L.jsx)(`p`,{className:`text-[10px] text-gray-400 mt-0.5`,children:`The port your app listens on inside the sandbox`})]}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:`Protocol`}),(0,L.jsxs)(`div`,{className:`flex gap-1.5 mt-1`,children:[(0,L.jsx)(`button`,{onClick:()=>_(`tcp`),className:`flex-1 px-2 py-1.5 text-xs rounded border ${g===`tcp`?`bg-blue-50 border-blue-300 text-blue-700`:`border-gray-200 text-gray-600`}`,children:`TCP`}),(0,L.jsx)(`button`,{onClick:()=>_(`udp`),className:`flex-1 px-2 py-1.5 text-xs rounded border ${g===`udp`?`bg-blue-50 border-blue-300 text-blue-700`:`border-gray-200 text-gray-600`}`,children:`UDP`})]})]}),(0,L.jsxs)(`div`,{children:[(0,L.jsxs)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider flex items-center gap-1.5`,children:[`Current host port`,(0,L.jsx)(Sn,{size:10,className:`text-gray-300`})]}),(0,L.jsx)(`div`,{className:`mt-1 px-2 py-1.5 text-sm bg-gray-50 rounded text-gray-700`,children:ie==null?(0,L.jsx)(`span`,{className:`text-gray-400 text-xs`,children:e.shareEnabled&&e.shareMode===`ephemeral`?`(container starting / not running)`:`(save to start — port assigned by kernel on restart)`}):(0,L.jsx)(`span`,{className:`font-mono`,children:ie})}),(0,L.jsxs)(`p`,{className:`text-[10px] text-amber-600 mt-1 flex items-center gap-1`,children:[(0,L.jsx)(bt,{size:10}),` Changes on every loop restart. Saving also restarts the container.`]})]})]}),(fe||ue&&N===`direct`&&!Se)&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:`External port`}),(0,L.jsxs)(`div`,{className:`flex gap-1.5 mt-1`,children:[(0,L.jsx)(`input`,{type:`number`,min:1024,max:65535,value:m,onChange:e=>h(parseInt(e.target.value,10)||1e4),className:`flex-1 px-2 py-1.5 text-sm border border-gray-200 rounded outline-none focus:border-gray-300`,placeholder:`10000`}),(0,L.jsx)(`button`,{onClick:async()=>{let e=await Gg();e.port&&h(e.port)},className:`px-2 py-1.5 rounded border border-gray-200 hover:bg-gray-100 text-gray-500`,title:`Pick a random available port`,children:(0,L.jsx)(Mn,{size:14})})]}),(0,L.jsx)(`p`,{className:`text-[10px] text-gray-400 mt-0.5`,children:`The public port clients connect to`}),A&&(0,L.jsx)(`span`,{className:`text-[11px] text-gray-400 mt-0.5`,children:`Checking availability…`}),O&&(0,L.jsxs)(`span`,{className:`text-[11px] text-red-500 mt-0.5 flex items-center gap-1`,children:[(0,L.jsx)(bt,{size:11}),` `,O]}),!A&&!O&&(0,L.jsx)(`span`,{className:`text-[11px] text-emerald-600 mt-0.5`,children:`Available`})]}),g!==`static`&&(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:`Container port`}),(0,L.jsx)(`input`,{type:`number`,min:1,max:65535,value:f,onChange:e=>p(parseInt(e.target.value,10)||3e3),className:`w-full mt-1 px-2 py-1.5 text-sm border border-gray-200 rounded outline-none focus:border-gray-300`}),(0,L.jsx)(`p`,{className:`text-[10px] text-gray-400 mt-0.5`,children:`The port your app listens on inside the sandbox`})]}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:`Protocol`}),(0,L.jsxs)(`div`,{className:`flex gap-1.5 mt-1`,children:[(0,L.jsx)(`button`,{onClick:()=>_(`tcp`),className:`flex-1 px-2 py-1.5 text-xs rounded border ${g===`tcp`?`bg-blue-50 border-blue-300 text-blue-700`:`border-gray-200 text-gray-600`}`,children:`TCP`}),i.serveDynamicUdpEnabled&&(0,L.jsx)(`button`,{onClick:()=>_(`udp`),className:`flex-1 px-2 py-1.5 text-xs rounded border ${g===`udp`?`bg-blue-50 border-blue-300 text-blue-700`:`border-gray-200 text-gray-600`}`,children:`UDP`}),i.serveDynamicStaticEnabled&&(0,L.jsx)(`button`,{onClick:()=>_(`static`),className:`flex-1 px-2 py-1.5 text-xs rounded border ${g===`static`?`bg-blue-50 border-blue-300 text-blue-700`:`border-gray-200 text-gray-600`}`,children:`Static`})]})]})]}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:`Access URL`}),(0,L.jsxs)(`div`,{className:`flex gap-2 mt-1`,children:[(0,L.jsx)(`code`,{className:`flex-1 px-2 py-1.5 text-xs bg-gray-50 rounded text-gray-700 truncate`,children:Ce}),(0,L.jsx)(`button`,{onClick:Te,className:`px-2 py-1.5 rounded hover:bg-gray-100 text-gray-500`,title:`Copy URL`,children:S?(0,L.jsx)(mt,{size:14,className:`text-emerald-600`}):(0,L.jsx)(Dt,{size:14})})]}),(0,L.jsx)(`p`,{className:`text-[10px] text-gray-400 mt-1`,children:xe?`Direct TCP/UDP access — no domain needed`:`Domain suffix configured in Settings → Workspace → Workspace Serve`})]})]}),(0,L.jsxs)(`div`,{className:`flex items-center justify-end gap-2 pt-2`,children:[M&&(0,L.jsx)(`span`,{className:`text-xs text-red-500`,children:M}),j&&(0,L.jsxs)(`span`,{className:`text-xs text-emerald-600 flex items-center gap-1`,children:[(0,L.jsx)(mt,{size:12}),` `,j]}),(0,L.jsx)(`button`,{onClick:n,className:`px-3 py-1.5 text-xs rounded bg-gray-100 text-gray-700 hover:bg-gray-200`,children:`Cancel`}),(0,L.jsx)(`button`,{onClick:we,disabled:!Ee,className:`px-3 py-1.5 text-xs rounded bg-blue-600 text-white hover:bg-blue-700 disabled:opacity-40`,children:w?`Saving...`:`Save`})]})]})]})}):null}var Sie=(0,F.lazy)(()=>A(()=>import(`./Editor-onKcF7Hk.js`).then(e=>({default:e.Editor})),__vite__mapDeps([78,3,79,80,81]))),Cie=(0,F.lazy)(()=>A(()=>import(`./Terminal-DQxchB0u.js`).then(e=>({default:e.Terminal})),__vite__mapDeps([82,3,80,83])));function wie(){let{id:e}=xi(),t=D_();if(!e)return(0,L.jsx)(Gi,{to:`/loop`,replace:!0});if(!t.currentUser)return(0,L.jsx)(cie,{});let n=t.loops.find(t=>t.id===e);return t.loopsLoading?null:n?(0,L.jsxs)(`div`,{className:`h-full w-full flex min-h-0`,children:[(0,L.jsx)(Tie,{currentId:e}),(0,L.jsx)(Eie,{meta:n},e)]}):(0,L.jsx)(Gi,{to:`/loop`,replace:!0})}function Tie({currentId:e}){let t=_i(),[n,r]=(0,F.useState)(()=>localStorage.getItem(`loopat:loopsList:collapsed`)===`1`),i=f6(),a=e=>{r(e),localStorage.setItem(`loopat:loopsList:collapsed`,e?`1`:`0`)},o=(0,L.jsxs)(`aside`,{className:`w-60 shrink-0 border-r border-gray-200 bg-white flex flex-col h-full`,children:[(0,L.jsx)(`div`,{className:`px-2 pt-1.5 border-b border-gray-200 flex items-center justify-end`,children:(0,L.jsx)(`button`,{type:`button`,onClick:()=>a(!0),className:`w-6 h-6 flex items-center justify-center text-gray-400 hover:text-gray-700 hover:bg-gray-100 rounded`,title:`collapse sidebar`,children:(0,L.jsx)(gn,{size:14})})}),(0,L.jsx)(C8,{currentId:e,onSelect:e=>{t(`/loop/${e}`),i&&a(!0)}})]});return n?(0,L.jsx)(`aside`,{className:`w-9 shrink-0 border-r border-gray-200 bg-white flex flex-col items-center pt-2`,children:(0,L.jsx)(`button`,{type:`button`,onClick:()=>a(!1),className:`w-7 h-7 flex items-center justify-center text-gray-500 hover:text-gray-900 hover:bg-gray-100 rounded`,title:`expand sidebar`,children:(0,L.jsx)(_n,{size:16})})}):i?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`aside`,{className:`w-9 shrink-0 border-r border-gray-200 bg-white flex flex-col items-center pt-2`,children:(0,L.jsx)(`button`,{type:`button`,onClick:()=>a(!0),className:`w-7 h-7 flex items-center justify-center text-gray-500 hover:text-gray-900 hover:bg-gray-100 rounded`,title:`collapse sidebar`,children:(0,L.jsx)(gn,{size:16})})}),(0,L.jsxs)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>a(!0),children:[(0,L.jsx)(`div`,{className:`absolute inset-0 bg-black/30`}),(0,L.jsx)(`div`,{className:`absolute left-0 top-0 bottom-0 w-64 max-w-[80vw] shadow-xl`,onClick:e=>e.stopPropagation(),children:o})]})]}):o}function Eie({meta:e}){let t=D_(),n=f6(),[r,i]=(0,F.useState)([]),[a,o]=(0,F.useState)(null),[s,c]=(0,F.useState)(null),[l,u]=(0,F.useState)([]),[d,f]=(0,F.useState)(!1),[p,m]=(0,F.useState)(null);(0,F.useEffect)(()=>{Hg().then(m)},[]);let[h,g]=(0,F.useState)(null),_=e=>{c(e),g(null),i(e=>e.includes(`editor`)?e:[...e,`editor`])},{runtime:v,connected:y,reconnecting:b,running:x,viewers:S,extra:C,queue:w,onClearQueue:T}=k6(e.id,t.currentUser?.id??``,_),E=S8((0,F.useMemo)(()=>[e.id],[e.id])),D=E[e.id]?.phase===`preparing`,O=E[e.id]?.status;(0,F.useEffect)(()=>{Vh(e.id).then(u),Nh(e.id),t.currentUser?.id&&localStorage.setItem(`loopat:lastLoop:${t.currentUser.id}`,e.id)},[e.id]);let k=pi(),A=_i(),ee=k.state?.kickoff;(0,F.useEffect)(()=>{!ee||!y||(C.enqueueMessage(ee),A(k.pathname,{replace:!0,state:null}))},[ee,y]);let j=e=>{i(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},te=e=>{i(t=>t.includes(e)?t.filter(t=>t!==e):[e])},M=e=>{i(t=>t.filter(t=>t!==e)),o(t=>t===e?null:t)},ne=r.length>0,N=r.filter(e=>e===`editor`||e===`terminal`),re=r.filter(e=>e!==`editor`&&e!==`terminal`),ie=N.length>0,ae=re.length>0,[oe,se]=(0,F.useState)(()=>{let e=parseInt(localStorage.getItem(`loopat:chatPct`)||``,10);return!isNaN(e)&&e>=10&&e<=90?e:55}),[ce,le]=(0,F.useState)(()=>{let e=parseInt(localStorage.getItem(`loopat:otherPct`)||``,10);return!isNaN(e)&&e>=5&&e<=50?e:18});(0,F.useEffect)(()=>{if(!ae){let e=parseInt(localStorage.getItem(`loopat:otherPct`)||``,10);!isNaN(e)&&e>=5&&e<=50&&le(e)}if(!ie&&!ae){let e=parseInt(localStorage.getItem(`loopat:chatPct`)||``,10);!isNaN(e)&&e>=10&&e<=90&&se(e)}},[ie,ae]);let ue=e=>{!isNaN(e.chat)&&e.chat>0&&localStorage.setItem(`loopat:chatPct`,String(Math.round(e.chat))),!isNaN(e.otherCol)&&e.otherCol>0&&localStorage.setItem(`loopat:otherPct`,String(Math.round(e.otherCol)))},de=n=>{let r=a===n;return(0,L.jsx)(Mie,{loopId:e.id,meta:e,mode:n,onClose:()=>M(n),pickedFile:s,onPickFile:_,currentUserId:t.currentUser?.id??``,isFullscreen:r,onToggleFullscreen:()=>o(r?null:n),onEditorSelection:g},n)};return(0,L.jsxs)(`div`,{className:`flex-1 min-w-0 min-h-0 flex flex-col`,children:[(0,L.jsx)(Die,{meta:e,mounts:l,connected:y,reconnecting:b,running:x,viewers:S,queue:w,onClearQueue:T,openPanels:r,toggleMode:j,onShareWork:()=>f(!0),showShareButton:!p||p.serveEnabled||p.serveDynamicEnabled||p.serveEphemeralEnabled}),e.contextWarnings&&e.contextWarnings.length>0&&(0,L.jsxs)(`div`,{className:`shrink-0 border-b border-amber-200 bg-amber-50 px-4 py-2 text-[12px] text-amber-800 leading-relaxed`,children:[(0,L.jsx)(`span`,{className:`font-semibold`,children:`⚠ Context not fully loaded.`}),` `,`This loop's knowledge/notes couldn't be cloned — it runs with an empty context until the access is fixed (check the key has access to the repo):`,(0,L.jsx)(`ul`,{className:`mt-1 ml-4 list-disc`,children:e.contextWarnings.map((e,t)=>(0,L.jsx)(`li`,{className:`font-mono text-[11px] break-all`,children:e},t))})]}),(0,L.jsxs)(`div`,{className:`relative flex-1 min-h-0 flex flex-col`,children:[D&&(0,L.jsx)(Aie,{detail:O}),n?(0,L.jsx)(`div`,{className:`flex-1 min-h-0`,children:(0,L.jsx)(O6,{extra:C,children:(0,L.jsx)(tw,{runtime:v,children:(0,L.jsx)(b8,{archived:e.archived===!0,onUnarchive:()=>t.setLoopArchived(e.id,!1),repo:e.repo,branch:e.branch,title:e.title,driver:e.driver??e.createdBy,driverHistory:e.driverHistory,rfdRequestedAt:e.rfdRequestedAt,rfdRequestedBy:e.rfdRequestedBy,onTakeDrive:()=>t.takeDrive(e.id),pickedFile:s,editorSelection:h})})})}):ne?(0,L.jsxs)(BE,{orientation:`horizontal`,className:`flex-1 min-w-0 min-h-0`,onLayoutChange:ue,children:[(0,L.jsx)(UE,{id:`chat`,minSize:20,defaultSize:oe,className:`flex flex-col min-h-0 min-w-0`,children:(0,L.jsx)(O6,{extra:C,children:(0,L.jsx)(tw,{runtime:v,children:(0,L.jsx)(b8,{archived:e.archived===!0,onUnarchive:()=>t.setLoopArchived(e.id,!1),repo:e.repo,branch:e.branch,title:e.title,driver:e.driver??e.createdBy,driverHistory:e.driverHistory,rfdRequestedAt:e.rfdRequestedAt,rfdRequestedBy:e.rfdRequestedBy,onTakeDrive:()=>t.takeDrive(e.id),pickedFile:s,editorSelection:h})})})}),(ie||ae)&&(0,L.jsx)(KE,{className:`relative w-4 -mx-1.5 cursor-col-resize group flex items-center justify-center after:absolute after:inset-y-0 after:left-1/2 after:w-px after:-translate-x-1/2 after:bg-gray-200 after:transition-colors hover:after:bg-blue-400`,children:(0,L.jsx)(`div`,{className:`absolute top-1/2 -translate-y-1/2 h-8 w-1.5 rounded-full bg-gray-300 group-hover:bg-blue-400 transition-colors`})}),ie&&(0,L.jsx)(UE,{id:`editorCol`,minSize:15,defaultSize:30,className:`flex flex-col min-h-0 min-w-0`,children:N.length>1?(0,L.jsx)(BE,{orientation:`vertical`,className:`flex-1 min-h-0`,children:N.map((e,t)=>(0,L.jsxs)(F.Fragment,{children:[t>0&&(0,L.jsx)(KE,{className:`relative h-4 -my-1.5 cursor-row-resize group flex items-center justify-center after:absolute after:left-0 after:right-0 after:top-1/2 after:h-px after:-translate-y-1/2 after:bg-gray-200 after:transition-colors hover:after:bg-blue-400`,children:(0,L.jsx)(`div`,{className:`absolute left-1/2 -translate-x-1/2 w-8 h-1.5 rounded-full bg-gray-300 group-hover:bg-blue-400 transition-colors`})}),(0,L.jsx)(UE,{id:e,minSize:10,defaultSize:100/N.length,className:`flex flex-col min-h-0 min-w-0`,children:de(e)})]},e))}):de(N[0])}),ie&&ae&&(0,L.jsx)(KE,{className:`relative w-4 -mx-1.5 cursor-col-resize group flex items-center justify-center after:absolute after:inset-y-0 after:left-1/2 after:w-px after:-translate-x-1/2 after:bg-gray-200 after:transition-colors hover:after:bg-blue-400`,children:(0,L.jsx)(`div`,{className:`absolute top-1/2 -translate-y-1/2 h-8 w-1.5 rounded-full bg-gray-300 group-hover:bg-blue-400 transition-colors`})}),ae&&(0,L.jsx)(UE,{id:`otherCol`,minSize:15,defaultSize:ce,className:`flex flex-col min-h-0 min-w-0`,children:re.length>1?(0,L.jsx)(BE,{orientation:`vertical`,className:`flex-1 min-h-0`,children:re.map((e,t)=>(0,L.jsxs)(F.Fragment,{children:[t>0&&(0,L.jsx)(KE,{className:`relative h-4 -my-1.5 cursor-row-resize group flex items-center justify-center after:absolute after:left-0 after:right-0 after:top-1/2 after:h-px after:-translate-y-1/2 after:bg-gray-200 after:transition-colors hover:after:bg-blue-400`,children:(0,L.jsx)(`div`,{className:`absolute left-1/2 -translate-x-1/2 w-8 h-1.5 rounded-full bg-gray-300 group-hover:bg-blue-400 transition-colors`})}),(0,L.jsx)(UE,{id:e,minSize:10,defaultSize:100/re.length,className:`flex flex-col min-h-0 min-w-0`,children:de(e)})]},e))}):de(re[0])})]}):(0,L.jsx)(`div`,{className:`flex-1 min-h-0`,children:(0,L.jsx)(O6,{extra:C,children:(0,L.jsx)(tw,{runtime:v,children:(0,L.jsx)(b8,{archived:e.archived===!0,onUnarchive:()=>t.setLoopArchived(e.id,!1),repo:e.repo,branch:e.branch,title:e.title,driver:e.driver??e.createdBy,driverHistory:e.driverHistory,rfdRequestedAt:e.rfdRequestedAt,rfdRequestedBy:e.rfdRequestedBy,onTakeDrive:()=>t.takeDrive(e.id),pickedFile:s,editorSelection:h})})})})]}),ne&&n&&r.map(e=>(0,L.jsx)(F.Fragment,{children:de(e)},e)),n&&(0,L.jsx)(`div`,{className:`fixed bottom-0 left-0 z-30 w-9 flex flex-col items-center gap-0.5 pb-2`,children:[`terminal`,`editor`,`workdir`,`git`].map(e=>(0,L.jsx)(`button`,{type:`button`,onClick:()=>te(e),className:`w-7 h-7 flex items-center justify-center rounded text-xs ${r.includes(e)?`bg-gray-200 text-gray-900`:`text-gray-400 hover:text-gray-700 hover:bg-gray-100`}`,title:e,children:e===`terminal`?`▷`:e===`editor`?`✎`:e===`workdir`?`▤`:`⑂`},e))}),(0,L.jsx)(xie,{loop:e,open:d,onClose:()=>f(!1),onSaved:async()=>{await t.refresh()}})]})}function Die({meta:e,mounts:t,connected:n,reconnecting:r,running:i,viewers:a,queue:o,onClearQueue:s,openPanels:c,toggleMode:l,onShareWork:u,showShareButton:d}){let f=f6(),p=_i(),m=D_(),[h,g]=(0,F.useState)(f),[_,v]=(0,F.useState)(!1),[y,b]=(0,F.useState)(!1),[x,S]=(0,F.useState)(e.title),C=m.currentUser?.id===e.createdBy,w=async()=>{if(!_){v(!0);try{let t=await bee(e.id);t&&p(`/loop/${t.id}`)}finally{v(!1)}}},T=async()=>{let t=x.trim();if(!t||t===e.title){b(!1),S(e.title);return}b(!1),await m.setLoopTitle(e.id,t)||S(e.title)},E=(e,t)=>(0,L.jsx)(`button`,{className:c.includes(t)?`px-2 py-0.5 rounded bg-gray-100 text-gray-900`:`px-2 py-0.5 rounded text-gray-500 hover:text-gray-900 hover:bg-gray-50`,onClick:()=>l(t),children:e},t);return(0,L.jsxs)(`header`,{className:`group/header px-3 md:px-5 shrink-0 border-b border-gray-200 `+(h?`py-1.5`:`pt-3 pb-2`),children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,L.jsx)(`button`,{type:`button`,onClick:()=>g(e=>!e),className:`text-gray-400 hover:text-gray-700 -ml-1 p-0.5 rounded hover:bg-gray-100`,title:h?`expand header`:`collapse header`,children:(0,L.jsx)(ht,{size:14,className:`transition-transform `+(h?`-rotate-90`:``)})}),y?(0,L.jsx)(`input`,{type:`text`,value:x,autoFocus:!0,onChange:e=>S(e.target.value),onKeyDown:t=>{t.key===`Enter`&&!t.nativeEvent.isComposing?(t.preventDefault(),T()):t.key===`Escape`&&(t.preventDefault(),b(!1),S(e.title))},onBlur:T,maxLength:200,className:`text-[14px] md:text-[15px] font-medium text-gray-900 bg-white border border-blue-400 rounded px-1 py-0 outline-none min-w-[120px]`}):(0,L.jsx)(`span`,{className:`text-[14px] md:text-[15px] font-medium text-gray-900 `+(C?`cursor-pointer hover:bg-gray-100 rounded px-1 -mx-1`:``),onClick:()=>{C&&(S(e.title),b(!0))},title:C?`click to rename`:void 0,children:e.title}),(0,L.jsxs)(`span`,{className:`text-xs text-gray-500`,children:[`driver: `,(0,L.jsx)(`span`,{className:`text-gray-900`,children:e.driver??e.createdBy})]}),e.rfdRequestedAt&&(0,L.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-amber-100 text-amber-800 border border-amber-200 font-medium tracking-wide`,title:`released for drive by ${e.rfdRequestedBy??`?`} at ${e.rfdRequestedAt}`,children:`RFD`}),!n&&r&&(0,L.jsx)(`span`,{className:`text-[11px] text-amber-600`,children:`reconnecting…`}),i&&(0,L.jsx)(`span`,{className:`text-[11px] text-blue-600`,children:`running`}),a>1&&(0,L.jsxs)(`span`,{title:`people watching`,className:`text-[11px] px-1.5 py-0.5 rounded bg-emerald-50 text-emerald-800 border border-emerald-200`,children:[`👥 `,a]}),(0,L.jsx)(`div`,{className:`flex-1`}),(0,L.jsxs)(`button`,{type:`button`,onClick:w,disabled:_,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] border bg-white text-violet-700 border-violet-300 hover:bg-violet-50 disabled:opacity-50`,title:`Spawn a child loop seeded with this loop's conversation, for sedimenting reusable insights into knowledge/`,children:[(0,L.jsx)(Bt,{size:11}),_?`Distilling…`:`Distill`]}),d!==!1&&(0,L.jsxs)(`button`,{onClick:u,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] border ${e.shareEnabled?`bg-blue-50 text-blue-700 border-blue-200 hover:bg-blue-100`:`bg-white text-gray-700 border-gray-300 hover:bg-gray-100`}`,title:`Share workspace artifact (static files or port forward)`,children:[(0,L.jsx)(qt,{size:11}),`Share Artifact`]}),(0,L.jsx)(kie,{meta:e}),(0,L.jsx)(Oie,{meta:e})]}),!h&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`div`,{className:`text-xs text-gray-500 mt-1.5 flex items-center gap-2 flex-wrap`,children:[(0,L.jsxs)(`span`,{className:`font-mono`,children:[`~/.loopat/loops/`,e.id.slice(0,8),`/workdir`]}),(0,L.jsx)(`span`,{children:`·`}),(0,L.jsx)(`span`,{children:`main`}),a>0&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`span`,{children:`·`}),(0,L.jsxs)(`span`,{children:[a,` viewing`]})]}),(0,L.jsx)(`div`,{className:`flex-1`}),(0,L.jsxs)(`div`,{className:`flex items-center gap-1 text-[11px]`,children:[E(`ℹ info`,`info`),E(`▤ workdir`,`workdir`),E(`✎ editor`,`editor`),E(`▷ terminal`,`terminal`),(0,L.jsx)(`button`,{className:c.includes(`git`)?`px-2 py-0.5 rounded bg-gray-100 text-gray-900`:`px-2 py-0.5 rounded text-gray-500 hover:text-gray-900 hover:bg-gray-50`,onClick:()=>l(`git`),title:`git changes`,children:(0,L.jsx)(Gt,{size:14})})]})]}),(0,L.jsxs)(`div`,{className:`mt-2 flex items-center gap-1.5 flex-wrap text-[11px]`,children:[(0,L.jsx)(`span`,{className:`text-gray-400`,children:`context:`}),t.map(e=>(0,L.jsx)(M8,{label:e.name,value:e.name===`knowledge`?`ro`:`rw`},e.path))]}),e.config?.profiles&&e.config.profiles.length>0&&(0,L.jsx)(jie,{profiles:e.config.profiles}),(0,L.jsxs)(`div`,{className:`mt-1 flex items-center gap-1.5 flex-wrap text-[11px]`,children:[(0,L.jsx)(`span`,{className:`text-gray-400`,children:`vault:`}),(0,L.jsx)(M8,{label:e.config?.vault??`default`,value:`loaded`})]})]})]})}function Oie({meta:e}){let t=D_(),[n,r]=(0,F.useState)(!1),[i,a]=(0,F.useState)(!1),o=t.currentUser?.id===e.createdBy,s=e.public===!0;if(!t.currentUser)return null;let c=`${location.origin}/loop/${e.id}`;return o?(0,L.jsxs)(`div`,{className:`inline-flex items-center gap-1`,children:[s&&(0,L.jsxs)(`button`,{type:`button`,onClick:async()=>{try{await navigator.clipboard.writeText(c),r(!0),setTimeout(()=>r(!1),1500)}catch{}},title:c,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] text-gray-600 hover:bg-gray-100`,children:[n?(0,L.jsx)(mt,{size:11}):(0,L.jsx)(Dt,{size:11}),(0,L.jsx)(`span`,{className:`hidden md:inline`,children:n?`copied`:`copy link`})]}),(0,L.jsxs)(`button`,{type:`button`,onClick:async()=>{if(!(!o||i)){a(!0);try{await t.setLoopPublic(e.id,!s)}finally{a(!1)}}},disabled:i,title:s?`stop sharing`:`share publicly (anyone with the link can view)`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] border disabled:opacity-50 `+(s?`bg-emerald-50 text-emerald-800 border-emerald-200 hover:bg-emerald-100`:`bg-white text-gray-700 border-gray-300 hover:bg-gray-100`),children:[s?(0,L.jsx)(qt,{size:11}):(0,L.jsx)(on,{size:11}),s?`shared`:`share`]})]}):(0,L.jsxs)(`span`,{title:s?`this loop is shared publicly`:`this loop is private`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] `+(s?`bg-emerald-50 text-emerald-800 border border-emerald-200`:`bg-gray-100 text-gray-600`),children:[s?(0,L.jsx)(qt,{size:11}):(0,L.jsx)(on,{size:11}),s?`public`:`private`]})}function kie({meta:e}){let t=D_(),[n,r]=(0,F.useState)(!1);if(!t.currentUser)return null;let i=e.driver??e.createdBy,a=t.currentUser.id===i;return e.rfdRequestedAt?(0,L.jsxs)(`button`,{type:`button`,disabled:n,onClick:async()=>{r(!0);try{await t.takeDrive(e.id)}finally{r(!1)}},title:`released for drive by ${e.rfdRequestedBy??`?`} — click to take over`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] border bg-amber-500 text-white border-amber-600 hover:bg-amber-600 disabled:opacity-50`,children:[(0,L.jsx)(Jt,{size:11}),`Drive`]}):a?(0,L.jsxs)(`button`,{type:`button`,disabled:n,onClick:async()=>{if(window.confirm(`Request For Drive: this will tear down the sandbox and release the loop so anyone else can take over. Continue?`)){r(!0);try{await t.requestDrive(e.id)}finally{r(!1)}}},title:`Release this loop so someone else can drive it`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] border bg-white text-amber-700 border-amber-300 hover:bg-amber-50 disabled:opacity-50`,children:[(0,L.jsx)(Jt,{size:11}),`Request For Drive`]}):null}function Aie({detail:e}){return(0,L.jsx)(`div`,{className:`absolute inset-0 z-30 flex items-center justify-center bg-white/70 backdrop-blur-sm`,children:(0,L.jsxs)(`div`,{className:`max-w-md mx-6 px-6 py-5 rounded-xl border border-blue-200 bg-white shadow-lg text-center`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-center gap-2 mb-2`,children:[(0,L.jsx)(`span`,{className:`inline-block w-4 h-4 rounded-full border-2 border-blue-500 border-t-transparent animate-spin`}),(0,L.jsx)(`span`,{className:`text-sm font-medium text-gray-900`,children:`Preparing this loop’s sandbox…`})]}),(0,L.jsxs)(`p`,{className:`text-[12px] text-gray-600 leading-relaxed`,children:[`Installing the toolchain from `,(0,L.jsx)(`code`,{className:`font-mono text-[11px] bg-gray-100 px-1 rounded`,children:`mise.toml`}),`. Terminal and chat are paused until tools are ready — this only happens the first time.`]}),e&&e!==`Ready`&&(0,L.jsx)(`p`,{className:`mt-2 text-[11px] font-mono text-blue-700 break-words`,children:e})]})})}function M8({label:e,value:t,title:n}){return(0,L.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded bg-gray-100 text-[11px]`,title:n,children:[(0,L.jsxs)(`span`,{className:`text-gray-500`,children:[e,`:`]}),(0,L.jsx)(`span`,{className:`text-gray-900 font-medium`,children:t})]})}function jie({profiles:e}){let[t,n]=(0,F.useState)({});return(0,F.useEffect)(()=>{let e=!1;return Mh().then(t=>{if(e)return;let r={};for(let e of t)e.description&&(r[e.name]=e.description);n(r)}).catch(()=>{}),()=>{e=!0}},[]),(0,L.jsxs)(`div`,{className:`mt-1 flex items-center gap-1.5 flex-wrap text-[11px]`,children:[(0,L.jsx)(`span`,{className:`text-gray-400`,children:`profiles:`}),e.map(e=>(0,L.jsx)(M8,{label:e,value:`active`,title:t[e]},e))]})}function Mie({loopId:e,meta:t,mode:n,onClose:r,pickedFile:i,onPickFile:a,currentUserId:o,isFullscreen:s,onToggleFullscreen:c,onEditorSelection:l}){let u=f6(),[d,f]=(0,F.useState)(()=>{let e=localStorage.getItem(`loopat:mobilePanelPct`);return e?Math.max(20,Math.min(95,parseInt(e)||55)):55}),p=(0,F.useRef)(null),m=e=>{localStorage.setItem(`loopat:mobilePanelPct`,String(e))},h=e=>{if(p.current={startY:e,startPct:d},s){let t=Math.round(e/window.innerHeight*100),n=Math.max(20,Math.min(95,t));f(n),m(n),c?.()}},g=e=>{if(!p.current)return;let t=e-p.current.startY,n=Math.round(t/window.innerHeight*100),r=Math.max(20,Math.min(95,p.current.startPct+n));f(r),m(r)},_=()=>{p.current=null},v=e=>{e.preventDefault(),e.stopPropagation(),h(e.touches[0].clientY)},y=e=>{e.preventDefault(),g(e.touches[0].clientY)},b=e=>{e.preventDefault(),_()},x=e=>{e.pointerType!==`touch`&&(e.preventDefault(),e.target.setPointerCapture(e.pointerId),h(e.clientY))},S=e=>{e.pointerType===`touch`||!p.current||g(e.clientY)},C=e=>{e.pointerType!==`touch`&&_()},w=(0,L.jsxs)(`aside`,{className:`flex-1 min-w-0 bg-white flex flex-col`,children:[(0,L.jsxs)(`header`,{className:`px-3 h-8 shrink-0 border-b border-gray-200 flex items-center gap-1 text-[11px] text-gray-500`,children:[(0,L.jsx)(`span`,{className:`capitalize`,children:n}),n===`editor`&&(0,L.jsx)(`span`,{className:`ml-2 truncate text-gray-700`,children:i||`(no file)`}),(0,L.jsx)(`div`,{className:`flex-1`}),(n===`editor`||n===`terminal`)&&(0,L.jsx)(`button`,{className:`text-gray-400 hover:text-gray-700 px-1 rounded hover:bg-gray-100`,onClick:c,title:s?`restore`:`maximize`,children:s?(0,L.jsx)(dn,{size:13}):(0,L.jsx)(cn,{size:13})}),(0,L.jsx)(`button`,{className:`text-gray-500 hover:text-gray-900 px-1 rounded hover:bg-gray-100`,onClick:r,title:`close panel`,children:`✕`})]}),n===`info`&&(0,L.jsx)(Nie,{meta:t}),n===`workdir`&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(pie,{loopId:e,onPick:a,picked:i}),(0,L.jsxs)(`div`,{className:`border-t border-gray-200 px-3 py-2 text-[11px] text-gray-500`,children:[`⑂ `,(0,L.jsx)(`span`,{className:`text-gray-900`,children:`main`})]})]}),(0,L.jsxs)(F.Suspense,{fallback:(0,L.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-gray-400 text-sm`,children:`Loading...`}),children:[n===`editor`&&(0,L.jsx)(Sie,{loopId:e,path:i,onSelectionChange:l}),n===`terminal`&&(0,L.jsx)(`div`,{className:`flex-1 min-h-0 bg-[#1a1c20] overflow-hidden`,children:(0,L.jsx)(Cie,{loopId:e,currentUserId:o})}),n===`git`&&(0,L.jsx)(yie,{loopId:e,onClose:r,onPickFile:a})]})]});return u?(0,L.jsxs)(`div`,{className:`fixed inset-x-0 top-0 z-40 bg-white rounded-b-xl shadow-xl pointer-events-auto overflow-hidden`,style:{height:s?`100vh`:`${d}vh`},children:[(0,L.jsx)(`div`,{className:`absolute inset-0 bottom-7 overflow-y-auto flex flex-col`,children:w}),(0,L.jsx)(`div`,{className:`absolute inset-x-0 bottom-0 h-7 z-10 flex items-center justify-center cursor-row-resize active:bg-gray-50 rounded-b-xl`,style:{touchAction:`none`},onTouchStart:v,onTouchMove:y,onTouchEnd:b,onPointerDown:x,onPointerMove:S,onPointerUp:C,children:(0,L.jsx)(`div`,{className:`w-8 h-1 rounded-full bg-gray-300`})})]}):s?(0,vo.createPortal)((0,L.jsx)(`div`,{className:`fixed inset-0 z-50 flex flex-col`,children:w}),document.body):w}function Nie({meta:e}){let t=D_().currentUser?.id===e.createdBy;return(0,L.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-auto px-5 py-4 text-[13px] text-gray-900`,children:[(0,L.jsxs)(N8,{label:`basics`,children:[(0,L.jsx)(P8,{label:`title`,value:e.title}),(0,L.jsx)(P8,{label:`created`,value:new Date(e.createdAt).toLocaleString()}),(0,L.jsx)(P8,{label:`status`,value:`active`}),(0,L.jsx)(P8,{label:`driver`,value:t?`${e.createdBy} (you)`:e.createdBy}),(0,L.jsx)(P8,{label:`sharing`,value:e.public?`public — /loop/${e.id.slice(0,8)}…`:`private`})]}),(0,L.jsxs)(N8,{label:`workdir`,children:[(0,L.jsx)(P8,{label:`id`,value:e.id,mono:!0}),(0,L.jsx)(P8,{label:`path`,value:`~/.loopat/loops/${e.id.slice(0,8)}/workdir`,mono:!0}),(0,L.jsx)(P8,{label:`branch`,value:`main`,mono:!0})]}),(0,L.jsxs)(N8,{label:`context`,children:[(0,L.jsx)(P8,{label:`knowledge`,value:`all (ro)`}),(0,L.jsx)(P8,{label:`notes`,value:`all (rw)`}),(0,L.jsx)(P8,{label:`personal`,value:`${e.createdBy} (rw)`})]})]})}function N8({label:e,children:t}){return(0,L.jsxs)(`section`,{className:`mb-5`,children:[(0,L.jsx)(`h3`,{className:`text-[11px] uppercase tracking-wide text-gray-400 mb-2`,children:e}),(0,L.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:t})]})}function P8({label:e,value:t,mono:n=!1}){return(0,L.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,L.jsx)(`span`,{className:`text-[11px] text-gray-500 w-24 shrink-0`,children:e}),(0,L.jsx)(`span`,{className:n?`font-mono text-[12px] text-gray-800 truncate`:`text-[13px] text-gray-900 truncate`,children:t})]})}function F8({name:e,onClick:t,onEdit:n,size:r=`sm`}){return(0,L.jsxs)(`span`,{className:`relative inline-flex items-center group/chip`,children:[(0,L.jsxs)(`button`,{type:`button`,onClick:t,className:`inline-flex items-center rounded-full bg-sky-50 text-sky-700 border border-sky-200 hover:bg-sky-100 transition-colors font-mono `+(r===`md`?`px-2 py-0.5 text-[12px]`:`px-1.5 py-0.5 text-[10px]`),title:`#${e}`,children:[`#`,e]}),n&&(0,L.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),n()},className:`absolute -top-1 -right-1 z-10 w-4 h-4 rounded-full bg-white border border-gray-300 hover:border-red-400 hover:text-red-500 text-[9px] text-gray-400 opacity-0 group-hover/chip:opacity-100 transition-opacity flex items-center justify-center shadow-sm`,title:`Remove tag`,children:`×`})]})}function Pie(){let{name:e}=xi(),t=decodeURIComponent(e??``),n=_i(),[r,i]=(0,F.useState)(null),[a,o]=(0,F.useState)(!0);return(0,F.useEffect)(()=>{let e=!1;return Nee().then(n=>{e||(i(n.find(e=>e.name===t.toLowerCase())??null),o(!1))}),()=>{e=!0}},[t]),(0,L.jsxs)(`div`,{className:`flex flex-col h-full w-full bg-white`,children:[(0,L.jsxs)(`header`,{className:`h-10 shrink-0 flex items-center gap-3 px-6 border-b border-gray-200`,children:[(0,L.jsx)(`button`,{type:`button`,onClick:()=>n(-1),className:`text-[11px] text-gray-500 hover:text-gray-900`,children:`← back`}),(0,L.jsx)(F8,{name:t,size:`md`}),(0,L.jsx)(`div`,{className:`flex-1`})]}),(0,L.jsx)(`main`,{className:`flex-1 min-w-0 flex flex-col overflow-auto`,children:(0,L.jsx)(`div`,{className:`px-4 md:px-8 py-4 md:py-8 mx-auto w-full max-w-[760px] flex flex-col gap-5`,children:a?(0,L.jsx)(`div`,{className:`text-[12px] text-gray-400 italic`,children:`loading…`}):!r||r.loops.length===0?(0,L.jsxs)(`div`,{className:`text-[12px] text-gray-400 italic`,children:[`no entities tagged with `,(0,L.jsxs)(`code`,{children:[`#`,t]})]}):(0,L.jsxs)(`section`,{children:[(0,L.jsxs)(`div`,{className:`text-[12px] uppercase tracking-wider text-gray-500 mb-2 px-1`,children:[`Loops (`,r.loops.length,`)`]}),(0,L.jsx)(`div`,{className:`flex flex-col gap-1`,children:r.loops.map(e=>(0,L.jsxs)(`button`,{type:`button`,onClick:()=>n(`/loop/${e.id}`),className:`w-full text-left px-3 py-2 rounded border border-gray-200 hover:border-gray-400 hover:bg-gray-50 text-[13px] text-gray-900`,children:[e.title,(0,L.jsx)(`span`,{className:`ml-2 text-[10px] font-mono text-gray-400`,children:e.id.slice(0,6)})]},e.id))})]})})})]})}var I8=(0,F.lazy)(()=>A(()=>import(`./CodeEditor-ROIg2ylA.js`).then(e=>({default:e.CodeEditor})),__vite__mapDeps([79,3,80,81]))),L8=(0,F.lazy)(()=>A(()=>import(`./Markdown-TRpyMaSJ.js`).then(e=>({default:e.Markdown})),__vite__mapDeps([84,3,85,80]))),Fie=(0,F.lazy)(()=>A(()=>import(`./MilkdownEditor-CPzvRlCr.js`).then(e=>({default:e.MilkdownEditor})),__vite__mapDeps([86,3,85,9,10,80,81]))),Iie=[{id:`knowledge`,label:`Knowledge`},{id:`notes`,label:`Notes`},{id:`personal`,label:`Personal`},{id:`repos`,label:`Repos`}],Lie=new Set([`knowledge`,`notes`,`personal`,`repos`]);function Rie(){let{sub:e}=xi(),[t]=Ya(),n=Lie.has(e)?e:`knowledge`,r=t.get(`file`)||void 0,i=t.get(`edit`)===`1`;return(0,L.jsxs)(`div`,{className:`flex flex-col h-full w-full`,children:[(0,L.jsx)(`nav`,{className:`flex items-center gap-1 px-3 h-9 shrink-0 border-b border-gray-200 bg-white`,children:Iie.map(e=>(0,L.jsx)(Ha,{to:`/context/${e.id}`,className:({isActive:e})=>e?`h-7 px-2.5 rounded flex items-center gap-1.5 text-xs bg-gray-100 text-gray-900`:`h-7 px-2.5 rounded flex items-center gap-1.5 text-xs text-gray-500 hover:bg-gray-50 hover:text-gray-900`,children:(0,L.jsx)(`span`,{children:e.label})},e.id))}),(0,L.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0`,children:n===`repos`?(0,L.jsx)(Jie,{}):(0,L.jsx)(Hie,{vault:n,initialFile:r,initialEditing:i},n)})]})}var zie={knowledge:`workspace's distilled materials`,notes:`workspace · public`,personal:`yours · private`,repos:`registered code repos`};function Bie({resource:e,canPush:t=!0}){let[n,r]=(0,F.useState)(null),[i,a]=(0,F.useState)(null),[o,s]=(0,F.useState)(null),c=(0,F.useCallback)(async()=>{a(`status`),r(await ig(e)),a(null)},[e]);(0,F.useEffect)(()=>{c()},[c]);let l=async()=>{a(`pull`),s(null);let t=await ag(e);a(null),s(t.ok?{ok:!0,text:t.message??`pulled`}:{ok:!1,text:t.error??`pull failed`}),t.ok&&c()},u=async()=>{a(`push`),s(null);let t=await og(e);a(null),s(t.ok?{ok:!0,text:t.message??`pushed`}:{ok:!1,text:t.error??`push failed`}),t.ok&&c()},d=n?.ahead??0,f=n?.behind??0,p=n&&!n.hasRemote;return(0,L.jsxs)(`div`,{className:`px-3 py-1.5 border-t border-gray-200 flex flex-col gap-1 text-[11px]`,children:[(0,L.jsx)(`div`,{className:`flex items-center gap-2`,children:p?(0,L.jsx)(`span`,{className:`text-gray-400`,children:`no remote`}):(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`span`,{className:d>0?`text-emerald-700`:`text-gray-400`,title:`unpushed commits`,children:[`↑`,d]}),(0,L.jsxs)(`span`,{className:f>0?`text-amber-700`:`text-gray-400`,title:`unpulled commits`,children:[`↓`,f]}),n&&n.uncommitted>0&&(0,L.jsxs)(`span`,{className:`text-red-600`,title:`uncommitted changes in primary`,children:[`! `,n.uncommitted]}),(0,L.jsx)(`button`,{onClick:()=>void c(),disabled:i!==null,className:`ml-auto text-gray-400 hover:text-gray-700 disabled:opacity-50`,title:`refresh status`,children:`↻`})]})}),!p&&(0,L.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,L.jsx)(`button`,{onClick:l,disabled:i!==null||f===0,className:`px-1.5 h-5 rounded border border-gray-200 hover:bg-gray-100 text-gray-700 disabled:opacity-40 disabled:cursor-not-allowed`,children:i===`pull`?`pulling…`:`pull`}),t&&(0,L.jsx)(`button`,{onClick:u,disabled:i!==null||d===0,className:`px-1.5 h-5 rounded border border-gray-200 hover:bg-gray-100 text-gray-700 disabled:opacity-40 disabled:cursor-not-allowed`,children:i===`push`?`pushing…`:`push`}),o&&(0,L.jsx)(`span`,{className:`truncate flex-1 min-w-0 `+(o.ok?`text-emerald-700`:`text-red-600`),title:o.text,children:o.text})]})]})}function Vie({onRefreshed:e}){let[t,n]=(0,F.useState)(0),[r,i]=(0,F.useState)(!1),[a,o]=(0,F.useState)(null),s=(0,F.useRef)(e);s.current=e;let c=(0,F.useCallback)(async()=>{i(!0),o(null);let e=await Jh();i(!1),e.ok?(n(0),s.current()):e.diverged?o(`你有未保存的编辑,先保存再刷新`):o(e.error??`refresh failed`)},[]);return(0,F.useEffect)(()=>{c()},[c]),(0,F.useEffect)(()=>{let e=()=>qh().then(n).catch(()=>{});e();let t=setInterval(e,5e3);return()=>clearInterval(t)},[]),(0,L.jsxs)(`div`,{className:`px-3 py-2 border-t border-gray-200 flex flex-col gap-1.5 text-[11px]`,children:[t>0?(0,L.jsxs)(`div`,{className:`flex items-center justify-between gap-2 bg-amber-50 border border-amber-200 rounded px-2 py-1 text-amber-800`,children:[(0,L.jsxs)(`span`,{children:[`远端已更新 `,t,` 个改动`]}),(0,L.jsx)(`button`,{type:`button`,onClick:c,disabled:r,className:`px-2 py-0.5 rounded bg-amber-600 text-white hover:bg-amber-700 disabled:opacity-50`,children:r?`刷新中…`:`刷新`})]}):(0,L.jsxs)(`div`,{className:`flex items-center justify-between gap-2 text-gray-400`,children:[(0,L.jsx)(`span`,{children:`已是最新`}),(0,L.jsx)(`button`,{type:`button`,onClick:c,disabled:r,className:`text-gray-500 hover:text-gray-900 underline disabled:opacity-50`,children:r?`刷新中…`:`刷新`})]}),a&&(0,L.jsx)(`div`,{className:`text-amber-700`,children:a})]})}function Hie({vault:e,initialFile:t,initialEditing:n}){let[r,i]=(0,F.useState)([]),[a,o]=(0,F.useState)([]),[s,c]=(0,F.useState)(t??null),[l,u]=Ya();(0,F.useEffect)(()=>{(l.get(`file`)??null)!==s&&u(s?{file:s}:{},{replace:!0})},[s,l,u]);let[d,f]=(0,F.useState)(0),[p,m]=(0,F.useState)(!1),[h,g]=(0,F.useState)(``),[_,v]=(0,F.useState)(!1),[y,b]=(0,F.useState)(null),[x,S]=(0,F.useState)(``),C=f6(),w=(0,F.useRef)(!1);if(!w.current&&t){w.current=!0;let n=`vault-${e}`,r=t.includes(`/`)?t.substring(0,t.lastIndexOf(`/`)):``;if(r)try{let e=`loopat:tree:expanded:`+n,t=localStorage.getItem(e),i=t?JSON.parse(t):[];for(let e=r;e;e=e.includes(`/`)?e.substring(0,e.lastIndexOf(`/`)):``)i.includes(e)||i.push(e);localStorage.setItem(e,JSON.stringify(i))}catch{}}(0,F.useEffect)(()=>{Hh(e).then(e=>{i(e),c(t=>{if(t)return t;let n=e.find(e=>e.type===`file`&&e.path.endsWith(`.md`));return n?n.path:null})}),Uh(e).then(o),g(``)},[e,d]),(0,F.useEffect)(()=>{let t=!1,n=()=>{t||f(e=>e+1)};return e===`knowledge`?ag(`knowledge`).then(e=>{e.ok&&(e.message??``).toLowerCase()!==`already up to date`&&n()}):e===`notes`?qh().then(e=>{e>0&&Jh().then(e=>{e.ok&&n()})}):e===`personal`&&Dh().then(e=>{e.ok&&(e.files?.length??0)>0&&n()}),()=>{t=!0}},[e]);let T=async t=>{let n=await Yh(e,t);n.ok?(m(!1),f(e=>e+1),c(t)):alert(`failed: ${n.error}`)},E=async()=>{if(!y||!x.trim()){b(null);return}let t=y.path+`/`+x.trim();if(y.type===`file`){let n=await Yh(e,t);if(!n.ok){alert(`create failed: ${n.error}`);return}}else{let n=await Xh(e,t);if(!n.ok){alert(`create failed: ${n.error}`);return}}b(null),S(``),f(e=>e+1)},D=(0,F.useCallback)((t,n)=>{if(t===`view`)c(n.path);else if(t===`new-file`||t===`new-folder`)b({type:t===`new-file`?`file`:`folder`,path:n.path}),S(``);else if(t===`delete`){if(!confirm(`Delete "${n.name}"?`))return;Zh(e,n.path).then(e=>{e.ok?(c(e=>e===n.path?null:e),f(e=>e+1)):alert(`delete failed: ${e.error}`)})}},[e]),O=(0,F.useCallback)(t=>R8(e,t.path)?[]:t.type===`dir`?[{label:`New file`,icon:(0,L.jsx)(Lt,{size:12}),action:`new-file`},{label:`New folder`,icon:(0,L.jsx)(Ut,{size:12}),action:`new-folder`},{label:`Delete`,icon:(0,L.jsx)(Bn,{size:12}),action:`delete`,danger:!0}]:z8(e,t.path)?[]:[{label:`View`,icon:(0,L.jsx)(Nt,{size:12}),action:`view`},{label:`Delete`,icon:(0,L.jsx)(Bn,{size:12}),action:`delete`,danger:!0}],[e]),k=(0,F.useCallback)(t=>Hh(e,t).then(e=>e),[e]),A=(0,F.useCallback)((t,n,r,i)=>{if(t.type===`dir`)return R8(e,t.path)?`w-full py-1.5 flex items-center gap-1.5 bg-amber-50/40 hover:bg-amber-50 text-left border-y border-amber-200/60 mt-1`:`w-full py-1 flex items-center gap-1 hover:bg-gray-50 text-left`;let a=z8(e,t.path);return`w-full py-1 flex items-center gap-2 text-left `+(i?`bg-gray-100`:a?`hover:bg-amber-50/50`:`hover:bg-gray-50`)},[e]),ee=h.trim().toLowerCase(),j=ee.length>0,te=j?a.filter(e=>e.path.toLowerCase().includes(ee)).slice(0,60):[],M=(0,L.jsxs)(`aside`,{className:`w-64 shrink-0 border-r border-gray-200 bg-white flex flex-col h-full`,children:[(0,L.jsxs)(`div`,{className:`px-3 h-9 flex items-center gap-1 border-b border-gray-200`,children:[C&&(0,L.jsx)(`button`,{onClick:()=>v(!1),className:`text-gray-500 hover:text-gray-900 px-1 rounded hover:bg-gray-100 mr-1`,title:`close sidebar`,children:(0,L.jsx)(gn,{size:14})}),(0,L.jsx)(Uie,{}),(0,L.jsx)(`input`,{type:`text`,value:h,onChange:e=>g(e.target.value),placeholder:`search files…`,className:`flex-1 min-w-0 bg-transparent outline-none text-[12px] text-gray-700 placeholder:text-gray-400`}),(0,L.jsx)(`button`,{onClick:()=>m(!0),className:`text-gray-500 hover:text-gray-900 px-1.5 rounded hover:bg-gray-100 text-xs`,title:`new file`,children:`+`}),(0,L.jsx)(`button`,{onClick:()=>f(e=>e+1),className:`text-gray-500 hover:text-gray-900 px-1.5 rounded hover:bg-gray-100 text-xs`,title:`refresh`,children:`↻`})]}),(0,L.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto py-2`,children:j?te.length===0?(0,L.jsx)(`div`,{className:`px-3 py-4 text-[12px] text-gray-400 italic`,children:`no matches`}):te.map(e=>(0,L.jsxs)(`button`,{type:`button`,onClick:()=>{c(e.path),C&&v(!1)},className:`w-full px-3 py-1.5 flex items-center gap-2 text-left `+(s===e.path?`bg-gray-100`:`hover:bg-gray-50`),title:e.path,children:[(0,L.jsx)(`span`,{className:`text-gray-500`,children:`📄`}),(0,L.jsx)(`span`,{className:`flex-1 min-w-0 truncate text-[13px] text-gray-900`,children:e.path})]},e.path)):(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(E8,{treeId:`vault-${e}`,entries:r,onPick:e=>{c(e),C&&v(!1)},picked:s,onLoadChildren:k,getContextActions:O,onAction:D,nodeClassName:A,reloadKey:d}),r.length===0&&(0,L.jsx)(`div`,{className:`px-3 py-4 text-[12px] text-gray-400 italic`,children:`empty · click + 创建第一个文件`})]})}),(0,L.jsx)(`div`,{className:`px-3 h-9 border-t border-gray-200 flex items-center text-[11px] text-gray-500`,children:zie[e]}),e===`knowledge`&&(0,L.jsx)(Bie,{resource:e}),e===`notes`&&(0,L.jsx)(Vie,{onRefreshed:()=>f(e=>e+1)})]});return(0,L.jsxs)(`div`,{className:`flex h-full w-full`,children:[C?(0,L.jsx)(L.Fragment,{children:_?(0,L.jsxs)(`div`,{className:`fixed inset-0 z-30`,onClick:()=>v(!1),children:[(0,L.jsx)(`div`,{className:`absolute inset-0 bg-black/30`}),(0,L.jsx)(`div`,{className:`absolute left-0 top-0 bottom-0 w-64 max-w-[80vw] shadow-xl`,onClick:e=>e.stopPropagation(),children:M})]}):(0,L.jsx)(`aside`,{className:`w-9 shrink-0 border-r border-gray-200 bg-white flex flex-col items-center pt-2`,children:(0,L.jsx)(`button`,{type:`button`,onClick:()=>v(!0),className:`w-7 h-7 flex items-center justify-center text-gray-500 hover:text-gray-900 hover:bg-gray-100 rounded`,title:`open file tree`,children:(0,L.jsx)(_n,{size:16})})})}):M,(0,L.jsx)(`main`,{className:`flex-1 min-w-0 flex flex-col bg-white min-h-0`,children:s?(0,L.jsx)(Kie,{vault:e,path:s,onSelect:c,onSaved:()=>f(e=>e+1),initialEditing:n}):(0,L.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-[13px] text-gray-400 italic`,children:`选一个文件,或点 + 新建`})}),p&&(0,L.jsx)(qie,{vault:e,onClose:()=>m(!1),onCreate:T}),y&&(0,L.jsx)(Wie,{type:y.type,parentPath:y.path,value:x,onChange:S,onSubmit:E,onCancel:()=>b(null)})]})}function Uie(){return(0,L.jsx)(`svg`,{viewBox:`0 0 16 16`,width:`14`,height:`14`,className:`text-gray-400 shrink-0`,children:(0,L.jsx)(`path`,{fill:`none`,stroke:`currentColor`,strokeWidth:`1.4`,strokeLinecap:`round`,d:`M11 11l3 3M7 12.5a5.5 5.5 0 1 1 0-11 5.5 5.5 0 0 1 0 11z`})})}function R8(e,t){return e!==`personal`||!t.startsWith(`.loopat/vaults/`)?!1:t.slice(15).length>0}function z8(e,t){return e!==`personal`||!t.startsWith(`.loopat/vaults/`)?!1:t.slice(15).includes(`/`)}function Wie({type:e,parentPath:t,value:n,onChange:r,onSubmit:i,onCancel:a}){return(0,L.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/30 flex items-center justify-center`,onClick:a,children:(0,L.jsxs)(`div`,{className:`w-full max-w-[420px] mx-4 bg-white rounded-md shadow-xl border border-gray-200 p-4 md:p-5`,onClick:e=>e.stopPropagation(),children:[(0,L.jsxs)(`div`,{className:`text-base font-semibold text-gray-900 mb-3`,children:[e===`file`?`New file`:`New folder`,` in `,(0,L.jsx)(`span`,{className:`font-mono text-[13px]`,children:t||`root`})]}),(0,L.jsx)(`input`,{autoFocus:!0,type:`text`,value:n,onChange:e=>r(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&i(),e.key===`Escape`&&a()},placeholder:e===`file`?`filename.md`:`folder-name`,className:`w-full px-3 py-2 text-sm border border-gray-300 rounded outline-none focus:border-gray-500 font-mono`}),(0,L.jsxs)(`div`,{className:`flex justify-end gap-2 mt-4`,children:[(0,L.jsx)(`button`,{onClick:a,className:`px-3 h-8 text-sm rounded text-gray-700 hover:bg-gray-100`,children:`cancel`}),(0,L.jsx)(`button`,{onClick:()=>n.trim()&&i(),disabled:!n.trim(),className:`px-3 h-8 text-sm rounded bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-50`,children:`create`})]})]})})}function Gie(e){return/(^|\/)secrets\//.test(e)||e===`secrets`}function Kie({vault:e,path:t,onSelect:n,onSaved:r,initialEditing:i}){let a=D_(),o=_i(),[s,c]=(0,F.useState)(``),[l,u]=(0,F.useState)(``),[d,f]=(0,F.useState)(i??!1),[p,m]=(0,F.useState)(!1),[h,g]=(0,F.useState)([]),[_,v]=(0,F.useState)(null),[y,b]=(0,F.useState)(!1),[x,S]=(0,F.useState)(!1),[C,w]=(0,F.useState)(!1),[T,E]=(0,F.useState)(!1),D=f6(),O=(0,F.useRef)(i);(0,F.useEffect)(()=>{O.current?O.current=!1:f(!1),S(!1),v(null),w(!1),E(!1),Wh(e,t).then(e=>{let t=e?.content??``;c(t),u(t),E(!!e?.secret)}),Qh(e,t).then(g)},[e,t]);let k=Gie(t)||T,A=t.endsWith(`.md`),ee=e!==`knowledge`,j=!k,te=e===`notes`&&!k,M=k?l.length>0:l!==s,ne=(0,F.useCallback)(async()=>{if(!(!M||p)){m(!0);try{let n=await Gh(e,t,l);if(n.ok){if(k?(c(``),u(``)):c(l),v(n.commit??null),f(!1),r(),Qh(e,t).then(g),e===`notes`){let e=await Kh();e.ok||(e.conflict?alert(`Saved locally, but it conflicts with the remote (${(e.files??[]).join(`, `)}). Your edit is kept — resolve by taking the remote, or in a loop.`):alert(`Saved locally, but push to remote failed: ${e.error??`unknown`}`))}else if(e===`personal`){let e=await Oh();e.ok||(e.conflict?alert(`Saved locally, but it conflicts with the remote (${(e.files??[]).join(`, `)}). Your edit is kept — pull first (re-open Personal) or resolve in a loop.`):alert(`Saved locally, but push to remote failed: ${e.error??`unknown`}`))}}else alert(`save failed: ${n.error}`)}finally{m(!1)}}},[e,t,l,M,p,r,k]),N=()=>{f(!0),A&&S(!0)},re=()=>{u(s),f(!1)},ie=async()=>{o(`/loop/${(await a.createLoop({title:`edit ${e}/${t}`})).id}`)},ae=async()=>{o(`/loop/${(await a.createLoop({title:`distill ${t} → knowledge`,knowledgeRw:!0})).id}`)},oe=e=>{n([t.replace(/[^/]+$/,``)+e+`.md`,e+`.md`,e][0].replace(/^\//,``))};return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`header`,{className:`px-3 md:px-5 h-10 shrink-0 border-b border-gray-200 flex items-center justify-between`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2 text-[13px] min-w-0`,children:[(0,L.jsx)(`span`,{className:`text-gray-500 shrink-0`,children:k?`🔒`:`📄`}),(0,L.jsx)(`span`,{className:`font-mono text-[12px] text-gray-500 truncate`,children:t}),_&&!M&&!d&&(0,L.jsxs)(`span`,{className:`hidden md:inline text-[10px] text-emerald-700 font-mono`,children:[`commit `,_]})]}),(0,L.jsx)(`div`,{className:`flex items-center gap-1 md:gap-2 text-xs text-gray-500`,children:d?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`button`,{onClick:re,className:`px-2.5 h-7 rounded text-xs text-gray-600 hover:bg-gray-100`,children:`cancel`}),(0,L.jsx)(`button`,{onClick:ne,disabled:!M||p,className:`px-2.5 h-7 rounded text-xs bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-50`,children:p?`saving…`:`save`})]}):(0,L.jsxs)(L.Fragment,{children:[te&&(0,L.jsxs)(`button`,{onClick:ae,className:`px-2.5 h-7 rounded text-xs bg-amber-100 text-amber-900 hover:bg-amber-200 flex items-center gap-1`,title:`open a loop to distill this notes file into knowledge`,children:[(0,L.jsx)(`span`,{children:`↑`}),(0,L.jsx)(`span`,{children:`distill`})]}),j&&(0,L.jsxs)(`button`,{onClick:ie,className:te?`px-2.5 h-7 rounded text-xs border border-gray-200 hover:bg-gray-100 text-gray-900 flex items-center gap-1`:`px-2.5 h-7 rounded text-xs bg-gray-900 text-white hover:bg-gray-700 flex items-center gap-1`,title:`open a new loop with AI assist for this file`,children:[(0,L.jsx)(`span`,{children:`↻`}),(0,L.jsx)(`span`,{children:`edit by loop`})]}),ee&&(0,L.jsx)(`button`,{onClick:N,className:`px-2.5 h-7 rounded text-xs border border-gray-200 hover:bg-gray-100 text-gray-900`,title:`direct edit (fastpath)`,children:`edit`}),D&&A&&(0,L.jsxs)(`button`,{onClick:()=>b(e=>!e),className:`px-2.5 h-7 rounded text-xs border ${y?`bg-gray-900 text-white`:`border-gray-200 hover:bg-gray-100 text-gray-900`}`,title:`toggle backlinks`,children:[`⇄ `,h.length]})]})})]}),d?k?(0,L.jsxs)(`div`,{className:C?`fixed inset-0 z-50 bg-white flex flex-col`:`flex-1 min-h-0 min-w-0 flex flex-col`,children:[(0,L.jsxs)(`div`,{className:`px-3 h-7 shrink-0 border-b border-gray-200 flex items-center gap-2 text-[11px] text-gray-500`,children:[(0,L.jsx)(`span`,{className:`text-amber-700`,children:`🔒`}),(0,L.jsx)(`span`,{children:`new value · saved encrypted`}),(0,L.jsx)(`div`,{className:`flex-1`}),(0,L.jsx)(`button`,{onClick:()=>w(!C),className:`text-gray-400 hover:text-gray-700 px-1 rounded hover:bg-gray-100`,title:C?`restore`:`maximize`,children:C?(0,L.jsx)(dn,{size:13}):(0,L.jsx)(cn,{size:13})})]}),(0,L.jsx)(`div`,{className:`flex-1 min-h-0 relative`,children:(0,L.jsx)(F.Suspense,{fallback:(0,L.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-gray-400 text-sm`,children:`Loading editor...`}),children:(0,L.jsx)(I8,{path:t,value:l,onChange:u})})})]}):A&&!x?(0,L.jsxs)(`div`,{className:C?`fixed inset-0 z-50 bg-white flex flex-col md:flex-row`:`flex-1 min-h-0 min-w-0 flex flex-col md:flex-row`,children:[(0,L.jsxs)(`div`,{className:`flex-1 min-w-0 min-h-0 border-r border-gray-200 flex flex-col`,children:[(0,L.jsxs)(`div`,{className:`px-3 h-7 shrink-0 border-b border-gray-200 flex items-center gap-2 text-[11px] text-gray-500`,children:[(0,L.jsx)(`span`,{children:`source · markdown`}),(0,L.jsx)(`button`,{type:`button`,onClick:()=>S(!0),className:`px-2 h-5 rounded text-[10px] bg-gray-100 hover:bg-gray-200 text-gray-600`,title:`Switch to WYSIWYG editor`,children:`wysiwyg`}),(0,L.jsx)(`div`,{className:`flex-1`}),(0,L.jsx)(`button`,{onClick:()=>w(!C),className:`text-gray-400 hover:text-gray-700 px-1 rounded hover:bg-gray-100`,title:C?`restore`:`maximize`,children:C?(0,L.jsx)(dn,{size:13}):(0,L.jsx)(cn,{size:13})})]}),(0,L.jsx)(`div`,{className:`flex-1 min-h-0 relative`,children:(0,L.jsx)(F.Suspense,{fallback:(0,L.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-gray-400 text-sm`,children:`Loading editor...`}),children:(0,L.jsx)(I8,{path:t,value:l,onChange:u})})})]}),(0,L.jsxs)(`div`,{className:`flex-1 min-w-0 min-h-0 flex flex-col`,children:[(0,L.jsx)(`div`,{className:`px-3 h-7 shrink-0 border-b border-gray-200 flex items-center text-[11px] text-gray-500`,children:`preview`}),(0,L.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto px-6 py-4`,children:(0,L.jsx)(`div`,{className:`max-w-[760px]`,children:(0,L.jsx)(F.Suspense,{fallback:(0,L.jsx)(`div`,{className:`text-gray-400 text-sm`,children:`Loading preview...`}),children:(0,L.jsx)(L8,{text:l,onWikilink:oe})})})})]})]}):A?(0,L.jsxs)(`div`,{className:C?`fixed inset-0 z-50 bg-white flex flex-col`:`flex-1 min-h-0 min-w-0 flex flex-col`,children:[(0,L.jsxs)(`div`,{className:`px-3 h-7 shrink-0 border-b border-gray-200 flex items-center gap-2 text-[11px] text-gray-500`,children:[(0,L.jsx)(`span`,{children:`wysiwyg · milkdown`}),(0,L.jsx)(`button`,{type:`button`,onClick:()=>S(!1),className:`px-2 h-5 rounded text-[10px] bg-gray-100 hover:bg-gray-200 text-gray-600`,title:`Switch to source editor`,children:`source`}),(0,L.jsx)(`div`,{className:`flex-1`}),(0,L.jsx)(`button`,{onClick:()=>w(!C),className:`text-gray-400 hover:text-gray-700 px-1 rounded hover:bg-gray-100`,title:C?`restore`:`maximize`,children:C?(0,L.jsx)(dn,{size:13}):(0,L.jsx)(cn,{size:13})})]}),(0,L.jsx)(`div`,{className:`flex-1 min-h-0 relative`,children:(0,L.jsx)(F.Suspense,{fallback:(0,L.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-gray-400 text-sm`,children:`Loading editor...`}),children:(0,L.jsx)(Fie,{value:l,onChange:u})})})]}):(0,L.jsxs)(`div`,{className:C?`fixed inset-0 z-50 bg-white flex flex-col`:`flex-1 min-h-0 min-w-0 flex flex-col`,children:[(0,L.jsxs)(`div`,{className:`px-3 h-7 shrink-0 border-b border-gray-200 flex items-center gap-2 text-[11px] text-gray-500`,children:[(0,L.jsxs)(`span`,{children:[`source · `,t.includes(`.`)?t.split(`.`).pop():`text`]}),t.endsWith(`.json`)&&(0,L.jsx)(`button`,{type:`button`,onClick:()=>{try{u(JSON.stringify(JSON.parse(l),null,2))}catch(e){alert(`Invalid JSON: `+(e?.message??`parse error`))}},className:`px-2 h-5 rounded text-[10px] bg-gray-100 hover:bg-gray-200 text-gray-600`,title:`Format JSON`,children:`format`}),(0,L.jsx)(`div`,{className:`flex-1`}),(0,L.jsx)(`button`,{onClick:()=>w(!C),className:`text-gray-400 hover:text-gray-700 px-1 rounded hover:bg-gray-100`,title:C?`restore`:`maximize`,children:C?(0,L.jsx)(dn,{size:13}):(0,L.jsx)(cn,{size:13})})]}),(0,L.jsx)(`div`,{className:`flex-1 min-h-0 relative`,children:(0,L.jsx)(F.Suspense,{fallback:(0,L.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-gray-400 text-sm`,children:`Loading editor...`}),children:(0,L.jsx)(I8,{path:t,value:l,onChange:u})})})]}):(0,L.jsxs)(`div`,{className:`flex flex-1 min-h-0 min-w-0 overflow-hidden`,children:[(0,L.jsx)(`article`,{className:`flex-1 min-h-0 overflow-auto px-4 md:px-8 py-4 md:py-6`,children:(0,L.jsx)(`div`,{className:`max-w-[760px]`,children:k?(0,L.jsxs)(`div`,{className:`font-sans text-[13px] text-gray-600 leading-relaxed`,children:[(0,L.jsx)(`div`,{className:`inline-flex items-center gap-1.5 px-2 py-1 rounded bg-amber-50 border border-amber-200 text-amber-800 text-[12px] font-medium`,children:`encrypted · value hidden by design`}),(0,L.jsxs)(`div`,{className:`mt-3 text-[12px] text-gray-500`,children:[`Click `,(0,L.jsx)(`b`,{children:`edit`}),` to overwrite. The current value is never returned by the server, so editing means typing a new replacement — there is no decrypt-and-view.`]})]}):A?(0,L.jsx)(F.Suspense,{fallback:(0,L.jsx)(`div`,{className:`text-gray-400 text-sm`,children:`Loading...`}),children:(0,L.jsx)(L8,{text:s,onWikilink:oe})}):(0,L.jsx)(`pre`,{className:`font-mono text-[12.5px] leading-relaxed whitespace-pre-wrap text-gray-900`,children:s||(0,L.jsx)(`span`,{className:`text-gray-400 italic`,children:`(empty)`})})})}),A&&!D&&(0,L.jsxs)(`aside`,{className:`w-64 shrink-0 border-l border-gray-200 bg-gray-50 overflow-auto`,children:[(0,L.jsxs)(`div`,{className:`px-3 h-9 flex items-center border-b border-gray-200`,children:[(0,L.jsx)(`span`,{className:`text-[11px] text-gray-500`,children:`Backlinks`}),(0,L.jsx)(`span`,{className:`ml-auto text-[11px] text-gray-500`,children:h.length})]}),h.length===0?(0,L.jsx)(`div`,{className:`px-3 py-4 text-xs text-gray-500`,children:`No documents link here yet.`}):(0,L.jsx)(`ul`,{className:`py-2`,children:h.map(e=>(0,L.jsx)(`li`,{children:(0,L.jsxs)(`button`,{type:`button`,onClick:()=>n(e.path),className:`w-full px-3 py-2 text-left hover:bg-gray-100`,children:[(0,L.jsx)(`div`,{className:`text-xs font-medium text-gray-900 truncate`,children:e.path}),(0,L.jsx)(`div`,{className:`text-[11px] text-gray-500 mt-0.5 leading-snug line-clamp-2`,children:e.preview})]})},e.path))})]}),D&&A&&y&&(0,L.jsxs)(`div`,{className:`fixed inset-0 z-30`,onClick:()=>b(!1),children:[(0,L.jsx)(`div`,{className:`absolute inset-0 bg-black/30`}),(0,L.jsxs)(`div`,{className:`absolute right-0 top-0 bottom-0 w-64 max-w-[80vw] bg-gray-50 border-l border-gray-200 shadow-xl overflow-auto`,onClick:e=>e.stopPropagation(),children:[(0,L.jsxs)(`div`,{className:`px-3 h-9 flex items-center border-b border-gray-200`,children:[(0,L.jsx)(`span`,{className:`text-[11px] text-gray-500`,children:`Backlinks`}),(0,L.jsx)(`span`,{className:`ml-auto text-[11px] text-gray-500`,children:h.length}),(0,L.jsx)(`button`,{onClick:()=>b(!1),className:`ml-2 text-gray-400 hover:text-gray-700 px-1`,title:`close backlinks`,children:`✕`})]}),h.length===0?(0,L.jsx)(`div`,{className:`px-3 py-4 text-xs text-gray-500`,children:`No documents link here yet.`}):(0,L.jsx)(`ul`,{className:`py-2`,children:h.map(e=>(0,L.jsx)(`li`,{children:(0,L.jsxs)(`button`,{type:`button`,onClick:()=>{n(e.path),b(!1)},className:`w-full px-3 py-2 text-left hover:bg-gray-100`,children:[(0,L.jsx)(`div`,{className:`text-xs font-medium text-gray-900 truncate`,children:e.path}),(0,L.jsx)(`div`,{className:`text-[11px] text-gray-500 mt-0.5 leading-snug line-clamp-2`,children:e.preview})]})},e.path))})]})]})]})]})}function qie({vault:e,onClose:t,onCreate:n}){let[r,i]=(0,F.useState)(``);return(0,L.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/30 flex items-center justify-center`,onClick:t,children:(0,L.jsxs)(`div`,{className:`w-full max-w-[420px] mx-4 bg-white rounded-md shadow-xl border border-gray-200 p-4 md:p-5`,onClick:e=>e.stopPropagation(),children:[(0,L.jsxs)(`div`,{className:`text-base font-semibold text-gray-900 mb-3`,children:[`new file in `,e,`/`]}),(0,L.jsx)(`input`,{autoFocus:!0,type:`text`,value:r,onChange:e=>i(e.target.value),placeholder:`loopat/new-doc.md`,className:`w-full px-3 py-2 text-sm border border-gray-300 rounded outline-none focus:border-gray-500 font-mono`}),(0,L.jsx)(`div`,{className:`text-[11px] text-gray-400 mt-1`,children:`relative path. directories created as needed.`}),(0,L.jsxs)(`div`,{className:`flex justify-end gap-2 mt-4`,children:[(0,L.jsx)(`button`,{onClick:t,className:`px-3 h-8 text-sm rounded text-gray-700 hover:bg-gray-100`,children:`cancel`}),(0,L.jsx)(`button`,{onClick:()=>r.trim()&&n(r.trim()),disabled:!r.trim(),className:`px-3 h-8 text-sm rounded bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-50`,children:`create`})]})]})})}function Jie(){let[e,t]=(0,F.useState)(null),[n,r]=(0,F.useState)([]),[i,a]=(0,F.useState)(!1),[o,s]=(0,F.useState)(null),c=(0,F.useCallback)(async()=>{let e=await $h();t(e),r(e.repos)},[]);(0,F.useEffect)(()=>{c()},[c]);let l=e!==null&&JSON.stringify(n)!==JSON.stringify(e.repos),u=()=>r(e=>[...e,{name:``,git:``}]),d=(e,t,n)=>r(r=>r.map((r,i)=>i===e?{...r,[t]:n}:r)),f=e=>r(t=>t.filter((t,n)=>n!==e));return e?(0,L.jsx)(`article`,{className:`flex-1 min-w-0 overflow-auto p-5`,children:(0,L.jsxs)(`div`,{className:`max-w-2xl flex flex-col gap-5`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`h2`,{className:`text-sm font-semibold text-gray-900`,children:`Repo roster`}),(0,L.jsxs)(`p`,{className:`text-[12px] text-gray-500 leading-relaxed mt-1`,children:[`Personal — saved straight to your own`,` `,(0,L.jsx)(`code`,{className:`bg-gray-100 px-1 rounded text-[11px]`,children:`.loopat/config.json`}),`. Repos are cloned on demand when a loop selects one.`]})]}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,L.jsx)(`span`,{className:`text-[12px] font-medium text-gray-700`,children:`repos`}),n.length===0&&(0,L.jsx)(`div`,{className:`text-[12px] text-gray-400`,children:`No repos yet.`}),n.map((e,t)=>(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(`input`,{value:e.name,onChange:e=>d(t,`name`,e.target.value),placeholder:`name`,className:`w-40 px-2 py-1.5 text-sm border border-gray-300 rounded outline-none focus:border-gray-500`}),(0,L.jsx)(`input`,{value:e.git,onChange:e=>d(t,`git`,e.target.value),placeholder:`git@…/repo.git`,className:`flex-1 px-2 py-1.5 text-sm font-mono border border-gray-300 rounded outline-none focus:border-gray-500`}),(0,L.jsx)(`button`,{type:`button`,onClick:()=>f(t),className:`px-2 py-1.5 text-gray-400 hover:text-red-600`,title:`remove`,children:`✕`})]},t)),(0,L.jsx)(`button`,{type:`button`,onClick:u,className:`self-start text-[12px] text-gray-600 hover:text-gray-900 border border-gray-200 rounded px-2 py-1`,children:`+ add repo`})]}),o&&(0,L.jsx)(`div`,{className:`text-[12px] rounded px-2 py-1.5 border ${o.ok?`text-emerald-700 bg-emerald-50 border-emerald-200`:`text-red-700 bg-red-50 border-red-200`}`,children:o.text}),(0,L.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,L.jsx)(`button`,{type:`button`,onClick:async()=>{a(!0),s(null);let e=await eg({repos:n.map(e=>({name:e.name.trim(),git:e.git.trim()})).filter(e=>e.name&&e.git)});a(!1),e.ok?(s({ok:!0,text:`Saved.`}),await c()):s({ok:!1,text:`Save failed: `+(e.error??``)})},disabled:!l||i,className:`px-3 h-9 text-sm rounded bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-40`,children:i?`Saving…`:`Save`}),l&&(0,L.jsx)(`span`,{className:`text-[11px] text-amber-600`,children:`unsaved changes`})]})]})}):(0,L.jsx)(`div`,{className:`p-6 text-sm text-gray-400`,children:`loading…`})}function Yie(){var e=[...arguments];return(0,F.useMemo)(()=>t=>{e.forEach(e=>e(t))},e)}var B8=typeof window<`u`&&window.document!==void 0&&window.document.createElement!==void 0;function V8(e){let t=Object.prototype.toString.call(e);return t===`[object Window]`||t===`[object global]`}function H8(e){return`nodeType`in e}function U8(e){return e?V8(e)?e:H8(e)?e.ownerDocument?.defaultView??window:window:window}function W8(e){let{Document:t}=U8(e);return e instanceof t}function G8(e){return V8(e)?!1:e instanceof U8(e).HTMLElement}function K8(e){return e instanceof U8(e).SVGElement}function q8(e){return e?V8(e)?e.document:H8(e)?W8(e)?e:G8(e)||K8(e)?e.ownerDocument:document:document:document}var J8=B8?F.useLayoutEffect:F.useEffect;function Y8(e){let t=(0,F.useRef)(e);return J8(()=>{t.current=e}),(0,F.useCallback)(function(){var e=[...arguments];return t.current==null?void 0:t.current(...e)},[])}function Xie(){let e=(0,F.useRef)(null);return[(0,F.useCallback)((t,n)=>{e.current=setInterval(t,n)},[]),(0,F.useCallback)(()=>{e.current!==null&&(clearInterval(e.current),e.current=null)},[])]}function X8(e,t){t===void 0&&(t=[e]);let n=(0,F.useRef)(e);return J8(()=>{n.current!==e&&(n.current=e)},t),n}function Z8(e,t){let n=(0,F.useRef)();return(0,F.useMemo)(()=>{let t=e(n.current);return n.current=t,t},[...t])}function Q8(e){let t=Y8(e),n=(0,F.useRef)(null);return[n,(0,F.useCallback)(e=>{e!==n.current&&t?.(e,n.current),n.current=e},[])]}function $8(e){let t=(0,F.useRef)();return(0,F.useEffect)(()=>{t.current=e},[e]),t.current}var e5={};function t5(e,t){return(0,F.useMemo)(()=>{if(t)return t;let n=e5[e]==null?0:e5[e]+1;return e5[e]=n,e+`-`+n},[e,t])}function n5(e){return function(t){return[...arguments].slice(1).reduce((t,n)=>{let r=Object.entries(n);for(let[n,i]of r){let r=t[n];r!=null&&(t[n]=r+e*i)}return t},{...t})}}var r5=n5(1),i5=n5(-1);function Zie(e){return`clientX`in e&&`clientY`in e}function a5(e){if(!e)return!1;let{KeyboardEvent:t}=U8(e.target);return t&&e instanceof t}function Qie(e){if(!e)return!1;let{TouchEvent:t}=U8(e.target);return t&&e instanceof t}function o5(e){if(Qie(e)){if(e.touches&&e.touches.length){let{clientX:t,clientY:n}=e.touches[0];return{x:t,y:n}}else if(e.changedTouches&&e.changedTouches.length){let{clientX:t,clientY:n}=e.changedTouches[0];return{x:t,y:n}}}return Zie(e)?{x:e.clientX,y:e.clientY}:null}var s5=Object.freeze({Translate:{toString(e){if(!e)return;let{x:t,y:n}=e;return`translate3d(`+(t?Math.round(t):0)+`px, `+(n?Math.round(n):0)+`px, 0)`}},Scale:{toString(e){if(!e)return;let{scaleX:t,scaleY:n}=e;return`scaleX(`+t+`) scaleY(`+n+`)`}},Transform:{toString(e){if(e)return[s5.Translate.toString(e),s5.Scale.toString(e)].join(` `)}},Transition:{toString(e){let{property:t,duration:n,easing:r}=e;return t+` `+n+`ms `+r}}}),c5=`a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]`;function $ie(e){return e.matches(c5)?e:e.querySelector(c5)}var eae={display:`none`};function tae(e){let{id:t,value:n}=e;return F.createElement(`div`,{id:t,style:eae},n)}function nae(e){let{id:t,announcement:n,ariaLiveType:r=`assertive`}=e;return F.createElement(`div`,{id:t,style:{position:`fixed`,top:0,left:0,width:1,height:1,margin:-1,border:0,padding:0,overflow:`hidden`,clip:`rect(0 0 0 0)`,clipPath:`inset(100%)`,whiteSpace:`nowrap`},role:`status`,"aria-live":r,"aria-atomic":!0},n)}function rae(){let[e,t]=(0,F.useState)(``);return{announce:(0,F.useCallback)(e=>{e!=null&&t(e)},[]),announcement:e}}var l5=(0,F.createContext)(null);function iae(e){let t=(0,F.useContext)(l5);(0,F.useEffect)(()=>{if(!t)throw Error(`useDndMonitor must be used within a children of <DndContext>`);return t(e)},[e,t])}function aae(){let[e]=(0,F.useState)(()=>new Set),t=(0,F.useCallback)(t=>(e.add(t),()=>e.delete(t)),[e]);return[(0,F.useCallback)(t=>{let{type:n,event:r}=t;e.forEach(e=>e[n]?.call(e,r))},[e]),t]}var oae={draggable:`
398
398
  To pick up a draggable item, press the space bar.
399
399
  While dragging, use the arrow keys to move the item.
400
400
  Press space again to drop the item in its new position, or press escape to cancel.
@@ -449,4 +449,4 @@ claude mcp add name url -t http -H "Key: Value"`,className:`ip text-[12px] w-ful
449
449
  `}var _9={team:{icon:qt,borderClass:`border-l-violet-400`,badgeClass:`bg-violet-100 text-violet-700`,desc:`Workspace-wide, set by admin`},personal:{icon:Gn,borderClass:`border-l-emerald-400`,badgeClass:`bg-emerald-100 text-emerald-700`,desc:`Your personal overrides`},project:{icon:Vt,borderClass:`border-l-gray-300`,badgeClass:`bg-gray-100 text-gray-500`,desc:`SDK reads from workdir`},local:{icon:Ft,borderClass:`border-l-amber-300`,badgeClass:`bg-amber-100 text-amber-700`,desc:`Per-checkout .local.* overrides`}};function v9(e){return e.startsWith(`profile:`)?{icon:lt,borderClass:`border-l-blue-400`,badgeClass:`bg-blue-100 text-blue-700`,desc:`Opt-in role-based config`}:_9[e]??_9.team}function y9(e){return e===`team`?1:e.startsWith(`profile:`)?2:e===`personal`?3:e===`project`?4:e===`local`?5:99}function Xse(e){return e===`admin`?`bg-violet-100 text-violet-700`:e===`user`?`bg-gray-100 text-gray-600`:`bg-gray-100 text-gray-400`}function Zse(e){return e.id===`team`?{vault:`knowledge`,file:`.loopat/.claude/mise.toml`}:e.id.startsWith(`profile:`)?{vault:`knowledge`,file:`.loopat/profiles/${e.id.slice(8)}/.claude/mise.toml`}:e.id===`personal`?{vault:`personal`,file:`.loopat/.claude/mise.toml`}:null}var b9=`w-full px-2.5 py-1.5 border border-gray-300 rounded text-[12px] outline-none bg-white focus:border-gray-900 focus:ring-1 focus:ring-gray-900 transition-colors font-mono`,x9=`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono`;function S9(e){let t={};try{t=Wse(e)}catch{}let n={};if(t.tools&&typeof t.tools==`object`)for(let[e,r]of Object.entries(t.tools))e.startsWith(`_`)||(typeof r==`string`?n[e]={version:r}:r&&typeof r==`object`&&(n[e]={version:typeof r.version==`string`?r.version:String(r.version??``),backend:typeof r.backend==`string`?r.backend:void 0}));let r={},i=``,a=[];if(t.env&&typeof t.env==`object`)for(let[e,n]of Object.entries(t.env)){if(e===`_.file`&&typeof n==`string`){i=n;continue}if(e===`_.path`&&Array.isArray(n)){a=n.map(String);continue}typeof n==`string`?r[e]=n:Array.isArray(n)?r[e]=n.join(`:`):n!=null&&(r[e]=String(n))}let o={};if(t.tasks&&typeof t.tasks==`object`)for(let[e,n]of Object.entries(t.tasks)){if(!n||typeof n!=`object`)continue;let t=n?.run_windows;o[e]={description:typeof n.description==`string`?n.description:void 0,run:typeof n.run==`string`?n.run:void 0,dir:typeof n.dir==`string`?n.dir:void 0,depends:Array.isArray(n.depends)?n.depends.map(String):void 0,waitFor:Array.isArray(n.wait_for)?n.wait_for.map(String):void 0,sources:Array.isArray(n.sources)?n.sources.map(String):void 0,outputs:Array.isArray(n.outputs)?n.outputs.map(String):void 0,hide:typeof n.hide==`boolean`?n.hide:void 0,raw:typeof n.raw==`boolean`?n.raw:void 0,env:n.env&&typeof n.env==`object`?Object.fromEntries(Object.entries(n.env).map(([e,t])=>[e,String(t)])):void 0,runWindows:typeof t==`string`?t:void 0}}let s={};if(t.alias&&typeof t.alias==`object`){for(let[e,n]of Object.entries(t.alias))if(n&&typeof n==`object`){s[e]={};for(let[t,r]of Object.entries(n))s[e][t]=String(r)}}let c={};if(t.settings&&typeof t.settings==`object`)for(let[e,n]of Object.entries(t.settings))e.startsWith(`_`)||(c[e]=n);let l={};if(t.plugins&&typeof t.plugins==`object`)for(let[e,n]of Object.entries(t.plugins))l[e]=n&&typeof n==`object`&&typeof n.url==`string`?n.url:typeof n==`string`?n:``;let u={};if(t.hooks&&typeof t.hooks==`object`)for(let[e,n]of Object.entries(t.hooks))typeof n==`string`&&(u[e]=n);return{tools:n,env:r,envFile:i,envPath:a,tasks:o,alias:s,settings:c,plugins:l,hooks:u}}function Qse(e){let t={};if(Object.keys(e.tools).length>0){t.tools={};for(let[n,r]of Object.entries(e.tools))r.backend?t.tools[n]={version:r.version,backend:r.backend}:t.tools[n]=r.version}if((Object.keys(e.env).length>0||e.envFile||e.envPath.length>0)&&(t.env={},e.envFile&&(t.env[`_.file`]=e.envFile),e.envPath.length>0&&(t.env[`_.path`]=e.envPath),Object.assign(t.env,e.env)),Object.keys(e.tasks).length>0){t.tasks={};for(let[n,r]of Object.entries(e.tasks)){let e={};r.description&&(e.description=r.description),r.run&&(e.run=r.run),r.dir&&(e.dir=r.dir),r.depends&&r.depends.length>0&&(e.depends=r.depends),r.waitFor&&r.waitFor.length>0&&(e.wait_for=r.waitFor),r.sources&&r.sources.length>0&&(e.sources=r.sources),r.outputs&&r.outputs.length>0&&(e.outputs=r.outputs),r.hide!==void 0&&(e.hide=r.hide),r.raw!==void 0&&(e.raw=r.raw),r.env&&Object.keys(r.env).length>0&&(e.env=r.env),r.runWindows&&(e.run_windows=r.runWindows),t.tasks[n]=e}}if(Object.keys(e.alias).length>0&&(t.alias=e.alias),Object.keys(e.settings).length>0&&(t.settings=e.settings),Object.keys(e.plugins).length>0){t.plugins={};for(let[n,r]of Object.entries(e.plugins))t.plugins[n]={url:r}}return Object.keys(e.hooks).length>0&&(t.hooks=e.hooks),Object.keys(t).length===0?``:Yse(t)}var C9=[{id:`tools`,label:`Tools`,desc:`Tool versions (node, python, rust, …)`},{id:`env`,label:`Env`,desc:`Environment variables`},{id:`tasks`,label:`Tasks`,desc:`Build / run tasks`},{id:`alias`,label:`Alias`,desc:`Tool version aliases`},{id:`settings`,label:`Settings`,desc:`mise behavior flags`},{id:`plugins`,label:`Plugins`,desc:`asdf plugin sources`},{id:`hooks`,label:`Hooks`,desc:`Lifecycle hook commands`},{id:`raw`,label:`Raw TOML`,desc:`Direct TOML editing`}];function $se({disabled:e}){let t=D_().currentUser?.role===`admin`,[n,r]=(0,F.useState)(null),[i,a]=(0,F.useState)(!0),[o,s]=Ya(),c=o.get(`expand`)??`personal`,l=new Set(c.split(`,`).filter(Boolean)),u=e=>{let t=[...e].join(`,`);s(t?{expand:t}:{},{replace:!0})},[d,f]=(0,F.useState)(!1),p=(0,F.useCallback)(async()=>{a(!0),r(await f_()),a(!1)},[]);(0,F.useEffect)(()=>{p()},[p]);let m=e=>{let t=new Set(l);t.has(e)?t.delete(e):t.add(e),u(t)},h=n?.tiers??[],g=h.filter(e=>e.id.startsWith(`profile:`)),_=h.filter(e=>!e.id.startsWith(`profile:`)).sort((e,t)=>y9(e.id)-y9(t.id)),v=g.reduce((e,t)=>e+t.toolchainCount,0),y=[..._.filter(e=>y9(e.id)<3),...g.length>0?[{id:`__profiles__`,label:`Profiles (${g.length})`,tier:g[0],isGroup:!0}]:[],..._.filter(e=>y9(e.id)>=3)];return i&&!n?(0,L.jsxs)(`div`,{className:`flex items-center gap-2 py-12 justify-center text-[13px] text-gray-400`,children:[(0,L.jsx)(Sn,{size:13,className:`animate-spin`}),` loading tiers…`]}):(0,L.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,L.jsxs)(`div`,{className:`rounded-lg border border-gray-200 bg-white overflow-hidden transition-shadow hover:shadow-sm`,children:[(0,L.jsxs)(`div`,{className:`px-4 py-3 border-b border-gray-100 flex items-center gap-2.5`,children:[(0,L.jsx)(Rn,{size:15,className:`text-gray-400`}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`span`,{className:`text-[13px] font-medium text-gray-900`,children:`Mise Config`}),(0,L.jsx)(`span`,{className:`text-[11px] text-gray-400 ml-2`,children:`mise.toml per tier — tools, env, tasks, aliases, settings, plugins, hooks`})]}),(0,L.jsx)(`div`,{className:`flex-1`}),(0,L.jsxs)(`a`,{href:`https://mise.jdx.dev/configuration.html`,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1 px-2 py-1 rounded text-[10px] text-gray-400 hover:text-gray-600 hover:bg-gray-100 transition-colors`,children:[(0,L.jsx)(Mt,{size:10}),` docs`]}),(0,L.jsx)(`button`,{onClick:p,disabled:i,className:`p-1.5 rounded hover:bg-gray-100 text-gray-400 hover:text-gray-700 transition-colors`,children:(0,L.jsx)(Sn,{size:13,className:i?`animate-spin`:``})})]}),(0,L.jsx)(`div`,{className:`flex flex-wrap gap-px bg-gray-100`,children:y.map(e=>{if(`isGroup`in e)return(0,L.jsx)(ece,{profiles:g,expanded:l,toolSum:v,open:d,onToggle:()=>f(!d)},`__profiles__`);let t=e,n=v9(t.id).icon,r=l.has(t.id);return(0,L.jsxs)(`button`,{type:`button`,onClick:()=>m(t.id),className:`flex-1 min-w-[120px] flex items-center gap-2 px-3 py-2.5 bg-white hover:bg-gray-50 transition-colors text-left ${r?`bg-gray-50`:``}`,children:[(0,L.jsx)(n,{size:14,className:`shrink-0 ${t.exists?`text-gray-500`:`text-gray-300`}`}),(0,L.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,L.jsx)(`span`,{className:`text-[11px] font-medium truncate ${t.exists?`text-gray-700`:`text-gray-400`}`,children:t.label}),(0,L.jsx)(`div`,{className:`text-[10px] text-gray-400 mt-0.5`,children:t.toolchainCount>0?`${t.toolchainCount} tools`:t.exists?`0 tools`:`—`})]}),r?(0,L.jsx)(ht,{size:10,className:`text-gray-400 shrink-0`}):(0,L.jsx)(gt,{size:10,className:`text-gray-400 shrink-0`})]},t.id)})}),d&&g.length>0&&(0,L.jsxs)(`div`,{className:`border-t border-gray-200 bg-gray-50/50 px-4 py-2 space-y-0.5`,children:[(0,L.jsx)(`div`,{className:`text-[10px] font-semibold text-gray-400 uppercase tracking-wider px-1 mb-1`,children:`Select a profile to expand`}),g.map(e=>{let t=l.has(e.id);return(0,L.jsxs)(`button`,{type:`button`,onClick:()=>{m(e.id),f(!1),setTimeout(()=>{document.getElementById(`tier-${e.id}`)?.scrollIntoView({behavior:`smooth`,block:`start`})},50)},className:`w-full flex items-center gap-2 px-2 py-1.5 rounded hover:bg-white/80 text-left transition-colors`,children:[(0,L.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full shrink-0 ${t?`bg-blue-400`:`bg-gray-300`}`}),(0,L.jsx)(`span`,{className:`text-[12px] text-gray-700 flex-1`,children:e.label.replace(`Profile: `,``)}),(0,L.jsx)(`span`,{className:`text-[10px] text-gray-400 tabular-nums shrink-0`,children:e.toolchainCount>0?`${e.toolchainCount} tools`:`—`}),t&&(0,L.jsx)(ht,{size:9,className:`text-blue-400 shrink-0`})]},e.id)}),t&&(0,L.jsx)(tce,{onCreated:e=>{f(!1),p().then(()=>{let t=`profile:${e}`;m(t),setTimeout(()=>{document.getElementById(`tier-${t}`)?.scrollIntoView({behavior:`smooth`,block:`start`})},100)})}})]})]}),[..._,...g].map(n=>(0,L.jsx)(nce,{tier:n,isAdmin:!!t,isExpanded:l.has(n.id),disabled:e,onSaved:()=>p()},n.id))]})}function ece({profiles:e,expanded:t,toolSum:n,open:r,onToggle:i}){return(0,L.jsxs)(`button`,{type:`button`,onClick:i,className:`flex-1 min-w-[120px] flex items-center gap-2 px-3 py-2.5 bg-white hover:bg-gray-50 transition-colors text-left ${e.some(e=>t.has(e.id))||r?`bg-gray-50`:``}`,children:[(0,L.jsx)(lt,{size:14,className:`text-blue-400 shrink-0`}),(0,L.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,L.jsxs)(`span`,{className:`text-[11px] font-medium text-gray-700`,children:[`Profiles (`,e.length,`)`]}),(0,L.jsx)(`div`,{className:`text-[10px] text-gray-400 mt-0.5`,children:n>0?`${n} tools`:`—`})]}),r?(0,L.jsx)(ht,{size:10,className:`text-gray-400 shrink-0`}):(0,L.jsx)(gt,{size:10,className:`text-gray-400 shrink-0`})]})}function tce({onCreated:e}){let[t,n]=(0,F.useState)(!1),[r,i]=(0,F.useState)(``),[a,o]=(0,F.useState)(null),s=async()=>{let t=r.trim();if(!t)return;o(null);let a=await b_(t);if(!a.ok){o(a.error??`create failed`);return}i(``),n(!1),e(t)};return t?(0,L.jsxs)(`div`,{className:`px-3 py-1.5 space-y-1.5`,children:[(0,L.jsx)(`input`,{autoFocus:!0,value:r,onChange:e=>{i(e.target.value),o(null)},onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&s(),e.key===`Escape`&&(n(!1),i(``))},placeholder:`profile name`,className:b9}),a&&(0,L.jsx)(`div`,{className:`text-[11px] text-red-600`,children:a}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(`button`,{onClick:s,className:`px-3 h-7 rounded-lg bg-gray-900 text-white text-[11px] font-medium hover:bg-gray-800`,children:`Create`}),(0,L.jsx)(`button`,{onClick:()=>{n(!1),i(``),o(null)},className:`text-[11px] text-gray-400 hover:text-gray-600`,children:`Cancel`})]})]}):(0,L.jsxs)(`button`,{onClick:()=>n(!0),className:`flex items-center gap-1.5 px-3 py-1.5 text-[11px] text-gray-400 hover:text-gray-700 hover:bg-white/80 rounded w-full transition-colors`,children:[(0,L.jsx)(bn,{size:12}),` Create profile`]})}function nce({tier:e,isAdmin:t,isExpanded:n,disabled:r,onSaved:i}){if(!n)return null;let a=v9(e.id),o=a.icon,s=e.editable&&(e.managedBy===`user`||e.managedBy===`admin`&&t),c=e.managedBy===`sdk`,l=e.id.startsWith(`profile:`),u=l?e.id.slice(8):``,d=!s&&e.managedBy===`admin`&&!t?`Admin access required`:null,f=_i(),p=Zse(e),[m,h]=(0,F.useState)(``),[g,_]=(0,F.useState)({tools:{},env:{},envFile:``,envPath:[],tasks:{},alias:{},settings:{},plugins:{},hooks:{}}),[v,y]=(0,F.useState)(`tools`),[b,x]=(0,F.useState)(!1),[S,C]=(0,F.useState)(!1),[w,T]=(0,F.useState)(null),[E,D]=(0,F.useState)(!1);(0,F.useEffect)(()=>{n&&(async()=>{let t=await m_(e.id),n=t.exists?t.content:``;h(n),_(S9(n)),x(!0),T(null),D(!1)})()},[n,e.id]);let O=async()=>{C(!0),T(null);let t=v===`raw`?m:Qse(g),n=await h_(e.id,t);if(C(!1),!n.ok){T(n.error??`save failed`);return}v===`raw`?_(S9(m)):(h(t),_(S9(t))),D(!0),setTimeout(()=>D(!1),2500),i()},k=e=>{_(t=>({...t,...e})),D(!1)},A=()=>{_(S9(m)),D(!1)},ee=Object.keys(g.tools).length>0||Object.keys(g.env).length>0||g.envFile||g.envPath.length>0||Object.keys(g.tasks).length>0||Object.keys(g.alias).length>0||Object.keys(g.settings).length>0||Object.keys(g.plugins).length>0||Object.keys(g.hooks).length>0;return b?(0,L.jsxs)(`div`,{id:`tier-${e.id}`,className:`rounded-lg border overflow-hidden transition-shadow hover:shadow-sm ${s?`border-gray-200 bg-white`:`border-gray-200 bg-gray-50/50`}`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 border-b border-gray-100 border-l-2 ${a.borderClass}`,children:[(0,L.jsx)(o,{size:16,className:`text-gray-500 shrink-0`}),(0,L.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(`span`,{className:`text-[14px] font-semibold text-gray-900`,children:e.label}),(0,L.jsx)(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full font-medium ${Xse(e.managedBy)}`,children:e.managedBy===`admin`?`admin`:e.managedBy===`user`?`you`:`SDK`}),!e.exists&&!c&&(0,L.jsx)(`span`,{className:`text-[10px] text-amber-600 bg-amber-50 px-1.5 py-0.5 rounded-full`,children:`not created`}),d&&(0,L.jsx)(on,{size:11,className:`text-amber-500 shrink-0`})]}),(0,L.jsx)(`div`,{className:`text-[11px] text-gray-400 mt-0.5`,children:c?e.path:a.desc})]}),(0,L.jsxs)(`div`,{className:`hidden sm:flex items-center gap-1 shrink-0`,children:[Object.keys(g.tools).length>0&&(0,L.jsx)(w9,{label:`tools`,value:Object.keys(g.tools).length}),Object.keys(g.tasks).length>0&&(0,L.jsx)(w9,{label:`tasks`,value:Object.keys(g.tasks).length}),Object.keys(g.env).length>0&&(0,L.jsx)(w9,{label:`env`,value:Object.keys(g.env).length})]}),p&&(0,L.jsxs)(dh,{children:[(0,L.jsx)(fh,{asChild:!0,children:(0,L.jsx)(`button`,{onClick:()=>f(`/context/${p.vault}?file=${encodeURIComponent(p.file)}&edit=1`),className:`shrink-0 p-1.5 rounded-lg text-gray-300 hover:text-gray-600 hover:bg-gray-100 transition-colors`,children:(0,L.jsx)(Ft,{size:13})})}),(0,L.jsxs)(ph,{children:[`edit `,p.vault,`/`,p.file]})]})]}),(0,L.jsx)(`div`,{className:`px-4 py-4 space-y-4`,children:c?(0,L.jsxs)(`div`,{className:`rounded-lg bg-gray-50 px-3 py-2.5 text-[12px] text-gray-500`,children:[`SDK-managed — mise.toml is read from `,(0,L.jsxs)(`code`,{className:`bg-gray-100 px-1 rounded text-[11px]`,children:[e.path,`/mise.toml`]}),`. Not editable here.`]}):(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`div`,{className:`flex items-center gap-0.5 bg-gray-100 rounded-lg p-0.5 overflow-x-auto`,children:C9.map(e=>(0,L.jsx)(`button`,{onClick:()=>y(e.id),className:`px-3 py-1 rounded text-[11px] font-medium whitespace-nowrap transition-colors ${v===e.id?`bg-white text-gray-900 shadow-sm`:`text-gray-500 hover:text-gray-700`}`,children:e.label},e.id))}),(0,L.jsx)(`p`,{className:`text-[10px] text-gray-400 -mt-3`,children:C9.find(e=>e.id===v)?.desc}),v===`tools`&&(0,L.jsx)(rce,{tools:g.tools,readonly:!s||!!r,onChange:e=>k({tools:e})}),v===`env`&&(0,L.jsx)(ice,{env:g.env,envFile:g.envFile,envPath:g.envPath,readonly:!s||!!r,onChange:(e,t,n)=>k({env:e,envFile:t,envPath:n})}),v===`tasks`&&(0,L.jsx)(ace,{tasks:g.tasks,readonly:!s||!!r,onChange:e=>k({tasks:e})}),v===`alias`&&(0,L.jsx)(oce,{alias:g.alias,readonly:!s||!!r,onChange:e=>k({alias:e})}),v===`settings`&&(0,L.jsx)(sce,{settings:g.settings,readonly:!s||!!r,onChange:e=>k({settings:e})}),v===`plugins`&&(0,L.jsx)(lce,{plugins:g.plugins,readonly:!s||!!r,onChange:e=>k({plugins:e})}),v===`hooks`&&(0,L.jsx)(uce,{hooks:g.hooks,readonly:!s||!!r,onChange:e=>k({hooks:e})}),v===`raw`&&(0,L.jsx)(`div`,{className:`space-y-2`,children:(0,L.jsx)(`textarea`,{value:m,onChange:e=>{h(e.target.value),D(!1)},onBlur:A,readOnly:!s||r,spellCheck:!1,className:`w-full h-80 px-3 py-2 border border-gray-300 rounded text-[12px] font-mono outline-none bg-white focus:border-gray-900 resize-y disabled:bg-gray-50 disabled:text-gray-500`})}),d&&(0,L.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-amber-50 text-[12px] text-amber-700`,children:[(0,L.jsx)(on,{size:12}),` `,d]}),s&&(0,L.jsxs)(`div`,{className:`flex items-center gap-2 pt-3 border-t border-gray-100 ${l?`justify-between`:`justify-end`}`,children:[l&&t&&(0,L.jsx)(`button`,{onClick:async()=>{if(!confirm(`Delete profile "${u}"?`))return;let e=await x_(u);if(!e.ok){T(e.error??`delete failed`);return}i()},className:`px-3 h-7 rounded-lg text-[11px] text-red-500 hover:bg-red-50 hover:text-red-600 transition-colors`,children:`Delete profile`}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[!ee&&v!==`raw`&&!m&&(0,L.jsx)(`span`,{className:`text-[11px] text-gray-400 italic`,children:`empty — save will create the file`}),w&&(0,L.jsx)(`span`,{className:`text-[12px] text-red-600`,children:w}),E&&(0,L.jsxs)(`span`,{className:`text-[12px] text-emerald-600 flex items-center gap-1`,children:[(0,L.jsx)(mt,{size:13}),` saved`]}),(0,L.jsx)(`button`,{onClick:O,disabled:S||r,className:`px-4 h-8 rounded-lg bg-gray-900 text-white text-xs font-medium hover:bg-gray-800 disabled:opacity-50 transition-colors`,children:S?`Saving…`:`Save`})]})]})]})})]}):(0,L.jsx)(`div`,{id:`tier-${e.id}`,className:`rounded-lg border border-gray-200 bg-white p-4 text-[12px] text-gray-400 italic`,children:`loading mise.toml…`})}function w9({label:e,value:t}){return(0,L.jsxs)(`span`,{className:`text-[10px] text-gray-500 bg-gray-100 px-1.5 py-0.5 rounded-full font-medium tabular-nums`,children:[t,` `,(0,L.jsx)(`span`,{className:`text-gray-400`,children:e})]})}function rce({tools:e,readonly:t,onChange:n}){let r=Object.entries(e),[i,a]=(0,F.useState)(!1),[o,s]=(0,F.useState)(``),[c,l]=(0,F.useState)(``),[u,d]=(0,F.useState)(``),[f,p]=(0,F.useState)([]);(0,F.useEffect)(()=>{Ig().then(e=>p(e.miseToolPresets)).catch(()=>{})},[]);let m=t=>{n({...e,[t.name]:{version:t.suggestedVersion,backend:t.backend}})},h=()=>{let t=o.trim();t&&(n({...e,[t]:{version:c.trim()||`latest`,backend:u.trim()||void 0}}),s(``),l(``),d(``),a(!1))},g=t=>{let{[t]:r,...i}=e;n(i)},_=(t,r)=>{let i={...e[t],...r};i.backend===``&&(i.backend=void 0),n({...e,[t]:i})};return(0,L.jsxs)(`div`,{className:`space-y-3`,children:[r.length===0&&!i&&(0,L.jsx)(`div`,{className:`text-[12px] text-gray-400 italic py-3`,children:`No tools. Add one to get started.`}),r.length>0&&(0,L.jsx)(`div`,{className:`border border-gray-200 rounded-lg overflow-hidden`,children:(0,L.jsxs)(`table`,{className:`w-full text-[13px]`,children:[(0,L.jsx)(`thead`,{children:(0,L.jsxs)(`tr`,{className:`border-b border-gray-100 bg-gray-50/50 text-left text-[10px] text-gray-500 uppercase tracking-wider`,children:[(0,L.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:`Tool`}),(0,L.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:`Version`}),(0,L.jsx)(`th`,{className:`px-3 py-2 font-medium hidden sm:table-cell`,children:`Backend`}),!t&&(0,L.jsx)(`th`,{className:`px-3 py-2 font-medium w-10`})]})}),(0,L.jsx)(`tbody`,{children:r.map(([r,i])=>(0,L.jsxs)(`tr`,{className:`border-b border-gray-50 hover:bg-gray-50/50 transition-colors`,children:[(0,L.jsx)(`td`,{className:`px-3 py-2`,children:t?(0,L.jsx)(`code`,{className:`text-[12px] text-gray-800`,children:r}):(0,L.jsx)(`input`,{value:r,onChange:t=>{let{[r]:i,...a}=e;n({...a,[t.target.value]:i})},className:x9})}),(0,L.jsx)(`td`,{className:`px-3 py-2`,children:t?(0,L.jsx)(`code`,{className:`text-[12px] text-gray-600`,children:i.version}):(0,L.jsx)(`input`,{value:i.version,onChange:e=>_(r,{version:e.target.value}),className:`w-24 ${x9}`})}),(0,L.jsx)(`td`,{className:`px-3 py-2 hidden sm:table-cell`,children:t?(0,L.jsx)(`code`,{className:`text-[11px] text-gray-500`,children:i.backend||`—`}):(0,L.jsx)(`input`,{value:i.backend??``,onChange:e=>_(r,{backend:e.target.value}),placeholder:`e.g. aqua:hashicorp/terraform`,className:`w-44 ${x9}`})}),!t&&(0,L.jsx)(`td`,{className:`px-3 py-2`,children:(0,L.jsx)(`button`,{onClick:()=>g(r),className:`text-gray-300 hover:text-red-500 transition-colors`,children:(0,L.jsx)(Bn,{size:12})})})]},r))})]})}),!t&&(0,L.jsxs)(L.Fragment,{children:[i?(0,L.jsxs)(`div`,{className:`border border-gray-200 rounded-lg p-3 space-y-2 bg-gray-50/50`,children:[(0,L.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-2`,children:[(0,L.jsx)(`input`,{autoFocus:!0,value:o,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&h(),e.key===`Escape`&&a(!1)},placeholder:`tool name`,className:x9}),(0,L.jsx)(`input`,{value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&h()},placeholder:`version (e.g. 3.12)`,className:x9}),(0,L.jsx)(`input`,{value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&h()},placeholder:`backend (optional)`,className:x9})]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(`button`,{onClick:h,className:`px-3 h-7 rounded bg-gray-900 text-white text-[11px] font-medium hover:bg-gray-800`,children:`Add`}),(0,L.jsx)(`button`,{onClick:()=>a(!1),className:`text-[11px] text-gray-400 hover:text-gray-600`,children:`Cancel`})]})]}):(0,L.jsxs)(`button`,{onClick:()=>a(!0),className:`text-[11px] text-gray-500 hover:text-gray-900 inline-flex items-center gap-1 transition-colors`,children:[(0,L.jsx)(bn,{size:11}),` add tool`]}),f.filter(t=>!e[t.name]).length>0&&(0,L.jsxs)(`div`,{className:`border-t border-gray-100 pt-3 mt-2`,children:[(0,L.jsx)(`span`,{className:`text-[10px] font-semibold text-gray-400 uppercase tracking-wider`,children:`Suggested tools`}),(0,L.jsx)(`div`,{className:`flex flex-wrap items-center gap-1.5 mt-2`,children:f.filter(t=>!e[t.name]).map(e=>(0,L.jsxs)(`button`,{onClick:()=>m(e),className:`px-2 py-0.5 rounded border border-gray-200 bg-white text-[10px] text-gray-500 hover:text-gray-900 hover:border-gray-400 transition-colors`,title:e.description,children:[`+ `,e.name,` `,e.suggestedVersion]},e.name))})]})]})]})}function ice({env:e,envFile:t,envPath:n,readonly:r,onChange:i}){let a=Object.entries(e),[o,s]=(0,F.useState)(!1),[c,l]=(0,F.useState)(``),[u,d]=(0,F.useState)(``),f=()=>{let r=c.trim();r&&(i({...e,[r]:u},t,n),l(``),d(``),s(!1))},p=r=>{let{[r]:a,...o}=e;i(o,t,n)},m=(r,a)=>{i({...e,[r]:a},t,n)};return(0,L.jsxs)(`div`,{className:`space-y-4`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,L.jsx)(`label`,{className:`text-[11px] font-medium text-gray-500 w-20 shrink-0`,children:`_.file`}),(0,L.jsx)(`input`,{value:t,onChange:t=>i(e,t.target.value,n),readOnly:r,placeholder:`.env (load from dotenv file)`,className:x9+` flex-1`})]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,L.jsx)(`label`,{className:`text-[11px] font-medium text-gray-500 w-20 shrink-0`,children:`_.path`}),(0,L.jsx)(`input`,{value:n.join(`, `),onChange:n=>i(e,t,n.target.value.split(`,`).map(e=>e.trim()).filter(Boolean)),readOnly:r,placeholder:`./node_modules/.bin (comma-separated PATH additions)`,className:x9+` flex-1`})]}),(0,L.jsxs)(`div`,{className:`border-t border-gray-100 pt-3`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,L.jsx)(`span`,{className:`text-[11px] font-semibold text-gray-400 uppercase tracking-wider`,children:`Variables`}),!r&&(0,L.jsxs)(`button`,{onClick:()=>s(!0),className:`text-[11px] text-gray-500 hover:text-gray-900 inline-flex items-center gap-1`,children:[(0,L.jsx)(bn,{size:11}),` add`]})]}),a.length===0&&!o&&(0,L.jsx)(`div`,{className:`text-[12px] text-gray-400 italic py-2`,children:`No env vars set.`}),a.length>0&&(0,L.jsx)(`div`,{className:`border border-gray-200 rounded-lg overflow-hidden`,children:(0,L.jsxs)(`table`,{className:`w-full text-[13px]`,children:[(0,L.jsx)(`thead`,{children:(0,L.jsxs)(`tr`,{className:`border-b border-gray-100 bg-gray-50/50 text-left text-[10px] text-gray-500 uppercase tracking-wider`,children:[(0,L.jsx)(`th`,{className:`px-3 py-2 font-medium w-1/3`,children:`Name`}),(0,L.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:`Value`}),!r&&(0,L.jsx)(`th`,{className:`px-3 py-2 font-medium w-10`})]})}),(0,L.jsx)(`tbody`,{children:a.map(([a,o])=>(0,L.jsxs)(`tr`,{className:`border-b border-gray-50 hover:bg-gray-50/50 transition-colors`,children:[(0,L.jsx)(`td`,{className:`px-3 py-2`,children:r?(0,L.jsx)(`code`,{className:`text-[12px] text-gray-800`,children:a}):(0,L.jsx)(`input`,{value:a,onChange:r=>{let{[a]:o,...s}=e;i({...s,[r.target.value]:o},t,n)},className:x9})}),(0,L.jsx)(`td`,{className:`px-3 py-2`,children:r?(0,L.jsx)(`code`,{className:`text-[12px] text-gray-600`,children:o}):(0,L.jsx)(`input`,{value:o,onChange:e=>m(a,e.target.value),className:x9})}),!r&&(0,L.jsx)(`td`,{className:`px-3 py-2`,children:(0,L.jsx)(`button`,{onClick:()=>p(a),className:`text-gray-300 hover:text-red-500`,children:(0,L.jsx)(Bn,{size:12})})})]},a))})]})}),!r&&o&&(0,L.jsxs)(`div`,{className:`flex items-center gap-2 mt-2`,children:[(0,L.jsx)(`input`,{autoFocus:!0,value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&f(),e.key===`Escape`&&s(!1)},placeholder:`VAR_NAME`,className:x9+` flex-1`}),(0,L.jsx)(`input`,{value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&f()},placeholder:`value`,className:x9+` flex-1`}),(0,L.jsx)(`button`,{onClick:f,className:`px-3 h-7 rounded bg-gray-900 text-white text-[11px] font-medium hover:bg-gray-800`,children:`Add`}),(0,L.jsx)(`button`,{onClick:()=>s(!1),className:`text-[11px] text-gray-400 hover:text-gray-600`,children:`Cancel`})]})]})]})}function ace({tasks:e,readonly:t,onChange:n}){let r=Object.entries(e),[i,a]=(0,F.useState)(null),[o,s]=(0,F.useState)(!1),[c,l]=(0,F.useState)(``),u=()=>{let t=c.trim();t&&(n({...e,[t]:{run:``}}),l(``),s(!1),a(t))},d=t=>{let{[t]:r,...o}=e;n(o),i===t&&a(null)},f=(t,r)=>{n({...e,[t]:{...e[t],...r}})};return(0,L.jsxs)(`div`,{className:`space-y-3`,children:[r.length===0&&!o&&(0,L.jsx)(`div`,{className:`text-[12px] text-gray-400 italic py-3`,children:`No tasks defined. Add a build or run task.`}),r.map(([e,n])=>{let r=i===e;return(0,L.jsxs)(`div`,{className:`border border-gray-200 rounded-lg overflow-hidden`,children:[(0,L.jsxs)(`button`,{onClick:()=>a(r?null:e),className:`w-full flex items-center gap-2 px-3 py-2 hover:bg-gray-50 transition-colors text-left`,children:[r?(0,L.jsx)(ht,{size:12,className:`text-gray-400 shrink-0`}):(0,L.jsx)(gt,{size:12,className:`text-gray-400 shrink-0`}),(0,L.jsx)(`code`,{className:`text-[13px] font-medium text-gray-800 flex-1`,children:e}),n.description&&(0,L.jsx)(`span`,{className:`text-[11px] text-gray-400 truncate hidden sm:inline`,children:n.description}),!t&&(0,L.jsx)(`button`,{onClick:t=>{t.stopPropagation(),d(e)},className:`text-gray-300 hover:text-red-500 ml-1`,children:(0,L.jsx)(Bn,{size:12})})]}),r&&(0,L.jsxs)(`div`,{className:`border-t border-gray-100 px-4 py-3 space-y-3 bg-gray-50/30`,children:[(0,L.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[(0,L.jsx)(D9,{label:`Run command`,children:(0,L.jsx)(`input`,{value:n.run??``,onChange:t=>f(e,{run:t.target.value}),readOnly:t,placeholder:`npm run build`,className:b9})}),(0,L.jsx)(D9,{label:`Description`,children:(0,L.jsx)(`input`,{value:n.description??``,onChange:t=>f(e,{description:t.target.value}),readOnly:t,placeholder:`Build the project`,className:b9})}),(0,L.jsx)(D9,{label:`Working dir`,children:(0,L.jsx)(`input`,{value:n.dir??``,onChange:t=>f(e,{dir:t.target.value}),readOnly:t,placeholder:`{{config_root}}/frontend`,className:b9})}),(0,L.jsx)(D9,{label:`Run (Windows)`,children:(0,L.jsx)(`input`,{value:n.runWindows??``,onChange:t=>f(e,{runWindows:t.target.value}),readOnly:t,placeholder:`npm.cmd run build`,className:b9})}),(0,L.jsx)(D9,{label:`Depends on (comma-sep)`,children:(0,L.jsx)(`input`,{value:n.depends?.join(`, `)??``,onChange:t=>f(e,{depends:t.target.value.split(`,`).map(e=>e.trim()).filter(Boolean)}),readOnly:t,placeholder:`lint, test`,className:b9})}),(0,L.jsx)(D9,{label:`Wait for (comma-sep)`,children:(0,L.jsx)(`input`,{value:n.waitFor?.join(`, `)??``,onChange:t=>f(e,{waitFor:t.target.value.split(`,`).map(e=>e.trim()).filter(Boolean)}),readOnly:t,placeholder:`db:5432`,className:b9})}),(0,L.jsx)(D9,{label:`Sources (comma-sep)`,children:(0,L.jsx)(`input`,{value:n.sources?.join(`, `)??``,onChange:t=>f(e,{sources:t.target.value.split(`,`).map(e=>e.trim()).filter(Boolean)}),readOnly:t,placeholder:`src/**/*.ts`,className:b9})}),(0,L.jsx)(D9,{label:`Outputs (comma-sep)`,children:(0,L.jsx)(`input`,{value:n.outputs?.join(`, `)??``,onChange:t=>f(e,{outputs:t.target.value.split(`,`).map(e=>e.trim()).filter(Boolean)}),readOnly:t,placeholder:`dist/**/*.js`,className:b9})})]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,L.jsxs)(`label`,{className:`flex items-center gap-2 text-[12px] text-gray-600 cursor-pointer`,children:[(0,L.jsx)(`input`,{type:`checkbox`,checked:n.hide??!1,onChange:t=>f(e,{hide:t.target.checked||void 0}),disabled:t,className:`h-3.5 w-3.5 rounded border-gray-300`}),`Hide in `,(0,L.jsx)(`code`,{className:`text-[11px] bg-gray-100 px-1 rounded`,children:`mise run`}),` list`]}),(0,L.jsxs)(`label`,{className:`flex items-center gap-2 text-[12px] text-gray-600 cursor-pointer`,children:[(0,L.jsx)(`input`,{type:`checkbox`,checked:n.raw??!1,onChange:t=>f(e,{raw:t.target.checked||void 0}),disabled:t,className:`h-3.5 w-3.5 rounded border-gray-300`}),`Raw (pass directly to shell)`]})]}),(0,L.jsxs)(`details`,{className:`text-[11px]`,children:[(0,L.jsxs)(`summary`,{className:`text-gray-400 cursor-pointer hover:text-gray-600`,children:[`Task environment variables (`,Object.keys(n.env??{}).length,`)`]}),(0,L.jsxs)(`div`,{className:`mt-2 space-y-1`,children:[Object.entries(n.env??{}).map(([r,i])=>(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(`input`,{value:r,onChange:t=>{let i={...n.env??{}},a=i[r]??``;delete i[r],i[t.target.value]=a,f(e,{env:i})},readOnly:t,placeholder:`VAR`,className:x9+` w-40`}),(0,L.jsx)(`span`,{className:`text-gray-400`,children:`=`}),(0,L.jsx)(`input`,{value:i,onChange:t=>{f(e,{env:{...n.env??{},[r]:t.target.value}})},readOnly:t,placeholder:`value`,className:x9+` flex-1`}),!t&&(0,L.jsx)(`button`,{onClick:()=>{let{[r]:t,...i}=n.env??{};f(e,{env:Object.keys(i).length>0?i:void 0})},className:`text-gray-300 hover:text-red-500`,children:(0,L.jsx)(Bn,{size:11})})]},r)),!t&&(0,L.jsxs)(`button`,{onClick:()=>f(e,{env:{...n.env??{},"":``}}),className:`text-[10px] text-gray-400 hover:text-gray-600 inline-flex items-center gap-1 mt-1`,children:[(0,L.jsx)(bn,{size:10}),` add env var`]})]})]})]})]},e)}),!t&&(0,L.jsx)(L.Fragment,{children:o?(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(`input`,{autoFocus:!0,value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&u(),e.key===`Escape`&&s(!1)},placeholder:`task name`,className:x9+` flex-1`}),(0,L.jsx)(`button`,{onClick:u,className:`px-3 h-7 rounded bg-gray-900 text-white text-[11px] font-medium hover:bg-gray-800`,children:`Add`}),(0,L.jsx)(`button`,{onClick:()=>s(!1),className:`text-[11px] text-gray-400 hover:text-gray-600`,children:`Cancel`})]}):(0,L.jsxs)(`button`,{onClick:()=>s(!0),className:`text-[11px] text-gray-500 hover:text-gray-900 inline-flex items-center gap-1`,children:[(0,L.jsx)(bn,{size:11}),` add task`]})})]})}function oce({alias:e,readonly:t,onChange:n}){let[r,i]=(0,F.useState)(``),[a,o]=(0,F.useState)(``),[s,c]=(0,F.useState)(``),[l,u]=(0,F.useState)(!1),d=()=>{let t=r.trim(),l=a.trim();!t||!l||(n({...e,[t]:{...e[t]??{},[l]:s.trim()||`latest`}}),i(``),o(``),c(``),u(!1))},f=(t,r)=>{let{[r]:i,...a}=e[t];if(Object.keys(a).length===0){let{[t]:r,...i}=e;n(i)}else n({...e,[t]:a})},p=Object.entries(e);return(0,L.jsxs)(`div`,{className:`space-y-3`,children:[p.length===0&&!l&&(0,L.jsx)(`div`,{className:`text-[12px] text-gray-400 italic py-3`,children:`No aliases. Create version aliases for tools (e.g. node:myapp → 22.11.0).`}),p.map(([e,n])=>(0,L.jsxs)(`div`,{className:`border border-gray-200 rounded-lg overflow-hidden`,children:[(0,L.jsx)(`div`,{className:`px-3 py-2 bg-gray-50/50 border-b border-gray-100 text-[11px] font-semibold text-gray-500 uppercase tracking-wider`,children:e}),Object.entries(n).map(([n,r])=>(0,L.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-1.5 border-b border-gray-50 hover:bg-gray-50/50`,children:[(0,L.jsx)(`code`,{className:`text-[12px] text-gray-600 w-32 truncate`,children:n}),(0,L.jsx)(`span`,{className:`text-gray-300`,children:`→`}),(0,L.jsx)(`code`,{className:`text-[12px] text-gray-800 flex-1`,children:r}),!t&&(0,L.jsx)(`button`,{onClick:()=>f(e,n),className:`text-gray-300 hover:text-red-500`,children:(0,L.jsx)(Bn,{size:11})})]},n))]},e)),!t&&(0,L.jsx)(L.Fragment,{children:l?(0,L.jsxs)(`div`,{className:`border border-gray-200 rounded-lg p-3 space-y-2 bg-gray-50/50`,children:[(0,L.jsxs)(`div`,{className:`grid grid-cols-3 gap-2`,children:[(0,L.jsx)(`input`,{autoFocus:!0,value:r,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&d(),e.key===`Escape`&&u(!1)},placeholder:`tool (e.g. node)`,className:x9}),(0,L.jsx)(`input`,{value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&d()},placeholder:`alias (e.g. myapp)`,className:x9}),(0,L.jsx)(`input`,{value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&d()},placeholder:`version`,className:x9})]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(`button`,{onClick:d,className:`px-3 h-7 rounded bg-gray-900 text-white text-[11px] font-medium hover:bg-gray-800`,children:`Add`}),(0,L.jsx)(`button`,{onClick:()=>u(!1),className:`text-[11px] text-gray-400 hover:text-gray-600`,children:`Cancel`})]})]}):(0,L.jsxs)(`button`,{onClick:()=>u(!0),className:`text-[11px] text-gray-500 hover:text-gray-900 inline-flex items-center gap-1`,children:[(0,L.jsx)(bn,{size:11}),` add alias`]})})]})}var T9=[{key:`always_keep_download`,label:`Always keep download`,type:`bool`,desc:`Keep downloaded archives after install`},{key:`always_keep_install`,label:`Always keep install`,type:`bool`,desc:`Keep install directory after uninstall`},{key:`legacy_version_file`,label:`Legacy version file`,type:`bool`,desc:`Read .node-version, .python-version, etc.`},{key:`jobs`,label:`Jobs`,type:`number`,desc:`Parallel install jobs (default: 4)`},{key:`experimental`,label:`Experimental`,type:`bool`,desc:`Enable experimental features`},{key:`yes`,label:`Yes`,type:`bool`,desc:`Auto-answer yes to prompts`},{key:`quiet`,label:`Quiet`,type:`bool`,desc:`Suppress non-error output`},{key:`verbose`,label:`Verbose`,type:`bool`,desc:`Show extra debug output`},{key:`raw`,label:`Raw`,type:`bool`,desc:`Pass commands directly to shell`},{key:`color`,label:`Color`,type:`bool`,desc:`Enable colored output`},{key:`pipx_uvx`,label:`pipx / uvx`,type:`bool`,desc:`Use uvx for pipx operations`},{key:`python_venv_auto_create`,label:`Python venv auto-create`,type:`bool`,desc:`Auto-create venv when entering dir`},{key:`python_default_packages_file`,label:`Python default packages file`,type:`string`,desc:`Default pip packages file`,placeholder:`~/.default-python-packages`},{key:`node_mirror_url`,label:`Node mirror URL`,type:`string`,desc:`Custom nodejs.org mirror`},{key:`python_mirror_url`,label:`Python mirror URL`,type:`string`,desc:`Custom python.org mirror`},{key:`plugin_autoupdate_last_check_duration`,label:`Plugin autoupdate check`,type:`string`,desc:`Duration between update checks`,placeholder:`7d`},{key:`trusted_config_paths`,label:`Trusted config paths`,type:`string[]`,desc:`Paths to trust (comma-separated)`,placeholder:`/path/to/trusted`}];function sce({settings:e,readonly:t,onChange:n}){let r=(t,r)=>{if(r===null||r===``||r===void 0||typeof r==`boolean`&&r===!0){let{[t]:r,...i}=e;n(i)}else n({...e,[t]:r})},i=new Set(Object.keys(e)),a=T9.filter(e=>i.has(e.key)||e.type===`bool`),o=Object.entries(e).filter(([e])=>!T9.some(t=>t.key===e));return(0,L.jsxs)(`div`,{className:`space-y-3`,children:[a.map(n=>{let i=e[n.key],a=i!==void 0;return(0,L.jsxs)(`div`,{className:`flex items-start gap-3 py-1.5 border-b border-gray-50`,children:[(0,L.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(`code`,{className:`text-[12px] text-gray-800`,children:n.label}),!a&&(0,L.jsx)(`span`,{className:`text-[9px] text-gray-300`,children:`default`})]}),(0,L.jsx)(`div`,{className:`text-[10px] text-gray-400`,children:n.desc})]}),(0,L.jsx)(`div`,{className:`shrink-0`,children:n.type===`bool`?(0,L.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,L.jsx)(`input`,{type:`checkbox`,checked:i===!0,onChange:e=>r(n.key,e.target.checked||null),disabled:t,className:`sr-only peer`}),(0,L.jsx)(`div`,{className:`w-8 h-4.5 bg-gray-200 peer-checked:bg-gray-900 rounded-full transition-colors after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-3.5 after:w-3.5 after:transition-transform peer-checked:after:translate-x-[14px]`})]}):n.type===`number`?(0,L.jsx)(`input`,{type:`number`,value:i??``,onChange:e=>r(n.key,e.target.value?Number(e.target.value):null),readOnly:t,placeholder:n.placeholder,className:x9+` w-24`}):(0,L.jsx)(`input`,{value:i??``,onChange:e=>r(n.key,e.target.value||null),readOnly:t,placeholder:n.placeholder,className:x9+` w-48`})})]},n.key)}),o.length>0&&(0,L.jsxs)(`div`,{className:`border-t border-gray-200 pt-3 mt-3`,children:[(0,L.jsx)(`span`,{className:`text-[10px] font-semibold text-gray-400 uppercase tracking-wider`,children:`Custom`}),o.map(([i,a])=>(0,L.jsxs)(`div`,{className:`flex items-center gap-2 mt-2`,children:[(0,L.jsx)(`input`,{value:i,readOnly:!0,className:x9+` w-40`}),(0,L.jsx)(`input`,{value:String(a),onChange:e=>r(i,e.target.value),readOnly:t,className:x9+` flex-1`}),!t&&(0,L.jsx)(`button`,{onClick:()=>{let{[i]:t,...r}=e;n(r)},className:`text-gray-300 hover:text-red-500`,children:(0,L.jsx)(Bn,{size:11})})]},i))]}),!t&&(0,L.jsx)(cce,{onAdd:(t,r)=>n({...e,[t]:r})})]})}function cce({onAdd:e}){let[t,n]=(0,F.useState)(!1),[r,i]=(0,F.useState)(``),[a,o]=(0,F.useState)(``),s=()=>{let t=r.trim();t&&(e(t,a),i(``),o(``),n(!1))};return t?(0,L.jsxs)(`div`,{className:`flex items-center gap-2 mt-2`,children:[(0,L.jsx)(`input`,{autoFocus:!0,value:r,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&s(),e.key===`Escape`&&n(!1)},placeholder:`setting key`,className:x9+` flex-1`}),(0,L.jsx)(`input`,{value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&s()},placeholder:`value`,className:x9+` flex-1`}),(0,L.jsx)(`button`,{onClick:s,className:`px-3 h-7 rounded bg-gray-900 text-white text-[11px] font-medium hover:bg-gray-800`,children:`Add`}),(0,L.jsx)(`button`,{onClick:()=>n(!1),className:`text-[11px] text-gray-400 hover:text-gray-600`,children:`Cancel`})]}):(0,L.jsxs)(`button`,{onClick:()=>n(!0),className:`text-[11px] text-gray-500 hover:text-gray-900 inline-flex items-center gap-1`,children:[(0,L.jsx)(bn,{size:11}),` add custom setting`]})}function lce({plugins:e,readonly:t,onChange:n}){let r=Object.entries(e),[i,a]=(0,F.useState)(!1),[o,s]=(0,F.useState)(``),[c,l]=(0,F.useState)(``),u=()=>{let t=o.trim();t&&(n({...e,[t]:c.trim()||`https://github.com/asdf-community/asdf-${t}.git`}),s(``),l(``),a(!1))},d=t=>{let{[t]:r,...i}=e;n(i)};return(0,L.jsxs)(`div`,{className:`space-y-3`,children:[r.length===0&&!i&&(0,L.jsx)(`div`,{className:`text-[12px] text-gray-400 italic py-3`,children:`No plugins. Add asdf-compatible plugin sources for tools not in the default registry.`}),r.length>0&&(0,L.jsx)(`div`,{className:`border border-gray-200 rounded-lg overflow-hidden`,children:(0,L.jsxs)(`table`,{className:`w-full text-[13px]`,children:[(0,L.jsx)(`thead`,{children:(0,L.jsxs)(`tr`,{className:`border-b border-gray-100 bg-gray-50/50 text-left text-[10px] text-gray-500 uppercase tracking-wider`,children:[(0,L.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:`Plugin`}),(0,L.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:`URL`}),!t&&(0,L.jsx)(`th`,{className:`px-3 py-2 font-medium w-10`})]})}),(0,L.jsx)(`tbody`,{children:r.map(([r,i])=>(0,L.jsxs)(`tr`,{className:`border-b border-gray-50 hover:bg-gray-50/50 transition-colors`,children:[(0,L.jsx)(`td`,{className:`px-3 py-2`,children:t?(0,L.jsx)(`code`,{className:`text-[12px] text-gray-800`,children:r}):(0,L.jsx)(`input`,{value:r,onChange:t=>{let{[r]:i,...a}=e;n({...a,[t.target.value]:i})},className:x9})}),(0,L.jsx)(`td`,{className:`px-3 py-2`,children:t?(0,L.jsx)(`code`,{className:`text-[11px] text-gray-500 truncate block max-w-xs`,children:i}):(0,L.jsx)(`input`,{value:i,onChange:t=>n({...e,[r]:t.target.value}),className:x9})}),!t&&(0,L.jsx)(`td`,{className:`px-3 py-2`,children:(0,L.jsx)(`button`,{onClick:()=>d(r),className:`text-gray-300 hover:text-red-500`,children:(0,L.jsx)(Bn,{size:12})})})]},r))})]})}),!t&&(0,L.jsx)(L.Fragment,{children:i?(0,L.jsxs)(`div`,{className:`border border-gray-200 rounded-lg p-3 space-y-2 bg-gray-50/50`,children:[(0,L.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2`,children:[(0,L.jsx)(`input`,{autoFocus:!0,value:o,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&u(),e.key===`Escape`&&a(!1)},placeholder:`plugin name (e.g. rust)`,className:x9}),(0,L.jsx)(`input`,{value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&u()},placeholder:`git URL (or leave empty for default)`,className:x9})]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(`button`,{onClick:u,className:`px-3 h-7 rounded bg-gray-900 text-white text-[11px] font-medium hover:bg-gray-800`,children:`Add`}),(0,L.jsx)(`button`,{onClick:()=>a(!1),className:`text-[11px] text-gray-400 hover:text-gray-600`,children:`Cancel`})]})]}):(0,L.jsxs)(`button`,{onClick:()=>a(!0),className:`text-[11px] text-gray-500 hover:text-gray-900 inline-flex items-center gap-1`,children:[(0,L.jsx)(bn,{size:11}),` add plugin`]})})]})}var E9=[`enter`,`leave`,`cd`,`preinstall`,`postinstall`];function uce({hooks:e,readonly:t,onChange:n}){let r=(t,r)=>{if(r.trim())n({...e,[t]:r});else{let{[t]:r,...i}=e;n(i)}};return(0,L.jsxs)(`div`,{className:`space-y-3`,children:[(0,L.jsxs)(`div`,{className:`text-[11px] text-gray-500 mb-2`,children:[`Commands that run on lifecycle events. Use `,(0,L.jsx)(`code`,{className:`bg-gray-100 px-1 rounded text-[10px]`,children:`{{env.PWD}}`}),` for template variables.`]}),E9.map(n=>(0,L.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,L.jsx)(`code`,{className:`text-[11px] font-medium text-gray-600 w-24 shrink-0`,children:n}),(0,L.jsx)(`input`,{value:e[n]??``,onChange:e=>r(n,e.target.value),readOnly:t,placeholder:`echo '${n} hook'`,className:x9+` flex-1`})]},n)),Object.entries(e).filter(([e])=>!E9.includes(e)).map(([i,a])=>(0,L.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,L.jsx)(`input`,{value:i,readOnly:!0,className:x9+` w-24 shrink-0`}),(0,L.jsx)(`input`,{value:a,onChange:e=>r(i,e.target.value),readOnly:t,className:x9+` flex-1`}),!t&&(0,L.jsx)(`button`,{onClick:()=>{let{[i]:t,...r}=e;n(r)},className:`text-gray-300 hover:text-red-500`,children:(0,L.jsx)(Bn,{size:11})})]},i)),!t&&(0,L.jsx)(dce,{onAdd:(t,r)=>n({...e,[t]:r})})]})}function dce({onAdd:e}){let[t,n]=(0,F.useState)(!1),[r,i]=(0,F.useState)(``),[a,o]=(0,F.useState)(``),s=()=>{let t=r.trim();t&&(e(t,a),i(``),o(``),n(!1))};return t?(0,L.jsxs)(`div`,{className:`flex items-center gap-2 mt-1`,children:[(0,L.jsx)(`input`,{autoFocus:!0,value:r,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&s(),e.key===`Escape`&&n(!1)},placeholder:`hook event`,className:x9+` w-32`}),(0,L.jsx)(`input`,{value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&s()},placeholder:`command`,className:x9+` flex-1`}),(0,L.jsx)(`button`,{onClick:s,className:`px-3 h-7 rounded bg-gray-900 text-white text-[11px] font-medium hover:bg-gray-800`,children:`Add`}),(0,L.jsx)(`button`,{onClick:()=>n(!1),className:`text-[11px] text-gray-400 hover:text-gray-600`,children:`Cancel`})]}):(0,L.jsxs)(`button`,{onClick:()=>n(!0),className:`text-[11px] text-gray-500 hover:text-gray-900 inline-flex items-center gap-1 mt-1`,children:[(0,L.jsx)(bn,{size:11}),` add custom hook`]})}function D9({label:e,children:t}){return(0,L.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,L.jsx)(`span`,{className:`text-[10px] font-medium text-gray-400 uppercase tracking-wider`,children:e}),t]})}var O9=`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono`;function fce(){let[e,t]=(0,F.useState)(null),[n,r]=(0,F.useState)(!0),[i,a]=(0,F.useState)(!1),[o,s]=(0,F.useState)(null),[c,l]=(0,F.useState)(!1),[u,d]=(0,F.useState)(`providers`),f=(0,F.useCallback)(async()=>{r(!0),s(null),t(await Ig()),r(!1)},[]);(0,F.useEffect)(()=>{f()},[f]);let p=async n=>{if(!e)return;let r={...e,...n};t(r),a(!0),s(null);let i=await Lg(r);if(a(!1),!i){s(`save failed`);return}l(!0),setTimeout(()=>l(!1),2500)};return n&&!e?(0,L.jsx)(`div`,{className:`text-[12px] text-gray-400 italic py-12 text-center`,children:`loading presets…`}):e?(0,L.jsxs)(`div`,{className:`space-y-4`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-1 bg-gray-100 rounded-lg p-0.5 w-fit`,children:[(0,L.jsxs)(`button`,{onClick:()=>d(`providers`),className:`px-3 py-1 rounded text-[11px] font-medium transition-colors flex items-center gap-1.5 ${u===`providers`?`bg-white text-gray-900 shadow-sm`:`text-gray-500 hover:text-gray-700`}`,children:[(0,L.jsx)(kt,{size:12}),` AI Providers`]}),(0,L.jsxs)(`button`,{onClick:()=>d(`mise-tools`),className:`px-3 py-1 rounded text-[11px] font-medium transition-colors flex items-center gap-1.5 ${u===`mise-tools`?`bg-white text-gray-900 shadow-sm`:`text-gray-500 hover:text-gray-700`}`,children:[(0,L.jsx)(qn,{size:12}),` Mise Tools`]})]}),u===`providers`&&(0,L.jsx)(pce,{presets:e.providerPresets,onChange:e=>p({providerPresets:e}),saving:i}),u===`mise-tools`&&(0,L.jsx)(mce,{presets:e.miseToolPresets,onChange:e=>p({miseToolPresets:e}),saving:i}),(0,L.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[o&&(0,L.jsx)(`span`,{className:`text-[12px] text-red-600`,children:o}),c&&(0,L.jsxs)(`span`,{className:`text-[12px] text-emerald-600 flex items-center gap-1`,children:[(0,L.jsx)(mt,{size:13}),` saved`]})]})]}):(0,L.jsx)(`div`,{className:`text-[12px] text-red-600 py-12 text-center`,children:`failed to load presets`})}function pce({presets:e,onChange:t,saving:n}){let[r,i]=(0,F.useState)(!1),[a,o]=(0,F.useState)(``),[s,c]=(0,F.useState)(``),[l,u]=(0,F.useState)(``),d=()=>{let n=a.trim();if(!n||!s.trim())return;let r=l.trim()?l.split(`
450
450
  `).map(e=>e.trim()).filter(Boolean):[];t([...e,{name:n,baseUrl:s.trim(),models:r}]),o(``),c(``),u(``),i(!1)},f=n=>{t(e.filter((e,t)=>t!==n))},p=(n,r)=>{t(e.map((e,t)=>t===n?{...e,...r}:e))};return(0,L.jsxs)(`div`,{className:`space-y-3`,children:[e.length===0&&!r&&(0,L.jsx)(`div`,{className:`text-[12px] text-gray-400 italic py-3`,children:`No provider presets. Add one to get started.`}),e.length>0&&(0,L.jsx)(`div`,{className:`border border-gray-200 rounded-lg overflow-hidden`,children:(0,L.jsxs)(`table`,{className:`w-full text-[13px]`,children:[(0,L.jsx)(`thead`,{children:(0,L.jsxs)(`tr`,{className:`border-b border-gray-100 bg-gray-50/50 text-left text-[10px] text-gray-500 uppercase tracking-wider`,children:[(0,L.jsx)(`th`,{className:`px-3 py-2 font-medium w-1/5`,children:`Name`}),(0,L.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:`Base URL`}),(0,L.jsx)(`th`,{className:`px-3 py-2 font-medium hidden sm:table-cell`,children:`Models`}),(0,L.jsx)(`th`,{className:`px-3 py-2 font-medium w-10`})]})}),(0,L.jsx)(`tbody`,{children:e.map((e,t)=>(0,L.jsxs)(`tr`,{className:`border-b border-gray-50 hover:bg-gray-50/50 transition-colors`,children:[(0,L.jsx)(`td`,{className:`px-3 py-2`,children:(0,L.jsx)(`input`,{value:e.name,onChange:e=>p(t,{name:e.target.value}),disabled:n,className:O9})}),(0,L.jsx)(`td`,{className:`px-3 py-2`,children:(0,L.jsx)(`input`,{value:e.baseUrl,onChange:e=>p(t,{baseUrl:e.target.value}),disabled:n,className:O9})}),(0,L.jsx)(`td`,{className:`px-3 py-2 hidden sm:table-cell`,children:(0,L.jsx)(`textarea`,{value:e.models.join(`
451
451
  `),onChange:e=>p(t,{models:e.target.value.split(`
452
- `).map(e=>e.trim()).filter(Boolean)}),disabled:n,rows:Math.max(1,e.models.length),className:O9+` resize-none`})}),(0,L.jsx)(`td`,{className:`px-3 py-2`,children:(0,L.jsx)(`button`,{onClick:()=>f(t),disabled:n,className:`text-gray-300 hover:text-red-500 transition-colors disabled:opacity-30`,children:(0,L.jsx)(Bn,{size:12})})})]},t))})]})}),r?(0,L.jsxs)(`div`,{className:`border border-gray-200 rounded-lg p-3 space-y-2 bg-gray-50/50`,children:[(0,L.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2`,children:[(0,L.jsx)(`input`,{autoFocus:!0,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&d(),e.key===`Escape`&&i(!1)},placeholder:`Provider name`,className:O9}),(0,L.jsx)(`input`,{value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&d()},placeholder:`Base URL`,className:O9})]}),(0,L.jsx)(`textarea`,{value:l,onChange:e=>u(e.target.value),placeholder:`Models (one per line)`,rows:3,className:O9+` resize-none`}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(`button`,{onClick:d,className:`px-3 h-7 rounded bg-gray-900 text-white text-[11px] font-medium hover:bg-gray-800`,children:`Add`}),(0,L.jsx)(`button`,{onClick:()=>i(!1),className:`text-[11px] text-gray-400 hover:text-gray-600`,children:`Cancel`})]})]}):(0,L.jsxs)(`button`,{onClick:()=>i(!0),disabled:n,className:`text-[11px] text-gray-500 hover:text-gray-900 inline-flex items-center gap-1 transition-colors disabled:opacity-50`,children:[(0,L.jsx)(bn,{size:11}),` add provider preset`]})]})}function mce({presets:e,onChange:t,saving:n}){let[r,i]=(0,F.useState)(!1),[a,o]=(0,F.useState)(``),[s,c]=(0,F.useState)(``),[l,u]=(0,F.useState)(``),[d,f]=(0,F.useState)(``),p=()=>{let n=a.trim();!n||!s.trim()||(t([...e,{name:n,suggestedVersion:s.trim(),description:l.trim()||void 0,backend:d.trim()||void 0}]),o(``),c(``),u(``),f(``),i(!1))},m=n=>{t(e.filter((e,t)=>t!==n))},h=(n,r)=>{t(e.map((e,t)=>t===n?{...e,...r}:e))};return(0,L.jsxs)(`div`,{className:`space-y-3`,children:[e.length===0&&!r&&(0,L.jsx)(`div`,{className:`text-[12px] text-gray-400 italic py-3`,children:`No mise tool presets. Add one to get started.`}),e.length>0&&(0,L.jsx)(`div`,{className:`border border-gray-200 rounded-lg overflow-hidden`,children:(0,L.jsxs)(`table`,{className:`w-full text-[13px]`,children:[(0,L.jsx)(`thead`,{children:(0,L.jsxs)(`tr`,{className:`border-b border-gray-100 bg-gray-50/50 text-left text-[10px] text-gray-500 uppercase tracking-wider`,children:[(0,L.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:`Tool`}),(0,L.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:`Version`}),(0,L.jsx)(`th`,{className:`px-3 py-2 font-medium hidden sm:table-cell`,children:`Description`}),(0,L.jsx)(`th`,{className:`px-3 py-2 font-medium hidden sm:table-cell`,children:`Backend`}),(0,L.jsx)(`th`,{className:`px-3 py-2 font-medium w-10`})]})}),(0,L.jsx)(`tbody`,{children:e.map((e,t)=>(0,L.jsxs)(`tr`,{className:`border-b border-gray-50 hover:bg-gray-50/50 transition-colors`,children:[(0,L.jsx)(`td`,{className:`px-3 py-2`,children:(0,L.jsx)(`input`,{value:e.name,onChange:e=>h(t,{name:e.target.value}),disabled:n,className:O9+` w-24`})}),(0,L.jsx)(`td`,{className:`px-3 py-2`,children:(0,L.jsx)(`input`,{value:e.suggestedVersion,onChange:e=>h(t,{suggestedVersion:e.target.value}),disabled:n,className:O9+` w-20`})}),(0,L.jsx)(`td`,{className:`px-3 py-2 hidden sm:table-cell`,children:(0,L.jsx)(`input`,{value:e.description??``,onChange:e=>h(t,{description:e.target.value||void 0}),disabled:n,placeholder:`optional`,className:O9})}),(0,L.jsx)(`td`,{className:`px-3 py-2 hidden sm:table-cell`,children:(0,L.jsx)(`input`,{value:e.backend??``,onChange:e=>h(t,{backend:e.target.value||void 0}),disabled:n,placeholder:`optional`,className:O9})}),(0,L.jsx)(`td`,{className:`px-3 py-2`,children:(0,L.jsx)(`button`,{onClick:()=>m(t),disabled:n,className:`text-gray-300 hover:text-red-500 transition-colors disabled:opacity-30`,children:(0,L.jsx)(Bn,{size:12})})})]},t))})]})}),r?(0,L.jsxs)(`div`,{className:`border border-gray-200 rounded-lg p-3 space-y-2 bg-gray-50/50`,children:[(0,L.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2`,children:[(0,L.jsx)(`input`,{autoFocus:!0,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&p(),e.key===`Escape`&&i(!1)},placeholder:`Tool name (e.g. python)`,className:O9}),(0,L.jsx)(`input`,{value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&p()},placeholder:`Suggested version (e.g. 3.12)`,className:O9})]}),(0,L.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2`,children:[(0,L.jsx)(`input`,{value:l,onChange:e=>u(e.target.value),placeholder:`Description (optional)`,className:O9}),(0,L.jsx)(`input`,{value:d,onChange:e=>f(e.target.value),placeholder:`Backend (optional, e.g. aqua:sharkdp/fd)`,className:O9})]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(`button`,{onClick:p,className:`px-3 h-7 rounded bg-gray-900 text-white text-[11px] font-medium hover:bg-gray-800`,children:`Add`}),(0,L.jsx)(`button`,{onClick:()=>i(!1),className:`text-[11px] text-gray-400 hover:text-gray-600`,children:`Cancel`})]})]}):(0,L.jsxs)(`button`,{onClick:()=>i(!0),disabled:n,className:`text-[11px] text-gray-500 hover:text-gray-900 inline-flex items-center gap-1 transition-colors disabled:opacity-50`,children:[(0,L.jsx)(bn,{size:11}),` add mise tool preset`]})]})}function k9(e){return e<1e3?String(e):e<1e6?`${(e/1e3).toFixed(1)}k`:`${(e/1e6).toFixed(1)}M`}function A9(e){return new Date(e).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`})}function hce(e){return new Date(e).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,year:`numeric`})}function j9(e){let t=new Date;return t.setDate(t.getDate()-e),t.toISOString().slice(0,10)}function M9(e){return e?e===`desc`?`asc`:null:`desc`}function N9({label:e,field:t,sortField:n,sortDir:r,onSort:i,className:a}){let o=n===t;return(0,L.jsx)(`th`,{className:`px-4 py-2.5 text-[11px] font-semibold text-gray-500 uppercase tracking-wider cursor-pointer select-none hover:text-gray-700 transition-colors ${a??``}`,onClick:()=>i(t),children:(0,L.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e,o&&r===`desc`?(0,L.jsx)(at,{className:`h-3 w-3`}):o&&r===`asc`?(0,L.jsx)(ct,{className:`h-3 w-3`}):(0,L.jsx)(st,{className:`h-3 w-3 opacity-30`})]})})}function gce({data:e,maxVal:t,height:n=24,gap:r=6}){return(0,L.jsx)(`svg`,{width:280,height:e.length*(n+r),className:`shrink-0`,children:e.map((e,i)=>{let a=i*(n+r),o=t>0?e.input/t*280:0,s=t>0?e.output/t*280:0;return(0,L.jsxs)(`g`,{children:[(0,L.jsx)(`rect`,{x:0,y:a,width:o,height:n,rx:3,fill:`var(--color-blue-500)`,opacity:.7}),(0,L.jsx)(`rect`,{x:o,y:a,width:s,height:n,rx:3,fill:`var(--color-green-500)`,opacity:.7}),(0,L.jsx)(`text`,{x:o+s+4,y:a+n/2,dominantBaseline:`central`,className:`fill-gray-500 text-[10px]`,children:e.label})]},e.label)})})}function _ce({data:e,w:t=600,h:n=180}){let r={top:10,right:10,bottom:24,left:50},i=t-r.left-r.right,a=n-r.top-r.bottom,o=Math.max(1,...e.map(e=>e.input+e.output)),s=t=>r.left+(e.length>1?t/(e.length-1)*i:i/2),c=e=>r.top+a-e/o*a,l=e.map((e,t)=>`${s(t)},${c(e.input)}`).join(` `),u=e.map((e,t)=>`${s(t)},${c(e.input+e.output)}`).join(` `),d=`${s(e.length-1)},${r.top+a} ${s(0)},${r.top+a}`,f=[0,o/2,o].map(e=>({y:c(e),label:k9(e)}));return(0,L.jsxs)(`svg`,{width:t,height:n,className:`w-full`,viewBox:`0 0 ${t} ${n}`,preserveAspectRatio:`xMidYMid meet`,children:[f.map(e=>(0,L.jsxs)(`g`,{children:[(0,L.jsx)(`line`,{x1:r.left,y1:e.y,x2:t-r.right,y2:e.y,stroke:`var(--color-gray-200)`,strokeDasharray:`3,2`}),(0,L.jsx)(`text`,{x:r.left-6,y:e.y,textAnchor:`end`,dominantBaseline:`central`,className:`fill-gray-400 text-[9px]`,children:e.label})]},e.label)),(0,L.jsx)(`polygon`,{points:`${u} ${d}`,fill:`var(--color-green-500)`,opacity:.2}),(0,L.jsx)(`polyline`,{points:u,fill:`none`,stroke:`var(--color-green-500)`,strokeWidth:1.5,opacity:.6}),(0,L.jsx)(`polygon`,{points:`${l} ${d}`,fill:`var(--color-blue-500)`,opacity:.2}),(0,L.jsx)(`polyline`,{points:l,fill:`none`,stroke:`var(--color-blue-500)`,strokeWidth:1.5}),e.filter((t,n)=>e.length<=14||n%Math.ceil(e.length/14)===0||n===e.length-1).map((t,r)=>(0,L.jsx)(`text`,{x:s(e.indexOf(t)),y:n-4,textAnchor:`middle`,className:`fill-gray-400 text-[9px]`,children:A9(t.date)},t.date))]})}function vce({dailyUsage:e,timeRange:t}){let[n,r]=(0,F.useState)(`total`),[i,a]=(0,F.useState)(`desc`),[o,s]=(0,F.useState)(!1),c=(0,F.useMemo)(()=>{let n=t===`today`?j9(0):t===`7d`?j9(7):t===`30d`?j9(30):``,r={};for(let[t,i]of Object.entries(e))for(let[e,a]of Object.entries(i)){if(n&&e<n)continue;let i=r[t]??{inputTokens:0,outputTokens:0,cacheReadInputTokens:0};i.inputTokens+=a.inputTokens,i.outputTokens+=a.outputTokens,i.cacheReadInputTokens+=a.cacheReadInputTokens??0,r[t]=i}return Object.entries(r).map(([e,t])=>({model:e,...t,total:t.inputTokens+t.outputTokens,cacheRate:t.inputTokens+t.cacheReadInputTokens>0?Math.round(t.cacheReadInputTokens/(t.inputTokens+t.cacheReadInputTokens)*100):0}))},[e,t]),l=(0,F.useMemo)(()=>{let e=[...c];return n&&i&&e.sort((e,t)=>{let r=n===`model`?e.model:e[n]??0,a=n===`model`?t.model:t[n]??0;return typeof r==`string`&&typeof a==`string`?i===`desc`?a.localeCompare(r):r.localeCompare(a):i===`desc`?a-r:r-a}),e},[c,n,i]),u=e=>{if(n===e){let e=M9(i);e?a(e):(r(null),a(null))}else r(e),a(`desc`)},d=l.reduce((e,t)=>e+t.total,0),f=Math.max(...l.map(e=>e.total),1),p=o?l:l.slice(0,10),m=p.map(e=>({label:e.model,input:e.inputTokens,output:e.outputTokens}));return(0,L.jsxs)(`div`,{children:[(0,L.jsxs)(`div`,{className:`grid grid-cols-4 gap-3 mb-6`,children:[(0,L.jsxs)(`div`,{className:`bg-white border border-gray-200 rounded-lg p-4`,children:[(0,L.jsx)(`div`,{className:`text-[11px] text-gray-500 mb-1`,children:`Total Tokens`}),(0,L.jsx)(`div`,{className:`text-xl font-semibold text-gray-900`,children:k9(d)})]}),(0,L.jsxs)(`div`,{className:`bg-white border border-gray-200 rounded-lg p-4`,children:[(0,L.jsx)(`div`,{className:`text-[11px] text-gray-500 mb-1`,children:`Prompt`}),(0,L.jsx)(`div`,{className:`text-xl font-semibold text-blue-600`,children:k9(l.reduce((e,t)=>e+t.inputTokens,0))})]}),(0,L.jsxs)(`div`,{className:`bg-white border border-gray-200 rounded-lg p-4`,children:[(0,L.jsx)(`div`,{className:`text-[11px] text-gray-500 mb-1`,children:`Completion`}),(0,L.jsx)(`div`,{className:`text-xl font-semibold text-green-600`,children:k9(l.reduce((e,t)=>e+t.outputTokens,0))})]}),(0,L.jsxs)(`div`,{className:`bg-white border border-gray-200 rounded-lg p-4`,children:[(0,L.jsx)(`div`,{className:`text-[11px] text-gray-500 mb-1`,children:`Cached Tokens`}),(0,L.jsx)(`div`,{className:`text-xl font-semibold text-purple-600`,children:k9(l.reduce((e,t)=>e+t.cacheReadInputTokens,0))}),(0,L.jsx)(`div`,{className:`text-[11px] text-purple-400 mt-0.5`,children:(()=>{let e=l.reduce((e,t)=>e+t.cacheReadInputTokens,0),t=l.reduce((e,t)=>e+t.inputTokens,0);return t+e>0?`${Math.round(e/(t+e)*100)}% of potential input`:`—`})()})]})]}),p.length>0&&(0,L.jsxs)(`div`,{className:`bg-white border border-gray-200 rounded-lg p-4 mb-4`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-4 mb-3`,children:[(0,L.jsx)(`span`,{className:`text-[11px] font-semibold text-gray-500 uppercase tracking-wider`,children:`Token Distribution`}),(0,L.jsxs)(`span`,{className:`flex items-center gap-1 text-[10px] text-gray-500`,children:[(0,L.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-sm bg-blue-500 opacity-70`}),` Input`]}),(0,L.jsxs)(`span`,{className:`flex items-center gap-1 text-[10px] text-gray-500`,children:[(0,L.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-sm bg-green-500 opacity-70`}),` Output`]})]}),(0,L.jsx)(`div`,{className:`overflow-x-auto`,children:(0,L.jsx)(gce,{data:m,maxVal:f})})]}),(0,L.jsxs)(`div`,{className:`bg-white border border-gray-200 rounded-lg overflow-hidden`,children:[(0,L.jsxs)(`table`,{className:`w-full`,children:[(0,L.jsx)(`thead`,{children:(0,L.jsxs)(`tr`,{className:`border-b border-gray-200 bg-gray-50/50`,children:[(0,L.jsx)(N9,{label:`Model`,field:`model`,sortField:n,sortDir:i,onSort:u,className:`text-left`}),(0,L.jsx)(N9,{label:`Input`,field:`inputTokens`,sortField:n,sortDir:i,onSort:u,className:`text-right`}),(0,L.jsx)(N9,{label:`Output`,field:`outputTokens`,sortField:n,sortDir:i,onSort:u,className:`text-right`}),(0,L.jsx)(N9,{label:`Total`,field:`total`,sortField:n,sortDir:i,onSort:u,className:`text-right`}),(0,L.jsx)(N9,{label:`Cached`,field:`cacheRate`,sortField:n,sortDir:i,onSort:u,className:`text-right`}),(0,L.jsx)(`th`,{className:`text-right px-4 py-2.5 text-[11px] font-semibold text-gray-500 uppercase tracking-wider`,children:`%`})]})}),(0,L.jsxs)(`tbody`,{children:[p.map(e=>(0,L.jsxs)(`tr`,{className:`border-b border-gray-100 hover:bg-gray-50/50 transition-colors`,children:[(0,L.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,L.jsx)(`code`,{className:`text-[12px] text-gray-800`,children:e.model})}),(0,L.jsx)(`td`,{className:`px-4 py-2.5 text-right text-[12px] text-blue-600 tabular-nums`,children:k9(e.inputTokens)}),(0,L.jsx)(`td`,{className:`px-4 py-2.5 text-right text-[12px] text-green-600 tabular-nums`,children:k9(e.outputTokens)}),(0,L.jsx)(`td`,{className:`px-4 py-2.5 text-right text-[12px] text-gray-900 font-medium tabular-nums`,children:k9(e.total)}),(0,L.jsxs)(`td`,{className:`px-4 py-2.5 text-right text-[12px] text-purple-600 tabular-nums`,children:[k9(e.cacheReadInputTokens),` `,(0,L.jsxs)(`span`,{className:`text-[10px] text-purple-400`,children:[`(`,e.cacheRate,`%)`]})]}),(0,L.jsxs)(`td`,{className:`px-4 py-2.5 text-right text-[11px] text-gray-400 tabular-nums`,children:[d>0?(e.total/d*100).toFixed(1):0,`%`]})]},e.model)),p.length===0&&(0,L.jsx)(`tr`,{children:(0,L.jsx)(`td`,{colSpan:6,className:`px-4 py-8 text-center text-[12px] text-gray-400 italic`,children:`No token usage data`})})]})]}),l.length>10&&(0,L.jsx)(`div`,{className:`px-4 py-2 border-t border-gray-100 bg-gray-50/50`,children:(0,L.jsx)(`button`,{onClick:()=>s(!o),className:`text-[11px] text-gray-500 hover:text-gray-900 transition-colors`,children:o?`Show less`:`Show all ${l.length} models`})})]})]})}function yce({dailyUsage:e,timeRange:t}){let{dates:n,models:r,data:i,chartData:a}=(0,F.useMemo)(()=>{let n=new Set(Object.keys(e)),r=new Set;for(let t of Object.keys(e))for(let n of Object.keys(e[t]))r.add(n);let i=Array.from(r).sort(),a=Array.from(n).sort(),o=t===`today`?j9(0):t===`7d`?j9(7):t===`30d`?j9(30):``,s=o?i.filter(e=>e>=o):i,c={};for(let t of a){c[t]={};for(let n of s)c[t][n]=(e[t]?.[n]?.inputTokens??0)+(e[t]?.[n]?.outputTokens??0)}return{dates:s,models:a,data:c,chartData:s.map(t=>{let n=0,r=0;for(let i of a)n+=e[i]?.[t]?.inputTokens??0,r+=e[i]?.[t]?.outputTokens??0;return{date:t,input:n,output:r}})}},[e,t]);return n.length===0?(0,L.jsx)(`div`,{className:`text-center py-8 text-[12px] text-gray-400 italic`,children:`No daily data for this time range`}):(0,L.jsxs)(`div`,{children:[(0,L.jsxs)(`div`,{className:`bg-white border border-gray-200 rounded-lg p-4 mb-4`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-4 mb-2`,children:[(0,L.jsx)(`span`,{className:`text-[11px] font-semibold text-gray-500 uppercase tracking-wider`,children:`Daily Trend`}),(0,L.jsxs)(`span`,{className:`flex items-center gap-1 text-[10px] text-gray-500`,children:[(0,L.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-sm bg-blue-500 opacity-70`}),` Input`]}),(0,L.jsxs)(`span`,{className:`flex items-center gap-1 text-[10px] text-gray-500`,children:[(0,L.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-sm bg-green-500 opacity-20`}),` Output`]})]}),(0,L.jsx)(_ce,{data:a})]}),(0,L.jsx)(`div`,{className:`bg-white border border-gray-200 rounded-lg overflow-hidden`,children:(0,L.jsx)(`div`,{className:`overflow-x-auto`,children:(0,L.jsxs)(`table`,{className:`w-full min-w-[500px]`,children:[(0,L.jsx)(`thead`,{children:(0,L.jsxs)(`tr`,{className:`border-b border-gray-200 bg-gray-50/50`,children:[(0,L.jsx)(`th`,{className:`text-left px-4 py-2.5 text-[11px] font-semibold text-gray-500 uppercase tracking-wider sticky left-0 bg-gray-50/50`,children:`Date`}),(0,L.jsx)(`th`,{className:`text-right px-4 py-2.5 text-[11px] font-semibold text-gray-500 uppercase tracking-wider`,children:`Total`}),r.map(e=>(0,L.jsx)(`th`,{className:`text-right px-3 py-2.5 text-[10px] font-medium text-gray-400 uppercase tracking-wider max-w-[120px]`,children:(0,L.jsx)(`span`,{className:`truncate block`,children:e})},e))]})}),(0,L.jsx)(`tbody`,{children:n.map(e=>(0,L.jsxs)(`tr`,{className:`border-b border-gray-100 hover:bg-gray-50/50 transition-colors`,children:[(0,L.jsx)(`td`,{className:`px-4 py-2 text-[12px] text-gray-700 sticky left-0 bg-white`,children:A9(e)}),(0,L.jsx)(`td`,{className:`px-4 py-2 text-right text-[12px] text-gray-900 font-medium tabular-nums`,children:k9(r.reduce((t,n)=>t+(i[n]?.[e]??0),0))}),r.map(t=>(0,L.jsx)(`td`,{className:`px-3 py-2 text-right text-[11px] text-gray-500 tabular-nums`,children:i[t]?.[e]?k9(i[t][e]):``},t))]},e))})]})})})]})}function bce({loopUsage:e,timeRange:t}){let[n,r]=(0,F.useState)(`lastActivity`),[i,a]=(0,F.useState)(`desc`),o=t===`today`?j9(0):t===`7d`?j9(7):t===`30d`?j9(30):``,s=(0,F.useMemo)(()=>{let t=o?e.filter(e=>(e.lastActivity??``).slice(0,10)>=o):[...e];return n&&i&&t.sort((e,t)=>{let r,a;return n===`total`?(r=e.inputTokens+e.outputTokens,a=t.inputTokens+t.outputTokens):n===`title`||n===`lastActivity`?(r=e[n]??``,a=t[n]??``):(r=e[n]??0,a=t[n]??0),typeof r==`string`&&typeof a==`string`?i===`desc`?a.localeCompare(r):r.localeCompare(a):i===`desc`?a-r:r-a}),t},[e,o,n,i]),c=e=>{if(n===e){let e=M9(i);e?a(e):(r(null),a(null))}else r(e),a(`desc`)},l=s.reduce((e,t)=>e+t.inputTokens+t.outputTokens,0),u=_i();return(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`div`,{className:`flex items-center gap-4 mb-4 px-1`,children:(0,L.jsxs)(`span`,{className:`text-[13px] text-gray-600`,children:[(0,L.jsx)(`span`,{className:`font-semibold text-gray-900`,children:s.length}),` loops ·`,` `,(0,L.jsx)(`span`,{className:`font-semibold text-gray-900`,children:k9(l)}),` total tokens`]})}),(0,L.jsx)(`div`,{className:`bg-white border border-gray-200 rounded-lg overflow-hidden`,children:(0,L.jsxs)(`table`,{className:`w-full`,children:[(0,L.jsx)(`thead`,{children:(0,L.jsxs)(`tr`,{className:`border-b border-gray-200 bg-gray-50/50`,children:[(0,L.jsx)(N9,{label:`Loop`,field:`title`,sortField:n,sortDir:i,onSort:c,className:`text-left`}),(0,L.jsx)(`th`,{className:`hidden sm:table-cell text-left px-4 py-2.5 text-[11px] font-semibold text-gray-500 uppercase tracking-wider`,children:`Models`}),(0,L.jsx)(N9,{label:`Input`,field:`inputTokens`,sortField:n,sortDir:i,onSort:c,className:`text-right`}),(0,L.jsx)(N9,{label:`Output`,field:`outputTokens`,sortField:n,sortDir:i,onSort:c,className:`text-right`}),(0,L.jsx)(N9,{label:`Total`,field:`total`,sortField:n,sortDir:i,onSort:c,className:`text-right`}),(0,L.jsx)(`th`,{className:`text-right px-4 py-2.5 text-[11px] font-semibold text-gray-500 uppercase tracking-wider`,children:`Cached`}),(0,L.jsx)(N9,{label:`Last active`,field:`lastActivity`,sortField:n,sortDir:i,onSort:c,className:`text-right hidden sm:table-cell`})]})}),(0,L.jsxs)(`tbody`,{children:[s.map(e=>{let t=e.inputTokens+e.outputTokens,n=e.inputTokens+e.cacheReadInputTokens>0?Math.round(e.cacheReadInputTokens/(e.inputTokens+e.cacheReadInputTokens)*100):0;return(0,L.jsxs)(`tr`,{className:`border-b border-gray-100 hover:bg-gray-50/50 transition-colors cursor-pointer`,onClick:()=>u(`/loop/${e.loopId}`),children:[(0,L.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,L.jsx)(`span`,{className:`text-[12px] text-gray-800 font-medium hover:text-blue-600`,children:e.title})}),(0,L.jsx)(`td`,{className:`hidden sm:table-cell px-4 py-2.5`,children:(0,L.jsx)(`code`,{className:`text-[11px] text-gray-500`,children:e.model})}),(0,L.jsx)(`td`,{className:`px-4 py-2.5 text-right text-[12px] text-blue-600 tabular-nums`,children:k9(e.inputTokens)}),(0,L.jsx)(`td`,{className:`px-4 py-2.5 text-right text-[12px] text-green-600 tabular-nums`,children:k9(e.outputTokens)}),(0,L.jsx)(`td`,{className:`px-4 py-2.5 text-right text-[12px] text-gray-900 font-medium tabular-nums`,children:k9(t)}),(0,L.jsxs)(`td`,{className:`px-4 py-2.5 text-right text-[12px] text-purple-600 tabular-nums`,children:[k9(e.cacheReadInputTokens),` `,(0,L.jsxs)(`span`,{className:`text-[10px] text-purple-400`,children:[`(`,n,`%)`]})]}),(0,L.jsx)(`td`,{className:`hidden sm:table-cell px-4 py-2.5 text-right text-[11px] text-gray-400`,children:hce(e.lastActivity)})]},e.loopId)}),s.length===0&&(0,L.jsx)(`tr`,{children:(0,L.jsxs)(`td`,{colSpan:6,className:`px-4 py-8 text-center text-[12px] text-gray-400 italic`,children:[`No loops with token usage`,o?` in this range`:``]})})]})]})})]})}var xce=[{id:`today`,label:`Today`},{id:`7d`,label:`7 days`},{id:`30d`,label:`30 days`},{id:`all`,label:`All time`}],Sce=[{id:`models`,label:`By Model`,icon:(0,L.jsx)(Yt,{className:`h-3.5 w-3.5`})},{id:`daily`,label:`Daily`,icon:(0,L.jsx)(pt,{className:`h-3.5 w-3.5`})},{id:`loops`,label:`By Loop`,icon:(0,L.jsx)(un,{className:`h-3.5 w-3.5`})}];function Cce(){_i();let[e,t]=(0,F.useState)(`models`),[n,r]=(0,F.useState)(`30d`),[i,a]=(0,F.useState)({}),[o,s]=(0,F.useState)([]),[c,l]=(0,F.useState)(!0);return(0,F.useEffect)(()=>{l(!0),Promise.all([Pg().then(a),Fg().then(s)]).finally(()=>l(!1))},[]),c?(0,L.jsx)(`div`,{className:`h-full flex items-center justify-center bg-gray-50`,children:(0,L.jsx)(`div`,{className:`text-[13px] text-gray-400`,children:`loading token data…`})}):(0,L.jsxs)(`div`,{children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-1 mb-6`,children:[Sce.map(n=>(0,L.jsxs)(`button`,{type:`button`,onClick:()=>t(n.id),className:`inline-flex items-center gap-1.5 px-3 py-1.5 rounded text-[12px] font-medium transition-colors ${e===n.id?`bg-white border border-gray-200 text-gray-900 shadow-sm`:`text-gray-500 hover:text-gray-700`}`,children:[n.icon,n.label]},n.id)),(0,L.jsx)(`div`,{className:`flex-1`}),(0,L.jsx)(`div`,{className:`flex items-center gap-0.5`,children:xce.map(e=>(0,L.jsx)(`button`,{type:`button`,onClick:()=>r(e.id),className:`px-2 py-1 rounded text-[11px] font-medium transition-colors ${n===e.id?`bg-white border border-gray-200 text-gray-900 shadow-sm`:`text-gray-500 hover:text-gray-700`}`,children:e.label},e.id))})]}),e===`models`&&(0,L.jsx)(vce,{dailyUsage:i,timeRange:n}),e===`daily`&&(0,L.jsx)(yce,{dailyUsage:i,timeRange:n}),e===`loops`&&(0,L.jsx)(bce,{loopUsage:o,timeRange:n})]})}var P9=`w-full px-2.5 py-1.5 border border-gray-300 rounded text-[13px] outline-none bg-white focus:border-gray-900 focus:ring-1 focus:ring-gray-900 transition-colors disabled:bg-gray-50 disabled:text-gray-400`;function F9(e){return`${e.replace(/[^A-Za-z0-9]+/g,`_`).replace(/^_+|_+$/g,``).toUpperCase()||`PROVIDER`}_API_KEY`}var I9=[{id:`personal-repo`,label:`Personal Repo`,gated:!1,description:`Your private repo carrying credentials + dotfiles.`,icon:Gn},{id:`providers`,label:`AI Providers`,gated:!0,description:`Models, base URLs, API keys. Pick a default.`,icon:kt},{id:`claude-config`,label:`Claude Config`,gated:!0,description:`Compose your .claude/ tiers — plugins, MCP servers, settings per tier.`,icon:en},{id:`mise-config`,label:`Mise Config`,gated:!0,description:`Configure mise toolchain tools per tier — mise.toml for each tier.`,icon:qn},{id:`token-usage`,label:`Token Usage`,gated:!1,description:`Token consumption across models, loops, and time.`,icon:pt},{id:`api-tokens`,label:`API Tokens`,gated:!1,description:`Bearer tokens for external programs to drive your loops via the Loop API. See API docs below.`,icon:$t},{id:`admin-users`,label:`Users`,gated:!1,description:`Manage workspace members — activate, promote, remove.`,icon:Kn},{id:`admin-workspace`,label:`Workspace AI Providers`,gated:!1,description:`Shared workspace provider configuration.`,icon:qt},{id:`admin-serve`,label:`Share Artifact Serve`,gated:!1,description:`Public share domain and HTTPS settings.`,icon:An},{id:`admin-presets`,label:`Presets`,gated:!1,description:`Manage preset defaults — AI providers and Mise tool suggestions.`,icon:ut}];function wce(){let e=_i(),t=D_(),n=t.currentUser?.role===`admin`,{tab:r}=xi(),i=I9.some(e=>e.id===r)?r:`personal-repo`,[a,o]=(0,F.useState)(!0),[s,c]=(0,F.useState)(!1),[l,u]=(0,F.useState)(``),[d,f]=(0,F.useState)(null),[p,m]=(0,F.useState)({}),h=(0,F.useCallback)(async()=>{o(!0);let[e,t]=await Promise.all([bh(),kg()]);c(!!e&&!!e.personalRepo&&e.imported),u(!e||!e.personalRepo?`no personal repo configured`:e.imported?``:`personal repo not imported yet`),t&&(f(t.disk),m(t.refExists)),o(!1)},[]);(0,F.useEffect)(()=>{Dh().catch(()=>{}).finally(()=>{h()})},[h]),(0,F.useEffect)(()=>{!a&&!s&&I9.find(e=>e.id===i)?.gated&&!i.startsWith(`admin-`)&&e(`/settings/personal-repo`,{replace:!0})},[a,s,i,e]);let g=I9.find(e=>e.id===i)??I9[0],_=g.gated&&!s&&!i.startsWith(`admin-`),[v,y]=(0,F.useState)(``),b=I9.filter(e=>!(e.id.startsWith(`admin-`)&&!n)),x=b.filter(e=>!e.id.startsWith(`admin-`)),S=b.filter(e=>e.id.startsWith(`admin-`)),C=v.trim()===``?b:b.filter(e=>e.label.toLowerCase().includes(v.toLowerCase())||e.description.toLowerCase().includes(v.toLowerCase())||e.id.toLowerCase().includes(v.toLowerCase()));return(0,L.jsxs)(`div`,{className:`h-full overflow-hidden bg-gray-50 flex flex-col`,children:[(0,L.jsxs)(`header`,{className:`shrink-0 border-b border-gray-200 bg-white px-4 sm:px-6 h-12 hidden sm:flex items-center gap-3`,children:[(0,L.jsx)(`button`,{type:`button`,onClick:()=>e(-1),className:`w-8 h-8 flex items-center justify-center rounded text-gray-500 hover:text-gray-900 hover:bg-gray-100`,title:`back`,children:(0,L.jsx)(ot,{size:16})}),(0,L.jsx)(`h1`,{className:`text-[15px] font-semibold text-gray-900`,children:`Settings`}),(0,L.jsx)(`div`,{className:`flex-1`}),(0,L.jsxs)(`button`,{type:`button`,onClick:()=>e(`/context/personal?file=.loopat/config.json&edit=1`),className:`h-7 px-2.5 rounded text-xs border border-gray-200 hover:bg-gray-100 text-gray-700 flex items-center gap-1.5`,title:`open raw config.json in Context tab`,children:[(0,L.jsx)(Ft,{size:12}),(0,L.jsx)(`span`,{className:`hidden sm:inline`,children:`edit raw config.json`})]}),(0,L.jsxs)(`button`,{type:`button`,onClick:h,disabled:a,className:`h-7 px-2.5 rounded text-xs border border-gray-200 hover:bg-gray-100 text-gray-700 flex items-center gap-1.5 disabled:opacity-50`,title:`reload`,children:[(0,L.jsx)(Sn,{size:12,className:a?`animate-spin`:``}),(0,L.jsx)(`span`,{className:`hidden sm:inline`,children:`reload`})]})]}),(0,L.jsxs)(`div`,{className:`flex-1 min-h-0 flex flex-col sm:flex-row`,children:[(0,L.jsxs)(`nav`,{className:`sm:w-56 shrink-0 sm:border-r border-b sm:border-b-0 border-gray-200 bg-white flex flex-col`,children:[(0,L.jsx)(`div`,{className:`hidden sm:block px-3 py-3 border-b border-gray-100`,children:(0,L.jsxs)(`div`,{className:`relative`,children:[(0,L.jsx)(En,{size:12,className:`absolute left-2 top-1/2 -translate-y-1/2 text-gray-400`}),(0,L.jsx)(`input`,{value:v,onChange:e=>y(e.target.value),placeholder:`search settings`,className:`w-full pl-7 pr-2 py-1.5 text-[12px] border border-gray-200 rounded outline-none focus:border-gray-400 bg-gray-50 focus:bg-white`})]})}),(0,L.jsxs)(`ul`,{className:`flex sm:flex-col gap-0.5 sm:gap-0 p-2 sm:py-2 overflow-x-auto sm:overflow-x-visible`,children:[v.trim()?C.map(t=>{let n=t.id===i,r=t.gated&&!a&&!s;return(0,L.jsx)(`li`,{className:`shrink-0 sm:px-1`,children:(0,L.jsxs)(`button`,{type:`button`,onClick:()=>e(`/settings/${t.id}`),className:`w-full text-left px-2.5 py-1.5 rounded text-[13px] flex items-center gap-2 transition-colors whitespace-nowrap `+(n?`bg-gray-100 text-gray-900 font-medium`:`text-gray-600 hover:bg-gray-50 hover:text-gray-900`),children:[(0,L.jsx)(t.icon,{size:14,className:`shrink-0 ${n?`text-gray-600`:`text-gray-400`}`}),(0,L.jsx)(`span`,{className:`flex-1 truncate`,children:t.label}),r&&(0,L.jsx)(`span`,{title:`locked`,children:(0,L.jsx)(on,{size:11,className:`text-gray-400 shrink-0`})})]})},t.id)}):(0,L.jsxs)(L.Fragment,{children:[x.map(t=>{let n=t.id===i,r=t.gated&&!a&&!s;return(0,L.jsx)(`li`,{className:`shrink-0 sm:px-1`,children:(0,L.jsxs)(`button`,{type:`button`,onClick:()=>e(`/settings/${t.id}`),className:`w-full text-left px-2.5 py-1.5 rounded text-[13px] flex items-center gap-2 transition-colors whitespace-nowrap `+(n?`bg-gray-100 text-gray-900 font-medium`:`text-gray-600 hover:bg-gray-50 hover:text-gray-900`),children:[(0,L.jsx)(t.icon,{size:14,className:`shrink-0 ${n?`text-gray-600`:`text-gray-400`}`}),(0,L.jsx)(`span`,{className:`flex-1 truncate`,children:t.label}),r&&(0,L.jsx)(`span`,{title:`locked`,children:(0,L.jsx)(on,{size:11,className:`text-gray-400 shrink-0`})})]})},t.id)}),S.length>0&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`li`,{className:`px-3 pt-3 pb-1 text-[10px] font-semibold text-gray-400 uppercase tracking-wider`,children:`Admin Settings`}),S.map(t=>{let n=t.id===i;return(0,L.jsx)(`li`,{className:`shrink-0 sm:px-1`,children:(0,L.jsxs)(`button`,{type:`button`,onClick:()=>e(`/settings/${t.id}`),className:`w-full text-left px-2.5 py-1.5 rounded text-[13px] flex items-center gap-2 transition-colors whitespace-nowrap `+(n?`bg-gray-100 text-gray-900 font-medium`:`text-gray-600 hover:bg-gray-50 hover:text-gray-900`),children:[(0,L.jsx)(t.icon,{size:14,className:`shrink-0 ${n?`text-gray-600`:`text-gray-400`}`}),(0,L.jsx)(`span`,{className:`flex-1 truncate`,children:t.label})]})},t.id)})]})]}),C.length===0&&(0,L.jsx)(`li`,{className:`px-3 py-2 text-[11px] text-gray-400 italic`,children:`no match`})]})]}),(0,L.jsx)(`main`,{className:`flex-1 min-w-0 min-h-0 overflow-auto`,children:(0,L.jsx)(`div`,{className:`max-w-4xl mx-auto px-4 sm:px-6 py-5`,children:a&&!d?(0,L.jsx)(`div`,{className:`text-[13px] text-gray-400 italic py-12 text-center`,children:`loading…`}):(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`div`,{className:`mb-4`,children:[(0,L.jsxs)(`h2`,{className:`text-base font-semibold text-gray-900 flex items-center gap-2`,children:[(0,L.jsx)(g.icon,{size:18,className:`text-gray-400`}),g.label]}),(0,L.jsx)(`p`,{className:`text-xs text-gray-500 mt-0.5`,children:g.description})]}),_&&(0,L.jsxs)(`div`,{className:`mb-4 rounded-lg border border-amber-200 bg-amber-50 px-4 py-3 flex items-start gap-2`,children:[(0,L.jsx)(bt,{size:16,className:`text-amber-700 mt-0.5 shrink-0`}),(0,L.jsxs)(`div`,{className:`text-[13px] text-amber-900 flex-1`,children:[(0,L.jsx)(`div`,{className:`font-medium`,children:`Set up your personal repo first`}),(0,L.jsxs)(`div`,{className:`text-[12px] text-amber-800/90 mt-0.5`,children:[`These settings live in your personal repo. Complete setup in the `,(0,L.jsx)(`button`,{onClick:()=>e(`/settings/personal-repo`),className:`underline`,children:`Personal Repo`}),` tab; this section will unlock automatically.`,(0,L.jsxs)(`span`,{className:`text-amber-700/70`,children:[` (`,l,`)`]})]})]})]}),(0,L.jsxs)(`div`,{className:`relative`,children:[_&&(0,L.jsxs)(`div`,{className:`absolute inset-0 z-10 flex flex-col items-center justify-center gap-2 bg-white/60 backdrop-blur-[1px] rounded-lg`,children:[(0,L.jsx)(on,{size:24,className:`text-gray-300`}),(0,L.jsx)(`span`,{className:`text-[13px] text-gray-500 font-medium`,children:`Set up your personal repo first`})]}),(0,L.jsxs)(`div`,{className:_?`opacity-30`:``,children:[i===`personal-repo`&&(0,L.jsx)(`div`,{className:`rounded-lg border border-gray-200 bg-white p-5`,children:(0,L.jsx)(U7,{onDone:h})}),i===`providers`&&(0,L.jsx)(Tce,{disk:d,refExists:p,onChanged:h,disabled:_}),i===`claude-config`&&(0,L.jsx)(Cse,{disabled:_}),i===`mise-config`&&(0,L.jsx)($se,{disabled:_}),i===`token-usage`&&(0,L.jsx)(Cce,{}),i===`api-tokens`&&(0,L.jsx)(Ece,{}),i===`admin-users`&&(0,L.jsx)(`div`,{className:`rounded-lg border border-gray-200 bg-white p-5`,children:(0,L.jsx)(ise,{currentUserId:t.currentUser?.id??``})}),i===`admin-workspace`&&(0,L.jsx)(sse,{}),i===`admin-serve`&&(0,L.jsx)(`div`,{className:`rounded-lg border border-gray-200 bg-white p-5`,children:(0,L.jsx)(cse,{})}),i===`admin-presets`&&(0,L.jsx)(fce,{})]})]})]})})})]})]})}function Tce({disk:e,refExists:t,onChanged:n,disabled:r}){let[i,a]=(0,F.useState)(null),[o,s]=(0,F.useState)(!1),[c,l]=(0,F.useState)(null),[u,d]=(0,F.useState)(!1),[f,p]=(0,F.useState)(``),[m,h]=(0,F.useState)(!1),[g,_]=(0,F.useState)({}),[v,y]=(0,F.useState)({}),[b,x]=(0,F.useState)(null),[S,C]=(0,F.useState)(``),[w,T]=(0,F.useState)(null),[E,D]=(0,F.useState)(``),[O,k]=(0,F.useState)({}),[A,ee]=(0,F.useState)({}),[j,te]=(0,F.useState)([]);(0,F.useEffect)(()=>{Ig().then(e=>te(e.providerPresets)).catch(()=>{})},[]),(0,F.useEffect)(()=>{if(!e){a(null),d(!1);return}let n={default:``,providers:{}};for(let[r,i]of Object.entries(e.providers)){if(r===`default`){typeof i==`string`&&(n.default=i);continue}if(i&&typeof i==`object`){let e=i,a=t[`providers.${r}.apiKey`];n.providers[r]={models:e.models&&e.models.length>0?e.models.map(e=>({id:e.id,enabled:e.enabled!==!1})):e.model?[{id:e.model,enabled:!0}]:[],baseUrl:e.baseUrl??``,maxContextTokens:e.maxContextTokens?String(e.maxContextTokens):``,enabled:e.enabled!==!1,apiKeyNewValue:``,apiKeyStored:!!a?.exists}}}a(n)},[e,t]);let M=i?Object.keys(i.providers):[],ne=(e,t)=>{a(n=>!n||!n.providers[e]?n:{...n,providers:{...n.providers,[e]:{...n.providers[e],...t}}})},N=e=>{a(t=>{if(!t)return t;let{[e]:n,...r}=t.providers,i=t.default===e||t.default.startsWith(`${e}/`);return{...t,providers:r,default:i?``:t.default}})},re=(e,t,n)=>{a(r=>{if(!r||!r.providers[e])return r;let i=r.providers[e].models.map(e=>e.id===t?{...e,...n}:e);return{...r,providers:{...r.providers,[e]:{...r.providers[e],models:i}}}})},ie=(e,t)=>{a(n=>{if(!n||!n.providers[e])return n;let r=n.providers[e].models.map(e=>e.id===t?{...e,enabled:!e.enabled}:e);return{...n,providers:{...n.providers,[e]:{...n.providers[e],models:r}}}})},ae=(e,t)=>{a(n=>{if(!n||!n.providers[e])return n;let r=n.providers[e].models.filter(e=>e.id!==t),i=n.default===`${e}/${t}`;return{...n,default:i?``:n.default,providers:{...n.providers,[e]:{...n.providers[e],models:r}}}})},oe=e=>{let t=(g[e]??``).trim();t&&(a(n=>!n||!n.providers[e]||n.providers[e].models.some(e=>e.id===t)?n:{...n,providers:{...n.providers,[e]:{...n.providers[e],models:[...n.providers[e].models,{id:t,enabled:!0}]}}}),_(t=>({...t,[e]:``})),y(t=>({...t,[e]:!1})))},se=(e,t)=>{let n=E.trim();if(!n||n===t){T(null);return}a(r=>{if(!r||!r.providers[e]||r.providers[e].models.some(e=>e.id===n))return r;let i=r.providers[e].models.map(e=>e.id===t?{...e,id:n}:e),a=r.default===`${e}/${t}`?`${e}/${n}`:r.default;return{...r,default:a,providers:{...r.providers,[e]:{...r.providers[e],models:i}}}}),T(null)},ce=e=>{let t=S.trim();if(!t||t===e||t===`default`){x(null);return}a(n=>{if(!n||!n.providers[e]||n.providers[t])return n;let{[e]:r,...i}=n.providers,a=n.default;return n.default===e?a=t:n.default.startsWith(`${e}/`)&&(a=t+n.default.slice(e.length)),{...n,default:a,providers:{...i,[t]:r}}}),x(null)},le=()=>{let e=f.trim();if(e){if(e===`default`){l(`'default' is reserved`);return}a(t=>!t||t.providers[e]?t:{...t,providers:{...t.providers,[e]:{models:[],baseUrl:``,maxContextTokens:``,enabled:!1,apiKeyNewValue:``,apiKeyStored:!1}}}),p(``),h(!1),l(null)}};return i?(0,L.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[M.map(e=>{let t=i.providers[e],n=v[e]??!1,r=t.apiKeyStored||t.apiKeyNewValue.trim()!==``;return(0,L.jsxs)(`div`,{className:`bg-white border border-gray-200 rounded-lg overflow-hidden transition-shadow hover:shadow-sm`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-2.5 bg-gray-50/50 border-b border-gray-100`,children:[(0,L.jsxs)(`label`,{className:`flex items-center gap-2.5 flex-1 min-w-0 select-none`,children:[(0,L.jsx)(K7,{checked:t.enabled,onCheckedChange:t=>r?ne(e,{enabled:t}):void 0,disabled:!r,size:`sm`}),b===e?(0,L.jsx)(`input`,{autoFocus:!0,value:S,onChange:e=>C(e.target.value),onBlur:()=>ce(e),onKeyDown:t=>{t.key===`Enter`&&!t.nativeEvent.isComposing&&ce(e),t.key===`Escape`&&x(null)},className:lh(P9,`text-[13px] font-semibold flex-1 min-w-0`)}):(0,L.jsx)(`button`,{type:`button`,onClick:()=>{x(e),C(e)},className:`text-[13px] font-semibold truncate text-left hover:underline ${t.enabled?`text-gray-900`:`text-gray-400`}`,title:`click to rename`,children:e}),!t.enabled&&(0,L.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded-full bg-gray-100 text-gray-400 font-medium shrink-0`,children:`disabled`})]}),(0,L.jsx)(`button`,{type:`button`,onClick:()=>N(e),className:`text-[11px] text-gray-400 hover:text-red-500 transition-colors shrink-0`,children:`remove`})]}),(0,L.jsxs)(`div`,{className:`p-4`,children:[(0,L.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3 mb-3`,children:[(0,L.jsx)(L9,{label:`Base URL`,children:(0,L.jsx)(`input`,{value:t.baseUrl,onChange:t=>ne(e,{baseUrl:t.target.value}),placeholder:`https://api.example.com`,className:P9})}),(0,L.jsx)(L9,{label:`Max context tokens`,children:(0,L.jsx)(`input`,{type:`number`,value:t.maxContextTokens,onChange:t=>ne(e,{maxContextTokens:t.target.value}),placeholder:`auto`,className:P9})}),(0,L.jsx)(L9,{label:t.apiKeyStored?`API key (set — type to overwrite)`:`API key`,className:`sm:col-span-2`,children:(0,L.jsx)(`input`,{type:`password`,value:t.apiKeyNewValue,onChange:t=>ne(e,{apiKeyNewValue:t.target.value}),placeholder:t.apiKeyStored?`•••••• stored encrypted in vault`:`paste API key`,className:P9})})]}),(0,L.jsxs)(`div`,{className:`border-t border-gray-100 pt-3`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,L.jsxs)(`span`,{className:`text-[11px] font-semibold text-gray-400 uppercase tracking-wider`,children:[`Models (`,t.models.length,`)`]}),(0,L.jsxs)(`button`,{type:`button`,onClick:()=>y(t=>({...t,[e]:!n})),className:`text-[11px] text-gray-500 hover:text-gray-900 inline-flex items-center gap-1 transition-colors`,children:[(0,L.jsx)(bn,{size:11}),` add model`]})]}),n&&(0,L.jsxs)(`div`,{className:`flex items-center gap-1.5 mb-2`,children:[(0,L.jsx)(`input`,{autoFocus:!0,value:g[e]??``,onChange:t=>_(n=>({...n,[e]:t.target.value})),onKeyDown:t=>{t.key===`Enter`&&!t.nativeEvent.isComposing&&oe(e),t.key===`Escape`&&y(t=>({...t,[e]:!1}))},placeholder:`model ID (e.g. claude-sonnet-4-20250514)`,className:lh(P9,`flex-1 text-[11px]`)}),(0,L.jsx)(N_,{size:`xs`,onClick:()=>oe(e),children:`add`}),(0,L.jsx)(N_,{variant:`ghost`,size:`xs`,onClick:()=>y(t=>({...t,[e]:!1})),children:`cancel`})]}),t.models.length===0&&!n&&(0,L.jsx)(`div`,{className:`text-[11px] text-gray-400 italic py-2`,children:`no models — add one above`}),(0,L.jsx)(`div`,{className:`-mx-1`,children:t.models.map(n=>{let r=i.default===`${e}/${n.id}`,o=`${e}::${n.id}`,s=w===o,c=O[`${e}::${n.id}`],l=A[`${e}::${n.id}`];return(0,L.jsxs)(`div`,{className:`flex items-center gap-1.5 px-1 py-1.5 rounded group hover:bg-gray-50 transition-colors`,children:[(0,L.jsx)(`button`,{type:`button`,onClick:()=>a(t=>t&&{...t,default:r?``:`${e}/${n.id}`}),className:`shrink-0 text-[13px] leading-none transition-colors ${r?`text-amber-500`:`text-gray-200 hover:text-amber-400`}`,title:r?`current default model`:`set as default model`,children:`★`}),(0,L.jsx)(`label`,{className:`flex items-center shrink-0 cursor-pointer`,children:(0,L.jsx)(`input`,{type:`checkbox`,checked:n.enabled!==!1,onChange:()=>ie(e,n.id),className:`h-3.5 w-3.5 rounded border-gray-300 text-gray-900 accent-gray-900`})}),(0,L.jsxs)(`div`,{className:`flex-1 min-w-0 flex items-center gap-1`,children:[s?(0,L.jsx)(`input`,{autoFocus:!0,value:E,onChange:e=>D(e.target.value),onBlur:()=>se(e,n.id),onKeyDown:t=>{t.key===`Enter`&&!t.nativeEvent.isComposing&&se(e,n.id),t.key===`Escape`&&T(null)},className:lh(P9,`text-[11px] flex-1 min-w-0`)}):(0,L.jsx)(`code`,{className:`text-[12px] truncate cursor-pointer hover:bg-gray-100 px-0.5 rounded ${n.enabled===!1?`text-gray-300 line-through`:`text-gray-700`}`,onClick:()=>{T(o),D(n.id)},title:`click to edit model ID`,children:n.id}),n.enabled===!1&&(0,L.jsx)(`span`,{className:`text-[10px] text-gray-300 font-medium shrink-0`,children:`off`})]}),(0,L.jsx)(`input`,{type:`number`,value:n.maxContextTokens??``,onChange:t=>re(e,n.id,{maxContextTokens:t.target.value?Number(t.target.value):void 0}),placeholder:`auto`,className:`w-24 px-1.5 py-0.5 border border-gray-200 rounded text-[10px] outline-none focus:border-gray-400 shrink-0 ${n.maxContextTokens?``:`opacity-0 group-hover:opacity-100 transition-opacity`}`,title:`max context tokens (empty = auto)`}),(0,L.jsx)(`button`,{type:`button`,onClick:async()=>{let r=t.apiKeyNewValue.trim(),i=`${e}::${n.id}`;if(!r&&!t.apiKeyStored){k(e=>({...e,[i]:`error`})),ee(e=>({...e,[i]:`enter an API key first`})),setTimeout(()=>{k(e=>{let{[i]:t,...n}=e;return n}),ee(e=>{let{[i]:t,...n}=e;return n})},3e3);return}k(e=>({...e,[i]:`testing`})),ee(e=>({...e,[i]:``}));try{let a=r?await _g(t.baseUrl,r,n.id):await _g(t.baseUrl,``,n.id,e,`personal`);k(e=>({...e,[i]:a.ok?`ok`:`error`})),a.ok||ee(e=>({...e,[i]:a.error??`unknown error`}))}catch(e){k(e=>({...e,[i]:`error`})),ee(t=>({...t,[i]:e?.message??`connection failed`}))}setTimeout(()=>{k(e=>{let{[i]:t,...n}=e;return n}),ee(e=>{let{[i]:t,...n}=e;return n})},4e3)},disabled:c===`testing`||!t.apiKeyStored&&!t.apiKeyNewValue.trim(),className:`shrink-0 text-[10px] px-1 py-0 rounded transition-colors ${!t.apiKeyStored&&!t.apiKeyNewValue.trim()?`opacity-0 group-hover:opacity-100 text-gray-300`:c===`ok`?`bg-emerald-100 text-emerald-700`:c===`error`?`bg-red-100 text-red-700`:c===`testing`?`bg-gray-100 text-gray-400 animate-pulse`:`text-gray-400 hover:text-gray-700 opacity-0 group-hover:opacity-100`}`,title:l||(t.apiKeyNewValue.trim()||t.apiKeyStored?`test connection`:`enter an API key first`),children:c===`ok`?`OK`:c===`error`?`FAIL`:c===`testing`?`...`:`test`}),(0,L.jsx)(`button`,{type:`button`,onClick:()=>ae(e,n.id),className:`text-gray-300 hover:text-red-500 opacity-0 group-hover:opacity-100 transition-opacity shrink-0`,title:`remove model`,children:(0,L.jsx)(Bn,{size:11})})]},n.id)})})]})]})]},e)}),(0,L.jsx)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:j.filter(e=>!i.providers[e.name]).map(e=>(0,L.jsxs)(`button`,{type:`button`,onClick:()=>{a(t=>!t||t.providers[e.name]?t:{...t,providers:{...t.providers,[e.name]:{models:e.models.map(e=>({id:e,enabled:!0})),baseUrl:e.baseUrl,maxContextTokens:``,enabled:!1,apiKeyNewValue:``,apiKeyStored:!1}}})},className:`px-2 py-0.5 rounded border border-gray-200 bg-white text-[10px] text-gray-500 hover:text-gray-900 hover:border-gray-400 transition-colors`,title:`Add ${e.name} preset`,children:[`+ `,e.name]},e.name))}),m?(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(`input`,{autoFocus:!0,value:f,onChange:e=>p(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&le(),e.key===`Escape`&&h(!1)},placeholder:`provider name`,className:lh(P9,`flex-1`)}),(0,L.jsx)(N_,{size:`sm`,onClick:le,children:`add`}),(0,L.jsx)(N_,{variant:`ghost`,size:`sm`,onClick:()=>{h(!1),p(``)},children:`cancel`})]}):(0,L.jsxs)(`button`,{onClick:()=>h(!0),className:`self-start text-xs text-gray-500 hover:text-gray-900 inline-flex items-center gap-1`,children:[(0,L.jsx)(bn,{size:12}),` add custom provider`]}),(0,L.jsxs)(`div`,{className:`flex items-center justify-end gap-2 px-4 py-3 border-t border-gray-100`,children:[c&&(0,L.jsx)(`span`,{className:`text-xs text-red-600`,children:c}),u&&!c&&(0,L.jsxs)(`span`,{className:`text-xs text-emerald-700 flex items-center gap-1`,children:[(0,L.jsx)(mt,{size:12}),` saved`]}),(0,L.jsx)(N_,{size:`sm`,onClick:async()=>{if(!i)return;s(!0),l(null);for(let[e,t]of Object.entries(i.providers)){if(!t.apiKeyNewValue.trim())continue;let n=await jg(F9(e),t.apiKeyNewValue.trim());if(!n.ok){l(`apiKey write failed for "${e}": ${n.error}`),s(!1);return}}let e={};i.default&&(e.default=i.default);for(let[t,n]of Object.entries(i.providers)){let r=n.models.filter(e=>e.id.trim()).map(e=>({id:e.id.trim(),...e.enabled?{}:{enabled:!1},...e.maxContextTokens&&e.maxContextTokens>0?{maxContextTokens:e.maxContextTokens}:{}}));e[t]={baseUrl:n.baseUrl,apiKey:`\${${F9(t)}}`,...r.length>0?{models:r}:{},...n.maxContextTokens?{maxContextTokens:Number(n.maxContextTokens)}:{},...n.enabled?{}:{enabled:!1}}}let t=await Ag({providers:e});if(!t.ok){s(!1),l(t.error??`save failed`);return}let r=await Oh();s(!1),r.ok||l(r.conflict?`Saved locally, but it conflicts with the remote — your edit is kept, not lost. Resolve it in Settings → Personal repo (take remote, or in a loop).`:r.needsPull?`Saved locally — remote moved while pushing. Save again to retry.`:`Saved locally, but push to remote failed: ${r.error??`unknown`}`),d(!0),setTimeout(()=>d(!1),2500),n()},disabled:o||r,children:o?`saving…`:`save providers`})]})]}):(0,L.jsx)(`div`,{className:`text-[12px] text-gray-400 italic`,children:`no providers yet`})}function L9({label:e,children:t,className:n}){return(0,L.jsxs)(`label`,{className:`flex flex-col gap-1 ${n??``}`,children:[(0,L.jsx)(`span`,{className:`text-[11px] font-medium text-gray-500`,children:e}),t]})}function Ece(){let[e,t]=(0,F.useState)([]),[n,r]=(0,F.useState)(!0),[i,a]=(0,F.useState)(``),[o,s]=(0,F.useState)(!1),[c,l]=(0,F.useState)(null),[u,d]=(0,F.useState)(!1),[f,p]=(0,F.useState)(null),[m,h]=(0,F.useState)(null),g=(0,F.useCallback)(async()=>{r(!0),h(null),t(await S_()),r(!1)},[]);(0,F.useEffect)(()=>{g()},[g]);let _=async()=>{if(o)return;s(!0),h(null);let e=await C_(i.trim()||`default`);s(!1),e?(l(e.token),a(``),d(!1),g()):h(`Failed to create token`)},v=async e=>{h(null);let t=await w_(e);p(null),t?g():h(`Failed to revoke token`)};return(0,L.jsxs)(`div`,{className:`space-y-4`,children:[m&&(0,L.jsxs)(`div`,{className:`rounded-lg border border-red-200 bg-red-50 px-4 py-3 text-[12px] text-red-700 flex items-center gap-2`,children:[(0,L.jsx)(bt,{size:14}),` `,m]}),c&&(0,L.jsxs)(`div`,{className:`rounded-lg border border-emerald-200 bg-emerald-50 p-4`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,L.jsx)(mt,{size:14,className:`text-emerald-600`}),(0,L.jsx)(`span`,{className:`text-[13px] font-medium text-emerald-900`,children:`Token created — copy it now, it won't be shown again`})]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(`code`,{className:`flex-1 text-[12px] bg-white border border-emerald-200 rounded px-3 py-2 font-mono text-gray-800 select-all break-all`,children:c}),(0,L.jsxs)(`button`,{type:`button`,onClick:()=>{c&&navigator.clipboard.writeText(c).then(()=>{d(!0),setTimeout(()=>d(!1),2e3)})},className:`shrink-0 h-8 px-3 rounded text-xs border border-emerald-300 hover:bg-emerald-100 text-emerald-800 flex items-center gap-1.5`,children:[u?(0,L.jsx)(mt,{size:12}):(0,L.jsx)(Dt,{size:12}),u?`copied`:`copy`]})]}),(0,L.jsx)(`button`,{type:`button`,onClick:()=>l(null),className:`mt-2 text-[11px] text-emerald-700 hover:text-emerald-900 underline`,children:`dismiss`})]}),(0,L.jsxs)(`div`,{className:`rounded-lg border border-gray-200 bg-white px-4 py-3 flex items-center justify-between`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`h3`,{className:`text-[13px] font-medium text-gray-900`,children:`Loop API documentation`}),(0,L.jsx)(`p`,{className:`text-[11px] text-gray-500 mt-0.5`,children:`Interactive reference for the endpoints these tokens authenticate against.`})]}),(0,L.jsx)(`a`,{href:`/api/v1/docs`,target:`_blank`,rel:`noopener noreferrer`,className:`shrink-0 inline-flex items-center gap-1.5 h-8 px-3 rounded text-[12px] border border-gray-300 hover:bg-gray-50 text-gray-700`,children:`Open docs →`})]}),(0,L.jsxs)(`div`,{className:`rounded-lg border border-gray-200 bg-white`,children:[(0,L.jsxs)(`div`,{className:`px-4 py-3 border-b border-gray-100`,children:[(0,L.jsx)(`h3`,{className:`text-[13px] font-medium text-gray-900`,children:`Your tokens`}),(0,L.jsx)(`p`,{className:`text-[11px] text-gray-500 mt-0.5`,children:`External programs use these tokens to call loopat under your identity — your providers, API keys, and vault.`})]}),n?(0,L.jsx)(`div`,{className:`px-4 py-8 text-center text-[12px] text-gray-400 italic`,children:`loading…`}):e.length===0?(0,L.jsx)(`div`,{className:`px-4 py-8 text-center text-[12px] text-gray-400`,children:`No API tokens yet. Create one below.`}):(0,L.jsxs)(`table`,{className:`w-full text-[13px]`,children:[(0,L.jsx)(`thead`,{children:(0,L.jsxs)(`tr`,{className:`border-b border-gray-100 text-left text-[11px] text-gray-500 uppercase tracking-wider`,children:[(0,L.jsx)(`th`,{className:`px-4 py-2 font-medium`,children:`Label`}),(0,L.jsx)(`th`,{className:`px-4 py-2 font-medium`,children:`Token`}),(0,L.jsx)(`th`,{className:`px-4 py-2 font-medium`,children:`Created`}),(0,L.jsx)(`th`,{className:`px-4 py-2 font-medium w-10`})]})}),(0,L.jsx)(`tbody`,{children:e.map(e=>(0,L.jsxs)(`tr`,{className:`border-b border-gray-50 hover:bg-gray-50`,children:[(0,L.jsx)(`td`,{className:`px-4 py-2.5 text-gray-900`,children:e.label}),(0,L.jsx)(`td`,{className:`px-4 py-2.5 font-mono text-[12px] text-gray-500`,children:e.tokenId}),(0,L.jsx)(`td`,{className:`px-4 py-2.5 text-gray-500 text-[12px]`,children:new Date(e.createdAt).toLocaleDateString()}),(0,L.jsx)(`td`,{className:`px-4 py-2.5`,children:f===e.tokenId?(0,L.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,L.jsx)(`button`,{type:`button`,onClick:()=>v(e.tokenId),className:`text-[11px] text-red-600 hover:text-red-800 font-medium`,children:`confirm`}),(0,L.jsx)(`button`,{type:`button`,onClick:()=>p(null),className:`text-[11px] text-gray-400 hover:text-gray-600`,children:`cancel`})]}):(0,L.jsx)(`button`,{type:`button`,onClick:()=>p(e.tokenId),className:`w-7 h-7 flex items-center justify-center rounded text-gray-400 hover:text-red-600 hover:bg-red-50`,title:`revoke token`,children:(0,L.jsx)(Bn,{size:13})})})]},e.tokenId))})]})]}),(0,L.jsxs)(`div`,{className:`rounded-lg border border-gray-200 bg-white p-4`,children:[(0,L.jsx)(`h3`,{className:`text-[13px] font-medium text-gray-900 mb-2`,children:`Create new token`}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(`input`,{value:i,onChange:e=>a(e.target.value),placeholder:`label (e.g. dingtalk-bot)`,className:`flex-1 px-2.5 py-1.5 border border-gray-300 rounded text-[13px] outline-none bg-white focus:border-gray-900 focus:ring-1 focus:ring-gray-900`,onKeyDown:e=>e.key===`Enter`&&_()}),(0,L.jsxs)(`button`,{type:`button`,onClick:_,disabled:o,className:`h-8 px-3 rounded text-xs bg-gray-900 hover:bg-gray-800 text-white flex items-center gap-1.5 disabled:opacity-50`,children:[(0,L.jsx)(bn,{size:12}),o?`creating…`:`create token`]})]})]}),(0,L.jsx)(`div`,{className:`rounded-lg border border-gray-100 bg-gray-50 px-4 py-3`,children:(0,L.jsxs)(`p`,{className:`text-[11px] text-gray-500 leading-relaxed`,children:[(0,L.jsx)(`strong`,{className:`text-gray-700`,children:`Usage:`}),` pass the token as`,` `,(0,L.jsx)(`code`,{className:`bg-white border border-gray-200 rounded px-1 py-0.5 text-[10px]`,children:`Authorization: Bearer <token>`}),` `,`when calling`,` `,(0,L.jsx)(`code`,{className:`bg-white border border-gray-200 rounded px-1 py-0.5 text-[10px]`,children:`POST /api/runtime/v1/turn/stream`}),`. The request will run under your identity with your configured providers and API keys.`]})}),(0,L.jsx)(rse,{})]})}function Dce(){let e=_i(),t=D_().currentUser?.role===`admin`,[n,r]=(0,F.useState)(null),[i,a]=(0,F.useState)(!0),[o,s]=(0,F.useState)(!1),[c,l]=(0,F.useState)(!1),[u,d]=(0,F.useState)(``),[f,p]=(0,F.useState)(null),[m,h]=(0,F.useState)(``),g=(0,F.useCallback)(async()=>{let e=await yg();e?r(e):h(`forbidden or server unreachable`),a(!1)},[]);if((0,F.useEffect)(()=>{if(!t)return;g();let e=setInterval(g,5e3);return()=>clearInterval(e)},[t,g]),!t)return(0,L.jsxs)(`div`,{className:`h-full flex items-center justify-center text-sm text-gray-500`,children:[`admin only.\xA0`,(0,L.jsx)(`button`,{className:`underline`,onClick:()=>e(`/loop`),children:`back`})]});async function _(){s(!0),h(``);try{let e=await bg();e.ok||h(e.error??`check failed`),await g()}finally{s(!1)}}async function v(){if(n&&!(n.activity.activeLoops>0&&!confirm(`${n.activity.activeLoops} loop(s) and ${n.activity.activeUsers} user(s) are active.\n\nbun --hot will reload code in-place — most pulls don't disturb anyone. If the pull touches deps or schema, you'll need to ssh in and restart manually.\n\nContinue?`))){l(!0),h(``),d(``);try{let e=await xg();p(e.ok),e.ok?e.pulled?d(`pulled ${e.oldHead?.slice(0,7)} → ${e.newHead?.slice(0,7)}\n${e.message??``}`.trim()):d(`already up to date`):d(e.error??`pull failed`),await g()}finally{l(!1)}}}return(0,L.jsx)(`div`,{className:`h-full overflow-y-auto bg-gray-50`,children:(0,L.jsxs)(`div`,{className:`max-w-3xl mx-auto p-4 sm:p-6 flex flex-col gap-4`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(`button`,{onClick:()=>e(-1),className:`p-1 rounded hover:bg-gray-100 text-gray-500 hover:text-gray-700`,title:`back`,children:(0,L.jsx)(ot,{className:`w-4 h-4`})}),(0,L.jsx)(`h1`,{className:`text-lg font-semibold text-gray-900`,children:`Platform`}),(0,L.jsx)(`span`,{className:`text-xs text-gray-400 ml-auto`,children:`refreshes every 5s`})]}),i&&!n&&(0,L.jsx)(`div`,{className:`text-sm text-gray-400 py-8 text-center`,children:`loading…`}),m&&(0,L.jsx)(`div`,{className:`text-xs text-red-600 bg-red-50 border border-red-200 rounded px-2 py-1.5`,children:m}),n&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(R9,{icon:(0,L.jsx)(Gt,{className:`w-4 h-4`}),title:`Version`,children:(0,L.jsxs)(`div`,{className:`flex flex-col gap-1 text-sm`,children:[(0,L.jsxs)(`div`,{className:`text-gray-700`,children:[(0,L.jsx)(`span`,{className:`text-gray-400 mr-2`,children:`branch`}),(0,L.jsx)(`span`,{className:`font-mono`,children:n.version.branch}),(0,L.jsx)(`span`,{className:`text-gray-400 mx-2`,children:`·`}),(0,L.jsx)(`span`,{className:`text-gray-400 mr-1`,children:`commit`}),(0,L.jsx)(`span`,{className:`font-mono`,children:n.version.commit.slice(0,7)})]}),n.version.behindBy>0?(0,L.jsxs)(`div`,{className:`text-amber-700 text-xs`,children:[`behind by `,n.version.behindBy,` commit`,n.version.behindBy===1?``:`s`,` —`,` `,(0,L.jsx)(`span`,{className:`font-mono`,children:n.version.latestCommit?.slice(0,7)}),` `,`"`,n.version.latestMessage,`"`]}):(0,L.jsx)(`div`,{className:`text-xs text-emerald-700`,children:`up to date`}),(0,L.jsx)(`div`,{className:`mt-2`,children:(0,L.jsxs)(`button`,{onClick:_,disabled:o,className:`text-xs px-2.5 py-1 rounded border border-gray-300 hover:bg-gray-100 disabled:opacity-50 inline-flex items-center gap-1.5`,children:[(0,L.jsx)(Sn,{className:`w-3 h-3 ${o?`animate-spin`:``}`}),o?`checking…`:`Check for updates`]})})]})}),(0,L.jsxs)(R9,{icon:(0,L.jsx)(nt,{className:`w-4 h-4`}),title:`Activity`,children:[(0,L.jsxs)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-3 text-sm mb-3`,children:[(0,L.jsx)(z9,{label:`Active loops`,value:n.activity.activeLoops}),(0,L.jsx)(z9,{label:`Active users`,value:n.activity.activeUsers}),(0,L.jsx)(z9,{label:`Live WS`,value:n.activity.totalWs}),(0,L.jsx)(z9,{label:`SDK streaming`,value:n.activity.totalGenerating})]}),n.activity.loops.length===0?(0,L.jsx)(`div`,{className:`text-xs text-gray-400 text-center py-3`,children:`no active loops`}):(0,L.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,L.jsx)(`thead`,{className:`text-gray-400 border-b border-gray-200`,children:(0,L.jsxs)(`tr`,{children:[(0,L.jsx)(`th`,{className:`text-left font-normal py-1.5 pr-2`,children:`title`}),(0,L.jsx)(`th`,{className:`text-left font-normal py-1.5 pr-2`,children:`driver`}),(0,L.jsx)(`th`,{className:`text-right font-normal py-1.5 pr-2`,children:`WS`}),(0,L.jsx)(`th`,{className:`text-left font-normal py-1.5`,children:`state`})]})}),(0,L.jsx)(`tbody`,{children:n.activity.loops.map(e=>(0,L.jsxs)(`tr`,{className:`border-b border-gray-100 last:border-b-0`,children:[(0,L.jsx)(`td`,{className:`py-1.5 pr-2 truncate max-w-[260px]`,title:e.title,children:e.title}),(0,L.jsx)(`td`,{className:`py-1.5 pr-2 text-gray-600`,children:e.driver}),(0,L.jsx)(`td`,{className:`py-1.5 pr-2 text-right`,children:e.wsCount}),(0,L.jsx)(`td`,{className:`py-1.5`,children:e.generating?(0,L.jsx)(`span`,{className:`text-blue-600`,children:`streaming…`}):e.lastMsgAgeSec>=0&&e.lastMsgAgeSec<60?(0,L.jsxs)(`span`,{className:`text-emerald-600`,children:[`msg `,e.lastMsgAgeSec,`s ago`]}):(0,L.jsx)(`span`,{className:`text-gray-400`,children:`idle (attached)`})})]},e.id))})]})]}),(0,L.jsx)(R9,{icon:(0,L.jsx)(At,{className:`w-4 h-4`}),title:`Update`,children:(0,L.jsxs)(`div`,{className:`flex flex-col gap-2 text-sm`,children:[(0,L.jsx)(`button`,{onClick:v,disabled:c||n.version.behindBy===0,className:`self-start text-sm px-3 py-1.5 rounded text-white disabled:opacity-50 `+(n.activity.activeLoops>0?`bg-amber-600 hover:bg-amber-700`:`bg-gray-900 hover:bg-gray-700`),children:c?`pulling…`:n.version.behindBy===0?`Pull latest (nothing to pull)`:`Pull latest`}),n.activity.activeLoops>0&&n.version.behindBy>0&&(0,L.jsxs)(`div`,{className:`text-xs text-amber-700`,children:[n.activity.activeLoops,` loop(s) active — bun --hot reloads code in-place. Dep / schema changes need a manual restart.`]}),u&&(0,L.jsx)(`pre`,{className:`text-xs whitespace-pre-wrap rounded p-2 border `+(f?`bg-emerald-50 border-emerald-200 text-emerald-800`:`bg-red-50 border-red-200 text-red-800`),children:u})]})})]})]})})}function R9({icon:e,title:t,children:n}){return(0,L.jsxs)(`div`,{className:`bg-white border border-gray-200 rounded-lg p-4`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium text-gray-700 mb-3`,children:[(0,L.jsx)(`span`,{className:`text-gray-400`,children:e}),t]}),n]})}function z9({label:e,value:t}){return(0,L.jsxs)(`div`,{className:`flex flex-col`,children:[(0,L.jsx)(`span`,{className:`text-[10px] text-gray-400 uppercase tracking-wide`,children:e}),(0,L.jsx)(`span`,{className:`text-xl font-semibold text-gray-900 tabular-nums`,children:t})]})}function Oce({onClose:e}={}){let t=D_(),[n,r]=(0,F.useState)(`login`),[i,a]=(0,F.useState)(``),[o,s]=(0,F.useState)(``),[c,l]=(0,F.useState)(!1),[u,d]=(0,F.useState)(null),[f,p]=(0,F.useState)(null);return(0,L.jsx)(`div`,{className:e?`fixed inset-0 z-50 bg-black/30 flex items-center justify-center`:`h-full w-full flex items-center justify-center bg-gray-50`,onClick:e?()=>e():void 0,children:(0,L.jsxs)(`div`,{className:`w-full max-w-[420px] mx-4 bg-white rounded-md shadow-xl border border-gray-200 p-4 md:p-6`,onClick:e=>e.stopPropagation(),children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2 mb-5`,children:[(0,L.jsx)(`span`,{className:`text-xl leading-none`,children:`🧶`}),(0,L.jsx)(`span`,{className:`text-base font-semibold text-gray-900`,children:`loopat`}),e&&(0,L.jsx)(`button`,{type:`button`,onClick:e,className:`ml-auto text-gray-400 hover:text-gray-700 px-1`,"aria-label":`close`,children:`✕`})]}),(0,L.jsx)(`div`,{className:`flex border-b border-gray-200 mb-5`,children:[`login`,`register`].map(e=>(0,L.jsx)(`button`,{type:`button`,onClick:()=>{r(e),d(null),p(null)},className:n===e?`px-3 py-2 text-sm border-b-2 border-gray-900 text-gray-900 font-medium`:`px-3 py-2 text-sm text-gray-500 hover:text-gray-800`,children:e===`login`?`Login`:`Register`},e))}),(0,L.jsxs)(`form`,{onSubmit:async a=>{if(a.preventDefault(),!c){d(null),l(!0);try{if(n===`login`){let n=await t.login(i.trim().toLowerCase(),o);n.error?d(n.error):e&&e();return}let a=await t.register({username:i.trim().toLowerCase(),password:o});if(a.error){d(a.error);return}if(a.user&&a.user.status===`pending`){p(`账号 ${a.user.id} 已创建,等待管理员激活后即可登录。`),r(`login`),s(``);return}e&&e()}finally{l(!1)}}},className:`flex flex-col gap-4`,children:[(0,L.jsx)(B9,{label:`Username`,hint:`lowercase a-z 0-9 _ - · 1-32 chars`,children:(0,L.jsx)(`input`,{type:`text`,value:i,onChange:e=>a(e.target.value),placeholder:`simpx`,autoFocus:!0,autoComplete:`username`,className:`w-full px-2 py-1.5 text-sm border border-gray-300 rounded outline-none focus:border-gray-500`})}),(0,L.jsx)(B9,{label:`Password`,children:(0,L.jsx)(`input`,{type:`password`,value:o,onChange:e=>s(e.target.value),autoComplete:n===`login`?`current-password`:`new-password`,className:`w-full px-2 py-1.5 text-sm border border-gray-300 rounded outline-none focus:border-gray-500`})}),n===`register`&&(0,L.jsx)(`div`,{className:`text-[11px] text-gray-400 leading-relaxed`,children:`Just creates your account. Set up your personal repo afterwards in Settings → Personal Repo.`}),f&&!u&&(0,L.jsx)(`div`,{className:`text-xs text-amber-700 bg-amber-50 border border-amber-200 rounded px-2 py-1.5`,children:f}),u&&(0,L.jsx)(`div`,{className:`text-xs text-red-600 bg-red-50 border border-red-200 rounded px-2 py-1.5`,children:u}),(0,L.jsx)(`button`,{type:`submit`,disabled:c||!i||!o,className:`px-3 h-9 text-sm rounded bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-50`,children:c?n===`login`?`logging in…`:`registering…`:n===`login`?`Login`:`Register`})]})]})})}function B9({label:e,hint:t,children:n}){return(0,L.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,L.jsx)(`span`,{className:`text-xs text-gray-700 font-medium`,children:e}),n,t&&(0,L.jsx)(`span`,{className:`text-[11px] text-gray-400`,children:t})]})}var V9=`loopat:floating-dm-open`,H9=`loopat:floating-dm-conv`;function U9(e){let t=new Date(e),n=new Date,r=t.toDateString()===n.toDateString(),i=t.toTimeString().slice(0,5);return r?i:new Date(n.getTime()-864e5).toDateString()===t.toDateString()?`yesterday ${i}`:`${t.getMonth()+1}/${t.getDate()} ${i}`}function kce({me:e}){let t=_i(),n=f6(),[r,i]=(0,F.useState)(()=>localStorage.getItem(V9)===`1`),[a,o]=(0,F.useState)(()=>localStorage.getItem(H9)),[s,c]=(0,F.useState)(!1),[l,u]=(0,F.useState)([]),[d,f]=(0,F.useState)([]),[p,m]=(0,F.useState)([]),[h,g]=(0,F.useState)(``),[_,v]=(0,F.useState)(!1),y=(0,F.useRef)(null),b=(0,F.useMemo)(()=>l.filter(e=>e.kind===`dm`).sort((e,t)=>(t.lastMessageTs??0)-(e.lastMessageTs??0)),[l]),x=(0,F.useMemo)(()=>b.reduce((e,t)=>e+t.unread,0),[b]),S=(0,F.useMemo)(()=>b.find(e=>e.id===a)??null,[b,a]);(0,F.useEffect)(()=>{localStorage.setItem(V9,r?`1`:`0`)},[r]),(0,F.useEffect)(()=>{a?localStorage.setItem(H9,a):localStorage.removeItem(H9)},[a]);let C=(0,F.useCallback)(async()=>{u(await Jg())},[]);(0,F.useEffect)(()=>{C(),Yg().then(f)},[C]),(0,F.useEffect)(()=>{if(!a){m([]);return}let e=!1;return $g(a,{limit:100}).then(t=>{if(e)return;m(t);let n=t[t.length-1];n&&(n_(a,n.id).catch(()=>{}),u(e=>e.map(e=>e.id===a?{...e,unread:0}:e)),window.dispatchEvent(new CustomEvent(`loopat:chat-read`,{detail:{convId:a}})))}),()=>{e=!0}},[a]),(0,F.useEffect)(()=>{r&&S&&y.current?.scrollIntoView({behavior:`auto`})},[p,r,S]);let w=(0,F.useRef)(a);w.current=a;let{subscribe:T,unsubscribe:E}=P7((0,F.useCallback)(t=>{if(t.type===`message`){let n=t.message,r=n.convId===w.current;r&&n.parentId==null?(m(e=>e.some(e=>e.id===n.id)?e:[...e,{...n,replyCount:0,lastReplyTs:null}]),n_(n.convId,n.id).catch(()=>{}),window.dispatchEvent(new CustomEvent(`loopat:chat-read`,{detail:{convId:n.convId}}))):r&&n.parentId!=null?m(e=>e.map(e=>e.id===n.parentId?{...e,replyCount:e.replyCount+1,lastReplyTs:n.ts}:e)):n.author!==e&&u(e=>e.map(e=>e.id===n.convId?{...e,unread:e.unread+1,lastMessageTs:n.ts}:e))}else t.type===`conv_created`?u(e=>e.some(e=>e.id===t.conv.id)?e:[...e,t.conv]):t.type===`conv_deleted`&&(u(e=>e.filter(e=>e.id!==t.convId)),w.current===t.convId&&o(null))},[e]));(0,F.useEffect)(()=>{for(let e of b)T(e.id);return()=>{for(let e of b)E(e.id)}},[b,T,E]),(0,F.useEffect)(()=>{let e=e=>{let t=e.detail;t?.convId&&u(e=>e.map(e=>e.id===t.convId?{...e,unread:0}:e))};return window.addEventListener(`loopat:chat-read`,e),()=>window.removeEventListener(`loopat:chat-read`,e)},[]);let D=async()=>{if(!S||!h.trim()||_)return;let e=h.trim();g(``),v(!0);let t=await t_(S.id,e);if(v(!1),t.message){let e=t.message;m(t=>t.some(t=>t.id===e.id)?t:[...t,{...e,replyCount:0,lastReplyTs:null}])}else g(e)};return e?(0,L.jsxs)(L.Fragment,{children:[!r&&(0,L.jsxs)(`button`,{type:`button`,onClick:()=>i(!0),className:`fixed ${n?`bottom-24`:`bottom-20`} right-5 z-30 w-12 h-12 rounded-full flex items-center justify-center shadow-lg transition-colors `+(x>0?`bg-gray-700 text-white animate-pulse`:`bg-gray-700 text-white hover:bg-gray-500`),title:`direct messages`,children:[(0,L.jsx)(ln,{size:20}),x>0&&(0,L.jsx)(`span`,{className:`absolute -top-1 -right-1 min-w-[18px] h-[18px] px-1 rounded-full bg-red-500 text-white text-[10px] font-medium flex items-center justify-center`,children:x>99?`99+`:x})]}),r&&(0,L.jsxs)(`div`,{className:`fixed ${n?`bottom-24`:`bottom-20`} right-5 z-30 w-[22rem] max-w-[calc(100vw-2.5rem)] h-[32rem] max-h-[calc(100dvh-2.5rem)] bg-white rounded-lg shadow-2xl border border-gray-200 flex flex-col overflow-hidden`,children:[(0,L.jsxs)(`header`,{className:`h-10 shrink-0 border-b border-gray-200 px-2 flex items-center gap-1`,children:[S?(0,L.jsx)(`button`,{type:`button`,onClick:()=>o(null),className:`w-7 h-7 flex items-center justify-center rounded text-gray-500 hover:text-gray-900 hover:bg-gray-100`,title:`back to DMs`,children:(0,L.jsx)(ot,{size:14})}):(0,L.jsx)(`span`,{className:`px-2 text-[13px] font-medium text-gray-900`,children:`Direct messages`}),S&&(0,L.jsxs)(`div`,{className:`flex-1 min-w-0 flex items-center gap-1.5`,children:[(0,L.jsx)(`span`,{className:`text-gray-400 text-[13px]`,children:`@`}),(0,L.jsx)(`span`,{className:`text-[13px] font-medium text-gray-900 truncate`,children:S.peerUserId??`(unknown)`})]}),!S&&(0,L.jsx)(`div`,{className:`flex-1`}),!S&&(0,L.jsx)(`button`,{type:`button`,onClick:()=>c(!0),className:`w-7 h-7 flex items-center justify-center rounded text-gray-500 hover:text-gray-900 hover:bg-gray-100`,title:`new DM`,children:(0,L.jsx)(bn,{size:14})}),S&&(0,L.jsx)(`button`,{type:`button`,onClick:()=>{t(S?`/chat/${S.id}`:`/chat`),i(!1)},className:`w-7 h-7 flex items-center justify-center rounded text-gray-500 hover:text-gray-900 hover:bg-gray-100`,title:`open in chat tab`,children:(0,L.jsx)(Mt,{size:13})}),(0,L.jsx)(`button`,{type:`button`,onClick:()=>i(!1),className:`w-7 h-7 flex items-center justify-center rounded text-gray-500 hover:text-gray-900 hover:bg-gray-100`,title:`close`,children:(0,L.jsx)(Jn,{size:14})})]}),S?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-auto px-3 py-2 flex flex-col gap-2`,children:[p.length===0&&(0,L.jsx)(`div`,{className:`text-[12px] text-gray-400 italic py-4 text-center`,children:`no messages yet — say hi`}),p.map(t=>(0,L.jsx)(Ace,{message:t,isMe:t.author===e},t.id)),(0,L.jsx)(`div`,{ref:y})]}),(0,L.jsx)(`div`,{className:`px-2 pb-2 pt-1 shrink-0`,children:(0,L.jsxs)(`div`,{className:`rounded-xl border border-gray-200 bg-white p-1.5 flex items-end gap-1`,children:[(0,L.jsx)(`textarea`,{value:h,onChange:e=>g(e.target.value),onKeyDown:e=>{e.nativeEvent.isComposing||e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),D())},rows:1,placeholder:`message @${S.peerUserId??``}…`,className:`field-sizing-content flex-1 max-h-32 min-h-7 resize-none bg-transparent px-1.5 py-1 text-sm text-gray-900 outline-none placeholder:text-gray-400`}),(0,L.jsx)(`button`,{type:`button`,onClick:D,disabled:_||!h.trim(),className:`px-2.5 h-7 rounded bg-gray-900 text-white text-xs hover:bg-gray-700 disabled:opacity-40 shrink-0`,children:`send`})]})})]}):(0,L.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto`,children:b.length===0?(0,L.jsxs)(`div`,{className:`px-4 py-6 text-center text-[12px] text-gray-400`,children:[`no DMs yet`,(0,L.jsx)(`div`,{className:`mt-2`,children:(0,L.jsxs)(`button`,{type:`button`,onClick:()=>c(!0),className:`px-2 py-1 rounded border border-gray-200 text-[12px] text-gray-700 hover:bg-gray-50 inline-flex items-center gap-1`,children:[(0,L.jsx)(bn,{size:12}),(0,L.jsx)(`span`,{children:`new DM`})]})})]}):(0,L.jsx)(`ul`,{className:`py-1`,children:b.map(e=>(0,L.jsx)(`li`,{children:(0,L.jsxs)(`button`,{type:`button`,onClick:()=>o(e.id),className:`w-full px-3 py-2 flex items-center gap-2 text-left hover:bg-gray-50`,children:[(0,L.jsx)(`span`,{className:`w-7 h-7 rounded bg-gray-200 text-gray-900 text-[11px] font-medium flex items-center justify-center shrink-0`,children:(e.peerUserId??`?`).slice(0,1).toUpperCase()}),(0,L.jsxs)(`span`,{className:`flex-1 min-w-0 text-[13px] text-gray-900 truncate`,children:[`@`,e.peerUserId??`(unknown)`]}),e.unread>0&&(0,L.jsx)(`span`,{className:`text-[10px] font-medium px-1.5 rounded-full bg-red-500 text-white`,children:e.unread}),e.lastMessageTs&&e.unread===0&&(0,L.jsx)(`span`,{className:`text-[10px] text-gray-400`,children:U9(e.lastMessageTs)})]})},e.id))})})]}),s&&(0,L.jsx)(jce,{users:d,onClose:()=>c(!1),onPick:async e=>{let t=await Qg(e);t.conv?(c(!1),o(t.conv.id),C()):t.error&&alert(t.error)}})]}):null}function Ace({message:e,isMe:t}){return(0,L.jsxs)(`div`,{className:`flex gap-1.5 `+(t?`flex-row-reverse`:``),children:[(0,L.jsx)(`div`,{className:t?`w-6 h-6 rounded shrink-0 flex items-center justify-center text-[10px] font-medium bg-gray-900 text-white`:`w-6 h-6 rounded shrink-0 flex items-center justify-center text-[10px] font-medium bg-gray-200 text-gray-900`,title:e.author,children:e.author.slice(0,1).toUpperCase()}),(0,L.jsxs)(`div`,{className:`min-w-0 max-w-[80%]`,children:[(0,L.jsx)(`div`,{className:`text-[10px] text-gray-400 `+(t?`text-right`:``),children:U9(e.ts)}),(0,L.jsx)(`div`,{className:`text-[12.5px] whitespace-pre-wrap break-words leading-relaxed px-2 py-1 rounded-lg `+(t?`bg-gray-900 text-white`:`bg-gray-100 text-gray-900`),children:e.text})]})]})}function jce({users:e,onClose:t,onPick:n}){let[r,i]=(0,F.useState)(``),a=e.filter(e=>!e.isMe).filter(e=>e.id.toLowerCase().includes(r.toLowerCase()));return(0,L.jsx)(`div`,{className:`fixed inset-0 z-40 bg-black/30 flex items-center justify-center`,onClick:t,children:(0,L.jsxs)(`div`,{className:`bg-white rounded-md shadow-lg w-80 p-3 flex flex-col gap-2`,onClick:e=>e.stopPropagation(),children:[(0,L.jsx)(`div`,{className:`text-sm font-medium text-gray-900`,children:`New DM`}),(0,L.jsx)(`input`,{autoFocus:!0,value:r,onChange:e=>i(e.target.value),placeholder:`search users…`,className:`px-2 py-1.5 text-sm rounded border border-gray-200 outline-none focus:border-gray-400`}),(0,L.jsxs)(`div`,{className:`max-h-64 overflow-auto flex flex-col gap-0.5`,children:[a.map(e=>(0,L.jsxs)(`button`,{type:`button`,onClick:()=>n(e.id),className:`text-left px-2 py-1.5 text-sm rounded hover:bg-gray-100 flex items-center gap-2`,children:[(0,L.jsx)(`span`,{className:`w-6 h-6 rounded bg-gray-200 text-gray-900 text-[11px] flex items-center justify-center`,children:e.id.slice(0,1).toUpperCase()}),(0,L.jsx)(`span`,{children:e.id})]},e.id)),a.length===0&&(0,L.jsx)(`div`,{className:`text-xs text-gray-400 px-2 py-2`,children:`no users match`})]})]})})}var Mce=[{id:`loop`,label:`Loop`,icon:`⑂`,path:`/loop`},{id:`chat`,label:`Chat`,icon:null,path:`/chat`},{id:`context`,label:`Context`,icon:`⌘`,path:`/context`},{id:`me`,label:`Me`,icon:null,path:`/me`}];function Nce(e,t,n){return!!(e===`/`&&n===`loop`||n===`loop`&&e.startsWith(`/loop`)||n===`chat`&&e.startsWith(`/chat`)||n===`context`&&e.startsWith(`/context`)||n===`me`&&e===`/me`)}function Pce({tabId:e}){switch(e){case`loop`:return(0,L.jsx)(`span`,{className:`text-lg leading-none`,children:`⑂`});case`chat`:return(0,L.jsx)(ln,{size:18});case`context`:return(0,L.jsx)(`span`,{className:`text-lg leading-none`,children:`⌘`});case`me`:return(0,L.jsx)(Gn,{size:18});default:return null}}function Fce(){let e=f6(),t=_i(),{pathname:n}=pi();return e?(0,L.jsx)(`nav`,{className:`fixed bottom-0 left-0 right-0 z-50 h-14 bg-white border-t border-gray-200 flex items-center justify-around`,style:{paddingBottom:`env(safe-area-inset-bottom, 0px)`},children:Mce.map(e=>(0,L.jsxs)(`button`,{type:`button`,onClick:()=>t(e.path),className:`flex flex-col items-center justify-center gap-0.5 h-full flex-1 transition-colors `+(Nce(n,e.path,e.id)?`text-gray-900`:`text-gray-400 hover:text-gray-600`),children:[(0,L.jsx)(Pce,{tabId:e.id}),(0,L.jsx)(`span`,{className:`text-[10px] leading-none font-medium`,children:e.label})]},e.id))}):null}var W9=`loopat:setupPersonalRepoDismissed`;function G9(){try{return localStorage.getItem(W9)===`1`}catch{return!1}}function K9({onDismiss:e,hideSkip:t}){let n=_i();return(0,L.jsxs)(`div`,{className:`max-w-2xl mx-auto mt-12 px-6 py-8 rounded-lg border border-gray-200 bg-white shadow-sm`,children:[(0,L.jsx)(`div`,{className:`text-2xl mb-2`,children:`👋 欢迎来到 loopat`}),(0,L.jsxs)(`p`,{className:`text-sm text-gray-600 leading-relaxed mb-3`,children:[`在你开始之前,建议先配一个`,(0,L.jsx)(`b`,{children:`个人仓库`}),`——`]}),(0,L.jsxs)(`p`,{className:`text-sm text-gray-600 leading-relaxed mb-3`,children:[`loopat 一个反直觉的设计:服务器`,(0,L.jsx)(`b`,{children:`不存你的数据`}),`。你的 API key、ssh、token、 笔记、memory 全部存在你自己的 GitHub 私有仓库里,由你自己持有解密密钥。 这是 loopat 跟其他工具最大的不同。`]}),(0,L.jsx)(`p`,{className:`text-sm text-gray-600 leading-relaxed mb-5`,children:`配置 3 步,大约 2 分钟:创建一个空的私有仓库 → 把 loopat 的 deploy key 贴上去 → 把仓库 URL 填进来。配完后回到这个页面,AI 引导会自动接上。`}),(0,L.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,L.jsx)(`button`,{onClick:()=>n(`/settings/personal-repo`),className:`px-4 h-9 rounded text-sm bg-gray-900 text-white hover:bg-gray-700`,children:`去配置个人仓库 →`}),!t&&(0,L.jsx)(`button`,{onClick:()=>{try{localStorage.setItem(W9,`1`)}catch{}e()},className:`text-xs text-gray-500 hover:text-gray-700`,children:`跳过(先用 workspace 的 key)`})]}),(0,L.jsx)(`p`,{className:`mt-4 text-[11px] text-gray-400 leading-relaxed`,children:`跳过后这个提示就不再出现。但 loopat 的核心安全模型依赖你的个人仓库 —— 想用自己的凭据、记自己的 memory 时,从右上角 Settings → Personal Repo 随时可以补上。`})]})}function Ice(){let e=D_(),t=_i(),[n,r]=(0,F.useState)(null),[i,a]=(0,F.useState)(0);return(0,F.useEffect)(()=>{e.currentUser&&bh().then(r)},[e.currentUser,i]),e.loopsLoading?(0,L.jsx)(`div`,{className:`h-full w-full flex items-center justify-center`,children:(0,L.jsx)(`div`,{className:`text-sm text-gray-400`,children:`loading…`})}):e.currentUser&&n&&!n.imported&&!G9()?(0,L.jsx)(`div`,{className:`h-full w-full overflow-auto`,children:(0,L.jsx)(K9,{onDismiss:()=>a(e=>e+1),hideSkip:!1})}):e.loops.length===0?(0,L.jsxs)(`div`,{className:`h-full w-full flex flex-col items-center justify-center text-gray-500 gap-3`,children:[(0,L.jsx)(`div`,{className:`text-sm`,children:`no loops yet`}),e.currentUser?(0,L.jsx)(`button`,{onClick:()=>e.setNewLoopDialogOpen(!0),className:`px-3 h-8 rounded text-sm bg-gray-900 text-white hover:bg-gray-700`,children:`+ New Loop`}):(0,L.jsx)(`div`,{className:`text-xs text-gray-400`,children:`log in to create one`})]}):(0,L.jsx)(`div`,{className:`h-full w-full bg-white overflow-auto`,children:(0,L.jsx)(C8,{onSelect:e=>t(`/loop/${e}`)})})}function Lce(){let e=D_(),t=_i(),n=e.currentUser?.role===`admin`,[r,i]=(0,F.useState)([]),[a,o]=(0,F.useState)(!0),[s,c]=(0,F.useState)(!1),[l,u]=(0,F.useState)(!1),[d,f]=(0,F.useState)(``),p=async()=>{o(!0);try{i(await Jg())}catch{}finally{o(!1)}};(0,F.useEffect)(()=>{p()},[]);let m=r.filter(e=>e.kind===`channel`),h=r.filter(e=>e.kind===`dm`);return(0,L.jsx)(`div`,{className:`h-full w-full bg-white overflow-auto`,children:a?(0,L.jsx)(`div`,{className:`h-full flex items-center justify-center text-sm text-gray-400`,children:`loading…`}):(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(M7,{channels:m,dms:h,activeConvId:void 0,isAdmin:n,onSelectConv:e=>{t(`/chat/${e.id}`)},onNewChannel:()=>u(!0),onNewDm:()=>c(!0),onDeleteChannel:n?async e=>{confirm(`Delete this channel?`)&&(await Zg(e),await p())}:void 0}),l&&(0,L.jsx)(q9,{title:`New channel`,placeholder:`channel name`,onSubmit:e=>{u(!1),Xg(e).then(p)},onClose:()=>u(!1)}),s&&(0,L.jsx)(q9,{title:`New DM`,placeholder:`username`,value:d,onChange:f,onSubmit:async()=>{let e=d.trim();if(!e)return;let n=await Qg(e);n.conv?(c(!1),f(``),t(`/chat/${n.conv.id}`),await p()):n.error&&alert(n.error)},onClose:()=>{c(!1),f(``)}})]})})}function q9(e){let[t,n]=(0,F.useState)(e.value??``);return(0,L.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,onClick:e.onClose,children:[(0,L.jsx)(`div`,{className:`absolute inset-0 bg-black/30`}),(0,L.jsxs)(`div`,{className:`relative bg-white rounded-lg shadow-xl w-80 max-w-[90vw] p-4 flex flex-col gap-3`,onClick:e=>e.stopPropagation(),children:[(0,L.jsx)(`div`,{className:`text-sm font-medium text-gray-900`,children:e.title}),(0,L.jsx)(`input`,{type:`text`,autoFocus:!0,value:e.onChange?e.value??``:t,onChange:t=>{e.onChange?e.onChange(t.target.value):n(t.target.value)},onKeyDown:n=>{if(n.key===`Enter`){let n=e.onChange?e.value??``:t;n.trim()&&e.onSubmit(n.trim())}},placeholder:e.placeholder,className:`h-9 px-3 rounded border border-gray-300 text-sm focus:outline-none focus:border-gray-500`}),(0,L.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,L.jsx)(`button`,{onClick:e.onClose,className:`px-3 h-7 rounded text-xs text-gray-500 hover:bg-gray-100`,children:`cancel`}),(0,L.jsx)(`button`,{onClick:()=>{let n=e.onChange?e.value??``:t;n.trim()&&e.onSubmit(n.trim())},className:`px-3 h-7 rounded text-xs bg-gray-900 text-white hover:bg-gray-700`,children:`create`})]})]})]})}var J9=(0,F.createContext)({theme:`light`,toggle:()=>{}});function Y9(){return(0,F.useContext)(J9)}var X9=`loopat:theme`;function Z9(){try{let e=localStorage.getItem(X9);if(e===`dark`||e===`light`)return e}catch{}return window.matchMedia?.(`(prefers-color-scheme: dark)`).matches?`dark`:`light`}function Q9(e){let t=document.documentElement;e===`dark`?t.classList.add(`dark`):t.classList.remove(`dark`)}Q9(Z9());function Rce({children:e}){let[t,n]=(0,F.useState)(Z9);(0,F.useLayoutEffect)(()=>{Q9(t)},[t]);let r=(0,F.useCallback)(()=>{n(e=>{let t=e===`light`?`dark`:`light`;Q9(t);try{localStorage.setItem(X9,t)}catch{}return t})},[]);return(0,L.jsx)(J9.Provider,{value:{theme:t,toggle:r},children:e})}function zce(){let e=D_(),t=_i(),{theme:n,toggle:r}=Y9(),[i,a]=(0,F.useState)(null),o=e.currentUser,s=o?.role===`admin`;return(0,F.useEffect)(()=>{o&&bh().then(a)},[o]),o?(0,L.jsxs)(`div`,{className:`h-full w-full bg-white overflow-auto`,children:[(0,L.jsx)(`div`,{className:`px-5 pt-8 pb-4 border-b border-gray-100`,children:(0,L.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,L.jsx)(`div`,{className:`w-14 h-14 rounded-full bg-gray-900 text-white text-xl flex items-center justify-center font-medium`,children:(o.id[0]??`?`).toUpperCase()}),(0,L.jsxs)(`div`,{className:`min-w-0`,children:[(0,L.jsx)(`div`,{className:`text-base font-medium text-gray-900 truncate`,children:o.id}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5`,children:[(0,L.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-gray-100 text-gray-600 font-medium`,children:o.role}),(0,L.jsx)(`span`,{className:`text-xs text-gray-400`,children:o.status})]})]})]})}),(0,L.jsxs)(`div`,{className:`px-5 py-3 border-b border-gray-100`,children:[(0,L.jsx)(`div`,{className:`text-[11px] uppercase tracking-wide text-gray-400 font-medium mb-2`,children:`Personal Repo`}),i?(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(`span`,{className:`w-2 h-2 rounded-full ${i.imported?`bg-emerald-500`:`bg-yellow-500`}`}),(0,L.jsx)(`span`,{className:`text-sm text-gray-700`,children:i.imported?`connected`:`not configured`}),(0,L.jsx)(`button`,{onClick:()=>t(`/settings/personal-repo`),className:`ml-auto text-xs text-blue-600 hover:text-blue-800`,children:`configure →`})]}):(0,L.jsx)(`div`,{className:`text-sm text-gray-400`,children:`loading…`})]}),(0,L.jsxs)(`div`,{className:`px-5 py-3 border-b border-gray-100`,children:[(0,L.jsx)(`div`,{className:`text-[11px] uppercase tracking-wide text-gray-400 font-medium mb-1`,children:`Quick Links`}),(0,L.jsxs)(`div`,{className:`flex flex-col`,children:[(0,L.jsx)($9,{icon:(0,L.jsx)(kn,{size:16}),label:`Settings`,onClick:()=>t(`/settings`)}),(0,L.jsx)($9,{icon:(0,L.jsx)(Zt,{size:16}),label:`Focus / Kanban`,onClick:()=>t(`/kanban`)}),(0,L.jsx)($9,{icon:(0,L.jsx)(pt,{size:16}),label:`Token Usage`,onClick:()=>t(`/settings/token-usage`)}),(0,L.jsx)($9,{icon:(0,L.jsx)(Qt,{size:16}),label:`API Tokens`,onClick:()=>t(`/settings/api-tokens`)}),(0,L.jsx)($9,{icon:n===`dark`?(0,L.jsx)(In,{size:16}):(0,L.jsx)(pn,{size:16}),label:`Theme: ${n===`dark`?`Dark`:`Light`}`,onClick:r}),(0,L.jsx)($9,{icon:(0,L.jsx)(Xt,{size:16}),label:`About`,onClick:()=>window.dispatchEvent(new CustomEvent(`loopat:open-about`))})]})]}),s&&(0,L.jsxs)(`div`,{className:`px-5 py-3 border-b border-gray-100`,children:[(0,L.jsx)(`div`,{className:`text-[11px] uppercase tracking-wide text-gray-400 font-medium mb-1`,children:`Admin`}),(0,L.jsxs)(`div`,{className:`flex flex-col`,children:[(0,L.jsx)($9,{icon:(0,L.jsx)(On,{size:16}),label:`Platform`,onClick:()=>t(`/admin/system`)}),(0,L.jsx)($9,{icon:(0,L.jsx)(jn,{size:16}),label:`Users`,onClick:()=>t(`/settings/admin-users`)})]})]}),(0,L.jsx)(`div`,{className:`px-5 py-3`,children:(0,L.jsxs)(`button`,{onClick:()=>{e.logout(),t(`/loop`)},className:`flex items-center gap-3 w-full px-2 py-2 rounded text-sm text-red-600 hover:bg-red-50`,children:[(0,L.jsx)(sn,{size:16}),(0,L.jsx)(`span`,{children:`Logout`})]})})]}):(0,L.jsx)(`div`,{className:`h-full w-full flex items-center justify-center text-sm text-gray-400`,children:`not logged in`})}function $9(e){return(0,L.jsxs)(`button`,{type:`button`,onClick:e.onClick,className:`flex items-center gap-3 px-2 py-2.5 rounded text-sm text-gray-700 hover:bg-gray-50 w-full text-left`,children:[(0,L.jsx)(`span`,{className:`text-gray-400 w-5 flex items-center justify-center`,children:e.icon}),(0,L.jsx)(`span`,{children:e.label})]})}function Bce({form:e,onAdvance:t}){let[n,r]=(0,F.useState)({}),[i,a]=(0,F.useState)(!1),[o,s]=(0,F.useState)(``),c=e.fields.filter(e=>(n[e.name]??``).trim().length>0).length,l=e.require===`any`?c>=1:c===e.fields.length;return(0,L.jsxs)(`div`,{className:`max-w-2xl mx-auto mt-12 px-6 py-8 rounded-lg border border-gray-200 bg-white shadow-sm`,children:[(0,L.jsx)(`div`,{className:`text-2xl mb-2`,children:e.title}),e.description&&(0,L.jsx)(`p`,{className:`text-sm text-gray-600 leading-relaxed mb-5`,children:e.description}),(0,L.jsx)(`div`,{className:`flex flex-col gap-4`,children:e.fields.map(e=>(0,L.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,L.jsxs)(`div`,{className:`flex items-baseline justify-between`,children:[(0,L.jsx)(`label`,{className:`text-sm font-medium text-gray-800`,children:e.label}),e.help&&(0,L.jsx)(`a`,{href:e.help,target:`_blank`,rel:`noreferrer`,className:`text-xs text-blue-600 hover:text-blue-800`,children:`获取 →`})]}),(0,L.jsx)(`input`,{type:e.type===`text`?`text`:`password`,autoComplete:`off`,spellCheck:!1,placeholder:e.placeholder??e.label,value:n[e.name]??``,onChange:t=>r(n=>({...n,[e.name]:t.target.value})),className:`h-9 px-3 rounded border border-gray-300 text-sm font-mono focus:outline-none focus:border-gray-500`})]},e.name))}),o&&(0,L.jsx)(`p`,{className:`mt-3 text-sm text-red-600`,children:o}),(0,L.jsxs)(`div`,{className:`mt-6 flex items-center gap-3`,children:[(0,L.jsx)(`button`,{onClick:async()=>{a(!0),s(``);try{let r={};for(let t of e.fields){let e=(n[t.name]??``).trim();e&&(r[t.name]=e)}let i=await Sh(r);if(`error`in i){s(i.error);return}t(i)}finally{a(!1)}},disabled:!l||i,className:`px-4 h-9 rounded text-sm bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-40 disabled:cursor-not-allowed`,children:i?`处理中…`:e.submitLabel??`继续 →`}),e.require===`any`&&e.fields.length>1&&(0,L.jsx)(`span`,{className:`text-xs text-gray-400`,children:`至少填一个`})]})]})}function Vce({show:e,onAdvance:t}){let[n,r]=(0,F.useState)(!1),[i,a]=(0,F.useState)(null);return(0,L.jsxs)(`div`,{className:`max-w-2xl mx-auto mt-12 px-6 py-8 rounded-lg border border-gray-200 bg-white shadow-sm`,children:[(0,L.jsxs)(`div`,{className:`text-2xl mb-2`,children:[`🔐 `,e.title]}),e.description&&(0,L.jsx)(`p`,{className:`text-sm text-gray-600 leading-relaxed mb-4 whitespace-pre-line`,children:e.description}),e.values&&e.values.length>0&&(0,L.jsx)(`div`,{className:`flex flex-col gap-2 mb-4`,children:e.values.map(e=>(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`div`,{className:`text-[11px] text-gray-500 mb-1`,children:e.label}),(0,L.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,L.jsx)(`code`,{className:`flex-1 min-w-0 break-all bg-gray-50 border border-gray-200 rounded px-2 py-1.5 text-[10px] font-mono`,children:e.value}),(0,L.jsx)(`button`,{onClick:()=>{navigator.clipboard.writeText(e.value),a(e.label),setTimeout(()=>a(null),1500)},className:`shrink-0 text-[11px] text-gray-500 hover:text-gray-800 px-1.5 py-1`,children:i===e.label?`copied`:`copy`})]})]},e.label))}),e.help&&e.help.length>0&&(0,L.jsx)(`div`,{className:`flex flex-wrap gap-3 mb-5`,children:e.help.map(e=>(0,L.jsxs)(`a`,{href:e.url,target:`_blank`,rel:`noreferrer`,className:`text-xs text-blue-600 hover:text-blue-800`,children:[e.label,` →`]},e.url))}),(0,L.jsx)(`div`,{className:`flex items-center gap-3`,children:(0,L.jsx)(`button`,{onClick:async()=>{r(!0);let e=await xh();r(!1),e&&t(e)},disabled:n,className:`px-4 h-9 rounded text-sm bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-40`,children:n?`检查中…`:`我已配置好,重新检查`})})]})}async function Hce(e){try{if(navigator.clipboard&&window.isSecureContext)return await navigator.clipboard.writeText(e),!0}catch{}try{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.left=`-9999px`,document.body.appendChild(t),t.focus(),t.select();let n=document.execCommand(`copy`);return document.body.removeChild(t),n}catch{return!1}}function Uce({show:e,onAdvance:t}){let[n,r]=(0,F.useState)(null),[i,a]=(0,F.useState)(null),[o,s]=(0,F.useState)(``),[c,l]=(0,F.useState)(!1),[u,d]=(0,F.useState)(!1),f=(0,F.useRef)(null),p=async()=>{s(``);let e=await Ch();if(`error`in e){s(e.error);return}r(e),l(!0),m(e.device_code,e.interval)},m=(e,t)=>{f.current=window.setTimeout(async()=>{let n=await wh(e);if(n.status===`ok`){l(!1),a(n.token);return}if(n.status===`error`){l(!1),s(n.error);return}m(e,n.status===`slow_down`?t+5:t)},t*1e3)};return(0,F.useEffect)(()=>()=>{f.current&&clearTimeout(f.current)},[]),i?(0,L.jsxs)(`div`,{className:`max-w-2xl mx-auto mt-12 px-6 py-8 rounded-lg border border-gray-200 bg-white shadow-sm`,children:[(0,L.jsx)(`div`,{className:`text-2xl mb-4`,children:`选择个人仓库`}),(0,L.jsx)(U7,{initialToken:i,onDone:()=>xh().then(e=>e&&t(e))})]}):(0,L.jsxs)(`div`,{className:`max-w-2xl mx-auto mt-12 px-6 py-8 rounded-lg border border-gray-200 bg-white shadow-sm`,children:[(0,L.jsx)(`div`,{className:`text-2xl mb-2`,children:e.title}),e.description&&(0,L.jsx)(`p`,{className:`text-sm text-gray-600 leading-relaxed mb-5`,children:e.description}),n?(0,L.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,L.jsx)(`p`,{className:`text-sm text-gray-600`,children:`1. 记下/复制这个码:`}),(0,L.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,L.jsx)(`code`,{className:`text-2xl font-mono tracking-widest bg-gray-50 border border-gray-200 rounded px-4 py-2`,children:n.user_code}),(0,L.jsx)(`button`,{onClick:async()=>{await Hce(n.user_code)&&(d(!0),setTimeout(()=>d(!1),1500))},className:`text-xs text-gray-500 hover:text-gray-800`,children:u?`已复制`:`复制`})]}),(0,L.jsxs)(`p`,{className:`text-sm text-gray-600`,children:[`2. 打开 GitHub 输码授权,完成后`,(0,L.jsx)(`b`,{children:`回到本标签页`}),`,会自动继续:`]}),(0,L.jsx)(`a`,{href:n.verification_uri,target:`_blank`,rel:`noreferrer`,className:`w-fit px-4 h-9 inline-flex items-center rounded text-sm bg-gray-900 text-white hover:bg-gray-700`,children:`打开 GitHub 授权 →`}),c&&(0,L.jsx)(`p`,{className:`text-xs text-gray-400`,children:`⏳ 等待授权…授权后回到这里,会自动让你选个人仓库,别关页面。`})]}):(0,L.jsx)(`button`,{onClick:p,className:`px-4 h-9 rounded text-sm bg-gray-900 text-white hover:bg-gray-700`,children:`用 GitHub 登录 →`}),o&&(0,L.jsx)(`p`,{className:`mt-3 text-sm text-red-600`,children:o})]})}function Wce(e,t,n){let[r,i]=(0,F.useState)({}),a=(0,F.useRef)(null);(0,F.useEffect)(()=>{if(!t)return;let e=!1,r=async()=>{let t=await Jg();if(e)return;let n={};for(let e of t)n[e.id]=e.unread;i(n)},o=t=>{let r=location.protocol===`https:`?`wss:`:`ws:`,o=new WebSocket(`${r}//${location.host}/ws/chat`);a.current=o,o.onopen=()=>{for(let e of t)o.send(JSON.stringify({type:`subscribe`,convId:e}))},o.onmessage=e=>{try{let t=JSON.parse(e.data);t.type===`message`?t.message.author!==n&&i(e=>({...e,[t.message.convId]:(e[t.message.convId]??0)+1})):t.type===`conv_created`&&o.send(JSON.stringify({type:`subscribe`,convId:t.conv.id}))}catch{}},o.onclose=()=>{e||setTimeout(()=>{e||s()},3e3)},o.onerror=()=>{try{o.close()}catch{}}},s=async()=>{let t=await Jg();if(e)return;let n={};for(let e of t)n[e.id]=e.unread;i(n),o(t.map(e=>e.id))};s();let c=e=>{let t=e.detail;t?.convId&&i(e=>e[t.convId]===0?e:{...e,[t.convId]:0})},l=()=>{r().catch(()=>{})};return window.addEventListener(`loopat:chat-read`,c),window.addEventListener(`focus`,l),()=>{e=!0,window.removeEventListener(`loopat:chat-read`,c),window.removeEventListener(`focus`,l);try{a.current?.close()}catch{}a.current=null}},[t,n]),(0,F.useEffect)(()=>{if(!t)return;let n=0;for(let e in r)n+=r[e];let i=`${e} · loopat`;document.title=n>0?`(${n}) ${i}`:i},[r,e,t])}var Gce=[{id:`loop`,label:`Loop`,icon:`⑂`},{id:`kanban`,label:`Focus`,icon:`◎`},{id:`context`,label:`Context`,icon:`⌘`},{id:`chat`,label:`Chat`,icon:(0,L.jsx)(ln,{size:14})}];function Kce(){let e=T_();return(0,L.jsx)(E_.Provider,{value:e,children:e.authLoading?null:(0,L.jsx)(qce,{ws:e})})}function qce({ws:e}){let t=_i(),n=pi(),r=f6(),[i,a]=(0,F.useState)(`loopat`),[o,s]=(0,F.useState)(!1),[c,l]=(0,F.useState)(!1),[u,d]=(0,F.useState)(!1),[f,p]=(0,F.useState)(``),[m,h]=(0,F.useState)(``),{theme:g,toggle:_}=Y9(),v=e.currentUser?.id??``,y=e.currentUser?.role===`admin`,b=!!e.currentUser,x=mi(`/loop/:id`),S=!!x,C=n.pathname.startsWith(`/chat`),w=!!mi(`/chat/:convId`),T=n.pathname.startsWith(`/settings`),E=!b&&S,D=r&&!E&&b&&!S&&!w,O=S?e.loops.find(e=>e.id===x?.params.id)?.title??`Loop`:w?`Chat`:null;(0,F.useEffect)(()=>{E||hh().then(e=>{e&&(a(e),document.title=`${e} · loopat`)})},[E]),Wce(i,b&&!E,v);let k=`loopat:version-dismissed`;(0,F.useEffect)(()=>{let e=e=>{let t=e.detail?.commit;if(t){try{if(JSON.parse(localStorage.getItem(k)||`[]`).includes(t))return}catch{}p(t),h(new Date(Sg().time).toLocaleString()),d(!0)}};return window.addEventListener(`loopat:version-mismatch`,e),()=>window.removeEventListener(`loopat:version-mismatch`,e)},[]),(0,F.useEffect)(()=>{let e=()=>l(!0);return window.addEventListener(`loopat:open-about`,e),()=>window.removeEventListener(`loopat:open-about`,e)},[]),(0,F.useEffect)(()=>{if(E)return;let e=Sg();vg().then(t=>{console.log(`%cloopat %cserver:%c ${t.branch}@${t.commit.slice(0,7)} %cbuild:%c ${e.commit.slice(0,7)} @ ${e.time}`,`font-weight:bold`,`color:#666`,`color:#61afef`,`color:#666`,`color:#98c379`)})},[E]);let[A,ee]=(0,F.useState)(null);return(0,F.useEffect)(()=>{if(!b||E){ee(null);return}xh().then(ee)},[b,E]),(0,F.useEffect)(()=>{if(!b||E||!A||A.done||!A.gated||A.show.kind!==`route`)return;let e=setInterval(()=>{xh().then(ee)},3e3);return()=>clearInterval(e)},[b,E,A]),E?(0,L.jsx)(`div`,{className:`h-full w-full bg-white text-gray-900`,children:(0,L.jsx)(Ki,{})}):b?(0,L.jsxs)(`div`,{className:`h-full w-full flex flex-col bg-gray-50 text-gray-900`,children:[(0,L.jsxs)(`header`,{className:`h-12 shrink-0 border-b border-gray-200 bg-white flex items-center px-2 md:px-4 gap-2 md:gap-4 relative`,children:[(0,L.jsxs)(`div`,{className:`hidden md:flex items-center gap-2 px-1 md:px-2 h-8 shrink-0 cursor-pointer`,title:`workspace: ${i}`,onClick:()=>{window.location.href=`/`},children:[(0,L.jsx)(`span`,{className:`text-lg leading-none`,children:`🧶`}),(0,L.jsx)(`span`,{className:`text-sm text-gray-900 font-medium`,children:i})]}),r&&(S||w||T)&&(0,L.jsx)(`button`,{type:`button`,onClick:()=>{t(S?`/loop`:w?`/chat`:-1)},className:`flex items-center gap-1 px-1 h-8 shrink-0 text-gray-600 hover:text-gray-900`,"aria-label":`back`,children:(0,L.jsx)(ot,{size:18})}),r&&!E&&b&&(0,L.jsx)(`div`,{className:`absolute left-1/2 -translate-x-1/2 pointer-events-none truncate max-w-[55vw]`,children:T?(0,L.jsx)(`span`,{className:`text-sm font-medium text-gray-700`,children:`Settings`}):O?(0,L.jsx)(`span`,{className:`text-sm font-medium text-gray-700`,children:O}):(0,L.jsx)(`span`,{className:`text-lg leading-none`,children:`🧶`})}),(0,L.jsx)(`nav`,{className:`hidden md:flex items-center gap-0.5 md:gap-1`,children:Gce.map(e=>(0,L.jsxs)(Ha,{to:`/${e.id}`,className:({isActive:e})=>e?`px-2 md:px-3 h-8 rounded text-sm bg-gray-900 text-white flex items-center gap-1.5`:`px-2 md:px-3 h-8 rounded text-sm text-gray-600 hover:bg-gray-100 flex items-center gap-1.5`,children:[(0,L.jsx)(`span`,{className:`opacity-70`,children:e.icon}),(0,L.jsx)(`span`,{className:`hidden md:inline`,children:e.label})]},e.id))}),(0,L.jsx)(`div`,{className:`flex-1`}),(0,L.jsxs)(`button`,{type:`button`,onClick:()=>e.setNewLoopDialogOpen(!0),className:`flex items-center gap-1 md:gap-1.5 px-2 md:px-3 h-8 rounded text-sm bg-gray-900 text-white hover:bg-gray-700`,title:`create new loop`,children:[(0,L.jsx)(`span`,{className:`text-base leading-none`,children:`+`}),(0,L.jsx)(`span`,{className:`hidden md:inline`,children:`New Loop`})]}),(0,L.jsx)(`button`,{type:`button`,onClick:_,className:`hidden md:flex items-center justify-center w-8 h-8 rounded text-gray-400 hover:text-gray-600 hover:bg-gray-100 transition-colors`,title:g===`dark`?`Switch to light mode`:`Switch to dark mode`,children:g===`dark`?(0,L.jsx)(In,{size:16}):(0,L.jsx)(pn,{size:16})}),(0,L.jsxs)(`div`,{className:`relative`,children:[(0,L.jsxs)(`button`,{type:`button`,onClick:()=>s(e=>!e),className:`flex items-center gap-1 md:gap-2 px-1 md:px-2 h-8 rounded hover:bg-gray-100`,title:`account`,children:[(0,L.jsx)(`span`,{className:`w-6 h-6 rounded-full bg-gray-900 text-white text-xs flex items-center justify-center`,children:v[0]?.toUpperCase()??`?`}),(0,L.jsx)(`span`,{className:`hidden md:inline text-sm text-gray-700`,children:v}),(0,L.jsx)(`span`,{className:`text-gray-400 text-xs`,children:`▾`})]}),o&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>s(!1)}),(0,L.jsxs)(`div`,{className:`absolute right-0 top-full mt-1 z-20 w-40 bg-white border border-gray-200 rounded shadow-md py-1`,children:[(0,L.jsx)(`button`,{type:`button`,onClick:()=>{s(!1),t(`/settings`)},className:`w-full text-left px-3 py-1.5 text-sm text-gray-700 hover:bg-gray-100`,children:`Settings`}),y&&(0,L.jsx)(`button`,{type:`button`,onClick:()=>{s(!1),t(`/admin/system`)},className:`w-full text-left px-3 py-1.5 text-sm text-gray-700 hover:bg-gray-100`,title:`server version + activity + pull latest code`,children:`Platform`}),y&&(0,L.jsx)(`button`,{type:`button`,onClick:async()=>{s(!1);try{t(`/loop/${(await e.createLoop({title:`cross-loop distill`,mountAllLoops:!0,knowledgeRw:!0})).id}`)}catch(e){alert(e?.message??`create failed`)}},className:`w-full text-left px-3 py-1.5 text-sm text-gray-700 hover:bg-gray-100`,title:`New loop with /loopat/loops/ mounted read-only — read every loop's chat/workdir for distill`,children:`Cross-loop distill`}),(0,L.jsx)(`button`,{type:`button`,onClick:()=>{s(!1),l(!0)},className:`w-full text-left px-3 py-1.5 text-sm text-gray-700 hover:bg-gray-100`,children:`About`}),(0,L.jsx)(`button`,{type:`button`,onClick:async()=>{s(!1),await e.logout(),t(`/loop`)},className:`w-full text-left px-3 py-1.5 text-sm text-gray-700 hover:bg-gray-100`,children:`Logout`})]})]})]})]}),u&&(0,L.jsxs)(`div`,{className:`shrink-0 bg-gradient-to-r from-blue-50 to-indigo-50 border-b border-blue-200 flex items-center px-4 py-2.5 gap-2.5`,children:[(0,L.jsx)(Sn,{className:`w-4 h-4 text-blue-500 shrink-0`}),(0,L.jsxs)(`span`,{className:`text-sm text-blue-700`,children:[`New version available`,(0,L.jsxs)(`span`,{className:`text-blue-400 ml-1 text-xs`,children:[`(`,f.slice(0,7),` `,m,`)`]})]}),(0,L.jsx)(`button`,{type:`button`,className:`text-xs font-medium px-2.5 py-1 rounded bg-blue-500 text-white hover:bg-blue-600 cursor-pointer shrink-0`,onClick:()=>{try{let e=JSON.parse(localStorage.getItem(k)||`[]`);e.push(f),localStorage.setItem(k,JSON.stringify(e))}catch{}window.location.reload()},children:`Update`}),(0,L.jsx)(`button`,{type:`button`,className:`ml-auto p-0.5 rounded hover:bg-blue-100 text-blue-400 hover:text-blue-600 cursor-pointer shrink-0`,onClick:()=>{try{let e=JSON.parse(localStorage.getItem(k)||`[]`);e.push(f),localStorage.setItem(k,JSON.stringify(e))}catch{}d(!1)},"aria-label":`关闭`,children:(0,L.jsx)(Jn,{className:`w-4 h-4`})})]}),(0,L.jsx)(`main`,{className:`flex-1 min-h-0 min-w-0 overflow-hidden ${D?`pb-14`:``}`,children:(()=>{let e=A;return b&&e&&e.gated&&!e.done?e.show.kind===`route`?n.pathname===e.show.path?(0,L.jsx)(Ki,{}):(0,L.jsx)(Gi,{to:e.show.path,replace:!0}):e.show.kind===`info`?(0,L.jsx)(Vce,{show:e.show,onAdvance:ee}):e.show.kind===`device`?(0,L.jsx)(Uce,{show:e.show,onAdvance:ee}):(0,L.jsx)(Bce,{form:e.show,onAdvance:ee}):(0,L.jsx)(Ki,{})})()}),e.newLoopDialogOpen&&(0,L.jsx)(O_,{onClose:()=>e.setNewLoopDialogOpen(!1),onCreate:async n=>{let r=await e.createLoop(n);return e.kanbanCreateCtx&&await Mee(e.kanbanCreateCtx.board,e.kanbanCreateCtx.filename,e.kanbanCreateCtx.cid,r.id),e.setNewLoopDialogOpen(!1),t(`/loop/${r.id}`),r.id},initialTitle:e.newLoopDialogTitle}),(0,L.jsx)(Fee,{open:c,onClose:()=>l(!1)}),D&&(0,L.jsx)(Fce,{}),!C&&!r&&(0,L.jsx)(kce,{me:v})]}):(0,L.jsx)(Oce,{})}function Jce(){return f6()?(0,L.jsx)(Ice,{}):(0,L.jsx)(Xce,{})}function Yce(){return f6()?(0,L.jsx)(Lce,{}):(0,L.jsx)(z7,{})}function Xce(){let e=D_(),[t,n]=(0,F.useState)(null),[r,i]=(0,F.useState)(0);if((0,F.useEffect)(()=>{e.currentUser&&bh().then(e=>n(e))},[e.currentUser,r]),e.currentUser&&t===null||e.loopsLoading)return null;if(e.currentUser&&t&&!t.imported&&!G9())return(0,L.jsx)(K9,{onDismiss:()=>i(e=>e+1)});if(e.loops.length===0)return(0,L.jsx)(Zce,{loggedIn:!!e.currentUser,onNew:()=>e.setNewLoopDialogOpen(!0)});let a=e.currentUser?.id?localStorage.getItem(`loopat:lastLoop:${e.currentUser.id}`):null,o=e.currentUser?.id?e.loops.filter(t=>t.createdBy===e.currentUser.id):[];return(0,L.jsx)(Gi,{to:`/loop/${a&&e.loops.some(e=>e.id===a)?a:o.length>0?o[0].id:e.loops[0].id}`,replace:!0})}function Zce({loggedIn:e,onNew:t}){return(0,L.jsxs)(`div`,{className:`h-full w-full flex flex-col items-center justify-center text-gray-500 gap-3`,children:[(0,L.jsx)(`div`,{children:`no loops yet`}),e?(0,L.jsx)(`button`,{onClick:t,className:`px-3 h-8 rounded text-sm bg-gray-900 text-white hover:bg-gray-700`,children:`+ New Loop`}):(0,L.jsx)(`div`,{className:`text-xs text-gray-400`,children:`log in to create one`})]})}function Qce(){return(0,L.jsx)(Rce,{children:(0,L.jsx)(uh,{children:(0,L.jsx)(Ra,{children:(0,L.jsx)(Yi,{children:(0,L.jsxs)(qi,{element:(0,L.jsx)(Kce,{}),children:[(0,L.jsx)(qi,{path:`/`,element:(0,L.jsx)(Gi,{to:`/loop`,replace:!0})}),(0,L.jsx)(qi,{path:`/loop`,element:(0,L.jsx)(Jce,{})}),(0,L.jsx)(qi,{path:`/loop/:id`,element:(0,L.jsx)(wie,{})}),(0,L.jsx)(qi,{path:`/topic/:name`,element:(0,L.jsx)(Pie,{})}),(0,L.jsx)(qi,{path:`/kanban`,element:(0,L.jsx)(Gi,{to:`/kanban/default`,replace:!0})}),(0,L.jsx)(qi,{path:`/kanban/:board`,element:(0,L.jsx)(Koe,{})}),(0,L.jsx)(qi,{path:`/context`,element:(0,L.jsx)(Gi,{to:`/context/knowledge`,replace:!0})}),(0,L.jsx)(qi,{path:`/context/:sub`,element:(0,L.jsx)(Rie,{})}),(0,L.jsx)(qi,{path:`/chat`,element:(0,L.jsx)(Yce,{})}),(0,L.jsx)(qi,{path:`/chat/:convId`,element:(0,L.jsx)(z7,{})}),(0,L.jsx)(qi,{path:`/me`,element:(0,L.jsx)(zce,{})}),(0,L.jsx)(qi,{path:`/settings`,element:(0,L.jsx)(Gi,{to:`/settings/personal-repo`,replace:!0})}),(0,L.jsx)(qi,{path:`/settings/:tab`,element:(0,L.jsx)(wce,{})}),(0,L.jsx)(qi,{path:`/admin/system`,element:(0,L.jsx)(Dce,{})})]})})})})})}var $ce=class extends F.Component{state={error:null};static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){console.error(`[ErrorBoundary]`,e,t.componentStack)}reset=()=>{this.setState({error:null})};render(){if(!this.state.error)return this.props.children;let e=this.state.error;return(0,L.jsxs)(`div`,{className:`m-4 flex flex-col gap-3 rounded-md border border-red-300 bg-red-50 p-4 text-sm text-red-900`,children:[(0,L.jsx)(`div`,{className:`font-medium`,children:`UI crashed — caught by error boundary`}),(0,L.jsxs)(`pre`,{className:`overflow-auto whitespace-pre-wrap break-words rounded bg-white/70 p-2 text-xs leading-relaxed`,children:[e.name,`: `,e.message,e.stack?`\n\n${e.stack}`:``]}),(0,L.jsxs)(`div`,{className:`flex gap-2`,children:[(0,L.jsx)(`button`,{type:`button`,className:`rounded bg-red-600 px-3 py-1 text-xs font-medium text-white hover:bg-red-700`,onClick:this.reset,children:`Try again`}),(0,L.jsx)(`button`,{type:`button`,className:`rounded border border-red-300 bg-white px-3 py-1 text-xs font-medium text-red-700 hover:bg-red-100`,onClick:()=>window.location.reload(),children:`Reload page`})]})]})}};document.addEventListener(`gesturestart`,e=>e.preventDefault()),(0,Up.createRoot)(document.getElementById(`root`)).render((0,L.jsx)(F.StrictMode,{children:(0,L.jsx)($ce,{children:(0,L.jsx)(Qce,{})})}));export{LK as a,eI as c,Lh as d,zn as f,IK as i,EF as l,WK as n,QH as o,UK as r,PL as s,P0 as t,Ih as u};
452
+ `).map(e=>e.trim()).filter(Boolean)}),disabled:n,rows:Math.max(1,e.models.length),className:O9+` resize-none`})}),(0,L.jsx)(`td`,{className:`px-3 py-2`,children:(0,L.jsx)(`button`,{onClick:()=>f(t),disabled:n,className:`text-gray-300 hover:text-red-500 transition-colors disabled:opacity-30`,children:(0,L.jsx)(Bn,{size:12})})})]},t))})]})}),r?(0,L.jsxs)(`div`,{className:`border border-gray-200 rounded-lg p-3 space-y-2 bg-gray-50/50`,children:[(0,L.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2`,children:[(0,L.jsx)(`input`,{autoFocus:!0,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&d(),e.key===`Escape`&&i(!1)},placeholder:`Provider name`,className:O9}),(0,L.jsx)(`input`,{value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&d()},placeholder:`Base URL`,className:O9})]}),(0,L.jsx)(`textarea`,{value:l,onChange:e=>u(e.target.value),placeholder:`Models (one per line)`,rows:3,className:O9+` resize-none`}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(`button`,{onClick:d,className:`px-3 h-7 rounded bg-gray-900 text-white text-[11px] font-medium hover:bg-gray-800`,children:`Add`}),(0,L.jsx)(`button`,{onClick:()=>i(!1),className:`text-[11px] text-gray-400 hover:text-gray-600`,children:`Cancel`})]})]}):(0,L.jsxs)(`button`,{onClick:()=>i(!0),disabled:n,className:`text-[11px] text-gray-500 hover:text-gray-900 inline-flex items-center gap-1 transition-colors disabled:opacity-50`,children:[(0,L.jsx)(bn,{size:11}),` add provider preset`]})]})}function mce({presets:e,onChange:t,saving:n}){let[r,i]=(0,F.useState)(!1),[a,o]=(0,F.useState)(``),[s,c]=(0,F.useState)(``),[l,u]=(0,F.useState)(``),[d,f]=(0,F.useState)(``),p=()=>{let n=a.trim();!n||!s.trim()||(t([...e,{name:n,suggestedVersion:s.trim(),description:l.trim()||void 0,backend:d.trim()||void 0}]),o(``),c(``),u(``),f(``),i(!1))},m=n=>{t(e.filter((e,t)=>t!==n))},h=(n,r)=>{t(e.map((e,t)=>t===n?{...e,...r}:e))};return(0,L.jsxs)(`div`,{className:`space-y-3`,children:[e.length===0&&!r&&(0,L.jsx)(`div`,{className:`text-[12px] text-gray-400 italic py-3`,children:`No mise tool presets. Add one to get started.`}),e.length>0&&(0,L.jsx)(`div`,{className:`border border-gray-200 rounded-lg overflow-hidden`,children:(0,L.jsxs)(`table`,{className:`w-full text-[13px]`,children:[(0,L.jsx)(`thead`,{children:(0,L.jsxs)(`tr`,{className:`border-b border-gray-100 bg-gray-50/50 text-left text-[10px] text-gray-500 uppercase tracking-wider`,children:[(0,L.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:`Tool`}),(0,L.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:`Version`}),(0,L.jsx)(`th`,{className:`px-3 py-2 font-medium hidden sm:table-cell`,children:`Description`}),(0,L.jsx)(`th`,{className:`px-3 py-2 font-medium hidden sm:table-cell`,children:`Backend`}),(0,L.jsx)(`th`,{className:`px-3 py-2 font-medium w-10`})]})}),(0,L.jsx)(`tbody`,{children:e.map((e,t)=>(0,L.jsxs)(`tr`,{className:`border-b border-gray-50 hover:bg-gray-50/50 transition-colors`,children:[(0,L.jsx)(`td`,{className:`px-3 py-2`,children:(0,L.jsx)(`input`,{value:e.name,onChange:e=>h(t,{name:e.target.value}),disabled:n,className:O9+` w-24`})}),(0,L.jsx)(`td`,{className:`px-3 py-2`,children:(0,L.jsx)(`input`,{value:e.suggestedVersion,onChange:e=>h(t,{suggestedVersion:e.target.value}),disabled:n,className:O9+` w-20`})}),(0,L.jsx)(`td`,{className:`px-3 py-2 hidden sm:table-cell`,children:(0,L.jsx)(`input`,{value:e.description??``,onChange:e=>h(t,{description:e.target.value||void 0}),disabled:n,placeholder:`optional`,className:O9})}),(0,L.jsx)(`td`,{className:`px-3 py-2 hidden sm:table-cell`,children:(0,L.jsx)(`input`,{value:e.backend??``,onChange:e=>h(t,{backend:e.target.value||void 0}),disabled:n,placeholder:`optional`,className:O9})}),(0,L.jsx)(`td`,{className:`px-3 py-2`,children:(0,L.jsx)(`button`,{onClick:()=>m(t),disabled:n,className:`text-gray-300 hover:text-red-500 transition-colors disabled:opacity-30`,children:(0,L.jsx)(Bn,{size:12})})})]},t))})]})}),r?(0,L.jsxs)(`div`,{className:`border border-gray-200 rounded-lg p-3 space-y-2 bg-gray-50/50`,children:[(0,L.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2`,children:[(0,L.jsx)(`input`,{autoFocus:!0,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&p(),e.key===`Escape`&&i(!1)},placeholder:`Tool name (e.g. python)`,className:O9}),(0,L.jsx)(`input`,{value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&p()},placeholder:`Suggested version (e.g. 3.12)`,className:O9})]}),(0,L.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2`,children:[(0,L.jsx)(`input`,{value:l,onChange:e=>u(e.target.value),placeholder:`Description (optional)`,className:O9}),(0,L.jsx)(`input`,{value:d,onChange:e=>f(e.target.value),placeholder:`Backend (optional, e.g. aqua:sharkdp/fd)`,className:O9})]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(`button`,{onClick:p,className:`px-3 h-7 rounded bg-gray-900 text-white text-[11px] font-medium hover:bg-gray-800`,children:`Add`}),(0,L.jsx)(`button`,{onClick:()=>i(!1),className:`text-[11px] text-gray-400 hover:text-gray-600`,children:`Cancel`})]})]}):(0,L.jsxs)(`button`,{onClick:()=>i(!0),disabled:n,className:`text-[11px] text-gray-500 hover:text-gray-900 inline-flex items-center gap-1 transition-colors disabled:opacity-50`,children:[(0,L.jsx)(bn,{size:11}),` add mise tool preset`]})]})}function k9(e){return e<1e3?String(e):e<1e6?`${(e/1e3).toFixed(1)}k`:`${(e/1e6).toFixed(1)}M`}function A9(e){return new Date(e).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`})}function hce(e){return new Date(e).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,year:`numeric`})}function j9(e){let t=new Date;return t.setDate(t.getDate()-e),t.toISOString().slice(0,10)}function M9(e){return e?e===`desc`?`asc`:null:`desc`}function N9({label:e,field:t,sortField:n,sortDir:r,onSort:i,className:a}){let o=n===t;return(0,L.jsx)(`th`,{className:`px-4 py-2.5 text-[11px] font-semibold text-gray-500 uppercase tracking-wider cursor-pointer select-none hover:text-gray-700 transition-colors ${a??``}`,onClick:()=>i(t),children:(0,L.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e,o&&r===`desc`?(0,L.jsx)(at,{className:`h-3 w-3`}):o&&r===`asc`?(0,L.jsx)(ct,{className:`h-3 w-3`}):(0,L.jsx)(st,{className:`h-3 w-3 opacity-30`})]})})}function gce({data:e,maxVal:t,height:n=24,gap:r=6}){return(0,L.jsx)(`svg`,{width:280,height:e.length*(n+r),className:`shrink-0`,children:e.map((e,i)=>{let a=i*(n+r),o=t>0?e.input/t*280:0,s=t>0?e.output/t*280:0;return(0,L.jsxs)(`g`,{children:[(0,L.jsx)(`rect`,{x:0,y:a,width:o,height:n,rx:3,fill:`var(--color-blue-500)`,opacity:.7}),(0,L.jsx)(`rect`,{x:o,y:a,width:s,height:n,rx:3,fill:`var(--color-green-500)`,opacity:.7}),(0,L.jsx)(`text`,{x:o+s+4,y:a+n/2,dominantBaseline:`central`,className:`fill-gray-500 text-[10px]`,children:e.label})]},e.label)})})}function _ce({data:e,w:t=600,h:n=180}){let r={top:10,right:10,bottom:24,left:50},i=t-r.left-r.right,a=n-r.top-r.bottom,o=Math.max(1,...e.map(e=>e.input+e.output)),s=t=>r.left+(e.length>1?t/(e.length-1)*i:i/2),c=e=>r.top+a-e/o*a,l=e.map((e,t)=>`${s(t)},${c(e.input)}`).join(` `),u=e.map((e,t)=>`${s(t)},${c(e.input+e.output)}`).join(` `),d=`${s(e.length-1)},${r.top+a} ${s(0)},${r.top+a}`,f=[0,o/2,o].map(e=>({y:c(e),label:k9(e)}));return(0,L.jsxs)(`svg`,{width:t,height:n,className:`w-full`,viewBox:`0 0 ${t} ${n}`,preserveAspectRatio:`xMidYMid meet`,children:[f.map(e=>(0,L.jsxs)(`g`,{children:[(0,L.jsx)(`line`,{x1:r.left,y1:e.y,x2:t-r.right,y2:e.y,stroke:`var(--color-gray-200)`,strokeDasharray:`3,2`}),(0,L.jsx)(`text`,{x:r.left-6,y:e.y,textAnchor:`end`,dominantBaseline:`central`,className:`fill-gray-400 text-[9px]`,children:e.label})]},e.label)),(0,L.jsx)(`polygon`,{points:`${u} ${d}`,fill:`var(--color-green-500)`,opacity:.2}),(0,L.jsx)(`polyline`,{points:u,fill:`none`,stroke:`var(--color-green-500)`,strokeWidth:1.5,opacity:.6}),(0,L.jsx)(`polygon`,{points:`${l} ${d}`,fill:`var(--color-blue-500)`,opacity:.2}),(0,L.jsx)(`polyline`,{points:l,fill:`none`,stroke:`var(--color-blue-500)`,strokeWidth:1.5}),e.filter((t,n)=>e.length<=14||n%Math.ceil(e.length/14)===0||n===e.length-1).map((t,r)=>(0,L.jsx)(`text`,{x:s(e.indexOf(t)),y:n-4,textAnchor:`middle`,className:`fill-gray-400 text-[9px]`,children:A9(t.date)},t.date))]})}function vce({dailyUsage:e,timeRange:t}){let[n,r]=(0,F.useState)(`total`),[i,a]=(0,F.useState)(`desc`),[o,s]=(0,F.useState)(!1),c=(0,F.useMemo)(()=>{let n=t===`today`?j9(0):t===`7d`?j9(7):t===`30d`?j9(30):``,r={};for(let[t,i]of Object.entries(e))for(let[e,a]of Object.entries(i)){if(n&&e<n)continue;let i=r[t]??{inputTokens:0,outputTokens:0,cacheReadInputTokens:0};i.inputTokens+=a.inputTokens,i.outputTokens+=a.outputTokens,i.cacheReadInputTokens+=a.cacheReadInputTokens??0,r[t]=i}return Object.entries(r).map(([e,t])=>({model:e,...t,total:t.inputTokens+t.outputTokens,cacheRate:t.inputTokens+t.cacheReadInputTokens>0?Math.round(t.cacheReadInputTokens/(t.inputTokens+t.cacheReadInputTokens)*100):0}))},[e,t]),l=(0,F.useMemo)(()=>{let e=[...c];return n&&i&&e.sort((e,t)=>{let r=n===`model`?e.model:e[n]??0,a=n===`model`?t.model:t[n]??0;return typeof r==`string`&&typeof a==`string`?i===`desc`?a.localeCompare(r):r.localeCompare(a):i===`desc`?a-r:r-a}),e},[c,n,i]),u=e=>{if(n===e){let e=M9(i);e?a(e):(r(null),a(null))}else r(e),a(`desc`)},d=l.reduce((e,t)=>e+t.total,0),f=Math.max(...l.map(e=>e.total),1),p=o?l:l.slice(0,10),m=p.map(e=>({label:e.model,input:e.inputTokens,output:e.outputTokens}));return(0,L.jsxs)(`div`,{children:[(0,L.jsxs)(`div`,{className:`grid grid-cols-4 gap-3 mb-6`,children:[(0,L.jsxs)(`div`,{className:`bg-white border border-gray-200 rounded-lg p-4`,children:[(0,L.jsx)(`div`,{className:`text-[11px] text-gray-500 mb-1`,children:`Total Tokens`}),(0,L.jsx)(`div`,{className:`text-xl font-semibold text-gray-900`,children:k9(d)})]}),(0,L.jsxs)(`div`,{className:`bg-white border border-gray-200 rounded-lg p-4`,children:[(0,L.jsx)(`div`,{className:`text-[11px] text-gray-500 mb-1`,children:`Prompt`}),(0,L.jsx)(`div`,{className:`text-xl font-semibold text-blue-600`,children:k9(l.reduce((e,t)=>e+t.inputTokens,0))})]}),(0,L.jsxs)(`div`,{className:`bg-white border border-gray-200 rounded-lg p-4`,children:[(0,L.jsx)(`div`,{className:`text-[11px] text-gray-500 mb-1`,children:`Completion`}),(0,L.jsx)(`div`,{className:`text-xl font-semibold text-green-600`,children:k9(l.reduce((e,t)=>e+t.outputTokens,0))})]}),(0,L.jsxs)(`div`,{className:`bg-white border border-gray-200 rounded-lg p-4`,children:[(0,L.jsx)(`div`,{className:`text-[11px] text-gray-500 mb-1`,children:`Cached Tokens`}),(0,L.jsx)(`div`,{className:`text-xl font-semibold text-purple-600`,children:k9(l.reduce((e,t)=>e+t.cacheReadInputTokens,0))}),(0,L.jsx)(`div`,{className:`text-[11px] text-purple-400 mt-0.5`,children:(()=>{let e=l.reduce((e,t)=>e+t.cacheReadInputTokens,0),t=l.reduce((e,t)=>e+t.inputTokens,0);return t+e>0?`${Math.round(e/(t+e)*100)}% of potential input`:`—`})()})]})]}),p.length>0&&(0,L.jsxs)(`div`,{className:`bg-white border border-gray-200 rounded-lg p-4 mb-4`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-4 mb-3`,children:[(0,L.jsx)(`span`,{className:`text-[11px] font-semibold text-gray-500 uppercase tracking-wider`,children:`Token Distribution`}),(0,L.jsxs)(`span`,{className:`flex items-center gap-1 text-[10px] text-gray-500`,children:[(0,L.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-sm bg-blue-500 opacity-70`}),` Input`]}),(0,L.jsxs)(`span`,{className:`flex items-center gap-1 text-[10px] text-gray-500`,children:[(0,L.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-sm bg-green-500 opacity-70`}),` Output`]})]}),(0,L.jsx)(`div`,{className:`overflow-x-auto`,children:(0,L.jsx)(gce,{data:m,maxVal:f})})]}),(0,L.jsxs)(`div`,{className:`bg-white border border-gray-200 rounded-lg overflow-hidden`,children:[(0,L.jsxs)(`table`,{className:`w-full`,children:[(0,L.jsx)(`thead`,{children:(0,L.jsxs)(`tr`,{className:`border-b border-gray-200 bg-gray-50/50`,children:[(0,L.jsx)(N9,{label:`Model`,field:`model`,sortField:n,sortDir:i,onSort:u,className:`text-left`}),(0,L.jsx)(N9,{label:`Input`,field:`inputTokens`,sortField:n,sortDir:i,onSort:u,className:`text-right`}),(0,L.jsx)(N9,{label:`Output`,field:`outputTokens`,sortField:n,sortDir:i,onSort:u,className:`text-right`}),(0,L.jsx)(N9,{label:`Total`,field:`total`,sortField:n,sortDir:i,onSort:u,className:`text-right`}),(0,L.jsx)(N9,{label:`Cached`,field:`cacheRate`,sortField:n,sortDir:i,onSort:u,className:`text-right`}),(0,L.jsx)(`th`,{className:`text-right px-4 py-2.5 text-[11px] font-semibold text-gray-500 uppercase tracking-wider`,children:`%`})]})}),(0,L.jsxs)(`tbody`,{children:[p.map(e=>(0,L.jsxs)(`tr`,{className:`border-b border-gray-100 hover:bg-gray-50/50 transition-colors`,children:[(0,L.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,L.jsx)(`code`,{className:`text-[12px] text-gray-800`,children:e.model})}),(0,L.jsx)(`td`,{className:`px-4 py-2.5 text-right text-[12px] text-blue-600 tabular-nums`,children:k9(e.inputTokens)}),(0,L.jsx)(`td`,{className:`px-4 py-2.5 text-right text-[12px] text-green-600 tabular-nums`,children:k9(e.outputTokens)}),(0,L.jsx)(`td`,{className:`px-4 py-2.5 text-right text-[12px] text-gray-900 font-medium tabular-nums`,children:k9(e.total)}),(0,L.jsxs)(`td`,{className:`px-4 py-2.5 text-right text-[12px] text-purple-600 tabular-nums`,children:[k9(e.cacheReadInputTokens),` `,(0,L.jsxs)(`span`,{className:`text-[10px] text-purple-400`,children:[`(`,e.cacheRate,`%)`]})]}),(0,L.jsxs)(`td`,{className:`px-4 py-2.5 text-right text-[11px] text-gray-400 tabular-nums`,children:[d>0?(e.total/d*100).toFixed(1):0,`%`]})]},e.model)),p.length===0&&(0,L.jsx)(`tr`,{children:(0,L.jsx)(`td`,{colSpan:6,className:`px-4 py-8 text-center text-[12px] text-gray-400 italic`,children:`No token usage data`})})]})]}),l.length>10&&(0,L.jsx)(`div`,{className:`px-4 py-2 border-t border-gray-100 bg-gray-50/50`,children:(0,L.jsx)(`button`,{onClick:()=>s(!o),className:`text-[11px] text-gray-500 hover:text-gray-900 transition-colors`,children:o?`Show less`:`Show all ${l.length} models`})})]})]})}function yce({dailyUsage:e,timeRange:t}){let{dates:n,models:r,data:i,chartData:a}=(0,F.useMemo)(()=>{let n=new Set(Object.keys(e)),r=new Set;for(let t of Object.keys(e))for(let n of Object.keys(e[t]))r.add(n);let i=Array.from(r).sort(),a=Array.from(n).sort(),o=t===`today`?j9(0):t===`7d`?j9(7):t===`30d`?j9(30):``,s=o?i.filter(e=>e>=o):i,c={};for(let t of a){c[t]={};for(let n of s)c[t][n]=(e[t]?.[n]?.inputTokens??0)+(e[t]?.[n]?.outputTokens??0)}return{dates:s,models:a,data:c,chartData:s.map(t=>{let n=0,r=0;for(let i of a)n+=e[i]?.[t]?.inputTokens??0,r+=e[i]?.[t]?.outputTokens??0;return{date:t,input:n,output:r}})}},[e,t]);return n.length===0?(0,L.jsx)(`div`,{className:`text-center py-8 text-[12px] text-gray-400 italic`,children:`No daily data for this time range`}):(0,L.jsxs)(`div`,{children:[(0,L.jsxs)(`div`,{className:`bg-white border border-gray-200 rounded-lg p-4 mb-4`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-4 mb-2`,children:[(0,L.jsx)(`span`,{className:`text-[11px] font-semibold text-gray-500 uppercase tracking-wider`,children:`Daily Trend`}),(0,L.jsxs)(`span`,{className:`flex items-center gap-1 text-[10px] text-gray-500`,children:[(0,L.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-sm bg-blue-500 opacity-70`}),` Input`]}),(0,L.jsxs)(`span`,{className:`flex items-center gap-1 text-[10px] text-gray-500`,children:[(0,L.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-sm bg-green-500 opacity-20`}),` Output`]})]}),(0,L.jsx)(_ce,{data:a})]}),(0,L.jsx)(`div`,{className:`bg-white border border-gray-200 rounded-lg overflow-hidden`,children:(0,L.jsx)(`div`,{className:`overflow-x-auto`,children:(0,L.jsxs)(`table`,{className:`w-full min-w-[500px]`,children:[(0,L.jsx)(`thead`,{children:(0,L.jsxs)(`tr`,{className:`border-b border-gray-200 bg-gray-50/50`,children:[(0,L.jsx)(`th`,{className:`text-left px-4 py-2.5 text-[11px] font-semibold text-gray-500 uppercase tracking-wider sticky left-0 bg-gray-50/50`,children:`Date`}),(0,L.jsx)(`th`,{className:`text-right px-4 py-2.5 text-[11px] font-semibold text-gray-500 uppercase tracking-wider`,children:`Total`}),r.map(e=>(0,L.jsx)(`th`,{className:`text-right px-3 py-2.5 text-[10px] font-medium text-gray-400 uppercase tracking-wider max-w-[120px]`,children:(0,L.jsx)(`span`,{className:`truncate block`,children:e})},e))]})}),(0,L.jsx)(`tbody`,{children:n.map(e=>(0,L.jsxs)(`tr`,{className:`border-b border-gray-100 hover:bg-gray-50/50 transition-colors`,children:[(0,L.jsx)(`td`,{className:`px-4 py-2 text-[12px] text-gray-700 sticky left-0 bg-white`,children:A9(e)}),(0,L.jsx)(`td`,{className:`px-4 py-2 text-right text-[12px] text-gray-900 font-medium tabular-nums`,children:k9(r.reduce((t,n)=>t+(i[n]?.[e]??0),0))}),r.map(t=>(0,L.jsx)(`td`,{className:`px-3 py-2 text-right text-[11px] text-gray-500 tabular-nums`,children:i[t]?.[e]?k9(i[t][e]):``},t))]},e))})]})})})]})}function bce({loopUsage:e,timeRange:t}){let[n,r]=(0,F.useState)(`lastActivity`),[i,a]=(0,F.useState)(`desc`),o=t===`today`?j9(0):t===`7d`?j9(7):t===`30d`?j9(30):``,s=(0,F.useMemo)(()=>{let t=o?e.filter(e=>(e.lastActivity??``).slice(0,10)>=o):[...e];return n&&i&&t.sort((e,t)=>{let r,a;return n===`total`?(r=e.inputTokens+e.outputTokens,a=t.inputTokens+t.outputTokens):n===`title`||n===`lastActivity`?(r=e[n]??``,a=t[n]??``):(r=e[n]??0,a=t[n]??0),typeof r==`string`&&typeof a==`string`?i===`desc`?a.localeCompare(r):r.localeCompare(a):i===`desc`?a-r:r-a}),t},[e,o,n,i]),c=e=>{if(n===e){let e=M9(i);e?a(e):(r(null),a(null))}else r(e),a(`desc`)},l=s.reduce((e,t)=>e+t.inputTokens+t.outputTokens,0),u=_i();return(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`div`,{className:`flex items-center gap-4 mb-4 px-1`,children:(0,L.jsxs)(`span`,{className:`text-[13px] text-gray-600`,children:[(0,L.jsx)(`span`,{className:`font-semibold text-gray-900`,children:s.length}),` loops ·`,` `,(0,L.jsx)(`span`,{className:`font-semibold text-gray-900`,children:k9(l)}),` total tokens`]})}),(0,L.jsx)(`div`,{className:`bg-white border border-gray-200 rounded-lg overflow-hidden`,children:(0,L.jsxs)(`table`,{className:`w-full`,children:[(0,L.jsx)(`thead`,{children:(0,L.jsxs)(`tr`,{className:`border-b border-gray-200 bg-gray-50/50`,children:[(0,L.jsx)(N9,{label:`Loop`,field:`title`,sortField:n,sortDir:i,onSort:c,className:`text-left`}),(0,L.jsx)(`th`,{className:`hidden sm:table-cell text-left px-4 py-2.5 text-[11px] font-semibold text-gray-500 uppercase tracking-wider`,children:`Models`}),(0,L.jsx)(N9,{label:`Input`,field:`inputTokens`,sortField:n,sortDir:i,onSort:c,className:`text-right`}),(0,L.jsx)(N9,{label:`Output`,field:`outputTokens`,sortField:n,sortDir:i,onSort:c,className:`text-right`}),(0,L.jsx)(N9,{label:`Total`,field:`total`,sortField:n,sortDir:i,onSort:c,className:`text-right`}),(0,L.jsx)(`th`,{className:`text-right px-4 py-2.5 text-[11px] font-semibold text-gray-500 uppercase tracking-wider`,children:`Cached`}),(0,L.jsx)(N9,{label:`Last active`,field:`lastActivity`,sortField:n,sortDir:i,onSort:c,className:`text-right hidden sm:table-cell`})]})}),(0,L.jsxs)(`tbody`,{children:[s.map(e=>{let t=e.inputTokens+e.outputTokens,n=e.inputTokens+e.cacheReadInputTokens>0?Math.round(e.cacheReadInputTokens/(e.inputTokens+e.cacheReadInputTokens)*100):0;return(0,L.jsxs)(`tr`,{className:`border-b border-gray-100 hover:bg-gray-50/50 transition-colors cursor-pointer`,onClick:()=>u(`/loop/${e.loopId}`),children:[(0,L.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,L.jsx)(`span`,{className:`text-[12px] text-gray-800 font-medium hover:text-blue-600`,children:e.title})}),(0,L.jsx)(`td`,{className:`hidden sm:table-cell px-4 py-2.5`,children:(0,L.jsx)(`code`,{className:`text-[11px] text-gray-500`,children:e.model})}),(0,L.jsx)(`td`,{className:`px-4 py-2.5 text-right text-[12px] text-blue-600 tabular-nums`,children:k9(e.inputTokens)}),(0,L.jsx)(`td`,{className:`px-4 py-2.5 text-right text-[12px] text-green-600 tabular-nums`,children:k9(e.outputTokens)}),(0,L.jsx)(`td`,{className:`px-4 py-2.5 text-right text-[12px] text-gray-900 font-medium tabular-nums`,children:k9(t)}),(0,L.jsxs)(`td`,{className:`px-4 py-2.5 text-right text-[12px] text-purple-600 tabular-nums`,children:[k9(e.cacheReadInputTokens),` `,(0,L.jsxs)(`span`,{className:`text-[10px] text-purple-400`,children:[`(`,n,`%)`]})]}),(0,L.jsx)(`td`,{className:`hidden sm:table-cell px-4 py-2.5 text-right text-[11px] text-gray-400`,children:hce(e.lastActivity)})]},e.loopId)}),s.length===0&&(0,L.jsx)(`tr`,{children:(0,L.jsxs)(`td`,{colSpan:6,className:`px-4 py-8 text-center text-[12px] text-gray-400 italic`,children:[`No loops with token usage`,o?` in this range`:``]})})]})]})})]})}var xce=[{id:`today`,label:`Today`},{id:`7d`,label:`7 days`},{id:`30d`,label:`30 days`},{id:`all`,label:`All time`}],Sce=[{id:`models`,label:`By Model`,icon:(0,L.jsx)(Yt,{className:`h-3.5 w-3.5`})},{id:`daily`,label:`Daily`,icon:(0,L.jsx)(pt,{className:`h-3.5 w-3.5`})},{id:`loops`,label:`By Loop`,icon:(0,L.jsx)(un,{className:`h-3.5 w-3.5`})}];function Cce(){_i();let[e,t]=(0,F.useState)(`models`),[n,r]=(0,F.useState)(`30d`),[i,a]=(0,F.useState)({}),[o,s]=(0,F.useState)([]),[c,l]=(0,F.useState)(!0);return(0,F.useEffect)(()=>{l(!0),Promise.all([Pg().then(a),Fg().then(s)]).finally(()=>l(!1))},[]),c?(0,L.jsx)(`div`,{className:`h-full flex items-center justify-center bg-gray-50`,children:(0,L.jsx)(`div`,{className:`text-[13px] text-gray-400`,children:`loading token data…`})}):(0,L.jsxs)(`div`,{children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-1 mb-6`,children:[Sce.map(n=>(0,L.jsxs)(`button`,{type:`button`,onClick:()=>t(n.id),className:`inline-flex items-center gap-1.5 px-3 py-1.5 rounded text-[12px] font-medium transition-colors ${e===n.id?`bg-white border border-gray-200 text-gray-900 shadow-sm`:`text-gray-500 hover:text-gray-700`}`,children:[n.icon,n.label]},n.id)),(0,L.jsx)(`div`,{className:`flex-1`}),(0,L.jsx)(`div`,{className:`flex items-center gap-0.5`,children:xce.map(e=>(0,L.jsx)(`button`,{type:`button`,onClick:()=>r(e.id),className:`px-2 py-1 rounded text-[11px] font-medium transition-colors ${n===e.id?`bg-white border border-gray-200 text-gray-900 shadow-sm`:`text-gray-500 hover:text-gray-700`}`,children:e.label},e.id))})]}),e===`models`&&(0,L.jsx)(vce,{dailyUsage:i,timeRange:n}),e===`daily`&&(0,L.jsx)(yce,{dailyUsage:i,timeRange:n}),e===`loops`&&(0,L.jsx)(bce,{loopUsage:o,timeRange:n})]})}var P9=`w-full px-2.5 py-1.5 border border-gray-300 rounded text-[13px] outline-none bg-white focus:border-gray-900 focus:ring-1 focus:ring-gray-900 transition-colors disabled:bg-gray-50 disabled:text-gray-400`;function F9(e){return`${e.replace(/[^A-Za-z0-9]+/g,`_`).replace(/^_+|_+$/g,``).toUpperCase()||`PROVIDER`}_API_KEY`}var I9=[{id:`personal-repo`,label:`Personal Repo`,gated:!1,description:`Your private repo carrying credentials + dotfiles.`,icon:Gn},{id:`providers`,label:`AI Providers`,gated:!0,description:`Models, base URLs, API keys. Pick a default.`,icon:kt},{id:`claude-config`,label:`Claude Config`,gated:!0,description:`Compose your .claude/ tiers — plugins, MCP servers, settings per tier.`,icon:en},{id:`mise-config`,label:`Mise Config`,gated:!0,description:`Configure mise toolchain tools per tier — mise.toml for each tier.`,icon:qn},{id:`token-usage`,label:`Token Usage`,gated:!1,description:`Token consumption across models, loops, and time.`,icon:pt},{id:`api-tokens`,label:`API Tokens`,gated:!1,description:`Bearer tokens for external programs to drive your loops via the Loop API. See API docs below.`,icon:$t},{id:`admin-users`,label:`Users`,gated:!1,description:`Manage workspace members — activate, promote, remove.`,icon:Kn},{id:`admin-workspace`,label:`Workspace AI Providers`,gated:!1,description:`Shared workspace provider configuration.`,icon:qt},{id:`admin-serve`,label:`Share Artifact Serve`,gated:!1,description:`Public share domain and HTTPS settings.`,icon:An},{id:`admin-presets`,label:`Presets`,gated:!1,description:`Manage preset defaults — AI providers and Mise tool suggestions.`,icon:ut}];function wce(){let e=_i(),t=D_(),n=t.currentUser?.role===`admin`,{tab:r}=xi(),i=I9.some(e=>e.id===r)?r:`personal-repo`,[a,o]=(0,F.useState)(!0),[s,c]=(0,F.useState)(!1),[l,u]=(0,F.useState)(``),[d,f]=(0,F.useState)(null),[p,m]=(0,F.useState)({}),h=(0,F.useCallback)(async()=>{o(!0);let[e,t]=await Promise.all([bh(),kg()]);c(!!e&&!!e.personalRepo&&e.imported),u(!e||!e.personalRepo?`no personal repo configured`:e.imported?``:`personal repo not imported yet`),t&&(f(t.disk),m(t.refExists)),o(!1)},[]);(0,F.useEffect)(()=>{Dh().catch(()=>{}).finally(()=>{h()})},[h]),(0,F.useEffect)(()=>{!a&&!s&&I9.find(e=>e.id===i)?.gated&&!i.startsWith(`admin-`)&&e(`/settings/personal-repo`,{replace:!0})},[a,s,i,e]);let g=I9.find(e=>e.id===i)??I9[0],_=g.gated&&!s&&!i.startsWith(`admin-`),[v,y]=(0,F.useState)(``),b=I9.filter(e=>!(e.id.startsWith(`admin-`)&&!n)),x=b.filter(e=>!e.id.startsWith(`admin-`)),S=b.filter(e=>e.id.startsWith(`admin-`)),C=v.trim()===``?b:b.filter(e=>e.label.toLowerCase().includes(v.toLowerCase())||e.description.toLowerCase().includes(v.toLowerCase())||e.id.toLowerCase().includes(v.toLowerCase()));return(0,L.jsxs)(`div`,{className:`h-full overflow-hidden bg-gray-50 flex flex-col`,children:[(0,L.jsxs)(`header`,{className:`shrink-0 border-b border-gray-200 bg-white px-4 sm:px-6 h-12 hidden sm:flex items-center gap-3`,children:[(0,L.jsx)(`button`,{type:`button`,onClick:()=>e(-1),className:`w-8 h-8 flex items-center justify-center rounded text-gray-500 hover:text-gray-900 hover:bg-gray-100`,title:`back`,children:(0,L.jsx)(ot,{size:16})}),(0,L.jsx)(`h1`,{className:`text-[15px] font-semibold text-gray-900`,children:`Settings`}),(0,L.jsx)(`div`,{className:`flex-1`}),(0,L.jsxs)(`button`,{type:`button`,onClick:()=>e(`/context/personal?file=.loopat/config.json&edit=1`),className:`h-7 px-2.5 rounded text-xs border border-gray-200 hover:bg-gray-100 text-gray-700 flex items-center gap-1.5`,title:`open raw config.json in Context tab`,children:[(0,L.jsx)(Ft,{size:12}),(0,L.jsx)(`span`,{className:`hidden sm:inline`,children:`edit raw config.json`})]}),(0,L.jsxs)(`button`,{type:`button`,onClick:h,disabled:a,className:`h-7 px-2.5 rounded text-xs border border-gray-200 hover:bg-gray-100 text-gray-700 flex items-center gap-1.5 disabled:opacity-50`,title:`reload`,children:[(0,L.jsx)(Sn,{size:12,className:a?`animate-spin`:``}),(0,L.jsx)(`span`,{className:`hidden sm:inline`,children:`reload`})]})]}),(0,L.jsxs)(`div`,{className:`flex-1 min-h-0 flex flex-col sm:flex-row`,children:[(0,L.jsxs)(`nav`,{className:`sm:w-56 shrink-0 sm:border-r border-b sm:border-b-0 border-gray-200 bg-white flex flex-col`,children:[(0,L.jsx)(`div`,{className:`hidden sm:block px-3 py-3 border-b border-gray-100`,children:(0,L.jsxs)(`div`,{className:`relative`,children:[(0,L.jsx)(En,{size:12,className:`absolute left-2 top-1/2 -translate-y-1/2 text-gray-400`}),(0,L.jsx)(`input`,{value:v,onChange:e=>y(e.target.value),placeholder:`search settings`,className:`w-full pl-7 pr-2 py-1.5 text-[12px] border border-gray-200 rounded outline-none focus:border-gray-400 bg-gray-50 focus:bg-white`})]})}),(0,L.jsxs)(`ul`,{className:`flex sm:flex-col gap-0.5 sm:gap-0 p-2 sm:py-2 overflow-x-auto sm:overflow-x-visible`,children:[v.trim()?C.map(t=>{let n=t.id===i,r=t.gated&&!a&&!s;return(0,L.jsx)(`li`,{className:`shrink-0 sm:px-1`,children:(0,L.jsxs)(`button`,{type:`button`,onClick:()=>e(`/settings/${t.id}`),className:`w-full text-left px-2.5 py-1.5 rounded text-[13px] flex items-center gap-2 transition-colors whitespace-nowrap `+(n?`bg-gray-100 text-gray-900 font-medium`:`text-gray-600 hover:bg-gray-50 hover:text-gray-900`),children:[(0,L.jsx)(t.icon,{size:14,className:`shrink-0 ${n?`text-gray-600`:`text-gray-400`}`}),(0,L.jsx)(`span`,{className:`flex-1 truncate`,children:t.label}),r&&(0,L.jsx)(`span`,{title:`locked`,children:(0,L.jsx)(on,{size:11,className:`text-gray-400 shrink-0`})})]})},t.id)}):(0,L.jsxs)(L.Fragment,{children:[x.map(t=>{let n=t.id===i,r=t.gated&&!a&&!s;return(0,L.jsx)(`li`,{className:`shrink-0 sm:px-1`,children:(0,L.jsxs)(`button`,{type:`button`,onClick:()=>e(`/settings/${t.id}`),className:`w-full text-left px-2.5 py-1.5 rounded text-[13px] flex items-center gap-2 transition-colors whitespace-nowrap `+(n?`bg-gray-100 text-gray-900 font-medium`:`text-gray-600 hover:bg-gray-50 hover:text-gray-900`),children:[(0,L.jsx)(t.icon,{size:14,className:`shrink-0 ${n?`text-gray-600`:`text-gray-400`}`}),(0,L.jsx)(`span`,{className:`flex-1 truncate`,children:t.label}),r&&(0,L.jsx)(`span`,{title:`locked`,children:(0,L.jsx)(on,{size:11,className:`text-gray-400 shrink-0`})})]})},t.id)}),S.length>0&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`li`,{className:`px-3 pt-3 pb-1 text-[10px] font-semibold text-gray-400 uppercase tracking-wider`,children:`Admin Settings`}),S.map(t=>{let n=t.id===i;return(0,L.jsx)(`li`,{className:`shrink-0 sm:px-1`,children:(0,L.jsxs)(`button`,{type:`button`,onClick:()=>e(`/settings/${t.id}`),className:`w-full text-left px-2.5 py-1.5 rounded text-[13px] flex items-center gap-2 transition-colors whitespace-nowrap `+(n?`bg-gray-100 text-gray-900 font-medium`:`text-gray-600 hover:bg-gray-50 hover:text-gray-900`),children:[(0,L.jsx)(t.icon,{size:14,className:`shrink-0 ${n?`text-gray-600`:`text-gray-400`}`}),(0,L.jsx)(`span`,{className:`flex-1 truncate`,children:t.label})]})},t.id)})]})]}),C.length===0&&(0,L.jsx)(`li`,{className:`px-3 py-2 text-[11px] text-gray-400 italic`,children:`no match`})]})]}),(0,L.jsx)(`main`,{className:`flex-1 min-w-0 min-h-0 overflow-auto`,children:(0,L.jsx)(`div`,{className:`max-w-4xl mx-auto px-4 sm:px-6 py-5`,children:a&&!d?(0,L.jsx)(`div`,{className:`text-[13px] text-gray-400 italic py-12 text-center`,children:`loading…`}):(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`div`,{className:`mb-4`,children:[(0,L.jsxs)(`h2`,{className:`text-base font-semibold text-gray-900 flex items-center gap-2`,children:[(0,L.jsx)(g.icon,{size:18,className:`text-gray-400`}),g.label]}),(0,L.jsx)(`p`,{className:`text-xs text-gray-500 mt-0.5`,children:g.description})]}),_&&(0,L.jsxs)(`div`,{className:`mb-4 rounded-lg border border-amber-200 bg-amber-50 px-4 py-3 flex items-start gap-2`,children:[(0,L.jsx)(bt,{size:16,className:`text-amber-700 mt-0.5 shrink-0`}),(0,L.jsxs)(`div`,{className:`text-[13px] text-amber-900 flex-1`,children:[(0,L.jsx)(`div`,{className:`font-medium`,children:`Set up your personal repo first`}),(0,L.jsxs)(`div`,{className:`text-[12px] text-amber-800/90 mt-0.5`,children:[`These settings live in your personal repo. Complete setup in the `,(0,L.jsx)(`button`,{onClick:()=>e(`/settings/personal-repo`),className:`underline`,children:`Personal Repo`}),` tab; this section will unlock automatically.`,(0,L.jsxs)(`span`,{className:`text-amber-700/70`,children:[` (`,l,`)`]})]})]})]}),(0,L.jsxs)(`div`,{className:`relative`,children:[_&&(0,L.jsxs)(`div`,{className:`absolute inset-0 z-10 flex flex-col items-center justify-center gap-2 bg-white/60 backdrop-blur-[1px] rounded-lg`,children:[(0,L.jsx)(on,{size:24,className:`text-gray-300`}),(0,L.jsx)(`span`,{className:`text-[13px] text-gray-500 font-medium`,children:`Set up your personal repo first`})]}),(0,L.jsxs)(`div`,{className:_?`opacity-30`:``,children:[i===`personal-repo`&&(0,L.jsx)(`div`,{className:`rounded-lg border border-gray-200 bg-white p-5`,children:(0,L.jsx)(U7,{onDone:h})}),i===`providers`&&(0,L.jsx)(Tce,{disk:d,refExists:p,onChanged:h,disabled:_}),i===`claude-config`&&(0,L.jsx)(Cse,{disabled:_}),i===`mise-config`&&(0,L.jsx)($se,{disabled:_}),i===`token-usage`&&(0,L.jsx)(Cce,{}),i===`api-tokens`&&(0,L.jsx)(Ece,{}),i===`admin-users`&&(0,L.jsx)(`div`,{className:`rounded-lg border border-gray-200 bg-white p-5`,children:(0,L.jsx)(ise,{currentUserId:t.currentUser?.id??``})}),i===`admin-workspace`&&(0,L.jsx)(sse,{}),i===`admin-serve`&&(0,L.jsx)(`div`,{className:`rounded-lg border border-gray-200 bg-white p-5`,children:(0,L.jsx)(cse,{})}),i===`admin-presets`&&(0,L.jsx)(fce,{})]})]})]})})})]})]})}function Tce({disk:e,refExists:t,onChanged:n,disabled:r}){let[i,a]=(0,F.useState)(null),[o,s]=(0,F.useState)(!1),[c,l]=(0,F.useState)(null),[u,d]=(0,F.useState)(!1),[f,p]=(0,F.useState)(``),[m,h]=(0,F.useState)(!1),[g,_]=(0,F.useState)({}),[v,y]=(0,F.useState)({}),[b,x]=(0,F.useState)(null),[S,C]=(0,F.useState)(``),[w,T]=(0,F.useState)(null),[E,D]=(0,F.useState)(``),[O,k]=(0,F.useState)({}),[A,ee]=(0,F.useState)({}),[j,te]=(0,F.useState)([]);(0,F.useEffect)(()=>{Ig().then(e=>te(e.providerPresets)).catch(()=>{})},[]),(0,F.useEffect)(()=>{if(!e){a(null),d(!1);return}let n={default:``,providers:{}};for(let[r,i]of Object.entries(e.providers)){if(r===`default`){typeof i==`string`&&(n.default=i);continue}if(i&&typeof i==`object`){let e=i,a=t[`providers.${r}.apiKey`];n.providers[r]={models:e.models&&e.models.length>0?e.models.map(e=>({id:e.id,enabled:e.enabled!==!1})):e.model?[{id:e.model,enabled:!0}]:[],baseUrl:e.baseUrl??``,maxContextTokens:e.maxContextTokens?String(e.maxContextTokens):``,enabled:e.enabled!==!1,apiKeyNewValue:``,apiKeyStored:!!a?.exists}}}a(n)},[e,t]);let M=i?Object.keys(i.providers):[],ne=(e,t)=>{a(n=>!n||!n.providers[e]?n:{...n,providers:{...n.providers,[e]:{...n.providers[e],...t}}})},N=e=>{a(t=>{if(!t)return t;let{[e]:n,...r}=t.providers,i=t.default===e||t.default.startsWith(`${e}/`);return{...t,providers:r,default:i?``:t.default}})},re=(e,t,n)=>{a(r=>{if(!r||!r.providers[e])return r;let i=r.providers[e].models.map(e=>e.id===t?{...e,...n}:e);return{...r,providers:{...r.providers,[e]:{...r.providers[e],models:i}}}})},ie=(e,t)=>{a(n=>{if(!n||!n.providers[e])return n;let r=n.providers[e].models.map(e=>e.id===t?{...e,enabled:!e.enabled}:e);return{...n,providers:{...n.providers,[e]:{...n.providers[e],models:r}}}})},ae=(e,t)=>{a(n=>{if(!n||!n.providers[e])return n;let r=n.providers[e].models.filter(e=>e.id!==t),i=n.default===`${e}/${t}`;return{...n,default:i?``:n.default,providers:{...n.providers,[e]:{...n.providers[e],models:r}}}})},oe=e=>{let t=(g[e]??``).trim();t&&(a(n=>!n||!n.providers[e]||n.providers[e].models.some(e=>e.id===t)?n:{...n,providers:{...n.providers,[e]:{...n.providers[e],models:[...n.providers[e].models,{id:t,enabled:!0}]}}}),_(t=>({...t,[e]:``})),y(t=>({...t,[e]:!1})))},se=(e,t)=>{let n=E.trim();if(!n||n===t){T(null);return}a(r=>{if(!r||!r.providers[e]||r.providers[e].models.some(e=>e.id===n))return r;let i=r.providers[e].models.map(e=>e.id===t?{...e,id:n}:e),a=r.default===`${e}/${t}`?`${e}/${n}`:r.default;return{...r,default:a,providers:{...r.providers,[e]:{...r.providers[e],models:i}}}}),T(null)},ce=e=>{let t=S.trim();if(!t||t===e||t===`default`){x(null);return}a(n=>{if(!n||!n.providers[e]||n.providers[t])return n;let{[e]:r,...i}=n.providers,a=n.default;return n.default===e?a=t:n.default.startsWith(`${e}/`)&&(a=t+n.default.slice(e.length)),{...n,default:a,providers:{...i,[t]:r}}}),x(null)},le=()=>{let e=f.trim();if(e){if(e===`default`){l(`'default' is reserved`);return}a(t=>!t||t.providers[e]?t:{...t,providers:{...t.providers,[e]:{models:[],baseUrl:``,maxContextTokens:``,enabled:!1,apiKeyNewValue:``,apiKeyStored:!1}}}),p(``),h(!1),l(null)}};return i?(0,L.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[M.map(e=>{let t=i.providers[e],n=v[e]??!1,r=t.apiKeyStored||t.apiKeyNewValue.trim()!==``;return(0,L.jsxs)(`div`,{className:`bg-white border border-gray-200 rounded-lg overflow-hidden transition-shadow hover:shadow-sm`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-2.5 bg-gray-50/50 border-b border-gray-100`,children:[(0,L.jsxs)(`label`,{className:`flex items-center gap-2.5 flex-1 min-w-0 select-none`,children:[(0,L.jsx)(K7,{checked:t.enabled,onCheckedChange:t=>r?ne(e,{enabled:t}):void 0,disabled:!r,size:`sm`}),b===e?(0,L.jsx)(`input`,{autoFocus:!0,value:S,onChange:e=>C(e.target.value),onBlur:()=>ce(e),onKeyDown:t=>{t.key===`Enter`&&!t.nativeEvent.isComposing&&ce(e),t.key===`Escape`&&x(null)},className:lh(P9,`text-[13px] font-semibold flex-1 min-w-0`)}):(0,L.jsx)(`button`,{type:`button`,onClick:()=>{x(e),C(e)},className:`text-[13px] font-semibold truncate text-left hover:underline ${t.enabled?`text-gray-900`:`text-gray-400`}`,title:`click to rename`,children:e}),!t.enabled&&(0,L.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded-full bg-gray-100 text-gray-400 font-medium shrink-0`,children:`disabled`})]}),(0,L.jsx)(`button`,{type:`button`,onClick:()=>N(e),className:`text-[11px] text-gray-400 hover:text-red-500 transition-colors shrink-0`,children:`remove`})]}),(0,L.jsxs)(`div`,{className:`p-4`,children:[(0,L.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3 mb-3`,children:[(0,L.jsx)(L9,{label:`Base URL`,children:(0,L.jsx)(`input`,{value:t.baseUrl,onChange:t=>ne(e,{baseUrl:t.target.value}),placeholder:`https://api.example.com`,className:P9})}),(0,L.jsx)(L9,{label:`Max context tokens`,children:(0,L.jsx)(`input`,{type:`number`,value:t.maxContextTokens,onChange:t=>ne(e,{maxContextTokens:t.target.value}),placeholder:`auto`,className:P9})}),(0,L.jsx)(L9,{label:t.apiKeyStored?`API key (set — type to overwrite)`:`API key`,className:`sm:col-span-2`,children:(0,L.jsx)(`input`,{type:`password`,value:t.apiKeyNewValue,onChange:t=>ne(e,{apiKeyNewValue:t.target.value}),placeholder:t.apiKeyStored?`•••••• stored encrypted in vault`:`paste API key`,className:P9})})]}),(0,L.jsxs)(`div`,{className:`border-t border-gray-100 pt-3`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,L.jsxs)(`span`,{className:`text-[11px] font-semibold text-gray-400 uppercase tracking-wider`,children:[`Models (`,t.models.length,`)`]}),(0,L.jsxs)(`button`,{type:`button`,onClick:()=>y(t=>({...t,[e]:!n})),className:`text-[11px] text-gray-500 hover:text-gray-900 inline-flex items-center gap-1 transition-colors`,children:[(0,L.jsx)(bn,{size:11}),` add model`]})]}),n&&(0,L.jsxs)(`div`,{className:`flex items-center gap-1.5 mb-2`,children:[(0,L.jsx)(`input`,{autoFocus:!0,value:g[e]??``,onChange:t=>_(n=>({...n,[e]:t.target.value})),onKeyDown:t=>{t.key===`Enter`&&!t.nativeEvent.isComposing&&oe(e),t.key===`Escape`&&y(t=>({...t,[e]:!1}))},placeholder:`model ID (e.g. claude-sonnet-4-20250514)`,className:lh(P9,`flex-1 text-[11px]`)}),(0,L.jsx)(N_,{size:`xs`,onClick:()=>oe(e),children:`add`}),(0,L.jsx)(N_,{variant:`ghost`,size:`xs`,onClick:()=>y(t=>({...t,[e]:!1})),children:`cancel`})]}),t.models.length===0&&!n&&(0,L.jsx)(`div`,{className:`text-[11px] text-gray-400 italic py-2`,children:`no models — add one above`}),(0,L.jsx)(`div`,{className:`-mx-1`,children:t.models.map(n=>{let r=i.default===`${e}/${n.id}`,o=`${e}::${n.id}`,s=w===o,c=O[`${e}::${n.id}`],l=A[`${e}::${n.id}`];return(0,L.jsxs)(`div`,{className:`flex items-center gap-1.5 px-1 py-1.5 rounded group hover:bg-gray-50 transition-colors`,children:[(0,L.jsx)(`button`,{type:`button`,onClick:()=>a(t=>t&&{...t,default:r?``:`${e}/${n.id}`}),className:`shrink-0 text-[13px] leading-none transition-colors ${r?`text-amber-500`:`text-gray-200 hover:text-amber-400`}`,title:r?`current default model`:`set as default model`,children:`★`}),(0,L.jsx)(`label`,{className:`flex items-center shrink-0 cursor-pointer`,children:(0,L.jsx)(`input`,{type:`checkbox`,checked:n.enabled!==!1,onChange:()=>ie(e,n.id),className:`h-3.5 w-3.5 rounded border-gray-300 text-gray-900 accent-gray-900`})}),(0,L.jsxs)(`div`,{className:`flex-1 min-w-0 flex items-center gap-1`,children:[s?(0,L.jsx)(`input`,{autoFocus:!0,value:E,onChange:e=>D(e.target.value),onBlur:()=>se(e,n.id),onKeyDown:t=>{t.key===`Enter`&&!t.nativeEvent.isComposing&&se(e,n.id),t.key===`Escape`&&T(null)},className:lh(P9,`text-[11px] flex-1 min-w-0`)}):(0,L.jsx)(`code`,{className:`text-[12px] truncate cursor-pointer hover:bg-gray-100 px-0.5 rounded ${n.enabled===!1?`text-gray-300 line-through`:`text-gray-700`}`,onClick:()=>{T(o),D(n.id)},title:`click to edit model ID`,children:n.id}),n.enabled===!1&&(0,L.jsx)(`span`,{className:`text-[10px] text-gray-300 font-medium shrink-0`,children:`off`})]}),(0,L.jsx)(`input`,{type:`number`,value:n.maxContextTokens??``,onChange:t=>re(e,n.id,{maxContextTokens:t.target.value?Number(t.target.value):void 0}),placeholder:`auto`,className:`w-24 px-1.5 py-0.5 border border-gray-200 rounded text-[10px] outline-none focus:border-gray-400 shrink-0 ${n.maxContextTokens?``:`opacity-0 group-hover:opacity-100 transition-opacity`}`,title:`max context tokens (empty = auto)`}),(0,L.jsx)(`button`,{type:`button`,onClick:async()=>{let r=t.apiKeyNewValue.trim(),i=`${e}::${n.id}`;if(!r&&!t.apiKeyStored){k(e=>({...e,[i]:`error`})),ee(e=>({...e,[i]:`enter an API key first`})),setTimeout(()=>{k(e=>{let{[i]:t,...n}=e;return n}),ee(e=>{let{[i]:t,...n}=e;return n})},3e3);return}k(e=>({...e,[i]:`testing`})),ee(e=>({...e,[i]:``}));try{let a=r?await _g(t.baseUrl,r,n.id):await _g(t.baseUrl,``,n.id,e,`personal`);k(e=>({...e,[i]:a.ok?`ok`:`error`})),a.ok||ee(e=>({...e,[i]:a.error??`unknown error`}))}catch(e){k(e=>({...e,[i]:`error`})),ee(t=>({...t,[i]:e?.message??`connection failed`}))}setTimeout(()=>{k(e=>{let{[i]:t,...n}=e;return n}),ee(e=>{let{[i]:t,...n}=e;return n})},4e3)},disabled:c===`testing`||!t.apiKeyStored&&!t.apiKeyNewValue.trim(),className:`shrink-0 text-[10px] px-1 py-0 rounded transition-colors ${!t.apiKeyStored&&!t.apiKeyNewValue.trim()?`opacity-0 group-hover:opacity-100 text-gray-300`:c===`ok`?`bg-emerald-100 text-emerald-700`:c===`error`?`bg-red-100 text-red-700`:c===`testing`?`bg-gray-100 text-gray-400 animate-pulse`:`text-gray-400 hover:text-gray-700 opacity-0 group-hover:opacity-100`}`,title:l||(t.apiKeyNewValue.trim()||t.apiKeyStored?`test connection`:`enter an API key first`),children:c===`ok`?`OK`:c===`error`?`FAIL`:c===`testing`?`...`:`test`}),(0,L.jsx)(`button`,{type:`button`,onClick:()=>ae(e,n.id),className:`text-gray-300 hover:text-red-500 opacity-0 group-hover:opacity-100 transition-opacity shrink-0`,title:`remove model`,children:(0,L.jsx)(Bn,{size:11})})]},n.id)})})]})]})]},e)}),(0,L.jsx)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:j.filter(e=>!i.providers[e.name]).map(e=>(0,L.jsxs)(`button`,{type:`button`,onClick:()=>{a(t=>!t||t.providers[e.name]?t:{...t,providers:{...t.providers,[e.name]:{models:e.models.map(e=>({id:e,enabled:!0})),baseUrl:e.baseUrl,maxContextTokens:``,enabled:!1,apiKeyNewValue:``,apiKeyStored:!1}}})},className:`px-2 py-0.5 rounded border border-gray-200 bg-white text-[10px] text-gray-500 hover:text-gray-900 hover:border-gray-400 transition-colors`,title:`Add ${e.name} preset`,children:[`+ `,e.name]},e.name))}),m?(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(`input`,{autoFocus:!0,value:f,onChange:e=>p(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&le(),e.key===`Escape`&&h(!1)},placeholder:`provider name`,className:lh(P9,`flex-1`)}),(0,L.jsx)(N_,{size:`sm`,onClick:le,children:`add`}),(0,L.jsx)(N_,{variant:`ghost`,size:`sm`,onClick:()=>{h(!1),p(``)},children:`cancel`})]}):(0,L.jsxs)(`button`,{onClick:()=>h(!0),className:`self-start text-xs text-gray-500 hover:text-gray-900 inline-flex items-center gap-1`,children:[(0,L.jsx)(bn,{size:12}),` add custom provider`]}),(0,L.jsxs)(`div`,{className:`flex items-center justify-end gap-2 px-4 py-3 border-t border-gray-100`,children:[c&&(0,L.jsx)(`span`,{className:`text-xs text-red-600`,children:c}),u&&!c&&(0,L.jsxs)(`span`,{className:`text-xs text-emerald-700 flex items-center gap-1`,children:[(0,L.jsx)(mt,{size:12}),` saved`]}),(0,L.jsx)(N_,{size:`sm`,onClick:async()=>{if(!i)return;s(!0),l(null);for(let[e,t]of Object.entries(i.providers)){if(!t.apiKeyNewValue.trim())continue;let n=await jg(F9(e),t.apiKeyNewValue.trim());if(!n.ok){l(`apiKey write failed for "${e}": ${n.error}`),s(!1);return}}let e={};i.default&&(e.default=i.default);for(let[t,n]of Object.entries(i.providers)){let r=n.models.filter(e=>e.id.trim()).map(e=>({id:e.id.trim(),...e.enabled?{}:{enabled:!1},...e.maxContextTokens&&e.maxContextTokens>0?{maxContextTokens:e.maxContextTokens}:{}}));e[t]={baseUrl:n.baseUrl,apiKey:`\${${F9(t)}}`,...r.length>0?{models:r}:{},...n.maxContextTokens?{maxContextTokens:Number(n.maxContextTokens)}:{},...n.enabled?{}:{enabled:!1}}}let t=await Ag({providers:e});if(!t.ok){s(!1),l(t.error??`save failed`);return}let r=await Oh();s(!1),r.ok||l(r.conflict?`Saved locally, but it conflicts with the remote — your edit is kept, not lost. Resolve it in Settings → Personal repo (take remote, or in a loop).`:r.needsPull?`Saved locally — remote moved while pushing. Save again to retry.`:`Saved locally, but push to remote failed: ${r.error??`unknown`}`),d(!0),setTimeout(()=>d(!1),2500),n()},disabled:o||r,children:o?`saving…`:`save providers`})]})]}):(0,L.jsx)(`div`,{className:`text-[12px] text-gray-400 italic`,children:`no providers yet`})}function L9({label:e,children:t,className:n}){return(0,L.jsxs)(`label`,{className:`flex flex-col gap-1 ${n??``}`,children:[(0,L.jsx)(`span`,{className:`text-[11px] font-medium text-gray-500`,children:e}),t]})}function Ece(){let[e,t]=(0,F.useState)([]),[n,r]=(0,F.useState)(!0),[i,a]=(0,F.useState)(``),[o,s]=(0,F.useState)(!1),[c,l]=(0,F.useState)(null),[u,d]=(0,F.useState)(!1),[f,p]=(0,F.useState)(null),[m,h]=(0,F.useState)(null),g=(0,F.useCallback)(async()=>{r(!0),h(null),t(await S_()),r(!1)},[]);(0,F.useEffect)(()=>{g()},[g]);let _=async()=>{if(o)return;s(!0),h(null);let e=await C_(i.trim()||`default`);s(!1),e?(l(e.token),a(``),d(!1),g()):h(`Failed to create token`)},v=async e=>{h(null);let t=await w_(e);p(null),t?g():h(`Failed to revoke token`)};return(0,L.jsxs)(`div`,{className:`space-y-4`,children:[m&&(0,L.jsxs)(`div`,{className:`rounded-lg border border-red-200 bg-red-50 px-4 py-3 text-[12px] text-red-700 flex items-center gap-2`,children:[(0,L.jsx)(bt,{size:14}),` `,m]}),c&&(0,L.jsxs)(`div`,{className:`rounded-lg border border-emerald-200 bg-emerald-50 p-4`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,L.jsx)(mt,{size:14,className:`text-emerald-600`}),(0,L.jsx)(`span`,{className:`text-[13px] font-medium text-emerald-900`,children:`Token created — copy it now, it won't be shown again`})]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(`code`,{className:`flex-1 text-[12px] bg-white border border-emerald-200 rounded px-3 py-2 font-mono text-gray-800 select-all break-all`,children:c}),(0,L.jsxs)(`button`,{type:`button`,onClick:()=>{c&&navigator.clipboard.writeText(c).then(()=>{d(!0),setTimeout(()=>d(!1),2e3)})},className:`shrink-0 h-8 px-3 rounded text-xs border border-emerald-300 hover:bg-emerald-100 text-emerald-800 flex items-center gap-1.5`,children:[u?(0,L.jsx)(mt,{size:12}):(0,L.jsx)(Dt,{size:12}),u?`copied`:`copy`]})]}),(0,L.jsx)(`button`,{type:`button`,onClick:()=>l(null),className:`mt-2 text-[11px] text-emerald-700 hover:text-emerald-900 underline`,children:`dismiss`})]}),(0,L.jsxs)(`div`,{className:`rounded-lg border border-gray-200 bg-white px-4 py-3 flex items-center justify-between`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`h3`,{className:`text-[13px] font-medium text-gray-900`,children:`Loop API documentation`}),(0,L.jsx)(`p`,{className:`text-[11px] text-gray-500 mt-0.5`,children:`Interactive reference for the endpoints these tokens authenticate against.`})]}),(0,L.jsx)(`a`,{href:`/api/v1/docs`,target:`_blank`,rel:`noopener noreferrer`,className:`shrink-0 inline-flex items-center gap-1.5 h-8 px-3 rounded text-[12px] border border-gray-300 hover:bg-gray-50 text-gray-700`,children:`Open docs →`})]}),(0,L.jsxs)(`div`,{className:`rounded-lg border border-gray-200 bg-white`,children:[(0,L.jsxs)(`div`,{className:`px-4 py-3 border-b border-gray-100`,children:[(0,L.jsx)(`h3`,{className:`text-[13px] font-medium text-gray-900`,children:`Your tokens`}),(0,L.jsx)(`p`,{className:`text-[11px] text-gray-500 mt-0.5`,children:`External programs use these tokens to call loopat under your identity — your providers, API keys, and vault.`})]}),n?(0,L.jsx)(`div`,{className:`px-4 py-8 text-center text-[12px] text-gray-400 italic`,children:`loading…`}):e.length===0?(0,L.jsx)(`div`,{className:`px-4 py-8 text-center text-[12px] text-gray-400`,children:`No API tokens yet. Create one below.`}):(0,L.jsxs)(`table`,{className:`w-full text-[13px]`,children:[(0,L.jsx)(`thead`,{children:(0,L.jsxs)(`tr`,{className:`border-b border-gray-100 text-left text-[11px] text-gray-500 uppercase tracking-wider`,children:[(0,L.jsx)(`th`,{className:`px-4 py-2 font-medium`,children:`Label`}),(0,L.jsx)(`th`,{className:`px-4 py-2 font-medium`,children:`Token`}),(0,L.jsx)(`th`,{className:`px-4 py-2 font-medium`,children:`Created`}),(0,L.jsx)(`th`,{className:`px-4 py-2 font-medium w-10`})]})}),(0,L.jsx)(`tbody`,{children:e.map(e=>(0,L.jsxs)(`tr`,{className:`border-b border-gray-50 hover:bg-gray-50`,children:[(0,L.jsx)(`td`,{className:`px-4 py-2.5 text-gray-900`,children:e.label}),(0,L.jsx)(`td`,{className:`px-4 py-2.5 font-mono text-[12px] text-gray-500`,children:e.tokenId}),(0,L.jsx)(`td`,{className:`px-4 py-2.5 text-gray-500 text-[12px]`,children:new Date(e.createdAt).toLocaleDateString()}),(0,L.jsx)(`td`,{className:`px-4 py-2.5`,children:f===e.tokenId?(0,L.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,L.jsx)(`button`,{type:`button`,onClick:()=>v(e.tokenId),className:`text-[11px] text-red-600 hover:text-red-800 font-medium`,children:`confirm`}),(0,L.jsx)(`button`,{type:`button`,onClick:()=>p(null),className:`text-[11px] text-gray-400 hover:text-gray-600`,children:`cancel`})]}):(0,L.jsx)(`button`,{type:`button`,onClick:()=>p(e.tokenId),className:`w-7 h-7 flex items-center justify-center rounded text-gray-400 hover:text-red-600 hover:bg-red-50`,title:`revoke token`,children:(0,L.jsx)(Bn,{size:13})})})]},e.tokenId))})]})]}),(0,L.jsxs)(`div`,{className:`rounded-lg border border-gray-200 bg-white p-4`,children:[(0,L.jsx)(`h3`,{className:`text-[13px] font-medium text-gray-900 mb-2`,children:`Create new token`}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(`input`,{value:i,onChange:e=>a(e.target.value),placeholder:`label (e.g. dingtalk-bot)`,className:`flex-1 px-2.5 py-1.5 border border-gray-300 rounded text-[13px] outline-none bg-white focus:border-gray-900 focus:ring-1 focus:ring-gray-900`,onKeyDown:e=>e.key===`Enter`&&_()}),(0,L.jsxs)(`button`,{type:`button`,onClick:_,disabled:o,className:`h-8 px-3 rounded text-xs bg-gray-900 hover:bg-gray-800 text-white flex items-center gap-1.5 disabled:opacity-50`,children:[(0,L.jsx)(bn,{size:12}),o?`creating…`:`create token`]})]})]}),(0,L.jsx)(`div`,{className:`rounded-lg border border-gray-100 bg-gray-50 px-4 py-3`,children:(0,L.jsxs)(`p`,{className:`text-[11px] text-gray-500 leading-relaxed`,children:[(0,L.jsx)(`strong`,{className:`text-gray-700`,children:`Usage:`}),` pass the token as`,` `,(0,L.jsx)(`code`,{className:`bg-white border border-gray-200 rounded px-1 py-0.5 text-[10px]`,children:`Authorization: Bearer <token>`}),` `,`when calling`,` `,(0,L.jsx)(`code`,{className:`bg-white border border-gray-200 rounded px-1 py-0.5 text-[10px]`,children:`POST /api/runtime/v1/turn/stream`}),`. The request will run under your identity with your configured providers and API keys.`]})}),(0,L.jsx)(rse,{})]})}function Dce(){let e=_i(),t=D_().currentUser?.role===`admin`,[n,r]=(0,F.useState)(null),[i,a]=(0,F.useState)(!0),[o,s]=(0,F.useState)(!1),[c,l]=(0,F.useState)(!1),[u,d]=(0,F.useState)(``),[f,p]=(0,F.useState)(null),[m,h]=(0,F.useState)(``),g=(0,F.useCallback)(async()=>{let e=await yg();e?r(e):h(`forbidden or server unreachable`),a(!1)},[]);if((0,F.useEffect)(()=>{if(!t)return;g();let e=setInterval(g,5e3);return()=>clearInterval(e)},[t,g]),!t)return(0,L.jsxs)(`div`,{className:`h-full flex items-center justify-center text-sm text-gray-500`,children:[`admin only.\xA0`,(0,L.jsx)(`button`,{className:`underline`,onClick:()=>e(`/loop`),children:`back`})]});async function _(){s(!0),h(``);try{let e=await bg();e.ok||h(e.error??`check failed`),await g()}finally{s(!1)}}async function v(){if(n&&!(n.activity.activeLoops>0&&!confirm(`${n.activity.activeLoops} loop(s) and ${n.activity.activeUsers} user(s) are active.\n\nbun --hot will reload code in-place — most pulls don't disturb anyone. If the pull touches deps or schema, you'll need to ssh in and restart manually.\n\nContinue?`))){l(!0),h(``),d(``);try{let e=await xg();p(e.ok),e.ok?e.pulled?d(`pulled ${e.oldHead?.slice(0,7)} → ${e.newHead?.slice(0,7)}\n${e.message??``}`.trim()):d(`already up to date`):d(e.error??`pull failed`),await g()}finally{l(!1)}}}return(0,L.jsx)(`div`,{className:`h-full overflow-y-auto bg-gray-50`,children:(0,L.jsxs)(`div`,{className:`max-w-3xl mx-auto p-4 sm:p-6 flex flex-col gap-4`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(`button`,{onClick:()=>e(-1),className:`p-1 rounded hover:bg-gray-100 text-gray-500 hover:text-gray-700`,title:`back`,children:(0,L.jsx)(ot,{className:`w-4 h-4`})}),(0,L.jsx)(`h1`,{className:`text-lg font-semibold text-gray-900`,children:`Platform`}),(0,L.jsx)(`span`,{className:`text-xs text-gray-400 ml-auto`,children:`refreshes every 5s`})]}),i&&!n&&(0,L.jsx)(`div`,{className:`text-sm text-gray-400 py-8 text-center`,children:`loading…`}),m&&(0,L.jsx)(`div`,{className:`text-xs text-red-600 bg-red-50 border border-red-200 rounded px-2 py-1.5`,children:m}),n&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(R9,{icon:(0,L.jsx)(Gt,{className:`w-4 h-4`}),title:`Version`,children:(0,L.jsxs)(`div`,{className:`flex flex-col gap-1 text-sm`,children:[(0,L.jsxs)(`div`,{className:`text-gray-700`,children:[(0,L.jsx)(`span`,{className:`text-gray-400 mr-2`,children:`branch`}),(0,L.jsx)(`span`,{className:`font-mono`,children:n.version.branch}),(0,L.jsx)(`span`,{className:`text-gray-400 mx-2`,children:`·`}),(0,L.jsx)(`span`,{className:`text-gray-400 mr-1`,children:`commit`}),(0,L.jsx)(`span`,{className:`font-mono`,children:n.version.commit.slice(0,7)})]}),n.version.behindBy>0?(0,L.jsxs)(`div`,{className:`text-amber-700 text-xs`,children:[`behind by `,n.version.behindBy,` commit`,n.version.behindBy===1?``:`s`,` —`,` `,(0,L.jsx)(`span`,{className:`font-mono`,children:n.version.latestCommit?.slice(0,7)}),` `,`"`,n.version.latestMessage,`"`]}):(0,L.jsx)(`div`,{className:`text-xs text-emerald-700`,children:`up to date`}),(0,L.jsx)(`div`,{className:`mt-2`,children:(0,L.jsxs)(`button`,{onClick:_,disabled:o,className:`text-xs px-2.5 py-1 rounded border border-gray-300 hover:bg-gray-100 disabled:opacity-50 inline-flex items-center gap-1.5`,children:[(0,L.jsx)(Sn,{className:`w-3 h-3 ${o?`animate-spin`:``}`}),o?`checking…`:`Check for updates`]})})]})}),(0,L.jsxs)(R9,{icon:(0,L.jsx)(nt,{className:`w-4 h-4`}),title:`Activity`,children:[(0,L.jsxs)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-3 text-sm mb-3`,children:[(0,L.jsx)(z9,{label:`Active loops`,value:n.activity.activeLoops}),(0,L.jsx)(z9,{label:`Active users`,value:n.activity.activeUsers}),(0,L.jsx)(z9,{label:`Live WS`,value:n.activity.totalWs}),(0,L.jsx)(z9,{label:`SDK streaming`,value:n.activity.totalGenerating})]}),n.activity.loops.length===0?(0,L.jsx)(`div`,{className:`text-xs text-gray-400 text-center py-3`,children:`no active loops`}):(0,L.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,L.jsx)(`thead`,{className:`text-gray-400 border-b border-gray-200`,children:(0,L.jsxs)(`tr`,{children:[(0,L.jsx)(`th`,{className:`text-left font-normal py-1.5 pr-2`,children:`title`}),(0,L.jsx)(`th`,{className:`text-left font-normal py-1.5 pr-2`,children:`driver`}),(0,L.jsx)(`th`,{className:`text-right font-normal py-1.5 pr-2`,children:`WS`}),(0,L.jsx)(`th`,{className:`text-left font-normal py-1.5`,children:`state`})]})}),(0,L.jsx)(`tbody`,{children:n.activity.loops.map(e=>(0,L.jsxs)(`tr`,{className:`border-b border-gray-100 last:border-b-0`,children:[(0,L.jsx)(`td`,{className:`py-1.5 pr-2 truncate max-w-[260px]`,title:e.title,children:e.title}),(0,L.jsx)(`td`,{className:`py-1.5 pr-2 text-gray-600`,children:e.driver}),(0,L.jsx)(`td`,{className:`py-1.5 pr-2 text-right`,children:e.wsCount}),(0,L.jsx)(`td`,{className:`py-1.5`,children:e.generating?(0,L.jsx)(`span`,{className:`text-blue-600`,children:`streaming…`}):e.lastMsgAgeSec>=0&&e.lastMsgAgeSec<60?(0,L.jsxs)(`span`,{className:`text-emerald-600`,children:[`msg `,e.lastMsgAgeSec,`s ago`]}):(0,L.jsx)(`span`,{className:`text-gray-400`,children:`idle (attached)`})})]},e.id))})]})]}),(0,L.jsx)(R9,{icon:(0,L.jsx)(At,{className:`w-4 h-4`}),title:`Update`,children:(0,L.jsxs)(`div`,{className:`flex flex-col gap-2 text-sm`,children:[(0,L.jsx)(`button`,{onClick:v,disabled:c||n.version.behindBy===0,className:`self-start text-sm px-3 py-1.5 rounded text-white disabled:opacity-50 `+(n.activity.activeLoops>0?`bg-amber-600 hover:bg-amber-700`:`bg-gray-900 hover:bg-gray-700`),children:c?`pulling…`:n.version.behindBy===0?`Pull latest (nothing to pull)`:`Pull latest`}),n.activity.activeLoops>0&&n.version.behindBy>0&&(0,L.jsxs)(`div`,{className:`text-xs text-amber-700`,children:[n.activity.activeLoops,` loop(s) active — bun --hot reloads code in-place. Dep / schema changes need a manual restart.`]}),u&&(0,L.jsx)(`pre`,{className:`text-xs whitespace-pre-wrap rounded p-2 border `+(f?`bg-emerald-50 border-emerald-200 text-emerald-800`:`bg-red-50 border-red-200 text-red-800`),children:u})]})})]})]})})}function R9({icon:e,title:t,children:n}){return(0,L.jsxs)(`div`,{className:`bg-white border border-gray-200 rounded-lg p-4`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium text-gray-700 mb-3`,children:[(0,L.jsx)(`span`,{className:`text-gray-400`,children:e}),t]}),n]})}function z9({label:e,value:t}){return(0,L.jsxs)(`div`,{className:`flex flex-col`,children:[(0,L.jsx)(`span`,{className:`text-[10px] text-gray-400 uppercase tracking-wide`,children:e}),(0,L.jsx)(`span`,{className:`text-xl font-semibold text-gray-900 tabular-nums`,children:t})]})}function Oce({onClose:e}={}){let t=D_(),[n,r]=(0,F.useState)(`login`),[i,a]=(0,F.useState)(``),[o,s]=(0,F.useState)(``),[c,l]=(0,F.useState)(!1),[u,d]=(0,F.useState)(null),[f,p]=(0,F.useState)(null);return(0,L.jsx)(`div`,{className:e?`fixed inset-0 z-50 bg-black/30 flex items-center justify-center`:`h-full w-full flex items-center justify-center bg-gray-50`,onClick:e?()=>e():void 0,children:(0,L.jsxs)(`div`,{className:`w-full max-w-[420px] mx-4 bg-white rounded-md shadow-xl border border-gray-200 p-4 md:p-6`,onClick:e=>e.stopPropagation(),children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2 mb-5`,children:[(0,L.jsx)(`span`,{className:`text-xl leading-none`,children:`🧶`}),(0,L.jsx)(`span`,{className:`text-base font-semibold text-gray-900`,children:`loopat`}),e&&(0,L.jsx)(`button`,{type:`button`,onClick:e,className:`ml-auto text-gray-400 hover:text-gray-700 px-1`,"aria-label":`close`,children:`✕`})]}),(0,L.jsx)(`div`,{className:`flex border-b border-gray-200 mb-5`,children:[`login`,`register`].map(e=>(0,L.jsx)(`button`,{type:`button`,onClick:()=>{r(e),d(null),p(null)},className:n===e?`px-3 py-2 text-sm border-b-2 border-gray-900 text-gray-900 font-medium`:`px-3 py-2 text-sm text-gray-500 hover:text-gray-800`,children:e===`login`?`Login`:`Register`},e))}),(0,L.jsxs)(`form`,{onSubmit:async a=>{if(a.preventDefault(),!c){d(null),l(!0);try{if(n===`login`){let n=await t.login(i.trim().toLowerCase(),o);n.error?d(n.error):e&&e();return}let a=await t.register({username:i.trim().toLowerCase(),password:o});if(a.error){d(a.error);return}if(a.user&&a.user.status===`pending`){p(`账号 ${a.user.id} 已创建,等待管理员激活后即可登录。`),r(`login`),s(``);return}e&&e()}finally{l(!1)}}},className:`flex flex-col gap-4`,children:[(0,L.jsx)(B9,{label:`Username`,hint:`lowercase a-z 0-9 _ - · 1-32 chars`,children:(0,L.jsx)(`input`,{type:`text`,value:i,onChange:e=>a(e.target.value),placeholder:`simpx`,autoFocus:!0,autoComplete:`username`,className:`w-full px-2 py-1.5 text-sm border border-gray-300 rounded outline-none focus:border-gray-500`})}),(0,L.jsx)(B9,{label:`Password`,children:(0,L.jsx)(`input`,{type:`password`,value:o,onChange:e=>s(e.target.value),autoComplete:n===`login`?`current-password`:`new-password`,className:`w-full px-2 py-1.5 text-sm border border-gray-300 rounded outline-none focus:border-gray-500`})}),n===`register`&&(0,L.jsx)(`div`,{className:`text-[11px] text-gray-400 leading-relaxed`,children:`Just creates your account. Set up your personal repo afterwards in Settings → Personal Repo.`}),f&&!u&&(0,L.jsx)(`div`,{className:`text-xs text-amber-700 bg-amber-50 border border-amber-200 rounded px-2 py-1.5`,children:f}),u&&(0,L.jsx)(`div`,{className:`text-xs text-red-600 bg-red-50 border border-red-200 rounded px-2 py-1.5`,children:u}),(0,L.jsx)(`button`,{type:`submit`,disabled:c||!i||!o,className:`px-3 h-9 text-sm rounded bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-50`,children:c?n===`login`?`logging in…`:`registering…`:n===`login`?`Login`:`Register`})]})]})})}function B9({label:e,hint:t,children:n}){return(0,L.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,L.jsx)(`span`,{className:`text-xs text-gray-700 font-medium`,children:e}),n,t&&(0,L.jsx)(`span`,{className:`text-[11px] text-gray-400`,children:t})]})}var V9=`loopat:floating-dm-open`,H9=`loopat:floating-dm-conv`;function U9(e){let t=new Date(e),n=new Date,r=t.toDateString()===n.toDateString(),i=t.toTimeString().slice(0,5);return r?i:new Date(n.getTime()-864e5).toDateString()===t.toDateString()?`yesterday ${i}`:`${t.getMonth()+1}/${t.getDate()} ${i}`}function kce({me:e}){let t=_i(),n=f6(),[r,i]=(0,F.useState)(()=>localStorage.getItem(V9)===`1`),[a,o]=(0,F.useState)(()=>localStorage.getItem(H9)),[s,c]=(0,F.useState)(!1),[l,u]=(0,F.useState)([]),[d,f]=(0,F.useState)([]),[p,m]=(0,F.useState)([]),[h,g]=(0,F.useState)(``),[_,v]=(0,F.useState)(!1),y=(0,F.useRef)(null),b=(0,F.useMemo)(()=>l.filter(e=>e.kind===`dm`).sort((e,t)=>(t.lastMessageTs??0)-(e.lastMessageTs??0)),[l]),x=(0,F.useMemo)(()=>b.reduce((e,t)=>e+t.unread,0),[b]),S=(0,F.useMemo)(()=>b.find(e=>e.id===a)??null,[b,a]);(0,F.useEffect)(()=>{localStorage.setItem(V9,r?`1`:`0`)},[r]),(0,F.useEffect)(()=>{a?localStorage.setItem(H9,a):localStorage.removeItem(H9)},[a]);let C=(0,F.useCallback)(async()=>{u(await Jg())},[]);(0,F.useEffect)(()=>{C(),Yg().then(f)},[C]),(0,F.useEffect)(()=>{if(!a){m([]);return}let e=!1;return $g(a,{limit:100}).then(t=>{if(e)return;m(t);let n=t[t.length-1];n&&(n_(a,n.id).catch(()=>{}),u(e=>e.map(e=>e.id===a?{...e,unread:0}:e)),window.dispatchEvent(new CustomEvent(`loopat:chat-read`,{detail:{convId:a}})))}),()=>{e=!0}},[a]),(0,F.useEffect)(()=>{r&&S&&y.current?.scrollIntoView({behavior:`auto`})},[p,r,S]);let w=(0,F.useRef)(a);w.current=a;let{subscribe:T,unsubscribe:E}=P7((0,F.useCallback)(t=>{if(t.type===`message`){let n=t.message,r=n.convId===w.current;r&&n.parentId==null?(m(e=>e.some(e=>e.id===n.id)?e:[...e,{...n,replyCount:0,lastReplyTs:null}]),n_(n.convId,n.id).catch(()=>{}),window.dispatchEvent(new CustomEvent(`loopat:chat-read`,{detail:{convId:n.convId}}))):r&&n.parentId!=null?m(e=>e.map(e=>e.id===n.parentId?{...e,replyCount:e.replyCount+1,lastReplyTs:n.ts}:e)):n.author!==e&&u(e=>e.map(e=>e.id===n.convId?{...e,unread:e.unread+1,lastMessageTs:n.ts}:e))}else t.type===`conv_created`?u(e=>e.some(e=>e.id===t.conv.id)?e:[...e,t.conv]):t.type===`conv_deleted`&&(u(e=>e.filter(e=>e.id!==t.convId)),w.current===t.convId&&o(null))},[e]));(0,F.useEffect)(()=>{for(let e of b)T(e.id);return()=>{for(let e of b)E(e.id)}},[b,T,E]),(0,F.useEffect)(()=>{let e=e=>{let t=e.detail;t?.convId&&u(e=>e.map(e=>e.id===t.convId?{...e,unread:0}:e))};return window.addEventListener(`loopat:chat-read`,e),()=>window.removeEventListener(`loopat:chat-read`,e)},[]);let D=async()=>{if(!S||!h.trim()||_)return;let e=h.trim();g(``),v(!0);let t=await t_(S.id,e);if(v(!1),t.message){let e=t.message;m(t=>t.some(t=>t.id===e.id)?t:[...t,{...e,replyCount:0,lastReplyTs:null}])}else g(e)};return e?(0,L.jsxs)(L.Fragment,{children:[!r&&(0,L.jsxs)(`button`,{type:`button`,onClick:()=>i(!0),className:`fixed ${n?`bottom-24`:`bottom-20`} right-5 z-30 w-12 h-12 rounded-full flex items-center justify-center shadow-lg transition-colors `+(x>0?`bg-gray-700 text-white animate-pulse`:`bg-gray-700 text-white hover:bg-gray-500`),title:`direct messages`,children:[(0,L.jsx)(ln,{size:20}),x>0&&(0,L.jsx)(`span`,{className:`absolute -top-1 -right-1 min-w-[18px] h-[18px] px-1 rounded-full bg-red-500 text-white text-[10px] font-medium flex items-center justify-center`,children:x>99?`99+`:x})]}),r&&(0,L.jsxs)(`div`,{className:`fixed ${n?`bottom-24`:`bottom-20`} right-5 z-30 w-[22rem] max-w-[calc(100vw-2.5rem)] h-[32rem] max-h-[calc(100dvh-2.5rem)] bg-white rounded-lg shadow-2xl border border-gray-200 flex flex-col overflow-hidden`,children:[(0,L.jsxs)(`header`,{className:`h-10 shrink-0 border-b border-gray-200 px-2 flex items-center gap-1`,children:[S?(0,L.jsx)(`button`,{type:`button`,onClick:()=>o(null),className:`w-7 h-7 flex items-center justify-center rounded text-gray-500 hover:text-gray-900 hover:bg-gray-100`,title:`back to DMs`,children:(0,L.jsx)(ot,{size:14})}):(0,L.jsx)(`span`,{className:`px-2 text-[13px] font-medium text-gray-900`,children:`Direct messages`}),S&&(0,L.jsxs)(`div`,{className:`flex-1 min-w-0 flex items-center gap-1.5`,children:[(0,L.jsx)(`span`,{className:`text-gray-400 text-[13px]`,children:`@`}),(0,L.jsx)(`span`,{className:`text-[13px] font-medium text-gray-900 truncate`,children:S.peerUserId??`(unknown)`})]}),!S&&(0,L.jsx)(`div`,{className:`flex-1`}),!S&&(0,L.jsx)(`button`,{type:`button`,onClick:()=>c(!0),className:`w-7 h-7 flex items-center justify-center rounded text-gray-500 hover:text-gray-900 hover:bg-gray-100`,title:`new DM`,children:(0,L.jsx)(bn,{size:14})}),S&&(0,L.jsx)(`button`,{type:`button`,onClick:()=>{t(S?`/chat/${S.id}`:`/chat`),i(!1)},className:`w-7 h-7 flex items-center justify-center rounded text-gray-500 hover:text-gray-900 hover:bg-gray-100`,title:`open in chat tab`,children:(0,L.jsx)(Mt,{size:13})}),(0,L.jsx)(`button`,{type:`button`,onClick:()=>i(!1),className:`w-7 h-7 flex items-center justify-center rounded text-gray-500 hover:text-gray-900 hover:bg-gray-100`,title:`close`,children:(0,L.jsx)(Jn,{size:14})})]}),S?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-auto px-3 py-2 flex flex-col gap-2`,children:[p.length===0&&(0,L.jsx)(`div`,{className:`text-[12px] text-gray-400 italic py-4 text-center`,children:`no messages yet — say hi`}),p.map(t=>(0,L.jsx)(Ace,{message:t,isMe:t.author===e},t.id)),(0,L.jsx)(`div`,{ref:y})]}),(0,L.jsx)(`div`,{className:`px-2 pb-2 pt-1 shrink-0`,children:(0,L.jsxs)(`div`,{className:`rounded-xl border border-gray-200 bg-white p-1.5 flex items-end gap-1`,children:[(0,L.jsx)(`textarea`,{value:h,onChange:e=>g(e.target.value),onKeyDown:e=>{e.nativeEvent.isComposing||e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),D())},rows:1,placeholder:`message @${S.peerUserId??``}…`,className:`field-sizing-content flex-1 max-h-32 min-h-7 resize-none bg-transparent px-1.5 py-1 text-sm text-gray-900 outline-none placeholder:text-gray-400`}),(0,L.jsx)(`button`,{type:`button`,onClick:D,disabled:_||!h.trim(),className:`px-2.5 h-7 rounded bg-gray-900 text-white text-xs hover:bg-gray-700 disabled:opacity-40 shrink-0`,children:`send`})]})})]}):(0,L.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto`,children:b.length===0?(0,L.jsxs)(`div`,{className:`px-4 py-6 text-center text-[12px] text-gray-400`,children:[`no DMs yet`,(0,L.jsx)(`div`,{className:`mt-2`,children:(0,L.jsxs)(`button`,{type:`button`,onClick:()=>c(!0),className:`px-2 py-1 rounded border border-gray-200 text-[12px] text-gray-700 hover:bg-gray-50 inline-flex items-center gap-1`,children:[(0,L.jsx)(bn,{size:12}),(0,L.jsx)(`span`,{children:`new DM`})]})})]}):(0,L.jsx)(`ul`,{className:`py-1`,children:b.map(e=>(0,L.jsx)(`li`,{children:(0,L.jsxs)(`button`,{type:`button`,onClick:()=>o(e.id),className:`w-full px-3 py-2 flex items-center gap-2 text-left hover:bg-gray-50`,children:[(0,L.jsx)(`span`,{className:`w-7 h-7 rounded bg-gray-200 text-gray-900 text-[11px] font-medium flex items-center justify-center shrink-0`,children:(e.peerUserId??`?`).slice(0,1).toUpperCase()}),(0,L.jsxs)(`span`,{className:`flex-1 min-w-0 text-[13px] text-gray-900 truncate`,children:[`@`,e.peerUserId??`(unknown)`]}),e.unread>0&&(0,L.jsx)(`span`,{className:`text-[10px] font-medium px-1.5 rounded-full bg-red-500 text-white`,children:e.unread}),e.lastMessageTs&&e.unread===0&&(0,L.jsx)(`span`,{className:`text-[10px] text-gray-400`,children:U9(e.lastMessageTs)})]})},e.id))})})]}),s&&(0,L.jsx)(jce,{users:d,onClose:()=>c(!1),onPick:async e=>{let t=await Qg(e);t.conv?(c(!1),o(t.conv.id),C()):t.error&&alert(t.error)}})]}):null}function Ace({message:e,isMe:t}){return(0,L.jsxs)(`div`,{className:`flex gap-1.5 `+(t?`flex-row-reverse`:``),children:[(0,L.jsx)(`div`,{className:t?`w-6 h-6 rounded shrink-0 flex items-center justify-center text-[10px] font-medium bg-gray-900 text-white`:`w-6 h-6 rounded shrink-0 flex items-center justify-center text-[10px] font-medium bg-gray-200 text-gray-900`,title:e.author,children:e.author.slice(0,1).toUpperCase()}),(0,L.jsxs)(`div`,{className:`min-w-0 max-w-[80%]`,children:[(0,L.jsx)(`div`,{className:`text-[10px] text-gray-400 `+(t?`text-right`:``),children:U9(e.ts)}),(0,L.jsx)(`div`,{className:`text-[12.5px] whitespace-pre-wrap break-words leading-relaxed px-2 py-1 rounded-lg `+(t?`bg-gray-900 text-white`:`bg-gray-100 text-gray-900`),children:e.text})]})]})}function jce({users:e,onClose:t,onPick:n}){let[r,i]=(0,F.useState)(``),a=e.filter(e=>!e.isMe).filter(e=>e.id.toLowerCase().includes(r.toLowerCase()));return(0,L.jsx)(`div`,{className:`fixed inset-0 z-40 bg-black/30 flex items-center justify-center`,onClick:t,children:(0,L.jsxs)(`div`,{className:`bg-white rounded-md shadow-lg w-80 p-3 flex flex-col gap-2`,onClick:e=>e.stopPropagation(),children:[(0,L.jsx)(`div`,{className:`text-sm font-medium text-gray-900`,children:`New DM`}),(0,L.jsx)(`input`,{autoFocus:!0,value:r,onChange:e=>i(e.target.value),placeholder:`search users…`,className:`px-2 py-1.5 text-sm rounded border border-gray-200 outline-none focus:border-gray-400`}),(0,L.jsxs)(`div`,{className:`max-h-64 overflow-auto flex flex-col gap-0.5`,children:[a.map(e=>(0,L.jsxs)(`button`,{type:`button`,onClick:()=>n(e.id),className:`text-left px-2 py-1.5 text-sm rounded hover:bg-gray-100 flex items-center gap-2`,children:[(0,L.jsx)(`span`,{className:`w-6 h-6 rounded bg-gray-200 text-gray-900 text-[11px] flex items-center justify-center`,children:e.id.slice(0,1).toUpperCase()}),(0,L.jsx)(`span`,{children:e.id})]},e.id)),a.length===0&&(0,L.jsx)(`div`,{className:`text-xs text-gray-400 px-2 py-2`,children:`no users match`})]})]})})}var Mce=[{id:`loop`,label:`Loop`,icon:`⑂`,path:`/loop`},{id:`chat`,label:`Chat`,icon:null,path:`/chat`},{id:`context`,label:`Context`,icon:`⌘`,path:`/context`},{id:`me`,label:`Me`,icon:null,path:`/me`}];function Nce(e,t,n){return!!(e===`/`&&n===`loop`||n===`loop`&&e.startsWith(`/loop`)||n===`chat`&&e.startsWith(`/chat`)||n===`context`&&e.startsWith(`/context`)||n===`me`&&e===`/me`)}function Pce({tabId:e}){switch(e){case`loop`:return(0,L.jsx)(`span`,{className:`text-lg leading-none`,children:`⑂`});case`chat`:return(0,L.jsx)(ln,{size:18});case`context`:return(0,L.jsx)(`span`,{className:`text-lg leading-none`,children:`⌘`});case`me`:return(0,L.jsx)(Gn,{size:18});default:return null}}function Fce(){let e=f6(),t=_i(),{pathname:n}=pi();return e?(0,L.jsx)(`nav`,{className:`fixed bottom-0 left-0 right-0 z-50 h-14 bg-white border-t border-gray-200 flex items-center justify-around`,style:{paddingBottom:`env(safe-area-inset-bottom, 0px)`},children:Mce.map(e=>(0,L.jsxs)(`button`,{type:`button`,onClick:()=>t(e.path),className:`flex flex-col items-center justify-center gap-0.5 h-full flex-1 transition-colors `+(Nce(n,e.path,e.id)?`text-gray-900`:`text-gray-400 hover:text-gray-600`),children:[(0,L.jsx)(Pce,{tabId:e.id}),(0,L.jsx)(`span`,{className:`text-[10px] leading-none font-medium`,children:e.label})]},e.id))}):null}var W9=`loopat:setupPersonalRepoDismissed`;function G9(){try{return localStorage.getItem(W9)===`1`}catch{return!1}}function K9({onDismiss:e,hideSkip:t}){let n=_i();return(0,L.jsxs)(`div`,{className:`max-w-2xl mx-auto mt-12 px-6 py-8 rounded-lg border border-gray-200 bg-white shadow-sm`,children:[(0,L.jsx)(`div`,{className:`text-2xl mb-2`,children:`👋 欢迎来到 loopat`}),(0,L.jsxs)(`p`,{className:`text-sm text-gray-600 leading-relaxed mb-3`,children:[`在你开始之前,建议先配一个`,(0,L.jsx)(`b`,{children:`个人仓库`}),`——`]}),(0,L.jsxs)(`p`,{className:`text-sm text-gray-600 leading-relaxed mb-3`,children:[`loopat 一个反直觉的设计:服务器`,(0,L.jsx)(`b`,{children:`不存你的数据`}),`。你的 API key、ssh、token、 笔记、memory 全部存在你自己的 GitHub 私有仓库里,由你自己持有解密密钥。 这是 loopat 跟其他工具最大的不同。`]}),(0,L.jsx)(`p`,{className:`text-sm text-gray-600 leading-relaxed mb-5`,children:`配置 3 步,大约 2 分钟:创建一个空的私有仓库 → 把 loopat 的 deploy key 贴上去 → 把仓库 URL 填进来。配完后回到这个页面,AI 引导会自动接上。`}),(0,L.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,L.jsx)(`button`,{onClick:()=>n(`/settings/personal-repo`),className:`px-4 h-9 rounded text-sm bg-gray-900 text-white hover:bg-gray-700`,children:`去配置个人仓库 →`}),!t&&(0,L.jsx)(`button`,{onClick:()=>{try{localStorage.setItem(W9,`1`)}catch{}e()},className:`text-xs text-gray-500 hover:text-gray-700`,children:`跳过(先用 workspace 的 key)`})]}),(0,L.jsx)(`p`,{className:`mt-4 text-[11px] text-gray-400 leading-relaxed`,children:`跳过后这个提示就不再出现。但 loopat 的核心安全模型依赖你的个人仓库 —— 想用自己的凭据、记自己的 memory 时,从右上角 Settings → Personal Repo 随时可以补上。`})]})}function Ice(){let e=D_(),t=_i(),[n,r]=(0,F.useState)(null),[i,a]=(0,F.useState)(0);return(0,F.useEffect)(()=>{e.currentUser&&bh().then(r)},[e.currentUser,i]),e.loopsLoading?(0,L.jsx)(`div`,{className:`h-full w-full flex items-center justify-center`,children:(0,L.jsx)(`div`,{className:`text-sm text-gray-400`,children:`loading…`})}):e.currentUser&&n&&!n.imported&&!G9()?(0,L.jsx)(`div`,{className:`h-full w-full overflow-auto`,children:(0,L.jsx)(K9,{onDismiss:()=>a(e=>e+1),hideSkip:!1})}):e.loops.length===0?(0,L.jsxs)(`div`,{className:`h-full w-full flex flex-col items-center justify-center text-gray-500 gap-3`,children:[(0,L.jsx)(`div`,{className:`text-sm`,children:`no loops yet`}),e.currentUser?(0,L.jsx)(`button`,{onClick:()=>e.setNewLoopDialogOpen(!0),className:`px-3 h-8 rounded text-sm bg-gray-900 text-white hover:bg-gray-700`,children:`+ New Loop`}):(0,L.jsx)(`div`,{className:`text-xs text-gray-400`,children:`log in to create one`})]}):(0,L.jsx)(`div`,{className:`h-full w-full bg-white overflow-auto`,children:(0,L.jsx)(C8,{onSelect:e=>t(`/loop/${e}`)})})}function Lce(){let e=D_(),t=_i(),n=e.currentUser?.role===`admin`,[r,i]=(0,F.useState)([]),[a,o]=(0,F.useState)(!0),[s,c]=(0,F.useState)(!1),[l,u]=(0,F.useState)(!1),[d,f]=(0,F.useState)(``),p=async()=>{o(!0);try{i(await Jg())}catch{}finally{o(!1)}};(0,F.useEffect)(()=>{p()},[]);let m=r.filter(e=>e.kind===`channel`),h=r.filter(e=>e.kind===`dm`);return(0,L.jsx)(`div`,{className:`h-full w-full bg-white overflow-auto`,children:a?(0,L.jsx)(`div`,{className:`h-full flex items-center justify-center text-sm text-gray-400`,children:`loading…`}):(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(M7,{channels:m,dms:h,activeConvId:void 0,isAdmin:n,onSelectConv:e=>{t(`/chat/${e.id}`)},onNewChannel:()=>u(!0),onNewDm:()=>c(!0),onDeleteChannel:n?async e=>{confirm(`Delete this channel?`)&&(await Zg(e),await p())}:void 0}),l&&(0,L.jsx)(q9,{title:`New channel`,placeholder:`channel name`,onSubmit:e=>{u(!1),Xg(e).then(p)},onClose:()=>u(!1)}),s&&(0,L.jsx)(q9,{title:`New DM`,placeholder:`username`,value:d,onChange:f,onSubmit:async()=>{let e=d.trim();if(!e)return;let n=await Qg(e);n.conv?(c(!1),f(``),t(`/chat/${n.conv.id}`),await p()):n.error&&alert(n.error)},onClose:()=>{c(!1),f(``)}})]})})}function q9(e){let[t,n]=(0,F.useState)(e.value??``);return(0,L.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,onClick:e.onClose,children:[(0,L.jsx)(`div`,{className:`absolute inset-0 bg-black/30`}),(0,L.jsxs)(`div`,{className:`relative bg-white rounded-lg shadow-xl w-80 max-w-[90vw] p-4 flex flex-col gap-3`,onClick:e=>e.stopPropagation(),children:[(0,L.jsx)(`div`,{className:`text-sm font-medium text-gray-900`,children:e.title}),(0,L.jsx)(`input`,{type:`text`,autoFocus:!0,value:e.onChange?e.value??``:t,onChange:t=>{e.onChange?e.onChange(t.target.value):n(t.target.value)},onKeyDown:n=>{if(n.key===`Enter`){let n=e.onChange?e.value??``:t;n.trim()&&e.onSubmit(n.trim())}},placeholder:e.placeholder,className:`h-9 px-3 rounded border border-gray-300 text-sm focus:outline-none focus:border-gray-500`}),(0,L.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,L.jsx)(`button`,{onClick:e.onClose,className:`px-3 h-7 rounded text-xs text-gray-500 hover:bg-gray-100`,children:`cancel`}),(0,L.jsx)(`button`,{onClick:()=>{let n=e.onChange?e.value??``:t;n.trim()&&e.onSubmit(n.trim())},className:`px-3 h-7 rounded text-xs bg-gray-900 text-white hover:bg-gray-700`,children:`create`})]})]})]})}var J9=(0,F.createContext)({theme:`light`,toggle:()=>{}});function Y9(){return(0,F.useContext)(J9)}var X9=`loopat:theme`;function Z9(){try{let e=localStorage.getItem(X9);if(e===`dark`||e===`light`)return e}catch{}return window.matchMedia?.(`(prefers-color-scheme: dark)`).matches?`dark`:`light`}function Q9(e){let t=document.documentElement;e===`dark`?t.classList.add(`dark`):t.classList.remove(`dark`)}Q9(Z9());function Rce({children:e}){let[t,n]=(0,F.useState)(Z9);(0,F.useLayoutEffect)(()=>{Q9(t)},[t]);let r=(0,F.useCallback)(()=>{n(e=>{let t=e===`light`?`dark`:`light`;Q9(t);try{localStorage.setItem(X9,t)}catch{}return t})},[]);return(0,L.jsx)(J9.Provider,{value:{theme:t,toggle:r},children:e})}function zce(){let e=D_(),t=_i(),{theme:n,toggle:r}=Y9(),[i,a]=(0,F.useState)(null),o=e.currentUser,s=o?.role===`admin`;return(0,F.useEffect)(()=>{o&&bh().then(a)},[o]),o?(0,L.jsxs)(`div`,{className:`h-full w-full bg-white overflow-auto`,children:[(0,L.jsx)(`div`,{className:`px-5 pt-8 pb-4 border-b border-gray-100`,children:(0,L.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,L.jsx)(`div`,{className:`w-14 h-14 rounded-full bg-gray-900 text-white text-xl flex items-center justify-center font-medium`,children:(o.id[0]??`?`).toUpperCase()}),(0,L.jsxs)(`div`,{className:`min-w-0`,children:[(0,L.jsx)(`div`,{className:`text-base font-medium text-gray-900 truncate`,children:o.id}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5`,children:[(0,L.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-gray-100 text-gray-600 font-medium`,children:o.role}),(0,L.jsx)(`span`,{className:`text-xs text-gray-400`,children:o.status})]})]})]})}),(0,L.jsxs)(`div`,{className:`px-5 py-3 border-b border-gray-100`,children:[(0,L.jsx)(`div`,{className:`text-[11px] uppercase tracking-wide text-gray-400 font-medium mb-2`,children:`Personal Repo`}),i?(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(`span`,{className:`w-2 h-2 rounded-full ${i.imported?`bg-emerald-500`:`bg-yellow-500`}`}),(0,L.jsx)(`span`,{className:`text-sm text-gray-700`,children:i.imported?`connected`:`not configured`}),(0,L.jsx)(`button`,{onClick:()=>t(`/settings/personal-repo`),className:`ml-auto text-xs text-blue-600 hover:text-blue-800`,children:`configure →`})]}):(0,L.jsx)(`div`,{className:`text-sm text-gray-400`,children:`loading…`})]}),(0,L.jsxs)(`div`,{className:`px-5 py-3 border-b border-gray-100`,children:[(0,L.jsx)(`div`,{className:`text-[11px] uppercase tracking-wide text-gray-400 font-medium mb-1`,children:`Quick Links`}),(0,L.jsxs)(`div`,{className:`flex flex-col`,children:[(0,L.jsx)($9,{icon:(0,L.jsx)(kn,{size:16}),label:`Settings`,onClick:()=>t(`/settings`)}),(0,L.jsx)($9,{icon:(0,L.jsx)(Zt,{size:16}),label:`Focus / Kanban`,onClick:()=>t(`/kanban`)}),(0,L.jsx)($9,{icon:(0,L.jsx)(pt,{size:16}),label:`Token Usage`,onClick:()=>t(`/settings/token-usage`)}),(0,L.jsx)($9,{icon:(0,L.jsx)(Qt,{size:16}),label:`API Tokens`,onClick:()=>t(`/settings/api-tokens`)}),(0,L.jsx)($9,{icon:n===`dark`?(0,L.jsx)(In,{size:16}):(0,L.jsx)(pn,{size:16}),label:`Theme: ${n===`dark`?`Dark`:`Light`}`,onClick:r}),(0,L.jsx)($9,{icon:(0,L.jsx)(Xt,{size:16}),label:`About`,onClick:()=>window.dispatchEvent(new CustomEvent(`loopat:open-about`))})]})]}),s&&(0,L.jsxs)(`div`,{className:`px-5 py-3 border-b border-gray-100`,children:[(0,L.jsx)(`div`,{className:`text-[11px] uppercase tracking-wide text-gray-400 font-medium mb-1`,children:`Admin`}),(0,L.jsxs)(`div`,{className:`flex flex-col`,children:[(0,L.jsx)($9,{icon:(0,L.jsx)(On,{size:16}),label:`Platform`,onClick:()=>t(`/admin/system`)}),(0,L.jsx)($9,{icon:(0,L.jsx)(jn,{size:16}),label:`Users`,onClick:()=>t(`/settings/admin-users`)})]})]}),(0,L.jsx)(`div`,{className:`px-5 py-3`,children:(0,L.jsxs)(`button`,{onClick:()=>{e.logout(),t(`/loop`)},className:`flex items-center gap-3 w-full px-2 py-2 rounded text-sm text-red-600 hover:bg-red-50`,children:[(0,L.jsx)(sn,{size:16}),(0,L.jsx)(`span`,{children:`Logout`})]})})]}):(0,L.jsx)(`div`,{className:`h-full w-full flex items-center justify-center text-sm text-gray-400`,children:`not logged in`})}function $9(e){return(0,L.jsxs)(`button`,{type:`button`,onClick:e.onClick,className:`flex items-center gap-3 px-2 py-2.5 rounded text-sm text-gray-700 hover:bg-gray-50 w-full text-left`,children:[(0,L.jsx)(`span`,{className:`text-gray-400 w-5 flex items-center justify-center`,children:e.icon}),(0,L.jsx)(`span`,{children:e.label})]})}function Bce({form:e,onAdvance:t}){let[n,r]=(0,F.useState)(()=>{let t={};for(let n of e.fields)n.value&&(t[n.name]=n.value);return t}),[i,a]=(0,F.useState)(!1),[o,s]=(0,F.useState)(``),c=e.fields.filter(e=>(n[e.name]??``).trim().length>0).length,l=e.require===`any`?c>=1:c===e.fields.length;return(0,L.jsxs)(`div`,{className:`max-w-2xl mx-auto mt-12 px-6 py-8 rounded-lg border border-gray-200 bg-white shadow-sm`,children:[(0,L.jsx)(`div`,{className:`text-2xl mb-2`,children:e.title}),e.description&&(0,L.jsx)(`p`,{className:`text-sm text-gray-600 leading-relaxed mb-5`,children:e.description}),(0,L.jsx)(`div`,{className:`flex flex-col gap-4`,children:e.fields.map(e=>(0,L.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,L.jsxs)(`div`,{className:`flex items-baseline justify-between`,children:[(0,L.jsx)(`label`,{className:`text-sm font-medium text-gray-800`,children:e.label}),e.help&&(0,L.jsx)(`a`,{href:e.help,target:`_blank`,rel:`noreferrer`,className:`text-xs text-blue-600 hover:text-blue-800`,children:`获取 →`})]}),(0,L.jsx)(`input`,{type:e.type===`text`?`text`:`password`,autoComplete:`off`,spellCheck:!1,placeholder:e.placeholder??e.label,value:n[e.name]??``,onChange:t=>r(n=>({...n,[e.name]:t.target.value})),className:`h-9 px-3 rounded border border-gray-300 text-sm font-mono focus:outline-none focus:border-gray-500`})]},e.name))}),o&&(0,L.jsx)(`p`,{className:`mt-3 text-sm text-red-600`,children:o}),(0,L.jsxs)(`div`,{className:`mt-6 flex items-center gap-3`,children:[(0,L.jsx)(`button`,{onClick:async()=>{a(!0),s(``);try{let r={};for(let t of e.fields){let e=(n[t.name]??``).trim();e&&(r[t.name]=e)}let i=await Sh(r);if(`error`in i){s(i.error);return}t(i)}finally{a(!1)}},disabled:!l||i,className:`px-4 h-9 rounded text-sm bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-40 disabled:cursor-not-allowed`,children:i?`处理中…`:e.submitLabel??`继续 →`}),e.require===`any`&&e.fields.length>1&&(0,L.jsx)(`span`,{className:`text-xs text-gray-400`,children:`至少填一个`})]})]})}function Vce({show:e,onAdvance:t}){let[n,r]=(0,F.useState)(!1),[i,a]=(0,F.useState)(null);return(0,L.jsxs)(`div`,{className:`max-w-2xl mx-auto mt-12 px-6 py-8 rounded-lg border border-gray-200 bg-white shadow-sm`,children:[(0,L.jsxs)(`div`,{className:`text-2xl mb-2`,children:[`🔐 `,e.title]}),e.description&&(0,L.jsx)(`p`,{className:`text-sm text-gray-600 leading-relaxed mb-4 whitespace-pre-line`,children:e.description}),e.values&&e.values.length>0&&(0,L.jsx)(`div`,{className:`flex flex-col gap-2 mb-4`,children:e.values.map(e=>(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`div`,{className:`text-[11px] text-gray-500 mb-1`,children:e.label}),(0,L.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,L.jsx)(`code`,{className:`flex-1 min-w-0 break-all bg-gray-50 border border-gray-200 rounded px-2 py-1.5 text-[10px] font-mono`,children:e.value}),(0,L.jsx)(`button`,{onClick:()=>{navigator.clipboard.writeText(e.value),a(e.label),setTimeout(()=>a(null),1500)},className:`shrink-0 text-[11px] text-gray-500 hover:text-gray-800 px-1.5 py-1`,children:i===e.label?`copied`:`copy`})]})]},e.label))}),e.help&&e.help.length>0&&(0,L.jsx)(`div`,{className:`flex flex-wrap gap-3 mb-5`,children:e.help.map(e=>(0,L.jsxs)(`a`,{href:e.url,target:`_blank`,rel:`noreferrer`,className:`text-xs text-blue-600 hover:text-blue-800`,children:[e.label,` →`]},e.url))}),(0,L.jsx)(`div`,{className:`flex items-center gap-3`,children:(0,L.jsx)(`button`,{onClick:async()=>{r(!0);let e=await xh();r(!1),e&&t(e)},disabled:n,className:`px-4 h-9 rounded text-sm bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-40`,children:n?`检查中…`:`我已配置好,重新检查`})})]})}async function Hce(e){try{if(navigator.clipboard&&window.isSecureContext)return await navigator.clipboard.writeText(e),!0}catch{}try{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.left=`-9999px`,document.body.appendChild(t),t.focus(),t.select();let n=document.execCommand(`copy`);return document.body.removeChild(t),n}catch{return!1}}function Uce({show:e,onAdvance:t}){let[n,r]=(0,F.useState)(null),[i,a]=(0,F.useState)(null),[o,s]=(0,F.useState)(``),[c,l]=(0,F.useState)(!1),[u,d]=(0,F.useState)(!1),f=(0,F.useRef)(null),p=async()=>{s(``);let e=await Ch();if(`error`in e){s(e.error);return}r(e),l(!0),m(e.device_code,e.interval)},m=(e,t)=>{f.current=window.setTimeout(async()=>{let n=await wh(e);if(n.status===`ok`){l(!1),a(n.token);return}if(n.status===`error`){l(!1),s(n.error);return}m(e,n.status===`slow_down`?t+5:t)},t*1e3)};return(0,F.useEffect)(()=>()=>{f.current&&clearTimeout(f.current)},[]),i?(0,L.jsxs)(`div`,{className:`max-w-2xl mx-auto mt-12 px-6 py-8 rounded-lg border border-gray-200 bg-white shadow-sm`,children:[(0,L.jsx)(`div`,{className:`text-2xl mb-4`,children:`选择个人仓库`}),(0,L.jsx)(U7,{initialToken:i,onDone:()=>xh().then(e=>e&&t(e))})]}):(0,L.jsxs)(`div`,{className:`max-w-2xl mx-auto mt-12 px-6 py-8 rounded-lg border border-gray-200 bg-white shadow-sm`,children:[(0,L.jsx)(`div`,{className:`text-2xl mb-2`,children:e.title}),e.description&&(0,L.jsx)(`p`,{className:`text-sm text-gray-600 leading-relaxed mb-5`,children:e.description}),n?(0,L.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,L.jsx)(`p`,{className:`text-sm text-gray-600`,children:`1. 记下/复制这个码:`}),(0,L.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,L.jsx)(`code`,{className:`text-2xl font-mono tracking-widest bg-gray-50 border border-gray-200 rounded px-4 py-2`,children:n.user_code}),(0,L.jsx)(`button`,{onClick:async()=>{await Hce(n.user_code)&&(d(!0),setTimeout(()=>d(!1),1500))},className:`text-xs text-gray-500 hover:text-gray-800`,children:u?`已复制`:`复制`})]}),(0,L.jsxs)(`p`,{className:`text-sm text-gray-600`,children:[`2. 打开 GitHub 输码授权,完成后`,(0,L.jsx)(`b`,{children:`回到本标签页`}),`,会自动继续:`]}),(0,L.jsx)(`a`,{href:n.verification_uri,target:`_blank`,rel:`noreferrer`,className:`w-fit px-4 h-9 inline-flex items-center rounded text-sm bg-gray-900 text-white hover:bg-gray-700`,children:`打开 GitHub 授权 →`}),c&&(0,L.jsx)(`p`,{className:`text-xs text-gray-400`,children:`⏳ 等待授权…授权后回到这里,会自动让你选个人仓库,别关页面。`})]}):(0,L.jsx)(`button`,{onClick:p,className:`px-4 h-9 rounded text-sm bg-gray-900 text-white hover:bg-gray-700`,children:`用 GitHub 登录 →`}),o&&(0,L.jsx)(`p`,{className:`mt-3 text-sm text-red-600`,children:o})]})}function Wce(e,t,n){let[r,i]=(0,F.useState)({}),a=(0,F.useRef)(null);(0,F.useEffect)(()=>{if(!t)return;let e=!1,r=async()=>{let t=await Jg();if(e)return;let n={};for(let e of t)n[e.id]=e.unread;i(n)},o=t=>{let r=location.protocol===`https:`?`wss:`:`ws:`,o=new WebSocket(`${r}//${location.host}/ws/chat`);a.current=o,o.onopen=()=>{for(let e of t)o.send(JSON.stringify({type:`subscribe`,convId:e}))},o.onmessage=e=>{try{let t=JSON.parse(e.data);t.type===`message`?t.message.author!==n&&i(e=>({...e,[t.message.convId]:(e[t.message.convId]??0)+1})):t.type===`conv_created`&&o.send(JSON.stringify({type:`subscribe`,convId:t.conv.id}))}catch{}},o.onclose=()=>{e||setTimeout(()=>{e||s()},3e3)},o.onerror=()=>{try{o.close()}catch{}}},s=async()=>{let t=await Jg();if(e)return;let n={};for(let e of t)n[e.id]=e.unread;i(n),o(t.map(e=>e.id))};s();let c=e=>{let t=e.detail;t?.convId&&i(e=>e[t.convId]===0?e:{...e,[t.convId]:0})},l=()=>{r().catch(()=>{})};return window.addEventListener(`loopat:chat-read`,c),window.addEventListener(`focus`,l),()=>{e=!0,window.removeEventListener(`loopat:chat-read`,c),window.removeEventListener(`focus`,l);try{a.current?.close()}catch{}a.current=null}},[t,n]),(0,F.useEffect)(()=>{if(!t)return;let n=0;for(let e in r)n+=r[e];let i=`${e} · loopat`;document.title=n>0?`(${n}) ${i}`:i},[r,e,t])}var Gce=[{id:`loop`,label:`Loop`,icon:`⑂`},{id:`kanban`,label:`Focus`,icon:`◎`},{id:`context`,label:`Context`,icon:`⌘`},{id:`chat`,label:`Chat`,icon:(0,L.jsx)(ln,{size:14})}];function Kce(){let e=T_();return(0,L.jsx)(E_.Provider,{value:e,children:e.authLoading?null:(0,L.jsx)(qce,{ws:e})})}function qce({ws:e}){let t=_i(),n=pi(),r=f6(),[i,a]=(0,F.useState)(`loopat`),[o,s]=(0,F.useState)(!1),[c,l]=(0,F.useState)(!1),[u,d]=(0,F.useState)(!1),[f,p]=(0,F.useState)(``),[m,h]=(0,F.useState)(``),{theme:g,toggle:_}=Y9(),v=e.currentUser?.id??``,y=e.currentUser?.role===`admin`,b=!!e.currentUser,x=mi(`/loop/:id`),S=!!x,C=n.pathname.startsWith(`/chat`),w=!!mi(`/chat/:convId`),T=n.pathname.startsWith(`/settings`),E=!b&&S,D=r&&!E&&b&&!S&&!w,O=S?e.loops.find(e=>e.id===x?.params.id)?.title??`Loop`:w?`Chat`:null;(0,F.useEffect)(()=>{E||hh().then(e=>{e&&(a(e),document.title=`${e} · loopat`)})},[E]),Wce(i,b&&!E,v);let k=`loopat:version-dismissed`;(0,F.useEffect)(()=>{let e=e=>{let t=e.detail?.commit;if(t){try{if(JSON.parse(localStorage.getItem(k)||`[]`).includes(t))return}catch{}p(t),h(new Date(Sg().time).toLocaleString()),d(!0)}};return window.addEventListener(`loopat:version-mismatch`,e),()=>window.removeEventListener(`loopat:version-mismatch`,e)},[]),(0,F.useEffect)(()=>{let e=()=>l(!0);return window.addEventListener(`loopat:open-about`,e),()=>window.removeEventListener(`loopat:open-about`,e)},[]),(0,F.useEffect)(()=>{if(E)return;let e=Sg();vg().then(t=>{console.log(`%cloopat %cserver:%c ${t.branch}@${t.commit.slice(0,7)} %cbuild:%c ${e.commit.slice(0,7)} @ ${e.time}`,`font-weight:bold`,`color:#666`,`color:#61afef`,`color:#666`,`color:#98c379`)})},[E]);let[A,ee]=(0,F.useState)(null);return(0,F.useEffect)(()=>{if(!b||E){ee(null);return}xh().then(ee)},[b,E]),(0,F.useEffect)(()=>{if(!b||E||!A||A.done||!A.gated||A.show.kind!==`route`)return;let e=setInterval(()=>{xh().then(ee)},3e3);return()=>clearInterval(e)},[b,E,A]),E?(0,L.jsx)(`div`,{className:`h-full w-full bg-white text-gray-900`,children:(0,L.jsx)(Ki,{})}):b?(0,L.jsxs)(`div`,{className:`h-full w-full flex flex-col bg-gray-50 text-gray-900`,children:[(0,L.jsxs)(`header`,{className:`h-12 shrink-0 border-b border-gray-200 bg-white flex items-center px-2 md:px-4 gap-2 md:gap-4 relative`,children:[(0,L.jsxs)(`div`,{className:`hidden md:flex items-center gap-2 px-1 md:px-2 h-8 shrink-0 cursor-pointer`,title:`workspace: ${i}`,onClick:()=>{window.location.href=`/`},children:[(0,L.jsx)(`span`,{className:`text-lg leading-none`,children:`🧶`}),(0,L.jsx)(`span`,{className:`text-sm text-gray-900 font-medium`,children:i})]}),r&&(S||w||T)&&(0,L.jsx)(`button`,{type:`button`,onClick:()=>{t(S?`/loop`:w?`/chat`:-1)},className:`flex items-center gap-1 px-1 h-8 shrink-0 text-gray-600 hover:text-gray-900`,"aria-label":`back`,children:(0,L.jsx)(ot,{size:18})}),r&&!E&&b&&(0,L.jsx)(`div`,{className:`absolute left-1/2 -translate-x-1/2 pointer-events-none truncate max-w-[55vw]`,children:T?(0,L.jsx)(`span`,{className:`text-sm font-medium text-gray-700`,children:`Settings`}):O?(0,L.jsx)(`span`,{className:`text-sm font-medium text-gray-700`,children:O}):(0,L.jsx)(`span`,{className:`text-lg leading-none`,children:`🧶`})}),(0,L.jsx)(`nav`,{className:`hidden md:flex items-center gap-0.5 md:gap-1`,children:Gce.map(e=>(0,L.jsxs)(Ha,{to:`/${e.id}`,className:({isActive:e})=>e?`px-2 md:px-3 h-8 rounded text-sm bg-gray-900 text-white flex items-center gap-1.5`:`px-2 md:px-3 h-8 rounded text-sm text-gray-600 hover:bg-gray-100 flex items-center gap-1.5`,children:[(0,L.jsx)(`span`,{className:`opacity-70`,children:e.icon}),(0,L.jsx)(`span`,{className:`hidden md:inline`,children:e.label})]},e.id))}),(0,L.jsx)(`div`,{className:`flex-1`}),(0,L.jsxs)(`button`,{type:`button`,onClick:()=>e.setNewLoopDialogOpen(!0),className:`flex items-center gap-1 md:gap-1.5 px-2 md:px-3 h-8 rounded text-sm bg-gray-900 text-white hover:bg-gray-700`,title:`create new loop`,children:[(0,L.jsx)(`span`,{className:`text-base leading-none`,children:`+`}),(0,L.jsx)(`span`,{className:`hidden md:inline`,children:`New Loop`})]}),(0,L.jsx)(`button`,{type:`button`,onClick:_,className:`hidden md:flex items-center justify-center w-8 h-8 rounded text-gray-400 hover:text-gray-600 hover:bg-gray-100 transition-colors`,title:g===`dark`?`Switch to light mode`:`Switch to dark mode`,children:g===`dark`?(0,L.jsx)(In,{size:16}):(0,L.jsx)(pn,{size:16})}),(0,L.jsxs)(`div`,{className:`relative`,children:[(0,L.jsxs)(`button`,{type:`button`,onClick:()=>s(e=>!e),className:`flex items-center gap-1 md:gap-2 px-1 md:px-2 h-8 rounded hover:bg-gray-100`,title:`account`,children:[(0,L.jsx)(`span`,{className:`w-6 h-6 rounded-full bg-gray-900 text-white text-xs flex items-center justify-center`,children:v[0]?.toUpperCase()??`?`}),(0,L.jsx)(`span`,{className:`hidden md:inline text-sm text-gray-700`,children:v}),(0,L.jsx)(`span`,{className:`text-gray-400 text-xs`,children:`▾`})]}),o&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>s(!1)}),(0,L.jsxs)(`div`,{className:`absolute right-0 top-full mt-1 z-20 w-40 bg-white border border-gray-200 rounded shadow-md py-1`,children:[(0,L.jsx)(`button`,{type:`button`,onClick:()=>{s(!1),t(`/settings`)},className:`w-full text-left px-3 py-1.5 text-sm text-gray-700 hover:bg-gray-100`,children:`Settings`}),y&&(0,L.jsx)(`button`,{type:`button`,onClick:()=>{s(!1),t(`/admin/system`)},className:`w-full text-left px-3 py-1.5 text-sm text-gray-700 hover:bg-gray-100`,title:`server version + activity + pull latest code`,children:`Platform`}),y&&(0,L.jsx)(`button`,{type:`button`,onClick:async()=>{s(!1);try{t(`/loop/${(await e.createLoop({title:`cross-loop distill`,mountAllLoops:!0,knowledgeRw:!0})).id}`)}catch(e){alert(e?.message??`create failed`)}},className:`w-full text-left px-3 py-1.5 text-sm text-gray-700 hover:bg-gray-100`,title:`New loop with /loopat/loops/ mounted read-only — read every loop's chat/workdir for distill`,children:`Cross-loop distill`}),(0,L.jsx)(`button`,{type:`button`,onClick:()=>{s(!1),l(!0)},className:`w-full text-left px-3 py-1.5 text-sm text-gray-700 hover:bg-gray-100`,children:`About`}),(0,L.jsx)(`button`,{type:`button`,onClick:async()=>{s(!1),await e.logout(),t(`/loop`)},className:`w-full text-left px-3 py-1.5 text-sm text-gray-700 hover:bg-gray-100`,children:`Logout`})]})]})]})]}),u&&(0,L.jsxs)(`div`,{className:`shrink-0 bg-gradient-to-r from-blue-50 to-indigo-50 border-b border-blue-200 flex items-center px-4 py-2.5 gap-2.5`,children:[(0,L.jsx)(Sn,{className:`w-4 h-4 text-blue-500 shrink-0`}),(0,L.jsxs)(`span`,{className:`text-sm text-blue-700`,children:[`New version available`,(0,L.jsxs)(`span`,{className:`text-blue-400 ml-1 text-xs`,children:[`(`,f.slice(0,7),` `,m,`)`]})]}),(0,L.jsx)(`button`,{type:`button`,className:`text-xs font-medium px-2.5 py-1 rounded bg-blue-500 text-white hover:bg-blue-600 cursor-pointer shrink-0`,onClick:()=>{try{let e=JSON.parse(localStorage.getItem(k)||`[]`);e.push(f),localStorage.setItem(k,JSON.stringify(e))}catch{}window.location.reload()},children:`Update`}),(0,L.jsx)(`button`,{type:`button`,className:`ml-auto p-0.5 rounded hover:bg-blue-100 text-blue-400 hover:text-blue-600 cursor-pointer shrink-0`,onClick:()=>{try{let e=JSON.parse(localStorage.getItem(k)||`[]`);e.push(f),localStorage.setItem(k,JSON.stringify(e))}catch{}d(!1)},"aria-label":`关闭`,children:(0,L.jsx)(Jn,{className:`w-4 h-4`})})]}),(0,L.jsx)(`main`,{className:`flex-1 min-h-0 min-w-0 overflow-hidden ${D?`pb-14`:``}`,children:(()=>{let e=A;return b&&e&&e.gated&&!e.done?e.show.kind===`route`?n.pathname===e.show.path?(0,L.jsx)(Ki,{}):(0,L.jsx)(Gi,{to:e.show.path,replace:!0}):e.show.kind===`info`?(0,L.jsx)(Vce,{show:e.show,onAdvance:ee}):e.show.kind===`device`?(0,L.jsx)(Uce,{show:e.show,onAdvance:ee}):(0,L.jsx)(Bce,{form:e.show,onAdvance:ee}):(0,L.jsx)(Ki,{})})()}),e.newLoopDialogOpen&&(0,L.jsx)(O_,{onClose:()=>e.setNewLoopDialogOpen(!1),onCreate:async n=>{let r=await e.createLoop(n);return e.kanbanCreateCtx&&await Mee(e.kanbanCreateCtx.board,e.kanbanCreateCtx.filename,e.kanbanCreateCtx.cid,r.id),e.setNewLoopDialogOpen(!1),t(`/loop/${r.id}`),r.id},initialTitle:e.newLoopDialogTitle}),(0,L.jsx)(Fee,{open:c,onClose:()=>l(!1)}),D&&(0,L.jsx)(Fce,{}),!C&&!r&&(0,L.jsx)(kce,{me:v})]}):(0,L.jsx)(Oce,{})}function Jce(){return f6()?(0,L.jsx)(Ice,{}):(0,L.jsx)(Xce,{})}function Yce(){return f6()?(0,L.jsx)(Lce,{}):(0,L.jsx)(z7,{})}function Xce(){let e=D_(),[t,n]=(0,F.useState)(null),[r,i]=(0,F.useState)(0);if((0,F.useEffect)(()=>{e.currentUser&&bh().then(e=>n(e))},[e.currentUser,r]),e.currentUser&&t===null||e.loopsLoading)return null;if(e.currentUser&&t&&!t.imported&&!G9())return(0,L.jsx)(K9,{onDismiss:()=>i(e=>e+1)});if(e.loops.length===0)return(0,L.jsx)(Zce,{loggedIn:!!e.currentUser,onNew:()=>e.setNewLoopDialogOpen(!0)});let a=e.currentUser?.id?localStorage.getItem(`loopat:lastLoop:${e.currentUser.id}`):null,o=e.currentUser?.id?e.loops.filter(t=>t.createdBy===e.currentUser.id):[];return(0,L.jsx)(Gi,{to:`/loop/${a&&e.loops.some(e=>e.id===a)?a:o.length>0?o[0].id:e.loops[0].id}`,replace:!0})}function Zce({loggedIn:e,onNew:t}){return(0,L.jsxs)(`div`,{className:`h-full w-full flex flex-col items-center justify-center text-gray-500 gap-3`,children:[(0,L.jsx)(`div`,{children:`no loops yet`}),e?(0,L.jsx)(`button`,{onClick:t,className:`px-3 h-8 rounded text-sm bg-gray-900 text-white hover:bg-gray-700`,children:`+ New Loop`}):(0,L.jsx)(`div`,{className:`text-xs text-gray-400`,children:`log in to create one`})]})}function Qce(){return(0,L.jsx)(Rce,{children:(0,L.jsx)(uh,{children:(0,L.jsx)(Ra,{children:(0,L.jsx)(Yi,{children:(0,L.jsxs)(qi,{element:(0,L.jsx)(Kce,{}),children:[(0,L.jsx)(qi,{path:`/`,element:(0,L.jsx)(Gi,{to:`/loop`,replace:!0})}),(0,L.jsx)(qi,{path:`/loop`,element:(0,L.jsx)(Jce,{})}),(0,L.jsx)(qi,{path:`/loop/:id`,element:(0,L.jsx)(wie,{})}),(0,L.jsx)(qi,{path:`/topic/:name`,element:(0,L.jsx)(Pie,{})}),(0,L.jsx)(qi,{path:`/kanban`,element:(0,L.jsx)(Gi,{to:`/kanban/default`,replace:!0})}),(0,L.jsx)(qi,{path:`/kanban/:board`,element:(0,L.jsx)(Koe,{})}),(0,L.jsx)(qi,{path:`/context`,element:(0,L.jsx)(Gi,{to:`/context/knowledge`,replace:!0})}),(0,L.jsx)(qi,{path:`/context/:sub`,element:(0,L.jsx)(Rie,{})}),(0,L.jsx)(qi,{path:`/chat`,element:(0,L.jsx)(Yce,{})}),(0,L.jsx)(qi,{path:`/chat/:convId`,element:(0,L.jsx)(z7,{})}),(0,L.jsx)(qi,{path:`/me`,element:(0,L.jsx)(zce,{})}),(0,L.jsx)(qi,{path:`/settings`,element:(0,L.jsx)(Gi,{to:`/settings/personal-repo`,replace:!0})}),(0,L.jsx)(qi,{path:`/settings/:tab`,element:(0,L.jsx)(wce,{})}),(0,L.jsx)(qi,{path:`/admin/system`,element:(0,L.jsx)(Dce,{})})]})})})})})}var $ce=class extends F.Component{state={error:null};static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){console.error(`[ErrorBoundary]`,e,t.componentStack)}reset=()=>{this.setState({error:null})};render(){if(!this.state.error)return this.props.children;let e=this.state.error;return(0,L.jsxs)(`div`,{className:`m-4 flex flex-col gap-3 rounded-md border border-red-300 bg-red-50 p-4 text-sm text-red-900`,children:[(0,L.jsx)(`div`,{className:`font-medium`,children:`UI crashed — caught by error boundary`}),(0,L.jsxs)(`pre`,{className:`overflow-auto whitespace-pre-wrap break-words rounded bg-white/70 p-2 text-xs leading-relaxed`,children:[e.name,`: `,e.message,e.stack?`\n\n${e.stack}`:``]}),(0,L.jsxs)(`div`,{className:`flex gap-2`,children:[(0,L.jsx)(`button`,{type:`button`,className:`rounded bg-red-600 px-3 py-1 text-xs font-medium text-white hover:bg-red-700`,onClick:this.reset,children:`Try again`}),(0,L.jsx)(`button`,{type:`button`,className:`rounded border border-red-300 bg-white px-3 py-1 text-xs font-medium text-red-700 hover:bg-red-100`,onClick:()=>window.location.reload(),children:`Reload page`})]})]})}};document.addEventListener(`gesturestart`,e=>e.preventDefault()),(0,Up.createRoot)(document.getElementById(`root`)).render((0,L.jsx)(F.StrictMode,{children:(0,L.jsx)($ce,{children:(0,L.jsx)(Qce,{})})}));export{LK as a,eI as c,Lh as d,zn as f,IK as i,EF as l,WK as n,QH as o,UK as r,PL as s,P0 as t,Ih as u};