forge-openclaw-plugin 0.3.2 → 0.3.4

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 (214) hide show
  1. package/dist/assets/action-bar-CMGr_Uv_.js +1 -0
  2. package/dist/assets/activity-page-DwGKkJtr.js +1 -0
  3. package/dist/assets/ai-surface-workspace-UtnoNmjq.js +1 -0
  4. package/dist/assets/{atlas-panel-G3wGxjYf.js → atlas-panel-f1kc-LkD.js} +1 -1
  5. package/dist/assets/{board-dIX6etHh.js → board-CLOHbg6t.js} +1 -1
  6. package/dist/assets/calendar-page-C4YqeVrC.js +1 -0
  7. package/dist/assets/calendar-rules-BQppCPiN.js +1 -0
  8. package/dist/assets/{calendar-week-toolbar-CWSK5hJl.js → calendar-week-toolbar-DdPuHUwd.js} +1 -1
  9. package/dist/assets/{charts-DFnEuIMB.js → charts-DwTguE_x.js} +1 -1
  10. package/dist/assets/companion-sync-lab-page-N3cR33GS.js +1 -0
  11. package/dist/assets/daily-metrics-dashboard-CXnAtN2T.js +1 -0
  12. package/dist/assets/define-workbench-box-DkffygDU.js +1 -0
  13. package/dist/assets/entity-link-multiselect-wuyJ8BbW.js +1 -0
  14. package/dist/assets/{entity-note-count-link-ef3ZOpKM.js → entity-note-count-link-CEtKyMAl.js} +1 -1
  15. package/dist/assets/entity-notes-surface-iKNiierJ.js +1 -0
  16. package/dist/assets/execution-board-DesFZ1f5.js +1 -0
  17. package/dist/assets/{faceted-token-search-CZmtyJTT.js → faceted-token-search-D4Okr-Kr.js} +1 -1
  18. package/dist/assets/{flagship-signal-deck-DxRfmfpN.js → flagship-signal-deck-CW91n6u9.js} +1 -1
  19. package/dist/assets/{floating-action-menu-cKjNsPYD.js → floating-action-menu-GCeuOdYZ.js} +1 -1
  20. package/dist/assets/{forms-hB0SqEh-.js → forms-C5d5hTf2.js} +1 -1
  21. package/dist/assets/generic-node-view-COhU_Wm3.js +10 -0
  22. package/dist/assets/goal-detail-page-Bd8JU3IK.js +1 -0
  23. package/dist/assets/goal-dialog-CLz5fYhO.js +1 -0
  24. package/dist/assets/goals-page-CZHNVyY-.js +1 -0
  25. package/dist/assets/{graph-DDUZNRsO.js → graph-Cd5WF3lw.js} +1 -1
  26. package/dist/assets/habits-page-CXiBB7_N.js +1 -0
  27. package/dist/assets/health-boxes-BUcsxDLh.js +1 -0
  28. package/dist/assets/index-BejvcRGb.js +2 -0
  29. package/dist/assets/{index-Bcem7l5u.css → index-CEgIwgk9.css} +1 -1
  30. package/dist/assets/inline-note-fields-CcRDO3pd.js +1 -0
  31. package/dist/assets/insight-flow-dialog-DUBk2MR8.js +1 -0
  32. package/dist/assets/{insights-page-DHG-o9P_.js → insights-page-8fLhCYsM.js} +3 -3
  33. package/dist/assets/kanban-boxes-CH7plRk1.js +1 -0
  34. package/dist/assets/kanban-page-Bq-aYwUL.js +1 -0
  35. package/dist/assets/knowledge-graph-page-DYFfWh4Y.js +1 -0
  36. package/dist/assets/life-force-page-D80rgBBR.js +1 -0
  37. package/dist/assets/{life-force-workspace-sszLD-Yn.js → life-force-workspace-CcmZRRfU.js} +1 -1
  38. package/dist/assets/{maps-C-yOWiDN.js → maps-D0Mm6WPG.js} +1 -1
  39. package/dist/assets/{metric-tile-B-tDTcBt.js → metric-tile-DysHMgM3.js} +1 -1
  40. package/dist/assets/{motion-Lt5B1XuE.js → motion-DwjmC9aq.js} +1 -1
  41. package/dist/assets/movement-boxes-BH3botKt.js +1 -0
  42. package/dist/assets/movement-page-D5KLMKS9.js +1 -0
  43. package/dist/assets/{note-markdown-CCyyE85h.js → note-markdown-Byd_vNkS.js} +1 -1
  44. package/dist/assets/note-tags-input-DYAFDq8Q.js +1 -0
  45. package/dist/assets/notes-boxes-CPiPps1e.js +1 -0
  46. package/dist/assets/notes-page-DehVrOOb.js +1 -0
  47. package/dist/assets/{open-in-graph-button-CMjJZX7G.js → open-in-graph-button-L21MKsb5.js} +1 -1
  48. package/dist/assets/{orbit-map-v2Pv9RU_.js → orbit-map-ChJOQ8CN.js} +1 -1
  49. package/dist/assets/overview-page-D_ewyeWF.js +1 -0
  50. package/dist/assets/page-hero-DlHEJ0Yt.js +1 -0
  51. package/dist/assets/pill-cluster-DhOR4m7X.js +1 -0
  52. package/dist/assets/{preference-entity-handoff-button-CKDxCnbl.js → preference-entity-handoff-button-ugHU2us9.js} +1 -1
  53. package/dist/assets/preferences-page-BTTXeSDR.js +1 -0
  54. package/dist/assets/{project-collections-NBwk6yV-.js → project-collections-USb6PUe0.js} +1 -1
  55. package/dist/assets/project-detail-page-1tD6tUsB.js +1 -0
  56. package/dist/assets/project-dialog-BaHhJqP6.js +1 -0
  57. package/dist/assets/project-management-hierarchy-page-D4HV8QXs.js +1 -0
  58. package/dist/assets/project-management-section-nav-9OV6_ifH.js +1 -0
  59. package/dist/assets/projects-boxes-AyudWls3.js +1 -0
  60. package/dist/assets/projects-page-DizVVzbt.js +1 -0
  61. package/dist/assets/psyche-behaviors-page-CX5MJjWj.js +5 -0
  62. package/dist/assets/psyche-flashcards-page-DzCGy-FV.js +1 -0
  63. package/dist/assets/psyche-goal-map-page-BcKR792E.js +1 -0
  64. package/dist/assets/psyche-graph-BNllZR67.js +1 -0
  65. package/dist/assets/psyche-metrics-page-CpEKlZLO.js +1 -0
  66. package/dist/assets/psyche-mode-guide-page-DXKSE2o7.js +1 -0
  67. package/dist/assets/psyche-modes-page-Bh6eeNm1.js +1 -0
  68. package/dist/assets/psyche-page-B44RJrrC.js +1 -0
  69. package/dist/assets/psyche-patterns-page-Bm7T5FMJ.js +5 -0
  70. package/dist/assets/psyche-questionnaire-builder-page-BNtMNjY8.js +1 -0
  71. package/dist/assets/psyche-questionnaire-detail-page-BnMXErRK.js +1 -0
  72. package/dist/assets/psyche-questionnaire-run-detail-page-CWKxbdwZ.js +1 -0
  73. package/dist/assets/psyche-questionnaire-run-page-DwH7Sk52.js +1 -0
  74. package/dist/assets/psyche-questionnaires-page-B1t_a8QU.js +1 -0
  75. package/dist/assets/{psyche-report-detail-page-Ci14mNUK.js → psyche-report-detail-page-x2AtC99e.js} +3 -3
  76. package/dist/assets/psyche-reports-page-KiwCgWPa.js +1 -0
  77. package/dist/assets/{psyche-schemas-Dxj554nU.js → psyche-schemas-Dtskzvv1.js} +1 -1
  78. package/dist/assets/psyche-schemas-beliefs-page-CIEoAJAp.js +9 -0
  79. package/dist/assets/psyche-screen-time-page-DO6UycL9.js +1 -0
  80. package/dist/assets/psyche-self-observation-page-CPcpUSdm.js +1 -0
  81. package/dist/assets/psyche-values-page-BAgNeo4L.js +5 -0
  82. package/dist/assets/question-flow-dialog-BByFV8Yw.js +2 -0
  83. package/dist/assets/{report-chain-fields-CbkT7WOO.js → report-chain-fields-BpRWMp7h.js} +1 -1
  84. package/dist/assets/rewards-page-kIiX8SHn.js +1 -0
  85. package/dist/assets/{scheduling-rules-editor-BUGnZJ0g.js → scheduling-rules-editor-oQXGcL5l.js} +1 -1
  86. package/dist/assets/{schema-badge-CLAA4p-b.js → schema-badge-BoNjw3h4.js} +1 -1
  87. package/dist/assets/schemas-IBbtdPzn.js +1 -0
  88. package/dist/assets/{select-menu-Cqs5t3ng.js → select-menu-U-YryCwP.js} +1 -1
  89. package/dist/assets/{settings-agents-page-pmkVrOO8.js → settings-agents-page-CbHeMq3e.js} +4 -4
  90. package/dist/assets/settings-bin-page-LxS2YPsA.js +1 -0
  91. package/dist/assets/{settings-calendar-page-BBjAMOCf.js → settings-calendar-page-CZc-I-HK.js} +3 -3
  92. package/dist/assets/settings-data-page-m-aBRMR9.js +1 -0
  93. package/dist/assets/settings-logs-page-BUEGWlQu.js +1 -0
  94. package/dist/assets/settings-mobile-page-C_5CHjHl.js +1 -0
  95. package/dist/assets/settings-models-page-B4HQu8kL.js +1 -0
  96. package/dist/assets/settings-page-CY8N-fNV.js +1 -0
  97. package/dist/assets/settings-rewards-page-C0XQoWjb.js +1 -0
  98. package/dist/assets/{settings-section-nav-Co0AaDG-.js → settings-section-nav-CkqqtM0F.js} +1 -1
  99. package/dist/assets/settings-users-page-COCBOq7d.js +1 -0
  100. package/dist/assets/settings-wiki-page-Dy1d7-z-.js +1 -0
  101. package/dist/assets/sleep-page-1kKicdFq.js +1 -0
  102. package/dist/assets/sports-page-DJErRii_.js +1 -0
  103. package/dist/assets/{state-vCcAT5Hq.js → state-BtwEvpO6.js} +1 -1
  104. package/dist/assets/strategies-page-CWNFb9vv.js +1 -0
  105. package/dist/assets/strategy-detail-page-D9rFVXRS.js +1 -0
  106. package/dist/assets/strategy-dialog-BIVHfUR6.js +1 -0
  107. package/dist/assets/{surface-CyWI7e1R.js → surface-B3oXO1No.js} +1 -1
  108. package/dist/assets/{table-BNqMG3_S.js → table-BuONJH1s.js} +1 -1
  109. package/dist/assets/task-detail-page-r8ipOpAF.js +1 -0
  110. package/dist/assets/task-dialog-C3kkWtcT.js +6 -0
  111. package/dist/assets/timebox-planning-dialog-BadS5tEr.js +1 -0
  112. package/dist/assets/today-boxes-CiccN0Gw.js +1 -0
  113. package/dist/assets/today-page-DvQredbl.js +1 -0
  114. package/dist/assets/training-load-page-CkX-nSoe.js +1 -0
  115. package/dist/assets/{ui-C1iwpj2-.js → ui-B9O-eUim.js} +1 -1
  116. package/dist/assets/use-anchored-overlay-position-BrQ4cqKn.js +1 -0
  117. package/dist/assets/{use-psyche-focus-target-Ct-acS9G.js → use-psyche-focus-target-Cuxni3SK.js} +1 -1
  118. package/dist/assets/user-badge-BKzwGZDd.js +1 -0
  119. package/dist/assets/user-ownership-DJGl4rAj.js +1 -0
  120. package/dist/assets/user-select-field-BNqv8-wd.js +1 -0
  121. package/dist/assets/utility-widgets-DvxKA6dI.js +3 -0
  122. package/dist/assets/{vendor-Dnkkx2co.js → vendor-Cpmju3nw.js} +1 -1
  123. package/dist/assets/vitals-page-CRIsr_C7.js +1 -0
  124. package/dist/assets/weekly-review-page-CNqxLRCd.js +1 -0
  125. package/dist/assets/weight-loss-page-SSsCp1Yw.js +5 -0
  126. package/dist/assets/{wiki-article-markdown-Bi02AsVt.js → wiki-article-markdown-C9VKineE.js} +2 -2
  127. package/dist/assets/{wiki-editor-page-OZf9l4Tg.js → wiki-editor-page-DxGsKvF7.js} +5 -5
  128. package/dist/assets/wiki-ingest-history-page-CFmP7K1F.js +1 -0
  129. package/dist/assets/wiki-ingest-modal-BLw2PSWP.js +1 -0
  130. package/dist/assets/wiki-page-BiQ-jAuz.js +1 -0
  131. package/dist/assets/workbench-flow-page-D960hXu_.js +5 -0
  132. package/dist/assets/workbench-page-BWlY-FiL.js +1 -0
  133. package/dist/assets/workout-detail-page-G32yJoE9.js +2 -0
  134. package/dist/index.html +8 -10
  135. package/dist/server/server/src/app.js +10 -0
  136. package/dist/server/server/src/health-weight-loss.js +11 -3
  137. package/dist/server/server/src/services/dashboard.js +4 -4
  138. package/dist/server/server/src/services/gamification.js +71 -32
  139. package/openclaw.plugin.json +1 -1
  140. package/package.json +1 -1
  141. package/dist/assets/activity-page-DRRbpVK-.js +0 -1
  142. package/dist/assets/ai-surface-workspace-DJPt-OaW.js +0 -1
  143. package/dist/assets/calendar-page-y8G1ige8.js +0 -1
  144. package/dist/assets/calendar-rules-CRhXqGQu.js +0 -1
  145. package/dist/assets/companion-sync-lab-page-kEgOF3c6.js +0 -1
  146. package/dist/assets/daily-metrics-dashboard-BJjUIZVA.js +0 -1
  147. package/dist/assets/entity-notes-surface-CaCjjUaq.js +0 -1
  148. package/dist/assets/execution-board-RRWm2srb.js +0 -1
  149. package/dist/assets/goal-detail-page-BgQlK7yT.js +0 -1
  150. package/dist/assets/goals-page-Cz2i3pVy.js +0 -1
  151. package/dist/assets/habits-page-BmEmWCGv.js +0 -1
  152. package/dist/assets/index-QJkjKYzZ.js +0 -19
  153. package/dist/assets/insight-flow-dialog-CdYMHwMP.js +0 -1
  154. package/dist/assets/kanban-page-C6S_fJRc.js +0 -1
  155. package/dist/assets/knowledge-graph-page-juA9QCy0.js +0 -1
  156. package/dist/assets/life-force-page-ChTIA4mV.js +0 -1
  157. package/dist/assets/movement-page-Dx3T3HrG.js +0 -1
  158. package/dist/assets/note-tags-input-BS14YXHn.js +0 -1
  159. package/dist/assets/notes-page-D3yGl8TN.js +0 -1
  160. package/dist/assets/overview-page-DSOpBpHf.js +0 -1
  161. package/dist/assets/page-hero-CONuJu5J.js +0 -1
  162. package/dist/assets/pill-cluster-W2fY48OM.js +0 -1
  163. package/dist/assets/preferences-page-Br3zrLlH.js +0 -1
  164. package/dist/assets/project-detail-page-BIU9_TRN.js +0 -1
  165. package/dist/assets/project-management-hierarchy-page-C2H620xD.js +0 -1
  166. package/dist/assets/project-management-section-nav-DRPVS1Eh.js +0 -1
  167. package/dist/assets/projects-page-w7a_L2-z.js +0 -1
  168. package/dist/assets/psyche-behaviors-page-Dt4CMC-q.js +0 -5
  169. package/dist/assets/psyche-flashcards-page-rXz06dqO.js +0 -1
  170. package/dist/assets/psyche-goal-map-page-BCcD6Jkl.js +0 -1
  171. package/dist/assets/psyche-graph-CXlAj4ED.js +0 -1
  172. package/dist/assets/psyche-metrics-page-B1otiir6.js +0 -1
  173. package/dist/assets/psyche-mode-guide-page-C6AdVIAv.js +0 -1
  174. package/dist/assets/psyche-modes-page-DoUqz2mR.js +0 -1
  175. package/dist/assets/psyche-page-BJNLQn8W.js +0 -1
  176. package/dist/assets/psyche-patterns-page-CzpMSAPu.js +0 -5
  177. package/dist/assets/psyche-questionnaire-builder-page-DjzatGVZ.js +0 -1
  178. package/dist/assets/psyche-questionnaire-detail-page-B0Qfowfg.js +0 -1
  179. package/dist/assets/psyche-questionnaire-run-detail-page-B2dNj4jJ.js +0 -1
  180. package/dist/assets/psyche-questionnaire-run-page-DyD9Ui-g.js +0 -1
  181. package/dist/assets/psyche-questionnaires-page-BxfKcoi3.js +0 -1
  182. package/dist/assets/psyche-reports-page-ALhNueiV.js +0 -1
  183. package/dist/assets/psyche-schemas-beliefs-page-C0P2Vw6-.js +0 -9
  184. package/dist/assets/psyche-screen-time-page-BYnaT3cb.js +0 -1
  185. package/dist/assets/psyche-self-observation-page-eM9vpwIB.js +0 -1
  186. package/dist/assets/psyche-values-page-BqrGIDok.js +0 -5
  187. package/dist/assets/rewards-page-DpAJ8IxE.js +0 -1
  188. package/dist/assets/settings-bin-page-BwtLrweW.js +0 -1
  189. package/dist/assets/settings-data-page-Bqy5SukM.js +0 -1
  190. package/dist/assets/settings-logs-page-8khtrf4T.js +0 -1
  191. package/dist/assets/settings-mobile-page-BcyRjEU_.js +0 -1
  192. package/dist/assets/settings-models-page-DlSnO9WX.js +0 -1
  193. package/dist/assets/settings-page-CyBQ2qcB.js +0 -1
  194. package/dist/assets/settings-rewards-page-BBX2WtVM.js +0 -1
  195. package/dist/assets/settings-users-page-JSnfFFPu.js +0 -1
  196. package/dist/assets/settings-wiki-page--nT23Fdy.js +0 -1
  197. package/dist/assets/sleep-page-CGMi3MtV.js +0 -1
  198. package/dist/assets/sports-page-Kv5bBoLr.js +0 -1
  199. package/dist/assets/strategies-page-Br7RdUJO.js +0 -1
  200. package/dist/assets/strategy-detail-page-CBWXjUhC.js +0 -1
  201. package/dist/assets/strategy-dialog-BTwkaSxI.js +0 -1
  202. package/dist/assets/task-detail-page-Qis9354n.js +0 -1
  203. package/dist/assets/timebox-planning-dialog-DB8snOBD.js +0 -1
  204. package/dist/assets/today-page-D9A5PU0S.js +0 -1
  205. package/dist/assets/training-load-page-Bpd4DQAh.js +0 -1
  206. package/dist/assets/vitals-page-CVYC-4RG.js +0 -1
  207. package/dist/assets/weekly-review-page-BP7N3fNB.js +0 -1
  208. package/dist/assets/weight-loss-page-_fX3N1UK.js +0 -5
  209. package/dist/assets/wiki-ingest-history-page-CzeNSL7N.js +0 -1
  210. package/dist/assets/wiki-ingest-modal-Ig_xnyc6.js +0 -1
  211. package/dist/assets/wiki-page-B4xuNgY4.js +0 -1
  212. package/dist/assets/workbench-flow-page-BhRJCALC.js +0 -5
  213. package/dist/assets/workbench-page-DxVs2AOY.js +0 -1
  214. package/dist/assets/workout-detail-page-D4wfkE98.js +0 -2
@@ -0,0 +1 @@
1
+ import{r as u,dh as ae,j as e,di as ie,dj as ne,cr as U,cs as _,dg as te,dk as G,dl as re,bG as K,bz as B,dm as le,dn as W,aC as E,c5 as L,dp as oe}from"./vendor-Cpmju3nw.js";import{j as de,i as ce,k as P}from"./state-BtwEvpO6.js";import{d as me,S as xe,e as pe,C as Q,B as m,k as t,dB as he,dC as ue,dD as ve,dE as ge,cW as fe}from"./index-BejvcRGb.js";import{S as je}from"./settings-section-nav-CkqqtM0F.js";import{P as we}from"./page-hero-DlHEJ0Yt.js";import{g as be}from"./user-ownership-DJGl4rAj.js";import"./motion-DwjmC9aq.js";import"./ui-B9O-eUim.js";import"./board-CLOHbg6t.js";import"./forms-C5d5hTf2.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 Ce(a){return a.transportMode==="iroh"?"Iroh":"Manual HTTP"}function $e(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=be(g),[b,N]=u.useState(null),[x,C]=u.useState(!1),[$,y]=u.useState(!1),[F,R]=u.useState(!1),[r,X]=u.useState(null),p=ce({queryKey:["forge-companion-overview",...g],queryFn:async()=>(await fe(g)).overview}),c=P({mutationFn:async(s="iroh")=>he({userId:S??null,transportMode:s}),onSuccess:async s=>{X({qrPayload:s.qrPayload}),C(!0),await d.invalidateQueries({queryKey:["forge-companion-overview"]})}}),A=P({mutationFn:async s=>ve(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=>ge(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(xe,{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(pe,{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){C(!1);return}if(r&&!x){C(!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(we,{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(je,{}),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(U,{className:"size-4"}):e.jsx(_,{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:$e(r.qrPayload),children:[e.jsx(te,{className:"size-3"}),Ce(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:[$?"Hide payload":"Show payload",$?e.jsx(U,{className:"size-4"}):e.jsx(_,{className:"size-4"})]})]})]}),$?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 D,H;const o=s.sourceStates[h],se=o.desiredEnabled!==o.appliedEnabled,q=k.isPending&&((D=k.variables)==null?void 0:D.pairingSessionId)===s.id&&((H=k.variables)==null?void 0:H.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};
@@ -0,0 +1 @@
1
+ import{r as n,j as e,b2 as le,dq as fe,c1 as ce,dr as ke,aG as ye,cN as Ne,de as Ce}from"./vendor-Cpmju3nw.js";import{j as we,i as I,k as h}from"./state-BtwEvpO6.js";import{S as Ae}from"./settings-section-nav-CkqqtM0F.js";import{P as Se}from"./page-hero-DlHEJ0Yt.js";import{L as Oe,e as Ie,C as w,B as o,k as l,cP as Me,dF as Pe,dG as Le,dH as Ee,dI as Ke,dJ as Fe,dK as Ue,dL as _e,cV as ze,bn as $e,dM as Be}from"./index-BejvcRGb.js";import"./motion-DwjmC9aq.js";import"./ui-B9O-eUim.js";import"./board-CLOHbg6t.js";import"./forms-C5d5hTf2.js";const ue="grid min-w-0 gap-2 rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",M="grid min-w-0 gap-3 rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",P="rounded-[20px] border border-dashed border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-5 text-sm leading-6 text-[var(--ui-ink-soft)]",d="min-w-0 rounded-[16px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-3 py-3 text-sm text-[var(--ui-ink-strong)] outline-none placeholder:text-[var(--ui-ink-faint)] transition focus:border-[var(--primary)]/35 focus:bg-[var(--ui-surface-3)]",j="text-sm text-[var(--ui-ink-strong)]",L="text-[var(--ui-ink-soft)]",m="text-[var(--ui-ink-faint)]",We="text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",g="bg-[var(--ui-surface-3)] text-[var(--ui-ink-medium)]",qe="bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]",Qe="rounded-[20px] border border-[color-mix(in_srgb,var(--danger)_28%,var(--ui-border-subtle)_72%)] bg-[var(--ui-danger-soft)] px-4 py-5 text-sm leading-6 text-[color-mix(in_srgb,var(--danger)_76%,var(--ui-ink-strong)_24%)]";function E(i="openai-api"){return{label:i==="openai-codex"?"OpenAI Codex":i==="openai-compatible"?"Local compatible endpoint":i==="mock"?"Workbench mock runtime":"OpenAI API",provider:i,baseUrl:i==="openai-codex"?"https://chatgpt.com/backend-api":i==="openai-compatible"?"http://127.0.0.1:11434/v1":i==="mock"?"mock://workbench":"https://api.openai.com/v1",model:i==="mock"?"mock-echo":"gpt-5.4-mini",apiKey:""}}function Te(i){return{id:i.id,label:i.label,provider:i.provider,baseUrl:i.baseUrl,model:i.model,apiKey:""}}function ea(){var ie,te,ne,re,de;const i=we(),[s,x]=n.useState(()=>E()),[K,F]=n.useState(""),[U,_]=n.useState("gpt-5.4-mini"),[z,$]=n.useState(""),[B,W]=n.useState("gpt-5.4-mini"),[A,me]=n.useState("Fast wiki search"),[S,ge]=n.useState("text-embedding-3-small"),[q,he]=n.useState("https://api.openai.com/v1"),[Q,T]=n.useState(""),[R,xe]=n.useState("1200"),[D,pe]=n.useState("200"),[O,y]=n.useState(""),[c,N]=n.useState(null),[G,v]=n.useState(null),u=I({queryKey:["forge-settings"],queryFn:ze}),C=I({queryKey:["forge-wiki-settings"],queryFn:$e}),ve=I({queryKey:["forge-openai-codex-oauth",c],queryFn:async()=>{if(!c)throw new Error("Missing OAuth session id");return await Be(c)},enabled:!!c,refetchInterval:a=>{var oe;const r=(oe=a.state.data)==null?void 0:oe.session.status;return r&&["authorized","error","consumed","expired"].includes(r)?!1:1500}}),f=async()=>{await i.invalidateQueries({queryKey:["forge-settings"]}),await i.invalidateQueries({queryKey:["forge-wiki-settings"]}),await i.invalidateQueries({queryKey:["forge-wiki-search"]}),await i.invalidateQueries({queryKey:["forge-openai-codex-oauth",c]})},H=h({mutationFn:()=>Me({modelSettings:{forgeAgent:{basicChat:{connectionId:K||null,model:U},wiki:{connectionId:z||null,model:B}}}}),onSuccess:f}),Z=h({mutationFn:()=>Fe({id:s.id,label:s.label,provider:s.provider,authMode:s.provider==="openai-codex"?"oauth":"api_key",baseUrl:s.baseUrl,model:s.model,apiKey:s.provider==="openai-codex"?void 0:s.apiKey||void 0,oauthSessionId:s.provider==="openai-codex"?c??void 0:void 0}),onSuccess:async()=>{v("Connection saved."),s.provider==="openai-codex"&&(N(null),y("")),x(E(s.provider)),await f()},onError:a=>{v(a instanceof Error?a.message:"Connection save failed.")}}),J=h({mutationFn:_e,onSuccess:f}),V=h({mutationFn:()=>Le({label:A.trim(),model:S.trim(),baseUrl:q.trim(),apiKey:Q.trim()||void 0,chunkSize:Number(R),chunkOverlap:Number(D)}),onSuccess:async()=>{T(""),await f()}}),X=h({mutationFn:a=>Pe("embedding",a),onSuccess:f}),Y=h({mutationFn:async()=>Ue({connectionId:s.id,provider:s.provider,baseUrl:s.baseUrl,model:s.model,apiKey:s.provider==="openai-codex"?void 0:s.apiKey||void 0}),onSuccess:({result:a})=>{v(`Connection test succeeded: ${a.outputPreview}`)},onError:a=>{v(a instanceof Error?a.message:"Connection test failed.")}}),ee=h({mutationFn:Ee,onSuccess:({session:a})=>{N(a.id),v("OpenAI Codex OAuth started."),a.authUrl&&window.open(a.authUrl,"_blank","noopener,noreferrer")}}),ae=h({mutationFn:async()=>{if(!c)throw new Error("No OAuth session started yet.");return await Ke(c,O)},onSuccess:({session:a})=>{v(a.status==="authorized"?"OpenAI Codex OAuth authorized.":"Manual OAuth code submitted.")}});n.useEffect(()=>{var r;const a=(r=u.data)==null?void 0:r.settings;a&&(F(a.modelSettings.forgeAgent.basicChat.connectionId??""),_(a.modelSettings.forgeAgent.basicChat.model),$(a.modelSettings.forgeAgent.wiki.provider==="openai-codex"?a.modelSettings.forgeAgent.wiki.connectionId??"":""),W(a.modelSettings.forgeAgent.wiki.model))},[u.data]);const p=((ie=u.data)==null?void 0:ie.settings.modelSettings.connections)??[],se=p.filter(a=>a.provider==="openai-codex"&&a.authMode==="oauth"),be=se.filter(a=>a.hasStoredCredential),t=((te=ve.data)==null?void 0:te.session)??null,b=s.id?p.find(a=>a.id===s.id):null,je=n.useMemo(()=>!s.label.trim()||!s.model.trim()?!1:s.provider==="openai-codex"?!!((t==null?void 0:t.status)==="authorized"||s.id&&(b!=null&&b.hasStoredCredential)):s.provider==="mock"?!0:s.apiKey.trim().length>0||!!s.id,[s,b==null?void 0:b.hasStoredCredential,t==null?void 0:t.status]);if(u.isLoading)return e.jsx(Oe,{eyebrow:"Models",title:"Loading model settings",description:"Fetching Forge agent defaults and configured AI connections."});if(u.isError||!((ne=u.data)!=null&&ne.settings))return e.jsx(Ie,{eyebrow:"Models",error:u.error??new Error("Forge returned an empty model settings payload."),onRetry:()=>void u.refetch()});const k=u.data.settings;return e.jsxs("div",{className:"mx-auto grid min-w-0 w-full max-w-[1440px] gap-5",children:[e.jsx(Se,{eyebrow:"AI runtime",title:"Model Settings",description:"Manage Forge Agent defaults, OpenAI OAuth/API connections, and local OpenAI-compatible endpoints as first-class chat agents.",badge:`${p.length} model connection${p.length===1?"":"s"}`}),e.jsx(Ae,{}),e.jsxs(w,{className:"grid gap-5",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(le,{className:"size-4 text-[var(--secondary)]"}),e.jsxs("div",{children:[e.jsx("div",{className:j,children:"Forge Agent defaults"}),e.jsx("div",{className:`text-xs leading-5 ${m}`,children:"Forge Agent stays the default system agent. Choose which model connection powers basic chat and the managed wiki workflow."})]})]}),e.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[e.jsxs("label",{className:ue,children:[e.jsx("span",{className:`text-sm ${L}`,children:"Basic chat connection"}),e.jsxs("select",{className:d,value:K,onChange:a=>F(a.target.value),children:[e.jsx("option",{value:"",children:"No external connection"}),p.map(a=>e.jsxs("option",{value:a.id,children:[a.label," (",a.agentLabel,")"]},a.id))]}),e.jsx("input",{className:d,value:U,onChange:a=>_(a.target.value),placeholder:"Model"})]}),e.jsxs("label",{className:ue,children:[e.jsx("span",{className:`text-sm ${L}`,children:"KarpaWiki Codex OAuth connection"}),e.jsxs("select",{className:d,value:z,onChange:a=>$(a.target.value),children:[e.jsx("option",{value:"",children:"No Codex OAuth connection"}),se.map(a=>e.jsxs("option",{value:a.id,disabled:!a.hasStoredCredential,children:[a.label," (",a.accountLabel??a.agentLabel,")",a.hasStoredCredential?"":" · needs OAuth"]},a.id))]}),e.jsx("input",{className:d,value:B,onChange:a=>W(a.target.value),placeholder:"Model"}),e.jsx("span",{className:`text-xs leading-5 ${m}`,children:"KarpaWiki smart ingest uses ChatGPT/Codex OAuth only. It does not use metered OpenAI Platform API keys."})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-3",children:[e.jsx(o,{pending:H.isPending,pendingLabel:"Saving defaults",onClick:()=>void H.mutateAsync(),children:"Save Forge Agent defaults"}),e.jsxs(l,{className:g,children:["Forge Agent",k.modelSettings.forgeAgent.basicChat.connectionLabel?` basic chat: ${k.modelSettings.forgeAgent.basicChat.connectionLabel}`:" basic chat stays local"]}),e.jsx(l,{className:g,children:k.modelSettings.forgeAgent.wiki.connectionLabel?`KarpaWiki OAuth: ${k.modelSettings.forgeAgent.wiki.connectionLabel}`:"KarpaWiki: no Codex OAuth model selected"}),be.length===0?e.jsx(l,{className:qe,children:"Add OpenAI Codex OAuth before smart ingest"}):null]})]}),e.jsxs(w,{className:"grid gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(fe,{className:"size-4 text-[var(--secondary)]"}),e.jsxs("div",{children:[e.jsx("div",{className:j,children:"KarpaWiki embeddings"}),e.jsx("div",{className:`text-xs leading-5 ${m}`,children:"Semantic search profiles live with model settings. They remain optional; KarpaWiki text search and entity-linked search still work without embeddings."})]})]}),e.jsxs("div",{className:"grid gap-4 lg:grid-cols-[minmax(0,1fr)_minmax(20rem,0.9fr)]",children:[e.jsxs("div",{className:"grid gap-3",children:[C.isLoading?e.jsx("div",{className:P,children:"Loading embedding profiles."}):null,C.isError?e.jsx("div",{className:Qe,children:"Could not load KarpaWiki embedding profiles."}):null,((re=C.data)==null?void 0:re.settings.embeddingProfiles.length)===0?e.jsx("div",{className:P,children:"No embedding profile yet. Add one only if you want semantic wiki search in addition to exact search and links."}):null,(de=C.data)==null?void 0:de.settings.embeddingProfiles.map(a=>e.jsxs("div",{className:"grid min-w-0 gap-2 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-[var(--ui-ink-strong)]",children:a.label}),e.jsxs("div",{className:`mt-1 break-words text-xs [overflow-wrap:anywhere] ${m}`,children:[a.model," · ",a.baseUrl]})]}),e.jsx(o,{variant:"secondary",pending:X.isPending,pendingLabel:"Deleting",onClick:()=>void X.mutateAsync(a.id),children:e.jsx(ce,{className:"size-4"})})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(l,{className:g,children:["chunk ",a.chunkSize]}),e.jsxs(l,{className:g,children:["overlap ",a.chunkOverlap]}),e.jsx(l,{className:g,children:a.enabled?"enabled":"disabled"})]})]},a.id))]}),e.jsxs("div",{className:M,children:[e.jsx("input",{className:d,value:A,onChange:a=>me(a.target.value),placeholder:"Profile label"}),e.jsx("input",{className:d,value:S,onChange:a=>ge(a.target.value),placeholder:"Embedding model"}),e.jsx("input",{className:d,value:q,onChange:a=>he(a.target.value),placeholder:"Embedding base URL"}),e.jsx("input",{className:d,value:Q,onChange:a=>T(a.target.value),placeholder:"Embedding API key (optional)",type:"password"}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsx("input",{className:d,value:R,onChange:a=>xe(a.target.value),placeholder:"Chunk size",type:"number"}),e.jsx("input",{className:d,value:D,onChange:a=>pe(a.target.value),placeholder:"Chunk overlap",type:"number"})]}),e.jsx(o,{pending:V.isPending,pendingLabel:"Saving",disabled:!A.trim()||!S.trim(),onClick:()=>void V.mutateAsync(),children:"Save embedding profile"})]})]})]}),e.jsxs("div",{className:"grid min-w-0 gap-5 xl:grid-cols-[minmax(0,1.1fr)_minmax(0,0.9fr)]",children:[e.jsxs(w,{className:"grid gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ke,{className:"size-4 text-[var(--secondary)]"}),e.jsxs("div",{children:[e.jsx("div",{className:j,children:"Connection editor"}),e.jsx("div",{className:`text-xs leading-5 ${m}`,children:"Every saved connection becomes a first-class agent layered on top of Forge Agent."})]})]}),e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:We,children:"Provider"}),e.jsx("div",{className:"grid gap-2 md:grid-cols-3",children:[["openai-api","OpenAI API"],["openai-codex","OpenAI Codex OAuth"],["openai-compatible","OpenAI-compatible"]].map(([a,r])=>e.jsx("button",{type:"button",className:`rounded-[18px] px-4 py-3 text-left text-sm transition ${s.provider===a?"border border-[color-mix(in_srgb,var(--primary)_34%,var(--ui-border-subtle)_66%)] bg-[var(--ui-accent-soft)] text-[var(--ui-ink-strong)] shadow-[var(--ui-shadow-soft)]":"border 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)]"}`,onClick:()=>{x(E(a)),N(null),y("")},children:r},a))})]}),e.jsx("input",{className:d,value:s.label,onChange:a=>x(r=>({...r,label:a.target.value})),placeholder:"Connection label"}),e.jsx("input",{className:d,value:s.model,onChange:a=>x(r=>({...r,model:a.target.value})),placeholder:"Model"}),s.provider==="mock"?e.jsxs("div",{className:M,children:[e.jsx("div",{className:j,children:"The Workbench mock runtime is only meant for local development and test workflows."}),e.jsxs("div",{className:`text-xs leading-5 ${m}`,children:["Use mock models like ",e.jsx("code",{children:"mock-echo"}),","," ",e.jsx("code",{children:"mock-json"}),",",e.jsx("code",{children:"mock-tool-search"}),","," ",e.jsx("code",{children:"mock-tool-note"}),", or",e.jsx("code",{children:"mock-chat-memory"})," to exercise deterministic flow behavior without a real external model."]})]}):s.provider!=="openai-codex"?e.jsxs(e.Fragment,{children:[e.jsx("input",{className:d,value:s.baseUrl,onChange:a=>x(r=>({...r,baseUrl:a.target.value})),placeholder:"Base URL"}),e.jsx("input",{className:d,value:s.apiKey,onChange:a=>x(r=>({...r,apiKey:a.target.value})),placeholder:s.id?"Leave blank to keep the stored key":"API key",type:"password"})]}):e.jsxs("div",{className:M,children:[e.jsxs("div",{className:j,children:["OpenAI Codex uses the documented PKCE flow with the local callback at"," ",e.jsx("span",{className:"break-words [overflow-wrap:anywhere]",children:k.modelSettings.oauth.openAiCodex.callbackUrl})]}),e.jsx("div",{className:`text-xs leading-5 ${m}`,children:"Start OAuth, finish the browser sign-in, then save the resulting connection as a chat agent backed by the ChatGPT Codex runtime."}),e.jsxs("div",{className:"flex flex-wrap gap-3",children:[e.jsxs(o,{variant:"secondary",pending:ee.isPending,pendingLabel:"Starting OAuth",onClick:()=>void ee.mutateAsync(),children:[e.jsx(ye,{className:"size-4"}),"Start OAuth"]}),t!=null&&t.authUrl?e.jsxs(o,{variant:"secondary",onClick:()=>window.open(t.authUrl??"","_blank","noopener,noreferrer"),children:["Open sign-in",e.jsx(Ne,{className:"size-4"})]}):null]}),t?e.jsxs("div",{className:"grid min-w-0 gap-2 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-code-bg)] p-3 text-sm text-[var(--ui-code-text)]",children:[e.jsxs("div",{children:["Status: ",t.status]}),t.accountLabel?e.jsxs("div",{children:["Account: ",t.accountLabel]}):null,t.error?e.jsx("div",{className:"text-[color-mix(in_srgb,var(--danger)_76%,var(--ui-ink-strong)_24%)]",children:t.error}):null]}):null,e.jsxs("div",{className:"grid gap-2",children:[e.jsx("input",{className:d,value:O,onChange:a=>y(a.target.value),placeholder:"Paste the authorization code or full redirect URL"}),e.jsx(o,{variant:"secondary",disabled:!O.trim()||!c,pending:ae.isPending,pendingLabel:"Submitting",onClick:()=>void ae.mutateAsync(),children:"Submit manual code"})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-3",children:[e.jsx(o,{pending:Z.isPending,pendingLabel:"Saving connection",disabled:!je,onClick:()=>void Z.mutateAsync(),children:"Save connection"}),e.jsxs(o,{variant:"secondary",pending:Y.isPending,pendingLabel:"Testing",disabled:s.provider==="openai-codex"?!s.id:s.provider==="mock"?!1:!s.id&&!s.apiKey.trim(),onClick:()=>void Y.mutateAsync(),children:[e.jsx(Ce,{className:"size-4"}),"Test connection"]})]}),G?e.jsx("div",{className:`rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-3 text-sm ${L}`,children:G}):null]})]}),e.jsxs(w,{className:"grid gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(le,{className:"size-4 text-[var(--secondary)]"}),e.jsxs("div",{children:[e.jsx("div",{className:j,children:"Connected agents"}),e.jsx("div",{className:`text-xs leading-5 ${m}`,children:"Each connection registers its own chat-facing agent identity."})]})]}),e.jsxs("div",{className:"grid gap-3",children:[p.length===0?e.jsx("div",{className:P,children:"No external model connection yet. Add one with OAuth or API credentials and Forge will expose it as a first-class agent."}):null,p.map(a=>e.jsxs("div",{className:"grid min-w-0 gap-3 rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",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",children:[e.jsx("div",{className:"break-words text-[var(--ui-ink-strong)] [overflow-wrap:anywhere]",children:a.label}),e.jsxs("div",{className:`mt-1 break-words text-xs [overflow-wrap:anywhere] ${m}`,children:[a.agentLabel," · ",a.provider," ·"," ",a.model]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(o,{variant:"secondary",onClick:()=>{x(Te(a)),N(null),y("")},children:"Edit"}),e.jsx(o,{variant:"secondary",pending:J.isPending,pendingLabel:"Deleting",onClick:()=>void J.mutateAsync(a.id),children:e.jsx(ce,{className:"size-4"})})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(l,{className:g,children:a.authMode==="oauth"?"OAuth":"API key"}),e.jsx(l,{className:g,children:a.status}),e.jsx(l,{className:g,wrap:!0,children:a.baseUrl}),a.accountLabel?e.jsx(l,{className:g,wrap:!0,children:a.accountLabel}):null]})]},a.id))]})]})]})]})}export{ea as SettingsModelsPage};
@@ -0,0 +1 @@
1
+ import{r as w,j as e,aD as ve,d8 as be,aC as fe,aG as ye,bG as je,d9 as Ne,aQ as we}from"./vendor-Cpmju3nw.js";import{j as ke,i as L,k as M}from"./state-BtwEvpO6.js";import{u as Se}from"./forms-C5d5hTf2.js";import{Q as Ce,F as R,a as Te}from"./question-flow-dialog-BByFV8Yw.js";import{cc as ee,I as _,cE as Fe,T as Pe,cF as A,B as k,cG as te,u as _e,aq as $e,cH as De,cI as Ae,cJ as Ee,cK as se,S as Ie,e as ae,C as $,cL as Le,cM as Me,cN as Qe,cO as Re,cP as Q,cQ as qe,cR as Je,cS as ze,cT as Ke,cU as Ge,cV as Oe,cW as He,cX as Ue}from"./index-BejvcRGb.js";import{S as We}from"./settings-section-nav-CkqqtM0F.js";import{P as Be}from"./page-hero-DlHEJ0Yt.js";import{s as Xe}from"./schemas-IBbtdPzn.js";import"./ui-B9O-eUim.js";import"./motion-DwjmC9aq.js";import"./board-CLOHbg6t.js";function K({theme:a,title:l,description:n}){return e.jsx("div",{className:"overflow-hidden rounded-[24px] border border-[var(--ui-border-subtle)]",style:{background:`linear-gradient(180deg, ${a.panelHigh}, ${a.panelLow})`,color:a.ink},children:e.jsxs("div",{className:"px-4 py-4",style:{background:`radial-gradient(circle at top left, ${a.primary}33, transparent 42%), radial-gradient(circle at top right, ${a.secondary}2a, transparent 36%), linear-gradient(180deg, ${a.panel}, ${a.canvas})`},children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.2em] opacity-60",children:"Preview"}),e.jsx("div",{className:"mt-2 font-display text-xl",children:l}),e.jsx("div",{className:"mt-2 text-sm leading-6 opacity-72",children:n}),e.jsx("div",{className:"mt-5 flex gap-2",children:[a.primary,a.secondary,a.tertiary,a.panelHigh].map(t=>e.jsx("div",{className:"h-9 flex-1 rounded-[14px] border border-[var(--ui-border-subtle)]",style:{background:t}},t))})]})})}function j({label:a,value:l,onChange:n,description:t}){return e.jsx(R,{label:a,description:t,children:e.jsxs("div",{className:"grid gap-3 sm:grid-cols-[5.5rem_minmax(0,1fr)]",children:[e.jsx("input",{type:"color",value:l,onChange:d=>n(d.target.value),className:"h-12 w-full cursor-pointer rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-1"}),e.jsx(_,{value:l,onChange:d=>n(d.target.value),placeholder:"#7cc7ff"})]})})}function Ye({open:a,onOpenChange:l,value:n,onSave:t}){const[d,m]=w.useState(n),[g,u]=w.useState(""),[f,b]=w.useState(null),S=w.useRef(null),c=r=>{const i=ee.parse(JSON.parse(r));m(i),u(JSON.stringify(i,null,2)),b(null)},x=r=>{const i=te(r);m({...i,label:d.label.trim().length>0?d.label:`${i.label} Custom`})},C=async r=>{var o;const i=(o=r.target.files)==null?void 0:o[0];if(i)try{c(await i.text())}catch(T){b(T instanceof Error?T.message:"Forge could not parse that JSON theme.")}finally{r.target.value=""}},E=[{id:"identity",eyebrow:"Custom theme",title:"Name the mood and choose a starting point",description:"Start from a Forge preset, then tune the accents and surfaces in the next steps.",render:(r,i)=>e.jsxs("div",{className:"grid gap-5",children:[e.jsx(R,{label:"Theme label",description:"This label appears in Settings when the custom theme is active.",children:e.jsx(_,{value:r.label,onChange:o=>i({label:o.target.value}),placeholder:"Midnight Circuit"})}),e.jsx(R,{label:"Starter preset",children:e.jsx(Te,{value:"",onChange:o=>x(o),options:Object.entries(Fe).map(([o,T])=>({value:o,label:T.label,description:T.description})),columns:2})}),e.jsx(K,{theme:r,title:r.label,description:"Live preview of the current custom theme draft."})]})},{id:"accents",eyebrow:"Custom theme",title:"Set the accent colors",description:"These colors drive buttons, highlights, charts, and the ambient shell lighting.",render:(r,i)=>e.jsxs("div",{className:"grid gap-4",children:[e.jsx(j,{label:"Primary",description:"Main emphasis color for actions and active state.",value:r.primary,onChange:o=>i({primary:o})}),e.jsx(j,{label:"Secondary",description:"Support accent for positive or secondary emphasis.",value:r.secondary,onChange:o=>i({secondary:o})}),e.jsx(j,{label:"Tertiary",description:"Warm contrast color for warnings, highlights, and supporting metrics.",value:r.tertiary,onChange:o=>i({tertiary:o})})]})},{id:"surfaces",eyebrow:"Custom theme",title:"Tune the shell surfaces",description:"Forge currently assumes a dark shell, so these should remain fairly deep colors for legibility.",render:(r,i)=>e.jsxs("div",{className:"grid gap-4",children:[e.jsx(j,{label:"Canvas",description:"Primary app background.",value:r.canvas,onChange:o=>i({canvas:o})}),e.jsx(j,{label:"Panel",description:"Default card and rail background.",value:r.panel,onChange:o=>i({panel:o})}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsx(j,{label:"Panel high",description:"Raised highlights and stronger sections.",value:r.panelHigh,onChange:o=>i({panelHigh:o})}),e.jsx(j,{label:"Panel low",description:"Lower contrast and deeper card areas.",value:r.panelLow,onChange:o=>i({panelLow:o})})]}),e.jsx(j,{label:"Ink",description:"Main text and readable foreground color.",value:r.ink,onChange:o=>i({ink:o})}),e.jsx(K,{theme:r,title:r.label,description:"Live preview after the current surface edits."})]})},{id:"import",eyebrow:"Custom theme",title:"Import or paste JSON directly",description:"You can skip the picker workflow entirely by uploading a JSON file or pasting a valid theme object.",render:r=>e.jsxs("div",{className:"grid gap-4",children:[e.jsx(R,{label:"Direct JSON",description:"Paste a full custom theme object, then click Apply JSON.",children:e.jsx(Pe,{value:g,onChange:i=>u(i.target.value),className:"min-h-52 font-mono text-[13px] leading-6",placeholder:JSON.stringify(A,null,2)})}),e.jsxs("div",{className:"flex flex-wrap gap-3",children:[e.jsx(k,{type:"button",variant:"secondary",onClick:()=>{try{c(g)}catch(i){b(i instanceof Error?i.message:"Forge could not parse that JSON theme.")}},children:"Apply JSON"}),e.jsx(k,{type:"button",variant:"ghost",onClick:()=>{var i;return(i=S.current)==null?void 0:i.click()},children:"Upload JSON file"}),e.jsx("input",{ref:S,type:"file",accept:"application/json,.json",className:"hidden",onChange:C})]}),e.jsx(K,{theme:r,title:r.label,description:"Preview of the theme that will be saved if you submit now."})]})}];return e.jsx(Ce,{open:a,onOpenChange:r=>{r&&(m(n),u(""),b(null)),l(r)},eyebrow:"Settings",title:"Forge custom theme",description:"Build a dark Forge palette visually, or import one directly as JSON.",value:d,onChange:r=>{m(r),b(null)},draftPersistenceKey:"settings.theme-customizer",steps:E,error:f,onSubmit:async()=>{try{const r=ee.parse(d);t(r),l(!1)}catch(r){b(r instanceof Error?r.message:"Forge could not save that custom theme.")}},submitLabel:"Save custom theme",contentClassName:"lg:w-[min(62rem,calc(100vw-1.5rem))]"})}const N="font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",F="text-sm leading-6 text-[var(--ui-ink-soft)]",ie="text-xs leading-5 text-[var(--ui-ink-faint)]",P="rounded-[16px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",q="rounded-[14px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]";function Ze({theme:a}){return e.jsx("div",{className:"mt-3 grid grid-cols-4 gap-2",children:[a.primary,a.secondary,a.tertiary,a.panelHigh].map(l=>e.jsx("div",{className:"h-6 rounded-[10px] border border-[var(--ui-border-subtle)]",style:{background:l}},l))})}function Ve({selected:a,theme:l}){return e.jsxs("div",{className:"relative min-h-[138px] overflow-hidden rounded-[18px] border border-[var(--ui-border-subtle)] bg-[linear-gradient(145deg,var(--ui-surface-2),var(--ui-surface-1))]",children:[e.jsx("div",{className:"absolute inset-x-0 bottom-0 h-16 bg-[linear-gradient(0deg,color-mix(in_srgb,var(--ui-surface-3)_82%,transparent),transparent)]"}),e.jsx("img",{src:Je(l),alt:`${l} neutral Forge Smith mascot preview`,className:"absolute bottom-1 left-1/2 h-[124px] w-[124px] -translate-x-1/2 object-contain drop-shadow-[0_18px_30px_color-mix(in_srgb,var(--ui-shadow-color)_30%,transparent)]"}),e.jsxs("div",{className:"absolute left-3 top-3 flex items-center gap-2 rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-glass)] px-2.5 py-1 text-[9px] font-semibold uppercase tracking-[0.14em] text-[var(--ui-ink-medium)] backdrop-blur-md",children:[e.jsx(ye,{className:"size-3 text-[var(--warning)]"}),"Live rewards"]}),e.jsx("div",{className:"absolute bottom-3 left-3 flex items-center gap-1.5",children:ze.map(n=>e.jsx("span",{className:"grid size-11 place-items-center overflow-hidden rounded-[12px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-glass)] p-1 shadow-[var(--ui-shadow-soft)] backdrop-blur-md",children:e.jsx("img",{src:Ke(l,n),alt:`${l} reward thumbnail`,className:"size-full object-contain"})},n))}),e.jsx("span",{className:`absolute right-3 top-3 grid size-7 place-items-center rounded-full border ${a?"border-[color-mix(in_srgb,var(--success)_42%,var(--ui-border-subtle)_58%)] bg-[var(--ui-success-soft)] text-[var(--success)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-glass)] text-[var(--ui-ink-faint)]"}`,children:a?e.jsx(je,{className:"size-4"}):null})]})}function re({healthy:a}){return e.jsx($,{className:"p-4",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:N,children:"Mobile companion"}),e.jsx("div",{className:"mt-1 text-base font-medium text-[var(--ui-ink-strong)]",children:a?"iPhone bridge is syncing":"Connect the iPhone bridge"}),e.jsx("div",{className:`mt-1 max-w-3xl ${F}`,children:a?"Review HealthKit, movement, and background sync permissions.":"Pair or refresh the native companion before relying on HealthKit, movement, or watch signals."})]}),e.jsx(fe,{to:"/settings/mobile",className:"inline-flex min-h-10 items-center rounded-[14px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-3 py-2 text-sm text-[var(--ui-ink-strong)] transition hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-hover)]",children:"Open mobile settings"})]})})}function J(a){return new Date(a).toLocaleString()}function ne({integrityScore:a,storageMode:l,lastAuditAt:n,doctor:t}){return t?[t.integrity.headline,t.integrity.topIssues.length>0?t.integrity.topIssues[0].summary:"No active Doctor warnings are holding back integrity.",`Storage mode: ${l}. Latest Doctor run: ${J(t.integrity.lastCheckedAt)}.`]:a>=100?["All currently reported settings and storage checks passed.",`Latest audit: ${J(n)}.`]:[`Forge is holding back ${Math.max(0,100-a)}% because the latest settings and storage audit reported a consistency warning.`,"The current audit only exposes the aggregate score, so per-check details are not available yet.",`Storage mode: ${l}. Latest audit: ${J(n)}.`]}function le({integrityScore:a,storageMode:l,lastAuditAt:n,doctor:t}){const d=(t==null?void 0:t.integrity.score)??a,m=ne({integrityScore:a,storageMode:l,lastAuditAt:n,doctor:t});return e.jsxs("details",{className:"group relative inline-flex",children:[e.jsxs("summary",{className:"inline-flex cursor-pointer list-none items-center gap-1 rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-2.5 py-1 text-[11px] font-medium normal-case tracking-normal text-[var(--ui-ink-soft)] transition marker:hidden hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[color-mix(in_srgb,var(--primary)_32%,transparent)] [&::-webkit-details-marker]:hidden",onKeyDown:g=>{var u;g.key==="Escape"&&((u=g.currentTarget.parentElement)==null||u.removeAttribute("open"))},children:[e.jsx(be,{className:"size-3.5","aria-hidden":"true"}),d,"% integrity"]}),e.jsxs("span",{role:"tooltip",className:"surface-modal-panel absolute right-0 top-[calc(100%+0.55rem)] z-50 hidden w-[min(19rem,calc(100vw-2rem))] rounded-[16px] border px-3 py-2.5 text-left text-xs leading-5 tracking-normal text-[var(--ui-ink-soft)] normal-case shadow-[var(--ui-shadow-strong)] group-open:block",children:[e.jsx("span",{className:"block font-medium text-[var(--ui-ink-strong)]",children:d>=100?"Integrity is complete":`Why this is ${d}%`}),m.map(g=>e.jsx("span",{className:"mt-1 block",children:g},g))]})]})}function es({integrityScore:a,storageMode:l,lastAuditAt:n,doctor:t,doctorLoading:d,onRefreshDoctor:m,onApplyFix:g,applyingFixId:u}){const f=(t==null?void 0:t.integrity.score)??a,b=(t==null?void 0:t.integrity.lastCheckedAt)??n,S=(t==null?void 0:t.issues.filter(x=>x.severity!=="info").slice(0,4))??[],[c]=ne({integrityScore:a,storageMode:l,lastAuditAt:n,doctor:t});return e.jsxs($,{className:"p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:N,children:"Security posture"}),e.jsx("div",{className:`mt-1 ${F}`,children:"Local-first means Forge stores its runtime data on this machine. Integrity is the latest internal consistency score from settings and data checks."}),e.jsx("div",{className:`mt-2 ${ie}`,children:c})]}),e.jsx(le,{integrityScore:a,storageMode:l,lastAuditAt:n,doctor:t})]}),e.jsxs("div",{className:"mt-3 grid gap-2 md:grid-cols-2",children:[e.jsxs("div",{className:`${q} px-3 py-3`,children:[e.jsx("div",{className:"text-xs text-[var(--ui-ink-soft)]",children:"Storage mode"}),e.jsx("div",{className:"mt-1 text-base font-medium text-[var(--ui-ink-strong)]",children:l})]}),e.jsxs("div",{className:`${q} px-3 py-3`,children:[e.jsx("div",{className:"text-xs text-[var(--ui-ink-soft)]",children:"Last Doctor run"}),e.jsx("div",{className:"mt-1 text-base font-medium text-[var(--ui-ink-strong)]",children:J(b)})]})]}),e.jsxs("div",{className:`mt-3 ${q} p-3`,children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium text-[var(--ui-ink-strong)]",children:[e.jsx(Ne,{className:"size-4 text-[var(--info)]"}),"Forge Doctor"]}),e.jsxs(k,{type:"button",variant:"secondary",pending:d,onClick:m,children:[e.jsx(we,{className:"size-4"}),"Run"]})]}),e.jsx("div",{className:`mt-2 ${F}`,children:t?`${f}% integrity. ${t.integrity.headline}`:"Run Doctor to check settings, storage, entities, rewards, and runtime consistency."}),S.length>0?e.jsx("div",{className:"mt-3 grid gap-2",children:S.map(x=>{var C;return e.jsx(ss,{issue:x,applying:u===((C=x.fix)==null?void 0:C.id),onApplyFix:g},x.id)})}):t?e.jsx("div",{className:"mt-3 rounded-[12px] border border-[color-mix(in_srgb,var(--success)_24%,var(--ui-border-subtle)_76%)] bg-[var(--ui-success-soft)] px-3 py-2 text-sm text-[var(--success)]",children:"No active consistency warnings."}):null]})]})}function ss({issue:a,applying:l,onApplyFix:n}){var t;return e.jsx("div",{className:`${q} px-3 py-2`,children:e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-2",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"text-xs uppercase tracking-[0.14em] text-[var(--ui-ink-faint)]",children:[a.group," / ",a.severity]}),e.jsx("div",{className:"mt-1 text-sm text-[var(--ui-ink-medium)]",children:a.summary})]}),((t=a.fix)==null?void 0:t.kind)==="safe_auto_fix"?e.jsx(k,{type:"button",variant:"secondary",pending:l,onClick:()=>n(a.fix.id),children:"Apply fix"}):null]})})}function ps(){var B,X,Y,Z,V;const{t:a}=_e(),l=$e(),n=ke(),[t,d]=w.useState(!1),m=L({queryKey:["forge-operator-session"],queryFn:Ge}),g=m.isSuccess,u=L({queryKey:["forge-settings"],queryFn:Oe,enabled:g}),f=De(void 0,{skip:!g}),b=L({queryKey:["forge-companion-overview"],queryFn:async()=>(await He()).overview,enabled:g,staleTime:3e4}),S=L({queryKey:["forge-gamification-assets"],queryFn:Ue,enabled:g,staleTime:3e4}),c=Se({defaultValues:{profile:{operatorName:"",operatorEmail:"",operatorTitle:""},notifications:{goalDriftAlerts:!0,dailyQuestReminders:!0,achievementCelebrations:!0},execution:{maxActiveTasks:2,timeAccountingMode:"split"},themePreference:"obsidian",gamificationTheme:"dramatic-smithie",customTheme:A,localePreference:"en"}}),x=async()=>{await Promise.all([n.invalidateQueries({queryKey:["forge-operator-session"]}),n.invalidateQueries({queryKey:["forge-settings"]})])},C=M({mutationFn:s=>Q(s),onSuccess:x}),E=M({mutationFn:s=>Q(s),onSuccess:async s=>{n.setQueryData(["forge-settings"],s),await x()}}),r=M({mutationFn:s=>Q(s),onSuccess:async s=>{n.setQueryData(["forge-settings"],s),await x()}}),i=M({mutationFn:async s=>(await qe(s),Q({gamificationTheme:s})),onSuccess:async s=>{n.setQueryData(["forge-settings"],s),await Promise.all([n.invalidateQueries({queryKey:["forge-settings"]}),n.invalidateQueries({queryKey:["forge-gamification-assets"]})])}}),[o,T]=Ae(),[oe,ce]=Ee(),[de,G]=w.useState(),ue=async()=>{await o().unwrap(),l(Qe([])),l(Re.util.resetApiState()),n.removeQueries({predicate:s=>{const[v]=s.queryKey;return typeof v=="string"&&v.startsWith("forge-")}}),await Promise.all([x(),m.refetch()])};w.useEffect(()=>{var s;(s=u.data)!=null&&s.settings&&c.reset(Xe.parse(u.data.settings))},[u.data,c]);const p=(B=u.data)==null?void 0:B.settings,me=(X=f.data)==null?void 0:X.doctor,D=c.watch("themePreference"),O=c.watch("gamificationTheme"),H=((Y=S.data)==null?void 0:Y.assets.styles)??[],z=H.find(s=>s.id===O),y=c.watch("customTheme")??A,U=((Z=b.data)==null?void 0:Z.healthState)==="healthy_sync",pe=async s=>{if(window.confirm("Apply this Forge Doctor fix? Forge will only run the selected safe repair.")){G(s);try{await oe({fixIds:[s]}).unwrap(),await Promise.all([u.refetch(),f.refetch()])}finally{G(void 0)}}},W=async(s,v=y)=>{c.setValue("themePreference",s,{shouldDirty:!0}),c.setValue("customTheme",v??A,{shouldDirty:!0}),await E.mutateAsync({themePreference:s,customTheme:v??A})},ge=async s=>{c.setValue("gamificationTheme",s,{shouldDirty:!0}),await r.mutateAsync({gamificationTheme:s})};return w.useEffect(()=>{if(p)return se(D,y),()=>{se(p.themePreference,p.customTheme??null)}},[y,D,p,p==null?void 0:p.customTheme,p==null?void 0:p.themePreference]),m.isLoading||u.isLoading?e.jsx(Ie,{eyebrow:"Settings",title:"Loading settings",description:"Establishing the operator session and fetching current configuration.",columns:2,blocks:6}):m.isError?e.jsx(ae,{eyebrow:"Settings",error:m.error,onRetry:()=>void m.refetch()}):u.isError||!p?e.jsx(ae,{eyebrow:"Settings",error:u.error??new Error("Forge returned an empty settings payload."),onRetry:()=>void u.refetch()}):e.jsxs("div",{className:"mx-auto grid w-full max-w-[1220px] gap-5",children:[e.jsx(Be,{title:"Settings",description:"Tune execution policy, timer behaviour, and personal preferences.",badge:e.jsx(le,{integrityScore:p.security.integrityScore,storageMode:p.security.storageMode,lastAuditAt:p.security.lastAuditAt})}),null,e.jsx(We,{}),(V=m.data)!=null&&V.session?e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 rounded-[18px] 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:[e.jsxs("div",{children:["Operator session active as"," ",e.jsx("span",{className:"font-medium text-[var(--ui-ink-strong)]",children:m.data.session.actorLabel}),"."]}),e.jsx(k,{variant:"secondary",size:"sm",pending:T.isLoading,pendingLabel:"Resetting session",onClick:()=>void ue(),children:"Reset operator session"})]}):null,e.jsxs("div",{className:"grid gap-4",children:[U?null:e.jsx(re,{healthy:!1}),e.jsxs("form",{className:"grid gap-4",onSubmit:c.handleSubmit(async s=>{await C.mutateAsync(s)}),children:[e.jsxs($,{className:"p-4",children:[e.jsx("div",{className:N,children:"Operator profile"}),e.jsxs("div",{className:"grid gap-3 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:"Name"}),e.jsx(_,{...c.register("profile.operatorName")})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Email"}),e.jsx(_,{...c.register("profile.operatorEmail")})]})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Title"}),e.jsx(_,{...c.register("profile.operatorTitle")})]}),e.jsx("div",{className:`mt-2 ${N}`,children:"Execution policy"}),e.jsxs("div",{className:"grid gap-3 lg:grid-cols-[minmax(0,0.7fr)_minmax(0,1.3fr)]",children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Maximum active tasks"}),e.jsx(_,{type:"number",min:1,max:8,...c.register("execution.maxActiveTasks",{valueAsNumber:!0})})]}),e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Time accounting mode"}),e.jsx("div",{className:"grid gap-2 md:grid-cols-3",children:[{value:"split",label:"Split",description:"Multitasking divides credited time across active tasks."},{value:"parallel",label:"Parallel",description:"Every active task receives full credited wall time."},{value:"primary_only",label:"Primary only",description:"Only the highlighted task earns credited time during overlap."}].map(s=>e.jsxs("label",{className:`grid gap-2 ${P} px-3 py-3`,children:[e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx("input",{type:"radio",value:s.value,...c.register("execution.timeAccountingMode")}),e.jsx("span",{className:"text-[var(--ui-ink-strong)]",children:s.label})]}),e.jsx("span",{className:ie,children:s.description})]},s.value))})]})]}),e.jsx("div",{className:`mt-2 ${N}`,children:"Notification rules"}),e.jsxs("label",{className:`flex items-center justify-between ${P} px-3 py-2.5`,children:[e.jsx("span",{className:"text-[var(--ui-ink-medium)]",children:"Goal drift alerts"}),e.jsx("input",{type:"checkbox",...c.register("notifications.goalDriftAlerts")})]}),e.jsxs("label",{className:`flex items-center justify-between ${P} px-3 py-2.5`,children:[e.jsx("span",{className:"text-[var(--ui-ink-medium)]",children:"Daily quest reminders"}),e.jsx("input",{type:"checkbox",...c.register("notifications.dailyQuestReminders")})]}),e.jsxs("label",{className:`flex items-center justify-between ${P} px-3 py-2.5`,children:[e.jsx("span",{className:"text-[var(--ui-ink-medium)]",children:"Achievement celebrations"}),e.jsx("input",{type:"checkbox",...c.register("notifications.achievementCelebrations")})]})]}),e.jsxs($,{className:"p-4",children:[e.jsx("div",{className:N,children:"Theme calibration"}),e.jsx("p",{className:F,children:"Switch between Forge dark and light presets, follow the system palette, or save your own shell theme."}),e.jsx("div",{className:"grid gap-2 xl:grid-cols-3",children:Le.map(s=>{const v=te(s.value,y),h=D===s.value;return e.jsxs("button",{type:"button",onClick:()=>void W(s.value,(s.value==="custom",y)),className:`rounded-[18px] border px-3 py-3 text-left transition ${h?"border-[color-mix(in_srgb,var(--primary)_34%,var(--ui-border-subtle)_66%)] bg-[var(--ui-accent-soft)] shadow-[var(--ui-shadow-soft)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-hover)]"}`,children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-semibold text-[var(--ui-ink-strong)]",children:s.value==="custom"?y.label:s.label}),e.jsx("div",{className:"mt-1 line-clamp-2 text-xs leading-5 text-[var(--ui-ink-soft)]",children:s.description})]}),e.jsx("div",{className:`mt-1 size-4 rounded-full border ${h?"border-[color-mix(in_srgb,var(--primary)_65%,var(--ui-border-subtle)_35%)] bg-[var(--primary)]":"border-[var(--ui-border-strong)]"}`})]}),e.jsx(Ze,{theme:v})]},s.value)})}),e.jsxs("div",{className:`mt-3 flex flex-wrap items-center justify-between gap-3 ${P} px-3 py-3`,children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-[var(--ui-ink-strong)]",children:"Custom theme editor"}),e.jsx("div",{className:`mt-1 ${F}`,children:"Save a custom Forge palette through a guided modal, or paste and upload JSON directly."})]}),e.jsx(k,{type:"button",variant:D==="custom"?"secondary":"ghost",onClick:()=>d(!0),pending:E.isPending,children:D==="custom"?"Edit custom theme":"Create custom theme"})]})]}),e.jsxs($,{className:"p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:N,children:"Gamification style"}),e.jsx("p",{className:F,children:"Choose the reward art style and download its optional trophy, unlock, and mascot sprites."})]}),z!=null&&z.installed?e.jsx("span",{className:"inline-flex rounded-full border border-[color-mix(in_srgb,var(--success)_26%,var(--ui-border-subtle)_74%)] bg-[var(--ui-success-soft)] px-3 py-1 text-xs font-medium text-[var(--success)]",children:"Selected style downloaded"}):e.jsx("span",{className:"inline-flex rounded-full border border-[color-mix(in_srgb,var(--warning)_26%,var(--ui-border-subtle)_74%)] bg-[var(--ui-warning-soft)] px-3 py-1 text-xs font-medium text-[var(--warning)]",children:"Selected style not downloaded"})]}),e.jsx("div",{className:"mt-3 grid gap-2 xl:grid-cols-3",children:Me.map(s=>{const v=O===s.value,h=H.find(he=>he.id===s.value),I=(h==null?void 0:h.installed)??!1,xe=i.isPending&&i.variables===s.value;return e.jsxs("div",{className:`grid gap-2 rounded-[18px] border p-2.5 text-left transition ${v?"border-[color-mix(in_srgb,var(--warning)_30%,var(--ui-border-subtle)_70%)] bg-[var(--ui-warning-soft)] shadow-[var(--ui-shadow-soft)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-hover)]"}`,children:[e.jsx("button",{type:"button",onClick:()=>void ge(s.value),className:"grid gap-2 text-left","aria-label":`Select ${s.label}`,"aria-pressed":v,children:e.jsx(Ve,{selected:v,theme:s.value})}),e.jsxs("span",{className:"grid gap-1 px-1 pb-1",children:[e.jsx("span",{className:"text-sm font-semibold text-[var(--ui-ink-strong)]",children:s.label}),e.jsx("span",{className:"line-clamp-2 text-xs leading-5 text-[var(--ui-ink-soft)]",children:s.description}),e.jsx("span",{className:"mt-1 text-[11px] uppercase tracking-[0.14em] text-[var(--ui-ink-faint)]",children:I?`Downloaded ${(h==null?void 0:h.spriteCount)??0}/${(h==null?void 0:h.expectedSpriteCount)??0}`:"Not downloaded"}),e.jsxs(k,{type:"button",variant:I?"secondary":"primary",pending:xe,disabled:I||i.isPending,onClick:()=>i.mutate(s.value),children:[e.jsx(ve,{className:"size-4"}),I?"Downloaded":"Download"]})]})]},s.value)})}),r.isPending?e.jsx("div",{className:"text-sm text-[var(--ui-ink-faint)]",children:"Saving reward style…"}):null,i.isError?e.jsx("div",{className:"mt-3 rounded-[14px] border border-[color-mix(in_srgb,var(--danger)_28%,var(--ui-border-subtle)_72%)] bg-[var(--ui-danger-soft)] px-3 py-2 text-sm text-[var(--danger)]",children:i.error instanceof Error?i.error.message:"Could not download the selected reward art."}):null]}),e.jsxs($,{className:"p-4",children:[e.jsx("div",{className:N,children:a("common.settings.localeLabel")}),e.jsx("p",{className:F,children:a("common.settings.localeDescription")}),e.jsx("div",{className:"grid gap-3 md:grid-cols-2",children:[{value:"en",label:a("common.settings.localeEnglish")},{value:"fr",label:a("common.settings.localeFrench")}].map(s=>e.jsxs("label",{className:`flex items-center gap-3 ${P} px-3 py-3`,children:[e.jsx("input",{type:"radio",value:s.value,...c.register("localePreference")}),e.jsx("span",{className:"text-[var(--ui-ink-medium)]",children:s.label})]},s.value))}),e.jsx(k,{type:"submit",pending:C.isPending,pendingLabel:"Saving settings",children:"Save settings"})]})]}),U?e.jsx(re,{healthy:!0}):null,e.jsx(es,{integrityScore:p.security.integrityScore,storageMode:p.security.storageMode,lastAuditAt:p.security.lastAuditAt,doctor:me,doctorLoading:f.isFetching||ce.isLoading,onRefreshDoctor:()=>void f.refetch(),onApplyFix:s=>void pe(s),applyingFixId:de})]}),e.jsx(Ye,{open:t,onOpenChange:d,value:y,onSave:s=>void W("custom",s)})]})}export{ps as SettingsPage};
@@ -0,0 +1 @@
1
+ import{j as e,r as v}from"./vendor-Cpmju3nw.js";import{j as de,i as k,k as Y}from"./state-BtwEvpO6.js";import{u as Z}from"./forms-C5d5hTf2.js";import{S as ce}from"./settings-section-nav-CkqqtM0F.js";import{k as p,c as _,P as ee,f as oe,d as me,S as ue,e as xe,C as ge,I as J,T as P,B as se,dP as pe,dQ as he,cU as be,cm as ve,dR as fe,dS as je,a2 as we}from"./index-BejvcRGb.js";import{m as ae}from"./motion-DwjmC9aq.js";import{P as ye}from"./page-hero-DlHEJ0Yt.js";import{M as re}from"./metric-tile-DysHMgM3.js";import"./ui-B9O-eUim.js";import"./board-CLOHbg6t.js";function Ne(r){switch(r){case"platinum":return"bg-[var(--ui-accent-soft)] text-[var(--primary)]";case"gold":return"bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]";case"silver":return"bg-[var(--ui-surface-3)] text-[var(--ui-ink-medium)]";default:return"bg-[var(--ui-warning-soft)] text-[var(--warning)]"}}function ke(r){switch(r){case"surging":return"bg-[color-mix(in_srgb,var(--ui-accent-soft)_62%,var(--ui-success-soft)_38%)]";case"steady":return"bg-[var(--ui-accent-soft)]";default:return"bg-[color-mix(in_srgb,var(--ui-warning-soft)_54%,var(--ui-accent-soft)_46%)]"}}const E="min-w-0 overflow-hidden rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",te="min-w-0 overflow-hidden rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",A="font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",S="text-[var(--ui-ink-strong)]",$="text-[var(--ui-ink-soft)]",I="text-[var(--ui-ink-faint)]",O="bg-[var(--ui-surface-3)] text-[var(--ui-ink-medium)]";function _e({profile:r,achievements:m,milestoneRewards:d,momentumPulse:u,recentLedger:R=[],className:j,tone:X="core"}){const w=m.filter(t=>t.unlocked),h=(w.length>0?w:m).slice(0,3),C=d.slice(0,3),M=R.slice(0,3),F=Math.min(100,Math.round(r.currentLevelXp/r.nextLevelXp*100));return e.jsxs("section",{className:_("min-w-0 overflow-hidden rounded-[30px] border border-[var(--ui-border-subtle)] bg-[var(--card-gradient)] shadow-[var(--card-shadow)]",X==="psyche"&&"border-[color-mix(in_srgb,var(--success)_18%,var(--ui-border-subtle)_82%)]",j),children:[e.jsx("div",{className:_("px-5 py-5",ke(u.status)),children:e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:A,children:"Weekly progress"}),e.jsx("h2",{className:`mt-3 font-display text-3xl leading-none lg:text-4xl ${S}`,children:u.headline}),e.jsx("p",{className:`mt-3 max-w-3xl text-sm leading-7 ${$}`,children:u.detail})]}),e.jsxs("div",{className:"flex min-w-0 flex-wrap gap-2",children:[e.jsxs(p,{wrap:!0,className:O,children:["Level ",r.level]}),e.jsxs(p,{wrap:!0,className:O,children:[r.streakDays," day streak"]}),e.jsxs(p,{wrap:!0,className:O,children:[r.weeklyXp," weekly XP"]})]})]})}),e.jsxs("div",{className:"grid gap-5 px-5 py-5 xl:grid-cols-[minmax(0,1.2fr)_minmax(0,0.8fr)]",children:[e.jsxs("div",{className:"grid gap-5",children:[e.jsxs(ae.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},transition:{duration:.24,ease:"easeOut"},className:E,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-medium ${S}`,children:"Next reward"}),e.jsx("div",{className:`mt-2 text-sm ${$}`,children:u.nextMilestoneLabel})]}),e.jsx(p,{wrap:!0,className:"max-w-[12rem] shrink-0 self-start text-[var(--tertiary)]",children:u.celebrationLabel})]}),e.jsx("div",{className:"mt-5",children:e.jsx(ee,{value:F})}),e.jsxs("div",{className:`mt-3 flex flex-wrap items-center justify-between gap-3 text-xs uppercase tracking-[0.16em] ${I}`,children:[e.jsxs("span",{children:[r.currentLevelXp,"/",r.nextLevelXp," XP"]}),e.jsxs("span",{children:[r.comboMultiplier.toFixed(2),"x combo"]})]})]}),e.jsx("div",{className:"grid gap-3 md:grid-cols-3",children:h.map((t,c)=>e.jsxs(ae.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{duration:.24,delay:.04*c,ease:"easeOut"},className:E,children:[e.jsxs("div",{className:"flex min-w-0 items-start justify-between gap-3",children:[e.jsx("div",{className:`min-w-0 flex-1 font-medium ${S}`,children:t.title}),e.jsx(p,{wrap:!0,className:_("max-w-[8rem] shrink-0 self-start",Ne(t.tier)),children:t.tier})]}),e.jsx("div",{className:`mt-2 text-sm leading-6 ${$}`,children:t.summary}),e.jsx("div",{className:`mt-4 text-xs uppercase tracking-[0.16em] ${I}`,children:t.progressLabel})]},t.id))})]}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:E,children:[e.jsx("div",{className:A,children:"Rewards in progress"}),e.jsx("div",{className:"mt-4 grid gap-3",children:C.map(t=>{const c=Math.min(100,Math.round(t.current/t.target*100));return e.jsxs("div",{className:te,children:[e.jsxs("div",{className:"flex min-w-0 items-start justify-between gap-3",children:[e.jsx("div",{className:`min-w-0 flex-1 font-medium ${S}`,children:t.title}),e.jsx(p,{wrap:!0,className:_("max-w-[10.5rem] shrink-0 self-start",t.completed?"bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_76%,var(--ui-ink-strong)_24%)]":O),children:t.rewardLabel})]}),e.jsx("div",{className:`mt-2 text-sm ${$}`,children:t.summary}),e.jsx("div",{className:"mt-4",children:e.jsx(ee,{value:c})}),e.jsx("div",{className:`mt-3 text-xs uppercase tracking-[0.16em] ${I}`,children:t.progressLabel})]},t.id)})})]}),M.length>0?e.jsxs("div",{className:E,children:[e.jsx("div",{className:A,children:"Recent XP changes"}),e.jsx("div",{className:"mt-4 grid gap-3",children:M.map(t=>e.jsxs("div",{className:te,children:[e.jsxs("div",{className:"flex min-w-0 items-start justify-between gap-3",children:[e.jsx("div",{className:`min-w-0 flex-1 font-medium ${S}`,children:t.reasonTitle}),e.jsxs(p,{wrap:!0,className:_("max-w-[8rem] shrink-0 self-start",t.deltaXp>=0?"bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_76%,var(--ui-ink-strong)_24%)]":"bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]"),children:[t.deltaXp>0?"+":"",t.deltaXp," XP"]})]}),e.jsx("div",{className:`mt-2 text-sm ${$}`,children:t.reasonSummary}),e.jsx("div",{className:`mt-3 text-xs uppercase tracking-[0.16em] ${I}`,children:oe(t.createdAt)})]},t.id))})]}):null]})]})]})}const Q="min-w-0 rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",ie="min-w-0 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",B="min-w-0 rounded-[14px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-3 py-3 text-sm text-[var(--ui-ink-strong)] outline-none transition focus:border-[var(--primary)]/35 focus:bg-[var(--ui-surface-3)]",Se="font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",q="text-[var(--ui-ink-strong)]",n="text-[var(--ui-ink-soft)]",$e="text-[var(--ui-ink-faint)]",ne="text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]",Re="mt-4 rounded-[18px] border border-[color-mix(in_srgb,var(--success)_28%,var(--ui-border-subtle)_72%)] bg-[var(--ui-success-soft)] p-4 text-sm text-[color-mix(in_srgb,var(--success)_76%,var(--ui-ink-strong)_24%)]";function Xe(r){return JSON.stringify(r,null,2)}function le(r){const m=r.trim();if(!m)return{};const d=JSON.parse(m);if(!d||typeof d!="object"||Array.isArray(d))throw new Error("Expected a JSON object.");return d}function Ae(){var G,W,H;const r=me(),m=de(),[d,u]=v.useState(""),[R,j]=v.useState(null),[X,w]=v.useState(null),h=k({queryKey:["forge-operator-session"],queryFn:be}),C=h.isSuccess,M=k({queryKey:["forge-xp-metrics"],queryFn:ve}),F=k({queryKey:["forge-reward-rules"],queryFn:fe,enabled:C}),t=k({queryKey:["forge-reward-ledger"],queryFn:()=>je(30),enabled:C}),c=k({queryKey:["forge-psyche-overview"],queryFn:async()=>(await we()).overview}),b=Z({defaultValues:{title:"",description:"",active:!0,configJson:"{}"}}),l=Z({defaultValues:{entityType:"task",entityId:"",deltaXp:15,reasonTitle:"Operator bonus",reasonSummary:"Manual boost for a meaningful action captured with good provenance.",metadataJson:"{}"}}),K=async()=>{await Promise.all([m.invalidateQueries({queryKey:["forge-xp-metrics"]}),m.invalidateQueries({queryKey:["forge-reward-rules"]}),m.invalidateQueries({queryKey:["forge-reward-ledger"]})])},D=Y({mutationFn:s=>pe(s.ruleId,{title:s.title,description:s.description,active:s.active,config:s.config}),onSuccess:K}),f=Y({mutationFn:he,onSuccess:K}),x=((G=F.data)==null?void 0:G.rules)??[],T=v.useMemo(()=>{var s,i,y,N,L,U,z;return{system:[{id:"operator_manual_reward",label:"Operator reward ledger"}],goal:r.snapshot.goals.map(a=>({id:a.id,label:a.title})),project:r.snapshot.dashboard.projects.map(a=>({id:a.id,label:a.title})),task:r.snapshot.tasks.map(a=>({id:a.id,label:a.title})),habit:r.snapshot.habits.map(a=>({id:a.id,label:a.title})),tag:r.snapshot.tags.map(a=>({id:a.id,label:a.name})),note:[],insight:[],psyche_value:(((s=c.data)==null?void 0:s.values)??[]).map(a=>({id:a.id,label:a.title})),behavior_pattern:(((i=c.data)==null?void 0:i.patterns)??[]).map(a=>({id:a.id,label:a.title})),behavior:(((y=c.data)==null?void 0:y.behaviors)??[]).map(a=>({id:a.id,label:a.title})),belief_entry:(((N=c.data)==null?void 0:N.beliefs)??[]).map(a=>({id:a.id,label:a.statement})),mode_profile:(((L=c.data)==null?void 0:L.modes)??[]).map(a=>({id:a.id,label:a.title})),flashcard:(((U=c.data)==null?void 0:U.flashcards)??[]).map(a=>({id:a.id,label:a.title||a.message})),trigger_report:(((z=c.data)==null?void 0:z.reports)??[]).map(a=>({id:a.id,label:a.title}))}},[c.data,r.snapshot.dashboard.projects,r.snapshot.goals,r.snapshot.habits,r.snapshot.tags,r.snapshot.tasks]);v.useEffect(()=>{var N;const s=l.getValues("entityType"),i=l.getValues("entityId"),y=T[s]??[];i&&y.some(L=>L.id===i)||l.setValue("entityId",((N=y[0])==null?void 0:N.id)??"")},[l,T]),v.useEffect(()=>{x.length&&(!d||!x.some(s=>s.id===d))&&u(x[0].id)},[x,d]);const g=x.find(s=>s.id===d)??x[0]??null;v.useEffect(()=>{g&&(b.reset({title:g.title,description:g.description,active:g.active,configJson:Xe(g.config)}),j(null))},[g,b]);const o=(W=M.data)==null?void 0:W.metrics,V=(((H=t.data)==null?void 0:H.ledger)??[]).filter(s=>s.metadata.manual===!0).slice(0,8);return h.isLoading?e.jsx(ue,{eyebrow:"Settings · Rewards",title:"Loading reward controls",description:"Establishing the operator session and fetching reward configuration.",columns:2,blocks:6}):h.isError?e.jsx(xe,{eyebrow:"Settings · Rewards",error:h.error,onRetry:()=>void h.refetch()}):e.jsxs("div",{className:"mx-auto grid w-full max-w-[1220px] gap-5",children:[e.jsx(ye,{title:"Rewards",description:"XP command deck, reward rule editor, manual bonus grants, and ledger history."}),e.jsx(ce,{}),e.jsx("div",{className:"grid gap-5",children:e.jsxs(ge,{children:[e.jsx("div",{className:Se,children:"Reward operations"}),e.jsxs("div",{className:"mt-4 grid gap-4",children:[o?e.jsx(_e,{profile:o.profile,achievements:o.achievements,milestoneRewards:o.milestoneRewards,momentumPulse:o.momentumPulse,recentLedger:o.recentLedger}):null,o?e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsx(re,{label:"Total XP",value:o.profile.totalXp,tone:"core"}),e.jsx(re,{label:"Daily ambient",value:`${o.dailyAmbientXp} / ${o.dailyAmbientCap}`,tone:"core"})]}):null,e.jsxs("div",{className:"grid gap-4 xl:grid-cols-2",children:[e.jsxs("div",{className:Q,children:[e.jsx("div",{className:`font-medium ${q}`,children:"Reward rule editor"}),x.length>0?e.jsxs("form",{className:"mt-4 grid gap-4",onSubmit:b.handleSubmit(async s=>{try{j(null);const i=le(s.configJson);if(!g)return;await D.mutateAsync({ruleId:g.id,title:s.title,description:s.description,active:s.active,config:i})}catch(i){j(i instanceof Error?i.message:"Invalid reward rule config.")}}),children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:`text-sm ${n}`,children:"Rule"}),e.jsx("select",{className:B,value:d,onChange:s=>u(s.target.value),children:x.map(s=>e.jsx("option",{value:s.id,children:s.title},s.id))})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:`text-sm ${n}`,children:"Title"}),e.jsx(J,{...b.register("title")})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:`text-sm ${n}`,children:"Description"}),e.jsx(P,{className:"min-h-24",...b.register("description")})]}),e.jsxs("label",{className:"flex min-w-0 items-center justify-between gap-3 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-3",children:[e.jsx("span",{className:n,children:"Rule is active"}),e.jsx("input",{type:"checkbox",...b.register("active")})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:`text-sm ${n}`,children:"Config JSON"}),e.jsx(P,{className:"min-h-28 font-mono text-xs",...b.register("configJson")})]}),R?e.jsx("div",{className:`text-sm ${ne}`,children:R}):null,e.jsx(se,{type:"submit",pending:D.isPending,pendingLabel:"Saving rule",children:"Save reward rule"})]}):e.jsx("div",{className:`mt-4 text-sm ${n}`,children:"Loading reward rules..."})]}),e.jsxs("div",{className:Q,children:[e.jsx("div",{className:`font-medium ${q}`,children:"Manual bonus XP"}),e.jsxs("form",{className:"mt-4 grid gap-4",onSubmit:l.handleSubmit(async s=>{try{w(null);const i=le(s.metadataJson);await f.mutateAsync({entityType:s.entityType,entityId:s.entityId,deltaXp:s.deltaXp,reasonTitle:s.reasonTitle,reasonSummary:s.reasonSummary,metadata:i}),l.reset({...s,entityId:"",reasonTitle:"Operator bonus",reasonSummary:"Manual boost for a meaningful action captured with good provenance.",metadataJson:"{}"})}catch(i){w(i instanceof Error?i.message:"Invalid metadata payload.")}}),children:[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 ${n}`,children:"Entity type"}),e.jsx("select",{className:B,...l.register("entityType"),children:Object.keys(T).map(s=>e.jsx("option",{value:s,children:s.replaceAll("_"," ")},s))})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:`text-sm ${n}`,children:"Entity id"}),e.jsx("select",{className:B,...l.register("entityId"),children:(T[l.watch("entityType")]??[]).map(s=>e.jsx("option",{value:s.id,children:s.label},s.id))})]})]}),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 ${n}`,children:"Delta XP"}),e.jsx(J,{type:"number",...l.register("deltaXp",{valueAsNumber:!0})})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:`text-sm ${n}`,children:"Reason title"}),e.jsx(J,{...l.register("reasonTitle")})]})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:`text-sm ${n}`,children:"Reason summary"}),e.jsx(P,{className:"min-h-24",...l.register("reasonSummary")})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:`text-sm ${n}`,children:"Metadata JSON"}),e.jsx(P,{className:"min-h-24 font-mono text-xs",...l.register("metadataJson")})]}),X?e.jsx("div",{className:`text-sm ${ne}`,children:X}):null,e.jsx(se,{type:"submit",pending:f.isPending,pendingLabel:"Issuing bonus",children:"Issue bonus XP"})]}),f.data?e.jsxs("div",{className:Re,children:["Granted ",f.data.reward.deltaXp>0?"+":"",f.data.reward.deltaXp," XP for"," ",e.jsx("strong",{children:f.data.reward.reasonTitle}),"."]}):null]})]}),e.jsxs("div",{className:Q,children:[e.jsx("div",{className:`font-medium ${q}`,children:"Manual bonus history"}),e.jsx("div",{className:"mt-4 grid gap-3",children:V.length===0?e.jsx("div",{className:`${ie} text-sm ${n}`,children:"No manual bonus grants yet."}):V.map(s=>e.jsxs("div",{className:ie,children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center justify-between gap-3",children:[e.jsx("div",{className:`min-w-0 break-words font-medium ${q}`,children:s.reasonTitle}),e.jsxs(p,{wrap:!0,className:s.deltaXp>=0?"bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_76%,var(--ui-ink-strong)_24%)]":"bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]",children:[s.deltaXp>0?"+":"",s.deltaXp," XP"]})]}),e.jsx("div",{className:`mt-2 text-sm leading-6 ${n}`,children:s.reasonSummary||"No summary supplied."}),e.jsxs("div",{className:`mt-2 break-words text-xs uppercase tracking-[0.16em] [overflow-wrap:anywhere] ${$e}`,children:[s.entityType," · ",s.entityId," ·"," ",new Date(s.createdAt).toLocaleString()]})]},s.id))})]})]})]})})]})}export{Ae as SettingsRewardsPage};
@@ -1 +1 @@
1
- import{aJ as b,r as d,cm as v,cr as f,bP as g,aV as h,cY as y,cZ as j,b2 as k,ba as N,c_ as w,aF as S,c$ as C,j as e,bB as x,F as z,aK as E}from"./vendor-Dnkkx2co.js";import{C as T,Z as i}from"./index-QJkjKYzZ.js";const o=[{to:"/settings",label:"General",icon:v},{to:"/settings/data",label:"Data",icon:f},{to:"/settings/users",label:"Users",icon:g},{to:"/settings/calendar",label:"Calendar",icon:h},{to:"/settings/mobile",label:"Mobile",icon:y},{to:"/settings/models",label:"Models",icon:j},{to:"/settings/agents",label:"Agents",icon:k},{to:"/settings/wiki",label:"KarpaWiki",icon:N},{to:"/settings/logs",label:"Logs",icon:w},{to:"/settings/rewards",label:"Rewards",icon:S},{to:"/settings/bin",label:"Bin",icon:C}];function m(t,a){return a==="/settings"?t==="/settings":t===a||t.startsWith(`${a}/`)}function L({className:t}){const a=b(),[l,n]=d.useState(!1),c=d.useMemo(()=>[...o].sort((r,s)=>s.to.length-r.to.length).find(r=>m(a.pathname,r.to))??o[0],[a.pathname]);return d.useEffect(()=>{if(!l)return;const r=document.body.style.overflow,s=document.body.style.touchAction,u=p=>{p.key==="Escape"&&n(!1)};return document.body.style.overflow="hidden",document.body.style.touchAction="none",window.addEventListener("keydown",u),()=>{document.body.style.overflow=r,document.body.style.touchAction=s,window.removeEventListener("keydown",u)}},[l]),e.jsxs(e.Fragment,{children:[e.jsxs(T,{className:i("surface-shell-panel overflow-hidden p-2",t),children:[e.jsx("div",{className:"hidden items-center gap-3 lg:flex",children:e.jsx("div",{className:"flex flex-wrap gap-2",children:o.map(r=>e.jsxs(x,{to:r.to,end:r.to==="/settings",className:({isActive:s})=>i("inline-flex items-center gap-2 whitespace-nowrap rounded-full px-3 py-1.5 text-[11px] font-semibold uppercase tracking-[0.14em] transition",s||m(a.pathname,r.to)?"border border-[var(--primary)]/14 bg-[var(--ui-accent-soft)] text-[var(--primary)]":"border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-soft)] hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]"),children:[e.jsx(r.icon,{className:"size-3.5"}),e.jsx("span",{children:r.label})]},r.to))})}),e.jsx("div",{className:"flex items-center justify-between gap-3 lg:hidden",children:e.jsxs("button",{type:"button",className:"surface-shell-panel inline-flex min-w-0 flex-1 items-center justify-between gap-3 rounded-[22px] border px-3.5 py-2.5 text-left transition hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-hover)]",onClick:()=>n(!0),children:[e.jsxs("span",{className:"flex min-w-0 items-center gap-3",children:[e.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-2xl border border-[var(--primary)]/20 bg-[var(--primary)]/12",children:e.jsx(c.icon,{className:"size-4 text-[var(--primary)]"})}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-[10px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Settings section"}),e.jsx("span",{className:"mt-0.5 block truncate text-sm font-medium text-[var(--ui-ink-strong)]",children:c.label})]})]}),e.jsx("span",{className:"rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-2.5 py-1 text-[10px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Browse"})]})})]}),l&&typeof document<"u"?z.createPortal(e.jsxs("div",{className:"lg:hidden",children:[e.jsx("div",{className:"surface-overlay fixed inset-0 z-50 backdrop-blur-xl"}),e.jsx("button",{type:"button","aria-label":"Close settings sections",className:"fixed inset-0 z-[51]",onClick:()=>n(!1)}),e.jsx("div",{className:"pointer-events-none fixed inset-0 z-[52] flex items-end justify-center px-3 pt-3 sm:px-4 sm:pt-4",style:{paddingLeft:"max(0.75rem, calc(var(--forge-safe-area-left) + 0.75rem))",paddingRight:"max(0.75rem, calc(var(--forge-safe-area-right) + 0.75rem))",paddingTop:"max(0.75rem, calc(env(safe-area-inset-top) + 0.75rem))",paddingBottom:"calc(var(--forge-mobile-nav-clearance) - 0.25rem)"},children:e.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":"Settings sections",className:"surface-modal-panel pointer-events-auto flex max-h-[min(34rem,calc(100dvh-var(--forge-mobile-nav-clearance)-1rem))] w-full max-w-xl min-h-0 flex-col overflow-hidden rounded-[30px] border",children:[e.jsx("div",{className:"shrink-0 border-b border-[var(--ui-border-subtle)] px-4 pb-3 pt-4 sm:px-5",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-label text-[10px] uppercase tracking-[0.22em] text-[var(--ui-ink-faint)]",children:"Settings"}),e.jsxs("div",{className:"mt-1 flex min-w-0 flex-wrap items-center gap-2",children:[e.jsx("div",{className:"truncate text-base font-semibold text-[var(--ui-ink-strong)]",children:"Tune Forge"}),e.jsx("span",{className:"rounded-full border border-[var(--primary)]/20 bg-[var(--primary)]/12 px-2.5 py-1 text-[10px] uppercase tracking-[0.16em] text-[var(--primary)]",children:c.label})]}),e.jsx("div",{className:"mt-1 text-xs leading-5 text-[var(--ui-ink-soft)]",children:"Jump between users, calendar, models, rewards, and more."})]}),e.jsx("button",{type:"button","aria-label":"Close settings sections",className:"inline-flex size-10 shrink-0 items-center justify-center rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-soft)] transition hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]",onClick:()=>n(!1),children:e.jsx(E,{className:"size-4"})})]})}),e.jsx("div",{className:"min-h-0 overflow-y-auto p-3 overscroll-contain sm:p-4",children:e.jsx("div",{className:"grid gap-2",children:o.map(r=>{const s=m(a.pathname,r.to);return e.jsxs(x,{to:r.to,end:r.to==="/settings",onClick:()=>n(!1),className:i("group flex items-center justify-between gap-3 rounded-[22px] border px-3.5 py-3 transition-[transform,border-color,background-color,color] duration-150 hover:-translate-y-[1px] hover:text-[var(--ui-ink-strong)]",s?"border-[var(--primary)]/18 bg-[var(--ui-accent-soft)] text-[var(--ui-ink-strong)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-medium)] hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-hover)]"),children:[e.jsxs("span",{className:"flex min-w-0 items-center gap-3",children:[e.jsx("span",{className:i("flex size-10 shrink-0 items-center justify-center rounded-2xl border transition",s?"border-[var(--primary)]/18 bg-[var(--primary)]/14 text-[var(--primary)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-soft)] group-hover:border-[var(--ui-border-strong)] group-hover:text-[var(--ui-ink-strong)]"),children:e.jsx(r.icon,{className:"size-4"})}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate text-sm font-semibold text-[var(--ui-ink-strong)]",children:r.label}),e.jsx("span",{className:"mt-0.5 block text-[10px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Forge settings"})]})]}),e.jsx("span",{className:i("rounded-full px-2.5 py-1 text-[10px] uppercase tracking-[0.16em]",s?"bg-[var(--primary)]/16 text-[var(--primary)]":"bg-[var(--ui-surface-1)] text-[var(--ui-ink-faint)]"),children:s?"Current":"Open"})]},r.to)})})})]})})]}),document.body):null]})}export{L as S};
1
+ import{aJ as b,r as d,cg as v,cl as f,bH as g,aV as h,cY as y,cZ as j,b2 as k,bv as N,c_ as w,aF as S,c$ as C,j as e,bl as x,F as z,aK as E}from"./vendor-Cpmju3nw.js";import{C as T,c as i}from"./index-BejvcRGb.js";const o=[{to:"/settings",label:"General",icon:v},{to:"/settings/data",label:"Data",icon:f},{to:"/settings/users",label:"Users",icon:g},{to:"/settings/calendar",label:"Calendar",icon:h},{to:"/settings/mobile",label:"Mobile",icon:y},{to:"/settings/models",label:"Models",icon:j},{to:"/settings/agents",label:"Agents",icon:k},{to:"/settings/wiki",label:"KarpaWiki",icon:N},{to:"/settings/logs",label:"Logs",icon:w},{to:"/settings/rewards",label:"Rewards",icon:S},{to:"/settings/bin",label:"Bin",icon:C}];function u(t,a){return a==="/settings"?t==="/settings":t===a||t.startsWith(`${a}/`)}function B({className:t}){const a=b(),[l,n]=d.useState(!1),c=d.useMemo(()=>[...o].sort((r,s)=>s.to.length-r.to.length).find(r=>u(a.pathname,r.to))??o[0],[a.pathname]);return d.useEffect(()=>{if(!l)return;const r=document.body.style.overflow,s=document.body.style.touchAction,m=p=>{p.key==="Escape"&&n(!1)};return document.body.style.overflow="hidden",document.body.style.touchAction="none",window.addEventListener("keydown",m),()=>{document.body.style.overflow=r,document.body.style.touchAction=s,window.removeEventListener("keydown",m)}},[l]),e.jsxs(e.Fragment,{children:[e.jsxs(T,{className:i("surface-shell-panel overflow-hidden p-2",t),children:[e.jsx("div",{className:"hidden items-center gap-3 lg:flex",children:e.jsx("div",{className:"flex flex-wrap gap-2",children:o.map(r=>e.jsxs(x,{to:r.to,end:r.to==="/settings",className:({isActive:s})=>i("inline-flex items-center gap-2 whitespace-nowrap rounded-full px-3 py-1.5 text-[11px] font-semibold uppercase tracking-[0.14em] transition",s||u(a.pathname,r.to)?"border border-[var(--primary)]/14 bg-[var(--ui-accent-soft)] text-[var(--primary)]":"border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-soft)] hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]"),children:[e.jsx(r.icon,{className:"size-3.5"}),e.jsx("span",{children:r.label})]},r.to))})}),e.jsx("div",{className:"flex items-center justify-between gap-3 lg:hidden",children:e.jsxs("button",{type:"button",className:"surface-shell-panel inline-flex min-w-0 flex-1 items-center justify-between gap-3 rounded-[22px] border px-3.5 py-2.5 text-left transition hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-hover)]",onClick:()=>n(!0),children:[e.jsxs("span",{className:"flex min-w-0 items-center gap-3",children:[e.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-2xl border border-[var(--primary)]/20 bg-[var(--primary)]/12",children:e.jsx(c.icon,{className:"size-4 text-[var(--primary)]"})}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-[10px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Settings section"}),e.jsx("span",{className:"mt-0.5 block truncate text-sm font-medium text-[var(--ui-ink-strong)]",children:c.label})]})]}),e.jsx("span",{className:"rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-2.5 py-1 text-[10px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Browse"})]})})]}),l&&typeof document<"u"?z.createPortal(e.jsxs("div",{className:"lg:hidden",children:[e.jsx("div",{className:"surface-overlay fixed inset-0 z-50 backdrop-blur-xl"}),e.jsx("button",{type:"button","aria-label":"Close settings sections",className:"fixed inset-0 z-[51]",onClick:()=>n(!1)}),e.jsx("div",{className:"pointer-events-none fixed inset-0 z-[52] flex items-end justify-center px-3 pt-3 sm:px-4 sm:pt-4",style:{paddingLeft:"max(0.75rem, calc(var(--forge-safe-area-left) + 0.75rem))",paddingRight:"max(0.75rem, calc(var(--forge-safe-area-right) + 0.75rem))",paddingTop:"max(0.75rem, calc(env(safe-area-inset-top) + 0.75rem))",paddingBottom:"calc(var(--forge-mobile-nav-clearance) - 0.25rem)"},children:e.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":"Settings sections",className:"surface-modal-panel pointer-events-auto flex max-h-[min(34rem,calc(100dvh-var(--forge-mobile-nav-clearance)-1rem))] w-full max-w-xl min-h-0 flex-col overflow-hidden rounded-[30px] border",children:[e.jsx("div",{className:"shrink-0 border-b border-[var(--ui-border-subtle)] px-4 pb-3 pt-4 sm:px-5",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-label text-[10px] uppercase tracking-[0.22em] text-[var(--ui-ink-faint)]",children:"Settings"}),e.jsxs("div",{className:"mt-1 flex min-w-0 flex-wrap items-center gap-2",children:[e.jsx("div",{className:"truncate text-base font-semibold text-[var(--ui-ink-strong)]",children:"Tune Forge"}),e.jsx("span",{className:"rounded-full border border-[var(--primary)]/20 bg-[var(--primary)]/12 px-2.5 py-1 text-[10px] uppercase tracking-[0.16em] text-[var(--primary)]",children:c.label})]}),e.jsx("div",{className:"mt-1 text-xs leading-5 text-[var(--ui-ink-soft)]",children:"Jump between users, calendar, models, rewards, and more."})]}),e.jsx("button",{type:"button","aria-label":"Close settings sections",className:"inline-flex size-10 shrink-0 items-center justify-center rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-soft)] transition hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]",onClick:()=>n(!1),children:e.jsx(E,{className:"size-4"})})]})}),e.jsx("div",{className:"min-h-0 overflow-y-auto p-3 overscroll-contain sm:p-4",children:e.jsx("div",{className:"grid gap-2",children:o.map(r=>{const s=u(a.pathname,r.to);return e.jsxs(x,{to:r.to,end:r.to==="/settings",onClick:()=>n(!1),className:i("group flex items-center justify-between gap-3 rounded-[22px] border px-3.5 py-3 transition-[transform,border-color,background-color,color] duration-150 hover:-translate-y-[1px] hover:text-[var(--ui-ink-strong)]",s?"border-[var(--primary)]/18 bg-[var(--ui-accent-soft)] text-[var(--ui-ink-strong)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-medium)] hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-hover)]"),children:[e.jsxs("span",{className:"flex min-w-0 items-center gap-3",children:[e.jsx("span",{className:i("flex size-10 shrink-0 items-center justify-center rounded-2xl border transition",s?"border-[var(--primary)]/18 bg-[var(--primary)]/14 text-[var(--primary)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-soft)] group-hover:border-[var(--ui-border-strong)] group-hover:text-[var(--ui-ink-strong)]"),children:e.jsx(r.icon,{className:"size-4"})}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate text-sm font-semibold text-[var(--ui-ink-strong)]",children:r.label}),e.jsx("span",{className:"mt-0.5 block text-[10px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Forge settings"})]})]}),e.jsx("span",{className:i("rounded-full px-2.5 py-1 text-[10px] uppercase tracking-[0.16em]",s?"bg-[var(--primary)]/16 text-[var(--primary)]":"bg-[var(--ui-surface-1)] text-[var(--ui-ink-faint)]"),children:s?"Current":"Open"})]},r.to)})})})]})})]}),document.body):null]})}export{B as S};
@@ -0,0 +1 @@
1
+ import{r as g,j as e,aC as ce}from"./vendor-Cpmju3nw.js";import{i as de,k as Z}from"./state-BtwEvpO6.js";import{S as he}from"./settings-section-nav-CkqqtM0F.js";import{P as ue}from"./page-hero-DlHEJ0Yt.js";import{i as pe,C as ge,B as me,M as xe}from"./graph-Cd5WF3lw.js";import{C as F,a4 as fe,k as b,I as T,T as be,P as ve,d as je,B as J,dT as we,dU as ye,dV as Ne,dW as ke}from"./index-BejvcRGb.js";import{U as E}from"./user-badge-BKzwGZDd.js";import{Q as ie,F as $,a as H}from"./question-flow-dialog-BByFV8Yw.js";import"./motion-DwjmC9aq.js";import"./ui-B9O-eUim.js";import"./board-CLOHbg6t.js";import"./forms-C5d5hTf2.js";const ae=[{id:"visibility",label:"Discovery and visibility",description:"What the source user can discover, inspect, and pull into read flows on the target side.",rights:[{key:"discoverable",label:"Discoverable",description:"The target appears as a reachable collaborator in the source user's graph and pickers."},{key:"canListUsers",label:"List users",description:"The source user can include the target in directory, comparison, and routing surfaces."},{key:"canReadProfile",label:"Read profile",description:"The source user can inspect the target's identity card, handle, type, and description."},{key:"canReadEntities",label:"Read entities",description:"The source user can read the target's goals, projects, tasks, notes, strategies, and related records."},{key:"canSearchEntities",label:"Search entities",description:"The source user can find the target's work through Forge search and entity pickers."}]},{id:"coordination",label:"Messaging, context, and handoff",description:"What the source user can message, connect, and coordinate on the target side before changing execution.",rights:[{key:"canLinkEntities",label:"Share context",description:"The source user can attach the target's records into shared notes, strategies, calendar context, and cross-owner plans."},{key:"canCoordinate",label:"Message and coordinate",description:"The source user can communicate with the target through Forge, hand off work, and coordinate execution."},{key:"canViewMetrics",label:"View metrics",description:"The source user can inspect the target's XP, alignment, and progress metrics."},{key:"canViewActivity",label:"View activity",description:"The source user can inspect the target's activity stream, evidence, and execution trail."}]},{id:"execution",label:"Plan and execution control",description:"What the source user can actually change on the target side once collaboration is trusted.",rights:[{key:"canManageStrategies",label:"Manage strategies",description:"The source user can draft and update strategies that belong to the target."},{key:"canCreateOnBehalf",label:"Create on behalf",description:"The source user can intentionally create new target-owned entities."},{key:"canAffectEntities",label:"Affect entities",description:"The source user can mutate work that belongs to the target."}]}],Ce=[{id:"full_collab",label:"Full collaboration",description:"Use when two humans or agents can see, coordinate, plan, and change each other's work.",rights:{discoverable:!0,canListUsers:!0,canReadProfile:!0,canReadEntities:!0,canSearchEntities:!0,canLinkEntities:!0,canCoordinate:!0,canAffectEntities:!0,canManageStrategies:!0,canCreateOnBehalf:!0,canViewMetrics:!0,canViewActivity:!0}},{id:"coordination_only",label:"Coordinate only",description:"Use when the source user may see and coordinate with the target but should not directly mutate target-owned work.",rights:{discoverable:!0,canListUsers:!0,canReadProfile:!0,canReadEntities:!0,canSearchEntities:!0,canLinkEntities:!0,canCoordinate:!0,canAffectEntities:!1,canManageStrategies:!0,canCreateOnBehalf:!1,canViewMetrics:!0,canViewActivity:!0}},{id:"observe_only",label:"Observe only",description:"Use when the source user should keep visibility into the target without planning or execution control.",rights:{discoverable:!0,canListUsers:!0,canReadProfile:!0,canReadEntities:!0,canSearchEntities:!0,canLinkEntities:!1,canCoordinate:!1,canAffectEntities:!1,canManageStrategies:!1,canCreateOnBehalf:!1,canViewMetrics:!0,canViewActivity:!0}},{id:"hidden",label:"Hidden edge",description:"Use when this direction should stop discovering, reading, or acting on the target.",rights:{discoverable:!1,canListUsers:!1,canReadProfile:!1,canReadEntities:!1,canSearchEntities:!1,canLinkEntities:!1,canCoordinate:!1,canAffectEntities:!1,canManageStrategies:!1,canCreateOnBehalf:!1,canViewMetrics:!1,canViewActivity:!1}}],A=ae.reduce((s,n)=>s+n.rights.length,0);function P(s){return Object.values(s.config.rights).filter(Boolean).length}function re(s){const n=[];return s.config.rights.canReadEntities&&n.push("See"),s.config.rights.canCoordinate&&n.push("Message"),s.config.rights.canManageStrategies&&n.push("Plan"),s.config.rights.canAffectEntities&&n.push("Affect"),n.join(" · ")||"Hidden"}function Ue(s){return!s.config.rights.discoverable&&!s.config.rights.canReadEntities?"Hidden":s.config.rights.canAffectEntities&&s.config.rights.canManageStrategies?"Trusted":s.config.rights.canCoordinate||s.config.rights.canLinkEntities?"Coordinated":"Observed"}function ne(s){return[{id:"see",label:"See",enabled:s.config.rights.discoverable&&s.config.rights.canReadEntities&&s.config.rights.canSearchEntities},{id:"message",label:"Message",enabled:s.config.rights.canCoordinate},{id:"share",label:"Share context",enabled:s.config.rights.canLinkEntities},{id:"plan",label:"Plan",enabled:s.config.rights.canManageStrategies},{id:"affect",label:"Affect",enabled:s.config.rights.canAffectEntities||s.config.rights.canCreateOnBehalf}]}function Ee(s,n){return Object.entries(n.rights).every(([i,u])=>s.config.rights[i]===u)}function Se(s,n){const i=s.filter(a=>a.kind==="human"),u=s.filter(a=>a.kind==="bot"),p={x:560,y:360},m={width:226,height:132},d=i[0]??null,w=[...i.slice(d?1:0).map(a=>({user:a,radius:245,offset:-90})),...u.map(a=>({user:a,radius:390,offset:-90}))],f=w.length,y=[...d?[{user:d,position:{x:p.x-m.width/2,y:p.y-m.height/2}}]:[],...w.map((a,c)=>{const h=(a.offset+360/Math.max(f,1)*c)*Math.PI/180;return{user:a.user,position:{x:p.x+Math.cos(h)*a.radius-m.width/2,y:p.y+Math.sin(h)*a.radius-m.height/2}}})],C=new Set(n.selectedGrant?[n.selectedGrant.subjectUserId,n.selectedGrant.targetUserId]:n.selectedUserId?[n.selectedUserId]:[]);return y.map(({user:a,position:c})=>{const h=C.has(a.id),t=a.id===n.selectedUserId;return{id:a.id,position:c,draggable:!1,selectable:!1,data:{label:e.jsxs("div",{className:`min-w-[206px] rounded-[22px] border px-4 py-4 shadow-[var(--ui-shadow-soft)] transition ${t?"border-[color-mix(in_srgb,var(--warning)_45%,var(--ui-border-subtle)_55%)] bg-[var(--ui-warning-soft)]":h?"border-[color-mix(in_srgb,var(--primary)_28%,var(--ui-border-subtle)_72%)] bg-[var(--ui-accent-soft)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)]"}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx(E,{user:a}),e.jsx(b,{tone:"meta",children:a.kind})]}),e.jsxs("div",{className:"mt-3 text-xs text-[var(--ui-ink-soft)]",children:["@",a.handle]}),e.jsx("div",{className:"mt-2 line-clamp-2 text-xs leading-5 text-[var(--ui-ink-faint)]",children:a.description||"No user description yet."})]})},style:{background:"transparent",border:"none",padding:0}}})}function Ie(s,n,i){return s.filter(u=>u.subjectUserId!==u.targetUserId).map(u=>{const p=n===u.id,m=i!==null&&(u.subjectUserId===i||u.targetUserId===i),d=P(u),v=p?"var(--warning)":!u.config.rights.discoverable&&!u.config.rights.canReadEntities?"var(--danger)":m?"var(--primary)":"var(--ui-border-strong)";return{id:u.id,source:u.subjectUserId,target:u.targetUserId,label:`${re(u)} · ${d}/${A}`,markerEnd:{type:xe.ArrowClosed,color:v},labelStyle:{fill:p?"var(--warning)":"var(--ui-ink-medium)",fontSize:11,fontWeight:600},labelBgStyle:{fill:p?"var(--ui-warning-soft)":"var(--ui-surface-1)",stroke:p?"color-mix(in_srgb,var(--warning)_36%,var(--ui-border-subtle)_64%)":"var(--ui-border-subtle)",strokeWidth:1},labelBgPadding:[7,5],labelBgBorderRadius:8,style:{stroke:v,strokeWidth:p?2.5:m?1.8:1.25},animated:p}})}function Me({users:s,grants:n,selectedGrantId:i=null,selectedUserId:u=null,onOpenGrant:p,onOpenUser:m}){const d=n.find(c=>c.id===i)??null,v=g.useMemo(()=>Se(s,{selectedUserId:u,selectedGrant:d}),[d,u,s]),w=g.useMemo(()=>Ie(n,i,u),[n,i,u]),f=g.useMemo(()=>n.filter(c=>c.subjectUserId!==c.targetUserId),[n]),y=f.filter(c=>P(c)===A).length,C=f.filter(c=>c.config.rights.canCoordinate).length,a=f.filter(c=>c.config.rights.canAffectEntities||c.config.rights.canCreateOnBehalf).length;return e.jsxs(F,{className:"overflow-hidden p-0",children:[e.jsxs("div",{className:"grid gap-4 border-b border-[var(--ui-border-subtle)] px-5 py-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"max-w-3xl",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Directed relationship graph"}),e.jsx(fe,{content:"Keep Forge, OpenClaw, Hermes, and the browser on the same runtime and storage root when these arrows should describe one shared human and bot system.",label:"Explain the shared runtime rule"})]}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Click a user card to open that user's settings. Click any arrow to open the exact directional relationship flow for that lane."})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(b,{tone:"meta",children:[f.length," edges"]}),e.jsxs(b,{className:"bg-[var(--ui-success-soft)] text-[var(--success)]",children:[y," fully open"]})]})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-3",children:[e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Full collaboration"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:y}),e.jsx("div",{className:"text-xs leading-5 text-[var(--ui-ink-faint)]",children:"Directions still running with the default fully open posture."})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Coordination lanes"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:C}),e.jsx("div",{className:"text-xs leading-5 text-[var(--ui-ink-faint)]",children:"Directions allowed to coordinate directly through Forge."})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Execution control"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:a}),e.jsx("div",{className:"text-xs leading-5 text-[var(--ui-ink-faint)]",children:"Directions allowed to create or mutate target-owned work."})]})]})]}),e.jsx("div",{className:"h-[clamp(26rem,58vh,42rem)] bg-[linear-gradient(180deg,var(--ui-surface-2),var(--ui-surface-1))] sm:h-[min(72vh,54rem)] sm:min-h-[34rem]",children:e.jsxs(pe,{className:"user-relationship-flow",nodes:v,edges:w,fitView:!0,fitViewOptions:{padding:.1,maxZoom:.95},nodesDraggable:!1,nodesConnectable:!1,elementsSelectable:!0,onNodeClick:(c,h)=>{m(h.id)},onEdgeClick:(c,h)=>{p(h.id)},attributionPosition:"bottom-left",children:[e.jsx(ge,{showInteractive:!1}),e.jsx(me,{gap:28,size:1,color:"var(--ui-border-subtle)"})]})})]})}const O="rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",Y="text-sm font-medium text-[var(--ui-ink-strong)]",Oe="text-sm leading-6 text-[var(--ui-ink-soft)]",Re={kind:"human",handle:"",displayName:"",description:"",accentColor:"#c0c1ff"};function ee(s){return s?{kind:s.kind,handle:s.handle,displayName:s.displayName,description:s.description,accentColor:s.accentColor}:Re}function Fe({open:s,onOpenChange:n,user:i,grants:u,ownership:p,xp:m,pending:d=!1,onSubmit:v,onOpenRelationship:w}){const[f,y]=g.useState(()=>ee(i)),[C,a]=g.useState(null);g.useEffect(()=>{s&&(y(ee(i)),a(null))},[s,i]);const c=g.useMemo(()=>u.filter(o=>o.subjectUserId!==o.targetUserId),[u]),h=g.useMemo(()=>i?c.filter(o=>o.subjectUserId===i.id):[],[c,i]),t=g.useMemo(()=>i?c.filter(o=>o.targetUserId===i.id):[],[c,i]),N=[{id:"identity",eyebrow:i?"Edit user":"Create user",title:i?"Update the user identity":"Add a human or bot user",description:"Set the owner type and the public identity Forge will use across ownership, routing, and collaboration surfaces.",render:(o,x)=>e.jsxs(e.Fragment,{children:[e.jsx($,{label:"Kind",description:"Humans represent real people. Bots represent agents or automations with their own ownership lane.",children:e.jsx(H,{columns:2,value:o.kind,onChange:k=>x({kind:k}),options:[{value:"human",label:"Human",description:"Use for a real person in the Forge runtime."},{value:"bot",label:"Bot",description:"Use for an agent, assistant, or automation actor."}]})}),e.jsx($,{label:"Handle",description:"This becomes the stable short id shown as @handle.",hint:"Use lowercase and a durable label, for example forge-operator or planner-bot.",children:e.jsx(T,{value:o.handle,onChange:k=>x({handle:k.target.value}),placeholder:"forge-operator"})}),e.jsx($,{label:"Display name",description:"This is the human-readable label used across the UI.",children:e.jsx(T,{value:o.displayName,onChange:k=>x({displayName:k.target.value}),placeholder:"Forge Operator"})})]})},{id:"profile",eyebrow:"Profile",title:"Describe the user lane",description:"Capture what this user represents in the shared Forge runtime and pick the accent color that helps the lane stay recognizable.",render:(o,x)=>e.jsxs(e.Fragment,{children:[e.jsx($,{label:"Description",description:"Explain what this user is responsible for and what side of the system it represents.",children:e.jsx(be,{value:o.description,onChange:k=>x({description:k.target.value}),className:"min-h-36",placeholder:"Primary human operator for strategy, execution, and review."})}),e.jsx($,{label:"Accent color",description:"Forge uses this accent to help the user stand out in ownership and collaboration surfaces.",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(T,{value:o.accentColor,onChange:k=>x({accentColor:k.target.value}),placeholder:"#c0c1ff"}),e.jsx("div",{className:"size-10 shrink-0 rounded-full border border-[var(--ui-border-subtle)]",style:{backgroundColor:o.accentColor||"#c0c1ff"}})]})}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[e.jsxs("div",{className:`${O} px-4 py-3`,children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Owned records"}),e.jsx("div",{className:"mt-2 text-[var(--ui-ink-strong)]",children:(p==null?void 0:p.totalOwnedEntities)??0})]}),e.jsxs("div",{className:`${O} px-4 py-3`,children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Total XP"}),e.jsx("div",{className:"mt-2 text-[var(--ui-ink-strong)]",children:(m==null?void 0:m.totalXp)??0})]}),e.jsxs("div",{className:`${O} px-4 py-3`,children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Weekly XP"}),e.jsx("div",{className:"mt-2 text-[var(--ui-ink-strong)]",children:(m==null?void 0:m.weeklyXp)??0})]})]})]})},{id:"relationships",eyebrow:"Relationships",title:"Open directional relationship settings",description:"Each arrow is a separate contract. Open the exact lane you want to adjust and Forge will take you into the relationship flow.",render:()=>i?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`${O} p-4`,children:[e.jsx(E,{user:i}),e.jsxs("div",{className:`mt-3 ${Oe}`,children:["@",i.handle," · ",i.description||"No description yet."]})]}),e.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:Y,children:"Outbound lanes"}),h.length>0?h.map(o=>e.jsxs("button",{type:"button",className:`${O} px-4 py-4 text-left transition hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-hover)]`,onClick:()=>w(o.id),children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(E,{user:o.subjectUser}),e.jsx("span",{className:"text-[var(--ui-ink-faint)]",children:"→"}),e.jsx(E,{user:o.targetUser})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx(b,{tone:"meta",children:re(o)}),e.jsxs(b,{tone:"meta",children:[P(o),"/",A," rights"]})]})]},o.id)):e.jsx("div",{className:"rounded-[20px] border border-dashed border-[var(--ui-border-subtle)] px-4 py-4 text-sm text-[var(--ui-ink-soft)]",children:"No outbound relationship lanes yet."})]}),e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:Y,children:"Inbound lanes"}),t.length>0?t.map(o=>e.jsxs("button",{type:"button",className:`${O} px-4 py-4 text-left transition hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-hover)]`,onClick:()=>w(o.id),children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(E,{user:o.subjectUser}),e.jsx("span",{className:"text-[var(--ui-ink-faint)]",children:"→"}),e.jsx(E,{user:o.targetUser})]}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:ne(o).map(x=>e.jsx(b,{className:x.enabled?"bg-[var(--ui-surface-1)] text-[var(--ui-ink-medium)]":"bg-[var(--ui-surface-1)] text-[var(--ui-ink-faint)] opacity-70",children:x.label},`${o.id}-${x.id}`))})]},o.id)):e.jsx("div",{className:"rounded-[20px] border border-dashed border-[var(--ui-border-subtle)] px-4 py-4 text-sm text-[var(--ui-ink-soft)]",children:"No inbound relationship lanes yet."})]})]})]}):e.jsx("div",{className:"rounded-[20px] border border-dashed border-[var(--ui-border-subtle)] px-4 py-4 text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Create the user first, then Forge will generate the directional relationship lanes you can tune from here."})}];return e.jsx(ie,{open:s,onOpenChange:n,eyebrow:i?"User settings":"Create user",title:i?"User settings":"Create user",description:"Edit the user identity, clarify what this lane represents, and jump into relationship settings without crowding the page.",value:f,onChange:y,draftPersistenceKey:i?`users.settings.${i.id}`:"users.settings.new",steps:N,submitLabel:i?"Save user":"Create user",pending:d,pendingLabel:i?"Saving user":"Creating user",error:C,contentClassName:"lg:w-[min(58rem,calc(100vw-1.5rem))]",onSubmit:async()=>{const o=f.handle.trim(),x=f.displayName.trim();if(o.length===0){a("Add a handle before saving this user.");return}if(x.length===0){a("Add a display name before saving this user.");return}await v({userId:i==null?void 0:i.id,input:{kind:f.kind,handle:o,displayName:x,description:f.description.trim(),accentColor:f.accentColor.trim()||"#c0c1ff"}}),n(!1)}})}const _="rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",S="text-sm font-medium text-[var(--ui-ink-strong)]",G="text-sm leading-6 text-[var(--ui-ink-soft)]",Ae="text-xs leading-5 text-[var(--ui-ink-faint)]";function se(s,n){return{accessLevel:(s==null?void 0:s.accessLevel)??"manage",applyScope:"this_arrow",rights:{discoverable:(s==null?void 0:s.config.rights.discoverable)??!0,canListUsers:(s==null?void 0:s.config.rights.canListUsers)??!0,canReadProfile:(s==null?void 0:s.config.rights.canReadProfile)??!0,canReadEntities:(s==null?void 0:s.config.rights.canReadEntities)??!0,canSearchEntities:(s==null?void 0:s.config.rights.canSearchEntities)??!0,canLinkEntities:(s==null?void 0:s.config.rights.canLinkEntities)??!0,canCoordinate:(s==null?void 0:s.config.rights.canCoordinate)??!0,canAffectEntities:(s==null?void 0:s.config.rights.canAffectEntities)??!0,canManageStrategies:(s==null?void 0:s.config.rights.canManageStrategies)??!0,canCreateOnBehalf:(s==null?void 0:s.config.rights.canCreateOnBehalf)??!0,canViewMetrics:(s==null?void 0:s.config.rights.canViewMetrics)??!0,canViewActivity:(s==null?void 0:s.config.rights.canViewActivity)??!0}}}function $e({open:s,onOpenChange:n,grant:i,grants:u,pending:p=!1,onSubmit:m}){const d=g.useMemo(()=>i?u.find(a=>a.subjectUserId===i.targetUserId&&a.targetUserId===i.subjectUserId)??null:null,[i,u]),[v,w]=g.useState(()=>se(i,!!d));g.useEffect(()=>{s&&w(se(i,!!d))},[i,s,d]);const f=g.useMemo(()=>Object.values(v.rights).filter(Boolean).length,[v.rights]),y=Math.round(f/A*100),C=[{id:"posture",eyebrow:"Relationship posture",title:"Set the trust mode for this arrow",description:"Each arrow is directional. Decide whether you want to tune only this lane or mirror the same contract onto both directions.",render:(a,c)=>e.jsxs(e.Fragment,{children:[i?e.jsxs("div",{className:`${_} p-4`,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(E,{user:i.subjectUser}),e.jsx("span",{className:"text-[var(--ui-ink-faint)]",children:"→"}),e.jsx(E,{user:i.targetUser})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx(b,{tone:"meta",children:Ue(i)}),e.jsxs(b,{tone:"meta",children:[P(i),"/",A," rights"]})]})]}):null,e.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:S,children:"Access level"}),e.jsx(H,{columns:2,value:a.accessLevel,onChange:h=>c({accessLevel:h}),options:[{value:"view",label:"View",description:"Use when this lane should stay mostly observational."},{value:"manage",label:"Manage",description:"Use when the source side can actively collaborate or act."}]})]}),d?e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:S,children:"Apply scope"}),e.jsx(H,{columns:2,value:a.applyScope,onChange:h=>c({applyScope:h}),options:[{value:"this_arrow",label:"This arrow",description:"Only change the exact direction you opened."},{value:"both_arrows",label:"Both arrows",description:"Mirror the same contract onto the reverse direction too."}]})]}):null]}),e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:S,children:"Quick preset"}),e.jsx("div",{className:"grid gap-3 md:grid-cols-2",children:Ce.map(h=>e.jsxs("button",{type:"button",className:`rounded-[22px] border p-4 text-left transition ${i&&Ee(i,h)?"border-[color-mix(in_srgb,var(--warning)_32%,var(--ui-border-subtle)_68%)] bg-[var(--ui-warning-soft)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-hover)]"}`,onClick:()=>c({rights:{...a.rights,...h.rights}}),children:[e.jsx("div",{className:S,children:h.label}),e.jsx("div",{className:`mt-2 ${G}`,children:h.description})]},h.id))})]})]})},{id:"rights",eyebrow:"Rights",title:"Tune the individual permissions",description:"Use the preset as the starting point, then sharpen the exact boundaries only where this relationship needs them.",render:(a,c)=>e.jsx(e.Fragment,{children:ae.map(h=>e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:S,children:h.label}),e.jsx("div",{className:`mt-1 ${G}`,children:h.description})]}),e.jsx("div",{className:"grid gap-2",children:h.rights.map(t=>e.jsxs("label",{className:"flex items-start justify-between gap-3 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:S,children:t.label}),e.jsx("div",{className:`mt-1 ${Ae}`,children:t.description})]}),e.jsx("input",{type:"checkbox",checked:a.rights[t.key],onChange:N=>c({rights:{...a.rights,[t.key]:N.target.checked}})})]},t.key))})]},h.id))})},{id:"review",eyebrow:"Review",title:"Review the final relationship contract",description:"Check the enabled capabilities, confirm whether both directions should match, and then save the relationship.",render:a=>{var c,h;return e.jsx(e.Fragment,{children:e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsxs("div",{className:`${_} p-4`,children:[e.jsx("div",{className:S,children:"Capability coverage"}),e.jsx("div",{className:"mt-4",children:e.jsx(ve,{value:y})}),e.jsxs("div",{className:"mt-3 text-sm text-[var(--ui-ink-soft)]",children:[f,"/",A," rights enabled"]}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:ne({...i??{id:"draft",subjectUserId:"",targetUserId:"",accessLevel:a.accessLevel,config:{self:!1,mutable:!0,linkedEntities:!0,rights:a.rights},createdAt:"",updatedAt:"",subjectUser:null,targetUser:null},accessLevel:a.accessLevel,config:{...(i==null?void 0:i.config)??{self:!1,mutable:!0,linkedEntities:!0},rights:a.rights}}).map(t=>e.jsx(b,{className:t.enabled?"bg-[var(--ui-surface-1)] text-[var(--ui-ink-medium)]":"bg-[var(--ui-surface-1)] text-[var(--ui-ink-faint)] opacity-70",children:t.label},t.id))})]}),e.jsxs("div",{className:`${_} p-4`,children:[e.jsx("div",{className:S,children:"Save scope"}),e.jsx("div",{className:`mt-3 ${G}`,children:a.applyScope==="both_arrows"&&d?"Forge will apply the same access level and rights to both directions of this pair.":"Forge will only update the exact arrow you opened."}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsxs(b,{tone:"meta",children:["access ",a.accessLevel]}),e.jsxs(b,{tone:"meta",children:["scope"," ",a.applyScope==="both_arrows"&&d?"both arrows":"this arrow"]})]}),d?e.jsxs("div",{className:"mt-4 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-3 text-sm text-[var(--ui-ink-soft)]",children:["Reverse arrow available:"," ",((c=d.subjectUser)==null?void 0:c.displayName)??d.subjectUserId," ","→"," ",((h=d.targetUser)==null?void 0:h.displayName)??d.targetUserId]}):null]})]})})}}];return e.jsx(ie,{open:s,onOpenChange:n,eyebrow:"Relationship settings",title:"Relationship settings",description:"Edit the exact directional contract between two users without keeping the full rights editor pinned on the page.",value:v,onChange:w,draftPersistenceKey:i?`users.relationship.${i.id}`:"users.relationship.new",steps:C,submitLabel:"Save relationship",pending:p,pendingLabel:"Saving relationship",contentClassName:"lg:w-[min(62rem,calc(100vw-1.5rem))]",onSubmit:async()=>{i&&(await m({grantId:i.id,patch:{accessLevel:v.accessLevel,rights:v.rights},reverseGrantId:(d==null?void 0:d.id)??null,applyToReverse:v.applyScope==="both_arrows"&&d!==null}),n(!1))}})}const U="font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",M="text-sm leading-6 text-[var(--ui-ink-soft)]",te="text-xs leading-5 text-[var(--ui-ink-faint)]",R="rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]";function Ke(){var X;const s=je(),[n,i]=g.useState(null),[u,p]=g.useState(null),[m,d]=g.useState(!1),[v,w]=g.useState(!1),[f,y]=g.useState(""),C=de({queryKey:["forge-user-directory"],queryFn:ke}),a=async()=>{await Promise.all([s.refresh(),C.refetch()])},c=Z({mutationFn:async({input:r,userId:l})=>l?(await we(l,r)).user:(await ye(r)).user,onSuccess:async()=>{i(null),d(!1),await a()}}),h=Z({mutationFn:async({grantId:r,patch:l})=>(await Ne(r,l)).grant,onSuccess:a}),t=(X=C.data)==null?void 0:X.directory,N=(t==null?void 0:t.grants.find(r=>r.id===u))??null,o=g.useMemo(()=>new Map(((t==null?void 0:t.ownership)??[]).map(r=>[r.userId,r])),[t==null?void 0:t.ownership]),x=g.useMemo(()=>new Map(((t==null?void 0:t.xp)??[]).map(r=>[r.userId,r])),[t==null?void 0:t.xp]),k=g.useMemo(()=>{const r=new Map;for(const l of(t==null?void 0:t.grants)??[]){if(!l.targetUser||l.subjectUserId===l.targetUserId)continue;const j=r.get(l.subjectUserId)??[];j.push(l.targetUser),r.set(l.subjectUserId,j)}return r},[t==null?void 0:t.grants]),L=g.useMemo(()=>{const r=((t==null?void 0:t.grants)??[]).filter(l=>l.subjectUserId!==l.targetUserId);return{totalEdges:r.length,fullyOpenEdges:r.filter(l=>Object.values(l.config.rights).every(Boolean)).length,coordinationEdges:r.filter(l=>l.config.rights.canCoordinate).length,executionEdges:r.filter(l=>l.config.rights.canAffectEntities||l.config.rights.canCreateOnBehalf).length}},[t==null?void 0:t.grants]),B=f.trim().toLowerCase(),V=g.useMemo(()=>{const l=((t==null?void 0:t.users)??s.snapshot.users).filter(j=>B?[j.displayName,j.handle,j.kind,j.description].join(" ").toLowerCase().includes(B):!0);return{humans:l.filter(j=>j.kind==="human"),bots:l.filter(j=>j.kind==="bot")}},[t==null?void 0:t.users,B,s.snapshot.users]),le=(N==null?void 0:N.subjectUserId)??(n==null?void 0:n.id)??null,oe=(N==null?void 0:N.id)??null;return e.jsxs("div",{className:"mx-auto grid w-full max-w-[1440px] gap-5",children:[e.jsx(ue,{title:"Users",description:"Forge users can be human or bot. Ownership, search, and routing are prepared so work can move across both sides of the system.",badge:`${s.snapshot.users.length} users`}),e.jsx(he,{}),e.jsx(Fe,{open:m,onOpenChange:d,user:n,grants:(t==null?void 0:t.grants)??[],ownership:n?o.get(n.id)??null:null,xp:n?x.get(n.id)??null:null,pending:c.isPending,onSubmit:async r=>{await c.mutateAsync(r)},onOpenRelationship:r=>{d(!1),p(r),w(!0)}}),e.jsx($e,{open:v,onOpenChange:w,grant:N,grants:(t==null?void 0:t.grants)??[],pending:h.isPending,onSubmit:async r=>{await h.mutateAsync({grantId:r.grantId,patch:r.patch}),r.applyToReverse&&r.reverseGrantId&&await h.mutateAsync({grantId:r.reverseGrantId,patch:r.patch})}}),e.jsxs(F,{className:"grid gap-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:U,children:"Multi-user posture"}),e.jsx("div",{className:`mt-2 ${M}`,children:(t==null?void 0:t.posture.summary)??"Forge is preparing modular user access while keeping the current posture permissive."})]}),e.jsx(b,{tone:"meta",children:(t==null?void 0:t.posture.accessModel)??"permissive"})]}),e.jsx("div",{className:`flex items-center gap-3 ${R} px-4 py-3`,children:e.jsx(T,{value:f,onChange:r=>y(r.target.value),placeholder:"Search human, bot, @handle, or description"})})]}),e.jsxs("div",{className:"grid gap-5",children:[e.jsxs("div",{className:"grid gap-5",children:[e.jsxs(F,{className:"grid gap-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:U,children:"Multi-agent onboarding"}),e.jsx("div",{className:`mt-2 ${M}`,children:"Forge now treats the users graph as the collaboration control plane. Create each human or bot here, keep the runtime shared, then narrow only the specific arrows that should stop seeing, coordinating, planning, or affecting another user."})]}),e.jsx(b,{tone:"meta",children:"default open"})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsxs("div",{className:`${R} px-4 py-3`,children:[e.jsx("div",{className:U,children:"Directional edges"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:L.totalEdges})]}),e.jsxs("div",{className:`${R} px-4 py-3`,children:[e.jsx("div",{className:U,children:"Fully open"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:L.fullyOpenEdges})]}),e.jsxs("div",{className:`${R} px-4 py-3`,children:[e.jsx("div",{className:U,children:"Coordination"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:L.coordinationEdges})]}),e.jsxs("div",{className:`${R} px-4 py-3`,children:[e.jsx("div",{className:U,children:"Execution control"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:L.executionEdges})]})]}),e.jsxs("div",{className:`grid gap-2 ${M}`,children:[e.jsx("div",{children:"1. Create the human and bot users that should exist in the shared Forge system."}),e.jsx("div",{children:"2. Point OpenClaw, Hermes, and the browser at the same Forge runtime and storage root."}),e.jsx("div",{children:"3. Use the graph below to decide what each direction can see, message, plan, or change."}),e.jsx("div",{children:"4. Keep strategy drafting open while the plan is negotiated, then lock the strategy once it becomes the contract."})]})]}),e.jsx(Me,{users:(t==null?void 0:t.users)??s.snapshot.users,grants:(t==null?void 0:t.grants)??[],selectedGrantId:oe,selectedUserId:le,onOpenUser:r=>{const l=((t==null?void 0:t.users)??s.snapshot.users).find(j=>j.id===r)??null;p(null),i(l),d(!0)},onOpenGrant:r=>{i(null),p(r),w(!0)}}),e.jsxs(F,{className:"grid gap-3",children:[e.jsx("div",{className:U,children:"Agent onboarding"}),e.jsx("div",{className:M,children:"OpenClaw, Hermes, and the Forge UI all read this same multi-user graph. Keep the defaults open while you are still wiring collaboration, then narrow specific arrows when one user or agent should stop seeing, messaging, planning, or changing another user's work."}),e.jsx("div",{className:M,children:"Forge now treats every owner as either human or bot, keeps search cross-user by default, and allows cross-owner links plus explicit coordination lanes between projects, tasks, notes, and strategies."}),e.jsx("div",{children:e.jsx(ce,{to:"/settings/agents",className:"inline-flex min-h-10 items-center justify-center rounded-[var(--radius-control)] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-3 py-2 text-[13px] font-medium text-[var(--ui-ink-strong)] transition hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-hover)]",children:"Open agent onboarding"})})]})]}),e.jsx(F,{children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:U,children:"User directory"}),e.jsx("div",{className:`mt-2 ${M}`,children:"Open any user to edit its identity and jump into the exact directional relationship lanes from the user settings flow."})]}),e.jsx(J,{onClick:()=>{p(null),i(null),d(!0)},children:"Create user"})]})}),e.jsx("div",{className:"grid gap-5",children:[{title:"Human users",users:V.humans},{title:"Bot users",users:V.bots}].map(r=>e.jsxs(F,{children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:U,children:r.title}),e.jsx(b,{tone:"meta",children:r.users.length})]}),e.jsx("div",{className:"mt-4 grid gap-3",children:r.users.map(l=>{var j,W,z,K,Q,q;return e.jsx("div",{className:`${R} px-4 py-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(E,{user:l}),e.jsxs("div",{className:"mt-3 text-sm text-[var(--ui-ink-soft)]",children:["@",l.handle]}),e.jsx("div",{className:`mt-2 ${M}`,children:l.description||"No description yet."}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsxs(b,{className:"bg-[var(--primary)]/14 text-[var(--primary)]",children:[((j=x.get(l.id))==null?void 0:j.totalXp)??0," XP"]}),e.jsxs(b,{tone:"meta",children:[((W=x.get(l.id))==null?void 0:W.weeklyXp)??0," weekly"]}),e.jsxs(b,{tone:"meta",children:[((z=x.get(l.id))==null?void 0:z.rewardEventCount)??0," ","rewards"]}),Object.entries(((K=o.get(l.id))==null?void 0:K.entityCounts)??{}).sort((I,D)=>D[1]-I[1]).slice(0,4).map(([I,D])=>e.jsxs(b,{tone:"meta",children:[D," ",I]},`${l.id}-${I}`)),e.jsxs(b,{tone:"meta",children:[((Q=o.get(l.id))==null?void 0:Q.totalOwnedEntities)??0," ","owned"]})]}),e.jsxs("div",{className:`mt-3 ${te}`,children:["Can currently read:"," ",(k.get(l.id)??[]).map(I=>`${I.displayName} (${I.kind})`).join(", ")||"no other users"]}),(q=x.get(l.id))!=null&&q.lastRewardAt?e.jsxs("div",{className:`mt-2 ${te}`,children:["Last XP movement:"," ",new Date(x.get(l.id).lastRewardAt).toLocaleString()]}):null]}),e.jsx("div",{className:"flex gap-2",children:e.jsx(J,{variant:"secondary",onClick:()=>{p(null),i(l),d(!0)},children:"Open settings"})})]})},l.id)})})]},r.title))})]})]})}export{Ke as SettingsUsersPage};
@@ -0,0 +1 @@
1
+ import{r as d,j as e,aC as y,b3 as k,cy as K}from"./vendor-Cpmju3nw.js";import{j as L,i as W,k as l}from"./state-BtwEvpO6.js";import{S as P}from"./settings-section-nav-CkqqtM0F.js";import{P as M}from"./page-hero-DlHEJ0Yt.js";import{L as Q,e as j,B as c,C as N,a4 as $,I as S,bk as A,bl as F,bm as R,bn as q}from"./index-BejvcRGb.js";import"./motion-DwjmC9aq.js";import"./ui-B9O-eUim.js";import"./board-CLOHbg6t.js";import"./forms-C5d5hTf2.js";const C="inline-flex min-h-11 max-w-full items-center justify-center rounded-[16px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-3 text-sm font-medium text-[var(--ui-ink-strong)] shadow-[var(--ui-shadow-soft)] transition hover:bg-[var(--ui-surface-hover)]",I="grid min-w-0 gap-3 rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",E="grid min-w-0 gap-1 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-4",O="min-w-0 rounded-[16px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-3 py-3 text-sm text-[var(--ui-ink-strong)] outline-none transition focus:border-[var(--primary)]/35 focus:bg-[var(--ui-surface-3)]",p="text-[var(--ui-ink-strong)]",T="text-[var(--ui-ink-soft)]",n="text-[var(--ui-ink-faint)]";function Z(){var w;const t=L(),[r,g]=d.useState(""),[m,u]=d.useState(""),[x,h]=d.useState("personal"),s=W({queryKey:["forge-wiki-settings"],queryFn:q}),o=async()=>{await Promise.all([t.invalidateQueries({queryKey:["forge-wiki-settings"]}),t.invalidateQueries({queryKey:["forge-wiki-pages"]}),t.invalidateQueries({queryKey:["forge-wiki-page"]}),t.invalidateQueries({queryKey:["forge-wiki-search"]})])},v=l({mutationFn:()=>R({label:r.trim(),description:m.trim(),visibility:x}),onSuccess:async()=>{g(""),u(""),h("personal"),await o()}}),b=l({mutationFn:()=>A(),onSuccess:o}),f=l({mutationFn:()=>F(),onSuccess:o});if(s.isLoading)return e.jsx(Q,{eyebrow:"KarpaWiki settings",title:"Loading KarpaWiki controls",description:"Fetching spaces and profile configuration for KarpaWiki."});if(s.isError)return e.jsx(j,{eyebrow:"KarpaWiki settings",error:s.error,onRetry:()=>void s.refetch()});const a=(w=s.data)==null?void 0:w.settings;return a?e.jsxs("div",{className:"mx-auto grid w-full max-w-[1440px] gap-5",children:[e.jsx(M,{eyebrow:"SQLite memory",title:"KarpaWiki Settings",titleText:"KarpaWiki Settings",description:"Manage SQLite-backed spaces and refresh KarpaWiki indexes. Model, OAuth, and embedding profile setup lives in Models.",badge:`${a.spaces.length} spaces · ${a.embeddingProfiles.length} embedding profiles`,actions:e.jsxs(e.Fragment,{children:[e.jsxs(y,{to:"/settings/models",className:C,children:["Open model settings",e.jsx(k,{className:"ml-2 size-4"})]}),e.jsx(c,{variant:"secondary",pending:b.isPending,pendingLabel:"Syncing",onClick:()=>void b.mutateAsync(),children:"Refresh indexes"}),e.jsx(c,{pending:f.isPending,pendingLabel:"Reindexing",onClick:()=>void f.mutateAsync(),disabled:a.embeddingProfiles.length===0,children:"Reindex embeddings"})]})}),e.jsx(P,{}),e.jsxs("div",{className:"grid gap-5",children:[e.jsxs(N,{className:"grid gap-4",children:[e.jsx("div",{className:"flex items-center gap-3",children:e.jsxs("div",{children:[e.jsx("div",{className:`text-sm ${p}`,children:"Model configuration moved"}),e.jsx("div",{className:`text-xs leading-5 ${n}`,children:"KarpaWiki ingest uses the OpenAI Codex OAuth connection selected in Models. OpenAI Platform API keys and embedding profile setup are not configured from this page."})]})}),e.jsxs(y,{to:"/settings/models",className:`${C} w-fit`,children:["Manage KarpaWiki models and embeddings",e.jsx(k,{className:"ml-2 size-4"})]})]}),e.jsx("div",{className:"grid gap-5",children:e.jsxs(N,{className:"grid gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(K,{className:"size-4 text-[var(--secondary)]"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:`text-sm ${p}`,children:"Spaces"}),e.jsx($,{content:"Canonical knowledge lives in SQLite notes, with Forge maintaining metadata, links, search, and optional embedding indexes in the database. Text search and entity-linked search work without embeddings, while semantic search stays additive and profile-driven. Ingest jobs can create pages and media assets now, with room for richer OCR, transcription, and multimodal compilation later.",label:"Explain the wiki operating model"})]}),e.jsx("div",{className:`text-xs leading-5 ${n}`,children:"Personal and shared wiki spaces map to explicit SQLite namespaces."})]})]}),e.jsx("div",{className:"grid gap-3",children:a.spaces.map(i=>e.jsxs("div",{className:E,children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center justify-between gap-3",children:[e.jsx("div",{className:`min-w-0 break-words [overflow-wrap:anywhere] ${p}`,children:i.label}),e.jsx("div",{className:`text-xs uppercase tracking-[0.16em] ${n}`,children:i.visibility})]}),e.jsx("div",{className:`break-words text-xs [overflow-wrap:anywhere] ${n}`,children:i.slug}),e.jsx("div",{className:`text-sm ${T}`,children:i.description||"No description yet."})]},i.id))}),e.jsxs("div",{className:I,children:[e.jsx(S,{value:r,onChange:i=>g(i.target.value),placeholder:"New space label"}),e.jsx(S,{value:m,onChange:i=>u(i.target.value),placeholder:"Description"}),e.jsxs("select",{className:O,value:x,onChange:i=>h(i.target.value),children:[e.jsx("option",{value:"personal",children:"Personal"}),e.jsx("option",{value:"shared",children:"Shared"})]}),e.jsx(c,{pending:v.isPending,pendingLabel:"Creating",disabled:!r.trim(),onClick:()=>void v.mutateAsync(),children:"Create space"})]})]})})]})]}):e.jsx(j,{eyebrow:"KarpaWiki settings",error:new Error("Forge returned an empty KarpaWiki settings payload."),onRetry:()=>void s.refetch()})}export{Z as SettingsWikiPage};
@@ -0,0 +1 @@
1
+ import{r as g,j as e,aV as re,ck as ae,cm as te}from"./vendor-Cpmju3nw.js";import{j as se,i as _,k as ie}from"./state-BtwEvpO6.js";import{E as ne}from"./entity-link-multiselect-wuyJ8BbW.js";import{d as de,S as le,e as ce,bs as oe,C as w,k as v,c as b,B as $,I as Q,T as ue,d$ as me,bd as xe,e0 as ve,b3 as pe,b4 as ge,b5 as he,b6 as fe,b9 as be}from"./index-BejvcRGb.js";import{P as je}from"./page-hero-DlHEJ0Yt.js";import{S as ye,a as ke,b as Ne}from"./health-boxes-BUcsxDLh.js";import{b as we,p as Se}from"./health-link-options-Cpx8w7uM.js";import"./use-anchored-overlay-position-BrQ4cqKn.js";import"./motion-DwjmC9aq.js";import"./ui-B9O-eUim.js";import"./board-CLOHbg6t.js";import"./forms-C5d5hTf2.js";import"./generic-node-view-COhU_Wm3.js";import"./graph-Cd5WF3lw.js";import"./define-workbench-box-DkffygDU.js";const _e=["Mon","Tue","Wed","Thu","Fri","Sat","Sun"],W={awake:{label:"Awake",strong:"var(--warning)",soft:"var(--ui-warning-soft)",text:"text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]"},core:{label:"Core",strong:"var(--primary)",soft:"var(--ui-accent-soft)",text:"text-[color-mix(in_srgb,var(--primary)_78%,var(--ui-ink-strong)_22%)]"},deep:{label:"Deep",strong:"var(--success)",soft:"var(--ui-success-soft)",text:"text-[color-mix(in_srgb,var(--success)_78%,var(--ui-ink-strong)_22%)]"},rem:{label:"REM",strong:"var(--info)",soft:"var(--ui-info-soft)",text:"text-[color-mix(in_srgb,var(--info)_78%,var(--ui-ink-strong)_22%)]"},in_bed:{label:"In bed",strong:"color-mix(in_srgb,var(--ui-ink-strong)_46%,transparent)",soft:"var(--ui-surface-3)",text:"text-[var(--ui-ink-medium)]"},asleep_unspecified:{label:"Asleep",strong:"var(--primary)",soft:"var(--ui-accent-soft)",text:"text-[color-mix(in_srgb,var(--primary)_78%,var(--ui-ink-strong)_22%)]"}};function I(r){return W[r]??W.asleep_unspecified}function p(r){if(r<=0)return"0m";const a=Math.floor(r/3600),t=Math.round(r%3600/60);return a===0?`${t}m`:t===0?`${a}h`:`${a}h ${t}m`}function Ae(r){const a=Math.round(r/60);return a===0?"on baseline":`${a>0?"+":"-"}${Math.abs(a)}m`}function T(r){return`${Math.round(r*100)}%`}function A(r,a){return r?new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit",timeZone:a}).format(new Date(r)):"n/a"}function O(r,a){return new Intl.DateTimeFormat(void 0,{weekday:"long",day:"numeric",month:"long",timeZone:a}).format(new Date(r))}function q(r,a,t){return`${A(r,t)} - ${A(a,t)}`}function Te(r){const[a,t]=r.split("-").map(Number);return new Intl.DateTimeFormat(void 0,{month:"long",year:"numeric"}).format(new Date(a,(t??1)-1,1))}function U(r){const a=new Date(r),t=(r.getDay()+6)%7;return a.setDate(r.getDate()-t),a}function Re(r){const a=U(r);return a.setDate(a.getDate()+6),a}function Me(r){const a=r.getFullYear(),t=`${r.getMonth()+1}`.padStart(2,"0"),s=`${r.getDate()}`.padStart(2,"0");return`${a}-${t}-${s}`}function B(r){return{qualitySummary:typeof r.annotations.qualitySummary=="string"?r.annotations.qualitySummary:"",notes:typeof r.annotations.notes=="string"?r.annotations.notes:"",tagsText:Array.isArray(r.annotations.tags)?r.annotations.tags.join(", "):"",linkValues:Array.isArray(r.links)?r.links.map(a=>`${a.entityType}:${a.entityId}`):[]}}function De(r,a){if(!r)return[];const[t,s]=r.split("-").map(Number),n=new Date(t,(s??1)-1,1),u=new Date(t,s??1,0),d=U(n),x=Re(u),l=new Map(a.map(c=>[c.dateKey,c])),i=[];for(const c=new Date(d);c<=x;c.setDate(c.getDate()+1)){const y=Me(c);i.push({dateKey:y,dayNumber:c.getDate(),outsideMonth:c.getMonth()!==n.getMonth(),sleep:l.get(y)??null})}return i}function Ie(r){return r>0?"text-[color-mix(in_srgb,var(--success)_78%,var(--ui-ink-strong)_22%)]":r<0?"text-[color-mix(in_srgb,var(--danger)_78%,var(--ui-ink-strong)_22%)]":"text-[var(--ui-ink-medium)]"}function J(r){return r==="recharged"||r==="recovered"?"bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_78%,var(--ui-ink-strong)_22%)]":r==="steady"||r==="stable"?"bg-[var(--ui-info-soft)] text-[color-mix(in_srgb,var(--info)_78%,var(--ui-ink-strong)_22%)]":r==="fragile"||r==="strained"?"bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]":r==="depleted"?"bg-[var(--ui-danger-soft)] text-[color-mix(in_srgb,var(--danger)_78%,var(--ui-ink-strong)_22%)]":"bg-[var(--ui-surface-3)] text-[var(--ui-ink-medium)]"}function Be(r){return r==="provider_raw"?"bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_78%,var(--ui-ink-strong)_22%)]":r==="historical_raw"?"bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]":"bg-[var(--ui-surface-3)] text-[var(--ui-ink-medium)]"}function qe(r){return r==="provider_raw"?"Provider raw data":r==="historical_raw"?"Historical raw data":"Raw data unavailable"}function $e(r){return r.qualityKind==="provider_native"?"bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_78%,var(--ui-ink-strong)_22%)]":"bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]"}function Ce(r,a){const t=r.stage;if(typeof t=="string"&&t.trim().length>0)return t;const s=r.sourceType;if(typeof s=="string"&&s.trim().length>0)return s;const n=r.stageBreakdown;if(Array.isArray(n)&&n.length>0){const u=n[0];if(u&&typeof u=="object"&&typeof u.stage=="string")return(u.stage||"asleep_unspecified").trim()}return a.includes("awake")?"awake":"asleep_unspecified"}function Ke(r){const a=r,t=(a==null?void 0:a.segments)??(a==null?void 0:a.rawSegments)??[],s=(a==null?void 0:a.auditLogs)??(a==null?void 0:a.rawLogs)??[],n=a!=null&&a.sourceRecords&&a.sourceRecords.length>0?a.sourceRecords:s.filter(d=>typeof d.startedAt=="string"&&typeof d.endedAt=="string").map(d=>({id:d.id,importRunId:d.importRunId,pairingSessionId:d.pairingSessionId,sleepSessionId:d.sleepSessionId,userId:d.userId,provider:d.source,providerRecordType:d.logType,providerRecordUid:d.externalUid??d.id,sourceDevice:"",sourceTimezone:d.sourceTimezone,localDateKey:d.localDateKey,startedAt:d.startedAt,endedAt:d.endedAt,rawStage:Ce(d.payload,d.logType),rawValue:null,qualityKind:"historical_import",payload:d.payload,metadata:d.metadata,ingestedAt:d.createdAt})),u=(a==null?void 0:a.rawDataStatus)??(n.length>0?"historical_raw":"raw_unavailable");return{sourceRecords:n,segments:t,auditLogs:s,rawDataStatus:u}}function G({stages:r}){const a=r.reduce((t,s)=>t+s.seconds,0);return r.length===0||a===0?e.jsx("div",{className:"rounded-[18px] border border-dashed border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4 text-sm text-[var(--ui-ink-muted)]",children:"No stage composition was stored for this night yet."}):e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:"flex h-3 overflow-hidden rounded-full bg-[var(--ui-surface-2)]",children:r.map(t=>{const s=I(t.stage);return e.jsx("div",{className:"h-full",style:{width:`${Math.max(4,t.seconds/a*100)}%`,background:s.strong},title:`${s.label} · ${p(t.seconds)}`},t.stage)})}),e.jsx("div",{className:"grid gap-2 sm:grid-cols-2 xl:grid-cols-4",children:r.map(t=>{const s=I(t.stage),n="percentage"in t&&typeof t.percentage=="number"?t.percentage:a>0?t.seconds/a:0;return e.jsxs("div",{className:"rounded-[16px] border border-[var(--ui-border-subtle)] px-3 py-3",style:{background:s.soft},children:[e.jsx("div",{className:b("text-sm font-medium",s.text),children:s.label}),e.jsx("div",{className:"mt-1 text-lg text-[var(--ui-ink-strong)]",children:p(t.seconds)}),e.jsx("div",{className:"text-xs text-[var(--ui-ink-muted)]",children:T(n)})]},t.stage)})})]})}function H({blocks:r,selectedBlockId:a,onSelect:t}){return e.jsxs("div",{className:"relative h-12 overflow-hidden rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",children:[e.jsx("div",{className:"pointer-events-none absolute inset-0 bg-[image:var(--ui-surface-section)] bg-[length:25%_100%]"}),r.map(s=>{const n=I(s.stage),u=a===s.id;return e.jsx("button",{type:"button",onClick:()=>t(s.id),className:b("absolute inset-y-[5px] rounded-[12px] border transition",u?"border-[var(--ui-border-strong)] shadow-[var(--ui-shadow-soft)]":"border-[var(--ui-border-subtle)]"),style:{left:`${s.offsetRatio*100}%`,width:`${Math.max(s.widthRatio*100,1.8)}%`,background:n.strong},title:`${s.label} · ${p(s.durationSeconds)} · ${s.startedAt} - ${s.endedAt}`,children:s.widthRatio>.13?e.jsx("span",{className:"truncate px-2 text-[10px] font-medium text-[var(--ui-ink-on-accent)]",children:s.label}):null},s.id)})]})}function Ee({timeline:r,timeZone:a}){var l,i;const t=r.blocks.filter(c=>c.lane==="in_bed"),s=r.blocks.filter(c=>c.lane==="sleep"),n=((l=s[0])==null?void 0:l.id)??((i=t[0])==null?void 0:i.id)??null,[u,d]=g.useState(n);g.useEffect(()=>{d(n)},[n,r.startedAt,r.endedAt,r.totalSeconds]);const x=r.blocks.find(c=>c.id===u)??null;return r.hasRawSegments?e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"grid gap-3",children:[t.length>0?e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"In bed window"}),e.jsx(H,{blocks:t,selectedBlockId:u,onSelect:d})]}):null,e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:r.hasSleepStageData?"Sleep phases":"Recorded sleep coverage"}),e.jsx(H,{blocks:s.length>0?s:t,selectedBlockId:u,onSelect:d})]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 text-xs text-[var(--ui-ink-muted)]",children:[e.jsx("span",{children:A(r.startedAt,a)}),e.jsx("span",{children:p(r.totalSeconds)}),e.jsx("span",{children:A(r.endedAt,a)})]}),x?e.jsx("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:b("text-sm font-medium",I(x.stage).text),children:x.label}),e.jsxs("div",{className:"mt-1 text-sm text-[var(--ui-ink-muted)]",children:[A(x.startedAt,a)," -"," ",A(x.endedAt,a)]})]}),e.jsx(v,{tone:"meta",children:p(x.durationSeconds)})]})}):null]}):e.jsx("div",{className:"rounded-[18px] border border-dashed border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-5 text-sm text-[var(--ui-ink-muted)]",children:"Phase timing is unavailable for this night. Forge still keeps the canonical overnight summary, but the companion did not store segment-level timing."})}function Fe({latestNight:r}){return r?e.jsx(w,{className:"overflow-hidden border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-0",children:e.jsxs("div",{className:"relative overflow-hidden px-6 py-6 sm:px-7 sm:py-7",children:[e.jsx("div",{className:"pointer-events-none absolute inset-0 bg-[image:var(--ui-surface-section)]"}),e.jsxs("div",{className:"relative grid gap-6 xl:grid-cols-[minmax(0,1.2fr)_minmax(0,0.8fr)]",children:[e.jsxs("div",{className:"grid gap-5",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx(v,{className:b("border-transparent",J(r.recoveryState)),children:r.qualitativeState}),e.jsx(v,{tone:"meta",children:r.sourceTimezone}),r.hasReflection?e.jsx(v,{tone:"meta",children:"Has reflection"}):null,r.hasRawSegments?e.jsxs(v,{tone:"meta",children:[r.rawSegmentCount," raw segments"]}):null]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Last night"}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-end gap-x-4 gap-y-2",children:[e.jsx("div",{className:"text-[clamp(2.5rem,6vw,5rem)] font-medium leading-none text-[var(--ui-ink-strong)]",children:p(r.asleepSeconds)}),e.jsxs("div",{className:"pb-2 text-sm text-[var(--ui-ink-muted)]",children:["asleep across ",q(r.startedAt,r.endedAt,r.sourceTimezone)]})]}),e.jsx("div",{className:"mt-3 text-sm text-[var(--ui-ink-medium)]",children:O(r.endedAt,r.sourceTimezone)}),r.qualitySummary?e.jsx("div",{className:"mt-4 max-w-2xl text-sm leading-6 text-[var(--ui-ink-medium)]",children:r.qualitySummary}):e.jsx("div",{className:"mt-4 max-w-2xl text-sm leading-6 text-[var(--ui-ink-muted)]",children:"Canonical overnight summary computed from synced sleep segments, with raw evidence still available underneath."})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"In bed"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:p(r.timeInBedSeconds)})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Score"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:r.score??"n/a"})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Regularity"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:r.regularity??"n/a"})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Efficiency"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:T(r.efficiency)})]})]})]}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-5 py-5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Baseline"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:"Compared with recent nights"})]}),e.jsx(ae,{className:"size-5 text-[var(--primary)]"})]}),e.jsxs("div",{className:"mt-4 grid gap-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[16px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-medium)]",children:"7-night average"}),e.jsx("span",{className:"text-sm text-[var(--ui-ink-strong)]",children:p(r.weeklyAverageSleepSeconds)})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[16px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-medium)]",children:"Versus baseline"}),e.jsx("span",{className:b("text-sm",Ie(r.deltaFromWeeklyAverageSeconds)),children:Ae(r.deltaFromWeeklyAverageSeconds)})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[16px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-medium)]",children:"Bedtime drift"}),e.jsxs("span",{className:"text-sm text-[var(--ui-ink-strong)]",children:[r.bedtimeDriftMinutes??0,"m"]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[16px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-medium)]",children:"Wake drift"}),e.jsxs("span",{className:"text-sm text-[var(--ui-ink-strong)]",children:[r.wakeDriftMinutes??0,"m"]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[16px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-medium)]",children:"Restorative share"}),e.jsx("span",{className:"text-sm text-[var(--ui-ink-strong)]",children:T(r.restorativeShare)})]})]})]}),e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-5 py-5",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Stage composition"}),e.jsx("div",{className:"mt-4",children:e.jsx(G,{stages:r.stageBreakdown})})]})]})]})]})}):e.jsxs(w,{className:"overflow-hidden p-6",children:[e.jsx("div",{className:"text-sm uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Sleep"}),e.jsx("div",{className:"mt-4 text-2xl text-[var(--ui-ink-strong)]",children:"No overnight sleep yet"}),e.jsx("div",{className:"mt-3 max-w-2xl text-sm leading-6 text-[var(--ui-ink-muted)]",children:"The sleep page will switch to a night-first summary once the companion syncs a canonical overnight session."})]})}function F({title:r,value:a,description:t}){return e.jsxs(w,{className:"h-full border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:r}),e.jsx("div",{className:"mt-3 text-3xl text-[var(--ui-ink-strong)]",children:a}),e.jsx("div",{className:"mt-3 text-sm leading-6 text-[var(--ui-ink-muted)]",children:t})]})}function ze({days:r,selectedSleepId:a,onSelect:t}){const s=g.useMemo(()=>Array.from(new Set(r.map(l=>l.dateKey.slice(0,7)))).sort((l,i)=>l.localeCompare(i)),[r]),[n,u]=g.useState(s[s.length-1]??"");g.useEffect(()=>{if(s.length===0){u("");return}s.includes(n)||u(s[s.length-1]??"")},[n,s]);const d=s.indexOf(n),x=g.useMemo(()=>De(n,r),[r,n]);return n?e.jsx(w,{className:"overflow-hidden border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-0",children:e.jsxs("div",{className:"grid gap-5 px-5 py-5",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Sleep calendar"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:Te(n)})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($,{type:"button",variant:"secondary",className:"h-9 rounded-full",disabled:d<=0,onClick:()=>u(s[Math.max(0,d-1)]??n),children:"Previous"}),e.jsx($,{type:"button",variant:"secondary",className:"h-9 rounded-full",disabled:d===-1||d>=s.length-1,onClick:()=>u(s[Math.min(s.length-1,d+1)]??n),children:"Next"})]})]}),e.jsx("div",{className:"grid grid-cols-7 gap-2 text-center text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-muted)]",children:_e.map(l=>e.jsx("div",{children:l},l))}),e.jsx("div",{className:"grid grid-cols-7 gap-2",children:x.map(l=>{const i=l.sleep,c=(i==null?void 0:i.sleepId)===a,y=i&&typeof i.score=="number"?i.score>=80?"var(--ui-success-soft)":i.score>=65?"var(--ui-info-soft)":"var(--ui-warning-soft)":"var(--ui-surface-2)";return e.jsxs("button",{type:"button",disabled:!i,"aria-pressed":c,"aria-label":`Select sleep for ${l.dateKey}`,onClick:()=>{i&&(u(i.dateKey.slice(0,7)),t(i.sleepId,i.dateKey.slice(0,7)))},className:b("min-h-[90px] rounded-[18px] border px-2 py-2 text-left transition",i?"border-[var(--ui-border-subtle)] hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-3)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",c&&"border-[var(--primary)] bg-[var(--primary)]/12",l.outsideMonth&&!i&&"opacity-35"),style:i?{background:y}:void 0,children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsx("span",{className:b("text-sm",l.outsideMonth?"text-[var(--ui-ink-muted)]":"text-[var(--ui-ink-medium)]"),children:l.dayNumber}),i!=null&&i.hasReflection?e.jsx("span",{className:"size-2 rounded-full bg-[var(--success)]"}):null]}),i?e.jsxs("div",{className:"mt-4 grid gap-1",children:[e.jsxs("div",{className:"text-lg text-[var(--ui-ink-strong)]",children:[i.sleepHours.toFixed(1),"h"]}),e.jsxs("div",{className:"text-xs text-[var(--ui-ink-muted)]",children:[i.score??"n/a"," score"]}),e.jsx("div",{className:"text-xs text-[var(--ui-ink-muted)]",children:i.hasRawSegments?"phases available":"summary only"})]}):null]},l.dateKey)})})]})}):e.jsx(w,{className:"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-5 py-8 text-sm leading-6 text-[var(--ui-ink-muted)]",children:"No canonical nights are available for the calendar yet."})}function z({active:r,children:a,onClick:t}){return e.jsx("button",{type:"button",onClick:t,className:b("rounded-full border px-4 py-2 text-sm transition",r?"border-[var(--primary)] bg-[var(--primary)]/12 text-[var(--ui-ink-strong)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)] hover:text-[var(--ui-ink-strong)]"),children:a})}function Le({session:r,draft:a,rawDetail:t,rawDetailLoading:s,pending:n,tab:u,linkOptions:d,onTabChange:x,onDraftChange:l,onSave:i}){const[c,y]=g.useState(null),k=g.useMemo(()=>Ke(t),[t]),C=typeof r.derived.efficiency=="number"?r.derived.efficiency:r.timeInBedSeconds>0?r.asleepSeconds/r.timeInBedSeconds:0,K=typeof r.derived.restorativeShare=="number"?r.derived.restorativeShare:0,R=typeof r.derived.recoveryState=="string"?r.derived.recoveryState:null;return e.jsx(w,{className:"overflow-hidden border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-0",children:e.jsxs("div",{className:"grid gap-5 px-5 py-5",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(v,{className:b("border-transparent",J(R)),children:R?R.replaceAll("_"," "):"Canonical night"}),e.jsxs(v,{tone:"meta",children:[r.rawSegmentCount," raw segments"]}),e.jsx(v,{tone:"meta",children:r.sourceTimezone})]}),e.jsx("div",{className:"mt-3 text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Selected night"}),e.jsx("div",{className:"mt-2 text-2xl text-[var(--ui-ink-strong)]",children:O(r.endedAt,r.sourceTimezone)}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:q(r.startedAt,r.endedAt,r.sourceTimezone)})]}),e.jsxs("div",{className:"grid gap-2 text-right",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Summary"}),e.jsx("div",{className:"text-3xl text-[var(--ui-ink-strong)]",children:p(r.asleepSeconds)}),e.jsx("div",{className:"text-sm text-[var(--ui-ink-muted)]",children:"asleep"})]})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"In bed"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:p(r.timeInBedSeconds)})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Awake"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:p(r.awakeSeconds)})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Efficiency"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:T(C)})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Restorative"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:T(K)})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(z,{active:u==="summary",onClick:()=>x("summary"),children:"Summary"}),e.jsx(z,{active:u==="reflection",onClick:()=>x("reflection"),children:"Reflection"}),e.jsx(z,{active:u==="raw",onClick:()=>x("raw"),children:"Show raw data"})]}),u==="summary"?e.jsxs("div",{className:"grid gap-5",children:[e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Phase timeline"}),e.jsx("div",{className:"mt-4",children:s?e.jsx("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-6 text-sm text-[var(--ui-ink-muted)]",children:"Loading phase timing from raw sleep segments…"}):e.jsx(Ee,{timeline:(t==null?void 0:t.phaseTimeline)??{startedAt:r.startedAt,endedAt:r.endedAt,totalSeconds:Math.max(0,Math.round((new Date(r.endedAt).getTime()-new Date(r.startedAt).getTime())/1e3)),hasRawSegments:!1,hasSleepStageData:!1,blocks:[]},timeZone:r.sourceTimezone})})]}),e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Stage composition"}),e.jsx("div",{className:"mt-4",children:e.jsx(G,{stages:r.stageBreakdown})})]})]}):null,u==="reflection"?e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-muted)]",children:"Quality summary"}),e.jsx(Q,{value:a.qualitySummary,onChange:o=>l({qualitySummary:o.target.value}),placeholder:"Recovered after a late evening, but sleep onset drifted."})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-muted)]",children:"Night notes"}),e.jsx(ue,{className:"min-h-[200px]",value:a.notes,onChange:o=>l({notes:o.target.value}),placeholder:"What shaped this night, and what should we remember about it?"})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-muted)]",children:"Tags"}),e.jsx(Q,{value:a.tagsText,onChange:o=>l({tagsText:o.target.value}),placeholder:"travel, stress, good-routine, late-caffeine"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-muted)]",children:"Linked context"}),e.jsx(ne,{options:d,selectedValues:a.linkValues,onChange:o=>l({linkValues:o}),placeholder:"Search goals, tasks, habits, beliefs, reports, or patterns…"})]}),e.jsx("div",{className:"flex justify-end",children:e.jsxs($,{type:"button",pending:n,pendingLabel:"Saving",onClick:i,children:[e.jsx(te,{className:"size-4"}),"Save reflection"]})})]}):null,u==="raw"?e.jsxs("div",{className:"grid gap-5",children:[e.jsx("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4 text-sm leading-6 text-[var(--ui-ink-muted)]",children:"Forge shows the canonical overnight session by default. This view reveals the evidence stack underneath it: raw provider or historical imported records first, then Forge-normalized sleep segments."}),s?e.jsx("div",{className:"text-sm text-[var(--ui-ink-muted)]",children:"Loading raw sleep evidence…"}):null,s?null:e.jsxs("div",{className:"grid gap-5",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(v,{className:b("border-transparent",Be(k.rawDataStatus)),children:qe(k.rawDataStatus)}),k.rawDataStatus==="historical_raw"?e.jsx(v,{tone:"meta",children:"Partial evidence"}):null]}),e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Raw data"}),k.sourceRecords.length?k.sourceRecords.map(o=>e.jsxs("div",{className:"rounded-[16px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(v,{className:b("border-transparent",$e(o)),children:o.qualityKind==="provider_native"?"Provider raw":"Historical raw"}),e.jsx(v,{tone:"meta",className:"capitalize",children:o.rawStage.replaceAll("_"," ")}),e.jsx("span",{className:"text-sm text-[var(--ui-ink-medium)]",children:q(o.startedAt,o.endedAt,o.sourceTimezone)})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-[var(--ui-ink-muted)]",children:o.providerRecordType.replaceAll("_"," ")}),e.jsx($,{type:"button",variant:"secondary",className:"h-8 rounded-full px-3",onClick:()=>y(M=>M===o.id?null:o.id),children:c===o.id?"Hide JSON":"See JSON"})]})]}),e.jsx("div",{className:"mt-3 text-sm text-[var(--ui-ink-muted)]",children:p(Math.max(0,Math.round((new Date(o.endedAt).getTime()-new Date(o.startedAt).getTime())/1e3)))}),c===o.id?e.jsx("pre",{className:"mt-3 overflow-x-auto rounded-[14px] border border-[var(--ui-border-subtle)] bg-[var(--ui-code-bg)] p-3 text-xs leading-6 text-[var(--ui-ink-medium)]",children:JSON.stringify({payload:o.payload,metadata:o.metadata},null,2)}):null]},o.id)):e.jsx("div",{className:"rounded-[16px] border border-dashed border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4 text-sm text-[var(--ui-ink-muted)]",children:"No raw data was stored for this night."})]}),e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Sleep segments"}),k.segments.length?k.segments.map(o=>e.jsx("div",{className:"rounded-[16px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-3",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(v,{tone:"meta",className:"capitalize",children:o.stage.replaceAll("_"," ")}),e.jsx(v,{tone:"meta",children:o.qualityKind==="provider_native"?"provider-backed":"historical"}),e.jsx("span",{className:"text-sm text-[var(--ui-ink-medium)]",children:q(o.startedAt,o.endedAt,o.sourceTimezone)})]}),e.jsx("span",{className:"text-sm text-[var(--ui-ink-muted)]",children:p(Math.max(0,Math.round((new Date(o.endedAt).getTime()-new Date(o.startedAt).getTime())/1e3)))})]})},o.id)):e.jsx("div",{className:"rounded-[16px] border border-dashed border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4 text-sm text-[var(--ui-ink-muted)]",children:"No normalized sleep segments were stored for this night."})]})]})]}):null]})})}function tr(){var V;const r=de(),a=se(),[t,s]=g.useState({}),[n,u]=g.useState(null),[d,x]=g.useState("summary"),l=Array.isArray(r==null?void 0:r.selectedUserIds)?r.selectedUserIds:[],i=r==null?void 0:r.snapshot,c=_({queryKey:["forge-sleep",...l],queryFn:async()=>(await xe(l)).sleep}),y=_({queryKey:["forge-sleep-raw",n],enabled:!!n,queryFn:async()=>ve(n)}),k=_({queryKey:["forge-sleep-values",...l],queryFn:async()=>(await pe(l)).values}),C=_({queryKey:["forge-sleep-patterns",...l],queryFn:async()=>(await ge(l)).patterns}),K=_({queryKey:["forge-sleep-behaviors",...l],queryFn:async()=>(await he(l)).behaviors}),R=_({queryKey:["forge-sleep-beliefs",...l],queryFn:async()=>(await fe(l)).beliefs}),o=_({queryKey:["forge-sleep-reports",...l],queryFn:async()=>(await be(l)).reports});g.useEffect(()=>{c.data&&s(Object.fromEntries(c.data.sessions.map(m=>[m.id,B(m)])))},[c.data]),g.useEffect(()=>{var N,j,S;if(!((N=c.data)!=null&&N.sessions.length)){u(null);return}c.data.sessions.some(E=>E.id===n)||u(((j=c.data.latestNight)==null?void 0:j.sleepId)??((S=c.data.sessions[0])==null?void 0:S.id)??null)},[n,c.data]),g.useEffect(()=>{x("summary")},[n]);const M=ie({mutationFn:async m=>me(m.sleepId,{qualitySummary:m.qualitySummary,notes:m.notes,tags:m.tagsText.split(",").map(N=>N.trim()).filter(Boolean),links:Se(m.linkValues)}),onSuccess:async()=>{await a.invalidateQueries({queryKey:["forge-sleep"]}),await a.invalidateQueries({queryKey:["forge-sleep-raw"]})}});if(c.isLoading)return e.jsx(le,{eyebrow:"Sleep",title:"Loading sleep surface",description:"Reading canonical nights, calendar summaries, and sleep phase detail.",columns:2,blocks:6});if(c.isError||!c.data)return e.jsx(ce,{eyebrow:"Sleep",error:c.error??new Error("Sleep data unavailable"),onRetry:()=>void c.refetch()});const h=c.data,D=h.sessions,L=new Map(D.map(m=>[m.id,m])),f=(n?L.get(n):null)??(h.latestNight?L.get(h.latestNight.sleepId):null)??D[0]??null,P=f?t[f.id]??B(f):null,Y=we({goals:(i==null?void 0:i.dashboard.goals)??[],projects:(i==null?void 0:i.dashboard.projects)??[],tasks:(i==null?void 0:i.dashboard.tasks)??[],habits:(i==null?void 0:i.dashboard.habits)??[],values:k.data??[],patterns:C.data??[],behaviors:K.data??[],beliefs:R.data??[],reports:o.data??[]});function X(m,N){s(j=>{const S=D.find(ee=>ee.id===m),E=j[m]??(S?B(S):{qualitySummary:"",notes:"",tagsText:"",linkValues:[]});return{...j,[m]:{...E,...N}}})}async function Z(m){const N=D.find(S=>S.id===m);if(!N)return;const j=t[m]??B(N);await M.mutateAsync({sleepId:m,qualitySummary:j.qualitySummary,notes:j.notes,tagsText:j.tagsText,linkValues:j.linkValues})}return e.jsxs("div",{className:"grid gap-5",children:[e.jsx(je,{eyebrow:"Health",title:"Sleep",description:"Canonical overnight sessions first, with last-night recovery, a clickable night calendar, and raw segment evidence only when you ask for it.",badge:`${D.length} nights`}),e.jsx(oe,{}),e.jsx(ye,{children:e.jsx(Fe,{latestNight:h.latestNight})}),e.jsx(ke,{children:e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,0.95fr)_minmax(0,1.05fr)]",children:[e.jsx(F,{title:"Weekly average",value:p(h.summary.averageSleepSeconds),description:"Average overnight sleep duration across the recent week, used as the baseline for the latest-night comparison."}),e.jsx(F,{title:"Regularity",value:`${h.summary.averageRegularityScore}`,description:`Average bedtime drift ${h.summary.averageBedtimeConsistencyMinutes}m and wake drift ${h.summary.averageWakeConsistencyMinutes}m.`}),e.jsx(F,{title:"Restorative share",value:T(h.summary.averageRestorativeShare),description:`Deep + REM share across recent nights, with ${h.summary.reflectiveNightCount} nights already carrying context.`}),e.jsxs(w,{className:"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Recent stage mix"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:"Average nightly phases"})]}),e.jsx(re,{className:"size-5 text-[var(--primary)]"})]}),e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:h.stageAverages.length>0?h.stageAverages.slice(0,5).map(m=>e.jsxs(v,{tone:"meta",children:[I(m.stage).label," ",p(m.averageSeconds)]},m.stage)):e.jsx("div",{className:"text-sm text-[var(--ui-ink-muted)]",children:"Stage averages will appear once nights include phase data."})})]})]})}),e.jsx(Ne,{children:e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,25rem)_minmax(0,1fr)]",children:[e.jsx(ze,{days:h.calendarDays,selectedSleepId:(f==null?void 0:f.id)??null,onSelect:m=>u(m)}),f&&P?e.jsx(Le,{session:f,draft:P,rawDetail:y.data??null,rawDetailLoading:y.isLoading,pending:M.isPending&&((V=M.variables)==null?void 0:V.sleepId)===f.id,tab:d,linkOptions:Y,onTabChange:x,onDraftChange:m=>X(f.id,m),onSave:()=>void Z(f.id)}):e.jsx(w,{className:"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-6 py-8 text-sm leading-6 text-[var(--ui-ink-muted)]",children:"Pick a night from the calendar to inspect its phase timing, stage summary, and reflection context."})]})})]})}export{tr as SleepPage};