forge-openclaw-plugin 0.2.102 → 0.2.104

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 (175) hide show
  1. package/dist/assets/activity-page-Dv6X5ZCV.js +1 -0
  2. package/dist/assets/{ai-surface-workspace-xtB5RFQu.js → ai-surface-workspace-CutiG6uS.js} +1 -1
  3. package/dist/assets/{atlas-panel-B3dPHCmZ.js → atlas-panel-jgMRyaHn.js} +1 -1
  4. package/dist/assets/{board-DqHzdCPQ.js → board-dIX6etHh.js} +1 -1
  5. package/dist/assets/calendar-page-q7Nm5E2U.js +1 -0
  6. package/dist/assets/calendar-rules-DPFsfiRl.js +1 -0
  7. package/dist/assets/{calendar-week-toolbar-BZ_-X3Wb.js → calendar-week-toolbar-nVhgB-0s.js} +1 -1
  8. package/dist/assets/{charts-FcU0F3XV.js → charts-DFnEuIMB.js} +1 -1
  9. package/dist/assets/companion-sync-lab-page-CJ8UTij8.js +1 -0
  10. package/dist/assets/{daily-metrics-dashboard-BMyL0Qr4.js → daily-metrics-dashboard-CiJkkkd1.js} +1 -1
  11. package/dist/assets/entity-note-count-link-RzBB6ujx.js +1 -0
  12. package/dist/assets/{entity-notes-surface-CBylYDwy.js → entity-notes-surface-Djz50HvD.js} +1 -1
  13. package/dist/assets/execution-board-CtPhI-58.js +1 -0
  14. package/dist/assets/{faceted-token-search-D7xPWfOl.js → faceted-token-search-DEC6ANa9.js} +1 -1
  15. package/dist/assets/{flagship-signal-deck-BEFKOhvx.js → flagship-signal-deck-CtHC3mql.js} +1 -1
  16. package/dist/assets/floating-action-menu-CKQRhff9.js +1 -0
  17. package/dist/assets/{forms-CmLAyGqz.js → forms-hB0SqEh-.js} +1 -1
  18. package/dist/assets/goal-detail-page-CF5fNQeR.js +1 -0
  19. package/dist/assets/goals-page-fsY8NzGB.js +1 -0
  20. package/dist/assets/{graph-BTa79qum.js → graph-DDUZNRsO.js} +1 -1
  21. package/dist/assets/habits-page-COoGz4kj.js +1 -0
  22. package/dist/assets/index-BAXYM89v.css +1 -0
  23. package/dist/assets/index-EqQsXoat.js +19 -0
  24. package/dist/assets/{insight-flow-dialog-BtIQXXsS.js → insight-flow-dialog-DtX_5W7g.js} +1 -1
  25. package/dist/assets/insights-page-cBd74ObU.js +8 -0
  26. package/dist/assets/kanban-page-CYav9THw.js +1 -0
  27. package/dist/assets/knowledge-graph-page-D2A-W1jE.js +1 -0
  28. package/dist/assets/{life-force-page-BGDkKfbJ.js → life-force-page-CACGlNhq.js} +1 -1
  29. package/dist/assets/life-force-workspace-BJ4N1I78.js +1 -0
  30. package/dist/assets/{maps-CF1RagUX.js → maps-C-yOWiDN.js} +1 -1
  31. package/dist/assets/{metric-tile-4iMd_WnJ.js → metric-tile-CMadwnGz.js} +1 -1
  32. package/dist/assets/{motion-CfdU2F35.js → motion-Lt5B1XuE.js} +1 -1
  33. package/dist/assets/movement-page-D5VqFd2q.js +1 -0
  34. package/dist/assets/{note-markdown-CsGQhQXF.js → note-markdown-BzK2Qlgr.js} +1 -1
  35. package/dist/assets/{note-tags-input-DdZi93tj.js → note-tags-input-CZzqJMLc.js} +1 -1
  36. package/dist/assets/notes-page-D3Hsh90C.js +1 -0
  37. package/dist/assets/{open-in-graph-button-C0TGev7c.js → open-in-graph-button-BFPKfyK3.js} +1 -1
  38. package/dist/assets/{orbit-map-DVXkfQdd.js → orbit-map-CnyfSmOG.js} +1 -1
  39. package/dist/assets/{overview-page-BwMlFQKX.js → overview-page-CXdWrOV1.js} +1 -1
  40. package/dist/assets/{page-hero-oFHaAjtL.js → page-hero-ffKzgyW3.js} +1 -1
  41. package/dist/assets/pill-cluster-C2D0h3lx.js +1 -0
  42. package/dist/assets/{preference-entity-handoff-button-DOKV9bZc.js → preference-entity-handoff-button-Dj3V6VxL.js} +1 -1
  43. package/dist/assets/preferences-page-Jo8Gw386.js +1 -0
  44. package/dist/assets/project-collections-qSqp90HN.js +1 -0
  45. package/dist/assets/{project-detail-page-DogvVNEn.js → project-detail-page-BifhiLQX.js} +1 -1
  46. package/dist/assets/project-management-hierarchy-page-DZ_9klIc.js +1 -0
  47. package/dist/assets/project-management-section-nav-BImLCVvf.js +1 -0
  48. package/dist/assets/projects-page-ptcx6H38.js +1 -0
  49. package/dist/assets/{psyche-behaviors-page-BeVlXvbj.js → psyche-behaviors-page-BDwXyDta.js} +1 -1
  50. package/dist/assets/{psyche-flashcards-page-CqAWCO4E.js → psyche-flashcards-page-DL1BP1jX.js} +1 -1
  51. package/dist/assets/{psyche-goal-map-page-IyNnbk_W.js → psyche-goal-map-page-ovcpisx1.js} +1 -1
  52. package/dist/assets/{psyche-graph-IkUQRaDK.js → psyche-graph-EP5GL612.js} +1 -1
  53. package/dist/assets/{psyche-metrics-page-uai0a7Lx.js → psyche-metrics-page-Bcu813Rg.js} +1 -1
  54. package/dist/assets/{psyche-mode-guide-page-C7p-ABiF.js → psyche-mode-guide-page-C0g27Xpt.js} +1 -1
  55. package/dist/assets/{psyche-modes-page-CLQ5V3w0.js → psyche-modes-page-BjKjX5MR.js} +1 -1
  56. package/dist/assets/{psyche-page-NQBHkkpU.js → psyche-page-F4tF2W70.js} +1 -1
  57. package/dist/assets/{psyche-patterns-page-BkRiNpI_.js → psyche-patterns-page-B-14hukK.js} +1 -1
  58. package/dist/assets/{psyche-questionnaire-builder-page-Du-7HwPC.js → psyche-questionnaire-builder-page-BdXmoHvK.js} +1 -1
  59. package/dist/assets/{psyche-questionnaire-detail-page-C5-yf8MF.js → psyche-questionnaire-detail-page-Cu5uwlJu.js} +1 -1
  60. package/dist/assets/{psyche-questionnaire-run-detail-page-CoSH5O6R.js → psyche-questionnaire-run-detail-page-C3R4PClg.js} +1 -1
  61. package/dist/assets/{psyche-questionnaire-run-page-ChI7c1wy.js → psyche-questionnaire-run-page-Div3iDdt.js} +1 -1
  62. package/dist/assets/{psyche-questionnaires-page-xUcJJzbI.js → psyche-questionnaires-page-DpqAPQCp.js} +1 -1
  63. package/dist/assets/{psyche-report-detail-page-BPrZCFZS.js → psyche-report-detail-page-BvWVDKP3.js} +1 -1
  64. package/dist/assets/{psyche-reports-page-D2EXJmm6.js → psyche-reports-page-BrbWUlAq.js} +1 -1
  65. package/dist/assets/{psyche-schemas-RcZYaokx.js → psyche-schemas-Dxj554nU.js} +1 -1
  66. package/dist/assets/{psyche-schemas-beliefs-page-h0ooZ1lp.js → psyche-schemas-beliefs-page-DYKvAtSD.js} +1 -1
  67. package/dist/assets/{psyche-screen-time-page-_3-4LikV.js → psyche-screen-time-page-CAOKCyQw.js} +1 -1
  68. package/dist/assets/{psyche-self-observation-page-BdbCsgR5.js → psyche-self-observation-page-F0MVA0UH.js} +1 -1
  69. package/dist/assets/{psyche-values-page-DuUVki5e.js → psyche-values-page-DyvX-d0o.js} +1 -1
  70. package/dist/assets/{report-chain-fields-BBMz0sGI.js → report-chain-fields-CeC1cJFS.js} +1 -1
  71. package/dist/assets/rewards-page-C2loyODo.js +1 -0
  72. package/dist/assets/scheduling-rules-editor-D40AC2jR.js +1 -0
  73. package/dist/assets/{schema-badge-D93RcG36.js → schema-badge-FY7818qB.js} +1 -1
  74. package/dist/assets/{select-menu-Cdq7foRu.js → select-menu-DJsCG6rM.js} +1 -1
  75. package/dist/assets/settings-agents-page-BFkJ5AAD.js +6 -0
  76. package/dist/assets/settings-bin-page-D3-Ab-iA.js +1 -0
  77. package/dist/assets/settings-calendar-page-ly_mSTAD.js +5 -0
  78. package/dist/assets/settings-data-page-D7QOqNf-.js +1 -0
  79. package/dist/assets/settings-logs-page-Ca87HEUx.js +1 -0
  80. package/dist/assets/settings-mobile-page-D0jejZot.js +1 -0
  81. package/dist/assets/settings-models-page-DPDsZjSc.js +1 -0
  82. package/dist/assets/settings-page-1cArlSPM.js +1 -0
  83. package/dist/assets/settings-rewards-page-Db4BV1DC.js +1 -0
  84. package/dist/assets/{settings-section-nav-Dc4IeVBt.js → settings-section-nav-DP9o4peU.js} +1 -1
  85. package/dist/assets/settings-users-page-BHFyDSsd.js +1 -0
  86. package/dist/assets/settings-wiki-page-BNaiupBm.js +1 -0
  87. package/dist/assets/sleep-page-BmOPF0yD.js +1 -0
  88. package/dist/assets/sports-page-BldIiclr.js +1 -0
  89. package/dist/assets/{state-VYvD1QVP.js → state-vCcAT5Hq.js} +1 -1
  90. package/dist/assets/strategies-page-CaTN99qj.js +1 -0
  91. package/dist/assets/strategy-detail-page-DsgFTd-U.js +1 -0
  92. package/dist/assets/{strategy-dialog-DMyRKrWf.js → strategy-dialog-7X7peRzu.js} +1 -1
  93. package/dist/assets/{surface-Bfz_sLX6.js → surface-CJI17F3n.js} +1 -1
  94. package/dist/assets/{table-C0VTeqw0.js → table-BNqMG3_S.js} +1 -1
  95. package/dist/assets/task-detail-page-M1sIIPA8.js +1 -0
  96. package/dist/assets/timebox-planning-dialog-ByojN0AN.js +1 -0
  97. package/dist/assets/today-page-BjDijtn8.js +1 -0
  98. package/dist/assets/training-load-page-BPRmaWmF.js +1 -0
  99. package/dist/assets/{ui-CsEkP2V8.js → ui-C1iwpj2-.js} +1 -1
  100. package/dist/assets/{use-psyche-focus-target-qxT5Oy_z.js → use-psyche-focus-target-Ct-acS9G.js} +1 -1
  101. package/dist/assets/{vendor-kIz9EZnX.js → vendor-Dnkkx2co.js} +3 -3
  102. package/dist/assets/{vitals-page-Dz1Jt5H8.js → vitals-page-CE9zdGLF.js} +1 -1
  103. package/dist/assets/weekly-review-page-CzhTv90n.js +1 -0
  104. package/dist/assets/weight-loss-page-Bp_cIk78.js +5 -0
  105. package/dist/assets/wiki-article-markdown-Dok2uy2p.js +4 -0
  106. package/dist/assets/wiki-editor-page-BuW32Y3f.js +26 -0
  107. package/dist/assets/wiki-ingest-history-page-DZKSBNHV.js +1 -0
  108. package/dist/assets/wiki-ingest-modal-DyqBEZcC.js +1 -0
  109. package/dist/assets/wiki-page-DqxlbLKG.js +1 -0
  110. package/dist/assets/workbench-flow-page-C4nc9jUg.js +5 -0
  111. package/dist/assets/workbench-page-BnyR7SL0.js +1 -0
  112. package/dist/assets/{workout-detail-page-DD9IGN6l.js → workout-detail-page-DT-c5cHL.js} +2 -2
  113. package/dist/index.html +9 -9
  114. package/dist/server/server/src/app.js +22 -3
  115. package/dist/server/server/src/health-weight-loss.js +114 -39
  116. package/dist/server/server/src/repositories/model-settings.js +9 -3
  117. package/dist/server/server/src/watch-mobile.js +28 -0
  118. package/dist/server/src/components/workbench-boxes/shared/generic-node-view.js +13 -5
  119. package/dist/server/src/lib/api.js +10 -1
  120. package/openclaw.plugin.json +1 -1
  121. package/package.json +1 -1
  122. package/dist/assets/activity-page-CgF7K2ww.js +0 -1
  123. package/dist/assets/calendar-page-C1Wfd2Fy.js +0 -1
  124. package/dist/assets/calendar-rules-CaZXtlxt.js +0 -1
  125. package/dist/assets/companion-sync-lab-page-NgeK-O-P.js +0 -1
  126. package/dist/assets/entity-note-count-link-BrS1-O0o.js +0 -1
  127. package/dist/assets/execution-board-CpO2ch6v.js +0 -1
  128. package/dist/assets/floating-action-menu-zzC2r0Ob.js +0 -1
  129. package/dist/assets/goal-detail-page-JK_Nva8e.js +0 -1
  130. package/dist/assets/goals-page-yeoJ06Vw.js +0 -1
  131. package/dist/assets/habits-page-Dx5EhkJi.js +0 -1
  132. package/dist/assets/index-BHIKoiZ6.js +0 -19
  133. package/dist/assets/index-H8R-ABM3.css +0 -1
  134. package/dist/assets/insights-page-CujrosD_.js +0 -8
  135. package/dist/assets/kanban-page-Q9NuIz5w.js +0 -1
  136. package/dist/assets/knowledge-graph-page-DaJmlvvM.js +0 -1
  137. package/dist/assets/life-force-workspace-CLVexVnb.js +0 -1
  138. package/dist/assets/movement-page-ClaoTNuX.js +0 -1
  139. package/dist/assets/notes-page-DYI8s3NN.js +0 -1
  140. package/dist/assets/pill-cluster-7UZd_lHp.js +0 -1
  141. package/dist/assets/preferences-page-BrKEkmfD.js +0 -1
  142. package/dist/assets/project-collections-CZagCmeH.js +0 -1
  143. package/dist/assets/project-management-hierarchy-page-Dr7hW9PW.js +0 -1
  144. package/dist/assets/project-management-section-nav-BLdAgTge.js +0 -1
  145. package/dist/assets/projects-page-UKrby_5-.js +0 -1
  146. package/dist/assets/rewards-page-PZFPa6rR.js +0 -1
  147. package/dist/assets/scheduling-rules-editor-B9KNKsQz.js +0 -1
  148. package/dist/assets/settings-agents-page-DPx2F6wf.js +0 -6
  149. package/dist/assets/settings-bin-page-COwP3gjo.js +0 -1
  150. package/dist/assets/settings-calendar-page-C-ghE0YT.js +0 -5
  151. package/dist/assets/settings-data-page-CBubzKBw.js +0 -1
  152. package/dist/assets/settings-logs-page-uOuXMeBm.js +0 -1
  153. package/dist/assets/settings-mobile-page-C5rfj8_r.js +0 -1
  154. package/dist/assets/settings-models-page-DijmUWdU.js +0 -1
  155. package/dist/assets/settings-page-B4u5TR5g.js +0 -1
  156. package/dist/assets/settings-rewards-page-COiTwkMH.js +0 -1
  157. package/dist/assets/settings-users-page-DEGa5DNn.js +0 -1
  158. package/dist/assets/settings-wiki-page-Cvsiz5_e.js +0 -1
  159. package/dist/assets/sleep-page-BnSOwkEU.js +0 -1
  160. package/dist/assets/sports-page-l1RqXzA_.js +0 -1
  161. package/dist/assets/strategies-page-DEnPlpAs.js +0 -1
  162. package/dist/assets/strategy-detail-page-Ls8bxKeH.js +0 -1
  163. package/dist/assets/task-detail-page-CgrYgQLD.js +0 -1
  164. package/dist/assets/timebox-planning-dialog-Ww0NGLLo.js +0 -1
  165. package/dist/assets/today-page-CIuFHMi1.js +0 -1
  166. package/dist/assets/training-load-page-BIwc648i.js +0 -1
  167. package/dist/assets/weekly-review-page-BFpBe1kI.js +0 -1
  168. package/dist/assets/weight-loss-page-BgMoBpBt.js +0 -5
  169. package/dist/assets/wiki-article-markdown-gsPTXTg1.js +0 -4
  170. package/dist/assets/wiki-editor-page-BpAZHooY.js +0 -26
  171. package/dist/assets/wiki-ingest-history-page-C-ig8O22.js +0 -1
  172. package/dist/assets/wiki-ingest-modal-BK4eQgqs.js +0 -1
  173. package/dist/assets/wiki-page-CMTZ60Zt.js +0 -1
  174. package/dist/assets/workbench-flow-page-BIpWUcLJ.js +0 -5
  175. package/dist/assets/workbench-page-CtCjYSRe.js +0 -1
@@ -1 +1 @@
1
- import{r as i,j as e,cx as g,bl as k}from"./vendor-kIz9EZnX.js";import{Z as n}from"./index-BHIKoiZ6.js";function y({label:m,value:l,options:u,onChange:b,className:h,triggerClassName:p,menuClassName:w}){const[a,c]=i.useState(!1),x=i.useRef(null),v=i.useRef(null),f=i.useId(),t=i.useMemo(()=>u.find(r=>r.value===l)??u[0],[u,l]);return i.useEffect(()=>{if(!a)return;const r=d=>{var o;(o=x.current)!=null&&o.contains(d.target)||c(!1)},s=d=>{var o;d.key==="Escape"&&(c(!1),(o=v.current)==null||o.focus())};return document.addEventListener("pointerdown",r),document.addEventListener("keydown",s),()=>{document.removeEventListener("pointerdown",r),document.removeEventListener("keydown",s)}},[a]),e.jsxs("div",{className:n("relative min-w-0 max-w-full",h),ref:x,children:[e.jsx("div",{className:"mb-1.5 text-[11px] font-medium uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:m}),e.jsxs("button",{ref:v,type:"button",className:n("flex min-h-11 w-full min-w-0 items-center justify-between gap-3 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-2.5 text-left shadow-[var(--ui-shadow-soft)] transition hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-hover)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[color-mix(in_srgb,var(--primary)_45%,transparent)] sm:min-w-[15rem]",p),"aria-haspopup":"listbox","aria-expanded":a,"aria-controls":f,onClick:()=>c(r=>!r),children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-medium text-[var(--ui-ink-strong)]",children:(t==null?void 0:t.label)??l}),t!=null&&t.description?e.jsx("div",{className:"truncate text-xs text-[var(--ui-ink-faint)]",children:t.description}):null]}),e.jsx(g,{className:n("size-4 shrink-0 text-[var(--ui-ink-faint)] transition",a&&"rotate-180 text-[var(--ui-ink-medium)]")})]}),a?e.jsx("div",{id:f,role:"listbox","aria-label":m,className:n("absolute left-0 top-[calc(100%+0.6rem)] z-30 w-full overflow-hidden rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-modal)] p-2 shadow-[var(--ui-shadow-floating)] backdrop-blur-xl",w),children:e.jsx("div",{className:"grid gap-1",children:u.map(r=>{const s=r.value===l;return e.jsxs("button",{type:"button",role:"option","aria-selected":s,className:n("flex w-full items-start justify-between gap-3 rounded-[16px] px-3 py-2.5 text-left transition",s?"bg-[var(--ui-surface-active)] text-[var(--ui-ink-strong)]":"text-[var(--ui-ink-medium)] hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]"),onClick:()=>{b(r.value),c(!1)},children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-medium",children:r.label}),r.description?e.jsx("div",{className:"mt-0.5 text-xs text-[var(--ui-ink-faint)]",children:r.description}):null]}),e.jsx(k,{className:n("mt-0.5 size-4 shrink-0 transition",s?"text-[var(--ui-ink-strong)]":"opacity-0")})]},r.value)})})}):null]})}export{y as S};
1
+ import{r as i,j as e,cx as g,bl as k}from"./vendor-Dnkkx2co.js";import{Z as n}from"./index-EqQsXoat.js";function y({label:m,value:l,options:u,onChange:b,className:h,triggerClassName:p,menuClassName:w}){const[a,c]=i.useState(!1),x=i.useRef(null),v=i.useRef(null),f=i.useId(),t=i.useMemo(()=>u.find(r=>r.value===l)??u[0],[u,l]);return i.useEffect(()=>{if(!a)return;const r=d=>{var o;(o=x.current)!=null&&o.contains(d.target)||c(!1)},s=d=>{var o;d.key==="Escape"&&(c(!1),(o=v.current)==null||o.focus())};return document.addEventListener("pointerdown",r),document.addEventListener("keydown",s),()=>{document.removeEventListener("pointerdown",r),document.removeEventListener("keydown",s)}},[a]),e.jsxs("div",{className:n("relative min-w-0 max-w-full",h),ref:x,children:[e.jsx("div",{className:"mb-1.5 text-[11px] font-medium uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:m}),e.jsxs("button",{ref:v,type:"button",className:n("flex min-h-11 w-full min-w-0 items-center justify-between gap-3 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-2.5 text-left shadow-[var(--ui-shadow-soft)] transition hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-hover)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[color-mix(in_srgb,var(--primary)_45%,transparent)] sm:min-w-[15rem]",p),"aria-haspopup":"listbox","aria-expanded":a,"aria-controls":f,onClick:()=>c(r=>!r),children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-medium text-[var(--ui-ink-strong)]",children:(t==null?void 0:t.label)??l}),t!=null&&t.description?e.jsx("div",{className:"truncate text-xs text-[var(--ui-ink-faint)]",children:t.description}):null]}),e.jsx(g,{className:n("size-4 shrink-0 text-[var(--ui-ink-faint)] transition",a&&"rotate-180 text-[var(--ui-ink-medium)]")})]}),a?e.jsx("div",{id:f,role:"listbox","aria-label":m,className:n("absolute left-0 top-[calc(100%+0.6rem)] z-30 w-full overflow-hidden rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-modal)] p-2 shadow-[var(--ui-shadow-floating)] backdrop-blur-xl",w),children:e.jsx("div",{className:"grid gap-1",children:u.map(r=>{const s=r.value===l;return e.jsxs("button",{type:"button",role:"option","aria-selected":s,className:n("flex w-full items-start justify-between gap-3 rounded-[16px] px-3 py-2.5 text-left transition",s?"bg-[var(--ui-surface-active)] text-[var(--ui-ink-strong)]":"text-[var(--ui-ink-medium)] hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]"),onClick:()=>{b(r.value),c(!1)},children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-medium",children:r.label}),r.description?e.jsx("div",{className:"mt-0.5 text-xs text-[var(--ui-ink-faint)]",children:r.description}):null]}),e.jsx(k,{className:n("mt-0.5 size-4 shrink-0 transition",s?"text-[var(--ui-ink-strong)]":"opacity-0")})]},r.value)})})}):null]})}export{y as S};
@@ -0,0 +1,6 @@
1
+ import{r as v,j as e,de as Me,aK as qe,bl as Ce,c8 as Oe,b8 as De,b4 as Ee,df as Be,cw as He,cx as Ue}from"./vendor-Dnkkx2co.js";import{j as Ke,i as R,k as _}from"./state-vCcAT5Hq.js";import{Q as Se,dF as $e,j as F,F as g,I as C,T as ze,c as h,B as P,dG as We,dH as Qe,dI as Xe,dJ as Ge,dK as Ye,dL as Je,dM as Ze,dN as Ve,S as es,E as ye,C as N,V as Z,b as ss,du as ts,dv as as,dO as is,dP as rs,dQ as ns,dR as os,dS as ls}from"./index-EqQsXoat.js";import{R as ds,P as cs,O as us,C as ms,T as xs,D as ps,a as gs}from"./ui-C1iwpj2-.js";import{m as hs}from"./motion-Lt5B1XuE.js";import{S as vs}from"./settings-section-nav-DP9o4peU.js";import{P as bs}from"./page-hero-ffKzgyW3.js";import{M as W}from"./metric-tile-CMadwnGz.js";import"./forms-hB0SqEh-.js";import"./board-dIX6etHh.js";import"./graph-DDUZNRsO.js";const G=["read","write","insights","rewards.manage","psyche.read","psyche.write","psyche.note","psyche.insight","psyche.mode"],js=[{value:"read",label:"Read",description:"Inspect goals, projects, tasks, reviews, and metrics."},{value:"write",label:"Write",description:"Create and update work through the versioned API."},{value:"insights",label:"Insights",description:"Store structured findings, rationale, and feedback."},{value:"rewards.manage",label:"Rewards",description:"Tune reward rules and issue explainable bonus XP grants."},{value:"psyche.read",label:"Psyche read",description:"Read sensitive values, patterns, and trigger analyses."},{value:"psyche.write",label:"Psyche write",description:"Create and update sensitive therapeutic records."},{value:"psyche.note",label:"Psyche note",description:"Create and edit Markdown notes linked to reflective records."},{value:"psyche.insight",label:"Psyche insight",description:"Store therapeutic insights on Psyche entities."},{value:"psyche.mode",label:"Psyche mode",description:"Name, refine, and map mode profiles and guided mode results."}],te={mode:"active_only",goalsLimit:5,projectsLimit:8,tasksLimit:10,habitsLimit:6,strategiesLimit:4,peoplePageLimit:4,includePeoplePages:!0},X={userIds:[],projectIds:[],tagIds:[]};function V(a){return a==="review"?{mode:"active_only",goalsLimit:3,projectsLimit:5,tasksLimit:6,habitsLimit:4,strategiesLimit:3,peoplePageLimit:0,includePeoplePages:!1}:a==="operator"?{...te}:a==="autonomous"?{mode:"scoped",goalsLimit:10,projectsLimit:14,tasksLimit:16,habitsLimit:10,strategiesLimit:8,peoplePageLimit:6,includePeoplePages:!0}:{...te}}function ee(a){return Array.from(new Set(a.split(",").map(r=>r.trim()).filter(r=>r.length>0)))}function Ae(a,r,l){return r==="review"?{...a,preset:r,trustLevel:"trusted",autonomyMode:"approval_required",approvalMode:"approval_by_default",scopes:[...l],bootstrapPolicy:V(r),scopePolicy:{...X}}:r==="operator"?{...a,preset:r,trustLevel:"trusted",autonomyMode:"scoped_write",approvalMode:"high_impact_only",scopes:[...G],bootstrapPolicy:V(r),scopePolicy:{...X}}:r==="autonomous"?{...a,preset:r,trustLevel:"autonomous",autonomyMode:"autonomous",approvalMode:"none",scopes:[...G],bootstrapPolicy:V(r),scopePolicy:{...X}}:{...a,preset:r}}function ke(a,r,l){const p={preset:a,label:"Forge Pilot Token",agentLabel:r,agentType:"assistant",description:"Collaborative planning agent.",trustLevel:"trusted",autonomyMode:"scoped_write",approvalMode:"high_impact_only",scopes:[...G],bootstrapPolicy:{...te},scopePolicy:{...X}};return Ae(p,a,l)}function fs({open:a,onOpenChange:r,pending:l=!1,initialPreset:p="operator",defaultAgentLabel:m="OpenClaw",recommendedScopes:b=[...G],onSubmit:k}){const[u,f]=v.useState(()=>ke(p,m,b)),[M,j]=v.useState(null);v.useEffect(()=>{a&&(f(ke(p,m,b)),j(null))},[a,p,m,b]);const A=[{id:"preset",eyebrow:"Agent token",title:"Choose a starting point for this token",description:"Each preset locks in a sensible trust, autonomy, and approval policy. You can tune any setting in the next steps.",render:(i,n)=>e.jsx(F,{columns:3,value:i.preset,onChange:t=>n(Ae(i,t,b)),options:[{value:"review",label:"Review-first",description:"Every action waits for your approval. Safe starting point for a new agent you have not yet trusted."},{value:"operator",label:"Full operator",description:"Trusted collaborator with full scopes. High-impact actions still ask for approval."},{value:"autonomous",label:"Autonomous pilot",description:"No approval gates. Use only for agents you have fully verified in a controlled setup."},{value:"custom",label:"Custom",description:"Start from a blank slate and configure every dimension yourself."}]})},{id:"identity",eyebrow:"Agent identity",title:"Name the agent and this token",description:"The agent name appears in logs, approval requests, and audit trails. The token label is for your reference.",render:(i,n)=>e.jsxs(e.Fragment,{children:[e.jsx(g,{label:"Agent name",labelHelp:"This label identifies the agent in every log entry, approval notification, and XP attribution. Pick something memorable.",children:e.jsx(C,{value:i.agentLabel,placeholder:"OpenClaw",onChange:t=>n({agentLabel:t.target.value})})}),e.jsx(g,{label:"Token label",description:"A short name for this credential — mainly for your reference in the token list.",children:e.jsx(C,{value:i.label,placeholder:"Forge Pilot Token",onChange:t=>n({label:t.target.value})})}),e.jsxs("div",{className:"grid gap-5 md:grid-cols-2",children:[e.jsx(g,{label:"Agent type",labelHelp:"Use 'assistant' for interactive agents. Use 'automation' for scripts or scheduled jobs with no conversational layer.",children:e.jsxs("select",{className:"rounded-[14px] bg-[var(--ui-surface-2)] px-3 py-3 text-[var(--ui-ink-strong)]",value:i.agentType,onChange:t=>n({agentType:t.target.value}),children:[e.jsx("option",{value:"assistant",children:"assistant"}),e.jsx("option",{value:"automation",children:"automation"}),e.jsx("option",{value:"observer",children:"observer"})]})}),e.jsx(g,{label:"Description",description:"Optional note about what this agent does.",children:e.jsx(C,{value:i.description,placeholder:"Collaborative planning agent.",onChange:t=>n({description:t.target.value})})})]})]})},{id:"policy",eyebrow:"Access policy",title:"Set trust level and approval behaviour",description:"These three settings control how much autonomy the agent has and when it needs your sign-off. The preset you chose filled sensible defaults — adjust only if needed.",render:(i,n)=>e.jsxs(e.Fragment,{children:[e.jsx(g,{label:"Trust level",labelHelp:"Standard agents are sandboxed readers. Trusted agents can write with policy guardrails. Autonomous agents bypass all trust checks — use with care.",children:e.jsx(F,{columns:3,value:i.trustLevel,onChange:t=>n({trustLevel:t}),options:[{value:"standard",label:"Standard",description:"Read-only by default, limited write surface."},{value:"trusted",label:"Trusted",description:"Full write surface with policy guardrails active."},{value:"autonomous",label:"Autonomous",description:"All checks bypassed — maximum capability."}]})}),e.jsx(g,{label:"Autonomy mode",labelHelp:"Approval-required means every mutation is held for review. Scoped write lets the agent act within its scopes. Autonomous skips all gates.",children:e.jsx(F,{columns:3,value:i.autonomyMode,onChange:t=>n({autonomyMode:t}),options:[{value:"approval_required",label:"Approval required",description:"Every write action queues for your review."},{value:"scoped_write",label:"Scoped write",description:"Acts freely within its assigned scopes."},{value:"autonomous",label:"Autonomous",description:"No gates — full freedom to write."}]})}),e.jsx(g,{label:"Approval policy",labelHelp:"Controls which actions trigger the approval queue. High-impact-only is the balanced default: routine writes go through, large mutations get reviewed.",children:e.jsx(F,{columns:3,value:i.approvalMode,onChange:t=>n({approvalMode:t}),options:[{value:"approval_by_default",label:"Approve by default",description:"Everything needs a sign-off unless explicitly exempt."},{value:"high_impact_only",label:"High impact only",description:"Routine writes pass through; high-stakes actions are held."},{value:"none",label:"None",description:"No approval gates — actions execute immediately."}]})})]})},{id:"scopes",eyebrow:"Scopes",title:"Select what this agent can access",description:"Scope selection follows the principle of least privilege — only grant what the agent actually needs. The full operator bundle covers every capability.",render:(i,n)=>e.jsxs(g,{label:"Capabilities",labelHelp:"Read lets the agent inspect the system. Write lets it create and update work. Rewards and Psyche scopes unlock more sensitive subsystems.",children:[e.jsx("div",{className:"grid gap-3 md:grid-cols-3",children:js.map(t=>{const y=i.scopes.includes(t.value);return e.jsxs("button",{type:"button",className:`rounded-[18px] border px-4 py-4 text-left transition ${y?"border-[color-mix(in_srgb,var(--primary)_28%,transparent)] bg-[var(--ui-accent-soft)] text-[var(--ui-ink-strong)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-muted)] hover:bg-[var(--ui-surface-2)]"}`,onClick:()=>{if(y){if(i.scopes.length===1)return;n({scopes:i.scopes.filter(S=>S!==t.value)})}else n({scopes:[...i.scopes,t.value]})},children:[e.jsx("div",{className:"font-medium",children:t.label}),e.jsx("div",{className:"mt-1 text-xs leading-5 text-[var(--ui-ink-muted)]",children:t.description})]},t.value)})}),e.jsxs("div",{className:"mt-2 text-xs text-[var(--ui-ink-muted)]",children:[i.scopes.length," scope",i.scopes.length!==1?"s":""," ","selected"]})]})},{id:"default-scope",eyebrow:"Default read scope",title:"Decide which owners and slices this agent sees by default",description:"Leave these blank for broad reads. When set, Forge automatically narrows overview, context, and bootstrap reads for this token unless the request narrows further.",render:(i,n)=>e.jsxs(e.Fragment,{children:[e.jsx(g,{label:"Default user IDs",description:"Comma-separated owner ids such as user_operator or user_forge_bot.",labelHelp:"If you set user ids here, this token only sees that owner slice by default. Explicit userIds in a request can narrow further, but they will not silently widen beyond this list.",children:e.jsx(C,{value:i.scopePolicy.userIds.join(", "),placeholder:"user_operator, user_forge_bot",onChange:t=>n({scopePolicy:{...i.scopePolicy,userIds:ee(t.target.value)}})})}),e.jsx(g,{label:"Project IDs",description:"Optional project-level boundary for overview, context, and bootstrap reads.",children:e.jsx(C,{value:i.scopePolicy.projectIds.join(", "),placeholder:"project_123, project_456",onChange:t=>n({scopePolicy:{...i.scopePolicy,projectIds:ee(t.target.value)}})})}),e.jsx(g,{label:"Tag IDs",description:"Optional tag-level boundary for overview, context, and bootstrap reads.",children:e.jsx(C,{value:i.scopePolicy.tagIds.join(", "),placeholder:"tag_focus, tag_client",onChange:t=>n({scopePolicy:{...i.scopePolicy,tagIds:ee(t.target.value)}})})}),e.jsxs("div",{className:"rounded-[16px] bg-[var(--ui-surface-2)] px-4 py-3 text-sm leading-6 text-[var(--ui-ink-medium)]",children:["Default scope summary:"," ",i.scopePolicy.userIds.length>0?`${i.scopePolicy.userIds.length} user slice${i.scopePolicy.userIds.length===1?"":"s"}`:"all visible users",i.scopePolicy.projectIds.length>0?` · ${i.scopePolicy.projectIds.length} project ${i.scopePolicy.projectIds.length===1?"boundary":"boundaries"}`:"",i.scopePolicy.tagIds.length>0?` · ${i.scopePolicy.tagIds.length} tag ${i.scopePolicy.tagIds.length===1?"boundary":"boundaries"}`:""]})]})},{id:"bootstrap",eyebrow:"Bootstrap",title:"Decide how much Forge context is injected at session start",description:"This controls the automatic BOOTSTRAP snapshot for agent sessions. Keep it lean unless the agent genuinely needs broad context on every new session.",render:(i,n)=>e.jsxs(e.Fragment,{children:[e.jsx(g,{label:"Bootstrap mode",labelHelp:"Disabled injects nothing. Active-only keeps a compact current-work snapshot. Scoped keeps budgets but not status filters. Full mirrors the legacy broad bootstrap.",children:e.jsx(F,{columns:3,value:i.bootstrapPolicy.mode,onChange:t=>n({bootstrapPolicy:{...i.bootstrapPolicy,mode:t}}),options:[{value:"disabled",label:"Disabled",description:"No automatic Forge snapshot is injected."},{value:"active_only",label:"Active only",description:"Only active projects, focus tasks, due habits, and bounded summaries."},{value:"scoped",label:"Scoped",description:"Bounded lists without forcing only active items."},{value:"full",label:"Full",description:"Legacy broad bootstrap. Highest context cost."}]})}),e.jsx("div",{className:"grid gap-5 md:grid-cols-3",children:[["goalsLimit","Goals"],["projectsLimit","Projects"],["tasksLimit","Tasks"],["habitsLimit","Habits"],["strategiesLimit","Strategies"],["peoplePageLimit","People pages"]].map(([t,y])=>e.jsx(g,{label:y,children:e.jsx(C,{type:"number",min:0,max:t==="peoplePageLimit"?50:100,value:i.bootstrapPolicy[t],onChange:S=>n({bootstrapPolicy:{...i.bootstrapPolicy,[t]:Number(S.target.value||0)}})})},t))}),e.jsxs("label",{className:"flex items-center gap-3 rounded-[16px] bg-[var(--ui-surface-2)] px-4 py-3 text-sm text-[var(--ui-ink-medium)]",children:[e.jsx("input",{type:"checkbox",checked:i.bootstrapPolicy.includePeoplePages,onChange:t=>n({bootstrapPolicy:{...i.bootstrapPolicy,includePeoplePages:t.target.checked}})}),"Include People wiki pages in the bootstrap snapshot"]})]})}];return e.jsx(Se,{open:a,onOpenChange:r,eyebrow:"Agent setup",title:"Issue an agent token",description:"Configure a new agent token step by step. The preset fills sensible defaults — adjust what you need.",value:u,onChange:f,draftPersistenceKey:"settings.agent-token.new",steps:A,submitLabel:"Issue token",pending:l,pendingLabel:"Issuing token…",error:M,onSubmit:async()=>{j(null);const i=$e.safeParse({label:u.label,agentLabel:u.agentLabel,agentType:u.agentType,description:u.description,trustLevel:u.trustLevel,autonomyMode:u.autonomyMode,approvalMode:u.approvalMode,scopes:u.scopes,bootstrapPolicy:u.bootstrapPolicy,scopePolicy:u.scopePolicy});if(!i.success){const n=i.error.issues[0];j((n==null?void 0:n.message)??"Check the agent name and at least one scope before issuing.");return}try{await k(i.data),r(!1)}catch(n){j(n instanceof Error?n.message:"Could not issue the token right now.")}}})}function we(a){return{source:"new",taskId:"",title:"",description:"",owner:a,projectId:"",status:"done",points:40}}function ys({open:a,onOpenChange:r,pending:l=!1,defaultOwner:p="",availableTasks:m=[],availableProjects:b=[],onSubmit:k}){const[u,f]=v.useState(()=>we(p)),[M,j]=v.useState(null);v.useEffect(()=>{a&&(f(we(p)),j(null))},[a,p]);const A=[{id:"source",eyebrow:"Log work",title:"Is this work already tracked?",description:"If a task exists, link the work to it so Forge can update the record with the right status and XP. If not, a new task will be created from what you describe.",render:(i,n)=>e.jsxs(e.Fragment,{children:[e.jsx(F,{columns:2,value:i.source,onChange:t=>n({source:t,taskId:""}),options:[{value:"new",label:"New task",description:"The work is not tracked yet — Forge will create a task and log the time against it."},{value:"existing",label:"Existing task",description:"Pick a task already in the board. The log will update its record and award XP."}]}),i.source==="existing"&&m.length>0?e.jsx(g,{label:"Pick the task",description:"Select the task this work belongs to.",children:e.jsxs("select",{className:"rounded-[14px] bg-[var(--ui-surface-2)] px-3 py-3 text-[var(--ui-ink-strong)]",value:i.taskId,onChange:t=>n({taskId:t.target.value}),children:[e.jsx("option",{value:"",children:"— choose a task —"}),m.map(t=>e.jsxs("option",{value:t.id,children:[t.title," · ",t.status.replaceAll("_"," ")]},t.id))]})}):i.source==="existing"&&m.length===0?e.jsx("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] px-4 py-3 text-sm text-[var(--ui-ink-muted)]",children:'No tasks are loaded yet. Switch to "New task" to create one from scratch.'}):null]})},{id:"details",eyebrow:"Work details",title:"Describe what was done",description:"Give the work a clear title and enough context to understand it later. These become the task record if you are creating a new one.",render:(i,n)=>e.jsxs(e.Fragment,{children:[e.jsx(g,{label:"Title",labelHelp:"Write the title like a short achievement: what was completed, not what was started.",children:e.jsx(C,{value:i.title,placeholder:"Write postmortem draft",onChange:t=>n({title:t.target.value})})}),e.jsx(g,{label:"Owner",description:"Who did this work? Defaults to the operator name.",children:e.jsx(C,{value:i.owner,placeholder:"Your name",onChange:t=>n({owner:t.target.value})})}),e.jsx(g,{label:"Description",description:"What moved forward? What should remain visible in the project history?",children:e.jsx(ze,{className:"min-h-28",value:i.description,placeholder:"Wrote the full incident timeline and drafted the three key learnings for the team retrospective.",onChange:t=>n({description:t.target.value})})})]})},{id:"placement",eyebrow:"Placement",title:"Set the context and XP value",description:"Assign the work to a project and choose its final status. The XP value controls how much this work contributes to the operator's progress curve.",render:(i,n)=>e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-5 md:grid-cols-2",children:[e.jsx(g,{label:"Project",description:"Link this work to an active project if it belongs to one.",children:e.jsxs("select",{className:"rounded-[14px] bg-[var(--ui-surface-2)] px-3 py-3 text-[var(--ui-ink-strong)]",value:i.projectId,onChange:t=>n({projectId:t.target.value}),children:[e.jsx("option",{value:"",children:"No project link"}),b.map(t=>e.jsx("option",{value:t.id,children:t.title},t.id))]})}),e.jsx(g,{label:"Final status",labelHelp:"'Done' is the most common choice. Use 'In progress' if the work was real but the task is still open.",children:e.jsx(F,{columns:2,value:i.status,onChange:t=>n({status:t}),options:[{value:"done",label:"Done",description:"Work is complete."},{value:"in_progress",label:"In progress",description:"Still active but already worth logging."},{value:"focus",label:"Focus",description:"Moved into focus."},{value:"blocked",label:"Blocked",description:"Work hit a wall."}]})})]}),e.jsx(g,{label:"XP value",labelHelp:"Typical task XP ranges from 20 to 100. Use 40 for routine tasks, 80+ for complex deliverables.",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(C,{type:"number",min:5,max:500,className:"w-36",value:i.points,onChange:t=>n({points:Number(t.target.value)})}),e.jsx("div",{className:"flex gap-2",children:[20,40,80,120].map(t=>e.jsxs("button",{type:"button",className:`rounded-full px-3 py-1.5 text-xs transition ${i.points===t?"bg-[var(--ui-surface-3)] text-[var(--ui-ink-strong)]":"bg-[var(--ui-surface-2)] text-[var(--ui-ink-muted)] hover:bg-[var(--ui-surface-2)]"}`,onClick:()=>n({points:t}),children:[t," xp"]},t))})]})})]})}];return e.jsx(Se,{open:a,onOpenChange:r,eyebrow:"Log work",title:"Log retroactive work",description:"Capture work that happened outside the timer so it counts toward progress and XP.",value:u,onChange:f,draftPersistenceKey:"settings.log-work",steps:A,submitLabel:"Log work",pending:l,pendingLabel:"Logging work…",error:M,onSubmit:async()=>{if(j(null),u.source==="new"&&u.title.trim().length===0){j("Add a title so Forge knows what work to create.");return}if(u.source==="existing"&&!u.taskId){j("Pick an existing task or switch to New task.");return}try{await k({taskId:u.source==="existing"&&u.taskId?u.taskId:void 0,title:u.source==="new"&&u.title.trim()?u.title.trim():void 0,description:u.description.trim()||void 0,owner:u.owner.trim()||void 0,projectId:u.projectId||null,status:u.status,points:u.points}),r(!1)}catch(i){j(i instanceof Error?i.message:"Could not log the work right now.")}}})}function Te({text:a}){const[r,l]=v.useState(!1),p=async()=>{try{await navigator.clipboard.writeText(a),l(!0),setTimeout(()=>l(!1),2200)}catch{}};return e.jsxs("button",{type:"button",onClick:()=>void p(),className:"flex items-center gap-1.5 rounded-full bg-[var(--ui-surface-2)] px-3 py-1.5 text-xs font-medium text-[var(--ui-ink-medium)] transition hover:bg-[var(--ui-surface-2)] hover:text-[var(--ui-ink-strong)]",children:[r?e.jsx(Ce,{className:"size-3 text-[var(--success)]"}):e.jsx(Oe,{className:"size-3"}),r?"Copied":"Copy"]})}function se({label:a,children:r,copyText:l}){return e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] p-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.14em] text-[var(--ui-ink-muted)]",children:a}),e.jsx(Te,{text:l??r})]}),e.jsx("pre",{className:"mt-3 overflow-x-auto rounded-[14px] bg-[var(--ui-code-bg)] p-3 text-xs leading-6 text-[var(--ui-ink-medium)]",children:e.jsx("code",{children:r})})]})}function ks({open:a,onOpenChange:r,state:l}){if(!l)return null;const{tokenString:p,agentLabel:m,onboarding:b}=l,k=JSON.stringify({baseUrl:b.forgeBaseUrl,apiToken:p,actorLabel:m,timeoutMs:b.defaultTimeoutMs},null,2),u=[`curl -s ${b.healthUrl} \\`,` -H "Authorization: Bearer ${p}" \\`,' -H "X-Forge-Source: agent" \\',` -H "X-Forge-Actor: ${m}"`].join(`
2
+ `),f=["openclaw gateway restart",'openclaw agent --message "forge_get_operator_overview"'].join(`
3
+ `);return e.jsx(ds,{open:a,onOpenChange:r,children:e.jsxs(cs,{children:[e.jsx(us,{className:"fixed inset-0 z-40 bg-[var(--overlay)] backdrop-blur-xl"}),e.jsxs(ms,{className:"fixed left-1/2 top-1/2 z-50 flex h-[min(52rem,calc(100vh-1rem))] w-[min(52rem,calc(100vw-1.5rem))] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-[34px] border border-[color-mix(in_srgb,var(--primary)_28%,transparent)] bg-[image:var(--ui-surface-modal)] shadow-[var(--ui-shadow-floating)]",children:[e.jsx(xs,{className:"sr-only",children:"Token issued — setup instructions"}),e.jsx(ps,{className:"sr-only",children:"Your new agent token has been issued. Copy it now and follow the setup guide."}),e.jsxs("div",{className:"flex shrink-0 items-start justify-between gap-4 border-b border-[var(--ui-border-subtle)] px-6 py-5",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex size-10 shrink-0 items-center justify-center rounded-full bg-[var(--ui-accent-soft)]",children:e.jsx(Me,{className:"size-5 text-[var(--primary)]"})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Token issued"}),e.jsx("div",{className:"mt-0.5 font-display text-xl text-[var(--ui-ink-strong)]",children:"Save your token now"})]})]}),e.jsx(gs,{asChild:!0,children:e.jsx("button",{type:"button","aria-label":"Close",className:"rounded-full bg-[var(--ui-surface-3)] p-2 text-[var(--ui-ink-muted)] transition hover:bg-[var(--ui-surface-3)] hover:text-[var(--ui-ink-strong)]",children:e.jsx(qe,{className:"size-4"})})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto px-6 py-5",children:e.jsxs(hs.div,{initial:{opacity:0,y:16},animate:{opacity:1,y:0},transition:{duration:.3,ease:"easeOut"},className:"grid gap-5",children:[e.jsxs("div",{className:"rounded-[20px] border border-[color-mix(in_srgb,var(--warning)_28%,transparent)] bg-[var(--ui-warning-soft)] p-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(h,{className:"text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]",children:"One-time reveal"}),e.jsx("span",{className:"text-sm text-[var(--ui-ink-medium)]",children:"This value will not be shown again."})]}),e.jsxs("div",{className:"mt-3 flex items-center justify-between gap-3 rounded-[14px] bg-[var(--ui-code-bg)] px-4 py-3",children:[e.jsx("code",{className:"min-w-0 flex-1 break-all text-xs text-[var(--ui-ink-medium)]",children:p}),e.jsx(Te,{text:p})]}),e.jsx("div",{className:"mt-2 text-xs text-[var(--ui-ink-muted)]",children:"Forge stores only a hash — the raw token is unrecoverable after you close this dialog. If lost, rotate the token from the Agents settings page."})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsx("div",{className:"flex size-5 items-center justify-center rounded-full bg-[var(--ui-surface-3)] text-xs font-semibold text-[var(--ui-ink-strong)]",children:"1"}),e.jsx("span",{className:"text-sm font-medium text-[var(--ui-ink-strong)]",children:"Add the token to your OpenClaw plugin config"})]}),e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] p-4 text-sm leading-6 text-[var(--ui-ink-medium)]",children:["Open your ",e.jsx("code",{className:"rounded-md bg-[var(--ui-surface-2)] px-1.5 py-0.5 text-xs text-[var(--ui-ink-medium)]",children:"openclaw.json"})," file and find the"," ",e.jsx("code",{className:"rounded-md bg-[var(--ui-surface-2)] px-1.5 py-0.5 text-xs text-[var(--ui-ink-medium)]",children:"forge"})," plugin entry under"," ",e.jsx("code",{className:"rounded-md bg-[var(--ui-surface-2)] px-1.5 py-0.5 text-xs text-[var(--ui-ink-medium)]",children:"plugins"}),". Add or replace its"," ",e.jsx("code",{className:"rounded-md bg-[var(--ui-surface-2)] px-1.5 py-0.5 text-xs text-[var(--ui-ink-medium)]",children:"params"})," with the config block below."]}),e.jsx("div",{className:"mt-3",children:e.jsx(se,{label:"Plugin params — paste into openclaw.json → plugins → forge → params",copyText:k,children:k})})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsx("div",{className:"flex size-5 items-center justify-center rounded-full bg-[var(--ui-surface-3)] text-xs font-semibold text-[var(--ui-ink-strong)]",children:"2"}),e.jsx("span",{className:"text-sm font-medium text-[var(--ui-ink-strong)]",children:"Restart the gateway and confirm the agent can connect"})]}),e.jsx(se,{label:"Run in terminal",copyText:f,children:f})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsx("div",{className:"flex size-5 items-center justify-center rounded-full bg-[var(--ui-surface-3)] text-xs font-semibold text-[var(--ui-ink-strong)]",children:"3"}),e.jsx("span",{className:"text-sm font-medium text-[var(--ui-ink-strong)]",children:"Verify the token is accepted by the API"})]}),e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] p-4 text-sm leading-6 text-[var(--ui-ink-medium)]",children:["Run the curl below. A"," ",e.jsx("code",{className:"rounded-md bg-[var(--ui-surface-2)] px-1.5 py-0.5 text-xs text-[color-mix(in_srgb,var(--success)_78%,var(--ui-ink-strong)_22%)]",children:"200 OK"})," response means the token works and the agent"," ",e.jsx("strong",{className:"text-[var(--ui-ink-medium)]",children:m})," is authenticated."]}),e.jsx("div",{className:"mt-3",children:e.jsx(se,{label:"Verify token — run in terminal",copyText:u,children:u})})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-3 text-sm leading-6 text-[var(--ui-ink-muted)]",children:[e.jsx("strong",{className:"text-[var(--ui-ink-medium)]",children:"Tip:"})," If you ever lose this token, go to ",e.jsx("strong",{className:"text-[var(--ui-ink-medium)]",children:"Settings → Agents → Agent tokens"}),", find the entry, and click"," ",e.jsx("strong",{className:"text-[var(--ui-ink-medium)]",children:"Rotate & reveal"})," to get a fresh value without creating a new agent identity."]})]})}),e.jsx("div",{className:"shrink-0 border-t border-[var(--ui-border-subtle)] px-6 py-4",children:e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-muted)]",children:"Token saved? Close this dialog when you are ready."}),e.jsxs(P,{onClick:()=>r(!1),children:[e.jsx(Ce,{className:"size-4"}),"Done"]})]})})]})]})})}function Q(a,r){return r.every(l=>a.scopes.includes(l))}function z(a){if(!a)return"Never";try{return new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}).format(new Date(a))}catch{return a}}function Ne(a){return a==="connected"?"text-[color-mix(in_srgb,var(--success)_78%,var(--ui-ink-strong)_22%)]":a==="stale"||a==="reconnecting"?"text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]":a==="error"?"text-[color-mix(in_srgb,var(--danger)_78%,var(--ui-ink-strong)_22%)]":"text-[var(--ui-ink-muted)]"}function ws(a){return a.some(r=>r.status==="connected")?"connected":a.some(r=>r.status==="reconnecting")?"reconnecting":a.some(r=>r.status==="error")?"error":a.some(r=>r.status==="stale")?"stale":"disconnected"}function Ns(a){const r=new Map;for(const l of a){const p=l.agentId??`${l.provider}:${l.agentLabel}`,m=r.get(p);if(!m){r.set(p,{key:p,agentId:l.agentId,agentLabel:l.agentLabel,provider:l.provider,status:l.status,primary:l,sessions:[l],actionCount:l.actionCount,eventCount:l.eventCount});continue}m.sessions.push(l),m.actionCount+=l.actionCount,m.eventCount+=l.eventCount,m.sessions.sort((b,k)=>Date.parse(k.lastHeartbeatAt)-Date.parse(b.lastHeartbeatAt)),m.primary=m.sessions[0]??m.primary,m.status=ws(m.sessions)}return Array.from(r.values()).sort((l,p)=>Date.parse(p.primary.lastHeartbeatAt)-Date.parse(l.primary.lastHeartbeatAt))}function Pe(a){return a.replaceAll("_"," ")}function Ps(a){const r=[];return a.scopePolicy.userIds.length>0?r.push(`${a.scopePolicy.userIds.length} user${a.scopePolicy.userIds.length===1?"":"s"}`):r.push("all visible users"),a.scopePolicy.projectIds.length>0&&r.push(`${a.scopePolicy.projectIds.length} project${a.scopePolicy.projectIds.length===1?"":"s"}`),a.scopePolicy.tagIds.length>0&&r.push(`${a.scopePolicy.tagIds.length} tag${a.scopePolicy.tagIds.length===1?"":"s"}`),r.join(" · ")}function Os(){var ge,he,ve,be,je,fe;const a=Ke(),[r,l]=v.useState(!1),[p,m]=v.useState("operator"),[b,k]=v.useState(null),[u,f]=v.useState(!1),[M,j]=v.useState(!1),[A,i]=v.useState(!1),[n,t]=v.useState(null),y=R({queryKey:["forge-operator-session"],queryFn:ts}),S=y.isSuccess,q=R({queryKey:["forge-settings"],queryFn:as,enabled:S}),Le=R({queryKey:["forge-approval-requests"],queryFn:is,enabled:S}),ae=R({queryKey:["forge-agent-onboarding"],queryFn:rs}),Y=R({queryKey:["forge-agent-runtime-sessions"],queryFn:ns,enabled:S}),J=R({queryKey:["forge-agent-runtime-session-history",n],queryFn:()=>os(n),enabled:S&&!!n}),_e=R({queryKey:["forge-operator-context"],queryFn:ls,enabled:S}),T=async()=>{await Promise.all([a.invalidateQueries({queryKey:["forge-operator-session"]}),a.invalidateQueries({queryKey:["forge-settings"]}),a.invalidateQueries({queryKey:["forge-approval-requests"]}),a.invalidateQueries({queryKey:["forge-agent-onboarding"]}),a.invalidateQueries({queryKey:["forge-agent-runtime-sessions"]}),a.invalidateQueries({queryKey:["forge-agent-runtime-session-history"]}),a.invalidateQueries({queryKey:["forge-operator-context"]})])},ie=_({mutationFn:s=>We(s),onSuccess:T}),re=_({mutationFn:s=>Qe(s),onSuccess:async s=>{if(await T(),o){const d=s.token;k({tokenString:d.token,agentLabel:d.tokenSummary.agentLabel??"forge-agent",onboarding:o}),f(!0)}}}),ne=_({mutationFn:s=>Xe(s),onSuccess:T}),oe=_({mutationFn:s=>Ge(s),onSuccess:T}),le=_({mutationFn:s=>Ye(s),onSuccess:T}),de=_({mutationFn:({sessionId:s,note:d})=>Je(s,d),onSuccess:T}),ce=_({mutationFn:({sessionId:s,note:d,lastError:c})=>Ze(s,{note:d,lastError:c}),onSuccess:T}),O=_({mutationFn:Ve,onSuccess:T}),w=(ge=q.data)==null?void 0:ge.settings,D=((he=Le.data)==null?void 0:he.approvalRequests)??[],o=(ve=ae.data)==null?void 0:ve.onboarding,ue=v.useMemo(()=>{var s;return((s=Y.data)==null?void 0:s.sessions)??[]},[(be=Y.data)==null?void 0:be.sessions]),E=v.useMemo(()=>Ns(ue),[ue]),I=J.data,x=(je=_e.data)==null?void 0:je.context,L=(w==null?void 0:w.agentTokens.filter(s=>s.status==="active"))??[],me=(o==null?void 0:o.recommendedScopes)??[],B=L.some(s=>Q(s,me)),H=L.some(s=>Q(s,["rewards.manage"])),U=L.some(s=>Q(s,["psyche.write"])),K=L.some(s=>s.autonomyMode!=="approval_required"&&Q(s,["write"])),$=L.length>0,xe=E.filter(s=>s.status==="connected"),pe=E.filter(s=>s.status==="stale"),Ie=v.useMemo(()=>{if(!x)return[];const s=[...x.focusTasks,...x.currentBoard.backlog,...x.currentBoard.focus,...x.currentBoard.inProgress,...x.currentBoard.blocked,...x.currentBoard.done],d=new Map;for(const c of s)d.set(c.id,c);return[...d.values()]},[x]),Re=(w==null?void 0:w.profile.operatorName)??"",Fe=[{label:"Operator session",ok:!0,badge:"active",badgeTone:"emerald",detail:(fe=y.data)!=null&&fe.session?`Session open as ${y.data.session.actorLabel}. Works for localhost and Tailscale without a token.`:"Passwordless session is active for local and Tailscale access.",action:null},{label:"Agent token",ok:$,badge:$?`${L.length} active`:"none issued",badgeTone:$?"emerald":"amber",detail:$?`${L.length} active token${L.length===1?"":"s"} allow external agents and scripts to authenticate.`:"No token yet. Issue one to let external agents connect via the API.",action:$?null:{label:"Issue token",preset:"operator",onClick:()=>{m("operator"),l(!0)}}},{label:"Full operator bundle",ok:B,badge:B?"ready":"optional",badgeTone:B?"emerald":"neutral",detail:B?"A token covers all recommended scopes for full operator collaboration.":"No token covers the full recommended scope bundle. Issue one to unlock complete agent collaboration.",action:B?null:{label:"Set up",preset:"operator",onClick:()=>{m("operator"),l(!0)}}},{label:"Reward control",ok:H,badge:H?"ready":"optional",badgeTone:H?"emerald":"neutral",detail:H?"An agent can tune reward rules and issue bonus XP grants.":"No token has rewards.manage — agents cannot adjust XP rules or issue bonuses.",action:H?null:{label:"Add scope",preset:"operator",onClick:()=>{m("operator"),l(!0)}}},{label:"Psyche writes",ok:U,badge:U?"ready":"optional",badgeTone:U?"emerald":"neutral",detail:U?"Sensitive Psyche collaboration is enabled — agents can create and update therapeutic records.":"No token has psyche.write — agent collaboration on sensitive Psyche records is disabled.",action:U?null:{label:"Add scope",preset:"operator",onClick:()=>{m("operator"),l(!0)}}},{label:"Scoped writes",ok:K,badge:K?"ready":"optional",badgeTone:K?"emerald":"neutral",detail:K?"A trusted agent can write without constant approval prompts.":"All write tokens are approval-required. Agents must queue every mutation for your review.",action:K?null:{label:"Configure",preset:"operator",onClick:()=>{m("operator"),l(!0)}}}];return y.isLoading||q.isLoading?e.jsx(es,{eyebrow:"Settings · Agents",title:"Loading agent console",description:"Establishing the operator session and loading agent configuration.",columns:2,blocks:6}):y.isError?e.jsx(ye,{eyebrow:"Settings · Agents",error:y.error,onRetry:()=>void y.refetch()}):q.isError||!w?e.jsx(ye,{eyebrow:"Settings · Agents",error:q.error??new Error("Could not load settings."),onRetry:()=>void q.refetch()}):e.jsxs("div",{className:"mx-auto grid w-full max-w-[1220px] gap-5",children:[e.jsx(bs,{title:"Agents",description:"Connection status, capability access, tokens, approval queue, and work logging."}),e.jsx(vs,{}),e.jsx(fs,{open:r,onOpenChange:l,pending:ie.isPending,initialPreset:p,defaultAgentLabel:(o==null?void 0:o.defaultActorLabel)??"OpenClaw",recommendedScopes:me,onSubmit:async s=>{const d=await ie.mutateAsync(s);l(!1),o&&(k({tokenString:d.token.token,agentLabel:s.agentLabel,onboarding:o}),f(!0))}}),e.jsx(ks,{open:u,onOpenChange:f,state:b}),e.jsx(ys,{open:M,onOpenChange:j,pending:O.isPending,defaultOwner:Re,availableTasks:Ie,availableProjects:(x==null?void 0:x.activeProjects)??[],onSubmit:async s=>{await O.mutateAsync(s)}}),e.jsxs("div",{className:"grid gap-5",children:[x?e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsx(W,{label:"Active sessions",value:xe.length,tone:"core"}),e.jsx(W,{label:"Stale sessions",value:pe.length,tone:"core"}),e.jsx(W,{label:"Pending approvals",value:D.filter(s=>s.status==="pending").length,tone:"core"}),e.jsx(W,{label:"Operator level",value:x.xp.profile.level,tone:"core",detail:`${x.xp.profile.totalXp} total XP`})]}):null,e.jsxs(N,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Capability status"}),e.jsx("div",{className:"mt-4 grid gap-3",children:Fe.map(s=>e.jsxs("div",{className:"flex items-start justify-between gap-4 rounded-[18px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"font-medium text-[var(--ui-ink-strong)]",children:s.label}),e.jsx(h,{className:s.badgeTone==="emerald"?"text-[color-mix(in_srgb,var(--success)_78%,var(--ui-ink-strong)_22%)]":s.badgeTone==="amber"?"text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]":"text-[var(--ui-ink-muted)]",children:s.badge})]}),e.jsx("div",{className:"mt-1 text-sm leading-6 text-[var(--ui-ink-muted)]",children:s.detail})]}),s.action?e.jsxs("button",{type:"button",onClick:s.action.onClick,className:"mt-0.5 flex shrink-0 items-center gap-1.5 rounded-full bg-[var(--ui-surface-2)] px-3 py-1.5 text-xs font-medium text-[var(--ui-ink-medium)] transition hover:bg-[var(--ui-surface-2)] hover:text-[var(--ui-ink-strong)]",children:[s.action.label,e.jsx(De,{className:"size-3"})]}):null]},s.label))})]}),e.jsxs(N,{children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Runtime sessions"}),e.jsx("div",{className:"mt-1 text-sm text-[var(--ui-ink-muted)]",children:"Live OpenClaw, Hermes, and Codex sessions registered against this Forge runtime, with stale detection and reconnect guidance."})]}),E.length>0?e.jsxs(h,{className:"text-[var(--ui-ink-medium)]",children:[xe.length," live ·"," ",pe.length," stale"]}):null]}),e.jsx("div",{className:"mt-4 grid gap-3",children:Y.isLoading?e.jsx("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] px-4 py-4 text-sm text-[var(--ui-ink-muted)]",children:"Loading agent runtime sessions…"}):E.length===0?e.jsx("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] px-4 py-4 text-sm text-[var(--ui-ink-muted)]",children:"No runtime sessions have registered yet. OpenClaw, Hermes, and Codex now self-register here when their Forge adapter starts."}):E.map(s=>{const d=s.primary;return e.jsxs("div",{className:"min-w-0 rounded-[18px] bg-[var(--ui-surface-2)] p-4",children:[e.jsxs("div",{className:"flex min-w-0 flex-col gap-3 lg:flex-row lg:items-start lg:justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"font-medium text-[var(--ui-ink-strong)]",children:s.agentLabel}),e.jsx(h,{className:Ne(s.status),children:s.status})]}),e.jsxs("div",{className:"mt-1 text-sm text-[var(--ui-ink-muted)]",children:[s.provider," ·"," ",d.connectionMode.replaceAll("_"," ")," · last heartbeat ",z(d.lastHeartbeatAt)]}),e.jsxs("div",{className:"mt-2 flex min-w-0 flex-wrap gap-x-4 gap-y-1 text-xs text-[var(--ui-ink-muted)]",children:[e.jsxs("span",{children:[s.sessions.length," runtime session",s.sessions.length===1?"":"s"]}),e.jsxs("span",{className:"min-w-0 break-all",children:["Current key ",d.sessionKey]}),e.jsxs("span",{children:[s.actionCount," recorded actions"]}),e.jsxs("span",{children:[s.eventCount," session events"]})]}),d.lastError?e.jsx("div",{className:"mt-3 text-sm text-[color-mix(in_srgb,var(--danger)_78%,var(--ui-ink-strong)_22%)]",children:d.lastError}):null]}),e.jsxs("div",{className:"flex min-w-0 flex-wrap gap-2 lg:shrink-0 lg:justify-end",children:[s.status!=="connected"?e.jsx(P,{variant:"secondary",size:"sm",className:"flex-1 sm:flex-none",pending:de.isPending,pendingLabel:"Requesting",onClick:()=>void de.mutateAsync({sessionId:d.id}),children:"Reconnect"}):null,e.jsx(P,{variant:"secondary",size:"sm",className:"flex-1 sm:flex-none",onClick:()=>t(c=>c===d.id?null:d.id),children:n===d.id?"Hide history":"View history"}),s.status!=="disconnected"?e.jsx(P,{variant:"ghost",size:"sm",className:"flex-1 sm:flex-none",pending:ce.isPending,pendingLabel:"Closing",onClick:()=>void ce.mutateAsync({sessionId:d.id,note:"Marked disconnected from the Forge agents console."}),children:"Mark offline"}):null]})]}),d.recentEvents.length>0?e.jsx("div",{className:"mt-4 grid gap-2",children:d.recentEvents.slice(0,3).map(c=>e.jsxs("div",{className:"flex items-start justify-between gap-3 rounded-[16px] bg-[var(--ui-surface-2)] px-3 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-strong)]",children:c.title}),e.jsx("div",{className:"mt-0.5 text-xs leading-5 text-[var(--ui-ink-muted)]",children:c.summary||c.eventType})]}),e.jsx("div",{className:"shrink-0 text-xs text-[var(--ui-ink-muted)]",children:z(c.createdAt)})]},c.id))}):null,e.jsxs("div",{className:"mt-4 rounded-[16px] bg-[var(--ui-code-bg)] p-3",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.14em] text-[var(--ui-ink-muted)]",children:"Reconnect plan"}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-medium)]",children:d.reconnectPlan.summary}),e.jsx("pre",{className:"mt-3 whitespace-pre-wrap break-words text-xs leading-6 text-[var(--ui-ink-medium)] md:overflow-x-auto md:whitespace-pre",children:e.jsx("code",{className:"break-words",children:d.reconnectPlan.commands.join(`
4
+ `)})})]}),s.sessions.length>1?e.jsxs("div",{className:"mt-4 rounded-[16px] bg-[var(--ui-code-bg)] p-3",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.14em] text-[var(--ui-ink-muted)]",children:"Session history under this agent"}),e.jsx("div",{className:"mt-2 grid gap-2",children:s.sessions.slice(0,6).map(c=>e.jsxs("div",{className:"grid min-w-0 gap-1 rounded-[12px] bg-[var(--ui-surface-2)] px-3 py-2 text-xs text-[var(--ui-ink-muted)] sm:flex sm:items-center sm:justify-between sm:gap-2",children:[e.jsx("span",{className:"min-w-0 break-all sm:truncate",children:c.sessionKey}),e.jsxs("span",{className:`${Ne(c.status)} min-w-0 break-words sm:shrink-0`,children:[c.status," ·"," ",z(c.lastHeartbeatAt)]})]},c.id))})]}):null,n===d.id?e.jsxs("div",{className:"mt-4 rounded-[16px] bg-[var(--ui-code-bg)] p-3",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.14em] text-[var(--ui-ink-muted)]",children:"Work history"}),J.isLoading?e.jsx("div",{className:"mt-3 text-sm text-[var(--ui-ink-muted)]",children:"Loading session history…"}):J.isError?e.jsx("div",{className:"mt-3 text-sm text-[color-mix(in_srgb,var(--danger)_78%,var(--ui-ink-strong)_22%)]",children:"Could not load session history."}):(I==null?void 0:I.session.id)===d.id?e.jsxs("div",{className:"mt-3 grid gap-4 lg:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.14em] text-[var(--ui-ink-muted)]",children:"Agent actions"}),e.jsx("div",{className:"mt-2 grid gap-2",children:I.actions.length>0?I.actions.map(c=>e.jsxs("div",{className:"rounded-[14px] bg-[var(--ui-surface-2)] px-3 py-2.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-strong)]",children:c.title}),e.jsx(h,{className:"text-[var(--ui-ink-muted)]",children:c.status})]}),e.jsx("div",{className:"mt-1 text-xs leading-5 text-[var(--ui-ink-muted)]",children:c.summary||c.actionType}),e.jsx("div",{className:"mt-1 text-xs text-[var(--ui-ink-muted)]",children:z(c.createdAt)})]},c.id)):e.jsx("div",{className:"rounded-[14px] bg-[var(--ui-surface-2)] px-3 py-2.5 text-sm text-[var(--ui-ink-muted)]",children:"No recorded agent actions for this session yet."})})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.14em] text-[var(--ui-ink-muted)]",children:"Session events"}),e.jsx("div",{className:"mt-2 grid gap-2",children:I.events.length>0?I.events.map(c=>e.jsxs("div",{className:"rounded-[14px] bg-[var(--ui-surface-2)] px-3 py-2.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-strong)]",children:c.title}),e.jsx(h,{className:"text-[var(--ui-ink-muted)]",children:c.level})]}),e.jsx("div",{className:"mt-1 text-xs leading-5 text-[var(--ui-ink-muted)]",children:c.summary||c.eventType}),e.jsx("div",{className:"mt-1 text-xs text-[var(--ui-ink-muted)]",children:z(c.createdAt)})]},c.id)):e.jsx("div",{className:"rounded-[14px] bg-[var(--ui-surface-2)] px-3 py-2.5 text-sm text-[var(--ui-ink-muted)]",children:"No session events recorded yet."})})]})]}):null]}):null]},s.key)})})]}),e.jsxs(N,{children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Agent tokens"}),e.jsxs(P,{size:"sm",variant:"secondary",onClick:()=>{m("operator"),l(!0)},children:[e.jsx(Ee,{className:"size-3.5"}),"Issue token"]})]}),e.jsx("div",{className:"mt-4 grid gap-3",children:w.agentTokens.length===0?e.jsx("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] px-4 py-4 text-sm text-[var(--ui-ink-muted)]",children:"No tokens yet. Issue one to let external agents or scripts authenticate with Forge."}):w.agentTokens.map(s=>e.jsxs("div",{className:"min-w-0 rounded-[18px] bg-[var(--ui-surface-2)] p-4",children:[e.jsxs("div",{className:"flex min-w-0 flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium text-[var(--ui-ink-strong)]",children:s.label}),e.jsxs("div",{className:"mt-0.5 text-sm text-[var(--ui-ink-muted)]",children:[s.agentLabel??"Unassigned agent"," ·"," ",e.jsx("span",{className:"break-all font-mono text-xs",children:s.tokenPrefix})]})]}),e.jsx(h,{className:`${s.status==="active"?"text-[color-mix(in_srgb,var(--success)_78%,var(--ui-ink-strong)_22%)]":"text-[var(--ui-ink-muted)]"} self-start`,children:s.status})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2 text-xs text-[var(--ui-ink-muted)]",children:[e.jsx("span",{children:s.trustLevel}),e.jsx("span",{children:"·"}),e.jsx("span",{children:s.autonomyMode.replaceAll("_"," ")}),e.jsx("span",{children:"·"}),e.jsx("span",{children:s.approvalMode.replaceAll("_"," ")})]}),e.jsxs("div",{className:"mt-2 text-xs text-[var(--ui-ink-muted)]",children:["Bootstrap: ",Pe(s.bootstrapPolicy.mode)," · ",s.bootstrapPolicy.projectsLimit," projects"," · ",s.bootstrapPolicy.tasksLimit," tasks",s.bootstrapPolicy.includePeoplePages?` · ${s.bootstrapPolicy.peoplePageLimit} people pages`:" · no people pages"]}),e.jsxs("div",{className:"mt-1 text-xs text-[var(--ui-ink-muted)]",children:["Default read scope: ",Ps(s)]}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-1.5",children:["write","rewards.manage","psyche.write"].map(d=>e.jsx(h,{className:s.scopes.includes(d)?"text-[color-mix(in_srgb,var(--success)_78%,var(--ui-ink-strong)_22%)]":"text-[var(--ui-ink-muted)]",children:d},d))}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-2",children:[e.jsx(P,{variant:"secondary",size:"sm",pending:re.isPending,pendingLabel:"Rotating",onClick:()=>void re.mutateAsync(s.id),children:"Rotate & reveal new token"}),e.jsx(P,{variant:"ghost",size:"sm",pending:ne.isPending,pendingLabel:"Revoking",onClick:()=>void ne.mutateAsync(s.id),children:"Revoke"})]})]},s.id))}),e.jsx("div",{className:"mt-3 px-1 text-xs text-[var(--ui-ink-muted)]",children:"Raw token values are shown once and are never recoverable. If a token is lost, rotate or issue a new one."})]}),w.agents.length>0?e.jsxs(N,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Connected agents"}),e.jsx("div",{className:"mt-4 grid gap-3",children:w.agents.map(s=>e.jsxs("div",{className:"flex min-w-0 flex-col gap-3 rounded-[18px] bg-[var(--ui-surface-2)] p-4 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium text-[var(--ui-ink-strong)]",children:s.label}),s.description?e.jsx("div",{className:"mt-1 text-sm text-[var(--ui-ink-muted)]",children:s.description}):null,s.linkedUsers.length>0?e.jsx("div",{className:"mt-2 flex flex-wrap gap-2",children:s.linkedUsers.map(d=>{var c;return e.jsx(h,{className:"text-[var(--ui-ink-muted)]",children:((c=d.user)==null?void 0:c.displayName)??d.userId},d.userId)})}):null,e.jsxs("div",{className:"mt-2 flex min-w-0 flex-wrap gap-x-4 gap-y-1 text-sm text-[var(--ui-ink-muted)]",children:[e.jsx("span",{children:s.agentType}),s.identityKey?e.jsx("span",{className:"min-w-0 break-all font-mono text-xs",children:s.identityKey}):null,e.jsx("span",{children:s.autonomyMode.replaceAll("_"," ")}),e.jsxs("span",{children:[s.activeTokenCount," active token",s.activeTokenCount!==1?"s":""]})]})]}),e.jsx(h,{className:"self-start text-[var(--ui-ink-medium)]",children:s.trustLevel})]},s.id))})]}):null,x?e.jsxs("div",{className:"grid gap-3 lg:grid-cols-[minmax(0,1.05fr)_minmax(0,0.95fr)]",children:[e.jsxs(N,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Recommended next move"}),x.recommendedNextTask?e.jsxs("div",{className:"mt-4 grid gap-2",children:[e.jsx(Z,{kind:"task",label:x.recommendedNextTask.title,variant:"heading",size:"lg"}),e.jsx("div",{className:"text-sm leading-6 text-[var(--ui-ink-muted)]",children:x.recommendedNextTask.description||"No extra notes yet."}),e.jsxs("div",{className:"mt-1 flex flex-wrap gap-2",children:[e.jsx(h,{children:x.recommendedNextTask.status.replaceAll("_"," ")}),e.jsxs(h,{children:[x.recommendedNextTask.points," xp"]}),e.jsx(h,{children:x.recommendedNextTask.owner})]})]}):e.jsx("div",{className:"mt-4 text-sm text-[var(--ui-ink-muted)]",children:"Board is clear. No recommended task right now."})]}),e.jsxs(N,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Board pulse"}),e.jsx("div",{className:"mt-4 grid grid-cols-2 gap-3",children:[{label:"Backlog",value:x.currentBoard.backlog.length},{label:"Focus",value:x.currentBoard.focus.length},{label:"In progress",value:x.currentBoard.inProgress.length},{label:"Blocked",value:x.currentBoard.blocked.length}].map(s=>e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.14em] text-[var(--ui-ink-muted)]",children:s.label}),e.jsx("div",{className:"mt-2 font-display text-3xl text-[var(--ui-ink-strong)]",children:s.value})]},s.label))})]})]}):null,x&&x.activeProjects.length>0?e.jsxs(N,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Active projects"}),e.jsx("div",{className:"mt-4 grid gap-3 sm:grid-cols-2",children:x.activeProjects.slice(0,6).map(s=>e.jsxs("div",{className:"min-w-0 rounded-[18px] bg-[var(--ui-surface-2)] p-4",children:[e.jsxs("div",{className:"flex min-w-0 flex-col gap-2 sm:flex-row sm:items-start sm:justify-between",children:[e.jsx("div",{className:"min-w-0",children:e.jsx(Z,{kind:"project",label:s.title})}),e.jsxs(h,{className:"self-start",children:[s.progress,"%"]})]}),e.jsx("div",{className:"mt-2",children:e.jsx(ss,{kind:"goal",label:s.goalTitle,compact:!0,gradient:!1})}),e.jsxs("div",{className:"mt-2 text-xs text-[var(--ui-ink-muted)]",children:[s.activeTaskCount," active ·"," ",s.completedTaskCount," done"]})]},s.id))})]}):null,e.jsxs(N,{children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Approval queue"}),D.filter(s=>s.status==="pending").length>0?e.jsxs(h,{className:"text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]",children:[D.filter(s=>s.status==="pending").length," pending"]}):null]}),e.jsx("div",{className:"mt-4 grid gap-3",children:D.length===0?e.jsx("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] px-4 py-4 text-sm text-[var(--ui-ink-muted)]",children:"No pending approvals. Agent actions are flowing through."}):D.map(s=>e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] p-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium text-[var(--ui-ink-strong)]",children:s.title}),e.jsx("div",{className:"mt-0.5 text-sm text-[var(--ui-ink-muted)]",children:s.summary||s.actionType})]}),e.jsx(h,{className:s.status==="pending"?"text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]":"text-[var(--ui-ink-muted)]",children:s.status})]}),s.status==="pending"?e.jsxs("div",{className:"mt-4 flex flex-wrap gap-2",children:[e.jsx(P,{variant:"secondary",size:"sm",pending:oe.isPending,pendingLabel:"Approving",onClick:()=>void oe.mutateAsync(s.id),children:"Approve"}),e.jsx(P,{variant:"ghost",size:"sm",pending:le.isPending,pendingLabel:"Rejecting",onClick:()=>void le.mutateAsync(s.id),children:"Reject"})]}):null]},s.id))})]}),e.jsxs(N,{children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Retroactive work log"}),e.jsx("div",{className:"mt-1 text-sm text-[var(--ui-ink-muted)]",children:"Capture work done outside the timer so it counts toward progress and XP."})]}),e.jsxs(P,{variant:"secondary",size:"sm",onClick:()=>j(!0),children:[e.jsx(Be,{className:"size-3.5"}),"Log work"]})]}),O.data?e.jsxs("div",{className:"mt-4 rounded-[18px] bg-[var(--ui-accent-soft)] px-4 py-3 text-sm text-[var(--ui-ink-strong)]",children:["Logged"," ",e.jsx("span",{className:"inline-block align-middle",children:e.jsx(Z,{kind:"task",label:O.data.task.title,showKind:!1})}),". Operator XP updated to ",O.data.xp.profile.totalXp,"."]}):null]}),e.jsxs(N,{children:[e.jsxs("button",{type:"button",className:"flex w-full items-center justify-between gap-4 text-left",onClick:()=>i(s=>!s),children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Connection & onboarding"}),o?e.jsx("div",{className:"mt-1 text-sm text-[var(--ui-ink-muted)]",children:o.forgeBaseUrl}):null]}),A?e.jsx(He,{className:"size-4 shrink-0 text-[var(--ui-ink-muted)]"}):e.jsx(Ue,{className:"size-4 shrink-0 text-[var(--ui-ink-muted)]"})]}),A&&o?e.jsxs("div",{className:"mt-5 grid gap-4",children:[e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.14em] text-[var(--ui-ink-muted)]",children:"Forge API"}),e.jsx("div",{className:"mt-2 break-all text-sm text-[var(--ui-ink-strong)]",children:o.forgeBaseUrl})]}),e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.14em] text-[var(--ui-ink-muted)]",children:"Web app"}),e.jsx("div",{className:"mt-2 break-all text-sm text-[var(--ui-ink-strong)]",children:o.webAppUrl})]}),e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.14em] text-[var(--ui-ink-muted)]",children:"OpenAPI spec"}),e.jsx("div",{className:"mt-2 break-all text-sm text-[var(--ui-ink-strong)]",children:o.openApiUrl})]}),e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.14em] text-[var(--ui-ink-muted)]",children:"Default policy"}),e.jsxs("div",{className:"mt-2 text-sm text-[var(--ui-ink-strong)]",children:[o.recommendedTrustLevel," ·"," ",o.recommendedAutonomyMode.replaceAll("_"," ")," ·"," ",o.recommendedApprovalMode.replaceAll("_"," ")]}),e.jsxs("div",{className:"mt-2 text-xs text-[var(--ui-ink-muted)]",children:["Bootstrap default:"," ",Pe(o.defaultBootstrapPolicy.mode)," · ",o.defaultBootstrapPolicy.projectsLimit," projects"," · ",o.defaultBootstrapPolicy.tasksLimit," tasks"]})]})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"font-medium text-[var(--ui-ink-strong)]",children:o.authModes.operatorSession.label}),e.jsx(h,{className:"mt-1 text-[color-mix(in_srgb,var(--success)_78%,var(--ui-ink-strong)_22%)]",children:o.defaultConnectionMode==="operator_session"?"default":"available"}),e.jsx("div",{className:"mt-3 text-sm leading-6 text-[var(--ui-ink-medium)]",children:o.authModes.operatorSession.summary}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:o.authModes.operatorSession.trustedTargets.map(s=>e.jsx(h,{className:"text-[var(--ui-ink-medium)]",children:s},s))})]}),e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"font-medium text-[var(--ui-ink-strong)]",children:o.authModes.managedToken.label}),e.jsx(h,{className:"mt-1 text-[var(--ui-ink-muted)]",children:"optional"}),e.jsx("div",{className:"mt-3 text-sm leading-6 text-[var(--ui-ink-medium)]",children:o.authModes.managedToken.summary}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-muted)]",children:o.tokenRecovery.rotationSummary})]})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.14em] text-[var(--ui-ink-muted)]",children:"Shared runtime"}),e.jsx("div",{className:"mt-3 text-sm leading-6 text-[var(--ui-ink-medium)]",children:"Keep Forge, OpenClaw, Hermes, and the browser on the same runtime when they should see one shared user directory, one strategy graph, and one task history."}),e.jsxs("div",{className:"mt-3 text-xs leading-5 text-[var(--ui-ink-muted)]",children:["Base URL: ",o.forgeBaseUrl]})]}),e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.14em] text-[var(--ui-ink-muted)]",children:"Agent identity"}),e.jsx("div",{className:"mt-3 text-sm leading-6 text-[var(--ui-ink-medium)]",children:"Create each agent as a bot user, then write with that user's `userId`. The relationship graph in Settings -> Users controls what each direction can see, message, share, plan, and affect."}),e.jsx("div",{className:"mt-3 text-xs leading-5 text-[var(--ui-ink-muted)]",children:"Cross-owner links stay valid even when ownership differs."})]}),e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.14em] text-[var(--ui-ink-muted)]",children:"Contract timing"}),e.jsx("div",{className:"mt-3 text-sm leading-6 text-[var(--ui-ink-medium)]",children:"Leave strategies editable while humans and bots refine the graph. Lock them only when the plan becomes the contract the alignment metrics should judge."}),e.jsx("div",{className:"mt-3 text-xs leading-5 text-[var(--ui-ink-muted)]",children:"Coverage, sequencing, scope discipline, and quality all contribute to alignment now."})]})]}),e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.14em] text-[var(--ui-ink-muted)]",children:"Fast onboarding checklist"}),e.jsxs("div",{className:"mt-3 grid gap-2 text-sm leading-6 text-[var(--ui-ink-medium)]",children:[e.jsx("div",{children:"1. Create the human and bot users in Settings -> Users."}),e.jsx("div",{children:"2. Keep the default graph permissive until collaboration is flowing cleanly."}),e.jsx("div",{children:"3. Point OpenClaw and Hermes at the same Forge runtime and storage root when they should collaborate."}),e.jsx("div",{children:"4. Give each adapter a distinct actor label so activity stays readable."}),e.jsx("div",{children:"5. Build strategies as drafts first, then lock when the plan is ready to become the contract."})]})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.14em] text-[var(--ui-ink-muted)]",children:"Rights language"}),e.jsxs("div",{className:"mt-3 grid gap-2 text-sm leading-6 text-[var(--ui-ink-medium)]",children:[e.jsx("div",{children:"`See` means discover, search, and read another owner."}),e.jsx("div",{children:"`Message` means coordinate and hand off through Forge."}),e.jsx("div",{children:"`Plan` means draft or edit that owner's strategies."}),e.jsx("div",{children:"`Affect` means create or mutate that owner's work."})]})]}),e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.14em] text-[var(--ui-ink-muted)]",children:"Strategy lifecycle"}),e.jsxs("div",{className:"mt-3 grid gap-2 text-sm leading-6 text-[var(--ui-ink-medium)]",children:[e.jsx("div",{children:"1. Save an incomplete draft while the plan is still being negotiated."}),e.jsx("div",{children:"2. Let humans and bots refine targets, nodes, and sequence together."}),e.jsx("div",{children:"3. Lock only when the graph becomes the contract for alignment."}),e.jsx("div",{children:"4. Unlock only when the contract itself is being renegotiated."})]})]})]}),e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.14em] text-[var(--ui-ink-muted)]",children:"Quick-connect verification"}),e.jsx("pre",{className:"mt-3 overflow-x-auto rounded-[16px] bg-[var(--ui-code-bg)] p-4 text-xs leading-6 text-[var(--ui-ink-medium)]",children:e.jsx("code",{children:[`curl -s ${o.healthUrl}`,"openclaw plugins install ./projects/forge","openclaw gateway restart"].join(`
5
+ `)})})]}),e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.14em] text-[var(--ui-ink-muted)]",children:"Required API headers"}),e.jsxs("div",{className:"mt-3 grid gap-1 text-sm text-[var(--ui-ink-medium)]",children:[e.jsx("div",{children:o.requiredHeaders.authorization}),e.jsx("div",{children:o.requiredHeaders.source}),e.jsx("div",{children:o.requiredHeaders.actor})]})]}),e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.14em] text-[var(--ui-ink-muted)]",children:"Session registry"}),e.jsx("div",{className:"mt-3 text-sm leading-6 text-[var(--ui-ink-medium)]",children:o.sessionRegistry.summary}),e.jsxs("div",{className:"mt-3 grid gap-1 text-xs leading-5 text-[var(--ui-ink-muted)]",children:[e.jsxs("div",{children:["Register: ",o.sessionRegistry.registerUrl]}),e.jsxs("div",{children:["Heartbeat: ",o.sessionRegistry.heartbeatUrl]}),e.jsxs("div",{children:["Events: ",o.sessionRegistry.eventsUrl]})]})]}),e.jsx("div",{className:"grid gap-3 md:grid-cols-3",children:[o.connectionGuides.openclaw,o.connectionGuides.hermes,o.connectionGuides.codex].map(s=>e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"font-medium text-[var(--ui-ink-strong)]",children:s.label}),e.jsx("div",{className:"mt-3 grid gap-2 text-sm leading-6 text-[var(--ui-ink-medium)]",children:s.installSteps.map(d=>e.jsx("div",{children:d},d))}),e.jsx("pre",{className:"mt-4 overflow-x-auto rounded-[16px] bg-[var(--ui-code-bg)] p-4 text-xs leading-6 text-[var(--ui-ink-medium)]",children:e.jsx("code",{children:s.verifyCommands.join(`
6
+ `)})}),e.jsx("div",{className:"mt-3 grid gap-1 text-sm leading-6 text-[var(--ui-ink-muted)]",children:s.configNotes.map(d=>e.jsx("div",{children:d},d))})]},s.label))}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.14em] text-[var(--ui-ink-muted)]",children:"Multi-user model"}),e.jsx("div",{className:"mt-3 text-sm leading-6 text-[var(--ui-ink-medium)]",children:o.multiUserModel.summary}),e.jsx("div",{className:"mt-3 grid gap-1 text-sm leading-6 text-[var(--ui-ink-muted)]",children:o.multiUserModel.routeScoping.map(s=>e.jsx("div",{children:s},s))})]}),e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.14em] text-[var(--ui-ink-muted)]",children:"Strategy contracts"}),e.jsx("div",{className:"mt-3 text-sm leading-6 text-[var(--ui-ink-medium)]",children:o.strategyContractModel.lockSummary}),e.jsx("div",{className:"mt-3 grid gap-1 text-sm leading-6 text-[var(--ui-ink-muted)]",children:o.strategyContractModel.metricBreakdown.map(s=>e.jsx("div",{children:s},s))})]})]})]}):A&&ae.isError?e.jsx("div",{className:"mt-4 rounded-[18px] bg-[var(--ui-danger-soft)] px-4 py-3 text-sm text-[color-mix(in_srgb,var(--danger)_78%,var(--ui-ink-strong)_22%)]",children:"Could not load the onboarding contract. Check the API bridge."}):A?e.jsx("div",{className:"mt-4 text-sm text-[var(--ui-ink-muted)]",children:"Loading…"}):null]})]})]})}export{Os as SettingsAgentsPage};
@@ -0,0 +1 @@
1
+ import{r as u,j as e,b3 as q,c$ as E,c7 as R}from"./vendor-Dnkkx2co.js";import{j as Q,i as B,k as h}from"./state-vCcAT5Hq.js";import{S as K}from"./settings-section-nav-DP9o4peU.js";import{dT as P,dU as A,S as H,E as $,C as x,I as V,Z as W,B as y,b as G,du as Y,dV as O}from"./index-EqQsXoat.js";import{P as U}from"./page-hero-ffKzgyW3.js";import"./motion-Lt5B1XuE.js";import"./ui-C1iwpj2-.js";import"./forms-hB0SqEh-.js";import"./board-dIX6etHh.js";import"./graph-DDUZNRsO.js";const a={goal:"Goals",project:"Projects",task:"Tasks",strategy:"Strategies",habit:"Habits",tag:"Tags",note:"Notes",insight:"Insights",psyche_value:"Values",behavior_pattern:"Patterns",behavior:"Behaviors",belief_entry:"Beliefs",mode_profile:"Modes",mode_guide_session:"Mode guides",flashcard:"Flashcards",event_type:"Event types",emotion_definition:"Emotions",trigger_report:"Reports",calendar_event:"Calendar events",work_block_template:"Work blocks",task_timebox:"Timeboxes",preference_catalog:"Preference catalogs",preference_catalog_item:"Preference catalog items",preference_context:"Preference contexts",preference_item:"Preference items",questionnaire_instrument:"Questionnaires",sleep_session:"Sleep sessions",workout_session:"Workout sessions"},Z={goal:"goal",project:"project",task:"task",strategy:"strategy",habit:"habit",tag:null,note:null,insight:"report",psyche_value:"value",behavior_pattern:"pattern",behavior:"behavior",belief_entry:"belief",mode_profile:"mode",mode_guide_session:"mode",flashcard:"flashcard",event_type:null,emotion_definition:null,trigger_report:"report",calendar_event:null,work_block_template:null,task_timebox:null,preference_catalog:null,preference_catalog_item:null,preference_context:null,preference_item:null,questionnaire_instrument:null,sleep_session:null,workout_session:null},v="font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",J="text-[var(--ui-ink-strong)]",j="text-[var(--ui-ink-soft)]",m="text-[var(--ui-ink-faint)]",X="border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)] hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]",ee="border-[color-mix(in_srgb,var(--primary)_30%,var(--ui-border-subtle)_70%)] bg-[var(--ui-accent-soft)] text-[var(--primary)]",te="grid min-w-0 gap-3 rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4 lg:grid-cols-[minmax(0,1fr)_auto]";function se(f){return new Date(f).toLocaleString()}function pe(){var C,T;const f=Q(),[b,D]=u.useState(""),[l,L]=u.useState([]),c=B({queryKey:["forge-operator-session"],queryFn:Y}),M=c.isSuccess,o=B({queryKey:["forge-settings-bin"],queryFn:O,enabled:M}),p=async()=>{await f.invalidateQueries({predicate:t=>Array.isArray(t.queryKey)&&typeof t.queryKey[0]=="string"&&t.queryKey[0].startsWith("forge-")})},_=h({mutationFn:t=>P({operations:[{entityType:t.entityType,id:t.entityId}]}),onSuccess:p}),w=h({mutationFn:t=>A({operations:[{entityType:t.entityType,id:t.entityId,mode:"hard"}]}),onSuccess:p}),k=h({mutationFn:t=>P({operations:t.map(s=>({entityType:s.entityType,id:s.entityId}))}),onSuccess:p}),N=h({mutationFn:t=>A({operations:t.map(s=>({entityType:s.entityType,id:s.entityId,mode:"hard"}))}),onSuccess:p}),d=((C=o.data)==null?void 0:C.bin.records)??[],g=b.trim().toLowerCase(),r=u.useMemo(()=>d.filter(t=>l.length===0||l.includes(t.entityType)?g?[t.title,t.subtitle??"",t.entityType,t.entityId,t.deletedByActor??"",t.deletedSource??"",t.deleteReason??""].join(" ").toLowerCase().includes(g):!0:!1),[g,d,l]),S=u.useMemo(()=>{const t=new Map;for(const s of r){const i=t.get(s.entityType)??[];i.push(s),t.set(s.entityType,i)}return[...t.entries()].sort((s,i)=>a[s[0]].localeCompare(a[i[0]]))},[r]),I=u.useMemo(()=>[...new Set(d.map(t=>t.entityType))].sort((t,s)=>a[t].localeCompare(a[s])),[d]);function z(t){L(s=>s.includes(t)?s.filter(i=>i!==t):[...s,t])}async function F(){r.length===0||!window.confirm(`Permanently delete ${r.length} item${r.length===1?"":"s"} from the bin? This cannot be undone.`)||await N.mutateAsync(r)}return c.isLoading||o.isLoading?e.jsx(H,{eyebrow:"Settings",title:"Loading bin",description:"Loading deleted items and restore controls.",columns:2,blocks:6}):c.isError?e.jsx($,{eyebrow:"Settings",error:c.error,onRetry:()=>void c.refetch()}):o.isError?e.jsx($,{eyebrow:"Settings",error:o.error,onRetry:()=>void o.refetch()}):e.jsxs("div",{className:"mx-auto grid w-full max-w-[1220px] gap-5",children:[e.jsx(U,{title:"Bin",description:"Restore soft-deleted items or permanently remove them when you really mean it.",badge:`${((T=o.data)==null?void 0:T.bin.totalCount)??0} deleted items`}),e.jsx(K,{}),e.jsxs(x,{className:"grid gap-4",children:[e.jsxs("div",{className:"grid gap-4 lg:grid-cols-[minmax(0,1fr)_auto] lg:items-start",children:[e.jsxs("div",{className:"grid gap-4",children:[e.jsx("div",{className:v,children:"Find deleted items"}),e.jsxs("div",{className:"relative",children:[e.jsx(q,{className:`pointer-events-none absolute left-4 top-1/2 size-4 -translate-y-1/2 ${m}`}),e.jsx(V,{value:b,onChange:t=>D(t.target.value),placeholder:"Search title, id, reason, or source",className:"pl-11"})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:I.map(t=>{const s=l.includes(t);return e.jsx("button",{type:"button",onClick:()=>z(t),className:W("rounded-full border px-3 py-1.5 text-[11px] font-semibold uppercase tracking-[0.14em] transition",s?ee:X),children:a[t]},t)})})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 lg:max-w-[22rem] lg:justify-end",children:[e.jsxs(y,{variant:"secondary",size:"sm",disabled:r.length===0,pending:k.isPending,pendingLabel:"Restoring",onClick:()=>void k.mutateAsync(r),children:[e.jsx(E,{className:"size-4"}),e.jsx("span",{children:"Restore visible"})]}),e.jsxs(y,{variant:"secondary",size:"sm",disabled:r.length===0,pending:N.isPending,pendingLabel:"Deleting",onClick:()=>void F(),children:[e.jsx(R,{className:"size-4"}),e.jsx("span",{children:"Delete visible forever"})]})]})]}),e.jsxs("div",{className:`flex flex-wrap gap-3 text-sm ${m}`,children:[e.jsxs("span",{children:[r.length," visible"]}),l.length>0?e.jsxs("span",{children:[l.length," type filters active"]}):null,g?e.jsxs("span",{children:["Search: “",b.trim(),"”"]}):null]})]}),d.length===0?e.jsxs(x,{children:[e.jsx("div",{className:v,children:"Deleted items"}),e.jsx("div",{className:`mt-4 ${j}`,children:"Nothing is in the bin right now."})]}):S.length===0?e.jsxs(x,{children:[e.jsx("div",{className:v,children:"Deleted items"}),e.jsx("div",{className:`mt-4 ${j}`,children:"No deleted items match the current search or filters."})]}):e.jsx("div",{className:"grid gap-5",children:S.map(([t,s])=>{const i=Z[t];return e.jsxs(x,{children:[e.jsx("div",{className:"flex flex-wrap items-center justify-between gap-3",children:e.jsxs("div",{className:"flex items-center gap-3",children:[i?e.jsx(G,{kind:i,label:a[t],compact:!0}):null,i?null:e.jsx("div",{className:`rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-3 py-1 text-[11px] uppercase tracking-[0.16em] ${m}`,children:a[t]}),e.jsxs("div",{className:`text-sm ${m}`,children:[s.length," deleted"]})]})}),e.jsx("div",{className:"mt-4 grid gap-3",children:s.map(n=>e.jsxs("div",{className:te,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:`break-words text-lg font-medium [overflow-wrap:anywhere] ${J}`,children:n.title}),n.subtitle?e.jsx("div",{className:`mt-1 break-words text-sm [overflow-wrap:anywhere] ${j}`,children:n.subtitle}):null,e.jsxs("div",{className:`mt-3 flex flex-wrap gap-3 break-words text-xs [overflow-wrap:anywhere] ${m}`,children:[e.jsxs("span",{children:["Deleted ",se(n.deletedAt)]}),n.deletedByActor?e.jsxs("span",{children:["By ",n.deletedByActor]}):null,n.deletedSource?e.jsxs("span",{children:["Source ",n.deletedSource]}):null,n.deleteReason?e.jsxs("span",{children:["Reason: ",n.deleteReason]}):null]})]}),e.jsxs("div",{className:"flex flex-wrap items-start justify-end gap-2",children:[e.jsxs(y,{variant:"secondary",size:"sm",pending:_.isPending,pendingLabel:"Restoring",onClick:()=>void _.mutateAsync(n),children:[e.jsx(E,{className:"size-4"}),e.jsx("span",{children:"Restore"})]}),e.jsxs(y,{variant:"secondary",size:"sm",pending:w.isPending,pendingLabel:"Deleting",onClick:()=>void w.mutateAsync(n),children:[e.jsx(R,{className:"size-4"}),e.jsx("span",{children:"Delete forever"})]})]})]},`${n.entityType}:${n.entityId}`))})]},t)})})]})}export{pe as SettingsBinPage};
@@ -0,0 +1,5 @@
1
+ import{j as e,de as $e,bK as Qe,ce as Rr,d5 as Je,bn as ke,cb as Re,aN as Tr,dg as Pr,r as c,c2 as Dr,cX as $r,c7 as zr,aV as er}from"./vendor-Dnkkx2co.js";import{j as Fr,k as ee,i as Me}from"./state-vCcAT5Hq.js";import{F as q,I as re,c as k,B as M,aq as qr,C as We,j as Br,n as Ve,dW as Kr,dX as dr,dY as Wr,dZ as Vr,dg as ur,d_ as Qr,Q as rr,a9 as Hr,d$ as Yr,e0 as Xr,e1 as Zr,e2 as Jr,e3 as es,e4 as rs,e5 as ss,e6 as as,e7 as ns,S as ts,E as hr,i as os,du as is,dv as ls,e8 as cs,e9 as ds,ea as us}from"./index-EqQsXoat.js";import{S as hs}from"./settings-section-nav-DP9o4peU.js";import{P as gs}from"./page-hero-ffKzgyW3.js";import{r as ps,b as ms,w as fs}from"./calendar-display-preferences-Cid-2RnL.js";import"./motion-Lt5B1XuE.js";import"./ui-C1iwpj2-.js";import"./forms-hB0SqEh-.js";import"./board-dIX6etHh.js";import"./graph-DDUZNRsO.js";const gr="/api/v1/calendar/oauth/microsoft/callback",vs=/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/,pr=1e3,He={google:{label:"Primary Google",serverUrl:""},apple:{label:"Primary Apple",serverUrl:"https://caldav.icloud.com"},microsoft:{label:"Primary Exchange Online",serverUrl:""},macos_local:{label:"Calendars On This Mac",serverUrl:"forge-macos-local://eventkit/"},caldav:{label:"Primary CalDAV",serverUrl:"https://caldav.example.com"}};function Ye(r){return{provider:r,label:He[r].label,serverUrl:He[r].serverUrl,username:"",password:"",selectedCalendarUrls:[],forgeCalendarUrl:null,createForgeCalendar:!1,sourceId:null,replaceConnectionIds:[]}}function ge(r,t){const i=t.trim();return i.length>0?i:He[r].label}function qe(r){return{clientId:r.clientId,tenantId:r.tenantId,redirectUri:r.redirectUri}}function Ge(r){return{clientId:r.storedClientId??"",clientSecret:r.storedClientSecret??""}}function xs(r){return r.replace(/\s*No GOOGLE_CLIENT_SECRET is used in this local PKCE flow\./gi,"").replace(/\s{2,}/g," ").trim()}function mr(){return["Google OAuth credentials are not set for this Forge install.","- Save a Google desktop-app client ID and client secret below for this Forge install.","- Or rely on the packaged or environment defaults for the Forge runtime."].join(`
2
+ `)}function fr(r,t){return[r,"- Open Forge from a local browser on the host running Forge.",`- Use one of these local addresses: ${t.join(", ")}.`].join(`
3
+ `)}function Sr(r){return{clientId:(r.clientId??"").trim(),clientSecret:(r.clientSecret??"").trim()}}function bs(r,t){return r.clientId.trim()===t.clientId.trim()&&r.clientSecret.trim()===t.clientSecret.trim()}function Cs(r){const t=Sr(r),i={},h=t.clientId.length>0,b=t.clientSecret.length>0;if(h!==b){const f="When overriding Google OAuth credentials, save the client ID and client secret together, or clear both to use the bundled defaults.";h||(i.clientId=f),b||(i.clientSecret=f)}return{normalized:t,issues:i,isValid:Object.keys(i).length===0}}function sr(r){return{clientId:r.clientId.trim(),tenantId:r.tenantId.trim()||"common",redirectUri:r.redirectUri.trim()}}function ws(r){const t=sr(r),i={};if(t.clientId?vs.test(t.clientId)||(i.clientId="Use the Microsoft app registration client ID GUID."):i.clientId="Microsoft client ID is required.",!t.redirectUri)i.redirectUri="Redirect URI is required.";else try{const h=new URL(t.redirectUri);h.protocol!=="http:"&&h.protocol!=="https:"?i.redirectUri="Redirect URI must use http or https.":h.pathname!==gr&&(i.redirectUri=`Redirect URI must end with ${gr}.`)}catch{i.redirectUri="Redirect URI must be a full URL."}return{normalized:t,issues:i,isValid:Object.keys(i).length===0}}function ys(r,t){return r.clientId.trim()===t.clientId.trim()&&r.tenantId.trim()===t.tenantId.trim()&&r.redirectUri.trim()===t.redirectUri.trim()}function ar(r){return r==="127.0.0.1"||r==="localhost"}function js(r){return r.endsWith(".ts.net")}function Ns(r){r.allowedOrigins.filter(h=>{try{return ar(new URL(h).hostname)}catch{return!1}});const t=(()=>{try{return new URL(r.redirectUri).hostname}catch{return""}})();let i="";try{i=new URL(r.currentOrigin).hostname}catch{i=""}return js(i)&&ar(t)?`Google sign-in has to start from a local browser on the host running Forge. Forge is currently open through Tailscale at ${r.currentOrigin}, but Google sends the callback to localhost on the device that opens the popup. On a phone or another computer, that callback goes to that device instead of the Forge host.`:r.isLocalOnly?"Google sign-in has to start from a local browser on the host running Forge. Google sends the callback to localhost, so if Forge is opened remotely, the callback goes to the other device instead of the Forge host.":`Google sign-in is only enabled from the configured Forge host for this deployment. Open Forge on ${r.appBaseUrl}. Current browser origin: ${r.currentOrigin}.`}const or="rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)]",Te="rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",vr="flex min-h-11 min-w-0 items-center overflow-hidden rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 text-sm text-[var(--ui-ink-faint)]",xr="inline-flex size-9 shrink-0 items-center justify-center rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)] transition hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]",pe="text-sm leading-6 text-[var(--ui-ink-soft)]",oe="font-medium text-[var(--ui-ink-strong)]",kr="bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)]",Pe="bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_74%,var(--ui-ink-strong)_26%)]",Fs="bg-[var(--ui-info-soft)] text-[color-mix(in_srgb,var(--info)_76%,var(--ui-ink-strong)_24%)]",Ss="rounded-[18px] border border-[var(--ui-info-soft)] bg-[var(--ui-info-soft)] px-4 py-3 text-sm leading-6 text-[var(--ui-ink-strong)]",Er="mt-4 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-3 text-sm leading-6 text-[var(--ui-ink-soft)]",ks="border-[color-mix(in_srgb,var(--primary)_34%,var(--ui-border-subtle)_66%)] bg-[var(--ui-accent-soft)] text-[var(--ui-ink-strong)]",Es="border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)] hover:bg-[var(--ui-surface-hover)]";function Is({value:r,setValue:t,macosStatus:i,macosDiscovery:h,requestMacosAccess:b,requestMacosAccessPending:f,checkMacosStatus:u,checkMacosStatusPending:A,runDiscovery:j,discoveryPending:v,applyMacosSource:E,activeGoogleSetup:s,googleRedirectOrigin:m,currentBrowserOrigin:L,googleClientIdEditing:g,setGoogleClientIdEditing:N,googleSettingsDraft:p,setGoogleSettingsDraft:I,savedGoogleSettingsDraft:_,googleValidation:G,hasUnsavedGoogleSettings:P,saveGoogleSettings:F,saveGoogleSettingsPending:U,googleSetupMessage:S,setGoogleSetupMessage:W,startGoogleFlow:C,googlePairingAllowedFromCurrentOrigin:ie,googleSession:B,microsoftSettingsDraft:H,setMicrosoftSettingsDraft:V,microsoftValidation:se,hasUnsavedMicrosoftSettings:we,saveMicrosoftSettings:ae,saveMicrosoftSettingsPending:Y,testMicrosoftSettings:O,testMicrosoftSettingsPending:D,microsoftSetupMessage:le,setMicrosoftSetupMessage:R,startMicrosoftFlow:fe,microsoftSession:ve}){return e.jsxs("div",{className:"grid gap-4",children:[e.jsx(q,{label:"Connection label",description:"This is the readable label Forge shows in settings and the calendar health cards.",children:e.jsx(re,{value:r.label,onChange:X=>t({label:X.target.value}),placeholder:He[r.provider].label})}),r.provider==="macos_local"?e.jsx(Us,{value:r,setValue:t,macosStatus:i,macosDiscovery:h,requestMacosAccess:b,requestMacosAccessPending:f,checkMacosStatus:u,checkMacosStatusPending:A,runDiscovery:j,discoveryPending:v,applyMacosSource:E}):r.provider==="google"?e.jsx(As,{activeGoogleSetup:s,googleRedirectOrigin:m,currentBrowserOrigin:L,googleClientIdEditing:g,setGoogleClientIdEditing:N,googleSettingsDraft:p,setGoogleSettingsDraft:I,savedGoogleSettingsDraft:_,googleValidation:G,hasUnsavedGoogleSettings:P,saveGoogleSettings:F,saveGoogleSettingsPending:U,googleSetupMessage:S,setGoogleSetupMessage:W,startGoogleFlow:C,googlePairingAllowedFromCurrentOrigin:ie,googleSession:B}):r.provider==="microsoft"?e.jsx(Ls,{microsoftSettingsDraft:H,setMicrosoftSettingsDraft:V,microsoftValidation:se,hasUnsavedMicrosoftSettings:we,saveMicrosoftSettings:ae,saveMicrosoftSettingsPending:Y,testMicrosoftSettings:O,testMicrosoftSettingsPending:D,microsoftSetupMessage:le,setMicrosoftSetupMessage:R,startMicrosoftFlow:fe,microsoftSession:ve}):e.jsx(_s,{value:r,setValue:t})]})}function Us({value:r,setValue:t,macosStatus:i,macosDiscovery:h,requestMacosAccess:b,requestMacosAccessPending:f,checkMacosStatus:u,checkMacosStatusPending:A,runDiscovery:j,discoveryPending:v,applyMacosSource:E}){var s;return e.jsx("div",{className:"grid gap-4",children:e.jsxs("div",{className:`${or} p-5`,children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:oe,children:"macOS Calendar access"}),e.jsx("p",{className:`mt-2 max-w-2xl ${pe}`,children:"Forge uses EventKit to read and write the calendars already configured in Calendar.app on this Mac. Grant Calendar full access, then discover the available account sources."})]}),e.jsx(k,{className:i==="full_access"?Pe:kr,children:i==="full_access"?"Full access":i.replaceAll("_"," ")})]}),e.jsxs("div",{className:"mt-4 flex flex-wrap items-center gap-3",children:[e.jsxs(M,{type:"button",onClick:b,pending:f,pendingLabel:"Waiting for macOS",children:[e.jsx($e,{className:"size-4"}),"Request Calendar access"]}),e.jsxs(M,{type:"button",variant:"secondary",onClick:u,pending:A,pendingLabel:"Checking",children:[e.jsx(Qe,{className:"size-4"}),"Check access"]}),e.jsxs(M,{type:"button",onClick:j,disabled:i!=="full_access",pending:v,pendingLabel:"Discovering",children:[e.jsx(Qe,{className:"size-4"}),"Discover host calendars"]})]}),(s=h==null?void 0:h.sources)!=null&&s.length?e.jsxs("div",{className:"mt-5 grid gap-3",children:[e.jsx("div",{className:"text-sm font-medium text-[var(--ui-ink-strong)]",children:"Host calendar sources"}),h.sources.map(m=>{const L=r.sourceId===m.sourceId;return e.jsxs("button",{type:"button",className:`rounded-[20px] border px-4 py-3 text-left transition ${L?ks:Es}`,onClick:()=>{t({sourceId:m.sourceId}),E({provider:"macos_local",accountLabel:m.accountLabel,serverUrl:r.serverUrl,principalUrl:null,homeUrl:null,calendars:m.calendars})},children:[e.jsx("div",{className:"font-medium",children:m.accountLabel||m.sourceTitle}),e.jsxs("div",{className:"mt-1 text-sm text-[var(--ui-ink-soft)]",children:[m.sourceType," · ",m.calendars.length," calendars"]})]},m.sourceId)})]}):null]})})}function As({activeGoogleSetup:r,googleRedirectOrigin:t,currentBrowserOrigin:i,googleClientIdEditing:h,setGoogleClientIdEditing:b,googleSettingsDraft:f,setGoogleSettingsDraft:u,savedGoogleSettingsDraft:A,googleValidation:j,hasUnsavedGoogleSettings:v,saveGoogleSettings:E,saveGoogleSettingsPending:s,googleSetupMessage:m,setGoogleSetupMessage:L,startGoogleFlow:g,googlePairingAllowedFromCurrentOrigin:N,googleSession:p}){const I=!!(r.storedClientId||r.storedClientSecret);return e.jsx("div",{className:"grid gap-4",children:e.jsxs("div",{className:`${or} p-5`,children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:oe,children:"How Google sign-in works"}),e.jsx("p",{className:`mt-2 max-w-2xl ${pe}`,children:"Start the popup from the host running Forge. Google returns to Forge on localhost, Forge completes the PKCE exchange on the backend, then Forge discovers the calendars for that account."})]}),e.jsx(k,{className:Pe,children:"Auth code + PKCE"})]}),e.jsxs("div",{className:`mt-4 ${Te} px-4 py-3 ${pe}`,children:[e.jsxs("div",{children:["Forge runtime:"," ",e.jsx("span",{className:oe,children:r.appBaseUrl})]}),e.jsxs("div",{className:"break-all",children:["Redirect URI:"," ",e.jsx("span",{className:oe,children:r.redirectUri})]}),e.jsxs("div",{className:"break-all",children:["Redirect origin:"," ",e.jsx("span",{className:oe,children:t||"Unavailable"})]}),e.jsxs("div",{children:["Allowed local browser origins:"," ",e.jsx("span",{className:oe,children:r.allowedOrigins.join(", ")})]}),e.jsxs("div",{className:"break-all",children:["Detected browser origin:"," ",e.jsx("span",{className:oe,children:i||"Unavailable"})]})]}),e.jsx("div",{className:`mt-4 ${Te} p-4`,children:h?e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:oe,children:"Google OAuth override"}),e.jsx("p",{className:`mt-2 max-w-2xl ${pe}`,children:"Save both the client ID and client secret only when this Forge install should use a different Google desktop OAuth app than the packaged default."})]}),e.jsx("button",{type:"button","aria-label":"Done editing Google OAuth client",className:xr,onClick:()=>{L(null),u(Ge(r)),b(!1)},children:e.jsx(Je,{className:"size-4"})})]}),e.jsxs(q,{label:"Client ID",description:"Override the packaged Google desktop-app client ID for this Forge install.",children:[e.jsx(re,{"aria-label":"Client ID",value:f.clientId,onChange:_=>{L(null),u({...f,clientId:_.target.value})},placeholder:"1234567890-abcdef.apps.googleusercontent.com"}),j.issues.clientId?e.jsx("p",{className:"mt-2 text-sm text-[var(--danger)]",children:j.issues.clientId}):null]}),e.jsxs(q,{label:"Client secret",description:"Override the packaged Google desktop-app client secret for this Forge install.",children:[e.jsx(re,{"aria-label":"Client secret",value:f.clientSecret,onChange:_=>{L(null),u({...f,clientSecret:_.target.value})},placeholder:"GOCSPX-..."}),j.issues.clientSecret?e.jsx("p",{className:"mt-2 text-sm text-[var(--danger)]",children:j.issues.clientSecret}):null]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx(M,{type:"button",onClick:()=>E(f),disabled:!v||!j.isValid,pending:s,pendingLabel:"Saving",children:"Save Google OAuth override"}),e.jsx(M,{type:"button",variant:"secondary",onClick:()=>{L(null),u({clientId:"",clientSecret:""})},disabled:s||!A.clientId&&!A.clientSecret&&f.clientId.length===0&&f.clientSecret.length===0,children:A.clientId||A.clientSecret?"Clear override":"Use packaged default"})]})]}):e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:"grid min-w-0 gap-3",children:e.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-3",children:[e.jsx("div",{className:"min-w-0 flex-1",children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"truncate font-medium text-[var(--ui-ink-strong)]",children:"Google OAuth client"}),e.jsx(k,{className:I?Pe:kr,children:I?"Stored on server":"Using packaged default"}),e.jsx(qr,{content:"Forge ships with a packaged Google desktop OAuth client by default. Save both fields only when this Forge install should use a different client ID and client secret pair.",label:"Explain Google OAuth client",className:"shrink-0"})]})}),e.jsx("button",{type:"button","aria-label":"Edit Google OAuth client",className:xr,onClick:()=>{L(null),b(!0)},children:e.jsx(Rr,{className:"size-4"})})]})}),e.jsx(q,{label:"Effective client ID",description:"This is the Google desktop-app client ID Forge will use right now.",children:e.jsx("div",{className:vr,children:e.jsx("span",{className:"block min-w-0 truncate",title:r.clientId,children:r.clientId})})}),e.jsx(q,{label:"Effective client secret",description:"Forge uses this value on the local backend when exchanging and refreshing Google tokens.",children:e.jsx("div",{className:vr,children:e.jsx("span",{className:"block min-w-0 truncate",title:r.clientSecret||"",children:r.clientSecret||""})})})]})}),m?e.jsx("div",{className:Er,children:m}):null,e.jsx("div",{className:`mt-4 ${Ss}`,children:"If you open Forge on a phone or another remote route, Google redirects to localhost on that other device instead of back to Forge."}),e.jsxs("div",{className:"mt-4 flex flex-wrap items-center gap-3",children:[e.jsxs(M,{type:"button",onClick:g,disabled:!r.isReadyForPairing||!N||v||s,pending:(p==null?void 0:p.status)==="pending",pendingLabel:"Waiting for Google",children:[e.jsx(ke,{className:"size-4"}),(p==null?void 0:p.status)==="authorized"?"Sign in again":"Sign in with Google"]}),p!=null&&p.accountLabel?e.jsxs(k,{className:Pe,children:[e.jsx(Je,{className:"mr-1 size-3.5"}),p.accountLabel]}):null]})]})})}function Ls({microsoftSettingsDraft:r,setMicrosoftSettingsDraft:t,microsoftValidation:i,hasUnsavedMicrosoftSettings:h,saveMicrosoftSettings:b,saveMicrosoftSettingsPending:f,testMicrosoftSettings:u,testMicrosoftSettingsPending:A,microsoftSetupMessage:j,setMicrosoftSetupMessage:v,startMicrosoftFlow:E,microsoftSession:s}){return e.jsx("div",{className:"grid gap-4",children:e.jsxs("div",{className:`${or} p-5`,children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:oe,children:"Guided Microsoft setup"}),e.jsx("p",{className:`mt-2 max-w-2xl ${pe}`,children:"Save the Microsoft app registration details for this Forge instance here, optionally test them, then continue into the Microsoft sign-in popup. Exchange Online stays read-only for now."})]}),e.jsx(k,{className:Fs,children:"Read only"})]}),e.jsxs("div",{className:"mt-4 grid gap-4 md:grid-cols-2",children:[e.jsxs(q,{label:"Microsoft client ID",description:"Use the Application (client) ID from the Microsoft Entra app registration for this Forge instance.",children:[e.jsx(re,{value:r.clientId,onChange:m=>{v(null),t({...r,clientId:m.target.value})},placeholder:"00000000-0000-0000-0000-000000000000"}),i.issues.clientId?e.jsx("div",{className:"text-sm text-[var(--danger)]",children:i.issues.clientId}):null]}),e.jsx(q,{label:"Tenant / authority",description:"Use common unless you need a tenant-specific authority.",children:e.jsx(re,{value:r.tenantId,onChange:m=>{v(null),t({...r,tenantId:m.target.value})},placeholder:"common"})})]}),e.jsxs(q,{label:"Redirect URI",description:"Register this exact Forge callback URI in the Microsoft app registration.",children:[e.jsx(re,{value:r.redirectUri,onChange:m=>{v(null),t({...r,redirectUri:m.target.value})},placeholder:"http://127.0.0.1:4317/api/v1/calendar/oauth/microsoft/callback"}),i.issues.redirectUri?e.jsx("div",{className:"text-sm text-[var(--danger)]",children:i.issues.redirectUri}):null]}),e.jsx("div",{className:`mt-4 ${Te} px-4 py-3 ${pe}`,children:"Forge saves the client ID, tenant, and redirect URI for this local instance, then handles Microsoft sign-in in a popup."}),e.jsxs("div",{className:"mt-4 flex flex-wrap items-center gap-3",children:[e.jsx(M,{type:"button",onClick:()=>b(r),disabled:!i.isValid,pending:f,pendingLabel:"Saving",children:"Save Microsoft settings"}),e.jsx(M,{type:"button",variant:"secondary",onClick:()=>u(r),disabled:!i.isValid,pending:A,pendingLabel:"Testing",children:"Test Microsoft configuration"}),e.jsxs(M,{type:"button",onClick:E,disabled:!i.isValid||h||f,pending:(s==null?void 0:s.status)==="pending",pendingLabel:"Waiting for Microsoft",children:[e.jsx(ke,{className:"size-4"}),(s==null?void 0:s.status)==="authorized"?"Sign in again":"Sign in with Microsoft"]}),s!=null&&s.accountLabel?e.jsxs(k,{className:Pe,children:[e.jsx(Je,{className:"mr-1 size-3.5"}),s.accountLabel]}):null]}),e.jsxs("div",{className:"mt-4 grid gap-3 md:grid-cols-2",children:[e.jsx("div",{className:`${Te} px-4 py-3 ${pe}`,children:"Save before sign-in. The Microsoft popup always uses the latest saved client ID, tenant, and redirect URI."}),e.jsx("div",{className:`${Te} px-4 py-3 ${pe}`,children:"After sign-in, Forge will let you choose which Exchange Online calendars to mirror into the Calendar page."})]}),j?e.jsx("div",{className:Er,children:j}):null]})})}function _s({value:r,setValue:t}){return e.jsxs(e.Fragment,{children:[r.provider==="caldav"?e.jsx(q,{label:"CalDAV base URL",description:"Use the account-level CalDAV server URL, not an individual calendar collection URL.",children:e.jsx(re,{value:r.serverUrl,onChange:i=>t({serverUrl:i.target.value}),placeholder:"https://caldav.example.com"})}):null,r.provider==="apple"?e.jsx(q,{label:"Apple CalDAV base URL",children:e.jsx(re,{value:"https://caldav.icloud.com",disabled:!0})}):null,e.jsx(q,{label:"Account email or username",children:e.jsx(re,{value:r.username,onChange:i=>t({username:i.target.value}),placeholder:"operator@example.com"})}),e.jsx(q,{label:r.provider==="apple"?"App-specific password":"Password or app password",children:e.jsx(re,{type:"password",value:r.password,onChange:i=>t({password:i.target.value}),placeholder:"Password"})})]})}const br=[{title:"Before you connect anything",description:"Forge mirrors provider events into Forge. Writable providers can also publish work blocks plus owned timeboxes into one shared Forge write target, while Exchange Online stays read-only for now.",bullets:["Google uses a localhost Authorization Code + PKCE flow. Each user signs in with their own Google account on the same machine running Forge, while Forge stores that user's refresh token on the server for background sync.","Calendars On This Mac uses EventKit to access the calendars already configured in Calendar.app on the host machine, including iCloud, Google, Exchange, and other accounts the Mac is already syncing.","Apple Calendar starts from https://caldav.icloud.com and autodiscovers the real principal plus calendar collections for you.","Exchange Online uses Microsoft Graph with a guided local public-client Microsoft sign-in flow and mirrors the calendars you select into Forge.","Custom CalDAV uses one account-level base URL, then Forge discovers the writable calendars before you choose what to mirror.","Read-only .ics feeds are not enough for writable-provider flows because Forge needs write access for work blocks and task timeboxes."],icon:Re,links:[]},{title:"Calendars On This Mac setup",description:"Use this path when the Mac already has the needed accounts connected in Calendar.app and Forge should sync them through EventKit instead of reconnecting each provider manually.",bullets:["Open Forge on the same Mac whose Calendar.app already contains the accounts you want to mirror.","Choose Calendars On This Mac in Forge settings.","Grant Calendar full access when macOS prompts for it, or re-enable it later in System Settings -> Privacy & Security -> Calendars.","Let Forge discover the available host calendar sources and pick the source account you want to sync.","Choose which calendars Forge should mirror. If Forge already has a write target on another writable connection, this new connection can reuse it instead of creating another Forge calendar.","If Forge already syncs the same account through Google, Apple, CalDAV, or Microsoft, the macOS-local connection replaces the older remote one instead of keeping two visible copies."],icon:Re,links:[]},{title:"Google Calendar setup",description:"Use one Google Cloud desktop-app OAuth client for local Forge, register the exact localhost callback URI, and let Forge complete the Authorization Code + PKCE exchange on the backend.",bullets:["Open Google Cloud credentials and create or reuse one OAuth client for Forge as a Desktop app.","Enable the Calendar API for the same project.","Register Forge's exact callback URI. In local Forge, the default callback is http://127.0.0.1:4317/api/v1/calendar/oauth/google/callback.","Open Forge on localhost on the same machine that is running Forge. If Forge is opened remotely from a phone or a Tailscale route while the callback is localhost, Google will redirect to localhost on that device and the flow will fail.","The user signs in with their own Google account and grants Forge access. They do not create their own Google OAuth client during this step.","Forge will discover the calendars, let you choose which calendars to mirror, and create or reuse Forge as the write calendar."],icon:$e,links:[{label:"Google Cloud credentials",href:"https://console.cloud.google.com/apis/credentials"},{label:"Calendar API quickstart",href:"https://developers.google.com/workspace/calendar/api/quickstart"}]},{title:"Apple Calendar setup",description:"Apple does not require you to paste raw calendar collection URLs into Forge. Start with your Apple ID email, an app-specific password, and the iCloud CalDAV base URL.",bullets:["Create an Apple app-specific password for third-party calendar access.","Open Forge settings and choose Apple Calendar.","Enter the Apple ID email and the app-specific password. Forge uses https://caldav.icloud.com for autodiscovery.","After discovery, choose which calendars Forge should mirror.","If a calendar named Forge already exists, Forge will preselect it as the write calendar. Otherwise you can ask Forge to create it for you."],icon:Tr,links:[{label:"Apple app-specific passwords",href:"https://support.apple.com/en-us/102654"},{label:"Use iCloud Calendar with third-party apps",href:"https://support.apple.com/guide/icloud/set-up-calendar-mmfc0f2442/icloud"}]},{title:"Exchange Online setup",description:"Use Microsoft Graph for Microsoft 365 or Exchange Online calendars. In self-hosted local Forge, the user first saves a Microsoft public client ID, tenant, and redirect URI in Settings -> Calendar, then completes a guided local sign-in flow with PKCE. The connection is still read-only in Forge today.",bullets:["Open Microsoft Entra App registrations and create or reuse an app for this local Forge instance.","Choose a supported account type that matches your self-hosted use case. Use a broad multi-account setup when Forge should work with normal personal or organizational Microsoft sign-ins.","Enable mobile and desktop or public client flow support for that app registration.","Add Forge's callback URI to the redirect URI list. The default local callback is http://127.0.0.1:4317/api/v1/calendar/oauth/microsoft/callback.","Add delegated Graph permissions for User.Read and Calendars.Read, then grant or request consent as required by the tenant.","Open Forge Settings -> Calendar and save the Microsoft client ID, tenant value, and redirect URI in the Exchange Online setup card.","Use Test Microsoft configuration to confirm Forge can launch the local sign-in flow.","Click Sign in with Microsoft, complete the popup flow, and then choose which Exchange Online calendars Forge should mirror."],icon:$e,links:[{label:"Microsoft Graph permissions",href:"https://learn.microsoft.com/en-us/graph/permissions-reference"},{label:"Microsoft identity platform",href:"https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-auth-code-flow"},{label:"Microsoft Graph calendar overview",href:"https://learn.microsoft.com/en-us/graph/api/resources/calendar?view=graph-rest-1.0"}]},{title:"Custom CalDAV setup",description:"Use this path for Nextcloud, Fastmail, Baikal, DAViCal, and other CalDAV-compatible providers that expose an account-level base URL.",bullets:["Confirm the provider supports CalDAV, not just an .ics export.","Gather the account-level CalDAV server URL, username, and password or app password.","Open Forge settings and choose Custom CalDAV.","Forge discovers the available calendars from that base URL before anything is saved.","Choose which calendars to mirror and either select an existing Forge calendar or let Forge create one automatically."],icon:Re,links:[]}];function Ms(r){if(!r)return br;const t=r==="google"?"Google Calendar setup":r==="macos_local"?"Calendars On This Mac setup":r==="apple"?"Apple Calendar setup":r==="microsoft"?"Exchange Online setup":"Custom CalDAV setup";return br.filter(i=>i.title==="Before you connect anything"||i.title===t)}function Os({section:r,compact:t}){const i=r.icon;return e.jsxs(We,{className:t?"grid gap-3 rounded-[24px] border border-[var(--ui-border-subtle)] !bg-[var(--ui-surface-1)] p-4":"grid gap-4 rounded-[28px] border border-[var(--ui-border-subtle)] !bg-[var(--ui-surface-1)]",children:[e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"rounded-[18px] bg-[var(--primary)]/14 p-3 text-[var(--primary)]",children:e.jsx(i,{className:t?"size-4":"size-5"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:t?"font-medium text-[var(--ui-ink-strong)]":"font-display text-[1.15rem] text-[var(--ui-ink-strong)]",children:r.title}),e.jsx("p",{className:t?"mt-1.5 text-sm leading-6 text-[var(--ui-ink-soft)]":"mt-2 max-w-3xl text-sm leading-6 text-[var(--ui-ink-soft)]",children:r.description})]})]}),e.jsx("div",{className:t?"grid gap-1.5":"grid gap-2",children:r.bullets.map(h=>e.jsx("div",{className:t?"rounded-[16px] bg-[var(--ui-surface-2)] px-3 py-2.5 text-sm leading-6 text-[var(--ui-ink-medium)]":"rounded-[18px] bg-[var(--ui-surface-2)] px-4 py-3 text-sm leading-6 text-[var(--ui-ink-medium)]",children:h},h))}),r.links.length>0?e.jsx("div",{className:"flex flex-wrap gap-2",children:r.links.map(h=>e.jsxs("a",{href:h.href,target:"_blank",rel:"noreferrer",className:"inline-flex min-h-10 items-center gap-2 rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-3 py-2 text-sm text-[var(--ui-ink-medium)] transition hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]",children:[e.jsx(ke,{className:"size-3.5"}),h.label]},h.href))}):null]})}function Gs({provider:r,compact:t=!1}){const i=Ms(r);return e.jsx("div",{className:"grid gap-4",children:i.map(h=>e.jsx(Os,{section:h,compact:t},h.title))})}const Se="rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",nr="rounded-[24px] border border-dashed border-[var(--ui-border-strong)] bg-[var(--ui-surface-1)]",Rs="rounded-[26px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)]",Cr="rounded-[20px] bg-[var(--ui-surface-2)] px-4 py-3 text-sm text-[var(--ui-ink-soft)]",Ts="text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",me="text-sm leading-6 text-[var(--ui-ink-soft)]",K="font-medium text-[var(--ui-ink-strong)]",De="bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)]",Ps="bg-[var(--ui-info-soft)] text-[color-mix(in_srgb,var(--info)_76%,var(--ui-ink-strong)_24%)]",Ds="rounded-[20px] border border-[var(--ui-warning-soft)] bg-[var(--ui-warning-soft)] px-4 py-3 text-sm leading-6 text-[var(--ui-ink-strong)]",$s="rounded-[24px] border border-[var(--ui-info-soft)] bg-[var(--ui-info-soft)] p-4 text-sm leading-6 text-[var(--ui-ink-strong)]",zs="rounded-[24px] border border-[var(--ui-success-soft)] bg-[var(--ui-success-soft)] p-4 text-sm leading-6 text-[var(--ui-ink-strong)]",qs="border border-[color-mix(in_srgb,var(--primary)_34%,var(--ui-border-subtle)_66%)] bg-[var(--ui-accent-soft)] text-[var(--primary)]",Ir="border border-[var(--ui-success-soft)] bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_74%,var(--ui-ink-strong)_26%)]",tr="border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)] hover:bg-[var(--ui-surface-hover)]";function Bs({value:r,onProviderChange:t}){return e.jsxs("div",{className:"grid gap-5",children:[e.jsx(q,{label:"Provider",description:"Each setup path is guided. Forge discovers calendars before anything is saved.",children:e.jsx(Br,{value:r.provider,onChange:i=>t(i),options:[{value:"google",label:"Google Calendar",description:"Use Google sign-in with Authorization Code + PKCE, let Forge exchange the code on the backend, and store a per-user refresh token server-side."},{value:"apple",label:"Apple Calendar",description:"Start from https://caldav.icloud.com and autodiscover calendars with your app password."},{value:"microsoft",label:"Exchange Online",description:"Save the Microsoft app registration fields in Settings, then sign in with Microsoft and mirror selected Exchange Online calendars in read-only mode."},{value:"macos_local",label:"Calendars On This Mac",description:"Use EventKit to access the calendars already configured in Calendar.app on this host machine and avoid reconnecting those same accounts manually."},{value:"caldav",label:"Custom CalDAV",description:"Use a CalDAV base URL for Nextcloud, Fastmail, Baikal, and other compatible providers."}]})}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsxs("div",{className:`${Se} p-4`,children:[e.jsxs("div",{className:"flex items-center gap-3 text-[var(--ui-ink-strong)]",children:[e.jsx(Pr,{className:"size-4 text-[var(--primary)]"}),e.jsx("div",{className:"font-medium",children:"Dedicated write calendar"})]}),e.jsx("p",{className:`mt-3 ${me}`,children:r.provider==="microsoft"?"Exchange Online is read-only for now. Forge mirrors selected calendars into Forge, but it does not publish work blocks or owned timeboxes back to Microsoft.":e.jsxs(e.Fragment,{children:["Forge writes work blocks and owned timeboxes into a dedicated calendar named ",e.jsx("span",{className:K,children:"Forge"}),"."]})})]}),e.jsxs("div",{className:`${Se} p-4`,children:[e.jsxs("div",{className:"flex items-center gap-3 text-[var(--ui-ink-strong)]",children:[e.jsx($e,{className:"size-4 text-[var(--primary)]"}),e.jsx("div",{className:"font-medium",children:"Discovery first"})]}),e.jsx("p",{className:`mt-3 ${me}`,children:r.provider==="google"?"Forge opens a Google sign-in popup, exchanges the authorization code on the backend, stores a per-user refresh token, and then discovers the writable calendars for that account.":r.provider==="macos_local"?"Forge asks macOS for Calendar access, discovers the host calendars grouped by account source, and replaces overlapping remote connections instead of keeping two copies.":r.provider==="microsoft"?"Forge starts a Microsoft sign-in popup, then discovers the calendars available to that account before you choose what to mirror.":"Forge discovers the actual calendar collections before you choose which ones to mirror and which one should receive owned timeboxes."})]})]}),e.jsxs("div",{className:`${Se} p-4`,children:[e.jsx("div",{className:Ts,children:"Setup guide"}),e.jsx("p",{className:`mt-2 ${me}`,children:"These are the exact setup steps for the selected provider. They stay inside this guided flow so Settings can stay focused on connection health and actions."}),e.jsx("div",{className:"mt-4",children:e.jsx(Gs,{provider:r.provider,compact:!0})})]})]})}function Ks({value:r,setValue:t,discovery:i,startGoogleFlow:h,startMicrosoftFlow:b,activeGoogleSetup:f,googlePairingAllowedFromCurrentOrigin:u,googleSession:A,microsoftValidation:j,hasUnsavedMicrosoftSettings:v,saveMicrosoftSettingsPending:E,microsoftSession:s,discoveryPending:m,runDiscovery:L,macosStatus:g,sharedForgeWriteTargetLabel:N}){return e.jsxs("div",{className:"grid gap-4",children:[e.jsx(Ws,{value:r,discovery:i,startGoogleFlow:h,startMicrosoftFlow:b,activeGoogleSetup:f,googlePairingAllowedFromCurrentOrigin:u,googleSession:A,microsoftValidation:j,hasUnsavedMicrosoftSettings:v,saveMicrosoftSettingsPending:E,microsoftSession:s,discoveryPending:m,runDiscovery:L,macosStatus:g}),i?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`${Se} p-4 ${me}`,children:[r.provider==="macos_local"?"Discovered through the host calendar store":"Discovered through"," ",e.jsx("span",{className:K,children:i.serverUrl}),i.homeUrl?e.jsxs(e.Fragment,{children:[" ","· home set"," ",e.jsx("span",{className:K,children:i.homeUrl})]}):null]}),r.provider!=="microsoft"&&N?e.jsxs("div",{className:zs,children:["Forge already writes work blocks and owned timeboxes through"," ",e.jsx("span",{className:K,children:N}),". This connection only needs a mirror selection."]}):null,e.jsx("div",{className:"grid gap-3",children:i.calendars.map(p=>{const I=r.selectedCalendarUrls.includes(p.url),_=r.forgeCalendarUrl===p.url;return e.jsxs("div",{className:`${Se} p-4`,children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:K,children:Ve(p)}),e.jsxs("div",{className:"mt-1 break-all text-sm text-[var(--ui-ink-soft)]",children:[p.timezone||"No timezone exposed"," ·"," ",p.url]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[p.isForgeCandidate?e.jsx(k,{className:"bg-[var(--primary)]/14 text-[var(--primary)]",children:"Forge match"}):null,p.isPrimary?e.jsx(k,{className:De,children:"Primary"}):null]})]}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",onClick:()=>t({selectedCalendarUrls:I?r.selectedCalendarUrls.filter(G=>G!==p.url):[...r.selectedCalendarUrls,p.url]}),className:`rounded-full px-3 py-2 text-sm transition ${I?qs:tr}`,children:I?"Mirrored":"Mirror into Forge"}),r.provider!=="microsoft"&&!N?e.jsx("button",{type:"button",onClick:()=>t({forgeCalendarUrl:p.url,createForgeCalendar:!1}),className:`rounded-full px-3 py-2 text-sm transition ${_?Ir:tr}`,children:_?"Forge writes here":"Use for Forge writes"}):e.jsx(k,{className:r.provider==="microsoft"?Ps:De,children:r.provider==="microsoft"?"Read only":"Shared target elsewhere"})]})]},p.url)})}),e.jsx(Vs,{value:r,setValue:t,sharedForgeWriteTargetLabel:N})]}):e.jsx(Qs,{value:r})]})}function Ws({value:r,discovery:t,startGoogleFlow:i,startMicrosoftFlow:h,activeGoogleSetup:b,googlePairingAllowedFromCurrentOrigin:f,googleSession:u,microsoftValidation:A,hasUnsavedMicrosoftSettings:j,saveMicrosoftSettingsPending:v,microsoftSession:E,discoveryPending:s,runDiscovery:m,macosStatus:L}){return r.provider==="google"?e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs(M,{type:"button",onClick:i,disabled:!b.isReadyForPairing||!f,pending:(u==null?void 0:u.status)==="pending",pendingLabel:"Waiting for Google",children:[e.jsx(ke,{className:"size-4"}),(u==null?void 0:u.status)==="authorized"?"Reconnect Google":"Sign in with Google"]}),t?e.jsxs(k,{className:De,children:[t.calendars.length," discovered"]}):null]}):r.provider==="microsoft"?e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs(M,{type:"button",onClick:h,disabled:!A.isValid||j||v,pending:(E==null?void 0:E.status)==="pending",pendingLabel:"Waiting for Microsoft",children:[e.jsx(ke,{className:"size-4"}),(E==null?void 0:E.status)==="authorized"?"Reconnect Microsoft":"Sign in with Microsoft"]}),t?e.jsxs(k,{className:De,children:[t.calendars.length," discovered"]}):null]}):e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs(M,{pending:s,pendingLabel:"Discovering",onClick:m,disabled:r.provider==="macos_local"&&L!=="full_access",children:[e.jsx(Qe,{className:"size-4"}),r.provider==="macos_local"?"Discover host calendars":"Discover calendars"]}),t?e.jsxs(k,{className:De,children:[t.calendars.length," discovered"]}):null]})}function Vs({value:r,setValue:t,sharedForgeWriteTargetLabel:i}){return r.provider!=="microsoft"&&!i?e.jsxs("div",{className:`${nr} p-4`,children:[e.jsx("div",{className:K,children:"No Forge calendar yet?"}),e.jsxs("p",{className:`mt-2 ${me}`,children:["If none of the discovered calendars should receive Forge-owned work blocks and timeboxes, let Forge create a dedicated calendar named"," ",e.jsx("span",{className:K,children:"Forge"}),"."]}),e.jsx("div",{className:"mt-4",children:e.jsx("button",{type:"button",onClick:()=>t({forgeCalendarUrl:null,createForgeCalendar:!r.createForgeCalendar}),className:`rounded-full px-3 py-2 text-sm transition ${r.createForgeCalendar?Ir:tr}`,children:r.createForgeCalendar?"Forge will create one":"Create a new Forge calendar"})})]}):r.provider==="microsoft"?e.jsx("div",{className:$s,children:"Exchange Online is connected through Microsoft Graph in read-only mode. Forge will mirror the calendars you select here, but it will keep work blocks and owned timeboxes local or publish them through another writable provider."}):e.jsxs("div",{className:`${nr} p-4 ${me}`,children:["Forge will keep"," ",e.jsx("span",{className:K,children:i})," ","as the canonical write target instead of creating another Forge calendar on this connection."]})}function Qs({value:r}){return e.jsx("div",{className:`${nr} px-4 py-6 ${me}`,children:r.provider==="google"?e.jsx(e.Fragment,{children:"Start the guided Google sign-in first. Forge will bring the discovered Google calendars back here as soon as the popup completes."}):r.provider==="microsoft"?e.jsx(e.Fragment,{children:"Start the guided Microsoft sign-in first. Forge will bring the discovered Exchange Online calendars back here as soon as the popup completes."}):e.jsx(e.Fragment,{children:r.provider==="macos_local"?"Grant macOS Calendar access and discover the host calendars first. If Calendar.app already aggregates Google, Exchange, or iCloud for this Mac, Forge will pick them up here without reconnecting those accounts.":e.jsxs(e.Fragment,{children:["Discover calendars after entering the credentials. For Apple, Forge starts from"," ",e.jsx("span",{className:K,children:"https://caldav.icloud.com"})," ","and resolves the principal plus calendar home automatically."]})})})}function Hs({value:r,macosDiscovery:t,existingConnections:i,sharedForgeWriteTargetLabel:h}){var b,f;return e.jsxs("div",{className:"grid gap-4",children:[r.provider==="macos_local"&&r.sourceId?e.jsxs("div",{className:`${Se} px-4 py-3 ${me}`,children:["Selected host source:"," ",e.jsx("span",{className:K,children:((b=t==null?void 0:t.sources.find(u=>u.sourceId===r.sourceId))==null?void 0:b.accountLabel)??((f=t==null?void 0:t.sources.find(u=>u.sourceId===r.sourceId))==null?void 0:f.sourceTitle)??r.sourceId})]}):null,e.jsxs("div",{className:`${Rs} p-5`,children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"rounded-[18px] bg-[var(--primary)]/14 p-3 text-[var(--primary)]",children:e.jsx(Re,{className:"size-4"})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-display text-xl text-[var(--ui-ink-strong)]",children:ge(r.provider,r.label)}),e.jsx("div",{className:"mt-1 text-sm text-[var(--ui-ink-soft)]",children:r.provider==="google"?"Google Calendar":r.provider==="macos_local"?"Calendars On This Mac":r.provider==="apple"?"Apple Calendar":r.provider==="microsoft"?"Exchange Online":"Custom CalDAV"})]})]}),e.jsxs("div",{className:"mt-4 grid gap-3 md:grid-cols-2",children:[e.jsxs("div",{className:Cr,children:["Mirrored calendars:"," ",e.jsx("span",{className:K,children:r.selectedCalendarUrls.length})]}),e.jsxs("div",{className:Cr,children:["Forge writes:"," ",e.jsx("span",{className:K,children:r.provider==="microsoft"?"read only":r.forgeCalendarUrl?"existing calendar":r.createForgeCalendar?"new Forge calendar":h?`shared target via ${h}`:"not selected"})]})]}),r.replaceConnectionIds.length>0?e.jsxs("div",{className:`mt-4 ${Ds}`,children:["Forge will replace ",r.replaceConnectionIds.length," older overlapping connection",r.replaceConnectionIds.length===1?"":"s"," for this same calendar account so only one visible copy remains.",i.filter(u=>r.replaceConnectionIds.includes(u.id)).map(u=>u.label).join(", ")?` ${i.filter(u=>r.replaceConnectionIds.includes(u.id)).map(u=>u.label).join(", ")}.`:""]}):null]})]})}function Ys({open:r,onOpenChange:t,initialProvider:i="google",initialStepId:h,googleSetup:b,microsoftSetup:f,onCalendarSettingsChanged:u,existingConnections:A=[],onSubmit:j,pending:v=!1}){const E=Fr(),[s,m]=c.useState(()=>Ye(i)),[L,g]=c.useState(null),[N,p]=c.useState(null),[I,_]=c.useState("not_determined"),[G,P]=c.useState(null),[F,U]=c.useState(null),[S,W]=c.useState(null),[C,ie]=c.useState(b),[B,H]=c.useState(()=>Ge(b)),[V,se]=c.useState(()=>Ge(b)),[we,ae]=c.useState(!1),[Y,O]=c.useState(null),[D,le]=c.useState(f),[R,fe]=c.useState(()=>qe(f)),[ve,X]=c.useState(()=>qe(f)),[Ee,Q]=c.useState(null),T=c.useRef(null),ye=(a=[])=>{const o=new Set(a);return A.find(l=>{var y;return o.has(l.id)?!1:typeof((y=l.config)==null?void 0:y.forgeCalendarUrl)=="string"&&l.config.forgeCalendarUrl.trim().length>0})??null},$=c.useMemo(()=>s.provider==="microsoft"?null:ye(s.replaceConnectionIds),[s.provider,s.replaceConnectionIds,A]),Z=$?$.accountLabel&&$.accountLabel.trim().length>0?`${$.label} · ${$.accountLabel}`:$.label:null,Ie=a=>(E.setQueryData(["forge-settings"],a),a.settings),n=()=>{U(null),T.current=null},d=()=>{W(null),T.current=null},x=a=>{p(a);const o=a.calendars.filter(y=>y.selectedByDefault).map(y=>y.url),l=a.calendars.find(y=>y.isForgeCandidate);m(y=>{const he=ye(y.replaceConnectionIds);return{...y,selectedCalendarUrls:y.selectedCalendarUrls.length>0?y.selectedCalendarUrls.filter(be=>a.calendars.some(Ae=>Ae.url===be)):o,forgeCalendarUrl:y.provider==="microsoft"||he?null:(l==null?void 0:l.url)??y.forgeCalendarUrl??null,createForgeCalendar:y.provider==="microsoft"||he?!1:y.createForgeCalendar&&!l}}),g(null)};c.useEffect(()=>{var a;if(!r){(a=T.current)==null||a.close(),T.current=null;return}g(null),p(null),m(Ye(i)),n(),d(),P(null),_("not_determined"),ae(!1),O(null),Q(null)},[i,r]),c.useEffect(()=>{!r||s.provider!=="macos_local"||z.mutateAsync()},[s.provider,r]),c.useEffect(()=>{if(!r||!N||s.provider==="microsoft"||$||s.forgeCalendarUrl||s.createForgeCalendar)return;const a=N.calendars.find(o=>o.isForgeCandidate);a&&m(o=>o.provider==="microsoft"||o.forgeCalendarUrl||o.createForgeCalendar||ye(o.replaceConnectionIds)?o:{...o,forgeCalendarUrl:a.url})},[N,s.createForgeCalendar,s.forgeCalendarUrl,s.provider,r,$]),c.useEffect(()=>{if(!r)return;ie(b);const a=Ge(b);H(a),se(a),ae(!1),O(null)},[b,r]),c.useEffect(()=>{if(!r)return;le(f);const a=qe(f);fe(a),X(a),Q(null)},[f,r]),c.useEffect(()=>{if(!r||!F||F.status!=="pending")return;const a=new URL(C.redirectUri).origin;let o=!1;const l=()=>{o||(o=!0,_r(F.sessionId).finally(()=>{o=!1}))},y=Ce=>{var Le,_e;Ce.origin===a&&(((Le=Ce.data)==null?void 0:Le.type)!=="forge:google-calendar-auth"||((_e=Ce.data)==null?void 0:_e.sessionId)!==F.sessionId||l())},he=()=>{l()},be=()=>{document.visibilityState==="visible"&&l()},Ae=window.setInterval(l,pr);return window.addEventListener("message",y),window.addEventListener("focus",he),document.addEventListener("visibilitychange",be),()=>{window.removeEventListener("message",y),window.removeEventListener("focus",he),document.removeEventListener("visibilitychange",be),window.clearInterval(Ae)}},[C.redirectUri,F,r]),c.useEffect(()=>{if(!r||!S||S.status!=="pending")return;const a=new URL(D.redirectUri).origin;let o=!1;const l=()=>{o||(o=!0,Mr(S.sessionId).finally(()=>{o=!1}))},y=Ce=>{var Le,_e;Ce.origin===a&&(((Le=Ce.data)==null?void 0:Le.type)!=="forge:microsoft-calendar-auth"||((_e=Ce.data)==null?void 0:_e.sessionId)!==S.sessionId||l())},he=()=>{l()},be=()=>{document.visibilityState==="visible"&&l()},Ae=window.setInterval(l,pr);return window.addEventListener("message",y),window.addEventListener("focus",he),document.addEventListener("visibilitychange",be),()=>{window.removeEventListener("message",y),window.removeEventListener("focus",he),document.removeEventListener("visibilitychange",be),window.clearInterval(Ae)}},[D.redirectUri,S,r]);const w=ee({mutationFn:()=>s.provider==="macos_local"?Kr().then(({discovery:a})=>{P(a),_(a.status);const o=a.sources.find(l=>l.sourceId===s.sourceId)??a.sources[0]??null;return o&&(x({provider:"macos_local",accountLabel:o.accountLabel,serverUrl:s.serverUrl,principalUrl:null,homeUrl:null,calendars:o.calendars}),m(l=>({...l,sourceId:o.sourceId}))),{discovery:null}}):s.provider==="apple"?dr({provider:"apple",username:s.username,password:s.password}):dr({provider:"caldav",serverUrl:s.serverUrl,username:s.username,password:s.password}),onSuccess:({discovery:a})=>{a&&x(a)},onError:a=>{p(null),g(a instanceof Error?a.message:"Forge could not discover calendars with these credentials.")}}),z=ee({mutationFn:Wr,onSuccess:({status:a})=>{_(a),a!=="full_access"&&(P(null),p(null))}}),ne=ee({mutationFn:Vr,onSuccess:({granted:a,status:o,message:l})=>{if(_(o),a){g(null);return}g(l??"Forge could not obtain Calendar access from macOS yet. Open System Settings > Privacy & Security > Calendars, allow Forge, then return here and click Check access.")},onError:a=>{g(a instanceof Error?a.message:"Forge could not request Calendar access from macOS.")}});c.useEffect(()=>{!r||s.provider!=="macos_local"||I!=="full_access"||G!==null||w.isPending||w.mutateAsync()},[w,s.provider,G,I,r]);const ce=ee({mutationFn:async a=>{const o=sr(a),l=await ur({calendarProviders:{microsoft:o}});return{normalized:o,settings:Ie(l)}},onSuccess:async({settings:a})=>{le(a.calendarProviders.microsoft);const o=qe(a.calendarProviders.microsoft);X(o),fe(o),Q("Microsoft settings saved. Start the guided Microsoft sign-in when you are ready."),u==null||u()},onError:a=>{Q(a instanceof Error?a.message:"Forge could not save the Microsoft settings.")}}),J=ee({mutationFn:async a=>{const o=Sr(a),l=await ur({calendarProviders:{google:o}});return{normalized:o,settings:Ie(l)}},onSuccess:async({normalized:a,settings:o})=>{ie(o.calendarProviders.google);const l=Ge(o.calendarProviders.google);se(l),H(l),ae(!1),O(a.clientId||a.clientSecret?"Google OAuth credentials saved on the Forge server for this install.":"Google OAuth override cleared. Forge will use the packaged or environment default again."),u==null||u()},onError:a=>{O(a instanceof Error?a.message:"Forge could not save the Google OAuth credentials.")}}),te=ee({mutationFn:a=>{const o=sr(a);return Qr(o)},onSuccess:({result:a})=>{Q(a.message)},onError:a=>{Q(a instanceof Error?a.message:"Forge could not validate the Microsoft configuration.")}}),de=c.useMemo(()=>ws(R),[R]),je=c.useMemo(()=>Cs(B),[B]),ue=!bs(B,V),Ne=!ys(R,ve),xe=typeof window>"u"?"":window.location.origin,ir=c.useMemo(()=>{try{return new URL(C.redirectUri).origin}catch{return""}},[C.redirectUri]),ze=xe.length>0&&C.allowedOrigins.includes(xe)&&(!C.isLocalOnly||ar(new URL(xe).hostname)),Ue=xe&&!ze?Ns({currentOrigin:xe,appBaseUrl:C.appBaseUrl,redirectUri:C.redirectUri,allowedOrigins:C.allowedOrigins,isLocalOnly:C.isLocalOnly}):null,Ur=C.isReadyForPairing?null:xs(C.setupMessage)||mr(),Ar=Ue?fr(Ue,C.allowedOrigins):null,Lr=a=>{if(L)return L;if(s.provider==="google"&&(a==="credentials"||a==="discovery")){if(ue)return"Save the Google OAuth credential change before starting sign-in.";const o=[Ar,Ur].filter(l=>!!l);if(o.length>0)return o.join(`
4
+
5
+ `)}if(s.provider==="microsoft"&&a==="credentials"){if(Ne)return"Save these Microsoft settings before starting sign-in.";if(!Ne&&!ve.clientId&&!Ee)return D.setupMessage}if(s.provider==="macos_local"&&(a==="credentials"||a==="discovery")&&I!=="full_access")return I==="unavailable"?"This provider is only available on macOS, because Forge uses EventKit to access the host machine's calendar store.":"Grant Calendar full access for Forge on this Mac before discovering host calendars."},_r=async(a,o)=>{try{const{session:l}=await Zr(a);if(U(l),l.status==="authorized"&&l.discovery){x(l.discovery),g(null);return}if(l.status==="error"||l.status==="expired"){g(l.error??"Google sign-in did not complete. Start the guided sign-in again.");return}o!=null&&o.afterPopupClose}catch(l){g(l instanceof Error?l.message:"Forge could not confirm the Google sign-in session.")}},Mr=async(a,o)=>{try{const{session:l}=await Jr(a);if(W(l),l.status==="authorized"&&l.discovery){x(l.discovery),g(null);return}if(l.status==="error"||l.status==="expired"){g(l.error??"Microsoft sign-in did not complete. Start the guided sign-in again.");return}o!=null&&o.afterPopupClose}catch(l){g(l instanceof Error?l.message:"Forge could not confirm the Microsoft sign-in session.")}},lr=async()=>{var a;try{if(Ue)throw new Error(fr(Ue,C.allowedOrigins));if(!C.isReadyForPairing)throw new Error(mr());g(null),p(null);const{session:o}=await Xr({label:ge("google",s.label),browserOrigin:xe||void 0});if(!o.authUrl)throw new Error("Forge could not prepare the Google sign-in URL.");if(U(o),(a=T.current)==null||a.close(),T.current=window.open(o.authUrl,"forge-google-calendar-auth","popup=yes,width=520,height=720,resizable=yes,scrollbars=yes"),!T.current)throw new Error("The Google sign-in popup was blocked. Allow popups for Forge and try again.");T.current.focus()}catch(o){n(),g(o instanceof Error?o.message:"Forge could not start the Google sign-in flow.")}},cr=async()=>{var a;try{if(!de.isValid)throw new Error("Enter a valid Microsoft client ID and redirect URI before starting sign-in.");if(Ne)throw new Error("Save the Microsoft settings in this guided flow before starting sign-in.");if(ce.isPending)throw new Error("Wait for Forge to finish saving the Microsoft settings before starting sign-in.");g(null),Q(null),p(null);const{session:o}=await Yr({label:ge("microsoft",s.label)});if(!o.authUrl)throw new Error("Forge could not prepare the Microsoft sign-in URL.");if(W(o),(a=T.current)==null||a.close(),T.current=window.open(o.authUrl,"forge-microsoft-calendar-auth","popup=yes,width=520,height=720,resizable=yes,scrollbars=yes"),!T.current)throw new Error("The Microsoft sign-in popup was blocked. Allow popups for Forge and try again.");T.current.focus()}catch(o){d(),g(o instanceof Error?o.message:"Forge could not start the Microsoft sign-in flow.")}},Or=c.useMemo(()=>[{id:"provider",eyebrow:"Connection",title:"Choose the calendar provider Forge should connect to",description:"macOS local uses EventKit to access the calendars already configured on this Mac, Apple uses autodiscovery from caldav.icloud.com, Google uses a localhost Authorization Code + PKCE flow, Exchange Online uses guided Microsoft sign-in in read-only mode, and custom CalDAV stays available for everything else.",render:(a,o)=>e.jsx(Bs,{value:a,onProviderChange:l=>{p(null),P(null),g(null),Q(null),n(),d(),o(Ye(l))}})},{id:"credentials",eyebrow:"Credentials",title:s.provider==="google"?"Sign in with Google":s.provider==="macos_local"?"Use the calendars already configured on this Mac":s.provider==="apple"?"Provide the Apple account email and app-specific password":s.provider==="microsoft"?"Sign in with Microsoft":"Provide the custom CalDAV base URL and credentials",description:s.provider==="google"?"Review the Google desktop OAuth client, save a local override only if you need one, then start the popup and let Forge finish the PKCE exchange on the backend.":s.provider==="macos_local"?"Forge requests Calendar access through EventKit, discovers sources from Calendar.app, then lets you choose which host calendars to mirror and where Forge should write.":s.provider==="apple"?"Apple discovery starts from https://caldav.icloud.com, so you only need the Apple ID email and app password here.":s.provider==="microsoft"?"Forge uses the Microsoft client ID, tenant, and redirect URI saved in Settings -> Calendar, then runs a guided popup sign-in.":"Forge stores the secrets securely, then discovers the available calendars before anything is saved.",render:(a,o)=>e.jsx(Is,{value:a,setValue:o,macosStatus:I,macosDiscovery:G,requestMacosAccess:()=>void ne.mutateAsync(),requestMacosAccessPending:ne.isPending,checkMacosStatus:()=>void z.mutateAsync(),checkMacosStatusPending:z.isPending,runDiscovery:()=>void w.mutateAsync(),discoveryPending:w.isPending,applyMacosSource:x,activeGoogleSetup:C,googleRedirectOrigin:ir,currentBrowserOrigin:xe,googleClientIdEditing:we,setGoogleClientIdEditing:ae,googleSettingsDraft:B,setGoogleSettingsDraft:H,savedGoogleSettingsDraft:V,googleValidation:je,hasUnsavedGoogleSettings:ue,saveGoogleSettings:l=>void J.mutateAsync(l),saveGoogleSettingsPending:J.isPending,googleSetupMessage:Y,setGoogleSetupMessage:O,startGoogleFlow:()=>void lr(),googlePairingAllowedFromCurrentOrigin:ze,googleSession:F,microsoftSettingsDraft:R,setMicrosoftSettingsDraft:fe,microsoftValidation:de,hasUnsavedMicrosoftSettings:Ne,saveMicrosoftSettings:l=>void ce.mutateAsync(l),saveMicrosoftSettingsPending:ce.isPending,testMicrosoftSettings:l=>void te.mutateAsync(l),testMicrosoftSettingsPending:te.isPending,microsoftSetupMessage:Ee,setMicrosoftSetupMessage:Q,startMicrosoftFlow:()=>void cr(),microsoftSession:S})},{id:"discovery",eyebrow:"Discovery",title:"Discover the calendars and choose what Forge should sync",description:s.provider==="microsoft"?"Select the Exchange Online calendars Forge should mirror into the Calendar page. This connection stays read-only for now.":s.provider==="macos_local"?Z?`Select the host-machine calendars Forge should mirror into the Calendar page. Forge already writes work blocks and timeboxes through ${Z}.`:"Select the host-machine calendars Forge should mirror into the Calendar page, then choose the host calendar Forge should write into for work blocks and timeboxes.":Z?`Select the calendars Forge should mirror into the Calendar page. Forge already writes work blocks and timeboxes through ${Z}.`:"Select the calendars Forge should mirror into the Calendar page, then choose the calendar Forge should write into for work blocks and timeboxes.",render:(a,o)=>e.jsx(Ks,{value:a,setValue:o,discovery:N,startGoogleFlow:()=>void lr(),startMicrosoftFlow:()=>void cr(),activeGoogleSetup:C,googlePairingAllowedFromCurrentOrigin:ze,googleSession:F,microsoftValidation:de,hasUnsavedMicrosoftSettings:Ne,saveMicrosoftSettingsPending:ce.isPending,microsoftSession:S,discoveryPending:w.isPending,runDiscovery:()=>void w.mutateAsync(),macosStatus:I,sharedForgeWriteTargetLabel:Z})},{id:"review",eyebrow:"Review",title:"Confirm what Forge will mirror and where it will write",description:"This keeps the sync model explicit before the provider connection is saved.",render:a=>e.jsx(Hs,{value:a,macosDiscovery:G,existingConnections:A,sharedForgeWriteTargetLabel:Z})}],[N,w.isPending,s.provider,we,B,F,C.clientId,Y,C.allowedOrigins,C.appBaseUrl,C.isLocalOnly,C.isReadyForPairing,C.redirectUri,ir,ue,ze,Ue,Ne,R,D.setupMessage,Ee,de,J.isPending,ce.isPending,ve,te.isPending,D.isReadyForSignIn,D.redirectUri,G,S,$,Z]),Gr=s.provider==="macos_local"&&s.replaceConnectionIds.length>0?"Replace and connect":"Connect provider";return e.jsx(rr,{open:r,onOpenChange:t,eyebrow:"Calendar settings",title:"Connect a calendar provider",description:"Discover provider calendars first, choose which calendars Forge should mirror, and only choose a Forge write target when the runtime does not already have one.",value:s,onChange:a=>{m(a),N&&a.provider!==N.provider&&p(null),a.provider!=="macos_local"&&P(null)},draftPersistenceKey:"calendar.connection.new",steps:Or,submitLabel:Gr,pending:v,pendingLabel:"Connecting",error:L,resolveError:Lr,initialStepId:h,onSubmit:async()=>{try{if(g(null),!N){g("Discover the available calendars before saving the connection.");return}if(s.selectedCalendarUrls.length===0){g("Select at least one calendar to mirror into Forge.");return}if(s.provider!=="microsoft"&&!s.forgeCalendarUrl&&!s.createForgeCalendar&&!$){g("Choose the calendar Forge should write into, ask Forge to create one, or keep using the existing shared Forge write target.");return}if(s.provider==="google"){if(!(F!=null&&F.sessionId)||F.status!=="authorized"){g("Complete the Google sign-in flow before saving this connection.");return}await j({provider:"google",label:ge("google",s.label),authSessionId:F.sessionId,selectedCalendarUrls:s.selectedCalendarUrls,forgeCalendarUrl:s.forgeCalendarUrl,createForgeCalendar:s.createForgeCalendar})}else if(s.provider==="apple")await j({provider:"apple",label:ge("apple",s.label),username:s.username.trim(),password:s.password.trim(),selectedCalendarUrls:s.selectedCalendarUrls,forgeCalendarUrl:s.forgeCalendarUrl,createForgeCalendar:s.createForgeCalendar});else if(s.provider==="microsoft"){if(!(S!=null&&S.sessionId)||S.status!=="authorized"){g("Complete the Microsoft sign-in flow before saving this connection.");return}await j({provider:"microsoft",label:ge("microsoft",s.label),authSessionId:S.sessionId,selectedCalendarUrls:s.selectedCalendarUrls})}else if(s.provider==="macos_local"){if(!s.sourceId){g("Choose which host calendar source Forge should connect before saving.");return}await j({provider:"macos_local",label:ge("macos_local",s.label),sourceId:s.sourceId,selectedCalendarUrls:s.selectedCalendarUrls,forgeCalendarUrl:s.forgeCalendarUrl,createForgeCalendar:s.createForgeCalendar,replaceConnectionIds:s.replaceConnectionIds})}else await j({provider:"caldav",label:ge("caldav",s.label),serverUrl:s.serverUrl.trim(),username:s.username.trim(),password:s.password.trim(),selectedCalendarUrls:s.selectedCalendarUrls,forgeCalendarUrl:s.forgeCalendarUrl,createForgeCalendar:s.createForgeCalendar});t(!1)}catch(a){if(a instanceof Hr&&a.code==="calendar_connection_overlap"){const o=a.response,l=Array.isArray(o==null?void 0:o.overlappingConnectionIds)?o==null?void 0:o.overlappingConnectionIds.filter(y=>typeof y=="string"):[];m(y=>({...y,replaceConnectionIds:l})),g(`${a.message} Submit again to replace the older overlapping connection${l.length===1?"":"s"}.`);return}g(a instanceof Error?a.message:"Forge could not create this calendar connection.")}}})}const Xe="text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",Oe="text-sm leading-6 text-[var(--ui-ink-soft)]",Be="font-medium text-[var(--ui-ink-strong)]",Xs="rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",wr="rounded-[24px] border border-dashed border-[var(--ui-border-strong)] bg-[var(--ui-surface-1)]",Ke="bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)]",Ze="bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_74%,var(--ui-ink-strong)_26%)]",yr="bg-[var(--ui-info-soft)] text-[color-mix(in_srgb,var(--info)_76%,var(--ui-ink-strong)_24%)]",Zs="border border-[var(--ui-success-soft)] bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_74%,var(--ui-ink-strong)_26%)]",Js="border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)] hover:bg-[var(--ui-surface-hover)]";function Fe(r){try{const t=new URL(r);return t.pathname.endsWith("/")||(t.pathname=`${t.pathname}/`),t.toString()}catch{return r}}function jr(r){switch(r){case"google":return"Google Calendar";case"apple":return"Apple Calendar";case"microsoft":return"Exchange Online";case"macos_local":return"Calendars On This Mac";case"caldav":default:return"Custom CalDAV"}}function ea(r){switch(r){case"google":return"Open Google guided flow";case"microsoft":return"Open Microsoft guided flow";case"macos_local":return"Open Mac calendar flow";default:return"Open guided setup"}}function ra(r){switch(r){case"google":case"microsoft":return $e;case"macos_local":return er;case"apple":return er;case"caldav":default:return Re}}function sa(r){switch(r){case"microsoft":return"Read only";case"macos_local":return"Read + write";default:return"Read + write"}}function aa(r){switch(r){case"google":return"Local PKCE";case"microsoft":return"Guided sign-in";case"macos_local":return"Host machine";case"apple":return"App password";case"caldav":default:return"CalDAV credentials"}}function na(r){switch(r){case"google":return"Sign in from the same machine running Forge. After connection, Forge can mirror the calendars you choose and reuse the current shared Forge write target, creating one only when the runtime does not already have one.";case"apple":return"Use your Apple ID email and app-specific password. Forge discovers your iCloud calendars before you choose what to mirror.";case"microsoft":return"Use the guided Microsoft sign-in flow. Forge mirrors the Exchange calendars you choose and keeps this provider read only.";case"macos_local":return"Use the calendars already configured in Calendar.app on this Mac. Forge requests Calendar access through macOS, discovers host calendars by account source, and replaces overlapping remote account connections instead of duplicating them.";case"caldav":default:return"Enter a CalDAV server URL and account credentials. Forge discovers the calendars on that account before you choose what to mirror."}}function Nr(r){return`${r} connection${r===1?"":"s"}`}function fa(){var T,ye,$,Z,Ie;const r=Fr(),[t,i]=Dr(),[h,b]=c.useState(!1),[f,u]=c.useState("google"),[A,j]=c.useState(void 0),[v,E]=c.useState(null),[s,m]=c.useState([]),[L,g]=c.useState(!1),[N,p]=c.useState(null),[I,_]=c.useState(()=>ps()),G=Me({queryKey:["forge-operator-session"],queryFn:is}),P=G.isSuccess,F=Me({queryKey:["forge-settings"],queryFn:ls,enabled:P}),U=Me({queryKey:["forge-calendar-connections"],queryFn:cs,enabled:P}),S=Me({queryKey:["forge-calendar-resources"],queryFn:ds,enabled:P}),W=async()=>{await Promise.all([r.invalidateQueries({queryKey:["forge-settings"]}),r.invalidateQueries({queryKey:["forge-calendar-connections"]}),r.invalidateQueries({queryKey:["forge-calendar-resources"]}),r.invalidateQueries({queryKey:["forge-calendar-overview"]}),os(r)])},C=ee({mutationFn:es,onSuccess:W}),ie=ee({mutationFn:n=>rs(n),onSuccess:W}),B=ee({mutationFn:({connectionId:n,patch:d})=>ss(n,d),onSuccess:W}),H=ee({mutationFn:n=>as(n),onSuccess:W});c.useEffect(()=>{if(!P)return;const n=t.get("intent"),d=t.get("provider");if(n!=="connect")return;u(d==="apple"||d==="caldav"||d==="google"||d==="microsoft"||d==="macos_local"?d:"google"),j(d==="microsoft"?"credentials":void 0),b(!0);const x=new URLSearchParams(t);x.delete("intent"),x.delete("provider"),i(x,{replace:!0})},[P,t,i]);const V=c.useMemo(()=>{var n,d;return ns(((n=S.data)==null?void 0:n.calendars)??[],((d=U.data)==null?void 0:d.connections)??[])},[(T=S.data)==null?void 0:T.calendars,(ye=U.data)==null?void 0:ye.connections]),se=c.useMemo(()=>{const n=new Map;for(const d of V){const x=n.get(d.connectionId)??[];x.push(d),n.set(d.connectionId,x)}return n},[V]),we=c.useMemo(()=>{var d;const n={};for(const x of((d=U.data)==null?void 0:d.connections)??[])n[x.provider]=(n[x.provider]??0)+1;return n},[($=U.data)==null?void 0:$.connections]),ae=c.useMemo(()=>ms(V,I.calendarColors),[V,I.calendarColors]),Y=c.useMemo(()=>{var n;return(((n=U.data)==null?void 0:n.connections)??[]).find(d=>{var x;return typeof((x=d.config)==null?void 0:x.forgeCalendarUrl)=="string"&&d.config.forgeCalendarUrl.trim().length>0})??null},[(Z=U.data)==null?void 0:Z.connections]),O=c.useMemo(()=>{var n;return((n=U.data)==null?void 0:n.connections.find(d=>d.id===v))??null},[U.data,v]),D=c.useMemo(()=>{var n;return((n=U.data)==null?void 0:n.connections.find(d=>d.id===N))??null},[U.data,N]),le=c.useMemo(()=>v?se.get(v)??[]:[],[se,v]),R=Me({queryKey:["forge-calendar-connection-discovery",v],queryFn:()=>us(v),enabled:P&&v!==null});c.useEffect(()=>{if(!v){m([]),g(!1);return}const n=le.filter(d=>d.selectedForSync).map(d=>Fe(d.remoteId));m(n),g(!0)},[v,le]),c.useEffect(()=>{fs(I)},[I]);const fe=c.useMemo(()=>[{id:"mirrors",eyebrow:"Mirroring",title:"Choose which calendars Forge should mirror",description:"Unselected calendars stop showing up in Forge’s mirrored calendar views. The Forge write calendar stays available for work blocks and timeboxes.",render:(n,d)=>{var ne,ce;if(R.isLoading)return e.jsx("div",{className:`${wr} px-4 py-6 ${Oe}`,children:"Rediscovering calendars for this connection."});if(R.isError||!((ne=R.data)!=null&&ne.discovery))return e.jsx("div",{className:"rounded-[24px] border border-rose-400/20 bg-rose-400/10 px-4 py-6 text-sm leading-6 text-rose-100",children:R.error instanceof Error?R.error.message:"Forge could not rediscover calendars for this connection."});const x=R.data.discovery,w=(O==null?void 0:O.provider)==="microsoft",z=typeof((ce=O==null?void 0:O.config)==null?void 0:ce.forgeCalendarUrl)=="string"?Fe(O.config.forgeCalendarUrl):null;return e.jsx("div",{className:"grid gap-3",children:x.calendars.map(J=>{const te=Fe(J.url),de=L?n.selectedCalendarUrls.includes(te):le.some(ue=>ue.selectedForSync&&Fe(ue.remoteId)===te),je=z===te;return e.jsxs("div",{className:`${Xs} p-4`,children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:Be,children:Ve(J)}),e.jsxs("div",{className:"mt-1 break-all text-sm text-[var(--ui-ink-soft)]",children:[J.timezone||"No timezone exposed"," ·"," ",J.url]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[je&&!w?e.jsx(k,{className:"bg-[var(--primary)]/14 text-[var(--primary)]",children:"Forge writes here"}):null,w?e.jsx(k,{className:"bg-sky-400/12 text-sky-100",children:"Read only"}):null,J.isPrimary?e.jsx(k,{className:Ke,children:"Primary"}):null]})]}),e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:e.jsx("button",{type:"button",disabled:je&&!w,onClick:()=>d({selectedCalendarUrls:de?n.selectedCalendarUrls.filter(ue=>ue!==te):[...n.selectedCalendarUrls,te]}),className:`rounded-full px-3 py-2 text-sm transition ${je&&!w?"cursor-not-allowed border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-faint)]":de?Zs:Js}`,children:je&&!w?"Always available for Forge writes":de?"Mirrored into Forge":"Do not mirror"})})]},J.url)})})}}],[O,R]);if(G.isLoading||F.isLoading||U.isLoading||S.isLoading)return e.jsx(ts,{eyebrow:"Settings · Calendar",title:"Loading calendar settings",description:"Checking the operator session and loading provider connections.",columns:2,blocks:6});if(G.isError)return e.jsx(hr,{eyebrow:"Settings · Calendar",error:G.error,onRetry:()=>void G.refetch()});if(F.isError||U.isError||S.isError||!((Ie=F.data)!=null&&Ie.settings)||!U.data||!S.data)return e.jsx(hr,{eyebrow:"Settings · Calendar",error:F.error??U.error??S.error??new Error("Calendar settings are unavailable."),onRetry:()=>{F.refetch(),U.refetch(),S.refetch()}});const{providers:ve,connections:X}=U.data,Ee=F.data.settings.calendarProviders.google,Q=F.data.settings.calendarProviders.microsoft;return e.jsxs("div",{className:"mx-auto grid w-full max-w-[1220px] gap-5",children:[e.jsx(gs,{title:"Calendar settings",description:"Manage provider connections, review the shared Forge write target, and open guided setup only when you need to connect or reconfigure a provider.",badge:`${X.length} connection${X.length===1?"":"s"}`}),e.jsx(hs,{}),e.jsxs("div",{className:"grid gap-5",children:[e.jsxs(We,{className:"surface-section-panel grid gap-5 rounded-[30px] border",children:[e.jsxs("div",{className:"max-w-3xl",children:[e.jsx("div",{className:Xe,children:"Provider connections"}),e.jsxs("p",{className:`mt-2 ${Oe}`,children:["Connect a provider here, then choose which calendars Forge should mirror. Writable providers publish work blocks and owned timeboxes through one shared"," ",e.jsx("span",{className:Be,children:"Forge"})," write target, creating it only when the runtime does not already have one."]})]}),e.jsx("div",{className:"grid gap-4 lg:grid-cols-2",children:ve.map(n=>{const d=ra(n.provider),x=we[n.provider]??0,w=x>0;return e.jsxs("div",{className:`flex min-h-[248px] flex-col rounded-[26px] border p-5 shadow-[inset_0_1px_0_var(--ui-border-subtle)] ${w?"border-[var(--ui-success-soft)] bg-[var(--ui-success-soft)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]"}`,children:[e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:`rounded-[18px] p-3 ${w?Ze:"bg-[var(--primary)]/14 text-[var(--primary)]"}`,children:e.jsx(d,{className:"size-4"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("div",{className:"font-medium text-[var(--ui-ink-strong)]",children:n.label}),w?e.jsxs(e.Fragment,{children:[e.jsx(k,{className:Ze,children:"Connected"}),e.jsx(k,{className:Ke,children:Nr(x)})]}):null]}),e.jsx("p",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:na(n.provider)}),w?e.jsxs("div",{className:"mt-3 text-sm text-[color-mix(in_srgb,var(--success)_68%,var(--ui-ink-strong)_32%)]",children:["Forge already has"," ",Nr(x)," for this provider. Open the guided flow again to add another account or reconfigure one."]}):null]})]}),e.jsxs("div",{className:"mt-5 flex flex-wrap gap-2",children:[e.jsx(k,{tone:"signal",className:"bg-[var(--ui-accent-soft)] text-[var(--primary)]",children:aa(n.provider)}),e.jsx(k,{className:n.supportsDedicatedForgeCalendar?Ze:yr,children:sa(n.provider)})]}),e.jsx("div",{className:"mt-auto pt-5",children:e.jsxs(M,{variant:"secondary",className:"w-full justify-center",onClick:()=>{u(n.provider),j(n.provider==="google"||n.provider==="microsoft"?"credentials":void 0),b(!0)},children:[e.jsx(ke,{className:"size-4"}),ea(n.provider)]})})]},n.provider)})})]}),e.jsxs(We,{className:"surface-section-panel grid gap-4 rounded-[30px] border",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:Xe,children:"Calendar colors"}),e.jsx("p",{className:`mt-2 max-w-3xl ${Oe}`,children:"Calendar colors are on by default so each mirrored calendar stays legible in the week view. Adjust any display color here without changing the provider itself."})]}),e.jsx("button",{type:"button",onClick:()=>_(n=>({...n,useCalendarColors:!n.useCalendarColors})),className:`rounded-full px-4 py-2 text-sm transition ${I.useCalendarColors?"border border-[color-mix(in_srgb,var(--primary)_34%,var(--ui-border-subtle)_66%)] bg-[var(--ui-accent-soft)] text-[var(--primary)]":"border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)] hover:bg-[var(--ui-surface-hover)]"}`,children:I.useCalendarColors?"Colors on":"Colors off"})]}),V.length>0?e.jsx("div",{className:"grid gap-3",children:V.map(n=>{const d=Ve(n);return e.jsxs("div",{className:"grid gap-3 rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4 md:grid-cols-[minmax(0,1fr)_auto]",children:[e.jsx("div",{className:"min-w-0",children:e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx("span",{"aria-hidden":"true",className:"size-3 shrink-0 rounded-full",style:{backgroundColor:ae[n.id]}}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate font-medium text-[var(--ui-ink-strong)]",children:d}),e.jsxs("div",{className:"mt-1 text-sm text-[var(--ui-ink-soft)]",children:[n.canWrite?"Writable":"Read only"," ·"," ",n.timezone]})]})]})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("input",{"aria-label":`Choose display color for ${d}`,type:"color",value:ae[n.id],onChange:x=>_(w=>({...w,calendarColors:{...w.calendarColors,[n.id]:x.target.value}})),className:"h-10 w-12 cursor-pointer rounded-[14px] border border-[var(--ui-border-subtle)] bg-transparent p-1"}),e.jsx(M,{size:"sm",variant:"secondary",onClick:()=>_(x=>{const w={...x.calendarColors};return delete w[n.id],{...x,calendarColors:w}}),children:"Reset palette"})]})]},n.id)})}):e.jsx("div",{className:"rounded-[24px] border border-dashed border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-5 text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Connect a provider first, then Forge will let you tune the display color of each mirrored calendar here."})]}),e.jsxs(We,{className:"surface-section-panel grid gap-4 rounded-[30px] border",children:[e.jsx("div",{className:"flex items-center justify-between gap-3",children:e.jsxs("div",{children:[e.jsx("div",{className:Xe,children:"Connected providers"}),e.jsx("p",{className:`mt-2 ${Oe}`,children:"Review connection health, confirm which provider calendars Forge can read or mirror, and see which connection currently owns the shared Forge write target."})]})}),X.length>0?e.jsx("div",{className:"grid gap-3",children:X.map(n=>{var w;const d=se.get(n.id)??[],x=n.provider!=="microsoft"&&Y!==null&&Y.id!==n.id;return e.jsxs("div",{className:"rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-[var(--ui-ink-strong)]",children:n.label}),e.jsxs("div",{className:"mt-1 text-sm text-[var(--ui-ink-soft)]",children:[jr(n.provider)," ·"," ",n.accountLabel||"No account label yet"]}),n.lastSyncedAt?e.jsxs("div",{className:"mt-2 text-sm text-[var(--ui-ink-faint)]",children:["Last synced"," ",new Date(n.lastSyncedAt).toLocaleString()]}):null,n.lastSyncError?e.jsx("div",{className:"mt-2 text-sm text-rose-200",children:n.lastSyncError}):null,x?e.jsxs("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:["Forge writes through"," ",e.jsx("span",{className:"font-medium text-[var(--ui-ink-strong)]",children:Y.label}),Y.accountLabel?` · ${Y.accountLabel}`:"","."]}):null]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(k,{className:Ke,children:n.status}),((w=n.config)==null?void 0:w.readOnly)===!0?e.jsx(k,{className:yr,children:"Read only"}):null,e.jsxs(M,{size:"sm",variant:"secondary",pending:ie.isPending&&ie.variables===n.id,pendingLabel:"Syncing",onClick:()=>void ie.mutateAsync(n.id),children:[e.jsx(Qe,{className:"size-4"}),"Sync"]}),e.jsxs(M,{size:"sm",variant:"secondary",onClick:()=>{const z=(se.get(n.id)??[]).filter(ne=>ne.selectedForSync).map(ne=>Fe(ne.remoteId));m(z),g(!0),E(n.id)},children:[e.jsx($r,{className:"size-4"}),"Manage mirrored calendars"]}),e.jsxs(M,{size:"sm",variant:"secondary",onClick:()=>p(n.id),children:[e.jsx(zr,{className:"size-4"}),"Remove"]})]})]}),e.jsx("div",{className:"mt-4 grid gap-2",children:d.map(z=>e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-medium text-[var(--ui-ink-strong)]",children:Ve(z)}),e.jsxs("div",{className:"mt-1 text-xs uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:[z.canWrite?"Writable":"Read only"," ·"," ",z.timezone]})]}),z.forgeManaged?e.jsx(k,{className:"bg-[var(--primary)]/14 text-[var(--primary)]",children:"Forge"}):e.jsxs(k,{className:Ke,children:[e.jsx(er,{className:"mr-1 size-3.5"}),"Mirrored"]})]},z.id))})]},n.id)})}):e.jsxs("div",{className:`${wr} px-5 py-6 ${Oe}`,children:["No provider is connected yet. Open a guided setup flow above when you are ready. Forge will reuse one shared"," ",e.jsx("span",{className:Be,children:"Forge"})," write target across writable providers when it already exists, create one only when none exists yet, and mirror selected calendars in read-only mode for providers like Exchange Online."]})]})]}),e.jsx(Ys,{open:h,onOpenChange:n=>{b(n),n||j(void 0)},initialProvider:f,initialStepId:A,googleSetup:Ee,microsoftSetup:Q,existingConnections:X.map(n=>({id:n.id,label:n.label,provider:n.provider,status:n.status,accountLabel:n.accountLabel,forgeCalendarId:n.forgeCalendarId,config:n.config})),onCalendarSettingsChanged:W,pending:C.isPending,onSubmit:async n=>{await C.mutateAsync(n)}}),e.jsx(rr,{open:v!==null,onOpenChange:n=>{n||E(null)},eyebrow:"Calendar settings",title:"Manage mirrored calendars",description:"Choose which calendars this connection should mirror into Forge.",value:{selectedCalendarUrls:s},onChange:n=>m(n.selectedCalendarUrls),draftPersistenceKey:v?`settings.calendar.manage.${v}`:"settings.calendar.manage",steps:fe,pending:B.isPending,pendingLabel:"Saving",submitLabel:"Save mirror selection",error:B.error instanceof Error?B.error.message:null,onSubmit:async()=>{v&&(await B.mutateAsync({connectionId:v,patch:{selectedCalendarUrls:s.map(Fe)}}),g(!1),E(null))}}),e.jsx(rr,{open:N!==null,onOpenChange:n=>{n||p(null)},eyebrow:"Calendar settings",title:"Remove calendar connection",description:"This removes the provider connection, stops syncing its calendars, removes mirrored external events from Forge, and keeps Forge-native events local.",value:{acknowledgement:!1},onChange:()=>{},draftPersistenceKey:N?`settings.calendar.remove.${N}`:"settings.calendar.remove",steps:[{id:"confirm",eyebrow:"Disconnect",title:D?`Remove ${D.label}?`:"Remove this connection?",description:"Use this when you want to disconnect the account entirely. You can reconnect later with the guided setup flow.",render:()=>e.jsx("div",{className:"rounded-[24px] border border-rose-400/20 bg-rose-400/10 p-4 text-sm leading-6 text-rose-100",children:D?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:Be,children:[jr(D.provider)," ·"," ",D.accountLabel||"No account label"]}),e.jsx("div",{className:"mt-2",children:"Mirrored provider calendars and external mirrored events from this connection will be removed. Forge-owned events, work blocks, and timeboxes remain in Forge."})]}):"This connection will be removed from Forge."})}],pending:H.isPending,pendingLabel:"Removing",submitLabel:"Remove connection",error:H.error instanceof Error?H.error.message:null,onSubmit:async()=>{N&&(await H.mutateAsync(N),p(null))}})]})}export{fa as SettingsCalendarPage};
@@ -0,0 +1 @@
1
+ import{r as o,j as e,da as V,db as Y,cr as xe,dc as Z,aQ as J,dd as me,aD as ge,cg as pe}from"./vendor-Dnkkx2co.js";import{j as he,i as X,k}from"./state-vCcAT5Hq.js";import{dy as ve,dz as be,dA as fe,dB as je,dC as ke,dD as ye,j as we,F as Ne,I as ee,c as u,S as Fe,E as ae,B as m,C as y,Z as T,Q as te,f as Se,du as Re,dE as De}from"./index-EqQsXoat.js";import{S as Ce}from"./settings-section-nav-DP9o4peU.js";import{P as Be}from"./page-hero-ffKzgyW3.js";import{M as g}from"./metric-tile-CMadwnGz.js";import"./motion-Lt5B1XuE.js";import"./ui-C1iwpj2-.js";import"./forms-hB0SqEh-.js";import"./board-dIX6etHh.js";import"./graph-DDUZNRsO.js";function A(t){if(!Number.isFinite(t)||t<=0)return"0 B";const l=["B","KB","MB","GB","TB"];let i=t,x=0;for(;i>=1024&&x<l.length-1;)i/=1024,x+=1;return`${i.toFixed(i>=100?0:i>=10?1:2)} ${l[x]}`}function _e(t,l){const i=URL.createObjectURL(t),x=document.createElement("a");x.href=i,x.download=l,x.click(),URL.revokeObjectURL(i)}function Me(t){return t?t===1?"Every hour":t===24?"Every day":t===168?"Every week":`Every ${t} hours`:"Off"}function se(t){switch(t){case"manual":return"Manual";case"automatic":return"Automatic";case"pre_restore":return"Safety backup before restore";case"pre_switch_root":return"Safety backup before folder change";default:return t}}function w(t,l="Unknown time"){if(!t)return l;const i=new Date(t);return Number.isNaN(i.getTime())?l:Se(t)}function Ae({tone:t,message:l}){return e.jsx("div",{className:T("rounded-[20px] border px-4 py-3 text-sm leading-6",t==="success"?"border-[color-mix(in_srgb,var(--success)_26%,var(--ui-border-subtle)_74%)] bg-[var(--ui-success-soft)] text-[var(--success)]":t==="warning"?"border-[color-mix(in_srgb,var(--warning)_26%,var(--ui-border-subtle)_74%)] bg-[var(--ui-warning-soft)] text-[var(--warning)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-soft)]"),children:l})}function z({label:t,value:l,icon:i}){return e.jsxs("div",{className:"min-w-0 overflow-hidden rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2 text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:[e.jsx(i,{className:"size-4"}),e.jsx("span",{className:"min-w-0 break-words",children:t})]}),e.jsx("div",{className:"mt-3 min-w-0 break-all text-sm leading-6 text-[var(--ui-ink-soft)] [overflow-wrap:anywhere]",children:l})]})}function Ie(){var G,W;const t=he(),[l,i]=o.useState(""),[x,$]=o.useState(""),[E,q]=o.useState(""),[O,U]=o.useState(!0),[b,re]=o.useState([]),[L,f]=o.useState(null),[ne,N]=o.useState(!1),[c,F]=o.useState({mode:"migrate_current",targetDataRoot:"",createSafetyBackup:!0}),[ie,j]=o.useState(null),[n,P]=o.useState(null),[K,H]=o.useState({createSafetyBackup:!0}),[oe,R]=o.useState(null),h=X({queryKey:["forge-operator-session"],queryFn:Re}),le=h.isSuccess,S=X({queryKey:["forge-data-management"],queryFn:De,enabled:le}),D=async()=>{await Promise.all([t.invalidateQueries({queryKey:["forge-operator-session"]}),t.invalidateQueries({queryKey:["forge-data-management"]})])},I=k({mutationFn:()=>ve({backupDirectory:l,backupFrequencyHours:x==="off"?null:Number(x||"24"),backupRetentionDays:E==="forever"?null:Number(E||"30"),autoRepairEnabled:O}),onSuccess:async()=>{f({tone:"success",message:"Backup settings saved."}),await D()}}),C=k({mutationFn:()=>be("Manual backup from Settings → Data"),onSuccess:async()=>{f({tone:"success",message:"Backup created."}),await D()}}),B=k({mutationFn:fe,onSuccess:({candidates:a})=>{re(a),f({tone:a.some(d=>d.newerThanCurrent)?"warning":"neutral",message:a.length>0?`Found ${a.length} Forge ${a.length===1?"copy":"copies"} on disk.`:"No other Forge data copies were found in the scanned folders."})}}),_=k({mutationFn:a=>je({targetDataRoot:a.targetDataRoot,mode:a.mode,createSafetyBackup:a.createSafetyBackup}),onSuccess:async()=>{f({tone:"success",message:"Forge is now using the selected data folder."}),N(!1),await D()}}),M=k({mutationFn:({backupId:a,createSafetyBackup:d})=>ke(a,d),onSuccess:async()=>{f({tone:"success",message:"Backup restored. Forge is now running from that restored state."}),P(null),await D()}}),Q=k({mutationFn:async a=>{const d=await ye(a);return _e(d.blob,d.fileName??`forge-export.${a}`),a},onSuccess:a=>{f({tone:"neutral",message:`Started download for ${a}.`})}}),s=(G=S.data)==null?void 0:G.data;o.useEffect(()=>{s&&(i(a=>a||s.settings.backupDirectory),$(a=>a||(s.settings.backupFrequencyHours?String(s.settings.backupFrequencyHours):"off")),U(s.settings.autoRepairEnabled),q(a=>a||(s.settings.backupRetentionDays?String(s.settings.backupRetentionDays):"forever")),F(a=>({...a,targetDataRoot:a.targetDataRoot||s.current.dataRoot})))},[s]);const de=o.useMemo(()=>b.find(a=>a.newerThanCurrent),[b]),p=o.useMemo(()=>b.find(a=>a.dataRoot===c.targetDataRoot.trim()),[c.targetDataRoot,b]),ce=[{id:"mode",eyebrow:"Step 1",title:"What do you want Forge to do?",description:"Choose whether Forge should move the current data into a new folder or switch to a folder that already contains the right Forge data.",render:(a,d)=>e.jsxs("div",{className:"grid gap-4",children:[e.jsx(we,{value:a.mode,onChange:v=>d({mode:v}),options:[{value:"migrate_current",label:"Move the current data",description:"Copy the live database and local secrets key into a new folder, then switch Forge to it."},{value:"adopt_existing",label:"Use an existing data folder",description:"Keep the target folder as it is and point Forge at that existing database directly."}]}),e.jsxs("label",{className:"flex items-start gap-3 rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-3",children:[e.jsx("input",{type:"checkbox",className:"mt-1",checked:a.createSafetyBackup,onChange:v=>d({createSafetyBackup:v.target.checked})}),e.jsx("span",{className:"text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Create one safety backup first."})]})]})},{id:"folder",eyebrow:"Step 2",title:c.mode==="migrate_current"?"Choose the new data folder":"Choose the data folder to use",description:c.mode==="migrate_current"?"Pick an empty folder for the moved Forge data.":"Pick the folder that already contains the Forge data you trust.",render:(a,d)=>e.jsxs("div",{className:"grid gap-4",children:[e.jsx(Ne,{label:"Data folder",description:"Forge will place or read the database and backups from here.",children:e.jsx(ee,{value:a.targetDataRoot,onChange:v=>d({targetDataRoot:v.target.value}),placeholder:"/absolute/path/to/forge-data"})}),p?e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4 text-sm leading-6 text-[var(--ui-ink-soft)]",children:[e.jsx("div",{className:"font-medium text-[var(--ui-ink-strong)]",children:"Found on this machine"}),e.jsx("div",{className:"mt-2 break-all",children:p.databasePath}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx(u,{tone:"meta",children:p.sourceHint}),e.jsxs(u,{tone:"meta",children:[p.counts.notes," notes"]}),e.jsxs(u,{tone:"meta",children:[p.counts.tasks," tasks"]}),p.newerThanCurrent?e.jsx(u,{className:"bg-[var(--ui-warning-soft)] text-[var(--warning)]",children:"Newer than the current copy"}):null]})]}):e.jsx("div",{className:"rounded-[22px] border border-dashed border-[var(--ui-border-subtle)] px-4 py-4 text-sm leading-6 text-[var(--ui-ink-soft)]",children:c.mode==="migrate_current"?"Forge will copy the current data into this folder and then switch over.":"If this folder already holds a Forge database, Forge will start using it after you confirm."})]})}],ue=[{id:"review",eyebrow:"Step 1",title:"Review the backup you want to restore",description:"Restoring replaces the current database with the selected backup.",render:(a,d)=>e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4 text-sm leading-6 text-[var(--ui-ink-soft)]",children:[e.jsx("div",{className:"font-medium text-[var(--ui-ink-strong)]",children:n?w(n.createdAt):"Selected backup"}),e.jsx("div",{className:"mt-2",children:(n==null?void 0:n.note)||"Forge backup archive"}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx(u,{tone:"meta",children:n?se(n.mode):"Backup"}),e.jsx(u,{tone:"meta",children:n?A(n.sizeBytes):"0 B"}),n!=null&&n.includesWiki?e.jsx(u,{tone:"meta",children:"Includes wiki"}):null]})]}),e.jsxs("label",{className:"flex items-start gap-3 rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-3",children:[e.jsx("input",{type:"checkbox",className:"mt-1",checked:a.createSafetyBackup,onChange:v=>d({createSafetyBackup:v.target.checked})}),e.jsx("span",{className:"text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Create one safety backup of the current state first."})]})]})},{id:"confirm",eyebrow:"Step 2",title:"Confirm the restore",description:"Use this only when you are confident this backup is the state you want back.",render:()=>e.jsx("div",{className:"rounded-[22px] border border-[color-mix(in_srgb,var(--warning)_26%,var(--ui-border-subtle)_74%)] bg-[var(--ui-warning-soft)] p-4 text-sm leading-6 text-[var(--warning)]",children:"Forge will replace the live database with this backup, then reopen the restored copy."})}];if(h.isLoading||S.isLoading)return e.jsx(Fe,{eyebrow:"Data",title:"Loading data controls",description:"Checking the live data folder, backup plan, and recovery tools.",columns:3,blocks:6});if(h.isError)return e.jsx(ae,{eyebrow:"Data",error:h.error,onRetry:()=>void h.refetch()});if(S.isError||!s)return e.jsx(ae,{eyebrow:"Data",error:S.error??new Error("Forge returned an empty data payload."),onRetry:()=>void S.refetch()});const r=s.current;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mx-auto grid w-full max-w-[1480px] gap-5",children:[e.jsx(Be,{eyebrow:"Data, backups, recovery",title:"Data",description:"See where Forge is saving the live data, keep it protected with backups, look for a newer copy on disk if something goes wrong, and download the database or its structure when you need it.",badge:`${r.integrityOk?"Healthy":"Needs attention"} · ${A(r.databaseSizeBytes)}`,actions:e.jsxs(e.Fragment,{children:[e.jsxs(m,{variant:"secondary",pending:B.isPending,pendingLabel:"Scanning",onClick:()=>void B.mutateAsync(),children:[e.jsx(V,{className:"size-4"}),"Look for other Forge copies"]}),e.jsxs(m,{pending:C.isPending,pendingLabel:"Creating backup",onClick:()=>void C.mutateAsync(),children:[e.jsx(Y,{className:"size-4"}),"Create backup now"]})]})}),e.jsx(Ce,{}),(W=h.data)!=null&&W.session?e.jsxs("div",{className:"rounded-[20px] border border-[color-mix(in_srgb,var(--success)_26%,var(--ui-border-subtle)_74%)] bg-[var(--ui-success-soft)] px-4 py-3 text-sm text-[var(--ui-ink-medium)]",children:["You are managing Forge data as"," ",e.jsx("span",{className:"font-medium text-[var(--ui-ink-strong)]",children:h.data.session.actorLabel}),"."]}):null,L?e.jsx(Ae,{tone:L.tone,message:L.message}):null,e.jsxs("div",{className:"grid gap-5 xl:grid-cols-[minmax(0,1.15fr)_minmax(0,0.85fr)]",children:[e.jsxs(y,{className:"grid gap-5",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Live data folder"}),e.jsx("div",{className:"mt-2 min-w-0 break-all text-xl font-semibold text-[var(--ui-ink-strong)] [overflow-wrap:anywhere]",children:r.dataRoot}),e.jsx("div",{className:"mt-2 max-w-3xl text-sm leading-6 text-[var(--ui-ink-soft)]",children:"This is the folder Forge is reading and writing right now."})]}),e.jsx(u,{className:T(r.integrityOk?"bg-[var(--ui-success-soft)] text-[var(--success)]":"bg-[var(--ui-warning-soft)] text-[var(--warning)]"),children:r.integrityMessage})]}),e.jsxs("div",{className:"grid min-w-0 gap-3 md:grid-cols-2 xl:grid-cols-3",children:[e.jsx(z,{label:"Database file",value:r.databasePath,icon:xe}),e.jsx(z,{label:"Folder layout",value:r.layout,icon:Z}),e.jsx(z,{label:"Last database change",value:r.databaseLastModifiedAt?w(r.databaseLastModifiedAt):"Unknown",icon:J})]}),e.jsxs("div",{className:"grid min-w-0 gap-3 md:grid-cols-3 xl:grid-cols-6",children:[e.jsx(g,{label:"Notes",value:r.counts.notes}),e.jsx(g,{label:"Goals",value:r.counts.goals}),e.jsx(g,{label:"Projects",value:r.counts.projects}),e.jsx(g,{label:"Tasks",value:r.counts.tasks}),e.jsx(g,{label:"Runs",value:r.counts.taskRuns}),e.jsx(g,{label:"Tags",value:r.counts.tags})]})]}),e.jsxs(y,{className:"grid gap-4",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"flex size-11 items-center justify-center rounded-2xl border border-[color-mix(in_srgb,var(--success)_26%,var(--ui-border-subtle)_74%)] bg-[var(--ui-success-soft)]",children:e.jsx(me,{className:"size-5 text-[var(--success)]"})}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-semibold text-[var(--ui-ink-strong)]",children:"Protection plan"}),e.jsx("div",{className:"mt-1 text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Choose where backups go, how often Forge creates them, and whether scans should call out newer copies found elsewhere on disk."})]})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[e.jsx(g,{label:"Automatic backup",value:Me(s.settings.backupFrequencyHours),detail:s.settings.lastAutoBackupAt?`Last run ${w(s.settings.lastAutoBackupAt)}`:"No automatic backup recorded yet"}),e.jsx(g,{label:"Manual backup",value:s.settings.lastManualBackupAt?w(s.settings.lastManualBackupAt):"None yet",detail:`${s.backups.length} backup${s.backups.length===1?"":"s"} saved`}),e.jsx(g,{label:"Retention",value:s.settings.backupRetentionDays?`${s.settings.backupRetentionDays} days`:"Keep forever",detail:"Automatic backups only"})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Backup folder"}),e.jsx(ee,{value:l,onChange:a=>i(a.target.value)})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Automatic backup"}),e.jsxs("select",{className:"h-11 rounded-[16px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-3 text-sm text-[var(--ui-ink-strong)] outline-none transition focus:border-[var(--primary)]",value:x||"24",onChange:a=>$(a.target.value),children:[e.jsx("option",{value:"off",children:"Off"}),e.jsx("option",{value:"1",children:"Every hour"}),e.jsx("option",{value:"6",children:"Every 6 hours"}),e.jsx("option",{value:"24",children:"Every day"}),e.jsx("option",{value:"168",children:"Every week"})]})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Keep automatic backups"}),e.jsxs("select",{className:"h-11 rounded-[16px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-3 text-sm text-[var(--ui-ink-strong)] outline-none transition focus:border-[var(--primary)]",value:E||"30",onChange:a=>q(a.target.value),children:[e.jsx("option",{value:"7",children:"7 days"}),e.jsx("option",{value:"14",children:"14 days"}),e.jsx("option",{value:"30",children:"30 days"}),e.jsx("option",{value:"90",children:"90 days"}),e.jsx("option",{value:"365",children:"1 year"}),e.jsx("option",{value:"forever",children:"Keep forever"})]})]}),e.jsxs("label",{className:"flex items-start gap-3 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-3",children:[e.jsx("input",{type:"checkbox",className:"mt-1",checked:O,onChange:a=>U(a.target.checked)}),e.jsx("span",{className:"text-sm leading-6 text-[var(--ui-ink-soft)]",children:"When I scan, point out Forge copies that look newer than the one I am using now."})]}),e.jsxs("div",{className:"flex flex-wrap gap-3",children:[e.jsx(m,{pending:I.isPending,pendingLabel:"Saving",onClick:()=>void I.mutateAsync(),children:"Save backup settings"}),e.jsx(m,{variant:"secondary",pending:C.isPending,pendingLabel:"Creating backup",onClick:()=>void C.mutateAsync(),children:"Create backup now"})]})]})]})]}),e.jsxs("div",{className:"grid gap-5 xl:grid-cols-[minmax(0,0.9fr)_minmax(0,1.1fr)]",children:[e.jsxs(y,{className:"grid gap-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Change data folder"}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Move today’s Forge data into a new folder, or switch to another folder that already contains the right Forge database."})]}),e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4 text-sm leading-6 text-[var(--ui-ink-soft)]",children:[e.jsx("div",{className:"font-medium text-[var(--ui-ink-strong)]",children:"Current folder"}),e.jsx("div",{className:"mt-2 break-all",children:r.dataRoot}),p?e.jsxs("div",{className:"mt-3 text-sm text-[var(--ui-ink-soft)]",children:["Selected scanned copy: ",p.dataRoot]}):null]}),e.jsxs("div",{className:"flex flex-wrap gap-3",children:[e.jsxs(m,{onClick:()=>{F(a=>({...a,mode:"migrate_current",targetDataRoot:a.targetDataRoot||r.dataRoot})),j(null),N(!0)},children:[e.jsx(Z,{className:"size-4"}),"Move current data"]}),e.jsxs(m,{variant:"secondary",onClick:()=>{F(a=>({...a,mode:"adopt_existing",targetDataRoot:a.targetDataRoot||r.dataRoot})),j(null),N(!0)},children:[e.jsx(J,{className:"size-4"}),"Use existing data folder"]})]})]}),e.jsxs(y,{className:"grid gap-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Downloads"}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Download the live database itself, or export a structure and table snapshot in other formats."})]}),e.jsx(ge,{className:"size-5 text-[var(--ui-ink-faint)]"})]}),e.jsx("div",{className:"grid gap-3",children:s.exportOptions.map(a=>e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-semibold text-[var(--ui-ink-strong)]",children:a.label}),e.jsx("div",{className:"mt-1 text-sm leading-6 text-[var(--ui-ink-soft)]",children:a.description})]}),e.jsx(m,{variant:"secondary",pending:Q.isPending,pendingLabel:"Preparing",onClick:()=>void Q.mutateAsync(a.format),children:"Download"})]},a.format))})]})]}),e.jsxs("div",{className:"grid gap-5 xl:grid-cols-[minmax(0,1.05fr)_minmax(0,0.95fr)]",children:[e.jsxs(y,{className:"grid gap-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Backup history"}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Go back to an older saved state if you need to undo a bad change."})]}),e.jsx(Y,{className:"size-5 text-[var(--ui-ink-faint)]"})]}),e.jsx("div",{className:"grid gap-3",children:s.backups.length===0?e.jsx("div",{className:"rounded-[20px] border border-dashed border-[var(--ui-border-subtle)] px-4 py-6 text-sm text-[var(--ui-ink-soft)]",children:"No backups yet. Create one now so you have a safe restore point."}):s.backups.map(a=>e.jsxs("div",{className:"rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("div",{className:"text-sm font-semibold text-[var(--ui-ink-strong)]",children:w(a.createdAt)}),e.jsx(u,{tone:"meta",children:se(a.mode)})]}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:a.note||"Forge backup archive"})]}),e.jsx(m,{variant:"secondary",onClick:()=>{H({createSafetyBackup:!0}),R(null),P(a)},children:"Restore"})]}),e.jsxs("div",{className:"mt-3 grid gap-2 text-xs text-[var(--ui-ink-faint)] md:grid-cols-2",children:[e.jsx("div",{className:"break-all",children:a.archivePath}),e.jsx("div",{children:A(a.sizeBytes)})]})]},a.id))})]}),e.jsxs(y,{className:"grid gap-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Find other Forge copies"}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Search common folders on this machine for other Forge databases. Use this when Forge opened the wrong copy or when you think a newer copy exists somewhere else."})]}),e.jsxs(m,{variant:"secondary",pending:B.isPending,pendingLabel:"Scanning",onClick:()=>void B.mutateAsync(),children:[e.jsx(V,{className:"size-4"}),"Scan now"]})]}),e.jsx("div",{className:"grid gap-3",children:b.length===0?e.jsx("div",{className:"rounded-[20px] border border-dashed border-[var(--ui-border-subtle)] px-4 py-6 text-sm text-[var(--ui-ink-soft)]",children:"No scan results yet. Run a scan to compare the live data folder with other Forge copies on disk."}):b.map(a=>e.jsxs("div",{className:T("rounded-[22px] border p-4",a.sameAsCurrent?"border-[color-mix(in_srgb,var(--success)_24%,var(--ui-border-subtle)_76%)] bg-[var(--ui-success-soft)]":a.newerThanCurrent?"border-[color-mix(in_srgb,var(--warning)_26%,var(--ui-border-subtle)_74%)] bg-[var(--ui-warning-soft)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)]"),children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("div",{className:"text-sm font-semibold text-[var(--ui-ink-strong)]",children:a.dataRoot}),e.jsx(u,{tone:"meta",children:a.sourceHint}),a.newerThanCurrent?e.jsx(u,{className:"bg-[var(--ui-warning-soft)] text-[var(--warning)]",children:"Newer than current"}):null,a.sameAsCurrent?e.jsx(u,{className:"bg-[var(--ui-success-soft)] text-[var(--success)]",children:"Current copy"}):null]}),e.jsx("div",{className:"mt-2 break-all text-sm text-[var(--ui-ink-soft)]",children:a.databasePath})]}),a.sameAsCurrent?null:e.jsx(m,{variant:"secondary",onClick:()=>{F({mode:"adopt_existing",targetDataRoot:a.dataRoot,createSafetyBackup:!0}),j(null),N(!0)},children:"Use this folder"})]}),e.jsxs("div",{className:"mt-4 grid gap-2 text-xs text-[var(--ui-ink-faint)] md:grid-cols-5",children:[e.jsx("div",{children:a.integrityMessage}),e.jsx("div",{children:w(a.databaseLastModifiedAt??new Date().toISOString())}),e.jsx("div",{children:A(a.databaseSizeBytes)}),e.jsxs("div",{children:[a.counts.notes," notes"]}),e.jsxs("div",{children:[a.counts.tasks," tasks"]})]})]},a.id))}),de?e.jsxs("div",{className:"flex items-start gap-3 rounded-[20px] border border-[color-mix(in_srgb,var(--warning)_26%,var(--ui-border-subtle)_74%)] bg-[var(--ui-warning-soft)] px-4 py-3 text-sm text-[var(--warning)]",children:[e.jsx(pe,{className:"mt-0.5 size-4 shrink-0"}),e.jsx("div",{children:"Forge found a copy on disk that looks newer than the one you are using now. Review it carefully before switching."})]}):null]})]})]}),e.jsx(te,{open:ne,onOpenChange:a=>{N(a),a||j(null)},eyebrow:"Data folder",title:c.mode==="migrate_current"?"Move Forge data":"Use an existing Forge data folder",description:"This guided flow keeps the folder change explicit and gives you a safety backup option first.",value:c,onChange:F,draftPersistenceKey:`settings.data.root.${c.mode}`,steps:ce,pending:_.isPending,pendingLabel:c.mode==="migrate_current"?"Moving data":"Switching folder",submitLabel:c.mode==="migrate_current"?"Move and switch":"Use this folder",error:ie??(_.error instanceof Error?_.error.message:null),onSubmit:async()=>{if(!c.targetDataRoot.trim()){j("Choose a data folder first.");return}j(null),await _.mutateAsync(c)}}),e.jsx(te,{open:n!==null,onOpenChange:a=>{a||(P(null),R(null))},eyebrow:"Restore backup",title:"Restore Forge backup",description:"This flow replaces the live data with an older saved state.",value:K,onChange:H,draftPersistenceKey:n?`settings.data.restore.${n.id}`:"settings.data.restore",steps:ue,pending:M.isPending,pendingLabel:"Restoring",submitLabel:"Restore this backup",error:oe??(M.error instanceof Error?M.error.message:null),onSubmit:async()=>{if(!n){R("Choose a backup first.");return}R(null),await M.mutateAsync({backupId:n.id,createSafetyBackup:K.createSafetyBackup})}})]})}export{Ie as SettingsDataPage};
@@ -0,0 +1 @@
1
+ import{c2 as H,r as c,j as r,cs as V,aK as Q,b3 as G,F as J}from"./vendor-Dnkkx2co.js";import{x as W}from"./state-vCcAT5Hq.js";import{c as q,S as Z,E as X,C as F,B as A,I as Y,Z as z,en as ee,eo as te,b as se,ep as re}from"./index-EqQsXoat.js";import{P as ne}from"./page-hero-ffKzgyW3.js";import{S as ie}from"./settings-section-nav-DP9o4peU.js";import"./motion-Lt5B1XuE.js";import"./ui-C1iwpj2-.js";import"./forms-hB0SqEh-.js";import"./board-dIX6etHh.js";import"./graph-DDUZNRsO.js";const ae=["error","warning","info","debug"],oe=["server","ui","system","agent","openclaw"],le=60,P="text-[11px] font-medium uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",T="text-[var(--ui-ink-soft)]",h="text-[var(--ui-ink-faint)]",ce="text-[var(--ui-ink-strong)]",de="bg-[var(--ui-surface-3)] text-[var(--ui-ink-medium)]",ue="relative rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-3 py-2.5",ge="inline-flex max-w-full items-center gap-1.5 rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-1.5 py-1",me="z-[80] overflow-y-auto overscroll-contain rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-popover)] p-2 shadow-[var(--ui-shadow-floating)] backdrop-blur-xl [webkit-overflow-scrolling:touch]",fe="rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-3";function L(t){return t.trim().toLowerCase()}function C(t){return Array.from(new Set(t.map(n=>(n==null?void 0:n.trim())??"").filter(Boolean)))}function $(t,n){const s=C(t.getAll(n));if(s.length>0)return s;const a=t.get(n);return a!=null&&a.trim()?[a.trim()]:[]}function pe(t){return new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"medium"}).format(new Date(t))}function U(t){return t==="error"?"border-[color-mix(in_srgb,var(--danger)_30%,var(--ui-border-subtle)_70%)] bg-[var(--ui-danger-soft)] text-[color-mix(in_srgb,var(--danger)_76%,var(--ui-ink-strong)_24%)]":t==="warning"?"border-[color-mix(in_srgb,var(--warning)_30%,var(--ui-border-subtle)_70%)] bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]":t==="info"?"border-[color-mix(in_srgb,var(--primary)_30%,var(--ui-border-subtle)_70%)] bg-[var(--ui-accent-soft)] text-[var(--primary)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-3)] text-[var(--ui-ink-medium)]"}function B(t){return t==="error"?"Errors":t==="warning"?"Warnings":t==="info"?"Info":"Debug"}function R(t){return t==="openclaw"?"OpenClaw":t.charAt(0).toUpperCase()+t.slice(1)}function xe(t){return[t.scope?`scope: ${t.scope}`:null,t.eventKey?`event: ${t.eventKey}`:null,t.route?`route: ${t.route}`:null,t.functionName?`function: ${t.functionName}`:null,t.jobId?`job: ${t.jobId}`:null,t.entityType&&t.entityId?`entity: ${t.entityType}:${t.entityId}`:null,t.requestId?`request: ${t.requestId}`:null].filter(n=>!!n)}function he(t){return L([t.message,t.scope,t.eventKey,t.route,t.functionName,t.requestId,t.entityType,t.entityId,t.jobId,JSON.stringify(t.details)].filter(Boolean).join(" "))}function j(t,n){return r.jsx(q,{size:"sm",className:z(de,n),children:t})}function K(t,n){return te(t)?r.jsx(se,{kind:t,label:n,compact:!0,gradient:!1}):j(n,"bg-[var(--ui-accent-soft)] text-[var(--primary)]")}function k({label:t,placeholder:n,options:s,selectedIds:a,onChange:m,emptyMessage:u="No matches yet."}){const[w,d]=c.useState(!1),[b,v]=c.useState(""),[I,y]=c.useState(0),E=c.useRef(null),M=c.useRef(null),O=ee(E,w,{offset:8,preferredMaxHeight:320,minHeight:160}),_=c.useMemo(()=>a.map(i=>s.find(o=>o.id===i)??null).filter(i=>i!==null),[s,a]),p=L(b),x=c.useMemo(()=>{const i=s.filter(o=>!a.includes(o.id));return p?i.filter(o=>L(`${o.label} ${o.description??""} ${o.searchText??""}`).includes(p)).slice(0,10):i.slice(0,10)},[p,s,a]),N=i=>{a.includes(i)||(m([...a,i]),v(""),y(0),d(!1))},D=i=>{m(a.filter(o=>o!==i))};return c.useEffect(()=>{if(!w)return;const i=e=>{var g,f;const l=e.target;(g=E.current)!=null&&g.contains(l)||(f=M.current)!=null&&f.contains(l)||d(!1)},o=e=>{e.key==="Escape"&&d(!1)};return document.addEventListener("pointerdown",i),document.addEventListener("keydown",o),()=>{document.removeEventListener("pointerdown",i),document.removeEventListener("keydown",o)}},[w]),r.jsxs("label",{className:"grid gap-2",children:[r.jsx("span",{className:P,children:t}),r.jsxs("div",{ref:E,className:ue,children:[_.length>0?r.jsx("div",{className:"mb-2 flex flex-wrap gap-1.5",children:_.map(i=>r.jsxs("span",{className:ge,children:[i.badge,r.jsx("button",{type:"button",className:`rounded-full p-0.5 transition hover:text-[var(--ui-ink-strong)] ${h}`,onClick:()=>D(i.id),"aria-label":`Remove ${i.label}`,children:r.jsx(Q,{className:"size-3"})})]},i.id))}):null,r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(G,{className:`size-3.5 ${h}`}),r.jsx("input",{value:b,onChange:i=>{v(i.target.value),y(0),d(!0)},onFocus:()=>d(!0),onKeyDown:i=>{if(i.key==="Backspace"&&!b&&a.length>0){D(a[a.length-1]);return}if(i.key==="ArrowDown"){i.preventDefault(),d(!0),y(o=>x.length===0?0:Math.min(x.length-1,o+1));return}if(i.key==="ArrowUp"){i.preventDefault(),y(o=>Math.max(0,o-1));return}if(i.key==="Escape"){d(!1);return}i.key==="Enter"&&x[I]&&(i.preventDefault(),N(x[I].id))},placeholder:n,className:"min-w-0 flex-1 bg-transparent text-sm text-[var(--ui-ink-strong)] placeholder:text-[var(--ui-ink-faint)] focus:outline-none"})]}),w&&O&&typeof document<"u"?J.createPortal(r.jsx("div",{ref:M,role:"listbox","aria-multiselectable":"true",className:me,style:O,children:x.length>0?x.map((i,o)=>r.jsx("button",{type:"button",role:"option","aria-selected":!1,className:z("flex w-full items-start justify-between gap-3 rounded-[16px] px-3 py-2 text-left transition",o===I?"bg-[var(--ui-accent-soft)] text-[var(--ui-ink-strong)]":"text-[var(--ui-ink-soft)] hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]"),onMouseEnter:()=>y(o),onMouseDown:e=>e.preventDefault(),onClick:()=>N(i.id),children:r.jsxs("div",{className:"min-w-0",children:[r.jsx("div",{className:"truncate text-sm font-medium",children:i.menuBadge??i.badge}),i.description?r.jsx("div",{className:`mt-1 text-xs leading-5 ${h}`,children:i.description}):null]})},i.id)):r.jsx("div",{className:`px-3 py-2 text-sm ${h}`,children:u})}),document.body):null]})]})}function be(t,n){const s=`${n.entityType}:${n.entityId}`;t.has(s)||t.set(s,{id:s,label:n.label,description:n.description,searchText:n.searchText,badge:n.badge,menuBadge:n.menuBadge})}function ve(t){const n=new Map;for(const s of t){if(!s.entityType||!s.entityId)continue;const a=`${s.entityType}:${s.entityId}`;if(n.has(a))continue;const m=s.entityType==="wiki_ingest_job"?`Ingest ${s.entityId}`:`${s.entityType} ${s.entityId}`;be(n,{entityType:s.entityType,entityId:s.entityId,label:m,description:"Seen in diagnostics logs",searchText:L(`${m} ${s.scope} ${s.message} ${s.eventKey}`),badge:K(s.entityType,m),menuBadge:K(s.entityType,m)})}return Array.from(n.values()).sort((s,a)=>s.label.localeCompare(a.label))}const ye=c.memo(function({entry:n}){const[s,a]=c.useState(!1),m=c.useMemo(()=>s&&Object.keys(n.details).length>0?JSON.stringify(n.details,null,2):"",[s,n.details]);return r.jsxs(F,{className:"grid gap-4",children:[r.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[r.jsxs("div",{className:"grid min-w-0 gap-3",children:[r.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[r.jsx("span",{className:z("rounded-full border px-2 py-0.5 text-[10px] font-semibold uppercase tracking-[0.16em]",U(n.level)),children:n.level}),r.jsx("span",{className:`rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-3)] px-2 py-0.5 text-[10px] font-semibold uppercase tracking-[0.16em] ${T}`,children:n.source}),r.jsx("span",{className:`rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-3)] px-2 py-0.5 text-[10px] font-semibold uppercase tracking-[0.16em] ${T}`,children:n.scope}),n.eventKey?r.jsx("span",{className:`max-w-full break-words rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-3)] px-2 py-0.5 text-[10px] font-semibold uppercase tracking-[0.16em] [overflow-wrap:anywhere] ${h}`,children:n.eventKey}):null]}),r.jsx("div",{className:`break-words text-base font-medium [overflow-wrap:anywhere] ${ce}`,children:n.message}),r.jsx("div",{className:`flex flex-wrap gap-3 break-words text-xs [overflow-wrap:anywhere] ${h}`,children:xe(n).map(u=>r.jsx("span",{children:u},u))})]}),r.jsxs("div",{className:`shrink-0 text-right text-xs ${h}`,children:[r.jsx("div",{children:pe(n.createdAt)}),r.jsx("div",{className:"mt-1 font-mono text-[11px]",children:n.id})]})]}),Object.keys(n.details).length>0?r.jsxs("details",{className:fe,onToggle:u=>a(u.currentTarget.open),children:[r.jsx("summary",{className:`cursor-pointer text-sm ${T}`,children:"View structured details"}),s?r.jsx("pre",{className:`mt-3 overflow-x-auto whitespace-pre-wrap text-xs leading-6 ${T}`,children:m}):null]}):null]})});function Le(){const[t,n]=H(),s=c.useMemo(()=>{var f,S;const e=((f=t.get("entityType"))==null?void 0:f.trim())||"",l=((S=t.get("entityId"))==null?void 0:S.trim())||"",g=$(t,"entity");return g.length===0&&e&&l&&g.push(`${e}:${l}`),{search:t.get("search")||"",levels:$(t,"level"),sources:$(t,"source"),scopes:$(t,"scope"),routes:$(t,"route"),jobs:$(t,"jobId"),entities:C(g)}},[t]),a=W({queryKey:["forge-diagnostic-logs","settings-filters"],initialPageParam:null,queryFn:({pageParam:e})=>re({limit:le,beforeCreatedAt:e==null?void 0:e.beforeCreatedAt,beforeId:e==null?void 0:e.beforeId}),getNextPageParam:e=>e.nextCursor,retry:!1,refetchOnWindowFocus:!1}),m=(e,l)=>{const g=new URLSearchParams(t);l.trim()?g.set(e,l.trim()):g.delete(e),n(g,{replace:!0})},u=(e,l,g=[])=>{const f=new URLSearchParams(t);f.delete(e);for(const S of g)f.delete(S);for(const S of C(l))f.append(e,S);n(f,{replace:!0})},w=()=>{const e=new URLSearchParams(t);["search","level","source","scope","route","jobId","entity","entityType","entityId"].forEach(l=>e.delete(l)),n(e,{replace:!0})},d=c.useMemo(()=>{var e;return((e=a.data)==null?void 0:e.pages.flatMap(l=>l.logs))??[]},[a.data]),b=L(s.search),v=c.useRef(null),I=c.useMemo(()=>ae.map(e=>({id:e,label:B(e),searchText:`${e} ${B(e)}`,badge:r.jsx(q,{size:"sm",className:U(e),children:B(e)})})),[]),y=c.useMemo(()=>oe.map(e=>({id:e,label:R(e),searchText:`${e} ${R(e)}`,badge:j(R(e))})),[]),E=c.useMemo(()=>C(d.map(e=>e.scope)).map(e=>({id:e,label:e,searchText:e,badge:j(e)})),[d]),M=c.useMemo(()=>C(d.map(e=>e.route)).map(e=>({id:e,label:e,description:"Filter logs to one or more exact routes.",searchText:e,badge:j(e,"max-w-[16rem]"),menuBadge:j(e)})),[d]),O=c.useMemo(()=>C(d.map(e=>e.jobId)).map(e=>({id:e,label:e,description:"Background job or ingest run id.",searchText:e,badge:j(e,"max-w-[14rem]"),menuBadge:j(e)})),[d]),_=c.useMemo(()=>ve(d),[d]),p=c.useMemo(()=>d.filter(e=>{if(b&&!he(e).includes(b)||s.levels.length>0&&!s.levels.includes(e.level)||s.sources.length>0&&!s.sources.includes(e.source)||s.scopes.length>0&&!s.scopes.includes(e.scope)||s.routes.length>0&&!s.routes.includes(e.route??"")||s.jobs.length>0&&!s.jobs.includes(e.jobId??""))return!1;if(s.entities.length>0){const l=e.entityType&&e.entityId?`${e.entityType}:${e.entityId}`:"";if(!l||!s.entities.includes(l))return!1}return!0}),[s,b,d]),x=[s.search,s.levels.join("|"),s.sources.join("|"),s.scopes.join("|"),s.routes.join("|"),s.jobs.join("|"),s.entities.join("|")].join("::");c.useEffect(()=>{var e;(e=v.current)==null||e.scrollTo({top:0})},[x]);const N=V({count:p.length,getScrollElement:()=>v.current,estimateSize:()=>260,overscan:8}),D=N.getVirtualItems(),i=()=>{const e=v.current;if(!e||!a.hasNextPage||a.isFetchingNextPage)return;e.scrollHeight-e.scrollTop-e.clientHeight<=800&&a.fetchNextPage()},o=s.levels.length+s.sources.length+s.scopes.length+s.routes.length+s.jobs.length+s.entities.length+(s.search.trim()?1:0);return a.isPending?r.jsx(Z,{eyebrow:"Settings",title:"Loading diagnostics",description:"Collecting the latest frontend, backend, and runtime traces.",columns:1,blocks:6}):a.isError?r.jsx(X,{eyebrow:"Settings",error:a.error,onRetry:()=>void a.refetch()}):r.jsxs("div",{className:"mx-auto grid w-full max-w-[1220px] gap-5",children:[r.jsx(ne,{title:"Logs",description:"Inspect shared diagnostics from the UI, backend routes, background jobs, and LLM flows.",badge:`${p.length} matching${p.length!==d.length?` · ${d.length} loaded`:""}${a.hasNextPage?" · more available":""}`}),r.jsx(ie,{}),r.jsxs(F,{className:"grid gap-4",children:[r.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[r.jsxs("div",{children:[r.jsx("div",{className:P,children:"Filters"}),r.jsx("div",{className:`mt-2 max-w-3xl text-sm leading-6 ${T}`,children:"Use token filters with OR-style badge selections for levels, sources, routes, jobs, scopes, and linked entities. Search still matches the message body and structured details."})]}),r.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[o>0?r.jsxs(A,{variant:"ghost",size:"sm",onClick:w,children:["Clear ",o]}):null,r.jsx(A,{variant:"secondary",size:"sm",onClick:()=>void a.refetch(),pending:a.isRefetching&&!a.isFetchingNextPage,pendingLabel:"Refreshing",children:"Refresh"})]})]}),r.jsxs("label",{className:"grid gap-2",children:[r.jsx("span",{className:P,children:"Search message or details"}),r.jsx(Y,{value:s.search,onChange:e=>m("search",e.target.value),placeholder:"LLM compilation failed, wiki_ingest, request_failed…",className:"h-11 rounded-[20px]"})]}),r.jsxs("div",{className:"grid gap-3 xl:grid-cols-2",children:[r.jsx(k,{label:"Levels",placeholder:"Add one or more levels",options:I,selectedIds:s.levels,onChange:e=>u("level",e),emptyMessage:"No additional log levels."}),r.jsx(k,{label:"Sources",placeholder:"Add one or more sources",options:y,selectedIds:s.sources,onChange:e=>u("source",e),emptyMessage:"No additional log sources."}),r.jsx(k,{label:"Scopes",placeholder:"Search scopes",options:E,selectedIds:s.scopes,onChange:e=>u("scope",e),emptyMessage:"No scopes match the current logs."}),r.jsx(k,{label:"Routes",placeholder:"Search exact routes",options:M,selectedIds:s.routes,onChange:e=>u("route",e),emptyMessage:"No routes match the current logs."}),r.jsx(k,{label:"Jobs",placeholder:"Search job ids",options:O,selectedIds:s.jobs,onChange:e=>u("jobId",e),emptyMessage:"No job ids match the current logs."}),r.jsx(k,{label:"Entities",placeholder:"Search Forge entities or logged ids",options:_,selectedIds:s.entities,onChange:e=>u("entity",e,["entityType","entityId"]),emptyMessage:"No logged entities match yet."})]})]}),r.jsx("div",{className:"grid gap-3",children:p.length===0?r.jsx(F,{className:`text-sm ${T}`,children:"No diagnostic entries match the current filters yet."}):r.jsx(F,{className:"p-0",children:r.jsxs("div",{ref:v,onScroll:i,className:"h-[72vh] overflow-y-auto px-3 py-3",children:[r.jsx("div",{className:"relative",style:{height:`${N.getTotalSize()}px`},children:D.map(e=>{const l=p[e.index];return l?r.jsx("div",{"data-index":e.index,ref:N.measureElement,className:"absolute left-0 top-0 w-full pb-3",style:{transform:`translateY(${e.start}px)`},children:r.jsx(ye,{entry:l})},l.id):null})}),r.jsx("div",{className:`border-t border-[var(--ui-border-subtle)] px-1 py-3 text-center text-xs ${h}`,children:a.isFetchingNextPage?"Loading older logs...":a.hasNextPage?"Scroll to load older logs.":`Showing all ${d.length} loaded logs.`})]})})})]})}export{Le as SettingsLogsPage};