forge-openclaw-plugin 0.3.13 → 0.3.14

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 (136) hide show
  1. package/dist/assets/{action-bar-BFjWjRIM.js → action-bar-B9MYlps2.js} +1 -1
  2. package/dist/assets/{activity-page-D-6yBWuZ.js → activity-page-DbzbChcE.js} +1 -1
  3. package/dist/assets/{ai-surface-workspace-BEfo9bRO.js → ai-surface-workspace-CF0257Hs.js} +1 -1
  4. package/dist/assets/{atlas-panel-BfMyJXxQ.js → atlas-panel-CO3RYAKn.js} +1 -1
  5. package/dist/assets/{calendar-page-D4tQNJ2V.js → calendar-page-BuuHKEHC.js} +1 -1
  6. package/dist/assets/{calendar-rules-C-6O_uGU.js → calendar-rules-DKftgNx5.js} +1 -1
  7. package/dist/assets/{calendar-week-toolbar-_NzeKsYx.js → calendar-week-toolbar-ChIpkT-G.js} +1 -1
  8. package/dist/assets/{companion-sync-lab-page-D1Oqsf6M.js → companion-sync-lab-page-BZRX4Btw.js} +1 -1
  9. package/dist/assets/{daily-metrics-dashboard-DtE3pVOl.js → daily-metrics-dashboard-CXDsaAQd.js} +1 -1
  10. package/dist/assets/{define-workbench-box-D-32C8nM.js → define-workbench-box-CpG0Zb1L.js} +1 -1
  11. package/dist/assets/{entity-link-multiselect-DcCvkesQ.js → entity-link-multiselect-Dl4rZqdg.js} +1 -1
  12. package/dist/assets/{entity-note-count-link-Cjsk5oT2.js → entity-note-count-link-Bs1aKYyD.js} +1 -1
  13. package/dist/assets/{entity-notes-surface-DQQPLjxd.js → entity-notes-surface-B56XSw7M.js} +1 -1
  14. package/dist/assets/{execution-board-agWQbN-y.js → execution-board-D66C_ikW.js} +1 -1
  15. package/dist/assets/{faceted-token-search-DldM3-ru.js → faceted-token-search-Dg2rjknH.js} +1 -1
  16. package/dist/assets/{flagship-signal-deck-BlLYW9Kz.js → flagship-signal-deck-C6KVPhmM.js} +1 -1
  17. package/dist/assets/{floating-action-menu-D9-psbha.js → floating-action-menu-DAFAEBcA.js} +1 -1
  18. package/dist/assets/{generic-node-view-CcepUVhP.js → generic-node-view-C6DK5hJ6.js} +1 -1
  19. package/dist/assets/{goal-detail-page-DP1n5-Hk.js → goal-detail-page-CC4VXud6.js} +1 -1
  20. package/dist/assets/{goal-dialog-Oxx8WqbZ.js → goal-dialog-15hD8EBp.js} +1 -1
  21. package/dist/assets/{goals-page-CUt1a4Y2.js → goals-page-CQ2lJMzI.js} +1 -1
  22. package/dist/assets/{habits-page-5REbWAlo.js → habits-page-a7KVPaQp.js} +1 -1
  23. package/dist/assets/{health-boxes-sHNML3tm.js → health-boxes-DqgvIYoL.js} +1 -1
  24. package/dist/assets/index-ClJbJhca.css +1 -0
  25. package/dist/assets/index-FpGANF9S.js +2 -0
  26. package/dist/assets/{inline-note-fields-Bql_KfR9.js → inline-note-fields-COgzxr_7.js} +1 -1
  27. package/dist/assets/{insight-flow-dialog-CN-CMSB7.js → insight-flow-dialog-Dmb6NSGp.js} +1 -1
  28. package/dist/assets/{insights-page-B1u6ONtQ.js → insights-page-OnqR4cYI.js} +1 -1
  29. package/dist/assets/{kanban-boxes-DB1kuUlY.js → kanban-boxes-BWUzntCV.js} +1 -1
  30. package/dist/assets/{kanban-page-BBW9_vMu.js → kanban-page-BI16Gzp_.js} +1 -1
  31. package/dist/assets/{knowledge-graph-page-CoJaydZb.js → knowledge-graph-page-DxEBaEke.js} +1 -1
  32. package/dist/assets/{life-force-page-DBYbA1GF.js → life-force-page-CDEXEQai.js} +1 -1
  33. package/dist/assets/{life-force-workspace-BiD9xOEt.js → life-force-workspace-C7UOnJEf.js} +1 -1
  34. package/dist/assets/{metric-tile-CuP9DOYm.js → metric-tile-boeHB1R1.js} +1 -1
  35. package/dist/assets/{movement-boxes-DZg_qPPg.js → movement-boxes-BUSqaTL2.js} +1 -1
  36. package/dist/assets/{movement-page-CmwsQGR_.js → movement-page-DcbO0497.js} +1 -1
  37. package/dist/assets/note-markdown-DXXI3W3V.js +3 -0
  38. package/dist/assets/{note-tags-input-C_x5WdK5.js → note-tags-input-CYh3TVW2.js} +1 -1
  39. package/dist/assets/{notes-boxes-BEFlp9yd.js → notes-boxes-CMJXX2K0.js} +1 -1
  40. package/dist/assets/{notes-page-B6Vl-GPf.js → notes-page-DvHMcQey.js} +1 -1
  41. package/dist/assets/{open-in-graph-button-C-bJekoH.js → open-in-graph-button-4UYrp1XP.js} +1 -1
  42. package/dist/assets/{orbit-map-DHeTM15g.js → orbit-map-BwK7sDaC.js} +1 -1
  43. package/dist/assets/{overview-page-BRWje1F9.js → overview-page-Z5vaUTm3.js} +1 -1
  44. package/dist/assets/{page-hero-8bITsx_x.js → page-hero-DvrM83_C.js} +1 -1
  45. package/dist/assets/{pill-cluster-XQjm-wPc.js → pill-cluster-DYI3Ibj8.js} +1 -1
  46. package/dist/assets/{preference-entity-handoff-button-DwYF_5i3.js → preference-entity-handoff-button-C2ATjvws.js} +1 -1
  47. package/dist/assets/{preferences-page-C7DBPpNb.js → preferences-page-BAexXHye.js} +1 -1
  48. package/dist/assets/{project-collections-mtxanSMf.js → project-collections-B9nr-Ts-.js} +1 -1
  49. package/dist/assets/{project-detail-page-BT87Goqc.js → project-detail-page-B9PqyPu9.js} +1 -1
  50. package/dist/assets/{project-dialog-DnZe757y.js → project-dialog-CBA-D65n.js} +1 -1
  51. package/dist/assets/{project-management-hierarchy-page-B3R2lNFI.js → project-management-hierarchy-page-DXK14jn0.js} +1 -1
  52. package/dist/assets/{project-management-section-nav-DyBWxHbe.js → project-management-section-nav-DJ3QKCtr.js} +1 -1
  53. package/dist/assets/{projects-boxes-CxZj3P29.js → projects-boxes-iBu_PRqe.js} +1 -1
  54. package/dist/assets/{projects-page-Bec11c0x.js → projects-page-CdAk-ByT.js} +1 -1
  55. package/dist/assets/{psyche-behaviors-page-DWRpYvl1.js → psyche-behaviors-page-CbhhTfU2.js} +1 -1
  56. package/dist/assets/{psyche-flashcards-page-CX4rcsXZ.js → psyche-flashcards-page-DQaw_vUQ.js} +1 -1
  57. package/dist/assets/{psyche-goal-map-page-Y6b3lCvV.js → psyche-goal-map-page-C-ZTVOEP.js} +1 -1
  58. package/dist/assets/{psyche-graph-CQuCWKIp.js → psyche-graph-DYzeClxn.js} +1 -1
  59. package/dist/assets/{psyche-metrics-page-DadDJOnm.js → psyche-metrics-page-C9hKn10A.js} +1 -1
  60. package/dist/assets/{psyche-mode-guide-page-B1nz0uCg.js → psyche-mode-guide-page-CR8e984W.js} +1 -1
  61. package/dist/assets/{psyche-modes-page-i3uSuhKA.js → psyche-modes-page-lQdpAcY3.js} +1 -1
  62. package/dist/assets/{psyche-page-Y_s-BE2m.js → psyche-page-CTdIDkw9.js} +1 -1
  63. package/dist/assets/{psyche-patterns-page-DaaOLIlN.js → psyche-patterns-page-Drgm-f7I.js} +1 -1
  64. package/dist/assets/{psyche-questionnaire-builder-page-CuF7rXOv.js → psyche-questionnaire-builder-page-gRwdGXde.js} +1 -1
  65. package/dist/assets/{psyche-questionnaire-detail-page-BfFEMkRY.js → psyche-questionnaire-detail-page-CIP9b2UI.js} +1 -1
  66. package/dist/assets/{psyche-questionnaire-run-detail-page-BoQTvd7Q.js → psyche-questionnaire-run-detail-page-SYndwtF3.js} +1 -1
  67. package/dist/assets/{psyche-questionnaire-run-page-C0qKiNZN.js → psyche-questionnaire-run-page-CXiJyd5i.js} +1 -1
  68. package/dist/assets/{psyche-questionnaires-page-B6hfD448.js → psyche-questionnaires-page-CFPKwA3O.js} +1 -1
  69. package/dist/assets/{psyche-report-detail-page-BlFL8moM.js → psyche-report-detail-page-dU30a2WE.js} +1 -1
  70. package/dist/assets/{psyche-reports-page-DAAcYENp.js → psyche-reports-page-Cn0EBndy.js} +1 -1
  71. package/dist/assets/{psyche-schemas-beliefs-page-CsxKSrKM.js → psyche-schemas-beliefs-page-Bab4xSWv.js} +1 -1
  72. package/dist/assets/{psyche-screen-time-page-n4b0e58x.js → psyche-screen-time-page-lIe6GQxJ.js} +1 -1
  73. package/dist/assets/{psyche-self-observation-page-BaxEQ2-3.js → psyche-self-observation-page-BTE3KfIl.js} +1 -1
  74. package/dist/assets/{psyche-values-page-DTv5NMSU.js → psyche-values-page-DclBZ9xw.js} +1 -1
  75. package/dist/assets/question-flow-dialog-Ded2E85L.js +2 -0
  76. package/dist/assets/{report-chain-fields-D132-EMh.js → report-chain-fields-DY640iqL.js} +1 -1
  77. package/dist/assets/{rewards-page-C533lVP-.js → rewards-page-FxUXB76B.js} +1 -1
  78. package/dist/assets/{scheduling-rules-editor-CDpontGp.js → scheduling-rules-editor-jakFfxqF.js} +1 -1
  79. package/dist/assets/{schema-badge-B3DiMnjB.js → schema-badge-30B5syHA.js} +1 -1
  80. package/dist/assets/{schemas-CH1_ngUX.js → schemas-Db29G8NU.js} +1 -1
  81. package/dist/assets/{select-menu-BOF-k4Ln.js → select-menu-BF2zI3RW.js} +1 -1
  82. package/dist/assets/{settings-agents-page-B5OQtlZX.js → settings-agents-page-Bh-Bv6FQ.js} +1 -1
  83. package/dist/assets/{settings-bin-page-D_bk3Kcu.js → settings-bin-page-DT8JJero.js} +1 -1
  84. package/dist/assets/{settings-calendar-page-PuSj9_kM.js → settings-calendar-page-BA4_Qqiu.js} +3 -3
  85. package/dist/assets/{settings-data-page-EwFMaeq6.js → settings-data-page-K4kpmQJY.js} +1 -1
  86. package/dist/assets/{settings-logs-page-BKkse0DX.js → settings-logs-page-DkuNPAZo.js} +1 -1
  87. package/dist/assets/{settings-mobile-page-BrIVmdeB.js → settings-mobile-page-4pCNwD91.js} +1 -1
  88. package/dist/assets/{settings-models-page-Mg84D_0K.js → settings-models-page-CZHG3t7W.js} +1 -1
  89. package/dist/assets/{settings-page-D-kul92f.js → settings-page-B_Be0vOY.js} +1 -1
  90. package/dist/assets/{settings-rewards-page-waNyCcX_.js → settings-rewards-page-C6nFTWJu.js} +1 -1
  91. package/dist/assets/{settings-section-nav-BmJWnrYk.js → settings-section-nav-Lo-VKCfZ.js} +1 -1
  92. package/dist/assets/{settings-users-page-DBgC6y56.js → settings-users-page-CVzNp4-m.js} +1 -1
  93. package/dist/assets/{settings-wiki-page-CM0te9dI.js → settings-wiki-page-DXM--7BB.js} +1 -1
  94. package/dist/assets/sleep-page-DvPdZMKx.js +1 -0
  95. package/dist/assets/{sports-page-eg5Rfc_E.js → sports-page-DjuZlOur.js} +1 -1
  96. package/dist/assets/{strategies-page-D4AqvFNW.js → strategies-page-PE1IlatS.js} +1 -1
  97. package/dist/assets/{strategy-detail-page-BlYVkXaW.js → strategy-detail-page-C4KiEGCI.js} +1 -1
  98. package/dist/assets/{strategy-dialog-FO9Oa0dB.js → strategy-dialog-Cwf7Y3P5.js} +1 -1
  99. package/dist/assets/surface-ubuOfukq.js +1 -0
  100. package/dist/assets/{task-detail-page-Dy-aRyY6.js → task-detail-page-B3SMFZQ3.js} +1 -1
  101. package/dist/assets/{task-dialog-DrA9pba7.js → task-dialog-CI_Fy_FW.js} +1 -1
  102. package/dist/assets/{timebox-planning-dialog-C_gnfxFx.js → timebox-planning-dialog-BtFuVoA1.js} +1 -1
  103. package/dist/assets/{today-boxes-BFOws_iC.js → today-boxes-CYuxSkZf.js} +1 -1
  104. package/dist/assets/{today-page-BoPj6a6q.js → today-page-CHGpLEZ3.js} +1 -1
  105. package/dist/assets/{training-load-page-DGU40Zfl.js → training-load-page-GZJF-Yy5.js} +1 -1
  106. package/dist/assets/{user-badge-CZWtYeMw.js → user-badge-ByhC6bMU.js} +1 -1
  107. package/dist/assets/{utility-widgets-B3wWGxQc.js → utility-widgets-ilORjDmg.js} +1 -1
  108. package/dist/assets/{vitals-page-BXRZEP_8.js → vitals-page-mdEqIm_9.js} +1 -1
  109. package/dist/assets/{weekly-review-page-D5cebA5x.js → weekly-review-page-C8W-yg5r.js} +1 -1
  110. package/dist/assets/weight-loss-page-BApTknCn.js +5 -0
  111. package/dist/assets/{wiki-article-markdown-CvaCjg_t.js → wiki-article-markdown-DBccllQg.js} +1 -1
  112. package/dist/assets/{wiki-editor-page-Dco79SLY.js → wiki-editor-page-BfRfH1O3.js} +2 -2
  113. package/dist/assets/{wiki-ingest-history-page-uvKRkRDF.js → wiki-ingest-history-page-C-6H3MU6.js} +1 -1
  114. package/dist/assets/{wiki-ingest-modal-BW6AJPea.js → wiki-ingest-modal-DnlhByD_.js} +1 -1
  115. package/dist/assets/{wiki-page-BIL5zMqv.js → wiki-page-DPZ55e3x.js} +1 -1
  116. package/dist/assets/{workbench-flow-page-Dx_nq8R_.js → workbench-flow-page-_-NKIx5R.js} +1 -1
  117. package/dist/assets/{workbench-page-BJnt_Zzf.js → workbench-page-NIAzggwX.js} +1 -1
  118. package/dist/assets/{workout-detail-page-CKgqyB-y.js → workout-detail-page-3fxr6HL4.js} +1 -1
  119. package/dist/index.html +2 -2
  120. package/dist/server/server/src/app.js +8 -4
  121. package/dist/server/server/src/health-weight-loss.js +321 -14
  122. package/dist/server/server/src/managers/platform/openai-responses-provider.js +2 -2
  123. package/dist/server/server/src/openapi.js +26 -3
  124. package/dist/server/server/src/repositories/ai-connectors.js +1 -1
  125. package/openclaw.plugin.json +1 -1
  126. package/package.json +1 -1
  127. package/skills/forge-openclaw/SKILL.md +22 -0
  128. package/skills/forge-openclaw/entity_conversation_playbooks.md +17 -0
  129. package/skills/forge-openclaw/psyche_entity_playbooks.md +7 -0
  130. package/dist/assets/index-CQ5r7ZUz.js +0 -2
  131. package/dist/assets/index-FxgNSuZX.css +0 -1
  132. package/dist/assets/note-markdown-B82ncnFt.js +0 -3
  133. package/dist/assets/question-flow-dialog-CskCt5NZ.js +0 -2
  134. package/dist/assets/sleep-page-C_krRE59.js +0 -1
  135. package/dist/assets/surface-MVeeZGKB.js +0 -1
  136. package/dist/assets/weight-loss-page-BuUdFh9z.js +0 -5
@@ -1 +1 @@
1
- import{bY as H,r as c,j as r,cn as V,aK as Q,b7 as G,F as J}from"./vendor-BwL6m4SE.js";import{x as W}from"./state-Bpe5dF3T.js";import{k as q,S as Y,e as X,C as F,B as A,I as Z,dN as ee,c as z,dO as te,b as se}from"./index-CQ5r7ZUz.js";import{P as re}from"./page-hero-8bITsx_x.js";import{S as ne}from"./settings-section-nav-BmJWnrYk.js";import{u as ie}from"./use-anchored-overlay-position-BY4kNzPj.js";import"./motion-DcgUnXhY.js";import"./ui-B9TWEtCx.js";import"./board-CuxQRKPJ.js";import"./forms-D1qJ3oOP.js";const ae=["error","warning","info","debug"],oe=["server","ui","system","agent","openclaw"],le=60,P="text-[11px] font-medium uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",T="text-[var(--ui-ink-soft)]",h="text-[var(--ui-ink-faint)]",ce="text-[var(--ui-ink-strong)]",de="bg-[var(--ui-surface-3)] text-[var(--ui-ink-medium)]",ue="relative rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-3 py-2.5",ge="inline-flex max-w-full items-center gap-1.5 rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-1.5 py-1",me="z-[80] overflow-y-auto overscroll-contain rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-popover)] p-2 shadow-[var(--ui-shadow-floating)] backdrop-blur-xl [webkit-overflow-scrolling:touch]",fe="rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-3";function L(t){return t.trim().toLowerCase()}function C(t){return Array.from(new Set(t.map(n=>(n==null?void 0:n.trim())??"").filter(Boolean)))}function $(t,n){const s=C(t.getAll(n));if(s.length>0)return s;const a=t.get(n);return a!=null&&a.trim()?[a.trim()]:[]}function pe(t){return new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"medium"}).format(new Date(t))}function U(t){return t==="error"?"border-[color-mix(in_srgb,var(--danger)_30%,var(--ui-border-subtle)_70%)] bg-[var(--ui-danger-soft)] text-[color-mix(in_srgb,var(--danger)_76%,var(--ui-ink-strong)_24%)]":t==="warning"?"border-[color-mix(in_srgb,var(--warning)_30%,var(--ui-border-subtle)_70%)] bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]":t==="info"?"border-[color-mix(in_srgb,var(--primary)_30%,var(--ui-border-subtle)_70%)] bg-[var(--ui-accent-soft)] text-[var(--primary)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-3)] text-[var(--ui-ink-medium)]"}function B(t){return t==="error"?"Errors":t==="warning"?"Warnings":t==="info"?"Info":"Debug"}function R(t){return t==="openclaw"?"OpenClaw":t.charAt(0).toUpperCase()+t.slice(1)}function xe(t){return[t.scope?`scope: ${t.scope}`:null,t.eventKey?`event: ${t.eventKey}`:null,t.route?`route: ${t.route}`:null,t.functionName?`function: ${t.functionName}`:null,t.jobId?`job: ${t.jobId}`:null,t.entityType&&t.entityId?`entity: ${t.entityType}:${t.entityId}`:null,t.requestId?`request: ${t.requestId}`:null].filter(n=>!!n)}function he(t){return L([t.message,t.scope,t.eventKey,t.route,t.functionName,t.requestId,t.entityType,t.entityId,t.jobId,JSON.stringify(t.details)].filter(Boolean).join(" "))}function j(t,n){return r.jsx(q,{size:"sm",className:z(de,n),children:t})}function K(t,n){return te(t)?r.jsx(se,{kind:t,label:n,compact:!0,gradient:!1}):j(n,"bg-[var(--ui-accent-soft)] text-[var(--primary)]")}function k({label:t,placeholder:n,options:s,selectedIds:a,onChange:m,emptyMessage:u="No matches yet."}){const[w,d]=c.useState(!1),[b,v]=c.useState(""),[I,y]=c.useState(0),E=c.useRef(null),M=c.useRef(null),O=ie(E,w,{offset:8,preferredMaxHeight:320,minHeight:160}),_=c.useMemo(()=>a.map(i=>s.find(o=>o.id===i)??null).filter(i=>i!==null),[s,a]),p=L(b),x=c.useMemo(()=>{const i=s.filter(o=>!a.includes(o.id));return p?i.filter(o=>L(`${o.label} ${o.description??""} ${o.searchText??""}`).includes(p)).slice(0,10):i.slice(0,10)},[p,s,a]),N=i=>{a.includes(i)||(m([...a,i]),v(""),y(0),d(!1))},D=i=>{m(a.filter(o=>o!==i))};return c.useEffect(()=>{if(!w)return;const i=e=>{var g,f;const l=e.target;(g=E.current)!=null&&g.contains(l)||(f=M.current)!=null&&f.contains(l)||d(!1)},o=e=>{e.key==="Escape"&&d(!1)};return document.addEventListener("pointerdown",i),document.addEventListener("keydown",o),()=>{document.removeEventListener("pointerdown",i),document.removeEventListener("keydown",o)}},[w]),r.jsxs("label",{className:"grid gap-2",children:[r.jsx("span",{className:P,children:t}),r.jsxs("div",{ref:E,className:ue,children:[_.length>0?r.jsx("div",{className:"mb-2 flex flex-wrap gap-1.5",children:_.map(i=>r.jsxs("span",{className:ge,children:[i.badge,r.jsx("button",{type:"button",className:`rounded-full p-0.5 transition hover:text-[var(--ui-ink-strong)] ${h}`,onClick:()=>D(i.id),"aria-label":`Remove ${i.label}`,children:r.jsx(Q,{className:"size-3"})})]},i.id))}):null,r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(G,{className:`size-3.5 ${h}`}),r.jsx("input",{value:b,onChange:i=>{v(i.target.value),y(0),d(!0)},onFocus:()=>d(!0),onKeyDown:i=>{if(i.key==="Backspace"&&!b&&a.length>0){D(a[a.length-1]);return}if(i.key==="ArrowDown"){i.preventDefault(),d(!0),y(o=>x.length===0?0:Math.min(x.length-1,o+1));return}if(i.key==="ArrowUp"){i.preventDefault(),y(o=>Math.max(0,o-1));return}if(i.key==="Escape"){d(!1);return}i.key==="Enter"&&x[I]&&(i.preventDefault(),N(x[I].id))},placeholder:n,className:"min-w-0 flex-1 bg-transparent text-sm text-[var(--ui-ink-strong)] placeholder:text-[var(--ui-ink-faint)] focus:outline-none"})]}),w&&O&&typeof document<"u"?J.createPortal(r.jsx("div",{ref:M,role:"listbox","aria-multiselectable":"true",className:me,style:O,children:x.length>0?x.map((i,o)=>r.jsx("button",{type:"button",role:"option","aria-selected":!1,className:z("flex w-full items-start justify-between gap-3 rounded-[16px] px-3 py-2 text-left transition",o===I?"bg-[var(--ui-accent-soft)] text-[var(--ui-ink-strong)]":"text-[var(--ui-ink-soft)] hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]"),onMouseEnter:()=>y(o),onMouseDown:e=>e.preventDefault(),onClick:()=>N(i.id),children:r.jsxs("div",{className:"min-w-0",children:[r.jsx("div",{className:"truncate text-sm font-medium",children:i.menuBadge??i.badge}),i.description?r.jsx("div",{className:`mt-1 text-xs leading-5 ${h}`,children:i.description}):null]})},i.id)):r.jsx("div",{className:`px-3 py-2 text-sm ${h}`,children:u})}),document.body):null]})]})}function be(t,n){const s=`${n.entityType}:${n.entityId}`;t.has(s)||t.set(s,{id:s,label:n.label,description:n.description,searchText:n.searchText,badge:n.badge,menuBadge:n.menuBadge})}function ve(t){const n=new Map;for(const s of t){if(!s.entityType||!s.entityId)continue;const a=`${s.entityType}:${s.entityId}`;if(n.has(a))continue;const m=s.entityType==="wiki_ingest_job"?`Ingest ${s.entityId}`:`${s.entityType} ${s.entityId}`;be(n,{entityType:s.entityType,entityId:s.entityId,label:m,description:"Seen in diagnostics logs",searchText:L(`${m} ${s.scope} ${s.message} ${s.eventKey}`),badge:K(s.entityType,m),menuBadge:K(s.entityType,m)})}return Array.from(n.values()).sort((s,a)=>s.label.localeCompare(a.label))}const ye=c.memo(function({entry:n}){const[s,a]=c.useState(!1),m=c.useMemo(()=>s&&Object.keys(n.details).length>0?JSON.stringify(n.details,null,2):"",[s,n.details]);return r.jsxs(F,{className:"grid gap-4",children:[r.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[r.jsxs("div",{className:"grid min-w-0 gap-3",children:[r.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[r.jsx("span",{className:z("rounded-full border px-2 py-0.5 text-[10px] font-semibold uppercase tracking-[0.16em]",U(n.level)),children:n.level}),r.jsx("span",{className:`rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-3)] px-2 py-0.5 text-[10px] font-semibold uppercase tracking-[0.16em] ${T}`,children:n.source}),r.jsx("span",{className:`rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-3)] px-2 py-0.5 text-[10px] font-semibold uppercase tracking-[0.16em] ${T}`,children:n.scope}),n.eventKey?r.jsx("span",{className:`max-w-full break-words rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-3)] px-2 py-0.5 text-[10px] font-semibold uppercase tracking-[0.16em] [overflow-wrap:anywhere] ${h}`,children:n.eventKey}):null]}),r.jsx("div",{className:`break-words text-base font-medium [overflow-wrap:anywhere] ${ce}`,children:n.message}),r.jsx("div",{className:`flex flex-wrap gap-3 break-words text-xs [overflow-wrap:anywhere] ${h}`,children:xe(n).map(u=>r.jsx("span",{children:u},u))})]}),r.jsxs("div",{className:`shrink-0 text-right text-xs ${h}`,children:[r.jsx("div",{children:pe(n.createdAt)}),r.jsx("div",{className:"mt-1 font-mono text-[11px]",children:n.id})]})]}),Object.keys(n.details).length>0?r.jsxs("details",{className:fe,onToggle:u=>a(u.currentTarget.open),children:[r.jsx("summary",{className:`cursor-pointer text-sm ${T}`,children:"View structured details"}),s?r.jsx("pre",{className:`mt-3 overflow-x-auto whitespace-pre-wrap text-xs leading-6 ${T}`,children:m}):null]}):null]})});function Le(){const[t,n]=H(),s=c.useMemo(()=>{var f,S;const e=((f=t.get("entityType"))==null?void 0:f.trim())||"",l=((S=t.get("entityId"))==null?void 0:S.trim())||"",g=$(t,"entity");return g.length===0&&e&&l&&g.push(`${e}:${l}`),{search:t.get("search")||"",levels:$(t,"level"),sources:$(t,"source"),scopes:$(t,"scope"),routes:$(t,"route"),jobs:$(t,"jobId"),entities:C(g)}},[t]),a=W({queryKey:["forge-diagnostic-logs","settings-filters"],initialPageParam:null,queryFn:({pageParam:e})=>ee({limit:le,beforeCreatedAt:e==null?void 0:e.beforeCreatedAt,beforeId:e==null?void 0:e.beforeId}),getNextPageParam:e=>e.nextCursor,retry:!1,refetchOnWindowFocus:!1}),m=(e,l)=>{const g=new URLSearchParams(t);l.trim()?g.set(e,l.trim()):g.delete(e),n(g,{replace:!0})},u=(e,l,g=[])=>{const f=new URLSearchParams(t);f.delete(e);for(const S of g)f.delete(S);for(const S of C(l))f.append(e,S);n(f,{replace:!0})},w=()=>{const e=new URLSearchParams(t);["search","level","source","scope","route","jobId","entity","entityType","entityId"].forEach(l=>e.delete(l)),n(e,{replace:!0})},d=c.useMemo(()=>{var e;return((e=a.data)==null?void 0:e.pages.flatMap(l=>l.logs))??[]},[a.data]),b=L(s.search),v=c.useRef(null),I=c.useMemo(()=>ae.map(e=>({id:e,label:B(e),searchText:`${e} ${B(e)}`,badge:r.jsx(q,{size:"sm",className:U(e),children:B(e)})})),[]),y=c.useMemo(()=>oe.map(e=>({id:e,label:R(e),searchText:`${e} ${R(e)}`,badge:j(R(e))})),[]),E=c.useMemo(()=>C(d.map(e=>e.scope)).map(e=>({id:e,label:e,searchText:e,badge:j(e)})),[d]),M=c.useMemo(()=>C(d.map(e=>e.route)).map(e=>({id:e,label:e,description:"Filter logs to one or more exact routes.",searchText:e,badge:j(e,"max-w-[16rem]"),menuBadge:j(e)})),[d]),O=c.useMemo(()=>C(d.map(e=>e.jobId)).map(e=>({id:e,label:e,description:"Background job or ingest run id.",searchText:e,badge:j(e,"max-w-[14rem]"),menuBadge:j(e)})),[d]),_=c.useMemo(()=>ve(d),[d]),p=c.useMemo(()=>d.filter(e=>{if(b&&!he(e).includes(b)||s.levels.length>0&&!s.levels.includes(e.level)||s.sources.length>0&&!s.sources.includes(e.source)||s.scopes.length>0&&!s.scopes.includes(e.scope)||s.routes.length>0&&!s.routes.includes(e.route??"")||s.jobs.length>0&&!s.jobs.includes(e.jobId??""))return!1;if(s.entities.length>0){const l=e.entityType&&e.entityId?`${e.entityType}:${e.entityId}`:"";if(!l||!s.entities.includes(l))return!1}return!0}),[s,b,d]),x=[s.search,s.levels.join("|"),s.sources.join("|"),s.scopes.join("|"),s.routes.join("|"),s.jobs.join("|"),s.entities.join("|")].join("::");c.useEffect(()=>{var e;(e=v.current)==null||e.scrollTo({top:0})},[x]);const N=V({count:p.length,getScrollElement:()=>v.current,estimateSize:()=>260,overscan:8}),D=N.getVirtualItems(),i=()=>{const e=v.current;if(!e||!a.hasNextPage||a.isFetchingNextPage)return;e.scrollHeight-e.scrollTop-e.clientHeight<=800&&a.fetchNextPage()},o=s.levels.length+s.sources.length+s.scopes.length+s.routes.length+s.jobs.length+s.entities.length+(s.search.trim()?1:0);return a.isPending?r.jsx(Y,{eyebrow:"Settings",title:"Loading diagnostics",description:"Collecting the latest frontend, backend, and runtime traces.",columns:1,blocks:6}):a.isError?r.jsx(X,{eyebrow:"Settings",error:a.error,onRetry:()=>void a.refetch()}):r.jsxs("div",{className:"mx-auto grid w-full max-w-[1220px] gap-5",children:[r.jsx(re,{title:"Logs",description:"Inspect shared diagnostics from the UI, backend routes, background jobs, and LLM flows.",badge:`${p.length} matching${p.length!==d.length?` · ${d.length} loaded`:""}${a.hasNextPage?" · more available":""}`}),r.jsx(ne,{}),r.jsxs(F,{className:"grid gap-4",children:[r.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[r.jsxs("div",{children:[r.jsx("div",{className:P,children:"Filters"}),r.jsx("div",{className:`mt-2 max-w-3xl text-sm leading-6 ${T}`,children:"Use token filters with OR-style badge selections for levels, sources, routes, jobs, scopes, and linked entities. Search still matches the message body and structured details."})]}),r.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[o>0?r.jsxs(A,{variant:"ghost",size:"sm",onClick:w,children:["Clear ",o]}):null,r.jsx(A,{variant:"secondary",size:"sm",onClick:()=>void a.refetch(),pending:a.isRefetching&&!a.isFetchingNextPage,pendingLabel:"Refreshing",children:"Refresh"})]})]}),r.jsxs("label",{className:"grid gap-2",children:[r.jsx("span",{className:P,children:"Search message or details"}),r.jsx(Z,{value:s.search,onChange:e=>m("search",e.target.value),placeholder:"LLM compilation failed, wiki_ingest, request_failed…",className:"h-11 rounded-[20px]"})]}),r.jsxs("div",{className:"grid gap-3 xl:grid-cols-2",children:[r.jsx(k,{label:"Levels",placeholder:"Add one or more levels",options:I,selectedIds:s.levels,onChange:e=>u("level",e),emptyMessage:"No additional log levels."}),r.jsx(k,{label:"Sources",placeholder:"Add one or more sources",options:y,selectedIds:s.sources,onChange:e=>u("source",e),emptyMessage:"No additional log sources."}),r.jsx(k,{label:"Scopes",placeholder:"Search scopes",options:E,selectedIds:s.scopes,onChange:e=>u("scope",e),emptyMessage:"No scopes match the current logs."}),r.jsx(k,{label:"Routes",placeholder:"Search exact routes",options:M,selectedIds:s.routes,onChange:e=>u("route",e),emptyMessage:"No routes match the current logs."}),r.jsx(k,{label:"Jobs",placeholder:"Search job ids",options:O,selectedIds:s.jobs,onChange:e=>u("jobId",e),emptyMessage:"No job ids match the current logs."}),r.jsx(k,{label:"Entities",placeholder:"Search Forge entities or logged ids",options:_,selectedIds:s.entities,onChange:e=>u("entity",e,["entityType","entityId"]),emptyMessage:"No logged entities match yet."})]})]}),r.jsx("div",{className:"grid gap-3",children:p.length===0?r.jsx(F,{className:`text-sm ${T}`,children:"No diagnostic entries match the current filters yet."}):r.jsx(F,{className:"p-0",children:r.jsxs("div",{ref:v,onScroll:i,className:"h-[72vh] overflow-y-auto px-3 py-3",children:[r.jsx("div",{className:"relative",style:{height:`${N.getTotalSize()}px`},children:D.map(e=>{const l=p[e.index];return l?r.jsx("div",{"data-index":e.index,ref:N.measureElement,className:"absolute left-0 top-0 w-full pb-3",style:{transform:`translateY(${e.start}px)`},children:r.jsx(ye,{entry:l})},l.id):null})}),r.jsx("div",{className:`border-t border-[var(--ui-border-subtle)] px-1 py-3 text-center text-xs ${h}`,children:a.isFetchingNextPage?"Loading older logs...":a.hasNextPage?"Scroll to load older logs.":`Showing all ${d.length} loaded logs.`})]})})})]})}export{Le as SettingsLogsPage};
1
+ import{bY as H,r as c,j as r,cn as V,aK as Q,b7 as G,F as J}from"./vendor-BwL6m4SE.js";import{x as W}from"./state-Bpe5dF3T.js";import{k as q,S as Y,e as X,C as F,B as A,I as Z,dN as ee,c as z,dO as te,b as se}from"./index-FpGANF9S.js";import{P as re}from"./page-hero-DvrM83_C.js";import{S as ne}from"./settings-section-nav-Lo-VKCfZ.js";import{u as ie}from"./use-anchored-overlay-position-BY4kNzPj.js";import"./motion-DcgUnXhY.js";import"./ui-B9TWEtCx.js";import"./board-CuxQRKPJ.js";import"./forms-D1qJ3oOP.js";const ae=["error","warning","info","debug"],oe=["server","ui","system","agent","openclaw"],le=60,P="text-[11px] font-medium uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",T="text-[var(--ui-ink-soft)]",h="text-[var(--ui-ink-faint)]",ce="text-[var(--ui-ink-strong)]",de="bg-[var(--ui-surface-3)] text-[var(--ui-ink-medium)]",ue="relative rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-3 py-2.5",ge="inline-flex max-w-full items-center gap-1.5 rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-1.5 py-1",me="z-[80] overflow-y-auto overscroll-contain rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-popover)] p-2 shadow-[var(--ui-shadow-floating)] backdrop-blur-xl [webkit-overflow-scrolling:touch]",fe="rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-3";function L(t){return t.trim().toLowerCase()}function C(t){return Array.from(new Set(t.map(n=>(n==null?void 0:n.trim())??"").filter(Boolean)))}function $(t,n){const s=C(t.getAll(n));if(s.length>0)return s;const a=t.get(n);return a!=null&&a.trim()?[a.trim()]:[]}function pe(t){return new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"medium"}).format(new Date(t))}function U(t){return t==="error"?"border-[color-mix(in_srgb,var(--danger)_30%,var(--ui-border-subtle)_70%)] bg-[var(--ui-danger-soft)] text-[color-mix(in_srgb,var(--danger)_76%,var(--ui-ink-strong)_24%)]":t==="warning"?"border-[color-mix(in_srgb,var(--warning)_30%,var(--ui-border-subtle)_70%)] bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]":t==="info"?"border-[color-mix(in_srgb,var(--primary)_30%,var(--ui-border-subtle)_70%)] bg-[var(--ui-accent-soft)] text-[var(--primary)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-3)] text-[var(--ui-ink-medium)]"}function B(t){return t==="error"?"Errors":t==="warning"?"Warnings":t==="info"?"Info":"Debug"}function R(t){return t==="openclaw"?"OpenClaw":t.charAt(0).toUpperCase()+t.slice(1)}function xe(t){return[t.scope?`scope: ${t.scope}`:null,t.eventKey?`event: ${t.eventKey}`:null,t.route?`route: ${t.route}`:null,t.functionName?`function: ${t.functionName}`:null,t.jobId?`job: ${t.jobId}`:null,t.entityType&&t.entityId?`entity: ${t.entityType}:${t.entityId}`:null,t.requestId?`request: ${t.requestId}`:null].filter(n=>!!n)}function he(t){return L([t.message,t.scope,t.eventKey,t.route,t.functionName,t.requestId,t.entityType,t.entityId,t.jobId,JSON.stringify(t.details)].filter(Boolean).join(" "))}function j(t,n){return r.jsx(q,{size:"sm",className:z(de,n),children:t})}function K(t,n){return te(t)?r.jsx(se,{kind:t,label:n,compact:!0,gradient:!1}):j(n,"bg-[var(--ui-accent-soft)] text-[var(--primary)]")}function k({label:t,placeholder:n,options:s,selectedIds:a,onChange:m,emptyMessage:u="No matches yet."}){const[w,d]=c.useState(!1),[b,v]=c.useState(""),[I,y]=c.useState(0),E=c.useRef(null),M=c.useRef(null),O=ie(E,w,{offset:8,preferredMaxHeight:320,minHeight:160}),_=c.useMemo(()=>a.map(i=>s.find(o=>o.id===i)??null).filter(i=>i!==null),[s,a]),p=L(b),x=c.useMemo(()=>{const i=s.filter(o=>!a.includes(o.id));return p?i.filter(o=>L(`${o.label} ${o.description??""} ${o.searchText??""}`).includes(p)).slice(0,10):i.slice(0,10)},[p,s,a]),N=i=>{a.includes(i)||(m([...a,i]),v(""),y(0),d(!1))},D=i=>{m(a.filter(o=>o!==i))};return c.useEffect(()=>{if(!w)return;const i=e=>{var g,f;const l=e.target;(g=E.current)!=null&&g.contains(l)||(f=M.current)!=null&&f.contains(l)||d(!1)},o=e=>{e.key==="Escape"&&d(!1)};return document.addEventListener("pointerdown",i),document.addEventListener("keydown",o),()=>{document.removeEventListener("pointerdown",i),document.removeEventListener("keydown",o)}},[w]),r.jsxs("label",{className:"grid gap-2",children:[r.jsx("span",{className:P,children:t}),r.jsxs("div",{ref:E,className:ue,children:[_.length>0?r.jsx("div",{className:"mb-2 flex flex-wrap gap-1.5",children:_.map(i=>r.jsxs("span",{className:ge,children:[i.badge,r.jsx("button",{type:"button",className:`rounded-full p-0.5 transition hover:text-[var(--ui-ink-strong)] ${h}`,onClick:()=>D(i.id),"aria-label":`Remove ${i.label}`,children:r.jsx(Q,{className:"size-3"})})]},i.id))}):null,r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(G,{className:`size-3.5 ${h}`}),r.jsx("input",{value:b,onChange:i=>{v(i.target.value),y(0),d(!0)},onFocus:()=>d(!0),onKeyDown:i=>{if(i.key==="Backspace"&&!b&&a.length>0){D(a[a.length-1]);return}if(i.key==="ArrowDown"){i.preventDefault(),d(!0),y(o=>x.length===0?0:Math.min(x.length-1,o+1));return}if(i.key==="ArrowUp"){i.preventDefault(),y(o=>Math.max(0,o-1));return}if(i.key==="Escape"){d(!1);return}i.key==="Enter"&&x[I]&&(i.preventDefault(),N(x[I].id))},placeholder:n,className:"min-w-0 flex-1 bg-transparent text-sm text-[var(--ui-ink-strong)] placeholder:text-[var(--ui-ink-faint)] focus:outline-none"})]}),w&&O&&typeof document<"u"?J.createPortal(r.jsx("div",{ref:M,role:"listbox","aria-multiselectable":"true",className:me,style:O,children:x.length>0?x.map((i,o)=>r.jsx("button",{type:"button",role:"option","aria-selected":!1,className:z("flex w-full items-start justify-between gap-3 rounded-[16px] px-3 py-2 text-left transition",o===I?"bg-[var(--ui-accent-soft)] text-[var(--ui-ink-strong)]":"text-[var(--ui-ink-soft)] hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]"),onMouseEnter:()=>y(o),onMouseDown:e=>e.preventDefault(),onClick:()=>N(i.id),children:r.jsxs("div",{className:"min-w-0",children:[r.jsx("div",{className:"truncate text-sm font-medium",children:i.menuBadge??i.badge}),i.description?r.jsx("div",{className:`mt-1 text-xs leading-5 ${h}`,children:i.description}):null]})},i.id)):r.jsx("div",{className:`px-3 py-2 text-sm ${h}`,children:u})}),document.body):null]})]})}function be(t,n){const s=`${n.entityType}:${n.entityId}`;t.has(s)||t.set(s,{id:s,label:n.label,description:n.description,searchText:n.searchText,badge:n.badge,menuBadge:n.menuBadge})}function ve(t){const n=new Map;for(const s of t){if(!s.entityType||!s.entityId)continue;const a=`${s.entityType}:${s.entityId}`;if(n.has(a))continue;const m=s.entityType==="wiki_ingest_job"?`Ingest ${s.entityId}`:`${s.entityType} ${s.entityId}`;be(n,{entityType:s.entityType,entityId:s.entityId,label:m,description:"Seen in diagnostics logs",searchText:L(`${m} ${s.scope} ${s.message} ${s.eventKey}`),badge:K(s.entityType,m),menuBadge:K(s.entityType,m)})}return Array.from(n.values()).sort((s,a)=>s.label.localeCompare(a.label))}const ye=c.memo(function({entry:n}){const[s,a]=c.useState(!1),m=c.useMemo(()=>s&&Object.keys(n.details).length>0?JSON.stringify(n.details,null,2):"",[s,n.details]);return r.jsxs(F,{className:"grid gap-4",children:[r.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[r.jsxs("div",{className:"grid min-w-0 gap-3",children:[r.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[r.jsx("span",{className:z("rounded-full border px-2 py-0.5 text-[10px] font-semibold uppercase tracking-[0.16em]",U(n.level)),children:n.level}),r.jsx("span",{className:`rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-3)] px-2 py-0.5 text-[10px] font-semibold uppercase tracking-[0.16em] ${T}`,children:n.source}),r.jsx("span",{className:`rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-3)] px-2 py-0.5 text-[10px] font-semibold uppercase tracking-[0.16em] ${T}`,children:n.scope}),n.eventKey?r.jsx("span",{className:`max-w-full break-words rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-3)] px-2 py-0.5 text-[10px] font-semibold uppercase tracking-[0.16em] [overflow-wrap:anywhere] ${h}`,children:n.eventKey}):null]}),r.jsx("div",{className:`break-words text-base font-medium [overflow-wrap:anywhere] ${ce}`,children:n.message}),r.jsx("div",{className:`flex flex-wrap gap-3 break-words text-xs [overflow-wrap:anywhere] ${h}`,children:xe(n).map(u=>r.jsx("span",{children:u},u))})]}),r.jsxs("div",{className:`shrink-0 text-right text-xs ${h}`,children:[r.jsx("div",{children:pe(n.createdAt)}),r.jsx("div",{className:"mt-1 font-mono text-[11px]",children:n.id})]})]}),Object.keys(n.details).length>0?r.jsxs("details",{className:fe,onToggle:u=>a(u.currentTarget.open),children:[r.jsx("summary",{className:`cursor-pointer text-sm ${T}`,children:"View structured details"}),s?r.jsx("pre",{className:`mt-3 overflow-x-auto whitespace-pre-wrap text-xs leading-6 ${T}`,children:m}):null]}):null]})});function Le(){const[t,n]=H(),s=c.useMemo(()=>{var f,S;const e=((f=t.get("entityType"))==null?void 0:f.trim())||"",l=((S=t.get("entityId"))==null?void 0:S.trim())||"",g=$(t,"entity");return g.length===0&&e&&l&&g.push(`${e}:${l}`),{search:t.get("search")||"",levels:$(t,"level"),sources:$(t,"source"),scopes:$(t,"scope"),routes:$(t,"route"),jobs:$(t,"jobId"),entities:C(g)}},[t]),a=W({queryKey:["forge-diagnostic-logs","settings-filters"],initialPageParam:null,queryFn:({pageParam:e})=>ee({limit:le,beforeCreatedAt:e==null?void 0:e.beforeCreatedAt,beforeId:e==null?void 0:e.beforeId}),getNextPageParam:e=>e.nextCursor,retry:!1,refetchOnWindowFocus:!1}),m=(e,l)=>{const g=new URLSearchParams(t);l.trim()?g.set(e,l.trim()):g.delete(e),n(g,{replace:!0})},u=(e,l,g=[])=>{const f=new URLSearchParams(t);f.delete(e);for(const S of g)f.delete(S);for(const S of C(l))f.append(e,S);n(f,{replace:!0})},w=()=>{const e=new URLSearchParams(t);["search","level","source","scope","route","jobId","entity","entityType","entityId"].forEach(l=>e.delete(l)),n(e,{replace:!0})},d=c.useMemo(()=>{var e;return((e=a.data)==null?void 0:e.pages.flatMap(l=>l.logs))??[]},[a.data]),b=L(s.search),v=c.useRef(null),I=c.useMemo(()=>ae.map(e=>({id:e,label:B(e),searchText:`${e} ${B(e)}`,badge:r.jsx(q,{size:"sm",className:U(e),children:B(e)})})),[]),y=c.useMemo(()=>oe.map(e=>({id:e,label:R(e),searchText:`${e} ${R(e)}`,badge:j(R(e))})),[]),E=c.useMemo(()=>C(d.map(e=>e.scope)).map(e=>({id:e,label:e,searchText:e,badge:j(e)})),[d]),M=c.useMemo(()=>C(d.map(e=>e.route)).map(e=>({id:e,label:e,description:"Filter logs to one or more exact routes.",searchText:e,badge:j(e,"max-w-[16rem]"),menuBadge:j(e)})),[d]),O=c.useMemo(()=>C(d.map(e=>e.jobId)).map(e=>({id:e,label:e,description:"Background job or ingest run id.",searchText:e,badge:j(e,"max-w-[14rem]"),menuBadge:j(e)})),[d]),_=c.useMemo(()=>ve(d),[d]),p=c.useMemo(()=>d.filter(e=>{if(b&&!he(e).includes(b)||s.levels.length>0&&!s.levels.includes(e.level)||s.sources.length>0&&!s.sources.includes(e.source)||s.scopes.length>0&&!s.scopes.includes(e.scope)||s.routes.length>0&&!s.routes.includes(e.route??"")||s.jobs.length>0&&!s.jobs.includes(e.jobId??""))return!1;if(s.entities.length>0){const l=e.entityType&&e.entityId?`${e.entityType}:${e.entityId}`:"";if(!l||!s.entities.includes(l))return!1}return!0}),[s,b,d]),x=[s.search,s.levels.join("|"),s.sources.join("|"),s.scopes.join("|"),s.routes.join("|"),s.jobs.join("|"),s.entities.join("|")].join("::");c.useEffect(()=>{var e;(e=v.current)==null||e.scrollTo({top:0})},[x]);const N=V({count:p.length,getScrollElement:()=>v.current,estimateSize:()=>260,overscan:8}),D=N.getVirtualItems(),i=()=>{const e=v.current;if(!e||!a.hasNextPage||a.isFetchingNextPage)return;e.scrollHeight-e.scrollTop-e.clientHeight<=800&&a.fetchNextPage()},o=s.levels.length+s.sources.length+s.scopes.length+s.routes.length+s.jobs.length+s.entities.length+(s.search.trim()?1:0);return a.isPending?r.jsx(Y,{eyebrow:"Settings",title:"Loading diagnostics",description:"Collecting the latest frontend, backend, and runtime traces.",columns:1,blocks:6}):a.isError?r.jsx(X,{eyebrow:"Settings",error:a.error,onRetry:()=>void a.refetch()}):r.jsxs("div",{className:"mx-auto grid w-full max-w-[1220px] gap-5",children:[r.jsx(re,{title:"Logs",description:"Inspect shared diagnostics from the UI, backend routes, background jobs, and LLM flows.",badge:`${p.length} matching${p.length!==d.length?` · ${d.length} loaded`:""}${a.hasNextPage?" · more available":""}`}),r.jsx(ne,{}),r.jsxs(F,{className:"grid gap-4",children:[r.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[r.jsxs("div",{children:[r.jsx("div",{className:P,children:"Filters"}),r.jsx("div",{className:`mt-2 max-w-3xl text-sm leading-6 ${T}`,children:"Use token filters with OR-style badge selections for levels, sources, routes, jobs, scopes, and linked entities. Search still matches the message body and structured details."})]}),r.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[o>0?r.jsxs(A,{variant:"ghost",size:"sm",onClick:w,children:["Clear ",o]}):null,r.jsx(A,{variant:"secondary",size:"sm",onClick:()=>void a.refetch(),pending:a.isRefetching&&!a.isFetchingNextPage,pendingLabel:"Refreshing",children:"Refresh"})]})]}),r.jsxs("label",{className:"grid gap-2",children:[r.jsx("span",{className:P,children:"Search message or details"}),r.jsx(Z,{value:s.search,onChange:e=>m("search",e.target.value),placeholder:"LLM compilation failed, wiki_ingest, request_failed…",className:"h-11 rounded-[20px]"})]}),r.jsxs("div",{className:"grid gap-3 xl:grid-cols-2",children:[r.jsx(k,{label:"Levels",placeholder:"Add one or more levels",options:I,selectedIds:s.levels,onChange:e=>u("level",e),emptyMessage:"No additional log levels."}),r.jsx(k,{label:"Sources",placeholder:"Add one or more sources",options:y,selectedIds:s.sources,onChange:e=>u("source",e),emptyMessage:"No additional log sources."}),r.jsx(k,{label:"Scopes",placeholder:"Search scopes",options:E,selectedIds:s.scopes,onChange:e=>u("scope",e),emptyMessage:"No scopes match the current logs."}),r.jsx(k,{label:"Routes",placeholder:"Search exact routes",options:M,selectedIds:s.routes,onChange:e=>u("route",e),emptyMessage:"No routes match the current logs."}),r.jsx(k,{label:"Jobs",placeholder:"Search job ids",options:O,selectedIds:s.jobs,onChange:e=>u("jobId",e),emptyMessage:"No job ids match the current logs."}),r.jsx(k,{label:"Entities",placeholder:"Search Forge entities or logged ids",options:_,selectedIds:s.entities,onChange:e=>u("entity",e,["entityType","entityId"]),emptyMessage:"No logged entities match yet."})]})]}),r.jsx("div",{className:"grid gap-3",children:p.length===0?r.jsx(F,{className:`text-sm ${T}`,children:"No diagnostic entries match the current filters yet."}):r.jsx(F,{className:"p-0",children:r.jsxs("div",{ref:v,onScroll:i,className:"h-[72vh] overflow-y-auto px-3 py-3",children:[r.jsx("div",{className:"relative",style:{height:`${N.getTotalSize()}px`},children:D.map(e=>{const l=p[e.index];return l?r.jsx("div",{"data-index":e.index,ref:N.measureElement,className:"absolute left-0 top-0 w-full pb-3",style:{transform:`translateY(${e.start}px)`},children:r.jsx(ye,{entry:l})},l.id):null})}),r.jsx("div",{className:`border-t border-[var(--ui-border-subtle)] px-1 py-3 text-center text-xs ${h}`,children:a.isFetchingNextPage?"Loading older logs...":a.hasNextPage?"Scroll to load older logs.":`Showing all ${d.length} loaded logs.`})]})})})]})}export{Le as SettingsLogsPage};
@@ -1 +1 @@
1
- import{r as u,dh as ae,j as e,di as ie,dj as ne,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-BwL6m4SE.js";import{j as de,i as ce,k as P}from"./state-Bpe5dF3T.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-CQ5r7ZUz.js";import{S as je}from"./settings-section-nav-BmJWnrYk.js";import{P as we}from"./page-hero-8bITsx_x.js";import{g as be}from"./user-ownership-DJGl4rAj.js";import"./motion-DcgUnXhY.js";import"./ui-B9TWEtCx.js";import"./board-CuxQRKPJ.js";import"./forms-D1qJ3oOP.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};
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-BwL6m4SE.js";import{j as de,i as ce,k as P}from"./state-Bpe5dF3T.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-FpGANF9S.js";import{S as je}from"./settings-section-nav-Lo-VKCfZ.js";import{P as we}from"./page-hero-DvrM83_C.js";import{g as be}from"./user-ownership-DJGl4rAj.js";import"./motion-DcgUnXhY.js";import"./ui-B9TWEtCx.js";import"./board-CuxQRKPJ.js";import"./forms-D1qJ3oOP.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};
@@ -1 +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-BwL6m4SE.js";import{j as we,i as I,k as h}from"./state-Bpe5dF3T.js";import{S as Ae}from"./settings-section-nav-BmJWnrYk.js";import{P as Se}from"./page-hero-8bITsx_x.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-CQ5r7ZUz.js";import"./motion-DcgUnXhY.js";import"./ui-B9TWEtCx.js";import"./board-CuxQRKPJ.js";import"./forms-D1qJ3oOP.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};
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-BwL6m4SE.js";import{j as we,i as I,k as h}from"./state-Bpe5dF3T.js";import{S as Ae}from"./settings-section-nav-Lo-VKCfZ.js";import{P as Se}from"./page-hero-DvrM83_C.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-FpGANF9S.js";import"./motion-DcgUnXhY.js";import"./ui-B9TWEtCx.js";import"./board-CuxQRKPJ.js";import"./forms-D1qJ3oOP.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};
@@ -1 +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-BwL6m4SE.js";import{j as ke,i as L,k as M}from"./state-Bpe5dF3T.js";import{u as Se}from"./forms-D1qJ3oOP.js";import{Q as Ce,F as R,a as Te}from"./question-flow-dialog-CskCt5NZ.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-CQ5r7ZUz.js";import{S as We}from"./settings-section-nav-BmJWnrYk.js";import{P as Be}from"./page-hero-8bITsx_x.js";import{s as Xe}from"./schemas-CH1_ngUX.js";import"./ui-B9TWEtCx.js";import"./motion-DcgUnXhY.js";import"./board-CuxQRKPJ.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};
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-BwL6m4SE.js";import{j as ke,i as L,k as M}from"./state-Bpe5dF3T.js";import{u as Se}from"./forms-D1qJ3oOP.js";import{Q as Ce,F as R,a as Te}from"./question-flow-dialog-Ded2E85L.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-FpGANF9S.js";import{S as We}from"./settings-section-nav-Lo-VKCfZ.js";import{P as Be}from"./page-hero-DvrM83_C.js";import{s as Xe}from"./schemas-Db29G8NU.js";import"./ui-B9TWEtCx.js";import"./motion-DcgUnXhY.js";import"./board-CuxQRKPJ.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};
@@ -1 +1 @@
1
- import{j as e,r as v}from"./vendor-BwL6m4SE.js";import{j as de,i as k,k as Y}from"./state-Bpe5dF3T.js";import{u as Z}from"./forms-D1qJ3oOP.js";import{S as ce}from"./settings-section-nav-BmJWnrYk.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-CQ5r7ZUz.js";import{m as ae}from"./motion-DcgUnXhY.js";import{P as ye}from"./page-hero-8bITsx_x.js";import{M as re}from"./metric-tile-CuP9DOYm.js";import"./ui-B9TWEtCx.js";import"./board-CuxQRKPJ.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
+ import{j as e,r as v}from"./vendor-BwL6m4SE.js";import{j as de,i as k,k as Y}from"./state-Bpe5dF3T.js";import{u as Z}from"./forms-D1qJ3oOP.js";import{S as ce}from"./settings-section-nav-Lo-VKCfZ.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-FpGANF9S.js";import{m as ae}from"./motion-DcgUnXhY.js";import{P as ye}from"./page-hero-DvrM83_C.js";import{M as re}from"./metric-tile-boeHB1R1.js";import"./ui-B9TWEtCx.js";import"./board-CuxQRKPJ.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};