forge-openclaw-plugin 0.2.118 → 0.3.1
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.
- package/dist/assets/{activity-page-DPPiiyLO.js → activity-page-DRRbpVK-.js} +1 -1
- package/dist/assets/{ai-surface-workspace-B_fV9C4s.js → ai-surface-workspace-DJPt-OaW.js} +1 -1
- package/dist/assets/{atlas-panel-BPTJyMcI.js → atlas-panel-G3wGxjYf.js} +1 -1
- package/dist/assets/{calendar-page-D4DcRQv7.js → calendar-page-y8G1ige8.js} +1 -1
- package/dist/assets/{calendar-rules-Cl_xMrBn.js → calendar-rules-CRhXqGQu.js} +1 -1
- package/dist/assets/{calendar-week-toolbar-BARSOEO9.js → calendar-week-toolbar-CWSK5hJl.js} +1 -1
- package/dist/assets/{companion-sync-lab-page-COFYDI3w.js → companion-sync-lab-page-kEgOF3c6.js} +1 -1
- package/dist/assets/daily-metrics-dashboard-BJjUIZVA.js +1 -0
- package/dist/assets/{entity-note-count-link-BX93WYgh.js → entity-note-count-link-ef3ZOpKM.js} +1 -1
- package/dist/assets/{entity-notes-surface-CBlKc-x-.js → entity-notes-surface-CaCjjUaq.js} +1 -1
- package/dist/assets/{execution-board-Dh41UeKR.js → execution-board-RRWm2srb.js} +1 -1
- package/dist/assets/{faceted-token-search-BgxYH_gW.js → faceted-token-search-CZmtyJTT.js} +1 -1
- package/dist/assets/{flagship-signal-deck-bolzzK8q.js → flagship-signal-deck-DxRfmfpN.js} +1 -1
- package/dist/assets/{floating-action-menu-C5H-Wr2B.js → floating-action-menu-cKjNsPYD.js} +1 -1
- package/dist/assets/{goal-detail-page-CQeFnGDJ.js → goal-detail-page-BgQlK7yT.js} +1 -1
- package/dist/assets/{goals-page-BTg9crEK.js → goals-page-Cz2i3pVy.js} +1 -1
- package/dist/assets/{habits-page-C4vqk346.js → habits-page-BmEmWCGv.js} +1 -1
- package/dist/assets/index-Bcem7l5u.css +1 -0
- package/dist/assets/{index-By3tQxiE.js → index-QJkjKYzZ.js} +2 -2
- package/dist/assets/{insight-flow-dialog-JPYCsTKI.js → insight-flow-dialog-CdYMHwMP.js} +1 -1
- package/dist/assets/{insights-page-CFhVMlVL.js → insights-page-DHG-o9P_.js} +1 -1
- package/dist/assets/{kanban-page-DC3IDsnh.js → kanban-page-C6S_fJRc.js} +1 -1
- package/dist/assets/{knowledge-graph-page-DucyRYTZ.js → knowledge-graph-page-juA9QCy0.js} +1 -1
- package/dist/assets/{life-force-page-UrXfxaSO.js → life-force-page-ChTIA4mV.js} +1 -1
- package/dist/assets/{life-force-workspace-BhPNH7ad.js → life-force-workspace-sszLD-Yn.js} +1 -1
- package/dist/assets/{metric-tile-DtRPjN4V.js → metric-tile-B-tDTcBt.js} +1 -1
- package/dist/assets/{movement-page-DCIdTQEN.js → movement-page-Dx3T3HrG.js} +1 -1
- package/dist/assets/{note-markdown-CepDxj3v.js → note-markdown-CCyyE85h.js} +1 -1
- package/dist/assets/{note-tags-input-BXYaDkOr.js → note-tags-input-BS14YXHn.js} +1 -1
- package/dist/assets/{notes-page-Bl1LlCLo.js → notes-page-D3yGl8TN.js} +1 -1
- package/dist/assets/{open-in-graph-button-C263zl5l.js → open-in-graph-button-CMjJZX7G.js} +1 -1
- package/dist/assets/{orbit-map-Cb_AJyIj.js → orbit-map-v2Pv9RU_.js} +1 -1
- package/dist/assets/{overview-page-C2yLity7.js → overview-page-DSOpBpHf.js} +1 -1
- package/dist/assets/{page-hero-5RTqAI88.js → page-hero-CONuJu5J.js} +1 -1
- package/dist/assets/{pill-cluster-CBrrtZBm.js → pill-cluster-W2fY48OM.js} +1 -1
- package/dist/assets/{preference-entity-handoff-button-BQzg2J4k.js → preference-entity-handoff-button-CKDxCnbl.js} +1 -1
- package/dist/assets/{preferences-page-DekYF-Yz.js → preferences-page-Br3zrLlH.js} +1 -1
- package/dist/assets/{project-collections-BVXB8PPF.js → project-collections-NBwk6yV-.js} +1 -1
- package/dist/assets/{project-detail-page-CQlrLEn9.js → project-detail-page-BIU9_TRN.js} +1 -1
- package/dist/assets/{project-management-hierarchy-page--mzM_zRE.js → project-management-hierarchy-page-C2H620xD.js} +1 -1
- package/dist/assets/{project-management-section-nav-DQl0qRWy.js → project-management-section-nav-DRPVS1Eh.js} +1 -1
- package/dist/assets/{projects-page-Dr_0NdVP.js → projects-page-w7a_L2-z.js} +1 -1
- package/dist/assets/{psyche-behaviors-page-DOUaCWON.js → psyche-behaviors-page-Dt4CMC-q.js} +1 -1
- package/dist/assets/{psyche-flashcards-page-BA84fO_X.js → psyche-flashcards-page-rXz06dqO.js} +1 -1
- package/dist/assets/{psyche-goal-map-page-DpXAg1Vf.js → psyche-goal-map-page-BCcD6Jkl.js} +1 -1
- package/dist/assets/{psyche-graph-BxcbAbXt.js → psyche-graph-CXlAj4ED.js} +1 -1
- package/dist/assets/psyche-metrics-page-B1otiir6.js +1 -0
- package/dist/assets/{psyche-mode-guide-page-CBlIS5N_.js → psyche-mode-guide-page-C6AdVIAv.js} +1 -1
- package/dist/assets/{psyche-modes-page-DE6KDK_1.js → psyche-modes-page-DoUqz2mR.js} +1 -1
- package/dist/assets/psyche-page-BJNLQn8W.js +1 -0
- package/dist/assets/{psyche-patterns-page-DbCNRuww.js → psyche-patterns-page-CzpMSAPu.js} +1 -1
- package/dist/assets/{psyche-questionnaire-builder-page-DnraDj1H.js → psyche-questionnaire-builder-page-DjzatGVZ.js} +1 -1
- package/dist/assets/{psyche-questionnaire-detail-page-DQ6zNQkk.js → psyche-questionnaire-detail-page-B0Qfowfg.js} +1 -1
- package/dist/assets/{psyche-questionnaire-run-detail-page-BGrOIX0B.js → psyche-questionnaire-run-detail-page-B2dNj4jJ.js} +1 -1
- package/dist/assets/{psyche-questionnaire-run-page-Bg3BhBHb.js → psyche-questionnaire-run-page-DyD9Ui-g.js} +1 -1
- package/dist/assets/{psyche-questionnaires-page-BEreTNjG.js → psyche-questionnaires-page-BxfKcoi3.js} +1 -1
- package/dist/assets/{psyche-report-detail-page-Br9KlJBG.js → psyche-report-detail-page-Ci14mNUK.js} +1 -1
- package/dist/assets/{psyche-reports-page-Bk6QpAEF.js → psyche-reports-page-ALhNueiV.js} +1 -1
- package/dist/assets/{psyche-schemas-beliefs-page-Db8d2ga7.js → psyche-schemas-beliefs-page-C0P2Vw6-.js} +1 -1
- package/dist/assets/{psyche-screen-time-page-NazHUAkT.js → psyche-screen-time-page-BYnaT3cb.js} +1 -1
- package/dist/assets/{psyche-self-observation-page-H6FToucM.js → psyche-self-observation-page-eM9vpwIB.js} +1 -1
- package/dist/assets/{psyche-values-page-DqM382-6.js → psyche-values-page-BqrGIDok.js} +1 -1
- package/dist/assets/{report-chain-fields-nW4zndrM.js → report-chain-fields-CbkT7WOO.js} +1 -1
- package/dist/assets/{rewards-page-C-tZVnIK.js → rewards-page-DpAJ8IxE.js} +1 -1
- package/dist/assets/{scheduling-rules-editor-DGF-044c.js → scheduling-rules-editor-BUGnZJ0g.js} +1 -1
- package/dist/assets/{schema-badge-57AJ3FY-.js → schema-badge-CLAA4p-b.js} +1 -1
- package/dist/assets/{select-menu-mfaklv7r.js → select-menu-Cqs5t3ng.js} +1 -1
- package/dist/assets/{settings-agents-page-CPJeeYg0.js → settings-agents-page-pmkVrOO8.js} +1 -1
- package/dist/assets/{settings-bin-page-D3eX5aNf.js → settings-bin-page-BwtLrweW.js} +1 -1
- package/dist/assets/{settings-calendar-page-Bgx8NIsP.js → settings-calendar-page-BBjAMOCf.js} +1 -1
- package/dist/assets/{settings-data-page-BuMSUjpp.js → settings-data-page-Bqy5SukM.js} +1 -1
- package/dist/assets/{settings-logs-page-CHb2GNUM.js → settings-logs-page-8khtrf4T.js} +1 -1
- package/dist/assets/{settings-mobile-page-ClUvXhJg.js → settings-mobile-page-BcyRjEU_.js} +1 -1
- package/dist/assets/{settings-models-page-njK6D7zc.js → settings-models-page-DlSnO9WX.js} +1 -1
- package/dist/assets/{settings-page-Dm--cx6B.js → settings-page-CyBQ2qcB.js} +1 -1
- package/dist/assets/{settings-rewards-page-3aShLM3A.js → settings-rewards-page-BBX2WtVM.js} +1 -1
- package/dist/assets/{settings-section-nav-BWox23Qv.js → settings-section-nav-Co0AaDG-.js} +1 -1
- package/dist/assets/{settings-users-page-D-hEPpgQ.js → settings-users-page-JSnfFFPu.js} +1 -1
- package/dist/assets/{settings-wiki-page-CC-rOtDm.js → settings-wiki-page--nT23Fdy.js} +1 -1
- package/dist/assets/{sleep-page-Cm_Ei2w1.js → sleep-page-CGMi3MtV.js} +1 -1
- package/dist/assets/{sports-page-CqSI-j-H.js → sports-page-Kv5bBoLr.js} +1 -1
- package/dist/assets/{strategies-page-BuJ4zLLv.js → strategies-page-Br7RdUJO.js} +1 -1
- package/dist/assets/{strategy-detail-page-CLmy0jbW.js → strategy-detail-page-CBWXjUhC.js} +1 -1
- package/dist/assets/{strategy-dialog-DnJix1ys.js → strategy-dialog-BTwkaSxI.js} +1 -1
- package/dist/assets/{surface-DRNu5Fpz.js → surface-CyWI7e1R.js} +1 -1
- package/dist/assets/{task-detail-page-DTnNjW33.js → task-detail-page-Qis9354n.js} +1 -1
- package/dist/assets/{timebox-planning-dialog-DckIr1K4.js → timebox-planning-dialog-DB8snOBD.js} +1 -1
- package/dist/assets/{today-page-Cgk4HBPK.js → today-page-D9A5PU0S.js} +1 -1
- package/dist/assets/{training-load-page-C-7iINaB.js → training-load-page-Bpd4DQAh.js} +1 -1
- package/dist/assets/vitals-page-CVYC-4RG.js +1 -0
- package/dist/assets/{weekly-review-page-DFmuzzig.js → weekly-review-page-BP7N3fNB.js} +1 -1
- package/dist/assets/{weight-loss-page-CWtgeuti.js → weight-loss-page-_fX3N1UK.js} +1 -1
- package/dist/assets/{wiki-article-markdown-BkQg8Hne.js → wiki-article-markdown-Bi02AsVt.js} +1 -1
- package/dist/assets/{wiki-editor-page-BYKcdX5I.js → wiki-editor-page-OZf9l4Tg.js} +1 -1
- package/dist/assets/{wiki-ingest-history-page-D_p4myw1.js → wiki-ingest-history-page-CzeNSL7N.js} +1 -1
- package/dist/assets/{wiki-ingest-modal-C-CidueO.js → wiki-ingest-modal-Ig_xnyc6.js} +1 -1
- package/dist/assets/wiki-page-B4xuNgY4.js +1 -0
- package/dist/assets/{workbench-flow-page-Q3r2IJty.js → workbench-flow-page-BhRJCALC.js} +1 -1
- package/dist/assets/{workbench-page-BFfWMGm6.js → workbench-page-DxVs2AOY.js} +1 -1
- package/dist/assets/{workout-detail-page-DeDyz1Kk.js → workout-detail-page-D4wfkE98.js} +1 -1
- package/dist/index.html +2 -2
- package/dist/server/server/migrations/069_psyche_devrage_cumulative_rage.sql +5 -0
- package/dist/server/server/src/app.js +3 -2
- package/dist/server/server/src/openapi.js +48 -8
- package/dist/server/server/src/psyche-types.js +18 -4
- package/dist/server/server/src/services/devrage-scanner.js +115 -10
- package/dist/server/server/src/services/devrage.js +61 -11
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- package/server/migrations/069_psyche_devrage_cumulative_rage.sql +5 -0
- package/skills/forge-openclaw/SKILL.md +7 -0
- package/skills/forge-openclaw/entity_conversation_playbooks.md +23 -0
- package/skills/forge-openclaw/psyche_entity_playbooks.md +32 -0
- package/dist/assets/daily-metrics-dashboard-BNGQlJkQ.js +0 -1
- package/dist/assets/index-BAXYM89v.css +0 -1
- package/dist/assets/psyche-metrics-page-D8JQEoOl.js +0 -1
- package/dist/assets/psyche-page-Dkh7R2Dc.js +0 -1
- package/dist/assets/vitals-page-CqE4bYMf.js +0 -1
- package/dist/assets/wiki-page-DYpg9ZEO.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{b5 as Pe,r as p,j as e,aK as se,dD as te,dE as Le,aN as Ke,dF as Fe,cg as Me,aG as G,dG as be,b7 as $e,b3 as he}from"./vendor-Dnkkx2co.js";import{R as qe,P as ze,O as De,C as Qe,T as Re,D as We,a as Ue}from"./ui-C1iwpj2-.js";import{j as Oe,i as re,k as D}from"./state-vCcAT5Hq.js";import{fb as Be,fc as Ge,fd as ye,fe as He,ff as Ve,fg as Ze,Z as c,I as je,T as Ye,B as C,b as ae,c as ie,g as Xe,fh as Je,fi as et,fj as tt}from"./index-By3tQxiE.js";const $=new Set(["queued","processing"]),Ne=15e3,j="border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)]",z="border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",q="border-[color-mix(in_srgb,var(--primary)_30%,transparent)] bg-[var(--ui-accent-soft)] text-[var(--ui-ink-strong)]",H="border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-medium)] hover:bg-[var(--ui-surface-2)] hover:text-[var(--ui-ink-strong)]",at=["goal","project","task","habit","strategy","psyche_value","flashcard","note"];function ke(i){return new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}).format(new Date(i))}function _(i,a){const r=i[a];return typeof r=="number"&&Number.isFinite(r)?r:null}function y(i,a){const r=i[a];return typeof r=="string"&&r.trim().length>0?r:null}function it(i,a){const r=y(i.metadata,"currentFileName")??y(i.metadata,"fileName")??"current source",b=y(i.metadata,"status")??"in_progress",o=_(i.metadata,"chunkIndex"),x=_(i.metadata,"chunkCount"),N=_(i.metadata,"currentFileIndex"),f=_(i.metadata,"currentFileTotal"),k=N!==null&&f!==null?`${r} (${N}/${f})`:r,u=o!==null&&x!==null&&x>1?` · chunk ${o}/${x}`:"";return`Waiting for OpenAI on ${k}${u}. ${a} polls · ${b}.`}function st(i){const a=[];for(const r of i){const b=y(r.metadata,"scope"),x=y(r.metadata,"eventKey")==="llm_compile_background_polled",N=y(r.metadata,"currentFileName")??y(r.metadata,"fileName"),f=_(r.metadata,"chunkIndex"),k=_(r.metadata,"chunkCount"),u=x?["poll",b??"",N??"",f??"",k??""].join(":"):null,m=a[a.length-1],A=m&&y(m.metadata,"eventKey"),w=m&&(y(m.metadata,"currentFileName")??y(m.metadata,"fileName")),E=m&&_(m.metadata,"chunkIndex"),h=m&&_(m.metadata,"chunkCount"),P=m&&A==="llm_compile_background_polled"?["poll",y(m.metadata,"scope")??"",w??"",E??"",h??""].join(":"):null;if(x&&m&&P===u){a[a.length-1]={...r,repetitionCount:m.repetitionCount+1,metadata:{...r.metadata,aggregatedPollCount:m.repetitionCount+1}};continue}a.push({...r,repetitionCount:1})}return a}function V(i){return Xe(i)}function we(i){return typeof i=="string"&&at.includes(i)}function rt(i,a){return typeof a.title=="string"&&a.title.trim().length>0?a.title:typeof a.displayName=="string"&&a.displayName.trim().length>0?a.displayName:typeof a.statement=="string"&&a.statement.trim().length>0?a.statement:`${i}:${String(a.id??"")}`}function nt(i,a){const b=[a.description,a.summary,a.overview,a.valuedDirection,a.whyItMatters,a.originNote].find(o=>typeof o=="string"&&o.trim().length>0);return b||(i==="note"&&typeof a.kind=="string"?a.kind:"")}function lt({candidate:i,decision:a,onDecisionChange:r,spaceId:b}){const o=we(i.payload.entityType)?i.payload.entityType:null,[x,N]=p.useState(a.mappedEntityLabel||i.title||""),[f,k]=p.useState(a.targetNoteLabel||i.title||""),u=typeof i.payload.contentMarkdown=="string"?i.payload.contentMarkdown:typeof i.payload.patchSummary=="string"?i.payload.patchSummary:typeof i.payload.rationale=="string"?i.payload.rationale:i.summary,m=re({queryKey:["forge-wiki-ingest-map-search",o,x.trim()],enabled:i.candidateType==="entity"&&a.action==="map_existing"&&o!==null&&x.trim().length>0,queryFn:async()=>{var F;const v=(await Je({searches:[{entityTypes:o?[o]:void 0,query:x.trim(),limit:8}]})).results[0];return((F=v==null?void 0:v.matches)==null?void 0:F.filter(g=>!!(g&&we(g.entityType)&&typeof g.id=="string"&&g.entity&&typeof g.entity=="object")).map(g=>({entityType:g.entityType,entityId:g.id,label:rt(g.entityType,g.entity),description:nt(g.entityType,g.entity),kind:V(g.entityType)})))??[]}}),A=m.data??[],w=re({queryKey:["forge-wiki-ingest-merge-search",b,f.trim()],enabled:i.candidateType==="page"&&a.action==="merge_existing"&&f.trim().length>0,queryFn:async()=>(await et({spaceId:b,kind:"wiki",mode:"text",query:f.trim(),limit:8})).results.map(v=>({noteId:v.page.id,title:v.page.title,slug:v.page.slug,summary:v.page.summary}))}),E=w.data??[],h=a.mappedEntityId&&a.mappedEntityType?A.find(s=>s.entityId===a.mappedEntityId&&s.entityType===a.mappedEntityType)??(a.mappedEntityLabel?{entityId:a.mappedEntityId,entityType:a.mappedEntityType,label:a.mappedEntityLabel,kind:V(a.mappedEntityType)}:null):null,P=a.targetNoteId?E.find(s=>s.noteId===a.targetNoteId)??(a.targetNoteLabel?{noteId:a.targetNoteId,title:a.targetNoteLabel}:null):null;return e.jsxs("div",{className:c("rounded-[24px] border p-4",j),children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:i.candidateType.replaceAll("_"," ")}),e.jsx("div",{className:"mt-2 text-base font-semibold text-[var(--ui-ink-strong)]",children:i.title||i.targetKey||"Untitled candidate"}),o?e.jsx("div",{className:"mt-2",children:V(o)?e.jsx(ae,{kind:V(o),label:o.replaceAll("_"," "),compact:!0,gradient:!1}):e.jsx(ie,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:o.replaceAll("_"," ")})}):null,i.summary?e.jsx("div",{className:"mt-1 text-sm leading-6 text-[var(--ui-ink-soft)]",children:i.summary}):null]}),e.jsxs("div",{className:"inline-flex items-center gap-2 rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-1",children:[e.jsx("button",{type:"button",className:c("rounded-full px-3 py-1.5 text-xs font-medium transition",a.action==="keep"?"bg-[var(--ui-accent-soft)] text-[var(--ui-ink-strong)]":"text-[var(--ui-ink-soft)] hover:text-[var(--ui-ink-strong)]"),onClick:()=>r({...a,action:"keep"}),children:"Keep"}),i.candidateType==="entity"&&o?e.jsx("button",{type:"button",className:c("rounded-full px-3 py-1.5 text-xs font-medium transition",a.action==="map_existing"?"bg-[var(--ui-info-soft)] text-[var(--ui-ink-strong)]":"text-[var(--ui-ink-soft)] hover:text-[var(--ui-ink-strong)]"),onClick:()=>r({...a,action:"map_existing",mappedEntityType:o}),children:"Map existing"}):null,i.candidateType==="page"?e.jsx("button",{type:"button",className:c("rounded-full px-3 py-1.5 text-xs font-medium transition",a.action==="merge_existing"?"bg-[var(--ui-info-soft)] text-[var(--ui-ink-strong)]":"text-[var(--ui-ink-soft)] hover:text-[var(--ui-ink-strong)]"),onClick:()=>r({...a,action:"merge_existing"}),children:"Merge existing"}):null,e.jsx("button",{type:"button",className:c("rounded-full px-3 py-1.5 text-xs font-medium transition",a.action==="discard"?"bg-[var(--ui-surface-2)] text-[var(--ui-ink-strong)]":"text-[var(--ui-ink-soft)] hover:text-[var(--ui-ink-strong)]"),onClick:()=>r({...a,action:"discard"}),children:"Discard"})]})]}),i.candidateType==="entity"&&o&&a.action==="map_existing"?e.jsxs("div",{className:c("mt-4 grid gap-3 rounded-[18px] border p-4",z),children:[e.jsxs("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:["Map to existing ",o.replaceAll("_"," ")]}),h?e.jsx("div",{className:"flex flex-wrap gap-2",children:e.jsxs("span",{className:"inline-flex items-center gap-2 rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-2.5 py-1.5",children:[h.kind?e.jsx(ae,{kind:h.kind,label:h.label,compact:!0,gradient:!1,className:"max-w-[20rem]"}):e.jsx(ie,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:h.label}),e.jsx("button",{type:"button",className:"rounded-full text-[var(--ui-ink-faint)] transition hover:text-[var(--ui-ink-strong)]",onClick:()=>r({...a,mappedEntityId:void 0,mappedEntityLabel:void 0}),"aria-label":"Clear mapped entity",children:e.jsx(se,{className:"size-3.5"})})]})}):null,e.jsxs("div",{className:c("flex items-center gap-3 rounded-[20px] border px-4 py-3",j),children:[e.jsx(he,{className:"size-4 text-[var(--ui-ink-faint)]"}),e.jsx("input",{value:x,onChange:s=>{N(s.target.value),a.mappedEntityId&&r({...a,mappedEntityId:void 0,mappedEntityLabel:void 0})},placeholder:`Search existing ${o.replaceAll("_"," ")}`,className:"min-w-0 flex-1 bg-transparent text-sm text-[var(--ui-ink-strong)] placeholder:text-[var(--ui-ink-faint)] focus:outline-none"})]}),e.jsx("div",{className:"grid gap-2",children:m.isPending?e.jsx("div",{className:c("rounded-[16px] border px-3 py-3 text-sm text-[var(--ui-ink-faint)]",j),children:"Searching Forge…"}):A.length===0?e.jsxs("div",{className:"rounded-[16px] border border-dashed border-[var(--ui-border-subtle)] px-3 py-3 text-sm text-[var(--ui-ink-faint)]",children:["No existing ",o.replaceAll("_"," ")," matches yet."]}):A.map(s=>{const v=a.mappedEntityType===s.entityType&&a.mappedEntityId===s.entityId;return e.jsx("button",{type:"button",className:c("flex w-full items-start justify-between gap-3 rounded-[18px] border px-3 py-3 text-left transition",v?q:"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-medium)] hover:bg-[var(--ui-surface-2)] hover:text-[var(--ui-ink-strong)]"),onClick:()=>r({action:"map_existing",mappedEntityType:s.entityType,mappedEntityId:s.entityId,mappedEntityLabel:s.label}),children:e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-medium",children:s.kind?e.jsx(ae,{kind:s.kind,label:s.label,compact:!0,gradient:!1}):s.label}),s.description?e.jsx("div",{className:"mt-1 text-xs leading-5 text-[var(--ui-ink-faint)]",children:s.description}):null]})},`${s.entityType}:${s.entityId}`)})})]}):null,i.candidateType==="page"&&a.action==="merge_existing"?e.jsxs("div",{className:c("mt-4 grid gap-3 rounded-[18px] border p-4",z),children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Merge into existing page"}),P?e.jsx("div",{className:"flex flex-wrap gap-2",children:e.jsxs("span",{className:"inline-flex items-center gap-2 rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-2.5 py-1.5",children:[e.jsx(ie,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:P.title}),e.jsx("button",{type:"button",className:"rounded-full text-[var(--ui-ink-faint)] transition hover:text-[var(--ui-ink-strong)]",onClick:()=>r({...a,targetNoteId:void 0,targetNoteLabel:void 0}),"aria-label":"Clear merge target",children:e.jsx(se,{className:"size-3.5"})})]})}):null,e.jsxs("div",{className:c("flex items-center gap-3 rounded-[20px] border px-4 py-3",j),children:[e.jsx(he,{className:"size-4 text-[var(--ui-ink-faint)]"}),e.jsx("input",{value:f,onChange:s=>{k(s.target.value),a.targetNoteId&&r({...a,targetNoteId:void 0,targetNoteLabel:void 0})},placeholder:"Search existing wiki pages",className:"min-w-0 flex-1 bg-transparent text-sm text-[var(--ui-ink-strong)] placeholder:text-[var(--ui-ink-faint)] focus:outline-none"})]}),e.jsx("div",{className:"grid gap-2",children:w.isPending?e.jsx("div",{className:c("rounded-[16px] border px-3 py-3 text-sm text-[var(--ui-ink-faint)]",j),children:"Searching Forge…"}):E.length===0?e.jsx("div",{className:"rounded-[16px] border border-dashed border-[var(--ui-border-subtle)] px-3 py-3 text-sm text-[var(--ui-ink-faint)]",children:"No existing wiki pages match yet."}):E.map(s=>{const v=a.targetNoteId===s.noteId;return e.jsx("button",{type:"button",className:c("flex w-full items-start justify-between gap-3 rounded-[18px] border px-3 py-3 text-left transition",v?q:"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-medium)] hover:bg-[var(--ui-surface-2)] hover:text-[var(--ui-ink-strong)]"),onClick:()=>r({action:"merge_existing",targetNoteId:s.noteId,targetNoteLabel:s.title}),children:e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-medium",children:s.title}),e.jsxs("div",{className:"mt-1 text-xs leading-5 text-[var(--ui-ink-faint)]",children:[s.slug?`${s.slug}`:"",s.summary?`${s.slug?" · ":""}${s.summary}`:""]})]})},s.noteId)})})]}):null,u?e.jsx("div",{className:c("mt-4 rounded-[18px] border px-4 py-3 text-sm leading-6 text-[var(--ui-ink-medium)]",z),children:e.jsx("pre",{className:"whitespace-pre-wrap font-sans",children:u})}):null]})}function pt({open:i,onOpenChange:a,spaces:r,llmProfiles:b,initialSpaceId:o,selectedJobId:x,onJobSelected:N,linkedEntityHints:f=[]}){var ge;const k=Pe(),u=Oe(),[m,A]=p.useState("files"),[w,E]=p.useState(o),[h,P]=p.useState(""),[s,v]=p.useState(""),[F,g]=p.useState(""),[Q,Z]=p.useState([]),[Ee,R]=p.useState(!1),[Ie,Se]=p.useState(!1),I=p.useMemo(()=>b.filter(t=>t.enabled&&!!t.secretId),[b]),[W,ne]=p.useState(((ge=I[0])==null?void 0:ge.id)??""),[U,Te]=p.useState("auto"),[Y,le]=p.useState({}),[O,S]=p.useState(null),[B,T]=p.useState(null),oe=p.useRef({});p.useEffect(()=>{o&&E(o)},[o]),p.useEffect(()=>{var t;!W&&((t=I[0])!=null&&t.id)&&ne(I[0].id)},[W,I]);const M=I.find(t=>t.id===W)??I[0]??null,L=re({queryKey:["forge-wiki-ingest-job",x],queryFn:()=>tt(x),enabled:i&&!!x,refetchInterval:t=>{const d=t.state.data;return d&&$.has(d.job.status)?2e3:!1}});p.useEffect(()=>{const t=L.data;t&&le(d=>{const l={};for(const K of t.candidates)l[K.id]=d[K.id]??(K.status==="rejected"?{action:"discard"}:{action:"keep"});return l})},[L.data]),p.useEffect(()=>{B&&T(null)},[Y,B]);const X=D({mutationFn:async t=>Be(t),onSuccess:(t,d)=>{t.job&&u.setQueryData(["forge-wiki-ingest-job",d],t.job),u.invalidateQueries({queryKey:["forge-wiki-ingest-jobs"]}),u.invalidateQueries({queryKey:["forge-wiki-ingest-history"]})}});p.useEffect(()=>{const t=L.data;if(!t||!$.has(t.job.status))return;const d=t.logs.reduce((ve,Ae)=>{const fe=Number(new Date(Ae.createdAt));return Number.isFinite(fe)?Math.max(ve,fe):ve},0),l=Number(new Date(t.job.updatedAt)),K=Math.max(Number.isFinite(l)?l:0,d);if(!Number.isFinite(K)||K<=0)return;const ee=Date.now();if(!(ee-K>=Ne)||X.isPending)return;const _e=oe.current[t.job.id]??0;ee-_e<Ne||(oe.current[t.job.id]=ee,X.mutate(t.job.id))},[L.data,X]);const de=D({mutationFn:async()=>{if(!M)throw new Error("Set up an OpenAI wiki ingest profile first. Forge now requires an LLM profile before auto-ingest can turn source material into draft pages and entities.");if(m==="files"){if(Q.length===0)throw new Error("Select at least one file to ingest.");return Ge({files:Q,spaceId:w||void 0,titleHint:h.trim()||void 0,llmProfileId:M.id,parseStrategy:U,createAsKind:"wiki",linkedEntityHints:f})}if(m==="url"){if(!s.trim())throw new Error("Enter a URL to ingest.");return ye({spaceId:w||void 0,titleHint:h.trim()||void 0,sourceKind:"url",sourceUrl:s.trim(),llmProfileId:M.id,parseStrategy:U,createAsKind:"wiki",linkedEntityHints:f})}if(!F.trim())throw new Error("Paste some text to ingest.");return ye({spaceId:w||void 0,titleHint:h.trim()||void 0,sourceKind:"raw_text",sourceText:F,mimeType:"text/plain",llmProfileId:M.id,parseStrategy:U,createAsKind:"wiki",linkedEntityHints:f})},onSuccess:async t=>{var l;const d=((l=t.job)==null?void 0:l.job.id)??null;await u.invalidateQueries({queryKey:["forge-wiki-ingest-jobs"]}),await u.invalidateQueries({queryKey:["forge-wiki-ingest-history"]}),d&&N(d),S(null),T(null)},onError:t=>{S(t instanceof Error?t.message:"Unable to start ingest.")}}),ce=D({mutationFn:async()=>{if(!x||!L.data)throw new Error("Choose an ingest job first.");const t=L.data.candidates.map(d=>{const l=Y[d.id]??{action:"keep"};if(l.action==="map_existing"&&(!l.mappedEntityType||!l.mappedEntityId))throw new Error(`Choose an existing ${String(d.payload.entityType??"entity").replaceAll("_"," ")} before publishing the review.`);if(l.action==="merge_existing"&&!l.targetNoteId)throw new Error(`Choose an existing wiki page before publishing the review for ${d.title||"this page candidate"}.`);return l.action==="map_existing"?{candidateId:d.id,action:"map_existing",mappedEntityType:l.mappedEntityType,mappedEntityId:l.mappedEntityId}:l.action==="merge_existing"?{candidateId:d.id,action:"merge_existing",targetNoteId:l.targetNoteId}:{candidateId:d.id,action:l.action}});return He({jobId:x,decisions:t})},onSuccess:async t=>{T(null),u.setQueryData(["forge-wiki-ingest-job",t.job.job.id],t.job),await Promise.all([u.invalidateQueries({queryKey:["forge-wiki-ingest-jobs"]}),u.invalidateQueries({queryKey:["forge-wiki-ingest-history"]}),u.invalidateQueries({queryKey:["forge-wiki-ingest-job",t.job.job.id]}),u.invalidateQueries({queryKey:["forge-wiki-home"]}),u.invalidateQueries({queryKey:["forge-wiki-page-by-slug"]}),u.invalidateQueries({queryKey:["forge-wiki-tree"]})])},onError:t=>{T(t instanceof Error?t.message:"Unable to publish review.")}}),ue=D({mutationFn:async()=>{if(!x)throw new Error("Choose an ingest job first.");return Ve(x)},onSuccess:async t=>{var l;const d=((l=t.job)==null?void 0:l.job.id)??null;await Promise.all([u.invalidateQueries({queryKey:["forge-wiki-ingest-jobs"]}),u.invalidateQueries({queryKey:["forge-wiki-ingest-history"]}),u.invalidateQueries({queryKey:["forge-wiki-ingest-job",x]})]),d&&N(d),S(null),T(null)},onError:t=>{S(t instanceof Error?t.message:"Unable to rerun ingest.")}}),me=D({mutationFn:async()=>{if(!x)throw new Error("Choose an ingest job first.");return Ze(x)},onSuccess:async()=>{await Promise.all([u.invalidateQueries({queryKey:["forge-wiki-ingest-jobs"]}),u.invalidateQueries({queryKey:["forge-wiki-ingest-history"]}),u.invalidateQueries({queryKey:["forge-wiki-ingest-job",x]})]),xe(),S(null),T(null)},onError:t=>{S(t instanceof Error?t.message:"Unable to delete ingest.")}}),n=L.data??null,Ce=n&&!$.has(n.job.status),J=p.useMemo(()=>(n==null?void 0:n.candidates.filter(t=>["suggested","rejected","failed"].includes(t.status)))??[],[n]),pe=p.useMemo(()=>st((n==null?void 0:n.logs)??[]),[n==null?void 0:n.logs]),xe=()=>{N(null),Z([]),v(""),g(""),P(""),S(null),T(null)};return e.jsx(qe,{open:i,onOpenChange:t=>{a(t),t||(S(null),T(null))},children:e.jsxs(ze,{children:[e.jsx(De,{className:"fixed inset-0 z-50 surface-overlay backdrop-blur-sm"}),e.jsxs(Qe,{className:"fixed inset-x-4 bottom-4 top-4 z-50 mx-auto flex max-w-[min(74rem,calc(100vw-2rem))] flex-col overflow-hidden rounded-[32px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-popover)] shadow-[var(--ui-shadow-floating)]",children:[e.jsx("div",{className:"border-b border-[var(--ui-border-subtle)] px-5 py-5",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"KarpaWiki Ingest"}),e.jsx(Re,{className:"mt-2 font-display text-[1.5rem] tracking-[-0.04em] text-[var(--ui-ink-strong)]",children:n?"Ingest review and progress":"Build KarpaWiki memory from source files"}),e.jsx(We,{className:"mt-2 max-w-3xl text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Upload notes, media, ZIP archives, links, or pasted text. Forge will process them in the background, propose pages and entities, and let you keep only what belongs."})]}),e.jsx(Ue,{asChild:!0,children:e.jsx("button",{type:"button",className:"rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-2 text-[var(--ui-ink-soft)] transition hover:bg-[var(--ui-surface-2)] hover:text-[var(--ui-ink-strong)]","aria-label":"Close ingest modal",children:e.jsx(se,{className:"size-4"})})})]})}),e.jsx("div",{className:"flex-1 overflow-y-auto px-5 py-5",children:n?e.jsxs("div",{className:"grid gap-5 xl:grid-cols-[minmax(0,0.9fr)_minmax(0,1.1fr)]",children:[e.jsxs("div",{className:"grid gap-5",children:[e.jsxs("div",{className:c("rounded-[28px] border p-4 sm:p-5",j),children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:["Job ",n.job.id]}),e.jsx("div",{className:"mt-2 text-xl font-semibold text-[var(--ui-ink-strong)]",children:n.job.latestMessage||"Ingest job"}),e.jsxs("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:[n.job.status," · ",n.job.phase," · started ",ke(n.job.createdAt)]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(C,{variant:"secondary",size:"sm",onClick:xe,children:"New ingest"}),Ce?e.jsxs(e.Fragment,{children:[e.jsxs(C,{variant:"secondary",size:"sm",pending:ue.isPending,pendingLabel:"Rerunning",onClick:()=>void ue.mutateAsync(),children:[e.jsx(G,{className:"size-3.5"}),"Rerun"]}),e.jsx(C,{variant:"ghost",size:"sm",className:"border border-rose-300/18 bg-rose-400/10 text-rose-100 hover:bg-rose-400/16",pending:me.isPending,pendingLabel:"Deleting",onClick:()=>{window.confirm("Delete this ingest history entry? Published pages or entities will stay, but discarded or unreviewed ingest data will be removed.")&&me.mutateAsync()},children:"Delete"})]}):null]})]}),e.jsx("div",{className:"mt-5 grid gap-3 sm:grid-cols-4",children:[{label:"Progress",value:`${n.job.progressPercent}%`},{label:"Files",value:`${n.job.processedFiles}/${n.job.totalFiles}`},{label:"Pages",value:String(n.job.createdPageCount)},{label:"Entities",value:String(n.job.createdEntityCount)}].map(t=>e.jsxs("div",{className:c("rounded-[22px] border px-4 py-3",z),children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:t.label}),e.jsx("div",{className:"mt-2 text-lg font-semibold text-[var(--ui-ink-strong)]",children:t.value})]},t.label))}),e.jsx("div",{className:"mt-5",children:e.jsx("div",{className:"h-2 overflow-hidden rounded-full bg-[var(--ui-surface-2)]",children:e.jsx("div",{className:"h-full rounded-full bg-[var(--primary)] transition-all duration-300",style:{width:`${n.job.progressPercent}%`}})})}),O?e.jsx("div",{className:"mt-4 rounded-[20px] border border-rose-300/22 bg-rose-400/10 px-4 py-3 text-sm text-rose-100",children:O}):null]}),e.jsxs("div",{className:c("rounded-[28px] border p-4 sm:p-5",j),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Rich log"}),e.jsx(C,{variant:"secondary",size:"sm",onClick:()=>k(`/settings/logs?jobId=${encodeURIComponent(n.job.id)}`),children:"Open full logs"})]}),e.jsx("div",{className:"mt-4 grid max-h-[28rem] gap-2 overflow-y-auto",children:pe.length===0?e.jsx("div",{className:"rounded-[18px] border border-dashed border-[var(--ui-border-subtle)] px-4 py-4 text-sm text-[var(--ui-ink-faint)]",children:"Waiting for the backend to emit progress."}):pe.map(t=>e.jsx("div",{className:c("rounded-[18px] border px-4 py-3",z),children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-2 py-1 text-[10px] font-semibold uppercase tracking-[0.14em] text-[var(--ui-ink-soft)]",children:t.level}),typeof t.metadata.scope=="string"?e.jsx("span",{className:"rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-2 py-1 text-[10px] font-semibold uppercase tracking-[0.14em] text-[var(--ui-ink-faint)]",children:t.metadata.scope}):null,typeof t.metadata.eventKey=="string"?e.jsx("span",{className:"rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-2 py-1 text-[10px] font-semibold uppercase tracking-[0.14em] text-[var(--ui-ink-faint)]",children:t.metadata.eventKey}):null]}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-strong)]",children:y(t.metadata,"eventKey")==="llm_compile_background_polled"?it(t,t.repetitionCount):t.message}),t.repetitionCount>1?e.jsxs("div",{className:"mt-2 text-xs text-[var(--ui-ink-faint)]",children:["Combined ",t.repetitionCount," repeated polling updates."]}):null,Object.keys(t.metadata).length>0?e.jsxs("details",{className:"mt-3",children:[e.jsx("summary",{className:"cursor-pointer text-xs text-[var(--ui-ink-faint)]",children:"View metadata"}),e.jsx("pre",{className:"mt-2 max-w-full overflow-x-auto whitespace-pre-wrap rounded-[14px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-code)] px-3 py-3 text-[11px] leading-5 text-[var(--ui-ink-soft)]",children:JSON.stringify(t.metadata,null,2)})]}):null]}),e.jsx("div",{className:"text-[11px] uppercase tracking-[0.14em] text-[var(--ui-ink-faint)]",children:ke(t.createdAt)})]})},t.id))})]})]}),e.jsxs("div",{className:"grid gap-5",children:[e.jsxs("div",{className:c("rounded-[28px] border p-4 sm:p-5",j),children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Source files"}),e.jsx("div",{className:"mt-4 grid gap-2",children:n.assets.map(t=>e.jsxs("div",{className:c("flex min-w-0 items-center justify-between gap-3 rounded-[18px] border px-4 py-3",z),children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-medium text-[var(--ui-ink-strong)]",children:t.fileName||t.sourceLocator||"Source"}),e.jsx("div",{className:"mt-1 text-xs text-[var(--ui-ink-faint)]",children:t.mimeType||t.sourceKind})]}),e.jsx("div",{className:"shrink-0 text-[11px] uppercase tracking-[0.14em] text-[var(--ui-ink-faint)]",children:t.status})]},t.id))})]}),e.jsxs("div",{className:c("rounded-[28px] border p-4 sm:p-5",j),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Review"}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Keep the candidates that belong in Forge and discard the rest."})]}),$.has(n.job.status)?e.jsxs("div",{className:"inline-flex items-center gap-2 rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-3 py-2 text-xs text-[var(--ui-ink-soft)]",children:[e.jsx($e,{className:"size-3.5 animate-spin"}),"Processing"]}):null]}),e.jsx("div",{className:"mt-4 grid gap-3",children:J.length===0?e.jsx("div",{className:"rounded-[18px] border border-dashed border-[var(--ui-border-subtle)] px-4 py-4 text-sm text-[var(--ui-ink-faint)]",children:$.has(n.job.status)?"Candidates will appear here while the job progresses.":"This job has no reviewable candidates left."}):J.map(t=>e.jsx(lt,{candidate:t,spaceId:n.job.spaceId,decision:Y[t.id]??{action:"keep"},onDecisionChange:d=>le(l=>({...l,[t.id]:d}))},t.id))}),B?e.jsx("div",{className:"mt-4 rounded-[20px] border border-rose-300/22 bg-rose-400/10 px-4 py-3 text-sm text-rose-100",children:B}):null,J.length>0&&!$.has(n.job.status)?e.jsx("div",{className:"mt-5",children:e.jsxs(C,{className:"min-h-12",pending:ce.isPending,pendingLabel:"Publishing review",onClick:()=>void ce.mutateAsync(),children:[e.jsx(be,{className:"size-4"}),"Publish kept candidates"]})}):null]})]})]}):e.jsxs("div",{className:"grid gap-5 lg:grid-cols-[minmax(0,1.15fr)_minmax(18rem,0.85fr)]",children:[e.jsxs("div",{className:"grid gap-5",children:[e.jsx("div",{className:"grid gap-3 sm:grid-cols-3",children:[{id:"files",label:"Files and ZIP",detail:"Drag many files or one archive.",icon:te},{id:"url",label:"URL",detail:"Pull a webpage or remote file.",icon:Le},{id:"text",label:"Paste text",detail:"Turn notes or transcripts into pages.",icon:Ke}].map(t=>{const d=t.icon,l=t.id===m;return e.jsxs("button",{type:"button",className:c("rounded-[24px] border px-4 py-4 text-left transition",l?q:H),onClick:()=>A(t.id),children:[e.jsx(d,{className:"size-4 text-[var(--secondary)]"}),e.jsx("div",{className:"mt-3 text-sm font-semibold",children:t.label}),e.jsx("div",{className:"mt-1 text-xs leading-5 text-[var(--ui-ink-faint)]",children:t.detail})]},t.id)})}),e.jsx("div",{className:c("rounded-[28px] border p-4 sm:p-5",j),children:e.jsxs("div",{className:"grid gap-4",children:[e.jsx(je,{value:h,onChange:t=>P(t.target.value),placeholder:"Optional title hint"}),m==="files"?e.jsxs("div",{className:c("rounded-[28px] border-2 border-dashed px-5 py-8 text-center transition",Ee?"border-[color-mix(in_srgb,var(--primary)_36%,transparent)] bg-[var(--ui-accent-soft)]":j),onDragEnter:t=>{t.preventDefault(),R(!0)},onDragLeave:t=>{t.preventDefault(),R(!1)},onDragOver:t=>{t.preventDefault(),R(!0)},onDrop:t=>{t.preventDefault(),R(!1);const d=Array.from(t.dataTransfer.files);Z(l=>[...l,...d])},children:[e.jsx("div",{className:"mx-auto flex size-14 items-center justify-center rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",children:e.jsx(te,{className:"size-5 text-[var(--ui-ink-medium)]"})}),e.jsx("div",{className:"mt-4 text-base font-semibold text-[var(--ui-ink-strong)]",children:"Drop files, media, notes, or ZIP archives here"}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-faint)]",children:"Forge accepts many files at once and queues the ingest in the background so the UI stays responsive."}),e.jsxs("label",{className:"mt-5 inline-flex cursor-pointer items-center gap-2 rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-2 text-sm text-[var(--ui-ink-medium)] transition hover:bg-[var(--ui-surface-2)] hover:text-[var(--ui-ink-strong)]",children:[e.jsx(te,{className:"size-4"}),"Choose files",e.jsx("input",{type:"file",multiple:!0,className:"hidden",onChange:t=>Z(Array.from(t.target.files??[]))})]}),Q.length>0?e.jsx("div",{className:"mt-5 grid gap-2 text-left",children:Q.map(t=>e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[18px] border ${INGEST_PANEL_CLASS} px-4 py-3 text-sm text-[var(--ui-ink-medium)]",children:[e.jsx("span",{className:"truncate",children:t.name}),e.jsx("span",{className:"shrink-0 text-xs text-[var(--ui-ink-faint)]",children:t.name.toLowerCase().endsWith(".zip")?e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Fe,{className:"size-3.5"}),"ZIP"]}):`${Math.max(1,Math.round(t.size/1024))} KB`})]},`${t.name}-${t.size}-${t.lastModified}`))}):null]}):null,m==="url"?e.jsx(je,{value:s,onChange:t=>v(t.target.value),placeholder:"https://example.com/source"}):null,m==="text"?e.jsx(Ye,{value:F,onChange:t=>g(t.target.value),placeholder:"Paste notes, transcripts, meeting writeups, or source material here…",className:"min-h-[18rem]"}):null]})})]}),e.jsxs("aside",{className:"grid h-fit gap-4",children:[M?null:e.jsxs("div",{className:"rounded-[30px] border border-[color-mix(in_srgb,var(--warning)_30%,transparent)] bg-[var(--ui-warning-soft)] p-5 shadow-[var(--ui-shadow-card)]",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"mt-0.5 flex size-10 shrink-0 items-center justify-center rounded-full border border-amber-200/20 bg-amber-300/12 text-amber-100",children:e.jsx(Me,{className:"size-4.5"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-amber-100/62",children:"OpenAI setup required for smart ingest"}),e.jsx("div",{className:"mt-2 text-lg font-semibold text-[var(--ui-ink-strong)]",children:"Forge can only do a raw import without OpenAI"}),e.jsx("div",{className:"mt-3 text-sm leading-6 text-[var(--ui-ink-medium)]",children:"Without an OpenAI ingest profile, Forge cannot extract key insights, split the source into draft wiki pages, or propose Forge entities. The fallback is just a direct text import or media reference with no structured synthesis."}),e.jsx("div",{className:"mt-3 text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Set up the API key, model, thinking, and verbosity first, then come back here to build real draft pages and reviewable entity proposals."})]})]}),e.jsxs("div",{className:"mt-5 grid gap-3 sm:grid-cols-2",children:[e.jsxs(C,{className:"w-full",onClick:()=>{a(!1),k("/settings/wiki?setupLlm=1")},children:[e.jsx(G,{className:"size-4"}),"Open OpenAI setup"]}),e.jsx(C,{variant:"secondary",className:"w-full",onClick:()=>{a(!1),k("/settings/wiki")},children:"Open KarpaWiki settings"})]})]}),e.jsxs("div",{className:"rounded-[28px] border ${INGEST_PANEL_CLASS} p-4",children:[e.jsxs("button",{type:"button",className:"flex w-full items-center justify-between gap-3 text-left",onClick:()=>Se(t=>!t),children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Advanced"}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-medium)]",children:"Model, parse, and target controls."})]}),e.jsx(G,{className:"size-4 text-[var(--ui-ink-soft)]"})]}),Ie?e.jsxs("div",{className:"mt-4 grid gap-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"mb-2 text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Space"}),e.jsx("div",{className:"grid gap-2",children:r.map(t=>e.jsxs("button",{type:"button",className:c("rounded-[18px] border px-3 py-3 text-left text-sm transition",w===t.id?q:H),onClick:()=>E(t.id),children:[e.jsx("div",{children:t.label}),e.jsx("div",{className:"mt-1 text-xs text-[var(--ui-ink-faint)]",children:t.description||`/${t.slug}`})]},t.id))})]}),e.jsxs("div",{children:[e.jsx("div",{className:"mb-2 text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"LLM profile"}),e.jsxs("div",{className:"grid gap-2",children:[I.map(t=>e.jsxs("button",{type:"button",className:c("rounded-[18px] border px-3 py-3 text-left text-sm transition",W===t.id?q:H),onClick:()=>ne(t.id),children:[e.jsx("div",{children:t.label}),e.jsx("div",{className:"mt-1 text-xs text-[var(--ui-ink-faint)]",children:t.model})]},t.id)),I.length===0?e.jsx("div",{className:"rounded-[18px] border border-dashed border-[var(--ui-border-subtle)] px-4 py-4 text-sm text-[var(--ui-ink-faint)]",children:"No enabled profile with a saved key yet."}):null]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"mb-2 text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Parse mode"}),e.jsx("div",{className:"grid gap-2 sm:grid-cols-3",children:[{id:"auto",label:"Auto"},{id:"multimodal",label:"Multimodal"},{id:"text_only",label:"Text only"}].map(t=>e.jsx("button",{type:"button",className:c("rounded-[18px] border px-3 py-3 text-sm transition",U===t.id?q:H),onClick:()=>Te(t.id),children:t.label},t.id))})]})]}):null]}),e.jsxs("div",{className:"rounded-[28px] border border-[color-mix(in_srgb,var(--primary)_24%,transparent)] bg-[var(--ui-accent-soft)] p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[var(--ui-ink-strong)]",children:[e.jsx(be,{className:"size-4 text-[var(--secondary)]"}),e.jsx("span",{className:"text-sm font-semibold",children:"Publish only what belongs"})]}),e.jsx("div",{className:"mt-3 text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Forge stages candidate pages, proposed entity records, and page updates first. You review the output before anything is committed to the live memory graph."})]}),O?e.jsx("div",{className:"rounded-[20px] border border-rose-300/22 bg-rose-400/10 px-4 py-3 text-sm text-rose-100",children:O}):null,e.jsxs(C,{className:"min-h-12",pending:de.isPending,pendingLabel:"Starting ingest",disabled:!M,onClick:()=>void de.mutateAsync(),children:[e.jsx(G,{className:"size-4"}),"Start background ingest"]})]})]})})]})]})})}export{pt as W};
|
|
1
|
+
import{b5 as Pe,r as p,j as e,aK as se,dD as te,dE as Le,aN as Ke,dF as Fe,cg as Me,aG as G,dG as be,b7 as $e,b3 as he}from"./vendor-Dnkkx2co.js";import{R as qe,P as ze,O as De,C as Qe,T as Re,D as We,a as Ue}from"./ui-C1iwpj2-.js";import{j as Oe,i as re,k as D}from"./state-vCcAT5Hq.js";import{fb as Be,fc as Ge,fd as ye,fe as He,ff as Ve,fg as Ze,Z as c,I as je,T as Ye,B as C,b as ae,c as ie,g as Xe,fh as Je,fi as et,fj as tt}from"./index-QJkjKYzZ.js";const $=new Set(["queued","processing"]),Ne=15e3,j="border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)]",z="border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",q="border-[color-mix(in_srgb,var(--primary)_30%,transparent)] bg-[var(--ui-accent-soft)] text-[var(--ui-ink-strong)]",H="border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-medium)] hover:bg-[var(--ui-surface-2)] hover:text-[var(--ui-ink-strong)]",at=["goal","project","task","habit","strategy","psyche_value","flashcard","note"];function ke(i){return new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}).format(new Date(i))}function _(i,a){const r=i[a];return typeof r=="number"&&Number.isFinite(r)?r:null}function y(i,a){const r=i[a];return typeof r=="string"&&r.trim().length>0?r:null}function it(i,a){const r=y(i.metadata,"currentFileName")??y(i.metadata,"fileName")??"current source",b=y(i.metadata,"status")??"in_progress",o=_(i.metadata,"chunkIndex"),x=_(i.metadata,"chunkCount"),N=_(i.metadata,"currentFileIndex"),f=_(i.metadata,"currentFileTotal"),k=N!==null&&f!==null?`${r} (${N}/${f})`:r,u=o!==null&&x!==null&&x>1?` · chunk ${o}/${x}`:"";return`Waiting for OpenAI on ${k}${u}. ${a} polls · ${b}.`}function st(i){const a=[];for(const r of i){const b=y(r.metadata,"scope"),x=y(r.metadata,"eventKey")==="llm_compile_background_polled",N=y(r.metadata,"currentFileName")??y(r.metadata,"fileName"),f=_(r.metadata,"chunkIndex"),k=_(r.metadata,"chunkCount"),u=x?["poll",b??"",N??"",f??"",k??""].join(":"):null,m=a[a.length-1],A=m&&y(m.metadata,"eventKey"),w=m&&(y(m.metadata,"currentFileName")??y(m.metadata,"fileName")),E=m&&_(m.metadata,"chunkIndex"),h=m&&_(m.metadata,"chunkCount"),P=m&&A==="llm_compile_background_polled"?["poll",y(m.metadata,"scope")??"",w??"",E??"",h??""].join(":"):null;if(x&&m&&P===u){a[a.length-1]={...r,repetitionCount:m.repetitionCount+1,metadata:{...r.metadata,aggregatedPollCount:m.repetitionCount+1}};continue}a.push({...r,repetitionCount:1})}return a}function V(i){return Xe(i)}function we(i){return typeof i=="string"&&at.includes(i)}function rt(i,a){return typeof a.title=="string"&&a.title.trim().length>0?a.title:typeof a.displayName=="string"&&a.displayName.trim().length>0?a.displayName:typeof a.statement=="string"&&a.statement.trim().length>0?a.statement:`${i}:${String(a.id??"")}`}function nt(i,a){const b=[a.description,a.summary,a.overview,a.valuedDirection,a.whyItMatters,a.originNote].find(o=>typeof o=="string"&&o.trim().length>0);return b||(i==="note"&&typeof a.kind=="string"?a.kind:"")}function lt({candidate:i,decision:a,onDecisionChange:r,spaceId:b}){const o=we(i.payload.entityType)?i.payload.entityType:null,[x,N]=p.useState(a.mappedEntityLabel||i.title||""),[f,k]=p.useState(a.targetNoteLabel||i.title||""),u=typeof i.payload.contentMarkdown=="string"?i.payload.contentMarkdown:typeof i.payload.patchSummary=="string"?i.payload.patchSummary:typeof i.payload.rationale=="string"?i.payload.rationale:i.summary,m=re({queryKey:["forge-wiki-ingest-map-search",o,x.trim()],enabled:i.candidateType==="entity"&&a.action==="map_existing"&&o!==null&&x.trim().length>0,queryFn:async()=>{var F;const v=(await Je({searches:[{entityTypes:o?[o]:void 0,query:x.trim(),limit:8}]})).results[0];return((F=v==null?void 0:v.matches)==null?void 0:F.filter(g=>!!(g&&we(g.entityType)&&typeof g.id=="string"&&g.entity&&typeof g.entity=="object")).map(g=>({entityType:g.entityType,entityId:g.id,label:rt(g.entityType,g.entity),description:nt(g.entityType,g.entity),kind:V(g.entityType)})))??[]}}),A=m.data??[],w=re({queryKey:["forge-wiki-ingest-merge-search",b,f.trim()],enabled:i.candidateType==="page"&&a.action==="merge_existing"&&f.trim().length>0,queryFn:async()=>(await et({spaceId:b,kind:"wiki",mode:"text",query:f.trim(),limit:8})).results.map(v=>({noteId:v.page.id,title:v.page.title,slug:v.page.slug,summary:v.page.summary}))}),E=w.data??[],h=a.mappedEntityId&&a.mappedEntityType?A.find(s=>s.entityId===a.mappedEntityId&&s.entityType===a.mappedEntityType)??(a.mappedEntityLabel?{entityId:a.mappedEntityId,entityType:a.mappedEntityType,label:a.mappedEntityLabel,kind:V(a.mappedEntityType)}:null):null,P=a.targetNoteId?E.find(s=>s.noteId===a.targetNoteId)??(a.targetNoteLabel?{noteId:a.targetNoteId,title:a.targetNoteLabel}:null):null;return e.jsxs("div",{className:c("rounded-[24px] border p-4",j),children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:i.candidateType.replaceAll("_"," ")}),e.jsx("div",{className:"mt-2 text-base font-semibold text-[var(--ui-ink-strong)]",children:i.title||i.targetKey||"Untitled candidate"}),o?e.jsx("div",{className:"mt-2",children:V(o)?e.jsx(ae,{kind:V(o),label:o.replaceAll("_"," "),compact:!0,gradient:!1}):e.jsx(ie,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:o.replaceAll("_"," ")})}):null,i.summary?e.jsx("div",{className:"mt-1 text-sm leading-6 text-[var(--ui-ink-soft)]",children:i.summary}):null]}),e.jsxs("div",{className:"inline-flex items-center gap-2 rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-1",children:[e.jsx("button",{type:"button",className:c("rounded-full px-3 py-1.5 text-xs font-medium transition",a.action==="keep"?"bg-[var(--ui-accent-soft)] text-[var(--ui-ink-strong)]":"text-[var(--ui-ink-soft)] hover:text-[var(--ui-ink-strong)]"),onClick:()=>r({...a,action:"keep"}),children:"Keep"}),i.candidateType==="entity"&&o?e.jsx("button",{type:"button",className:c("rounded-full px-3 py-1.5 text-xs font-medium transition",a.action==="map_existing"?"bg-[var(--ui-info-soft)] text-[var(--ui-ink-strong)]":"text-[var(--ui-ink-soft)] hover:text-[var(--ui-ink-strong)]"),onClick:()=>r({...a,action:"map_existing",mappedEntityType:o}),children:"Map existing"}):null,i.candidateType==="page"?e.jsx("button",{type:"button",className:c("rounded-full px-3 py-1.5 text-xs font-medium transition",a.action==="merge_existing"?"bg-[var(--ui-info-soft)] text-[var(--ui-ink-strong)]":"text-[var(--ui-ink-soft)] hover:text-[var(--ui-ink-strong)]"),onClick:()=>r({...a,action:"merge_existing"}),children:"Merge existing"}):null,e.jsx("button",{type:"button",className:c("rounded-full px-3 py-1.5 text-xs font-medium transition",a.action==="discard"?"bg-[var(--ui-surface-2)] text-[var(--ui-ink-strong)]":"text-[var(--ui-ink-soft)] hover:text-[var(--ui-ink-strong)]"),onClick:()=>r({...a,action:"discard"}),children:"Discard"})]})]}),i.candidateType==="entity"&&o&&a.action==="map_existing"?e.jsxs("div",{className:c("mt-4 grid gap-3 rounded-[18px] border p-4",z),children:[e.jsxs("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:["Map to existing ",o.replaceAll("_"," ")]}),h?e.jsx("div",{className:"flex flex-wrap gap-2",children:e.jsxs("span",{className:"inline-flex items-center gap-2 rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-2.5 py-1.5",children:[h.kind?e.jsx(ae,{kind:h.kind,label:h.label,compact:!0,gradient:!1,className:"max-w-[20rem]"}):e.jsx(ie,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:h.label}),e.jsx("button",{type:"button",className:"rounded-full text-[var(--ui-ink-faint)] transition hover:text-[var(--ui-ink-strong)]",onClick:()=>r({...a,mappedEntityId:void 0,mappedEntityLabel:void 0}),"aria-label":"Clear mapped entity",children:e.jsx(se,{className:"size-3.5"})})]})}):null,e.jsxs("div",{className:c("flex items-center gap-3 rounded-[20px] border px-4 py-3",j),children:[e.jsx(he,{className:"size-4 text-[var(--ui-ink-faint)]"}),e.jsx("input",{value:x,onChange:s=>{N(s.target.value),a.mappedEntityId&&r({...a,mappedEntityId:void 0,mappedEntityLabel:void 0})},placeholder:`Search existing ${o.replaceAll("_"," ")}`,className:"min-w-0 flex-1 bg-transparent text-sm text-[var(--ui-ink-strong)] placeholder:text-[var(--ui-ink-faint)] focus:outline-none"})]}),e.jsx("div",{className:"grid gap-2",children:m.isPending?e.jsx("div",{className:c("rounded-[16px] border px-3 py-3 text-sm text-[var(--ui-ink-faint)]",j),children:"Searching Forge…"}):A.length===0?e.jsxs("div",{className:"rounded-[16px] border border-dashed border-[var(--ui-border-subtle)] px-3 py-3 text-sm text-[var(--ui-ink-faint)]",children:["No existing ",o.replaceAll("_"," ")," matches yet."]}):A.map(s=>{const v=a.mappedEntityType===s.entityType&&a.mappedEntityId===s.entityId;return e.jsx("button",{type:"button",className:c("flex w-full items-start justify-between gap-3 rounded-[18px] border px-3 py-3 text-left transition",v?q:"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-medium)] hover:bg-[var(--ui-surface-2)] hover:text-[var(--ui-ink-strong)]"),onClick:()=>r({action:"map_existing",mappedEntityType:s.entityType,mappedEntityId:s.entityId,mappedEntityLabel:s.label}),children:e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-medium",children:s.kind?e.jsx(ae,{kind:s.kind,label:s.label,compact:!0,gradient:!1}):s.label}),s.description?e.jsx("div",{className:"mt-1 text-xs leading-5 text-[var(--ui-ink-faint)]",children:s.description}):null]})},`${s.entityType}:${s.entityId}`)})})]}):null,i.candidateType==="page"&&a.action==="merge_existing"?e.jsxs("div",{className:c("mt-4 grid gap-3 rounded-[18px] border p-4",z),children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Merge into existing page"}),P?e.jsx("div",{className:"flex flex-wrap gap-2",children:e.jsxs("span",{className:"inline-flex items-center gap-2 rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-2.5 py-1.5",children:[e.jsx(ie,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:P.title}),e.jsx("button",{type:"button",className:"rounded-full text-[var(--ui-ink-faint)] transition hover:text-[var(--ui-ink-strong)]",onClick:()=>r({...a,targetNoteId:void 0,targetNoteLabel:void 0}),"aria-label":"Clear merge target",children:e.jsx(se,{className:"size-3.5"})})]})}):null,e.jsxs("div",{className:c("flex items-center gap-3 rounded-[20px] border px-4 py-3",j),children:[e.jsx(he,{className:"size-4 text-[var(--ui-ink-faint)]"}),e.jsx("input",{value:f,onChange:s=>{k(s.target.value),a.targetNoteId&&r({...a,targetNoteId:void 0,targetNoteLabel:void 0})},placeholder:"Search existing wiki pages",className:"min-w-0 flex-1 bg-transparent text-sm text-[var(--ui-ink-strong)] placeholder:text-[var(--ui-ink-faint)] focus:outline-none"})]}),e.jsx("div",{className:"grid gap-2",children:w.isPending?e.jsx("div",{className:c("rounded-[16px] border px-3 py-3 text-sm text-[var(--ui-ink-faint)]",j),children:"Searching Forge…"}):E.length===0?e.jsx("div",{className:"rounded-[16px] border border-dashed border-[var(--ui-border-subtle)] px-3 py-3 text-sm text-[var(--ui-ink-faint)]",children:"No existing wiki pages match yet."}):E.map(s=>{const v=a.targetNoteId===s.noteId;return e.jsx("button",{type:"button",className:c("flex w-full items-start justify-between gap-3 rounded-[18px] border px-3 py-3 text-left transition",v?q:"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-medium)] hover:bg-[var(--ui-surface-2)] hover:text-[var(--ui-ink-strong)]"),onClick:()=>r({action:"merge_existing",targetNoteId:s.noteId,targetNoteLabel:s.title}),children:e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-medium",children:s.title}),e.jsxs("div",{className:"mt-1 text-xs leading-5 text-[var(--ui-ink-faint)]",children:[s.slug?`${s.slug}`:"",s.summary?`${s.slug?" · ":""}${s.summary}`:""]})]})},s.noteId)})})]}):null,u?e.jsx("div",{className:c("mt-4 rounded-[18px] border px-4 py-3 text-sm leading-6 text-[var(--ui-ink-medium)]",z),children:e.jsx("pre",{className:"whitespace-pre-wrap font-sans",children:u})}):null]})}function pt({open:i,onOpenChange:a,spaces:r,llmProfiles:b,initialSpaceId:o,selectedJobId:x,onJobSelected:N,linkedEntityHints:f=[]}){var ge;const k=Pe(),u=Oe(),[m,A]=p.useState("files"),[w,E]=p.useState(o),[h,P]=p.useState(""),[s,v]=p.useState(""),[F,g]=p.useState(""),[Q,Z]=p.useState([]),[Ee,R]=p.useState(!1),[Ie,Se]=p.useState(!1),I=p.useMemo(()=>b.filter(t=>t.enabled&&!!t.secretId),[b]),[W,ne]=p.useState(((ge=I[0])==null?void 0:ge.id)??""),[U,Te]=p.useState("auto"),[Y,le]=p.useState({}),[O,S]=p.useState(null),[B,T]=p.useState(null),oe=p.useRef({});p.useEffect(()=>{o&&E(o)},[o]),p.useEffect(()=>{var t;!W&&((t=I[0])!=null&&t.id)&&ne(I[0].id)},[W,I]);const M=I.find(t=>t.id===W)??I[0]??null,L=re({queryKey:["forge-wiki-ingest-job",x],queryFn:()=>tt(x),enabled:i&&!!x,refetchInterval:t=>{const d=t.state.data;return d&&$.has(d.job.status)?2e3:!1}});p.useEffect(()=>{const t=L.data;t&&le(d=>{const l={};for(const K of t.candidates)l[K.id]=d[K.id]??(K.status==="rejected"?{action:"discard"}:{action:"keep"});return l})},[L.data]),p.useEffect(()=>{B&&T(null)},[Y,B]);const X=D({mutationFn:async t=>Be(t),onSuccess:(t,d)=>{t.job&&u.setQueryData(["forge-wiki-ingest-job",d],t.job),u.invalidateQueries({queryKey:["forge-wiki-ingest-jobs"]}),u.invalidateQueries({queryKey:["forge-wiki-ingest-history"]})}});p.useEffect(()=>{const t=L.data;if(!t||!$.has(t.job.status))return;const d=t.logs.reduce((ve,Ae)=>{const fe=Number(new Date(Ae.createdAt));return Number.isFinite(fe)?Math.max(ve,fe):ve},0),l=Number(new Date(t.job.updatedAt)),K=Math.max(Number.isFinite(l)?l:0,d);if(!Number.isFinite(K)||K<=0)return;const ee=Date.now();if(!(ee-K>=Ne)||X.isPending)return;const _e=oe.current[t.job.id]??0;ee-_e<Ne||(oe.current[t.job.id]=ee,X.mutate(t.job.id))},[L.data,X]);const de=D({mutationFn:async()=>{if(!M)throw new Error("Set up an OpenAI wiki ingest profile first. Forge now requires an LLM profile before auto-ingest can turn source material into draft pages and entities.");if(m==="files"){if(Q.length===0)throw new Error("Select at least one file to ingest.");return Ge({files:Q,spaceId:w||void 0,titleHint:h.trim()||void 0,llmProfileId:M.id,parseStrategy:U,createAsKind:"wiki",linkedEntityHints:f})}if(m==="url"){if(!s.trim())throw new Error("Enter a URL to ingest.");return ye({spaceId:w||void 0,titleHint:h.trim()||void 0,sourceKind:"url",sourceUrl:s.trim(),llmProfileId:M.id,parseStrategy:U,createAsKind:"wiki",linkedEntityHints:f})}if(!F.trim())throw new Error("Paste some text to ingest.");return ye({spaceId:w||void 0,titleHint:h.trim()||void 0,sourceKind:"raw_text",sourceText:F,mimeType:"text/plain",llmProfileId:M.id,parseStrategy:U,createAsKind:"wiki",linkedEntityHints:f})},onSuccess:async t=>{var l;const d=((l=t.job)==null?void 0:l.job.id)??null;await u.invalidateQueries({queryKey:["forge-wiki-ingest-jobs"]}),await u.invalidateQueries({queryKey:["forge-wiki-ingest-history"]}),d&&N(d),S(null),T(null)},onError:t=>{S(t instanceof Error?t.message:"Unable to start ingest.")}}),ce=D({mutationFn:async()=>{if(!x||!L.data)throw new Error("Choose an ingest job first.");const t=L.data.candidates.map(d=>{const l=Y[d.id]??{action:"keep"};if(l.action==="map_existing"&&(!l.mappedEntityType||!l.mappedEntityId))throw new Error(`Choose an existing ${String(d.payload.entityType??"entity").replaceAll("_"," ")} before publishing the review.`);if(l.action==="merge_existing"&&!l.targetNoteId)throw new Error(`Choose an existing wiki page before publishing the review for ${d.title||"this page candidate"}.`);return l.action==="map_existing"?{candidateId:d.id,action:"map_existing",mappedEntityType:l.mappedEntityType,mappedEntityId:l.mappedEntityId}:l.action==="merge_existing"?{candidateId:d.id,action:"merge_existing",targetNoteId:l.targetNoteId}:{candidateId:d.id,action:l.action}});return He({jobId:x,decisions:t})},onSuccess:async t=>{T(null),u.setQueryData(["forge-wiki-ingest-job",t.job.job.id],t.job),await Promise.all([u.invalidateQueries({queryKey:["forge-wiki-ingest-jobs"]}),u.invalidateQueries({queryKey:["forge-wiki-ingest-history"]}),u.invalidateQueries({queryKey:["forge-wiki-ingest-job",t.job.job.id]}),u.invalidateQueries({queryKey:["forge-wiki-home"]}),u.invalidateQueries({queryKey:["forge-wiki-page-by-slug"]}),u.invalidateQueries({queryKey:["forge-wiki-tree"]})])},onError:t=>{T(t instanceof Error?t.message:"Unable to publish review.")}}),ue=D({mutationFn:async()=>{if(!x)throw new Error("Choose an ingest job first.");return Ve(x)},onSuccess:async t=>{var l;const d=((l=t.job)==null?void 0:l.job.id)??null;await Promise.all([u.invalidateQueries({queryKey:["forge-wiki-ingest-jobs"]}),u.invalidateQueries({queryKey:["forge-wiki-ingest-history"]}),u.invalidateQueries({queryKey:["forge-wiki-ingest-job",x]})]),d&&N(d),S(null),T(null)},onError:t=>{S(t instanceof Error?t.message:"Unable to rerun ingest.")}}),me=D({mutationFn:async()=>{if(!x)throw new Error("Choose an ingest job first.");return Ze(x)},onSuccess:async()=>{await Promise.all([u.invalidateQueries({queryKey:["forge-wiki-ingest-jobs"]}),u.invalidateQueries({queryKey:["forge-wiki-ingest-history"]}),u.invalidateQueries({queryKey:["forge-wiki-ingest-job",x]})]),xe(),S(null),T(null)},onError:t=>{S(t instanceof Error?t.message:"Unable to delete ingest.")}}),n=L.data??null,Ce=n&&!$.has(n.job.status),J=p.useMemo(()=>(n==null?void 0:n.candidates.filter(t=>["suggested","rejected","failed"].includes(t.status)))??[],[n]),pe=p.useMemo(()=>st((n==null?void 0:n.logs)??[]),[n==null?void 0:n.logs]),xe=()=>{N(null),Z([]),v(""),g(""),P(""),S(null),T(null)};return e.jsx(qe,{open:i,onOpenChange:t=>{a(t),t||(S(null),T(null))},children:e.jsxs(ze,{children:[e.jsx(De,{className:"fixed inset-0 z-50 surface-overlay backdrop-blur-sm"}),e.jsxs(Qe,{className:"fixed inset-x-4 bottom-4 top-4 z-50 mx-auto flex max-w-[min(74rem,calc(100vw-2rem))] flex-col overflow-hidden rounded-[32px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-popover)] shadow-[var(--ui-shadow-floating)]",children:[e.jsx("div",{className:"border-b border-[var(--ui-border-subtle)] px-5 py-5",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"KarpaWiki Ingest"}),e.jsx(Re,{className:"mt-2 font-display text-[1.5rem] tracking-[-0.04em] text-[var(--ui-ink-strong)]",children:n?"Ingest review and progress":"Build KarpaWiki memory from source files"}),e.jsx(We,{className:"mt-2 max-w-3xl text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Upload notes, media, ZIP archives, links, or pasted text. Forge will process them in the background, propose pages and entities, and let you keep only what belongs."})]}),e.jsx(Ue,{asChild:!0,children:e.jsx("button",{type:"button",className:"rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-2 text-[var(--ui-ink-soft)] transition hover:bg-[var(--ui-surface-2)] hover:text-[var(--ui-ink-strong)]","aria-label":"Close ingest modal",children:e.jsx(se,{className:"size-4"})})})]})}),e.jsx("div",{className:"flex-1 overflow-y-auto px-5 py-5",children:n?e.jsxs("div",{className:"grid gap-5 xl:grid-cols-[minmax(0,0.9fr)_minmax(0,1.1fr)]",children:[e.jsxs("div",{className:"grid gap-5",children:[e.jsxs("div",{className:c("rounded-[28px] border p-4 sm:p-5",j),children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:["Job ",n.job.id]}),e.jsx("div",{className:"mt-2 text-xl font-semibold text-[var(--ui-ink-strong)]",children:n.job.latestMessage||"Ingest job"}),e.jsxs("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:[n.job.status," · ",n.job.phase," · started ",ke(n.job.createdAt)]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(C,{variant:"secondary",size:"sm",onClick:xe,children:"New ingest"}),Ce?e.jsxs(e.Fragment,{children:[e.jsxs(C,{variant:"secondary",size:"sm",pending:ue.isPending,pendingLabel:"Rerunning",onClick:()=>void ue.mutateAsync(),children:[e.jsx(G,{className:"size-3.5"}),"Rerun"]}),e.jsx(C,{variant:"ghost",size:"sm",className:"border border-rose-300/18 bg-rose-400/10 text-rose-100 hover:bg-rose-400/16",pending:me.isPending,pendingLabel:"Deleting",onClick:()=>{window.confirm("Delete this ingest history entry? Published pages or entities will stay, but discarded or unreviewed ingest data will be removed.")&&me.mutateAsync()},children:"Delete"})]}):null]})]}),e.jsx("div",{className:"mt-5 grid gap-3 sm:grid-cols-4",children:[{label:"Progress",value:`${n.job.progressPercent}%`},{label:"Files",value:`${n.job.processedFiles}/${n.job.totalFiles}`},{label:"Pages",value:String(n.job.createdPageCount)},{label:"Entities",value:String(n.job.createdEntityCount)}].map(t=>e.jsxs("div",{className:c("rounded-[22px] border px-4 py-3",z),children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:t.label}),e.jsx("div",{className:"mt-2 text-lg font-semibold text-[var(--ui-ink-strong)]",children:t.value})]},t.label))}),e.jsx("div",{className:"mt-5",children:e.jsx("div",{className:"h-2 overflow-hidden rounded-full bg-[var(--ui-surface-2)]",children:e.jsx("div",{className:"h-full rounded-full bg-[var(--primary)] transition-all duration-300",style:{width:`${n.job.progressPercent}%`}})})}),O?e.jsx("div",{className:"mt-4 rounded-[20px] border border-rose-300/22 bg-rose-400/10 px-4 py-3 text-sm text-rose-100",children:O}):null]}),e.jsxs("div",{className:c("rounded-[28px] border p-4 sm:p-5",j),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Rich log"}),e.jsx(C,{variant:"secondary",size:"sm",onClick:()=>k(`/settings/logs?jobId=${encodeURIComponent(n.job.id)}`),children:"Open full logs"})]}),e.jsx("div",{className:"mt-4 grid max-h-[28rem] gap-2 overflow-y-auto",children:pe.length===0?e.jsx("div",{className:"rounded-[18px] border border-dashed border-[var(--ui-border-subtle)] px-4 py-4 text-sm text-[var(--ui-ink-faint)]",children:"Waiting for the backend to emit progress."}):pe.map(t=>e.jsx("div",{className:c("rounded-[18px] border px-4 py-3",z),children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-2 py-1 text-[10px] font-semibold uppercase tracking-[0.14em] text-[var(--ui-ink-soft)]",children:t.level}),typeof t.metadata.scope=="string"?e.jsx("span",{className:"rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-2 py-1 text-[10px] font-semibold uppercase tracking-[0.14em] text-[var(--ui-ink-faint)]",children:t.metadata.scope}):null,typeof t.metadata.eventKey=="string"?e.jsx("span",{className:"rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-2 py-1 text-[10px] font-semibold uppercase tracking-[0.14em] text-[var(--ui-ink-faint)]",children:t.metadata.eventKey}):null]}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-strong)]",children:y(t.metadata,"eventKey")==="llm_compile_background_polled"?it(t,t.repetitionCount):t.message}),t.repetitionCount>1?e.jsxs("div",{className:"mt-2 text-xs text-[var(--ui-ink-faint)]",children:["Combined ",t.repetitionCount," repeated polling updates."]}):null,Object.keys(t.metadata).length>0?e.jsxs("details",{className:"mt-3",children:[e.jsx("summary",{className:"cursor-pointer text-xs text-[var(--ui-ink-faint)]",children:"View metadata"}),e.jsx("pre",{className:"mt-2 max-w-full overflow-x-auto whitespace-pre-wrap rounded-[14px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-code)] px-3 py-3 text-[11px] leading-5 text-[var(--ui-ink-soft)]",children:JSON.stringify(t.metadata,null,2)})]}):null]}),e.jsx("div",{className:"text-[11px] uppercase tracking-[0.14em] text-[var(--ui-ink-faint)]",children:ke(t.createdAt)})]})},t.id))})]})]}),e.jsxs("div",{className:"grid gap-5",children:[e.jsxs("div",{className:c("rounded-[28px] border p-4 sm:p-5",j),children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Source files"}),e.jsx("div",{className:"mt-4 grid gap-2",children:n.assets.map(t=>e.jsxs("div",{className:c("flex min-w-0 items-center justify-between gap-3 rounded-[18px] border px-4 py-3",z),children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-medium text-[var(--ui-ink-strong)]",children:t.fileName||t.sourceLocator||"Source"}),e.jsx("div",{className:"mt-1 text-xs text-[var(--ui-ink-faint)]",children:t.mimeType||t.sourceKind})]}),e.jsx("div",{className:"shrink-0 text-[11px] uppercase tracking-[0.14em] text-[var(--ui-ink-faint)]",children:t.status})]},t.id))})]}),e.jsxs("div",{className:c("rounded-[28px] border p-4 sm:p-5",j),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Review"}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Keep the candidates that belong in Forge and discard the rest."})]}),$.has(n.job.status)?e.jsxs("div",{className:"inline-flex items-center gap-2 rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-3 py-2 text-xs text-[var(--ui-ink-soft)]",children:[e.jsx($e,{className:"size-3.5 animate-spin"}),"Processing"]}):null]}),e.jsx("div",{className:"mt-4 grid gap-3",children:J.length===0?e.jsx("div",{className:"rounded-[18px] border border-dashed border-[var(--ui-border-subtle)] px-4 py-4 text-sm text-[var(--ui-ink-faint)]",children:$.has(n.job.status)?"Candidates will appear here while the job progresses.":"This job has no reviewable candidates left."}):J.map(t=>e.jsx(lt,{candidate:t,spaceId:n.job.spaceId,decision:Y[t.id]??{action:"keep"},onDecisionChange:d=>le(l=>({...l,[t.id]:d}))},t.id))}),B?e.jsx("div",{className:"mt-4 rounded-[20px] border border-rose-300/22 bg-rose-400/10 px-4 py-3 text-sm text-rose-100",children:B}):null,J.length>0&&!$.has(n.job.status)?e.jsx("div",{className:"mt-5",children:e.jsxs(C,{className:"min-h-12",pending:ce.isPending,pendingLabel:"Publishing review",onClick:()=>void ce.mutateAsync(),children:[e.jsx(be,{className:"size-4"}),"Publish kept candidates"]})}):null]})]})]}):e.jsxs("div",{className:"grid gap-5 lg:grid-cols-[minmax(0,1.15fr)_minmax(18rem,0.85fr)]",children:[e.jsxs("div",{className:"grid gap-5",children:[e.jsx("div",{className:"grid gap-3 sm:grid-cols-3",children:[{id:"files",label:"Files and ZIP",detail:"Drag many files or one archive.",icon:te},{id:"url",label:"URL",detail:"Pull a webpage or remote file.",icon:Le},{id:"text",label:"Paste text",detail:"Turn notes or transcripts into pages.",icon:Ke}].map(t=>{const d=t.icon,l=t.id===m;return e.jsxs("button",{type:"button",className:c("rounded-[24px] border px-4 py-4 text-left transition",l?q:H),onClick:()=>A(t.id),children:[e.jsx(d,{className:"size-4 text-[var(--secondary)]"}),e.jsx("div",{className:"mt-3 text-sm font-semibold",children:t.label}),e.jsx("div",{className:"mt-1 text-xs leading-5 text-[var(--ui-ink-faint)]",children:t.detail})]},t.id)})}),e.jsx("div",{className:c("rounded-[28px] border p-4 sm:p-5",j),children:e.jsxs("div",{className:"grid gap-4",children:[e.jsx(je,{value:h,onChange:t=>P(t.target.value),placeholder:"Optional title hint"}),m==="files"?e.jsxs("div",{className:c("rounded-[28px] border-2 border-dashed px-5 py-8 text-center transition",Ee?"border-[color-mix(in_srgb,var(--primary)_36%,transparent)] bg-[var(--ui-accent-soft)]":j),onDragEnter:t=>{t.preventDefault(),R(!0)},onDragLeave:t=>{t.preventDefault(),R(!1)},onDragOver:t=>{t.preventDefault(),R(!0)},onDrop:t=>{t.preventDefault(),R(!1);const d=Array.from(t.dataTransfer.files);Z(l=>[...l,...d])},children:[e.jsx("div",{className:"mx-auto flex size-14 items-center justify-center rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",children:e.jsx(te,{className:"size-5 text-[var(--ui-ink-medium)]"})}),e.jsx("div",{className:"mt-4 text-base font-semibold text-[var(--ui-ink-strong)]",children:"Drop files, media, notes, or ZIP archives here"}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-faint)]",children:"Forge accepts many files at once and queues the ingest in the background so the UI stays responsive."}),e.jsxs("label",{className:"mt-5 inline-flex cursor-pointer items-center gap-2 rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-2 text-sm text-[var(--ui-ink-medium)] transition hover:bg-[var(--ui-surface-2)] hover:text-[var(--ui-ink-strong)]",children:[e.jsx(te,{className:"size-4"}),"Choose files",e.jsx("input",{type:"file",multiple:!0,className:"hidden",onChange:t=>Z(Array.from(t.target.files??[]))})]}),Q.length>0?e.jsx("div",{className:"mt-5 grid gap-2 text-left",children:Q.map(t=>e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[18px] border ${INGEST_PANEL_CLASS} px-4 py-3 text-sm text-[var(--ui-ink-medium)]",children:[e.jsx("span",{className:"truncate",children:t.name}),e.jsx("span",{className:"shrink-0 text-xs text-[var(--ui-ink-faint)]",children:t.name.toLowerCase().endsWith(".zip")?e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Fe,{className:"size-3.5"}),"ZIP"]}):`${Math.max(1,Math.round(t.size/1024))} KB`})]},`${t.name}-${t.size}-${t.lastModified}`))}):null]}):null,m==="url"?e.jsx(je,{value:s,onChange:t=>v(t.target.value),placeholder:"https://example.com/source"}):null,m==="text"?e.jsx(Ye,{value:F,onChange:t=>g(t.target.value),placeholder:"Paste notes, transcripts, meeting writeups, or source material here…",className:"min-h-[18rem]"}):null]})})]}),e.jsxs("aside",{className:"grid h-fit gap-4",children:[M?null:e.jsxs("div",{className:"rounded-[30px] border border-[color-mix(in_srgb,var(--warning)_30%,transparent)] bg-[var(--ui-warning-soft)] p-5 shadow-[var(--ui-shadow-card)]",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"mt-0.5 flex size-10 shrink-0 items-center justify-center rounded-full border border-amber-200/20 bg-amber-300/12 text-amber-100",children:e.jsx(Me,{className:"size-4.5"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-amber-100/62",children:"OpenAI setup required for smart ingest"}),e.jsx("div",{className:"mt-2 text-lg font-semibold text-[var(--ui-ink-strong)]",children:"Forge can only do a raw import without OpenAI"}),e.jsx("div",{className:"mt-3 text-sm leading-6 text-[var(--ui-ink-medium)]",children:"Without an OpenAI ingest profile, Forge cannot extract key insights, split the source into draft wiki pages, or propose Forge entities. The fallback is just a direct text import or media reference with no structured synthesis."}),e.jsx("div",{className:"mt-3 text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Set up the API key, model, thinking, and verbosity first, then come back here to build real draft pages and reviewable entity proposals."})]})]}),e.jsxs("div",{className:"mt-5 grid gap-3 sm:grid-cols-2",children:[e.jsxs(C,{className:"w-full",onClick:()=>{a(!1),k("/settings/wiki?setupLlm=1")},children:[e.jsx(G,{className:"size-4"}),"Open OpenAI setup"]}),e.jsx(C,{variant:"secondary",className:"w-full",onClick:()=>{a(!1),k("/settings/wiki")},children:"Open KarpaWiki settings"})]})]}),e.jsxs("div",{className:"rounded-[28px] border ${INGEST_PANEL_CLASS} p-4",children:[e.jsxs("button",{type:"button",className:"flex w-full items-center justify-between gap-3 text-left",onClick:()=>Se(t=>!t),children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Advanced"}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-medium)]",children:"Model, parse, and target controls."})]}),e.jsx(G,{className:"size-4 text-[var(--ui-ink-soft)]"})]}),Ie?e.jsxs("div",{className:"mt-4 grid gap-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"mb-2 text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Space"}),e.jsx("div",{className:"grid gap-2",children:r.map(t=>e.jsxs("button",{type:"button",className:c("rounded-[18px] border px-3 py-3 text-left text-sm transition",w===t.id?q:H),onClick:()=>E(t.id),children:[e.jsx("div",{children:t.label}),e.jsx("div",{className:"mt-1 text-xs text-[var(--ui-ink-faint)]",children:t.description||`/${t.slug}`})]},t.id))})]}),e.jsxs("div",{children:[e.jsx("div",{className:"mb-2 text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"LLM profile"}),e.jsxs("div",{className:"grid gap-2",children:[I.map(t=>e.jsxs("button",{type:"button",className:c("rounded-[18px] border px-3 py-3 text-left text-sm transition",W===t.id?q:H),onClick:()=>ne(t.id),children:[e.jsx("div",{children:t.label}),e.jsx("div",{className:"mt-1 text-xs text-[var(--ui-ink-faint)]",children:t.model})]},t.id)),I.length===0?e.jsx("div",{className:"rounded-[18px] border border-dashed border-[var(--ui-border-subtle)] px-4 py-4 text-sm text-[var(--ui-ink-faint)]",children:"No enabled profile with a saved key yet."}):null]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"mb-2 text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Parse mode"}),e.jsx("div",{className:"grid gap-2 sm:grid-cols-3",children:[{id:"auto",label:"Auto"},{id:"multimodal",label:"Multimodal"},{id:"text_only",label:"Text only"}].map(t=>e.jsx("button",{type:"button",className:c("rounded-[18px] border px-3 py-3 text-sm transition",U===t.id?q:H),onClick:()=>Te(t.id),children:t.label},t.id))})]})]}):null]}),e.jsxs("div",{className:"rounded-[28px] border border-[color-mix(in_srgb,var(--primary)_24%,transparent)] bg-[var(--ui-accent-soft)] p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[var(--ui-ink-strong)]",children:[e.jsx(be,{className:"size-4 text-[var(--secondary)]"}),e.jsx("span",{className:"text-sm font-semibold",children:"Publish only what belongs"})]}),e.jsx("div",{className:"mt-3 text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Forge stages candidate pages, proposed entity records, and page updates first. You review the output before anything is committed to the live memory graph."})]}),O?e.jsx("div",{className:"rounded-[20px] border border-rose-300/22 bg-rose-400/10 px-4 py-3 text-sm text-rose-100",children:O}):null,e.jsxs(C,{className:"min-h-12",pending:de.isPending,pendingLabel:"Starting ingest",disabled:!M,onClick:()=>void de.mutateAsync(),children:[e.jsx(G,{className:"size-4"}),"Start background ingest"]})]})]})})]})]})})}export{pt as W};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{b5 as Se,cc as Ee,c2 as We,r as c,j as e,b3 as Pe,cx as B,aG as ie,cG as Re,cL as ze,c7 as Ke,b4 as $e,aC as le,aK as ce,bl as Le,cA as qe}from"./vendor-Dnkkx2co.js";import{R as de,P as ue,O as pe,C as me,T as xe,a as ge,D as Te}from"./ui-C1iwpj2-.js";import{j as Ue,i as K,k as Fe}from"./state-vCcAT5Hq.js";import{u as De,a9 as Oe,bq as Be,f6 as Me,L as O,E as ne,a as Qe,b as oe,a8 as Je,B as T,Z as w,cL as Ae,I as _e,c as He,bY as Ge,f7 as Ye,f8 as Ve,f9 as Xe,fa as Ze}from"./index-QJkjKYzZ.js";import{O as es}from"./open-in-graph-button-CMjJZX7G.js";import{W as ss}from"./wiki-article-markdown-Bi02AsVt.js";import{W as ts}from"./wiki-ingest-modal-Ig_xnyc6.js";import"./motion-Lt5B1XuE.js";import"./forms-hB0SqEh-.js";import"./board-dIX6etHh.js";import"./graph-DDUZNRsO.js";function rs(a){return new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric",year:"numeric"}).format(new Date(a))}function as(a){return a.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function he({nodes:a,activeSlug:i,spaceId:u,depth:n=0}){return e.jsx("ul",{className:w("grid gap-1",n>0&&"mt-1"),children:a.map(d=>e.jsx(is,{node:d,activeSlug:i,spaceId:u,depth:n},d.page.id))})}function fe(a,i){return i?a.page.slug===i?!0:a.children.some(u=>fe(u,i)):!1}function is({node:a,activeSlug:i,spaceId:u,depth:n}){const d=a.children.length>0,f=a.page.slug===i,x=fe(a,i),[l,b]=c.useState(d&&(n===0||x));return c.useEffect(()=>{x&&b(!0)},[x]),e.jsxs("li",{className:"grid gap-1",children:[e.jsxs("div",{className:"flex items-start gap-1",children:[d?e.jsx("button",{type:"button",className:w("mt-1 inline-flex size-5 shrink-0 items-center justify-center rounded-md text-[var(--ui-ink-faint)] transition hover:bg-[var(--ui-surface-1)] hover:text-[var(--ui-ink-strong)]",n>0&&"size-4"),style:{marginLeft:`${n*.7}rem`},"aria-label":l?`Collapse ${a.page.title}`:`Expand ${a.page.title}`,"aria-expanded":l,onClick:()=>b(N=>!N),children:l?e.jsx(B,{className:"size-3.5"}):e.jsx(qe,{className:"size-3.5"})}):e.jsx("span",{className:"mt-1 size-5 shrink-0",style:{marginLeft:`${n*.7}rem`}}),e.jsx(le,{to:{pathname:a.page.slug==="index"?"/wiki":`/wiki/page/${encodeURIComponent(a.page.slug)}`,search:`?spaceId=${encodeURIComponent(u)}`},className:w("min-w-0 flex-1 rounded-lg px-2 py-1.5 text-[12px] leading-5 transition",f?"bg-[var(--ui-surface-2)] text-[var(--ui-ink-strong)]":"text-[var(--ui-ink-soft)] hover:bg-[var(--ui-surface-1)] hover:text-[var(--ui-ink-strong)]"),children:e.jsx("span",{className:"line-clamp-2",children:a.page.title})})]}),d&&l?e.jsx(he,{nodes:a.children,activeSlug:i,spaceId:u,depth:n+1}):null]})}function ns({open:a,onOpenChange:i,spaces:u,activeSpaceId:n,onSelect:d}){var x;const f=((x=u.find(l=>l.visibility==="shared"))==null?void 0:x.id)??"";return e.jsx(de,{open:a,onOpenChange:i,children:e.jsxs(ue,{children:[e.jsx(pe,{className:"fixed inset-0 z-50 surface-overlay backdrop-blur-sm"}),e.jsxs(me,{className:"fixed left-1/2 top-[14vh] z-50 w-[min(28rem,calc(100vw-1.5rem))] -translate-x-1/2 rounded-[28px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-popover)] p-4 shadow-[var(--ui-shadow-floating)] sm:p-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx(xe,{className:"font-display text-[1.2rem] tracking-[-0.04em] text-[var(--ui-ink-strong)]",children:"Choose KarpaWiki space"}),e.jsx(Te,{className:"mt-1 text-[13px] leading-6 text-[var(--ui-ink-soft)]",children:"Switch the reading space without leaving the article surface."})]}),e.jsx(ge,{asChild:!0,children:e.jsx("button",{type:"button",className:"rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-2 text-[var(--ui-ink-soft)] transition hover:bg-[var(--ui-surface-2)] hover:text-[var(--ui-ink-strong)]","aria-label":"Close space picker",children:e.jsx(ce,{className:"size-4"})})})]}),e.jsx("div",{className:"mt-4 grid gap-2",children:u.map(l=>{const b=l.id===n,N=l.id===f;return e.jsxs("button",{type:"button",className:w("flex items-center justify-between gap-3 rounded-[22px] border px-4 py-3 text-left transition",b?"border-[color-mix(in_srgb,var(--primary)_26%,transparent)] bg-[var(--ui-accent-soft)] text-[var(--ui-ink-strong)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-medium)] hover:bg-[var(--ui-surface-2)] hover:text-[var(--ui-ink-strong)]"),onClick:()=>{d(l.id),i(!1)},children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-[14px] font-semibold text-inherit",children:l.label}),e.jsx("span",{className:"mt-1 block text-[12px] leading-5 text-[var(--ui-ink-soft)]",children:l.description||`/${l.slug}`}),N?e.jsx("span",{className:"mt-2 inline-flex rounded-full bg-amber-200/90 px-2 py-0.5 text-[10px] font-semibold uppercase tracking-[0.14em] text-stone-950",children:"Recovered pages"}):null]}),b?e.jsx(Le,{className:"size-4 shrink-0 text-[var(--primary)]"}):null]},l.id)})})]})]})})}function bs(){var H,G,Y,V,X,Z,ee,se,te,re;const a=De(),i=Se(),u=Ue(),{slug:n}=Ee(),[d,f]=We(),[x,l]=c.useState(!1),[b,N]=c.useState(!1),[U,E]=c.useState(!1),[v,be]=c.useState("hybrid"),[W,ve]=c.useState(""),[P,M]=c.useState(""),Q=c.useRef(null),F=d.get("spaceId")??"",ke=d.get("ingest")==="1",J=d.get("ingestJobId"),p=K({queryKey:["forge-wiki-settings"],queryFn:Ge}),t=F||((G=(H=p.data)==null?void 0:H.settings.spaces[0])==null?void 0:G.id)||"",R=((Y=p.data)==null?void 0:Y.settings.embeddingProfiles.filter(s=>s.enabled))??[];c.useEffect(()=>{var s;!P&&((s=R[0])!=null&&s.id)&&M(R[0].id)},[R,P]),c.useEffect(()=>{var s,o;if(!F&&((o=(s=p.data)==null?void 0:s.settings.spaces[0])!=null&&o.id)){const g=new URLSearchParams(d);g.set("spaceId",p.data.settings.spaces[0].id),f(g,{replace:!0})}},[d,F,f,p.data]);const I=K({queryKey:["forge-wiki-home",t],queryFn:()=>Ye({spaceId:t||void 0}),enabled:!!t&&!n}),h=K({queryKey:["forge-wiki-page-by-slug",t,n],queryFn:()=>Ve({slug:n??"index",spaceId:t||void 0}),enabled:!!t&&!!n}),z=K({queryKey:["forge-wiki-tree",t],queryFn:()=>Xe({spaceId:t||void 0,kind:"wiki"}),enabled:!!t}),C=K({queryKey:["forge-wiki-modal-search",t,v,W,P],queryFn:()=>Ze({spaceId:t||void 0,mode:v,query:W.trim(),profileId:(v==="semantic"||v==="hybrid")&&P||void 0,limit:30}),enabled:x&&!!t&&W.trim().length>0}),$=n?h.data??null:I.data??null,[ye,je]=c.useState(null);c.useEffect(()=>{$&&je($)},[$]);const L=!!t&&(n?h.isFetching:I.isFetching),k=$??(L?ye:null),r=(k==null?void 0:k.page)??null,m=((V=p.data)==null?void 0:V.settings.spaces.find(s=>s.id===t))??null,y=((X=p.data)==null?void 0:X.settings.spaces.find(s=>s.visibility==="shared"))??null,we=!!y&&!!m&&(m==null?void 0:m.id)!==(y==null?void 0:y.id)&&(m==null?void 0:m.visibility)==="personal",q=(r==null?void 0:r.slug)!=="index",j=n&&h.error instanceof Oe&&h.error.status===404?n.trim():null;c.useEffect(()=>{if(!t||!j)return;const s=new URLSearchParams;s.set("spaceId",t),s.set("title",j);const o=as(j);o&&s.set("slug",o),i(`/wiki/new?${s.toString()}`,{replace:!0})},[t,j,i]);const A=c.useMemo(()=>((r==null?void 0:r.links)??[]).map(s=>({id:`${s.entityType}:${s.entityId}`,href:Be(s.entityType,s.entityId),label:`${s.entityType} · ${s.entityId}`})),[r==null?void 0:r.links]),S=Fe({mutationFn:async s=>Me(s),onSuccess:async()=>{await Promise.all([u.invalidateQueries({queryKey:["forge-wiki-tree"]}),u.invalidateQueries({queryKey:["forge-wiki-home"]}),u.invalidateQueries({queryKey:["forge-wiki-page-by-slug"]}),u.invalidateQueries({queryKey:["forge-wiki-modal-search"]})]),i(`/wiki${t?`?spaceId=${encodeURIComponent(t)}`:""}`)}}),D=(s,o=!1)=>{const g=new URLSearchParams(d);s(g),f(g,{replace:o})},_=s=>{D(o=>{o.set("ingest","1"),s?o.set("ingestJobId",s):o.delete("ingestJobId"),t&&o.set("spaceId",t)})},Ne=()=>{D(s=>{s.delete("ingest"),s.delete("ingestJobId")})},Ie=s=>{D(o=>{o.set("ingest","1"),s?o.set("ingestJobId",s):o.delete("ingestJobId"),t&&o.set("spaceId",t)})},Ce=()=>{!r||!q||S.isPending||!window.confirm(`Delete KarpaWiki page "${r.title}"? You can restore it later from the bin.`)||S.mutateAsync(r.id)};return c.useEffect(()=>{if(!U)return;const s=g=>{var ae;(ae=Q.current)!=null&&ae.contains(g.target)||E(!1)},o=g=>{g.key==="Escape"&&E(!1)};return document.addEventListener("pointerdown",s),document.addEventListener("keydown",o),()=>{document.removeEventListener("pointerdown",s),document.removeEventListener("keydown",o)}},[U]),!r&&(p.isLoading||z.isLoading||!n&&I.isLoading||n&&h.isLoading)?e.jsx(O,{eyebrow:"KarpaWiki",title:"Loading the article",description:"Preparing the current space, article, and KarpaWiki index."}):!r&&!j&&(p.isError||I.isError||h.isError||z.isError)?e.jsx(ne,{eyebrow:"KarpaWiki",error:p.error??I.error??h.error??z.error,onRetry:()=>{p.refetch(),I.refetch(),h.refetch(),z.refetch()}}):r?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"px-3 py-4 sm:px-5 lg:px-6",children:e.jsxs("div",{className:"mx-auto flex w-full max-w-[1680px] flex-col gap-4",children:[e.jsxs("section",{className:"wiki-frame px-3 py-3 sm:px-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(oe,{kind:"wiki_page",label:"KarpaWiki page",compact:!0,gradient:!1}),m?e.jsx(oe,{kind:"wiki_space",label:m.label,compact:!0,gradient:!1,wrap:!0,className:"max-w-[20rem]"}):null,e.jsx("span",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:rs(r.updatedAt)}),e.jsx(Je,{metrics:a.snapshot.metrics,className:"ml-auto"})]}),e.jsxs("div",{className:"mt-3 flex flex-col gap-2 lg:flex-row lg:items-center",children:[e.jsxs("button",{type:"button",className:"wiki-search-launch flex min-h-[2.9rem] w-full items-center gap-3 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 text-left text-[14px] text-[var(--ui-ink-soft)] transition hover:bg-[var(--ui-surface-2)] hover:text-[var(--ui-ink-strong)] lg:flex-1",onClick:()=>l(!0),children:[e.jsx(Pe,{className:"size-4 shrink-0 text-[var(--ui-ink-faint)]"}),e.jsx("span",{children:"Search KarpaWiki"})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 lg:shrink-0",children:[e.jsxs("button",{type:"button",className:"wiki-space-trigger inline-flex min-h-[2.9rem] items-center gap-2 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 text-[13px] font-medium text-[var(--ui-ink-medium)] transition hover:bg-[var(--ui-surface-2)] hover:text-[var(--ui-ink-strong)]",onClick:()=>N(!0),children:[e.jsx("span",{className:"text-[11px] uppercase tracking-[0.14em] text-[var(--ui-ink-faint)]",children:"Space"}),e.jsx("span",{className:"max-w-[16rem] truncate",children:(m==null?void 0:m.label)??"KarpaWiki space"}),e.jsx(B,{className:"size-3.5 text-[var(--ui-ink-faint)]"})]}),e.jsxs("div",{className:"relative",ref:Q,children:[e.jsxs(T,{variant:"secondary",size:"sm",className:"min-h-[2.9rem]",onClick:()=>E(s=>!s),children:[e.jsx(ie,{className:"size-3.5"}),"Ingest",e.jsx(B,{className:"size-3.5"})]}),U?e.jsxs("div",{className:"absolute right-0 top-[calc(100%+0.5rem)] z-20 grid min-w-[15rem] gap-2 rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-popover)] p-2 shadow-[var(--ui-shadow-floating)]",children:[e.jsxs("button",{type:"button",className:"flex items-start gap-3 rounded-[18px] px-3 py-3 text-left transition hover:bg-[var(--ui-surface-2)]",onClick:()=>{E(!1),_()},children:[e.jsx(ie,{className:"mt-0.5 size-4 shrink-0 text-[var(--primary)]"}),e.jsxs("span",{children:[e.jsx("span",{className:"block text-sm font-medium text-[var(--ui-ink-strong)]",children:"New ingest"}),e.jsx("span",{className:"mt-1 block text-xs leading-5 text-[var(--ui-ink-faint)]",children:"Start a fresh import from files, URLs, or pasted text."})]})]}),e.jsxs("button",{type:"button",className:"flex items-start gap-3 rounded-[18px] px-3 py-3 text-left transition hover:bg-[var(--ui-surface-2)]",onClick:()=>{E(!1),i(`/wiki/ingest-history${t?`?spaceId=${encodeURIComponent(t)}`:""}`)},children:[e.jsx(Re,{className:"mt-0.5 size-4 shrink-0 text-[var(--secondary)]"}),e.jsxs("span",{children:[e.jsx("span",{className:"block text-sm font-medium text-[var(--ui-ink-strong)]",children:"History"}),e.jsx("span",{className:"mt-1 block text-xs leading-5 text-[var(--ui-ink-faint)]",children:"Browse prior ingests, reopen reviews, and delete old ingest records."})]})]})]}):null]}),e.jsxs(T,{variant:"secondary",size:"sm",className:"min-h-[2.9rem]",onClick:()=>i(`/wiki/edit/${encodeURIComponent(r.id)}?spaceId=${encodeURIComponent(t)}`,{state:{initialPage:r}}),children:[e.jsx(ze,{className:"size-3.5"}),"Edit"]}),e.jsx(es,{entityType:"note",entityId:r.id,label:"Open in graph",size:"sm"}),e.jsxs(T,{variant:"secondary",size:"sm",className:w("min-h-[2.9rem] border border-rose-400/18 bg-rose-500/10 text-rose-100 hover:bg-rose-500/18",!q&&"opacity-60"),onClick:Ce,pending:S.isPending,pendingLabel:"Deleting",disabled:!q,title:q?"Delete this KarpaWiki page":"The KarpaWiki home page cannot be deleted",children:[e.jsx(Ke,{className:"size-3.5"}),"Delete"]}),e.jsxs(T,{size:"sm",className:"min-h-[2.9rem]",onClick:()=>i(`/wiki/new?spaceId=${encodeURIComponent(t)}`),children:[e.jsx($e,{className:"size-3.5"}),"New page"]})]})]}),we&&y?e.jsxs("div",{className:"mt-3 flex flex-col gap-3 rounded-[22px] border border-amber-300/20 bg-amber-300/[0.08] px-4 py-3 text-[13px] leading-6 text-amber-50 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("span",{children:["You are viewing the personal starter wiki. The recovered people, story, and conversation pages are in"," ",e.jsx("strong",{children:y.label}),"."]}),e.jsx("button",{type:"button",className:"inline-flex min-h-10 shrink-0 items-center justify-center rounded-2xl bg-amber-200 px-4 text-[12px] font-semibold uppercase tracking-[0.14em] text-stone-950 transition hover:bg-amber-100",onClick:()=>{i({pathname:"/wiki",search:`?spaceId=${encodeURIComponent(y.id)}`})},children:"Open shared memory"})]}):null]}),e.jsxs("section",{className:"grid gap-4 lg:grid-cols-[15rem_minmax(0,1fr)] xl:grid-cols-[16rem_minmax(0,1fr)]",children:[e.jsxs("aside",{className:"wiki-frame h-fit px-2 py-3 sm:px-3 lg:sticky lg:top-[5.75rem]",children:[e.jsx("div",{className:"px-2 pb-2 text-[11px] font-semibold uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Index"}),e.jsx(he,{nodes:((Z=z.data)==null?void 0:Z.tree)??[],activeSlug:r.slug,spaceId:t})]}),e.jsxs("article",{"aria-busy":L,className:w("wiki-frame relative overflow-hidden px-4 py-5 transition-[opacity,transform] duration-200 sm:px-6 sm:py-6",L&&"opacity-[0.985]"),children:[L?e.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 h-px bg-[color-mix(in_srgb,var(--primary)_70%,transparent)] opacity-90"}):null,e.jsxs("div",{className:"wiki-reading-copy wiki-reading-flow mx-auto max-w-[76rem]",children:[S.isError?e.jsx("div",{className:"mb-4 rounded-[18px] border border-rose-400/20 bg-rose-500/10 px-4 py-3 text-sm text-rose-100",children:S.error instanceof Error?S.error.message:"Forge could not delete this KarpaWiki page."}):null,e.jsx(ss,{markdown:r.contentMarkdown,spaceId:t}),r.summary.trim()?e.jsx("p",{className:"mt-5 border-t border-[var(--ui-border-subtle)] pt-4 text-[13px] leading-6 text-[var(--ui-ink-soft)]",children:r.summary}):null,A.length>0?e.jsxs("section",{className:"mt-8 border-t border-[var(--ui-border-subtle)] pt-4",children:[e.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Forge links"}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:A.map(s=>e.jsx("a",{href:s.href?Ae(s.href):void 0,className:"rounded-full bg-[var(--ui-surface-2)] px-3 py-1.5 text-[12px] text-[var(--ui-ink-medium)] transition hover:bg-[var(--ui-surface-3)] hover:text-[var(--ui-ink-strong)]",children:s.label},s.id))})]}):null,k!=null&&k.backlinkSourceNotes.length?e.jsxs("section",{className:"mt-8 border-t border-[var(--ui-border-subtle)] pt-4",children:[e.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Linked here"}),e.jsx("div",{className:"mt-3 grid gap-2 sm:grid-cols-2",children:k.backlinkSourceNotes.map(s=>e.jsxs(le,{to:{pathname:s.slug==="index"?"/wiki":`/wiki/page/${encodeURIComponent(s.slug)}`,search:`?spaceId=${encodeURIComponent(s.spaceId)}`},className:"rounded-xl border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-3 transition hover:bg-[var(--ui-surface-2)]",children:[e.jsx("div",{className:"text-[13px] font-semibold text-[var(--ui-ink-strong)]",children:s.title}),s.summary?e.jsx("div",{className:"mt-1 text-[12px] leading-5 text-[var(--ui-ink-soft)]",children:s.summary}):null]},s.id))})]}):null]})]})]})]})}),e.jsx(de,{open:x,onOpenChange:l,children:e.jsxs(ue,{children:[e.jsx(pe,{className:"fixed inset-0 z-50 surface-overlay backdrop-blur-sm"}),e.jsxs(me,{className:"fixed left-1/2 top-[8vh] z-50 w-[min(54rem,calc(100vw-1.5rem))] -translate-x-1/2 rounded-[28px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-popover)] p-4 shadow-[var(--ui-shadow-floating)] sm:p-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsx("div",{children:e.jsx(xe,{className:"font-display text-[1.35rem] tracking-[-0.04em] text-[var(--ui-ink-strong)]",children:"Search the wiki"})}),e.jsx(ge,{asChild:!0,children:e.jsx("button",{type:"button",className:"rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-2 text-[var(--ui-ink-soft)] transition hover:bg-[var(--ui-surface-2)] hover:text-[var(--ui-ink-strong)]","aria-label":"Close search",children:e.jsx(ce,{className:"size-4"})})})]}),e.jsxs("div",{className:"mt-4 grid gap-3",children:[e.jsx(_e,{autoFocus:!0,value:W,onChange:s=>ve(s.target.value),placeholder:"Search KarpaWiki pages",className:"h-11 rounded-2xl border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[14px] text-[var(--ui-ink-strong)] placeholder:text-[var(--ui-ink-faint)]"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[["text","hybrid","semantic","entity"].map(s=>e.jsx("button",{type:"button",className:w("rounded-full px-3 py-1.5 text-[12px] font-medium uppercase tracking-[0.14em] transition",v===s?"bg-[var(--ui-surface-3)] text-[var(--ui-ink-strong)]":"bg-[var(--ui-surface-1)] text-[var(--ui-ink-soft)] hover:bg-[var(--ui-surface-2)] hover:text-[var(--ui-ink-strong)]"),onClick:()=>be(s),children:s},s)),(v==="semantic"||v==="hybrid")&&R.length>0?e.jsx("select",{className:"ml-auto rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-3 py-1.5 text-[12px] text-[var(--ui-ink-strong)]",value:P,onChange:s=>M(s.target.value),children:R.map(s=>e.jsx("option",{value:s.id,children:s.label},s.id))}):null]})]}),e.jsx("div",{className:"mt-4 max-h-[60vh] overflow-y-auto",children:W.trim()?C.isLoading?e.jsx(O,{eyebrow:"KarpaWiki search",title:"Searching",description:"Ranking matching pages for this query."}):C.isError?e.jsx(ne,{eyebrow:"KarpaWiki search",error:C.error,onRetry:()=>void C.refetch()}):(ee=C.data)!=null&&ee.results.length?e.jsx("div",{className:"grid gap-2",children:C.data.results.map(s=>e.jsx("button",{type:"button",className:"rounded-2xl border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-3 text-left transition hover:bg-[var(--ui-surface-2)]",onClick:()=>{l(!1),i({pathname:s.page.slug==="index"?"/wiki":`/wiki/page/${encodeURIComponent(s.page.slug)}`,search:`?spaceId=${encodeURIComponent(s.page.spaceId)}`})},children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[14px] font-semibold text-[var(--ui-ink-strong)]",children:s.page.title}),s.page.summary?e.jsx("div",{className:"mt-1 text-[12px] leading-5 text-[var(--ui-ink-soft)]",children:s.page.summary}):null]}),e.jsx(He,{size:"sm",tone:"meta",children:s.score.toFixed(2)})]})},s.page.id))}):e.jsx("div",{className:"rounded-2xl border border-dashed border-[var(--ui-border-subtle)] px-4 py-10 text-center text-[13px] leading-6 text-[var(--ui-ink-faint)]",children:"No pages matched this search."}):e.jsx("div",{className:"rounded-2xl border border-dashed border-[var(--ui-border-subtle)] px-4 py-10 text-center text-[13px] leading-6 text-[var(--ui-ink-faint)]",children:"Start typing to search the current KarpaWiki space."})})]})]})}),e.jsx(ns,{open:b,onOpenChange:N,spaces:((se=p.data)==null?void 0:se.settings.spaces)??[],activeSpaceId:t,onSelect:s=>{i({pathname:"/wiki",search:`?spaceId=${encodeURIComponent(s)}`},{replace:!0})}}),e.jsx(ts,{open:ke,onOpenChange:s=>{if(s){_(J);return}Ne()},spaces:((te=p.data)==null?void 0:te.settings.spaces)??[],llmProfiles:((re=p.data)==null?void 0:re.settings.llmProfiles)??[],initialSpaceId:t,selectedJobId:J,onJobSelected:Ie,linkedEntityHints:r.links.map(s=>({entityType:s.entityType,entityId:s.entityId,anchorKey:null}))??[]})]}):j?e.jsx(O,{eyebrow:"KarpaWiki",title:"Opening a new page",description:`Creating a draft for ${j}.`}):e.jsx(Qe,{eyebrow:"KarpaWiki",title:"Article not found",description:"This page does not exist in the selected space."})}export{bs as WikiPage};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{r as x,j as e,dJ as At,dK as Kt,dG as Mt,dL as zt,dM as Wt,dN as $t,aG as Ht,dO as Lt,cr as xa,c7 as Ke,bX as Bt,br as Me,b2 as ga,aC as ba,bk as va,ca as fa,cm as ya,dP as ja,cc as ka,b5 as Na}from"./vendor-Dnkkx2co.js";import{O as wa}from"./open-in-graph-button-C263zl5l.js";import{P as Ca}from"./page-hero-5RTqAI88.js";import{fu as Sa,a9 as Ut,fv as Ct,fw as _a,Z as O,aq as D,B as R,F as S,aV as Ia,fx as Ta,fy as Fa,b as St,fs as Ra,Q as Ea,fz as Oa,fA as Pa,fB as Aa,fC as Ka,fD as Ma,fE as za,fF as Wa,L as $a,a as Ha,E as La}from"./index-By3tQxiE.js";import{H as Ba,P as _t,i as Ua,B as qa,a as Da,b as Va,c as Ga}from"./graph-DDUZNRsO.js";import{R as Qa,P as Ja,O as Ya,C as Xa,T as Za,D as es,a as ts}from"./ui-C1iwpj2-.js";import{F as as}from"./faceted-token-search-BgxYH_gW.js";import"./state-vCcAT5Hq.js";import"./motion-Lt5B1XuE.js";import"./forms-hB0SqEh-.js";import"./board-dIX6etHh.js";const ze=[...Sa];function fe(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 qt(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 ss(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 Dt(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 Vt(t,i){var d,u,p,o;const s=(l,h)=>l.map(m=>{const v=Ct(m),j=v.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":v.key:v.key;return Ct({...v,key:j,kind:j===v.key?v.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=Dt(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 rs(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=Vt(u,i),o={...u,data:{...u.data,inputs:p.inputs,outputs:p.outputs,outputKey:rs(u,p.outputs)}};return We(o,i)}),n=new Map(s.map(u=>[u.id,u])),d=t.graph.edges.map(u=>{var m,v,j,f;const p=n.get(u.source),o=n.get(u.target),l=It(u.sourceHandle,(p==null?void 0:p.data.outputs)??[],(v=(m=p==null?void 0:p.data.outputs)==null?void 0:m[0])==null?void 0:v.key),h=It(u.targetHandle,(o==null?void 0:o.data.inputs)??[],(f=(j=o==null?void 0:o.data.inputs)==null?void 0:j[0])==null?void 0:f.key);return Gt({...u,sourceHandle:l,targetHandle:h})});return{nodes:s,edges:d}}function We(t,i){const s=Vt(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 Gt(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 Qt(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 ns(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=Dt(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 is(t){return[t.kind,t.modelName,t.itemKind?`item:${t.itemKind}`:null].filter(Boolean).join(" · ")}function ls(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 os(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 ds(){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 cs(t){const i=t instanceof Ut||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(`
|
|
1
|
+
import{r as x,j as e,dJ as At,dK as Kt,dG as Mt,dL as zt,dM as Wt,dN as $t,aG as Ht,dO as Lt,cr as xa,c7 as Ke,bX as Bt,br as Me,b2 as ga,aC as ba,bk as va,ca as fa,cm as ya,dP as ja,cc as ka,b5 as Na}from"./vendor-Dnkkx2co.js";import{O as wa}from"./open-in-graph-button-CMjJZX7G.js";import{P as Ca}from"./page-hero-CONuJu5J.js";import{fu as Sa,a9 as Ut,fv as Ct,fw as _a,Z as O,aq as D,B as R,F as S,aV as Ia,fx as Ta,fy as Fa,b as St,fs as Ra,Q as Ea,fz as Oa,fA as Pa,fB as Aa,fC as Ka,fD as Ma,fE as za,fF as Wa,L as $a,a as Ha,E as La}from"./index-QJkjKYzZ.js";import{H as Ba,P as _t,i as Ua,B as qa,a as Da,b as Va,c as Ga}from"./graph-DDUZNRsO.js";import{R as Qa,P as Ja,O as Ya,C as Xa,T as Za,D as es,a as ts}from"./ui-C1iwpj2-.js";import{F as as}from"./faceted-token-search-CZmtyJTT.js";import"./state-vCcAT5Hq.js";import"./motion-Lt5B1XuE.js";import"./forms-hB0SqEh-.js";import"./board-dIX6etHh.js";const ze=[...Sa];function fe(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 qt(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 ss(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 Dt(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 Vt(t,i){var d,u,p,o;const s=(l,h)=>l.map(m=>{const v=Ct(m),j=v.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":v.key:v.key;return Ct({...v,key:j,kind:j===v.key?v.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=Dt(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 rs(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=Vt(u,i),o={...u,data:{...u.data,inputs:p.inputs,outputs:p.outputs,outputKey:rs(u,p.outputs)}};return We(o,i)}),n=new Map(s.map(u=>[u.id,u])),d=t.graph.edges.map(u=>{var m,v,j,f;const p=n.get(u.source),o=n.get(u.target),l=It(u.sourceHandle,(p==null?void 0:p.data.outputs)??[],(v=(m=p==null?void 0:p.data.outputs)==null?void 0:m[0])==null?void 0:v.key),h=It(u.targetHandle,(o==null?void 0:o.data.inputs)??[],(f=(j=o==null?void 0:o.data.inputs)==null?void 0:j[0])==null?void 0:f.key);return Gt({...u,sourceHandle:l,targetHandle:h})});return{nodes:s,edges:d}}function We(t,i){const s=Vt(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 Gt(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 Qt(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 ns(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=Dt(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 is(t){return[t.kind,t.modelName,t.itemKind?`item:${t.itemKind}`:null].filter(Boolean).join(" · ")}function ls(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 os(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 ds(){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 cs(t){const i=t instanceof Ut||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
2
|
|
|
3
3
|
`):i}function us(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 ps(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 ms(t,i){return Jt(t,i)[0]??null}function Jt(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),v=(h==null?void 0:h.data.outputs)??[],j=(m==null?void 0:m.data.inputs)??[];h&&(l.sourceHandle&&!v.some(f=>f.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&&v.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(f=>f.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 v=n.get(m.source),j=(v==null?void 0:v.data.outputs)??[];return m.sourceHandle?j.filter(f=>f.key===m.sourceHandle).map(f=>f.key):j.map(f=>f.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(v=>v.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(Qt),edges:u.map(ns)}}}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)]",Yt={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 hs(t){switch(t){case"box":case"box_input":return{icon:e.jsx(xa,{className:"size-4"}),badge:"box"};case"chat":return{icon:e.jsx(Lt,{className:"size-4"}),badge:"chat"};case"functor":return{icon:e.jsx(Ht,{className:"size-4"}),badge:"functor"};case"output":return{icon:e.jsx($t,{className:"size-4"}),badge:"output"};case"value":return{icon:e.jsx(Wt,{className:"size-4"}),badge:"value"};case"merge":return{icon:e.jsx(zt,{className:"size-4"}),badge:"merge"};case"template":return{icon:e.jsx(Mt,{className:"size-4"}),badge:"template"};case"pick_key":return{icon:e.jsx(Kt,{className:"size-4"}),badge:"pick key"};default:return{icon:e.jsx(At,{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]",Yt[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(D,{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)]",Yt[n.kind]??"border-[var(--ui-border-subtle)] text-[var(--ui-ink-soft)]"),children:[e.jsx(Ba,{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:is(n)})]})]},`${t}-${n.key}`))]})}function xs(t){var h,m,v,j;const i=_a(t.data.boxId??null),[s,n]=x.useState(!1),[d,u]=x.useState(!1),p=hs(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 · ${((v=t.data.outputs)==null?void 0:v.length)??0} out`;if(i&&t.data.nodeType==="box"){const f=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 k,F;return(F=(k=t.data).onEditRequest)==null?void 0:F.call(k)}}),e.jsx(W,{label:l,onClick:()=>{var k,F;return(F=(k=t.data).onContractEditRequest)==null?void 0:F.call(k)}}),o>0?e.jsx(W,{label:`${o} parameter${o===1?"":"s"}`,onClick:()=>{var k,F;return(F=(k=t.data).onParameterEditRequest)==null?void 0:F.call(k)},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(f,{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(f=>!f)}),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(f=>!f)}),e.jsx(W,{label:"Edit",onClick:()=>{var f,k;return(k=(f=t.data).onEditRequest)==null?void 0:k.call(f)}}),e.jsx(W,{label:l,onClick:()=>{var f,k;return(k=(f=t.data).onContractEditRequest)==null?void 0:k.call(f)}}),o>0?e.jsx(W,{label:`${o} parameter${o===1?"":"s"}`,onClick:()=>{var f,k;return(k=(f=t.data).onParameterEditRequest)==null?void 0:k.call(f)},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(D,{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:f,kind:k,required:F})=>({key:f,kind:k,required:!!F})),outputs:(t.data.outputs??[]).map(({key:f,kind:k,required:F})=>({key:f,kind:k,required:!!F})),tools:t.data.enabledToolKeys??[]},null,2)})]}):null]})}const Xt="grid gap-3 rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",Zt="grid gap-3 rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",gs="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)]",ea="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 bs(){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:Xt,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(D,{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??[],os(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:Zt,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??[],bs()]}: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:gs,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((v,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:ea,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 vs({inputs:t,nodes:i,onChange:s}){return e.jsxs("div",{className:Xt,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(D,{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??[],ds()]),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:Zt,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:fe(n.defaultValue),onChange:o=>p({defaultValue:qt(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:ea,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(D,{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(v=>v.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:v=>p({bindings:(n.bindings??[]).map((j,f)=>f===l?{...j,nodeId:v.target.value,targetKey:""}:j)}),className:y,children:[e.jsx("option",{value:"",children:"Select node"}),u.map(v=>e.jsx("option",{value:v.id,children:v.data.label},v.id))]}),e.jsxs("select",{value:o.targetKind,onChange:v=>p({bindings:(n.bindings??[]).map((j,f)=>f===l?{...j,targetKind:v.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:v=>p({bindings:(n.bindings??[]).map((j,f)=>f===l?{...j,targetKey:v.target.value}:j)}),className:y,children:[e.jsx("option",{value:"",children:"Select target"}),m.map(v=>e.jsx("option",{value:v.key,children:v.label},v.key))]}),e.jsx(R,{type:"button",variant:"ghost",size:"sm",onClick:()=>p({bindings:(n.bindings??[]).filter((v,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}`)})})]})}const fs="min-w-0 rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",Et="min-w-0 rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-left text-[var(--ui-ink-medium)] transition hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-hover)]",Ot="rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-2.5 py-1 text-[11px] text-[var(--ui-ink-soft)]",ys="text-[10px] uppercase tracking-[0.14em] text-[var(--ui-ink-faint)]";function ie({open:t,onOpenChange:i,title:s,description:n,children:d}){return e.jsx(Qa,{open:t,onOpenChange:i,children:e.jsxs(Ja,{children:[e.jsx(Ya,{className:"fixed inset-0 z-50 bg-[var(--ui-overlay-backdrop)] backdrop-blur-sm"}),e.jsxs(Xa,{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(Za,{className:"font-display text-[1.28rem] tracking-[-0.04em] text-[var(--ui-ink-strong)]",children:s}),n?e.jsx(es,{className:"mt-1 text-sm leading-6 text-[var(--ui-ink-soft)]",children:n}):null]}),e.jsx(ts,{asChild:!0,children:e.jsx(Ia,{"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 js=[{type:"user_input",label:"User input",icon:e.jsx(At,{className:"size-4"})},{type:"value",label:"Value",icon:e.jsx(Wt,{className:"size-4"})},{type:"functor",label:"Functor",icon:e.jsx(Ht,{className:"size-4"})},{type:"chat",label:"Chat",icon:e.jsx(ga,{className:"size-4"})},{type:"merge",label:"Merge",icon:e.jsx(zt,{className:"size-4"})},{type:"template",label:"Template",icon:e.jsx(Mt,{className:"size-4"})},{type:"pick_key",label:"Pick key",icon:e.jsx(Kt,{className:"size-4"})},{type:"output",label:"Output",icon:e.jsx($t,{className:"size-4"})}];function ks({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:js.map(m=>e.jsxs("button",{type:"button",className:`${Et} flex items-center gap-3 px-4 py-3`,onClick:()=>l(m.type),children:[m.icon,e.jsx("span",{children:m.label})]},m.type))}),e.jsx(as,{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:`${Et} px-4 py-3`,onClick:()=>h(m),children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsx("div",{className:"min-w-0 break-words text-sm font-medium text-[var(--ui-ink-strong)]",children:m.title}),e.jsxs("div",{className:`flex shrink-0 flex-wrap gap-2 ${ys}`,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-[var(--ui-ink-soft)]",children:m.description}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx("div",{className:Ot,children:m.category}),m.routePath?e.jsx("div",{className:Ot,children:m.routePath}):null]})]},m.id))})]})})}function Ns({open:t,onOpenChange:i,title:s,onTitleChange:n,description:d,onDescriptionChange:u,kind:p,onKindChange:o,publicInputs:l,onPublicInputsChange:h,nodes:m,flowId:v,onDelete:j,onSave:f}){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:k=>n(k.target.value),placeholder:"Flow title",className:y}),e.jsx("textarea",{rows:4,value:d,onChange:k=>u(k.target.value),placeholder:"Flow description",className:y}),e.jsxs("select",{value:p,onChange:k=>o(k.target.value),className:y,children:[e.jsx("option",{value:"functor",children:"Functor flow"}),e.jsx("option",{value:"chat",children:"Chat flow"})]}),e.jsx(vs,{inputs:l,nodes:m,onChange:h}),e.jsx("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-code-bg)] px-4 py-3 font-mono text-sm text-[var(--ui-code-text)] [overflow-wrap:anywhere]",children:v}),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:()=>{f().then(()=>i(!1))},children:[e.jsx(Bt,{className:"size-4"}),"Save settings"]})]})]})})}function ws(t){if(t.trim())try{return JSON.parse(t)}catch{return t}}function Cs({open:t,onOpenChange:i,runError:s,graphIssues:n,hasAiNodes:d,modelConnectionCount:u,publicInputs:p,runInputs:o,onRunInputChange:l,shouldShowLegacyUserInput:h,userInput:m,onUserInputChange:v,debugEnabled:j,onDebugEnabledChange:f,onRun:k,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 p-4 ${fs}`,children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-[var(--ui-ink-strong)]",children:["Flow inputs",e.jsx(D,{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-[var(--ui-ink-medium)]",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:fe(o[g.key]),onChange:_=>l(g.key,ws(_.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=>v(g.target.value),placeholder:"User input",className:y}):null,e.jsxs("label",{className:"flex items-center gap-2 text-sm text-[var(--ui-ink-soft)]",children:[e.jsx("input",{type:"checkbox",checked:j,onChange:g=>f(g.target.checked)}),"Return debug trace"]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(R,{type:"button",variant:"primary",onClick:k,children:[e.jsx(Me,{className:"size-4"}),"Run"]}),e.jsxs(R,{type:"button",variant:"secondary",onClick:F,children:[e.jsx(Lt,{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-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 text-[12px] text-[var(--ui-ink-faint)]",children:[e.jsx("span",{children:g.mode}),e.jsx("span",{children:new Date(g.createdAt).toLocaleString()})]}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-medium)]",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 Ss(t,i){return je(t)>=je(i)?t:i}function Pt(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 _s(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:Pt(n.key,[n.description]),accessMode:n.accessMode,argsSchema:n.argsSchema,sources:[s.title],sourceSurfaceIds:s.surfaceId?[s.surfaceId]:[]});continue}d.accessMode=Ss(d.accessMode,n.accessMode),d.label=d.label.length>=n.label.length?d.label:n.label,d.description=Pt(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 Is={workbench:xs},ve="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 Ts(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 Fs({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,vt,ft,yt,jt,kt,Nt,wt;const[l,h]=x.useState(t.title),[m,v]=x.useState(t.description),[j,f]=x.useState(t.kind),[k,F]=x.useState(t.publicInputs??[]),[I,g]=x.useState(()=>Ae(t,i).nodes),[_,J]=x.useState(()=>Ae(t,i).edges),[le,ke]=x.useState(null),[ta,oe]=x.useState(!1),[Be,H]=x.useState(!1),[de,ce]=x.useState("overview"),[aa,Ne]=x.useState(void 0),[sa,ue]=x.useState(!1),[ra,Ue]=x.useState(!1),[we,Ce]=x.useState(!1),[Se,na]=x.useState(""),[_e,ia]=x.useState([]),[Ie,la]=x.useState(""),[qe,De]=x.useState({}),[Te,oa]=x.useState(!0),[da,L]=x.useState(null),[Fe,B]=x.useState("idle"),[ca,pe]=x.useState(null),[V,Ve]=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(Gt)})),[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),v(t.description),f(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(()=>{De(Object.fromEntries((t.publicInputs??[]).filter(a=>a.defaultValue!==void 0).map(a=>[a.key,a.defaultValue])))},[t.publicInputs]),x.useEffect(()=>{var a;Ve(((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(Qt(r),i)))},[i]);const ua=x.useMemo(()=>Array.from(new Set(i.map(r=>r.category))).map(r=>({id:`category:${r}`,label:r,description:"Workbench box category"})),[i]),pa=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),w=_e.every(C=>C.startsWith("category:")?r.category===C.replace("category:",""):!0);return c&&w})},[_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===V)??Y??null,Q=Ta({flowId:t.id,runId:V??""},{skip:!V||!we}),A=((rt=Q.data)==null?void 0:rt.nodeResults.find(a=>a.nodeId===me))??null,K=Fa({flowId:t.id,runId:V??"",nodeId:me??""},{skip:!V||!me||!we}),Ee=x.useMemo(()=>Jt(I,_),[I,_]),Je=x.useMemo(()=>I.some(a=>ne(a.data.nodeType)),[I]),Oe=x.useMemo(()=>I.some(a=>a.data.nodeType==="user_input")||(k??[]).length===0,[I,k]);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(w=>w.id===a.source),c=(r==null?void 0:r.data.outputs)??[];return a.sourceHandle?c.filter(w=>w.key===a.sourceHandle):c}):[],[_,I,b]),X=x.useMemo(()=>_s(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:k,nodes:I,edges:_}),[m,_,j,I,k,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 ma=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,w,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:N=>{var M,z;const T=s.find(q=>q.id===N.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(N=>e.jsx("option",{value:N.id,children:N.label},N.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:((w=a.modelConfig)==null?void 0:w.thinking)??"",onChange:N=>{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:N.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:N=>{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:N.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 w=(a.enabledToolKeys??[]).includes(c.key);return e.jsxs("label",{className:"flex items-start gap-3 rounded-[16px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-3 py-2 text-left",children:[e.jsx("input",{type:"checkbox",checked:w,onChange:C=>{const N=new Set(a.enabledToolKeys??[]);C.target.checked?N.add(c.key):N.delete(c.key),r({enabledToolKeys:[...N]})}}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-[var(--ui-ink-strong)]",children:[e.jsx("span",{children:c.label}),e.jsx("span",{className:"rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-2 py-0.5 text-[10px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:c.accessMode.replace("_"," ")})]}),e.jsx("div",{className:"text-[12px] leading-5 text-[var(--ui-ink-soft)]",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 border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-2 py-1 text-[10px] text-[var(--ui-ink-faint)]",children:C},`${c.key}-${C}`))}):null,e.jsx("div",{className:"mt-1 font-mono text-[10px] text-[var(--ui-ink-faint)]",children:c.key}),c.argsSchema?e.jsxs("details",{className:"mt-2 rounded-[14px] border border-[var(--ui-border-subtle)] bg-[var(--ui-code-bg)] px-3 py-2",children:[e.jsx("summary",{className:"cursor-pointer text-[11px] text-[var(--ui-ink-soft)]",children:"Preview tool arguments"}),e.jsx("pre",{className:"mt-2 overflow-auto whitespace-pre-wrap text-[10px] leading-5 text-[var(--ui-ink-faint)]",children:JSON.stringify(c.argsSchema,null,2)})]}):null]})]},c.key)}):e.jsx("div",{className:"text-sm text-[var(--ui-ink-faint)]",children:"No registered Forge tools are available yet."})})}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsx(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-[var(--ui-border-subtle)] bg-[var(--ui-code-bg)] px-4 py-3",children:[e.jsx("summary",{className:"cursor-pointer text-sm text-[var(--ui-ink-medium)]",children: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-[var(--ui-ink-soft)]",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-[var(--ui-border-subtle)] bg-[var(--ui-code-bg)] px-4 py-3",children:[e.jsxs("summary",{className:"cursor-pointer text-sm text-[var(--ui-ink-medium)]",children:[(a.outputs??[]).length," published output",(a.outputs??[]).length===1?"":"s"]}),e.jsx("pre",{className:"mt-3 overflow-auto whitespace-pre-wrap text-[11px] leading-5 text-[var(--ui-ink-soft)]",children:JSON.stringify(us(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:ps(["answer",...c.target.value.split(",")])}),placeholder:"summary, plan, next_steps",className:y})}),e.jsxs("div",{className:"rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Danger zone"}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Remove this node from the graph if you no longer need it."}),e.jsxs(R,{type:"button",variant:"secondary",className:"mt-4",onClick:()=>{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(w=>{const C=w instanceof Ut||w instanceof Error?w.message:String(w);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")=>{ke(a),ce(r),Ne(r==="contracts"?"contracts":"overview"),H(!0)},[]),ha=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)),ke(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=ms(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
4
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{b5 as v,c2 as j,r as o,j as t}from"./vendor-Dnkkx2co.js";import{j as S,i as N,k as F}from"./state-vCcAT5Hq.js";import{F as C}from"./faceted-token-search-
|
|
1
|
+
import{b5 as v,c2 as j,r as o,j as t}from"./vendor-Dnkkx2co.js";import{j as S,i as N,k as F}from"./state-vCcAT5Hq.js";import{F as C}from"./faceted-token-search-CZmtyJTT.js";import{P as I}from"./page-hero-CONuJu5J.js";import{fr as Q,B as m,b as W,fs as K,ft as $}from"./index-QJkjKYzZ.js";import"./motion-Lt5B1XuE.js";import"./ui-C1iwpj2-.js";import"./forms-hB0SqEh-.js";import"./board-dIX6etHh.js";import"./graph-DDUZNRsO.js";function R(){var h;const l=v(),p=S(),[f]=j(),g=f.get("surface"),[i,b]=o.useState(""),[c,w]=o.useState([]),x=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})=>{p.invalidateQueries({queryKey:["forge-workbench-flows"]}),l(`/workbench/${e.id}`)}}),a=((h=x.data)==null?void 0:h.flows)??[],y=o.useMemo(()=>{const e=[{id:"kind:functor",label:"Functor",description:"Single transformation flows"},{id:"kind:chat",label:"Chat",description:"Conversational flows with user input"}],r=Array.from(new Set(a.map(s=>s.homeSurfaceId).filter(s=>!!s))).map(s=>({id:`surface:${s}`,label:s,description:"Home surface"}));return[...e,...r]},[a]),u=o.useMemo(()=>{const e=i.trim().toLowerCase();return a.filter(r=>{const s=e.length===0||[r.title,r.description,r.kind,r.homeSurfaceId??"",...r.graph.nodes.map(n=>n.data.label)].join(" ").toLowerCase().includes(e),k=c.every(n=>n.startsWith("kind:")?r.kind===n.replace("kind:",""):n.startsWith("surface:")?r.homeSurfaceId===n.replace("surface:",""):!0);return s&&k})},[a,i,c]);return t.jsxs("div",{className:"grid gap-5",children:[t.jsx(I,{entityKind:"workbench",title:"Workbench",titleText:"Workbench",description:"Search and launch reusable Forge flows, then open a flow to edit its graph, tools, prompts, and outputs.",badge:`${a.length} flows`}),t.jsxs("div",{className:"flex flex-wrap gap-2",children:[t.jsx(m,{type:"button",variant:"primary",onClick:()=>void d.mutateAsync("functor"),children:"New flow"}),t.jsx(m,{type:"button",variant:"secondary",onClick:()=>void d.mutateAsync("chat"),children:"New chat flow"})]}),t.jsx(C,{title:"Flow search",description:"Filter by flow kind or surface, then open a flow to edit or run it.",query:i,onQueryChange:b,options:y,selectedOptionIds:c,onSelectedOptionIdsChange:w,resultSummary:`${u.length} of ${a.length} flows`,placeholder:"Search flow title, description, nodes, or home surface"}),t.jsx("div",{className:"grid gap-3 lg:grid-cols-2",children:u.map(e=>t.jsxs("button",{type:"button",className:"min-w-0 rounded-[26px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-5 text-left transition hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-hover)]",onClick:()=>l(`/workbench/${e.id}`),children:[t.jsxs("div",{className:"flex items-start justify-between gap-4",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"truncate text-lg font-semibold text-[var(--ui-ink-strong)]",children:e.title}),t.jsx("div",{className:"mt-1 line-clamp-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:e.description||"No description yet."})]}),t.jsx(W,{kind:K(e.kind),label:e.kind==="chat"?"Chat flow":"Functor flow",compact:!0,gradient:!1})]}),t.jsxs("div",{className:"mt-4 flex min-w-0 flex-wrap gap-2 text-[12px] text-[var(--ui-ink-faint)]",children:[t.jsxs("span",{className:"min-w-0 break-words",children:[e.graph.nodes.length," nodes"]}),t.jsxs("span",{className:"min-w-0 break-words",children:[e.graph.edges.length," edges"]}),e.homeSurfaceId?t.jsx("span",{className:"min-w-0 break-words",children:e.homeSurfaceId}):null]})]},e.id))})]})}export{R as WorkbenchPage};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/maps-C-yOWiDN.js","assets/vendor-Dnkkx2co.js","assets/vendor-CRS-psbw.css","assets/maps-B-YMMjus.css"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{eH as D,S as H,E as B,c as j,C as c,T as E,I as P,B as I,eM as K,eN as W}from"./index-By3tQxiE.js";import{cc as Q,r as h,j as e,aC as O,bk as q,bG as Z,bL as G,dw as X,bX as Y}from"./vendor-Dnkkx2co.js";import{j as U,i as V,k as J}from"./state-vCcAT5Hq.js";import"./maps-C-yOWiDN.js";import{P as ee}from"./page-hero-5RTqAI88.js";import{R as C,A as te,C as ae,X as T,Y as _,T as z,a as se,e as ie,B as re}from"./charts-DFnEuIMB.js";import"./motion-Lt5B1XuE.js";import"./ui-C1iwpj2-.js";import"./forms-hB0SqEh-.js";import"./board-dIX6etHh.js";import"./graph-DDUZNRsO.js";const A={below_z1:"#94a3b8",zone_1:"#38bdf8",zone_2:"#22c55e",zone_3:"#eab308",zone_4:"#f97316",zone_5:"#ef4444"};function k(t){return t?`${Math.round(t/60)}m`:"0m"}function F(t,s){const o=new Intl.DateTimeFormat(void 0,{weekday:"short",day:"numeric",month:"short"}),n=new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"});return`${o.format(new Date(t))} · ${n.format(new Date(t))} - ${n.format(new Date(s))}`}function $(t){const s=typeof t=="number"?Math.floor(t):Number.parseFloat(String(t??""));return Number.isFinite(s)?new Date(s).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):""}function ne(t,s){if(typeof t=="number"){const o=Number.isInteger(t)?String(t):t.toFixed(1);return s&&s!=="count"?`${o} ${s}`:o}return typeof t=="boolean"?t?"Yes":"No":t==null?"n/a":String(t)}function oe(t){return t.length===0?null:{minLat:Math.min(...t.map(s=>s.latitude)),maxLat:Math.max(...t.map(s=>s.latitude)),minLon:Math.min(...t.map(s=>s.longitude)),maxLon:Math.max(...t.map(s=>s.longitude))}}function le({points:t}){var g;const s=h.useRef(null),[o,n]=h.useState(!1),u=typeof window<"u"?((g=window.localStorage.getItem("forge.map.tile-url"))==null?void 0:g.trim())??"":"";h.useEffect(()=>{let x=!1,i=null;if(!u||!s.current||t.length<2){n(!1);return}return K(()=>import("./maps-C-yOWiDN.js").then(r=>r.m),__vite__mapDeps([0,1,2,3])).then(r=>{x||!s.current||(i=new r.Map({container:s.current,style:{version:8,sources:{tiles:{type:"raster",tiles:[u],tileSize:256}},layers:[{id:"tiles",type:"raster",source:"tiles"}]},center:[t[0].longitude,t[0].latitude],zoom:13,attributionControl:!1}),i.on("load",()=>{if(!i)return;const d=t.map(m=>[m.longitude,m.latitude]);i.addSource("route",{type:"geojson",data:{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:d}}}),i.addLayer({id:"route",type:"line",source:"route",paint:{"line-color":"#f97316","line-width":4}});const f=d.reduce((m,p)=>m.extend(p),new r.LngLatBounds(d[0],d[0]));i.fitBounds(f,{padding:44,maxZoom:15}),n(!0)}))}),()=>{x=!0,i==null||i.remove()}},[t,u]);const l=oe(t),v=h.useMemo(()=>{if(!l||t.length<2)return"";const x=720,i=280,r=Math.max(1e-6,l.maxLon-l.minLon),d=Math.max(1e-6,l.maxLat-l.minLat);return t.map(f=>{const m=(f.longitude-l.minLon)/r*x,p=i-(f.latitude-l.minLat)/d*i;return`${m.toFixed(1)},${p.toFixed(1)}`}).join(" ")},[l,t]);return e.jsxs("div",{className:"relative min-h-[280px] overflow-hidden rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)]",children:[e.jsx("div",{ref:s,className:"absolute inset-0"}),o?null:e.jsxs("svg",{viewBox:"0 0 720 280",className:"absolute inset-0 h-full w-full",children:[e.jsx("rect",{width:"720",height:"280",fill:"var(--ui-surface-1)"}),v?e.jsx("polyline",{points:v,fill:"none",stroke:"#f97316",strokeWidth:"5",strokeLinecap:"round",strokeLinejoin:"round"}):null]}),e.jsx("div",{className:"absolute left-3 top-3 max-w-[calc(100%-1.5rem)] rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--surface-glass)] px-3 py-2 text-xs text-[var(--ui-ink-medium)] backdrop-blur",children:u?"Local-first map tiles configured":"No tile source configured; showing private route shape only"})]})}function de({zones:t}){return e.jsx("div",{className:"grid gap-3",children:t.map(s=>e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 text-sm",children:[e.jsx("span",{className:"min-w-0 break-words text-[var(--ui-ink-medium)] [overflow-wrap:anywhere]",children:s.label}),e.jsxs("span",{className:"shrink-0 text-[var(--ui-ink-strong)]",children:[(s.percentage*100).toFixed(1),"% · ",k(s.seconds)]})]}),e.jsx("div",{className:"h-2 overflow-hidden rounded-full bg-[var(--ui-surface-2)]",children:e.jsx("div",{className:"h-full rounded-full",style:{width:`${Math.max(1,s.percentage*100)}%`,background:A[s.key]??"#f8fafc"}})})]},s.key))})}function ke(){var p,N,b,y,S,L,M,R;const{workoutId:t=""}=Q(),s=U(),o=V({queryKey:["workout-detail",t],queryFn:()=>W(t),enabled:t.length>0}),n=o.data,[u,l]=h.useState(""),[v,g]=h.useState("");h.useEffect(()=>{n!=null&&n.workout&&(l(n.workout.meaningText??""),g(n.workout.tags.join(", ")))},[n==null?void 0:n.workout]);const x=J({mutationFn:()=>D(t,{meaningText:u,tags:v.split(",").map(a=>a.trim()).filter(Boolean)}),onSuccess:async()=>{await s.invalidateQueries({queryKey:["workout-detail",t]}),await s.invalidateQueries({queryKey:["forge-fitness"]})}});if(o.isLoading)return e.jsx(H,{title:"Loading workout"});if(o.isError||!n)return e.jsx(B,{eyebrow:"Workout detail",error:o.error??new Error("Forge could not load this workout detail."),onRetry:()=>void o.refetch()});const{workout:i,analytics:r,evidence:d}=n,f=d.timeSeries.filter(a=>a.metricKey==="heart_rate").map((a,w)=>({time:Date.parse(a.startedAt)+w/1e3,bpm:a.value})),m=r.zoneDurations.map(a=>({zone:a.label,minutes:Math.round(a.seconds/60),fill:A[a.key]??"#f8fafc"}));return e.jsxs("div",{className:"grid gap-6",children:[e.jsxs(O,{to:"/sports",className:"inline-flex w-fit items-center gap-2 text-sm text-[var(--ui-ink-soft)] transition hover:text-[var(--ui-ink-strong)]",children:[e.jsx(q,{className:"size-4"}),"Back to sports"]}),e.jsx(ee,{eyebrow:"Workout evidence",title:i.workoutTypeLabel??i.workoutType,description:`${F(i.startedAt,i.endedAt)} · ${i.sourceDevice||"Apple Health"}`,actions:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(j,{children:k(i.durationSeconds)}),e.jsxs(j,{tone:"meta",children:[r.confidence," HR zones"]}),(p=r.routeSummary)!=null&&p.hasRoute?e.jsxs(j,{tone:"meta",children:[r.routeSummary.pointCount," route points"]}):null]})}),e.jsxs("section",{className:"grid gap-4 lg:grid-cols-4",children:[e.jsxs(c,{children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Avg HR"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:r.hrSummary.averageHr??i.averageHeartRate??"n/a"}),e.jsx("div",{className:"mt-1 text-sm text-[var(--ui-ink-faint)]",children:"bpm"})]}),e.jsxs(c,{children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Max HR"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:r.hrSummary.maxHr??i.maxHeartRate??"n/a"}),e.jsx("div",{className:"mt-1 text-sm text-[var(--ui-ink-faint)]",children:"bpm"})]}),e.jsxs(c,{children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Training load"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:r.load.trimp??"n/a"}),e.jsx("div",{className:"mt-1 text-sm text-[var(--ui-ink-faint)]",children:"Forge TRIMP"})]}),e.jsxs(c,{children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"HR coverage"}),e.jsxs("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:[Math.round((r.dataQuality.sampleCoverage??0)*100),"%"]}),e.jsxs("div",{className:"mt-1 text-sm text-[var(--ui-ink-faint)]",children:[r.dataQuality.heartRateSampleCount??0," samples"]})]})]}),e.jsxs("section",{className:"grid min-w-0 gap-4 xl:grid-cols-[minmax(0,1.25fr)_minmax(280px,0.75fr)]",children:[e.jsxs(c,{className:"min-h-[360px] min-w-0 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[var(--ui-ink-strong)]",children:[e.jsx(Z,{className:"size-4 text-[var(--primary)]"}),"Heart-rate timeline"]}),e.jsx("div",{className:"mt-4 h-[300px]",children:f.length>0?e.jsx(C,{width:"100%",height:"100%",children:e.jsxs(te,{data:f,children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"hrFill",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:"#ef4444",stopOpacity:.38}),e.jsx("stop",{offset:"100%",stopColor:"#ef4444",stopOpacity:.04})]})}),e.jsx(ae,{stroke:"var(--ui-border-subtle)",vertical:!1}),e.jsx(T,{dataKey:"time",interval:"preserveStartEnd",tick:{fill:"var(--ui-ink-soft)",fontSize:11},tickFormatter:$,type:"number",domain:["dataMin","dataMax"]}),e.jsx(_,{tick:{fill:"var(--ui-ink-soft)",fontSize:11},width:42}),e.jsx(z,{labelFormatter:$,contentStyle:{background:"var(--surface-glass)",border:"1px solid var(--ui-border-subtle)",borderRadius:8,color:"var(--ui-ink-strong)"}}),e.jsx(se,{type:"monotone",dataKey:"bpm",stroke:"#ef4444",fill:"url(#hrFill)",strokeWidth:2,dot:!1})]})}):e.jsx("div",{className:"grid h-full place-items-center rounded-[8px] bg-[var(--ui-surface-1)] text-sm text-[var(--ui-ink-soft)]",children:"No raw HR timeline has been synced for this workout yet."})})]}),e.jsxs(c,{className:"min-w-0 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[var(--ui-ink-strong)]",children:[e.jsx(G,{className:"size-4 text-[var(--primary)]"}),"Zone mix"]}),e.jsx("div",{className:"mt-4",children:e.jsx(de,{zones:r.zoneDurations})}),e.jsx("div",{className:"mt-5 h-[180px]",children:e.jsx(C,{width:"100%",height:"100%",children:e.jsxs(ie,{data:m,children:[e.jsx(T,{dataKey:"zone",tick:{fill:"var(--ui-ink-soft)",fontSize:10}}),e.jsx(_,{tick:{fill:"var(--ui-ink-soft)",fontSize:10},width:34}),e.jsx(z,{contentStyle:{background:"var(--surface-glass)",border:"1px solid var(--ui-border-subtle)",borderRadius:8,color:"var(--ui-ink-strong)"}}),e.jsx(re,{dataKey:"minutes",radius:[4,4,0,0]})]})})})]})]}),e.jsxs("section",{className:"grid min-w-0 gap-4 xl:grid-cols-[minmax(0,1fr)_360px]",children:[e.jsxs(c,{className:"min-w-0 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[var(--ui-ink-strong)]",children:[e.jsx(X,{className:"size-4 text-[var(--primary)]"}),"Route"]}),e.jsx("div",{className:"mt-4",children:d.routePoints.length>1?e.jsx(le,{points:d.routePoints}):e.jsx("div",{className:"grid min-h-[240px] place-items-center rounded-[8px] bg-[var(--ui-surface-1)] text-sm text-[var(--ui-ink-soft)]",children:"No route evidence is available for this workout."})})]}),e.jsxs(c,{className:"min-w-0 overflow-hidden",children:[e.jsx("div",{className:"text-[var(--ui-ink-strong)]",children:"Captured metrics"}),e.jsx("div",{className:"mt-4 grid gap-3",children:(((N=i.details)==null?void 0:N.metrics)??[]).slice(0,14).map(a=>e.jsxs("div",{className:"min-w-0 rounded-[8px] bg-[var(--ui-surface-1)] px-3 py-2",children:[e.jsx("div",{className:"break-words text-sm text-[var(--ui-ink-soft)] [overflow-wrap:anywhere]",children:a.label}),e.jsx("div",{className:"mt-1 break-words text-[var(--ui-ink-strong)] [overflow-wrap:anywhere]",children:ne(a.value,a.unit)})]},`${a.category}:${a.key}:${a.statistic}`))})]})]}),e.jsxs("section",{className:"grid min-w-0 gap-4 lg:grid-cols-[minmax(0,1fr)_minmax(280px,0.7fr)]",children:[e.jsxs(c,{className:"min-w-0 overflow-hidden",children:[e.jsx("div",{className:"text-[var(--ui-ink-strong)]",children:"Events and phases"}),e.jsxs("div",{className:"mt-4 grid gap-3",children:[[...((b=i.details)==null?void 0:b.events)??[],...((y=i.details)==null?void 0:y.components)??[]].slice(0,18).map((a,w)=>e.jsxs("div",{className:"min-w-0 rounded-[8px] bg-[var(--ui-surface-1)] px-4 py-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx("div",{className:"min-w-0 break-words text-[var(--ui-ink-strong)] [overflow-wrap:anywhere]",children:"label"in a?a.label:a.activity.canonicalLabel}),e.jsx(j,{tone:"meta",children:k(a.durationSeconds)})]}),e.jsx("div",{className:"mt-1 text-sm text-[var(--ui-ink-soft)]",children:F(a.startedAt,a.endedAt??a.startedAt)})]},`${"type"in a?a.type:a.externalUid}:${a.startedAt}:${w}`)),(((L=(S=i.details)==null?void 0:S.events)==null?void 0:L.length)??0)+(((R=(M=i.details)==null?void 0:M.components)==null?void 0:R.length)??0)===0?e.jsx("div",{className:"rounded-[8px] bg-[var(--ui-surface-1)] p-4 text-sm text-[var(--ui-ink-soft)]",children:"No provider events or phases were captured."}):null]})]}),e.jsxs(c,{className:"min-w-0 overflow-hidden",children:[e.jsx("div",{className:"text-[var(--ui-ink-strong)]",children:"Reflection"}),e.jsxs("div",{className:"mt-4 grid gap-4",children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Meaning and impact"}),e.jsx(E,{className:"min-h-[160px]",value:u,onChange:a=>l(a.target.value)})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Tags"}),e.jsx(P,{value:v,onChange:a=>g(a.target.value)})]}),e.jsxs(I,{type:"button",pending:x.isPending,pendingLabel:"Saving",onClick:()=>x.mutate(),children:[e.jsx(Y,{className:"size-4"}),"Save reflection"]})]})]})]})]})}export{ke as WorkoutDetailPage};
|
|
2
|
+
import{eH as D,S as H,E as B,c as j,C as c,T as E,I as P,B as I,eM as K,eN as W}from"./index-QJkjKYzZ.js";import{cc as Q,r as h,j as e,aC as O,bk as q,bG as Z,bL as G,dw as X,bX as Y}from"./vendor-Dnkkx2co.js";import{j as U,i as V,k as J}from"./state-vCcAT5Hq.js";import"./maps-C-yOWiDN.js";import{P as ee}from"./page-hero-CONuJu5J.js";import{R as C,A as te,C as ae,X as T,Y as _,T as z,a as se,e as ie,B as re}from"./charts-DFnEuIMB.js";import"./motion-Lt5B1XuE.js";import"./ui-C1iwpj2-.js";import"./forms-hB0SqEh-.js";import"./board-dIX6etHh.js";import"./graph-DDUZNRsO.js";const A={below_z1:"#94a3b8",zone_1:"#38bdf8",zone_2:"#22c55e",zone_3:"#eab308",zone_4:"#f97316",zone_5:"#ef4444"};function k(t){return t?`${Math.round(t/60)}m`:"0m"}function F(t,s){const o=new Intl.DateTimeFormat(void 0,{weekday:"short",day:"numeric",month:"short"}),n=new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"});return`${o.format(new Date(t))} · ${n.format(new Date(t))} - ${n.format(new Date(s))}`}function $(t){const s=typeof t=="number"?Math.floor(t):Number.parseFloat(String(t??""));return Number.isFinite(s)?new Date(s).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):""}function ne(t,s){if(typeof t=="number"){const o=Number.isInteger(t)?String(t):t.toFixed(1);return s&&s!=="count"?`${o} ${s}`:o}return typeof t=="boolean"?t?"Yes":"No":t==null?"n/a":String(t)}function oe(t){return t.length===0?null:{minLat:Math.min(...t.map(s=>s.latitude)),maxLat:Math.max(...t.map(s=>s.latitude)),minLon:Math.min(...t.map(s=>s.longitude)),maxLon:Math.max(...t.map(s=>s.longitude))}}function le({points:t}){var g;const s=h.useRef(null),[o,n]=h.useState(!1),u=typeof window<"u"?((g=window.localStorage.getItem("forge.map.tile-url"))==null?void 0:g.trim())??"":"";h.useEffect(()=>{let x=!1,i=null;if(!u||!s.current||t.length<2){n(!1);return}return K(()=>import("./maps-C-yOWiDN.js").then(r=>r.m),__vite__mapDeps([0,1,2,3])).then(r=>{x||!s.current||(i=new r.Map({container:s.current,style:{version:8,sources:{tiles:{type:"raster",tiles:[u],tileSize:256}},layers:[{id:"tiles",type:"raster",source:"tiles"}]},center:[t[0].longitude,t[0].latitude],zoom:13,attributionControl:!1}),i.on("load",()=>{if(!i)return;const d=t.map(m=>[m.longitude,m.latitude]);i.addSource("route",{type:"geojson",data:{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:d}}}),i.addLayer({id:"route",type:"line",source:"route",paint:{"line-color":"#f97316","line-width":4}});const f=d.reduce((m,p)=>m.extend(p),new r.LngLatBounds(d[0],d[0]));i.fitBounds(f,{padding:44,maxZoom:15}),n(!0)}))}),()=>{x=!0,i==null||i.remove()}},[t,u]);const l=oe(t),v=h.useMemo(()=>{if(!l||t.length<2)return"";const x=720,i=280,r=Math.max(1e-6,l.maxLon-l.minLon),d=Math.max(1e-6,l.maxLat-l.minLat);return t.map(f=>{const m=(f.longitude-l.minLon)/r*x,p=i-(f.latitude-l.minLat)/d*i;return`${m.toFixed(1)},${p.toFixed(1)}`}).join(" ")},[l,t]);return e.jsxs("div",{className:"relative min-h-[280px] overflow-hidden rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)]",children:[e.jsx("div",{ref:s,className:"absolute inset-0"}),o?null:e.jsxs("svg",{viewBox:"0 0 720 280",className:"absolute inset-0 h-full w-full",children:[e.jsx("rect",{width:"720",height:"280",fill:"var(--ui-surface-1)"}),v?e.jsx("polyline",{points:v,fill:"none",stroke:"#f97316",strokeWidth:"5",strokeLinecap:"round",strokeLinejoin:"round"}):null]}),e.jsx("div",{className:"absolute left-3 top-3 max-w-[calc(100%-1.5rem)] rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--surface-glass)] px-3 py-2 text-xs text-[var(--ui-ink-medium)] backdrop-blur",children:u?"Local-first map tiles configured":"No tile source configured; showing private route shape only"})]})}function de({zones:t}){return e.jsx("div",{className:"grid gap-3",children:t.map(s=>e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 text-sm",children:[e.jsx("span",{className:"min-w-0 break-words text-[var(--ui-ink-medium)] [overflow-wrap:anywhere]",children:s.label}),e.jsxs("span",{className:"shrink-0 text-[var(--ui-ink-strong)]",children:[(s.percentage*100).toFixed(1),"% · ",k(s.seconds)]})]}),e.jsx("div",{className:"h-2 overflow-hidden rounded-full bg-[var(--ui-surface-2)]",children:e.jsx("div",{className:"h-full rounded-full",style:{width:`${Math.max(1,s.percentage*100)}%`,background:A[s.key]??"#f8fafc"}})})]},s.key))})}function ke(){var p,N,b,y,S,L,M,R;const{workoutId:t=""}=Q(),s=U(),o=V({queryKey:["workout-detail",t],queryFn:()=>W(t),enabled:t.length>0}),n=o.data,[u,l]=h.useState(""),[v,g]=h.useState("");h.useEffect(()=>{n!=null&&n.workout&&(l(n.workout.meaningText??""),g(n.workout.tags.join(", ")))},[n==null?void 0:n.workout]);const x=J({mutationFn:()=>D(t,{meaningText:u,tags:v.split(",").map(a=>a.trim()).filter(Boolean)}),onSuccess:async()=>{await s.invalidateQueries({queryKey:["workout-detail",t]}),await s.invalidateQueries({queryKey:["forge-fitness"]})}});if(o.isLoading)return e.jsx(H,{title:"Loading workout"});if(o.isError||!n)return e.jsx(B,{eyebrow:"Workout detail",error:o.error??new Error("Forge could not load this workout detail."),onRetry:()=>void o.refetch()});const{workout:i,analytics:r,evidence:d}=n,f=d.timeSeries.filter(a=>a.metricKey==="heart_rate").map((a,w)=>({time:Date.parse(a.startedAt)+w/1e3,bpm:a.value})),m=r.zoneDurations.map(a=>({zone:a.label,minutes:Math.round(a.seconds/60),fill:A[a.key]??"#f8fafc"}));return e.jsxs("div",{className:"grid gap-6",children:[e.jsxs(O,{to:"/sports",className:"inline-flex w-fit items-center gap-2 text-sm text-[var(--ui-ink-soft)] transition hover:text-[var(--ui-ink-strong)]",children:[e.jsx(q,{className:"size-4"}),"Back to sports"]}),e.jsx(ee,{eyebrow:"Workout evidence",title:i.workoutTypeLabel??i.workoutType,description:`${F(i.startedAt,i.endedAt)} · ${i.sourceDevice||"Apple Health"}`,actions:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(j,{children:k(i.durationSeconds)}),e.jsxs(j,{tone:"meta",children:[r.confidence," HR zones"]}),(p=r.routeSummary)!=null&&p.hasRoute?e.jsxs(j,{tone:"meta",children:[r.routeSummary.pointCount," route points"]}):null]})}),e.jsxs("section",{className:"grid gap-4 lg:grid-cols-4",children:[e.jsxs(c,{children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Avg HR"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:r.hrSummary.averageHr??i.averageHeartRate??"n/a"}),e.jsx("div",{className:"mt-1 text-sm text-[var(--ui-ink-faint)]",children:"bpm"})]}),e.jsxs(c,{children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Max HR"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:r.hrSummary.maxHr??i.maxHeartRate??"n/a"}),e.jsx("div",{className:"mt-1 text-sm text-[var(--ui-ink-faint)]",children:"bpm"})]}),e.jsxs(c,{children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Training load"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:r.load.trimp??"n/a"}),e.jsx("div",{className:"mt-1 text-sm text-[var(--ui-ink-faint)]",children:"Forge TRIMP"})]}),e.jsxs(c,{children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"HR coverage"}),e.jsxs("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:[Math.round((r.dataQuality.sampleCoverage??0)*100),"%"]}),e.jsxs("div",{className:"mt-1 text-sm text-[var(--ui-ink-faint)]",children:[r.dataQuality.heartRateSampleCount??0," samples"]})]})]}),e.jsxs("section",{className:"grid min-w-0 gap-4 xl:grid-cols-[minmax(0,1.25fr)_minmax(280px,0.75fr)]",children:[e.jsxs(c,{className:"min-h-[360px] min-w-0 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[var(--ui-ink-strong)]",children:[e.jsx(Z,{className:"size-4 text-[var(--primary)]"}),"Heart-rate timeline"]}),e.jsx("div",{className:"mt-4 h-[300px]",children:f.length>0?e.jsx(C,{width:"100%",height:"100%",children:e.jsxs(te,{data:f,children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"hrFill",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:"#ef4444",stopOpacity:.38}),e.jsx("stop",{offset:"100%",stopColor:"#ef4444",stopOpacity:.04})]})}),e.jsx(ae,{stroke:"var(--ui-border-subtle)",vertical:!1}),e.jsx(T,{dataKey:"time",interval:"preserveStartEnd",tick:{fill:"var(--ui-ink-soft)",fontSize:11},tickFormatter:$,type:"number",domain:["dataMin","dataMax"]}),e.jsx(_,{tick:{fill:"var(--ui-ink-soft)",fontSize:11},width:42}),e.jsx(z,{labelFormatter:$,contentStyle:{background:"var(--surface-glass)",border:"1px solid var(--ui-border-subtle)",borderRadius:8,color:"var(--ui-ink-strong)"}}),e.jsx(se,{type:"monotone",dataKey:"bpm",stroke:"#ef4444",fill:"url(#hrFill)",strokeWidth:2,dot:!1})]})}):e.jsx("div",{className:"grid h-full place-items-center rounded-[8px] bg-[var(--ui-surface-1)] text-sm text-[var(--ui-ink-soft)]",children:"No raw HR timeline has been synced for this workout yet."})})]}),e.jsxs(c,{className:"min-w-0 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[var(--ui-ink-strong)]",children:[e.jsx(G,{className:"size-4 text-[var(--primary)]"}),"Zone mix"]}),e.jsx("div",{className:"mt-4",children:e.jsx(de,{zones:r.zoneDurations})}),e.jsx("div",{className:"mt-5 h-[180px]",children:e.jsx(C,{width:"100%",height:"100%",children:e.jsxs(ie,{data:m,children:[e.jsx(T,{dataKey:"zone",tick:{fill:"var(--ui-ink-soft)",fontSize:10}}),e.jsx(_,{tick:{fill:"var(--ui-ink-soft)",fontSize:10},width:34}),e.jsx(z,{contentStyle:{background:"var(--surface-glass)",border:"1px solid var(--ui-border-subtle)",borderRadius:8,color:"var(--ui-ink-strong)"}}),e.jsx(re,{dataKey:"minutes",radius:[4,4,0,0]})]})})})]})]}),e.jsxs("section",{className:"grid min-w-0 gap-4 xl:grid-cols-[minmax(0,1fr)_360px]",children:[e.jsxs(c,{className:"min-w-0 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[var(--ui-ink-strong)]",children:[e.jsx(X,{className:"size-4 text-[var(--primary)]"}),"Route"]}),e.jsx("div",{className:"mt-4",children:d.routePoints.length>1?e.jsx(le,{points:d.routePoints}):e.jsx("div",{className:"grid min-h-[240px] place-items-center rounded-[8px] bg-[var(--ui-surface-1)] text-sm text-[var(--ui-ink-soft)]",children:"No route evidence is available for this workout."})})]}),e.jsxs(c,{className:"min-w-0 overflow-hidden",children:[e.jsx("div",{className:"text-[var(--ui-ink-strong)]",children:"Captured metrics"}),e.jsx("div",{className:"mt-4 grid gap-3",children:(((N=i.details)==null?void 0:N.metrics)??[]).slice(0,14).map(a=>e.jsxs("div",{className:"min-w-0 rounded-[8px] bg-[var(--ui-surface-1)] px-3 py-2",children:[e.jsx("div",{className:"break-words text-sm text-[var(--ui-ink-soft)] [overflow-wrap:anywhere]",children:a.label}),e.jsx("div",{className:"mt-1 break-words text-[var(--ui-ink-strong)] [overflow-wrap:anywhere]",children:ne(a.value,a.unit)})]},`${a.category}:${a.key}:${a.statistic}`))})]})]}),e.jsxs("section",{className:"grid min-w-0 gap-4 lg:grid-cols-[minmax(0,1fr)_minmax(280px,0.7fr)]",children:[e.jsxs(c,{className:"min-w-0 overflow-hidden",children:[e.jsx("div",{className:"text-[var(--ui-ink-strong)]",children:"Events and phases"}),e.jsxs("div",{className:"mt-4 grid gap-3",children:[[...((b=i.details)==null?void 0:b.events)??[],...((y=i.details)==null?void 0:y.components)??[]].slice(0,18).map((a,w)=>e.jsxs("div",{className:"min-w-0 rounded-[8px] bg-[var(--ui-surface-1)] px-4 py-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx("div",{className:"min-w-0 break-words text-[var(--ui-ink-strong)] [overflow-wrap:anywhere]",children:"label"in a?a.label:a.activity.canonicalLabel}),e.jsx(j,{tone:"meta",children:k(a.durationSeconds)})]}),e.jsx("div",{className:"mt-1 text-sm text-[var(--ui-ink-soft)]",children:F(a.startedAt,a.endedAt??a.startedAt)})]},`${"type"in a?a.type:a.externalUid}:${a.startedAt}:${w}`)),(((L=(S=i.details)==null?void 0:S.events)==null?void 0:L.length)??0)+(((R=(M=i.details)==null?void 0:M.components)==null?void 0:R.length)??0)===0?e.jsx("div",{className:"rounded-[8px] bg-[var(--ui-surface-1)] p-4 text-sm text-[var(--ui-ink-soft)]",children:"No provider events or phases were captured."}):null]})]}),e.jsxs(c,{className:"min-w-0 overflow-hidden",children:[e.jsx("div",{className:"text-[var(--ui-ink-strong)]",children:"Reflection"}),e.jsxs("div",{className:"mt-4 grid gap-4",children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Meaning and impact"}),e.jsx(E,{className:"min-h-[160px]",value:u,onChange:a=>l(a.target.value)})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Tags"}),e.jsx(P,{value:v,onChange:a=>g(a.target.value)})]}),e.jsxs(I,{type:"button",pending:x.isPending,pendingLabel:"Saving",onClick:()=>x.mutate(),children:[e.jsx(Y,{className:"size-4"}),"Save reflection"]})]})]})]})]})}export{ke as WorkoutDetailPage};
|
package/dist/index.html
CHANGED
|
@@ -130,7 +130,7 @@
|
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
132
|
</style>
|
|
133
|
-
<script type="module" crossorigin src="/forge/assets/index-
|
|
133
|
+
<script type="module" crossorigin src="/forge/assets/index-QJkjKYzZ.js"></script>
|
|
134
134
|
<link rel="modulepreload" crossorigin href="/forge/assets/vendor-Dnkkx2co.js">
|
|
135
135
|
<link rel="modulepreload" crossorigin href="/forge/assets/state-vCcAT5Hq.js">
|
|
136
136
|
<link rel="modulepreload" crossorigin href="/forge/assets/motion-Lt5B1XuE.js">
|
|
@@ -140,7 +140,7 @@
|
|
|
140
140
|
<link rel="modulepreload" crossorigin href="/forge/assets/graph-DDUZNRsO.js">
|
|
141
141
|
<link rel="stylesheet" crossorigin href="/forge/assets/vendor-CRS-psbw.css">
|
|
142
142
|
<link rel="stylesheet" crossorigin href="/forge/assets/graph-BZV40eAE.css">
|
|
143
|
-
<link rel="stylesheet" crossorigin href="/forge/assets/index-
|
|
143
|
+
<link rel="stylesheet" crossorigin href="/forge/assets/index-Bcem7l5u.css">
|
|
144
144
|
</head>
|
|
145
145
|
<body class="bg-canvas text-ink antialiased">
|
|
146
146
|
<div id="root">
|