@kabmo-labs/kabmo 0.38.0 → 0.38.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/dist/client/index.html +1 -1
  2. package/dist/client/index.js +420 -419
  3. package/dist/client/static/js/{CsvGrid-90zfbn7f.js → CsvGrid-t1n057vw.js} +1 -1
  4. package/dist/client/static/js/{DocxView-vwq2rf16.js → DocxView-c9g6teks.js} +1 -1
  5. package/dist/client/static/js/{DrawioView-bvx7eqcz.js → DrawioView-gd14j54m.js} +1 -1
  6. package/dist/client/static/js/{ImageView-q6xfmbrq.js → ImageView-57f1ecdp.js} +1 -1
  7. package/dist/client/static/js/{LayoutWrapper-qatdaw3n.js → LayoutWrapper-x7srbpz1.js} +1 -1
  8. package/dist/client/static/js/{Modal-6jx1fvfb.js → Modal-0bn3f77b.js} +1 -1
  9. package/dist/client/static/js/{PdfView-tkv2d2zs.js → PdfView-cybz0xbj.js} +1 -1
  10. package/dist/client/static/js/{SessionsView-rbnecykz.js → SessionsView-gx5q68tp.js} +1 -1
  11. package/dist/client/static/js/{SheetView-t08g8kdr.js → SheetView-1kk5y326.js} +1 -1
  12. package/dist/client/static/js/{SvgPreview-9vh6mdcp.js → SvgPreview-mp4tk37p.js} +1 -1
  13. package/dist/client/static/js/{abnfDiagram-O67JEVCF-bxcn33e1.js → abnfDiagram-O67JEVCF-78qb3can.js} +1 -1
  14. package/dist/client/static/js/{architectureDiagram-NJMV4G6O-40ggw6e8.js → architectureDiagram-NJMV4G6O-n0fr4hb6.js} +1 -1
  15. package/dist/client/static/js/{blockDiagram-BEXU5L5S-k41cvjrd.js → blockDiagram-BEXU5L5S-2xemfrzh.js} +1 -1
  16. package/dist/client/static/js/{c4Diagram-YGBWAQC7-rdcmn6ac.js → c4Diagram-YGBWAQC7-zxfdx3eb.js} +1 -1
  17. package/dist/client/static/js/{classDiagram-v2-NBCMYWYE-txbmbkxv.js → classDiagram-v2-NBCMYWYE-z9sasy3k.js} +1 -1
  18. package/dist/client/static/js/{cose-bilkent-JH36ORCC-bxzh3qj1.js → cose-bilkent-JH36ORCC-9byp0czh.js} +1 -1
  19. package/dist/client/static/js/{cynefinDiagram-VND7K2PF-abx5343b.js → cynefinDiagram-VND7K2PF-gnm129fx.js} +1 -1
  20. package/dist/client/static/js/{dagre-6A5THRUB-baj278kt.js → dagre-6A5THRUB-sc5tfv1w.js} +1 -1
  21. package/dist/client/static/js/{diagram-22UHCM2B-vqvhdc5m.js → diagram-22UHCM2B-hq11eek7.js} +1 -1
  22. package/dist/client/static/js/{diagram-3UASUU5V-w328rfx0.js → diagram-3UASUU5V-7bk532gd.js} +1 -1
  23. package/dist/client/static/js/{diagram-ATOU4E4O-zzcmwnm8.js → diagram-ATOU4E4O-yt8wxttm.js} +1 -1
  24. package/dist/client/static/js/{diagram-CDSNMT55-8yw39mmj.js → diagram-CDSNMT55-n3978w6p.js} +1 -1
  25. package/dist/client/static/js/{diagram-MLGK6HIB-zgc386pv.js → diagram-MLGK6HIB-004x4gyw.js} +1 -1
  26. package/dist/client/static/js/{diagram-MPIPVDR6-efmvvscm.js → diagram-MPIPVDR6-498nt489.js} +1 -1
  27. package/dist/client/static/js/{dockerfile-bp5dre33.js → dockerfile-6hbcmkc8.js} +1 -1
  28. package/dist/client/static/js/{ebnfDiagram-ZINNZB2B-p66h0dzq.js → ebnfDiagram-ZINNZB2B-5fkmymqn.js} +1 -1
  29. package/dist/client/static/js/{elk-276RUBZZ-g0jjxcqd.js → elk-276RUBZZ-6xrfa2kd.js} +1 -1
  30. package/dist/client/static/js/{erDiagram-OPXOYQCR-39gat96z.js → erDiagram-OPXOYQCR-byz4zbkn.js} +1 -1
  31. package/dist/client/static/js/flowDiagram-KWPJA3E3-s3fbfwrz.js +1 -0
  32. package/dist/client/static/js/{ganttDiagram-FUAMR5RP-nsjv1zt4.js → ganttDiagram-FUAMR5RP-4fkw1k01.js} +1 -1
  33. package/dist/client/static/js/{gitGraphDiagram-X574FWY7-r4vnkcy3.js → gitGraphDiagram-X574FWY7-19g84yw8.js} +1 -1
  34. package/dist/client/static/js/{index-hzx81cjq.js → index-0v8b5pzb.js} +1 -1
  35. package/dist/client/static/js/{index-h8h5c2r8.js → index-1j1s91c4.js} +1 -1
  36. package/dist/client/static/js/{index-6ax2z70w.js → index-20vhkcb9.js} +1 -1
  37. package/dist/client/static/js/{index-st202rjv.js → index-3wpsr2bc.js} +7 -7
  38. package/dist/client/static/js/{index-73jwm4d5.js → index-3y6krykq.js} +1 -1
  39. package/dist/client/static/js/{index-1qszrvzk.js → index-4jbbdq6n.js} +1 -1
  40. package/dist/client/static/js/{index-tfsaj5d1.js → index-4qt2e84b.js} +1 -1
  41. package/dist/client/static/js/{index-da10qpns.js → index-57z8mtmx.js} +1 -1
  42. package/dist/client/static/js/{index-ha75kff0.js → index-5gn56236.js} +1 -1
  43. package/dist/client/static/js/{index-k9xsvab3.js → index-74scnfpk.js} +1 -1
  44. package/dist/client/static/js/{index-dkseg29t.js → index-7kafzae0.js} +2 -2
  45. package/dist/client/static/js/{index-ra38ggke.js → index-89a2702q.js} +1 -1
  46. package/dist/client/static/js/{index-tv61v3t3.js → index-8j90mdgz.js} +1 -1
  47. package/dist/client/static/js/{index-50z4ek83.js → index-baet2nv8.js} +1 -1
  48. package/dist/client/static/js/{index-a74k07z2.js → index-bhng2dax.js} +1 -1
  49. package/dist/client/static/js/{index-24yyj78e.js → index-cj9193d5.js} +1 -1
  50. package/dist/client/static/js/{index-5ebhb94w.js → index-dd4q54y0.js} +1 -1
  51. package/dist/client/static/js/{index-dfgdn3fj.js → index-e3w46vsc.js} +1 -1
  52. package/dist/client/static/js/{index-rgp69pa8.js → index-e99ec2f0.js} +1 -1
  53. package/dist/client/static/js/{index-2ndq1ngv.js → index-ehnztdd2.js} +1 -1
  54. package/dist/client/static/js/{index-rqrcw8nj.js → index-epbqzayj.js} +1 -1
  55. package/dist/client/static/js/{index-vnn7m9yp.js → index-fpf1jkwd.js} +1 -1
  56. package/dist/client/static/js/{index-vxd4gykh.js → index-g252205p.js} +1 -1
  57. package/dist/client/static/js/{index-11bdd235.js → index-gxtgyya0.js} +1 -1
  58. package/dist/client/static/js/{index-tzm90bsz.js → index-j314me09.js} +1 -1
  59. package/dist/client/static/js/{index-gwhx66f4.js → index-jbwns6sc.js} +1 -1
  60. package/dist/client/static/js/{index-c15r8jd3.js → index-kdgcbt17.js} +1 -1
  61. package/dist/client/static/js/{index-rf0p3v7q.js → index-m4bjsyj2.js} +1 -1
  62. package/dist/client/static/js/{index-2drjp9ks.js → index-pfwd0160.js} +1 -1
  63. package/dist/client/static/js/{index-e1pr3k50.js → index-qntytvt0.js} +1 -1
  64. package/dist/client/static/js/{index-z0cpp5bc.js → index-rgdhyry3.js} +1 -1
  65. package/dist/client/static/js/{index-9wtg6ywn.js → index-sjnnv1gd.js} +1 -1
  66. package/dist/client/static/js/{index-5y0bvq4q.js → index-zj45wj1x.js} +2 -2
  67. package/dist/client/static/js/{index-0kxqzafy.js → index-zw7qjx65.js} +1 -1
  68. package/dist/client/static/js/{infoDiagram-VRGFBTTK-e39pvm4j.js → infoDiagram-VRGFBTTK-aw6ter0a.js} +1 -1
  69. package/dist/client/static/js/{ishikawaDiagram-OU5B5YK6-rqhszgvp.js → ishikawaDiagram-OU5B5YK6-62gst5wh.js} +1 -1
  70. package/dist/client/static/js/{journeyDiagram-ZHPQQLJL-wgy5qrsv.js → journeyDiagram-ZHPQQLJL-6kgv5a4j.js} +1 -1
  71. package/dist/client/static/js/{kanban-definition-PNTS6WVX-b8bxn0h1.js → kanban-definition-PNTS6WVX-8p3515b7.js} +1 -1
  72. package/dist/client/static/js/{mermaid.core-vb5ehtre.js → mermaid.core-b6ga2y8y.js} +2 -2
  73. package/dist/client/static/js/{mindmap-definition-NLK3R4M7-t4p38s38.js → mindmap-definition-NLK3R4M7-na9e9b4a.js} +1 -1
  74. package/dist/client/static/js/one-dark-pro-xp6ssk4z.js +1 -0
  75. package/dist/client/static/js/one-light-xgab7b02.js +1 -0
  76. package/dist/client/static/js/{pegDiagram-GJSIUBJH-3gp4madx.js → pegDiagram-GJSIUBJH-d1hk7fnq.js} +1 -1
  77. package/dist/client/static/js/{pieDiagram-5QR66LMP-0cbm773h.js → pieDiagram-5QR66LMP-7b9f4x0y.js} +1 -1
  78. package/dist/client/static/js/{quadrantDiagram-O4NWA36T-jwg7fc9f.js → quadrantDiagram-O4NWA36T-q4wxgmhg.js} +1 -1
  79. package/dist/client/static/js/{railroadDiagram-XR7U4H2S-38xh691s.js → railroadDiagram-XR7U4H2S-jngq1qx4.js} +1 -1
  80. package/dist/client/static/js/{requirementDiagram-PLB6GJNP-gpddawxh.js → requirementDiagram-PLB6GJNP-6xph3b72.js} +1 -1
  81. package/dist/client/static/js/{rust-bx3ecv4n.js → rust-w6hen2h4.js} +1 -1
  82. package/dist/client/static/js/{sankeyDiagram-IPEJSGJF-s6t6bbhk.js → sankeyDiagram-IPEJSGJF-ncfzgdj8.js} +1 -1
  83. package/dist/client/static/js/{sequenceDiagram-PO4LG4MO-wkq51pmb.js → sequenceDiagram-PO4LG4MO-sqz0yfg0.js} +1 -1
  84. package/dist/client/static/js/{sizeCapture-INFHLROL-xtwexf8k.js → sizeCapture-INFHLROL-vt8qp04d.js} +1 -1
  85. package/dist/client/static/js/{stateDiagram-v2-GCMORJYK-jnwsqa7y.js → stateDiagram-v2-GCMORJYK-myjtrmfe.js} +1 -1
  86. package/dist/client/static/js/{swimlanes-2SLR337P-mnkkqcbx.js → swimlanes-2SLR337P-z9vx7z4j.js} +1 -1
  87. package/dist/client/static/js/{swimlanesDiagram-TC7HE7FX-6xmrz03n.js → swimlanesDiagram-TC7HE7FX-5vha7thx.js} +1 -1
  88. package/dist/client/static/js/{timeline-definition-EJHVYXUP-rxq6heqh.js → timeline-definition-EJHVYXUP-z815np57.js} +1 -1
  89. package/dist/client/static/js/{usecaseDiagram-POWQR4AR-dz94f57t.js → usecaseDiagram-POWQR4AR-06ntggng.js} +1 -1
  90. package/dist/client/static/js/{vennDiagram-UO4OBE2U-5mmvkhsq.js → vennDiagram-UO4OBE2U-nmtaf5rp.js} +1 -1
  91. package/dist/client/static/js/{wardleyDiagram-VNRHLVJA-dctdntpa.js → wardleyDiagram-VNRHLVJA-zgsxmak8.js} +1 -1
  92. package/dist/client/static/js/{xychartDiagram-PMCCYNJV-njyfrqkv.js → xychartDiagram-PMCCYNJV-8bg9qdra.js} +1 -1
  93. package/package.json +1 -1
  94. package/src/server/lib/changes/capture-bash.server.ts +69 -4
  95. package/src/server/lib/changes/capture-fs.server.ts +2 -2
  96. package/src/server/lib/changes/capture-races.test.ts +107 -0
  97. package/src/server/lib/changes/capture-scan.test.ts +157 -0
  98. package/src/server/lib/changes/capture-test-util.ts +1 -1
  99. package/src/server/lib/changes/capture-types.ts +3 -1
  100. package/src/server/lib/changes/capture-write.server.ts +50 -0
  101. package/src/server/lib/changes/capture.server.ts +32 -16
  102. package/src/server/lib/changes/capture.test.ts +48 -0
  103. package/src/server/lib/changes/journal.server.ts +3 -1
  104. package/src/server/lib/changes/omp-fallback.server.ts +48 -0
  105. package/src/server/lib/changes/omp-fallback.test.ts +75 -0
  106. package/src/server/lib/changes/reader.server.ts +28 -0
  107. package/src/server/lib/changes/scan.server.ts +51 -1
  108. package/src/server/lib/changes/sessions.server.ts +65 -0
  109. package/src/server/lib/changes/sessions.test.ts +52 -0
  110. package/dist/client/static/js/flowDiagram-KWPJA3E3-f6jpcqyq.js +0 -1
  111. package/dist/client/static/js/one-dark-pro-dhybn1ff.js +0 -1
  112. package/dist/client/static/js/one-light-bqg77ay0.js +0 -1
@@ -1,2 +1,2 @@
1
- import{d,n,i,o,a,e,s,I,ne,De,Le,D,Vi,tt,Se,_e,b,ee,io,Bm}from"./index-st202rjv.js";var F={name:"list-filter",size:24,node:[["path",{d:"M2 5h20",key:"1fs1ex"}],["path",{d:"M6 12h12",key:"8npq4p"}],["path",{d:"M9 19h6",key:"456am0"}]]},M=s(F);function T({title:t,options:r,methodLabel:p,badge:m,icon:x,onCancel:g}){let f=io({title:t,options:r})?Bm(t):null,h=f?`Allow ${f.tool}`:t||p;return e("div",{className:"flex items-center justify-between border-b border-ink/8 bg-canvas/40 px-5 py-3.5",children:[e("div",{className:"flex items-center gap-3 min-w-0",children:[e("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg border border-ink/12 bg-paper text-ink shadow-xs",children:x}),e("div",{className:"min-w-0",children:[e("div",{className:"flex items-center gap-2",children:[e("h3",{className:"truncate text-[14px] font-semibold tracking-tight text-ink",children:h}),e("span",{className:"flex items-center gap-1 rounded-full border border-ink/10 bg-paper px-2 py-0.5 font-mono text-[10px] font-medium tracking-wider text-ink/60 uppercase",children:[e(Le,{size:9,className:"text-ink/40"}),m]})]}),e("p",{className:"mt-0.5 text-[11px] text-ink/50",children:f?"The agent wants to run this. Review it before you allow.":"Autonomous agent inquiry requiring user confirmation"})]})]}),e("button",{type:"button",onClick:g,"aria-label":"Close dialog (Esc)",title:"Cancel (Esc)",className:"flex h-7 w-7 shrink-0 cursor-pointer items-center justify-center rounded-lg border border-ink/10 text-ink/45 transition-colors hover:border-ink/25 hover:bg-ink/5 hover:text-ink",children:e(b,{size:14})})]})}function S({options:t,optionDetails:r,selectedOption:p,customValue:m,onCustomChange:x,customInputRef:g,onSelect:f,onConfirmOption:h,hideCustomAnswer:l=!1}){return e("div",{className:"space-y-2",children:[e("div",{className:"flex items-center justify-between text-[11px] font-medium tracking-wider text-ink/50 uppercase",children:[e("span",{children:"Available Options"}),e("span",{className:"font-mono text-[10px] text-ink/40",children:["Press [1-",Math.min(9,t.length),"] to choose"]})]}),e("div",{className:"grid gap-2",role:"radiogroup",children:t.map((k,y)=>{let u=p===k,v=r[y]?.description;return e("button",{type:"button",onClick:()=>f(k),onDblClick:()=>h(k),"aria-checked":u,role:"radio",className:`group flex w-full cursor-pointer items-start gap-3 rounded-xl border p-3.5 text-left transition-all ${u?"border-ink bg-paper shadow-sm ring-1 ring-ink/10":"border-ink/10 bg-canvas/30 hover:border-ink/25 hover:bg-paper"}`,children:[e("span",{className:`flex h-6 w-6 shrink-0 items-center justify-center rounded-md font-mono text-[11px] font-semibold transition-colors ${u?"bg-ink text-paper":"border border-ink/15 bg-paper text-ink/60 group-hover:border-ink/30 group-hover:text-ink"}`,children:y+1}),e("div",{className:"min-w-0 flex-1",children:[e("div",{className:"flex items-center gap-2",children:e("span",{className:`text-[13px] font-medium leading-snug ${u?"text-ink font-semibold":"text-ink/85"}`,children:k})}),v&&e("div",{className:"mt-1 text-[11.5px] leading-relaxed text-ink/55",children:v})]}),e("span",{className:"mt-0.5 shrink-0",children:u?e(ne,{size:16,className:"text-ink"}):e(Vi,{size:16,className:"text-ink/20 group-hover:text-ink/40"})})]},k)})}),!l&&e("div",{className:"space-y-1.5 pt-1",children:[e("div",{className:"text-[11px] font-medium tracking-wider text-ink/50 uppercase",children:"Other: type your own answer"}),e("input",{ref:g,type:"text",value:m,placeholder:"Type a custom answer and press Enter...",onChange:(k)=>x(k.currentTarget.value),onKeyDown:(k)=>{if(k.key==="Enter"){if(k.preventDefault(),k.stopPropagation(),m.trim())h(m.trim())}},className:"w-full rounded-xl border border-ink/15 bg-paper px-4 py-3 text-[13.5px] text-ink placeholder:text-ink/35 outline-none transition-all focus:border-ink focus:ring-2 focus:ring-ink/15"})]})]})}function P({method:t,optionsLength:r,selectedOption:p,hasCustomAnswer:m=!1,onCancel:x,onSubmit:g}){let f=t==="select"&&!p&&!m;return e("div",{className:"flex flex-wrap items-center justify-between gap-3 border-t border-ink/8 bg-canvas/40 px-5 py-3.5",children:[e("div",{className:"flex items-center gap-2 font-mono text-[11px] text-ink/50",children:[t==="select"&&e(d,{children:[e("span",{className:"hidden items-center gap-1 sm:inline-flex",children:[e("kbd",{className:"rounded border border-ink/15 bg-paper px-1.5 py-0.5 text-[10px] text-ink shadow-xs",children:["1-",Math.min(9,r)]}),e("span",{className:"text-ink/40",children:"choose"})]}),e("span",{className:"hidden text-ink/30 sm:inline",children:"•"}),e("span",{className:"inline-flex items-center gap-1",children:[e("kbd",{className:"rounded border border-ink/15 bg-paper px-1.5 py-0.5 text-[10px] text-ink shadow-xs",children:"↵"}),e("span",{className:"text-ink/40",children:"select"})]})]}),t==="confirm"&&e("span",{className:"inline-flex items-center gap-1",children:[e("kbd",{className:"rounded border border-ink/15 bg-paper px-1.5 py-0.5 text-[10px] text-ink shadow-xs",children:"↵"}),e("span",{className:"text-ink/40",children:"confirm"})]}),t==="editor"&&e("span",{className:"inline-flex items-center gap-1",children:[e("kbd",{className:"rounded border border-ink/15 bg-paper px-1.5 py-0.5 text-[10px] text-ink shadow-xs",children:"⌘↵"}),e("span",{className:"text-ink/40",children:"save buffer"})]}),e("span",{className:"text-ink/30",children:"•"}),e("span",{className:"inline-flex items-center gap-1",children:[e("kbd",{className:"rounded border border-ink/15 bg-paper px-1.5 py-0.5 text-[10px] text-ink shadow-xs",children:"Esc"}),e("span",{className:"text-ink/40",children:"cancel"})]})]}),e("div",{className:"flex items-center gap-2.5 ml-auto",children:[e("button",{type:"button",onClick:x,className:"flex cursor-pointer items-center gap-1 rounded-lg border border-ink/15 bg-paper px-3.5 py-1.5 text-[12px] font-medium text-ink/70 transition-colors hover:border-ink/30 hover:bg-canvas/50 hover:text-ink",children:[e(b,{size:12,className:"opacity-60"}),e("span",{children:"Cancel"})]}),e("button",{type:"button",onClick:g,disabled:f,className:"flex cursor-pointer items-center gap-1.5 rounded-lg bg-ink px-4 py-1.5 text-[12px] font-semibold text-paper shadow-xs transition-all hover:opacity-90 active:scale-[0.98] disabled:cursor-not-allowed disabled:opacity-35",children:[e("span",{children:t==="confirm"?"Confirm":t==="select"?"Select Option":"Submit Response"}),e(tt,{size:12,className:"opacity-70"})]})]})]})}function R({title:t,options:r}){let p=io({title:t,options:r})?Bm(t):null;if(!p)return null;return e("div",{className:"space-y-2",children:[p.reason&&e("div",{className:"flex items-start gap-2 rounded-xl border border-warning/25 bg-warning/8 px-3.5 py-2.5 text-[12px] leading-relaxed text-ink/80",children:[e(D,{size:13,className:"mt-0.5 shrink-0 text-warning"}),e("span",{className:"min-w-0 break-words",children:p.reason})]}),p.details.length>0&&e("div",{className:"rounded-xl border border-ink/10 bg-canvas/40 px-3.5 py-2.5",children:p.details.map((m,x)=>e("div",{className:"font-mono text-[11.5px] leading-relaxed text-ink/75 break-all",children:m},`${x}-${m}`))})]})}function L({method:t,options:r,selectedOption:p,onSelectOption:m,customInputRef:x,onSubmit:g,onCancel:f}){i(()=>{let h=(l)=>{if(l.key==="Escape"){l.preventDefault(),l.stopPropagation(),f();return}if(t==="select"&&r.length>0){if(l.target instanceof HTMLInputElement&&l.target===x.current)return;let y=parseInt(l.key,10);if(!isNaN(y)&&y>=1&&y<=r.length){l.preventDefault(),m(r[y-1]);return}if(l.key==="ArrowDown"){l.preventDefault();let u=r.findIndex((N)=>N===p),v=u<r.length-1?u+1:0;m(r[v]);return}if(l.key==="ArrowUp"){l.preventDefault();let u=r.findIndex((N)=>N===p),v=u>0?u-1:r.length-1;m(r[v]);return}if(l.key==="Enter"&&p){l.preventDefault(),g();return}}if(t==="confirm"){if(l.key==="Enter"){l.preventDefault(),g();return}}if(t==="editor"){if((l.metaKey||l.ctrlKey)&&l.key==="Enter"){l.preventDefault(),g();return}}};return window.addEventListener("keydown",h),()=>window.removeEventListener("keydown",h)},[f,g,t,r,p,m,x])}function O(t,r){switch(t){case"select":return{icon:e(M,{size:16,className:"text-ink"}),label:"Decision Required",badge:`${r} Choices`};case"confirm":return{icon:e(I,{size:16,className:"text-ink"}),label:"Confirmation Required",badge:"Confirm Action"};case"input":return{icon:e(_e,{size:16,className:"text-ink"}),label:"Prompt Input",badge:"Text Input"};case"editor":return{icon:e(Se,{size:16,className:"text-ink"}),label:"Buffer Editor",badge:"Multiline Buffer"};default:return{icon:e(De,{size:16,className:"text-ink"}),label:"Agent Request",badge:"Input"}}}function ke({request:t,onRespond:r}){let[p,m]=n(t.method==="editor"?t.prefill??"":""),[x,g]=n(null),[f,h]=n(""),l=o(null),k=o(null),y=o(null),u=o(null),v=t.options??[],N=t.optionDetails??[],E=io(t);i(()=>{let c=t.options??[];m(t.method==="editor"?t.prefill??"":""),g(c.length>0?c[0]:null),h("")},[t]),i(()=>{if(l.current?.focus(),t.method==="input")k.current?.focus();else if(t.method==="editor")y.current?.focus();else if(t.method==="select"){if((t.options??[]).some((B)=>/^other\b/i.test(B.trim())))u.current?.focus()}},[t]);let w=a(()=>{r(t,{cancelled:!0})},[r,t]),A=a(()=>{if(t.method==="confirm")r(t,{confirmed:!0});else if(t.method==="select"){if(f.trim()&&!E)r(t,{value:f.trim()});else if(x)r(t,{value:x})}else r(t,{value:p})},[r,t,x,p,f,E]),z=a((c)=>{if(/^other\b/i.test(c.trim())){g(c),u.current?.focus();return}r(t,{value:c})},[r,t]),H=a((c)=>{if(g(c),/^other\b/i.test(c.trim()))u.current?.focus()},[]);L({method:t.method,options:v,selectedOption:x,onSelectOption:g,customInputRef:u,onSubmit:A,onCancel:w});let C=O(t.method,v.length);return e("div",{className:"extension-dialog-backdrop modal-scrim fixed inset-0 z-50 flex items-center justify-center p-4 sm:p-6 backdrop-blur-[8px]",onMouseDown:(c)=>{if(c.target===c.currentTarget)w()},children:e("div",{ref:l,role:"dialog","aria-modal":"true","aria-label":t.title||C.label,tabIndex:-1,className:"glass-overlay extension-dialog-panel w-full max-w-[560px] overflow-hidden rounded-2xl border border-ink/15 bg-paper shadow-2xl outline-none",style:{boxShadow:"0 24px 64px -8px color-mix(in srgb, var(--theme-ink) 28%, transparent)"},children:[e(T,{title:t.title,options:v,methodLabel:C.label,badge:C.badge,icon:C.icon,onCancel:w}),e("div",{className:"max-h-[65vh] overflow-y-auto px-6 py-5 space-y-4",children:[e(R,{title:t.title,options:v}),t.message&&e("div",{className:"rounded-xl border border-ink/8 bg-canvas/40 p-4 text-[13px] leading-relaxed text-ink/85 select-text",children:e(ee,{content:t.message})}),t.method==="select"&&e(S,{options:v,optionDetails:N,selectedOption:x,customValue:f,onCustomChange:h,customInputRef:u,onSelect:H,onConfirmOption:z,hideCustomAnswer:E}),t.method==="confirm"&&e("div",{className:"flex items-center gap-3 rounded-xl border border-ink/10 bg-canvas/30 p-4",children:[e("div",{className:"flex h-9 w-9 shrink-0 items-center justify-center rounded-lg bg-ink/5 text-ink",children:e(ne,{size:18})}),e("div",{className:"text-[12.5px] leading-relaxed text-ink/75",children:["Confirming will allow the autonomous agent to proceed with this operation. Press ",e("kbd",{className:"rounded border border-ink/20 bg-paper px-1 py-0.2 font-mono text-[10.5px]",children:"Enter"})," to confirm or ",e("kbd",{className:"rounded border border-ink/20 bg-paper px-1 py-0.2 font-mono text-[10.5px]",children:"Esc"})," to abort."]})]}),t.method==="input"&&e("div",{className:"space-y-2",children:[e("div",{className:"flex items-center justify-between text-[11px] font-medium tracking-wider text-ink/50 uppercase",children:[e("span",{children:"Your Response"}),e("span",{className:"font-mono text-[10px] text-ink/40",children:"Press [Enter] to submit"})]}),e("input",{ref:k,type:t.secret===!0?"password":"text",value:p,placeholder:t.placeholder||"Type your response...",onChange:(c)=>m(c.currentTarget.value),onKeyDown:(c)=>{if(c.key==="Enter")c.preventDefault(),A()},className:"w-full rounded-xl border border-ink/15 bg-paper px-4 py-3 text-[13.5px] text-ink placeholder:text-ink/35 outline-none transition-all focus:border-ink focus:ring-2 focus:ring-ink/15"})]}),t.method==="editor"&&e("div",{className:"space-y-2",children:[e("div",{className:"flex items-center justify-between text-[11px] font-medium tracking-wider text-ink/50 uppercase",children:[e("span",{children:"Buffer Content"}),e("span",{className:"font-mono text-[10px] text-ink/40",children:[p.split(`
1
+ import{d,n,i,o,a,e,s,I,ne,De,Le,D,Vi,tt,Se,_e,b,ee,io,Bm}from"./index-3wpsr2bc.js";var F={name:"list-filter",size:24,node:[["path",{d:"M2 5h20",key:"1fs1ex"}],["path",{d:"M6 12h12",key:"8npq4p"}],["path",{d:"M9 19h6",key:"456am0"}]]},M=s(F);function T({title:t,options:r,methodLabel:p,badge:m,icon:x,onCancel:g}){let f=io({title:t,options:r})?Bm(t):null,h=f?`Allow ${f.tool}`:t||p;return e("div",{className:"flex items-center justify-between border-b border-ink/8 bg-canvas/40 px-5 py-3.5",children:[e("div",{className:"flex items-center gap-3 min-w-0",children:[e("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg border border-ink/12 bg-paper text-ink shadow-xs",children:x}),e("div",{className:"min-w-0",children:[e("div",{className:"flex items-center gap-2",children:[e("h3",{className:"truncate text-[14px] font-semibold tracking-tight text-ink",children:h}),e("span",{className:"flex items-center gap-1 rounded-full border border-ink/10 bg-paper px-2 py-0.5 font-mono text-[10px] font-medium tracking-wider text-ink/60 uppercase",children:[e(Le,{size:9,className:"text-ink/40"}),m]})]}),e("p",{className:"mt-0.5 text-[11px] text-ink/50",children:f?"The agent wants to run this. Review it before you allow.":"Autonomous agent inquiry requiring user confirmation"})]})]}),e("button",{type:"button",onClick:g,"aria-label":"Close dialog (Esc)",title:"Cancel (Esc)",className:"flex h-7 w-7 shrink-0 cursor-pointer items-center justify-center rounded-lg border border-ink/10 text-ink/45 transition-colors hover:border-ink/25 hover:bg-ink/5 hover:text-ink",children:e(b,{size:14})})]})}function S({options:t,optionDetails:r,selectedOption:p,customValue:m,onCustomChange:x,customInputRef:g,onSelect:f,onConfirmOption:h,hideCustomAnswer:l=!1}){return e("div",{className:"space-y-2",children:[e("div",{className:"flex items-center justify-between text-[11px] font-medium tracking-wider text-ink/50 uppercase",children:[e("span",{children:"Available Options"}),e("span",{className:"font-mono text-[10px] text-ink/40",children:["Press [1-",Math.min(9,t.length),"] to choose"]})]}),e("div",{className:"grid gap-2",role:"radiogroup",children:t.map((k,y)=>{let u=p===k,v=r[y]?.description;return e("button",{type:"button",onClick:()=>f(k),onDblClick:()=>h(k),"aria-checked":u,role:"radio",className:`group flex w-full cursor-pointer items-start gap-3 rounded-xl border p-3.5 text-left transition-all ${u?"border-ink bg-paper shadow-sm ring-1 ring-ink/10":"border-ink/10 bg-canvas/30 hover:border-ink/25 hover:bg-paper"}`,children:[e("span",{className:`flex h-6 w-6 shrink-0 items-center justify-center rounded-md font-mono text-[11px] font-semibold transition-colors ${u?"bg-ink text-paper":"border border-ink/15 bg-paper text-ink/60 group-hover:border-ink/30 group-hover:text-ink"}`,children:y+1}),e("div",{className:"min-w-0 flex-1",children:[e("div",{className:"flex items-center gap-2",children:e("span",{className:`text-[13px] font-medium leading-snug ${u?"text-ink font-semibold":"text-ink/85"}`,children:k})}),v&&e("div",{className:"mt-1 text-[11.5px] leading-relaxed text-ink/55",children:v})]}),e("span",{className:"mt-0.5 shrink-0",children:u?e(ne,{size:16,className:"text-ink"}):e(Vi,{size:16,className:"text-ink/20 group-hover:text-ink/40"})})]},k)})}),!l&&e("div",{className:"space-y-1.5 pt-1",children:[e("div",{className:"text-[11px] font-medium tracking-wider text-ink/50 uppercase",children:"Other: type your own answer"}),e("input",{ref:g,type:"text",value:m,placeholder:"Type a custom answer and press Enter...",onChange:(k)=>x(k.currentTarget.value),onKeyDown:(k)=>{if(k.key==="Enter"){if(k.preventDefault(),k.stopPropagation(),m.trim())h(m.trim())}},className:"w-full rounded-xl border border-ink/15 bg-paper px-4 py-3 text-[13.5px] text-ink placeholder:text-ink/35 outline-none transition-all focus:border-ink focus:ring-2 focus:ring-ink/15"})]})]})}function P({method:t,optionsLength:r,selectedOption:p,hasCustomAnswer:m=!1,onCancel:x,onSubmit:g}){let f=t==="select"&&!p&&!m;return e("div",{className:"flex flex-wrap items-center justify-between gap-3 border-t border-ink/8 bg-canvas/40 px-5 py-3.5",children:[e("div",{className:"flex items-center gap-2 font-mono text-[11px] text-ink/50",children:[t==="select"&&e(d,{children:[e("span",{className:"hidden items-center gap-1 sm:inline-flex",children:[e("kbd",{className:"rounded border border-ink/15 bg-paper px-1.5 py-0.5 text-[10px] text-ink shadow-xs",children:["1-",Math.min(9,r)]}),e("span",{className:"text-ink/40",children:"choose"})]}),e("span",{className:"hidden text-ink/30 sm:inline",children:"•"}),e("span",{className:"inline-flex items-center gap-1",children:[e("kbd",{className:"rounded border border-ink/15 bg-paper px-1.5 py-0.5 text-[10px] text-ink shadow-xs",children:"↵"}),e("span",{className:"text-ink/40",children:"select"})]})]}),t==="confirm"&&e("span",{className:"inline-flex items-center gap-1",children:[e("kbd",{className:"rounded border border-ink/15 bg-paper px-1.5 py-0.5 text-[10px] text-ink shadow-xs",children:"↵"}),e("span",{className:"text-ink/40",children:"confirm"})]}),t==="editor"&&e("span",{className:"inline-flex items-center gap-1",children:[e("kbd",{className:"rounded border border-ink/15 bg-paper px-1.5 py-0.5 text-[10px] text-ink shadow-xs",children:"⌘↵"}),e("span",{className:"text-ink/40",children:"save buffer"})]}),e("span",{className:"text-ink/30",children:"•"}),e("span",{className:"inline-flex items-center gap-1",children:[e("kbd",{className:"rounded border border-ink/15 bg-paper px-1.5 py-0.5 text-[10px] text-ink shadow-xs",children:"Esc"}),e("span",{className:"text-ink/40",children:"cancel"})]})]}),e("div",{className:"flex items-center gap-2.5 ml-auto",children:[e("button",{type:"button",onClick:x,className:"flex cursor-pointer items-center gap-1 rounded-lg border border-ink/15 bg-paper px-3.5 py-1.5 text-[12px] font-medium text-ink/70 transition-colors hover:border-ink/30 hover:bg-canvas/50 hover:text-ink",children:[e(b,{size:12,className:"opacity-60"}),e("span",{children:"Cancel"})]}),e("button",{type:"button",onClick:g,disabled:f,className:"flex cursor-pointer items-center gap-1.5 rounded-lg bg-ink px-4 py-1.5 text-[12px] font-semibold text-paper shadow-xs transition-all hover:opacity-90 active:scale-[0.98] disabled:cursor-not-allowed disabled:opacity-35",children:[e("span",{children:t==="confirm"?"Confirm":t==="select"?"Select Option":"Submit Response"}),e(tt,{size:12,className:"opacity-70"})]})]})]})}function R({title:t,options:r}){let p=io({title:t,options:r})?Bm(t):null;if(!p)return null;return e("div",{className:"space-y-2",children:[p.reason&&e("div",{className:"flex items-start gap-2 rounded-xl border border-warning/25 bg-warning/8 px-3.5 py-2.5 text-[12px] leading-relaxed text-ink/80",children:[e(D,{size:13,className:"mt-0.5 shrink-0 text-warning"}),e("span",{className:"min-w-0 break-words",children:p.reason})]}),p.details.length>0&&e("div",{className:"rounded-xl border border-ink/10 bg-canvas/40 px-3.5 py-2.5",children:p.details.map((m,x)=>e("div",{className:"font-mono text-[11.5px] leading-relaxed text-ink/75 break-all",children:m},`${x}-${m}`))})]})}function L({method:t,options:r,selectedOption:p,onSelectOption:m,customInputRef:x,onSubmit:g,onCancel:f}){i(()=>{let h=(l)=>{if(l.key==="Escape"){l.preventDefault(),l.stopPropagation(),f();return}if(t==="select"&&r.length>0){if(l.target instanceof HTMLInputElement&&l.target===x.current)return;let y=parseInt(l.key,10);if(!isNaN(y)&&y>=1&&y<=r.length){l.preventDefault(),m(r[y-1]);return}if(l.key==="ArrowDown"){l.preventDefault();let u=r.findIndex((N)=>N===p),v=u<r.length-1?u+1:0;m(r[v]);return}if(l.key==="ArrowUp"){l.preventDefault();let u=r.findIndex((N)=>N===p),v=u>0?u-1:r.length-1;m(r[v]);return}if(l.key==="Enter"&&p){l.preventDefault(),g();return}}if(t==="confirm"){if(l.key==="Enter"){l.preventDefault(),g();return}}if(t==="editor"){if((l.metaKey||l.ctrlKey)&&l.key==="Enter"){l.preventDefault(),g();return}}};return window.addEventListener("keydown",h),()=>window.removeEventListener("keydown",h)},[f,g,t,r,p,m,x])}function O(t,r){switch(t){case"select":return{icon:e(M,{size:16,className:"text-ink"}),label:"Decision Required",badge:`${r} Choices`};case"confirm":return{icon:e(I,{size:16,className:"text-ink"}),label:"Confirmation Required",badge:"Confirm Action"};case"input":return{icon:e(_e,{size:16,className:"text-ink"}),label:"Prompt Input",badge:"Text Input"};case"editor":return{icon:e(Se,{size:16,className:"text-ink"}),label:"Buffer Editor",badge:"Multiline Buffer"};default:return{icon:e(De,{size:16,className:"text-ink"}),label:"Agent Request",badge:"Input"}}}function ke({request:t,onRespond:r}){let[p,m]=n(t.method==="editor"?t.prefill??"":""),[x,g]=n(null),[f,h]=n(""),l=o(null),k=o(null),y=o(null),u=o(null),v=t.options??[],N=t.optionDetails??[],E=io(t);i(()=>{let c=t.options??[];m(t.method==="editor"?t.prefill??"":""),g(c.length>0?c[0]:null),h("")},[t]),i(()=>{if(l.current?.focus(),t.method==="input")k.current?.focus();else if(t.method==="editor")y.current?.focus();else if(t.method==="select"){if((t.options??[]).some((B)=>/^other\b/i.test(B.trim())))u.current?.focus()}},[t]);let w=a(()=>{r(t,{cancelled:!0})},[r,t]),A=a(()=>{if(t.method==="confirm")r(t,{confirmed:!0});else if(t.method==="select"){if(f.trim()&&!E)r(t,{value:f.trim()});else if(x)r(t,{value:x})}else r(t,{value:p})},[r,t,x,p,f,E]),z=a((c)=>{if(/^other\b/i.test(c.trim())){g(c),u.current?.focus();return}r(t,{value:c})},[r,t]),H=a((c)=>{if(g(c),/^other\b/i.test(c.trim()))u.current?.focus()},[]);L({method:t.method,options:v,selectedOption:x,onSelectOption:g,customInputRef:u,onSubmit:A,onCancel:w});let C=O(t.method,v.length);return e("div",{className:"extension-dialog-backdrop modal-scrim fixed inset-0 z-50 flex items-center justify-center p-4 sm:p-6 backdrop-blur-[8px]",onMouseDown:(c)=>{if(c.target===c.currentTarget)w()},children:e("div",{ref:l,role:"dialog","aria-modal":"true","aria-label":t.title||C.label,tabIndex:-1,className:"glass-overlay extension-dialog-panel w-full max-w-[560px] overflow-hidden rounded-2xl border border-ink/15 bg-paper shadow-2xl outline-none",style:{boxShadow:"0 24px 64px -8px color-mix(in srgb, var(--theme-ink) 28%, transparent)"},children:[e(T,{title:t.title,options:v,methodLabel:C.label,badge:C.badge,icon:C.icon,onCancel:w}),e("div",{className:"max-h-[65vh] overflow-y-auto px-6 py-5 space-y-4",children:[e(R,{title:t.title,options:v}),t.message&&e("div",{className:"rounded-xl border border-ink/8 bg-canvas/40 p-4 text-[13px] leading-relaxed text-ink/85 select-text",children:e(ee,{content:t.message})}),t.method==="select"&&e(S,{options:v,optionDetails:N,selectedOption:x,customValue:f,onCustomChange:h,customInputRef:u,onSelect:H,onConfirmOption:z,hideCustomAnswer:E}),t.method==="confirm"&&e("div",{className:"flex items-center gap-3 rounded-xl border border-ink/10 bg-canvas/30 p-4",children:[e("div",{className:"flex h-9 w-9 shrink-0 items-center justify-center rounded-lg bg-ink/5 text-ink",children:e(ne,{size:18})}),e("div",{className:"text-[12.5px] leading-relaxed text-ink/75",children:["Confirming will allow the autonomous agent to proceed with this operation. Press ",e("kbd",{className:"rounded border border-ink/20 bg-paper px-1 py-0.2 font-mono text-[10.5px]",children:"Enter"})," to confirm or ",e("kbd",{className:"rounded border border-ink/20 bg-paper px-1 py-0.2 font-mono text-[10.5px]",children:"Esc"})," to abort."]})]}),t.method==="input"&&e("div",{className:"space-y-2",children:[e("div",{className:"flex items-center justify-between text-[11px] font-medium tracking-wider text-ink/50 uppercase",children:[e("span",{children:"Your Response"}),e("span",{className:"font-mono text-[10px] text-ink/40",children:"Press [Enter] to submit"})]}),e("input",{ref:k,type:t.secret===!0?"password":"text",value:p,placeholder:t.placeholder||"Type your response...",onChange:(c)=>m(c.currentTarget.value),onKeyDown:(c)=>{if(c.key==="Enter")c.preventDefault(),A()},className:"w-full rounded-xl border border-ink/15 bg-paper px-4 py-3 text-[13.5px] text-ink placeholder:text-ink/35 outline-none transition-all focus:border-ink focus:ring-2 focus:ring-ink/15"})]}),t.method==="editor"&&e("div",{className:"space-y-2",children:[e("div",{className:"flex items-center justify-between text-[11px] font-medium tracking-wider text-ink/50 uppercase",children:[e("span",{children:"Buffer Content"}),e("span",{className:"font-mono text-[10px] text-ink/40",children:[p.split(`
2
2
  `).length," lines · ⌘↵ to save"]})]}),e("textarea",{ref:y,value:p,onChange:(c)=>m(c.currentTarget.value),rows:8,placeholder:t.placeholder||"Enter content...",className:"w-full rounded-xl border border-ink/15 bg-canvas/30 px-4 py-3 font-mono text-[12px] leading-relaxed text-ink placeholder:text-ink/35 outline-none transition-all focus:border-ink focus:bg-paper focus:ring-2 focus:ring-ink/15"})]})]}),e(P,{method:t.method,optionsLength:v.length,selectedOption:x,hasCustomAnswer:f.trim().length>0,onCancel:w,onSubmit:A})]})})}export{ke as ExtensionDialog};
@@ -1,2 +1,2 @@
1
- import{t,l,E,p,W,Z,la,ca,xA,Pr,si,wA,Is,$t,CA,Ef,ua,li,Ss}from"./index-5y0bvq4q.js";import{$e}from"./index-r83kr4s5.js";function Ad(e,{edgePathsClass:r="edges edgePaths"}={}){let n=e.insert("g").attr("class","root"),i=n.insert("g").attr("class","clusters"),s=n.insert("g").attr("class",r),o=n.insert("g").attr("class","edgeLabels"),c=n.insert("g").attr("class","nodes");return{clusters:i,edgePaths:s,edgeLabels:o,nodes:c,rootGroups:n}}t(Ad,"createLayoutElementGroups");async function L(e,r,n){if(r.label){let{shapeSvg:i,bbox:s}=await Z(e,n===void 0?r:{...r,width:n});r.labelBBox={width:s.width,height:s.height},i.remove()}else r.labelBBox={width:0,height:0}}t(L,"measureGroupLabel");async function gd(e,r,n){let i=await ca(e,r,n),s=i.node()?.getBBox()??{width:0,height:0};return r.width=s.width,r.height=s.height,i}t(gd,"insertMeasuredNode");function D(e,r,n){let i=e,s=new Set;while(i){if(i.dir)return i.dir;if(!i.parentId||s.has(i.parentId))break;s.add(i.parentId),i=r.get(i.parentId)}return n}t(D,"resolveNodeDir");async function S(e,r,n={}){let i=new $e({multigraph:!0,compound:!0}),s=[...r.edges],o=p(),c=Ad(e),{edgeLabels:f,nodes:a}=c,d=new Map,m=new Map(r.nodes.map((u)=>[u.id,u])),y=r.direction,b=e.node()!=null;await Promise.all(r.nodes.map(async(u)=>{if(u.isGroup){if(b){let h=n.unwrapGroupLabels&&u.labelType!=="markdown";await L(a,u,h?Number.POSITIVE_INFINITY:void 0)}i.setNode(u.id,{...u})}else{if(b){let h=await gd(a,u,{config:o,dir:D(u,m,y)});d.set(u.id,h)}i.setNode(u.id,{...u})}}));for(let u of s){if(b&&Ef(u))await ua(f,u);if(i.setEdge(u.start,u.end,{...u},u.id),!r.edges.some((v)=>v.id===u.id))r.edges.push(u)}if(globalThis.mermaidCaptureSizes){let{captureNodeSizes:u}=await import("./sizeCapture-INFHLROL-xtwexf8k.js");u(e,r)}return{graph:i,groups:c,nodeElements:d}}t(S,"createGraphWithElements");var Ae=new Map,g=new Map,P=new Map,V=t(()=>{g.clear(),P.clear(),Ae.clear()},"clear"),w=t((e,r)=>{let n=g.get(r)||[];return l.trace("In isDescendant",r," ",e," = ",n.includes(e)),n.includes(e)},"isDescendant"),Y=t((e,r)=>{let n=g.get(r)||[];if(l.info("Descendants of ",r," is ",n),l.info("Edge is ",e),e.v===r||e.w===r)return!1;if(!n)return l.debug("Tilt, ",r,",not in descendants"),!1;return n.includes(e.v)||w(e.v,r)||w(e.w,r)||n.includes(e.w)},"edgeInCluster"),k=t((e,r,n,i)=>{l.debug("Copying children of ",e,"root",i,"data",r.node(e),i);let s=r.children(e)||[];if(e!==i)s.push(e);l.debug("Copying (nodes) clusterId",e,"nodes",s),s.forEach((o)=>{if(r.children(o).length>0)k(o,r,n,i);else{let c=r.node(o);if(l.info("cp ",o," to ",i," with parent ",e),n.setNode(o,c),i!==r.parent(o))l.debug("Setting parent",o,r.parent(o)),n.setParent(o,r.parent(o));if(e!==i&&o!==e)l.debug("Setting parent",o,e),n.setParent(o,e);else l.info("In copy ",e,"root",i,"data",r.node(e),i),l.debug("Not Setting parent for node=",o,"cluster!==rootId",e!==i,"node!==clusterId",o!==e);let f=r.edges(o);l.debug("Copying Edges",f),f.forEach((a)=>{l.info("Edge",a);let d=r.edge(a.v,a.w,a.name);l.info("Edge data",d,i);try{if(Y(a,i))l.info("Copying as ",a.v,a.w,d,a.name),n.setEdge(a.v,a.w,d,a.name),l.info("newGraph edges ",n.edges(),n.edge(n.edges()[0]));else l.info("Skipping copy of edge ",a.v,"-->",a.w," rootId: ",i," clusterId:",e)}catch(m){l.error(m)}})}l.debug("Removing node",o),r.removeNode(o)})},"copy"),T=t((e,r)=>{let n=r.children(e),i=[...n];for(let s of n)P.set(s,e),i=[...i,...T(s,r)];return i},"extractDescendants"),q=t((e,r,n)=>{let i=e.edges().filter((a)=>a.v===r||a.w===r),s=e.edges().filter((a)=>a.v===n||a.w===n),o=i.map((a)=>({v:a.v===r?n:a.v,w:a.w===r?r:a.w})),c=s.map((a)=>({v:a.v,w:a.w}));return o.filter((a)=>c.some((d)=>a.v===d.v&&a.w===d.w))},"findCommonEdges"),xs=t((e,r,n)=>{let i=r.children(e);if(l.trace("Searching children of id ",e,i),i.length<1)return e;let s;for(let o of i){let c=xs(o,r,n),f=q(r,n,c);if(c)if(f.length>0)s=c;else return c}return s},"findNonClusterChild"),N=t((e)=>{if(!Ae.has(e))return e;if(!Ae.get(e).externalConnections)return e;if(Ae.has(e))return Ae.get(e).id;return e},"getAnchorId"),cA=t((e,r)=>{if(!e||r>10){l.debug("Opting out, no graph ");return}else l.debug("Opting in, graph ");e.nodes().forEach(function(n){if(e.children(n).length>0)l.debug("Cluster identified",n," Replacement id in edges: ",xs(n,e,n)),g.set(n,T(n,e)),Ae.set(n,{id:xs(n,e,n),clusterData:e.node(n)})}),e.nodes().forEach(function(n){let i=e.children(n),s=e.edges();if(i.length>0)l.debug("Cluster identified",n,g),s.forEach((o)=>{let c=w(o.v,n),f=w(o.w,n);if(c^f)l.debug("Edge: ",o," leaves cluster ",n),l.debug("Descendants of XXX ",n,": ",g.get(n)),Ae.get(n).externalConnections=!0});else l.debug("Not a cluster ",n,g)});for(let n of Ae.keys()){let i=Ae.get(n).id,s=e.parent(i);if(s!==n&&Ae.has(s)&&!Ae.get(s).externalConnections)Ae.get(n).id=s;let o=e.edges().some((c)=>c.v===n);if(i&&Ae.get(n)?.externalConnections&&o&&M(e,i,n)){let c=K(e,n,e.parent(i));if(c)Ae.get(n).id=c}}e.edges().forEach(function(n){let i=e.edge(n);l.debug("Edge "+n.v+" -> "+n.w+": "+JSON.stringify(n)),l.debug("Edge "+n.v+" -> "+n.w+": "+JSON.stringify(e.edge(n)));let{v:s,w:o}=n;if(l.debug("Fix XXX",Ae,"ids:",n.v,n.w,"Translating: ",Ae.get(n.v)," --- ",Ae.get(n.w)),Ae.get(n.v)||Ae.get(n.w)){if(l.debug("Fixing and trying - removing XXX",n.v,n.w,n.name),s=N(n.v),o=N(n.w),e.removeEdge(n.v,n.w,n.name),s!==n.v){let c=e.parent(s);Ae.get(c).externalConnections=!0,i.fromCluster=n.v}if(o!==n.w){let c=e.parent(o);Ae.get(c).externalConnections=!0,i.toCluster=n.w}l.debug("Fix Replacing with XXX",s,o,n.name),e.setEdge(s,o,i,n.name)}}),R(e,0),l.trace(Ae)},"adjustClustersAndEdges"),R=t((e,r)=>{if(r>10){l.error("Bailing out");return}let n=e.nodes(),i=!1;for(let s of n){let o=e.children(s);i=i||o.length>0}if(!i){l.debug("Done, no node has children",e.nodes());return}l.debug("Nodes = ",n,r);for(let s of n)if(l.debug("Extracting node",s,Ae,Ae.has(s)&&!Ae.get(s).externalConnections,!e.parent(s),e.node(s),e.children("D")," Depth ",r),!Ae.has(s))l.debug("Not a cluster",s,r);else if(!Ae.get(s).externalConnections&&e.children(s)&&e.children(s).length>0){l.debug("Cluster without external connections, without a parent and with children",s,r);let c=e.graph().rankdir==="TB"?"LR":"TB";if(Ae.get(s)?.clusterData?.dir)c=Ae.get(s).clusterData.dir,l.debug("Fixing dir",Ae.get(s).clusterData.dir,c);let f=new $e({multigraph:!0,compound:!0}).setGraph({rankdir:c,nodesep:50,ranksep:50,marginx:8,marginy:8}).setDefaultEdgeLabel(function(){return{}});k(s,e,f,s),e.setNode(s,{clusterNode:!0,id:s,clusterData:Ae.get(s).clusterData,label:Ae.get(s).label,graph:f})}else l.debug("Cluster ** ",s," **not meeting the criteria !externalConnections:",!Ae.get(s).externalConnections," no parent: ",!e.parent(s)," children ",e.children(s)&&e.children(s).length>0,e.children("D"),r),l.debug(Ae);n=e.nodes(),l.debug("New list of nodes",n);for(let s of n){let o=e.node(s);if(l.debug(" Now next level",s,o),o?.clusterNode)R(o.graph,r+1)}},"extractor"),B=t((e,r)=>{if(r.length===0)return[];let n=Object.assign([],r);return r.forEach((i)=>{let s=e.children(i),o=B(e,s);n=[...n,...o]}),n},"sorter"),hd=t((e)=>B(e,e.children()),"sortNodesByHierarchy"),M=t((e,r,n)=>{let i=e.parent(r);while(i&&i!==n){let s=Ae.get(i);if(s&&!s.externalConnections)return!0;i=e.parent(i)}return!1},"isNodeInExtractableCluster"),K=t((e,r,n)=>{let i=e.children(r)??[];for(let s of i){if(s===n||w(s,n))continue;let o=xs(s,e,r);if(!o)continue;if(!M(e,o,r))return o}return null},"findSafeAnchorNode");function Oi({prepareLayout:e,measureLayout:r,runLayoutCore:n,paintLayout:i,afterPaint:s,paintOptions:o}){let c=r??bd;return t(async function(a,d,m,y){let b=d.select("g");(m?.insertMarkers??Ss)(b,a.markers,a.type,a.diagramId),X();let u={element:b,helpers:m,options:y};u.preparedLayout=await e?.(a,u);let h=await c(a,u),v=await n(a,u),C={...u,measure:h};if(i)await i(a,C,v);else await G(a,C,o);await s?.(a,C,v)},"render")}t(Oi,"createCommonLayoutRenderer");function X(){xA(),CA(),wA(),V()}t(X,"clearLayoutRenderState");async function bd(e,{element:r},n){return await S(r,e,n)}t(bd,"defaultMeasureLayout");async function G(e,r,n={}){let{measure:i}=r,{groups:s}=i;for(let c of n.getNodes?.(e,r)??e.nodes){if(n.skipNode?.(c,r))continue;await _(s,c,r,n)}let o=O(e.nodes);for(let c of e.edges){if(F(c,n))continue;await j(s,c,o,e,n,r)}}t(G,"paintLayoutData");async function _(e,r,n,i){if(r.clusterNode)Pr(r);else if(A(r,n,i))await si(e.clusters,r);else Pr(r)}t(_,"paintLayoutNode");function A(e,r,n){return e.isGroup===!0&&(n.isCluster?.(e,r)??!0)}t(A,"shouldPaintAsCluster");function O(e){let r=new Map;for(let n of e)if(n?.id)r.set(n.id,n);return r}t(O,"buildNodeLookup");function F(e,r){return e.isLayoutOnly||Boolean(r.skipEdge?.(e))}t(F,"shouldSkipPaintEdge");async function j(e,r,n,i,s,o){let c=li(e.edgePaths,{...r},s.clusterDb??new Map,i.type,x(r.start,r,n,o,s),x(r.end,r,n,o,s),i.diagramId,H(r,s));if(Ef(r)){if(!Is.has(r.id))await ua(e.edgeLabels,r);z(r,c)}}t(j,"paintLayoutEdge");function x(e,r,n,i,s){return s.getEdgeNode?.(e,r,i)??(e?n.get(e)??{}:{})}t(x,"getRenderedNode");function H(e,r){return typeof r.skipIntersect==="function"?r.skipIntersect(e):r.skipIntersect??!1}t(H,"shouldSkipIntersect");function z(e,r){let n=r?.updatedPath??r?.originalPath,i=E(),{subGraphTitleTotalMargin:s}=la({flowchart:i.flowchart??{}});if(e.label){let o=Is.get(e.id),{x:c,y:f}=e;if(n){let a=W.calcLabelPosition(n);if(l.debug("Moving label "+e.label+" from (",c,",",f,") to (",a.x,",",a.y,") abc88"),r?.updatedPath)c=a.x,f=a.y}o.attr("transform",`translate(${c}, ${f+s/2})`)}if(e?.startLabelLeft){let o=$t.get(e.id).startLeft,c=e?.x,f=e?.y;if(n){let a=W.calcTerminalLabelPosition(e.arrowTypeStart?10:0,"start_left",n);c=a.x,f=a.y}o.attr("transform",`translate(${c}, ${f})`)}if(e.startLabelRight){let o=$t.get(e.id).startRight,{x:c,y:f}=e;if(n){let a=W.calcTerminalLabelPosition(e.arrowTypeStart?10:0,"start_right",n);c=a.x,f=a.y}o.attr("transform",`translate(${c}, ${f})`)}if(e.endLabelLeft){let o=$t.get(e.id).endLeft,{x:c,y:f}=e;if(n){let a=W.calcTerminalLabelPosition(e.arrowTypeEnd?10:0,"end_left",n);c=a.x,f=a.y}o.attr("transform",`translate(${c}, ${f})`)}if(e.endLabelRight){let o=$t.get(e.id).endRight,{x:c,y:f}=e;if(n){let a=W.calcTerminalLabelPosition(e.arrowTypeEnd?10:0,"end_right",n);c=a.x,f=a.y}o.attr("transform",`translate(${c}, ${f})`)}}t(z,"positionRenderedEdgeLabel");
1
+ import{t,l,E,p,W,Z,la,ca,xA,Pr,si,wA,Is,$t,CA,Ef,ua,li,Ss}from"./index-zj45wj1x.js";import{$e}from"./index-r83kr4s5.js";function Ad(e,{edgePathsClass:r="edges edgePaths"}={}){let n=e.insert("g").attr("class","root"),i=n.insert("g").attr("class","clusters"),s=n.insert("g").attr("class",r),o=n.insert("g").attr("class","edgeLabels"),c=n.insert("g").attr("class","nodes");return{clusters:i,edgePaths:s,edgeLabels:o,nodes:c,rootGroups:n}}t(Ad,"createLayoutElementGroups");async function L(e,r,n){if(r.label){let{shapeSvg:i,bbox:s}=await Z(e,n===void 0?r:{...r,width:n});r.labelBBox={width:s.width,height:s.height},i.remove()}else r.labelBBox={width:0,height:0}}t(L,"measureGroupLabel");async function gd(e,r,n){let i=await ca(e,r,n),s=i.node()?.getBBox()??{width:0,height:0};return r.width=s.width,r.height=s.height,i}t(gd,"insertMeasuredNode");function D(e,r,n){let i=e,s=new Set;while(i){if(i.dir)return i.dir;if(!i.parentId||s.has(i.parentId))break;s.add(i.parentId),i=r.get(i.parentId)}return n}t(D,"resolveNodeDir");async function S(e,r,n={}){let i=new $e({multigraph:!0,compound:!0}),s=[...r.edges],o=p(),c=Ad(e),{edgeLabels:f,nodes:a}=c,d=new Map,m=new Map(r.nodes.map((u)=>[u.id,u])),y=r.direction,b=e.node()!=null;await Promise.all(r.nodes.map(async(u)=>{if(u.isGroup){if(b){let h=n.unwrapGroupLabels&&u.labelType!=="markdown";await L(a,u,h?Number.POSITIVE_INFINITY:void 0)}i.setNode(u.id,{...u})}else{if(b){let h=await gd(a,u,{config:o,dir:D(u,m,y)});d.set(u.id,h)}i.setNode(u.id,{...u})}}));for(let u of s){if(b&&Ef(u))await ua(f,u);if(i.setEdge(u.start,u.end,{...u},u.id),!r.edges.some((v)=>v.id===u.id))r.edges.push(u)}if(globalThis.mermaidCaptureSizes){let{captureNodeSizes:u}=await import("./sizeCapture-INFHLROL-vt8qp04d.js");u(e,r)}return{graph:i,groups:c,nodeElements:d}}t(S,"createGraphWithElements");var Ae=new Map,g=new Map,P=new Map,V=t(()=>{g.clear(),P.clear(),Ae.clear()},"clear"),w=t((e,r)=>{let n=g.get(r)||[];return l.trace("In isDescendant",r," ",e," = ",n.includes(e)),n.includes(e)},"isDescendant"),Y=t((e,r)=>{let n=g.get(r)||[];if(l.info("Descendants of ",r," is ",n),l.info("Edge is ",e),e.v===r||e.w===r)return!1;if(!n)return l.debug("Tilt, ",r,",not in descendants"),!1;return n.includes(e.v)||w(e.v,r)||w(e.w,r)||n.includes(e.w)},"edgeInCluster"),k=t((e,r,n,i)=>{l.debug("Copying children of ",e,"root",i,"data",r.node(e),i);let s=r.children(e)||[];if(e!==i)s.push(e);l.debug("Copying (nodes) clusterId",e,"nodes",s),s.forEach((o)=>{if(r.children(o).length>0)k(o,r,n,i);else{let c=r.node(o);if(l.info("cp ",o," to ",i," with parent ",e),n.setNode(o,c),i!==r.parent(o))l.debug("Setting parent",o,r.parent(o)),n.setParent(o,r.parent(o));if(e!==i&&o!==e)l.debug("Setting parent",o,e),n.setParent(o,e);else l.info("In copy ",e,"root",i,"data",r.node(e),i),l.debug("Not Setting parent for node=",o,"cluster!==rootId",e!==i,"node!==clusterId",o!==e);let f=r.edges(o);l.debug("Copying Edges",f),f.forEach((a)=>{l.info("Edge",a);let d=r.edge(a.v,a.w,a.name);l.info("Edge data",d,i);try{if(Y(a,i))l.info("Copying as ",a.v,a.w,d,a.name),n.setEdge(a.v,a.w,d,a.name),l.info("newGraph edges ",n.edges(),n.edge(n.edges()[0]));else l.info("Skipping copy of edge ",a.v,"-->",a.w," rootId: ",i," clusterId:",e)}catch(m){l.error(m)}})}l.debug("Removing node",o),r.removeNode(o)})},"copy"),T=t((e,r)=>{let n=r.children(e),i=[...n];for(let s of n)P.set(s,e),i=[...i,...T(s,r)];return i},"extractDescendants"),q=t((e,r,n)=>{let i=e.edges().filter((a)=>a.v===r||a.w===r),s=e.edges().filter((a)=>a.v===n||a.w===n),o=i.map((a)=>({v:a.v===r?n:a.v,w:a.w===r?r:a.w})),c=s.map((a)=>({v:a.v,w:a.w}));return o.filter((a)=>c.some((d)=>a.v===d.v&&a.w===d.w))},"findCommonEdges"),xs=t((e,r,n)=>{let i=r.children(e);if(l.trace("Searching children of id ",e,i),i.length<1)return e;let s;for(let o of i){let c=xs(o,r,n),f=q(r,n,c);if(c)if(f.length>0)s=c;else return c}return s},"findNonClusterChild"),N=t((e)=>{if(!Ae.has(e))return e;if(!Ae.get(e).externalConnections)return e;if(Ae.has(e))return Ae.get(e).id;return e},"getAnchorId"),cA=t((e,r)=>{if(!e||r>10){l.debug("Opting out, no graph ");return}else l.debug("Opting in, graph ");e.nodes().forEach(function(n){if(e.children(n).length>0)l.debug("Cluster identified",n," Replacement id in edges: ",xs(n,e,n)),g.set(n,T(n,e)),Ae.set(n,{id:xs(n,e,n),clusterData:e.node(n)})}),e.nodes().forEach(function(n){let i=e.children(n),s=e.edges();if(i.length>0)l.debug("Cluster identified",n,g),s.forEach((o)=>{let c=w(o.v,n),f=w(o.w,n);if(c^f)l.debug("Edge: ",o," leaves cluster ",n),l.debug("Descendants of XXX ",n,": ",g.get(n)),Ae.get(n).externalConnections=!0});else l.debug("Not a cluster ",n,g)});for(let n of Ae.keys()){let i=Ae.get(n).id,s=e.parent(i);if(s!==n&&Ae.has(s)&&!Ae.get(s).externalConnections)Ae.get(n).id=s;let o=e.edges().some((c)=>c.v===n);if(i&&Ae.get(n)?.externalConnections&&o&&M(e,i,n)){let c=K(e,n,e.parent(i));if(c)Ae.get(n).id=c}}e.edges().forEach(function(n){let i=e.edge(n);l.debug("Edge "+n.v+" -> "+n.w+": "+JSON.stringify(n)),l.debug("Edge "+n.v+" -> "+n.w+": "+JSON.stringify(e.edge(n)));let{v:s,w:o}=n;if(l.debug("Fix XXX",Ae,"ids:",n.v,n.w,"Translating: ",Ae.get(n.v)," --- ",Ae.get(n.w)),Ae.get(n.v)||Ae.get(n.w)){if(l.debug("Fixing and trying - removing XXX",n.v,n.w,n.name),s=N(n.v),o=N(n.w),e.removeEdge(n.v,n.w,n.name),s!==n.v){let c=e.parent(s);Ae.get(c).externalConnections=!0,i.fromCluster=n.v}if(o!==n.w){let c=e.parent(o);Ae.get(c).externalConnections=!0,i.toCluster=n.w}l.debug("Fix Replacing with XXX",s,o,n.name),e.setEdge(s,o,i,n.name)}}),R(e,0),l.trace(Ae)},"adjustClustersAndEdges"),R=t((e,r)=>{if(r>10){l.error("Bailing out");return}let n=e.nodes(),i=!1;for(let s of n){let o=e.children(s);i=i||o.length>0}if(!i){l.debug("Done, no node has children",e.nodes());return}l.debug("Nodes = ",n,r);for(let s of n)if(l.debug("Extracting node",s,Ae,Ae.has(s)&&!Ae.get(s).externalConnections,!e.parent(s),e.node(s),e.children("D")," Depth ",r),!Ae.has(s))l.debug("Not a cluster",s,r);else if(!Ae.get(s).externalConnections&&e.children(s)&&e.children(s).length>0){l.debug("Cluster without external connections, without a parent and with children",s,r);let c=e.graph().rankdir==="TB"?"LR":"TB";if(Ae.get(s)?.clusterData?.dir)c=Ae.get(s).clusterData.dir,l.debug("Fixing dir",Ae.get(s).clusterData.dir,c);let f=new $e({multigraph:!0,compound:!0}).setGraph({rankdir:c,nodesep:50,ranksep:50,marginx:8,marginy:8}).setDefaultEdgeLabel(function(){return{}});k(s,e,f,s),e.setNode(s,{clusterNode:!0,id:s,clusterData:Ae.get(s).clusterData,label:Ae.get(s).label,graph:f})}else l.debug("Cluster ** ",s," **not meeting the criteria !externalConnections:",!Ae.get(s).externalConnections," no parent: ",!e.parent(s)," children ",e.children(s)&&e.children(s).length>0,e.children("D"),r),l.debug(Ae);n=e.nodes(),l.debug("New list of nodes",n);for(let s of n){let o=e.node(s);if(l.debug(" Now next level",s,o),o?.clusterNode)R(o.graph,r+1)}},"extractor"),B=t((e,r)=>{if(r.length===0)return[];let n=Object.assign([],r);return r.forEach((i)=>{let s=e.children(i),o=B(e,s);n=[...n,...o]}),n},"sorter"),hd=t((e)=>B(e,e.children()),"sortNodesByHierarchy"),M=t((e,r,n)=>{let i=e.parent(r);while(i&&i!==n){let s=Ae.get(i);if(s&&!s.externalConnections)return!0;i=e.parent(i)}return!1},"isNodeInExtractableCluster"),K=t((e,r,n)=>{let i=e.children(r)??[];for(let s of i){if(s===n||w(s,n))continue;let o=xs(s,e,r);if(!o)continue;if(!M(e,o,r))return o}return null},"findSafeAnchorNode");function Oi({prepareLayout:e,measureLayout:r,runLayoutCore:n,paintLayout:i,afterPaint:s,paintOptions:o}){let c=r??bd;return t(async function(a,d,m,y){let b=d.select("g");(m?.insertMarkers??Ss)(b,a.markers,a.type,a.diagramId),X();let u={element:b,helpers:m,options:y};u.preparedLayout=await e?.(a,u);let h=await c(a,u),v=await n(a,u),C={...u,measure:h};if(i)await i(a,C,v);else await G(a,C,o);await s?.(a,C,v)},"render")}t(Oi,"createCommonLayoutRenderer");function X(){xA(),CA(),wA(),V()}t(X,"clearLayoutRenderState");async function bd(e,{element:r},n){return await S(r,e,n)}t(bd,"defaultMeasureLayout");async function G(e,r,n={}){let{measure:i}=r,{groups:s}=i;for(let c of n.getNodes?.(e,r)??e.nodes){if(n.skipNode?.(c,r))continue;await _(s,c,r,n)}let o=O(e.nodes);for(let c of e.edges){if(F(c,n))continue;await j(s,c,o,e,n,r)}}t(G,"paintLayoutData");async function _(e,r,n,i){if(r.clusterNode)Pr(r);else if(A(r,n,i))await si(e.clusters,r);else Pr(r)}t(_,"paintLayoutNode");function A(e,r,n){return e.isGroup===!0&&(n.isCluster?.(e,r)??!0)}t(A,"shouldPaintAsCluster");function O(e){let r=new Map;for(let n of e)if(n?.id)r.set(n.id,n);return r}t(O,"buildNodeLookup");function F(e,r){return e.isLayoutOnly||Boolean(r.skipEdge?.(e))}t(F,"shouldSkipPaintEdge");async function j(e,r,n,i,s,o){let c=li(e.edgePaths,{...r},s.clusterDb??new Map,i.type,x(r.start,r,n,o,s),x(r.end,r,n,o,s),i.diagramId,H(r,s));if(Ef(r)){if(!Is.has(r.id))await ua(e.edgeLabels,r);z(r,c)}}t(j,"paintLayoutEdge");function x(e,r,n,i,s){return s.getEdgeNode?.(e,r,i)??(e?n.get(e)??{}:{})}t(x,"getRenderedNode");function H(e,r){return typeof r.skipIntersect==="function"?r.skipIntersect(e):r.skipIntersect??!1}t(H,"shouldSkipIntersect");function z(e,r){let n=r?.updatedPath??r?.originalPath,i=E(),{subGraphTitleTotalMargin:s}=la({flowchart:i.flowchart??{}});if(e.label){let o=Is.get(e.id),{x:c,y:f}=e;if(n){let a=W.calcLabelPosition(n);if(l.debug("Moving label "+e.label+" from (",c,",",f,") to (",a.x,",",a.y,") abc88"),r?.updatedPath)c=a.x,f=a.y}o.attr("transform",`translate(${c}, ${f+s/2})`)}if(e?.startLabelLeft){let o=$t.get(e.id).startLeft,c=e?.x,f=e?.y;if(n){let a=W.calcTerminalLabelPosition(e.arrowTypeStart?10:0,"start_left",n);c=a.x,f=a.y}o.attr("transform",`translate(${c}, ${f})`)}if(e.startLabelRight){let o=$t.get(e.id).startRight,{x:c,y:f}=e;if(n){let a=W.calcTerminalLabelPosition(e.arrowTypeStart?10:0,"start_right",n);c=a.x,f=a.y}o.attr("transform",`translate(${c}, ${f})`)}if(e.endLabelLeft){let o=$t.get(e.id).endLeft,{x:c,y:f}=e;if(n){let a=W.calcTerminalLabelPosition(e.arrowTypeEnd?10:0,"end_left",n);c=a.x,f=a.y}o.attr("transform",`translate(${c}, ${f})`)}if(e.endLabelRight){let o=$t.get(e.id).endRight,{x:c,y:f}=e;if(n){let a=W.calcTerminalLabelPosition(e.arrowTypeEnd?10:0,"end_right",n);c=a.x,f=a.y}o.attr("transform",`translate(${c}, ${f})`)}}t(z,"positionRenderedEdgeLabel");
2
2
  export{Ad,gd,Ae,xs,cA,hd,Oi,bd};
@@ -1,2 +1,2 @@
1
- import{d,n,i,o,u,a,e,ui,s,m,D,$r,No,f,ae,Dt,fe,C,F,wp,J,nn,jl,Cp,Du}from"./index-st202rjv.js";var Y={name:"clipboard-paste",size:24,node:[["path",{d:"M11 14h10",key:"1w8e9d"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v1.344",key:"1e62lh"}],["path",{d:"m17 18 4-4-4-4",key:"z2g111"}],["path",{d:"M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 1.793-1.113",key:"bjbb7m"}],["rect",{x:"8",y:"2",width:"8",height:"4",rx:"1",key:"ublpy"}]]},Ts=s(Y);var K={name:"folder-git-2",size:24,node:[["path",{d:"M18 19a5 5 0 0 1-5-5v8",key:"sz5oeg"}],["path",{d:"M9 20H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v5",key:"1w6njk"}],["circle",{cx:"13",cy:"12",r:"2",key:"1j92g6"}],["circle",{cx:"20",cy:"19",r:"2",key:"1obnsp"}]]},pp=s(K);function _({row:t,active:r,name:p,loading:c,onSelect:l,onCopyPath:g,onReveal:M}){return e("div",{className:"grid grid-cols-[1rem_minmax(0,1fr)_3.5rem] items-start gap-x-2 px-4 py-2 border-b border-ink/5 last:border-b-0 hover:bg-ink/[0.02] group/row transition-colors",children:[e("div",{className:"h-5 flex items-center justify-center",children:r&&e(f,{size:12,className:"text-ink","aria-label":"Selected repository"})}),e("button",{type:"button",onClick:l,disabled:r||!t.isRepo,title:!t.isRepo?t.error??"Not a git repository":r?"Already showing this repository":`Show ${t.path}`,className:"min-w-0 text-left cursor-pointer disabled:cursor-default",children:e("div",{className:"h-5 flex items-center gap-1.5 min-w-0",children:[e(fe,{size:11,className:r?"text-ink/60 flex-shrink-0":"text-ink/40 flex-shrink-0"}),e("span",{className:`truncate text-xs ${r?"font-semibold text-ink":"text-ink/90"}`,children:p})]})}),e("div",{className:"h-5 flex items-center justify-end gap-0.5 touch-visible opacity-0 group-hover/row:opacity-100",children:[e("button",{type:"button",onClick:g,disabled:c,title:`Copy the absolute path of ${t.path}`,"aria-label":`Copy path of ${t.path}`,className:"w-5 h-5 flex items-center justify-center rounded text-ink/40 hover:text-ink hover:bg-ink/10 cursor-pointer transition-colors disabled:opacity-30 disabled:cursor-default",children:e(ae,{size:11})}),e("button",{type:"button",onClick:M,title:`Reveal ${t.path} in the file manager`,"aria-label":`Reveal ${t.path}`,className:"w-5 h-5 flex items-center justify-center rounded text-ink/40 hover:text-ink hover:bg-ink/10 cursor-pointer transition-colors",children:e(Dt,{size:11})})]}),e("div",{className:"col-start-2 col-span-2 flex flex-wrap items-center gap-x-2 gap-y-0.5 min-w-0 mt-0.5",children:[t.isRepo?e(d,{children:[e("span",{className:`text-[10px] font-mono truncate ${t.detached?"text-warning":"text-ink/50"}`,title:t.detached?`Detached HEAD at ${t.branch}`:`On branch ${t.branch}`,children:t.branch}),e("span",{className:"text-[10px] text-ink/25","aria-hidden":!0,children:"·"}),e(X,{row:t})]}):e("span",{className:"text-[10px] text-ink/40 truncate",children:t.error??"Not a git repository"}),t.isRepo&&t.subject&&e(d,{children:[e("span",{className:"text-[10px] text-ink/25","aria-hidden":!0,children:"·"}),e("span",{className:"text-[10px] text-ink/40 truncate min-w-0",title:t.subject,children:t.subject})]})]})]})}function X({row:t}){let r=[];if(t.operation)r.push(e("span",{className:"flex flex-shrink-0 items-center gap-0.5 rounded border border-warning/30 px-1 text-[10px] font-mono text-warning",title:t.operation==="stash-pop"?`A stash pop stopped on ${t.conflicts} conflict(s)`:`A ${ui[t.operation]} is in progress, stopped on ${t.conflicts} conflict(s)`,children:[e(D,{size:9}),ui[t.operation]]},"operation"));else if(t.conflicts>0)r.push(e("span",{className:"flex flex-shrink-0 items-center gap-0.5 rounded border border-warning/30 px-1 text-[10px] font-mono text-warning",title:`${t.conflicts} conflicted path(s)`,children:[e(D,{size:9}),t.conflicts]},"conflicts"));if(t.changed>0||t.untracked>0)r.push(e("span",{className:"flex-shrink-0 rounded border border-info/30 px-1 text-[10px] font-mono tabular-nums text-info",title:`${t.changed} changed, ${t.untracked} untracked`,children:[t.changed>0?`${t.changed}±`:"",t.changed>0&&t.untracked>0?" ":"",t.untracked>0?`${t.untracked}?`:""]},"dirty"));if(t.gone)r.push(e("span",{className:"flex-shrink-0 rounded border border-warning/30 px-1 text-[10px] font-mono text-warning",title:`${t.upstream} no longer exists on the remote — fetch --prune to drop it`,children:"gone"},"gone"));else if(t.upstream&&(t.ahead>0||t.behind>0))r.push(e("span",{className:"flex flex-shrink-0 items-center gap-0.5 text-[10px] font-mono tabular-nums text-ink/60",title:`${t.ahead} ahead of, ${t.behind} behind ${t.upstream}`,children:[t.ahead>0&&e("span",{className:"flex items-center",children:[e(No,{size:9}),t.ahead]}),t.behind>0&&e("span",{className:"flex items-center",children:[e($r,{size:9}),t.behind]})]},"track"));if(r.length===0)return e("span",{className:"text-[10px] font-mono text-ink/30",title:"Nothing to report: clean and in sync",children:"clean, in sync"});return e(d,{children:r})}function q(t){let{open:r,rootPath:p,scanning:c}=t,[l,g]=n([]),[M,y]=n(!1),[S,P]=n(!1),[k,v]=n(null),[w,j]=n(0),E=t.repos.join("\x00"),G=o(!0),b=o(null);i(()=>(G.current=!0,()=>{G.current=!1,b.current?.abort(),b.current=null}),[]);let A=a(async()=>{b.current?.abort();let R=new AbortController;b.current=R,P(!0),y(!0);try{let N=new URLSearchParams({repoDetails:"1"});if(p)N.set("root",p);let L=await fetch(`/api/fs/git?${N.toString()}`,{signal:R.signal}),T=await L.json();if(!G.current||b.current!==R)return;if(!L.ok||!Array.isArray(T.details)){v(T.error||`Failed to read repositories (HTTP ${L.status})`);return}g(T.details),v(null)}catch(N){if(!G.current||b.current!==R)return;if(N instanceof Error&&N.name==="AbortError")return;v(N instanceof Error?N.message:"Failed to read repositories")}finally{if(G.current&&b.current===R)b.current=null,P(!1),y(!1)}},[p]);i(()=>{if(!r){g([]),v(null),y(!1);return}A()},[r,A,E,c,w]);let O=a(()=>j((R)=>R+1),[]);return{details:l,loading:M,reading:S,error:k,refresh:O}}function I(t){let r=new Map;for(let p of t){if(!p||p==="."){if(!r.has(""))r.set("",{key:"",label:null,paths:[]});r.get("").paths.push(".");continue}let c=p.indexOf("/"),l=c===-1?"":p.slice(0,c),g=r.get(l);if(!g)g={key:l,label:l===""?null:l,paths:[]},r.set(l,g);g.paths.push(p)}for(let p of r.values())p.paths.sort((c,l)=>c==="."?-1:l==="."?1:c.localeCompare(l));return[...r.values()].sort((p,c)=>{if(p.key==="")return-1;if(c.key==="")return 1;return p.key.localeCompare(c.key)})}function B(t,r){if(t===".")return"workspace root";if(r==="")return t;return t.slice(r.length+1)}function U({isOpen:t,rootPath:r,activeRepo:p,repos:c,scanning:l,onSelectRepo:g,onRefreshRepos:M,onClose:y}){let[S,P]=n(""),[k,v]=n(null),{details:w,loading:j,reading:E,error:G,refresh:b}=q({open:t,rootPath:r,repos:c,scanning:l});i(()=>{if(!t)P(""),v(null)},[t]);let A=u(()=>{let x=S.trim().toLowerCase();if(!x)return w;return w.filter((h)=>h.path.toLowerCase().includes(x))},[w,S]),O=u(()=>I(A.map((x)=>x.path)),[A]),R=u(()=>{let x=new Map;for(let h of w)x.set(h.path,h);return x},[w]),N=a(()=>{M(),b()},[M,b]),L=a(async(x)=>{let h=r?Du(r,x==="."?"":x):x,z=await nn(h);v(z?{text:`Copied ${h}`,kind:"success"}:{text:"Clipboard unavailable",kind:"error"})},[r]),T=a(async(x)=>{let h=new FormData;if(h.append("actionType","open_explorer"),h.append("path","."),h.append("repo",x),r)h.append("root",r);try{let z=await fetch("/api/fs/action",{method:"POST",body:h}),H=await z.json();if(!z.ok||H.error)v({text:H.error||"Could not open the file manager",kind:"error"})}catch{v({text:"Could not open the file manager",kind:"error"})}},[r]);if(!t)return null;return e(J,{onClose:y,maxWidthClass:"max-w-[min(96vw,720px)]",header:e("div",{className:"flex items-center gap-2 min-w-0",children:[e(pp,{size:14,className:"text-ink/60 flex-shrink-0"}),e("h2",{className:"text-sm font-semibold text-ink",children:"Repositories"}),e("span",{className:"text-[10px] font-mono text-ink/50 truncate",children:[c.length," in this workspace"]})]}),children:[e("div",{className:"px-5 py-3 flex items-center gap-2 border-b border-ink/10",children:[e(F,{size:12,className:"text-ink/40 flex-shrink-0"}),e("input",{type:"text",value:S,onChange:(x)=>P(x.currentTarget.value),placeholder:"Filter repositories…","aria-label":"Filter repositories",className:"flex-1 min-w-0 bg-transparent outline-none text-xs text-ink placeholder-ink/40",autoFocus:!0}),e("button",{type:"button",onClick:N,disabled:E||l,title:"Re-discover repositories and re-read their state","aria-label":"Refresh repositories",className:"text-ink/40 hover:text-ink transition-colors cursor-pointer disabled:opacity-40 flex-shrink-0",children:e(C,{size:12,className:E||l?"animate-spin":""})})]}),l&&e("div",{className:"px-5 py-1.5 border-b border-ink/10 text-[10px] font-mono text-ink/50 flex items-center gap-1.5",children:[e(m,{size:10,className:"animate-spin"}),"Still discovering repositories in this workspace…"]}),k&&e("div",{className:`px-5 py-1.5 border-b border-ink/10 text-[10px] font-mono truncate ${k.kind==="error"?"text-error":"text-ink/60"}`,title:k.text,role:"status",children:k.text}),e("div",{className:"min-h-[40vh] max-h-[60vh] overflow-y-auto scrollbar-overlay-container",children:j&&w.length===0?e("div",{className:"flex items-center justify-center gap-2 py-12 text-xs text-ink/50 font-mono",children:[e(m,{size:14,className:"animate-spin text-info"}),"Reading repositories…"]}):G?e("div",{className:"py-12 px-6 text-center text-xs text-error font-mono",children:G}):A.length===0?e("div",{className:"py-12 text-center text-xs text-ink/40 font-mono",children:S.trim()?"No matching repositories.":"No repositories in this workspace."}):O.map((x)=>e("div",{children:[e("div",{className:"px-4 py-1 text-[10px] uppercase tracking-wider text-ink/40 font-semibold bg-canvas/40 border-b border-ink/5 sticky top-0",children:x.label??jl(".",r)}),x.paths.map((h)=>{let z=R.get(h);if(!z)return null;return e(_,{row:z,active:h===p,name:B(h,x.key),loading:E,onSelect:()=>{g(h),y()},onCopyPath:()=>void L(h),onReveal:()=>void T(h)},h)})]},x.key))})]})}function fr({rootPath:t,activeRepo:r,onSelectRepo:p,repos:c,scanning:l,onRefreshRepos:g}){let[M,y]=n(!1),S=u(()=>({root:t??null,repo:r,rows:c.map((k)=>({repo:k,label:jl(k,t),short:Cp(k,t)})),scanning:l,ready:!0,setRepo:p,refresh:g}),[t,r,c,l,p,g]),P=a(()=>y(!0),[]);return e("div",{className:"relative",children:[e(wp,{scope:S,onManage:P}),e(U,{isOpen:M,rootPath:t,activeRepo:r,repos:c,scanning:l,onSelectRepo:p,onRefreshRepos:g,onClose:()=>y(!1)})]})}var W="(pointer: coarse)",V="(hover: none)";function Q(){if(typeof window>"u")return!1;if(window.matchMedia(W).matches)return!0;return navigator.maxTouchPoints>0&&window.matchMedia(V).matches}function _u(){let[t,r]=n(Q);return i(()=>{let p=[W,V].map((l)=>window.matchMedia(l)),c=()=>r(Q());for(let l of p)l.addEventListener("change",c);return()=>{for(let l of p)l.removeEventListener("change",c)}},[]),t}
1
+ import{d,n,i,o,u,a,e,ui,s,m,D,$r,No,f,ae,Dt,fe,C,F,wp,J,nn,jl,Cp,Du}from"./index-3wpsr2bc.js";var Y={name:"clipboard-paste",size:24,node:[["path",{d:"M11 14h10",key:"1w8e9d"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v1.344",key:"1e62lh"}],["path",{d:"m17 18 4-4-4-4",key:"z2g111"}],["path",{d:"M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 1.793-1.113",key:"bjbb7m"}],["rect",{x:"8",y:"2",width:"8",height:"4",rx:"1",key:"ublpy"}]]},Ts=s(Y);var K={name:"folder-git-2",size:24,node:[["path",{d:"M18 19a5 5 0 0 1-5-5v8",key:"sz5oeg"}],["path",{d:"M9 20H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v5",key:"1w6njk"}],["circle",{cx:"13",cy:"12",r:"2",key:"1j92g6"}],["circle",{cx:"20",cy:"19",r:"2",key:"1obnsp"}]]},pp=s(K);function _({row:t,active:r,name:p,loading:c,onSelect:l,onCopyPath:g,onReveal:M}){return e("div",{className:"grid grid-cols-[1rem_minmax(0,1fr)_3.5rem] items-start gap-x-2 px-4 py-2 border-b border-ink/5 last:border-b-0 hover:bg-ink/[0.02] group/row transition-colors",children:[e("div",{className:"h-5 flex items-center justify-center",children:r&&e(f,{size:12,className:"text-ink","aria-label":"Selected repository"})}),e("button",{type:"button",onClick:l,disabled:r||!t.isRepo,title:!t.isRepo?t.error??"Not a git repository":r?"Already showing this repository":`Show ${t.path}`,className:"min-w-0 text-left cursor-pointer disabled:cursor-default",children:e("div",{className:"h-5 flex items-center gap-1.5 min-w-0",children:[e(fe,{size:11,className:r?"text-ink/60 flex-shrink-0":"text-ink/40 flex-shrink-0"}),e("span",{className:`truncate text-xs ${r?"font-semibold text-ink":"text-ink/90"}`,children:p})]})}),e("div",{className:"h-5 flex items-center justify-end gap-0.5 touch-visible opacity-0 group-hover/row:opacity-100",children:[e("button",{type:"button",onClick:g,disabled:c,title:`Copy the absolute path of ${t.path}`,"aria-label":`Copy path of ${t.path}`,className:"w-5 h-5 flex items-center justify-center rounded text-ink/40 hover:text-ink hover:bg-ink/10 cursor-pointer transition-colors disabled:opacity-30 disabled:cursor-default",children:e(ae,{size:11})}),e("button",{type:"button",onClick:M,title:`Reveal ${t.path} in the file manager`,"aria-label":`Reveal ${t.path}`,className:"w-5 h-5 flex items-center justify-center rounded text-ink/40 hover:text-ink hover:bg-ink/10 cursor-pointer transition-colors",children:e(Dt,{size:11})})]}),e("div",{className:"col-start-2 col-span-2 flex flex-wrap items-center gap-x-2 gap-y-0.5 min-w-0 mt-0.5",children:[t.isRepo?e(d,{children:[e("span",{className:`text-[10px] font-mono truncate ${t.detached?"text-warning":"text-ink/50"}`,title:t.detached?`Detached HEAD at ${t.branch}`:`On branch ${t.branch}`,children:t.branch}),e("span",{className:"text-[10px] text-ink/25","aria-hidden":!0,children:"·"}),e(X,{row:t})]}):e("span",{className:"text-[10px] text-ink/40 truncate",children:t.error??"Not a git repository"}),t.isRepo&&t.subject&&e(d,{children:[e("span",{className:"text-[10px] text-ink/25","aria-hidden":!0,children:"·"}),e("span",{className:"text-[10px] text-ink/40 truncate min-w-0",title:t.subject,children:t.subject})]})]})]})}function X({row:t}){let r=[];if(t.operation)r.push(e("span",{className:"flex flex-shrink-0 items-center gap-0.5 rounded border border-warning/30 px-1 text-[10px] font-mono text-warning",title:t.operation==="stash-pop"?`A stash pop stopped on ${t.conflicts} conflict(s)`:`A ${ui[t.operation]} is in progress, stopped on ${t.conflicts} conflict(s)`,children:[e(D,{size:9}),ui[t.operation]]},"operation"));else if(t.conflicts>0)r.push(e("span",{className:"flex flex-shrink-0 items-center gap-0.5 rounded border border-warning/30 px-1 text-[10px] font-mono text-warning",title:`${t.conflicts} conflicted path(s)`,children:[e(D,{size:9}),t.conflicts]},"conflicts"));if(t.changed>0||t.untracked>0)r.push(e("span",{className:"flex-shrink-0 rounded border border-info/30 px-1 text-[10px] font-mono tabular-nums text-info",title:`${t.changed} changed, ${t.untracked} untracked`,children:[t.changed>0?`${t.changed}±`:"",t.changed>0&&t.untracked>0?" ":"",t.untracked>0?`${t.untracked}?`:""]},"dirty"));if(t.gone)r.push(e("span",{className:"flex-shrink-0 rounded border border-warning/30 px-1 text-[10px] font-mono text-warning",title:`${t.upstream} no longer exists on the remote — fetch --prune to drop it`,children:"gone"},"gone"));else if(t.upstream&&(t.ahead>0||t.behind>0))r.push(e("span",{className:"flex flex-shrink-0 items-center gap-0.5 text-[10px] font-mono tabular-nums text-ink/60",title:`${t.ahead} ahead of, ${t.behind} behind ${t.upstream}`,children:[t.ahead>0&&e("span",{className:"flex items-center",children:[e(No,{size:9}),t.ahead]}),t.behind>0&&e("span",{className:"flex items-center",children:[e($r,{size:9}),t.behind]})]},"track"));if(r.length===0)return e("span",{className:"text-[10px] font-mono text-ink/30",title:"Nothing to report: clean and in sync",children:"clean, in sync"});return e(d,{children:r})}function q(t){let{open:r,rootPath:p,scanning:c}=t,[l,g]=n([]),[M,y]=n(!1),[S,P]=n(!1),[k,v]=n(null),[w,j]=n(0),E=t.repos.join("\x00"),G=o(!0),b=o(null);i(()=>(G.current=!0,()=>{G.current=!1,b.current?.abort(),b.current=null}),[]);let A=a(async()=>{b.current?.abort();let R=new AbortController;b.current=R,P(!0),y(!0);try{let N=new URLSearchParams({repoDetails:"1"});if(p)N.set("root",p);let L=await fetch(`/api/fs/git?${N.toString()}`,{signal:R.signal}),T=await L.json();if(!G.current||b.current!==R)return;if(!L.ok||!Array.isArray(T.details)){v(T.error||`Failed to read repositories (HTTP ${L.status})`);return}g(T.details),v(null)}catch(N){if(!G.current||b.current!==R)return;if(N instanceof Error&&N.name==="AbortError")return;v(N instanceof Error?N.message:"Failed to read repositories")}finally{if(G.current&&b.current===R)b.current=null,P(!1),y(!1)}},[p]);i(()=>{if(!r){g([]),v(null),y(!1);return}A()},[r,A,E,c,w]);let O=a(()=>j((R)=>R+1),[]);return{details:l,loading:M,reading:S,error:k,refresh:O}}function I(t){let r=new Map;for(let p of t){if(!p||p==="."){if(!r.has(""))r.set("",{key:"",label:null,paths:[]});r.get("").paths.push(".");continue}let c=p.indexOf("/"),l=c===-1?"":p.slice(0,c),g=r.get(l);if(!g)g={key:l,label:l===""?null:l,paths:[]},r.set(l,g);g.paths.push(p)}for(let p of r.values())p.paths.sort((c,l)=>c==="."?-1:l==="."?1:c.localeCompare(l));return[...r.values()].sort((p,c)=>{if(p.key==="")return-1;if(c.key==="")return 1;return p.key.localeCompare(c.key)})}function B(t,r){if(t===".")return"workspace root";if(r==="")return t;return t.slice(r.length+1)}function U({isOpen:t,rootPath:r,activeRepo:p,repos:c,scanning:l,onSelectRepo:g,onRefreshRepos:M,onClose:y}){let[S,P]=n(""),[k,v]=n(null),{details:w,loading:j,reading:E,error:G,refresh:b}=q({open:t,rootPath:r,repos:c,scanning:l});i(()=>{if(!t)P(""),v(null)},[t]);let A=u(()=>{let x=S.trim().toLowerCase();if(!x)return w;return w.filter((h)=>h.path.toLowerCase().includes(x))},[w,S]),O=u(()=>I(A.map((x)=>x.path)),[A]),R=u(()=>{let x=new Map;for(let h of w)x.set(h.path,h);return x},[w]),N=a(()=>{M(),b()},[M,b]),L=a(async(x)=>{let h=r?Du(r,x==="."?"":x):x,z=await nn(h);v(z?{text:`Copied ${h}`,kind:"success"}:{text:"Clipboard unavailable",kind:"error"})},[r]),T=a(async(x)=>{let h=new FormData;if(h.append("actionType","open_explorer"),h.append("path","."),h.append("repo",x),r)h.append("root",r);try{let z=await fetch("/api/fs/action",{method:"POST",body:h}),H=await z.json();if(!z.ok||H.error)v({text:H.error||"Could not open the file manager",kind:"error"})}catch{v({text:"Could not open the file manager",kind:"error"})}},[r]);if(!t)return null;return e(J,{onClose:y,maxWidthClass:"max-w-[min(96vw,720px)]",header:e("div",{className:"flex items-center gap-2 min-w-0",children:[e(pp,{size:14,className:"text-ink/60 flex-shrink-0"}),e("h2",{className:"text-sm font-semibold text-ink",children:"Repositories"}),e("span",{className:"text-[10px] font-mono text-ink/50 truncate",children:[c.length," in this workspace"]})]}),children:[e("div",{className:"px-5 py-3 flex items-center gap-2 border-b border-ink/10",children:[e(F,{size:12,className:"text-ink/40 flex-shrink-0"}),e("input",{type:"text",value:S,onChange:(x)=>P(x.currentTarget.value),placeholder:"Filter repositories…","aria-label":"Filter repositories",className:"flex-1 min-w-0 bg-transparent outline-none text-xs text-ink placeholder-ink/40",autoFocus:!0}),e("button",{type:"button",onClick:N,disabled:E||l,title:"Re-discover repositories and re-read their state","aria-label":"Refresh repositories",className:"text-ink/40 hover:text-ink transition-colors cursor-pointer disabled:opacity-40 flex-shrink-0",children:e(C,{size:12,className:E||l?"animate-spin":""})})]}),l&&e("div",{className:"px-5 py-1.5 border-b border-ink/10 text-[10px] font-mono text-ink/50 flex items-center gap-1.5",children:[e(m,{size:10,className:"animate-spin"}),"Still discovering repositories in this workspace…"]}),k&&e("div",{className:`px-5 py-1.5 border-b border-ink/10 text-[10px] font-mono truncate ${k.kind==="error"?"text-error":"text-ink/60"}`,title:k.text,role:"status",children:k.text}),e("div",{className:"min-h-[40vh] max-h-[60vh] overflow-y-auto scrollbar-overlay-container",children:j&&w.length===0?e("div",{className:"flex items-center justify-center gap-2 py-12 text-xs text-ink/50 font-mono",children:[e(m,{size:14,className:"animate-spin text-info"}),"Reading repositories…"]}):G?e("div",{className:"py-12 px-6 text-center text-xs text-error font-mono",children:G}):A.length===0?e("div",{className:"py-12 text-center text-xs text-ink/40 font-mono",children:S.trim()?"No matching repositories.":"No repositories in this workspace."}):O.map((x)=>e("div",{children:[e("div",{className:"px-4 py-1 text-[10px] uppercase tracking-wider text-ink/40 font-semibold bg-canvas/40 border-b border-ink/5 sticky top-0",children:x.label??jl(".",r)}),x.paths.map((h)=>{let z=R.get(h);if(!z)return null;return e(_,{row:z,active:h===p,name:B(h,x.key),loading:E,onSelect:()=>{g(h),y()},onCopyPath:()=>void L(h),onReveal:()=>void T(h)},h)})]},x.key))})]})}function fr({rootPath:t,activeRepo:r,onSelectRepo:p,repos:c,scanning:l,onRefreshRepos:g}){let[M,y]=n(!1),S=u(()=>({root:t??null,repo:r,rows:c.map((k)=>({repo:k,label:jl(k,t),short:Cp(k,t)})),scanning:l,ready:!0,setRepo:p,refresh:g}),[t,r,c,l,p,g]),P=a(()=>y(!0),[]);return e("div",{className:"relative",children:[e(wp,{scope:S,onManage:P}),e(U,{isOpen:M,rootPath:t,activeRepo:r,repos:c,scanning:l,onSelectRepo:p,onRefreshRepos:g,onClose:()=>y(!1)})]})}var W="(pointer: coarse)",V="(hover: none)";function Q(){if(typeof window>"u")return!1;if(window.matchMedia(W).matches)return!0;return navigator.maxTouchPoints>0&&window.matchMedia(V).matches}function _u(){let[t,r]=n(Q);return i(()=>{let p=[W,V].map((l)=>window.matchMedia(l)),c=()=>r(Q());for(let l of p)l.addEventListener("change",c);return()=>{for(let l of p)l.removeEventListener("change",c)}},[]),t}
2
2
  export{Ts,pp,fr,_u};
@@ -1,2 +1,2 @@
1
- import{d,n,i,a,e,s,I,C,rt,Me}from"./index-st202rjv.js";var q={name:"ticket",size:24,node:[["path",{d:"M2 9a3 3 0 0 1 0 6v2a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-2a3 3 0 0 1 0-6V7a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2Z",key:"qn84l0"}],["path",{d:"M13 5v2",key:"dyzc3o"}],["path",{d:"M13 17v2",key:"1ont0d"}],["path",{d:"M13 11v2",key:"1wjjxi"}]]},S=s(q);function P({providerName:t,providerSlug:r,iconUrl:o,credentialSources:l,error:p,note:c,children:m}){return e("section",{className:"bg-paper border border-ink/15 rounded-lg shadow-xs",children:[e("header",{className:"flex items-center justify-between gap-2 px-3.5 py-2.5 border-b border-ink/10",children:[e("span",{className:"flex min-w-0 items-center gap-2",children:[r&&e(Me,{provider:{slug:r,name:t,...o?{iconUrl:o}:{}},size:20}),e("span",{className:"truncate text-xs font-semibold text-ink",children:t})]}),e("span",{className:"text-[10px] font-mono uppercase tracking-wider text-ink/50 truncate",title:`Credentials from ${l.join(", ")}`,children:l.join(" · ")})]}),e("div",{className:"p-3.5 space-y-4",children:[p&&e("p",{className:"flex items-start gap-2 text-error text-xs leading-relaxed",children:[e(I,{size:14,className:"shrink-0 mt-0.5"}),e("span",{className:"break-words",children:p})]}),m,c&&e("p",{className:"text-[10px] text-ink/50 leading-relaxed border-t border-ink/10 pt-2.5",children:c})]})]})}var B=new Intl.NumberFormat("id-ID",{style:"currency",currency:"IDR",maximumFractionDigits:0}),j=new Intl.NumberFormat("id-ID"),y=new Intl.NumberFormat("id-ID",{minimumFractionDigits:2,maximumFractionDigits:2,useGrouping:!1}),G=new Intl.DateTimeFormat("id-ID",{dateStyle:"medium",timeStyle:"short"});function x(t){return B.format(t)}function b(t){return j.format(t)}function ea(t){let r=new Date(t);if(Number.isNaN(r.getTime()))return t;return G.format(r)}function L(t,r){if(r<=0)return 0;return Math.min(100,Math.max(0,t/r*100))}function T(t,r){if(r<=0)return"0%";return`${new Intl.NumberFormat("id-ID",{maximumFractionDigits:1}).format(t/r*100)}%`}function k(t){if(!Number.isFinite(t))return"0";let r=Math.abs(t);if(r>=1e9)return`${y.format(t/1e9)}B`;if(r>=1e6)return`${y.format(t/1e6)}M`;if(r>=1000)return`${y.format(t/1000)}K`;return b(t)}function N(t){let r=Number(t);if(t.trim()===""||!Number.isFinite(r))return t;return b(r)}var O=new Intl.NumberFormat("id-ID",{minimumFractionDigits:2,maximumFractionDigits:2});function U(t){if(!Number.isFinite(t))return"$0,00";return`$${O.format(t)}`}function w(t,r){if(!Number.isFinite(t))return"—";switch(r){case"percent":return`${new Intl.NumberFormat("id-ID",{maximumFractionDigits:1}).format(t)}%`;case"usd":return U(t);case"tokens":case"bytes":return k(t);default:return b(t)}}function D(t){if(!Number.isFinite(t))return"0%";return`${new Intl.NumberFormat("id-ID",{maximumFractionDigits:1}).format(t*100)}%`}function z({window:t}){let r=t.usedRp+t.remainingRp,o=L(t.usedRp,r);return e("div",{className:"bg-paper border border-ink/15 rounded-lg p-3 shadow-xs space-y-2",children:[e("div",{className:"flex items-center justify-between gap-2",children:[e("span",{className:"text-[11px] font-semibold text-ink",children:t.label}),e("span",{className:"text-[10px] text-ink/50",children:["Resets ",ea(t.resetsAt)]})]}),e("div",{className:"h-1.5 w-full bg-ink/10 rounded-full overflow-hidden",children:e("div",{className:"h-full bg-ink/80 rounded-full",style:{width:`${o}%`}})}),e("div",{className:"flex flex-wrap items-center justify-between gap-x-3 gap-y-0.5 text-[10px] text-ink/60",children:[e("span",{children:["Used ",e("span",{className:"font-semibold text-ink",children:x(t.usedRp)})," ·"," ",T(t.usedRp,r)]}),e("span",{children:["Remaining ",e("span",{className:"font-semibold text-ink",children:x(t.remainingRp)})]})]})]})}function H({coupon:t}){return e("div",{className:"bg-ink/5 border border-ink/10 rounded-lg p-3 shadow-xs",children:[e("div",{className:"flex items-center gap-1.5 mb-1.5",children:[e(S,{size:12,className:"text-ink/60"}),e("span",{className:"text-[11px] font-semibold text-ink",children:["Active coupon · ",t.name]})]}),e("div",{className:"text-[10px] text-ink/60 space-y-0.5",children:[e("div",{children:["Remaining"," ",e("span",{className:"font-semibold text-ink",children:t.remainingRp===null?"Unlimited":x(t.remainingRp)})," ","· Used ",e("span",{className:"font-semibold text-ink",children:x(t.usedRp)})]}),e("div",{children:["Expires ",ea(t.expiresAt)]}),t.scopeModels.length>0&&e("div",{children:["Models: ",t.scopeModels.join(", ")]})]})]})}function A({quota:t}){if(!t)return e("p",{className:"text-[11px] text-ink/50",children:"Quota data is not available for this account."});return e("div",{className:"space-y-2",children:[e("div",{className:"flex items-center justify-between gap-2",children:[e("h4",{className:"text-[10px] font-mono font-semibold uppercase tracking-wider text-ink/40",children:"Quota windows"}),t.planName&&e("span",{className:"text-[10px] text-ink/60",children:["Plan ",e("span",{className:"font-semibold text-ink",children:t.planName})]})]}),t.windows.length===0?e("p",{className:"text-[11px] text-ink/50",children:"No quota windows reported."}):e("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-2.5",children:t.windows.map((r)=>e(z,{window:r},r.key))}),t.coupon&&e(H,{coupon:t.coupon})]})}function F({usage:t}){if(!t)return e("p",{className:"text-[11px] text-ink/50",children:"The 30-day usage report is not available."});let r=t.rows.reduce((l,p)=>l+p.inputTokens,0),o=t.rows.reduce((l,p)=>l+p.outputTokens,0);return e("div",{className:"space-y-2",children:[e("h4",{className:"text-[10px] font-mono font-semibold uppercase tracking-wider text-ink/40",children:"30-day usage by model"}),e("div",{className:"overflow-x-auto border border-ink/15 rounded-lg shadow-xs",children:e("table",{className:"w-full text-[11px]",children:[e("thead",{className:"bg-ink/5 text-ink/60",children:e("tr",{children:[e("th",{className:"text-left font-semibold px-3 py-2 whitespace-nowrap",children:"Model"}),e("th",{className:"text-right font-semibold px-3 py-2 whitespace-nowrap",children:"Requests"}),e("th",{className:"text-right font-semibold px-3 py-2 whitespace-nowrap",children:"Input tokens"}),e("th",{className:"text-right font-semibold px-3 py-2 whitespace-nowrap",children:"Output tokens"}),e("th",{className:"text-right font-semibold px-3 py-2 whitespace-nowrap",children:"Cost"})]})}),e("tbody",{className:"divide-y divide-ink/10",children:t.rows.length===0?e("tr",{children:e("td",{colSpan:5,className:"px-3 py-3 text-center text-ink/50",children:"No usage recorded in the last 30 days."})}):t.rows.map((l)=>e("tr",{children:[e("td",{className:"px-3 py-1.5 font-mono text-ink whitespace-nowrap",children:l.model}),e("td",{className:"px-3 py-1.5 text-right tabular-nums text-ink/80",children:b(l.requests)}),e("td",{className:"px-3 py-1.5 text-right tabular-nums text-ink/80",children:k(l.inputTokens)}),e("td",{className:"px-3 py-1.5 text-right tabular-nums text-ink/80",children:k(l.outputTokens)}),e("td",{className:"px-3 py-1.5 text-right tabular-nums text-ink/80",children:x(l.costRp)})]},l.model))}),e("tfoot",{className:"bg-ink/5 border-t border-ink/15 font-semibold text-ink",children:e("tr",{children:[e("td",{className:"px-3 py-2",children:"Total"}),e("td",{className:"px-3 py-2 text-right tabular-nums",children:b(t.totalRequests)}),e("td",{className:"px-3 py-2 text-right tabular-nums",children:k(r)}),e("td",{className:"px-3 py-2 text-right tabular-nums",children:k(o)}),e("td",{className:"px-3 py-2 text-right tabular-nums",children:x(t.totalCostRp)})]})})]})})]})}function E({report:t}){let{balance:r,usage:o,quota:l}=t;if(!r&&!o&&!l)return e("p",{className:"text-[11px] text-ink/50",children:"No kenari data was returned for this account."});let p=r?r.amountRp!==null?x(r.amountRp):r.raw:"–",c=r?r.amountRp!==null?r.raw:"Amount could not be parsed":"Balance unavailable",m=o?o.rows.reduce((g,u)=>g+u.inputTokens+u.outputTokens,0):0;return e(d,{children:[e("div",{className:"@container",children:e("div",{className:"grid grid-cols-3 @[540px]:grid-cols-5 gap-2.5 items-stretch",children:[e(rt,{value:p,label:"Wallet balance",hint:c}),e(rt,{value:l?.planName??"–",label:"Active plan",hint:l?"kenari quota plan":"Quota unavailable"}),e(rt,{value:o?b(o.totalRequests):"–",label:"Requests (30 days)",hint:o?"Across all models":"Usage report unavailable"}),e(rt,{value:o?x(o.totalCostRp):"–",label:"Cost (30 days)",hint:o?"Billed in Rupiah":"Usage report unavailable"}),e(rt,{value:o?k(m):"–",label:"Tokens processed (30 days)",hint:o?"Input + output":"Usage report unavailable",tone:"muted",className:"col-span-2 @[540px]:col-span-1"})]})}),e(A,{quota:l}),e(F,{usage:o})]})}function W({report:t}){let r=t.balance;if(!r)return e("p",{className:"text-[11px] text-ink/50",children:"DeepSeek balance data is not available."});return e(d,{children:[e("div",{className:"@container",children:e("div",{className:"grid grid-cols-3 @[540px]:grid-cols-5 gap-2.5 items-stretch",children:[e(rt,{value:r.isAvailable?"Available":"Unavailable",label:"Prepaid balance",hint:r.isAvailable?"Account can spend":"Top up required",tone:r.isAvailable?"default":"muted"}),e(rt,{value:b(r.entries.length),label:"Currency buckets",hint:r.entries.length>0?"From the balance endpoint":"No entries returned",tone:"muted"})]})}),r.entries.length===0?e("p",{className:"text-[11px] text-ink/50",children:"The balance endpoint returned no currency entries."}):e("div",{className:"grid grid-cols-1 gap-2.5",children:r.entries.map((o)=>e("div",{className:"bg-paper border border-ink/15 rounded-lg p-3 shadow-xs",children:[e("div",{className:"flex items-center justify-between gap-2 mb-2",children:[e("span",{className:"text-[11px] font-semibold text-ink",children:o.currency}),e("span",{className:"text-[10px] font-mono uppercase tracking-wider text-ink/40",children:"Balance"})]}),e("dl",{className:"grid grid-cols-3 gap-2 text-[10px]",children:[e("div",{children:[e("dt",{className:"text-ink/50",children:"Total"}),e("dd",{className:"font-semibold text-ink tabular-nums break-words",children:N(o.totalBalance)})]}),e("div",{children:[e("dt",{className:"text-ink/50",children:"Granted"}),e("dd",{className:"font-semibold text-ink tabular-nums break-words",children:N(o.grantedBalance)})]}),e("div",{children:[e("dt",{className:"text-ink/50",children:"Topped up"}),e("dd",{className:"font-semibold text-ink tabular-nums break-words",children:N(o.toppedUpBalance)})]})]})]},o.currency))})]})}function R(t,r,o,l){let p=t.find((c)=>c.id===r);if(p){p.limits.push(l);return}t.push({id:r,title:o,limits:[l]})}function V(t){let r=(t.split(":")[1]??"").toLowerCase();if(r==="google")return{id:"google",title:"Google"};if(r==="anthropic"||r==="openai")return{id:"third-party",title:"Claude & GPT (shared)"};if(r==="default"||r==="")return{id:"default",title:"Usage"};return{id:r,title:r}}function X(t){let r=[];for(let o of t)if(o.id==="anthropic:extra")R(r,"balance","Balance",o);else R(r,"windows","Quota windows",o);return r}function J(t){let r=[];for(let o of t){let l=V(o.id);if(l.id==="third-party"){if(r.find((c)=>c.id==="third-party")?.limits.some((c)=>Z(c,o)))continue}R(r,l.id,l.title,o)}return r}function Z(t,r){return t.unit===r.unit&&t.label===r.label&&t.usedFraction===r.usedFraction&&t.remaining===r.remaining&&t.resetsAt===r.resetsAt}function _(t,r){if(r.length===0)return[];let o=t.trim().toLowerCase();if(o==="anthropic")return X(r);if(o==="google-antigravity")return J(r);return[{id:"all",title:"Quota windows",limits:[...r]}]}function Y({limit:t}){let r=Math.min(100,Math.max(0,(t.usedFraction??0)*100)),o=t.modelId??t.accountId,l=t.used!==void 0?w(t.used,t.unit):void 0,p=t.limit!==void 0?w(t.limit,t.unit):void 0,c=t.remaining!==void 0?w(t.remaining,t.unit):void 0;return e("div",{className:"bg-paper border border-ink/15 rounded-lg p-3 shadow-xs space-y-2",children:[e("div",{className:"flex items-start justify-between gap-2",children:[e("div",{className:"min-w-0",children:[e("div",{className:"text-[11px] font-semibold text-ink truncate",children:[t.label,t.windowLabel&&e("span",{className:"ml-1.5 rounded border border-ink/15 px-1 py-px font-mono text-[9px] font-normal text-ink/50",children:t.windowLabel})]}),o&&e("div",{className:"text-[10px] text-ink/50 truncate",children:o})]}),e("span",{className:"text-[10px] text-ink/50 flex-shrink-0 whitespace-nowrap",children:t.resetsAt!==void 0?`Resets ${ea(new Date(t.resetsAt).toISOString())}`:""})]}),e("div",{className:"h-1.5 w-full bg-ink/10 rounded-full overflow-hidden",children:e("div",{className:`h-full rounded-full ${t.status==="exhausted"?"bg-error/70":"bg-ink/80"}`,style:{width:`${r}%`}})}),e("div",{className:"flex flex-wrap items-center justify-between gap-x-3 gap-y-0.5 text-[10px] text-ink/60",children:[e("span",{children:["Used"," ",e("span",{className:"font-semibold text-ink",children:t.unit==="percent"||!l?D(t.usedFraction??0):l}),t.unit!=="percent"&&l&&p?` of ${p}`:""]}),e("span",{className:"flex items-center gap-2",children:[t.status!=="ok"&&t.status!=="unknown"&&e("span",{className:"text-[10px] font-mono uppercase px-1.5 py-0.5 rounded bg-ink/10 text-ink/70",children:t.status}),c&&e("span",{children:["Remaining ",e("span",{className:"font-semibold text-ink",children:c})]})]})]}),t.notes&&t.notes.length>0&&e("ul",{className:"text-[10px] text-ink/50 leading-relaxed space-y-0.5",children:t.notes.map((m)=>e("li",{children:m},m))})]})}function Q({providerId:t,limits:r,tracked:o,unavailable:l,notes:p}){let c=_(t,r);return e("div",{className:"space-y-2",children:[p&&p.length>0&&e("ul",{className:"text-[10px] text-ink/50 leading-relaxed space-y-0.5",children:p.map((m)=>e("li",{children:m},m))}),c.length===0?e(d,{children:[e("h4",{className:"text-[10px] font-mono font-semibold uppercase tracking-wider text-ink/40",children:"Quota windows"}),e("p",{className:"text-[11px] text-ink/50",children:!o?"No quota source for this provider: omp ships no usage adapter for it and it exposes no balance endpoint Kabmo knows.":l?"omp tracks this provider but its usage endpoint returned no data — an invalid or expired credential, an unreachable endpoint, or a plan without quota windows.":"No quota windows were reported for this provider."})]}):c.map((m)=>e("div",{className:"@container space-y-2",children:[e("h4",{className:"text-[10px] font-mono font-semibold uppercase tracking-wider text-ink/40",children:m.title}),e("div",{className:"grid grid-cols-1 @[520px]:grid-cols-2 gap-2.5",children:m.limits.map((g)=>e(Y,{limit:g},g.id))})]},m.id))]})}var ee="DeepSeek exposes no usage or quota API — only the prepaid balance (and the web console at platform.deepseek.com) is available.";function ou({summary:t}){let r=Boolean(t.kenari||t.deepseek);return e(P,{providerName:t.name,providerSlug:t.id,iconUrl:t.iconUrl,credentialSources:t.credentialSources,error:t.error,note:t.deepseek?ee:void 0,children:[t.kenari&&e(E,{report:t.kenari}),t.deepseek&&e(W,{report:t.deepseek}),!r&&(t.limits.length>0||!t.error)&&e(Q,{providerId:t.id,limits:t.limits,tracked:t.tracked,unavailable:t.limitsUnavailable,notes:t.notes})]})}function te(t){let r=t.filter((p)=>p.usedFraction!==void 0);if(r.length===0){let p=t.find((c)=>c.unit==="usd"&&c.remaining!==void 0);if(p)return`${U(p.remaining??0)} left`;return t[0]?.label}let o=r.reduce((p,c)=>(c.usedFraction??0)>(p.usedFraction??0)?c:p),l=Math.round((o.usedFraction??0)*100);return o.windowLabel?`${l}% · ${o.windowLabel}`:`${l}% used`}function vs(t){return t.providers.map((r)=>({id:r.id,name:r.name,...r.iconUrl?{iconUrl:r.iconUrl}:{},error:r.error,hint:ne(r),limits:r.limits,tracked:r.tracked,limitsUnavailable:r.limitsUnavailable,summary:r}))}function ne(t){let r=t.kenari?.quota?.planName;if(r)return r;let o=t.deepseek?.balance?.entries[0];if(o)return`${o.currency} ${N(o.totalBalance)}`;return te(t.limits)??"No quota reported"}function ks(t){return t.error?"Error":"Connected"}function K(){let[t,r]=n([]),[o,l]=n(null),[p,c]=n(!0),m=a(()=>{c(!0),fetch("/api/settings/usage/reset").then((u)=>u.json()).then((u)=>{r(Array.isArray(u.accounts)?u.accounts:[]),l(typeof u.error==="string"?u.error:null)}).catch((u)=>{r([]),l(u instanceof Error?u.message:"Failed to load saved resets")}).finally(()=>c(!1))},[]);i(()=>{m()},[m]);let g=a(async(u)=>{try{let h=await(await fetch("/api/settings/usage/reset",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({target:u})})).json();if(h.ok)m();return{ok:Boolean(h.ok),message:h.message||"No result reported."}}catch(f){return{ok:!1,message:f instanceof Error?f.message:"Failed to spend the saved reset"}}},[m]);return{accounts:t,error:o,isLoading:p,reload:m,spend:g}}function ae({account:t,onSpend:r,spending:o}){let l=`${t.provider}/${t.credentialId}`,p=t.email??t.accountId??t.credentialId,c=t.orgName??t.orgId,m=t.availableCount??t.credits.length,g=t.redeemableCount??0,u=t.error??t.unavailableReason;return e("div",{className:"bg-paper border border-ink/15 rounded-lg p-3 shadow-xs space-y-2",children:[e("div",{className:"flex items-start justify-between gap-2",children:[e("div",{className:"min-w-0",children:[e("div",{className:"text-[11px] font-semibold text-ink truncate",children:[p,c?e("span",{className:"text-ink/50 font-normal",children:[" · ",c]}):null]}),e("div",{className:"text-[10px] text-ink/50 font-mono truncate",children:l})]}),e("span",{className:"text-[10px] text-ink/60 flex-shrink-0 whitespace-nowrap",children:g>0?`${g} of ${m} usable`:`${m} saved`})]}),t.soonestExpiry!==void 0&&e("div",{className:"text-[10px] text-ink/60",children:["Soonest expires ",ea(new Date(t.soonestExpiry).toISOString())]}),t.credits.length>0&&e("div",{className:"space-y-1",children:t.credits.map((f)=>e("div",{className:"flex items-center justify-between gap-2 text-[10px] text-ink/70",children:[e("span",{className:"truncate",children:f.title??f.program??f.id}),e("span",{className:"flex items-center gap-1.5 flex-shrink-0",children:[f.clears&&f.clears.length>0&&e("span",{className:"font-mono text-ink/50",children:f.clears.join(", ")}),f.usable===!1&&e("span",{className:"font-mono uppercase px-1.5 py-0.5 rounded bg-ink/10 text-ink/60",children:"blocked"})]})]},f.id))}),u&&e("div",{className:"text-[10px] text-ink/60 leading-snug",children:u}),e("button",{type:"button",onClick:()=>r(l),disabled:o||g===0,title:g===0?u??"Nothing to spend on this account right now.":`Spend a saved reset on ${l}`,className:"w-full rounded-md border border-ink/15 px-2 py-1 text-[11px] font-medium text-ink/80 hover:bg-ink/5 transition-colors cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed",children:o?"Spending…":"Spend saved reset"})]})}function su(){let{accounts:t,error:r,isLoading:o,reload:l,spend:p}=K(),[c,m]=n(null),[g,u]=n(null),f=(v)=>{m(v),u(null),p(v).then((M)=>{u(M),m(null)})},h=!o&&!r&&t.length===0;return e("div",{className:"space-y-2",children:[e("div",{className:"flex items-center justify-between gap-2",children:[e("div",{className:"min-w-0",children:[e("div",{className:"text-[11px] font-semibold text-ink",children:"Saved rate-limit resets"}),e("div",{className:"text-[10px] text-ink/50 leading-snug",children:"Provider-issued resets for Codex and Claude accounts. Spending one clears the window it covers."})]}),e("button",{type:"button",onClick:l,disabled:o,title:"Re-read saved resets",className:"p-1.5 bg-paper border border-ink/15 rounded-md hover:bg-ink/5 text-ink/80 transition-colors disabled:opacity-50 flex-shrink-0",children:e(C,{size:12,className:o?"animate-spin text-ink":""})})]}),r&&e("div",{className:"flex items-start gap-1.5 text-[10px] text-error leading-snug",children:[e(I,{size:12,className:"flex-shrink-0 mt-px"}),e("span",{children:r})]}),t.map((v)=>e(ae,{account:v,onSpend:f,spending:c===`${v.provider}/${v.credentialId}`},`${v.provider}/${v.credentialId}`)),h&&e("p",{className:"text-[10px] text-ink/50 leading-snug",children:"No saved resets on any account."}),g&&e("div",{className:`text-[10px] leading-snug ${g.ok?"text-ink/70":"text-error"}`,children:g.message})]})}function lu(){let[t,r]=n(null),[o,l]=n(!0),[p,c]=n(null),m=a(async(g)=>{if(!g?.silent)l(!0);c(null);try{let u=g?.force?"/api/settings/usage?refresh=1":"/api/settings/usage",f=await fetch(u);if(!f.ok)throw Error(`Usage request failed (${f.status})`);let h=await f.json();r(h)}catch(u){c(u instanceof Error?u.message:"Failed to load provider usage")}finally{if(!g?.silent)l(!1)}},[]);return i(()=>{m()},[m]),{report:t,isLoading:o,error:p,reload:m}}
1
+ import{d,n,i,a,e,s,I,C,rt,Me}from"./index-3wpsr2bc.js";var q={name:"ticket",size:24,node:[["path",{d:"M2 9a3 3 0 0 1 0 6v2a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-2a3 3 0 0 1 0-6V7a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2Z",key:"qn84l0"}],["path",{d:"M13 5v2",key:"dyzc3o"}],["path",{d:"M13 17v2",key:"1ont0d"}],["path",{d:"M13 11v2",key:"1wjjxi"}]]},S=s(q);function P({providerName:t,providerSlug:r,iconUrl:o,credentialSources:l,error:p,note:c,children:m}){return e("section",{className:"bg-paper border border-ink/15 rounded-lg shadow-xs",children:[e("header",{className:"flex items-center justify-between gap-2 px-3.5 py-2.5 border-b border-ink/10",children:[e("span",{className:"flex min-w-0 items-center gap-2",children:[r&&e(Me,{provider:{slug:r,name:t,...o?{iconUrl:o}:{}},size:20}),e("span",{className:"truncate text-xs font-semibold text-ink",children:t})]}),e("span",{className:"text-[10px] font-mono uppercase tracking-wider text-ink/50 truncate",title:`Credentials from ${l.join(", ")}`,children:l.join(" · ")})]}),e("div",{className:"p-3.5 space-y-4",children:[p&&e("p",{className:"flex items-start gap-2 text-error text-xs leading-relaxed",children:[e(I,{size:14,className:"shrink-0 mt-0.5"}),e("span",{className:"break-words",children:p})]}),m,c&&e("p",{className:"text-[10px] text-ink/50 leading-relaxed border-t border-ink/10 pt-2.5",children:c})]})]})}var B=new Intl.NumberFormat("id-ID",{style:"currency",currency:"IDR",maximumFractionDigits:0}),j=new Intl.NumberFormat("id-ID"),y=new Intl.NumberFormat("id-ID",{minimumFractionDigits:2,maximumFractionDigits:2,useGrouping:!1}),G=new Intl.DateTimeFormat("id-ID",{dateStyle:"medium",timeStyle:"short"});function x(t){return B.format(t)}function b(t){return j.format(t)}function ea(t){let r=new Date(t);if(Number.isNaN(r.getTime()))return t;return G.format(r)}function L(t,r){if(r<=0)return 0;return Math.min(100,Math.max(0,t/r*100))}function T(t,r){if(r<=0)return"0%";return`${new Intl.NumberFormat("id-ID",{maximumFractionDigits:1}).format(t/r*100)}%`}function k(t){if(!Number.isFinite(t))return"0";let r=Math.abs(t);if(r>=1e9)return`${y.format(t/1e9)}B`;if(r>=1e6)return`${y.format(t/1e6)}M`;if(r>=1000)return`${y.format(t/1000)}K`;return b(t)}function N(t){let r=Number(t);if(t.trim()===""||!Number.isFinite(r))return t;return b(r)}var O=new Intl.NumberFormat("id-ID",{minimumFractionDigits:2,maximumFractionDigits:2});function U(t){if(!Number.isFinite(t))return"$0,00";return`$${O.format(t)}`}function w(t,r){if(!Number.isFinite(t))return"—";switch(r){case"percent":return`${new Intl.NumberFormat("id-ID",{maximumFractionDigits:1}).format(t)}%`;case"usd":return U(t);case"tokens":case"bytes":return k(t);default:return b(t)}}function D(t){if(!Number.isFinite(t))return"0%";return`${new Intl.NumberFormat("id-ID",{maximumFractionDigits:1}).format(t*100)}%`}function z({window:t}){let r=t.usedRp+t.remainingRp,o=L(t.usedRp,r);return e("div",{className:"bg-paper border border-ink/15 rounded-lg p-3 shadow-xs space-y-2",children:[e("div",{className:"flex items-center justify-between gap-2",children:[e("span",{className:"text-[11px] font-semibold text-ink",children:t.label}),e("span",{className:"text-[10px] text-ink/50",children:["Resets ",ea(t.resetsAt)]})]}),e("div",{className:"h-1.5 w-full bg-ink/10 rounded-full overflow-hidden",children:e("div",{className:"h-full bg-ink/80 rounded-full",style:{width:`${o}%`}})}),e("div",{className:"flex flex-wrap items-center justify-between gap-x-3 gap-y-0.5 text-[10px] text-ink/60",children:[e("span",{children:["Used ",e("span",{className:"font-semibold text-ink",children:x(t.usedRp)})," ·"," ",T(t.usedRp,r)]}),e("span",{children:["Remaining ",e("span",{className:"font-semibold text-ink",children:x(t.remainingRp)})]})]})]})}function H({coupon:t}){return e("div",{className:"bg-ink/5 border border-ink/10 rounded-lg p-3 shadow-xs",children:[e("div",{className:"flex items-center gap-1.5 mb-1.5",children:[e(S,{size:12,className:"text-ink/60"}),e("span",{className:"text-[11px] font-semibold text-ink",children:["Active coupon · ",t.name]})]}),e("div",{className:"text-[10px] text-ink/60 space-y-0.5",children:[e("div",{children:["Remaining"," ",e("span",{className:"font-semibold text-ink",children:t.remainingRp===null?"Unlimited":x(t.remainingRp)})," ","· Used ",e("span",{className:"font-semibold text-ink",children:x(t.usedRp)})]}),e("div",{children:["Expires ",ea(t.expiresAt)]}),t.scopeModels.length>0&&e("div",{children:["Models: ",t.scopeModels.join(", ")]})]})]})}function A({quota:t}){if(!t)return e("p",{className:"text-[11px] text-ink/50",children:"Quota data is not available for this account."});return e("div",{className:"space-y-2",children:[e("div",{className:"flex items-center justify-between gap-2",children:[e("h4",{className:"text-[10px] font-mono font-semibold uppercase tracking-wider text-ink/40",children:"Quota windows"}),t.planName&&e("span",{className:"text-[10px] text-ink/60",children:["Plan ",e("span",{className:"font-semibold text-ink",children:t.planName})]})]}),t.windows.length===0?e("p",{className:"text-[11px] text-ink/50",children:"No quota windows reported."}):e("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-2.5",children:t.windows.map((r)=>e(z,{window:r},r.key))}),t.coupon&&e(H,{coupon:t.coupon})]})}function F({usage:t}){if(!t)return e("p",{className:"text-[11px] text-ink/50",children:"The 30-day usage report is not available."});let r=t.rows.reduce((l,p)=>l+p.inputTokens,0),o=t.rows.reduce((l,p)=>l+p.outputTokens,0);return e("div",{className:"space-y-2",children:[e("h4",{className:"text-[10px] font-mono font-semibold uppercase tracking-wider text-ink/40",children:"30-day usage by model"}),e("div",{className:"overflow-x-auto border border-ink/15 rounded-lg shadow-xs",children:e("table",{className:"w-full text-[11px]",children:[e("thead",{className:"bg-ink/5 text-ink/60",children:e("tr",{children:[e("th",{className:"text-left font-semibold px-3 py-2 whitespace-nowrap",children:"Model"}),e("th",{className:"text-right font-semibold px-3 py-2 whitespace-nowrap",children:"Requests"}),e("th",{className:"text-right font-semibold px-3 py-2 whitespace-nowrap",children:"Input tokens"}),e("th",{className:"text-right font-semibold px-3 py-2 whitespace-nowrap",children:"Output tokens"}),e("th",{className:"text-right font-semibold px-3 py-2 whitespace-nowrap",children:"Cost"})]})}),e("tbody",{className:"divide-y divide-ink/10",children:t.rows.length===0?e("tr",{children:e("td",{colSpan:5,className:"px-3 py-3 text-center text-ink/50",children:"No usage recorded in the last 30 days."})}):t.rows.map((l)=>e("tr",{children:[e("td",{className:"px-3 py-1.5 font-mono text-ink whitespace-nowrap",children:l.model}),e("td",{className:"px-3 py-1.5 text-right tabular-nums text-ink/80",children:b(l.requests)}),e("td",{className:"px-3 py-1.5 text-right tabular-nums text-ink/80",children:k(l.inputTokens)}),e("td",{className:"px-3 py-1.5 text-right tabular-nums text-ink/80",children:k(l.outputTokens)}),e("td",{className:"px-3 py-1.5 text-right tabular-nums text-ink/80",children:x(l.costRp)})]},l.model))}),e("tfoot",{className:"bg-ink/5 border-t border-ink/15 font-semibold text-ink",children:e("tr",{children:[e("td",{className:"px-3 py-2",children:"Total"}),e("td",{className:"px-3 py-2 text-right tabular-nums",children:b(t.totalRequests)}),e("td",{className:"px-3 py-2 text-right tabular-nums",children:k(r)}),e("td",{className:"px-3 py-2 text-right tabular-nums",children:k(o)}),e("td",{className:"px-3 py-2 text-right tabular-nums",children:x(t.totalCostRp)})]})})]})})]})}function E({report:t}){let{balance:r,usage:o,quota:l}=t;if(!r&&!o&&!l)return e("p",{className:"text-[11px] text-ink/50",children:"No kenari data was returned for this account."});let p=r?r.amountRp!==null?x(r.amountRp):r.raw:"–",c=r?r.amountRp!==null?r.raw:"Amount could not be parsed":"Balance unavailable",m=o?o.rows.reduce((g,u)=>g+u.inputTokens+u.outputTokens,0):0;return e(d,{children:[e("div",{className:"@container",children:e("div",{className:"grid grid-cols-3 @[540px]:grid-cols-5 gap-2.5 items-stretch",children:[e(rt,{value:p,label:"Wallet balance",hint:c}),e(rt,{value:l?.planName??"–",label:"Active plan",hint:l?"kenari quota plan":"Quota unavailable"}),e(rt,{value:o?b(o.totalRequests):"–",label:"Requests (30 days)",hint:o?"Across all models":"Usage report unavailable"}),e(rt,{value:o?x(o.totalCostRp):"–",label:"Cost (30 days)",hint:o?"Billed in Rupiah":"Usage report unavailable"}),e(rt,{value:o?k(m):"–",label:"Tokens processed (30 days)",hint:o?"Input + output":"Usage report unavailable",tone:"muted",className:"col-span-2 @[540px]:col-span-1"})]})}),e(A,{quota:l}),e(F,{usage:o})]})}function W({report:t}){let r=t.balance;if(!r)return e("p",{className:"text-[11px] text-ink/50",children:"DeepSeek balance data is not available."});return e(d,{children:[e("div",{className:"@container",children:e("div",{className:"grid grid-cols-3 @[540px]:grid-cols-5 gap-2.5 items-stretch",children:[e(rt,{value:r.isAvailable?"Available":"Unavailable",label:"Prepaid balance",hint:r.isAvailable?"Account can spend":"Top up required",tone:r.isAvailable?"default":"muted"}),e(rt,{value:b(r.entries.length),label:"Currency buckets",hint:r.entries.length>0?"From the balance endpoint":"No entries returned",tone:"muted"})]})}),r.entries.length===0?e("p",{className:"text-[11px] text-ink/50",children:"The balance endpoint returned no currency entries."}):e("div",{className:"grid grid-cols-1 gap-2.5",children:r.entries.map((o)=>e("div",{className:"bg-paper border border-ink/15 rounded-lg p-3 shadow-xs",children:[e("div",{className:"flex items-center justify-between gap-2 mb-2",children:[e("span",{className:"text-[11px] font-semibold text-ink",children:o.currency}),e("span",{className:"text-[10px] font-mono uppercase tracking-wider text-ink/40",children:"Balance"})]}),e("dl",{className:"grid grid-cols-3 gap-2 text-[10px]",children:[e("div",{children:[e("dt",{className:"text-ink/50",children:"Total"}),e("dd",{className:"font-semibold text-ink tabular-nums break-words",children:N(o.totalBalance)})]}),e("div",{children:[e("dt",{className:"text-ink/50",children:"Granted"}),e("dd",{className:"font-semibold text-ink tabular-nums break-words",children:N(o.grantedBalance)})]}),e("div",{children:[e("dt",{className:"text-ink/50",children:"Topped up"}),e("dd",{className:"font-semibold text-ink tabular-nums break-words",children:N(o.toppedUpBalance)})]})]})]},o.currency))})]})}function R(t,r,o,l){let p=t.find((c)=>c.id===r);if(p){p.limits.push(l);return}t.push({id:r,title:o,limits:[l]})}function V(t){let r=(t.split(":")[1]??"").toLowerCase();if(r==="google")return{id:"google",title:"Google"};if(r==="anthropic"||r==="openai")return{id:"third-party",title:"Claude & GPT (shared)"};if(r==="default"||r==="")return{id:"default",title:"Usage"};return{id:r,title:r}}function X(t){let r=[];for(let o of t)if(o.id==="anthropic:extra")R(r,"balance","Balance",o);else R(r,"windows","Quota windows",o);return r}function J(t){let r=[];for(let o of t){let l=V(o.id);if(l.id==="third-party"){if(r.find((c)=>c.id==="third-party")?.limits.some((c)=>Z(c,o)))continue}R(r,l.id,l.title,o)}return r}function Z(t,r){return t.unit===r.unit&&t.label===r.label&&t.usedFraction===r.usedFraction&&t.remaining===r.remaining&&t.resetsAt===r.resetsAt}function _(t,r){if(r.length===0)return[];let o=t.trim().toLowerCase();if(o==="anthropic")return X(r);if(o==="google-antigravity")return J(r);return[{id:"all",title:"Quota windows",limits:[...r]}]}function Y({limit:t}){let r=Math.min(100,Math.max(0,(t.usedFraction??0)*100)),o=t.modelId??t.accountId,l=t.used!==void 0?w(t.used,t.unit):void 0,p=t.limit!==void 0?w(t.limit,t.unit):void 0,c=t.remaining!==void 0?w(t.remaining,t.unit):void 0;return e("div",{className:"bg-paper border border-ink/15 rounded-lg p-3 shadow-xs space-y-2",children:[e("div",{className:"flex items-start justify-between gap-2",children:[e("div",{className:"min-w-0",children:[e("div",{className:"text-[11px] font-semibold text-ink truncate",children:[t.label,t.windowLabel&&e("span",{className:"ml-1.5 rounded border border-ink/15 px-1 py-px font-mono text-[9px] font-normal text-ink/50",children:t.windowLabel})]}),o&&e("div",{className:"text-[10px] text-ink/50 truncate",children:o})]}),e("span",{className:"text-[10px] text-ink/50 flex-shrink-0 whitespace-nowrap",children:t.resetsAt!==void 0?`Resets ${ea(new Date(t.resetsAt).toISOString())}`:""})]}),e("div",{className:"h-1.5 w-full bg-ink/10 rounded-full overflow-hidden",children:e("div",{className:`h-full rounded-full ${t.status==="exhausted"?"bg-error/70":"bg-ink/80"}`,style:{width:`${r}%`}})}),e("div",{className:"flex flex-wrap items-center justify-between gap-x-3 gap-y-0.5 text-[10px] text-ink/60",children:[e("span",{children:["Used"," ",e("span",{className:"font-semibold text-ink",children:t.unit==="percent"||!l?D(t.usedFraction??0):l}),t.unit!=="percent"&&l&&p?` of ${p}`:""]}),e("span",{className:"flex items-center gap-2",children:[t.status!=="ok"&&t.status!=="unknown"&&e("span",{className:"text-[10px] font-mono uppercase px-1.5 py-0.5 rounded bg-ink/10 text-ink/70",children:t.status}),c&&e("span",{children:["Remaining ",e("span",{className:"font-semibold text-ink",children:c})]})]})]}),t.notes&&t.notes.length>0&&e("ul",{className:"text-[10px] text-ink/50 leading-relaxed space-y-0.5",children:t.notes.map((m)=>e("li",{children:m},m))})]})}function Q({providerId:t,limits:r,tracked:o,unavailable:l,notes:p}){let c=_(t,r);return e("div",{className:"space-y-2",children:[p&&p.length>0&&e("ul",{className:"text-[10px] text-ink/50 leading-relaxed space-y-0.5",children:p.map((m)=>e("li",{children:m},m))}),c.length===0?e(d,{children:[e("h4",{className:"text-[10px] font-mono font-semibold uppercase tracking-wider text-ink/40",children:"Quota windows"}),e("p",{className:"text-[11px] text-ink/50",children:!o?"No quota source for this provider: omp ships no usage adapter for it and it exposes no balance endpoint Kabmo knows.":l?"omp tracks this provider but its usage endpoint returned no data — an invalid or expired credential, an unreachable endpoint, or a plan without quota windows.":"No quota windows were reported for this provider."})]}):c.map((m)=>e("div",{className:"@container space-y-2",children:[e("h4",{className:"text-[10px] font-mono font-semibold uppercase tracking-wider text-ink/40",children:m.title}),e("div",{className:"grid grid-cols-1 @[520px]:grid-cols-2 gap-2.5",children:m.limits.map((g)=>e(Y,{limit:g},g.id))})]},m.id))]})}var ee="DeepSeek exposes no usage or quota API — only the prepaid balance (and the web console at platform.deepseek.com) is available.";function ou({summary:t}){let r=Boolean(t.kenari||t.deepseek);return e(P,{providerName:t.name,providerSlug:t.id,iconUrl:t.iconUrl,credentialSources:t.credentialSources,error:t.error,note:t.deepseek?ee:void 0,children:[t.kenari&&e(E,{report:t.kenari}),t.deepseek&&e(W,{report:t.deepseek}),!r&&(t.limits.length>0||!t.error)&&e(Q,{providerId:t.id,limits:t.limits,tracked:t.tracked,unavailable:t.limitsUnavailable,notes:t.notes})]})}function te(t){let r=t.filter((p)=>p.usedFraction!==void 0);if(r.length===0){let p=t.find((c)=>c.unit==="usd"&&c.remaining!==void 0);if(p)return`${U(p.remaining??0)} left`;return t[0]?.label}let o=r.reduce((p,c)=>(c.usedFraction??0)>(p.usedFraction??0)?c:p),l=Math.round((o.usedFraction??0)*100);return o.windowLabel?`${l}% · ${o.windowLabel}`:`${l}% used`}function vs(t){return t.providers.map((r)=>({id:r.id,name:r.name,...r.iconUrl?{iconUrl:r.iconUrl}:{},error:r.error,hint:ne(r),limits:r.limits,tracked:r.tracked,limitsUnavailable:r.limitsUnavailable,summary:r}))}function ne(t){let r=t.kenari?.quota?.planName;if(r)return r;let o=t.deepseek?.balance?.entries[0];if(o)return`${o.currency} ${N(o.totalBalance)}`;return te(t.limits)??"No quota reported"}function ks(t){return t.error?"Error":"Connected"}function K(){let[t,r]=n([]),[o,l]=n(null),[p,c]=n(!0),m=a(()=>{c(!0),fetch("/api/settings/usage/reset").then((u)=>u.json()).then((u)=>{r(Array.isArray(u.accounts)?u.accounts:[]),l(typeof u.error==="string"?u.error:null)}).catch((u)=>{r([]),l(u instanceof Error?u.message:"Failed to load saved resets")}).finally(()=>c(!1))},[]);i(()=>{m()},[m]);let g=a(async(u)=>{try{let h=await(await fetch("/api/settings/usage/reset",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({target:u})})).json();if(h.ok)m();return{ok:Boolean(h.ok),message:h.message||"No result reported."}}catch(f){return{ok:!1,message:f instanceof Error?f.message:"Failed to spend the saved reset"}}},[m]);return{accounts:t,error:o,isLoading:p,reload:m,spend:g}}function ae({account:t,onSpend:r,spending:o}){let l=`${t.provider}/${t.credentialId}`,p=t.email??t.accountId??t.credentialId,c=t.orgName??t.orgId,m=t.availableCount??t.credits.length,g=t.redeemableCount??0,u=t.error??t.unavailableReason;return e("div",{className:"bg-paper border border-ink/15 rounded-lg p-3 shadow-xs space-y-2",children:[e("div",{className:"flex items-start justify-between gap-2",children:[e("div",{className:"min-w-0",children:[e("div",{className:"text-[11px] font-semibold text-ink truncate",children:[p,c?e("span",{className:"text-ink/50 font-normal",children:[" · ",c]}):null]}),e("div",{className:"text-[10px] text-ink/50 font-mono truncate",children:l})]}),e("span",{className:"text-[10px] text-ink/60 flex-shrink-0 whitespace-nowrap",children:g>0?`${g} of ${m} usable`:`${m} saved`})]}),t.soonestExpiry!==void 0&&e("div",{className:"text-[10px] text-ink/60",children:["Soonest expires ",ea(new Date(t.soonestExpiry).toISOString())]}),t.credits.length>0&&e("div",{className:"space-y-1",children:t.credits.map((f)=>e("div",{className:"flex items-center justify-between gap-2 text-[10px] text-ink/70",children:[e("span",{className:"truncate",children:f.title??f.program??f.id}),e("span",{className:"flex items-center gap-1.5 flex-shrink-0",children:[f.clears&&f.clears.length>0&&e("span",{className:"font-mono text-ink/50",children:f.clears.join(", ")}),f.usable===!1&&e("span",{className:"font-mono uppercase px-1.5 py-0.5 rounded bg-ink/10 text-ink/60",children:"blocked"})]})]},f.id))}),u&&e("div",{className:"text-[10px] text-ink/60 leading-snug",children:u}),e("button",{type:"button",onClick:()=>r(l),disabled:o||g===0,title:g===0?u??"Nothing to spend on this account right now.":`Spend a saved reset on ${l}`,className:"w-full rounded-md border border-ink/15 px-2 py-1 text-[11px] font-medium text-ink/80 hover:bg-ink/5 transition-colors cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed",children:o?"Spending…":"Spend saved reset"})]})}function su(){let{accounts:t,error:r,isLoading:o,reload:l,spend:p}=K(),[c,m]=n(null),[g,u]=n(null),f=(v)=>{m(v),u(null),p(v).then((M)=>{u(M),m(null)})},h=!o&&!r&&t.length===0;return e("div",{className:"space-y-2",children:[e("div",{className:"flex items-center justify-between gap-2",children:[e("div",{className:"min-w-0",children:[e("div",{className:"text-[11px] font-semibold text-ink",children:"Saved rate-limit resets"}),e("div",{className:"text-[10px] text-ink/50 leading-snug",children:"Provider-issued resets for Codex and Claude accounts. Spending one clears the window it covers."})]}),e("button",{type:"button",onClick:l,disabled:o,title:"Re-read saved resets",className:"p-1.5 bg-paper border border-ink/15 rounded-md hover:bg-ink/5 text-ink/80 transition-colors disabled:opacity-50 flex-shrink-0",children:e(C,{size:12,className:o?"animate-spin text-ink":""})})]}),r&&e("div",{className:"flex items-start gap-1.5 text-[10px] text-error leading-snug",children:[e(I,{size:12,className:"flex-shrink-0 mt-px"}),e("span",{children:r})]}),t.map((v)=>e(ae,{account:v,onSpend:f,spending:c===`${v.provider}/${v.credentialId}`},`${v.provider}/${v.credentialId}`)),h&&e("p",{className:"text-[10px] text-ink/50 leading-snug",children:"No saved resets on any account."}),g&&e("div",{className:`text-[10px] leading-snug ${g.ok?"text-ink/70":"text-error"}`,children:g.message})]})}function lu(){let[t,r]=n(null),[o,l]=n(!0),[p,c]=n(null),m=a(async(g)=>{if(!g?.silent)l(!0);c(null);try{let u=g?.force?"/api/settings/usage?refresh=1":"/api/settings/usage",f=await fetch(u);if(!f.ok)throw Error(`Usage request failed (${f.status})`);let h=await f.json();r(h)}catch(u){c(u instanceof Error?u.message:"Failed to load provider usage")}finally{if(!g?.silent)l(!1)}},[]);return i(()=>{m()},[m]),{report:t,isLoading:o,error:p,reload:m}}
2
2
  export{ea,ou,vs,ks,su,lu};
@@ -1,2 +1,2 @@
1
- import{t,Ot}from"./index-5y0bvq4q.js";var N=5,R=0.00001,X=2,Y=0.6,w=0.000001;function P(n){let o=[];for(let r=0;r<n.length-1;r++)o.push({a:n[r],b:n[r+1]});return o}t(P,"buildSegmentList");function T(n,o,r,a){let c=o.x-n.x,s=o.y-n.y,u=a.x-r.x,f=a.y-r.y,d=c*f-s*u;if(d===0)return null;let e=r.x-n.x,i=r.y-n.y,h=(e*f-i*u)/d,p=(e*s-i*c)/d;if(h<=w||h>=1-w||p<=w||p>=1-w)return null;return{point:{x:n.x+h*c,y:n.y+h*s},tA:h,tB:p}}t(T,"segmentIntersection");function v(n){return Math.abs(n.b.x-n.a.x)>=Math.abs(n.b.y-n.a.y)}t(v,"isHorizontalSeg");function B(n,o,r){if(n.curve!=="rounded")return!1;let a=n.points,c=a[o],s=a[o+1];if(!c||!s)return!1;let u=Math.hypot(s.x-c.x,s.y-c.y),f=r*u,d=o>0?L(a[o-1],c,s,N):null;if(d&&f<d.cutLen)return!0;let e=o+2<a.length?L(c,s,a[o+2],N):null;return e!==null&&u-f<e.cutLen}t(B,"crossingSitsInRoundedCorner");function C(n){let o=[];for(let r=0;r<n.length;r++){let a=n[r],c=P(a.points);for(let s=r+1;s<n.length;s++){let u=n[s],f=P(u.points);for(let[d,e]of c.entries())for(let[i,h]of f.entries()){let p=T(e.a,e.b,h.a,h.b);if(!p)continue;if(B(a,d,p.tA)||B(u,i,p.tB))continue;let g=v(e),S=v(h);if(g!==S?g:!1)o.push({jumpEdgeId:a.id,otherEdgeId:u.id,segIndex:d,t:p.tA,point:p.point});else o.push({jumpEdgeId:u.id,otherEdgeId:a.id,segIndex:i,t:p.tB,point:p.point})}}}return o}t(C,"findEdgeIntersections");function M(n){let o=Math.round(n*1000)/1000;return Number.isInteger(o)?`${o}`:`${o}`}t(M,"fmt");function A(n){return`${M(n.x)},${M(n.y)}`}t(A,"pointToString");function D(n){let o=n.b.x-n.a.x,r=n.b.y-n.a.y;if(Math.abs(o)>=Math.abs(r))return o>=0?1:0;return r>=0?1:0}t(D,"getArcSweepFlag");function _(n,o){if(n.length<2)return n.map((s)=>({...s}));let r=n.map((s)=>({...s})),a=o.arrowTypeStart&&Ot[o.arrowTypeStart];if(a){let s=n[0],u=n[1],f=Math.atan2(u.y-s.y,u.x-s.x);r[0].x=s.x+a*Math.cos(f),r[0].y=s.y+a*Math.sin(f)}let c=o.arrowTypeEnd&&Ot[o.arrowTypeEnd];if(c){let s=n.length,u=n[s-2],f=n[s-1],d=Math.atan2(f.y-u.y,f.x-u.x);r[s-1].x=f.x-c*Math.cos(d),r[s-1].y=f.y-c*Math.sin(d)}return r}t(_,"applyMarkerOffsets");function k(n,o,r,a,c){let s=n.point.x,u=n.point.y,f={x:s-o*n.r,y:u-r*n.r},d={x:s+o*n.r,y:u+r*n.r},e=[`L${A(f)}`];if(c==="arc")e.push(`A${M(n.r)},${M(n.r)} 0 0 ${a} ${A(d)}`);else e.push(`M${A(d)}`);return e}t(k,"emitJump");function L(n,o,r,a){let c=o.x-n.x,s=o.y-n.y,u=r.x-o.x,f=r.y-o.y,d=Math.hypot(c,s),e=Math.hypot(u,f);if(d<R||e<R)return null;let i=c/d,h=s/d,p=u/e,g=f/e,S=i*p+h*g,b=Math.max(-1,Math.min(1,S)),x=Math.acos(b);if(x<R||Math.abs(Math.PI-x)<R)return null;let y=Math.min(a/Math.sin(x/2),d/2,e/2);return{startX:o.x-i*y,startY:o.y-h*y,endX:o.x+p*y,endY:o.y+g*y,ctrlX:o.x,ctrlY:o.y,cutLen:y}}t(L,"computeRoundedCorner");function H(n,o,r){let a=n.points;if(a.length<2)return"";let c=_(a,n),s=n.curve==="rounded",u=P(c),f=new Map;for(let e of o){let i=u[e.segIndex];if(!i)continue;let h=Math.hypot(i.b.x-i.a.x,i.b.y-i.a.y),p=f.get(e.segIndex)??[];p.push({t:e.t,point:e.point,d:e.t*h,r:r.jumpRadius}),f.set(e.segIndex,p)}let d=[`M${A(c[0])}`];for(let e=0;e<u.length;e++){let i=u[e],h=Math.hypot(i.b.x-i.a.x,i.b.y-i.a.y),p=h===0?0:(i.b.x-i.a.x)/h,g=h===0?0:(i.b.y-i.a.y)/h,S=D(i),b=0;if(s&&e>0){let l=L(c[e-1],c[e],c[e+1]??c[e],N);if(l)b=l.cutLen}let x=h,y=null;if(s&&e<u.length-1){if(y=L(c[e],c[e+1],c[e+2]??c[e+1],N),y)x=h-y.cutLen}let I=r.jumpRadius*Y,m=[...f.get(e)??[]].sort((l,E)=>l.t-E.t).filter((l)=>{let E=Math.min(l.d-b,x-l.d)-X;return l.r=Math.min(l.r,E),l.r>=I});for(let l=0;l<m.length-1;l++){let E=m[l+1].d-m[l].d;if(m[l].r+m[l+1].r>E){let O=E/2;m[l].r=Math.min(m[l].r,O),m[l+1].r=Math.min(m[l+1].r,O)}}for(let l of m){if(l.r<I)continue;d.push(...k(l,p,g,S,r.jumpStyle))}if(s&&y)d.push(`L${M(y.startX)},${M(y.startY)}`),d.push(`Q${M(y.ctrlX)},${M(y.ctrlY)} ${M(y.endX)},${M(y.endY)}`);else d.push(`L${A(i.b)}`)}return d.join(" ")}t(H,"rewriteEdgePath");function J(n){return/^[\d\s+,.LMelm-]*$/.test(n)}t(J,"isStraightPath");function U(n){if(!n)return!0;return n==="linear"||n==="rounded"||n==="step"||n==="stepBefore"||n==="stepAfter"}t(U,"curveSupportsLineHops");function j(n){if(!n)return null;try{let o=typeof atob==="function"?atob(n):Buffer.from(n,"base64").toString(),r=JSON.parse(o);if(!Array.isArray(r))return null;let a=[];for(let c of r)if(c&&typeof c.x==="number"&&typeof c.y==="number")a.push({x:c.x,y:c.y});return a.length>=2?a:null}catch{return null}}t(j,"decodeDataPoints");function gl(n,o,r){if(!r.enabled)return;let a=n.node();if(!a)return;let c=new Map;for(let e of o)c.set(e.id,e);let s=new Map;for(let e of a.querySelectorAll("path[data-id]")){let i=e.getAttribute("data-id");if(i!==null&&!s.has(i))s.set(i,e)}let u=[];for(let e of o){let i=s.get(e.id);if(!i)continue;let p=j(i.getAttribute("data-points"))??e.points;u.push({...e,points:p})}let f=C(u);if(f.length===0)return;let d=new Map;for(let e of f){let i=d.get(e.jumpEdgeId)??[];i.push(e),d.set(e.jumpEdgeId,i)}for(let e of u){let i=d.get(e.id);if(!i||i.length===0)continue;let p=c.get(e.id)?.curve;if(p!==void 0&&!U(p))continue;let g=s.get(e.id);if(!g)continue;if(p===void 0){let m=g.getAttribute("d")??"";if(!J(m))continue}let S=g.getAttribute("style")??"",b=/stroke-dasharray\s*:\s*0\s+([\d.]+)\s+[\d.]+\s+([\d.]+)/.exec(S),x=b?Number.parseFloat(b[1]):null,y=b?Number.parseFloat(b[2]):null,I=H(e,i,r);if(g.setAttribute("d",I),x!==null&&y!==null&&typeof g.getTotalLength==="function"){let m=g.getTotalLength(),l=Math.max(0,m-x-y),E=`0 ${x} ${l} ${y}`,O=S.replace(/stroke-dasharray\s*:[^;]*;?/g,`stroke-dasharray: ${E};`).replace(/;\s*;+/g,";");g.setAttribute("style",O)}}}t(gl,"applyLineJumpsToSvg");
1
+ import{t,Ot}from"./index-zj45wj1x.js";var N=5,R=0.00001,X=2,Y=0.6,w=0.000001;function P(n){let o=[];for(let r=0;r<n.length-1;r++)o.push({a:n[r],b:n[r+1]});return o}t(P,"buildSegmentList");function T(n,o,r,a){let c=o.x-n.x,s=o.y-n.y,u=a.x-r.x,f=a.y-r.y,d=c*f-s*u;if(d===0)return null;let e=r.x-n.x,i=r.y-n.y,h=(e*f-i*u)/d,p=(e*s-i*c)/d;if(h<=w||h>=1-w||p<=w||p>=1-w)return null;return{point:{x:n.x+h*c,y:n.y+h*s},tA:h,tB:p}}t(T,"segmentIntersection");function v(n){return Math.abs(n.b.x-n.a.x)>=Math.abs(n.b.y-n.a.y)}t(v,"isHorizontalSeg");function B(n,o,r){if(n.curve!=="rounded")return!1;let a=n.points,c=a[o],s=a[o+1];if(!c||!s)return!1;let u=Math.hypot(s.x-c.x,s.y-c.y),f=r*u,d=o>0?L(a[o-1],c,s,N):null;if(d&&f<d.cutLen)return!0;let e=o+2<a.length?L(c,s,a[o+2],N):null;return e!==null&&u-f<e.cutLen}t(B,"crossingSitsInRoundedCorner");function C(n){let o=[];for(let r=0;r<n.length;r++){let a=n[r],c=P(a.points);for(let s=r+1;s<n.length;s++){let u=n[s],f=P(u.points);for(let[d,e]of c.entries())for(let[i,h]of f.entries()){let p=T(e.a,e.b,h.a,h.b);if(!p)continue;if(B(a,d,p.tA)||B(u,i,p.tB))continue;let g=v(e),S=v(h);if(g!==S?g:!1)o.push({jumpEdgeId:a.id,otherEdgeId:u.id,segIndex:d,t:p.tA,point:p.point});else o.push({jumpEdgeId:u.id,otherEdgeId:a.id,segIndex:i,t:p.tB,point:p.point})}}}return o}t(C,"findEdgeIntersections");function M(n){let o=Math.round(n*1000)/1000;return Number.isInteger(o)?`${o}`:`${o}`}t(M,"fmt");function A(n){return`${M(n.x)},${M(n.y)}`}t(A,"pointToString");function D(n){let o=n.b.x-n.a.x,r=n.b.y-n.a.y;if(Math.abs(o)>=Math.abs(r))return o>=0?1:0;return r>=0?1:0}t(D,"getArcSweepFlag");function _(n,o){if(n.length<2)return n.map((s)=>({...s}));let r=n.map((s)=>({...s})),a=o.arrowTypeStart&&Ot[o.arrowTypeStart];if(a){let s=n[0],u=n[1],f=Math.atan2(u.y-s.y,u.x-s.x);r[0].x=s.x+a*Math.cos(f),r[0].y=s.y+a*Math.sin(f)}let c=o.arrowTypeEnd&&Ot[o.arrowTypeEnd];if(c){let s=n.length,u=n[s-2],f=n[s-1],d=Math.atan2(f.y-u.y,f.x-u.x);r[s-1].x=f.x-c*Math.cos(d),r[s-1].y=f.y-c*Math.sin(d)}return r}t(_,"applyMarkerOffsets");function k(n,o,r,a,c){let s=n.point.x,u=n.point.y,f={x:s-o*n.r,y:u-r*n.r},d={x:s+o*n.r,y:u+r*n.r},e=[`L${A(f)}`];if(c==="arc")e.push(`A${M(n.r)},${M(n.r)} 0 0 ${a} ${A(d)}`);else e.push(`M${A(d)}`);return e}t(k,"emitJump");function L(n,o,r,a){let c=o.x-n.x,s=o.y-n.y,u=r.x-o.x,f=r.y-o.y,d=Math.hypot(c,s),e=Math.hypot(u,f);if(d<R||e<R)return null;let i=c/d,h=s/d,p=u/e,g=f/e,S=i*p+h*g,b=Math.max(-1,Math.min(1,S)),x=Math.acos(b);if(x<R||Math.abs(Math.PI-x)<R)return null;let y=Math.min(a/Math.sin(x/2),d/2,e/2);return{startX:o.x-i*y,startY:o.y-h*y,endX:o.x+p*y,endY:o.y+g*y,ctrlX:o.x,ctrlY:o.y,cutLen:y}}t(L,"computeRoundedCorner");function H(n,o,r){let a=n.points;if(a.length<2)return"";let c=_(a,n),s=n.curve==="rounded",u=P(c),f=new Map;for(let e of o){let i=u[e.segIndex];if(!i)continue;let h=Math.hypot(i.b.x-i.a.x,i.b.y-i.a.y),p=f.get(e.segIndex)??[];p.push({t:e.t,point:e.point,d:e.t*h,r:r.jumpRadius}),f.set(e.segIndex,p)}let d=[`M${A(c[0])}`];for(let e=0;e<u.length;e++){let i=u[e],h=Math.hypot(i.b.x-i.a.x,i.b.y-i.a.y),p=h===0?0:(i.b.x-i.a.x)/h,g=h===0?0:(i.b.y-i.a.y)/h,S=D(i),b=0;if(s&&e>0){let l=L(c[e-1],c[e],c[e+1]??c[e],N);if(l)b=l.cutLen}let x=h,y=null;if(s&&e<u.length-1){if(y=L(c[e],c[e+1],c[e+2]??c[e+1],N),y)x=h-y.cutLen}let I=r.jumpRadius*Y,m=[...f.get(e)??[]].sort((l,E)=>l.t-E.t).filter((l)=>{let E=Math.min(l.d-b,x-l.d)-X;return l.r=Math.min(l.r,E),l.r>=I});for(let l=0;l<m.length-1;l++){let E=m[l+1].d-m[l].d;if(m[l].r+m[l+1].r>E){let O=E/2;m[l].r=Math.min(m[l].r,O),m[l+1].r=Math.min(m[l+1].r,O)}}for(let l of m){if(l.r<I)continue;d.push(...k(l,p,g,S,r.jumpStyle))}if(s&&y)d.push(`L${M(y.startX)},${M(y.startY)}`),d.push(`Q${M(y.ctrlX)},${M(y.ctrlY)} ${M(y.endX)},${M(y.endY)}`);else d.push(`L${A(i.b)}`)}return d.join(" ")}t(H,"rewriteEdgePath");function J(n){return/^[\d\s+,.LMelm-]*$/.test(n)}t(J,"isStraightPath");function U(n){if(!n)return!0;return n==="linear"||n==="rounded"||n==="step"||n==="stepBefore"||n==="stepAfter"}t(U,"curveSupportsLineHops");function j(n){if(!n)return null;try{let o=typeof atob==="function"?atob(n):Buffer.from(n,"base64").toString(),r=JSON.parse(o);if(!Array.isArray(r))return null;let a=[];for(let c of r)if(c&&typeof c.x==="number"&&typeof c.y==="number")a.push({x:c.x,y:c.y});return a.length>=2?a:null}catch{return null}}t(j,"decodeDataPoints");function gl(n,o,r){if(!r.enabled)return;let a=n.node();if(!a)return;let c=new Map;for(let e of o)c.set(e.id,e);let s=new Map;for(let e of a.querySelectorAll("path[data-id]")){let i=e.getAttribute("data-id");if(i!==null&&!s.has(i))s.set(i,e)}let u=[];for(let e of o){let i=s.get(e.id);if(!i)continue;let p=j(i.getAttribute("data-points"))??e.points;u.push({...e,points:p})}let f=C(u);if(f.length===0)return;let d=new Map;for(let e of f){let i=d.get(e.jumpEdgeId)??[];i.push(e),d.set(e.jumpEdgeId,i)}for(let e of u){let i=d.get(e.id);if(!i||i.length===0)continue;let p=c.get(e.id)?.curve;if(p!==void 0&&!U(p))continue;let g=s.get(e.id);if(!g)continue;if(p===void 0){let m=g.getAttribute("d")??"";if(!J(m))continue}let S=g.getAttribute("style")??"",b=/stroke-dasharray\s*:\s*0\s+([\d.]+)\s+[\d.]+\s+([\d.]+)/.exec(S),x=b?Number.parseFloat(b[1]):null,y=b?Number.parseFloat(b[2]):null,I=H(e,i,r);if(g.setAttribute("d",I),x!==null&&y!==null&&typeof g.getTotalLength==="function"){let m=g.getTotalLength(),l=Math.max(0,m-x-y),E=`0 ${x} ${l} ${y}`,O=S.replace(/stroke-dasharray\s*:[^;]*;?/g,`stroke-dasharray: ${E};`).replace(/;\s*;+/g,";");g.setAttribute("style",O)}}}t(gl,"applyLineJumpsToSvg");
2
2
  export{gl};
@@ -1 +1 @@
1
- import{n,i,o,ci,a,Ds,e,w,Ze,ze,S,ir,or,s,m,$r,f,va,_e,nn,OA,cn,xr,Rp,Wl}from"./index-st202rjv.js";import{Ts,fr,_u}from"./index-tfsaj5d1.js";function re(){if(typeof crypto<"u"&&typeof crypto.randomUUID==="function")return crypto.randomUUID();return`t-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function oe(t){return JSON.stringify(t)}function ce(t){let r=Qe(t);if(!w(r))return null;if(r.t==="ready"){if(typeof r.id!=="string"||typeof r.cwd!=="string")return null;let l=typeof r.replayBytes==="number"?r.replayBytes:0;return{...r,t:"ready",replayBytes:l}}if(r.t==="exit")return{t:"exit",exitCode:typeof r.exitCode==="number"?r.exitCode:null,signal:typeof r.signal==="string"?r.signal:null};if(r.t==="error"&&typeof r.message==="string")return{t:"error",code:Ve(r.code),message:r.message};return null}function ue(t){return`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/api/terminal/${encodeURIComponent(t)}/ws`}function Ve(t){return t==="capacity"||t==="cwd"||t==="shell"||t==="spawn"?t:"unknown"}function Qe(t){try{return JSON.parse(t)}catch{return null}}function me(t){if(t.buffer instanceof ArrayBuffer)return t;return new Uint8Array(t)}var Je=500,je=8000,et=4;function de(t,r){let l=null,c=null,d=0,u=!1,p=!1,h=!1,T=null,k=[],A=0,F=null,U=()=>{let b=new WebSocket(ue(t));b.binaryType="arraybuffer",l=b,b.onopen=()=>{if(p)return;if(d=0,u=!0,r.onConnectionChange(!0),T)b.send(oe(T))},b.onmessage=(y)=>{if(p)return;if(y.data instanceof ArrayBuffer){v(new Uint8Array(y.data));return}if(typeof y.data!=="string")return;let P=ce(y.data);if(P)B(P)},b.onclose=()=>{if(l=null,p)return;if(r.onConnectionChange(!1),h=!1,k=[],A=0,F=null,!u)return;if(d+=1,d>et)return;let y=Math.min(Je*2**(d-1),je);c=setTimeout(()=>{if(c=null,!p)U()},y)},b.onerror=()=>{}},B=(b)=>{if(b.t==="ready"){if(h=!0,F=b,A=b.replayBytes,k=[],r.onReady(b),A===0)M();return}if(b.t==="exit"){r.onExit(b.exitCode,b.signal);return}r.onError(b.code,b.message)},v=(b)=>{if(A<=0){r.onOutput(b);return}if(k.push(b),A-=b.length,A>0)return;M()},M=()=>{let b=F,y=k;if(F=null,k=[],A=0,!b)return;r.onReplay(y.length===1?y[0]:tt(y),b)};U();let O=(b)=>{let y=l;if(!y||y.readyState!==WebSocket.OPEN)return;y.send(oe(b))};return{attach(b,y,P,E,D){if(h)return;let R={t:"attach",cols:b,rows:y};if(P)R.root=P;if(E)R.repo=E;if(D)R.theme=D;T=R,O(R)},resize(b,y){O({t:"resize",cols:b,rows:y})},input(b){let y=l;if(!y||y.readyState!==WebSocket.OPEN)return;y.send(me(b))},close(){O({t:"close"})},release(){if(p=!0,c!==null)clearTimeout(c),c=null;let b=l;if(l=null,!b)return;b.onopen=null,b.onmessage=null,b.onclose=null,b.onerror=null,b.close()}}}function tt(t){let r=0;for(let d of t)r+=d.length;let l=new Uint8Array(r),c=0;for(let d of t)l.set(d,c),c+=d.length;return l}function pe(t){return{connect:t.visible||t.opened,persist:t.ready&&t.visible&&!t.opened}}function fe(t={}){let{sessionId:r,ready:l}=Ze(),[c,d]=S("terminal.id",""),[u,p]=S("terminal.opened",!1),h=pe({visible:t.visible===!0,ready:l,opened:u}),[T,k]=n("connecting"),[A,F]=n(""),[U,B]=n(null),[v,M]=n(null),[O,b]=n(0),y=o(null),P=o(null),E=o(t.onOutput);E.current=t.onOutput;let D=o(t.onReplay);D.current=t.onReplay;let R=o(t.onRestart);R.current=t.onRestart;let g=o(t.root);g.current=t.root;let x=o(t.repo);x.current=t.repo;let L=o(t.theme);L.current=t.theme;let N=o(d);N.current=d;let z=o(null);i(()=>{if(!h.persist)return;p(!0)},[h.persist]),i(()=>{if(!h.connect||!l)return;if(ze(r,"terminal.id"))return;N.current(re())},[h.connect,l,r]),i(()=>{if(!h.connect||!l||!c)return;k("connecting"),M(null),B(null);let I=de(c,{onReady(K){k("running"),F(K.shell),B(null)},onReplay(K,G){D.current?.(K,G)},onOutput(K){E.current?.(K)},onExit(K){k("exited"),B(K)},onError(K,G){k("error"),M(`${K}: ${G}`)},onConnectionChange(K){if(!K)k("connecting")}});y.current=I;let q=P.current;if(q)I.attach(q.cols,q.rows,g.current,x.current,L.current);return()=>{I.release(),y.current=null}},[h.connect,l,c,O]);let H=a(()=>{y.current?.close(),R.current?.(),N.current(re())},[]);i(()=>{if(!l)return;let I=t.root;if(!I)return;let q=`${I}\x00${t.repo??"."}`;if(z.current===null){z.current=q;return}if(z.current===q)return;z.current=q,H()},[l,t.root,t.repo,H]);let Q=a((I,q)=>{P.current={cols:I,rows:q},y.current?.attach(I,q,g.current,x.current,L.current)},[]),Z=a((I,q)=>{P.current={cols:I,rows:q},y.current?.resize(I,q)},[]),ee=a((I)=>{y.current?.input(I)},[]),te=a(()=>{b((I)=>I+1)},[]);return{status:T,shell:A,exitCode:U,error:v,attach:Q,resize:Z,input:ee,restart:H,reattach:te}}var nt={name:"clipboard-copy",size:24,node:[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1",key:"tgr4d6"}],["path",{d:"M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2",key:"4jdomd"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v4",key:"3hqy98"}],["path",{d:"M21 14H11",key:"1bme5i"}],["path",{d:"m15 10-4 4 4 4",key:"5dvupr"}]]},be=s(nt);var rt={name:"zap",size:24,node:[["path",{d:"M15.914 4a1.5 1.5 0 00-2.474-1.561l-9 9A1.5 1.5 0 005.5 14h4.002a.5.5 0 01.471.666L8.086 20a1.5 1.5 0 002.475 1.56l9-9A1.5 1.5 0 0018.5 10h-3.997a.5.5 0 01-.472-.667z",key:"1v7up4"}]]},he=s(rt);var ot={connecting:"CONNECTING",running:"LIVE",exited:"EXITED",error:"ERROR"},it={connecting:"bg-warning/10 text-warning border-warning/20",running:"bg-success/10 text-success border-success/20",exited:"bg-ink/5 text-ink/60 border-ink/15",error:"bg-error/10 text-error border-error/20"};function ye({status:t,exitCode:r,rootPath:l,activeRepo:c,onSelectRepo:d,repos:u,reposScanning:p,onRefreshRepos:h,shell:T,onRestart:k}){let A=T?T.split("/").pop():"";return e("div",{className:"h-10 px-3 border-b border-ink/10 bg-paper flex items-center justify-between flex-shrink-0 select-none",children:[e("div",{className:"flex items-center space-x-2 min-w-0",children:[e("div",{className:"flex items-center space-x-1.5",children:[e(_e,{size:14,className:"text-ink/80 flex-shrink-0"}),e("span",{className:"text-xs font-semibold tracking-wider text-ink uppercase",children:"Terminal"})]}),e("span",{className:`inline-flex items-center space-x-1 px-1.5 py-0.5 rounded text-[10px] font-mono border ${it[t]}`,title:t==="exited"&&r!==null?`Shell exited with code ${r}`:void 0,children:[t==="connecting"&&e(m,{size:10,className:"animate-spin"}),e("span",{children:t==="exited"&&r!==null?`EXIT ${r}`:ot[t]})]}),e(fr,{rootPath:l,activeRepo:c,onSelectRepo:d,repos:u,scanning:p,onRefreshRepos:h}),e("button",{type:"button",onClick:k,title:"Kill this shell and start a new one",className:"p-1 rounded text-ink/50 hover:text-ink hover:bg-ink/5 transition-colors cursor-pointer flex-shrink-0",children:e(va,{size:12})})]}),A&&e("span",{className:"hidden sm:block text-[10px] font-mono text-ink/40 flex-shrink-0",children:A})]})}var at=[{label:"bun build",cmd:"bun run build"},{label:"bun test",cmd:"bun test"},{label:"git status",cmd:"git status -s"},{label:"git diff",cmd:"git diff"},{label:"ls -la",cmd:"ls -la"},{label:"pwd",cmd:"pwd"},{label:"bun -v",cmd:"bun --version"}];function ge({onSelectCommand:t,disabled:r}){return e("div",{className:"flex flex-wrap items-center gap-1.5 px-3 py-1.5 bg-paper border-b border-ink/10 flex-shrink-0",children:[e("div",{className:"flex items-center space-x-1 text-[10px] font-mono text-ink/50 uppercase tracking-wider flex-shrink-0 select-none",children:[e(he,{size:11,className:"text-warning"}),e("span",{children:"Quick:"})]}),at.map((l)=>e("button",{type:"button",disabled:r,onClick:()=>t(l.cmd),className:"px-2 py-0.5 rounded text-[10px] font-mono bg-canvas hover:bg-ink/5 active:bg-ink/10 text-ink/80 hover:text-ink border border-ink/15 transition-all whitespace-nowrap disabled:opacity-40 cursor-pointer shadow-2xs",children:l.label},l.cmd))]})}var X=Object.freeze({ctrl:!1,alt:!1}),ie=[{id:"escape",label:"Esc",name:"Escape",sequence:"\x1B"},{id:"tab",label:"Tab",name:"Tab",sequence:"\t"},{id:"interrupt",label:"^C",name:"Ctrl+C — interrupt",sequence:"\x03"},{id:"left",label:"←",name:"Left arrow",csi:{prefix:"1",final:"D",application:"OD"}},{id:"up",label:"↑",name:"Up arrow",csi:{prefix:"1",final:"A",application:"OA"}},{id:"down",label:"↓",name:"Down arrow",csi:{prefix:"1",final:"B",application:"OB"}},{id:"right",label:"→",name:"Right arrow",csi:{prefix:"1",final:"C",application:"OC"}},{id:"home",label:"Home",name:"Home",csi:{prefix:"1",final:"H",application:"OH",terminfo:"\x1BOH"}},{id:"end",label:"End",name:"End",csi:{prefix:"1",final:"F",application:"OF",terminfo:"\x1BOF"}},{id:"pageUp",label:"PgUp",name:"Page up",csi:{prefix:"5",final:"~"}},{id:"pageDown",label:"PgDn",name:"Page down",csi:{prefix:"6",final:"~"}},{id:"delete",label:"Del",name:"Delete",csi:{prefix:"3",final:"~"}},{id:"shiftTab",label:"⇧Tab",name:"Shift+Tab",sequence:"\x1B[Z"},{id:"eof",label:"^D",name:"Ctrl+D — end of input",sequence:"\x04"},{id:"clear",label:"^L",name:"Ctrl+L — clear screen",sequence:"\f"}],ae=[{id:"pipe",label:"|",name:"Pipe",sequence:"|"},{id:"tilde",label:"~",name:"Tilde",sequence:"~"},{id:"dollar",label:"$",name:"Dollar",sequence:"$"},{id:"asterisk",label:"*",name:"Asterisk",sequence:"*"},{id:"question",label:"?",name:"Question mark",sequence:"?"},{id:"underscore",label:"_",name:"Underscore",sequence:"_"},{id:"backslash",label:"\\",name:"Backslash",sequence:"\\"},{id:"slash",label:"/",name:"Slash",sequence:"/"},{id:"minus",label:"-",name:"Minus",sequence:"-"},{id:"equals",label:"=",name:"Equals",sequence:"="},{id:"plus",label:"+",name:"Plus",sequence:"+"},{id:"ampersand",label:"&",name:"Ampersand",sequence:"&"},{id:"semicolon",label:";",name:"Semicolon",sequence:";"},{id:"colon",label:":",name:"Colon",sequence:":"},{id:"comma",label:",",name:"Comma",sequence:","},{id:"dot",label:".",name:"Period",sequence:"."},{id:"at",label:"@",name:"At sign",sequence:"@"},{id:"percent",label:"%",name:"Percent",sequence:"%"},{id:"caret",label:"^",name:"Caret",sequence:"^"},{id:"hash",label:"#",name:"Hash",sequence:"#"},{id:"bang",label:"!",name:"Exclamation mark",sequence:"!"},{id:"parenOpen",label:"(",name:"Open parenthesis",sequence:"("},{id:"parenClose",label:")",name:"Close parenthesis",sequence:")"},{id:"bracketOpen",label:"[",name:"Open bracket",sequence:"["},{id:"bracketClose",label:"]",name:"Close bracket",sequence:"]"},{id:"braceOpen",label:"{",name:"Open brace",sequence:"{"},{id:"braceClose",label:"}",name:"Close brace",sequence:"}"},{id:"lessThan",label:"<",name:"Less than",sequence:"<"},{id:"greaterThan",label:">",name:"Greater than",sequence:">"},{id:"quote",label:"'",name:"Single quote",sequence:"'"},{id:"doubleQuote",label:'"',name:"Double quote",sequence:'"'},{id:"backtick",label:"`",name:"Backtick",sequence:"`"}],Te={};for(let t of[...ie,...ae])Te[t.id]=t;function xe(t,r={}){let l=Te[t];if(!l)return"";let c=r.modifiers??X;if(l.csi)return st(l.csi,c,r.applicationCursorKeys??!1);let d=l.sequence??"";return c.alt?`\x1B${d}`:d}function st(t,r,l){let c=lt(r);if(c!==null)return`\x1B[${t.prefix};${c}${t.final}`;if(t.terminfo)return t.terminfo;if(l&&t.application)return`\x1B${t.application}`;return`\x1B[${t.prefix==="1"?"":t.prefix}${t.final}`}function lt(t){let r=(t.alt?2:0)|(t.ctrl?4:0);return r===0?null:r+1}function we(t,r){if(t.length!==1)return t;let l=t;if(r.ctrl)l=ut(l)??l;if(r.alt)l=`\x1B${l}`;return l}var ct={"@":"\x00"," ":"\x00","":"\b","[":"\x1B","\\":"\x1C","]":"\x1D","^":"\x1E",_:"\x1F","?":""};function ut(t){if(t.length!==1)return null;let r=t.charCodeAt(0);if(r>=97&&r<=122)return String.fromCharCode(r-96);if(r>=65&&r<=90)return String.fromCharCode(r-64);return ct[t]??null}var mt=[{modifier:"ctrl",label:"Ctrl",name:"Ctrl — applies to the next key"},{modifier:"alt",label:"Alt",name:"Alt / meta — applies to the next key"}],W="flex items-center justify-center h-8 min-w-8 px-1.5 rounded border font-mono transition-colors cursor-pointer select-none disabled:opacity-40 disabled:cursor-default text-[11px] @[420px]:h-9 @[420px]:min-w-10 @[420px]:text-xs",V="bg-canvas text-ink/80 border-ink/15 hover:text-ink hover:bg-ink/5 active:bg-ink/10",ve="bg-ink text-canvas border-ink";function Re({modifiers:t,onToggleModifier:r,onKey:l,onCopy:c,onPaste:d,disabled:u}){let[p,h]=n(!1),[T,k]=n(null),A=t.ctrl||t.alt,F=(v)=>{k(v),setTimeout(()=>k((M)=>M===v?null:M),1500)},U=async()=>{F(await c()?"copied":"empty")},B=async()=>{if(!await d())F("pasteFailed")};return e("div",{className:"@container flex flex-col gap-1 px-2 py-1.5 border-t border-ink/10 bg-paper flex-shrink-0",onPointerDown:(v)=>v.preventDefault(),children:[e("div",{className:"flex flex-wrap items-center gap-1",children:[mt.map(({modifier:v,label:M,name:O})=>e("button",{type:"button",onClick:()=>r(v),"aria-pressed":t[v],title:O,"aria-label":O,className:`${W} ${t[v]?ve:V}`,children:M},v)),A&&e("span",{className:"text-[10px] font-mono text-ink/50 px-0.5 whitespace-nowrap","aria-hidden":!0,children:"next"}),e("span",{className:"w-px h-5 bg-ink/15 flex-shrink-0","aria-hidden":!0}),e("button",{type:"button",onClick:U,disabled:u,title:T==="empty"?"Nothing selected":"Copy selection","aria-label":"Copy selection",className:`${W} ${T==="empty"?"bg-warning/10 text-warning border-warning/30":V}`,children:[T==="copied"?e(f,{size:13}):e(be,{size:13}),e("span",{className:"pl-1",children:"Copy"})]}),e("button",{type:"button",onClick:B,disabled:u,title:T==="pasteFailed"?"Clipboard unavailable":"Paste into the shell","aria-label":"Paste into the shell",className:`${W} ${T==="pasteFailed"?"bg-error/10 text-error border-error/30":V}`,children:[e(Ts,{size:13}),e("span",{className:"pl-1",children:"Paste"})]}),e("button",{type:"button",onClick:()=>h((v)=>!v),"aria-pressed":p,title:p?"Show control keys":"Show symbols","aria-label":p?"Show control keys":"Show symbols",className:`${W} ml-auto ${p?ve:V}`,children:p?"ABC":"123"})]}),e("div",{className:"flex flex-wrap items-center gap-1",children:(p?ae:ie).map((v)=>e("button",{type:"button",disabled:u,onClick:()=>l(v.id),title:v.name,"aria-label":v.name,className:`${W} ${V}`,children:v.label},v.id))})]})}function Se(t){if(!t.startsWith("\x1B[M")||t.length<6)return{text:t};let r=new Uint8Array(t.length);for(let l=0;l<t.length;l+=1)r[l]=t.charCodeAt(l)&255;return{bytes:r}}function Ce(t){let r=cn(t),{canvas:l,ink:c,paper:d}=r,u=(h)=>xr(h,c,0.2),p=(h)=>xr(l,c,h);return{background:"transparent",foreground:c,cursor:r.meta,cursorAccent:d,selectionBackground:p(0.28),selectionForeground:c,black:p(0.2),red:r.error,green:r.success,yellow:r.warning,blue:r.info,magenta:r.meta,cyan:xr(r.info,r.success,0.5),white:p(0.75),brightBlack:p(0.5),brightRed:u(r.error),brightGreen:u(r.success),brightYellow:u(r.warning),brightBlue:u(r.info),brightMagenta:u(r.meta),brightCyan:u(xr(r.info,r.success,0.5)),brightWhite:p(0.92)}}var J="Fira Code",dt="'FiraCode Nerd Font Mono', 'FiraCode Nerd Font', 'JetBrainsMono Nerd Font', 'JetBrainsMono NF', 'JetBrains Mono Nerd Font', 'Hack Nerd Font', 'MesloLGS NF', 'MesloLGM Nerd Font', 'CaskaydiaCove Nerd Font', 'SauceCodePro Nerd Font', 'Symbols Nerd Font Mono', 'Symbols Nerd Font', 'PowerlineSymbols'",ke="Kabmo Nerd Symbols",Ae=[J,ke],j=`'${J}', ${dt}, '${ke}', Menlo, Monaco, 'Courier New', monospace`,Y=12,pt=16,ft=1e4;function bt(t,r){return Math.max(1,t)*Math.max(1,r)*pt}var Me=bt(ft,100);var ht=2000;async function Fe(){if(typeof document>"u"||!document.fonts?.load)return;let t=Promise.withResolvers(),r=setTimeout(t.resolve,ht);try{await Promise.race([document.fonts.load(`${Y}px "${J}"`).then(()=>{return},()=>{return}),t.promise])}finally{clearTimeout(r)}}function Le(t){if(typeof document>"u"||!document.fonts)return()=>{};let r=new Set(Ae),l=(c)=>{if([...c.fontfaces].some((u)=>r.has(u.family.replace(/['"]/g,"").trim())))t()};return document.fonts.addEventListener("loadingdone",l),()=>document.fonts.removeEventListener("loadingdone",l)}var Ee=2.5,yt=1;function gt(t,r){let l=t*0.8,c=t*0.2,d=Math.ceil(t*0.6),u=l,p=c,h=typeof document>"u"?null:document.createElement("canvas").getContext("2d");if(h){h.font=`${t}px ${r}`,d=Math.ceil(h.measureText("M").width)||d;let T=h.measureText("Mg");u=T.actualBoundingBoxAscent||l,p=T.actualBoundingBoxDescent||c}return{width:d,height:Math.ceil(u+p+Ee+yt),baseline:Math.round(u+Ee)}}function Ne(t){let r=t.renderer;if(!r)return;r.measureFont=()=>gt(t.options.fontSize??Y,t.options.fontFamily??j),r.remeasureFont()}function Tt(t,r,l){if(!l.width||!l.height)return null;return{cols:Math.max(2,Math.floor(t/l.width)),rows:Math.max(1,Math.floor(r/l.height))}}function Ie(t,r){let l=t;l.proposeDimensions=()=>{let c=r.element,d=r.renderer?.getMetrics();if(!c||!d)return;let u=getComputedStyle(c),p=(parseFloat(u.paddingLeft)||0)+(parseFloat(u.paddingRight)||0),h=(parseFloat(u.paddingTop)||0)+(parseFloat(u.paddingBottom)||0);return Tt(c.clientWidth-p,c.clientHeight-h,d)??void 0}}function xt(t){let{cols:r,rows:l,attached:c,committed:d}=t;if(r<10||l<5)return{kind:"ignore"};if(!c)return{kind:"attach",cols:r,rows:l};if(r===d.cols&&l===d.rows)return{kind:"ignore"};return{kind:"change",cols:r,rows:l}}function Oe(t){let r={cols:0,rows:0},l=!1,c,d=()=>{if(!t.fit())return;let u=t.current();if(!u)return;let p=xt({cols:u.cols,rows:u.rows,attached:l,committed:r});if(p.kind==="ignore")return;if(r={cols:p.cols,rows:p.rows},p.kind==="attach"){l=!0,t.onReady(p.cols,p.rows);return}t.onGridChange(p.cols,p.rows)};return{schedule(){clearTimeout(c),c=setTimeout(d,120)},restate(){r={cols:0,rows:0}},isAttached:()=>l,dispose(){clearTimeout(c),c=void 0}}}function Pe(t,r){if(r.type!=="keydown"||!r.shiftKey)return!1;if(r.key==="PageUp")return t.scrollPages(-1),!0;if(r.key==="PageDown")return t.scrollPages(1),!0;if(r.key==="Home")return t.scrollToTop(),!0;if(r.key==="End")return t.scrollToBottom(),!0;if(r.key==="ArrowUp")return t.scrollLines(-1),!0;if(r.key==="ArrowDown")return t.scrollLines(1),!0;return!1}function Ue(t,r){let l=0,c=(u)=>{if(u.touches.length===1)l=u.touches[0].clientY},d=(u)=>{if(u.touches.length!==1)return;let p=l-u.touches[0].clientY;if(Math.abs(p)<16)return;r()?.scrollLines(Math.trunc(p/16)),l=u.touches[0].clientY};return t.addEventListener("touchstart",c,{passive:!0}),t.addEventListener("touchmove",d,{passive:!0}),()=>{t.removeEventListener("touchstart",c),t.removeEventListener("touchmove",d)}}function wt(t){if(t.viewportY<=0&&!t.hasSelection&&!t.pointerHeld)return null;return t.scrollback-t.viewportY}function vt(t){let r=t.scrollback-t.top;return r>0?r:null}function Be(t){let r={pointerHeld:!1},l=()=>{r.pointerHeld=!0},c=()=>{r.pointerHeld=!1};return t.addEventListener("pointerdown",l,!0),globalThis.addEventListener("pointerup",c),globalThis.addEventListener("pointercancel",c),{get pointerHeld(){return r.pointerHeld},stop(){t.removeEventListener("pointerdown",l,!0),globalThis.removeEventListener("pointerup",c),globalThis.removeEventListener("pointercancel",c)}}}function De(t,r,l){let c=wt({scrollback:t.getScrollbackLength(),viewportY:t.getViewportY(),hasSelection:t.hasSelection(),pointerHeld:r.pointerHeld});if(l(),c===null)return;let d=vt({scrollback:t.getScrollbackLength(),top:c});if(d===null)return;let u=d-t.getViewportY();if(u===0)return;try{t.scrollLines(-u)}catch{}}async function qe(t,r,l,c){let d=await import("./ghostty-web-2gt2tp72.js"),[u]=await Promise.all([d.Ghostty.load(),Fe()]);if(c())return null;let p=r,h=null,T=!1,k,A=null,F=!1,U=(g)=>{let{term:x}=g;x.attachCustomKeyEventHandler((L)=>Pe(x,L)),g.disposables.push(x.onScroll((L)=>l.onScrolledUpChange(L>0)),x.onData((L)=>{let N=Se(L);if(N.bytes)l.onBinaryInput(N.bytes);else l.onInput(N.text)}),x.onResize(()=>{if(T)return;y.schedule()}))},B=(g)=>{let x=new d.Terminal({cursorBlink:!0,cursorStyle:"block",fontSize:Y,fontFamily:j,theme:Ce(g),scrollback:Me,smoothScrollDuration:0,ghostty:u});x.open(t),Ne(x),x.clear();let L=new d.FitAddon;x.loadAddon(L),Ie(L,x);let N={term:x,fitAddon:L,disposables:[]};return U(N),N},v=(g)=>{if(!g)return;for(let x of g.disposables)try{x.dispose()}catch{}try{g.fitAddon.dispose()}catch{}try{g.term.dispose()}catch{}},M=()=>{if(F)return!1;if(t.clientWidth<=0||t.clientHeight<=0)return!1;let g=h?.term.renderer?.getMetrics();if(!g?.width||!g.height)return!1;try{return h?.fitAddon.fit(),!0}catch{return!1}},O=()=>{if(F)return;T=!1,M(),y.restate(),y.schedule()},b=(g,x,L)=>{let N=h?.term;if(!N)return;if(T=!0,N.cols!==x||N.rows!==L)N.resize(x,L);if(g.length===0){requestAnimationFrame(O);return}N.write(g,O)},y=Oe({current:()=>h?.term,fit:M,onReady:l.onReady,onGridChange:l.onGridChange}),P=Be(t);h=B(p),M(),y.schedule();let E=new ResizeObserver(()=>{clearTimeout(k),k=setTimeout(()=>{M(),y.schedule()},35)});E.observe(t);let D=Le(()=>{let g=h?.term;if(!g)return;let x=g.options.fontSize??Y;g.options.fontSize=x+0.1,g.options.fontSize=x,M(),y.schedule()}),R=Ue(t,()=>h?.term??null);return A=requestAnimationFrame(()=>{M(),y.schedule()}),{write(g){let x=h?.term;if(!x)return;De(x,P,()=>x.write(g))},writeReplay:b,reset(){let g=h?.term;if(!g)return;g.reset(),g.clear(),M()},focus(){h?.term.focus()},applicationCursorKeys(){return h?.term.wasmTerm?.getMode(1,!1)??!1},getSelection(){return h?.term.getSelection()??""},paste(g){h?.term.paste(g)},scrollToBottom(){h?.term.scrollToBottom()},setTheme(g){if(F||g===p)return;p=g,v(h),h=B(g),M()},dispose(){if(F=!0,A!==null)cancelAnimationFrame(A);clearTimeout(k),y.dispose(),D(),R(),P.stop(),E.disconnect(),v(h),h=null}}}function Ke(){let t=null,r=!1;return{request(){if(t)t();else r=!0},attach(l){if(t=l,!r)return;r=!1,l()},detach(){t=null,r=!1}}}var se=Ds(({onInput:t,onBinaryInput:r,onGridChange:l,onReady:c,onReattach:d},u)=>{let{theme:p}=Rp(),h=o(null),T=o(null),[k,A]=n(!1),F=o(null);if(!F.current)F.current=Ke();let U=F.current,B=o(t);B.current=t;let v=o(r);v.current=r;let M=o(l);M.current=l;let O=o(c);O.current=c;let b=o(d);b.current=d;let y=o(p);y.current=p,i(()=>{let E=T.current;if(!E)return;E.setTheme(p),b.current?.()},[p]),ci(u,()=>({write(E){T.current?.write(E)},writeReplay(E,D,R){T.current?.writeReplay(E,D,R)},reset(){T.current?.reset()},focus(){U.request()},applicationCursorKeys(){return T.current?.applicationCursorKeys()??!1},getSelection(){return T.current?.getSelection()??""},paste(E){T.current?.paste(E)}}),[]);let P=a(()=>{T.current?.scrollToBottom(),A(!1)},[]);return i(()=>{let E=h.current;if(!E)return;let D=!1;return qe(E,y.current,{onInput:(R)=>B.current(R),onBinaryInput:(R)=>v.current(R),onGridChange:(R,g)=>M.current(R,g),onReady:(R,g)=>O.current(R,g),onScrolledUpChange:A},()=>D).then((R)=>{if(!R)return;if(D){R.dispose();return}T.current=R,E.querySelector("textarea")?.setAttribute("data-terminal-input",""),U.attach(()=>T.current?.focus())}),()=>{D=!0,U.detach(),T.current?.dispose(),T.current=null}},[]),e("div",{className:"relative flex-1 w-full h-full overflow-hidden p-2",children:[e("div",{ref:h,"data-terminal-root":"",className:"kabmo-terminal w-full h-full cursor-text",style:{height:"100%",width:"100%"}}),k&&e("button",{type:"button",onClick:P,className:"absolute bottom-3 right-4 z-20 flex items-center space-x-1.5 px-2.5 py-1 bg-paper hover:bg-canvas text-ink border border-ink/20 rounded-full shadow-lg text-[11px] font-mono transition-all animate-fade-in cursor-pointer active:scale-95",title:"Scroll to latest output (Shift+End)",children:[e($r,{size:12,className:"text-warning"}),e("span",{children:"Latest"})]})]})});se.displayName="RealtimeTerminalView";var le=new TextEncoder;function $n({className:t="",enabled:r=!0,rootPath:l,showHeader:c=!0,active:d=!0}){let u=o(null),{isDark:p}=Rp(),h=_u(),T=o(null),k=Wl(T),[A,F]=n(X),{activeRepo:U,setActiveRepo:B}=ir(l),{repos:v,scanning:M,rescan:O}=or(l,r),b=o(null),y=o(A);y.current=A;let P=a((C)=>{u.current?.write(C)},[]);i(()=>{if(!d||!r)return;u.current?.focus()},[d,r]);let E=a((C,_)=>{u.current?.writeReplay(C,_.replayCols,_.replayRows)},[]),D=a(()=>{u.current?.reset()},[]),{status:R,shell:g,exitCode:x,error:L,attach:N,resize:z,input:H,restart:Q,reattach:Z}=fe({visible:d&&r,root:r?l:void 0,repo:U,theme:p?"dark":"light",onOutput:P,onReplay:E,onRestart:D}),ee=a((C,_)=>{b.current={cols:C,rows:_},N(C,_)},[N]),te=a((C,_)=>{let ne=b.current;if(b.current={cols:C,rows:_},!ne)return;z(C,_)},[z]),I=a((C)=>{let _=y.current,ne=_.ctrl||_.alt,We=we(C,_);if(ne&&C.length===1)F(X);H(le.encode(We))},[H]),q=a((C)=>{F((_)=>({..._,[C]:!_[C]})),u.current?.focus()},[]),K=a((C)=>{let _=xe(C,{applicationCursorKeys:u.current?.applicationCursorKeys()??!1,modifiers:y.current});if(!_)return;H(le.encode(_)),F(X),u.current?.focus()},[H]),G=a(async()=>{let C=u.current?.getSelection()??"";if(!C)return!1;return nn(C)},[]),He=a(async()=>{let C=await OA();if(C===null||C.length===0)return!1;return u.current?.paste(C),u.current?.focus(),!0},[]),$e=a((C)=>{H(C)},[H]),Ye=a((C)=>{H(le.encode(`${C}\r`)),u.current?.focus()},[H]),Ge=a(()=>{Q()},[Q]),Xe=a(()=>{Z()},[Z]);if(!r)return e("div",{className:`flex flex-col h-full bg-paper items-center justify-center text-ink/40 ${t}`,children:e("span",{className:"text-xs font-mono text-muted",children:"No session selected"})});return e("div",{ref:T,className:`flex flex-col h-full w-full bg-paper text-ink overflow-hidden ${t}`,"aria-hidden":!d,style:k>0?{paddingBottom:k}:void 0,children:[c&&e(ye,{status:R,exitCode:x,rootPath:l,activeRepo:U,onSelectRepo:B,repos:v,reposScanning:M,onRefreshRepos:O,shell:g,onRestart:Ge}),e(ge,{onSelectCommand:Ye,disabled:R!=="running"}),L&&e("div",{className:"px-3 py-1.5 border-b border-error/20 bg-error/5 text-[11px] font-mono text-error flex-shrink-0",children:L}),e("div",{className:"flex-1 w-full min-h-0 bg-canvas overflow-hidden",children:e(se,{ref:u,onInput:I,onBinaryInput:$e,onReady:ee,onGridChange:te,onReattach:Xe})}),h&&e(Re,{modifiers:A,onToggleModifier:q,onKey:K,onCopy:G,onPaste:He,disabled:R!=="running"})]})}export{$n as TerminalPanel};
1
+ import{n,i,o,ci,a,Ds,e,w,Ze,ze,S,ir,or,s,m,$r,f,va,_e,nn,OA,cn,xr,Rp,Wl}from"./index-3wpsr2bc.js";import{Ts,fr,_u}from"./index-4qt2e84b.js";function re(){if(typeof crypto<"u"&&typeof crypto.randomUUID==="function")return crypto.randomUUID();return`t-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function oe(t){return JSON.stringify(t)}function ce(t){let r=Qe(t);if(!w(r))return null;if(r.t==="ready"){if(typeof r.id!=="string"||typeof r.cwd!=="string")return null;let l=typeof r.replayBytes==="number"?r.replayBytes:0;return{...r,t:"ready",replayBytes:l}}if(r.t==="exit")return{t:"exit",exitCode:typeof r.exitCode==="number"?r.exitCode:null,signal:typeof r.signal==="string"?r.signal:null};if(r.t==="error"&&typeof r.message==="string")return{t:"error",code:Ve(r.code),message:r.message};return null}function ue(t){return`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/api/terminal/${encodeURIComponent(t)}/ws`}function Ve(t){return t==="capacity"||t==="cwd"||t==="shell"||t==="spawn"?t:"unknown"}function Qe(t){try{return JSON.parse(t)}catch{return null}}function me(t){if(t.buffer instanceof ArrayBuffer)return t;return new Uint8Array(t)}var Je=500,je=8000,et=4;function de(t,r){let l=null,c=null,d=0,u=!1,p=!1,h=!1,T=null,k=[],A=0,F=null,U=()=>{let b=new WebSocket(ue(t));b.binaryType="arraybuffer",l=b,b.onopen=()=>{if(p)return;if(d=0,u=!0,r.onConnectionChange(!0),T)b.send(oe(T))},b.onmessage=(y)=>{if(p)return;if(y.data instanceof ArrayBuffer){v(new Uint8Array(y.data));return}if(typeof y.data!=="string")return;let P=ce(y.data);if(P)B(P)},b.onclose=()=>{if(l=null,p)return;if(r.onConnectionChange(!1),h=!1,k=[],A=0,F=null,!u)return;if(d+=1,d>et)return;let y=Math.min(Je*2**(d-1),je);c=setTimeout(()=>{if(c=null,!p)U()},y)},b.onerror=()=>{}},B=(b)=>{if(b.t==="ready"){if(h=!0,F=b,A=b.replayBytes,k=[],r.onReady(b),A===0)M();return}if(b.t==="exit"){r.onExit(b.exitCode,b.signal);return}r.onError(b.code,b.message)},v=(b)=>{if(A<=0){r.onOutput(b);return}if(k.push(b),A-=b.length,A>0)return;M()},M=()=>{let b=F,y=k;if(F=null,k=[],A=0,!b)return;r.onReplay(y.length===1?y[0]:tt(y),b)};U();let O=(b)=>{let y=l;if(!y||y.readyState!==WebSocket.OPEN)return;y.send(oe(b))};return{attach(b,y,P,E,D){if(h)return;let R={t:"attach",cols:b,rows:y};if(P)R.root=P;if(E)R.repo=E;if(D)R.theme=D;T=R,O(R)},resize(b,y){O({t:"resize",cols:b,rows:y})},input(b){let y=l;if(!y||y.readyState!==WebSocket.OPEN)return;y.send(me(b))},close(){O({t:"close"})},release(){if(p=!0,c!==null)clearTimeout(c),c=null;let b=l;if(l=null,!b)return;b.onopen=null,b.onmessage=null,b.onclose=null,b.onerror=null,b.close()}}}function tt(t){let r=0;for(let d of t)r+=d.length;let l=new Uint8Array(r),c=0;for(let d of t)l.set(d,c),c+=d.length;return l}function pe(t){return{connect:t.visible||t.opened,persist:t.ready&&t.visible&&!t.opened}}function fe(t={}){let{sessionId:r,ready:l}=Ze(),[c,d]=S("terminal.id",""),[u,p]=S("terminal.opened",!1),h=pe({visible:t.visible===!0,ready:l,opened:u}),[T,k]=n("connecting"),[A,F]=n(""),[U,B]=n(null),[v,M]=n(null),[O,b]=n(0),y=o(null),P=o(null),E=o(t.onOutput);E.current=t.onOutput;let D=o(t.onReplay);D.current=t.onReplay;let R=o(t.onRestart);R.current=t.onRestart;let g=o(t.root);g.current=t.root;let x=o(t.repo);x.current=t.repo;let L=o(t.theme);L.current=t.theme;let N=o(d);N.current=d;let z=o(null);i(()=>{if(!h.persist)return;p(!0)},[h.persist]),i(()=>{if(!h.connect||!l)return;if(ze(r,"terminal.id"))return;N.current(re())},[h.connect,l,r]),i(()=>{if(!h.connect||!l||!c)return;k("connecting"),M(null),B(null);let I=de(c,{onReady(K){k("running"),F(K.shell),B(null)},onReplay(K,G){D.current?.(K,G)},onOutput(K){E.current?.(K)},onExit(K){k("exited"),B(K)},onError(K,G){k("error"),M(`${K}: ${G}`)},onConnectionChange(K){if(!K)k("connecting")}});y.current=I;let q=P.current;if(q)I.attach(q.cols,q.rows,g.current,x.current,L.current);return()=>{I.release(),y.current=null}},[h.connect,l,c,O]);let H=a(()=>{y.current?.close(),R.current?.(),N.current(re())},[]);i(()=>{if(!l)return;let I=t.root;if(!I)return;let q=`${I}\x00${t.repo??"."}`;if(z.current===null){z.current=q;return}if(z.current===q)return;z.current=q,H()},[l,t.root,t.repo,H]);let Q=a((I,q)=>{P.current={cols:I,rows:q},y.current?.attach(I,q,g.current,x.current,L.current)},[]),Z=a((I,q)=>{P.current={cols:I,rows:q},y.current?.resize(I,q)},[]),ee=a((I)=>{y.current?.input(I)},[]),te=a(()=>{b((I)=>I+1)},[]);return{status:T,shell:A,exitCode:U,error:v,attach:Q,resize:Z,input:ee,restart:H,reattach:te}}var nt={name:"clipboard-copy",size:24,node:[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1",key:"tgr4d6"}],["path",{d:"M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2",key:"4jdomd"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v4",key:"3hqy98"}],["path",{d:"M21 14H11",key:"1bme5i"}],["path",{d:"m15 10-4 4 4 4",key:"5dvupr"}]]},be=s(nt);var rt={name:"zap",size:24,node:[["path",{d:"M15.914 4a1.5 1.5 0 00-2.474-1.561l-9 9A1.5 1.5 0 005.5 14h4.002a.5.5 0 01.471.666L8.086 20a1.5 1.5 0 002.475 1.56l9-9A1.5 1.5 0 0018.5 10h-3.997a.5.5 0 01-.472-.667z",key:"1v7up4"}]]},he=s(rt);var ot={connecting:"CONNECTING",running:"LIVE",exited:"EXITED",error:"ERROR"},it={connecting:"bg-warning/10 text-warning border-warning/20",running:"bg-success/10 text-success border-success/20",exited:"bg-ink/5 text-ink/60 border-ink/15",error:"bg-error/10 text-error border-error/20"};function ye({status:t,exitCode:r,rootPath:l,activeRepo:c,onSelectRepo:d,repos:u,reposScanning:p,onRefreshRepos:h,shell:T,onRestart:k}){let A=T?T.split("/").pop():"";return e("div",{className:"h-10 px-3 border-b border-ink/10 bg-paper flex items-center justify-between flex-shrink-0 select-none",children:[e("div",{className:"flex items-center space-x-2 min-w-0",children:[e("div",{className:"flex items-center space-x-1.5",children:[e(_e,{size:14,className:"text-ink/80 flex-shrink-0"}),e("span",{className:"text-xs font-semibold tracking-wider text-ink uppercase",children:"Terminal"})]}),e("span",{className:`inline-flex items-center space-x-1 px-1.5 py-0.5 rounded text-[10px] font-mono border ${it[t]}`,title:t==="exited"&&r!==null?`Shell exited with code ${r}`:void 0,children:[t==="connecting"&&e(m,{size:10,className:"animate-spin"}),e("span",{children:t==="exited"&&r!==null?`EXIT ${r}`:ot[t]})]}),e(fr,{rootPath:l,activeRepo:c,onSelectRepo:d,repos:u,scanning:p,onRefreshRepos:h}),e("button",{type:"button",onClick:k,title:"Kill this shell and start a new one",className:"p-1 rounded text-ink/50 hover:text-ink hover:bg-ink/5 transition-colors cursor-pointer flex-shrink-0",children:e(va,{size:12})})]}),A&&e("span",{className:"hidden sm:block text-[10px] font-mono text-ink/40 flex-shrink-0",children:A})]})}var at=[{label:"bun build",cmd:"bun run build"},{label:"bun test",cmd:"bun test"},{label:"git status",cmd:"git status -s"},{label:"git diff",cmd:"git diff"},{label:"ls -la",cmd:"ls -la"},{label:"pwd",cmd:"pwd"},{label:"bun -v",cmd:"bun --version"}];function ge({onSelectCommand:t,disabled:r}){return e("div",{className:"flex flex-wrap items-center gap-1.5 px-3 py-1.5 bg-paper border-b border-ink/10 flex-shrink-0",children:[e("div",{className:"flex items-center space-x-1 text-[10px] font-mono text-ink/50 uppercase tracking-wider flex-shrink-0 select-none",children:[e(he,{size:11,className:"text-warning"}),e("span",{children:"Quick:"})]}),at.map((l)=>e("button",{type:"button",disabled:r,onClick:()=>t(l.cmd),className:"px-2 py-0.5 rounded text-[10px] font-mono bg-canvas hover:bg-ink/5 active:bg-ink/10 text-ink/80 hover:text-ink border border-ink/15 transition-all whitespace-nowrap disabled:opacity-40 cursor-pointer shadow-2xs",children:l.label},l.cmd))]})}var X=Object.freeze({ctrl:!1,alt:!1}),ie=[{id:"escape",label:"Esc",name:"Escape",sequence:"\x1B"},{id:"tab",label:"Tab",name:"Tab",sequence:"\t"},{id:"interrupt",label:"^C",name:"Ctrl+C — interrupt",sequence:"\x03"},{id:"left",label:"←",name:"Left arrow",csi:{prefix:"1",final:"D",application:"OD"}},{id:"up",label:"↑",name:"Up arrow",csi:{prefix:"1",final:"A",application:"OA"}},{id:"down",label:"↓",name:"Down arrow",csi:{prefix:"1",final:"B",application:"OB"}},{id:"right",label:"→",name:"Right arrow",csi:{prefix:"1",final:"C",application:"OC"}},{id:"home",label:"Home",name:"Home",csi:{prefix:"1",final:"H",application:"OH",terminfo:"\x1BOH"}},{id:"end",label:"End",name:"End",csi:{prefix:"1",final:"F",application:"OF",terminfo:"\x1BOF"}},{id:"pageUp",label:"PgUp",name:"Page up",csi:{prefix:"5",final:"~"}},{id:"pageDown",label:"PgDn",name:"Page down",csi:{prefix:"6",final:"~"}},{id:"delete",label:"Del",name:"Delete",csi:{prefix:"3",final:"~"}},{id:"shiftTab",label:"⇧Tab",name:"Shift+Tab",sequence:"\x1B[Z"},{id:"eof",label:"^D",name:"Ctrl+D — end of input",sequence:"\x04"},{id:"clear",label:"^L",name:"Ctrl+L — clear screen",sequence:"\f"}],ae=[{id:"pipe",label:"|",name:"Pipe",sequence:"|"},{id:"tilde",label:"~",name:"Tilde",sequence:"~"},{id:"dollar",label:"$",name:"Dollar",sequence:"$"},{id:"asterisk",label:"*",name:"Asterisk",sequence:"*"},{id:"question",label:"?",name:"Question mark",sequence:"?"},{id:"underscore",label:"_",name:"Underscore",sequence:"_"},{id:"backslash",label:"\\",name:"Backslash",sequence:"\\"},{id:"slash",label:"/",name:"Slash",sequence:"/"},{id:"minus",label:"-",name:"Minus",sequence:"-"},{id:"equals",label:"=",name:"Equals",sequence:"="},{id:"plus",label:"+",name:"Plus",sequence:"+"},{id:"ampersand",label:"&",name:"Ampersand",sequence:"&"},{id:"semicolon",label:";",name:"Semicolon",sequence:";"},{id:"colon",label:":",name:"Colon",sequence:":"},{id:"comma",label:",",name:"Comma",sequence:","},{id:"dot",label:".",name:"Period",sequence:"."},{id:"at",label:"@",name:"At sign",sequence:"@"},{id:"percent",label:"%",name:"Percent",sequence:"%"},{id:"caret",label:"^",name:"Caret",sequence:"^"},{id:"hash",label:"#",name:"Hash",sequence:"#"},{id:"bang",label:"!",name:"Exclamation mark",sequence:"!"},{id:"parenOpen",label:"(",name:"Open parenthesis",sequence:"("},{id:"parenClose",label:")",name:"Close parenthesis",sequence:")"},{id:"bracketOpen",label:"[",name:"Open bracket",sequence:"["},{id:"bracketClose",label:"]",name:"Close bracket",sequence:"]"},{id:"braceOpen",label:"{",name:"Open brace",sequence:"{"},{id:"braceClose",label:"}",name:"Close brace",sequence:"}"},{id:"lessThan",label:"<",name:"Less than",sequence:"<"},{id:"greaterThan",label:">",name:"Greater than",sequence:">"},{id:"quote",label:"'",name:"Single quote",sequence:"'"},{id:"doubleQuote",label:'"',name:"Double quote",sequence:'"'},{id:"backtick",label:"`",name:"Backtick",sequence:"`"}],Te={};for(let t of[...ie,...ae])Te[t.id]=t;function xe(t,r={}){let l=Te[t];if(!l)return"";let c=r.modifiers??X;if(l.csi)return st(l.csi,c,r.applicationCursorKeys??!1);let d=l.sequence??"";return c.alt?`\x1B${d}`:d}function st(t,r,l){let c=lt(r);if(c!==null)return`\x1B[${t.prefix};${c}${t.final}`;if(t.terminfo)return t.terminfo;if(l&&t.application)return`\x1B${t.application}`;return`\x1B[${t.prefix==="1"?"":t.prefix}${t.final}`}function lt(t){let r=(t.alt?2:0)|(t.ctrl?4:0);return r===0?null:r+1}function we(t,r){if(t.length!==1)return t;let l=t;if(r.ctrl)l=ut(l)??l;if(r.alt)l=`\x1B${l}`;return l}var ct={"@":"\x00"," ":"\x00","":"\b","[":"\x1B","\\":"\x1C","]":"\x1D","^":"\x1E",_:"\x1F","?":""};function ut(t){if(t.length!==1)return null;let r=t.charCodeAt(0);if(r>=97&&r<=122)return String.fromCharCode(r-96);if(r>=65&&r<=90)return String.fromCharCode(r-64);return ct[t]??null}var mt=[{modifier:"ctrl",label:"Ctrl",name:"Ctrl — applies to the next key"},{modifier:"alt",label:"Alt",name:"Alt / meta — applies to the next key"}],W="flex items-center justify-center h-8 min-w-8 px-1.5 rounded border font-mono transition-colors cursor-pointer select-none disabled:opacity-40 disabled:cursor-default text-[11px] @[420px]:h-9 @[420px]:min-w-10 @[420px]:text-xs",V="bg-canvas text-ink/80 border-ink/15 hover:text-ink hover:bg-ink/5 active:bg-ink/10",ve="bg-ink text-canvas border-ink";function Re({modifiers:t,onToggleModifier:r,onKey:l,onCopy:c,onPaste:d,disabled:u}){let[p,h]=n(!1),[T,k]=n(null),A=t.ctrl||t.alt,F=(v)=>{k(v),setTimeout(()=>k((M)=>M===v?null:M),1500)},U=async()=>{F(await c()?"copied":"empty")},B=async()=>{if(!await d())F("pasteFailed")};return e("div",{className:"@container flex flex-col gap-1 px-2 py-1.5 border-t border-ink/10 bg-paper flex-shrink-0",onPointerDown:(v)=>v.preventDefault(),children:[e("div",{className:"flex flex-wrap items-center gap-1",children:[mt.map(({modifier:v,label:M,name:O})=>e("button",{type:"button",onClick:()=>r(v),"aria-pressed":t[v],title:O,"aria-label":O,className:`${W} ${t[v]?ve:V}`,children:M},v)),A&&e("span",{className:"text-[10px] font-mono text-ink/50 px-0.5 whitespace-nowrap","aria-hidden":!0,children:"next"}),e("span",{className:"w-px h-5 bg-ink/15 flex-shrink-0","aria-hidden":!0}),e("button",{type:"button",onClick:U,disabled:u,title:T==="empty"?"Nothing selected":"Copy selection","aria-label":"Copy selection",className:`${W} ${T==="empty"?"bg-warning/10 text-warning border-warning/30":V}`,children:[T==="copied"?e(f,{size:13}):e(be,{size:13}),e("span",{className:"pl-1",children:"Copy"})]}),e("button",{type:"button",onClick:B,disabled:u,title:T==="pasteFailed"?"Clipboard unavailable":"Paste into the shell","aria-label":"Paste into the shell",className:`${W} ${T==="pasteFailed"?"bg-error/10 text-error border-error/30":V}`,children:[e(Ts,{size:13}),e("span",{className:"pl-1",children:"Paste"})]}),e("button",{type:"button",onClick:()=>h((v)=>!v),"aria-pressed":p,title:p?"Show control keys":"Show symbols","aria-label":p?"Show control keys":"Show symbols",className:`${W} ml-auto ${p?ve:V}`,children:p?"ABC":"123"})]}),e("div",{className:"flex flex-wrap items-center gap-1",children:(p?ae:ie).map((v)=>e("button",{type:"button",disabled:u,onClick:()=>l(v.id),title:v.name,"aria-label":v.name,className:`${W} ${V}`,children:v.label},v.id))})]})}function Se(t){if(!t.startsWith("\x1B[M")||t.length<6)return{text:t};let r=new Uint8Array(t.length);for(let l=0;l<t.length;l+=1)r[l]=t.charCodeAt(l)&255;return{bytes:r}}function Ce(t){let r=cn(t),{canvas:l,ink:c,paper:d}=r,u=(h)=>xr(h,c,0.2),p=(h)=>xr(l,c,h);return{background:"transparent",foreground:c,cursor:r.meta,cursorAccent:d,selectionBackground:p(0.28),selectionForeground:c,black:p(0.2),red:r.error,green:r.success,yellow:r.warning,blue:r.info,magenta:r.meta,cyan:xr(r.info,r.success,0.5),white:p(0.75),brightBlack:p(0.5),brightRed:u(r.error),brightGreen:u(r.success),brightYellow:u(r.warning),brightBlue:u(r.info),brightMagenta:u(r.meta),brightCyan:u(xr(r.info,r.success,0.5)),brightWhite:p(0.92)}}var J="Fira Code",dt="'FiraCode Nerd Font Mono', 'FiraCode Nerd Font', 'JetBrainsMono Nerd Font', 'JetBrainsMono NF', 'JetBrains Mono Nerd Font', 'Hack Nerd Font', 'MesloLGS NF', 'MesloLGM Nerd Font', 'CaskaydiaCove Nerd Font', 'SauceCodePro Nerd Font', 'Symbols Nerd Font Mono', 'Symbols Nerd Font', 'PowerlineSymbols'",ke="Kabmo Nerd Symbols",Ae=[J,ke],j=`'${J}', ${dt}, '${ke}', Menlo, Monaco, 'Courier New', monospace`,Y=12,pt=16,ft=1e4;function bt(t,r){return Math.max(1,t)*Math.max(1,r)*pt}var Me=bt(ft,100);var ht=2000;async function Fe(){if(typeof document>"u"||!document.fonts?.load)return;let t=Promise.withResolvers(),r=setTimeout(t.resolve,ht);try{await Promise.race([document.fonts.load(`${Y}px "${J}"`).then(()=>{return},()=>{return}),t.promise])}finally{clearTimeout(r)}}function Le(t){if(typeof document>"u"||!document.fonts)return()=>{};let r=new Set(Ae),l=(c)=>{if([...c.fontfaces].some((u)=>r.has(u.family.replace(/['"]/g,"").trim())))t()};return document.fonts.addEventListener("loadingdone",l),()=>document.fonts.removeEventListener("loadingdone",l)}var Ee=2.5,yt=1;function gt(t,r){let l=t*0.8,c=t*0.2,d=Math.ceil(t*0.6),u=l,p=c,h=typeof document>"u"?null:document.createElement("canvas").getContext("2d");if(h){h.font=`${t}px ${r}`,d=Math.ceil(h.measureText("M").width)||d;let T=h.measureText("Mg");u=T.actualBoundingBoxAscent||l,p=T.actualBoundingBoxDescent||c}return{width:d,height:Math.ceil(u+p+Ee+yt),baseline:Math.round(u+Ee)}}function Ne(t){let r=t.renderer;if(!r)return;r.measureFont=()=>gt(t.options.fontSize??Y,t.options.fontFamily??j),r.remeasureFont()}function Tt(t,r,l){if(!l.width||!l.height)return null;return{cols:Math.max(2,Math.floor(t/l.width)),rows:Math.max(1,Math.floor(r/l.height))}}function Ie(t,r){let l=t;l.proposeDimensions=()=>{let c=r.element,d=r.renderer?.getMetrics();if(!c||!d)return;let u=getComputedStyle(c),p=(parseFloat(u.paddingLeft)||0)+(parseFloat(u.paddingRight)||0),h=(parseFloat(u.paddingTop)||0)+(parseFloat(u.paddingBottom)||0);return Tt(c.clientWidth-p,c.clientHeight-h,d)??void 0}}function xt(t){let{cols:r,rows:l,attached:c,committed:d}=t;if(r<10||l<5)return{kind:"ignore"};if(!c)return{kind:"attach",cols:r,rows:l};if(r===d.cols&&l===d.rows)return{kind:"ignore"};return{kind:"change",cols:r,rows:l}}function Oe(t){let r={cols:0,rows:0},l=!1,c,d=()=>{if(!t.fit())return;let u=t.current();if(!u)return;let p=xt({cols:u.cols,rows:u.rows,attached:l,committed:r});if(p.kind==="ignore")return;if(r={cols:p.cols,rows:p.rows},p.kind==="attach"){l=!0,t.onReady(p.cols,p.rows);return}t.onGridChange(p.cols,p.rows)};return{schedule(){clearTimeout(c),c=setTimeout(d,120)},restate(){r={cols:0,rows:0}},isAttached:()=>l,dispose(){clearTimeout(c),c=void 0}}}function Pe(t,r){if(r.type!=="keydown"||!r.shiftKey)return!1;if(r.key==="PageUp")return t.scrollPages(-1),!0;if(r.key==="PageDown")return t.scrollPages(1),!0;if(r.key==="Home")return t.scrollToTop(),!0;if(r.key==="End")return t.scrollToBottom(),!0;if(r.key==="ArrowUp")return t.scrollLines(-1),!0;if(r.key==="ArrowDown")return t.scrollLines(1),!0;return!1}function Ue(t,r){let l=0,c=(u)=>{if(u.touches.length===1)l=u.touches[0].clientY},d=(u)=>{if(u.touches.length!==1)return;let p=l-u.touches[0].clientY;if(Math.abs(p)<16)return;r()?.scrollLines(Math.trunc(p/16)),l=u.touches[0].clientY};return t.addEventListener("touchstart",c,{passive:!0}),t.addEventListener("touchmove",d,{passive:!0}),()=>{t.removeEventListener("touchstart",c),t.removeEventListener("touchmove",d)}}function wt(t){if(t.viewportY<=0&&!t.hasSelection&&!t.pointerHeld)return null;return t.scrollback-t.viewportY}function vt(t){let r=t.scrollback-t.top;return r>0?r:null}function Be(t){let r={pointerHeld:!1},l=()=>{r.pointerHeld=!0},c=()=>{r.pointerHeld=!1};return t.addEventListener("pointerdown",l,!0),globalThis.addEventListener("pointerup",c),globalThis.addEventListener("pointercancel",c),{get pointerHeld(){return r.pointerHeld},stop(){t.removeEventListener("pointerdown",l,!0),globalThis.removeEventListener("pointerup",c),globalThis.removeEventListener("pointercancel",c)}}}function De(t,r,l){let c=wt({scrollback:t.getScrollbackLength(),viewportY:t.getViewportY(),hasSelection:t.hasSelection(),pointerHeld:r.pointerHeld});if(l(),c===null)return;let d=vt({scrollback:t.getScrollbackLength(),top:c});if(d===null)return;let u=d-t.getViewportY();if(u===0)return;try{t.scrollLines(-u)}catch{}}async function qe(t,r,l,c){let d=await import("./ghostty-web-2gt2tp72.js"),[u]=await Promise.all([d.Ghostty.load(),Fe()]);if(c())return null;let p=r,h=null,T=!1,k,A=null,F=!1,U=(g)=>{let{term:x}=g;x.attachCustomKeyEventHandler((L)=>Pe(x,L)),g.disposables.push(x.onScroll((L)=>l.onScrolledUpChange(L>0)),x.onData((L)=>{let N=Se(L);if(N.bytes)l.onBinaryInput(N.bytes);else l.onInput(N.text)}),x.onResize(()=>{if(T)return;y.schedule()}))},B=(g)=>{let x=new d.Terminal({cursorBlink:!0,cursorStyle:"block",fontSize:Y,fontFamily:j,theme:Ce(g),scrollback:Me,smoothScrollDuration:0,ghostty:u});x.open(t),Ne(x),x.clear();let L=new d.FitAddon;x.loadAddon(L),Ie(L,x);let N={term:x,fitAddon:L,disposables:[]};return U(N),N},v=(g)=>{if(!g)return;for(let x of g.disposables)try{x.dispose()}catch{}try{g.fitAddon.dispose()}catch{}try{g.term.dispose()}catch{}},M=()=>{if(F)return!1;if(t.clientWidth<=0||t.clientHeight<=0)return!1;let g=h?.term.renderer?.getMetrics();if(!g?.width||!g.height)return!1;try{return h?.fitAddon.fit(),!0}catch{return!1}},O=()=>{if(F)return;T=!1,M(),y.restate(),y.schedule()},b=(g,x,L)=>{let N=h?.term;if(!N)return;if(T=!0,N.cols!==x||N.rows!==L)N.resize(x,L);if(g.length===0){requestAnimationFrame(O);return}N.write(g,O)},y=Oe({current:()=>h?.term,fit:M,onReady:l.onReady,onGridChange:l.onGridChange}),P=Be(t);h=B(p),M(),y.schedule();let E=new ResizeObserver(()=>{clearTimeout(k),k=setTimeout(()=>{M(),y.schedule()},35)});E.observe(t);let D=Le(()=>{let g=h?.term;if(!g)return;let x=g.options.fontSize??Y;g.options.fontSize=x+0.1,g.options.fontSize=x,M(),y.schedule()}),R=Ue(t,()=>h?.term??null);return A=requestAnimationFrame(()=>{M(),y.schedule()}),{write(g){let x=h?.term;if(!x)return;De(x,P,()=>x.write(g))},writeReplay:b,reset(){let g=h?.term;if(!g)return;g.reset(),g.clear(),M()},focus(){h?.term.focus()},applicationCursorKeys(){return h?.term.wasmTerm?.getMode(1,!1)??!1},getSelection(){return h?.term.getSelection()??""},paste(g){h?.term.paste(g)},scrollToBottom(){h?.term.scrollToBottom()},setTheme(g){if(F||g===p)return;p=g,v(h),h=B(g),M()},dispose(){if(F=!0,A!==null)cancelAnimationFrame(A);clearTimeout(k),y.dispose(),D(),R(),P.stop(),E.disconnect(),v(h),h=null}}}function Ke(){let t=null,r=!1;return{request(){if(t)t();else r=!0},attach(l){if(t=l,!r)return;r=!1,l()},detach(){t=null,r=!1}}}var se=Ds(({onInput:t,onBinaryInput:r,onGridChange:l,onReady:c,onReattach:d},u)=>{let{theme:p}=Rp(),h=o(null),T=o(null),[k,A]=n(!1),F=o(null);if(!F.current)F.current=Ke();let U=F.current,B=o(t);B.current=t;let v=o(r);v.current=r;let M=o(l);M.current=l;let O=o(c);O.current=c;let b=o(d);b.current=d;let y=o(p);y.current=p,i(()=>{let E=T.current;if(!E)return;E.setTheme(p),b.current?.()},[p]),ci(u,()=>({write(E){T.current?.write(E)},writeReplay(E,D,R){T.current?.writeReplay(E,D,R)},reset(){T.current?.reset()},focus(){U.request()},applicationCursorKeys(){return T.current?.applicationCursorKeys()??!1},getSelection(){return T.current?.getSelection()??""},paste(E){T.current?.paste(E)}}),[]);let P=a(()=>{T.current?.scrollToBottom(),A(!1)},[]);return i(()=>{let E=h.current;if(!E)return;let D=!1;return qe(E,y.current,{onInput:(R)=>B.current(R),onBinaryInput:(R)=>v.current(R),onGridChange:(R,g)=>M.current(R,g),onReady:(R,g)=>O.current(R,g),onScrolledUpChange:A},()=>D).then((R)=>{if(!R)return;if(D){R.dispose();return}T.current=R,E.querySelector("textarea")?.setAttribute("data-terminal-input",""),U.attach(()=>T.current?.focus())}),()=>{D=!0,U.detach(),T.current?.dispose(),T.current=null}},[]),e("div",{className:"relative flex-1 w-full h-full overflow-hidden p-2",children:[e("div",{ref:h,"data-terminal-root":"",className:"kabmo-terminal w-full h-full cursor-text",style:{height:"100%",width:"100%"}}),k&&e("button",{type:"button",onClick:P,className:"absolute bottom-3 right-4 z-20 flex items-center space-x-1.5 px-2.5 py-1 bg-paper hover:bg-canvas text-ink border border-ink/20 rounded-full shadow-lg text-[11px] font-mono transition-all animate-fade-in cursor-pointer active:scale-95",title:"Scroll to latest output (Shift+End)",children:[e($r,{size:12,className:"text-warning"}),e("span",{children:"Latest"})]})]})});se.displayName="RealtimeTerminalView";var le=new TextEncoder;function $n({className:t="",enabled:r=!0,rootPath:l,showHeader:c=!0,active:d=!0}){let u=o(null),{isDark:p}=Rp(),h=_u(),T=o(null),k=Wl(T),[A,F]=n(X),{activeRepo:U,setActiveRepo:B}=ir(l),{repos:v,scanning:M,rescan:O}=or(l,r),b=o(null),y=o(A);y.current=A;let P=a((C)=>{u.current?.write(C)},[]);i(()=>{if(!d||!r)return;u.current?.focus()},[d,r]);let E=a((C,_)=>{u.current?.writeReplay(C,_.replayCols,_.replayRows)},[]),D=a(()=>{u.current?.reset()},[]),{status:R,shell:g,exitCode:x,error:L,attach:N,resize:z,input:H,restart:Q,reattach:Z}=fe({visible:d&&r,root:r?l:void 0,repo:U,theme:p?"dark":"light",onOutput:P,onReplay:E,onRestart:D}),ee=a((C,_)=>{b.current={cols:C,rows:_},N(C,_)},[N]),te=a((C,_)=>{let ne=b.current;if(b.current={cols:C,rows:_},!ne)return;z(C,_)},[z]),I=a((C)=>{let _=y.current,ne=_.ctrl||_.alt,We=we(C,_);if(ne&&C.length===1)F(X);H(le.encode(We))},[H]),q=a((C)=>{F((_)=>({..._,[C]:!_[C]})),u.current?.focus()},[]),K=a((C)=>{let _=xe(C,{applicationCursorKeys:u.current?.applicationCursorKeys()??!1,modifiers:y.current});if(!_)return;H(le.encode(_)),F(X),u.current?.focus()},[H]),G=a(async()=>{let C=u.current?.getSelection()??"";if(!C)return!1;return nn(C)},[]),He=a(async()=>{let C=await OA();if(C===null||C.length===0)return!1;return u.current?.paste(C),u.current?.focus(),!0},[]),$e=a((C)=>{H(C)},[H]),Ye=a((C)=>{H(le.encode(`${C}\r`)),u.current?.focus()},[H]),Ge=a(()=>{Q()},[Q]),Xe=a(()=>{Z()},[Z]);if(!r)return e("div",{className:`flex flex-col h-full bg-paper items-center justify-center text-ink/40 ${t}`,children:e("span",{className:"text-xs font-mono text-muted",children:"No session selected"})});return e("div",{ref:T,className:`flex flex-col h-full w-full bg-paper text-ink overflow-hidden ${t}`,"aria-hidden":!d,style:k>0?{paddingBottom:k}:void 0,children:[c&&e(ye,{status:R,exitCode:x,rootPath:l,activeRepo:U,onSelectRepo:B,repos:v,reposScanning:M,onRefreshRepos:O,shell:g,onRestart:Ge}),e(ge,{onSelectCommand:Ye,disabled:R!=="running"}),L&&e("div",{className:"px-3 py-1.5 border-b border-error/20 bg-error/5 text-[11px] font-mono text-error flex-shrink-0",children:L}),e("div",{className:"flex-1 w-full min-h-0 bg-canvas overflow-hidden",children:e(se,{ref:u,onInput:I,onBinaryInput:$e,onReady:ee,onGridChange:te,onReattach:Xe})}),h&&e(Re,{modifiers:A,onToggleModifier:q,onKey:K,onCopy:G,onPaste:He,disabled:R!=="running"})]})}export{$n as TerminalPanel};