forge-openclaw-plugin 0.3.16 → 0.3.17

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 (186) hide show
  1. package/dist/assets/{action-bar-DgrmzFrI.js → action-bar-D3CEYlj4.js} +1 -1
  2. package/dist/assets/{activity-page-CF451ueg.js → activity-page-Ce1pHIu5.js} +1 -1
  3. package/dist/assets/{ai-surface-workspace-DtwybxJB.js → ai-surface-workspace-DEliwOjF.js} +1 -1
  4. package/dist/assets/artifacts-page-BgyFVIVM.js +2 -0
  5. package/dist/assets/{atlas-panel-CB3uYk_K.js → atlas-panel-VZOnJa1c.js} +1 -1
  6. package/dist/assets/{board-CuxQRKPJ.js → board-DprRipIG.js} +1 -1
  7. package/dist/assets/{calendar-page-BYsDuLnh.js → calendar-page-Zstsn4uG.js} +1 -1
  8. package/dist/assets/{calendar-rules-DXuOv2J-.js → calendar-rules-BGIBuEDk.js} +1 -1
  9. package/dist/assets/{calendar-week-toolbar-8PJmiUE_.js → calendar-week-toolbar-DXFkMkbq.js} +1 -1
  10. package/dist/assets/{charts-BzT4pUPg.js → charts-C5S0-BL7.js} +1 -1
  11. package/dist/assets/{companion-sync-lab-page-DzWNOaBh.js → companion-sync-lab-page-DIPPLFKt.js} +1 -1
  12. package/dist/assets/{daily-metrics-dashboard-CHcYxDhs.js → daily-metrics-dashboard-CG-OOCJz.js} +1 -1
  13. package/dist/assets/{define-workbench-box-DcI0_QKW.js → define-workbench-box-BEEdtBkQ.js} +1 -1
  14. package/dist/assets/{entity-link-multiselect-C--AiCMb.js → entity-link-multiselect-BfDAROHB.js} +1 -1
  15. package/dist/assets/{entity-note-count-link-xne6mshj.js → entity-note-count-link-BGOiaash.js} +1 -1
  16. package/dist/assets/{entity-notes-surface-jy6Psist.js → entity-notes-surface-DPsJwqQa.js} +1 -1
  17. package/dist/assets/execution-board-Dg-2GSKv.js +1 -0
  18. package/dist/assets/{faceted-token-search-BMQ1Wwzt.js → faceted-token-search-DV7MSVYb.js} +1 -1
  19. package/dist/assets/{flagship-signal-deck-DjcskRwF.js → flagship-signal-deck-D3wVL3bC.js} +1 -1
  20. package/dist/assets/{floating-action-menu-cGhbJ2tc.js → floating-action-menu-BUs382px.js} +1 -1
  21. package/dist/assets/{forms-D1qJ3oOP.js → forms-ByKjodjN.js} +1 -1
  22. package/dist/assets/{generic-node-view-DNVwfqqq.js → generic-node-view-BY5dbPXJ.js} +1 -1
  23. package/dist/assets/{goal-detail-page-dAbyCilO.js → goal-detail-page-MYr6j2B4.js} +1 -1
  24. package/dist/assets/{goal-dialog-DH50D0tP.js → goal-dialog-nkdME5Uy.js} +1 -1
  25. package/dist/assets/goals-page-BsFeBzU1.js +1 -0
  26. package/dist/assets/{graph-BF4IsheG.js → graph-CHVj0Z7n.js} +1 -1
  27. package/dist/assets/habits-page-wO461EVU.js +1 -0
  28. package/dist/assets/{health-boxes-BPTgGM6G.js → health-boxes-BphMeSJj.js} +1 -1
  29. package/dist/assets/index-CSd8ylsy.css +1 -0
  30. package/dist/assets/index-gmPaoLN-.js +2 -0
  31. package/dist/assets/{inline-note-fields-D4mCM1gO.js → inline-note-fields-BvQwmMAv.js} +1 -1
  32. package/dist/assets/{insight-flow-dialog-Btp6bkbV.js → insight-flow-dialog-H_eaOmst.js} +1 -1
  33. package/dist/assets/{insights-page-1qM4mxjS.js → insights-page-DINYe3cB.js} +3 -3
  34. package/dist/assets/{kanban-boxes-u_A-UJG-.js → kanban-boxes-oACOTDYG.js} +1 -1
  35. package/dist/assets/{kanban-page-CKCa_3Qb.js → kanban-page-BGLXH91f.js} +1 -1
  36. package/dist/assets/knowledge-graph-page-VfMvw5jL.js +1 -0
  37. package/dist/assets/{life-force-page-BZlyA144.js → life-force-page-DQPb6UL-.js} +1 -1
  38. package/dist/assets/{life-force-workspace-CtAWZXNw.js → life-force-workspace-BJ1aI3JE.js} +1 -1
  39. package/dist/assets/{maps-BTVHALP8.js → maps-CvEHVkBk.js} +1 -1
  40. package/dist/assets/{metric-tile-Bkx2btO2.js → metric-tile-CbEe19Gd.js} +1 -1
  41. package/dist/assets/{motion-DcgUnXhY.js → motion-BibSzp57.js} +1 -1
  42. package/dist/assets/{movement-boxes-QZ2EIS9q.js → movement-boxes-dtDYhw5c.js} +1 -1
  43. package/dist/assets/{movement-page-B-3ihggI.js → movement-page-BhmwCHjs.js} +1 -1
  44. package/dist/assets/{note-markdown-BWedRE3c.js → note-markdown-CG8u2d6p.js} +1 -1
  45. package/dist/assets/{note-tags-input-DZkCqI1w.js → note-tags-input-D_conqDO.js} +1 -1
  46. package/dist/assets/{notes-boxes-DGFmt7Dp.js → notes-boxes-BLKucFqW.js} +1 -1
  47. package/dist/assets/notes-page-CafVxWjb.js +1 -0
  48. package/dist/assets/{open-in-graph-button-CjvkEj1P.js → open-in-graph-button-DFQ4r6SN.js} +1 -1
  49. package/dist/assets/{orbit-map-CRHSPenk.js → orbit-map-DsEl3ori.js} +1 -1
  50. package/dist/assets/overview-page-BffcX-pM.js +1 -0
  51. package/dist/assets/page-hero-U603l9rQ.js +1 -0
  52. package/dist/assets/pill-cluster-BYVFNppV.js +1 -0
  53. package/dist/assets/{preference-entity-handoff-button-CfCQl3cW.js → preference-entity-handoff-button-cPrTpHsV.js} +1 -1
  54. package/dist/assets/{preferences-page-OltGdsQ2.js → preferences-page-DQjFIOmt.js} +1 -1
  55. package/dist/assets/{project-collections-FfBIVwXu.js → project-collections-B9OGHGqm.js} +1 -1
  56. package/dist/assets/project-detail-page-r1Sw2kcO.js +1 -0
  57. package/dist/assets/{project-dialog-B_J1ESMk.js → project-dialog-B2_PcXAf.js} +1 -1
  58. package/dist/assets/project-management-hierarchy-page-qLNG8hsh.js +1 -0
  59. package/dist/assets/{project-management-section-nav-DBNHt9p5.js → project-management-section-nav-DFUlmMEB.js} +1 -1
  60. package/dist/assets/{projects-boxes-BvlVsO5q.js → projects-boxes-BA7_XaqX.js} +1 -1
  61. package/dist/assets/projects-page-B6ggXWFw.js +1 -0
  62. package/dist/assets/psyche-behaviors-page-ByWpXlLq.js +5 -0
  63. package/dist/assets/{psyche-flashcards-page-05606-97.js → psyche-flashcards-page-B9nSc0mk.js} +1 -1
  64. package/dist/assets/{psyche-goal-map-page-Cw-aqS3Y.js → psyche-goal-map-page-BQU7qI88.js} +1 -1
  65. package/dist/assets/{psyche-graph-0E22QHPe.js → psyche-graph-DCeP7r2b.js} +1 -1
  66. package/dist/assets/{psyche-metrics-page-DBFVPeMa.js → psyche-metrics-page-DD2lOP-J.js} +1 -1
  67. package/dist/assets/psyche-mode-guide-page-DbtZgnjr.js +1 -0
  68. package/dist/assets/psyche-modes-page-3zFJWFQf.js +1 -0
  69. package/dist/assets/psyche-page-D5vXYkfB.js +1 -0
  70. package/dist/assets/psyche-patterns-page-BneAAeKS.js +5 -0
  71. package/dist/assets/{psyche-questionnaire-builder-page-DEt0UDsz.js → psyche-questionnaire-builder-page-BH1la5C9.js} +1 -1
  72. package/dist/assets/{psyche-questionnaire-detail-page-BXQbOE6A.js → psyche-questionnaire-detail-page-DYav634P.js} +1 -1
  73. package/dist/assets/psyche-questionnaire-run-detail-page-9VaijhJm.js +1 -0
  74. package/dist/assets/{psyche-questionnaire-run-page-D_EokOQm.js → psyche-questionnaire-run-page-e1T6k_dS.js} +1 -1
  75. package/dist/assets/{psyche-questionnaires-page-D1Ov2L4n.js → psyche-questionnaires-page-Dyv367z9.js} +1 -1
  76. package/dist/assets/{psyche-report-detail-page-9HyPr8BJ.js → psyche-report-detail-page-hqxHIXw2.js} +3 -3
  77. package/dist/assets/psyche-reports-page-DhIfcGbt.js +1 -0
  78. package/dist/assets/{psyche-schemas-DDol0j-g.js → psyche-schemas-Cg51Ztxz.js} +1 -1
  79. package/dist/assets/psyche-schemas-beliefs-page-Dgb5o9vx.js +9 -0
  80. package/dist/assets/{psyche-screen-time-page-DJMDR5oo.js → psyche-screen-time-page-D6MnJGNa.js} +1 -1
  81. package/dist/assets/{psyche-self-observation-page-DFKXG1Yv.js → psyche-self-observation-page-C1Vyezbv.js} +1 -1
  82. package/dist/assets/{psyche-values-page-TWKth89J.js → psyche-values-page-B_JWVw1Q.js} +2 -2
  83. package/dist/assets/{question-flow-dialog-D-_EvoAt.js → question-flow-dialog-yMYVk998.js} +2 -2
  84. package/dist/assets/{report-chain-fields-Dy-jBQDn.js → report-chain-fields-D4NM9a6I.js} +1 -1
  85. package/dist/assets/rewards-page-B5-bcL4R.js +1 -0
  86. package/dist/assets/{scheduling-rules-editor-CAd290IE.js → scheduling-rules-editor-De72IUax.js} +1 -1
  87. package/dist/assets/{schema-badge-BLaVI1D7.js → schema-badge-jX28kUa6.js} +1 -1
  88. package/dist/assets/{schemas-B0Pa-V-A.js → schemas-BlFy-uPR.js} +1 -1
  89. package/dist/assets/{select-menu-DcS4Ukjf.js → select-menu-BXv1rsVc.js} +1 -1
  90. package/dist/assets/{settings-agents-page-Bt38HhEJ.js → settings-agents-page-DN_np10S.js} +1 -1
  91. package/dist/assets/settings-bin-page-BM5BpK_i.js +1 -0
  92. package/dist/assets/{settings-calendar-page-DPSSZV3s.js → settings-calendar-page-Cg0gSSFs.js} +3 -3
  93. package/dist/assets/{settings-data-page-BdHsD1C_.js → settings-data-page-Dwmp2rLy.js} +1 -1
  94. package/dist/assets/{settings-logs-page-D9OnWoFq.js → settings-logs-page-DQNM21Re.js} +1 -1
  95. package/dist/assets/{settings-mobile-page-DFpsXA4M.js → settings-mobile-page-DQdiRa-a.js} +1 -1
  96. package/dist/assets/settings-models-page-CAEPpuHF.js +1 -0
  97. package/dist/assets/{settings-page-m_3iYPwU.js → settings-page-Cl2KiCFg.js} +1 -1
  98. package/dist/assets/{settings-rewards-page-B2aBm-dA.js → settings-rewards-page-DoIUumhe.js} +1 -1
  99. package/dist/assets/{settings-section-nav-CMeU19Rx.js → settings-section-nav-D_N87IG0.js} +1 -1
  100. package/dist/assets/{settings-users-page-D8jyewJl.js → settings-users-page-CPesR62N.js} +1 -1
  101. package/dist/assets/{settings-wiki-page-DjOgQJAh.js → settings-wiki-page-BxMQM5Vi.js} +1 -1
  102. package/dist/assets/{sleep-page-D8-dA4bE.js → sleep-page-DUYmQKrg.js} +1 -1
  103. package/dist/assets/{sports-page-CK3PgPKB.js → sports-page-Bzi5TF9T.js} +1 -1
  104. package/dist/assets/{state-Bpe5dF3T.js → state-BFyKSULP.js} +1 -1
  105. package/dist/assets/{strategies-page-aFpJath-.js → strategies-page-C-T2MZx4.js} +1 -1
  106. package/dist/assets/{strategy-detail-page-CobF5qLv.js → strategy-detail-page-3tYuSZu-.js} +1 -1
  107. package/dist/assets/{strategy-dialog-Fgoaoob5.js → strategy-dialog-BWm4slo4.js} +1 -1
  108. package/dist/assets/{surface-D0dqgX-k.js → surface-BJObZeRw.js} +1 -1
  109. package/dist/assets/{table-U7otr5go.js → table-CTLroJKN.js} +1 -1
  110. package/dist/assets/task-detail-page-ZZOXSpSF.js +1 -0
  111. package/dist/assets/{task-dialog-eCDTF8xe.js → task-dialog-2wy0xI7f.js} +5 -5
  112. package/dist/assets/timebox-planning-dialog-C6h0Hp71.js +1 -0
  113. package/dist/assets/{today-boxes-CYfskVrM.js → today-boxes-B_TdgSDz.js} +1 -1
  114. package/dist/assets/today-page-Dipns9tl.js +1 -0
  115. package/dist/assets/training-load-page-B78e1-o-.js +1 -0
  116. package/dist/assets/{ui-B9TWEtCx.js → ui-uo_bNP7c.js} +1 -1
  117. package/dist/assets/{use-anchored-overlay-position-BY4kNzPj.js → use-anchored-overlay-position-BSxFX6Hi.js} +1 -1
  118. package/dist/assets/{use-psyche-focus-target-BhNedCZB.js → use-psyche-focus-target-1GLkhYiv.js} +1 -1
  119. package/dist/assets/{user-badge-MEZuJiir.js → user-badge-C4eZu1e_.js} +1 -1
  120. package/dist/assets/{user-select-field-fx129Uh6.js → user-select-field-CmKwcbZt.js} +1 -1
  121. package/dist/assets/{utility-widgets-h5eG2jvc.js → utility-widgets-B06wQFrd.js} +2 -2
  122. package/dist/assets/{vendor-BwL6m4SE.js → vendor-B7FKSwHK.js} +222 -212
  123. package/dist/assets/{vitals-page-eoFnQ3XL.js → vitals-page-BC7QFsm2.js} +1 -1
  124. package/dist/assets/{weekly-review-page-C7BU1gkK.js → weekly-review-page-BjNsNoWj.js} +1 -1
  125. package/dist/assets/{weight-loss-page-Cc7Do3XY.js → weight-loss-page-BOahGY9r.js} +1 -1
  126. package/dist/assets/{wiki-article-markdown-CCKoSptz.js → wiki-article-markdown-DO47HnZf.js} +2 -2
  127. package/dist/assets/{wiki-editor-page-BpbxZrgz.js → wiki-editor-page-OWRUHl4O.js} +5 -5
  128. package/dist/assets/{wiki-ingest-history-page-D5Wfr8pc.js → wiki-ingest-history-page-CuHpg2lZ.js} +1 -1
  129. package/dist/assets/{wiki-ingest-modal-DhRVsEwC.js → wiki-ingest-modal-EZ3kX-vA.js} +1 -1
  130. package/dist/assets/wiki-page-BPV3HIgu.js +1 -0
  131. package/dist/assets/{workbench-flow-page-y9FxDbKO.js → workbench-flow-page-C53KueEz.js} +3 -3
  132. package/dist/assets/{workbench-page-Da16AZvN.js → workbench-page-DJ7nT2JQ.js} +1 -1
  133. package/dist/assets/workout-detail-page-Dhyu0q7o.js +2 -0
  134. package/dist/index.html +8 -8
  135. package/dist/openclaw/parity.d.ts +1 -1
  136. package/dist/openclaw/parity.js +10 -0
  137. package/dist/openclaw/routes.js +78 -0
  138. package/dist/openclaw/tools.js +42 -0
  139. package/dist/server/apps/api/migrations/072_artifact_store.sql +106 -0
  140. package/dist/server/apps/api/src/app.js +364 -3
  141. package/dist/server/apps/api/src/openapi.js +570 -1
  142. package/dist/server/apps/api/src/repositories/entity-links.js +66 -0
  143. package/dist/server/apps/api/src/services/artifacts.js +1059 -0
  144. package/dist/server/apps/api/src/services/entity-crud.js +22 -0
  145. package/dist/server/apps/api/src/services/knowledge-graph.js +45 -0
  146. package/dist/server/apps/api/src/services/psyche-observation-calendar.js +1 -0
  147. package/dist/server/apps/api/src/types.js +2 -0
  148. package/dist/server/apps/web/src/lib/api.js +69 -0
  149. package/dist/server/apps/web/src/lib/entity-visuals.js +10 -1
  150. package/dist/server/apps/web/src/lib/knowledge-graph-types.js +9 -0
  151. package/openclaw.plugin.json +2 -1
  152. package/package.json +1 -1
  153. package/server/migrations/072_artifact_store.sql +106 -0
  154. package/skills/forge-openclaw/SKILL.md +57 -4
  155. package/skills/forge-openclaw/entity_conversation_playbooks.md +212 -14
  156. package/skills/forge-openclaw/psyche_entity_playbooks.md +20 -0
  157. package/dist/assets/execution-board-BSUZCIIx.js +0 -1
  158. package/dist/assets/goals-page-DkMy9mPD.js +0 -1
  159. package/dist/assets/habits-page-CCQR8rg6.js +0 -1
  160. package/dist/assets/index-VzCGTBS_.css +0 -1
  161. package/dist/assets/index-izRKx6JK.js +0 -2
  162. package/dist/assets/knowledge-graph-page-BZOxRv19.js +0 -1
  163. package/dist/assets/notes-page-DYkn04tz.js +0 -1
  164. package/dist/assets/overview-page-D6LsjPWe.js +0 -1
  165. package/dist/assets/page-hero-BLhM8FF3.js +0 -1
  166. package/dist/assets/pill-cluster-B5bYs_e2.js +0 -1
  167. package/dist/assets/project-detail-page-CCm3iZPQ.js +0 -1
  168. package/dist/assets/project-management-hierarchy-page-BNzvtNZj.js +0 -1
  169. package/dist/assets/projects-page-BUf7KV-_.js +0 -1
  170. package/dist/assets/psyche-behaviors-page-jtyhdpJ1.js +0 -5
  171. package/dist/assets/psyche-mode-guide-page-DI-LNEDT.js +0 -1
  172. package/dist/assets/psyche-modes-page-CaMupyfi.js +0 -1
  173. package/dist/assets/psyche-page-CFBq0YKf.js +0 -1
  174. package/dist/assets/psyche-patterns-page-sp4ikoef.js +0 -5
  175. package/dist/assets/psyche-questionnaire-run-detail-page-Cd3ClsSK.js +0 -1
  176. package/dist/assets/psyche-reports-page-BeyJg5fb.js +0 -1
  177. package/dist/assets/psyche-schemas-beliefs-page-DNmf-Vma.js +0 -9
  178. package/dist/assets/rewards-page-D3ymEd2X.js +0 -1
  179. package/dist/assets/settings-bin-page-DqyVI1i1.js +0 -1
  180. package/dist/assets/settings-models-page-DaFXLp-O.js +0 -1
  181. package/dist/assets/task-detail-page-CDK79bzk.js +0 -1
  182. package/dist/assets/timebox-planning-dialog-CNZIGSpd.js +0 -1
  183. package/dist/assets/today-page-Bnh8wopq.js +0 -1
  184. package/dist/assets/training-load-page-C7lq-jqy.js +0 -1
  185. package/dist/assets/wiki-page-1vf-HErs.js +0 -1
  186. package/dist/assets/workout-detail-page-Cq0YamXF.js +0 -2
@@ -1,5 +1,5 @@
1
- import{j as e,r as g,dK as aa,dL as ra,dH as sa,dM as na,dN as ia,dO as oa,aG as la,dP 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,dQ as Qa,c6 as Ja,b6 as Ya}from"./vendor-BwL6m4SE.js";import{O as Xa}from"./open-in-graph-button-CjvkEj1P.js";import{P as Za}from"./page-hero-BLhM8FF3.js";import{T as er,M as tr,S as ar,W as rr,Q as sr}from"./utility-widgets-h5eG2jvc.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-DNVwfqqq.js";import{d as K}from"./define-workbench-box-DcI0_QKW.js";import{K as ur,a as mr,b as pr}from"./kanban-boxes-u_A-UJG-.js";import{S as hr,a as gr,b as xr,c as br,d as fr,e as vr}from"./health-boxes-BPTgGM6G.js";import{M as yr,a as kr,b as wr,c as jr,d as Nr}from"./movement-boxes-QZ2EIS9q.js";import{N as Sr,a as Cr,b as _r}from"./notes-boxes-DGFmt7Dp.js";import{P as Tr,a as Ir,b as Pr}from"./projects-boxes-BvlVsO5q.js";import{T as Fr,a as Br,b as Rr,c as Wr,d as Er}from"./today-boxes-CYfskVrM.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-BF4IsheG.js";import{F as C,Q as qr}from"./question-flow-dialog-D-_EvoAt.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-izRKx6JK.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-B9TWEtCx.js";import{F as cs}from"./faceted-token-search-BMQ1Wwzt.js";import"./state-Bpe5dF3T.js";import"./motion-DcgUnXhY.js";import"./board-CuxQRKPJ.js";import"./forms-D1qJ3oOP.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(`
1
+ import{j as e,r as g,dM as aa,dN as ra,dJ as sa,dO as na,dP as ia,dQ as oa,aG as la,dR as ca,cp as $a,c7 as Ue,cq as da,ba as Ge,b3 as za,aC as Va,cO as Da,ca as Ua,ck as Ga,dS as Qa,b_ as Ja,b7 as Ya}from"./vendor-B7FKSwHK.js";import{O as Xa}from"./open-in-graph-button-DFQ4r6SN.js";import{P as Za}from"./page-hero-U603l9rQ.js";import{T as er,M as tr,S as ar,W as rr,Q as sr}from"./utility-widgets-B06wQFrd.js";import{a as _,n as xe,q as ua,j as B,c as O,e as M,d as A,g as L,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-BY5dbPXJ.js";import{d as K}from"./define-workbench-box-BEEdtBkQ.js";import{K as ur,a as mr,b as pr}from"./kanban-boxes-oACOTDYG.js";import{S as hr,a as gr,b as xr,c as br,d as fr,e as vr}from"./health-boxes-BphMeSJj.js";import{M as yr,a as kr,b as wr,c as jr,d as Nr}from"./movement-boxes-dtDYhw5c.js";import{N as Sr,a as Cr,b as _r}from"./notes-boxes-BLKucFqW.js";import{P as Tr,a as Ir,b as Pr}from"./projects-boxes-BA7_XaqX.js";import{T as Fr,a as Rr,b as Br,c as Wr,d as Er}from"./today-boxes-B_TdgSDz.js";import{H as Or,P as Ut,i as Kr,B as Mr,a as Ar,b as Lr,c as Hr}from"./graph-CHVj0Z7n.js";import{F as C,Q as qr}from"./question-flow-dialog-yMYVk998.js";import{a3 as pa,c as E,ad as te,B as R,aL as $r,eP as zr,eQ as Vr,b as Gt,eM as Dr,eR as Ur,eS as Gr,eT as Qr,eU as Jr,eV as Yr,eW as Xr,L as Zr,h as es,e as ts}from"./index-gmPaoLN-.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-uo_bNP7c.js";import{F as cs}from"./faceted-token-search-DV7MSVYb.js";import"./state-BFyKSULP.js";import"./motion-BibSzp57.js";import"./board-DprRipIG.js";import"./forms-ByKjodjN.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=>B(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=>B(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"}),[L("Search calendar-backed Forge entities and planning records.")],{inputs:A({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"}),[L("Search calendar-backed Forge entities and planning records.")],{inputs:A({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=>B(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"}),[L("Search goal entities by query and entity types.")],{inputs:A({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=>B(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=>B(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"}),[L("Search habit entities by query and entity types.")],{inputs:A({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=>B(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=>B(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=>B(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"}),[L("Search preference contexts and modeled preference items.")],{inputs:A({itemKind:"preference_context",itemLabel:"Preference context",defaultEntityTypes:["preference_context"],defaultLimit:20}),params:M()}),Rs=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"}),[L("Search preference contexts and modeled preference items.")],{inputs:A({itemKind:"preference_item",itemLabel:"Preference item",defaultEntityTypes:["preference_item"],defaultLimit:20}),params:M()});function Bs({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(Bs,{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=>B(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"}),[L("Search psyche entities and reflective records.")],{inputs:A({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"}),[L("Search psyche entities and reflective records.")],{inputs:A({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"}),[L("Search questionnaire instruments and related records.")],{inputs:A({itemKind:"questionnaire_instrument",itemLabel:"Questionnaire",defaultEntityTypes:["questionnaire_instrument"],defaultLimit:20}),params:M()}),As=it("surface:questionnaires:drafting","Questionnaire drafting","Drafting and publishing context for questionnaire instruments.",["questionnaires","drafting","authoring"],t=>B(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."})]),Ls=it("surface:questionnaires:self-observation","Self-observation calendar","Calendar of self-observation notes and linked psyche context.",["questionnaires","self-observation","psyche"],t=>B(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=>B(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=>B(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"}),[L("Search strategy entities by query and entity types.")],{inputs:A({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=>B(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"}),[L("Search task entities by title, status, or linked context."),ma("Move a task between backlog, focus, in progress, blocked, and done.")],{inputs:A({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=>B(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=>B(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=>B(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,Rs,Ws,Es,Os,Ms,As,Ls,qs,$s,Vs,Ds,Us,Qs,Js,Ys,Fr,Rr,Br,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
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(`
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(R,{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(R,{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(R,{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(R,{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(R,{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(R,{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(R,{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(R,{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(R,{type:"button",variant:"secondary",onClick:()=>{k()},children:[e.jsx(Ue,{className:"size-4"}),"Delete flow"]}),e.jsxs(R,{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 Rn({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(R,{type:"button",variant:"primary",onClick:w,children:[e.jsx(Ge,{className:"size-4"}),"Run"]}),e.jsxs(R,{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 Re(t){switch(t){case"exec":return 4;case"read_write":return 3;case"write":return 2;case"read":default:return 1}}function Bn(t,n){return Re(t)>=Re(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=Bn(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=Re(i.accessMode)-Re(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,Rt,Bt,Wt,Et,Ot,Kt,Mt,At,Lt,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,Be]=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),[Ra,ut]=g.useState(!1),[Ee,Oe]=g.useState(!1),[Ke,Ba]=g.useState(""),[Me,Wa]=g.useState([]),[Ae,Ea]=g.useState(""),[mt,pt]=g.useState({}),[Le,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 Aa=g.useMemo(()=>Array.from(new Set(n.map(l=>l.category))).map(l=>({id:`category:${l}`,label:l,description:"Workbench box category"})),[n]),La=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(R,{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")=>{Be(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)),Be(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
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};
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?Ae:"",inputs:N,debug:Le}):await s({userInput:ze?Ae:"",inputs:N,debug:Le}),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(R,{type:"button",variant:"secondary",onClick:()=>ke(!0),children:[e.jsx(Ge,{className:"size-4"}),"Run"]}),e.jsxs(R,{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=>Lr(a,l)),onConnect:a=>ne(l=>Ar({...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)=>{Be(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:Ba,boxOptions:Aa,boxFilters:Me,onBoxFiltersChange:Wa,filteredBoxes:La,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(R,{type:"button",variant:"secondary",onClick:()=>{kt(b.id),J(!1)},children:[e.jsx(Ue,{className:"size-4"}),"Delete node"]}),e.jsx(R,{type:"button",variant:"primary",onClick:()=>{J(!1),ye("overview")},children:"Done"})]})]}):null}),e.jsx(Pn,{open:Ra,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(Rn,{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:Ae,onUserInputChange:Ea,debugEnabled:Le,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:(Bt=((Rt=V.data)==null?void 0:Rt.nodeResult)??z)==null?void 0:Bt.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",(((At=((Mt=V.data)==null?void 0:Mt.nodeResult)??z)==null?void 0:At.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=((Lt=V.data)==null?void 0:Lt.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};
@@ -1 +1 @@
1
- import{b6 as v,bY as j,r as o,j as t}from"./vendor-BwL6m4SE.js";import{j as S,i as N,k as F}from"./state-Bpe5dF3T.js";import{F as C}from"./faceted-token-search-BMQ1Wwzt.js";import{P as I}from"./page-hero-BLhM8FF3.js";import{B as m,b as Q,eD as W,eE as K,eF as $}from"./index-izRKx6JK.js";import"./motion-DcgUnXhY.js";import"./ui-B9TWEtCx.js";import"./board-CuxQRKPJ.js";import"./forms-D1qJ3oOP.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};
1
+ import{b7 as v,bZ as j,r as o,j as t}from"./vendor-B7FKSwHK.js";import{j as N,i as S,k as F}from"./state-BFyKSULP.js";import{F as C}from"./faceted-token-search-DV7MSVYb.js";import{P as I}from"./page-hero-U603l9rQ.js";import{B as m,b as Q,eM as W,eN as K,eO as O}from"./index-gmPaoLN-.js";import"./motion-BibSzp57.js";import"./ui-uo_bNP7c.js";import"./board-DprRipIG.js";import"./forms-ByKjodjN.js";function L(){var h;const l=v(),p=N(),[f]=j(),b=f.get("surface"),[i,g]=o.useState(""),[c,w]=o.useState([]),x=S({queryKey:["forge-workbench-flows"],queryFn:O}),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};