forge-openclaw-plugin 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/dist/assets/{activity-page-DPPiiyLO.js → activity-page-DRRbpVK-.js} +1 -1
  2. package/dist/assets/{ai-surface-workspace-B_fV9C4s.js → ai-surface-workspace-DJPt-OaW.js} +1 -1
  3. package/dist/assets/{atlas-panel-BPTJyMcI.js → atlas-panel-G3wGxjYf.js} +1 -1
  4. package/dist/assets/{calendar-page-D4DcRQv7.js → calendar-page-y8G1ige8.js} +1 -1
  5. package/dist/assets/{calendar-rules-Cl_xMrBn.js → calendar-rules-CRhXqGQu.js} +1 -1
  6. package/dist/assets/{calendar-week-toolbar-BARSOEO9.js → calendar-week-toolbar-CWSK5hJl.js} +1 -1
  7. package/dist/assets/{companion-sync-lab-page-COFYDI3w.js → companion-sync-lab-page-kEgOF3c6.js} +1 -1
  8. package/dist/assets/daily-metrics-dashboard-BJjUIZVA.js +1 -0
  9. package/dist/assets/{entity-note-count-link-BX93WYgh.js → entity-note-count-link-ef3ZOpKM.js} +1 -1
  10. package/dist/assets/{entity-notes-surface-CBlKc-x-.js → entity-notes-surface-CaCjjUaq.js} +1 -1
  11. package/dist/assets/{execution-board-Dh41UeKR.js → execution-board-RRWm2srb.js} +1 -1
  12. package/dist/assets/{faceted-token-search-BgxYH_gW.js → faceted-token-search-CZmtyJTT.js} +1 -1
  13. package/dist/assets/{flagship-signal-deck-bolzzK8q.js → flagship-signal-deck-DxRfmfpN.js} +1 -1
  14. package/dist/assets/{floating-action-menu-C5H-Wr2B.js → floating-action-menu-cKjNsPYD.js} +1 -1
  15. package/dist/assets/{goal-detail-page-CQeFnGDJ.js → goal-detail-page-BgQlK7yT.js} +1 -1
  16. package/dist/assets/{goals-page-BTg9crEK.js → goals-page-Cz2i3pVy.js} +1 -1
  17. package/dist/assets/{habits-page-C4vqk346.js → habits-page-BmEmWCGv.js} +1 -1
  18. package/dist/assets/index-Bcem7l5u.css +1 -0
  19. package/dist/assets/{index-By3tQxiE.js → index-QJkjKYzZ.js} +2 -2
  20. package/dist/assets/{insight-flow-dialog-JPYCsTKI.js → insight-flow-dialog-CdYMHwMP.js} +1 -1
  21. package/dist/assets/{insights-page-CFhVMlVL.js → insights-page-DHG-o9P_.js} +1 -1
  22. package/dist/assets/{kanban-page-DC3IDsnh.js → kanban-page-C6S_fJRc.js} +1 -1
  23. package/dist/assets/{knowledge-graph-page-DucyRYTZ.js → knowledge-graph-page-juA9QCy0.js} +1 -1
  24. package/dist/assets/{life-force-page-UrXfxaSO.js → life-force-page-ChTIA4mV.js} +1 -1
  25. package/dist/assets/{life-force-workspace-BhPNH7ad.js → life-force-workspace-sszLD-Yn.js} +1 -1
  26. package/dist/assets/{metric-tile-DtRPjN4V.js → metric-tile-B-tDTcBt.js} +1 -1
  27. package/dist/assets/{movement-page-DCIdTQEN.js → movement-page-Dx3T3HrG.js} +1 -1
  28. package/dist/assets/{note-markdown-CepDxj3v.js → note-markdown-CCyyE85h.js} +1 -1
  29. package/dist/assets/{note-tags-input-BXYaDkOr.js → note-tags-input-BS14YXHn.js} +1 -1
  30. package/dist/assets/{notes-page-Bl1LlCLo.js → notes-page-D3yGl8TN.js} +1 -1
  31. package/dist/assets/{open-in-graph-button-C263zl5l.js → open-in-graph-button-CMjJZX7G.js} +1 -1
  32. package/dist/assets/{orbit-map-Cb_AJyIj.js → orbit-map-v2Pv9RU_.js} +1 -1
  33. package/dist/assets/{overview-page-C2yLity7.js → overview-page-DSOpBpHf.js} +1 -1
  34. package/dist/assets/{page-hero-5RTqAI88.js → page-hero-CONuJu5J.js} +1 -1
  35. package/dist/assets/{pill-cluster-CBrrtZBm.js → pill-cluster-W2fY48OM.js} +1 -1
  36. package/dist/assets/{preference-entity-handoff-button-BQzg2J4k.js → preference-entity-handoff-button-CKDxCnbl.js} +1 -1
  37. package/dist/assets/{preferences-page-DekYF-Yz.js → preferences-page-Br3zrLlH.js} +1 -1
  38. package/dist/assets/{project-collections-BVXB8PPF.js → project-collections-NBwk6yV-.js} +1 -1
  39. package/dist/assets/{project-detail-page-CQlrLEn9.js → project-detail-page-BIU9_TRN.js} +1 -1
  40. package/dist/assets/{project-management-hierarchy-page--mzM_zRE.js → project-management-hierarchy-page-C2H620xD.js} +1 -1
  41. package/dist/assets/{project-management-section-nav-DQl0qRWy.js → project-management-section-nav-DRPVS1Eh.js} +1 -1
  42. package/dist/assets/{projects-page-Dr_0NdVP.js → projects-page-w7a_L2-z.js} +1 -1
  43. package/dist/assets/{psyche-behaviors-page-DOUaCWON.js → psyche-behaviors-page-Dt4CMC-q.js} +1 -1
  44. package/dist/assets/{psyche-flashcards-page-BA84fO_X.js → psyche-flashcards-page-rXz06dqO.js} +1 -1
  45. package/dist/assets/{psyche-goal-map-page-DpXAg1Vf.js → psyche-goal-map-page-BCcD6Jkl.js} +1 -1
  46. package/dist/assets/{psyche-graph-BxcbAbXt.js → psyche-graph-CXlAj4ED.js} +1 -1
  47. package/dist/assets/psyche-metrics-page-B1otiir6.js +1 -0
  48. package/dist/assets/{psyche-mode-guide-page-CBlIS5N_.js → psyche-mode-guide-page-C6AdVIAv.js} +1 -1
  49. package/dist/assets/{psyche-modes-page-DE6KDK_1.js → psyche-modes-page-DoUqz2mR.js} +1 -1
  50. package/dist/assets/psyche-page-BJNLQn8W.js +1 -0
  51. package/dist/assets/{psyche-patterns-page-DbCNRuww.js → psyche-patterns-page-CzpMSAPu.js} +1 -1
  52. package/dist/assets/{psyche-questionnaire-builder-page-DnraDj1H.js → psyche-questionnaire-builder-page-DjzatGVZ.js} +1 -1
  53. package/dist/assets/{psyche-questionnaire-detail-page-DQ6zNQkk.js → psyche-questionnaire-detail-page-B0Qfowfg.js} +1 -1
  54. package/dist/assets/{psyche-questionnaire-run-detail-page-BGrOIX0B.js → psyche-questionnaire-run-detail-page-B2dNj4jJ.js} +1 -1
  55. package/dist/assets/{psyche-questionnaire-run-page-Bg3BhBHb.js → psyche-questionnaire-run-page-DyD9Ui-g.js} +1 -1
  56. package/dist/assets/{psyche-questionnaires-page-BEreTNjG.js → psyche-questionnaires-page-BxfKcoi3.js} +1 -1
  57. package/dist/assets/{psyche-report-detail-page-Br9KlJBG.js → psyche-report-detail-page-Ci14mNUK.js} +1 -1
  58. package/dist/assets/{psyche-reports-page-Bk6QpAEF.js → psyche-reports-page-ALhNueiV.js} +1 -1
  59. package/dist/assets/{psyche-schemas-beliefs-page-Db8d2ga7.js → psyche-schemas-beliefs-page-C0P2Vw6-.js} +1 -1
  60. package/dist/assets/{psyche-screen-time-page-NazHUAkT.js → psyche-screen-time-page-BYnaT3cb.js} +1 -1
  61. package/dist/assets/{psyche-self-observation-page-H6FToucM.js → psyche-self-observation-page-eM9vpwIB.js} +1 -1
  62. package/dist/assets/{psyche-values-page-DqM382-6.js → psyche-values-page-BqrGIDok.js} +1 -1
  63. package/dist/assets/{report-chain-fields-nW4zndrM.js → report-chain-fields-CbkT7WOO.js} +1 -1
  64. package/dist/assets/{rewards-page-C-tZVnIK.js → rewards-page-DpAJ8IxE.js} +1 -1
  65. package/dist/assets/{scheduling-rules-editor-DGF-044c.js → scheduling-rules-editor-BUGnZJ0g.js} +1 -1
  66. package/dist/assets/{schema-badge-57AJ3FY-.js → schema-badge-CLAA4p-b.js} +1 -1
  67. package/dist/assets/{select-menu-mfaklv7r.js → select-menu-Cqs5t3ng.js} +1 -1
  68. package/dist/assets/{settings-agents-page-CPJeeYg0.js → settings-agents-page-pmkVrOO8.js} +1 -1
  69. package/dist/assets/{settings-bin-page-D3eX5aNf.js → settings-bin-page-BwtLrweW.js} +1 -1
  70. package/dist/assets/{settings-calendar-page-Bgx8NIsP.js → settings-calendar-page-BBjAMOCf.js} +1 -1
  71. package/dist/assets/{settings-data-page-BuMSUjpp.js → settings-data-page-Bqy5SukM.js} +1 -1
  72. package/dist/assets/{settings-logs-page-CHb2GNUM.js → settings-logs-page-8khtrf4T.js} +1 -1
  73. package/dist/assets/{settings-mobile-page-ClUvXhJg.js → settings-mobile-page-BcyRjEU_.js} +1 -1
  74. package/dist/assets/{settings-models-page-njK6D7zc.js → settings-models-page-DlSnO9WX.js} +1 -1
  75. package/dist/assets/{settings-page-Dm--cx6B.js → settings-page-CyBQ2qcB.js} +1 -1
  76. package/dist/assets/{settings-rewards-page-3aShLM3A.js → settings-rewards-page-BBX2WtVM.js} +1 -1
  77. package/dist/assets/{settings-section-nav-BWox23Qv.js → settings-section-nav-Co0AaDG-.js} +1 -1
  78. package/dist/assets/{settings-users-page-D-hEPpgQ.js → settings-users-page-JSnfFFPu.js} +1 -1
  79. package/dist/assets/{settings-wiki-page-CC-rOtDm.js → settings-wiki-page--nT23Fdy.js} +1 -1
  80. package/dist/assets/{sleep-page-Cm_Ei2w1.js → sleep-page-CGMi3MtV.js} +1 -1
  81. package/dist/assets/{sports-page-CqSI-j-H.js → sports-page-Kv5bBoLr.js} +1 -1
  82. package/dist/assets/{strategies-page-BuJ4zLLv.js → strategies-page-Br7RdUJO.js} +1 -1
  83. package/dist/assets/{strategy-detail-page-CLmy0jbW.js → strategy-detail-page-CBWXjUhC.js} +1 -1
  84. package/dist/assets/{strategy-dialog-DnJix1ys.js → strategy-dialog-BTwkaSxI.js} +1 -1
  85. package/dist/assets/{surface-DRNu5Fpz.js → surface-CyWI7e1R.js} +1 -1
  86. package/dist/assets/{task-detail-page-DTnNjW33.js → task-detail-page-Qis9354n.js} +1 -1
  87. package/dist/assets/{timebox-planning-dialog-DckIr1K4.js → timebox-planning-dialog-DB8snOBD.js} +1 -1
  88. package/dist/assets/{today-page-Cgk4HBPK.js → today-page-D9A5PU0S.js} +1 -1
  89. package/dist/assets/{training-load-page-C-7iINaB.js → training-load-page-Bpd4DQAh.js} +1 -1
  90. package/dist/assets/vitals-page-CVYC-4RG.js +1 -0
  91. package/dist/assets/{weekly-review-page-DFmuzzig.js → weekly-review-page-BP7N3fNB.js} +1 -1
  92. package/dist/assets/{weight-loss-page-CWtgeuti.js → weight-loss-page-_fX3N1UK.js} +1 -1
  93. package/dist/assets/{wiki-article-markdown-BkQg8Hne.js → wiki-article-markdown-Bi02AsVt.js} +1 -1
  94. package/dist/assets/{wiki-editor-page-BYKcdX5I.js → wiki-editor-page-OZf9l4Tg.js} +1 -1
  95. package/dist/assets/{wiki-ingest-history-page-D_p4myw1.js → wiki-ingest-history-page-CzeNSL7N.js} +1 -1
  96. package/dist/assets/{wiki-ingest-modal-C-CidueO.js → wiki-ingest-modal-Ig_xnyc6.js} +1 -1
  97. package/dist/assets/wiki-page-B4xuNgY4.js +1 -0
  98. package/dist/assets/{workbench-flow-page-Q3r2IJty.js → workbench-flow-page-BhRJCALC.js} +1 -1
  99. package/dist/assets/{workbench-page-BFfWMGm6.js → workbench-page-DxVs2AOY.js} +1 -1
  100. package/dist/assets/{workout-detail-page-DeDyz1Kk.js → workout-detail-page-D4wfkE98.js} +1 -1
  101. package/dist/index.html +2 -2
  102. package/dist/server/server/migrations/069_psyche_devrage_cumulative_rage.sql +5 -0
  103. package/dist/server/server/src/app.js +3 -2
  104. package/dist/server/server/src/openapi.js +48 -8
  105. package/dist/server/server/src/psyche-types.js +18 -4
  106. package/dist/server/server/src/services/devrage-scanner.js +115 -10
  107. package/dist/server/server/src/services/devrage.js +61 -11
  108. package/openclaw.plugin.json +1 -1
  109. package/package.json +1 -1
  110. package/server/migrations/069_psyche_devrage_cumulative_rage.sql +5 -0
  111. package/skills/forge-openclaw/SKILL.md +7 -0
  112. package/skills/forge-openclaw/entity_conversation_playbooks.md +23 -0
  113. package/skills/forge-openclaw/psyche_entity_playbooks.md +32 -0
  114. package/dist/assets/daily-metrics-dashboard-BNGQlJkQ.js +0 -1
  115. package/dist/assets/index-BAXYM89v.css +0 -1
  116. package/dist/assets/psyche-metrics-page-D8JQEoOl.js +0 -1
  117. package/dist/assets/psyche-page-Dkh7R2Dc.js +0 -1
  118. package/dist/assets/vitals-page-CqE4bYMf.js +0 -1
  119. package/dist/assets/wiki-page-DYpg9ZEO.js +0 -1
@@ -1 +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-BWox23Qv.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-By3tQxiE.js";import{P as U}from"./page-hero-5RTqAI88.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};
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-Co0AaDG-.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-QJkjKYzZ.js";import{P as U}from"./page-hero-CONuJu5J.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};
@@ -1,4 +1,4 @@
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-By3tQxiE.js";import{S as hs}from"./settings-section-nav-BWox23Qv.js";import{P as gs}from"./page-hero-5RTqAI88.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(`
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-QJkjKYzZ.js";import{S as hs}from"./settings-section-nav-Co0AaDG-.js";import{P as gs}from"./page-hero-CONuJu5J.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
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
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
4
 
@@ -1 +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-By3tQxiE.js";import{S as Ce}from"./settings-section-nav-BWox23Qv.js";import{P as Be}from"./page-hero-5RTqAI88.js";import{M as g}from"./metric-tile-DtRPjN4V.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};
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-QJkjKYzZ.js";import{S as Ce}from"./settings-section-nav-Co0AaDG-.js";import{P as Be}from"./page-hero-CONuJu5J.js";import{M as g}from"./metric-tile-B-tDTcBt.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};
@@ -1 +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-By3tQxiE.js";import{P as ne}from"./page-hero-5RTqAI88.js";import{S as ie}from"./settings-section-nav-BWox23Qv.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};
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-QJkjKYzZ.js";import{P as ne}from"./page-hero-CONuJu5J.js";import{S as ie}from"./settings-section-nav-Co0AaDG-.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};
@@ -1 +1 @@
1
- import{r as u,dh as ae,j as e,di as ie,dj as ne,cw as _,cx as D,dg as te,dk as G,dl as re,bl as K,bK as B,dm as le,dn as W,aC as E,cb as L,dp as oe}from"./vendor-Dnkkx2co.js";import{j as de,i as ce,k as P}from"./state-vCcAT5Hq.js";import{u as me,s as xe,eb as pe,ec as he,ed as ue,ee as ve,S as ge,E as fe,C as Q,B as m,c as t,dw as je}from"./index-By3tQxiE.js";import{S as we}from"./settings-section-nav-BWox23Qv.js";import{P as be}from"./page-hero-5RTqAI88.js";import"./motion-Lt5B1XuE.js";import"./ui-C1iwpj2-.js";import"./forms-hB0SqEh-.js";import"./board-dIX6etHh.js";import"./graph-DDUZNRsO.js";function Ne(a){return a.replaceAll("."," ")}function ye(a){const d=typeof a.sleepNights=="number"?a.sleepNights:typeof a.sleepSessions=="number"?a.sleepSessions:0,g=typeof a.sleepSegments=="number"?a.sleepSegments:0,S=typeof a.sleepRawRecords=="number"?a.sleepRawRecords:0,b=typeof a.sleepSessions=="number"?a.sleepSessions:0,N=typeof a.workouts=="number"?a.workouts:0,x=a.vitals&&typeof a.vitals=="object"&&!Array.isArray(a.vitals)&&typeof a.vitals.metricEntries=="number"?a.vitals.metricEntries:0;return`${d||b} nights · ${g} segments · ${S} raw records · ${N} workouts · ${x} vitals`}function J(a){return a?"signal":"meta"}function ke(a){return a.replaceAll("_"," ")}function Pe(a){return a?new Date(a).toLocaleString():"Waiting for device update"}function Se(a,d){return a?d?"signal":"default":"meta"}function $e(a){return a.transportMode==="iroh"?"Iroh":"Manual HTTP"}function Ce(a){return a.transportMode==="iroh"?"signal":"meta"}const j="font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",i="text-[var(--ui-ink-soft)]",v="text-[var(--ui-ink-faint)]",l="rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",w="rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)]",V="rounded-[24px] border border-dashed border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",T="inline-flex min-h-11 items-center gap-2 rounded-[16px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-3 text-sm text-[var(--ui-ink-medium)] transition hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]";function Oe(){const a=me(),d=de(),g=Array.isArray(a.selectedUserIds)?a.selectedUserIds:[],S=xe(g),[b,N]=u.useState(null),[x,$]=u.useState(!1),[C,y]=u.useState(!1),[F,R]=u.useState(!1),[r,X]=u.useState(null),p=ce({queryKey:["forge-companion-overview",...g],queryFn:async()=>(await je(g)).overview}),c=P({mutationFn:async(s="iroh")=>pe({userId:S??null,transportMode:s}),onSuccess:async s=>{X({qrPayload:s.qrPayload}),$(!0),await d.invalidateQueries({queryKey:["forge-companion-overview"]})}}),A=P({mutationFn:async s=>he(s),onSuccess:async()=>{await d.invalidateQueries({queryKey:["forge-companion-overview"]})}}),I=P({mutationFn:async()=>ue({userIds:g,includeRevoked:!1}),onSuccess:async()=>{await d.invalidateQueries({queryKey:["forge-companion-overview"]})}}),k=P({mutationFn:async s=>ve(s.pairingSessionId,s.source,s.desiredEnabled),onSuccess:async()=>{await d.invalidateQueries({queryKey:["forge-companion-overview"]})}});if(u.useEffect(()=>{if(!r){N(null);return}ae.toDataURL(JSON.stringify(r.qrPayload),{width:320,margin:1}).then(N)},[r]),u.useEffect(()=>{y(!1),R(!1)},[r]),p.isLoading)return e.jsx(ge,{eyebrow:"Companion",title:"Loading mobile companion",description:"Checking pairing state and recent sync status.",columns:2,blocks:5});if(p.isError||!p.data)return e.jsx(fe,{eyebrow:"Companion",error:p.error??new Error("Companion overview unavailable"),onRetry:()=>void p.refetch()});const n=p.data,f=n.pairings.filter(s=>s.status!=="revoked"),M=n.pairings.length-f.length,z=r?JSON.stringify(r.qrPayload,null,2):"",Y=async()=>{if(r&&x){$(!1);return}if(r&&!x){$(!0);return}await c.mutateAsync("iroh")},Z=async()=>{await c.mutateAsync("manual-http")},ee=async()=>{if(z){if(!navigator.clipboard){y(!0);return}try{await navigator.clipboard.writeText(z),R(!0),window.setTimeout(()=>R(!1),1800)}catch{y(!0)}}};return e.jsxs("div",{className:"mx-auto grid min-w-0 w-full max-w-[1220px] gap-5 pb-24 lg:pb-0",children:[e.jsx(be,{title:"Mobile companion",description:"Pair the native iPhone companion, sync Apple Health, and keep the bridge open for watch and location signals.",badge:n.healthState.replaceAll("_"," ")}),e.jsx(we,{}),e.jsxs("section",{className:"grid min-w-0 gap-4",children:[null,e.jsxs(Q,{className:"grid min-w-0 gap-4 overflow-hidden",children:[e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:j,children:"Pair iPhone"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:"Pair your iPhone privately"}),e.jsx("div",{className:`mt-2 max-w-3xl text-sm leading-6 ${i}`,children:"Forge uses its own Iroh/QUIC companion route by default. Scan once from the iPhone app; manual HTTP stays as the advanced LAN or Tailscale path."})]}),e.jsxs("div",{className:"flex w-full flex-col gap-2 sm:w-auto sm:flex-row sm:flex-wrap sm:justify-end",children:[e.jsxs(m,{variant:"secondary",className:"w-full sm:w-auto",onClick:()=>void Z(),pending:c.isPending&&c.variables==="manual-http",pendingLabel:"Generating",children:[e.jsx(ie,{className:"size-4"}),"Advanced HTTP"]}),e.jsxs(m,{className:"w-full sm:w-auto",onClick:()=>void Y(),pending:c.isPending&&c.variables!=="manual-http",pendingLabel:"Generating",children:[e.jsx(ne,{className:"size-4"}),r?x?"Hide QR":"Show QR":"Generate Forge QR",r?x?e.jsx(_,{className:"size-4"}):e.jsx(D,{className:"size-4"}):null]})]})]}),x?e.jsxs("div",{className:"grid min-w-0 gap-4 overflow-hidden rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4 sm:p-5",children:[e.jsxs("div",{className:"grid min-w-0 gap-4 lg:grid-cols-[minmax(260px,360px)_1fr]",children:[b?e.jsxs("div",{className:"grid justify-items-center gap-4 rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-6 py-6 text-[var(--ui-ink-strong)]",children:[e.jsx("img",{src:b,alt:"Forge Companion pairing QR code",className:"w-full max-w-[320px]"}),e.jsx("div",{className:`max-w-[320px] text-center text-sm ${i}`,children:"Scan this code from Forge Companion on iPhone."})]}):e.jsx("div",{className:`${V} px-5 py-8 text-center text-sm ${i}`,children:"Generating the QR code now."}),e.jsxs("div",{className:"grid content-start gap-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[r?e.jsxs(t,{tone:Ce(r.qrPayload),children:[e.jsx(te,{className:"size-3"}),$e(r.qrPayload)]}):null,e.jsxs(t,{tone:"meta",children:[e.jsx(G,{className:"size-3"}),"One-time token"]})]}),e.jsxs("div",{className:`grid gap-3 text-sm leading-6 ${i}`,children:[e.jsxs("div",{className:"flex gap-3",children:[e.jsx(re,{className:`mt-1 size-4 shrink-0 ${v}`}),e.jsx("span",{children:"Open Forge Companion and choose Scan Forge QR."})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx(G,{className:`mt-1 size-4 shrink-0 ${v}`}),e.jsx("span",{children:"The iPhone receives the desktop node, relay hint, and pairing token for the Forge Iroh route."})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx(K,{className:`mt-1 size-4 shrink-0 ${v}`}),e.jsx("span",{children:"After verification, the app moves straight into native permissions and first sync."})]})]}),e.jsxs("div",{className:`flex flex-wrap items-center justify-between gap-3 ${w} p-4`,children:[e.jsx("div",{className:`text-sm ${i}`,children:r?e.jsxs("span",{children:["Expires"," ",new Date(r.qrPayload.expiresAt).toLocaleString(),"."]}):"Generate the one-time QR and scan it from the iPhone app."}),r?e.jsxs(m,{variant:"secondary",pending:c.isPending,pendingLabel:"Generating",onClick:()=>void c.mutateAsync("iroh"),children:[e.jsx(B,{className:"size-4"}),"Regenerate QR"]}):null]})]})]}),r?e.jsxs("div",{className:`grid gap-3 ${w} p-4 text-sm ${i}`,children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"max-w-2xl",children:[e.jsx("div",{className:"text-[var(--ui-ink-strong)]",children:"Fallback pairing payload"}),e.jsx("div",{className:`mt-1 text-xs leading-5 ${v}`,children:"Use this only when the iPhone camera cannot scan the QR. The payload contains the same Forge Iroh connection recipe."})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(m,{variant:"secondary",onClick:()=>void ee(),children:[F?e.jsx(K,{className:"size-4"}):e.jsx(le,{className:"size-4"}),F?"Copied":"Copy payload"]}),e.jsxs(m,{variant:"secondary",onClick:()=>y(s=>!s),children:[C?"Hide payload":"Show payload",C?e.jsx(_,{className:"size-4"}):e.jsx(D,{className:"size-4"})]})]})]}),C?e.jsx("pre",{className:"max-h-56 overflow-auto whitespace-pre-wrap break-words rounded-[16px] border border-[var(--ui-border-subtle)] bg-[var(--ui-code-bg)] p-3 font-mono text-[11px] leading-5 text-[var(--ui-code-text)]",children:z}):null]}):null]}):e.jsx("div",{className:`${V} px-5 py-6 text-sm leading-6 ${i}`,children:"Generate a one-time Forge QR when the iPhone is in your hand. The code expires automatically and can be regenerated anytime."})]}),e.jsxs(Q,{className:"grid min-w-0 gap-4 overflow-hidden",children:[e.jsx("div",{className:j,children:"Companion state"}),e.jsxs("div",{className:"grid min-w-0 max-w-full gap-3 md:grid-cols-3",children:[e.jsxs("div",{className:`${l} p-4`,children:[e.jsx("div",{className:`text-sm ${i}`,children:"Pairings"}),e.jsx("div",{className:"mt-2 font-display text-3xl text-[var(--ui-ink-strong)]",children:f.length}),M>0?e.jsxs("div",{className:`mt-2 text-xs ${v}`,children:[M," revoked hidden"]}):null]}),e.jsxs("div",{className:`${l} p-4`,children:[e.jsx("div",{className:`text-sm ${i}`,children:"Sleep sessions"}),e.jsx("div",{className:"mt-2 font-display text-3xl text-[var(--ui-ink-strong)]",children:n.counts.sleepSessions})]}),e.jsxs("div",{className:`${l} p-4`,children:[e.jsx("div",{className:`text-sm ${i}`,children:"Raw sleep records"}),e.jsx("div",{className:"mt-2 font-display text-3xl text-[var(--ui-ink-strong)]",children:n.counts.sleepRawRecords})]}),e.jsxs("div",{className:`${l} p-4`,children:[e.jsx("div",{className:`text-sm ${i}`,children:"Workouts"}),e.jsx("div",{className:"mt-2 font-display text-3xl text-[var(--ui-ink-strong)]",children:n.counts.workouts})]}),e.jsxs("div",{className:`${l} p-4`,children:[e.jsx("div",{className:`text-sm ${i}`,children:"Vitals days"}),e.jsx("div",{className:"mt-2 font-display text-3xl text-[var(--ui-ink-strong)]",children:n.counts.vitalsDaySummaries??0})]}),e.jsxs("div",{className:`${l} p-4`,children:[e.jsx("div",{className:`text-sm ${i}`,children:"Vital entries"}),e.jsx("div",{className:"mt-2 font-display text-3xl text-[var(--ui-ink-strong)]",children:n.counts.vitalsMetricEntries??0})]}),e.jsxs("div",{className:`${l} p-4`,children:[e.jsx("div",{className:`text-sm ${i}`,children:"Reflected sleep"}),e.jsx("div",{className:"mt-2 font-display text-3xl text-[var(--ui-ink-strong)]",children:n.counts.reflectiveSleepSessions})]}),e.jsxs("div",{className:`${l} p-4`,children:[e.jsx("div",{className:`text-sm ${i}`,children:"Linked workouts"}),e.jsx("div",{className:"mt-2 font-display text-3xl text-[var(--ui-ink-strong)]",children:n.counts.linkedWorkouts})]}),e.jsxs("div",{className:`${l} p-4`,children:[e.jsx("div",{className:`text-sm ${i}`,children:"Habit-generated"}),e.jsx("div",{className:"mt-2 font-display text-3xl text-[var(--ui-ink-strong)]",children:n.counts.habitGeneratedWorkouts})]}),e.jsxs("div",{className:`${l} p-4`,children:[e.jsx("div",{className:`text-sm ${i}`,children:"Reconciled"}),e.jsx("div",{className:"mt-2 font-display text-3xl text-[var(--ui-ink-strong)]",children:n.counts.reconciledWorkouts})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(t,{children:n.healthState.replaceAll("_"," ")}),n.lastSyncAt?e.jsxs(t,{tone:"meta",children:["Last sync ",new Date(n.lastSyncAt).toLocaleString()]}):null,e.jsxs(t,{tone:J(n.permissions.healthKitAuthorized),children:["HealthKit"," ",n.permissions.healthKitAuthorized?"ready":"needed"]}),e.jsxs(t,{tone:J(n.permissions.backgroundRefreshEnabled),children:["Background refresh"," ",n.permissions.backgroundRefreshEnabled?"ready":"not yet"]}),e.jsxs(t,{tone:"meta",children:["Location ",n.permissions.locationReady?"ready":"later"]}),e.jsxs(t,{tone:"meta",children:["Motion ",n.permissions.motionReady?"ready":"later"]})]}),e.jsxs("div",{className:`grid gap-3 ${w} p-4`,children:[e.jsx("div",{className:j,children:"Pairing path"}),e.jsxs("div",{className:`grid gap-2 text-sm ${i}`,children:[e.jsx("div",{children:"1. Generate the Forge QR from this page."}),e.jsx("div",{children:"2. Scan it in Forge Companion to pass the desktop node and pairing token."}),e.jsx("div",{children:"3. Approve Health access on iPhone, then run the first sync."}),e.jsx("div",{children:"4. Use Advanced HTTP only for a local, Tailscale, or direct TCP route."})]})]}),e.jsxs("div",{className:"grid min-w-0 gap-3",children:[f.length>0?e.jsx("div",{className:"flex min-w-0 max-w-full justify-end overflow-hidden",children:e.jsxs(m,{variant:"secondary",pending:I.isPending,pendingLabel:"Revoking all",onClick:()=>void I.mutateAsync(),children:[e.jsx(W,{className:"size-4"}),"Revoke all"]})}):null,f.map(s=>e.jsxs("div",{className:`grid min-w-0 max-w-full gap-3 overflow-hidden ${l} px-4 py-4`,children:[e.jsxs("div",{className:"flex min-w-0 max-w-full flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-base text-[var(--ui-ink-strong)]",children:s.deviceName??s.label}),e.jsxs("div",{className:`mt-1 text-sm ${i}`,children:[s.platform??"ios"," · ",s.status]})]}),e.jsxs("div",{className:"flex min-w-0 flex-wrap gap-2",children:[e.jsx(t,{tone:s.status==="healthy"?"signal":"meta",children:s.status.replaceAll("_"," ")}),s.lastSyncAt?e.jsxs(t,{tone:"meta",children:["Synced ",new Date(s.lastSyncAt).toLocaleString()]}):null]})]}),e.jsx("div",{className:"flex min-w-0 max-w-full flex-wrap gap-2 overflow-hidden",children:s.capabilities.map(h=>e.jsx(t,{tone:"meta",size:"sm",wrap:!0,children:Ne(h)},h))}),e.jsxs("div",{className:`flex min-w-0 max-w-full flex-wrap items-center justify-between gap-3 overflow-hidden text-sm ${i}`,children:[e.jsxs("div",{className:"grid min-w-0 max-w-full flex-1 basis-[16rem] gap-1",children:[e.jsx("div",{className:"min-w-0 max-w-full break-all [overflow-wrap:anywhere]",children:s.apiBaseUrl}),e.jsxs("div",{className:"min-w-0 max-w-full break-words [overflow-wrap:anywhere]",children:["Expires ",new Date(s.expiresAt).toLocaleString()]}),s.lastSyncError?e.jsx("div",{className:"text-[color-mix(in_srgb,var(--danger)_76%,var(--ui-ink-strong)_24%)]",children:s.lastSyncError}):null]}),e.jsxs(m,{variant:"secondary",pending:A.isPending&&A.variables===s.id,pendingLabel:"Revoking",disabled:s.status==="revoked",onClick:()=>void A.mutateAsync(s.id),children:[e.jsx(W,{className:"size-4"}),s.status==="revoked"?"Revoked":"Revoke"]})]}),e.jsxs("div",{className:"grid min-w-0 gap-3 rounded-[16px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-3",children:[e.jsx("div",{className:j,children:"Device sync sources"}),[["health","Health"],["movement","Movement"],["screenTime","Screen Time"]].map(([h,O])=>{var H,U;const o=s.sourceStates[h],se=o.desiredEnabled!==o.appliedEnabled,q=k.isPending&&((H=k.variables)==null?void 0:H.pairingSessionId)===s.id&&((U=k.variables)==null?void 0:U.source)===h;return e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 rounded-[14px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-3 py-3",children:[e.jsxs("div",{className:"grid min-w-0 gap-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-strong)]",children:O}),e.jsx(t,{tone:Se(o.desiredEnabled,o.syncEligible),size:"sm",children:o.desiredEnabled?"Enabled":"Off"}),se?e.jsx(t,{tone:"meta",size:"sm",children:"Pending on phone"}):e.jsx(t,{tone:"meta",size:"sm",children:"Applied"})]}),e.jsxs("div",{className:`break-words text-xs [overflow-wrap:anywhere] ${i}`,children:["Authorization"," ",ke(o.authorizationStatus)," · ","Last seen"," ",Pe(o.lastObservedAt)]})]}),e.jsx("button",{type:"button",role:"switch","aria-checked":o.desiredEnabled,"aria-label":`${O} sync source`,disabled:q,onClick:()=>void k.mutateAsync({pairingSessionId:s.id,source:h,desiredEnabled:!o.desiredEnabled}),className:`relative inline-flex h-7 w-12 items-center rounded-full border transition ${o.desiredEnabled?"border-[color-mix(in_srgb,var(--primary)_45%,var(--ui-border-subtle)_55%)] bg-[var(--ui-accent-soft)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-3)]"} ${q?"opacity-60":""}`,children:e.jsx("span",{className:`inline-block size-5 rounded-full bg-[var(--ui-ink-strong)] shadow transition ${o.desiredEnabled?"translate-x-6":"translate-x-1"}`})})]},h)})]})]},s.id)),f.length===0?e.jsx("div",{className:`${w} px-4 py-6 text-sm ${i}`,children:"No companion paired yet. Generate a QR code, then open the iOS companion and scan it."}):null]}),e.jsxs("div",{className:"flex flex-wrap gap-3",children:[e.jsxs(m,{variant:"secondary",onClick:()=>void p.refetch(),children:[e.jsx(B,{className:"size-4"}),"Refresh status"]}),e.jsxs(E,{to:"/sleep",className:T,children:[e.jsx(L,{className:"size-4"}),"Open sleep view"]}),e.jsxs(E,{to:"/sports",className:T,children:[e.jsx(L,{className:"size-4"}),"Open sports view"]}),e.jsxs(E,{to:"/vitals",className:T,children:[e.jsx(L,{className:"size-4"}),"Open vitals view"]})]})]})]}),e.jsxs(Q,{className:"grid min-w-0 gap-4 overflow-hidden",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:j,children:"Sync history"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:"Recent HealthKit import runs"})]}),e.jsxs(t,{tone:"meta",children:[n.importRuns.length," recent runs"]})]}),e.jsxs("div",{className:"grid min-w-0 gap-3",children:[n.importRuns.map(s=>e.jsxs("div",{className:`grid gap-3 ${l} px-4 py-4 lg:grid-cols-[minmax(0,1fr)_auto]`,children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(oe,{className:`size-4 ${v}`}),e.jsxs("div",{className:"text-base text-[var(--ui-ink-strong)]",children:[s.sourceDevice||"iPhone"," import"]}),e.jsx(t,{tone:s.status==="completed"?"signal":"meta",children:s.status})]}),e.jsxs("div",{className:`break-words text-sm [overflow-wrap:anywhere] ${i}`,children:[new Date(s.importedAt).toLocaleString()," ·"," ",ye(s.payloadSummary)]}),e.jsxs("div",{className:`flex flex-wrap gap-2 text-sm ${i}`,children:[e.jsxs(t,{tone:"meta",children:["Imported ",s.importedCount]}),e.jsxs(t,{tone:"meta",children:["Created ",s.createdCount]}),e.jsxs(t,{tone:"meta",children:["Updated ",s.updatedCount]}),e.jsxs(t,{tone:"meta",children:["Merged ",s.mergedCount]})]}),s.errorMessage?e.jsx("div",{className:"text-sm text-[color-mix(in_srgb,var(--danger)_76%,var(--ui-ink-strong)_24%)]",children:s.errorMessage}):null]}),s.pairingSessionId?e.jsxs("div",{className:`break-words text-sm [overflow-wrap:anywhere] ${v} lg:text-right`,children:["Pairing ",s.pairingSessionId]}):null]},s.id)),n.importRuns.length===0?e.jsx("div",{className:`${w} px-4 py-6 text-sm ${i}`,children:"No sync runs yet. Pair the iPhone companion and run the first HealthKit import."}):null]})]})]})}export{Oe as SettingsMobilePage};
1
+ import{r as u,dh as ae,j as e,di as ie,dj as ne,cw as _,cx as D,dg as te,dk as G,dl as re,bl as K,bK as B,dm as le,dn as W,aC as E,cb as L,dp as oe}from"./vendor-Dnkkx2co.js";import{j as de,i as ce,k as P}from"./state-vCcAT5Hq.js";import{u as me,s as xe,eb as pe,ec as he,ed as ue,ee as ve,S as ge,E as fe,C as Q,B as m,c as t,dw as je}from"./index-QJkjKYzZ.js";import{S as we}from"./settings-section-nav-Co0AaDG-.js";import{P as be}from"./page-hero-CONuJu5J.js";import"./motion-Lt5B1XuE.js";import"./ui-C1iwpj2-.js";import"./forms-hB0SqEh-.js";import"./board-dIX6etHh.js";import"./graph-DDUZNRsO.js";function Ne(a){return a.replaceAll("."," ")}function ye(a){const d=typeof a.sleepNights=="number"?a.sleepNights:typeof a.sleepSessions=="number"?a.sleepSessions:0,g=typeof a.sleepSegments=="number"?a.sleepSegments:0,S=typeof a.sleepRawRecords=="number"?a.sleepRawRecords:0,b=typeof a.sleepSessions=="number"?a.sleepSessions:0,N=typeof a.workouts=="number"?a.workouts:0,x=a.vitals&&typeof a.vitals=="object"&&!Array.isArray(a.vitals)&&typeof a.vitals.metricEntries=="number"?a.vitals.metricEntries:0;return`${d||b} nights · ${g} segments · ${S} raw records · ${N} workouts · ${x} vitals`}function J(a){return a?"signal":"meta"}function ke(a){return a.replaceAll("_"," ")}function Pe(a){return a?new Date(a).toLocaleString():"Waiting for device update"}function Se(a,d){return a?d?"signal":"default":"meta"}function $e(a){return a.transportMode==="iroh"?"Iroh":"Manual HTTP"}function Ce(a){return a.transportMode==="iroh"?"signal":"meta"}const j="font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",i="text-[var(--ui-ink-soft)]",v="text-[var(--ui-ink-faint)]",l="rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",w="rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)]",V="rounded-[24px] border border-dashed border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",T="inline-flex min-h-11 items-center gap-2 rounded-[16px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-3 text-sm text-[var(--ui-ink-medium)] transition hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]";function Oe(){const a=me(),d=de(),g=Array.isArray(a.selectedUserIds)?a.selectedUserIds:[],S=xe(g),[b,N]=u.useState(null),[x,$]=u.useState(!1),[C,y]=u.useState(!1),[F,R]=u.useState(!1),[r,X]=u.useState(null),p=ce({queryKey:["forge-companion-overview",...g],queryFn:async()=>(await je(g)).overview}),c=P({mutationFn:async(s="iroh")=>pe({userId:S??null,transportMode:s}),onSuccess:async s=>{X({qrPayload:s.qrPayload}),$(!0),await d.invalidateQueries({queryKey:["forge-companion-overview"]})}}),A=P({mutationFn:async s=>he(s),onSuccess:async()=>{await d.invalidateQueries({queryKey:["forge-companion-overview"]})}}),I=P({mutationFn:async()=>ue({userIds:g,includeRevoked:!1}),onSuccess:async()=>{await d.invalidateQueries({queryKey:["forge-companion-overview"]})}}),k=P({mutationFn:async s=>ve(s.pairingSessionId,s.source,s.desiredEnabled),onSuccess:async()=>{await d.invalidateQueries({queryKey:["forge-companion-overview"]})}});if(u.useEffect(()=>{if(!r){N(null);return}ae.toDataURL(JSON.stringify(r.qrPayload),{width:320,margin:1}).then(N)},[r]),u.useEffect(()=>{y(!1),R(!1)},[r]),p.isLoading)return e.jsx(ge,{eyebrow:"Companion",title:"Loading mobile companion",description:"Checking pairing state and recent sync status.",columns:2,blocks:5});if(p.isError||!p.data)return e.jsx(fe,{eyebrow:"Companion",error:p.error??new Error("Companion overview unavailable"),onRetry:()=>void p.refetch()});const n=p.data,f=n.pairings.filter(s=>s.status!=="revoked"),M=n.pairings.length-f.length,z=r?JSON.stringify(r.qrPayload,null,2):"",Y=async()=>{if(r&&x){$(!1);return}if(r&&!x){$(!0);return}await c.mutateAsync("iroh")},Z=async()=>{await c.mutateAsync("manual-http")},ee=async()=>{if(z){if(!navigator.clipboard){y(!0);return}try{await navigator.clipboard.writeText(z),R(!0),window.setTimeout(()=>R(!1),1800)}catch{y(!0)}}};return e.jsxs("div",{className:"mx-auto grid min-w-0 w-full max-w-[1220px] gap-5 pb-24 lg:pb-0",children:[e.jsx(be,{title:"Mobile companion",description:"Pair the native iPhone companion, sync Apple Health, and keep the bridge open for watch and location signals.",badge:n.healthState.replaceAll("_"," ")}),e.jsx(we,{}),e.jsxs("section",{className:"grid min-w-0 gap-4",children:[null,e.jsxs(Q,{className:"grid min-w-0 gap-4 overflow-hidden",children:[e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:j,children:"Pair iPhone"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:"Pair your iPhone privately"}),e.jsx("div",{className:`mt-2 max-w-3xl text-sm leading-6 ${i}`,children:"Forge uses its own Iroh/QUIC companion route by default. Scan once from the iPhone app; manual HTTP stays as the advanced LAN or Tailscale path."})]}),e.jsxs("div",{className:"flex w-full flex-col gap-2 sm:w-auto sm:flex-row sm:flex-wrap sm:justify-end",children:[e.jsxs(m,{variant:"secondary",className:"w-full sm:w-auto",onClick:()=>void Z(),pending:c.isPending&&c.variables==="manual-http",pendingLabel:"Generating",children:[e.jsx(ie,{className:"size-4"}),"Advanced HTTP"]}),e.jsxs(m,{className:"w-full sm:w-auto",onClick:()=>void Y(),pending:c.isPending&&c.variables!=="manual-http",pendingLabel:"Generating",children:[e.jsx(ne,{className:"size-4"}),r?x?"Hide QR":"Show QR":"Generate Forge QR",r?x?e.jsx(_,{className:"size-4"}):e.jsx(D,{className:"size-4"}):null]})]})]}),x?e.jsxs("div",{className:"grid min-w-0 gap-4 overflow-hidden rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4 sm:p-5",children:[e.jsxs("div",{className:"grid min-w-0 gap-4 lg:grid-cols-[minmax(260px,360px)_1fr]",children:[b?e.jsxs("div",{className:"grid justify-items-center gap-4 rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-6 py-6 text-[var(--ui-ink-strong)]",children:[e.jsx("img",{src:b,alt:"Forge Companion pairing QR code",className:"w-full max-w-[320px]"}),e.jsx("div",{className:`max-w-[320px] text-center text-sm ${i}`,children:"Scan this code from Forge Companion on iPhone."})]}):e.jsx("div",{className:`${V} px-5 py-8 text-center text-sm ${i}`,children:"Generating the QR code now."}),e.jsxs("div",{className:"grid content-start gap-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[r?e.jsxs(t,{tone:Ce(r.qrPayload),children:[e.jsx(te,{className:"size-3"}),$e(r.qrPayload)]}):null,e.jsxs(t,{tone:"meta",children:[e.jsx(G,{className:"size-3"}),"One-time token"]})]}),e.jsxs("div",{className:`grid gap-3 text-sm leading-6 ${i}`,children:[e.jsxs("div",{className:"flex gap-3",children:[e.jsx(re,{className:`mt-1 size-4 shrink-0 ${v}`}),e.jsx("span",{children:"Open Forge Companion and choose Scan Forge QR."})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx(G,{className:`mt-1 size-4 shrink-0 ${v}`}),e.jsx("span",{children:"The iPhone receives the desktop node, relay hint, and pairing token for the Forge Iroh route."})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx(K,{className:`mt-1 size-4 shrink-0 ${v}`}),e.jsx("span",{children:"After verification, the app moves straight into native permissions and first sync."})]})]}),e.jsxs("div",{className:`flex flex-wrap items-center justify-between gap-3 ${w} p-4`,children:[e.jsx("div",{className:`text-sm ${i}`,children:r?e.jsxs("span",{children:["Expires"," ",new Date(r.qrPayload.expiresAt).toLocaleString(),"."]}):"Generate the one-time QR and scan it from the iPhone app."}),r?e.jsxs(m,{variant:"secondary",pending:c.isPending,pendingLabel:"Generating",onClick:()=>void c.mutateAsync("iroh"),children:[e.jsx(B,{className:"size-4"}),"Regenerate QR"]}):null]})]})]}),r?e.jsxs("div",{className:`grid gap-3 ${w} p-4 text-sm ${i}`,children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"max-w-2xl",children:[e.jsx("div",{className:"text-[var(--ui-ink-strong)]",children:"Fallback pairing payload"}),e.jsx("div",{className:`mt-1 text-xs leading-5 ${v}`,children:"Use this only when the iPhone camera cannot scan the QR. The payload contains the same Forge Iroh connection recipe."})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(m,{variant:"secondary",onClick:()=>void ee(),children:[F?e.jsx(K,{className:"size-4"}):e.jsx(le,{className:"size-4"}),F?"Copied":"Copy payload"]}),e.jsxs(m,{variant:"secondary",onClick:()=>y(s=>!s),children:[C?"Hide payload":"Show payload",C?e.jsx(_,{className:"size-4"}):e.jsx(D,{className:"size-4"})]})]})]}),C?e.jsx("pre",{className:"max-h-56 overflow-auto whitespace-pre-wrap break-words rounded-[16px] border border-[var(--ui-border-subtle)] bg-[var(--ui-code-bg)] p-3 font-mono text-[11px] leading-5 text-[var(--ui-code-text)]",children:z}):null]}):null]}):e.jsx("div",{className:`${V} px-5 py-6 text-sm leading-6 ${i}`,children:"Generate a one-time Forge QR when the iPhone is in your hand. The code expires automatically and can be regenerated anytime."})]}),e.jsxs(Q,{className:"grid min-w-0 gap-4 overflow-hidden",children:[e.jsx("div",{className:j,children:"Companion state"}),e.jsxs("div",{className:"grid min-w-0 max-w-full gap-3 md:grid-cols-3",children:[e.jsxs("div",{className:`${l} p-4`,children:[e.jsx("div",{className:`text-sm ${i}`,children:"Pairings"}),e.jsx("div",{className:"mt-2 font-display text-3xl text-[var(--ui-ink-strong)]",children:f.length}),M>0?e.jsxs("div",{className:`mt-2 text-xs ${v}`,children:[M," revoked hidden"]}):null]}),e.jsxs("div",{className:`${l} p-4`,children:[e.jsx("div",{className:`text-sm ${i}`,children:"Sleep sessions"}),e.jsx("div",{className:"mt-2 font-display text-3xl text-[var(--ui-ink-strong)]",children:n.counts.sleepSessions})]}),e.jsxs("div",{className:`${l} p-4`,children:[e.jsx("div",{className:`text-sm ${i}`,children:"Raw sleep records"}),e.jsx("div",{className:"mt-2 font-display text-3xl text-[var(--ui-ink-strong)]",children:n.counts.sleepRawRecords})]}),e.jsxs("div",{className:`${l} p-4`,children:[e.jsx("div",{className:`text-sm ${i}`,children:"Workouts"}),e.jsx("div",{className:"mt-2 font-display text-3xl text-[var(--ui-ink-strong)]",children:n.counts.workouts})]}),e.jsxs("div",{className:`${l} p-4`,children:[e.jsx("div",{className:`text-sm ${i}`,children:"Vitals days"}),e.jsx("div",{className:"mt-2 font-display text-3xl text-[var(--ui-ink-strong)]",children:n.counts.vitalsDaySummaries??0})]}),e.jsxs("div",{className:`${l} p-4`,children:[e.jsx("div",{className:`text-sm ${i}`,children:"Vital entries"}),e.jsx("div",{className:"mt-2 font-display text-3xl text-[var(--ui-ink-strong)]",children:n.counts.vitalsMetricEntries??0})]}),e.jsxs("div",{className:`${l} p-4`,children:[e.jsx("div",{className:`text-sm ${i}`,children:"Reflected sleep"}),e.jsx("div",{className:"mt-2 font-display text-3xl text-[var(--ui-ink-strong)]",children:n.counts.reflectiveSleepSessions})]}),e.jsxs("div",{className:`${l} p-4`,children:[e.jsx("div",{className:`text-sm ${i}`,children:"Linked workouts"}),e.jsx("div",{className:"mt-2 font-display text-3xl text-[var(--ui-ink-strong)]",children:n.counts.linkedWorkouts})]}),e.jsxs("div",{className:`${l} p-4`,children:[e.jsx("div",{className:`text-sm ${i}`,children:"Habit-generated"}),e.jsx("div",{className:"mt-2 font-display text-3xl text-[var(--ui-ink-strong)]",children:n.counts.habitGeneratedWorkouts})]}),e.jsxs("div",{className:`${l} p-4`,children:[e.jsx("div",{className:`text-sm ${i}`,children:"Reconciled"}),e.jsx("div",{className:"mt-2 font-display text-3xl text-[var(--ui-ink-strong)]",children:n.counts.reconciledWorkouts})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(t,{children:n.healthState.replaceAll("_"," ")}),n.lastSyncAt?e.jsxs(t,{tone:"meta",children:["Last sync ",new Date(n.lastSyncAt).toLocaleString()]}):null,e.jsxs(t,{tone:J(n.permissions.healthKitAuthorized),children:["HealthKit"," ",n.permissions.healthKitAuthorized?"ready":"needed"]}),e.jsxs(t,{tone:J(n.permissions.backgroundRefreshEnabled),children:["Background refresh"," ",n.permissions.backgroundRefreshEnabled?"ready":"not yet"]}),e.jsxs(t,{tone:"meta",children:["Location ",n.permissions.locationReady?"ready":"later"]}),e.jsxs(t,{tone:"meta",children:["Motion ",n.permissions.motionReady?"ready":"later"]})]}),e.jsxs("div",{className:`grid gap-3 ${w} p-4`,children:[e.jsx("div",{className:j,children:"Pairing path"}),e.jsxs("div",{className:`grid gap-2 text-sm ${i}`,children:[e.jsx("div",{children:"1. Generate the Forge QR from this page."}),e.jsx("div",{children:"2. Scan it in Forge Companion to pass the desktop node and pairing token."}),e.jsx("div",{children:"3. Approve Health access on iPhone, then run the first sync."}),e.jsx("div",{children:"4. Use Advanced HTTP only for a local, Tailscale, or direct TCP route."})]})]}),e.jsxs("div",{className:"grid min-w-0 gap-3",children:[f.length>0?e.jsx("div",{className:"flex min-w-0 max-w-full justify-end overflow-hidden",children:e.jsxs(m,{variant:"secondary",pending:I.isPending,pendingLabel:"Revoking all",onClick:()=>void I.mutateAsync(),children:[e.jsx(W,{className:"size-4"}),"Revoke all"]})}):null,f.map(s=>e.jsxs("div",{className:`grid min-w-0 max-w-full gap-3 overflow-hidden ${l} px-4 py-4`,children:[e.jsxs("div",{className:"flex min-w-0 max-w-full flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-base text-[var(--ui-ink-strong)]",children:s.deviceName??s.label}),e.jsxs("div",{className:`mt-1 text-sm ${i}`,children:[s.platform??"ios"," · ",s.status]})]}),e.jsxs("div",{className:"flex min-w-0 flex-wrap gap-2",children:[e.jsx(t,{tone:s.status==="healthy"?"signal":"meta",children:s.status.replaceAll("_"," ")}),s.lastSyncAt?e.jsxs(t,{tone:"meta",children:["Synced ",new Date(s.lastSyncAt).toLocaleString()]}):null]})]}),e.jsx("div",{className:"flex min-w-0 max-w-full flex-wrap gap-2 overflow-hidden",children:s.capabilities.map(h=>e.jsx(t,{tone:"meta",size:"sm",wrap:!0,children:Ne(h)},h))}),e.jsxs("div",{className:`flex min-w-0 max-w-full flex-wrap items-center justify-between gap-3 overflow-hidden text-sm ${i}`,children:[e.jsxs("div",{className:"grid min-w-0 max-w-full flex-1 basis-[16rem] gap-1",children:[e.jsx("div",{className:"min-w-0 max-w-full break-all [overflow-wrap:anywhere]",children:s.apiBaseUrl}),e.jsxs("div",{className:"min-w-0 max-w-full break-words [overflow-wrap:anywhere]",children:["Expires ",new Date(s.expiresAt).toLocaleString()]}),s.lastSyncError?e.jsx("div",{className:"text-[color-mix(in_srgb,var(--danger)_76%,var(--ui-ink-strong)_24%)]",children:s.lastSyncError}):null]}),e.jsxs(m,{variant:"secondary",pending:A.isPending&&A.variables===s.id,pendingLabel:"Revoking",disabled:s.status==="revoked",onClick:()=>void A.mutateAsync(s.id),children:[e.jsx(W,{className:"size-4"}),s.status==="revoked"?"Revoked":"Revoke"]})]}),e.jsxs("div",{className:"grid min-w-0 gap-3 rounded-[16px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-3",children:[e.jsx("div",{className:j,children:"Device sync sources"}),[["health","Health"],["movement","Movement"],["screenTime","Screen Time"]].map(([h,O])=>{var H,U;const o=s.sourceStates[h],se=o.desiredEnabled!==o.appliedEnabled,q=k.isPending&&((H=k.variables)==null?void 0:H.pairingSessionId)===s.id&&((U=k.variables)==null?void 0:U.source)===h;return e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 rounded-[14px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-3 py-3",children:[e.jsxs("div",{className:"grid min-w-0 gap-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-strong)]",children:O}),e.jsx(t,{tone:Se(o.desiredEnabled,o.syncEligible),size:"sm",children:o.desiredEnabled?"Enabled":"Off"}),se?e.jsx(t,{tone:"meta",size:"sm",children:"Pending on phone"}):e.jsx(t,{tone:"meta",size:"sm",children:"Applied"})]}),e.jsxs("div",{className:`break-words text-xs [overflow-wrap:anywhere] ${i}`,children:["Authorization"," ",ke(o.authorizationStatus)," · ","Last seen"," ",Pe(o.lastObservedAt)]})]}),e.jsx("button",{type:"button",role:"switch","aria-checked":o.desiredEnabled,"aria-label":`${O} sync source`,disabled:q,onClick:()=>void k.mutateAsync({pairingSessionId:s.id,source:h,desiredEnabled:!o.desiredEnabled}),className:`relative inline-flex h-7 w-12 items-center rounded-full border transition ${o.desiredEnabled?"border-[color-mix(in_srgb,var(--primary)_45%,var(--ui-border-subtle)_55%)] bg-[var(--ui-accent-soft)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-3)]"} ${q?"opacity-60":""}`,children:e.jsx("span",{className:`inline-block size-5 rounded-full bg-[var(--ui-ink-strong)] shadow transition ${o.desiredEnabled?"translate-x-6":"translate-x-1"}`})})]},h)})]})]},s.id)),f.length===0?e.jsx("div",{className:`${w} px-4 py-6 text-sm ${i}`,children:"No companion paired yet. Generate a QR code, then open the iOS companion and scan it."}):null]}),e.jsxs("div",{className:"flex flex-wrap gap-3",children:[e.jsxs(m,{variant:"secondary",onClick:()=>void p.refetch(),children:[e.jsx(B,{className:"size-4"}),"Refresh status"]}),e.jsxs(E,{to:"/sleep",className:T,children:[e.jsx(L,{className:"size-4"}),"Open sleep view"]}),e.jsxs(E,{to:"/sports",className:T,children:[e.jsx(L,{className:"size-4"}),"Open sports view"]}),e.jsxs(E,{to:"/vitals",className:T,children:[e.jsx(L,{className:"size-4"}),"Open vitals view"]})]})]})]}),e.jsxs(Q,{className:"grid min-w-0 gap-4 overflow-hidden",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:j,children:"Sync history"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:"Recent HealthKit import runs"})]}),e.jsxs(t,{tone:"meta",children:[n.importRuns.length," recent runs"]})]}),e.jsxs("div",{className:"grid min-w-0 gap-3",children:[n.importRuns.map(s=>e.jsxs("div",{className:`grid gap-3 ${l} px-4 py-4 lg:grid-cols-[minmax(0,1fr)_auto]`,children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(oe,{className:`size-4 ${v}`}),e.jsxs("div",{className:"text-base text-[var(--ui-ink-strong)]",children:[s.sourceDevice||"iPhone"," import"]}),e.jsx(t,{tone:s.status==="completed"?"signal":"meta",children:s.status})]}),e.jsxs("div",{className:`break-words text-sm [overflow-wrap:anywhere] ${i}`,children:[new Date(s.importedAt).toLocaleString()," ·"," ",ye(s.payloadSummary)]}),e.jsxs("div",{className:`flex flex-wrap gap-2 text-sm ${i}`,children:[e.jsxs(t,{tone:"meta",children:["Imported ",s.importedCount]}),e.jsxs(t,{tone:"meta",children:["Created ",s.createdCount]}),e.jsxs(t,{tone:"meta",children:["Updated ",s.updatedCount]}),e.jsxs(t,{tone:"meta",children:["Merged ",s.mergedCount]})]}),s.errorMessage?e.jsx("div",{className:"text-sm text-[color-mix(in_srgb,var(--danger)_76%,var(--ui-ink-strong)_24%)]",children:s.errorMessage}):null]}),s.pairingSessionId?e.jsxs("div",{className:`break-words text-sm [overflow-wrap:anywhere] ${v} lg:text-right`,children:["Pairing ",s.pairingSessionId]}):null]},s.id)),n.importRuns.length===0?e.jsx("div",{className:`${w} px-4 py-6 text-sm ${i}`,children:"No sync runs yet. Pair the iPhone companion and run the first HealthKit import."}):null]})]})]})}export{Oe as SettingsMobilePage};