forge-openclaw-plugin 0.3.2 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (214) hide show
  1. package/dist/assets/action-bar-CMGr_Uv_.js +1 -0
  2. package/dist/assets/activity-page-DwGKkJtr.js +1 -0
  3. package/dist/assets/ai-surface-workspace-UtnoNmjq.js +1 -0
  4. package/dist/assets/{atlas-panel-G3wGxjYf.js → atlas-panel-f1kc-LkD.js} +1 -1
  5. package/dist/assets/{board-dIX6etHh.js → board-CLOHbg6t.js} +1 -1
  6. package/dist/assets/calendar-page-C4YqeVrC.js +1 -0
  7. package/dist/assets/calendar-rules-BQppCPiN.js +1 -0
  8. package/dist/assets/{calendar-week-toolbar-CWSK5hJl.js → calendar-week-toolbar-DdPuHUwd.js} +1 -1
  9. package/dist/assets/{charts-DFnEuIMB.js → charts-DwTguE_x.js} +1 -1
  10. package/dist/assets/companion-sync-lab-page-N3cR33GS.js +1 -0
  11. package/dist/assets/daily-metrics-dashboard-CXnAtN2T.js +1 -0
  12. package/dist/assets/define-workbench-box-DkffygDU.js +1 -0
  13. package/dist/assets/entity-link-multiselect-wuyJ8BbW.js +1 -0
  14. package/dist/assets/{entity-note-count-link-ef3ZOpKM.js → entity-note-count-link-CEtKyMAl.js} +1 -1
  15. package/dist/assets/entity-notes-surface-iKNiierJ.js +1 -0
  16. package/dist/assets/execution-board-DesFZ1f5.js +1 -0
  17. package/dist/assets/{faceted-token-search-CZmtyJTT.js → faceted-token-search-D4Okr-Kr.js} +1 -1
  18. package/dist/assets/{flagship-signal-deck-DxRfmfpN.js → flagship-signal-deck-CW91n6u9.js} +1 -1
  19. package/dist/assets/{floating-action-menu-cKjNsPYD.js → floating-action-menu-GCeuOdYZ.js} +1 -1
  20. package/dist/assets/{forms-hB0SqEh-.js → forms-C5d5hTf2.js} +1 -1
  21. package/dist/assets/generic-node-view-COhU_Wm3.js +10 -0
  22. package/dist/assets/goal-detail-page-Bd8JU3IK.js +1 -0
  23. package/dist/assets/goal-dialog-CLz5fYhO.js +1 -0
  24. package/dist/assets/goals-page-CZHNVyY-.js +1 -0
  25. package/dist/assets/{graph-DDUZNRsO.js → graph-Cd5WF3lw.js} +1 -1
  26. package/dist/assets/habits-page-CXiBB7_N.js +1 -0
  27. package/dist/assets/health-boxes-BUcsxDLh.js +1 -0
  28. package/dist/assets/index-BejvcRGb.js +2 -0
  29. package/dist/assets/{index-Bcem7l5u.css → index-CEgIwgk9.css} +1 -1
  30. package/dist/assets/inline-note-fields-CcRDO3pd.js +1 -0
  31. package/dist/assets/insight-flow-dialog-DUBk2MR8.js +1 -0
  32. package/dist/assets/{insights-page-DHG-o9P_.js → insights-page-8fLhCYsM.js} +3 -3
  33. package/dist/assets/kanban-boxes-CH7plRk1.js +1 -0
  34. package/dist/assets/kanban-page-Bq-aYwUL.js +1 -0
  35. package/dist/assets/knowledge-graph-page-DYFfWh4Y.js +1 -0
  36. package/dist/assets/life-force-page-D80rgBBR.js +1 -0
  37. package/dist/assets/{life-force-workspace-sszLD-Yn.js → life-force-workspace-CcmZRRfU.js} +1 -1
  38. package/dist/assets/{maps-C-yOWiDN.js → maps-D0Mm6WPG.js} +1 -1
  39. package/dist/assets/{metric-tile-B-tDTcBt.js → metric-tile-DysHMgM3.js} +1 -1
  40. package/dist/assets/{motion-Lt5B1XuE.js → motion-DwjmC9aq.js} +1 -1
  41. package/dist/assets/movement-boxes-BH3botKt.js +1 -0
  42. package/dist/assets/movement-page-D5KLMKS9.js +1 -0
  43. package/dist/assets/{note-markdown-CCyyE85h.js → note-markdown-Byd_vNkS.js} +1 -1
  44. package/dist/assets/note-tags-input-DYAFDq8Q.js +1 -0
  45. package/dist/assets/notes-boxes-CPiPps1e.js +1 -0
  46. package/dist/assets/notes-page-DehVrOOb.js +1 -0
  47. package/dist/assets/{open-in-graph-button-CMjJZX7G.js → open-in-graph-button-L21MKsb5.js} +1 -1
  48. package/dist/assets/{orbit-map-v2Pv9RU_.js → orbit-map-ChJOQ8CN.js} +1 -1
  49. package/dist/assets/overview-page-D_ewyeWF.js +1 -0
  50. package/dist/assets/page-hero-DlHEJ0Yt.js +1 -0
  51. package/dist/assets/pill-cluster-DhOR4m7X.js +1 -0
  52. package/dist/assets/{preference-entity-handoff-button-CKDxCnbl.js → preference-entity-handoff-button-ugHU2us9.js} +1 -1
  53. package/dist/assets/preferences-page-BTTXeSDR.js +1 -0
  54. package/dist/assets/{project-collections-NBwk6yV-.js → project-collections-USb6PUe0.js} +1 -1
  55. package/dist/assets/project-detail-page-1tD6tUsB.js +1 -0
  56. package/dist/assets/project-dialog-BaHhJqP6.js +1 -0
  57. package/dist/assets/project-management-hierarchy-page-D4HV8QXs.js +1 -0
  58. package/dist/assets/project-management-section-nav-9OV6_ifH.js +1 -0
  59. package/dist/assets/projects-boxes-AyudWls3.js +1 -0
  60. package/dist/assets/projects-page-DizVVzbt.js +1 -0
  61. package/dist/assets/psyche-behaviors-page-CX5MJjWj.js +5 -0
  62. package/dist/assets/psyche-flashcards-page-DzCGy-FV.js +1 -0
  63. package/dist/assets/psyche-goal-map-page-BcKR792E.js +1 -0
  64. package/dist/assets/psyche-graph-BNllZR67.js +1 -0
  65. package/dist/assets/psyche-metrics-page-CpEKlZLO.js +1 -0
  66. package/dist/assets/psyche-mode-guide-page-DXKSE2o7.js +1 -0
  67. package/dist/assets/psyche-modes-page-Bh6eeNm1.js +1 -0
  68. package/dist/assets/psyche-page-B44RJrrC.js +1 -0
  69. package/dist/assets/psyche-patterns-page-Bm7T5FMJ.js +5 -0
  70. package/dist/assets/psyche-questionnaire-builder-page-BNtMNjY8.js +1 -0
  71. package/dist/assets/psyche-questionnaire-detail-page-BnMXErRK.js +1 -0
  72. package/dist/assets/psyche-questionnaire-run-detail-page-CWKxbdwZ.js +1 -0
  73. package/dist/assets/psyche-questionnaire-run-page-DwH7Sk52.js +1 -0
  74. package/dist/assets/psyche-questionnaires-page-B1t_a8QU.js +1 -0
  75. package/dist/assets/{psyche-report-detail-page-Ci14mNUK.js → psyche-report-detail-page-x2AtC99e.js} +3 -3
  76. package/dist/assets/psyche-reports-page-KiwCgWPa.js +1 -0
  77. package/dist/assets/{psyche-schemas-Dxj554nU.js → psyche-schemas-Dtskzvv1.js} +1 -1
  78. package/dist/assets/psyche-schemas-beliefs-page-CIEoAJAp.js +9 -0
  79. package/dist/assets/psyche-screen-time-page-DO6UycL9.js +1 -0
  80. package/dist/assets/psyche-self-observation-page-CPcpUSdm.js +1 -0
  81. package/dist/assets/psyche-values-page-BAgNeo4L.js +5 -0
  82. package/dist/assets/question-flow-dialog-BByFV8Yw.js +2 -0
  83. package/dist/assets/{report-chain-fields-CbkT7WOO.js → report-chain-fields-BpRWMp7h.js} +1 -1
  84. package/dist/assets/rewards-page-kIiX8SHn.js +1 -0
  85. package/dist/assets/{scheduling-rules-editor-BUGnZJ0g.js → scheduling-rules-editor-oQXGcL5l.js} +1 -1
  86. package/dist/assets/{schema-badge-CLAA4p-b.js → schema-badge-BoNjw3h4.js} +1 -1
  87. package/dist/assets/schemas-IBbtdPzn.js +1 -0
  88. package/dist/assets/{select-menu-Cqs5t3ng.js → select-menu-U-YryCwP.js} +1 -1
  89. package/dist/assets/{settings-agents-page-pmkVrOO8.js → settings-agents-page-CbHeMq3e.js} +4 -4
  90. package/dist/assets/settings-bin-page-LxS2YPsA.js +1 -0
  91. package/dist/assets/{settings-calendar-page-BBjAMOCf.js → settings-calendar-page-CZc-I-HK.js} +3 -3
  92. package/dist/assets/settings-data-page-m-aBRMR9.js +1 -0
  93. package/dist/assets/settings-logs-page-BUEGWlQu.js +1 -0
  94. package/dist/assets/settings-mobile-page-C_5CHjHl.js +1 -0
  95. package/dist/assets/settings-models-page-B4HQu8kL.js +1 -0
  96. package/dist/assets/settings-page-CY8N-fNV.js +1 -0
  97. package/dist/assets/settings-rewards-page-C0XQoWjb.js +1 -0
  98. package/dist/assets/{settings-section-nav-Co0AaDG-.js → settings-section-nav-CkqqtM0F.js} +1 -1
  99. package/dist/assets/settings-users-page-COCBOq7d.js +1 -0
  100. package/dist/assets/settings-wiki-page-Dy1d7-z-.js +1 -0
  101. package/dist/assets/sleep-page-1kKicdFq.js +1 -0
  102. package/dist/assets/sports-page-DJErRii_.js +1 -0
  103. package/dist/assets/{state-vCcAT5Hq.js → state-BtwEvpO6.js} +1 -1
  104. package/dist/assets/strategies-page-CWNFb9vv.js +1 -0
  105. package/dist/assets/strategy-detail-page-D9rFVXRS.js +1 -0
  106. package/dist/assets/strategy-dialog-BIVHfUR6.js +1 -0
  107. package/dist/assets/{surface-CyWI7e1R.js → surface-B3oXO1No.js} +1 -1
  108. package/dist/assets/{table-BNqMG3_S.js → table-BuONJH1s.js} +1 -1
  109. package/dist/assets/task-detail-page-r8ipOpAF.js +1 -0
  110. package/dist/assets/task-dialog-C3kkWtcT.js +6 -0
  111. package/dist/assets/timebox-planning-dialog-BadS5tEr.js +1 -0
  112. package/dist/assets/today-boxes-CiccN0Gw.js +1 -0
  113. package/dist/assets/today-page-DvQredbl.js +1 -0
  114. package/dist/assets/training-load-page-CkX-nSoe.js +1 -0
  115. package/dist/assets/{ui-C1iwpj2-.js → ui-B9O-eUim.js} +1 -1
  116. package/dist/assets/use-anchored-overlay-position-BrQ4cqKn.js +1 -0
  117. package/dist/assets/{use-psyche-focus-target-Ct-acS9G.js → use-psyche-focus-target-Cuxni3SK.js} +1 -1
  118. package/dist/assets/user-badge-BKzwGZDd.js +1 -0
  119. package/dist/assets/user-ownership-DJGl4rAj.js +1 -0
  120. package/dist/assets/user-select-field-BNqv8-wd.js +1 -0
  121. package/dist/assets/utility-widgets-DvxKA6dI.js +3 -0
  122. package/dist/assets/{vendor-Dnkkx2co.js → vendor-Cpmju3nw.js} +1 -1
  123. package/dist/assets/vitals-page-CRIsr_C7.js +1 -0
  124. package/dist/assets/weekly-review-page-CNqxLRCd.js +1 -0
  125. package/dist/assets/weight-loss-page-SSsCp1Yw.js +5 -0
  126. package/dist/assets/{wiki-article-markdown-Bi02AsVt.js → wiki-article-markdown-C9VKineE.js} +2 -2
  127. package/dist/assets/{wiki-editor-page-OZf9l4Tg.js → wiki-editor-page-DxGsKvF7.js} +5 -5
  128. package/dist/assets/wiki-ingest-history-page-CFmP7K1F.js +1 -0
  129. package/dist/assets/wiki-ingest-modal-BLw2PSWP.js +1 -0
  130. package/dist/assets/wiki-page-BiQ-jAuz.js +1 -0
  131. package/dist/assets/workbench-flow-page-D960hXu_.js +5 -0
  132. package/dist/assets/workbench-page-BWlY-FiL.js +1 -0
  133. package/dist/assets/workout-detail-page-G32yJoE9.js +2 -0
  134. package/dist/index.html +8 -10
  135. package/dist/server/server/src/app.js +10 -0
  136. package/dist/server/server/src/health-weight-loss.js +11 -3
  137. package/dist/server/server/src/services/dashboard.js +4 -4
  138. package/dist/server/server/src/services/gamification.js +71 -32
  139. package/openclaw.plugin.json +1 -1
  140. package/package.json +1 -1
  141. package/dist/assets/activity-page-DRRbpVK-.js +0 -1
  142. package/dist/assets/ai-surface-workspace-DJPt-OaW.js +0 -1
  143. package/dist/assets/calendar-page-y8G1ige8.js +0 -1
  144. package/dist/assets/calendar-rules-CRhXqGQu.js +0 -1
  145. package/dist/assets/companion-sync-lab-page-kEgOF3c6.js +0 -1
  146. package/dist/assets/daily-metrics-dashboard-BJjUIZVA.js +0 -1
  147. package/dist/assets/entity-notes-surface-CaCjjUaq.js +0 -1
  148. package/dist/assets/execution-board-RRWm2srb.js +0 -1
  149. package/dist/assets/goal-detail-page-BgQlK7yT.js +0 -1
  150. package/dist/assets/goals-page-Cz2i3pVy.js +0 -1
  151. package/dist/assets/habits-page-BmEmWCGv.js +0 -1
  152. package/dist/assets/index-QJkjKYzZ.js +0 -19
  153. package/dist/assets/insight-flow-dialog-CdYMHwMP.js +0 -1
  154. package/dist/assets/kanban-page-C6S_fJRc.js +0 -1
  155. package/dist/assets/knowledge-graph-page-juA9QCy0.js +0 -1
  156. package/dist/assets/life-force-page-ChTIA4mV.js +0 -1
  157. package/dist/assets/movement-page-Dx3T3HrG.js +0 -1
  158. package/dist/assets/note-tags-input-BS14YXHn.js +0 -1
  159. package/dist/assets/notes-page-D3yGl8TN.js +0 -1
  160. package/dist/assets/overview-page-DSOpBpHf.js +0 -1
  161. package/dist/assets/page-hero-CONuJu5J.js +0 -1
  162. package/dist/assets/pill-cluster-W2fY48OM.js +0 -1
  163. package/dist/assets/preferences-page-Br3zrLlH.js +0 -1
  164. package/dist/assets/project-detail-page-BIU9_TRN.js +0 -1
  165. package/dist/assets/project-management-hierarchy-page-C2H620xD.js +0 -1
  166. package/dist/assets/project-management-section-nav-DRPVS1Eh.js +0 -1
  167. package/dist/assets/projects-page-w7a_L2-z.js +0 -1
  168. package/dist/assets/psyche-behaviors-page-Dt4CMC-q.js +0 -5
  169. package/dist/assets/psyche-flashcards-page-rXz06dqO.js +0 -1
  170. package/dist/assets/psyche-goal-map-page-BCcD6Jkl.js +0 -1
  171. package/dist/assets/psyche-graph-CXlAj4ED.js +0 -1
  172. package/dist/assets/psyche-metrics-page-B1otiir6.js +0 -1
  173. package/dist/assets/psyche-mode-guide-page-C6AdVIAv.js +0 -1
  174. package/dist/assets/psyche-modes-page-DoUqz2mR.js +0 -1
  175. package/dist/assets/psyche-page-BJNLQn8W.js +0 -1
  176. package/dist/assets/psyche-patterns-page-CzpMSAPu.js +0 -5
  177. package/dist/assets/psyche-questionnaire-builder-page-DjzatGVZ.js +0 -1
  178. package/dist/assets/psyche-questionnaire-detail-page-B0Qfowfg.js +0 -1
  179. package/dist/assets/psyche-questionnaire-run-detail-page-B2dNj4jJ.js +0 -1
  180. package/dist/assets/psyche-questionnaire-run-page-DyD9Ui-g.js +0 -1
  181. package/dist/assets/psyche-questionnaires-page-BxfKcoi3.js +0 -1
  182. package/dist/assets/psyche-reports-page-ALhNueiV.js +0 -1
  183. package/dist/assets/psyche-schemas-beliefs-page-C0P2Vw6-.js +0 -9
  184. package/dist/assets/psyche-screen-time-page-BYnaT3cb.js +0 -1
  185. package/dist/assets/psyche-self-observation-page-eM9vpwIB.js +0 -1
  186. package/dist/assets/psyche-values-page-BqrGIDok.js +0 -5
  187. package/dist/assets/rewards-page-DpAJ8IxE.js +0 -1
  188. package/dist/assets/settings-bin-page-BwtLrweW.js +0 -1
  189. package/dist/assets/settings-data-page-Bqy5SukM.js +0 -1
  190. package/dist/assets/settings-logs-page-8khtrf4T.js +0 -1
  191. package/dist/assets/settings-mobile-page-BcyRjEU_.js +0 -1
  192. package/dist/assets/settings-models-page-DlSnO9WX.js +0 -1
  193. package/dist/assets/settings-page-CyBQ2qcB.js +0 -1
  194. package/dist/assets/settings-rewards-page-BBX2WtVM.js +0 -1
  195. package/dist/assets/settings-users-page-JSnfFFPu.js +0 -1
  196. package/dist/assets/settings-wiki-page--nT23Fdy.js +0 -1
  197. package/dist/assets/sleep-page-CGMi3MtV.js +0 -1
  198. package/dist/assets/sports-page-Kv5bBoLr.js +0 -1
  199. package/dist/assets/strategies-page-Br7RdUJO.js +0 -1
  200. package/dist/assets/strategy-detail-page-CBWXjUhC.js +0 -1
  201. package/dist/assets/strategy-dialog-BTwkaSxI.js +0 -1
  202. package/dist/assets/task-detail-page-Qis9354n.js +0 -1
  203. package/dist/assets/timebox-planning-dialog-DB8snOBD.js +0 -1
  204. package/dist/assets/today-page-D9A5PU0S.js +0 -1
  205. package/dist/assets/training-load-page-Bpd4DQAh.js +0 -1
  206. package/dist/assets/vitals-page-CVYC-4RG.js +0 -1
  207. package/dist/assets/weekly-review-page-BP7N3fNB.js +0 -1
  208. package/dist/assets/weight-loss-page-_fX3N1UK.js +0 -5
  209. package/dist/assets/wiki-ingest-history-page-CzeNSL7N.js +0 -1
  210. package/dist/assets/wiki-ingest-modal-Ig_xnyc6.js +0 -1
  211. package/dist/assets/wiki-page-B4xuNgY4.js +0 -1
  212. package/dist/assets/workbench-flow-page-BhRJCALC.js +0 -5
  213. package/dist/assets/workbench-page-DxVs2AOY.js +0 -1
  214. package/dist/assets/workout-detail-page-D4wfkE98.js +0 -2
@@ -0,0 +1 @@
1
+ import{b6 as Pe,r as p,j as e,aK as se,dD as te,dE as Le,aN as Ke,dF as Fe,ca as Me,aG as G,dG as fe,bV as $e,b7 as he}from"./vendor-Cpmju3nw.js";import{R as qe,P as ze,O as De,C as Qe,T as Re,D as We,a as Ue}from"./ui-B9O-eUim.js";import{j as Oe,i as re,k as D}from"./state-BtwEvpO6.js";import{ep as Be,eq as Ge,er as ye,es as Ve,et as He,eu as Ze,c,I as je,T as Ye,B as C,b as ae,k as ie,g as Xe,s as Je,ev as et,ew as tt}from"./index-BejvcRGb.js";const $=new Set(["queued","processing"]),Ne=15e3,j="border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)]",z="border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",q="border-[color-mix(in_srgb,var(--primary)_30%,transparent)] bg-[var(--ui-accent-soft)] text-[var(--ui-ink-strong)]",V="border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-medium)] hover:bg-[var(--ui-surface-2)] hover:text-[var(--ui-ink-strong)]",at=["goal","project","task","habit","strategy","psyche_value","flashcard","note"];function ke(i){return new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}).format(new Date(i))}function _(i,a){const r=i[a];return typeof r=="number"&&Number.isFinite(r)?r:null}function y(i,a){const r=i[a];return typeof r=="string"&&r.trim().length>0?r:null}function it(i,a){const r=y(i.metadata,"currentFileName")??y(i.metadata,"fileName")??"current source",f=y(i.metadata,"status")??"in_progress",o=_(i.metadata,"chunkIndex"),x=_(i.metadata,"chunkCount"),N=_(i.metadata,"currentFileIndex"),b=_(i.metadata,"currentFileTotal"),k=N!==null&&b!==null?`${r} (${N}/${b})`:r,u=o!==null&&x!==null&&x>1?` · chunk ${o}/${x}`:"";return`Waiting for OpenAI on ${k}${u}. ${a} polls · ${f}.`}function st(i){const a=[];for(const r of i){const f=y(r.metadata,"scope"),x=y(r.metadata,"eventKey")==="llm_compile_background_polled",N=y(r.metadata,"currentFileName")??y(r.metadata,"fileName"),b=_(r.metadata,"chunkIndex"),k=_(r.metadata,"chunkCount"),u=x?["poll",f??"",N??"",b??"",k??""].join(":"):null,m=a[a.length-1],A=m&&y(m.metadata,"eventKey"),w=m&&(y(m.metadata,"currentFileName")??y(m.metadata,"fileName")),E=m&&_(m.metadata,"chunkIndex"),h=m&&_(m.metadata,"chunkCount"),P=m&&A==="llm_compile_background_polled"?["poll",y(m.metadata,"scope")??"",w??"",E??"",h??""].join(":"):null;if(x&&m&&P===u){a[a.length-1]={...r,repetitionCount:m.repetitionCount+1,metadata:{...r.metadata,aggregatedPollCount:m.repetitionCount+1}};continue}a.push({...r,repetitionCount:1})}return a}function H(i){return Xe(i)}function we(i){return typeof i=="string"&&at.includes(i)}function rt(i,a){return typeof a.title=="string"&&a.title.trim().length>0?a.title:typeof a.displayName=="string"&&a.displayName.trim().length>0?a.displayName:typeof a.statement=="string"&&a.statement.trim().length>0?a.statement:`${i}:${String(a.id??"")}`}function nt(i,a){const f=[a.description,a.summary,a.overview,a.valuedDirection,a.whyItMatters,a.originNote].find(o=>typeof o=="string"&&o.trim().length>0);return f||(i==="note"&&typeof a.kind=="string"?a.kind:"")}function lt({candidate:i,decision:a,onDecisionChange:r,spaceId:f}){const o=we(i.payload.entityType)?i.payload.entityType:null,[x,N]=p.useState(a.mappedEntityLabel||i.title||""),[b,k]=p.useState(a.targetNoteLabel||i.title||""),u=typeof i.payload.contentMarkdown=="string"?i.payload.contentMarkdown:typeof i.payload.patchSummary=="string"?i.payload.patchSummary:typeof i.payload.rationale=="string"?i.payload.rationale:i.summary,m=re({queryKey:["forge-wiki-ingest-map-search",o,x.trim()],enabled:i.candidateType==="entity"&&a.action==="map_existing"&&o!==null&&x.trim().length>0,queryFn:async()=>{var F;const v=(await Je({searches:[{entityTypes:o?[o]:void 0,query:x.trim(),limit:8}]})).results[0];return((F=v==null?void 0:v.matches)==null?void 0:F.filter(g=>!!(g&&we(g.entityType)&&typeof g.id=="string"&&g.entity&&typeof g.entity=="object")).map(g=>({entityType:g.entityType,entityId:g.id,label:rt(g.entityType,g.entity),description:nt(g.entityType,g.entity),kind:H(g.entityType)})))??[]}}),A=m.data??[],w=re({queryKey:["forge-wiki-ingest-merge-search",f,b.trim()],enabled:i.candidateType==="page"&&a.action==="merge_existing"&&b.trim().length>0,queryFn:async()=>(await et({spaceId:f,kind:"wiki",mode:"text",query:b.trim(),limit:8})).results.map(v=>({noteId:v.page.id,title:v.page.title,slug:v.page.slug,summary:v.page.summary}))}),E=w.data??[],h=a.mappedEntityId&&a.mappedEntityType?A.find(s=>s.entityId===a.mappedEntityId&&s.entityType===a.mappedEntityType)??(a.mappedEntityLabel?{entityId:a.mappedEntityId,entityType:a.mappedEntityType,label:a.mappedEntityLabel,kind:H(a.mappedEntityType)}:null):null,P=a.targetNoteId?E.find(s=>s.noteId===a.targetNoteId)??(a.targetNoteLabel?{noteId:a.targetNoteId,title:a.targetNoteLabel}:null):null;return e.jsxs("div",{className:c("rounded-[24px] border p-4",j),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:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:i.candidateType.replaceAll("_"," ")}),e.jsx("div",{className:"mt-2 text-base font-semibold text-[var(--ui-ink-strong)]",children:i.title||i.targetKey||"Untitled candidate"}),o?e.jsx("div",{className:"mt-2",children:H(o)?e.jsx(ae,{kind:H(o),label:o.replaceAll("_"," "),compact:!0,gradient:!1}):e.jsx(ie,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:o.replaceAll("_"," ")})}):null,i.summary?e.jsx("div",{className:"mt-1 text-sm leading-6 text-[var(--ui-ink-soft)]",children:i.summary}):null]}),e.jsxs("div",{className:"inline-flex items-center gap-2 rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-1",children:[e.jsx("button",{type:"button",className:c("rounded-full px-3 py-1.5 text-xs font-medium transition",a.action==="keep"?"bg-[var(--ui-accent-soft)] text-[var(--ui-ink-strong)]":"text-[var(--ui-ink-soft)] hover:text-[var(--ui-ink-strong)]"),onClick:()=>r({...a,action:"keep"}),children:"Keep"}),i.candidateType==="entity"&&o?e.jsx("button",{type:"button",className:c("rounded-full px-3 py-1.5 text-xs font-medium transition",a.action==="map_existing"?"bg-[var(--ui-info-soft)] text-[var(--ui-ink-strong)]":"text-[var(--ui-ink-soft)] hover:text-[var(--ui-ink-strong)]"),onClick:()=>r({...a,action:"map_existing",mappedEntityType:o}),children:"Map existing"}):null,i.candidateType==="page"?e.jsx("button",{type:"button",className:c("rounded-full px-3 py-1.5 text-xs font-medium transition",a.action==="merge_existing"?"bg-[var(--ui-info-soft)] text-[var(--ui-ink-strong)]":"text-[var(--ui-ink-soft)] hover:text-[var(--ui-ink-strong)]"),onClick:()=>r({...a,action:"merge_existing"}),children:"Merge existing"}):null,e.jsx("button",{type:"button",className:c("rounded-full px-3 py-1.5 text-xs font-medium transition",a.action==="discard"?"bg-[var(--ui-surface-2)] text-[var(--ui-ink-strong)]":"text-[var(--ui-ink-soft)] hover:text-[var(--ui-ink-strong)]"),onClick:()=>r({...a,action:"discard"}),children:"Discard"})]})]}),i.candidateType==="entity"&&o&&a.action==="map_existing"?e.jsxs("div",{className:c("mt-4 grid gap-3 rounded-[18px] border p-4",z),children:[e.jsxs("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:["Map to existing ",o.replaceAll("_"," ")]}),h?e.jsx("div",{className:"flex flex-wrap gap-2",children:e.jsxs("span",{className:"inline-flex items-center gap-2 rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-2.5 py-1.5",children:[h.kind?e.jsx(ae,{kind:h.kind,label:h.label,compact:!0,gradient:!1,className:"max-w-[20rem]"}):e.jsx(ie,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:h.label}),e.jsx("button",{type:"button",className:"rounded-full text-[var(--ui-ink-faint)] transition hover:text-[var(--ui-ink-strong)]",onClick:()=>r({...a,mappedEntityId:void 0,mappedEntityLabel:void 0}),"aria-label":"Clear mapped entity",children:e.jsx(se,{className:"size-3.5"})})]})}):null,e.jsxs("div",{className:c("flex items-center gap-3 rounded-[20px] border px-4 py-3",j),children:[e.jsx(he,{className:"size-4 text-[var(--ui-ink-faint)]"}),e.jsx("input",{value:x,onChange:s=>{N(s.target.value),a.mappedEntityId&&r({...a,mappedEntityId:void 0,mappedEntityLabel:void 0})},placeholder:`Search existing ${o.replaceAll("_"," ")}`,className:"min-w-0 flex-1 bg-transparent text-sm text-[var(--ui-ink-strong)] placeholder:text-[var(--ui-ink-faint)] focus:outline-none"})]}),e.jsx("div",{className:"grid gap-2",children:m.isPending?e.jsx("div",{className:c("rounded-[16px] border px-3 py-3 text-sm text-[var(--ui-ink-faint)]",j),children:"Searching Forge…"}):A.length===0?e.jsxs("div",{className:"rounded-[16px] border border-dashed border-[var(--ui-border-subtle)] px-3 py-3 text-sm text-[var(--ui-ink-faint)]",children:["No existing ",o.replaceAll("_"," ")," matches yet."]}):A.map(s=>{const v=a.mappedEntityType===s.entityType&&a.mappedEntityId===s.entityId;return e.jsx("button",{type:"button",className:c("flex w-full items-start justify-between gap-3 rounded-[18px] border px-3 py-3 text-left transition",v?q:"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-medium)] hover:bg-[var(--ui-surface-2)] hover:text-[var(--ui-ink-strong)]"),onClick:()=>r({action:"map_existing",mappedEntityType:s.entityType,mappedEntityId:s.entityId,mappedEntityLabel:s.label}),children:e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-medium",children:s.kind?e.jsx(ae,{kind:s.kind,label:s.label,compact:!0,gradient:!1}):s.label}),s.description?e.jsx("div",{className:"mt-1 text-xs leading-5 text-[var(--ui-ink-faint)]",children:s.description}):null]})},`${s.entityType}:${s.entityId}`)})})]}):null,i.candidateType==="page"&&a.action==="merge_existing"?e.jsxs("div",{className:c("mt-4 grid gap-3 rounded-[18px] border p-4",z),children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Merge into existing page"}),P?e.jsx("div",{className:"flex flex-wrap gap-2",children:e.jsxs("span",{className:"inline-flex items-center gap-2 rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-2.5 py-1.5",children:[e.jsx(ie,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:P.title}),e.jsx("button",{type:"button",className:"rounded-full text-[var(--ui-ink-faint)] transition hover:text-[var(--ui-ink-strong)]",onClick:()=>r({...a,targetNoteId:void 0,targetNoteLabel:void 0}),"aria-label":"Clear merge target",children:e.jsx(se,{className:"size-3.5"})})]})}):null,e.jsxs("div",{className:c("flex items-center gap-3 rounded-[20px] border px-4 py-3",j),children:[e.jsx(he,{className:"size-4 text-[var(--ui-ink-faint)]"}),e.jsx("input",{value:b,onChange:s=>{k(s.target.value),a.targetNoteId&&r({...a,targetNoteId:void 0,targetNoteLabel:void 0})},placeholder:"Search existing wiki pages",className:"min-w-0 flex-1 bg-transparent text-sm text-[var(--ui-ink-strong)] placeholder:text-[var(--ui-ink-faint)] focus:outline-none"})]}),e.jsx("div",{className:"grid gap-2",children:w.isPending?e.jsx("div",{className:c("rounded-[16px] border px-3 py-3 text-sm text-[var(--ui-ink-faint)]",j),children:"Searching Forge…"}):E.length===0?e.jsx("div",{className:"rounded-[16px] border border-dashed border-[var(--ui-border-subtle)] px-3 py-3 text-sm text-[var(--ui-ink-faint)]",children:"No existing wiki pages match yet."}):E.map(s=>{const v=a.targetNoteId===s.noteId;return e.jsx("button",{type:"button",className:c("flex w-full items-start justify-between gap-3 rounded-[18px] border px-3 py-3 text-left transition",v?q:"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-medium)] hover:bg-[var(--ui-surface-2)] hover:text-[var(--ui-ink-strong)]"),onClick:()=>r({action:"merge_existing",targetNoteId:s.noteId,targetNoteLabel:s.title}),children:e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-medium",children:s.title}),e.jsxs("div",{className:"mt-1 text-xs leading-5 text-[var(--ui-ink-faint)]",children:[s.slug?`${s.slug}`:"",s.summary?`${s.slug?" · ":""}${s.summary}`:""]})]})},s.noteId)})})]}):null,u?e.jsx("div",{className:c("mt-4 rounded-[18px] border px-4 py-3 text-sm leading-6 text-[var(--ui-ink-medium)]",z),children:e.jsx("pre",{className:"whitespace-pre-wrap font-sans",children:u})}):null]})}function pt({open:i,onOpenChange:a,spaces:r,llmProfiles:f,initialSpaceId:o,selectedJobId:x,onJobSelected:N,linkedEntityHints:b=[]}){var ge;const k=Pe(),u=Oe(),[m,A]=p.useState("files"),[w,E]=p.useState(o),[h,P]=p.useState(""),[s,v]=p.useState(""),[F,g]=p.useState(""),[Q,Z]=p.useState([]),[Ee,R]=p.useState(!1),[Ie,Se]=p.useState(!1),I=p.useMemo(()=>f.filter(t=>t.enabled&&!!t.secretId),[f]),[W,ne]=p.useState(((ge=I[0])==null?void 0:ge.id)??""),[U,Te]=p.useState("auto"),[Y,le]=p.useState({}),[O,S]=p.useState(null),[B,T]=p.useState(null),oe=p.useRef({});p.useEffect(()=>{o&&E(o)},[o]),p.useEffect(()=>{var t;!W&&((t=I[0])!=null&&t.id)&&ne(I[0].id)},[W,I]);const M=I.find(t=>t.id===W)??I[0]??null,L=re({queryKey:["forge-wiki-ingest-job",x],queryFn:()=>tt(x),enabled:i&&!!x,refetchInterval:t=>{const d=t.state.data;return d&&$.has(d.job.status)?2e3:!1}});p.useEffect(()=>{const t=L.data;t&&le(d=>{const l={};for(const K of t.candidates)l[K.id]=d[K.id]??(K.status==="rejected"?{action:"discard"}:{action:"keep"});return l})},[L.data]),p.useEffect(()=>{B&&T(null)},[Y,B]);const X=D({mutationFn:async t=>Be(t),onSuccess:(t,d)=>{t.job&&u.setQueryData(["forge-wiki-ingest-job",d],t.job),u.invalidateQueries({queryKey:["forge-wiki-ingest-jobs"]}),u.invalidateQueries({queryKey:["forge-wiki-ingest-history"]})}});p.useEffect(()=>{const t=L.data;if(!t||!$.has(t.job.status))return;const d=t.logs.reduce((ve,Ae)=>{const be=Number(new Date(Ae.createdAt));return Number.isFinite(be)?Math.max(ve,be):ve},0),l=Number(new Date(t.job.updatedAt)),K=Math.max(Number.isFinite(l)?l:0,d);if(!Number.isFinite(K)||K<=0)return;const ee=Date.now();if(!(ee-K>=Ne)||X.isPending)return;const _e=oe.current[t.job.id]??0;ee-_e<Ne||(oe.current[t.job.id]=ee,X.mutate(t.job.id))},[L.data,X]);const de=D({mutationFn:async()=>{if(!M)throw new Error("Set up an OpenAI wiki ingest profile first. Forge now requires an LLM profile before auto-ingest can turn source material into draft pages and entities.");if(m==="files"){if(Q.length===0)throw new Error("Select at least one file to ingest.");return Ge({files:Q,spaceId:w||void 0,titleHint:h.trim()||void 0,llmProfileId:M.id,parseStrategy:U,createAsKind:"wiki",linkedEntityHints:b})}if(m==="url"){if(!s.trim())throw new Error("Enter a URL to ingest.");return ye({spaceId:w||void 0,titleHint:h.trim()||void 0,sourceKind:"url",sourceUrl:s.trim(),llmProfileId:M.id,parseStrategy:U,createAsKind:"wiki",linkedEntityHints:b})}if(!F.trim())throw new Error("Paste some text to ingest.");return ye({spaceId:w||void 0,titleHint:h.trim()||void 0,sourceKind:"raw_text",sourceText:F,mimeType:"text/plain",llmProfileId:M.id,parseStrategy:U,createAsKind:"wiki",linkedEntityHints:b})},onSuccess:async t=>{var l;const d=((l=t.job)==null?void 0:l.job.id)??null;await u.invalidateQueries({queryKey:["forge-wiki-ingest-jobs"]}),await u.invalidateQueries({queryKey:["forge-wiki-ingest-history"]}),d&&N(d),S(null),T(null)},onError:t=>{S(t instanceof Error?t.message:"Unable to start ingest.")}}),ce=D({mutationFn:async()=>{if(!x||!L.data)throw new Error("Choose an ingest job first.");const t=L.data.candidates.map(d=>{const l=Y[d.id]??{action:"keep"};if(l.action==="map_existing"&&(!l.mappedEntityType||!l.mappedEntityId))throw new Error(`Choose an existing ${String(d.payload.entityType??"entity").replaceAll("_"," ")} before publishing the review.`);if(l.action==="merge_existing"&&!l.targetNoteId)throw new Error(`Choose an existing wiki page before publishing the review for ${d.title||"this page candidate"}.`);return l.action==="map_existing"?{candidateId:d.id,action:"map_existing",mappedEntityType:l.mappedEntityType,mappedEntityId:l.mappedEntityId}:l.action==="merge_existing"?{candidateId:d.id,action:"merge_existing",targetNoteId:l.targetNoteId}:{candidateId:d.id,action:l.action}});return Ve({jobId:x,decisions:t})},onSuccess:async t=>{T(null),u.setQueryData(["forge-wiki-ingest-job",t.job.job.id],t.job),await Promise.all([u.invalidateQueries({queryKey:["forge-wiki-ingest-jobs"]}),u.invalidateQueries({queryKey:["forge-wiki-ingest-history"]}),u.invalidateQueries({queryKey:["forge-wiki-ingest-job",t.job.job.id]}),u.invalidateQueries({queryKey:["forge-wiki-home"]}),u.invalidateQueries({queryKey:["forge-wiki-page-by-slug"]}),u.invalidateQueries({queryKey:["forge-wiki-tree"]})])},onError:t=>{T(t instanceof Error?t.message:"Unable to publish review.")}}),ue=D({mutationFn:async()=>{if(!x)throw new Error("Choose an ingest job first.");return He(x)},onSuccess:async t=>{var l;const d=((l=t.job)==null?void 0:l.job.id)??null;await Promise.all([u.invalidateQueries({queryKey:["forge-wiki-ingest-jobs"]}),u.invalidateQueries({queryKey:["forge-wiki-ingest-history"]}),u.invalidateQueries({queryKey:["forge-wiki-ingest-job",x]})]),d&&N(d),S(null),T(null)},onError:t=>{S(t instanceof Error?t.message:"Unable to rerun ingest.")}}),me=D({mutationFn:async()=>{if(!x)throw new Error("Choose an ingest job first.");return Ze(x)},onSuccess:async()=>{await Promise.all([u.invalidateQueries({queryKey:["forge-wiki-ingest-jobs"]}),u.invalidateQueries({queryKey:["forge-wiki-ingest-history"]}),u.invalidateQueries({queryKey:["forge-wiki-ingest-job",x]})]),xe(),S(null),T(null)},onError:t=>{S(t instanceof Error?t.message:"Unable to delete ingest.")}}),n=L.data??null,Ce=n&&!$.has(n.job.status),J=p.useMemo(()=>(n==null?void 0:n.candidates.filter(t=>["suggested","rejected","failed"].includes(t.status)))??[],[n]),pe=p.useMemo(()=>st((n==null?void 0:n.logs)??[]),[n==null?void 0:n.logs]),xe=()=>{N(null),Z([]),v(""),g(""),P(""),S(null),T(null)};return e.jsx(qe,{open:i,onOpenChange:t=>{a(t),t||(S(null),T(null))},children:e.jsxs(ze,{children:[e.jsx(De,{className:"fixed inset-0 z-50 surface-overlay backdrop-blur-sm"}),e.jsxs(Qe,{className:"fixed inset-x-4 bottom-4 top-4 z-50 mx-auto flex max-w-[min(74rem,calc(100vw-2rem))] flex-col overflow-hidden rounded-[32px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-popover)] shadow-[var(--ui-shadow-floating)]",children:[e.jsx("div",{className:"border-b border-[var(--ui-border-subtle)] px-5 py-5",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"KarpaWiki Ingest"}),e.jsx(Re,{className:"mt-2 font-display text-[1.5rem] tracking-[-0.04em] text-[var(--ui-ink-strong)]",children:n?"Ingest review and progress":"Build KarpaWiki memory from source files"}),e.jsx(We,{className:"mt-2 max-w-3xl text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Upload notes, media, ZIP archives, links, or pasted text. Forge will process them in the background, propose pages and entities, and let you keep only what belongs."})]}),e.jsx(Ue,{asChild:!0,children:e.jsx("button",{type:"button",className:"rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-2 text-[var(--ui-ink-soft)] transition hover:bg-[var(--ui-surface-2)] hover:text-[var(--ui-ink-strong)]","aria-label":"Close ingest modal",children:e.jsx(se,{className:"size-4"})})})]})}),e.jsx("div",{className:"flex-1 overflow-y-auto px-5 py-5",children:n?e.jsxs("div",{className:"grid gap-5 xl:grid-cols-[minmax(0,0.9fr)_minmax(0,1.1fr)]",children:[e.jsxs("div",{className:"grid gap-5",children:[e.jsxs("div",{className:c("rounded-[28px] border p-4 sm:p-5",j),children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:["Job ",n.job.id]}),e.jsx("div",{className:"mt-2 text-xl font-semibold text-[var(--ui-ink-strong)]",children:n.job.latestMessage||"Ingest job"}),e.jsxs("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:[n.job.status," · ",n.job.phase," · started ",ke(n.job.createdAt)]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(C,{variant:"secondary",size:"sm",onClick:xe,children:"New ingest"}),Ce?e.jsxs(e.Fragment,{children:[e.jsxs(C,{variant:"secondary",size:"sm",pending:ue.isPending,pendingLabel:"Rerunning",onClick:()=>void ue.mutateAsync(),children:[e.jsx(G,{className:"size-3.5"}),"Rerun"]}),e.jsx(C,{variant:"ghost",size:"sm",className:"border border-rose-300/18 bg-rose-400/10 text-rose-100 hover:bg-rose-400/16",pending:me.isPending,pendingLabel:"Deleting",onClick:()=>{window.confirm("Delete this ingest history entry? Published pages or entities will stay, but discarded or unreviewed ingest data will be removed.")&&me.mutateAsync()},children:"Delete"})]}):null]})]}),e.jsx("div",{className:"mt-5 grid gap-3 sm:grid-cols-4",children:[{label:"Progress",value:`${n.job.progressPercent}%`},{label:"Files",value:`${n.job.processedFiles}/${n.job.totalFiles}`},{label:"Pages",value:String(n.job.createdPageCount)},{label:"Entities",value:String(n.job.createdEntityCount)}].map(t=>e.jsxs("div",{className:c("rounded-[22px] border px-4 py-3",z),children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:t.label}),e.jsx("div",{className:"mt-2 text-lg font-semibold text-[var(--ui-ink-strong)]",children:t.value})]},t.label))}),e.jsx("div",{className:"mt-5",children:e.jsx("div",{className:"h-2 overflow-hidden rounded-full bg-[var(--ui-surface-2)]",children:e.jsx("div",{className:"h-full rounded-full bg-[var(--primary)] transition-all duration-300",style:{width:`${n.job.progressPercent}%`}})})}),O?e.jsx("div",{className:"mt-4 rounded-[20px] border border-rose-300/22 bg-rose-400/10 px-4 py-3 text-sm text-rose-100",children:O}):null]}),e.jsxs("div",{className:c("rounded-[28px] border p-4 sm:p-5",j),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Rich log"}),e.jsx(C,{variant:"secondary",size:"sm",onClick:()=>k(`/settings/logs?jobId=${encodeURIComponent(n.job.id)}`),children:"Open full logs"})]}),e.jsx("div",{className:"mt-4 grid max-h-[28rem] gap-2 overflow-y-auto",children:pe.length===0?e.jsx("div",{className:"rounded-[18px] border border-dashed border-[var(--ui-border-subtle)] px-4 py-4 text-sm text-[var(--ui-ink-faint)]",children:"Waiting for the backend to emit progress."}):pe.map(t=>e.jsx("div",{className:c("rounded-[18px] border px-4 py-3",z),children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-2 py-1 text-[10px] font-semibold uppercase tracking-[0.14em] text-[var(--ui-ink-soft)]",children:t.level}),typeof t.metadata.scope=="string"?e.jsx("span",{className:"rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-2 py-1 text-[10px] font-semibold uppercase tracking-[0.14em] text-[var(--ui-ink-faint)]",children:t.metadata.scope}):null,typeof t.metadata.eventKey=="string"?e.jsx("span",{className:"rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-2 py-1 text-[10px] font-semibold uppercase tracking-[0.14em] text-[var(--ui-ink-faint)]",children:t.metadata.eventKey}):null]}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-strong)]",children:y(t.metadata,"eventKey")==="llm_compile_background_polled"?it(t,t.repetitionCount):t.message}),t.repetitionCount>1?e.jsxs("div",{className:"mt-2 text-xs text-[var(--ui-ink-faint)]",children:["Combined ",t.repetitionCount," repeated polling updates."]}):null,Object.keys(t.metadata).length>0?e.jsxs("details",{className:"mt-3",children:[e.jsx("summary",{className:"cursor-pointer text-xs text-[var(--ui-ink-faint)]",children:"View metadata"}),e.jsx("pre",{className:"mt-2 max-w-full overflow-x-auto whitespace-pre-wrap rounded-[14px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-code)] px-3 py-3 text-[11px] leading-5 text-[var(--ui-ink-soft)]",children:JSON.stringify(t.metadata,null,2)})]}):null]}),e.jsx("div",{className:"text-[11px] uppercase tracking-[0.14em] text-[var(--ui-ink-faint)]",children:ke(t.createdAt)})]})},t.id))})]})]}),e.jsxs("div",{className:"grid gap-5",children:[e.jsxs("div",{className:c("rounded-[28px] border p-4 sm:p-5",j),children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Source files"}),e.jsx("div",{className:"mt-4 grid gap-2",children:n.assets.map(t=>e.jsxs("div",{className:c("flex min-w-0 items-center justify-between gap-3 rounded-[18px] border px-4 py-3",z),children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-medium text-[var(--ui-ink-strong)]",children:t.fileName||t.sourceLocator||"Source"}),e.jsx("div",{className:"mt-1 text-xs text-[var(--ui-ink-faint)]",children:t.mimeType||t.sourceKind})]}),e.jsx("div",{className:"shrink-0 text-[11px] uppercase tracking-[0.14em] text-[var(--ui-ink-faint)]",children:t.status})]},t.id))})]}),e.jsxs("div",{className:c("rounded-[28px] border p-4 sm:p-5",j),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Review"}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Keep the candidates that belong in Forge and discard the rest."})]}),$.has(n.job.status)?e.jsxs("div",{className:"inline-flex items-center gap-2 rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-3 py-2 text-xs text-[var(--ui-ink-soft)]",children:[e.jsx($e,{className:"size-3.5 animate-spin"}),"Processing"]}):null]}),e.jsx("div",{className:"mt-4 grid gap-3",children:J.length===0?e.jsx("div",{className:"rounded-[18px] border border-dashed border-[var(--ui-border-subtle)] px-4 py-4 text-sm text-[var(--ui-ink-faint)]",children:$.has(n.job.status)?"Candidates will appear here while the job progresses.":"This job has no reviewable candidates left."}):J.map(t=>e.jsx(lt,{candidate:t,spaceId:n.job.spaceId,decision:Y[t.id]??{action:"keep"},onDecisionChange:d=>le(l=>({...l,[t.id]:d}))},t.id))}),B?e.jsx("div",{className:"mt-4 rounded-[20px] border border-rose-300/22 bg-rose-400/10 px-4 py-3 text-sm text-rose-100",children:B}):null,J.length>0&&!$.has(n.job.status)?e.jsx("div",{className:"mt-5",children:e.jsxs(C,{className:"min-h-12",pending:ce.isPending,pendingLabel:"Publishing review",onClick:()=>void ce.mutateAsync(),children:[e.jsx(fe,{className:"size-4"}),"Publish kept candidates"]})}):null]})]})]}):e.jsxs("div",{className:"grid gap-5 lg:grid-cols-[minmax(0,1.15fr)_minmax(18rem,0.85fr)]",children:[e.jsxs("div",{className:"grid gap-5",children:[e.jsx("div",{className:"grid gap-3 sm:grid-cols-3",children:[{id:"files",label:"Files and ZIP",detail:"Drag many files or one archive.",icon:te},{id:"url",label:"URL",detail:"Pull a webpage or remote file.",icon:Le},{id:"text",label:"Paste text",detail:"Turn notes or transcripts into pages.",icon:Ke}].map(t=>{const d=t.icon,l=t.id===m;return e.jsxs("button",{type:"button",className:c("rounded-[24px] border px-4 py-4 text-left transition",l?q:V),onClick:()=>A(t.id),children:[e.jsx(d,{className:"size-4 text-[var(--secondary)]"}),e.jsx("div",{className:"mt-3 text-sm font-semibold",children:t.label}),e.jsx("div",{className:"mt-1 text-xs leading-5 text-[var(--ui-ink-faint)]",children:t.detail})]},t.id)})}),e.jsx("div",{className:c("rounded-[28px] border p-4 sm:p-5",j),children:e.jsxs("div",{className:"grid gap-4",children:[e.jsx(je,{value:h,onChange:t=>P(t.target.value),placeholder:"Optional title hint"}),m==="files"?e.jsxs("div",{className:c("rounded-[28px] border-2 border-dashed px-5 py-8 text-center transition",Ee?"border-[color-mix(in_srgb,var(--primary)_36%,transparent)] bg-[var(--ui-accent-soft)]":j),onDragEnter:t=>{t.preventDefault(),R(!0)},onDragLeave:t=>{t.preventDefault(),R(!1)},onDragOver:t=>{t.preventDefault(),R(!0)},onDrop:t=>{t.preventDefault(),R(!1);const d=Array.from(t.dataTransfer.files);Z(l=>[...l,...d])},children:[e.jsx("div",{className:"mx-auto flex size-14 items-center justify-center rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",children:e.jsx(te,{className:"size-5 text-[var(--ui-ink-medium)]"})}),e.jsx("div",{className:"mt-4 text-base font-semibold text-[var(--ui-ink-strong)]",children:"Drop files, media, notes, or ZIP archives here"}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-faint)]",children:"Forge accepts many files at once and queues the ingest in the background so the UI stays responsive."}),e.jsxs("label",{className:"mt-5 inline-flex cursor-pointer items-center gap-2 rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-2 text-sm text-[var(--ui-ink-medium)] transition hover:bg-[var(--ui-surface-2)] hover:text-[var(--ui-ink-strong)]",children:[e.jsx(te,{className:"size-4"}),"Choose files",e.jsx("input",{type:"file",multiple:!0,className:"hidden",onChange:t=>Z(Array.from(t.target.files??[]))})]}),Q.length>0?e.jsx("div",{className:"mt-5 grid gap-2 text-left",children:Q.map(t=>e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[18px] border ${INGEST_PANEL_CLASS} px-4 py-3 text-sm text-[var(--ui-ink-medium)]",children:[e.jsx("span",{className:"truncate",children:t.name}),e.jsx("span",{className:"shrink-0 text-xs text-[var(--ui-ink-faint)]",children:t.name.toLowerCase().endsWith(".zip")?e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Fe,{className:"size-3.5"}),"ZIP"]}):`${Math.max(1,Math.round(t.size/1024))} KB`})]},`${t.name}-${t.size}-${t.lastModified}`))}):null]}):null,m==="url"?e.jsx(je,{value:s,onChange:t=>v(t.target.value),placeholder:"https://example.com/source"}):null,m==="text"?e.jsx(Ye,{value:F,onChange:t=>g(t.target.value),placeholder:"Paste notes, transcripts, meeting writeups, or source material here…",className:"min-h-[18rem]"}):null]})})]}),e.jsxs("aside",{className:"grid h-fit gap-4",children:[M?null:e.jsxs("div",{className:"rounded-[30px] border border-[color-mix(in_srgb,var(--warning)_30%,transparent)] bg-[var(--ui-warning-soft)] p-5 shadow-[var(--ui-shadow-card)]",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"mt-0.5 flex size-10 shrink-0 items-center justify-center rounded-full border border-amber-200/20 bg-amber-300/12 text-amber-100",children:e.jsx(Me,{className:"size-4.5"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-amber-100/62",children:"OpenAI setup required for smart ingest"}),e.jsx("div",{className:"mt-2 text-lg font-semibold text-[var(--ui-ink-strong)]",children:"Forge can only do a raw import without OpenAI"}),e.jsx("div",{className:"mt-3 text-sm leading-6 text-[var(--ui-ink-medium)]",children:"Without an OpenAI ingest profile, Forge cannot extract key insights, split the source into draft wiki pages, or propose Forge entities. The fallback is just a direct text import or media reference with no structured synthesis."}),e.jsx("div",{className:"mt-3 text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Set up the API key, model, thinking, and verbosity first, then come back here to build real draft pages and reviewable entity proposals."})]})]}),e.jsxs("div",{className:"mt-5 grid gap-3 sm:grid-cols-2",children:[e.jsxs(C,{className:"w-full",onClick:()=>{a(!1),k("/settings/wiki?setupLlm=1")},children:[e.jsx(G,{className:"size-4"}),"Open OpenAI setup"]}),e.jsx(C,{variant:"secondary",className:"w-full",onClick:()=>{a(!1),k("/settings/wiki")},children:"Open KarpaWiki settings"})]})]}),e.jsxs("div",{className:"rounded-[28px] border ${INGEST_PANEL_CLASS} p-4",children:[e.jsxs("button",{type:"button",className:"flex w-full items-center justify-between gap-3 text-left",onClick:()=>Se(t=>!t),children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Advanced"}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-medium)]",children:"Model, parse, and target controls."})]}),e.jsx(G,{className:"size-4 text-[var(--ui-ink-soft)]"})]}),Ie?e.jsxs("div",{className:"mt-4 grid gap-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"mb-2 text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Space"}),e.jsx("div",{className:"grid gap-2",children:r.map(t=>e.jsxs("button",{type:"button",className:c("rounded-[18px] border px-3 py-3 text-left text-sm transition",w===t.id?q:V),onClick:()=>E(t.id),children:[e.jsx("div",{children:t.label}),e.jsx("div",{className:"mt-1 text-xs text-[var(--ui-ink-faint)]",children:t.description||`/${t.slug}`})]},t.id))})]}),e.jsxs("div",{children:[e.jsx("div",{className:"mb-2 text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"LLM profile"}),e.jsxs("div",{className:"grid gap-2",children:[I.map(t=>e.jsxs("button",{type:"button",className:c("rounded-[18px] border px-3 py-3 text-left text-sm transition",W===t.id?q:V),onClick:()=>ne(t.id),children:[e.jsx("div",{children:t.label}),e.jsx("div",{className:"mt-1 text-xs text-[var(--ui-ink-faint)]",children:t.model})]},t.id)),I.length===0?e.jsx("div",{className:"rounded-[18px] border border-dashed border-[var(--ui-border-subtle)] px-4 py-4 text-sm text-[var(--ui-ink-faint)]",children:"No enabled profile with a saved key yet."}):null]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"mb-2 text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Parse mode"}),e.jsx("div",{className:"grid gap-2 sm:grid-cols-3",children:[{id:"auto",label:"Auto"},{id:"multimodal",label:"Multimodal"},{id:"text_only",label:"Text only"}].map(t=>e.jsx("button",{type:"button",className:c("rounded-[18px] border px-3 py-3 text-sm transition",U===t.id?q:V),onClick:()=>Te(t.id),children:t.label},t.id))})]})]}):null]}),e.jsxs("div",{className:"rounded-[28px] border border-[color-mix(in_srgb,var(--primary)_24%,transparent)] bg-[var(--ui-accent-soft)] p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[var(--ui-ink-strong)]",children:[e.jsx(fe,{className:"size-4 text-[var(--secondary)]"}),e.jsx("span",{className:"text-sm font-semibold",children:"Publish only what belongs"})]}),e.jsx("div",{className:"mt-3 text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Forge stages candidate pages, proposed entity records, and page updates first. You review the output before anything is committed to the live memory graph."})]}),O?e.jsx("div",{className:"rounded-[20px] border border-rose-300/22 bg-rose-400/10 px-4 py-3 text-sm text-rose-100",children:O}):null,e.jsxs(C,{className:"min-h-12",pending:de.isPending,pendingLabel:"Starting ingest",disabled:!M,onClick:()=>void de.mutateAsync(),children:[e.jsx(G,{className:"size-4"}),"Start background ingest"]})]})]})})]})]})})}export{pt as W};
@@ -0,0 +1 @@
1
+ import{b6 as Se,c6 as Ee,bY as We,r as c,j as e,b7 as Pe,cs as O,aG as ie,cB as Re,cG as ze,c1 as Ke,bX as $e,aC as le,aK as ce,bG as Le,cv as qe}from"./vendor-Cpmju3nw.js";import{R as de,P as ue,O as pe,C as me,T as xe,a as ge,D as Te}from"./ui-B9O-eUim.js";import{j as Ue,i as K,k as Fe}from"./state-BtwEvpO6.js";import{d as Be,W as De,a_ as Oe,L as D,e as ne,h as Me,b as oe,V as Qe,B as T,c as w,c8 as Je,I as _e,k as Ae,ek as He,bn as Ge,el as Ye,em as Ve,en as Xe,eo as Ze}from"./index-BejvcRGb.js";import{O as es}from"./open-in-graph-button-L21MKsb5.js";import{W as ss}from"./wiki-article-markdown-C9VKineE.js";import{W as ts}from"./wiki-ingest-modal-BLw2PSWP.js";import"./motion-DwjmC9aq.js";import"./board-CLOHbg6t.js";import"./forms-C5d5hTf2.js";function rs(a){return new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric",year:"numeric"}).format(new Date(a))}function as(a){return a.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function he({nodes:a,activeSlug:i,spaceId:u,depth:n=0}){return e.jsx("ul",{className:w("grid gap-1",n>0&&"mt-1"),children:a.map(d=>e.jsx(is,{node:d,activeSlug:i,spaceId:u,depth:n},d.page.id))})}function fe(a,i){return i?a.page.slug===i?!0:a.children.some(u=>fe(u,i)):!1}function is({node:a,activeSlug:i,spaceId:u,depth:n}){const d=a.children.length>0,f=a.page.slug===i,x=fe(a,i),[l,b]=c.useState(d&&(n===0||x));return c.useEffect(()=>{x&&b(!0)},[x]),e.jsxs("li",{className:"grid gap-1",children:[e.jsxs("div",{className:"flex items-start gap-1",children:[d?e.jsx("button",{type:"button",className:w("mt-1 inline-flex size-5 shrink-0 items-center justify-center rounded-md text-[var(--ui-ink-faint)] transition hover:bg-[var(--ui-surface-1)] hover:text-[var(--ui-ink-strong)]",n>0&&"size-4"),style:{marginLeft:`${n*.7}rem`},"aria-label":l?`Collapse ${a.page.title}`:`Expand ${a.page.title}`,"aria-expanded":l,onClick:()=>b(N=>!N),children:l?e.jsx(O,{className:"size-3.5"}):e.jsx(qe,{className:"size-3.5"})}):e.jsx("span",{className:"mt-1 size-5 shrink-0",style:{marginLeft:`${n*.7}rem`}}),e.jsx(le,{to:{pathname:a.page.slug==="index"?"/wiki":`/wiki/page/${encodeURIComponent(a.page.slug)}`,search:`?spaceId=${encodeURIComponent(u)}`},className:w("min-w-0 flex-1 rounded-lg px-2 py-1.5 text-[12px] leading-5 transition",f?"bg-[var(--ui-surface-2)] text-[var(--ui-ink-strong)]":"text-[var(--ui-ink-soft)] hover:bg-[var(--ui-surface-1)] hover:text-[var(--ui-ink-strong)]"),children:e.jsx("span",{className:"line-clamp-2",children:a.page.title})})]}),d&&l?e.jsx(he,{nodes:a.children,activeSlug:i,spaceId:u,depth:n+1}):null]})}function ns({open:a,onOpenChange:i,spaces:u,activeSpaceId:n,onSelect:d}){var x;const f=((x=u.find(l=>l.visibility==="shared"))==null?void 0:x.id)??"";return e.jsx(de,{open:a,onOpenChange:i,children:e.jsxs(ue,{children:[e.jsx(pe,{className:"fixed inset-0 z-50 surface-overlay backdrop-blur-sm"}),e.jsxs(me,{className:"fixed left-1/2 top-[14vh] z-50 w-[min(28rem,calc(100vw-1.5rem))] -translate-x-1/2 rounded-[28px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-popover)] p-4 shadow-[var(--ui-shadow-floating)] sm:p-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx(xe,{className:"font-display text-[1.2rem] tracking-[-0.04em] text-[var(--ui-ink-strong)]",children:"Choose KarpaWiki space"}),e.jsx(Te,{className:"mt-1 text-[13px] leading-6 text-[var(--ui-ink-soft)]",children:"Switch the reading space without leaving the article surface."})]}),e.jsx(ge,{asChild:!0,children:e.jsx("button",{type:"button",className:"rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-2 text-[var(--ui-ink-soft)] transition hover:bg-[var(--ui-surface-2)] hover:text-[var(--ui-ink-strong)]","aria-label":"Close space picker",children:e.jsx(ce,{className:"size-4"})})})]}),e.jsx("div",{className:"mt-4 grid gap-2",children:u.map(l=>{const b=l.id===n,N=l.id===f;return e.jsxs("button",{type:"button",className:w("flex items-center justify-between gap-3 rounded-[22px] border px-4 py-3 text-left transition",b?"border-[color-mix(in_srgb,var(--primary)_26%,transparent)] bg-[var(--ui-accent-soft)] text-[var(--ui-ink-strong)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-medium)] hover:bg-[var(--ui-surface-2)] hover:text-[var(--ui-ink-strong)]"),onClick:()=>{d(l.id),i(!1)},children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-[14px] font-semibold text-inherit",children:l.label}),e.jsx("span",{className:"mt-1 block text-[12px] leading-5 text-[var(--ui-ink-soft)]",children:l.description||`/${l.slug}`}),N?e.jsx("span",{className:"mt-2 inline-flex rounded-full bg-amber-200/90 px-2 py-0.5 text-[10px] font-semibold uppercase tracking-[0.14em] text-stone-950",children:"Recovered pages"}):null]}),b?e.jsx(Le,{className:"size-4 shrink-0 text-[var(--primary)]"}):null]},l.id)})})]})]})})}function fs(){var H,G,Y,V,X,Z,ee,se,te,re;const a=Be(),i=Se(),u=Ue(),{slug:n}=Ee(),[d,f]=We(),[x,l]=c.useState(!1),[b,N]=c.useState(!1),[U,E]=c.useState(!1),[v,be]=c.useState("hybrid"),[W,ve]=c.useState(""),[P,M]=c.useState(""),Q=c.useRef(null),F=d.get("spaceId")??"",ke=d.get("ingest")==="1",J=d.get("ingestJobId"),p=K({queryKey:["forge-wiki-settings"],queryFn:Ge}),t=F||((G=(H=p.data)==null?void 0:H.settings.spaces[0])==null?void 0:G.id)||"",R=((Y=p.data)==null?void 0:Y.settings.embeddingProfiles.filter(s=>s.enabled))??[];c.useEffect(()=>{var s;!P&&((s=R[0])!=null&&s.id)&&M(R[0].id)},[R,P]),c.useEffect(()=>{var s,o;if(!F&&((o=(s=p.data)==null?void 0:s.settings.spaces[0])!=null&&o.id)){const g=new URLSearchParams(d);g.set("spaceId",p.data.settings.spaces[0].id),f(g,{replace:!0})}},[d,F,f,p.data]);const I=K({queryKey:["forge-wiki-home",t],queryFn:()=>Ye({spaceId:t||void 0}),enabled:!!t&&!n}),h=K({queryKey:["forge-wiki-page-by-slug",t,n],queryFn:()=>Ve({slug:n??"index",spaceId:t||void 0}),enabled:!!t&&!!n}),z=K({queryKey:["forge-wiki-tree",t],queryFn:()=>Xe({spaceId:t||void 0,kind:"wiki"}),enabled:!!t}),C=K({queryKey:["forge-wiki-modal-search",t,v,W,P],queryFn:()=>Ze({spaceId:t||void 0,mode:v,query:W.trim(),profileId:(v==="semantic"||v==="hybrid")&&P||void 0,limit:30}),enabled:x&&!!t&&W.trim().length>0}),$=n?h.data??null:I.data??null,[ye,je]=c.useState(null);c.useEffect(()=>{$&&je($)},[$]);const L=!!t&&(n?h.isFetching:I.isFetching),k=$??(L?ye:null),r=(k==null?void 0:k.page)??null,m=((V=p.data)==null?void 0:V.settings.spaces.find(s=>s.id===t))??null,y=((X=p.data)==null?void 0:X.settings.spaces.find(s=>s.visibility==="shared"))??null,we=!!y&&!!m&&(m==null?void 0:m.id)!==(y==null?void 0:y.id)&&(m==null?void 0:m.visibility)==="personal",q=(r==null?void 0:r.slug)!=="index",j=n&&h.error instanceof De&&h.error.status===404?n.trim():null;c.useEffect(()=>{if(!t||!j)return;const s=new URLSearchParams;s.set("spaceId",t),s.set("title",j);const o=as(j);o&&s.set("slug",o),i(`/wiki/new?${s.toString()}`,{replace:!0})},[t,j,i]);const _=c.useMemo(()=>((r==null?void 0:r.links)??[]).map(s=>({id:`${s.entityType}:${s.entityId}`,href:Oe(s.entityType,s.entityId),label:`${s.entityType} · ${s.entityId}`})),[r==null?void 0:r.links]),S=Fe({mutationFn:async s=>He(s),onSuccess:async()=>{await Promise.all([u.invalidateQueries({queryKey:["forge-wiki-tree"]}),u.invalidateQueries({queryKey:["forge-wiki-home"]}),u.invalidateQueries({queryKey:["forge-wiki-page-by-slug"]}),u.invalidateQueries({queryKey:["forge-wiki-modal-search"]})]),i(`/wiki${t?`?spaceId=${encodeURIComponent(t)}`:""}`)}}),B=(s,o=!1)=>{const g=new URLSearchParams(d);s(g),f(g,{replace:o})},A=s=>{B(o=>{o.set("ingest","1"),s?o.set("ingestJobId",s):o.delete("ingestJobId"),t&&o.set("spaceId",t)})},Ne=()=>{B(s=>{s.delete("ingest"),s.delete("ingestJobId")})},Ie=s=>{B(o=>{o.set("ingest","1"),s?o.set("ingestJobId",s):o.delete("ingestJobId"),t&&o.set("spaceId",t)})},Ce=()=>{!r||!q||S.isPending||!window.confirm(`Delete KarpaWiki page "${r.title}"? You can restore it later from the bin.`)||S.mutateAsync(r.id)};return c.useEffect(()=>{if(!U)return;const s=g=>{var ae;(ae=Q.current)!=null&&ae.contains(g.target)||E(!1)},o=g=>{g.key==="Escape"&&E(!1)};return document.addEventListener("pointerdown",s),document.addEventListener("keydown",o),()=>{document.removeEventListener("pointerdown",s),document.removeEventListener("keydown",o)}},[U]),!r&&(p.isLoading||z.isLoading||!n&&I.isLoading||n&&h.isLoading)?e.jsx(D,{eyebrow:"KarpaWiki",title:"Loading the article",description:"Preparing the current space, article, and KarpaWiki index."}):!r&&!j&&(p.isError||I.isError||h.isError||z.isError)?e.jsx(ne,{eyebrow:"KarpaWiki",error:p.error??I.error??h.error??z.error,onRetry:()=>{p.refetch(),I.refetch(),h.refetch(),z.refetch()}}):r?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"px-3 py-4 sm:px-5 lg:px-6",children:e.jsxs("div",{className:"mx-auto flex w-full max-w-[1680px] flex-col gap-4",children:[e.jsxs("section",{className:"wiki-frame px-3 py-3 sm:px-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(oe,{kind:"wiki_page",label:"KarpaWiki page",compact:!0,gradient:!1}),m?e.jsx(oe,{kind:"wiki_space",label:m.label,compact:!0,gradient:!1,wrap:!0,className:"max-w-[20rem]"}):null,e.jsx("span",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:rs(r.updatedAt)}),e.jsx(Qe,{metrics:a.snapshot.metrics,className:"ml-auto"})]}),e.jsxs("div",{className:"mt-3 flex flex-col gap-2 lg:flex-row lg:items-center",children:[e.jsxs("button",{type:"button",className:"wiki-search-launch flex min-h-[2.9rem] w-full items-center gap-3 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 text-left text-[14px] text-[var(--ui-ink-soft)] transition hover:bg-[var(--ui-surface-2)] hover:text-[var(--ui-ink-strong)] lg:flex-1",onClick:()=>l(!0),children:[e.jsx(Pe,{className:"size-4 shrink-0 text-[var(--ui-ink-faint)]"}),e.jsx("span",{children:"Search KarpaWiki"})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 lg:shrink-0",children:[e.jsxs("button",{type:"button",className:"wiki-space-trigger inline-flex min-h-[2.9rem] items-center gap-2 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 text-[13px] font-medium text-[var(--ui-ink-medium)] transition hover:bg-[var(--ui-surface-2)] hover:text-[var(--ui-ink-strong)]",onClick:()=>N(!0),children:[e.jsx("span",{className:"text-[11px] uppercase tracking-[0.14em] text-[var(--ui-ink-faint)]",children:"Space"}),e.jsx("span",{className:"max-w-[16rem] truncate",children:(m==null?void 0:m.label)??"KarpaWiki space"}),e.jsx(O,{className:"size-3.5 text-[var(--ui-ink-faint)]"})]}),e.jsxs("div",{className:"relative",ref:Q,children:[e.jsxs(T,{variant:"secondary",size:"sm",className:"min-h-[2.9rem]",onClick:()=>E(s=>!s),children:[e.jsx(ie,{className:"size-3.5"}),"Ingest",e.jsx(O,{className:"size-3.5"})]}),U?e.jsxs("div",{className:"absolute right-0 top-[calc(100%+0.5rem)] z-20 grid min-w-[15rem] gap-2 rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-popover)] p-2 shadow-[var(--ui-shadow-floating)]",children:[e.jsxs("button",{type:"button",className:"flex items-start gap-3 rounded-[18px] px-3 py-3 text-left transition hover:bg-[var(--ui-surface-2)]",onClick:()=>{E(!1),A()},children:[e.jsx(ie,{className:"mt-0.5 size-4 shrink-0 text-[var(--primary)]"}),e.jsxs("span",{children:[e.jsx("span",{className:"block text-sm font-medium text-[var(--ui-ink-strong)]",children:"New ingest"}),e.jsx("span",{className:"mt-1 block text-xs leading-5 text-[var(--ui-ink-faint)]",children:"Start a fresh import from files, URLs, or pasted text."})]})]}),e.jsxs("button",{type:"button",className:"flex items-start gap-3 rounded-[18px] px-3 py-3 text-left transition hover:bg-[var(--ui-surface-2)]",onClick:()=>{E(!1),i(`/wiki/ingest-history${t?`?spaceId=${encodeURIComponent(t)}`:""}`)},children:[e.jsx(Re,{className:"mt-0.5 size-4 shrink-0 text-[var(--secondary)]"}),e.jsxs("span",{children:[e.jsx("span",{className:"block text-sm font-medium text-[var(--ui-ink-strong)]",children:"History"}),e.jsx("span",{className:"mt-1 block text-xs leading-5 text-[var(--ui-ink-faint)]",children:"Browse prior ingests, reopen reviews, and delete old ingest records."})]})]})]}):null]}),e.jsxs(T,{variant:"secondary",size:"sm",className:"min-h-[2.9rem]",onClick:()=>i(`/wiki/edit/${encodeURIComponent(r.id)}?spaceId=${encodeURIComponent(t)}`,{state:{initialPage:r}}),children:[e.jsx(ze,{className:"size-3.5"}),"Edit"]}),e.jsx(es,{entityType:"note",entityId:r.id,label:"Open in graph",size:"sm"}),e.jsxs(T,{variant:"secondary",size:"sm",className:w("min-h-[2.9rem] border border-rose-400/18 bg-rose-500/10 text-rose-100 hover:bg-rose-500/18",!q&&"opacity-60"),onClick:Ce,pending:S.isPending,pendingLabel:"Deleting",disabled:!q,title:q?"Delete this KarpaWiki page":"The KarpaWiki home page cannot be deleted",children:[e.jsx(Ke,{className:"size-3.5"}),"Delete"]}),e.jsxs(T,{size:"sm",className:"min-h-[2.9rem]",onClick:()=>i(`/wiki/new?spaceId=${encodeURIComponent(t)}`),children:[e.jsx($e,{className:"size-3.5"}),"New page"]})]})]}),we&&y?e.jsxs("div",{className:"mt-3 flex flex-col gap-3 rounded-[22px] border border-amber-300/20 bg-amber-300/[0.08] px-4 py-3 text-[13px] leading-6 text-amber-50 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("span",{children:["You are viewing the personal starter wiki. The recovered people, story, and conversation pages are in"," ",e.jsx("strong",{children:y.label}),"."]}),e.jsx("button",{type:"button",className:"inline-flex min-h-10 shrink-0 items-center justify-center rounded-2xl bg-amber-200 px-4 text-[12px] font-semibold uppercase tracking-[0.14em] text-stone-950 transition hover:bg-amber-100",onClick:()=>{i({pathname:"/wiki",search:`?spaceId=${encodeURIComponent(y.id)}`})},children:"Open shared memory"})]}):null]}),e.jsxs("section",{className:"grid gap-4 lg:grid-cols-[15rem_minmax(0,1fr)] xl:grid-cols-[16rem_minmax(0,1fr)]",children:[e.jsxs("aside",{className:"wiki-frame h-fit px-2 py-3 sm:px-3 lg:sticky lg:top-[5.75rem]",children:[e.jsx("div",{className:"px-2 pb-2 text-[11px] font-semibold uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Index"}),e.jsx(he,{nodes:((Z=z.data)==null?void 0:Z.tree)??[],activeSlug:r.slug,spaceId:t})]}),e.jsxs("article",{"aria-busy":L,className:w("wiki-frame relative overflow-hidden px-4 py-5 transition-[opacity,transform] duration-200 sm:px-6 sm:py-6",L&&"opacity-[0.985]"),children:[L?e.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 h-px bg-[color-mix(in_srgb,var(--primary)_70%,transparent)] opacity-90"}):null,e.jsxs("div",{className:"wiki-reading-copy wiki-reading-flow mx-auto max-w-[76rem]",children:[S.isError?e.jsx("div",{className:"mb-4 rounded-[18px] border border-rose-400/20 bg-rose-500/10 px-4 py-3 text-sm text-rose-100",children:S.error instanceof Error?S.error.message:"Forge could not delete this KarpaWiki page."}):null,e.jsx(ss,{markdown:r.contentMarkdown,spaceId:t}),r.summary.trim()?e.jsx("p",{className:"mt-5 border-t border-[var(--ui-border-subtle)] pt-4 text-[13px] leading-6 text-[var(--ui-ink-soft)]",children:r.summary}):null,_.length>0?e.jsxs("section",{className:"mt-8 border-t border-[var(--ui-border-subtle)] pt-4",children:[e.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Forge links"}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:_.map(s=>e.jsx("a",{href:s.href?Je(s.href):void 0,className:"rounded-full bg-[var(--ui-surface-2)] px-3 py-1.5 text-[12px] text-[var(--ui-ink-medium)] transition hover:bg-[var(--ui-surface-3)] hover:text-[var(--ui-ink-strong)]",children:s.label},s.id))})]}):null,k!=null&&k.backlinkSourceNotes.length?e.jsxs("section",{className:"mt-8 border-t border-[var(--ui-border-subtle)] pt-4",children:[e.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Linked here"}),e.jsx("div",{className:"mt-3 grid gap-2 sm:grid-cols-2",children:k.backlinkSourceNotes.map(s=>e.jsxs(le,{to:{pathname:s.slug==="index"?"/wiki":`/wiki/page/${encodeURIComponent(s.slug)}`,search:`?spaceId=${encodeURIComponent(s.spaceId)}`},className:"rounded-xl border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-3 transition hover:bg-[var(--ui-surface-2)]",children:[e.jsx("div",{className:"text-[13px] font-semibold text-[var(--ui-ink-strong)]",children:s.title}),s.summary?e.jsx("div",{className:"mt-1 text-[12px] leading-5 text-[var(--ui-ink-soft)]",children:s.summary}):null]},s.id))})]}):null]})]})]})]})}),e.jsx(de,{open:x,onOpenChange:l,children:e.jsxs(ue,{children:[e.jsx(pe,{className:"fixed inset-0 z-50 surface-overlay backdrop-blur-sm"}),e.jsxs(me,{className:"fixed left-1/2 top-[8vh] z-50 w-[min(54rem,calc(100vw-1.5rem))] -translate-x-1/2 rounded-[28px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-popover)] p-4 shadow-[var(--ui-shadow-floating)] sm:p-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsx("div",{children:e.jsx(xe,{className:"font-display text-[1.35rem] tracking-[-0.04em] text-[var(--ui-ink-strong)]",children:"Search the wiki"})}),e.jsx(ge,{asChild:!0,children:e.jsx("button",{type:"button",className:"rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-2 text-[var(--ui-ink-soft)] transition hover:bg-[var(--ui-surface-2)] hover:text-[var(--ui-ink-strong)]","aria-label":"Close search",children:e.jsx(ce,{className:"size-4"})})})]}),e.jsxs("div",{className:"mt-4 grid gap-3",children:[e.jsx(_e,{autoFocus:!0,value:W,onChange:s=>ve(s.target.value),placeholder:"Search KarpaWiki pages",className:"h-11 rounded-2xl border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[14px] text-[var(--ui-ink-strong)] placeholder:text-[var(--ui-ink-faint)]"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[["text","hybrid","semantic","entity"].map(s=>e.jsx("button",{type:"button",className:w("rounded-full px-3 py-1.5 text-[12px] font-medium uppercase tracking-[0.14em] transition",v===s?"bg-[var(--ui-surface-3)] text-[var(--ui-ink-strong)]":"bg-[var(--ui-surface-1)] text-[var(--ui-ink-soft)] hover:bg-[var(--ui-surface-2)] hover:text-[var(--ui-ink-strong)]"),onClick:()=>be(s),children:s},s)),(v==="semantic"||v==="hybrid")&&R.length>0?e.jsx("select",{className:"ml-auto rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-3 py-1.5 text-[12px] text-[var(--ui-ink-strong)]",value:P,onChange:s=>M(s.target.value),children:R.map(s=>e.jsx("option",{value:s.id,children:s.label},s.id))}):null]})]}),e.jsx("div",{className:"mt-4 max-h-[60vh] overflow-y-auto",children:W.trim()?C.isLoading?e.jsx(D,{eyebrow:"KarpaWiki search",title:"Searching",description:"Ranking matching pages for this query."}):C.isError?e.jsx(ne,{eyebrow:"KarpaWiki search",error:C.error,onRetry:()=>void C.refetch()}):(ee=C.data)!=null&&ee.results.length?e.jsx("div",{className:"grid gap-2",children:C.data.results.map(s=>e.jsx("button",{type:"button",className:"rounded-2xl border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-3 text-left transition hover:bg-[var(--ui-surface-2)]",onClick:()=>{l(!1),i({pathname:s.page.slug==="index"?"/wiki":`/wiki/page/${encodeURIComponent(s.page.slug)}`,search:`?spaceId=${encodeURIComponent(s.page.spaceId)}`})},children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[14px] font-semibold text-[var(--ui-ink-strong)]",children:s.page.title}),s.page.summary?e.jsx("div",{className:"mt-1 text-[12px] leading-5 text-[var(--ui-ink-soft)]",children:s.page.summary}):null]}),e.jsx(Ae,{size:"sm",tone:"meta",children:s.score.toFixed(2)})]})},s.page.id))}):e.jsx("div",{className:"rounded-2xl border border-dashed border-[var(--ui-border-subtle)] px-4 py-10 text-center text-[13px] leading-6 text-[var(--ui-ink-faint)]",children:"No pages matched this search."}):e.jsx("div",{className:"rounded-2xl border border-dashed border-[var(--ui-border-subtle)] px-4 py-10 text-center text-[13px] leading-6 text-[var(--ui-ink-faint)]",children:"Start typing to search the current KarpaWiki space."})})]})]})}),e.jsx(ns,{open:b,onOpenChange:N,spaces:((se=p.data)==null?void 0:se.settings.spaces)??[],activeSpaceId:t,onSelect:s=>{i({pathname:"/wiki",search:`?spaceId=${encodeURIComponent(s)}`},{replace:!0})}}),e.jsx(ts,{open:ke,onOpenChange:s=>{if(s){A(J);return}Ne()},spaces:((te=p.data)==null?void 0:te.settings.spaces)??[],llmProfiles:((re=p.data)==null?void 0:re.settings.llmProfiles)??[],initialSpaceId:t,selectedJobId:J,onJobSelected:Ie,linkedEntityHints:r.links.map(s=>({entityType:s.entityType,entityId:s.entityId,anchorKey:null}))??[]})]}):j?e.jsx(D,{eyebrow:"KarpaWiki",title:"Opening a new page",description:`Creating a draft for ${j}.`}):e.jsx(Me,{eyebrow:"KarpaWiki",title:"Article not found",description:"This page does not exist in the selected space."})}export{fs as WikiPage};
@@ -0,0 +1,5 @@
1
+ import{j as e,r as g,dJ as aa,dK as ra,dG as sa,dL as na,dM as ia,dN as oa,aG as la,dO as ca,cl as $a,c1 as Ue,cm as da,b9 as Ge,b2 as za,aC as Va,cL as Da,c4 as Ua,cg as Ga,dP as Qa,c6 as Ja,b6 as Ya}from"./vendor-Cpmju3nw.js";import{O as Xa}from"./open-in-graph-button-L21MKsb5.js";import{P as Za}from"./page-hero-DlHEJ0Yt.js";import{T as er,M as tr,S as ar,W as rr,Q as sr}from"./utility-widgets-DvxKA6dI.js";import{a as _,n as xe,q as ua,j as R,c as O,e as M,d as L,g as A,b as H,f as q,r as nr,s as ir,h as ma,k as or,t as lr,u as cr,v as _e,W as dr,w as Dt}from"./generic-node-view-COhU_Wm3.js";import{d as K}from"./define-workbench-box-DkffygDU.js";import{K as ur,a as mr,b as pr}from"./kanban-boxes-CH7plRk1.js";import{S as hr,a as gr,b as xr,c as br,d as fr,e as vr}from"./health-boxes-BUcsxDLh.js";import{M as yr,a as kr,b as wr,c as jr,d as Nr}from"./movement-boxes-BH3botKt.js";import{N as Sr,a as Cr,b as _r}from"./notes-boxes-CPiPps1e.js";import{P as Tr,a as Ir,b as Pr}from"./projects-boxes-AyudWls3.js";import{T as Fr,a as Br,b as Rr,c as Wr,d as Er}from"./today-boxes-CiccN0Gw.js";import{H as Or,P as Ut,i as Kr,B as Mr,a as Lr,b as Ar,c as Hr}from"./graph-Cd5WF3lw.js";import{F as C,Q as qr}from"./question-flow-dialog-BByFV8Yw.js";import{W as pa,c as E,a4 as te,B,aC as $r,eG as zr,eH as Vr,b as Gt,eD as Dr,eI as Ur,eJ as Gr,eK as Qr,eL as Jr,eM as Yr,eN as Xr,L as Zr,h as es,e as ts}from"./index-BejvcRGb.js";import{R as as,P as rs,O as ss,C as ns,T as is,D as os,a as ls}from"./ui-B9O-eUim.js";import{F as cs}from"./faceted-token-search-D4Okr-Kr.js";import"./state-BtwEvpO6.js";import"./motion-DwjmC9aq.js";import"./board-CLOHbg6t.js";import"./forms-C5d5hTf2.js";function ds({children:t}){return e.jsx(e.Fragment,{children:t})}function ha(t,n,r,i,c,d){return K(ds,{id:t,surfaceId:"insights",routePath:"/insights",title:n,icon:"insights",description:r,category:"Insights",tags:i,inputs:[],params:[],output:d,tools:[],NodeView:O({title:n,description:r,inputs:[],params:[],output:d,tools:[]}),execute:c})}const us=ha("surface:insights:feed","Insights feed","Current coaching feed, status summary, and evidence-backed insight stream.",["insights","feed"],t=>ua(t),[_({label:"Insight summary",description:"Summary of the current coaching feed and evidence-backed insight stream."}),xe({key:"insights",label:"Insight payload",description:"Structured status and coaching payload returned by Forge insights.",modelName:"ForgeInsightsPayload"})]),ms=ha("surface:insights:coaching","Coaching recommendation","Single-action coaching summary for what Forge thinks matters next.",["insights","coaching"],t=>R(t,{focus:"coaching_recommendation"},"Coaching recommendation surface for the highest-leverage next move."),[_({label:"Coaching recommendation",description:"Summary of the highest-leverage coaching recommendation."})]);function ps({children:t}){return e.jsx(e.Fragment,{children:t})}function et(t,n,r,i,c,d,u,s){const o=(s==null?void 0:s.inputs)??[],m=(s==null?void 0:s.params)??[];return K(ps,{id:t,surfaceId:"calendar",routePath:"/calendar",title:n,icon:"calendar",description:r,category:"Calendar",tags:i,inputs:o,params:m,output:d,tools:u,NodeView:O({title:n,description:r,inputs:o,params:m,output:d,tools:u}),execute:c})}const hs=et("surface:calendar:overview","Calendar overview","Main calendar surface for mirrored events, work blocks, and planned timeboxes.",["calendar","overview"],t=>R(t,{surfaces:["events","work_blocks","timeboxes"]},"Calendar overview spanning mirrored events, work blocks, and timeboxes."),[_({label:"Calendar summary",description:"Summary of mirrored events, work blocks, and timeboxes."})],[]),gs=et("surface:calendar:events","Calendar events","Mirrored calendar events and Forge-managed calendar records.",["calendar","events","mirrored"],t=>q(t,{query:"",entityTypes:["calendar_event"],limit:20}),H({itemKind:"calendar_event",itemLabel:"Calendar event"}),[A("Search calendar-backed Forge entities and planning records.")],{inputs:L({itemKind:"calendar_event",itemLabel:"Calendar event",defaultEntityTypes:["calendar_event"],defaultLimit:20}),params:M()}),xs=et("surface:calendar:planning","Planning blocks","Planned task timeboxes and reusable work block templates.",["calendar","planning","timeboxes"],t=>q(t,{query:"",entityTypes:["task_timebox","work_block_template"],limit:20}),H({itemKind:"calendar_plan",itemLabel:"Planning record"}),[A("Search calendar-backed Forge entities and planning records.")],{inputs:L({itemKind:"calendar_plan",itemLabel:"Planning record",defaultEntityTypes:["task_timebox","work_block_template"],defaultLimit:20}),params:M()});function bs({children:t}){return e.jsx(e.Fragment,{children:t})}function tt(t,n,r,i,c,d,u=[],s){const o=(s==null?void 0:s.inputs)??[],m=(s==null?void 0:s.params)??[];return K(bs,{id:t,surfaceId:"goals",routePath:"/goals",title:n,icon:"goal",description:r,category:"Goals",tags:i,inputs:o,params:m,output:d,tools:u,NodeView:O({title:n,description:r,inputs:o,params:m,output:d,tools:u}),execute:c})}const fs=tt("surface:goals:hero","Goals hero","Goals page header and long-horizon direction context.",["goals","hero"],t=>R(t,null,"Goals page header."),[_({label:"Goals summary",description:"High-level goals page framing."})]),vs=tt("surface:goals:search-results","Goals list and results","Goal browser, linked context, and search results.",["goals","search"],t=>q(t,{query:"",entityTypes:["goal"],limit:20}),H({itemKind:"goal",itemLabel:"Goal"}),[A("Search goal entities by query and entity types.")],{inputs:L({itemKind:"goal",itemLabel:"Goal",defaultEntityTypes:["goal"],defaultLimit:20}),params:M()}),ys=tt("surface:goals:summary","Goals summary","Goal collection summary and state context.",["goals","summary"],t=>R(t,null,"Goal collection summary."),[_({label:"Goals summary",description:"Summary of the goal collection and its current state."})]);function ks({children:t}){return e.jsx(e.Fragment,{children:t})}function at(t,n,r,i,c,d,u=[],s){const o=(s==null?void 0:s.inputs)??[],m=(s==null?void 0:s.params)??[];return K(ks,{id:t,surfaceId:"habits",routePath:"/habits",title:n,icon:"habit",description:r,category:"Habits",tags:i,inputs:o,params:m,output:d,tools:u,NodeView:O({title:n,description:r,inputs:o,params:m,output:d,tools:u}),execute:c})}const ws=at("surface:habits:hero","Habits hero","Habits page header and recurring execution context.",["habits","hero"],t=>R(t,null,"Habits page header."),[_({label:"Habits summary",description:"High-level habits page framing."})]),js=at("surface:habits:search-results","Habits list and results","Habit browser, due habits, and recurring check-in context.",["habits","search","check-ins"],t=>q(t,{query:"",entityTypes:["habit"],limit:20}),H({itemKind:"habit",itemLabel:"Habit"}),[A("Search habit entities by query and entity types.")],{inputs:L({itemKind:"habit",itemLabel:"Habit",defaultEntityTypes:["habit"],defaultLimit:20}),params:M()}),Ns=at("surface:habits:summary","Habits summary","Habit streaks, due state, and collection-level rhythm context.",["habits","summary","streaks"],t=>R(t,null,"Habit collection summary."),[_({label:"Habit summary",description:"Summary of habit streaks, due state, and collection rhythm."})]);function Ss({children:t}){return e.jsx(e.Fragment,{children:t})}function rt(t,n,r,i,c,d){return K(Ss,{id:t,surfaceId:"overview",routePath:"/overview",title:n,icon:"overview",description:r,category:"Overview",tags:i,inputs:[],params:[],output:d,tools:[],NodeView:O({title:n,description:r,inputs:[],params:[],output:d,tools:[]}),execute:c})}const Cs=rt("surface:overview:snapshot","Forge snapshot","Live overview of goals, projects, tasks, habits, and current operating pressure.",["overview","snapshot"],t=>nr(t),[_({label:"Overview summary",description:"Compact summary of goals, projects, tasks, and habits."}),xe({key:"context",label:"Overview context",description:"Structured Forge overview context for the current operating picture.",modelName:"ForgeOverviewContext"})]),_s=rt("surface:overview:momentum","Momentum and health","Momentum-focused summary of streaks, neglected areas, and active execution pressure.",["overview","momentum"],t=>R(t,{dimensions:["momentum","neglected_goals","domain_balance"]},"Overview momentum surface tracking neglected goals, domain balance, and execution pressure."),[_({label:"Momentum summary",description:"Summary of momentum, neglected goals, and execution pressure."})]),Ts=rt("surface:overview:insights","Overview insights","Insight-oriented summary of the current Forge operating picture.",["overview","insights"],t=>ua(t),[_({label:"Insight summary",description:"Compact explanation of the current insight payload."}),xe({key:"insights",label:"Insight payload",description:"Structured insight and coaching payload returned by Forge.",modelName:"ForgeInsightsPayload"})]);function Is({children:t}){return e.jsx(e.Fragment,{children:t})}function st(t,n,r,i,c,d,u=[],s){const o=(s==null?void 0:s.inputs)??[],m=(s==null?void 0:s.params)??[];return K(Is,{id:t,surfaceId:"preferences",routePath:"/preferences",title:n,icon:"preferences",description:r,category:"Preferences",tags:i,inputs:o,params:m,output:d,tools:u,NodeView:O({title:n,description:r,inputs:o,params:m,output:d,tools:u}),execute:c})}const Ps=st("surface:preferences:workspace","Preferences workspace","Main preference modeling workspace, including summaries, tradeoffs, and evidence.",["preferences","workspace"],t=>R(t,{surfaces:["summary","comparison_game","evidence"]},"Preferences workspace with summary, pairwise comparison, and evidence views."),[_({label:"Preference summary",description:"Summary of the active preference modeling workspace."})]),Fs=st("surface:preferences:contexts","Preference contexts","Preference contexts that shape which tradeoffs and evidence are active.",["preferences","contexts"],t=>q(t,{query:"",entityTypes:["preference_context"],limit:20}),H({itemKind:"preference_context",itemLabel:"Preference context"}),[A("Search preference contexts and modeled preference items.")],{inputs:L({itemKind:"preference_context",itemLabel:"Preference context",defaultEntityTypes:["preference_context"],defaultLimit:20}),params:M()}),Bs=st("surface:preferences:items","Preference items","Preference items scored and compared inside the active context.",["preferences","items"],t=>q(t,{query:"",entityTypes:["preference_item"],limit:20}),H({itemKind:"preference_item",itemLabel:"Preference item"}),[A("Search preference contexts and modeled preference items.")],{inputs:L({itemKind:"preference_item",itemLabel:"Preference item",defaultEntityTypes:["preference_item"],defaultLimit:20}),params:M()});function Rs({children:t}){return e.jsx(e.Fragment,{children:t})}function nt(t,n,r,i,c,d,u=[],s){const o=(s==null?void 0:s.inputs)??[],m=(s==null?void 0:s.params)??[];return K(Rs,{id:t,surfaceId:"psyche",routePath:"/psyche",title:n,icon:"psyche",description:r,category:"Psyche",tags:i,inputs:o,params:m,output:d,tools:u,NodeView:O({title:n,description:r,inputs:o,params:m,output:d,tools:u}),execute:c})}const Ws=nt("surface:psyche:overview","Psyche overview","High-level overview of values, patterns, beliefs, modes, and reports.",["psyche","overview"],t=>R(t,{surfaces:["values","patterns","beliefs","modes","reports"]},"Psyche overview spanning values, patterns, beliefs, modes, and reports."),[_({label:"Psyche summary",description:"Summary of values, patterns, beliefs, modes, and reports."})]),Es=nt("surface:psyche:values","Psyche values","Values and long-lived internal directions tracked inside Forge.",["psyche","values"],t=>q(t,{query:"",entityTypes:["psyche_value"],limit:20}),H({itemKind:"psyche_value",itemLabel:"Psyche value"}),[A("Search psyche entities and reflective records.")],{inputs:L({itemKind:"psyche_value",itemLabel:"Psyche value",defaultEntityTypes:["psyche_value"],defaultLimit:20}),params:M()}),Os=nt("surface:psyche:reports","Trigger reports","Trigger reports and behavior-pattern signals linked to reflective work.",["psyche","reports","patterns"],t=>q(t,{query:"",entityTypes:["trigger_report","behavior_pattern","belief_entry","mode_profile"],limit:20}),H({itemKind:"psyche_record",itemLabel:"Psyche record"}),[A("Search psyche entities and reflective records.")],{inputs:L({itemKind:"psyche_record",itemLabel:"Psyche record",defaultEntityTypes:["trigger_report","behavior_pattern","belief_entry","mode_profile"],defaultLimit:20}),params:M()});function Ks({children:t}){return e.jsx(e.Fragment,{children:t})}function it(t,n,r,i,c,d,u=[],s){const o=(s==null?void 0:s.inputs)??[],m=(s==null?void 0:s.params)??[];return K(Ks,{id:t,surfaceId:"questionnaires",routePath:"/psyche/questionnaires",title:n,icon:"questionnaire",description:r,category:"Questionnaires",tags:i,inputs:o,params:m,output:d,tools:u,NodeView:O({title:n,description:r,inputs:o,params:m,output:d,tools:u}),execute:c})}const Ms=it("surface:questionnaires:library","Questionnaire library","Library of questionnaire instruments available in Forge.",["questionnaires","library"],t=>q(t,{query:"",entityTypes:["questionnaire_instrument"],limit:20}),H({itemKind:"questionnaire_instrument",itemLabel:"Questionnaire"}),[A("Search questionnaire instruments and related records.")],{inputs:L({itemKind:"questionnaire_instrument",itemLabel:"Questionnaire",defaultEntityTypes:["questionnaire_instrument"],defaultLimit:20}),params:M()}),Ls=it("surface:questionnaires:drafting","Questionnaire drafting","Drafting and publishing context for questionnaire instruments.",["questionnaires","drafting","authoring"],t=>R(t,{states:["draft","published","run"]},"Questionnaire drafting surface with draft, publish, and run lifecycle context."),[_({label:"Drafting summary",description:"Summary of questionnaire drafting and lifecycle context."})]),As=it("surface:questionnaires:self-observation","Self-observation calendar","Calendar of self-observation notes and linked psyche context.",["questionnaires","self-observation","psyche"],t=>R(t,{linkedDomains:["patterns","reports","notes"]},"Self-observation calendar surface with linked psyche context."),[_({label:"Observation summary",description:"Summary of the self-observation calendar and linked psyche context."})]);function Hs({children:t}){return e.jsx(e.Fragment,{children:t})}function ga(t,n,r,i,c,d){return K(Hs,{id:t,surfaceId:"review",routePath:"/review/weekly",title:n,icon:"review",description:r,category:"Review",tags:i,inputs:[],params:[],output:d,tools:[],NodeView:O({title:n,description:r,inputs:[],params:[],output:d,tools:[]}),execute:c})}const qs=ga("surface:review:weekly-summary","Weekly review summary","Weekly review payload with momentum, wins, calibration, and completion state.",["review","weekly"],t=>ir(t),[_({label:"Weekly review summary",description:"Summary of momentum, wins, calibration, and review completion state."}),xe({key:"weeklyReview",label:"Weekly review payload",description:"Structured weekly review payload returned by Forge.",modelName:"ForgeWeeklyReview"})]),$s=ga("surface:review:reward","Review reward","Reward framing and completion incentive for closing the current review cycle.",["review","reward"],t=>R(t,{reward:"weekly_review_completion"},"Weekly review reward surface for locking the current cycle into evidence."),[_({label:"Review reward summary",description:"Summary of the reward framing for closing the current review cycle."})]);function zs({children:t}){return e.jsx(e.Fragment,{children:t})}function ot(t,n,r,i,c,d,u=[],s){const o=(s==null?void 0:s.inputs)??[],m=(s==null?void 0:s.params)??[];return K(zs,{id:t,surfaceId:"strategies",routePath:"/strategies",title:n,icon:"strategy",description:r,category:"Strategies",tags:i,inputs:o,params:m,output:d,tools:u,NodeView:O({title:n,description:r,inputs:o,params:m,output:d,tools:u}),execute:c})}const Vs=ot("surface:strategies:hero","Strategies hero","Strategies page header and sequencing context.",["strategies","hero"],t=>R(t,null,"Strategies page header."),[_({label:"Strategies summary",description:"High-level strategies page framing."})]),Ds=ot("surface:strategies:search-results","Strategies list and results","Strategy browser and structured operating context.",["strategies","search"],t=>q(t,{query:"",entityTypes:["strategy"],limit:20}),H({itemKind:"strategy",itemLabel:"Strategy"}),[A("Search strategy entities by query and entity types.")],{inputs:L({itemKind:"strategy",itemLabel:"Strategy",defaultEntityTypes:["strategy"],defaultLimit:20}),params:M()}),Us=ot("surface:strategies:summary","Strategies summary","Strategy collection summary and state context.",["strategies","summary"],t=>R(t,null,"Strategy collection summary."),[_({label:"Strategy summary",description:"Summary of strategy state and collection context."})]);function Gs({children:t}){return e.jsx(e.Fragment,{children:t})}function lt(t,n,r,i,c,d,u=[],s){const o=(s==null?void 0:s.inputs)??[],m=(s==null?void 0:s.params)??[];return K(Gs,{id:t,surfaceId:"tasks",routePath:"/today",title:n,icon:"task",description:r,category:"Tasks",tags:i,inputs:o,params:m,output:d,tools:u,NodeView:O({title:n,description:r,inputs:o,params:m,output:d,tools:u}),execute:c})}const Qs=lt("surface:tasks:inbox","Task queue","Searchable task queue spanning backlog, focus, and in-progress work.",["tasks","queue","search"],t=>q(t,{query:"",entityTypes:["task"],limit:20}),H({itemKind:"task",itemLabel:"Task"}),[A("Search task entities by title, status, or linked context."),ma("Move a task between backlog, focus, in progress, blocked, and done.")],{inputs:L({itemKind:"task",itemLabel:"Task",defaultEntityTypes:["task"],defaultLimit:20}),params:M()}),Js=lt("surface:tasks:focus-lane","Focus lane","Focused task lane for what should happen next right now.",["tasks","focus","execution"],t=>R(t,{hint:"Use this surface to represent active or next-up work."},"Focus lane context for the current execution board."),[_({label:"Focus summary",description:"Human-readable explanation of what the focus lane represents."})],[ma("Change task state as the flow decides what should happen next.")]),Ys=lt("surface:tasks:summary","Task summary","High-level summary of the current task system and work state.",["tasks","summary"],t=>R(t,{states:["backlog","focus","in_progress","blocked","done"]},"Task system summary with the key task states Forge tracks."),[_({label:"Task summary",description:"High-level summary of the current task system and work state."})]);function Xs({children:t}){return e.jsx(e.Fragment,{children:t})}function ct(t,n,r,i,c,d){return K(Xs,{id:t,surfaceId:"wiki",routePath:"/wiki",title:n,icon:"wiki",description:r,category:"Wiki",tags:i,inputs:[],params:[],output:d,tools:[],NodeView:O({title:n,description:r,inputs:[],params:[],output:d,tools:[]}),execute:c})}const Zs=ct("surface:wiki:pages","Wiki pages","Live list of wiki pages that can be used as memory or authored knowledge.",["wiki","pages"],t=>lr(t),[_({label:"Wiki page summary",description:"Summary of the currently available wiki pages."}),or({key:"pages",label:"Wiki pages",description:"Structured wiki page records available in Forge memory.",modelName:"ForgeWikiPages",itemKind:"wiki_page"})]),en=ct("surface:wiki:health","Wiki health","Index health, unresolved links, and orphaned-page signals for the wiki.",["wiki","health"],t=>cr(t),[_({label:"Wiki health summary",description:"Summary of unresolved links and orphaned-page signals."}),xe({key:"health",label:"Wiki health",description:"Structured wiki health payload returned by Forge.",modelName:"ForgeWikiHealth"})]),tn=ct("surface:wiki:authoring","Wiki authoring","Authoring and ingest surface for creating or refining Forge memory.",["wiki","authoring","ingest"],t=>R(t,{actions:["upsert","ingest","reindex"]},"Wiki authoring surface for ingesting sources and maintaining memory pages."),[_({label:"Wiki authoring summary",description:"Summary of wiki authoring and ingest actions available on this surface."})]),an=[er,tr,ar,rr,sr,hs,gs,xs,fs,vs,ys,ws,js,Ns,us,ms,ur,mr,pr,Sr,Cr,_r,Cs,_s,Ts,yr,kr,wr,jr,Nr,hr,gr,xr,br,fr,vr,Tr,Ir,Pr,Ps,Fs,Bs,Ws,Es,Os,Ms,Ls,As,qs,$s,Vs,Ds,Us,Qs,Js,Ys,Fr,Br,Rr,Wr,Er,Zs,en,tn],xa=new Map(an.filter(t=>t.workbench).map(t=>[t.workbench.id,t.workbench]));function ba(){return Array.from(xa.values())}function rn(t){return xa.get(t)??null}function sn(){return ba().map(t=>({id:t.id,boxId:t.id,surfaceId:t.surfaceId,routePath:t.routePath,title:t.title,label:t.title,icon:t.icon??null,description:t.description,category:t.category,tags:t.tags,capabilityModes:["content",...t.tools.length>0?["tool"]:[]],inputs:_e(t.inputs),params:_e(t.params),output:_e(t.output),tools:t.tools,outputs:_e(t.output),toolAdapters:t.tools,snapshotResolverKey:void 0}))}const nn=g.createContext(null),on={definitions:ba(),catalog:sn(),getDefinition:rn};function fa(){return g.useContext(nn)??on}function ln(){return fa().catalog}function cn(t){const n=fa();return t?n.getDefinition(t):null}const Qe=[...dr];function Pe(t){return typeof t=="string"?t:typeof t=="number"||typeof t=="boolean"?String(t):Array.isArray(t)||t&&typeof t=="object"?JSON.stringify(t,null,2):""}function va(t,n){if(t==="array"||t==="entity_list"||t==="record_list"||t==="object"||t==="json"||t==="record"||t==="context"||t==="filters"||t==="metrics"||t==="timeline"||t==="selection"||t==="entity"){if(!n.trim())return"";try{return JSON.parse(n)}catch{return n}}if(t==="boolean")return n.trim()?n.trim().toLowerCase()==="true"?!0:n.trim().toLowerCase()==="false"?!1:n:"";if(t==="number"){const r=n.trim();if(!r)return"";const i=Number(r);return Number.isFinite(i)?i:n}return n}function dn(t,n){if(n==null||typeof n=="string"&&n.trim().length===0)return!t.required;switch(t.kind){case"text":case"markdown":case"summary":return typeof n=="string";case"number":return typeof n=="number"&&Number.isFinite(n);case"boolean":return typeof n=="boolean";case"array":case"entity_list":case"record_list":return Array.isArray(n);case"object":case"json":case"record":case"context":case"filters":case"metrics":case"timeline":case"selection":case"entity":return!!n&&typeof n=="object";default:return!0}}function ya(t){switch(t){case"box":case"box_input":return{inputs:[],outputs:[{key:"summary",label:"Summary",kind:"summary",description:"Human-readable summary of the box snapshot.",modelName:"WorkbenchBoxSummary"}]};case"user_input":return{inputs:[],outputs:[{key:"message",label:"Message",kind:"text",description:"Raw user message passed into the flow.",modelName:"WorkbenchUserMessage"},{key:"context",label:"Structured context",kind:"context",description:"Structured context fields that arrived with the user input.",modelName:"WorkbenchUserContext"}]};case"value":return{inputs:[],outputs:[{key:"value",label:"Value",kind:"record",description:"Literal value emitted by this node.",modelName:"WorkbenchLiteralValue"}]};case"functor":case"chat":return{inputs:[{key:"input",label:"Flow input",kind:"context",required:!1,description:"Context gathered from upstream nodes."}],outputs:[{key:"answer",label:"Answer",kind:"markdown",description:"Primary answer returned by this AI node.",modelName:"WorkbenchAiAnswer"}]};case"merge":return{inputs:[{key:"left",label:"Left input",kind:"context",required:!1,description:"First context record to merge."},{key:"right",label:"Right input",kind:"context",required:!1,description:"Second context record to merge."}],outputs:[{key:"merged",label:"Merged context",kind:"context",description:"Combined context assembled from upstream nodes.",modelName:"WorkbenchMergedContext"}]};case"template":return{inputs:[{key:"input",label:"Template input",kind:"context",required:!1,description:"Structured context available to the template."}],outputs:[{key:"rendered",label:"Rendered output",kind:"markdown",description:"Rendered text produced by the template node.",modelName:"WorkbenchTemplateOutput"}]};case"pick_key":return{inputs:[{key:"object",label:"Source object",kind:"object",required:!1,description:"Object record the node should read from."}],outputs:[{key:"selected",label:"Selected value",kind:"record",description:"Value extracted from the chosen key.",modelName:"WorkbenchSelectedValue"}]};case"output":return{inputs:[{key:"result",label:"Published result",kind:"context",required:!1,description:"Final value the flow should publish."}],outputs:[]}}}function ka(t,n){var c,d,u,s;const r=(o,m)=>o.map(h=>{const f=Dt(h),k=f.key==="primary"?m==="output"?t.type==="functor"||t.type==="chat"?"answer":t.type==="box"||t.type==="box_input"?"summary":t.type==="value"?"value":t.type==="merge"?"merged":t.type==="template"?"rendered":t.type==="pick_key"?"selected":"result":t.type==="functor"||t.type==="chat"?"input":t.type==="output"?"result":f.key:f.key;return Dt({...f,key:k,kind:k===f.key?f.kind:void 0})});if(t.type==="box"||t.type==="box_input"){const o=n.find(m=>m.id===t.data.boxId);return{inputs:r((o==null?void 0:o.inputs)??[],"input"),outputs:(c=o==null?void 0:o.output)!=null&&c.length?r(o.output,"output"):r([{key:"summary",label:"Summary",kind:"summary",description:"Human-readable summary of the box snapshot.",modelName:"WorkbenchBoxSummary"}],"output"),enabledToolKeys:(d=t.data.enabledToolKeys)!=null&&d.length?t.data.enabledToolKeys:((o==null?void 0:o.tools)??[]).map(m=>m.key),boxId:(o==null?void 0:o.id)??t.data.boxId??null}}const i=ya(t.type);return{inputs:r((u=t.data.inputs)!=null&&u.length?t.data.inputs:i.inputs,"input"),outputs:r((s=t.data.outputs)!=null&&s.length?t.data.outputs:i.outputs,"output"),enabledToolKeys:t.data.enabledToolKeys??[],boxId:t.data.boxId??null}}function un(t,n){var i,c,d;const r=(i=t.data.outputKey)==null?void 0:i.trim();return!r||r==="primary"?((c=n[0])==null?void 0:c.key)??"":n.some(u=>u.key===r)?r:((d=n[0])==null?void 0:d.key)??r}function Qt(t,n,r){var i,c;return n.length===0?null:!t||t==="primary"?r&&n.some(d=>d.key===r)?r:((i=n[0])==null?void 0:i.key)??null:n.some(d=>d.key===t)?t:r&&n.some(d=>d.key===r)?r:((c=n[0])==null?void 0:c.key)??null}function De(t,n){const r=t.graph.nodes.map(d=>{const u=ka(d,n),s={...d,data:{...d.data,inputs:u.inputs,outputs:u.outputs,outputKey:un(d,u.outputs)}};return Je(s,n)}),i=new Map(r.map(d=>[d.id,d])),c=t.graph.edges.map(d=>{var h,f,k,v;const u=i.get(d.source),s=i.get(d.target),o=Qt(d.sourceHandle,(u==null?void 0:u.data.outputs)??[],(f=(h=u==null?void 0:u.data.outputs)==null?void 0:h[0])==null?void 0:f.key),m=Qt(d.targetHandle,(s==null?void 0:s.data.inputs)??[],(v=(k=s==null?void 0:s.data.inputs)==null?void 0:k[0])==null?void 0:v.key);return wa({...d,sourceHandle:o,targetHandle:m})});return{nodes:r,edges:c}}function Je(t,n){const r=ka(t,n);return{id:t.id,type:"workbench",position:t.position,data:{...t.data,nodeType:t.type==="box_input"?"box":t.type,boxId:r.boxId,enabledToolKeys:r.enabledToolKeys,inputs:r.inputs,outputs:r.outputs,params:t.data.params??[],paramValues:t.data.paramValues??{}}}}function wa(t){return{id:t.id,source:t.source,target:t.target,sourceHandle:t.sourceHandle??void 0,targetHandle:t.targetHandle??void 0,label:t.label??void 0,style:{stroke:"color-mix(in srgb, var(--primary) 44%, transparent)",strokeWidth:1.6}}}function ja(t){return{id:t.id,type:t.data.nodeType==="box"?"box":t.data.nodeType,position:t.position,data:{label:t.data.label,description:t.data.description,boxId:t.data.boxId??null,prompt:t.data.prompt??"",promptTemplate:t.data.promptTemplate??"",systemPrompt:t.data.systemPrompt??"",outputKey:t.data.outputKey??"",enabledToolKeys:t.data.enabledToolKeys??[],inputs:t.data.inputs??[],outputs:t.data.outputs??[],params:t.data.params??[],paramValues:t.data.paramValues??{},template:t.data.template??"",selectedKey:t.data.selectedKey??"",valueType:t.data.valueType??"string",valueLiteral:t.data.valueLiteral??"",modelConfig:t.data.modelConfig}}}function mn(t){return{id:t.id,source:t.source,target:t.target,sourceHandle:t.sourceHandle??null,targetHandle:t.targetHandle??null,label:typeof t.label=="string"?t.label:null}}function Jt(t,n,r){var c;const i=ya(t);return{id:`node_${crypto.randomUUID().replaceAll("-","").slice(0,8)}`,type:"workbench",position:{x:120+n.length%3*320,y:80+Math.floor(n.length/3)*220},data:{nodeType:t,label:(r==null?void 0:r.title)??(t==="functor"?"Functor":t==="chat"?"Chat node":t==="output"?"Output":t==="value"?"Value":t==="template"?"Template":t==="pick_key"?"Pick key":t==="merge"?"Merge":"User input"),description:(r==null?void 0:r.description)??(t==="box"?"Registered Forge box.":t==="chat"?"Conversational flow node.":t==="functor"?"Single transformation node.":"Workbench node."),boxId:(r==null?void 0:r.id)??null,enabledToolKeys:((r==null?void 0:r.tools)??[]).map(d=>d.key),inputs:(r==null?void 0:r.inputs)??i.inputs,outputs:(r==null?void 0:r.output)??i.outputs,params:(r==null?void 0:r.params)??[],paramValues:{},prompt:"",promptTemplate:"",systemPrompt:"",template:"",selectedKey:"",valueType:"string",valueLiteral:"",outputKey:((c=((r==null?void 0:r.output)??i.outputs)[0])==null?void 0:c.key)??"summary",modelConfig:{connectionId:null,provider:null,baseUrl:null,model:"",thinking:null,verbosity:null}}}}function pn(t){return[t.kind,t.modelName,t.itemKind?`item:${t.itemKind}`:null].filter(Boolean).join(" · ")}function hn(t,n){switch(t){case"dirty":return"Unsaved changes";case"saving":return"Saving…";case"saved":return"All changes saved";case"error":return n?`Save failed: ${n}`:"Save failed";default:return"Saved"}}function gn(t){const n=crypto.randomUUID().replaceAll("-","").slice(0,4);return{key:`${t}_${n}`,label:t==="input"?"New input":"New output",kind:t==="input"?"context":"record",description:"",required:!1,modelName:t==="input"?"WorkbenchInputContract":"WorkbenchOutputContract"}}function xn(){return{key:`flow_input_${crypto.randomUUID().replaceAll("-","").slice(0,4)}`,label:"New flow input",kind:"text",description:"",required:!1,modelName:"WorkbenchFlowInput",bindings:[]}}function he(t){return t==="functor"||t==="chat"}function bn(t){const n=t instanceof pa||t instanceof Error?t.message:String(t);return n.includes("No model connection is configured for this connector node.")?["This flow uses an AI node, but Forge does not have any model connection configured yet.","Open Settings > Models, add a model connection, then run the flow again.","Once a model exists, the node can use the default model automatically or you can pick a specific model inside the node editor."].join(`
2
+
3
+ `):n}function fn(t){return t.map(({key:n,kind:r,required:i,description:c,modelName:d,itemKind:u,shape:s,exampleValue:o})=>({key:n,kind:r,required:!!i,description:c,modelName:d,itemKind:u,shape:s,exampleValue:o}))}function vn(t){const n=Array.from(new Set(t.map(i=>i.trim()).filter(Boolean)));return(n.includes("answer")?n:["answer",...n]).map(i=>({key:i,label:i==="answer"?"Answer":i.split(/[_-]+/).map(c=>c.charAt(0).toUpperCase()+c.slice(1)).join(" "),kind:i==="answer"?"markdown":"record",description:i==="answer"?"Primary answer returned by this AI node.":`Named output published for downstream nodes under "${i}".`,modelName:i==="answer"?"WorkbenchAiAnswer":`Workbench${i.split(/[_-]+/).map(c=>c.charAt(0).toUpperCase()+c.slice(1)).join("")}`,exampleValue:i==="answer"?"Concise answer":void 0}))}function yn(t,n){return Na(t,n)[0]??null}function Na(t,n){var u,s;const r=[],i=new Map(t.map(o=>[o.id,o]));t.length===0&&r.push("Add at least one node before running the flow.");const c=t.filter(o=>o.data.nodeType==="output");c.length===0&&r.push("Add an Output node so Forge knows what result the flow should publish.");const d=new Map;for(const o of n){d.set(o.target,(d.get(o.target)??0)+1);const m=i.get(o.source),h=i.get(o.target),f=(m==null?void 0:m.data.outputs)??[],k=(h==null?void 0:h.data.inputs)??[];m&&(o.sourceHandle&&!f.some(v=>v.key===o.sourceHandle)?r.push(`Edge from "${m.data.label}" points to missing output "${o.sourceHandle}". Update the edge or restore that output contract.`):!o.sourceHandle&&f.length>1&&r.push(`Edge from "${m.data.label}" does not name which output it should use. Pick one explicit output handle.`)),h&&(o.targetHandle&&!k.some(v=>v.key===o.targetHandle)?r.push(`Edge into "${h.data.label}" points to missing input "${o.targetHandle}". Update the edge or restore that input contract.`):!o.targetHandle&&k.length>1&&r.push(`Edge into "${h.data.label}" does not name which input it should feed. Pick one explicit input handle.`))}for(const o of c){(d.get(o.id)??0)===0&&r.push(`Connect something into the output node "${o.data.label}" so the flow has something to return.`);const m=n.filter(h=>h.target===o.id).flatMap(h=>{const f=i.get(h.source),k=(f==null?void 0:f.data.outputs)??[];return h.sourceHandle?k.filter(v=>v.key===h.sourceHandle).map(v=>v.key):k.map(v=>v.key)});o.data.outputKey&&m.length>0&&!m.includes(o.data.outputKey)&&r.push(`Output node "${o.data.label}" is configured to publish "${o.data.outputKey}", but that key is not arriving from its upstream nodes.`)}for(const o of t){const m=d.get(o.id)??0,h=n.filter(f=>f.source===o.id).length;o.data.nodeType!=="user_input"&&o.data.nodeType!=="value"&&m===0&&o.data.nodeType!=="box"&&r.push(`Connect an upstream source into "${o.data.label}" so it has real input to work with.`),o.data.nodeType==="merge"&&m<2&&r.push(`Merge node "${o.data.label}" should receive both left and right inputs before you run it.`),o.data.nodeType==="template"&&!(o.data.template??"").trim()&&r.push(`Add a template string to "${o.data.label}" before running the flow.`),o.data.nodeType==="pick_key"&&!(o.data.selectedKey??"").trim()&&r.push(`Choose which key "${o.data.label}" should pick from incoming objects.`),o.data.nodeType!=="output"&&h===0&&r.push(`Connect the output of "${o.data.label}" somewhere useful or remove the node from the graph.`)}for(const o of t)he(o.data.nodeType)&&!((u=o.data.promptTemplate)!=null&&u.trim()||(s=o.data.prompt)!=null&&s.trim())&&r.push(`Add a prompt to the AI node "${o.data.label}" before running the flow.`);return r}function Yt({title:t,description:n,kind:r,publicInputs:i,nodes:c,edges:d}){return{title:t,description:n,kind:r,publicInputs:i,graph:{nodes:c.map(ja),edges:d.map(mn)}}}const y="rounded-[18px] 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)_40%,transparent)] focus:bg-[var(--ui-surface-2)]",Sa={summary:"border-[color-mix(in_srgb,var(--warning)_30%,transparent)] bg-[var(--ui-warning-soft)] text-[var(--warning)]",markdown:"border-[color-mix(in_srgb,var(--primary)_30%,transparent)] bg-[var(--ui-accent-soft)] text-[var(--primary)]",text:"border-[color-mix(in_srgb,var(--info)_30%,transparent)] bg-[var(--ui-info-soft)] text-[var(--info)]",number:"border-[color-mix(in_srgb,var(--success)_30%,transparent)] bg-[var(--ui-success-soft)] text-[var(--success)]",boolean:"border-[color-mix(in_srgb,var(--success)_30%,transparent)] bg-[var(--ui-success-soft)] text-[var(--success)]",entity:"border-[color-mix(in_srgb,var(--primary)_30%,transparent)] bg-[var(--ui-accent-soft)] text-[var(--primary)]",entity_list:"border-[color-mix(in_srgb,var(--primary)_30%,transparent)] bg-[var(--ui-accent-soft)] text-[var(--primary)]",context:"border-[color-mix(in_srgb,var(--info)_30%,transparent)] bg-[var(--ui-info-soft)] text-[var(--info)]",metrics:"border-[color-mix(in_srgb,var(--success)_30%,transparent)] bg-[var(--ui-success-soft)] text-[var(--success)]",filters:"border-[color-mix(in_srgb,var(--warning)_30%,transparent)] bg-[var(--ui-warning-soft)] text-[var(--warning)]",record:"border-[color-mix(in_srgb,var(--primary)_30%,transparent)] bg-[var(--ui-accent-soft)] text-[var(--primary)]",record_list:"border-[color-mix(in_srgb,var(--primary)_30%,transparent)] bg-[var(--ui-accent-soft)] text-[var(--primary)]",selection:"border-[color-mix(in_srgb,var(--danger)_30%,transparent)] bg-[var(--ui-danger-soft)] text-[var(--danger)]",timeline:"border-[color-mix(in_srgb,var(--info)_30%,transparent)] bg-[var(--ui-info-soft)] text-[var(--info)]",json:"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)]",object:"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)]",array:"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)]",tool:"border-[color-mix(in_srgb,var(--danger)_30%,transparent)] bg-[var(--ui-danger-soft)] text-[var(--danger)]"};function kn(t){switch(t){case"box":case"box_input":return{icon:e.jsx($a,{className:"size-4"}),badge:"box"};case"chat":return{icon:e.jsx(ca,{className:"size-4"}),badge:"chat"};case"functor":return{icon:e.jsx(la,{className:"size-4"}),badge:"functor"};case"output":return{icon:e.jsx(oa,{className:"size-4"}),badge:"output"};case"value":return{icon:e.jsx(ia,{className:"size-4"}),badge:"value"};case"merge":return{icon:e.jsx(na,{className:"size-4"}),badge:"merge"};case"template":return{icon:e.jsx(sa,{className:"size-4"}),badge:"template"};case"pick_key":return{icon:e.jsx(ra,{className:"size-4"}),badge:"pick key"};default:return{icon:e.jsx(aa,{className:"size-4"}),badge:"input"}}}function Fe({kind:t}){return e.jsx("span",{className:E("inline-flex items-center rounded-full border px-2.5 py-1 text-[10px] uppercase tracking-[0.16em]",Sa[t]??"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)]"),children:t.replaceAll("_"," ")})}function G({label:t,onClick:n,emphasis:r=!1}){return e.jsx("button",{type:"button",className:E("rounded-full border px-3 py-1.5 text-[11px] font-medium transition",r?"border-[color-mix(in_srgb,var(--primary)_32%,transparent)] bg-[var(--ui-accent-soft)] text-[var(--ui-ink-strong)] hover:bg-[var(--ui-surface-active)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-soft)] hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]"),onPointerDown:i=>i.stopPropagation(),onClick:i=>{i.stopPropagation(),n()},children:t})}function Xt({side:t,ports:n,collapsed:r}){return e.jsxs("div",{className:"grid gap-1.5",children:[e.jsxs("div",{className:E("flex items-center gap-1 px-1 text-[10px] font-medium uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",t==="left"?"text-left":"text-right"),children:[e.jsx("span",{children:t==="left"?"Inputs":"Outputs"}),e.jsx(te,{content:t==="left"?"Inputs are values this node expects from earlier nodes in the flow.":"Outputs are the values this node publishes for later nodes to consume.",label:t==="left"?"Explain node inputs":"Explain node outputs"})]}),n.length===0?e.jsx("div",{className:E("rounded-full border border-dashed border-[var(--ui-border-subtle)] px-3 py-1.5 text-[11px] text-[var(--ui-ink-faint)]",t==="left"?"text-left":"text-right"),children:"None"}):null,n.map(i=>e.jsxs("div",{className:E("relative min-h-6 rounded-[16px] border px-3 py-2 text-[11px] tracking-[0.01em]",t==="left"?"pl-5 text-left":"pr-5 text-right",r?"bg-[var(--ui-surface-1)]":"bg-[var(--ui-surface-2)]",Sa[i.kind]??"border-[var(--ui-border-subtle)] text-[var(--ui-ink-soft)]"),children:[e.jsx(Or,{type:t==="left"?"target":"source",position:t==="left"?Ut.Left:Ut.Right,id:i.key,className:"!size-2.5 !border",style:{[t]:6,background:"var(--primary)",borderColor:"var(--ui-ink-strong)"}}),r?null:e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{children:i.label}),e.jsx(Fe,{kind:i.kind})]}),e.jsx("div",{className:"mt-1 text-[10px] text-[var(--ui-ink-faint)]",children:pn(i)})]})]},`${t}-${i.key}`))]})}function wn(t){var m,h,f,k;const n=cn(t.data.boxId??null),[r,i]=g.useState(!1),[c,d]=g.useState(!1),u=kn(t.data.nodeType),s=((m=t.data.params)==null?void 0:m.length)??0,o=`${((h=t.data.inputs)==null?void 0:h.length)??0} in · ${((f=t.data.outputs)==null?void 0:f.length)??0} out`;if(n&&t.data.nodeType==="box"){const v=n.NodeView;return e.jsxs("div",{className:"relative",children:[e.jsxs("div",{className:"absolute right-3 top-3 z-10 flex flex-wrap items-center justify-end gap-2",children:[e.jsx(G,{label:"Edit",onClick:()=>{var w,F;return(F=(w=t.data).onEditRequest)==null?void 0:F.call(w)}}),e.jsx(G,{label:o,onClick:()=>{var w,F;return(F=(w=t.data).onContractEditRequest)==null?void 0:F.call(w)}}),s>0?e.jsx(G,{label:`${s} parameter${s===1?"":"s"}`,onClick:()=>{var w,F;return(F=(w=t.data).onParameterEditRequest)==null?void 0:F.call(w)},emphasis:!0}):null]}),e.jsx("div",{className:E("rounded-[28px] p-[2px] transition",t.selected?"bg-[linear-gradient(135deg,color-mix(in_srgb,var(--primary)_60%,transparent),color-mix(in_srgb,var(--primary)_28%,transparent))]":"bg-transparent"),children:e.jsx(v,{nodeId:t.id,inputs:void 0,params:void 0,compact:!1})})]})}return e.jsxs("div",{className:E("min-w-[270px] rounded-[24px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-modal)] p-3 shadow-[var(--ui-shadow-floating)]",t.selected&&"border-[color-mix(in_srgb,var(--primary)_52%,transparent)]"),children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[var(--ui-ink-strong)]",children:[u.icon,e.jsx("div",{className:"truncate text-sm font-semibold",children:t.data.label})]}),t.data.description?e.jsx("div",{className:"mt-1 line-clamp-2 text-[12px] leading-5 text-[var(--ui-ink-soft)]",children:t.data.description}):null]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(G,{label:r?"Show ports":"Hide labels",onClick:()=>i(v=>!v)}),e.jsx("div",{className:"rounded-full bg-[var(--ui-surface-2)] px-2.5 py-1 text-[10px] uppercase tracking-[0.16em] text-[var(--ui-ink-soft)]",children:u.badge})]})]}),t.data.boxId?e.jsx("div",{className:"mt-3 rounded-full bg-[var(--ui-surface-2)] px-3 py-1.5 text-[11px] text-[var(--ui-ink-soft)]",children:t.data.boxId}):null,e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[(k=t.data.enabledToolKeys)!=null&&k.length?e.jsxs("div",{className:"rounded-full bg-[var(--ui-surface-2)] px-3 py-1.5 text-[11px] text-[var(--ui-ink-soft)]",children:[t.data.enabledToolKeys.length," tool",t.data.enabledToolKeys.length===1?"":"s"," enabled"]}):null,e.jsx(G,{label:c?"Hide schema":"Preview schema",onClick:()=>d(v=>!v)}),e.jsx(G,{label:"Edit",onClick:()=>{var v,w;return(w=(v=t.data).onEditRequest)==null?void 0:w.call(v)}}),e.jsx(G,{label:o,onClick:()=>{var v,w;return(w=(v=t.data).onContractEditRequest)==null?void 0:w.call(v)}}),s>0?e.jsx(G,{label:`${s} parameter${s===1?"":"s"}`,onClick:()=>{var v,w;return(w=(v=t.data).onParameterEditRequest)==null?void 0:w.call(v)},emphasis:!0}):null]}),e.jsxs("div",{className:"mt-3 grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)] gap-3",children:[e.jsx(Xt,{side:"left",ports:t.data.inputs??[],collapsed:r}),e.jsx(Xt,{side:"right",ports:t.data.outputs??[],collapsed:r})]}),c?e.jsxs("div",{className:"mt-3 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[10px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:[e.jsx("span",{children:"Node contract"}),e.jsx(te,{content:"This preview shows the shape of the values and tools this node exposes inside the flow graph.",label:"Explain node contract preview"})]}),e.jsx("pre",{className:"mt-2 overflow-auto whitespace-pre-wrap text-[11px] leading-5 text-[var(--ui-ink-soft)]",children:JSON.stringify({inputs:(t.data.inputs??[]).map(({key:v,kind:w,required:F})=>({key:v,kind:w,required:!!F})),outputs:(t.data.outputs??[]).map(({key:v,kind:w,required:F})=>({key:v,kind:w,required:!!F})),tools:t.data.enabledToolKeys??[]},null,2)})]}):null]})}const Ca="grid gap-3 rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",_a="grid gap-3 rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",jn="grid gap-3 rounded-[16px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",Ye="rounded-[18px] border border-dashed border-[var(--ui-border-strong)] px-4 py-3 text-sm text-[var(--ui-ink-faint)]",Xe="flex items-center gap-2 text-sm font-medium text-[var(--ui-ink-strong)]",Ze="text-sm leading-6 text-[var(--ui-ink-soft)]",Ta="flex items-center gap-2 text-sm text-[var(--ui-ink-medium)]";function Q(t,n,r){return t.map((i,c)=>c===n?{...i,...r}:i)}function pe(t,n,r,i){return t.map((c,d)=>d===n?{...c,shape:(c.shape??[]).map((u,s)=>s===r?{...u,...i}:u)}:c)}function Nn(){return{key:`field_${crypto.randomUUID().replaceAll("-","").slice(0,4)}`,label:"New field",kind:"text",required:!1}}function Te({title:t,description:n,ports:r,onChange:i,prefix:c}){return e.jsxs("div",{className:Ca,children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:Xe,children:[e.jsx("span",{children:t}),e.jsx(te,{content:n,label:`Explain ${t.toLowerCase()}`})]}),e.jsx("div",{className:`mt-1 ${Ze}`,children:n})]}),e.jsxs(B,{type:"button",variant:"secondary",size:"sm",onClick:()=>i([...r??[],gn(c)]),children:["Add ",c]})]}),e.jsxs("div",{className:"grid gap-3",children:[r.length===0?e.jsxs("div",{className:Ye,children:["No ",c,"s defined yet."]}):null,r.map((d,u)=>e.jsxs("div",{className:_a,children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(Fe,{kind:d.kind}),e.jsx("span",{className:"text-sm font-medium text-[var(--ui-ink-strong)]",children:d.label})]}),e.jsx(B,{type:"button",variant:"ghost",size:"sm",onClick:()=>i(r.filter((s,o)=>o!==u)),children:"Remove"})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsx(C,{label:"Key",description:"Downstream nodes reference this exact key.",labelHelp:"Keep keys stable once edges depend on them. Use snake_case names that describe the value clearly.",children:e.jsx("input",{value:d.key,onChange:s=>i(Q(r,u,{key:s.target.value})),className:y})}),e.jsx(C,{label:"Label",description:"Readable name shown in the graph editor.",children:e.jsx("input",{value:d.label,onChange:s=>i(Q(r,u,{label:s.target.value})),className:y})})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsx(C,{label:"Value type",description:"This colors the port and tells the flow what sort of value should move through it.",children:e.jsx("select",{value:d.kind,onChange:s=>i(Q(r,u,{kind:s.target.value})),className:y,children:Qe.map(s=>e.jsx("option",{value:s,children:s.replaceAll("_"," ")},s))})}),e.jsx(C,{label:"Model name",description:"Semantic model name for this port, used in previews and runtime contracts.",children:e.jsx("input",{value:d.modelName??"",onChange:s=>i(Q(r,u,{modelName:s.target.value||void 0})),placeholder:"WorkbenchTaskSearchResults",className:y})})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsx(C,{label:"Item kind",description:"Optional entity or item subtype when this port carries a collection.",children:e.jsx("input",{value:d.itemKind??"",onChange:s=>i(Q(r,u,{itemKind:s.target.value||void 0})),placeholder:"task",className:y})}),e.jsx(C,{label:"Example value",description:"Short example shown in collapsed previews.",children:e.jsx("input",{value:d.exampleValue??"",onChange:s=>i(Q(r,u,{exampleValue:s.target.value||void 0})),placeholder:c==="input"?"task ids and filters":"summarized result",className:y})})]}),e.jsx(C,{label:"Expectation",description:"Describe what should actually be inside this value so the graph stays legible.",children:e.jsx("textarea",{rows:3,value:d.description??"",onChange:s=>i(Q(r,u,{description:s.target.value||void 0})),placeholder:c==="input"?"Explain what upstream nodes should provide here.":"Explain what downstream nodes can expect from this output.",className:y})}),e.jsxs("details",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("summary",{className:"cursor-pointer text-sm font-medium text-[var(--ui-ink-strong)]",children:"Shape fields"}),e.jsxs("div",{className:"mt-3 grid gap-3",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsx("div",{className:Ze,children:"Describe the object structure or list item shape this port carries."}),e.jsx(B,{type:"button",variant:"secondary",size:"sm",onClick:()=>i(r.map((s,o)=>o===u?{...s,shape:[...s.shape??[],Nn()]}:s)),children:"Add field"})]}),(d.shape??[]).length===0?e.jsx("div",{className:Ye,children:"No explicit structure fields yet."}):null,(d.shape??[]).map((s,o)=>e.jsxs("div",{className:jn,children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx(Fe,{kind:s.kind}),e.jsx(B,{type:"button",variant:"ghost",size:"sm",onClick:()=>i(r.map((m,h)=>h===u?{...m,shape:(m.shape??[]).filter((f,k)=>k!==o)}:m)),children:"Remove field"})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsx("input",{value:s.key,onChange:m=>i(pe(r,u,o,{key:m.target.value})),placeholder:"field_key",className:y}),e.jsx("input",{value:s.label,onChange:m=>i(pe(r,u,o,{label:m.target.value})),placeholder:"Field label",className:y})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsx("select",{value:s.kind,onChange:m=>i(pe(r,u,o,{kind:m.target.value})),className:y,children:Qe.map(m=>e.jsx("option",{value:m,children:m.replaceAll("_"," ")},m))}),e.jsxs("label",{className:"flex items-center gap-2 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-3 text-sm text-[var(--ui-ink-medium)]",children:[e.jsx("input",{type:"checkbox",checked:!!s.required,onChange:m=>i(pe(r,u,o,{required:m.target.checked}))}),"Required field"]})]}),e.jsx("textarea",{rows:2,value:s.description??"",onChange:m=>i(pe(r,u,o,{description:m.target.value||void 0})),placeholder:"What should this field contain?",className:y})]},`${d.key}-shape-${s.key}-${o}`))]})]}),e.jsxs("label",{className:Ta,children:[e.jsx("input",{type:"checkbox",checked:!!d.required,onChange:s=>i(Q(r,u,{required:s.target.checked}))}),"Required port"]})]},`${c}-${d.key}-${u}`))]})]})}function Sn({inputs:t,nodes:n,onChange:r}){return e.jsxs("div",{className:Ca,children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:Xe,children:[e.jsx("span",{children:"Flow inputs"}),e.jsx(te,{content:"These are the typed inputs your Workbench flow exposes to the API and the Run modal.",label:"Explain flow inputs"})]}),e.jsx("div",{className:`mt-1 ${Ze}`,children:"Define the external contract once, then bind each input to the node inputs or parameters that should consume it."})]}),e.jsx(B,{type:"button",variant:"secondary",size:"sm",onClick:()=>r([...t??[],xn()]),children:"Add flow input"})]}),t.length===0?e.jsx("div",{className:Ye,children:"No public flow inputs defined yet."}):null,e.jsx("div",{className:"grid gap-3",children:t.map((i,c)=>{const d=n.filter(s=>(s.data.inputs??[]).length>0||(s.data.params??[]).length>0),u=s=>r(t.map((o,m)=>m===c?{...o,...s}:o));return e.jsxs("div",{className:_a,children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(Fe,{kind:i.kind}),e.jsx("span",{className:"text-sm font-medium text-[var(--ui-ink-strong)]",children:i.label})]}),e.jsx(B,{type:"button",variant:"ghost",size:"sm",onClick:()=>r(t.filter((s,o)=>o!==c)),children:"Remove"})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsx(C,{label:"Key",description:"External API key callers will send.",children:e.jsx("input",{value:i.key,onChange:s=>u({key:s.target.value}),className:y})}),e.jsx(C,{label:"Label",description:"Human-readable name used in the Run modal.",children:e.jsx("input",{value:i.label,onChange:s=>u({label:s.target.value}),className:y})})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsx(C,{label:"Value type",description:"Expected type for this flow input.",children:e.jsx("select",{value:i.kind,onChange:s=>u({kind:s.target.value}),className:y,children:Qe.map(s=>e.jsx("option",{value:s,children:s.replaceAll("_"," ")},s))})}),e.jsx(C,{label:"Default value",description:"Used when a caller omits this input.",children:e.jsx("textarea",{rows:3,value:Pe(i.defaultValue),onChange:s=>u({defaultValue:va(i.kind,s.target.value)}),className:y})})]}),e.jsx(C,{label:"Description",description:"Explain what callers should send here.",children:e.jsx("textarea",{rows:3,value:i.description??"",onChange:s=>u({description:s.target.value}),className:y})}),e.jsxs("label",{className:Ta,children:[e.jsx("input",{type:"checkbox",checked:!!i.required,onChange:s=>u({required:s.target.checked})}),"Required input"]}),e.jsxs("div",{className:"grid gap-2 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-3",children:[e.jsxs("div",{className:Xe,children:["Bindings",e.jsx(te,{content:"Bind this public input to one or more node inputs or parameters. If you leave bindings empty and a node uses the same key, Forge will bind it automatically by key.",label:"Explain bindings"})]}),(i.bindings??[]).map((s,o)=>{const m=n.find(f=>f.id===s.nodeId)??null,h=s.targetKind==="param"?(m==null?void 0:m.data.params)??[]:(m==null?void 0:m.data.inputs)??[];return e.jsxs("div",{className:"grid gap-3 rounded-[16px] bg-[var(--ui-surface-2)] p-3 md:grid-cols-[1.2fr_1fr_1fr_auto]",children:[e.jsxs("select",{value:s.nodeId,onChange:f=>u({bindings:(i.bindings??[]).map((k,v)=>v===o?{...k,nodeId:f.target.value,targetKey:""}:k)}),className:y,children:[e.jsx("option",{value:"",children:"Select node"}),d.map(f=>e.jsx("option",{value:f.id,children:f.data.label},f.id))]}),e.jsxs("select",{value:s.targetKind,onChange:f=>u({bindings:(i.bindings??[]).map((k,v)=>v===o?{...k,targetKind:f.target.value,targetKey:""}:k)}),className:y,children:[e.jsx("option",{value:"input",children:"Node input"}),e.jsx("option",{value:"param",children:"Node parameter"})]}),e.jsxs("select",{value:s.targetKey,onChange:f=>u({bindings:(i.bindings??[]).map((k,v)=>v===o?{...k,targetKey:f.target.value}:k)}),className:y,children:[e.jsx("option",{value:"",children:"Select target"}),h.map(f=>e.jsx("option",{value:f.key,children:f.label},f.key))]}),e.jsx(B,{type:"button",variant:"ghost",size:"sm",onClick:()=>u({bindings:(i.bindings??[]).filter((f,k)=>k!==o)}),children:"Remove"})]},`${s.nodeId}-${s.targetKey}-${o}`)}),e.jsx(B,{type:"button",variant:"secondary",size:"sm",onClick:()=>u({bindings:[...i.bindings??[],{nodeId:"",targetKind:"input",targetKey:""}]}),children:"Add binding"})]})]},`${i.key}-${c}`)})})]})}const Cn="min-w-0 rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",Zt="min-w-0 rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-left text-[var(--ui-ink-medium)] transition hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-hover)]",ea="rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-2.5 py-1 text-[11px] text-[var(--ui-ink-soft)]",_n="text-[10px] uppercase tracking-[0.14em] text-[var(--ui-ink-faint)]";function ge({open:t,onOpenChange:n,title:r,description:i,children:c}){return e.jsx(as,{open:t,onOpenChange:n,children:e.jsxs(rs,{children:[e.jsx(ss,{className:"fixed inset-0 z-50 bg-[var(--ui-overlay-backdrop)] backdrop-blur-sm"}),e.jsxs(ns,{className:"fixed inset-x-4 bottom-4 top-4 z-50 mx-auto flex max-w-[min(44rem,calc(100vw-2rem))] flex-col overflow-hidden rounded-[32px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-modal)] shadow-[var(--ui-shadow-floating)] md:left-1/2 md:right-auto md:top-[8vh] md:h-[min(82vh,58rem)] md:w-[min(44rem,calc(100vw-1.25rem))] md:-translate-x-1/2 md:bottom-auto",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4 border-b border-[var(--ui-border-subtle)] px-5 py-4 backdrop-blur-xl",children:[e.jsxs("div",{children:[e.jsx(is,{className:"font-display text-[1.28rem] tracking-[-0.04em] text-[var(--ui-ink-strong)]",children:r}),i?e.jsx(os,{className:"mt-1 text-sm leading-6 text-[var(--ui-ink-soft)]",children:i}):null]}),e.jsx(ls,{asChild:!0,children:e.jsx($r,{"aria-label":"Close workbench flow dialog"})})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto overscroll-contain px-5 py-5",children:c})]})]})})}const Tn=[{type:"user_input",label:"User input",icon:e.jsx(aa,{className:"size-4"})},{type:"value",label:"Value",icon:e.jsx(ia,{className:"size-4"})},{type:"functor",label:"Functor",icon:e.jsx(la,{className:"size-4"})},{type:"chat",label:"Chat",icon:e.jsx(za,{className:"size-4"})},{type:"merge",label:"Merge",icon:e.jsx(na,{className:"size-4"})},{type:"template",label:"Template",icon:e.jsx(sa,{className:"size-4"})},{type:"pick_key",label:"Pick key",icon:e.jsx(ra,{className:"size-4"})},{type:"output",label:"Output",icon:e.jsx(oa,{className:"size-4"})}];function In({open:t,onOpenChange:n,boxQuery:r,onBoxQueryChange:i,boxOptions:c,boxFilters:d,onBoxFiltersChange:u,filteredBoxes:s,onAddNodeType:o,onAddBox:m}){return e.jsx(ge,{open:t,onOpenChange:n,title:"Add node",description:"Add a Forge box, AI node, or utility node to the flow.",children:e.jsxs("div",{className:"grid gap-4",children:[e.jsx("div",{className:"grid gap-2 sm:grid-cols-2",children:Tn.map(h=>e.jsxs("button",{type:"button",className:`${Zt} flex items-center gap-3 px-4 py-3`,onClick:()=>o(h.type),children:[h.icon,e.jsx("span",{children:h.label})]},h.type))}),e.jsx(cs,{title:"Forge boxes",description:"",query:r,onQueryChange:i,options:c,selectedOptionIds:d,onSelectedOptionIdsChange:u,resultSummary:`${s.length} boxes`,placeholder:"Search visible Forge boxes by title, route, or category",emptyStateMessage:"No boxes match the current query."}),e.jsx("div",{className:"grid max-h-[18rem] gap-2 overflow-auto pr-1",children:s.map(h=>e.jsxs("button",{type:"button",className:`${Zt} px-4 py-3`,onClick:()=>m(h),children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsx("div",{className:"min-w-0 break-words text-sm font-medium text-[var(--ui-ink-strong)]",children:h.title}),e.jsxs("div",{className:`flex shrink-0 flex-wrap gap-2 ${_n}`,children:[e.jsxs("span",{children:[h.output.length," output",h.output.length===1?"":"s"]}),e.jsxs("span",{children:[h.tools.length," tool",h.tools.length===1?"":"s"]})]})]}),e.jsx("div",{className:"mt-1 text-[12px] leading-5 text-[var(--ui-ink-soft)]",children:h.description}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx("div",{className:ea,children:h.category}),h.routePath?e.jsx("div",{className:ea,children:h.routePath}):null]})]},h.id))})]})})}function Pn({open:t,onOpenChange:n,title:r,onTitleChange:i,description:c,onDescriptionChange:d,kind:u,onKindChange:s,publicInputs:o,onPublicInputsChange:m,nodes:h,flowId:f,onDelete:k,onSave:v}){return e.jsx(ge,{open:t,onOpenChange:n,title:"Flow settings",description:"Edit the flow identity and persistence without covering the graph with permanent forms.",children:e.jsxs("div",{className:"grid gap-3",children:[e.jsx("input",{value:r,onChange:w=>i(w.target.value),placeholder:"Flow title",className:y}),e.jsx("textarea",{rows:4,value:c,onChange:w=>d(w.target.value),placeholder:"Flow description",className:y}),e.jsxs("select",{value:u,onChange:w=>s(w.target.value),className:y,children:[e.jsx("option",{value:"functor",children:"Functor flow"}),e.jsx("option",{value:"chat",children:"Chat flow"})]}),e.jsx(Sn,{inputs:o,nodes:h,onChange:m}),e.jsx("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-code-bg)] px-4 py-3 font-mono text-sm text-[var(--ui-code-text)] [overflow-wrap:anywhere]",children:f}),e.jsxs("div",{className:"flex flex-wrap justify-between gap-2 pt-2",children:[e.jsxs(B,{type:"button",variant:"secondary",onClick:()=>{k()},children:[e.jsx(Ue,{className:"size-4"}),"Delete flow"]}),e.jsxs(B,{type:"button",variant:"primary",onClick:()=>{v().then(()=>n(!1))},children:[e.jsx(da,{className:"size-4"}),"Save settings"]})]})]})})}function Fn(t){if(t.trim())try{return JSON.parse(t)}catch{return t}}function Bn({open:t,onOpenChange:n,runError:r,graphIssues:i,hasAiNodes:c,modelConnectionCount:d,publicInputs:u,runInputs:s,onRunInputChange:o,shouldShowLegacyUserInput:m,userInput:h,onUserInputChange:f,debugEnabled:k,onDebugEnabledChange:v,onRun:w,onChat:F,runs:I}){return e.jsx(ge,{open:t,onOpenChange:n,title:"Run flow",description:"Run the flow or chat with it and keep the debug trace for every node.",children:e.jsxs("div",{className:"grid gap-3",children:[r?e.jsx("div",{className:"rounded-[20px] border border-[color-mix(in_srgb,var(--danger)_28%,transparent)] bg-[var(--ui-danger-soft)] px-4 py-3 text-sm leading-6 text-[var(--danger)]",children:r}):null,!r&&i.length>0?e.jsxs("div",{className:"rounded-[20px] border border-[color-mix(in_srgb,var(--warning)_28%,transparent)] bg-[var(--ui-warning-soft)] px-4 py-3 text-sm leading-6 text-[var(--warning)]",children:[e.jsx("div",{className:"font-medium",children:"Fix these graph issues before running:"}),e.jsx("ul",{className:"mt-2 grid gap-1",children:i.slice(0,4).map(x=>e.jsxs("li",{children:["• ",x]},x))})]}):null,!r&&c&&d===0?e.jsx("div",{className:"rounded-[20px] border border-[color-mix(in_srgb,var(--info)_28%,transparent)] bg-[var(--ui-info-soft)] px-4 py-3 text-sm leading-6 text-[var(--info)]",children:"This flow contains AI nodes, but Forge does not have a model connection yet. Open Settings > Models, add one connection, then come back and run the flow."}):null,u.length>0?e.jsxs("div",{className:`grid gap-3 p-4 ${Cn}`,children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-[var(--ui-ink-strong)]",children:["Flow inputs",e.jsx(te,{content:"These are the typed inputs this flow exposes through the API and the Run modal.",label:"Explain flow inputs"})]}),e.jsx("div",{className:"grid gap-3",children:u.map(x=>e.jsx(C,{label:x.label,description:x.description||"Typed input for this flow.",children:x.kind==="boolean"?e.jsxs("label",{className:"flex items-center gap-2 text-sm text-[var(--ui-ink-medium)]",children:[e.jsx("input",{type:"checkbox",checked:!!s[x.key],onChange:T=>o(x.key,T.target.checked)}),x.label]}):x.kind==="number"?e.jsx("input",{type:"number",value:typeof s[x.key]=="number"?String(s[x.key]):"",onChange:T=>o(x.key,T.target.value.trim().length===0?void 0:Number(T.target.value)),className:y}):x.kind==="array"||x.kind==="entity_list"||x.kind==="record_list"||x.kind==="object"||x.kind==="json"||x.kind==="record"||x.kind==="context"||x.kind==="filters"||x.kind==="metrics"||x.kind==="timeline"||x.kind==="selection"||x.kind==="entity"?e.jsx("textarea",{rows:4,value:Pe(s[x.key]),onChange:T=>o(x.key,Fn(T.target.value)),placeholder:'{"key":"value"}',className:y}):e.jsx("input",{value:typeof s[x.key]=="string"?s[x.key]:"",onChange:T=>o(x.key,T.target.value),placeholder:x.exampleValue||x.label,className:y})},x.key))})]}):null,m?e.jsx("textarea",{rows:5,value:h,onChange:x=>f(x.target.value),placeholder:"User input",className:y}):null,e.jsxs("label",{className:"flex items-center gap-2 text-sm text-[var(--ui-ink-soft)]",children:[e.jsx("input",{type:"checkbox",checked:k,onChange:x=>v(x.target.checked)}),"Return debug trace"]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(B,{type:"button",variant:"primary",onClick:w,children:[e.jsx(Ge,{className:"size-4"}),"Run"]}),e.jsxs(B,{type:"button",variant:"secondary",onClick:F,children:[e.jsx(ca,{className:"size-4"}),"Chat"]})]}),e.jsx("div",{className:"grid gap-2 pt-2",children:I.slice(0,5).map(x=>{var T;return e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 text-[12px] text-[var(--ui-ink-faint)]",children:[e.jsx("span",{children:x.mode}),e.jsx("span",{children:new Date(x.createdAt).toLocaleString()})]}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-medium)]",children:((T=x.result)==null?void 0:T.primaryText)??x.error??"No output yet."})]},x.id)})})]})})}function Be(t){switch(t){case"exec":return 4;case"read_write":return 3;case"write":return 2;case"read":default:return 1}}function Rn(t,n){return Be(t)>=Be(n)?t:n}function ta(t,n){return t==="forge.search_entities"?"Search across Forge entities. You can optionally narrow the search to specific entity types.":t==="forge.create_note"?"Create a Forge note from generated content or captured markdown.":t==="forge.update_task_status"?"Move a task between execution states such as backlog, focus, in progress, blocked, and done.":n.sort((r,i)=>i.length-r.length)[0]??"Workbench tool"}function Wn(t){const n=new Map;for(const r of t)for(const i of r.tools){const c=n.get(i.key);if(!c){n.set(i.key,{key:i.key,label:i.label,description:ta(i.key,[i.description]),accessMode:i.accessMode,argsSchema:i.argsSchema,sources:[r.title],sourceSurfaceIds:r.surfaceId?[r.surfaceId]:[]});continue}c.accessMode=Rn(c.accessMode,i.accessMode),c.label=c.label.length>=i.label.length?c.label:i.label,c.description=ta(i.key,[c.description,i.description]),c.argsSchema=c.argsSchema??i.argsSchema,c.sources.includes(r.title)||c.sources.push(r.title),r.surfaceId&&!c.sourceSurfaceIds.includes(r.surfaceId)&&c.sourceSurfaceIds.push(r.surfaceId)}return[...n.values()].sort((r,i)=>{const c=Be(i.accessMode)-Be(r.accessMode);return c!==0?c:r.label.localeCompare(i.label)})}const En={workbench:wn},Ie="inline-flex h-11 items-center gap-2 rounded-full bg-[color-mix(in_srgb,var(--surface-glass)_94%,transparent)] px-4 text-sm font-medium text-[var(--ui-ink-strong)] shadow-[var(--ui-shadow-soft)] transition hover:bg-[var(--ui-surface-hover)]";function On(t){return t==="error"?"border-[color-mix(in_srgb,var(--danger)_28%,transparent)] bg-[var(--ui-danger-soft)] text-[var(--danger)]":t==="saving"?"border-[color-mix(in_srgb,var(--info)_28%,transparent)] bg-[var(--ui-info-soft)] text-[var(--info)]":t==="dirty"?"border-[color-mix(in_srgb,var(--warning)_28%,transparent)] bg-[var(--ui-warning-soft)] text-[var(--warning)]":"border-[color-mix(in_srgb,var(--success)_28%,transparent)] bg-[var(--ui-success-soft)] text-[var(--success)]"}function Kn({flow:t,boxes:n,modelConnections:r,runs:i,onSave:c,onDelete:d,onRun:u,onChat:s}){var Nt,St,Ct,_t,Tt,It,Pt,Ft,Bt,Rt,Wt,Et,Ot,Kt,Mt,Lt,At,Ht,qt,$t,zt,Vt;const[o,m]=g.useState(t.title),[h,f]=g.useState(t.description),[k,v]=g.useState(t.kind),[w,F]=g.useState(t.publicInputs??[]),[I,x]=g.useState(()=>De(t,n).nodes),[T,ne]=g.useState(()=>De(t,n).edges),[be,Re]=g.useState(null),[Ia,fe]=g.useState(!1),[dt,J]=g.useState(!1),[ve,ye]=g.useState("overview"),[Pa,We]=g.useState(void 0),[Fa,ke]=g.useState(!1),[Ba,ut]=g.useState(!1),[Ee,Oe]=g.useState(!1),[Ke,Ra]=g.useState(""),[Me,Wa]=g.useState([]),[Le,Ea]=g.useState(""),[mt,pt]=g.useState({}),[Ae,Oa]=g.useState(!0),[Ka,Y]=g.useState(null),[He,X]=g.useState("idle"),[Ma,we]=g.useState(null),[ae,ht]=g.useState(((Nt=i[0])==null?void 0:Nt.id)??null),[je,gt]=g.useState(null),$=g.useMemo(()=>JSON.stringify(Yt({title:t.title,description:t.description,kind:t.kind,publicInputs:t.publicInputs??[],nodes:t.graph.nodes.map(a=>Je(a,n)),edges:t.graph.edges.map(wa)})),[n,t]),re=g.useRef($),qe=g.useRef($),xt=g.useRef({}),Ne=g.useRef($),Se=g.useRef(null),Ce=g.useRef(!1);g.useEffect(()=>{if($===qe.current)return;qe.current=$,re.current=$,Ne.current=$,m(t.title),f(t.description),v(t.kind),F(t.publicInputs??[]);const a=De(t,n);x(a.nodes),ne(a.edges),X("idle"),we(null)},[n,t,$]),g.useEffect(()=>{pt(Object.fromEntries((t.publicInputs??[]).filter(a=>a.defaultValue!==void 0).map(a=>[a.key,a.defaultValue])))},[t.publicInputs]),g.useEffect(()=>{var a;ht(((a=i[0])==null?void 0:a.id)??null)},[i]),g.useEffect(()=>{x(a=>a.map(l=>l.data.nodeType!=="box"||!l.data.boxId?l:Je(ja(l),n)))},[n]);const La=g.useMemo(()=>Array.from(new Set(n.map(l=>l.category))).map(l=>({id:`category:${l}`,label:l,description:"Workbench box category"})),[n]),Aa=g.useMemo(()=>{const a=Ke.trim().toLowerCase();return n.filter(l=>{const p=a.length===0||[l.title,l.description,l.category,l.routePath??"",...l.tags].join(" ").toLowerCase().includes(a),N=Me.every(S=>S.startsWith("category:")?l.category===S.replace("category:",""):!0);return p&&N})},[Me,Ke,n]),b=g.useMemo(()=>I.find(a=>a.id===be)??null,[I,be]),ie=i[0]??null,Z=i.find(a=>a.id===ae)??ie??null,se=zr({flowId:t.id,runId:ae??""},{skip:!ae||!Ee}),z=((St=se.data)==null?void 0:St.nodeResults.find(a=>a.nodeId===je))??null,V=Vr({flowId:t.id,runId:ae??"",nodeId:je??""},{skip:!ae||!je||!Ee}),$e=g.useMemo(()=>Na(I,T),[I,T]),bt=g.useMemo(()=>I.some(a=>he(a.data.nodeType)),[I]),ze=g.useMemo(()=>I.some(a=>a.data.nodeType==="user_input")||(w??[]).length===0,[I,w]);g.useEffect(()=>{var l,p;const a=((p=(l=se.data)==null?void 0:l.nodeResults[0])==null?void 0:p.nodeId)??null;gt(a)},[(Ct=se.data)==null?void 0:Ct.nodeResults]);const ft=g.useMemo(()=>!!(b&&b.data.nodeType!=="box"&&b.data.nodeType!=="box_input"),[b]),vt=g.useMemo(()=>b?T.filter(a=>a.target===b.id).flatMap(a=>{const l=I.find(N=>N.id===a.source),p=(l==null?void 0:l.data.outputs)??[];return a.sourceHandle?p.filter(N=>N.key===a.sourceHandle):p}):[],[T,I,b]),oe=g.useMemo(()=>Wn(n),[n]),le=g.useMemo(()=>{if(!b||!he(b.data.nodeType))return[];const a=new Set(b.data.enabledToolKeys??[]);return oe.filter(l=>a.has(l.key))},[oe,b]),Ve=g.useMemo(()=>Yt({title:o,description:h,kind:k,publicInputs:w,nodes:I,edges:T}),[h,T,k,I,w,o]),ce=g.useMemo(()=>JSON.stringify(Ve),[Ve]),yt=ce!==re.current;g.useEffect(()=>{if(xt.current=Ve,Ne.current=ce,ce===re.current){we(null),X(a=>a==="saved"?a:"idle");return}X(a=>a==="saving"?a:"dirty")},[ce]);const Ha=g.useMemo(()=>!b||!he(b.data.nodeType)?[]:[{id:"overview",eyebrow:b.data.nodeType==="chat"?"Chat node":"Functor node",title:"Define what this node is responsible for",description:"Give the node a clear role in the flow before configuring prompts and models.",render:(a,l)=>e.jsxs(e.Fragment,{children:[e.jsx(C,{label:"Label",description:"This is the name shown on the canvas and in debug traces.",children:e.jsx("input",{value:a.label,onChange:p=>l({label:p.target.value}),className:y})}),e.jsx(C,{label:"Description",description:"Explain what this node should do with the incoming flow context.",children:e.jsx("textarea",{rows:4,value:a.description,onChange:p=>l({description:p.target.value}),className:y})})]})},{id:"prompts",eyebrow:"Prompts",title:"Set the prompt contract",description:"Separate the main prompt from the system instruction so this node stays easier to maintain.",render:(a,l)=>e.jsxs(e.Fragment,{children:[e.jsx(C,{label:"Prompt template",description:"This is the main instruction the node sends with the current flow input.",children:e.jsx("textarea",{rows:8,value:a.promptTemplate??a.prompt??"",onChange:p=>l({promptTemplate:p.target.value,prompt:p.target.value}),className:y})}),e.jsx(C,{label:"System prompt",description:"Use this for durable behavior and output rules that should stay consistent.",children:e.jsx("textarea",{rows:5,value:a.systemPrompt??"",onChange:p=>l({systemPrompt:p.target.value}),className:y})})]})},{id:"model",eyebrow:"Model",title:"Choose how this node reaches a model",description:"Pick a specific model connection or leave it on the Forge default once models are configured.",render:(a,l)=>{var p,N,S;return e.jsxs(e.Fragment,{children:[r.length===0?e.jsx("div",{className:"rounded-[20px] border border-[color-mix(in_srgb,var(--warning)_28%,transparent)] bg-[var(--ui-warning-soft)] px-4 py-3 text-sm leading-6 text-[var(--warning)]",children:"No model connection is configured yet. Open Settings > Models, add one connection, then come back here."}):null,e.jsx(C,{label:"Model connection",description:"This can stay empty if you want the node to use Forge's default configured model.",children:e.jsxs("select",{value:((p=a.modelConfig)==null?void 0:p.connectionId)??"",onChange:j=>{var D,U;const P=r.find(ee=>ee.id===j.target.value);l({modelConfig:{connectionId:(P==null?void 0:P.id)??null,provider:(P==null?void 0:P.provider)??null,baseUrl:(P==null?void 0:P.baseUrl)??null,model:(P==null?void 0:P.model)??"",thinking:((D=a.modelConfig)==null?void 0:D.thinking)??null,verbosity:((U=a.modelConfig)==null?void 0:U.verbosity)??null}})},className:y,children:[e.jsx("option",{value:"",children:"Use Forge default model"}),r.map(j=>e.jsx("option",{value:j.id,children:j.label},j.id))]})}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsx(C,{label:"Thinking effort",description:"Optional reasoning setting for models that support it.",children:e.jsxs("select",{value:((N=a.modelConfig)==null?void 0:N.thinking)??"",onChange:j=>{var P,D,U,ee,me;return l({modelConfig:{connectionId:((P=a.modelConfig)==null?void 0:P.connectionId)??null,provider:((D=a.modelConfig)==null?void 0:D.provider)??null,baseUrl:((U=a.modelConfig)==null?void 0:U.baseUrl)??null,model:((ee=a.modelConfig)==null?void 0:ee.model)??"",thinking:j.target.value||null,verbosity:((me=a.modelConfig)==null?void 0:me.verbosity)??null}})},className:y,children:[e.jsx("option",{value:"",children:"Default"}),e.jsx("option",{value:"low",children:"Low"}),e.jsx("option",{value:"medium",children:"Medium"}),e.jsx("option",{value:"high",children:"High"})]})}),e.jsx(C,{label:"Verbosity",description:"Optional output detail setting for models that support it.",children:e.jsxs("select",{value:((S=a.modelConfig)==null?void 0:S.verbosity)??"",onChange:j=>{var P,D,U,ee,me;return l({modelConfig:{connectionId:((P=a.modelConfig)==null?void 0:P.connectionId)??null,provider:((D=a.modelConfig)==null?void 0:D.provider)??null,baseUrl:((U=a.modelConfig)==null?void 0:U.baseUrl)??null,model:((ee=a.modelConfig)==null?void 0:ee.model)??"",thinking:((me=a.modelConfig)==null?void 0:me.thinking)??null,verbosity:j.target.value||null}})},className:y,children:[e.jsx("option",{value:"",children:"Default"}),e.jsx("option",{value:"low",children:"Low"}),e.jsx("option",{value:"medium",children:"Medium"}),e.jsx("option",{value:"high",children:"High"})]})})]})]})}},{id:"contracts",eyebrow:"Contracts",title:"Define the input and output contract",description:"Give this AI node truthful port names, value types, and expectations so the graph stays readable.",render:(a,l)=>e.jsxs("div",{className:"grid gap-4",children:[e.jsx(Te,{title:"Inputs",description:"Name the upstream values this AI node expects to receive.",ports:a.inputs??[],onChange:p=>l({inputs:p}),prefix:"input"}),e.jsx(Te,{title:"Outputs",description:"Describe exactly what this AI node will publish for later nodes.",ports:a.outputs??[],onChange:p=>l({outputs:p}),prefix:"output"})]})},{id:"tools",eyebrow:"Outputs and tools",title:"Control what this node can call and publish",description:"Keep tool access tight and name any extra outputs the rest of the flow should consume.",render:(a,l)=>e.jsxs(e.Fragment,{children:[e.jsx(C,{label:"Enabled tools",description:"Only checked tools will be available to this AI node during execution.",children:e.jsx("div",{className:"grid max-h-[18rem] gap-2 overflow-y-auto pr-1",children:oe.length>0?oe.map(p=>{const N=(a.enabledToolKeys??[]).includes(p.key);return e.jsxs("label",{className:"flex items-start gap-3 rounded-[16px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-3 py-2 text-left",children:[e.jsx("input",{type:"checkbox",checked:N,onChange:S=>{const j=new Set(a.enabledToolKeys??[]);S.target.checked?j.add(p.key):j.delete(p.key),l({enabledToolKeys:[...j]})}}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-[var(--ui-ink-strong)]",children:[e.jsx("span",{children:p.label}),e.jsx("span",{className:"rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-2 py-0.5 text-[10px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:p.accessMode.replace("_"," ")})]}),e.jsx("div",{className:"text-[12px] leading-5 text-[var(--ui-ink-soft)]",children:p.description}),p.sources.length>0?e.jsx("div",{className:"mt-2 flex flex-wrap gap-2",children:p.sources.map(S=>e.jsx("span",{className:"rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-2 py-1 text-[10px] text-[var(--ui-ink-faint)]",children:S},`${p.key}-${S}`))}):null,e.jsx("div",{className:"mt-1 font-mono text-[10px] text-[var(--ui-ink-faint)]",children:p.key}),p.argsSchema?e.jsxs("details",{className:"mt-2 rounded-[14px] border border-[var(--ui-border-subtle)] bg-[var(--ui-code-bg)] px-3 py-2",children:[e.jsx("summary",{className:"cursor-pointer text-[11px] text-[var(--ui-ink-soft)]",children:"Preview tool arguments"}),e.jsx("pre",{className:"mt-2 overflow-auto whitespace-pre-wrap text-[10px] leading-5 text-[var(--ui-ink-faint)]",children:JSON.stringify(p.argsSchema,null,2)})]}):null]})]},p.key)}):e.jsx("div",{className:"text-sm text-[var(--ui-ink-faint)]",children:"No registered Forge tools are available yet."})})}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsx(C,{label:"Enabled tool preview",description:"Collapsed by default in the node card, this is the contract the AI node can call at run time.",children:e.jsxs("details",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-code-bg)] px-4 py-3",children:[e.jsx("summary",{className:"cursor-pointer text-sm text-[var(--ui-ink-medium)]",children:le.length>0?`${le.length} tool contract${le.length===1?"":"s"}`:"No tool contract yet"}),e.jsx("pre",{className:"mt-3 overflow-auto whitespace-pre-wrap text-[11px] leading-5 text-[var(--ui-ink-soft)]",children:JSON.stringify(le.map(p=>({key:p.key,label:p.label,accessMode:p.accessMode,sources:p.sources,argsSchema:p.argsSchema})),null,2)})]})}),e.jsx(C,{label:"Output preview",description:"This is the structure downstream nodes will see from this AI node.",children:e.jsxs("details",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-code-bg)] px-4 py-3",children:[e.jsxs("summary",{className:"cursor-pointer text-sm text-[var(--ui-ink-medium)]",children:[(a.outputs??[]).length," published output",(a.outputs??[]).length===1?"":"s"]}),e.jsx("pre",{className:"mt-3 overflow-auto whitespace-pre-wrap text-[11px] leading-5 text-[var(--ui-ink-soft)]",children:JSON.stringify(fn(a.outputs??[]),null,2)})]})})]}),e.jsx(C,{label:"Named outputs",description:"Add comma-separated output keys when later nodes should read more than the primary answer.",children:e.jsx("input",{value:(a.outputs??[]).filter(p=>p.key!=="answer").map(p=>p.key).join(", "),onChange:p=>l({outputs:vn(["answer",...p.target.value.split(",")])}),placeholder:"summary, plan, next_steps",className:y})}),e.jsxs("div",{className:"rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Danger zone"}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Remove this node from the graph if you no longer need it."}),e.jsxs(B,{type:"button",variant:"secondary",className:"mt-4",onClick:()=>{kt(b.id),J(!1)},children:[e.jsx(Ue,{className:"size-4"}),"Delete node"]})]})]})}],[oe,r,le,b]),de=g.useCallback(async()=>{const a=Ne.current,l=xt.current;if(a===re.current)return X("saved"),!0;if(Se.current)return Ce.current=!0,Se.current;X("saving"),we(null);const p=c(l).then(()=>(re.current=a,qe.current=a,X("saved"),!0)).catch(N=>{const S=N instanceof pa||N instanceof Error?N.message:String(N);return we(S),X("error"),!1}).finally(()=>{Se.current=null,Ce.current&&Ne.current!==re.current?(Ce.current=!1,de()):Ce.current=!1});return Se.current=p,p},[c]);g.useEffect(()=>{if(!yt)return;const a=window.setTimeout(()=>{de()},2e3);return()=>window.clearTimeout(a)},[yt,de,ce]);const ue=g.useCallback((a,l="overview")=>{Re(a),ye(l),We(l==="contracts"?"contracts":"overview"),J(!0)},[]),qa=g.useMemo(()=>I.map(a=>({...a,data:{...a.data,onEditRequest:()=>ue(a.id,"overview"),onContractEditRequest:()=>ue(a.id,"contracts"),onParameterEditRequest:()=>ue(a.id,"parameters")}})),[I,ue]);function W(a){be&&x(l=>l.map(p=>p.id===be?a(p):p))}function kt(a){x(l=>l.filter(p=>p.id!==a)),ne(l=>l.filter(p=>p.source!==a&&p.target!==a)),Re(l=>l===a?null:l)}async function wt(){await de()}async function jt(a){if(!await de()){Y("Forge could not save the latest flow changes before running. Fix the save error and try again.");return}const p=yn(I,T);if(p){Y(p);return}if(bt&&r.length===0){Y(["This flow includes an AI node, but no model is configured in Forge yet.","Open Settings > Models, add a model connection, then try again."].join(`
4
+
5
+ `));return}Y(null);const N={};for(const S of w){const j=mt[S.key];if(!dn(S,j)){Y(`Flow input "${S.label}" must match the ${S.kind} type.`);return}j!=null&&!(typeof j=="string"&&j.trim().length===0)&&(N[S.key]=j)}try{a==="run"?await u({userInput:ze?Le:"",inputs:N,debug:Ae}):await s({userInput:ze?Le:"",inputs:N,debug:Ae}),ke(!1)}catch(S){Y(bn(S))}}return e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsxs(Va,{to:"/workbench",className:"inline-flex h-9 items-center gap-2 rounded-full bg-[var(--ui-surface-1)] px-3 text-sm text-[var(--ui-ink-soft)] transition hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]",children:[e.jsx(Da,{className:"size-4"}),"Flows"]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx(Gt,{kind:"workbench",label:"Workbench Flow",compact:!0,gradient:!1}),e.jsx("div",{className:"truncate font-display text-[1.55rem] tracking-[-0.05em] text-[var(--ui-ink-strong)]",children:o})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(Gt,{kind:Dr(k),label:k==="chat"?"Chat flow":"Functor flow",compact:!0,gradient:!1}),e.jsx("div",{className:E("rounded-full border px-3 py-2 text-[12px]",On(He)),children:hn(He,Ma)}),ie?e.jsxs("button",{type:"button",className:"rounded-full bg-[var(--ui-surface-1)] px-3 py-2 text-[12px] text-[var(--ui-ink-soft)] transition hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]",onClick:()=>Oe(!0),children:["Latest ",ie.mode," · ",ie.status]}):null,e.jsxs(B,{type:"button",variant:"secondary",onClick:()=>ke(!0),children:[e.jsx(Ge,{className:"size-4"}),"Run"]}),e.jsxs(B,{type:"button",variant:"primary",pending:He==="saving",pendingLabel:"Saving…",onClick:()=>void wt(),children:[e.jsx(da,{className:"size-4"}),"Save now"]})]})]}),e.jsxs("div",{className:"relative h-[76vh] overflow-hidden rounded-[32px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)]",children:[$e.length>0?e.jsxs("div",{className:"pointer-events-none absolute left-4 top-4 z-20 max-w-[32rem] rounded-[24px] border border-[color-mix(in_srgb,var(--warning)_28%,transparent)] bg-[color-mix(in_srgb,var(--ui-warning-soft)_82%,var(--surface-glass))] p-4 shadow-[var(--ui-shadow-floating)] backdrop-blur-xl",children:[e.jsxs("div",{className:"pointer-events-auto flex items-center gap-2 text-[11px] uppercase tracking-[0.18em] text-[var(--warning)]",children:[e.jsx("span",{children:"Graph checks"}),e.jsx(te,{content:"These are preflight issues Forge found in the current graph before runtime. Fixing them here should prevent brittle run failures later.",label:"Explain graph checks"})]}),e.jsx("ul",{className:"mt-3 grid gap-2 text-sm leading-6 text-[var(--ui-ink-strong)]",children:$e.map(a=>e.jsx("li",{className:"list-inside list-disc",children:a},a))})]}):null,e.jsx(Kr,{nodeTypes:En,nodes:qa,edges:T,onNodesChange:a=>x(l=>Hr(a,l)),onEdgesChange:a=>ne(l=>Ar(a,l)),onConnect:a=>ne(l=>Lr({...a,id:`edge_${crypto.randomUUID().replaceAll("-","").slice(0,8)}`,style:{stroke:"color-mix(in srgb, var(--primary) 44%, transparent)",strokeWidth:1.6}},l)),onEdgeClick:(a,l)=>{ne(p=>p.filter(N=>N.id!==l.id))},onNodeClick:(a,l)=>{Re(l.id)},onNodeDoubleClick:(a,l)=>{ue(l.id,"overview")},fitView:!0,proOptions:{hideAttribution:!0},className:"bg-transparent",children:e.jsx(Mr,{color:"var(--ui-border-subtle)",gap:28})}),e.jsx("div",{className:"pointer-events-none absolute right-4 bottom-4 z-20 flex flex-col gap-2",children:e.jsxs("div",{className:"pointer-events-auto flex flex-col items-end gap-2",children:[e.jsxs("button",{type:"button",className:Ie,onClick:()=>fe(!0),children:[e.jsx(Ua,{className:"size-4"}),"Add node"]}),e.jsxs("button",{type:"button",className:Ie,onClick:()=>ut(!0),children:[e.jsx(Ga,{className:"size-4"}),"Flow settings"]}),e.jsxs("button",{type:"button",className:Ie,onClick:()=>ke(!0),children:[e.jsx(Ge,{className:"size-4"}),"Run flow"]}),ie?e.jsxs("button",{type:"button",className:Ie,onClick:()=>Oe(!0),children:[e.jsx(Qa,{className:"size-4"}),"Latest trace"]}):null]})})]}),e.jsx(In,{open:Ia,onOpenChange:fe,boxQuery:Ke,onBoxQueryChange:Ra,boxOptions:La,boxFilters:Me,onBoxFiltersChange:Wa,filteredBoxes:Aa,onAddNodeType:a=>{x(l=>[...l,Jt(a,l)]),fe(!1)},onAddBox:a=>{x(l=>[...l,Jt("box",l,a)]),fe(!1)}}),b&&he(b.data.nodeType)?e.jsx(qr,{open:dt,onOpenChange:a=>{J(a),a||We(void 0)},eyebrow:`Workbench · ${b.data.nodeType==="chat"?"Chat node":"Functor node"}`,title:b.data.label??"Edit node",description:"Configure this AI node with the same paged editor Forge uses elsewhere.",value:b.data,onChange:a=>W(l=>({...l,data:a})),draftPersistenceKey:`workbench.ai-node.${b.id}`,steps:Ha,initialStepId:Pa,onSubmit:async()=>{J(!1),We(void 0)},submitLabel:"Done",contentClassName:"md:w-[min(60rem,calc(100vw-1.5rem))]"}):e.jsx(ge,{open:dt,onOpenChange:a=>{J(a),a||ye("overview")},title:(b==null?void 0:b.data.label)??"Edit node",description:"Edit the selected node without covering the graph with permanent forms.",children:b?e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:"flex flex-wrap gap-2 rounded-full bg-[var(--ui-surface-1)] p-1",children:[{id:"overview",label:"Overview"},{id:"contracts",label:"Contracts"},{id:"parameters",label:"Parameters"}].filter(a=>a.id!=="contracts"||ft).filter(a=>{var l;return a.id!=="parameters"||(((l=b.data.params)==null?void 0:l.length)??0)>0}).map(a=>e.jsx("button",{type:"button",className:E("rounded-full px-3 py-2 text-sm transition",ve===a.id?"bg-[var(--ui-accent-soft)] text-[var(--ui-ink-strong)]":"text-[var(--ui-ink-soft)] hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]"),onClick:()=>ye(a.id),children:a.label},a.id))}),ve==="overview"?e.jsxs("div",{className:"grid gap-3",children:[e.jsx("input",{value:b.data.label,onChange:a=>W(l=>({...l,data:{...l.data,label:a.target.value}})),className:y}),e.jsx("textarea",{rows:3,value:b.data.description,onChange:a=>W(l=>({...l,data:{...l.data,description:a.target.value}})),className:y}),b.data.nodeType==="box"||b.data.nodeType==="box_input"?e.jsxs("select",{value:b.data.boxId??"",onChange:a=>{const l=n.find(p=>p.id===a.target.value);W(p=>({...p,data:{...p.data,boxId:a.target.value,label:(l==null?void 0:l.title)??p.data.label,description:(l==null?void 0:l.description)??p.data.description,inputs:(l==null?void 0:l.inputs)??[],outputs:(l==null?void 0:l.output)??[],params:(l==null?void 0:l.params)??[],enabledToolKeys:((l==null?void 0:l.tools)??[]).map(N=>N.key)}}))},className:y,children:[e.jsx("option",{value:"",children:"Select Forge box"}),n.map(a=>e.jsx("option",{value:a.id,children:a.title},a.id))]}):null,b.data.nodeType==="template"?e.jsx("textarea",{rows:4,value:b.data.template??"",onChange:a=>W(l=>({...l,data:{...l.data,template:a.target.value}})),placeholder:"Template string",className:y}):null,b.data.nodeType==="pick_key"?e.jsx("input",{value:b.data.selectedKey??"",onChange:a=>W(l=>({...l,data:{...l.data,selectedKey:a.target.value}})),placeholder:"Key to select from object input",className:y}):null,b.data.nodeType==="output"?e.jsxs("div",{className:"grid gap-3",children:[e.jsx("select",{value:b.data.outputKey??"answer",onChange:a=>W(l=>({...l,data:{...l.data,outputKey:a.target.value}})),className:y,children:vt.length>0?vt.map(a=>e.jsxs("option",{value:a.key,children:[a.label," (",a.key,")"]},a.key)):e.jsx("option",{value:b.data.outputKey??"answer",children:b.data.outputKey??"answer"})}),e.jsx("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-3 text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Publish one upstream output as the flow result. If the output key is missing from the graph, Forge will flag it in graph checks."})]}):null,b.data.nodeType==="value"?e.jsxs(e.Fragment,{children:[e.jsx("select",{value:b.data.valueType??"string",onChange:a=>W(l=>({...l,data:{...l.data,valueType:a.target.value}})),className:y,children:["string","number","boolean","null","array","object"].map(a=>e.jsx("option",{value:a,children:a},a))}),e.jsx("textarea",{rows:4,value:b.data.valueLiteral??"",onChange:a=>W(l=>({...l,data:{...l.data,valueLiteral:a.target.value}})),placeholder:"Value literal or JSON",className:y})]}):null]}):null,ve==="contracts"?ft?e.jsxs("div",{className:"grid gap-4",children:[e.jsx(Te,{title:"Inputs",description:"Name the values this node expects so upstream wiring stays obvious.",ports:b.data.inputs??[],onChange:a=>W(l=>({...l,data:{...l.data,inputs:a}})),prefix:"input"}),e.jsx(Te,{title:"Outputs",description:"Describe exactly what this node publishes, including semantic model names.",ports:b.data.outputs??[],onChange:a=>W(l=>({...l,data:{...l.data,outputs:a}})),prefix:"output"})]}):e.jsx("div",{className:"rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4 text-sm leading-6 text-[var(--ui-ink-soft)]",children:"This node inherits its contract from the registered Forge box. Edit the box definition in the registry when the contract itself needs to change."}):null,ve==="parameters"?e.jsxs("div",{className:"grid gap-3",children:[(b.data.params??[]).length===0?e.jsx("div",{className:"rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4 text-sm leading-6 text-[var(--ui-ink-soft)]",children:"This node does not expose any configurable parameters."}):null,(b.data.params??[]).map(a=>{var l,p,N;return e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:a.label}),a.kind==="boolean"?e.jsxs("label",{className:"flex items-center gap-3 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-code-bg)] px-4 py-3 text-sm text-[var(--ui-ink-strong)]",children:[e.jsx("input",{type:"checkbox",checked:!!((l=b.data.paramValues)!=null&&l[a.key]),onChange:S=>W(j=>({...j,data:{...j.data,paramValues:{...j.data.paramValues??{},[a.key]:S.target.checked}}}))}),a.description??"Enabled"]}):a.kind==="array"||a.kind==="json"?e.jsx("textarea",{value:Pe((p=b.data.paramValues)==null?void 0:p[a.key]),onChange:S=>W(j=>({...j,data:{...j.data,paramValues:{...j.data.paramValues??{},[a.key]:S.target.value}}})),placeholder:a.description??a.label,className:E(y,"min-h-[104px] resize-y")}):e.jsx("input",{type:a.kind==="number"?"number":"text",value:Pe((N=b.data.paramValues)==null?void 0:N[a.key]),onChange:S=>W(j=>({...j,data:{...j.data,paramValues:{...j.data.paramValues??{},[a.key]:va(a.kind,S.target.value)}}})),placeholder:a.description??a.label,className:y})]},a.key)})]}):null,e.jsxs("div",{className:"flex flex-wrap justify-between gap-2 pt-2",children:[e.jsxs(B,{type:"button",variant:"secondary",onClick:()=>{kt(b.id),J(!1)},children:[e.jsx(Ue,{className:"size-4"}),"Delete node"]}),e.jsx(B,{type:"button",variant:"primary",onClick:()=>{J(!1),ye("overview")},children:"Done"})]})]}):null}),e.jsx(Pn,{open:Ba,onOpenChange:ut,title:o,onTitleChange:m,description:h,onDescriptionChange:f,kind:k,onKindChange:v,publicInputs:w,onPublicInputsChange:F,nodes:I,flowId:t.id,onDelete:d,onSave:wt}),e.jsx(Bn,{open:Fa,onOpenChange:a=>{ke(a),a&&Y(null)},runError:Ka,graphIssues:$e,hasAiNodes:bt,modelConnectionCount:r.length,publicInputs:w,runInputs:mt,onRunInputChange:(a,l)=>pt(p=>({...p,[a]:l})),shouldShowLegacyUserInput:ze,userInput:Le,onUserInputChange:Ea,debugEnabled:Ae,onDebugEnabledChange:Oa,onRun:()=>void jt("run"),onChat:()=>void jt("chat"),runs:i}),e.jsx(ge,{open:Ee,onOpenChange:Oe,title:"Run inspector",description:"Inspect whole-flow outputs and stable node-level results for any saved run.",children:Z?e.jsx("div",{className:"grid gap-4",children:e.jsxs("div",{className:"grid gap-3 md:grid-cols-[0.9fr_1.1fr]",children:[e.jsxs("div",{className:"rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Run history"}),e.jsx("div",{className:"mt-3 grid gap-2",children:i.slice(0,12).map(a=>{var l;return e.jsxs("button",{type:"button",className:E("rounded-[18px] border px-4 py-3 text-left transition",ae===a.id?"border-[var(--secondary)]/40 bg-[var(--secondary)]/12":"border-[var(--ui-border-subtle)] bg-[var(--ui-code-bg)] hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-hover)]"),onClick:()=>ht(a.id),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 text-[12px] text-[var(--ui-ink-soft)]",children:[e.jsx("span",{children:a.mode}),e.jsx("span",{children:new Date(a.createdAt).toLocaleString()})]}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-medium)]",children:((l=a.result)==null?void 0:l.primaryText)??a.error??"No output yet."})]},a.id)})})]}),e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("div",{className:"rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 text-[12px] text-[var(--ui-ink-soft)]",children:[e.jsx("span",{children:Z.mode}),e.jsx("span",{children:new Date(Z.createdAt).toLocaleString()})]}),e.jsx("div",{className:"mt-3 text-sm leading-6 text-[var(--ui-ink-medium)]",children:((_t=Z.result)==null?void 0:_t.primaryText)??Z.error??"No output yet."}),(Tt=Z.result)!=null&&Tt.outputs?e.jsxs("details",{className:"mt-3 rounded-[16px] bg-[var(--ui-code-bg)] p-3",children:[e.jsx("summary",{className:"cursor-pointer text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Published outputs"}),e.jsx("pre",{className:"mt-3 overflow-auto whitespace-pre-wrap text-[12px] leading-5 text-[var(--ui-code-text)]",children:JSON.stringify(Z.result.outputs,null,2)})]}):null]}),(((It=se.data)==null?void 0:It.nodeResults)??[]).length>0?e.jsxs("div",{className:"grid gap-3 xl:grid-cols-[0.9fr_1.1fr]",children:[e.jsxs("div",{className:"rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Node results"}),e.jsx("div",{className:"mt-3 grid gap-2",children:(((Pt=se.data)==null?void 0:Pt.nodeResults)??[]).map(a=>e.jsx("button",{type:"button",className:E("rounded-[18px] border px-4 py-3 text-left transition",je===a.nodeId?"border-[var(--secondary)]/40 bg-[var(--secondary)]/12":"border-[var(--ui-border-subtle)] bg-[var(--ui-code-bg)] hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-hover)]"),onClick:()=>gt(a.nodeId),children:e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-strong)]",children:a.label}),e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:a.nodeType})]}),e.jsxs("div",{className:"rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-3 py-1 text-[11px] text-[var(--ui-ink-soft)]",children:[Object.keys(a.outputMap).length," outputs"]})]})},a.nodeId))})]}),e.jsx("div",{className:"rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:z||(Ft=V.data)!=null&&Ft.nodeResult?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-[var(--ui-ink-strong)]",children:(Rt=((Bt=V.data)==null?void 0:Bt.nodeResult)??z)==null?void 0:Rt.label}),e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:(Et=((Wt=V.data)==null?void 0:Wt.nodeResult)??z)==null?void 0:Et.nodeType})]}),e.jsxs("div",{className:"rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-3 py-1 text-[11px] text-[var(--ui-ink-soft)]",children:[(((Kt=((Ot=V.data)==null?void 0:Ot.nodeResult)??z)==null?void 0:Kt.tools)??[]).length," ","tool",(((Lt=((Mt=V.data)==null?void 0:Mt.nodeResult)??z)==null?void 0:Lt.tools)??[]).length===1?"":"s"]})]}),e.jsxs("div",{className:"mt-3 grid gap-3",children:[e.jsxs("details",{className:"rounded-[16px] bg-[var(--ui-code-bg)] p-3",children:[e.jsx("summary",{className:"cursor-pointer text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Inputs"}),e.jsx("pre",{className:"mt-3 overflow-auto whitespace-pre-wrap text-[12px] leading-5 text-[var(--ui-code-text)]",children:JSON.stringify(((Ht=((At=V.data)==null?void 0:At.nodeResult)??z)==null?void 0:Ht.input)??[],null,2)})]}),e.jsxs("details",{className:"rounded-[16px] bg-[var(--ui-code-bg)] p-3",children:[e.jsx("summary",{className:"cursor-pointer text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Output map"}),e.jsx("pre",{className:"mt-3 overflow-auto whitespace-pre-wrap text-[12px] leading-5 text-[var(--ui-code-text)]",children:JSON.stringify((($t=((qt=V.data)==null?void 0:qt.nodeResult)??z)==null?void 0:$t.outputMap)??{},null,2)})]}),e.jsxs("details",{className:"rounded-[16px] bg-[var(--ui-code-bg)] p-3",children:[e.jsx("summary",{className:"cursor-pointer text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Payload"}),e.jsx("pre",{className:"mt-3 overflow-auto whitespace-pre-wrap text-[12px] leading-5 text-[var(--ui-code-text)]",children:JSON.stringify(((Vt=((zt=V.data)==null?void 0:zt.nodeResult)??z)==null?void 0:Vt.payload)??null,null,2)})]})]})]}):e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Pick a node result to inspect its resolved inputs and outputs."})})]}):e.jsx("div",{className:"rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4 text-sm text-[var(--ui-ink-soft)]",children:se.isFetching?"Loading node results…":"This run does not have stored node results yet."})]})]})}):e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Run the flow once to inspect its published outputs and node-level results here."})})]})}function ni(){const t=Ja(),n=Ya(),r=t.flowId??"",i=ln(),c=Ur(r,{skip:r.length===0}),d=Gr(),[u]=Qr(),[s]=Jr(),[o]=Yr(),[m]=Xr();return c.isLoading||d.isLoading?e.jsx(Zr,{eyebrow:"Workbench Flow",title:"Loading flow",description:"Preparing the Workbench graph editor."}):c.isError||d.isError||!c.data?!c.data&&!c.isError&&!d.isError?e.jsx(es,{eyebrow:"Workbench Flow",title:"Flow unavailable",description:"Forge could not find that flow."}):e.jsx(ts,{eyebrow:"Workbench Flow",error:c.error??d.error??null}):e.jsxs("div",{className:"grid gap-5",children:[e.jsx(Za,{entityKind:c.data.flow.kind,title:c.data.flow.title,titleText:c.data.flow.title,description:c.data.flow.description||"Inspect, run, and publish this Workbench flow.",badge:c.data.flow.kind,actions:e.jsx(Xa,{entityType:"workbench_flow",entityId:c.data.flow.id})}),e.jsx(Kn,{flow:c.data.flow,boxes:i,modelConnections:(d.data.settings.modelSettings.connections??[]).map(h=>({id:h.id,label:h.label,provider:h.provider,model:h.model,baseUrl:h.baseUrl})),runs:c.data.runs,onSave:async h=>{await u({flowId:r,patch:h}).unwrap()},onDelete:async()=>{await s(r).unwrap(),n("/workbench")},onRun:async h=>{await o({flowId:r,input:h}).unwrap()},onChat:async h=>{await m({flowId:r,input:h}).unwrap()}})]})}export{ni as WorkbenchFlowPage};
@@ -0,0 +1 @@
1
+ import{b6 as v,bY as j,r as o,j as t}from"./vendor-Cpmju3nw.js";import{j as S,i as N,k as F}from"./state-BtwEvpO6.js";import{F as C}from"./faceted-token-search-D4Okr-Kr.js";import{P as I}from"./page-hero-DlHEJ0Yt.js";import{B as m,b as Q,eD as W,eE as K,eF as $}from"./index-BejvcRGb.js";import"./motion-DwjmC9aq.js";import"./ui-B9O-eUim.js";import"./board-CLOHbg6t.js";import"./forms-C5d5hTf2.js";function L(){var h;const l=v(),p=S(),[f]=j(),b=f.get("surface"),[i,g]=o.useState(""),[c,w]=o.useState([]),x=N({queryKey:["forge-workbench-flows"],queryFn:$}),d=F({mutationFn:e=>K({title:e==="chat"?"New chat flow":"New flow",description:e==="chat"?"Conversational workbench flow.":"Reusable workbench transformation flow.",kind:e,homeSurfaceId:b}),onSuccess:({flow:e})=>{p.invalidateQueries({queryKey:["forge-workbench-flows"]}),l(`/workbench/${e.id}`)}}),a=((h=x.data)==null?void 0:h.flows)??[],y=o.useMemo(()=>{const e=[{id:"kind:functor",label:"Functor",description:"Single transformation flows"},{id:"kind:chat",label:"Chat",description:"Conversational flows with user input"}],r=Array.from(new Set(a.map(s=>s.homeSurfaceId).filter(s=>!!s))).map(s=>({id:`surface:${s}`,label:s,description:"Home surface"}));return[...e,...r]},[a]),u=o.useMemo(()=>{const e=i.trim().toLowerCase();return a.filter(r=>{const s=e.length===0||[r.title,r.description,r.kind,r.homeSurfaceId??"",...r.graph.nodes.map(n=>n.data.label)].join(" ").toLowerCase().includes(e),k=c.every(n=>n.startsWith("kind:")?r.kind===n.replace("kind:",""):n.startsWith("surface:")?r.homeSurfaceId===n.replace("surface:",""):!0);return s&&k})},[a,i,c]);return t.jsxs("div",{className:"grid gap-5",children:[t.jsx(I,{entityKind:"workbench",title:"Workbench",titleText:"Workbench",description:"Search and launch reusable Forge flows, then open a flow to edit its graph, tools, prompts, and outputs.",badge:`${a.length} flows`}),t.jsxs("div",{className:"flex flex-wrap gap-2",children:[t.jsx(m,{type:"button",variant:"primary",onClick:()=>void d.mutateAsync("functor"),children:"New flow"}),t.jsx(m,{type:"button",variant:"secondary",onClick:()=>void d.mutateAsync("chat"),children:"New chat flow"})]}),t.jsx(C,{title:"Flow search",description:"Filter by flow kind or surface, then open a flow to edit or run it.",query:i,onQueryChange:g,options:y,selectedOptionIds:c,onSelectedOptionIdsChange:w,resultSummary:`${u.length} of ${a.length} flows`,placeholder:"Search flow title, description, nodes, or home surface"}),t.jsx("div",{className:"grid gap-3 lg:grid-cols-2",children:u.map(e=>t.jsxs("button",{type:"button",className:"min-w-0 rounded-[26px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-5 text-left transition hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-hover)]",onClick:()=>l(`/workbench/${e.id}`),children:[t.jsxs("div",{className:"flex items-start justify-between gap-4",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"truncate text-lg font-semibold text-[var(--ui-ink-strong)]",children:e.title}),t.jsx("div",{className:"mt-1 line-clamp-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:e.description||"No description yet."})]}),t.jsx(Q,{kind:W(e.kind),label:e.kind==="chat"?"Chat flow":"Functor flow",compact:!0,gradient:!1})]}),t.jsxs("div",{className:"mt-4 flex min-w-0 flex-wrap gap-2 text-[12px] text-[var(--ui-ink-faint)]",children:[t.jsxs("span",{className:"min-w-0 break-words",children:[e.graph.nodes.length," nodes"]}),t.jsxs("span",{className:"min-w-0 break-words",children:[e.graph.edges.length," edges"]}),e.homeSurfaceId?t.jsx("span",{className:"min-w-0 break-words",children:e.homeSurfaceId}):null]})]},e.id))})]})}export{L as WorkbenchPage};
@@ -0,0 +1,2 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/maps-D0Mm6WPG.js","assets/vendor-Cpmju3nw.js","assets/vendor-CRS-psbw.css","assets/maps-B-YMMjus.css"])))=>i.map(i=>d[i]);
2
+ import{S as B,e as D,k as j,C as c,T as H,I as P,B as E,e3 as I,e1 as K,e4 as W}from"./index-BejvcRGb.js";import{c6 as Q,r as h,j as e,aC as O,cL as q,bs as Z,bB as Y,dw as G,cm as U}from"./vendor-Cpmju3nw.js";import{j as V,i as X,k as J}from"./state-BtwEvpO6.js";import"./maps-D0Mm6WPG.js";import{P as ee}from"./page-hero-DlHEJ0Yt.js";import{R as C,A as te,C as ae,X as T,Y as _,T as z,a as se,e as ie,B as re}from"./charts-DwTguE_x.js";import"./motion-DwjmC9aq.js";import"./ui-B9O-eUim.js";import"./board-CLOHbg6t.js";import"./forms-C5d5hTf2.js";const A={below_z1:"#94a3b8",zone_1:"#38bdf8",zone_2:"#22c55e",zone_3:"#eab308",zone_4:"#f97316",zone_5:"#ef4444"};function k(t){return t?`${Math.round(t/60)}m`:"0m"}function F(t,s){const o=new Intl.DateTimeFormat(void 0,{weekday:"short",day:"numeric",month:"short"}),n=new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"});return`${o.format(new Date(t))} · ${n.format(new Date(t))} - ${n.format(new Date(s))}`}function $(t){const s=typeof t=="number"?Math.floor(t):Number.parseFloat(String(t??""));return Number.isFinite(s)?new Date(s).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):""}function ne(t,s){if(typeof t=="number"){const o=Number.isInteger(t)?String(t):t.toFixed(1);return s&&s!=="count"?`${o} ${s}`:o}return typeof t=="boolean"?t?"Yes":"No":t==null?"n/a":String(t)}function oe(t){return t.length===0?null:{minLat:Math.min(...t.map(s=>s.latitude)),maxLat:Math.max(...t.map(s=>s.latitude)),minLon:Math.min(...t.map(s=>s.longitude)),maxLon:Math.max(...t.map(s=>s.longitude))}}function le({points:t}){var g;const s=h.useRef(null),[o,n]=h.useState(!1),u=typeof window<"u"?((g=window.localStorage.getItem("forge.map.tile-url"))==null?void 0:g.trim())??"":"";h.useEffect(()=>{let x=!1,i=null;if(!u||!s.current||t.length<2){n(!1);return}return I(()=>import("./maps-D0Mm6WPG.js").then(r=>r.m),__vite__mapDeps([0,1,2,3])).then(r=>{x||!s.current||(i=new r.Map({container:s.current,style:{version:8,sources:{tiles:{type:"raster",tiles:[u],tileSize:256}},layers:[{id:"tiles",type:"raster",source:"tiles"}]},center:[t[0].longitude,t[0].latitude],zoom:13,attributionControl:!1}),i.on("load",()=>{if(!i)return;const d=t.map(m=>[m.longitude,m.latitude]);i.addSource("route",{type:"geojson",data:{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:d}}}),i.addLayer({id:"route",type:"line",source:"route",paint:{"line-color":"#f97316","line-width":4}});const f=d.reduce((m,p)=>m.extend(p),new r.LngLatBounds(d[0],d[0]));i.fitBounds(f,{padding:44,maxZoom:15}),n(!0)}))}),()=>{x=!0,i==null||i.remove()}},[t,u]);const l=oe(t),v=h.useMemo(()=>{if(!l||t.length<2)return"";const x=720,i=280,r=Math.max(1e-6,l.maxLon-l.minLon),d=Math.max(1e-6,l.maxLat-l.minLat);return t.map(f=>{const m=(f.longitude-l.minLon)/r*x,p=i-(f.latitude-l.minLat)/d*i;return`${m.toFixed(1)},${p.toFixed(1)}`}).join(" ")},[l,t]);return e.jsxs("div",{className:"relative min-h-[280px] overflow-hidden rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)]",children:[e.jsx("div",{ref:s,className:"absolute inset-0"}),o?null:e.jsxs("svg",{viewBox:"0 0 720 280",className:"absolute inset-0 h-full w-full",children:[e.jsx("rect",{width:"720",height:"280",fill:"var(--ui-surface-1)"}),v?e.jsx("polyline",{points:v,fill:"none",stroke:"#f97316",strokeWidth:"5",strokeLinecap:"round",strokeLinejoin:"round"}):null]}),e.jsx("div",{className:"absolute left-3 top-3 max-w-[calc(100%-1.5rem)] rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--surface-glass)] px-3 py-2 text-xs text-[var(--ui-ink-medium)] backdrop-blur",children:u?"Local-first map tiles configured":"No tile source configured; showing private route shape only"})]})}function de({zones:t}){return e.jsx("div",{className:"grid gap-3",children:t.map(s=>e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 text-sm",children:[e.jsx("span",{className:"min-w-0 break-words text-[var(--ui-ink-medium)] [overflow-wrap:anywhere]",children:s.label}),e.jsxs("span",{className:"shrink-0 text-[var(--ui-ink-strong)]",children:[(s.percentage*100).toFixed(1),"% · ",k(s.seconds)]})]}),e.jsx("div",{className:"h-2 overflow-hidden rounded-full bg-[var(--ui-surface-2)]",children:e.jsx("div",{className:"h-full rounded-full",style:{width:`${Math.max(1,s.percentage*100)}%`,background:A[s.key]??"#f8fafc"}})})]},s.key))})}function we(){var p,y,N,b,S,L,R,M;const{workoutId:t=""}=Q(),s=V(),o=X({queryKey:["workout-detail",t],queryFn:()=>W(t),enabled:t.length>0}),n=o.data,[u,l]=h.useState(""),[v,g]=h.useState("");h.useEffect(()=>{n!=null&&n.workout&&(l(n.workout.meaningText??""),g(n.workout.tags.join(", ")))},[n==null?void 0:n.workout]);const x=J({mutationFn:()=>K(t,{meaningText:u,tags:v.split(",").map(a=>a.trim()).filter(Boolean)}),onSuccess:async()=>{await s.invalidateQueries({queryKey:["workout-detail",t]}),await s.invalidateQueries({queryKey:["forge-fitness"]})}});if(o.isLoading)return e.jsx(B,{title:"Loading workout"});if(o.isError||!n)return e.jsx(D,{eyebrow:"Workout detail",error:o.error??new Error("Forge could not load this workout detail."),onRetry:()=>void o.refetch()});const{workout:i,analytics:r,evidence:d}=n,f=d.timeSeries.filter(a=>a.metricKey==="heart_rate").map((a,w)=>({time:Date.parse(a.startedAt)+w/1e3,bpm:a.value})),m=r.zoneDurations.map(a=>({zone:a.label,minutes:Math.round(a.seconds/60),fill:A[a.key]??"#f8fafc"}));return e.jsxs("div",{className:"grid gap-6",children:[e.jsxs(O,{to:"/sports",className:"inline-flex w-fit items-center gap-2 text-sm text-[var(--ui-ink-soft)] transition hover:text-[var(--ui-ink-strong)]",children:[e.jsx(q,{className:"size-4"}),"Back to sports"]}),e.jsx(ee,{eyebrow:"Workout evidence",title:i.workoutTypeLabel??i.workoutType,description:`${F(i.startedAt,i.endedAt)} · ${i.sourceDevice||"Apple Health"}`,actions:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(j,{children:k(i.durationSeconds)}),e.jsxs(j,{tone:"meta",children:[r.confidence," HR zones"]}),(p=r.routeSummary)!=null&&p.hasRoute?e.jsxs(j,{tone:"meta",children:[r.routeSummary.pointCount," route points"]}):null]})}),e.jsxs("section",{className:"grid gap-4 lg:grid-cols-4",children:[e.jsxs(c,{children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Avg HR"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:r.hrSummary.averageHr??i.averageHeartRate??"n/a"}),e.jsx("div",{className:"mt-1 text-sm text-[var(--ui-ink-faint)]",children:"bpm"})]}),e.jsxs(c,{children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Max HR"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:r.hrSummary.maxHr??i.maxHeartRate??"n/a"}),e.jsx("div",{className:"mt-1 text-sm text-[var(--ui-ink-faint)]",children:"bpm"})]}),e.jsxs(c,{children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Training load"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:r.load.trimp??"n/a"}),e.jsx("div",{className:"mt-1 text-sm text-[var(--ui-ink-faint)]",children:"Forge TRIMP"})]}),e.jsxs(c,{children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"HR coverage"}),e.jsxs("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:[Math.round((r.dataQuality.sampleCoverage??0)*100),"%"]}),e.jsxs("div",{className:"mt-1 text-sm text-[var(--ui-ink-faint)]",children:[r.dataQuality.heartRateSampleCount??0," samples"]})]})]}),e.jsxs("section",{className:"grid min-w-0 gap-4 xl:grid-cols-[minmax(0,1.25fr)_minmax(280px,0.75fr)]",children:[e.jsxs(c,{className:"min-h-[360px] min-w-0 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[var(--ui-ink-strong)]",children:[e.jsx(Z,{className:"size-4 text-[var(--primary)]"}),"Heart-rate timeline"]}),e.jsx("div",{className:"mt-4 h-[300px]",children:f.length>0?e.jsx(C,{width:"100%",height:"100%",children:e.jsxs(te,{data:f,children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"hrFill",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:"#ef4444",stopOpacity:.38}),e.jsx("stop",{offset:"100%",stopColor:"#ef4444",stopOpacity:.04})]})}),e.jsx(ae,{stroke:"var(--ui-border-subtle)",vertical:!1}),e.jsx(T,{dataKey:"time",interval:"preserveStartEnd",tick:{fill:"var(--ui-ink-soft)",fontSize:11},tickFormatter:$,type:"number",domain:["dataMin","dataMax"]}),e.jsx(_,{tick:{fill:"var(--ui-ink-soft)",fontSize:11},width:42}),e.jsx(z,{labelFormatter:$,contentStyle:{background:"var(--surface-glass)",border:"1px solid var(--ui-border-subtle)",borderRadius:8,color:"var(--ui-ink-strong)"}}),e.jsx(se,{type:"monotone",dataKey:"bpm",stroke:"#ef4444",fill:"url(#hrFill)",strokeWidth:2,dot:!1})]})}):e.jsx("div",{className:"grid h-full place-items-center rounded-[8px] bg-[var(--ui-surface-1)] text-sm text-[var(--ui-ink-soft)]",children:"No raw HR timeline has been synced for this workout yet."})})]}),e.jsxs(c,{className:"min-w-0 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[var(--ui-ink-strong)]",children:[e.jsx(Y,{className:"size-4 text-[var(--primary)]"}),"Zone mix"]}),e.jsx("div",{className:"mt-4",children:e.jsx(de,{zones:r.zoneDurations})}),e.jsx("div",{className:"mt-5 h-[180px]",children:e.jsx(C,{width:"100%",height:"100%",children:e.jsxs(ie,{data:m,children:[e.jsx(T,{dataKey:"zone",tick:{fill:"var(--ui-ink-soft)",fontSize:10}}),e.jsx(_,{tick:{fill:"var(--ui-ink-soft)",fontSize:10},width:34}),e.jsx(z,{contentStyle:{background:"var(--surface-glass)",border:"1px solid var(--ui-border-subtle)",borderRadius:8,color:"var(--ui-ink-strong)"}}),e.jsx(re,{dataKey:"minutes",radius:[4,4,0,0]})]})})})]})]}),e.jsxs("section",{className:"grid min-w-0 gap-4 xl:grid-cols-[minmax(0,1fr)_360px]",children:[e.jsxs(c,{className:"min-w-0 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[var(--ui-ink-strong)]",children:[e.jsx(G,{className:"size-4 text-[var(--primary)]"}),"Route"]}),e.jsx("div",{className:"mt-4",children:d.routePoints.length>1?e.jsx(le,{points:d.routePoints}):e.jsx("div",{className:"grid min-h-[240px] place-items-center rounded-[8px] bg-[var(--ui-surface-1)] text-sm text-[var(--ui-ink-soft)]",children:"No route evidence is available for this workout."})})]}),e.jsxs(c,{className:"min-w-0 overflow-hidden",children:[e.jsx("div",{className:"text-[var(--ui-ink-strong)]",children:"Captured metrics"}),e.jsx("div",{className:"mt-4 grid gap-3",children:(((y=i.details)==null?void 0:y.metrics)??[]).slice(0,14).map(a=>e.jsxs("div",{className:"min-w-0 rounded-[8px] bg-[var(--ui-surface-1)] px-3 py-2",children:[e.jsx("div",{className:"break-words text-sm text-[var(--ui-ink-soft)] [overflow-wrap:anywhere]",children:a.label}),e.jsx("div",{className:"mt-1 break-words text-[var(--ui-ink-strong)] [overflow-wrap:anywhere]",children:ne(a.value,a.unit)})]},`${a.category}:${a.key}:${a.statistic}`))})]})]}),e.jsxs("section",{className:"grid min-w-0 gap-4 lg:grid-cols-[minmax(0,1fr)_minmax(280px,0.7fr)]",children:[e.jsxs(c,{className:"min-w-0 overflow-hidden",children:[e.jsx("div",{className:"text-[var(--ui-ink-strong)]",children:"Events and phases"}),e.jsxs("div",{className:"mt-4 grid gap-3",children:[[...((N=i.details)==null?void 0:N.events)??[],...((b=i.details)==null?void 0:b.components)??[]].slice(0,18).map((a,w)=>e.jsxs("div",{className:"min-w-0 rounded-[8px] bg-[var(--ui-surface-1)] px-4 py-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx("div",{className:"min-w-0 break-words text-[var(--ui-ink-strong)] [overflow-wrap:anywhere]",children:"label"in a?a.label:a.activity.canonicalLabel}),e.jsx(j,{tone:"meta",children:k(a.durationSeconds)})]}),e.jsx("div",{className:"mt-1 text-sm text-[var(--ui-ink-soft)]",children:F(a.startedAt,a.endedAt??a.startedAt)})]},`${"type"in a?a.type:a.externalUid}:${a.startedAt}:${w}`)),(((L=(S=i.details)==null?void 0:S.events)==null?void 0:L.length)??0)+(((M=(R=i.details)==null?void 0:R.components)==null?void 0:M.length)??0)===0?e.jsx("div",{className:"rounded-[8px] bg-[var(--ui-surface-1)] p-4 text-sm text-[var(--ui-ink-soft)]",children:"No provider events or phases were captured."}):null]})]}),e.jsxs(c,{className:"min-w-0 overflow-hidden",children:[e.jsx("div",{className:"text-[var(--ui-ink-strong)]",children:"Reflection"}),e.jsxs("div",{className:"mt-4 grid gap-4",children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Meaning and impact"}),e.jsx(H,{className:"min-h-[160px]",value:u,onChange:a=>l(a.target.value)})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Tags"}),e.jsx(P,{value:v,onChange:a=>g(a.target.value)})]}),e.jsxs(E,{type:"button",pending:x.isPending,pendingLabel:"Saving",onClick:()=>x.mutate(),children:[e.jsx(U,{className:"size-4"}),"Save reflection"]})]})]})]})]})}export{we as WorkoutDetailPage};
package/dist/index.html CHANGED
@@ -130,17 +130,15 @@
130
130
  }
131
131
  }
132
132
  </style>
133
- <script type="module" crossorigin src="/forge/assets/index-QJkjKYzZ.js"></script>
134
- <link rel="modulepreload" crossorigin href="/forge/assets/vendor-Dnkkx2co.js">
135
- <link rel="modulepreload" crossorigin href="/forge/assets/state-vCcAT5Hq.js">
136
- <link rel="modulepreload" crossorigin href="/forge/assets/motion-Lt5B1XuE.js">
137
- <link rel="modulepreload" crossorigin href="/forge/assets/ui-C1iwpj2-.js">
138
- <link rel="modulepreload" crossorigin href="/forge/assets/forms-hB0SqEh-.js">
139
- <link rel="modulepreload" crossorigin href="/forge/assets/board-dIX6etHh.js">
140
- <link rel="modulepreload" crossorigin href="/forge/assets/graph-DDUZNRsO.js">
133
+ <script type="module" crossorigin src="/forge/assets/index-BejvcRGb.js"></script>
134
+ <link rel="modulepreload" crossorigin href="/forge/assets/vendor-Cpmju3nw.js">
135
+ <link rel="modulepreload" crossorigin href="/forge/assets/state-BtwEvpO6.js">
136
+ <link rel="modulepreload" crossorigin href="/forge/assets/motion-DwjmC9aq.js">
137
+ <link rel="modulepreload" crossorigin href="/forge/assets/ui-B9O-eUim.js">
138
+ <link rel="modulepreload" crossorigin href="/forge/assets/board-CLOHbg6t.js">
139
+ <link rel="modulepreload" crossorigin href="/forge/assets/forms-C5d5hTf2.js">
141
140
  <link rel="stylesheet" crossorigin href="/forge/assets/vendor-CRS-psbw.css">
142
- <link rel="stylesheet" crossorigin href="/forge/assets/graph-BZV40eAE.css">
143
- <link rel="stylesheet" crossorigin href="/forge/assets/index-Bcem7l5u.css">
141
+ <link rel="stylesheet" crossorigin href="/forge/assets/index-CEgIwgk9.css">
144
142
  </head>
145
143
  <body class="bg-canvas text-ink antialiased">
146
144
  <div id="root">
@@ -6516,8 +6516,12 @@ function compactWeightLoss(weightLoss) {
6516
6516
  dateKey: weightLoss.todayLedger.dateKey,
6517
6517
  mealCount: weightLoss.todayLedger.meals.length,
6518
6518
  totals: weightLoss.todayLedger.totals,
6519
+ plannedTargetCalories: weightLoss.todayLedger.plannedTargetCalories,
6519
6520
  targetCalories: weightLoss.todayLedger.targetCalories,
6521
+ remainingCalories: weightLoss.todayLedger.remainingCalories,
6520
6522
  calorieDelta: weightLoss.todayLedger.calorieDelta,
6523
+ activeAdjustmentCalories: weightLoss.todayLedger.activeAdjustmentCalories,
6524
+ activeCaloriesSource: weightLoss.todayLedger.activeCaloriesSource,
6521
6525
  proteinCoverage: weightLoss.todayLedger.proteinCoverage,
6522
6526
  fiberCoverage: weightLoss.todayLedger.fiberCoverage,
6523
6527
  unconfirmedCount: weightLoss.todayLedger.unconfirmedCount
@@ -6525,6 +6529,12 @@ function compactWeightLoss(weightLoss) {
6525
6529
  energyModel: {
6526
6530
  estimatedTdeeKcal: weightLoss.energyModel.estimatedTdeeKcal,
6527
6531
  activeBurnKcal: weightLoss.energyModel.activeBurnKcal,
6532
+ baselineActiveCaloriesKcal: weightLoss.energyModel.baselineActiveCaloriesKcal,
6533
+ todayActiveCaloriesKcal: weightLoss.energyModel.todayActiveCaloriesKcal,
6534
+ todayActiveCaloriesSource: weightLoss.energyModel.todayActiveCaloriesSource,
6535
+ todayTargetAdjustmentKcal: weightLoss.energyModel.todayTargetAdjustmentKcal,
6536
+ todayActiveDeltaKcal: weightLoss.energyModel.todayActiveDeltaKcal,
6537
+ todayActiveOverride: weightLoss.energyModel.todayActiveOverride,
6528
6538
  movementCaloriesKcal: weightLoss.energyModel.movementCaloriesKcal,
6529
6539
  averageCalorieIntake: weightLoss.energyModel.averageCalorieIntake,
6530
6540
  estimatedDailyEnergyBalanceKcal: weightLoss.energyModel.estimatedDailyEnergyBalanceKcal,