forge-openclaw-plugin 0.2.102 → 0.2.103

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 (174) hide show
  1. package/dist/assets/activity-page-Dv6X5ZCV.js +1 -0
  2. package/dist/assets/{ai-surface-workspace-xtB5RFQu.js → ai-surface-workspace-CutiG6uS.js} +1 -1
  3. package/dist/assets/{atlas-panel-B3dPHCmZ.js → atlas-panel-jgMRyaHn.js} +1 -1
  4. package/dist/assets/{board-DqHzdCPQ.js → board-dIX6etHh.js} +1 -1
  5. package/dist/assets/calendar-page-q7Nm5E2U.js +1 -0
  6. package/dist/assets/calendar-rules-DPFsfiRl.js +1 -0
  7. package/dist/assets/{calendar-week-toolbar-BZ_-X3Wb.js → calendar-week-toolbar-nVhgB-0s.js} +1 -1
  8. package/dist/assets/{charts-FcU0F3XV.js → charts-DFnEuIMB.js} +1 -1
  9. package/dist/assets/companion-sync-lab-page-CJ8UTij8.js +1 -0
  10. package/dist/assets/{daily-metrics-dashboard-BMyL0Qr4.js → daily-metrics-dashboard-CiJkkkd1.js} +1 -1
  11. package/dist/assets/entity-note-count-link-RzBB6ujx.js +1 -0
  12. package/dist/assets/{entity-notes-surface-CBylYDwy.js → entity-notes-surface-Djz50HvD.js} +1 -1
  13. package/dist/assets/execution-board-CtPhI-58.js +1 -0
  14. package/dist/assets/{faceted-token-search-D7xPWfOl.js → faceted-token-search-DEC6ANa9.js} +1 -1
  15. package/dist/assets/{flagship-signal-deck-BEFKOhvx.js → flagship-signal-deck-CtHC3mql.js} +1 -1
  16. package/dist/assets/floating-action-menu-CKQRhff9.js +1 -0
  17. package/dist/assets/{forms-CmLAyGqz.js → forms-hB0SqEh-.js} +1 -1
  18. package/dist/assets/goal-detail-page-CF5fNQeR.js +1 -0
  19. package/dist/assets/goals-page-fsY8NzGB.js +1 -0
  20. package/dist/assets/{graph-BTa79qum.js → graph-DDUZNRsO.js} +1 -1
  21. package/dist/assets/habits-page-COoGz4kj.js +1 -0
  22. package/dist/assets/index-BAXYM89v.css +1 -0
  23. package/dist/assets/index-EqQsXoat.js +19 -0
  24. package/dist/assets/{insight-flow-dialog-BtIQXXsS.js → insight-flow-dialog-DtX_5W7g.js} +1 -1
  25. package/dist/assets/insights-page-cBd74ObU.js +8 -0
  26. package/dist/assets/kanban-page-CYav9THw.js +1 -0
  27. package/dist/assets/knowledge-graph-page-D2A-W1jE.js +1 -0
  28. package/dist/assets/{life-force-page-BGDkKfbJ.js → life-force-page-CACGlNhq.js} +1 -1
  29. package/dist/assets/life-force-workspace-BJ4N1I78.js +1 -0
  30. package/dist/assets/{maps-CF1RagUX.js → maps-C-yOWiDN.js} +1 -1
  31. package/dist/assets/{metric-tile-4iMd_WnJ.js → metric-tile-CMadwnGz.js} +1 -1
  32. package/dist/assets/{motion-CfdU2F35.js → motion-Lt5B1XuE.js} +1 -1
  33. package/dist/assets/movement-page-D5VqFd2q.js +1 -0
  34. package/dist/assets/{note-markdown-CsGQhQXF.js → note-markdown-BzK2Qlgr.js} +1 -1
  35. package/dist/assets/{note-tags-input-DdZi93tj.js → note-tags-input-CZzqJMLc.js} +1 -1
  36. package/dist/assets/notes-page-D3Hsh90C.js +1 -0
  37. package/dist/assets/{open-in-graph-button-C0TGev7c.js → open-in-graph-button-BFPKfyK3.js} +1 -1
  38. package/dist/assets/{orbit-map-DVXkfQdd.js → orbit-map-CnyfSmOG.js} +1 -1
  39. package/dist/assets/{overview-page-BwMlFQKX.js → overview-page-CXdWrOV1.js} +1 -1
  40. package/dist/assets/{page-hero-oFHaAjtL.js → page-hero-ffKzgyW3.js} +1 -1
  41. package/dist/assets/pill-cluster-C2D0h3lx.js +1 -0
  42. package/dist/assets/{preference-entity-handoff-button-DOKV9bZc.js → preference-entity-handoff-button-Dj3V6VxL.js} +1 -1
  43. package/dist/assets/preferences-page-Jo8Gw386.js +1 -0
  44. package/dist/assets/project-collections-qSqp90HN.js +1 -0
  45. package/dist/assets/{project-detail-page-DogvVNEn.js → project-detail-page-BifhiLQX.js} +1 -1
  46. package/dist/assets/project-management-hierarchy-page-DZ_9klIc.js +1 -0
  47. package/dist/assets/project-management-section-nav-BImLCVvf.js +1 -0
  48. package/dist/assets/projects-page-ptcx6H38.js +1 -0
  49. package/dist/assets/{psyche-behaviors-page-BeVlXvbj.js → psyche-behaviors-page-BDwXyDta.js} +1 -1
  50. package/dist/assets/{psyche-flashcards-page-CqAWCO4E.js → psyche-flashcards-page-DL1BP1jX.js} +1 -1
  51. package/dist/assets/{psyche-goal-map-page-IyNnbk_W.js → psyche-goal-map-page-ovcpisx1.js} +1 -1
  52. package/dist/assets/{psyche-graph-IkUQRaDK.js → psyche-graph-EP5GL612.js} +1 -1
  53. package/dist/assets/{psyche-metrics-page-uai0a7Lx.js → psyche-metrics-page-Bcu813Rg.js} +1 -1
  54. package/dist/assets/{psyche-mode-guide-page-C7p-ABiF.js → psyche-mode-guide-page-C0g27Xpt.js} +1 -1
  55. package/dist/assets/{psyche-modes-page-CLQ5V3w0.js → psyche-modes-page-BjKjX5MR.js} +1 -1
  56. package/dist/assets/{psyche-page-NQBHkkpU.js → psyche-page-F4tF2W70.js} +1 -1
  57. package/dist/assets/{psyche-patterns-page-BkRiNpI_.js → psyche-patterns-page-B-14hukK.js} +1 -1
  58. package/dist/assets/{psyche-questionnaire-builder-page-Du-7HwPC.js → psyche-questionnaire-builder-page-BdXmoHvK.js} +1 -1
  59. package/dist/assets/{psyche-questionnaire-detail-page-C5-yf8MF.js → psyche-questionnaire-detail-page-Cu5uwlJu.js} +1 -1
  60. package/dist/assets/{psyche-questionnaire-run-detail-page-CoSH5O6R.js → psyche-questionnaire-run-detail-page-C3R4PClg.js} +1 -1
  61. package/dist/assets/{psyche-questionnaire-run-page-ChI7c1wy.js → psyche-questionnaire-run-page-Div3iDdt.js} +1 -1
  62. package/dist/assets/{psyche-questionnaires-page-xUcJJzbI.js → psyche-questionnaires-page-DpqAPQCp.js} +1 -1
  63. package/dist/assets/{psyche-report-detail-page-BPrZCFZS.js → psyche-report-detail-page-BvWVDKP3.js} +1 -1
  64. package/dist/assets/{psyche-reports-page-D2EXJmm6.js → psyche-reports-page-BrbWUlAq.js} +1 -1
  65. package/dist/assets/{psyche-schemas-RcZYaokx.js → psyche-schemas-Dxj554nU.js} +1 -1
  66. package/dist/assets/{psyche-schemas-beliefs-page-h0ooZ1lp.js → psyche-schemas-beliefs-page-DYKvAtSD.js} +1 -1
  67. package/dist/assets/{psyche-screen-time-page-_3-4LikV.js → psyche-screen-time-page-CAOKCyQw.js} +1 -1
  68. package/dist/assets/{psyche-self-observation-page-BdbCsgR5.js → psyche-self-observation-page-F0MVA0UH.js} +1 -1
  69. package/dist/assets/{psyche-values-page-DuUVki5e.js → psyche-values-page-DyvX-d0o.js} +1 -1
  70. package/dist/assets/{report-chain-fields-BBMz0sGI.js → report-chain-fields-CeC1cJFS.js} +1 -1
  71. package/dist/assets/rewards-page-C2loyODo.js +1 -0
  72. package/dist/assets/scheduling-rules-editor-D40AC2jR.js +1 -0
  73. package/dist/assets/{schema-badge-D93RcG36.js → schema-badge-FY7818qB.js} +1 -1
  74. package/dist/assets/{select-menu-Cdq7foRu.js → select-menu-DJsCG6rM.js} +1 -1
  75. package/dist/assets/settings-agents-page-BFkJ5AAD.js +6 -0
  76. package/dist/assets/settings-bin-page-D3-Ab-iA.js +1 -0
  77. package/dist/assets/settings-calendar-page-ly_mSTAD.js +5 -0
  78. package/dist/assets/settings-data-page-D7QOqNf-.js +1 -0
  79. package/dist/assets/settings-logs-page-Ca87HEUx.js +1 -0
  80. package/dist/assets/settings-mobile-page-D0jejZot.js +1 -0
  81. package/dist/assets/settings-models-page-DPDsZjSc.js +1 -0
  82. package/dist/assets/settings-page-1cArlSPM.js +1 -0
  83. package/dist/assets/settings-rewards-page-Db4BV1DC.js +1 -0
  84. package/dist/assets/{settings-section-nav-Dc4IeVBt.js → settings-section-nav-DP9o4peU.js} +1 -1
  85. package/dist/assets/settings-users-page-BHFyDSsd.js +1 -0
  86. package/dist/assets/settings-wiki-page-BNaiupBm.js +1 -0
  87. package/dist/assets/sleep-page-BmOPF0yD.js +1 -0
  88. package/dist/assets/sports-page-BldIiclr.js +1 -0
  89. package/dist/assets/{state-VYvD1QVP.js → state-vCcAT5Hq.js} +1 -1
  90. package/dist/assets/strategies-page-CaTN99qj.js +1 -0
  91. package/dist/assets/strategy-detail-page-DsgFTd-U.js +1 -0
  92. package/dist/assets/{strategy-dialog-DMyRKrWf.js → strategy-dialog-7X7peRzu.js} +1 -1
  93. package/dist/assets/{surface-Bfz_sLX6.js → surface-CJI17F3n.js} +1 -1
  94. package/dist/assets/{table-C0VTeqw0.js → table-BNqMG3_S.js} +1 -1
  95. package/dist/assets/task-detail-page-M1sIIPA8.js +1 -0
  96. package/dist/assets/timebox-planning-dialog-ByojN0AN.js +1 -0
  97. package/dist/assets/today-page-BjDijtn8.js +1 -0
  98. package/dist/assets/training-load-page-BPRmaWmF.js +1 -0
  99. package/dist/assets/{ui-CsEkP2V8.js → ui-C1iwpj2-.js} +1 -1
  100. package/dist/assets/{use-psyche-focus-target-qxT5Oy_z.js → use-psyche-focus-target-Ct-acS9G.js} +1 -1
  101. package/dist/assets/{vendor-kIz9EZnX.js → vendor-Dnkkx2co.js} +3 -3
  102. package/dist/assets/{vitals-page-Dz1Jt5H8.js → vitals-page-CE9zdGLF.js} +1 -1
  103. package/dist/assets/weekly-review-page-CzhTv90n.js +1 -0
  104. package/dist/assets/weight-loss-page-Bp_cIk78.js +5 -0
  105. package/dist/assets/wiki-article-markdown-Dok2uy2p.js +4 -0
  106. package/dist/assets/wiki-editor-page-BuW32Y3f.js +26 -0
  107. package/dist/assets/wiki-ingest-history-page-DZKSBNHV.js +1 -0
  108. package/dist/assets/wiki-ingest-modal-DyqBEZcC.js +1 -0
  109. package/dist/assets/wiki-page-DqxlbLKG.js +1 -0
  110. package/dist/assets/workbench-flow-page-C4nc9jUg.js +5 -0
  111. package/dist/assets/workbench-page-BnyR7SL0.js +1 -0
  112. package/dist/assets/{workout-detail-page-DD9IGN6l.js → workout-detail-page-DT-c5cHL.js} +2 -2
  113. package/dist/index.html +9 -9
  114. package/dist/server/server/src/app.js +22 -3
  115. package/dist/server/server/src/health-weight-loss.js +114 -39
  116. package/dist/server/server/src/repositories/model-settings.js +9 -3
  117. package/dist/server/src/components/workbench-boxes/shared/generic-node-view.js +13 -5
  118. package/dist/server/src/lib/api.js +10 -1
  119. package/openclaw.plugin.json +1 -1
  120. package/package.json +1 -1
  121. package/dist/assets/activity-page-CgF7K2ww.js +0 -1
  122. package/dist/assets/calendar-page-C1Wfd2Fy.js +0 -1
  123. package/dist/assets/calendar-rules-CaZXtlxt.js +0 -1
  124. package/dist/assets/companion-sync-lab-page-NgeK-O-P.js +0 -1
  125. package/dist/assets/entity-note-count-link-BrS1-O0o.js +0 -1
  126. package/dist/assets/execution-board-CpO2ch6v.js +0 -1
  127. package/dist/assets/floating-action-menu-zzC2r0Ob.js +0 -1
  128. package/dist/assets/goal-detail-page-JK_Nva8e.js +0 -1
  129. package/dist/assets/goals-page-yeoJ06Vw.js +0 -1
  130. package/dist/assets/habits-page-Dx5EhkJi.js +0 -1
  131. package/dist/assets/index-BHIKoiZ6.js +0 -19
  132. package/dist/assets/index-H8R-ABM3.css +0 -1
  133. package/dist/assets/insights-page-CujrosD_.js +0 -8
  134. package/dist/assets/kanban-page-Q9NuIz5w.js +0 -1
  135. package/dist/assets/knowledge-graph-page-DaJmlvvM.js +0 -1
  136. package/dist/assets/life-force-workspace-CLVexVnb.js +0 -1
  137. package/dist/assets/movement-page-ClaoTNuX.js +0 -1
  138. package/dist/assets/notes-page-DYI8s3NN.js +0 -1
  139. package/dist/assets/pill-cluster-7UZd_lHp.js +0 -1
  140. package/dist/assets/preferences-page-BrKEkmfD.js +0 -1
  141. package/dist/assets/project-collections-CZagCmeH.js +0 -1
  142. package/dist/assets/project-management-hierarchy-page-Dr7hW9PW.js +0 -1
  143. package/dist/assets/project-management-section-nav-BLdAgTge.js +0 -1
  144. package/dist/assets/projects-page-UKrby_5-.js +0 -1
  145. package/dist/assets/rewards-page-PZFPa6rR.js +0 -1
  146. package/dist/assets/scheduling-rules-editor-B9KNKsQz.js +0 -1
  147. package/dist/assets/settings-agents-page-DPx2F6wf.js +0 -6
  148. package/dist/assets/settings-bin-page-COwP3gjo.js +0 -1
  149. package/dist/assets/settings-calendar-page-C-ghE0YT.js +0 -5
  150. package/dist/assets/settings-data-page-CBubzKBw.js +0 -1
  151. package/dist/assets/settings-logs-page-uOuXMeBm.js +0 -1
  152. package/dist/assets/settings-mobile-page-C5rfj8_r.js +0 -1
  153. package/dist/assets/settings-models-page-DijmUWdU.js +0 -1
  154. package/dist/assets/settings-page-B4u5TR5g.js +0 -1
  155. package/dist/assets/settings-rewards-page-COiTwkMH.js +0 -1
  156. package/dist/assets/settings-users-page-DEGa5DNn.js +0 -1
  157. package/dist/assets/settings-wiki-page-Cvsiz5_e.js +0 -1
  158. package/dist/assets/sleep-page-BnSOwkEU.js +0 -1
  159. package/dist/assets/sports-page-l1RqXzA_.js +0 -1
  160. package/dist/assets/strategies-page-DEnPlpAs.js +0 -1
  161. package/dist/assets/strategy-detail-page-Ls8bxKeH.js +0 -1
  162. package/dist/assets/task-detail-page-CgrYgQLD.js +0 -1
  163. package/dist/assets/timebox-planning-dialog-Ww0NGLLo.js +0 -1
  164. package/dist/assets/today-page-CIuFHMi1.js +0 -1
  165. package/dist/assets/training-load-page-BIwc648i.js +0 -1
  166. package/dist/assets/weekly-review-page-BFpBe1kI.js +0 -1
  167. package/dist/assets/weight-loss-page-BgMoBpBt.js +0 -5
  168. package/dist/assets/wiki-article-markdown-gsPTXTg1.js +0 -4
  169. package/dist/assets/wiki-editor-page-BpAZHooY.js +0 -26
  170. package/dist/assets/wiki-ingest-history-page-C-ig8O22.js +0 -1
  171. package/dist/assets/wiki-ingest-modal-BK4eQgqs.js +0 -1
  172. package/dist/assets/wiki-page-CMTZ60Zt.js +0 -1
  173. package/dist/assets/workbench-flow-page-BIpWUcLJ.js +0 -5
  174. package/dist/assets/workbench-page-CtCjYSRe.js +0 -1
@@ -1 +0,0 @@
1
- import{b5 as F,c2 as J,r as R,j as s,aG as D,c7 as E,b7 as Q}from"./vendor-kIz9EZnX.js";import{j as H,i as q,k as z}from"./state-VYvD1QVP.js";import{W as A}from"./wiki-ingest-modal-BK4eQgqs.js";import{P as U}from"./page-hero-oFHaAjtL.js";import{fg as _,S as O,E as B,C as W,B as b,I as v,Z as G,a as $,bY as Y,fk as Z}from"./index-BHIKoiZ6.js";import"./ui-CsEkP2V8.js";import"./motion-CfdU2F35.js";import"./forms-CmLAyGqz.js";import"./board-DqHzdCPQ.js";import"./graph-BTa79qum.js";const V=[{value:"all",label:"All"},{value:"queued",label:"Queued"},{value:"processing",label:"Processing"},{value:"completed",label:"Completed"},{value:"failed",label:"Failed"},{value:"review",label:"Review"},{value:"reviewed",label:"Reviewed"}];function X(n){return new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"short"}).format(new Date(n))}function ee(n,o){return o==="all"?!0:n.job.status===o||n.job.phase===o}function ge(){var k,y,S,C,I,P;const n=F(),o=H(),[i,g]=J(),c=i.get("spaceId")||"",j=i.get("q")||"",f=i.get("tag")||"all",m=i.get("from")||"",u=i.get("to")||"",K=i.get("ingest")==="1",N=i.get("ingestJobId"),r=q({queryKey:["forge-wiki-settings"],queryFn:Y}),d=q({queryKey:["forge-wiki-ingest-history",c],queryFn:()=>Z({spaceId:c||void 0,limit:200}),enabled:r.isSuccess}),x=z({mutationFn:e=>_(e),onSuccess:async(e,t)=>{if(await o.invalidateQueries({queryKey:["forge-wiki-ingest-history"]}),await o.invalidateQueries({queryKey:["forge-wiki-ingest-jobs"]}),N===t){const a=new URLSearchParams(i);a.delete("ingest"),a.delete("ingestJobId"),g(a,{replace:!0})}}}),p=(e,t)=>{const a=new URLSearchParams(i);t.trim()?a.set(e,t.trim()):a.delete(e),g(a,{replace:!0})},w=R.useMemo(()=>{var a;const e=((a=d.data)==null?void 0:a.jobs)??[],t=j.trim().toLowerCase();return e.filter(l=>{if(!ee(l,f))return!1;const L=l.job.createdAt.slice(0,10);return m&&L<m||u&&L>u?!1:t?[l.job.titleHint,l.job.latestMessage,l.job.sourceLocator,l.job.status,l.job.phase,l.job.mimeType].join(" ").toLowerCase().includes(t):!0})},[m,(k=d.data)==null?void 0:k.jobs,j,f,u]),M=c||((S=(y=r.data)==null?void 0:y.settings.spaces[0])==null?void 0:S.id)||"",h=e=>{const t=new URLSearchParams(i);t.set("ingest","1"),e?t.set("ingestJobId",e):t.delete("ingestJobId"),g(t,{replace:!0})},T=()=>{const e=new URLSearchParams(i);e.delete("ingest"),e.delete("ingestJobId"),g(e,{replace:!0})};return r.isLoading||d.isLoading?s.jsx(O,{eyebrow:"KarpaWiki",title:"Loading ingest history",description:"Gathering prior imports, statuses, and review state.",columns:1,blocks:6}):r.isError||d.isError?s.jsx(B,{eyebrow:"KarpaWiki",error:r.error??d.error,onRetry:()=>{r.refetch(),d.refetch()}}):s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-3 py-4 sm:px-5 lg:px-6",children:s.jsxs("div",{className:"mx-auto grid w-full max-w-[1480px] gap-5",children:[s.jsx(U,{title:"KarpaWiki Ingest History",description:"Search prior ingests, reopen a review, or clear ingest records without touching pages and entities that were already published.",badge:`${w.length} matching jobs`}),s.jsxs(W,{className:"grid gap-4",children:[s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[s.jsxs("div",{children:[s.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-white/45",children:"History Filters"}),s.jsx("div",{className:"mt-2 text-sm text-white/58",children:"Narrow by free text, date range, space, or status tags."})]}),s.jsxs("div",{className:"flex flex-wrap gap-2",children:[s.jsx(b,{variant:"secondary",onClick:()=>n(`/wiki${c?`?spaceId=${encodeURIComponent(c)}`:""}`),children:"Back to KarpaWiki"}),s.jsxs(b,{onClick:()=>h(),children:[s.jsx(D,{className:"size-3.5"}),"New ingest"]})]})]}),s.jsxs("div",{className:"grid gap-3 lg:grid-cols-[minmax(0,1.4fr)_minmax(0,0.8fr)_minmax(0,0.8fr)_minmax(0,0.8fr)]",children:[s.jsxs("label",{className:"grid gap-2",children:[s.jsx("span",{className:"text-sm text-white/58",children:"Free text"}),s.jsx(v,{value:j,onChange:e=>p("q",e.target.value),placeholder:"title, source, status, failure message…"})]}),s.jsxs("label",{className:"grid gap-2",children:[s.jsx("span",{className:"text-sm text-white/58",children:"From"}),s.jsx(v,{type:"date",value:m,onChange:e=>p("from",e.target.value)})]}),s.jsxs("label",{className:"grid gap-2",children:[s.jsx("span",{className:"text-sm text-white/58",children:"To"}),s.jsx(v,{type:"date",value:u,onChange:e=>p("to",e.target.value)})]}),s.jsxs("label",{className:"grid gap-2",children:[s.jsx("span",{className:"text-sm text-white/58",children:"Space"}),s.jsxs("select",{className:"h-11 rounded-[18px] border border-white/10 bg-white/[0.04] px-3 text-sm text-white",value:c,onChange:e=>p("spaceId",e.target.value),children:[s.jsx("option",{value:"",children:"All spaces"}),(((C=r.data)==null?void 0:C.settings.spaces)??[]).map(e=>s.jsx("option",{value:e.id,children:e.label},e.id))]})]})]}),s.jsx("div",{className:"flex flex-wrap gap-2",children:V.map(e=>s.jsx("button",{type:"button",className:G("rounded-full px-3 py-2 text-xs font-semibold uppercase tracking-[0.14em] transition",f===e.value?"bg-[var(--primary)]/[0.18] text-[var(--primary)]":"bg-white/[0.04] text-white/58 hover:bg-white/[0.08] hover:text-white"),onClick:()=>p("tag",e.value==="all"?"":e.value),children:e.label},e.value))})]}),w.length===0?s.jsx($,{eyebrow:"KarpaWiki ingest",title:"No ingest jobs match these filters",description:"Try widening the dates or clearing a status tag."}):s.jsx("div",{className:"grid gap-3",children:w.map(e=>{const t=e.job.titleHint||e.job.latestMessage||e.job.sourceLocator||"KarpaWiki ingest",a=!["queued","processing"].includes(e.job.status);return s.jsxs(W,{className:"grid gap-4",children:[s.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[s.jsxs("button",{type:"button",className:"min-w-0 flex-1 text-left",onClick:()=>h(e.job.id),children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:"text-[11px] uppercase tracking-[0.16em] text-white/42",children:"KarpaWiki ingest"}),s.jsx("span",{className:"rounded-full border border-white/10 bg-white/[0.04] px-2.5 py-1 text-[10px] uppercase tracking-[0.16em] text-white/60",children:e.job.status}),s.jsx("span",{className:"rounded-full border border-white/10 bg-white/[0.04] px-2.5 py-1 text-[10px] uppercase tracking-[0.16em] text-white/44",children:e.job.phase})]}),s.jsx("div",{className:"mt-3 text-lg font-semibold text-white",children:t}),s.jsxs("div",{className:"mt-2 flex flex-wrap gap-x-4 gap-y-1 text-sm text-white/56",children:[s.jsxs("span",{children:[e.job.progressPercent,"% · ",e.job.createdPageCount," pages ·"," ",e.job.createdEntityCount," entities"]}),s.jsx("span",{children:X(e.job.createdAt)}),e.job.sourceLocator?s.jsx("span",{className:"truncate",children:e.job.sourceLocator}):null]})]}),s.jsxs("div",{className:"flex shrink-0 flex-wrap gap-2",children:[s.jsx(b,{variant:"secondary",size:"sm",onClick:()=>h(e.job.id),children:"Open review"}),s.jsxs(b,{variant:"secondary",size:"sm",disabled:!a||x.isPending,pending:x.isPending&&x.variables===e.job.id,pendingLabel:"Deleting",onClick:()=>{!a||!window.confirm("Delete this ingest history entry? Published pages and entities will stay, but discarded or unreviewed ingest artifacts will be removed.")||x.mutateAsync(e.job.id)},children:[s.jsx(E,{className:"size-3.5"}),"Delete"]})]})]}),e.job.errorMessage?s.jsx("div",{className:"rounded-[18px] border border-rose-400/18 bg-rose-500/[0.08] px-4 py-3 text-sm text-rose-100/86",children:e.job.errorMessage}):null,["queued","processing"].includes(e.job.status)?s.jsxs("div",{className:"inline-flex items-center gap-2 text-sm text-white/50",children:[s.jsx(Q,{className:"size-4 animate-spin"}),"This ingest is still active and cannot be deleted yet."]}):null]},e.job.id)})})]})}),s.jsx(A,{open:K,onOpenChange:e=>{e||T()},spaces:((I=r.data)==null?void 0:I.settings.spaces)??[],llmProfiles:((P=r.data)==null?void 0:P.settings.llmProfiles)??[],initialSpaceId:M,selectedJobId:N,onJobSelected:e=>h(e)})]})}export{ge as WikiIngestHistoryPage};
@@ -1 +0,0 @@
1
- import{b5 as Ce,r as p,j as e,aK as ee,dD as Y,dE as Se,aN as _e,dF as Ae,cg as Pe,aG as U,dG as ue,b7 as Ke,b3 as ge}from"./vendor-kIz9EZnX.js";import{R as Fe,P as Me,O as Le,C as qe,T as ze,D as $e,a as Qe}from"./ui-CsEkP2V8.js";import{j as De,i as te,k as q}from"./state-VYvD1QVP.js";import{fb as Re,fc as We,fd as he,fe as Ue,ff as Oe,fg as Be,Z as y,I as be,T as He,B as C,b as X,c as J,g as Ve,fh as Ze,fi as Ge,fj as Ye}from"./index-BHIKoiZ6.js";const L=new Set(["queued","processing"]),we=15e3,Xe=["goal","project","task","habit","strategy","psyche_value","flashcard","note"];function fe(s){return new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}).format(new Date(s))}function S(s,i){const r=s[i];return typeof r=="number"&&Number.isFinite(r)?r:null}function f(s,i){const r=s[i];return typeof r=="string"&&r.trim().length>0?r:null}function Je(s,i){const r=f(s.metadata,"currentFileName")??f(s.metadata,"fileName")??"current source",b=f(s.metadata,"status")??"in_progress",d=S(s.metadata,"chunkIndex"),x=S(s.metadata,"chunkCount"),j=S(s.metadata,"currentFileIndex"),h=S(s.metadata,"currentFileTotal"),v=j!==null&&h!==null?`${r} (${j}/${h})`:r,c=d!==null&&x!==null&&x>1?` · chunk ${d}/${x}`:"";return`Waiting for OpenAI on ${v}${c}. ${i} polls · ${b}.`}function et(s){const i=[];for(const r of s){const b=f(r.metadata,"scope"),x=f(r.metadata,"eventKey")==="llm_compile_background_polled",j=f(r.metadata,"currentFileName")??f(r.metadata,"fileName"),h=S(r.metadata,"chunkIndex"),v=S(r.metadata,"chunkCount"),c=x?["poll",b??"",j??"",h??"",v??""].join(":"):null,m=i[i.length-1],_=m&&f(m.metadata,"eventKey"),N=m&&(f(m.metadata,"currentFileName")??f(m.metadata,"fileName")),k=m&&S(m.metadata,"chunkIndex"),w=m&&S(m.metadata,"chunkCount"),A=m&&_==="llm_compile_background_polled"?["poll",f(m.metadata,"scope")??"",N??"",k??"",w??""].join(":"):null;if(x&&m&&A===c){i[i.length-1]={...r,repetitionCount:m.repetitionCount+1,metadata:{...r.metadata,aggregatedPollCount:m.repetitionCount+1}};continue}i.push({...r,repetitionCount:1})}return i}function O(s){return Ve(s)}function ye(s){return typeof s=="string"&&Xe.includes(s)}function tt(s,i){return typeof i.title=="string"&&i.title.trim().length>0?i.title:typeof i.displayName=="string"&&i.displayName.trim().length>0?i.displayName:typeof i.statement=="string"&&i.statement.trim().length>0?i.statement:`${s}:${String(i.id??"")}`}function it(s,i){const b=[i.description,i.summary,i.overview,i.valuedDirection,i.whyItMatters,i.originNote].find(d=>typeof d=="string"&&d.trim().length>0);return b||(s==="note"&&typeof i.kind=="string"?i.kind:"")}function st({candidate:s,decision:i,onDecisionChange:r,spaceId:b}){const d=ye(s.payload.entityType)?s.payload.entityType:null,[x,j]=p.useState(i.mappedEntityLabel||s.title||""),[h,v]=p.useState(i.targetNoteLabel||s.title||""),c=typeof s.payload.contentMarkdown=="string"?s.payload.contentMarkdown:typeof s.payload.patchSummary=="string"?s.payload.patchSummary:typeof s.payload.rationale=="string"?s.payload.rationale:s.summary,m=te({queryKey:["forge-wiki-ingest-map-search",d,x.trim()],enabled:s.candidateType==="entity"&&i.action==="map_existing"&&d!==null&&x.trim().length>0,queryFn:async()=>{var F;const g=(await Ze({searches:[{entityTypes:d?[d]:void 0,query:x.trim(),limit:8}]})).results[0];return((F=g==null?void 0:g.matches)==null?void 0:F.filter(u=>!!(u&&ye(u.entityType)&&typeof u.id=="string"&&u.entity&&typeof u.entity=="object")).map(u=>({entityType:u.entityType,entityId:u.id,label:tt(u.entityType,u.entity),description:it(u.entityType,u.entity),kind:O(u.entityType)})))??[]}}),_=m.data??[],N=te({queryKey:["forge-wiki-ingest-merge-search",b,h.trim()],enabled:s.candidateType==="page"&&i.action==="merge_existing"&&h.trim().length>0,queryFn:async()=>(await Ge({spaceId:b,kind:"wiki",mode:"text",query:h.trim(),limit:8})).results.map(g=>({noteId:g.page.id,title:g.page.title,slug:g.page.slug,summary:g.page.summary}))}),k=N.data??[],w=i.mappedEntityId&&i.mappedEntityType?_.find(a=>a.entityId===i.mappedEntityId&&a.entityType===i.mappedEntityType)??(i.mappedEntityLabel?{entityId:i.mappedEntityId,entityType:i.mappedEntityType,label:i.mappedEntityLabel,kind:O(i.mappedEntityType)}:null):null,A=i.targetNoteId?k.find(a=>a.noteId===i.targetNoteId)??(i.targetNoteLabel?{noteId:i.targetNoteId,title:i.targetNoteLabel}:null):null;return e.jsxs("div",{className:"rounded-[24px] border border-white/8 bg-white/[0.04] p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-white/40",children:s.candidateType.replaceAll("_"," ")}),e.jsx("div",{className:"mt-2 text-base font-semibold text-white",children:s.title||s.targetKey||"Untitled candidate"}),d?e.jsx("div",{className:"mt-2",children:O(d)?e.jsx(X,{kind:O(d),label:d.replaceAll("_"," "),compact:!0,gradient:!1}):e.jsx(J,{className:"bg-white/[0.08] text-white/72",children:d.replaceAll("_"," ")})}):null,s.summary?e.jsx("div",{className:"mt-1 text-sm leading-6 text-white/58",children:s.summary}):null]}),e.jsxs("div",{className:"inline-flex items-center gap-2 rounded-full border border-white/10 bg-white/[0.03] p-1",children:[e.jsx("button",{type:"button",className:y("rounded-full px-3 py-1.5 text-xs font-medium transition",i.action==="keep"?"bg-[rgba(192,193,255,0.2)] text-white":"text-white/54 hover:text-white"),onClick:()=>r({...i,action:"keep"}),children:"Keep"}),s.candidateType==="entity"&&d?e.jsx("button",{type:"button",className:y("rounded-full px-3 py-1.5 text-xs font-medium transition",i.action==="map_existing"?"bg-[rgba(133,222,255,0.18)] text-white":"text-white/54 hover:text-white"),onClick:()=>r({...i,action:"map_existing",mappedEntityType:d}),children:"Map existing"}):null,s.candidateType==="page"?e.jsx("button",{type:"button",className:y("rounded-full px-3 py-1.5 text-xs font-medium transition",i.action==="merge_existing"?"bg-[rgba(133,222,255,0.18)] text-white":"text-white/54 hover:text-white"),onClick:()=>r({...i,action:"merge_existing"}),children:"Merge existing"}):null,e.jsx("button",{type:"button",className:y("rounded-full px-3 py-1.5 text-xs font-medium transition",i.action==="discard"?"bg-[rgba(255,255,255,0.12)] text-white":"text-white/54 hover:text-white"),onClick:()=>r({...i,action:"discard"}),children:"Discard"})]})]}),s.candidateType==="entity"&&d&&i.action==="map_existing"?e.jsxs("div",{className:"mt-4 grid gap-3 rounded-[18px] border border-white/8 bg-[rgba(6,10,20,0.55)] p-4",children:[e.jsxs("div",{className:"text-[11px] uppercase tracking-[0.16em] text-white/42",children:["Map to existing ",d.replaceAll("_"," ")]}),w?e.jsx("div",{className:"flex flex-wrap gap-2",children:e.jsxs("span",{className:"inline-flex items-center gap-2 rounded-full border border-white/8 bg-white/[0.06] px-2.5 py-1.5",children:[w.kind?e.jsx(X,{kind:w.kind,label:w.label,compact:!0,gradient:!1,className:"max-w-[20rem]"}):e.jsx(J,{className:"bg-white/[0.08] text-white/78",children:w.label}),e.jsx("button",{type:"button",className:"rounded-full text-white/50 transition hover:text-white",onClick:()=>r({...i,mappedEntityId:void 0,mappedEntityLabel:void 0}),"aria-label":"Clear mapped entity",children:e.jsx(ee,{className:"size-3.5"})})]})}):null,e.jsxs("div",{className:"flex items-center gap-3 rounded-[20px] border border-white/8 bg-white/[0.04] px-4 py-3",children:[e.jsx(ge,{className:"size-4 text-white/34"}),e.jsx("input",{value:x,onChange:a=>{j(a.target.value),i.mappedEntityId&&r({...i,mappedEntityId:void 0,mappedEntityLabel:void 0})},placeholder:`Search existing ${d.replaceAll("_"," ")}`,className:"min-w-0 flex-1 bg-transparent text-sm text-white placeholder:text-white/34 focus:outline-none"})]}),e.jsx("div",{className:"grid gap-2",children:m.isPending?e.jsx("div",{className:"rounded-[16px] border border-white/8 bg-white/[0.03] px-3 py-3 text-sm text-white/48",children:"Searching Forge…"}):_.length===0?e.jsxs("div",{className:"rounded-[16px] border border-dashed border-white/10 px-3 py-3 text-sm text-white/42",children:["No existing ",d.replaceAll("_"," ")," matches yet."]}):_.map(a=>{const g=i.mappedEntityType===a.entityType&&i.mappedEntityId===a.entityId;return e.jsx("button",{type:"button",className:y("flex w-full items-start justify-between gap-3 rounded-[18px] border px-3 py-3 text-left transition",g?"border-[rgba(133,222,255,0.24)] bg-[rgba(133,222,255,0.12)] text-white":"border-white/8 bg-white/[0.03] text-white/72 hover:bg-white/[0.06] hover:text-white"),onClick:()=>r({action:"map_existing",mappedEntityType:a.entityType,mappedEntityId:a.entityId,mappedEntityLabel:a.label}),children:e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-medium",children:a.kind?e.jsx(X,{kind:a.kind,label:a.label,compact:!0,gradient:!1}):a.label}),a.description?e.jsx("div",{className:"mt-1 text-xs leading-5 text-white/46",children:a.description}):null]})},`${a.entityType}:${a.entityId}`)})})]}):null,s.candidateType==="page"&&i.action==="merge_existing"?e.jsxs("div",{className:"mt-4 grid gap-3 rounded-[18px] border border-white/8 bg-[rgba(6,10,20,0.55)] p-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-white/42",children:"Merge into existing page"}),A?e.jsx("div",{className:"flex flex-wrap gap-2",children:e.jsxs("span",{className:"inline-flex items-center gap-2 rounded-full border border-white/8 bg-white/[0.06] px-2.5 py-1.5",children:[e.jsx(J,{className:"bg-white/[0.08] text-white/78",children:A.title}),e.jsx("button",{type:"button",className:"rounded-full text-white/50 transition hover:text-white",onClick:()=>r({...i,targetNoteId:void 0,targetNoteLabel:void 0}),"aria-label":"Clear merge target",children:e.jsx(ee,{className:"size-3.5"})})]})}):null,e.jsxs("div",{className:"flex items-center gap-3 rounded-[20px] border border-white/8 bg-white/[0.04] px-4 py-3",children:[e.jsx(ge,{className:"size-4 text-white/34"}),e.jsx("input",{value:h,onChange:a=>{v(a.target.value),i.targetNoteId&&r({...i,targetNoteId:void 0,targetNoteLabel:void 0})},placeholder:"Search existing wiki pages",className:"min-w-0 flex-1 bg-transparent text-sm text-white placeholder:text-white/34 focus:outline-none"})]}),e.jsx("div",{className:"grid gap-2",children:N.isPending?e.jsx("div",{className:"rounded-[16px] border border-white/8 bg-white/[0.03] px-3 py-3 text-sm text-white/48",children:"Searching Forge…"}):k.length===0?e.jsx("div",{className:"rounded-[16px] border border-dashed border-white/10 px-3 py-3 text-sm text-white/42",children:"No existing wiki pages match yet."}):k.map(a=>{const g=i.targetNoteId===a.noteId;return e.jsx("button",{type:"button",className:y("flex w-full items-start justify-between gap-3 rounded-[18px] border px-3 py-3 text-left transition",g?"border-[rgba(133,222,255,0.24)] bg-[rgba(133,222,255,0.12)] text-white":"border-white/8 bg-white/[0.03] text-white/72 hover:bg-white/[0.06] hover:text-white"),onClick:()=>r({action:"merge_existing",targetNoteId:a.noteId,targetNoteLabel:a.title}),children:e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-medium",children:a.title}),e.jsxs("div",{className:"mt-1 text-xs leading-5 text-white/46",children:[a.slug?`${a.slug}`:"",a.summary?`${a.slug?" · ":""}${a.summary}`:""]})]})},a.noteId)})})]}):null,c?e.jsx("div",{className:"mt-4 rounded-[18px] border border-white/8 bg-[rgba(6,10,20,0.65)] px-4 py-3 text-sm leading-6 text-white/72",children:e.jsx("pre",{className:"whitespace-pre-wrap font-sans",children:c})}):null]})}function ot({open:s,onOpenChange:i,spaces:r,llmProfiles:b,initialSpaceId:d,selectedJobId:x,onJobSelected:j,linkedEntityHints:h=[]}){var me;const v=Ce(),c=De(),[m,_]=p.useState("files"),[N,k]=p.useState(d),[w,A]=p.useState(""),[a,g]=p.useState(""),[F,u]=p.useState(""),[z,B]=p.useState([]),[je,$]=p.useState(!1),[ve,Ne]=p.useState(!1),I=p.useMemo(()=>b.filter(t=>t.enabled&&!!t.secretId),[b]),[Q,ie]=p.useState(((me=I[0])==null?void 0:me.id)??""),[D,ke]=p.useState("auto"),[H,se]=p.useState({}),[R,E]=p.useState(null),[W,T]=p.useState(null),ae=p.useRef({});p.useEffect(()=>{d&&k(d)},[d]),p.useEffect(()=>{var t;!Q&&((t=I[0])!=null&&t.id)&&ie(I[0].id)},[Q,I]);const M=I.find(t=>t.id===Q)??I[0]??null,P=te({queryKey:["forge-wiki-ingest-job",x],queryFn:()=>Ye(x),enabled:s&&!!x,refetchInterval:t=>{const o=t.state.data;return o&&L.has(o.job.status)?2e3:!1}});p.useEffect(()=>{const t=P.data;t&&se(o=>{const l={};for(const K of t.candidates)l[K.id]=o[K.id]??(K.status==="rejected"?{action:"discard"}:{action:"keep"});return l})},[P.data]),p.useEffect(()=>{W&&T(null)},[H,W]);const V=q({mutationFn:async t=>Re(t),onSuccess:(t,o)=>{t.job&&c.setQueryData(["forge-wiki-ingest-job",o],t.job),c.invalidateQueries({queryKey:["forge-wiki-ingest-jobs"]}),c.invalidateQueries({queryKey:["forge-wiki-ingest-history"]})}});p.useEffect(()=>{const t=P.data;if(!t||!L.has(t.job.status))return;const o=t.logs.reduce((pe,Te)=>{const xe=Number(new Date(Te.createdAt));return Number.isFinite(xe)?Math.max(pe,xe):pe},0),l=Number(new Date(t.job.updatedAt)),K=Math.max(Number.isFinite(l)?l:0,o);if(!Number.isFinite(K)||K<=0)return;const G=Date.now();if(!(G-K>=we)||V.isPending)return;const Ee=ae.current[t.job.id]??0;G-Ee<we||(ae.current[t.job.id]=G,V.mutate(t.job.id))},[P.data,V]);const re=q({mutationFn:async()=>{if(!M)throw new Error("Set up an OpenAI wiki ingest profile first. Forge now requires an LLM profile before auto-ingest can turn source material into draft pages and entities.");if(m==="files"){if(z.length===0)throw new Error("Select at least one file to ingest.");return We({files:z,spaceId:N||void 0,titleHint:w.trim()||void 0,llmProfileId:M.id,parseStrategy:D,createAsKind:"wiki",linkedEntityHints:h})}if(m==="url"){if(!a.trim())throw new Error("Enter a URL to ingest.");return he({spaceId:N||void 0,titleHint:w.trim()||void 0,sourceKind:"url",sourceUrl:a.trim(),llmProfileId:M.id,parseStrategy:D,createAsKind:"wiki",linkedEntityHints:h})}if(!F.trim())throw new Error("Paste some text to ingest.");return he({spaceId:N||void 0,titleHint:w.trim()||void 0,sourceKind:"raw_text",sourceText:F,mimeType:"text/plain",llmProfileId:M.id,parseStrategy:D,createAsKind:"wiki",linkedEntityHints:h})},onSuccess:async t=>{var l;const o=((l=t.job)==null?void 0:l.job.id)??null;await c.invalidateQueries({queryKey:["forge-wiki-ingest-jobs"]}),await c.invalidateQueries({queryKey:["forge-wiki-ingest-history"]}),o&&j(o),E(null),T(null)},onError:t=>{E(t instanceof Error?t.message:"Unable to start ingest.")}}),ne=q({mutationFn:async()=>{if(!x||!P.data)throw new Error("Choose an ingest job first.");const t=P.data.candidates.map(o=>{const l=H[o.id]??{action:"keep"};if(l.action==="map_existing"&&(!l.mappedEntityType||!l.mappedEntityId))throw new Error(`Choose an existing ${String(o.payload.entityType??"entity").replaceAll("_"," ")} before publishing the review.`);if(l.action==="merge_existing"&&!l.targetNoteId)throw new Error(`Choose an existing wiki page before publishing the review for ${o.title||"this page candidate"}.`);return l.action==="map_existing"?{candidateId:o.id,action:"map_existing",mappedEntityType:l.mappedEntityType,mappedEntityId:l.mappedEntityId}:l.action==="merge_existing"?{candidateId:o.id,action:"merge_existing",targetNoteId:l.targetNoteId}:{candidateId:o.id,action:l.action}});return Ue({jobId:x,decisions:t})},onSuccess:async t=>{T(null),c.setQueryData(["forge-wiki-ingest-job",t.job.job.id],t.job),await Promise.all([c.invalidateQueries({queryKey:["forge-wiki-ingest-jobs"]}),c.invalidateQueries({queryKey:["forge-wiki-ingest-history"]}),c.invalidateQueries({queryKey:["forge-wiki-ingest-job",t.job.job.id]}),c.invalidateQueries({queryKey:["forge-wiki-home"]}),c.invalidateQueries({queryKey:["forge-wiki-page-by-slug"]}),c.invalidateQueries({queryKey:["forge-wiki-tree"]})])},onError:t=>{T(t instanceof Error?t.message:"Unable to publish review.")}}),le=q({mutationFn:async()=>{if(!x)throw new Error("Choose an ingest job first.");return Oe(x)},onSuccess:async t=>{var l;const o=((l=t.job)==null?void 0:l.job.id)??null;await Promise.all([c.invalidateQueries({queryKey:["forge-wiki-ingest-jobs"]}),c.invalidateQueries({queryKey:["forge-wiki-ingest-history"]}),c.invalidateQueries({queryKey:["forge-wiki-ingest-job",x]})]),o&&j(o),E(null),T(null)},onError:t=>{E(t instanceof Error?t.message:"Unable to rerun ingest.")}}),de=q({mutationFn:async()=>{if(!x)throw new Error("Choose an ingest job first.");return Be(x)},onSuccess:async()=>{await Promise.all([c.invalidateQueries({queryKey:["forge-wiki-ingest-jobs"]}),c.invalidateQueries({queryKey:["forge-wiki-ingest-history"]}),c.invalidateQueries({queryKey:["forge-wiki-ingest-job",x]})]),ce(),E(null),T(null)},onError:t=>{E(t instanceof Error?t.message:"Unable to delete ingest.")}}),n=P.data??null,Ie=n&&!L.has(n.job.status),Z=p.useMemo(()=>(n==null?void 0:n.candidates.filter(t=>["suggested","rejected","failed"].includes(t.status)))??[],[n]),oe=p.useMemo(()=>et((n==null?void 0:n.logs)??[]),[n==null?void 0:n.logs]),ce=()=>{j(null),B([]),g(""),u(""),A(""),E(null),T(null)};return e.jsx(Fe,{open:s,onOpenChange:t=>{i(t),t||(E(null),T(null))},children:e.jsxs(Me,{children:[e.jsx(Le,{className:"fixed inset-0 z-50 bg-[rgba(3,7,18,0.78)] backdrop-blur-sm"}),e.jsxs(qe,{className:"fixed inset-x-4 bottom-4 top-4 z-50 mx-auto flex max-w-[min(74rem,calc(100vw-2rem))] flex-col overflow-hidden rounded-[32px] border border-white/8 bg-[linear-gradient(180deg,rgba(18,27,42,0.98),rgba(10,15,28,0.98))] shadow-[0_36px_110px_rgba(3,8,18,0.48)]",children:[e.jsx("div",{className:"border-b border-white/8 px-5 py-5",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/42",children:"KarpaWiki Ingest"}),e.jsx(ze,{className:"mt-2 font-display text-[1.5rem] tracking-[-0.04em] text-white",children:n?"Ingest review and progress":"Build KarpaWiki memory from source files"}),e.jsx($e,{className:"mt-2 max-w-3xl text-sm leading-6 text-white/58",children:"Upload notes, media, ZIP archives, links, or pasted text. Forge will process them in the background, propose pages and entities, and let you keep only what belongs."})]}),e.jsx(Qe,{asChild:!0,children:e.jsx("button",{type:"button",className:"rounded-full border border-white/10 bg-white/[0.04] p-2 text-white/64 transition hover:bg-white/[0.08] hover:text-white","aria-label":"Close ingest modal",children:e.jsx(ee,{className:"size-4"})})})]})}),e.jsx("div",{className:"flex-1 overflow-y-auto px-5 py-5",children:n?e.jsxs("div",{className:"grid gap-5 xl:grid-cols-[minmax(0,0.9fr)_minmax(0,1.1fr)]",children:[e.jsxs("div",{className:"grid gap-5",children:[e.jsxs("div",{className:"rounded-[28px] border border-white/8 bg-white/[0.04] p-4 sm:p-5",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"text-[11px] uppercase tracking-[0.16em] text-white/42",children:["Job ",n.job.id]}),e.jsx("div",{className:"mt-2 text-xl font-semibold text-white",children:n.job.latestMessage||"Ingest job"}),e.jsxs("div",{className:"mt-2 text-sm leading-6 text-white/56",children:[n.job.status," · ",n.job.phase," · started ",fe(n.job.createdAt)]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(C,{variant:"secondary",size:"sm",onClick:ce,children:"New ingest"}),Ie?e.jsxs(e.Fragment,{children:[e.jsxs(C,{variant:"secondary",size:"sm",pending:le.isPending,pendingLabel:"Rerunning",onClick:()=>void le.mutateAsync(),children:[e.jsx(U,{className:"size-3.5"}),"Rerun"]}),e.jsx(C,{variant:"ghost",size:"sm",className:"border border-rose-300/18 bg-rose-400/10 text-rose-100 hover:bg-rose-400/16",pending:de.isPending,pendingLabel:"Deleting",onClick:()=>{window.confirm("Delete this ingest history entry? Published pages or entities will stay, but discarded or unreviewed ingest data will be removed.")&&de.mutateAsync()},children:"Delete"})]}):null]})]}),e.jsx("div",{className:"mt-5 grid gap-3 sm:grid-cols-4",children:[{label:"Progress",value:`${n.job.progressPercent}%`},{label:"Files",value:`${n.job.processedFiles}/${n.job.totalFiles}`},{label:"Pages",value:String(n.job.createdPageCount)},{label:"Entities",value:String(n.job.createdEntityCount)}].map(t=>e.jsxs("div",{className:"rounded-[22px] border border-white/8 bg-[rgba(8,12,22,0.68)] px-4 py-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-white/42",children:t.label}),e.jsx("div",{className:"mt-2 text-lg font-semibold text-white",children:t.value})]},t.label))}),e.jsx("div",{className:"mt-5",children:e.jsx("div",{className:"h-2 overflow-hidden rounded-full bg-white/[0.06]",children:e.jsx("div",{className:"h-full rounded-full bg-[linear-gradient(90deg,rgba(192,193,255,0.8),rgba(133,222,255,0.8))] transition-all duration-300",style:{width:`${n.job.progressPercent}%`}})})}),R?e.jsx("div",{className:"mt-4 rounded-[20px] border border-rose-300/22 bg-rose-400/10 px-4 py-3 text-sm text-rose-100",children:R}):null]}),e.jsxs("div",{className:"rounded-[28px] border border-white/8 bg-white/[0.04] p-4 sm:p-5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-white/42",children:"Rich log"}),e.jsx(C,{variant:"secondary",size:"sm",onClick:()=>v(`/settings/logs?jobId=${encodeURIComponent(n.job.id)}`),children:"Open full logs"})]}),e.jsx("div",{className:"mt-4 grid max-h-[28rem] gap-2 overflow-y-auto",children:oe.length===0?e.jsx("div",{className:"rounded-[18px] border border-dashed border-white/10 px-4 py-4 text-sm text-white/45",children:"Waiting for the backend to emit progress."}):oe.map(t=>e.jsx("div",{className:"rounded-[18px] border border-white/8 bg-[rgba(7,11,21,0.72)] px-4 py-3",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"rounded-full border border-white/10 bg-white/[0.04] px-2 py-1 text-[10px] font-semibold uppercase tracking-[0.14em] text-white/55",children:t.level}),typeof t.metadata.scope=="string"?e.jsx("span",{className:"rounded-full border border-white/10 bg-white/[0.04] px-2 py-1 text-[10px] font-semibold uppercase tracking-[0.14em] text-white/38",children:t.metadata.scope}):null,typeof t.metadata.eventKey=="string"?e.jsx("span",{className:"rounded-full border border-white/10 bg-white/[0.04] px-2 py-1 text-[10px] font-semibold uppercase tracking-[0.14em] text-white/38",children:t.metadata.eventKey}):null]}),e.jsx("div",{className:"mt-2 text-sm text-white/82",children:f(t.metadata,"eventKey")==="llm_compile_background_polled"?Je(t,t.repetitionCount):t.message}),t.repetitionCount>1?e.jsxs("div",{className:"mt-2 text-xs text-white/44",children:["Combined ",t.repetitionCount," repeated polling updates."]}):null,Object.keys(t.metadata).length>0?e.jsxs("details",{className:"mt-3",children:[e.jsx("summary",{className:"cursor-pointer text-xs text-white/45",children:"View metadata"}),e.jsx("pre",{className:"mt-2 overflow-x-auto whitespace-pre-wrap rounded-[14px] border border-white/8 bg-black/20 px-3 py-3 text-[11px] leading-5 text-white/52",children:JSON.stringify(t.metadata,null,2)})]}):null]}),e.jsx("div",{className:"text-[11px] uppercase tracking-[0.14em] text-white/38",children:fe(t.createdAt)})]})},t.id))})]})]}),e.jsxs("div",{className:"grid gap-5",children:[e.jsxs("div",{className:"rounded-[28px] border border-white/8 bg-white/[0.04] p-4 sm:p-5",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-white/42",children:"Source files"}),e.jsx("div",{className:"mt-4 grid gap-2",children:n.assets.map(t=>e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[18px] border border-white/8 bg-[rgba(7,11,21,0.72)] px-4 py-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-medium text-white",children:t.fileName||t.sourceLocator||"Source"}),e.jsx("div",{className:"mt-1 text-xs text-white/45",children:t.mimeType||t.sourceKind})]}),e.jsx("div",{className:"shrink-0 text-[11px] uppercase tracking-[0.14em] text-white/40",children:t.status})]},t.id))})]}),e.jsxs("div",{className:"rounded-[28px] border border-white/8 bg-white/[0.04] p-4 sm:p-5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-white/42",children:"Review"}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-white/58",children:"Keep the candidates that belong in Forge and discard the rest."})]}),L.has(n.job.status)?e.jsxs("div",{className:"inline-flex items-center gap-2 rounded-full border border-white/10 bg-white/[0.04] px-3 py-2 text-xs text-white/58",children:[e.jsx(Ke,{className:"size-3.5 animate-spin"}),"Processing"]}):null]}),e.jsx("div",{className:"mt-4 grid gap-3",children:Z.length===0?e.jsx("div",{className:"rounded-[18px] border border-dashed border-white/10 px-4 py-4 text-sm text-white/45",children:L.has(n.job.status)?"Candidates will appear here while the job progresses.":"This job has no reviewable candidates left."}):Z.map(t=>e.jsx(st,{candidate:t,spaceId:n.job.spaceId,decision:H[t.id]??{action:"keep"},onDecisionChange:o=>se(l=>({...l,[t.id]:o}))},t.id))}),W?e.jsx("div",{className:"mt-4 rounded-[20px] border border-rose-300/22 bg-rose-400/10 px-4 py-3 text-sm text-rose-100",children:W}):null,Z.length>0&&!L.has(n.job.status)?e.jsx("div",{className:"mt-5",children:e.jsxs(C,{className:"min-h-12",pending:ne.isPending,pendingLabel:"Publishing review",onClick:()=>void ne.mutateAsync(),children:[e.jsx(ue,{className:"size-4"}),"Publish kept candidates"]})}):null]})]})]}):e.jsxs("div",{className:"grid gap-5 lg:grid-cols-[minmax(0,1.15fr)_minmax(18rem,0.85fr)]",children:[e.jsxs("div",{className:"grid gap-5",children:[e.jsx("div",{className:"grid gap-3 sm:grid-cols-3",children:[{id:"files",label:"Files and ZIP",detail:"Drag many files or one archive.",icon:Y},{id:"url",label:"URL",detail:"Pull a webpage or remote file.",icon:Se},{id:"text",label:"Paste text",detail:"Turn notes or transcripts into pages.",icon:_e}].map(t=>{const o=t.icon,l=t.id===m;return e.jsxs("button",{type:"button",className:y("rounded-[24px] border px-4 py-4 text-left transition",l?"border-[rgba(192,193,255,0.24)] bg-[rgba(192,193,255,0.12)] text-white":"border-white/8 bg-white/[0.04] text-white/72 hover:bg-white/[0.07] hover:text-white"),onClick:()=>_(t.id),children:[e.jsx(o,{className:"size-4 text-[var(--secondary)]"}),e.jsx("div",{className:"mt-3 text-sm font-semibold",children:t.label}),e.jsx("div",{className:"mt-1 text-xs leading-5 text-white/48",children:t.detail})]},t.id)})}),e.jsx("div",{className:"rounded-[28px] border border-white/8 bg-[rgba(9,14,26,0.72)] p-4 sm:p-5",children:e.jsxs("div",{className:"grid gap-4",children:[e.jsx(be,{value:w,onChange:t=>A(t.target.value),placeholder:"Optional title hint"}),m==="files"?e.jsxs("div",{className:y("rounded-[28px] border-2 border-dashed px-5 py-8 text-center transition",je?"border-[rgba(192,193,255,0.35)] bg-[rgba(192,193,255,0.08)]":"border-white/10 bg-white/[0.03]"),onDragEnter:t=>{t.preventDefault(),$(!0)},onDragLeave:t=>{t.preventDefault(),$(!1)},onDragOver:t=>{t.preventDefault(),$(!0)},onDrop:t=>{t.preventDefault(),$(!1);const o=Array.from(t.dataTransfer.files);B(l=>[...l,...o])},children:[e.jsx("div",{className:"mx-auto flex size-14 items-center justify-center rounded-full border border-white/10 bg-white/[0.05]",children:e.jsx(Y,{className:"size-5 text-white/72"})}),e.jsx("div",{className:"mt-4 text-base font-semibold text-white",children:"Drop files, media, notes, or ZIP archives here"}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-white/50",children:"Forge accepts many files at once and queues the ingest in the background so the UI stays responsive."}),e.jsxs("label",{className:"mt-5 inline-flex cursor-pointer items-center gap-2 rounded-full border border-white/10 bg-white/[0.05] px-4 py-2 text-sm text-white/78 transition hover:bg-white/[0.08] hover:text-white",children:[e.jsx(Y,{className:"size-4"}),"Choose files",e.jsx("input",{type:"file",multiple:!0,className:"hidden",onChange:t=>B(Array.from(t.target.files??[]))})]}),z.length>0?e.jsx("div",{className:"mt-5 grid gap-2 text-left",children:z.map(t=>e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[18px] border border-white/8 bg-white/[0.04] px-4 py-3 text-sm text-white/72",children:[e.jsx("span",{className:"truncate",children:t.name}),e.jsx("span",{className:"shrink-0 text-xs text-white/42",children:t.name.toLowerCase().endsWith(".zip")?e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Ae,{className:"size-3.5"}),"ZIP"]}):`${Math.max(1,Math.round(t.size/1024))} KB`})]},`${t.name}-${t.size}-${t.lastModified}`))}):null]}):null,m==="url"?e.jsx(be,{value:a,onChange:t=>g(t.target.value),placeholder:"https://example.com/source"}):null,m==="text"?e.jsx(He,{value:F,onChange:t=>u(t.target.value),placeholder:"Paste notes, transcripts, meeting writeups, or source material here…",className:"min-h-[18rem]"}):null]})})]}),e.jsxs("aside",{className:"grid h-fit gap-4",children:[M?null:e.jsxs("div",{className:"rounded-[30px] border border-amber-300/28 bg-[linear-gradient(180deg,rgba(120,74,14,0.28),rgba(37,22,8,0.42))] p-5 shadow-[0_24px_64px_rgba(12,6,0,0.22)]",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"mt-0.5 flex size-10 shrink-0 items-center justify-center rounded-full border border-amber-200/20 bg-amber-300/12 text-amber-100",children:e.jsx(Pe,{className:"size-4.5"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-amber-100/62",children:"OpenAI setup required for smart ingest"}),e.jsx("div",{className:"mt-2 text-lg font-semibold text-white",children:"Forge can only do a raw import without OpenAI"}),e.jsx("div",{className:"mt-3 text-sm leading-6 text-white/78",children:"Without an OpenAI ingest profile, Forge cannot extract key insights, split the source into draft wiki pages, or propose Forge entities. The fallback is just a direct text import or media reference with no structured synthesis."}),e.jsx("div",{className:"mt-3 text-sm leading-6 text-white/62",children:"Set up the API key, model, thinking, and verbosity first, then come back here to build real draft pages and reviewable entity proposals."})]})]}),e.jsxs("div",{className:"mt-5 grid gap-3 sm:grid-cols-2",children:[e.jsxs(C,{className:"w-full",onClick:()=>{i(!1),v("/settings/wiki?setupLlm=1")},children:[e.jsx(U,{className:"size-4"}),"Open OpenAI setup"]}),e.jsx(C,{variant:"secondary",className:"w-full",onClick:()=>{i(!1),v("/settings/wiki")},children:"Open KarpaWiki settings"})]})]}),e.jsxs("div",{className:"rounded-[28px] border border-white/8 bg-white/[0.04] p-4",children:[e.jsxs("button",{type:"button",className:"flex w-full items-center justify-between gap-3 text-left",onClick:()=>Ne(t=>!t),children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-white/42",children:"Advanced"}),e.jsx("div",{className:"mt-2 text-sm text-white/72",children:"Model, parse, and target controls."})]}),e.jsx(U,{className:"size-4 text-white/58"})]}),ve?e.jsxs("div",{className:"mt-4 grid gap-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"mb-2 text-[11px] uppercase tracking-[0.16em] text-white/42",children:"Space"}),e.jsx("div",{className:"grid gap-2",children:r.map(t=>e.jsxs("button",{type:"button",className:y("rounded-[18px] border px-3 py-3 text-left text-sm transition",N===t.id?"border-[rgba(192,193,255,0.24)] bg-[rgba(192,193,255,0.12)] text-white":"border-white/8 bg-white/[0.03] text-white/68 hover:bg-white/[0.06] hover:text-white"),onClick:()=>k(t.id),children:[e.jsx("div",{children:t.label}),e.jsx("div",{className:"mt-1 text-xs text-white/45",children:t.description||`/${t.slug}`})]},t.id))})]}),e.jsxs("div",{children:[e.jsx("div",{className:"mb-2 text-[11px] uppercase tracking-[0.16em] text-white/42",children:"LLM profile"}),e.jsxs("div",{className:"grid gap-2",children:[I.map(t=>e.jsxs("button",{type:"button",className:y("rounded-[18px] border px-3 py-3 text-left text-sm transition",Q===t.id?"border-[rgba(192,193,255,0.24)] bg-[rgba(192,193,255,0.12)] text-white":"border-white/8 bg-white/[0.03] text-white/68 hover:bg-white/[0.06] hover:text-white"),onClick:()=>ie(t.id),children:[e.jsx("div",{children:t.label}),e.jsx("div",{className:"mt-1 text-xs text-white/45",children:t.model})]},t.id)),I.length===0?e.jsx("div",{className:"rounded-[18px] border border-dashed border-white/10 px-4 py-4 text-sm text-white/48",children:"No enabled profile with a saved key yet."}):null]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"mb-2 text-[11px] uppercase tracking-[0.16em] text-white/42",children:"Parse mode"}),e.jsx("div",{className:"grid gap-2 sm:grid-cols-3",children:[{id:"auto",label:"Auto"},{id:"multimodal",label:"Multimodal"},{id:"text_only",label:"Text only"}].map(t=>e.jsx("button",{type:"button",className:y("rounded-[18px] border px-3 py-3 text-sm transition",D===t.id?"border-[rgba(192,193,255,0.24)] bg-[rgba(192,193,255,0.12)] text-white":"border-white/8 bg-white/[0.03] text-white/68 hover:bg-white/[0.06] hover:text-white"),onClick:()=>ke(t.id),children:t.label},t.id))})]})]}):null]}),e.jsxs("div",{className:"rounded-[28px] border border-white/8 bg-[linear-gradient(180deg,rgba(192,193,255,0.12),rgba(192,193,255,0.05))] p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-white",children:[e.jsx(ue,{className:"size-4 text-[var(--secondary)]"}),e.jsx("span",{className:"text-sm font-semibold",children:"Publish only what belongs"})]}),e.jsx("div",{className:"mt-3 text-sm leading-6 text-white/62",children:"Forge stages candidate pages, proposed entity records, and page updates first. You review the output before anything is committed to the live memory graph."})]}),R?e.jsx("div",{className:"rounded-[20px] border border-rose-300/22 bg-rose-400/10 px-4 py-3 text-sm text-rose-100",children:R}):null,e.jsxs(C,{className:"min-h-12",pending:re.isPending,pendingLabel:"Starting ingest",disabled:!M,onClick:()=>void re.mutateAsync(),children:[e.jsx(U,{className:"size-4"}),"Start background ingest"]})]})]})})]})]})})}export{ot as W};
@@ -1 +0,0 @@
1
- import{b5 as Ce,cc as Se,c2 as Ee,r as d,j as e,b3 as Pe,cx as ae,aG as re,cG as We,cL as Re,c7 as Ke,b4 as Le,aC as le,aK as de,bl as $e}from"./vendor-kIz9EZnX.js";import{R as ce,P as pe,O as me,C as xe,T as he,a as ge,D as ze}from"./ui-CsEkP2V8.js";import{j as qe,i as R,k as Ue}from"./state-VYvD1QVP.js";import{u as Fe,a9 as Te,bq as De,f6 as Oe,L as O,E as ne,a as Be,b as oe,a8 as Me,B as U,Z as N,cL as Qe,I as _e,c as Je,bY as Ae,f7 as He,f8 as Ge,f9 as Ye,fa as Ve}from"./index-BHIKoiZ6.js";import{O as Xe}from"./open-in-graph-button-C0TGev7c.js";import{W as Ze}from"./wiki-article-markdown-gsPTXTg1.js";import{W as et}from"./wiki-ingest-modal-BK4eQgqs.js";import"./motion-CfdU2F35.js";import"./forms-CmLAyGqz.js";import"./board-DqHzdCPQ.js";import"./graph-BTa79qum.js";function tt(x){return new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric",year:"numeric"}).format(new Date(x))}function st(x){return x.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function ue({nodes:x,activeSlug:o,spaceId:m,depth:r=0}){return e.jsx("ul",{className:N("grid gap-1",r>0&&"mt-1"),children:x.map(n=>{const u=n.page.slug===o;return e.jsxs("li",{className:"grid gap-1",children:[e.jsx(le,{to:{pathname:n.page.slug==="index"?"/wiki":`/wiki/page/${encodeURIComponent(n.page.slug)}`,search:`?spaceId=${encodeURIComponent(m)}`},className:N("rounded-lg px-2 py-1.5 text-[12px] leading-5 transition",u?"bg-white/[0.08] text-white":"text-white/64 hover:bg-white/[0.04] hover:text-white"),style:{paddingLeft:`${.5+r*.7}rem`},children:n.page.title}),n.children.length>0?e.jsx(ue,{nodes:n.children,activeSlug:o,spaceId:m,depth:r+1}):null]},n.page.id)})})}function it({open:x,onOpenChange:o,spaces:m,activeSpaceId:r,onSelect:n}){var I;const u=((I=m.find(c=>c.visibility==="shared"))==null?void 0:I.id)??"";return e.jsx(ce,{open:x,onOpenChange:o,children:e.jsxs(pe,{children:[e.jsx(me,{className:"fixed inset-0 z-50 bg-[rgba(3,7,18,0.72)] backdrop-blur-sm"}),e.jsxs(xe,{className:"fixed left-1/2 top-[14vh] z-50 w-[min(28rem,calc(100vw-1.5rem))] -translate-x-1/2 rounded-[28px] border border-white/10 bg-[rgba(10,15,28,0.97)] p-4 shadow-[0_32px_90px_rgba(0,0,0,0.45)] sm:p-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx(he,{className:"font-display text-[1.2rem] tracking-[-0.04em] text-white",children:"Choose KarpaWiki space"}),e.jsx(ze,{className:"mt-1 text-[13px] leading-6 text-white/56",children:"Switch the reading space without leaving the article surface."})]}),e.jsx(ge,{asChild:!0,children:e.jsx("button",{type:"button",className:"rounded-full border border-white/10 bg-white/[0.04] p-2 text-white/64 transition hover:bg-white/[0.08] hover:text-white","aria-label":"Close space picker",children:e.jsx(de,{className:"size-4"})})})]}),e.jsx("div",{className:"mt-4 grid gap-2",children:m.map(c=>{const K=c.id===r,L=c.id===u;return e.jsxs("button",{type:"button",className:N("flex items-center justify-between gap-3 rounded-[22px] border px-4 py-3 text-left transition",K?"border-[rgba(192,193,255,0.22)] bg-[rgba(192,193,255,0.12)] text-white":"border-white/8 bg-white/[0.03] text-white/78 hover:bg-white/[0.06] hover:text-white"),onClick:()=>{n(c.id),o(!1)},children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-[14px] font-semibold text-inherit",children:c.label}),e.jsx("span",{className:"mt-1 block text-[12px] leading-5 text-white/52",children:c.description||`/${c.slug}`}),L?e.jsx("span",{className:"mt-2 inline-flex rounded-full bg-amber-200/90 px-2 py-0.5 text-[10px] font-semibold uppercase tracking-[0.14em] text-stone-950",children:"Recovered pages"}):null]}),K?e.jsx($e,{className:"size-4 shrink-0 text-[var(--primary)]"}):null]},c.id)})})]})]})})}function gt(){var A,H,G,Y,V,X,Z,ee,te,se;const x=Fe(),o=Ce(),m=qe(),{slug:r}=Se(),[n,u]=Ee(),[I,c]=d.useState(!1),[K,L]=d.useState(!1),[F,C]=d.useState(!1),[b,be]=d.useState("hybrid"),[S,we]=d.useState(""),[E,B]=d.useState(""),M=d.useRef(null),T=n.get("spaceId")??"",fe=n.get("ingest")==="1",Q=n.get("ingestJobId"),l=R({queryKey:["forge-wiki-settings"],queryFn:Ae}),s=T||((H=(A=l.data)==null?void 0:A.settings.spaces[0])==null?void 0:H.id)||"",P=((G=l.data)==null?void 0:G.settings.embeddingProfiles.filter(t=>t.enabled))??[];d.useEffect(()=>{var t;!E&&((t=P[0])!=null&&t.id)&&B(P[0].id)},[P,E]),d.useEffect(()=>{var t,a;if(!T&&((a=(t=l.data)==null?void 0:t.settings.spaces[0])!=null&&a.id)){const h=new URLSearchParams(n);h.set("spaceId",l.data.settings.spaces[0].id),u(h,{replace:!0})}},[n,T,u,l.data]);const j=R({queryKey:["forge-wiki-home",s],queryFn:()=>He({spaceId:s||void 0}),enabled:!!s&&!r}),g=R({queryKey:["forge-wiki-page-by-slug",s,r],queryFn:()=>Ge({slug:r??"index",spaceId:s||void 0}),enabled:!!s&&!!r}),W=R({queryKey:["forge-wiki-tree",s],queryFn:()=>Ye({spaceId:s||void 0,kind:"wiki"}),enabled:!!s}),k=R({queryKey:["forge-wiki-modal-search",s,b,S,E],queryFn:()=>Ve({spaceId:s||void 0,mode:b,query:S.trim(),profileId:(b==="semantic"||b==="hybrid")&&E||void 0,limit:30}),enabled:I&&!!s&&S.trim().length>0}),$=r?g.data??null:j.data??null,[ye,je]=d.useState(null);d.useEffect(()=>{$&&je($)},[$]);const z=!!s&&(r?g.isFetching:j.isFetching),w=$??(z?ye:null),i=(w==null?void 0:w.page)??null,p=((Y=l.data)==null?void 0:Y.settings.spaces.find(t=>t.id===s))??null,f=((V=l.data)==null?void 0:V.settings.spaces.find(t=>t.visibility==="shared"))??null,ke=!!f&&!!p&&(p==null?void 0:p.id)!==(f==null?void 0:f.id)&&(p==null?void 0:p.visibility)==="personal",q=(i==null?void 0:i.slug)!=="index",y=r&&g.error instanceof Te&&g.error.status===404?r.trim():null;d.useEffect(()=>{if(!s||!y)return;const t=new URLSearchParams;t.set("spaceId",s),t.set("title",y);const a=st(y);a&&t.set("slug",a),o(`/wiki/new?${t.toString()}`,{replace:!0})},[s,y,o]);const _=d.useMemo(()=>((i==null?void 0:i.links)??[]).map(t=>({id:`${t.entityType}:${t.entityId}`,href:De(t.entityType,t.entityId),label:`${t.entityType} · ${t.entityId}`})),[i==null?void 0:i.links]),v=Ue({mutationFn:async t=>Oe(t),onSuccess:async()=>{await Promise.all([m.invalidateQueries({queryKey:["forge-wiki-tree"]}),m.invalidateQueries({queryKey:["forge-wiki-home"]}),m.invalidateQueries({queryKey:["forge-wiki-page-by-slug"]}),m.invalidateQueries({queryKey:["forge-wiki-modal-search"]})]),o(`/wiki${s?`?spaceId=${encodeURIComponent(s)}`:""}`)}}),D=(t,a=!1)=>{const h=new URLSearchParams(n);t(h),u(h,{replace:a})},J=t=>{D(a=>{a.set("ingest","1"),t?a.set("ingestJobId",t):a.delete("ingestJobId"),s&&a.set("spaceId",s)})},ve=()=>{D(t=>{t.delete("ingest"),t.delete("ingestJobId")})},Ne=t=>{D(a=>{a.set("ingest","1"),t?a.set("ingestJobId",t):a.delete("ingestJobId"),s&&a.set("spaceId",s)})},Ie=()=>{!i||!q||v.isPending||!window.confirm(`Delete KarpaWiki page "${i.title}"? You can restore it later from the bin.`)||v.mutateAsync(i.id)};return d.useEffect(()=>{if(!F)return;const t=h=>{var ie;(ie=M.current)!=null&&ie.contains(h.target)||C(!1)},a=h=>{h.key==="Escape"&&C(!1)};return document.addEventListener("pointerdown",t),document.addEventListener("keydown",a),()=>{document.removeEventListener("pointerdown",t),document.removeEventListener("keydown",a)}},[F]),!i&&(l.isLoading||W.isLoading||!r&&j.isLoading||r&&g.isLoading)?e.jsx(O,{eyebrow:"KarpaWiki",title:"Loading the article",description:"Preparing the current space, article, and KarpaWiki index."}):!i&&!y&&(l.isError||j.isError||g.isError||W.isError)?e.jsx(ne,{eyebrow:"KarpaWiki",error:l.error??j.error??g.error??W.error,onRetry:()=>{l.refetch(),j.refetch(),g.refetch(),W.refetch()}}):i?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"px-3 py-4 sm:px-5 lg:px-6",children:e.jsxs("div",{className:"mx-auto flex w-full max-w-[1680px] flex-col gap-4",children:[e.jsxs("section",{className:"wiki-frame px-3 py-3 sm:px-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(oe,{kind:"wiki_page",label:"KarpaWiki page",compact:!0,gradient:!1}),p?e.jsx(oe,{kind:"wiki_space",label:p.label,compact:!0,gradient:!1,wrap:!0,className:"max-w-[20rem]"}):null,e.jsx("span",{className:"text-[11px] uppercase tracking-[0.16em] text-white/42",children:tt(i.updatedAt)}),e.jsx(Me,{metrics:x.snapshot.metrics,className:"ml-auto"})]}),e.jsxs("div",{className:"mt-3 flex flex-col gap-2 lg:flex-row lg:items-center",children:[e.jsxs("button",{type:"button",className:"wiki-search-launch flex min-h-[2.9rem] w-full items-center gap-3 rounded-[18px] border border-white/8 bg-white/[0.04] px-4 text-left text-[14px] text-white/56 transition hover:bg-white/[0.06] hover:text-white lg:flex-1",onClick:()=>c(!0),children:[e.jsx(Pe,{className:"size-4 shrink-0 text-white/44"}),e.jsx("span",{children:"Search KarpaWiki"})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 lg:shrink-0",children:[e.jsxs("button",{type:"button",className:"wiki-space-trigger inline-flex min-h-[2.9rem] items-center gap-2 rounded-[18px] border border-white/8 bg-white/[0.04] px-4 text-[13px] font-medium text-white/78 transition hover:bg-white/[0.07] hover:text-white",onClick:()=>L(!0),children:[e.jsx("span",{className:"text-[11px] uppercase tracking-[0.14em] text-white/38",children:"Space"}),e.jsx("span",{className:"max-w-[16rem] truncate",children:(p==null?void 0:p.label)??"KarpaWiki space"}),e.jsx(ae,{className:"size-3.5 text-white/44"})]}),e.jsxs("div",{className:"relative",ref:M,children:[e.jsxs(U,{variant:"secondary",size:"sm",className:"min-h-[2.9rem]",onClick:()=>C(t=>!t),children:[e.jsx(re,{className:"size-3.5"}),"Ingest",e.jsx(ae,{className:"size-3.5"})]}),F?e.jsxs("div",{className:"absolute right-0 top-[calc(100%+0.5rem)] z-20 grid min-w-[15rem] gap-2 rounded-[22px] border border-white/10 bg-[rgba(9,14,27,0.98)] p-2 shadow-[0_24px_60px_rgba(0,0,0,0.35)]",children:[e.jsxs("button",{type:"button",className:"flex items-start gap-3 rounded-[18px] px-3 py-3 text-left transition hover:bg-white/[0.06]",onClick:()=>{C(!1),J()},children:[e.jsx(re,{className:"mt-0.5 size-4 shrink-0 text-[var(--primary)]"}),e.jsxs("span",{children:[e.jsx("span",{className:"block text-sm font-medium text-white",children:"New ingest"}),e.jsx("span",{className:"mt-1 block text-xs leading-5 text-white/48",children:"Start a fresh import from files, URLs, or pasted text."})]})]}),e.jsxs("button",{type:"button",className:"flex items-start gap-3 rounded-[18px] px-3 py-3 text-left transition hover:bg-white/[0.06]",onClick:()=>{C(!1),o(`/wiki/ingest-history${s?`?spaceId=${encodeURIComponent(s)}`:""}`)},children:[e.jsx(We,{className:"mt-0.5 size-4 shrink-0 text-[var(--secondary)]"}),e.jsxs("span",{children:[e.jsx("span",{className:"block text-sm font-medium text-white",children:"History"}),e.jsx("span",{className:"mt-1 block text-xs leading-5 text-white/48",children:"Browse prior ingests, reopen reviews, and delete old ingest records."})]})]})]}):null]}),e.jsxs(U,{variant:"secondary",size:"sm",className:"min-h-[2.9rem]",onClick:()=>o(`/wiki/edit/${encodeURIComponent(i.id)}?spaceId=${encodeURIComponent(s)}`,{state:{initialPage:i}}),children:[e.jsx(Re,{className:"size-3.5"}),"Edit"]}),e.jsx(Xe,{entityType:"note",entityId:i.id,label:"Open in graph",size:"sm"}),e.jsxs(U,{variant:"secondary",size:"sm",className:N("min-h-[2.9rem] border border-rose-400/18 bg-rose-500/10 text-rose-100 hover:bg-rose-500/18",!q&&"opacity-60"),onClick:Ie,pending:v.isPending,pendingLabel:"Deleting",disabled:!q,title:q?"Delete this KarpaWiki page":"The KarpaWiki home page cannot be deleted",children:[e.jsx(Ke,{className:"size-3.5"}),"Delete"]}),e.jsxs(U,{size:"sm",className:"min-h-[2.9rem]",onClick:()=>o(`/wiki/new?spaceId=${encodeURIComponent(s)}`),children:[e.jsx(Le,{className:"size-3.5"}),"New page"]})]})]}),ke&&f?e.jsxs("div",{className:"mt-3 flex flex-col gap-3 rounded-[22px] border border-amber-300/20 bg-amber-300/[0.08] px-4 py-3 text-[13px] leading-6 text-amber-50 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("span",{children:["You are viewing the personal starter wiki. The recovered people, story, and conversation pages are in"," ",e.jsx("strong",{children:f.label}),"."]}),e.jsx("button",{type:"button",className:"inline-flex min-h-10 shrink-0 items-center justify-center rounded-2xl bg-amber-200 px-4 text-[12px] font-semibold uppercase tracking-[0.14em] text-stone-950 transition hover:bg-amber-100",onClick:()=>{o({pathname:"/wiki",search:`?spaceId=${encodeURIComponent(f.id)}`})},children:"Open shared memory"})]}):null]}),e.jsxs("section",{className:"grid gap-4 lg:grid-cols-[15rem_minmax(0,1fr)] xl:grid-cols-[16rem_minmax(0,1fr)]",children:[e.jsxs("aside",{className:"wiki-frame h-fit px-2 py-3 sm:px-3 lg:sticky lg:top-[5.75rem]",children:[e.jsx("div",{className:"px-2 pb-2 text-[11px] font-semibold uppercase tracking-[0.16em] text-white/42",children:"Index"}),e.jsx(ue,{nodes:((X=W.data)==null?void 0:X.tree)??[],activeSlug:i.slug,spaceId:s})]}),e.jsxs("article",{"aria-busy":z,className:N("wiki-frame relative overflow-hidden px-4 py-5 transition-[opacity,transform] duration-200 sm:px-6 sm:py-6",z&&"opacity-[0.985]"),children:[z?e.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 h-px bg-[linear-gradient(90deg,transparent,rgba(192,193,255,0.8),transparent)] opacity-90"}):null,e.jsxs("div",{className:"wiki-reading-copy wiki-reading-flow mx-auto max-w-[76rem]",children:[v.isError?e.jsx("div",{className:"mb-4 rounded-[18px] border border-rose-400/20 bg-rose-500/10 px-4 py-3 text-sm text-rose-100",children:v.error instanceof Error?v.error.message:"Forge could not delete this KarpaWiki page."}):null,e.jsx(Ze,{markdown:i.contentMarkdown,spaceId:s}),i.summary.trim()?e.jsx("p",{className:"mt-5 border-t border-white/8 pt-4 text-[13px] leading-6 text-white/56",children:i.summary}):null,_.length>0?e.jsxs("section",{className:"mt-8 border-t border-white/8 pt-4",children:[e.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-white/42",children:"Forge links"}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:_.map(t=>e.jsx("a",{href:t.href?Qe(t.href):void 0,className:"rounded-full bg-white/[0.05] px-3 py-1.5 text-[12px] text-white/76 transition hover:bg-white/[0.1] hover:text-white",children:t.label},t.id))})]}):null,w!=null&&w.backlinkSourceNotes.length?e.jsxs("section",{className:"mt-8 border-t border-white/8 pt-4",children:[e.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-white/42",children:"Linked here"}),e.jsx("div",{className:"mt-3 grid gap-2 sm:grid-cols-2",children:w.backlinkSourceNotes.map(t=>e.jsxs(le,{to:{pathname:t.slug==="index"?"/wiki":`/wiki/page/${encodeURIComponent(t.slug)}`,search:`?spaceId=${encodeURIComponent(t.spaceId)}`},className:"rounded-xl border border-white/8 bg-white/[0.03] px-4 py-3 transition hover:bg-white/[0.06]",children:[e.jsx("div",{className:"text-[13px] font-semibold text-white",children:t.title}),t.summary?e.jsx("div",{className:"mt-1 text-[12px] leading-5 text-white/56",children:t.summary}):null]},t.id))})]}):null]})]})]})]})}),e.jsx(ce,{open:I,onOpenChange:c,children:e.jsxs(pe,{children:[e.jsx(me,{className:"fixed inset-0 z-50 bg-[rgba(3,7,18,0.8)] backdrop-blur-sm"}),e.jsxs(xe,{className:"fixed left-1/2 top-[8vh] z-50 w-[min(54rem,calc(100vw-1.5rem))] -translate-x-1/2 rounded-[28px] border border-white/10 bg-[rgba(10,15,28,0.96)] p-4 shadow-[0_30px_90px_rgba(0,0,0,0.45)] sm:p-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsx("div",{children:e.jsx(he,{className:"font-display text-[1.35rem] tracking-[-0.04em] text-white",children:"Search the wiki"})}),e.jsx(ge,{asChild:!0,children:e.jsx("button",{type:"button",className:"rounded-full border border-white/10 bg-white/[0.04] p-2 text-white/64 transition hover:bg-white/[0.08] hover:text-white","aria-label":"Close search",children:e.jsx(de,{className:"size-4"})})})]}),e.jsxs("div",{className:"mt-4 grid gap-3",children:[e.jsx(_e,{autoFocus:!0,value:S,onChange:t=>we(t.target.value),placeholder:"Search KarpaWiki pages",className:"h-11 rounded-2xl border-white/10 bg-white/[0.04] text-[14px] text-white placeholder:text-white/28"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[["text","hybrid","semantic","entity"].map(t=>e.jsx("button",{type:"button",className:N("rounded-full px-3 py-1.5 text-[12px] font-medium uppercase tracking-[0.14em] transition",b===t?"bg-white/[0.12] text-white":"bg-white/[0.04] text-white/54 hover:bg-white/[0.08] hover:text-white"),onClick:()=>be(t),children:t},t)),(b==="semantic"||b==="hybrid")&&P.length>0?e.jsx("select",{className:"ml-auto rounded-full border border-white/10 bg-white/[0.04] px-3 py-1.5 text-[12px] text-white",value:E,onChange:t=>B(t.target.value),children:P.map(t=>e.jsx("option",{value:t.id,children:t.label},t.id))}):null]})]}),e.jsx("div",{className:"mt-4 max-h-[60vh] overflow-y-auto",children:S.trim()?k.isLoading?e.jsx(O,{eyebrow:"KarpaWiki search",title:"Searching",description:"Ranking matching pages for this query."}):k.isError?e.jsx(ne,{eyebrow:"KarpaWiki search",error:k.error,onRetry:()=>void k.refetch()}):(Z=k.data)!=null&&Z.results.length?e.jsx("div",{className:"grid gap-2",children:k.data.results.map(t=>e.jsx("button",{type:"button",className:"rounded-2xl border border-white/8 bg-white/[0.03] px-4 py-3 text-left transition hover:bg-white/[0.06]",onClick:()=>{c(!1),o({pathname:t.page.slug==="index"?"/wiki":`/wiki/page/${encodeURIComponent(t.page.slug)}`,search:`?spaceId=${encodeURIComponent(t.page.spaceId)}`})},children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[14px] font-semibold text-white",children:t.page.title}),t.page.summary?e.jsx("div",{className:"mt-1 text-[12px] leading-5 text-white/56",children:t.page.summary}):null]}),e.jsx(Je,{size:"sm",tone:"meta",children:t.score.toFixed(2)})]})},t.page.id))}):e.jsx("div",{className:"rounded-2xl border border-dashed border-white/10 px-4 py-10 text-center text-[13px] leading-6 text-white/42",children:"No pages matched this search."}):e.jsx("div",{className:"rounded-2xl border border-dashed border-white/10 px-4 py-10 text-center text-[13px] leading-6 text-white/42",children:"Start typing to search the current KarpaWiki space."})})]})]})}),e.jsx(it,{open:K,onOpenChange:L,spaces:((ee=l.data)==null?void 0:ee.settings.spaces)??[],activeSpaceId:s,onSelect:t=>{o({pathname:"/wiki",search:`?spaceId=${encodeURIComponent(t)}`},{replace:!0})}}),e.jsx(et,{open:fe,onOpenChange:t=>{if(t){J(Q);return}ve()},spaces:((te=l.data)==null?void 0:te.settings.spaces)??[],llmProfiles:((se=l.data)==null?void 0:se.settings.llmProfiles)??[],initialSpaceId:s,selectedJobId:Q,onJobSelected:Ne,linkedEntityHints:i.links.map(t=>({entityType:t.entityType,entityId:t.entityId,anchorKey:null}))??[]})]}):y?e.jsx(O,{eyebrow:"KarpaWiki",title:"Opening a new page",description:`Creating a draft for ${y}.`}):e.jsx(Be,{eyebrow:"KarpaWiki",title:"Article not found",description:"This page does not exist in the selected space."})}export{gt as WikiPage};
@@ -1,5 +0,0 @@
1
- import{r as x,j as e,dJ as Ot,dK as Pt,dG as At,dL as Kt,dM as Mt,dN as zt,aG as Wt,dO as $t,cr as ma,c7 as Ke,bX as Ht,br as Me,b2 as ha,aC as xa,bk as ga,ca as ba,cm as fa,dP as va,cc as ya,b5 as ja}from"./vendor-kIz9EZnX.js";import{O as wa}from"./open-in-graph-button-C0TGev7c.js";import{P as ka}from"./page-hero-oFHaAjtL.js";import{fu as Na,a9 as Lt,fv as Ct,fw as Ca,Z as O,aq as V,B as R,F as S,aV as Sa,fx as _a,fy as Ia,b as St,fs as Ta,Q as Fa,fz as Ra,fA as Ea,fB as Oa,fC as Pa,fD as Aa,fE as Ka,fF as Ma,L as za,a as Wa,E as $a}from"./index-BHIKoiZ6.js";import{H as Ha,P as _t,i as La,B as Ba,a as Ua,b as qa,c as Va}from"./graph-BTa79qum.js";import{R as Da,P as Ga,O as Qa,C as Ja,T as Ya,D as Xa,a as Za}from"./ui-CsEkP2V8.js";import{F as es}from"./faceted-token-search-D7xPWfOl.js";import"./state-VYvD1QVP.js";import"./motion-CfdU2F35.js";import"./forms-CmLAyGqz.js";import"./board-DqHzdCPQ.js";const ze=[...Na];function ve(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 Bt(t,i){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(!i.trim())return"";try{return JSON.parse(i)}catch{return i}}if(t==="boolean")return i.trim()?i.trim().toLowerCase()==="true"?!0:i.trim().toLowerCase()==="false"?!1:i:"";if(t==="number"){const s=i.trim();if(!s)return"";const n=Number(s);return Number.isFinite(n)?n:i}return i}function ts(t,i){if(i==null||typeof i=="string"&&i.trim().length===0)return!t.required;switch(t.kind){case"text":case"markdown":case"summary":return typeof i=="string";case"number":return typeof i=="number"&&Number.isFinite(i);case"boolean":return typeof i=="boolean";case"array":case"entity_list":case"record_list":return Array.isArray(i);case"object":case"json":case"record":case"context":case"filters":case"metrics":case"timeline":case"selection":case"entity":return!!i&&typeof i=="object";default:return!0}}function Ut(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 qt(t,i){var d,u,p,o;const s=(l,h)=>l.map(m=>{const f=Ct(m),j=f.key==="primary"?h==="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 Ct({...f,key:j,kind:j===f.key?f.kind:void 0})});if(t.type==="box"||t.type==="box_input"){const l=i.find(h=>h.id===t.data.boxId);return{inputs:s((l==null?void 0:l.inputs)??[],"input"),outputs:(d=l==null?void 0:l.output)!=null&&d.length?s(l.output,"output"):s([{key:"summary",label:"Summary",kind:"summary",description:"Human-readable summary of the box snapshot.",modelName:"WorkbenchBoxSummary"}],"output"),enabledToolKeys:(u=t.data.enabledToolKeys)!=null&&u.length?t.data.enabledToolKeys:((l==null?void 0:l.tools)??[]).map(h=>h.key),boxId:(l==null?void 0:l.id)??t.data.boxId??null}}const n=Ut(t.type);return{inputs:s((p=t.data.inputs)!=null&&p.length?t.data.inputs:n.inputs,"input"),outputs:s((o=t.data.outputs)!=null&&o.length?t.data.outputs:n.outputs,"output"),enabledToolKeys:t.data.enabledToolKeys??[],boxId:t.data.boxId??null}}function as(t,i){var n,d,u;const s=(n=t.data.outputKey)==null?void 0:n.trim();return!s||s==="primary"?((d=i[0])==null?void 0:d.key)??"":i.some(p=>p.key===s)?s:((u=i[0])==null?void 0:u.key)??s}function It(t,i,s){var n,d;return i.length===0?null:!t||t==="primary"?s&&i.some(u=>u.key===s)?s:((n=i[0])==null?void 0:n.key)??null:i.some(u=>u.key===t)?t:s&&i.some(u=>u.key===s)?s:((d=i[0])==null?void 0:d.key)??null}function Ae(t,i){const s=t.graph.nodes.map(u=>{const p=qt(u,i),o={...u,data:{...u.data,inputs:p.inputs,outputs:p.outputs,outputKey:as(u,p.outputs)}};return We(o,i)}),n=new Map(s.map(u=>[u.id,u])),d=t.graph.edges.map(u=>{var m,f,j,v;const p=n.get(u.source),o=n.get(u.target),l=It(u.sourceHandle,(p==null?void 0:p.data.outputs)??[],(f=(m=p==null?void 0:p.data.outputs)==null?void 0:m[0])==null?void 0:f.key),h=It(u.targetHandle,(o==null?void 0:o.data.inputs)??[],(v=(j=o==null?void 0:o.data.inputs)==null?void 0:j[0])==null?void 0:v.key);return Vt({...u,sourceHandle:l,targetHandle:h})});return{nodes:s,edges:d}}function We(t,i){const s=qt(t,i);return{id:t.id,type:"workbench",position:t.position,data:{...t.data,nodeType:t.type==="box_input"?"box":t.type,boxId:s.boxId,enabledToolKeys:s.enabledToolKeys,inputs:s.inputs,outputs:s.outputs,params:t.data.params??[],paramValues:t.data.paramValues??{}}}}function Vt(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 Dt(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 ss(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 Tt(t,i,s){var d;const n=Ut(t);return{id:`node_${crypto.randomUUID().replaceAll("-","").slice(0,8)}`,type:"workbench",position:{x:120+i.length%3*320,y:80+Math.floor(i.length/3)*220},data:{nodeType:t,label:(s==null?void 0:s.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:(s==null?void 0:s.description)??(t==="box"?"Registered Forge box.":t==="chat"?"Conversational flow node.":t==="functor"?"Single transformation node.":"Workbench node."),boxId:(s==null?void 0:s.id)??null,enabledToolKeys:((s==null?void 0:s.tools)??[]).map(u=>u.key),inputs:(s==null?void 0:s.inputs)??n.inputs,outputs:(s==null?void 0:s.output)??n.outputs,params:(s==null?void 0:s.params)??[],paramValues:{},prompt:"",promptTemplate:"",systemPrompt:"",template:"",selectedKey:"",valueType:"string",valueLiteral:"",outputKey:((d=((s==null?void 0:s.output)??n.outputs)[0])==null?void 0:d.key)??"summary",modelConfig:{connectionId:null,provider:null,baseUrl:null,model:"",thinking:null,verbosity:null}}}}function rs(t){return[t.kind,t.modelName,t.itemKind?`item:${t.itemKind}`:null].filter(Boolean).join(" · ")}function ns(t,i){switch(t){case"dirty":return"Unsaved changes";case"saving":return"Saving…";case"saved":return"All changes saved";case"error":return i?`Save failed: ${i}`:"Save failed";default:return"Saved"}}function is(t){const i=crypto.randomUUID().replaceAll("-","").slice(0,4);return{key:`${t}_${i}`,label:t==="input"?"New input":"New output",kind:t==="input"?"context":"record",description:"",required:!1,modelName:t==="input"?"WorkbenchInputContract":"WorkbenchOutputContract"}}function ls(){return{key:`flow_input_${crypto.randomUUID().replaceAll("-","").slice(0,4)}`,label:"New flow input",kind:"text",description:"",required:!1,modelName:"WorkbenchFlowInput",bindings:[]}}function ne(t){return t==="functor"||t==="chat"}function os(t){const i=t instanceof Lt||t instanceof Error?t.message:String(t);return i.includes("No model connection is configured for this connector node.")?["This flow uses an AI node, but Forge does not have any model connection configured yet.","Open Settings > Models, add a model connection, then run the flow again.","Once a model exists, the node can use the default model automatically or you can pick a specific model inside the node editor."].join(`
2
-
3
- `):i}function ds(t){return t.map(({key:i,kind:s,required:n,description:d,modelName:u,itemKind:p,shape:o,exampleValue:l})=>({key:i,kind:s,required:!!n,description:d,modelName:u,itemKind:p,shape:o,exampleValue:l}))}function cs(t){const i=Array.from(new Set(t.map(n=>n.trim()).filter(Boolean)));return(i.includes("answer")?i:["answer",...i]).map(n=>({key:n,label:n==="answer"?"Answer":n.split(/[_-]+/).map(d=>d.charAt(0).toUpperCase()+d.slice(1)).join(" "),kind:n==="answer"?"markdown":"record",description:n==="answer"?"Primary answer returned by this AI node.":`Named output published for downstream nodes under "${n}".`,modelName:n==="answer"?"WorkbenchAiAnswer":`Workbench${n.split(/[_-]+/).map(d=>d.charAt(0).toUpperCase()+d.slice(1)).join("")}`,exampleValue:n==="answer"?"Concise answer":void 0}))}function us(t,i){return Gt(t,i)[0]??null}function Gt(t,i){var p,o;const s=[],n=new Map(t.map(l=>[l.id,l]));t.length===0&&s.push("Add at least one node before running the flow.");const d=t.filter(l=>l.data.nodeType==="output");d.length===0&&s.push("Add an Output node so Forge knows what result the flow should publish.");const u=new Map;for(const l of i){u.set(l.target,(u.get(l.target)??0)+1);const h=n.get(l.source),m=n.get(l.target),f=(h==null?void 0:h.data.outputs)??[],j=(m==null?void 0:m.data.inputs)??[];h&&(l.sourceHandle&&!f.some(v=>v.key===l.sourceHandle)?s.push(`Edge from "${h.data.label}" points to missing output "${l.sourceHandle}". Update the edge or restore that output contract.`):!l.sourceHandle&&f.length>1&&s.push(`Edge from "${h.data.label}" does not name which output it should use. Pick one explicit output handle.`)),m&&(l.targetHandle&&!j.some(v=>v.key===l.targetHandle)?s.push(`Edge into "${m.data.label}" points to missing input "${l.targetHandle}". Update the edge or restore that input contract.`):!l.targetHandle&&j.length>1&&s.push(`Edge into "${m.data.label}" does not name which input it should feed. Pick one explicit input handle.`))}for(const l of d){(u.get(l.id)??0)===0&&s.push(`Connect something into the output node "${l.data.label}" so the flow has something to return.`);const h=i.filter(m=>m.target===l.id).flatMap(m=>{const f=n.get(m.source),j=(f==null?void 0:f.data.outputs)??[];return m.sourceHandle?j.filter(v=>v.key===m.sourceHandle).map(v=>v.key):j.map(v=>v.key)});l.data.outputKey&&h.length>0&&!h.includes(l.data.outputKey)&&s.push(`Output node "${l.data.label}" is configured to publish "${l.data.outputKey}", but that key is not arriving from its upstream nodes.`)}for(const l of t){const h=u.get(l.id)??0,m=i.filter(f=>f.source===l.id).length;l.data.nodeType!=="user_input"&&l.data.nodeType!=="value"&&h===0&&l.data.nodeType!=="box"&&s.push(`Connect an upstream source into "${l.data.label}" so it has real input to work with.`),l.data.nodeType==="merge"&&h<2&&s.push(`Merge node "${l.data.label}" should receive both left and right inputs before you run it.`),l.data.nodeType==="template"&&!(l.data.template??"").trim()&&s.push(`Add a template string to "${l.data.label}" before running the flow.`),l.data.nodeType==="pick_key"&&!(l.data.selectedKey??"").trim()&&s.push(`Choose which key "${l.data.label}" should pick from incoming objects.`),l.data.nodeType!=="output"&&m===0&&s.push(`Connect the output of "${l.data.label}" somewhere useful or remove the node from the graph.`)}for(const l of t)ne(l.data.nodeType)&&!((p=l.data.promptTemplate)!=null&&p.trim()||(o=l.data.prompt)!=null&&o.trim())&&s.push(`Add a prompt to the AI node "${l.data.label}" before running the flow.`);return s}function Ft({title:t,description:i,kind:s,publicInputs:n,nodes:d,edges:u}){return{title:t,description:i,kind:s,publicInputs:n,graph:{nodes:d.map(Dt),edges:u.map(ss)}}}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)]",Qt={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 ps(t){switch(t){case"box":case"box_input":return{icon:e.jsx(ma,{className:"size-4"}),badge:"box"};case"chat":return{icon:e.jsx($t,{className:"size-4"}),badge:"chat"};case"functor":return{icon:e.jsx(Wt,{className:"size-4"}),badge:"functor"};case"output":return{icon:e.jsx(zt,{className:"size-4"}),badge:"output"};case"value":return{icon:e.jsx(Mt,{className:"size-4"}),badge:"value"};case"merge":return{icon:e.jsx(Kt,{className:"size-4"}),badge:"merge"};case"template":return{icon:e.jsx(At,{className:"size-4"}),badge:"template"};case"pick_key":return{icon:e.jsx(Pt,{className:"size-4"}),badge:"pick key"};default:return{icon:e.jsx(Ot,{className:"size-4"}),badge:"input"}}}function ye({kind:t}){return e.jsx("span",{className:O("inline-flex items-center rounded-full border px-2.5 py-1 text-[10px] uppercase tracking-[0.16em]",Qt[t]??"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)]"),children:t.replaceAll("_"," ")})}function W({label:t,onClick:i,emphasis:s=!1}){return e.jsx("button",{type:"button",className:O("rounded-full border px-3 py-1.5 text-[11px] font-medium transition",s?"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:n=>n.stopPropagation(),onClick:n=>{n.stopPropagation(),i()},children:t})}function Rt({side:t,ports:i,collapsed:s}){return e.jsxs("div",{className:"grid gap-1.5",children:[e.jsxs("div",{className:O("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(V,{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"})]}),i.length===0?e.jsx("div",{className:O("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,i.map(n=>e.jsxs("div",{className:O("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",s?"bg-[var(--ui-surface-1)]":"bg-[var(--ui-surface-2)]",Qt[n.kind]??"border-[var(--ui-border-subtle)] text-[var(--ui-ink-soft)]"),children:[e.jsx(Ha,{type:t==="left"?"target":"source",position:t==="left"?_t.Left:_t.Right,id:n.key,className:"!size-2.5 !border",style:{[t]:6,background:"var(--primary)",borderColor:"var(--ui-ink-strong)"}}),s?null:e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{children:n.label}),e.jsx(ye,{kind:n.kind})]}),e.jsx("div",{className:"mt-1 text-[10px] text-[var(--ui-ink-faint)]",children:rs(n)})]})]},`${t}-${n.key}`))]})}function ms(t){var h,m,f,j;const i=Ca(t.data.boxId??null),[s,n]=x.useState(!1),[d,u]=x.useState(!1),p=ps(t.data.nodeType),o=((h=t.data.params)==null?void 0:h.length)??0,l=`${((m=t.data.inputs)==null?void 0:m.length)??0} in · ${((f=t.data.outputs)==null?void 0:f.length)??0} out`;if(i&&t.data.nodeType==="box"){const v=i.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(W,{label:"Edit",onClick:()=>{var w,F;return(F=(w=t.data).onEditRequest)==null?void 0:F.call(w)}}),e.jsx(W,{label:l,onClick:()=>{var w,F;return(F=(w=t.data).onContractEditRequest)==null?void 0:F.call(w)}}),o>0?e.jsx(W,{label:`${o} parameter${o===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:O("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:O("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:[p.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(W,{label:s?"Show ports":"Hide labels",onClick:()=>n(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:p.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:[(j=t.data.enabledToolKeys)!=null&&j.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(W,{label:d?"Hide schema":"Preview schema",onClick:()=>u(v=>!v)}),e.jsx(W,{label:"Edit",onClick:()=>{var v,w;return(w=(v=t.data).onEditRequest)==null?void 0:w.call(v)}}),e.jsx(W,{label:l,onClick:()=>{var v,w;return(w=(v=t.data).onContractEditRequest)==null?void 0:w.call(v)}}),o>0?e.jsx(W,{label:`${o} parameter${o===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(Rt,{side:"left",ports:t.data.inputs??[],collapsed:s}),e.jsx(Rt,{side:"right",ports:t.data.outputs??[],collapsed:s})]}),d?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(V,{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 Jt="grid gap-3 rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",Yt="grid gap-3 rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",hs="grid gap-3 rounded-[16px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",$e="rounded-[18px] border border-dashed border-[var(--ui-border-strong)] px-4 py-3 text-sm text-[var(--ui-ink-faint)]",He="flex items-center gap-2 text-sm font-medium text-[var(--ui-ink-strong)]",Le="text-sm leading-6 text-[var(--ui-ink-soft)]",Xt="flex items-center gap-2 text-sm text-[var(--ui-ink-medium)]";function $(t,i,s){return t.map((n,d)=>d===i?{...n,...s}:n)}function re(t,i,s,n){return t.map((d,u)=>u===i?{...d,shape:(d.shape??[]).map((p,o)=>o===s?{...p,...n}:p)}:d)}function xs(){return{key:`field_${crypto.randomUUID().replaceAll("-","").slice(0,4)}`,label:"New field",kind:"text",required:!1}}function be({title:t,description:i,ports:s,onChange:n,prefix:d}){return e.jsxs("div",{className:Jt,children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:He,children:[e.jsx("span",{children:t}),e.jsx(V,{content:i,label:`Explain ${t.toLowerCase()}`})]}),e.jsx("div",{className:`mt-1 ${Le}`,children:i})]}),e.jsxs(R,{type:"button",variant:"secondary",size:"sm",onClick:()=>n([...s??[],is(d)]),children:["Add ",d]})]}),e.jsxs("div",{className:"grid gap-3",children:[s.length===0?e.jsxs("div",{className:$e,children:["No ",d,"s defined yet."]}):null,s.map((u,p)=>e.jsxs("div",{className:Yt,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(ye,{kind:u.kind}),e.jsx("span",{className:"text-sm font-medium text-[var(--ui-ink-strong)]",children:u.label})]}),e.jsx(R,{type:"button",variant:"ghost",size:"sm",onClick:()=>n(s.filter((o,l)=>l!==p)),children:"Remove"})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsx(S,{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:u.key,onChange:o=>n($(s,p,{key:o.target.value})),className:y})}),e.jsx(S,{label:"Label",description:"Readable name shown in the graph editor.",children:e.jsx("input",{value:u.label,onChange:o=>n($(s,p,{label:o.target.value})),className:y})})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsx(S,{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:u.kind,onChange:o=>n($(s,p,{kind:o.target.value})),className:y,children:ze.map(o=>e.jsx("option",{value:o,children:o.replaceAll("_"," ")},o))})}),e.jsx(S,{label:"Model name",description:"Semantic model name for this port, used in previews and runtime contracts.",children:e.jsx("input",{value:u.modelName??"",onChange:o=>n($(s,p,{modelName:o.target.value||void 0})),placeholder:"WorkbenchTaskSearchResults",className:y})})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsx(S,{label:"Item kind",description:"Optional entity or item subtype when this port carries a collection.",children:e.jsx("input",{value:u.itemKind??"",onChange:o=>n($(s,p,{itemKind:o.target.value||void 0})),placeholder:"task",className:y})}),e.jsx(S,{label:"Example value",description:"Short example shown in collapsed previews.",children:e.jsx("input",{value:u.exampleValue??"",onChange:o=>n($(s,p,{exampleValue:o.target.value||void 0})),placeholder:d==="input"?"task ids and filters":"summarized result",className:y})})]}),e.jsx(S,{label:"Expectation",description:"Describe what should actually be inside this value so the graph stays legible.",children:e.jsx("textarea",{rows:3,value:u.description??"",onChange:o=>n($(s,p,{description:o.target.value||void 0})),placeholder:d==="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:Le,children:"Describe the object structure or list item shape this port carries."}),e.jsx(R,{type:"button",variant:"secondary",size:"sm",onClick:()=>n(s.map((o,l)=>l===p?{...o,shape:[...o.shape??[],xs()]}:o)),children:"Add field"})]}),(u.shape??[]).length===0?e.jsx("div",{className:$e,children:"No explicit structure fields yet."}):null,(u.shape??[]).map((o,l)=>e.jsxs("div",{className:hs,children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx(ye,{kind:o.kind}),e.jsx(R,{type:"button",variant:"ghost",size:"sm",onClick:()=>n(s.map((h,m)=>m===p?{...h,shape:(h.shape??[]).filter((f,j)=>j!==l)}:h)),children:"Remove field"})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsx("input",{value:o.key,onChange:h=>n(re(s,p,l,{key:h.target.value})),placeholder:"field_key",className:y}),e.jsx("input",{value:o.label,onChange:h=>n(re(s,p,l,{label:h.target.value})),placeholder:"Field label",className:y})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsx("select",{value:o.kind,onChange:h=>n(re(s,p,l,{kind:h.target.value})),className:y,children:ze.map(h=>e.jsx("option",{value:h,children:h.replaceAll("_"," ")},h))}),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:!!o.required,onChange:h=>n(re(s,p,l,{required:h.target.checked}))}),"Required field"]})]}),e.jsx("textarea",{rows:2,value:o.description??"",onChange:h=>n(re(s,p,l,{description:h.target.value||void 0})),placeholder:"What should this field contain?",className:y})]},`${u.key}-shape-${o.key}-${l}`))]})]}),e.jsxs("label",{className:Xt,children:[e.jsx("input",{type:"checkbox",checked:!!u.required,onChange:o=>n($(s,p,{required:o.target.checked}))}),"Required port"]})]},`${d}-${u.key}-${p}`))]})]})}function gs({inputs:t,nodes:i,onChange:s}){return e.jsxs("div",{className:Jt,children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:He,children:[e.jsx("span",{children:"Flow inputs"}),e.jsx(V,{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 ${Le}`,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:()=>s([...t??[],ls()]),children:"Add flow input"})]}),t.length===0?e.jsx("div",{className:$e,children:"No public flow inputs defined yet."}):null,e.jsx("div",{className:"grid gap-3",children:t.map((n,d)=>{const u=i.filter(o=>(o.data.inputs??[]).length>0||(o.data.params??[]).length>0),p=o=>s(t.map((l,h)=>h===d?{...l,...o}:l));return e.jsxs("div",{className:Yt,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(ye,{kind:n.kind}),e.jsx("span",{className:"text-sm font-medium text-[var(--ui-ink-strong)]",children:n.label})]}),e.jsx(R,{type:"button",variant:"ghost",size:"sm",onClick:()=>s(t.filter((o,l)=>l!==d)),children:"Remove"})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsx(S,{label:"Key",description:"External API key callers will send.",children:e.jsx("input",{value:n.key,onChange:o=>p({key:o.target.value}),className:y})}),e.jsx(S,{label:"Label",description:"Human-readable name used in the Run modal.",children:e.jsx("input",{value:n.label,onChange:o=>p({label:o.target.value}),className:y})})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsx(S,{label:"Value type",description:"Expected type for this flow input.",children:e.jsx("select",{value:n.kind,onChange:o=>p({kind:o.target.value}),className:y,children:ze.map(o=>e.jsx("option",{value:o,children:o.replaceAll("_"," ")},o))})}),e.jsx(S,{label:"Default value",description:"Used when a caller omits this input.",children:e.jsx("textarea",{rows:3,value:ve(n.defaultValue),onChange:o=>p({defaultValue:Bt(n.kind,o.target.value)}),className:y})})]}),e.jsx(S,{label:"Description",description:"Explain what callers should send here.",children:e.jsx("textarea",{rows:3,value:n.description??"",onChange:o=>p({description:o.target.value}),className:y})}),e.jsxs("label",{className:Xt,children:[e.jsx("input",{type:"checkbox",checked:!!n.required,onChange:o=>p({required:o.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:He,children:["Bindings",e.jsx(V,{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"})]}),(n.bindings??[]).map((o,l)=>{const h=i.find(f=>f.id===o.nodeId)??null,m=o.targetKind==="param"?(h==null?void 0:h.data.params)??[]:(h==null?void 0:h.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:o.nodeId,onChange:f=>p({bindings:(n.bindings??[]).map((j,v)=>v===l?{...j,nodeId:f.target.value,targetKey:""}:j)}),className:y,children:[e.jsx("option",{value:"",children:"Select node"}),u.map(f=>e.jsx("option",{value:f.id,children:f.data.label},f.id))]}),e.jsxs("select",{value:o.targetKind,onChange:f=>p({bindings:(n.bindings??[]).map((j,v)=>v===l?{...j,targetKind:f.target.value,targetKey:""}:j)}),className:y,children:[e.jsx("option",{value:"input",children:"Node input"}),e.jsx("option",{value:"param",children:"Node parameter"})]}),e.jsxs("select",{value:o.targetKey,onChange:f=>p({bindings:(n.bindings??[]).map((j,v)=>v===l?{...j,targetKey:f.target.value}:j)}),className:y,children:[e.jsx("option",{value:"",children:"Select target"}),m.map(f=>e.jsx("option",{value:f.key,children:f.label},f.key))]}),e.jsx(R,{type:"button",variant:"ghost",size:"sm",onClick:()=>p({bindings:(n.bindings??[]).filter((f,j)=>j!==l)}),children:"Remove"})]},`${o.nodeId}-${o.targetKey}-${l}`)}),e.jsx(R,{type:"button",variant:"secondary",size:"sm",onClick:()=>p({bindings:[...n.bindings??[],{nodeId:"",targetKind:"input",targetKey:""}]}),children:"Add binding"})]})]},`${n.key}-${d}`)})})]})}function ie({open:t,onOpenChange:i,title:s,description:n,children:d}){return e.jsx(Da,{open:t,onOpenChange:i,children:e.jsxs(Ga,{children:[e.jsx(Qa,{className:"fixed inset-0 z-50 bg-[var(--ui-overlay-backdrop)] backdrop-blur-sm"}),e.jsxs(Ja,{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(Ya,{className:"font-display text-[1.28rem] tracking-[-0.04em] text-[var(--ui-ink-strong)]",children:s}),n?e.jsx(Xa,{className:"mt-1 text-sm leading-6 text-[var(--ui-ink-soft)]",children:n}):null]}),e.jsx(Za,{asChild:!0,children:e.jsx(Sa,{"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:d})]})]})})}const bs=[{type:"user_input",label:"User input",icon:e.jsx(Ot,{className:"size-4"})},{type:"value",label:"Value",icon:e.jsx(Mt,{className:"size-4"})},{type:"functor",label:"Functor",icon:e.jsx(Wt,{className:"size-4"})},{type:"chat",label:"Chat",icon:e.jsx(ha,{className:"size-4"})},{type:"merge",label:"Merge",icon:e.jsx(Kt,{className:"size-4"})},{type:"template",label:"Template",icon:e.jsx(At,{className:"size-4"})},{type:"pick_key",label:"Pick key",icon:e.jsx(Pt,{className:"size-4"})},{type:"output",label:"Output",icon:e.jsx(zt,{className:"size-4"})}];function fs({open:t,onOpenChange:i,boxQuery:s,onBoxQueryChange:n,boxOptions:d,boxFilters:u,onBoxFiltersChange:p,filteredBoxes:o,onAddNodeType:l,onAddBox:h}){return e.jsx(ie,{open:t,onOpenChange:i,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:bs.map(m=>e.jsxs("button",{type:"button",className:"flex items-center gap-3 rounded-[20px] bg-white/[0.04] px-4 py-3 text-left text-white transition hover:bg-white/[0.08]",onClick:()=>l(m.type),children:[m.icon,e.jsx("span",{children:m.label})]},m.type))}),e.jsx(es,{title:"Forge boxes",description:"",query:s,onQueryChange:n,options:d,selectedOptionIds:u,onSelectedOptionIdsChange:p,resultSummary:`${o.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:o.map(m=>e.jsxs("button",{type:"button",className:"rounded-[20px] bg-white/[0.04] px-4 py-3 text-left transition hover:bg-white/[0.08]",onClick:()=>h(m),children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsx("div",{className:"text-sm font-medium text-white",children:m.title}),e.jsxs("div",{className:"flex shrink-0 flex-wrap gap-2 text-[10px] uppercase tracking-[0.14em] text-white/42",children:[e.jsxs("span",{children:[m.output.length," output",m.output.length===1?"":"s"]}),e.jsxs("span",{children:[m.tools.length," tool",m.tools.length===1?"":"s"]})]})]}),e.jsx("div",{className:"mt-1 text-[12px] leading-5 text-white/50",children:m.description}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx("div",{className:"rounded-full bg-white/[0.05] px-2.5 py-1 text-[11px] text-white/56",children:m.category}),m.routePath?e.jsx("div",{className:"rounded-full bg-white/[0.05] px-2.5 py-1 text-[11px] text-white/56",children:m.routePath}):null]})]},m.id))})]})})}function vs({open:t,onOpenChange:i,title:s,onTitleChange:n,description:d,onDescriptionChange:u,kind:p,onKindChange:o,publicInputs:l,onPublicInputsChange:h,nodes:m,flowId:f,onDelete:j,onSave:v}){return e.jsx(ie,{open:t,onOpenChange:i,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:s,onChange:w=>n(w.target.value),placeholder:"Flow title",className:y}),e.jsx("textarea",{rows:4,value:d,onChange:w=>u(w.target.value),placeholder:"Flow description",className:y}),e.jsxs("select",{value:p,onChange:w=>o(w.target.value),className:y,children:[e.jsx("option",{value:"functor",children:"Functor flow"}),e.jsx("option",{value:"chat",children:"Chat flow"})]}),e.jsx(gs,{inputs:l,nodes:m,onChange:h}),e.jsx("div",{className:"rounded-[18px] border border-white/8 bg-white/[0.03] px-4 py-3 text-sm text-white/58",children:f}),e.jsxs("div",{className:"flex flex-wrap justify-between gap-2 pt-2",children:[e.jsxs(R,{type:"button",variant:"secondary",onClick:()=>{j()},children:[e.jsx(Ke,{className:"size-4"}),"Delete flow"]}),e.jsxs(R,{type:"button",variant:"primary",onClick:()=>{v().then(()=>i(!1))},children:[e.jsx(Ht,{className:"size-4"}),"Save settings"]})]})]})})}function ys(t){if(t.trim())try{return JSON.parse(t)}catch{return t}}function js({open:t,onOpenChange:i,runError:s,graphIssues:n,hasAiNodes:d,modelConnectionCount:u,publicInputs:p,runInputs:o,onRunInputChange:l,shouldShowLegacyUserInput:h,userInput:m,onUserInputChange:f,debugEnabled:j,onDebugEnabledChange:v,onRun:w,onChat:F,runs:I}){return e.jsx(ie,{open:t,onOpenChange:i,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:[s?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:s}):null,!s&&n.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:n.slice(0,4).map(g=>e.jsxs("li",{children:["• ",g]},g))})]}):null,!s&&d&&u===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,p.length>0?e.jsxs("div",{className:"grid gap-3 rounded-[20px] border border-white/8 bg-white/[0.03] p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-white",children:["Flow inputs",e.jsx(V,{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:p.map(g=>e.jsx(S,{label:g.label,description:g.description||"Typed input for this flow.",children:g.kind==="boolean"?e.jsxs("label",{className:"flex items-center gap-2 text-sm text-white/68",children:[e.jsx("input",{type:"checkbox",checked:!!o[g.key],onChange:_=>l(g.key,_.target.checked)}),g.label]}):g.kind==="number"?e.jsx("input",{type:"number",value:typeof o[g.key]=="number"?String(o[g.key]):"",onChange:_=>l(g.key,_.target.value.trim().length===0?void 0:Number(_.target.value)),className:y}):g.kind==="array"||g.kind==="entity_list"||g.kind==="record_list"||g.kind==="object"||g.kind==="json"||g.kind==="record"||g.kind==="context"||g.kind==="filters"||g.kind==="metrics"||g.kind==="timeline"||g.kind==="selection"||g.kind==="entity"?e.jsx("textarea",{rows:4,value:ve(o[g.key]),onChange:_=>l(g.key,ys(_.target.value)),placeholder:'{"key":"value"}',className:y}):e.jsx("input",{value:typeof o[g.key]=="string"?o[g.key]:"",onChange:_=>l(g.key,_.target.value),placeholder:g.exampleValue||g.label,className:y})},g.key))})]}):null,h?e.jsx("textarea",{rows:5,value:m,onChange:g=>f(g.target.value),placeholder:"User input",className:y}):null,e.jsxs("label",{className:"flex items-center gap-2 text-sm text-white/64",children:[e.jsx("input",{type:"checkbox",checked:j,onChange:g=>v(g.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(Me,{className:"size-4"}),"Run"]}),e.jsxs(R,{type:"button",variant:"secondary",onClick:F,children:[e.jsx($t,{className:"size-4"}),"Chat"]})]}),e.jsx("div",{className:"grid gap-2 pt-2",children:I.slice(0,5).map(g=>{var _;return e.jsxs("div",{className:"rounded-[18px] border border-white/8 bg-white/[0.04] px-4 py-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 text-[12px] text-white/48",children:[e.jsx("span",{children:g.mode}),e.jsx("span",{children:new Date(g.createdAt).toLocaleString()})]}),e.jsx("div",{className:"mt-2 text-sm text-white/78",children:((_=g.result)==null?void 0:_.primaryText)??g.error??"No output yet."})]},g.id)})})]})})}function je(t){switch(t){case"exec":return 4;case"read_write":return 3;case"write":return 2;case"read":default:return 1}}function ws(t,i){return je(t)>=je(i)?t:i}function Et(t,i){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.":i.sort((s,n)=>n.length-s.length)[0]??"Workbench tool"}function ks(t){const i=new Map;for(const s of t)for(const n of s.tools){const d=i.get(n.key);if(!d){i.set(n.key,{key:n.key,label:n.label,description:Et(n.key,[n.description]),accessMode:n.accessMode,argsSchema:n.argsSchema,sources:[s.title],sourceSurfaceIds:s.surfaceId?[s.surfaceId]:[]});continue}d.accessMode=ws(d.accessMode,n.accessMode),d.label=d.label.length>=n.label.length?d.label:n.label,d.description=Et(n.key,[d.description,n.description]),d.argsSchema=d.argsSchema??n.argsSchema,d.sources.includes(s.title)||d.sources.push(s.title),s.surfaceId&&!d.sourceSurfaceIds.includes(s.surfaceId)&&d.sourceSurfaceIds.push(s.surfaceId)}return[...i.values()].sort((s,n)=>{const d=je(n.accessMode)-je(s.accessMode);return d!==0?d:s.label.localeCompare(n.label)})}const Ns={workbench:ms},fe="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 Cs(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 Ss({flow:t,boxes:i,modelConnections:s,runs:n,onSave:d,onDelete:u,onRun:p,onChat:o}){var st,rt,nt,it,lt,ot,dt,ct,ut,pt,mt,ht,xt,gt,bt,ft,vt,yt,jt,wt,kt,Nt;const[l,h]=x.useState(t.title),[m,f]=x.useState(t.description),[j,v]=x.useState(t.kind),[w,F]=x.useState(t.publicInputs??[]),[I,g]=x.useState(()=>Ae(t,i).nodes),[_,J]=x.useState(()=>Ae(t,i).edges),[le,we]=x.useState(null),[Zt,oe]=x.useState(!1),[Be,H]=x.useState(!1),[de,ce]=x.useState("overview"),[ea,ke]=x.useState(void 0),[ta,ue]=x.useState(!1),[aa,Ue]=x.useState(!1),[Ne,Ce]=x.useState(!1),[Se,sa]=x.useState(""),[_e,ra]=x.useState([]),[Ie,na]=x.useState(""),[qe,Ve]=x.useState({}),[Te,ia]=x.useState(!0),[la,L]=x.useState(null),[Fe,B]=x.useState("idle"),[oa,pe]=x.useState(null),[D,De]=x.useState(((st=n[0])==null?void 0:st.id)??null),[me,Ge]=x.useState(null),P=x.useMemo(()=>JSON.stringify(Ft({title:t.title,description:t.description,kind:t.kind,publicInputs:t.publicInputs??[],nodes:t.graph.nodes.map(a=>We(a,i)),edges:t.graph.edges.map(Vt)})),[i,t]),G=x.useRef(P),Re=x.useRef(P),Qe=x.useRef({}),he=x.useRef(P),xe=x.useRef(null),ge=x.useRef(!1);x.useEffect(()=>{if(P===Re.current)return;Re.current=P,G.current=P,he.current=P,h(t.title),f(t.description),v(t.kind),F(t.publicInputs??[]);const a=Ae(t,i);g(a.nodes),J(a.edges),B("idle"),pe(null)},[i,t,P]),x.useEffect(()=>{Ve(Object.fromEntries((t.publicInputs??[]).filter(a=>a.defaultValue!==void 0).map(a=>[a.key,a.defaultValue])))},[t.publicInputs]),x.useEffect(()=>{var a;De(((a=n[0])==null?void 0:a.id)??null)},[n]),x.useEffect(()=>{g(a=>a.map(r=>r.data.nodeType!=="box"||!r.data.boxId?r:We(Dt(r),i)))},[i]);const da=x.useMemo(()=>Array.from(new Set(i.map(r=>r.category))).map(r=>({id:`category:${r}`,label:r,description:"Workbench box category"})),[i]),ca=x.useMemo(()=>{const a=Se.trim().toLowerCase();return i.filter(r=>{const c=a.length===0||[r.title,r.description,r.category,r.routePath??"",...r.tags].join(" ").toLowerCase().includes(a),N=_e.every(C=>C.startsWith("category:")?r.category===C.replace("category:",""):!0);return c&&N})},[_e,Se,i]),b=x.useMemo(()=>I.find(a=>a.id===le)??null,[I,le]),Y=n[0]??null,U=n.find(a=>a.id===D)??Y??null,Q=_a({flowId:t.id,runId:D??""},{skip:!D||!Ne}),A=((rt=Q.data)==null?void 0:rt.nodeResults.find(a=>a.nodeId===me))??null,K=Ia({flowId:t.id,runId:D??"",nodeId:me??""},{skip:!D||!me||!Ne}),Ee=x.useMemo(()=>Gt(I,_),[I,_]),Je=x.useMemo(()=>I.some(a=>ne(a.data.nodeType)),[I]),Oe=x.useMemo(()=>I.some(a=>a.data.nodeType==="user_input")||(w??[]).length===0,[I,w]);x.useEffect(()=>{var r,c;const a=((c=(r=Q.data)==null?void 0:r.nodeResults[0])==null?void 0:c.nodeId)??null;Ge(a)},[(nt=Q.data)==null?void 0:nt.nodeResults]);const Ye=x.useMemo(()=>!!(b&&b.data.nodeType!=="box"&&b.data.nodeType!=="box_input"),[b]),Xe=x.useMemo(()=>b?_.filter(a=>a.target===b.id).flatMap(a=>{const r=I.find(N=>N.id===a.source),c=(r==null?void 0:r.data.outputs)??[];return a.sourceHandle?c.filter(N=>N.key===a.sourceHandle):c}):[],[_,I,b]),X=x.useMemo(()=>ks(i),[i]),Z=x.useMemo(()=>{if(!b||!ne(b.data.nodeType))return[];const a=new Set(b.data.enabledToolKeys??[]);return X.filter(r=>a.has(r.key))},[X,b]),Pe=x.useMemo(()=>Ft({title:l,description:m,kind:j,publicInputs:w,nodes:I,edges:_}),[m,_,j,I,w,l]),ee=x.useMemo(()=>JSON.stringify(Pe),[Pe]),Ze=ee!==G.current;x.useEffect(()=>{if(Qe.current=Pe,he.current=ee,ee===G.current){pe(null),B(a=>a==="saved"?a:"idle");return}B(a=>a==="saving"?a:"dirty")},[ee]);const ua=x.useMemo(()=>!b||!ne(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,r)=>e.jsxs(e.Fragment,{children:[e.jsx(S,{label:"Label",description:"This is the name shown on the canvas and in debug traces.",children:e.jsx("input",{value:a.label,onChange:c=>r({label:c.target.value}),className:y})}),e.jsx(S,{label:"Description",description:"Explain what this node should do with the incoming flow context.",children:e.jsx("textarea",{rows:4,value:a.description,onChange:c=>r({description:c.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,r)=>e.jsxs(e.Fragment,{children:[e.jsx(S,{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:c=>r({promptTemplate:c.target.value,prompt:c.target.value}),className:y})}),e.jsx(S,{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:c=>r({systemPrompt:c.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,r)=>{var c,N,C;return e.jsxs(e.Fragment,{children:[s.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(S,{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:((c=a.modelConfig)==null?void 0:c.connectionId)??"",onChange:k=>{var M,z;const T=s.find(q=>q.id===k.target.value);r({modelConfig:{connectionId:(T==null?void 0:T.id)??null,provider:(T==null?void 0:T.provider)??null,baseUrl:(T==null?void 0:T.baseUrl)??null,model:(T==null?void 0:T.model)??"",thinking:((M=a.modelConfig)==null?void 0:M.thinking)??null,verbosity:((z=a.modelConfig)==null?void 0:z.verbosity)??null}})},className:y,children:[e.jsx("option",{value:"",children:"Use Forge default model"}),s.map(k=>e.jsx("option",{value:k.id,children:k.label},k.id))]})}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsx(S,{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:k=>{var T,M,z,q,se;return r({modelConfig:{connectionId:((T=a.modelConfig)==null?void 0:T.connectionId)??null,provider:((M=a.modelConfig)==null?void 0:M.provider)??null,baseUrl:((z=a.modelConfig)==null?void 0:z.baseUrl)??null,model:((q=a.modelConfig)==null?void 0:q.model)??"",thinking:k.target.value||null,verbosity:((se=a.modelConfig)==null?void 0:se.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(S,{label:"Verbosity",description:"Optional output detail setting for models that support it.",children:e.jsxs("select",{value:((C=a.modelConfig)==null?void 0:C.verbosity)??"",onChange:k=>{var T,M,z,q,se;return r({modelConfig:{connectionId:((T=a.modelConfig)==null?void 0:T.connectionId)??null,provider:((M=a.modelConfig)==null?void 0:M.provider)??null,baseUrl:((z=a.modelConfig)==null?void 0:z.baseUrl)??null,model:((q=a.modelConfig)==null?void 0:q.model)??"",thinking:((se=a.modelConfig)==null?void 0:se.thinking)??null,verbosity:k.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,r)=>e.jsxs("div",{className:"grid gap-4",children:[e.jsx(be,{title:"Inputs",description:"Name the upstream values this AI node expects to receive.",ports:a.inputs??[],onChange:c=>r({inputs:c}),prefix:"input"}),e.jsx(be,{title:"Outputs",description:"Describe exactly what this AI node will publish for later nodes.",ports:a.outputs??[],onChange:c=>r({outputs:c}),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,r)=>e.jsxs(e.Fragment,{children:[e.jsx(S,{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:X.length>0?X.map(c=>{const N=(a.enabledToolKeys??[]).includes(c.key);return e.jsxs("label",{className:"flex items-start gap-3 rounded-[16px] bg-white/[0.03] px-3 py-2 text-left",children:[e.jsx("input",{type:"checkbox",checked:N,onChange:C=>{const k=new Set(a.enabledToolKeys??[]);C.target.checked?k.add(c.key):k.delete(c.key),r({enabledToolKeys:[...k]})}}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-white",children:[e.jsx("span",{children:c.label}),e.jsx("span",{className:"rounded-full bg-white/[0.06] px-2 py-0.5 text-[10px] uppercase tracking-[0.16em] text-white/48",children:c.accessMode.replace("_"," ")})]}),e.jsx("div",{className:"text-[12px] leading-5 text-white/46",children:c.description}),c.sources.length>0?e.jsx("div",{className:"mt-2 flex flex-wrap gap-2",children:c.sources.map(C=>e.jsx("span",{className:"rounded-full bg-white/[0.05] px-2 py-1 text-[10px] text-white/44",children:C},`${c.key}-${C}`))}):null,e.jsx("div",{className:"mt-1 font-mono text-[10px] text-white/32",children:c.key}),c.argsSchema?e.jsxs("details",{className:"mt-2 rounded-[14px] border border-white/8 bg-black/20 px-3 py-2",children:[e.jsx("summary",{className:"cursor-pointer text-[11px] text-white/56",children:"Preview tool arguments"}),e.jsx("pre",{className:"mt-2 overflow-auto whitespace-pre-wrap text-[10px] leading-5 text-white/44",children:JSON.stringify(c.argsSchema,null,2)})]}):null]})]},c.key)}):e.jsx("div",{className:"text-sm text-white/48",children:"No registered Forge tools are available yet."})})}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsx(S,{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-white/8 bg-black/20 px-4 py-3",children:[e.jsx("summary",{className:"cursor-pointer text-sm text-white/70",children:Z.length>0?`${Z.length} tool contract${Z.length===1?"":"s"}`:"No tool contract yet"}),e.jsx("pre",{className:"mt-3 overflow-auto whitespace-pre-wrap text-[11px] leading-5 text-white/58",children:JSON.stringify(Z.map(c=>({key:c.key,label:c.label,accessMode:c.accessMode,sources:c.sources,argsSchema:c.argsSchema})),null,2)})]})}),e.jsx(S,{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-white/8 bg-black/20 px-4 py-3",children:[e.jsxs("summary",{className:"cursor-pointer text-sm text-white/70",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-white/58",children:JSON.stringify(ds(a.outputs??[]),null,2)})]})})]}),e.jsx(S,{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(c=>c.key!=="answer").map(c=>c.key).join(", "),onChange:c=>r({outputs:cs(["answer",...c.target.value.split(",")])}),placeholder:"summary, plan, next_steps",className:y})}),e.jsxs("div",{className:"rounded-[20px] border border-white/8 bg-white/[0.03] p-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/40",children:"Danger zone"}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-white/58",children:"Remove this node from the graph if you no longer need it."}),e.jsxs(R,{type:"button",variant:"secondary",className:"mt-4",onClick:()=>{et(b.id),H(!1)},children:[e.jsx(Ke,{className:"size-4"}),"Delete node"]})]})]})}],[X,s,Z,b]),te=x.useCallback(async()=>{const a=he.current,r=Qe.current;if(a===G.current)return B("saved"),!0;if(xe.current)return ge.current=!0,xe.current;B("saving"),pe(null);const c=d(r).then(()=>(G.current=a,Re.current=a,B("saved"),!0)).catch(N=>{const C=N instanceof Lt||N instanceof Error?N.message:String(N);return pe(C),B("error"),!1}).finally(()=>{xe.current=null,ge.current&&he.current!==G.current?(ge.current=!1,te()):ge.current=!1});return xe.current=c,c},[d]);x.useEffect(()=>{if(!Ze)return;const a=window.setTimeout(()=>{te()},2e3);return()=>window.clearTimeout(a)},[Ze,te,ee]);const ae=x.useCallback((a,r="overview")=>{we(a),ce(r),ke(r==="contracts"?"contracts":"overview"),H(!0)},[]),pa=x.useMemo(()=>I.map(a=>({...a,data:{...a.data,onEditRequest:()=>ae(a.id,"overview"),onContractEditRequest:()=>ae(a.id,"contracts"),onParameterEditRequest:()=>ae(a.id,"parameters")}})),[I,ae]);function E(a){le&&g(r=>r.map(c=>c.id===le?a(c):c))}function et(a){g(r=>r.filter(c=>c.id!==a)),J(r=>r.filter(c=>c.source!==a&&c.target!==a)),we(r=>r===a?null:r)}async function tt(){await te()}async function at(a){if(!await te()){L("Forge could not save the latest flow changes before running. Fix the save error and try again.");return}const c=us(I,_);if(c){L(c);return}if(Je&&s.length===0){L(["This flow includes an AI node, but no model is configured in Forge yet.","Open Settings > Models, add a model connection, then try again."].join(`
4
-
5
- `));return}L(null);const N={};for(const C of w){const k=qe[C.key];if(!ts(C,k)){L(`Flow input "${C.label}" must match the ${C.kind} type.`);return}k!=null&&!(typeof k=="string"&&k.trim().length===0)&&(N[C.key]=k)}try{a==="run"?await p({userInput:Oe?Ie:"",inputs:N,debug:Te}):await o({userInput:Oe?Ie:"",inputs:N,debug:Te}),ue(!1)}catch(C){L(os(C))}}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(xa,{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(ga,{className:"size-4"}),"Flows"]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx(St,{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:l})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(St,{kind:Ta(j),label:j==="chat"?"Chat flow":"Functor flow",compact:!0,gradient:!1}),e.jsx("div",{className:O("rounded-full border px-3 py-2 text-[12px]",Cs(Fe)),children:ns(Fe,oa)}),Y?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:()=>Ce(!0),children:["Latest ",Y.mode," · ",Y.status]}):null,e.jsxs(R,{type:"button",variant:"secondary",onClick:()=>ue(!0),children:[e.jsx(Me,{className:"size-4"}),"Run"]}),e.jsxs(R,{type:"button",variant:"primary",pending:Fe==="saving",pendingLabel:"Saving…",onClick:()=>void tt(),children:[e.jsx(Ht,{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:[Ee.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(V,{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:Ee.map(a=>e.jsx("li",{className:"list-inside list-disc",children:a},a))})]}):null,e.jsx(La,{nodeTypes:Ns,nodes:pa,edges:_,onNodesChange:a=>g(r=>Va(a,r)),onEdgesChange:a=>J(r=>qa(a,r)),onConnect:a=>J(r=>Ua({...a,id:`edge_${crypto.randomUUID().replaceAll("-","").slice(0,8)}`,style:{stroke:"color-mix(in srgb, var(--primary) 44%, transparent)",strokeWidth:1.6}},r)),onEdgeClick:(a,r)=>{J(c=>c.filter(N=>N.id!==r.id))},onNodeClick:(a,r)=>{we(r.id)},onNodeDoubleClick:(a,r)=>{ae(r.id,"overview")},fitView:!0,proOptions:{hideAttribution:!0},className:"bg-transparent",children:e.jsx(Ba,{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:fe,onClick:()=>oe(!0),children:[e.jsx(ba,{className:"size-4"}),"Add node"]}),e.jsxs("button",{type:"button",className:fe,onClick:()=>Ue(!0),children:[e.jsx(fa,{className:"size-4"}),"Flow settings"]}),e.jsxs("button",{type:"button",className:fe,onClick:()=>ue(!0),children:[e.jsx(Me,{className:"size-4"}),"Run flow"]}),Y?e.jsxs("button",{type:"button",className:fe,onClick:()=>Ce(!0),children:[e.jsx(va,{className:"size-4"}),"Latest trace"]}):null]})})]}),e.jsx(fs,{open:Zt,onOpenChange:oe,boxQuery:Se,onBoxQueryChange:sa,boxOptions:da,boxFilters:_e,onBoxFiltersChange:ra,filteredBoxes:ca,onAddNodeType:a=>{g(r=>[...r,Tt(a,r)]),oe(!1)},onAddBox:a=>{g(r=>[...r,Tt("box",r,a)]),oe(!1)}}),b&&ne(b.data.nodeType)?e.jsx(Fa,{open:Be,onOpenChange:a=>{H(a),a||ke(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=>E(r=>({...r,data:a})),draftPersistenceKey:`workbench.ai-node.${b.id}`,steps:ua,initialStepId:ea,onSubmit:async()=>{H(!1),ke(void 0)},submitLabel:"Done",contentClassName:"md:w-[min(60rem,calc(100vw-1.5rem))]"}):e.jsx(ie,{open:Be,onOpenChange:a=>{H(a),a||ce("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"||Ye).filter(a=>{var r;return a.id!=="parameters"||(((r=b.data.params)==null?void 0:r.length)??0)>0}).map(a=>e.jsx("button",{type:"button",className:O("rounded-full px-3 py-2 text-sm transition",de===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:()=>ce(a.id),children:a.label},a.id))}),de==="overview"?e.jsxs("div",{className:"grid gap-3",children:[e.jsx("input",{value:b.data.label,onChange:a=>E(r=>({...r,data:{...r.data,label:a.target.value}})),className:y}),e.jsx("textarea",{rows:3,value:b.data.description,onChange:a=>E(r=>({...r,data:{...r.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 r=i.find(c=>c.id===a.target.value);E(c=>({...c,data:{...c.data,boxId:a.target.value,label:(r==null?void 0:r.title)??c.data.label,description:(r==null?void 0:r.description)??c.data.description,inputs:(r==null?void 0:r.inputs)??[],outputs:(r==null?void 0:r.output)??[],params:(r==null?void 0:r.params)??[],enabledToolKeys:((r==null?void 0:r.tools)??[]).map(N=>N.key)}}))},className:y,children:[e.jsx("option",{value:"",children:"Select Forge box"}),i.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=>E(r=>({...r,data:{...r.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=>E(r=>({...r,data:{...r.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=>E(r=>({...r,data:{...r.data,outputKey:a.target.value}})),className:y,children:Xe.length>0?Xe.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-white/8 bg-white/[0.03] px-4 py-3 text-sm leading-6 text-white/58",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=>E(r=>({...r,data:{...r.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=>E(r=>({...r,data:{...r.data,valueLiteral:a.target.value}})),placeholder:"Value literal or JSON",className:y})]}):null]}):null,de==="contracts"?Ye?e.jsxs("div",{className:"grid gap-4",children:[e.jsx(be,{title:"Inputs",description:"Name the values this node expects so upstream wiring stays obvious.",ports:b.data.inputs??[],onChange:a=>E(r=>({...r,data:{...r.data,inputs:a}})),prefix:"input"}),e.jsx(be,{title:"Outputs",description:"Describe exactly what this node publishes, including semantic model names.",ports:b.data.outputs??[],onChange:a=>E(r=>({...r,data:{...r.data,outputs:a}})),prefix:"output"})]}):e.jsx("div",{className:"rounded-[20px] border border-white/8 bg-white/[0.03] px-4 py-4 text-sm leading-6 text-white/58",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,de==="parameters"?e.jsxs("div",{className:"grid gap-3",children:[(b.data.params??[]).length===0?e.jsx("div",{className:"rounded-[20px] border border-white/8 bg-white/[0.03] px-4 py-4 text-sm leading-6 text-white/58",children:"This node does not expose any configurable parameters."}):null,(b.data.params??[]).map(a=>{var r,c,N;return e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/40",children:a.label}),a.kind==="boolean"?e.jsxs("label",{className:"flex items-center gap-3 rounded-[18px] border border-white/10 bg-black/20 px-4 py-3 text-sm text-white",children:[e.jsx("input",{type:"checkbox",checked:!!((r=b.data.paramValues)!=null&&r[a.key]),onChange:C=>E(k=>({...k,data:{...k.data,paramValues:{...k.data.paramValues??{},[a.key]:C.target.checked}}}))}),a.description??"Enabled"]}):a.kind==="array"||a.kind==="json"?e.jsx("textarea",{value:ve((c=b.data.paramValues)==null?void 0:c[a.key]),onChange:C=>E(k=>({...k,data:{...k.data,paramValues:{...k.data.paramValues??{},[a.key]:C.target.value}}})),placeholder:a.description??a.label,className:O(y,"min-h-[104px] resize-y")}):e.jsx("input",{type:a.kind==="number"?"number":"text",value:ve((N=b.data.paramValues)==null?void 0:N[a.key]),onChange:C=>E(k=>({...k,data:{...k.data,paramValues:{...k.data.paramValues??{},[a.key]:Bt(a.kind,C.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:()=>{et(b.id),H(!1)},children:[e.jsx(Ke,{className:"size-4"}),"Delete node"]}),e.jsx(R,{type:"button",variant:"primary",onClick:()=>{H(!1),ce("overview")},children:"Done"})]})]}):null}),e.jsx(vs,{open:aa,onOpenChange:Ue,title:l,onTitleChange:h,description:m,onDescriptionChange:f,kind:j,onKindChange:v,publicInputs:w,onPublicInputsChange:F,nodes:I,flowId:t.id,onDelete:u,onSave:tt}),e.jsx(js,{open:ta,onOpenChange:a=>{ue(a),a&&L(null)},runError:la,graphIssues:Ee,hasAiNodes:Je,modelConnectionCount:s.length,publicInputs:w,runInputs:qe,onRunInputChange:(a,r)=>Ve(c=>({...c,[a]:r})),shouldShowLegacyUserInput:Oe,userInput:Ie,onUserInputChange:na,debugEnabled:Te,onDebugEnabledChange:ia,onRun:()=>void at("run"),onChat:()=>void at("chat"),runs:n}),e.jsx(ie,{open:Ne,onOpenChange:Ce,title:"Run inspector",description:"Inspect whole-flow outputs and stable node-level results for any saved run.",children:U?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-white/8 bg-white/[0.04] p-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/42",children:"Run history"}),e.jsx("div",{className:"mt-3 grid gap-2",children:n.slice(0,12).map(a=>{var r;return e.jsxs("button",{type:"button",className:O("rounded-[18px] border px-4 py-3 text-left transition",D===a.id?"border-[var(--secondary)]/40 bg-[var(--secondary)]/12":"border-white/8 bg-black/20 hover:bg-white/[0.05]"),onClick:()=>De(a.id),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 text-[12px] text-white/50",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-white/80",children:((r=a.result)==null?void 0:r.primaryText)??a.error??"No output yet."})]},a.id)})})]}),e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("div",{className:"rounded-[20px] border border-white/8 bg-white/[0.04] p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 text-[12px] text-white/50",children:[e.jsx("span",{children:U.mode}),e.jsx("span",{children:new Date(U.createdAt).toLocaleString()})]}),e.jsx("div",{className:"mt-3 text-sm leading-6 text-white/82",children:((it=U.result)==null?void 0:it.primaryText)??U.error??"No output yet."}),(lt=U.result)!=null&&lt.outputs?e.jsxs("details",{className:"mt-3 rounded-[16px] bg-black/20 p-3",children:[e.jsx("summary",{className:"cursor-pointer text-[11px] uppercase tracking-[0.16em] text-white/38",children:"Published outputs"}),e.jsx("pre",{className:"mt-3 overflow-auto whitespace-pre-wrap text-[12px] leading-5 text-white/66",children:JSON.stringify(U.result.outputs,null,2)})]}):null]}),(((ot=Q.data)==null?void 0:ot.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-white/8 bg-white/[0.04] p-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/42",children:"Node results"}),e.jsx("div",{className:"mt-3 grid gap-2",children:(((dt=Q.data)==null?void 0:dt.nodeResults)??[]).map(a=>e.jsx("button",{type:"button",className:O("rounded-[18px] border px-4 py-3 text-left transition",me===a.nodeId?"border-[var(--secondary)]/40 bg-[var(--secondary)]/12":"border-white/8 bg-black/20 hover:bg-white/[0.05]"),onClick:()=>Ge(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-white",children:a.label}),e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-white/40",children:a.nodeType})]}),e.jsxs("div",{className:"rounded-full bg-white/[0.05] px-3 py-1 text-[11px] text-white/56",children:[Object.keys(a.outputMap).length," outputs"]})]})},a.nodeId))})]}),e.jsx("div",{className:"rounded-[20px] border border-white/8 bg-white/[0.04] p-4",children:A||(ct=K.data)!=null&&ct.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-white",children:(pt=((ut=K.data)==null?void 0:ut.nodeResult)??A)==null?void 0:pt.label}),e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-white/38",children:(ht=((mt=K.data)==null?void 0:mt.nodeResult)??A)==null?void 0:ht.nodeType})]}),e.jsxs("div",{className:"rounded-full bg-white/[0.05] px-3 py-1 text-[11px] text-white/56",children:[(((gt=((xt=K.data)==null?void 0:xt.nodeResult)??A)==null?void 0:gt.tools)??[]).length," ","tool",(((ft=((bt=K.data)==null?void 0:bt.nodeResult)??A)==null?void 0:ft.tools)??[]).length===1?"":"s"]})]}),e.jsxs("div",{className:"mt-3 grid gap-3",children:[e.jsxs("details",{className:"rounded-[16px] bg-black/20 p-3",children:[e.jsx("summary",{className:"cursor-pointer text-[11px] uppercase tracking-[0.16em] text-white/38",children:"Inputs"}),e.jsx("pre",{className:"mt-3 overflow-auto whitespace-pre-wrap text-[12px] leading-5 text-white/66",children:JSON.stringify(((yt=((vt=K.data)==null?void 0:vt.nodeResult)??A)==null?void 0:yt.input)??[],null,2)})]}),e.jsxs("details",{className:"rounded-[16px] bg-black/20 p-3",children:[e.jsx("summary",{className:"cursor-pointer text-[11px] uppercase tracking-[0.16em] text-white/38",children:"Output map"}),e.jsx("pre",{className:"mt-3 overflow-auto whitespace-pre-wrap text-[12px] leading-5 text-white/66",children:JSON.stringify(((wt=((jt=K.data)==null?void 0:jt.nodeResult)??A)==null?void 0:wt.outputMap)??{},null,2)})]}),e.jsxs("details",{className:"rounded-[16px] bg-black/20 p-3",children:[e.jsx("summary",{className:"cursor-pointer text-[11px] uppercase tracking-[0.16em] text-white/38",children:"Payload"}),e.jsx("pre",{className:"mt-3 overflow-auto whitespace-pre-wrap text-[12px] leading-5 text-white/66",children:JSON.stringify(((Nt=((kt=K.data)==null?void 0:kt.nodeResult)??A)==null?void 0:Nt.payload)??null,null,2)})]})]})]}):e.jsx("div",{className:"text-sm text-white/56",children:"Pick a node result to inspect its resolved inputs and outputs."})})]}):e.jsx("div",{className:"rounded-[20px] border border-white/8 bg-white/[0.04] p-4 text-sm text-white/56",children:Q.isFetching?"Loading node results…":"This run does not have stored node results yet."})]})]})}):e.jsx("div",{className:"text-sm text-white/56",children:"Run the flow once to inspect its published outputs and node-level results here."})})]})}function zs(){const t=ya(),i=ja(),s=t.flowId??"",n=Ra(),d=Ea(s,{skip:s.length===0}),u=Oa(),[p]=Pa(),[o]=Aa(),[l]=Ka(),[h]=Ma();return d.isLoading||u.isLoading?e.jsx(za,{eyebrow:"Workbench Flow",title:"Loading flow",description:"Preparing the Workbench graph editor."}):d.isError||u.isError||!d.data?!d.data&&!d.isError&&!u.isError?e.jsx(Wa,{eyebrow:"Workbench Flow",title:"Flow unavailable",description:"Forge could not find that flow."}):e.jsx($a,{eyebrow:"Workbench Flow",error:d.error??u.error??null}):e.jsxs("div",{className:"grid gap-5",children:[e.jsx(ka,{entityKind:d.data.flow.kind,title:d.data.flow.title,titleText:d.data.flow.title,description:d.data.flow.description||"Inspect, run, and publish this Workbench flow.",badge:d.data.flow.kind,actions:e.jsx(wa,{entityType:"workbench_flow",entityId:d.data.flow.id})}),e.jsx(Ss,{flow:d.data.flow,boxes:n,modelConnections:(u.data.settings.modelSettings.connections??[]).map(m=>({id:m.id,label:m.label,provider:m.provider,model:m.model,baseUrl:m.baseUrl})),runs:d.data.runs,onSave:async m=>{await p({flowId:s,patch:m}).unwrap()},onDelete:async()=>{await o(s).unwrap(),i("/workbench")},onRun:async m=>{await l({flowId:s,input:m}).unwrap()},onChat:async m=>{await h({flowId:s,input:m}).unwrap()}})]})}export{zs as WorkbenchFlowPage};
@@ -1 +0,0 @@
1
- import{b5 as k,c2 as j,r as o,j as t}from"./vendor-kIz9EZnX.js";import{j as S,i as N,k as F}from"./state-VYvD1QVP.js";import{F as C}from"./faceted-token-search-D7xPWfOl.js";import{P as I}from"./page-hero-oFHaAjtL.js";import{fr as Q,B as p,b as W,fs as K,ft as $}from"./index-BHIKoiZ6.js";import"./motion-CfdU2F35.js";import"./ui-CsEkP2V8.js";import"./forms-CmLAyGqz.js";import"./board-DqHzdCPQ.js";import"./graph-BTa79qum.js";function R(){var h;const l=k(),m=S(),[f]=j(),g=f.get("surface"),[i,b]=o.useState(""),[c,x]=o.useState([]),w=N({queryKey:["forge-workbench-flows"],queryFn:$}),d=F({mutationFn:e=>Q({title:e==="chat"?"New chat flow":"New flow",description:e==="chat"?"Conversational workbench flow.":"Reusable workbench transformation flow.",kind:e,homeSurfaceId:g}),onSuccess:({flow:e})=>{m.invalidateQueries({queryKey:["forge-workbench-flows"]}),l(`/workbench/${e.id}`)}}),a=((h=w.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),v=c.every(n=>n.startsWith("kind:")?r.kind===n.replace("kind:",""):n.startsWith("surface:")?r.homeSurfaceId===n.replace("surface:",""):!0);return s&&v})},[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(p,{type:"button",variant:"primary",onClick:()=>void d.mutateAsync("functor"),children:"New flow"}),t.jsx(p,{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:b,options:y,selectedOptionIds:c,onSelectedOptionIdsChange:x,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:"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(W,{kind:K(e.kind),label:e.kind==="chat"?"Chat flow":"Functor flow",compact:!0,gradient:!1})]}),t.jsxs("div",{className:"mt-4 flex flex-wrap gap-2 text-[12px] text-white/44",children:[t.jsxs("span",{children:[e.graph.nodes.length," nodes"]}),t.jsxs("span",{children:[e.graph.edges.length," edges"]}),e.homeSurfaceId?t.jsx("span",{children:e.homeSurfaceId}):null]})]},e.id))})]})}export{R as WorkbenchPage};