forge-openclaw-plugin 0.3.3 → 0.3.5

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 (126) hide show
  1. package/dist/assets/{action-bar-5Ii4UzHa.js → action-bar-DBZ38L_6.js} +1 -1
  2. package/dist/assets/{activity-page-CWjTKFY3.js → activity-page-BJxUR9bD.js} +1 -1
  3. package/dist/assets/{ai-surface-workspace-Dd2FSRom.js → ai-surface-workspace-ehzBjTsW.js} +1 -1
  4. package/dist/assets/{atlas-panel-Dinteouh.js → atlas-panel-BFUeVT69.js} +1 -1
  5. package/dist/assets/{calendar-page-BWkXhzDf.js → calendar-page-Bg8W-YQ-.js} +1 -1
  6. package/dist/assets/{calendar-rules-CjyuTu2I.js → calendar-rules-9XQLoI96.js} +1 -1
  7. package/dist/assets/{calendar-week-toolbar-D-nd9tkk.js → calendar-week-toolbar-BeYnx1pE.js} +1 -1
  8. package/dist/assets/{companion-sync-lab-page-G0t1TqqZ.js → companion-sync-lab-page-BRKYkIrs.js} +1 -1
  9. package/dist/assets/{daily-metrics-dashboard-DpIAdzFX.js → daily-metrics-dashboard-Jt0nAHU5.js} +1 -1
  10. package/dist/assets/{define-workbench-box-BIOZopF2.js → define-workbench-box-5h-dyvJY.js} +1 -1
  11. package/dist/assets/{entity-link-multiselect-DZZjpL_d.js → entity-link-multiselect-Bb4De_e3.js} +1 -1
  12. package/dist/assets/{entity-note-count-link-CmRRdXAr.js → entity-note-count-link-BzWnsOmI.js} +1 -1
  13. package/dist/assets/{entity-notes-surface-8MPDscsu.js → entity-notes-surface-CagOwdng.js} +1 -1
  14. package/dist/assets/{execution-board-Bi8gi8J6.js → execution-board-DTmAtmqZ.js} +1 -1
  15. package/dist/assets/{faceted-token-search-BGs4TqxT.js → faceted-token-search-DJPRm9AY.js} +1 -1
  16. package/dist/assets/{flagship-signal-deck-jLxHEHvb.js → flagship-signal-deck-CJbGZF7I.js} +1 -1
  17. package/dist/assets/{floating-action-menu-Itpm7T2_.js → floating-action-menu-K77jh8XZ.js} +1 -1
  18. package/dist/assets/{generic-node-view-KePoUF3Z.js → generic-node-view-p5ePSFuG.js} +1 -1
  19. package/dist/assets/{goal-detail-page-a1lEswpJ.js → goal-detail-page-DGu_khEK.js} +1 -1
  20. package/dist/assets/{goal-dialog-CYgRzl4y.js → goal-dialog-BWD7cOv9.js} +1 -1
  21. package/dist/assets/{goals-page-JY_EJq9U.js → goals-page-Bgj3sj0f.js} +1 -1
  22. package/dist/assets/{habits-page-BRI8AoaQ.js → habits-page-Ctut1tuX.js} +1 -1
  23. package/dist/assets/{health-boxes-DZJOFTOI.js → health-boxes-Ie3horXx.js} +1 -1
  24. package/dist/assets/index-BaiwtAgo.js +2 -0
  25. package/dist/assets/{index-Bcem7l5u.css → index-CEgIwgk9.css} +1 -1
  26. package/dist/assets/{inline-note-fields-CUVRzQkI.js → inline-note-fields-DE6WM9uM.js} +1 -1
  27. package/dist/assets/{insight-flow-dialog-By73oG1H.js → insight-flow-dialog-XL8I74eJ.js} +1 -1
  28. package/dist/assets/{insights-page-DLyN-9yz.js → insights-page-Bz1FLbp5.js} +1 -1
  29. package/dist/assets/{kanban-boxes-M71CejV4.js → kanban-boxes-BBziel7P.js} +1 -1
  30. package/dist/assets/{kanban-page-InKHhJQD.js → kanban-page-DdQP73I3.js} +1 -1
  31. package/dist/assets/{knowledge-graph-page-C-GEQGRY.js → knowledge-graph-page-DdHWj4Dj.js} +1 -1
  32. package/dist/assets/{life-force-page-Dq88NzNp.js → life-force-page-BRN-93cI.js} +1 -1
  33. package/dist/assets/{life-force-workspace-Bl_0slZi.js → life-force-workspace-BowvP5R4.js} +1 -1
  34. package/dist/assets/{metric-tile-yQJgjYrN.js → metric-tile-B6aJueRo.js} +1 -1
  35. package/dist/assets/{movement-boxes-C-rc3N8Z.js → movement-boxes-5cjWjIdR.js} +1 -1
  36. package/dist/assets/{movement-page-DK-d1uYa.js → movement-page-Dy53RWtB.js} +1 -1
  37. package/dist/assets/{note-markdown-7czv-KMH.js → note-markdown-CvEQCfoi.js} +1 -1
  38. package/dist/assets/{note-tags-input-CkgkqiT3.js → note-tags-input-Cg5zBXos.js} +1 -1
  39. package/dist/assets/{notes-boxes-BQuR1MiB.js → notes-boxes-CgZyf7mV.js} +1 -1
  40. package/dist/assets/{notes-page-ec9g1mPh.js → notes-page-Cbdcv0Ej.js} +1 -1
  41. package/dist/assets/{open-in-graph-button-B_4fdm4l.js → open-in-graph-button-D31ZOEhA.js} +1 -1
  42. package/dist/assets/{orbit-map-DPQNBqS-.js → orbit-map-8eNDWek8.js} +1 -1
  43. package/dist/assets/overview-page-CZ6q52Qj.js +1 -0
  44. package/dist/assets/{page-hero-BRcqE3a4.js → page-hero-C0MpI3MM.js} +1 -1
  45. package/dist/assets/{pill-cluster-dy6jG_dV.js → pill-cluster-DGwKZQKF.js} +1 -1
  46. package/dist/assets/{preference-entity-handoff-button-DOV-_2Vm.js → preference-entity-handoff-button-CJhr5AXl.js} +1 -1
  47. package/dist/assets/{preferences-page-Co8w5hzp.js → preferences-page-8vszDNFX.js} +1 -1
  48. package/dist/assets/{project-collections-DNgKleDl.js → project-collections-sC7eAAhS.js} +1 -1
  49. package/dist/assets/{project-detail-page-C-Ib1x8w.js → project-detail-page-BKdnMjJy.js} +1 -1
  50. package/dist/assets/{project-dialog-D_hgOdB9.js → project-dialog-BiHZpOo1.js} +1 -1
  51. package/dist/assets/{project-management-hierarchy-page-asf61KSz.js → project-management-hierarchy-page-VW-hykAI.js} +1 -1
  52. package/dist/assets/{project-management-section-nav-DAZA1oXG.js → project-management-section-nav-BEZ5zihs.js} +1 -1
  53. package/dist/assets/{projects-boxes-CHLr1Bs-.js → projects-boxes-Ca6rpYeE.js} +1 -1
  54. package/dist/assets/{projects-page-BsM8yCqQ.js → projects-page-D86pjpTf.js} +1 -1
  55. package/dist/assets/{psyche-behaviors-page-COSZeP4J.js → psyche-behaviors-page-YLJB6CRU.js} +1 -1
  56. package/dist/assets/{psyche-flashcards-page-CJmgGL9x.js → psyche-flashcards-page-D3gdHLUw.js} +1 -1
  57. package/dist/assets/{psyche-goal-map-page-avrWNSs9.js → psyche-goal-map-page-DJiqSiCx.js} +1 -1
  58. package/dist/assets/{psyche-graph-BmwbnNBY.js → psyche-graph-Tke0qFdt.js} +1 -1
  59. package/dist/assets/{psyche-metrics-page-CY0J_aMx.js → psyche-metrics-page-DoLnvmC2.js} +1 -1
  60. package/dist/assets/{psyche-mode-guide-page-COcswIHZ.js → psyche-mode-guide-page-_Zbvg_HL.js} +1 -1
  61. package/dist/assets/{psyche-modes-page-BXF_GZoP.js → psyche-modes-page-eAkaAzJc.js} +1 -1
  62. package/dist/assets/{psyche-page-VsMBNG1F.js → psyche-page-CwmuBVjA.js} +1 -1
  63. package/dist/assets/{psyche-patterns-page-DVoIro0Q.js → psyche-patterns-page-D7B4Ykjq.js} +1 -1
  64. package/dist/assets/{psyche-questionnaire-builder-page-CahcrbQj.js → psyche-questionnaire-builder-page-CHJlvCzX.js} +1 -1
  65. package/dist/assets/{psyche-questionnaire-detail-page-CYSgADAD.js → psyche-questionnaire-detail-page-Bg3ll-D4.js} +1 -1
  66. package/dist/assets/{psyche-questionnaire-run-detail-page-D5q5URTu.js → psyche-questionnaire-run-detail-page-CIEerczF.js} +1 -1
  67. package/dist/assets/{psyche-questionnaire-run-page-DUoA-VSs.js → psyche-questionnaire-run-page-DyxIk6Qx.js} +1 -1
  68. package/dist/assets/{psyche-questionnaires-page-dbQlqbKh.js → psyche-questionnaires-page-ZlqUxuIl.js} +1 -1
  69. package/dist/assets/{psyche-report-detail-page-D_Mmlf2D.js → psyche-report-detail-page-B2jgYnQ5.js} +1 -1
  70. package/dist/assets/{psyche-reports-page-CO3J4Js3.js → psyche-reports-page-DlXr52yr.js} +1 -1
  71. package/dist/assets/{psyche-schemas-beliefs-page-BUNGL4zW.js → psyche-schemas-beliefs-page-BhrTZN9B.js} +1 -1
  72. package/dist/assets/{psyche-screen-time-page-Bm18uHDg.js → psyche-screen-time-page-WNGcdusx.js} +1 -1
  73. package/dist/assets/{psyche-self-observation-page-VdPMBuK4.js → psyche-self-observation-page-XsCOglo4.js} +1 -1
  74. package/dist/assets/{psyche-values-page-DivSQodJ.js → psyche-values-page-NvHI6zWK.js} +1 -1
  75. package/dist/assets/{question-flow-dialog-Dsnsc8be.js → question-flow-dialog-Bj4PxpjS.js} +1 -1
  76. package/dist/assets/{report-chain-fields-Bf-WCSJQ.js → report-chain-fields-mWFikZzT.js} +1 -1
  77. package/dist/assets/{rewards-page-CI53Cp0i.js → rewards-page-DyjwXsQN.js} +1 -1
  78. package/dist/assets/{scheduling-rules-editor-Bg3QU_qt.js → scheduling-rules-editor-C6FEYOxd.js} +1 -1
  79. package/dist/assets/{schema-badge-CRThEDqP.js → schema-badge-CCe4zkSN.js} +1 -1
  80. package/dist/assets/{schemas-B8-kIOFQ.js → schemas-Cjwn6ooR.js} +1 -1
  81. package/dist/assets/{select-menu-rT3Qd5t5.js → select-menu-DeJhCsd8.js} +1 -1
  82. package/dist/assets/{settings-agents-page-VDUv2WuO.js → settings-agents-page-DYDxyKu-.js} +1 -1
  83. package/dist/assets/{settings-bin-page-DfuGJVqc.js → settings-bin-page-BWLfKVW1.js} +1 -1
  84. package/dist/assets/{settings-calendar-page-ex7eHB1y.js → settings-calendar-page-Ci-wXhCv.js} +1 -1
  85. package/dist/assets/{settings-data-page-BPWyPVGo.js → settings-data-page-DxIw-fWn.js} +1 -1
  86. package/dist/assets/{settings-logs-page-CwTT4n63.js → settings-logs-page-inpyIdu6.js} +1 -1
  87. package/dist/assets/{settings-mobile-page-B6sVk872.js → settings-mobile-page-BcJGLax8.js} +1 -1
  88. package/dist/assets/{settings-models-page-Dq5XViZd.js → settings-models-page-OWTRhfkj.js} +1 -1
  89. package/dist/assets/{settings-page-BRxdAxbS.js → settings-page-DXxF3qK2.js} +1 -1
  90. package/dist/assets/{settings-rewards-page-DRvxTwv3.js → settings-rewards-page-CCXin1n_.js} +1 -1
  91. package/dist/assets/{settings-section-nav-D_vKvOWd.js → settings-section-nav-CwSDNC3W.js} +1 -1
  92. package/dist/assets/{settings-users-page-B6oSpOaV.js → settings-users-page-B4NEACwR.js} +1 -1
  93. package/dist/assets/{settings-wiki-page-Bkv-SS3J.js → settings-wiki-page-BNRK1SYc.js} +1 -1
  94. package/dist/assets/{sleep-page-DELXxo6j.js → sleep-page-Bara54nB.js} +1 -1
  95. package/dist/assets/{sports-page-ByWQL0Gf.js → sports-page-BawekFKD.js} +1 -1
  96. package/dist/assets/{strategies-page-PuUHsaSJ.js → strategies-page-BEl3NGAU.js} +1 -1
  97. package/dist/assets/{strategy-detail-page-CSyVdv29.js → strategy-detail-page-DPPI_8Ub.js} +1 -1
  98. package/dist/assets/{strategy-dialog-Fgpc0z1M.js → strategy-dialog-DU6wbBkQ.js} +1 -1
  99. package/dist/assets/{surface-DzVqQDmf.js → surface-BVYp-Wq9.js} +1 -1
  100. package/dist/assets/{task-detail-page-BoLvJ_4F.js → task-detail-page-BsMVAsbb.js} +1 -1
  101. package/dist/assets/{task-dialog-B2cGkhLk.js → task-dialog-BGzPc6TW.js} +1 -1
  102. package/dist/assets/{timebox-planning-dialog-BjiC2jh0.js → timebox-planning-dialog-4_XWuqkw.js} +1 -1
  103. package/dist/assets/{today-boxes-B4f4sBXg.js → today-boxes-5pCvh5zS.js} +1 -1
  104. package/dist/assets/{today-page-Cusp2JI8.js → today-page-BGurICpl.js} +1 -1
  105. package/dist/assets/{training-load-page-CsZbK6rY.js → training-load-page-BkoYKZ9_.js} +1 -1
  106. package/dist/assets/{user-badge-CQygGKVs.js → user-badge-DfDv87j7.js} +1 -1
  107. package/dist/assets/{utility-widgets-DRESNarT.js → utility-widgets-CbYj32he.js} +1 -1
  108. package/dist/assets/{vitals-page-BlTZ4f78.js → vitals-page-DlxMk-L7.js} +1 -1
  109. package/dist/assets/{weekly-review-page-3Pk3NeGE.js → weekly-review-page-VrEvAl1T.js} +1 -1
  110. package/dist/assets/{weight-loss-page-CRCtv1fX.js → weight-loss-page-DJDnjxKF.js} +3 -3
  111. package/dist/assets/{wiki-article-markdown-D0PWvioX.js → wiki-article-markdown-DxTkiQRy.js} +1 -1
  112. package/dist/assets/{wiki-editor-page-OZMYUgFo.js → wiki-editor-page-Beu92YnZ.js} +1 -1
  113. package/dist/assets/{wiki-ingest-history-page-DXZHzAqU.js → wiki-ingest-history-page-Cq_soygm.js} +1 -1
  114. package/dist/assets/{wiki-ingest-modal-Ro0V4UMB.js → wiki-ingest-modal-D6xs2sEn.js} +1 -1
  115. package/dist/assets/{wiki-page-B1g3Rfxy.js → wiki-page-yF3Flgtg.js} +1 -1
  116. package/dist/assets/{workbench-flow-page-qh5nItU6.js → workbench-flow-page-CZZGg3a8.js} +1 -1
  117. package/dist/assets/{workbench-page-CFWfAYMV.js → workbench-page-DKENZ5Nz.js} +1 -1
  118. package/dist/assets/{workout-detail-page-Cw6t6Xj9.js → workout-detail-page-CeN4QiYQ.js} +1 -1
  119. package/dist/index.html +2 -2
  120. package/dist/server/server/src/app.js +4 -1
  121. package/dist/server/server/src/health.js +47 -19
  122. package/dist/server/src/lib/api.js +4 -1
  123. package/openclaw.plugin.json +1 -1
  124. package/package.json +1 -1
  125. package/dist/assets/index-wEZUnRh0.js +0 -2
  126. package/dist/assets/overview-page-CZjMab2o.js +0 -1
@@ -1 +1 @@
1
- import{j as e}from"./vendor-Cpmju3nw.js";import{i as p}from"./state-BtwEvpO6.js";import{L as u,e as w,bs as v,C as i,k as h,c as y,bV as j}from"./index-wEZUnRh0.js";import{P as f}from"./page-hero-BRcqE3a4.js";import{D as b,S as n,f as N,m as k,M}from"./daily-metrics-dashboard-DpIAdzFX.js";import"./motion-DwjmC9aq.js";import"./ui-B9O-eUim.js";import"./board-CLOHbg6t.js";import"./forms-C5d5hTf2.js";import"./charts-DwTguE_x.js";function r(s){return new Intl.NumberFormat().format(Math.round(s))}function d(s){return`${s.toFixed(s>=10?1:2)}%`}function C(s){return s.summary.categoryBreakdown.map(t=>({...t,metrics:s.metrics.filter(c=>c.category===t.category)}))}function P(){return e.jsxs(i,{className:"rounded-[30px] border-white/8 bg-[linear-gradient(180deg,rgba(14,20,32,0.96),rgba(9,13,24,0.98))] p-6",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/40",children:"No daily metrics yet"}),e.jsx("div",{className:"mt-2 text-2xl font-semibold text-white",children:"Psyche metrics will appear after the first local backfill finds conversations."}),e.jsx("p",{className:"mt-3 max-w-3xl text-sm leading-6 text-white/58",children:"This surface stays quiet until Forge has stored daily metric rows. It does not run the scanner while rendering the page."})]})}function K(){const s=p({queryKey:["forge-psyche-metrics-view"],queryFn:async()=>(await j()).metrics});if(s.isLoading)return e.jsx(u,{title:"Loading Psyche metrics",description:"Reading stored daily metric rows and summary statistics."});if(s.isError||!s.data)return e.jsx(w,{eyebrow:"Psyche metrics",error:s.error??new Error("Psyche metrics unavailable"),onRetry:()=>void s.refetch()});const t=s.data,c=C(t),l=t.metrics.find(a=>a.metric==="devrageSwearCount")??null,m=t.metrics.find(a=>a.metric==="swearingMessagePercent")??null,o=t.metrics.find(a=>a.metric==="devrageAverageMaxCumulativeRage")??null,x=t.metrics.find(a=>a.metric==="devrageMaxCumulativeRage")??null;return e.jsxs("div",{className:"mx-auto grid w-full max-w-[1380px] gap-5",children:[e.jsx(f,{title:"Psyche Metrics",titleText:"Psyche Metrics",description:"Daily Psyche measurements from stored history, presented with the same operational shape as Vitals.",badge:t.summary.hasData?`${t.summary.metricCount} daily metrics`:"No daily metrics yet"}),e.jsx(v,{}),t.summary.hasData?e.jsxs(e.Fragment,{children:[e.jsx(b,{swearMetric:l,percentMetric:m,averageRageMetric:o,maxRageMetric:x}),e.jsxs("section",{className:"grid gap-4 xl:grid-cols-4",children:[e.jsx(n,{title:"Devrage count",description:"Raw daily swear count across scanned user messages.",metric:l}),e.jsx(n,{title:"Swearing rate",description:"Percentage of user messages that contained at least one tracked swear.",metric:m}),e.jsx(n,{title:"Average rage peak",description:"Average per-thread peak after swears add and clean messages cool the score down.",metric:o}),e.jsx(n,{title:"Max rage peak",description:"Highest cumulative thread score reached on the latest tracked day.",metric:x}),e.jsxs(i,{className:"rounded-[28px] border border-amber-200/12 bg-[linear-gradient(180deg,rgba(39,31,17,0.96),rgba(19,21,17,0.95))] p-5",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-amber-100/72",children:"Seven-day averages"}),e.jsxs("div",{className:"mt-4 grid gap-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[18px] bg-white/[0.045] px-4 py-3",children:[e.jsx("span",{className:"text-sm text-white/58",children:"Swears"}),e.jsx("span",{className:"text-xl font-semibold text-white",children:r(t.context.weeklyAverage.rawSwearCount)})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[18px] bg-white/[0.045] px-4 py-3",children:[e.jsx("span",{className:"text-sm text-white/58",children:"Swearing messages"}),e.jsx("span",{className:"text-xl font-semibold text-white",children:d(t.context.weeklyAverage.swearingMessagePercent)})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[18px] bg-white/[0.045] px-4 py-3",children:[e.jsx("span",{className:"text-sm text-white/58",children:"Average rage peak"}),e.jsx("span",{className:"text-xl font-semibold text-white",children:r(t.context.weeklyAverage.averageMaxCumulativeRage)})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[18px] bg-white/[0.045] px-4 py-3",children:[e.jsx("span",{className:"text-sm text-white/58",children:"Max rage peak"}),e.jsx("span",{className:"text-xl font-semibold text-white",children:r(t.context.weeklyAverage.maxCumulativeRage)})]})]})]}),e.jsxs(i,{className:"rounded-[28px] border border-white/8 bg-[linear-gradient(180deg,rgba(13,19,37,0.96),rgba(10,14,30,0.96))] p-5",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/40",children:"Stored coverage"}),e.jsxs("div",{className:"mt-3 text-2xl font-semibold text-white",children:[t.summary.trackedDays," days"]}),e.jsxs("div",{className:"mt-3 grid gap-2 text-sm text-white/62",children:[e.jsxs("div",{children:[r(t.context.conversationsScanned)," conversations"]}),e.jsxs("div",{children:[r(t.context.messagesScanned)," user messages"]}),e.jsxs("div",{children:[t.context.sourceCount," source families"]})]})]})]}),e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.1fr)_minmax(340px,0.9fr)]",children:[e.jsxs(i,{className:"overflow-hidden rounded-[30px] border-white/8 bg-[radial-gradient(circle_at_top_left,rgba(251,191,36,0.14),transparent_36%),linear-gradient(180deg,rgba(20,18,31,0.98),rgba(10,13,26,0.98))] p-6",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/40",children:"Coverage"}),e.jsxs("div",{className:"text-2xl font-semibold text-white",children:[t.summary.trackedDays," tracked days across ",t.summary.metricCount," metrics"]}),e.jsx("div",{className:"max-w-3xl text-sm leading-6 text-white/58",children:"Devrage is stored as daily Psyche measurements, so this view reads history from SQLite instead of rescanning conversations during page load."})]}),e.jsxs(h,{className:"bg-white/[0.08] text-white/72",children:["Latest snapshot ",N(t.summary.latestDateKey)]})]}),e.jsx("div",{className:"mt-5 grid gap-3 md:grid-cols-2 xl:grid-cols-3",children:t.summary.categoryBreakdown.map(a=>{const g=k(a.category);return e.jsxs("div",{className:y("rounded-[22px] border bg-white/[0.03] p-4",g.ring),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx(h,{className:g.badge,children:a.category}),e.jsxs("div",{className:"text-xs text-white/44",children:[a.coverageDays," days"]})]}),e.jsx("div",{className:"mt-3 text-2xl font-semibold text-white",children:a.metricCount}),e.jsxs("div",{className:"mt-1 text-sm text-white/58",children:["active metric",a.metricCount===1?"":"s"]})]},a.category)})})]}),e.jsx(i,{className:"rounded-[30px] border-white/8 bg-[linear-gradient(180deg,rgba(13,19,37,0.96),rgba(10,14,30,0.96))] p-6",children:e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/40",children:"Summary statistics"}),e.jsxs("div",{className:"text-lg font-semibold text-white",children:[r(t.context.totalSwears)," total swears across stored history."]}),e.jsxs("div",{className:"grid gap-3 text-sm leading-6 text-white/58",children:[e.jsxs("div",{children:["Daily average: ",r(t.context.dailyAverage.rawSwearCount)," swears, ",d(t.context.dailyAverage.swearingMessagePercent)," swearing messages, and ",r(t.context.dailyAverage.averageMaxCumulativeRage)," average rage peak."]}),e.jsxs("div",{children:["Weekly average: ",r(t.context.weeklyAverage.rawSwearCount)," swears, ",d(t.context.weeklyAverage.swearingMessagePercent)," swearing messages, and ",r(t.context.weeklyAverage.maxCumulativeRage)," max rage peak."]}),e.jsxs("div",{children:[r(t.context.messagesWithSwears)," user messages contained at least one tracked swear."]})]}),e.jsxs("div",{className:"mt-2 rounded-[22px] border border-white/8 bg-white/[0.035] p-4 text-sm text-white/70",children:[t.summary.latestMetricCount," metrics updated on the latest tracked day."]})]})})]}),e.jsx(M,{groups:c})]}):e.jsx(P,{})]})}export{K as PsycheMetricsPage};
1
+ import{j as e}from"./vendor-Cpmju3nw.js";import{i as p}from"./state-BtwEvpO6.js";import{L as u,e as w,bs as v,C as i,k as h,c as y,bV as j}from"./index-BaiwtAgo.js";import{P as f}from"./page-hero-C0MpI3MM.js";import{D as b,S as n,f as N,m as k,M}from"./daily-metrics-dashboard-Jt0nAHU5.js";import"./motion-DwjmC9aq.js";import"./ui-B9O-eUim.js";import"./board-CLOHbg6t.js";import"./forms-C5d5hTf2.js";import"./charts-DwTguE_x.js";function r(s){return new Intl.NumberFormat().format(Math.round(s))}function d(s){return`${s.toFixed(s>=10?1:2)}%`}function C(s){return s.summary.categoryBreakdown.map(t=>({...t,metrics:s.metrics.filter(c=>c.category===t.category)}))}function P(){return e.jsxs(i,{className:"rounded-[30px] border-white/8 bg-[linear-gradient(180deg,rgba(14,20,32,0.96),rgba(9,13,24,0.98))] p-6",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/40",children:"No daily metrics yet"}),e.jsx("div",{className:"mt-2 text-2xl font-semibold text-white",children:"Psyche metrics will appear after the first local backfill finds conversations."}),e.jsx("p",{className:"mt-3 max-w-3xl text-sm leading-6 text-white/58",children:"This surface stays quiet until Forge has stored daily metric rows. It does not run the scanner while rendering the page."})]})}function K(){const s=p({queryKey:["forge-psyche-metrics-view"],queryFn:async()=>(await j()).metrics});if(s.isLoading)return e.jsx(u,{title:"Loading Psyche metrics",description:"Reading stored daily metric rows and summary statistics."});if(s.isError||!s.data)return e.jsx(w,{eyebrow:"Psyche metrics",error:s.error??new Error("Psyche metrics unavailable"),onRetry:()=>void s.refetch()});const t=s.data,c=C(t),l=t.metrics.find(a=>a.metric==="devrageSwearCount")??null,m=t.metrics.find(a=>a.metric==="swearingMessagePercent")??null,o=t.metrics.find(a=>a.metric==="devrageAverageMaxCumulativeRage")??null,x=t.metrics.find(a=>a.metric==="devrageMaxCumulativeRage")??null;return e.jsxs("div",{className:"mx-auto grid w-full max-w-[1380px] gap-5",children:[e.jsx(f,{title:"Psyche Metrics",titleText:"Psyche Metrics",description:"Daily Psyche measurements from stored history, presented with the same operational shape as Vitals.",badge:t.summary.hasData?`${t.summary.metricCount} daily metrics`:"No daily metrics yet"}),e.jsx(v,{}),t.summary.hasData?e.jsxs(e.Fragment,{children:[e.jsx(b,{swearMetric:l,percentMetric:m,averageRageMetric:o,maxRageMetric:x}),e.jsxs("section",{className:"grid gap-4 xl:grid-cols-4",children:[e.jsx(n,{title:"Devrage count",description:"Raw daily swear count across scanned user messages.",metric:l}),e.jsx(n,{title:"Swearing rate",description:"Percentage of user messages that contained at least one tracked swear.",metric:m}),e.jsx(n,{title:"Average rage peak",description:"Average per-thread peak after swears add and clean messages cool the score down.",metric:o}),e.jsx(n,{title:"Max rage peak",description:"Highest cumulative thread score reached on the latest tracked day.",metric:x}),e.jsxs(i,{className:"rounded-[28px] border border-amber-200/12 bg-[linear-gradient(180deg,rgba(39,31,17,0.96),rgba(19,21,17,0.95))] p-5",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-amber-100/72",children:"Seven-day averages"}),e.jsxs("div",{className:"mt-4 grid gap-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[18px] bg-white/[0.045] px-4 py-3",children:[e.jsx("span",{className:"text-sm text-white/58",children:"Swears"}),e.jsx("span",{className:"text-xl font-semibold text-white",children:r(t.context.weeklyAverage.rawSwearCount)})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[18px] bg-white/[0.045] px-4 py-3",children:[e.jsx("span",{className:"text-sm text-white/58",children:"Swearing messages"}),e.jsx("span",{className:"text-xl font-semibold text-white",children:d(t.context.weeklyAverage.swearingMessagePercent)})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[18px] bg-white/[0.045] px-4 py-3",children:[e.jsx("span",{className:"text-sm text-white/58",children:"Average rage peak"}),e.jsx("span",{className:"text-xl font-semibold text-white",children:r(t.context.weeklyAverage.averageMaxCumulativeRage)})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[18px] bg-white/[0.045] px-4 py-3",children:[e.jsx("span",{className:"text-sm text-white/58",children:"Max rage peak"}),e.jsx("span",{className:"text-xl font-semibold text-white",children:r(t.context.weeklyAverage.maxCumulativeRage)})]})]})]}),e.jsxs(i,{className:"rounded-[28px] border border-white/8 bg-[linear-gradient(180deg,rgba(13,19,37,0.96),rgba(10,14,30,0.96))] p-5",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/40",children:"Stored coverage"}),e.jsxs("div",{className:"mt-3 text-2xl font-semibold text-white",children:[t.summary.trackedDays," days"]}),e.jsxs("div",{className:"mt-3 grid gap-2 text-sm text-white/62",children:[e.jsxs("div",{children:[r(t.context.conversationsScanned)," conversations"]}),e.jsxs("div",{children:[r(t.context.messagesScanned)," user messages"]}),e.jsxs("div",{children:[t.context.sourceCount," source families"]})]})]})]}),e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.1fr)_minmax(340px,0.9fr)]",children:[e.jsxs(i,{className:"overflow-hidden rounded-[30px] border-white/8 bg-[radial-gradient(circle_at_top_left,rgba(251,191,36,0.14),transparent_36%),linear-gradient(180deg,rgba(20,18,31,0.98),rgba(10,13,26,0.98))] p-6",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/40",children:"Coverage"}),e.jsxs("div",{className:"text-2xl font-semibold text-white",children:[t.summary.trackedDays," tracked days across ",t.summary.metricCount," metrics"]}),e.jsx("div",{className:"max-w-3xl text-sm leading-6 text-white/58",children:"Devrage is stored as daily Psyche measurements, so this view reads history from SQLite instead of rescanning conversations during page load."})]}),e.jsxs(h,{className:"bg-white/[0.08] text-white/72",children:["Latest snapshot ",N(t.summary.latestDateKey)]})]}),e.jsx("div",{className:"mt-5 grid gap-3 md:grid-cols-2 xl:grid-cols-3",children:t.summary.categoryBreakdown.map(a=>{const g=k(a.category);return e.jsxs("div",{className:y("rounded-[22px] border bg-white/[0.03] p-4",g.ring),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx(h,{className:g.badge,children:a.category}),e.jsxs("div",{className:"text-xs text-white/44",children:[a.coverageDays," days"]})]}),e.jsx("div",{className:"mt-3 text-2xl font-semibold text-white",children:a.metricCount}),e.jsxs("div",{className:"mt-1 text-sm text-white/58",children:["active metric",a.metricCount===1?"":"s"]})]},a.category)})})]}),e.jsx(i,{className:"rounded-[30px] border-white/8 bg-[linear-gradient(180deg,rgba(13,19,37,0.96),rgba(10,14,30,0.96))] p-6",children:e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/40",children:"Summary statistics"}),e.jsxs("div",{className:"text-lg font-semibold text-white",children:[r(t.context.totalSwears)," total swears across stored history."]}),e.jsxs("div",{className:"grid gap-3 text-sm leading-6 text-white/58",children:[e.jsxs("div",{children:["Daily average: ",r(t.context.dailyAverage.rawSwearCount)," swears, ",d(t.context.dailyAverage.swearingMessagePercent)," swearing messages, and ",r(t.context.dailyAverage.averageMaxCumulativeRage)," average rage peak."]}),e.jsxs("div",{children:["Weekly average: ",r(t.context.weeklyAverage.rawSwearCount)," swears, ",d(t.context.weeklyAverage.swearingMessagePercent)," swearing messages, and ",r(t.context.weeklyAverage.maxCumulativeRage)," max rage peak."]}),e.jsxs("div",{children:[r(t.context.messagesWithSwears)," user messages contained at least one tracked swear."]})]}),e.jsxs("div",{className:"mt-2 rounded-[22px] border border-white/8 bg-white/[0.035] p-4 text-sm text-white/70",children:[t.summary.latestMetricCount," metrics updated on the latest tracked day."]})]})})]}),e.jsx(M,{groups:c})]}):e.jsx(P,{})]})}export{K as PsycheMetricsPage};
@@ -1 +1 @@
1
- import{j as e,aC as b}from"./vendor-Cpmju3nw.js";import{j as N,i as k,k as S}from"./state-BtwEvpO6.js";import{u as w}from"./forms-C5d5hTf2.js";import{L as C,e as _,B as d,bs as M,C as r,h as f,k as j,bW as P,bX as q}from"./index-wEZUnRh0.js";import{P as L}from"./page-hero-BRcqE3a4.js";import{m as Q}from"./psyche-schemas-Dtskzvv1.js";import"./motion-DwjmC9aq.js";import"./ui-B9O-eUim.js";import"./board-CLOHbg6t.js";function R(s){return s instanceof Error?s:typeof s=="string"&&s.trim().length>0?new Error(s):new Error("Forge could not complete the requested query collection.")}function E(s){const t=s.find(i=>i.isError);return{isLoading:s.some(i=>i.isPending||i.isLoading),error:t?R(t.error):null}}async function F(s){await Promise.all(s.map(t=>t.refetch()))}const n={copingResponse:[{value:"fight",label:"Fight"},{value:"flight",label:"Flight"},{value:"freeze",label:"Freeze"},{value:"detach",label:"Detach"},{value:"comply",label:"Comply"},{value:"overcompensate",label:"Overcompensate"},{value:"none",label:"Mixed / unsure"}],childState:[{value:"vulnerable",label:"Vulnerable"},{value:"angry",label:"Angry"},{value:"impulsive",label:"Impulsive"},{value:"lonely",label:"Lonely"},{value:"ashamed",label:"Ashamed"},{value:"none",label:"Mixed / unsure"}],criticStyle:[{value:"demanding",label:"Demanding"},{value:"punitive",label:"Punitive"},{value:"none",label:"Neither / unclear"}],healthyContact:[{value:"healthy_adult",label:"Healthy adult"},{value:"happy_child",label:"Happy child"},{value:"none",label:"Hard to access right now"}]};function O(){var p,h,x,g,v,y;const s=N(),t=k({queryKey:["forge-psyche-mode-guide-sessions"],queryFn:q}),i=w({defaultValues:{summary:"What mode was most present in this moment?",copingResponse:"none",childState:"none",criticStyle:"none",healthyContact:"none"}}),o=S({mutationFn:async a=>{const l=Q.parse({summary:a.summary,answers:[{questionKey:"coping_response",value:a.copingResponse},{questionKey:"child_state",value:a.childState},{questionKey:"critic_style",value:a.criticStyle},{questionKey:"healthy_contact",value:a.healthyContact}]});return P(l)},onSuccess:async()=>{await s.invalidateQueries({queryKey:["forge-psyche-mode-guide-sessions"]})}}),u=[t],c=E(u),m=((p=o.data)==null?void 0:p.session)??((x=(h=t.data)==null?void 0:h.sessions)==null?void 0:x[0]);return c.isLoading?e.jsx(C,{eyebrow:"Mode guide",title:"Loading guided sessions",description:"Hydrating previous mode-guide runs and the latest stored readings."}):c.error?e.jsx(_,{eyebrow:"Mode guide",error:c.error,onRetry:()=>void F(u)}):e.jsxs("div",{className:"grid gap-5",children:[e.jsx(L,{eyebrow:"Mode guide",title:"Guided Mode Identification",description:"A short guided pass can help separate coping responses, child states, critic pressure, and whatever healthy contact is still available.",badge:`${((g=t.data)==null?void 0:g.sessions.length)??0} sessions`,actions:e.jsx(b,{to:"/psyche/modes",children:e.jsx(d,{variant:"secondary",children:"Back to mode map"})})}),e.jsx(M,{}),e.jsxs("section",{className:"grid gap-5 xl:grid-cols-[minmax(0,0.9fr)_minmax(0,1.1fr)]",children:[e.jsxs(r,{className:"bg-[var(--ui-surface-section)]",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Guided questionnaire"}),e.jsxs("form",{className:"mt-4 grid gap-5",onSubmit:i.handleSubmit(async a=>o.mutateAsync(a)),children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Prompt"}),e.jsx("input",{className:"w-full rounded-2xl border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-3 text-sm text-[var(--ui-ink-strong)] outline-none placeholder:text-[var(--ui-ink-muted)]",...i.register("summary")})]}),e.jsxs(r,{className:"rounded-[24px] bg-[var(--ui-danger-soft)] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[color-mix(in_srgb,var(--danger)_76%,var(--ui-ink-strong)_24%)]",children:"When the pressure rose, what coping move dominated?"}),e.jsx("div",{className:"mt-3 grid gap-2 sm:grid-cols-2",children:n.copingResponse.map(a=>e.jsxs("label",{className:"flex items-center gap-3 rounded-[18px] bg-[var(--ui-surface-1)] px-4 py-3",children:[e.jsx("input",{type:"radio",value:a.value,...i.register("copingResponse")}),e.jsx("span",{className:"text-[var(--ui-ink-medium)]",children:a.label})]},a.value))})]}),e.jsxs(r,{className:"rounded-[24px] bg-[color-mix(in_srgb,var(--primary)_8%,var(--ui-surface-1)_92%)] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--primary)]",children:"Which child state felt closest?"}),e.jsx("div",{className:"mt-3 grid gap-2 sm:grid-cols-2",children:n.childState.map(a=>e.jsxs("label",{className:"flex items-center gap-3 rounded-[18px] bg-[var(--ui-surface-1)] px-4 py-3",children:[e.jsx("input",{type:"radio",value:a.value,...i.register("childState")}),e.jsx("span",{className:"text-[var(--ui-ink-medium)]",children:a.label})]},a.value))})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs(r,{className:"rounded-[24px] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"What was the critic like?"}),e.jsx("div",{className:"mt-3 grid gap-2",children:n.criticStyle.map(a=>e.jsxs("label",{className:"flex items-center gap-3 rounded-[18px] bg-[var(--ui-surface-1)] px-4 py-3",children:[e.jsx("input",{type:"radio",value:a.value,...i.register("criticStyle")}),e.jsx("span",{className:"text-[var(--ui-ink-medium)]",children:a.label})]},a.value))})]}),e.jsxs(r,{className:"rounded-[24px] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"What healthy contact was still reachable?"}),e.jsx("div",{className:"mt-3 grid gap-2",children:n.healthyContact.map(a=>e.jsxs("label",{className:"flex items-center gap-3 rounded-[18px] bg-[var(--ui-surface-1)] px-4 py-3",children:[e.jsx("input",{type:"radio",value:a.value,...i.register("healthyContact")}),e.jsx("span",{className:"text-[var(--ui-ink-medium)]",children:a.label})]},a.value))})]})]}),e.jsx(d,{type:"submit",children:"Run guide"})]})]}),e.jsxs("div",{className:"grid gap-5",children:[e.jsxs(r,{className:"bg-[var(--ui-surface-section)]",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Latest reading"}),m?e.jsxs("div",{className:"mt-4 grid gap-3",children:[m.results.map(a=>e.jsxs("div",{className:"rounded-[22px] bg-[var(--ui-surface-1)] p-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"font-medium text-[var(--ui-ink-strong)]",children:a.label}),e.jsxs(j,{className:"text-[var(--ui-ink-medium)]",children:[Math.round(a.confidence*100),"%"]})]}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:a.family.replaceAll("_"," ")}),e.jsx("div",{className:"mt-3 text-sm leading-6 text-[var(--ui-ink-medium)]",children:a.reasoning})]},`${a.family}:${a.label}`)),e.jsx(b,{to:"/psyche/modes",children:e.jsx(d,{variant:"secondary",children:"Use this in the mode map"})})]}):e.jsx("div",{className:"mt-4",children:e.jsx(f,{eyebrow:"Guided reading",title:"No guided sessions yet",description:"Run the guide once to separate coping response, child state, critic pressure, and reachable healthy contact."})})]}),e.jsxs(r,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Session history"}),e.jsx("div",{className:"mt-4 grid gap-3",children:(((v=t.data)==null?void 0:v.sessions)??[]).length===0?e.jsx(f,{eyebrow:"Session history",title:"No stored guide history",description:"Completed guide sessions will accumulate here so later mode-map work can build from real prior readings."}):(((y=t.data)==null?void 0:y.sessions)??[]).map(a=>e.jsxs("div",{className:"rounded-[20px] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"font-medium text-[var(--ui-ink-strong)]",children:a.summary}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:a.results.map(l=>e.jsx(j,{className:"text-[var(--ui-ink-medium)]",children:l.label},`${a.id}:${l.label}`))})]},a.id))})]})]})]})]})}export{O as PsycheModeGuidePage};
1
+ import{j as e,aC as b}from"./vendor-Cpmju3nw.js";import{j as N,i as k,k as S}from"./state-BtwEvpO6.js";import{u as w}from"./forms-C5d5hTf2.js";import{L as C,e as _,B as d,bs as M,C as r,h as f,k as j,bW as P,bX as q}from"./index-BaiwtAgo.js";import{P as L}from"./page-hero-C0MpI3MM.js";import{m as Q}from"./psyche-schemas-Dtskzvv1.js";import"./motion-DwjmC9aq.js";import"./ui-B9O-eUim.js";import"./board-CLOHbg6t.js";function R(s){return s instanceof Error?s:typeof s=="string"&&s.trim().length>0?new Error(s):new Error("Forge could not complete the requested query collection.")}function E(s){const t=s.find(i=>i.isError);return{isLoading:s.some(i=>i.isPending||i.isLoading),error:t?R(t.error):null}}async function F(s){await Promise.all(s.map(t=>t.refetch()))}const n={copingResponse:[{value:"fight",label:"Fight"},{value:"flight",label:"Flight"},{value:"freeze",label:"Freeze"},{value:"detach",label:"Detach"},{value:"comply",label:"Comply"},{value:"overcompensate",label:"Overcompensate"},{value:"none",label:"Mixed / unsure"}],childState:[{value:"vulnerable",label:"Vulnerable"},{value:"angry",label:"Angry"},{value:"impulsive",label:"Impulsive"},{value:"lonely",label:"Lonely"},{value:"ashamed",label:"Ashamed"},{value:"none",label:"Mixed / unsure"}],criticStyle:[{value:"demanding",label:"Demanding"},{value:"punitive",label:"Punitive"},{value:"none",label:"Neither / unclear"}],healthyContact:[{value:"healthy_adult",label:"Healthy adult"},{value:"happy_child",label:"Happy child"},{value:"none",label:"Hard to access right now"}]};function O(){var p,h,x,g,v,y;const s=N(),t=k({queryKey:["forge-psyche-mode-guide-sessions"],queryFn:q}),i=w({defaultValues:{summary:"What mode was most present in this moment?",copingResponse:"none",childState:"none",criticStyle:"none",healthyContact:"none"}}),o=S({mutationFn:async a=>{const l=Q.parse({summary:a.summary,answers:[{questionKey:"coping_response",value:a.copingResponse},{questionKey:"child_state",value:a.childState},{questionKey:"critic_style",value:a.criticStyle},{questionKey:"healthy_contact",value:a.healthyContact}]});return P(l)},onSuccess:async()=>{await s.invalidateQueries({queryKey:["forge-psyche-mode-guide-sessions"]})}}),u=[t],c=E(u),m=((p=o.data)==null?void 0:p.session)??((x=(h=t.data)==null?void 0:h.sessions)==null?void 0:x[0]);return c.isLoading?e.jsx(C,{eyebrow:"Mode guide",title:"Loading guided sessions",description:"Hydrating previous mode-guide runs and the latest stored readings."}):c.error?e.jsx(_,{eyebrow:"Mode guide",error:c.error,onRetry:()=>void F(u)}):e.jsxs("div",{className:"grid gap-5",children:[e.jsx(L,{eyebrow:"Mode guide",title:"Guided Mode Identification",description:"A short guided pass can help separate coping responses, child states, critic pressure, and whatever healthy contact is still available.",badge:`${((g=t.data)==null?void 0:g.sessions.length)??0} sessions`,actions:e.jsx(b,{to:"/psyche/modes",children:e.jsx(d,{variant:"secondary",children:"Back to mode map"})})}),e.jsx(M,{}),e.jsxs("section",{className:"grid gap-5 xl:grid-cols-[minmax(0,0.9fr)_minmax(0,1.1fr)]",children:[e.jsxs(r,{className:"bg-[var(--ui-surface-section)]",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Guided questionnaire"}),e.jsxs("form",{className:"mt-4 grid gap-5",onSubmit:i.handleSubmit(async a=>o.mutateAsync(a)),children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Prompt"}),e.jsx("input",{className:"w-full rounded-2xl border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-3 text-sm text-[var(--ui-ink-strong)] outline-none placeholder:text-[var(--ui-ink-muted)]",...i.register("summary")})]}),e.jsxs(r,{className:"rounded-[24px] bg-[var(--ui-danger-soft)] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[color-mix(in_srgb,var(--danger)_76%,var(--ui-ink-strong)_24%)]",children:"When the pressure rose, what coping move dominated?"}),e.jsx("div",{className:"mt-3 grid gap-2 sm:grid-cols-2",children:n.copingResponse.map(a=>e.jsxs("label",{className:"flex items-center gap-3 rounded-[18px] bg-[var(--ui-surface-1)] px-4 py-3",children:[e.jsx("input",{type:"radio",value:a.value,...i.register("copingResponse")}),e.jsx("span",{className:"text-[var(--ui-ink-medium)]",children:a.label})]},a.value))})]}),e.jsxs(r,{className:"rounded-[24px] bg-[color-mix(in_srgb,var(--primary)_8%,var(--ui-surface-1)_92%)] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--primary)]",children:"Which child state felt closest?"}),e.jsx("div",{className:"mt-3 grid gap-2 sm:grid-cols-2",children:n.childState.map(a=>e.jsxs("label",{className:"flex items-center gap-3 rounded-[18px] bg-[var(--ui-surface-1)] px-4 py-3",children:[e.jsx("input",{type:"radio",value:a.value,...i.register("childState")}),e.jsx("span",{className:"text-[var(--ui-ink-medium)]",children:a.label})]},a.value))})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs(r,{className:"rounded-[24px] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"What was the critic like?"}),e.jsx("div",{className:"mt-3 grid gap-2",children:n.criticStyle.map(a=>e.jsxs("label",{className:"flex items-center gap-3 rounded-[18px] bg-[var(--ui-surface-1)] px-4 py-3",children:[e.jsx("input",{type:"radio",value:a.value,...i.register("criticStyle")}),e.jsx("span",{className:"text-[var(--ui-ink-medium)]",children:a.label})]},a.value))})]}),e.jsxs(r,{className:"rounded-[24px] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"What healthy contact was still reachable?"}),e.jsx("div",{className:"mt-3 grid gap-2",children:n.healthyContact.map(a=>e.jsxs("label",{className:"flex items-center gap-3 rounded-[18px] bg-[var(--ui-surface-1)] px-4 py-3",children:[e.jsx("input",{type:"radio",value:a.value,...i.register("healthyContact")}),e.jsx("span",{className:"text-[var(--ui-ink-medium)]",children:a.label})]},a.value))})]})]}),e.jsx(d,{type:"submit",children:"Run guide"})]})]}),e.jsxs("div",{className:"grid gap-5",children:[e.jsxs(r,{className:"bg-[var(--ui-surface-section)]",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Latest reading"}),m?e.jsxs("div",{className:"mt-4 grid gap-3",children:[m.results.map(a=>e.jsxs("div",{className:"rounded-[22px] bg-[var(--ui-surface-1)] p-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"font-medium text-[var(--ui-ink-strong)]",children:a.label}),e.jsxs(j,{className:"text-[var(--ui-ink-medium)]",children:[Math.round(a.confidence*100),"%"]})]}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:a.family.replaceAll("_"," ")}),e.jsx("div",{className:"mt-3 text-sm leading-6 text-[var(--ui-ink-medium)]",children:a.reasoning})]},`${a.family}:${a.label}`)),e.jsx(b,{to:"/psyche/modes",children:e.jsx(d,{variant:"secondary",children:"Use this in the mode map"})})]}):e.jsx("div",{className:"mt-4",children:e.jsx(f,{eyebrow:"Guided reading",title:"No guided sessions yet",description:"Run the guide once to separate coping response, child state, critic pressure, and reachable healthy contact."})})]}),e.jsxs(r,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Session history"}),e.jsx("div",{className:"mt-4 grid gap-3",children:(((v=t.data)==null?void 0:v.sessions)??[]).length===0?e.jsx(f,{eyebrow:"Session history",title:"No stored guide history",description:"Completed guide sessions will accumulate here so later mode-map work can build from real prior readings."}):(((y=t.data)==null?void 0:y.sessions)??[]).map(a=>e.jsxs("div",{className:"rounded-[20px] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"font-medium text-[var(--ui-ink-strong)]",children:a.summary}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:a.results.map(l=>e.jsx(j,{className:"text-[var(--ui-ink-medium)]",children:l.label},`${a.id}:${l.label}`))})]},a.id))})]})]})]})]})}export{O as PsycheModeGuidePage};
@@ -1 +1 @@
1
- import{j as t,bY as re,r as b}from"./vendor-Cpmju3nw.js";import{j as ae,i as I,k as se}from"./state-BtwEvpO6.js";import{Q as ie,F as i}from"./question-flow-dialog-Dsnsc8be.js";import{E as oe}from"./entity-note-count-link-CmRRdXAr.js";import{A as ne}from"./atlas-panel-Dinteouh.js";import{E as S}from"./entity-link-multiselect-DZZjpL_d.js";import{c as le,d as de,L as ce,e as he,B as C,E as q,bs as pe,k as ue,b as me,R as ge,bY as ye,bQ as be,I as P,T as m,bO as fe,bN as ve,bP as xe,b7 as ke,b4 as je,b5 as we,b3 as Ie}from"./index-wEZUnRh0.js";import{u as Ce,p as Pe}from"./use-psyche-focus-target-Cuxni3SK.js";import{P as Se}from"./page-hero-BRcqE3a4.js";import{U as Me}from"./user-select-field-BNqv8-wd.js";import{p as M}from"./query-cache-IQ8W-LNC.js";import{a as K}from"./psyche-schemas-Dtskzvv1.js";import{g as Ee,b as E,d as N,e as F,a as Ne}from"./user-ownership-DJGl4rAj.js";import"./ui-B9O-eUim.js";import"./motion-DwjmC9aq.js";import"./use-anchored-overlay-position-BrQ4cqKn.js";import"./board-CLOHbg6t.js";import"./forms-C5d5hTf2.js";const Fe={coping:"bg-[rgba(251,113,133,0.16)] text-rose-100",child:"bg-[rgba(125,211,252,0.16)] text-sky-100",critic_parent:"bg-[rgba(196,181,253,0.16)] text-violet-100",healthy_adult:"bg-[rgba(110,231,183,0.16)] text-emerald-100",happy_child:"bg-[rgba(251,191,36,0.16)] text-amber-100"};function Le({family:s,label:o,className:h}){return t.jsx("span",{className:le("inline-flex items-center rounded-full px-3 py-1.5 text-xs",Fe[s],h),children:o})}const g={family:"coping",archetype:"",title:"",persona:"",imagery:"",symbolicForm:"",facialExpression:"",fear:"",burden:"",protectiveJob:"",originContext:"",firstAppearanceAt:null,linkedPatternIds:[],linkedBehaviorIds:[],linkedValueIds:[],userId:null};function Te(s){return{family:s.family,archetype:s.archetype,title:s.title,persona:s.persona,imagery:s.imagery,symbolicForm:s.symbolicForm,facialExpression:s.facialExpression,fear:s.fear,burden:s.burden,protectiveJob:s.protectiveJob,originContext:s.originContext,firstAppearanceAt:s.firstAppearanceAt,linkedPatternIds:s.linkedPatternIds,linkedBehaviorIds:s.linkedBehaviorIds,linkedValueIds:s.linkedValueIds,userId:s.userId??null}}const L={coping:"Coping",child:"Child",critic_parent:"Critic / parent",healthy_adult:"Healthy adult",happy_child:"Happy child"};function Xe(){var D,O,H,Q;const s=de(),o=ae(),[h,T]=re(),[U,n]=b.useState(!1),[p,u]=b.useState(null),[y,l]=b.useState(g),[R,f]=b.useState(null),v=I({queryKey:["forge-psyche-modes"],queryFn:ke}),x=I({queryKey:["forge-psyche-patterns"],queryFn:je}),k=I({queryKey:["forge-psyche-behaviors"],queryFn:we}),j=I({queryKey:["forge-psyche-values"],queryFn:Ie}),d=((D=v.data)==null?void 0:D.modes)??[],z=((O=x.data)==null?void 0:O.patterns)??[],J=((H=k.data)==null?void 0:H.behaviors)??[],G=((Q=j.data)==null?void 0:Q.values)??[],c=Ee(s.selectedUserIds),B=h.get("focus"),$=s.snapshot.dashboard.notesSummaryByEntity;Ce(B),b.useEffect(()=>{if(h.get("create")==="1"){n(!0),u(null),l({...g,userId:c});const e=new URLSearchParams(h);e.delete("create"),T(e,{replace:!0})}},[c,h,T]);const A=se({mutationFn:async e=>{const r=K.parse(e);return p?ye(p.id,r):be(r)},onSuccess:async()=>{n(!1),u(null),l({...g,userId:c}),f(null),await Promise.all([o.invalidateQueries({queryKey:["forge-psyche-modes"]}),o.invalidateQueries({queryKey:["forge-psyche-overview"]})])}}),V=z.map(e=>({value:e.id,label:F(e.title,e.user),description:N(e.preferredResponse||e.targetBehavior,e.user),searchText:E([e.title,e.preferredResponse,e.targetBehavior,e.description],e),kind:"pattern"})),Y=J.map(e=>({value:e.id,label:F(e.title,e.user),description:N(e.kind,e.user),searchText:E([e.title,e.kind,e.description],e),kind:"behavior"})),W=G.map(e=>({value:e.id,label:F(e.title,e.user),description:N(e.valuedDirection,e.user),searchText:E([e.title,e.valuedDirection,e.description],e),kind:"value"})),X=async e=>{const{pattern:r}=await fe({title:e,description:"",targetBehavior:e,cueContexts:[],shortTermPayoff:"",longTermCost:"",preferredResponse:"",linkedValueIds:[],linkedSchemaLabels:[],linkedModeIds:[],linkedBeliefIds:[],userId:y.userId});return M(o,["forge-psyche-patterns"],"patterns",r),await o.invalidateQueries({queryKey:["forge-psyche-overview"]}),{value:r.id,label:r.title,description:r.preferredResponse||r.targetBehavior,kind:"pattern"}},Z=async e=>{const{behavior:r}=await ve({kind:"away",title:e,description:"",commonCues:[],urgeStory:"",shortTermPayoff:"",longTermCost:"",replacementMove:"",repairPlan:"",linkedPatternIds:[],linkedValueIds:[],linkedSchemaIds:[],linkedModeIds:[],userId:y.userId});return M(o,["forge-psyche-behaviors"],"behaviors",r),await o.invalidateQueries({queryKey:["forge-psyche-overview"]}),{value:r.id,label:r.title,description:r.kind,kind:"behavior"}},ee=async e=>{const{value:r}=await xe({title:e,description:"",valuedDirection:e,whyItMatters:"",linkedGoalIds:[],linkedProjectIds:[],linkedTaskIds:[],committedActions:[],userId:y.userId});return M(o,["forge-psyche-values"],"values",r),await o.invalidateQueries({queryKey:["forge-psyche-overview"]}),{value:r.id,label:r.title,description:r.valuedDirection,kind:"value"}},te=[{id:"identity",eyebrow:"Identity",title:"Name the cast member and place it in the right family",description:"Start with the mode itself: who it feels like, what family it belongs to, and the recognizable role it plays.",render:(e,r)=>t.jsxs(t.Fragment,{children:[t.jsx(Me,{value:e.userId??null,users:s.snapshot.users,onChange:a=>r({userId:a}),defaultLabel:Ne(s.snapshot.users.find(a=>a.id===c)??null,"Choose mode owner"),help:"Modes can belong to a human or bot user while still linking across shared patterns, behaviors, and values."}),t.jsx(i,{label:"Mode family",description:"Choose the broader inner family this mode belongs to.",labelHelp:"A mode family is the bigger cluster this state belongs to, like a coping part, a vulnerable child state, or a healthy adult response.",children:t.jsx("div",{className:"grid gap-3 md:grid-cols-3",children:["coping","child","critic_parent","healthy_adult","happy_child"].map(a=>t.jsx("button",{type:"button",className:`rounded-[22px] border px-4 py-4 text-left transition ${e.family===a?"border-[var(--ui-border-strong)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-strong)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-soft)] hover:bg-[var(--ui-surface-hover)]"}`,onClick:()=>r({family:a}),children:L[a]},a))})}),t.jsx(i,{label:"Mode name",description:"Give it a memorable name you would instantly recognize later.",labelHelp:"This is the user-facing name of the mode. It should read like a cast member title, not a clinical record.",children:t.jsx(P,{value:e.title,onChange:a=>r({title:a.target.value}),placeholder:"The Friday Vigil, The Scanner, The Good Son"})}),t.jsx(i,{label:"Archetype",description:"Name the recognizable inner role or pattern this mode most resembles.",labelHelp:"An archetype is the role this mode tends to play, like a protector, a critic, a frightened child, or a calm adult anchor.",children:t.jsx(P,{value:e.archetype,onChange:a=>r({archetype:a.target.value}),placeholder:"Detached protector, vulnerable child, demanding critic"})})]})},{id:"texture",eyebrow:"Texture",title:"Give the mode a recognizable presence",description:"Imagery, facial expression, and persona should make the mode instantly memorable.",render:(e,r)=>t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[t.jsx(i,{label:"Persona",description:"Describe how this mode sounds, moves, and carries itself.",labelHelp:"Persona is the tone, posture, and voice of the mode. Imagine how it enters the room and how it speaks.",children:t.jsx(m,{value:e.persona,onChange:a=>r({persona:a.target.value}),placeholder:"Quiet, hyper-alert, always scanning for threat and trying to stay one step ahead."})}),t.jsx(i,{label:"Imagery",description:"Capture the mental image or scene that helps this mode feel vivid.",labelHelp:"Imagery is the picture that makes the mode easy to remember, like a scene, posture, weather pattern, or atmosphere.",children:t.jsx(m,{value:e.imagery,onChange:a=>r({imagery:a.target.value}),placeholder:"A night watchman under cold fluorescent light, pacing and checking every door twice."})})]}),t.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[t.jsx(i,{label:"Symbolic form",description:"Pick the object, creature, or shape that best symbolizes this mode.",labelHelp:"Symbolic form is the metaphor for the mode, like armor, a fox, a storm front, or a glass wall.",children:t.jsx(P,{value:e.symbolicForm,onChange:a=>r({symbolicForm:a.target.value}),placeholder:"A locked visor, a fox, a steel shield"})}),t.jsx(i,{label:"Facial expression",description:"Describe what you would see on the mode's face if it took over.",labelHelp:"This is the visible emotional expression of the mode: tight jaw, blank stare, pleading eyes, or calm grounded attention.",children:t.jsx(P,{value:e.facialExpression,onChange:a=>r({facialExpression:a.target.value}),placeholder:"Tight jaw, narrowed eyes, forced calm"})})]})]})},{id:"burden",eyebrow:"Burden",title:"Map fear, burden, job, and origin",description:"This is what turns a named mode into a readable inner-state profile.",render:(e,r)=>t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[t.jsx(i,{label:"Fear",description:"Name the threat this mode is trying hard to prevent.",labelHelp:"Fear is the danger the mode believes it must protect you from, such as rejection, shame, collapse, failure, or being trapped.",children:t.jsx(m,{value:e.fear,onChange:a=>r({fear:a.target.value}),placeholder:"If I relax, I will miss the threat and get hurt."})}),t.jsx(i,{label:"Burden",description:"Describe the emotional weight or exhausting role this mode keeps carrying.",labelHelp:"Burden is the heavy job or emotional load the mode feels stuck holding, even when it costs a lot.",children:t.jsx(m,{value:e.burden,onChange:a=>r({burden:a.target.value}),placeholder:"It believes it must never let the guard down, even when that means constant tension."})}),t.jsx(i,{label:"Protective job",description:"Describe the job this mode thinks it is performing for you.",labelHelp:"Protective job is the function the mode is trying to serve, like preventing rejection, keeping control, stopping humiliation, or preserving closeness.",children:t.jsx(m,{value:e.protectiveJob,onChange:a=>r({protectiveJob:a.target.value}),placeholder:"Keeps me prepared so I never get blindsided or look naive."})})]}),t.jsx(i,{label:"Origin context",description:"Describe when this mode first became useful or understandable.",labelHelp:"Origin context is the stretch of life where this mode likely learned its job or became especially necessary.",children:t.jsx(m,{value:e.originContext,onChange:a=>r({originContext:a.target.value}),placeholder:"Started getting stronger during adolescence when mistakes were met with criticism and unpredictability."})})]})},{id:"links",eyebrow:"Links",title:"Attach the mode to the rest of the psyche system",description:"Modes should connect to patterns, behaviors, and values, not sit in isolation.",render:(e,r)=>t.jsxs(t.Fragment,{children:[t.jsx(i,{label:"Linked patterns",description:"Choose the loops this mode tends to activate or maintain.",children:t.jsx(S,{options:V,selectedValues:e.linkedPatternIds,onChange:a=>r({linkedPatternIds:a}),placeholder:"Search or create a pattern…",emptyMessage:"No patterns match yet.",createLabel:"Create pattern",onCreate:X})}),t.jsx(i,{label:"Linked behaviors",description:"Choose the moves this mode tends to trigger, justify, or amplify.",children:t.jsx(S,{options:Y,selectedValues:e.linkedBehaviorIds,onChange:a=>r({linkedBehaviorIds:a}),placeholder:"Search or create a behavior…",emptyMessage:"No behaviors match yet.",createLabel:"Create behavior",onCreate:Z})}),t.jsx(i,{label:"Colliding values",description:"Choose the valued directions this mode most often interrupts.",labelHelp:"These are the values that get obscured, sidelined, or distorted when this mode takes over.",children:t.jsx(S,{options:W,selectedValues:e.linkedValueIds,onChange:a=>r({linkedValueIds:a}),placeholder:"Search or create a value…",emptyMessage:"No values match yet.",createLabel:"Create value",onCreate:ee})})]})}];if(v.isLoading||x.isLoading||k.isLoading||j.isLoading)return t.jsx(ce,{eyebrow:"Modes",title:"Loading modes",description:"Getting modes, linked patterns, behaviors, and values ready."});const _=v.error??x.error??k.error??j.error;if(_)return t.jsx(he,{eyebrow:"Modes",error:_,onRetry:()=>void Promise.all([v.refetch(),x.refetch(),k.refetch(),j.refetch()])});const w={coping:d.filter(e=>e.family==="coping"),child:d.filter(e=>e.family==="child"),critic_parent:d.filter(e=>e.family==="critic_parent"),healthy_adult:d.filter(e=>e.family==="healthy_adult"),happy_child:d.filter(e=>e.family==="happy_child")};return t.jsxs("div",{className:"grid gap-5",children:[t.jsx(Se,{entityKind:"mode",title:t.jsx(q,{kind:"mode",label:"Modes",variant:"heading",size:"lg"}),description:"Modes should look and feel like a cast of inner states with identity, burden, and relational links, not a flat list of records.",badge:`${d.length} modes`,actions:t.jsx(C,{onClick:()=>{u(null),l({...g,userId:c}),n(!0)},children:"Add mode"})}),t.jsx(pe,{}),t.jsx(ne,{eyebrow:"Mode families",title:"Modes by family",description:"Use these groups to see which modes show up most often, what role they play, and what they are connected to.",tone:"violet",children:d.length===0?t.jsx("div",{className:"flex justify-start",children:t.jsx(C,{onClick:()=>{u(null),l({...g,userId:c}),n(!0)},children:"Add mode"})}):t.jsx("div",{className:"grid gap-4 xl:grid-cols-2",children:Object.keys(w).map(e=>t.jsxs("div",{className:"grid gap-3 rounded-[26px] bg-[var(--ui-surface-1)] p-4",children:[t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[t.jsx(Le,{family:e,label:L[e]}),t.jsx(ue,{children:w[e].length})]}),w[e].length===0?t.jsx("div",{className:"flex",children:t.jsxs(C,{variant:"secondary",onClick:()=>{u(null),l({...g,userId:c}),n(!0)},children:["Add ",L[e].toLowerCase()]})}):w[e].map(r=>t.jsxs("div",{"data-psyche-focus-id":r.id,className:`rounded-[22px] bg-[var(--ui-surface-1)] p-4 text-left transition hover:bg-[var(--ui-surface-2)] ${Pe(B===r.id)}`,children:[t.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[t.jsxs("div",{children:[t.jsx(me,{kind:"mode",compact:!0,gradient:!1}),t.jsx(q,{kind:"mode",label:r.title,variant:"heading",size:"lg"})]}),t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx(oe,{entityType:"mode_profile",entityId:r.id,count:ge($,"mode_profile",r.id).count}),t.jsx(C,{variant:"secondary",size:"sm",onClick:()=>{u(r),l(Te(r)),n(!0)},children:"Edit"})]})]}),t.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:r.archetype}),t.jsx("div",{className:"mt-3 text-sm leading-6 text-[var(--ui-ink-soft)]",children:r.persona||r.protectiveJob||"Open the mode to add persona and protective details."})]},r.id))]},e))})}),t.jsx(ie,{open:U,onOpenChange:n,eyebrow:"Mode",title:p?"Refine cast member":"Create mode",description:"Use this guided flow to define the mode, how it shows up, what it is protecting, and where it comes from.",value:y,onChange:l,draftPersistenceKey:p?`psyche.mode.${p.id}`:"psyche.mode.new",steps:te,submitLabel:p?"Save mode":"Create mode",pending:A.isPending,error:R,onSubmit:async()=>{f(null);const e=K.safeParse(y);if(!e.success){f("This mode still needs a family and a name before it can be saved.");return}try{await A.mutateAsync(e.data)}catch(r){f(r instanceof Error?r.message:"Unable to save this mode right now.")}}})]})}export{Xe as PsycheModesPage};
1
+ import{j as t,bY as re,r as b}from"./vendor-Cpmju3nw.js";import{j as ae,i as I,k as se}from"./state-BtwEvpO6.js";import{Q as ie,F as i}from"./question-flow-dialog-Bj4PxpjS.js";import{E as oe}from"./entity-note-count-link-BzWnsOmI.js";import{A as ne}from"./atlas-panel-BFUeVT69.js";import{E as S}from"./entity-link-multiselect-Bb4De_e3.js";import{c as le,d as de,L as ce,e as he,B as C,E as q,bs as pe,k as ue,b as me,R as ge,bY as ye,bQ as be,I as P,T as m,bO as fe,bN as ve,bP as xe,b7 as ke,b4 as je,b5 as we,b3 as Ie}from"./index-BaiwtAgo.js";import{u as Ce,p as Pe}from"./use-psyche-focus-target-Cuxni3SK.js";import{P as Se}from"./page-hero-C0MpI3MM.js";import{U as Me}from"./user-select-field-BNqv8-wd.js";import{p as M}from"./query-cache-IQ8W-LNC.js";import{a as K}from"./psyche-schemas-Dtskzvv1.js";import{g as Ee,b as E,d as N,e as F,a as Ne}from"./user-ownership-DJGl4rAj.js";import"./ui-B9O-eUim.js";import"./motion-DwjmC9aq.js";import"./use-anchored-overlay-position-BrQ4cqKn.js";import"./board-CLOHbg6t.js";import"./forms-C5d5hTf2.js";const Fe={coping:"bg-[rgba(251,113,133,0.16)] text-rose-100",child:"bg-[rgba(125,211,252,0.16)] text-sky-100",critic_parent:"bg-[rgba(196,181,253,0.16)] text-violet-100",healthy_adult:"bg-[rgba(110,231,183,0.16)] text-emerald-100",happy_child:"bg-[rgba(251,191,36,0.16)] text-amber-100"};function Le({family:s,label:o,className:h}){return t.jsx("span",{className:le("inline-flex items-center rounded-full px-3 py-1.5 text-xs",Fe[s],h),children:o})}const g={family:"coping",archetype:"",title:"",persona:"",imagery:"",symbolicForm:"",facialExpression:"",fear:"",burden:"",protectiveJob:"",originContext:"",firstAppearanceAt:null,linkedPatternIds:[],linkedBehaviorIds:[],linkedValueIds:[],userId:null};function Te(s){return{family:s.family,archetype:s.archetype,title:s.title,persona:s.persona,imagery:s.imagery,symbolicForm:s.symbolicForm,facialExpression:s.facialExpression,fear:s.fear,burden:s.burden,protectiveJob:s.protectiveJob,originContext:s.originContext,firstAppearanceAt:s.firstAppearanceAt,linkedPatternIds:s.linkedPatternIds,linkedBehaviorIds:s.linkedBehaviorIds,linkedValueIds:s.linkedValueIds,userId:s.userId??null}}const L={coping:"Coping",child:"Child",critic_parent:"Critic / parent",healthy_adult:"Healthy adult",happy_child:"Happy child"};function Xe(){var D,O,H,Q;const s=de(),o=ae(),[h,T]=re(),[U,n]=b.useState(!1),[p,u]=b.useState(null),[y,l]=b.useState(g),[R,f]=b.useState(null),v=I({queryKey:["forge-psyche-modes"],queryFn:ke}),x=I({queryKey:["forge-psyche-patterns"],queryFn:je}),k=I({queryKey:["forge-psyche-behaviors"],queryFn:we}),j=I({queryKey:["forge-psyche-values"],queryFn:Ie}),d=((D=v.data)==null?void 0:D.modes)??[],z=((O=x.data)==null?void 0:O.patterns)??[],J=((H=k.data)==null?void 0:H.behaviors)??[],G=((Q=j.data)==null?void 0:Q.values)??[],c=Ee(s.selectedUserIds),B=h.get("focus"),$=s.snapshot.dashboard.notesSummaryByEntity;Ce(B),b.useEffect(()=>{if(h.get("create")==="1"){n(!0),u(null),l({...g,userId:c});const e=new URLSearchParams(h);e.delete("create"),T(e,{replace:!0})}},[c,h,T]);const A=se({mutationFn:async e=>{const r=K.parse(e);return p?ye(p.id,r):be(r)},onSuccess:async()=>{n(!1),u(null),l({...g,userId:c}),f(null),await Promise.all([o.invalidateQueries({queryKey:["forge-psyche-modes"]}),o.invalidateQueries({queryKey:["forge-psyche-overview"]})])}}),V=z.map(e=>({value:e.id,label:F(e.title,e.user),description:N(e.preferredResponse||e.targetBehavior,e.user),searchText:E([e.title,e.preferredResponse,e.targetBehavior,e.description],e),kind:"pattern"})),Y=J.map(e=>({value:e.id,label:F(e.title,e.user),description:N(e.kind,e.user),searchText:E([e.title,e.kind,e.description],e),kind:"behavior"})),W=G.map(e=>({value:e.id,label:F(e.title,e.user),description:N(e.valuedDirection,e.user),searchText:E([e.title,e.valuedDirection,e.description],e),kind:"value"})),X=async e=>{const{pattern:r}=await fe({title:e,description:"",targetBehavior:e,cueContexts:[],shortTermPayoff:"",longTermCost:"",preferredResponse:"",linkedValueIds:[],linkedSchemaLabels:[],linkedModeIds:[],linkedBeliefIds:[],userId:y.userId});return M(o,["forge-psyche-patterns"],"patterns",r),await o.invalidateQueries({queryKey:["forge-psyche-overview"]}),{value:r.id,label:r.title,description:r.preferredResponse||r.targetBehavior,kind:"pattern"}},Z=async e=>{const{behavior:r}=await ve({kind:"away",title:e,description:"",commonCues:[],urgeStory:"",shortTermPayoff:"",longTermCost:"",replacementMove:"",repairPlan:"",linkedPatternIds:[],linkedValueIds:[],linkedSchemaIds:[],linkedModeIds:[],userId:y.userId});return M(o,["forge-psyche-behaviors"],"behaviors",r),await o.invalidateQueries({queryKey:["forge-psyche-overview"]}),{value:r.id,label:r.title,description:r.kind,kind:"behavior"}},ee=async e=>{const{value:r}=await xe({title:e,description:"",valuedDirection:e,whyItMatters:"",linkedGoalIds:[],linkedProjectIds:[],linkedTaskIds:[],committedActions:[],userId:y.userId});return M(o,["forge-psyche-values"],"values",r),await o.invalidateQueries({queryKey:["forge-psyche-overview"]}),{value:r.id,label:r.title,description:r.valuedDirection,kind:"value"}},te=[{id:"identity",eyebrow:"Identity",title:"Name the cast member and place it in the right family",description:"Start with the mode itself: who it feels like, what family it belongs to, and the recognizable role it plays.",render:(e,r)=>t.jsxs(t.Fragment,{children:[t.jsx(Me,{value:e.userId??null,users:s.snapshot.users,onChange:a=>r({userId:a}),defaultLabel:Ne(s.snapshot.users.find(a=>a.id===c)??null,"Choose mode owner"),help:"Modes can belong to a human or bot user while still linking across shared patterns, behaviors, and values."}),t.jsx(i,{label:"Mode family",description:"Choose the broader inner family this mode belongs to.",labelHelp:"A mode family is the bigger cluster this state belongs to, like a coping part, a vulnerable child state, or a healthy adult response.",children:t.jsx("div",{className:"grid gap-3 md:grid-cols-3",children:["coping","child","critic_parent","healthy_adult","happy_child"].map(a=>t.jsx("button",{type:"button",className:`rounded-[22px] border px-4 py-4 text-left transition ${e.family===a?"border-[var(--ui-border-strong)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-strong)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-soft)] hover:bg-[var(--ui-surface-hover)]"}`,onClick:()=>r({family:a}),children:L[a]},a))})}),t.jsx(i,{label:"Mode name",description:"Give it a memorable name you would instantly recognize later.",labelHelp:"This is the user-facing name of the mode. It should read like a cast member title, not a clinical record.",children:t.jsx(P,{value:e.title,onChange:a=>r({title:a.target.value}),placeholder:"The Friday Vigil, The Scanner, The Good Son"})}),t.jsx(i,{label:"Archetype",description:"Name the recognizable inner role or pattern this mode most resembles.",labelHelp:"An archetype is the role this mode tends to play, like a protector, a critic, a frightened child, or a calm adult anchor.",children:t.jsx(P,{value:e.archetype,onChange:a=>r({archetype:a.target.value}),placeholder:"Detached protector, vulnerable child, demanding critic"})})]})},{id:"texture",eyebrow:"Texture",title:"Give the mode a recognizable presence",description:"Imagery, facial expression, and persona should make the mode instantly memorable.",render:(e,r)=>t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[t.jsx(i,{label:"Persona",description:"Describe how this mode sounds, moves, and carries itself.",labelHelp:"Persona is the tone, posture, and voice of the mode. Imagine how it enters the room and how it speaks.",children:t.jsx(m,{value:e.persona,onChange:a=>r({persona:a.target.value}),placeholder:"Quiet, hyper-alert, always scanning for threat and trying to stay one step ahead."})}),t.jsx(i,{label:"Imagery",description:"Capture the mental image or scene that helps this mode feel vivid.",labelHelp:"Imagery is the picture that makes the mode easy to remember, like a scene, posture, weather pattern, or atmosphere.",children:t.jsx(m,{value:e.imagery,onChange:a=>r({imagery:a.target.value}),placeholder:"A night watchman under cold fluorescent light, pacing and checking every door twice."})})]}),t.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[t.jsx(i,{label:"Symbolic form",description:"Pick the object, creature, or shape that best symbolizes this mode.",labelHelp:"Symbolic form is the metaphor for the mode, like armor, a fox, a storm front, or a glass wall.",children:t.jsx(P,{value:e.symbolicForm,onChange:a=>r({symbolicForm:a.target.value}),placeholder:"A locked visor, a fox, a steel shield"})}),t.jsx(i,{label:"Facial expression",description:"Describe what you would see on the mode's face if it took over.",labelHelp:"This is the visible emotional expression of the mode: tight jaw, blank stare, pleading eyes, or calm grounded attention.",children:t.jsx(P,{value:e.facialExpression,onChange:a=>r({facialExpression:a.target.value}),placeholder:"Tight jaw, narrowed eyes, forced calm"})})]})]})},{id:"burden",eyebrow:"Burden",title:"Map fear, burden, job, and origin",description:"This is what turns a named mode into a readable inner-state profile.",render:(e,r)=>t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[t.jsx(i,{label:"Fear",description:"Name the threat this mode is trying hard to prevent.",labelHelp:"Fear is the danger the mode believes it must protect you from, such as rejection, shame, collapse, failure, or being trapped.",children:t.jsx(m,{value:e.fear,onChange:a=>r({fear:a.target.value}),placeholder:"If I relax, I will miss the threat and get hurt."})}),t.jsx(i,{label:"Burden",description:"Describe the emotional weight or exhausting role this mode keeps carrying.",labelHelp:"Burden is the heavy job or emotional load the mode feels stuck holding, even when it costs a lot.",children:t.jsx(m,{value:e.burden,onChange:a=>r({burden:a.target.value}),placeholder:"It believes it must never let the guard down, even when that means constant tension."})}),t.jsx(i,{label:"Protective job",description:"Describe the job this mode thinks it is performing for you.",labelHelp:"Protective job is the function the mode is trying to serve, like preventing rejection, keeping control, stopping humiliation, or preserving closeness.",children:t.jsx(m,{value:e.protectiveJob,onChange:a=>r({protectiveJob:a.target.value}),placeholder:"Keeps me prepared so I never get blindsided or look naive."})})]}),t.jsx(i,{label:"Origin context",description:"Describe when this mode first became useful or understandable.",labelHelp:"Origin context is the stretch of life where this mode likely learned its job or became especially necessary.",children:t.jsx(m,{value:e.originContext,onChange:a=>r({originContext:a.target.value}),placeholder:"Started getting stronger during adolescence when mistakes were met with criticism and unpredictability."})})]})},{id:"links",eyebrow:"Links",title:"Attach the mode to the rest of the psyche system",description:"Modes should connect to patterns, behaviors, and values, not sit in isolation.",render:(e,r)=>t.jsxs(t.Fragment,{children:[t.jsx(i,{label:"Linked patterns",description:"Choose the loops this mode tends to activate or maintain.",children:t.jsx(S,{options:V,selectedValues:e.linkedPatternIds,onChange:a=>r({linkedPatternIds:a}),placeholder:"Search or create a pattern…",emptyMessage:"No patterns match yet.",createLabel:"Create pattern",onCreate:X})}),t.jsx(i,{label:"Linked behaviors",description:"Choose the moves this mode tends to trigger, justify, or amplify.",children:t.jsx(S,{options:Y,selectedValues:e.linkedBehaviorIds,onChange:a=>r({linkedBehaviorIds:a}),placeholder:"Search or create a behavior…",emptyMessage:"No behaviors match yet.",createLabel:"Create behavior",onCreate:Z})}),t.jsx(i,{label:"Colliding values",description:"Choose the valued directions this mode most often interrupts.",labelHelp:"These are the values that get obscured, sidelined, or distorted when this mode takes over.",children:t.jsx(S,{options:W,selectedValues:e.linkedValueIds,onChange:a=>r({linkedValueIds:a}),placeholder:"Search or create a value…",emptyMessage:"No values match yet.",createLabel:"Create value",onCreate:ee})})]})}];if(v.isLoading||x.isLoading||k.isLoading||j.isLoading)return t.jsx(ce,{eyebrow:"Modes",title:"Loading modes",description:"Getting modes, linked patterns, behaviors, and values ready."});const _=v.error??x.error??k.error??j.error;if(_)return t.jsx(he,{eyebrow:"Modes",error:_,onRetry:()=>void Promise.all([v.refetch(),x.refetch(),k.refetch(),j.refetch()])});const w={coping:d.filter(e=>e.family==="coping"),child:d.filter(e=>e.family==="child"),critic_parent:d.filter(e=>e.family==="critic_parent"),healthy_adult:d.filter(e=>e.family==="healthy_adult"),happy_child:d.filter(e=>e.family==="happy_child")};return t.jsxs("div",{className:"grid gap-5",children:[t.jsx(Se,{entityKind:"mode",title:t.jsx(q,{kind:"mode",label:"Modes",variant:"heading",size:"lg"}),description:"Modes should look and feel like a cast of inner states with identity, burden, and relational links, not a flat list of records.",badge:`${d.length} modes`,actions:t.jsx(C,{onClick:()=>{u(null),l({...g,userId:c}),n(!0)},children:"Add mode"})}),t.jsx(pe,{}),t.jsx(ne,{eyebrow:"Mode families",title:"Modes by family",description:"Use these groups to see which modes show up most often, what role they play, and what they are connected to.",tone:"violet",children:d.length===0?t.jsx("div",{className:"flex justify-start",children:t.jsx(C,{onClick:()=>{u(null),l({...g,userId:c}),n(!0)},children:"Add mode"})}):t.jsx("div",{className:"grid gap-4 xl:grid-cols-2",children:Object.keys(w).map(e=>t.jsxs("div",{className:"grid gap-3 rounded-[26px] bg-[var(--ui-surface-1)] p-4",children:[t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[t.jsx(Le,{family:e,label:L[e]}),t.jsx(ue,{children:w[e].length})]}),w[e].length===0?t.jsx("div",{className:"flex",children:t.jsxs(C,{variant:"secondary",onClick:()=>{u(null),l({...g,userId:c}),n(!0)},children:["Add ",L[e].toLowerCase()]})}):w[e].map(r=>t.jsxs("div",{"data-psyche-focus-id":r.id,className:`rounded-[22px] bg-[var(--ui-surface-1)] p-4 text-left transition hover:bg-[var(--ui-surface-2)] ${Pe(B===r.id)}`,children:[t.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[t.jsxs("div",{children:[t.jsx(me,{kind:"mode",compact:!0,gradient:!1}),t.jsx(q,{kind:"mode",label:r.title,variant:"heading",size:"lg"})]}),t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx(oe,{entityType:"mode_profile",entityId:r.id,count:ge($,"mode_profile",r.id).count}),t.jsx(C,{variant:"secondary",size:"sm",onClick:()=>{u(r),l(Te(r)),n(!0)},children:"Edit"})]})]}),t.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:r.archetype}),t.jsx("div",{className:"mt-3 text-sm leading-6 text-[var(--ui-ink-soft)]",children:r.persona||r.protectiveJob||"Open the mode to add persona and protective details."})]},r.id))]},e))})}),t.jsx(ie,{open:U,onOpenChange:n,eyebrow:"Mode",title:p?"Refine cast member":"Create mode",description:"Use this guided flow to define the mode, how it shows up, what it is protecting, and where it comes from.",value:y,onChange:l,draftPersistenceKey:p?`psyche.mode.${p.id}`:"psyche.mode.new",steps:te,submitLabel:p?"Save mode":"Create mode",pending:A.isPending,error:R,onSubmit:async()=>{f(null);const e=K.safeParse(y);if(!e.success){f("This mode still needs a family and a name before it can be saved.");return}try{await A.mutateAsync(e.data)}catch(r){f(r instanceof Error?r.message:"Unable to save this mode right now.")}}})]})}export{Xe as PsycheModesPage};
@@ -1 +1 @@
1
- import{b6 as V,r as f,j as e,aC as k,bY as Q}from"./vendor-Cpmju3nw.js";import{i as F}from"./state-BtwEvpO6.js";import{A as U}from"./ai-surface-workspace-Dd2FSRom.js";import{b as z,P as Y}from"./psyche-graph-BmwbnNBY.js";import{d as W,b as N,C,c as H,S as J,e as X,V as Z,bs as ee,B as te,E as se,k as I,bK as ae,a2 as re,bL as ie}from"./index-wEZUnRh0.js";import{Q as ne,a as oe,F as le}from"./question-flow-dialog-Dsnsc8be.js";import{P as de}from"./page-hero-BRcqE3a4.js";import"./board-CLOHbg6t.js";import"./motion-DwjmC9aq.js";import"./ui-B9O-eUim.js";import"./forms-C5d5hTf2.js";const G={intent:"trigger_report",linkedGoalId:"",linkedProjectId:"",linkedTaskId:""};function ce({open:t,onOpenChange:c}){const u=V(),o=W(),[l,b]=f.useState(G),y=[{id:"intent",eyebrow:"Reflect",title:"What do you want to reflect on?",description:"Choose the entrypoint first. Forge will route you into the right guided flow instead of dropping you into a generic form.",render:(i,a)=>e.jsx(oe,{columns:3,value:i.intent,onChange:s=>a({intent:s}),options:[{value:"trigger_report",label:"A situation",description:"Start a Spark-to-Pivot report about something that happened."},{value:"behavior",label:"A behavior",description:"Trace an away move, committed action, or recovery path."},{value:"belief",label:"A belief script",description:"Capture or refine the belief beneath the reaction."},{value:"pattern",label:"A recurring pattern",description:"Map the loop, payoff, cost, and better response."},{value:"value",label:"A blocked value",description:"Clarify which value is being challenged or needs support."},{value:"execution_tension",label:"A goal tension",description:"Reflect on a goal, project, or task that carries friction."}]})},{id:"placement",eyebrow:"Placement",title:"Attach the reflection to the wider system",description:"This keeps the reflection connected to values, behaviors, and live work instead of becoming an isolated note.",render:(i,a)=>e.jsx("div",{className:"grid gap-4",children:e.jsx(le,{label:"Goal / project / task tension",children:e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(N,{kind:"goal",label:"Goal",compact:!0,gradient:!1}),e.jsx(N,{kind:"project",label:"Project",compact:!0,gradient:!1}),e.jsx(N,{kind:"task",label:"Task",compact:!0,gradient:!1})]}),e.jsxs("select",{className:"rounded-[18px] border border-white/8 bg-white/6 px-4 py-3 text-sm text-white",value:i.linkedGoalId,onChange:s=>a({linkedGoalId:s.target.value}),children:[e.jsx("option",{value:"",children:"No goal selected"}),o.snapshot.goals.map(s=>e.jsxs("option",{value:s.id,children:["Goal · ",s.title]},s.id))]}),e.jsxs("select",{className:"rounded-[18px] border border-white/8 bg-white/6 px-4 py-3 text-sm text-white",value:i.linkedProjectId,onChange:s=>a({linkedProjectId:s.target.value}),children:[e.jsx("option",{value:"",children:"No project selected"}),o.snapshot.dashboard.projects.map(s=>e.jsxs("option",{value:s.id,children:["Project · ",s.title]},s.id))]}),e.jsxs("select",{className:"rounded-[18px] border border-white/8 bg-white/6 px-4 py-3 text-sm text-white",value:i.linkedTaskId,onChange:s=>a({linkedTaskId:s.target.value}),children:[e.jsx("option",{value:"",children:"No task selected"}),o.snapshot.tasks.slice(0,40).map(s=>e.jsxs("option",{value:s.id,children:["Task · ",s.title]},s.id))]})]})})})}],x=async()=>{const i=new URLSearchParams({create:"1",intent:l.intent});switch(l.linkedGoalId&&i.set("goalId",l.linkedGoalId),l.linkedProjectId&&i.set("projectId",l.linkedProjectId),l.linkedTaskId&&i.set("taskId",l.linkedTaskId),l.intent){case"behavior":u(`/psyche/behaviors?${i.toString()}`);break;case"belief":u(`/psyche/schemas-beliefs?${i.toString()}`);break;case"pattern":u(`/psyche/patterns?${i.toString()}`);break;case"value":u(`/psyche/values?${i.toString()}`);break;case"execution_tension":case"trigger_report":default:u(`/psyche/reports?${i.toString()}`);break}c(!1),b(G)};return e.jsx(ne,{open:t,onOpenChange:c,eyebrow:"Reflect",title:"Start from the right reflective doorway",description:"Choose what you want to reflect on first. Forge will take you into the right guided flow instead of leaving you in a generic form.",value:l,onChange:b,draftPersistenceKey:"psyche.reflect.launcher",steps:y,submitLabel:"Open guided reflection",onSubmit:x})}function _({to:t,children:c,className:u}){return e.jsx(k,{to:t,className:"group block transition-transform duration-[var(--motion-medium)] ease-[var(--ease-standard)] hover:-translate-y-0.5 focus-visible:outline-none",children:e.jsx(C,{className:H("transition-[transform,box-shadow,background,border-color] duration-[var(--motion-medium)] ease-[var(--ease-standard)] group-hover:border-[var(--ui-border-strong)] group-hover:bg-[var(--ui-surface-hover)] group-hover:shadow-[var(--card-shadow-hover)] group-focus-visible:shadow-[var(--card-shadow-hover)]",u),children:c})})}function D(t){return`${t.toFixed(t>=10?0:1)}%`}function h(t){return new Intl.NumberFormat().format(Math.round(t))}const M="inline-flex min-h-10 min-w-0 max-w-full items-center justify-center rounded-[var(--radius-control)] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-2 text-sm font-medium whitespace-nowrap text-[var(--ui-ink-medium)] transition hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]",ue="bg-[linear-gradient(135deg,color-mix(in_srgb,var(--primary)_34%,var(--ui-surface-2)_66%),color-mix(in_srgb,var(--primary)_18%,var(--ui-surface-1)_82%))] text-[var(--ui-ink-strong)]";function me({metric:t}){const c=t.history.slice(0,7).reverse(),u=Math.max(1,...c.map(o=>o.rawSwearCount));return e.jsxs(C,{className:"min-w-0 border border-[color-mix(in_srgb,var(--warning)_24%,var(--ui-border-subtle)_76%)] bg-[color-mix(in_srgb,var(--ui-warning-soft)_48%,var(--ui-surface-1)_52%)] p-5",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--warning)]",children:"Devrage metric"}),e.jsxs("div",{className:"mt-2 break-words font-display text-[clamp(1.4rem,2.5vw,2.15rem)] leading-none text-[var(--ui-ink-strong)]",children:[h(t.rawSwearCount)," swears"]})]}),e.jsx(I,{className:"bg-[var(--ui-warning-soft)] text-[var(--warning)]",children:t.latestDateKey??"No history"})]}),e.jsxs("div",{className:"mt-4 grid gap-3 sm:grid-cols-3",children:[e.jsxs("div",{className:"min-w-0 rounded-[18px] bg-[var(--ui-surface-1)] px-4 py-3",children:[e.jsx("div",{className:"text-xs text-[var(--ui-ink-faint)]",children:"Swearing messages"}),e.jsx("div",{className:"mt-1 break-words text-2xl font-semibold text-[var(--ui-ink-strong)]",children:D(t.swearingMessagePercent)})]}),e.jsxs("div",{className:"min-w-0 rounded-[18px] bg-[var(--ui-surface-1)] px-4 py-3",children:[e.jsx("div",{className:"text-xs text-[var(--ui-ink-faint)]",children:"Rage peak"}),e.jsx("div",{className:"mt-1 break-words text-2xl font-semibold text-[var(--ui-ink-strong)]",children:h(t.maxCumulativeRage)})]}),e.jsxs("div",{className:"min-w-0 rounded-[18px] bg-[var(--ui-surface-1)] px-4 py-3",children:[e.jsx("div",{className:"text-xs text-[var(--ui-ink-faint)]",children:"Avg thread peak"}),e.jsx("div",{className:"mt-1 break-words text-2xl font-semibold text-[var(--ui-ink-strong)]",children:h(t.averageMaxCumulativeRage)})]})]}),e.jsx("div",{className:"mt-4 flex h-16 items-end gap-1.5",children:c.length>0?c.map(o=>e.jsx("div",{className:"min-w-0 flex-1 rounded-t-[6px] bg-[var(--warning)]/50",style:{height:`${Math.max(8,o.rawSwearCount/u*64)}px`},title:`${o.dateKey}: ${h(o.rawSwearCount)} swears, ${D(o.swearingMessagePercent)} swearing messages, ${h(o.maxCumulativeRage)} max cumulative rage`},o.dateKey)):e.jsx("div",{className:"self-center text-sm text-[var(--ui-ink-faint)]",children:"History will appear after the first local backfill."})}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-2 text-xs text-[var(--ui-ink-soft)]",children:[e.jsxs("span",{children:[h(t.conversationsScanned)," conversations"]}),e.jsxs("span",{children:[h(t.messagesScanned)," messages"]}),e.jsxs("span",{children:[h(t.messagesWithSwears)," flagged"]}),e.jsxs("span",{children:[h(t.maxSwearingStreak)," max streak"]})]}),e.jsx(k,{to:"/psyche/metrics",className:"mt-4 inline-flex min-h-10 items-center justify-center rounded-[var(--radius-control)] border border-[color-mix(in_srgb,var(--warning)_24%,transparent)] bg-[var(--ui-warning-soft)] px-4 py-2 text-sm font-medium text-[var(--warning)] transition hover:bg-[color-mix(in_srgb,var(--warning)_20%,transparent)]",children:"Open metrics"})]})}function Ne(){var R,T;const t=W(),[c,u]=Q(),[o,l]=f.useState(c.get("reflect")==="1"),[b,y]=f.useState(null),x=F({queryKey:["forge-psyche-overview"],queryFn:re}),i=F({queryKey:["forge-psyche-questionnaires-hub"],queryFn:()=>ie()}),a=(R=x.data)==null?void 0:R.overview,s=f.useMemo(()=>a?t.snapshot.goals.slice(0,3).map(r=>{const m=a.values.filter(d=>d.linkedGoalIds.includes(r.id)),S=t.snapshot.dashboard.projects.filter(d=>d.goalId===r.id),A=t.snapshot.habits.filter(d=>d.linkedGoalIds.includes(r.id)||d.linkedValueIds.some(w=>m.some(j=>j.id===w))),B=a.reports.filter(d=>d.linkedGoalIds.includes(r.id)),L=a.behaviors.filter(d=>d.linkedValueIds.some(w=>m.some(j=>j.id===w))),O=a.beliefs.filter(d=>d.linkedValueIds.some(w=>m.some(j=>j.id===w)));return{goal:r,linkedValues:m,linkedProjects:S,linkedHabits:A,linkedReports:B,linkedBehaviors:L,linkedBeliefs:O}}):[],[a,t.snapshot.dashboard.projects,t.snapshot.goals,t.snapshot.habits]),p=f.useMemo(()=>z(s,{compact:!0}),[s]);if(f.useEffect(()=>{y(p.defaultSelectedId)},[p.defaultSelectedId]),x.isLoading)return e.jsx(J,{});if(x.isError||!a)return e.jsx(X,{eyebrow:"Psyche",error:x.error,onRetry:()=>void x.refetch()});const n=p.inspectors[b??p.defaultSelectedId]??p.inspectors[p.defaultSelectedId],g=a.patterns[0]??null,P=a.reports[0]??null,v=[...((T=i.data)==null?void 0:T.instruments)??[]].sort((r,m)=>{const S=r.latestRunAt?new Date(r.latestRunAt).getTime():0;return(m.latestRunAt?new Date(m.latestRunAt).getTime():0)-S})[0]??null,K="Values, patterns, behaviors, beliefs, habits, and reports in one live field.",$=a.devrageMetric.hasData||a.devrageMetric.conversationsScanned>0||a.devrageMetric.history.length>0,E=e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[e.jsx(Z,{metrics:t.snapshot.metrics}),e.jsx(k,{to:"/psyche/goal-map",className:M,children:"Open goal map"})]}),q=[{id:"hero",title:"Psyche",description:"Top route composition",defaultWidth:12,defaultHeight:1,removable:!1,surfaceChrome:"none",defaultTitleVisible:!1,defaultDescriptionVisible:!1,render:()=>e.jsx(de,{title:"Psyche",titleText:"Psyche",description:K,actions:E})},{id:"sections",title:"Psyche sections",description:"Section switcher",defaultWidth:12,defaultHeight:1,surfaceChrome:"none",defaultTitleVisible:!1,defaultDescriptionVisible:!1,render:()=>e.jsx(ee,{})},{id:"field",title:"Live field",description:"Graph and inspector stay as movable widgets.",defaultWidth:8,defaultHeight:5,minWidth:6,render:()=>e.jsx(Y,{testId:"psyche-hub-graph",compact:!0,title:"Reflective pulse and live entity field",hint:"Select any goal, value, habit, belief, behavior, project, or report.",nodes:p.nodes,edges:p.edges,fields:p.fields,selectedNodeId:b,onSelectNode:y,minHeightClassName:"min-h-[20rem] sm:min-h-[24rem] lg:min-h-[34rem]",legend:[{label:"Goals",kind:"goal"},{label:"Values",kind:"value"},{label:"Habits",kind:"habit"},{label:"Behaviors",kind:"behavior"}],action:e.jsxs(e.Fragment,{children:[e.jsx(k,{to:"/psyche/goal-map",className:M,children:"Open goal map"}),e.jsx(te,{size:"sm",className:"min-w-0 sm:min-w-[6.5rem]",onClick:()=>l(!0),children:"Reflect"})]})})},{id:"inspector",title:"Inspector",description:"Selected-node inspector widget.",defaultWidth:4,defaultHeight:5,minWidth:4,render:()=>e.jsxs(C,{className:"h-full min-w-0",children:[e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:n.entityKind?e.jsx(N,{kind:n.entityKind,compact:!0,gradient:!1,iconOnly:!0}):e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:n.eyebrow})}),e.jsx("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:n.entityKind?e.jsx(se,{kind:n.entityKind,label:n.title,variant:"heading",size:"lg",showKind:!1}):e.jsx("h2",{className:"break-words font-display text-[clamp(1.25rem,2.2vw,1.8rem)] leading-none text-[var(--ui-ink-strong)]",children:n.title})}),e.jsx("p",{className:"mt-3 break-words text-sm leading-6 text-[var(--ui-ink-soft)]",children:n.summary}),n.chips.length>0?e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:n.chips.map(r=>e.jsx(I,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:r},r))}):null,n.stats.length>0?e.jsx("div",{className:"mt-4 grid gap-2",children:n.stats.map(r=>e.jsx("div",{className:"min-w-0 rounded-[18px] bg-[var(--ui-surface-1)] px-3 py-3 text-sm text-[var(--ui-ink-medium)] break-words",children:r},r))}):null,e.jsx("div",{className:"mt-5",children:e.jsx(k,{to:n.href,className:H("inline-flex min-h-11 w-full items-center justify-center rounded-[var(--radius-control)] px-4 py-2.5 text-sm font-medium whitespace-nowrap shadow-[var(--ui-shadow-soft)]",n.entityKind?ae(n.entityKind,!0):ue),children:n.ctaLabel})})]})},...$?[{id:"devrage",title:"Devrage metric",description:"Daily user-message frustration metric.",defaultWidth:4,defaultHeight:3,minWidth:4,render:()=>e.jsx(me,{metric:a.devrageMetric})}]:[],{id:"actions",title:"Open threads",description:"Action and pulse cards.",defaultWidth:8,defaultHeight:3,render:()=>e.jsxs("div",{className:"grid min-w-0 gap-4 lg:grid-cols-[minmax(0,1.05fr)_minmax(0,0.95fr)]",children:[e.jsxs(_,{to:"/psyche/behaviors",className:"rounded-[28px] border border-[color-mix(in_srgb,var(--success)_22%,var(--ui-border-subtle)_78%)] bg-[color-mix(in_srgb,var(--ui-success-soft)_44%,var(--ui-surface-1)_56%)] p-5",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--success)]",children:"Best next reflective move"}),e.jsx("div",{className:"mt-3 break-words font-display text-[clamp(1.45rem,2.2vw,2rem)] leading-none text-[var(--ui-ink-strong)]",children:(g==null?void 0:g.preferredResponse)||"Map the active loop, then name the committed move that brings you back."}),e.jsx("p",{className:"mt-3 break-words text-sm leading-6 text-[var(--ui-ink-soft)]",children:(g==null?void 0:g.targetBehavior)||"When the loop is explicit, the return path stops feeling abstract."})]}),e.jsxs(_,{to:P?`/psyche/reports/${P.id}`:"/psyche/reports",className:"rounded-[28px] border border-[color-mix(in_srgb,var(--primary)_22%,var(--ui-border-subtle)_78%)] bg-[color-mix(in_srgb,var(--ui-accent-soft)_46%,var(--ui-surface-1)_54%)] p-5",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--primary)]",children:"Open threads"}),e.jsxs("div",{className:"mt-3 grid gap-3 md:grid-cols-2",children:[e.jsxs("div",{className:"min-w-0 rounded-[22px] bg-[var(--ui-surface-1)] px-4 py-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Insights"}),e.jsx("div",{className:"mt-2 break-words font-display text-4xl text-[var(--ui-ink-strong)]",children:a.openInsights})]}),e.jsxs("div",{className:"min-w-0 rounded-[22px] bg-[var(--ui-surface-1)] px-4 py-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Notes"}),e.jsx("div",{className:"mt-2 break-words font-display text-4xl text-[var(--ui-ink-strong)]",children:a.openNotes})]})]})]})]})},{id:"questionnaires",title:"Questionnaire pulse",description:"Recent questionnaire state.",defaultWidth:12,defaultHeight:2,render:()=>{var r;return e.jsxs(_,{to:v!=null&&v.latestRunId?`/psyche/questionnaire-runs/${v.latestRunId}`:"/psyche/questionnaires",className:"rounded-[28px] border border-[color-mix(in_srgb,var(--info)_22%,var(--ui-border-subtle)_78%)] bg-[color-mix(in_srgb,var(--ui-info-soft)_42%,var(--ui-surface-1)_58%)] p-5",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--info)]",children:"Questionnaire pulse"}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center justify-between gap-3",children:[e.jsx("div",{className:"min-w-0 break-words font-display text-[clamp(1.4rem,2.2vw,2rem)] leading-none text-[var(--ui-ink-strong)]",children:(v==null?void 0:v.title)??"Questionnaire library ready"}),e.jsxs(I,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:[(((r=i.data)==null?void 0:r.instruments)??[]).length," available"]})]})]})}}];return e.jsxs("div",{className:"grid min-w-0 gap-4 overflow-x-clip",children:[e.jsx(U,{surfaceId:"psyche",baseWidgets:q}),e.jsx(ce,{open:o,onOpenChange:r=>{l(r);const m=new URLSearchParams(c);m.delete("reflect"),u(m,{replace:!0})}})]})}export{Ne as PsychePage};
1
+ import{b6 as V,r as f,j as e,aC as k,bY as Q}from"./vendor-Cpmju3nw.js";import{i as F}from"./state-BtwEvpO6.js";import{A as U}from"./ai-surface-workspace-ehzBjTsW.js";import{b as z,P as Y}from"./psyche-graph-Tke0qFdt.js";import{d as W,b as N,C,c as H,S as J,e as X,V as Z,bs as ee,B as te,E as se,k as I,bK as ae,a2 as re,bL as ie}from"./index-BaiwtAgo.js";import{Q as ne,a as oe,F as le}from"./question-flow-dialog-Bj4PxpjS.js";import{P as de}from"./page-hero-C0MpI3MM.js";import"./board-CLOHbg6t.js";import"./motion-DwjmC9aq.js";import"./ui-B9O-eUim.js";import"./forms-C5d5hTf2.js";const G={intent:"trigger_report",linkedGoalId:"",linkedProjectId:"",linkedTaskId:""};function ce({open:t,onOpenChange:c}){const u=V(),o=W(),[l,b]=f.useState(G),y=[{id:"intent",eyebrow:"Reflect",title:"What do you want to reflect on?",description:"Choose the entrypoint first. Forge will route you into the right guided flow instead of dropping you into a generic form.",render:(i,a)=>e.jsx(oe,{columns:3,value:i.intent,onChange:s=>a({intent:s}),options:[{value:"trigger_report",label:"A situation",description:"Start a Spark-to-Pivot report about something that happened."},{value:"behavior",label:"A behavior",description:"Trace an away move, committed action, or recovery path."},{value:"belief",label:"A belief script",description:"Capture or refine the belief beneath the reaction."},{value:"pattern",label:"A recurring pattern",description:"Map the loop, payoff, cost, and better response."},{value:"value",label:"A blocked value",description:"Clarify which value is being challenged or needs support."},{value:"execution_tension",label:"A goal tension",description:"Reflect on a goal, project, or task that carries friction."}]})},{id:"placement",eyebrow:"Placement",title:"Attach the reflection to the wider system",description:"This keeps the reflection connected to values, behaviors, and live work instead of becoming an isolated note.",render:(i,a)=>e.jsx("div",{className:"grid gap-4",children:e.jsx(le,{label:"Goal / project / task tension",children:e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(N,{kind:"goal",label:"Goal",compact:!0,gradient:!1}),e.jsx(N,{kind:"project",label:"Project",compact:!0,gradient:!1}),e.jsx(N,{kind:"task",label:"Task",compact:!0,gradient:!1})]}),e.jsxs("select",{className:"rounded-[18px] border border-white/8 bg-white/6 px-4 py-3 text-sm text-white",value:i.linkedGoalId,onChange:s=>a({linkedGoalId:s.target.value}),children:[e.jsx("option",{value:"",children:"No goal selected"}),o.snapshot.goals.map(s=>e.jsxs("option",{value:s.id,children:["Goal · ",s.title]},s.id))]}),e.jsxs("select",{className:"rounded-[18px] border border-white/8 bg-white/6 px-4 py-3 text-sm text-white",value:i.linkedProjectId,onChange:s=>a({linkedProjectId:s.target.value}),children:[e.jsx("option",{value:"",children:"No project selected"}),o.snapshot.dashboard.projects.map(s=>e.jsxs("option",{value:s.id,children:["Project · ",s.title]},s.id))]}),e.jsxs("select",{className:"rounded-[18px] border border-white/8 bg-white/6 px-4 py-3 text-sm text-white",value:i.linkedTaskId,onChange:s=>a({linkedTaskId:s.target.value}),children:[e.jsx("option",{value:"",children:"No task selected"}),o.snapshot.tasks.slice(0,40).map(s=>e.jsxs("option",{value:s.id,children:["Task · ",s.title]},s.id))]})]})})})}],x=async()=>{const i=new URLSearchParams({create:"1",intent:l.intent});switch(l.linkedGoalId&&i.set("goalId",l.linkedGoalId),l.linkedProjectId&&i.set("projectId",l.linkedProjectId),l.linkedTaskId&&i.set("taskId",l.linkedTaskId),l.intent){case"behavior":u(`/psyche/behaviors?${i.toString()}`);break;case"belief":u(`/psyche/schemas-beliefs?${i.toString()}`);break;case"pattern":u(`/psyche/patterns?${i.toString()}`);break;case"value":u(`/psyche/values?${i.toString()}`);break;case"execution_tension":case"trigger_report":default:u(`/psyche/reports?${i.toString()}`);break}c(!1),b(G)};return e.jsx(ne,{open:t,onOpenChange:c,eyebrow:"Reflect",title:"Start from the right reflective doorway",description:"Choose what you want to reflect on first. Forge will take you into the right guided flow instead of leaving you in a generic form.",value:l,onChange:b,draftPersistenceKey:"psyche.reflect.launcher",steps:y,submitLabel:"Open guided reflection",onSubmit:x})}function _({to:t,children:c,className:u}){return e.jsx(k,{to:t,className:"group block transition-transform duration-[var(--motion-medium)] ease-[var(--ease-standard)] hover:-translate-y-0.5 focus-visible:outline-none",children:e.jsx(C,{className:H("transition-[transform,box-shadow,background,border-color] duration-[var(--motion-medium)] ease-[var(--ease-standard)] group-hover:border-[var(--ui-border-strong)] group-hover:bg-[var(--ui-surface-hover)] group-hover:shadow-[var(--card-shadow-hover)] group-focus-visible:shadow-[var(--card-shadow-hover)]",u),children:c})})}function D(t){return`${t.toFixed(t>=10?0:1)}%`}function h(t){return new Intl.NumberFormat().format(Math.round(t))}const M="inline-flex min-h-10 min-w-0 max-w-full items-center justify-center rounded-[var(--radius-control)] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-2 text-sm font-medium whitespace-nowrap text-[var(--ui-ink-medium)] transition hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]",ue="bg-[linear-gradient(135deg,color-mix(in_srgb,var(--primary)_34%,var(--ui-surface-2)_66%),color-mix(in_srgb,var(--primary)_18%,var(--ui-surface-1)_82%))] text-[var(--ui-ink-strong)]";function me({metric:t}){const c=t.history.slice(0,7).reverse(),u=Math.max(1,...c.map(o=>o.rawSwearCount));return e.jsxs(C,{className:"min-w-0 border border-[color-mix(in_srgb,var(--warning)_24%,var(--ui-border-subtle)_76%)] bg-[color-mix(in_srgb,var(--ui-warning-soft)_48%,var(--ui-surface-1)_52%)] p-5",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--warning)]",children:"Devrage metric"}),e.jsxs("div",{className:"mt-2 break-words font-display text-[clamp(1.4rem,2.5vw,2.15rem)] leading-none text-[var(--ui-ink-strong)]",children:[h(t.rawSwearCount)," swears"]})]}),e.jsx(I,{className:"bg-[var(--ui-warning-soft)] text-[var(--warning)]",children:t.latestDateKey??"No history"})]}),e.jsxs("div",{className:"mt-4 grid gap-3 sm:grid-cols-3",children:[e.jsxs("div",{className:"min-w-0 rounded-[18px] bg-[var(--ui-surface-1)] px-4 py-3",children:[e.jsx("div",{className:"text-xs text-[var(--ui-ink-faint)]",children:"Swearing messages"}),e.jsx("div",{className:"mt-1 break-words text-2xl font-semibold text-[var(--ui-ink-strong)]",children:D(t.swearingMessagePercent)})]}),e.jsxs("div",{className:"min-w-0 rounded-[18px] bg-[var(--ui-surface-1)] px-4 py-3",children:[e.jsx("div",{className:"text-xs text-[var(--ui-ink-faint)]",children:"Rage peak"}),e.jsx("div",{className:"mt-1 break-words text-2xl font-semibold text-[var(--ui-ink-strong)]",children:h(t.maxCumulativeRage)})]}),e.jsxs("div",{className:"min-w-0 rounded-[18px] bg-[var(--ui-surface-1)] px-4 py-3",children:[e.jsx("div",{className:"text-xs text-[var(--ui-ink-faint)]",children:"Avg thread peak"}),e.jsx("div",{className:"mt-1 break-words text-2xl font-semibold text-[var(--ui-ink-strong)]",children:h(t.averageMaxCumulativeRage)})]})]}),e.jsx("div",{className:"mt-4 flex h-16 items-end gap-1.5",children:c.length>0?c.map(o=>e.jsx("div",{className:"min-w-0 flex-1 rounded-t-[6px] bg-[var(--warning)]/50",style:{height:`${Math.max(8,o.rawSwearCount/u*64)}px`},title:`${o.dateKey}: ${h(o.rawSwearCount)} swears, ${D(o.swearingMessagePercent)} swearing messages, ${h(o.maxCumulativeRage)} max cumulative rage`},o.dateKey)):e.jsx("div",{className:"self-center text-sm text-[var(--ui-ink-faint)]",children:"History will appear after the first local backfill."})}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-2 text-xs text-[var(--ui-ink-soft)]",children:[e.jsxs("span",{children:[h(t.conversationsScanned)," conversations"]}),e.jsxs("span",{children:[h(t.messagesScanned)," messages"]}),e.jsxs("span",{children:[h(t.messagesWithSwears)," flagged"]}),e.jsxs("span",{children:[h(t.maxSwearingStreak)," max streak"]})]}),e.jsx(k,{to:"/psyche/metrics",className:"mt-4 inline-flex min-h-10 items-center justify-center rounded-[var(--radius-control)] border border-[color-mix(in_srgb,var(--warning)_24%,transparent)] bg-[var(--ui-warning-soft)] px-4 py-2 text-sm font-medium text-[var(--warning)] transition hover:bg-[color-mix(in_srgb,var(--warning)_20%,transparent)]",children:"Open metrics"})]})}function Ne(){var R,T;const t=W(),[c,u]=Q(),[o,l]=f.useState(c.get("reflect")==="1"),[b,y]=f.useState(null),x=F({queryKey:["forge-psyche-overview"],queryFn:re}),i=F({queryKey:["forge-psyche-questionnaires-hub"],queryFn:()=>ie()}),a=(R=x.data)==null?void 0:R.overview,s=f.useMemo(()=>a?t.snapshot.goals.slice(0,3).map(r=>{const m=a.values.filter(d=>d.linkedGoalIds.includes(r.id)),S=t.snapshot.dashboard.projects.filter(d=>d.goalId===r.id),A=t.snapshot.habits.filter(d=>d.linkedGoalIds.includes(r.id)||d.linkedValueIds.some(w=>m.some(j=>j.id===w))),B=a.reports.filter(d=>d.linkedGoalIds.includes(r.id)),L=a.behaviors.filter(d=>d.linkedValueIds.some(w=>m.some(j=>j.id===w))),O=a.beliefs.filter(d=>d.linkedValueIds.some(w=>m.some(j=>j.id===w)));return{goal:r,linkedValues:m,linkedProjects:S,linkedHabits:A,linkedReports:B,linkedBehaviors:L,linkedBeliefs:O}}):[],[a,t.snapshot.dashboard.projects,t.snapshot.goals,t.snapshot.habits]),p=f.useMemo(()=>z(s,{compact:!0}),[s]);if(f.useEffect(()=>{y(p.defaultSelectedId)},[p.defaultSelectedId]),x.isLoading)return e.jsx(J,{});if(x.isError||!a)return e.jsx(X,{eyebrow:"Psyche",error:x.error,onRetry:()=>void x.refetch()});const n=p.inspectors[b??p.defaultSelectedId]??p.inspectors[p.defaultSelectedId],g=a.patterns[0]??null,P=a.reports[0]??null,v=[...((T=i.data)==null?void 0:T.instruments)??[]].sort((r,m)=>{const S=r.latestRunAt?new Date(r.latestRunAt).getTime():0;return(m.latestRunAt?new Date(m.latestRunAt).getTime():0)-S})[0]??null,K="Values, patterns, behaviors, beliefs, habits, and reports in one live field.",$=a.devrageMetric.hasData||a.devrageMetric.conversationsScanned>0||a.devrageMetric.history.length>0,E=e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[e.jsx(Z,{metrics:t.snapshot.metrics}),e.jsx(k,{to:"/psyche/goal-map",className:M,children:"Open goal map"})]}),q=[{id:"hero",title:"Psyche",description:"Top route composition",defaultWidth:12,defaultHeight:1,removable:!1,surfaceChrome:"none",defaultTitleVisible:!1,defaultDescriptionVisible:!1,render:()=>e.jsx(de,{title:"Psyche",titleText:"Psyche",description:K,actions:E})},{id:"sections",title:"Psyche sections",description:"Section switcher",defaultWidth:12,defaultHeight:1,surfaceChrome:"none",defaultTitleVisible:!1,defaultDescriptionVisible:!1,render:()=>e.jsx(ee,{})},{id:"field",title:"Live field",description:"Graph and inspector stay as movable widgets.",defaultWidth:8,defaultHeight:5,minWidth:6,render:()=>e.jsx(Y,{testId:"psyche-hub-graph",compact:!0,title:"Reflective pulse and live entity field",hint:"Select any goal, value, habit, belief, behavior, project, or report.",nodes:p.nodes,edges:p.edges,fields:p.fields,selectedNodeId:b,onSelectNode:y,minHeightClassName:"min-h-[20rem] sm:min-h-[24rem] lg:min-h-[34rem]",legend:[{label:"Goals",kind:"goal"},{label:"Values",kind:"value"},{label:"Habits",kind:"habit"},{label:"Behaviors",kind:"behavior"}],action:e.jsxs(e.Fragment,{children:[e.jsx(k,{to:"/psyche/goal-map",className:M,children:"Open goal map"}),e.jsx(te,{size:"sm",className:"min-w-0 sm:min-w-[6.5rem]",onClick:()=>l(!0),children:"Reflect"})]})})},{id:"inspector",title:"Inspector",description:"Selected-node inspector widget.",defaultWidth:4,defaultHeight:5,minWidth:4,render:()=>e.jsxs(C,{className:"h-full min-w-0",children:[e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:n.entityKind?e.jsx(N,{kind:n.entityKind,compact:!0,gradient:!1,iconOnly:!0}):e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:n.eyebrow})}),e.jsx("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:n.entityKind?e.jsx(se,{kind:n.entityKind,label:n.title,variant:"heading",size:"lg",showKind:!1}):e.jsx("h2",{className:"break-words font-display text-[clamp(1.25rem,2.2vw,1.8rem)] leading-none text-[var(--ui-ink-strong)]",children:n.title})}),e.jsx("p",{className:"mt-3 break-words text-sm leading-6 text-[var(--ui-ink-soft)]",children:n.summary}),n.chips.length>0?e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:n.chips.map(r=>e.jsx(I,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:r},r))}):null,n.stats.length>0?e.jsx("div",{className:"mt-4 grid gap-2",children:n.stats.map(r=>e.jsx("div",{className:"min-w-0 rounded-[18px] bg-[var(--ui-surface-1)] px-3 py-3 text-sm text-[var(--ui-ink-medium)] break-words",children:r},r))}):null,e.jsx("div",{className:"mt-5",children:e.jsx(k,{to:n.href,className:H("inline-flex min-h-11 w-full items-center justify-center rounded-[var(--radius-control)] px-4 py-2.5 text-sm font-medium whitespace-nowrap shadow-[var(--ui-shadow-soft)]",n.entityKind?ae(n.entityKind,!0):ue),children:n.ctaLabel})})]})},...$?[{id:"devrage",title:"Devrage metric",description:"Daily user-message frustration metric.",defaultWidth:4,defaultHeight:3,minWidth:4,render:()=>e.jsx(me,{metric:a.devrageMetric})}]:[],{id:"actions",title:"Open threads",description:"Action and pulse cards.",defaultWidth:8,defaultHeight:3,render:()=>e.jsxs("div",{className:"grid min-w-0 gap-4 lg:grid-cols-[minmax(0,1.05fr)_minmax(0,0.95fr)]",children:[e.jsxs(_,{to:"/psyche/behaviors",className:"rounded-[28px] border border-[color-mix(in_srgb,var(--success)_22%,var(--ui-border-subtle)_78%)] bg-[color-mix(in_srgb,var(--ui-success-soft)_44%,var(--ui-surface-1)_56%)] p-5",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--success)]",children:"Best next reflective move"}),e.jsx("div",{className:"mt-3 break-words font-display text-[clamp(1.45rem,2.2vw,2rem)] leading-none text-[var(--ui-ink-strong)]",children:(g==null?void 0:g.preferredResponse)||"Map the active loop, then name the committed move that brings you back."}),e.jsx("p",{className:"mt-3 break-words text-sm leading-6 text-[var(--ui-ink-soft)]",children:(g==null?void 0:g.targetBehavior)||"When the loop is explicit, the return path stops feeling abstract."})]}),e.jsxs(_,{to:P?`/psyche/reports/${P.id}`:"/psyche/reports",className:"rounded-[28px] border border-[color-mix(in_srgb,var(--primary)_22%,var(--ui-border-subtle)_78%)] bg-[color-mix(in_srgb,var(--ui-accent-soft)_46%,var(--ui-surface-1)_54%)] p-5",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--primary)]",children:"Open threads"}),e.jsxs("div",{className:"mt-3 grid gap-3 md:grid-cols-2",children:[e.jsxs("div",{className:"min-w-0 rounded-[22px] bg-[var(--ui-surface-1)] px-4 py-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Insights"}),e.jsx("div",{className:"mt-2 break-words font-display text-4xl text-[var(--ui-ink-strong)]",children:a.openInsights})]}),e.jsxs("div",{className:"min-w-0 rounded-[22px] bg-[var(--ui-surface-1)] px-4 py-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Notes"}),e.jsx("div",{className:"mt-2 break-words font-display text-4xl text-[var(--ui-ink-strong)]",children:a.openNotes})]})]})]})]})},{id:"questionnaires",title:"Questionnaire pulse",description:"Recent questionnaire state.",defaultWidth:12,defaultHeight:2,render:()=>{var r;return e.jsxs(_,{to:v!=null&&v.latestRunId?`/psyche/questionnaire-runs/${v.latestRunId}`:"/psyche/questionnaires",className:"rounded-[28px] border border-[color-mix(in_srgb,var(--info)_22%,var(--ui-border-subtle)_78%)] bg-[color-mix(in_srgb,var(--ui-info-soft)_42%,var(--ui-surface-1)_58%)] p-5",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--info)]",children:"Questionnaire pulse"}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center justify-between gap-3",children:[e.jsx("div",{className:"min-w-0 break-words font-display text-[clamp(1.4rem,2.2vw,2rem)] leading-none text-[var(--ui-ink-strong)]",children:(v==null?void 0:v.title)??"Questionnaire library ready"}),e.jsxs(I,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:[(((r=i.data)==null?void 0:r.instruments)??[]).length," available"]})]})]})}}];return e.jsxs("div",{className:"grid min-w-0 gap-4 overflow-x-clip",children:[e.jsx(U,{surfaceId:"psyche",baseWidgets:q}),e.jsx(ce,{open:o,onOpenChange:r=>{l(r);const m=new URLSearchParams(c);m.delete("reflect"),u(m,{replace:!0})}})]})}export{Ne as PsychePage};
@@ -1,4 +1,4 @@
1
- import{bY as ke,r as y,j as t}from"./vendor-Cpmju3nw.js";import{j as je,i as f,k as Ie}from"./state-BtwEvpO6.js";import{Q as Ne,F as l}from"./question-flow-dialog-Dsnsc8be.js";import{E as Se}from"./entity-note-count-link-CmRRdXAr.js";import{A as ie}from"./atlas-panel-Dinteouh.js";import{E as F}from"./entity-link-multiselect-DZZjpL_d.js";import{O as Ce}from"./orbit-map-DPQNBqS-.js";import{d as Pe,L as Te,e as Le,B as q,E as ne,bs as Be,b as _,R as Ee,k as Fe,i as qe,bZ as _e,bO as Me,b_ as oe,b2 as Oe,I as Ae,T as w,bP as Qe,bQ as Ke,b$ as $e,b4 as Re,b3 as De,bR as Ue,b7 as Ve,b6 as We,b5 as ze}from"./index-wEZUnRh0.js";import{S as A}from"./schema-badge-CRThEDqP.js";import{u as Ge,p as He}from"./use-psyche-focus-target-Cuxni3SK.js";import{P as Je}from"./page-hero-BRcqE3a4.js";import{U as Ye}from"./user-badge-CQygGKVs.js";import{U as Ze}from"./user-select-field-BNqv8-wd.js";import{p as Q}from"./query-cache-IQ8W-LNC.js";import{c as le}from"./psyche-schemas-Dtskzvv1.js";import{g as Xe,f as de}from"./schema-visuals-CvC9a3i6.js";import{g as et,b as K,d as $,e as R,a as tt}from"./user-ownership-DJGl4rAj.js";import"./ui-B9O-eUim.js";import"./motion-DwjmC9aq.js";import"./use-anchored-overlay-position-BrQ4cqKn.js";import"./board-CLOHbg6t.js";import"./forms-C5d5hTf2.js";const k={title:"",description:"",targetBehavior:"",cueContexts:[],shortTermPayoff:"",longTermCost:"",preferredResponse:"",linkedValueIds:[],linkedSchemaLabels:[],linkedModeIds:[],linkedBeliefIds:[],userId:null};function at(i){return{title:i.title,description:i.description,targetBehavior:i.targetBehavior,cueContexts:i.cueContexts,shortTermPayoff:i.shortTermPayoff,longTermCost:i.longTermCost,preferredResponse:i.preferredResponse,linkedValueIds:i.linkedValueIds,linkedSchemaLabels:i.linkedSchemaLabels,linkedModeIds:i.linkedModeIds,linkedBeliefIds:i.linkedBeliefIds,userId:i.userId??null}}function st(i){const n=new Set;return i.filter(d=>{const j=`${d.entityType}:${d.entityId}:${d.anchorKey??""}`;return n.has(j)?!1:(n.add(j),!0)})}function rt(i){const n=i.replace(/\s+/g," ").trim();return n.length<=180?n:`${n.slice(0,177).trimEnd()}...`}function Ct(){var Y,Z,X,ee,te,ae;const i=Pe(),n=je(),[d,j]=ke(),[ce,p]=y.useState(!1),[u,v]=y.useState(null),[c,b]=y.useState(null),[I,h]=y.useState(k),[ue,N]=y.useState(null),S=f({queryKey:["forge-psyche-patterns"],queryFn:Re}),C=f({queryKey:["forge-psyche-values"],queryFn:De}),P=f({queryKey:["forge-psyche-schema-catalog"],queryFn:Ue}),T=f({queryKey:["forge-psyche-modes"],queryFn:Ve}),L=f({queryKey:["forge-psyche-beliefs"],queryFn:We}),B=f({queryKey:["forge-psyche-behaviors"],queryFn:ze}),m=((Y=S.data)==null?void 0:Y.patterns)??[],D=((Z=C.data)==null?void 0:Z.values)??[],M=((X=P.data)==null?void 0:X.schemas)??[],U=((ee=T.data)==null?void 0:ee.modes)??[],V=((te=L.data)==null?void 0:te.beliefs)??[],W=((ae=B.data)==null?void 0:ae.behaviors)??[],g=et(i.selectedUserIds),z=d.get("focus"),pe=i.snapshot.dashboard.notesSummaryByEntity,x=f({enabled:c!==null,queryKey:["forge-note",c],queryFn:()=>oe(c)});Ge(z),y.useEffect(()=>{if(d.get("create")==="1"){p(!0),v(null),h({...k,userId:d.get("userId")??g}),b(d.get("sourceObservationNoteId"));const e=new URLSearchParams(d);e.delete("create"),e.delete("sourceObservationNoteId"),e.delete("userId"),j(e,{replace:!0})}},[g,d,j]);const G=Ie({mutationFn:async e=>{var o,E;const a=le.parse(e);if(u)return _e(u.id,a);const s=await Me(a);if(c){const O=((E=(o=x.data)==null?void 0:o.note)==null?void 0:E.id)===c?x.data.note:(await oe(c)).note;await Oe(c,{links:st([...O.links,{entityType:"behavior_pattern",entityId:s.pattern.id,anchorKey:null}])})}return s},onSuccess:async()=>{p(!1),v(null),b(null),h({...k,userId:g}),N(null),await Promise.all([n.invalidateQueries({queryKey:["forge-psyche-patterns"]}),n.invalidateQueries({queryKey:["forge-psyche-overview"]}),n.invalidateQueries({queryKey:["forge-psyche-self-observation-calendar"]}),qe(n),n.invalidateQueries({queryKey:["notes-index"]})])}}),he=D.map(e=>({value:e.id,label:R(e.title,e.user),description:$(e.valuedDirection,e.user),searchText:K([e.title,e.valuedDirection,e.description],e),kind:"value"})),me=M.map(e=>({value:e.title,label:e.title,description:`${e.description} ${Xe(e.family)}`,searchText:`${e.slug} ${e.family} ${e.schemaType}`,badge:t.jsx(A,{label:e.title,schemaType:e.schemaType,compact:!0}),menuBadge:t.jsx(A,{label:e.title,schemaType:e.schemaType,compact:!0})})),ge=U.map(e=>({value:e.id,label:R(e.title,e.user),description:$(e.archetype||e.family,e.user),searchText:K([e.title,e.archetype,e.family,e.persona],e),kind:"mode"})),ye=V.map(e=>({value:e.id,label:R(e.statement,e.user),description:$(e.flexibleAlternative||e.originNote,e.user),searchText:K([e.statement,e.flexibleAlternative,e.originNote,e.beliefType],e),kind:"belief"})),fe=async e=>{const{mode:a}=await Ke({family:"coping",archetype:"",title:e,persona:"",imagery:"",symbolicForm:"",facialExpression:"",fear:"",burden:"",protectiveJob:"",originContext:"",firstAppearanceAt:null,linkedPatternIds:[],linkedBehaviorIds:[],linkedValueIds:[],userId:I.userId});return Q(n,["forge-psyche-modes"],"modes",a),await n.invalidateQueries({queryKey:["forge-psyche-overview"]}),{value:a.id,label:a.title,description:a.archetype||a.family,kind:"mode"}},ve=async e=>{const{value:a}=await Qe({title:e,description:"",valuedDirection:e,whyItMatters:"",linkedGoalIds:[],linkedProjectIds:[],linkedTaskIds:[],committedActions:[],userId:I.userId});return Q(n,["forge-psyche-values"],"values",a),await n.invalidateQueries({queryKey:["forge-psyche-overview"]}),{value:a.id,label:a.title,description:a.valuedDirection,kind:"value"}},be=async e=>{const{belief:a}=await $e({schemaId:null,statement:e,beliefType:"absolute",originNote:"",confidence:60,evidenceFor:[],evidenceAgainst:[],flexibleAlternative:"",linkedValueIds:[],linkedBehaviorIds:[],linkedModeIds:[],linkedReportIds:[],userId:I.userId});return Q(n,["forge-psyche-beliefs"],"beliefs",a),await n.invalidateQueries({queryKey:["forge-psyche-overview"]}),{value:a.id,label:a.statement,description:a.flexibleAlternative||a.originNote,kind:"belief"}},H=y.useMemo(()=>m.filter(e=>!W.some(a=>a.kind==="away"&&a.linkedPatternIds.includes(e.id))),[m,W]),xe=m.slice(0,5).map((e,a)=>({id:e.id,label:`${e.linkedValueIds.length} values`,title:e.title,detail:e.preferredResponse,href:`/psyche/patterns?focus=${e.id}#pattern-lanes`,angle:-92+a*70,radius:150+a%2*14,tone:["rose","sky","violet","mint"][a%4]})),we=[{id:"loop",eyebrow:"Loop",title:"Name the pattern and the behavior it keeps producing",description:"This should feel like a recognizable loop, not a diagnostic label.",render:(e,a)=>{var s;return t.jsxs(t.Fragment,{children:[c?t.jsxs("div",{className:"rounded-[22px] border border-[color-mix(in_srgb,var(--tertiary)_24%,var(--ui-border-subtle)_76%)] bg-[color-mix(in_srgb,var(--tertiary)_10%,var(--ui-surface-1)_90%)] p-4",children:[t.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--tertiary)]",children:"Source observation"}),t.jsx("div",{className:"mt-2 break-words text-sm leading-6 text-[var(--ui-ink-medium)] [overflow-wrap:anywhere]",children:x.isLoading?"Loading the saved observation note...":(s=x.data)!=null&&s.note?rt(x.data.note.contentPlain||x.data.note.contentMarkdown):"Forge will link this pattern back to the saved observation when you submit it."})]}):null,t.jsx(Ze,{value:e.userId??null,users:i.snapshot.users,onChange:o=>a({userId:o}),defaultLabel:tt(i.snapshot.users.find(o=>o.id===g)??null,"Choose pattern owner"),help:"Patterns can belong to a human or bot user even when linked values, modes, or beliefs cross owners."}),t.jsx(l,{label:"Pattern name",description:"Give the loop a name you will recognize quickly later.",children:t.jsx(Ae,{value:e.title,onChange:o=>a({title:o.target.value}),placeholder:"Anxious reassurance loop"})}),t.jsx(l,{label:"What happens in the loop",description:"Describe the actual sequence of behavior, not the diagnosis.",children:t.jsx(w,{value:e.targetBehavior,onChange:o=>a({targetBehavior:o.target.value}),placeholder:"What do you actually do when the trigger hits?"})}),t.jsx(l,{label:"Description",description:"Write the loop in plain language so it stays usable in the future.",children:t.jsx(w,{value:e.description,onChange:o=>a({description:o.target.value}),placeholder:"Describe the loop in plain human language so it stays recognizable later."})})]})}},{id:"dynamics",eyebrow:"Dynamics",title:"Capture cues, payoff, cost, and the desired response",description:"The goal is to make the action map obvious at a glance.",render:(e,a)=>t.jsxs(t.Fragment,{children:[t.jsx(l,{label:"Common cues",description:"Add one cue per line so the trigger pattern stays easy to scan.",children:t.jsx(w,{value:e.cueContexts.join(`
1
+ import{bY as ke,r as y,j as t}from"./vendor-Cpmju3nw.js";import{j as je,i as f,k as Ie}from"./state-BtwEvpO6.js";import{Q as Ne,F as l}from"./question-flow-dialog-Bj4PxpjS.js";import{E as Se}from"./entity-note-count-link-BzWnsOmI.js";import{A as ie}from"./atlas-panel-BFUeVT69.js";import{E as F}from"./entity-link-multiselect-Bb4De_e3.js";import{O as Ce}from"./orbit-map-8eNDWek8.js";import{d as Pe,L as Te,e as Le,B as q,E as ne,bs as Be,b as _,R as Ee,k as Fe,i as qe,bZ as _e,bO as Me,b_ as oe,b2 as Oe,I as Ae,T as w,bP as Qe,bQ as Ke,b$ as $e,b4 as Re,b3 as De,bR as Ue,b7 as Ve,b6 as We,b5 as ze}from"./index-BaiwtAgo.js";import{S as A}from"./schema-badge-CCe4zkSN.js";import{u as Ge,p as He}from"./use-psyche-focus-target-Cuxni3SK.js";import{P as Je}from"./page-hero-C0MpI3MM.js";import{U as Ye}from"./user-badge-DfDv87j7.js";import{U as Ze}from"./user-select-field-BNqv8-wd.js";import{p as Q}from"./query-cache-IQ8W-LNC.js";import{c as le}from"./psyche-schemas-Dtskzvv1.js";import{g as Xe,f as de}from"./schema-visuals-CvC9a3i6.js";import{g as et,b as K,d as $,e as R,a as tt}from"./user-ownership-DJGl4rAj.js";import"./ui-B9O-eUim.js";import"./motion-DwjmC9aq.js";import"./use-anchored-overlay-position-BrQ4cqKn.js";import"./board-CLOHbg6t.js";import"./forms-C5d5hTf2.js";const k={title:"",description:"",targetBehavior:"",cueContexts:[],shortTermPayoff:"",longTermCost:"",preferredResponse:"",linkedValueIds:[],linkedSchemaLabels:[],linkedModeIds:[],linkedBeliefIds:[],userId:null};function at(i){return{title:i.title,description:i.description,targetBehavior:i.targetBehavior,cueContexts:i.cueContexts,shortTermPayoff:i.shortTermPayoff,longTermCost:i.longTermCost,preferredResponse:i.preferredResponse,linkedValueIds:i.linkedValueIds,linkedSchemaLabels:i.linkedSchemaLabels,linkedModeIds:i.linkedModeIds,linkedBeliefIds:i.linkedBeliefIds,userId:i.userId??null}}function st(i){const n=new Set;return i.filter(d=>{const j=`${d.entityType}:${d.entityId}:${d.anchorKey??""}`;return n.has(j)?!1:(n.add(j),!0)})}function rt(i){const n=i.replace(/\s+/g," ").trim();return n.length<=180?n:`${n.slice(0,177).trimEnd()}...`}function Ct(){var Y,Z,X,ee,te,ae;const i=Pe(),n=je(),[d,j]=ke(),[ce,p]=y.useState(!1),[u,v]=y.useState(null),[c,b]=y.useState(null),[I,h]=y.useState(k),[ue,N]=y.useState(null),S=f({queryKey:["forge-psyche-patterns"],queryFn:Re}),C=f({queryKey:["forge-psyche-values"],queryFn:De}),P=f({queryKey:["forge-psyche-schema-catalog"],queryFn:Ue}),T=f({queryKey:["forge-psyche-modes"],queryFn:Ve}),L=f({queryKey:["forge-psyche-beliefs"],queryFn:We}),B=f({queryKey:["forge-psyche-behaviors"],queryFn:ze}),m=((Y=S.data)==null?void 0:Y.patterns)??[],D=((Z=C.data)==null?void 0:Z.values)??[],M=((X=P.data)==null?void 0:X.schemas)??[],U=((ee=T.data)==null?void 0:ee.modes)??[],V=((te=L.data)==null?void 0:te.beliefs)??[],W=((ae=B.data)==null?void 0:ae.behaviors)??[],g=et(i.selectedUserIds),z=d.get("focus"),pe=i.snapshot.dashboard.notesSummaryByEntity,x=f({enabled:c!==null,queryKey:["forge-note",c],queryFn:()=>oe(c)});Ge(z),y.useEffect(()=>{if(d.get("create")==="1"){p(!0),v(null),h({...k,userId:d.get("userId")??g}),b(d.get("sourceObservationNoteId"));const e=new URLSearchParams(d);e.delete("create"),e.delete("sourceObservationNoteId"),e.delete("userId"),j(e,{replace:!0})}},[g,d,j]);const G=Ie({mutationFn:async e=>{var o,E;const a=le.parse(e);if(u)return _e(u.id,a);const s=await Me(a);if(c){const O=((E=(o=x.data)==null?void 0:o.note)==null?void 0:E.id)===c?x.data.note:(await oe(c)).note;await Oe(c,{links:st([...O.links,{entityType:"behavior_pattern",entityId:s.pattern.id,anchorKey:null}])})}return s},onSuccess:async()=>{p(!1),v(null),b(null),h({...k,userId:g}),N(null),await Promise.all([n.invalidateQueries({queryKey:["forge-psyche-patterns"]}),n.invalidateQueries({queryKey:["forge-psyche-overview"]}),n.invalidateQueries({queryKey:["forge-psyche-self-observation-calendar"]}),qe(n),n.invalidateQueries({queryKey:["notes-index"]})])}}),he=D.map(e=>({value:e.id,label:R(e.title,e.user),description:$(e.valuedDirection,e.user),searchText:K([e.title,e.valuedDirection,e.description],e),kind:"value"})),me=M.map(e=>({value:e.title,label:e.title,description:`${e.description} ${Xe(e.family)}`,searchText:`${e.slug} ${e.family} ${e.schemaType}`,badge:t.jsx(A,{label:e.title,schemaType:e.schemaType,compact:!0}),menuBadge:t.jsx(A,{label:e.title,schemaType:e.schemaType,compact:!0})})),ge=U.map(e=>({value:e.id,label:R(e.title,e.user),description:$(e.archetype||e.family,e.user),searchText:K([e.title,e.archetype,e.family,e.persona],e),kind:"mode"})),ye=V.map(e=>({value:e.id,label:R(e.statement,e.user),description:$(e.flexibleAlternative||e.originNote,e.user),searchText:K([e.statement,e.flexibleAlternative,e.originNote,e.beliefType],e),kind:"belief"})),fe=async e=>{const{mode:a}=await Ke({family:"coping",archetype:"",title:e,persona:"",imagery:"",symbolicForm:"",facialExpression:"",fear:"",burden:"",protectiveJob:"",originContext:"",firstAppearanceAt:null,linkedPatternIds:[],linkedBehaviorIds:[],linkedValueIds:[],userId:I.userId});return Q(n,["forge-psyche-modes"],"modes",a),await n.invalidateQueries({queryKey:["forge-psyche-overview"]}),{value:a.id,label:a.title,description:a.archetype||a.family,kind:"mode"}},ve=async e=>{const{value:a}=await Qe({title:e,description:"",valuedDirection:e,whyItMatters:"",linkedGoalIds:[],linkedProjectIds:[],linkedTaskIds:[],committedActions:[],userId:I.userId});return Q(n,["forge-psyche-values"],"values",a),await n.invalidateQueries({queryKey:["forge-psyche-overview"]}),{value:a.id,label:a.title,description:a.valuedDirection,kind:"value"}},be=async e=>{const{belief:a}=await $e({schemaId:null,statement:e,beliefType:"absolute",originNote:"",confidence:60,evidenceFor:[],evidenceAgainst:[],flexibleAlternative:"",linkedValueIds:[],linkedBehaviorIds:[],linkedModeIds:[],linkedReportIds:[],userId:I.userId});return Q(n,["forge-psyche-beliefs"],"beliefs",a),await n.invalidateQueries({queryKey:["forge-psyche-overview"]}),{value:a.id,label:a.statement,description:a.flexibleAlternative||a.originNote,kind:"belief"}},H=y.useMemo(()=>m.filter(e=>!W.some(a=>a.kind==="away"&&a.linkedPatternIds.includes(e.id))),[m,W]),xe=m.slice(0,5).map((e,a)=>({id:e.id,label:`${e.linkedValueIds.length} values`,title:e.title,detail:e.preferredResponse,href:`/psyche/patterns?focus=${e.id}#pattern-lanes`,angle:-92+a*70,radius:150+a%2*14,tone:["rose","sky","violet","mint"][a%4]})),we=[{id:"loop",eyebrow:"Loop",title:"Name the pattern and the behavior it keeps producing",description:"This should feel like a recognizable loop, not a diagnostic label.",render:(e,a)=>{var s;return t.jsxs(t.Fragment,{children:[c?t.jsxs("div",{className:"rounded-[22px] border border-[color-mix(in_srgb,var(--tertiary)_24%,var(--ui-border-subtle)_76%)] bg-[color-mix(in_srgb,var(--tertiary)_10%,var(--ui-surface-1)_90%)] p-4",children:[t.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--tertiary)]",children:"Source observation"}),t.jsx("div",{className:"mt-2 break-words text-sm leading-6 text-[var(--ui-ink-medium)] [overflow-wrap:anywhere]",children:x.isLoading?"Loading the saved observation note...":(s=x.data)!=null&&s.note?rt(x.data.note.contentPlain||x.data.note.contentMarkdown):"Forge will link this pattern back to the saved observation when you submit it."})]}):null,t.jsx(Ze,{value:e.userId??null,users:i.snapshot.users,onChange:o=>a({userId:o}),defaultLabel:tt(i.snapshot.users.find(o=>o.id===g)??null,"Choose pattern owner"),help:"Patterns can belong to a human or bot user even when linked values, modes, or beliefs cross owners."}),t.jsx(l,{label:"Pattern name",description:"Give the loop a name you will recognize quickly later.",children:t.jsx(Ae,{value:e.title,onChange:o=>a({title:o.target.value}),placeholder:"Anxious reassurance loop"})}),t.jsx(l,{label:"What happens in the loop",description:"Describe the actual sequence of behavior, not the diagnosis.",children:t.jsx(w,{value:e.targetBehavior,onChange:o=>a({targetBehavior:o.target.value}),placeholder:"What do you actually do when the trigger hits?"})}),t.jsx(l,{label:"Description",description:"Write the loop in plain language so it stays usable in the future.",children:t.jsx(w,{value:e.description,onChange:o=>a({description:o.target.value}),placeholder:"Describe the loop in plain human language so it stays recognizable later."})})]})}},{id:"dynamics",eyebrow:"Dynamics",title:"Capture cues, payoff, cost, and the desired response",description:"The goal is to make the action map obvious at a glance.",render:(e,a)=>t.jsxs(t.Fragment,{children:[t.jsx(l,{label:"Common cues",description:"Add one cue per line so the trigger pattern stays easy to scan.",children:t.jsx(w,{value:e.cueContexts.join(`
2
2
  `),onChange:s=>a({cueContexts:s.target.value.split(`
3
3
  `).map(o=>o.trim()).filter(Boolean)}),placeholder:`One line per cue
4
4
  Silence after vulnerability
@@ -1 +1 @@
1
- import{c6 as B,b6 as Q,r as p,j as e,aC as R,cG as A,cH as F,cI as V,cJ as z}from"./vendor-Cpmju3nw.js";import{i as $,k as h}from"./state-BtwEvpO6.js";import{L as Y,e as G,B as j,bs as H,C as v,c as d,h as K,k as U,c0 as W,c1 as X,c2 as Z,c3 as ee,c4 as se,c5 as ae}from"./index-wEZUnRh0.js";import{P as ie}from"./page-hero-BRcqE3a4.js";import"./motion-DwjmC9aq.js";import"./ui-B9O-eUim.js";import"./board-CLOHbg6t.js";import"./forms-C5d5hTf2.js";const re={locale:"en",instructions:"Add questionnaire instructions here.",completionNote:"",presentationMode:"single_question",responseStyle:"four_point_frequency",itemIds:["item_1"],items:[{id:"item_1",prompt:"Sample question",shortLabel:"",description:"",helperText:"",required:!0,visibility:null,tags:[],options:[{key:"0",label:"Not at all",value:0,description:""},{key:"1",label:"Several days",value:1,description:""},{key:"2",label:"More than half the days",value:2,description:""},{key:"3",label:"Nearly every day",value:3,description:""}]}],sections:[{id:"section_1",title:"Section 1",description:"",visibility:null,itemIds:["item_1"]}],pageSize:null},ne={scores:[{key:"total",label:"Total score",description:"",valueType:"number",expression:{kind:"sum",itemIds:["item_1"]},dependsOnItemIds:["item_1"],missingPolicy:{mode:"require_all"},bands:[],roundTo:null,unitLabel:""}]},te={retrievalDate:"2026-04-06",sourceClass:"secondary_verified",scoringNotes:"Describe the scoring method and provenance here.",sources:[{label:"Primary source",url:"https://example.com",citation:"Replace with a real citation.",notes:""}]};function f(s){const n=(s==null?void 0:s.draftVersion)??(s==null?void 0:s.currentVersion);return{title:(s==null?void 0:s.title)??"",subtitle:(s==null?void 0:s.subtitle)??"",description:(s==null?void 0:s.description)??"",aliases:(s==null?void 0:s.aliases.join(", "))??"",symptomDomains:(s==null?void 0:s.symptomDomains.join(", "))??"",tags:(s==null?void 0:s.tags.join(", "))??"",sourceClass:(s==null?void 0:s.sourceClass)??"secondary_verified",availability:(s==null?void 0:s.availability)??"custom",isSelfReport:(s==null?void 0:s.isSelfReport)??!0,label:(n==null?void 0:n.label)??"Draft 1",definitionJson:JSON.stringify((n==null?void 0:n.definition)??re,null,2),scoringJson:JSON.stringify((n==null?void 0:n.scoring)??ne,null,2),provenanceJson:JSON.stringify((n==null?void 0:n.provenance)??te,null,2)}}function y(s){return s.split(",").map(n=>n.trim()).filter(Boolean)}function T(s){return{title:s.title.trim(),subtitle:s.subtitle.trim(),description:s.description.trim(),aliases:y(s.aliases),symptomDomains:y(s.symptomDomains),tags:y(s.tags),sourceClass:s.sourceClass,availability:s.availability,isSelfReport:s.isSelfReport,versionLabel:s.label.trim()||"Draft 1",definition:JSON.parse(s.definitionJson),scoring:JSON.parse(s.scoringJson),provenance:JSON.parse(s.provenanceJson),userId:"user_operator"}}const oe=[{id:"metadata",label:"Metadata",icon:A},{id:"structure",label:"Structure",icon:F},{id:"scoring",label:"Scoring",icon:V},{id:"publish",label:"Publish",icon:z}],o="text-sm font-medium text-[var(--ui-ink-medium)]",c="min-w-0 max-w-full rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-3 text-sm text-[var(--ui-ink-strong)] outline-none transition placeholder:text-[var(--ui-ink-faint)] focus:border-[color-mix(in_srgb,var(--primary)_45%,var(--ui-border-strong)_55%)] focus:bg-[var(--ui-surface-2)]",S=d(c,"resize-y whitespace-pre-wrap break-words font-mono leading-6 [overflow-wrap:anywhere]"),g="font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",w="min-w-0 rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-4",_="mx-1 rounded-[6px] bg-[var(--ui-surface-2)] px-1.5 py-0.5 text-xs text-[var(--ui-ink-strong)] [overflow-wrap:anywhere]";function xe(){var E,O;const{instrumentId:s}=B(),n=Q(),[m,I]=p.useState("metadata"),[r,t]=p.useState(()=>f(null)),[N,k]=p.useState(null),u=$({queryKey:["forge-psyche-questionnaire-builder",s],queryFn:()=>ae(s),enabled:!!s}),b=h({mutationFn:async()=>{var i;if(!s)throw new Error("Missing questionnaire id");const a=(i=u.data)==null?void 0:i.instrument;return a!=null&&a.isSystem?W(s,{userId:"user_operator"}):X(s)},onSuccess:a=>{t(f(a.instrument)),a.instrument.id!==s&&n(`/psyche/questionnaires/${a.instrument.id}/edit`,{replace:!0})}}),C=h({mutationFn:async()=>Z(T(r)),onSuccess:a=>{n(`/psyche/questionnaires/${a.instrument.id}/edit`,{replace:!0})}}),J=h({mutationFn:async()=>{if(!s)throw new Error("Missing questionnaire id");const a=T(r);return ee(s,{...a,label:a.versionLabel})}}),P=h({mutationFn:async()=>{if(!s)throw new Error("Missing questionnaire id");return se(s,{label:r.label})},onSuccess:a=>{n(`/psyche/questionnaires/${a.instrument.id}`)}}),q=(E=u.data)==null?void 0:E.instrument;p.useEffect(()=>{if(!s){t(f(null));return}const a=q;if(a){if(!a.draftVersion&&!b.isPending){b.mutate();return}t(f(a))}},[s,b.isPending,q]);const M=s?"Edit questionnaire":"Build questionnaire",l=((O=u.data)==null?void 0:O.instrument)??null,D=u.isLoading||b.isPending||C.isPending||J.isPending||P.isPending,x=p.useMemo(()=>{try{return{definition:JSON.parse(r.definitionJson),scoring:JSON.parse(r.scoringJson)}}catch{return null}},[r.definitionJson,r.scoringJson]);if(s&&u.isLoading&&!l)return e.jsx(Y,{eyebrow:"Questionnaire builder",title:"Loading editable draft",description:"Preparing the current questionnaire draft so the builder can open on real versioned data."});if(u.isError)return e.jsx(G,{eyebrow:"Questionnaire builder",error:u.error,onRetry:()=>void u.refetch()});const L=async()=>{try{k(null),s?await J.mutateAsync():await C.mutateAsync()}catch(a){k(a instanceof Error?a.message:"Unable to save questionnaire draft.")}};return e.jsxs("div",{className:"grid gap-5",children:[e.jsx(ie,{eyebrow:"Psyche",title:M,description:"Edit versioned questionnaire metadata, structure, scoring, and publication state directly in the app. Seeded instruments branch into editable drafts before any change is made.",badge:s?(l==null?void 0:l.title)??"Draft":"New draft",actions:s?e.jsx(R,{to:`/psyche/questionnaires/${s}`,children:e.jsx(j,{variant:"secondary",children:"Back to detail"})}):null}),e.jsx(H,{}),e.jsx(v,{className:"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-section)]",children:e.jsx("div",{className:"grid gap-3 md:grid-cols-4",children:oe.map(a=>e.jsxs("button",{type:"button",className:d("min-w-0 rounded-[8px] border px-4 py-4 text-left transition",m===a.id?"border-[color-mix(in_srgb,var(--success)_42%,var(--ui-border-subtle)_58%)] bg-[var(--ui-success-soft)] text-[var(--ui-ink-strong)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-soft)] hover:bg-[var(--ui-surface-2)]"),onClick:()=>I(a.id),children:[e.jsx(a.icon,{className:"size-4 shrink-0"}),e.jsx("div",{className:"mt-3 min-w-0 break-words text-sm font-medium",children:a.label})]},a.id))})}),e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.1fr)_minmax(18rem,0.9fr)]",children:[e.jsxs(v,{className:"min-w-0 border-[var(--ui-border-subtle)] bg-[var(--ui-surface-section)]",children:[m==="metadata"?e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:o,children:"Title"}),e.jsx("input",{value:r.title,onChange:a=>t(i=>({...i,title:a.target.value})),className:c})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:o,children:"Subtitle"}),e.jsx("input",{value:r.subtitle,onChange:a=>t(i=>({...i,subtitle:a.target.value})),className:c})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:o,children:"Description"}),e.jsx("textarea",{value:r.description,onChange:a=>t(i=>({...i,description:a.target.value})),className:d(c,"min-h-28 resize-y")})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:o,children:"Aliases"}),e.jsx("input",{value:r.aliases,onChange:a=>t(i=>({...i,aliases:a.target.value})),className:c})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:o,children:"Symptom domains"}),e.jsx("input",{value:r.symptomDomains,onChange:a=>t(i=>({...i,symptomDomains:a.target.value})),className:c})]})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:o,children:"Tags"}),e.jsx("input",{value:r.tags,onChange:a=>t(i=>({...i,tags:a.target.value})),className:c})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:o,children:"Source class"}),e.jsx("select",{value:r.sourceClass,onChange:a=>t(i=>({...i,sourceClass:a.target.value})),className:c,children:["public_domain","free_use","open_access","open_noncommercial","free_clinician","secondary_verified"].map(a=>e.jsx("option",{value:a,children:a.replaceAll("_"," ")},a))})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:o,children:"Availability"}),e.jsx("select",{value:r.availability,onChange:a=>t(i=>({...i,availability:a.target.value})),className:c,children:["open","free_clinician","custom"].map(a=>e.jsx("option",{value:a,children:a.replaceAll("_"," ")},a))})]})]})]}):null,m==="structure"?e.jsxs("div",{className:"grid min-w-0 gap-2",children:[e.jsx("span",{className:o,children:"Definition JSON"}),e.jsxs("div",{className:"min-w-0 break-words text-sm leading-6 text-[var(--ui-ink-soft)] [overflow-wrap:anywhere]",children:["Items and sections can declare",e.jsx("code",{className:_,children:"visibility.script"}),"rules such as",e.jsx("code",{className:_,children:"audit_1 > 0"}),"or",e.jsx("code",{className:_,children:'answered(question_12) and option(question_12) == "yes"'}),"."]}),e.jsx("textarea",{value:r.definitionJson,onChange:a=>t(i=>({...i,definitionJson:a.target.value})),className:d(S,"min-h-[32rem]")})]}):null,m==="scoring"?e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:o,children:"Scoring JSON"}),e.jsx("textarea",{value:r.scoringJson,onChange:a=>t(i=>({...i,scoringJson:a.target.value})),className:d(S,"min-h-[24rem]")})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:o,children:"Provenance JSON"}),e.jsx("textarea",{value:r.provenanceJson,onChange:a=>t(i=>({...i,provenanceJson:a.target.value})),className:d(S,"min-h-[16rem]")})]})]}):null,m==="publish"?e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:o,children:"Version label"}),e.jsx("input",{value:r.label,onChange:a=>t(i=>({...i,label:a.target.value})),className:c})]}),x?e.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[e.jsxs("div",{className:w,children:[e.jsx("div",{className:g,children:"Items"}),e.jsx("div",{className:"mt-2 text-2xl font-semibold text-[var(--ui-ink-strong)]",children:x.definition.items.length})]}),e.jsxs("div",{className:w,children:[e.jsx("div",{className:g,children:"Sections"}),e.jsx("div",{className:"mt-2 text-2xl font-semibold text-[var(--ui-ink-strong)]",children:x.definition.sections.length})]}),e.jsxs("div",{className:w,children:[e.jsx("div",{className:g,children:"Scores"}),e.jsx("div",{className:"mt-2 text-2xl font-semibold text-[var(--ui-ink-strong)]",children:x.scoring.scores.length})]})]}):null,e.jsx("p",{className:"text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Publishing freezes the current draft into an immutable version for future runs. Past run history will always keep the version it was scored against."})]}):null]}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs(v,{className:"min-w-0 border-[var(--ui-border-subtle)] bg-[var(--ui-surface-section)]",children:[e.jsx("div",{className:g,children:"Draft posture"}),l!=null&&l.isSystem?e.jsx("div",{className:"mt-4",children:e.jsx(K,{eyebrow:"System seed",title:"This started as a read-only seed",description:"The builder branched it into a user-owned draft before exposing any editable state."})}):e.jsxs("div",{className:"mt-4 grid gap-2",children:[e.jsx(U,{className:"w-fit border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:l!=null&&l.draftVersion?"Draft available":"New draft"}),e.jsx("div",{className:"break-words text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Save updates whenever the metadata or JSON changes, then publish once the definition is ready for scoring and longitudinal history."})]})]}),e.jsxs(v,{className:"min-w-0 border-[var(--ui-border-subtle)] bg-[var(--ui-surface-section)]",children:[e.jsx("div",{className:g,children:"Actions"}),e.jsxs("div",{className:"mt-4 grid gap-3",children:[e.jsx(j,{onClick:()=>void L(),disabled:D,children:"Save draft"}),s?e.jsx(j,{variant:"secondary",onClick:()=>P.mutate(),disabled:D||!!N,children:"Publish version"}):null,N?e.jsx("div",{className:"break-words rounded-[8px] border border-[var(--danger)]/20 bg-[var(--ui-danger-soft)] px-4 py-3 text-sm text-[color-mix(in_srgb,var(--danger)_76%,var(--ui-ink-strong)_24%)]",children:N}):null]})]})]})]})]})}export{xe as PsycheQuestionnaireBuilderPage};
1
+ import{c6 as B,b6 as Q,r as p,j as e,aC as R,cG as A,cH as F,cI as V,cJ as z}from"./vendor-Cpmju3nw.js";import{i as $,k as h}from"./state-BtwEvpO6.js";import{L as Y,e as G,B as j,bs as H,C as v,c as d,h as K,k as U,c0 as W,c1 as X,c2 as Z,c3 as ee,c4 as se,c5 as ae}from"./index-BaiwtAgo.js";import{P as ie}from"./page-hero-C0MpI3MM.js";import"./motion-DwjmC9aq.js";import"./ui-B9O-eUim.js";import"./board-CLOHbg6t.js";import"./forms-C5d5hTf2.js";const re={locale:"en",instructions:"Add questionnaire instructions here.",completionNote:"",presentationMode:"single_question",responseStyle:"four_point_frequency",itemIds:["item_1"],items:[{id:"item_1",prompt:"Sample question",shortLabel:"",description:"",helperText:"",required:!0,visibility:null,tags:[],options:[{key:"0",label:"Not at all",value:0,description:""},{key:"1",label:"Several days",value:1,description:""},{key:"2",label:"More than half the days",value:2,description:""},{key:"3",label:"Nearly every day",value:3,description:""}]}],sections:[{id:"section_1",title:"Section 1",description:"",visibility:null,itemIds:["item_1"]}],pageSize:null},ne={scores:[{key:"total",label:"Total score",description:"",valueType:"number",expression:{kind:"sum",itemIds:["item_1"]},dependsOnItemIds:["item_1"],missingPolicy:{mode:"require_all"},bands:[],roundTo:null,unitLabel:""}]},te={retrievalDate:"2026-04-06",sourceClass:"secondary_verified",scoringNotes:"Describe the scoring method and provenance here.",sources:[{label:"Primary source",url:"https://example.com",citation:"Replace with a real citation.",notes:""}]};function f(s){const n=(s==null?void 0:s.draftVersion)??(s==null?void 0:s.currentVersion);return{title:(s==null?void 0:s.title)??"",subtitle:(s==null?void 0:s.subtitle)??"",description:(s==null?void 0:s.description)??"",aliases:(s==null?void 0:s.aliases.join(", "))??"",symptomDomains:(s==null?void 0:s.symptomDomains.join(", "))??"",tags:(s==null?void 0:s.tags.join(", "))??"",sourceClass:(s==null?void 0:s.sourceClass)??"secondary_verified",availability:(s==null?void 0:s.availability)??"custom",isSelfReport:(s==null?void 0:s.isSelfReport)??!0,label:(n==null?void 0:n.label)??"Draft 1",definitionJson:JSON.stringify((n==null?void 0:n.definition)??re,null,2),scoringJson:JSON.stringify((n==null?void 0:n.scoring)??ne,null,2),provenanceJson:JSON.stringify((n==null?void 0:n.provenance)??te,null,2)}}function y(s){return s.split(",").map(n=>n.trim()).filter(Boolean)}function T(s){return{title:s.title.trim(),subtitle:s.subtitle.trim(),description:s.description.trim(),aliases:y(s.aliases),symptomDomains:y(s.symptomDomains),tags:y(s.tags),sourceClass:s.sourceClass,availability:s.availability,isSelfReport:s.isSelfReport,versionLabel:s.label.trim()||"Draft 1",definition:JSON.parse(s.definitionJson),scoring:JSON.parse(s.scoringJson),provenance:JSON.parse(s.provenanceJson),userId:"user_operator"}}const oe=[{id:"metadata",label:"Metadata",icon:A},{id:"structure",label:"Structure",icon:F},{id:"scoring",label:"Scoring",icon:V},{id:"publish",label:"Publish",icon:z}],o="text-sm font-medium text-[var(--ui-ink-medium)]",c="min-w-0 max-w-full rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-3 text-sm text-[var(--ui-ink-strong)] outline-none transition placeholder:text-[var(--ui-ink-faint)] focus:border-[color-mix(in_srgb,var(--primary)_45%,var(--ui-border-strong)_55%)] focus:bg-[var(--ui-surface-2)]",S=d(c,"resize-y whitespace-pre-wrap break-words font-mono leading-6 [overflow-wrap:anywhere]"),g="font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",w="min-w-0 rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-4",_="mx-1 rounded-[6px] bg-[var(--ui-surface-2)] px-1.5 py-0.5 text-xs text-[var(--ui-ink-strong)] [overflow-wrap:anywhere]";function xe(){var E,O;const{instrumentId:s}=B(),n=Q(),[m,I]=p.useState("metadata"),[r,t]=p.useState(()=>f(null)),[N,k]=p.useState(null),u=$({queryKey:["forge-psyche-questionnaire-builder",s],queryFn:()=>ae(s),enabled:!!s}),b=h({mutationFn:async()=>{var i;if(!s)throw new Error("Missing questionnaire id");const a=(i=u.data)==null?void 0:i.instrument;return a!=null&&a.isSystem?W(s,{userId:"user_operator"}):X(s)},onSuccess:a=>{t(f(a.instrument)),a.instrument.id!==s&&n(`/psyche/questionnaires/${a.instrument.id}/edit`,{replace:!0})}}),C=h({mutationFn:async()=>Z(T(r)),onSuccess:a=>{n(`/psyche/questionnaires/${a.instrument.id}/edit`,{replace:!0})}}),J=h({mutationFn:async()=>{if(!s)throw new Error("Missing questionnaire id");const a=T(r);return ee(s,{...a,label:a.versionLabel})}}),P=h({mutationFn:async()=>{if(!s)throw new Error("Missing questionnaire id");return se(s,{label:r.label})},onSuccess:a=>{n(`/psyche/questionnaires/${a.instrument.id}`)}}),q=(E=u.data)==null?void 0:E.instrument;p.useEffect(()=>{if(!s){t(f(null));return}const a=q;if(a){if(!a.draftVersion&&!b.isPending){b.mutate();return}t(f(a))}},[s,b.isPending,q]);const M=s?"Edit questionnaire":"Build questionnaire",l=((O=u.data)==null?void 0:O.instrument)??null,D=u.isLoading||b.isPending||C.isPending||J.isPending||P.isPending,x=p.useMemo(()=>{try{return{definition:JSON.parse(r.definitionJson),scoring:JSON.parse(r.scoringJson)}}catch{return null}},[r.definitionJson,r.scoringJson]);if(s&&u.isLoading&&!l)return e.jsx(Y,{eyebrow:"Questionnaire builder",title:"Loading editable draft",description:"Preparing the current questionnaire draft so the builder can open on real versioned data."});if(u.isError)return e.jsx(G,{eyebrow:"Questionnaire builder",error:u.error,onRetry:()=>void u.refetch()});const L=async()=>{try{k(null),s?await J.mutateAsync():await C.mutateAsync()}catch(a){k(a instanceof Error?a.message:"Unable to save questionnaire draft.")}};return e.jsxs("div",{className:"grid gap-5",children:[e.jsx(ie,{eyebrow:"Psyche",title:M,description:"Edit versioned questionnaire metadata, structure, scoring, and publication state directly in the app. Seeded instruments branch into editable drafts before any change is made.",badge:s?(l==null?void 0:l.title)??"Draft":"New draft",actions:s?e.jsx(R,{to:`/psyche/questionnaires/${s}`,children:e.jsx(j,{variant:"secondary",children:"Back to detail"})}):null}),e.jsx(H,{}),e.jsx(v,{className:"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-section)]",children:e.jsx("div",{className:"grid gap-3 md:grid-cols-4",children:oe.map(a=>e.jsxs("button",{type:"button",className:d("min-w-0 rounded-[8px] border px-4 py-4 text-left transition",m===a.id?"border-[color-mix(in_srgb,var(--success)_42%,var(--ui-border-subtle)_58%)] bg-[var(--ui-success-soft)] text-[var(--ui-ink-strong)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-soft)] hover:bg-[var(--ui-surface-2)]"),onClick:()=>I(a.id),children:[e.jsx(a.icon,{className:"size-4 shrink-0"}),e.jsx("div",{className:"mt-3 min-w-0 break-words text-sm font-medium",children:a.label})]},a.id))})}),e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.1fr)_minmax(18rem,0.9fr)]",children:[e.jsxs(v,{className:"min-w-0 border-[var(--ui-border-subtle)] bg-[var(--ui-surface-section)]",children:[m==="metadata"?e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:o,children:"Title"}),e.jsx("input",{value:r.title,onChange:a=>t(i=>({...i,title:a.target.value})),className:c})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:o,children:"Subtitle"}),e.jsx("input",{value:r.subtitle,onChange:a=>t(i=>({...i,subtitle:a.target.value})),className:c})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:o,children:"Description"}),e.jsx("textarea",{value:r.description,onChange:a=>t(i=>({...i,description:a.target.value})),className:d(c,"min-h-28 resize-y")})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:o,children:"Aliases"}),e.jsx("input",{value:r.aliases,onChange:a=>t(i=>({...i,aliases:a.target.value})),className:c})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:o,children:"Symptom domains"}),e.jsx("input",{value:r.symptomDomains,onChange:a=>t(i=>({...i,symptomDomains:a.target.value})),className:c})]})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:o,children:"Tags"}),e.jsx("input",{value:r.tags,onChange:a=>t(i=>({...i,tags:a.target.value})),className:c})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:o,children:"Source class"}),e.jsx("select",{value:r.sourceClass,onChange:a=>t(i=>({...i,sourceClass:a.target.value})),className:c,children:["public_domain","free_use","open_access","open_noncommercial","free_clinician","secondary_verified"].map(a=>e.jsx("option",{value:a,children:a.replaceAll("_"," ")},a))})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:o,children:"Availability"}),e.jsx("select",{value:r.availability,onChange:a=>t(i=>({...i,availability:a.target.value})),className:c,children:["open","free_clinician","custom"].map(a=>e.jsx("option",{value:a,children:a.replaceAll("_"," ")},a))})]})]})]}):null,m==="structure"?e.jsxs("div",{className:"grid min-w-0 gap-2",children:[e.jsx("span",{className:o,children:"Definition JSON"}),e.jsxs("div",{className:"min-w-0 break-words text-sm leading-6 text-[var(--ui-ink-soft)] [overflow-wrap:anywhere]",children:["Items and sections can declare",e.jsx("code",{className:_,children:"visibility.script"}),"rules such as",e.jsx("code",{className:_,children:"audit_1 > 0"}),"or",e.jsx("code",{className:_,children:'answered(question_12) and option(question_12) == "yes"'}),"."]}),e.jsx("textarea",{value:r.definitionJson,onChange:a=>t(i=>({...i,definitionJson:a.target.value})),className:d(S,"min-h-[32rem]")})]}):null,m==="scoring"?e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:o,children:"Scoring JSON"}),e.jsx("textarea",{value:r.scoringJson,onChange:a=>t(i=>({...i,scoringJson:a.target.value})),className:d(S,"min-h-[24rem]")})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:o,children:"Provenance JSON"}),e.jsx("textarea",{value:r.provenanceJson,onChange:a=>t(i=>({...i,provenanceJson:a.target.value})),className:d(S,"min-h-[16rem]")})]})]}):null,m==="publish"?e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:o,children:"Version label"}),e.jsx("input",{value:r.label,onChange:a=>t(i=>({...i,label:a.target.value})),className:c})]}),x?e.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[e.jsxs("div",{className:w,children:[e.jsx("div",{className:g,children:"Items"}),e.jsx("div",{className:"mt-2 text-2xl font-semibold text-[var(--ui-ink-strong)]",children:x.definition.items.length})]}),e.jsxs("div",{className:w,children:[e.jsx("div",{className:g,children:"Sections"}),e.jsx("div",{className:"mt-2 text-2xl font-semibold text-[var(--ui-ink-strong)]",children:x.definition.sections.length})]}),e.jsxs("div",{className:w,children:[e.jsx("div",{className:g,children:"Scores"}),e.jsx("div",{className:"mt-2 text-2xl font-semibold text-[var(--ui-ink-strong)]",children:x.scoring.scores.length})]})]}):null,e.jsx("p",{className:"text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Publishing freezes the current draft into an immutable version for future runs. Past run history will always keep the version it was scored against."})]}):null]}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs(v,{className:"min-w-0 border-[var(--ui-border-subtle)] bg-[var(--ui-surface-section)]",children:[e.jsx("div",{className:g,children:"Draft posture"}),l!=null&&l.isSystem?e.jsx("div",{className:"mt-4",children:e.jsx(K,{eyebrow:"System seed",title:"This started as a read-only seed",description:"The builder branched it into a user-owned draft before exposing any editable state."})}):e.jsxs("div",{className:"mt-4 grid gap-2",children:[e.jsx(U,{className:"w-fit border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:l!=null&&l.draftVersion?"Draft available":"New draft"}),e.jsx("div",{className:"break-words text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Save updates whenever the metadata or JSON changes, then publish once the definition is ready for scoring and longitudinal history."})]})]}),e.jsxs(v,{className:"min-w-0 border-[var(--ui-border-subtle)] bg-[var(--ui-surface-section)]",children:[e.jsx("div",{className:g,children:"Actions"}),e.jsxs("div",{className:"mt-4 grid gap-3",children:[e.jsx(j,{onClick:()=>void L(),disabled:D,children:"Save draft"}),s?e.jsx(j,{variant:"secondary",onClick:()=>P.mutate(),disabled:D||!!N,children:"Publish version"}):null,N?e.jsx("div",{className:"break-words rounded-[8px] border border-[var(--danger)]/20 bg-[var(--ui-danger-soft)] px-4 py-3 text-sm text-[color-mix(in_srgb,var(--danger)_76%,var(--ui-ink-strong)_24%)]",children:N}):null]})]})]})]})]})}export{xe as PsycheQuestionnaireBuilderPage};
@@ -1 +1 @@
1
- import{c6 as k,j as e,aC as o,b9 as S,cG as L,cK as C}from"./vendor-Cpmju3nw.js";import{i as P}from"./state-BtwEvpO6.js";import{L as $,e as _,B as m,bs as q,C as u,k as c,h as E,c5 as A}from"./index-wEZUnRh0.js";import{P as Q}from"./page-hero-BRcqE3a4.js";import"./motion-DwjmC9aq.js";import"./ui-B9O-eUim.js";import"./board-CLOHbg6t.js";import"./forms-C5d5hTf2.js";const x="font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",v="min-w-0 rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-4",h="text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",b="mt-2 break-words text-sm font-medium text-[var(--ui-ink-strong)] [overflow-wrap:anywhere]",j="block min-w-0 rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-4 transition hover:bg-[var(--ui-surface-2)]";function D({history:n}){var p,f;const a=[...n].reverse().filter(i=>typeof i.primaryScore=="number");if(a.length===0)return null;const s=a.map(i=>Number(i.primaryScore)),t=Math.min(...s),d=Math.max(...s),l=Math.max(1,d-t),r=a.map((i,w)=>{const y=a.length===1?50:8+w/(a.length-1)*84,N=84-(Number(i.primaryScore)-t)/l*68;return{x:y,y:N,label:new Date(i.completedAt).toLocaleDateString(void 0,{month:"short",day:"numeric"}),score:Number(i.primaryScore)}}),g=r.map(i=>`${i.x},${i.y}`).join(" ");return e.jsxs("div",{className:"mt-4 min-w-0 rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-3",children:[e.jsxs("svg",{viewBox:"0 0 100 100",role:"img","aria-label":"Questionnaire score history",className:"h-56 w-full overflow-visible",preserveAspectRatio:"none",children:[[16,50,84].map(i=>e.jsx("line",{x1:"6",x2:"94",y1:i,y2:i,stroke:"var(--ui-border-subtle)",strokeWidth:"0.6",vectorEffect:"non-scaling-stroke"},i)),e.jsx("polyline",{fill:"none",points:g,stroke:"var(--success)",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2.5",vectorEffect:"non-scaling-stroke"}),r.map(i=>e.jsxs("g",{children:[e.jsx("circle",{cx:i.x,cy:i.y,r:"2.8",fill:"var(--ui-surface-section)",stroke:"var(--success)",strokeWidth:"1.4",vectorEffect:"non-scaling-stroke"}),e.jsx("title",{children:`${i.label}: ${i.score}`})]},`${i.label}-${i.score}-${i.x}`))]}),e.jsxs("div",{className:"mt-2 flex min-w-0 flex-wrap justify-between gap-2 text-xs text-[var(--ui-ink-faint)]",children:[e.jsxs("span",{children:["Oldest ",(p=r[0])==null?void 0:p.label]}),e.jsxs("span",{children:["Latest ",(f=r.at(-1))==null?void 0:f.label]})]})]})}function W(){var l;const{instrumentId:n=""}=k(),a=P({queryKey:["forge-psyche-questionnaire",n],queryFn:()=>A(n),enabled:n.length>0});if(a.isLoading)return e.jsx($,{eyebrow:"Questionnaire",title:"Loading questionnaire detail",description:"Hydrating the versioned definition, source provenance, and run history."});if(a.isError||!((l=a.data)!=null&&l.instrument))return e.jsx(_,{eyebrow:"Questionnaire",error:a.error,onRetry:()=>void a.refetch()});const s=a.data.instrument,t=s.currentVersion??s.draftVersion,d=!s.isSystem;return e.jsxs("div",{className:"grid gap-5",children:[e.jsx(Q,{eyebrow:"Psyche",title:s.title,description:s.description,badge:`${s.itemCount} items`,actions:e.jsxs(e.Fragment,{children:[e.jsx(o,{to:`/psyche/questionnaires/${s.id}/take`,children:e.jsxs(m,{children:[e.jsx(S,{className:"mr-2 size-4"}),"Start run"]})}),d?e.jsx(o,{to:`/psyche/questionnaires/${s.id}/edit`,children:e.jsxs(m,{variant:"secondary",children:[e.jsx(L,{className:"mr-2 size-4"}),"Edit draft"]})}):e.jsx(o,{to:`/psyche/questionnaires/${s.id}/edit`,children:e.jsxs(m,{variant:"secondary",children:[e.jsx(C,{className:"mr-2 size-4"}),"Clone to draft"]})})]})}),e.jsx(q,{}),e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.05fr)_minmax(18rem,0.95fr)]",children:[e.jsxs(u,{className:"min-w-0 border-[var(--ui-border-subtle)] bg-[var(--ui-surface-section)]",children:[e.jsx("div",{className:x,children:"Guided definition"}),e.jsxs("div",{className:"mt-4 grid gap-4 md:grid-cols-3",children:[e.jsxs("div",{className:v,children:[e.jsx("div",{className:h,children:"Flow"}),e.jsx("div",{className:b,children:s.presentationMode.replaceAll("_"," ")})]}),e.jsxs("div",{className:v,children:[e.jsx("div",{className:h,children:"Response style"}),e.jsx("div",{className:b,children:s.responseStyle.replaceAll("_"," ")})]}),e.jsxs("div",{className:v,children:[e.jsx("div",{className:h,children:"Version"}),e.jsx("div",{className:b,children:s.currentVersionNumber?`v${s.currentVersionNumber}`:"Draft"})]})]}),t?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"mt-5 break-words text-sm leading-6 text-[var(--ui-ink-soft)] [overflow-wrap:anywhere]",children:t.definition.instructions}),e.jsx("div",{className:"mt-5 grid gap-3",children:t.definition.sections.map(r=>e.jsx("div",{className:"min-w-0 rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-4",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"break-words text-sm font-medium text-[var(--ui-ink-strong)] [overflow-wrap:anywhere]",children:r.title}),r.description?e.jsx("div",{className:"mt-1 break-words text-sm text-[var(--ui-ink-soft)] [overflow-wrap:anywhere]",children:r.description}):null]}),e.jsxs(c,{className:"shrink-0 border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:[r.itemIds.length," items"]})]})},r.id))})]}):null]}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs(u,{className:"min-w-0 border-[var(--ui-border-subtle)] bg-[var(--ui-surface-section)]",children:[e.jsx("div",{className:x,children:"Provenance"}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-2",children:[e.jsx(c,{className:"border border-[var(--ui-border-subtle)] bg-[var(--ui-info-soft)] text-[color-mix(in_srgb,var(--info)_76%,var(--ui-ink-strong)_24%)]",children:s.sourceClass.replaceAll("_"," ")}),e.jsx(c,{className:"border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:s.availability.replaceAll("_"," ")}),s.symptomDomains.map(r=>e.jsx(c,{className:"max-w-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:r},r))]}),t?e.jsx("div",{className:"mt-4 grid gap-3",children:t.provenance.sources.map(r=>e.jsxs("a",{href:r.url,target:"_blank",rel:"noreferrer",className:j,children:[e.jsx("div",{className:"break-words text-sm font-medium text-[var(--ui-ink-strong)] [overflow-wrap:anywhere]",children:r.label}),e.jsx("div",{className:"mt-2 break-words text-sm leading-6 text-[var(--ui-ink-soft)] [overflow-wrap:anywhere]",children:r.citation})]},r.url))}):null]}),e.jsxs(u,{className:"min-w-0 border-[var(--ui-border-subtle)] bg-[var(--ui-surface-section)]",children:[e.jsx("div",{className:x,children:"History over time"}),s.history.length===0?e.jsx("div",{className:"mt-4",children:e.jsx(E,{eyebrow:"Run history",title:"No completed runs yet",description:"Complete the first guided run and the longitudinal score trace will appear here."})}):e.jsxs(e.Fragment,{children:[e.jsx(D,{history:s.history}),e.jsx("div",{className:"mt-4 grid gap-3",children:s.history.slice(0,5).map(r=>e.jsx(o,{to:`/psyche/questionnaire-runs/${r.runId}`,className:j,children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"break-words text-sm font-medium text-[var(--ui-ink-strong)] [overflow-wrap:anywhere]",children:r.primaryScoreLabel||"Primary score"}),e.jsx("div",{className:"mt-1 break-words text-sm text-[var(--ui-ink-soft)] [overflow-wrap:anywhere]",children:new Date(r.completedAt).toLocaleString()})]}),e.jsxs("div",{className:"shrink-0 text-right",children:[e.jsx("div",{className:"text-lg font-semibold text-[var(--ui-ink-strong)]",children:r.primaryScore??"—"}),r.bandLabel?e.jsx("div",{className:"max-w-[10rem] break-words text-xs uppercase tracking-[0.16em] text-[color-mix(in_srgb,var(--success)_76%,var(--ui-ink-strong)_24%)] [overflow-wrap:anywhere]",children:r.bandLabel}):null]})]})},r.runId))})]})]})]})]})]})}export{W as PsycheQuestionnaireDetailPage};
1
+ import{c6 as k,j as e,aC as o,b9 as S,cG as L,cK as C}from"./vendor-Cpmju3nw.js";import{i as P}from"./state-BtwEvpO6.js";import{L as $,e as _,B as m,bs as q,C as u,k as c,h as E,c5 as A}from"./index-BaiwtAgo.js";import{P as Q}from"./page-hero-C0MpI3MM.js";import"./motion-DwjmC9aq.js";import"./ui-B9O-eUim.js";import"./board-CLOHbg6t.js";import"./forms-C5d5hTf2.js";const x="font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",v="min-w-0 rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-4",h="text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",b="mt-2 break-words text-sm font-medium text-[var(--ui-ink-strong)] [overflow-wrap:anywhere]",j="block min-w-0 rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-4 transition hover:bg-[var(--ui-surface-2)]";function D({history:n}){var p,f;const a=[...n].reverse().filter(i=>typeof i.primaryScore=="number");if(a.length===0)return null;const s=a.map(i=>Number(i.primaryScore)),t=Math.min(...s),d=Math.max(...s),l=Math.max(1,d-t),r=a.map((i,w)=>{const y=a.length===1?50:8+w/(a.length-1)*84,N=84-(Number(i.primaryScore)-t)/l*68;return{x:y,y:N,label:new Date(i.completedAt).toLocaleDateString(void 0,{month:"short",day:"numeric"}),score:Number(i.primaryScore)}}),g=r.map(i=>`${i.x},${i.y}`).join(" ");return e.jsxs("div",{className:"mt-4 min-w-0 rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-3",children:[e.jsxs("svg",{viewBox:"0 0 100 100",role:"img","aria-label":"Questionnaire score history",className:"h-56 w-full overflow-visible",preserveAspectRatio:"none",children:[[16,50,84].map(i=>e.jsx("line",{x1:"6",x2:"94",y1:i,y2:i,stroke:"var(--ui-border-subtle)",strokeWidth:"0.6",vectorEffect:"non-scaling-stroke"},i)),e.jsx("polyline",{fill:"none",points:g,stroke:"var(--success)",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2.5",vectorEffect:"non-scaling-stroke"}),r.map(i=>e.jsxs("g",{children:[e.jsx("circle",{cx:i.x,cy:i.y,r:"2.8",fill:"var(--ui-surface-section)",stroke:"var(--success)",strokeWidth:"1.4",vectorEffect:"non-scaling-stroke"}),e.jsx("title",{children:`${i.label}: ${i.score}`})]},`${i.label}-${i.score}-${i.x}`))]}),e.jsxs("div",{className:"mt-2 flex min-w-0 flex-wrap justify-between gap-2 text-xs text-[var(--ui-ink-faint)]",children:[e.jsxs("span",{children:["Oldest ",(p=r[0])==null?void 0:p.label]}),e.jsxs("span",{children:["Latest ",(f=r.at(-1))==null?void 0:f.label]})]})]})}function W(){var l;const{instrumentId:n=""}=k(),a=P({queryKey:["forge-psyche-questionnaire",n],queryFn:()=>A(n),enabled:n.length>0});if(a.isLoading)return e.jsx($,{eyebrow:"Questionnaire",title:"Loading questionnaire detail",description:"Hydrating the versioned definition, source provenance, and run history."});if(a.isError||!((l=a.data)!=null&&l.instrument))return e.jsx(_,{eyebrow:"Questionnaire",error:a.error,onRetry:()=>void a.refetch()});const s=a.data.instrument,t=s.currentVersion??s.draftVersion,d=!s.isSystem;return e.jsxs("div",{className:"grid gap-5",children:[e.jsx(Q,{eyebrow:"Psyche",title:s.title,description:s.description,badge:`${s.itemCount} items`,actions:e.jsxs(e.Fragment,{children:[e.jsx(o,{to:`/psyche/questionnaires/${s.id}/take`,children:e.jsxs(m,{children:[e.jsx(S,{className:"mr-2 size-4"}),"Start run"]})}),d?e.jsx(o,{to:`/psyche/questionnaires/${s.id}/edit`,children:e.jsxs(m,{variant:"secondary",children:[e.jsx(L,{className:"mr-2 size-4"}),"Edit draft"]})}):e.jsx(o,{to:`/psyche/questionnaires/${s.id}/edit`,children:e.jsxs(m,{variant:"secondary",children:[e.jsx(C,{className:"mr-2 size-4"}),"Clone to draft"]})})]})}),e.jsx(q,{}),e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.05fr)_minmax(18rem,0.95fr)]",children:[e.jsxs(u,{className:"min-w-0 border-[var(--ui-border-subtle)] bg-[var(--ui-surface-section)]",children:[e.jsx("div",{className:x,children:"Guided definition"}),e.jsxs("div",{className:"mt-4 grid gap-4 md:grid-cols-3",children:[e.jsxs("div",{className:v,children:[e.jsx("div",{className:h,children:"Flow"}),e.jsx("div",{className:b,children:s.presentationMode.replaceAll("_"," ")})]}),e.jsxs("div",{className:v,children:[e.jsx("div",{className:h,children:"Response style"}),e.jsx("div",{className:b,children:s.responseStyle.replaceAll("_"," ")})]}),e.jsxs("div",{className:v,children:[e.jsx("div",{className:h,children:"Version"}),e.jsx("div",{className:b,children:s.currentVersionNumber?`v${s.currentVersionNumber}`:"Draft"})]})]}),t?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"mt-5 break-words text-sm leading-6 text-[var(--ui-ink-soft)] [overflow-wrap:anywhere]",children:t.definition.instructions}),e.jsx("div",{className:"mt-5 grid gap-3",children:t.definition.sections.map(r=>e.jsx("div",{className:"min-w-0 rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-4",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"break-words text-sm font-medium text-[var(--ui-ink-strong)] [overflow-wrap:anywhere]",children:r.title}),r.description?e.jsx("div",{className:"mt-1 break-words text-sm text-[var(--ui-ink-soft)] [overflow-wrap:anywhere]",children:r.description}):null]}),e.jsxs(c,{className:"shrink-0 border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:[r.itemIds.length," items"]})]})},r.id))})]}):null]}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs(u,{className:"min-w-0 border-[var(--ui-border-subtle)] bg-[var(--ui-surface-section)]",children:[e.jsx("div",{className:x,children:"Provenance"}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-2",children:[e.jsx(c,{className:"border border-[var(--ui-border-subtle)] bg-[var(--ui-info-soft)] text-[color-mix(in_srgb,var(--info)_76%,var(--ui-ink-strong)_24%)]",children:s.sourceClass.replaceAll("_"," ")}),e.jsx(c,{className:"border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:s.availability.replaceAll("_"," ")}),s.symptomDomains.map(r=>e.jsx(c,{className:"max-w-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:r},r))]}),t?e.jsx("div",{className:"mt-4 grid gap-3",children:t.provenance.sources.map(r=>e.jsxs("a",{href:r.url,target:"_blank",rel:"noreferrer",className:j,children:[e.jsx("div",{className:"break-words text-sm font-medium text-[var(--ui-ink-strong)] [overflow-wrap:anywhere]",children:r.label}),e.jsx("div",{className:"mt-2 break-words text-sm leading-6 text-[var(--ui-ink-soft)] [overflow-wrap:anywhere]",children:r.citation})]},r.url))}):null]}),e.jsxs(u,{className:"min-w-0 border-[var(--ui-border-subtle)] bg-[var(--ui-surface-section)]",children:[e.jsx("div",{className:x,children:"History over time"}),s.history.length===0?e.jsx("div",{className:"mt-4",children:e.jsx(E,{eyebrow:"Run history",title:"No completed runs yet",description:"Complete the first guided run and the longitudinal score trace will appear here."})}):e.jsxs(e.Fragment,{children:[e.jsx(D,{history:s.history}),e.jsx("div",{className:"mt-4 grid gap-3",children:s.history.slice(0,5).map(r=>e.jsx(o,{to:`/psyche/questionnaire-runs/${r.runId}`,className:j,children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"break-words text-sm font-medium text-[var(--ui-ink-strong)] [overflow-wrap:anywhere]",children:r.primaryScoreLabel||"Primary score"}),e.jsx("div",{className:"mt-1 break-words text-sm text-[var(--ui-ink-soft)] [overflow-wrap:anywhere]",children:new Date(r.completedAt).toLocaleString()})]}),e.jsxs("div",{className:"shrink-0 text-right",children:[e.jsx("div",{className:"text-lg font-semibold text-[var(--ui-ink-strong)]",children:r.primaryScore??"—"}),r.bandLabel?e.jsx("div",{className:"max-w-[10rem] break-words text-xs uppercase tracking-[0.16em] text-[color-mix(in_srgb,var(--success)_76%,var(--ui-ink-strong)_24%)] [overflow-wrap:anywhere]",children:r.bandLabel}):null]})]})},r.runId))})]})]})]})]})]})}export{W as PsycheQuestionnaireDetailPage};
@@ -1 +1 @@
1
- import{c6 as g,j as e,aC as o}from"./vendor-Cpmju3nw.js";import{i as h}from"./state-BtwEvpO6.js";import{P as v}from"./page-hero-BRcqE3a4.js";import{L as b,e as w,B as d,C as l,h as f,k as y,c as j,cn as k}from"./index-wEZUnRh0.js";import"./motion-DwjmC9aq.js";import"./ui-B9O-eUim.js";import"./board-CLOHbg6t.js";import"./forms-C5d5hTf2.js";const c="font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",u="min-w-0 overflow-hidden border-[var(--ui-border-subtle)] bg-[var(--ui-surface-section)]",m="min-w-0 rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-4",N="border border-[color-mix(in_srgb,var(--success)_36%,var(--ui-border-subtle)_64%)] bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_70%,var(--ui-ink-strong)_30%)]",C="border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)]";function R(){const{runId:t=""}=g(),a=h({queryKey:["forge-psyche-questionnaire-run",t],queryFn:()=>k(t),enabled:t.length>0});if(a.isLoading)return e.jsx(b,{eyebrow:"Questionnaire result",title:"Loading scored run",description:"Hydrating the recorded answers, stored scores, and longitudinal context."});if(a.isError||!a.data)return e.jsx(w,{eyebrow:"Questionnaire result",error:a.error,onRetry:()=>void a.refetch()});const s=a.data,x=new Map(s.answers.map(r=>[r.itemId,r]));return e.jsxs("div",{className:"grid gap-5",children:[e.jsx(v,{eyebrow:"Questionnaire result",title:s.instrument.title,description:"Stored raw answers, computed scores, and score history all remain attached to the exact version used for this run.",badge:s.run.completedAt?"Completed":"Draft",actions:e.jsxs(e.Fragment,{children:[e.jsx(o,{to:`/psyche/questionnaires/${s.instrument.id}`,children:e.jsx(d,{variant:"secondary",children:"Back to questionnaire"})}),e.jsx(o,{to:`/psyche/questionnaires/${s.instrument.id}/take`,children:e.jsx(d,{children:"Take again"})})]})}),e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,0.9fr)_minmax(18rem,1.1fr)]",children:[e.jsxs(l,{className:u,children:[e.jsx("div",{className:c,children:"Stored scores"}),s.scores.length===0?e.jsx("div",{className:"mt-4",children:e.jsx(f,{eyebrow:"Scores",title:"No scores stored yet",description:"This run has not been completed, so there are no persisted score rows yet."})}):e.jsx("div",{className:"mt-4 grid gap-3",children:s.scores.map(r=>e.jsx("div",{className:m,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:"break-words text-sm font-medium text-[var(--ui-ink-strong)] [overflow-wrap:anywhere]",children:r.label}),r.bandLabel?e.jsx("div",{className:"mt-2 break-words text-xs uppercase tracking-[0.16em] text-[color-mix(in_srgb,var(--success)_74%,var(--ui-ink-strong)_26%)] [overflow-wrap:anywhere]",children:r.bandLabel}):null]}),e.jsx("div",{className:"min-w-0 break-words text-right text-lg font-semibold text-[var(--ui-ink-strong)] [overflow-wrap:anywhere]",children:r.valueText??r.valueNumeric??"—"})]})},r.scoreKey))})]}),e.jsxs(l,{className:u,children:[e.jsx("div",{className:c,children:"Answer ledger"}),e.jsx("div",{className:"mt-4 grid gap-3",children:s.version.definition.items.map(r=>{const i=x.get(r.id);return e.jsxs("div",{className:m,children:[e.jsx("div",{className:"break-words text-sm font-medium leading-6 text-[var(--ui-ink-strong)] [overflow-wrap:anywhere]",children:r.prompt}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:r.options.map(n=>{const p=(i==null?void 0:i.optionKey)===n.key;return e.jsx(y,{className:j("max-w-full break-words [overflow-wrap:anywhere]",p?N:C),children:n.label},`${r.id}-${n.key}`)})})]},r.id)})})]})]})]})}export{R as PsycheQuestionnaireRunDetailPage};
1
+ import{c6 as g,j as e,aC as o}from"./vendor-Cpmju3nw.js";import{i as h}from"./state-BtwEvpO6.js";import{P as v}from"./page-hero-C0MpI3MM.js";import{L as b,e as w,B as d,C as l,h as f,k as y,c as j,cn as k}from"./index-BaiwtAgo.js";import"./motion-DwjmC9aq.js";import"./ui-B9O-eUim.js";import"./board-CLOHbg6t.js";import"./forms-C5d5hTf2.js";const c="font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",u="min-w-0 overflow-hidden border-[var(--ui-border-subtle)] bg-[var(--ui-surface-section)]",m="min-w-0 rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-4",N="border border-[color-mix(in_srgb,var(--success)_36%,var(--ui-border-subtle)_64%)] bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_70%,var(--ui-ink-strong)_30%)]",C="border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)]";function R(){const{runId:t=""}=g(),a=h({queryKey:["forge-psyche-questionnaire-run",t],queryFn:()=>k(t),enabled:t.length>0});if(a.isLoading)return e.jsx(b,{eyebrow:"Questionnaire result",title:"Loading scored run",description:"Hydrating the recorded answers, stored scores, and longitudinal context."});if(a.isError||!a.data)return e.jsx(w,{eyebrow:"Questionnaire result",error:a.error,onRetry:()=>void a.refetch()});const s=a.data,x=new Map(s.answers.map(r=>[r.itemId,r]));return e.jsxs("div",{className:"grid gap-5",children:[e.jsx(v,{eyebrow:"Questionnaire result",title:s.instrument.title,description:"Stored raw answers, computed scores, and score history all remain attached to the exact version used for this run.",badge:s.run.completedAt?"Completed":"Draft",actions:e.jsxs(e.Fragment,{children:[e.jsx(o,{to:`/psyche/questionnaires/${s.instrument.id}`,children:e.jsx(d,{variant:"secondary",children:"Back to questionnaire"})}),e.jsx(o,{to:`/psyche/questionnaires/${s.instrument.id}/take`,children:e.jsx(d,{children:"Take again"})})]})}),e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,0.9fr)_minmax(18rem,1.1fr)]",children:[e.jsxs(l,{className:u,children:[e.jsx("div",{className:c,children:"Stored scores"}),s.scores.length===0?e.jsx("div",{className:"mt-4",children:e.jsx(f,{eyebrow:"Scores",title:"No scores stored yet",description:"This run has not been completed, so there are no persisted score rows yet."})}):e.jsx("div",{className:"mt-4 grid gap-3",children:s.scores.map(r=>e.jsx("div",{className:m,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:"break-words text-sm font-medium text-[var(--ui-ink-strong)] [overflow-wrap:anywhere]",children:r.label}),r.bandLabel?e.jsx("div",{className:"mt-2 break-words text-xs uppercase tracking-[0.16em] text-[color-mix(in_srgb,var(--success)_74%,var(--ui-ink-strong)_26%)] [overflow-wrap:anywhere]",children:r.bandLabel}):null]}),e.jsx("div",{className:"min-w-0 break-words text-right text-lg font-semibold text-[var(--ui-ink-strong)] [overflow-wrap:anywhere]",children:r.valueText??r.valueNumeric??"—"})]})},r.scoreKey))})]}),e.jsxs(l,{className:u,children:[e.jsx("div",{className:c,children:"Answer ledger"}),e.jsx("div",{className:"mt-4 grid gap-3",children:s.version.definition.items.map(r=>{const i=x.get(r.id);return e.jsxs("div",{className:m,children:[e.jsx("div",{className:"break-words text-sm font-medium leading-6 text-[var(--ui-ink-strong)] [overflow-wrap:anywhere]",children:r.prompt}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:r.options.map(n=>{const p=(i==null?void 0:i.optionKey)===n.key;return e.jsx(y,{className:j("max-w-full break-words [overflow-wrap:anywhere]",p?N:C),children:n.label},`${r.id}-${n.key}`)})})]},r.id)})})]})]})]})}export{R as PsycheQuestionnaireRunDetailPage};
@@ -1 +1 @@
1
- import{c6 as T,b6 as H,r as S,j as i,aC as Z,bV as G,d5 as W,cL as E,bW as q}from"./vendor-Cpmju3nw.js";import{k as V}from"./state-BtwEvpO6.js";import{P as J}from"./page-hero-BRcqE3a4.js";import{e as X,L as Y,B as k,C as D,c as K,k as ee,co as ne,cp as te,cq as ie}from"./index-wEZUnRh0.js";import"./motion-DwjmC9aq.js";import"./ui-B9O-eUim.js";import"./board-CLOHbg6t.js";import"./forms-C5d5hTf2.js";const z=new Map;function j(n){return new Error(n)}function re(n){const r=[];let e=0;for(;e<n.length;){const a=n[e];if(/\s/.test(a)){e+=1;continue}const s=n.slice(e,e+2);if(s==="=="||s==="!="||s===">="||s==="<="||s==="&&"||s==="||"){r.push({type:s}),e+=2;continue}if("(),><+-*/!".includes(a)){r.push({type:a}),e+=1;continue}if(a==="'"||a==='"'){const d=a;e+=1;let u="";for(;e<n.length&&n[e]!==d;){const t=n[e];if(t==="\\"&&e+1<n.length){u+=n[e+1],e+=2;continue}u+=t,e+=1}if(n[e]!==d)throw j(`Unterminated string in flow rule: ${n}`);e+=1,r.push({type:"string",value:u});continue}if(/\d/.test(a)){let d=a;for(e+=1;e<n.length&&/[\d.]/.test(n[e]);)d+=n[e],e+=1;r.push({type:"number",value:Number(d)});continue}if(/[A-Za-z_]/.test(a)){let d=a;for(e+=1;e<n.length&&/[A-Za-z0-9_]/.test(n[e]);)d+=n[e],e+=1;const u=d.toLowerCase();u==="and"?r.push({type:"&&"}):u==="or"?r.push({type:"||"}):u==="not"?r.push({type:"!"}):u==="true"?r.push({type:"boolean",value:!0}):u==="false"?r.push({type:"boolean",value:!1}):u==="null"?r.push({type:"null"}):r.push({type:"identifier",value:d});continue}throw j(`Unexpected token '${a}' in flow rule: ${n}`)}return r}function se(n,r){let e=0;function a(){return n[e]}function s(l){const o=n[e];return!o||l&&o.type!==l?null:(e+=1,o)}function d(l){const o=s(l);if(!o)throw j(`Expected '${l}' in flow rule: ${r}`);return o}function u(){const l=a();if(!l)throw j(`Unexpected end of flow rule: ${r}`);if(s("(")){const o=b();return d(")"),o}if(l.type==="number")return s("number"),{kind:"literal",value:l.value};if(l.type==="string")return s("string"),{kind:"literal",value:l.value};if(l.type==="boolean")return s("boolean"),{kind:"literal",value:l.value};if(l.type==="null")return s("null"),{kind:"literal",value:null};if(l.type==="identifier"){const o=s("identifier").value;if(s("(")){const m=[];if(!s(")")){do m.push(b());while(s(","));d(")")}if(o!=="answered"&&o!=="option"&&o!=="label"&&o!=="value")throw j(`Unknown flow function '${o}' in rule: ${r}`);return{kind:"call",name:o,args:m}}return{kind:"reference",itemId:o}}throw j(`Unexpected token '${l.type}' in flow rule: ${r}`)}function t(){return s("!")?{kind:"unary",operator:"!",operand:t()}:s("-")?{kind:"unary",operator:"-",operand:t()}:u()}function v(){let l=t();for(;;){if(s("*")){l={kind:"binary",operator:"*",left:l,right:t()};continue}if(s("/")){l={kind:"binary",operator:"/",left:l,right:t()};continue}return l}}function y(){let l=v();for(;;){if(s("+")){l={kind:"binary",operator:"+",left:l,right:v()};continue}if(s("-")){l={kind:"binary",operator:"-",left:l,right:v()};continue}return l}}function g(){let l=y();for(;;){const o=a(),m=o&&(o.type==="=="||o.type==="!="||o.type===">="||o.type==="<="||o.type===">"||o.type==="<")?o.type:null;if(!m)return l;e+=1,l={kind:"binary",operator:m,left:l,right:y()}}}function p(){let l=g();for(;s("&&");)l={kind:"binary",operator:"&&",left:l,right:g()};return l}function b(){let l=p();for(;s("||");)l={kind:"binary",operator:"||",left:l,right:p()};return l}const N=b();if(e<n.length)throw j(`Unexpected trailing tokens in flow rule: ${r}`);return N}function ae(n){const r=z.get(n);if(r)return r;const e=se(re(n),n);return z.set(n,e),e}function le(n){return n.kind==="reference"?n.itemId:n.kind==="literal"&&typeof n.value=="string"&&n.value.trim().length>0?n.value.trim():null}function M(n){return typeof n=="boolean"?n:typeof n=="number"?n!==0:typeof n=="string"?n.length>0:!1}function h(n){if(typeof n=="number"&&Number.isFinite(n))return n;if(typeof n=="boolean")return n?1:0;if(typeof n=="string"){const r=Number(n);return Number.isFinite(r)?r:null}return null}function oe(n,r,e){const a=h(n),s=h(e);if(a!==null&&s!==null)switch(r){case"==":return a===s;case"!=":return a!==s;case">":return a>s;case">=":return a>=s;case"<":return a<s;case"<=":return a<=s}return r==="=="||r==="!="?r==="=="?n===e:n!==e:!1}function P(n,r){switch(n.kind){case"literal":return n.value;case"reference":return r.getAnswerValue(n.itemId);case"unary":{const e=P(n.operand,r);if(n.operator==="!")return!M(e);const a=h(e);return a===null?null:-a}case"binary":{const e=P(n.left,r),a=P(n.right,r);switch(n.operator){case"&&":return M(e)&&M(a);case"||":return M(e)||M(a);case"+":return e===null||a===null?null:(h(e)??0)+(h(a)??0);case"-":return e===null||a===null?null:(h(e)??0)-(h(a)??0);case"*":return e===null||a===null?null:(h(e)??0)*(h(a)??0);case"/":{const s=h(a);return e===null||s===null||s===0?null:(h(e)??0)/s}default:return oe(e,n.operator,a)}}case"call":{const e=n.args[0]?le(n.args[0]):null;if(!e)return null;switch(n.name){case"answered":return r.isAnswered(e);case"option":return r.getOptionKey(e);case"label":return r.getLabel(e);case"value":return r.getAnswerValue(e)}}}}function ue(n){return new Map(n.map(r=>[r.itemId,{optionKey:r.optionKey??null,numericValue:r.numericValue??null,valueText:r.valueText??null}]))}function F(n,r,e){const a=ae(n),s=ue(r),d=P(a,{getAnswerValue:u=>{if(!e.has(u))return null;const t=s.get(u);return(t==null?void 0:t.numericValue)??(t==null?void 0:t.optionKey)??(t==null?void 0:t.valueText)??null},getOptionKey:u=>{var t;return e.has(u)?((t=s.get(u))==null?void 0:t.optionKey)??null:null},getLabel:u=>{var t;return e.has(u)?((t=s.get(u))==null?void 0:t.valueText)??null:null},isAnswered:u=>{if(!e.has(u))return!1;const t=s.get(u);return!!(t&&(t.optionKey!==null||t.numericValue!==null||(t.valueText??"").trim().length>0))}});return M(d)}function ce(n,r){const e=new Set,a=new Set,s=new Map(n.items.map(u=>[u.id,u])),d=new Map;for(const u of n.sections){if(!(!u.visibility||F(u.visibility.script,r,e)))continue;const v=u.itemIds.filter(y=>{const g=s.get(y);if(!g)return!1;const p=!g.visibility||F(g.visibility.script,r,e);return p&&e.add(g.id),p});v.length>0&&(a.add(u.id),d.set(u.id,v))}return{visibleItemIds:e,visibleSectionIds:a,visibleItemIdsBySection:d}}const L="font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",de="min-w-0 rounded-[8px] border px-5 py-5 text-left transition",fe="min-w-0 rounded-[8px] border px-3 py-3 text-sm transition",O="border-[color-mix(in_srgb,var(--success)_42%,var(--ui-border-subtle)_58%)] bg-[var(--ui-success-soft)] text-[var(--ui-ink-strong)]",_="border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-medium)] hover:bg-[var(--ui-surface-2)]";function me(n,r){const e=n.options.find(a=>a.key===r);return e?{itemId:n.id,optionKey:e.key,valueText:e.label,numericValue:e.value,answer:{label:e.label,value:e.value}}:null}function ke(){const{instrumentId:n=""}=T(),r=H(),[e,a]=S.useState(null),s=V({mutationFn:()=>ne(n,{userId:"user_operator"}),onSuccess:c=>a(c)}),d=V({mutationFn:c=>te(e.run.id,c),onSuccess:c=>a(c)}),u=V({mutationFn:()=>ie(e.run.id),onSuccess:c=>{a(c),r(`/psyche/questionnaire-runs/${c.run.id}`)}});S.useEffect(()=>{n&&s.mutate()},[n]);const t=e,v=S.useMemo(()=>new Map(((t==null?void 0:t.answers)??[]).map(c=>[c.itemId,c.optionKey??""])),[t]),y=(t==null?void 0:t.version.definition.sections)??[],g=(t==null?void 0:t.version.definition.items)??[],p=S.useMemo(()=>t?ce(t.version.definition,t.answers):{visibleItemIds:new Set,visibleSectionIds:new Set,visibleItemIdsBySection:new Map},[t]),b=S.useMemo(()=>g.filter(c=>p.visibleItemIds.has(c.id)),[g,p]),N=S.useMemo(()=>y.filter(c=>p.visibleSectionIds.has(c.id)).map(c=>({...c,itemIds:p.visibleItemIdsBySection.get(c.id)??[]})),[y,p]),l=(t==null?void 0:t.version.definition.presentationMode)==="single_question"?b.length:N.length,o=l>0?Math.min((t==null?void 0:t.run.progressIndex)??0,l-1):0,m=N[o]??null,I=(t==null?void 0:t.version.definition.presentationMode)==="single_question"?b[o]??null:null,$=b.every(c=>!c.required||v.has(c.id)),A=async c=>{t&&(a(f=>f&&{...f,run:{...f.run,progressIndex:c}}),await d.mutateAsync({answers:[],progressIndex:c}))},B=async(c,f,x)=>{const w=me(c,f);!w||!t||(a(C=>{if(!C)return C;const Q=C.answers.filter(U=>U.itemId!==c.id);return{...C,run:{...C.run,progressIndex:x},answers:[...Q,{...w,optionKey:w.optionKey??null,numericValue:w.numericValue??null,createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()}]}}),await d.mutateAsync({answers:[w],progressIndex:x}))};if(s.isError)return i.jsx(X,{eyebrow:"Questionnaire run",error:s.error,onRetry:()=>s.mutate()});if(s.isPending||!t)return i.jsx(Y,{eyebrow:"Questionnaire run",title:"Preparing guided run",description:"Opening the current questionnaire version, loading any draft answers, and restoring your place."});const R=l>0?(o+1)/l*100:0;return i.jsxs("div",{className:"grid gap-5",children:[i.jsx(J,{eyebrow:"Guided questionnaire",title:t.instrument.title,description:t.version.definition.instructions,badge:`v${t.version.versionNumber}`,actions:i.jsx(Z,{to:`/psyche/questionnaires/${t.instrument.id}`,children:i.jsx(k,{variant:"secondary",children:"Back to detail"})})}),i.jsxs(D,{className:"min-w-0 overflow-hidden border-[var(--ui-border-subtle)] bg-[var(--ui-surface-section)] p-0",children:[i.jsxs("div",{className:"border-b border-[var(--ui-border-subtle)] px-5 py-4",children:[i.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[i.jsxs("div",{className:"min-w-0",children:[i.jsx("div",{className:L,children:"Progress"}),i.jsxs("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:["Step ",o+1," of ",l]})]}),i.jsx("div",{className:"flex items-center gap-2 text-sm text-[var(--ui-ink-soft)]",children:d.isPending?i.jsxs(i.Fragment,{children:[i.jsx(G,{className:"size-4 animate-spin"}),"Autosaving"]}):i.jsxs(i.Fragment,{children:[i.jsx(W,{className:"size-4 text-[var(--tertiary)]"}),"Saved"]})})]}),i.jsx("div",{className:"mt-3 h-1.5 rounded-full bg-[var(--ui-surface-2)]",children:i.jsx("div",{className:"h-full rounded-full bg-[linear-gradient(90deg,var(--success),var(--info))] transition-[width] duration-300",style:{width:`${R}%`}})})]}),t.version.definition.presentationMode==="single_question"&&I?i.jsx("div",{className:"px-5 py-6 sm:px-6",children:i.jsxs("div",{className:"mx-auto grid max-w-3xl gap-6",children:[i.jsx("div",{className:"min-w-0 break-words font-display text-[clamp(1.7rem,3vw,2.4rem)] leading-tight text-[var(--ui-ink-strong)] [overflow-wrap:anywhere]",children:I.prompt}),i.jsx("div",{className:"grid gap-3",children:I.options.map(c=>{const f=v.get(I.id)===c.key;return i.jsxs("button",{type:"button",className:K(de,f?O:_),onClick:()=>void B(I,c.key,o),children:[i.jsx("div",{className:"break-words text-base font-medium [overflow-wrap:anywhere]",children:c.label}),c.description?i.jsx("div",{className:"mt-2 break-words text-sm leading-6 text-[var(--ui-ink-soft)] [overflow-wrap:anywhere]",children:c.description}):null]},c.key)})}),i.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[i.jsxs(k,{variant:"secondary",disabled:o===0,onClick:()=>void A(Math.max(0,o-1)),children:[i.jsx(E,{className:"mr-2 size-4"}),"Previous"]}),o<b.length-1?i.jsxs(k,{onClick:()=>void A(Math.min(b.length-1,o+1)),children:["Next",i.jsx(q,{className:"ml-2 size-4"})]}):i.jsx(k,{disabled:!$||u.isPending,onClick:()=>u.mutate(),children:"Finish and score"})]})]})}):m?i.jsx("div",{className:"px-5 py-6 sm:px-6",children:i.jsxs("div",{className:"mx-auto max-w-5xl",children:[i.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[i.jsxs("div",{className:"min-w-0",children:[i.jsx("div",{className:L,children:m.title}),m.description?i.jsx("div",{className:"mt-2 break-words text-sm text-[var(--ui-ink-soft)] [overflow-wrap:anywhere]",children:m.description}):null]}),i.jsxs(ee,{className:"shrink-0 border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:[m.itemIds.length," items"]})]}),i.jsx("div",{className:"mt-6 grid gap-4",children:m.itemIds.map(c=>{const f=b.find(x=>x.id===c);return f?i.jsxs("div",{className:"min-w-0 rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-4",children:[i.jsx("div",{className:"break-words text-sm leading-6 text-[var(--ui-ink-strong)] [overflow-wrap:anywhere]",children:f.prompt}),i.jsx("div",{className:"mt-4 grid gap-2 md:grid-cols-3 xl:grid-cols-6",children:f.options.map(x=>{const w=v.get(f.id)===x.key;return i.jsx("button",{type:"button",className:K(fe,w?O:_),onClick:()=>void B(f,x.key,o),children:i.jsx("span",{className:"break-words [overflow-wrap:anywhere]",children:x.label})},x.key)})})]},f.id):null})}),i.jsxs("div",{className:"mt-6 flex flex-wrap items-center justify-between gap-3",children:[i.jsxs(k,{variant:"secondary",disabled:o===0,onClick:()=>void A(Math.max(0,o-1)),children:[i.jsx(E,{className:"mr-2 size-4"}),"Previous section"]}),o<N.length-1?i.jsxs(k,{onClick:()=>void A(Math.min(N.length-1,o+1)),children:["Next section",i.jsx(q,{className:"ml-2 size-4"})]}):i.jsx(k,{disabled:!$||u.isPending,onClick:()=>u.mutate(),children:"Finish and score"})]})]})}):null]})]})}export{ke as PsycheQuestionnaireRunPage};
1
+ import{c6 as T,b6 as H,r as S,j as i,aC as Z,bV as G,d5 as W,cL as E,bW as q}from"./vendor-Cpmju3nw.js";import{k as V}from"./state-BtwEvpO6.js";import{P as J}from"./page-hero-C0MpI3MM.js";import{e as X,L as Y,B as k,C as D,c as K,k as ee,co as ne,cp as te,cq as ie}from"./index-BaiwtAgo.js";import"./motion-DwjmC9aq.js";import"./ui-B9O-eUim.js";import"./board-CLOHbg6t.js";import"./forms-C5d5hTf2.js";const z=new Map;function j(n){return new Error(n)}function re(n){const r=[];let e=0;for(;e<n.length;){const a=n[e];if(/\s/.test(a)){e+=1;continue}const s=n.slice(e,e+2);if(s==="=="||s==="!="||s===">="||s==="<="||s==="&&"||s==="||"){r.push({type:s}),e+=2;continue}if("(),><+-*/!".includes(a)){r.push({type:a}),e+=1;continue}if(a==="'"||a==='"'){const d=a;e+=1;let u="";for(;e<n.length&&n[e]!==d;){const t=n[e];if(t==="\\"&&e+1<n.length){u+=n[e+1],e+=2;continue}u+=t,e+=1}if(n[e]!==d)throw j(`Unterminated string in flow rule: ${n}`);e+=1,r.push({type:"string",value:u});continue}if(/\d/.test(a)){let d=a;for(e+=1;e<n.length&&/[\d.]/.test(n[e]);)d+=n[e],e+=1;r.push({type:"number",value:Number(d)});continue}if(/[A-Za-z_]/.test(a)){let d=a;for(e+=1;e<n.length&&/[A-Za-z0-9_]/.test(n[e]);)d+=n[e],e+=1;const u=d.toLowerCase();u==="and"?r.push({type:"&&"}):u==="or"?r.push({type:"||"}):u==="not"?r.push({type:"!"}):u==="true"?r.push({type:"boolean",value:!0}):u==="false"?r.push({type:"boolean",value:!1}):u==="null"?r.push({type:"null"}):r.push({type:"identifier",value:d});continue}throw j(`Unexpected token '${a}' in flow rule: ${n}`)}return r}function se(n,r){let e=0;function a(){return n[e]}function s(l){const o=n[e];return!o||l&&o.type!==l?null:(e+=1,o)}function d(l){const o=s(l);if(!o)throw j(`Expected '${l}' in flow rule: ${r}`);return o}function u(){const l=a();if(!l)throw j(`Unexpected end of flow rule: ${r}`);if(s("(")){const o=b();return d(")"),o}if(l.type==="number")return s("number"),{kind:"literal",value:l.value};if(l.type==="string")return s("string"),{kind:"literal",value:l.value};if(l.type==="boolean")return s("boolean"),{kind:"literal",value:l.value};if(l.type==="null")return s("null"),{kind:"literal",value:null};if(l.type==="identifier"){const o=s("identifier").value;if(s("(")){const m=[];if(!s(")")){do m.push(b());while(s(","));d(")")}if(o!=="answered"&&o!=="option"&&o!=="label"&&o!=="value")throw j(`Unknown flow function '${o}' in rule: ${r}`);return{kind:"call",name:o,args:m}}return{kind:"reference",itemId:o}}throw j(`Unexpected token '${l.type}' in flow rule: ${r}`)}function t(){return s("!")?{kind:"unary",operator:"!",operand:t()}:s("-")?{kind:"unary",operator:"-",operand:t()}:u()}function v(){let l=t();for(;;){if(s("*")){l={kind:"binary",operator:"*",left:l,right:t()};continue}if(s("/")){l={kind:"binary",operator:"/",left:l,right:t()};continue}return l}}function y(){let l=v();for(;;){if(s("+")){l={kind:"binary",operator:"+",left:l,right:v()};continue}if(s("-")){l={kind:"binary",operator:"-",left:l,right:v()};continue}return l}}function g(){let l=y();for(;;){const o=a(),m=o&&(o.type==="=="||o.type==="!="||o.type===">="||o.type==="<="||o.type===">"||o.type==="<")?o.type:null;if(!m)return l;e+=1,l={kind:"binary",operator:m,left:l,right:y()}}}function p(){let l=g();for(;s("&&");)l={kind:"binary",operator:"&&",left:l,right:g()};return l}function b(){let l=p();for(;s("||");)l={kind:"binary",operator:"||",left:l,right:p()};return l}const N=b();if(e<n.length)throw j(`Unexpected trailing tokens in flow rule: ${r}`);return N}function ae(n){const r=z.get(n);if(r)return r;const e=se(re(n),n);return z.set(n,e),e}function le(n){return n.kind==="reference"?n.itemId:n.kind==="literal"&&typeof n.value=="string"&&n.value.trim().length>0?n.value.trim():null}function M(n){return typeof n=="boolean"?n:typeof n=="number"?n!==0:typeof n=="string"?n.length>0:!1}function h(n){if(typeof n=="number"&&Number.isFinite(n))return n;if(typeof n=="boolean")return n?1:0;if(typeof n=="string"){const r=Number(n);return Number.isFinite(r)?r:null}return null}function oe(n,r,e){const a=h(n),s=h(e);if(a!==null&&s!==null)switch(r){case"==":return a===s;case"!=":return a!==s;case">":return a>s;case">=":return a>=s;case"<":return a<s;case"<=":return a<=s}return r==="=="||r==="!="?r==="=="?n===e:n!==e:!1}function P(n,r){switch(n.kind){case"literal":return n.value;case"reference":return r.getAnswerValue(n.itemId);case"unary":{const e=P(n.operand,r);if(n.operator==="!")return!M(e);const a=h(e);return a===null?null:-a}case"binary":{const e=P(n.left,r),a=P(n.right,r);switch(n.operator){case"&&":return M(e)&&M(a);case"||":return M(e)||M(a);case"+":return e===null||a===null?null:(h(e)??0)+(h(a)??0);case"-":return e===null||a===null?null:(h(e)??0)-(h(a)??0);case"*":return e===null||a===null?null:(h(e)??0)*(h(a)??0);case"/":{const s=h(a);return e===null||s===null||s===0?null:(h(e)??0)/s}default:return oe(e,n.operator,a)}}case"call":{const e=n.args[0]?le(n.args[0]):null;if(!e)return null;switch(n.name){case"answered":return r.isAnswered(e);case"option":return r.getOptionKey(e);case"label":return r.getLabel(e);case"value":return r.getAnswerValue(e)}}}}function ue(n){return new Map(n.map(r=>[r.itemId,{optionKey:r.optionKey??null,numericValue:r.numericValue??null,valueText:r.valueText??null}]))}function F(n,r,e){const a=ae(n),s=ue(r),d=P(a,{getAnswerValue:u=>{if(!e.has(u))return null;const t=s.get(u);return(t==null?void 0:t.numericValue)??(t==null?void 0:t.optionKey)??(t==null?void 0:t.valueText)??null},getOptionKey:u=>{var t;return e.has(u)?((t=s.get(u))==null?void 0:t.optionKey)??null:null},getLabel:u=>{var t;return e.has(u)?((t=s.get(u))==null?void 0:t.valueText)??null:null},isAnswered:u=>{if(!e.has(u))return!1;const t=s.get(u);return!!(t&&(t.optionKey!==null||t.numericValue!==null||(t.valueText??"").trim().length>0))}});return M(d)}function ce(n,r){const e=new Set,a=new Set,s=new Map(n.items.map(u=>[u.id,u])),d=new Map;for(const u of n.sections){if(!(!u.visibility||F(u.visibility.script,r,e)))continue;const v=u.itemIds.filter(y=>{const g=s.get(y);if(!g)return!1;const p=!g.visibility||F(g.visibility.script,r,e);return p&&e.add(g.id),p});v.length>0&&(a.add(u.id),d.set(u.id,v))}return{visibleItemIds:e,visibleSectionIds:a,visibleItemIdsBySection:d}}const L="font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",de="min-w-0 rounded-[8px] border px-5 py-5 text-left transition",fe="min-w-0 rounded-[8px] border px-3 py-3 text-sm transition",O="border-[color-mix(in_srgb,var(--success)_42%,var(--ui-border-subtle)_58%)] bg-[var(--ui-success-soft)] text-[var(--ui-ink-strong)]",_="border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-medium)] hover:bg-[var(--ui-surface-2)]";function me(n,r){const e=n.options.find(a=>a.key===r);return e?{itemId:n.id,optionKey:e.key,valueText:e.label,numericValue:e.value,answer:{label:e.label,value:e.value}}:null}function ke(){const{instrumentId:n=""}=T(),r=H(),[e,a]=S.useState(null),s=V({mutationFn:()=>ne(n,{userId:"user_operator"}),onSuccess:c=>a(c)}),d=V({mutationFn:c=>te(e.run.id,c),onSuccess:c=>a(c)}),u=V({mutationFn:()=>ie(e.run.id),onSuccess:c=>{a(c),r(`/psyche/questionnaire-runs/${c.run.id}`)}});S.useEffect(()=>{n&&s.mutate()},[n]);const t=e,v=S.useMemo(()=>new Map(((t==null?void 0:t.answers)??[]).map(c=>[c.itemId,c.optionKey??""])),[t]),y=(t==null?void 0:t.version.definition.sections)??[],g=(t==null?void 0:t.version.definition.items)??[],p=S.useMemo(()=>t?ce(t.version.definition,t.answers):{visibleItemIds:new Set,visibleSectionIds:new Set,visibleItemIdsBySection:new Map},[t]),b=S.useMemo(()=>g.filter(c=>p.visibleItemIds.has(c.id)),[g,p]),N=S.useMemo(()=>y.filter(c=>p.visibleSectionIds.has(c.id)).map(c=>({...c,itemIds:p.visibleItemIdsBySection.get(c.id)??[]})),[y,p]),l=(t==null?void 0:t.version.definition.presentationMode)==="single_question"?b.length:N.length,o=l>0?Math.min((t==null?void 0:t.run.progressIndex)??0,l-1):0,m=N[o]??null,I=(t==null?void 0:t.version.definition.presentationMode)==="single_question"?b[o]??null:null,$=b.every(c=>!c.required||v.has(c.id)),A=async c=>{t&&(a(f=>f&&{...f,run:{...f.run,progressIndex:c}}),await d.mutateAsync({answers:[],progressIndex:c}))},B=async(c,f,x)=>{const w=me(c,f);!w||!t||(a(C=>{if(!C)return C;const Q=C.answers.filter(U=>U.itemId!==c.id);return{...C,run:{...C.run,progressIndex:x},answers:[...Q,{...w,optionKey:w.optionKey??null,numericValue:w.numericValue??null,createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()}]}}),await d.mutateAsync({answers:[w],progressIndex:x}))};if(s.isError)return i.jsx(X,{eyebrow:"Questionnaire run",error:s.error,onRetry:()=>s.mutate()});if(s.isPending||!t)return i.jsx(Y,{eyebrow:"Questionnaire run",title:"Preparing guided run",description:"Opening the current questionnaire version, loading any draft answers, and restoring your place."});const R=l>0?(o+1)/l*100:0;return i.jsxs("div",{className:"grid gap-5",children:[i.jsx(J,{eyebrow:"Guided questionnaire",title:t.instrument.title,description:t.version.definition.instructions,badge:`v${t.version.versionNumber}`,actions:i.jsx(Z,{to:`/psyche/questionnaires/${t.instrument.id}`,children:i.jsx(k,{variant:"secondary",children:"Back to detail"})})}),i.jsxs(D,{className:"min-w-0 overflow-hidden border-[var(--ui-border-subtle)] bg-[var(--ui-surface-section)] p-0",children:[i.jsxs("div",{className:"border-b border-[var(--ui-border-subtle)] px-5 py-4",children:[i.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[i.jsxs("div",{className:"min-w-0",children:[i.jsx("div",{className:L,children:"Progress"}),i.jsxs("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:["Step ",o+1," of ",l]})]}),i.jsx("div",{className:"flex items-center gap-2 text-sm text-[var(--ui-ink-soft)]",children:d.isPending?i.jsxs(i.Fragment,{children:[i.jsx(G,{className:"size-4 animate-spin"}),"Autosaving"]}):i.jsxs(i.Fragment,{children:[i.jsx(W,{className:"size-4 text-[var(--tertiary)]"}),"Saved"]})})]}),i.jsx("div",{className:"mt-3 h-1.5 rounded-full bg-[var(--ui-surface-2)]",children:i.jsx("div",{className:"h-full rounded-full bg-[linear-gradient(90deg,var(--success),var(--info))] transition-[width] duration-300",style:{width:`${R}%`}})})]}),t.version.definition.presentationMode==="single_question"&&I?i.jsx("div",{className:"px-5 py-6 sm:px-6",children:i.jsxs("div",{className:"mx-auto grid max-w-3xl gap-6",children:[i.jsx("div",{className:"min-w-0 break-words font-display text-[clamp(1.7rem,3vw,2.4rem)] leading-tight text-[var(--ui-ink-strong)] [overflow-wrap:anywhere]",children:I.prompt}),i.jsx("div",{className:"grid gap-3",children:I.options.map(c=>{const f=v.get(I.id)===c.key;return i.jsxs("button",{type:"button",className:K(de,f?O:_),onClick:()=>void B(I,c.key,o),children:[i.jsx("div",{className:"break-words text-base font-medium [overflow-wrap:anywhere]",children:c.label}),c.description?i.jsx("div",{className:"mt-2 break-words text-sm leading-6 text-[var(--ui-ink-soft)] [overflow-wrap:anywhere]",children:c.description}):null]},c.key)})}),i.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[i.jsxs(k,{variant:"secondary",disabled:o===0,onClick:()=>void A(Math.max(0,o-1)),children:[i.jsx(E,{className:"mr-2 size-4"}),"Previous"]}),o<b.length-1?i.jsxs(k,{onClick:()=>void A(Math.min(b.length-1,o+1)),children:["Next",i.jsx(q,{className:"ml-2 size-4"})]}):i.jsx(k,{disabled:!$||u.isPending,onClick:()=>u.mutate(),children:"Finish and score"})]})]})}):m?i.jsx("div",{className:"px-5 py-6 sm:px-6",children:i.jsxs("div",{className:"mx-auto max-w-5xl",children:[i.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[i.jsxs("div",{className:"min-w-0",children:[i.jsx("div",{className:L,children:m.title}),m.description?i.jsx("div",{className:"mt-2 break-words text-sm text-[var(--ui-ink-soft)] [overflow-wrap:anywhere]",children:m.description}):null]}),i.jsxs(ee,{className:"shrink-0 border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:[m.itemIds.length," items"]})]}),i.jsx("div",{className:"mt-6 grid gap-4",children:m.itemIds.map(c=>{const f=b.find(x=>x.id===c);return f?i.jsxs("div",{className:"min-w-0 rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-4",children:[i.jsx("div",{className:"break-words text-sm leading-6 text-[var(--ui-ink-strong)] [overflow-wrap:anywhere]",children:f.prompt}),i.jsx("div",{className:"mt-4 grid gap-2 md:grid-cols-3 xl:grid-cols-6",children:f.options.map(x=>{const w=v.get(f.id)===x.key;return i.jsx("button",{type:"button",className:K(fe,w?O:_),onClick:()=>void B(f,x.key,o),children:i.jsx("span",{className:"break-words [overflow-wrap:anywhere]",children:x.label})},x.key)})})]},f.id):null})}),i.jsxs("div",{className:"mt-6 flex flex-wrap items-center justify-between gap-3",children:[i.jsxs(k,{variant:"secondary",disabled:o===0,onClick:()=>void A(Math.max(0,o-1)),children:[i.jsx(E,{className:"mr-2 size-4"}),"Previous section"]}),o<N.length-1?i.jsxs(k,{onClick:()=>void A(Math.min(N.length-1,o+1)),children:["Next section",i.jsx(q,{className:"ml-2 size-4"})]}):i.jsx(k,{disabled:!$||u.isPending,onClick:()=>u.mutate(),children:"Finish and score"})]})]})}):null]})]})}export{ke as PsycheQuestionnaireRunPage};