@hienlh/ppm 0.20.6 → 0.20.8

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 (172) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/assets/skills/ppm/SKILL.md +1 -1
  3. package/assets/skills/ppm/references/http-api.md +1 -1
  4. package/dist/web/assets/{accounts-settings-section-B-F7U-gq.js → accounts-settings-section-CRXY4Bsc.js} +1 -1
  5. package/dist/web/assets/{ai-resource-editor-qRHwpktf.js → ai-resource-editor-CMQfhxXp.js} +1 -1
  6. package/dist/web/assets/ai-settings-section-446NZWhI.js +1 -0
  7. package/dist/web/assets/{ai-settings-section-DSlsTrpf.js → ai-settings-section-M07DCjAI.js} +1 -1
  8. package/dist/web/assets/api-client-CYZ79uUS.js +1 -0
  9. package/dist/web/assets/{api-client-CEYCBt_0.js → api-client-DwXlVfXP.js} +1 -1
  10. package/dist/web/assets/{api-settings-D18Q4Ocp.js → api-settings-BQIwZoLm.js} +1 -1
  11. package/dist/web/assets/{api-themes-sSv-6OLk.js → api-themes-CmJZLEY1.js} +1 -1
  12. package/dist/web/assets/{appearance-settings-section-BMlkj9U2.js → appearance-settings-section-BBlJtEm5.js} +1 -1
  13. package/dist/web/assets/arrow-left-DpXaakMC.js +1 -0
  14. package/dist/web/assets/{audio-preview-B4E5_7TW.js → audio-preview-DPMXOZ55.js} +1 -1
  15. package/dist/web/assets/{bot-D6sx11y0.js → bot-D3-n2i31.js} +1 -1
  16. package/dist/web/assets/{brain-KDa9jFRq.js → brain-CuAQMSBE.js} +1 -1
  17. package/dist/web/assets/{button-DX32ffge.js → button-zgoXa9r7.js} +1 -1
  18. package/dist/web/assets/{calendar-clock-C1asT-gk.js → calendar-clock-CDP7AVjA.js} +1 -1
  19. package/dist/web/assets/{chat-tab-DmqV3MlC.js → chat-tab-Dn45anqr.js} +4 -4
  20. package/dist/web/assets/check-BQKbhtoA.js +1 -0
  21. package/dist/web/assets/{chevron-down-Dp0rpHb8.js → chevron-down-B9puixxZ.js} +1 -1
  22. package/dist/web/assets/chevron-right-DK_HbYZC.js +1 -0
  23. package/dist/web/assets/{chevron-up-8PbsNiJp.js → chevron-up-BPAINgoK.js} +1 -1
  24. package/dist/web/assets/circle-OKk7s0DX.js +1 -0
  25. package/dist/web/assets/{circle-question-mark-CzR7YRc-.js → circle-question-mark-qcWYO1P_.js} +1 -1
  26. package/dist/web/assets/clock-BmPiGrSF.js +1 -0
  27. package/dist/web/assets/code-CRiIHSiv.js +1 -0
  28. package/dist/web/assets/{code-editor-C4CriX9c.js → code-editor-CKASeDbu.js} +2 -2
  29. package/dist/web/assets/{conflict-editor-LfQoRcK-.js → conflict-editor-C-Nv8YYj.js} +1 -1
  30. package/dist/web/assets/{context-menu-CJL8L98s.js → context-menu-DM9CgxGh.js} +1 -1
  31. package/dist/web/assets/{copy-BewHj66E.js → copy-CXuIH4VC.js} +1 -1
  32. package/dist/web/assets/{createLucideIcon-D8pyde1A.js → createLucideIcon-D6fVXe3s.js} +1 -1
  33. package/dist/web/assets/{csv-preview-BEYKn68B.js → csv-preview-ou3KFzIH.js} +1 -1
  34. package/dist/web/assets/{data-grid-overlay-editor-CbBkhhJa.js → data-grid-overlay-editor-dnWnblYo.js} +1 -1
  35. package/dist/web/assets/{data-grid-types-DeY60CLU.js → data-grid-types-BfGeMDy0.js} +1 -1
  36. package/dist/web/assets/{database-Y3ESDK4-.js → database-Dz0W7OH7.js} +1 -1
  37. package/dist/web/assets/{database-viewer-BL9R-ciJ.js → database-viewer-Ckqg_-SS.js} +1 -1
  38. package/dist/web/assets/{diff-viewer-D91SI_zb.js → diff-viewer-CMzFnBCD.js} +1 -1
  39. package/dist/web/assets/{dist-B0J2eYBz.js → dist-CWMPvPem.js} +1 -1
  40. package/dist/web/assets/{docx-preview-Xy7SZ7Vf.js → docx-preview-B7Aospmh.js} +1 -1
  41. package/dist/web/assets/{download-DG3_9xXy.js → download-D70Q4Ba6.js} +1 -1
  42. package/dist/web/assets/{edit-diff-preview-xdDQvPhs.js → edit-diff-preview-BvgPvuhH.js} +1 -1
  43. package/dist/web/assets/{esm-B-vXxHUd.js → esm-BHyWbWKE.js} +1 -1
  44. package/dist/web/assets/{explorer-body-ColVUjgk.js → explorer-body-CVx4qaIF.js} +1 -1
  45. package/dist/web/assets/explorer-window-content-CqKVMkgW.js +1 -0
  46. package/dist/web/assets/{extension-manager-section-B-BRHGu1.js → extension-manager-section-CtcpVMWs.js} +1 -1
  47. package/dist/web/assets/{extension-webview-DufzanN9.js → extension-webview-DZ_QRZSM.js} +1 -1
  48. package/dist/web/assets/{eye-gWwaF4Lg.js → eye-dfZn7evX.js} +1 -1
  49. package/dist/web/assets/{eye-off-GjXVuAOn.js → eye-off-CmtfyRUD.js} +1 -1
  50. package/dist/web/assets/{file-exclamation-point-JzhTU2TX.js → file-exclamation-point-D5K2aaLi.js} +1 -1
  51. package/dist/web/assets/{files-settings-section-Do5YbTUK.js → files-settings-section-D7v-6nTa.js} +1 -1
  52. package/dist/web/assets/{flask-conical-tp8gyZGh.js → flask-conical-Dix4qNDj.js} +1 -1
  53. package/dist/web/assets/{folder-symlink-fQRoG_rV.js → folder-symlink-BavsIzoj.js} +1 -1
  54. package/dist/web/assets/{general-settings-section-B-n_PYzs.js → general-settings-section-BW_h8pdA.js} +1 -1
  55. package/dist/web/assets/{git-log-panel-BQzOHgxG.js → git-log-panel-BQZkJDu0.js} +1 -1
  56. package/dist/web/assets/{glide-data-grid-BUS44oLM.js → glide-data-grid-JKEslqGe.js} +4 -4
  57. package/dist/web/assets/{group-chat-tab-CkHXqorZ.js → group-chat-tab-CTAhtVCr.js} +1 -1
  58. package/dist/web/assets/{hand-x0ejq3fS.js → hand-CIPALZsE.js} +1 -1
  59. package/dist/web/assets/{image-preview-fuU4h2nr.js → image-preview-V5SglTWk.js} +1 -1
  60. package/dist/web/assets/{index-Cx1meAwb.js → index-DVNJ2W5R.js} +7 -7
  61. package/dist/web/assets/{jira-watcher-section-BQ4hVqWo.js → jira-watcher-section-VyzVbAnw.js} +1 -1
  62. package/dist/web/assets/{key-round-CQpDrDxg.js → key-round-oIll4vo-.js} +1 -1
  63. package/dist/web/assets/keybindings-store-B5dEz0n1.js +1 -0
  64. package/dist/web/assets/{keyboard-DiOYrs6C.js → keyboard-BLwfiRkT.js} +1 -1
  65. package/dist/web/assets/{keyboard-shortcuts-section-BZUYdXGx.js → keyboard-shortcuts-section-DOJi75mV.js} +1 -1
  66. package/dist/web/assets/{lib-el9rA30D.js → lib-BAsciSLw.js} +1 -1
  67. package/dist/web/assets/loader-circle-DxI3O9_f.js +1 -0
  68. package/dist/web/assets/markdown-renderer-BGPo364Y.js +1 -0
  69. package/dist/web/assets/markdown-renderer-DtQIHtLs.js +3 -0
  70. package/dist/web/assets/{media-url-BMeBaB0q.js → media-url-TYMlO0M5.js} +1 -1
  71. package/dist/web/assets/{mobile-bottom-sheet-CmySDB6I.js → mobile-bottom-sheet-Ch1e_JBq.js} +1 -1
  72. package/dist/web/assets/mobile-explorer-sheet-C1q_DhrI.js +1 -0
  73. package/dist/web/assets/{monitor-C835ucWH.js → monitor-CG69bSMW.js} +1 -1
  74. package/dist/web/assets/notification-store-DvUtkAXs.js +1 -0
  75. package/dist/web/assets/{notifications-settings-section-JQ3l-Qp-.js → notifications-settings-section-CeRvkXOM.js} +1 -1
  76. package/dist/web/assets/{number-overlay-editor-DRjTIcPH.js → number-overlay-editor-DldrUNs4.js} +1 -1
  77. package/dist/web/assets/{overview-panel-DiiA3B_Z.js → overview-panel-DA0QB1-5.js} +1 -1
  78. package/dist/web/assets/{panel-store-BmdcSBNb.js → panel-store-D42k25jy.js} +1 -1
  79. package/dist/web/assets/{pdf-preview-B-JAU8JV.js → pdf-preview-Cq33D5ej.js} +1 -1
  80. package/dist/web/assets/portal-container-context-DeLx1cOI.js +1 -0
  81. package/dist/web/assets/{postgres-viewer-B--Y59n5.js → postgres-viewer-C__Z0C0s.js} +3 -3
  82. package/dist/web/assets/power-CvtnQHU4.js +1 -0
  83. package/dist/web/assets/{ppmbot-settings-section-D1SCOc0_.js → ppmbot-settings-section-Cma4VU7p.js} +1 -1
  84. package/dist/web/assets/{process-table-D9z7cEmb.js → process-table-DH_HXtGc.js} +1 -1
  85. package/dist/web/assets/{project-store-wWZ6bjwq.js → project-store-C83MMnlt.js} +1 -1
  86. package/dist/web/assets/{proxy-settings-section-y7VwH0Hf.js → proxy-settings-section-xrTsFlTF.js} +1 -1
  87. package/dist/web/assets/{query-audit-section-Ca_gRQ_s.js → query-audit-section-Drk97gb8.js} +1 -1
  88. package/dist/web/assets/{react-D1Yg256j.js → react-DqIU0LFM.js} +1 -1
  89. package/dist/web/assets/remote-desktop-mobile-sheet-6JdUr0Bj.js +2 -0
  90. package/dist/web/assets/{remote-desktop-mobile-view-CGQ8vSf1.js → remote-desktop-mobile-view-Gk8UCVIx.js} +1 -1
  91. package/dist/web/assets/{remote-desktop-readiness-gate-BmC3b05e.js → remote-desktop-readiness-gate-6reSZvad.js} +1 -1
  92. package/dist/web/assets/{remote-desktop-window-content-Cdaoltdz.js → remote-desktop-window-content-BW2KqONI.js} +1 -1
  93. package/dist/web/assets/{run-in-terminal-wHKwAnWP.js → run-in-terminal-DoTOtgQS.js} +1 -1
  94. package/dist/web/assets/{save-CipGrG1k.js → save-B1y4KIK9.js} +1 -1
  95. package/dist/web/assets/{schedules-settings-section--0s10CfA.js → schedules-settings-section-DcKEz-S7.js} +1 -1
  96. package/dist/web/assets/{send-Bb0jtcR6.js → send-B9VUQlEK.js} +1 -1
  97. package/dist/web/assets/{send-to-chat-BI7-fFpG.js → send-to-chat-Kl-0dNwN.js} +1 -1
  98. package/dist/web/assets/{separator-W_hJcXPk.js → separator-DvCsdlws.js} +1 -1
  99. package/dist/web/assets/{settings-body-DEMqFm5z.js → settings-body-CcKls51a.js} +2 -2
  100. package/dist/web/assets/{settings-store-CzLnTR8p.js → settings-store-_s4xFcFq.js} +2 -2
  101. package/dist/web/assets/settings-tab-ChAk8nh2.js +1 -0
  102. package/dist/web/assets/settings-window-content-sA1K0cPW.js +1 -0
  103. package/dist/web/assets/{shield-check-BsG3LV8i.js → shield-check-BJSX7cAS.js} +1 -1
  104. package/dist/web/assets/{shield-off-7jKWpJBD.js → shield-off-E1cQwXdc.js} +1 -1
  105. package/dist/web/assets/{sparkles-Dh-_J2Rd.js → sparkles-blTKn0vi.js} +1 -1
  106. package/dist/web/assets/{sql-query-editor-Clo90z8-.js → sql-query-editor-BoYxc5vd.js} +1 -1
  107. package/dist/web/assets/{sqlite-viewer-C08QQR_L.js → sqlite-viewer-O5lF3MMj.js} +1 -1
  108. package/dist/web/assets/{streaming-store-9XVmAMfV.js → streaming-store-QQvg1cS-.js} +1 -1
  109. package/dist/web/assets/{system-monitor-body-30-TFH3a.js → system-monitor-body-C2mVJ7PV.js} +2 -2
  110. package/dist/web/assets/system-monitor-tab-tXkg3jpV.js +1 -0
  111. package/dist/web/assets/system-monitor-window-content-BaKoFDEz.js +1 -0
  112. package/dist/web/assets/{tab-host-window-content-C6eG_Rf1.js → tab-host-window-content-C7F6D8hJ.js} +1 -1
  113. package/dist/web/assets/{tab-store-1xYJb0gM.js → tab-store-B2ip0-Mv.js} +1 -1
  114. package/dist/web/assets/{table-CRJsmfeg.js → table-8HT8BG30.js} +1 -1
  115. package/dist/web/assets/team-member-sheet-BA70_jmM.js +2 -0
  116. package/dist/web/assets/{team-member-window-content-BN3luct-.js → team-member-window-content-BwOTsc9r.js} +1 -1
  117. package/dist/web/assets/{terminal-tab-afylLiLY.js → terminal-tab-DlZW3MCn.js} +1 -1
  118. package/dist/web/assets/{text-wrap-oiekm5SB.js → text-wrap-DafY0-Pa.js} +1 -1
  119. package/dist/web/assets/{tool-cards-Ct1QdT8c.js → tool-cards-yiwO861p.js} +3 -3
  120. package/dist/web/assets/{use-accounts-data-C0bvcMhi.js → use-accounts-data-B9t4BQaI.js} +1 -1
  121. package/dist/web/assets/{use-blob-url-CrwoZJUJ.js → use-blob-url-D358Rpyp.js} +1 -1
  122. package/dist/web/assets/{use-coarse-long-press-BmI_GVW5.js → use-coarse-long-press-BsBpxWup.js} +1 -1
  123. package/dist/web/assets/{use-inline-blame-C1G-_NjC.js → use-inline-blame-D2pZjDoA.js} +1 -1
  124. package/dist/web/assets/{use-is-mobile-D1weanbj.js → use-is-mobile-Bi42QhIi.js} +1 -1
  125. package/dist/web/assets/{use-monaco-theme-cgPbRDUm.js → use-monaco-theme-DTPfPPvF.js} +1 -1
  126. package/dist/web/assets/use-open-team-member-DGEx9xB0.js +1 -0
  127. package/dist/web/assets/{use-remote-desktop-display-choice-DSqF1Rgx.js → use-remote-desktop-display-choice-BnVT4dhX.js} +1 -1
  128. package/dist/web/assets/{use-visual-viewport-Bfl3Bxxb.js → use-visual-viewport-CNdG4QHH.js} +1 -1
  129. package/dist/web/assets/use-websocket-DQg9BQcq.js +1 -0
  130. package/dist/web/assets/{vendor-markdown-Ls5AcU91.js → vendor-markdown-CuWCHIVb.js} +1 -1
  131. package/dist/web/assets/{vendor-ui-CaeeFO0B.js → vendor-ui-BBdkypKW.js} +1 -1
  132. package/dist/web/assets/{video-preview-BTzstVhM.js → video-preview-Dc4YbBqm.js} +1 -1
  133. package/dist/web/assets/{window-pip-registry-CrCYYTTf.js → window-pip-registry-BWxaVLj5.js} +1 -1
  134. package/dist/web/assets/{window-store-D0HbQ1pM.js → window-store-CfxP5yor.js} +1 -1
  135. package/dist/web/assets/ws-auth-FRzMmfQx.js +1 -0
  136. package/dist/web/assets/x-Bdaog6Az.js +1 -0
  137. package/dist/web/index.html +38 -38
  138. package/dist/web/sw.js +1 -1
  139. package/docs/architecture/ai-chat-and-providers.md +4 -0
  140. package/package.json +1 -1
  141. package/src/services/db.service.ts +18 -4
  142. package/src/web/components/shared/markdown-context.ts +6 -0
  143. package/src/web/components/shared/markdown-renderer.tsx +7 -3
  144. package/src/web/hooks/use-chat.ts +4 -0
  145. package/src/web/hooks/use-websocket.ts +7 -1
  146. package/dist/web/assets/ai-settings-section-BePrVceb.js +0 -1
  147. package/dist/web/assets/api-client-QfreGirP.js +0 -1
  148. package/dist/web/assets/arrow-left-CyFcsyzD.js +0 -1
  149. package/dist/web/assets/check-DN75Ucvz.js +0 -1
  150. package/dist/web/assets/chevron-right-De-Wz5Lz.js +0 -1
  151. package/dist/web/assets/circle-BCy0AUCo.js +0 -1
  152. package/dist/web/assets/clock-C1CQUQPZ.js +0 -1
  153. package/dist/web/assets/code-DJgYrFzm.js +0 -1
  154. package/dist/web/assets/explorer-window-content-VSMJfZC2.js +0 -1
  155. package/dist/web/assets/keybindings-store-yYx88hvw.js +0 -1
  156. package/dist/web/assets/loader-circle-DPMrnLQ2.js +0 -1
  157. package/dist/web/assets/markdown-renderer-BA3C2L-a.js +0 -3
  158. package/dist/web/assets/markdown-renderer-CMFkajd7.js +0 -1
  159. package/dist/web/assets/mobile-explorer-sheet-gvO7a80O.js +0 -1
  160. package/dist/web/assets/notification-store-CCh6a8RD.js +0 -1
  161. package/dist/web/assets/portal-container-context-DKymYOY-.js +0 -1
  162. package/dist/web/assets/power-CriQkeK5.js +0 -1
  163. package/dist/web/assets/remote-desktop-mobile-sheet-CdO2aMXl.js +0 -2
  164. package/dist/web/assets/settings-tab-Dh1FpBny.js +0 -1
  165. package/dist/web/assets/settings-window-content-3KrQ6imZ.js +0 -1
  166. package/dist/web/assets/system-monitor-tab-ChIXfOWg.js +0 -1
  167. package/dist/web/assets/system-monitor-window-content-C1Cd_pT7.js +0 -1
  168. package/dist/web/assets/team-member-sheet-BhatQbL1.js +0 -2
  169. package/dist/web/assets/use-open-team-member-CSUU7Z8N.js +0 -1
  170. package/dist/web/assets/use-websocket-BQssVSIR.js +0 -1
  171. package/dist/web/assets/ws-auth-D111jj32.js +0 -1
  172. package/dist/web/assets/x-CxoBA0po.js +0 -1
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{S as t,x as n}from"./vendor-markdown-Ls5AcU91.js";import"./vendor-ui-CaeeFO0B.js";import{t as r}from"./chevron-down-Dp0rpHb8.js";import{t as i}from"./chevron-right-De-Wz5Lz.js";import{t as a}from"./x-CxoBA0po.js";import{r as o,s}from"./api-client-CEYCBt_0.js";import{n as c}from"./utils-IrnQujwR.js";import"./portal-container-context-DKymYOY-.js";import{n as l}from"./use-is-mobile-D1weanbj.js";import{t as u}from"./button-DX32ffge.js";import{t as d}from"./mobile-bottom-sheet-CmySDB6I.js";import"./use-visual-viewport-Bfl3Bxxb.js";import{$t as f,Br as p,Ft as m,G as h,Vr as g,Xt as _,Yt as v,en as y,qn as b}from"./index-Cx1meAwb.js";import{n as x,t as S}from"./format-bytes-Bc6SqF7M.js";var C=e(t(),1);function w(e,t){return{cpu:e.cpu,ramMB:e.ramMB,name:t,diskReadBps:e.diskReadBps,diskWriteBps:e.diskWriteBps,gpuPct:e.gpuPct,gpuMemMB:e.gpuMemMB,netInBps:e.netInBps,netOutBps:e.netOutBps}}function T(e,t){if(!(e===void 0&&t===void 0))return(e??0)+(t??0)}function E(e,t){return e===`disk`?T(t.diskReadBps,t.diskWriteBps):e===`net`?T(t.netInBps,t.netOutBps):e===`gpu`?t.gpuPct:t.gpuMemMB}function D(e){return e===`disk`||e===`gpu`||e===`gpuMem`||e===`net`}function O(e,t,n,r){return t?[...e].sort((e,i)=>{let a=r(e),o=r(i);if(t===`name`){let e=a.name.localeCompare(o.name);return n===`asc`?e:-e}if(t===`cpu`)return n===`asc`?a.cpu-o.cpu:o.cpu-a.cpu;if(t===`ram`)return n===`asc`?a.ramMB-o.ramMB:o.ramMB-a.ramMB;if(D(t)){let e=E(t,a),r=E(t,o);return e===void 0&&r===void 0?0:e===void 0?1:r===void 0?-1:n===`asc`?e-r:r-e}return 0}):e}var k={cpu:0,ramMB:0,count:0};function A(e,t){return t===void 0?e:(e??0)+t}function j(e,t,n){return{cpu:e.cpu+t.cpu,ramMB:e.ramMB+t.ramMB,count:e.count+n,diskReadBps:A(e.diskReadBps,t.diskReadBps),diskWriteBps:A(e.diskWriteBps,t.diskWriteBps),gpuMemMB:A(e.gpuMemMB,t.gpuMemMB),netInBps:A(e.netInBps,t.netInBps),netOutBps:A(e.netOutBps,t.netOutBps)}}function M(e,t){return e.toLowerCase().includes(t)}function N(e,t){return M(e.name,t)||M(e.command,t)}function ee(e){let{processes:t,groups:n,mode:r,ppmOnly:i,query:a,sortKey:o,sortDir:s,expanded:c}=e,l=a.trim().toLowerCase(),u=new Map(t.map(e=>[e.pid,e]));if(r===`flat`){let e=i?t.filter(e=>e.ppm):t;l&&(e=e.filter(e=>N(e,l))),e=O(e,o,s,e=>w(e,e.name));let n=e.reduce((e,t)=>j(e,t,1),k);return{rows:e.map(e=>({kind:`process`,proc:e,indent:!1})),totals:n,autoExpanded:new Set}}let d=i?n.filter(e=>e.ppm):n,f=new Set;l&&(d=d.filter(e=>{let t=M(e.label,l),n=e.pids.some(e=>{let t=u.get(e);return t?N(t,l):!1}),r=t||n;return r&&n&&f.add(e.key),r})),d=O(d,o,s,e=>w(e,e.label));let p=[];for(let e of d){let t=l&&f.has(e.key)||c.has(e.key);if(p.push({kind:`group`,group:e,expanded:t}),!t)continue;let n=e.pids.map(e=>u.get(e)).filter(e=>e!==void 0);l&&(n=n.filter(e=>N(e,l))),n=O(n,o,s,e=>w(e,e.name));for(let e of n)p.push({kind:`process`,proc:e,indent:!0})}return{rows:p,totals:d.reduce((e,t)=>j(e,t,t.count),k),autoExpanded:f}}function te(e,t,n){return e===n?t===`desc`?[n,`asc`]:[null,`desc`]:[n,`desc`]}var P=[`disk`,`gpu`,`net`],ne={cpu:64,ram:80,disk:120,gpu:90,net:120},F=`minmax(0,1fr)`,I=`44px`;function re(e){return e===`disk`||e===`gpu`||e===`net`}function L(e){return Math.round(Math.min(400,Math.max(48,e)))}function R(e,t){let n=t[e];return typeof n==`number`&&Number.isFinite(n)?L(n):ne[e]}function ie(e,t,n={}){let r=P.filter(t=>e[t]),i=re(t)&&e[t]?t:null,a=e=>`${R(e,n)}px`,o=[F,a(`cpu`),a(`ram`)];return{wideTemplate:[...o,...r.map(a),I].join(` `),narrowTemplate:[...o,...i?[a(i)]:[],I].join(` `),columns:e,narrowExtra:i}}var z=`grid-cols-[var(--sysmon-grid-n)] @lg:grid-cols-[var(--sysmon-grid-w)]`;function B(e){return{"--sysmon-grid-n":e.narrowTemplate,"--sysmon-grid-w":e.wideTemplate}}function V(e,t){return e.narrowExtra===t?`block`:`hidden @lg:block`}function H(e){return e>80?`text-error`:e>50?`text-warning`:`text-success`}function ae(e){if(!e)return``;let t=Math.round((Date.now()-e)/1e3);if(t<60)return`${t}s`;let n=Math.floor(t/60);if(n<60)return`${n}m`;let r=Math.floor(n/60);return r<24?`${r}h ${n%60}m`:`${Math.floor(r/24)}d ${r%24}h`}function U(e,t){return e===void 0&&t===void 0?`—`:`↓ ${S(e??0)} ↑ ${S(t??0)}`}function W(e,t){return e===void 0&&t===void 0?`—`:`↓ ${S(e??0)} ↑ ${S(t??0)}`}function G(e,t){return e===void 0&&t===void 0?`—`:`${e===void 0?`—`:`${e.toFixed(0)}%`} · ${t===void 0?`—`:x(t)}`}function K(e,t){if(!(e===void 0&&t===void 0))return(e??0)+(t??0)}var q=n();function J({label:e,field:t,activeKey:n,activeDir:r,onClick:i,align:a=`right`,testId:o,className:s,resizeKey:l,resize:u}){let d=n===t,f=d?r===`asc`?p:g:null,m=d?r===`asc`?`ascending`:`descending`:`none`;return(0,q.jsxs)(`div`,{role:`columnheader`,"aria-sort":m,className:c(`relative py-1.5 px-2 font-medium select-none`,a===`left`?`text-left`:`text-right`,s),children:[(0,q.jsxs)(`button`,{type:`button`,"data-testid":o,onClick:()=>i(t),className:c(`flex items-center gap-0.5 w-full min-h-11 md:min-h-0 cursor-pointer hover:text-text-primary transition-colors`,a===`left`?`justify-start`:`justify-end`,d&&`text-text-primary`),children:[(0,q.jsx)(`span`,{className:`truncate`,children:e}),f&&(0,q.jsx)(f,{className:`size-3 shrink-0`})]}),l&&u&&(0,q.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize ${e} column`,"data-testid":o?`${o}-resize`:void 0,onPointerDown:e=>u.onResizeStart(l,e),onDoubleClick:()=>u.onResizeReset(l),className:`hidden md:block absolute top-0 -right-1 h-full w-2 cursor-col-resize hover:bg-primary/40 active:bg-primary/60`})]})}var oe=150;function se({mode:e,onModeChange:t,ppmOnly:n,onPpmOnlyChange:r,onQueryChange:i}){let[a,o]=(0,C.useState)(``),s=(0,C.useRef)(null);return(0,C.useEffect)(()=>(s.current&&clearTimeout(s.current),s.current=setTimeout(()=>i(a),oe),()=>{s.current&&clearTimeout(s.current)}),[a]),(0,q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 p-2 border-b border-border shrink-0`,children:[(0,q.jsxs)(`div`,{className:`relative flex-1 min-w-[140px]`,children:[(0,q.jsx)(b,{className:`absolute left-2 top-1/2 -translate-y-1/2 size-3.5 text-text-subtle`}),(0,q.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),placeholder:`Search processes`,"aria-label":`Search processes`,"data-testid":`sysmon-process-search`,className:`w-full min-h-11 md:min-h-8 pl-7 pr-2 text-sm rounded-md border border-border bg-transparent focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`})]}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>t(e===`grouped`?`flat`:`grouped`),"aria-pressed":e===`flat`,"data-testid":`sysmon-toggle-flat`,className:`min-h-11 md:min-h-8 px-3 text-xs rounded-md border border-border hover:bg-surface-hover transition-colors`,children:e===`flat`?`Flat`:`Grouped`}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>r(!n),"aria-pressed":n,"data-testid":`sysmon-filter-ppm`,className:c(`min-h-11 md:min-h-8 px-3 text-xs rounded-md border transition-colors`,n?`border-primary bg-primary/10 text-primary`:`border-border hover:bg-surface-hover`),children:`PPM only`})]})}function ce({sortKey:e,sortDir:t,grid:n,onSort:r,resize:i}){let a={activeKey:e,activeDir:t,onClick:r,resize:i};return(0,q.jsxs)(`div`,{role:`row`,className:c(`grid gap-1 px-3 py-1.5 text-[11px] text-text-subtle border-b border-border sticky top-0 bg-background z-10`,z),children:[(0,q.jsx)(J,{label:`Process`,field:`name`,...a,resize:void 0,align:`left`,testId:`sysmon-sort-name`}),(0,q.jsx)(J,{label:`CPU`,field:`cpu`,...a,resizeKey:`cpu`,testId:`sysmon-sort-cpu`}),(0,q.jsx)(J,{label:`RAM`,field:`ram`,...a,resizeKey:`ram`,testId:`sysmon-sort-ram`}),n.columns.disk&&(0,q.jsx)(J,{label:`Disk`,field:`disk`,...a,resizeKey:`disk`,testId:`sysmon-col-disk`,className:V(n,`disk`)}),n.columns.gpu&&(0,q.jsx)(J,{label:`GPU`,field:`gpu`,...a,resizeKey:`gpu`,testId:`sysmon-col-gpu`,className:V(n,`gpu`)}),n.columns.net&&(0,q.jsx)(J,{label:`Net`,field:`net`,...a,resizeKey:`net`,testId:`sysmon-col-net`,className:V(n,`net`)}),(0,q.jsx)(`span`,{})]})}function le({totals:e,grid:t,gpuUtilPercent:n}){return(0,q.jsxs)(`div`,{className:c(`grid gap-1 px-3 py-1.5 text-xs font-medium border-t border-border shrink-0`,z),"data-testid":`sysmon-total`,"data-process-count":e.count,children:[(0,q.jsxs)(`span`,{className:`truncate`,children:[`Total (`,e.count,` processes)`]}),(0,q.jsxs)(`span`,{className:c(`text-right`,H(e.cpu)),children:[e.cpu.toFixed(1),`%`]}),(0,q.jsx)(`span`,{className:`text-right text-text-secondary`,children:x(e.ramMB)}),t.columns.disk&&(0,q.jsx)(`span`,{className:c(`text-right text-text-secondary tabular-nums truncate`,V(t,`disk`)),children:U(e.diskReadBps,e.diskWriteBps)}),t.columns.gpu&&(0,q.jsx)(`span`,{className:c(`text-right text-text-secondary tabular-nums truncate`,V(t,`gpu`)),children:G(n,e.gpuMemMB)}),t.columns.net&&(0,q.jsx)(`span`,{className:c(`text-right text-text-secondary tabular-nums truncate`,V(t,`net`)),children:W(e.netInBps,e.netOutBps)}),(0,q.jsx)(`span`,{})]})}var ue=`Protected: this app contains a PPM or OS-critical process — cannot be ended as a whole.`;function de({group:e,expanded:t,grid:n,killProtected:o,onToggle:s,onKillClick:l}){let u=t?r:i;return(0,q.jsxs)(`div`,{className:`grid items-center gap-1 min-h-11 md:min-h-7 px-3 text-xs cursor-pointer hover:bg-surface-hover transition-colors group/proc grid-cols-[var(--sysmon-grid-n)] @lg:grid-cols-[var(--sysmon-grid-w)]`,onClick:()=>s(e.key),"data-testid":`sysmon-group-row`,"data-group-key":e.key,"data-count":e.count,"data-disk-bps":K(e.diskReadBps,e.diskWriteBps),"data-gpu-pct":e.gpuPct,"data-net-bps":K(e.netInBps,e.netOutBps),children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,q.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s(e.key)},"aria-expanded":t,"aria-label":`${t?`Collapse`:`Expand`} ${e.label}`,"data-testid":`sysmon-group-expand`,className:`flex items-center justify-center size-11 md:size-7 -ml-2 shrink-0`,children:(0,q.jsx)(u,{className:`size-3.5 text-text-subtle`})}),(0,q.jsx)(`span`,{className:`truncate font-medium`,children:e.label}),(0,q.jsxs)(`span`,{className:`text-text-subtle shrink-0`,children:[`(`,e.count,`)`]})]}),(0,q.jsxs)(`span`,{className:c(`text-right`,H(e.cpu)),children:[e.cpu.toFixed(1),`%`]}),(0,q.jsx)(`span`,{className:`text-right text-text-secondary`,children:x(e.ramMB)}),n.columns.disk&&(0,q.jsx)(`span`,{className:c(`text-right text-text-secondary tabular-nums truncate`,V(n,`disk`)),children:U(e.diskReadBps,e.diskWriteBps)}),n.columns.gpu&&(0,q.jsx)(`span`,{className:c(`text-right text-text-secondary tabular-nums truncate`,V(n,`gpu`)),children:G(e.gpuPct,e.gpuMemMB)}),n.columns.net&&(0,q.jsx)(`span`,{className:c(`text-right text-text-secondary tabular-nums truncate`,V(n,`net`)),children:W(e.netInBps,e.netOutBps)}),(0,q.jsx)(`div`,{className:`flex justify-end`,children:(0,q.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),l(e)},disabled:o,"aria-label":`End ${e.label} and its ${e.count} processes`,title:o?ue:`End ${e.label} (${e.count} processes)`,"data-testid":`sysmon-group-kill-btn`,className:c(`flex items-center justify-center size-11 md:size-7 rounded transition-all`,`can-hover:opacity-0 can-hover:group-hover/proc:opacity-100`,o?`opacity-40 cursor-not-allowed`:`hover:bg-error/20 hover:text-error active:bg-error/30`),children:(0,q.jsx)(a,{className:`size-3.5`})})})]})}var fe=`Protected: PPM or OS-critical process — cannot be ended.`;function pe({proc:e,indent:t,grid:n,onKillClick:r}){return(0,q.jsxs)(`div`,{className:`grid items-center gap-1 min-h-11 md:min-h-7 px-3 text-xs group/proc hover:bg-surface-hover transition-colors grid-cols-[var(--sysmon-grid-n)] @lg:grid-cols-[var(--sysmon-grid-w)]`,"data-testid":`sysmon-process-row`,"data-pid":e.pid,"data-ppm":e.ppm,"data-protected":e.protected,"data-disk-bps":K(e.diskReadBps,e.diskWriteBps),"data-gpu-pct":e.gpuPct,"data-net-bps":K(e.netInBps,e.netOutBps),children:[(0,q.jsxs)(`div`,{className:c(`flex items-start gap-1.5 min-w-0`,t&&`pl-6`),children:[(0,q.jsx)(`span`,{className:`text-text-subtle shrink-0`,children:e.pid}),(0,q.jsx)(`span`,{className:`truncate text-text-secondary`,title:e.startedAt?`${e.command}\nRunning ${ae(e.startedAt)}`:e.command,children:e.command})]}),(0,q.jsxs)(`span`,{className:c(`text-right`,H(e.cpu)),children:[e.cpu.toFixed(1),`%`]}),(0,q.jsx)(`span`,{className:`text-right text-text-secondary`,children:x(e.ramMB)}),n.columns.disk&&(0,q.jsx)(`span`,{className:c(`text-right text-text-secondary tabular-nums truncate`,V(n,`disk`)),children:U(e.diskReadBps,e.diskWriteBps)}),n.columns.gpu&&(0,q.jsx)(`span`,{className:c(`text-right text-text-secondary tabular-nums truncate`,V(n,`gpu`)),children:G(e.gpuPct,e.gpuMemMB)}),n.columns.net&&(0,q.jsx)(`span`,{className:c(`text-right text-text-secondary tabular-nums truncate`,V(n,`net`)),children:W(e.netInBps,e.netOutBps)}),(0,q.jsx)(`div`,{className:`flex justify-end`,children:(0,q.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),r(e)},disabled:e.protected,"aria-label":`End process ${e.name} (${e.pid})`,title:e.protected?fe:`End process ${e.name}`,"data-testid":`sysmon-kill-btn`,className:c(`flex items-center justify-center size-11 md:size-7 rounded transition-all`,`can-hover:opacity-0 can-hover:group-hover/proc:opacity-100`,e.protected?`opacity-40 cursor-not-allowed`:`hover:bg-error/20 hover:text-error active:bg-error/30`),children:(0,q.jsx)(a,{className:`size-3.5`})})})]})}function me({target:e,onConfirm:t,onCancel:n}){let r=l(),[i,a]=(0,C.useState)(!1);if((0,C.useEffect)(()=>{e||a(!1)},[e]),!e)return null;let o=e.kind===`group`,s=o?`End app`:`End process`,c=o?e.group.cpu:e.proc.cpu,p=o?e.group.ramMB:e.proc.ramMB,m=(0,q.jsxs)(`div`,{className:`space-y-4`,"data-testid":`sysmon-kill-confirm`,"data-kill-kind":e.kind,children:[o?(0,q.jsxs)(`p`,{className:`text-sm`,children:[`End `,(0,q.jsx)(`span`,{className:`font-medium`,children:e.group.label}),` and all its`,` `,(0,q.jsx)(`span`,{className:`font-medium`,children:e.members.length}),` processes?`]}):(0,q.jsxs)(`p`,{className:`text-sm`,children:[`End `,(0,q.jsx)(`span`,{className:`font-medium`,children:e.proc.name}),` (pid `,e.proc.pid,`)?`]}),(0,q.jsxs)(`p`,{className:`text-xs text-text-subtle`,children:[`CPU `,c.toFixed(1),`% · RAM `,x(p)]}),!o&&(0,q.jsxs)(`label`,{className:`flex items-center justify-between gap-3 min-h-11 py-1`,children:[(0,q.jsx)(`span`,{className:`text-sm`,children:`Also end child processes`}),(0,q.jsx)(h,{checked:i,onCheckedChange:a,"data-testid":`sysmon-kill-tree`,"aria-label":`Also end child processes`})]}),(0,q.jsxs)(`div`,{className:`flex flex-col-reverse md:flex-row gap-2 md:justify-end pt-2`,children:[(0,q.jsx)(u,{variant:`outline`,onClick:n,"data-testid":`sysmon-kill-confirm-cancel`,className:`min-h-11`,children:`Cancel`}),(0,q.jsx)(u,{variant:`destructive`,autoFocus:!1,onClick:()=>t(e,i),"data-testid":`sysmon-kill-confirm-ok`,className:`min-h-11`,children:o?`End ${e.members.length} processes`:`End process`})]})]});return r?(0,q.jsx)(d,{open:!0,onClose:n,children:(0,q.jsxs)(`div`,{className:`px-4 pb-4`,children:[(0,q.jsx)(`h2`,{className:`text-base font-semibold mb-3`,children:s}),m]})}):(0,q.jsx)(v,{open:!0,onOpenChange:e=>!e&&n(),children:(0,q.jsxs)(_,{children:[(0,q.jsx)(f,{children:(0,q.jsx)(y,{children:s})}),m]})})}function Y(e,t){return{pid:e.pid,startedAt:e.startedAt,tree:t}}function he(e,t){let n=e.rootPid===null?void 0:t.find(t=>t.pid===e.rootPid);return n?[Y(n,!0)]:t.map(e=>Y(e,!1))}function ge(e){return e.some(e=>e.protected)}async function X(e){let t=o(),n={"Content-Type":`application/json`,"X-PPM-Request":`1`};t&&(n.Authorization=`Bearer ${t}`);let r=await fetch(`/api/system/resources/kill`,{method:`POST`,headers:n,body:JSON.stringify(e)}),i;try{i=await r.json()}catch{throw Error(r.ok?`Empty response from server`:`Server error (HTTP ${r.status})`)}if(i.ok===!1)throw Error(i.error??`HTTP ${r.status}`);return i.data}function _e(e){let[t,n]=(0,C.useState)(null),r=(0,C.useCallback)(t=>{let n=new Map(e.processes.map(e=>[e.pid,e]));return t.pids.map(e=>n.get(e)).filter(e=>!!e)},[e.processes]),i=(0,C.useMemo)(()=>new Map(e.groups.map(e=>[e.key,ge(r(e))])),[e.groups,r]),a=(0,C.useCallback)(e=>n({kind:`process`,proc:e}),[]),o=(0,C.useCallback)(e=>n({kind:`group`,group:e,members:r(e)}),[r]),c=(0,C.useCallback)(()=>n(null),[]);return{pendingKill:t,groupProtected:i,requestKillProcess:a,requestKillGroup:o,confirmKill:(0,C.useCallback)(async(e,t)=>{if(n(null),e.kind===`process`){let{proc:n}=e;try{await X(Y(n,t)),s.success(`Ended ${n.name} (${n.pid})`)}catch(e){s.error(e instanceof Error?e.message:`Failed to end ${n.name}`)}return}let{group:r,members:i}=e,a=[];for(let e of he(r,i))try{await X(e)}catch(t){a.push(t instanceof Error?t.message:`pid ${e.pid}`)}a.length===0?s.success(`Ended ${r.label} (${i.length} processes)`):s.error(`${r.label}: ${a.length} of ${i.length} could not be ended — ${a[0]}`)},[]),cancelKill:c}}var Z=`ppm-sysmon-col-widths`;function Q(){try{let e=localStorage.getItem(Z);if(!e)return{};let t=JSON.parse(e),n={};for(let e of[`cpu`,`ram`,`disk`,`gpu`,`net`]){let r=t[e];typeof r==`number`&&Number.isFinite(r)&&(n[e]=L(r))}return n}catch{return{}}}function $(e){try{Object.keys(e).length===0?localStorage.removeItem(Z):localStorage.setItem(Z,JSON.stringify(e))}catch{}}function ve(){let[e,t]=(0,C.useState)(()=>typeof localStorage>`u`?{}:Q()),n=(0,C.useRef)(null);return(0,C.useEffect)(()=>{let e=e=>{let r=n.current;if(!r)return;let i=L(r.startWidth+(e.clientX-r.startX));t(e=>e[r.key]===i?e:{...e,[r.key]:i})},r=()=>{n.current&&(n.current=null,document.body.style.cursor=``,t(e=>($(e),e)))};return window.addEventListener(`pointermove`,e),window.addEventListener(`pointerup`,r),window.addEventListener(`pointercancel`,r),()=>{window.removeEventListener(`pointermove`,e),window.removeEventListener(`pointerup`,r),window.removeEventListener(`pointercancel`,r)}},[]),{widths:e,begin:(0,C.useCallback)((t,r)=>{r.preventDefault(),n.current={key:t,startX:r.clientX,startWidth:R(t,e)},document.body.style.cursor=`col-resize`},[e]),reset:(0,C.useCallback)(e=>{t(t=>{if(!(e in t))return t;let{[e]:n,...r}=t;return $(r),r})},[])}}var ye={disk:!1,gpu:!1,net:!1};function be({snapshot:e}){let t=l(),n=(0,C.useRef)(null),[r,i]=(0,C.useState)(`grouped`),[a,o]=(0,C.useState)(!1),[s,c]=(0,C.useState)(``),[u,d]=(0,C.useState)(null),[f,p]=(0,C.useState)(`desc`),[h,g]=(0,C.useState)(()=>new Set),{pendingKill:_,groupProtected:v,requestKillProcess:y,requestKillGroup:b,confirmKill:x,cancelKill:S}=_e(e),{widths:w,begin:T,reset:E}=ve(),{rows:D,totals:O}=(0,C.useMemo)(()=>ee({processes:e.processes,groups:e.groups,mode:r,ppmOnly:a,query:s,sortKey:u,sortDir:f,expanded:h}),[e.processes,e.groups,r,a,s,u,f,h]),k=e.processColumns??ye,A=(0,C.useMemo)(()=>ie(k,u,w),[k,u,w]),j=e.system.gpus[0]?.utilPercent,M=m({count:D.length,getScrollElement:()=>n.current,estimateSize:()=>t?44:28,overscan:12}),N=(0,C.useCallback)(e=>{let[t,n]=te(u,f,e);d(t),p(n)},[u,f]),P=(0,C.useCallback)(e=>{g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]);return(0,q.jsxs)(`div`,{className:`h-full flex flex-col min-h-0 @container`,style:B(A),"data-testid":`sysmon-processes`,"data-row-count":D.length,children:[(0,q.jsx)(se,{mode:r,onModeChange:i,ppmOnly:a,onPpmOnlyChange:o,onQueryChange:c}),(0,q.jsx)(ce,{sortKey:u,sortDir:f,grid:A,onSort:N,resize:{onResizeStart:T,onResizeReset:E}}),(0,q.jsx)(`div`,{ref:n,className:`flex-1 min-h-0 overflow-y-auto`,children:(0,q.jsx)(`div`,{style:{height:M.getTotalSize(),position:`relative`},children:M.getVirtualItems().map(e=>{let t=D[e.index];return t?(0,q.jsx)(`div`,{style:{position:`absolute`,top:0,left:0,right:0,transform:`translateY(${e.start}px)`},children:t.kind===`group`?(0,q.jsx)(de,{group:t.group,expanded:t.expanded,grid:A,killProtected:v.get(t.group.key)??!0,onToggle:P,onKillClick:b}):(0,q.jsx)(pe,{proc:t.proc,indent:t.indent,grid:A,onKillClick:y})},t.kind===`group`?t.group.key:`p:${t.proc.pid}`):null})})}),(0,q.jsx)(le,{totals:O,grid:A,gpuUtilPercent:j}),(0,q.jsx)(me,{target:_,onConfirm:x,onCancel:S})]})}export{be as ProcessTable};
1
+ import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{C as t,S as n}from"./vendor-markdown-CuWCHIVb.js";import"./vendor-ui-BBdkypKW.js";import{t as r}from"./chevron-down-B9puixxZ.js";import{t as i}from"./chevron-right-DK_HbYZC.js";import{t as a}from"./x-Bdaog6Az.js";import{r as o,s}from"./api-client-DwXlVfXP.js";import{n as c}from"./utils-IrnQujwR.js";import"./portal-container-context-DeLx1cOI.js";import{n as l}from"./use-is-mobile-Bi42QhIi.js";import{t as u}from"./button-zgoXa9r7.js";import{t as d}from"./mobile-bottom-sheet-Ch1e_JBq.js";import"./use-visual-viewport-CNdG4QHH.js";import{$t as f,Br as p,Ft as m,G as h,Vr as g,Xt as _,Yt as v,en as y,qn as b}from"./index-DVNJ2W5R.js";import{n as x,t as S}from"./format-bytes-Bc6SqF7M.js";var C=e(t(),1);function w(e,t){return{cpu:e.cpu,ramMB:e.ramMB,name:t,diskReadBps:e.diskReadBps,diskWriteBps:e.diskWriteBps,gpuPct:e.gpuPct,gpuMemMB:e.gpuMemMB,netInBps:e.netInBps,netOutBps:e.netOutBps}}function T(e,t){if(!(e===void 0&&t===void 0))return(e??0)+(t??0)}function E(e,t){return e===`disk`?T(t.diskReadBps,t.diskWriteBps):e===`net`?T(t.netInBps,t.netOutBps):e===`gpu`?t.gpuPct:t.gpuMemMB}function D(e){return e===`disk`||e===`gpu`||e===`gpuMem`||e===`net`}function O(e,t,n,r){return t?[...e].sort((e,i)=>{let a=r(e),o=r(i);if(t===`name`){let e=a.name.localeCompare(o.name);return n===`asc`?e:-e}if(t===`cpu`)return n===`asc`?a.cpu-o.cpu:o.cpu-a.cpu;if(t===`ram`)return n===`asc`?a.ramMB-o.ramMB:o.ramMB-a.ramMB;if(D(t)){let e=E(t,a),r=E(t,o);return e===void 0&&r===void 0?0:e===void 0?1:r===void 0?-1:n===`asc`?e-r:r-e}return 0}):e}var k={cpu:0,ramMB:0,count:0};function A(e,t){return t===void 0?e:(e??0)+t}function j(e,t,n){return{cpu:e.cpu+t.cpu,ramMB:e.ramMB+t.ramMB,count:e.count+n,diskReadBps:A(e.diskReadBps,t.diskReadBps),diskWriteBps:A(e.diskWriteBps,t.diskWriteBps),gpuMemMB:A(e.gpuMemMB,t.gpuMemMB),netInBps:A(e.netInBps,t.netInBps),netOutBps:A(e.netOutBps,t.netOutBps)}}function M(e,t){return e.toLowerCase().includes(t)}function N(e,t){return M(e.name,t)||M(e.command,t)}function ee(e){let{processes:t,groups:n,mode:r,ppmOnly:i,query:a,sortKey:o,sortDir:s,expanded:c}=e,l=a.trim().toLowerCase(),u=new Map(t.map(e=>[e.pid,e]));if(r===`flat`){let e=i?t.filter(e=>e.ppm):t;l&&(e=e.filter(e=>N(e,l))),e=O(e,o,s,e=>w(e,e.name));let n=e.reduce((e,t)=>j(e,t,1),k);return{rows:e.map(e=>({kind:`process`,proc:e,indent:!1})),totals:n,autoExpanded:new Set}}let d=i?n.filter(e=>e.ppm):n,f=new Set;l&&(d=d.filter(e=>{let t=M(e.label,l),n=e.pids.some(e=>{let t=u.get(e);return t?N(t,l):!1}),r=t||n;return r&&n&&f.add(e.key),r})),d=O(d,o,s,e=>w(e,e.label));let p=[];for(let e of d){let t=l&&f.has(e.key)||c.has(e.key);if(p.push({kind:`group`,group:e,expanded:t}),!t)continue;let n=e.pids.map(e=>u.get(e)).filter(e=>e!==void 0);l&&(n=n.filter(e=>N(e,l))),n=O(n,o,s,e=>w(e,e.name));for(let e of n)p.push({kind:`process`,proc:e,indent:!0})}return{rows:p,totals:d.reduce((e,t)=>j(e,t,t.count),k),autoExpanded:f}}function te(e,t,n){return e===n?t===`desc`?[n,`asc`]:[null,`desc`]:[n,`desc`]}var P=[`disk`,`gpu`,`net`],ne={cpu:64,ram:80,disk:120,gpu:90,net:120},F=`minmax(0,1fr)`,I=`44px`;function re(e){return e===`disk`||e===`gpu`||e===`net`}function L(e){return Math.round(Math.min(400,Math.max(48,e)))}function R(e,t){let n=t[e];return typeof n==`number`&&Number.isFinite(n)?L(n):ne[e]}function ie(e,t,n={}){let r=P.filter(t=>e[t]),i=re(t)&&e[t]?t:null,a=e=>`${R(e,n)}px`,o=[F,a(`cpu`),a(`ram`)];return{wideTemplate:[...o,...r.map(a),I].join(` `),narrowTemplate:[...o,...i?[a(i)]:[],I].join(` `),columns:e,narrowExtra:i}}var z=`grid-cols-[var(--sysmon-grid-n)] @lg:grid-cols-[var(--sysmon-grid-w)]`;function B(e){return{"--sysmon-grid-n":e.narrowTemplate,"--sysmon-grid-w":e.wideTemplate}}function V(e,t){return e.narrowExtra===t?`block`:`hidden @lg:block`}function H(e){return e>80?`text-error`:e>50?`text-warning`:`text-success`}function ae(e){if(!e)return``;let t=Math.round((Date.now()-e)/1e3);if(t<60)return`${t}s`;let n=Math.floor(t/60);if(n<60)return`${n}m`;let r=Math.floor(n/60);return r<24?`${r}h ${n%60}m`:`${Math.floor(r/24)}d ${r%24}h`}function U(e,t){return e===void 0&&t===void 0?`—`:`↓ ${S(e??0)} ↑ ${S(t??0)}`}function W(e,t){return e===void 0&&t===void 0?`—`:`↓ ${S(e??0)} ↑ ${S(t??0)}`}function G(e,t){return e===void 0&&t===void 0?`—`:`${e===void 0?`—`:`${e.toFixed(0)}%`} · ${t===void 0?`—`:x(t)}`}function K(e,t){if(!(e===void 0&&t===void 0))return(e??0)+(t??0)}var q=n();function J({label:e,field:t,activeKey:n,activeDir:r,onClick:i,align:a=`right`,testId:o,className:s,resizeKey:l,resize:u}){let d=n===t,f=d?r===`asc`?p:g:null,m=d?r===`asc`?`ascending`:`descending`:`none`;return(0,q.jsxs)(`div`,{role:`columnheader`,"aria-sort":m,className:c(`relative py-1.5 px-2 font-medium select-none`,a===`left`?`text-left`:`text-right`,s),children:[(0,q.jsxs)(`button`,{type:`button`,"data-testid":o,onClick:()=>i(t),className:c(`flex items-center gap-0.5 w-full min-h-11 md:min-h-0 cursor-pointer hover:text-text-primary transition-colors`,a===`left`?`justify-start`:`justify-end`,d&&`text-text-primary`),children:[(0,q.jsx)(`span`,{className:`truncate`,children:e}),f&&(0,q.jsx)(f,{className:`size-3 shrink-0`})]}),l&&u&&(0,q.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize ${e} column`,"data-testid":o?`${o}-resize`:void 0,onPointerDown:e=>u.onResizeStart(l,e),onDoubleClick:()=>u.onResizeReset(l),className:`hidden md:block absolute top-0 -right-1 h-full w-2 cursor-col-resize hover:bg-primary/40 active:bg-primary/60`})]})}var oe=150;function se({mode:e,onModeChange:t,ppmOnly:n,onPpmOnlyChange:r,onQueryChange:i}){let[a,o]=(0,C.useState)(``),s=(0,C.useRef)(null);return(0,C.useEffect)(()=>(s.current&&clearTimeout(s.current),s.current=setTimeout(()=>i(a),oe),()=>{s.current&&clearTimeout(s.current)}),[a]),(0,q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 p-2 border-b border-border shrink-0`,children:[(0,q.jsxs)(`div`,{className:`relative flex-1 min-w-[140px]`,children:[(0,q.jsx)(b,{className:`absolute left-2 top-1/2 -translate-y-1/2 size-3.5 text-text-subtle`}),(0,q.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),placeholder:`Search processes`,"aria-label":`Search processes`,"data-testid":`sysmon-process-search`,className:`w-full min-h-11 md:min-h-8 pl-7 pr-2 text-sm rounded-md border border-border bg-transparent focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`})]}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>t(e===`grouped`?`flat`:`grouped`),"aria-pressed":e===`flat`,"data-testid":`sysmon-toggle-flat`,className:`min-h-11 md:min-h-8 px-3 text-xs rounded-md border border-border hover:bg-surface-hover transition-colors`,children:e===`flat`?`Flat`:`Grouped`}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>r(!n),"aria-pressed":n,"data-testid":`sysmon-filter-ppm`,className:c(`min-h-11 md:min-h-8 px-3 text-xs rounded-md border transition-colors`,n?`border-primary bg-primary/10 text-primary`:`border-border hover:bg-surface-hover`),children:`PPM only`})]})}function ce({sortKey:e,sortDir:t,grid:n,onSort:r,resize:i}){let a={activeKey:e,activeDir:t,onClick:r,resize:i};return(0,q.jsxs)(`div`,{role:`row`,className:c(`grid gap-1 px-3 py-1.5 text-[11px] text-text-subtle border-b border-border sticky top-0 bg-background z-10`,z),children:[(0,q.jsx)(J,{label:`Process`,field:`name`,...a,resize:void 0,align:`left`,testId:`sysmon-sort-name`}),(0,q.jsx)(J,{label:`CPU`,field:`cpu`,...a,resizeKey:`cpu`,testId:`sysmon-sort-cpu`}),(0,q.jsx)(J,{label:`RAM`,field:`ram`,...a,resizeKey:`ram`,testId:`sysmon-sort-ram`}),n.columns.disk&&(0,q.jsx)(J,{label:`Disk`,field:`disk`,...a,resizeKey:`disk`,testId:`sysmon-col-disk`,className:V(n,`disk`)}),n.columns.gpu&&(0,q.jsx)(J,{label:`GPU`,field:`gpu`,...a,resizeKey:`gpu`,testId:`sysmon-col-gpu`,className:V(n,`gpu`)}),n.columns.net&&(0,q.jsx)(J,{label:`Net`,field:`net`,...a,resizeKey:`net`,testId:`sysmon-col-net`,className:V(n,`net`)}),(0,q.jsx)(`span`,{})]})}function le({totals:e,grid:t,gpuUtilPercent:n}){return(0,q.jsxs)(`div`,{className:c(`grid gap-1 px-3 py-1.5 text-xs font-medium border-t border-border shrink-0`,z),"data-testid":`sysmon-total`,"data-process-count":e.count,children:[(0,q.jsxs)(`span`,{className:`truncate`,children:[`Total (`,e.count,` processes)`]}),(0,q.jsxs)(`span`,{className:c(`text-right`,H(e.cpu)),children:[e.cpu.toFixed(1),`%`]}),(0,q.jsx)(`span`,{className:`text-right text-text-secondary`,children:x(e.ramMB)}),t.columns.disk&&(0,q.jsx)(`span`,{className:c(`text-right text-text-secondary tabular-nums truncate`,V(t,`disk`)),children:U(e.diskReadBps,e.diskWriteBps)}),t.columns.gpu&&(0,q.jsx)(`span`,{className:c(`text-right text-text-secondary tabular-nums truncate`,V(t,`gpu`)),children:G(n,e.gpuMemMB)}),t.columns.net&&(0,q.jsx)(`span`,{className:c(`text-right text-text-secondary tabular-nums truncate`,V(t,`net`)),children:W(e.netInBps,e.netOutBps)}),(0,q.jsx)(`span`,{})]})}var ue=`Protected: this app contains a PPM or OS-critical process — cannot be ended as a whole.`;function de({group:e,expanded:t,grid:n,killProtected:o,onToggle:s,onKillClick:l}){let u=t?r:i;return(0,q.jsxs)(`div`,{className:`grid items-center gap-1 min-h-11 md:min-h-7 px-3 text-xs cursor-pointer hover:bg-surface-hover transition-colors group/proc grid-cols-[var(--sysmon-grid-n)] @lg:grid-cols-[var(--sysmon-grid-w)]`,onClick:()=>s(e.key),"data-testid":`sysmon-group-row`,"data-group-key":e.key,"data-count":e.count,"data-disk-bps":K(e.diskReadBps,e.diskWriteBps),"data-gpu-pct":e.gpuPct,"data-net-bps":K(e.netInBps,e.netOutBps),children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,q.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s(e.key)},"aria-expanded":t,"aria-label":`${t?`Collapse`:`Expand`} ${e.label}`,"data-testid":`sysmon-group-expand`,className:`flex items-center justify-center size-11 md:size-7 -ml-2 shrink-0`,children:(0,q.jsx)(u,{className:`size-3.5 text-text-subtle`})}),(0,q.jsx)(`span`,{className:`truncate font-medium`,children:e.label}),(0,q.jsxs)(`span`,{className:`text-text-subtle shrink-0`,children:[`(`,e.count,`)`]})]}),(0,q.jsxs)(`span`,{className:c(`text-right`,H(e.cpu)),children:[e.cpu.toFixed(1),`%`]}),(0,q.jsx)(`span`,{className:`text-right text-text-secondary`,children:x(e.ramMB)}),n.columns.disk&&(0,q.jsx)(`span`,{className:c(`text-right text-text-secondary tabular-nums truncate`,V(n,`disk`)),children:U(e.diskReadBps,e.diskWriteBps)}),n.columns.gpu&&(0,q.jsx)(`span`,{className:c(`text-right text-text-secondary tabular-nums truncate`,V(n,`gpu`)),children:G(e.gpuPct,e.gpuMemMB)}),n.columns.net&&(0,q.jsx)(`span`,{className:c(`text-right text-text-secondary tabular-nums truncate`,V(n,`net`)),children:W(e.netInBps,e.netOutBps)}),(0,q.jsx)(`div`,{className:`flex justify-end`,children:(0,q.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),l(e)},disabled:o,"aria-label":`End ${e.label} and its ${e.count} processes`,title:o?ue:`End ${e.label} (${e.count} processes)`,"data-testid":`sysmon-group-kill-btn`,className:c(`flex items-center justify-center size-11 md:size-7 rounded transition-all`,`can-hover:opacity-0 can-hover:group-hover/proc:opacity-100`,o?`opacity-40 cursor-not-allowed`:`hover:bg-error/20 hover:text-error active:bg-error/30`),children:(0,q.jsx)(a,{className:`size-3.5`})})})]})}var fe=`Protected: PPM or OS-critical process — cannot be ended.`;function pe({proc:e,indent:t,grid:n,onKillClick:r}){return(0,q.jsxs)(`div`,{className:`grid items-center gap-1 min-h-11 md:min-h-7 px-3 text-xs group/proc hover:bg-surface-hover transition-colors grid-cols-[var(--sysmon-grid-n)] @lg:grid-cols-[var(--sysmon-grid-w)]`,"data-testid":`sysmon-process-row`,"data-pid":e.pid,"data-ppm":e.ppm,"data-protected":e.protected,"data-disk-bps":K(e.diskReadBps,e.diskWriteBps),"data-gpu-pct":e.gpuPct,"data-net-bps":K(e.netInBps,e.netOutBps),children:[(0,q.jsxs)(`div`,{className:c(`flex items-start gap-1.5 min-w-0`,t&&`pl-6`),children:[(0,q.jsx)(`span`,{className:`text-text-subtle shrink-0`,children:e.pid}),(0,q.jsx)(`span`,{className:`truncate text-text-secondary`,title:e.startedAt?`${e.command}\nRunning ${ae(e.startedAt)}`:e.command,children:e.command})]}),(0,q.jsxs)(`span`,{className:c(`text-right`,H(e.cpu)),children:[e.cpu.toFixed(1),`%`]}),(0,q.jsx)(`span`,{className:`text-right text-text-secondary`,children:x(e.ramMB)}),n.columns.disk&&(0,q.jsx)(`span`,{className:c(`text-right text-text-secondary tabular-nums truncate`,V(n,`disk`)),children:U(e.diskReadBps,e.diskWriteBps)}),n.columns.gpu&&(0,q.jsx)(`span`,{className:c(`text-right text-text-secondary tabular-nums truncate`,V(n,`gpu`)),children:G(e.gpuPct,e.gpuMemMB)}),n.columns.net&&(0,q.jsx)(`span`,{className:c(`text-right text-text-secondary tabular-nums truncate`,V(n,`net`)),children:W(e.netInBps,e.netOutBps)}),(0,q.jsx)(`div`,{className:`flex justify-end`,children:(0,q.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),r(e)},disabled:e.protected,"aria-label":`End process ${e.name} (${e.pid})`,title:e.protected?fe:`End process ${e.name}`,"data-testid":`sysmon-kill-btn`,className:c(`flex items-center justify-center size-11 md:size-7 rounded transition-all`,`can-hover:opacity-0 can-hover:group-hover/proc:opacity-100`,e.protected?`opacity-40 cursor-not-allowed`:`hover:bg-error/20 hover:text-error active:bg-error/30`),children:(0,q.jsx)(a,{className:`size-3.5`})})})]})}function me({target:e,onConfirm:t,onCancel:n}){let r=l(),[i,a]=(0,C.useState)(!1);if((0,C.useEffect)(()=>{e||a(!1)},[e]),!e)return null;let o=e.kind===`group`,s=o?`End app`:`End process`,c=o?e.group.cpu:e.proc.cpu,p=o?e.group.ramMB:e.proc.ramMB,m=(0,q.jsxs)(`div`,{className:`space-y-4`,"data-testid":`sysmon-kill-confirm`,"data-kill-kind":e.kind,children:[o?(0,q.jsxs)(`p`,{className:`text-sm`,children:[`End `,(0,q.jsx)(`span`,{className:`font-medium`,children:e.group.label}),` and all its`,` `,(0,q.jsx)(`span`,{className:`font-medium`,children:e.members.length}),` processes?`]}):(0,q.jsxs)(`p`,{className:`text-sm`,children:[`End `,(0,q.jsx)(`span`,{className:`font-medium`,children:e.proc.name}),` (pid `,e.proc.pid,`)?`]}),(0,q.jsxs)(`p`,{className:`text-xs text-text-subtle`,children:[`CPU `,c.toFixed(1),`% · RAM `,x(p)]}),!o&&(0,q.jsxs)(`label`,{className:`flex items-center justify-between gap-3 min-h-11 py-1`,children:[(0,q.jsx)(`span`,{className:`text-sm`,children:`Also end child processes`}),(0,q.jsx)(h,{checked:i,onCheckedChange:a,"data-testid":`sysmon-kill-tree`,"aria-label":`Also end child processes`})]}),(0,q.jsxs)(`div`,{className:`flex flex-col-reverse md:flex-row gap-2 md:justify-end pt-2`,children:[(0,q.jsx)(u,{variant:`outline`,onClick:n,"data-testid":`sysmon-kill-confirm-cancel`,className:`min-h-11`,children:`Cancel`}),(0,q.jsx)(u,{variant:`destructive`,autoFocus:!1,onClick:()=>t(e,i),"data-testid":`sysmon-kill-confirm-ok`,className:`min-h-11`,children:o?`End ${e.members.length} processes`:`End process`})]})]});return r?(0,q.jsx)(d,{open:!0,onClose:n,children:(0,q.jsxs)(`div`,{className:`px-4 pb-4`,children:[(0,q.jsx)(`h2`,{className:`text-base font-semibold mb-3`,children:s}),m]})}):(0,q.jsx)(v,{open:!0,onOpenChange:e=>!e&&n(),children:(0,q.jsxs)(_,{children:[(0,q.jsx)(f,{children:(0,q.jsx)(y,{children:s})}),m]})})}function Y(e,t){return{pid:e.pid,startedAt:e.startedAt,tree:t}}function he(e,t){let n=e.rootPid===null?void 0:t.find(t=>t.pid===e.rootPid);return n?[Y(n,!0)]:t.map(e=>Y(e,!1))}function ge(e){return e.some(e=>e.protected)}async function X(e){let t=o(),n={"Content-Type":`application/json`,"X-PPM-Request":`1`};t&&(n.Authorization=`Bearer ${t}`);let r=await fetch(`/api/system/resources/kill`,{method:`POST`,headers:n,body:JSON.stringify(e)}),i;try{i=await r.json()}catch{throw Error(r.ok?`Empty response from server`:`Server error (HTTP ${r.status})`)}if(i.ok===!1)throw Error(i.error??`HTTP ${r.status}`);return i.data}function _e(e){let[t,n]=(0,C.useState)(null),r=(0,C.useCallback)(t=>{let n=new Map(e.processes.map(e=>[e.pid,e]));return t.pids.map(e=>n.get(e)).filter(e=>!!e)},[e.processes]),i=(0,C.useMemo)(()=>new Map(e.groups.map(e=>[e.key,ge(r(e))])),[e.groups,r]),a=(0,C.useCallback)(e=>n({kind:`process`,proc:e}),[]),o=(0,C.useCallback)(e=>n({kind:`group`,group:e,members:r(e)}),[r]),c=(0,C.useCallback)(()=>n(null),[]);return{pendingKill:t,groupProtected:i,requestKillProcess:a,requestKillGroup:o,confirmKill:(0,C.useCallback)(async(e,t)=>{if(n(null),e.kind===`process`){let{proc:n}=e;try{await X(Y(n,t)),s.success(`Ended ${n.name} (${n.pid})`)}catch(e){s.error(e instanceof Error?e.message:`Failed to end ${n.name}`)}return}let{group:r,members:i}=e,a=[];for(let e of he(r,i))try{await X(e)}catch(t){a.push(t instanceof Error?t.message:`pid ${e.pid}`)}a.length===0?s.success(`Ended ${r.label} (${i.length} processes)`):s.error(`${r.label}: ${a.length} of ${i.length} could not be ended — ${a[0]}`)},[]),cancelKill:c}}var Z=`ppm-sysmon-col-widths`;function Q(){try{let e=localStorage.getItem(Z);if(!e)return{};let t=JSON.parse(e),n={};for(let e of[`cpu`,`ram`,`disk`,`gpu`,`net`]){let r=t[e];typeof r==`number`&&Number.isFinite(r)&&(n[e]=L(r))}return n}catch{return{}}}function $(e){try{Object.keys(e).length===0?localStorage.removeItem(Z):localStorage.setItem(Z,JSON.stringify(e))}catch{}}function ve(){let[e,t]=(0,C.useState)(()=>typeof localStorage>`u`?{}:Q()),n=(0,C.useRef)(null);return(0,C.useEffect)(()=>{let e=e=>{let r=n.current;if(!r)return;let i=L(r.startWidth+(e.clientX-r.startX));t(e=>e[r.key]===i?e:{...e,[r.key]:i})},r=()=>{n.current&&(n.current=null,document.body.style.cursor=``,t(e=>($(e),e)))};return window.addEventListener(`pointermove`,e),window.addEventListener(`pointerup`,r),window.addEventListener(`pointercancel`,r),()=>{window.removeEventListener(`pointermove`,e),window.removeEventListener(`pointerup`,r),window.removeEventListener(`pointercancel`,r)}},[]),{widths:e,begin:(0,C.useCallback)((t,r)=>{r.preventDefault(),n.current={key:t,startX:r.clientX,startWidth:R(t,e)},document.body.style.cursor=`col-resize`},[e]),reset:(0,C.useCallback)(e=>{t(t=>{if(!(e in t))return t;let{[e]:n,...r}=t;return $(r),r})},[])}}var ye={disk:!1,gpu:!1,net:!1};function be({snapshot:e}){let t=l(),n=(0,C.useRef)(null),[r,i]=(0,C.useState)(`grouped`),[a,o]=(0,C.useState)(!1),[s,c]=(0,C.useState)(``),[u,d]=(0,C.useState)(null),[f,p]=(0,C.useState)(`desc`),[h,g]=(0,C.useState)(()=>new Set),{pendingKill:_,groupProtected:v,requestKillProcess:y,requestKillGroup:b,confirmKill:x,cancelKill:S}=_e(e),{widths:w,begin:T,reset:E}=ve(),{rows:D,totals:O}=(0,C.useMemo)(()=>ee({processes:e.processes,groups:e.groups,mode:r,ppmOnly:a,query:s,sortKey:u,sortDir:f,expanded:h}),[e.processes,e.groups,r,a,s,u,f,h]),k=e.processColumns??ye,A=(0,C.useMemo)(()=>ie(k,u,w),[k,u,w]),j=e.system.gpus[0]?.utilPercent,M=m({count:D.length,getScrollElement:()=>n.current,estimateSize:()=>t?44:28,overscan:12}),N=(0,C.useCallback)(e=>{let[t,n]=te(u,f,e);d(t),p(n)},[u,f]),P=(0,C.useCallback)(e=>{g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]);return(0,q.jsxs)(`div`,{className:`h-full flex flex-col min-h-0 @container`,style:B(A),"data-testid":`sysmon-processes`,"data-row-count":D.length,children:[(0,q.jsx)(se,{mode:r,onModeChange:i,ppmOnly:a,onPpmOnlyChange:o,onQueryChange:c}),(0,q.jsx)(ce,{sortKey:u,sortDir:f,grid:A,onSort:N,resize:{onResizeStart:T,onResizeReset:E}}),(0,q.jsx)(`div`,{ref:n,className:`flex-1 min-h-0 overflow-y-auto`,children:(0,q.jsx)(`div`,{style:{height:M.getTotalSize(),position:`relative`},children:M.getVirtualItems().map(e=>{let t=D[e.index];return t?(0,q.jsx)(`div`,{style:{position:`absolute`,top:0,left:0,right:0,transform:`translateY(${e.start}px)`},children:t.kind===`group`?(0,q.jsx)(de,{group:t.group,expanded:t.expanded,grid:A,killProtected:v.get(t.group.key)??!0,onToggle:P,onKillClick:b}):(0,q.jsx)(pe,{proc:t.proc,indent:t.indent,grid:A,onKillClick:y})},t.kind===`group`?t.group.key:`p:${t.proc.pid}`):null})})}),(0,q.jsx)(le,{totals:O,grid:A,gpuUtilPercent:j}),(0,q.jsx)(me,{target:_,onConfirm:x,onCancel:S})]})}export{be as ProcessTable};
@@ -1 +1 @@
1
- import{n as e,r as t}from"./api-client-CEYCBt_0.js";import{t as n}from"./react-D1Yg256j.js";async function r(e){if(!e.type.startsWith(`image/`))throw Error(`Please choose an image file`);if(e.size>10485760)throw Error(`Image too large (max 10MB)`);let t=await createImageBitmap(e),n=Math.min(t.width,t.height),r=(t.width-n)/2,i=(t.height-n)/2,a=document.createElement(`canvas`);a.width=128,a.height=128;let o=a.getContext(`2d`);if(!o)throw t.close(),Error(`Canvas not supported`);return o.drawImage(t,r,i,n,n,0,0,128,128),t.close(),await new Promise((e,t)=>{a.toBlob(n=>n?e(n):t(Error(`Encode failed`)),`image/webp`,.85)})}var i=`ppm-recent-projects`,a=`ppm-recent-times`,o=`ppm-custom-order`;function s(){try{let e=localStorage.getItem(i);return e?JSON.parse(e):[]}catch{return[]}}function c(e){try{localStorage.setItem(i,JSON.stringify(e))}catch{}}function l(){try{let e=localStorage.getItem(a);return e?JSON.parse(e):{}}catch{return{}}}function u(e){try{localStorage.setItem(a,JSON.stringify(e))}catch{}}function d(t){let n=s().filter(e=>e!==t);n.unshift(t),c(n);let r=l();r[t]=Date.now(),u(r),e.put(`/api/settings/ui-prefs`,{recentOpen:r}).catch(()=>{})}var f=`ppm-project-sort`;function p(){let e=localStorage.getItem(f);return e===`recent`||e===`name`?e:`priority`}function m(e){let t=s(),n=new Map(t.map((e,t)=>[e,t]));return[...e].sort((e,t)=>(n.get(e.name)??1/0)-(n.get(t.name)??1/0))}function h(){try{let e=localStorage.getItem(o);return e?JSON.parse(e):null}catch{return null}}function g(e){try{localStorage.setItem(o,JSON.stringify(e))}catch{}}function _(e,t){if(!t)return[...e];let n=new Map(t.map((e,t)=>[e,t]));return[...e].sort((e,t)=>(n.get(e.name)??1/0)-(n.get(t.name)??1/0))}function v(e,t,n){if(e().activeProject?.name!==n)return;let r=e().projects.find(e=>e.name===n);r&&t({activeProject:r})}var y=n((n,i)=>({projects:[],activeProject:null,customOrder:h(),projectSortMode:p(),loading:!1,error:null,fetchProjects:async()=>{n({loading:!0,error:null});try{n({projects:await e.get(`/api/projects`),loading:!1})}catch(e){n({error:e instanceof Error?e.message:`Failed to fetch projects`,loading:!1})}},hydrateUiPrefs:async()=>{try{let t=await e.get(`/api/settings/ui-prefs`);if(t.recentOpen&&Object.keys(t.recentOpen).length>0&&(u(t.recentOpen),c(Object.entries(t.recentOpen).sort((e,t)=>t[1]-e[1]).map(([e])=>e))),t.projectSortMode===`recent`||t.projectSortMode===`priority`||t.projectSortMode===`name`){try{localStorage.setItem(f,t.projectSortMode)}catch{}n({projectSortMode:t.projectSortMode})}}catch{}},setProjectSortMode:t=>{try{localStorage.setItem(f,t)}catch{}n({projectSortMode:t}),e.put(`/api/settings/ui-prefs`,{projectSortMode:t}).catch(()=>{})},setActiveProject:e=>{d(e.name),n({activeProject:e})},addProject:async(t,r)=>{let a=await e.post(`/api/projects`,{path:t,name:r});await i().fetchProjects();let o=i().projects.find(e=>e.name===(r??a.name)||e.path===t);return o&&n({activeProject:o}),a},setProjectColor:async(t,n)=>{await e.patch(`/api/projects/${encodeURIComponent(t)}/color`,{color:n}),await i().fetchProjects()},setProjectImage:async(e,a)=>{let o=await r(a),s=new FormData;s.append(`file`,o,`avatar.webp`);let c=t();if(!(await fetch(`/api/projects/${encodeURIComponent(e)}/image`,{method:`POST`,headers:c?{Authorization:`Bearer ${c}`}:void 0,body:s})).ok)throw Error(`Upload failed`);await i().fetchProjects(),v(i,n,e)},removeProjectImage:async t=>{await e.del(`/api/projects/${encodeURIComponent(t)}/image`),await i().fetchProjects(),v(i,n,t)},moveProject:async(t,r)=>{let{projects:a,customOrder:o}=i(),s=_(a,o),c=s.findIndex(e=>e.name===t);if(c===-1)return;let l=r===`up`?c-1:c+1;if(l<0||l>=s.length)return;let u=s.map(e=>e.name);[u[c],u[l]]=[u[l],u[c]],g(u),await e.patch(`/api/projects/reorder`,{order:u}),n({customOrder:u})},reorderProjects:async t=>{g(t),n({customOrder:t}),await e.patch(`/api/projects/reorder`,{order:t}).catch(()=>{})},renameProject:async(t,n)=>{await e.patch(`/api/projects/${encodeURIComponent(t)}`,{name:n}),await i().fetchProjects()},deleteProject:async t=>{await e.del(`/api/projects/${encodeURIComponent(t)}`),n(e=>{let n=e.projects.filter(e=>e.name!==t),r=e.customOrder?e.customOrder.filter(e=>e!==t):null;return r&&g(r),{projects:n,customOrder:r,activeProject:e.activeProject?.name===t?n[0]??null:e.activeProject}})}}));export{y as i,_ as n,m as r,l as t};
1
+ import{n as e,r as t}from"./api-client-DwXlVfXP.js";import{t as n}from"./react-DqIU0LFM.js";async function r(e){if(!e.type.startsWith(`image/`))throw Error(`Please choose an image file`);if(e.size>10485760)throw Error(`Image too large (max 10MB)`);let t=await createImageBitmap(e),n=Math.min(t.width,t.height),r=(t.width-n)/2,i=(t.height-n)/2,a=document.createElement(`canvas`);a.width=128,a.height=128;let o=a.getContext(`2d`);if(!o)throw t.close(),Error(`Canvas not supported`);return o.drawImage(t,r,i,n,n,0,0,128,128),t.close(),await new Promise((e,t)=>{a.toBlob(n=>n?e(n):t(Error(`Encode failed`)),`image/webp`,.85)})}var i=`ppm-recent-projects`,a=`ppm-recent-times`,o=`ppm-custom-order`;function s(){try{let e=localStorage.getItem(i);return e?JSON.parse(e):[]}catch{return[]}}function c(e){try{localStorage.setItem(i,JSON.stringify(e))}catch{}}function l(){try{let e=localStorage.getItem(a);return e?JSON.parse(e):{}}catch{return{}}}function u(e){try{localStorage.setItem(a,JSON.stringify(e))}catch{}}function d(t){let n=s().filter(e=>e!==t);n.unshift(t),c(n);let r=l();r[t]=Date.now(),u(r),e.put(`/api/settings/ui-prefs`,{recentOpen:r}).catch(()=>{})}var f=`ppm-project-sort`;function p(){let e=localStorage.getItem(f);return e===`recent`||e===`name`?e:`priority`}function m(e){let t=s(),n=new Map(t.map((e,t)=>[e,t]));return[...e].sort((e,t)=>(n.get(e.name)??1/0)-(n.get(t.name)??1/0))}function h(){try{let e=localStorage.getItem(o);return e?JSON.parse(e):null}catch{return null}}function g(e){try{localStorage.setItem(o,JSON.stringify(e))}catch{}}function _(e,t){if(!t)return[...e];let n=new Map(t.map((e,t)=>[e,t]));return[...e].sort((e,t)=>(n.get(e.name)??1/0)-(n.get(t.name)??1/0))}function v(e,t,n){if(e().activeProject?.name!==n)return;let r=e().projects.find(e=>e.name===n);r&&t({activeProject:r})}var y=n((n,i)=>({projects:[],activeProject:null,customOrder:h(),projectSortMode:p(),loading:!1,error:null,fetchProjects:async()=>{n({loading:!0,error:null});try{n({projects:await e.get(`/api/projects`),loading:!1})}catch(e){n({error:e instanceof Error?e.message:`Failed to fetch projects`,loading:!1})}},hydrateUiPrefs:async()=>{try{let t=await e.get(`/api/settings/ui-prefs`);if(t.recentOpen&&Object.keys(t.recentOpen).length>0&&(u(t.recentOpen),c(Object.entries(t.recentOpen).sort((e,t)=>t[1]-e[1]).map(([e])=>e))),t.projectSortMode===`recent`||t.projectSortMode===`priority`||t.projectSortMode===`name`){try{localStorage.setItem(f,t.projectSortMode)}catch{}n({projectSortMode:t.projectSortMode})}}catch{}},setProjectSortMode:t=>{try{localStorage.setItem(f,t)}catch{}n({projectSortMode:t}),e.put(`/api/settings/ui-prefs`,{projectSortMode:t}).catch(()=>{})},setActiveProject:e=>{d(e.name),n({activeProject:e})},addProject:async(t,r)=>{let a=await e.post(`/api/projects`,{path:t,name:r});await i().fetchProjects();let o=i().projects.find(e=>e.name===(r??a.name)||e.path===t);return o&&n({activeProject:o}),a},setProjectColor:async(t,n)=>{await e.patch(`/api/projects/${encodeURIComponent(t)}/color`,{color:n}),await i().fetchProjects()},setProjectImage:async(e,a)=>{let o=await r(a),s=new FormData;s.append(`file`,o,`avatar.webp`);let c=t();if(!(await fetch(`/api/projects/${encodeURIComponent(e)}/image`,{method:`POST`,headers:c?{Authorization:`Bearer ${c}`}:void 0,body:s})).ok)throw Error(`Upload failed`);await i().fetchProjects(),v(i,n,e)},removeProjectImage:async t=>{await e.del(`/api/projects/${encodeURIComponent(t)}/image`),await i().fetchProjects(),v(i,n,t)},moveProject:async(t,r)=>{let{projects:a,customOrder:o}=i(),s=_(a,o),c=s.findIndex(e=>e.name===t);if(c===-1)return;let l=r===`up`?c-1:c+1;if(l<0||l>=s.length)return;let u=s.map(e=>e.name);[u[c],u[l]]=[u[l],u[c]],g(u),await e.patch(`/api/projects/reorder`,{order:u}),n({customOrder:u})},reorderProjects:async t=>{g(t),n({customOrder:t}),await e.patch(`/api/projects/reorder`,{order:t}).catch(()=>{})},renameProject:async(t,n)=>{await e.patch(`/api/projects/${encodeURIComponent(t)}`,{name:n}),await i().fetchProjects()},deleteProject:async t=>{await e.del(`/api/projects/${encodeURIComponent(t)}`),n(e=>{let n=e.projects.filter(e=>e.name!==t),r=e.customOrder?e.customOrder.filter(e=>e!==t):null;return r&&g(r),{projects:n,customOrder:r,activeProject:e.activeProject?.name===t?n[0]??null:e.activeProject}})}}));export{y as i,_ as n,m as r,l as t};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{S as t,x as n}from"./vendor-markdown-Ls5AcU91.js";import"./vendor-ui-CaeeFO0B.js";import{t as r}from"./copy-BewHj66E.js";import{t as i}from"./flask-conical-tp8gyZGh.js";import{t as a}from"./loader-circle-DPMrnLQ2.js";import"./api-client-CEYCBt_0.js";import"./portal-container-context-DKymYOY-.js";import{t as o}from"./button-DX32ffge.js";import{$n as s,$t as c,G as l,X as u,Xn as d,Xt as f,Y as p,Yt as m,Zt as h,en as g,nn as _,tn as v}from"./index-Cx1meAwb.js";import{getAISettings as y,getProxySettings as b,updateProxySettings as x}from"./api-settings-D18Q4Ocp.js";var S=e(t(),1),C=[{value:`claude-opus-5`,label:`Claude Opus 5`,hint:`most powerful`},{value:`claude-fable-5-1`,label:`Claude Fable 5.1`,hint:`flagship`},{value:`claude-fable-5`,label:`Claude Fable 5`,hint:`flagship`},{value:`claude-opus-4-8`,label:`Claude Opus 4.8`,hint:`powerful`},{value:`claude-opus-4-7`,label:`Claude Opus 4.7`,hint:`powerful`},{value:`claude-opus-4-6`,label:`Claude Opus 4.6`,hint:`powerful`},{value:`claude-sonnet-5`,label:`Claude Sonnet 5`,hint:`fast`},{value:`claude-sonnet-4-6`,label:`Claude Sonnet 4.6`,hint:`fast`},{value:`claude-haiku-4-5`,label:`Claude Haiku 4.5`,hint:`cheap`}];C.map(e=>e.value);function w(e,t){return`${e}/proxy${t?`/${t}`:``}`}function T(e,t){let n=w(e,t);return{anthropicBase:n,openAiBase:`${n}/v1`,anthropicMessages:`${n}/v1/messages`,openAiChatCompletions:`${n}/v1/chat/completions`,models:`${n}/v1/models`,imagesGenerations:t?`${n}/v1/images/generations`:null,imagesEdits:t?`${n}/v1/images/edits`:null}}var E=n(),D=`Hello! Reply briefly.`,O=`claude-opus-5`;function k(e){let[t,n]=(0,S.useState)(!1);return(0,E.jsxs)(m,{open:t,onOpenChange:n,children:[(0,E.jsx)(v,{asChild:!0,children:(0,E.jsxs)(o,{variant:`outline`,size:`sm`,className:`h-7 text-[11px] gap-1.5 cursor-pointer`,children:[(0,E.jsx)(i,{className:`size-3`}),`Test`]})}),(0,E.jsxs)(f,{className:`sm:max-w-md max-h-[85vh] overflow-y-auto`,children:[(0,E.jsxs)(c,{children:[(0,E.jsx)(g,{className:`text-sm`,children:`Test Proxy`}),(0,E.jsx)(h,{className:`text-[11px]`,children:`Send a test request and inspect the raw response.`})]}),t&&(0,E.jsx)(A,{...e})]})]})}function A({authKey:e,baseUrl:t,provider:n}){let[r,i]=(0,S.useState)(`anthropic`),[c,l]=(0,S.useState)(D),[d,f]=(0,S.useState)(n?``:O),[m,h]=(0,S.useState)(!0),[g,_]=(0,S.useState)(!1),[v,y]=(0,S.useState)(null),[b,x]=(0,S.useState)(null),[w,k]=(0,S.useState)(null),A=(0,S.useRef)(null),j=(0,S.useRef)(null);(0,S.useEffect)(()=>{A.current?.select()},[]),(0,S.useEffect)(()=>{j.current&&(j.current.scrollTop=j.current.scrollHeight)},[v]);let M=e=>{i(e),y(null),x(null),k(null)},N=async()=>{_(!0),y(null),x(null),k(null);let i=Date.now(),a=r===`openai`,o=T(t,n),s=a?o.openAiChatCompletions:o.anthropicMessages,l=JSON.stringify({...d?{model:d}:{},max_tokens:256,stream:m,messages:[{role:`user`,content:c}]}),u={"Content-Type":`application/json`};a?u.Authorization=`Bearer ${e}`:(u[`x-api-key`]=e,u[`anthropic-version`]=`2023-06-01`);try{let e=await fetch(s,{method:`POST`,headers:u,body:l});if(!e.ok){let t=await e.text();x(`HTTP ${e.status}: ${t}`),_(!1),k(Date.now()-i);return}if(m){let t=e.body?.getReader();if(!t){x(`No response body`),_(!1);return}let n=new TextDecoder,r=``;for(;;){let{done:e,value:i}=await t.read();if(e)break;r+=n.decode(i,{stream:!0}),y(r)}k(Date.now()-i)}else{let t=await e.text();try{y(JSON.stringify(JSON.parse(t),null,2))}catch{y(t)}k(Date.now()-i)}}catch(e){x(e.message)}finally{_(!1),k(e=>e??Date.now()-i)}};return(0,E.jsxs)(`div`,{className:`space-y-3 min-w-0`,children:[(0,E.jsxs)(`div`,{className:`space-y-1.5 min-w-0`,children:[(0,E.jsx)(p,{className:`text-[11px]`,children:`Auth Style`}),(0,E.jsx)(`div`,{className:`flex gap-1`,children:[`anthropic`,`openai`].map(e=>(0,E.jsx)(`button`,{onClick:()=>M(e),className:`flex-1 h-8 rounded-md text-[11px] font-medium border transition-colors cursor-pointer ${r===e?`bg-primary text-primary-foreground border-primary`:`bg-muted text-muted-foreground border-transparent hover:bg-muted/80`}`,children:e===`anthropic`?`Anthropic`:`OpenAI`},e))}),(0,E.jsxs)(`p`,{className:`text-[9px] text-muted-foreground break-all`,children:[r===`anthropic`?`x-api-key header`:`Authorization: Bearer header`,` · `,(0,E.jsx)(`code`,{children:`/proxy${n?`/${n}`:``}/v1/${r===`anthropic`?`messages`:`chat/completions`}`})]})]}),(0,E.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,E.jsx)(p,{className:`text-[11px]`,children:`Model`}),n?(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(u,{value:d,onChange:e=>f(e.target.value),placeholder:`leave empty to let the provider choose`,className:`h-8 text-[11px] font-mono`}),(0,E.jsxs)(`p`,{className:`text-[9px] text-muted-foreground`,children:[`Names come from `,(0,E.jsxs)(`code`,{children:[`GET /proxy/`,n,`/v1/models`]}),`.`]})]}):(0,E.jsx)(`select`,{value:d,onChange:e=>f(e.target.value),className:`h-8 w-full rounded-md border bg-background px-2 text-[11px]`,children:C.map(e=>(0,E.jsx)(`option`,{value:e.value,children:e.value},e.value))})]}),(0,E.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,E.jsx)(p,{className:`text-[11px]`,children:`Streaming`}),(0,E.jsx)(`div`,{className:`flex gap-1`,children:[!0,!1].map(e=>(0,E.jsx)(`button`,{onClick:()=>h(e),className:`h-7 px-3 rounded-md text-[11px] font-medium border transition-colors cursor-pointer ${m===e?`bg-primary text-primary-foreground border-primary`:`bg-muted text-muted-foreground border-transparent hover:bg-muted/80`}`,children:e?`Stream`:`JSON`},String(e)))})]}),(0,E.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,E.jsx)(p,{className:`text-[11px]`,children:`Message`}),(0,E.jsxs)(`div`,{className:`flex gap-1.5`,children:[(0,E.jsx)(u,{ref:A,value:c,onChange:e=>l(e.target.value),placeholder:`Type a test message...`,className:`h-9 text-[11px] flex-1 min-w-0`,onKeyDown:e=>{e.key===`Enter`&&!g&&N()}}),(0,E.jsxs)(o,{size:`sm`,className:`h-9 px-3 cursor-pointer shrink-0`,onClick:N,disabled:g||!c.trim(),children:[g?(0,E.jsx)(a,{className:`size-3.5 animate-spin`}):(0,E.jsx)(s,{className:`size-3.5`}),(0,E.jsx)(`span`,{className:`ml-1 text-[11px]`,children:g?`...`:`Send`})]})]})]}),(v||b)&&(0,E.jsxs)(`div`,{className:`space-y-1 min-w-0`,children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,E.jsx)(p,{className:`text-[10px] text-muted-foreground`,children:`Raw Response`}),w!=null&&(0,E.jsxs)(`span`,{className:`text-[9px] font-mono text-muted-foreground`,children:[(w/1e3).toFixed(1),`s`]})]}),b?(0,E.jsx)(`pre`,{className:`text-[9px] font-mono bg-error/10 text-error p-2 rounded overflow-auto max-h-52 whitespace-pre-wrap break-all`,children:b}):(0,E.jsx)(`pre`,{ref:j,className:`text-[9px] font-mono bg-muted p-2 rounded overflow-auto max-h-52 whitespace-pre-wrap break-all`,children:v})]})]})}function j(){let[e,t]=(0,S.useState)(``),[n,i]=(0,S.useState)([]);(0,S.useEffect)(()=>{y().then(e=>i(Object.keys(e.providers??{}).filter(e=>e!==`mock`&&e!==`claude`))).catch(()=>i([]))},[]);let[a,s]=(0,S.useState)(null),[c,f]=(0,S.useState)(!0),[m,h]=(0,S.useState)(!1),[g,v]=(0,S.useState)(null),[C,w]=(0,S.useState)(null);(0,S.useEffect)(()=>{f(!0),b().then(s).catch(e=>v(e.message)).finally(()=>f(!1))},[]);let D=async e=>{h(!0),v(null);try{s(await x(e))}catch(e){v(e.message)}finally{h(!1)}},O=(e,t)=>{_(e),w(t),setTimeout(()=>w(null),2e3)};if(c||!a)return(0,E.jsxs)(`div`,{className:`space-y-2`,children:[(0,E.jsx)(`h3`,{className:`text-xs font-medium text-text-secondary`,children:`API Proxy`}),(0,E.jsx)(`p`,{className:`text-[11px] text-text-subtle`,children:g?`Error: ${g}`:`Loading...`})]});let A=!!a.authKey,j=!!a.tunnelUrl,M=a.localEndpoint.replace(/\/proxy\/v1\/messages$/,``),N=T(j?a.tunnelUrl:M,e),P=N.anthropicMessages,F=N.openAiChatCompletions,I=`ANTHROPIC_BASE_URL=${N.anthropicBase}\nANTHROPIC_API_KEY=${a.authKey}`,L=`OPENAI_BASE_URL=${N.openAiBase}\nOPENAI_API_KEY=${a.authKey}`;return(0,E.jsxs)(`div`,{className:`space-y-4`,children:[(0,E.jsx)(`div`,{className:`space-y-1.5`,children:(0,E.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`Expose your accounts as an API that speaks both the Anthropic and OpenAI formats, so most SDKs need only a new base URL. The default path answers from your Claude accounts; pick a provider below to run its agent instead, which also unlocks image generation.`})}),(0,E.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,E.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,E.jsx)(p,{className:`text-xs`,children:`Enable Proxy`}),(0,E.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`Accept API requests under /proxy`})]}),(0,E.jsx)(l,{checked:a.enabled,onCheckedChange:e=>D({enabled:e}),disabled:m})]}),(0,E.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,E.jsx)(p,{className:`text-[11px]`,children:`Auth Key`}),A?(0,E.jsxs)(`div`,{className:`flex gap-1.5`,children:[(0,E.jsx)(u,{readOnly:!0,value:a.authKey,className:`h-7 text-[11px] font-mono flex-1`}),(0,E.jsx)(o,{variant:`outline`,size:`sm`,className:`h-7 px-2 cursor-pointer shrink-0`,onClick:()=>O(a.authKey,`key`),children:C===`key`?`Copied!`:(0,E.jsx)(r,{className:`size-3`})}),(0,E.jsx)(o,{variant:`outline`,size:`sm`,className:`h-7 px-2 cursor-pointer shrink-0`,onClick:()=>D({generateKey:!0}),disabled:m,children:(0,E.jsx)(d,{className:`size-3`})})]}):(0,E.jsx)(o,{variant:`outline`,size:`sm`,className:`h-7 text-xs cursor-pointer`,onClick:()=>D({generateKey:!0}),disabled:m,children:`Generate Auth Key`}),(0,E.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Use as Bearer token or x-api-key when calling the proxy.`})]}),a.enabled&&A&&(0,E.jsxs)(`div`,{className:`space-y-2 rounded-md border p-3 bg-muted/30`,children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,E.jsx)(`h4`,{className:`text-[11px] font-medium`,children:`Connection Info`}),(0,E.jsx)(k,{authKey:a.authKey,baseUrl:window.location.origin,provider:e})]}),(0,E.jsxs)(`div`,{className:`space-y-1`,children:[(0,E.jsx)(p,{className:`text-[10px] text-muted-foreground`,children:`Provider`}),(0,E.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:[{id:``,label:`Claude (default)`},...n.map(e=>({id:e,label:e}))].map(n=>(0,E.jsx)(`button`,{type:`button`,onClick:()=>t(n.id),className:`text-[10px] px-2.5 min-h-[36px] rounded-md border transition-colors cursor-pointer ${e===n.id?`border-primary bg-primary/15`:`border-border bg-muted/40 hover:bg-muted`}`,children:n.label},n.id||`default`))}),e&&(0,E.jsxs)(`p`,{className:`text-[10px] text-muted-foreground`,children:[`Runs the `,e,` agent per request (read-only sandbox, one turn). Slower than the default path.`]})]}),(0,E.jsxs)(`div`,{className:`space-y-1`,children:[(0,E.jsx)(p,{className:`text-[10px] text-muted-foreground`,children:`Anthropic Endpoint`}),(0,E.jsxs)(`div`,{className:`flex gap-1.5 items-center`,children:[(0,E.jsx)(`code`,{className:`text-[10px] font-mono bg-muted px-1.5 py-0.5 rounded flex-1 truncate`,children:P}),(0,E.jsx)(o,{variant:`ghost`,size:`sm`,className:`h-6 px-1.5 cursor-pointer shrink-0`,onClick:()=>O(P,`anthropic`),children:C===`anthropic`?`Copied!`:(0,E.jsx)(r,{className:`size-3`})})]})]}),(0,E.jsxs)(`div`,{className:`space-y-1`,children:[(0,E.jsx)(p,{className:`text-[10px] text-muted-foreground`,children:`OpenAI-Compatible Endpoint`}),(0,E.jsxs)(`div`,{className:`flex gap-1.5 items-center`,children:[(0,E.jsx)(`code`,{className:`text-[10px] font-mono bg-muted px-1.5 py-0.5 rounded flex-1 truncate`,children:F}),(0,E.jsx)(o,{variant:`ghost`,size:`sm`,className:`h-6 px-1.5 cursor-pointer shrink-0`,onClick:()=>O(F,`openai`),children:C===`openai`?`Copied!`:(0,E.jsx)(r,{className:`size-3`})})]})]}),N.imagesGenerations&&N.imagesEdits&&(0,E.jsxs)(`div`,{className:`space-y-1`,children:[(0,E.jsx)(p,{className:`text-[10px] text-muted-foreground`,children:`Image Endpoints`}),(0,E.jsx)(`code`,{className:`block text-[10px] font-mono bg-muted px-1.5 py-0.5 rounded truncate`,children:N.imagesGenerations}),(0,E.jsx)(`code`,{className:`block text-[10px] font-mono bg-muted px-1.5 py-0.5 rounded truncate`,children:N.imagesEdits})]}),!j&&(0,E.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Start a Cloudflare tunnel (Share) to get a public URL.`}),(0,E.jsxs)(`div`,{className:`space-y-1 pt-1`,children:[(0,E.jsx)(p,{className:`text-[10px] text-muted-foreground`,children:`Anthropic Format`}),(0,E.jsxs)(`div`,{className:`relative`,children:[(0,E.jsx)(`pre`,{className:`text-[9px] font-mono bg-muted p-2 rounded overflow-x-auto whitespace-pre`,children:I}),(0,E.jsx)(o,{variant:`ghost`,size:`sm`,className:`absolute top-1 right-1 h-5 px-1 cursor-pointer`,onClick:()=>O(I,`anthropic-env`),children:C===`anthropic-env`?`Copied!`:(0,E.jsx)(r,{className:`size-2.5`})})]})]}),(0,E.jsxs)(`div`,{className:`space-y-1`,children:[(0,E.jsx)(p,{className:`text-[10px] text-muted-foreground`,children:`OpenAI Format`}),(0,E.jsxs)(`div`,{className:`relative`,children:[(0,E.jsx)(`pre`,{className:`text-[9px] font-mono bg-muted p-2 rounded overflow-x-auto whitespace-pre`,children:L}),(0,E.jsx)(o,{variant:`ghost`,size:`sm`,className:`absolute top-1 right-1 h-5 px-1 cursor-pointer`,onClick:()=>O(L,`openai-env`),children:C===`openai-env`?`Copied!`:(0,E.jsx)(r,{className:`size-2.5`})})]})]}),(0,E.jsx)(`div`,{className:`flex items-center gap-3 pt-1`,children:(0,E.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`Requests served: `,(0,E.jsx)(`span`,{className:`font-mono`,children:a.requestCount})]})})]}),m&&(0,E.jsx)(`p`,{className:`text-[11px] text-text-subtle`,children:`Saving...`}),g&&(0,E.jsx)(`p`,{className:`text-[11px] text-error`,children:g})]})}export{j as ProxySettingsSection};
1
+ import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{C as t,S as n}from"./vendor-markdown-CuWCHIVb.js";import"./vendor-ui-BBdkypKW.js";import{t as r}from"./copy-CXuIH4VC.js";import{t as i}from"./flask-conical-Dix4qNDj.js";import{t as a}from"./loader-circle-DxI3O9_f.js";import"./api-client-DwXlVfXP.js";import"./portal-container-context-DeLx1cOI.js";import{t as o}from"./button-zgoXa9r7.js";import{$n as s,$t as c,G as l,X as u,Xn as d,Xt as f,Y as p,Yt as m,Zt as h,en as g,nn as _,tn as v}from"./index-DVNJ2W5R.js";import{getAISettings as y,getProxySettings as b,updateProxySettings as x}from"./api-settings-BQIwZoLm.js";var S=e(t(),1),C=[{value:`claude-opus-5`,label:`Claude Opus 5`,hint:`most powerful`},{value:`claude-fable-5-1`,label:`Claude Fable 5.1`,hint:`flagship`},{value:`claude-fable-5`,label:`Claude Fable 5`,hint:`flagship`},{value:`claude-opus-4-8`,label:`Claude Opus 4.8`,hint:`powerful`},{value:`claude-opus-4-7`,label:`Claude Opus 4.7`,hint:`powerful`},{value:`claude-opus-4-6`,label:`Claude Opus 4.6`,hint:`powerful`},{value:`claude-sonnet-5`,label:`Claude Sonnet 5`,hint:`fast`},{value:`claude-sonnet-4-6`,label:`Claude Sonnet 4.6`,hint:`fast`},{value:`claude-haiku-4-5`,label:`Claude Haiku 4.5`,hint:`cheap`}];C.map(e=>e.value);function w(e,t){return`${e}/proxy${t?`/${t}`:``}`}function T(e,t){let n=w(e,t);return{anthropicBase:n,openAiBase:`${n}/v1`,anthropicMessages:`${n}/v1/messages`,openAiChatCompletions:`${n}/v1/chat/completions`,models:`${n}/v1/models`,imagesGenerations:t?`${n}/v1/images/generations`:null,imagesEdits:t?`${n}/v1/images/edits`:null}}var E=n(),D=`Hello! Reply briefly.`,O=`claude-opus-5`;function k(e){let[t,n]=(0,S.useState)(!1);return(0,E.jsxs)(m,{open:t,onOpenChange:n,children:[(0,E.jsx)(v,{asChild:!0,children:(0,E.jsxs)(o,{variant:`outline`,size:`sm`,className:`h-7 text-[11px] gap-1.5 cursor-pointer`,children:[(0,E.jsx)(i,{className:`size-3`}),`Test`]})}),(0,E.jsxs)(f,{className:`sm:max-w-md max-h-[85vh] overflow-y-auto`,children:[(0,E.jsxs)(c,{children:[(0,E.jsx)(g,{className:`text-sm`,children:`Test Proxy`}),(0,E.jsx)(h,{className:`text-[11px]`,children:`Send a test request and inspect the raw response.`})]}),t&&(0,E.jsx)(A,{...e})]})]})}function A({authKey:e,baseUrl:t,provider:n}){let[r,i]=(0,S.useState)(`anthropic`),[c,l]=(0,S.useState)(D),[d,f]=(0,S.useState)(n?``:O),[m,h]=(0,S.useState)(!0),[g,_]=(0,S.useState)(!1),[v,y]=(0,S.useState)(null),[b,x]=(0,S.useState)(null),[w,k]=(0,S.useState)(null),A=(0,S.useRef)(null),j=(0,S.useRef)(null);(0,S.useEffect)(()=>{A.current?.select()},[]),(0,S.useEffect)(()=>{j.current&&(j.current.scrollTop=j.current.scrollHeight)},[v]);let M=e=>{i(e),y(null),x(null),k(null)},N=async()=>{_(!0),y(null),x(null),k(null);let i=Date.now(),a=r===`openai`,o=T(t,n),s=a?o.openAiChatCompletions:o.anthropicMessages,l=JSON.stringify({...d?{model:d}:{},max_tokens:256,stream:m,messages:[{role:`user`,content:c}]}),u={"Content-Type":`application/json`};a?u.Authorization=`Bearer ${e}`:(u[`x-api-key`]=e,u[`anthropic-version`]=`2023-06-01`);try{let e=await fetch(s,{method:`POST`,headers:u,body:l});if(!e.ok){let t=await e.text();x(`HTTP ${e.status}: ${t}`),_(!1),k(Date.now()-i);return}if(m){let t=e.body?.getReader();if(!t){x(`No response body`),_(!1);return}let n=new TextDecoder,r=``;for(;;){let{done:e,value:i}=await t.read();if(e)break;r+=n.decode(i,{stream:!0}),y(r)}k(Date.now()-i)}else{let t=await e.text();try{y(JSON.stringify(JSON.parse(t),null,2))}catch{y(t)}k(Date.now()-i)}}catch(e){x(e.message)}finally{_(!1),k(e=>e??Date.now()-i)}};return(0,E.jsxs)(`div`,{className:`space-y-3 min-w-0`,children:[(0,E.jsxs)(`div`,{className:`space-y-1.5 min-w-0`,children:[(0,E.jsx)(p,{className:`text-[11px]`,children:`Auth Style`}),(0,E.jsx)(`div`,{className:`flex gap-1`,children:[`anthropic`,`openai`].map(e=>(0,E.jsx)(`button`,{onClick:()=>M(e),className:`flex-1 h-8 rounded-md text-[11px] font-medium border transition-colors cursor-pointer ${r===e?`bg-primary text-primary-foreground border-primary`:`bg-muted text-muted-foreground border-transparent hover:bg-muted/80`}`,children:e===`anthropic`?`Anthropic`:`OpenAI`},e))}),(0,E.jsxs)(`p`,{className:`text-[9px] text-muted-foreground break-all`,children:[r===`anthropic`?`x-api-key header`:`Authorization: Bearer header`,` · `,(0,E.jsx)(`code`,{children:`/proxy${n?`/${n}`:``}/v1/${r===`anthropic`?`messages`:`chat/completions`}`})]})]}),(0,E.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,E.jsx)(p,{className:`text-[11px]`,children:`Model`}),n?(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(u,{value:d,onChange:e=>f(e.target.value),placeholder:`leave empty to let the provider choose`,className:`h-8 text-[11px] font-mono`}),(0,E.jsxs)(`p`,{className:`text-[9px] text-muted-foreground`,children:[`Names come from `,(0,E.jsxs)(`code`,{children:[`GET /proxy/`,n,`/v1/models`]}),`.`]})]}):(0,E.jsx)(`select`,{value:d,onChange:e=>f(e.target.value),className:`h-8 w-full rounded-md border bg-background px-2 text-[11px]`,children:C.map(e=>(0,E.jsx)(`option`,{value:e.value,children:e.value},e.value))})]}),(0,E.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,E.jsx)(p,{className:`text-[11px]`,children:`Streaming`}),(0,E.jsx)(`div`,{className:`flex gap-1`,children:[!0,!1].map(e=>(0,E.jsx)(`button`,{onClick:()=>h(e),className:`h-7 px-3 rounded-md text-[11px] font-medium border transition-colors cursor-pointer ${m===e?`bg-primary text-primary-foreground border-primary`:`bg-muted text-muted-foreground border-transparent hover:bg-muted/80`}`,children:e?`Stream`:`JSON`},String(e)))})]}),(0,E.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,E.jsx)(p,{className:`text-[11px]`,children:`Message`}),(0,E.jsxs)(`div`,{className:`flex gap-1.5`,children:[(0,E.jsx)(u,{ref:A,value:c,onChange:e=>l(e.target.value),placeholder:`Type a test message...`,className:`h-9 text-[11px] flex-1 min-w-0`,onKeyDown:e=>{e.key===`Enter`&&!g&&N()}}),(0,E.jsxs)(o,{size:`sm`,className:`h-9 px-3 cursor-pointer shrink-0`,onClick:N,disabled:g||!c.trim(),children:[g?(0,E.jsx)(a,{className:`size-3.5 animate-spin`}):(0,E.jsx)(s,{className:`size-3.5`}),(0,E.jsx)(`span`,{className:`ml-1 text-[11px]`,children:g?`...`:`Send`})]})]})]}),(v||b)&&(0,E.jsxs)(`div`,{className:`space-y-1 min-w-0`,children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,E.jsx)(p,{className:`text-[10px] text-muted-foreground`,children:`Raw Response`}),w!=null&&(0,E.jsxs)(`span`,{className:`text-[9px] font-mono text-muted-foreground`,children:[(w/1e3).toFixed(1),`s`]})]}),b?(0,E.jsx)(`pre`,{className:`text-[9px] font-mono bg-error/10 text-error p-2 rounded overflow-auto max-h-52 whitespace-pre-wrap break-all`,children:b}):(0,E.jsx)(`pre`,{ref:j,className:`text-[9px] font-mono bg-muted p-2 rounded overflow-auto max-h-52 whitespace-pre-wrap break-all`,children:v})]})]})}function j(){let[e,t]=(0,S.useState)(``),[n,i]=(0,S.useState)([]);(0,S.useEffect)(()=>{y().then(e=>i(Object.keys(e.providers??{}).filter(e=>e!==`mock`&&e!==`claude`))).catch(()=>i([]))},[]);let[a,s]=(0,S.useState)(null),[c,f]=(0,S.useState)(!0),[m,h]=(0,S.useState)(!1),[g,v]=(0,S.useState)(null),[C,w]=(0,S.useState)(null);(0,S.useEffect)(()=>{f(!0),b().then(s).catch(e=>v(e.message)).finally(()=>f(!1))},[]);let D=async e=>{h(!0),v(null);try{s(await x(e))}catch(e){v(e.message)}finally{h(!1)}},O=(e,t)=>{_(e),w(t),setTimeout(()=>w(null),2e3)};if(c||!a)return(0,E.jsxs)(`div`,{className:`space-y-2`,children:[(0,E.jsx)(`h3`,{className:`text-xs font-medium text-text-secondary`,children:`API Proxy`}),(0,E.jsx)(`p`,{className:`text-[11px] text-text-subtle`,children:g?`Error: ${g}`:`Loading...`})]});let A=!!a.authKey,j=!!a.tunnelUrl,M=a.localEndpoint.replace(/\/proxy\/v1\/messages$/,``),N=T(j?a.tunnelUrl:M,e),P=N.anthropicMessages,F=N.openAiChatCompletions,I=`ANTHROPIC_BASE_URL=${N.anthropicBase}\nANTHROPIC_API_KEY=${a.authKey}`,L=`OPENAI_BASE_URL=${N.openAiBase}\nOPENAI_API_KEY=${a.authKey}`;return(0,E.jsxs)(`div`,{className:`space-y-4`,children:[(0,E.jsx)(`div`,{className:`space-y-1.5`,children:(0,E.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`Expose your accounts as an API that speaks both the Anthropic and OpenAI formats, so most SDKs need only a new base URL. The default path answers from your Claude accounts; pick a provider below to run its agent instead, which also unlocks image generation.`})}),(0,E.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,E.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,E.jsx)(p,{className:`text-xs`,children:`Enable Proxy`}),(0,E.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`Accept API requests under /proxy`})]}),(0,E.jsx)(l,{checked:a.enabled,onCheckedChange:e=>D({enabled:e}),disabled:m})]}),(0,E.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,E.jsx)(p,{className:`text-[11px]`,children:`Auth Key`}),A?(0,E.jsxs)(`div`,{className:`flex gap-1.5`,children:[(0,E.jsx)(u,{readOnly:!0,value:a.authKey,className:`h-7 text-[11px] font-mono flex-1`}),(0,E.jsx)(o,{variant:`outline`,size:`sm`,className:`h-7 px-2 cursor-pointer shrink-0`,onClick:()=>O(a.authKey,`key`),children:C===`key`?`Copied!`:(0,E.jsx)(r,{className:`size-3`})}),(0,E.jsx)(o,{variant:`outline`,size:`sm`,className:`h-7 px-2 cursor-pointer shrink-0`,onClick:()=>D({generateKey:!0}),disabled:m,children:(0,E.jsx)(d,{className:`size-3`})})]}):(0,E.jsx)(o,{variant:`outline`,size:`sm`,className:`h-7 text-xs cursor-pointer`,onClick:()=>D({generateKey:!0}),disabled:m,children:`Generate Auth Key`}),(0,E.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Use as Bearer token or x-api-key when calling the proxy.`})]}),a.enabled&&A&&(0,E.jsxs)(`div`,{className:`space-y-2 rounded-md border p-3 bg-muted/30`,children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,E.jsx)(`h4`,{className:`text-[11px] font-medium`,children:`Connection Info`}),(0,E.jsx)(k,{authKey:a.authKey,baseUrl:window.location.origin,provider:e})]}),(0,E.jsxs)(`div`,{className:`space-y-1`,children:[(0,E.jsx)(p,{className:`text-[10px] text-muted-foreground`,children:`Provider`}),(0,E.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:[{id:``,label:`Claude (default)`},...n.map(e=>({id:e,label:e}))].map(n=>(0,E.jsx)(`button`,{type:`button`,onClick:()=>t(n.id),className:`text-[10px] px-2.5 min-h-[36px] rounded-md border transition-colors cursor-pointer ${e===n.id?`border-primary bg-primary/15`:`border-border bg-muted/40 hover:bg-muted`}`,children:n.label},n.id||`default`))}),e&&(0,E.jsxs)(`p`,{className:`text-[10px] text-muted-foreground`,children:[`Runs the `,e,` agent per request (read-only sandbox, one turn). Slower than the default path.`]})]}),(0,E.jsxs)(`div`,{className:`space-y-1`,children:[(0,E.jsx)(p,{className:`text-[10px] text-muted-foreground`,children:`Anthropic Endpoint`}),(0,E.jsxs)(`div`,{className:`flex gap-1.5 items-center`,children:[(0,E.jsx)(`code`,{className:`text-[10px] font-mono bg-muted px-1.5 py-0.5 rounded flex-1 truncate`,children:P}),(0,E.jsx)(o,{variant:`ghost`,size:`sm`,className:`h-6 px-1.5 cursor-pointer shrink-0`,onClick:()=>O(P,`anthropic`),children:C===`anthropic`?`Copied!`:(0,E.jsx)(r,{className:`size-3`})})]})]}),(0,E.jsxs)(`div`,{className:`space-y-1`,children:[(0,E.jsx)(p,{className:`text-[10px] text-muted-foreground`,children:`OpenAI-Compatible Endpoint`}),(0,E.jsxs)(`div`,{className:`flex gap-1.5 items-center`,children:[(0,E.jsx)(`code`,{className:`text-[10px] font-mono bg-muted px-1.5 py-0.5 rounded flex-1 truncate`,children:F}),(0,E.jsx)(o,{variant:`ghost`,size:`sm`,className:`h-6 px-1.5 cursor-pointer shrink-0`,onClick:()=>O(F,`openai`),children:C===`openai`?`Copied!`:(0,E.jsx)(r,{className:`size-3`})})]})]}),N.imagesGenerations&&N.imagesEdits&&(0,E.jsxs)(`div`,{className:`space-y-1`,children:[(0,E.jsx)(p,{className:`text-[10px] text-muted-foreground`,children:`Image Endpoints`}),(0,E.jsx)(`code`,{className:`block text-[10px] font-mono bg-muted px-1.5 py-0.5 rounded truncate`,children:N.imagesGenerations}),(0,E.jsx)(`code`,{className:`block text-[10px] font-mono bg-muted px-1.5 py-0.5 rounded truncate`,children:N.imagesEdits})]}),!j&&(0,E.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Start a Cloudflare tunnel (Share) to get a public URL.`}),(0,E.jsxs)(`div`,{className:`space-y-1 pt-1`,children:[(0,E.jsx)(p,{className:`text-[10px] text-muted-foreground`,children:`Anthropic Format`}),(0,E.jsxs)(`div`,{className:`relative`,children:[(0,E.jsx)(`pre`,{className:`text-[9px] font-mono bg-muted p-2 rounded overflow-x-auto whitespace-pre`,children:I}),(0,E.jsx)(o,{variant:`ghost`,size:`sm`,className:`absolute top-1 right-1 h-5 px-1 cursor-pointer`,onClick:()=>O(I,`anthropic-env`),children:C===`anthropic-env`?`Copied!`:(0,E.jsx)(r,{className:`size-2.5`})})]})]}),(0,E.jsxs)(`div`,{className:`space-y-1`,children:[(0,E.jsx)(p,{className:`text-[10px] text-muted-foreground`,children:`OpenAI Format`}),(0,E.jsxs)(`div`,{className:`relative`,children:[(0,E.jsx)(`pre`,{className:`text-[9px] font-mono bg-muted p-2 rounded overflow-x-auto whitespace-pre`,children:L}),(0,E.jsx)(o,{variant:`ghost`,size:`sm`,className:`absolute top-1 right-1 h-5 px-1 cursor-pointer`,onClick:()=>O(L,`openai-env`),children:C===`openai-env`?`Copied!`:(0,E.jsx)(r,{className:`size-2.5`})})]})]}),(0,E.jsx)(`div`,{className:`flex items-center gap-3 pt-1`,children:(0,E.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`Requests served: `,(0,E.jsx)(`span`,{className:`font-mono`,children:a.requestCount})]})})]}),m&&(0,E.jsx)(`p`,{className:`text-[11px] text-text-subtle`,children:`Saving...`}),g&&(0,E.jsx)(`p`,{className:`text-[11px] text-error`,children:g})]})}export{j as ProxySettingsSection};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{S as t,x as n}from"./vendor-markdown-Ls5AcU91.js";import"./vendor-ui-CaeeFO0B.js";import{t as r}from"./loader-circle-DPMrnLQ2.js";import{s as i}from"./api-client-CEYCBt_0.js";import{t as a}from"./button-DX32ffge.js";import{Ln as o,X as s}from"./index-Cx1meAwb.js";import{clearQueryAuditLogs as c,getQueryAuditSettings as l,updateQueryAuditSettings as u}from"./api-settings-D18Q4Ocp.js";var d=e(t(),1),f=n();function p(e){return e<1024*1024?`${(e/1024).toFixed(0)} KB`:`${(e/1024/1024).toFixed(1)} MB`}function m(){let[e,t]=(0,d.useState)(null),[n,m]=(0,d.useState)(``),[h,g]=(0,d.useState)(``),[_,v]=(0,d.useState)(!1),[y,b]=(0,d.useState)(!1);function x(e){t(e),m(String(e.retention_days)),g(String(e.max_size_mb))}(0,d.useEffect)(()=>{l().then(x).catch(e=>i.error(`Could not load audit settings`,{description:e.message}))},[]);async function S(){v(!0);try{x(await u({retention_days:Number(n),max_size_mb:Number(h)})),i.success(`Audit retention updated`)}catch(e){i.error(`Could not save`,{description:e.message})}finally{v(!1)}}async function C(){if(confirm(`Delete every recorded query? This cannot be undone.`)){b(!0);try{await c(),x(await l()),i.success(`Query audit log cleared`)}catch(e){i.error(`Could not clear the log`,{description:e.message})}finally{b(!1)}}}if(!e)return(0,f.jsx)(`div`,{className:`flex items-center justify-center py-8 text-muted-foreground`,children:(0,f.jsx)(r,{className:`size-4 animate-spin`})});let w=n!==String(e.retention_days)||h!==String(e.max_size_mb);return(0,f.jsxs)(`div`,{className:`space-y-4`,children:[(0,f.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,children:[`Every statement run from the SQL editor, the data grid and the `,(0,f.jsx)(`code`,{children:`ppm db`}),` CLI is recorded, together with a sample of the result. Entries are pruned once they pass either limit below — whichever comes first.`]}),(0,f.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,f.jsxs)(`label`,{className:`space-y-1`,children:[(0,f.jsx)(`span`,{className:`text-xs font-medium`,children:`Keep for (days)`}),(0,f.jsx)(s,{type:`number`,min:1,value:n,onChange:e=>m(e.target.value),className:`h-8 text-xs`})]}),(0,f.jsxs)(`label`,{className:`space-y-1`,children:[(0,f.jsx)(`span`,{className:`text-xs font-medium`,children:`Max size (MB)`}),(0,f.jsx)(s,{type:`number`,min:10,value:h,onChange:e=>g(e.target.value),className:`h-8 text-xs`})]})]}),(0,f.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,f.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[e.entry_count.toLocaleString(),` entries · `,p(e.size_bytes),` on disk`]}),(0,f.jsx)(a,{size:`sm`,className:`h-8 text-xs`,disabled:!w||_,onClick:S,children:_?(0,f.jsx)(r,{className:`size-3.5 animate-spin`}):`Save`})]}),(0,f.jsxs)(a,{variant:`outline`,size:`sm`,className:`h-8 w-full gap-1.5 text-xs text-destructive`,disabled:y||e.entry_count===0,onClick:C,children:[y?(0,f.jsx)(r,{className:`size-3.5 animate-spin`}):(0,f.jsx)(o,{className:`size-3.5`}),`Clear all recorded queries`]})]})}export{m as QueryAuditSection};
1
+ import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{C as t,S as n}from"./vendor-markdown-CuWCHIVb.js";import"./vendor-ui-BBdkypKW.js";import{t as r}from"./loader-circle-DxI3O9_f.js";import{s as i}from"./api-client-DwXlVfXP.js";import{t as a}from"./button-zgoXa9r7.js";import{Ln as o,X as s}from"./index-DVNJ2W5R.js";import{clearQueryAuditLogs as c,getQueryAuditSettings as l,updateQueryAuditSettings as u}from"./api-settings-BQIwZoLm.js";var d=e(t(),1),f=n();function p(e){return e<1024*1024?`${(e/1024).toFixed(0)} KB`:`${(e/1024/1024).toFixed(1)} MB`}function m(){let[e,t]=(0,d.useState)(null),[n,m]=(0,d.useState)(``),[h,g]=(0,d.useState)(``),[_,v]=(0,d.useState)(!1),[y,b]=(0,d.useState)(!1);function x(e){t(e),m(String(e.retention_days)),g(String(e.max_size_mb))}(0,d.useEffect)(()=>{l().then(x).catch(e=>i.error(`Could not load audit settings`,{description:e.message}))},[]);async function S(){v(!0);try{x(await u({retention_days:Number(n),max_size_mb:Number(h)})),i.success(`Audit retention updated`)}catch(e){i.error(`Could not save`,{description:e.message})}finally{v(!1)}}async function C(){if(confirm(`Delete every recorded query? This cannot be undone.`)){b(!0);try{await c(),x(await l()),i.success(`Query audit log cleared`)}catch(e){i.error(`Could not clear the log`,{description:e.message})}finally{b(!1)}}}if(!e)return(0,f.jsx)(`div`,{className:`flex items-center justify-center py-8 text-muted-foreground`,children:(0,f.jsx)(r,{className:`size-4 animate-spin`})});let w=n!==String(e.retention_days)||h!==String(e.max_size_mb);return(0,f.jsxs)(`div`,{className:`space-y-4`,children:[(0,f.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,children:[`Every statement run from the SQL editor, the data grid and the `,(0,f.jsx)(`code`,{children:`ppm db`}),` CLI is recorded, together with a sample of the result. Entries are pruned once they pass either limit below — whichever comes first.`]}),(0,f.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,f.jsxs)(`label`,{className:`space-y-1`,children:[(0,f.jsx)(`span`,{className:`text-xs font-medium`,children:`Keep for (days)`}),(0,f.jsx)(s,{type:`number`,min:1,value:n,onChange:e=>m(e.target.value),className:`h-8 text-xs`})]}),(0,f.jsxs)(`label`,{className:`space-y-1`,children:[(0,f.jsx)(`span`,{className:`text-xs font-medium`,children:`Max size (MB)`}),(0,f.jsx)(s,{type:`number`,min:10,value:h,onChange:e=>g(e.target.value),className:`h-8 text-xs`})]})]}),(0,f.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,f.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[e.entry_count.toLocaleString(),` entries · `,p(e.size_bytes),` on disk`]}),(0,f.jsx)(a,{size:`sm`,className:`h-8 text-xs`,disabled:!w||_,onClick:S,children:_?(0,f.jsx)(r,{className:`size-3.5 animate-spin`}):`Save`})]}),(0,f.jsxs)(a,{variant:`outline`,size:`sm`,className:`h-8 w-full gap-1.5 text-xs text-destructive`,disabled:y||e.entry_count===0,onClick:C,children:[y?(0,f.jsx)(r,{className:`size-3.5 animate-spin`}):(0,f.jsx)(o,{className:`size-3.5`}),`Clear all recorded queries`]})]})}export{m as QueryAuditSection};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{S as t}from"./vendor-markdown-Ls5AcU91.js";var n=e=>{let t,n=new Set,r=(e,r)=>{let i=typeof e==`function`?e(t):e;if(!Object.is(i,t)){let e=t;t=r??(typeof i!=`object`||!i)?i:Object.assign({},t,i),n.forEach(n=>n(t,e))}},i=()=>t,a={setState:r,getState:i,getInitialState:()=>o,subscribe:e=>(n.add(e),()=>n.delete(e))},o=t=e(r,i,a);return a},r=(e=>e?n(e):n),i=e(t(),1),a=e=>e;function o(e,t=a){let n=i.useSyncExternalStore(e.subscribe,i.useCallback(()=>t(e.getState()),[e,t]),i.useCallback(()=>t(e.getInitialState()),[e,t]));return i.useDebugValue(n),n}var s=e=>{let t=r(e),n=e=>o(t,e);return Object.assign(n,t),n},c=(e=>e?s(e):s);export{c as t};
1
+ import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{C as t}from"./vendor-markdown-CuWCHIVb.js";var n=e=>{let t,n=new Set,r=(e,r)=>{let i=typeof e==`function`?e(t):e;if(!Object.is(i,t)){let e=t;t=r??(typeof i!=`object`||!i)?i:Object.assign({},t,i),n.forEach(n=>n(t,e))}},i=()=>t,a={setState:r,getState:i,getInitialState:()=>o,subscribe:e=>(n.add(e),()=>n.delete(e))},o=t=e(r,i,a);return a},r=(e=>e?n(e):n),i=e(t(),1),a=e=>e;function o(e,t=a){let n=i.useSyncExternalStore(e.subscribe,i.useCallback(()=>t(e.getState()),[e,t]),i.useCallback(()=>t(e.getInitialState()),[e,t]));return i.useDebugValue(n),n}var s=e=>{let t=r(e),n=e=>o(t,e);return Object.assign(n,t),n},c=(e=>e?s(e):s);export{c as t};
@@ -0,0 +1,2 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/remote-desktop-mobile-view-Gk8UCVIx.js","assets/rolldown-runtime-FhOqtrmT.js","assets/index-DVNJ2W5R.js","assets/vendor-mermaid-CfY1-PkA.js","assets/vendor-ui-BBdkypKW.js","assets/vendor-markdown-CuWCHIVb.js","assets/button-zgoXa9r7.js","assets/utils-IrnQujwR.js","assets/createLucideIcon-D6fVXe3s.js","assets/arrow-left-DpXaakMC.js","assets/bot-D3-n2i31.js","assets/check-BQKbhtoA.js","assets/chevron-down-B9puixxZ.js","assets/chevron-right-DK_HbYZC.js","assets/chevron-up-BPAINgoK.js","assets/circle-OKk7s0DX.js","assets/clock-BmPiGrSF.js","assets/sparkles-blTKn0vi.js","assets/copy-CXuIH4VC.js","assets/database-Dz0W7OH7.js","assets/download-D70Q4Ba6.js","assets/use-coarse-long-press-BsBpxWup.js","assets/eye-off-CmtfyRUD.js","assets/eye-dfZn7evX.js","assets/loader-circle-DxI3O9_f.js","assets/monitor-CG69bSMW.js","assets/x-Bdaog6Az.js","assets/api-client-DwXlVfXP.js","assets/react-DqIU0LFM.js","assets/window-store-CfxP5yor.js","assets/window-pip-registry-BWxaVLj5.js","assets/panel-store-D42k25jy.js","assets/context-menu-DM9CgxGh.js","assets/portal-container-context-DeLx1cOI.js","assets/mobile-bottom-sheet-Ch1e_JBq.js","assets/use-visual-viewport-CNdG4QHH.js","assets/use-is-mobile-Bi42QhIi.js","assets/project-store-C83MMnlt.js","assets/ws-auth-FRzMmfQx.js","assets/settings-store-_s4xFcFq.js","assets/streaming-store-QQvg1cS-.js","assets/tab-store-B2ip0-Mv.js","assets/apply-theme-BVXAUYoN.js","assets/resolve-theme-CMp5xxCW.js","assets/index-B9Wbjl0o.css","assets/use-remote-desktop-display-choice-BnVT4dhX.js","assets/hand-CIPALZsE.js","assets/keyboard-BLwfiRkT.js"])))=>i.map(i=>d[i]);
2
+ import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{C as t,S as n}from"./vendor-markdown-CuWCHIVb.js";import{ft as r}from"./vendor-ui-BBdkypKW.js";import"./api-client-DwXlVfXP.js";import{q as i}from"./vendor-mermaid-CfY1-PkA.js";import"./settings-store-_s4xFcFq.js";import{n as a}from"./portal-container-context-DeLx1cOI.js";import"./panel-store-D42k25jy.js";import"./window-store-CfxP5yor.js";import{b as o}from"./index-DVNJ2W5R.js";import"./run-in-terminal-DoTOtgQS.js";import{n as s,t as c}from"./remote-desktop-readiness-gate-6reSZvad.js";var l=e(t(),1),u=e(r(),1),d=n(),f=(0,l.lazy)(()=>i(()=>import(`./remote-desktop-mobile-view-Gk8UCVIx.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47])));function p(){let e=o(e=>e.isOpen),t=o(e=>e.close),n=a();return e?(0,u.createPortal)((0,d.jsx)(`div`,{className:`fixed inset-0 z-[45] bg-black`,"data-testid":`remote-desktop-mobile-sheet`,children:(0,d.jsx)(s,{onCancel:t,children:(0,d.jsx)(c,{onCancel:t,children:(0,d.jsx)(l.Suspense,{fallback:(0,d.jsx)(`div`,{className:`flex h-full items-center justify-center text-sm text-text-2`,children:`Loading…`}),children:(0,d.jsx)(f,{onClose:t})})})})}),n??document.getElementById(`root`)??document.body):null}export{p as RemoteDesktopMobileSheet};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{S as t,x as n}from"./vendor-markdown-Ls5AcU91.js";import"./vendor-ui-CaeeFO0B.js";import{t as r}from"./createLucideIcon-D8pyde1A.js";import{a as i,c as a,i as o,n as s,o as c,s as l,t as u}from"./use-remote-desktop-display-choice-DSqF1Rgx.js";import{t as d}from"./hand-x0ejq3fS.js";import{t as f}from"./keyboard-DiOYrs6C.js";import{t as p}from"./monitor-C835ucWH.js";import{t as m}from"./x-CxoBA0po.js";import"./api-client-CEYCBt_0.js";import"./vendor-mermaid-CfY1-PkA.js";import{t as h}from"./settings-store-CzLnTR8p.js";import{n as g}from"./utils-IrnQujwR.js";import{t as _}from"./use-visual-viewport-Bfl3Bxxb.js";import"./ws-auth-D111jj32.js";import{An as v,Jn as y}from"./index-Cx1meAwb.js";var b=r(`mouse-pointer-2`,[[`path`,{d:`M4.037 4.688a.495.495 0 0 1 .651-.651l16 6.5a.5.5 0 0 1-.063.947l-6.124 1.58a2 2 0 0 0-1.438 1.435l-1.579 6.126a.5.5 0 0 1-.947.063z`,key:`edeuup`}]]),x=e(t(),1);function S(e,t,n=10,r=300){let i=Math.hypot(t.x-e.x,t.y-e.y),a=t.t-e.t;return i<=n&&a<=r}function C(e,t,n=15){return Math.abs(t-e)>n?`pinch`:`scroll`}function w(e,t){return Math.hypot(t.x-e.x,t.y-e.y)}function T(e,t){return{x:(e.x+t.x)/2,y:(e.y+t.y)/2}}function E(e,t,n){return Math.min(Math.max(e,t),n)}function D(e,t,n){return[{type:`pointer`,xFrac:e,yFrac:t,button:n,down:!0},{type:`pointer`,xFrac:e,yFrac:t,button:n,down:!1}]}function O(e,t,n){return{start:{x:e,y:t,t:performance.now()},last:{x:e,y:t},moved:!1,rect:n}}function k(e,t,n,r,i,a){let s=Math.hypot(t-e.start.x,n-e.start.y);if(r===`touch`){if(!e.moved&&s>10){e.moved=!0;let r=o(e.start.x,e.start.y,e.rect,i);return e.last={x:t,y:n},{message:{type:`pointer`,xFrac:r.xFrac,yFrac:r.yFrac,button:`left`,down:!0}}}if(e.last={x:t,y:n},!e.moved)return{};let r=o(t,n,e.rect,i);return{message:{type:`pointer`,xFrac:r.xFrac,yFrac:r.yFrac,button:null,down:null}}}let c=(t-e.last.x)/i.scale,l=(n-e.last.y)/i.scale;return s>10&&(e.moved=!0),e.last={x:t,y:n},{cursor:{xFrac:E(a.xFrac+c/e.rect.width,0,1),yFrac:E(a.yFrac+l/e.rect.height,0,1)},sendCursorMove:!0}}function A(e,t,n,r,i,a){let s={x:t,y:n,t:performance.now()},c=S(e.start,s,10,300);if(r===`touch`){let r=o(t,n,e.rect,i);return!e.moved&&c?D(r.xFrac,r.yFrac,`left`):e.moved?[{type:`pointer`,xFrac:r.xFrac,yFrac:r.yFrac,button:`left`,down:!1}]:[]}return!e.moved&&c?D(a.xFrac,a.yFrac,`left`):[]}function j(e,t,n){let r=T(e,t);return{startDistance:w(e,t),startMid:r,lastMid:r,startScale:n,startTime:performance.now(),gesture:null}}function M(e,t,n,r){let i=w(t,n),a=T(t,n);if(e.gesture===null){let t=Math.abs(i-e.startDistance),n=w(e.startMid,a);if(t>15)e.gesture=C(e.startDistance,i,15);else if(n>15)e.gesture=`scroll`;else return e.lastMid=a,{}}let o;if(e.gesture===`pinch`)o={transform:{scale:E(e.startScale*(i/e.startDistance),1,4),panX:r.panX,panY:r.panY}};else if(r.scale>1.01){let t=a.x-e.lastMid.x,n=a.y-e.lastMid.y;o={transform:{scale:r.scale,panX:r.panX+t,panY:r.panY+n}}}else o={wheelDeltaPx:a.y-e.lastMid.y};return e.lastMid=a,o}function N(e,t,n){if(e.gesture===null&&performance.now()-e.startTime<=300){let r=o(e.lastMid.x,e.lastMid.y,t,n);return D(r.xFrac,r.yFrac,`right`)}return[]}var P={scale:1,panX:0,panY:0},F=40,I=120;function L({containerRef:e,canvasRef:t,mode:n,sendMessage:r,enabled:a}){let[o,s]=(0,x.useState)(P),[c,l]=(0,x.useState)({xFrac:.5,yFrac:.5}),u=(0,x.useRef)(o),d=(0,x.useRef)(c),f=(0,x.useRef)(n);f.current=n;let p=(0,x.useRef)({transform:null,cursor:null,sendCursorMove:!1,wheelPx:0}),m=(0,x.useRef)(0),h=(0,x.useCallback)(()=>{m.current=0;let e=p.current;e.transform&&=(u.current=e.transform,s(e.transform),null),e.cursor&&(d.current=e.cursor,l(e.cursor),e.sendCursorMove&&r({type:`pointer`,xFrac:e.cursor.xFrac,yFrac:e.cursor.yFrac,button:null,down:null}),e.cursor=null,e.sendCursorMove=!1),e.wheelPx!==0&&(r({type:`wheel`,dy:-(e.wheelPx/F)*I}),e.wheelPx=0)},[r]),g=(0,x.useCallback)(()=>{m.current||=requestAnimationFrame(h)},[h]),_=(0,x.useCallback)(()=>{u.current=P,s(P)},[]);return(0,x.useEffect)(()=>{let n=e.current;if(!n||!a)return;let o=null,s=null,c=e=>e.forEach(r),l=()=>{let e=n.getBoundingClientRect(),r=t.current;return!r||!r.width||!r.height?e:i(e,r.width,r.height)},h=e=>{e.preventDefault(),e.stopPropagation();let t=l();if(e.touches.length===1){s=null;let n=e.touches[0];o=O(n.clientX,n.clientY,t)}else if(e.touches.length===2){o=null;let[t,n]=[e.touches[0],e.touches[1]];s=j({x:t.clientX,y:t.clientY},{x:n.clientX,y:n.clientY},u.current.scale)}else o=null,s=null},_=e=>{if(e.preventDefault(),e.stopPropagation(),o&&e.touches.length===1){let t=e.touches[0],n=k(o,t.clientX,t.clientY,f.current,u.current,d.current);n.message&&r(n.message),n.cursor&&(d.current=n.cursor,p.current.cursor=n.cursor,p.current.sendCursorMove=!!n.sendCursorMove,g());return}if(s&&e.touches.length===2){let[t,n]=[e.touches[0],e.touches[1]],r=M(s,{x:t.clientX,y:t.clientY},{x:n.clientX,y:n.clientY},u.current);r.transform&&(u.current=r.transform,p.current.transform=r.transform,g()),r.wheelDeltaPx&&(p.current.wheelPx+=r.wheelDeltaPx,g())}},v=e=>{e.preventDefault(),e.stopPropagation();let t=e.changedTouches[0];if(o){let e=t?t.clientX:o.last.x,n=t?t.clientY:o.last.y;c(A(o,e,n,f.current,u.current,d.current)),o=null}s&&=(c(N(s,l(),u.current)),null)},y=e=>{e.stopPropagation(),o?.moved&&f.current===`touch`&&c(A(o,o.last.x,o.last.y,`touch`,u.current,d.current)),o=null,s=null};return n.addEventListener(`touchstart`,h,{passive:!1}),n.addEventListener(`touchmove`,_,{passive:!1}),n.addEventListener(`touchend`,v,{passive:!1}),n.addEventListener(`touchcancel`,y,{passive:!1}),()=>{m.current&&cancelAnimationFrame(m.current),n.removeEventListener(`touchstart`,h),n.removeEventListener(`touchmove`,_),n.removeEventListener(`touchend`,v),n.removeEventListener(`touchcancel`,y)}},[e,t,a,r,g]),{transform:o,virtualCursor:n===`mouse`?c:null,resetZoom:_}}function R(e,t,n){let r=e=>{n({type:`key`,code:e,down:!0}),n({type:`key`,code:e,down:!1})};switch(e){case`insertText`:return t&&n({type:`text`,text:t}),!0;case`insertLineBreak`:case`insertParagraph`:return r(`Enter`),!0;case`deleteContentBackward`:return r(`Backspace`),!0;case`deleteContentForward`:return r(`Delete`),!0;default:return!1}}function z(e,t){let n=(0,x.useRef)(null);return(0,x.useEffect)(()=>{let r=n.current;if(!r||!t)return;let i=()=>e({type:`releaseAll`}),a=e=>e.code!==``&&e.key!==`Unidentified`,o=t=>{a(t)&&(t.preventDefault(),e({type:`key`,code:t.code,down:!0}))},s=t=>{a(t)&&(t.preventDefault(),e({type:`key`,code:t.code,down:!1}))},c=t=>{R(t.inputType,t.data,e)&&t.preventDefault()},l=t=>{t.data&&e({type:`text`,text:t.data}),r.value=``},u=()=>i(),d=()=>{document.hidden&&i()};return r.addEventListener(`keydown`,o),r.addEventListener(`keyup`,s),r.addEventListener(`beforeinput`,c),r.addEventListener(`compositionend`,l),r.addEventListener(`blur`,u),document.addEventListener(`visibilitychange`,d),()=>{r.removeEventListener(`keydown`,o),r.removeEventListener(`keyup`,s),r.removeEventListener(`beforeinput`,c),r.removeEventListener(`compositionend`,l),r.removeEventListener(`blur`,u),document.removeEventListener(`visibilitychange`,d),i()}},[t,e]),{inputRef:n,show:(0,x.useCallback)(()=>n.current?.focus(),[])}}var B=n();function V({onClick:e,label:t,active:n,children:r}){return(0,B.jsxs)(`button`,{type:`button`,onClick:e,"aria-label":t,className:g(`flex min-h-11 min-w-11 flex-1 flex-col items-center justify-center gap-0.5 rounded-lg py-1.5 text-[10px]`,`text-white/80 active:bg-white/10 transition-colors`,n&&`bg-white/15 text-white`),children:[r,(0,B.jsx)(`span`,{children:t})]})}function H({displayLabel:e,onNextDisplay:t,mode:n,onToggleMode:r,onOpenKeyboard:i,onResetZoom:o,onClose:s}){let c=h(e=>e.remoteDesktopStatsVisible),l=h(e=>e.toggleRemoteDesktopStatsVisible);return(0,B.jsxs)(`div`,{className:`flex shrink-0 items-stretch gap-1 border-t border-white/10 bg-black/90 px-2 pb-[max(0.375rem,env(safe-area-inset-bottom))] pt-1.5`,"data-testid":`remote-desktop-mobile-toolbar`,children:[(0,B.jsx)(V,{onClick:r,label:n===`mouse`?`Mouse`:`Touch`,active:!0,children:n===`mouse`?(0,B.jsx)(b,{className:`size-5`}):(0,B.jsx)(d,{className:`size-5`})}),(0,B.jsx)(V,{onClick:i,label:`Keyboard`,children:(0,B.jsx)(f,{className:`size-5`})}),(0,B.jsx)(V,{onClick:o,label:`Reset zoom`,children:(0,B.jsx)(v,{className:`size-5`})}),e!==null&&(0,B.jsx)(V,{onClick:t,label:e.length>10?`${e.slice(0,9)}…`:e,children:(0,B.jsx)(p,{className:`size-5`})}),(0,B.jsx)(V,{onClick:l,label:`Stats`,active:c,children:(0,B.jsx)(a,{className:`size-5`})}),(0,B.jsx)(V,{onClick:s,label:`Close`,children:(0,B.jsx)(m,{className:`size-5`})})]})}var U=[{label:`Ctrl`,code:`ControlLeft`},{label:`Alt`,code:`AltLeft`},{label:`Shift`,code:`ShiftLeft`},{label:`Win`,code:`MetaLeft`}],W=[{label:`Esc`,code:`Escape`},{label:`Tab`,code:`Tab`},{label:`←`,code:`ArrowLeft`},{label:`↑`,code:`ArrowUp`},{label:`↓`,code:`ArrowDown`},{label:`→`,code:`ArrowRight`}],G=[{label:`Ctrl+C`,codes:[`ControlLeft`,`KeyC`]},{label:`Ctrl+V`,codes:[`ControlLeft`,`KeyV`]},{label:`Ctrl+Z`,codes:[`ControlLeft`,`KeyZ`]},{label:`Ctrl+A`,codes:[`ControlLeft`,`KeyA`]},{label:`Alt+Tab`,codes:[`AltLeft`,`Tab`]},{label:`Ctrl+Alt+Del`,codes:[`ControlLeft`,`AltLeft`,`Delete`]}];function K({onClick:e,active:t,className:n,children:r}){return(0,B.jsx)(`button`,{type:`button`,onClick:e,className:g(`min-h-11 min-w-11 shrink-0 whitespace-nowrap rounded-md px-2.5 text-xs font-medium text-white/80`,`active:bg-white/15 transition-colors`,t&&`bg-primary text-primary-foreground`,n),children:r})}function q({sendMessage:e}){let[t,n]=(0,x.useState)(new Set),r=(0,x.useRef)(t);r.current=t,(0,x.useEffect)(()=>()=>{r.current.forEach(t=>e({type:`key`,code:t,down:!1}))},[e]);let i=(0,x.useCallback)(t=>{n(n=>{let r=n.has(t);e({type:`key`,code:t,down:!r});let i=new Set(n);return r?i.delete(t):i.add(t),i})},[e]),a=(0,x.useCallback)(t=>{e({type:`key`,code:t,down:!0}),e({type:`key`,code:t,down:!1})},[e]),o=(0,x.useCallback)(t=>{t.forEach(t=>e({type:`key`,code:t,down:!0})),[...t].reverse().forEach(t=>e({type:`key`,code:t,down:!1}))},[e]);return(0,B.jsxs)(`div`,{className:`flex shrink-0 gap-1 overflow-x-auto border-t border-white/10 bg-black/90 px-2 py-1.5`,"data-testid":`remote-desktop-mobile-key-bar`,children:[U.map(e=>(0,B.jsx)(K,{onClick:()=>i(e.code),active:t.has(e.code),children:e.label},e.code)),(0,B.jsx)(`div`,{className:`mx-0.5 w-px shrink-0 bg-white/10`}),W.map(e=>(0,B.jsx)(K,{onClick:()=>a(e.code),children:e.label},e.code)),(0,B.jsx)(`div`,{className:`mx-0.5 w-px shrink-0 bg-white/10`}),G.map(e=>(0,B.jsx)(K,{onClick:()=>o(e.codes),children:e.label},e.label))]})}function J({onClose:e}){let t=(0,x.useRef)(null),n=(0,x.useRef)(null),[r,a]=(0,x.useState)(`mouse`),[o,d]=(0,x.useState)(!1),f=u(),{connState:p,errorMessage:m,decoderStatus:h,decoderErrorMessage:g,sendMessage:v,reconnect:b,getTotalBytes:S,getFrameCount:C}=c(n,{displayId:f.displayId}),w=p===`streaming`,{transform:T,virtualCursor:E,resetZoom:D}=L({containerRef:t,canvasRef:n,mode:r,sendMessage:v,enabled:w}),{inputRef:O,show:k}=z(v,w),A=_(!0)?.keyboardInset??0,j=(0,x.useCallback)(()=>a(e=>e===`mouse`?`touch`:`mouse`),[]),M=(0,x.useCallback)(()=>{k(),d(!0)},[k]),N=h===`unsupported`?g:p===`error`?m:p===`closed`?`Disconnected`:p===`connecting`?`Connecting…`:null,P={transform:`translate(${T.panX}px, ${T.panY}px) scale(${T.scale})`},F=`${(E?.xFrac??.5)*100}%`,I=`${(E?.yFrac??.5)*100}%`;if(E&&t.current&&n.current?.width&&n.current.height){let e=t.current.getBoundingClientRect(),r=i({left:0,top:0,width:e.width,height:e.height},n.current.width,n.current.height);F=`${r.left+E.xFrac*r.width}px`,I=`${r.top+E.yFrac*r.height}px`}return(0,B.jsxs)(`div`,{className:`relative h-full w-full bg-black`,"data-testid":`remote-desktop-mobile-view`,"data-conn-state":p,children:[(0,B.jsxs)(`div`,{ref:t,className:`absolute inset-x-0 top-0 flex items-center justify-center overflow-hidden`,style:{touchAction:`none`,bottom:A},"data-testid":`remote-desktop-mobile-stage-container`,children:[(0,B.jsxs)(`div`,{className:`relative flex h-full w-full items-center justify-center`,style:P,children:[(0,B.jsx)(`canvas`,{ref:n,"data-testid":`remote-desktop-canvas`,className:`block h-full w-full min-h-0 min-w-0 object-contain outline-none`}),r===`mouse`&&E&&w&&(0,B.jsx)(`div`,{className:`pointer-events-none absolute rounded-full border-2 border-white bg-primary shadow-[0_0_0_1px_rgba(0,0,0,0.6)]`,style:{left:F,top:I,width:14,height:14,transform:`translate(-50%, -50%) scale(${1/T.scale})`},"data-testid":`remote-desktop-virtual-cursor`})]}),N&&(0,B.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center gap-3 bg-black/70 text-sm text-white`,children:[(0,B.jsx)(l,{className:`size-6 opacity-70`}),(0,B.jsx)(`span`,{className:`max-w-sm px-4 text-center`,children:N}),(p===`error`||p===`closed`)&&h!==`unsupported`&&(0,B.jsxs)(`button`,{onClick:b,className:`flex items-center gap-1.5 rounded-md bg-white/10 px-3 py-1.5 hover:bg-white/20`,children:[(0,B.jsx)(y,{className:`size-3.5`}),` Reconnect`]})]}),(0,B.jsx)(`input`,{ref:O,type:`text`,autoComplete:`off`,autoCapitalize:`off`,autoCorrect:`off`,spellCheck:!1,className:`absolute size-px opacity-0`,"aria-hidden":`true`,tabIndex:-1,onBlur:()=>d(!1),"data-testid":`remote-desktop-virtual-keyboard-input`})]}),(0,B.jsxs)(`div`,{className:`absolute inset-x-0 bottom-0`,style:A>0?{transform:`translateY(-${A}px)`}:void 0,"data-testid":`remote-desktop-mobile-bottom-bar`,children:[o&&(0,B.jsx)(q,{sendMessage:v}),(0,B.jsx)(H,{displayLabel:f.displays.length>1?f.current?.label??null:null,onNextDisplay:f.next,mode:r,onToggleMode:j,onOpenKeyboard:M,onResetZoom:D,onClose:e})]}),(0,B.jsx)(s,{canvasRef:n,getFrameCount:C,getTotalBytes:S,positionClassName:`left-1 top-[calc(env(safe-area-inset-top,0px)+2.75rem)]`})]})}export{J as default};
1
+ import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{C as t,S as n}from"./vendor-markdown-CuWCHIVb.js";import"./vendor-ui-BBdkypKW.js";import{t as r}from"./createLucideIcon-D6fVXe3s.js";import{a as i,c as a,i as o,n as s,o as c,s as l,t as u}from"./use-remote-desktop-display-choice-BnVT4dhX.js";import{t as d}from"./hand-CIPALZsE.js";import{t as f}from"./keyboard-BLwfiRkT.js";import{t as p}from"./monitor-CG69bSMW.js";import{t as m}from"./x-Bdaog6Az.js";import"./api-client-DwXlVfXP.js";import"./vendor-mermaid-CfY1-PkA.js";import{t as h}from"./settings-store-_s4xFcFq.js";import{n as g}from"./utils-IrnQujwR.js";import{t as _}from"./use-visual-viewport-CNdG4QHH.js";import"./ws-auth-FRzMmfQx.js";import{An as v,Jn as y}from"./index-DVNJ2W5R.js";var b=r(`mouse-pointer-2`,[[`path`,{d:`M4.037 4.688a.495.495 0 0 1 .651-.651l16 6.5a.5.5 0 0 1-.063.947l-6.124 1.58a2 2 0 0 0-1.438 1.435l-1.579 6.126a.5.5 0 0 1-.947.063z`,key:`edeuup`}]]),x=e(t(),1);function S(e,t,n=10,r=300){let i=Math.hypot(t.x-e.x,t.y-e.y),a=t.t-e.t;return i<=n&&a<=r}function C(e,t,n=15){return Math.abs(t-e)>n?`pinch`:`scroll`}function w(e,t){return Math.hypot(t.x-e.x,t.y-e.y)}function T(e,t){return{x:(e.x+t.x)/2,y:(e.y+t.y)/2}}function E(e,t,n){return Math.min(Math.max(e,t),n)}function D(e,t,n){return[{type:`pointer`,xFrac:e,yFrac:t,button:n,down:!0},{type:`pointer`,xFrac:e,yFrac:t,button:n,down:!1}]}function O(e,t,n){return{start:{x:e,y:t,t:performance.now()},last:{x:e,y:t},moved:!1,rect:n}}function k(e,t,n,r,i,a){let s=Math.hypot(t-e.start.x,n-e.start.y);if(r===`touch`){if(!e.moved&&s>10){e.moved=!0;let r=o(e.start.x,e.start.y,e.rect,i);return e.last={x:t,y:n},{message:{type:`pointer`,xFrac:r.xFrac,yFrac:r.yFrac,button:`left`,down:!0}}}if(e.last={x:t,y:n},!e.moved)return{};let r=o(t,n,e.rect,i);return{message:{type:`pointer`,xFrac:r.xFrac,yFrac:r.yFrac,button:null,down:null}}}let c=(t-e.last.x)/i.scale,l=(n-e.last.y)/i.scale;return s>10&&(e.moved=!0),e.last={x:t,y:n},{cursor:{xFrac:E(a.xFrac+c/e.rect.width,0,1),yFrac:E(a.yFrac+l/e.rect.height,0,1)},sendCursorMove:!0}}function A(e,t,n,r,i,a){let s={x:t,y:n,t:performance.now()},c=S(e.start,s,10,300);if(r===`touch`){let r=o(t,n,e.rect,i);return!e.moved&&c?D(r.xFrac,r.yFrac,`left`):e.moved?[{type:`pointer`,xFrac:r.xFrac,yFrac:r.yFrac,button:`left`,down:!1}]:[]}return!e.moved&&c?D(a.xFrac,a.yFrac,`left`):[]}function j(e,t,n){let r=T(e,t);return{startDistance:w(e,t),startMid:r,lastMid:r,startScale:n,startTime:performance.now(),gesture:null}}function M(e,t,n,r){let i=w(t,n),a=T(t,n);if(e.gesture===null){let t=Math.abs(i-e.startDistance),n=w(e.startMid,a);if(t>15)e.gesture=C(e.startDistance,i,15);else if(n>15)e.gesture=`scroll`;else return e.lastMid=a,{}}let o;if(e.gesture===`pinch`)o={transform:{scale:E(e.startScale*(i/e.startDistance),1,4),panX:r.panX,panY:r.panY}};else if(r.scale>1.01){let t=a.x-e.lastMid.x,n=a.y-e.lastMid.y;o={transform:{scale:r.scale,panX:r.panX+t,panY:r.panY+n}}}else o={wheelDeltaPx:a.y-e.lastMid.y};return e.lastMid=a,o}function N(e,t,n){if(e.gesture===null&&performance.now()-e.startTime<=300){let r=o(e.lastMid.x,e.lastMid.y,t,n);return D(r.xFrac,r.yFrac,`right`)}return[]}var P={scale:1,panX:0,panY:0},F=40,I=120;function L({containerRef:e,canvasRef:t,mode:n,sendMessage:r,enabled:a}){let[o,s]=(0,x.useState)(P),[c,l]=(0,x.useState)({xFrac:.5,yFrac:.5}),u=(0,x.useRef)(o),d=(0,x.useRef)(c),f=(0,x.useRef)(n);f.current=n;let p=(0,x.useRef)({transform:null,cursor:null,sendCursorMove:!1,wheelPx:0}),m=(0,x.useRef)(0),h=(0,x.useCallback)(()=>{m.current=0;let e=p.current;e.transform&&=(u.current=e.transform,s(e.transform),null),e.cursor&&(d.current=e.cursor,l(e.cursor),e.sendCursorMove&&r({type:`pointer`,xFrac:e.cursor.xFrac,yFrac:e.cursor.yFrac,button:null,down:null}),e.cursor=null,e.sendCursorMove=!1),e.wheelPx!==0&&(r({type:`wheel`,dy:-(e.wheelPx/F)*I}),e.wheelPx=0)},[r]),g=(0,x.useCallback)(()=>{m.current||=requestAnimationFrame(h)},[h]),_=(0,x.useCallback)(()=>{u.current=P,s(P)},[]);return(0,x.useEffect)(()=>{let n=e.current;if(!n||!a)return;let o=null,s=null,c=e=>e.forEach(r),l=()=>{let e=n.getBoundingClientRect(),r=t.current;return!r||!r.width||!r.height?e:i(e,r.width,r.height)},h=e=>{e.preventDefault(),e.stopPropagation();let t=l();if(e.touches.length===1){s=null;let n=e.touches[0];o=O(n.clientX,n.clientY,t)}else if(e.touches.length===2){o=null;let[t,n]=[e.touches[0],e.touches[1]];s=j({x:t.clientX,y:t.clientY},{x:n.clientX,y:n.clientY},u.current.scale)}else o=null,s=null},_=e=>{if(e.preventDefault(),e.stopPropagation(),o&&e.touches.length===1){let t=e.touches[0],n=k(o,t.clientX,t.clientY,f.current,u.current,d.current);n.message&&r(n.message),n.cursor&&(d.current=n.cursor,p.current.cursor=n.cursor,p.current.sendCursorMove=!!n.sendCursorMove,g());return}if(s&&e.touches.length===2){let[t,n]=[e.touches[0],e.touches[1]],r=M(s,{x:t.clientX,y:t.clientY},{x:n.clientX,y:n.clientY},u.current);r.transform&&(u.current=r.transform,p.current.transform=r.transform,g()),r.wheelDeltaPx&&(p.current.wheelPx+=r.wheelDeltaPx,g())}},v=e=>{e.preventDefault(),e.stopPropagation();let t=e.changedTouches[0];if(o){let e=t?t.clientX:o.last.x,n=t?t.clientY:o.last.y;c(A(o,e,n,f.current,u.current,d.current)),o=null}s&&=(c(N(s,l(),u.current)),null)},y=e=>{e.stopPropagation(),o?.moved&&f.current===`touch`&&c(A(o,o.last.x,o.last.y,`touch`,u.current,d.current)),o=null,s=null};return n.addEventListener(`touchstart`,h,{passive:!1}),n.addEventListener(`touchmove`,_,{passive:!1}),n.addEventListener(`touchend`,v,{passive:!1}),n.addEventListener(`touchcancel`,y,{passive:!1}),()=>{m.current&&cancelAnimationFrame(m.current),n.removeEventListener(`touchstart`,h),n.removeEventListener(`touchmove`,_),n.removeEventListener(`touchend`,v),n.removeEventListener(`touchcancel`,y)}},[e,t,a,r,g]),{transform:o,virtualCursor:n===`mouse`?c:null,resetZoom:_}}function R(e,t,n){let r=e=>{n({type:`key`,code:e,down:!0}),n({type:`key`,code:e,down:!1})};switch(e){case`insertText`:return t&&n({type:`text`,text:t}),!0;case`insertLineBreak`:case`insertParagraph`:return r(`Enter`),!0;case`deleteContentBackward`:return r(`Backspace`),!0;case`deleteContentForward`:return r(`Delete`),!0;default:return!1}}function z(e,t){let n=(0,x.useRef)(null);return(0,x.useEffect)(()=>{let r=n.current;if(!r||!t)return;let i=()=>e({type:`releaseAll`}),a=e=>e.code!==``&&e.key!==`Unidentified`,o=t=>{a(t)&&(t.preventDefault(),e({type:`key`,code:t.code,down:!0}))},s=t=>{a(t)&&(t.preventDefault(),e({type:`key`,code:t.code,down:!1}))},c=t=>{R(t.inputType,t.data,e)&&t.preventDefault()},l=t=>{t.data&&e({type:`text`,text:t.data}),r.value=``},u=()=>i(),d=()=>{document.hidden&&i()};return r.addEventListener(`keydown`,o),r.addEventListener(`keyup`,s),r.addEventListener(`beforeinput`,c),r.addEventListener(`compositionend`,l),r.addEventListener(`blur`,u),document.addEventListener(`visibilitychange`,d),()=>{r.removeEventListener(`keydown`,o),r.removeEventListener(`keyup`,s),r.removeEventListener(`beforeinput`,c),r.removeEventListener(`compositionend`,l),r.removeEventListener(`blur`,u),document.removeEventListener(`visibilitychange`,d),i()}},[t,e]),{inputRef:n,show:(0,x.useCallback)(()=>n.current?.focus(),[])}}var B=n();function V({onClick:e,label:t,active:n,children:r}){return(0,B.jsxs)(`button`,{type:`button`,onClick:e,"aria-label":t,className:g(`flex min-h-11 min-w-11 flex-1 flex-col items-center justify-center gap-0.5 rounded-lg py-1.5 text-[10px]`,`text-white/80 active:bg-white/10 transition-colors`,n&&`bg-white/15 text-white`),children:[r,(0,B.jsx)(`span`,{children:t})]})}function H({displayLabel:e,onNextDisplay:t,mode:n,onToggleMode:r,onOpenKeyboard:i,onResetZoom:o,onClose:s}){let c=h(e=>e.remoteDesktopStatsVisible),l=h(e=>e.toggleRemoteDesktopStatsVisible);return(0,B.jsxs)(`div`,{className:`flex shrink-0 items-stretch gap-1 border-t border-white/10 bg-black/90 px-2 pb-[max(0.375rem,env(safe-area-inset-bottom))] pt-1.5`,"data-testid":`remote-desktop-mobile-toolbar`,children:[(0,B.jsx)(V,{onClick:r,label:n===`mouse`?`Mouse`:`Touch`,active:!0,children:n===`mouse`?(0,B.jsx)(b,{className:`size-5`}):(0,B.jsx)(d,{className:`size-5`})}),(0,B.jsx)(V,{onClick:i,label:`Keyboard`,children:(0,B.jsx)(f,{className:`size-5`})}),(0,B.jsx)(V,{onClick:o,label:`Reset zoom`,children:(0,B.jsx)(v,{className:`size-5`})}),e!==null&&(0,B.jsx)(V,{onClick:t,label:e.length>10?`${e.slice(0,9)}…`:e,children:(0,B.jsx)(p,{className:`size-5`})}),(0,B.jsx)(V,{onClick:l,label:`Stats`,active:c,children:(0,B.jsx)(a,{className:`size-5`})}),(0,B.jsx)(V,{onClick:s,label:`Close`,children:(0,B.jsx)(m,{className:`size-5`})})]})}var U=[{label:`Ctrl`,code:`ControlLeft`},{label:`Alt`,code:`AltLeft`},{label:`Shift`,code:`ShiftLeft`},{label:`Win`,code:`MetaLeft`}],W=[{label:`Esc`,code:`Escape`},{label:`Tab`,code:`Tab`},{label:`←`,code:`ArrowLeft`},{label:`↑`,code:`ArrowUp`},{label:`↓`,code:`ArrowDown`},{label:`→`,code:`ArrowRight`}],G=[{label:`Ctrl+C`,codes:[`ControlLeft`,`KeyC`]},{label:`Ctrl+V`,codes:[`ControlLeft`,`KeyV`]},{label:`Ctrl+Z`,codes:[`ControlLeft`,`KeyZ`]},{label:`Ctrl+A`,codes:[`ControlLeft`,`KeyA`]},{label:`Alt+Tab`,codes:[`AltLeft`,`Tab`]},{label:`Ctrl+Alt+Del`,codes:[`ControlLeft`,`AltLeft`,`Delete`]}];function K({onClick:e,active:t,className:n,children:r}){return(0,B.jsx)(`button`,{type:`button`,onClick:e,className:g(`min-h-11 min-w-11 shrink-0 whitespace-nowrap rounded-md px-2.5 text-xs font-medium text-white/80`,`active:bg-white/15 transition-colors`,t&&`bg-primary text-primary-foreground`,n),children:r})}function q({sendMessage:e}){let[t,n]=(0,x.useState)(new Set),r=(0,x.useRef)(t);r.current=t,(0,x.useEffect)(()=>()=>{r.current.forEach(t=>e({type:`key`,code:t,down:!1}))},[e]);let i=(0,x.useCallback)(t=>{n(n=>{let r=n.has(t);e({type:`key`,code:t,down:!r});let i=new Set(n);return r?i.delete(t):i.add(t),i})},[e]),a=(0,x.useCallback)(t=>{e({type:`key`,code:t,down:!0}),e({type:`key`,code:t,down:!1})},[e]),o=(0,x.useCallback)(t=>{t.forEach(t=>e({type:`key`,code:t,down:!0})),[...t].reverse().forEach(t=>e({type:`key`,code:t,down:!1}))},[e]);return(0,B.jsxs)(`div`,{className:`flex shrink-0 gap-1 overflow-x-auto border-t border-white/10 bg-black/90 px-2 py-1.5`,"data-testid":`remote-desktop-mobile-key-bar`,children:[U.map(e=>(0,B.jsx)(K,{onClick:()=>i(e.code),active:t.has(e.code),children:e.label},e.code)),(0,B.jsx)(`div`,{className:`mx-0.5 w-px shrink-0 bg-white/10`}),W.map(e=>(0,B.jsx)(K,{onClick:()=>a(e.code),children:e.label},e.code)),(0,B.jsx)(`div`,{className:`mx-0.5 w-px shrink-0 bg-white/10`}),G.map(e=>(0,B.jsx)(K,{onClick:()=>o(e.codes),children:e.label},e.label))]})}function J({onClose:e}){let t=(0,x.useRef)(null),n=(0,x.useRef)(null),[r,a]=(0,x.useState)(`mouse`),[o,d]=(0,x.useState)(!1),f=u(),{connState:p,errorMessage:m,decoderStatus:h,decoderErrorMessage:g,sendMessage:v,reconnect:b,getTotalBytes:S,getFrameCount:C}=c(n,{displayId:f.displayId}),w=p===`streaming`,{transform:T,virtualCursor:E,resetZoom:D}=L({containerRef:t,canvasRef:n,mode:r,sendMessage:v,enabled:w}),{inputRef:O,show:k}=z(v,w),A=_(!0)?.keyboardInset??0,j=(0,x.useCallback)(()=>a(e=>e===`mouse`?`touch`:`mouse`),[]),M=(0,x.useCallback)(()=>{k(),d(!0)},[k]),N=h===`unsupported`?g:p===`error`?m:p===`closed`?`Disconnected`:p===`connecting`?`Connecting…`:null,P={transform:`translate(${T.panX}px, ${T.panY}px) scale(${T.scale})`},F=`${(E?.xFrac??.5)*100}%`,I=`${(E?.yFrac??.5)*100}%`;if(E&&t.current&&n.current?.width&&n.current.height){let e=t.current.getBoundingClientRect(),r=i({left:0,top:0,width:e.width,height:e.height},n.current.width,n.current.height);F=`${r.left+E.xFrac*r.width}px`,I=`${r.top+E.yFrac*r.height}px`}return(0,B.jsxs)(`div`,{className:`relative h-full w-full bg-black`,"data-testid":`remote-desktop-mobile-view`,"data-conn-state":p,children:[(0,B.jsxs)(`div`,{ref:t,className:`absolute inset-x-0 top-0 flex items-center justify-center overflow-hidden`,style:{touchAction:`none`,bottom:A},"data-testid":`remote-desktop-mobile-stage-container`,children:[(0,B.jsxs)(`div`,{className:`relative flex h-full w-full items-center justify-center`,style:P,children:[(0,B.jsx)(`canvas`,{ref:n,"data-testid":`remote-desktop-canvas`,className:`block h-full w-full min-h-0 min-w-0 object-contain outline-none`}),r===`mouse`&&E&&w&&(0,B.jsx)(`div`,{className:`pointer-events-none absolute rounded-full border-2 border-white bg-primary shadow-[0_0_0_1px_rgba(0,0,0,0.6)]`,style:{left:F,top:I,width:14,height:14,transform:`translate(-50%, -50%) scale(${1/T.scale})`},"data-testid":`remote-desktop-virtual-cursor`})]}),N&&(0,B.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center gap-3 bg-black/70 text-sm text-white`,children:[(0,B.jsx)(l,{className:`size-6 opacity-70`}),(0,B.jsx)(`span`,{className:`max-w-sm px-4 text-center`,children:N}),(p===`error`||p===`closed`)&&h!==`unsupported`&&(0,B.jsxs)(`button`,{onClick:b,className:`flex items-center gap-1.5 rounded-md bg-white/10 px-3 py-1.5 hover:bg-white/20`,children:[(0,B.jsx)(y,{className:`size-3.5`}),` Reconnect`]})]}),(0,B.jsx)(`input`,{ref:O,type:`text`,autoComplete:`off`,autoCapitalize:`off`,autoCorrect:`off`,spellCheck:!1,className:`absolute size-px opacity-0`,"aria-hidden":`true`,tabIndex:-1,onBlur:()=>d(!1),"data-testid":`remote-desktop-virtual-keyboard-input`})]}),(0,B.jsxs)(`div`,{className:`absolute inset-x-0 bottom-0`,style:A>0?{transform:`translateY(-${A}px)`}:void 0,"data-testid":`remote-desktop-mobile-bottom-bar`,children:[o&&(0,B.jsx)(q,{sendMessage:v}),(0,B.jsx)(H,{displayLabel:f.displays.length>1?f.current?.label??null:null,onNextDisplay:f.next,mode:r,onToggleMode:j,onOpenKeyboard:M,onResetZoom:D,onClose:e})]}),(0,B.jsx)(s,{canvasRef:n,getFrameCount:C,getTotalBytes:S,positionClassName:`left-1 top-[calc(env(safe-area-inset-top,0px)+2.75rem)]`})]})}export{J as default};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{S as t,x as n}from"./vendor-markdown-Ls5AcU91.js";import{t as r}from"./circle-BCy0AUCo.js";import{t as i}from"./loader-circle-DPMrnLQ2.js";import{t as a}from"./settings-store-CzLnTR8p.js";import{Ar as o,Dr as s,Un as c,Wn as l,ir as u,y as d}from"./index-Cx1meAwb.js";import{r as f}from"./run-in-terminal-wHKwAnWP.js";var p=e(t(),1),m=n();function h({onCancel:e,children:t}){let n=a(e=>e.remoteDesktopWarningDismissed),r=a(e=>e.setRemoteDesktopWarningDismissed),[i,o]=(0,p.useState)(!1),[s,c]=(0,p.useState)(!1);if(n||i)return(0,m.jsx)(m.Fragment,{children:t});let d=()=>{s&&r(!0),o(!0)};return(0,m.jsx)(`div`,{className:`flex h-full w-full items-center justify-center overflow-y-auto bg-black p-4 text-white`,"data-testid":`remote-desktop-warning-gate`,children:(0,m.jsxs)(`div`,{className:`flex w-full max-w-sm flex-col gap-4 rounded-xl border border-white/10 bg-white/5 p-5`,children:[(0,m.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,m.jsx)(u,{className:`size-5 shrink-0 text-primary`}),(0,m.jsx)(`h2`,{className:`text-base font-semibold`,children:`Remote Desktop`}),(0,m.jsx)(`span`,{className:`ml-auto rounded-full bg-amber-500/20 px-2 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-amber-300`,children:`Beta`})]}),(0,m.jsxs)(`ul`,{className:`flex flex-col gap-2 text-sm text-white/80`,children:[(0,m.jsxs)(`li`,{className:`flex gap-2`,children:[(0,m.jsx)(l,{className:`mt-0.5 size-4 shrink-0 text-amber-300`}),(0,m.jsxs)(`span`,{children:[`This streams the host's `,(0,m.jsx)(`strong`,{children:`whole screen`}),` and lets you `,(0,m.jsx)(`strong`,{children:`move its mouse and type`}),` as if you were sitting at it. Anything you do here happens on the real desktop.`]})]}),(0,m.jsxs)(`li`,{className:`flex gap-2`,children:[(0,m.jsx)(l,{className:`mt-0.5 size-4 shrink-0 text-amber-300`}),(0,m.jsx)(`span`,{children:`Anyone signed in to this PPM can do the same. Avoid opening it over a public share link you don't fully trust; a private network (Tailscale, LAN) is safer.`})]}),(0,m.jsxs)(`li`,{className:`flex gap-2`,children:[(0,m.jsx)(l,{className:`mt-0.5 size-4 shrink-0 text-amber-300`}),(0,m.jsx)(`span`,{children:`Still beta: the host must be unlocked with an active session, UAC prompts stay hidden, and a person at the host will fight you for the cursor.`})]})]}),(0,m.jsxs)(`label`,{className:`flex min-h-11 cursor-pointer items-center gap-2 text-sm text-white/70`,children:[(0,m.jsx)(`input`,{type:`checkbox`,checked:s,onChange:e=>c(e.target.checked),className:`size-4 accent-primary`,"data-testid":`remote-desktop-warning-dont-show`}),`Don't show this again`]}),(0,m.jsxs)(`div`,{className:`flex gap-2`,children:[(0,m.jsx)(`button`,{type:`button`,onClick:e,className:`min-h-11 flex-1 rounded-md bg-white/10 px-3 text-sm hover:bg-white/20`,"data-testid":`remote-desktop-warning-cancel`,children:`Cancel`}),(0,m.jsx)(`button`,{type:`button`,onClick:d,className:`min-h-11 flex-1 rounded-md bg-primary px-3 text-sm font-medium text-primary-foreground hover:bg-primary/90`,"data-testid":`remote-desktop-warning-continue`,children:`Continue`})]})]})})}function g({onCancel:e,children:t}){let[n,r]=(0,p.useState)(!1),{caps:a,failed:o,runHostAction:s}=d(!n);if(n||a?.videoReady&&a.inputReady)return(0,m.jsx)(m.Fragment,{children:t});let c=a?.requirements.filter(e=>!e.ok)??[],l=!!a?.videoReady&&!a.inputReady,h=t=>{f(t),e()};return(0,m.jsx)(`div`,{className:`flex h-full w-full items-center justify-center overflow-y-auto bg-black p-4 text-white`,"data-testid":`remote-desktop-readiness-gate`,children:(0,m.jsxs)(`div`,{className:`flex w-full max-w-sm flex-col gap-4 rounded-xl border border-white/10 bg-white/5 p-5`,children:[(0,m.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,m.jsx)(u,{className:`size-5 shrink-0 text-primary`}),(0,m.jsx)(`h2`,{className:`text-base font-semibold`,children:`This host needs a few things`})]}),!a&&!o&&(0,m.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-white/70`,children:[(0,m.jsx)(i,{className:`size-4 animate-spin`}),` Checking the host…`]}),o&&(0,m.jsx)(`p`,{className:`text-sm text-red-300`,children:`Could not reach the host's remote-desktop service.`}),(0,m.jsx)(`ul`,{className:`flex flex-col gap-3`,children:a?.requirements.map(e=>(0,m.jsx)(_,{req:e,onHostAction:s,onTerminal:h},e.id))}),c.length>0&&(0,m.jsx)(`p`,{className:`text-xs text-white/50`,children:`Re-checking every few seconds — this updates by itself once fixed.`}),(0,m.jsxs)(`div`,{className:`flex gap-2`,children:[(0,m.jsx)(`button`,{type:`button`,onClick:e,className:`min-h-11 flex-1 rounded-md bg-white/10 px-3 text-sm hover:bg-white/20`,children:`Cancel`}),(0,m.jsx)(`button`,{type:`button`,disabled:!a?.videoReady,onClick:()=>r(!0),className:`min-h-11 flex-1 rounded-md bg-primary px-3 text-sm font-medium text-primary-foreground hover:bg-primary/90 disabled:cursor-not-allowed disabled:opacity-40`,"data-testid":`remote-desktop-readiness-continue`,children:l?`Continue (view only)`:`Continue`})]})]})})}function _({req:e,...t}){return(0,m.jsxs)(`li`,{className:`flex gap-2`,"data-testid":`remote-desktop-requirement-${e.id}`,"data-ok":e.ok,children:[e.ok?(0,m.jsx)(o,{className:`mt-0.5 size-4 shrink-0 text-emerald-400`}):(0,m.jsx)(r,{className:`mt-0.5 size-4 shrink-0 text-amber-300`}),(0,m.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-2`,children:[(0,m.jsxs)(`div`,{className:`text-sm font-medium`,children:[e.title,!e.ok&&(0,m.jsx)(`span`,{className:`ml-2 text-xs font-normal text-white/50`,children:e.gates===`video`?`required`:`for mouse & keyboard`})]}),!e.ok&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`p`,{className:`text-sm text-white/70`,children:e.detail}),(0,m.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:e.actions.map(n=>(0,m.jsx)(v,{action:n,reqId:e.id,...t},n.label))})]})]})]})}function v({action:e,reqId:t,onHostAction:n,onTerminal:r}){let i=`inline-flex min-h-11 items-center gap-1.5 rounded-md bg-white/10 px-3 text-sm hover:bg-white/20`;return e.kind===`terminal`?(0,m.jsxs)(`button`,{type:`button`,className:i,onClick:()=>r(e.command),title:e.command,children:[(0,m.jsx)(c,{className:`size-4`}),` `,e.label]}):e.kind===`link`?(0,m.jsxs)(`a`,{className:i,href:e.url,target:`_blank`,rel:`noreferrer`,children:[(0,m.jsx)(s,{className:`size-4`}),` `,e.label]}):(0,m.jsx)(`button`,{type:`button`,className:i,onClick:()=>void n(t,e.action),children:e.label})}export{h as n,g as t};
1
+ import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{C as t,S as n}from"./vendor-markdown-CuWCHIVb.js";import{t as r}from"./circle-OKk7s0DX.js";import{t as i}from"./loader-circle-DxI3O9_f.js";import{t as a}from"./settings-store-_s4xFcFq.js";import{Ar as o,Dr as s,Un as c,Wn as l,ir as u,y as d}from"./index-DVNJ2W5R.js";import{r as f}from"./run-in-terminal-DoTOtgQS.js";var p=e(t(),1),m=n();function h({onCancel:e,children:t}){let n=a(e=>e.remoteDesktopWarningDismissed),r=a(e=>e.setRemoteDesktopWarningDismissed),[i,o]=(0,p.useState)(!1),[s,c]=(0,p.useState)(!1);if(n||i)return(0,m.jsx)(m.Fragment,{children:t});let d=()=>{s&&r(!0),o(!0)};return(0,m.jsx)(`div`,{className:`flex h-full w-full items-center justify-center overflow-y-auto bg-black p-4 text-white`,"data-testid":`remote-desktop-warning-gate`,children:(0,m.jsxs)(`div`,{className:`flex w-full max-w-sm flex-col gap-4 rounded-xl border border-white/10 bg-white/5 p-5`,children:[(0,m.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,m.jsx)(u,{className:`size-5 shrink-0 text-primary`}),(0,m.jsx)(`h2`,{className:`text-base font-semibold`,children:`Remote Desktop`}),(0,m.jsx)(`span`,{className:`ml-auto rounded-full bg-amber-500/20 px-2 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-amber-300`,children:`Beta`})]}),(0,m.jsxs)(`ul`,{className:`flex flex-col gap-2 text-sm text-white/80`,children:[(0,m.jsxs)(`li`,{className:`flex gap-2`,children:[(0,m.jsx)(l,{className:`mt-0.5 size-4 shrink-0 text-amber-300`}),(0,m.jsxs)(`span`,{children:[`This streams the host's `,(0,m.jsx)(`strong`,{children:`whole screen`}),` and lets you `,(0,m.jsx)(`strong`,{children:`move its mouse and type`}),` as if you were sitting at it. Anything you do here happens on the real desktop.`]})]}),(0,m.jsxs)(`li`,{className:`flex gap-2`,children:[(0,m.jsx)(l,{className:`mt-0.5 size-4 shrink-0 text-amber-300`}),(0,m.jsx)(`span`,{children:`Anyone signed in to this PPM can do the same. Avoid opening it over a public share link you don't fully trust; a private network (Tailscale, LAN) is safer.`})]}),(0,m.jsxs)(`li`,{className:`flex gap-2`,children:[(0,m.jsx)(l,{className:`mt-0.5 size-4 shrink-0 text-amber-300`}),(0,m.jsx)(`span`,{children:`Still beta: the host must be unlocked with an active session, UAC prompts stay hidden, and a person at the host will fight you for the cursor.`})]})]}),(0,m.jsxs)(`label`,{className:`flex min-h-11 cursor-pointer items-center gap-2 text-sm text-white/70`,children:[(0,m.jsx)(`input`,{type:`checkbox`,checked:s,onChange:e=>c(e.target.checked),className:`size-4 accent-primary`,"data-testid":`remote-desktop-warning-dont-show`}),`Don't show this again`]}),(0,m.jsxs)(`div`,{className:`flex gap-2`,children:[(0,m.jsx)(`button`,{type:`button`,onClick:e,className:`min-h-11 flex-1 rounded-md bg-white/10 px-3 text-sm hover:bg-white/20`,"data-testid":`remote-desktop-warning-cancel`,children:`Cancel`}),(0,m.jsx)(`button`,{type:`button`,onClick:d,className:`min-h-11 flex-1 rounded-md bg-primary px-3 text-sm font-medium text-primary-foreground hover:bg-primary/90`,"data-testid":`remote-desktop-warning-continue`,children:`Continue`})]})]})})}function g({onCancel:e,children:t}){let[n,r]=(0,p.useState)(!1),{caps:a,failed:o,runHostAction:s}=d(!n);if(n||a?.videoReady&&a.inputReady)return(0,m.jsx)(m.Fragment,{children:t});let c=a?.requirements.filter(e=>!e.ok)??[],l=!!a?.videoReady&&!a.inputReady,h=t=>{f(t),e()};return(0,m.jsx)(`div`,{className:`flex h-full w-full items-center justify-center overflow-y-auto bg-black p-4 text-white`,"data-testid":`remote-desktop-readiness-gate`,children:(0,m.jsxs)(`div`,{className:`flex w-full max-w-sm flex-col gap-4 rounded-xl border border-white/10 bg-white/5 p-5`,children:[(0,m.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,m.jsx)(u,{className:`size-5 shrink-0 text-primary`}),(0,m.jsx)(`h2`,{className:`text-base font-semibold`,children:`This host needs a few things`})]}),!a&&!o&&(0,m.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-white/70`,children:[(0,m.jsx)(i,{className:`size-4 animate-spin`}),` Checking the host…`]}),o&&(0,m.jsx)(`p`,{className:`text-sm text-red-300`,children:`Could not reach the host's remote-desktop service.`}),(0,m.jsx)(`ul`,{className:`flex flex-col gap-3`,children:a?.requirements.map(e=>(0,m.jsx)(_,{req:e,onHostAction:s,onTerminal:h},e.id))}),c.length>0&&(0,m.jsx)(`p`,{className:`text-xs text-white/50`,children:`Re-checking every few seconds — this updates by itself once fixed.`}),(0,m.jsxs)(`div`,{className:`flex gap-2`,children:[(0,m.jsx)(`button`,{type:`button`,onClick:e,className:`min-h-11 flex-1 rounded-md bg-white/10 px-3 text-sm hover:bg-white/20`,children:`Cancel`}),(0,m.jsx)(`button`,{type:`button`,disabled:!a?.videoReady,onClick:()=>r(!0),className:`min-h-11 flex-1 rounded-md bg-primary px-3 text-sm font-medium text-primary-foreground hover:bg-primary/90 disabled:cursor-not-allowed disabled:opacity-40`,"data-testid":`remote-desktop-readiness-continue`,children:l?`Continue (view only)`:`Continue`})]})]})})}function _({req:e,...t}){return(0,m.jsxs)(`li`,{className:`flex gap-2`,"data-testid":`remote-desktop-requirement-${e.id}`,"data-ok":e.ok,children:[e.ok?(0,m.jsx)(o,{className:`mt-0.5 size-4 shrink-0 text-emerald-400`}):(0,m.jsx)(r,{className:`mt-0.5 size-4 shrink-0 text-amber-300`}),(0,m.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-2`,children:[(0,m.jsxs)(`div`,{className:`text-sm font-medium`,children:[e.title,!e.ok&&(0,m.jsx)(`span`,{className:`ml-2 text-xs font-normal text-white/50`,children:e.gates===`video`?`required`:`for mouse & keyboard`})]}),!e.ok&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`p`,{className:`text-sm text-white/70`,children:e.detail}),(0,m.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:e.actions.map(n=>(0,m.jsx)(v,{action:n,reqId:e.id,...t},n.label))})]})]})]})}function v({action:e,reqId:t,onHostAction:n,onTerminal:r}){let i=`inline-flex min-h-11 items-center gap-1.5 rounded-md bg-white/10 px-3 text-sm hover:bg-white/20`;return e.kind===`terminal`?(0,m.jsxs)(`button`,{type:`button`,className:i,onClick:()=>r(e.command),title:e.command,children:[(0,m.jsx)(c,{className:`size-4`}),` `,e.label]}):e.kind===`link`?(0,m.jsxs)(`a`,{className:i,href:e.url,target:`_blank`,rel:`noreferrer`,children:[(0,m.jsx)(s,{className:`size-4`}),` `,e.label]}):(0,m.jsx)(`button`,{type:`button`,className:i,onClick:()=>void n(t,e.action),children:e.label})}export{h as n,g as t};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{S as t,x as n}from"./vendor-markdown-Ls5AcU91.js";import"./vendor-ui-CaeeFO0B.js";import{c as r,n as i,o as a,r as o,s,t as c}from"./use-remote-desktop-display-choice-DSqF1Rgx.js";import"./api-client-CEYCBt_0.js";import"./vendor-mermaid-CfY1-PkA.js";import{t as l}from"./settings-store-CzLnTR8p.js";import{n as u}from"./utils-IrnQujwR.js";import"./panel-store-BmdcSBNb.js";import{t as d}from"./window-store-D0HbQ1pM.js";import"./ws-auth-D111jj32.js";import{Jn as f}from"./index-Cx1meAwb.js";import"./run-in-terminal-wHKwAnWP.js";import{n as p,t as m}from"./remote-desktop-readiness-gate-BmC3b05e.js";var h=e(t(),1);function g(e,t,n){let r=(0,h.useCallback)((n,r,i,a)=>{let s=e.current;if(!s)return;let{xFrac:c,yFrac:l}=o(n,r,s.getBoundingClientRect());t({type:`pointer`,xFrac:c,yFrac:l,button:i,down:a})},[e,t]);(0,h.useEffect)(()=>{let i=e.current;if(!i||!n)return;let a=e=>e===0?`left`:e===2?`right`:null,o=()=>t({type:`releaseAll`}),s=null,c=0,l=()=>{c=0,s&&=(r(s.x,s.y,null,null),null)},u=()=>{c&&=(cancelAnimationFrame(c),0),s&&=(r(s.x,s.y,null,null),null)},d=e=>{e.preventDefault(),i.setPointerCapture(e.pointerId),i.focus(),u(),r(e.clientX,e.clientY,a(e.button),!0)},f=e=>{s={x:e.clientX,y:e.clientY},c||=requestAnimationFrame(l)},p=e=>{u(),r(e.clientX,e.clientY,a(e.button),!1)},m=e=>e.preventDefault(),h=e=>{e.preventDefault(),t({type:`key`,code:e.code,down:!0})},g=e=>{e.preventDefault(),t({type:`key`,code:e.code,down:!1})},_=()=>{document.hidden&&o()};return i.tabIndex=0,i.addEventListener(`pointerdown`,d),i.addEventListener(`pointermove`,f),i.addEventListener(`pointerup`,p),i.addEventListener(`contextmenu`,m),i.addEventListener(`keydown`,h),i.addEventListener(`keyup`,g),i.addEventListener(`blur`,o),document.addEventListener(`visibilitychange`,_),()=>{c&&cancelAnimationFrame(c),i.removeEventListener(`pointerdown`,d),i.removeEventListener(`pointermove`,f),i.removeEventListener(`pointerup`,p),i.removeEventListener(`contextmenu`,m),i.removeEventListener(`keydown`,h),i.removeEventListener(`keyup`,g),i.removeEventListener(`blur`,o),document.removeEventListener(`visibilitychange`,_)}},[e,n,r,t])}var _=n();function v({id:e}){let t=d(e=>e.close),n=(0,h.useCallback)(()=>t(e),[t,e]);return(0,_.jsx)(p,{onCancel:n,children:(0,_.jsx)(m,{onCancel:n,children:(0,_.jsx)(y,{})})})}function y(){let e=(0,h.useRef)(null),t=c(),{connState:n,errorMessage:o,decoderStatus:d,decoderErrorMessage:p,sendMessage:m,reconnect:v,getFrameCount:y,getTotalBytes:b}=a(e,{displayId:t.displayId}),x=l(e=>e.remoteDesktopStatsVisible),S=l(e=>e.toggleRemoteDesktopStatsVisible);g(e,m,n===`streaming`);let C=d===`unsupported`?p:n===`error`?o:n===`closed`?`Disconnected`:n===`connecting`?`Connecting…`:null;return(0,_.jsxs)(`div`,{className:`relative flex h-full w-full items-center justify-center bg-black`,"data-testid":`remote-desktop-window`,"data-conn-state":n,children:[(0,_.jsx)(`canvas`,{ref:e,"data-testid":`remote-desktop-canvas`,className:`max-h-full max-w-full outline-none`}),(0,_.jsx)(i,{canvasRef:e,getFrameCount:y,getTotalBytes:b}),t.displays.length>1&&(0,_.jsx)(`select`,{value:t.current?.id??``,onChange:e=>t.select(e.target.value),"aria-label":`Display`,className:`absolute right-8 top-1 z-40 h-6 max-w-[45%] rounded bg-black/40 px-1.5 text-xs text-white/80 hover:bg-black/60`,"data-testid":`remote-desktop-display-select`,children:t.displays.map(e=>(0,_.jsxs)(`option`,{value:e.id,children:[e.label,e.primary?` (main)`:``,` · `,e.width,`×`,e.height]},e.id))}),(0,_.jsx)(`button`,{type:`button`,onClick:S,"aria-label":`Toggle stats overlay`,"aria-pressed":x,className:u(`absolute right-1 top-1 z-40 flex size-6 items-center justify-center rounded bg-black/40 text-white/70 hover:bg-black/60 hover:text-white`,x&&`bg-primary/70 text-primary-foreground hover:bg-primary/80`),children:(0,_.jsx)(r,{className:`size-3.5`})}),C&&(0,_.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center gap-3 bg-black/70 text-sm text-white`,children:[(0,_.jsx)(s,{className:`size-6 opacity-70`}),(0,_.jsx)(`span`,{className:`max-w-sm text-center px-4`,children:C}),(n===`error`||n===`closed`)&&d!==`unsupported`&&(0,_.jsxs)(`button`,{onClick:v,className:`flex items-center gap-1.5 rounded-md bg-white/10 px-3 py-1.5 hover:bg-white/20`,children:[(0,_.jsx)(f,{className:`size-3.5`}),` Reconnect`]})]})]})}export{v as default};
1
+ import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{C as t,S as n}from"./vendor-markdown-CuWCHIVb.js";import"./vendor-ui-BBdkypKW.js";import{c as r,n as i,o as a,r as o,s,t as c}from"./use-remote-desktop-display-choice-BnVT4dhX.js";import"./api-client-DwXlVfXP.js";import"./vendor-mermaid-CfY1-PkA.js";import{t as l}from"./settings-store-_s4xFcFq.js";import{n as u}from"./utils-IrnQujwR.js";import"./panel-store-D42k25jy.js";import{t as d}from"./window-store-CfxP5yor.js";import"./ws-auth-FRzMmfQx.js";import{Jn as f}from"./index-DVNJ2W5R.js";import"./run-in-terminal-DoTOtgQS.js";import{n as p,t as m}from"./remote-desktop-readiness-gate-6reSZvad.js";var h=e(t(),1);function g(e,t,n){let r=(0,h.useCallback)((n,r,i,a)=>{let s=e.current;if(!s)return;let{xFrac:c,yFrac:l}=o(n,r,s.getBoundingClientRect());t({type:`pointer`,xFrac:c,yFrac:l,button:i,down:a})},[e,t]);(0,h.useEffect)(()=>{let i=e.current;if(!i||!n)return;let a=e=>e===0?`left`:e===2?`right`:null,o=()=>t({type:`releaseAll`}),s=null,c=0,l=()=>{c=0,s&&=(r(s.x,s.y,null,null),null)},u=()=>{c&&=(cancelAnimationFrame(c),0),s&&=(r(s.x,s.y,null,null),null)},d=e=>{e.preventDefault(),i.setPointerCapture(e.pointerId),i.focus(),u(),r(e.clientX,e.clientY,a(e.button),!0)},f=e=>{s={x:e.clientX,y:e.clientY},c||=requestAnimationFrame(l)},p=e=>{u(),r(e.clientX,e.clientY,a(e.button),!1)},m=e=>e.preventDefault(),h=e=>{e.preventDefault(),t({type:`key`,code:e.code,down:!0})},g=e=>{e.preventDefault(),t({type:`key`,code:e.code,down:!1})},_=()=>{document.hidden&&o()};return i.tabIndex=0,i.addEventListener(`pointerdown`,d),i.addEventListener(`pointermove`,f),i.addEventListener(`pointerup`,p),i.addEventListener(`contextmenu`,m),i.addEventListener(`keydown`,h),i.addEventListener(`keyup`,g),i.addEventListener(`blur`,o),document.addEventListener(`visibilitychange`,_),()=>{c&&cancelAnimationFrame(c),i.removeEventListener(`pointerdown`,d),i.removeEventListener(`pointermove`,f),i.removeEventListener(`pointerup`,p),i.removeEventListener(`contextmenu`,m),i.removeEventListener(`keydown`,h),i.removeEventListener(`keyup`,g),i.removeEventListener(`blur`,o),document.removeEventListener(`visibilitychange`,_)}},[e,n,r,t])}var _=n();function v({id:e}){let t=d(e=>e.close),n=(0,h.useCallback)(()=>t(e),[t,e]);return(0,_.jsx)(p,{onCancel:n,children:(0,_.jsx)(m,{onCancel:n,children:(0,_.jsx)(y,{})})})}function y(){let e=(0,h.useRef)(null),t=c(),{connState:n,errorMessage:o,decoderStatus:d,decoderErrorMessage:p,sendMessage:m,reconnect:v,getFrameCount:y,getTotalBytes:b}=a(e,{displayId:t.displayId}),x=l(e=>e.remoteDesktopStatsVisible),S=l(e=>e.toggleRemoteDesktopStatsVisible);g(e,m,n===`streaming`);let C=d===`unsupported`?p:n===`error`?o:n===`closed`?`Disconnected`:n===`connecting`?`Connecting…`:null;return(0,_.jsxs)(`div`,{className:`relative flex h-full w-full items-center justify-center bg-black`,"data-testid":`remote-desktop-window`,"data-conn-state":n,children:[(0,_.jsx)(`canvas`,{ref:e,"data-testid":`remote-desktop-canvas`,className:`max-h-full max-w-full outline-none`}),(0,_.jsx)(i,{canvasRef:e,getFrameCount:y,getTotalBytes:b}),t.displays.length>1&&(0,_.jsx)(`select`,{value:t.current?.id??``,onChange:e=>t.select(e.target.value),"aria-label":`Display`,className:`absolute right-8 top-1 z-40 h-6 max-w-[45%] rounded bg-black/40 px-1.5 text-xs text-white/80 hover:bg-black/60`,"data-testid":`remote-desktop-display-select`,children:t.displays.map(e=>(0,_.jsxs)(`option`,{value:e.id,children:[e.label,e.primary?` (main)`:``,` · `,e.width,`×`,e.height]},e.id))}),(0,_.jsx)(`button`,{type:`button`,onClick:S,"aria-label":`Toggle stats overlay`,"aria-pressed":x,className:u(`absolute right-1 top-1 z-40 flex size-6 items-center justify-center rounded bg-black/40 text-white/70 hover:bg-black/60 hover:text-white`,x&&`bg-primary/70 text-primary-foreground hover:bg-primary/80`),children:(0,_.jsx)(r,{className:`size-3.5`})}),C&&(0,_.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center gap-3 bg-black/70 text-sm text-white`,children:[(0,_.jsx)(s,{className:`size-6 opacity-70`}),(0,_.jsx)(`span`,{className:`max-w-sm text-center px-4`,children:C}),(n===`error`||n===`closed`)&&d!==`unsupported`&&(0,_.jsxs)(`button`,{onClick:v,className:`flex items-center gap-1.5 rounded-md bg-white/10 px-3 py-1.5 hover:bg-white/20`,children:[(0,_.jsx)(f,{className:`size-3.5`}),` Reconnect`]})]})]})}export{v as default};
@@ -1 +1 @@
1
- import{t as e}from"./panel-store-BmdcSBNb.js";var t=`ppm:run-in-terminal`,n=`ppm:run-in-terminal:ack`;function r(e){return e.replace(/^[ \t]*\$[ \t]+/gm,``).replace(/\s+$/,``)}function i(i,a){let o=r(i);if(!o)return;let s=!1,c=()=>{s=!0};window.addEventListener(n,c),window.dispatchEvent(new CustomEvent(t,{detail:{command:o,projectName:a}})),window.removeEventListener(n,c),!s&&e.getState().openInDock({type:`terminal`,title:`Terminal`,projectId:a??null,closable:!0,metadata:{...a?{projectName:a}:{},pendingCommand:o}})}export{t as n,i as r,n as t};
1
+ import{t as e}from"./panel-store-D42k25jy.js";var t=`ppm:run-in-terminal`,n=`ppm:run-in-terminal:ack`;function r(e){return e.replace(/^[ \t]*\$[ \t]+/gm,``).replace(/\s+$/,``)}function i(i,a){let o=r(i);if(!o)return;let s=!1,c=()=>{s=!0};window.addEventListener(n,c),window.dispatchEvent(new CustomEvent(t,{detail:{command:o,projectName:a}})),window.removeEventListener(n,c),!s&&e.getState().openInDock({type:`terminal`,title:`Terminal`,projectId:a??null,closable:!0,metadata:{...a?{projectName:a}:{},pendingCommand:o}})}export{t as n,i as r,n as t};
@@ -1 +1 @@
1
- import{t as e}from"./createLucideIcon-D8pyde1A.js";var t=e(`save`,[[`path`,{d:`M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z`,key:`1c8476`}],[`path`,{d:`M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7`,key:`1ydtos`}],[`path`,{d:`M7 3v4a1 1 0 0 0 1 1h7`,key:`t51u73`}]]);export{t};
1
+ import{t as e}from"./createLucideIcon-D6fVXe3s.js";var t=e(`save`,[[`path`,{d:`M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z`,key:`1c8476`}],[`path`,{d:`M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7`,key:`1ydtos`}],[`path`,{d:`M7 3v4a1 1 0 0 0 1 1h7`,key:`t51u73`}]]);export{t};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{S as t,x as n}from"./vendor-markdown-Ls5AcU91.js";import"./vendor-ui-CaeeFO0B.js";import{t as r}from"./calendar-clock-C1asT-gk.js";import{t as i}from"./chevron-down-Dp0rpHb8.js";import{t as a}from"./chevron-right-De-Wz5Lz.js";import{t as o}from"./power-CriQkeK5.js";import{n as s,s as c}from"./api-client-CEYCBt_0.js";import{n as l}from"./utils-IrnQujwR.js";import"./portal-container-context-DKymYOY-.js";import"./context-menu-CJL8L98s.js";import{n as u}from"./use-is-mobile-D1weanbj.js";import{t as d}from"./button-DX32ffge.js";import{t as f}from"./mobile-bottom-sheet-CmySDB6I.js";import"./use-visual-viewport-Bfl3Bxxb.js";import{$n as p,$t as ee,At as m,B as h,Dt as g,Et as _,G as v,H as y,J as b,Ln as x,Pt as S,Qn as C,Tt as w,U as T,V as E,W as D,X as O,Xt as te,Yt as k,en as A,nr as j}from"./index-Cx1meAwb.js";var M=e(t(),1),N=1e4;function P(){let[e,t]=(0,M.useState)([]),[n,r]=(0,M.useState)(!0),i=(0,M.useCallback)(async()=>{try{t(await s.get(`/api/schedules`))}catch{}finally{r(!1)}},[]);return(0,M.useEffect)(()=>{i();let e=setInterval(()=>{document.visibilityState===`visible`&&i()},N);return()=>clearInterval(e)},[i]),{schedules:e,loading:n,refetch:i}}function F(e){let[t,n]=(0,M.useState)([]),[r,i]=(0,M.useState)(!1),a=(0,M.useCallback)(async()=>{if(e!=null){i(!0);try{n(await s.get(`/api/schedules/${e}/runs?limit=20`))}catch{n([])}finally{i(!1)}}},[e]);return(0,M.useEffect)(()=>{a()},[a]),{runs:t,loading:r,refetch:a}}var I=n(),ne={done:`bg-success/10 text-success`,error:`bg-error/10 text-error`,running:`bg-warning/10 text-warning`,skipped:`bg-muted text-muted-foreground`};function re({scheduleId:e}){let{runs:t,loading:n}=F(e);return n&&t.length===0?(0,I.jsx)(`p`,{className:`text-[11px] text-muted-foreground py-1`,children:`Loading runs…`}):t.length===0?(0,I.jsx)(`p`,{className:`text-[11px] text-muted-foreground py-1`,children:`No runs yet.`}):(0,I.jsx)(`div`,{className:`space-y-1`,children:t.map(e=>(0,I.jsx)(ie,{run:e},e.id))})}function L(e){return new Date(e.includes(`T`)?e:e.replace(` `,`T`)+`Z`)}function ie({run:e}){let[t,n]=(0,M.useState)(!1),r=!!(e.output_truncated||e.error),i=e.ended_at?`${Math.round((L(e.ended_at).getTime()-L(e.started_at).getTime())/1e3)}s`:`…`;return(0,I.jsxs)(`div`,{className:`rounded border border-border text-[11px]`,children:[(0,I.jsxs)(`button`,{type:`button`,onClick:()=>r&&n(!t),className:l(`w-full flex items-center gap-2 px-2 py-2 min-h-11 text-left`,r&&`cursor-pointer hover:bg-accent/30`),children:[(0,I.jsx)(`span`,{className:l(`rounded px-1.5 py-0.5 font-medium shrink-0`,ne[e.status]),children:e.status}),(0,I.jsxs)(`span`,{className:`text-muted-foreground truncate flex-1`,children:[L(e.started_at).toLocaleString(),` · `,i,e.cost_usd!=null&&` · $${e.cost_usd.toFixed(4)}`,e.context_window_pct!=null&&` · ctx ${e.context_window_pct}%`]})]}),t&&(0,I.jsxs)(`div`,{className:`px-2 pb-2 space-y-1`,children:[e.error&&(0,I.jsx)(`p`,{className:`text-error break-all`,children:e.error}),e.output_truncated&&(0,I.jsx)(`pre`,{className:`overflow-auto max-h-96 whitespace-pre-wrap break-all text-muted-foreground font-mono text-[10px]`,children:e.output_truncated})]})]})}function ae({schedule:e,onEdit:t,onChanged:n}){let[r,u]=(0,M.useState)(!1),[d,f]=(0,M.useState)(0);return(0,I.jsxs)(`div`,{className:`rounded-lg border border-border`,children:[(0,I.jsxs)(w,{children:[(0,I.jsx)(S,{asChild:!0,children:(0,I.jsxs)(`button`,{type:`button`,onClick:()=>u(!r),className:`w-full flex items-center gap-2 px-2.5 py-2.5 min-h-11 text-left cursor-pointer hover:bg-accent/30`,children:[r?(0,I.jsx)(i,{className:`size-3.5 shrink-0 text-muted-foreground`}):(0,I.jsx)(a,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,I.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,I.jsx)(`p`,{className:`text-xs font-medium truncate`,children:e.name}),(0,I.jsxs)(`p`,{className:`text-[11px] text-muted-foreground truncate`,children:[(0,I.jsx)(`span`,{className:`font-mono`,children:e.cron_expr}),` · `,e.next_fire_at&&e.enabled?`next ${new Date(e.next_fire_at).toLocaleString()}`:`—`]})]}),(0,I.jsx)(`span`,{className:l(`rounded px-1.5 py-0.5 text-[10px] font-medium shrink-0`,e.enabled?`bg-success/10 text-success`:`bg-muted text-muted-foreground`),children:e.enabled?`Enabled`:`Disabled`})]})}),(0,I.jsxs)(_,{children:[(0,I.jsxs)(g,{onClick:async()=>{try{let t=await s.post(`/api/schedules/${e.id}/run-now`);c.success(`Run #${t.runId} started${t.wasRunning?` (previous run still active)`:``}`),u(!0),f(e=>e+1)}catch(e){c.error(e instanceof Error?e.message:`Run failed`)}},children:[(0,I.jsx)(p,{className:`size-3.5`}),` Run now`]}),(0,I.jsxs)(g,{onClick:async()=>{try{await s.patch(`/api/schedules/${e.id}`,{enabled:!e.enabled}),n()}catch(e){c.error(e instanceof Error?e.message:`Update failed`)}},children:[(0,I.jsx)(o,{className:`size-3.5`}),` `,e.enabled?`Disable`:`Enable`]}),(0,I.jsxs)(g,{onClick:t,children:[(0,I.jsx)(j,{className:`size-3.5`}),` Edit`]}),(0,I.jsx)(m,{}),(0,I.jsxs)(g,{variant:`destructive`,onClick:async()=>{try{await s.del(`/api/schedules/${e.id}`),c.success(`Schedule deleted`),n()}catch(e){c.error(e instanceof Error?e.message:`Delete failed`)}},children:[(0,I.jsx)(x,{className:`size-3.5`}),` Delete`]})]})]}),r&&(0,I.jsxs)(`div`,{className:`px-2.5 pb-2.5 space-y-1.5`,children:[(0,I.jsx)(`p`,{className:`text-[11px] text-muted-foreground break-all line-clamp-3`,children:e.prompt}),(0,I.jsx)(re,{scheduleId:e.id},d)]})]})}function R(e,t,n,r,i,a,o,s){return R.fromTZ(R.tp(e,t,n,r,i,a,o),s)}R.fromTZISO=(e,t,n)=>R.fromTZ(B(e,t),n),R.fromTZ=function(e,t){let n=new Date(Date.UTC(e.y,e.m-1,e.d,e.h,e.i,e.s)),r=z(e.tz,n),i=new Date(n.getTime()-r),a=z(e.tz,i);if(a-r===0)return i;{let r=new Date(n.getTime()-a),o=z(e.tz,r);if(o-a===0||!t&&o-a>0)return r;if(t)throw Error(`Invalid date passed to fromTZ()`);return i}},R.toTZ=function(e,t){let n=e.toLocaleString(`en-US`,{timeZone:t}).replace(/[\u202f]/,` `),r=new Date(n);return{y:r.getFullYear(),m:r.getMonth()+1,d:r.getDate(),h:r.getHours(),i:r.getMinutes(),s:r.getSeconds(),tz:t}},R.tp=(e,t,n,r,i,a,o)=>({y:e,m:t,d:n,h:r,i,s:a,tz:o});function z(e,t=new Date){let n=t.toLocaleString(`en-US`,{timeZone:e,timeZoneName:`shortOffset`}).split(` `).slice(-1)[0],r=t.toLocaleString(`en-US`).replace(/[\u202f]/,` `);return Date.parse(`${r} GMT`)-Date.parse(`${r} ${n}`)}function B(e,t){let n=new Date(Date.parse(e));if(isNaN(n))throw Error(`minitz: Invalid ISO8601 passed to parser.`);let r=e.substring(9);return e.includes(`Z`)||r.includes(`-`)||r.includes(`+`)?R.tp(n.getUTCFullYear(),n.getUTCMonth()+1,n.getUTCDate(),n.getUTCHours(),n.getUTCMinutes(),n.getUTCSeconds(),`Etc/UTC`):R.tp(n.getFullYear(),n.getMonth()+1,n.getDate(),n.getHours(),n.getMinutes(),n.getSeconds(),t)}R.minitz=R;var V=32,H=31|V,U=[1,2,4,8,16],W=class{pattern;timezone;second;minute;hour;day;month;dayOfWeek;lastDayOfMonth;starDOM;starDOW;constructor(e,t){this.pattern=e,this.timezone=t,this.second=Array(60).fill(0),this.minute=Array(60).fill(0),this.hour=Array(24).fill(0),this.day=Array(31).fill(0),this.month=Array(12).fill(0),this.dayOfWeek=Array(7).fill(0),this.lastDayOfMonth=!1,this.starDOM=!1,this.starDOW=!1,this.parse()}parse(){if(!(typeof this.pattern==`string`||this.pattern instanceof String))throw TypeError(`CronPattern: Pattern has to be of type string.`);this.pattern.indexOf(`@`)>=0&&(this.pattern=this.handleNicknames(this.pattern).trim());let e=this.pattern.replace(/\s+/g,` `).split(` `);if(e.length<5||e.length>6)throw TypeError(`CronPattern: invalid configuration format ('`+this.pattern+`'), exactly five or six space separated parts are required.`);if(e.length===5&&e.unshift(`0`),e[3].indexOf(`L`)>=0&&(e[3]=e[3].replace(`L`,``),this.lastDayOfMonth=!0),e[3]==`*`&&(this.starDOM=!0),e[4].length>=3&&(e[4]=this.replaceAlphaMonths(e[4])),e[5].length>=3&&(e[5]=this.replaceAlphaDays(e[5])),e[5]==`*`&&(this.starDOW=!0),this.pattern.indexOf(`?`)>=0){let t=new q(new Date,this.timezone).getDate(!0);e[0]=e[0].replace(`?`,t.getSeconds().toString()),e[1]=e[1].replace(`?`,t.getMinutes().toString()),e[2]=e[2].replace(`?`,t.getHours().toString()),this.starDOM||(e[3]=e[3].replace(`?`,t.getDate().toString())),e[4]=e[4].replace(`?`,(t.getMonth()+1).toString()),this.starDOW||(e[5]=e[5].replace(`?`,t.getDay().toString()))}this.throwAtIllegalCharacters(e),this.partToArray(`second`,e[0],0,1),this.partToArray(`minute`,e[1],0,1),this.partToArray(`hour`,e[2],0,1),this.partToArray(`day`,e[3],-1,1),this.partToArray(`month`,e[4],-1,1),this.partToArray(`dayOfWeek`,e[5],0,H),this.dayOfWeek[7]&&(this.dayOfWeek[0]=this.dayOfWeek[7])}partToArray(e,t,n,r){let i=this[e],a=e===`day`&&this.lastDayOfMonth;if(t===``&&!a)throw TypeError(`CronPattern: configuration entry `+e+` (`+t+`) is empty, check for trailing spaces.`);if(t===`*`)return i.fill(r);let o=t.split(`,`);if(o.length>1)for(let t=0;t<o.length;t++)this.partToArray(e,o[t],n,r);else t.indexOf(`-`)!==-1&&t.indexOf(`/`)!==-1?this.handleRangeWithStepping(t,e,n,r):t.indexOf(`-`)===-1?t.indexOf(`/`)===-1?t!==``&&this.handleNumber(t,e,n,r):this.handleStepping(t,e,n,r):this.handleRange(t,e,n,r)}throwAtIllegalCharacters(e){for(let t=0;t<e.length;t++)if((t===5?/[^/*0-9,\-#L]+/:/[^/*0-9,-]+/).test(e[t]))throw TypeError(`CronPattern: configuration entry `+t+` (`+e[t]+`) contains illegal characters.`)}handleNumber(e,t,n,r){let i=this.extractNth(e,t),a=parseInt(i[0],10)+n;if(isNaN(a))throw TypeError(`CronPattern: `+t+` is not a number: '`+e+`'`);this.setPart(t,a,i[1]||r)}setPart(e,t,n){if(!Object.prototype.hasOwnProperty.call(this,e))throw TypeError(`CronPattern: Invalid part specified: `+e);if(e===`dayOfWeek`){if(t===7&&(t=0),t<0||t>6)throw RangeError(`CronPattern: Invalid value for dayOfWeek: `+t);this.setNthWeekdayOfMonth(t,n);return}if(e===`second`||e===`minute`){if(t<0||t>=60)throw RangeError(`CronPattern: Invalid value for `+e+`: `+t)}else if(e===`hour`){if(t<0||t>=24)throw RangeError(`CronPattern: Invalid value for `+e+`: `+t)}else if(e===`day`){if(t<0||t>=31)throw RangeError(`CronPattern: Invalid value for `+e+`: `+t)}else if(e===`month`&&(t<0||t>=12))throw RangeError(`CronPattern: Invalid value for `+e+`: `+t);this[e][t]=n}handleRangeWithStepping(e,t,n,r){let i=this.extractNth(e,t),a=i[0].match(/^(\d+)-(\d+)\/(\d+)$/);if(a===null)throw TypeError(`CronPattern: Syntax error, illegal range with stepping: '`+e+`'`);let[,o,s,c]=a,l=parseInt(o,10)+n,u=parseInt(s,10)+n,d=parseInt(c,10);if(isNaN(l))throw TypeError(`CronPattern: Syntax error, illegal lower range (NaN)`);if(isNaN(u))throw TypeError(`CronPattern: Syntax error, illegal upper range (NaN)`);if(isNaN(d))throw TypeError(`CronPattern: Syntax error, illegal stepping: (NaN)`);if(d===0)throw TypeError(`CronPattern: Syntax error, illegal stepping: 0`);if(d>this[t].length)throw TypeError(`CronPattern: Syntax error, steps cannot be greater than maximum value of part (`+this[t].length+`)`);if(l>u)throw TypeError(`CronPattern: From value is larger than to value: '`+e+`'`);for(let e=l;e<=u;e+=d)this.setPart(t,e,i[1]||r)}extractNth(e,t){let n=e,r;if(n.includes(`#`)){if(t!==`dayOfWeek`)throw Error(`CronPattern: nth (#) only allowed in day-of-week field`);r=n.split(`#`)[1],n=n.split(`#`)[0]}return[n,r]}handleRange(e,t,n,r){let i=this.extractNth(e,t),a=i[0].split(`-`);if(a.length!==2)throw TypeError(`CronPattern: Syntax error, illegal range: '`+e+`'`);let o=parseInt(a[0],10)+n,s=parseInt(a[1],10)+n;if(isNaN(o))throw TypeError(`CronPattern: Syntax error, illegal lower range (NaN)`);if(isNaN(s))throw TypeError(`CronPattern: Syntax error, illegal upper range (NaN)`);if(o>s)throw TypeError(`CronPattern: From value is larger than to value: '`+e+`'`);for(let e=o;e<=s;e++)this.setPart(t,e,i[1]||r)}handleStepping(e,t,n,r){let i=this.extractNth(e,t),a=i[0].split(`/`);if(a.length!==2)throw TypeError(`CronPattern: Syntax error, illegal stepping: '`+e+`'`);a[0]===``&&(a[0]=`*`);let o=0;a[0]!==`*`&&(o=parseInt(a[0],10)+n);let s=parseInt(a[1],10);if(isNaN(s))throw TypeError(`CronPattern: Syntax error, illegal stepping: (NaN)`);if(s===0)throw TypeError(`CronPattern: Syntax error, illegal stepping: 0`);if(s>this[t].length)throw TypeError(`CronPattern: Syntax error, max steps for part is (`+this[t].length+`)`);for(let e=o;e<this[t].length;e+=s)this.setPart(t,e,i[1]||r)}replaceAlphaDays(e){return e.replace(/-sun/gi,`-7`).replace(/sun/gi,`0`).replace(/mon/gi,`1`).replace(/tue/gi,`2`).replace(/wed/gi,`3`).replace(/thu/gi,`4`).replace(/fri/gi,`5`).replace(/sat/gi,`6`)}replaceAlphaMonths(e){return e.replace(/jan/gi,`1`).replace(/feb/gi,`2`).replace(/mar/gi,`3`).replace(/apr/gi,`4`).replace(/may/gi,`5`).replace(/jun/gi,`6`).replace(/jul/gi,`7`).replace(/aug/gi,`8`).replace(/sep/gi,`9`).replace(/oct/gi,`10`).replace(/nov/gi,`11`).replace(/dec/gi,`12`)}handleNicknames(e){let t=e.trim().toLowerCase();return t===`@yearly`||t===`@annually`?`0 0 1 1 *`:t===`@monthly`?`0 0 1 * *`:t===`@weekly`?`0 0 * * 0`:t===`@daily`?`0 0 * * *`:t===`@hourly`?`0 * * * *`:e}setNthWeekdayOfMonth(e,t){if(typeof t!=`number`&&t===`L`)this.dayOfWeek[e]=this.dayOfWeek[e]|V;else if(t===H)this.dayOfWeek[e]=H;else if(t<6&&t>0)this.dayOfWeek[e]=this.dayOfWeek[e]|U[t-1];else throw TypeError(`CronPattern: nth weekday out of range, should be 1-5 or L. Value: ${t}, Type: ${typeof t}`)}},G=[31,28,31,30,31,30,31,31,30,31,30,31],K=[[`month`,`year`,0],[`day`,`month`,-1],[`hour`,`day`,0],[`minute`,`hour`,0],[`second`,`minute`,0]],q=class e{tz;ms;second;minute;hour;day;month;year;constructor(t,n){if(this.tz=n,t&&t instanceof Date)if(!isNaN(t))this.fromDate(t);else throw TypeError(`CronDate: Invalid date passed to CronDate constructor`);else if(t===void 0)this.fromDate(new Date);else if(t&&typeof t==`string`)this.fromString(t);else if(t instanceof e)this.fromCronDate(t);else throw TypeError(`CronDate: Invalid type (`+typeof t+`) passed to CronDate constructor`)}isNthWeekdayOfMonth(e,t,n,r){let i=new Date(Date.UTC(e,t,n)).getUTCDay(),a=0;for(let r=1;r<=n;r++)new Date(Date.UTC(e,t,r)).getUTCDay()===i&&a++;if(r&H&&U[a-1]&r)return!0;if(r&V){let r=new Date(Date.UTC(e,t+1,0)).getUTCDate();for(let a=n+1;a<=r;a++)if(new Date(Date.UTC(e,t,a)).getUTCDay()===i)return!1;return!0}return!1}fromDate(e){if(this.tz!==void 0)if(typeof this.tz==`number`)this.ms=e.getUTCMilliseconds(),this.second=e.getUTCSeconds(),this.minute=e.getUTCMinutes()+this.tz,this.hour=e.getUTCHours(),this.day=e.getUTCDate(),this.month=e.getUTCMonth(),this.year=e.getUTCFullYear(),this.apply();else{let t=R.toTZ(e,this.tz);this.ms=e.getMilliseconds(),this.second=t.s,this.minute=t.i,this.hour=t.h,this.day=t.d,this.month=t.m-1,this.year=t.y}else this.ms=e.getMilliseconds(),this.second=e.getSeconds(),this.minute=e.getMinutes(),this.hour=e.getHours(),this.day=e.getDate(),this.month=e.getMonth(),this.year=e.getFullYear()}fromCronDate(e){this.tz=e.tz,this.year=e.year,this.month=e.month,this.day=e.day,this.hour=e.hour,this.minute=e.minute,this.second=e.second,this.ms=e.ms}apply(){if(this.month>11||this.day>G[this.month]||this.hour>59||this.minute>59||this.second>59||this.hour<0||this.minute<0||this.second<0){let e=new Date(Date.UTC(this.year,this.month,this.day,this.hour,this.minute,this.second,this.ms));return this.ms=e.getUTCMilliseconds(),this.second=e.getUTCSeconds(),this.minute=e.getUTCMinutes(),this.hour=e.getUTCHours(),this.day=e.getUTCDate(),this.month=e.getUTCMonth(),this.year=e.getUTCFullYear(),!0}else return!1}fromString(e){if(typeof this.tz==`number`){let t=R.fromTZISO(e);this.ms=t.getUTCMilliseconds(),this.second=t.getUTCSeconds(),this.minute=t.getUTCMinutes(),this.hour=t.getUTCHours(),this.day=t.getUTCDate(),this.month=t.getUTCMonth(),this.year=t.getUTCFullYear(),this.apply()}else return this.fromDate(R.fromTZISO(e,this.tz))}findNext(e,t,n,r){let i=this[t],a;n.lastDayOfMonth&&(a=this.month===1?new Date(Date.UTC(this.year,this.month+1,0,0,0,0,0)).getUTCDate():G[this.month]);let o=!n.starDOW&&t==`day`?new Date(Date.UTC(this.year,this.month,1,0,0,0,0)).getUTCDay():void 0;for(let s=this[t]+r;s<n[t].length;s++){let c=n[t][s];if(t===`day`&&n.lastDayOfMonth&&s-r==a&&(c=1),t===`day`&&!n.starDOW){let t=n.dayOfWeek[(o+(s-r-1))%7];if(t&&t&H)t=this.isNthWeekdayOfMonth(this.year,this.month,s-r,t)?1:0;else if(t)throw Error(`CronDate: Invalid value for dayOfWeek encountered. ${t}`);e.legacyMode&&!n.starDOM?c||=t:c&&=t}if(c)return this[t]=s-r,i===this[t]?1:2}return 3}recurse(e,t,n){let r=this.findNext(t,K[n][0],e,K[n][2]);if(r>1){let i=n+1;for(;i<K.length;)this[K[i][0]]=-K[i][2],i++;if(r===3)return this[K[n][1]]++,this[K[n][0]]=-K[n][2],this.apply(),this.recurse(e,t,0);if(this.apply())return this.recurse(e,t,n-1)}return n+=1,n>=K.length?this:this.year>=3e3?null:this.recurse(e,t,n)}increment(e,t,n){return this.second+=t.interval!==void 0&&t.interval>1&&n?t.interval:1,this.ms=0,this.apply(),this.recurse(e,t,0)}getDate(e){return e||this.tz===void 0?new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.ms):typeof this.tz==`number`?new Date(Date.UTC(this.year,this.month,this.day,this.hour,this.minute-this.tz,this.second,this.ms)):R.fromTZ(R.tp(this.year,this.month+1,this.day,this.hour,this.minute,this.second,this.tz),!1)}getTime(){return this.getDate(!1).getTime()}};function oe(e){if(e===void 0&&(e={}),delete e.name,e.legacyMode=e.legacyMode===void 0?!0:e.legacyMode,e.paused=e.paused===void 0?!1:e.paused,e.maxRuns=e.maxRuns===void 0?1/0:e.maxRuns,e.catch=e.catch===void 0?!1:e.catch,e.interval=e.interval===void 0?0:parseInt(e.interval.toString(),10),e.utcOffset=e.utcOffset===void 0?void 0:parseInt(e.utcOffset.toString(),10),e.unref=e.unref===void 0?!1:e.unref,e.startAt&&=new q(e.startAt,e.timezone),e.stopAt&&=new q(e.stopAt,e.timezone),e.interval!==null){if(isNaN(e.interval))throw Error(`CronOptions: Supplied value for interval is not a number`);if(e.interval<0)throw Error(`CronOptions: Supplied value for interval can not be negative`)}if(e.utcOffset!==void 0){if(isNaN(e.utcOffset))throw Error(`CronOptions: Invalid value passed for utcOffset, should be number representing minutes offset from UTC.`);if(e.utcOffset<-870||e.utcOffset>870)throw Error(`CronOptions: utcOffset out of bounds.`);if(e.utcOffset!==void 0&&e.timezone)throw Error(`CronOptions: Combining 'utcOffset' with 'timezone' is not allowed.`)}if(e.unref!==!0&&e.unref!==!1)throw Error(`CronOptions: Unref should be either true, false or undefined(false).`);return e}function J(e){return Object.prototype.toString.call(e)===`[object Function]`||typeof e==`function`||e instanceof Function}function se(e){return J(e)}function ce(e){typeof Deno<`u`&&typeof Deno.unrefTimer<`u`?Deno.unrefTimer(e):e&&typeof e.unref<`u`&&e.unref()}var Y=30*1e3,X=[],Z=class{name;options;_states;fn;constructor(e,t,n){let r,i;if(J(t))i=t;else if(typeof t==`object`)r=t;else if(t!==void 0)throw Error(`Cron: Invalid argument passed for optionsIn. Should be one of function, or object (options).`);if(J(n))i=n;else if(typeof n==`object`)r=n;else if(n!==void 0)throw Error(`Cron: Invalid argument passed for funcIn. Should be one of function, or object (options).`);if(this.name=r?.name,this.options=oe(r),this._states={kill:!1,blocking:!1,previousRun:void 0,currentRun:void 0,once:void 0,currentTimeout:void 0,maxRuns:r?r.maxRuns:void 0,paused:r?r.paused:!1,pattern:new W(`* * * * *`)},e&&(e instanceof Date||typeof e==`string`&&e.indexOf(`:`)>0)?this._states.once=new q(e,this.options.timezone||this.options.utcOffset):this._states.pattern=new W(e,this.options.timezone),this.name){if(X.find(e=>e.name===this.name))throw Error(`Cron: Tried to initialize new named job '`+this.name+`', but name already taken.`);X.push(this)}return i!==void 0&&se(i)&&(this.fn=i,this.schedule()),this}nextRun(e){let t=this._next(e);return t?t.getDate(!1):null}nextRuns(e,t){this._states.maxRuns!==void 0&&e>this._states.maxRuns&&(e=this._states.maxRuns);let n=[],r=t||this._states.currentRun||void 0;for(;e--&&(r=this.nextRun(r));)n.push(r);return n}getPattern(){return this._states.pattern?this._states.pattern.pattern:void 0}isRunning(){let e=this.nextRun(this._states.currentRun),t=!this._states.paused,n=this.fn!==void 0,r=!this._states.kill;return t&&n&&r&&e!==null}isStopped(){return this._states.kill}isBusy(){return this._states.blocking}currentRun(){return this._states.currentRun?this._states.currentRun.getDate():null}previousRun(){return this._states.previousRun?this._states.previousRun.getDate():null}msToNext(e){let t=this._next(e);return t?e instanceof q||e instanceof Date?t.getTime()-e.getTime():t.getTime()-new q(e).getTime():null}stop(){this._states.kill=!0,this._states.currentTimeout&&clearTimeout(this._states.currentTimeout);let e=X.indexOf(this);e>=0&&X.splice(e,1)}pause(){return this._states.paused=!0,!this._states.kill}resume(){return this._states.paused=!1,!this._states.kill}schedule(e){if(e&&this.fn)throw Error(`Cron: It is not allowed to schedule two functions using the same Croner instance.`);e&&(this.fn=e);let t=this.msToNext(),n=this.nextRun(this._states.currentRun);return t==null||isNaN(t)||n===null?this:(t>Y&&(t=Y),this._states.currentTimeout=setTimeout(()=>this._checkTrigger(n),t),this._states.currentTimeout&&this.options.unref&&ce(this._states.currentTimeout),this)}async _trigger(e){if(this._states.blocking=!0,this._states.currentRun=new q(void 0,this.options.timezone||this.options.utcOffset),this.options.catch)try{this.fn!==void 0&&await this.fn(this,this.options.context)}catch(e){J(this.options.catch)&&this.options.catch(e,this)}else this.fn!==void 0&&await this.fn(this,this.options.context);this._states.previousRun=new q(e,this.options.timezone||this.options.utcOffset),this._states.blocking=!1}async trigger(){await this._trigger()}runsLeft(){return this._states.maxRuns}_checkTrigger(e){let t=new Date,n=!this._states.paused&&t.getTime()>=e.getTime(),r=this._states.blocking&&this.options.protect;n&&!r?(this._states.maxRuns!==void 0&&this._states.maxRuns--,this._trigger()):n&&r&&J(this.options.protect)&&setTimeout(()=>this.options.protect(this),0),this.schedule()}_next(e){let t=!!(e||this._states.currentRun),n=!1;!e&&this.options.startAt&&this.options.interval&&([e,t]=this._calculatePreviousRun(e,t),n=!e),e=new q(e,this.options.timezone||this.options.utcOffset),this.options.startAt&&e&&e.getTime()<this.options.startAt.getTime()&&(e=this.options.startAt);let r=this._states.once||new q(e,this.options.timezone||this.options.utcOffset);return!n&&r!==this._states.once&&(r=r.increment(this._states.pattern,this.options,t)),this._states.once&&this._states.once.getTime()<=e.getTime()||r===null||this._states.maxRuns!==void 0&&this._states.maxRuns<=0||this._states.kill||this.options.stopAt&&r.getTime()>=this.options.stopAt.getTime()?null:r}_calculatePreviousRun(e,t){let n=new q(void 0,this.options.timezone||this.options.utcOffset),r=e;if(this.options.startAt.getTime()<=n.getTime()){r=this.options.startAt;let e=r.getTime()+this.options.interval*1e3;for(;e<=n.getTime();)r=new q(r,this.options.timezone||this.options.utcOffset).increment(this._states.pattern,this.options,!0),e=r.getTime()+this.options.interval*1e3;t=!0}return r===null&&(r=void 0),[r,t]}},le=[`bypassPermissions`,`acceptEdits`,`default`,`plan`];function ue({open:e,schedule:t,onClose:n,onSaved:r}){let i=u(),[a,o]=(0,M.useState)(()=>$(t)),[c,l]=(0,M.useState)([]),[p,m]=(0,M.useState)(!1),[g,_]=(0,M.useState)(null);(0,M.useEffect)(()=>{e&&(o($(t)),_(null),s.get(`/api/projects`).then(l).catch(()=>l([])))},[e,t]);let x=(0,M.useMemo)(()=>{try{return new Z(a.cron_expr).nextRuns(3).map(e=>e.toLocaleString())}catch{return null}},[a.cron_expr]),S=(e,t)=>o(n=>({...n,[e]:t})),C=(0,I.jsxs)(`div`,{className:`space-y-3 px-1`,children:[(0,I.jsx)(Q,{label:`Name`,children:(0,I.jsx)(O,{value:a.name,onChange:e=>S(`name`,e.target.value),placeholder:`Morning PR review`,className:`h-11 md:h-9 text-xs`})}),(0,I.jsxs)(Q,{label:`Cron expression (local timezone)`,children:[(0,I.jsx)(O,{value:a.cron_expr,onChange:e=>S(`cron_expr`,e.target.value),placeholder:`0 7 * * *`,className:`h-11 md:h-9 text-xs font-mono`}),(0,I.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:x?`Next: ${x.join(` · `)}`:`—`})]}),(0,I.jsx)(Q,{label:`Project`,children:(0,I.jsxs)(h,{value:a.project_path,onValueChange:e=>S(`project_path`,e),children:[(0,I.jsx)(T,{className:`w-full min-h-11 md:min-h-9 text-xs`,children:(0,I.jsx)(D,{placeholder:`Select project`})}),(0,I.jsx)(E,{children:c.map(e=>(0,I.jsx)(y,{value:e.path,children:e.name},e.path))})]})}),(0,I.jsx)(Q,{label:`Prompt (do not embed secrets)`,children:(0,I.jsx)(`textarea`,{value:a.prompt,onChange:e=>S(`prompt`,e.target.value),placeholder:`Check open PRs and summarize. If nothing to do, finish immediately.`,rows:4,className:`w-full rounded-md border border-input bg-transparent px-3 py-2 text-xs outline-none focus-visible:ring-2 focus-visible:ring-ring/50 resize-y`})}),(0,I.jsxs)(Q,{label:`Permission mode`,children:[(0,I.jsxs)(h,{value:a.permission_mode,onValueChange:e=>S(`permission_mode`,e),children:[(0,I.jsx)(T,{className:`w-full min-h-11 md:min-h-9 text-xs`,children:(0,I.jsx)(D,{})}),(0,I.jsx)(E,{children:le.map(e=>(0,I.jsx)(y,{value:e,children:e},e))})]}),a.permission_mode===`bypassPermissions`&&(0,I.jsx)(`p`,{className:`text-[11px] text-warning`,children:`⚠ Unattended writes — agent can modify code and run commands`})]}),(0,I.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,I.jsx)(Q,{label:`Max turns (optional)`,children:(0,I.jsx)(O,{type:`number`,min:1,value:a.max_turns,onChange:e=>S(`max_turns`,e.target.value),placeholder:`∞`,className:`h-11 md:h-9 text-xs`})}),(0,I.jsx)(Q,{label:`Timeout (ms)`,children:(0,I.jsx)(O,{type:`number`,min:1e4,value:a.timeout_ms,onChange:e=>S(`timeout_ms`,e.target.value),className:`h-11 md:h-9 text-xs`})})]}),(0,I.jsxs)(`div`,{className:`flex items-center justify-between min-h-11`,children:[(0,I.jsx)(`span`,{className:`text-xs font-medium`,children:`Enabled`}),(0,I.jsx)(v,{checked:a.enabled,onCheckedChange:e=>S(`enabled`,e)})]}),g&&(0,I.jsx)(`p`,{className:`text-[11px] text-error`,children:g}),(0,I.jsx)(d,{onClick:async()=>{if(!a.name.trim()||!a.project_path||!a.prompt.trim()){_(`Name, project, and prompt are required`);return}if(!x){_(`Invalid cron expression`);return}m(!0),_(null);try{let e={name:a.name.trim(),cron_expr:a.cron_expr,project_path:a.project_path,prompt:a.prompt,permission_mode:a.permission_mode,max_turns:a.max_turns===``?null:Number(a.max_turns),timeout_ms:Number(a.timeout_ms)||18e5,enabled:a.enabled};t?await s.patch(`/api/schedules/${t.id}`,e):await s.post(`/api/schedules`,e),r(),n()}catch(e){_(e instanceof Error?e.message:String(e))}finally{m(!1)}},disabled:p,className:`w-full min-h-11 cursor-pointer`,children:p?`Saving…`:t?`Save changes`:`Create schedule`})]}),w=t?`Edit: ${t.name}`:`New schedule`;return i?(0,I.jsxs)(f,{open:e,onClose:n,className:`max-h-[85vh] flex flex-col`,children:[(0,I.jsx)(`p`,{className:`text-sm font-semibold text-center pb-2`,children:w}),(0,I.jsx)(b,{className:`flex-1 min-h-0 px-3 pb-3`,children:C})]}):(0,I.jsx)(k,{open:e,onOpenChange:e=>!e&&n(),children:(0,I.jsxs)(te,{className:`max-w-md max-h-[85vh] overflow-y-auto`,children:[(0,I.jsx)(ee,{children:(0,I.jsx)(A,{className:`text-sm`,children:w})}),C]})})}function Q({label:e,children:t}){return(0,I.jsxs)(`div`,{className:`space-y-1`,children:[(0,I.jsx)(`p`,{className:`text-xs font-medium text-muted-foreground`,children:e}),t]})}function $(e){return{name:e?.name??``,cron_expr:e?.cron_expr??`0 7 * * *`,project_path:e?.project_path??``,prompt:e?.prompt??``,permission_mode:e?.permission_mode??`bypassPermissions`,max_turns:e?.max_turns==null?``:String(e.max_turns),timeout_ms:String(e?.timeout_ms??18e5),enabled:e?!!e.enabled:!0}}function de(){let{schedules:e,loading:t,refetch:n}=P(),[i,a]=(0,M.useState)(!1),[o,s]=(0,M.useState)(null),c=()=>{s(null),a(!0)},l=e=>{s(e),a(!0)};return(0,I.jsxs)(`div`,{className:`space-y-3`,children:[(0,I.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,I.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`Periodically wake Claude to work on a project unattended.`}),(0,I.jsxs)(d,{size:`sm`,onClick:c,className:`min-h-11 md:min-h-8 text-xs gap-1 cursor-pointer shrink-0`,children:[(0,I.jsx)(C,{className:`size-3.5`}),` Add`]})]}),t&&e.length===0?(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground py-4 text-center`,children:`Loading…`}):e.length===0?(0,I.jsxs)(`div`,{className:`flex flex-col items-center gap-2 py-8 text-center`,children:[(0,I.jsx)(r,{className:`size-8 text-muted-foreground/50`}),(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`No schedules yet. Add one to run Claude periodically.`}),(0,I.jsxs)(d,{size:`sm`,onClick:c,className:`min-h-11 text-xs gap-1 cursor-pointer`,children:[(0,I.jsx)(C,{className:`size-3.5`}),` Add schedule`]})]}):(0,I.jsx)(`div`,{className:`space-y-2`,children:e.map(e=>(0,I.jsx)(ae,{schedule:e,onEdit:()=>l(e),onChanged:n},e.id))}),(0,I.jsx)(ue,{open:i,schedule:o,onClose:()=>a(!1),onSaved:n})]})}export{de as SchedulesSettingsSection};
1
+ import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{C as t,S as n}from"./vendor-markdown-CuWCHIVb.js";import"./vendor-ui-BBdkypKW.js";import{t as r}from"./calendar-clock-CDP7AVjA.js";import{t as i}from"./chevron-down-B9puixxZ.js";import{t as a}from"./chevron-right-DK_HbYZC.js";import{t as o}from"./power-CvtnQHU4.js";import{n as s,s as c}from"./api-client-DwXlVfXP.js";import{n as l}from"./utils-IrnQujwR.js";import"./portal-container-context-DeLx1cOI.js";import"./context-menu-DM9CgxGh.js";import{n as u}from"./use-is-mobile-Bi42QhIi.js";import{t as d}from"./button-zgoXa9r7.js";import{t as f}from"./mobile-bottom-sheet-Ch1e_JBq.js";import"./use-visual-viewport-CNdG4QHH.js";import{$n as p,$t as ee,At as m,B as h,Dt as g,Et as _,G as v,H as y,J as b,Ln as x,Pt as S,Qn as C,Tt as w,U as T,V as E,W as D,X as O,Xt as te,Yt as k,en as A,nr as j}from"./index-DVNJ2W5R.js";var M=e(t(),1),N=1e4;function P(){let[e,t]=(0,M.useState)([]),[n,r]=(0,M.useState)(!0),i=(0,M.useCallback)(async()=>{try{t(await s.get(`/api/schedules`))}catch{}finally{r(!1)}},[]);return(0,M.useEffect)(()=>{i();let e=setInterval(()=>{document.visibilityState===`visible`&&i()},N);return()=>clearInterval(e)},[i]),{schedules:e,loading:n,refetch:i}}function F(e){let[t,n]=(0,M.useState)([]),[r,i]=(0,M.useState)(!1),a=(0,M.useCallback)(async()=>{if(e!=null){i(!0);try{n(await s.get(`/api/schedules/${e}/runs?limit=20`))}catch{n([])}finally{i(!1)}}},[e]);return(0,M.useEffect)(()=>{a()},[a]),{runs:t,loading:r,refetch:a}}var I=n(),ne={done:`bg-success/10 text-success`,error:`bg-error/10 text-error`,running:`bg-warning/10 text-warning`,skipped:`bg-muted text-muted-foreground`};function re({scheduleId:e}){let{runs:t,loading:n}=F(e);return n&&t.length===0?(0,I.jsx)(`p`,{className:`text-[11px] text-muted-foreground py-1`,children:`Loading runs…`}):t.length===0?(0,I.jsx)(`p`,{className:`text-[11px] text-muted-foreground py-1`,children:`No runs yet.`}):(0,I.jsx)(`div`,{className:`space-y-1`,children:t.map(e=>(0,I.jsx)(ie,{run:e},e.id))})}function L(e){return new Date(e.includes(`T`)?e:e.replace(` `,`T`)+`Z`)}function ie({run:e}){let[t,n]=(0,M.useState)(!1),r=!!(e.output_truncated||e.error),i=e.ended_at?`${Math.round((L(e.ended_at).getTime()-L(e.started_at).getTime())/1e3)}s`:`…`;return(0,I.jsxs)(`div`,{className:`rounded border border-border text-[11px]`,children:[(0,I.jsxs)(`button`,{type:`button`,onClick:()=>r&&n(!t),className:l(`w-full flex items-center gap-2 px-2 py-2 min-h-11 text-left`,r&&`cursor-pointer hover:bg-accent/30`),children:[(0,I.jsx)(`span`,{className:l(`rounded px-1.5 py-0.5 font-medium shrink-0`,ne[e.status]),children:e.status}),(0,I.jsxs)(`span`,{className:`text-muted-foreground truncate flex-1`,children:[L(e.started_at).toLocaleString(),` · `,i,e.cost_usd!=null&&` · $${e.cost_usd.toFixed(4)}`,e.context_window_pct!=null&&` · ctx ${e.context_window_pct}%`]})]}),t&&(0,I.jsxs)(`div`,{className:`px-2 pb-2 space-y-1`,children:[e.error&&(0,I.jsx)(`p`,{className:`text-error break-all`,children:e.error}),e.output_truncated&&(0,I.jsx)(`pre`,{className:`overflow-auto max-h-96 whitespace-pre-wrap break-all text-muted-foreground font-mono text-[10px]`,children:e.output_truncated})]})]})}function ae({schedule:e,onEdit:t,onChanged:n}){let[r,u]=(0,M.useState)(!1),[d,f]=(0,M.useState)(0);return(0,I.jsxs)(`div`,{className:`rounded-lg border border-border`,children:[(0,I.jsxs)(w,{children:[(0,I.jsx)(S,{asChild:!0,children:(0,I.jsxs)(`button`,{type:`button`,onClick:()=>u(!r),className:`w-full flex items-center gap-2 px-2.5 py-2.5 min-h-11 text-left cursor-pointer hover:bg-accent/30`,children:[r?(0,I.jsx)(i,{className:`size-3.5 shrink-0 text-muted-foreground`}):(0,I.jsx)(a,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,I.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,I.jsx)(`p`,{className:`text-xs font-medium truncate`,children:e.name}),(0,I.jsxs)(`p`,{className:`text-[11px] text-muted-foreground truncate`,children:[(0,I.jsx)(`span`,{className:`font-mono`,children:e.cron_expr}),` · `,e.next_fire_at&&e.enabled?`next ${new Date(e.next_fire_at).toLocaleString()}`:`—`]})]}),(0,I.jsx)(`span`,{className:l(`rounded px-1.5 py-0.5 text-[10px] font-medium shrink-0`,e.enabled?`bg-success/10 text-success`:`bg-muted text-muted-foreground`),children:e.enabled?`Enabled`:`Disabled`})]})}),(0,I.jsxs)(_,{children:[(0,I.jsxs)(g,{onClick:async()=>{try{let t=await s.post(`/api/schedules/${e.id}/run-now`);c.success(`Run #${t.runId} started${t.wasRunning?` (previous run still active)`:``}`),u(!0),f(e=>e+1)}catch(e){c.error(e instanceof Error?e.message:`Run failed`)}},children:[(0,I.jsx)(p,{className:`size-3.5`}),` Run now`]}),(0,I.jsxs)(g,{onClick:async()=>{try{await s.patch(`/api/schedules/${e.id}`,{enabled:!e.enabled}),n()}catch(e){c.error(e instanceof Error?e.message:`Update failed`)}},children:[(0,I.jsx)(o,{className:`size-3.5`}),` `,e.enabled?`Disable`:`Enable`]}),(0,I.jsxs)(g,{onClick:t,children:[(0,I.jsx)(j,{className:`size-3.5`}),` Edit`]}),(0,I.jsx)(m,{}),(0,I.jsxs)(g,{variant:`destructive`,onClick:async()=>{try{await s.del(`/api/schedules/${e.id}`),c.success(`Schedule deleted`),n()}catch(e){c.error(e instanceof Error?e.message:`Delete failed`)}},children:[(0,I.jsx)(x,{className:`size-3.5`}),` Delete`]})]})]}),r&&(0,I.jsxs)(`div`,{className:`px-2.5 pb-2.5 space-y-1.5`,children:[(0,I.jsx)(`p`,{className:`text-[11px] text-muted-foreground break-all line-clamp-3`,children:e.prompt}),(0,I.jsx)(re,{scheduleId:e.id},d)]})]})}function R(e,t,n,r,i,a,o,s){return R.fromTZ(R.tp(e,t,n,r,i,a,o),s)}R.fromTZISO=(e,t,n)=>R.fromTZ(B(e,t),n),R.fromTZ=function(e,t){let n=new Date(Date.UTC(e.y,e.m-1,e.d,e.h,e.i,e.s)),r=z(e.tz,n),i=new Date(n.getTime()-r),a=z(e.tz,i);if(a-r===0)return i;{let r=new Date(n.getTime()-a),o=z(e.tz,r);if(o-a===0||!t&&o-a>0)return r;if(t)throw Error(`Invalid date passed to fromTZ()`);return i}},R.toTZ=function(e,t){let n=e.toLocaleString(`en-US`,{timeZone:t}).replace(/[\u202f]/,` `),r=new Date(n);return{y:r.getFullYear(),m:r.getMonth()+1,d:r.getDate(),h:r.getHours(),i:r.getMinutes(),s:r.getSeconds(),tz:t}},R.tp=(e,t,n,r,i,a,o)=>({y:e,m:t,d:n,h:r,i,s:a,tz:o});function z(e,t=new Date){let n=t.toLocaleString(`en-US`,{timeZone:e,timeZoneName:`shortOffset`}).split(` `).slice(-1)[0],r=t.toLocaleString(`en-US`).replace(/[\u202f]/,` `);return Date.parse(`${r} GMT`)-Date.parse(`${r} ${n}`)}function B(e,t){let n=new Date(Date.parse(e));if(isNaN(n))throw Error(`minitz: Invalid ISO8601 passed to parser.`);let r=e.substring(9);return e.includes(`Z`)||r.includes(`-`)||r.includes(`+`)?R.tp(n.getUTCFullYear(),n.getUTCMonth()+1,n.getUTCDate(),n.getUTCHours(),n.getUTCMinutes(),n.getUTCSeconds(),`Etc/UTC`):R.tp(n.getFullYear(),n.getMonth()+1,n.getDate(),n.getHours(),n.getMinutes(),n.getSeconds(),t)}R.minitz=R;var V=32,H=31|V,U=[1,2,4,8,16],W=class{pattern;timezone;second;minute;hour;day;month;dayOfWeek;lastDayOfMonth;starDOM;starDOW;constructor(e,t){this.pattern=e,this.timezone=t,this.second=Array(60).fill(0),this.minute=Array(60).fill(0),this.hour=Array(24).fill(0),this.day=Array(31).fill(0),this.month=Array(12).fill(0),this.dayOfWeek=Array(7).fill(0),this.lastDayOfMonth=!1,this.starDOM=!1,this.starDOW=!1,this.parse()}parse(){if(!(typeof this.pattern==`string`||this.pattern instanceof String))throw TypeError(`CronPattern: Pattern has to be of type string.`);this.pattern.indexOf(`@`)>=0&&(this.pattern=this.handleNicknames(this.pattern).trim());let e=this.pattern.replace(/\s+/g,` `).split(` `);if(e.length<5||e.length>6)throw TypeError(`CronPattern: invalid configuration format ('`+this.pattern+`'), exactly five or six space separated parts are required.`);if(e.length===5&&e.unshift(`0`),e[3].indexOf(`L`)>=0&&(e[3]=e[3].replace(`L`,``),this.lastDayOfMonth=!0),e[3]==`*`&&(this.starDOM=!0),e[4].length>=3&&(e[4]=this.replaceAlphaMonths(e[4])),e[5].length>=3&&(e[5]=this.replaceAlphaDays(e[5])),e[5]==`*`&&(this.starDOW=!0),this.pattern.indexOf(`?`)>=0){let t=new q(new Date,this.timezone).getDate(!0);e[0]=e[0].replace(`?`,t.getSeconds().toString()),e[1]=e[1].replace(`?`,t.getMinutes().toString()),e[2]=e[2].replace(`?`,t.getHours().toString()),this.starDOM||(e[3]=e[3].replace(`?`,t.getDate().toString())),e[4]=e[4].replace(`?`,(t.getMonth()+1).toString()),this.starDOW||(e[5]=e[5].replace(`?`,t.getDay().toString()))}this.throwAtIllegalCharacters(e),this.partToArray(`second`,e[0],0,1),this.partToArray(`minute`,e[1],0,1),this.partToArray(`hour`,e[2],0,1),this.partToArray(`day`,e[3],-1,1),this.partToArray(`month`,e[4],-1,1),this.partToArray(`dayOfWeek`,e[5],0,H),this.dayOfWeek[7]&&(this.dayOfWeek[0]=this.dayOfWeek[7])}partToArray(e,t,n,r){let i=this[e],a=e===`day`&&this.lastDayOfMonth;if(t===``&&!a)throw TypeError(`CronPattern: configuration entry `+e+` (`+t+`) is empty, check for trailing spaces.`);if(t===`*`)return i.fill(r);let o=t.split(`,`);if(o.length>1)for(let t=0;t<o.length;t++)this.partToArray(e,o[t],n,r);else t.indexOf(`-`)!==-1&&t.indexOf(`/`)!==-1?this.handleRangeWithStepping(t,e,n,r):t.indexOf(`-`)===-1?t.indexOf(`/`)===-1?t!==``&&this.handleNumber(t,e,n,r):this.handleStepping(t,e,n,r):this.handleRange(t,e,n,r)}throwAtIllegalCharacters(e){for(let t=0;t<e.length;t++)if((t===5?/[^/*0-9,\-#L]+/:/[^/*0-9,-]+/).test(e[t]))throw TypeError(`CronPattern: configuration entry `+t+` (`+e[t]+`) contains illegal characters.`)}handleNumber(e,t,n,r){let i=this.extractNth(e,t),a=parseInt(i[0],10)+n;if(isNaN(a))throw TypeError(`CronPattern: `+t+` is not a number: '`+e+`'`);this.setPart(t,a,i[1]||r)}setPart(e,t,n){if(!Object.prototype.hasOwnProperty.call(this,e))throw TypeError(`CronPattern: Invalid part specified: `+e);if(e===`dayOfWeek`){if(t===7&&(t=0),t<0||t>6)throw RangeError(`CronPattern: Invalid value for dayOfWeek: `+t);this.setNthWeekdayOfMonth(t,n);return}if(e===`second`||e===`minute`){if(t<0||t>=60)throw RangeError(`CronPattern: Invalid value for `+e+`: `+t)}else if(e===`hour`){if(t<0||t>=24)throw RangeError(`CronPattern: Invalid value for `+e+`: `+t)}else if(e===`day`){if(t<0||t>=31)throw RangeError(`CronPattern: Invalid value for `+e+`: `+t)}else if(e===`month`&&(t<0||t>=12))throw RangeError(`CronPattern: Invalid value for `+e+`: `+t);this[e][t]=n}handleRangeWithStepping(e,t,n,r){let i=this.extractNth(e,t),a=i[0].match(/^(\d+)-(\d+)\/(\d+)$/);if(a===null)throw TypeError(`CronPattern: Syntax error, illegal range with stepping: '`+e+`'`);let[,o,s,c]=a,l=parseInt(o,10)+n,u=parseInt(s,10)+n,d=parseInt(c,10);if(isNaN(l))throw TypeError(`CronPattern: Syntax error, illegal lower range (NaN)`);if(isNaN(u))throw TypeError(`CronPattern: Syntax error, illegal upper range (NaN)`);if(isNaN(d))throw TypeError(`CronPattern: Syntax error, illegal stepping: (NaN)`);if(d===0)throw TypeError(`CronPattern: Syntax error, illegal stepping: 0`);if(d>this[t].length)throw TypeError(`CronPattern: Syntax error, steps cannot be greater than maximum value of part (`+this[t].length+`)`);if(l>u)throw TypeError(`CronPattern: From value is larger than to value: '`+e+`'`);for(let e=l;e<=u;e+=d)this.setPart(t,e,i[1]||r)}extractNth(e,t){let n=e,r;if(n.includes(`#`)){if(t!==`dayOfWeek`)throw Error(`CronPattern: nth (#) only allowed in day-of-week field`);r=n.split(`#`)[1],n=n.split(`#`)[0]}return[n,r]}handleRange(e,t,n,r){let i=this.extractNth(e,t),a=i[0].split(`-`);if(a.length!==2)throw TypeError(`CronPattern: Syntax error, illegal range: '`+e+`'`);let o=parseInt(a[0],10)+n,s=parseInt(a[1],10)+n;if(isNaN(o))throw TypeError(`CronPattern: Syntax error, illegal lower range (NaN)`);if(isNaN(s))throw TypeError(`CronPattern: Syntax error, illegal upper range (NaN)`);if(o>s)throw TypeError(`CronPattern: From value is larger than to value: '`+e+`'`);for(let e=o;e<=s;e++)this.setPart(t,e,i[1]||r)}handleStepping(e,t,n,r){let i=this.extractNth(e,t),a=i[0].split(`/`);if(a.length!==2)throw TypeError(`CronPattern: Syntax error, illegal stepping: '`+e+`'`);a[0]===``&&(a[0]=`*`);let o=0;a[0]!==`*`&&(o=parseInt(a[0],10)+n);let s=parseInt(a[1],10);if(isNaN(s))throw TypeError(`CronPattern: Syntax error, illegal stepping: (NaN)`);if(s===0)throw TypeError(`CronPattern: Syntax error, illegal stepping: 0`);if(s>this[t].length)throw TypeError(`CronPattern: Syntax error, max steps for part is (`+this[t].length+`)`);for(let e=o;e<this[t].length;e+=s)this.setPart(t,e,i[1]||r)}replaceAlphaDays(e){return e.replace(/-sun/gi,`-7`).replace(/sun/gi,`0`).replace(/mon/gi,`1`).replace(/tue/gi,`2`).replace(/wed/gi,`3`).replace(/thu/gi,`4`).replace(/fri/gi,`5`).replace(/sat/gi,`6`)}replaceAlphaMonths(e){return e.replace(/jan/gi,`1`).replace(/feb/gi,`2`).replace(/mar/gi,`3`).replace(/apr/gi,`4`).replace(/may/gi,`5`).replace(/jun/gi,`6`).replace(/jul/gi,`7`).replace(/aug/gi,`8`).replace(/sep/gi,`9`).replace(/oct/gi,`10`).replace(/nov/gi,`11`).replace(/dec/gi,`12`)}handleNicknames(e){let t=e.trim().toLowerCase();return t===`@yearly`||t===`@annually`?`0 0 1 1 *`:t===`@monthly`?`0 0 1 * *`:t===`@weekly`?`0 0 * * 0`:t===`@daily`?`0 0 * * *`:t===`@hourly`?`0 * * * *`:e}setNthWeekdayOfMonth(e,t){if(typeof t!=`number`&&t===`L`)this.dayOfWeek[e]=this.dayOfWeek[e]|V;else if(t===H)this.dayOfWeek[e]=H;else if(t<6&&t>0)this.dayOfWeek[e]=this.dayOfWeek[e]|U[t-1];else throw TypeError(`CronPattern: nth weekday out of range, should be 1-5 or L. Value: ${t}, Type: ${typeof t}`)}},G=[31,28,31,30,31,30,31,31,30,31,30,31],K=[[`month`,`year`,0],[`day`,`month`,-1],[`hour`,`day`,0],[`minute`,`hour`,0],[`second`,`minute`,0]],q=class e{tz;ms;second;minute;hour;day;month;year;constructor(t,n){if(this.tz=n,t&&t instanceof Date)if(!isNaN(t))this.fromDate(t);else throw TypeError(`CronDate: Invalid date passed to CronDate constructor`);else if(t===void 0)this.fromDate(new Date);else if(t&&typeof t==`string`)this.fromString(t);else if(t instanceof e)this.fromCronDate(t);else throw TypeError(`CronDate: Invalid type (`+typeof t+`) passed to CronDate constructor`)}isNthWeekdayOfMonth(e,t,n,r){let i=new Date(Date.UTC(e,t,n)).getUTCDay(),a=0;for(let r=1;r<=n;r++)new Date(Date.UTC(e,t,r)).getUTCDay()===i&&a++;if(r&H&&U[a-1]&r)return!0;if(r&V){let r=new Date(Date.UTC(e,t+1,0)).getUTCDate();for(let a=n+1;a<=r;a++)if(new Date(Date.UTC(e,t,a)).getUTCDay()===i)return!1;return!0}return!1}fromDate(e){if(this.tz!==void 0)if(typeof this.tz==`number`)this.ms=e.getUTCMilliseconds(),this.second=e.getUTCSeconds(),this.minute=e.getUTCMinutes()+this.tz,this.hour=e.getUTCHours(),this.day=e.getUTCDate(),this.month=e.getUTCMonth(),this.year=e.getUTCFullYear(),this.apply();else{let t=R.toTZ(e,this.tz);this.ms=e.getMilliseconds(),this.second=t.s,this.minute=t.i,this.hour=t.h,this.day=t.d,this.month=t.m-1,this.year=t.y}else this.ms=e.getMilliseconds(),this.second=e.getSeconds(),this.minute=e.getMinutes(),this.hour=e.getHours(),this.day=e.getDate(),this.month=e.getMonth(),this.year=e.getFullYear()}fromCronDate(e){this.tz=e.tz,this.year=e.year,this.month=e.month,this.day=e.day,this.hour=e.hour,this.minute=e.minute,this.second=e.second,this.ms=e.ms}apply(){if(this.month>11||this.day>G[this.month]||this.hour>59||this.minute>59||this.second>59||this.hour<0||this.minute<0||this.second<0){let e=new Date(Date.UTC(this.year,this.month,this.day,this.hour,this.minute,this.second,this.ms));return this.ms=e.getUTCMilliseconds(),this.second=e.getUTCSeconds(),this.minute=e.getUTCMinutes(),this.hour=e.getUTCHours(),this.day=e.getUTCDate(),this.month=e.getUTCMonth(),this.year=e.getUTCFullYear(),!0}else return!1}fromString(e){if(typeof this.tz==`number`){let t=R.fromTZISO(e);this.ms=t.getUTCMilliseconds(),this.second=t.getUTCSeconds(),this.minute=t.getUTCMinutes(),this.hour=t.getUTCHours(),this.day=t.getUTCDate(),this.month=t.getUTCMonth(),this.year=t.getUTCFullYear(),this.apply()}else return this.fromDate(R.fromTZISO(e,this.tz))}findNext(e,t,n,r){let i=this[t],a;n.lastDayOfMonth&&(a=this.month===1?new Date(Date.UTC(this.year,this.month+1,0,0,0,0,0)).getUTCDate():G[this.month]);let o=!n.starDOW&&t==`day`?new Date(Date.UTC(this.year,this.month,1,0,0,0,0)).getUTCDay():void 0;for(let s=this[t]+r;s<n[t].length;s++){let c=n[t][s];if(t===`day`&&n.lastDayOfMonth&&s-r==a&&(c=1),t===`day`&&!n.starDOW){let t=n.dayOfWeek[(o+(s-r-1))%7];if(t&&t&H)t=this.isNthWeekdayOfMonth(this.year,this.month,s-r,t)?1:0;else if(t)throw Error(`CronDate: Invalid value for dayOfWeek encountered. ${t}`);e.legacyMode&&!n.starDOM?c||=t:c&&=t}if(c)return this[t]=s-r,i===this[t]?1:2}return 3}recurse(e,t,n){let r=this.findNext(t,K[n][0],e,K[n][2]);if(r>1){let i=n+1;for(;i<K.length;)this[K[i][0]]=-K[i][2],i++;if(r===3)return this[K[n][1]]++,this[K[n][0]]=-K[n][2],this.apply(),this.recurse(e,t,0);if(this.apply())return this.recurse(e,t,n-1)}return n+=1,n>=K.length?this:this.year>=3e3?null:this.recurse(e,t,n)}increment(e,t,n){return this.second+=t.interval!==void 0&&t.interval>1&&n?t.interval:1,this.ms=0,this.apply(),this.recurse(e,t,0)}getDate(e){return e||this.tz===void 0?new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.ms):typeof this.tz==`number`?new Date(Date.UTC(this.year,this.month,this.day,this.hour,this.minute-this.tz,this.second,this.ms)):R.fromTZ(R.tp(this.year,this.month+1,this.day,this.hour,this.minute,this.second,this.tz),!1)}getTime(){return this.getDate(!1).getTime()}};function oe(e){if(e===void 0&&(e={}),delete e.name,e.legacyMode=e.legacyMode===void 0?!0:e.legacyMode,e.paused=e.paused===void 0?!1:e.paused,e.maxRuns=e.maxRuns===void 0?1/0:e.maxRuns,e.catch=e.catch===void 0?!1:e.catch,e.interval=e.interval===void 0?0:parseInt(e.interval.toString(),10),e.utcOffset=e.utcOffset===void 0?void 0:parseInt(e.utcOffset.toString(),10),e.unref=e.unref===void 0?!1:e.unref,e.startAt&&=new q(e.startAt,e.timezone),e.stopAt&&=new q(e.stopAt,e.timezone),e.interval!==null){if(isNaN(e.interval))throw Error(`CronOptions: Supplied value for interval is not a number`);if(e.interval<0)throw Error(`CronOptions: Supplied value for interval can not be negative`)}if(e.utcOffset!==void 0){if(isNaN(e.utcOffset))throw Error(`CronOptions: Invalid value passed for utcOffset, should be number representing minutes offset from UTC.`);if(e.utcOffset<-870||e.utcOffset>870)throw Error(`CronOptions: utcOffset out of bounds.`);if(e.utcOffset!==void 0&&e.timezone)throw Error(`CronOptions: Combining 'utcOffset' with 'timezone' is not allowed.`)}if(e.unref!==!0&&e.unref!==!1)throw Error(`CronOptions: Unref should be either true, false or undefined(false).`);return e}function J(e){return Object.prototype.toString.call(e)===`[object Function]`||typeof e==`function`||e instanceof Function}function se(e){return J(e)}function ce(e){typeof Deno<`u`&&typeof Deno.unrefTimer<`u`?Deno.unrefTimer(e):e&&typeof e.unref<`u`&&e.unref()}var Y=30*1e3,X=[],Z=class{name;options;_states;fn;constructor(e,t,n){let r,i;if(J(t))i=t;else if(typeof t==`object`)r=t;else if(t!==void 0)throw Error(`Cron: Invalid argument passed for optionsIn. Should be one of function, or object (options).`);if(J(n))i=n;else if(typeof n==`object`)r=n;else if(n!==void 0)throw Error(`Cron: Invalid argument passed for funcIn. Should be one of function, or object (options).`);if(this.name=r?.name,this.options=oe(r),this._states={kill:!1,blocking:!1,previousRun:void 0,currentRun:void 0,once:void 0,currentTimeout:void 0,maxRuns:r?r.maxRuns:void 0,paused:r?r.paused:!1,pattern:new W(`* * * * *`)},e&&(e instanceof Date||typeof e==`string`&&e.indexOf(`:`)>0)?this._states.once=new q(e,this.options.timezone||this.options.utcOffset):this._states.pattern=new W(e,this.options.timezone),this.name){if(X.find(e=>e.name===this.name))throw Error(`Cron: Tried to initialize new named job '`+this.name+`', but name already taken.`);X.push(this)}return i!==void 0&&se(i)&&(this.fn=i,this.schedule()),this}nextRun(e){let t=this._next(e);return t?t.getDate(!1):null}nextRuns(e,t){this._states.maxRuns!==void 0&&e>this._states.maxRuns&&(e=this._states.maxRuns);let n=[],r=t||this._states.currentRun||void 0;for(;e--&&(r=this.nextRun(r));)n.push(r);return n}getPattern(){return this._states.pattern?this._states.pattern.pattern:void 0}isRunning(){let e=this.nextRun(this._states.currentRun),t=!this._states.paused,n=this.fn!==void 0,r=!this._states.kill;return t&&n&&r&&e!==null}isStopped(){return this._states.kill}isBusy(){return this._states.blocking}currentRun(){return this._states.currentRun?this._states.currentRun.getDate():null}previousRun(){return this._states.previousRun?this._states.previousRun.getDate():null}msToNext(e){let t=this._next(e);return t?e instanceof q||e instanceof Date?t.getTime()-e.getTime():t.getTime()-new q(e).getTime():null}stop(){this._states.kill=!0,this._states.currentTimeout&&clearTimeout(this._states.currentTimeout);let e=X.indexOf(this);e>=0&&X.splice(e,1)}pause(){return this._states.paused=!0,!this._states.kill}resume(){return this._states.paused=!1,!this._states.kill}schedule(e){if(e&&this.fn)throw Error(`Cron: It is not allowed to schedule two functions using the same Croner instance.`);e&&(this.fn=e);let t=this.msToNext(),n=this.nextRun(this._states.currentRun);return t==null||isNaN(t)||n===null?this:(t>Y&&(t=Y),this._states.currentTimeout=setTimeout(()=>this._checkTrigger(n),t),this._states.currentTimeout&&this.options.unref&&ce(this._states.currentTimeout),this)}async _trigger(e){if(this._states.blocking=!0,this._states.currentRun=new q(void 0,this.options.timezone||this.options.utcOffset),this.options.catch)try{this.fn!==void 0&&await this.fn(this,this.options.context)}catch(e){J(this.options.catch)&&this.options.catch(e,this)}else this.fn!==void 0&&await this.fn(this,this.options.context);this._states.previousRun=new q(e,this.options.timezone||this.options.utcOffset),this._states.blocking=!1}async trigger(){await this._trigger()}runsLeft(){return this._states.maxRuns}_checkTrigger(e){let t=new Date,n=!this._states.paused&&t.getTime()>=e.getTime(),r=this._states.blocking&&this.options.protect;n&&!r?(this._states.maxRuns!==void 0&&this._states.maxRuns--,this._trigger()):n&&r&&J(this.options.protect)&&setTimeout(()=>this.options.protect(this),0),this.schedule()}_next(e){let t=!!(e||this._states.currentRun),n=!1;!e&&this.options.startAt&&this.options.interval&&([e,t]=this._calculatePreviousRun(e,t),n=!e),e=new q(e,this.options.timezone||this.options.utcOffset),this.options.startAt&&e&&e.getTime()<this.options.startAt.getTime()&&(e=this.options.startAt);let r=this._states.once||new q(e,this.options.timezone||this.options.utcOffset);return!n&&r!==this._states.once&&(r=r.increment(this._states.pattern,this.options,t)),this._states.once&&this._states.once.getTime()<=e.getTime()||r===null||this._states.maxRuns!==void 0&&this._states.maxRuns<=0||this._states.kill||this.options.stopAt&&r.getTime()>=this.options.stopAt.getTime()?null:r}_calculatePreviousRun(e,t){let n=new q(void 0,this.options.timezone||this.options.utcOffset),r=e;if(this.options.startAt.getTime()<=n.getTime()){r=this.options.startAt;let e=r.getTime()+this.options.interval*1e3;for(;e<=n.getTime();)r=new q(r,this.options.timezone||this.options.utcOffset).increment(this._states.pattern,this.options,!0),e=r.getTime()+this.options.interval*1e3;t=!0}return r===null&&(r=void 0),[r,t]}},le=[`bypassPermissions`,`acceptEdits`,`default`,`plan`];function ue({open:e,schedule:t,onClose:n,onSaved:r}){let i=u(),[a,o]=(0,M.useState)(()=>$(t)),[c,l]=(0,M.useState)([]),[p,m]=(0,M.useState)(!1),[g,_]=(0,M.useState)(null);(0,M.useEffect)(()=>{e&&(o($(t)),_(null),s.get(`/api/projects`).then(l).catch(()=>l([])))},[e,t]);let x=(0,M.useMemo)(()=>{try{return new Z(a.cron_expr).nextRuns(3).map(e=>e.toLocaleString())}catch{return null}},[a.cron_expr]),S=(e,t)=>o(n=>({...n,[e]:t})),C=(0,I.jsxs)(`div`,{className:`space-y-3 px-1`,children:[(0,I.jsx)(Q,{label:`Name`,children:(0,I.jsx)(O,{value:a.name,onChange:e=>S(`name`,e.target.value),placeholder:`Morning PR review`,className:`h-11 md:h-9 text-xs`})}),(0,I.jsxs)(Q,{label:`Cron expression (local timezone)`,children:[(0,I.jsx)(O,{value:a.cron_expr,onChange:e=>S(`cron_expr`,e.target.value),placeholder:`0 7 * * *`,className:`h-11 md:h-9 text-xs font-mono`}),(0,I.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:x?`Next: ${x.join(` · `)}`:`—`})]}),(0,I.jsx)(Q,{label:`Project`,children:(0,I.jsxs)(h,{value:a.project_path,onValueChange:e=>S(`project_path`,e),children:[(0,I.jsx)(T,{className:`w-full min-h-11 md:min-h-9 text-xs`,children:(0,I.jsx)(D,{placeholder:`Select project`})}),(0,I.jsx)(E,{children:c.map(e=>(0,I.jsx)(y,{value:e.path,children:e.name},e.path))})]})}),(0,I.jsx)(Q,{label:`Prompt (do not embed secrets)`,children:(0,I.jsx)(`textarea`,{value:a.prompt,onChange:e=>S(`prompt`,e.target.value),placeholder:`Check open PRs and summarize. If nothing to do, finish immediately.`,rows:4,className:`w-full rounded-md border border-input bg-transparent px-3 py-2 text-xs outline-none focus-visible:ring-2 focus-visible:ring-ring/50 resize-y`})}),(0,I.jsxs)(Q,{label:`Permission mode`,children:[(0,I.jsxs)(h,{value:a.permission_mode,onValueChange:e=>S(`permission_mode`,e),children:[(0,I.jsx)(T,{className:`w-full min-h-11 md:min-h-9 text-xs`,children:(0,I.jsx)(D,{})}),(0,I.jsx)(E,{children:le.map(e=>(0,I.jsx)(y,{value:e,children:e},e))})]}),a.permission_mode===`bypassPermissions`&&(0,I.jsx)(`p`,{className:`text-[11px] text-warning`,children:`⚠ Unattended writes — agent can modify code and run commands`})]}),(0,I.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,I.jsx)(Q,{label:`Max turns (optional)`,children:(0,I.jsx)(O,{type:`number`,min:1,value:a.max_turns,onChange:e=>S(`max_turns`,e.target.value),placeholder:`∞`,className:`h-11 md:h-9 text-xs`})}),(0,I.jsx)(Q,{label:`Timeout (ms)`,children:(0,I.jsx)(O,{type:`number`,min:1e4,value:a.timeout_ms,onChange:e=>S(`timeout_ms`,e.target.value),className:`h-11 md:h-9 text-xs`})})]}),(0,I.jsxs)(`div`,{className:`flex items-center justify-between min-h-11`,children:[(0,I.jsx)(`span`,{className:`text-xs font-medium`,children:`Enabled`}),(0,I.jsx)(v,{checked:a.enabled,onCheckedChange:e=>S(`enabled`,e)})]}),g&&(0,I.jsx)(`p`,{className:`text-[11px] text-error`,children:g}),(0,I.jsx)(d,{onClick:async()=>{if(!a.name.trim()||!a.project_path||!a.prompt.trim()){_(`Name, project, and prompt are required`);return}if(!x){_(`Invalid cron expression`);return}m(!0),_(null);try{let e={name:a.name.trim(),cron_expr:a.cron_expr,project_path:a.project_path,prompt:a.prompt,permission_mode:a.permission_mode,max_turns:a.max_turns===``?null:Number(a.max_turns),timeout_ms:Number(a.timeout_ms)||18e5,enabled:a.enabled};t?await s.patch(`/api/schedules/${t.id}`,e):await s.post(`/api/schedules`,e),r(),n()}catch(e){_(e instanceof Error?e.message:String(e))}finally{m(!1)}},disabled:p,className:`w-full min-h-11 cursor-pointer`,children:p?`Saving…`:t?`Save changes`:`Create schedule`})]}),w=t?`Edit: ${t.name}`:`New schedule`;return i?(0,I.jsxs)(f,{open:e,onClose:n,className:`max-h-[85vh] flex flex-col`,children:[(0,I.jsx)(`p`,{className:`text-sm font-semibold text-center pb-2`,children:w}),(0,I.jsx)(b,{className:`flex-1 min-h-0 px-3 pb-3`,children:C})]}):(0,I.jsx)(k,{open:e,onOpenChange:e=>!e&&n(),children:(0,I.jsxs)(te,{className:`max-w-md max-h-[85vh] overflow-y-auto`,children:[(0,I.jsx)(ee,{children:(0,I.jsx)(A,{className:`text-sm`,children:w})}),C]})})}function Q({label:e,children:t}){return(0,I.jsxs)(`div`,{className:`space-y-1`,children:[(0,I.jsx)(`p`,{className:`text-xs font-medium text-muted-foreground`,children:e}),t]})}function $(e){return{name:e?.name??``,cron_expr:e?.cron_expr??`0 7 * * *`,project_path:e?.project_path??``,prompt:e?.prompt??``,permission_mode:e?.permission_mode??`bypassPermissions`,max_turns:e?.max_turns==null?``:String(e.max_turns),timeout_ms:String(e?.timeout_ms??18e5),enabled:e?!!e.enabled:!0}}function de(){let{schedules:e,loading:t,refetch:n}=P(),[i,a]=(0,M.useState)(!1),[o,s]=(0,M.useState)(null),c=()=>{s(null),a(!0)},l=e=>{s(e),a(!0)};return(0,I.jsxs)(`div`,{className:`space-y-3`,children:[(0,I.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,I.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`Periodically wake Claude to work on a project unattended.`}),(0,I.jsxs)(d,{size:`sm`,onClick:c,className:`min-h-11 md:min-h-8 text-xs gap-1 cursor-pointer shrink-0`,children:[(0,I.jsx)(C,{className:`size-3.5`}),` Add`]})]}),t&&e.length===0?(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground py-4 text-center`,children:`Loading…`}):e.length===0?(0,I.jsxs)(`div`,{className:`flex flex-col items-center gap-2 py-8 text-center`,children:[(0,I.jsx)(r,{className:`size-8 text-muted-foreground/50`}),(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`No schedules yet. Add one to run Claude periodically.`}),(0,I.jsxs)(d,{size:`sm`,onClick:c,className:`min-h-11 text-xs gap-1 cursor-pointer`,children:[(0,I.jsx)(C,{className:`size-3.5`}),` Add schedule`]})]}):(0,I.jsx)(`div`,{className:`space-y-2`,children:e.map(e=>(0,I.jsx)(ae,{schedule:e,onEdit:()=>l(e),onChanged:n},e.id))}),(0,I.jsx)(ue,{open:i,schedule:o,onClose:()=>a(!1),onSaved:n})]})}export{de as SchedulesSettingsSection};
@@ -1 +1 @@
1
- import{t as e}from"./createLucideIcon-D8pyde1A.js";var t=e(`send`,[[`path`,{d:`M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z`,key:`1ffxy3`}],[`path`,{d:`m21.854 2.147-10.94 10.939`,key:`12cjpa`}]]);export{t};
1
+ import{t as e}from"./createLucideIcon-D6fVXe3s.js";var t=e(`send`,[[`path`,{d:`M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z`,key:`1ffxy3`}],[`path`,{d:`m21.854 2.147-10.94 10.939`,key:`12cjpa`}]]);export{t};
@@ -1 +1 @@
1
- import{t as e}from"./panel-store-BmdcSBNb.js";var t=`ppm:send-to-chat`,n=`ppm:send-to-chat:ack`;function r(e){return typeof e.metadata?.lastActiveAt==`number`?e.metadata.lastActiveAt:-1}function i(t){let{panels:n,focusedPanelId:i}=e.getState(),a=Object.values(n).flatMap(e=>e.tabs.filter(e=>e.type===`chat`).map(t=>({tab:t,selected:e.activeTabId===t.id,focusedPanel:e.id===i})));if(a.length===0)return null;let o=t?a.filter(e=>e.tab.projectId===t||e.tab.metadata?.projectName===t):[],s=o.length>0?o:a,c=e=>[e.selected?e.focusedPanel?2:1:0,r(e.tab)];return s.reduce((e,t)=>{let[n,r]=[c(e),c(t)];for(let i=0;i<n.length;i++)if(n[i]!==r[i])return n[i]>r[i]?e:t;return e}).tab.id}function a(r){let{text:a,label:o,projectName:s}=r;if(!a.trim())return;let c=i(s),l=e.getState();if(c){l.setActiveTab(c);let e=!1,r=()=>{e=!0};if(window.addEventListener(n,r),window.dispatchEvent(new CustomEvent(t,{detail:{text:a,label:o,projectName:s,targetTabId:c}})),window.removeEventListener(n,r),e)return;let i=Object.values(l.panels).flatMap(e=>e.tabs).find(e=>e.id===c);l.updateTab(c,{metadata:{...i?.metadata,pendingMessage:a}});return}l.openTab({type:`chat`,title:`Chat`,projectId:null,metadata:{...s?{projectName:s}:{},pendingMessage:a},closable:!0})}export{t as n,a as r,n as t};
1
+ import{t as e}from"./panel-store-D42k25jy.js";var t=`ppm:send-to-chat`,n=`ppm:send-to-chat:ack`;function r(e){return typeof e.metadata?.lastActiveAt==`number`?e.metadata.lastActiveAt:-1}function i(t){let{panels:n,focusedPanelId:i}=e.getState(),a=Object.values(n).flatMap(e=>e.tabs.filter(e=>e.type===`chat`).map(t=>({tab:t,selected:e.activeTabId===t.id,focusedPanel:e.id===i})));if(a.length===0)return null;let o=t?a.filter(e=>e.tab.projectId===t||e.tab.metadata?.projectName===t):[],s=o.length>0?o:a,c=e=>[e.selected?e.focusedPanel?2:1:0,r(e.tab)];return s.reduce((e,t)=>{let[n,r]=[c(e),c(t)];for(let i=0;i<n.length;i++)if(n[i]!==r[i])return n[i]>r[i]?e:t;return e}).tab.id}function a(r){let{text:a,label:o,projectName:s}=r;if(!a.trim())return;let c=i(s),l=e.getState();if(c){l.setActiveTab(c);let e=!1,r=()=>{e=!0};if(window.addEventListener(n,r),window.dispatchEvent(new CustomEvent(t,{detail:{text:a,label:o,projectName:s,targetTabId:c}})),window.removeEventListener(n,r),e)return;let i=Object.values(l.panels).flatMap(e=>e.tabs).find(e=>e.id===c);l.updateTab(c,{metadata:{...i?.metadata,pendingMessage:a}});return}l.openTab({type:`chat`,title:`Chat`,projectId:null,metadata:{...s?{projectName:s}:{},pendingMessage:a},closable:!0})}export{t as n,a as r,n as t};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{S as t,x as n}from"./vendor-markdown-Ls5AcU91.js";import{p as r}from"./vendor-ui-CaeeFO0B.js";import{n as i}from"./utils-IrnQujwR.js";e(t(),1);var a=n();function o({className:e,orientation:t=`horizontal`,decorative:n=!0,...o}){return(0,a.jsx)(r,{"data-slot":`separator`,decorative:n,orientation:t,className:i(`shrink-0 bg-border data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-px`,e),...o})}export{o as t};
1
+ import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{C as t,S as n}from"./vendor-markdown-CuWCHIVb.js";import{p as r}from"./vendor-ui-BBdkypKW.js";import{n as i}from"./utils-IrnQujwR.js";e(t(),1);var a=n();function o({className:e,orientation:t=`horizontal`,decorative:n=!0,...o}){return(0,a.jsx)(r,{"data-slot":`separator`,decorative:n,orientation:t,className:i(`shrink-0 bg-border data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-px`,e),...o})}export{o as t};