@mean-weasel/lineage 0.1.12 → 0.1.14
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 +12 -0
- package/README.md +152 -56
- package/dist/cli/lineage-channel.js +303 -0
- package/dist/cli/lineage-channel.js.map +7 -0
- package/dist/cli/lineage-dev.js +900 -220
- package/dist/cli/lineage-dev.js.map +4 -4
- package/dist/cli/lineage-preview.js +6182 -0
- package/dist/cli/lineage-preview.js.map +7 -0
- package/dist/cli/lineage.js +891 -216
- package/dist/cli/lineage.js.map +4 -4
- package/dist/cli/managed-service.js +430 -0
- package/dist/cli/managed-service.js.map +7 -0
- package/dist/runtime-build.json +9 -0
- package/dist/server.js +452 -164
- package/dist/server.js.map +4 -4
- package/dist/web/assets/{index-OkymIyPO.js → index-DJ5UR_oa.js} +1 -1
- package/dist/web/index.html +1 -1
- package/package.json +22 -9
|
@@ -20,4 +20,4 @@ Error generating stack: `+e.message+`
|
|
|
20
20
|
`),p=e=>e===`variation source`?`Copy source`:e===`agent brief`?`Copy prompt`:e===`link-child command`?`Copy link command`:`Copy command`,m=ah(i,o);async function h(e,t){try{await Bm(e),r(`ok`,`Copied ${t}`)}catch(e){r(`error`,e instanceof Error?e.message:String(e))}}async function g(){try{let n=await v(`/api/agent-claims`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({agentName:`Copied Lineage handoff`,channel:t?.channel,project:i,scopeType:`lineage_workspace`,targetId:m,targetTitle:t?`${t.title} lineage`:`Lineage workspace ${o}`,ttl:`20m`})});await Bm(uh(n.claim_token,s,e,f)),r(`ok`,`Copied claim-aware handoff for ${n.claim.id}`)}catch(e){r(`error`,e instanceof Error?e.message:String(e))}}return(0,W.jsxs)(`section`,{className:`lineage-handoff-panel`,"data-testid":`lineage-handoff-panel`,children:[(0,W.jsx)(`h3`,{children:`Agent handoff`}),(0,W.jsxs)(`div`,{className:`lineage-handoff-base ${t&&!t.is_latest?`branch`:``}`,children:[(0,W.jsx)(`span`,{children:t?`Agent will evolve`:`Choose a variation source`}),(0,W.jsx)(`strong`,{children:l}),t&&(0,W.jsx)(`small`,{children:[t.channel,t.status,t.review_state].filter(Boolean).join(` / `)}),t&&!t.is_latest&&(0,W.jsx)(`p`,{children:`Branch from here: this asset is not a latest leaf.`})]}),u.map(e=>(0,W.jsxs)(`div`,{className:`lineage-copy-row`,children:[(0,W.jsx)(`code`,{children:e.text}),(0,W.jsx)(`button`,{"aria-label":`Copy ${e.label}`,onClick:()=>void h(e.text,e.label),children:p(e.label)})]},e.label)),a.length>0&&(0,W.jsxs)(`div`,{className:`lineage-brief-group`,children:[(0,W.jsxs)(`div`,{className:`lineage-brief-head`,children:[(0,W.jsx)(`h4`,{children:`Re-roll queue`}),(0,W.jsx)(`button`,{"aria-label":`Copy re-roll queue handoff`,onClick:()=>void h(ih(c,a),`re-roll queue`),children:`Copy queue`})]}),(0,W.jsx)(`p`,{children:`Use this for repair work. Import outputs with reroll import; do not link them as lineage children.`}),(0,W.jsxs)(`div`,{className:`lineage-copy-row`,children:[(0,W.jsx)(`code`,{children:c}),(0,W.jsx)(`button`,{"aria-label":`Copy reroll list command`,onClick:()=>void h(c,`reroll list command`),children:`Copy command`})]}),a.map(e=>(0,W.jsxs)(`div`,{className:`lineage-copy-row`,children:[(0,W.jsxs)(`code`,{children:[e.asset_id,e.reroll_request?.notes?`: ${e.reroll_request.notes}`:``]}),(0,W.jsx)(`button`,{"aria-label":`Copy re-roll target ${e.asset_id}`,onClick:()=>void h(e.asset_id,`re-roll target`),children:`Copy target`})]},e.asset_id))]}),d.length>0&&(0,W.jsxs)(`div`,{className:`lineage-brief-group`,children:[(0,W.jsxs)(`div`,{className:`lineage-brief-head`,children:[(0,W.jsx)(`h4`,{children:`Generated brief`}),(0,W.jsx)(`button`,{"aria-label":`Copy full generated brief`,onClick:()=>void h(f,`full brief`),children:`Copy all`})]}),(0,W.jsx)(`p`,{children:`Use this bundle when asking an agent to continue from the chosen asset.`}),(0,W.jsx)(`button`,{"aria-label":`Copy claim-aware handoff`,className:`lineage-claim-handoff-button`,onClick:()=>g(),children:`Copy claim handoff`}),(0,W.jsxs)(`details`,{children:[(0,W.jsx)(`summary`,{children:`Commands and prompt`}),d.map(e=>(0,W.jsxs)(`div`,{className:`lineage-copy-row`,children:[(0,W.jsx)(`code`,{children:e.text}),(0,W.jsx)(`button`,{"aria-label":`Copy ${e.label}`,onClick:()=>void h(e.text,e.label),children:p(e.label)})]},e.label))]})]}),(0,W.jsx)(`button`,{"aria-label":d.length>0?`Regenerate agent brief`:`Generate agent brief`,onClick:n,children:d.length>0?`Regenerate brief`:`Generate brief`})]})}function ih(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(`
|
|
21
21
|
`)}function ah(e,t){return`${e}:lineage-workspace:${t}`}function oh(e){return`'${e.replace(/'/g,`'\\''`)}'`}function sh(e){let t=/\s--(db|profile)\s+('[^']*(?:'\\''[^']*)*'|"[^"]*"|\S+)/.exec(e);return t?` --${t[1]} ${t[2]}`:``}function ch(e){let t=/\s(?:next|inspect|link-child)\s/.exec(e);return t?e.slice(0,t.index):`npx @mean-weasel/lineage`}function lh(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 uh(e,t,n,r){let i=n?.handoff?.link_child_command||n?.handoff?.next_command||t,a=sh(i),o=`${ch(i)} agent heartbeat --claim-token "$LINEAGE_CLAIM_TOKEN"${a} --json`;return[`export LINEAGE_CLAIM_TOKEN=${oh(e)}`,o,t,n?.handoff?.inspect_command,n?.handoff?.link_child_command?lh(n.handoff.link_child_command):void 0,r?`Agent brief:\n${r}`:void 0].filter(e=>!!e).join(`
|
|
22
22
|
|
|
23
|
-
`)}function dh(e){let{activeNode:t,brief:n,childAssetId:r,clearNextVariation:i,closePanel:a,latestNodes:o,linkChild:s,markReview:c,noteDirty:l,onSelectedAsset:u,nextVariationLimit:d,onToast:f,project:p,refreshBrief:m,saveRationale:h,selectNextBase:g,selectedNode:_,selectedNodes:v,selectionFull:y,refreshLineage:b,replaceNextVariation:x,selectionNote:S,setActiveNodeId:C,setChildAssetId:w,setDetailNodeId:T,setSelected:E,setSelectionNote:D,sideOpen:O,snapshot:k}=e,A=t?Le({hasLocal:!!t.local_path,hasS3:!!t.s3_key}):null,j=v.filter(e=>!e.is_latest),M=k.nodes.filter(e=>e.reroll_request?.status===`pending`);return(0,W.jsxs)(`aside`,{"aria-hidden":!O,className:`lineage-side ${O?``:`collapsed`}`,id:`lineage-selection-panel`,children:[(0,W.jsxs)(`div`,{className:`lineage-side-head`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h3`,{children:`Next variation`}),(0,W.jsx)(`p`,{className:`muted-copy`,children:`Choose what the agent will evolve next; double-click nodes for full details.`})]}),(0,W.jsx)(`button`,{"aria-label":`Close lineage selection panel`,className:`icon-button`,onClick:a,type:`button`,children:`×`})]}),(0,W.jsxs)(`section`,{className:`lineage-next-panel`,children:[(0,W.jsxs)(`div`,{className:`lineage-panel-title-row`,children:[(0,W.jsx)(`h3`,{children:`Using for next variation`}),(0,W.jsxs)(`span`,{className:`lineage-count-pill ${y?`full`:``}`,children:[v.length,`/`,d]})]}),v.length>0&&(0,W.jsx)(`div`,{className:`lineage-panel-action-row`,children:(0,W.jsx)(`button`,{onClick:()=>void i(),type:`button`,children:`Clear all`})}),j.length>0&&(0,W.jsxs)(`div`,{className:`lineage-selection-warning`,role:`status`,children:[j.length,` selected asset`,j.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.`]}),v.length>0?v.map(e=>(0,W.jsxs)(`div`,{className:`lineage-candidate selected`,children:[(0,W.jsxs)(`button`,{"aria-label":`Inspect asset used for next variation ${e.title}`,className:`lineage-candidate-main`,onClick:()=>{C(e.asset_id),u(e.asset_id)},children:[(0,W.jsx)(`span`,{children:e.title}),(0,W.jsx)(`code`,{children:e.asset_id}),(0,W.jsx)(nh,{node:e})]}),!e.is_latest&&(0,W.jsx)(`span`,{className:`lineage-candidate-warning`,children:`Not latest`}),(0,W.jsxs)(`div`,{className:`lineage-candidate-actions`,children:[v.length>1&&(0,W.jsx)(`button`,{className:`lineage-candidate-action secondary`,onClick:()=>x(e),children:`Use only this`}),(0,W.jsx)(`button`,{className:`lineage-candidate-action remove`,onClick:()=>void i(e.asset_id),children:`Remove`})]})]},e.asset_id)):(0,W.jsxs)(`p`,{className:`muted-copy`,children:[`Choose up to `,d,` assets to guide the next generation.`]}),v.length>1&&(0,W.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,W.jsx)(fh,{activeNode:t,onSelectedAsset:u,onToast:f,project:p,refreshLineage:b,setActiveNodeId:C,snapshot:k}),(0,W.jsxs)(`section`,{className:`lineage-next-panel`,children:[(0,W.jsxs)(`div`,{className:`lineage-panel-title-row`,children:[(0,W.jsx)(`h3`,{children:`Re-roll queue`}),(0,W.jsx)(`span`,{className:`lineage-count-pill`,children:M.length})]}),M.length>0?M.map(e=>(0,W.jsx)(`div`,{className:`lineage-candidate ${e.asset_id===t?.asset_id?`active`:``}`,children:(0,W.jsxs)(`button`,{"aria-label":`Inspect re-roll target ${e.title}`,className:`lineage-candidate-main`,onClick:()=>{C(e.asset_id),u(e.asset_id)},children:[(0,W.jsx)(`span`,{children:e.title}),(0,W.jsx)(`code`,{children:e.asset_id}),e.reroll_request?.notes&&(0,W.jsx)(`small`,{children:e.reroll_request.notes})]})},e.asset_id)):(0,W.jsx)(`p`,{className:`muted-copy`,children:`No pending re-roll targets.`})]}),(0,W.jsxs)(`section`,{className:`lineage-next-panel`,children:[(0,W.jsx)(`h3`,{children:`Latest candidates`}),o.length>0?o.map(e=>{let n=!e.user_selected&&y;return(0,W.jsxs)(`div`,{className:`lineage-candidate ${e.asset_id===t?.asset_id?`active`:``} ${e.user_selected?`selected`:``}`,children:[(0,W.jsxs)(`button`,{"aria-label":`Inspect ${e.title}`,className:`lineage-candidate-main`,onClick:()=>{C(e.asset_id),u(e.asset_id)},children:[(0,W.jsx)(`span`,{children:e.title}),(0,W.jsx)(`code`,{children:e.asset_id}),(0,W.jsx)(nh,{node:e})]}),(0,W.jsxs)(`div`,{className:`lineage-candidate-actions`,children:[(0,W.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:n,onClick:()=>e.user_selected?void i(e.asset_id):g(e),children:e.user_selected?`Remove`:n?`Selection full`:`Use for next variation`}),!e.user_selected&&v.length>0&&(0,W.jsx)(`button`,{className:`lineage-candidate-action secondary`,onClick:()=>x(e),children:`Replace selection`})]})]},e.asset_id)}):(0,W.jsx)(`p`,{className:`muted-copy`,children:`No latest leaves yet.`})]}),(0,W.jsx)(rh,{brief:n,nextBase:_,onRefreshBrief:()=>void m(),onToast:f,project:p,rerollTargets:M,rootAssetId:k.root_asset_id}),(0,W.jsx)(`h3`,{children:`Inspecting`}),t?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`strong`,{children:t.title}),(0,W.jsx)(`code`,{children:t.asset_id}),(0,W.jsxs)(`dl`,{children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`dt`,{children:`Storage`}),(0,W.jsx)(`dd`,{children:A&&(0,W.jsx)(`span`,{className:`storage-chip ${A.kind}`,children:A.label})})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`dt`,{children:`Source`}),(0,W.jsx)(`dd`,{children:t.source})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`dt`,{children:`Review`}),(0,W.jsx)(`dd`,{children:t.review_state})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`dt`,{children:`Latest`}),(0,W.jsx)(`dd`,{children:t.is_latest?`yes`:`no`})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`dt`,{children:`Next variation`}),(0,W.jsx)(`dd`,{children:t.user_selected?`yes`:`no`})]})]}),t.user_selected&&!t.is_latest&&(0,W.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,W.jsxs)(`label`,{className:`lineage-note-field`,children:[`Variation rationale`,(0,W.jsx)(`textarea`,{value:S,onChange:e=>D(e.target.value),placeholder:`Why should the next generation branch from this asset?`}),(0,W.jsx)(`span`,{className:`lineage-note-status ${l?`dirty`:``}`,children:t.user_selected?l?`Unsaved rationale`:`Rationale saved for next variation`:`Rationale saves when this is used for next variation`})]}),(0,W.jsxs)(`div`,{className:`lineage-side-actions`,children:[(0,W.jsx)(`button`,{"aria-label":t.user_selected?`Remove ${t.title} from next variation`:`Use ${t.title} for next variation`,className:`primary-lite`,disabled:!t.user_selected&&y,onClick:()=>t.user_selected?void i(t.asset_id):E(),children:t.user_selected?`Remove from next variation`:y?`Selection full`:`Use for next variation`}),t.user_selected&&v.length>1&&(0,W.jsx)(`button`,{onClick:()=>x(t,S),children:`Use only this`}),!t.user_selected&&v.length>0&&(0,W.jsx)(`button`,{onClick:()=>x(t,S),children:`Replace selection`}),(0,W.jsx)(`button`,{disabled:!t.user_selected||!l,onClick:h,children:`Save rationale`}),(0,W.jsx)(`button`,{"aria-label":`Open detail for ${t.title}`,onClick:()=>T(t.asset_id),children:`Open detail`}),(0,W.jsx)(`button`,{"aria-label":`Approve ${t.title}`,onClick:()=>void c(`approved`),children:`Approve`}),(0,W.jsx)(`button`,{"aria-label":`Reject ${t.title}`,onClick:()=>void c(`rejected`),children:`Reject`}),(0,W.jsx)(`button`,{"aria-label":`Ignore ${t.title}`,onClick:()=>void c(`ignored`),children:`Ignore`})]}),(0,W.jsxs)(`form`,{className:`lineage-link-form`,onSubmit:e=>{e.preventDefault(),s()},children:[(0,W.jsxs)(`label`,{children:[`Child asset ID`,(0,W.jsx)(`input`,{value:r,onChange:e=>w(e.target.value),placeholder:`local-... or catalog id`})]}),(0,W.jsx)(`button`,{disabled:!r.trim(),type:`submit`,children:`Link child`})]})]}):(0,W.jsx)(`p`,{className:`muted-copy`,children:`No lineage node selected.`})]})}function fh({activeNode:e,onSelectedAsset:t,onToast:n,project:r,refreshLineage:i,setActiveNodeId:a,snapshot:o}){let s=(0,g.useMemo)(()=>hh(o.tasks||[]),[o.tasks]),c=s.filter(e=>gh(e)).length,l=(0,g.useMemo)(()=>new Map(o.nodes.map(e=>[e.asset_id,e])),[o.nodes]);return(0,W.jsxs)(`section`,{className:`lineage-next-panel lineage-task-queue-panel`,children:[(0,W.jsxs)(`div`,{className:`lineage-panel-title-row`,children:[(0,W.jsx)(`h3`,{children:`Task queue`}),(0,W.jsx)(`span`,{className:`lineage-count-pill`,children:c})]}),s.length>0?s.map(o=>(0,W.jsx)(ph,{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,W.jsx)(`p`,{className:`muted-copy`,children:`No open lineage tasks.`})]})}function ph({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,g.useState)(o.instructions||``),[d,f]=(0,g.useState)(``),[p,m]=(0,g.useState)(!1);(0,g.useEffect)(()=>u(o.instructions||``),[o.id,o.instructions]);async function h(e,t,n){m(!0);try{return await v(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{m(!1)}}async function _(e){e.preventDefault(),await h(`/api/lineage/tasks/${encodeURIComponent(o.id)}/instructions`,{instructions:l},`Updated ${vh(o)} instructions`)}async function y(e){e.preventDefault();let t=d.trim();t&&await h(`/api/lineage/tasks/${encodeURIComponent(o.id)}/comment`,{actor:`human`,message:t},`Commented on ${vh(o)}`)&&f(``)}async function b(){window.confirm(`Unlock ${vh(o)} for human edits?`)&&await h(`/api/lineage/tasks/${encodeURIComponent(o.id)}/override`,{actor:`human`,reason:`Human unlocked task from lineage UI.`},`Unlocked ${vh(o)}`)}async function x(){window.confirm(s?`Cancel ${vh(o)} while an agent is working?`:`Cancel ${vh(o)}?`)&&await h(`/api/lineage/tasks/${encodeURIComponent(o.id)}/cancel`,{actor:`human`,confirmWrite:!0,override:s},`Cancelled ${vh(o)}`)}return(0,W.jsxs)(`article`,{className:`lineage-task-card ${e?`active`:``} ${s?`locked`:o.status}`,children:[(0,W.jsxs)(`button`,{"aria-label":`Inspect task target ${t?.title||o.target_asset_id}`,className:`lineage-task-target`,onClick:n,type:`button`,children:[(0,W.jsx)(`span`,{children:t?.title||o.target_asset_id}),(0,W.jsx)(`code`,{children:o.target_asset_id})]}),(0,W.jsxs)(`div`,{className:`lineage-task-meta`,children:[(0,W.jsx)(`span`,{className:`lineage-task-status ${o.status}`,children:_h(o.status)}),(0,W.jsx)(`span`,{children:o.task_type})]}),c?(0,W.jsxs)(`form`,{className:`lineage-task-form`,onSubmit:_,children:[(0,W.jsxs)(`label`,{children:[`Instructions`,(0,W.jsx)(`textarea`,{"aria-label":`Instructions for ${o.id}`,value:l,onChange:e=>u(e.target.value)})]}),(0,W.jsxs)(`div`,{className:`lineage-task-actions`,children:[(0,W.jsx)(`button`,{disabled:p||l===(o.instructions||``),type:`submit`,children:`Save instructions`}),(0,W.jsx)(`button`,{disabled:p,onClick:x,type:`button`,children:`Cancel`})]})]}):(0,W.jsxs)(`div`,{className:`lineage-task-locked-body`,children:[(0,W.jsxs)(`label`,{children:[`Instructions`,(0,W.jsx)(`textarea`,{"aria-label":`Locked instructions for ${o.id}`,disabled:!0,readOnly:!0,value:l||`No instructions.`})]}),s&&(0,W.jsx)(mh,{claim:o.active_claim}),s&&(0,W.jsxs)(`form`,{className:`lineage-task-form`,onSubmit:y,children:[(0,W.jsxs)(`label`,{children:[`Comment`,(0,W.jsx)(`textarea`,{"aria-label":`Comment for ${o.id}`,value:d,onChange:e=>f(e.target.value)})]}),(0,W.jsxs)(`div`,{className:`lineage-task-actions`,children:[(0,W.jsx)(`button`,{disabled:p||!d.trim(),type:`submit`,children:`Add comment`}),(0,W.jsx)(`button`,{disabled:p,onClick:b,type:`button`,children:`Unlock`}),(0,W.jsx)(`button`,{disabled:p,onClick:x,type:`button`,children:`Cancel`})]})]})]})]})}function mh({claim:e}){return e?(0,W.jsxs)(`p`,{className:`lineage-task-claim ${e.derived_state===`active`?`active`:e.derived_state}`,children:[(0,W.jsxs)(`span`,{children:[_h(e.derived_state),` claim`]}),(0,W.jsx)(`strong`,{children:e.agent_name})]}):(0,W.jsx)(`p`,{className:`lineage-task-claim`,children:`Claimed by agent`})}function hh(e){return[...e].sort((e,t)=>{let n=+!gh(e),r=+!gh(t);return n===r?e.created_at.localeCompare(t.created_at):n-r})}function gh(e){return e.status===`pending`||e.status===`claimed`||e.status===`in_progress`}function _h(e){return e.replace(/_/g,` `)}function vh(e){return`${e.task_type} task`}function yh(e,t){return e?.root_asset_id||t||``}function bh(e){return`${e.title} (${e.root_asset_id})`}function xh(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 Sh(e){return e.some(e=>e.derived_state===`stale`)?`stale`:e.some(e=>e.derived_state===`idle`)?`idle`:`active`}function Ch(e){let t=Sh(e);return e.length===1?`${t===`active`?`Claimed`:t===`idle`?`Idle claim`:`Stale claim`} by ${e[0].agent_name}`:`${e.length} active claims`}function wh({activeWorkspace:e,closeSignal:t,loading:n,onNewLineage:r,onRefresh:i,onSelect:a,workspaces:o}){let[s,c]=(0,g.useState)(!1),[l,u]=(0,g.useState)([]),d=(0,g.useRef)(null),f=e?.project||o[0]?.project||``;(0,g.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,g.useEffect)(()=>{c(!1)},[t]),(0,g.useEffect)(()=>{if(!f){u([]);return}let e=!1;return v(`/api/agent-claims?${new URLSearchParams({project:f})}`).then(t=>{e||u(t.claims)}).catch(()=>{e||u([])}),()=>{e=!0}},[f,t,o.length]);function p(e){c(!1),a(e)}let m=e?xh(l,e):[];return(0,W.jsxs)(`section`,{"aria-label":`Lineage workspace picker`,className:`lineage-workspace-picker`,ref:d,children:[(0,W.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,W.jsx)(`span`,{children:`Workspace`}),(0,W.jsx)(`strong`,{children:e?.title||`No workspace selected`}),(0,W.jsx)(`code`,{children:e?.root_asset_id||`Start with New lineage`}),(0,W.jsx)(Eh,{claims:m})]}),s&&(0,W.jsxs)(`div`,{className:`lineage-workspace-menu`,children:[(0,W.jsxs)(`div`,{className:`lineage-workspace-options`,role:`listbox`,children:[o.length===0&&(0,W.jsx)(`p`,{children:`No workspaces yet.`}),o.map(t=>(0,W.jsx)(Th,{active:e?.id===t.id,claims:xh(l,t),onSelect:()=>p(t.id),workspace:t},t.id))]}),(0,W.jsxs)(`footer`,{children:[(0,W.jsx)(`button`,{className:`secondary-button`,disabled:n,onClick:i,type:`button`,children:`Refresh`}),(0,W.jsx)(`button`,{className:`primary-button`,onClick:()=>{c(!1),r()},type:`button`,children:`New lineage`})]})]})]})}function Th({active:e,claims:t,onSelect:n,workspace:r}){return(0,W.jsxs)(`button`,{"aria-selected":e,className:e?`active`:``,onClick:n,role:`option`,type:`button`,children:[(0,W.jsx)(`strong`,{children:r.title}),(0,W.jsx)(`code`,{children:r.root_asset_id}),(0,W.jsx)(`span`,{children:bh(r)}),(0,W.jsx)(Eh,{claims:t})]})}function Eh({claims:e}){return e.length===0?null:(0,W.jsxs)(`small`,{className:`lineage-workspace-claim ${Sh(e)}`,children:[(0,W.jsx)(xe,{size:13}),(0,W.jsx)(`span`,{children:Ch(e)})]})}function Dh({activeWorkspace:e,closeSignal:t,demoSeedStatus:n,graphDirection:r,loading:i,onArchiveWorkspace:a,onDownloadSwissifierMedia:o,onFitGraph:s,onGraphDirection:c,onIndexLocal:l,onNewLineage:u,onRefreshLineage:d,onRefreshWorkspaces:f,onRestoreDemoMedia:p,onRestoreSwissifierMedia:m,onSeedDemo:h,onSeedSwissifierDemo:_,onSelectWorkspace:v,onTidyGraph:y,onToggleNextPanel:b,sideOpen:x,snapshot:S,swissifierDemoStatus:C,workspaceLoading:w,workspaceRootAssetId:T,workspaces:E}){let D=n?`${n.present}/${n.total} SVG placeholders`:`Checking media`,O=C?`${C.present}/${C.total} PNG images`:`Checking media`,k=!!(C&&C.present===C.total),A=!!(C?.download_available&&!k),j=S?`${S.nodes.length} nodes · ${S.edges.length} links`:T||`Choose a lineage workspace`,[M,N]=(0,g.useState)(!1);(0,g.useEffect)(()=>{N(!1)},[t]),(0,g.useEffect)(()=>{function e(e){e.key===`Escape`&&N(!1)}return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)},[]);function P(e){N(!1),e()}function F(e){e.key===`Escape`&&(e.preventDefault(),N(!1))}return(0,W.jsxs)(`header`,{className:`lineage-header`,children:[(0,W.jsxs)(`div`,{className:`lineage-primary-controls`,children:[(0,W.jsx)(wh,{activeWorkspace:e,closeSignal:t,loading:w,onNewLineage:u,onRefresh:f,onSelect:v,workspaces:E}),(0,W.jsx)(`p`,{className:`lineage-toolbar-context`,children:j}),(0,W.jsx)(`button`,{className:`primary-button`,onClick:u,type:`button`,children:`New lineage`})]}),(0,W.jsxs)(`details`,{className:`lineage-overflow`,onToggle:e=>N(e.currentTarget.open),open:M,children:[(0,W.jsx)(`summary`,{onKeyDown:F,tabIndex:0,children:`Actions`}),(0,W.jsxs)(`div`,{children:[!e&&(0,W.jsx)(`button`,{disabled:w,onClick:()=>P(h),type:`button`,children:`Load demo lineage`}),(0,W.jsxs)(`p`,{children:[(0,W.jsx)(`strong`,{children:`QA seed media`}),(0,W.jsx)(`span`,{children:O})]}),(0,W.jsxs)(`p`,{children:[(0,W.jsx)(`strong`,{children:`Basic SVG demo`}),(0,W.jsx)(`span`,{children:D})]}),(0,W.jsx)(`button`,{disabled:w||n?.present===n?.total,onClick:p,type:`button`,children:`Restore basic media`}),(0,W.jsx)(`button`,{disabled:w,onClick:()=>P(h),type:`button`,children:`Load SVG placeholder demo`}),(0,W.jsxs)(`p`,{children:[(0,W.jsx)(`strong`,{children:`Swissifier rich demo`}),(0,W.jsx)(`span`,{children:O})]}),(0,W.jsx)(`button`,{disabled:w||!A,onClick:o,type:`button`,children:`Download rich images`}),(0,W.jsx)(`button`,{disabled:w||k,onClick:m,type:`button`,children:`Restore rich media`}),(0,W.jsx)(`button`,{disabled:w,onClick:()=>P(_),type:`button`,children:`Load rich image demo`}),(0,W.jsxs)(`label`,{className:`lineage-action-select`,children:[(0,W.jsx)(`span`,{children:`Direction`}),(0,W.jsxs)(`select`,{"aria-label":`Lineage graph direction`,disabled:!S||i,onChange:e=>c(e.target.value),value:r,children:[(0,W.jsx)(`option`,{value:`LR`,children:`Left to right`}),(0,W.jsx)(`option`,{value:`TB`,children:`Top to bottom`}),(0,W.jsx)(`option`,{value:`RL`,children:`Right to left`}),(0,W.jsx)(`option`,{value:`BT`,children:`Bottom to top`})]})]}),(0,W.jsx)(`button`,{disabled:!S,onClick:()=>P(s),type:`button`,children:`Fit graph`}),(0,W.jsx)(`button`,{disabled:!S,onClick:()=>P(y),type:`button`,children:`Tidy tree`}),(0,W.jsx)(`button`,{"aria-controls":`lineage-selection-panel`,"aria-expanded":x,disabled:!S,onClick:()=>P(b),type:`button`,children:`Manage selection`}),(0,W.jsx)(`button`,{disabled:w||!e,onClick:()=>P(a),type:`button`,children:`Archive current lineage`}),(0,W.jsx)(`button`,{disabled:i,onClick:()=>P(l),type:`button`,children:`Index local`}),(0,W.jsx)(`button`,{disabled:i||!S,onClick:()=>P(d),type:`button`,children:`Refresh graph`}),(0,W.jsx)(`button`,{disabled:w,onClick:()=>P(f),type:`button`,children:`Refresh workspaces`})]})]})]})}async function Oh(e,t,n){await v(`/api/lineage/layout`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({confirmWrite:!0,positions:n,project:e,rootAssetId:t})})}function kh(e,t,n){return wd(e.filter(e=>e.type!==`remove`),t)}function Ah(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 jh=Object.defineProperty,Mh=(e,t,n)=>t in e?jh(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Nh=(e,t)=>{for(var n in t)jh(e,n,{get:t[n],enumerable:!0})},Ph=(e,t,n)=>Mh(e,typeof t==`symbol`?t:t+``,n),Fh={};Nh(Fh,{Graph:()=>Rh,alg:()=>Xh,json:()=>Gh,version:()=>Wh});var Ih=Object.defineProperty,Lh=(e,t)=>{for(var n in t)Ih(e,n,{get:t[n],enumerable:!0})},Rh=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=Vh(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=Hh(this._isDirected,i,a,o);return i=u.v,a=u.w,Object.freeze(u),this._edgeObjs[l]=u,zh(this._preds[a],i),zh(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?Uh(this._isDirected,e):Vh(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?Uh(this._isDirected,e):Vh(this._isDirected,e,t,n))in this._edgeLabels}removeEdge(e,t,n){let r=arguments.length===1?Uh(this._isDirected,e):Vh(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],Bh(this._preds[t],e),Bh(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 zh(e,t){e[t]?e[t]++:e[t]=1}function Bh(e,t){e[t]!==void 0&&!--e[t]&&delete e[t]}function Vh(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 Hh(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 Uh(e,t){return Vh(e,t.v,t.w,t.name)}var Wh=`4.0.1`,Gh={};Lh(Gh,{read:()=>Yh,write:()=>Kh});function Kh(e){let t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:qh(e),edges:Jh(e)},n=e.graph();return n!==void 0&&(t.value=structuredClone(n)),t}function qh(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 Jh(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 Yh(e){let t=new Rh(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 Xh={};Lh(Xh,{CycleException:()=>dg,bellmanFord:()=>Qh,components:()=>eg,dijkstra:()=>rg,dijkstraAll:()=>ag,findCycles:()=>sg,floydWarshall:()=>lg,isAcyclic:()=>pg,postorder:()=>_g,preorder:()=>vg,prim:()=>yg,shortestPaths:()=>bg,tarjan:()=>og,topsort:()=>fg});var Zh=()=>1;function Qh(e,t,n,r){return $h(e,String(t),n||Zh,r||function(t){return e.outEdges(t)})}function $h(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 eg(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 tg=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}},ng=()=>1;function rg(e,t,n,r){return ig(e,String(t),n||ng,r||function(t){return e.outEdges(t)})}function ig(e,t,n,r){let i={},a=new tg,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 ag(e,t,n){return e.nodes().reduce(function(r,i){return r[i]=rg(e,i,t,n),r},{})}function og(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 sg(e){return og(e).filter(function(t){return t.length>1||t.length===1&&e.hasEdge(t[0],t[0])})}var cg=()=>1;function lg(e,t,n){return ug(e,t||cg,n||function(t){return e.outEdges(t)})}function ug(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 dg=class extends Error{constructor(...e){super(...e)}};function fg(e){let t={},n={},r=[];function i(a){if(a in n)throw new dg;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 dg;return r}function pg(e){try{fg(e)}catch(e){if(e instanceof dg)return!1;throw e}return!0}function mg(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=hg(e,t,n===`post`,o,a,r,i)}),i}function hg(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=hg(e,t,n,r,i,a,o)}),n&&(o=a(o,t))),o}function gg(e,t,n){return mg(e,t,n,function(e,t){return e.push(t),e},[])}function _g(e,t){return gg(e,t,`post`)}function vg(e,t){return gg(e,t,`pre`)}function yg(e,t){let n=new Rh,r={},i=new tg,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 bg(e,t,n,r){return xg(e,t,n,r??(t=>e.outEdges(t)??[]))}function xg(e,t,n,r){if(n===void 0)return rg(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 Qh(e,t,n,r)}return rg(e,t,n,r)}function Sg(e,t,n,r){let i=r;for(;e.hasNode(i);)i=Rg(r);return n.dummy=t,e.setNode(i,n),i}function Cg(e){let t=new Rh().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 wg(e){let t=new Rh({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 Tg(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 Eg(e){let t=zg(Ng(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 Dg(e){let t=e.nodes().map(t=>{let n=e.node(t).rank;return n===void 0?Number.MAX_VALUE:n}),n=Mg(Math.min,t);e.nodes().forEach(t=>{let r=e.node(t);Object.hasOwn(r,`rank`)&&(r.rank-=n)})}function Og(e){let t=e.nodes().map(t=>e.node(t).rank).filter(e=>e!==void 0),n=Mg(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 kg(e,t,n,r){let i={width:0,height:0};return arguments.length>=4&&(i.rank=n,i.order=r),Sg(e,`border`,i,t)}function Ag(e,t=jg){let n=[];for(let r=0;r<e.length;r+=t){let i=e.slice(r,r+t);n.push(i)}return n}var jg=65535;function Mg(e,t){return t.length>jg?e(...Ag(t).map(t=>e(...t))):e(...t)}function Ng(e){let t=e.nodes().map(t=>{let n=e.node(t).rank;return n===void 0?Number.MIN_VALUE:n});return Mg(Math.max,t)}function Pg(e,t){let n={lhs:[],rhs:[]};return e.forEach(e=>{t(e)?n.lhs.push(e):n.rhs.push(e)}),n}function Fg(e,t){let n=Date.now();try{return t()}finally{console.log(e+` time: `+(Date.now()-n)+`ms`)}}function Ig(e,t){return t()}var Lg=0;function Rg(e){return e+(``+ ++Lg)}function zg(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 Bg(e,t){let n={};for(let r of t)e[r]!==void 0&&(n[r]=e[r]);return n}function Vg(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 Hg(e,t){return e.reduce((e,n,r)=>(e[n]=t[r],e),{})}var Ug=`\0`,Wg=class{constructor(){Ph(this,`_sentinel`);let e={};e._next=e._prev=e,this._sentinel=e}dequeue(){let e=this._sentinel,t=e._prev;if(t!==e)return Gg(t),t}enqueue(e){let t=this._sentinel;e._prev&&e._next&&Gg(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,Kg)),n=n._prev;return`[`+e.join(`, `)+`]`}};function Gg(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function Kg(e,t){if(e!==`_next`&&e!==`_prev`)return t}var qg=Wg,Jg=()=>1;function Yg(e,t){if(e.nodeCount()<=1)return[];let n=Qg(e,t||Jg);return Xg(n.graph,n.buckets,n.zeroIdx).flatMap(t=>e.outEdges(t.v,t.w)||[])}function Xg(e,t,n){let r=[],i=t[t.length-1],a=t[0],o;for(;e.nodeCount();){for(;o=a.dequeue();)Zg(e,t,n,o);for(;o=i.dequeue();)Zg(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(Zg(e,t,n,o,!0)||[]);break}}}return r}function Zg(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,$g(t,n,s)}),(e.outEdges(r.v)||[]).forEach(r=>{let i=e.edge(r),a=r.w,o=e.node(a);o.in-=i,$g(t,n,o)}),e.removeNode(r.v),o}function Qg(e,t){let n=new Rh,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=e_(i+r+3).map(()=>new qg),o=r+1;return n.nodes().forEach(e=>{$g(a,o,n.node(e))}),{graph:n,buckets:a,zeroIdx:o}}function $g(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 e_(e){let t=[];for(let n=0;n<e;n++)t.push(n);return t}function t_(e){(e.graph().acyclicer===`greedy`?Yg(e,t(e)):n_(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,Rg(`rev`))});function t(e){return t=>e.edge(t).weight}}function n_(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 r_(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 i_(e){e.graph().dummyChains=[],e.edges().forEach(t=>a_(e,t))}function a_(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=Sg(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 o_(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 s_(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=Mg(Math.min,o);return s===1/0&&(s=0),i.rank=s}e.sources().forEach(n)}function c_(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}var l_=u_;function u_(e){let t=new Rh({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(;d_(t,e)<i&&(a=f_(t,e),a);)o=t.hasNode(a.v)?c_(e,a):-c_(e,a),p_(t,e,o);return t}function d_(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)&&!c_(t,i)&&(e.setNode(o,{}),e.setEdge(r,o,{}),n(o))})}return e.nodes().forEach(n),e.nodeCount()}function f_(e,t){return t.edges().reduce((n,r)=>{let i=1/0;return e.hasNode(r.v)!==e.hasNode(r.w)&&(i=c_(t,r)),i<n[0]?[i,r]:n},[1/0,null])[1]}function p_(e,t,n){e.nodes().forEach(e=>t.node(e).rank+=n)}var{preorder:m_,postorder:h_}=Xh,g_=__;__.initLowLimValues=x_,__.initCutValues=v_,__.calcCutValue=b_,__.leaveEdge=C_,__.enterEdge=w_,__.exchangeEdges=T_;function __(e){e=Cg(e),s_(e);let t=l_(e);x_(t),v_(t,e);let n,r;for(;n=C_(t);)r=w_(t,e,n),T_(t,e,n,r)}function v_(e,t){let n=h_(e,e.nodes());n=n.slice(0,n.length-1),n.forEach(n=>y_(e,t,n))}function y_(e,t,n){let r=e.node(n).parent,i=e.edge(n,r);i.cutvalue=b_(e,t,n)}function b_(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,D_(e,n,c)){let t=e.edge(n,c).cutvalue;o+=r?-t:t}}}),o}function x_(e,t){arguments.length<2&&(t=e.nodes()[0]),S_(e,{},1,t)}function S_(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=S_(e,t,n,i,r))}),o.low=a,o.lim=n++,i?o.parent=i:delete o.parent,n}function C_(e){return e.edges().find(t=>e.edge(t).cutvalue<0)}function w_(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===O_(e,e.node(t.v),s)&&c!==O_(e,e.node(t.w),s)).reduce((e,n)=>c_(t,n)<c_(t,e)?n:e)}function T_(e,t,n,r){let i=n.v,a=n.w;e.removeEdge(i,a),e.setEdge(r.v,r.w,{}),x_(e),v_(e,t),E_(e,t)}function E_(e,t){let n=e.nodes().find(t=>!e.node(t).parent);if(!n)return;let r=m_(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 D_(e,t,n){return e.hasEdge(t,n)}function O_(e,t,n){return n.low<=t.lim&&t.lim<=n.lim}var k_=A_;function A_(e){let t=e.graph().ranker;if(typeof t==`function`)return t(e);switch(t){case`network-simplex`:N_(e);break;case`tight-tree`:M_(e);break;case`longest-path`:j_(e);break;case`none`:break;default:N_(e)}}var j_=s_;function M_(e){s_(e),l_(e)}function N_(e){g_(e)}var P_=F_;function F_(e){let t=L_(e);e.graph().dummyChains.forEach(n=>{let r=e.node(n),i=r.edgeObj,a=I_(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 I_(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 L_(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(Ug).forEach(r),t}function R_(e){let t=Sg(e,`root`,{},`_root`),n=B_(e),r=Object.values(n),i=Mg(Math.max,r)-1,a=2*i+1;e.graph().nestingRoot=t,e.edges().forEach(t=>e.edge(t).minlen*=a);let o=V_(e)+1;e.children(Ug).forEach(r=>z_(e,t,a,o,i,n,r)),e.graph().nodeRankFactor=a}function z_(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=kg(e,`_bt`),l=kg(e,`_bb`),u=e.node(o);e.setParent(c,o),u.borderTop=c,e.setParent(l,o),u.borderBottom=l,s.forEach(s=>{z_(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 B_(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(Ug).forEach(e=>n(e,1)),t}function V_(e){return e.edges().reduce((t,n)=>t+e.edge(n).weight,0)}function H_(e){let t=e.graph();e.removeNode(t.nestingRoot),delete t.nestingRoot,e.edges().forEach(t=>{e.edge(t).nestingEdge&&e.removeEdge(t)})}var U_=W_;function W_(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)G_(e,`borderLeft`,`_bl`,n,i,t),G_(e,`borderRight`,`_br`,n,i,t)}}e.children(Ug).forEach(t)}function G_(e,t,n,r,i,a){let o={width:0,height:0,rank:a,borderType:t},s=i[t][a-1],c=Sg(e,`border`,o,n);i[t][a]=c,e.setParent(c,r),s&&e.setEdge(s,c,{weight:1})}function K_(e){let t=e.graph().rankdir?.toLowerCase();(t===`lr`||t===`rl`)&&J_(e)}function q_(e){let t=e.graph().rankdir?.toLowerCase();(t===`bt`||t===`rl`)&&X_(e),(t===`lr`||t===`rl`)&&(Q_(e),J_(e))}function J_(e){e.nodes().forEach(t=>Y_(e.node(t))),e.edges().forEach(t=>Y_(e.edge(t)))}function Y_(e){let t=e.width;e.width=e.height,e.height=t}function X_(e){e.nodes().forEach(t=>Z_(e.node(t))),e.edges().forEach(t=>{var n;let r=e.edge(t);(n=r.points)==null||n.forEach(Z_),Object.hasOwn(r,`y`)&&Z_(r)})}function Z_(e){e.y=-e.y}function Q_(e){e.nodes().forEach(t=>$_(e.node(t))),e.edges().forEach(t=>{var n;let r=e.edge(t);(n=r.points)==null||n.forEach($_),Object.hasOwn(r,`x`)&&$_(r)})}function $_(e){let t=e.x;e.x=e.y,e.y=t}function ev(e){let t={},n=e.nodes().filter(t=>!e.children(t).length),r=n.map(t=>e.node(t).rank),i=zg(Mg(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 tv(e,t){let n=0;for(let r=1;r<t.length;++r)n+=nv(e,t[r-1],t[r]);return n}function nv(e,t,n){let r=Hg(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 rv(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 iv(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))}),av(Object.values(n).filter(e=>!e.indegree))}function av(e){let t=[];function n(e){return t=>{t.merged||(t.barycenter===void 0||e.barycenter===void 0||t.barycenter>=e.barycenter)&&ov(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=>Bg(e,[`vs`,`i`,`barycenter`,`weight`]))}function ov(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 sv(e,t){let n=Pg(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(lv(!!t)),c=cv(a,i,c),r.forEach(e=>{c+=e.vs.length,a.push(e.vs),o+=e.barycenter*e.weight,s+=e.weight,c=cv(a,i,c)});let l={vs:a.flat(1)};return s&&(l.barycenter=o/s,l.weight=s),l}function cv(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 lv(e){return(t,n)=>t.barycenter<n.barycenter?-1:t.barycenter>n.barycenter?1:e?n.i-t.i:t.i-n.i}function uv(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=rv(e,i);l.forEach(t=>{if(e.children(t.v).length){let i=uv(e,t.v,n,r);c[t.v]=i,Object.hasOwn(i,`barycenter`)&&fv(t,i)}});let u=iv(l,n);dv(u,c);let d=sv(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 dv(e,t){e.forEach(e=>{e.vs=e.vs.flatMap(e=>t[e]?t[e].vs:e)})}function fv(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 pv(e,t,n,r){r||=e.nodes();let i=mv(e),a=new Rh({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 mv(e){let t;for(;e.hasNode(t=Rg(`_root`)););return t}function hv(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 gv(e,t={}){if(typeof t.customOrder==`function`){t.customOrder(e,gv);return}let n=Ng(e),r=_v(e,zg(1,n+1),`inEdges`),i=_v(e,zg(n-1,-1,-1),`outEdges`),a=ev(e);if(yv(e,a),t.disableOptimalOrderHeuristic)return;let o=1/0,s,c=t.constraints||[];for(let t=0,n=0;n<4;++t,++n){vv(t%2?r:i,t%4>=2,c),a=Eg(e);let l=tv(e,a);l<o?(n=0,s=Object.assign({},a),o=l):l===o&&(s=structuredClone(a))}yv(e,s)}function _v(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 pv(e,t,n,r.get(t)||[])})}function vv(e,t,n){let r=new Rh;e.forEach(function(e){n.forEach(e=>r.setEdge(e.left,e.right));let i=e.graph().root,a=uv(e,i,r,t);a.vs.forEach((t,n)=>e.node(t).order=n),hv(e,r,a.vs)})}function yv(e,t){Object.values(t).forEach(t=>t.forEach((t,n)=>e.node(t).order=n))}function bv(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=Sv(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)&&Cv(n,r,t)})}),a=c+1,i=u)}),r}return t.length&&t.reduce(r),n}function xv(e,t){let n={};function r(t,r,i,a,o){zg(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)&&Cv(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 Sv(e,t){if(e.node(t).dummy){let n=e.predecessors(t);if(n)return n.find(t=>e.node(t).dummy)}}function Cv(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 wv(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 Tv(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&&!wv(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 Ev(e,t,n,r,i=!1){let a={},o=Dv(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 Dv(e,t,n,r){let i=new Rh,a=e.graph(),o=Mv(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 Ov(e,t){return Object.values(t).reduce((t,n)=>{let r=-1/0,i=1/0;Object.entries(n).forEach(([t,n])=>{let a=Nv(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 kv(e,t){let n=Object.values(t),r=Mg(Math.min,n),i=Mg(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-Mg(Math.min,c);a!==`l`&&(l=i-Mg(Math.max,c)),l&&(e[o]=Vg(s,e=>e+l))})})}function Av(e,t=void 0){let n=e.ul;return n?Vg(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 jv(e){let t=Eg(e),n=Object.assign(bv(e,t),xv(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=Tv(e,i,n,t=>(a===`u`?e.predecessors(t):e.successors(t))||[]),s=Ev(e,i,o.root,o.align,t===`r`);t===`r`&&(s=Vg(s,e=>-e)),r[a+t]=s})}),kv(r,Ov(e,r)),Av(r,e.graph().align)}function Mv(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 Nv(e,t){return e.node(t).width}function Pv(e){e=wg(e),Fv(e),Object.entries(jv(e)).forEach(([t,n])=>e.node(t).x=n)}function Fv(e){let t=Eg(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 Iv(e,t={}){let n=t.debugTiming?Fg:Ig;return n(`layout`,()=>{let r=n(` buildLayoutGraph`,()=>qv(e));return n(` runLayout`,()=>Lv(r,n,t)),n(` updateInputGraph`,()=>Rv(e,r)),r})}function Lv(e,t,n){t(` makeSpaceForEdgeLabels`,()=>Jv(e)),t(` removeSelfEdges`,()=>ry(e)),t(` acyclic`,()=>t_(e)),t(` nestingGraph.run`,()=>R_(e)),t(` rank`,()=>k_(wg(e))),t(` injectEdgeLabelProxies`,()=>Yv(e)),t(` removeEmptyRanks`,()=>Og(e)),t(` nestingGraph.cleanup`,()=>H_(e)),t(` normalizeRanks`,()=>Dg(e)),t(` assignRankMinMax`,()=>Xv(e)),t(` removeEdgeLabelProxies`,()=>Zv(e)),t(` normalize.run`,()=>i_(e)),t(` parentDummyChains`,()=>P_(e)),t(` addBorderSegments`,()=>U_(e)),t(` order`,()=>gv(e,n)),t(` insertSelfEdges`,()=>iy(e)),t(` adjustCoordinateSystem`,()=>K_(e)),t(` position`,()=>Pv(e)),t(` positionSelfEdges`,()=>ay(e)),t(` removeBorderNodes`,()=>ny(e)),t(` normalize.undo`,()=>o_(e)),t(` fixupEdgeLabelCoords`,()=>ey(e)),t(` undoCoordinateSystem`,()=>q_(e)),t(` translateGraph`,()=>Qv(e)),t(` assignNodeIntersects`,()=>$v(e)),t(` reversePoints`,()=>ty(e)),t(` acyclic.undo`,()=>r_(e))}function Rv(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 zv=[`nodesep`,`edgesep`,`ranksep`,`marginx`,`marginy`],Bv={ranksep:50,edgesep:20,nodesep:50,rankdir:`TB`,rankalign:`center`},Vv=[`acyclicer`,`ranker`,`rankdir`,`align`,`rankalign`],Hv=[`width`,`height`,`rank`],Uv={width:0,height:0},Wv=[`minlen`,`weight`,`width`,`height`,`labeloffset`],Gv={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:`r`},Kv=[`labelpos`];function qv(e){let t=new Rh({multigraph:!0,compound:!0}),n=sy(e.graph());return t.setGraph(Object.assign({},Bv,oy(n,zv),Bg(n,Vv))),e.nodes().forEach(n=>{let r=oy(sy(e.node(n)),Hv);Object.keys(Uv).forEach(e=>{r[e]===void 0&&(r[e]=Uv[e])}),t.setNode(n,r);let i=e.parent(n);i!==void 0&&t.setParent(n,i)}),e.edges().forEach(n=>{let r=sy(e.edge(n));t.setEdge(n,Object.assign({},Gv,oy(r,Wv),Bg(r,Kv)))}),t}function Jv(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 Yv(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.width&&n.height){let n=e.node(t.v);Sg(e,`edge-proxy`,{rank:(e.node(t.w).rank-n.rank)/2+n.rank,e:t},`_ep`)}})}function Xv(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 Zv(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 Qv(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 $v(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(Tg(r,a)),n.points.push(Tg(i,o))})}function ey(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 ty(e){e.edges().forEach(t=>{let n=e.edge(t);n.reversed&&n.points.reverse()})}function ny(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 ry(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 iy(e){Eg(e).forEach(t=>{let n=0;t.forEach((t,r)=>{let i=e.node(t);i.order=r+n,(i.selfEdges||[]).forEach(t=>{Sg(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 ay(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 oy(e,t){return Vg(Bg(e,t),Number)}function sy(e){let t={};return e&&Object.entries(e).forEach(([e,n])=>{typeof e==`string`&&(e=e.toLowerCase()),t[e]=n}),t}var cy=212,ly=164;function uy(e,t,n=`LR`){if(!e)return{nodes:[],edges:[]};let r=my(e,n),i=dy(n),a=py(e,t);return{nodes:e.nodes.map(n=>({id:n.asset_id,initialHeight:ly,initialWidth:cy,measured:{height:ly,width:cy},type:`assetNode`,height:ly,position:n.position||r.get(n.asset_id)||{x:0,y:0},sourcePosition:i.source,targetPosition:i.target,width:cy,data:{...n,active:n.asset_id===t,focusRole:a.roles.get(n.asset_id)||`none`,root:n.asset_id===e.root_asset_id,sourcePosition:i.source,targetPosition:i.target}})),edges:e.edges.map(t=>({className:a.edgeClasses.get(t.id),id:t.id,markerEnd:{type:Qs.ArrowClosed},source:t.parent_asset_id,target:t.child_asset_id,type:`smoothstep`,animated:e.selected.includes(t.child_asset_id)}))}}function dy(e){return{BT:{source:X.Top,target:X.Bottom},LR:{source:X.Right,target:X.Left},RL:{source:X.Left,target:X.Right},TB:{source:X.Bottom,target:X.Top}}[e]}function fy(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 py(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 my(e,t=`LR`){let n=new Fh.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:ly,width:cy});for(let t of e.edges)n.setEdge(t.parent_asset_id,t.child_asset_id);return Iv(n),new Map(e.nodes.map(e=>{let t=n.node(e.asset_id);return[e.asset_id,{x:Math.round((t?.x||cy/2)-cy/2),y:Math.round((t?.y||ly/2)-ly/2)}]}))}function hy(e,t){(0,g.useEffect)(()=>{function n(n){n.key===`Escape`&&e&&t()}return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t])}function gy({asset:e,onResetLineage:t,onSelectedAsset:n,onToast:r,project:i}){let a=(0,g.useRef)(i),[o,s]=(0,g.useState)(null),[c,l]=(0,g.useState)(null),[u,d]=(0,g.useState)(null),[f,p]=(0,g.useState)(!1),m=o?.project===i,h=m?o:null,_=(h?.workspaces||[]).filter(e=>e.status!==`archived`),y=h?.active_workspace||_[0]||null,b=yh(y,m&&h?.workspaces.length===0?e?.asset_id:void 0);(0,g.useEffect)(()=>{a.current=i,s(null),l(null),d(null)},[i]);let x=(0,g.useCallback)(async()=>{p(!0);try{let e=await v(`/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{p(!1)}},[r,i]),S=(0,g.useCallback)(async()=>{try{let e=new URLSearchParams({project:i}),[t,n]=await Promise.all([v(`/api/lineage-workspaces/demo/media?${e.toString()}`),v(`/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){p(!0);try{let a=await v(`/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{p(!1)}}}async function w(e={}){p(!0);try{let a=await v(`/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{p(!1)}}async function T(e={}){p(!0);try{let a=await v(`/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{p(!1)}}async function E(){p(!0);try{let e=await v(`/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{p(!1)}}async function D(){p(!0);try{let e=await v(`/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{p(!1)}}async function O(){p(!0);try{let e=await v(`/api/lineage-workspaces/demo/swissifier/media/download`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:i,confirmWrite:!0})});await S(),e.result.download_available?r(`ok`,`Downloaded ${e.result.restored||0} Swissifier media file${e.result.restored===1?``:`s`}`):r(`error`,`Swissifier media download is not configured`)}catch(e){r(`error`,e instanceof Error?e.message:String(e))}finally{p(!1)}}async function k(){if(y&&window.confirm(`Archive ${y.title}? This hides it from the picker and clears its next-variation selection.`)){p(!0);try{await v(`/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{p(!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:_,workspaceLoading:f,workspaceRootAssetId:b}}function _y(e,t,n){let r=(0,g.useRef)(!1),i=(0,g.useRef)(``),a=(0,g.useRef)(!1),o=(0,g.useRef)(``),s=(0,g.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,g.useCallback)(()=>{r.current||(a.current=!0)},[]);return(0,g.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 vy({asset:e,onAssetsChanged:t,project:n,onSelectedAsset:r,onToast:i}){let[a,o]=(0,g.useState)(null),[s,c]=(0,g.useState)(null),[l,u]=(0,g.useState)(``),[d,f]=(0,g.useState)(null),[p,m]=(0,g.useState)(null),[h,_]=(0,g.useState)([]),[y,b]=(0,g.useState)(null),[x,S]=(0,g.useState)([]),[C,w]=(0,g.useState)(`LR`),[T,E]=(0,g.useState)(``),[D,O]=(0,g.useState)(null),[k,A]=(0,g.useState)(!1),[j,M]=(0,g.useState)(!1),[N,P]=(0,g.useState)(!1),[F,I,L]=Yp([]),[R,z]=Xp([]),[B,ee]=(0,g.useState)(null),[te,ne]=(0,g.useState)(!1),[re,ie]=(0,g.useState)(0),V=a?.nodes.find(e=>e.asset_id===s)||a?.nodes[0],ae=a?.nodes.filter(e=>a.latest.includes(e.asset_id))||[],oe=a?.selected.map(e=>a.nodes.find(t=>t.asset_id===e)).filter(e=>!!e)||[],se=oe[0],ce=oe.length>=3,le=a?.nodes.find(e=>e.asset_id===d)||null,ue=a?.nodes.find(e=>e.asset_id===p)||null,H=a?.nodes.find(e=>e.asset_id===D?.assetId),de=!!(s&&V),fe=V?.asset_id||`none`,pe=!!(V&&T!==(V.selection_note||``)),me=(0,g.useRef)(null),he=(0,g.useRef)([]),ge=(0,g.useRef)(``),U=(0,g.useRef)(``),{fitGraph:_e,markViewportInteraction:ve}=_y(B,a?.root_asset_id,j),ye=(0,g.useCallback)(()=>{ie(e=>e+1),O(null)},[]),be=(0,g.useRef)(n);(0,g.useEffect)(()=>{be.current=n},[n]);let xe=(0,g.useCallback)(()=>{c(null),ye()},[ye]),Se=(0,g.useCallback)(()=>{o(null),c(null),b(null)},[]),{activateWorkspace:Ce,activeWorkspace:we,archiveWorkspace:Te,demoSeedStatus:Ee,downloadSwissifierDemoMedia:De,handleWorkspaceCreated:Oe,refreshDemoSeedStatus:ke,refreshWorkspaces:Ae,restoreDemoSeedMedia:je,restoreSwissifierDemoMedia:Me,seedDemoWorkspace:Ne,seedSwissifierDemoWorkspace:Pe,swissifierDemoStatus:Fe,visibleWorkspaces:Ie,workspaceLoading:Le,workspaceRootAssetId:Re}=gy({asset:e,onResetLineage:Se,onSelectedAsset:r,onToast:i,project:n});U.current=Re,(0,g.useEffect)(()=>{ke()},[ke]);let ze=(0,g.useCallback)(async(e={})=>{let t=e.rootAssetId||Re;if(t){e.quiet||ne(!0);try{let r=new URLSearchParams({project:n}),[i,a]=await Promise.all([v(`/api/lineage/${t}?${r.toString()}`),v(`/api/agent-claims?${r.toString()}`)]);if(!e.rootAssetId&&U.current!==t)return;o(i),S(a.claims),e.quiet||b(null),c(e=>e&&i.nodes.some(t=>t.asset_id===e)?e:i.active_asset_id)}catch(r){if(!e.rootAssetId&&U.current!==t)return;!e.quiet&&be.current===n&&(o(null),i(`error`,r instanceof Error?r.message:String(r)))}finally{!e.quiet&&be.current===n&&ne(!1)}}},[i,n,Re]);async function Be(){ne(!0);try{i(`ok`,`Indexed ${(await v(`/api/index/local`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:n})})).summary.total} assets`),await Ae(),await ze()}catch(e){i(`error`,e instanceof Error?e.message:String(e))}finally{ne(!1)}}async function Ve(){ye();let e=await Ne();await t?.();let n=await Ne({quiet:!0});await ze({rootAssetId:n?.workspace?.root_asset_id||n?.root_asset_id||e?.workspace?.root_asset_id||e?.root_asset_id})}async function He(){ye();let e=await Pe();await t?.();let n=await Pe({quiet:!0});await ze({rootAssetId:n?.workspace?.root_asset_id||n?.root_asset_id||e?.workspace?.root_asset_id||e?.root_asset_id})}async function Ue(e,t,r){try{await v(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:n,...t})}),i(`ok`,r),await ze()}catch(e){i(`error`,e instanceof Error?e.message:String(e))}}function We(){V&&Ke(V,T)}function Ge(){V?.user_selected&&Ke(V,T)}function Ke(e,t=e.selection_note||``){if(!e.user_selected&&ce){i(`error`,`Choose at most 3 assets for next variation`);return}Ue(`/api/selection`,{assetId:e.asset_id,rootAssetId:a?.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`)}function qe(e,t=e.selection_note||``){Ue(`/api/selection`,{assetId:e.asset_id,rootAssetId:a?.root_asset_id,mode:`replace`,notes:t,confirmWrite:!0},`Using only ${e.asset_id} for next variation`)}async function Je(e){if(a){if(e){await Ue(`/api/selection`,{assetId:e,rootAssetId:a.root_asset_id,mode:`remove`,confirmWrite:!0},`Removed ${e} from next variation`);return}oe.length>0&&await Ue(`/api/selection`,{rootAssetId:a.root_asset_id,clear:!0,confirmWrite:!0},`Removed all assets from next variation`)}}function Ye(){if(me.current&&window.clearTimeout(me.current),j){M(!1),me.current=window.setTimeout(()=>P(!1),260);return}P(!0),window.requestAnimationFrame(()=>M(!0))}async function Xe(e,t=V?.asset_id){if(!t)return;let n=a?.nodes.find(e=>e.asset_id===t),r=Ah(n,e);r&&!window.confirm(r.confirmation)||(r&&await Je(t),Ue(`/api/reviews/${t}`,{reviewState:e,confirmWrite:!0},`Marked ${t} ${e}`))}async function Ze(e){a&&await Ue(`/api/lineage/${a.root_asset_id}/rerolls/${e.asset_id}`,{confirmWrite:!0,requestedBy:`human`},`Marked ${e.asset_id} for re-roll`)}async function Qe(e){a&&await Ue(`/api/lineage/${a.root_asset_id}/rerolls/${e.asset_id}/cancel`,{confirmWrite:!0},`Cleared re-roll request for ${e.asset_id}`)}async function $e(e){if(a)try{let t=new URLSearchParams({project:n}),r=await v(`/api/lineage/${a.root_asset_id}/attempts/${e}?${t.toString()}`);_(r.attempts),m(e)}catch(e){i(`error`,e instanceof Error?e.message:String(e))}}function et(){m(null),_([])}function tt(e){et(),f(e)}async function nt(e){if(!(!a||!p))try{let t=await v(`/api/lineage/${a.root_asset_id}/attempts/${p}/promote`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:n,attemptId:e.id,confirmWrite:!0})});_(t.attempts),i(`ok`,`Set v${e.attempt_index} as current`),await ze({quiet:!0})}catch(e){i(`error`,e instanceof Error?e.message:String(e))}}async function rt(){!V||!l.trim()||(await Ue(`/api/lineage/link`,{childAssetId:l.trim(),confirmWrite:!0,parentAssetId:V.asset_id},`Linked ${l.trim()} from ${V.asset_id}`),u(``))}async function it(e){if(!a)return;if(e.asset_id===a.root_asset_id){i(`error`,`Root lineage node cannot be removed. Archive this workspace or start a new lineage instead.`);return}let t=a.edges.filter(t=>t.parent_asset_id===e.asset_id).length,n=a.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 Ue(`/api/lineage/remove-node`,{assetId:e.asset_id,rootAssetId:a.root_asset_id,confirmWrite:!0},`Removed ${e.asset_id} from lineage`),O(null),f(t=>t===e.asset_id?null:t),c(t=>t===e.asset_id?a.root_asset_id:t))}async function at(e){if(a)try{await Oh(n,a.root_asset_id,[{assetId:e.id,x:e.position.x,y:e.position.y}])}catch(e){i(`error`,e instanceof Error?e.message:String(e))}}async function ot(){if(!a)return;let e=[...my(a,C)].map(([e,t])=>({assetId:e,...t}));ct(e),I(t=>t.map(t=>({...t,position:e.find(e=>e.assetId===t.id)||t.position})));try{await Oh(n,a.root_asset_id,e),i(`ok`,`Tidied ${e.length} lineage nodes`),_e(80),await ze()}catch(e){i(`error`,e instanceof Error?e.message:String(e))}}async function st(e){if(!a)return;let t=[...my(a,e)].map(([e,t])=>({assetId:e,...t}));ct(t),w(e),I(e=>e.map(e=>({...e,position:t.find(t=>t.assetId===e.id)||e.position})));try{await Oh(n,a.root_asset_id,t),i(`ok`,`Rotated lineage graph ${by(e).toLowerCase()}`),_e(80),await ze()}catch(e){i(`error`,e instanceof Error?e.message:String(e))}}function ct(e){let t=new Map(e.map(e=>[e.assetId,{x:e.x,y:e.y}]));o(e=>e&&{...e,nodes:e.nodes.map(e=>({...e,position:t.get(e.asset_id)||e.position}))})}async function lt(){if(a)try{let e=new URLSearchParams({project:n});b(await v(`/api/lineage/${a.root_asset_id}/brief?${e.toString()}`))}catch(e){i(`error`,e instanceof Error?e.message:String(e))}}async function ut(e,t,r){try{await v(`/api/agent-claims/${t.id}/${e}`,{body:JSON.stringify({project:n,...r}),headers:{"Content-Type":`application/json`},method:`POST`}),i(`ok`,`Updated claim ${t.id}`),await ze({quiet:!0})}catch(e){i(`error`,e instanceof Error?e.message:String(e))}}(0,g.useEffect)(()=>{Ae()},[Ae]),(0,g.useEffect)(()=>{ze()},[ze]),(0,g.useEffect)(()=>{Re||Se()},[Se,Re]),(0,g.useEffect)(()=>{if(!a)return;let e=window.setInterval(()=>void ze({quiet:!0}),8e3);return()=>window.clearInterval(e)},[ze,a?.root_asset_id]);let G=(0,g.useMemo)(()=>uy(a,s,C),[s,C,a]),dt=(0,g.useMemo)(()=>fy(a,C),[C,a]);he.current=G.edges;let ft=(0,g.useCallback)(e=>{z(t=>kh(e,t,he.current))},[z]),pt=(0,g.useCallback)(e=>{e.key===`Escape`&&ye()},[ye]);return(0,g.useEffect)(()=>{E(V?.selection_note||``)},[V?.asset_id,V?.selection_note]),(0,g.useEffect)(()=>{let e=ge.current!==dt;ge.current=dt,I(t=>G.nodes.map(n=>({...n,position:e?n.position:t.find(e=>e.id===n.id)?.position||n.position}))),z(G.edges)},[G.edges,G.nodes,dt,z,I]),hy(!!s,xe),(0,g.useEffect)(()=>()=>{me.current&&window.clearTimeout(me.current)},[]),(0,g.useEffect)(()=>{Se()},[n,Se]),(0,W.jsxs)(`section`,{className:`lineage-view`,onKeyDownCapture:pt,children:[(0,W.jsx)(Dh,{activeWorkspace:we,closeSignal:re,loading:te,graphDirection:C,demoSeedStatus:Ee,onArchiveWorkspace:()=>void Te(),onFitGraph:()=>_e(),onIndexLocal:()=>void Be(),onGraphDirection:e=>void st(e),onNewLineage:()=>A(!0),onRefreshLineage:()=>void ze(),onRefreshWorkspaces:()=>void Ae(),onRestoreDemoMedia:()=>void je(),onRestoreSwissifierMedia:()=>void Me(),onDownloadSwissifierMedia:()=>void De(),onSeedDemo:()=>void Ve(),onSeedSwissifierDemo:()=>void He(),onSelectWorkspace:e=>void Ce(e),onTidyGraph:()=>void ot(),onToggleNextPanel:Ye,sideOpen:j,snapshot:a,swissifierDemoStatus:Fe,workspaceLoading:Le,workspaceRootAssetId:Re,workspaces:Ie}),(0,W.jsxs)(`div`,{className:`lineage-workbench`,"data-testid":`lineage-workbench`,children:[(0,W.jsx)(`div`,{className:`lineage-canvas ${s?`focus-active`:``}`,children:(0,W.jsx)(Pm,{activeNode:V,flowEdges:a?R:[],flowNodes:a?F:[],graphKey:dt,inspectingId:fe,loading:te,onEdgesChange:ft,onClearFocus:xe,onIndexNow:()=>void Be(),onNewLineage:()=>A(!0),onSeedDemo:()=>void Ve(),onNodeActionMenu:(e,t,n)=>O(e?{assetId:e,x:t,y:n}:null),onNodeInspect:e=>{ye(),c(e)},onNodeOpenDetail:f,onNodeOpenHistory:e=>void $e(e),onNodePosition:e=>void at(e),onNodesChange:L,onReady:ee,onSelectedAsset:r,onViewportInteraction:ve,showCanvasStatus:de,workspaceRootAssetId:Re})}),N&&a&&(0,W.jsx)(dh,{activeNode:V,brief:y,childAssetId:l,clearNextVariation:Je,closePanel:Ye,latestNodes:ae,linkChild:rt,markReview:Xe,nextVariationLimit:3,noteDirty:pe,onSelectedAsset:r,onToast:i,project:n,refreshBrief:lt,refreshLineage:()=>ze({quiet:!0}),saveRationale:Ge,replaceNextVariation:qe,selectNextBase:Ke,selectedNode:se,selectedNodes:oe,selectionFull:ce,selectionNote:T,setActiveNodeId:c,setChildAssetId:u,setDetailNodeId:f,setSelected:We,setSelectionNote:E,sideOpen:j,snapshot:a}),D&&H&&a&&(0,W.jsx)(Fm,{canRemoveFromLineage:H.asset_id!==a.root_asset_id,claims:yy(x,n,a.root_asset_id),node:H,onClaimControl:(e,t,n)=>{ut(e,t,n)},onClearAllNext:()=>void Je(),onClearNext:()=>void Je(H.asset_id),onClearReroll:()=>void Qe(H),onClose:()=>O(null),onMarkReroll:()=>void Ze(H),onOpenDetail:()=>f(H.asset_id),onRemoveFromLineage:()=>void it(H),onReplaceNext:()=>qe(H),onReview:e=>void Xe(e,H.asset_id),onSelectNext:()=>Ke(H),position:D,selectedCount:oe.length,selectionFull:ce})]}),ue&&a&&(0,W.jsx)(Wm,{actions:{canRemoveFromLineage:ue.asset_id!==a.root_asset_id,onClearAllNext:()=>void Je(),onClearNext:()=>void Je(ue.asset_id),onOpenNode:tt,onRemoveFromLineage:e=>void it(e),onReplaceNext:qe,onReview:Xe,onSelectNext:Ke,onToast:i,selectedCount:oe.length,selectionFull:ce,snapshot:a},attempts:h,node:ue,onClose:et,onPromoteAttempt:nt,project:n}),le&&a&&(0,W.jsx)(Xm,{canRemoveFromLineage:le.asset_id!==a.root_asset_id,node:le,onClearAllNext:()=>void Je(),onClearNext:()=>void Je(le.asset_id),onClose:()=>f(null),onOpenNode:f,onRemoveFromLineage:e=>void it(e),onReplaceNext:qe,onReview:Xe,onSelectNext:Ke,onToast:i,selectedCount:oe.length,selectionFull:ce,snapshot:a}),(0,W.jsx)(th,{onClose:()=>A(!1),onCreated:Oe,onToast:i,open:k,project:n})]})}function yy(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 by(e){return{BT:`bottom to top`,LR:`left to right`,RL:`right to left`,TB:`top to bottom`}[e]}function xy({assets:e,onClose:t,onDone:n,onError:r,project:i}){let a=e[0],[o,s]=(0,g.useState)(!1),[c,l]=(0,g.useState)(!1),[u,d]=(0,g.useState)([]),[f,p]=(0,g.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`}),m=e.filter(e=>!Cy(e)),h=m.length>0||e.length===0;function _(e,t){p(n=>({...n,[e]:t}))}function y(e,t){let n=Ae(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(h){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 v(`/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,W.jsx)(`div`,{className:`drawer-backdrop`,children:(0,W.jsxs)(`section`,{className:`local-backup-drawer`,children:[(0,W.jsxs)(`header`,{children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h2`,{children:`Back up local assets`}),(0,W.jsx)(`p`,{children:i})]}),(0,W.jsx)(`button`,{onClick:t,children:`Close`})]}),(0,W.jsx)(`div`,{className:`local-backup-list`,children:e.map(e=>(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`strong`,{children:Ae(e.title)||e.asset_id}),(0,W.jsx)(`span`,{children:e.local?.relative_path}),(0,W.jsxs)(`span`,{children:[`Review: `,wy(Sy(e))]})]},e.asset_id))}),h&&(0,W.jsxs)(`div`,{className:`local-backup-warning`,role:`alert`,children:[(0,W.jsx)(`strong`,{children:`Backup is locked until local review is approved.`}),e.length===0?(0,W.jsx)(`span`,{children:`No local assets are selected.`}):null,m.map(e=>(0,W.jsxs)(`span`,{children:[Ae(e.title)||e.asset_id,`: `,wy(Sy(e))]},e.asset_id))]}),(0,W.jsxs)(`div`,{className:`form-grid`,children:[(0,W.jsxs)(`label`,{children:[`Campaign`,(0,W.jsx)(`input`,{value:f.campaign,onChange:e=>_(`campaign`,e.target.value)})]}),(0,W.jsxs)(`label`,{children:[`Channel`,(0,W.jsx)(`input`,{value:f.channel,onChange:e=>_(`channel`,e.target.value)})]}),(0,W.jsxs)(`label`,{children:[`Audience`,(0,W.jsx)(`input`,{value:f.audience,onChange:e=>_(`audience`,e.target.value)})]}),(0,W.jsxs)(`label`,{children:[`Status`,(0,W.jsxs)(`select`,{value:f.status,onChange:e=>_(`status`,e.target.value),children:[(0,W.jsx)(`option`,{children:`working`}),(0,W.jsx)(`option`,{children:`published`})]})]}),(0,W.jsxs)(`label`,{className:`wide`,children:[`CTA`,(0,W.jsx)(`input`,{value:f.cta,onChange:e=>_(`cta`,e.target.value)})]})]}),u.length>0&&(0,W.jsx)(`div`,{className:`local-backup-preview`,children:u.map(e=>(0,W.jsx)(`span`,{children:e},e))}),(0,W.jsxs)(`label`,{className:`confirm-line`,children:[(0,W.jsx)(`input`,{checked:o,type:`checkbox`,onChange:e=>s(e.target.checked)}),(0,W.jsx)(`span`,{children:`Confirm write to the production asset bucket`})]}),(0,W.jsxs)(`footer`,{children:[(0,W.jsx)(`button`,{disabled:c||h,onClick:()=>void b(!0),children:`Dry run`}),(0,W.jsxs)(`button`,{className:`primary-button`,disabled:c||h||!o,onClick:()=>void b(!1),children:[c?(0,W.jsx)(pe,{className:`spin`,size:16}):(0,W.jsx)(I,{size:16}),`Back up`]})]})]})})}function Sy(e){return e.review?.review_state||`unreviewed`}function Cy(e){return!!e.local?.relative_path&&Sy(e)===`approved`}function wy(e){return e===`needs_revision`?`needs revision`:e}var Ty=[[`unreviewed`,`Needs review`],[`approved`,`Approved keepers`],[`needs_revision`,`Needs revision`],[`rejected`,`Rejected or ignored`]];function Ey(e){let t=e.assets.filter(e=>e.local?.relative_path&&!e.s3?.key),n=t.filter(e=>ky(e)===`approved`),r=e.selectedBackupIds.length,i=`npx lineage local queue --project ${e.project} --json`;function a(){for(let t of n)e.onQueueBackup(t)}return(0,W.jsxs)(`section`,{className:`local-backup-queue`,children:[(0,W.jsxs)(`header`,{className:`backup-queue-head`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h2`,{children:`Local Backup Queue`}),(0,W.jsx)(`p`,{children:`Review local-only candidates, select approved keepers, then back them up intentionally.`}),(0,W.jsxs)(`p`,{children:[e.snapshot?.catalog.default_bucket||`No bucket loaded`,` · refreshed `,ke(e.snapshot?.fetchedAt)]})]}),(0,W.jsxs)(`div`,{className:`backup-queue-actions`,children:[(0,W.jsxs)(`button`,{disabled:n.length===0,onClick:a,type:`button`,children:[(0,W.jsx)(P,{size:15}),` Select approved`]}),(0,W.jsxs)(`button`,{disabled:r===0,onClick:e.onOpenBackup,type:`button`,children:[(0,W.jsx)(I,{size:15}),` Back up selected`]})]})]}),(0,W.jsxs)(`div`,{className:`backup-queue-stats`,"aria-label":`Local backup queue summary`,children:[(0,W.jsx)(Oy,{label:`Local only`,value:t.length}),(0,W.jsx)(Oy,{label:`Needs review`,value:t.filter(e=>ky(e)===`unreviewed`).length}),(0,W.jsx)(Oy,{label:`Approved`,value:n.length}),(0,W.jsx)(Oy,{label:`Selected`,value:r})]}),(0,W.jsxs)(`div`,{className:`handoff-strip`,children:[(0,W.jsx)(`code`,{children:i}),(0,W.jsxs)(`button`,{onClick:()=>void e.onCopy(i,`local backup queue command`),type:`button`,children:[(0,W.jsx)(F,{size:14}),` Copy`]})]}),t.length===0?(0,W.jsx)(`div`,{className:`backup-empty`,children:`No local-only assets are waiting for review or backup.`}):(0,W.jsx)(`div`,{className:`backup-queue-grid`,children:Ty.map(([n,r])=>(0,W.jsxs)(`section`,{className:`backup-queue-lane`,children:[(0,W.jsx)(`h3`,{children:r}),t.filter(e=>Ay(e)===n).map(t=>(0,W.jsx)(Dy,{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,W.jsxs)(`footer`,{className:`pagination-bar`,children:[(0,W.jsx)(`button`,{disabled:!e.snapshot||e.snapshot.pagination.page<=1,onClick:()=>e.setPage(e=>Math.max(e-1,1)),type:`button`,children:`Previous`}),(0,W.jsxs)(`span`,{children:[e.snapshot?.pagination.page||e.page,` of `,e.snapshot?.pagination.totalPages||1]}),(0,W.jsx)(`button`,{disabled:!e.snapshot||e.snapshot.pagination.page>=e.snapshot.pagination.totalPages,onClick:()=>e.setPage(e=>e+1),type:`button`,children:`Next`}),(0,W.jsxs)(`label`,{children:[`Per page`,(0,W.jsx)(`select`,{onChange:t=>e.setPageSize(Number(t.target.value)),value:e.pageSize,children:[10,25,50,100].map(e=>(0,W.jsx)(`option`,{value:e,children:e},e))})]})]})]})}function Dy(e){let t=ky(e.asset),n=Re(e.asset),r=t===`approved`;return(0,W.jsxs)(`article`,{className:`backup-queue-card ${e.selected?`selected`:``}`,children:[(0,W.jsx)(`strong`,{children:e.asset.title}),(0,W.jsx)(`code`,{children:e.asset.asset_id}),(0,W.jsx)(`small`,{children:e.asset.local?.relative_path}),(0,W.jsxs)(`div`,{className:`backup-card-meta`,children:[(0,W.jsx)(`span`,{children:n.label}),(0,W.jsx)(`span`,{children:jy(t)}),(0,W.jsx)(`span`,{children:Oe(e.asset.local?.size_bytes)})]}),(0,W.jsxs)(`div`,{className:`backup-card-actions`,children:[(0,W.jsx)(`button`,{onClick:()=>e.onSelectAsset(e.asset),type:`button`,children:`Open`}),(0,W.jsx)(`button`,{"aria-pressed":t===`approved`,onClick:()=>void e.onLocalReview(e.asset,`approved`),type:`button`,children:`Approve`}),(0,W.jsx)(`button`,{"aria-pressed":t===`needs_revision`,onClick:()=>void e.onLocalReview(e.asset,`needs_revision`),type:`button`,children:`Revise`}),(0,W.jsx)(`button`,{"aria-pressed":t===`rejected`,onClick:()=>void e.onLocalReview(e.asset,`rejected`),type:`button`,children:`Reject`}),(0,W.jsx)(`button`,{disabled:!r,onClick:()=>e.onQueueBackup(e.asset),type:`button`,children:e.selectedForBackup?`Selected`:r?`Select backup`:`Approve first`})]})]})}function Oy({label:e,value:t}){return(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`strong`,{children:t}),(0,W.jsx)(`span`,{children:e})]})}function ky(e){return e.review?.review_state||`unreviewed`}function Ay(e){let t=ky(e);return t===`ignored`?`rejected`:t}function jy(e){return e===`needs_revision`?`needs revision`:e}function My({assets:e,onClear:t,onOpen:n}){return e.length===0?null:(0,W.jsxs)(`div`,{className:`local-selection-toolbar`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(`strong`,{children:[e.length,` local keeper`,e.length===1?``:`s`,` selected`]}),(0,W.jsx)(`span`,{children:`Ready for S3 backup preflight`})]}),(0,W.jsxs)(`button`,{onClick:n,children:[(0,W.jsx)(I,{size:16}),`Back up selected`]}),(0,W.jsx)(`button`,{"aria-label":`Clear local backup selection`,className:`icon-lite`,onClick:t,children:(0,W.jsx)(De,{size:16})})]})}function Ny(e){return e.find(e=>Py(e)>0)?.channel||e[0]?.channel}function Py(e){return e.totals.needsQa+e.totals.approvedLocal+e.totals.needsRevision+e.totals.rejectedLocal}var Fy=[[`needsQa`,`Needs QA`],[`approvedLocal`,`Approved`],[`needsRevision`,`Revise`],[`rejectedLocal`,`Rejected`],[`readyToPost`,`S3 ready`],[`scheduled`,`Scheduled`],[`posted`,`Posted`]];function Iy(e){let[t,n]=(0,g.useState)(null),[r,i]=(0,g.useState)(null),[a,o]=(0,g.useState)(null),[s,c]=(0,g.useState)([]),[l,u]=(0,g.useState)(``);async function d(){try{let t=new URLSearchParams({project:e.project,limit:`4`});e.channel!==`all`&&t.set(`channel`,e.channel),n(await v(`/api/review/queue?${t.toString()}`)),i(null)}catch(e){i(e instanceof Error?e.message:String(e))}}if((0,g.useEffect)(()=>{d()},[e.project,e.channel]),r)return(0,W.jsx)(`section`,{className:`review-queue`,children:(0,W.jsx)(`div`,{className:`toast error`,children:r})});if(!t)return(0,W.jsx)(`section`,{className:`review-queue`,children:(0,W.jsx)(`div`,{className:`asset-board`,children:(0,W.jsx)(`div`,{className:`board-head`,children:(0,W.jsx)(`h2`,{children:`Loading review queue`})})})});let f=t.totals.needsQa+t.totals.approvedLocal+t.totals.needsRevision+t.totals.rejectedLocal,p=new Set(t.lanes.flatMap(e=>[...e.needsQa,...e.approvedLocal,...e.needsRevision,...e.rejectedLocal]).map(e=>e.asset_id)),m=s.filter(e=>p.has(e)),h=Ny(t.lanes);function _(e){c(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])}async function y(t){if(m.length!==0){o(`batch`);try{await v(`/api/local-review/batch`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({assetIds:m,confirmWrite:!0,notes:l,project:e.project,reviewState:t})}),c(e=>e.filter(e=>!p.has(e))),u(``),await d()}finally{o(null)}}}return(0,W.jsxs)(`section`,{className:`review-queue`,children:[(0,W.jsxs)(`div`,{className:`review-summary`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(`h2`,{children:[t.project,` review queue`]}),(0,W.jsx)(`p`,{children:`Local-first queue for demo assets, channel posting state, and agent handoff.`}),(0,W.jsxs)(`p`,{children:[t.totals.channels,` channels · refreshed `,ke(t.fetchedAt)]})]}),(0,W.jsx)(Ly,{label:`Local review`,value:f}),(0,W.jsx)(Ly,{label:`S3 ready`,value:t.totals.readyToPost}),(0,W.jsx)(Ly,{label:`Scheduled`,value:t.totals.scheduled}),(0,W.jsx)(Ly,{label:`Posted`,value:t.totals.posted})]}),m.length>0?(0,W.jsxs)(`div`,{className:`batch-review-strip`,"aria-label":`Batch local review actions`,children:[(0,W.jsxs)(`strong`,{children:[m.length,` selected`]}),(0,W.jsx)(`textarea`,{"aria-label":`Shared batch review notes`,onChange:e=>u(e.target.value),placeholder:`Shared review notes`,rows:2,value:l}),(0,W.jsx)(`button`,{disabled:m.length===0||a===`batch`,onClick:()=>void y(`approved`),type:`button`,children:`Approve`}),(0,W.jsx)(`button`,{disabled:m.length===0||a===`batch`,onClick:()=>void y(`needs_revision`),type:`button`,children:`Needs revision`}),(0,W.jsx)(`button`,{disabled:m.length===0||a===`batch`,onClick:()=>void y(`rejected`),type:`button`,children:`Reject`})]}):null,(0,W.jsx)(`div`,{className:`queue-lanes`,children:t.lanes.map(t=>(0,W.jsxs)(`details`,{className:`queue-lane`,open:e.channel!==`all`||t.channel===h,children:[(0,W.jsxs)(`summary`,{children:[(0,W.jsx)(`h3`,{children:t.channel}),(0,W.jsxs)(`div`,{className:`lane-counts`,children:[(0,W.jsxs)(`span`,{children:[t.totals.needsQa,` qa`]}),(0,W.jsxs)(`span`,{children:[t.totals.approvedLocal,` approved`]}),(0,W.jsxs)(`span`,{children:[t.totals.needsRevision,` revise`]}),(0,W.jsxs)(`span`,{children:[t.totals.readyToPost,` ready`]}),(0,W.jsxs)(`span`,{children:[t.totals.scheduled,` scheduled`]}),(0,W.jsxs)(`span`,{children:[t.totals.posted,` posted`]})]})]}),(0,W.jsxs)(`div`,{className:`queue-columns`,children:[Fy.filter(([e])=>t[e].length>0).map(([n,r])=>(0,W.jsx)(Ry,{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:m,onToggleReviewSelection:_},n)),Fy.every(([e])=>t[e].length===0)&&(0,W.jsx)(`p`,{className:`review-empty`,children:`No items in this channel.`})]})]},t.channel))})]})}function Ly({label:e,value:t}){return(0,W.jsxs)(`div`,{className:`queue-stat`,children:[(0,W.jsx)(`strong`,{children:t}),(0,W.jsx)(`span`,{children:e})]})}function Ry(e){return(0,W.jsxs)(`div`,{className:`queue-column`,children:[(0,W.jsx)(`h4`,{children:e.label}),e.assets.map(t=>(0,W.jsx)(zy,{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 zy(e){let t=Re(e.asset),n=e.asset.local?By(e.asset):null,r=n===`approved`,i=e.asset.source===`local`?`npx lineage local inspect --asset-id ${e.asset.asset_id} --json`:`npx lineage inspect --asset-id ${e.asset.asset_id} --json`;return(0,W.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:[n?(0,W.jsxs)(`label`,{className:`confirm-line`,onClick:e=>e.stopPropagation(),onKeyDown:Gy,children:[(0,W.jsx)(`input`,{checked:e.selectedForReview,onChange:()=>e.onToggleReviewSelection(e.asset.asset_id),type:`checkbox`}),(0,W.jsx)(`span`,{children:`Select for batch review`})]}):null,(0,W.jsx)(`strong`,{children:e.asset.title}),(0,W.jsx)(`small`,{children:e.asset.asset_id}),(0,W.jsxs)(`div`,{className:`lane-counts`,children:[(0,W.jsx)(`span`,{className:`storage-chip ${t.kind}`,children:t.label}),(0,W.jsx)(`span`,{className:`queue-tag`,children:We(e.asset)}),n?(0,W.jsx)(`span`,{className:`review-chip ${n}`,children:Vy(n)}):null]}),n?(0,W.jsxs)(`div`,{className:`review-actions`,"aria-label":`Local review actions for ${e.asset.title}`,onKeyDown:Gy,children:[(0,W.jsx)(`button`,{"aria-pressed":n===`approved`,disabled:e.pendingReview,type:`button`,onClick:t=>Uy(t,e.onLocalReview,e.asset,`approved`),children:`Approve`}),(0,W.jsx)(`button`,{"aria-pressed":n===`needs_revision`,disabled:e.pendingReview,type:`button`,onClick:t=>Uy(t,e.onLocalReview,e.asset,`needs_revision`),children:`Needs revision`}),(0,W.jsx)(`button`,{"aria-pressed":n===`rejected`,disabled:e.pendingReview,type:`button`,onClick:t=>Uy(t,e.onLocalReview,e.asset,`rejected`),children:`Reject`})]}):null,(0,W.jsxs)(`div`,{className:`queue-actions`,onKeyDown:Gy,children:[(0,W.jsx)(`button`,{type:`button`,onClick:t=>Hy(t,e.onCopy,i),children:`Copy inspect`}),e.asset.local?r?(0,W.jsx)(`button`,{type:`button`,onClick:t=>Wy(t,e.onOpenBackup,e.asset),children:`Back up`}):(0,W.jsx)(`span`,{className:`backup-locked`,title:`Approve this local asset before backup`,children:`Backup locked until approved.`}):null]})]})}function By(e){return e.review?.review_state||`unreviewed`}function Vy(e){return e===`needs_revision`?`needs revision`:e}function Hy(e,t,n){e.stopPropagation(),t(n,`inspect command`)}function Uy(e,t,n,r){e.stopPropagation(),t(n,r)}function Wy(e,t,n){e.stopPropagation(),t(n)}function Gy(e){(e.key===`Enter`||e.key===` `)&&e.stopPropagation()}var Ky={channel:`dev`,version:`0.1.12`},qy={cloud:L,image_generator:ue,scheduler:be},Jy={cloud:`Cloud storage`,image_generator:`Image generation`,scheduler:`Social scheduling`},Yy=[{adapterType:`cloud`,ariaLabel:`Cloud storage settings`},{adapterType:`scheduler`,ariaLabel:`Social scheduling settings`},{adapterType:`image_generator`,ariaLabel:`Image generation settings`}];function Xy(e){return typeof e==`boolean`?e?`on`:`off`:typeof e==`number`?String(e):typeof e==`string`?e||`not set`:JSON.stringify(e)}function Zy(e){return Object.entries(e.safe_config).filter(([e])=>![`secret`,`token`,`password`,`credential`,`apiKey`].includes(e))}function Qy(e){return e.health_status===`configured`?`ok`:e.health_status===`missing_config`?`warn`:`muted`}function $y(e){return(0,W.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,W.jsx)(`span`,{})})}function eb(e){let[t,n]=(0,g.useState)(null),[r,i]=(0,g.useState)(null),[a,o]=(0,g.useState)(!0),[s,c]=(0,g.useState)(``);async function l(){o(!0);try{let[t,r]=await Promise.all([v(`/api/adapters/settings?project=${encodeURIComponent(e.project)}`),v(`/api/runtime`)]);n(t),i(r.runtime)}catch(t){e.onToast(`error`,t instanceof Error?t.message:String(t))}finally{o(!1)}}async function u(t){let r=`${t.adapter_type}:${t.provider}`;c(r);try{let r=await v(`/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`,`${Jy[t.adapter_type]} ${r.setting.enabled?`enabled`:`disabled`}`)}catch(t){e.onToast(`error`,t instanceof Error?t.message:String(t))}finally{c(``)}}return(0,g.useEffect)(()=>{l()},[e.project]),(0,W.jsxs)(`section`,{className:`settings-view`,children:[(0,W.jsxs)(`header`,{className:`settings-header`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h2`,{children:`Settings`}),(0,W.jsxs)(`p`,{children:[`Adapter switches, safe local preferences, and credential-source status for `,e.project,`.`]})]}),(0,W.jsxs)(`button`,{className:`secondary-button`,disabled:a,onClick:()=>void l(),type:`button`,children:[a?(0,W.jsx)(pe,{className:`spin`,size:17}):(0,W.jsx)(ve,{size:17}),`Refresh`]})]}),(0,W.jsxs)(`div`,{className:`settings-sections`,children:[(0,W.jsxs)(`section`,{"aria-label":`Release information`,className:`settings-section`,children:[(0,W.jsx)(`h3`,{children:`Release`}),(0,W.jsxs)(`dl`,{className:`settings-release`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`dt`,{children:`Version`}),(0,W.jsx)(`dd`,{children:r?.version||Ky.version})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`dt`,{children:`Channel`}),(0,W.jsx)(`dd`,{children:r?.channel||Ky.channel})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`dt`,{children:`Profile`}),(0,W.jsx)(`dd`,{children:r?.profile.id||`loading`})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`dt`,{children:`Environment`}),(0,W.jsx)(`dd`,{children:r?.profile.environment||`loading`})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`dt`,{children:`Binding`}),(0,W.jsx)(`dd`,{children:r?r.profile.bound?`bound`:`legacy unbound`:`loading`})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`dt`,{children:`Git`}),(0,W.jsx)(`dd`,{children:r?.git_sha||`not available`})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`dt`,{children:`Assets`}),(0,W.jsx)(`dd`,{className:`settings-path`,children:r?.asset_root||`loading`})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`dt`,{children:`SQLite`}),(0,W.jsx)(`dd`,{className:`settings-path`,children:r?.database.path||`loading`})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`dt`,{children:`Database`}),(0,W.jsx)(`dd`,{children:r?.database.exists?`${r.database.projects??0} projects / ${r.database.workspaces??0} workspaces`:`not created yet`})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`dt`,{children:`Schema`}),(0,W.jsx)(`dd`,{children:r?`${r.schema.migration_keys.length} migration marker(s)`:`loading`})]})]})]}),Yy.map(e=>(0,W.jsxs)(`section`,{"aria-label":e.ariaLabel,className:`settings-section`,children:[(0,W.jsx)(`h3`,{children:Jy[e.adapterType]}),(0,W.jsx)(`div`,{className:`settings-grid`,children:(t?.settings||[]).filter(t=>t.adapter_type===e.adapterType).map(e=>{let t=qy[e.adapter_type],n=`Enable ${e.label===`Buffer`?`Buffer scheduling`:e.label}`,r=s===`${e.adapter_type}:${e.provider}`;return(0,W.jsxs)(`article`,{className:`settings-card`,children:[(0,W.jsxs)(`div`,{className:`settings-card-head`,children:[(0,W.jsx)(`span`,{className:`settings-icon`,children:(0,W.jsx)(t,{size:19})}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h4`,{children:e.label}),(0,W.jsx)(`p`,{children:e.description})]}),(0,W.jsx)($y,{checked:e.enabled,disabled:r,label:n,onClick:()=>void u(e)})]}),(0,W.jsxs)(`dl`,{className:`settings-meta`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`dt`,{children:`Status`}),(0,W.jsxs)(`dd`,{className:Qy(e),children:[e.health_status===`configured`?(0,W.jsx)(P,{size:14}):(0,W.jsx)(N,{size:14}),e.health_status.replace(/_/g,` `)]})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`dt`,{children:`Credential source`}),(0,W.jsx)(`dd`,{children:e.credential.label})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`dt`,{children:`Secret ref`}),(0,W.jsx)(`dd`,{children:e.credential.secret_ref||`none`})]})]}),Zy(e).length>0&&(0,W.jsx)(`div`,{className:`settings-config`,children:Zy(e).map(([e,t])=>(0,W.jsxs)(`span`,{children:[(0,W.jsx)(`strong`,{children:e}),Xy(t)]},e))})]},`${e.adapter_type}:${e.provider}`)})})]},e.adapterType)),a&&!t&&(0,W.jsx)(`div`,{className:`settings-loading`,children:`Loading settings...`})]})]})}var tb=`Lineage`,nb=`Local-first creative lineage workspace`;function rb(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,[p,m]=(0,g.useState)(!1),[h,_]=(0,g.useState)(!0),v=a.length?a.map(e=>e.project):[i];return(0,W.jsxs)(`aside`,{className:`sidebar ${h?``:`collapsed`}`,children:[(0,W.jsx)(`button`,{"aria-label":h?`Collapse sidebar`:`Expand sidebar`,className:`sidebar-collapse-toggle`,onClick:()=>_(e=>!e),type:`button`,children:h?(0,W.jsx)(he,{size:16}):(0,W.jsx)(ge,{size:16})}),(0,W.jsxs)(`div`,{className:`brand`,children:[(0,W.jsx)(`div`,{className:`brand-mark`,"aria-label":nb,children:`L`}),(0,W.jsxs)(`div`,{className:`brand-copy`,children:[(0,W.jsx)(`h1`,{children:tb}),(0,W.jsxs)(`p`,{children:[(0,W.jsx)(`span`,{children:i}),(0,W.jsxs)(`span`,{"aria-label":`Lineage version ${Ky.version}`,className:`brand-version`,title:`Lineage version ${Ky.version}, ${Ky.channel} channel`,children:[`v`,Ky.version]})]})]})]}),(0,W.jsxs)(`button`,{"aria-controls":`mobile-sidebar-controls`,"aria-expanded":p,className:`mobile-filter-toggle`,onClick:()=>m(e=>!e),type:`button`,children:[(0,W.jsx)(Se,{size:16}),`Filters`,(0,W.jsx)(A,{className:p?`open`:``,size:16})]}),(0,W.jsxs)(`div`,{className:`sidebar-mobile-collapse`,"data-open":p,id:`mobile-sidebar-controls`,children:[(0,W.jsxs)(`div`,{className:`side-section`,children:[(0,W.jsx)(`h2`,{children:`Project`}),(0,W.jsx)(ib,{id:`asset-project-filter`,label:`Project`,value:i,values:v,onChange:c})]}),(0,W.jsxs)(`section`,{className:`side-section`,children:[(0,W.jsx)(`h2`,{children:`Filters`}),(0,W.jsx)(ib,{id:`asset-source-filter`,label:`Source`,value:d,values:Pe,onChange:e=>l(e)}),(0,W.jsx)(ib,{id:`asset-status-filter`,label:`Status`,value:f,values:Me,onChange:e=>u(e)}),(0,W.jsx)(ib,{id:`asset-channel-filter`,label:`Channel`,value:t,values:n,onChange:o}),(0,W.jsx)(ib,{id:`asset-placement-filter`,label:`Placement`,value:r,values:Ne,onChange:e=>s(e)})]})]})]})}function ib({id:e,label:t,value:n,values:r,onChange:i}){return(0,W.jsxs)(`label`,{htmlFor:e,children:[t,(0,W.jsx)(`select`,{"aria-label":t,id:e,value:n,onChange:e=>i(e.target.value),children:r.map(e=>(0,W.jsx)(`option`,{value:e,children:e},e))})]})}var ab=[{label:`Lineage`,view:`lineage`},{label:`Review`,view:`review`},{label:`Assets`,view:`assets`},{label:`Agents`,view:`agents`},{label:`Settings`,view:`settings`}],ob=[{label:`Ledger`,view:`ledger`},{label:`Content batches`,view:`content`},{label:`Backup queue`,view:`backup`}];function sb(e){let[t,n]=(0,g.useState)(!1),r=ob.some(t=>t.view===e.view);function i(t){e.setView(t),n(!1)}function a(t){e.setView(t),n(!1)}return(0,W.jsxs)(`header`,{className:`topbar`,children:[(0,W.jsxs)(`div`,{className:`view-tabs`,role:`tablist`,"aria-label":`${tb} views`,children:[ab.map(t=>(0,W.jsx)(`button`,{"aria-pressed":e.view===t.view,className:e.view===t.view?`active`:``,onClick:()=>i(t.view),type:`button`,children:t.label},t.view)),(0,W.jsxs)(`div`,{className:`more-menu`,children:[(0,W.jsxs)(`button`,{"aria-expanded":t,"aria-haspopup":`menu`,"aria-pressed":r,className:r?`active`:``,onClick:()=>n(e=>!e),type:`button`,children:[(0,W.jsx)(te,{size:16}),` More `,(0,W.jsx)(A,{className:t?`open`:``,size:15})]}),t&&(0,W.jsx)(`div`,{className:`more-menu-popover`,role:`menu`,children:ob.map(t=>(0,W.jsx)(`button`,{"aria-pressed":e.view===t.view,onClick:()=>a(t.view),role:`menuitem`,type:`button`,children:t.label},t.view))})]})]}),(0,W.jsx)(cb,{runtime:e.runtime,unavailable:e.runtimeIdentityUnavailable}),(0,W.jsxs)(`div`,{className:`searchbox`,children:[(0,W.jsx)(ye,{size:17}),(0,W.jsx)(`input`,{onChange:t=>e.setQuery(t.target.value),placeholder:`Search assets, campaigns, hooks`,value:e.query})]}),e.view!==`lineage`&&(0,W.jsxs)(`button`,{"aria-expanded":e.assetDetailsOpen,className:`secondary-button`,disabled:!e.canInspectAsset,onClick:()=>{n(!1),e.setAssetDetailsOpen(!e.assetDetailsOpen)},type:`button`,children:[(0,W.jsx)(ae,{size:17}),`Details`]}),(0,W.jsx)(`button`,{className:`icon-button`,disabled:e.loading,onClick:()=>void e.refresh(),title:`Refresh current page`,children:e.loading?(0,W.jsx)(pe,{className:`spin`,size:18}):(0,W.jsx)(ve,{size:18})}),(0,W.jsxs)(`button`,{className:`primary-button`,onClick:()=>e.setUploadOpen(!0),children:[(0,W.jsx)(Ee,{size:17}),`Upload`]})]})}function cb(e){if(e.unavailable)return(0,W.jsx)(`div`,{"aria-label":`Lineage runtime identity unavailable`,className:`runtime-identity-badge unavailable`,children:`IDENTITY UNAVAILABLE`});if(!e.runtime)return(0,W.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,W.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,W.jsx)(`strong`,{children:t.environment.toUpperCase()}),(0,W.jsxs)(`span`,{children:[t.id,n]})]})}function lb({toast:e,onDismiss:t}){return(0,W.jsxs)(`div`,{className:`toast ${e.type}`,role:`status`,children:[e.type===`ok`?(0,W.jsx)(P,{size:16}):(0,W.jsx)(xe,{size:16}),(0,W.jsx)(`span`,{children:e.message}),(0,W.jsx)(`button`,{onClick:t,children:`Dismiss`})]})}var ub=200*1024*1024;function db({channels:e,project:t,onClose:n,onUploaded:r,onError:i}){let[a,o]=(0,g.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,g.useState)(null),[l,u]=(0,g.useState)(!1),[d,f]=(0,g.useState)(!1);function p(e,t){o(n=>({...n,[e]:t}))}function m(e){o(t=>({...t,assetId:t.assetId||Ae(`demo-${t.channel}-${e}`),title:e,utmContent:t.utmContent||Ae(e).replaceAll(`-`,`_`)}))}function h(e){if(!e){c(null);return}if(e.size>ub){i(`File is larger than ${Oe(ub)}`);return}c(e)}async function _(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 v(`/api/assets/upload`,{method:`POST`,body:e})).message)}catch(e){i(e instanceof Error?e.message:String(e))}finally{f(!1)}}return(0,W.jsx)(`div`,{className:`drawer-backdrop`,children:(0,W.jsxs)(`form`,{className:`upload-drawer`,onSubmit:_,children:[(0,W.jsxs)(`header`,{children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h2`,{children:`Upload asset`}),(0,W.jsx)(`p`,{children:t})]}),(0,W.jsx)(`button`,{type:`button`,onClick:n,children:`Close`})]}),(0,W.jsxs)(`label`,{className:`file-drop`,children:[(0,W.jsx)(Ee,{size:20}),(0,W.jsx)(`span`,{children:s?s.name:`Choose creative export up to ${Oe(ub)}`}),(0,W.jsx)(`input`,{type:`file`,onChange:e=>h(e.target.files?.[0])})]}),(0,W.jsxs)(`div`,{className:`form-grid`,children:[(0,W.jsxs)(`label`,{children:[`Title`,(0,W.jsx)(`input`,{value:a.title,onChange:e=>m(e.target.value),required:!0})]}),(0,W.jsxs)(`label`,{children:[`Asset ID`,(0,W.jsx)(`input`,{value:a.assetId,onChange:e=>p(`assetId`,e.target.value),required:!0})]}),(0,W.jsxs)(`label`,{children:[`Campaign`,(0,W.jsx)(`input`,{value:a.campaign,onChange:e=>p(`campaign`,e.target.value),required:!0})]}),(0,W.jsxs)(`label`,{children:[`Channel`,(0,W.jsx)(`select`,{value:a.channel,onChange:e=>p(`channel`,e.target.value),children:e.map(e=>(0,W.jsx)(`option`,{children:e},e))})]}),(0,W.jsxs)(`label`,{children:[`Audience`,(0,W.jsx)(`input`,{value:a.audience,onChange:e=>p(`audience`,e.target.value),required:!0})]}),(0,W.jsxs)(`label`,{children:[`Status`,(0,W.jsxs)(`select`,{value:a.status,onChange:e=>p(`status`,e.target.value),children:[(0,W.jsx)(`option`,{children:`working`}),(0,W.jsx)(`option`,{children:`published`})]})]}),(0,W.jsxs)(`label`,{children:[`Type`,(0,W.jsx)(`select`,{value:a.type,onChange:e=>p(`type`,e.target.value),children:Fe.map(e=>(0,W.jsx)(`option`,{children:e},e))})]}),(0,W.jsxs)(`label`,{children:[`UTM content`,(0,W.jsx)(`input`,{value:a.utmContent,onChange:e=>p(`utmContent`,e.target.value),required:!0})]}),(0,W.jsxs)(`label`,{className:`wide`,children:[`Hook`,(0,W.jsx)(`input`,{value:a.hook,onChange:e=>p(`hook`,e.target.value)})]}),(0,W.jsxs)(`label`,{className:`wide`,children:[`CTA`,(0,W.jsx)(`input`,{value:a.cta,onChange:e=>p(`cta`,e.target.value),required:!0})]})]}),(0,W.jsxs)(`label`,{className:`confirm-line`,children:[(0,W.jsx)(`input`,{type:`checkbox`,checked:l,onChange:e=>u(e.target.checked)}),(0,W.jsx)(`span`,{children:`Confirm write to the production asset bucket`})]}),(0,W.jsxs)(`footer`,{children:[(0,W.jsx)(`button`,{type:`button`,onClick:n,children:`Cancel`}),(0,W.jsxs)(`button`,{className:`primary-button`,disabled:d||!l,children:[d?(0,W.jsx)(pe,{className:`spin`,size:16}):(0,W.jsx)(Ee,{size:16}),`Upload`]})]})]})})}function fb(e,t){let n=`${e} ${t}`.toLowerCase();return n.includes(`agent`)||n.includes(`command`)||n.includes(`selection`)||n.includes(`next context`)}function pb(){return typeof window>`u`?je:new URLSearchParams(window.location.search).get(`project`)||`demo-project`}function mb(){let[e,t]=(0,g.useState)(null),[n,r]=(0,g.useState)(null),[i,a]=(0,g.useState)(pb),[o,s]=(0,g.useState)([]),[c,l]=(0,g.useState)(`all`),[u,d]=(0,g.useState)(`all`),[f,p]=(0,g.useState)(`local`),[m,h]=(0,g.useState)(`all`),[_,x]=(0,g.useState)(``),[S,C]=(0,g.useState)(1),[w,T]=(0,g.useState)(10),[E,D]=(0,g.useState)(!1),[O,k]=(0,g.useState)(!0),[A,j]=(0,g.useState)(null),[M,N]=(0,g.useState)(null),[P,F]=(0,g.useState)({}),[I,L]=(0,g.useState)({}),[R,z]=(0,g.useState)([]),[B,ee]=(0,g.useState)([]),[te,ne]=(0,g.useState)(!1),[re,ie]=(0,g.useState)(!1),[V,ae]=(0,g.useState)(`lineage`),[oe,se]=(0,g.useState)(!1),[ce,le]=(0,g.useState)(null),[ue,H]=(0,g.useState)(0),[de,fe]=(0,g.useState)(null),[pe,me]=(0,g.useState)(!1),he=e?.catalog.project===i?e:null,ge=he?.assets||[],U=Be(ge,n)||(ce?.project===i&&ce.asset_id===n?ce:void 0),_e=U?.asset_id||``,ve=[...B.filter(e=>R.includes(e.asset_id)),...ge.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),ye=U&&P[U.asset_id]||null,be=(0,g.useMemo)(()=>[`all`,...he?.facets.channels||[]],[he]),xe=(0,g.useMemo)(()=>({assets:he?.catalog.asset_count||0,live:he?.liveObjects.length||0,orphan:he?.orphanObjects.length||0,size:he?.facets.totalSizeBytes||0}),[he]);async function Se(){try{let e=await v(`/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 Ce(){try{let e=await v(`/api/runtime`);fe(e.runtime),me(!1)}catch{fe(null),me(!0)}}async function we(){k(!0);try{let e=await v(`/api/assets?${Te()}`);t(e),r(t=>Be(e.assets,t)?.asset_id||(t&&ce?.asset_id===t?t:null)),F({}),L({})}catch(e){j({type:`error`,message:e instanceof Error?e.message:String(e)})}finally{k(!1)}}function Te(){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),m!==`all`&&e.set(`channel`,m),_.trim()&&e.set(`q`,_.trim()),e.toString()}async function Ee(e){try{let t=await e();j({type:`ok`,message:t.message}),F({}),await we()}catch(e){j({type:`error`,message:e instanceof Error?e.message:String(e)})}}async function De(e,t={}){if(!Ve(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 v(`/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 Oe(e,t){try{let n=await Bm(e);j({type:`ok`,message:n.method===`fallback`?`Copied ${t} using browser fallback`:`Copied ${t}`}),N(fb(t,e)?{label:t,text:e}:null)}catch(n){N(fb(t,e)?{label:t,text:e}:null),j({type:`error`,message:n instanceof Error?n.message:String(n)})}}async function ke(e){let t=await De(e,{quiet:!0});t&&await Oe(t,`preview link`)}function Ae(e){e.local?.relative_path&&(z(t=>t.includes(e.asset_id)?t:[...t,e.asset_id]),ee(t=>t.some(t=>t.asset_id===e.asset_id)?t:[...t,e]))}function je(e){le(e),r(e.asset_id),se(!0)}async function Me(e){r(e),se(!0);let t=ge.find(t=>t.asset_id===e);if(t){le(t);return}try{let t=await v(`/api/assets/lookup`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:i,assetIds:[e]})});t.assets[0]&&le(t.assets[0])}catch(e){j({type:`error`,message:e instanceof Error?e.message:String(e)})}}function Ne(){p(`local`),l(`all`),d(`all`),x(``),ae(`backup`)}async function Pe(e){try{e.assetId&&r(e.assetId),e.view===`lineage`&&e.workspaceId&&await v(`/api/lineage-workspaces/${encodeURIComponent(e.workspaceId)}/activate`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:i,confirmWrite:!0})}),se(!1),ae(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 Fe(e){e.local?.relative_path&&(z(t=>t.includes(e.asset_id)?t.filter(t=>t!==e.asset_id):[...t,e.asset_id]),ee(t=>t.filter(t=>t.asset_id!==e.asset_id)))}return(0,g.useEffect)(()=>{Se(),Ce()},[]),(0,g.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,g.useEffect)(()=>{j(null),N(null),le(null),se(!1)},[i]),(0,g.useEffect)(()=>{we()},[S,w,i,c,u,f,m,_,E]),(0,g.useEffect)(()=>{C(1)},[i,c,u,f,m,_,w]),(0,g.useEffect)(()=>{!Ve(U)||P[U.asset_id]||De(U,{quiet:!0})},[U?.asset_id,U?.s3?.version_id,P]),(0,g.useEffect)(()=>{if(A?.type!==`ok`)return;let e=window.setTimeout(()=>j(null),2600);return()=>window.clearTimeout(e)},[A?.message,A?.type]),(0,g.useEffect)(()=>{V===`backup`&&(p(`local`),l(`all`),d(`all`))},[V]),(0,g.useEffect)(()=>{_e||se(!1)},[_e]),(0,W.jsxs)(`div`,{className:`app-shell ${V===`lineage`?`lineage-mode`:``}`,children:[(0,W.jsx)(rb,{channel:m,channels:be,liveSync:E,placementStatus:u,project:i,projects:o,setChannel:h,setPlacementStatus:d,setProject:a,setSource:p,setStatus:l,setView:ae,showBackupQueue:Ne,source:f,snapshot:he,status:c,totals:xe}),(0,W.jsxs)(`main`,{className:`workspace`,children:[(0,W.jsx)(sb,{assetDetailsOpen:oe,canInspectAsset:!!U,loading:O,query:_,refresh:we,runtime:de,runtimeIdentityUnavailable:pe,setAssetDetailsOpen:se,setQuery:x,setUploadOpen:ie,setView:e=>e===`backup`?Ne():ae(e),view:V}),A&&(0,W.jsx)(lb,{toast:A,onDismiss:()=>j(null)}),M&&(0,W.jsx)(Rt,{copiedText:M,onDismiss:()=>N(null)}),(0,W.jsx)(Ut,{onCopy:Oe,project:i,refreshKey:ue,selectedAsset:U,view:V}),V===`review`?(0,W.jsx)(Iy,{channel:m,onCopy:Oe,onLocalReview:async(e,t)=>{await Ee(()=>y(`/api/local-review/${e.asset_id}`,i,{reviewState:t,confirmWrite:!0}))},onOpenBackup:e=>{Ae(e),ne(!0)},onSelectAsset:e=>{je(e)},project:i,selected:U}):V===`ledger`?(0,W.jsx)(nn,{project:i,query:_,onOpenAsset:Me}):V===`content`?(0,W.jsx)(Nt,{onCopy:Oe,onOpenAsset:Me,onToast:(e,t)=>j({type:e,message:t}),onWorkTargetsChanged:()=>H(e=>e+1),project:i,selectedAsset:U}):V===`agents`?(0,W.jsx)(nt,{onCopy:Oe,onOpenWork:Pe,project:i}):V===`backup`?(0,W.jsx)(Ey,{assets:ge,onCopy:Oe,onLocalReview:async(e,t)=>{await Ee(()=>y(`/api/local-review/${e.asset_id}`,i,{reviewState:t,confirmWrite:!0}))},onOpenBackup:()=>ne(!0),onQueueBackup:Ae,onSelectAsset:e=>{je(e)},page:S,pageSize:w,project:i,selected:U,selectedBackupIds:R,setPage:C,setPageSize:T,snapshot:he}):V===`assets`?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(My,{assets:ve,onClear:()=>{z([]),ee([])},onOpen:()=>ne(!0)}),(0,W.jsx)(tt,{assets:ge,liveSync:E,onCopy:Oe,onSelectionChanged:()=>H(e=>e+1),page:S,pageSize:w,previewUrls:P,project:i,selected:U,setLiveSync:D,setPage:C,setPageSize:T,setSelectedId:r,snapshot:he,source:f,totals:xe})]}):V===`settings`?(0,W.jsx)(eb,{onToast:(e,t)=>j({type:e,message:t}),project:i}):(0,W.jsx)(vy,{asset:U,onAssetsChanged:we,onSelectedAsset:r,onToast:(e,t)=>j({type:e,message:t}),project:i})]}),V!==`lineage`&&oe&&(0,W.jsx)(Xe,{asset:U,onArchive:e=>void Ee(()=>y(`/api/assets/archive`,i,{assetId:e.asset_id,confirmArchive:!0})),onClose:()=>se(!1),onCopy:(e,t)=>void Oe(e,t),onCopyPreview:e=>void ke(e),onDelete:(e,t)=>void Ee(()=>y(`/api/assets/delete-object`,i,{assetId:e.asset_id,confirmation:t})),onPlacement:(e,t,n)=>void Ee(()=>y(`/api/assets/placement`,i,{assetId:e.asset_id,channel:e.channel,...b(n),status:t,confirmWrite:!0})),onPresign:e=>void De(e,{open:!0}),onPromote:e=>void Ee(()=>y(`/api/assets/promote`,i,{assetId:e.asset_id,confirmWrite:!0})),onPull:e=>void Ee(()=>y(`/api/assets/pull`,i,{assetId:e.asset_id,out:`.asset-scratch`})),onToggleBackup:Fe,previewError:U&&I[U.asset_id]||null,previewUrl:ye,selectedForBackup:U?R.includes(U.asset_id):!1}),re&&(0,W.jsx)(db,{channels:be.filter(e=>e!==`all`),project:i,onClose:()=>ie(!1),onError:e=>j({type:`error`,message:e}),onUploaded:async e=>{j({type:`ok`,message:e}),ie(!1),await we()}}),te&&(0,W.jsx)(xy,{assets:ve,project:i,onClose:()=>ne(!1),onError:e=>j({type:`error`,message:e}),onDone:async e=>{j({type:`ok`,message:e}),z([]),ee([]),ne(!1),await we()}})]})}(0,_.createRoot)(document.getElementById(`root`)).render((0,W.jsx)(g.StrictMode,{children:(0,W.jsx)(mb,{})}));
|
|
23
|
+
`)}function dh(e){let{activeNode:t,brief:n,childAssetId:r,clearNextVariation:i,closePanel:a,latestNodes:o,linkChild:s,markReview:c,noteDirty:l,onSelectedAsset:u,nextVariationLimit:d,onToast:f,project:p,refreshBrief:m,saveRationale:h,selectNextBase:g,selectedNode:_,selectedNodes:v,selectionFull:y,refreshLineage:b,replaceNextVariation:x,selectionNote:S,setActiveNodeId:C,setChildAssetId:w,setDetailNodeId:T,setSelected:E,setSelectionNote:D,sideOpen:O,snapshot:k}=e,A=t?Le({hasLocal:!!t.local_path,hasS3:!!t.s3_key}):null,j=v.filter(e=>!e.is_latest),M=k.nodes.filter(e=>e.reroll_request?.status===`pending`);return(0,W.jsxs)(`aside`,{"aria-hidden":!O,className:`lineage-side ${O?``:`collapsed`}`,id:`lineage-selection-panel`,children:[(0,W.jsxs)(`div`,{className:`lineage-side-head`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h3`,{children:`Next variation`}),(0,W.jsx)(`p`,{className:`muted-copy`,children:`Choose what the agent will evolve next; double-click nodes for full details.`})]}),(0,W.jsx)(`button`,{"aria-label":`Close lineage selection panel`,className:`icon-button`,onClick:a,type:`button`,children:`×`})]}),(0,W.jsxs)(`section`,{className:`lineage-next-panel`,children:[(0,W.jsxs)(`div`,{className:`lineage-panel-title-row`,children:[(0,W.jsx)(`h3`,{children:`Using for next variation`}),(0,W.jsxs)(`span`,{className:`lineage-count-pill ${y?`full`:``}`,children:[v.length,`/`,d]})]}),v.length>0&&(0,W.jsx)(`div`,{className:`lineage-panel-action-row`,children:(0,W.jsx)(`button`,{onClick:()=>void i(),type:`button`,children:`Clear all`})}),j.length>0&&(0,W.jsxs)(`div`,{className:`lineage-selection-warning`,role:`status`,children:[j.length,` selected asset`,j.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.`]}),v.length>0?v.map(e=>(0,W.jsxs)(`div`,{className:`lineage-candidate selected`,children:[(0,W.jsxs)(`button`,{"aria-label":`Inspect asset used for next variation ${e.title}`,className:`lineage-candidate-main`,onClick:()=>{C(e.asset_id),u(e.asset_id)},children:[(0,W.jsx)(`span`,{children:e.title}),(0,W.jsx)(`code`,{children:e.asset_id}),(0,W.jsx)(nh,{node:e})]}),!e.is_latest&&(0,W.jsx)(`span`,{className:`lineage-candidate-warning`,children:`Not latest`}),(0,W.jsxs)(`div`,{className:`lineage-candidate-actions`,children:[v.length>1&&(0,W.jsx)(`button`,{className:`lineage-candidate-action secondary`,onClick:()=>x(e),children:`Use only this`}),(0,W.jsx)(`button`,{className:`lineage-candidate-action remove`,onClick:()=>void i(e.asset_id),children:`Remove`})]})]},e.asset_id)):(0,W.jsxs)(`p`,{className:`muted-copy`,children:[`Choose up to `,d,` assets to guide the next generation.`]}),v.length>1&&(0,W.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,W.jsx)(fh,{activeNode:t,onSelectedAsset:u,onToast:f,project:p,refreshLineage:b,setActiveNodeId:C,snapshot:k}),(0,W.jsxs)(`section`,{className:`lineage-next-panel`,children:[(0,W.jsxs)(`div`,{className:`lineage-panel-title-row`,children:[(0,W.jsx)(`h3`,{children:`Re-roll queue`}),(0,W.jsx)(`span`,{className:`lineage-count-pill`,children:M.length})]}),M.length>0?M.map(e=>(0,W.jsx)(`div`,{className:`lineage-candidate ${e.asset_id===t?.asset_id?`active`:``}`,children:(0,W.jsxs)(`button`,{"aria-label":`Inspect re-roll target ${e.title}`,className:`lineage-candidate-main`,onClick:()=>{C(e.asset_id),u(e.asset_id)},children:[(0,W.jsx)(`span`,{children:e.title}),(0,W.jsx)(`code`,{children:e.asset_id}),e.reroll_request?.notes&&(0,W.jsx)(`small`,{children:e.reroll_request.notes})]})},e.asset_id)):(0,W.jsx)(`p`,{className:`muted-copy`,children:`No pending re-roll targets.`})]}),(0,W.jsxs)(`section`,{className:`lineage-next-panel`,children:[(0,W.jsx)(`h3`,{children:`Latest candidates`}),o.length>0?o.map(e=>{let n=!e.user_selected&&y;return(0,W.jsxs)(`div`,{className:`lineage-candidate ${e.asset_id===t?.asset_id?`active`:``} ${e.user_selected?`selected`:``}`,children:[(0,W.jsxs)(`button`,{"aria-label":`Inspect ${e.title}`,className:`lineage-candidate-main`,onClick:()=>{C(e.asset_id),u(e.asset_id)},children:[(0,W.jsx)(`span`,{children:e.title}),(0,W.jsx)(`code`,{children:e.asset_id}),(0,W.jsx)(nh,{node:e})]}),(0,W.jsxs)(`div`,{className:`lineage-candidate-actions`,children:[(0,W.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:n,onClick:()=>e.user_selected?void i(e.asset_id):g(e),children:e.user_selected?`Remove`:n?`Selection full`:`Use for next variation`}),!e.user_selected&&v.length>0&&(0,W.jsx)(`button`,{className:`lineage-candidate-action secondary`,onClick:()=>x(e),children:`Replace selection`})]})]},e.asset_id)}):(0,W.jsx)(`p`,{className:`muted-copy`,children:`No latest leaves yet.`})]}),(0,W.jsx)(rh,{brief:n,nextBase:_,onRefreshBrief:()=>void m(),onToast:f,project:p,rerollTargets:M,rootAssetId:k.root_asset_id}),(0,W.jsx)(`h3`,{children:`Inspecting`}),t?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`strong`,{children:t.title}),(0,W.jsx)(`code`,{children:t.asset_id}),(0,W.jsxs)(`dl`,{children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`dt`,{children:`Storage`}),(0,W.jsx)(`dd`,{children:A&&(0,W.jsx)(`span`,{className:`storage-chip ${A.kind}`,children:A.label})})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`dt`,{children:`Source`}),(0,W.jsx)(`dd`,{children:t.source})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`dt`,{children:`Review`}),(0,W.jsx)(`dd`,{children:t.review_state})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`dt`,{children:`Latest`}),(0,W.jsx)(`dd`,{children:t.is_latest?`yes`:`no`})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`dt`,{children:`Next variation`}),(0,W.jsx)(`dd`,{children:t.user_selected?`yes`:`no`})]})]}),t.user_selected&&!t.is_latest&&(0,W.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,W.jsxs)(`label`,{className:`lineage-note-field`,children:[`Variation rationale`,(0,W.jsx)(`textarea`,{value:S,onChange:e=>D(e.target.value),placeholder:`Why should the next generation branch from this asset?`}),(0,W.jsx)(`span`,{className:`lineage-note-status ${l?`dirty`:``}`,children:t.user_selected?l?`Unsaved rationale`:`Rationale saved for next variation`:`Rationale saves when this is used for next variation`})]}),(0,W.jsxs)(`div`,{className:`lineage-side-actions`,children:[(0,W.jsx)(`button`,{"aria-label":t.user_selected?`Remove ${t.title} from next variation`:`Use ${t.title} for next variation`,className:`primary-lite`,disabled:!t.user_selected&&y,onClick:()=>t.user_selected?void i(t.asset_id):E(),children:t.user_selected?`Remove from next variation`:y?`Selection full`:`Use for next variation`}),t.user_selected&&v.length>1&&(0,W.jsx)(`button`,{onClick:()=>x(t,S),children:`Use only this`}),!t.user_selected&&v.length>0&&(0,W.jsx)(`button`,{onClick:()=>x(t,S),children:`Replace selection`}),(0,W.jsx)(`button`,{disabled:!t.user_selected||!l,onClick:h,children:`Save rationale`}),(0,W.jsx)(`button`,{"aria-label":`Open detail for ${t.title}`,onClick:()=>T(t.asset_id),children:`Open detail`}),(0,W.jsx)(`button`,{"aria-label":`Approve ${t.title}`,onClick:()=>void c(`approved`),children:`Approve`}),(0,W.jsx)(`button`,{"aria-label":`Reject ${t.title}`,onClick:()=>void c(`rejected`),children:`Reject`}),(0,W.jsx)(`button`,{"aria-label":`Ignore ${t.title}`,onClick:()=>void c(`ignored`),children:`Ignore`})]}),(0,W.jsxs)(`form`,{className:`lineage-link-form`,onSubmit:e=>{e.preventDefault(),s()},children:[(0,W.jsxs)(`label`,{children:[`Child asset ID`,(0,W.jsx)(`input`,{value:r,onChange:e=>w(e.target.value),placeholder:`local-... or catalog id`})]}),(0,W.jsx)(`button`,{disabled:!r.trim(),type:`submit`,children:`Link child`})]})]}):(0,W.jsx)(`p`,{className:`muted-copy`,children:`No lineage node selected.`})]})}function fh({activeNode:e,onSelectedAsset:t,onToast:n,project:r,refreshLineage:i,setActiveNodeId:a,snapshot:o}){let s=(0,g.useMemo)(()=>hh(o.tasks||[]),[o.tasks]),c=s.filter(e=>gh(e)).length,l=(0,g.useMemo)(()=>new Map(o.nodes.map(e=>[e.asset_id,e])),[o.nodes]);return(0,W.jsxs)(`section`,{className:`lineage-next-panel lineage-task-queue-panel`,children:[(0,W.jsxs)(`div`,{className:`lineage-panel-title-row`,children:[(0,W.jsx)(`h3`,{children:`Task queue`}),(0,W.jsx)(`span`,{className:`lineage-count-pill`,children:c})]}),s.length>0?s.map(o=>(0,W.jsx)(ph,{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,W.jsx)(`p`,{className:`muted-copy`,children:`No open lineage tasks.`})]})}function ph({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,g.useState)(o.instructions||``),[d,f]=(0,g.useState)(``),[p,m]=(0,g.useState)(!1);(0,g.useEffect)(()=>u(o.instructions||``),[o.id,o.instructions]);async function h(e,t,n){m(!0);try{return await v(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{m(!1)}}async function _(e){e.preventDefault(),await h(`/api/lineage/tasks/${encodeURIComponent(o.id)}/instructions`,{instructions:l},`Updated ${vh(o)} instructions`)}async function y(e){e.preventDefault();let t=d.trim();t&&await h(`/api/lineage/tasks/${encodeURIComponent(o.id)}/comment`,{actor:`human`,message:t},`Commented on ${vh(o)}`)&&f(``)}async function b(){window.confirm(`Unlock ${vh(o)} for human edits?`)&&await h(`/api/lineage/tasks/${encodeURIComponent(o.id)}/override`,{actor:`human`,reason:`Human unlocked task from lineage UI.`},`Unlocked ${vh(o)}`)}async function x(){window.confirm(s?`Cancel ${vh(o)} while an agent is working?`:`Cancel ${vh(o)}?`)&&await h(`/api/lineage/tasks/${encodeURIComponent(o.id)}/cancel`,{actor:`human`,confirmWrite:!0,override:s},`Cancelled ${vh(o)}`)}return(0,W.jsxs)(`article`,{className:`lineage-task-card ${e?`active`:``} ${s?`locked`:o.status}`,children:[(0,W.jsxs)(`button`,{"aria-label":`Inspect task target ${t?.title||o.target_asset_id}`,className:`lineage-task-target`,onClick:n,type:`button`,children:[(0,W.jsx)(`span`,{children:t?.title||o.target_asset_id}),(0,W.jsx)(`code`,{children:o.target_asset_id})]}),(0,W.jsxs)(`div`,{className:`lineage-task-meta`,children:[(0,W.jsx)(`span`,{className:`lineage-task-status ${o.status}`,children:_h(o.status)}),(0,W.jsx)(`span`,{children:o.task_type})]}),c?(0,W.jsxs)(`form`,{className:`lineage-task-form`,onSubmit:_,children:[(0,W.jsxs)(`label`,{children:[`Instructions`,(0,W.jsx)(`textarea`,{"aria-label":`Instructions for ${o.id}`,value:l,onChange:e=>u(e.target.value)})]}),(0,W.jsxs)(`div`,{className:`lineage-task-actions`,children:[(0,W.jsx)(`button`,{disabled:p||l===(o.instructions||``),type:`submit`,children:`Save instructions`}),(0,W.jsx)(`button`,{disabled:p,onClick:x,type:`button`,children:`Cancel`})]})]}):(0,W.jsxs)(`div`,{className:`lineage-task-locked-body`,children:[(0,W.jsxs)(`label`,{children:[`Instructions`,(0,W.jsx)(`textarea`,{"aria-label":`Locked instructions for ${o.id}`,disabled:!0,readOnly:!0,value:l||`No instructions.`})]}),s&&(0,W.jsx)(mh,{claim:o.active_claim}),s&&(0,W.jsxs)(`form`,{className:`lineage-task-form`,onSubmit:y,children:[(0,W.jsxs)(`label`,{children:[`Comment`,(0,W.jsx)(`textarea`,{"aria-label":`Comment for ${o.id}`,value:d,onChange:e=>f(e.target.value)})]}),(0,W.jsxs)(`div`,{className:`lineage-task-actions`,children:[(0,W.jsx)(`button`,{disabled:p||!d.trim(),type:`submit`,children:`Add comment`}),(0,W.jsx)(`button`,{disabled:p,onClick:b,type:`button`,children:`Unlock`}),(0,W.jsx)(`button`,{disabled:p,onClick:x,type:`button`,children:`Cancel`})]})]})]})]})}function mh({claim:e}){return e?(0,W.jsxs)(`p`,{className:`lineage-task-claim ${e.derived_state===`active`?`active`:e.derived_state}`,children:[(0,W.jsxs)(`span`,{children:[_h(e.derived_state),` claim`]}),(0,W.jsx)(`strong`,{children:e.agent_name})]}):(0,W.jsx)(`p`,{className:`lineage-task-claim`,children:`Claimed by agent`})}function hh(e){return[...e].sort((e,t)=>{let n=+!gh(e),r=+!gh(t);return n===r?e.created_at.localeCompare(t.created_at):n-r})}function gh(e){return e.status===`pending`||e.status===`claimed`||e.status===`in_progress`}function _h(e){return e.replace(/_/g,` `)}function vh(e){return`${e.task_type} task`}function yh(e,t){return e?.root_asset_id||t||``}function bh(e){return`${e.title} (${e.root_asset_id})`}function xh(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 Sh(e){return e.some(e=>e.derived_state===`stale`)?`stale`:e.some(e=>e.derived_state===`idle`)?`idle`:`active`}function Ch(e){let t=Sh(e);return e.length===1?`${t===`active`?`Claimed`:t===`idle`?`Idle claim`:`Stale claim`} by ${e[0].agent_name}`:`${e.length} active claims`}function wh({activeWorkspace:e,closeSignal:t,loading:n,onNewLineage:r,onRefresh:i,onSelect:a,workspaces:o}){let[s,c]=(0,g.useState)(!1),[l,u]=(0,g.useState)([]),d=(0,g.useRef)(null),f=e?.project||o[0]?.project||``;(0,g.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,g.useEffect)(()=>{c(!1)},[t]),(0,g.useEffect)(()=>{if(!f){u([]);return}let e=!1;return v(`/api/agent-claims?${new URLSearchParams({project:f})}`).then(t=>{e||u(t.claims)}).catch(()=>{e||u([])}),()=>{e=!0}},[f,t,o.length]);function p(e){c(!1),a(e)}let m=e?xh(l,e):[];return(0,W.jsxs)(`section`,{"aria-label":`Lineage workspace picker`,className:`lineage-workspace-picker`,ref:d,children:[(0,W.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,W.jsx)(`span`,{children:`Workspace`}),(0,W.jsx)(`strong`,{children:e?.title||`No workspace selected`}),(0,W.jsx)(`code`,{children:e?.root_asset_id||`Start with New lineage`}),(0,W.jsx)(Eh,{claims:m})]}),s&&(0,W.jsxs)(`div`,{className:`lineage-workspace-menu`,children:[(0,W.jsxs)(`div`,{className:`lineage-workspace-options`,role:`listbox`,children:[o.length===0&&(0,W.jsx)(`p`,{children:`No workspaces yet.`}),o.map(t=>(0,W.jsx)(Th,{active:e?.id===t.id,claims:xh(l,t),onSelect:()=>p(t.id),workspace:t},t.id))]}),(0,W.jsxs)(`footer`,{children:[(0,W.jsx)(`button`,{className:`secondary-button`,disabled:n,onClick:i,type:`button`,children:`Refresh`}),(0,W.jsx)(`button`,{className:`primary-button`,onClick:()=>{c(!1),r()},type:`button`,children:`New lineage`})]})]})]})}function Th({active:e,claims:t,onSelect:n,workspace:r}){return(0,W.jsxs)(`button`,{"aria-selected":e,className:e?`active`:``,onClick:n,role:`option`,type:`button`,children:[(0,W.jsx)(`strong`,{children:r.title}),(0,W.jsx)(`code`,{children:r.root_asset_id}),(0,W.jsx)(`span`,{children:bh(r)}),(0,W.jsx)(Eh,{claims:t})]})}function Eh({claims:e}){return e.length===0?null:(0,W.jsxs)(`small`,{className:`lineage-workspace-claim ${Sh(e)}`,children:[(0,W.jsx)(xe,{size:13}),(0,W.jsx)(`span`,{children:Ch(e)})]})}function Dh({activeWorkspace:e,closeSignal:t,demoSeedStatus:n,graphDirection:r,loading:i,onArchiveWorkspace:a,onDownloadSwissifierMedia:o,onFitGraph:s,onGraphDirection:c,onIndexLocal:l,onNewLineage:u,onRefreshLineage:d,onRefreshWorkspaces:f,onRestoreDemoMedia:p,onRestoreSwissifierMedia:m,onSeedDemo:h,onSeedSwissifierDemo:_,onSelectWorkspace:v,onTidyGraph:y,onToggleNextPanel:b,sideOpen:x,snapshot:S,swissifierDemoStatus:C,workspaceLoading:w,workspaceRootAssetId:T,workspaces:E}){let D=n?`${n.present}/${n.total} SVG placeholders`:`Checking media`,O=C?`${C.present}/${C.total} PNG images`:`Checking media`,k=!!(C&&C.present===C.total),A=!!(C?.download_available&&!k),j=S?`${S.nodes.length} nodes · ${S.edges.length} links`:T||`Choose a lineage workspace`,[M,N]=(0,g.useState)(!1);(0,g.useEffect)(()=>{N(!1)},[t]),(0,g.useEffect)(()=>{function e(e){e.key===`Escape`&&N(!1)}return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)},[]);function P(e){N(!1),e()}function F(e){e.key===`Escape`&&(e.preventDefault(),N(!1))}return(0,W.jsxs)(`header`,{className:`lineage-header`,children:[(0,W.jsxs)(`div`,{className:`lineage-primary-controls`,children:[(0,W.jsx)(wh,{activeWorkspace:e,closeSignal:t,loading:w,onNewLineage:u,onRefresh:f,onSelect:v,workspaces:E}),(0,W.jsx)(`p`,{className:`lineage-toolbar-context`,children:j}),(0,W.jsx)(`button`,{className:`primary-button`,onClick:u,type:`button`,children:`New lineage`})]}),(0,W.jsxs)(`details`,{className:`lineage-overflow`,onToggle:e=>N(e.currentTarget.open),open:M,children:[(0,W.jsx)(`summary`,{onKeyDown:F,tabIndex:0,children:`Actions`}),(0,W.jsxs)(`div`,{children:[!e&&(0,W.jsx)(`button`,{disabled:w,onClick:()=>P(h),type:`button`,children:`Load demo lineage`}),(0,W.jsxs)(`p`,{children:[(0,W.jsx)(`strong`,{children:`QA seed media`}),(0,W.jsx)(`span`,{children:O})]}),(0,W.jsxs)(`p`,{children:[(0,W.jsx)(`strong`,{children:`Basic SVG demo`}),(0,W.jsx)(`span`,{children:D})]}),(0,W.jsx)(`button`,{disabled:w||n?.present===n?.total,onClick:p,type:`button`,children:`Restore basic media`}),(0,W.jsx)(`button`,{disabled:w,onClick:()=>P(h),type:`button`,children:`Load SVG placeholder demo`}),(0,W.jsxs)(`p`,{children:[(0,W.jsx)(`strong`,{children:`Swissifier rich demo`}),(0,W.jsx)(`span`,{children:O})]}),(0,W.jsx)(`button`,{disabled:w||!A,onClick:o,type:`button`,children:`Download rich images`}),(0,W.jsx)(`button`,{disabled:w||k,onClick:m,type:`button`,children:`Restore rich media`}),(0,W.jsx)(`button`,{disabled:w,onClick:()=>P(_),type:`button`,children:`Load rich image demo`}),(0,W.jsxs)(`label`,{className:`lineage-action-select`,children:[(0,W.jsx)(`span`,{children:`Direction`}),(0,W.jsxs)(`select`,{"aria-label":`Lineage graph direction`,disabled:!S||i,onChange:e=>c(e.target.value),value:r,children:[(0,W.jsx)(`option`,{value:`LR`,children:`Left to right`}),(0,W.jsx)(`option`,{value:`TB`,children:`Top to bottom`}),(0,W.jsx)(`option`,{value:`RL`,children:`Right to left`}),(0,W.jsx)(`option`,{value:`BT`,children:`Bottom to top`})]})]}),(0,W.jsx)(`button`,{disabled:!S,onClick:()=>P(s),type:`button`,children:`Fit graph`}),(0,W.jsx)(`button`,{disabled:!S,onClick:()=>P(y),type:`button`,children:`Tidy tree`}),(0,W.jsx)(`button`,{"aria-controls":`lineage-selection-panel`,"aria-expanded":x,disabled:!S,onClick:()=>P(b),type:`button`,children:`Manage selection`}),(0,W.jsx)(`button`,{disabled:w||!e,onClick:()=>P(a),type:`button`,children:`Archive current lineage`}),(0,W.jsx)(`button`,{disabled:i,onClick:()=>P(l),type:`button`,children:`Index local`}),(0,W.jsx)(`button`,{disabled:i||!S,onClick:()=>P(d),type:`button`,children:`Refresh graph`}),(0,W.jsx)(`button`,{disabled:w,onClick:()=>P(f),type:`button`,children:`Refresh workspaces`})]})]})]})}async function Oh(e,t,n){await v(`/api/lineage/layout`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({confirmWrite:!0,positions:n,project:e,rootAssetId:t})})}function kh(e,t,n){return wd(e.filter(e=>e.type!==`remove`),t)}function Ah(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 jh=Object.defineProperty,Mh=(e,t,n)=>t in e?jh(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Nh=(e,t)=>{for(var n in t)jh(e,n,{get:t[n],enumerable:!0})},Ph=(e,t,n)=>Mh(e,typeof t==`symbol`?t:t+``,n),Fh={};Nh(Fh,{Graph:()=>Rh,alg:()=>Xh,json:()=>Gh,version:()=>Wh});var Ih=Object.defineProperty,Lh=(e,t)=>{for(var n in t)Ih(e,n,{get:t[n],enumerable:!0})},Rh=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=Vh(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=Hh(this._isDirected,i,a,o);return i=u.v,a=u.w,Object.freeze(u),this._edgeObjs[l]=u,zh(this._preds[a],i),zh(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?Uh(this._isDirected,e):Vh(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?Uh(this._isDirected,e):Vh(this._isDirected,e,t,n))in this._edgeLabels}removeEdge(e,t,n){let r=arguments.length===1?Uh(this._isDirected,e):Vh(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],Bh(this._preds[t],e),Bh(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 zh(e,t){e[t]?e[t]++:e[t]=1}function Bh(e,t){e[t]!==void 0&&!--e[t]&&delete e[t]}function Vh(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 Hh(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 Uh(e,t){return Vh(e,t.v,t.w,t.name)}var Wh=`4.0.1`,Gh={};Lh(Gh,{read:()=>Yh,write:()=>Kh});function Kh(e){let t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:qh(e),edges:Jh(e)},n=e.graph();return n!==void 0&&(t.value=structuredClone(n)),t}function qh(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 Jh(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 Yh(e){let t=new Rh(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 Xh={};Lh(Xh,{CycleException:()=>dg,bellmanFord:()=>Qh,components:()=>eg,dijkstra:()=>rg,dijkstraAll:()=>ag,findCycles:()=>sg,floydWarshall:()=>lg,isAcyclic:()=>pg,postorder:()=>_g,preorder:()=>vg,prim:()=>yg,shortestPaths:()=>bg,tarjan:()=>og,topsort:()=>fg});var Zh=()=>1;function Qh(e,t,n,r){return $h(e,String(t),n||Zh,r||function(t){return e.outEdges(t)})}function $h(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 eg(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 tg=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}},ng=()=>1;function rg(e,t,n,r){return ig(e,String(t),n||ng,r||function(t){return e.outEdges(t)})}function ig(e,t,n,r){let i={},a=new tg,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 ag(e,t,n){return e.nodes().reduce(function(r,i){return r[i]=rg(e,i,t,n),r},{})}function og(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 sg(e){return og(e).filter(function(t){return t.length>1||t.length===1&&e.hasEdge(t[0],t[0])})}var cg=()=>1;function lg(e,t,n){return ug(e,t||cg,n||function(t){return e.outEdges(t)})}function ug(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 dg=class extends Error{constructor(...e){super(...e)}};function fg(e){let t={},n={},r=[];function i(a){if(a in n)throw new dg;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 dg;return r}function pg(e){try{fg(e)}catch(e){if(e instanceof dg)return!1;throw e}return!0}function mg(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=hg(e,t,n===`post`,o,a,r,i)}),i}function hg(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=hg(e,t,n,r,i,a,o)}),n&&(o=a(o,t))),o}function gg(e,t,n){return mg(e,t,n,function(e,t){return e.push(t),e},[])}function _g(e,t){return gg(e,t,`post`)}function vg(e,t){return gg(e,t,`pre`)}function yg(e,t){let n=new Rh,r={},i=new tg,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 bg(e,t,n,r){return xg(e,t,n,r??(t=>e.outEdges(t)??[]))}function xg(e,t,n,r){if(n===void 0)return rg(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 Qh(e,t,n,r)}return rg(e,t,n,r)}function Sg(e,t,n,r){let i=r;for(;e.hasNode(i);)i=Rg(r);return n.dummy=t,e.setNode(i,n),i}function Cg(e){let t=new Rh().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 wg(e){let t=new Rh({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 Tg(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 Eg(e){let t=zg(Ng(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 Dg(e){let t=e.nodes().map(t=>{let n=e.node(t).rank;return n===void 0?Number.MAX_VALUE:n}),n=Mg(Math.min,t);e.nodes().forEach(t=>{let r=e.node(t);Object.hasOwn(r,`rank`)&&(r.rank-=n)})}function Og(e){let t=e.nodes().map(t=>e.node(t).rank).filter(e=>e!==void 0),n=Mg(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 kg(e,t,n,r){let i={width:0,height:0};return arguments.length>=4&&(i.rank=n,i.order=r),Sg(e,`border`,i,t)}function Ag(e,t=jg){let n=[];for(let r=0;r<e.length;r+=t){let i=e.slice(r,r+t);n.push(i)}return n}var jg=65535;function Mg(e,t){return t.length>jg?e(...Ag(t).map(t=>e(...t))):e(...t)}function Ng(e){let t=e.nodes().map(t=>{let n=e.node(t).rank;return n===void 0?Number.MIN_VALUE:n});return Mg(Math.max,t)}function Pg(e,t){let n={lhs:[],rhs:[]};return e.forEach(e=>{t(e)?n.lhs.push(e):n.rhs.push(e)}),n}function Fg(e,t){let n=Date.now();try{return t()}finally{console.log(e+` time: `+(Date.now()-n)+`ms`)}}function Ig(e,t){return t()}var Lg=0;function Rg(e){return e+(``+ ++Lg)}function zg(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 Bg(e,t){let n={};for(let r of t)e[r]!==void 0&&(n[r]=e[r]);return n}function Vg(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 Hg(e,t){return e.reduce((e,n,r)=>(e[n]=t[r],e),{})}var Ug=`\0`,Wg=class{constructor(){Ph(this,`_sentinel`);let e={};e._next=e._prev=e,this._sentinel=e}dequeue(){let e=this._sentinel,t=e._prev;if(t!==e)return Gg(t),t}enqueue(e){let t=this._sentinel;e._prev&&e._next&&Gg(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,Kg)),n=n._prev;return`[`+e.join(`, `)+`]`}};function Gg(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function Kg(e,t){if(e!==`_next`&&e!==`_prev`)return t}var qg=Wg,Jg=()=>1;function Yg(e,t){if(e.nodeCount()<=1)return[];let n=Qg(e,t||Jg);return Xg(n.graph,n.buckets,n.zeroIdx).flatMap(t=>e.outEdges(t.v,t.w)||[])}function Xg(e,t,n){let r=[],i=t[t.length-1],a=t[0],o;for(;e.nodeCount();){for(;o=a.dequeue();)Zg(e,t,n,o);for(;o=i.dequeue();)Zg(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(Zg(e,t,n,o,!0)||[]);break}}}return r}function Zg(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,$g(t,n,s)}),(e.outEdges(r.v)||[]).forEach(r=>{let i=e.edge(r),a=r.w,o=e.node(a);o.in-=i,$g(t,n,o)}),e.removeNode(r.v),o}function Qg(e,t){let n=new Rh,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=e_(i+r+3).map(()=>new qg),o=r+1;return n.nodes().forEach(e=>{$g(a,o,n.node(e))}),{graph:n,buckets:a,zeroIdx:o}}function $g(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 e_(e){let t=[];for(let n=0;n<e;n++)t.push(n);return t}function t_(e){(e.graph().acyclicer===`greedy`?Yg(e,t(e)):n_(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,Rg(`rev`))});function t(e){return t=>e.edge(t).weight}}function n_(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 r_(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 i_(e){e.graph().dummyChains=[],e.edges().forEach(t=>a_(e,t))}function a_(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=Sg(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 o_(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 s_(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=Mg(Math.min,o);return s===1/0&&(s=0),i.rank=s}e.sources().forEach(n)}function c_(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}var l_=u_;function u_(e){let t=new Rh({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(;d_(t,e)<i&&(a=f_(t,e),a);)o=t.hasNode(a.v)?c_(e,a):-c_(e,a),p_(t,e,o);return t}function d_(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)&&!c_(t,i)&&(e.setNode(o,{}),e.setEdge(r,o,{}),n(o))})}return e.nodes().forEach(n),e.nodeCount()}function f_(e,t){return t.edges().reduce((n,r)=>{let i=1/0;return e.hasNode(r.v)!==e.hasNode(r.w)&&(i=c_(t,r)),i<n[0]?[i,r]:n},[1/0,null])[1]}function p_(e,t,n){e.nodes().forEach(e=>t.node(e).rank+=n)}var{preorder:m_,postorder:h_}=Xh,g_=__;__.initLowLimValues=x_,__.initCutValues=v_,__.calcCutValue=b_,__.leaveEdge=C_,__.enterEdge=w_,__.exchangeEdges=T_;function __(e){e=Cg(e),s_(e);let t=l_(e);x_(t),v_(t,e);let n,r;for(;n=C_(t);)r=w_(t,e,n),T_(t,e,n,r)}function v_(e,t){let n=h_(e,e.nodes());n=n.slice(0,n.length-1),n.forEach(n=>y_(e,t,n))}function y_(e,t,n){let r=e.node(n).parent,i=e.edge(n,r);i.cutvalue=b_(e,t,n)}function b_(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,D_(e,n,c)){let t=e.edge(n,c).cutvalue;o+=r?-t:t}}}),o}function x_(e,t){arguments.length<2&&(t=e.nodes()[0]),S_(e,{},1,t)}function S_(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=S_(e,t,n,i,r))}),o.low=a,o.lim=n++,i?o.parent=i:delete o.parent,n}function C_(e){return e.edges().find(t=>e.edge(t).cutvalue<0)}function w_(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===O_(e,e.node(t.v),s)&&c!==O_(e,e.node(t.w),s)).reduce((e,n)=>c_(t,n)<c_(t,e)?n:e)}function T_(e,t,n,r){let i=n.v,a=n.w;e.removeEdge(i,a),e.setEdge(r.v,r.w,{}),x_(e),v_(e,t),E_(e,t)}function E_(e,t){let n=e.nodes().find(t=>!e.node(t).parent);if(!n)return;let r=m_(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 D_(e,t,n){return e.hasEdge(t,n)}function O_(e,t,n){return n.low<=t.lim&&t.lim<=n.lim}var k_=A_;function A_(e){let t=e.graph().ranker;if(typeof t==`function`)return t(e);switch(t){case`network-simplex`:N_(e);break;case`tight-tree`:M_(e);break;case`longest-path`:j_(e);break;case`none`:break;default:N_(e)}}var j_=s_;function M_(e){s_(e),l_(e)}function N_(e){g_(e)}var P_=F_;function F_(e){let t=L_(e);e.graph().dummyChains.forEach(n=>{let r=e.node(n),i=r.edgeObj,a=I_(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 I_(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 L_(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(Ug).forEach(r),t}function R_(e){let t=Sg(e,`root`,{},`_root`),n=B_(e),r=Object.values(n),i=Mg(Math.max,r)-1,a=2*i+1;e.graph().nestingRoot=t,e.edges().forEach(t=>e.edge(t).minlen*=a);let o=V_(e)+1;e.children(Ug).forEach(r=>z_(e,t,a,o,i,n,r)),e.graph().nodeRankFactor=a}function z_(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=kg(e,`_bt`),l=kg(e,`_bb`),u=e.node(o);e.setParent(c,o),u.borderTop=c,e.setParent(l,o),u.borderBottom=l,s.forEach(s=>{z_(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 B_(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(Ug).forEach(e=>n(e,1)),t}function V_(e){return e.edges().reduce((t,n)=>t+e.edge(n).weight,0)}function H_(e){let t=e.graph();e.removeNode(t.nestingRoot),delete t.nestingRoot,e.edges().forEach(t=>{e.edge(t).nestingEdge&&e.removeEdge(t)})}var U_=W_;function W_(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)G_(e,`borderLeft`,`_bl`,n,i,t),G_(e,`borderRight`,`_br`,n,i,t)}}e.children(Ug).forEach(t)}function G_(e,t,n,r,i,a){let o={width:0,height:0,rank:a,borderType:t},s=i[t][a-1],c=Sg(e,`border`,o,n);i[t][a]=c,e.setParent(c,r),s&&e.setEdge(s,c,{weight:1})}function K_(e){let t=e.graph().rankdir?.toLowerCase();(t===`lr`||t===`rl`)&&J_(e)}function q_(e){let t=e.graph().rankdir?.toLowerCase();(t===`bt`||t===`rl`)&&X_(e),(t===`lr`||t===`rl`)&&(Q_(e),J_(e))}function J_(e){e.nodes().forEach(t=>Y_(e.node(t))),e.edges().forEach(t=>Y_(e.edge(t)))}function Y_(e){let t=e.width;e.width=e.height,e.height=t}function X_(e){e.nodes().forEach(t=>Z_(e.node(t))),e.edges().forEach(t=>{var n;let r=e.edge(t);(n=r.points)==null||n.forEach(Z_),Object.hasOwn(r,`y`)&&Z_(r)})}function Z_(e){e.y=-e.y}function Q_(e){e.nodes().forEach(t=>$_(e.node(t))),e.edges().forEach(t=>{var n;let r=e.edge(t);(n=r.points)==null||n.forEach($_),Object.hasOwn(r,`x`)&&$_(r)})}function $_(e){let t=e.x;e.x=e.y,e.y=t}function ev(e){let t={},n=e.nodes().filter(t=>!e.children(t).length),r=n.map(t=>e.node(t).rank),i=zg(Mg(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 tv(e,t){let n=0;for(let r=1;r<t.length;++r)n+=nv(e,t[r-1],t[r]);return n}function nv(e,t,n){let r=Hg(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 rv(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 iv(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))}),av(Object.values(n).filter(e=>!e.indegree))}function av(e){let t=[];function n(e){return t=>{t.merged||(t.barycenter===void 0||e.barycenter===void 0||t.barycenter>=e.barycenter)&&ov(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=>Bg(e,[`vs`,`i`,`barycenter`,`weight`]))}function ov(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 sv(e,t){let n=Pg(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(lv(!!t)),c=cv(a,i,c),r.forEach(e=>{c+=e.vs.length,a.push(e.vs),o+=e.barycenter*e.weight,s+=e.weight,c=cv(a,i,c)});let l={vs:a.flat(1)};return s&&(l.barycenter=o/s,l.weight=s),l}function cv(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 lv(e){return(t,n)=>t.barycenter<n.barycenter?-1:t.barycenter>n.barycenter?1:e?n.i-t.i:t.i-n.i}function uv(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=rv(e,i);l.forEach(t=>{if(e.children(t.v).length){let i=uv(e,t.v,n,r);c[t.v]=i,Object.hasOwn(i,`barycenter`)&&fv(t,i)}});let u=iv(l,n);dv(u,c);let d=sv(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 dv(e,t){e.forEach(e=>{e.vs=e.vs.flatMap(e=>t[e]?t[e].vs:e)})}function fv(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 pv(e,t,n,r){r||=e.nodes();let i=mv(e),a=new Rh({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 mv(e){let t;for(;e.hasNode(t=Rg(`_root`)););return t}function hv(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 gv(e,t={}){if(typeof t.customOrder==`function`){t.customOrder(e,gv);return}let n=Ng(e),r=_v(e,zg(1,n+1),`inEdges`),i=_v(e,zg(n-1,-1,-1),`outEdges`),a=ev(e);if(yv(e,a),t.disableOptimalOrderHeuristic)return;let o=1/0,s,c=t.constraints||[];for(let t=0,n=0;n<4;++t,++n){vv(t%2?r:i,t%4>=2,c),a=Eg(e);let l=tv(e,a);l<o?(n=0,s=Object.assign({},a),o=l):l===o&&(s=structuredClone(a))}yv(e,s)}function _v(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 pv(e,t,n,r.get(t)||[])})}function vv(e,t,n){let r=new Rh;e.forEach(function(e){n.forEach(e=>r.setEdge(e.left,e.right));let i=e.graph().root,a=uv(e,i,r,t);a.vs.forEach((t,n)=>e.node(t).order=n),hv(e,r,a.vs)})}function yv(e,t){Object.values(t).forEach(t=>t.forEach((t,n)=>e.node(t).order=n))}function bv(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=Sv(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)&&Cv(n,r,t)})}),a=c+1,i=u)}),r}return t.length&&t.reduce(r),n}function xv(e,t){let n={};function r(t,r,i,a,o){zg(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)&&Cv(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 Sv(e,t){if(e.node(t).dummy){let n=e.predecessors(t);if(n)return n.find(t=>e.node(t).dummy)}}function Cv(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 wv(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 Tv(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&&!wv(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 Ev(e,t,n,r,i=!1){let a={},o=Dv(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 Dv(e,t,n,r){let i=new Rh,a=e.graph(),o=Mv(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 Ov(e,t){return Object.values(t).reduce((t,n)=>{let r=-1/0,i=1/0;Object.entries(n).forEach(([t,n])=>{let a=Nv(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 kv(e,t){let n=Object.values(t),r=Mg(Math.min,n),i=Mg(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-Mg(Math.min,c);a!==`l`&&(l=i-Mg(Math.max,c)),l&&(e[o]=Vg(s,e=>e+l))})})}function Av(e,t=void 0){let n=e.ul;return n?Vg(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 jv(e){let t=Eg(e),n=Object.assign(bv(e,t),xv(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=Tv(e,i,n,t=>(a===`u`?e.predecessors(t):e.successors(t))||[]),s=Ev(e,i,o.root,o.align,t===`r`);t===`r`&&(s=Vg(s,e=>-e)),r[a+t]=s})}),kv(r,Ov(e,r)),Av(r,e.graph().align)}function Mv(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 Nv(e,t){return e.node(t).width}function Pv(e){e=wg(e),Fv(e),Object.entries(jv(e)).forEach(([t,n])=>e.node(t).x=n)}function Fv(e){let t=Eg(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 Iv(e,t={}){let n=t.debugTiming?Fg:Ig;return n(`layout`,()=>{let r=n(` buildLayoutGraph`,()=>qv(e));return n(` runLayout`,()=>Lv(r,n,t)),n(` updateInputGraph`,()=>Rv(e,r)),r})}function Lv(e,t,n){t(` makeSpaceForEdgeLabels`,()=>Jv(e)),t(` removeSelfEdges`,()=>ry(e)),t(` acyclic`,()=>t_(e)),t(` nestingGraph.run`,()=>R_(e)),t(` rank`,()=>k_(wg(e))),t(` injectEdgeLabelProxies`,()=>Yv(e)),t(` removeEmptyRanks`,()=>Og(e)),t(` nestingGraph.cleanup`,()=>H_(e)),t(` normalizeRanks`,()=>Dg(e)),t(` assignRankMinMax`,()=>Xv(e)),t(` removeEdgeLabelProxies`,()=>Zv(e)),t(` normalize.run`,()=>i_(e)),t(` parentDummyChains`,()=>P_(e)),t(` addBorderSegments`,()=>U_(e)),t(` order`,()=>gv(e,n)),t(` insertSelfEdges`,()=>iy(e)),t(` adjustCoordinateSystem`,()=>K_(e)),t(` position`,()=>Pv(e)),t(` positionSelfEdges`,()=>ay(e)),t(` removeBorderNodes`,()=>ny(e)),t(` normalize.undo`,()=>o_(e)),t(` fixupEdgeLabelCoords`,()=>ey(e)),t(` undoCoordinateSystem`,()=>q_(e)),t(` translateGraph`,()=>Qv(e)),t(` assignNodeIntersects`,()=>$v(e)),t(` reversePoints`,()=>ty(e)),t(` acyclic.undo`,()=>r_(e))}function Rv(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 zv=[`nodesep`,`edgesep`,`ranksep`,`marginx`,`marginy`],Bv={ranksep:50,edgesep:20,nodesep:50,rankdir:`TB`,rankalign:`center`},Vv=[`acyclicer`,`ranker`,`rankdir`,`align`,`rankalign`],Hv=[`width`,`height`,`rank`],Uv={width:0,height:0},Wv=[`minlen`,`weight`,`width`,`height`,`labeloffset`],Gv={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:`r`},Kv=[`labelpos`];function qv(e){let t=new Rh({multigraph:!0,compound:!0}),n=sy(e.graph());return t.setGraph(Object.assign({},Bv,oy(n,zv),Bg(n,Vv))),e.nodes().forEach(n=>{let r=oy(sy(e.node(n)),Hv);Object.keys(Uv).forEach(e=>{r[e]===void 0&&(r[e]=Uv[e])}),t.setNode(n,r);let i=e.parent(n);i!==void 0&&t.setParent(n,i)}),e.edges().forEach(n=>{let r=sy(e.edge(n));t.setEdge(n,Object.assign({},Gv,oy(r,Wv),Bg(r,Kv)))}),t}function Jv(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 Yv(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.width&&n.height){let n=e.node(t.v);Sg(e,`edge-proxy`,{rank:(e.node(t.w).rank-n.rank)/2+n.rank,e:t},`_ep`)}})}function Xv(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 Zv(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 Qv(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 $v(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(Tg(r,a)),n.points.push(Tg(i,o))})}function ey(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 ty(e){e.edges().forEach(t=>{let n=e.edge(t);n.reversed&&n.points.reverse()})}function ny(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 ry(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 iy(e){Eg(e).forEach(t=>{let n=0;t.forEach((t,r)=>{let i=e.node(t);i.order=r+n,(i.selfEdges||[]).forEach(t=>{Sg(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 ay(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 oy(e,t){return Vg(Bg(e,t),Number)}function sy(e){let t={};return e&&Object.entries(e).forEach(([e,n])=>{typeof e==`string`&&(e=e.toLowerCase()),t[e]=n}),t}var cy=212,ly=164;function uy(e,t,n=`LR`){if(!e)return{nodes:[],edges:[]};let r=my(e,n),i=dy(n),a=py(e,t);return{nodes:e.nodes.map(n=>({id:n.asset_id,initialHeight:ly,initialWidth:cy,measured:{height:ly,width:cy},type:`assetNode`,height:ly,position:n.position||r.get(n.asset_id)||{x:0,y:0},sourcePosition:i.source,targetPosition:i.target,width:cy,data:{...n,active:n.asset_id===t,focusRole:a.roles.get(n.asset_id)||`none`,root:n.asset_id===e.root_asset_id,sourcePosition:i.source,targetPosition:i.target}})),edges:e.edges.map(t=>({className:a.edgeClasses.get(t.id),id:t.id,markerEnd:{type:Qs.ArrowClosed},source:t.parent_asset_id,target:t.child_asset_id,type:`smoothstep`,animated:e.selected.includes(t.child_asset_id)}))}}function dy(e){return{BT:{source:X.Top,target:X.Bottom},LR:{source:X.Right,target:X.Left},RL:{source:X.Left,target:X.Right},TB:{source:X.Bottom,target:X.Top}}[e]}function fy(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 py(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 my(e,t=`LR`){let n=new Fh.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:ly,width:cy});for(let t of e.edges)n.setEdge(t.parent_asset_id,t.child_asset_id);return Iv(n),new Map(e.nodes.map(e=>{let t=n.node(e.asset_id);return[e.asset_id,{x:Math.round((t?.x||cy/2)-cy/2),y:Math.round((t?.y||ly/2)-ly/2)}]}))}function hy(e,t){(0,g.useEffect)(()=>{function n(n){n.key===`Escape`&&e&&t()}return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t])}function gy({asset:e,onResetLineage:t,onSelectedAsset:n,onToast:r,project:i}){let a=(0,g.useRef)(i),[o,s]=(0,g.useState)(null),[c,l]=(0,g.useState)(null),[u,d]=(0,g.useState)(null),[f,p]=(0,g.useState)(!1),m=o?.project===i,h=m?o:null,_=(h?.workspaces||[]).filter(e=>e.status!==`archived`),y=h?.active_workspace||_[0]||null,b=yh(y,m&&h?.workspaces.length===0?e?.asset_id:void 0);(0,g.useEffect)(()=>{a.current=i,s(null),l(null),d(null)},[i]);let x=(0,g.useCallback)(async()=>{p(!0);try{let e=await v(`/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{p(!1)}},[r,i]),S=(0,g.useCallback)(async()=>{try{let e=new URLSearchParams({project:i}),[t,n]=await Promise.all([v(`/api/lineage-workspaces/demo/media?${e.toString()}`),v(`/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){p(!0);try{let a=await v(`/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{p(!1)}}}async function w(e={}){p(!0);try{let a=await v(`/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{p(!1)}}async function T(e={}){p(!0);try{let a=await v(`/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{p(!1)}}async function E(){p(!0);try{let e=await v(`/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{p(!1)}}async function D(){p(!0);try{let e=await v(`/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{p(!1)}}async function O(){p(!0);try{let e=await v(`/api/lineage-workspaces/demo/swissifier/media/download`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:i,confirmWrite:!0})});await S(),e.result.download_available?r(`ok`,`Downloaded ${e.result.restored||0} Swissifier media file${e.result.restored===1?``:`s`}`):r(`error`,`Swissifier media download is not configured`)}catch(e){r(`error`,e instanceof Error?e.message:String(e))}finally{p(!1)}}async function k(){if(y&&window.confirm(`Archive ${y.title}? This hides it from the picker and clears its next-variation selection.`)){p(!0);try{await v(`/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{p(!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:_,workspaceLoading:f,workspaceRootAssetId:b}}function _y(e,t,n){let r=(0,g.useRef)(!1),i=(0,g.useRef)(``),a=(0,g.useRef)(!1),o=(0,g.useRef)(``),s=(0,g.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,g.useCallback)(()=>{r.current||(a.current=!0)},[]);return(0,g.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 vy({asset:e,onAssetsChanged:t,project:n,onSelectedAsset:r,onToast:i}){let[a,o]=(0,g.useState)(null),[s,c]=(0,g.useState)(null),[l,u]=(0,g.useState)(``),[d,f]=(0,g.useState)(null),[p,m]=(0,g.useState)(null),[h,_]=(0,g.useState)([]),[y,b]=(0,g.useState)(null),[x,S]=(0,g.useState)([]),[C,w]=(0,g.useState)(`LR`),[T,E]=(0,g.useState)(``),[D,O]=(0,g.useState)(null),[k,A]=(0,g.useState)(!1),[j,M]=(0,g.useState)(!1),[N,P]=(0,g.useState)(!1),[F,I,L]=Yp([]),[R,z]=Xp([]),[B,ee]=(0,g.useState)(null),[te,ne]=(0,g.useState)(!1),[re,ie]=(0,g.useState)(0),V=a?.nodes.find(e=>e.asset_id===s)||a?.nodes[0],ae=a?.nodes.filter(e=>a.latest.includes(e.asset_id))||[],oe=a?.selected.map(e=>a.nodes.find(t=>t.asset_id===e)).filter(e=>!!e)||[],se=oe[0],ce=oe.length>=3,le=a?.nodes.find(e=>e.asset_id===d)||null,ue=a?.nodes.find(e=>e.asset_id===p)||null,H=a?.nodes.find(e=>e.asset_id===D?.assetId),de=!!(s&&V),fe=V?.asset_id||`none`,pe=!!(V&&T!==(V.selection_note||``)),me=(0,g.useRef)(null),he=(0,g.useRef)([]),ge=(0,g.useRef)(``),U=(0,g.useRef)(``),{fitGraph:_e,markViewportInteraction:ve}=_y(B,a?.root_asset_id,j),ye=(0,g.useCallback)(()=>{ie(e=>e+1),O(null)},[]),be=(0,g.useRef)(n);(0,g.useEffect)(()=>{be.current=n},[n]);let xe=(0,g.useCallback)(()=>{c(null),ye()},[ye]),Se=(0,g.useCallback)(()=>{o(null),c(null),b(null)},[]),{activateWorkspace:Ce,activeWorkspace:we,archiveWorkspace:Te,demoSeedStatus:Ee,downloadSwissifierDemoMedia:De,handleWorkspaceCreated:Oe,refreshDemoSeedStatus:ke,refreshWorkspaces:Ae,restoreDemoSeedMedia:je,restoreSwissifierDemoMedia:Me,seedDemoWorkspace:Ne,seedSwissifierDemoWorkspace:Pe,swissifierDemoStatus:Fe,visibleWorkspaces:Ie,workspaceLoading:Le,workspaceRootAssetId:Re}=gy({asset:e,onResetLineage:Se,onSelectedAsset:r,onToast:i,project:n});U.current=Re,(0,g.useEffect)(()=>{ke()},[ke]);let ze=(0,g.useCallback)(async(e={})=>{let t=e.rootAssetId||Re;if(t){e.quiet||ne(!0);try{let r=new URLSearchParams({project:n}),[i,a]=await Promise.all([v(`/api/lineage/${t}?${r.toString()}`),v(`/api/agent-claims?${r.toString()}`)]);if(!e.rootAssetId&&U.current!==t)return;o(i),S(a.claims),e.quiet||b(null),c(e=>e&&i.nodes.some(t=>t.asset_id===e)?e:i.active_asset_id)}catch(r){if(!e.rootAssetId&&U.current!==t)return;!e.quiet&&be.current===n&&(o(null),i(`error`,r instanceof Error?r.message:String(r)))}finally{!e.quiet&&be.current===n&&ne(!1)}}},[i,n,Re]);async function Be(){ne(!0);try{i(`ok`,`Indexed ${(await v(`/api/index/local`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:n})})).summary.total} assets`),await Ae(),await ze()}catch(e){i(`error`,e instanceof Error?e.message:String(e))}finally{ne(!1)}}async function Ve(){ye();let e=await Ne();await t?.();let n=await Ne({quiet:!0});await ze({rootAssetId:n?.workspace?.root_asset_id||n?.root_asset_id||e?.workspace?.root_asset_id||e?.root_asset_id})}async function He(){ye();let e=await Pe();await t?.();let n=await Pe({quiet:!0});await ze({rootAssetId:n?.workspace?.root_asset_id||n?.root_asset_id||e?.workspace?.root_asset_id||e?.root_asset_id})}async function Ue(e,t,r){try{await v(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:n,...t})}),i(`ok`,r),await ze()}catch(e){i(`error`,e instanceof Error?e.message:String(e))}}function We(){V&&Ke(V,T)}function Ge(){V?.user_selected&&Ke(V,T)}function Ke(e,t=e.selection_note||``){if(!e.user_selected&&ce){i(`error`,`Choose at most 3 assets for next variation`);return}Ue(`/api/selection`,{assetId:e.asset_id,rootAssetId:a?.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`)}function qe(e,t=e.selection_note||``){Ue(`/api/selection`,{assetId:e.asset_id,rootAssetId:a?.root_asset_id,mode:`replace`,notes:t,confirmWrite:!0},`Using only ${e.asset_id} for next variation`)}async function Je(e){if(a){if(e){await Ue(`/api/selection`,{assetId:e,rootAssetId:a.root_asset_id,mode:`remove`,confirmWrite:!0},`Removed ${e} from next variation`);return}oe.length>0&&await Ue(`/api/selection`,{rootAssetId:a.root_asset_id,clear:!0,confirmWrite:!0},`Removed all assets from next variation`)}}function Ye(){if(me.current&&window.clearTimeout(me.current),j){M(!1),me.current=window.setTimeout(()=>P(!1),260);return}P(!0),window.requestAnimationFrame(()=>M(!0))}async function Xe(e,t=V?.asset_id){if(!t)return;let n=a?.nodes.find(e=>e.asset_id===t),r=Ah(n,e);r&&!window.confirm(r.confirmation)||(r&&await Je(t),Ue(`/api/reviews/${t}`,{reviewState:e,confirmWrite:!0},`Marked ${t} ${e}`))}async function Ze(e){a&&await Ue(`/api/lineage/${a.root_asset_id}/rerolls/${e.asset_id}`,{confirmWrite:!0,requestedBy:`human`},`Marked ${e.asset_id} for re-roll`)}async function Qe(e){a&&await Ue(`/api/lineage/${a.root_asset_id}/rerolls/${e.asset_id}/cancel`,{confirmWrite:!0},`Cleared re-roll request for ${e.asset_id}`)}async function $e(e){if(a)try{let t=new URLSearchParams({project:n}),r=await v(`/api/lineage/${a.root_asset_id}/attempts/${e}?${t.toString()}`);_(r.attempts),m(e)}catch(e){i(`error`,e instanceof Error?e.message:String(e))}}function et(){m(null),_([])}function tt(e){et(),f(e)}async function nt(e){if(!(!a||!p))try{let t=await v(`/api/lineage/${a.root_asset_id}/attempts/${p}/promote`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:n,attemptId:e.id,confirmWrite:!0})});_(t.attempts),i(`ok`,`Set v${e.attempt_index} as current`),await ze({quiet:!0})}catch(e){i(`error`,e instanceof Error?e.message:String(e))}}async function rt(){!V||!l.trim()||(await Ue(`/api/lineage/link`,{childAssetId:l.trim(),confirmWrite:!0,parentAssetId:V.asset_id},`Linked ${l.trim()} from ${V.asset_id}`),u(``))}async function it(e){if(!a)return;if(e.asset_id===a.root_asset_id){i(`error`,`Root lineage node cannot be removed. Archive this workspace or start a new lineage instead.`);return}let t=a.edges.filter(t=>t.parent_asset_id===e.asset_id).length,n=a.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 Ue(`/api/lineage/remove-node`,{assetId:e.asset_id,rootAssetId:a.root_asset_id,confirmWrite:!0},`Removed ${e.asset_id} from lineage`),O(null),f(t=>t===e.asset_id?null:t),c(t=>t===e.asset_id?a.root_asset_id:t))}async function at(e){if(a)try{await Oh(n,a.root_asset_id,[{assetId:e.id,x:e.position.x,y:e.position.y}])}catch(e){i(`error`,e instanceof Error?e.message:String(e))}}async function ot(){if(!a)return;let e=[...my(a,C)].map(([e,t])=>({assetId:e,...t}));ct(e),I(t=>t.map(t=>({...t,position:e.find(e=>e.assetId===t.id)||t.position})));try{await Oh(n,a.root_asset_id,e),i(`ok`,`Tidied ${e.length} lineage nodes`),_e(80),await ze()}catch(e){i(`error`,e instanceof Error?e.message:String(e))}}async function st(e){if(!a)return;let t=[...my(a,e)].map(([e,t])=>({assetId:e,...t}));ct(t),w(e),I(e=>e.map(e=>({...e,position:t.find(t=>t.assetId===e.id)||e.position})));try{await Oh(n,a.root_asset_id,t),i(`ok`,`Rotated lineage graph ${by(e).toLowerCase()}`),_e(80),await ze()}catch(e){i(`error`,e instanceof Error?e.message:String(e))}}function ct(e){let t=new Map(e.map(e=>[e.assetId,{x:e.x,y:e.y}]));o(e=>e&&{...e,nodes:e.nodes.map(e=>({...e,position:t.get(e.asset_id)||e.position}))})}async function lt(){if(a)try{let e=new URLSearchParams({project:n});b(await v(`/api/lineage/${a.root_asset_id}/brief?${e.toString()}`))}catch(e){i(`error`,e instanceof Error?e.message:String(e))}}async function ut(e,t,r){try{await v(`/api/agent-claims/${t.id}/${e}`,{body:JSON.stringify({project:n,...r}),headers:{"Content-Type":`application/json`},method:`POST`}),i(`ok`,`Updated claim ${t.id}`),await ze({quiet:!0})}catch(e){i(`error`,e instanceof Error?e.message:String(e))}}(0,g.useEffect)(()=>{Ae()},[Ae]),(0,g.useEffect)(()=>{ze()},[ze]),(0,g.useEffect)(()=>{Re||Se()},[Se,Re]),(0,g.useEffect)(()=>{if(!a)return;let e=window.setInterval(()=>void ze({quiet:!0}),8e3);return()=>window.clearInterval(e)},[ze,a?.root_asset_id]);let G=(0,g.useMemo)(()=>uy(a,s,C),[s,C,a]),dt=(0,g.useMemo)(()=>fy(a,C),[C,a]);he.current=G.edges;let ft=(0,g.useCallback)(e=>{z(t=>kh(e,t,he.current))},[z]),pt=(0,g.useCallback)(e=>{e.key===`Escape`&&ye()},[ye]);return(0,g.useEffect)(()=>{E(V?.selection_note||``)},[V?.asset_id,V?.selection_note]),(0,g.useEffect)(()=>{let e=ge.current!==dt;ge.current=dt,I(t=>G.nodes.map(n=>({...n,position:e?n.position:t.find(e=>e.id===n.id)?.position||n.position}))),z(G.edges)},[G.edges,G.nodes,dt,z,I]),hy(!!s,xe),(0,g.useEffect)(()=>()=>{me.current&&window.clearTimeout(me.current)},[]),(0,g.useEffect)(()=>{Se()},[n,Se]),(0,W.jsxs)(`section`,{className:`lineage-view`,onKeyDownCapture:pt,children:[(0,W.jsx)(Dh,{activeWorkspace:we,closeSignal:re,loading:te,graphDirection:C,demoSeedStatus:Ee,onArchiveWorkspace:()=>void Te(),onFitGraph:()=>_e(),onIndexLocal:()=>void Be(),onGraphDirection:e=>void st(e),onNewLineage:()=>A(!0),onRefreshLineage:()=>void ze(),onRefreshWorkspaces:()=>void Ae(),onRestoreDemoMedia:()=>void je(),onRestoreSwissifierMedia:()=>void Me(),onDownloadSwissifierMedia:()=>void De(),onSeedDemo:()=>void Ve(),onSeedSwissifierDemo:()=>void He(),onSelectWorkspace:e=>void Ce(e),onTidyGraph:()=>void ot(),onToggleNextPanel:Ye,sideOpen:j,snapshot:a,swissifierDemoStatus:Fe,workspaceLoading:Le,workspaceRootAssetId:Re,workspaces:Ie}),(0,W.jsxs)(`div`,{className:`lineage-workbench`,"data-testid":`lineage-workbench`,children:[(0,W.jsx)(`div`,{className:`lineage-canvas ${s?`focus-active`:``}`,children:(0,W.jsx)(Pm,{activeNode:V,flowEdges:a?R:[],flowNodes:a?F:[],graphKey:dt,inspectingId:fe,loading:te,onEdgesChange:ft,onClearFocus:xe,onIndexNow:()=>void Be(),onNewLineage:()=>A(!0),onSeedDemo:()=>void Ve(),onNodeActionMenu:(e,t,n)=>O(e?{assetId:e,x:t,y:n}:null),onNodeInspect:e=>{ye(),c(e)},onNodeOpenDetail:f,onNodeOpenHistory:e=>void $e(e),onNodePosition:e=>void at(e),onNodesChange:L,onReady:ee,onSelectedAsset:r,onViewportInteraction:ve,showCanvasStatus:de,workspaceRootAssetId:Re})}),N&&a&&(0,W.jsx)(dh,{activeNode:V,brief:y,childAssetId:l,clearNextVariation:Je,closePanel:Ye,latestNodes:ae,linkChild:rt,markReview:Xe,nextVariationLimit:3,noteDirty:pe,onSelectedAsset:r,onToast:i,project:n,refreshBrief:lt,refreshLineage:()=>ze({quiet:!0}),saveRationale:Ge,replaceNextVariation:qe,selectNextBase:Ke,selectedNode:se,selectedNodes:oe,selectionFull:ce,selectionNote:T,setActiveNodeId:c,setChildAssetId:u,setDetailNodeId:f,setSelected:We,setSelectionNote:E,sideOpen:j,snapshot:a}),D&&H&&a&&(0,W.jsx)(Fm,{canRemoveFromLineage:H.asset_id!==a.root_asset_id,claims:yy(x,n,a.root_asset_id),node:H,onClaimControl:(e,t,n)=>{ut(e,t,n)},onClearAllNext:()=>void Je(),onClearNext:()=>void Je(H.asset_id),onClearReroll:()=>void Qe(H),onClose:()=>O(null),onMarkReroll:()=>void Ze(H),onOpenDetail:()=>f(H.asset_id),onRemoveFromLineage:()=>void it(H),onReplaceNext:()=>qe(H),onReview:e=>void Xe(e,H.asset_id),onSelectNext:()=>Ke(H),position:D,selectedCount:oe.length,selectionFull:ce})]}),ue&&a&&(0,W.jsx)(Wm,{actions:{canRemoveFromLineage:ue.asset_id!==a.root_asset_id,onClearAllNext:()=>void Je(),onClearNext:()=>void Je(ue.asset_id),onOpenNode:tt,onRemoveFromLineage:e=>void it(e),onReplaceNext:qe,onReview:Xe,onSelectNext:Ke,onToast:i,selectedCount:oe.length,selectionFull:ce,snapshot:a},attempts:h,node:ue,onClose:et,onPromoteAttempt:nt,project:n}),le&&a&&(0,W.jsx)(Xm,{canRemoveFromLineage:le.asset_id!==a.root_asset_id,node:le,onClearAllNext:()=>void Je(),onClearNext:()=>void Je(le.asset_id),onClose:()=>f(null),onOpenNode:f,onRemoveFromLineage:e=>void it(e),onReplaceNext:qe,onReview:Xe,onSelectNext:Ke,onToast:i,selectedCount:oe.length,selectionFull:ce,snapshot:a}),(0,W.jsx)(th,{onClose:()=>A(!1),onCreated:Oe,onToast:i,open:k,project:n})]})}function yy(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 by(e){return{BT:`bottom to top`,LR:`left to right`,RL:`right to left`,TB:`top to bottom`}[e]}function xy({assets:e,onClose:t,onDone:n,onError:r,project:i}){let a=e[0],[o,s]=(0,g.useState)(!1),[c,l]=(0,g.useState)(!1),[u,d]=(0,g.useState)([]),[f,p]=(0,g.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`}),m=e.filter(e=>!Cy(e)),h=m.length>0||e.length===0;function _(e,t){p(n=>({...n,[e]:t}))}function y(e,t){let n=Ae(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(h){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 v(`/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,W.jsx)(`div`,{className:`drawer-backdrop`,children:(0,W.jsxs)(`section`,{className:`local-backup-drawer`,children:[(0,W.jsxs)(`header`,{children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h2`,{children:`Back up local assets`}),(0,W.jsx)(`p`,{children:i})]}),(0,W.jsx)(`button`,{onClick:t,children:`Close`})]}),(0,W.jsx)(`div`,{className:`local-backup-list`,children:e.map(e=>(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`strong`,{children:Ae(e.title)||e.asset_id}),(0,W.jsx)(`span`,{children:e.local?.relative_path}),(0,W.jsxs)(`span`,{children:[`Review: `,wy(Sy(e))]})]},e.asset_id))}),h&&(0,W.jsxs)(`div`,{className:`local-backup-warning`,role:`alert`,children:[(0,W.jsx)(`strong`,{children:`Backup is locked until local review is approved.`}),e.length===0?(0,W.jsx)(`span`,{children:`No local assets are selected.`}):null,m.map(e=>(0,W.jsxs)(`span`,{children:[Ae(e.title)||e.asset_id,`: `,wy(Sy(e))]},e.asset_id))]}),(0,W.jsxs)(`div`,{className:`form-grid`,children:[(0,W.jsxs)(`label`,{children:[`Campaign`,(0,W.jsx)(`input`,{value:f.campaign,onChange:e=>_(`campaign`,e.target.value)})]}),(0,W.jsxs)(`label`,{children:[`Channel`,(0,W.jsx)(`input`,{value:f.channel,onChange:e=>_(`channel`,e.target.value)})]}),(0,W.jsxs)(`label`,{children:[`Audience`,(0,W.jsx)(`input`,{value:f.audience,onChange:e=>_(`audience`,e.target.value)})]}),(0,W.jsxs)(`label`,{children:[`Status`,(0,W.jsxs)(`select`,{value:f.status,onChange:e=>_(`status`,e.target.value),children:[(0,W.jsx)(`option`,{children:`working`}),(0,W.jsx)(`option`,{children:`published`})]})]}),(0,W.jsxs)(`label`,{className:`wide`,children:[`CTA`,(0,W.jsx)(`input`,{value:f.cta,onChange:e=>_(`cta`,e.target.value)})]})]}),u.length>0&&(0,W.jsx)(`div`,{className:`local-backup-preview`,children:u.map(e=>(0,W.jsx)(`span`,{children:e},e))}),(0,W.jsxs)(`label`,{className:`confirm-line`,children:[(0,W.jsx)(`input`,{checked:o,type:`checkbox`,onChange:e=>s(e.target.checked)}),(0,W.jsx)(`span`,{children:`Confirm write to the production asset bucket`})]}),(0,W.jsxs)(`footer`,{children:[(0,W.jsx)(`button`,{disabled:c||h,onClick:()=>void b(!0),children:`Dry run`}),(0,W.jsxs)(`button`,{className:`primary-button`,disabled:c||h||!o,onClick:()=>void b(!1),children:[c?(0,W.jsx)(pe,{className:`spin`,size:16}):(0,W.jsx)(I,{size:16}),`Back up`]})]})]})})}function Sy(e){return e.review?.review_state||`unreviewed`}function Cy(e){return!!e.local?.relative_path&&Sy(e)===`approved`}function wy(e){return e===`needs_revision`?`needs revision`:e}var Ty=[[`unreviewed`,`Needs review`],[`approved`,`Approved keepers`],[`needs_revision`,`Needs revision`],[`rejected`,`Rejected or ignored`]];function Ey(e){let t=e.assets.filter(e=>e.local?.relative_path&&!e.s3?.key),n=t.filter(e=>ky(e)===`approved`),r=e.selectedBackupIds.length,i=`npx lineage local queue --project ${e.project} --json`;function a(){for(let t of n)e.onQueueBackup(t)}return(0,W.jsxs)(`section`,{className:`local-backup-queue`,children:[(0,W.jsxs)(`header`,{className:`backup-queue-head`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h2`,{children:`Local Backup Queue`}),(0,W.jsx)(`p`,{children:`Review local-only candidates, select approved keepers, then back them up intentionally.`}),(0,W.jsxs)(`p`,{children:[e.snapshot?.catalog.default_bucket||`No bucket loaded`,` · refreshed `,ke(e.snapshot?.fetchedAt)]})]}),(0,W.jsxs)(`div`,{className:`backup-queue-actions`,children:[(0,W.jsxs)(`button`,{disabled:n.length===0,onClick:a,type:`button`,children:[(0,W.jsx)(P,{size:15}),` Select approved`]}),(0,W.jsxs)(`button`,{disabled:r===0,onClick:e.onOpenBackup,type:`button`,children:[(0,W.jsx)(I,{size:15}),` Back up selected`]})]})]}),(0,W.jsxs)(`div`,{className:`backup-queue-stats`,"aria-label":`Local backup queue summary`,children:[(0,W.jsx)(Oy,{label:`Local only`,value:t.length}),(0,W.jsx)(Oy,{label:`Needs review`,value:t.filter(e=>ky(e)===`unreviewed`).length}),(0,W.jsx)(Oy,{label:`Approved`,value:n.length}),(0,W.jsx)(Oy,{label:`Selected`,value:r})]}),(0,W.jsxs)(`div`,{className:`handoff-strip`,children:[(0,W.jsx)(`code`,{children:i}),(0,W.jsxs)(`button`,{onClick:()=>void e.onCopy(i,`local backup queue command`),type:`button`,children:[(0,W.jsx)(F,{size:14}),` Copy`]})]}),t.length===0?(0,W.jsx)(`div`,{className:`backup-empty`,children:`No local-only assets are waiting for review or backup.`}):(0,W.jsx)(`div`,{className:`backup-queue-grid`,children:Ty.map(([n,r])=>(0,W.jsxs)(`section`,{className:`backup-queue-lane`,children:[(0,W.jsx)(`h3`,{children:r}),t.filter(e=>Ay(e)===n).map(t=>(0,W.jsx)(Dy,{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,W.jsxs)(`footer`,{className:`pagination-bar`,children:[(0,W.jsx)(`button`,{disabled:!e.snapshot||e.snapshot.pagination.page<=1,onClick:()=>e.setPage(e=>Math.max(e-1,1)),type:`button`,children:`Previous`}),(0,W.jsxs)(`span`,{children:[e.snapshot?.pagination.page||e.page,` of `,e.snapshot?.pagination.totalPages||1]}),(0,W.jsx)(`button`,{disabled:!e.snapshot||e.snapshot.pagination.page>=e.snapshot.pagination.totalPages,onClick:()=>e.setPage(e=>e+1),type:`button`,children:`Next`}),(0,W.jsxs)(`label`,{children:[`Per page`,(0,W.jsx)(`select`,{onChange:t=>e.setPageSize(Number(t.target.value)),value:e.pageSize,children:[10,25,50,100].map(e=>(0,W.jsx)(`option`,{value:e,children:e},e))})]})]})]})}function Dy(e){let t=ky(e.asset),n=Re(e.asset),r=t===`approved`;return(0,W.jsxs)(`article`,{className:`backup-queue-card ${e.selected?`selected`:``}`,children:[(0,W.jsx)(`strong`,{children:e.asset.title}),(0,W.jsx)(`code`,{children:e.asset.asset_id}),(0,W.jsx)(`small`,{children:e.asset.local?.relative_path}),(0,W.jsxs)(`div`,{className:`backup-card-meta`,children:[(0,W.jsx)(`span`,{children:n.label}),(0,W.jsx)(`span`,{children:jy(t)}),(0,W.jsx)(`span`,{children:Oe(e.asset.local?.size_bytes)})]}),(0,W.jsxs)(`div`,{className:`backup-card-actions`,children:[(0,W.jsx)(`button`,{onClick:()=>e.onSelectAsset(e.asset),type:`button`,children:`Open`}),(0,W.jsx)(`button`,{"aria-pressed":t===`approved`,onClick:()=>void e.onLocalReview(e.asset,`approved`),type:`button`,children:`Approve`}),(0,W.jsx)(`button`,{"aria-pressed":t===`needs_revision`,onClick:()=>void e.onLocalReview(e.asset,`needs_revision`),type:`button`,children:`Revise`}),(0,W.jsx)(`button`,{"aria-pressed":t===`rejected`,onClick:()=>void e.onLocalReview(e.asset,`rejected`),type:`button`,children:`Reject`}),(0,W.jsx)(`button`,{disabled:!r,onClick:()=>e.onQueueBackup(e.asset),type:`button`,children:e.selectedForBackup?`Selected`:r?`Select backup`:`Approve first`})]})]})}function Oy({label:e,value:t}){return(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`strong`,{children:t}),(0,W.jsx)(`span`,{children:e})]})}function ky(e){return e.review?.review_state||`unreviewed`}function Ay(e){let t=ky(e);return t===`ignored`?`rejected`:t}function jy(e){return e===`needs_revision`?`needs revision`:e}function My({assets:e,onClear:t,onOpen:n}){return e.length===0?null:(0,W.jsxs)(`div`,{className:`local-selection-toolbar`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(`strong`,{children:[e.length,` local keeper`,e.length===1?``:`s`,` selected`]}),(0,W.jsx)(`span`,{children:`Ready for S3 backup preflight`})]}),(0,W.jsxs)(`button`,{onClick:n,children:[(0,W.jsx)(I,{size:16}),`Back up selected`]}),(0,W.jsx)(`button`,{"aria-label":`Clear local backup selection`,className:`icon-lite`,onClick:t,children:(0,W.jsx)(De,{size:16})})]})}function Ny(e){return e.find(e=>Py(e)>0)?.channel||e[0]?.channel}function Py(e){return e.totals.needsQa+e.totals.approvedLocal+e.totals.needsRevision+e.totals.rejectedLocal}var Fy=[[`needsQa`,`Needs QA`],[`approvedLocal`,`Approved`],[`needsRevision`,`Revise`],[`rejectedLocal`,`Rejected`],[`readyToPost`,`S3 ready`],[`scheduled`,`Scheduled`],[`posted`,`Posted`]];function Iy(e){let[t,n]=(0,g.useState)(null),[r,i]=(0,g.useState)(null),[a,o]=(0,g.useState)(null),[s,c]=(0,g.useState)([]),[l,u]=(0,g.useState)(``);async function d(){try{let t=new URLSearchParams({project:e.project,limit:`4`});e.channel!==`all`&&t.set(`channel`,e.channel),n(await v(`/api/review/queue?${t.toString()}`)),i(null)}catch(e){i(e instanceof Error?e.message:String(e))}}if((0,g.useEffect)(()=>{d()},[e.project,e.channel]),r)return(0,W.jsx)(`section`,{className:`review-queue`,children:(0,W.jsx)(`div`,{className:`toast error`,children:r})});if(!t)return(0,W.jsx)(`section`,{className:`review-queue`,children:(0,W.jsx)(`div`,{className:`asset-board`,children:(0,W.jsx)(`div`,{className:`board-head`,children:(0,W.jsx)(`h2`,{children:`Loading review queue`})})})});let f=t.totals.needsQa+t.totals.approvedLocal+t.totals.needsRevision+t.totals.rejectedLocal,p=new Set(t.lanes.flatMap(e=>[...e.needsQa,...e.approvedLocal,...e.needsRevision,...e.rejectedLocal]).map(e=>e.asset_id)),m=s.filter(e=>p.has(e)),h=Ny(t.lanes);function _(e){c(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])}async function y(t){if(m.length!==0){o(`batch`);try{await v(`/api/local-review/batch`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({assetIds:m,confirmWrite:!0,notes:l,project:e.project,reviewState:t})}),c(e=>e.filter(e=>!p.has(e))),u(``),await d()}finally{o(null)}}}return(0,W.jsxs)(`section`,{className:`review-queue`,children:[(0,W.jsxs)(`div`,{className:`review-summary`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(`h2`,{children:[t.project,` review queue`]}),(0,W.jsx)(`p`,{children:`Local-first queue for demo assets, channel posting state, and agent handoff.`}),(0,W.jsxs)(`p`,{children:[t.totals.channels,` channels · refreshed `,ke(t.fetchedAt)]})]}),(0,W.jsx)(Ly,{label:`Local review`,value:f}),(0,W.jsx)(Ly,{label:`S3 ready`,value:t.totals.readyToPost}),(0,W.jsx)(Ly,{label:`Scheduled`,value:t.totals.scheduled}),(0,W.jsx)(Ly,{label:`Posted`,value:t.totals.posted})]}),m.length>0?(0,W.jsxs)(`div`,{className:`batch-review-strip`,"aria-label":`Batch local review actions`,children:[(0,W.jsxs)(`strong`,{children:[m.length,` selected`]}),(0,W.jsx)(`textarea`,{"aria-label":`Shared batch review notes`,onChange:e=>u(e.target.value),placeholder:`Shared review notes`,rows:2,value:l}),(0,W.jsx)(`button`,{disabled:m.length===0||a===`batch`,onClick:()=>void y(`approved`),type:`button`,children:`Approve`}),(0,W.jsx)(`button`,{disabled:m.length===0||a===`batch`,onClick:()=>void y(`needs_revision`),type:`button`,children:`Needs revision`}),(0,W.jsx)(`button`,{disabled:m.length===0||a===`batch`,onClick:()=>void y(`rejected`),type:`button`,children:`Reject`})]}):null,(0,W.jsx)(`div`,{className:`queue-lanes`,children:t.lanes.map(t=>(0,W.jsxs)(`details`,{className:`queue-lane`,open:e.channel!==`all`||t.channel===h,children:[(0,W.jsxs)(`summary`,{children:[(0,W.jsx)(`h3`,{children:t.channel}),(0,W.jsxs)(`div`,{className:`lane-counts`,children:[(0,W.jsxs)(`span`,{children:[t.totals.needsQa,` qa`]}),(0,W.jsxs)(`span`,{children:[t.totals.approvedLocal,` approved`]}),(0,W.jsxs)(`span`,{children:[t.totals.needsRevision,` revise`]}),(0,W.jsxs)(`span`,{children:[t.totals.readyToPost,` ready`]}),(0,W.jsxs)(`span`,{children:[t.totals.scheduled,` scheduled`]}),(0,W.jsxs)(`span`,{children:[t.totals.posted,` posted`]})]})]}),(0,W.jsxs)(`div`,{className:`queue-columns`,children:[Fy.filter(([e])=>t[e].length>0).map(([n,r])=>(0,W.jsx)(Ry,{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:m,onToggleReviewSelection:_},n)),Fy.every(([e])=>t[e].length===0)&&(0,W.jsx)(`p`,{className:`review-empty`,children:`No items in this channel.`})]})]},t.channel))})]})}function Ly({label:e,value:t}){return(0,W.jsxs)(`div`,{className:`queue-stat`,children:[(0,W.jsx)(`strong`,{children:t}),(0,W.jsx)(`span`,{children:e})]})}function Ry(e){return(0,W.jsxs)(`div`,{className:`queue-column`,children:[(0,W.jsx)(`h4`,{children:e.label}),e.assets.map(t=>(0,W.jsx)(zy,{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 zy(e){let t=Re(e.asset),n=e.asset.local?By(e.asset):null,r=n===`approved`,i=e.asset.source===`local`?`npx lineage local inspect --asset-id ${e.asset.asset_id} --json`:`npx lineage inspect --asset-id ${e.asset.asset_id} --json`;return(0,W.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:[n?(0,W.jsxs)(`label`,{className:`confirm-line`,onClick:e=>e.stopPropagation(),onKeyDown:Gy,children:[(0,W.jsx)(`input`,{checked:e.selectedForReview,onChange:()=>e.onToggleReviewSelection(e.asset.asset_id),type:`checkbox`}),(0,W.jsx)(`span`,{children:`Select for batch review`})]}):null,(0,W.jsx)(`strong`,{children:e.asset.title}),(0,W.jsx)(`small`,{children:e.asset.asset_id}),(0,W.jsxs)(`div`,{className:`lane-counts`,children:[(0,W.jsx)(`span`,{className:`storage-chip ${t.kind}`,children:t.label}),(0,W.jsx)(`span`,{className:`queue-tag`,children:We(e.asset)}),n?(0,W.jsx)(`span`,{className:`review-chip ${n}`,children:Vy(n)}):null]}),n?(0,W.jsxs)(`div`,{className:`review-actions`,"aria-label":`Local review actions for ${e.asset.title}`,onKeyDown:Gy,children:[(0,W.jsx)(`button`,{"aria-pressed":n===`approved`,disabled:e.pendingReview,type:`button`,onClick:t=>Uy(t,e.onLocalReview,e.asset,`approved`),children:`Approve`}),(0,W.jsx)(`button`,{"aria-pressed":n===`needs_revision`,disabled:e.pendingReview,type:`button`,onClick:t=>Uy(t,e.onLocalReview,e.asset,`needs_revision`),children:`Needs revision`}),(0,W.jsx)(`button`,{"aria-pressed":n===`rejected`,disabled:e.pendingReview,type:`button`,onClick:t=>Uy(t,e.onLocalReview,e.asset,`rejected`),children:`Reject`})]}):null,(0,W.jsxs)(`div`,{className:`queue-actions`,onKeyDown:Gy,children:[(0,W.jsx)(`button`,{type:`button`,onClick:t=>Hy(t,e.onCopy,i),children:`Copy inspect`}),e.asset.local?r?(0,W.jsx)(`button`,{type:`button`,onClick:t=>Wy(t,e.onOpenBackup,e.asset),children:`Back up`}):(0,W.jsx)(`span`,{className:`backup-locked`,title:`Approve this local asset before backup`,children:`Backup locked until approved.`}):null]})]})}function By(e){return e.review?.review_state||`unreviewed`}function Vy(e){return e===`needs_revision`?`needs revision`:e}function Hy(e,t,n){e.stopPropagation(),t(n,`inspect command`)}function Uy(e,t,n,r){e.stopPropagation(),t(n,r)}function Wy(e,t,n){e.stopPropagation(),t(n)}function Gy(e){(e.key===`Enter`||e.key===` `)&&e.stopPropagation()}var Ky={channel:`dev`,version:`0.1.14`},qy={cloud:L,image_generator:ue,scheduler:be},Jy={cloud:`Cloud storage`,image_generator:`Image generation`,scheduler:`Social scheduling`},Yy=[{adapterType:`cloud`,ariaLabel:`Cloud storage settings`},{adapterType:`scheduler`,ariaLabel:`Social scheduling settings`},{adapterType:`image_generator`,ariaLabel:`Image generation settings`}];function Xy(e){return typeof e==`boolean`?e?`on`:`off`:typeof e==`number`?String(e):typeof e==`string`?e||`not set`:JSON.stringify(e)}function Zy(e){return Object.entries(e.safe_config).filter(([e])=>![`secret`,`token`,`password`,`credential`,`apiKey`].includes(e))}function Qy(e){return e.health_status===`configured`?`ok`:e.health_status===`missing_config`?`warn`:`muted`}function $y(e){return(0,W.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,W.jsx)(`span`,{})})}function eb(e){let[t,n]=(0,g.useState)(null),[r,i]=(0,g.useState)(null),[a,o]=(0,g.useState)(!0),[s,c]=(0,g.useState)(``);async function l(){o(!0);try{let[t,r]=await Promise.all([v(`/api/adapters/settings?project=${encodeURIComponent(e.project)}`),v(`/api/runtime`)]);n(t),i(r.runtime)}catch(t){e.onToast(`error`,t instanceof Error?t.message:String(t))}finally{o(!1)}}async function u(t){let r=`${t.adapter_type}:${t.provider}`;c(r);try{let r=await v(`/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`,`${Jy[t.adapter_type]} ${r.setting.enabled?`enabled`:`disabled`}`)}catch(t){e.onToast(`error`,t instanceof Error?t.message:String(t))}finally{c(``)}}return(0,g.useEffect)(()=>{l()},[e.project]),(0,W.jsxs)(`section`,{className:`settings-view`,children:[(0,W.jsxs)(`header`,{className:`settings-header`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h2`,{children:`Settings`}),(0,W.jsxs)(`p`,{children:[`Adapter switches, safe local preferences, and credential-source status for `,e.project,`.`]})]}),(0,W.jsxs)(`button`,{className:`secondary-button`,disabled:a,onClick:()=>void l(),type:`button`,children:[a?(0,W.jsx)(pe,{className:`spin`,size:17}):(0,W.jsx)(ve,{size:17}),`Refresh`]})]}),(0,W.jsxs)(`div`,{className:`settings-sections`,children:[(0,W.jsxs)(`section`,{"aria-label":`Release information`,className:`settings-section`,children:[(0,W.jsx)(`h3`,{children:`Release`}),(0,W.jsxs)(`dl`,{className:`settings-release`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`dt`,{children:`Version`}),(0,W.jsx)(`dd`,{children:r?.version||Ky.version})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`dt`,{children:`Channel`}),(0,W.jsx)(`dd`,{children:r?.channel||Ky.channel})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`dt`,{children:`Profile`}),(0,W.jsx)(`dd`,{children:r?.profile.id||`loading`})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`dt`,{children:`Environment`}),(0,W.jsx)(`dd`,{children:r?.profile.environment||`loading`})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`dt`,{children:`Binding`}),(0,W.jsx)(`dd`,{children:r?r.profile.bound?`bound`:`legacy unbound`:`loading`})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`dt`,{children:`Git`}),(0,W.jsx)(`dd`,{children:r?.git_sha||`not available`})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`dt`,{children:`Assets`}),(0,W.jsx)(`dd`,{className:`settings-path`,children:r?.asset_root||`loading`})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`dt`,{children:`SQLite`}),(0,W.jsx)(`dd`,{className:`settings-path`,children:r?.database.path||`loading`})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`dt`,{children:`Database`}),(0,W.jsx)(`dd`,{children:r?.database.exists?`${r.database.projects??0} projects / ${r.database.workspaces??0} workspaces`:`not created yet`})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`dt`,{children:`Schema`}),(0,W.jsx)(`dd`,{children:r?`${r.schema.migration_keys.length} migration marker(s)`:`loading`})]})]})]}),Yy.map(e=>(0,W.jsxs)(`section`,{"aria-label":e.ariaLabel,className:`settings-section`,children:[(0,W.jsx)(`h3`,{children:Jy[e.adapterType]}),(0,W.jsx)(`div`,{className:`settings-grid`,children:(t?.settings||[]).filter(t=>t.adapter_type===e.adapterType).map(e=>{let t=qy[e.adapter_type],n=`Enable ${e.label===`Buffer`?`Buffer scheduling`:e.label}`,r=s===`${e.adapter_type}:${e.provider}`;return(0,W.jsxs)(`article`,{className:`settings-card`,children:[(0,W.jsxs)(`div`,{className:`settings-card-head`,children:[(0,W.jsx)(`span`,{className:`settings-icon`,children:(0,W.jsx)(t,{size:19})}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h4`,{children:e.label}),(0,W.jsx)(`p`,{children:e.description})]}),(0,W.jsx)($y,{checked:e.enabled,disabled:r,label:n,onClick:()=>void u(e)})]}),(0,W.jsxs)(`dl`,{className:`settings-meta`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`dt`,{children:`Status`}),(0,W.jsxs)(`dd`,{className:Qy(e),children:[e.health_status===`configured`?(0,W.jsx)(P,{size:14}):(0,W.jsx)(N,{size:14}),e.health_status.replace(/_/g,` `)]})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`dt`,{children:`Credential source`}),(0,W.jsx)(`dd`,{children:e.credential.label})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`dt`,{children:`Secret ref`}),(0,W.jsx)(`dd`,{children:e.credential.secret_ref||`none`})]})]}),Zy(e).length>0&&(0,W.jsx)(`div`,{className:`settings-config`,children:Zy(e).map(([e,t])=>(0,W.jsxs)(`span`,{children:[(0,W.jsx)(`strong`,{children:e}),Xy(t)]},e))})]},`${e.adapter_type}:${e.provider}`)})})]},e.adapterType)),a&&!t&&(0,W.jsx)(`div`,{className:`settings-loading`,children:`Loading settings...`})]})]})}var tb=`Lineage`,nb=`Local-first creative lineage workspace`;function rb(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,[p,m]=(0,g.useState)(!1),[h,_]=(0,g.useState)(!0),v=a.length?a.map(e=>e.project):[i];return(0,W.jsxs)(`aside`,{className:`sidebar ${h?``:`collapsed`}`,children:[(0,W.jsx)(`button`,{"aria-label":h?`Collapse sidebar`:`Expand sidebar`,className:`sidebar-collapse-toggle`,onClick:()=>_(e=>!e),type:`button`,children:h?(0,W.jsx)(he,{size:16}):(0,W.jsx)(ge,{size:16})}),(0,W.jsxs)(`div`,{className:`brand`,children:[(0,W.jsx)(`div`,{className:`brand-mark`,"aria-label":nb,children:`L`}),(0,W.jsxs)(`div`,{className:`brand-copy`,children:[(0,W.jsx)(`h1`,{children:tb}),(0,W.jsxs)(`p`,{children:[(0,W.jsx)(`span`,{children:i}),(0,W.jsxs)(`span`,{"aria-label":`Lineage version ${Ky.version}`,className:`brand-version`,title:`Lineage version ${Ky.version}, ${Ky.channel} channel`,children:[`v`,Ky.version]})]})]})]}),(0,W.jsxs)(`button`,{"aria-controls":`mobile-sidebar-controls`,"aria-expanded":p,className:`mobile-filter-toggle`,onClick:()=>m(e=>!e),type:`button`,children:[(0,W.jsx)(Se,{size:16}),`Filters`,(0,W.jsx)(A,{className:p?`open`:``,size:16})]}),(0,W.jsxs)(`div`,{className:`sidebar-mobile-collapse`,"data-open":p,id:`mobile-sidebar-controls`,children:[(0,W.jsxs)(`div`,{className:`side-section`,children:[(0,W.jsx)(`h2`,{children:`Project`}),(0,W.jsx)(ib,{id:`asset-project-filter`,label:`Project`,value:i,values:v,onChange:c})]}),(0,W.jsxs)(`section`,{className:`side-section`,children:[(0,W.jsx)(`h2`,{children:`Filters`}),(0,W.jsx)(ib,{id:`asset-source-filter`,label:`Source`,value:d,values:Pe,onChange:e=>l(e)}),(0,W.jsx)(ib,{id:`asset-status-filter`,label:`Status`,value:f,values:Me,onChange:e=>u(e)}),(0,W.jsx)(ib,{id:`asset-channel-filter`,label:`Channel`,value:t,values:n,onChange:o}),(0,W.jsx)(ib,{id:`asset-placement-filter`,label:`Placement`,value:r,values:Ne,onChange:e=>s(e)})]})]})]})}function ib({id:e,label:t,value:n,values:r,onChange:i}){return(0,W.jsxs)(`label`,{htmlFor:e,children:[t,(0,W.jsx)(`select`,{"aria-label":t,id:e,value:n,onChange:e=>i(e.target.value),children:r.map(e=>(0,W.jsx)(`option`,{value:e,children:e},e))})]})}var ab=[{label:`Lineage`,view:`lineage`},{label:`Review`,view:`review`},{label:`Assets`,view:`assets`},{label:`Agents`,view:`agents`},{label:`Settings`,view:`settings`}],ob=[{label:`Ledger`,view:`ledger`},{label:`Content batches`,view:`content`},{label:`Backup queue`,view:`backup`}];function sb(e){let[t,n]=(0,g.useState)(!1),r=ob.some(t=>t.view===e.view);function i(t){e.setView(t),n(!1)}function a(t){e.setView(t),n(!1)}return(0,W.jsxs)(`header`,{className:`topbar`,children:[(0,W.jsxs)(`div`,{className:`view-tabs`,role:`tablist`,"aria-label":`${tb} views`,children:[ab.map(t=>(0,W.jsx)(`button`,{"aria-pressed":e.view===t.view,className:e.view===t.view?`active`:``,onClick:()=>i(t.view),type:`button`,children:t.label},t.view)),(0,W.jsxs)(`div`,{className:`more-menu`,children:[(0,W.jsxs)(`button`,{"aria-expanded":t,"aria-haspopup":`menu`,"aria-pressed":r,className:r?`active`:``,onClick:()=>n(e=>!e),type:`button`,children:[(0,W.jsx)(te,{size:16}),` More `,(0,W.jsx)(A,{className:t?`open`:``,size:15})]}),t&&(0,W.jsx)(`div`,{className:`more-menu-popover`,role:`menu`,children:ob.map(t=>(0,W.jsx)(`button`,{"aria-pressed":e.view===t.view,onClick:()=>a(t.view),role:`menuitem`,type:`button`,children:t.label},t.view))})]})]}),(0,W.jsx)(cb,{runtime:e.runtime,unavailable:e.runtimeIdentityUnavailable}),(0,W.jsxs)(`div`,{className:`searchbox`,children:[(0,W.jsx)(ye,{size:17}),(0,W.jsx)(`input`,{onChange:t=>e.setQuery(t.target.value),placeholder:`Search assets, campaigns, hooks`,value:e.query})]}),e.view!==`lineage`&&(0,W.jsxs)(`button`,{"aria-expanded":e.assetDetailsOpen,className:`secondary-button`,disabled:!e.canInspectAsset,onClick:()=>{n(!1),e.setAssetDetailsOpen(!e.assetDetailsOpen)},type:`button`,children:[(0,W.jsx)(ae,{size:17}),`Details`]}),(0,W.jsx)(`button`,{className:`icon-button`,disabled:e.loading,onClick:()=>void e.refresh(),title:`Refresh current page`,children:e.loading?(0,W.jsx)(pe,{className:`spin`,size:18}):(0,W.jsx)(ve,{size:18})}),(0,W.jsxs)(`button`,{className:`primary-button`,onClick:()=>e.setUploadOpen(!0),children:[(0,W.jsx)(Ee,{size:17}),`Upload`]})]})}function cb(e){if(e.unavailable)return(0,W.jsx)(`div`,{"aria-label":`Lineage runtime identity unavailable`,className:`runtime-identity-badge unavailable`,children:`IDENTITY UNAVAILABLE`});if(!e.runtime)return(0,W.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,W.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,W.jsx)(`strong`,{children:t.environment.toUpperCase()}),(0,W.jsxs)(`span`,{children:[t.id,n]})]})}function lb({toast:e,onDismiss:t}){return(0,W.jsxs)(`div`,{className:`toast ${e.type}`,role:`status`,children:[e.type===`ok`?(0,W.jsx)(P,{size:16}):(0,W.jsx)(xe,{size:16}),(0,W.jsx)(`span`,{children:e.message}),(0,W.jsx)(`button`,{onClick:t,children:`Dismiss`})]})}var ub=200*1024*1024;function db({channels:e,project:t,onClose:n,onUploaded:r,onError:i}){let[a,o]=(0,g.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,g.useState)(null),[l,u]=(0,g.useState)(!1),[d,f]=(0,g.useState)(!1);function p(e,t){o(n=>({...n,[e]:t}))}function m(e){o(t=>({...t,assetId:t.assetId||Ae(`demo-${t.channel}-${e}`),title:e,utmContent:t.utmContent||Ae(e).replaceAll(`-`,`_`)}))}function h(e){if(!e){c(null);return}if(e.size>ub){i(`File is larger than ${Oe(ub)}`);return}c(e)}async function _(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 v(`/api/assets/upload`,{method:`POST`,body:e})).message)}catch(e){i(e instanceof Error?e.message:String(e))}finally{f(!1)}}return(0,W.jsx)(`div`,{className:`drawer-backdrop`,children:(0,W.jsxs)(`form`,{className:`upload-drawer`,onSubmit:_,children:[(0,W.jsxs)(`header`,{children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h2`,{children:`Upload asset`}),(0,W.jsx)(`p`,{children:t})]}),(0,W.jsx)(`button`,{type:`button`,onClick:n,children:`Close`})]}),(0,W.jsxs)(`label`,{className:`file-drop`,children:[(0,W.jsx)(Ee,{size:20}),(0,W.jsx)(`span`,{children:s?s.name:`Choose creative export up to ${Oe(ub)}`}),(0,W.jsx)(`input`,{type:`file`,onChange:e=>h(e.target.files?.[0])})]}),(0,W.jsxs)(`div`,{className:`form-grid`,children:[(0,W.jsxs)(`label`,{children:[`Title`,(0,W.jsx)(`input`,{value:a.title,onChange:e=>m(e.target.value),required:!0})]}),(0,W.jsxs)(`label`,{children:[`Asset ID`,(0,W.jsx)(`input`,{value:a.assetId,onChange:e=>p(`assetId`,e.target.value),required:!0})]}),(0,W.jsxs)(`label`,{children:[`Campaign`,(0,W.jsx)(`input`,{value:a.campaign,onChange:e=>p(`campaign`,e.target.value),required:!0})]}),(0,W.jsxs)(`label`,{children:[`Channel`,(0,W.jsx)(`select`,{value:a.channel,onChange:e=>p(`channel`,e.target.value),children:e.map(e=>(0,W.jsx)(`option`,{children:e},e))})]}),(0,W.jsxs)(`label`,{children:[`Audience`,(0,W.jsx)(`input`,{value:a.audience,onChange:e=>p(`audience`,e.target.value),required:!0})]}),(0,W.jsxs)(`label`,{children:[`Status`,(0,W.jsxs)(`select`,{value:a.status,onChange:e=>p(`status`,e.target.value),children:[(0,W.jsx)(`option`,{children:`working`}),(0,W.jsx)(`option`,{children:`published`})]})]}),(0,W.jsxs)(`label`,{children:[`Type`,(0,W.jsx)(`select`,{value:a.type,onChange:e=>p(`type`,e.target.value),children:Fe.map(e=>(0,W.jsx)(`option`,{children:e},e))})]}),(0,W.jsxs)(`label`,{children:[`UTM content`,(0,W.jsx)(`input`,{value:a.utmContent,onChange:e=>p(`utmContent`,e.target.value),required:!0})]}),(0,W.jsxs)(`label`,{className:`wide`,children:[`Hook`,(0,W.jsx)(`input`,{value:a.hook,onChange:e=>p(`hook`,e.target.value)})]}),(0,W.jsxs)(`label`,{className:`wide`,children:[`CTA`,(0,W.jsx)(`input`,{value:a.cta,onChange:e=>p(`cta`,e.target.value),required:!0})]})]}),(0,W.jsxs)(`label`,{className:`confirm-line`,children:[(0,W.jsx)(`input`,{type:`checkbox`,checked:l,onChange:e=>u(e.target.checked)}),(0,W.jsx)(`span`,{children:`Confirm write to the production asset bucket`})]}),(0,W.jsxs)(`footer`,{children:[(0,W.jsx)(`button`,{type:`button`,onClick:n,children:`Cancel`}),(0,W.jsxs)(`button`,{className:`primary-button`,disabled:d||!l,children:[d?(0,W.jsx)(pe,{className:`spin`,size:16}):(0,W.jsx)(Ee,{size:16}),`Upload`]})]})]})})}function fb(e,t){let n=`${e} ${t}`.toLowerCase();return n.includes(`agent`)||n.includes(`command`)||n.includes(`selection`)||n.includes(`next context`)}function pb(){return typeof window>`u`?je:new URLSearchParams(window.location.search).get(`project`)||`demo-project`}function mb(){let[e,t]=(0,g.useState)(null),[n,r]=(0,g.useState)(null),[i,a]=(0,g.useState)(pb),[o,s]=(0,g.useState)([]),[c,l]=(0,g.useState)(`all`),[u,d]=(0,g.useState)(`all`),[f,p]=(0,g.useState)(`local`),[m,h]=(0,g.useState)(`all`),[_,x]=(0,g.useState)(``),[S,C]=(0,g.useState)(1),[w,T]=(0,g.useState)(10),[E,D]=(0,g.useState)(!1),[O,k]=(0,g.useState)(!0),[A,j]=(0,g.useState)(null),[M,N]=(0,g.useState)(null),[P,F]=(0,g.useState)({}),[I,L]=(0,g.useState)({}),[R,z]=(0,g.useState)([]),[B,ee]=(0,g.useState)([]),[te,ne]=(0,g.useState)(!1),[re,ie]=(0,g.useState)(!1),[V,ae]=(0,g.useState)(`lineage`),[oe,se]=(0,g.useState)(!1),[ce,le]=(0,g.useState)(null),[ue,H]=(0,g.useState)(0),[de,fe]=(0,g.useState)(null),[pe,me]=(0,g.useState)(!1),he=e?.catalog.project===i?e:null,ge=he?.assets||[],U=Be(ge,n)||(ce?.project===i&&ce.asset_id===n?ce:void 0),_e=U?.asset_id||``,ve=[...B.filter(e=>R.includes(e.asset_id)),...ge.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),ye=U&&P[U.asset_id]||null,be=(0,g.useMemo)(()=>[`all`,...he?.facets.channels||[]],[he]),xe=(0,g.useMemo)(()=>({assets:he?.catalog.asset_count||0,live:he?.liveObjects.length||0,orphan:he?.orphanObjects.length||0,size:he?.facets.totalSizeBytes||0}),[he]);async function Se(){try{let e=await v(`/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 Ce(){try{let e=await v(`/api/runtime`);fe(e.runtime),me(!1)}catch{fe(null),me(!0)}}async function we(){k(!0);try{let e=await v(`/api/assets?${Te()}`);t(e),r(t=>Be(e.assets,t)?.asset_id||(t&&ce?.asset_id===t?t:null)),F({}),L({})}catch(e){j({type:`error`,message:e instanceof Error?e.message:String(e)})}finally{k(!1)}}function Te(){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),m!==`all`&&e.set(`channel`,m),_.trim()&&e.set(`q`,_.trim()),e.toString()}async function Ee(e){try{let t=await e();j({type:`ok`,message:t.message}),F({}),await we()}catch(e){j({type:`error`,message:e instanceof Error?e.message:String(e)})}}async function De(e,t={}){if(!Ve(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 v(`/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 Oe(e,t){try{let n=await Bm(e);j({type:`ok`,message:n.method===`fallback`?`Copied ${t} using browser fallback`:`Copied ${t}`}),N(fb(t,e)?{label:t,text:e}:null)}catch(n){N(fb(t,e)?{label:t,text:e}:null),j({type:`error`,message:n instanceof Error?n.message:String(n)})}}async function ke(e){let t=await De(e,{quiet:!0});t&&await Oe(t,`preview link`)}function Ae(e){e.local?.relative_path&&(z(t=>t.includes(e.asset_id)?t:[...t,e.asset_id]),ee(t=>t.some(t=>t.asset_id===e.asset_id)?t:[...t,e]))}function je(e){le(e),r(e.asset_id),se(!0)}async function Me(e){r(e),se(!0);let t=ge.find(t=>t.asset_id===e);if(t){le(t);return}try{let t=await v(`/api/assets/lookup`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:i,assetIds:[e]})});t.assets[0]&&le(t.assets[0])}catch(e){j({type:`error`,message:e instanceof Error?e.message:String(e)})}}function Ne(){p(`local`),l(`all`),d(`all`),x(``),ae(`backup`)}async function Pe(e){try{e.assetId&&r(e.assetId),e.view===`lineage`&&e.workspaceId&&await v(`/api/lineage-workspaces/${encodeURIComponent(e.workspaceId)}/activate`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:i,confirmWrite:!0})}),se(!1),ae(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 Fe(e){e.local?.relative_path&&(z(t=>t.includes(e.asset_id)?t.filter(t=>t!==e.asset_id):[...t,e.asset_id]),ee(t=>t.filter(t=>t.asset_id!==e.asset_id)))}return(0,g.useEffect)(()=>{Se(),Ce()},[]),(0,g.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,g.useEffect)(()=>{j(null),N(null),le(null),se(!1)},[i]),(0,g.useEffect)(()=>{we()},[S,w,i,c,u,f,m,_,E]),(0,g.useEffect)(()=>{C(1)},[i,c,u,f,m,_,w]),(0,g.useEffect)(()=>{!Ve(U)||P[U.asset_id]||De(U,{quiet:!0})},[U?.asset_id,U?.s3?.version_id,P]),(0,g.useEffect)(()=>{if(A?.type!==`ok`)return;let e=window.setTimeout(()=>j(null),2600);return()=>window.clearTimeout(e)},[A?.message,A?.type]),(0,g.useEffect)(()=>{V===`backup`&&(p(`local`),l(`all`),d(`all`))},[V]),(0,g.useEffect)(()=>{_e||se(!1)},[_e]),(0,W.jsxs)(`div`,{className:`app-shell ${V===`lineage`?`lineage-mode`:``}`,children:[(0,W.jsx)(rb,{channel:m,channels:be,liveSync:E,placementStatus:u,project:i,projects:o,setChannel:h,setPlacementStatus:d,setProject:a,setSource:p,setStatus:l,setView:ae,showBackupQueue:Ne,source:f,snapshot:he,status:c,totals:xe}),(0,W.jsxs)(`main`,{className:`workspace`,children:[(0,W.jsx)(sb,{assetDetailsOpen:oe,canInspectAsset:!!U,loading:O,query:_,refresh:we,runtime:de,runtimeIdentityUnavailable:pe,setAssetDetailsOpen:se,setQuery:x,setUploadOpen:ie,setView:e=>e===`backup`?Ne():ae(e),view:V}),A&&(0,W.jsx)(lb,{toast:A,onDismiss:()=>j(null)}),M&&(0,W.jsx)(Rt,{copiedText:M,onDismiss:()=>N(null)}),(0,W.jsx)(Ut,{onCopy:Oe,project:i,refreshKey:ue,selectedAsset:U,view:V}),V===`review`?(0,W.jsx)(Iy,{channel:m,onCopy:Oe,onLocalReview:async(e,t)=>{await Ee(()=>y(`/api/local-review/${e.asset_id}`,i,{reviewState:t,confirmWrite:!0}))},onOpenBackup:e=>{Ae(e),ne(!0)},onSelectAsset:e=>{je(e)},project:i,selected:U}):V===`ledger`?(0,W.jsx)(nn,{project:i,query:_,onOpenAsset:Me}):V===`content`?(0,W.jsx)(Nt,{onCopy:Oe,onOpenAsset:Me,onToast:(e,t)=>j({type:e,message:t}),onWorkTargetsChanged:()=>H(e=>e+1),project:i,selectedAsset:U}):V===`agents`?(0,W.jsx)(nt,{onCopy:Oe,onOpenWork:Pe,project:i}):V===`backup`?(0,W.jsx)(Ey,{assets:ge,onCopy:Oe,onLocalReview:async(e,t)=>{await Ee(()=>y(`/api/local-review/${e.asset_id}`,i,{reviewState:t,confirmWrite:!0}))},onOpenBackup:()=>ne(!0),onQueueBackup:Ae,onSelectAsset:e=>{je(e)},page:S,pageSize:w,project:i,selected:U,selectedBackupIds:R,setPage:C,setPageSize:T,snapshot:he}):V===`assets`?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(My,{assets:ve,onClear:()=>{z([]),ee([])},onOpen:()=>ne(!0)}),(0,W.jsx)(tt,{assets:ge,liveSync:E,onCopy:Oe,onSelectionChanged:()=>H(e=>e+1),page:S,pageSize:w,previewUrls:P,project:i,selected:U,setLiveSync:D,setPage:C,setPageSize:T,setSelectedId:r,snapshot:he,source:f,totals:xe})]}):V===`settings`?(0,W.jsx)(eb,{onToast:(e,t)=>j({type:e,message:t}),project:i}):(0,W.jsx)(vy,{asset:U,onAssetsChanged:we,onSelectedAsset:r,onToast:(e,t)=>j({type:e,message:t}),project:i})]}),V!==`lineage`&&oe&&(0,W.jsx)(Xe,{asset:U,onArchive:e=>void Ee(()=>y(`/api/assets/archive`,i,{assetId:e.asset_id,confirmArchive:!0})),onClose:()=>se(!1),onCopy:(e,t)=>void Oe(e,t),onCopyPreview:e=>void ke(e),onDelete:(e,t)=>void Ee(()=>y(`/api/assets/delete-object`,i,{assetId:e.asset_id,confirmation:t})),onPlacement:(e,t,n)=>void Ee(()=>y(`/api/assets/placement`,i,{assetId:e.asset_id,channel:e.channel,...b(n),status:t,confirmWrite:!0})),onPresign:e=>void De(e,{open:!0}),onPromote:e=>void Ee(()=>y(`/api/assets/promote`,i,{assetId:e.asset_id,confirmWrite:!0})),onPull:e=>void Ee(()=>y(`/api/assets/pull`,i,{assetId:e.asset_id,out:`.asset-scratch`})),onToggleBackup:Fe,previewError:U&&I[U.asset_id]||null,previewUrl:ye,selectedForBackup:U?R.includes(U.asset_id):!1}),re&&(0,W.jsx)(db,{channels:be.filter(e=>e!==`all`),project:i,onClose:()=>ie(!1),onError:e=>j({type:`error`,message:e}),onUploaded:async e=>{j({type:`ok`,message:e}),ie(!1),await we()}}),te&&(0,W.jsx)(xy,{assets:ve,project:i,onClose:()=>ne(!1),onError:e=>j({type:`error`,message:e}),onDone:async e=>{j({type:`ok`,message:e}),z([]),ee([]),ne(!1),await we()}})]})}(0,_.createRoot)(document.getElementById(`root`)).render((0,W.jsx)(g.StrictMode,{children:(0,W.jsx)(mb,{})}));
|