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{r as g,j as e,aC as ce}from"./vendor-Dnkkx2co.js";import{i as de,k as Z}from"./state-vCcAT5Hq.js";import{S as he}from"./settings-section-nav-BWox23Qv.js";import{P as ue}from"./page-hero-5RTqAI88.js";import{i as pe,C as ge,B as me,M as xe}from"./graph-DDUZNRsO.js";import{C as F,aq as fe,c as b,U as E,Q as ie,F as $,j as H,I as T,T as be,W as ve,u as je,eu as we,ev as ye,ew as Ne,B as J,ex as ke}from"./index-By3tQxiE.js";import"./motion-Lt5B1XuE.js";import"./ui-C1iwpj2-.js";import"./forms-hB0SqEh-.js";import"./board-dIX6etHh.js";const ae=[{id:"visibility",label:"Discovery and visibility",description:"What the source user can discover, inspect, and pull into read flows on the target side.",rights:[{key:"discoverable",label:"Discoverable",description:"The target appears as a reachable collaborator in the source user's graph and pickers."},{key:"canListUsers",label:"List users",description:"The source user can include the target in directory, comparison, and routing surfaces."},{key:"canReadProfile",label:"Read profile",description:"The source user can inspect the target's identity card, handle, type, and description."},{key:"canReadEntities",label:"Read entities",description:"The source user can read the target's goals, projects, tasks, notes, strategies, and related records."},{key:"canSearchEntities",label:"Search entities",description:"The source user can find the target's work through Forge search and entity pickers."}]},{id:"coordination",label:"Messaging, context, and handoff",description:"What the source user can message, connect, and coordinate on the target side before changing execution.",rights:[{key:"canLinkEntities",label:"Share context",description:"The source user can attach the target's records into shared notes, strategies, calendar context, and cross-owner plans."},{key:"canCoordinate",label:"Message and coordinate",description:"The source user can communicate with the target through Forge, hand off work, and coordinate execution."},{key:"canViewMetrics",label:"View metrics",description:"The source user can inspect the target's XP, alignment, and progress metrics."},{key:"canViewActivity",label:"View activity",description:"The source user can inspect the target's activity stream, evidence, and execution trail."}]},{id:"execution",label:"Plan and execution control",description:"What the source user can actually change on the target side once collaboration is trusted.",rights:[{key:"canManageStrategies",label:"Manage strategies",description:"The source user can draft and update strategies that belong to the target."},{key:"canCreateOnBehalf",label:"Create on behalf",description:"The source user can intentionally create new target-owned entities."},{key:"canAffectEntities",label:"Affect entities",description:"The source user can mutate work that belongs to the target."}]}],Ce=[{id:"full_collab",label:"Full collaboration",description:"Use when two humans or agents can see, coordinate, plan, and change each other's work.",rights:{discoverable:!0,canListUsers:!0,canReadProfile:!0,canReadEntities:!0,canSearchEntities:!0,canLinkEntities:!0,canCoordinate:!0,canAffectEntities:!0,canManageStrategies:!0,canCreateOnBehalf:!0,canViewMetrics:!0,canViewActivity:!0}},{id:"coordination_only",label:"Coordinate only",description:"Use when the source user may see and coordinate with the target but should not directly mutate target-owned work.",rights:{discoverable:!0,canListUsers:!0,canReadProfile:!0,canReadEntities:!0,canSearchEntities:!0,canLinkEntities:!0,canCoordinate:!0,canAffectEntities:!1,canManageStrategies:!0,canCreateOnBehalf:!1,canViewMetrics:!0,canViewActivity:!0}},{id:"observe_only",label:"Observe only",description:"Use when the source user should keep visibility into the target without planning or execution control.",rights:{discoverable:!0,canListUsers:!0,canReadProfile:!0,canReadEntities:!0,canSearchEntities:!0,canLinkEntities:!1,canCoordinate:!1,canAffectEntities:!1,canManageStrategies:!1,canCreateOnBehalf:!1,canViewMetrics:!0,canViewActivity:!0}},{id:"hidden",label:"Hidden edge",description:"Use when this direction should stop discovering, reading, or acting on the target.",rights:{discoverable:!1,canListUsers:!1,canReadProfile:!1,canReadEntities:!1,canSearchEntities:!1,canLinkEntities:!1,canCoordinate:!1,canAffectEntities:!1,canManageStrategies:!1,canCreateOnBehalf:!1,canViewMetrics:!1,canViewActivity:!1}}],A=ae.reduce((s,n)=>s+n.rights.length,0);function P(s){return Object.values(s.config.rights).filter(Boolean).length}function re(s){const n=[];return s.config.rights.canReadEntities&&n.push("See"),s.config.rights.canCoordinate&&n.push("Message"),s.config.rights.canManageStrategies&&n.push("Plan"),s.config.rights.canAffectEntities&&n.push("Affect"),n.join(" · ")||"Hidden"}function Ue(s){return!s.config.rights.discoverable&&!s.config.rights.canReadEntities?"Hidden":s.config.rights.canAffectEntities&&s.config.rights.canManageStrategies?"Trusted":s.config.rights.canCoordinate||s.config.rights.canLinkEntities?"Coordinated":"Observed"}function ne(s){return[{id:"see",label:"See",enabled:s.config.rights.discoverable&&s.config.rights.canReadEntities&&s.config.rights.canSearchEntities},{id:"message",label:"Message",enabled:s.config.rights.canCoordinate},{id:"share",label:"Share context",enabled:s.config.rights.canLinkEntities},{id:"plan",label:"Plan",enabled:s.config.rights.canManageStrategies},{id:"affect",label:"Affect",enabled:s.config.rights.canAffectEntities||s.config.rights.canCreateOnBehalf}]}function Ee(s,n){return Object.entries(n.rights).every(([i,u])=>s.config.rights[i]===u)}function Se(s,n){const i=s.filter(a=>a.kind==="human"),u=s.filter(a=>a.kind==="bot"),p={x:560,y:360},m={width:226,height:132},d=i[0]??null,w=[...i.slice(d?1:0).map(a=>({user:a,radius:245,offset:-90})),...u.map(a=>({user:a,radius:390,offset:-90}))],f=w.length,y=[...d?[{user:d,position:{x:p.x-m.width/2,y:p.y-m.height/2}}]:[],...w.map((a,c)=>{const h=(a.offset+360/Math.max(f,1)*c)*Math.PI/180;return{user:a.user,position:{x:p.x+Math.cos(h)*a.radius-m.width/2,y:p.y+Math.sin(h)*a.radius-m.height/2}}})],C=new Set(n.selectedGrant?[n.selectedGrant.subjectUserId,n.selectedGrant.targetUserId]:n.selectedUserId?[n.selectedUserId]:[]);return y.map(({user:a,position:c})=>{const h=C.has(a.id),t=a.id===n.selectedUserId;return{id:a.id,position:c,draggable:!1,selectable:!1,data:{label:e.jsxs("div",{className:`min-w-[206px] rounded-[22px] border px-4 py-4 shadow-[var(--ui-shadow-soft)] transition ${t?"border-[color-mix(in_srgb,var(--warning)_45%,var(--ui-border-subtle)_55%)] bg-[var(--ui-warning-soft)]":h?"border-[color-mix(in_srgb,var(--primary)_28%,var(--ui-border-subtle)_72%)] bg-[var(--ui-accent-soft)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)]"}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx(E,{user:a}),e.jsx(b,{tone:"meta",children:a.kind})]}),e.jsxs("div",{className:"mt-3 text-xs text-[var(--ui-ink-soft)]",children:["@",a.handle]}),e.jsx("div",{className:"mt-2 line-clamp-2 text-xs leading-5 text-[var(--ui-ink-faint)]",children:a.description||"No user description yet."})]})},style:{background:"transparent",border:"none",padding:0}}})}function Ie(s,n,i){return s.filter(u=>u.subjectUserId!==u.targetUserId).map(u=>{const p=n===u.id,m=i!==null&&(u.subjectUserId===i||u.targetUserId===i),d=P(u),v=p?"var(--warning)":!u.config.rights.discoverable&&!u.config.rights.canReadEntities?"var(--danger)":m?"var(--primary)":"var(--ui-border-strong)";return{id:u.id,source:u.subjectUserId,target:u.targetUserId,label:`${re(u)} · ${d}/${A}`,markerEnd:{type:xe.ArrowClosed,color:v},labelStyle:{fill:p?"var(--warning)":"var(--ui-ink-medium)",fontSize:11,fontWeight:600},labelBgStyle:{fill:p?"var(--ui-warning-soft)":"var(--ui-surface-1)",stroke:p?"color-mix(in_srgb,var(--warning)_36%,var(--ui-border-subtle)_64%)":"var(--ui-border-subtle)",strokeWidth:1},labelBgPadding:[7,5],labelBgBorderRadius:8,style:{stroke:v,strokeWidth:p?2.5:m?1.8:1.25},animated:p}})}function Me({users:s,grants:n,selectedGrantId:i=null,selectedUserId:u=null,onOpenGrant:p,onOpenUser:m}){const d=n.find(c=>c.id===i)??null,v=g.useMemo(()=>Se(s,{selectedUserId:u,selectedGrant:d}),[d,u,s]),w=g.useMemo(()=>Ie(n,i,u),[n,i,u]),f=g.useMemo(()=>n.filter(c=>c.subjectUserId!==c.targetUserId),[n]),y=f.filter(c=>P(c)===A).length,C=f.filter(c=>c.config.rights.canCoordinate).length,a=f.filter(c=>c.config.rights.canAffectEntities||c.config.rights.canCreateOnBehalf).length;return e.jsxs(F,{className:"overflow-hidden p-0",children:[e.jsxs("div",{className:"grid gap-4 border-b border-[var(--ui-border-subtle)] px-5 py-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"max-w-3xl",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Directed relationship graph"}),e.jsx(fe,{content:"Keep Forge, OpenClaw, Hermes, and the browser on the same runtime and storage root when these arrows should describe one shared human and bot system.",label:"Explain the shared runtime rule"})]}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Click a user card to open that user's settings. Click any arrow to open the exact directional relationship flow for that lane."})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(b,{tone:"meta",children:[f.length," edges"]}),e.jsxs(b,{className:"bg-[var(--ui-success-soft)] text-[var(--success)]",children:[y," fully open"]})]})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-3",children:[e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Full collaboration"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:y}),e.jsx("div",{className:"text-xs leading-5 text-[var(--ui-ink-faint)]",children:"Directions still running with the default fully open posture."})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Coordination lanes"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:C}),e.jsx("div",{className:"text-xs leading-5 text-[var(--ui-ink-faint)]",children:"Directions allowed to coordinate directly through Forge."})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Execution control"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:a}),e.jsx("div",{className:"text-xs leading-5 text-[var(--ui-ink-faint)]",children:"Directions allowed to create or mutate target-owned work."})]})]})]}),e.jsx("div",{className:"h-[clamp(26rem,58vh,42rem)] bg-[linear-gradient(180deg,var(--ui-surface-2),var(--ui-surface-1))] sm:h-[min(72vh,54rem)] sm:min-h-[34rem]",children:e.jsxs(pe,{className:"user-relationship-flow",nodes:v,edges:w,fitView:!0,fitViewOptions:{padding:.1,maxZoom:.95},nodesDraggable:!1,nodesConnectable:!1,elementsSelectable:!0,onNodeClick:(c,h)=>{m(h.id)},onEdgeClick:(c,h)=>{p(h.id)},attributionPosition:"bottom-left",children:[e.jsx(ge,{showInteractive:!1}),e.jsx(me,{gap:28,size:1,color:"var(--ui-border-subtle)"})]})})]})}const O="rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",Y="text-sm font-medium text-[var(--ui-ink-strong)]",Oe="text-sm leading-6 text-[var(--ui-ink-soft)]",Re={kind:"human",handle:"",displayName:"",description:"",accentColor:"#c0c1ff"};function ee(s){return s?{kind:s.kind,handle:s.handle,displayName:s.displayName,description:s.description,accentColor:s.accentColor}:Re}function Fe({open:s,onOpenChange:n,user:i,grants:u,ownership:p,xp:m,pending:d=!1,onSubmit:v,onOpenRelationship:w}){const[f,y]=g.useState(()=>ee(i)),[C,a]=g.useState(null);g.useEffect(()=>{s&&(y(ee(i)),a(null))},[s,i]);const c=g.useMemo(()=>u.filter(o=>o.subjectUserId!==o.targetUserId),[u]),h=g.useMemo(()=>i?c.filter(o=>o.subjectUserId===i.id):[],[c,i]),t=g.useMemo(()=>i?c.filter(o=>o.targetUserId===i.id):[],[c,i]),N=[{id:"identity",eyebrow:i?"Edit user":"Create user",title:i?"Update the user identity":"Add a human or bot user",description:"Set the owner type and the public identity Forge will use across ownership, routing, and collaboration surfaces.",render:(o,x)=>e.jsxs(e.Fragment,{children:[e.jsx($,{label:"Kind",description:"Humans represent real people. Bots represent agents or automations with their own ownership lane.",children:e.jsx(H,{columns:2,value:o.kind,onChange:k=>x({kind:k}),options:[{value:"human",label:"Human",description:"Use for a real person in the Forge runtime."},{value:"bot",label:"Bot",description:"Use for an agent, assistant, or automation actor."}]})}),e.jsx($,{label:"Handle",description:"This becomes the stable short id shown as @handle.",hint:"Use lowercase and a durable label, for example forge-operator or planner-bot.",children:e.jsx(T,{value:o.handle,onChange:k=>x({handle:k.target.value}),placeholder:"forge-operator"})}),e.jsx($,{label:"Display name",description:"This is the human-readable label used across the UI.",children:e.jsx(T,{value:o.displayName,onChange:k=>x({displayName:k.target.value}),placeholder:"Forge Operator"})})]})},{id:"profile",eyebrow:"Profile",title:"Describe the user lane",description:"Capture what this user represents in the shared Forge runtime and pick the accent color that helps the lane stay recognizable.",render:(o,x)=>e.jsxs(e.Fragment,{children:[e.jsx($,{label:"Description",description:"Explain what this user is responsible for and what side of the system it represents.",children:e.jsx(be,{value:o.description,onChange:k=>x({description:k.target.value}),className:"min-h-36",placeholder:"Primary human operator for strategy, execution, and review."})}),e.jsx($,{label:"Accent color",description:"Forge uses this accent to help the user stand out in ownership and collaboration surfaces.",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(T,{value:o.accentColor,onChange:k=>x({accentColor:k.target.value}),placeholder:"#c0c1ff"}),e.jsx("div",{className:"size-10 shrink-0 rounded-full border border-[var(--ui-border-subtle)]",style:{backgroundColor:o.accentColor||"#c0c1ff"}})]})}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[e.jsxs("div",{className:`${O} px-4 py-3`,children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Owned records"}),e.jsx("div",{className:"mt-2 text-[var(--ui-ink-strong)]",children:(p==null?void 0:p.totalOwnedEntities)??0})]}),e.jsxs("div",{className:`${O} px-4 py-3`,children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Total XP"}),e.jsx("div",{className:"mt-2 text-[var(--ui-ink-strong)]",children:(m==null?void 0:m.totalXp)??0})]}),e.jsxs("div",{className:`${O} px-4 py-3`,children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Weekly XP"}),e.jsx("div",{className:"mt-2 text-[var(--ui-ink-strong)]",children:(m==null?void 0:m.weeklyXp)??0})]})]})]})},{id:"relationships",eyebrow:"Relationships",title:"Open directional relationship settings",description:"Each arrow is a separate contract. Open the exact lane you want to adjust and Forge will take you into the relationship flow.",render:()=>i?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`${O} p-4`,children:[e.jsx(E,{user:i}),e.jsxs("div",{className:`mt-3 ${Oe}`,children:["@",i.handle," · ",i.description||"No description yet."]})]}),e.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:Y,children:"Outbound lanes"}),h.length>0?h.map(o=>e.jsxs("button",{type:"button",className:`${O} px-4 py-4 text-left transition hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-hover)]`,onClick:()=>w(o.id),children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(E,{user:o.subjectUser}),e.jsx("span",{className:"text-[var(--ui-ink-faint)]",children:"→"}),e.jsx(E,{user:o.targetUser})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx(b,{tone:"meta",children:re(o)}),e.jsxs(b,{tone:"meta",children:[P(o),"/",A," rights"]})]})]},o.id)):e.jsx("div",{className:"rounded-[20px] border border-dashed border-[var(--ui-border-subtle)] px-4 py-4 text-sm text-[var(--ui-ink-soft)]",children:"No outbound relationship lanes yet."})]}),e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:Y,children:"Inbound lanes"}),t.length>0?t.map(o=>e.jsxs("button",{type:"button",className:`${O} px-4 py-4 text-left transition hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-hover)]`,onClick:()=>w(o.id),children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(E,{user:o.subjectUser}),e.jsx("span",{className:"text-[var(--ui-ink-faint)]",children:"→"}),e.jsx(E,{user:o.targetUser})]}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:ne(o).map(x=>e.jsx(b,{className:x.enabled?"bg-[var(--ui-surface-1)] text-[var(--ui-ink-medium)]":"bg-[var(--ui-surface-1)] text-[var(--ui-ink-faint)] opacity-70",children:x.label},`${o.id}-${x.id}`))})]},o.id)):e.jsx("div",{className:"rounded-[20px] border border-dashed border-[var(--ui-border-subtle)] px-4 py-4 text-sm text-[var(--ui-ink-soft)]",children:"No inbound relationship lanes yet."})]})]})]}):e.jsx("div",{className:"rounded-[20px] border border-dashed border-[var(--ui-border-subtle)] px-4 py-4 text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Create the user first, then Forge will generate the directional relationship lanes you can tune from here."})}];return e.jsx(ie,{open:s,onOpenChange:n,eyebrow:i?"User settings":"Create user",title:i?"User settings":"Create user",description:"Edit the user identity, clarify what this lane represents, and jump into relationship settings without crowding the page.",value:f,onChange:y,draftPersistenceKey:i?`users.settings.${i.id}`:"users.settings.new",steps:N,submitLabel:i?"Save user":"Create user",pending:d,pendingLabel:i?"Saving user":"Creating user",error:C,contentClassName:"lg:w-[min(58rem,calc(100vw-1.5rem))]",onSubmit:async()=>{const o=f.handle.trim(),x=f.displayName.trim();if(o.length===0){a("Add a handle before saving this user.");return}if(x.length===0){a("Add a display name before saving this user.");return}await v({userId:i==null?void 0:i.id,input:{kind:f.kind,handle:o,displayName:x,description:f.description.trim(),accentColor:f.accentColor.trim()||"#c0c1ff"}}),n(!1)}})}const _="rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",S="text-sm font-medium text-[var(--ui-ink-strong)]",G="text-sm leading-6 text-[var(--ui-ink-soft)]",Ae="text-xs leading-5 text-[var(--ui-ink-faint)]";function se(s,n){return{accessLevel:(s==null?void 0:s.accessLevel)??"manage",applyScope:"this_arrow",rights:{discoverable:(s==null?void 0:s.config.rights.discoverable)??!0,canListUsers:(s==null?void 0:s.config.rights.canListUsers)??!0,canReadProfile:(s==null?void 0:s.config.rights.canReadProfile)??!0,canReadEntities:(s==null?void 0:s.config.rights.canReadEntities)??!0,canSearchEntities:(s==null?void 0:s.config.rights.canSearchEntities)??!0,canLinkEntities:(s==null?void 0:s.config.rights.canLinkEntities)??!0,canCoordinate:(s==null?void 0:s.config.rights.canCoordinate)??!0,canAffectEntities:(s==null?void 0:s.config.rights.canAffectEntities)??!0,canManageStrategies:(s==null?void 0:s.config.rights.canManageStrategies)??!0,canCreateOnBehalf:(s==null?void 0:s.config.rights.canCreateOnBehalf)??!0,canViewMetrics:(s==null?void 0:s.config.rights.canViewMetrics)??!0,canViewActivity:(s==null?void 0:s.config.rights.canViewActivity)??!0}}}function $e({open:s,onOpenChange:n,grant:i,grants:u,pending:p=!1,onSubmit:m}){const d=g.useMemo(()=>i?u.find(a=>a.subjectUserId===i.targetUserId&&a.targetUserId===i.subjectUserId)??null:null,[i,u]),[v,w]=g.useState(()=>se(i,!!d));g.useEffect(()=>{s&&w(se(i,!!d))},[i,s,d]);const f=g.useMemo(()=>Object.values(v.rights).filter(Boolean).length,[v.rights]),y=Math.round(f/A*100),C=[{id:"posture",eyebrow:"Relationship posture",title:"Set the trust mode for this arrow",description:"Each arrow is directional. Decide whether you want to tune only this lane or mirror the same contract onto both directions.",render:(a,c)=>e.jsxs(e.Fragment,{children:[i?e.jsxs("div",{className:`${_} p-4`,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(E,{user:i.subjectUser}),e.jsx("span",{className:"text-[var(--ui-ink-faint)]",children:"→"}),e.jsx(E,{user:i.targetUser})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx(b,{tone:"meta",children:Ue(i)}),e.jsxs(b,{tone:"meta",children:[P(i),"/",A," rights"]})]})]}):null,e.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:S,children:"Access level"}),e.jsx(H,{columns:2,value:a.accessLevel,onChange:h=>c({accessLevel:h}),options:[{value:"view",label:"View",description:"Use when this lane should stay mostly observational."},{value:"manage",label:"Manage",description:"Use when the source side can actively collaborate or act."}]})]}),d?e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:S,children:"Apply scope"}),e.jsx(H,{columns:2,value:a.applyScope,onChange:h=>c({applyScope:h}),options:[{value:"this_arrow",label:"This arrow",description:"Only change the exact direction you opened."},{value:"both_arrows",label:"Both arrows",description:"Mirror the same contract onto the reverse direction too."}]})]}):null]}),e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:S,children:"Quick preset"}),e.jsx("div",{className:"grid gap-3 md:grid-cols-2",children:Ce.map(h=>e.jsxs("button",{type:"button",className:`rounded-[22px] border p-4 text-left transition ${i&&Ee(i,h)?"border-[color-mix(in_srgb,var(--warning)_32%,var(--ui-border-subtle)_68%)] bg-[var(--ui-warning-soft)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-hover)]"}`,onClick:()=>c({rights:{...a.rights,...h.rights}}),children:[e.jsx("div",{className:S,children:h.label}),e.jsx("div",{className:`mt-2 ${G}`,children:h.description})]},h.id))})]})]})},{id:"rights",eyebrow:"Rights",title:"Tune the individual permissions",description:"Use the preset as the starting point, then sharpen the exact boundaries only where this relationship needs them.",render:(a,c)=>e.jsx(e.Fragment,{children:ae.map(h=>e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:S,children:h.label}),e.jsx("div",{className:`mt-1 ${G}`,children:h.description})]}),e.jsx("div",{className:"grid gap-2",children:h.rights.map(t=>e.jsxs("label",{className:"flex items-start justify-between gap-3 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:S,children:t.label}),e.jsx("div",{className:`mt-1 ${Ae}`,children:t.description})]}),e.jsx("input",{type:"checkbox",checked:a.rights[t.key],onChange:N=>c({rights:{...a.rights,[t.key]:N.target.checked}})})]},t.key))})]},h.id))})},{id:"review",eyebrow:"Review",title:"Review the final relationship contract",description:"Check the enabled capabilities, confirm whether both directions should match, and then save the relationship.",render:a=>{var c,h;return e.jsx(e.Fragment,{children:e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsxs("div",{className:`${_} p-4`,children:[e.jsx("div",{className:S,children:"Capability coverage"}),e.jsx("div",{className:"mt-4",children:e.jsx(ve,{value:y})}),e.jsxs("div",{className:"mt-3 text-sm text-[var(--ui-ink-soft)]",children:[f,"/",A," rights enabled"]}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:ne({...i??{id:"draft",subjectUserId:"",targetUserId:"",accessLevel:a.accessLevel,config:{self:!1,mutable:!0,linkedEntities:!0,rights:a.rights},createdAt:"",updatedAt:"",subjectUser:null,targetUser:null},accessLevel:a.accessLevel,config:{...(i==null?void 0:i.config)??{self:!1,mutable:!0,linkedEntities:!0},rights:a.rights}}).map(t=>e.jsx(b,{className:t.enabled?"bg-[var(--ui-surface-1)] text-[var(--ui-ink-medium)]":"bg-[var(--ui-surface-1)] text-[var(--ui-ink-faint)] opacity-70",children:t.label},t.id))})]}),e.jsxs("div",{className:`${_} p-4`,children:[e.jsx("div",{className:S,children:"Save scope"}),e.jsx("div",{className:`mt-3 ${G}`,children:a.applyScope==="both_arrows"&&d?"Forge will apply the same access level and rights to both directions of this pair.":"Forge will only update the exact arrow you opened."}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsxs(b,{tone:"meta",children:["access ",a.accessLevel]}),e.jsxs(b,{tone:"meta",children:["scope"," ",a.applyScope==="both_arrows"&&d?"both arrows":"this arrow"]})]}),d?e.jsxs("div",{className:"mt-4 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-3 text-sm text-[var(--ui-ink-soft)]",children:["Reverse arrow available:"," ",((c=d.subjectUser)==null?void 0:c.displayName)??d.subjectUserId," ","→"," ",((h=d.targetUser)==null?void 0:h.displayName)??d.targetUserId]}):null]})]})})}}];return e.jsx(ie,{open:s,onOpenChange:n,eyebrow:"Relationship settings",title:"Relationship settings",description:"Edit the exact directional contract between two users without keeping the full rights editor pinned on the page.",value:v,onChange:w,draftPersistenceKey:i?`users.relationship.${i.id}`:"users.relationship.new",steps:C,submitLabel:"Save relationship",pending:p,pendingLabel:"Saving relationship",contentClassName:"lg:w-[min(62rem,calc(100vw-1.5rem))]",onSubmit:async()=>{i&&(await m({grantId:i.id,patch:{accessLevel:v.accessLevel,rights:v.rights},reverseGrantId:(d==null?void 0:d.id)??null,applyToReverse:v.applyScope==="both_arrows"&&d!==null}),n(!1))}})}const U="font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",M="text-sm leading-6 text-[var(--ui-ink-soft)]",te="text-xs leading-5 text-[var(--ui-ink-faint)]",R="rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]";function We(){var X;const s=je(),[n,i]=g.useState(null),[u,p]=g.useState(null),[m,d]=g.useState(!1),[v,w]=g.useState(!1),[f,y]=g.useState(""),C=de({queryKey:["forge-user-directory"],queryFn:ke}),a=async()=>{await Promise.all([s.refresh(),C.refetch()])},c=Z({mutationFn:async({input:r,userId:l})=>l?(await we(l,r)).user:(await ye(r)).user,onSuccess:async()=>{i(null),d(!1),await a()}}),h=Z({mutationFn:async({grantId:r,patch:l})=>(await Ne(r,l)).grant,onSuccess:a}),t=(X=C.data)==null?void 0:X.directory,N=(t==null?void 0:t.grants.find(r=>r.id===u))??null,o=g.useMemo(()=>new Map(((t==null?void 0:t.ownership)??[]).map(r=>[r.userId,r])),[t==null?void 0:t.ownership]),x=g.useMemo(()=>new Map(((t==null?void 0:t.xp)??[]).map(r=>[r.userId,r])),[t==null?void 0:t.xp]),k=g.useMemo(()=>{const r=new Map;for(const l of(t==null?void 0:t.grants)??[]){if(!l.targetUser||l.subjectUserId===l.targetUserId)continue;const j=r.get(l.subjectUserId)??[];j.push(l.targetUser),r.set(l.subjectUserId,j)}return r},[t==null?void 0:t.grants]),L=g.useMemo(()=>{const r=((t==null?void 0:t.grants)??[]).filter(l=>l.subjectUserId!==l.targetUserId);return{totalEdges:r.length,fullyOpenEdges:r.filter(l=>Object.values(l.config.rights).every(Boolean)).length,coordinationEdges:r.filter(l=>l.config.rights.canCoordinate).length,executionEdges:r.filter(l=>l.config.rights.canAffectEntities||l.config.rights.canCreateOnBehalf).length}},[t==null?void 0:t.grants]),B=f.trim().toLowerCase(),V=g.useMemo(()=>{const l=((t==null?void 0:t.users)??s.snapshot.users).filter(j=>B?[j.displayName,j.handle,j.kind,j.description].join(" ").toLowerCase().includes(B):!0);return{humans:l.filter(j=>j.kind==="human"),bots:l.filter(j=>j.kind==="bot")}},[t==null?void 0:t.users,B,s.snapshot.users]),le=(N==null?void 0:N.subjectUserId)??(n==null?void 0:n.id)??null,oe=(N==null?void 0:N.id)??null;return e.jsxs("div",{className:"mx-auto grid w-full max-w-[1440px] gap-5",children:[e.jsx(ue,{title:"Users",description:"Forge users can be human or bot. Ownership, search, and routing are prepared so work can move across both sides of the system.",badge:`${s.snapshot.users.length} users`}),e.jsx(he,{}),e.jsx(Fe,{open:m,onOpenChange:d,user:n,grants:(t==null?void 0:t.grants)??[],ownership:n?o.get(n.id)??null:null,xp:n?x.get(n.id)??null:null,pending:c.isPending,onSubmit:async r=>{await c.mutateAsync(r)},onOpenRelationship:r=>{d(!1),p(r),w(!0)}}),e.jsx($e,{open:v,onOpenChange:w,grant:N,grants:(t==null?void 0:t.grants)??[],pending:h.isPending,onSubmit:async r=>{await h.mutateAsync({grantId:r.grantId,patch:r.patch}),r.applyToReverse&&r.reverseGrantId&&await h.mutateAsync({grantId:r.reverseGrantId,patch:r.patch})}}),e.jsxs(F,{className:"grid gap-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:U,children:"Multi-user posture"}),e.jsx("div",{className:`mt-2 ${M}`,children:(t==null?void 0:t.posture.summary)??"Forge is preparing modular user access while keeping the current posture permissive."})]}),e.jsx(b,{tone:"meta",children:(t==null?void 0:t.posture.accessModel)??"permissive"})]}),e.jsx("div",{className:`flex items-center gap-3 ${R} px-4 py-3`,children:e.jsx(T,{value:f,onChange:r=>y(r.target.value),placeholder:"Search human, bot, @handle, or description"})})]}),e.jsxs("div",{className:"grid gap-5",children:[e.jsxs("div",{className:"grid gap-5",children:[e.jsxs(F,{className:"grid gap-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:U,children:"Multi-agent onboarding"}),e.jsx("div",{className:`mt-2 ${M}`,children:"Forge now treats the users graph as the collaboration control plane. Create each human or bot here, keep the runtime shared, then narrow only the specific arrows that should stop seeing, coordinating, planning, or affecting another user."})]}),e.jsx(b,{tone:"meta",children:"default open"})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsxs("div",{className:`${R} px-4 py-3`,children:[e.jsx("div",{className:U,children:"Directional edges"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:L.totalEdges})]}),e.jsxs("div",{className:`${R} px-4 py-3`,children:[e.jsx("div",{className:U,children:"Fully open"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:L.fullyOpenEdges})]}),e.jsxs("div",{className:`${R} px-4 py-3`,children:[e.jsx("div",{className:U,children:"Coordination"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:L.coordinationEdges})]}),e.jsxs("div",{className:`${R} px-4 py-3`,children:[e.jsx("div",{className:U,children:"Execution control"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:L.executionEdges})]})]}),e.jsxs("div",{className:`grid gap-2 ${M}`,children:[e.jsx("div",{children:"1. Create the human and bot users that should exist in the shared Forge system."}),e.jsx("div",{children:"2. Point OpenClaw, Hermes, and the browser at the same Forge runtime and storage root."}),e.jsx("div",{children:"3. Use the graph below to decide what each direction can see, message, plan, or change."}),e.jsx("div",{children:"4. Keep strategy drafting open while the plan is negotiated, then lock the strategy once it becomes the contract."})]})]}),e.jsx(Me,{users:(t==null?void 0:t.users)??s.snapshot.users,grants:(t==null?void 0:t.grants)??[],selectedGrantId:oe,selectedUserId:le,onOpenUser:r=>{const l=((t==null?void 0:t.users)??s.snapshot.users).find(j=>j.id===r)??null;p(null),i(l),d(!0)},onOpenGrant:r=>{i(null),p(r),w(!0)}}),e.jsxs(F,{className:"grid gap-3",children:[e.jsx("div",{className:U,children:"Agent onboarding"}),e.jsx("div",{className:M,children:"OpenClaw, Hermes, and the Forge UI all read this same multi-user graph. Keep the defaults open while you are still wiring collaboration, then narrow specific arrows when one user or agent should stop seeing, messaging, planning, or changing another user's work."}),e.jsx("div",{className:M,children:"Forge now treats every owner as either human or bot, keeps search cross-user by default, and allows cross-owner links plus explicit coordination lanes between projects, tasks, notes, and strategies."}),e.jsx("div",{children:e.jsx(ce,{to:"/settings/agents",className:"inline-flex min-h-10 items-center justify-center rounded-[var(--radius-control)] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-3 py-2 text-[13px] font-medium text-[var(--ui-ink-strong)] transition hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-hover)]",children:"Open agent onboarding"})})]})]}),e.jsx(F,{children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:U,children:"User directory"}),e.jsx("div",{className:`mt-2 ${M}`,children:"Open any user to edit its identity and jump into the exact directional relationship lanes from the user settings flow."})]}),e.jsx(J,{onClick:()=>{p(null),i(null),d(!0)},children:"Create user"})]})}),e.jsx("div",{className:"grid gap-5",children:[{title:"Human users",users:V.humans},{title:"Bot users",users:V.bots}].map(r=>e.jsxs(F,{children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:U,children:r.title}),e.jsx(b,{tone:"meta",children:r.users.length})]}),e.jsx("div",{className:"mt-4 grid gap-3",children:r.users.map(l=>{var j,W,z,K,Q,q;return e.jsx("div",{className:`${R} px-4 py-4`,children:e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx(E,{user:l}),e.jsxs("div",{className:"mt-3 text-sm text-[var(--ui-ink-soft)]",children:["@",l.handle]}),e.jsx("div",{className:`mt-2 ${M}`,children:l.description||"No description yet."}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsxs(b,{className:"bg-[var(--primary)]/14 text-[var(--primary)]",children:[((j=x.get(l.id))==null?void 0:j.totalXp)??0," XP"]}),e.jsxs(b,{tone:"meta",children:[((W=x.get(l.id))==null?void 0:W.weeklyXp)??0," weekly"]}),e.jsxs(b,{tone:"meta",children:[((z=x.get(l.id))==null?void 0:z.rewardEventCount)??0," ","rewards"]}),Object.entries(((K=o.get(l.id))==null?void 0:K.entityCounts)??{}).sort((I,D)=>D[1]-I[1]).slice(0,4).map(([I,D])=>e.jsxs(b,{tone:"meta",children:[D," ",I]},`${l.id}-${I}`)),e.jsxs(b,{tone:"meta",children:[((Q=o.get(l.id))==null?void 0:Q.totalOwnedEntities)??0," ","owned"]})]}),e.jsxs("div",{className:`mt-3 ${te}`,children:["Can currently read:"," ",(k.get(l.id)??[]).map(I=>`${I.displayName} (${I.kind})`).join(", ")||"no other users"]}),(q=x.get(l.id))!=null&&q.lastRewardAt?e.jsxs("div",{className:`mt-2 ${te}`,children:["Last XP movement:"," ",new Date(x.get(l.id).lastRewardAt).toLocaleString()]}):null]}),e.jsx("div",{className:"flex gap-2",children:e.jsx(J,{variant:"secondary",onClick:()=>{p(null),i(l),d(!0)},children:"Open settings"})})]})},l.id)})})]},r.title))})]})]})}export{We as SettingsUsersPage};
|
|
1
|
+
import{r as g,j as e,aC as ce}from"./vendor-Dnkkx2co.js";import{i as de,k as Z}from"./state-vCcAT5Hq.js";import{S as he}from"./settings-section-nav-Co0AaDG-.js";import{P as ue}from"./page-hero-CONuJu5J.js";import{i as pe,C as ge,B as me,M as xe}from"./graph-DDUZNRsO.js";import{C as F,aq as fe,c as b,U as E,Q as ie,F as $,j as H,I as T,T as be,W as ve,u as je,eu as we,ev as ye,ew as Ne,B as J,ex as ke}from"./index-QJkjKYzZ.js";import"./motion-Lt5B1XuE.js";import"./ui-C1iwpj2-.js";import"./forms-hB0SqEh-.js";import"./board-dIX6etHh.js";const ae=[{id:"visibility",label:"Discovery and visibility",description:"What the source user can discover, inspect, and pull into read flows on the target side.",rights:[{key:"discoverable",label:"Discoverable",description:"The target appears as a reachable collaborator in the source user's graph and pickers."},{key:"canListUsers",label:"List users",description:"The source user can include the target in directory, comparison, and routing surfaces."},{key:"canReadProfile",label:"Read profile",description:"The source user can inspect the target's identity card, handle, type, and description."},{key:"canReadEntities",label:"Read entities",description:"The source user can read the target's goals, projects, tasks, notes, strategies, and related records."},{key:"canSearchEntities",label:"Search entities",description:"The source user can find the target's work through Forge search and entity pickers."}]},{id:"coordination",label:"Messaging, context, and handoff",description:"What the source user can message, connect, and coordinate on the target side before changing execution.",rights:[{key:"canLinkEntities",label:"Share context",description:"The source user can attach the target's records into shared notes, strategies, calendar context, and cross-owner plans."},{key:"canCoordinate",label:"Message and coordinate",description:"The source user can communicate with the target through Forge, hand off work, and coordinate execution."},{key:"canViewMetrics",label:"View metrics",description:"The source user can inspect the target's XP, alignment, and progress metrics."},{key:"canViewActivity",label:"View activity",description:"The source user can inspect the target's activity stream, evidence, and execution trail."}]},{id:"execution",label:"Plan and execution control",description:"What the source user can actually change on the target side once collaboration is trusted.",rights:[{key:"canManageStrategies",label:"Manage strategies",description:"The source user can draft and update strategies that belong to the target."},{key:"canCreateOnBehalf",label:"Create on behalf",description:"The source user can intentionally create new target-owned entities."},{key:"canAffectEntities",label:"Affect entities",description:"The source user can mutate work that belongs to the target."}]}],Ce=[{id:"full_collab",label:"Full collaboration",description:"Use when two humans or agents can see, coordinate, plan, and change each other's work.",rights:{discoverable:!0,canListUsers:!0,canReadProfile:!0,canReadEntities:!0,canSearchEntities:!0,canLinkEntities:!0,canCoordinate:!0,canAffectEntities:!0,canManageStrategies:!0,canCreateOnBehalf:!0,canViewMetrics:!0,canViewActivity:!0}},{id:"coordination_only",label:"Coordinate only",description:"Use when the source user may see and coordinate with the target but should not directly mutate target-owned work.",rights:{discoverable:!0,canListUsers:!0,canReadProfile:!0,canReadEntities:!0,canSearchEntities:!0,canLinkEntities:!0,canCoordinate:!0,canAffectEntities:!1,canManageStrategies:!0,canCreateOnBehalf:!1,canViewMetrics:!0,canViewActivity:!0}},{id:"observe_only",label:"Observe only",description:"Use when the source user should keep visibility into the target without planning or execution control.",rights:{discoverable:!0,canListUsers:!0,canReadProfile:!0,canReadEntities:!0,canSearchEntities:!0,canLinkEntities:!1,canCoordinate:!1,canAffectEntities:!1,canManageStrategies:!1,canCreateOnBehalf:!1,canViewMetrics:!0,canViewActivity:!0}},{id:"hidden",label:"Hidden edge",description:"Use when this direction should stop discovering, reading, or acting on the target.",rights:{discoverable:!1,canListUsers:!1,canReadProfile:!1,canReadEntities:!1,canSearchEntities:!1,canLinkEntities:!1,canCoordinate:!1,canAffectEntities:!1,canManageStrategies:!1,canCreateOnBehalf:!1,canViewMetrics:!1,canViewActivity:!1}}],A=ae.reduce((s,n)=>s+n.rights.length,0);function P(s){return Object.values(s.config.rights).filter(Boolean).length}function re(s){const n=[];return s.config.rights.canReadEntities&&n.push("See"),s.config.rights.canCoordinate&&n.push("Message"),s.config.rights.canManageStrategies&&n.push("Plan"),s.config.rights.canAffectEntities&&n.push("Affect"),n.join(" · ")||"Hidden"}function Ue(s){return!s.config.rights.discoverable&&!s.config.rights.canReadEntities?"Hidden":s.config.rights.canAffectEntities&&s.config.rights.canManageStrategies?"Trusted":s.config.rights.canCoordinate||s.config.rights.canLinkEntities?"Coordinated":"Observed"}function ne(s){return[{id:"see",label:"See",enabled:s.config.rights.discoverable&&s.config.rights.canReadEntities&&s.config.rights.canSearchEntities},{id:"message",label:"Message",enabled:s.config.rights.canCoordinate},{id:"share",label:"Share context",enabled:s.config.rights.canLinkEntities},{id:"plan",label:"Plan",enabled:s.config.rights.canManageStrategies},{id:"affect",label:"Affect",enabled:s.config.rights.canAffectEntities||s.config.rights.canCreateOnBehalf}]}function Ee(s,n){return Object.entries(n.rights).every(([i,u])=>s.config.rights[i]===u)}function Se(s,n){const i=s.filter(a=>a.kind==="human"),u=s.filter(a=>a.kind==="bot"),p={x:560,y:360},m={width:226,height:132},d=i[0]??null,w=[...i.slice(d?1:0).map(a=>({user:a,radius:245,offset:-90})),...u.map(a=>({user:a,radius:390,offset:-90}))],f=w.length,y=[...d?[{user:d,position:{x:p.x-m.width/2,y:p.y-m.height/2}}]:[],...w.map((a,c)=>{const h=(a.offset+360/Math.max(f,1)*c)*Math.PI/180;return{user:a.user,position:{x:p.x+Math.cos(h)*a.radius-m.width/2,y:p.y+Math.sin(h)*a.radius-m.height/2}}})],C=new Set(n.selectedGrant?[n.selectedGrant.subjectUserId,n.selectedGrant.targetUserId]:n.selectedUserId?[n.selectedUserId]:[]);return y.map(({user:a,position:c})=>{const h=C.has(a.id),t=a.id===n.selectedUserId;return{id:a.id,position:c,draggable:!1,selectable:!1,data:{label:e.jsxs("div",{className:`min-w-[206px] rounded-[22px] border px-4 py-4 shadow-[var(--ui-shadow-soft)] transition ${t?"border-[color-mix(in_srgb,var(--warning)_45%,var(--ui-border-subtle)_55%)] bg-[var(--ui-warning-soft)]":h?"border-[color-mix(in_srgb,var(--primary)_28%,var(--ui-border-subtle)_72%)] bg-[var(--ui-accent-soft)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)]"}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx(E,{user:a}),e.jsx(b,{tone:"meta",children:a.kind})]}),e.jsxs("div",{className:"mt-3 text-xs text-[var(--ui-ink-soft)]",children:["@",a.handle]}),e.jsx("div",{className:"mt-2 line-clamp-2 text-xs leading-5 text-[var(--ui-ink-faint)]",children:a.description||"No user description yet."})]})},style:{background:"transparent",border:"none",padding:0}}})}function Ie(s,n,i){return s.filter(u=>u.subjectUserId!==u.targetUserId).map(u=>{const p=n===u.id,m=i!==null&&(u.subjectUserId===i||u.targetUserId===i),d=P(u),v=p?"var(--warning)":!u.config.rights.discoverable&&!u.config.rights.canReadEntities?"var(--danger)":m?"var(--primary)":"var(--ui-border-strong)";return{id:u.id,source:u.subjectUserId,target:u.targetUserId,label:`${re(u)} · ${d}/${A}`,markerEnd:{type:xe.ArrowClosed,color:v},labelStyle:{fill:p?"var(--warning)":"var(--ui-ink-medium)",fontSize:11,fontWeight:600},labelBgStyle:{fill:p?"var(--ui-warning-soft)":"var(--ui-surface-1)",stroke:p?"color-mix(in_srgb,var(--warning)_36%,var(--ui-border-subtle)_64%)":"var(--ui-border-subtle)",strokeWidth:1},labelBgPadding:[7,5],labelBgBorderRadius:8,style:{stroke:v,strokeWidth:p?2.5:m?1.8:1.25},animated:p}})}function Me({users:s,grants:n,selectedGrantId:i=null,selectedUserId:u=null,onOpenGrant:p,onOpenUser:m}){const d=n.find(c=>c.id===i)??null,v=g.useMemo(()=>Se(s,{selectedUserId:u,selectedGrant:d}),[d,u,s]),w=g.useMemo(()=>Ie(n,i,u),[n,i,u]),f=g.useMemo(()=>n.filter(c=>c.subjectUserId!==c.targetUserId),[n]),y=f.filter(c=>P(c)===A).length,C=f.filter(c=>c.config.rights.canCoordinate).length,a=f.filter(c=>c.config.rights.canAffectEntities||c.config.rights.canCreateOnBehalf).length;return e.jsxs(F,{className:"overflow-hidden p-0",children:[e.jsxs("div",{className:"grid gap-4 border-b border-[var(--ui-border-subtle)] px-5 py-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"max-w-3xl",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Directed relationship graph"}),e.jsx(fe,{content:"Keep Forge, OpenClaw, Hermes, and the browser on the same runtime and storage root when these arrows should describe one shared human and bot system.",label:"Explain the shared runtime rule"})]}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Click a user card to open that user's settings. Click any arrow to open the exact directional relationship flow for that lane."})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(b,{tone:"meta",children:[f.length," edges"]}),e.jsxs(b,{className:"bg-[var(--ui-success-soft)] text-[var(--success)]",children:[y," fully open"]})]})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-3",children:[e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Full collaboration"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:y}),e.jsx("div",{className:"text-xs leading-5 text-[var(--ui-ink-faint)]",children:"Directions still running with the default fully open posture."})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Coordination lanes"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:C}),e.jsx("div",{className:"text-xs leading-5 text-[var(--ui-ink-faint)]",children:"Directions allowed to coordinate directly through Forge."})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Execution control"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:a}),e.jsx("div",{className:"text-xs leading-5 text-[var(--ui-ink-faint)]",children:"Directions allowed to create or mutate target-owned work."})]})]})]}),e.jsx("div",{className:"h-[clamp(26rem,58vh,42rem)] bg-[linear-gradient(180deg,var(--ui-surface-2),var(--ui-surface-1))] sm:h-[min(72vh,54rem)] sm:min-h-[34rem]",children:e.jsxs(pe,{className:"user-relationship-flow",nodes:v,edges:w,fitView:!0,fitViewOptions:{padding:.1,maxZoom:.95},nodesDraggable:!1,nodesConnectable:!1,elementsSelectable:!0,onNodeClick:(c,h)=>{m(h.id)},onEdgeClick:(c,h)=>{p(h.id)},attributionPosition:"bottom-left",children:[e.jsx(ge,{showInteractive:!1}),e.jsx(me,{gap:28,size:1,color:"var(--ui-border-subtle)"})]})})]})}const O="rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",Y="text-sm font-medium text-[var(--ui-ink-strong)]",Oe="text-sm leading-6 text-[var(--ui-ink-soft)]",Re={kind:"human",handle:"",displayName:"",description:"",accentColor:"#c0c1ff"};function ee(s){return s?{kind:s.kind,handle:s.handle,displayName:s.displayName,description:s.description,accentColor:s.accentColor}:Re}function Fe({open:s,onOpenChange:n,user:i,grants:u,ownership:p,xp:m,pending:d=!1,onSubmit:v,onOpenRelationship:w}){const[f,y]=g.useState(()=>ee(i)),[C,a]=g.useState(null);g.useEffect(()=>{s&&(y(ee(i)),a(null))},[s,i]);const c=g.useMemo(()=>u.filter(o=>o.subjectUserId!==o.targetUserId),[u]),h=g.useMemo(()=>i?c.filter(o=>o.subjectUserId===i.id):[],[c,i]),t=g.useMemo(()=>i?c.filter(o=>o.targetUserId===i.id):[],[c,i]),N=[{id:"identity",eyebrow:i?"Edit user":"Create user",title:i?"Update the user identity":"Add a human or bot user",description:"Set the owner type and the public identity Forge will use across ownership, routing, and collaboration surfaces.",render:(o,x)=>e.jsxs(e.Fragment,{children:[e.jsx($,{label:"Kind",description:"Humans represent real people. Bots represent agents or automations with their own ownership lane.",children:e.jsx(H,{columns:2,value:o.kind,onChange:k=>x({kind:k}),options:[{value:"human",label:"Human",description:"Use for a real person in the Forge runtime."},{value:"bot",label:"Bot",description:"Use for an agent, assistant, or automation actor."}]})}),e.jsx($,{label:"Handle",description:"This becomes the stable short id shown as @handle.",hint:"Use lowercase and a durable label, for example forge-operator or planner-bot.",children:e.jsx(T,{value:o.handle,onChange:k=>x({handle:k.target.value}),placeholder:"forge-operator"})}),e.jsx($,{label:"Display name",description:"This is the human-readable label used across the UI.",children:e.jsx(T,{value:o.displayName,onChange:k=>x({displayName:k.target.value}),placeholder:"Forge Operator"})})]})},{id:"profile",eyebrow:"Profile",title:"Describe the user lane",description:"Capture what this user represents in the shared Forge runtime and pick the accent color that helps the lane stay recognizable.",render:(o,x)=>e.jsxs(e.Fragment,{children:[e.jsx($,{label:"Description",description:"Explain what this user is responsible for and what side of the system it represents.",children:e.jsx(be,{value:o.description,onChange:k=>x({description:k.target.value}),className:"min-h-36",placeholder:"Primary human operator for strategy, execution, and review."})}),e.jsx($,{label:"Accent color",description:"Forge uses this accent to help the user stand out in ownership and collaboration surfaces.",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(T,{value:o.accentColor,onChange:k=>x({accentColor:k.target.value}),placeholder:"#c0c1ff"}),e.jsx("div",{className:"size-10 shrink-0 rounded-full border border-[var(--ui-border-subtle)]",style:{backgroundColor:o.accentColor||"#c0c1ff"}})]})}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[e.jsxs("div",{className:`${O} px-4 py-3`,children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Owned records"}),e.jsx("div",{className:"mt-2 text-[var(--ui-ink-strong)]",children:(p==null?void 0:p.totalOwnedEntities)??0})]}),e.jsxs("div",{className:`${O} px-4 py-3`,children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Total XP"}),e.jsx("div",{className:"mt-2 text-[var(--ui-ink-strong)]",children:(m==null?void 0:m.totalXp)??0})]}),e.jsxs("div",{className:`${O} px-4 py-3`,children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Weekly XP"}),e.jsx("div",{className:"mt-2 text-[var(--ui-ink-strong)]",children:(m==null?void 0:m.weeklyXp)??0})]})]})]})},{id:"relationships",eyebrow:"Relationships",title:"Open directional relationship settings",description:"Each arrow is a separate contract. Open the exact lane you want to adjust and Forge will take you into the relationship flow.",render:()=>i?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`${O} p-4`,children:[e.jsx(E,{user:i}),e.jsxs("div",{className:`mt-3 ${Oe}`,children:["@",i.handle," · ",i.description||"No description yet."]})]}),e.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:Y,children:"Outbound lanes"}),h.length>0?h.map(o=>e.jsxs("button",{type:"button",className:`${O} px-4 py-4 text-left transition hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-hover)]`,onClick:()=>w(o.id),children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(E,{user:o.subjectUser}),e.jsx("span",{className:"text-[var(--ui-ink-faint)]",children:"→"}),e.jsx(E,{user:o.targetUser})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx(b,{tone:"meta",children:re(o)}),e.jsxs(b,{tone:"meta",children:[P(o),"/",A," rights"]})]})]},o.id)):e.jsx("div",{className:"rounded-[20px] border border-dashed border-[var(--ui-border-subtle)] px-4 py-4 text-sm text-[var(--ui-ink-soft)]",children:"No outbound relationship lanes yet."})]}),e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:Y,children:"Inbound lanes"}),t.length>0?t.map(o=>e.jsxs("button",{type:"button",className:`${O} px-4 py-4 text-left transition hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-hover)]`,onClick:()=>w(o.id),children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(E,{user:o.subjectUser}),e.jsx("span",{className:"text-[var(--ui-ink-faint)]",children:"→"}),e.jsx(E,{user:o.targetUser})]}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:ne(o).map(x=>e.jsx(b,{className:x.enabled?"bg-[var(--ui-surface-1)] text-[var(--ui-ink-medium)]":"bg-[var(--ui-surface-1)] text-[var(--ui-ink-faint)] opacity-70",children:x.label},`${o.id}-${x.id}`))})]},o.id)):e.jsx("div",{className:"rounded-[20px] border border-dashed border-[var(--ui-border-subtle)] px-4 py-4 text-sm text-[var(--ui-ink-soft)]",children:"No inbound relationship lanes yet."})]})]})]}):e.jsx("div",{className:"rounded-[20px] border border-dashed border-[var(--ui-border-subtle)] px-4 py-4 text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Create the user first, then Forge will generate the directional relationship lanes you can tune from here."})}];return e.jsx(ie,{open:s,onOpenChange:n,eyebrow:i?"User settings":"Create user",title:i?"User settings":"Create user",description:"Edit the user identity, clarify what this lane represents, and jump into relationship settings without crowding the page.",value:f,onChange:y,draftPersistenceKey:i?`users.settings.${i.id}`:"users.settings.new",steps:N,submitLabel:i?"Save user":"Create user",pending:d,pendingLabel:i?"Saving user":"Creating user",error:C,contentClassName:"lg:w-[min(58rem,calc(100vw-1.5rem))]",onSubmit:async()=>{const o=f.handle.trim(),x=f.displayName.trim();if(o.length===0){a("Add a handle before saving this user.");return}if(x.length===0){a("Add a display name before saving this user.");return}await v({userId:i==null?void 0:i.id,input:{kind:f.kind,handle:o,displayName:x,description:f.description.trim(),accentColor:f.accentColor.trim()||"#c0c1ff"}}),n(!1)}})}const _="rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",S="text-sm font-medium text-[var(--ui-ink-strong)]",G="text-sm leading-6 text-[var(--ui-ink-soft)]",Ae="text-xs leading-5 text-[var(--ui-ink-faint)]";function se(s,n){return{accessLevel:(s==null?void 0:s.accessLevel)??"manage",applyScope:"this_arrow",rights:{discoverable:(s==null?void 0:s.config.rights.discoverable)??!0,canListUsers:(s==null?void 0:s.config.rights.canListUsers)??!0,canReadProfile:(s==null?void 0:s.config.rights.canReadProfile)??!0,canReadEntities:(s==null?void 0:s.config.rights.canReadEntities)??!0,canSearchEntities:(s==null?void 0:s.config.rights.canSearchEntities)??!0,canLinkEntities:(s==null?void 0:s.config.rights.canLinkEntities)??!0,canCoordinate:(s==null?void 0:s.config.rights.canCoordinate)??!0,canAffectEntities:(s==null?void 0:s.config.rights.canAffectEntities)??!0,canManageStrategies:(s==null?void 0:s.config.rights.canManageStrategies)??!0,canCreateOnBehalf:(s==null?void 0:s.config.rights.canCreateOnBehalf)??!0,canViewMetrics:(s==null?void 0:s.config.rights.canViewMetrics)??!0,canViewActivity:(s==null?void 0:s.config.rights.canViewActivity)??!0}}}function $e({open:s,onOpenChange:n,grant:i,grants:u,pending:p=!1,onSubmit:m}){const d=g.useMemo(()=>i?u.find(a=>a.subjectUserId===i.targetUserId&&a.targetUserId===i.subjectUserId)??null:null,[i,u]),[v,w]=g.useState(()=>se(i,!!d));g.useEffect(()=>{s&&w(se(i,!!d))},[i,s,d]);const f=g.useMemo(()=>Object.values(v.rights).filter(Boolean).length,[v.rights]),y=Math.round(f/A*100),C=[{id:"posture",eyebrow:"Relationship posture",title:"Set the trust mode for this arrow",description:"Each arrow is directional. Decide whether you want to tune only this lane or mirror the same contract onto both directions.",render:(a,c)=>e.jsxs(e.Fragment,{children:[i?e.jsxs("div",{className:`${_} p-4`,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(E,{user:i.subjectUser}),e.jsx("span",{className:"text-[var(--ui-ink-faint)]",children:"→"}),e.jsx(E,{user:i.targetUser})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx(b,{tone:"meta",children:Ue(i)}),e.jsxs(b,{tone:"meta",children:[P(i),"/",A," rights"]})]})]}):null,e.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:S,children:"Access level"}),e.jsx(H,{columns:2,value:a.accessLevel,onChange:h=>c({accessLevel:h}),options:[{value:"view",label:"View",description:"Use when this lane should stay mostly observational."},{value:"manage",label:"Manage",description:"Use when the source side can actively collaborate or act."}]})]}),d?e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:S,children:"Apply scope"}),e.jsx(H,{columns:2,value:a.applyScope,onChange:h=>c({applyScope:h}),options:[{value:"this_arrow",label:"This arrow",description:"Only change the exact direction you opened."},{value:"both_arrows",label:"Both arrows",description:"Mirror the same contract onto the reverse direction too."}]})]}):null]}),e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:S,children:"Quick preset"}),e.jsx("div",{className:"grid gap-3 md:grid-cols-2",children:Ce.map(h=>e.jsxs("button",{type:"button",className:`rounded-[22px] border p-4 text-left transition ${i&&Ee(i,h)?"border-[color-mix(in_srgb,var(--warning)_32%,var(--ui-border-subtle)_68%)] bg-[var(--ui-warning-soft)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-hover)]"}`,onClick:()=>c({rights:{...a.rights,...h.rights}}),children:[e.jsx("div",{className:S,children:h.label}),e.jsx("div",{className:`mt-2 ${G}`,children:h.description})]},h.id))})]})]})},{id:"rights",eyebrow:"Rights",title:"Tune the individual permissions",description:"Use the preset as the starting point, then sharpen the exact boundaries only where this relationship needs them.",render:(a,c)=>e.jsx(e.Fragment,{children:ae.map(h=>e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:S,children:h.label}),e.jsx("div",{className:`mt-1 ${G}`,children:h.description})]}),e.jsx("div",{className:"grid gap-2",children:h.rights.map(t=>e.jsxs("label",{className:"flex items-start justify-between gap-3 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:S,children:t.label}),e.jsx("div",{className:`mt-1 ${Ae}`,children:t.description})]}),e.jsx("input",{type:"checkbox",checked:a.rights[t.key],onChange:N=>c({rights:{...a.rights,[t.key]:N.target.checked}})})]},t.key))})]},h.id))})},{id:"review",eyebrow:"Review",title:"Review the final relationship contract",description:"Check the enabled capabilities, confirm whether both directions should match, and then save the relationship.",render:a=>{var c,h;return e.jsx(e.Fragment,{children:e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsxs("div",{className:`${_} p-4`,children:[e.jsx("div",{className:S,children:"Capability coverage"}),e.jsx("div",{className:"mt-4",children:e.jsx(ve,{value:y})}),e.jsxs("div",{className:"mt-3 text-sm text-[var(--ui-ink-soft)]",children:[f,"/",A," rights enabled"]}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:ne({...i??{id:"draft",subjectUserId:"",targetUserId:"",accessLevel:a.accessLevel,config:{self:!1,mutable:!0,linkedEntities:!0,rights:a.rights},createdAt:"",updatedAt:"",subjectUser:null,targetUser:null},accessLevel:a.accessLevel,config:{...(i==null?void 0:i.config)??{self:!1,mutable:!0,linkedEntities:!0},rights:a.rights}}).map(t=>e.jsx(b,{className:t.enabled?"bg-[var(--ui-surface-1)] text-[var(--ui-ink-medium)]":"bg-[var(--ui-surface-1)] text-[var(--ui-ink-faint)] opacity-70",children:t.label},t.id))})]}),e.jsxs("div",{className:`${_} p-4`,children:[e.jsx("div",{className:S,children:"Save scope"}),e.jsx("div",{className:`mt-3 ${G}`,children:a.applyScope==="both_arrows"&&d?"Forge will apply the same access level and rights to both directions of this pair.":"Forge will only update the exact arrow you opened."}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsxs(b,{tone:"meta",children:["access ",a.accessLevel]}),e.jsxs(b,{tone:"meta",children:["scope"," ",a.applyScope==="both_arrows"&&d?"both arrows":"this arrow"]})]}),d?e.jsxs("div",{className:"mt-4 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-3 text-sm text-[var(--ui-ink-soft)]",children:["Reverse arrow available:"," ",((c=d.subjectUser)==null?void 0:c.displayName)??d.subjectUserId," ","→"," ",((h=d.targetUser)==null?void 0:h.displayName)??d.targetUserId]}):null]})]})})}}];return e.jsx(ie,{open:s,onOpenChange:n,eyebrow:"Relationship settings",title:"Relationship settings",description:"Edit the exact directional contract between two users without keeping the full rights editor pinned on the page.",value:v,onChange:w,draftPersistenceKey:i?`users.relationship.${i.id}`:"users.relationship.new",steps:C,submitLabel:"Save relationship",pending:p,pendingLabel:"Saving relationship",contentClassName:"lg:w-[min(62rem,calc(100vw-1.5rem))]",onSubmit:async()=>{i&&(await m({grantId:i.id,patch:{accessLevel:v.accessLevel,rights:v.rights},reverseGrantId:(d==null?void 0:d.id)??null,applyToReverse:v.applyScope==="both_arrows"&&d!==null}),n(!1))}})}const U="font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",M="text-sm leading-6 text-[var(--ui-ink-soft)]",te="text-xs leading-5 text-[var(--ui-ink-faint)]",R="rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]";function We(){var X;const s=je(),[n,i]=g.useState(null),[u,p]=g.useState(null),[m,d]=g.useState(!1),[v,w]=g.useState(!1),[f,y]=g.useState(""),C=de({queryKey:["forge-user-directory"],queryFn:ke}),a=async()=>{await Promise.all([s.refresh(),C.refetch()])},c=Z({mutationFn:async({input:r,userId:l})=>l?(await we(l,r)).user:(await ye(r)).user,onSuccess:async()=>{i(null),d(!1),await a()}}),h=Z({mutationFn:async({grantId:r,patch:l})=>(await Ne(r,l)).grant,onSuccess:a}),t=(X=C.data)==null?void 0:X.directory,N=(t==null?void 0:t.grants.find(r=>r.id===u))??null,o=g.useMemo(()=>new Map(((t==null?void 0:t.ownership)??[]).map(r=>[r.userId,r])),[t==null?void 0:t.ownership]),x=g.useMemo(()=>new Map(((t==null?void 0:t.xp)??[]).map(r=>[r.userId,r])),[t==null?void 0:t.xp]),k=g.useMemo(()=>{const r=new Map;for(const l of(t==null?void 0:t.grants)??[]){if(!l.targetUser||l.subjectUserId===l.targetUserId)continue;const j=r.get(l.subjectUserId)??[];j.push(l.targetUser),r.set(l.subjectUserId,j)}return r},[t==null?void 0:t.grants]),L=g.useMemo(()=>{const r=((t==null?void 0:t.grants)??[]).filter(l=>l.subjectUserId!==l.targetUserId);return{totalEdges:r.length,fullyOpenEdges:r.filter(l=>Object.values(l.config.rights).every(Boolean)).length,coordinationEdges:r.filter(l=>l.config.rights.canCoordinate).length,executionEdges:r.filter(l=>l.config.rights.canAffectEntities||l.config.rights.canCreateOnBehalf).length}},[t==null?void 0:t.grants]),B=f.trim().toLowerCase(),V=g.useMemo(()=>{const l=((t==null?void 0:t.users)??s.snapshot.users).filter(j=>B?[j.displayName,j.handle,j.kind,j.description].join(" ").toLowerCase().includes(B):!0);return{humans:l.filter(j=>j.kind==="human"),bots:l.filter(j=>j.kind==="bot")}},[t==null?void 0:t.users,B,s.snapshot.users]),le=(N==null?void 0:N.subjectUserId)??(n==null?void 0:n.id)??null,oe=(N==null?void 0:N.id)??null;return e.jsxs("div",{className:"mx-auto grid w-full max-w-[1440px] gap-5",children:[e.jsx(ue,{title:"Users",description:"Forge users can be human or bot. Ownership, search, and routing are prepared so work can move across both sides of the system.",badge:`${s.snapshot.users.length} users`}),e.jsx(he,{}),e.jsx(Fe,{open:m,onOpenChange:d,user:n,grants:(t==null?void 0:t.grants)??[],ownership:n?o.get(n.id)??null:null,xp:n?x.get(n.id)??null:null,pending:c.isPending,onSubmit:async r=>{await c.mutateAsync(r)},onOpenRelationship:r=>{d(!1),p(r),w(!0)}}),e.jsx($e,{open:v,onOpenChange:w,grant:N,grants:(t==null?void 0:t.grants)??[],pending:h.isPending,onSubmit:async r=>{await h.mutateAsync({grantId:r.grantId,patch:r.patch}),r.applyToReverse&&r.reverseGrantId&&await h.mutateAsync({grantId:r.reverseGrantId,patch:r.patch})}}),e.jsxs(F,{className:"grid gap-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:U,children:"Multi-user posture"}),e.jsx("div",{className:`mt-2 ${M}`,children:(t==null?void 0:t.posture.summary)??"Forge is preparing modular user access while keeping the current posture permissive."})]}),e.jsx(b,{tone:"meta",children:(t==null?void 0:t.posture.accessModel)??"permissive"})]}),e.jsx("div",{className:`flex items-center gap-3 ${R} px-4 py-3`,children:e.jsx(T,{value:f,onChange:r=>y(r.target.value),placeholder:"Search human, bot, @handle, or description"})})]}),e.jsxs("div",{className:"grid gap-5",children:[e.jsxs("div",{className:"grid gap-5",children:[e.jsxs(F,{className:"grid gap-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:U,children:"Multi-agent onboarding"}),e.jsx("div",{className:`mt-2 ${M}`,children:"Forge now treats the users graph as the collaboration control plane. Create each human or bot here, keep the runtime shared, then narrow only the specific arrows that should stop seeing, coordinating, planning, or affecting another user."})]}),e.jsx(b,{tone:"meta",children:"default open"})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsxs("div",{className:`${R} px-4 py-3`,children:[e.jsx("div",{className:U,children:"Directional edges"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:L.totalEdges})]}),e.jsxs("div",{className:`${R} px-4 py-3`,children:[e.jsx("div",{className:U,children:"Fully open"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:L.fullyOpenEdges})]}),e.jsxs("div",{className:`${R} px-4 py-3`,children:[e.jsx("div",{className:U,children:"Coordination"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:L.coordinationEdges})]}),e.jsxs("div",{className:`${R} px-4 py-3`,children:[e.jsx("div",{className:U,children:"Execution control"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:L.executionEdges})]})]}),e.jsxs("div",{className:`grid gap-2 ${M}`,children:[e.jsx("div",{children:"1. Create the human and bot users that should exist in the shared Forge system."}),e.jsx("div",{children:"2. Point OpenClaw, Hermes, and the browser at the same Forge runtime and storage root."}),e.jsx("div",{children:"3. Use the graph below to decide what each direction can see, message, plan, or change."}),e.jsx("div",{children:"4. Keep strategy drafting open while the plan is negotiated, then lock the strategy once it becomes the contract."})]})]}),e.jsx(Me,{users:(t==null?void 0:t.users)??s.snapshot.users,grants:(t==null?void 0:t.grants)??[],selectedGrantId:oe,selectedUserId:le,onOpenUser:r=>{const l=((t==null?void 0:t.users)??s.snapshot.users).find(j=>j.id===r)??null;p(null),i(l),d(!0)},onOpenGrant:r=>{i(null),p(r),w(!0)}}),e.jsxs(F,{className:"grid gap-3",children:[e.jsx("div",{className:U,children:"Agent onboarding"}),e.jsx("div",{className:M,children:"OpenClaw, Hermes, and the Forge UI all read this same multi-user graph. Keep the defaults open while you are still wiring collaboration, then narrow specific arrows when one user or agent should stop seeing, messaging, planning, or changing another user's work."}),e.jsx("div",{className:M,children:"Forge now treats every owner as either human or bot, keeps search cross-user by default, and allows cross-owner links plus explicit coordination lanes between projects, tasks, notes, and strategies."}),e.jsx("div",{children:e.jsx(ce,{to:"/settings/agents",className:"inline-flex min-h-10 items-center justify-center rounded-[var(--radius-control)] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-3 py-2 text-[13px] font-medium text-[var(--ui-ink-strong)] transition hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-hover)]",children:"Open agent onboarding"})})]})]}),e.jsx(F,{children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:U,children:"User directory"}),e.jsx("div",{className:`mt-2 ${M}`,children:"Open any user to edit its identity and jump into the exact directional relationship lanes from the user settings flow."})]}),e.jsx(J,{onClick:()=>{p(null),i(null),d(!0)},children:"Create user"})]})}),e.jsx("div",{className:"grid gap-5",children:[{title:"Human users",users:V.humans},{title:"Bot users",users:V.bots}].map(r=>e.jsxs(F,{children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:U,children:r.title}),e.jsx(b,{tone:"meta",children:r.users.length})]}),e.jsx("div",{className:"mt-4 grid gap-3",children:r.users.map(l=>{var j,W,z,K,Q,q;return e.jsx("div",{className:`${R} px-4 py-4`,children:e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx(E,{user:l}),e.jsxs("div",{className:"mt-3 text-sm text-[var(--ui-ink-soft)]",children:["@",l.handle]}),e.jsx("div",{className:`mt-2 ${M}`,children:l.description||"No description yet."}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsxs(b,{className:"bg-[var(--primary)]/14 text-[var(--primary)]",children:[((j=x.get(l.id))==null?void 0:j.totalXp)??0," XP"]}),e.jsxs(b,{tone:"meta",children:[((W=x.get(l.id))==null?void 0:W.weeklyXp)??0," weekly"]}),e.jsxs(b,{tone:"meta",children:[((z=x.get(l.id))==null?void 0:z.rewardEventCount)??0," ","rewards"]}),Object.entries(((K=o.get(l.id))==null?void 0:K.entityCounts)??{}).sort((I,D)=>D[1]-I[1]).slice(0,4).map(([I,D])=>e.jsxs(b,{tone:"meta",children:[D," ",I]},`${l.id}-${I}`)),e.jsxs(b,{tone:"meta",children:[((Q=o.get(l.id))==null?void 0:Q.totalOwnedEntities)??0," ","owned"]})]}),e.jsxs("div",{className:`mt-3 ${te}`,children:["Can currently read:"," ",(k.get(l.id)??[]).map(I=>`${I.displayName} (${I.kind})`).join(", ")||"no other users"]}),(q=x.get(l.id))!=null&&q.lastRewardAt?e.jsxs("div",{className:`mt-2 ${te}`,children:["Last XP movement:"," ",new Date(x.get(l.id).lastRewardAt).toLocaleString()]}):null]}),e.jsx("div",{className:"flex gap-2",children:e.jsx(J,{variant:"secondary",onClick:()=>{p(null),i(l),d(!0)},children:"Open settings"})})]})},l.id)})})]},r.title))})]})]})}export{We as SettingsUsersPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as d,j as e,aC as y,bg as k,cD as W}from"./vendor-Dnkkx2co.js";import{j as K,i as L,k as l}from"./state-vCcAT5Hq.js";import{S as P}from"./settings-section-nav-
|
|
1
|
+
import{r as d,j as e,aC as y,bg as k,cD as W}from"./vendor-Dnkkx2co.js";import{j as K,i as L,k as l}from"./state-vCcAT5Hq.js";import{S as P}from"./settings-section-nav-Co0AaDG-.js";import{P as M}from"./page-hero-CONuJu5J.js";import{bV as Q,bW as $,bX as A,L as F,E as j,B as c,C as N,aq as R,I as S,bY as q}from"./index-QJkjKYzZ.js";import"./motion-Lt5B1XuE.js";import"./ui-C1iwpj2-.js";import"./forms-hB0SqEh-.js";import"./board-dIX6etHh.js";import"./graph-DDUZNRsO.js";const C="inline-flex min-h-11 max-w-full items-center justify-center rounded-[16px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-3 text-sm font-medium text-[var(--ui-ink-strong)] shadow-[var(--ui-shadow-soft)] transition hover:bg-[var(--ui-surface-hover)]",E="grid min-w-0 gap-3 rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",I="grid min-w-0 gap-1 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-4",O="min-w-0 rounded-[16px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-3 py-3 text-sm text-[var(--ui-ink-strong)] outline-none transition focus:border-[var(--primary)]/35 focus:bg-[var(--ui-surface-3)]",p="text-[var(--ui-ink-strong)]",T="text-[var(--ui-ink-soft)]",n="text-[var(--ui-ink-faint)]";function _(){var w;const t=K(),[r,g]=d.useState(""),[m,u]=d.useState(""),[x,h]=d.useState("personal"),s=L({queryKey:["forge-wiki-settings"],queryFn:q}),o=async()=>{await Promise.all([t.invalidateQueries({queryKey:["forge-wiki-settings"]}),t.invalidateQueries({queryKey:["forge-wiki-pages"]}),t.invalidateQueries({queryKey:["forge-wiki-page"]}),t.invalidateQueries({queryKey:["forge-wiki-search"]})])},v=l({mutationFn:()=>Q({label:r.trim(),description:m.trim(),visibility:x}),onSuccess:async()=>{g(""),u(""),h("personal"),await o()}}),b=l({mutationFn:()=>$(),onSuccess:o}),f=l({mutationFn:()=>A(),onSuccess:o});if(s.isLoading)return e.jsx(F,{eyebrow:"KarpaWiki settings",title:"Loading KarpaWiki controls",description:"Fetching spaces and profile configuration for KarpaWiki."});if(s.isError)return e.jsx(j,{eyebrow:"KarpaWiki settings",error:s.error,onRetry:()=>void s.refetch()});const a=(w=s.data)==null?void 0:w.settings;return a?e.jsxs("div",{className:"mx-auto grid w-full max-w-[1440px] gap-5",children:[e.jsx(M,{eyebrow:"SQLite memory",title:"KarpaWiki Settings",titleText:"KarpaWiki Settings",description:"Manage SQLite-backed spaces and refresh KarpaWiki indexes. Model, OAuth, and embedding profile setup lives in Models.",badge:`${a.spaces.length} spaces · ${a.embeddingProfiles.length} embedding profiles`,actions:e.jsxs(e.Fragment,{children:[e.jsxs(y,{to:"/settings/models",className:C,children:["Open model settings",e.jsx(k,{className:"ml-2 size-4"})]}),e.jsx(c,{variant:"secondary",pending:b.isPending,pendingLabel:"Syncing",onClick:()=>void b.mutateAsync(),children:"Refresh indexes"}),e.jsx(c,{pending:f.isPending,pendingLabel:"Reindexing",onClick:()=>void f.mutateAsync(),disabled:a.embeddingProfiles.length===0,children:"Reindex embeddings"})]})}),e.jsx(P,{}),e.jsxs("div",{className:"grid gap-5",children:[e.jsxs(N,{className:"grid gap-4",children:[e.jsx("div",{className:"flex items-center gap-3",children:e.jsxs("div",{children:[e.jsx("div",{className:`text-sm ${p}`,children:"Model configuration moved"}),e.jsx("div",{className:`text-xs leading-5 ${n}`,children:"KarpaWiki ingest uses the OpenAI Codex OAuth connection selected in Models. OpenAI Platform API keys and embedding profile setup are not configured from this page."})]})}),e.jsxs(y,{to:"/settings/models",className:`${C} w-fit`,children:["Manage KarpaWiki models and embeddings",e.jsx(k,{className:"ml-2 size-4"})]})]}),e.jsx("div",{className:"grid gap-5",children:e.jsxs(N,{className:"grid gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(W,{className:"size-4 text-[var(--secondary)]"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:`text-sm ${p}`,children:"Spaces"}),e.jsx(R,{content:"Canonical knowledge lives in SQLite notes, with Forge maintaining metadata, links, search, and optional embedding indexes in the database. Text search and entity-linked search work without embeddings, while semantic search stays additive and profile-driven. Ingest jobs can create pages and media assets now, with room for richer OCR, transcription, and multimodal compilation later.",label:"Explain the wiki operating model"})]}),e.jsx("div",{className:`text-xs leading-5 ${n}`,children:"Personal and shared wiki spaces map to explicit SQLite namespaces."})]})]}),e.jsx("div",{className:"grid gap-3",children:a.spaces.map(i=>e.jsxs("div",{className:I,children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center justify-between gap-3",children:[e.jsx("div",{className:`min-w-0 break-words [overflow-wrap:anywhere] ${p}`,children:i.label}),e.jsx("div",{className:`text-xs uppercase tracking-[0.16em] ${n}`,children:i.visibility})]}),e.jsx("div",{className:`break-words text-xs [overflow-wrap:anywhere] ${n}`,children:i.slug}),e.jsx("div",{className:`text-sm ${T}`,children:i.description||"No description yet."})]},i.id))}),e.jsxs("div",{className:E,children:[e.jsx(S,{value:r,onChange:i=>g(i.target.value),placeholder:"New space label"}),e.jsx(S,{value:m,onChange:i=>u(i.target.value),placeholder:"Description"}),e.jsxs("select",{className:O,value:x,onChange:i=>h(i.target.value),children:[e.jsx("option",{value:"personal",children:"Personal"}),e.jsx("option",{value:"shared",children:"Shared"})]}),e.jsx(c,{pending:v.isPending,pendingLabel:"Creating",disabled:!r.trim(),onClick:()=>void v.mutateAsync(),children:"Create space"})]})]})})]})]}):e.jsx(j,{eyebrow:"KarpaWiki settings",error:new Error("Forge returned an empty KarpaWiki settings payload."),onRetry:()=>void s.refetch()})}export{_ as SettingsWikiPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as g,j as e,aV as re,cq as ae,bX as te}from"./vendor-Dnkkx2co.js";import{j as se,i as _,k as ie}from"./state-vCcAT5Hq.js";import{u as ne,eC as de,S as le,E as ce,ch as oe,eD as ue,eE as me,C as w,c as v,eF as xe,Z as b,B as C,I as Q,T as ve,m as pe,bL as ge,eG as he,bw as fe,bx as be,by as je,bz as ye,bC as ke}from"./index-By3tQxiE.js";import{P as Ne}from"./page-hero-5RTqAI88.js";import{p as we,b as Se}from"./health-link-options-Cpx8w7uM.js";import"./motion-Lt5B1XuE.js";import"./ui-C1iwpj2-.js";import"./forms-hB0SqEh-.js";import"./board-dIX6etHh.js";import"./graph-DDUZNRsO.js";const _e=["Mon","Tue","Wed","Thu","Fri","Sat","Sun"],W={awake:{label:"Awake",strong:"var(--warning)",soft:"var(--ui-warning-soft)",text:"text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]"},core:{label:"Core",strong:"var(--primary)",soft:"var(--ui-accent-soft)",text:"text-[color-mix(in_srgb,var(--primary)_78%,var(--ui-ink-strong)_22%)]"},deep:{label:"Deep",strong:"var(--success)",soft:"var(--ui-success-soft)",text:"text-[color-mix(in_srgb,var(--success)_78%,var(--ui-ink-strong)_22%)]"},rem:{label:"REM",strong:"var(--info)",soft:"var(--ui-info-soft)",text:"text-[color-mix(in_srgb,var(--info)_78%,var(--ui-ink-strong)_22%)]"},in_bed:{label:"In bed",strong:"color-mix(in_srgb,var(--ui-ink-strong)_46%,transparent)",soft:"var(--ui-surface-3)",text:"text-[var(--ui-ink-medium)]"},asleep_unspecified:{label:"Asleep",strong:"var(--primary)",soft:"var(--ui-accent-soft)",text:"text-[color-mix(in_srgb,var(--primary)_78%,var(--ui-ink-strong)_22%)]"}};function I(r){return W[r]??W.asleep_unspecified}function p(r){if(r<=0)return"0m";const a=Math.floor(r/3600),t=Math.round(r%3600/60);return a===0?`${t}m`:t===0?`${a}h`:`${a}h ${t}m`}function Ae(r){const a=Math.round(r/60);return a===0?"on baseline":`${a>0?"+":"-"}${Math.abs(a)}m`}function T(r){return`${Math.round(r*100)}%`}function A(r,a){return r?new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit",timeZone:a}).format(new Date(r)):"n/a"}function O(r,a){return new Intl.DateTimeFormat(void 0,{weekday:"long",day:"numeric",month:"long",timeZone:a}).format(new Date(r))}function q(r,a,t){return`${A(r,t)} - ${A(a,t)}`}function Te(r){const[a,t]=r.split("-").map(Number);return new Intl.DateTimeFormat(void 0,{month:"long",year:"numeric"}).format(new Date(a,(t??1)-1,1))}function U(r){const a=new Date(r),t=(r.getDay()+6)%7;return a.setDate(r.getDate()-t),a}function Re(r){const a=U(r);return a.setDate(a.getDate()+6),a}function Me(r){const a=r.getFullYear(),t=`${r.getMonth()+1}`.padStart(2,"0"),s=`${r.getDate()}`.padStart(2,"0");return`${a}-${t}-${s}`}function B(r){return{qualitySummary:typeof r.annotations.qualitySummary=="string"?r.annotations.qualitySummary:"",notes:typeof r.annotations.notes=="string"?r.annotations.notes:"",tagsText:Array.isArray(r.annotations.tags)?r.annotations.tags.join(", "):"",linkValues:Array.isArray(r.links)?r.links.map(a=>`${a.entityType}:${a.entityId}`):[]}}function De(r,a){if(!r)return[];const[t,s]=r.split("-").map(Number),n=new Date(t,(s??1)-1,1),u=new Date(t,s??1,0),d=U(n),x=Re(u),l=new Map(a.map(c=>[c.dateKey,c])),i=[];for(const c=new Date(d);c<=x;c.setDate(c.getDate()+1)){const y=Me(c);i.push({dateKey:y,dayNumber:c.getDate(),outsideMonth:c.getMonth()!==n.getMonth(),sleep:l.get(y)??null})}return i}function Ie(r){return r>0?"text-[color-mix(in_srgb,var(--success)_78%,var(--ui-ink-strong)_22%)]":r<0?"text-[color-mix(in_srgb,var(--danger)_78%,var(--ui-ink-strong)_22%)]":"text-[var(--ui-ink-medium)]"}function G(r){return r==="recharged"||r==="recovered"?"bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_78%,var(--ui-ink-strong)_22%)]":r==="steady"||r==="stable"?"bg-[var(--ui-info-soft)] text-[color-mix(in_srgb,var(--info)_78%,var(--ui-ink-strong)_22%)]":r==="fragile"||r==="strained"?"bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]":r==="depleted"?"bg-[var(--ui-danger-soft)] text-[color-mix(in_srgb,var(--danger)_78%,var(--ui-ink-strong)_22%)]":"bg-[var(--ui-surface-3)] text-[var(--ui-ink-medium)]"}function Be(r){return r==="provider_raw"?"bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_78%,var(--ui-ink-strong)_22%)]":r==="historical_raw"?"bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]":"bg-[var(--ui-surface-3)] text-[var(--ui-ink-medium)]"}function qe(r){return r==="provider_raw"?"Provider raw data":r==="historical_raw"?"Historical raw data":"Raw data unavailable"}function Ce(r){return r.qualityKind==="provider_native"?"bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_78%,var(--ui-ink-strong)_22%)]":"bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]"}function $e(r,a){const t=r.stage;if(typeof t=="string"&&t.trim().length>0)return t;const s=r.sourceType;if(typeof s=="string"&&s.trim().length>0)return s;const n=r.stageBreakdown;if(Array.isArray(n)&&n.length>0){const u=n[0];if(u&&typeof u=="object"&&typeof u.stage=="string")return(u.stage||"asleep_unspecified").trim()}return a.includes("awake")?"awake":"asleep_unspecified"}function Ee(r){const a=r,t=(a==null?void 0:a.segments)??(a==null?void 0:a.rawSegments)??[],s=(a==null?void 0:a.auditLogs)??(a==null?void 0:a.rawLogs)??[],n=a!=null&&a.sourceRecords&&a.sourceRecords.length>0?a.sourceRecords:s.filter(d=>typeof d.startedAt=="string"&&typeof d.endedAt=="string").map(d=>({id:d.id,importRunId:d.importRunId,pairingSessionId:d.pairingSessionId,sleepSessionId:d.sleepSessionId,userId:d.userId,provider:d.source,providerRecordType:d.logType,providerRecordUid:d.externalUid??d.id,sourceDevice:"",sourceTimezone:d.sourceTimezone,localDateKey:d.localDateKey,startedAt:d.startedAt,endedAt:d.endedAt,rawStage:$e(d.payload,d.logType),rawValue:null,qualityKind:"historical_import",payload:d.payload,metadata:d.metadata,ingestedAt:d.createdAt})),u=(a==null?void 0:a.rawDataStatus)??(n.length>0?"historical_raw":"raw_unavailable");return{sourceRecords:n,segments:t,auditLogs:s,rawDataStatus:u}}function J({stages:r}){const a=r.reduce((t,s)=>t+s.seconds,0);return r.length===0||a===0?e.jsx("div",{className:"rounded-[18px] border border-dashed border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4 text-sm text-[var(--ui-ink-muted)]",children:"No stage composition was stored for this night yet."}):e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:"flex h-3 overflow-hidden rounded-full bg-[var(--ui-surface-2)]",children:r.map(t=>{const s=I(t.stage);return e.jsx("div",{className:"h-full",style:{width:`${Math.max(4,t.seconds/a*100)}%`,background:s.strong},title:`${s.label} · ${p(t.seconds)}`},t.stage)})}),e.jsx("div",{className:"grid gap-2 sm:grid-cols-2 xl:grid-cols-4",children:r.map(t=>{const s=I(t.stage),n="percentage"in t&&typeof t.percentage=="number"?t.percentage:a>0?t.seconds/a:0;return e.jsxs("div",{className:"rounded-[16px] border border-[var(--ui-border-subtle)] px-3 py-3",style:{background:s.soft},children:[e.jsx("div",{className:b("text-sm font-medium",s.text),children:s.label}),e.jsx("div",{className:"mt-1 text-lg text-[var(--ui-ink-strong)]",children:p(t.seconds)}),e.jsx("div",{className:"text-xs text-[var(--ui-ink-muted)]",children:T(n)})]},t.stage)})})]})}function H({blocks:r,selectedBlockId:a,onSelect:t}){return e.jsxs("div",{className:"relative h-12 overflow-hidden rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",children:[e.jsx("div",{className:"pointer-events-none absolute inset-0 bg-[image:var(--ui-surface-section)] bg-[length:25%_100%]"}),r.map(s=>{const n=I(s.stage),u=a===s.id;return e.jsx("button",{type:"button",onClick:()=>t(s.id),className:b("absolute inset-y-[5px] rounded-[12px] border transition",u?"border-[var(--ui-border-strong)] shadow-[var(--ui-shadow-soft)]":"border-[var(--ui-border-subtle)]"),style:{left:`${s.offsetRatio*100}%`,width:`${Math.max(s.widthRatio*100,1.8)}%`,background:n.strong},title:`${s.label} · ${p(s.durationSeconds)} · ${s.startedAt} - ${s.endedAt}`,children:s.widthRatio>.13?e.jsx("span",{className:"truncate px-2 text-[10px] font-medium text-[var(--ui-ink-on-accent)]",children:s.label}):null},s.id)})]})}function Ke({timeline:r,timeZone:a}){var l,i;const t=r.blocks.filter(c=>c.lane==="in_bed"),s=r.blocks.filter(c=>c.lane==="sleep"),n=((l=s[0])==null?void 0:l.id)??((i=t[0])==null?void 0:i.id)??null,[u,d]=g.useState(n);g.useEffect(()=>{d(n)},[n,r.startedAt,r.endedAt,r.totalSeconds]);const x=r.blocks.find(c=>c.id===u)??null;return r.hasRawSegments?e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"grid gap-3",children:[t.length>0?e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"In bed window"}),e.jsx(H,{blocks:t,selectedBlockId:u,onSelect:d})]}):null,e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:r.hasSleepStageData?"Sleep phases":"Recorded sleep coverage"}),e.jsx(H,{blocks:s.length>0?s:t,selectedBlockId:u,onSelect:d})]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 text-xs text-[var(--ui-ink-muted)]",children:[e.jsx("span",{children:A(r.startedAt,a)}),e.jsx("span",{children:p(r.totalSeconds)}),e.jsx("span",{children:A(r.endedAt,a)})]}),x?e.jsx("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:b("text-sm font-medium",I(x.stage).text),children:x.label}),e.jsxs("div",{className:"mt-1 text-sm text-[var(--ui-ink-muted)]",children:[A(x.startedAt,a)," -"," ",A(x.endedAt,a)]})]}),e.jsx(v,{tone:"meta",children:p(x.durationSeconds)})]})}):null]}):e.jsx("div",{className:"rounded-[18px] border border-dashed border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-5 text-sm text-[var(--ui-ink-muted)]",children:"Phase timing is unavailable for this night. Forge still keeps the canonical overnight summary, but the companion did not store segment-level timing."})}function Fe({latestNight:r}){return r?e.jsx(w,{className:"overflow-hidden border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-0",children:e.jsxs("div",{className:"relative overflow-hidden px-6 py-6 sm:px-7 sm:py-7",children:[e.jsx("div",{className:"pointer-events-none absolute inset-0 bg-[image:var(--ui-surface-section)]"}),e.jsxs("div",{className:"relative grid gap-6 xl:grid-cols-[minmax(0,1.2fr)_minmax(0,0.8fr)]",children:[e.jsxs("div",{className:"grid gap-5",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx(v,{className:b("border-transparent",G(r.recoveryState)),children:r.qualitativeState}),e.jsx(v,{tone:"meta",children:r.sourceTimezone}),r.hasReflection?e.jsx(v,{tone:"meta",children:"Has reflection"}):null,r.hasRawSegments?e.jsxs(v,{tone:"meta",children:[r.rawSegmentCount," raw segments"]}):null]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Last night"}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-end gap-x-4 gap-y-2",children:[e.jsx("div",{className:"text-[clamp(2.5rem,6vw,5rem)] font-medium leading-none text-[var(--ui-ink-strong)]",children:p(r.asleepSeconds)}),e.jsxs("div",{className:"pb-2 text-sm text-[var(--ui-ink-muted)]",children:["asleep across ",q(r.startedAt,r.endedAt,r.sourceTimezone)]})]}),e.jsx("div",{className:"mt-3 text-sm text-[var(--ui-ink-medium)]",children:O(r.endedAt,r.sourceTimezone)}),r.qualitySummary?e.jsx("div",{className:"mt-4 max-w-2xl text-sm leading-6 text-[var(--ui-ink-medium)]",children:r.qualitySummary}):e.jsx("div",{className:"mt-4 max-w-2xl text-sm leading-6 text-[var(--ui-ink-muted)]",children:"Canonical overnight summary computed from synced sleep segments, with raw evidence still available underneath."})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"In bed"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:p(r.timeInBedSeconds)})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Score"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:r.score??"n/a"})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Regularity"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:r.regularity??"n/a"})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Efficiency"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:T(r.efficiency)})]})]})]}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-5 py-5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Baseline"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:"Compared with recent nights"})]}),e.jsx(ae,{className:"size-5 text-[var(--primary)]"})]}),e.jsxs("div",{className:"mt-4 grid gap-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[16px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-medium)]",children:"7-night average"}),e.jsx("span",{className:"text-sm text-[var(--ui-ink-strong)]",children:p(r.weeklyAverageSleepSeconds)})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[16px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-medium)]",children:"Versus baseline"}),e.jsx("span",{className:b("text-sm",Ie(r.deltaFromWeeklyAverageSeconds)),children:Ae(r.deltaFromWeeklyAverageSeconds)})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[16px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-medium)]",children:"Bedtime drift"}),e.jsxs("span",{className:"text-sm text-[var(--ui-ink-strong)]",children:[r.bedtimeDriftMinutes??0,"m"]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[16px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-medium)]",children:"Wake drift"}),e.jsxs("span",{className:"text-sm text-[var(--ui-ink-strong)]",children:[r.wakeDriftMinutes??0,"m"]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[16px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-medium)]",children:"Restorative share"}),e.jsx("span",{className:"text-sm text-[var(--ui-ink-strong)]",children:T(r.restorativeShare)})]})]})]}),e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-5 py-5",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Stage composition"}),e.jsx("div",{className:"mt-4",children:e.jsx(J,{stages:r.stageBreakdown})})]})]})]})]})}):e.jsxs(w,{className:"overflow-hidden p-6",children:[e.jsx("div",{className:"text-sm uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Sleep"}),e.jsx("div",{className:"mt-4 text-2xl text-[var(--ui-ink-strong)]",children:"No overnight sleep yet"}),e.jsx("div",{className:"mt-3 max-w-2xl text-sm leading-6 text-[var(--ui-ink-muted)]",children:"The sleep page will switch to a night-first summary once the companion syncs a canonical overnight session."})]})}function F({title:r,value:a,description:t}){return e.jsxs(w,{className:"h-full border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:r}),e.jsx("div",{className:"mt-3 text-3xl text-[var(--ui-ink-strong)]",children:a}),e.jsx("div",{className:"mt-3 text-sm leading-6 text-[var(--ui-ink-muted)]",children:t})]})}function ze({days:r,selectedSleepId:a,onSelect:t}){const s=g.useMemo(()=>Array.from(new Set(r.map(l=>l.dateKey.slice(0,7)))).sort((l,i)=>l.localeCompare(i)),[r]),[n,u]=g.useState(s[s.length-1]??"");g.useEffect(()=>{if(s.length===0){u("");return}s.includes(n)||u(s[s.length-1]??"")},[n,s]);const d=s.indexOf(n),x=g.useMemo(()=>De(n,r),[r,n]);return n?e.jsx(w,{className:"overflow-hidden border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-0",children:e.jsxs("div",{className:"grid gap-5 px-5 py-5",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Sleep calendar"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:Te(n)})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(C,{type:"button",variant:"secondary",className:"h-9 rounded-full",disabled:d<=0,onClick:()=>u(s[Math.max(0,d-1)]??n),children:"Previous"}),e.jsx(C,{type:"button",variant:"secondary",className:"h-9 rounded-full",disabled:d===-1||d>=s.length-1,onClick:()=>u(s[Math.min(s.length-1,d+1)]??n),children:"Next"})]})]}),e.jsx("div",{className:"grid grid-cols-7 gap-2 text-center text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-muted)]",children:_e.map(l=>e.jsx("div",{children:l},l))}),e.jsx("div",{className:"grid grid-cols-7 gap-2",children:x.map(l=>{const i=l.sleep,c=(i==null?void 0:i.sleepId)===a,y=i&&typeof i.score=="number"?i.score>=80?"var(--ui-success-soft)":i.score>=65?"var(--ui-info-soft)":"var(--ui-warning-soft)":"var(--ui-surface-2)";return e.jsxs("button",{type:"button",disabled:!i,"aria-pressed":c,"aria-label":`Select sleep for ${l.dateKey}`,onClick:()=>{i&&(u(i.dateKey.slice(0,7)),t(i.sleepId,i.dateKey.slice(0,7)))},className:b("min-h-[90px] rounded-[18px] border px-2 py-2 text-left transition",i?"border-[var(--ui-border-subtle)] hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-3)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",c&&"border-[var(--primary)] bg-[var(--primary)]/12",l.outsideMonth&&!i&&"opacity-35"),style:i?{background:y}:void 0,children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsx("span",{className:b("text-sm",l.outsideMonth?"text-[var(--ui-ink-muted)]":"text-[var(--ui-ink-medium)]"),children:l.dayNumber}),i!=null&&i.hasReflection?e.jsx("span",{className:"size-2 rounded-full bg-[var(--success)]"}):null]}),i?e.jsxs("div",{className:"mt-4 grid gap-1",children:[e.jsxs("div",{className:"text-lg text-[var(--ui-ink-strong)]",children:[i.sleepHours.toFixed(1),"h"]}),e.jsxs("div",{className:"text-xs text-[var(--ui-ink-muted)]",children:[i.score??"n/a"," score"]}),e.jsx("div",{className:"text-xs text-[var(--ui-ink-muted)]",children:i.hasRawSegments?"phases available":"summary only"})]}):null]},l.dateKey)})})]})}):e.jsx(w,{className:"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-5 py-8 text-sm leading-6 text-[var(--ui-ink-muted)]",children:"No canonical nights are available for the calendar yet."})}function z({active:r,children:a,onClick:t}){return e.jsx("button",{type:"button",onClick:t,className:b("rounded-full border px-4 py-2 text-sm transition",r?"border-[var(--primary)] bg-[var(--primary)]/12 text-[var(--ui-ink-strong)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)] hover:text-[var(--ui-ink-strong)]"),children:a})}function Le({session:r,draft:a,rawDetail:t,rawDetailLoading:s,pending:n,tab:u,linkOptions:d,onTabChange:x,onDraftChange:l,onSave:i}){const[c,y]=g.useState(null),k=g.useMemo(()=>Ee(t),[t]),$=typeof r.derived.efficiency=="number"?r.derived.efficiency:r.timeInBedSeconds>0?r.asleepSeconds/r.timeInBedSeconds:0,E=typeof r.derived.restorativeShare=="number"?r.derived.restorativeShare:0,R=typeof r.derived.recoveryState=="string"?r.derived.recoveryState:null;return e.jsx(w,{className:"overflow-hidden border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-0",children:e.jsxs("div",{className:"grid gap-5 px-5 py-5",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(v,{className:b("border-transparent",G(R)),children:R?R.replaceAll("_"," "):"Canonical night"}),e.jsxs(v,{tone:"meta",children:[r.rawSegmentCount," raw segments"]}),e.jsx(v,{tone:"meta",children:r.sourceTimezone})]}),e.jsx("div",{className:"mt-3 text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Selected night"}),e.jsx("div",{className:"mt-2 text-2xl text-[var(--ui-ink-strong)]",children:O(r.endedAt,r.sourceTimezone)}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:q(r.startedAt,r.endedAt,r.sourceTimezone)})]}),e.jsxs("div",{className:"grid gap-2 text-right",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Summary"}),e.jsx("div",{className:"text-3xl text-[var(--ui-ink-strong)]",children:p(r.asleepSeconds)}),e.jsx("div",{className:"text-sm text-[var(--ui-ink-muted)]",children:"asleep"})]})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"In bed"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:p(r.timeInBedSeconds)})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Awake"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:p(r.awakeSeconds)})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Efficiency"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:T($)})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Restorative"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:T(E)})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(z,{active:u==="summary",onClick:()=>x("summary"),children:"Summary"}),e.jsx(z,{active:u==="reflection",onClick:()=>x("reflection"),children:"Reflection"}),e.jsx(z,{active:u==="raw",onClick:()=>x("raw"),children:"Show raw data"})]}),u==="summary"?e.jsxs("div",{className:"grid gap-5",children:[e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Phase timeline"}),e.jsx("div",{className:"mt-4",children:s?e.jsx("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-6 text-sm text-[var(--ui-ink-muted)]",children:"Loading phase timing from raw sleep segments…"}):e.jsx(Ke,{timeline:(t==null?void 0:t.phaseTimeline)??{startedAt:r.startedAt,endedAt:r.endedAt,totalSeconds:Math.max(0,Math.round((new Date(r.endedAt).getTime()-new Date(r.startedAt).getTime())/1e3)),hasRawSegments:!1,hasSleepStageData:!1,blocks:[]},timeZone:r.sourceTimezone})})]}),e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Stage composition"}),e.jsx("div",{className:"mt-4",children:e.jsx(J,{stages:r.stageBreakdown})})]})]}):null,u==="reflection"?e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-muted)]",children:"Quality summary"}),e.jsx(Q,{value:a.qualitySummary,onChange:o=>l({qualitySummary:o.target.value}),placeholder:"Recovered after a late evening, but sleep onset drifted."})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-muted)]",children:"Night notes"}),e.jsx(ve,{className:"min-h-[200px]",value:a.notes,onChange:o=>l({notes:o.target.value}),placeholder:"What shaped this night, and what should we remember about it?"})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-muted)]",children:"Tags"}),e.jsx(Q,{value:a.tagsText,onChange:o=>l({tagsText:o.target.value}),placeholder:"travel, stress, good-routine, late-caffeine"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-muted)]",children:"Linked context"}),e.jsx(pe,{options:d,selectedValues:a.linkValues,onChange:o=>l({linkValues:o}),placeholder:"Search goals, tasks, habits, beliefs, reports, or patterns…"})]}),e.jsx("div",{className:"flex justify-end",children:e.jsxs(C,{type:"button",pending:n,pendingLabel:"Saving",onClick:i,children:[e.jsx(te,{className:"size-4"}),"Save reflection"]})})]}):null,u==="raw"?e.jsxs("div",{className:"grid gap-5",children:[e.jsx("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4 text-sm leading-6 text-[var(--ui-ink-muted)]",children:"Forge shows the canonical overnight session by default. This view reveals the evidence stack underneath it: raw provider or historical imported records first, then Forge-normalized sleep segments."}),s?e.jsx("div",{className:"text-sm text-[var(--ui-ink-muted)]",children:"Loading raw sleep evidence…"}):null,s?null:e.jsxs("div",{className:"grid gap-5",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(v,{className:b("border-transparent",Be(k.rawDataStatus)),children:qe(k.rawDataStatus)}),k.rawDataStatus==="historical_raw"?e.jsx(v,{tone:"meta",children:"Partial evidence"}):null]}),e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Raw data"}),k.sourceRecords.length?k.sourceRecords.map(o=>e.jsxs("div",{className:"rounded-[16px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-3",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(v,{className:b("border-transparent",Ce(o)),children:o.qualityKind==="provider_native"?"Provider raw":"Historical raw"}),e.jsx(v,{tone:"meta",className:"capitalize",children:o.rawStage.replaceAll("_"," ")}),e.jsx("span",{className:"text-sm text-[var(--ui-ink-medium)]",children:q(o.startedAt,o.endedAt,o.sourceTimezone)})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-[var(--ui-ink-muted)]",children:o.providerRecordType.replaceAll("_"," ")}),e.jsx(C,{type:"button",variant:"secondary",className:"h-8 rounded-full px-3",onClick:()=>y(M=>M===o.id?null:o.id),children:c===o.id?"Hide JSON":"See JSON"})]})]}),e.jsx("div",{className:"mt-3 text-sm text-[var(--ui-ink-muted)]",children:p(Math.max(0,Math.round((new Date(o.endedAt).getTime()-new Date(o.startedAt).getTime())/1e3)))}),c===o.id?e.jsx("pre",{className:"mt-3 overflow-x-auto rounded-[14px] border border-[var(--ui-border-subtle)] bg-[var(--ui-code-bg)] p-3 text-xs leading-6 text-[var(--ui-ink-medium)]",children:JSON.stringify({payload:o.payload,metadata:o.metadata},null,2)}):null]},o.id)):e.jsx("div",{className:"rounded-[16px] border border-dashed border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4 text-sm text-[var(--ui-ink-muted)]",children:"No raw data was stored for this night."})]}),e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Sleep segments"}),k.segments.length?k.segments.map(o=>e.jsx("div",{className:"rounded-[16px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-3",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(v,{tone:"meta",className:"capitalize",children:o.stage.replaceAll("_"," ")}),e.jsx(v,{tone:"meta",children:o.qualityKind==="provider_native"?"provider-backed":"historical"}),e.jsx("span",{className:"text-sm text-[var(--ui-ink-medium)]",children:q(o.startedAt,o.endedAt,o.sourceTimezone)})]}),e.jsx("span",{className:"text-sm text-[var(--ui-ink-muted)]",children:p(Math.max(0,Math.round((new Date(o.endedAt).getTime()-new Date(o.startedAt).getTime())/1e3)))})]})},o.id)):e.jsx("div",{className:"rounded-[16px] border border-dashed border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4 text-sm text-[var(--ui-ink-muted)]",children:"No normalized sleep segments were stored for this night."})]})]})]}):null]})})}function Xe(){var V;const r=ne(),a=se(),[t,s]=g.useState({}),[n,u]=g.useState(null),[d,x]=g.useState("summary"),l=Array.isArray(r==null?void 0:r.selectedUserIds)?r.selectedUserIds:[],i=r==null?void 0:r.snapshot,c=_({queryKey:["forge-sleep",...l],queryFn:async()=>(await ge(l)).sleep}),y=_({queryKey:["forge-sleep-raw",n],enabled:!!n,queryFn:async()=>he(n)}),k=_({queryKey:["forge-sleep-values",...l],queryFn:async()=>(await fe(l)).values}),$=_({queryKey:["forge-sleep-patterns",...l],queryFn:async()=>(await be(l)).patterns}),E=_({queryKey:["forge-sleep-behaviors",...l],queryFn:async()=>(await je(l)).behaviors}),R=_({queryKey:["forge-sleep-beliefs",...l],queryFn:async()=>(await ye(l)).beliefs}),o=_({queryKey:["forge-sleep-reports",...l],queryFn:async()=>(await ke(l)).reports});g.useEffect(()=>{c.data&&s(Object.fromEntries(c.data.sessions.map(m=>[m.id,B(m)])))},[c.data]),g.useEffect(()=>{var N,j,S;if(!((N=c.data)!=null&&N.sessions.length)){u(null);return}c.data.sessions.some(K=>K.id===n)||u(((j=c.data.latestNight)==null?void 0:j.sleepId)??((S=c.data.sessions[0])==null?void 0:S.id)??null)},[n,c.data]),g.useEffect(()=>{x("summary")},[n]);const M=ie({mutationFn:async m=>de(m.sleepId,{qualitySummary:m.qualitySummary,notes:m.notes,tags:m.tagsText.split(",").map(N=>N.trim()).filter(Boolean),links:we(m.linkValues)}),onSuccess:async()=>{await a.invalidateQueries({queryKey:["forge-sleep"]}),await a.invalidateQueries({queryKey:["forge-sleep-raw"]})}});if(c.isLoading)return e.jsx(le,{eyebrow:"Sleep",title:"Loading sleep surface",description:"Reading canonical nights, calendar summaries, and sleep phase detail.",columns:2,blocks:6});if(c.isError||!c.data)return e.jsx(ce,{eyebrow:"Sleep",error:c.error??new Error("Sleep data unavailable"),onRetry:()=>void c.refetch()});const h=c.data,D=h.sessions,L=new Map(D.map(m=>[m.id,m])),f=(n?L.get(n):null)??(h.latestNight?L.get(h.latestNight.sleepId):null)??D[0]??null,P=f?t[f.id]??B(f):null,Y=Se({goals:(i==null?void 0:i.dashboard.goals)??[],projects:(i==null?void 0:i.dashboard.projects)??[],tasks:(i==null?void 0:i.dashboard.tasks)??[],habits:(i==null?void 0:i.dashboard.habits)??[],values:k.data??[],patterns:$.data??[],behaviors:E.data??[],beliefs:R.data??[],reports:o.data??[]});function X(m,N){s(j=>{const S=D.find(ee=>ee.id===m),K=j[m]??(S?B(S):{qualitySummary:"",notes:"",tagsText:"",linkValues:[]});return{...j,[m]:{...K,...N}}})}async function Z(m){const N=D.find(S=>S.id===m);if(!N)return;const j=t[m]??B(N);await M.mutateAsync({sleepId:m,qualitySummary:j.qualitySummary,notes:j.notes,tagsText:j.tagsText,linkValues:j.linkValues})}return e.jsxs("div",{className:"grid gap-5",children:[e.jsx(Ne,{eyebrow:"Health",title:"Sleep",description:"Canonical overnight sessions first, with last-night recovery, a clickable night calendar, and raw segment evidence only when you ask for it.",badge:`${D.length} nights`}),e.jsx(oe,{}),e.jsx(ue,{children:e.jsx(Fe,{latestNight:h.latestNight})}),e.jsx(me,{children:e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,0.95fr)_minmax(0,1.05fr)]",children:[e.jsx(F,{title:"Weekly average",value:p(h.summary.averageSleepSeconds),description:"Average overnight sleep duration across the recent week, used as the baseline for the latest-night comparison."}),e.jsx(F,{title:"Regularity",value:`${h.summary.averageRegularityScore}`,description:`Average bedtime drift ${h.summary.averageBedtimeConsistencyMinutes}m and wake drift ${h.summary.averageWakeConsistencyMinutes}m.`}),e.jsx(F,{title:"Restorative share",value:T(h.summary.averageRestorativeShare),description:`Deep + REM share across recent nights, with ${h.summary.reflectiveNightCount} nights already carrying context.`}),e.jsxs(w,{className:"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",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.18em] text-[var(--ui-ink-muted)]",children:"Recent stage mix"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:"Average nightly phases"})]}),e.jsx(re,{className:"size-5 text-[var(--primary)]"})]}),e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:h.stageAverages.length>0?h.stageAverages.slice(0,5).map(m=>e.jsxs(v,{tone:"meta",children:[I(m.stage).label," ",p(m.averageSeconds)]},m.stage)):e.jsx("div",{className:"text-sm text-[var(--ui-ink-muted)]",children:"Stage averages will appear once nights include phase data."})})]})]})}),e.jsx(xe,{children:e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,25rem)_minmax(0,1fr)]",children:[e.jsx(ze,{days:h.calendarDays,selectedSleepId:(f==null?void 0:f.id)??null,onSelect:m=>u(m)}),f&&P?e.jsx(Le,{session:f,draft:P,rawDetail:y.data??null,rawDetailLoading:y.isLoading,pending:M.isPending&&((V=M.variables)==null?void 0:V.sleepId)===f.id,tab:d,linkOptions:Y,onTabChange:x,onDraftChange:m=>X(f.id,m),onSave:()=>void Z(f.id)}):e.jsx(w,{className:"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-6 py-8 text-sm leading-6 text-[var(--ui-ink-muted)]",children:"Pick a night from the calendar to inspect its phase timing, stage summary, and reflection context."})]})})]})}export{Xe as SleepPage};
|
|
1
|
+
import{r as g,j as e,aV as re,cq as ae,bX as te}from"./vendor-Dnkkx2co.js";import{j as se,i as _,k as ie}from"./state-vCcAT5Hq.js";import{u as ne,eC as de,S as le,E as ce,ch as oe,eD as ue,eE as me,C as w,c as v,eF as xe,Z as b,B as C,I as Q,T as ve,m as pe,bL as ge,eG as he,bw as fe,bx as be,by as je,bz as ye,bC as ke}from"./index-QJkjKYzZ.js";import{P as Ne}from"./page-hero-CONuJu5J.js";import{p as we,b as Se}from"./health-link-options-Cpx8w7uM.js";import"./motion-Lt5B1XuE.js";import"./ui-C1iwpj2-.js";import"./forms-hB0SqEh-.js";import"./board-dIX6etHh.js";import"./graph-DDUZNRsO.js";const _e=["Mon","Tue","Wed","Thu","Fri","Sat","Sun"],W={awake:{label:"Awake",strong:"var(--warning)",soft:"var(--ui-warning-soft)",text:"text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]"},core:{label:"Core",strong:"var(--primary)",soft:"var(--ui-accent-soft)",text:"text-[color-mix(in_srgb,var(--primary)_78%,var(--ui-ink-strong)_22%)]"},deep:{label:"Deep",strong:"var(--success)",soft:"var(--ui-success-soft)",text:"text-[color-mix(in_srgb,var(--success)_78%,var(--ui-ink-strong)_22%)]"},rem:{label:"REM",strong:"var(--info)",soft:"var(--ui-info-soft)",text:"text-[color-mix(in_srgb,var(--info)_78%,var(--ui-ink-strong)_22%)]"},in_bed:{label:"In bed",strong:"color-mix(in_srgb,var(--ui-ink-strong)_46%,transparent)",soft:"var(--ui-surface-3)",text:"text-[var(--ui-ink-medium)]"},asleep_unspecified:{label:"Asleep",strong:"var(--primary)",soft:"var(--ui-accent-soft)",text:"text-[color-mix(in_srgb,var(--primary)_78%,var(--ui-ink-strong)_22%)]"}};function I(r){return W[r]??W.asleep_unspecified}function p(r){if(r<=0)return"0m";const a=Math.floor(r/3600),t=Math.round(r%3600/60);return a===0?`${t}m`:t===0?`${a}h`:`${a}h ${t}m`}function Ae(r){const a=Math.round(r/60);return a===0?"on baseline":`${a>0?"+":"-"}${Math.abs(a)}m`}function T(r){return`${Math.round(r*100)}%`}function A(r,a){return r?new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit",timeZone:a}).format(new Date(r)):"n/a"}function O(r,a){return new Intl.DateTimeFormat(void 0,{weekday:"long",day:"numeric",month:"long",timeZone:a}).format(new Date(r))}function q(r,a,t){return`${A(r,t)} - ${A(a,t)}`}function Te(r){const[a,t]=r.split("-").map(Number);return new Intl.DateTimeFormat(void 0,{month:"long",year:"numeric"}).format(new Date(a,(t??1)-1,1))}function U(r){const a=new Date(r),t=(r.getDay()+6)%7;return a.setDate(r.getDate()-t),a}function Re(r){const a=U(r);return a.setDate(a.getDate()+6),a}function Me(r){const a=r.getFullYear(),t=`${r.getMonth()+1}`.padStart(2,"0"),s=`${r.getDate()}`.padStart(2,"0");return`${a}-${t}-${s}`}function B(r){return{qualitySummary:typeof r.annotations.qualitySummary=="string"?r.annotations.qualitySummary:"",notes:typeof r.annotations.notes=="string"?r.annotations.notes:"",tagsText:Array.isArray(r.annotations.tags)?r.annotations.tags.join(", "):"",linkValues:Array.isArray(r.links)?r.links.map(a=>`${a.entityType}:${a.entityId}`):[]}}function De(r,a){if(!r)return[];const[t,s]=r.split("-").map(Number),n=new Date(t,(s??1)-1,1),u=new Date(t,s??1,0),d=U(n),x=Re(u),l=new Map(a.map(c=>[c.dateKey,c])),i=[];for(const c=new Date(d);c<=x;c.setDate(c.getDate()+1)){const y=Me(c);i.push({dateKey:y,dayNumber:c.getDate(),outsideMonth:c.getMonth()!==n.getMonth(),sleep:l.get(y)??null})}return i}function Ie(r){return r>0?"text-[color-mix(in_srgb,var(--success)_78%,var(--ui-ink-strong)_22%)]":r<0?"text-[color-mix(in_srgb,var(--danger)_78%,var(--ui-ink-strong)_22%)]":"text-[var(--ui-ink-medium)]"}function G(r){return r==="recharged"||r==="recovered"?"bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_78%,var(--ui-ink-strong)_22%)]":r==="steady"||r==="stable"?"bg-[var(--ui-info-soft)] text-[color-mix(in_srgb,var(--info)_78%,var(--ui-ink-strong)_22%)]":r==="fragile"||r==="strained"?"bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]":r==="depleted"?"bg-[var(--ui-danger-soft)] text-[color-mix(in_srgb,var(--danger)_78%,var(--ui-ink-strong)_22%)]":"bg-[var(--ui-surface-3)] text-[var(--ui-ink-medium)]"}function Be(r){return r==="provider_raw"?"bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_78%,var(--ui-ink-strong)_22%)]":r==="historical_raw"?"bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]":"bg-[var(--ui-surface-3)] text-[var(--ui-ink-medium)]"}function qe(r){return r==="provider_raw"?"Provider raw data":r==="historical_raw"?"Historical raw data":"Raw data unavailable"}function Ce(r){return r.qualityKind==="provider_native"?"bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_78%,var(--ui-ink-strong)_22%)]":"bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]"}function $e(r,a){const t=r.stage;if(typeof t=="string"&&t.trim().length>0)return t;const s=r.sourceType;if(typeof s=="string"&&s.trim().length>0)return s;const n=r.stageBreakdown;if(Array.isArray(n)&&n.length>0){const u=n[0];if(u&&typeof u=="object"&&typeof u.stage=="string")return(u.stage||"asleep_unspecified").trim()}return a.includes("awake")?"awake":"asleep_unspecified"}function Ee(r){const a=r,t=(a==null?void 0:a.segments)??(a==null?void 0:a.rawSegments)??[],s=(a==null?void 0:a.auditLogs)??(a==null?void 0:a.rawLogs)??[],n=a!=null&&a.sourceRecords&&a.sourceRecords.length>0?a.sourceRecords:s.filter(d=>typeof d.startedAt=="string"&&typeof d.endedAt=="string").map(d=>({id:d.id,importRunId:d.importRunId,pairingSessionId:d.pairingSessionId,sleepSessionId:d.sleepSessionId,userId:d.userId,provider:d.source,providerRecordType:d.logType,providerRecordUid:d.externalUid??d.id,sourceDevice:"",sourceTimezone:d.sourceTimezone,localDateKey:d.localDateKey,startedAt:d.startedAt,endedAt:d.endedAt,rawStage:$e(d.payload,d.logType),rawValue:null,qualityKind:"historical_import",payload:d.payload,metadata:d.metadata,ingestedAt:d.createdAt})),u=(a==null?void 0:a.rawDataStatus)??(n.length>0?"historical_raw":"raw_unavailable");return{sourceRecords:n,segments:t,auditLogs:s,rawDataStatus:u}}function J({stages:r}){const a=r.reduce((t,s)=>t+s.seconds,0);return r.length===0||a===0?e.jsx("div",{className:"rounded-[18px] border border-dashed border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4 text-sm text-[var(--ui-ink-muted)]",children:"No stage composition was stored for this night yet."}):e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:"flex h-3 overflow-hidden rounded-full bg-[var(--ui-surface-2)]",children:r.map(t=>{const s=I(t.stage);return e.jsx("div",{className:"h-full",style:{width:`${Math.max(4,t.seconds/a*100)}%`,background:s.strong},title:`${s.label} · ${p(t.seconds)}`},t.stage)})}),e.jsx("div",{className:"grid gap-2 sm:grid-cols-2 xl:grid-cols-4",children:r.map(t=>{const s=I(t.stage),n="percentage"in t&&typeof t.percentage=="number"?t.percentage:a>0?t.seconds/a:0;return e.jsxs("div",{className:"rounded-[16px] border border-[var(--ui-border-subtle)] px-3 py-3",style:{background:s.soft},children:[e.jsx("div",{className:b("text-sm font-medium",s.text),children:s.label}),e.jsx("div",{className:"mt-1 text-lg text-[var(--ui-ink-strong)]",children:p(t.seconds)}),e.jsx("div",{className:"text-xs text-[var(--ui-ink-muted)]",children:T(n)})]},t.stage)})})]})}function H({blocks:r,selectedBlockId:a,onSelect:t}){return e.jsxs("div",{className:"relative h-12 overflow-hidden rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",children:[e.jsx("div",{className:"pointer-events-none absolute inset-0 bg-[image:var(--ui-surface-section)] bg-[length:25%_100%]"}),r.map(s=>{const n=I(s.stage),u=a===s.id;return e.jsx("button",{type:"button",onClick:()=>t(s.id),className:b("absolute inset-y-[5px] rounded-[12px] border transition",u?"border-[var(--ui-border-strong)] shadow-[var(--ui-shadow-soft)]":"border-[var(--ui-border-subtle)]"),style:{left:`${s.offsetRatio*100}%`,width:`${Math.max(s.widthRatio*100,1.8)}%`,background:n.strong},title:`${s.label} · ${p(s.durationSeconds)} · ${s.startedAt} - ${s.endedAt}`,children:s.widthRatio>.13?e.jsx("span",{className:"truncate px-2 text-[10px] font-medium text-[var(--ui-ink-on-accent)]",children:s.label}):null},s.id)})]})}function Ke({timeline:r,timeZone:a}){var l,i;const t=r.blocks.filter(c=>c.lane==="in_bed"),s=r.blocks.filter(c=>c.lane==="sleep"),n=((l=s[0])==null?void 0:l.id)??((i=t[0])==null?void 0:i.id)??null,[u,d]=g.useState(n);g.useEffect(()=>{d(n)},[n,r.startedAt,r.endedAt,r.totalSeconds]);const x=r.blocks.find(c=>c.id===u)??null;return r.hasRawSegments?e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"grid gap-3",children:[t.length>0?e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"In bed window"}),e.jsx(H,{blocks:t,selectedBlockId:u,onSelect:d})]}):null,e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:r.hasSleepStageData?"Sleep phases":"Recorded sleep coverage"}),e.jsx(H,{blocks:s.length>0?s:t,selectedBlockId:u,onSelect:d})]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 text-xs text-[var(--ui-ink-muted)]",children:[e.jsx("span",{children:A(r.startedAt,a)}),e.jsx("span",{children:p(r.totalSeconds)}),e.jsx("span",{children:A(r.endedAt,a)})]}),x?e.jsx("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:b("text-sm font-medium",I(x.stage).text),children:x.label}),e.jsxs("div",{className:"mt-1 text-sm text-[var(--ui-ink-muted)]",children:[A(x.startedAt,a)," -"," ",A(x.endedAt,a)]})]}),e.jsx(v,{tone:"meta",children:p(x.durationSeconds)})]})}):null]}):e.jsx("div",{className:"rounded-[18px] border border-dashed border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-5 text-sm text-[var(--ui-ink-muted)]",children:"Phase timing is unavailable for this night. Forge still keeps the canonical overnight summary, but the companion did not store segment-level timing."})}function Fe({latestNight:r}){return r?e.jsx(w,{className:"overflow-hidden border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-0",children:e.jsxs("div",{className:"relative overflow-hidden px-6 py-6 sm:px-7 sm:py-7",children:[e.jsx("div",{className:"pointer-events-none absolute inset-0 bg-[image:var(--ui-surface-section)]"}),e.jsxs("div",{className:"relative grid gap-6 xl:grid-cols-[minmax(0,1.2fr)_minmax(0,0.8fr)]",children:[e.jsxs("div",{className:"grid gap-5",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx(v,{className:b("border-transparent",G(r.recoveryState)),children:r.qualitativeState}),e.jsx(v,{tone:"meta",children:r.sourceTimezone}),r.hasReflection?e.jsx(v,{tone:"meta",children:"Has reflection"}):null,r.hasRawSegments?e.jsxs(v,{tone:"meta",children:[r.rawSegmentCount," raw segments"]}):null]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Last night"}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-end gap-x-4 gap-y-2",children:[e.jsx("div",{className:"text-[clamp(2.5rem,6vw,5rem)] font-medium leading-none text-[var(--ui-ink-strong)]",children:p(r.asleepSeconds)}),e.jsxs("div",{className:"pb-2 text-sm text-[var(--ui-ink-muted)]",children:["asleep across ",q(r.startedAt,r.endedAt,r.sourceTimezone)]})]}),e.jsx("div",{className:"mt-3 text-sm text-[var(--ui-ink-medium)]",children:O(r.endedAt,r.sourceTimezone)}),r.qualitySummary?e.jsx("div",{className:"mt-4 max-w-2xl text-sm leading-6 text-[var(--ui-ink-medium)]",children:r.qualitySummary}):e.jsx("div",{className:"mt-4 max-w-2xl text-sm leading-6 text-[var(--ui-ink-muted)]",children:"Canonical overnight summary computed from synced sleep segments, with raw evidence still available underneath."})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"In bed"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:p(r.timeInBedSeconds)})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Score"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:r.score??"n/a"})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Regularity"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:r.regularity??"n/a"})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Efficiency"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:T(r.efficiency)})]})]})]}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-5 py-5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Baseline"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:"Compared with recent nights"})]}),e.jsx(ae,{className:"size-5 text-[var(--primary)]"})]}),e.jsxs("div",{className:"mt-4 grid gap-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[16px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-medium)]",children:"7-night average"}),e.jsx("span",{className:"text-sm text-[var(--ui-ink-strong)]",children:p(r.weeklyAverageSleepSeconds)})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[16px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-medium)]",children:"Versus baseline"}),e.jsx("span",{className:b("text-sm",Ie(r.deltaFromWeeklyAverageSeconds)),children:Ae(r.deltaFromWeeklyAverageSeconds)})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[16px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-medium)]",children:"Bedtime drift"}),e.jsxs("span",{className:"text-sm text-[var(--ui-ink-strong)]",children:[r.bedtimeDriftMinutes??0,"m"]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[16px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-medium)]",children:"Wake drift"}),e.jsxs("span",{className:"text-sm text-[var(--ui-ink-strong)]",children:[r.wakeDriftMinutes??0,"m"]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[16px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-medium)]",children:"Restorative share"}),e.jsx("span",{className:"text-sm text-[var(--ui-ink-strong)]",children:T(r.restorativeShare)})]})]})]}),e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-5 py-5",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Stage composition"}),e.jsx("div",{className:"mt-4",children:e.jsx(J,{stages:r.stageBreakdown})})]})]})]})]})}):e.jsxs(w,{className:"overflow-hidden p-6",children:[e.jsx("div",{className:"text-sm uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Sleep"}),e.jsx("div",{className:"mt-4 text-2xl text-[var(--ui-ink-strong)]",children:"No overnight sleep yet"}),e.jsx("div",{className:"mt-3 max-w-2xl text-sm leading-6 text-[var(--ui-ink-muted)]",children:"The sleep page will switch to a night-first summary once the companion syncs a canonical overnight session."})]})}function F({title:r,value:a,description:t}){return e.jsxs(w,{className:"h-full border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:r}),e.jsx("div",{className:"mt-3 text-3xl text-[var(--ui-ink-strong)]",children:a}),e.jsx("div",{className:"mt-3 text-sm leading-6 text-[var(--ui-ink-muted)]",children:t})]})}function ze({days:r,selectedSleepId:a,onSelect:t}){const s=g.useMemo(()=>Array.from(new Set(r.map(l=>l.dateKey.slice(0,7)))).sort((l,i)=>l.localeCompare(i)),[r]),[n,u]=g.useState(s[s.length-1]??"");g.useEffect(()=>{if(s.length===0){u("");return}s.includes(n)||u(s[s.length-1]??"")},[n,s]);const d=s.indexOf(n),x=g.useMemo(()=>De(n,r),[r,n]);return n?e.jsx(w,{className:"overflow-hidden border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-0",children:e.jsxs("div",{className:"grid gap-5 px-5 py-5",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Sleep calendar"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:Te(n)})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(C,{type:"button",variant:"secondary",className:"h-9 rounded-full",disabled:d<=0,onClick:()=>u(s[Math.max(0,d-1)]??n),children:"Previous"}),e.jsx(C,{type:"button",variant:"secondary",className:"h-9 rounded-full",disabled:d===-1||d>=s.length-1,onClick:()=>u(s[Math.min(s.length-1,d+1)]??n),children:"Next"})]})]}),e.jsx("div",{className:"grid grid-cols-7 gap-2 text-center text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-muted)]",children:_e.map(l=>e.jsx("div",{children:l},l))}),e.jsx("div",{className:"grid grid-cols-7 gap-2",children:x.map(l=>{const i=l.sleep,c=(i==null?void 0:i.sleepId)===a,y=i&&typeof i.score=="number"?i.score>=80?"var(--ui-success-soft)":i.score>=65?"var(--ui-info-soft)":"var(--ui-warning-soft)":"var(--ui-surface-2)";return e.jsxs("button",{type:"button",disabled:!i,"aria-pressed":c,"aria-label":`Select sleep for ${l.dateKey}`,onClick:()=>{i&&(u(i.dateKey.slice(0,7)),t(i.sleepId,i.dateKey.slice(0,7)))},className:b("min-h-[90px] rounded-[18px] border px-2 py-2 text-left transition",i?"border-[var(--ui-border-subtle)] hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-3)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",c&&"border-[var(--primary)] bg-[var(--primary)]/12",l.outsideMonth&&!i&&"opacity-35"),style:i?{background:y}:void 0,children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsx("span",{className:b("text-sm",l.outsideMonth?"text-[var(--ui-ink-muted)]":"text-[var(--ui-ink-medium)]"),children:l.dayNumber}),i!=null&&i.hasReflection?e.jsx("span",{className:"size-2 rounded-full bg-[var(--success)]"}):null]}),i?e.jsxs("div",{className:"mt-4 grid gap-1",children:[e.jsxs("div",{className:"text-lg text-[var(--ui-ink-strong)]",children:[i.sleepHours.toFixed(1),"h"]}),e.jsxs("div",{className:"text-xs text-[var(--ui-ink-muted)]",children:[i.score??"n/a"," score"]}),e.jsx("div",{className:"text-xs text-[var(--ui-ink-muted)]",children:i.hasRawSegments?"phases available":"summary only"})]}):null]},l.dateKey)})})]})}):e.jsx(w,{className:"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-5 py-8 text-sm leading-6 text-[var(--ui-ink-muted)]",children:"No canonical nights are available for the calendar yet."})}function z({active:r,children:a,onClick:t}){return e.jsx("button",{type:"button",onClick:t,className:b("rounded-full border px-4 py-2 text-sm transition",r?"border-[var(--primary)] bg-[var(--primary)]/12 text-[var(--ui-ink-strong)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)] hover:text-[var(--ui-ink-strong)]"),children:a})}function Le({session:r,draft:a,rawDetail:t,rawDetailLoading:s,pending:n,tab:u,linkOptions:d,onTabChange:x,onDraftChange:l,onSave:i}){const[c,y]=g.useState(null),k=g.useMemo(()=>Ee(t),[t]),$=typeof r.derived.efficiency=="number"?r.derived.efficiency:r.timeInBedSeconds>0?r.asleepSeconds/r.timeInBedSeconds:0,E=typeof r.derived.restorativeShare=="number"?r.derived.restorativeShare:0,R=typeof r.derived.recoveryState=="string"?r.derived.recoveryState:null;return e.jsx(w,{className:"overflow-hidden border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-0",children:e.jsxs("div",{className:"grid gap-5 px-5 py-5",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(v,{className:b("border-transparent",G(R)),children:R?R.replaceAll("_"," "):"Canonical night"}),e.jsxs(v,{tone:"meta",children:[r.rawSegmentCount," raw segments"]}),e.jsx(v,{tone:"meta",children:r.sourceTimezone})]}),e.jsx("div",{className:"mt-3 text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Selected night"}),e.jsx("div",{className:"mt-2 text-2xl text-[var(--ui-ink-strong)]",children:O(r.endedAt,r.sourceTimezone)}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:q(r.startedAt,r.endedAt,r.sourceTimezone)})]}),e.jsxs("div",{className:"grid gap-2 text-right",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Summary"}),e.jsx("div",{className:"text-3xl text-[var(--ui-ink-strong)]",children:p(r.asleepSeconds)}),e.jsx("div",{className:"text-sm text-[var(--ui-ink-muted)]",children:"asleep"})]})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"In bed"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:p(r.timeInBedSeconds)})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Awake"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:p(r.awakeSeconds)})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Efficiency"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:T($)})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Restorative"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:T(E)})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(z,{active:u==="summary",onClick:()=>x("summary"),children:"Summary"}),e.jsx(z,{active:u==="reflection",onClick:()=>x("reflection"),children:"Reflection"}),e.jsx(z,{active:u==="raw",onClick:()=>x("raw"),children:"Show raw data"})]}),u==="summary"?e.jsxs("div",{className:"grid gap-5",children:[e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Phase timeline"}),e.jsx("div",{className:"mt-4",children:s?e.jsx("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-6 text-sm text-[var(--ui-ink-muted)]",children:"Loading phase timing from raw sleep segments…"}):e.jsx(Ke,{timeline:(t==null?void 0:t.phaseTimeline)??{startedAt:r.startedAt,endedAt:r.endedAt,totalSeconds:Math.max(0,Math.round((new Date(r.endedAt).getTime()-new Date(r.startedAt).getTime())/1e3)),hasRawSegments:!1,hasSleepStageData:!1,blocks:[]},timeZone:r.sourceTimezone})})]}),e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Stage composition"}),e.jsx("div",{className:"mt-4",children:e.jsx(J,{stages:r.stageBreakdown})})]})]}):null,u==="reflection"?e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-muted)]",children:"Quality summary"}),e.jsx(Q,{value:a.qualitySummary,onChange:o=>l({qualitySummary:o.target.value}),placeholder:"Recovered after a late evening, but sleep onset drifted."})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-muted)]",children:"Night notes"}),e.jsx(ve,{className:"min-h-[200px]",value:a.notes,onChange:o=>l({notes:o.target.value}),placeholder:"What shaped this night, and what should we remember about it?"})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-muted)]",children:"Tags"}),e.jsx(Q,{value:a.tagsText,onChange:o=>l({tagsText:o.target.value}),placeholder:"travel, stress, good-routine, late-caffeine"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-muted)]",children:"Linked context"}),e.jsx(pe,{options:d,selectedValues:a.linkValues,onChange:o=>l({linkValues:o}),placeholder:"Search goals, tasks, habits, beliefs, reports, or patterns…"})]}),e.jsx("div",{className:"flex justify-end",children:e.jsxs(C,{type:"button",pending:n,pendingLabel:"Saving",onClick:i,children:[e.jsx(te,{className:"size-4"}),"Save reflection"]})})]}):null,u==="raw"?e.jsxs("div",{className:"grid gap-5",children:[e.jsx("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4 text-sm leading-6 text-[var(--ui-ink-muted)]",children:"Forge shows the canonical overnight session by default. This view reveals the evidence stack underneath it: raw provider or historical imported records first, then Forge-normalized sleep segments."}),s?e.jsx("div",{className:"text-sm text-[var(--ui-ink-muted)]",children:"Loading raw sleep evidence…"}):null,s?null:e.jsxs("div",{className:"grid gap-5",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(v,{className:b("border-transparent",Be(k.rawDataStatus)),children:qe(k.rawDataStatus)}),k.rawDataStatus==="historical_raw"?e.jsx(v,{tone:"meta",children:"Partial evidence"}):null]}),e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Raw data"}),k.sourceRecords.length?k.sourceRecords.map(o=>e.jsxs("div",{className:"rounded-[16px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-3",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(v,{className:b("border-transparent",Ce(o)),children:o.qualityKind==="provider_native"?"Provider raw":"Historical raw"}),e.jsx(v,{tone:"meta",className:"capitalize",children:o.rawStage.replaceAll("_"," ")}),e.jsx("span",{className:"text-sm text-[var(--ui-ink-medium)]",children:q(o.startedAt,o.endedAt,o.sourceTimezone)})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-[var(--ui-ink-muted)]",children:o.providerRecordType.replaceAll("_"," ")}),e.jsx(C,{type:"button",variant:"secondary",className:"h-8 rounded-full px-3",onClick:()=>y(M=>M===o.id?null:o.id),children:c===o.id?"Hide JSON":"See JSON"})]})]}),e.jsx("div",{className:"mt-3 text-sm text-[var(--ui-ink-muted)]",children:p(Math.max(0,Math.round((new Date(o.endedAt).getTime()-new Date(o.startedAt).getTime())/1e3)))}),c===o.id?e.jsx("pre",{className:"mt-3 overflow-x-auto rounded-[14px] border border-[var(--ui-border-subtle)] bg-[var(--ui-code-bg)] p-3 text-xs leading-6 text-[var(--ui-ink-medium)]",children:JSON.stringify({payload:o.payload,metadata:o.metadata},null,2)}):null]},o.id)):e.jsx("div",{className:"rounded-[16px] border border-dashed border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4 text-sm text-[var(--ui-ink-muted)]",children:"No raw data was stored for this night."})]}),e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Sleep segments"}),k.segments.length?k.segments.map(o=>e.jsx("div",{className:"rounded-[16px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-3",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(v,{tone:"meta",className:"capitalize",children:o.stage.replaceAll("_"," ")}),e.jsx(v,{tone:"meta",children:o.qualityKind==="provider_native"?"provider-backed":"historical"}),e.jsx("span",{className:"text-sm text-[var(--ui-ink-medium)]",children:q(o.startedAt,o.endedAt,o.sourceTimezone)})]}),e.jsx("span",{className:"text-sm text-[var(--ui-ink-muted)]",children:p(Math.max(0,Math.round((new Date(o.endedAt).getTime()-new Date(o.startedAt).getTime())/1e3)))})]})},o.id)):e.jsx("div",{className:"rounded-[16px] border border-dashed border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4 text-sm text-[var(--ui-ink-muted)]",children:"No normalized sleep segments were stored for this night."})]})]})]}):null]})})}function Xe(){var V;const r=ne(),a=se(),[t,s]=g.useState({}),[n,u]=g.useState(null),[d,x]=g.useState("summary"),l=Array.isArray(r==null?void 0:r.selectedUserIds)?r.selectedUserIds:[],i=r==null?void 0:r.snapshot,c=_({queryKey:["forge-sleep",...l],queryFn:async()=>(await ge(l)).sleep}),y=_({queryKey:["forge-sleep-raw",n],enabled:!!n,queryFn:async()=>he(n)}),k=_({queryKey:["forge-sleep-values",...l],queryFn:async()=>(await fe(l)).values}),$=_({queryKey:["forge-sleep-patterns",...l],queryFn:async()=>(await be(l)).patterns}),E=_({queryKey:["forge-sleep-behaviors",...l],queryFn:async()=>(await je(l)).behaviors}),R=_({queryKey:["forge-sleep-beliefs",...l],queryFn:async()=>(await ye(l)).beliefs}),o=_({queryKey:["forge-sleep-reports",...l],queryFn:async()=>(await ke(l)).reports});g.useEffect(()=>{c.data&&s(Object.fromEntries(c.data.sessions.map(m=>[m.id,B(m)])))},[c.data]),g.useEffect(()=>{var N,j,S;if(!((N=c.data)!=null&&N.sessions.length)){u(null);return}c.data.sessions.some(K=>K.id===n)||u(((j=c.data.latestNight)==null?void 0:j.sleepId)??((S=c.data.sessions[0])==null?void 0:S.id)??null)},[n,c.data]),g.useEffect(()=>{x("summary")},[n]);const M=ie({mutationFn:async m=>de(m.sleepId,{qualitySummary:m.qualitySummary,notes:m.notes,tags:m.tagsText.split(",").map(N=>N.trim()).filter(Boolean),links:we(m.linkValues)}),onSuccess:async()=>{await a.invalidateQueries({queryKey:["forge-sleep"]}),await a.invalidateQueries({queryKey:["forge-sleep-raw"]})}});if(c.isLoading)return e.jsx(le,{eyebrow:"Sleep",title:"Loading sleep surface",description:"Reading canonical nights, calendar summaries, and sleep phase detail.",columns:2,blocks:6});if(c.isError||!c.data)return e.jsx(ce,{eyebrow:"Sleep",error:c.error??new Error("Sleep data unavailable"),onRetry:()=>void c.refetch()});const h=c.data,D=h.sessions,L=new Map(D.map(m=>[m.id,m])),f=(n?L.get(n):null)??(h.latestNight?L.get(h.latestNight.sleepId):null)??D[0]??null,P=f?t[f.id]??B(f):null,Y=Se({goals:(i==null?void 0:i.dashboard.goals)??[],projects:(i==null?void 0:i.dashboard.projects)??[],tasks:(i==null?void 0:i.dashboard.tasks)??[],habits:(i==null?void 0:i.dashboard.habits)??[],values:k.data??[],patterns:$.data??[],behaviors:E.data??[],beliefs:R.data??[],reports:o.data??[]});function X(m,N){s(j=>{const S=D.find(ee=>ee.id===m),K=j[m]??(S?B(S):{qualitySummary:"",notes:"",tagsText:"",linkValues:[]});return{...j,[m]:{...K,...N}}})}async function Z(m){const N=D.find(S=>S.id===m);if(!N)return;const j=t[m]??B(N);await M.mutateAsync({sleepId:m,qualitySummary:j.qualitySummary,notes:j.notes,tagsText:j.tagsText,linkValues:j.linkValues})}return e.jsxs("div",{className:"grid gap-5",children:[e.jsx(Ne,{eyebrow:"Health",title:"Sleep",description:"Canonical overnight sessions first, with last-night recovery, a clickable night calendar, and raw segment evidence only when you ask for it.",badge:`${D.length} nights`}),e.jsx(oe,{}),e.jsx(ue,{children:e.jsx(Fe,{latestNight:h.latestNight})}),e.jsx(me,{children:e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,0.95fr)_minmax(0,1.05fr)]",children:[e.jsx(F,{title:"Weekly average",value:p(h.summary.averageSleepSeconds),description:"Average overnight sleep duration across the recent week, used as the baseline for the latest-night comparison."}),e.jsx(F,{title:"Regularity",value:`${h.summary.averageRegularityScore}`,description:`Average bedtime drift ${h.summary.averageBedtimeConsistencyMinutes}m and wake drift ${h.summary.averageWakeConsistencyMinutes}m.`}),e.jsx(F,{title:"Restorative share",value:T(h.summary.averageRestorativeShare),description:`Deep + REM share across recent nights, with ${h.summary.reflectiveNightCount} nights already carrying context.`}),e.jsxs(w,{className:"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",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.18em] text-[var(--ui-ink-muted)]",children:"Recent stage mix"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:"Average nightly phases"})]}),e.jsx(re,{className:"size-5 text-[var(--primary)]"})]}),e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:h.stageAverages.length>0?h.stageAverages.slice(0,5).map(m=>e.jsxs(v,{tone:"meta",children:[I(m.stage).label," ",p(m.averageSeconds)]},m.stage)):e.jsx("div",{className:"text-sm text-[var(--ui-ink-muted)]",children:"Stage averages will appear once nights include phase data."})})]})]})}),e.jsx(xe,{children:e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,25rem)_minmax(0,1fr)]",children:[e.jsx(ze,{days:h.calendarDays,selectedSleepId:(f==null?void 0:f.id)??null,onSelect:m=>u(m)}),f&&P?e.jsx(Le,{session:f,draft:P,rawDetail:y.data??null,rawDetailLoading:y.isLoading,pending:M.isPending&&((V=M.variables)==null?void 0:V.sleepId)===f.id,tab:d,linkOptions:Y,onTabChange:x,onDraftChange:m=>X(f.id,m),onSave:()=>void Z(f.id)}):e.jsx(w,{className:"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-6 py-8 text-sm leading-6 text-[var(--ui-ink-muted)]",children:"Pick a night from the calendar to inspect its phase timing, stage summary, and reflection context."})]})})]})}export{Xe as SleepPage};
|