@mean-weasel/lineage 0.1.21 → 0.1.22
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/CHANGELOG.md +8 -0
- package/MANUAL_INSTALL_DOGFOOD.md +340 -0
- package/README.md +38 -9
- package/dist/runtime-build.json +4 -4
- package/dist/web/assets/{app-DX744BME.js → app-D-7R33Mc.js} +1 -1
- package/dist/web/assets/landing-DIjBBL33.js +2 -0
- package/dist/web/assets/{landing-Dmkx4R_N.css → landing-wy4L-yBm.css} +1 -1
- package/dist/web/index.html +1 -1
- package/dist/web/landing/index.html +2 -2
- package/package.json +2 -1
- package/dist/web/assets/landing-CPZnU7M8.js +0 -1
|
@@ -13,4 +13,4 @@ import{a as e,c as t,d as n,f as r,i,l as a,n as o,o as s,p as c,r as l,s as u,t
|
|
|
13
13
|
`),m=e=>e===`variation source`?`Copy source`:e===`agent brief`?`Copy prompt`:e===`link-child command`?`Copy link command`:`Copy command`,h=fh(a,s);async function _(e,t){try{await Bm(e),i(`ok`,`Copied ${t}`)}catch(e){i(`error`,e instanceof Error?e.message:String(e))}}async function v(){try{let t=await g(`/api/agent-claims`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({agentName:`Copied Lineage handoff`,channel:n?.channel,project:a,scopeType:`lineage_workspace`,targetId:h,targetTitle:n?`${n.title} lineage`:`Lineage workspace ${s}`,ttl:`20m`})});await Bm(_h(t.claim_token,c,e,p)),i(`ok`,`Copied claim-aware handoff for ${t.claim.id}`)}catch(e){i(`error`,e instanceof Error?e.message:String(e))}}return(0,X.jsxs)(`section`,{className:`lineage-handoff-panel`,"data-testid":`lineage-handoff-panel`,children:[(0,X.jsx)(`h3`,{children:`Agent handoff`}),(0,X.jsxs)(`div`,{className:`lineage-handoff-base ${n&&!n.is_latest?`branch`:``}`,children:[(0,X.jsx)(`span`,{children:n?`Agent will evolve`:`Choose a variation source`}),(0,X.jsx)(`strong`,{children:u}),n&&(0,X.jsx)(`small`,{children:[n.channel,n.status,n.review_state].filter(Boolean).join(` / `)}),n&&!n.is_latest&&(0,X.jsx)(`p`,{children:`Branch from here: this asset is not a latest leaf.`})]}),d.map(e=>(0,X.jsxs)(`div`,{className:`lineage-copy-row`,children:[(0,X.jsx)(`code`,{children:e.text}),(0,X.jsx)(`button`,{"aria-label":`Copy ${e.label}`,onClick:()=>void _(e.text,e.label),children:m(e.label)})]},e.label)),o.length>0&&(0,X.jsxs)(`div`,{className:`lineage-brief-group`,children:[(0,X.jsxs)(`div`,{className:`lineage-brief-head`,children:[(0,X.jsx)(`h4`,{children:`Re-roll queue`}),(0,X.jsx)(`button`,{"aria-label":`Copy re-roll queue handoff`,onClick:()=>void _(dh(l,o),`re-roll queue`),children:`Copy queue`})]}),(0,X.jsx)(`p`,{children:`Use this for repair work. Import outputs with reroll import; do not link them as lineage children.`}),(0,X.jsxs)(`div`,{className:`lineage-copy-row`,children:[(0,X.jsx)(`code`,{children:l}),(0,X.jsx)(`button`,{"aria-label":`Copy reroll list command`,onClick:()=>void _(l,`reroll list command`),children:`Copy command`})]}),o.map(e=>(0,X.jsxs)(`div`,{className:`lineage-copy-row`,children:[(0,X.jsxs)(`code`,{children:[e.asset_id,e.reroll_request?.notes?`: ${e.reroll_request.notes}`:``]}),(0,X.jsx)(`button`,{"aria-label":`Copy re-roll target ${e.asset_id}`,onClick:()=>void _(e.asset_id,`re-roll target`),children:`Copy target`})]},e.asset_id))]}),f.length>0&&(0,X.jsxs)(`div`,{className:`lineage-brief-group`,children:[(0,X.jsxs)(`div`,{className:`lineage-brief-head`,children:[(0,X.jsx)(`h4`,{children:`Generated brief`}),(0,X.jsx)(`button`,{"aria-label":`Copy full generated brief`,onClick:()=>void _(p,`full brief`),children:`Copy all`})]}),(0,X.jsx)(`p`,{children:`Use this bundle when asking an agent to continue from the chosen asset.`}),(0,X.jsx)(`button`,{"aria-label":`Copy claim-aware handoff`,className:`lineage-claim-handoff-button`,onClick:()=>v(),children:`Copy claim handoff`}),(0,X.jsxs)(`details`,{children:[(0,X.jsx)(`summary`,{children:`Commands and prompt`}),f.map(e=>(0,X.jsxs)(`div`,{className:`lineage-copy-row`,children:[(0,X.jsx)(`code`,{children:e.text}),(0,X.jsx)(`button`,{"aria-label":`Copy ${e.label}`,onClick:()=>void _(e.text,e.label),children:m(e.label)})]},e.label))]})]}),(0,X.jsx)(`button`,{"aria-label":f.length>0?`Regenerate agent brief`:`Generate agent brief`,onClick:r,children:f.length>0?`Regenerate brief`:`Generate brief`})]})}function dh(e,t){return[e,`For each pending target, ask for or use a target-specific repair prompt.`,`Run reroll plan for one target at a time, generate one file under .asset-scratch, then run reroll import.`,`Do not use link-child for re-roll outputs.`,...t.map(e=>`Target ${e.asset_id}: ${e.title}${e.reroll_request?.notes?` (${e.reroll_request.notes})`:``}`)].join(`
|
|
14
14
|
`)}function fh(e,t){return`${e}:lineage-workspace:${t}`}function ph(e){return`'${e.replace(/'/g,`'\\''`)}'`}function mh(e){let t=/\s--(db|profile)\s+('[^']*(?:'\\''[^']*)*'|"[^"]*"|\S+)/.exec(e);return t?` --${t[1]} ${t[2]}`:``}function hh(e){let t=/\s(?:next|inspect|link-child)\s/.exec(e);if(!t)throw Error(`Verified Lineage launcher missing from handoff command`);return e.slice(0,t.index)}function gh(e){return e.includes(`--claim-token`)?e:/\s--json$/.test(e)?e.replace(/\s--json$/,` --claim-token "$LINEAGE_CLAIM_TOKEN" --json`):`${e} --claim-token "$LINEAGE_CLAIM_TOKEN"`}function _h(e,t,n,r){let i=n?.handoff?.link_child_command||n?.handoff?.next_command||t,a=mh(i),o=`${hh(i)} agent heartbeat --claim-token "$LINEAGE_CLAIM_TOKEN"${a} --json`;return[`export LINEAGE_CLAIM_TOKEN=${ph(e)}`,o,t,n?.handoff?.inspect_command,n?.handoff?.link_child_command?gh(n.handoff.link_child_command):void 0,r?`Agent brief:\n${r}`:void 0].filter(e=>!!e).join(`
|
|
15
15
|
|
|
16
|
-
`)}function vh(e){let t=Ne(),{activeNode:n,brief:r,childAssetId:i,clearNextVariation:a,closePanel:o,latestNodes:s,linkChild:c,markReview:l,noteDirty:u,onSelectedAsset:d,nextVariationLimit:f,onToast:p,project:m,refreshBrief:h,saveRationale:g,selectNextBase:_,selectedNode:v,selectedNodes:y,selectionFull:b,refreshLineage:x,replaceNextVariation:S,selectionNote:C,setActiveNodeId:w,setChildAssetId:T,setDetailNodeId:E,setSelected:D,setSelectionNote:O,sideOpen:k,snapshot:A}=e,j=n?ve({hasLocal:!!n.local_path,hasS3:!!n.s3_key}):null,M=y.filter(e=>!e.is_latest),N=A.nodes.filter(e=>e.reroll_request?.status===`pending`);return(0,X.jsxs)(`aside`,{"aria-hidden":!k,className:`lineage-side ${k?``:`collapsed`}`,id:`lineage-selection-panel`,children:[(0,X.jsxs)(`div`,{className:`lineage-side-head`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h3`,{children:`Next variation`}),(0,X.jsx)(`p`,{className:`muted-copy`,children:`Choose what the agent will evolve next; double-click nodes for full details.`})]}),(0,X.jsx)(`button`,{"aria-label":`Close lineage selection panel`,className:`icon-button`,onClick:o,type:`button`,children:`×`})]}),(0,X.jsxs)(`section`,{className:`lineage-next-panel`,children:[(0,X.jsxs)(`div`,{className:`lineage-panel-title-row`,children:[(0,X.jsx)(`h3`,{children:`Using for next variation`}),(0,X.jsxs)(`span`,{className:`lineage-count-pill ${b?`full`:``}`,children:[y.length,`/`,f]})]}),y.length>0&&(0,X.jsx)(`div`,{className:`lineage-panel-action-row`,children:(0,X.jsx)(`button`,{onClick:()=>void a(),type:`button`,children:`Clear all`})}),M.length>0&&(0,X.jsxs)(`div`,{className:`lineage-selection-warning`,role:`status`,children:[M.length,` selected asset`,M.length===1?` is`:`s are`,` not latest. This is valid for branching, but clear or replace it if you meant to continue from the newest leaves.`]}),y.length>0?y.map(e=>(0,X.jsxs)(`div`,{className:`lineage-candidate selected`,children:[(0,X.jsxs)(`button`,{"aria-label":`Inspect asset used for next variation ${e.title}`,className:`lineage-candidate-main`,onClick:()=>{w(e.asset_id),d(e.asset_id)},children:[(0,X.jsx)(`span`,{children:e.title}),(0,X.jsx)(`code`,{children:e.asset_id}),(0,X.jsx)(lh,{node:e})]}),!e.is_latest&&(0,X.jsx)(`span`,{className:`lineage-candidate-warning`,children:`Not latest`}),(0,X.jsxs)(`div`,{className:`lineage-candidate-actions`,children:[y.length>1&&(0,X.jsx)(`button`,{className:`lineage-candidate-action secondary`,onClick:()=>S(e),children:`Use only this`}),(0,X.jsx)(`button`,{className:`lineage-candidate-action remove`,onClick:()=>void a(e.asset_id),children:`Remove`})]})]},e.asset_id)):(0,X.jsxs)(`p`,{className:`muted-copy`,children:[`Choose up to `,f,` assets to guide the next generation.`]}),y.length>1&&(0,X.jsx)(`p`,{className:`muted-copy`,children:`The agent will use these as separate next-variation bases; imported outputs should link back to the matching selected parent.`})]}),(0,X.jsx)(yh,{activeNode:n,onSelectedAsset:d,onToast:p,project:m,refreshLineage:x,setActiveNodeId:w,snapshot:A}),(0,X.jsxs)(`section`,{className:`lineage-next-panel`,children:[(0,X.jsxs)(`div`,{className:`lineage-panel-title-row`,children:[(0,X.jsx)(`h3`,{children:`Re-roll queue`}),(0,X.jsx)(`span`,{className:`lineage-count-pill`,children:N.length})]}),N.length>0?N.map(e=>(0,X.jsx)(`div`,{className:`lineage-candidate ${e.asset_id===n?.asset_id?`active`:``}`,children:(0,X.jsxs)(`button`,{"aria-label":`Inspect re-roll target ${e.title}`,className:`lineage-candidate-main`,onClick:()=>{w(e.asset_id),d(e.asset_id)},children:[(0,X.jsx)(`span`,{children:e.title}),(0,X.jsx)(`code`,{children:e.asset_id}),e.reroll_request?.notes&&(0,X.jsx)(`small`,{children:e.reroll_request.notes})]})},e.asset_id)):(0,X.jsx)(`p`,{className:`muted-copy`,children:`No pending re-roll targets.`})]}),(0,X.jsxs)(`section`,{className:`lineage-next-panel`,children:[(0,X.jsx)(`h3`,{children:`Latest candidates`}),s.length>0?s.map(e=>{let t=!e.user_selected&&b;return(0,X.jsxs)(`div`,{className:`lineage-candidate ${e.asset_id===n?.asset_id?`active`:``} ${e.user_selected?`selected`:``}`,children:[(0,X.jsxs)(`button`,{"aria-label":`Inspect ${e.title}`,className:`lineage-candidate-main`,onClick:()=>{w(e.asset_id),d(e.asset_id)},children:[(0,X.jsx)(`span`,{children:e.title}),(0,X.jsx)(`code`,{children:e.asset_id}),(0,X.jsx)(lh,{node:e})]}),(0,X.jsxs)(`div`,{className:`lineage-candidate-actions`,children:[(0,X.jsx)(`button`,{"aria-label":e.user_selected?`Remove ${e.title} from next variation`:`Use ${e.title} for next variation`,className:`lineage-candidate-action ${e.user_selected?`remove`:``}`,disabled:t,onClick:()=>e.user_selected?void a(e.asset_id):_(e),children:e.user_selected?`Remove`:t?`Selection full`:`Use for next variation`}),!e.user_selected&&y.length>0&&(0,X.jsx)(`button`,{className:`lineage-candidate-action secondary`,onClick:()=>S(e),children:`Replace selection`})]})]},e.asset_id)}):(0,X.jsx)(`p`,{className:`muted-copy`,children:`No latest leaves yet.`})]}),(0,X.jsx)(uh,{brief:r,cli:t,nextBase:v,onRefreshBrief:()=>void h(),onToast:p,project:m,rerollTargets:N,rootAssetId:A.root_asset_id}),(0,X.jsx)(`h3`,{children:`Inspecting`}),n?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`strong`,{children:n.title}),(0,X.jsx)(`code`,{children:n.asset_id}),(0,X.jsxs)(`dl`,{children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Storage`}),(0,X.jsx)(`dd`,{children:j&&(0,X.jsx)(`span`,{className:`storage-chip ${j.kind}`,children:j.label})})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Source`}),(0,X.jsx)(`dd`,{children:n.source})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Review`}),(0,X.jsx)(`dd`,{children:n.review_state})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Latest`}),(0,X.jsx)(`dd`,{children:n.is_latest?`yes`:`no`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Next variation`}),(0,X.jsx)(`dd`,{children:n.user_selected?`yes`:`no`})]})]}),n.user_selected&&!n.is_latest&&(0,X.jsx)(`div`,{className:`lineage-selection-warning`,role:`status`,children:`This selected asset is not a latest leaf. Keep it selected to branch from an earlier idea, or replace it with the current inspected asset.`}),(0,X.jsxs)(`label`,{className:`lineage-note-field`,children:[`Variation rationale`,(0,X.jsx)(`textarea`,{value:C,onChange:e=>O(e.target.value),placeholder:`Why should the next generation branch from this asset?`}),(0,X.jsx)(`span`,{className:`lineage-note-status ${u?`dirty`:``}`,children:n.user_selected?u?`Unsaved rationale`:`Rationale saved for next variation`:`Rationale saves when this is used for next variation`})]}),(0,X.jsxs)(`div`,{className:`lineage-side-actions`,children:[(0,X.jsx)(`button`,{"aria-label":n.user_selected?`Remove ${n.title} from next variation`:`Use ${n.title} for next variation`,className:`primary-lite`,disabled:!n.user_selected&&b,onClick:()=>n.user_selected?void a(n.asset_id):D(),children:n.user_selected?`Remove from next variation`:b?`Selection full`:`Use for next variation`}),n.user_selected&&y.length>1&&(0,X.jsx)(`button`,{onClick:()=>S(n,C),children:`Use only this`}),!n.user_selected&&y.length>0&&(0,X.jsx)(`button`,{onClick:()=>S(n,C),children:`Replace selection`}),(0,X.jsx)(`button`,{disabled:!n.user_selected||!u,onClick:g,children:`Save rationale`}),(0,X.jsx)(`button`,{"aria-label":`Open detail for ${n.title}`,onClick:()=>E(n.asset_id),children:`Open detail`}),(0,X.jsx)(`button`,{"aria-label":`Approve ${n.title}`,onClick:()=>void l(`approved`),children:`Approve`}),(0,X.jsx)(`button`,{"aria-label":`Reject ${n.title}`,onClick:()=>void l(`rejected`),children:`Reject`}),(0,X.jsx)(`button`,{"aria-label":`Ignore ${n.title}`,onClick:()=>void l(`ignored`),children:`Ignore`})]}),(0,X.jsxs)(`form`,{className:`lineage-link-form`,onSubmit:e=>{e.preventDefault(),c()},children:[(0,X.jsxs)(`label`,{children:[`Child asset ID`,(0,X.jsx)(`input`,{value:i,onChange:e=>T(e.target.value),placeholder:`local-... or catalog id`})]}),(0,X.jsx)(`button`,{disabled:!i.trim(),type:`submit`,children:`Link child`})]})]}):(0,X.jsx)(`p`,{className:`muted-copy`,children:`No lineage node selected.`})]})}function yh({activeNode:e,onSelectedAsset:t,onToast:n,project:r,refreshLineage:i,setActiveNodeId:a,snapshot:o}){let s=(0,p.useMemo)(()=>Sh(o.tasks||[]),[o.tasks]),c=s.filter(e=>Ch(e)).length,l=(0,p.useMemo)(()=>new Map(o.nodes.map(e=>[e.asset_id,e])),[o.nodes]);return(0,X.jsxs)(`section`,{className:`lineage-next-panel lineage-task-queue-panel`,children:[(0,X.jsxs)(`div`,{className:`lineage-panel-title-row`,children:[(0,X.jsx)(`h3`,{children:`Task queue`}),(0,X.jsx)(`span`,{className:`lineage-count-pill`,children:c})]}),s.length>0?s.map(o=>(0,X.jsx)(bh,{active:o.target_asset_id===e?.asset_id,node:l.get(o.target_asset_id),onInspect:()=>{a(o.target_asset_id),t(o.target_asset_id)},onToast:n,project:r,refreshLineage:i,task:o},`${o.id}:${o.updated_at}`)):(0,X.jsx)(`p`,{className:`muted-copy`,children:`No open lineage tasks.`})]})}function bh({active:e,node:t,onInspect:n,onToast:r,project:i,refreshLineage:a,task:o}){let s=o.status===`claimed`||o.status===`in_progress`,c=o.status===`pending`,[l,u]=(0,p.useState)(o.instructions||``),[d,f]=(0,p.useState)(``),[m,h]=(0,p.useState)(!1);(0,p.useEffect)(()=>u(o.instructions||``),[o.id,o.instructions]);async function _(e,t,n){h(!0);try{return await g(e,{body:JSON.stringify({project:i,...t}),headers:{"Content-Type":`application/json`},method:`POST`}),r(`ok`,n),await a(),!0}catch(e){return r(`error`,e instanceof Error?e.message:String(e)),!1}finally{h(!1)}}async function v(e){e.preventDefault(),await _(`/api/lineage/tasks/${encodeURIComponent(o.id)}/instructions`,{instructions:l},`Updated ${Th(o)} instructions`)}async function y(e){e.preventDefault();let t=d.trim();t&&await _(`/api/lineage/tasks/${encodeURIComponent(o.id)}/comment`,{actor:`human`,message:t},`Commented on ${Th(o)}`)&&f(``)}async function b(){window.confirm(`Unlock ${Th(o)} for human edits?`)&&await _(`/api/lineage/tasks/${encodeURIComponent(o.id)}/override`,{actor:`human`,reason:`Human unlocked task from lineage UI.`},`Unlocked ${Th(o)}`)}async function x(){window.confirm(s?`Cancel ${Th(o)} while an agent is working?`:`Cancel ${Th(o)}?`)&&await _(`/api/lineage/tasks/${encodeURIComponent(o.id)}/cancel`,{actor:`human`,confirmWrite:!0,override:s},`Cancelled ${Th(o)}`)}return(0,X.jsxs)(`article`,{className:`lineage-task-card ${e?`active`:``} ${s?`locked`:o.status}`,children:[(0,X.jsxs)(`button`,{"aria-label":`Inspect task target ${t?.title||o.target_asset_id}`,className:`lineage-task-target`,onClick:n,type:`button`,children:[(0,X.jsx)(`span`,{children:t?.title||o.target_asset_id}),(0,X.jsx)(`code`,{children:o.target_asset_id})]}),(0,X.jsxs)(`div`,{className:`lineage-task-meta`,children:[(0,X.jsx)(`span`,{className:`lineage-task-status ${o.status}`,children:wh(o.status)}),(0,X.jsx)(`span`,{children:o.task_type})]}),c?(0,X.jsxs)(`form`,{className:`lineage-task-form`,onSubmit:v,children:[(0,X.jsxs)(`label`,{children:[`Instructions`,(0,X.jsx)(`textarea`,{"aria-label":`Instructions for ${o.id}`,value:l,onChange:e=>u(e.target.value)})]}),(0,X.jsxs)(`div`,{className:`lineage-task-actions`,children:[(0,X.jsx)(`button`,{disabled:m||l===(o.instructions||``),type:`submit`,children:`Save instructions`}),(0,X.jsx)(`button`,{disabled:m,onClick:x,type:`button`,children:`Cancel`})]})]}):(0,X.jsxs)(`div`,{className:`lineage-task-locked-body`,children:[(0,X.jsxs)(`label`,{children:[`Instructions`,(0,X.jsx)(`textarea`,{"aria-label":`Locked instructions for ${o.id}`,disabled:!0,readOnly:!0,value:l||`No instructions.`})]}),s&&(0,X.jsx)(xh,{claim:o.active_claim}),s&&(0,X.jsxs)(`form`,{className:`lineage-task-form`,onSubmit:y,children:[(0,X.jsxs)(`label`,{children:[`Comment`,(0,X.jsx)(`textarea`,{"aria-label":`Comment for ${o.id}`,value:d,onChange:e=>f(e.target.value)})]}),(0,X.jsxs)(`div`,{className:`lineage-task-actions`,children:[(0,X.jsx)(`button`,{disabled:m||!d.trim(),type:`submit`,children:`Add comment`}),(0,X.jsx)(`button`,{disabled:m,onClick:b,type:`button`,children:`Unlock`}),(0,X.jsx)(`button`,{disabled:m,onClick:x,type:`button`,children:`Cancel`})]})]})]})]})}function xh({claim:e}){return e?(0,X.jsxs)(`p`,{className:`lineage-task-claim ${e.derived_state===`active`?`active`:e.derived_state}`,children:[(0,X.jsxs)(`span`,{children:[wh(e.derived_state),` claim`]}),(0,X.jsx)(`strong`,{children:e.agent_name})]}):(0,X.jsx)(`p`,{className:`lineage-task-claim`,children:`Claimed by agent`})}function Sh(e){return[...e].sort((e,t)=>{let n=+!Ch(e),r=+!Ch(t);return n===r?e.created_at.localeCompare(t.created_at):n-r})}function Ch(e){return e.status===`pending`||e.status===`claimed`||e.status===`in_progress`}function wh(e){return e.replace(/_/g,` `)}function Th(e){return`${e.task_type} task`}function Eh(e,t){return e?.root_asset_id||t||``}function Dh(e){return`${e.title} (${e.root_asset_id})`}function Oh(e,t){let n=`${t.project}:lineage-workspace:${t.root_asset_id}`;return e.filter(e=>e.project!==t.project||e.status!==`active`||e.derived_state===`expired`?!1:e.scope_type===`lineage_workspace`?e.target_id===t.id||e.target_id===n:e.scope_type===`project_channel`)}function kh(e){return e.some(e=>e.derived_state===`stale`)?`stale`:e.some(e=>e.derived_state===`idle`)?`idle`:`active`}function Ah(e){let t=kh(e);return e.length===1?`${t===`active`?`Claimed`:t===`idle`?`Idle claim`:`Stale claim`} by ${e[0].agent_name}`:`${e.length} active claims`}function jh({activeWorkspace:e,closeSignal:t,loading:n,onNewLineage:r,onRefresh:i,onSelect:a,workspaces:o}){let[s,c]=(0,p.useState)(!1),[l,u]=(0,p.useState)([]),d=(0,p.useRef)(null),f=e?.project||o[0]?.project||``;(0,p.useEffect)(()=>{function e(e){d.current?.contains(e.target)||c(!1)}function t(e){e.key===`Escape`&&c(!1)}return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t,!0),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t,!0)}},[]),(0,p.useEffect)(()=>{c(!1)},[t]),(0,p.useEffect)(()=>{if(!f){u([]);return}let e=!1;return g(`/api/agent-claims?${new URLSearchParams({project:f})}`).then(t=>{e||u(t.claims)}).catch(()=>{e||u([])}),()=>{e=!0}},[f,t,o.length]);function m(e){c(!1),a(e)}let h=e?Oh(l,e):[];return(0,X.jsxs)(`section`,{"aria-label":`Lineage workspace picker`,className:`lineage-workspace-picker`,ref:d,children:[(0,X.jsxs)(`button`,{"aria-expanded":s,"aria-haspopup":`listbox`,className:`lineage-workspace-trigger`,disabled:n,onClick:()=>c(e=>!e),onKeyDown:e=>{e.key===`Escape`&&c(!1)},type:`button`,children:[(0,X.jsx)(`span`,{children:`Workspace`}),(0,X.jsx)(`strong`,{children:e?.title||`No workspace selected`}),(0,X.jsx)(`code`,{children:e?.root_asset_id||`Start with New lineage`}),(0,X.jsx)(Nh,{claims:h})]}),s&&(0,X.jsxs)(`div`,{className:`lineage-workspace-menu`,children:[(0,X.jsxs)(`div`,{className:`lineage-workspace-options`,role:`listbox`,children:[o.length===0&&(0,X.jsx)(`p`,{children:`No workspaces yet.`}),o.map(t=>(0,X.jsx)(Mh,{active:e?.id===t.id,claims:Oh(l,t),onSelect:()=>m(t.id),workspace:t},t.id))]}),(0,X.jsxs)(`footer`,{children:[(0,X.jsx)(`button`,{className:`secondary-button`,disabled:n,onClick:i,type:`button`,children:`Refresh`}),(0,X.jsx)(`button`,{className:`primary-button`,onClick:()=>{c(!1),r()},type:`button`,children:`New lineage`})]})]})]})}function Mh({active:e,claims:t,onSelect:n,workspace:r}){return(0,X.jsxs)(`button`,{"aria-selected":e,className:e?`active`:``,onClick:n,role:`option`,type:`button`,children:[(0,X.jsx)(`strong`,{children:r.title}),(0,X.jsx)(`code`,{children:r.root_asset_id}),(0,X.jsx)(`span`,{children:Dh(r)}),(0,X.jsx)(Nh,{claims:t})]})}function Nh({claims:e}){return e.length===0?null:(0,X.jsxs)(`small`,{className:`lineage-workspace-claim ${kh(e)}`,children:[(0,X.jsx)(se,{size:13}),(0,X.jsx)(`span`,{children:Ah(e)})]})}function Ph({activeWorkspace:e,actionsOpen:t,closeSignal:n,demoSeedStatus:r,edgeSummariesVisible:i,graphDirection:a,loading:o,onArchiveWorkspace:s,onActionsOpenChange:c,onDownloadSwissifierMedia:l,onEdgeSummariesVisible:u,onFitGraph:d,onGraphDirection:f,onIndexLocal:m,onNewLineage:h,onRefreshLineage:g,onRefreshWorkspaces:_,onReplayGrowth:v,onRestoreDemoMedia:y,onRestoreSwissifierMedia:b,onSeedDemo:x,onSeedSwissifierDemo:S,onSelectWorkspace:C,onTidyGraph:w,onToggleNextPanel:T,sideOpen:E,replayActive:D,snapshot:O,swissifierDemoStatus:k,workspaceLoading:A,workspaceProgress:j,workspaceRootAssetId:M,workspaces:N}){let P=r?`${r.present}/${r.total} SVG placeholders`:`Checking media`,F=k?`${k.present}/${k.total} PNG images`:`Checking media`,I=!!(k&&k.present===k.total),L=!!(k?.download_available&&!I),R=j===`downloading`?`Downloading rich demo media`:j===`downloaded`?`Rich demo media ready to seed`:j===`seeding`?`Creating rich demo workspace`:j===`indexing`?`Indexing 14 rich demo images`:j===`ready`?`Rich demo ready`:j===`error`?`Rich demo setup failed`:null,z=A||[`downloading`,`seeding`,`indexing`].includes(j||``),B=R||(O?`${O.nodes.length} nodes · ${O.edges.length} links`:M||`Choose a lineage workspace`);(0,p.useEffect)(()=>{c(!1)},[n,c]),(0,p.useEffect)(()=>{function e(e){e.key===`Escape`&&c(!1)}return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)},[c]);function V(e){c(!1),e()}function H(e){e.key===`Escape`&&(e.preventDefault(),c(!1))}return(0,X.jsxs)(`header`,{className:`lineage-header`,children:[(0,X.jsxs)(`div`,{className:`lineage-primary-controls`,children:[(0,X.jsx)(jh,{activeWorkspace:e,closeSignal:n,loading:z,onNewLineage:h,onRefresh:_,onSelect:C,workspaces:N}),(0,X.jsx)(`p`,{className:`lineage-toolbar-context`,children:B}),(0,X.jsx)(`button`,{"aria-pressed":D,className:`secondary-button lineage-replay-launch`,disabled:D||!O||O.nodes.length<2||O.edges.length===0,onClick:v,type:`button`,children:`Replay growth`}),(0,X.jsx)(`button`,{className:`primary-button`,onClick:h,type:`button`,children:`New lineage`})]}),(0,X.jsxs)(`details`,{className:`lineage-overflow`,onToggle:e=>c(e.currentTarget.open),open:t,children:[(0,X.jsx)(`summary`,{onKeyDown:H,tabIndex:0,children:`Actions`}),(0,X.jsxs)(`div`,{children:[!e&&(0,X.jsx)(`button`,{disabled:z,onClick:()=>V(x),type:`button`,children:`Load demo lineage`}),(0,X.jsxs)(`p`,{children:[(0,X.jsx)(`strong`,{children:`QA seed media`}),(0,X.jsx)(`span`,{children:F})]}),(0,X.jsxs)(`p`,{children:[(0,X.jsx)(`strong`,{children:`Basic SVG demo`}),(0,X.jsx)(`span`,{children:P})]}),(0,X.jsx)(`button`,{disabled:z||r?.present===r?.total,onClick:y,type:`button`,children:`Restore basic media`}),(0,X.jsx)(`button`,{disabled:z,onClick:()=>V(x),type:`button`,children:`Load SVG placeholder demo`}),(0,X.jsxs)(`p`,{children:[(0,X.jsx)(`strong`,{children:`Swissifier rich demo`}),(0,X.jsx)(`span`,{children:F})]}),(0,X.jsx)(`button`,{disabled:z||!L,onClick:l,type:`button`,children:`Download rich images`}),(0,X.jsx)(`button`,{disabled:z||I,onClick:b,type:`button`,children:`Restore rich media`}),(0,X.jsx)(`button`,{disabled:z,onClick:()=>V(S),type:`button`,children:`Load rich image demo`}),(0,X.jsxs)(`label`,{className:`lineage-action-select`,children:[(0,X.jsx)(`span`,{children:`Direction`}),(0,X.jsxs)(`select`,{"aria-label":`Lineage graph direction`,disabled:!O||o,onChange:e=>f(e.target.value),value:a,children:[(0,X.jsx)(`option`,{value:`LR`,children:`Left to right`}),(0,X.jsx)(`option`,{value:`TB`,children:`Top to bottom`}),(0,X.jsx)(`option`,{value:`RL`,children:`Right to left`}),(0,X.jsx)(`option`,{value:`BT`,children:`Bottom to top`})]})]}),(0,X.jsx)(`button`,{"aria-pressed":i,disabled:!O,onClick:()=>V(u),type:`button`,children:i?`Hide edge labels`:`Show edge labels`}),(0,X.jsx)(`button`,{disabled:!O,onClick:()=>V(d),type:`button`,children:`Fit graph`}),(0,X.jsx)(`button`,{disabled:!O,onClick:()=>V(w),type:`button`,children:`Tidy tree`}),(0,X.jsx)(`button`,{"aria-controls":`lineage-selection-panel`,"aria-expanded":E,disabled:!O,onClick:()=>V(T),type:`button`,children:`Manage selection`}),(0,X.jsx)(`button`,{disabled:z||!e,onClick:()=>V(s),type:`button`,children:`Archive current lineage`}),(0,X.jsx)(`button`,{disabled:o||z,onClick:()=>V(m),type:`button`,children:`Index local`}),(0,X.jsx)(`button`,{disabled:o||!O,onClick:()=>V(g),type:`button`,children:`Refresh graph`}),(0,X.jsx)(`button`,{disabled:z,onClick:()=>V(_),type:`button`,children:`Refresh workspaces`})]})]})]})}async function Fh(e,t,n){await g(`/api/lineage/layout`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({confirmWrite:!0,positions:n,project:e,rootAssetId:t})})}function Ih(e,t,n){return hd(e.filter(e=>e.type!==`remove`),t)}function Lh(e,t){return!e?.user_selected||t!==`rejected`&&t!==`ignored`?null:{confirmation:`${e.title} is being used for next variation. Marking it ${t} will remove it from next variation.`,clearsSelection:!0}}var Rh=Object.defineProperty,zh=(e,t,n)=>t in e?Rh(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Bh=(e,t)=>{for(var n in t)Rh(e,n,{get:t[n],enumerable:!0})},Vh=(e,t,n)=>zh(e,typeof t==`symbol`?t:t+``,n),Hh={};Bh(Hh,{Graph:()=>Gh,alg:()=>rg,json:()=>Qh,version:()=>Zh});var Uh=Object.defineProperty,Wh=(e,t)=>{for(var n in t)Uh(e,n,{get:t[n],enumerable:!0})},Gh=class{constructor(e){this._isDirected=!0,this._isMultigraph=!1,this._isCompound=!1,this._nodes={},this._in={},this._preds={},this._out={},this._sucs={},this._edgeObjs={},this._edgeLabels={},this._nodeCount=0,this._edgeCount=0,this._defaultNodeLabelFn=()=>{},this._defaultEdgeLabelFn=()=>{},e&&(this._isDirected=`directed`in e?e.directed:!0,this._isMultigraph=`multigraph`in e?e.multigraph:!1,this._isCompound=`compound`in e?e.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children[`\0`]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(e){return this._label=e,this}graph(){return this._label}setDefaultNodeLabel(e){return typeof e==`function`?this._defaultNodeLabelFn=e:this._defaultNodeLabelFn=()=>e,this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){return this.nodes().filter(e=>Object.keys(this._in[e]).length===0)}sinks(){return this.nodes().filter(e=>Object.keys(this._out[e]).length===0)}setNodes(e,t){return e.forEach(e=>{t===void 0?this.setNode(e):this.setNode(e,t)}),this}setNode(e,t){return e in this._nodes?(arguments.length>1&&(this._nodes[e]=t),this):(this._nodes[e]=arguments.length>1?t:this._defaultNodeLabelFn(e),this._isCompound&&(this._parent[e]=`\0`,this._children[e]={},this._children[`\0`][e]=!0),this._in[e]={},this._preds[e]={},this._out[e]={},this._sucs[e]={},++this._nodeCount,this)}node(e){return this._nodes[e]}hasNode(e){return e in this._nodes}removeNode(e){if(e in this._nodes){let t=e=>this.removeEdge(this._edgeObjs[e]);delete this._nodes[e],this._isCompound&&(this._removeFromParentsChildList(e),delete this._parent[e],this.children(e).forEach(e=>{this.setParent(e)}),delete this._children[e]),Object.keys(this._in[e]).forEach(t),delete this._in[e],delete this._preds[e],Object.keys(this._out[e]).forEach(t),delete this._out[e],delete this._sucs[e],--this._nodeCount}return this}setParent(e,t){if(!this._isCompound)throw Error(`Cannot set parent in a non-compound graph`);if(t===void 0)t=`\0`;else{t+=``;for(let n=t;n!==void 0;n=this.parent(n))if(n===e)throw Error(`Setting `+t+` as parent of `+e+` would create a cycle`);this.setNode(t)}return this.setNode(e),this._removeFromParentsChildList(e),this._parent[e]=t,this._children[t][e]=!0,this}parent(e){if(this._isCompound){let t=this._parent[e];if(t!==`\0`)return t}}children(e=`\0`){if(this._isCompound){let t=this._children[e];if(t)return Object.keys(t)}else{if(e===`\0`)return this.nodes();if(this.hasNode(e))return[]}return[]}predecessors(e){let t=this._preds[e];if(t)return Object.keys(t)}successors(e){let t=this._sucs[e];if(t)return Object.keys(t)}neighbors(e){let t=this.predecessors(e);if(t){let n=new Set(t);for(let t of this.successors(e))n.add(t);return Array.from(n.values())}}isLeaf(e){let t;return t=this.isDirected()?this.successors(e):this.neighbors(e),t.length===0}filterNodes(e){let t=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});t.setGraph(this.graph()),Object.entries(this._nodes).forEach(([n,r])=>{e(n)&&t.setNode(n,r)}),Object.values(this._edgeObjs).forEach(e=>{t.hasNode(e.v)&&t.hasNode(e.w)&&t.setEdge(e,this.edge(e))});let n={},r=e=>{let i=this.parent(e);return!i||t.hasNode(i)?(n[e]=i??void 0,i??void 0):i in n?n[i]:r(i)};return this._isCompound&&t.nodes().forEach(e=>t.setParent(e,r(e))),t}setDefaultEdgeLabel(e){return typeof e==`function`?this._defaultEdgeLabelFn=e:this._defaultEdgeLabelFn=()=>e,this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(e,t){return e.reduce((e,n)=>(t===void 0?this.setEdge(e,n):this.setEdge(e,n,t),n)),this}setEdge(e,t,n,r){let i,a,o,s,c=!1;typeof e==`object`&&e&&`v`in e?(i=e.v,a=e.w,o=e.name,arguments.length===2&&(s=t,c=!0)):(i=e,a=t,o=r,arguments.length>2&&(s=n,c=!0)),i=``+i,a=``+a,o!==void 0&&(o=``+o);let l=Jh(this._isDirected,i,a,o);if(l in this._edgeLabels)return c&&(this._edgeLabels[l]=s),this;if(o!==void 0&&!this._isMultigraph)throw Error(`Cannot set a named edge when isMultigraph = false`);this.setNode(i),this.setNode(a),this._edgeLabels[l]=c?s:this._defaultEdgeLabelFn(i,a,o);let u=Yh(this._isDirected,i,a,o);return i=u.v,a=u.w,Object.freeze(u),this._edgeObjs[l]=u,Kh(this._preds[a],i),Kh(this._sucs[i],a),this._in[a][l]=u,this._out[i][l]=u,this._edgeCount++,this}edge(e,t,n){let r=arguments.length===1?Xh(this._isDirected,e):Jh(this._isDirected,e,t,n);return this._edgeLabels[r]}edgeAsObj(e,t,n){let r=arguments.length===1?this.edge(e):this.edge(e,t,n);return typeof r==`object`?r:{label:r}}hasEdge(e,t,n){return(arguments.length===1?Xh(this._isDirected,e):Jh(this._isDirected,e,t,n))in this._edgeLabels}removeEdge(e,t,n){let r=arguments.length===1?Xh(this._isDirected,e):Jh(this._isDirected,e,t,n),i=this._edgeObjs[r];if(i){let e=i.v,t=i.w;delete this._edgeLabels[r],delete this._edgeObjs[r],qh(this._preds[t],e),qh(this._sucs[e],t),delete this._in[t][r],delete this._out[e][r],this._edgeCount--}return this}inEdges(e,t){return this.isDirected()?this.filterEdges(this._in[e],e,t):this.nodeEdges(e,t)}outEdges(e,t){return this.isDirected()?this.filterEdges(this._out[e],e,t):this.nodeEdges(e,t)}nodeEdges(e,t){if(e in this._nodes)return this.filterEdges({...this._in[e],...this._out[e]},e,t)}_removeFromParentsChildList(e){delete this._children[this._parent[e]][e]}filterEdges(e,t,n){if(!e)return;let r=Object.values(e);return n?r.filter(e=>e.v===t&&e.w===n||e.v===n&&e.w===t):r}};function Kh(e,t){e[t]?e[t]++:e[t]=1}function qh(e,t){e[t]!==void 0&&!--e[t]&&delete e[t]}function Jh(e,t,n,r){let i=``+t,a=``+n;if(!e&&i>a){let e=i;i=a,a=e}return i+``+a+``+(r===void 0?`\0`:r)}function Yh(e,t,n,r){let i=``+t,a=``+n;if(!e&&i>a){let e=i;i=a,a=e}let o={v:i,w:a};return r&&(o.name=r),o}function Xh(e,t){return Jh(e,t.v,t.w,t.name)}var Zh=`4.0.1`,Qh={};Wh(Qh,{read:()=>ng,write:()=>$h});function $h(e){let t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:eg(e),edges:tg(e)},n=e.graph();return n!==void 0&&(t.value=structuredClone(n)),t}function eg(e){return e.nodes().map(t=>{let n=e.node(t),r=e.parent(t),i={v:t};return n!==void 0&&(i.value=n),r!==void 0&&(i.parent=r),i})}function tg(e){return e.edges().map(t=>{let n=e.edge(t),r={v:t.v,w:t.w};return t.name!==void 0&&(r.name=t.name),n!==void 0&&(r.value=n),r})}function ng(e){let t=new Gh(e.options);return e.value!==void 0&&t.setGraph(e.value),e.nodes.forEach(e=>{t.setNode(e.v,e.value),e.parent&&t.setParent(e.v,e.parent)}),e.edges.forEach(e=>{t.setEdge({v:e.v,w:e.w,name:e.name},e.value)}),t}var rg={};Wh(rg,{CycleException:()=>vg,bellmanFord:()=>ag,components:()=>sg,dijkstra:()=>ug,dijkstraAll:()=>fg,findCycles:()=>mg,floydWarshall:()=>gg,isAcyclic:()=>bg,postorder:()=>wg,preorder:()=>Tg,prim:()=>Eg,shortestPaths:()=>Dg,tarjan:()=>pg,topsort:()=>yg});var ig=()=>1;function ag(e,t,n,r){return og(e,String(t),n||ig,r||function(t){return e.outEdges(t)})}function og(e,t,n,r){let i={},a,o=0,s=e.nodes(),c=function(e){let t=n(e);i[e.v].distance+t<i[e.w].distance&&(i[e.w]={distance:i[e.v].distance+t,predecessor:e.v},a=!0)},l=function(){s.forEach(function(e){r(e).forEach(function(t){let n=t.v===e?t.v:t.w,r=n===t.v?t.w:t.v;c({v:n,w:r})})})};s.forEach(function(e){i[e]={distance:e===t?0:1/0,predecessor:``}});let u=s.length;for(let e=1;e<u&&(a=!1,o++,l(),a);e++);if(o===u-1&&(a=!1,l(),a))throw Error(`The graph contains a negative weight cycle`);return i}function sg(e){let t={},n=[],r;function i(n){n in t||(t[n]=!0,r.push(n),e.successors(n).forEach(i),e.predecessors(n).forEach(i))}return e.nodes().forEach(function(e){r=[],i(e),r.length&&n.push(r)}),n}var cg=class{constructor(){this._arr=[],this._keyIndices={}}size(){return this._arr.length}keys(){return this._arr.map(e=>e.key)}has(e){return e in this._keyIndices}priority(e){let t=this._keyIndices[e];if(t!==void 0)return this._arr[t].priority}min(){if(this.size()===0)throw Error(`Queue underflow`);return this._arr[0].key}add(e,t){let n=this._keyIndices,r=String(e);if(!(r in n)){let e=this._arr,i=e.length;return n[r]=i,e.push({key:r,priority:t}),this._decrease(i),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);let e=this._arr.pop();return delete this._keyIndices[e.key],this._heapify(0),e.key}decrease(e,t){let n=this._keyIndices[e];if(n===void 0)throw Error(`Key not found: ${e}`);let r=this._arr[n].priority;if(t>r)throw Error(`New priority is greater than current priority. Key: ${e} Old: ${r} New: ${t}`);this._arr[n].priority=t,this._decrease(n)}_heapify(e){let t=this._arr,n=2*e,r=n+1,i=e;n<t.length&&(i=t[n].priority<t[i].priority?n:i,r<t.length&&(i=t[r].priority<t[i].priority?r:i),i!==e&&(this._swap(e,i),this._heapify(i)))}_decrease(e){let t=this._arr,n=t[e].priority,r;for(;e!==0&&(r=e>>1,!(t[r].priority<n));)this._swap(e,r),e=r}_swap(e,t){let n=this._arr,r=this._keyIndices,i=n[e],a=n[t];n[e]=a,n[t]=i,r[a.key]=e,r[i.key]=t}},lg=()=>1;function ug(e,t,n,r){return dg(e,String(t),n||lg,r||function(t){return e.outEdges(t)})}function dg(e,t,n,r){let i={},a=new cg,o,s,c=function(e){let t=e.v===o?e.w:e.v,r=i[t],c=n(e),l=s.distance+c;if(c<0)throw Error(`dijkstra does not allow negative edge weights. Bad edge: `+e+` Weight: `+c);l<r.distance&&(r.distance=l,r.predecessor=o,a.decrease(t,l))};for(e.nodes().forEach(function(e){let n=e===t?0:1/0;i[e]={distance:n,predecessor:``},a.add(e,n)});a.size()>0&&(o=a.removeMin(),s=i[o],s.distance!==1/0);)r(o).forEach(c);return i}function fg(e,t,n){return e.nodes().reduce(function(r,i){return r[i]=ug(e,i,t,n),r},{})}function pg(e){let t=0,n=[],r={},i=[];function a(o){let s=r[o]={onStack:!0,lowlink:t,index:t++};if(n.push(o),e.successors(o).forEach(function(e){e in r?r[e].onStack&&(s.lowlink=Math.min(s.lowlink,r[e].index)):(a(e),s.lowlink=Math.min(s.lowlink,r[e].lowlink))}),s.lowlink===s.index){let e=[],t;do t=n.pop(),r[t].onStack=!1,e.push(t);while(o!==t);i.push(e)}}return e.nodes().forEach(function(e){e in r||a(e)}),i}function mg(e){return pg(e).filter(function(t){return t.length>1||t.length===1&&e.hasEdge(t[0],t[0])})}var hg=()=>1;function gg(e,t,n){return _g(e,t||hg,n||function(t){return e.outEdges(t)})}function _g(e,t,n){let r={},i=e.nodes();return i.forEach(function(e){r[e]={},r[e][e]={distance:0,predecessor:``},i.forEach(function(t){e!==t&&(r[e][t]={distance:1/0,predecessor:``})}),n(e).forEach(function(n){let i=n.v===e?n.w:n.v,a=t(n);r[e][i]={distance:a,predecessor:e}})}),i.forEach(function(e){let t=r[e];i.forEach(function(n){let a=r[n];i.forEach(function(n){let r=a[e],i=t[n],o=a[n],s=r.distance+i.distance;s<o.distance&&(o.distance=s,o.predecessor=i.predecessor)})})}),r}var vg=class extends Error{constructor(...e){super(...e)}};function yg(e){let t={},n={},r=[];function i(a){if(a in n)throw new vg;a in t||(n[a]=!0,t[a]=!0,e.predecessors(a).forEach(i),delete n[a],r.push(a))}if(e.sinks().forEach(i),Object.keys(t).length!==e.nodeCount())throw new vg;return r}function bg(e){try{yg(e)}catch(e){if(e instanceof vg)return!1;throw e}return!0}function xg(e,t,n,r,i){Array.isArray(t)||(t=[t]);let a=(t=>(e.isDirected()?e.successors(t):e.neighbors(t))??[]),o={};return t.forEach(function(t){if(!e.hasNode(t))throw Error(`Graph does not have node: `+t);i=Sg(e,t,n===`post`,o,a,r,i)}),i}function Sg(e,t,n,r,i,a,o){return t in r||(r[t]=!0,n||(o=a(o,t)),i(t).forEach(function(t){o=Sg(e,t,n,r,i,a,o)}),n&&(o=a(o,t))),o}function Cg(e,t,n){return xg(e,t,n,function(e,t){return e.push(t),e},[])}function wg(e,t){return Cg(e,t,`post`)}function Tg(e,t){return Cg(e,t,`pre`)}function Eg(e,t){let n=new Gh,r={},i=new cg,a;function o(e){let n=e.v===a?e.w:e.v,o=i.priority(n);if(o!==void 0){let s=t(e);s<o&&(r[n]=a,i.decrease(n,s))}}if(e.nodeCount()===0)return n;e.nodes().forEach(function(e){i.add(e,1/0),n.setNode(e)}),i.decrease(e.nodes()[0],0);let s=!1;for(;i.size()>0;){if(a=i.removeMin(),a in r)n.setEdge(a,r[a]);else{if(s)throw Error(`Input graph is not connected: `+e);s=!0}e.nodeEdges(a).forEach(o)}return n}function Dg(e,t,n,r){return Og(e,t,n,r??(t=>e.outEdges(t)??[]))}function Og(e,t,n,r){if(n===void 0)return ug(e,t,n,r);let i=!1,a=e.nodes();for(let o=0;o<a.length;o++){let s=r(a[o]);for(let e=0;e<s.length;e++){let t=s[e],r=t.v===a[o]?t.v:t.w;n({v:r,w:r===t.v?t.w:t.v})<0&&(i=!0)}if(i)return ag(e,t,n,r)}return ug(e,t,n,r)}function kg(e,t,n,r){let i=r;for(;e.hasNode(i);)i=Gg(r);return n.dummy=t,e.setNode(i,n),i}function Ag(e){let t=new Gh().setGraph(e.graph());return e.nodes().forEach(n=>t.setNode(n,e.node(n))),e.edges().forEach(n=>{let r=t.edge(n.v,n.w)||{weight:0,minlen:1},i=e.edge(n);t.setEdge(n.v,n.w,{weight:r.weight+i.weight,minlen:Math.max(r.minlen,i.minlen)})}),t}function jg(e){let t=new Gh({multigraph:e.isMultigraph()}).setGraph(e.graph());return e.nodes().forEach(n=>{e.children(n).length||t.setNode(n,e.node(n))}),e.edges().forEach(n=>{t.setEdge(n,e.edge(n))}),t}function Mg(e,t){let n=e.x,r=e.y,i=t.x-n,a=t.y-r,o=e.width/2,s=e.height/2;if(!i&&!a)throw Error(`Not possible to find intersection inside of the rectangle`);let c,l;return Math.abs(a)*o>Math.abs(i)*s?(a<0&&(s=-s),c=s*i/a,l=s):(i<0&&(o=-o),c=o,l=o*a/i),{x:n+c,y:r+l}}function Ng(e){let t=Kg(Bg(e)+1).map(()=>[]);return e.nodes().forEach(n=>{let r=e.node(n),i=r.rank;i!==void 0&&(t[i]||(t[i]=[]),t[i][r.order]=n)}),t}function Pg(e){let t=e.nodes().map(t=>{let n=e.node(t).rank;return n===void 0?Number.MAX_VALUE:n}),n=zg(Math.min,t);e.nodes().forEach(t=>{let r=e.node(t);Object.hasOwn(r,`rank`)&&(r.rank-=n)})}function Fg(e){let t=e.nodes().map(t=>e.node(t).rank).filter(e=>e!==void 0),n=zg(Math.min,t),r=[];e.nodes().forEach(t=>{let i=e.node(t).rank-n;r[i]||(r[i]=[]),r[i].push(t)});let i=0,a=e.graph().nodeRankFactor;Array.from(r).forEach((t,n)=>{t===void 0&&n%a!==0?--i:t!==void 0&&i&&t.forEach(t=>e.node(t).rank+=i)})}function Ig(e,t,n,r){let i={width:0,height:0};return arguments.length>=4&&(i.rank=n,i.order=r),kg(e,`border`,i,t)}function Lg(e,t=Rg){let n=[];for(let r=0;r<e.length;r+=t){let i=e.slice(r,r+t);n.push(i)}return n}var Rg=65535;function zg(e,t){return t.length>Rg?e(...Lg(t).map(t=>e(...t))):e(...t)}function Bg(e){let t=e.nodes().map(t=>{let n=e.node(t).rank;return n===void 0?Number.MIN_VALUE:n});return zg(Math.max,t)}function Vg(e,t){let n={lhs:[],rhs:[]};return e.forEach(e=>{t(e)?n.lhs.push(e):n.rhs.push(e)}),n}function Hg(e,t){let n=Date.now();try{return t()}finally{console.log(e+` time: `+(Date.now()-n)+`ms`)}}function Ug(e,t){return t()}var Wg=0;function Gg(e){return e+(``+ ++Wg)}function Kg(e,t,n=1){t??(t=e,e=0);let r=e=>e<t;n<0&&(r=e=>t<e);let i=[];for(let t=e;r(t);t+=n)i.push(t);return i}function qg(e,t){let n={};for(let r of t)e[r]!==void 0&&(n[r]=e[r]);return n}function Jg(e,t){let n;return n=typeof t==`string`?e=>e[t]:t,Object.entries(e).reduce((e,[t,r])=>(e[t]=n(r,t),e),{})}function Yg(e,t){return e.reduce((e,n,r)=>(e[n]=t[r],e),{})}var Xg=`\0`,Zg=class{constructor(){Vh(this,`_sentinel`);let e={};e._next=e._prev=e,this._sentinel=e}dequeue(){let e=this._sentinel,t=e._prev;if(t!==e)return Qg(t),t}enqueue(e){let t=this._sentinel;e._prev&&e._next&&Qg(e),e._next=t._next,t._next._prev=e,t._next=e,e._prev=t}toString(){let e=[],t=this._sentinel,n=t._prev;for(;n!==t;)e.push(JSON.stringify(n,$g)),n=n._prev;return`[`+e.join(`, `)+`]`}};function Qg(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function $g(e,t){if(e!==`_next`&&e!==`_prev`)return t}var e_=Zg,t_=()=>1;function n_(e,t){if(e.nodeCount()<=1)return[];let n=a_(e,t||t_);return r_(n.graph,n.buckets,n.zeroIdx).flatMap(t=>e.outEdges(t.v,t.w)||[])}function r_(e,t,n){let r=[],i=t[t.length-1],a=t[0],o;for(;e.nodeCount();){for(;o=a.dequeue();)i_(e,t,n,o);for(;o=i.dequeue();)i_(e,t,n,o);if(e.nodeCount()){for(let i=t.length-2;i>0;--i)if(o=t[i]?.dequeue(),o){r=r.concat(i_(e,t,n,o,!0)||[]);break}}}return r}function i_(e,t,n,r,i){let a=[],o=i?a:void 0;return(e.inEdges(r.v)||[]).forEach(r=>{let o=e.edge(r),s=e.node(r.v);i&&a.push({v:r.v,w:r.w}),s.out-=o,o_(t,n,s)}),(e.outEdges(r.v)||[]).forEach(r=>{let i=e.edge(r),a=r.w,o=e.node(a);o.in-=i,o_(t,n,o)}),e.removeNode(r.v),o}function a_(e,t){let n=new Gh,r=0,i=0;e.nodes().forEach(e=>{n.setNode(e,{v:e,in:0,out:0})}),e.edges().forEach(e=>{let a=n.edge(e.v,e.w)||0,o=t(e),s=a+o;n.setEdge(e.v,e.w,s);let c=n.node(e.v),l=n.node(e.w);i=Math.max(i,c.out+=o),r=Math.max(r,l.in+=o)});let a=s_(i+r+3).map(()=>new e_),o=r+1;return n.nodes().forEach(e=>{o_(a,o,n.node(e))}),{graph:n,buckets:a,zeroIdx:o}}function o_(e,t,n){var r,i,a;n.out?n.in?(a=e[n.out-n.in+t])==null||a.enqueue(n):(i=e[e.length-1])==null||i.enqueue(n):(r=e[0])==null||r.enqueue(n)}function s_(e){let t=[];for(let n=0;n<e;n++)t.push(n);return t}function c_(e){(e.graph().acyclicer===`greedy`?n_(e,t(e)):l_(e)).forEach(t=>{let n=e.edge(t);e.removeEdge(t),n.forwardName=t.name,n.reversed=!0,e.setEdge(t.w,t.v,n,Gg(`rev`))});function t(e){return t=>e.edge(t).weight}}function l_(e){let t=[],n={},r={};function i(a){Object.hasOwn(r,a)||(r[a]=!0,n[a]=!0,e.outEdges(a).forEach(e=>{Object.hasOwn(n,e.w)?t.push(e):i(e.w)}),delete n[a])}return e.nodes().forEach(i),t}function u_(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.reversed){e.removeEdge(t);let r=n.forwardName;delete n.reversed,delete n.forwardName,e.setEdge(t.w,t.v,n,r)}})}function d_(e){e.graph().dummyChains=[],e.edges().forEach(t=>f_(e,t))}function f_(e,t){let n=t.v,r=e.node(n).rank,i=t.w,a=e.node(i).rank,o=t.name,s=e.edge(t),c=s.labelRank;if(a===r+1)return;e.removeEdge(t);let l,u,d;for(d=0,++r;r<a;++d,++r)s.points=[],u={width:0,height:0,edgeLabel:s,edgeObj:t,rank:r},l=kg(e,`edge`,u,`_d`),r===c&&(u.width=s.width,u.height=s.height,u.dummy=`edge-label`,u.labelpos=s.labelpos),e.setEdge(n,l,{weight:s.weight},o),d===0&&e.graph().dummyChains.push(l),n=l;e.setEdge(n,i,{weight:s.weight},o)}function p_(e){e.graph().dummyChains.forEach(t=>{let n=e.node(t),r=n.edgeLabel,i;for(e.setEdge(n.edgeObj,r);n.dummy;)i=e.successors(t)[0],e.removeNode(t),r.points.push({x:n.x,y:n.y}),n.dummy===`edge-label`&&(r.x=n.x,r.y=n.y,r.width=n.width,r.height=n.height),t=i,n=e.node(t)})}function m_(e){let t={};function n(r){let i=e.node(r);if(Object.hasOwn(t,r))return i.rank;t[r]=!0;let a=e.outEdges(r),o=a?a.map(t=>t==null?1/0:n(t.w)-e.edge(t).minlen):[],s=zg(Math.min,o);return s===1/0&&(s=0),i.rank=s}e.sources().forEach(n)}function h_(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}var g_=__;function __(e){let t=new Gh({directed:!1}),n=e.nodes();if(n.length===0)throw Error(`Graph must have at least one node`);let r=n[0],i=e.nodeCount();t.setNode(r,{});let a,o;for(;v_(t,e)<i&&(a=y_(t,e),a);)o=t.hasNode(a.v)?h_(e,a):-h_(e,a),b_(t,e,o);return t}function v_(e,t){function n(r){let i=t.nodeEdges(r);i&&i.forEach(i=>{let a=i.v,o=r===a?i.w:a;!e.hasNode(o)&&!h_(t,i)&&(e.setNode(o,{}),e.setEdge(r,o,{}),n(o))})}return e.nodes().forEach(n),e.nodeCount()}function y_(e,t){return t.edges().reduce((n,r)=>{let i=1/0;return e.hasNode(r.v)!==e.hasNode(r.w)&&(i=h_(t,r)),i<n[0]?[i,r]:n},[1/0,null])[1]}function b_(e,t,n){e.nodes().forEach(e=>t.node(e).rank+=n)}var{preorder:x_,postorder:S_}=rg,C_=w_;w_.initLowLimValues=O_,w_.initCutValues=T_,w_.calcCutValue=D_,w_.leaveEdge=A_,w_.enterEdge=j_,w_.exchangeEdges=M_;function w_(e){e=Ag(e),m_(e);let t=g_(e);O_(t),T_(t,e);let n,r;for(;n=A_(t);)r=j_(t,e,n),M_(t,e,n,r)}function T_(e,t){let n=S_(e,e.nodes());n=n.slice(0,n.length-1),n.forEach(n=>E_(e,t,n))}function E_(e,t,n){let r=e.node(n).parent,i=e.edge(n,r);i.cutvalue=D_(e,t,n)}function D_(e,t,n){let r=e.node(n).parent,i=!0,a=t.edge(n,r),o=0;a||=(i=!1,t.edge(r,n)),o=a.weight;let s=t.nodeEdges(n);return s&&s.forEach(a=>{let s=a.v===n,c=s?a.w:a.v;if(c!==r){let r=s===i,l=t.edge(a).weight;if(o+=r?l:-l,P_(e,n,c)){let t=e.edge(n,c).cutvalue;o+=r?-t:t}}}),o}function O_(e,t){arguments.length<2&&(t=e.nodes()[0]),k_(e,{},1,t)}function k_(e,t,n,r,i){let a=n,o=e.node(r);t[r]=!0;let s=e.neighbors(r);return s&&s.forEach(i=>{Object.hasOwn(t,i)||(n=k_(e,t,n,i,r))}),o.low=a,o.lim=n++,i?o.parent=i:delete o.parent,n}function A_(e){return e.edges().find(t=>e.edge(t).cutvalue<0)}function j_(e,t,n){let r=n.v,i=n.w;t.hasEdge(r,i)||(r=n.w,i=n.v);let a=e.node(r),o=e.node(i),s=a,c=!1;return a.lim>o.lim&&(s=o,c=!0),t.edges().filter(t=>c===F_(e,e.node(t.v),s)&&c!==F_(e,e.node(t.w),s)).reduce((e,n)=>h_(t,n)<h_(t,e)?n:e)}function M_(e,t,n,r){let i=n.v,a=n.w;e.removeEdge(i,a),e.setEdge(r.v,r.w,{}),O_(e),T_(e,t),N_(e,t)}function N_(e,t){let n=e.nodes().find(t=>!e.node(t).parent);if(!n)return;let r=x_(e,[n]);r=r.slice(1),r.forEach(n=>{let r=e.node(n).parent,i=t.edge(n,r),a=!1;i||(i=t.edge(r,n),a=!0),t.node(n).rank=t.node(r).rank+(a?i.minlen:-i.minlen)})}function P_(e,t,n){return e.hasEdge(t,n)}function F_(e,t,n){return n.low<=t.lim&&t.lim<=n.lim}var I_=L_;function L_(e){let t=e.graph().ranker;if(typeof t==`function`)return t(e);switch(t){case`network-simplex`:B_(e);break;case`tight-tree`:z_(e);break;case`longest-path`:R_(e);break;case`none`:break;default:B_(e)}}var R_=m_;function z_(e){m_(e),g_(e)}function B_(e){C_(e)}var V_=H_;function H_(e){let t=W_(e);e.graph().dummyChains.forEach(n=>{let r=e.node(n),i=r.edgeObj,a=U_(e,t,i.v,i.w),o=a.path,s=a.lca,c=0,l=o[c],u=!0;for(;n!==i.w;){if(r=e.node(n),u){for(;(l=o[c])!==s&&e.node(l).maxRank<r.rank;)c++;l===s&&(u=!1)}if(!u){for(;c<o.length-1&&e.node(o[c+1]).minRank<=r.rank;)c++;l=o[c]}l!==void 0&&e.setParent(n,l),n=e.successors(n)[0]}})}function U_(e,t,n,r){let i=[],a=[],o=Math.min(t[n].low,t[r].low),s=Math.max(t[n].lim,t[r].lim),c;c=n;do c=e.parent(c),i.push(c);while(c&&(t[c].low>o||s>t[c].lim));let l=c,u=r;for(;(u=e.parent(u))!==l;)a.push(u);return{path:i.concat(a.reverse()),lca:l}}function W_(e){let t={},n=0;function r(i){let a=n;e.children(i).forEach(r),t[i]={low:a,lim:n++}}return e.children(Xg).forEach(r),t}function G_(e){let t=kg(e,`root`,{},`_root`),n=q_(e),r=Object.values(n),i=zg(Math.max,r)-1,a=2*i+1;e.graph().nestingRoot=t,e.edges().forEach(t=>e.edge(t).minlen*=a);let o=J_(e)+1;e.children(Xg).forEach(r=>K_(e,t,a,o,i,n,r)),e.graph().nodeRankFactor=a}function K_(e,t,n,r,i,a,o){let s=e.children(o);if(!s.length){o!==t&&e.setEdge(t,o,{weight:0,minlen:n});return}let c=Ig(e,`_bt`),l=Ig(e,`_bb`),u=e.node(o);e.setParent(c,o),u.borderTop=c,e.setParent(l,o),u.borderBottom=l,s.forEach(s=>{K_(e,t,n,r,i,a,s);let u=e.node(s),d=u.borderTop?u.borderTop:s,f=u.borderBottom?u.borderBottom:s,p=u.borderTop?r:2*r,m=d===f?i-(a[o]??0)+1:1;e.setEdge(c,d,{weight:p,minlen:m,nestingEdge:!0}),e.setEdge(f,l,{weight:p,minlen:m,nestingEdge:!0})}),e.parent(o)||e.setEdge(t,c,{weight:0,minlen:i+(a[o]??0)})}function q_(e){let t={};function n(r,i){let a=e.children(r);a&&a.length&&a.forEach(e=>n(e,i+1)),t[r]=i}return e.children(Xg).forEach(e=>n(e,1)),t}function J_(e){return e.edges().reduce((t,n)=>t+e.edge(n).weight,0)}function Y_(e){let t=e.graph();e.removeNode(t.nestingRoot),delete t.nestingRoot,e.edges().forEach(t=>{e.edge(t).nestingEdge&&e.removeEdge(t)})}var X_=Z_;function Z_(e){function t(n){let r=e.children(n),i=e.node(n);if(r.length&&r.forEach(t),Object.hasOwn(i,`minRank`)){i.borderLeft=[],i.borderRight=[];for(let t=i.minRank,r=i.maxRank+1;t<r;++t)Q_(e,`borderLeft`,`_bl`,n,i,t),Q_(e,`borderRight`,`_br`,n,i,t)}}e.children(Xg).forEach(t)}function Q_(e,t,n,r,i,a){let o={width:0,height:0,rank:a,borderType:t},s=i[t][a-1],c=kg(e,`border`,o,n);i[t][a]=c,e.setParent(c,r),s&&e.setEdge(s,c,{weight:1})}function $_(e){let t=e.graph().rankdir?.toLowerCase();(t===`lr`||t===`rl`)&&tv(e)}function ev(e){let t=e.graph().rankdir?.toLowerCase();(t===`bt`||t===`rl`)&&rv(e),(t===`lr`||t===`rl`)&&(av(e),tv(e))}function tv(e){e.nodes().forEach(t=>nv(e.node(t))),e.edges().forEach(t=>nv(e.edge(t)))}function nv(e){let t=e.width;e.width=e.height,e.height=t}function rv(e){e.nodes().forEach(t=>iv(e.node(t))),e.edges().forEach(t=>{var n;let r=e.edge(t);(n=r.points)==null||n.forEach(iv),Object.hasOwn(r,`y`)&&iv(r)})}function iv(e){e.y=-e.y}function av(e){e.nodes().forEach(t=>ov(e.node(t))),e.edges().forEach(t=>{var n;let r=e.edge(t);(n=r.points)==null||n.forEach(ov),Object.hasOwn(r,`x`)&&ov(r)})}function ov(e){let t=e.x;e.x=e.y,e.y=t}function sv(e){let t={},n=e.nodes().filter(t=>!e.children(t).length),r=n.map(t=>e.node(t).rank),i=Kg(zg(Math.max,r)+1).map(()=>[]);function a(n){if(t[n])return;t[n]=!0;let r=e.node(n);i[r.rank].push(n);let o=e.successors(n);o&&o.forEach(a)}return n.sort((t,n)=>e.node(t).rank-e.node(n).rank).forEach(a),i}function cv(e,t){let n=0;for(let r=1;r<t.length;++r)n+=lv(e,t[r-1],t[r]);return n}function lv(e,t,n){let r=Yg(n,n.map((e,t)=>t)),i=t.flatMap(t=>{let n=e.outEdges(t);return n?n.map(t=>({pos:r[t.w],weight:e.edge(t).weight})).sort((e,t)=>e.pos-t.pos):[]}),a=1;for(;a<n.length;)a<<=1;let o=2*a-1;--a;let s=Array(o).fill(0),c=0;return i.forEach(e=>{let t=e.pos+a;s[t]+=e.weight;let n=0;for(;t>0;)t%2&&(n+=s[t+1]),t=t-1>>1,s[t]+=e.weight;c+=e.weight*n}),c}function uv(e,t=[]){return t.map(t=>{let n=e.inEdges(t);if(!n||!n.length)return{v:t};{let r=n.reduce((t,n)=>{let r=e.edge(n),i=e.node(n.v);return{sum:t.sum+r.weight*i.order,weight:t.weight+r.weight}},{sum:0,weight:0});return{v:t,barycenter:r.sum/r.weight,weight:r.weight}}})}function dv(e,t){let n={};return e.forEach((e,t)=>{let r={indegree:0,in:[],out:[],vs:[e.v],i:t};e.barycenter!==void 0&&(r.barycenter=e.barycenter,r.weight=e.weight),n[e.v]=r}),t.edges().forEach(e=>{let t=n[e.v],r=n[e.w];t!==void 0&&r!==void 0&&(r.indegree++,t.out.push(r))}),fv(Object.values(n).filter(e=>!e.indegree))}function fv(e){let t=[];function n(e){return t=>{t.merged||(t.barycenter===void 0||e.barycenter===void 0||t.barycenter>=e.barycenter)&&pv(e,t)}}function r(t){return n=>{n.in.push(t),--n.indegree===0&&e.push(n)}}for(;e.length;){let i=e.pop();t.push(i),i.in.reverse().forEach(n(i)),i.out.forEach(r(i))}return t.filter(e=>!e.merged).map(e=>qg(e,[`vs`,`i`,`barycenter`,`weight`]))}function pv(e,t){let n=0,r=0;e.weight&&(n+=e.barycenter*e.weight,r+=e.weight),t.weight&&(n+=t.barycenter*t.weight,r+=t.weight),e.vs=t.vs.concat(e.vs),e.barycenter=n/r,e.weight=r,e.i=Math.min(t.i,e.i),t.merged=!0}function mv(e,t){let n=Vg(e,e=>Object.hasOwn(e,`barycenter`)),r=n.lhs,i=n.rhs.sort((e,t)=>t.i-e.i),a=[],o=0,s=0,c=0;r.sort(gv(!!t)),c=hv(a,i,c),r.forEach(e=>{c+=e.vs.length,a.push(e.vs),o+=e.barycenter*e.weight,s+=e.weight,c=hv(a,i,c)});let l={vs:a.flat(1)};return s&&(l.barycenter=o/s,l.weight=s),l}function hv(e,t,n){let r;for(;t.length&&(r=t[t.length-1]).i<=n;)t.pop(),e.push(r.vs),n++;return n}function gv(e){return(t,n)=>t.barycenter<n.barycenter?-1:t.barycenter>n.barycenter?1:e?n.i-t.i:t.i-n.i}function _v(e,t,n,r){let i=e.children(t),a=e.node(t),o=a?a.borderLeft:void 0,s=a?a.borderRight:void 0,c={};o&&(i=i.filter(e=>e!==o&&e!==s));let l=uv(e,i);l.forEach(t=>{if(e.children(t.v).length){let i=_v(e,t.v,n,r);c[t.v]=i,Object.hasOwn(i,`barycenter`)&&yv(t,i)}});let u=dv(l,n);vv(u,c);let d=mv(u,r);if(o&&s){d.vs=[o,d.vs,s].flat(1);let t=e.predecessors(o);if(t&&t.length){let n=e.node(t[0]),r=e.predecessors(s),i=e.node(r[0]);Object.hasOwn(d,`barycenter`)||(d.barycenter=0,d.weight=0),d.barycenter=(d.barycenter*d.weight+n.order+i.order)/(d.weight+2),d.weight+=2}}return d}function vv(e,t){e.forEach(e=>{e.vs=e.vs.flatMap(e=>t[e]?t[e].vs:e)})}function yv(e,t){e.barycenter===void 0?(e.barycenter=t.barycenter,e.weight=t.weight):(e.barycenter=(e.barycenter*e.weight+t.barycenter*t.weight)/(e.weight+t.weight),e.weight+=t.weight)}function bv(e,t,n,r){r||=e.nodes();let i=xv(e),a=new Gh({compound:!0}).setGraph({root:i}).setDefaultNodeLabel(t=>e.node(t));return r.forEach(r=>{let o=e.node(r),s=e.parent(r);if(o.rank===t||o.minRank<=t&&t<=o.maxRank){a.setNode(r),a.setParent(r,s||i);let c=e[n](r);c&&c.forEach(t=>{let n=t.v===r?t.w:t.v,i=a.edge(n,r),o=i===void 0?0:i.weight;a.setEdge(n,r,{weight:e.edge(t).weight+o})}),Object.hasOwn(o,`minRank`)&&a.setNode(r,{borderLeft:o.borderLeft[t],borderRight:o.borderRight[t]})}}),a}function xv(e){let t;for(;e.hasNode(t=Gg(`_root`)););return t}function Sv(e,t,n){let r={},i;n.forEach(n=>{let a=e.parent(n),o,s;for(;a;){if(o=e.parent(a),o?(s=r[o],r[o]=a):(s=i,i=a),s&&s!==a){t.setEdge(s,a);return}a=o}})}function Cv(e,t={}){if(typeof t.customOrder==`function`){t.customOrder(e,Cv);return}let n=Bg(e),r=wv(e,Kg(1,n+1),`inEdges`),i=wv(e,Kg(n-1,-1,-1),`outEdges`),a=sv(e);if(Ev(e,a),t.disableOptimalOrderHeuristic)return;let o=1/0,s,c=t.constraints||[];for(let t=0,n=0;n<4;++t,++n){Tv(t%2?r:i,t%4>=2,c),a=Ng(e);let l=cv(e,a);l<o?(n=0,s=Object.assign({},a),o=l):l===o&&(s=structuredClone(a))}Ev(e,s)}function wv(e,t,n){let r=new Map,i=(e,t)=>{r.has(e)||r.set(e,[]),r.get(e).push(t)};for(let t of e.nodes()){let n=e.node(t);if(typeof n.rank==`number`&&i(n.rank,t),typeof n.minRank==`number`&&typeof n.maxRank==`number`)for(let e=n.minRank;e<=n.maxRank;e++)e!==n.rank&&i(e,t)}return t.map(function(t){return bv(e,t,n,r.get(t)||[])})}function Tv(e,t,n){let r=new Gh;e.forEach(function(e){n.forEach(e=>r.setEdge(e.left,e.right));let i=e.graph().root,a=_v(e,i,r,t);a.vs.forEach((t,n)=>e.node(t).order=n),Sv(e,r,a.vs)})}function Ev(e,t){Object.values(t).forEach(t=>t.forEach((t,n)=>e.node(t).order=n))}function Dv(e,t){let n={};function r(t,r){let i=0,a=0,o=t.length,s=r[r.length-1];return r.forEach((t,c)=>{let l=kv(e,t),u=l?e.node(l).order:o;(l||t===s)&&(r.slice(a,c+1).forEach(t=>{let r=e.predecessors(t);r&&r.forEach(r=>{let a=e.node(r),o=a.order;(o<i||u<o)&&!(a.dummy&&e.node(t).dummy)&&Av(n,r,t)})}),a=c+1,i=u)}),r}return t.length&&t.reduce(r),n}function Ov(e,t){let n={};function r(t,r,i,a,o){Kg(r,i).forEach(r=>{let i=t[r];if(i!==void 0&&e.node(i).dummy){let t=e.predecessors(i);t&&t.forEach(t=>{if(t===void 0)return;let r=e.node(t);r.dummy&&(r.order<a||r.order>o)&&Av(n,t,i)})}})}function i(t,n){let i=-1,a=-1,o=0;return n.forEach((s,c)=>{if(e.node(s).dummy===`border`){let t=e.predecessors(s);if(t&&t.length){let s=t[0];if(s===void 0)return;a=e.node(s).order,r(n,o,c,i,a),o=c,i=a}}r(n,o,n.length,a,t.length)}),n}return t.length&&t.reduce(i),n}function kv(e,t){if(e.node(t).dummy){let n=e.predecessors(t);if(n)return n.find(t=>e.node(t).dummy)}}function Av(e,t,n){if(t>n){let e=t;t=n,n=e}let r=e[t];r||(e[t]=r={}),r[n]=!0}function jv(e,t,n){if(t>n){let e=t;t=n,n=e}let r=e[t];return r!==void 0&&Object.hasOwn(r,n)}function Mv(e,t,n,r){let i={},a={},o={};return t.forEach(e=>{e.forEach((e,t)=>{i[e]=e,a[e]=e,o[e]=t})}),t.forEach(e=>{let t=-1;e.forEach(e=>{let s=r(e);if(s&&s.length){let r=s.sort((e,t)=>{let n=o[e],r=o[t];return(n===void 0?0:n)-(r===void 0?0:r)}),c=(r.length-1)/2;for(let s=Math.floor(c),l=Math.ceil(c);s<=l;++s){let c=r[s];if(c===void 0)continue;let l=o[c];if(l!==void 0&&a[e]===e&&t<l&&!jv(n,e,c)){let n=i[c];n!==void 0&&(a[c]=e,a[e]=i[e]=n,t=l)}}}})}),{root:i,align:a}}function Nv(e,t,n,r,i=!1){let a={},o=Pv(e,t,n,i),s=i?`borderLeft`:`borderRight`;function c(e,t){let n=o.nodes().slice(),r={},i=n.pop();for(;i;){if(r[i])e(i);else{r[i]=!0,n.push(i);for(let e of t(i))n.push(e)}i=n.pop()}}function l(e){let t=o.inEdges(e);t?a[e]=t.reduce((e,t)=>{let n=a[t.v]??0,r=o.edge(t);return Math.max(e,n+(r===void 0?0:r))},0):a[e]=0}function u(t){let n=o.outEdges(t),r=1/0;n&&(r=n.reduce((e,t)=>{let n=a[t.w],r=o.edge(t);return Math.min(e,(n===void 0?0:n)-(r===void 0?0:r))},1/0));let i=e.node(t);r!==1/0&&i.borderType!==s&&(a[t]=Math.max(a[t]===void 0?0:a[t],r))}function d(e){return o.predecessors(e)||[]}function f(e){return o.successors(e)||[]}return c(l,d),c(u,f),Object.keys(r).forEach(e=>{let t=n[e];t!==void 0&&(a[e]=a[t]??0)}),a}function Pv(e,t,n,r){let i=new Gh,a=e.graph(),o=zv(a.nodesep,a.edgesep,r);return t.forEach(t=>{let r;t.forEach(t=>{let a=n[t];if(a!==void 0){if(i.setNode(a),r!==void 0){let s=n[r];if(s!==void 0){let n=i.edge(s,a);i.setEdge(s,a,Math.max(o(e,t,r),n||0))}}r=t}})}),i}function Fv(e,t){return Object.values(t).reduce((t,n)=>{let r=-1/0,i=1/0;Object.entries(n).forEach(([t,n])=>{let a=Bv(e,t)/2;r=Math.max(n+a,r),i=Math.min(n-a,i)});let a=r-i;return a<t[0]&&(t=[a,n]),t},[1/0,null])[1]}function Iv(e,t){let n=Object.values(t),r=zg(Math.min,n),i=zg(Math.max,n);[`u`,`d`].forEach(n=>{[`l`,`r`].forEach(a=>{let o=n+a,s=e[o];if(!s||s===t)return;let c=Object.values(s),l=r-zg(Math.min,c);a!==`l`&&(l=i-zg(Math.max,c)),l&&(e[o]=Jg(s,e=>e+l))})})}function Lv(e,t=void 0){let n=e.ul;return n?Jg(n,(n,r)=>{if(t){let n=e[t.toLowerCase()];if(n&&n[r]!==void 0)return n[r]}let i=Object.values(e).map(e=>{let t=e[r];return t===void 0?0:t}).sort((e,t)=>e-t);return((i[1]??0)+(i[2]??0))/2}):{}}function Rv(e){let t=Ng(e),n=Object.assign(Dv(e,t),Ov(e,t)),r={},i;return[`u`,`d`].forEach(a=>{i=a===`u`?t:Object.values(t).reverse(),[`l`,`r`].forEach(t=>{t===`r`&&(i=i.map(e=>Object.values(e).reverse()));let o=Mv(e,i,n,t=>(a===`u`?e.predecessors(t):e.successors(t))||[]),s=Nv(e,i,o.root,o.align,t===`r`);t===`r`&&(s=Jg(s,e=>-e)),r[a+t]=s})}),Iv(r,Fv(e,r)),Lv(r,e.graph().align)}function zv(e,t,n){return(r,i,a)=>{let o=r.node(i),s=r.node(a),c=0,l;if(c+=o.width/2,Object.hasOwn(o,`labelpos`))switch(o.labelpos.toLowerCase()){case`l`:l=-o.width/2;break;case`r`:l=o.width/2;break}if(l&&(c+=n?l:-l),l=void 0,c+=(o.dummy?t:e)/2,c+=(s.dummy?t:e)/2,c+=s.width/2,Object.hasOwn(s,`labelpos`))switch(s.labelpos.toLowerCase()){case`l`:l=s.width/2;break;case`r`:l=-s.width/2;break}return l&&(c+=n?l:-l),c}}function Bv(e,t){return e.node(t).width}function Vv(e){e=jg(e),Hv(e),Object.entries(Rv(e)).forEach(([t,n])=>e.node(t).x=n)}function Hv(e){let t=Ng(e),n=e.graph(),r=n.ranksep,i=n.rankalign,a=0;t.forEach(t=>{let n=t.reduce((t,n)=>{let r=e.node(n).height??0;return t>r?t:r},0);t.forEach(t=>{let r=e.node(t);i===`top`?r.y=a+r.height/2:i===`bottom`?r.y=a+n-r.height/2:r.y=a+n/2}),a+=n+r})}function Uv(e,t={}){let n=t.debugTiming?Hg:Ug;return n(`layout`,()=>{let r=n(` buildLayoutGraph`,()=>ey(e));return n(` runLayout`,()=>Wv(r,n,t)),n(` updateInputGraph`,()=>Gv(e,r)),r})}function Wv(e,t,n){t(` makeSpaceForEdgeLabels`,()=>ty(e)),t(` removeSelfEdges`,()=>uy(e)),t(` acyclic`,()=>c_(e)),t(` nestingGraph.run`,()=>G_(e)),t(` rank`,()=>I_(jg(e))),t(` injectEdgeLabelProxies`,()=>ny(e)),t(` removeEmptyRanks`,()=>Fg(e)),t(` nestingGraph.cleanup`,()=>Y_(e)),t(` normalizeRanks`,()=>Pg(e)),t(` assignRankMinMax`,()=>ry(e)),t(` removeEdgeLabelProxies`,()=>iy(e)),t(` normalize.run`,()=>d_(e)),t(` parentDummyChains`,()=>V_(e)),t(` addBorderSegments`,()=>X_(e)),t(` order`,()=>Cv(e,n)),t(` insertSelfEdges`,()=>dy(e)),t(` adjustCoordinateSystem`,()=>$_(e)),t(` position`,()=>Vv(e)),t(` positionSelfEdges`,()=>fy(e)),t(` removeBorderNodes`,()=>ly(e)),t(` normalize.undo`,()=>p_(e)),t(` fixupEdgeLabelCoords`,()=>sy(e)),t(` undoCoordinateSystem`,()=>ev(e)),t(` translateGraph`,()=>ay(e)),t(` assignNodeIntersects`,()=>oy(e)),t(` reversePoints`,()=>cy(e)),t(` acyclic.undo`,()=>u_(e))}function Gv(e,t){e.nodes().forEach(n=>{let r=e.node(n),i=t.node(n);r&&(r.x=i.x,r.y=i.y,r.order=i.order,r.rank=i.rank,t.children(n).length&&(r.width=i.width,r.height=i.height))}),e.edges().forEach(n=>{let r=e.edge(n),i=t.edge(n);r.points=i.points,Object.hasOwn(i,`x`)&&(r.x=i.x,r.y=i.y)}),e.graph().width=t.graph().width,e.graph().height=t.graph().height}var Kv=[`nodesep`,`edgesep`,`ranksep`,`marginx`,`marginy`],qv={ranksep:50,edgesep:20,nodesep:50,rankdir:`TB`,rankalign:`center`},Jv=[`acyclicer`,`ranker`,`rankdir`,`align`,`rankalign`],Yv=[`width`,`height`,`rank`],Xv={width:0,height:0},Zv=[`minlen`,`weight`,`width`,`height`,`labeloffset`],Qv={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:`r`},$v=[`labelpos`];function ey(e){let t=new Gh({multigraph:!0,compound:!0}),n=my(e.graph());return t.setGraph(Object.assign({},qv,py(n,Kv),qg(n,Jv))),e.nodes().forEach(n=>{let r=py(my(e.node(n)),Yv);Object.keys(Xv).forEach(e=>{r[e]===void 0&&(r[e]=Xv[e])}),t.setNode(n,r);let i=e.parent(n);i!==void 0&&t.setParent(n,i)}),e.edges().forEach(n=>{let r=my(e.edge(n));t.setEdge(n,Object.assign({},Qv,py(r,Zv),qg(r,$v)))}),t}function ty(e){let t=e.graph();t.ranksep/=2,e.edges().forEach(n=>{let r=e.edge(n);r.minlen*=2,r.labelpos.toLowerCase()!==`c`&&(t.rankdir===`TB`||t.rankdir===`BT`?r.width+=r.labeloffset:r.height+=r.labeloffset)})}function ny(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.width&&n.height){let n=e.node(t.v);kg(e,`edge-proxy`,{rank:(e.node(t.w).rank-n.rank)/2+n.rank,e:t},`_ep`)}})}function ry(e){let t=0;e.nodes().forEach(n=>{let r=e.node(n);r.borderTop&&(r.minRank=e.node(r.borderTop).rank,r.maxRank=e.node(r.borderBottom).rank,t=Math.max(t,r.maxRank))}),e.graph().maxRank=t}function iy(e){e.nodes().forEach(t=>{let n=e.node(t);if(n.dummy===`edge-proxy`){let r=n;e.edge(r.e).labelRank=n.rank,e.removeNode(t)}})}function ay(e){let t=1/0,n=0,r=1/0,i=0,a=e.graph(),o=a.marginx||0,s=a.marginy||0;function c(e){let a=e.x,o=e.y,s=e.width,c=e.height;t=Math.min(t,a-s/2),n=Math.max(n,a+s/2),r=Math.min(r,o-c/2),i=Math.max(i,o+c/2)}e.nodes().forEach(t=>c(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);Object.hasOwn(n,`x`)&&c(n)}),t-=o,r-=s,e.nodes().forEach(n=>{let i=e.node(n);i.x-=t,i.y-=r}),e.edges().forEach(n=>{let i=e.edge(n);i.points.forEach(e=>{e.x-=t,e.y-=r}),Object.hasOwn(i,`x`)&&(i.x-=t),Object.hasOwn(i,`y`)&&(i.y-=r)}),a.width=n-t+o,a.height=i-r+s}function oy(e){e.edges().forEach(t=>{let n=e.edge(t),r=e.node(t.v),i=e.node(t.w),a,o;n.points?(a=n.points[0],o=n.points[n.points.length-1]):(n.points=[],a=i,o=r),n.points.unshift(Mg(r,a)),n.points.push(Mg(i,o))})}function sy(e){e.edges().forEach(t=>{let n=e.edge(t);if(Object.hasOwn(n,`x`))switch((n.labelpos===`l`||n.labelpos===`r`)&&(n.width-=n.labeloffset),n.labelpos){case`l`:n.x-=n.width/2+n.labeloffset;break;case`r`:n.x+=n.width/2+n.labeloffset;break}})}function cy(e){e.edges().forEach(t=>{let n=e.edge(t);n.reversed&&n.points.reverse()})}function ly(e){e.nodes().forEach(t=>{if(e.children(t).length){let n=e.node(t),r=e.node(n.borderTop),i=e.node(n.borderBottom),a=e.node(n.borderLeft[n.borderLeft.length-1]),o=e.node(n.borderRight[n.borderRight.length-1]);n.width=Math.abs(o.x-a.x),n.height=Math.abs(i.y-r.y),n.x=a.x+n.width/2,n.y=r.y+n.height/2}}),e.nodes().forEach(t=>{e.node(t).dummy===`border`&&e.removeNode(t)})}function uy(e){e.edges().forEach(t=>{if(t.v===t.w){let n=e.node(t.v);n.selfEdges||=[],n.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}})}function dy(e){Ng(e).forEach(t=>{let n=0;t.forEach((t,r)=>{let i=e.node(t);i.order=r+n,(i.selfEdges||[]).forEach(t=>{kg(e,`selfedge`,{width:t.label.width,height:t.label.height,rank:i.rank,order:r+ ++n,e:t.e,label:t.label},`_se`)}),delete i.selfEdges})})}function fy(e){e.nodes().forEach(t=>{let n=e.node(t);if(n.dummy===`selfedge`){let r=n,i=e.node(r.e.v),a=i.x+i.width/2,o=i.y,s=n.x-a,c=i.height/2;e.setEdge(r.e,r.label),e.removeNode(t),r.label.points=[{x:a+2*s/3,y:o-c},{x:a+5*s/6,y:o-c},{x:a+s,y:o},{x:a+5*s/6,y:o+c},{x:a+2*s/3,y:o+c}],r.label.x=n.x,r.label.y=n.y}})}function py(e,t){return Jg(qg(e,t),Number)}function my(e){let t={};return e&&Object.entries(e).forEach(([e,n])=>{typeof e==`string`&&(e=e.toLowerCase()),t[e]=n}),t}var hy=212,gy=164;function _y(e,t,n=`LR`,r=!0){if(!e)return{nodes:[],edges:[]};let i=xy(e,n),a=vy(n),o=by(e,t),s=e.nodes.map(n=>({id:n.asset_id,initialHeight:gy,initialWidth:hy,measured:{height:gy,width:hy},type:`assetNode`,height:gy,position:n.position||i.get(n.asset_id)||{x:0,y:0},sourcePosition:a.source,targetPosition:a.target,width:hy,data:{...n,active:n.asset_id===t,focusRole:o.roles.get(n.asset_id)||`none`,root:n.asset_id===e.root_asset_id,sourcePosition:a.source,targetPosition:a.target}})),c=new Map(e.nodes.map(e=>[e.asset_id,e.title]));return{nodes:s,edges:e.edges.map(t=>{let n=t.summary?`lineage-edge-summary`:``,i=[o.edgeClasses.get(t.id),n].filter(Boolean).join(` `)||void 0,a=`${c.get(t.parent_asset_id)||t.parent_asset_id} to ${c.get(t.child_asset_id)||t.child_asset_id}`;return{ariaLabel:t.summary?`${a}: ${t.summary}`:a,ariaRole:`button`,className:i,domAttributes:{"aria-keyshortcuts":`Enter Space`},focusable:!0,id:t.id,markerEnd:{type:Bs.ArrowClosed},source:t.parent_asset_id,target:t.child_asset_id,type:`smoothstep`,animated:e.selected.includes(t.child_asset_id),...t.summary&&r?{label:t.summary,labelBgBorderRadius:4,labelBgPadding:[5,3],labelShowBg:!0}:{}}})}}function vy(e){return{BT:{source:Q.Top,target:Q.Bottom},LR:{source:Q.Right,target:Q.Left},RL:{source:Q.Left,target:Q.Right},TB:{source:Q.Bottom,target:Q.Top}}[e]}function yy(e,t=`LR`){if(!e)return`lineage-empty`;let n=e.nodes.map(e=>e.asset_id).sort().join(`,`),r=e.edges.map(e=>e.id).sort().join(`,`);return`${e.root_asset_id}:${t}:${n}:${r}`}function by(e,t){let n=new Map,r=new Map;if(!t||!e.nodes.some(e=>e.asset_id===t))return{edgeClasses:r,roles:n};n.set(t,`active`);for(let i of e.edges)i.child_asset_id===t&&(n.has(i.parent_asset_id)||n.set(i.parent_asset_id,`parent`),r.set(i.id,`lineage-edge-focus lineage-edge-focus-parent`)),i.parent_asset_id===t&&(n.has(i.child_asset_id)||n.set(i.child_asset_id,`child`),r.set(i.id,`lineage-edge-focus lineage-edge-focus-child`));return{edgeClasses:r,roles:n}}function xy(e,t=`LR`){let n=new Hh.Graph;n.setGraph({marginx:40,marginy:40,nodesep:80,rankdir:t,ranksep:110}),n.setDefaultEdgeLabel(()=>({}));for(let t of e.nodes)n.setNode(t.asset_id,{height:gy,width:hy});for(let t of e.edges)n.setEdge(t.parent_asset_id,t.child_asset_id);return Uv(n),new Map(e.nodes.map(e=>{let t=n.node(e.asset_id);return[e.asset_id,{x:Math.round((t?.x||hy/2)-hy/2),y:Math.round((t?.y||gy/2)-gy/2)}]}))}function Sy(e){return!!(e&&e.nodes.length>1&&e.edges.length>0)}function Cy(e){let t=new Set(e.nodes.map(e=>e.asset_id));if(t.size===0)return{stages:[]};let n=[...t].sort(Dy),r=t.has(e.root_asset_id)?e.root_asset_id:n[0],i=new Set([r]),a=new Set,o=e.edges.filter(e=>t.has(e.parent_asset_id)&&t.has(e.child_asset_id)).sort(Ey),s=[Ty(0,i,a,[r],[])];for(;i.size<t.size||o.length>0;){let e=o.findIndex(e=>i.has(e.parent_asset_id));if(e>=0){let[t]=o.splice(e,1);a.add(t.id);let n=i.has(t.child_asset_id)?[]:[t.child_asset_id];i.add(t.child_asset_id),s.push(Ty(s.length,i,a,n,[t.id]));continue}let t=n.find(e=>!i.has(e));if(t){i.add(t),s.push(Ty(s.length,i,a,[t],[]));continue}break}return{stages:s}}function wy(e,t,n,r,i){let a=n.stages,o=a.length-1,s=Math.max(-1,Math.min(r,o)),c=s>=0?a[s]:void 0,l=s<o?a[s+1]:void 0,u=new Set(c?.nodeIds||[]),d=new Set(c?.edgeIds||[]),f=new Set,p=new Set;if(l&&(i===`edge`||i===`node`))for(let e of l.enteringEdgeIds)i===`edge`?p.add(e):d.add(e);if(l&&i===`node`)for(let e of l.enteringNodeIds)f.add(e);let m=s===o&&i===`settled`,h=new Map(e.map(e=>[e.id,f.has(e.id)?`entering`:u.has(e.id)?`visible`:`future`])),g=new Map(t.map(e=>[e.id,p.has(e.id)?`entering`:d.has(e.id)?`visible`:`future`]));return{nodes:e.map(e=>({...e,data:{...e.data,replayInteractive:m,replayState:h.get(e.id)||`future`}})),edges:t.map(e=>{let t=g.get(e.id)||`future`;return{...e,className:[e.className,`lineage-edge-replay-${t}`].filter(Boolean).join(` `),domAttributes:{...e.domAttributes,"aria-hidden":t===`future`?!0:void 0},focusable:m?e.focusable:!1}}),projection:{edgeStates:g,interactive:m,nodeStates:h}}}function Ty(e,t,n,r,i){return{edgeIds:[...n],enteringEdgeIds:i,enteringNodeIds:r,index:e,nodeIds:[...t]}}function Ey(e,t){return Dy(e.created_at||``,t.created_at||``)||Dy(e.id,t.id)}function Dy(e,t){return e.localeCompare(t)}function Oy(e,t){(0,p.useEffect)(()=>{function n(n){n.key===`Escape`&&e&&t()}return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t])}function ky({asset:e,onResetLineage:t,onSelectedAsset:n,onToast:r,project:i}){let a=(0,p.useRef)(i),[o,s]=(0,p.useState)(null),[c,l]=(0,p.useState)(null),[u,d]=(0,p.useState)(null),[f,m]=(0,p.useState)(!1),h=o?.project===i,_=h?o:null,v=(_?.workspaces||[]).filter(e=>e.status!==`archived`),y=_?.active_workspace||v[0]||null,b=Eh(y,h&&_?.workspaces.length===0?e?.asset_id:void 0);(0,p.useEffect)(()=>{a.current=i,s(null),l(null),d(null)},[i]);let x=(0,p.useCallback)(async()=>{m(!0);try{let e=await g(`/api/lineage-workspaces?${new URLSearchParams({project:i}).toString()}`);e.project===a.current&&s(e)}catch(e){r(`error`,e instanceof Error?e.message:String(e))}finally{m(!1)}},[r,i]),S=(0,p.useCallback)(async()=>{try{let e=new URLSearchParams({project:i}),[t,n]=await Promise.all([g(`/api/lineage-workspaces/demo/media?${e.toString()}`),g(`/api/lineage-workspaces/demo/swissifier/media?${e.toString()}`)]);if(a.current!==i)return;l(t.status),d(n.status)}catch(e){r(`error`,e instanceof Error?e.message:String(e))}},[r,i]);async function C(e){if(e){m(!0);try{let a=await g(`/api/lineage-workspaces/${encodeURIComponent(e)}/activate`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:i,confirmWrite:!0})});t(),await x(),n(a.workspace.root_asset_id),r(`ok`,`Using ${a.workspace.title}`)}catch(e){r(`error`,e instanceof Error?e.message:String(e))}finally{m(!1)}}}async function w(e={}){m(!0);try{let a=await g(`/api/lineage-workspaces/demo/seed`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:i,confirmWrite:!0})});return t(),await x(),await S(),n(a.workspace?.root_asset_id||a.root_asset_id),e.quiet||r(`ok`,`Seeded demo lineage workspace`),a}catch(e){return r(`error`,e instanceof Error?e.message:String(e)),null}finally{m(!1)}}async function T(e={}){m(!0);try{let a=await g(`/api/lineage-workspaces/demo/swissifier/seed`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:i,confirmWrite:!0})});return t(),await x(),await S(),n(a.workspace?.root_asset_id||a.root_asset_id),e.quiet||r(`ok`,`Seeded Swissifier demo lineage`),a}catch(e){return r(`error`,e instanceof Error?e.message:String(e)),null}finally{m(!1)}}async function E(){m(!0);try{let e=await g(`/api/lineage-workspaces/demo/media/restore`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:i,confirmWrite:!0})});await S(),r(`ok`,`Restored ${e.result.restored||0} demo media file${e.result.restored===1?``:`s`}`)}catch(e){r(`error`,e instanceof Error?e.message:String(e))}finally{m(!1)}}async function D(){m(!0);try{let e=await g(`/api/lineage-workspaces/demo/swissifier/media/restore`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:i,confirmWrite:!0})});await S(),e.result.source_required?r(`error`,`Set ${e.result.source_env||`LINEAGE_SWISSIFIER_MEDIA_DIR`} to restore Swissifier media`):r(`ok`,`Restored ${e.result.restored||0} Swissifier media file${e.result.restored===1?``:`s`}`)}catch(e){r(`error`,e instanceof Error?e.message:String(e))}finally{m(!1)}}async function O(){m(!0);try{let e=await g(`/api/lineage-workspaces/demo/swissifier/media/download`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:i,confirmWrite:!0})});return e.result.media_status?d(e.result.media_status):await S(),e.result.download_available?(r(`ok`,`Downloaded ${e.result.restored||0} Swissifier media file${e.result.restored===1?``:`s`}`),!0):(r(`error`,`Swissifier media download is not configured`),!1)}catch(e){return r(`error`,e instanceof Error?e.message:String(e)),!1}finally{m(!1)}}async function k(){if(y&&window.confirm(`Archive ${y.title}? This hides it from the picker and clears its next-variation selection.`)){m(!0);try{await g(`/api/lineage-workspaces/${encodeURIComponent(y.id)}/archive`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:i,confirmWrite:!0})}),t(),await x(),await S(),r(`ok`,`Archived ${y.title}`)}catch(e){r(`error`,e instanceof Error?e.message:String(e))}finally{m(!1)}}}function A(e){s(t=>({project:i,active_workspace:e,workspaces:[e,...(t?.workspaces||[]).filter(t=>t.id!==e.id)],fetchedAt:new Date().toISOString()})),t(),n(e.root_asset_id),r(`ok`,`Using ${e.title}`)}return{activateWorkspace:C,activeWorkspace:y,archiveWorkspace:k,demoSeedStatus:c,downloadSwissifierDemoMedia:O,handleWorkspaceCreated:A,refreshDemoSeedStatus:S,refreshWorkspaces:x,restoreDemoSeedMedia:E,restoreSwissifierDemoMedia:D,seedDemoWorkspace:w,seedSwissifierDemoWorkspace:T,swissifierDemoStatus:u,visibleWorkspaces:v,workspaceLoading:f,workspaceRootAssetId:b}}function Ay(e,t,n){let r=(0,p.useRef)(!1),i=(0,p.useRef)(``),a=(0,p.useRef)(!1),o=(0,p.useRef)(``),s=(0,p.useCallback)((t=0)=>{window.setTimeout(()=>{e&&(r.current=!0,e.fitView({maxZoom:.9,padding:.32}),window.setTimeout(()=>{r.current=!1},450))},t)},[e]),c=(0,p.useCallback)(()=>{r.current||(a.current=!0)},[]);return(0,p.useEffect)(()=>{if(!t||!e)return;o.current!==t&&(o.current=t,a.current=!1,i.current=``);let r=`${t}:${n?`side-open`:`side-closed`}`;i.current!==r&&(i.current=r,a.current||s(280))},[s,e,t,n]),{fitGraph:s,markViewportInteraction:c}}function jy({actionsOpen:e,asset:t,onActionsOpenChange:n,onAssetsChanged:r,project:i,onSelectedAsset:a,onToast:o}){let[s,c]=(0,p.useState)(null),[l,u]=(0,p.useState)(null),[d,f]=(0,p.useState)(``),[m,_]=(0,p.useState)(null),[v,y]=(0,p.useState)(null),[b,x]=(0,p.useState)([]),[S]=(0,p.useState)(Cm),[C,w]=(0,p.useState)(null),[T,E]=(0,p.useState)([]),[D,O]=(0,p.useState)(!0),[k,A]=(0,p.useState)(null),[j,M]=(0,p.useState)(`LR`),[N,P]=(0,p.useState)(``),[F,I]=(0,p.useState)(null),[L,R]=(0,p.useState)(!1),[z,B]=(0,p.useState)(!1),[V,H]=(0,p.useState)(!1),[U,W,ee]=Bp([]),[te,ne]=Vp([]),[re,ie]=(0,p.useState)(null),[ae,oe]=(0,p.useState)(!1),[se,G]=(0,p.useState)(null),[ce,le]=(0,p.useState)(0),[K,ue]=(0,p.useState)(null),[de,q]=(0,p.useState)(-1),[fe,pe]=(0,p.useState)(`settled`),[me,J]=(0,p.useState)(!1),[he,Y]=(0,p.useState)(1),[ge,_e]=(0,p.useState)(!1),ve=(0,p.useMemo)(()=>K?Cy(K):{stages:[]},[K]),ye=ve.stages.length-1,be=!!(K&&de===ye&&fe===`settled`),xe=K&&!be?K:s,Se=s?.nodes.find(e=>e.asset_id===l)||s?.nodes[0],Ce=s?.edges.find(e=>e.id===k?.edgeId),we=s?.nodes.filter(e=>s.latest.includes(e.asset_id))||[],Te=s?.selected.map(e=>s.nodes.find(t=>t.asset_id===e)).filter(e=>!!e)||[],Ee=Te[0],De=Te.length>=3,Oe=s?.nodes.find(e=>e.asset_id===m)||null,ke=s?.nodes.find(e=>e.asset_id===v)||null,Ae=s?.nodes.find(e=>e.asset_id===F?.assetId),je=S&&!Oe&&!ke&&!Ce&&(!K||be),Me=!!(Se&&N!==(Se.selection_note||``)),Ne=(0,p.useRef)(null),Z=(0,p.useRef)([]),Pe=(0,p.useRef)(``),Fe=(0,p.useRef)(``),{fitGraph:Ie,markViewportInteraction:Le}=Ay(re,s?.root_asset_id,z),Re=(0,p.useCallback)(()=>{le(e=>e+1),I(null)},[]),ze=(0,p.useRef)(i);(0,p.useEffect)(()=>{ze.current=i},[i]);let Be=(0,p.useCallback)(()=>{u(null),Re()},[Re]),Ve=(0,p.useCallback)(()=>{c(null),u(null),w(null),ue(null),J(!1),pe(`settled`),q(-1)},[]),{activateWorkspace:He,activeWorkspace:Ue,archiveWorkspace:We,demoSeedStatus:Ge,downloadSwissifierDemoMedia:Ke,handleWorkspaceCreated:qe,refreshDemoSeedStatus:Je,refreshWorkspaces:Ye,restoreDemoSeedMedia:Xe,restoreSwissifierDemoMedia:Ze,seedDemoWorkspace:Qe,seedSwissifierDemoWorkspace:$e,swissifierDemoStatus:et,visibleWorkspaces:tt,workspaceLoading:nt,workspaceRootAssetId:rt}=ky({asset:t,onResetLineage:Ve,onSelectedAsset:a,onToast:o,project:i});Fe.current=rt,(0,p.useEffect)(()=>{Je()},[Je]);let it=(0,p.useCallback)(async(e={})=>{let t=e.rootAssetId||rt;if(!t)return!1;e.quiet||oe(!0);try{let n=new URLSearchParams({project:i}),[r,a]=await Promise.all([g(`/api/lineage/${t}?${n.toString()}`),g(`/api/agent-claims?${n.toString()}`)]);return!e.rootAssetId&&Fe.current!==t?!1:(c(r),E(a.claims),e.quiet||w(null),u(t=>Rm(t,r.nodes,r.active_asset_id,!!e.quiet)),!0)}catch(n){return!e.rootAssetId&&Fe.current!==t||!e.quiet&&ze.current===i&&(c(null),o(`error`,n instanceof Error?n.message:String(n))),!1}finally{!e.quiet&&ze.current===i&&oe(!1)}},[o,i,rt]),at=(0,p.useCallback)(()=>{!s||!Sy(s)||(Ne.current&&window.clearTimeout(Ne.current),Re(),u(null),_(null),y(null),x([]),A(null),B(!1),H(!1),ue(s),q(-1),pe(`node`),J(!0))},[Re,s]),ot=(0,p.useCallback)(()=>{ue(null),q(-1),pe(`settled`),J(!1),it({quiet:!0})},[it]),st=(0,p.useCallback)(()=>{be&&s&&ue(s),q(-1),pe(`node`),J(!0)},[be,s]),ct=(0,p.useCallback)(()=>{if(be){st();return}J(e=>!e)},[be,st]),lt=(0,p.useCallback)(e=>{J(!1),pe(`settled`),q(Math.max(0,Math.min(e,ye)))},[ye]);async function ut(){G(null),oe(!0);try{o(`ok`,`Indexed ${(await g(`/api/index/local`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:i})})).summary.total} assets`),await Ye(),await it()}catch(e){o(`error`,e instanceof Error?e.message:String(e))}finally{oe(!1)}}async function dt(){Re(),G(null);let e=await Qe();if(e)try{await r?.(),await it({rootAssetId:e.workspace?.root_asset_id||e.root_asset_id})}catch(e){o(`error`,e instanceof Error?e.message:String(e))}}async function ft(){Re(),G(`seeding`);let e=await $e();if(!e){G(`error`);return}try{G(`indexing`),await r?.(),await it({rootAssetId:e.workspace?.root_asset_id||e.root_asset_id})||G(`error`)}catch(e){G(`error`),o(`error`,e instanceof Error?e.message:String(e))}}async function pt(){G(`downloading`);let e=await Ke();G(e?`downloaded`:`error`)}async function mt(e,t,n){try{await g(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:i,...t})}),o(`ok`,n),await it()}catch(e){o(`error`,e instanceof Error?e.message:String(e))}}function ht(){Se&&_t(Se,N)}function gt(){Se?.user_selected&&_t(Se,N)}async function _t(e,t=e.selection_note||``){if(!e.user_selected&&De){o(`error`,`Choose at most 3 assets for next variation`);return}await mt(`/api/selection`,{assetId:e.asset_id,rootAssetId:s?.root_asset_id,mode:e.user_selected?`remove`:`add`,notes:t,confirmWrite:!0},e.user_selected?`Removed ${e.asset_id} from next variation`:`Using ${e.asset_id} for next variation`)}async function vt(e,t=e.selection_note||``){await mt(`/api/selection`,{assetId:e.asset_id,rootAssetId:s?.root_asset_id,mode:`replace`,notes:t,confirmWrite:!0},`Using only ${e.asset_id} for next variation`)}async function yt(e){if(s){if(e){await mt(`/api/selection`,{assetId:e,rootAssetId:s.root_asset_id,mode:`remove`,confirmWrite:!0},`Removed ${e} from next variation`);return}Te.length>0&&await mt(`/api/selection`,{rootAssetId:s.root_asset_id,clear:!0,confirmWrite:!0},`Removed all assets from next variation`)}}function bt(){if(Ne.current&&window.clearTimeout(Ne.current),z){B(!1),Ne.current=window.setTimeout(()=>H(!1),260);return}H(!0),window.requestAnimationFrame(()=>B(!0))}async function xt(e,t=Se?.asset_id){if(!t)return;let n=s?.nodes.find(e=>e.asset_id===t),r=Lh(n,e);r&&!window.confirm(r.confirmation)||(r&&await yt(t),mt(`/api/reviews/${t}`,{reviewState:e,confirmWrite:!0},`Marked ${t} ${e}`))}async function St(e){s&&await mt(`/api/lineage/${s.root_asset_id}/rerolls/${e.asset_id}`,{confirmWrite:!0,requestedBy:`human`},`Marked ${e.asset_id} for re-roll`)}async function Ct(e){s&&await mt(`/api/lineage/${s.root_asset_id}/rerolls/${e.asset_id}/cancel`,{confirmWrite:!0},`Cleared re-roll request for ${e.asset_id}`)}async function wt(e){if(s)try{let t=new URLSearchParams({project:i}),n=await g(`/api/lineage/${s.root_asset_id}/attempts/${e}?${t.toString()}`);x(n.attempts),y(e)}catch(e){o(`error`,e instanceof Error?e.message:String(e))}}function Tt(){y(null),x([])}function Et(e){Tt(),_(e)}async function Dt(e){if(!(!s||!v))try{let t=await g(`/api/lineage/${s.root_asset_id}/attempts/${v}/promote`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:i,attemptId:e.id,confirmWrite:!0})});x(t.attempts),o(`ok`,`Set v${e.attempt_index} as current`),await it({quiet:!0})}catch(e){o(`error`,e instanceof Error?e.message:String(e))}}async function Ot(){!Se||!d.trim()||(await mt(`/api/lineage/link`,{childAssetId:d.trim(),confirmWrite:!0,parentAssetId:Se.asset_id},`Linked ${d.trim()} from ${Se.asset_id}`),f(``))}async function kt(e,t){if(Ce)try{let n=await g(`/api/lineage/edges/${encodeURIComponent(Ce.id)}/summary`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:e,confirmWrite:!0,expectedSummaryUpdatedAt:Ce.summary_updated_at||null,project:i,...e===`set`?{summary:t}:{}})});await it({quiet:!0}),o(`ok`,n.message),A(null)}catch(e){throw e instanceof h&&e.status===409&&e.message.includes(`Edge summary changed since it was opened`)?(await it({quiet:!0}),Error(`This edge changed elsewhere. The current label has been reloaded; review it and retry.`,{cause:e})):e}}async function At(e){if(!s)return;if(e.asset_id===s.root_asset_id){o(`error`,`Root lineage node cannot be removed. Archive this workspace or start a new lineage instead.`);return}let t=s.edges.filter(t=>t.parent_asset_id===e.asset_id).length,n=s.edges.filter(t=>t.child_asset_id===e.asset_id).length,r=t>0&&n>0?` Its ${t} child${t===1?``:`ren`} will be reconnected to its parent${n===1?``:`s`}.`:``;window.confirm(`Remove "${e.title}" from this lineage? This keeps the asset file and S3 object intact.${r}`)&&(await mt(`/api/lineage/remove-node`,{assetId:e.asset_id,rootAssetId:s.root_asset_id,confirmWrite:!0},`Removed ${e.asset_id} from lineage`),I(null),_(t=>t===e.asset_id?null:t),u(t=>t===e.asset_id?s.root_asset_id:t))}async function jt(e){if(s)try{await Fh(i,s.root_asset_id,[{assetId:e.id,x:e.position.x,y:e.position.y}])}catch(e){o(`error`,e instanceof Error?e.message:String(e))}}async function Mt(){if(!s)return;let e=[...xy(s,j)].map(([e,t])=>({assetId:e,...t}));Pt(e),W(t=>t.map(t=>({...t,position:e.find(e=>e.assetId===t.id)||t.position})));try{await Fh(i,s.root_asset_id,e),o(`ok`,`Tidied ${e.length} lineage nodes`),Ie(80),await it({quiet:!0})}catch(e){o(`error`,e instanceof Error?e.message:String(e))}}async function Nt(e){if(!s)return;let t=[...xy(s,e)].map(([e,t])=>({assetId:e,...t}));Pt(t),M(e),W(e=>e.map(e=>({...e,position:t.find(t=>t.assetId===e.id)||e.position})));try{await Fh(i,s.root_asset_id,t),o(`ok`,`Rotated lineage graph ${Ny(e).toLowerCase()}`),Ie(80),await it({quiet:!0})}catch(e){o(`error`,e instanceof Error?e.message:String(e))}}function Pt(e){let t=new Map(e.map(e=>[e.assetId,{x:e.x,y:e.y}]));c(e=>e&&{...e,nodes:e.nodes.map(e=>({...e,position:t.get(e.asset_id)||e.position}))})}async function Ft(){if(s)try{let e=new URLSearchParams({project:i});w(await g(`/api/lineage/${s.root_asset_id}/brief?${e.toString()}`))}catch(e){o(`error`,e instanceof Error?e.message:String(e))}}async function It(e,t,n){try{await g(`/api/agent-claims/${t.id}/${e}`,{body:JSON.stringify({project:i,...n}),headers:{"Content-Type":`application/json`},method:`POST`}),o(`ok`,`Updated claim ${t.id}`),await it({quiet:!0})}catch(e){o(`error`,e instanceof Error?e.message:String(e))}}(0,p.useEffect)(()=>{Ye()},[Ye]),(0,p.useEffect)(()=>{it()},[it]),(0,p.useEffect)(()=>{rt||Ve()},[Ve,rt]),(0,p.useEffect)(()=>{if(!s)return;let e=window.setInterval(()=>void it({quiet:!0}),8e3);return()=>window.clearInterval(e)},[it,s?.root_asset_id]),(0,p.useEffect)(()=>{let e=window.matchMedia?.(`(prefers-reduced-motion: reduce)`);if(!e)return;let t=()=>_e(e.matches);return t(),e.addEventListener?.(`change`,t),()=>e.removeEventListener?.(`change`,t)},[]),(0,p.useEffect)(()=>{if(!K||!me||ye<0)return;let e=Math.min(de+1,ye);if(fe===`settled`&&de>=ye){J(!1);return}let t=ve.stages[e],n=ge?40:void 0,r=n??120/he,i=()=>{let e=t.enteringEdgeIds.length>0?`edge`:`node`;pe(e)};fe===`edge`?(r=n??320/he,i=()=>{t.enteringNodeIds.length>0?pe(`node`):(q(e),pe(`settled`))}):fe===`node`&&(r=n??200/he,i=()=>{q(e),pe(`settled`)});let a=window.setTimeout(i,r);return()=>window.clearTimeout(a)},[ge,ye,fe,me,K,he,de,ve.stages]);let Lt=(0,p.useMemo)(()=>_y(xe,l,j,D),[l,D,j,xe]),Rt=(0,p.useMemo)(()=>K&&!be?wy(Lt.nodes,Lt.edges,ve,de,fe):Lt,[Lt,be,fe,K,de,ve]),zt=(0,p.useMemo)(()=>yy(xe,j),[j,xe]);Z.current=Rt.edges;let Bt=(0,p.useCallback)(e=>{ne(t=>Ih(e,t,Z.current))},[ne]),Vt=(0,p.useCallback)(e=>{e.key===`Escape`&&Re()},[Re]);return(0,p.useEffect)(()=>{P(Se?.selection_note||``)},[Se?.asset_id,Se?.selection_note]),(0,p.useEffect)(()=>{let e=Pe.current!==zt;Pe.current=zt,W(t=>Rt.nodes.map(n=>({...n,position:e?n.position:t.find(e=>e.id===n.id)?.position||n.position}))),ne(Rt.edges)},[Rt.edges,Rt.nodes,zt,ne,W]),(0,p.useEffect)(()=>{se!==`indexing`||!s?.nodes.length||Pe.current!==zt||U.length!==s.nodes.length||G(`ready`)},[U.length,zt,s,se]),Oy(!!l,Be),(0,p.useEffect)(()=>()=>{Ne.current&&window.clearTimeout(Ne.current)},[]),(0,p.useEffect)(()=>{Ve(),G(null)},[i,Ve]),(0,X.jsxs)(`section`,{className:`lineage-view`,onKeyDownCapture:Vt,children:[(0,X.jsx)(Ph,{actionsOpen:e,activeWorkspace:Ue,closeSignal:ce,edgeSummariesVisible:D,loading:ae,graphDirection:j,demoSeedStatus:Ge,onArchiveWorkspace:()=>{G(null),We()},onActionsOpenChange:n,onFitGraph:()=>Ie(),onIndexLocal:()=>void ut(),onGraphDirection:e=>void Nt(e),onNewLineage:()=>{G(null),R(!0)},onRefreshLineage:()=>void it(),onRefreshWorkspaces:()=>void Ye(),onReplayGrowth:at,onRestoreDemoMedia:()=>void Xe(),onRestoreSwissifierMedia:()=>void Ze(),onDownloadSwissifierMedia:()=>void pt(),onEdgeSummariesVisible:()=>O(e=>!e),onSeedDemo:()=>void dt(),onSeedSwissifierDemo:()=>void ft(),onSelectWorkspace:e=>{G(null),He(e)},onTidyGraph:()=>void Mt(),onToggleNextPanel:bt,replayActive:!!K,sideOpen:z,snapshot:s,swissifierDemoStatus:et,workspaceLoading:nt,workspaceProgress:se,workspaceRootAssetId:rt,workspaces:tt}),(0,X.jsxs)(`div`,{className:`lineage-workbench`,"data-testid":`lineage-workbench`,children:[(0,X.jsxs)(`div`,{className:`lineage-canvas ${l?`focus-active`:``} ${K?`lineage-replay-active`:``} ${be?`lineage-replay-interactive`:``} ${K&&!me?`lineage-replay-paused`:``}`,style:K?{"--lineage-replay-edge-duration":`${ge?1:320/he}ms`,"--lineage-replay-node-duration":`${ge?1:200/he}ms`}:void 0,children:[K&&ve.stages.length>0&&(0,X.jsx)(ch,{atEnd:be,onClose:ot,onPlayPause:ct,onRestart:st,onScrub:lt,onSpeed:Y,playing:me,speed:he,stageIndex:de,totalStages:ve.stages.length}),(0,X.jsx)(Nm,{flowEdges:xe?te:[],flowNodes:xe?U:[],graphKey:zt,hoverPreviewsEnabled:je,loading:ae,onEdgesChange:Bt,onEdgeEdit:(e,t)=>A({edgeId:e,returnFocus:t}),onClearFocus:Be,onIndexNow:()=>void ut(),onNewLineage:()=>{G(null),R(!0)},onSeedDemo:()=>void dt(),onNodeActionMenu:(e,t,n)=>I(e?{assetId:e,x:t,y:n}:null),onNodeInspect:e=>{Re(),u(e)},onNodeOpenDetail:_,onNodeOpenHistory:e=>void wt(e),onNodePosition:e=>void jt(e),onNodesChange:ee,onReady:ie,onSelectedAsset:a,onToggleBranch:e=>e.user_selected?yt(e.asset_id):_t(e),onToggleReroll:e=>e.reroll_request?.status===`pending`?Ct(e):St(e),onViewportInteraction:Le,replayInteractive:!K||be,selectionFull:De,workspaceProgress:se,workspaceRootAssetId:rt})]}),V&&s&&(0,X.jsx)(vh,{activeNode:Se,brief:C,childAssetId:d,clearNextVariation:yt,closePanel:bt,latestNodes:we,linkChild:Ot,markReview:xt,nextVariationLimit:3,noteDirty:Me,onSelectedAsset:a,onToast:o,project:i,refreshBrief:Ft,refreshLineage:async()=>{await it({quiet:!0})},saveRationale:gt,replaceNextVariation:vt,selectNextBase:_t,selectedNode:Ee,selectedNodes:Te,selectionFull:De,selectionNote:N,setActiveNodeId:u,setChildAssetId:f,setDetailNodeId:_,setSelected:ht,setSelectionNote:P,sideOpen:z,snapshot:s}),F&&Ae&&s&&(0,X.jsx)(Pm,{canRemoveFromLineage:Ae.asset_id!==s.root_asset_id,claims:My(T,i,s.root_asset_id),node:Ae,onClaimControl:(e,t,n)=>{It(e,t,n)},onClearAllNext:()=>void yt(),onClearNext:()=>void yt(Ae.asset_id),onClearReroll:()=>void Ct(Ae),onClose:()=>I(null),onMarkReroll:()=>void St(Ae),onOpenDetail:()=>_(Ae.asset_id),onRemoveFromLineage:()=>void At(Ae),onReplaceNext:()=>vt(Ae),onReview:e=>void xt(e,Ae.asset_id),onSelectNext:()=>_t(Ae),position:F,selectedCount:Te.length,selectionFull:De})]}),ke&&s&&(0,X.jsx)(Wm,{actions:{canRemoveFromLineage:ke.asset_id!==s.root_asset_id,onClearAllNext:()=>void yt(),onClearNext:()=>void yt(ke.asset_id),onOpenNode:Et,onRemoveFromLineage:e=>void At(e),onReplaceNext:vt,onReview:xt,onSelectNext:_t,onToast:o,selectedCount:Te.length,selectionFull:De,snapshot:s},attempts:b,node:ke,onClose:Tt,onPromoteAttempt:Dt,project:i}),Oe&&s&&(0,X.jsx)(Xm,{canRemoveFromLineage:Oe.asset_id!==s.root_asset_id,node:Oe,onClearAllNext:()=>void yt(),onClearNext:()=>void yt(Oe.asset_id),onClose:()=>_(null),onOpenNode:_,onRemoveFromLineage:e=>void At(e),onReplaceNext:vt,onReview:xt,onSelectNext:_t,onToast:o,selectedCount:Te.length,selectionFull:De,snapshot:s}),Ce&&k&&s&&(0,X.jsx)($m,{childTitle:s.nodes.find(e=>e.asset_id===Ce.child_asset_id)?.title||Ce.child_asset_id,edge:Ce,onClose:()=>A(null),onSubmit:kt,parentTitle:s.nodes.find(e=>e.asset_id===Ce.parent_asset_id)?.title||Ce.parent_asset_id,returnFocus:k.returnFocus}),(0,X.jsx)(sh,{onClose:()=>R(!1),onCreated:qe,onToast:o,open:L,project:i})]})}function My(e,t,n){let r=`${t}:lineage-workspace:${n}`;return e.filter(e=>e.project!==t||e.status!==`active`||e.derived_state===`expired`?!1:e.scope_type===`lineage_workspace`?e.target_id===r:e.scope_type===`project_channel`)}function Ny(e){return{BT:`bottom to top`,LR:`left to right`,RL:`right to left`,TB:`top to bottom`}[e]}function Py({assets:e,onClose:t,onDone:n,onError:r,project:i}){let a=e[0],[o,s]=(0,p.useState)(!1),[c,l]=(0,p.useState)(!1),[u,d]=(0,p.useState)([]),[f,m]=(0,p.useState)({audience:a?.audience||`local-review`,campaign:a?.campaign||`local-review`,channel:a?.channel===`local`?`meta`:a?.channel||`meta`,cta:a?.cta||`Review before upload`,status:`working`}),h=e.filter(e=>!Iy(e)),_=h.length>0||e.length===0;function v(e,t){m(n=>({...n,[e]:t}))}function y(e,t){let n=pe(e.title)||e.asset_id;return{...f,assetId:n,confirmWrite:o,dryRun:t,hook:e.hook,notes:e.notes,path:e.local?.relative_path,project:i,title:e.title,type:e.content_type,utmContent:e.utm_content||n.replaceAll(`-`,`_`)}}async function b(t){if(_){r(`Local backup is locked until every selected local asset is approved.`);return}l(!0);try{let r=[];for(let n of e){if(!n.local?.relative_path)throw Error(`${n.asset_id} has no local path`);let e=await g(`/api/assets/local-backup`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(y(n,t))});r.push(e.message)}t?d(r):await n(`Backed up ${e.length} local asset${e.length===1?``:`s`}`)}catch(e){r(e instanceof Error?e.message:String(e))}finally{l(!1)}}return(0,X.jsx)(`div`,{className:`drawer-backdrop`,children:(0,X.jsxs)(`section`,{className:`local-backup-drawer`,children:[(0,X.jsxs)(`header`,{children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h2`,{children:`Back up local assets`}),(0,X.jsx)(`p`,{children:i})]}),(0,X.jsx)(`button`,{onClick:t,children:`Close`})]}),(0,X.jsx)(`div`,{className:`local-backup-list`,children:e.map(e=>(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`strong`,{children:pe(e.title)||e.asset_id}),(0,X.jsx)(`span`,{children:e.local?.relative_path}),(0,X.jsxs)(`span`,{children:[`Review: `,Ly(Fy(e))]})]},e.asset_id))}),_&&(0,X.jsxs)(`div`,{className:`local-backup-warning`,role:`alert`,children:[(0,X.jsx)(`strong`,{children:`Backup is locked until local review is approved.`}),e.length===0?(0,X.jsx)(`span`,{children:`No local assets are selected.`}):null,h.map(e=>(0,X.jsxs)(`span`,{children:[pe(e.title)||e.asset_id,`: `,Ly(Fy(e))]},e.asset_id))]}),(0,X.jsxs)(`div`,{className:`form-grid`,children:[(0,X.jsxs)(`label`,{children:[`Campaign`,(0,X.jsx)(`input`,{value:f.campaign,onChange:e=>v(`campaign`,e.target.value)})]}),(0,X.jsxs)(`label`,{children:[`Channel`,(0,X.jsx)(`input`,{value:f.channel,onChange:e=>v(`channel`,e.target.value)})]}),(0,X.jsxs)(`label`,{children:[`Audience`,(0,X.jsx)(`input`,{value:f.audience,onChange:e=>v(`audience`,e.target.value)})]}),(0,X.jsxs)(`label`,{children:[`Status`,(0,X.jsxs)(`select`,{value:f.status,onChange:e=>v(`status`,e.target.value),children:[(0,X.jsx)(`option`,{children:`working`}),(0,X.jsx)(`option`,{children:`published`})]})]}),(0,X.jsxs)(`label`,{className:`wide`,children:[`CTA`,(0,X.jsx)(`input`,{value:f.cta,onChange:e=>v(`cta`,e.target.value)})]})]}),u.length>0&&(0,X.jsx)(`div`,{className:`local-backup-preview`,children:u.map(e=>(0,X.jsx)(`span`,{children:e},e))}),(0,X.jsxs)(`label`,{className:`confirm-line`,children:[(0,X.jsx)(`input`,{checked:o,type:`checkbox`,onChange:e=>s(e.target.checked)}),(0,X.jsx)(`span`,{children:`Confirm write to the production asset bucket`})]}),(0,X.jsxs)(`footer`,{children:[(0,X.jsx)(`button`,{disabled:c||_,onClick:()=>void b(!0),children:`Dry run`}),(0,X.jsxs)(`button`,{className:`primary-button`,disabled:c||_||!o,onClick:()=>void b(!1),children:[c?(0,X.jsx)(ee,{className:`spin`,size:16}):(0,X.jsx)(E,{size:16}),`Back up`]})]})]})})}function Fy(e){return e.review?.review_state||`unreviewed`}function Iy(e){return!!e.local?.relative_path&&Fy(e)===`approved`}function Ly(e){return e===`needs_revision`?`needs revision`:e}var Ry=[[`unreviewed`,`Needs review`],[`approved`,`Approved keepers`],[`needs_revision`,`Needs revision`],[`rejected`,`Rejected or ignored`]];function zy(e){let t=e.assets.filter(e=>e.local?.relative_path&&!e.s3?.key),n=t.filter(e=>Hy(e)===`approved`),r=e.selectedBackupIds.length,i=Z(e.cli||null,`local queue --project '${e.project}'`);function a(){for(let t of n)e.onQueueBackup(t)}return(0,X.jsxs)(`section`,{className:`local-backup-queue`,children:[(0,X.jsxs)(`header`,{className:`backup-queue-head`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h2`,{children:`Local Backup Queue`}),(0,X.jsx)(`p`,{children:`Review local-only candidates, select approved keepers, then back them up intentionally.`}),(0,X.jsxs)(`p`,{children:[e.snapshot?.catalog.default_bucket||`No bucket loaded`,` · refreshed `,fe(e.snapshot?.fetchedAt)]})]}),(0,X.jsxs)(`div`,{className:`backup-queue-actions`,children:[(0,X.jsxs)(`button`,{disabled:n.length===0,onClick:a,type:`button`,children:[(0,X.jsx)(w,{size:15}),` Select approved`]}),(0,X.jsxs)(`button`,{disabled:r===0,onClick:e.onOpenBackup,type:`button`,children:[(0,X.jsx)(E,{size:15}),` Back up selected`]})]})]}),(0,X.jsxs)(`div`,{className:`backup-queue-stats`,"aria-label":`Local backup queue summary`,children:[(0,X.jsx)(Vy,{label:`Local only`,value:t.length}),(0,X.jsx)(Vy,{label:`Needs review`,value:t.filter(e=>Hy(e)===`unreviewed`).length}),(0,X.jsx)(Vy,{label:`Approved`,value:n.length}),(0,X.jsx)(Vy,{label:`Selected`,value:r})]}),(0,X.jsxs)(`div`,{className:`handoff-strip`,children:[(0,X.jsx)(`code`,{children:i}),(0,X.jsxs)(`button`,{onClick:()=>void e.onCopy(i,`local backup queue command`),type:`button`,children:[(0,X.jsx)(T,{size:14}),` Copy`]})]}),t.length===0?(0,X.jsx)(`div`,{className:`backup-empty`,children:`No local-only assets are waiting for review or backup.`}):(0,X.jsx)(`div`,{className:`backup-queue-grid`,children:Ry.map(([n,r])=>(0,X.jsxs)(`section`,{className:`backup-queue-lane`,children:[(0,X.jsx)(`h3`,{children:r}),t.filter(e=>Uy(e)===n).map(t=>(0,X.jsx)(By,{asset:t,onLocalReview:e.onLocalReview,onQueueBackup:e.onQueueBackup,onSelectAsset:e.onSelectAsset,selected:e.selected?.asset_id===t.asset_id,selectedForBackup:e.selectedBackupIds.includes(t.asset_id)},t.asset_id))]},n))}),(0,X.jsxs)(`footer`,{className:`pagination-bar`,children:[(0,X.jsx)(`button`,{disabled:!e.snapshot||e.snapshot.pagination.page<=1,onClick:()=>e.setPage(e=>Math.max(e-1,1)),type:`button`,children:`Previous`}),(0,X.jsxs)(`span`,{children:[e.snapshot?.pagination.page||e.page,` of `,e.snapshot?.pagination.totalPages||1]}),(0,X.jsx)(`button`,{disabled:!e.snapshot||e.snapshot.pagination.page>=e.snapshot.pagination.totalPages,onClick:()=>e.setPage(e=>e+1),type:`button`,children:`Next`}),(0,X.jsxs)(`label`,{children:[`Per page`,(0,X.jsx)(`select`,{onChange:t=>e.setPageSize(Number(t.target.value)),value:e.pageSize,children:[10,25,50,100].map(e=>(0,X.jsx)(`option`,{value:e,children:e},e))})]})]})]})}function By(e){let t=Hy(e.asset),n=ye(e.asset),r=t===`approved`;return(0,X.jsxs)(`article`,{className:`backup-queue-card ${e.selected?`selected`:``}`,children:[(0,X.jsx)(`strong`,{children:e.asset.title}),(0,X.jsx)(`code`,{children:e.asset.asset_id}),(0,X.jsx)(`small`,{children:e.asset.local?.relative_path}),(0,X.jsxs)(`div`,{className:`backup-card-meta`,children:[(0,X.jsx)(`span`,{children:n.label}),(0,X.jsx)(`span`,{children:Wy(t)}),(0,X.jsx)(`span`,{children:q(e.asset.local?.size_bytes)})]}),(0,X.jsxs)(`div`,{className:`backup-card-actions`,children:[(0,X.jsx)(`button`,{onClick:()=>e.onSelectAsset(e.asset),type:`button`,children:`Open`}),(0,X.jsx)(`button`,{"aria-pressed":t===`approved`,onClick:()=>void e.onLocalReview(e.asset,`approved`),type:`button`,children:`Approve`}),(0,X.jsx)(`button`,{"aria-pressed":t===`needs_revision`,onClick:()=>void e.onLocalReview(e.asset,`needs_revision`),type:`button`,children:`Revise`}),(0,X.jsx)(`button`,{"aria-pressed":t===`rejected`,onClick:()=>void e.onLocalReview(e.asset,`rejected`),type:`button`,children:`Reject`}),(0,X.jsx)(`button`,{disabled:!r,onClick:()=>e.onQueueBackup(e.asset),type:`button`,children:e.selectedForBackup?`Selected`:r?`Select backup`:`Approve first`})]})]})}function Vy({label:e,value:t}){return(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`strong`,{children:t}),(0,X.jsx)(`span`,{children:e})]})}function Hy(e){return e.review?.review_state||`unreviewed`}function Uy(e){let t=Hy(e);return t===`ignored`?`rejected`:t}function Wy(e){return e===`needs_revision`?`needs revision`:e}function Gy({assets:e,onClear:t,onOpen:n}){return e.length===0?null:(0,X.jsxs)(`div`,{className:`local-selection-toolbar`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`strong`,{children:[e.length,` local keeper`,e.length===1?``:`s`,` selected`]}),(0,X.jsx)(`span`,{children:`Ready for S3 backup preflight`})]}),(0,X.jsxs)(`button`,{onClick:n,children:[(0,X.jsx)(E,{size:16}),`Back up selected`]}),(0,X.jsx)(`button`,{"aria-label":`Clear local backup selection`,className:`icon-lite`,onClick:t,children:(0,X.jsx)(de,{size:16})})]})}function Ky(e){return e.find(e=>qy(e)>0)?.channel||e[0]?.channel}function qy(e){return e.totals.needsQa+e.totals.approvedLocal+e.totals.needsRevision+e.totals.rejectedLocal}var Jy=[[`needsQa`,`Needs QA`],[`approvedLocal`,`Approved`],[`needsRevision`,`Revise`],[`rejectedLocal`,`Rejected`],[`readyToPost`,`S3 ready`],[`scheduled`,`Scheduled`],[`posted`,`Posted`]];function Yy(e){let[t,n]=(0,p.useState)(null),[r,i]=(0,p.useState)(null),[a,o]=(0,p.useState)(null),[s,c]=(0,p.useState)([]),[l,u]=(0,p.useState)(``);async function d(){try{let t=new URLSearchParams({project:e.project,limit:`4`});e.channel!==`all`&&t.set(`channel`,e.channel),n(await g(`/api/review/queue?${t.toString()}`)),i(null)}catch(e){i(e instanceof Error?e.message:String(e))}}if((0,p.useEffect)(()=>{d()},[e.project,e.channel]),r)return(0,X.jsx)(`section`,{className:`review-queue`,children:(0,X.jsx)(`div`,{className:`toast error`,children:r})});if(!t)return(0,X.jsx)(`section`,{className:`review-queue`,children:(0,X.jsx)(`div`,{className:`asset-board`,children:(0,X.jsx)(`div`,{className:`board-head`,children:(0,X.jsx)(`h2`,{children:`Loading review queue`})})})});let f=t.totals.needsQa+t.totals.approvedLocal+t.totals.needsRevision+t.totals.rejectedLocal,m=new Set(t.lanes.flatMap(e=>[...e.needsQa,...e.approvedLocal,...e.needsRevision,...e.rejectedLocal]).map(e=>e.asset_id)),h=s.filter(e=>m.has(e)),_=Ky(t.lanes);function v(e){c(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])}async function y(t){if(h.length!==0){o(`batch`);try{await g(`/api/local-review/batch`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({assetIds:h,confirmWrite:!0,notes:l,project:e.project,reviewState:t})}),c(e=>e.filter(e=>!m.has(e))),u(``),await d()}finally{o(null)}}}return(0,X.jsxs)(`section`,{className:`review-queue`,children:[(0,X.jsxs)(`div`,{className:`review-summary`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`h2`,{children:[t.project,` review queue`]}),(0,X.jsx)(`p`,{children:`Local-first queue for demo assets, channel posting state, and agent handoff.`}),(0,X.jsxs)(`p`,{children:[t.totals.channels,` channels · refreshed `,fe(t.fetchedAt)]})]}),(0,X.jsx)(Xy,{label:`Local review`,value:f}),(0,X.jsx)(Xy,{label:`S3 ready`,value:t.totals.readyToPost}),(0,X.jsx)(Xy,{label:`Scheduled`,value:t.totals.scheduled}),(0,X.jsx)(Xy,{label:`Posted`,value:t.totals.posted})]}),h.length>0?(0,X.jsxs)(`div`,{className:`batch-review-strip`,"aria-label":`Batch local review actions`,children:[(0,X.jsxs)(`strong`,{children:[h.length,` selected`]}),(0,X.jsx)(`textarea`,{"aria-label":`Shared batch review notes`,onChange:e=>u(e.target.value),placeholder:`Shared review notes`,rows:2,value:l}),(0,X.jsx)(`button`,{disabled:h.length===0||a===`batch`,onClick:()=>void y(`approved`),type:`button`,children:`Approve`}),(0,X.jsx)(`button`,{disabled:h.length===0||a===`batch`,onClick:()=>void y(`needs_revision`),type:`button`,children:`Needs revision`}),(0,X.jsx)(`button`,{disabled:h.length===0||a===`batch`,onClick:()=>void y(`rejected`),type:`button`,children:`Reject`})]}):null,(0,X.jsx)(`div`,{className:`queue-lanes`,children:t.lanes.map(t=>(0,X.jsxs)(`details`,{className:`queue-lane`,open:e.channel!==`all`||t.channel===_,children:[(0,X.jsxs)(`summary`,{children:[(0,X.jsx)(`h3`,{children:t.channel}),(0,X.jsxs)(`div`,{className:`lane-counts`,children:[(0,X.jsxs)(`span`,{children:[t.totals.needsQa,` qa`]}),(0,X.jsxs)(`span`,{children:[t.totals.approvedLocal,` approved`]}),(0,X.jsxs)(`span`,{children:[t.totals.needsRevision,` revise`]}),(0,X.jsxs)(`span`,{children:[t.totals.readyToPost,` ready`]}),(0,X.jsxs)(`span`,{children:[t.totals.scheduled,` scheduled`]}),(0,X.jsxs)(`span`,{children:[t.totals.posted,` posted`]})]})]}),(0,X.jsxs)(`div`,{className:`queue-columns`,children:[Jy.filter(([e])=>t[e].length>0).map(([n,r])=>(0,X.jsx)(Zy,{assets:t[n],label:r,onCopy:e.onCopy,onLocalReview:async(t,n)=>{o(t.asset_id);try{await e.onLocalReview(t,n),await d()}finally{o(null)}},onOpenBackup:e.onOpenBackup,onSelectAsset:e.onSelectAsset,pendingReview:a,selected:e.selected,selectedReviewIds:h,onToggleReviewSelection:v},n)),Jy.every(([e])=>t[e].length===0)&&(0,X.jsx)(`p`,{className:`review-empty`,children:`No items in this channel.`})]})]},t.channel))})]})}function Xy({label:e,value:t}){return(0,X.jsxs)(`div`,{className:`queue-stat`,children:[(0,X.jsx)(`strong`,{children:t}),(0,X.jsx)(`span`,{children:e})]})}function Zy(e){return(0,X.jsxs)(`div`,{className:`queue-column`,children:[(0,X.jsx)(`h4`,{children:e.label}),e.assets.map(t=>(0,X.jsx)(Qy,{asset:t,onCopy:e.onCopy,onLocalReview:e.onLocalReview,onOpenBackup:e.onOpenBackup,onSelectAsset:e.onSelectAsset,onToggleReviewSelection:e.onToggleReviewSelection,pendingReview:e.pendingReview===t.asset_id,selected:e.selected?.asset_id===t.asset_id,selectedForReview:e.selectedReviewIds.includes(t.asset_id)},t.asset_id))]})}function Qy(e){let t=Ne(),n=ye(e.asset),r=e.asset.local?$y(e.asset):null,i=r===`approved`,a=e.asset.source===`local`?Z(t,`local inspect --asset-id '${e.asset.asset_id}'`):Z(t,`inspect --asset-id '${e.asset.asset_id}'`);return(0,X.jsxs)(`article`,{className:`queue-card ${e.selected?`selected`:``}`,onClick:()=>e.onSelectAsset(e.asset),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&e.onSelectAsset(e.asset)},role:`button`,tabIndex:0,children:[r?(0,X.jsxs)(`label`,{className:`confirm-line`,onClick:e=>e.stopPropagation(),onKeyDown:ib,children:[(0,X.jsx)(`input`,{checked:e.selectedForReview,onChange:()=>e.onToggleReviewSelection(e.asset.asset_id),type:`checkbox`}),(0,X.jsx)(`span`,{children:`Select for batch review`})]}):null,(0,X.jsx)(`strong`,{children:e.asset.title}),(0,X.jsx)(`small`,{children:e.asset.asset_id}),(0,X.jsxs)(`div`,{className:`lane-counts`,children:[(0,X.jsx)(`span`,{className:`storage-chip ${n.kind}`,children:n.label}),(0,X.jsx)(`span`,{className:`queue-tag`,children:Te(e.asset)}),r?(0,X.jsx)(`span`,{className:`review-chip ${r}`,children:eb(r)}):null]}),r?(0,X.jsxs)(`div`,{className:`review-actions`,"aria-label":`Local review actions for ${e.asset.title}`,onKeyDown:ib,children:[(0,X.jsx)(`button`,{"aria-pressed":r===`approved`,disabled:e.pendingReview,type:`button`,onClick:t=>nb(t,e.onLocalReview,e.asset,`approved`),children:`Approve`}),(0,X.jsx)(`button`,{"aria-pressed":r===`needs_revision`,disabled:e.pendingReview,type:`button`,onClick:t=>nb(t,e.onLocalReview,e.asset,`needs_revision`),children:`Needs revision`}),(0,X.jsx)(`button`,{"aria-pressed":r===`rejected`,disabled:e.pendingReview,type:`button`,onClick:t=>nb(t,e.onLocalReview,e.asset,`rejected`),children:`Reject`})]}):null,(0,X.jsxs)(`div`,{className:`queue-actions`,onKeyDown:ib,children:[(0,X.jsx)(`button`,{type:`button`,onClick:t=>tb(t,e.onCopy,a),children:`Copy inspect`}),e.asset.local?i?(0,X.jsx)(`button`,{type:`button`,onClick:t=>rb(t,e.onOpenBackup,e.asset),children:`Back up`}):(0,X.jsx)(`span`,{className:`backup-locked`,title:`Approve this local asset before backup`,children:`Backup locked until approved.`}):null]})]})}function $y(e){return e.review?.review_state||`unreviewed`}function eb(e){return e===`needs_revision`?`needs revision`:e}function tb(e,t,n){e.stopPropagation(),t(n,`inspect command`)}function nb(e,t,n,r){e.stopPropagation(),t(n,r)}function rb(e,t,n){e.stopPropagation(),t(n)}function ib(e){(e.key===`Enter`||e.key===` `)&&e.stopPropagation()}var ab={channel:`dev`,version:`0.1.21`},ob={cloud:D,image_generator:V,scheduler:oe},sb={cloud:`Cloud storage`,image_generator:`Image generation`,scheduler:`Social scheduling`},cb=[{adapterType:`cloud`,ariaLabel:`Cloud storage settings`},{adapterType:`scheduler`,ariaLabel:`Social scheduling settings`},{adapterType:`image_generator`,ariaLabel:`Image generation settings`}];function lb(e){return typeof e==`boolean`?e?`on`:`off`:typeof e==`number`?String(e):typeof e==`string`?e||`not set`:JSON.stringify(e)}function ub(e){return Object.entries(e.safe_config).filter(([e])=>![`secret`,`token`,`password`,`credential`,`apiKey`].includes(e))}function db(e){return e.health_status===`configured`?`ok`:e.health_status===`missing_config`?`warn`:`muted`}function fb(e){return(0,X.jsx)(`button`,{"aria-checked":e.checked,"aria-label":e.label,className:`settings-switch ${e.checked?`on`:``}`,disabled:e.disabled,onClick:e.onClick,role:`switch`,type:`button`,children:(0,X.jsx)(`span`,{})})}function pb(e){let[t,n]=(0,p.useState)(null),[r,i]=(0,p.useState)(null),[a,s]=(0,p.useState)(!0),[c,l]=(0,p.useState)(``),[u,d]=(0,p.useState)(Cm);function f(){let t=!u;if(!wm(t)){e.onToast(`error`,`Browser storage is unavailable, so the hover preview preference could not be saved`);return}d(t),e.onToast(`ok`,`Lineage hover previews ${t?`enabled`:`disabled`}`)}async function m(){s(!0);try{let[t,r]=await Promise.all([g(`/api/adapters/settings?project=${encodeURIComponent(e.project)}`),g(`/api/runtime`)]);n(t),i(r.runtime)}catch(t){e.onToast(`error`,t instanceof Error?t.message:String(t))}finally{s(!1)}}async function h(t){let r=`${t.adapter_type}:${t.provider}`;l(r);try{let r=await g(`/api/adapters/settings/${t.adapter_type}/${t.provider}`,{body:JSON.stringify({confirmWrite:!0,enabled:!t.enabled,project:e.project,safeConfig:t.safe_config}),headers:{"Content-Type":`application/json`},method:`POST`});n(e=>e&&{...e,settings:e.settings.map(e=>e.adapter_type===r.setting.adapter_type&&e.provider===r.setting.provider?r.setting:e)}),e.onToast(`ok`,`${sb[t.adapter_type]} ${r.setting.enabled?`enabled`:`disabled`}`)}catch(t){e.onToast(`error`,t instanceof Error?t.message:String(t))}finally{l(``)}}return(0,p.useEffect)(()=>{m()},[e.project]),(0,X.jsxs)(`section`,{className:`settings-view`,children:[(0,X.jsxs)(`header`,{className:`settings-header`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h2`,{children:`Settings`}),(0,X.jsxs)(`p`,{children:[`Adapter switches, safe local preferences, and credential-source status for `,e.project,`.`]})]}),(0,X.jsxs)(`button`,{className:`secondary-button`,disabled:a,onClick:()=>void m(),type:`button`,children:[a?(0,X.jsx)(ee,{className:`spin`,size:17}):(0,X.jsx)(o,{size:17}),`Refresh`]})]}),(0,X.jsxs)(`div`,{className:`settings-sections`,children:[(0,X.jsxs)(`section`,{"aria-label":`Release information`,className:`settings-section`,children:[(0,X.jsx)(`h3`,{children:`Release`}),(0,X.jsxs)(`dl`,{className:`settings-release`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Version`}),(0,X.jsx)(`dd`,{children:r?.version||ab.version})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Channel`}),(0,X.jsx)(`dd`,{children:r?.channel||ab.channel})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Profile`}),(0,X.jsx)(`dd`,{children:r?.profile.id||`loading`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Environment`}),(0,X.jsx)(`dd`,{children:r?.profile.environment||`loading`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Binding`}),(0,X.jsx)(`dd`,{children:r?r.profile.bound?`bound`:`legacy unbound`:`loading`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Git`}),(0,X.jsx)(`dd`,{children:r?.git_sha||`not available`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Assets`}),(0,X.jsx)(`dd`,{className:`settings-path`,children:r?.asset_root||`loading`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`SQLite`}),(0,X.jsx)(`dd`,{className:`settings-path`,children:r?.database.path||`loading`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Database`}),(0,X.jsx)(`dd`,{children:r?.database.exists?`${r.database.projects??0} projects / ${r.database.workspaces??0} workspaces`:`not created yet`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Schema`}),(0,X.jsx)(`dd`,{children:r?`${r.schema.migration_keys.length} migration marker(s)`:`loading`})]})]})]}),(0,X.jsxs)(`section`,{"aria-label":`Lineage experience settings`,className:`settings-section`,children:[(0,X.jsx)(`h3`,{children:`Lineage experience`}),(0,X.jsx)(`div`,{className:`settings-grid`,children:(0,X.jsx)(`article`,{className:`settings-card`,children:(0,X.jsxs)(`div`,{className:`settings-card-head`,children:[(0,X.jsx)(`span`,{className:`settings-icon`,children:(0,X.jsx)(N,{size:19})}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h4`,{children:`Hover previews`}),(0,X.jsx)(`p`,{children:`Show the full asset and quick Branch/Re-roll/Details actions when hovering over or focusing a lineage node. Double-click details remain available when this is off.`})]}),(0,X.jsx)(fb,{checked:u,label:`Enable lineage hover previews`,onClick:f})]})})})]}),cb.map(e=>(0,X.jsxs)(`section`,{"aria-label":e.ariaLabel,className:`settings-section`,children:[(0,X.jsx)(`h3`,{children:sb[e.adapterType]}),(0,X.jsx)(`div`,{className:`settings-grid`,children:(t?.settings||[]).filter(t=>t.adapter_type===e.adapterType).map(e=>{let t=ob[e.adapter_type],n=`Enable ${e.label===`Buffer`?`Buffer scheduling`:e.label}`,r=c===`${e.adapter_type}:${e.provider}`;return(0,X.jsxs)(`article`,{className:`settings-card`,children:[(0,X.jsxs)(`div`,{className:`settings-card-head`,children:[(0,X.jsx)(`span`,{className:`settings-icon`,children:(0,X.jsx)(t,{size:19})}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h4`,{children:e.label}),(0,X.jsx)(`p`,{children:e.description})]}),(0,X.jsx)(fb,{checked:e.enabled,disabled:r,label:n,onClick:()=>void h(e)})]}),(0,X.jsxs)(`dl`,{className:`settings-meta`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Status`}),(0,X.jsxs)(`dd`,{className:db(e),children:[e.health_status===`configured`?(0,X.jsx)(w,{size:14}):(0,X.jsx)(C,{size:14}),e.health_status.replace(/_/g,` `)]})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Credential source`}),(0,X.jsx)(`dd`,{children:e.credential.label})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Secret ref`}),(0,X.jsx)(`dd`,{children:e.credential.secret_ref||`none`})]})]}),ub(e).length>0&&(0,X.jsx)(`div`,{className:`settings-config`,children:ub(e).map(([e,t])=>(0,X.jsxs)(`span`,{children:[(0,X.jsx)(`strong`,{children:e}),lb(t)]},e))})]},`${e.adapter_type}:${e.provider}`)})})]},e.adapterType)),a&&!t&&(0,X.jsx)(`div`,{className:`settings-loading`,children:`Loading settings...`})]})]})}var mb=`Lineage`,hb=`Local-first creative lineage workspace`;function gb(e){let{channel:t,channels:n,placementStatus:r,project:i,projects:a,setChannel:o,setPlacementStatus:s,setProject:c,setSource:l,setStatus:u,source:d,status:f}=e,[m,h]=(0,p.useState)(!1),[g,_]=(0,p.useState)(!0),v=a.length?a.map(e=>e.project):[i];return(0,X.jsxs)(`aside`,{className:`sidebar ${g?``:`collapsed`}`,children:[(0,X.jsx)(`button`,{"aria-label":g?`Collapse sidebar`:`Expand sidebar`,className:`sidebar-collapse-toggle`,onClick:()=>_(e=>!e),type:`button`,children:g?(0,X.jsx)(ne,{size:16}):(0,X.jsx)(re,{size:16})}),(0,X.jsxs)(`div`,{className:`brand`,children:[(0,X.jsx)(`div`,{className:`brand-mark`,"aria-label":hb,children:`L`}),(0,X.jsxs)(`div`,{className:`brand-copy`,children:[(0,X.jsx)(`h1`,{children:mb}),(0,X.jsxs)(`p`,{children:[(0,X.jsx)(`span`,{children:i}),(0,X.jsxs)(`span`,{"aria-label":`Lineage version ${ab.version}`,className:`brand-version`,title:`Lineage version ${ab.version}, ${ab.channel} channel`,children:[`v`,ab.version]})]})]})]}),(0,X.jsxs)(`button`,{"aria-controls":`mobile-sidebar-controls`,"aria-expanded":m,className:`mobile-filter-toggle`,onClick:()=>h(e=>!e),type:`button`,children:[(0,X.jsx)(G,{size:16}),`Filters`,(0,X.jsx)(S,{className:m?`open`:``,size:16})]}),(0,X.jsxs)(`div`,{className:`sidebar-mobile-collapse`,"data-open":m,id:`mobile-sidebar-controls`,children:[(0,X.jsxs)(`div`,{className:`side-section`,children:[(0,X.jsx)(`h2`,{children:`Project`}),(0,X.jsx)(_b,{id:`asset-project-filter`,label:`Project`,value:i,values:v,onChange:c})]}),(0,X.jsxs)(`section`,{className:`side-section`,children:[(0,X.jsx)(`h2`,{children:`Filters`}),(0,X.jsx)(_b,{id:`asset-source-filter`,label:`Source`,value:d,values:Y,onChange:e=>l(e)}),(0,X.jsx)(_b,{id:`asset-status-filter`,label:`Status`,value:f,values:J,onChange:e=>u(e)}),(0,X.jsx)(_b,{id:`asset-channel-filter`,label:`Channel`,value:t,values:n,onChange:o}),(0,X.jsx)(_b,{id:`asset-placement-filter`,label:`Placement`,value:r,values:he,onChange:e=>s(e)})]})]})]})}function _b({id:e,label:t,value:n,values:r,onChange:i}){return(0,X.jsxs)(`label`,{htmlFor:e,children:[t,(0,X.jsx)(`select`,{"aria-label":t,id:e,value:n,onChange:e=>i(e.target.value),children:r.map(e=>(0,X.jsx)(`option`,{value:e,children:e},e))})]})}var vb=[{label:`Lineage`,view:`lineage`},{label:`Review`,view:`review`},{label:`Assets`,view:`assets`},{label:`Agents`,view:`agents`},{label:`Settings`,view:`settings`}],yb=[{label:`Ledger`,view:`ledger`},{label:`Content batches`,view:`content`},{label:`Backup queue`,view:`backup`}];function bb(e){let t=yb.some(t=>t.view===e.view);function n(t){e.setView(t),e.onMoreOpenChange(!1)}function r(t){e.setView(t),e.onMoreOpenChange(!1)}return(0,X.jsxs)(`header`,{className:`topbar`,children:[(0,X.jsxs)(`div`,{className:`view-tabs`,role:`tablist`,"aria-label":`${mb} views`,children:[vb.map(t=>(0,X.jsx)(`button`,{"aria-pressed":e.view===t.view,className:e.view===t.view?`active`:``,onClick:()=>n(t.view),type:`button`,children:t.label},t.view)),(0,X.jsxs)(`div`,{className:`more-menu`,children:[(0,X.jsxs)(`button`,{"aria-expanded":e.moreOpen,"aria-haspopup":`menu`,"aria-pressed":t,className:t?`active`:``,onClick:()=>e.onMoreOpenChange(!e.moreOpen),type:`button`,children:[(0,X.jsx)(j,{size:16}),` More `,(0,X.jsx)(S,{className:e.moreOpen?`open`:``,size:15})]}),e.moreOpen&&(0,X.jsx)(`div`,{className:`more-menu-popover`,role:`menu`,children:yb.map(t=>(0,X.jsx)(`button`,{"aria-pressed":e.view===t.view,onClick:()=>r(t.view),role:`menuitem`,type:`button`,children:t.label},t.view))})]})]}),(0,X.jsx)(xb,{runtime:e.runtime,unavailable:e.runtimeIdentityUnavailable}),(0,X.jsxs)(`div`,{className:`searchbox`,children:[(0,X.jsx)(ae,{size:17}),(0,X.jsx)(`input`,{onChange:t=>e.setQuery(t.target.value),placeholder:`Search assets, campaigns, hooks`,value:e.query})]}),e.view!==`lineage`&&(0,X.jsxs)(`button`,{"aria-expanded":e.assetDetailsOpen,className:`secondary-button`,disabled:!e.canInspectAsset,onClick:()=>{e.onMoreOpenChange(!1),e.setAssetDetailsOpen(!e.assetDetailsOpen)},type:`button`,children:[(0,X.jsx)(I,{size:17}),`Details`]}),(0,X.jsx)(`button`,{className:`icon-button`,disabled:e.loading,onClick:()=>void e.refresh(),title:`Refresh current page`,children:e.loading?(0,X.jsx)(ee,{className:`spin`,size:18}):(0,X.jsx)(o,{size:18})}),(0,X.jsxs)(`button`,{className:`primary-button`,onClick:()=>e.setUploadOpen(!0),children:[(0,X.jsx)(ue,{size:17}),`Upload`]})]})}function xb(e){if(e.unavailable)return(0,X.jsx)(`div`,{"aria-label":`Lineage runtime identity unavailable`,className:`runtime-identity-badge unavailable`,children:`IDENTITY UNAVAILABLE`});if(!e.runtime)return(0,X.jsx)(`div`,{"aria-label":`Loading Lineage runtime identity`,className:`runtime-identity-badge loading`,children:`IDENTITY LOADING`});let{profile:t}=e.runtime,n=t.bound?``:` · UNBOUND`,r=[`${t.environment.toUpperCase()} profile ${t.id}${t.bound?``:` (unbound)`}`,`Channel ${e.runtime.channel}`,`Version ${e.runtime.version}`,t.warning].filter(Boolean).join(` · `);return(0,X.jsxs)(`div`,{"aria-label":`Lineage ${t.environment} profile ${t.id}${t.bound?``:` unbound`}`,className:`runtime-identity-badge ${t.environment} ${t.bound?`bound`:`unbound`}`,"data-profile-id":t.id,title:r,children:[(0,X.jsx)(`strong`,{children:t.environment.toUpperCase()}),(0,X.jsxs)(`span`,{children:[t.id,n]})]})}function Sb({toast:e,onDismiss:t}){return(0,X.jsxs)(`div`,{className:`toast ${e.type}`,role:`status`,children:[e.type===`ok`?(0,X.jsx)(w,{size:16}):(0,X.jsx)(se,{size:16}),(0,X.jsx)(`span`,{children:e.message}),(0,X.jsx)(`button`,{onClick:t,children:`Dismiss`})]})}var Cb=200*1024*1024;function wb({channels:e,project:t,onClose:n,onUploaded:r,onError:i}){let[a,o]=(0,p.useState)({assetId:``,audience:`short-form-creators`,campaign:`2026-06-organic-traffic-test`,channel:e[0]||`meta`,cta:``,hook:``,status:`working`,title:``,type:`image`,utmContent:``}),[s,c]=(0,p.useState)(null),[l,u]=(0,p.useState)(!1),[d,f]=(0,p.useState)(!1);function m(e,t){o(n=>({...n,[e]:t}))}function h(e){o(t=>({...t,assetId:t.assetId||pe(`demo-${t.channel}-${e}`),title:e,utmContent:t.utmContent||pe(e).replaceAll(`-`,`_`)}))}function _(e){if(!e){c(null);return}if(e.size>Cb){i(`File is larger than ${q(Cb)}`);return}c(e)}async function v(e){if(e.preventDefault(),!s)return i(`Choose a file before uploading`);f(!0);try{let e=new FormData;Object.entries({project:t,...a,confirmWrite:String(l)}).forEach(([t,n])=>e.append(t,n)),e.append(`file`,s),await r((await g(`/api/assets/upload`,{method:`POST`,body:e})).message)}catch(e){i(e instanceof Error?e.message:String(e))}finally{f(!1)}}return(0,X.jsx)(`div`,{className:`drawer-backdrop`,children:(0,X.jsxs)(`form`,{className:`upload-drawer`,onSubmit:v,children:[(0,X.jsxs)(`header`,{children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h2`,{children:`Upload asset`}),(0,X.jsx)(`p`,{children:t})]}),(0,X.jsx)(`button`,{type:`button`,onClick:n,children:`Close`})]}),(0,X.jsxs)(`label`,{className:`file-drop`,children:[(0,X.jsx)(ue,{size:20}),(0,X.jsx)(`span`,{children:s?s.name:`Choose creative export up to ${q(Cb)}`}),(0,X.jsx)(`input`,{type:`file`,onChange:e=>_(e.target.files?.[0])})]}),(0,X.jsxs)(`div`,{className:`form-grid`,children:[(0,X.jsxs)(`label`,{children:[`Title`,(0,X.jsx)(`input`,{value:a.title,onChange:e=>h(e.target.value),required:!0})]}),(0,X.jsxs)(`label`,{children:[`Asset ID`,(0,X.jsx)(`input`,{value:a.assetId,onChange:e=>m(`assetId`,e.target.value),required:!0})]}),(0,X.jsxs)(`label`,{children:[`Campaign`,(0,X.jsx)(`input`,{value:a.campaign,onChange:e=>m(`campaign`,e.target.value),required:!0})]}),(0,X.jsxs)(`label`,{children:[`Channel`,(0,X.jsx)(`select`,{value:a.channel,onChange:e=>m(`channel`,e.target.value),children:e.map(e=>(0,X.jsx)(`option`,{children:e},e))})]}),(0,X.jsxs)(`label`,{children:[`Audience`,(0,X.jsx)(`input`,{value:a.audience,onChange:e=>m(`audience`,e.target.value),required:!0})]}),(0,X.jsxs)(`label`,{children:[`Status`,(0,X.jsxs)(`select`,{value:a.status,onChange:e=>m(`status`,e.target.value),children:[(0,X.jsx)(`option`,{children:`working`}),(0,X.jsx)(`option`,{children:`published`})]})]}),(0,X.jsxs)(`label`,{children:[`Type`,(0,X.jsx)(`select`,{value:a.type,onChange:e=>m(`type`,e.target.value),children:ge.map(e=>(0,X.jsx)(`option`,{children:e},e))})]}),(0,X.jsxs)(`label`,{children:[`UTM content`,(0,X.jsx)(`input`,{value:a.utmContent,onChange:e=>m(`utmContent`,e.target.value),required:!0})]}),(0,X.jsxs)(`label`,{className:`wide`,children:[`Hook`,(0,X.jsx)(`input`,{value:a.hook,onChange:e=>m(`hook`,e.target.value)})]}),(0,X.jsxs)(`label`,{className:`wide`,children:[`CTA`,(0,X.jsx)(`input`,{value:a.cta,onChange:e=>m(`cta`,e.target.value),required:!0})]})]}),(0,X.jsxs)(`label`,{className:`confirm-line`,children:[(0,X.jsx)(`input`,{type:`checkbox`,checked:l,onChange:e=>u(e.target.checked)}),(0,X.jsx)(`span`,{children:`Confirm write to the production asset bucket`})]}),(0,X.jsxs)(`footer`,{children:[(0,X.jsx)(`button`,{type:`button`,onClick:n,children:`Cancel`}),(0,X.jsxs)(`button`,{className:`primary-button`,disabled:d||!l,children:[d?(0,X.jsx)(ee,{className:`spin`,size:16}):(0,X.jsx)(ue,{size:16}),`Upload`]})]})]})})}function Tb(e,t){let n=`${e} ${t}`.toLowerCase();return n.includes(`agent`)||n.includes(`command`)||n.includes(`selection`)||n.includes(`next context`)}function Eb(){return typeof window>`u`?me:new URLSearchParams(window.location.search).get(`project`)||`demo-project`}function Db(){let[e,t]=(0,p.useState)(null),[n,r]=(0,p.useState)(null),[i,a]=(0,p.useState)(Eb),[o,s]=(0,p.useState)([]),[c,l]=(0,p.useState)(`all`),[u,d]=(0,p.useState)(`all`),[f,m]=(0,p.useState)(`local`),[h,y]=(0,p.useState)(`all`),[b,x]=(0,p.useState)(``),[S,C]=(0,p.useState)(1),[w,T]=(0,p.useState)(10),[E,D]=(0,p.useState)(!1),[O,k]=(0,p.useState)(!0),[A,j]=(0,p.useState)(null),[M,N]=(0,p.useState)(null),[P,F]=(0,p.useState)({}),[I,L]=(0,p.useState)({}),[R,z]=(0,p.useState)([]),[B,V]=(0,p.useState)([]),[H,U]=(0,p.useState)(!1),[W,ee]=(0,p.useState)(!1),[te,ne]=(0,p.useState)(`lineage`),[re,ie]=(0,p.useState)(!1),[ae,oe]=(0,p.useState)(null),[se,G]=(0,p.useState)(0),[ce,le]=(0,p.useState)(null),[K,ue]=(0,p.useState)(!1),[de,q]=(0,p.useState)(null),fe=(0,p.useCallback)(e=>{q(t=>e?`lineage-actions`:t===`lineage-actions`?null:t)},[]),pe=(0,p.useCallback)(e=>{q(t=>e?`topbar-more`:t===`topbar-more`?null:t)},[]),me=(0,p.useCallback)((e,t)=>{j({type:e,message:t})},[]),J=e?.catalog.project===i?e:null,he=J?.assets||[],Y=xe(he,n)||(ae?.project===i&&ae.asset_id===n?ae:void 0),ge=Y?.asset_id||``,_e=[...B.filter(e=>R.includes(e.asset_id)),...he.filter(e=>R.includes(e.asset_id)&&e.local?.relative_path)].filter((e,t,n)=>n.findIndex(t=>t.asset_id===e.asset_id)===t),ve=Y&&P[Y.asset_id]||null,ye=(0,p.useMemo)(()=>[`all`,...J?.facets.channels||[]],[J]),be=(0,p.useMemo)(()=>({assets:J?.catalog.asset_count||0,live:J?.liveObjects.length||0,orphan:J?.orphanObjects.length||0,size:J?.facets.totalSizeBytes||0}),[J]);async function Ce(){try{let e=await g(`/api/projects`);s(e.projects),a(t=>e.projects.some(e=>e.project===t)?t:e.projects[0]?.project||`demo-project`)}catch(e){j({type:`error`,message:e instanceof Error?e.message:String(e)})}}async function we(){try{let e=await g(`/api/runtime`);le(e.runtime),ue(!1)}catch{le(null),ue(!0)}}async function Te(){k(!0);try{let e=await g(`/api/assets?${Ee()}`);t(e),r(t=>xe(e.assets,t)?.asset_id||(t&&ae?.asset_id===t?t:null)),F({}),L({})}catch(e){j({type:`error`,message:e instanceof Error?e.message:String(e)})}finally{k(!1)}}function Ee(){let e=new URLSearchParams({project:i,page:String(S),pageSize:String(w),live:String(E),source:f});return c!==`all`&&e.set(`status`,c),u!==`all`&&e.set(`placementStatus`,u),h!==`all`&&e.set(`channel`,h),b.trim()&&e.set(`q`,b.trim()),e.toString()}async function De(e){try{let t=await e();j({type:`ok`,message:t.message}),F({}),await Te()}catch(e){j({type:`error`,message:e instanceof Error?e.message:String(e)})}}async function Oe(e,t={}){if(!Se(e))return null;let n=P[e.asset_id];if(n)return t.open&&window.open(n,`_blank`,`noopener,noreferrer`),n;if(e.local?.relative_path){let n=`/api/assets/local-preview?${new URLSearchParams({project:i,path:e.local.relative_path}).toString()}`;return F(t=>({...t,[e.asset_id]:n})),L(t=>({...t,[e.asset_id]:``})),t.open&&window.open(n,`_blank`,`noopener,noreferrer`),n}try{let n=await g(`/api/assets/presign`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:i,assetId:e.asset_id,expiresIn:900})});return F(t=>({...t,[e.asset_id]:n.url})),L(t=>({...t,[e.asset_id]:``})),t.open&&window.open(n.url,`_blank`,`noopener,noreferrer`),n.url}catch(n){let r=n instanceof Error?n.message:String(n);return L(t=>({...t,[e.asset_id]:r})),t.quiet||j({type:`error`,message:`Preview unavailable. Check S3 credentials or pull the asset locally.`}),null}}async function ke(e,t){try{let n=await Bm(e);j({type:`ok`,message:n.method===`fallback`?`Copied ${t} using browser fallback`:`Copied ${t}`}),N(Tb(t,e)?{label:t,text:e}:null)}catch(n){N(Tb(t,e)?{label:t,text:e}:null),j({type:`error`,message:n instanceof Error?n.message:String(n)})}}async function je(e){let t=await Oe(e,{quiet:!0});t&&await ke(t,`preview link`)}function Ne(e){e.local?.relative_path&&(z(t=>t.includes(e.asset_id)?t:[...t,e.asset_id]),V(t=>t.some(t=>t.asset_id===e.asset_id)?t:[...t,e]))}function Z(e){oe(e),r(e.asset_id),ie(!0)}async function Pe(e){r(e),ie(!0);let t=he.find(t=>t.asset_id===e);if(t){oe(t);return}try{let t=await g(`/api/assets/lookup`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:i,assetIds:[e]})});t.assets[0]&&oe(t.assets[0])}catch(e){j({type:`error`,message:e instanceof Error?e.message:String(e)})}}function Fe(){m(`local`),l(`all`),d(`all`),x(``),ne(`backup`)}async function Ie(e){try{e.assetId&&r(e.assetId),e.view===`lineage`&&e.workspaceId&&await g(`/api/lineage-workspaces/${encodeURIComponent(e.workspaceId)}/activate`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:i,confirmWrite:!0})}),ie(!1),ne(e.view),j({type:`ok`,message:`Opened ${e.claim.target_title||e.claim.target_id}`})}catch(e){j({type:`error`,message:e instanceof Error?e.message:String(e)})}}function Le(e){e.local?.relative_path&&(z(t=>t.includes(e.asset_id)?t.filter(t=>t!==e.asset_id):[...t,e.asset_id]),V(t=>t.filter(t=>t.asset_id!==e.asset_id)))}return(0,p.useEffect)(()=>{Ce(),we()},[]),(0,p.useEffect)(()=>{let e=new URLSearchParams(window.location.search);e.get(`project`)!==i&&(e.set(`project`,i),window.history.replaceState(null,``,`${window.location.pathname}?${e.toString()}${window.location.hash}`))},[i]),(0,p.useEffect)(()=>{j(null),N(null),oe(null),ie(!1)},[i]),(0,p.useEffect)(()=>{Te()},[S,w,i,c,u,f,h,b,E]),(0,p.useEffect)(()=>{C(1)},[i,c,u,f,h,b,w]),(0,p.useEffect)(()=>{!Se(Y)||P[Y.asset_id]||Oe(Y,{quiet:!0})},[Y?.asset_id,Y?.s3?.version_id,P]),(0,p.useEffect)(()=>{if(A?.type!==`ok`)return;let e=window.setTimeout(()=>j(null),2600);return()=>window.clearTimeout(e)},[A?.message,A?.type]),(0,p.useEffect)(()=>{te===`backup`&&(m(`local`),l(`all`),d(`all`))},[te]),(0,p.useEffect)(()=>{q(null)},[te]),(0,p.useEffect)(()=>{ge||ie(!1)},[ge]),(0,X.jsx)(Me,{runtime:ce,children:(0,X.jsxs)(`div`,{className:`app-shell ${te===`lineage`?`lineage-mode`:``}`,children:[(0,X.jsx)(gb,{channel:h,channels:ye,liveSync:E,placementStatus:u,project:i,projects:o,setChannel:y,setPlacementStatus:d,setProject:a,setSource:m,setStatus:l,setView:ne,showBackupQueue:Fe,source:f,snapshot:J,status:c,totals:be}),(0,X.jsxs)(`main`,{className:`workspace`,children:[(0,X.jsx)(bb,{assetDetailsOpen:re,canInspectAsset:!!Y,loading:O,moreOpen:de===`topbar-more`,onMoreOpenChange:pe,query:b,refresh:Te,runtime:ce,runtimeIdentityUnavailable:K,setAssetDetailsOpen:ie,setQuery:x,setUploadOpen:ee,setView:e=>e===`backup`?Fe():ne(e),view:te}),A&&(0,X.jsx)(Sb,{toast:A,onDismiss:()=>j(null)}),M&&(0,X.jsx)(Ct,{copiedText:M,onDismiss:()=>N(null)}),(0,X.jsx)(Ot,{onCopy:ke,project:i,refreshKey:se,selectedAsset:Y,view:te}),te===`review`?(0,X.jsx)(Yy,{channel:h,onCopy:ke,onLocalReview:async(e,t)=>{await De(()=>_(`/api/local-review/${e.asset_id}`,i,{reviewState:t,confirmWrite:!0}))},onOpenBackup:e=>{Ne(e),U(!0)},onSelectAsset:e=>{Z(e)},project:i,selected:Y}):te===`ledger`?(0,X.jsx)(Vt,{project:i,query:b,onOpenAsset:Pe}):te===`content`?(0,X.jsx)(_t,{onCopy:ke,onOpenAsset:Pe,onToast:me,onWorkTargetsChanged:()=>G(e=>e+1),project:i,selectedAsset:Y}):te===`agents`?(0,X.jsx)(ze,{onCopy:ke,onOpenWork:Ie,project:i}):te===`backup`?(0,X.jsx)(zy,{assets:he,cli:ce?.cli,onCopy:ke,onLocalReview:async(e,t)=>{await De(()=>_(`/api/local-review/${e.asset_id}`,i,{reviewState:t,confirmWrite:!0}))},onOpenBackup:()=>U(!0),onQueueBackup:Ne,onSelectAsset:e=>{Z(e)},page:S,pageSize:w,project:i,selected:Y,selectedBackupIds:R,setPage:C,setPageSize:T,snapshot:J}):te===`assets`?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Gy,{assets:_e,onClear:()=>{z([]),V([])},onOpen:()=>U(!0)}),(0,X.jsx)(Re,{assets:he,liveSync:E,onCopy:ke,onSelectionChanged:()=>G(e=>e+1),page:S,pageSize:w,previewUrls:P,project:i,selected:Y,setLiveSync:D,setPage:C,setPageSize:T,setSelectedId:r,snapshot:J,source:f,totals:be})]}):te===`settings`?(0,X.jsx)(pb,{onToast:me,project:i}):(0,X.jsx)(jy,{asset:Y,actionsOpen:de===`lineage-actions`,onAssetsChanged:Te,onActionsOpenChange:fe,onSelectedAsset:r,onToast:me,project:i})]}),te!==`lineage`&&re&&(0,X.jsx)(Ae,{asset:Y,onArchive:e=>void De(()=>_(`/api/assets/archive`,i,{assetId:e.asset_id,confirmArchive:!0})),onClose:()=>ie(!1),onCopy:(e,t)=>void ke(e,t),onCopyPreview:e=>void je(e),onDelete:(e,t)=>void De(()=>_(`/api/assets/delete-object`,i,{assetId:e.asset_id,confirmation:t})),onPlacement:(e,t,n)=>void De(()=>_(`/api/assets/placement`,i,{assetId:e.asset_id,channel:e.channel,...v(n),status:t,confirmWrite:!0})),onPresign:e=>void Oe(e,{open:!0}),onPromote:e=>void De(()=>_(`/api/assets/promote`,i,{assetId:e.asset_id,confirmWrite:!0})),onPull:e=>void De(()=>_(`/api/assets/pull`,i,{assetId:e.asset_id,out:`.asset-scratch`})),onToggleBackup:Le,previewError:Y&&I[Y.asset_id]||null,previewUrl:ve,selectedForBackup:Y?R.includes(Y.asset_id):!1}),W&&(0,X.jsx)(wb,{channels:ye.filter(e=>e!==`all`),project:i,onClose:()=>ee(!1),onError:e=>j({type:`error`,message:e}),onUploaded:async e=>{j({type:`ok`,message:e}),ee(!1),await Te()}}),H&&(0,X.jsx)(Py,{assets:_e,project:i,onClose:()=>U(!1),onError:e=>j({type:`error`,message:e}),onDone:async e=>{j({type:`ok`,message:e}),z([]),V([]),U(!1),await Te()}})]})})}(0,m.createRoot)(document.getElementById(`root`)).render((0,X.jsx)(p.StrictMode,{children:(0,X.jsx)(Db,{})}));
|
|
16
|
+
`)}function vh(e){let t=Ne(),{activeNode:n,brief:r,childAssetId:i,clearNextVariation:a,closePanel:o,latestNodes:s,linkChild:c,markReview:l,noteDirty:u,onSelectedAsset:d,nextVariationLimit:f,onToast:p,project:m,refreshBrief:h,saveRationale:g,selectNextBase:_,selectedNode:v,selectedNodes:y,selectionFull:b,refreshLineage:x,replaceNextVariation:S,selectionNote:C,setActiveNodeId:w,setChildAssetId:T,setDetailNodeId:E,setSelected:D,setSelectionNote:O,sideOpen:k,snapshot:A}=e,j=n?ve({hasLocal:!!n.local_path,hasS3:!!n.s3_key}):null,M=y.filter(e=>!e.is_latest),N=A.nodes.filter(e=>e.reroll_request?.status===`pending`);return(0,X.jsxs)(`aside`,{"aria-hidden":!k,className:`lineage-side ${k?``:`collapsed`}`,id:`lineage-selection-panel`,children:[(0,X.jsxs)(`div`,{className:`lineage-side-head`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h3`,{children:`Next variation`}),(0,X.jsx)(`p`,{className:`muted-copy`,children:`Choose what the agent will evolve next; double-click nodes for full details.`})]}),(0,X.jsx)(`button`,{"aria-label":`Close lineage selection panel`,className:`icon-button`,onClick:o,type:`button`,children:`×`})]}),(0,X.jsxs)(`section`,{className:`lineage-next-panel`,children:[(0,X.jsxs)(`div`,{className:`lineage-panel-title-row`,children:[(0,X.jsx)(`h3`,{children:`Using for next variation`}),(0,X.jsxs)(`span`,{className:`lineage-count-pill ${b?`full`:``}`,children:[y.length,`/`,f]})]}),y.length>0&&(0,X.jsx)(`div`,{className:`lineage-panel-action-row`,children:(0,X.jsx)(`button`,{onClick:()=>void a(),type:`button`,children:`Clear all`})}),M.length>0&&(0,X.jsxs)(`div`,{className:`lineage-selection-warning`,role:`status`,children:[M.length,` selected asset`,M.length===1?` is`:`s are`,` not latest. This is valid for branching, but clear or replace it if you meant to continue from the newest leaves.`]}),y.length>0?y.map(e=>(0,X.jsxs)(`div`,{className:`lineage-candidate selected`,children:[(0,X.jsxs)(`button`,{"aria-label":`Inspect asset used for next variation ${e.title}`,className:`lineage-candidate-main`,onClick:()=>{w(e.asset_id),d(e.asset_id)},children:[(0,X.jsx)(`span`,{children:e.title}),(0,X.jsx)(`code`,{children:e.asset_id}),(0,X.jsx)(lh,{node:e})]}),!e.is_latest&&(0,X.jsx)(`span`,{className:`lineage-candidate-warning`,children:`Not latest`}),(0,X.jsxs)(`div`,{className:`lineage-candidate-actions`,children:[y.length>1&&(0,X.jsx)(`button`,{className:`lineage-candidate-action secondary`,onClick:()=>S(e),children:`Use only this`}),(0,X.jsx)(`button`,{className:`lineage-candidate-action remove`,onClick:()=>void a(e.asset_id),children:`Remove`})]})]},e.asset_id)):(0,X.jsxs)(`p`,{className:`muted-copy`,children:[`Choose up to `,f,` assets to guide the next generation.`]}),y.length>1&&(0,X.jsx)(`p`,{className:`muted-copy`,children:`The agent will use these as separate next-variation bases; imported outputs should link back to the matching selected parent.`})]}),(0,X.jsx)(yh,{activeNode:n,onSelectedAsset:d,onToast:p,project:m,refreshLineage:x,setActiveNodeId:w,snapshot:A}),(0,X.jsxs)(`section`,{className:`lineage-next-panel`,children:[(0,X.jsxs)(`div`,{className:`lineage-panel-title-row`,children:[(0,X.jsx)(`h3`,{children:`Re-roll queue`}),(0,X.jsx)(`span`,{className:`lineage-count-pill`,children:N.length})]}),N.length>0?N.map(e=>(0,X.jsx)(`div`,{className:`lineage-candidate ${e.asset_id===n?.asset_id?`active`:``}`,children:(0,X.jsxs)(`button`,{"aria-label":`Inspect re-roll target ${e.title}`,className:`lineage-candidate-main`,onClick:()=>{w(e.asset_id),d(e.asset_id)},children:[(0,X.jsx)(`span`,{children:e.title}),(0,X.jsx)(`code`,{children:e.asset_id}),e.reroll_request?.notes&&(0,X.jsx)(`small`,{children:e.reroll_request.notes})]})},e.asset_id)):(0,X.jsx)(`p`,{className:`muted-copy`,children:`No pending re-roll targets.`})]}),(0,X.jsxs)(`section`,{className:`lineage-next-panel`,children:[(0,X.jsx)(`h3`,{children:`Latest candidates`}),s.length>0?s.map(e=>{let t=!e.user_selected&&b;return(0,X.jsxs)(`div`,{className:`lineage-candidate ${e.asset_id===n?.asset_id?`active`:``} ${e.user_selected?`selected`:``}`,children:[(0,X.jsxs)(`button`,{"aria-label":`Inspect ${e.title}`,className:`lineage-candidate-main`,onClick:()=>{w(e.asset_id),d(e.asset_id)},children:[(0,X.jsx)(`span`,{children:e.title}),(0,X.jsx)(`code`,{children:e.asset_id}),(0,X.jsx)(lh,{node:e})]}),(0,X.jsxs)(`div`,{className:`lineage-candidate-actions`,children:[(0,X.jsx)(`button`,{"aria-label":e.user_selected?`Remove ${e.title} from next variation`:`Use ${e.title} for next variation`,className:`lineage-candidate-action ${e.user_selected?`remove`:``}`,disabled:t,onClick:()=>e.user_selected?void a(e.asset_id):_(e),children:e.user_selected?`Remove`:t?`Selection full`:`Use for next variation`}),!e.user_selected&&y.length>0&&(0,X.jsx)(`button`,{className:`lineage-candidate-action secondary`,onClick:()=>S(e),children:`Replace selection`})]})]},e.asset_id)}):(0,X.jsx)(`p`,{className:`muted-copy`,children:`No latest leaves yet.`})]}),(0,X.jsx)(uh,{brief:r,cli:t,nextBase:v,onRefreshBrief:()=>void h(),onToast:p,project:m,rerollTargets:N,rootAssetId:A.root_asset_id}),(0,X.jsx)(`h3`,{children:`Inspecting`}),n?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`strong`,{children:n.title}),(0,X.jsx)(`code`,{children:n.asset_id}),(0,X.jsxs)(`dl`,{children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Storage`}),(0,X.jsx)(`dd`,{children:j&&(0,X.jsx)(`span`,{className:`storage-chip ${j.kind}`,children:j.label})})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Source`}),(0,X.jsx)(`dd`,{children:n.source})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Review`}),(0,X.jsx)(`dd`,{children:n.review_state})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Latest`}),(0,X.jsx)(`dd`,{children:n.is_latest?`yes`:`no`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Next variation`}),(0,X.jsx)(`dd`,{children:n.user_selected?`yes`:`no`})]})]}),n.user_selected&&!n.is_latest&&(0,X.jsx)(`div`,{className:`lineage-selection-warning`,role:`status`,children:`This selected asset is not a latest leaf. Keep it selected to branch from an earlier idea, or replace it with the current inspected asset.`}),(0,X.jsxs)(`label`,{className:`lineage-note-field`,children:[`Variation rationale`,(0,X.jsx)(`textarea`,{value:C,onChange:e=>O(e.target.value),placeholder:`Why should the next generation branch from this asset?`}),(0,X.jsx)(`span`,{className:`lineage-note-status ${u?`dirty`:``}`,children:n.user_selected?u?`Unsaved rationale`:`Rationale saved for next variation`:`Rationale saves when this is used for next variation`})]}),(0,X.jsxs)(`div`,{className:`lineage-side-actions`,children:[(0,X.jsx)(`button`,{"aria-label":n.user_selected?`Remove ${n.title} from next variation`:`Use ${n.title} for next variation`,className:`primary-lite`,disabled:!n.user_selected&&b,onClick:()=>n.user_selected?void a(n.asset_id):D(),children:n.user_selected?`Remove from next variation`:b?`Selection full`:`Use for next variation`}),n.user_selected&&y.length>1&&(0,X.jsx)(`button`,{onClick:()=>S(n,C),children:`Use only this`}),!n.user_selected&&y.length>0&&(0,X.jsx)(`button`,{onClick:()=>S(n,C),children:`Replace selection`}),(0,X.jsx)(`button`,{disabled:!n.user_selected||!u,onClick:g,children:`Save rationale`}),(0,X.jsx)(`button`,{"aria-label":`Open detail for ${n.title}`,onClick:()=>E(n.asset_id),children:`Open detail`}),(0,X.jsx)(`button`,{"aria-label":`Approve ${n.title}`,onClick:()=>void l(`approved`),children:`Approve`}),(0,X.jsx)(`button`,{"aria-label":`Reject ${n.title}`,onClick:()=>void l(`rejected`),children:`Reject`}),(0,X.jsx)(`button`,{"aria-label":`Ignore ${n.title}`,onClick:()=>void l(`ignored`),children:`Ignore`})]}),(0,X.jsxs)(`form`,{className:`lineage-link-form`,onSubmit:e=>{e.preventDefault(),c()},children:[(0,X.jsxs)(`label`,{children:[`Child asset ID`,(0,X.jsx)(`input`,{value:i,onChange:e=>T(e.target.value),placeholder:`local-... or catalog id`})]}),(0,X.jsx)(`button`,{disabled:!i.trim(),type:`submit`,children:`Link child`})]})]}):(0,X.jsx)(`p`,{className:`muted-copy`,children:`No lineage node selected.`})]})}function yh({activeNode:e,onSelectedAsset:t,onToast:n,project:r,refreshLineage:i,setActiveNodeId:a,snapshot:o}){let s=(0,p.useMemo)(()=>Sh(o.tasks||[]),[o.tasks]),c=s.filter(e=>Ch(e)).length,l=(0,p.useMemo)(()=>new Map(o.nodes.map(e=>[e.asset_id,e])),[o.nodes]);return(0,X.jsxs)(`section`,{className:`lineage-next-panel lineage-task-queue-panel`,children:[(0,X.jsxs)(`div`,{className:`lineage-panel-title-row`,children:[(0,X.jsx)(`h3`,{children:`Task queue`}),(0,X.jsx)(`span`,{className:`lineage-count-pill`,children:c})]}),s.length>0?s.map(o=>(0,X.jsx)(bh,{active:o.target_asset_id===e?.asset_id,node:l.get(o.target_asset_id),onInspect:()=>{a(o.target_asset_id),t(o.target_asset_id)},onToast:n,project:r,refreshLineage:i,task:o},`${o.id}:${o.updated_at}`)):(0,X.jsx)(`p`,{className:`muted-copy`,children:`No open lineage tasks.`})]})}function bh({active:e,node:t,onInspect:n,onToast:r,project:i,refreshLineage:a,task:o}){let s=o.status===`claimed`||o.status===`in_progress`,c=o.status===`pending`,[l,u]=(0,p.useState)(o.instructions||``),[d,f]=(0,p.useState)(``),[m,h]=(0,p.useState)(!1);(0,p.useEffect)(()=>u(o.instructions||``),[o.id,o.instructions]);async function _(e,t,n){h(!0);try{return await g(e,{body:JSON.stringify({project:i,...t}),headers:{"Content-Type":`application/json`},method:`POST`}),r(`ok`,n),await a(),!0}catch(e){return r(`error`,e instanceof Error?e.message:String(e)),!1}finally{h(!1)}}async function v(e){e.preventDefault(),await _(`/api/lineage/tasks/${encodeURIComponent(o.id)}/instructions`,{instructions:l},`Updated ${Th(o)} instructions`)}async function y(e){e.preventDefault();let t=d.trim();t&&await _(`/api/lineage/tasks/${encodeURIComponent(o.id)}/comment`,{actor:`human`,message:t},`Commented on ${Th(o)}`)&&f(``)}async function b(){window.confirm(`Unlock ${Th(o)} for human edits?`)&&await _(`/api/lineage/tasks/${encodeURIComponent(o.id)}/override`,{actor:`human`,reason:`Human unlocked task from lineage UI.`},`Unlocked ${Th(o)}`)}async function x(){window.confirm(s?`Cancel ${Th(o)} while an agent is working?`:`Cancel ${Th(o)}?`)&&await _(`/api/lineage/tasks/${encodeURIComponent(o.id)}/cancel`,{actor:`human`,confirmWrite:!0,override:s},`Cancelled ${Th(o)}`)}return(0,X.jsxs)(`article`,{className:`lineage-task-card ${e?`active`:``} ${s?`locked`:o.status}`,children:[(0,X.jsxs)(`button`,{"aria-label":`Inspect task target ${t?.title||o.target_asset_id}`,className:`lineage-task-target`,onClick:n,type:`button`,children:[(0,X.jsx)(`span`,{children:t?.title||o.target_asset_id}),(0,X.jsx)(`code`,{children:o.target_asset_id})]}),(0,X.jsxs)(`div`,{className:`lineage-task-meta`,children:[(0,X.jsx)(`span`,{className:`lineage-task-status ${o.status}`,children:wh(o.status)}),(0,X.jsx)(`span`,{children:o.task_type})]}),c?(0,X.jsxs)(`form`,{className:`lineage-task-form`,onSubmit:v,children:[(0,X.jsxs)(`label`,{children:[`Instructions`,(0,X.jsx)(`textarea`,{"aria-label":`Instructions for ${o.id}`,value:l,onChange:e=>u(e.target.value)})]}),(0,X.jsxs)(`div`,{className:`lineage-task-actions`,children:[(0,X.jsx)(`button`,{disabled:m||l===(o.instructions||``),type:`submit`,children:`Save instructions`}),(0,X.jsx)(`button`,{disabled:m,onClick:x,type:`button`,children:`Cancel`})]})]}):(0,X.jsxs)(`div`,{className:`lineage-task-locked-body`,children:[(0,X.jsxs)(`label`,{children:[`Instructions`,(0,X.jsx)(`textarea`,{"aria-label":`Locked instructions for ${o.id}`,disabled:!0,readOnly:!0,value:l||`No instructions.`})]}),s&&(0,X.jsx)(xh,{claim:o.active_claim}),s&&(0,X.jsxs)(`form`,{className:`lineage-task-form`,onSubmit:y,children:[(0,X.jsxs)(`label`,{children:[`Comment`,(0,X.jsx)(`textarea`,{"aria-label":`Comment for ${o.id}`,value:d,onChange:e=>f(e.target.value)})]}),(0,X.jsxs)(`div`,{className:`lineage-task-actions`,children:[(0,X.jsx)(`button`,{disabled:m||!d.trim(),type:`submit`,children:`Add comment`}),(0,X.jsx)(`button`,{disabled:m,onClick:b,type:`button`,children:`Unlock`}),(0,X.jsx)(`button`,{disabled:m,onClick:x,type:`button`,children:`Cancel`})]})]})]})]})}function xh({claim:e}){return e?(0,X.jsxs)(`p`,{className:`lineage-task-claim ${e.derived_state===`active`?`active`:e.derived_state}`,children:[(0,X.jsxs)(`span`,{children:[wh(e.derived_state),` claim`]}),(0,X.jsx)(`strong`,{children:e.agent_name})]}):(0,X.jsx)(`p`,{className:`lineage-task-claim`,children:`Claimed by agent`})}function Sh(e){return[...e].sort((e,t)=>{let n=+!Ch(e),r=+!Ch(t);return n===r?e.created_at.localeCompare(t.created_at):n-r})}function Ch(e){return e.status===`pending`||e.status===`claimed`||e.status===`in_progress`}function wh(e){return e.replace(/_/g,` `)}function Th(e){return`${e.task_type} task`}function Eh(e,t){return e?.root_asset_id||t||``}function Dh(e){return`${e.title} (${e.root_asset_id})`}function Oh(e,t){let n=`${t.project}:lineage-workspace:${t.root_asset_id}`;return e.filter(e=>e.project!==t.project||e.status!==`active`||e.derived_state===`expired`?!1:e.scope_type===`lineage_workspace`?e.target_id===t.id||e.target_id===n:e.scope_type===`project_channel`)}function kh(e){return e.some(e=>e.derived_state===`stale`)?`stale`:e.some(e=>e.derived_state===`idle`)?`idle`:`active`}function Ah(e){let t=kh(e);return e.length===1?`${t===`active`?`Claimed`:t===`idle`?`Idle claim`:`Stale claim`} by ${e[0].agent_name}`:`${e.length} active claims`}function jh({activeWorkspace:e,closeSignal:t,loading:n,onNewLineage:r,onRefresh:i,onSelect:a,workspaces:o}){let[s,c]=(0,p.useState)(!1),[l,u]=(0,p.useState)([]),d=(0,p.useRef)(null),f=e?.project||o[0]?.project||``;(0,p.useEffect)(()=>{function e(e){d.current?.contains(e.target)||c(!1)}function t(e){e.key===`Escape`&&c(!1)}return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t,!0),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t,!0)}},[]),(0,p.useEffect)(()=>{c(!1)},[t]),(0,p.useEffect)(()=>{if(!f){u([]);return}let e=!1;return g(`/api/agent-claims?${new URLSearchParams({project:f})}`).then(t=>{e||u(t.claims)}).catch(()=>{e||u([])}),()=>{e=!0}},[f,t,o.length]);function m(e){c(!1),a(e)}let h=e?Oh(l,e):[];return(0,X.jsxs)(`section`,{"aria-label":`Lineage workspace picker`,className:`lineage-workspace-picker`,ref:d,children:[(0,X.jsxs)(`button`,{"aria-expanded":s,"aria-haspopup":`listbox`,className:`lineage-workspace-trigger`,disabled:n,onClick:()=>c(e=>!e),onKeyDown:e=>{e.key===`Escape`&&c(!1)},type:`button`,children:[(0,X.jsx)(`span`,{children:`Workspace`}),(0,X.jsx)(`strong`,{children:e?.title||`No workspace selected`}),(0,X.jsx)(`code`,{children:e?.root_asset_id||`Start with New lineage`}),(0,X.jsx)(Nh,{claims:h})]}),s&&(0,X.jsxs)(`div`,{className:`lineage-workspace-menu`,children:[(0,X.jsxs)(`div`,{className:`lineage-workspace-options`,role:`listbox`,children:[o.length===0&&(0,X.jsx)(`p`,{children:`No workspaces yet.`}),o.map(t=>(0,X.jsx)(Mh,{active:e?.id===t.id,claims:Oh(l,t),onSelect:()=>m(t.id),workspace:t},t.id))]}),(0,X.jsxs)(`footer`,{children:[(0,X.jsx)(`button`,{className:`secondary-button`,disabled:n,onClick:i,type:`button`,children:`Refresh`}),(0,X.jsx)(`button`,{className:`primary-button`,onClick:()=>{c(!1),r()},type:`button`,children:`New lineage`})]})]})]})}function Mh({active:e,claims:t,onSelect:n,workspace:r}){return(0,X.jsxs)(`button`,{"aria-selected":e,className:e?`active`:``,onClick:n,role:`option`,type:`button`,children:[(0,X.jsx)(`strong`,{children:r.title}),(0,X.jsx)(`code`,{children:r.root_asset_id}),(0,X.jsx)(`span`,{children:Dh(r)}),(0,X.jsx)(Nh,{claims:t})]})}function Nh({claims:e}){return e.length===0?null:(0,X.jsxs)(`small`,{className:`lineage-workspace-claim ${kh(e)}`,children:[(0,X.jsx)(se,{size:13}),(0,X.jsx)(`span`,{children:Ah(e)})]})}function Ph({activeWorkspace:e,actionsOpen:t,closeSignal:n,demoSeedStatus:r,edgeSummariesVisible:i,graphDirection:a,loading:o,onArchiveWorkspace:s,onActionsOpenChange:c,onDownloadSwissifierMedia:l,onEdgeSummariesVisible:u,onFitGraph:d,onGraphDirection:f,onIndexLocal:m,onNewLineage:h,onRefreshLineage:g,onRefreshWorkspaces:_,onReplayGrowth:v,onRestoreDemoMedia:y,onRestoreSwissifierMedia:b,onSeedDemo:x,onSeedSwissifierDemo:S,onSelectWorkspace:C,onTidyGraph:w,onToggleNextPanel:T,sideOpen:E,replayActive:D,snapshot:O,swissifierDemoStatus:k,workspaceLoading:A,workspaceProgress:j,workspaceRootAssetId:M,workspaces:N}){let P=r?`${r.present}/${r.total} SVG placeholders`:`Checking media`,F=k?`${k.present}/${k.total} PNG images`:`Checking media`,I=!!(k&&k.present===k.total),L=!!(k?.download_available&&!I),R=j===`downloading`?`Downloading rich demo media`:j===`downloaded`?`Rich demo media ready to seed`:j===`seeding`?`Creating rich demo workspace`:j===`indexing`?`Indexing 14 rich demo images`:j===`ready`?`Rich demo ready`:j===`error`?`Rich demo setup failed`:null,z=A||[`downloading`,`seeding`,`indexing`].includes(j||``),B=R||(O?`${O.nodes.length} nodes · ${O.edges.length} links`:M||`Choose a lineage workspace`);(0,p.useEffect)(()=>{c(!1)},[n,c]),(0,p.useEffect)(()=>{function e(e){e.key===`Escape`&&c(!1)}return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)},[c]);function V(e){c(!1),e()}function H(e){e.key===`Escape`&&(e.preventDefault(),c(!1))}return(0,X.jsxs)(`header`,{className:`lineage-header`,children:[(0,X.jsxs)(`div`,{className:`lineage-primary-controls`,children:[(0,X.jsx)(jh,{activeWorkspace:e,closeSignal:n,loading:z,onNewLineage:h,onRefresh:_,onSelect:C,workspaces:N}),(0,X.jsx)(`p`,{className:`lineage-toolbar-context`,children:B}),(0,X.jsx)(`button`,{"aria-pressed":D,className:`secondary-button lineage-replay-launch`,disabled:D||!O||O.nodes.length<2||O.edges.length===0,onClick:v,type:`button`,children:`Replay growth`}),(0,X.jsx)(`button`,{className:`primary-button`,onClick:h,type:`button`,children:`New lineage`})]}),(0,X.jsxs)(`details`,{className:`lineage-overflow`,onToggle:e=>c(e.currentTarget.open),open:t,children:[(0,X.jsx)(`summary`,{onKeyDown:H,tabIndex:0,children:`Actions`}),(0,X.jsxs)(`div`,{children:[!e&&(0,X.jsx)(`button`,{disabled:z,onClick:()=>V(x),type:`button`,children:`Load demo lineage`}),(0,X.jsxs)(`p`,{children:[(0,X.jsx)(`strong`,{children:`QA seed media`}),(0,X.jsx)(`span`,{children:F})]}),(0,X.jsxs)(`p`,{children:[(0,X.jsx)(`strong`,{children:`Basic SVG demo`}),(0,X.jsx)(`span`,{children:P})]}),(0,X.jsx)(`button`,{disabled:z||r?.present===r?.total,onClick:y,type:`button`,children:`Restore basic media`}),(0,X.jsx)(`button`,{disabled:z,onClick:()=>V(x),type:`button`,children:`Load SVG placeholder demo`}),(0,X.jsxs)(`p`,{children:[(0,X.jsx)(`strong`,{children:`Swissifier rich demo`}),(0,X.jsx)(`span`,{children:F})]}),(0,X.jsx)(`button`,{disabled:z||!L,onClick:l,type:`button`,children:`Download rich images`}),(0,X.jsx)(`button`,{disabled:z||I,onClick:b,type:`button`,children:`Restore rich media`}),(0,X.jsx)(`button`,{disabled:z,onClick:()=>V(S),type:`button`,children:`Load rich image demo`}),(0,X.jsxs)(`label`,{className:`lineage-action-select`,children:[(0,X.jsx)(`span`,{children:`Direction`}),(0,X.jsxs)(`select`,{"aria-label":`Lineage graph direction`,disabled:!O||o,onChange:e=>f(e.target.value),value:a,children:[(0,X.jsx)(`option`,{value:`LR`,children:`Left to right`}),(0,X.jsx)(`option`,{value:`TB`,children:`Top to bottom`}),(0,X.jsx)(`option`,{value:`RL`,children:`Right to left`}),(0,X.jsx)(`option`,{value:`BT`,children:`Bottom to top`})]})]}),(0,X.jsx)(`button`,{"aria-pressed":i,disabled:!O,onClick:()=>V(u),type:`button`,children:i?`Hide edge labels`:`Show edge labels`}),(0,X.jsx)(`button`,{disabled:!O,onClick:()=>V(d),type:`button`,children:`Fit graph`}),(0,X.jsx)(`button`,{disabled:!O,onClick:()=>V(w),type:`button`,children:`Tidy tree`}),(0,X.jsx)(`button`,{"aria-controls":`lineage-selection-panel`,"aria-expanded":E,disabled:!O,onClick:()=>V(T),type:`button`,children:`Manage selection`}),(0,X.jsx)(`button`,{disabled:z||!e,onClick:()=>V(s),type:`button`,children:`Archive current lineage`}),(0,X.jsx)(`button`,{disabled:o||z,onClick:()=>V(m),type:`button`,children:`Index local`}),(0,X.jsx)(`button`,{disabled:o||!O,onClick:()=>V(g),type:`button`,children:`Refresh graph`}),(0,X.jsx)(`button`,{disabled:z,onClick:()=>V(_),type:`button`,children:`Refresh workspaces`})]})]})]})}async function Fh(e,t,n){await g(`/api/lineage/layout`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({confirmWrite:!0,positions:n,project:e,rootAssetId:t})})}function Ih(e,t,n){return hd(e.filter(e=>e.type!==`remove`),t)}function Lh(e,t){return!e?.user_selected||t!==`rejected`&&t!==`ignored`?null:{confirmation:`${e.title} is being used for next variation. Marking it ${t} will remove it from next variation.`,clearsSelection:!0}}var Rh=Object.defineProperty,zh=(e,t,n)=>t in e?Rh(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Bh=(e,t)=>{for(var n in t)Rh(e,n,{get:t[n],enumerable:!0})},Vh=(e,t,n)=>zh(e,typeof t==`symbol`?t:t+``,n),Hh={};Bh(Hh,{Graph:()=>Gh,alg:()=>rg,json:()=>Qh,version:()=>Zh});var Uh=Object.defineProperty,Wh=(e,t)=>{for(var n in t)Uh(e,n,{get:t[n],enumerable:!0})},Gh=class{constructor(e){this._isDirected=!0,this._isMultigraph=!1,this._isCompound=!1,this._nodes={},this._in={},this._preds={},this._out={},this._sucs={},this._edgeObjs={},this._edgeLabels={},this._nodeCount=0,this._edgeCount=0,this._defaultNodeLabelFn=()=>{},this._defaultEdgeLabelFn=()=>{},e&&(this._isDirected=`directed`in e?e.directed:!0,this._isMultigraph=`multigraph`in e?e.multigraph:!1,this._isCompound=`compound`in e?e.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children[`\0`]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(e){return this._label=e,this}graph(){return this._label}setDefaultNodeLabel(e){return typeof e==`function`?this._defaultNodeLabelFn=e:this._defaultNodeLabelFn=()=>e,this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){return this.nodes().filter(e=>Object.keys(this._in[e]).length===0)}sinks(){return this.nodes().filter(e=>Object.keys(this._out[e]).length===0)}setNodes(e,t){return e.forEach(e=>{t===void 0?this.setNode(e):this.setNode(e,t)}),this}setNode(e,t){return e in this._nodes?(arguments.length>1&&(this._nodes[e]=t),this):(this._nodes[e]=arguments.length>1?t:this._defaultNodeLabelFn(e),this._isCompound&&(this._parent[e]=`\0`,this._children[e]={},this._children[`\0`][e]=!0),this._in[e]={},this._preds[e]={},this._out[e]={},this._sucs[e]={},++this._nodeCount,this)}node(e){return this._nodes[e]}hasNode(e){return e in this._nodes}removeNode(e){if(e in this._nodes){let t=e=>this.removeEdge(this._edgeObjs[e]);delete this._nodes[e],this._isCompound&&(this._removeFromParentsChildList(e),delete this._parent[e],this.children(e).forEach(e=>{this.setParent(e)}),delete this._children[e]),Object.keys(this._in[e]).forEach(t),delete this._in[e],delete this._preds[e],Object.keys(this._out[e]).forEach(t),delete this._out[e],delete this._sucs[e],--this._nodeCount}return this}setParent(e,t){if(!this._isCompound)throw Error(`Cannot set parent in a non-compound graph`);if(t===void 0)t=`\0`;else{t+=``;for(let n=t;n!==void 0;n=this.parent(n))if(n===e)throw Error(`Setting `+t+` as parent of `+e+` would create a cycle`);this.setNode(t)}return this.setNode(e),this._removeFromParentsChildList(e),this._parent[e]=t,this._children[t][e]=!0,this}parent(e){if(this._isCompound){let t=this._parent[e];if(t!==`\0`)return t}}children(e=`\0`){if(this._isCompound){let t=this._children[e];if(t)return Object.keys(t)}else{if(e===`\0`)return this.nodes();if(this.hasNode(e))return[]}return[]}predecessors(e){let t=this._preds[e];if(t)return Object.keys(t)}successors(e){let t=this._sucs[e];if(t)return Object.keys(t)}neighbors(e){let t=this.predecessors(e);if(t){let n=new Set(t);for(let t of this.successors(e))n.add(t);return Array.from(n.values())}}isLeaf(e){let t;return t=this.isDirected()?this.successors(e):this.neighbors(e),t.length===0}filterNodes(e){let t=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});t.setGraph(this.graph()),Object.entries(this._nodes).forEach(([n,r])=>{e(n)&&t.setNode(n,r)}),Object.values(this._edgeObjs).forEach(e=>{t.hasNode(e.v)&&t.hasNode(e.w)&&t.setEdge(e,this.edge(e))});let n={},r=e=>{let i=this.parent(e);return!i||t.hasNode(i)?(n[e]=i??void 0,i??void 0):i in n?n[i]:r(i)};return this._isCompound&&t.nodes().forEach(e=>t.setParent(e,r(e))),t}setDefaultEdgeLabel(e){return typeof e==`function`?this._defaultEdgeLabelFn=e:this._defaultEdgeLabelFn=()=>e,this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(e,t){return e.reduce((e,n)=>(t===void 0?this.setEdge(e,n):this.setEdge(e,n,t),n)),this}setEdge(e,t,n,r){let i,a,o,s,c=!1;typeof e==`object`&&e&&`v`in e?(i=e.v,a=e.w,o=e.name,arguments.length===2&&(s=t,c=!0)):(i=e,a=t,o=r,arguments.length>2&&(s=n,c=!0)),i=``+i,a=``+a,o!==void 0&&(o=``+o);let l=Jh(this._isDirected,i,a,o);if(l in this._edgeLabels)return c&&(this._edgeLabels[l]=s),this;if(o!==void 0&&!this._isMultigraph)throw Error(`Cannot set a named edge when isMultigraph = false`);this.setNode(i),this.setNode(a),this._edgeLabels[l]=c?s:this._defaultEdgeLabelFn(i,a,o);let u=Yh(this._isDirected,i,a,o);return i=u.v,a=u.w,Object.freeze(u),this._edgeObjs[l]=u,Kh(this._preds[a],i),Kh(this._sucs[i],a),this._in[a][l]=u,this._out[i][l]=u,this._edgeCount++,this}edge(e,t,n){let r=arguments.length===1?Xh(this._isDirected,e):Jh(this._isDirected,e,t,n);return this._edgeLabels[r]}edgeAsObj(e,t,n){let r=arguments.length===1?this.edge(e):this.edge(e,t,n);return typeof r==`object`?r:{label:r}}hasEdge(e,t,n){return(arguments.length===1?Xh(this._isDirected,e):Jh(this._isDirected,e,t,n))in this._edgeLabels}removeEdge(e,t,n){let r=arguments.length===1?Xh(this._isDirected,e):Jh(this._isDirected,e,t,n),i=this._edgeObjs[r];if(i){let e=i.v,t=i.w;delete this._edgeLabels[r],delete this._edgeObjs[r],qh(this._preds[t],e),qh(this._sucs[e],t),delete this._in[t][r],delete this._out[e][r],this._edgeCount--}return this}inEdges(e,t){return this.isDirected()?this.filterEdges(this._in[e],e,t):this.nodeEdges(e,t)}outEdges(e,t){return this.isDirected()?this.filterEdges(this._out[e],e,t):this.nodeEdges(e,t)}nodeEdges(e,t){if(e in this._nodes)return this.filterEdges({...this._in[e],...this._out[e]},e,t)}_removeFromParentsChildList(e){delete this._children[this._parent[e]][e]}filterEdges(e,t,n){if(!e)return;let r=Object.values(e);return n?r.filter(e=>e.v===t&&e.w===n||e.v===n&&e.w===t):r}};function Kh(e,t){e[t]?e[t]++:e[t]=1}function qh(e,t){e[t]!==void 0&&!--e[t]&&delete e[t]}function Jh(e,t,n,r){let i=``+t,a=``+n;if(!e&&i>a){let e=i;i=a,a=e}return i+``+a+``+(r===void 0?`\0`:r)}function Yh(e,t,n,r){let i=``+t,a=``+n;if(!e&&i>a){let e=i;i=a,a=e}let o={v:i,w:a};return r&&(o.name=r),o}function Xh(e,t){return Jh(e,t.v,t.w,t.name)}var Zh=`4.0.1`,Qh={};Wh(Qh,{read:()=>ng,write:()=>$h});function $h(e){let t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:eg(e),edges:tg(e)},n=e.graph();return n!==void 0&&(t.value=structuredClone(n)),t}function eg(e){return e.nodes().map(t=>{let n=e.node(t),r=e.parent(t),i={v:t};return n!==void 0&&(i.value=n),r!==void 0&&(i.parent=r),i})}function tg(e){return e.edges().map(t=>{let n=e.edge(t),r={v:t.v,w:t.w};return t.name!==void 0&&(r.name=t.name),n!==void 0&&(r.value=n),r})}function ng(e){let t=new Gh(e.options);return e.value!==void 0&&t.setGraph(e.value),e.nodes.forEach(e=>{t.setNode(e.v,e.value),e.parent&&t.setParent(e.v,e.parent)}),e.edges.forEach(e=>{t.setEdge({v:e.v,w:e.w,name:e.name},e.value)}),t}var rg={};Wh(rg,{CycleException:()=>vg,bellmanFord:()=>ag,components:()=>sg,dijkstra:()=>ug,dijkstraAll:()=>fg,findCycles:()=>mg,floydWarshall:()=>gg,isAcyclic:()=>bg,postorder:()=>wg,preorder:()=>Tg,prim:()=>Eg,shortestPaths:()=>Dg,tarjan:()=>pg,topsort:()=>yg});var ig=()=>1;function ag(e,t,n,r){return og(e,String(t),n||ig,r||function(t){return e.outEdges(t)})}function og(e,t,n,r){let i={},a,o=0,s=e.nodes(),c=function(e){let t=n(e);i[e.v].distance+t<i[e.w].distance&&(i[e.w]={distance:i[e.v].distance+t,predecessor:e.v},a=!0)},l=function(){s.forEach(function(e){r(e).forEach(function(t){let n=t.v===e?t.v:t.w,r=n===t.v?t.w:t.v;c({v:n,w:r})})})};s.forEach(function(e){i[e]={distance:e===t?0:1/0,predecessor:``}});let u=s.length;for(let e=1;e<u&&(a=!1,o++,l(),a);e++);if(o===u-1&&(a=!1,l(),a))throw Error(`The graph contains a negative weight cycle`);return i}function sg(e){let t={},n=[],r;function i(n){n in t||(t[n]=!0,r.push(n),e.successors(n).forEach(i),e.predecessors(n).forEach(i))}return e.nodes().forEach(function(e){r=[],i(e),r.length&&n.push(r)}),n}var cg=class{constructor(){this._arr=[],this._keyIndices={}}size(){return this._arr.length}keys(){return this._arr.map(e=>e.key)}has(e){return e in this._keyIndices}priority(e){let t=this._keyIndices[e];if(t!==void 0)return this._arr[t].priority}min(){if(this.size()===0)throw Error(`Queue underflow`);return this._arr[0].key}add(e,t){let n=this._keyIndices,r=String(e);if(!(r in n)){let e=this._arr,i=e.length;return n[r]=i,e.push({key:r,priority:t}),this._decrease(i),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);let e=this._arr.pop();return delete this._keyIndices[e.key],this._heapify(0),e.key}decrease(e,t){let n=this._keyIndices[e];if(n===void 0)throw Error(`Key not found: ${e}`);let r=this._arr[n].priority;if(t>r)throw Error(`New priority is greater than current priority. Key: ${e} Old: ${r} New: ${t}`);this._arr[n].priority=t,this._decrease(n)}_heapify(e){let t=this._arr,n=2*e,r=n+1,i=e;n<t.length&&(i=t[n].priority<t[i].priority?n:i,r<t.length&&(i=t[r].priority<t[i].priority?r:i),i!==e&&(this._swap(e,i),this._heapify(i)))}_decrease(e){let t=this._arr,n=t[e].priority,r;for(;e!==0&&(r=e>>1,!(t[r].priority<n));)this._swap(e,r),e=r}_swap(e,t){let n=this._arr,r=this._keyIndices,i=n[e],a=n[t];n[e]=a,n[t]=i,r[a.key]=e,r[i.key]=t}},lg=()=>1;function ug(e,t,n,r){return dg(e,String(t),n||lg,r||function(t){return e.outEdges(t)})}function dg(e,t,n,r){let i={},a=new cg,o,s,c=function(e){let t=e.v===o?e.w:e.v,r=i[t],c=n(e),l=s.distance+c;if(c<0)throw Error(`dijkstra does not allow negative edge weights. Bad edge: `+e+` Weight: `+c);l<r.distance&&(r.distance=l,r.predecessor=o,a.decrease(t,l))};for(e.nodes().forEach(function(e){let n=e===t?0:1/0;i[e]={distance:n,predecessor:``},a.add(e,n)});a.size()>0&&(o=a.removeMin(),s=i[o],s.distance!==1/0);)r(o).forEach(c);return i}function fg(e,t,n){return e.nodes().reduce(function(r,i){return r[i]=ug(e,i,t,n),r},{})}function pg(e){let t=0,n=[],r={},i=[];function a(o){let s=r[o]={onStack:!0,lowlink:t,index:t++};if(n.push(o),e.successors(o).forEach(function(e){e in r?r[e].onStack&&(s.lowlink=Math.min(s.lowlink,r[e].index)):(a(e),s.lowlink=Math.min(s.lowlink,r[e].lowlink))}),s.lowlink===s.index){let e=[],t;do t=n.pop(),r[t].onStack=!1,e.push(t);while(o!==t);i.push(e)}}return e.nodes().forEach(function(e){e in r||a(e)}),i}function mg(e){return pg(e).filter(function(t){return t.length>1||t.length===1&&e.hasEdge(t[0],t[0])})}var hg=()=>1;function gg(e,t,n){return _g(e,t||hg,n||function(t){return e.outEdges(t)})}function _g(e,t,n){let r={},i=e.nodes();return i.forEach(function(e){r[e]={},r[e][e]={distance:0,predecessor:``},i.forEach(function(t){e!==t&&(r[e][t]={distance:1/0,predecessor:``})}),n(e).forEach(function(n){let i=n.v===e?n.w:n.v,a=t(n);r[e][i]={distance:a,predecessor:e}})}),i.forEach(function(e){let t=r[e];i.forEach(function(n){let a=r[n];i.forEach(function(n){let r=a[e],i=t[n],o=a[n],s=r.distance+i.distance;s<o.distance&&(o.distance=s,o.predecessor=i.predecessor)})})}),r}var vg=class extends Error{constructor(...e){super(...e)}};function yg(e){let t={},n={},r=[];function i(a){if(a in n)throw new vg;a in t||(n[a]=!0,t[a]=!0,e.predecessors(a).forEach(i),delete n[a],r.push(a))}if(e.sinks().forEach(i),Object.keys(t).length!==e.nodeCount())throw new vg;return r}function bg(e){try{yg(e)}catch(e){if(e instanceof vg)return!1;throw e}return!0}function xg(e,t,n,r,i){Array.isArray(t)||(t=[t]);let a=(t=>(e.isDirected()?e.successors(t):e.neighbors(t))??[]),o={};return t.forEach(function(t){if(!e.hasNode(t))throw Error(`Graph does not have node: `+t);i=Sg(e,t,n===`post`,o,a,r,i)}),i}function Sg(e,t,n,r,i,a,o){return t in r||(r[t]=!0,n||(o=a(o,t)),i(t).forEach(function(t){o=Sg(e,t,n,r,i,a,o)}),n&&(o=a(o,t))),o}function Cg(e,t,n){return xg(e,t,n,function(e,t){return e.push(t),e},[])}function wg(e,t){return Cg(e,t,`post`)}function Tg(e,t){return Cg(e,t,`pre`)}function Eg(e,t){let n=new Gh,r={},i=new cg,a;function o(e){let n=e.v===a?e.w:e.v,o=i.priority(n);if(o!==void 0){let s=t(e);s<o&&(r[n]=a,i.decrease(n,s))}}if(e.nodeCount()===0)return n;e.nodes().forEach(function(e){i.add(e,1/0),n.setNode(e)}),i.decrease(e.nodes()[0],0);let s=!1;for(;i.size()>0;){if(a=i.removeMin(),a in r)n.setEdge(a,r[a]);else{if(s)throw Error(`Input graph is not connected: `+e);s=!0}e.nodeEdges(a).forEach(o)}return n}function Dg(e,t,n,r){return Og(e,t,n,r??(t=>e.outEdges(t)??[]))}function Og(e,t,n,r){if(n===void 0)return ug(e,t,n,r);let i=!1,a=e.nodes();for(let o=0;o<a.length;o++){let s=r(a[o]);for(let e=0;e<s.length;e++){let t=s[e],r=t.v===a[o]?t.v:t.w;n({v:r,w:r===t.v?t.w:t.v})<0&&(i=!0)}if(i)return ag(e,t,n,r)}return ug(e,t,n,r)}function kg(e,t,n,r){let i=r;for(;e.hasNode(i);)i=Gg(r);return n.dummy=t,e.setNode(i,n),i}function Ag(e){let t=new Gh().setGraph(e.graph());return e.nodes().forEach(n=>t.setNode(n,e.node(n))),e.edges().forEach(n=>{let r=t.edge(n.v,n.w)||{weight:0,minlen:1},i=e.edge(n);t.setEdge(n.v,n.w,{weight:r.weight+i.weight,minlen:Math.max(r.minlen,i.minlen)})}),t}function jg(e){let t=new Gh({multigraph:e.isMultigraph()}).setGraph(e.graph());return e.nodes().forEach(n=>{e.children(n).length||t.setNode(n,e.node(n))}),e.edges().forEach(n=>{t.setEdge(n,e.edge(n))}),t}function Mg(e,t){let n=e.x,r=e.y,i=t.x-n,a=t.y-r,o=e.width/2,s=e.height/2;if(!i&&!a)throw Error(`Not possible to find intersection inside of the rectangle`);let c,l;return Math.abs(a)*o>Math.abs(i)*s?(a<0&&(s=-s),c=s*i/a,l=s):(i<0&&(o=-o),c=o,l=o*a/i),{x:n+c,y:r+l}}function Ng(e){let t=Kg(Bg(e)+1).map(()=>[]);return e.nodes().forEach(n=>{let r=e.node(n),i=r.rank;i!==void 0&&(t[i]||(t[i]=[]),t[i][r.order]=n)}),t}function Pg(e){let t=e.nodes().map(t=>{let n=e.node(t).rank;return n===void 0?Number.MAX_VALUE:n}),n=zg(Math.min,t);e.nodes().forEach(t=>{let r=e.node(t);Object.hasOwn(r,`rank`)&&(r.rank-=n)})}function Fg(e){let t=e.nodes().map(t=>e.node(t).rank).filter(e=>e!==void 0),n=zg(Math.min,t),r=[];e.nodes().forEach(t=>{let i=e.node(t).rank-n;r[i]||(r[i]=[]),r[i].push(t)});let i=0,a=e.graph().nodeRankFactor;Array.from(r).forEach((t,n)=>{t===void 0&&n%a!==0?--i:t!==void 0&&i&&t.forEach(t=>e.node(t).rank+=i)})}function Ig(e,t,n,r){let i={width:0,height:0};return arguments.length>=4&&(i.rank=n,i.order=r),kg(e,`border`,i,t)}function Lg(e,t=Rg){let n=[];for(let r=0;r<e.length;r+=t){let i=e.slice(r,r+t);n.push(i)}return n}var Rg=65535;function zg(e,t){return t.length>Rg?e(...Lg(t).map(t=>e(...t))):e(...t)}function Bg(e){let t=e.nodes().map(t=>{let n=e.node(t).rank;return n===void 0?Number.MIN_VALUE:n});return zg(Math.max,t)}function Vg(e,t){let n={lhs:[],rhs:[]};return e.forEach(e=>{t(e)?n.lhs.push(e):n.rhs.push(e)}),n}function Hg(e,t){let n=Date.now();try{return t()}finally{console.log(e+` time: `+(Date.now()-n)+`ms`)}}function Ug(e,t){return t()}var Wg=0;function Gg(e){return e+(``+ ++Wg)}function Kg(e,t,n=1){t??(t=e,e=0);let r=e=>e<t;n<0&&(r=e=>t<e);let i=[];for(let t=e;r(t);t+=n)i.push(t);return i}function qg(e,t){let n={};for(let r of t)e[r]!==void 0&&(n[r]=e[r]);return n}function Jg(e,t){let n;return n=typeof t==`string`?e=>e[t]:t,Object.entries(e).reduce((e,[t,r])=>(e[t]=n(r,t),e),{})}function Yg(e,t){return e.reduce((e,n,r)=>(e[n]=t[r],e),{})}var Xg=`\0`,Zg=class{constructor(){Vh(this,`_sentinel`);let e={};e._next=e._prev=e,this._sentinel=e}dequeue(){let e=this._sentinel,t=e._prev;if(t!==e)return Qg(t),t}enqueue(e){let t=this._sentinel;e._prev&&e._next&&Qg(e),e._next=t._next,t._next._prev=e,t._next=e,e._prev=t}toString(){let e=[],t=this._sentinel,n=t._prev;for(;n!==t;)e.push(JSON.stringify(n,$g)),n=n._prev;return`[`+e.join(`, `)+`]`}};function Qg(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function $g(e,t){if(e!==`_next`&&e!==`_prev`)return t}var e_=Zg,t_=()=>1;function n_(e,t){if(e.nodeCount()<=1)return[];let n=a_(e,t||t_);return r_(n.graph,n.buckets,n.zeroIdx).flatMap(t=>e.outEdges(t.v,t.w)||[])}function r_(e,t,n){let r=[],i=t[t.length-1],a=t[0],o;for(;e.nodeCount();){for(;o=a.dequeue();)i_(e,t,n,o);for(;o=i.dequeue();)i_(e,t,n,o);if(e.nodeCount()){for(let i=t.length-2;i>0;--i)if(o=t[i]?.dequeue(),o){r=r.concat(i_(e,t,n,o,!0)||[]);break}}}return r}function i_(e,t,n,r,i){let a=[],o=i?a:void 0;return(e.inEdges(r.v)||[]).forEach(r=>{let o=e.edge(r),s=e.node(r.v);i&&a.push({v:r.v,w:r.w}),s.out-=o,o_(t,n,s)}),(e.outEdges(r.v)||[]).forEach(r=>{let i=e.edge(r),a=r.w,o=e.node(a);o.in-=i,o_(t,n,o)}),e.removeNode(r.v),o}function a_(e,t){let n=new Gh,r=0,i=0;e.nodes().forEach(e=>{n.setNode(e,{v:e,in:0,out:0})}),e.edges().forEach(e=>{let a=n.edge(e.v,e.w)||0,o=t(e),s=a+o;n.setEdge(e.v,e.w,s);let c=n.node(e.v),l=n.node(e.w);i=Math.max(i,c.out+=o),r=Math.max(r,l.in+=o)});let a=s_(i+r+3).map(()=>new e_),o=r+1;return n.nodes().forEach(e=>{o_(a,o,n.node(e))}),{graph:n,buckets:a,zeroIdx:o}}function o_(e,t,n){var r,i,a;n.out?n.in?(a=e[n.out-n.in+t])==null||a.enqueue(n):(i=e[e.length-1])==null||i.enqueue(n):(r=e[0])==null||r.enqueue(n)}function s_(e){let t=[];for(let n=0;n<e;n++)t.push(n);return t}function c_(e){(e.graph().acyclicer===`greedy`?n_(e,t(e)):l_(e)).forEach(t=>{let n=e.edge(t);e.removeEdge(t),n.forwardName=t.name,n.reversed=!0,e.setEdge(t.w,t.v,n,Gg(`rev`))});function t(e){return t=>e.edge(t).weight}}function l_(e){let t=[],n={},r={};function i(a){Object.hasOwn(r,a)||(r[a]=!0,n[a]=!0,e.outEdges(a).forEach(e=>{Object.hasOwn(n,e.w)?t.push(e):i(e.w)}),delete n[a])}return e.nodes().forEach(i),t}function u_(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.reversed){e.removeEdge(t);let r=n.forwardName;delete n.reversed,delete n.forwardName,e.setEdge(t.w,t.v,n,r)}})}function d_(e){e.graph().dummyChains=[],e.edges().forEach(t=>f_(e,t))}function f_(e,t){let n=t.v,r=e.node(n).rank,i=t.w,a=e.node(i).rank,o=t.name,s=e.edge(t),c=s.labelRank;if(a===r+1)return;e.removeEdge(t);let l,u,d;for(d=0,++r;r<a;++d,++r)s.points=[],u={width:0,height:0,edgeLabel:s,edgeObj:t,rank:r},l=kg(e,`edge`,u,`_d`),r===c&&(u.width=s.width,u.height=s.height,u.dummy=`edge-label`,u.labelpos=s.labelpos),e.setEdge(n,l,{weight:s.weight},o),d===0&&e.graph().dummyChains.push(l),n=l;e.setEdge(n,i,{weight:s.weight},o)}function p_(e){e.graph().dummyChains.forEach(t=>{let n=e.node(t),r=n.edgeLabel,i;for(e.setEdge(n.edgeObj,r);n.dummy;)i=e.successors(t)[0],e.removeNode(t),r.points.push({x:n.x,y:n.y}),n.dummy===`edge-label`&&(r.x=n.x,r.y=n.y,r.width=n.width,r.height=n.height),t=i,n=e.node(t)})}function m_(e){let t={};function n(r){let i=e.node(r);if(Object.hasOwn(t,r))return i.rank;t[r]=!0;let a=e.outEdges(r),o=a?a.map(t=>t==null?1/0:n(t.w)-e.edge(t).minlen):[],s=zg(Math.min,o);return s===1/0&&(s=0),i.rank=s}e.sources().forEach(n)}function h_(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}var g_=__;function __(e){let t=new Gh({directed:!1}),n=e.nodes();if(n.length===0)throw Error(`Graph must have at least one node`);let r=n[0],i=e.nodeCount();t.setNode(r,{});let a,o;for(;v_(t,e)<i&&(a=y_(t,e),a);)o=t.hasNode(a.v)?h_(e,a):-h_(e,a),b_(t,e,o);return t}function v_(e,t){function n(r){let i=t.nodeEdges(r);i&&i.forEach(i=>{let a=i.v,o=r===a?i.w:a;!e.hasNode(o)&&!h_(t,i)&&(e.setNode(o,{}),e.setEdge(r,o,{}),n(o))})}return e.nodes().forEach(n),e.nodeCount()}function y_(e,t){return t.edges().reduce((n,r)=>{let i=1/0;return e.hasNode(r.v)!==e.hasNode(r.w)&&(i=h_(t,r)),i<n[0]?[i,r]:n},[1/0,null])[1]}function b_(e,t,n){e.nodes().forEach(e=>t.node(e).rank+=n)}var{preorder:x_,postorder:S_}=rg,C_=w_;w_.initLowLimValues=O_,w_.initCutValues=T_,w_.calcCutValue=D_,w_.leaveEdge=A_,w_.enterEdge=j_,w_.exchangeEdges=M_;function w_(e){e=Ag(e),m_(e);let t=g_(e);O_(t),T_(t,e);let n,r;for(;n=A_(t);)r=j_(t,e,n),M_(t,e,n,r)}function T_(e,t){let n=S_(e,e.nodes());n=n.slice(0,n.length-1),n.forEach(n=>E_(e,t,n))}function E_(e,t,n){let r=e.node(n).parent,i=e.edge(n,r);i.cutvalue=D_(e,t,n)}function D_(e,t,n){let r=e.node(n).parent,i=!0,a=t.edge(n,r),o=0;a||=(i=!1,t.edge(r,n)),o=a.weight;let s=t.nodeEdges(n);return s&&s.forEach(a=>{let s=a.v===n,c=s?a.w:a.v;if(c!==r){let r=s===i,l=t.edge(a).weight;if(o+=r?l:-l,P_(e,n,c)){let t=e.edge(n,c).cutvalue;o+=r?-t:t}}}),o}function O_(e,t){arguments.length<2&&(t=e.nodes()[0]),k_(e,{},1,t)}function k_(e,t,n,r,i){let a=n,o=e.node(r);t[r]=!0;let s=e.neighbors(r);return s&&s.forEach(i=>{Object.hasOwn(t,i)||(n=k_(e,t,n,i,r))}),o.low=a,o.lim=n++,i?o.parent=i:delete o.parent,n}function A_(e){return e.edges().find(t=>e.edge(t).cutvalue<0)}function j_(e,t,n){let r=n.v,i=n.w;t.hasEdge(r,i)||(r=n.w,i=n.v);let a=e.node(r),o=e.node(i),s=a,c=!1;return a.lim>o.lim&&(s=o,c=!0),t.edges().filter(t=>c===F_(e,e.node(t.v),s)&&c!==F_(e,e.node(t.w),s)).reduce((e,n)=>h_(t,n)<h_(t,e)?n:e)}function M_(e,t,n,r){let i=n.v,a=n.w;e.removeEdge(i,a),e.setEdge(r.v,r.w,{}),O_(e),T_(e,t),N_(e,t)}function N_(e,t){let n=e.nodes().find(t=>!e.node(t).parent);if(!n)return;let r=x_(e,[n]);r=r.slice(1),r.forEach(n=>{let r=e.node(n).parent,i=t.edge(n,r),a=!1;i||(i=t.edge(r,n),a=!0),t.node(n).rank=t.node(r).rank+(a?i.minlen:-i.minlen)})}function P_(e,t,n){return e.hasEdge(t,n)}function F_(e,t,n){return n.low<=t.lim&&t.lim<=n.lim}var I_=L_;function L_(e){let t=e.graph().ranker;if(typeof t==`function`)return t(e);switch(t){case`network-simplex`:B_(e);break;case`tight-tree`:z_(e);break;case`longest-path`:R_(e);break;case`none`:break;default:B_(e)}}var R_=m_;function z_(e){m_(e),g_(e)}function B_(e){C_(e)}var V_=H_;function H_(e){let t=W_(e);e.graph().dummyChains.forEach(n=>{let r=e.node(n),i=r.edgeObj,a=U_(e,t,i.v,i.w),o=a.path,s=a.lca,c=0,l=o[c],u=!0;for(;n!==i.w;){if(r=e.node(n),u){for(;(l=o[c])!==s&&e.node(l).maxRank<r.rank;)c++;l===s&&(u=!1)}if(!u){for(;c<o.length-1&&e.node(o[c+1]).minRank<=r.rank;)c++;l=o[c]}l!==void 0&&e.setParent(n,l),n=e.successors(n)[0]}})}function U_(e,t,n,r){let i=[],a=[],o=Math.min(t[n].low,t[r].low),s=Math.max(t[n].lim,t[r].lim),c;c=n;do c=e.parent(c),i.push(c);while(c&&(t[c].low>o||s>t[c].lim));let l=c,u=r;for(;(u=e.parent(u))!==l;)a.push(u);return{path:i.concat(a.reverse()),lca:l}}function W_(e){let t={},n=0;function r(i){let a=n;e.children(i).forEach(r),t[i]={low:a,lim:n++}}return e.children(Xg).forEach(r),t}function G_(e){let t=kg(e,`root`,{},`_root`),n=q_(e),r=Object.values(n),i=zg(Math.max,r)-1,a=2*i+1;e.graph().nestingRoot=t,e.edges().forEach(t=>e.edge(t).minlen*=a);let o=J_(e)+1;e.children(Xg).forEach(r=>K_(e,t,a,o,i,n,r)),e.graph().nodeRankFactor=a}function K_(e,t,n,r,i,a,o){let s=e.children(o);if(!s.length){o!==t&&e.setEdge(t,o,{weight:0,minlen:n});return}let c=Ig(e,`_bt`),l=Ig(e,`_bb`),u=e.node(o);e.setParent(c,o),u.borderTop=c,e.setParent(l,o),u.borderBottom=l,s.forEach(s=>{K_(e,t,n,r,i,a,s);let u=e.node(s),d=u.borderTop?u.borderTop:s,f=u.borderBottom?u.borderBottom:s,p=u.borderTop?r:2*r,m=d===f?i-(a[o]??0)+1:1;e.setEdge(c,d,{weight:p,minlen:m,nestingEdge:!0}),e.setEdge(f,l,{weight:p,minlen:m,nestingEdge:!0})}),e.parent(o)||e.setEdge(t,c,{weight:0,minlen:i+(a[o]??0)})}function q_(e){let t={};function n(r,i){let a=e.children(r);a&&a.length&&a.forEach(e=>n(e,i+1)),t[r]=i}return e.children(Xg).forEach(e=>n(e,1)),t}function J_(e){return e.edges().reduce((t,n)=>t+e.edge(n).weight,0)}function Y_(e){let t=e.graph();e.removeNode(t.nestingRoot),delete t.nestingRoot,e.edges().forEach(t=>{e.edge(t).nestingEdge&&e.removeEdge(t)})}var X_=Z_;function Z_(e){function t(n){let r=e.children(n),i=e.node(n);if(r.length&&r.forEach(t),Object.hasOwn(i,`minRank`)){i.borderLeft=[],i.borderRight=[];for(let t=i.minRank,r=i.maxRank+1;t<r;++t)Q_(e,`borderLeft`,`_bl`,n,i,t),Q_(e,`borderRight`,`_br`,n,i,t)}}e.children(Xg).forEach(t)}function Q_(e,t,n,r,i,a){let o={width:0,height:0,rank:a,borderType:t},s=i[t][a-1],c=kg(e,`border`,o,n);i[t][a]=c,e.setParent(c,r),s&&e.setEdge(s,c,{weight:1})}function $_(e){let t=e.graph().rankdir?.toLowerCase();(t===`lr`||t===`rl`)&&tv(e)}function ev(e){let t=e.graph().rankdir?.toLowerCase();(t===`bt`||t===`rl`)&&rv(e),(t===`lr`||t===`rl`)&&(av(e),tv(e))}function tv(e){e.nodes().forEach(t=>nv(e.node(t))),e.edges().forEach(t=>nv(e.edge(t)))}function nv(e){let t=e.width;e.width=e.height,e.height=t}function rv(e){e.nodes().forEach(t=>iv(e.node(t))),e.edges().forEach(t=>{var n;let r=e.edge(t);(n=r.points)==null||n.forEach(iv),Object.hasOwn(r,`y`)&&iv(r)})}function iv(e){e.y=-e.y}function av(e){e.nodes().forEach(t=>ov(e.node(t))),e.edges().forEach(t=>{var n;let r=e.edge(t);(n=r.points)==null||n.forEach(ov),Object.hasOwn(r,`x`)&&ov(r)})}function ov(e){let t=e.x;e.x=e.y,e.y=t}function sv(e){let t={},n=e.nodes().filter(t=>!e.children(t).length),r=n.map(t=>e.node(t).rank),i=Kg(zg(Math.max,r)+1).map(()=>[]);function a(n){if(t[n])return;t[n]=!0;let r=e.node(n);i[r.rank].push(n);let o=e.successors(n);o&&o.forEach(a)}return n.sort((t,n)=>e.node(t).rank-e.node(n).rank).forEach(a),i}function cv(e,t){let n=0;for(let r=1;r<t.length;++r)n+=lv(e,t[r-1],t[r]);return n}function lv(e,t,n){let r=Yg(n,n.map((e,t)=>t)),i=t.flatMap(t=>{let n=e.outEdges(t);return n?n.map(t=>({pos:r[t.w],weight:e.edge(t).weight})).sort((e,t)=>e.pos-t.pos):[]}),a=1;for(;a<n.length;)a<<=1;let o=2*a-1;--a;let s=Array(o).fill(0),c=0;return i.forEach(e=>{let t=e.pos+a;s[t]+=e.weight;let n=0;for(;t>0;)t%2&&(n+=s[t+1]),t=t-1>>1,s[t]+=e.weight;c+=e.weight*n}),c}function uv(e,t=[]){return t.map(t=>{let n=e.inEdges(t);if(!n||!n.length)return{v:t};{let r=n.reduce((t,n)=>{let r=e.edge(n),i=e.node(n.v);return{sum:t.sum+r.weight*i.order,weight:t.weight+r.weight}},{sum:0,weight:0});return{v:t,barycenter:r.sum/r.weight,weight:r.weight}}})}function dv(e,t){let n={};return e.forEach((e,t)=>{let r={indegree:0,in:[],out:[],vs:[e.v],i:t};e.barycenter!==void 0&&(r.barycenter=e.barycenter,r.weight=e.weight),n[e.v]=r}),t.edges().forEach(e=>{let t=n[e.v],r=n[e.w];t!==void 0&&r!==void 0&&(r.indegree++,t.out.push(r))}),fv(Object.values(n).filter(e=>!e.indegree))}function fv(e){let t=[];function n(e){return t=>{t.merged||(t.barycenter===void 0||e.barycenter===void 0||t.barycenter>=e.barycenter)&&pv(e,t)}}function r(t){return n=>{n.in.push(t),--n.indegree===0&&e.push(n)}}for(;e.length;){let i=e.pop();t.push(i),i.in.reverse().forEach(n(i)),i.out.forEach(r(i))}return t.filter(e=>!e.merged).map(e=>qg(e,[`vs`,`i`,`barycenter`,`weight`]))}function pv(e,t){let n=0,r=0;e.weight&&(n+=e.barycenter*e.weight,r+=e.weight),t.weight&&(n+=t.barycenter*t.weight,r+=t.weight),e.vs=t.vs.concat(e.vs),e.barycenter=n/r,e.weight=r,e.i=Math.min(t.i,e.i),t.merged=!0}function mv(e,t){let n=Vg(e,e=>Object.hasOwn(e,`barycenter`)),r=n.lhs,i=n.rhs.sort((e,t)=>t.i-e.i),a=[],o=0,s=0,c=0;r.sort(gv(!!t)),c=hv(a,i,c),r.forEach(e=>{c+=e.vs.length,a.push(e.vs),o+=e.barycenter*e.weight,s+=e.weight,c=hv(a,i,c)});let l={vs:a.flat(1)};return s&&(l.barycenter=o/s,l.weight=s),l}function hv(e,t,n){let r;for(;t.length&&(r=t[t.length-1]).i<=n;)t.pop(),e.push(r.vs),n++;return n}function gv(e){return(t,n)=>t.barycenter<n.barycenter?-1:t.barycenter>n.barycenter?1:e?n.i-t.i:t.i-n.i}function _v(e,t,n,r){let i=e.children(t),a=e.node(t),o=a?a.borderLeft:void 0,s=a?a.borderRight:void 0,c={};o&&(i=i.filter(e=>e!==o&&e!==s));let l=uv(e,i);l.forEach(t=>{if(e.children(t.v).length){let i=_v(e,t.v,n,r);c[t.v]=i,Object.hasOwn(i,`barycenter`)&&yv(t,i)}});let u=dv(l,n);vv(u,c);let d=mv(u,r);if(o&&s){d.vs=[o,d.vs,s].flat(1);let t=e.predecessors(o);if(t&&t.length){let n=e.node(t[0]),r=e.predecessors(s),i=e.node(r[0]);Object.hasOwn(d,`barycenter`)||(d.barycenter=0,d.weight=0),d.barycenter=(d.barycenter*d.weight+n.order+i.order)/(d.weight+2),d.weight+=2}}return d}function vv(e,t){e.forEach(e=>{e.vs=e.vs.flatMap(e=>t[e]?t[e].vs:e)})}function yv(e,t){e.barycenter===void 0?(e.barycenter=t.barycenter,e.weight=t.weight):(e.barycenter=(e.barycenter*e.weight+t.barycenter*t.weight)/(e.weight+t.weight),e.weight+=t.weight)}function bv(e,t,n,r){r||=e.nodes();let i=xv(e),a=new Gh({compound:!0}).setGraph({root:i}).setDefaultNodeLabel(t=>e.node(t));return r.forEach(r=>{let o=e.node(r),s=e.parent(r);if(o.rank===t||o.minRank<=t&&t<=o.maxRank){a.setNode(r),a.setParent(r,s||i);let c=e[n](r);c&&c.forEach(t=>{let n=t.v===r?t.w:t.v,i=a.edge(n,r),o=i===void 0?0:i.weight;a.setEdge(n,r,{weight:e.edge(t).weight+o})}),Object.hasOwn(o,`minRank`)&&a.setNode(r,{borderLeft:o.borderLeft[t],borderRight:o.borderRight[t]})}}),a}function xv(e){let t;for(;e.hasNode(t=Gg(`_root`)););return t}function Sv(e,t,n){let r={},i;n.forEach(n=>{let a=e.parent(n),o,s;for(;a;){if(o=e.parent(a),o?(s=r[o],r[o]=a):(s=i,i=a),s&&s!==a){t.setEdge(s,a);return}a=o}})}function Cv(e,t={}){if(typeof t.customOrder==`function`){t.customOrder(e,Cv);return}let n=Bg(e),r=wv(e,Kg(1,n+1),`inEdges`),i=wv(e,Kg(n-1,-1,-1),`outEdges`),a=sv(e);if(Ev(e,a),t.disableOptimalOrderHeuristic)return;let o=1/0,s,c=t.constraints||[];for(let t=0,n=0;n<4;++t,++n){Tv(t%2?r:i,t%4>=2,c),a=Ng(e);let l=cv(e,a);l<o?(n=0,s=Object.assign({},a),o=l):l===o&&(s=structuredClone(a))}Ev(e,s)}function wv(e,t,n){let r=new Map,i=(e,t)=>{r.has(e)||r.set(e,[]),r.get(e).push(t)};for(let t of e.nodes()){let n=e.node(t);if(typeof n.rank==`number`&&i(n.rank,t),typeof n.minRank==`number`&&typeof n.maxRank==`number`)for(let e=n.minRank;e<=n.maxRank;e++)e!==n.rank&&i(e,t)}return t.map(function(t){return bv(e,t,n,r.get(t)||[])})}function Tv(e,t,n){let r=new Gh;e.forEach(function(e){n.forEach(e=>r.setEdge(e.left,e.right));let i=e.graph().root,a=_v(e,i,r,t);a.vs.forEach((t,n)=>e.node(t).order=n),Sv(e,r,a.vs)})}function Ev(e,t){Object.values(t).forEach(t=>t.forEach((t,n)=>e.node(t).order=n))}function Dv(e,t){let n={};function r(t,r){let i=0,a=0,o=t.length,s=r[r.length-1];return r.forEach((t,c)=>{let l=kv(e,t),u=l?e.node(l).order:o;(l||t===s)&&(r.slice(a,c+1).forEach(t=>{let r=e.predecessors(t);r&&r.forEach(r=>{let a=e.node(r),o=a.order;(o<i||u<o)&&!(a.dummy&&e.node(t).dummy)&&Av(n,r,t)})}),a=c+1,i=u)}),r}return t.length&&t.reduce(r),n}function Ov(e,t){let n={};function r(t,r,i,a,o){Kg(r,i).forEach(r=>{let i=t[r];if(i!==void 0&&e.node(i).dummy){let t=e.predecessors(i);t&&t.forEach(t=>{if(t===void 0)return;let r=e.node(t);r.dummy&&(r.order<a||r.order>o)&&Av(n,t,i)})}})}function i(t,n){let i=-1,a=-1,o=0;return n.forEach((s,c)=>{if(e.node(s).dummy===`border`){let t=e.predecessors(s);if(t&&t.length){let s=t[0];if(s===void 0)return;a=e.node(s).order,r(n,o,c,i,a),o=c,i=a}}r(n,o,n.length,a,t.length)}),n}return t.length&&t.reduce(i),n}function kv(e,t){if(e.node(t).dummy){let n=e.predecessors(t);if(n)return n.find(t=>e.node(t).dummy)}}function Av(e,t,n){if(t>n){let e=t;t=n,n=e}let r=e[t];r||(e[t]=r={}),r[n]=!0}function jv(e,t,n){if(t>n){let e=t;t=n,n=e}let r=e[t];return r!==void 0&&Object.hasOwn(r,n)}function Mv(e,t,n,r){let i={},a={},o={};return t.forEach(e=>{e.forEach((e,t)=>{i[e]=e,a[e]=e,o[e]=t})}),t.forEach(e=>{let t=-1;e.forEach(e=>{let s=r(e);if(s&&s.length){let r=s.sort((e,t)=>{let n=o[e],r=o[t];return(n===void 0?0:n)-(r===void 0?0:r)}),c=(r.length-1)/2;for(let s=Math.floor(c),l=Math.ceil(c);s<=l;++s){let c=r[s];if(c===void 0)continue;let l=o[c];if(l!==void 0&&a[e]===e&&t<l&&!jv(n,e,c)){let n=i[c];n!==void 0&&(a[c]=e,a[e]=i[e]=n,t=l)}}}})}),{root:i,align:a}}function Nv(e,t,n,r,i=!1){let a={},o=Pv(e,t,n,i),s=i?`borderLeft`:`borderRight`;function c(e,t){let n=o.nodes().slice(),r={},i=n.pop();for(;i;){if(r[i])e(i);else{r[i]=!0,n.push(i);for(let e of t(i))n.push(e)}i=n.pop()}}function l(e){let t=o.inEdges(e);t?a[e]=t.reduce((e,t)=>{let n=a[t.v]??0,r=o.edge(t);return Math.max(e,n+(r===void 0?0:r))},0):a[e]=0}function u(t){let n=o.outEdges(t),r=1/0;n&&(r=n.reduce((e,t)=>{let n=a[t.w],r=o.edge(t);return Math.min(e,(n===void 0?0:n)-(r===void 0?0:r))},1/0));let i=e.node(t);r!==1/0&&i.borderType!==s&&(a[t]=Math.max(a[t]===void 0?0:a[t],r))}function d(e){return o.predecessors(e)||[]}function f(e){return o.successors(e)||[]}return c(l,d),c(u,f),Object.keys(r).forEach(e=>{let t=n[e];t!==void 0&&(a[e]=a[t]??0)}),a}function Pv(e,t,n,r){let i=new Gh,a=e.graph(),o=zv(a.nodesep,a.edgesep,r);return t.forEach(t=>{let r;t.forEach(t=>{let a=n[t];if(a!==void 0){if(i.setNode(a),r!==void 0){let s=n[r];if(s!==void 0){let n=i.edge(s,a);i.setEdge(s,a,Math.max(o(e,t,r),n||0))}}r=t}})}),i}function Fv(e,t){return Object.values(t).reduce((t,n)=>{let r=-1/0,i=1/0;Object.entries(n).forEach(([t,n])=>{let a=Bv(e,t)/2;r=Math.max(n+a,r),i=Math.min(n-a,i)});let a=r-i;return a<t[0]&&(t=[a,n]),t},[1/0,null])[1]}function Iv(e,t){let n=Object.values(t),r=zg(Math.min,n),i=zg(Math.max,n);[`u`,`d`].forEach(n=>{[`l`,`r`].forEach(a=>{let o=n+a,s=e[o];if(!s||s===t)return;let c=Object.values(s),l=r-zg(Math.min,c);a!==`l`&&(l=i-zg(Math.max,c)),l&&(e[o]=Jg(s,e=>e+l))})})}function Lv(e,t=void 0){let n=e.ul;return n?Jg(n,(n,r)=>{if(t){let n=e[t.toLowerCase()];if(n&&n[r]!==void 0)return n[r]}let i=Object.values(e).map(e=>{let t=e[r];return t===void 0?0:t}).sort((e,t)=>e-t);return((i[1]??0)+(i[2]??0))/2}):{}}function Rv(e){let t=Ng(e),n=Object.assign(Dv(e,t),Ov(e,t)),r={},i;return[`u`,`d`].forEach(a=>{i=a===`u`?t:Object.values(t).reverse(),[`l`,`r`].forEach(t=>{t===`r`&&(i=i.map(e=>Object.values(e).reverse()));let o=Mv(e,i,n,t=>(a===`u`?e.predecessors(t):e.successors(t))||[]),s=Nv(e,i,o.root,o.align,t===`r`);t===`r`&&(s=Jg(s,e=>-e)),r[a+t]=s})}),Iv(r,Fv(e,r)),Lv(r,e.graph().align)}function zv(e,t,n){return(r,i,a)=>{let o=r.node(i),s=r.node(a),c=0,l;if(c+=o.width/2,Object.hasOwn(o,`labelpos`))switch(o.labelpos.toLowerCase()){case`l`:l=-o.width/2;break;case`r`:l=o.width/2;break}if(l&&(c+=n?l:-l),l=void 0,c+=(o.dummy?t:e)/2,c+=(s.dummy?t:e)/2,c+=s.width/2,Object.hasOwn(s,`labelpos`))switch(s.labelpos.toLowerCase()){case`l`:l=s.width/2;break;case`r`:l=-s.width/2;break}return l&&(c+=n?l:-l),c}}function Bv(e,t){return e.node(t).width}function Vv(e){e=jg(e),Hv(e),Object.entries(Rv(e)).forEach(([t,n])=>e.node(t).x=n)}function Hv(e){let t=Ng(e),n=e.graph(),r=n.ranksep,i=n.rankalign,a=0;t.forEach(t=>{let n=t.reduce((t,n)=>{let r=e.node(n).height??0;return t>r?t:r},0);t.forEach(t=>{let r=e.node(t);i===`top`?r.y=a+r.height/2:i===`bottom`?r.y=a+n-r.height/2:r.y=a+n/2}),a+=n+r})}function Uv(e,t={}){let n=t.debugTiming?Hg:Ug;return n(`layout`,()=>{let r=n(` buildLayoutGraph`,()=>ey(e));return n(` runLayout`,()=>Wv(r,n,t)),n(` updateInputGraph`,()=>Gv(e,r)),r})}function Wv(e,t,n){t(` makeSpaceForEdgeLabels`,()=>ty(e)),t(` removeSelfEdges`,()=>uy(e)),t(` acyclic`,()=>c_(e)),t(` nestingGraph.run`,()=>G_(e)),t(` rank`,()=>I_(jg(e))),t(` injectEdgeLabelProxies`,()=>ny(e)),t(` removeEmptyRanks`,()=>Fg(e)),t(` nestingGraph.cleanup`,()=>Y_(e)),t(` normalizeRanks`,()=>Pg(e)),t(` assignRankMinMax`,()=>ry(e)),t(` removeEdgeLabelProxies`,()=>iy(e)),t(` normalize.run`,()=>d_(e)),t(` parentDummyChains`,()=>V_(e)),t(` addBorderSegments`,()=>X_(e)),t(` order`,()=>Cv(e,n)),t(` insertSelfEdges`,()=>dy(e)),t(` adjustCoordinateSystem`,()=>$_(e)),t(` position`,()=>Vv(e)),t(` positionSelfEdges`,()=>fy(e)),t(` removeBorderNodes`,()=>ly(e)),t(` normalize.undo`,()=>p_(e)),t(` fixupEdgeLabelCoords`,()=>sy(e)),t(` undoCoordinateSystem`,()=>ev(e)),t(` translateGraph`,()=>ay(e)),t(` assignNodeIntersects`,()=>oy(e)),t(` reversePoints`,()=>cy(e)),t(` acyclic.undo`,()=>u_(e))}function Gv(e,t){e.nodes().forEach(n=>{let r=e.node(n),i=t.node(n);r&&(r.x=i.x,r.y=i.y,r.order=i.order,r.rank=i.rank,t.children(n).length&&(r.width=i.width,r.height=i.height))}),e.edges().forEach(n=>{let r=e.edge(n),i=t.edge(n);r.points=i.points,Object.hasOwn(i,`x`)&&(r.x=i.x,r.y=i.y)}),e.graph().width=t.graph().width,e.graph().height=t.graph().height}var Kv=[`nodesep`,`edgesep`,`ranksep`,`marginx`,`marginy`],qv={ranksep:50,edgesep:20,nodesep:50,rankdir:`TB`,rankalign:`center`},Jv=[`acyclicer`,`ranker`,`rankdir`,`align`,`rankalign`],Yv=[`width`,`height`,`rank`],Xv={width:0,height:0},Zv=[`minlen`,`weight`,`width`,`height`,`labeloffset`],Qv={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:`r`},$v=[`labelpos`];function ey(e){let t=new Gh({multigraph:!0,compound:!0}),n=my(e.graph());return t.setGraph(Object.assign({},qv,py(n,Kv),qg(n,Jv))),e.nodes().forEach(n=>{let r=py(my(e.node(n)),Yv);Object.keys(Xv).forEach(e=>{r[e]===void 0&&(r[e]=Xv[e])}),t.setNode(n,r);let i=e.parent(n);i!==void 0&&t.setParent(n,i)}),e.edges().forEach(n=>{let r=my(e.edge(n));t.setEdge(n,Object.assign({},Qv,py(r,Zv),qg(r,$v)))}),t}function ty(e){let t=e.graph();t.ranksep/=2,e.edges().forEach(n=>{let r=e.edge(n);r.minlen*=2,r.labelpos.toLowerCase()!==`c`&&(t.rankdir===`TB`||t.rankdir===`BT`?r.width+=r.labeloffset:r.height+=r.labeloffset)})}function ny(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.width&&n.height){let n=e.node(t.v);kg(e,`edge-proxy`,{rank:(e.node(t.w).rank-n.rank)/2+n.rank,e:t},`_ep`)}})}function ry(e){let t=0;e.nodes().forEach(n=>{let r=e.node(n);r.borderTop&&(r.minRank=e.node(r.borderTop).rank,r.maxRank=e.node(r.borderBottom).rank,t=Math.max(t,r.maxRank))}),e.graph().maxRank=t}function iy(e){e.nodes().forEach(t=>{let n=e.node(t);if(n.dummy===`edge-proxy`){let r=n;e.edge(r.e).labelRank=n.rank,e.removeNode(t)}})}function ay(e){let t=1/0,n=0,r=1/0,i=0,a=e.graph(),o=a.marginx||0,s=a.marginy||0;function c(e){let a=e.x,o=e.y,s=e.width,c=e.height;t=Math.min(t,a-s/2),n=Math.max(n,a+s/2),r=Math.min(r,o-c/2),i=Math.max(i,o+c/2)}e.nodes().forEach(t=>c(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);Object.hasOwn(n,`x`)&&c(n)}),t-=o,r-=s,e.nodes().forEach(n=>{let i=e.node(n);i.x-=t,i.y-=r}),e.edges().forEach(n=>{let i=e.edge(n);i.points.forEach(e=>{e.x-=t,e.y-=r}),Object.hasOwn(i,`x`)&&(i.x-=t),Object.hasOwn(i,`y`)&&(i.y-=r)}),a.width=n-t+o,a.height=i-r+s}function oy(e){e.edges().forEach(t=>{let n=e.edge(t),r=e.node(t.v),i=e.node(t.w),a,o;n.points?(a=n.points[0],o=n.points[n.points.length-1]):(n.points=[],a=i,o=r),n.points.unshift(Mg(r,a)),n.points.push(Mg(i,o))})}function sy(e){e.edges().forEach(t=>{let n=e.edge(t);if(Object.hasOwn(n,`x`))switch((n.labelpos===`l`||n.labelpos===`r`)&&(n.width-=n.labeloffset),n.labelpos){case`l`:n.x-=n.width/2+n.labeloffset;break;case`r`:n.x+=n.width/2+n.labeloffset;break}})}function cy(e){e.edges().forEach(t=>{let n=e.edge(t);n.reversed&&n.points.reverse()})}function ly(e){e.nodes().forEach(t=>{if(e.children(t).length){let n=e.node(t),r=e.node(n.borderTop),i=e.node(n.borderBottom),a=e.node(n.borderLeft[n.borderLeft.length-1]),o=e.node(n.borderRight[n.borderRight.length-1]);n.width=Math.abs(o.x-a.x),n.height=Math.abs(i.y-r.y),n.x=a.x+n.width/2,n.y=r.y+n.height/2}}),e.nodes().forEach(t=>{e.node(t).dummy===`border`&&e.removeNode(t)})}function uy(e){e.edges().forEach(t=>{if(t.v===t.w){let n=e.node(t.v);n.selfEdges||=[],n.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}})}function dy(e){Ng(e).forEach(t=>{let n=0;t.forEach((t,r)=>{let i=e.node(t);i.order=r+n,(i.selfEdges||[]).forEach(t=>{kg(e,`selfedge`,{width:t.label.width,height:t.label.height,rank:i.rank,order:r+ ++n,e:t.e,label:t.label},`_se`)}),delete i.selfEdges})})}function fy(e){e.nodes().forEach(t=>{let n=e.node(t);if(n.dummy===`selfedge`){let r=n,i=e.node(r.e.v),a=i.x+i.width/2,o=i.y,s=n.x-a,c=i.height/2;e.setEdge(r.e,r.label),e.removeNode(t),r.label.points=[{x:a+2*s/3,y:o-c},{x:a+5*s/6,y:o-c},{x:a+s,y:o},{x:a+5*s/6,y:o+c},{x:a+2*s/3,y:o+c}],r.label.x=n.x,r.label.y=n.y}})}function py(e,t){return Jg(qg(e,t),Number)}function my(e){let t={};return e&&Object.entries(e).forEach(([e,n])=>{typeof e==`string`&&(e=e.toLowerCase()),t[e]=n}),t}var hy=212,gy=164;function _y(e,t,n=`LR`,r=!0){if(!e)return{nodes:[],edges:[]};let i=xy(e,n),a=vy(n),o=by(e,t),s=e.nodes.map(n=>({id:n.asset_id,initialHeight:gy,initialWidth:hy,measured:{height:gy,width:hy},type:`assetNode`,height:gy,position:n.position||i.get(n.asset_id)||{x:0,y:0},sourcePosition:a.source,targetPosition:a.target,width:hy,data:{...n,active:n.asset_id===t,focusRole:o.roles.get(n.asset_id)||`none`,root:n.asset_id===e.root_asset_id,sourcePosition:a.source,targetPosition:a.target}})),c=new Map(e.nodes.map(e=>[e.asset_id,e.title]));return{nodes:s,edges:e.edges.map(t=>{let n=t.summary?`lineage-edge-summary`:``,i=[o.edgeClasses.get(t.id),n].filter(Boolean).join(` `)||void 0,a=`${c.get(t.parent_asset_id)||t.parent_asset_id} to ${c.get(t.child_asset_id)||t.child_asset_id}`;return{ariaLabel:t.summary?`${a}: ${t.summary}`:a,ariaRole:`button`,className:i,domAttributes:{"aria-keyshortcuts":`Enter Space`},focusable:!0,id:t.id,markerEnd:{type:Bs.ArrowClosed},source:t.parent_asset_id,target:t.child_asset_id,type:`smoothstep`,animated:e.selected.includes(t.child_asset_id),...t.summary&&r?{label:t.summary,labelBgBorderRadius:4,labelBgPadding:[5,3],labelShowBg:!0}:{}}})}}function vy(e){return{BT:{source:Q.Top,target:Q.Bottom},LR:{source:Q.Right,target:Q.Left},RL:{source:Q.Left,target:Q.Right},TB:{source:Q.Bottom,target:Q.Top}}[e]}function yy(e,t=`LR`){if(!e)return`lineage-empty`;let n=e.nodes.map(e=>e.asset_id).sort().join(`,`),r=e.edges.map(e=>e.id).sort().join(`,`);return`${e.root_asset_id}:${t}:${n}:${r}`}function by(e,t){let n=new Map,r=new Map;if(!t||!e.nodes.some(e=>e.asset_id===t))return{edgeClasses:r,roles:n};n.set(t,`active`);for(let i of e.edges)i.child_asset_id===t&&(n.has(i.parent_asset_id)||n.set(i.parent_asset_id,`parent`),r.set(i.id,`lineage-edge-focus lineage-edge-focus-parent`)),i.parent_asset_id===t&&(n.has(i.child_asset_id)||n.set(i.child_asset_id,`child`),r.set(i.id,`lineage-edge-focus lineage-edge-focus-child`));return{edgeClasses:r,roles:n}}function xy(e,t=`LR`){let n=new Hh.Graph;n.setGraph({marginx:40,marginy:40,nodesep:80,rankdir:t,ranksep:110}),n.setDefaultEdgeLabel(()=>({}));for(let t of e.nodes)n.setNode(t.asset_id,{height:gy,width:hy});for(let t of e.edges)n.setEdge(t.parent_asset_id,t.child_asset_id);return Uv(n),new Map(e.nodes.map(e=>{let t=n.node(e.asset_id);return[e.asset_id,{x:Math.round((t?.x||hy/2)-hy/2),y:Math.round((t?.y||gy/2)-gy/2)}]}))}function Sy(e){return!!(e&&e.nodes.length>1&&e.edges.length>0)}function Cy(e){let t=new Set(e.nodes.map(e=>e.asset_id));if(t.size===0)return{stages:[]};let n=[...t].sort(Dy),r=t.has(e.root_asset_id)?e.root_asset_id:n[0],i=new Set([r]),a=new Set,o=e.edges.filter(e=>t.has(e.parent_asset_id)&&t.has(e.child_asset_id)).sort(Ey),s=[Ty(0,i,a,[r],[])];for(;i.size<t.size||o.length>0;){let e=o.findIndex(e=>i.has(e.parent_asset_id));if(e>=0){let[t]=o.splice(e,1);a.add(t.id);let n=i.has(t.child_asset_id)?[]:[t.child_asset_id];i.add(t.child_asset_id),s.push(Ty(s.length,i,a,n,[t.id]));continue}let t=n.find(e=>!i.has(e));if(t){i.add(t),s.push(Ty(s.length,i,a,[t],[]));continue}break}return{stages:s}}function wy(e,t,n,r,i){let a=n.stages,o=a.length-1,s=Math.max(-1,Math.min(r,o)),c=s>=0?a[s]:void 0,l=s<o?a[s+1]:void 0,u=new Set(c?.nodeIds||[]),d=new Set(c?.edgeIds||[]),f=new Set,p=new Set;if(l&&(i===`edge`||i===`node`))for(let e of l.enteringEdgeIds)i===`edge`?p.add(e):d.add(e);if(l&&i===`node`)for(let e of l.enteringNodeIds)f.add(e);let m=s===o&&i===`settled`,h=new Map(e.map(e=>[e.id,f.has(e.id)?`entering`:u.has(e.id)?`visible`:`future`])),g=new Map(t.map(e=>[e.id,p.has(e.id)?`entering`:d.has(e.id)?`visible`:`future`]));return{nodes:e.map(e=>({...e,data:{...e.data,replayInteractive:m,replayState:h.get(e.id)||`future`}})),edges:t.map(e=>{let t=g.get(e.id)||`future`;return{...e,className:[e.className,`lineage-edge-replay-${t}`].filter(Boolean).join(` `),domAttributes:{...e.domAttributes,"aria-hidden":t===`future`?!0:void 0},focusable:m?e.focusable:!1}}),projection:{edgeStates:g,interactive:m,nodeStates:h}}}function Ty(e,t,n,r,i){return{edgeIds:[...n],enteringEdgeIds:i,enteringNodeIds:r,index:e,nodeIds:[...t]}}function Ey(e,t){return Dy(e.created_at||``,t.created_at||``)||Dy(e.id,t.id)}function Dy(e,t){return e.localeCompare(t)}function Oy(e,t){(0,p.useEffect)(()=>{function n(n){n.key===`Escape`&&e&&t()}return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t])}function ky({asset:e,onResetLineage:t,onSelectedAsset:n,onToast:r,project:i}){let a=(0,p.useRef)(i),[o,s]=(0,p.useState)(null),[c,l]=(0,p.useState)(null),[u,d]=(0,p.useState)(null),[f,m]=(0,p.useState)(!1),h=o?.project===i,_=h?o:null,v=(_?.workspaces||[]).filter(e=>e.status!==`archived`),y=_?.active_workspace||v[0]||null,b=Eh(y,h&&_?.workspaces.length===0?e?.asset_id:void 0);(0,p.useEffect)(()=>{a.current=i,s(null),l(null),d(null)},[i]);let x=(0,p.useCallback)(async()=>{m(!0);try{let e=await g(`/api/lineage-workspaces?${new URLSearchParams({project:i}).toString()}`);e.project===a.current&&s(e)}catch(e){r(`error`,e instanceof Error?e.message:String(e))}finally{m(!1)}},[r,i]),S=(0,p.useCallback)(async()=>{try{let e=new URLSearchParams({project:i}),[t,n]=await Promise.all([g(`/api/lineage-workspaces/demo/media?${e.toString()}`),g(`/api/lineage-workspaces/demo/swissifier/media?${e.toString()}`)]);if(a.current!==i)return;l(t.status),d(n.status)}catch(e){r(`error`,e instanceof Error?e.message:String(e))}},[r,i]);async function C(e){if(e){m(!0);try{let a=await g(`/api/lineage-workspaces/${encodeURIComponent(e)}/activate`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:i,confirmWrite:!0})});t(),await x(),n(a.workspace.root_asset_id),r(`ok`,`Using ${a.workspace.title}`)}catch(e){r(`error`,e instanceof Error?e.message:String(e))}finally{m(!1)}}}async function w(e={}){m(!0);try{let a=await g(`/api/lineage-workspaces/demo/seed`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:i,confirmWrite:!0})});return t(),await x(),await S(),n(a.workspace?.root_asset_id||a.root_asset_id),e.quiet||r(`ok`,`Seeded demo lineage workspace`),a}catch(e){return r(`error`,e instanceof Error?e.message:String(e)),null}finally{m(!1)}}async function T(e={}){m(!0);try{let a=await g(`/api/lineage-workspaces/demo/swissifier/seed`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:i,confirmWrite:!0})});return t(),await x(),await S(),n(a.workspace?.root_asset_id||a.root_asset_id),e.quiet||r(`ok`,`Seeded Swissifier demo lineage`),a}catch(e){return r(`error`,e instanceof Error?e.message:String(e)),null}finally{m(!1)}}async function E(){m(!0);try{let e=await g(`/api/lineage-workspaces/demo/media/restore`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:i,confirmWrite:!0})});await S(),r(`ok`,`Restored ${e.result.restored||0} demo media file${e.result.restored===1?``:`s`}`)}catch(e){r(`error`,e instanceof Error?e.message:String(e))}finally{m(!1)}}async function D(){m(!0);try{let e=await g(`/api/lineage-workspaces/demo/swissifier/media/restore`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:i,confirmWrite:!0})});await S(),e.result.source_required?r(`error`,`Set ${e.result.source_env||`LINEAGE_SWISSIFIER_MEDIA_DIR`} to restore Swissifier media`):r(`ok`,`Restored ${e.result.restored||0} Swissifier media file${e.result.restored===1?``:`s`}`)}catch(e){r(`error`,e instanceof Error?e.message:String(e))}finally{m(!1)}}async function O(){m(!0);try{let e=await g(`/api/lineage-workspaces/demo/swissifier/media/download`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:i,confirmWrite:!0})});return e.result.media_status?d(e.result.media_status):await S(),e.result.download_available?(r(`ok`,`Downloaded ${e.result.restored||0} Swissifier media file${e.result.restored===1?``:`s`}`),!0):(r(`error`,`Swissifier media download is not configured`),!1)}catch(e){return r(`error`,e instanceof Error?e.message:String(e)),!1}finally{m(!1)}}async function k(){if(y&&window.confirm(`Archive ${y.title}? This hides it from the picker and clears its next-variation selection.`)){m(!0);try{await g(`/api/lineage-workspaces/${encodeURIComponent(y.id)}/archive`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:i,confirmWrite:!0})}),t(),await x(),await S(),r(`ok`,`Archived ${y.title}`)}catch(e){r(`error`,e instanceof Error?e.message:String(e))}finally{m(!1)}}}function A(e){s(t=>({project:i,active_workspace:e,workspaces:[e,...(t?.workspaces||[]).filter(t=>t.id!==e.id)],fetchedAt:new Date().toISOString()})),t(),n(e.root_asset_id),r(`ok`,`Using ${e.title}`)}return{activateWorkspace:C,activeWorkspace:y,archiveWorkspace:k,demoSeedStatus:c,downloadSwissifierDemoMedia:O,handleWorkspaceCreated:A,refreshDemoSeedStatus:S,refreshWorkspaces:x,restoreDemoSeedMedia:E,restoreSwissifierDemoMedia:D,seedDemoWorkspace:w,seedSwissifierDemoWorkspace:T,swissifierDemoStatus:u,visibleWorkspaces:v,workspaceLoading:f,workspaceRootAssetId:b}}function Ay(e,t,n){let r=(0,p.useRef)(!1),i=(0,p.useRef)(``),a=(0,p.useRef)(!1),o=(0,p.useRef)(``),s=(0,p.useCallback)((t=0)=>{window.setTimeout(()=>{e&&(r.current=!0,e.fitView({maxZoom:.9,padding:.32}),window.setTimeout(()=>{r.current=!1},450))},t)},[e]),c=(0,p.useCallback)(()=>{r.current||(a.current=!0)},[]);return(0,p.useEffect)(()=>{if(!t||!e)return;o.current!==t&&(o.current=t,a.current=!1,i.current=``);let r=`${t}:${n?`side-open`:`side-closed`}`;i.current!==r&&(i.current=r,a.current||s(280))},[s,e,t,n]),{fitGraph:s,markViewportInteraction:c}}function jy({actionsOpen:e,asset:t,onActionsOpenChange:n,onAssetsChanged:r,project:i,onSelectedAsset:a,onToast:o}){let[s,c]=(0,p.useState)(null),[l,u]=(0,p.useState)(null),[d,f]=(0,p.useState)(``),[m,_]=(0,p.useState)(null),[v,y]=(0,p.useState)(null),[b,x]=(0,p.useState)([]),[S]=(0,p.useState)(Cm),[C,w]=(0,p.useState)(null),[T,E]=(0,p.useState)([]),[D,O]=(0,p.useState)(!0),[k,A]=(0,p.useState)(null),[j,M]=(0,p.useState)(`LR`),[N,P]=(0,p.useState)(``),[F,I]=(0,p.useState)(null),[L,R]=(0,p.useState)(!1),[z,B]=(0,p.useState)(!1),[V,H]=(0,p.useState)(!1),[U,W,ee]=Bp([]),[te,ne]=Vp([]),[re,ie]=(0,p.useState)(null),[ae,oe]=(0,p.useState)(!1),[se,G]=(0,p.useState)(null),[ce,le]=(0,p.useState)(0),[K,ue]=(0,p.useState)(null),[de,q]=(0,p.useState)(-1),[fe,pe]=(0,p.useState)(`settled`),[me,J]=(0,p.useState)(!1),[he,Y]=(0,p.useState)(1),[ge,_e]=(0,p.useState)(!1),ve=(0,p.useMemo)(()=>K?Cy(K):{stages:[]},[K]),ye=ve.stages.length-1,be=!!(K&&de===ye&&fe===`settled`),xe=K&&!be?K:s,Se=s?.nodes.find(e=>e.asset_id===l)||s?.nodes[0],Ce=s?.edges.find(e=>e.id===k?.edgeId),we=s?.nodes.filter(e=>s.latest.includes(e.asset_id))||[],Te=s?.selected.map(e=>s.nodes.find(t=>t.asset_id===e)).filter(e=>!!e)||[],Ee=Te[0],De=Te.length>=3,Oe=s?.nodes.find(e=>e.asset_id===m)||null,ke=s?.nodes.find(e=>e.asset_id===v)||null,Ae=s?.nodes.find(e=>e.asset_id===F?.assetId),je=S&&!Oe&&!ke&&!Ce&&(!K||be),Me=!!(Se&&N!==(Se.selection_note||``)),Ne=(0,p.useRef)(null),Z=(0,p.useRef)([]),Pe=(0,p.useRef)(``),Fe=(0,p.useRef)(``),{fitGraph:Ie,markViewportInteraction:Le}=Ay(re,s?.root_asset_id,z),Re=(0,p.useCallback)(()=>{le(e=>e+1),I(null)},[]),ze=(0,p.useRef)(i);(0,p.useEffect)(()=>{ze.current=i},[i]);let Be=(0,p.useCallback)(()=>{u(null),Re()},[Re]),Ve=(0,p.useCallback)(()=>{c(null),u(null),w(null),ue(null),J(!1),pe(`settled`),q(-1)},[]),{activateWorkspace:He,activeWorkspace:Ue,archiveWorkspace:We,demoSeedStatus:Ge,downloadSwissifierDemoMedia:Ke,handleWorkspaceCreated:qe,refreshDemoSeedStatus:Je,refreshWorkspaces:Ye,restoreDemoSeedMedia:Xe,restoreSwissifierDemoMedia:Ze,seedDemoWorkspace:Qe,seedSwissifierDemoWorkspace:$e,swissifierDemoStatus:et,visibleWorkspaces:tt,workspaceLoading:nt,workspaceRootAssetId:rt}=ky({asset:t,onResetLineage:Ve,onSelectedAsset:a,onToast:o,project:i});Fe.current=rt,(0,p.useEffect)(()=>{Je()},[Je]);let it=(0,p.useCallback)(async(e={})=>{let t=e.rootAssetId||rt;if(!t)return!1;e.quiet||oe(!0);try{let n=new URLSearchParams({project:i}),[r,a]=await Promise.all([g(`/api/lineage/${t}?${n.toString()}`),g(`/api/agent-claims?${n.toString()}`)]);return!e.rootAssetId&&Fe.current!==t?!1:(c(r),E(a.claims),e.quiet||w(null),u(t=>Rm(t,r.nodes,r.active_asset_id,!!e.quiet)),!0)}catch(n){return!e.rootAssetId&&Fe.current!==t||!e.quiet&&ze.current===i&&(c(null),o(`error`,n instanceof Error?n.message:String(n))),!1}finally{!e.quiet&&ze.current===i&&oe(!1)}},[o,i,rt]),at=(0,p.useCallback)(()=>{!s||!Sy(s)||(Ne.current&&window.clearTimeout(Ne.current),Re(),u(null),_(null),y(null),x([]),A(null),B(!1),H(!1),ue(s),q(-1),pe(`node`),J(!0))},[Re,s]),ot=(0,p.useCallback)(()=>{ue(null),q(-1),pe(`settled`),J(!1),it({quiet:!0})},[it]),st=(0,p.useCallback)(()=>{be&&s&&ue(s),q(-1),pe(`node`),J(!0)},[be,s]),ct=(0,p.useCallback)(()=>{if(be){st();return}J(e=>!e)},[be,st]),lt=(0,p.useCallback)(e=>{J(!1),pe(`settled`),q(Math.max(0,Math.min(e,ye)))},[ye]);async function ut(){G(null),oe(!0);try{o(`ok`,`Indexed ${(await g(`/api/index/local`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:i})})).summary.total} assets`),await Ye(),await it()}catch(e){o(`error`,e instanceof Error?e.message:String(e))}finally{oe(!1)}}async function dt(){Re(),G(null);let e=await Qe();if(e)try{await r?.(),await it({rootAssetId:e.workspace?.root_asset_id||e.root_asset_id})}catch(e){o(`error`,e instanceof Error?e.message:String(e))}}async function ft(){Re(),G(`seeding`);let e=await $e();if(!e){G(`error`);return}try{G(`indexing`),await r?.(),await it({rootAssetId:e.workspace?.root_asset_id||e.root_asset_id})||G(`error`)}catch(e){G(`error`),o(`error`,e instanceof Error?e.message:String(e))}}async function pt(){G(`downloading`);let e=await Ke();G(e?`downloaded`:`error`)}async function mt(e,t,n){try{await g(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:i,...t})}),o(`ok`,n),await it()}catch(e){o(`error`,e instanceof Error?e.message:String(e))}}function ht(){Se&&_t(Se,N)}function gt(){Se?.user_selected&&_t(Se,N)}async function _t(e,t=e.selection_note||``){if(!e.user_selected&&De){o(`error`,`Choose at most 3 assets for next variation`);return}await mt(`/api/selection`,{assetId:e.asset_id,rootAssetId:s?.root_asset_id,mode:e.user_selected?`remove`:`add`,notes:t,confirmWrite:!0},e.user_selected?`Removed ${e.asset_id} from next variation`:`Using ${e.asset_id} for next variation`)}async function vt(e,t=e.selection_note||``){await mt(`/api/selection`,{assetId:e.asset_id,rootAssetId:s?.root_asset_id,mode:`replace`,notes:t,confirmWrite:!0},`Using only ${e.asset_id} for next variation`)}async function yt(e){if(s){if(e){await mt(`/api/selection`,{assetId:e,rootAssetId:s.root_asset_id,mode:`remove`,confirmWrite:!0},`Removed ${e} from next variation`);return}Te.length>0&&await mt(`/api/selection`,{rootAssetId:s.root_asset_id,clear:!0,confirmWrite:!0},`Removed all assets from next variation`)}}function bt(){if(Ne.current&&window.clearTimeout(Ne.current),z){B(!1),Ne.current=window.setTimeout(()=>H(!1),260);return}H(!0),window.requestAnimationFrame(()=>B(!0))}async function xt(e,t=Se?.asset_id){if(!t)return;let n=s?.nodes.find(e=>e.asset_id===t),r=Lh(n,e);r&&!window.confirm(r.confirmation)||(r&&await yt(t),mt(`/api/reviews/${t}`,{reviewState:e,confirmWrite:!0},`Marked ${t} ${e}`))}async function St(e){s&&await mt(`/api/lineage/${s.root_asset_id}/rerolls/${e.asset_id}`,{confirmWrite:!0,requestedBy:`human`},`Marked ${e.asset_id} for re-roll`)}async function Ct(e){s&&await mt(`/api/lineage/${s.root_asset_id}/rerolls/${e.asset_id}/cancel`,{confirmWrite:!0},`Cleared re-roll request for ${e.asset_id}`)}async function wt(e){if(s)try{let t=new URLSearchParams({project:i}),n=await g(`/api/lineage/${s.root_asset_id}/attempts/${e}?${t.toString()}`);x(n.attempts),y(e)}catch(e){o(`error`,e instanceof Error?e.message:String(e))}}function Tt(){y(null),x([])}function Et(e){Tt(),_(e)}async function Dt(e){if(!(!s||!v))try{let t=await g(`/api/lineage/${s.root_asset_id}/attempts/${v}/promote`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:i,attemptId:e.id,confirmWrite:!0})});x(t.attempts),o(`ok`,`Set v${e.attempt_index} as current`),await it({quiet:!0})}catch(e){o(`error`,e instanceof Error?e.message:String(e))}}async function Ot(){!Se||!d.trim()||(await mt(`/api/lineage/link`,{childAssetId:d.trim(),confirmWrite:!0,parentAssetId:Se.asset_id},`Linked ${d.trim()} from ${Se.asset_id}`),f(``))}async function kt(e,t){if(Ce)try{let n=await g(`/api/lineage/edges/${encodeURIComponent(Ce.id)}/summary`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:e,confirmWrite:!0,expectedSummaryUpdatedAt:Ce.summary_updated_at||null,project:i,...e===`set`?{summary:t}:{}})});await it({quiet:!0}),o(`ok`,n.message),A(null)}catch(e){throw e instanceof h&&e.status===409&&e.message.includes(`Edge summary changed since it was opened`)?(await it({quiet:!0}),Error(`This edge changed elsewhere. The current label has been reloaded; review it and retry.`,{cause:e})):e}}async function At(e){if(!s)return;if(e.asset_id===s.root_asset_id){o(`error`,`Root lineage node cannot be removed. Archive this workspace or start a new lineage instead.`);return}let t=s.edges.filter(t=>t.parent_asset_id===e.asset_id).length,n=s.edges.filter(t=>t.child_asset_id===e.asset_id).length,r=t>0&&n>0?` Its ${t} child${t===1?``:`ren`} will be reconnected to its parent${n===1?``:`s`}.`:``;window.confirm(`Remove "${e.title}" from this lineage? This keeps the asset file and S3 object intact.${r}`)&&(await mt(`/api/lineage/remove-node`,{assetId:e.asset_id,rootAssetId:s.root_asset_id,confirmWrite:!0},`Removed ${e.asset_id} from lineage`),I(null),_(t=>t===e.asset_id?null:t),u(t=>t===e.asset_id?s.root_asset_id:t))}async function jt(e){if(s)try{await Fh(i,s.root_asset_id,[{assetId:e.id,x:e.position.x,y:e.position.y}])}catch(e){o(`error`,e instanceof Error?e.message:String(e))}}async function Mt(){if(!s)return;let e=[...xy(s,j)].map(([e,t])=>({assetId:e,...t}));Pt(e),W(t=>t.map(t=>({...t,position:e.find(e=>e.assetId===t.id)||t.position})));try{await Fh(i,s.root_asset_id,e),o(`ok`,`Tidied ${e.length} lineage nodes`),Ie(80),await it({quiet:!0})}catch(e){o(`error`,e instanceof Error?e.message:String(e))}}async function Nt(e){if(!s)return;let t=[...xy(s,e)].map(([e,t])=>({assetId:e,...t}));Pt(t),M(e),W(e=>e.map(e=>({...e,position:t.find(t=>t.assetId===e.id)||e.position})));try{await Fh(i,s.root_asset_id,t),o(`ok`,`Rotated lineage graph ${Ny(e).toLowerCase()}`),Ie(80),await it({quiet:!0})}catch(e){o(`error`,e instanceof Error?e.message:String(e))}}function Pt(e){let t=new Map(e.map(e=>[e.assetId,{x:e.x,y:e.y}]));c(e=>e&&{...e,nodes:e.nodes.map(e=>({...e,position:t.get(e.asset_id)||e.position}))})}async function Ft(){if(s)try{let e=new URLSearchParams({project:i});w(await g(`/api/lineage/${s.root_asset_id}/brief?${e.toString()}`))}catch(e){o(`error`,e instanceof Error?e.message:String(e))}}async function It(e,t,n){try{await g(`/api/agent-claims/${t.id}/${e}`,{body:JSON.stringify({project:i,...n}),headers:{"Content-Type":`application/json`},method:`POST`}),o(`ok`,`Updated claim ${t.id}`),await it({quiet:!0})}catch(e){o(`error`,e instanceof Error?e.message:String(e))}}(0,p.useEffect)(()=>{Ye()},[Ye]),(0,p.useEffect)(()=>{it()},[it]),(0,p.useEffect)(()=>{rt||Ve()},[Ve,rt]),(0,p.useEffect)(()=>{if(!s)return;let e=window.setInterval(()=>void it({quiet:!0}),8e3);return()=>window.clearInterval(e)},[it,s?.root_asset_id]),(0,p.useEffect)(()=>{let e=window.matchMedia?.(`(prefers-reduced-motion: reduce)`);if(!e)return;let t=()=>_e(e.matches);return t(),e.addEventListener?.(`change`,t),()=>e.removeEventListener?.(`change`,t)},[]),(0,p.useEffect)(()=>{if(!K||!me||ye<0)return;let e=Math.min(de+1,ye);if(fe===`settled`&&de>=ye){J(!1);return}let t=ve.stages[e],n=ge?40:void 0,r=n??120/he,i=()=>{let e=t.enteringEdgeIds.length>0?`edge`:`node`;pe(e)};fe===`edge`?(r=n??320/he,i=()=>{t.enteringNodeIds.length>0?pe(`node`):(q(e),pe(`settled`))}):fe===`node`&&(r=n??200/he,i=()=>{q(e),pe(`settled`)});let a=window.setTimeout(i,r);return()=>window.clearTimeout(a)},[ge,ye,fe,me,K,he,de,ve.stages]);let Lt=(0,p.useMemo)(()=>_y(xe,l,j,D),[l,D,j,xe]),Rt=(0,p.useMemo)(()=>K&&!be?wy(Lt.nodes,Lt.edges,ve,de,fe):Lt,[Lt,be,fe,K,de,ve]),zt=(0,p.useMemo)(()=>yy(xe,j),[j,xe]);Z.current=Rt.edges;let Bt=(0,p.useCallback)(e=>{ne(t=>Ih(e,t,Z.current))},[ne]),Vt=(0,p.useCallback)(e=>{e.key===`Escape`&&Re()},[Re]);return(0,p.useEffect)(()=>{P(Se?.selection_note||``)},[Se?.asset_id,Se?.selection_note]),(0,p.useEffect)(()=>{let e=Pe.current!==zt;Pe.current=zt,W(t=>Rt.nodes.map(n=>({...n,position:e?n.position:t.find(e=>e.id===n.id)?.position||n.position}))),ne(Rt.edges)},[Rt.edges,Rt.nodes,zt,ne,W]),(0,p.useEffect)(()=>{se!==`indexing`||!s?.nodes.length||Pe.current!==zt||U.length!==s.nodes.length||G(`ready`)},[U.length,zt,s,se]),Oy(!!l,Be),(0,p.useEffect)(()=>()=>{Ne.current&&window.clearTimeout(Ne.current)},[]),(0,p.useEffect)(()=>{Ve(),G(null)},[i,Ve]),(0,X.jsxs)(`section`,{className:`lineage-view`,onKeyDownCapture:Vt,children:[(0,X.jsx)(Ph,{actionsOpen:e,activeWorkspace:Ue,closeSignal:ce,edgeSummariesVisible:D,loading:ae,graphDirection:j,demoSeedStatus:Ge,onArchiveWorkspace:()=>{G(null),We()},onActionsOpenChange:n,onFitGraph:()=>Ie(),onIndexLocal:()=>void ut(),onGraphDirection:e=>void Nt(e),onNewLineage:()=>{G(null),R(!0)},onRefreshLineage:()=>void it(),onRefreshWorkspaces:()=>void Ye(),onReplayGrowth:at,onRestoreDemoMedia:()=>void Xe(),onRestoreSwissifierMedia:()=>void Ze(),onDownloadSwissifierMedia:()=>void pt(),onEdgeSummariesVisible:()=>O(e=>!e),onSeedDemo:()=>void dt(),onSeedSwissifierDemo:()=>void ft(),onSelectWorkspace:e=>{G(null),He(e)},onTidyGraph:()=>void Mt(),onToggleNextPanel:bt,replayActive:!!K,sideOpen:z,snapshot:s,swissifierDemoStatus:et,workspaceLoading:nt,workspaceProgress:se,workspaceRootAssetId:rt,workspaces:tt}),(0,X.jsxs)(`div`,{className:`lineage-workbench`,"data-testid":`lineage-workbench`,children:[(0,X.jsxs)(`div`,{className:`lineage-canvas ${l?`focus-active`:``} ${K?`lineage-replay-active`:``} ${be?`lineage-replay-interactive`:``} ${K&&!me?`lineage-replay-paused`:``}`,style:K?{"--lineage-replay-edge-duration":`${ge?1:320/he}ms`,"--lineage-replay-node-duration":`${ge?1:200/he}ms`}:void 0,children:[K&&ve.stages.length>0&&(0,X.jsx)(ch,{atEnd:be,onClose:ot,onPlayPause:ct,onRestart:st,onScrub:lt,onSpeed:Y,playing:me,speed:he,stageIndex:de,totalStages:ve.stages.length}),(0,X.jsx)(Nm,{flowEdges:xe?te:[],flowNodes:xe?U:[],graphKey:zt,hoverPreviewsEnabled:je,loading:ae,onEdgesChange:Bt,onEdgeEdit:(e,t)=>A({edgeId:e,returnFocus:t}),onClearFocus:Be,onIndexNow:()=>void ut(),onNewLineage:()=>{G(null),R(!0)},onSeedDemo:()=>void dt(),onNodeActionMenu:(e,t,n)=>I(e?{assetId:e,x:t,y:n}:null),onNodeInspect:e=>{Re(),u(e)},onNodeOpenDetail:_,onNodeOpenHistory:e=>void wt(e),onNodePosition:e=>void jt(e),onNodesChange:ee,onReady:ie,onSelectedAsset:a,onToggleBranch:e=>e.user_selected?yt(e.asset_id):_t(e),onToggleReroll:e=>e.reroll_request?.status===`pending`?Ct(e):St(e),onViewportInteraction:Le,replayInteractive:!K||be,selectionFull:De,workspaceProgress:se,workspaceRootAssetId:rt})]}),V&&s&&(0,X.jsx)(vh,{activeNode:Se,brief:C,childAssetId:d,clearNextVariation:yt,closePanel:bt,latestNodes:we,linkChild:Ot,markReview:xt,nextVariationLimit:3,noteDirty:Me,onSelectedAsset:a,onToast:o,project:i,refreshBrief:Ft,refreshLineage:async()=>{await it({quiet:!0})},saveRationale:gt,replaceNextVariation:vt,selectNextBase:_t,selectedNode:Ee,selectedNodes:Te,selectionFull:De,selectionNote:N,setActiveNodeId:u,setChildAssetId:f,setDetailNodeId:_,setSelected:ht,setSelectionNote:P,sideOpen:z,snapshot:s}),F&&Ae&&s&&(0,X.jsx)(Pm,{canRemoveFromLineage:Ae.asset_id!==s.root_asset_id,claims:My(T,i,s.root_asset_id),node:Ae,onClaimControl:(e,t,n)=>{It(e,t,n)},onClearAllNext:()=>void yt(),onClearNext:()=>void yt(Ae.asset_id),onClearReroll:()=>void Ct(Ae),onClose:()=>I(null),onMarkReroll:()=>void St(Ae),onOpenDetail:()=>_(Ae.asset_id),onRemoveFromLineage:()=>void At(Ae),onReplaceNext:()=>vt(Ae),onReview:e=>void xt(e,Ae.asset_id),onSelectNext:()=>_t(Ae),position:F,selectedCount:Te.length,selectionFull:De})]}),ke&&s&&(0,X.jsx)(Wm,{actions:{canRemoveFromLineage:ke.asset_id!==s.root_asset_id,onClearAllNext:()=>void yt(),onClearNext:()=>void yt(ke.asset_id),onOpenNode:Et,onRemoveFromLineage:e=>void At(e),onReplaceNext:vt,onReview:xt,onSelectNext:_t,onToast:o,selectedCount:Te.length,selectionFull:De,snapshot:s},attempts:b,node:ke,onClose:Tt,onPromoteAttempt:Dt,project:i}),Oe&&s&&(0,X.jsx)(Xm,{canRemoveFromLineage:Oe.asset_id!==s.root_asset_id,node:Oe,onClearAllNext:()=>void yt(),onClearNext:()=>void yt(Oe.asset_id),onClose:()=>_(null),onOpenNode:_,onRemoveFromLineage:e=>void At(e),onReplaceNext:vt,onReview:xt,onSelectNext:_t,onToast:o,selectedCount:Te.length,selectionFull:De,snapshot:s}),Ce&&k&&s&&(0,X.jsx)($m,{childTitle:s.nodes.find(e=>e.asset_id===Ce.child_asset_id)?.title||Ce.child_asset_id,edge:Ce,onClose:()=>A(null),onSubmit:kt,parentTitle:s.nodes.find(e=>e.asset_id===Ce.parent_asset_id)?.title||Ce.parent_asset_id,returnFocus:k.returnFocus}),(0,X.jsx)(sh,{onClose:()=>R(!1),onCreated:qe,onToast:o,open:L,project:i})]})}function My(e,t,n){let r=`${t}:lineage-workspace:${n}`;return e.filter(e=>e.project!==t||e.status!==`active`||e.derived_state===`expired`?!1:e.scope_type===`lineage_workspace`?e.target_id===r:e.scope_type===`project_channel`)}function Ny(e){return{BT:`bottom to top`,LR:`left to right`,RL:`right to left`,TB:`top to bottom`}[e]}function Py({assets:e,onClose:t,onDone:n,onError:r,project:i}){let a=e[0],[o,s]=(0,p.useState)(!1),[c,l]=(0,p.useState)(!1),[u,d]=(0,p.useState)([]),[f,m]=(0,p.useState)({audience:a?.audience||`local-review`,campaign:a?.campaign||`local-review`,channel:a?.channel===`local`?`meta`:a?.channel||`meta`,cta:a?.cta||`Review before upload`,status:`working`}),h=e.filter(e=>!Iy(e)),_=h.length>0||e.length===0;function v(e,t){m(n=>({...n,[e]:t}))}function y(e,t){let n=pe(e.title)||e.asset_id;return{...f,assetId:n,confirmWrite:o,dryRun:t,hook:e.hook,notes:e.notes,path:e.local?.relative_path,project:i,title:e.title,type:e.content_type,utmContent:e.utm_content||n.replaceAll(`-`,`_`)}}async function b(t){if(_){r(`Local backup is locked until every selected local asset is approved.`);return}l(!0);try{let r=[];for(let n of e){if(!n.local?.relative_path)throw Error(`${n.asset_id} has no local path`);let e=await g(`/api/assets/local-backup`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(y(n,t))});r.push(e.message)}t?d(r):await n(`Backed up ${e.length} local asset${e.length===1?``:`s`}`)}catch(e){r(e instanceof Error?e.message:String(e))}finally{l(!1)}}return(0,X.jsx)(`div`,{className:`drawer-backdrop`,children:(0,X.jsxs)(`section`,{className:`local-backup-drawer`,children:[(0,X.jsxs)(`header`,{children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h2`,{children:`Back up local assets`}),(0,X.jsx)(`p`,{children:i})]}),(0,X.jsx)(`button`,{onClick:t,children:`Close`})]}),(0,X.jsx)(`div`,{className:`local-backup-list`,children:e.map(e=>(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`strong`,{children:pe(e.title)||e.asset_id}),(0,X.jsx)(`span`,{children:e.local?.relative_path}),(0,X.jsxs)(`span`,{children:[`Review: `,Ly(Fy(e))]})]},e.asset_id))}),_&&(0,X.jsxs)(`div`,{className:`local-backup-warning`,role:`alert`,children:[(0,X.jsx)(`strong`,{children:`Backup is locked until local review is approved.`}),e.length===0?(0,X.jsx)(`span`,{children:`No local assets are selected.`}):null,h.map(e=>(0,X.jsxs)(`span`,{children:[pe(e.title)||e.asset_id,`: `,Ly(Fy(e))]},e.asset_id))]}),(0,X.jsxs)(`div`,{className:`form-grid`,children:[(0,X.jsxs)(`label`,{children:[`Campaign`,(0,X.jsx)(`input`,{value:f.campaign,onChange:e=>v(`campaign`,e.target.value)})]}),(0,X.jsxs)(`label`,{children:[`Channel`,(0,X.jsx)(`input`,{value:f.channel,onChange:e=>v(`channel`,e.target.value)})]}),(0,X.jsxs)(`label`,{children:[`Audience`,(0,X.jsx)(`input`,{value:f.audience,onChange:e=>v(`audience`,e.target.value)})]}),(0,X.jsxs)(`label`,{children:[`Status`,(0,X.jsxs)(`select`,{value:f.status,onChange:e=>v(`status`,e.target.value),children:[(0,X.jsx)(`option`,{children:`working`}),(0,X.jsx)(`option`,{children:`published`})]})]}),(0,X.jsxs)(`label`,{className:`wide`,children:[`CTA`,(0,X.jsx)(`input`,{value:f.cta,onChange:e=>v(`cta`,e.target.value)})]})]}),u.length>0&&(0,X.jsx)(`div`,{className:`local-backup-preview`,children:u.map(e=>(0,X.jsx)(`span`,{children:e},e))}),(0,X.jsxs)(`label`,{className:`confirm-line`,children:[(0,X.jsx)(`input`,{checked:o,type:`checkbox`,onChange:e=>s(e.target.checked)}),(0,X.jsx)(`span`,{children:`Confirm write to the production asset bucket`})]}),(0,X.jsxs)(`footer`,{children:[(0,X.jsx)(`button`,{disabled:c||_,onClick:()=>void b(!0),children:`Dry run`}),(0,X.jsxs)(`button`,{className:`primary-button`,disabled:c||_||!o,onClick:()=>void b(!1),children:[c?(0,X.jsx)(ee,{className:`spin`,size:16}):(0,X.jsx)(E,{size:16}),`Back up`]})]})]})})}function Fy(e){return e.review?.review_state||`unreviewed`}function Iy(e){return!!e.local?.relative_path&&Fy(e)===`approved`}function Ly(e){return e===`needs_revision`?`needs revision`:e}var Ry=[[`unreviewed`,`Needs review`],[`approved`,`Approved keepers`],[`needs_revision`,`Needs revision`],[`rejected`,`Rejected or ignored`]];function zy(e){let t=e.assets.filter(e=>e.local?.relative_path&&!e.s3?.key),n=t.filter(e=>Hy(e)===`approved`),r=e.selectedBackupIds.length,i=Z(e.cli||null,`local queue --project '${e.project}'`);function a(){for(let t of n)e.onQueueBackup(t)}return(0,X.jsxs)(`section`,{className:`local-backup-queue`,children:[(0,X.jsxs)(`header`,{className:`backup-queue-head`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h2`,{children:`Local Backup Queue`}),(0,X.jsx)(`p`,{children:`Review local-only candidates, select approved keepers, then back them up intentionally.`}),(0,X.jsxs)(`p`,{children:[e.snapshot?.catalog.default_bucket||`No bucket loaded`,` · refreshed `,fe(e.snapshot?.fetchedAt)]})]}),(0,X.jsxs)(`div`,{className:`backup-queue-actions`,children:[(0,X.jsxs)(`button`,{disabled:n.length===0,onClick:a,type:`button`,children:[(0,X.jsx)(w,{size:15}),` Select approved`]}),(0,X.jsxs)(`button`,{disabled:r===0,onClick:e.onOpenBackup,type:`button`,children:[(0,X.jsx)(E,{size:15}),` Back up selected`]})]})]}),(0,X.jsxs)(`div`,{className:`backup-queue-stats`,"aria-label":`Local backup queue summary`,children:[(0,X.jsx)(Vy,{label:`Local only`,value:t.length}),(0,X.jsx)(Vy,{label:`Needs review`,value:t.filter(e=>Hy(e)===`unreviewed`).length}),(0,X.jsx)(Vy,{label:`Approved`,value:n.length}),(0,X.jsx)(Vy,{label:`Selected`,value:r})]}),(0,X.jsxs)(`div`,{className:`handoff-strip`,children:[(0,X.jsx)(`code`,{children:i}),(0,X.jsxs)(`button`,{onClick:()=>void e.onCopy(i,`local backup queue command`),type:`button`,children:[(0,X.jsx)(T,{size:14}),` Copy`]})]}),t.length===0?(0,X.jsx)(`div`,{className:`backup-empty`,children:`No local-only assets are waiting for review or backup.`}):(0,X.jsx)(`div`,{className:`backup-queue-grid`,children:Ry.map(([n,r])=>(0,X.jsxs)(`section`,{className:`backup-queue-lane`,children:[(0,X.jsx)(`h3`,{children:r}),t.filter(e=>Uy(e)===n).map(t=>(0,X.jsx)(By,{asset:t,onLocalReview:e.onLocalReview,onQueueBackup:e.onQueueBackup,onSelectAsset:e.onSelectAsset,selected:e.selected?.asset_id===t.asset_id,selectedForBackup:e.selectedBackupIds.includes(t.asset_id)},t.asset_id))]},n))}),(0,X.jsxs)(`footer`,{className:`pagination-bar`,children:[(0,X.jsx)(`button`,{disabled:!e.snapshot||e.snapshot.pagination.page<=1,onClick:()=>e.setPage(e=>Math.max(e-1,1)),type:`button`,children:`Previous`}),(0,X.jsxs)(`span`,{children:[e.snapshot?.pagination.page||e.page,` of `,e.snapshot?.pagination.totalPages||1]}),(0,X.jsx)(`button`,{disabled:!e.snapshot||e.snapshot.pagination.page>=e.snapshot.pagination.totalPages,onClick:()=>e.setPage(e=>e+1),type:`button`,children:`Next`}),(0,X.jsxs)(`label`,{children:[`Per page`,(0,X.jsx)(`select`,{onChange:t=>e.setPageSize(Number(t.target.value)),value:e.pageSize,children:[10,25,50,100].map(e=>(0,X.jsx)(`option`,{value:e,children:e},e))})]})]})]})}function By(e){let t=Hy(e.asset),n=ye(e.asset),r=t===`approved`;return(0,X.jsxs)(`article`,{className:`backup-queue-card ${e.selected?`selected`:``}`,children:[(0,X.jsx)(`strong`,{children:e.asset.title}),(0,X.jsx)(`code`,{children:e.asset.asset_id}),(0,X.jsx)(`small`,{children:e.asset.local?.relative_path}),(0,X.jsxs)(`div`,{className:`backup-card-meta`,children:[(0,X.jsx)(`span`,{children:n.label}),(0,X.jsx)(`span`,{children:Wy(t)}),(0,X.jsx)(`span`,{children:q(e.asset.local?.size_bytes)})]}),(0,X.jsxs)(`div`,{className:`backup-card-actions`,children:[(0,X.jsx)(`button`,{onClick:()=>e.onSelectAsset(e.asset),type:`button`,children:`Open`}),(0,X.jsx)(`button`,{"aria-pressed":t===`approved`,onClick:()=>void e.onLocalReview(e.asset,`approved`),type:`button`,children:`Approve`}),(0,X.jsx)(`button`,{"aria-pressed":t===`needs_revision`,onClick:()=>void e.onLocalReview(e.asset,`needs_revision`),type:`button`,children:`Revise`}),(0,X.jsx)(`button`,{"aria-pressed":t===`rejected`,onClick:()=>void e.onLocalReview(e.asset,`rejected`),type:`button`,children:`Reject`}),(0,X.jsx)(`button`,{disabled:!r,onClick:()=>e.onQueueBackup(e.asset),type:`button`,children:e.selectedForBackup?`Selected`:r?`Select backup`:`Approve first`})]})]})}function Vy({label:e,value:t}){return(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`strong`,{children:t}),(0,X.jsx)(`span`,{children:e})]})}function Hy(e){return e.review?.review_state||`unreviewed`}function Uy(e){let t=Hy(e);return t===`ignored`?`rejected`:t}function Wy(e){return e===`needs_revision`?`needs revision`:e}function Gy({assets:e,onClear:t,onOpen:n}){return e.length===0?null:(0,X.jsxs)(`div`,{className:`local-selection-toolbar`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`strong`,{children:[e.length,` local keeper`,e.length===1?``:`s`,` selected`]}),(0,X.jsx)(`span`,{children:`Ready for S3 backup preflight`})]}),(0,X.jsxs)(`button`,{onClick:n,children:[(0,X.jsx)(E,{size:16}),`Back up selected`]}),(0,X.jsx)(`button`,{"aria-label":`Clear local backup selection`,className:`icon-lite`,onClick:t,children:(0,X.jsx)(de,{size:16})})]})}function Ky(e){return e.find(e=>qy(e)>0)?.channel||e[0]?.channel}function qy(e){return e.totals.needsQa+e.totals.approvedLocal+e.totals.needsRevision+e.totals.rejectedLocal}var Jy=[[`needsQa`,`Needs QA`],[`approvedLocal`,`Approved`],[`needsRevision`,`Revise`],[`rejectedLocal`,`Rejected`],[`readyToPost`,`S3 ready`],[`scheduled`,`Scheduled`],[`posted`,`Posted`]];function Yy(e){let[t,n]=(0,p.useState)(null),[r,i]=(0,p.useState)(null),[a,o]=(0,p.useState)(null),[s,c]=(0,p.useState)([]),[l,u]=(0,p.useState)(``);async function d(){try{let t=new URLSearchParams({project:e.project,limit:`4`});e.channel!==`all`&&t.set(`channel`,e.channel),n(await g(`/api/review/queue?${t.toString()}`)),i(null)}catch(e){i(e instanceof Error?e.message:String(e))}}if((0,p.useEffect)(()=>{d()},[e.project,e.channel]),r)return(0,X.jsx)(`section`,{className:`review-queue`,children:(0,X.jsx)(`div`,{className:`toast error`,children:r})});if(!t)return(0,X.jsx)(`section`,{className:`review-queue`,children:(0,X.jsx)(`div`,{className:`asset-board`,children:(0,X.jsx)(`div`,{className:`board-head`,children:(0,X.jsx)(`h2`,{children:`Loading review queue`})})})});let f=t.totals.needsQa+t.totals.approvedLocal+t.totals.needsRevision+t.totals.rejectedLocal,m=new Set(t.lanes.flatMap(e=>[...e.needsQa,...e.approvedLocal,...e.needsRevision,...e.rejectedLocal]).map(e=>e.asset_id)),h=s.filter(e=>m.has(e)),_=Ky(t.lanes);function v(e){c(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])}async function y(t){if(h.length!==0){o(`batch`);try{await g(`/api/local-review/batch`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({assetIds:h,confirmWrite:!0,notes:l,project:e.project,reviewState:t})}),c(e=>e.filter(e=>!m.has(e))),u(``),await d()}finally{o(null)}}}return(0,X.jsxs)(`section`,{className:`review-queue`,children:[(0,X.jsxs)(`div`,{className:`review-summary`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`h2`,{children:[t.project,` review queue`]}),(0,X.jsx)(`p`,{children:`Local-first queue for demo assets, channel posting state, and agent handoff.`}),(0,X.jsxs)(`p`,{children:[t.totals.channels,` channels · refreshed `,fe(t.fetchedAt)]})]}),(0,X.jsx)(Xy,{label:`Local review`,value:f}),(0,X.jsx)(Xy,{label:`S3 ready`,value:t.totals.readyToPost}),(0,X.jsx)(Xy,{label:`Scheduled`,value:t.totals.scheduled}),(0,X.jsx)(Xy,{label:`Posted`,value:t.totals.posted})]}),h.length>0?(0,X.jsxs)(`div`,{className:`batch-review-strip`,"aria-label":`Batch local review actions`,children:[(0,X.jsxs)(`strong`,{children:[h.length,` selected`]}),(0,X.jsx)(`textarea`,{"aria-label":`Shared batch review notes`,onChange:e=>u(e.target.value),placeholder:`Shared review notes`,rows:2,value:l}),(0,X.jsx)(`button`,{disabled:h.length===0||a===`batch`,onClick:()=>void y(`approved`),type:`button`,children:`Approve`}),(0,X.jsx)(`button`,{disabled:h.length===0||a===`batch`,onClick:()=>void y(`needs_revision`),type:`button`,children:`Needs revision`}),(0,X.jsx)(`button`,{disabled:h.length===0||a===`batch`,onClick:()=>void y(`rejected`),type:`button`,children:`Reject`})]}):null,(0,X.jsx)(`div`,{className:`queue-lanes`,children:t.lanes.map(t=>(0,X.jsxs)(`details`,{className:`queue-lane`,open:e.channel!==`all`||t.channel===_,children:[(0,X.jsxs)(`summary`,{children:[(0,X.jsx)(`h3`,{children:t.channel}),(0,X.jsxs)(`div`,{className:`lane-counts`,children:[(0,X.jsxs)(`span`,{children:[t.totals.needsQa,` qa`]}),(0,X.jsxs)(`span`,{children:[t.totals.approvedLocal,` approved`]}),(0,X.jsxs)(`span`,{children:[t.totals.needsRevision,` revise`]}),(0,X.jsxs)(`span`,{children:[t.totals.readyToPost,` ready`]}),(0,X.jsxs)(`span`,{children:[t.totals.scheduled,` scheduled`]}),(0,X.jsxs)(`span`,{children:[t.totals.posted,` posted`]})]})]}),(0,X.jsxs)(`div`,{className:`queue-columns`,children:[Jy.filter(([e])=>t[e].length>0).map(([n,r])=>(0,X.jsx)(Zy,{assets:t[n],label:r,onCopy:e.onCopy,onLocalReview:async(t,n)=>{o(t.asset_id);try{await e.onLocalReview(t,n),await d()}finally{o(null)}},onOpenBackup:e.onOpenBackup,onSelectAsset:e.onSelectAsset,pendingReview:a,selected:e.selected,selectedReviewIds:h,onToggleReviewSelection:v},n)),Jy.every(([e])=>t[e].length===0)&&(0,X.jsx)(`p`,{className:`review-empty`,children:`No items in this channel.`})]})]},t.channel))})]})}function Xy({label:e,value:t}){return(0,X.jsxs)(`div`,{className:`queue-stat`,children:[(0,X.jsx)(`strong`,{children:t}),(0,X.jsx)(`span`,{children:e})]})}function Zy(e){return(0,X.jsxs)(`div`,{className:`queue-column`,children:[(0,X.jsx)(`h4`,{children:e.label}),e.assets.map(t=>(0,X.jsx)(Qy,{asset:t,onCopy:e.onCopy,onLocalReview:e.onLocalReview,onOpenBackup:e.onOpenBackup,onSelectAsset:e.onSelectAsset,onToggleReviewSelection:e.onToggleReviewSelection,pendingReview:e.pendingReview===t.asset_id,selected:e.selected?.asset_id===t.asset_id,selectedForReview:e.selectedReviewIds.includes(t.asset_id)},t.asset_id))]})}function Qy(e){let t=Ne(),n=ye(e.asset),r=e.asset.local?$y(e.asset):null,i=r===`approved`,a=e.asset.source===`local`?Z(t,`local inspect --asset-id '${e.asset.asset_id}'`):Z(t,`inspect --asset-id '${e.asset.asset_id}'`);return(0,X.jsxs)(`article`,{className:`queue-card ${e.selected?`selected`:``}`,onClick:()=>e.onSelectAsset(e.asset),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&e.onSelectAsset(e.asset)},role:`button`,tabIndex:0,children:[r?(0,X.jsxs)(`label`,{className:`confirm-line`,onClick:e=>e.stopPropagation(),onKeyDown:ib,children:[(0,X.jsx)(`input`,{checked:e.selectedForReview,onChange:()=>e.onToggleReviewSelection(e.asset.asset_id),type:`checkbox`}),(0,X.jsx)(`span`,{children:`Select for batch review`})]}):null,(0,X.jsx)(`strong`,{children:e.asset.title}),(0,X.jsx)(`small`,{children:e.asset.asset_id}),(0,X.jsxs)(`div`,{className:`lane-counts`,children:[(0,X.jsx)(`span`,{className:`storage-chip ${n.kind}`,children:n.label}),(0,X.jsx)(`span`,{className:`queue-tag`,children:Te(e.asset)}),r?(0,X.jsx)(`span`,{className:`review-chip ${r}`,children:eb(r)}):null]}),r?(0,X.jsxs)(`div`,{className:`review-actions`,"aria-label":`Local review actions for ${e.asset.title}`,onKeyDown:ib,children:[(0,X.jsx)(`button`,{"aria-pressed":r===`approved`,disabled:e.pendingReview,type:`button`,onClick:t=>nb(t,e.onLocalReview,e.asset,`approved`),children:`Approve`}),(0,X.jsx)(`button`,{"aria-pressed":r===`needs_revision`,disabled:e.pendingReview,type:`button`,onClick:t=>nb(t,e.onLocalReview,e.asset,`needs_revision`),children:`Needs revision`}),(0,X.jsx)(`button`,{"aria-pressed":r===`rejected`,disabled:e.pendingReview,type:`button`,onClick:t=>nb(t,e.onLocalReview,e.asset,`rejected`),children:`Reject`})]}):null,(0,X.jsxs)(`div`,{className:`queue-actions`,onKeyDown:ib,children:[(0,X.jsx)(`button`,{type:`button`,onClick:t=>tb(t,e.onCopy,a),children:`Copy inspect`}),e.asset.local?i?(0,X.jsx)(`button`,{type:`button`,onClick:t=>rb(t,e.onOpenBackup,e.asset),children:`Back up`}):(0,X.jsx)(`span`,{className:`backup-locked`,title:`Approve this local asset before backup`,children:`Backup locked until approved.`}):null]})]})}function $y(e){return e.review?.review_state||`unreviewed`}function eb(e){return e===`needs_revision`?`needs revision`:e}function tb(e,t,n){e.stopPropagation(),t(n,`inspect command`)}function nb(e,t,n,r){e.stopPropagation(),t(n,r)}function rb(e,t,n){e.stopPropagation(),t(n)}function ib(e){(e.key===`Enter`||e.key===` `)&&e.stopPropagation()}var ab={channel:`dev`,version:`0.1.22`},ob={cloud:D,image_generator:V,scheduler:oe},sb={cloud:`Cloud storage`,image_generator:`Image generation`,scheduler:`Social scheduling`},cb=[{adapterType:`cloud`,ariaLabel:`Cloud storage settings`},{adapterType:`scheduler`,ariaLabel:`Social scheduling settings`},{adapterType:`image_generator`,ariaLabel:`Image generation settings`}];function lb(e){return typeof e==`boolean`?e?`on`:`off`:typeof e==`number`?String(e):typeof e==`string`?e||`not set`:JSON.stringify(e)}function ub(e){return Object.entries(e.safe_config).filter(([e])=>![`secret`,`token`,`password`,`credential`,`apiKey`].includes(e))}function db(e){return e.health_status===`configured`?`ok`:e.health_status===`missing_config`?`warn`:`muted`}function fb(e){return(0,X.jsx)(`button`,{"aria-checked":e.checked,"aria-label":e.label,className:`settings-switch ${e.checked?`on`:``}`,disabled:e.disabled,onClick:e.onClick,role:`switch`,type:`button`,children:(0,X.jsx)(`span`,{})})}function pb(e){let[t,n]=(0,p.useState)(null),[r,i]=(0,p.useState)(null),[a,s]=(0,p.useState)(!0),[c,l]=(0,p.useState)(``),[u,d]=(0,p.useState)(Cm);function f(){let t=!u;if(!wm(t)){e.onToast(`error`,`Browser storage is unavailable, so the hover preview preference could not be saved`);return}d(t),e.onToast(`ok`,`Lineage hover previews ${t?`enabled`:`disabled`}`)}async function m(){s(!0);try{let[t,r]=await Promise.all([g(`/api/adapters/settings?project=${encodeURIComponent(e.project)}`),g(`/api/runtime`)]);n(t),i(r.runtime)}catch(t){e.onToast(`error`,t instanceof Error?t.message:String(t))}finally{s(!1)}}async function h(t){let r=`${t.adapter_type}:${t.provider}`;l(r);try{let r=await g(`/api/adapters/settings/${t.adapter_type}/${t.provider}`,{body:JSON.stringify({confirmWrite:!0,enabled:!t.enabled,project:e.project,safeConfig:t.safe_config}),headers:{"Content-Type":`application/json`},method:`POST`});n(e=>e&&{...e,settings:e.settings.map(e=>e.adapter_type===r.setting.adapter_type&&e.provider===r.setting.provider?r.setting:e)}),e.onToast(`ok`,`${sb[t.adapter_type]} ${r.setting.enabled?`enabled`:`disabled`}`)}catch(t){e.onToast(`error`,t instanceof Error?t.message:String(t))}finally{l(``)}}return(0,p.useEffect)(()=>{m()},[e.project]),(0,X.jsxs)(`section`,{className:`settings-view`,children:[(0,X.jsxs)(`header`,{className:`settings-header`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h2`,{children:`Settings`}),(0,X.jsxs)(`p`,{children:[`Adapter switches, safe local preferences, and credential-source status for `,e.project,`.`]})]}),(0,X.jsxs)(`button`,{className:`secondary-button`,disabled:a,onClick:()=>void m(),type:`button`,children:[a?(0,X.jsx)(ee,{className:`spin`,size:17}):(0,X.jsx)(o,{size:17}),`Refresh`]})]}),(0,X.jsxs)(`div`,{className:`settings-sections`,children:[(0,X.jsxs)(`section`,{"aria-label":`Release information`,className:`settings-section`,children:[(0,X.jsx)(`h3`,{children:`Release`}),(0,X.jsxs)(`dl`,{className:`settings-release`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Version`}),(0,X.jsx)(`dd`,{children:r?.version||ab.version})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Channel`}),(0,X.jsx)(`dd`,{children:r?.channel||ab.channel})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Profile`}),(0,X.jsx)(`dd`,{children:r?.profile.id||`loading`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Environment`}),(0,X.jsx)(`dd`,{children:r?.profile.environment||`loading`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Binding`}),(0,X.jsx)(`dd`,{children:r?r.profile.bound?`bound`:`legacy unbound`:`loading`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Git`}),(0,X.jsx)(`dd`,{children:r?.git_sha||`not available`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Assets`}),(0,X.jsx)(`dd`,{className:`settings-path`,children:r?.asset_root||`loading`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`SQLite`}),(0,X.jsx)(`dd`,{className:`settings-path`,children:r?.database.path||`loading`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Database`}),(0,X.jsx)(`dd`,{children:r?.database.exists?`${r.database.projects??0} projects / ${r.database.workspaces??0} workspaces`:`not created yet`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Schema`}),(0,X.jsx)(`dd`,{children:r?`${r.schema.migration_keys.length} migration marker(s)`:`loading`})]})]})]}),(0,X.jsxs)(`section`,{"aria-label":`Lineage experience settings`,className:`settings-section`,children:[(0,X.jsx)(`h3`,{children:`Lineage experience`}),(0,X.jsx)(`div`,{className:`settings-grid`,children:(0,X.jsx)(`article`,{className:`settings-card`,children:(0,X.jsxs)(`div`,{className:`settings-card-head`,children:[(0,X.jsx)(`span`,{className:`settings-icon`,children:(0,X.jsx)(N,{size:19})}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h4`,{children:`Hover previews`}),(0,X.jsx)(`p`,{children:`Show the full asset and quick Branch/Re-roll/Details actions when hovering over or focusing a lineage node. Double-click details remain available when this is off.`})]}),(0,X.jsx)(fb,{checked:u,label:`Enable lineage hover previews`,onClick:f})]})})})]}),cb.map(e=>(0,X.jsxs)(`section`,{"aria-label":e.ariaLabel,className:`settings-section`,children:[(0,X.jsx)(`h3`,{children:sb[e.adapterType]}),(0,X.jsx)(`div`,{className:`settings-grid`,children:(t?.settings||[]).filter(t=>t.adapter_type===e.adapterType).map(e=>{let t=ob[e.adapter_type],n=`Enable ${e.label===`Buffer`?`Buffer scheduling`:e.label}`,r=c===`${e.adapter_type}:${e.provider}`;return(0,X.jsxs)(`article`,{className:`settings-card`,children:[(0,X.jsxs)(`div`,{className:`settings-card-head`,children:[(0,X.jsx)(`span`,{className:`settings-icon`,children:(0,X.jsx)(t,{size:19})}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h4`,{children:e.label}),(0,X.jsx)(`p`,{children:e.description})]}),(0,X.jsx)(fb,{checked:e.enabled,disabled:r,label:n,onClick:()=>void h(e)})]}),(0,X.jsxs)(`dl`,{className:`settings-meta`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Status`}),(0,X.jsxs)(`dd`,{className:db(e),children:[e.health_status===`configured`?(0,X.jsx)(w,{size:14}):(0,X.jsx)(C,{size:14}),e.health_status.replace(/_/g,` `)]})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Credential source`}),(0,X.jsx)(`dd`,{children:e.credential.label})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Secret ref`}),(0,X.jsx)(`dd`,{children:e.credential.secret_ref||`none`})]})]}),ub(e).length>0&&(0,X.jsx)(`div`,{className:`settings-config`,children:ub(e).map(([e,t])=>(0,X.jsxs)(`span`,{children:[(0,X.jsx)(`strong`,{children:e}),lb(t)]},e))})]},`${e.adapter_type}:${e.provider}`)})})]},e.adapterType)),a&&!t&&(0,X.jsx)(`div`,{className:`settings-loading`,children:`Loading settings...`})]})]})}var mb=`Lineage`,hb=`Local-first creative lineage workspace`;function gb(e){let{channel:t,channels:n,placementStatus:r,project:i,projects:a,setChannel:o,setPlacementStatus:s,setProject:c,setSource:l,setStatus:u,source:d,status:f}=e,[m,h]=(0,p.useState)(!1),[g,_]=(0,p.useState)(!0),v=a.length?a.map(e=>e.project):[i];return(0,X.jsxs)(`aside`,{className:`sidebar ${g?``:`collapsed`}`,children:[(0,X.jsx)(`button`,{"aria-label":g?`Collapse sidebar`:`Expand sidebar`,className:`sidebar-collapse-toggle`,onClick:()=>_(e=>!e),type:`button`,children:g?(0,X.jsx)(ne,{size:16}):(0,X.jsx)(re,{size:16})}),(0,X.jsxs)(`div`,{className:`brand`,children:[(0,X.jsx)(`div`,{className:`brand-mark`,"aria-label":hb,children:`L`}),(0,X.jsxs)(`div`,{className:`brand-copy`,children:[(0,X.jsx)(`h1`,{children:mb}),(0,X.jsxs)(`p`,{children:[(0,X.jsx)(`span`,{children:i}),(0,X.jsxs)(`span`,{"aria-label":`Lineage version ${ab.version}`,className:`brand-version`,title:`Lineage version ${ab.version}, ${ab.channel} channel`,children:[`v`,ab.version]})]})]})]}),(0,X.jsxs)(`button`,{"aria-controls":`mobile-sidebar-controls`,"aria-expanded":m,className:`mobile-filter-toggle`,onClick:()=>h(e=>!e),type:`button`,children:[(0,X.jsx)(G,{size:16}),`Filters`,(0,X.jsx)(S,{className:m?`open`:``,size:16})]}),(0,X.jsxs)(`div`,{className:`sidebar-mobile-collapse`,"data-open":m,id:`mobile-sidebar-controls`,children:[(0,X.jsxs)(`div`,{className:`side-section`,children:[(0,X.jsx)(`h2`,{children:`Project`}),(0,X.jsx)(_b,{id:`asset-project-filter`,label:`Project`,value:i,values:v,onChange:c})]}),(0,X.jsxs)(`section`,{className:`side-section`,children:[(0,X.jsx)(`h2`,{children:`Filters`}),(0,X.jsx)(_b,{id:`asset-source-filter`,label:`Source`,value:d,values:Y,onChange:e=>l(e)}),(0,X.jsx)(_b,{id:`asset-status-filter`,label:`Status`,value:f,values:J,onChange:e=>u(e)}),(0,X.jsx)(_b,{id:`asset-channel-filter`,label:`Channel`,value:t,values:n,onChange:o}),(0,X.jsx)(_b,{id:`asset-placement-filter`,label:`Placement`,value:r,values:he,onChange:e=>s(e)})]})]})]})}function _b({id:e,label:t,value:n,values:r,onChange:i}){return(0,X.jsxs)(`label`,{htmlFor:e,children:[t,(0,X.jsx)(`select`,{"aria-label":t,id:e,value:n,onChange:e=>i(e.target.value),children:r.map(e=>(0,X.jsx)(`option`,{value:e,children:e},e))})]})}var vb=[{label:`Lineage`,view:`lineage`},{label:`Review`,view:`review`},{label:`Assets`,view:`assets`},{label:`Agents`,view:`agents`},{label:`Settings`,view:`settings`}],yb=[{label:`Ledger`,view:`ledger`},{label:`Content batches`,view:`content`},{label:`Backup queue`,view:`backup`}];function bb(e){let t=yb.some(t=>t.view===e.view);function n(t){e.setView(t),e.onMoreOpenChange(!1)}function r(t){e.setView(t),e.onMoreOpenChange(!1)}return(0,X.jsxs)(`header`,{className:`topbar`,children:[(0,X.jsxs)(`div`,{className:`view-tabs`,role:`tablist`,"aria-label":`${mb} views`,children:[vb.map(t=>(0,X.jsx)(`button`,{"aria-pressed":e.view===t.view,className:e.view===t.view?`active`:``,onClick:()=>n(t.view),type:`button`,children:t.label},t.view)),(0,X.jsxs)(`div`,{className:`more-menu`,children:[(0,X.jsxs)(`button`,{"aria-expanded":e.moreOpen,"aria-haspopup":`menu`,"aria-pressed":t,className:t?`active`:``,onClick:()=>e.onMoreOpenChange(!e.moreOpen),type:`button`,children:[(0,X.jsx)(j,{size:16}),` More `,(0,X.jsx)(S,{className:e.moreOpen?`open`:``,size:15})]}),e.moreOpen&&(0,X.jsx)(`div`,{className:`more-menu-popover`,role:`menu`,children:yb.map(t=>(0,X.jsx)(`button`,{"aria-pressed":e.view===t.view,onClick:()=>r(t.view),role:`menuitem`,type:`button`,children:t.label},t.view))})]})]}),(0,X.jsx)(xb,{runtime:e.runtime,unavailable:e.runtimeIdentityUnavailable}),(0,X.jsxs)(`div`,{className:`searchbox`,children:[(0,X.jsx)(ae,{size:17}),(0,X.jsx)(`input`,{onChange:t=>e.setQuery(t.target.value),placeholder:`Search assets, campaigns, hooks`,value:e.query})]}),e.view!==`lineage`&&(0,X.jsxs)(`button`,{"aria-expanded":e.assetDetailsOpen,className:`secondary-button`,disabled:!e.canInspectAsset,onClick:()=>{e.onMoreOpenChange(!1),e.setAssetDetailsOpen(!e.assetDetailsOpen)},type:`button`,children:[(0,X.jsx)(I,{size:17}),`Details`]}),(0,X.jsx)(`button`,{className:`icon-button`,disabled:e.loading,onClick:()=>void e.refresh(),title:`Refresh current page`,children:e.loading?(0,X.jsx)(ee,{className:`spin`,size:18}):(0,X.jsx)(o,{size:18})}),(0,X.jsxs)(`button`,{className:`primary-button`,onClick:()=>e.setUploadOpen(!0),children:[(0,X.jsx)(ue,{size:17}),`Upload`]})]})}function xb(e){if(e.unavailable)return(0,X.jsx)(`div`,{"aria-label":`Lineage runtime identity unavailable`,className:`runtime-identity-badge unavailable`,children:`IDENTITY UNAVAILABLE`});if(!e.runtime)return(0,X.jsx)(`div`,{"aria-label":`Loading Lineage runtime identity`,className:`runtime-identity-badge loading`,children:`IDENTITY LOADING`});let{profile:t}=e.runtime,n=t.bound?``:` · UNBOUND`,r=[`${t.environment.toUpperCase()} profile ${t.id}${t.bound?``:` (unbound)`}`,`Channel ${e.runtime.channel}`,`Version ${e.runtime.version}`,t.warning].filter(Boolean).join(` · `);return(0,X.jsxs)(`div`,{"aria-label":`Lineage ${t.environment} profile ${t.id}${t.bound?``:` unbound`}`,className:`runtime-identity-badge ${t.environment} ${t.bound?`bound`:`unbound`}`,"data-profile-id":t.id,title:r,children:[(0,X.jsx)(`strong`,{children:t.environment.toUpperCase()}),(0,X.jsxs)(`span`,{children:[t.id,n]})]})}function Sb({toast:e,onDismiss:t}){return(0,X.jsxs)(`div`,{className:`toast ${e.type}`,role:`status`,children:[e.type===`ok`?(0,X.jsx)(w,{size:16}):(0,X.jsx)(se,{size:16}),(0,X.jsx)(`span`,{children:e.message}),(0,X.jsx)(`button`,{onClick:t,children:`Dismiss`})]})}var Cb=200*1024*1024;function wb({channels:e,project:t,onClose:n,onUploaded:r,onError:i}){let[a,o]=(0,p.useState)({assetId:``,audience:`short-form-creators`,campaign:`2026-06-organic-traffic-test`,channel:e[0]||`meta`,cta:``,hook:``,status:`working`,title:``,type:`image`,utmContent:``}),[s,c]=(0,p.useState)(null),[l,u]=(0,p.useState)(!1),[d,f]=(0,p.useState)(!1);function m(e,t){o(n=>({...n,[e]:t}))}function h(e){o(t=>({...t,assetId:t.assetId||pe(`demo-${t.channel}-${e}`),title:e,utmContent:t.utmContent||pe(e).replaceAll(`-`,`_`)}))}function _(e){if(!e){c(null);return}if(e.size>Cb){i(`File is larger than ${q(Cb)}`);return}c(e)}async function v(e){if(e.preventDefault(),!s)return i(`Choose a file before uploading`);f(!0);try{let e=new FormData;Object.entries({project:t,...a,confirmWrite:String(l)}).forEach(([t,n])=>e.append(t,n)),e.append(`file`,s),await r((await g(`/api/assets/upload`,{method:`POST`,body:e})).message)}catch(e){i(e instanceof Error?e.message:String(e))}finally{f(!1)}}return(0,X.jsx)(`div`,{className:`drawer-backdrop`,children:(0,X.jsxs)(`form`,{className:`upload-drawer`,onSubmit:v,children:[(0,X.jsxs)(`header`,{children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h2`,{children:`Upload asset`}),(0,X.jsx)(`p`,{children:t})]}),(0,X.jsx)(`button`,{type:`button`,onClick:n,children:`Close`})]}),(0,X.jsxs)(`label`,{className:`file-drop`,children:[(0,X.jsx)(ue,{size:20}),(0,X.jsx)(`span`,{children:s?s.name:`Choose creative export up to ${q(Cb)}`}),(0,X.jsx)(`input`,{type:`file`,onChange:e=>_(e.target.files?.[0])})]}),(0,X.jsxs)(`div`,{className:`form-grid`,children:[(0,X.jsxs)(`label`,{children:[`Title`,(0,X.jsx)(`input`,{value:a.title,onChange:e=>h(e.target.value),required:!0})]}),(0,X.jsxs)(`label`,{children:[`Asset ID`,(0,X.jsx)(`input`,{value:a.assetId,onChange:e=>m(`assetId`,e.target.value),required:!0})]}),(0,X.jsxs)(`label`,{children:[`Campaign`,(0,X.jsx)(`input`,{value:a.campaign,onChange:e=>m(`campaign`,e.target.value),required:!0})]}),(0,X.jsxs)(`label`,{children:[`Channel`,(0,X.jsx)(`select`,{value:a.channel,onChange:e=>m(`channel`,e.target.value),children:e.map(e=>(0,X.jsx)(`option`,{children:e},e))})]}),(0,X.jsxs)(`label`,{children:[`Audience`,(0,X.jsx)(`input`,{value:a.audience,onChange:e=>m(`audience`,e.target.value),required:!0})]}),(0,X.jsxs)(`label`,{children:[`Status`,(0,X.jsxs)(`select`,{value:a.status,onChange:e=>m(`status`,e.target.value),children:[(0,X.jsx)(`option`,{children:`working`}),(0,X.jsx)(`option`,{children:`published`})]})]}),(0,X.jsxs)(`label`,{children:[`Type`,(0,X.jsx)(`select`,{value:a.type,onChange:e=>m(`type`,e.target.value),children:ge.map(e=>(0,X.jsx)(`option`,{children:e},e))})]}),(0,X.jsxs)(`label`,{children:[`UTM content`,(0,X.jsx)(`input`,{value:a.utmContent,onChange:e=>m(`utmContent`,e.target.value),required:!0})]}),(0,X.jsxs)(`label`,{className:`wide`,children:[`Hook`,(0,X.jsx)(`input`,{value:a.hook,onChange:e=>m(`hook`,e.target.value)})]}),(0,X.jsxs)(`label`,{className:`wide`,children:[`CTA`,(0,X.jsx)(`input`,{value:a.cta,onChange:e=>m(`cta`,e.target.value),required:!0})]})]}),(0,X.jsxs)(`label`,{className:`confirm-line`,children:[(0,X.jsx)(`input`,{type:`checkbox`,checked:l,onChange:e=>u(e.target.checked)}),(0,X.jsx)(`span`,{children:`Confirm write to the production asset bucket`})]}),(0,X.jsxs)(`footer`,{children:[(0,X.jsx)(`button`,{type:`button`,onClick:n,children:`Cancel`}),(0,X.jsxs)(`button`,{className:`primary-button`,disabled:d||!l,children:[d?(0,X.jsx)(ee,{className:`spin`,size:16}):(0,X.jsx)(ue,{size:16}),`Upload`]})]})]})})}function Tb(e,t){let n=`${e} ${t}`.toLowerCase();return n.includes(`agent`)||n.includes(`command`)||n.includes(`selection`)||n.includes(`next context`)}function Eb(){return typeof window>`u`?me:new URLSearchParams(window.location.search).get(`project`)||`demo-project`}function Db(){let[e,t]=(0,p.useState)(null),[n,r]=(0,p.useState)(null),[i,a]=(0,p.useState)(Eb),[o,s]=(0,p.useState)([]),[c,l]=(0,p.useState)(`all`),[u,d]=(0,p.useState)(`all`),[f,m]=(0,p.useState)(`local`),[h,y]=(0,p.useState)(`all`),[b,x]=(0,p.useState)(``),[S,C]=(0,p.useState)(1),[w,T]=(0,p.useState)(10),[E,D]=(0,p.useState)(!1),[O,k]=(0,p.useState)(!0),[A,j]=(0,p.useState)(null),[M,N]=(0,p.useState)(null),[P,F]=(0,p.useState)({}),[I,L]=(0,p.useState)({}),[R,z]=(0,p.useState)([]),[B,V]=(0,p.useState)([]),[H,U]=(0,p.useState)(!1),[W,ee]=(0,p.useState)(!1),[te,ne]=(0,p.useState)(`lineage`),[re,ie]=(0,p.useState)(!1),[ae,oe]=(0,p.useState)(null),[se,G]=(0,p.useState)(0),[ce,le]=(0,p.useState)(null),[K,ue]=(0,p.useState)(!1),[de,q]=(0,p.useState)(null),fe=(0,p.useCallback)(e=>{q(t=>e?`lineage-actions`:t===`lineage-actions`?null:t)},[]),pe=(0,p.useCallback)(e=>{q(t=>e?`topbar-more`:t===`topbar-more`?null:t)},[]),me=(0,p.useCallback)((e,t)=>{j({type:e,message:t})},[]),J=e?.catalog.project===i?e:null,he=J?.assets||[],Y=xe(he,n)||(ae?.project===i&&ae.asset_id===n?ae:void 0),ge=Y?.asset_id||``,_e=[...B.filter(e=>R.includes(e.asset_id)),...he.filter(e=>R.includes(e.asset_id)&&e.local?.relative_path)].filter((e,t,n)=>n.findIndex(t=>t.asset_id===e.asset_id)===t),ve=Y&&P[Y.asset_id]||null,ye=(0,p.useMemo)(()=>[`all`,...J?.facets.channels||[]],[J]),be=(0,p.useMemo)(()=>({assets:J?.catalog.asset_count||0,live:J?.liveObjects.length||0,orphan:J?.orphanObjects.length||0,size:J?.facets.totalSizeBytes||0}),[J]);async function Ce(){try{let e=await g(`/api/projects`);s(e.projects),a(t=>e.projects.some(e=>e.project===t)?t:e.projects[0]?.project||`demo-project`)}catch(e){j({type:`error`,message:e instanceof Error?e.message:String(e)})}}async function we(){try{let e=await g(`/api/runtime`);le(e.runtime),ue(!1)}catch{le(null),ue(!0)}}async function Te(){k(!0);try{let e=await g(`/api/assets?${Ee()}`);t(e),r(t=>xe(e.assets,t)?.asset_id||(t&&ae?.asset_id===t?t:null)),F({}),L({})}catch(e){j({type:`error`,message:e instanceof Error?e.message:String(e)})}finally{k(!1)}}function Ee(){let e=new URLSearchParams({project:i,page:String(S),pageSize:String(w),live:String(E),source:f});return c!==`all`&&e.set(`status`,c),u!==`all`&&e.set(`placementStatus`,u),h!==`all`&&e.set(`channel`,h),b.trim()&&e.set(`q`,b.trim()),e.toString()}async function De(e){try{let t=await e();j({type:`ok`,message:t.message}),F({}),await Te()}catch(e){j({type:`error`,message:e instanceof Error?e.message:String(e)})}}async function Oe(e,t={}){if(!Se(e))return null;let n=P[e.asset_id];if(n)return t.open&&window.open(n,`_blank`,`noopener,noreferrer`),n;if(e.local?.relative_path){let n=`/api/assets/local-preview?${new URLSearchParams({project:i,path:e.local.relative_path}).toString()}`;return F(t=>({...t,[e.asset_id]:n})),L(t=>({...t,[e.asset_id]:``})),t.open&&window.open(n,`_blank`,`noopener,noreferrer`),n}try{let n=await g(`/api/assets/presign`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:i,assetId:e.asset_id,expiresIn:900})});return F(t=>({...t,[e.asset_id]:n.url})),L(t=>({...t,[e.asset_id]:``})),t.open&&window.open(n.url,`_blank`,`noopener,noreferrer`),n.url}catch(n){let r=n instanceof Error?n.message:String(n);return L(t=>({...t,[e.asset_id]:r})),t.quiet||j({type:`error`,message:`Preview unavailable. Check S3 credentials or pull the asset locally.`}),null}}async function ke(e,t){try{let n=await Bm(e);j({type:`ok`,message:n.method===`fallback`?`Copied ${t} using browser fallback`:`Copied ${t}`}),N(Tb(t,e)?{label:t,text:e}:null)}catch(n){N(Tb(t,e)?{label:t,text:e}:null),j({type:`error`,message:n instanceof Error?n.message:String(n)})}}async function je(e){let t=await Oe(e,{quiet:!0});t&&await ke(t,`preview link`)}function Ne(e){e.local?.relative_path&&(z(t=>t.includes(e.asset_id)?t:[...t,e.asset_id]),V(t=>t.some(t=>t.asset_id===e.asset_id)?t:[...t,e]))}function Z(e){oe(e),r(e.asset_id),ie(!0)}async function Pe(e){r(e),ie(!0);let t=he.find(t=>t.asset_id===e);if(t){oe(t);return}try{let t=await g(`/api/assets/lookup`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:i,assetIds:[e]})});t.assets[0]&&oe(t.assets[0])}catch(e){j({type:`error`,message:e instanceof Error?e.message:String(e)})}}function Fe(){m(`local`),l(`all`),d(`all`),x(``),ne(`backup`)}async function Ie(e){try{e.assetId&&r(e.assetId),e.view===`lineage`&&e.workspaceId&&await g(`/api/lineage-workspaces/${encodeURIComponent(e.workspaceId)}/activate`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:i,confirmWrite:!0})}),ie(!1),ne(e.view),j({type:`ok`,message:`Opened ${e.claim.target_title||e.claim.target_id}`})}catch(e){j({type:`error`,message:e instanceof Error?e.message:String(e)})}}function Le(e){e.local?.relative_path&&(z(t=>t.includes(e.asset_id)?t.filter(t=>t!==e.asset_id):[...t,e.asset_id]),V(t=>t.filter(t=>t.asset_id!==e.asset_id)))}return(0,p.useEffect)(()=>{Ce(),we()},[]),(0,p.useEffect)(()=>{let e=new URLSearchParams(window.location.search);e.get(`project`)!==i&&(e.set(`project`,i),window.history.replaceState(null,``,`${window.location.pathname}?${e.toString()}${window.location.hash}`))},[i]),(0,p.useEffect)(()=>{j(null),N(null),oe(null),ie(!1)},[i]),(0,p.useEffect)(()=>{Te()},[S,w,i,c,u,f,h,b,E]),(0,p.useEffect)(()=>{C(1)},[i,c,u,f,h,b,w]),(0,p.useEffect)(()=>{!Se(Y)||P[Y.asset_id]||Oe(Y,{quiet:!0})},[Y?.asset_id,Y?.s3?.version_id,P]),(0,p.useEffect)(()=>{if(A?.type!==`ok`)return;let e=window.setTimeout(()=>j(null),2600);return()=>window.clearTimeout(e)},[A?.message,A?.type]),(0,p.useEffect)(()=>{te===`backup`&&(m(`local`),l(`all`),d(`all`))},[te]),(0,p.useEffect)(()=>{q(null)},[te]),(0,p.useEffect)(()=>{ge||ie(!1)},[ge]),(0,X.jsx)(Me,{runtime:ce,children:(0,X.jsxs)(`div`,{className:`app-shell ${te===`lineage`?`lineage-mode`:``}`,children:[(0,X.jsx)(gb,{channel:h,channels:ye,liveSync:E,placementStatus:u,project:i,projects:o,setChannel:y,setPlacementStatus:d,setProject:a,setSource:m,setStatus:l,setView:ne,showBackupQueue:Fe,source:f,snapshot:J,status:c,totals:be}),(0,X.jsxs)(`main`,{className:`workspace`,children:[(0,X.jsx)(bb,{assetDetailsOpen:re,canInspectAsset:!!Y,loading:O,moreOpen:de===`topbar-more`,onMoreOpenChange:pe,query:b,refresh:Te,runtime:ce,runtimeIdentityUnavailable:K,setAssetDetailsOpen:ie,setQuery:x,setUploadOpen:ee,setView:e=>e===`backup`?Fe():ne(e),view:te}),A&&(0,X.jsx)(Sb,{toast:A,onDismiss:()=>j(null)}),M&&(0,X.jsx)(Ct,{copiedText:M,onDismiss:()=>N(null)}),(0,X.jsx)(Ot,{onCopy:ke,project:i,refreshKey:se,selectedAsset:Y,view:te}),te===`review`?(0,X.jsx)(Yy,{channel:h,onCopy:ke,onLocalReview:async(e,t)=>{await De(()=>_(`/api/local-review/${e.asset_id}`,i,{reviewState:t,confirmWrite:!0}))},onOpenBackup:e=>{Ne(e),U(!0)},onSelectAsset:e=>{Z(e)},project:i,selected:Y}):te===`ledger`?(0,X.jsx)(Vt,{project:i,query:b,onOpenAsset:Pe}):te===`content`?(0,X.jsx)(_t,{onCopy:ke,onOpenAsset:Pe,onToast:me,onWorkTargetsChanged:()=>G(e=>e+1),project:i,selectedAsset:Y}):te===`agents`?(0,X.jsx)(ze,{onCopy:ke,onOpenWork:Ie,project:i}):te===`backup`?(0,X.jsx)(zy,{assets:he,cli:ce?.cli,onCopy:ke,onLocalReview:async(e,t)=>{await De(()=>_(`/api/local-review/${e.asset_id}`,i,{reviewState:t,confirmWrite:!0}))},onOpenBackup:()=>U(!0),onQueueBackup:Ne,onSelectAsset:e=>{Z(e)},page:S,pageSize:w,project:i,selected:Y,selectedBackupIds:R,setPage:C,setPageSize:T,snapshot:J}):te===`assets`?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Gy,{assets:_e,onClear:()=>{z([]),V([])},onOpen:()=>U(!0)}),(0,X.jsx)(Re,{assets:he,liveSync:E,onCopy:ke,onSelectionChanged:()=>G(e=>e+1),page:S,pageSize:w,previewUrls:P,project:i,selected:Y,setLiveSync:D,setPage:C,setPageSize:T,setSelectedId:r,snapshot:J,source:f,totals:be})]}):te===`settings`?(0,X.jsx)(pb,{onToast:me,project:i}):(0,X.jsx)(jy,{asset:Y,actionsOpen:de===`lineage-actions`,onAssetsChanged:Te,onActionsOpenChange:fe,onSelectedAsset:r,onToast:me,project:i})]}),te!==`lineage`&&re&&(0,X.jsx)(Ae,{asset:Y,onArchive:e=>void De(()=>_(`/api/assets/archive`,i,{assetId:e.asset_id,confirmArchive:!0})),onClose:()=>ie(!1),onCopy:(e,t)=>void ke(e,t),onCopyPreview:e=>void je(e),onDelete:(e,t)=>void De(()=>_(`/api/assets/delete-object`,i,{assetId:e.asset_id,confirmation:t})),onPlacement:(e,t,n)=>void De(()=>_(`/api/assets/placement`,i,{assetId:e.asset_id,channel:e.channel,...v(n),status:t,confirmWrite:!0})),onPresign:e=>void Oe(e,{open:!0}),onPromote:e=>void De(()=>_(`/api/assets/promote`,i,{assetId:e.asset_id,confirmWrite:!0})),onPull:e=>void De(()=>_(`/api/assets/pull`,i,{assetId:e.asset_id,out:`.asset-scratch`})),onToggleBackup:Le,previewError:Y&&I[Y.asset_id]||null,previewUrl:ve,selectedForBackup:Y?R.includes(Y.asset_id):!1}),W&&(0,X.jsx)(wb,{channels:ye.filter(e=>e!==`all`),project:i,onClose:()=>ee(!1),onError:e=>j({type:`error`,message:e}),onUploaded:async e=>{j({type:`ok`,message:e}),ee(!1),await Te()}}),H&&(0,X.jsx)(Py,{assets:_e,project:i,onClose:()=>U(!1),onError:e=>j({type:`error`,message:e}),onDone:async e=>{j({type:`ok`,message:e}),z([]),V([]),U(!1),await Te()}})]})})}(0,m.createRoot)(document.getElementById(`root`)).render((0,X.jsx)(p.StrictMode,{children:(0,X.jsx)(Db,{})}));
|