@useorgx/openclaw-plugin 0.4.6 → 0.4.8

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.
@@ -1,214 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/CyxZio4Y.js","assets/B3ziCA02.js","assets/C-KIc3Wc.js","assets/sAhvFnpk.js","assets/CpJsfbXo.js","assets/Bm8QnMJ_.js"])))=>i.map(i=>d[i]);
2
- var tr=Object.defineProperty;var sr=(t,s,r)=>s in t?tr(t,s,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[s]=r;var Lt=(t,s,r)=>sr(t,typeof s!="symbol"?s+"":s,r);import{r as a,j as e,a as nr,u as ls,b as it,c as ht,d as rr,Q as ir}from"./B3ziCA02.js";import{b as ar}from"./C-KIc3Wc.js";import{v as An}from"./sAhvFnpk.js";import{m as ue,A as qe,u as In,R as or,a as lr,b as cr}from"./CpJsfbXo.js";(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))n(i);new MutationObserver(i=>{for(const o of i)if(o.type==="childList")for(const c of o.addedNodes)c.tagName==="LINK"&&c.rel==="modulepreload"&&n(c)}).observe(document,{childList:!0,subtree:!0});function r(i){const o={};return i.integrity&&(o.integrity=i.integrity),i.referrerPolicy&&(o.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?o.credentials="include":i.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function n(i){if(i.ep)return;i.ep=!0;const o=r(i);fetch(i.href,o)}})();const dr="modulepreload",ur=function(t){return"/orgx/live/"+t},Os={},rs=function(s,r,n){let i=Promise.resolve();if(r&&r.length>0){let c=function(m){return Promise.all(m.map(x=>Promise.resolve(x).then(p=>({status:"fulfilled",value:p}),p=>({status:"rejected",reason:p}))))};document.getElementsByTagName("link");const l=document.querySelector("meta[property=csp-nonce]"),y=(l==null?void 0:l.nonce)||(l==null?void 0:l.getAttribute("nonce"));i=c(r.map(m=>{if(m=ur(m),m in Os)return;Os[m]=!0;const x=m.endsWith(".css"),p=x?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${m}"]${p}`))return;const d=document.createElement("link");if(d.rel=x?"stylesheet":dr,x||(d.as="script"),d.crossOrigin="",d.href=m,y&&d.setAttribute("nonce",y),document.head.appendChild(d),x)return new Promise((h,N)=>{d.addEventListener("load",h),d.addEventListener("error",()=>N(new Error(`Unable to preload CSS for ${m}`)))})}))}function o(c){const l=new Event("vite:preloadError",{cancelable:!0});if(l.payload=c,window.dispatchEvent(l),!l.defaultPrevented)throw c}return i.then(c=>{for(const l of c||[])l.status==="rejected"&&o(l.reason);return s().catch(o)})},Rs=()=>{const t=new Date,s=r=>new Date(t.getTime()-r*60*1e3).toISOString();return{connection:"connected",lastActivity:"2m ago",lastSnapshotAt:t.toISOString(),sessions:{groups:[{id:"init-1",label:"Q4 Feature Ship",status:"active"},{id:"init-2",label:"Black Friday Email",status:"active"}],edges:[{parentId:"run-1",childId:"run-2"},{parentId:"run-1",childId:"run-3"}],nodes:[{id:"run-1",parentId:null,runId:"run-1",title:"Q4 Feature Ship – Planning",agentId:"eli",agentName:"Eli",status:"running",progress:45,initiativeId:"init-1",workstreamId:null,groupId:"init-1",groupLabel:"Q4 Feature Ship",startedAt:s(120),updatedAt:s(2),lastEventAt:s(2),lastEventSummary:"Delegated work to design and data agents.",blockers:[]},{id:"run-2",parentId:"run-1",runId:"run-2",title:"Dashboard UI pass",agentId:"dana",agentName:"Dana",status:"running",progress:70,initiativeId:"init-1",workstreamId:"ws-4",groupId:"init-1",groupLabel:"Q4 Feature Ship",startedAt:s(80),updatedAt:s(5),lastEventAt:s(5),lastEventSummary:"Drafted handoff for approval.",blockers:["Approval pending"]},{id:"run-3",parentId:"run-1",runId:"run-3",title:"Usage tracking instrumentation",agentId:"pace",agentName:"Pace",status:"queued",progress:0,initiativeId:"init-1",workstreamId:"ws-5",groupId:"init-1",groupLabel:"Q4 Feature Ship",startedAt:s(30),updatedAt:s(12),lastEventAt:s(12),lastEventSummary:"Waiting for data pipeline access.",blockers:["Access to events table"]},{id:"run-4",parentId:null,runId:"run-4",title:"Black Friday Email Campaign",agentId:"mark",agentName:"Mark",status:"running",progress:55,initiativeId:"init-2",workstreamId:null,groupId:"init-2",groupLabel:"Black Friday Email",startedAt:s(90),updatedAt:s(8),lastEventAt:s(8),lastEventSummary:"Drafted subject line variants.",blockers:[]}]},activity:[{id:"activity-1",type:"decision_requested",title:"Decision requested",description:"Approve dashboard UI layout for Q4 Feature Ship.",agentId:"dana",agentName:"Dana",runId:"run-2",initiativeId:"init-1",timestamp:s(2)},{id:"activity-2",type:"artifact_created",title:"Artifact created: Subject line variants",description:"Drafted 3 subject line variants for approval.",agentId:"mark",agentName:"Mark",runId:"run-4",initiativeId:"init-2",timestamp:s(8)},{id:"activity-3",type:"delegation",title:"Task delegated",description:"Spin up data agent for instrumentation plan.",agentId:"eli",agentName:"Eli",runId:"run-1",initiativeId:"init-1",timestamp:s(18)}],handoffs:[{id:"handoff-1",title:"Dashboard UI approval",status:"created",priority:"high",summary:"Need approval on dashboard UI layout and component hierarchy.",currentActorType:"user",currentActorId:"me",createdAt:s(12),updatedAt:s(2),events:[{id:"handoff-event-1",handoffId:"handoff-1",eventType:"created",actorType:"agent",actorId:"dana",payload:{summary:"Draft layout ready for review."},createdAt:s(12)}]}],decisions:[{id:"decision-1",title:"Approve dashboard copy update",context:"Marketing requested a copy refresh before final launch. Confirm wording changes.",status:"pending",agentName:"Mark",requestedAt:s(22),updatedAt:s(2),waitingMinutes:22}],outbox:{pendingTotal:0,pendingByQueue:{},oldestEventAt:null,newestEventAt:null,replayStatus:"idle",lastReplayAttemptAt:null,lastReplaySuccessAt:null,lastReplayFailureAt:null,lastReplayError:null}}};function jt(t){const s=t instanceof Date?t:new Date(t);return Number.isNaN(s.getTime())?"":s.toLocaleString()}function Ce(t){const r=(t instanceof Date?t:new Date(t)).getTime()-Date.now();if(Number.isNaN(r))return"unknown";const n=Math.floor(Math.abs(r)/1e3),i=r<0?"past":"future";if(n<10)return i==="past"?"just now":"soon";if(n<60)return i==="past"?`${n}s ago`:`in ${n}s`;const o=Math.floor(n/60);if(o<60)return i==="past"?`${o}m ago`:`in ${o}m`;const c=Math.floor(o/60);if(c<24)return i==="past"?`${c}h ago`:`in ${c}h`;const l=Math.floor(c/24);return i==="past"?`${l}d ago`:`in ${l}d`}const pr=8e3,mr=320,xr=600,hr=120,fr=120,gr=90,qs=6e4,En={pendingTotal:0,pendingByQueue:{},oldestEventAt:null,newestEventAt:null,replayStatus:"idle",lastReplayAttemptAt:null,lastReplaySuccessAt:null,lastReplayFailureAt:null,lastReplayError:null},zs={running:0,active:0,queued:1,in_progress:1,working:1,planning:1,pending:2,blocked:3,failed:4,cancelled:5,paused:6,completed:6,archived:7},Mn=new Set(["running","active","queued","in_progress","working","planning","pending","blocked"]),Us=45*6e4;function Ee(t){if(!t)return 0;const s=Date.parse(t);return Number.isFinite(s)?s:0}function is(t,s){const r=zs[t.status]??99,n=zs[s.status]??99;if(r!==n)return r-n;const i=Ee(t.updatedAt??t.lastEventAt??t.startedAt),o=Ee(s.updatedAt??s.lastEventAt??s.startedAt);return i!==o?o-i:t.id.localeCompare(s.id)}function br(t){return(t??"").trim().toLowerCase()}function Ws(t){return Mn.has(br(t.status))}function xs(t){const s=[];return t.id&&s.push(`id:${t.id}`),t.runId&&s.push(`run:${t.runId}`),s}function Ks(t,s){if(!t.nodes.length)return s;if(!s.nodes.length){const h=Date.now(),N=t.nodes.filter(g=>{const f=Ee(g.updatedAt??g.lastEventAt??g.startedAt);return Ws(g)||h-f<=Us});if(!N.length)return s;const w=new Set(N.map(g=>g.id)),F=new Set(N.map(g=>g.groupId));return{nodes:N.sort(is),edges:t.edges.filter(g=>w.has(g.parentId)&&w.has(g.childId)),groups:t.groups.filter(g=>F.has(g.id))}}const r=new Set,n=[...s.nodes];for(const h of s.nodes)for(const N of xs(h))r.add(N);const i=Date.now(),o=[];for(const h of t.nodes){if(xs(h).some(g=>r.has(g)))continue;const w=Ee(h.updatedAt??h.lastEventAt??h.startedAt),F=i-w<=Us;if(Ws(h)||F){o.push(h),n.push(h);for(const g of xs(h))r.add(g)}}if(!o.length)return s;const c=new Set(n.map(h=>h.id)),l=new Map(t.groups.map(h=>[h.id,h])),y=new Map(s.groups.map(h=>[h.id,h])),m=[...s.groups];for(const h of o){if(y.has(h.groupId))continue;const N=l.get(h.groupId)??{id:h.groupId,label:h.groupLabel||h.agentName||"Ungrouped",status:null};y.set(h.groupId,N),m.push(N)}const x=h=>`${h.parentId}->${h.childId}`,p=new Set,d=[];for(const h of s.edges){if(!c.has(h.parentId)||!c.has(h.childId))continue;const N=x(h);p.has(N)||(p.add(N),d.push(h))}for(const h of t.edges){if(!c.has(h.parentId)||!c.has(h.childId))continue;const N=x(h);p.has(N)||(p.add(N),d.push(h))}return{nodes:n.sort(is),edges:d,groups:m}}function Kt(t,s){if(t.nodes.length<=s)return t;const r=[...t.nodes].sort(is).slice(0,s),n=new Set(r.map(o=>o.id)),i=new Set(r.map(o=>o.groupId));return{nodes:r,edges:t.edges.filter(o=>n.has(o.parentId)&&n.has(o.childId)),groups:t.groups.filter(o=>i.has(o.id))}}function Vs(t,s){return t.length<=s?t:[...t].sort((r,n)=>Ee(n.updatedAt)-Ee(r.updatedAt)).slice(0,s)}function yr(t){const s=t.requestedAt??t.updatedAt??null,r=t.updatedAt??s,n=Number.isFinite(t.waitingMinutes)?Math.max(0,Math.floor(t.waitingMinutes)):s?Math.max(0,Math.floor((Date.now()-Ee(s))/6e4)):0;return{id:t.id,title:t.title,context:t.context??null,status:t.status??"pending",agentName:t.agentName??null,requestedAt:s,updatedAt:r,waitingMinutes:n,metadata:t.metadata}}function Fn(t,s){if(t.length!==s.length)return!1;for(let r=0;r<t.length;r+=1)if(t[r].id!==s[r].id||t[r].timestamp!==s[r].timestamp||t[r].type!==s[r].type||t[r].title!==s[r].title)return!1;return!0}function Hs(t,s){if(t.nodes.length!==s.nodes.length||t.edges.length!==s.edges.length||t.groups.length!==s.groups.length)return!1;for(let r=0;r<t.nodes.length;r+=1){const n=t.nodes[r],i=s.nodes[r];if(n.id!==i.id||n.status!==i.status||n.title!==i.title||n.progress!==i.progress||n.updatedAt!==i.updatedAt||n.lastEventAt!==i.lastEventAt)return!1}for(let r=0;r<t.edges.length;r+=1){const n=t.edges[r],i=s.edges[r];if(n.parentId!==i.parentId||n.childId!==i.childId)return!1}for(let r=0;r<t.groups.length;r+=1){const n=t.groups[r],i=s.groups[r];if(n.id!==i.id||n.label!==i.label||n.status!==i.status)return!1}return!0}function Js(t,s){if(t.length!==s.length)return!1;for(let r=0;r<t.length;r+=1)if(t[r].id!==s[r].id||t[r].updatedAt!==s[r].updatedAt||t[r].status!==s[r].status||t[r].title!==s[r].title)return!1;return!0}function Qs(t,s){if(t.length!==s.length)return!1;for(let r=0;r<t.length;r+=1)if(t[r].id!==s[r].id||t[r].status!==s[r].status||t[r].updatedAt!==s[r].updatedAt||t[r].waitingMinutes!==s[r].waitingMinutes)return!1;return!0}function _n(t){if(!t||typeof t!="object")return En;const s=t.pendingByQueue&&typeof t.pendingByQueue=="object"?Object.fromEntries(Object.entries(t.pendingByQueue).filter(([n])=>typeof n=="string"&&n.length>0).map(([n,i])=>[n,Number.isFinite(Number(i))?Math.max(0,Math.floor(Number(i))):0])):{},r=t.replayStatus==="running"||t.replayStatus==="success"||t.replayStatus==="error"?t.replayStatus:"idle";return{pendingTotal:Number.isFinite(t.pendingTotal)?Math.max(0,Math.floor(t.pendingTotal)):Object.values(s).reduce((n,i)=>n+i,0),pendingByQueue:s,oldestEventAt:t.oldestEventAt??null,newestEventAt:t.newestEventAt??null,replayStatus:r,lastReplayAttemptAt:t.lastReplayAttemptAt??null,lastReplaySuccessAt:t.lastReplaySuccessAt??null,lastReplayFailureAt:t.lastReplayFailureAt??null,lastReplayError:t.lastReplayError??null}}function wr(t,s){if(t.pendingTotal!==s.pendingTotal||t.oldestEventAt!==s.oldestEventAt||t.newestEventAt!==s.newestEventAt||t.replayStatus!==s.replayStatus||t.lastReplayAttemptAt!==s.lastReplayAttemptAt||t.lastReplaySuccessAt!==s.lastReplaySuccessAt||t.lastReplayFailureAt!==s.lastReplayFailureAt||t.lastReplayError!==s.lastReplayError)return!1;const r=Object.keys(t.pendingByQueue),n=Object.keys(s.pendingByQueue);if(r.length!==n.length)return!1;for(const i of r)if(t.pendingByQueue[i]!==s.pendingByQueue[i])return!1;return!0}function vr(t,s,r){if(s.length===0)return t;const n=new Map;for(const c of t)n.set(c.id,c);let i=!1;for(const c of s){const l=n.get(c.id);if(!l){n.set(c.id,c),i=!0;continue}(l.timestamp!==c.timestamp||l.type!==c.type||l.title!==c.title||l.description!==c.description||l.summary!==c.summary||l.kind!==c.kind||l.agentId!==c.agentId||l.agentName!==c.agentName||l.runId!==c.runId||l.initiativeId!==c.initiativeId||l.decisionRequired!==c.decisionRequired||JSON.stringify(l.metadata??null)!==JSON.stringify(c.metadata??null))&&(n.set(c.id,c),i=!0)}if(!i)return t;const o=Array.from(n.values()).sort((c,l)=>Ee(l.timestamp)-Ee(c.timestamp)).slice(0,r);return Fn(t,o)?t:o}function hs(t,s){const r=[...t].sort((o,c)=>Ee(c.timestamp)-Ee(o.timestamp)).slice(0,s),n=new Set,i=[];for(const o of r)n.has(o.id)||(n.add(o.id),i.push(o));return i}function Xs(t,s){const r=t.filter(o=>!!o&&typeof o.id=="string"&&o.id.length>0).map(yr).sort((o,c)=>o.waitingMinutes!==c.waitingMinutes?c.waitingMinutes-o.waitingMinutes:Ee(c.requestedAt??c.updatedAt)-Ee(o.requestedAt??o.updatedAt)).slice(0,s),n=new Set,i=[];for(const o of r)n.has(o.id)||(n.add(o.id),i.push(o));return i}function Gs(t){return t==="run_failed"||t==="blocker_created"?"blocked":t==="run_completed"||t==="milestone_completed"?"completed":t==="decision_requested"||t==="handoff_requested"?"pending":t==="decision_resolved"||t==="handoff_fulfilled"?"completed":"running"}function jr(t){const s=t.toLowerCase();return s==="running"||s==="active"?"running":s==="queued"||s==="pending"?"queued":s==="blocked"?"blocked":s==="failed"?"failed":s==="completed"||s==="done"?"completed":"archived"}function kr(t,s){return!!(Mn.has(s)||t.runId&&t.runId.trim().length>0||t.currentTask&&t.currentTask.trim().length>0)}function Vt(t){return t?`Initiative ${t.length>16?`${t.slice(0,8)}…`:t}`:"Unscoped"}function fs(t){if(!Array.isArray(t))return[];const s=[];for(const r of t)typeof r=="string"&&r.trim().length>0&&s.push(r.trim());return s}function Nr(t,s,r){const n=new Map,i=[...t].sort((l,y)=>Ee(y.timestamp)-Ee(l.timestamp));for(const l of i){if(!l.runId)continue;const y=l.runId,m=n.get(y),x=l.timestamp;if(!m){const p=l.initiativeId??null;n.set(y,{id:y,parentId:null,runId:y,title:l.title,agentId:l.agentId??null,agentName:l.agentName??null,status:Gs(l.type),progress:null,initiativeId:p,workstreamId:null,groupId:p??"unscoped",groupLabel:Vt(p),startedAt:x,updatedAt:x,lastEventAt:x,lastEventSummary:l.title,blockers:l.type==="blocker_created"&&l.description?[l.description]:[]});continue}(!m.startedAt||Ee(x)<Ee(m.startedAt))&&(m.startedAt=x),Ee(x)>=Ee(m.updatedAt??m.lastEventAt)&&(m.updatedAt=x,m.lastEventAt=x,m.lastEventSummary=l.title,m.status=Gs(l.type),l.agentName&&(m.agentName=l.agentName),l.agentId&&(m.agentId=l.agentId),l.initiativeId&&(m.initiativeId=l.initiativeId,m.groupId=l.initiativeId,m.groupLabel=Vt(l.initiativeId)),(!m.title||m.title.length<4)&&(m.title=l.title)),l.type==="blocker_created"&&l.description&&(m.blockers.includes(l.description)||m.blockers.push(l.description))}for(const l of s??[]){const y=l.runId??`agent:${l.id}`,m=n.get(y),x=jr(l.status),p=new Date().toISOString(),d=kr(l,x),h=l.startedAt??(d?p:null),N=l.initiativeId??null,w=l.currentTask&&l.currentTask.trim().length>0?l.currentTask.trim():`${l.name??l.id} ${x==="archived"?"idle":x}`;if(!m){n.set(y,{id:y,parentId:null,runId:y,title:w,agentId:l.id,agentName:l.name??l.id,status:x,progress:null,initiativeId:N,workstreamId:null,groupId:N??"unscoped",groupLabel:Vt(N),startedAt:h,updatedAt:h,lastEventAt:h,lastEventSummary:l.currentTask,blockers:fs(l.blockers)});continue}!m.agentName&&l.name&&(m.agentName=l.name),m.agentId||(m.agentId=l.id),(!m.title||m.title===m.runId)&&(m.title=w),d&&(m.updatedAt=h??m.updatedAt??p,m.lastEventAt=h??m.lastEventAt??p),m.status==="archived"&&x!=="archived"&&(m.status=x),fs(l.blockers).length>0&&(m.blockers=fs(l.blockers)),N&&!m.initiativeId&&(m.initiativeId=N,m.groupId=N,m.groupLabel=Vt(N))}const o=Array.from(n.values()).sort(is).slice(0,r),c=new Map;for(const l of o)c.has(l.groupId)||c.set(l.groupId,{id:l.groupId,label:l.groupLabel,status:l.status});return{nodes:o,edges:[],groups:Array.from(c.values())}}async function Sr(t,s){var r;try{const n=await fetch(t,s),o=(((r=n.headers.get("content-type"))==null?void 0:r.toLowerCase())??"").includes("application/json");if(!n.ok){let c=`${n.status} ${n.statusText}`;if(o){const l=await n.json().catch(()=>null);l!=null&&l.error&&(c=`${n.status} ${l.error}`)}else{const l=(await n.text().catch(()=>"")).replace(/\s+/g," ").slice(0,80);l.length>0&&(c=`${n.status} ${l}`)}return{ok:!1,status:n.status,data:null,error:c}}if(!o){const c=(await n.text().catch(()=>"")).replace(/\s+/g," ").slice(0,80);return{ok:!1,status:n.status,data:null,error:`Unexpected content type for ${t}${c?`: ${c}`:""}`}}return{ok:!0,status:n.status,data:await n.json(),error:null}}catch(n){return{ok:!1,status:0,data:null,error:n instanceof Error?n.message:"Network error"}}}function Cr(t,s,r,n,i=En,o=null,c=[]){var x,p,d;const l=((x=s[0])==null?void 0:x.timestamp)??null,y=((p=n[0])==null?void 0:p.requestedAt)??((d=n[0])==null?void 0:d.updatedAt)??null,m=Ee(l)>=Ee(y)?l:y;return{connection:"connected",lastActivity:m?Ce(m):null,lastSnapshotAt:o,sessions:t,activity:s,handoffs:r,decisions:n,outbox:_n(i),runtimeInstances:c}}function Ys(t){if(!Array.isArray(t)||t.length===0)return[];const s=new Map;for(const r of t){if(!r||typeof r!="object"||typeof r.id!="string")continue;const n=r.id.trim();n&&s.set(n,r)}return Array.from(s.values()).sort((r,n)=>Ee(n.lastEventAt??n.lastHeartbeatAt)-Ee(r.lastEventAt??r.lastHeartbeatAt))}function Zs(t,s){const r=t??[],n=s??[];if(r.length!==n.length)return!1;for(let i=0;i<r.length;i+=1)if(r[i].id!==n[i].id||r[i].state!==n[i].state||r[i].lastEventAt!==n[i].lastEventAt||r[i].runId!==n[i].runId||r[i].progressPct!==n[i].progressPct)return!1;return!0}function Ar(t={}){const{enabled:s=!0,pollInterval:r=pr,useMock:n=!1,enableDecisions:i=!0,maxSessions:o=mr,maxActivityItems:c=xr,maxHandoffs:l=hr,maxDecisions:y=fr,batchWindowMs:m=gr}=t,[x,p]=a.useState(Rs()),[d,h]=a.useState(!n),[N,w]=a.useState(null),F=a.useRef(),g=a.useRef(null),[f,k]=a.useState(!1),v=a.useRef(0),T=a.useRef(!1),D=a.useCallback((G,te,pe,j=null,E=null,u=null,I=null)=>{v.current=Date.now(),T.current=!1;const L=hs(te,c),z=Vs(pe,l);p(R=>{const me=Kt(Ks(R.sessions,Kt(G,o)),o),re=j===null?R.decisions:Xs(j,y),X=E===null?R.outbox:_n(E),K=I===null?R.runtimeInstances??[]:Ys(I);return Hs(R.sessions,me)&&Fn(R.activity,L)&&Js(R.handoffs,z)&&Qs(R.decisions,re)&&wr(R.outbox,X)&&Zs(R.runtimeInstances,K)&&R.lastSnapshotAt===u&&R.connection==="connected"?R:Cr(me,L,z,re,X,u,K)}),h(!1)},[c,y,l,o]),A=a.useCallback(async()=>{if(!s){p(te=>te.connection==="disconnected"?te:{...te,connection:"disconnected"}),h(!1),w(null);return}if(g.current)return g.current;if(n){p(Rs()),h(!1);return}const G=(async()=>{try{const te=new URLSearchParams({sessionsLimit:String(o),activityLimit:String(c),decisionsLimit:String(y),include_idle:"true"}),pe=[{label:"dashboard-bundle",url:`/orgx/api/dashboard-bundle?${te.toString()}`},{label:"live/snapshot",url:`/orgx/api/live/snapshot?${te.toString()}`}],j=[];let E=null,u=!1;for(const re of pe){const X=await Sr(re.url);if(X.ok&&X.data){E=X.data;break}(X.status===401||X.status===403)&&(u=!0),j.push(`${re.label}: ${X.error??"unavailable"}`)}if(!E){if(u){const re=new Error("Unauthorized. Update your OrgX API key in Settings (use a user-scoped oxk_... key; userId should be blank).");throw re.code="ORGX_AUTH",re}throw new Error(j.length>0?j.join(" | "):"Snapshot endpoint unavailable")}const I=Array.isArray(E.activity)?E.activity:[],L=Array.isArray(E.handoffs)?E.handoffs:[],z=i&&Array.isArray(E.decisions)?E.decisions:[],R=E.sessions&&Array.isArray(E.sessions.nodes)&&Array.isArray(E.sessions.edges)&&Array.isArray(E.sessions.groups)?E.sessions:Nr(I,E.agents,o);D(R,I,L,z,E.outbox??null,E.generatedAt??null,E.runtimeInstances??null);const me=Array.isArray(E.degraded)?E.degraded:[];me.length>0?(w(`Partial live data: ${me.join("; ")}`),p(re=>re.connection==="connected"?re:{...re,connection:"connected"}),k(!1)):(w(null),p(re=>re.connection==="connected"?re:{...re,connection:"connected"}))}catch(te){const pe=te instanceof Error?te.message:"Unknown error",j=!!(te&&typeof te=="object"&&"code"in te&&te.code==="ORGX_AUTH");j&&(T.current=!0);const E=v.current>0&&Date.now()-v.current>qs;w(pe),p(u=>{const I=j||E?"disconnected":"reconnecting";return u.connection===I?u:{...u,connection:I}}),k(!j),h(!1)}finally{g.current=null}})();return g.current=G,G},[D,s,i,c,y,l,o,n]),ee=a.useCallback(async(G,te)=>{if(!i)throw new Error("OrgX decisions are unavailable while disconnected.");const pe=Array.from(new Set(G.filter(Boolean)));if(pe.length===0)return{updated:0,failed:0};if(n){const R=new Set(pe);return p(me=>{const re=me.decisions.filter(le=>R.has(le.id));if(re.length===0)return me;const X=new Date().toISOString(),K=re.map(le=>({id:`decision:${te}:${le.id}:${Date.now()}`,type:"decision_resolved",title:te==="approve"?`Approved: ${le.title}`:`Rejected: ${le.title}`,description:le.context,agentId:null,agentName:le.agentName,runId:null,initiativeId:null,timestamp:X,metadata:{decisionId:le.id,action:te}})),Ae=hs(K.concat(me.activity),c);return{...me,decisions:me.decisions.filter(le=>!R.has(le.id)),activity:Ae,lastActivity:Ce(X)}}),{updated:R.size,failed:0}}const j=await fetch("/orgx/api/live/decisions/approve",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({ids:pe,action:te})}),E=await j.json().catch(()=>null),u=Array.isArray(E==null?void 0:E.results)?E.results:[],I=new Set(u.filter(R=>R.ok).map(R=>R.id));if(!j.ok&&j.status!==207){const R=typeof(E==null?void 0:E.error)=="string"?E.error:`Decision action failed (${j.status})`;throw new Error(R)}if(I.size===0&&j.ok&&((E==null?void 0:E.failed)??0)===0)for(const R of pe)I.add(R);I.size>0?p(R=>{const me=R.decisions.filter(le=>I.has(le.id));if(me.length===0)return R;const re=new Date().toISOString(),X=me.map(le=>({id:`decision:${te}:${le.id}:${Date.now()}`,type:"decision_resolved",title:te==="approve"?`Approved: ${le.title}`:`Rejected: ${le.title}`,description:le.context,agentId:null,agentName:le.agentName,runId:null,initiativeId:null,timestamp:re,metadata:{decisionId:le.id,action:te}})),K=hs(X.concat(R.activity),c);return{...R,decisions:R.decisions.filter(le=>!I.has(le.id)),activity:K,lastActivity:Ce(re)}}):j.ok&&pe.length>0&&p(R=>({...R,decisions:R.decisions.filter(me=>!pe.includes(me.id))})),A();const L=(E==null?void 0:E.updated)??I.size,z=(E==null?void 0:E.failed)??Math.max(0,pe.length-I.size);return{updated:L,failed:z}},[i,A,c,n]),ie=a.useCallback(async G=>ee([G],"approve"),[ee]),ne=a.useCallback(async()=>{let G=[];return p(te=>(G=te.decisions.map(pe=>pe.id),te)),G.length===0?{updated:0,failed:0}:ee(G,"approve")},[ee]);return a.useEffect(()=>{i||p(G=>G.decisions.length===0?G:{...G,decisions:[]})},[i]),a.useEffect(()=>{if(!s){k(!1),h(!1),w(null);return}if(n){A();return}A();const G=new EventSource("/orgx/api/live/stream"),te=new EventSource("/orgx/api/hooks/runtime/stream");let pe=null,j=null,E=null,u=null,I=[],L=null,z;const R=()=>{if(z=void 0,pe){v.current=Date.now(),T.current=!1;const X=pe;pe=null,E=null,u=null,I=[],L=null,j=null,D(X.sessions,X.activity,X.handoffs,X.decisions,X.outbox,X.generatedAt,X.runtimeInstances);return}!E&&!u&&!L&&!j&&I.length===0||(v.current=Date.now(),T.current=!1,p(X=>{var Ae;let K=X;if(E){const le=Kt(E,o),Ie=Kt(Ks(K.sessions,le),o);E=null,Hs(K.sessions,Ie)||(K={...K,sessions:Ie})}if(u){const le=Vs(u,l);u=null,Js(K.handoffs,le)||(K={...K,handoffs:le})}if(L){const le=Xs(L,y);L=null,Qs(K.decisions,le)||(K={...K,decisions:le})}if(j){const le=Ys(j);j=null,Zs(K.runtimeInstances,le)||(K={...K,runtimeInstances:le})}if(I.length>0){const le=vr(K.activity,I,c);I=[],le!==K.activity&&(K={...K,activity:le,lastActivity:(Ae=le[0])!=null&&Ae.timestamp?Ce(le[0].timestamp):K.lastActivity})}return K===X?X:K.connection==="connected"?K:{...K,connection:"connected"}}),w(null),h(!1))},me=()=>{z||(z=setTimeout(R,m))};G.onopen=()=>{v.current=Date.now(),T.current=!1,k(!1),p(X=>X.connection==="connected"?X:{...X,connection:"connected"}),w(null)},G.onerror=()=>{if(T.current){p(K=>K.connection==="disconnected"?K:{...K,connection:"disconnected"}),k(!1);return}const X=v.current>0&&Date.now()-v.current>qs;p(K=>K.connection===(X?"disconnected":"reconnecting")?K:{...K,connection:X?"disconnected":"reconnecting"}),k(!0)},G.addEventListener("snapshot",X=>{try{const K=JSON.parse(X.data),Ae=typeof K.generatedAt=="string"&&K.generatedAt.length>0?K.generatedAt:new Date().toISOString();pe={sessions:K.sessions,activity:K.activity??[],handoffs:K.handoffs??[],decisions:i?K.decisions??null:[],outbox:K.outbox??null,generatedAt:Ae,runtimeInstances:Array.isArray(K.runtimeInstances)?K.runtimeInstances:null},me()}catch(K){w(K instanceof Error?K.message:"Invalid snapshot")}}),G.addEventListener("activity.appended",X=>{try{const K=JSON.parse(X.data);if(K.length===0)return;I=I.concat(K),me()}catch{}}),G.addEventListener("session.updated",X=>{try{E=JSON.parse(X.data),me()}catch{}});const re=X=>{try{const K=JSON.parse(X.data);j=Array.isArray(K)?K:[K],me()}catch{}};return G.addEventListener("runtime.updated",re),te.addEventListener("runtime.updated",re),G.addEventListener("handoff.updated",X=>{try{u=JSON.parse(X.data),me()}catch{}}),G.addEventListener("decision.updated",X=>{if(i)try{L=JSON.parse(X.data),me()}catch{}}),()=>{z&&clearTimeout(z),G.close(),te.close()}},[D,m,s,i,A,c,y,l,o,n]),a.useEffect(()=>{if(s&&!n&&(F.current&&clearInterval(F.current),!!f))return F.current=setInterval(A,r),()=>{F.current&&clearInterval(F.current)}},[s,A,r,f,n]),{data:x,isLoading:d,error:N,refetch:A,approveDecision:ie,approveAllDecisions:ne}}const Ot=[{id:"live",label:"Live",minutes:null},{id:"all",label:"All",minutes:null},{id:"24h",label:"24h",minutes:1440},{id:"3d",label:"3d",minutes:4320},{id:"7d",label:"7d",minutes:10080},{id:"30d",label:"30d",minutes:720*60}];function $n(t){return Ot.find(s=>s.id===t)??Ot[0]}function Bs(t,s=Date.now()){if(t==="all")return null;if(t==="live")return s-60*6e4;const r=Ot.find(n=>n.id===t);return!r||r.minutes===null?null:s-r.minutes*6e4}function Ir(t,s=Date.now()){const r=Bs(t,s);return r?new Date(r).toISOString():null}function as(t){if(!t)return 0;const s=Date.parse(t);return Number.isFinite(s)?s:0}function Tn(t,s){const r=as(s.timestamp)-as(t.timestamp);return r!==0?r:String(s.id).localeCompare(String(t.id))}function Er(t,s){const r=JSON.stringify({beforeEpoch:t,beforeId:s});return btoa(unescape(encodeURIComponent(r))).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+/g,"")}function en(t){if(!t||t.length===0)return null;const s=t[t.length-1],r=as(s.timestamp);return r?Er(r,String(s.id)):null}function Mr(t,s,r){const n=new Map;for(const i of t??[]){if(!i||typeof i.id!="string"||r&&i.runId!==r)continue;const o=as(i.timestamp);o&&(s!==null&&o<s||n.set(i.id,i))}return Array.from(n.values()).sort(Tn)}function tn(t,s){if(s.length===0)return t;const r=new Map;for(const i of t)r.set(i.id,i);let n=!1;for(const i of s){const o=r.get(i.id);if(!o){r.set(i.id,i),n=!0;continue}(o.timestamp!==i.timestamp||o.type!==i.type||o.title!==i.title||o.description!==i.description||o.summary!==i.summary||JSON.stringify(o.metadata??null)!==JSON.stringify(i.metadata??null))&&(r.set(i.id,i),n=!0)}return n?Array.from(r.values()).sort(Tn):t}function Fr(t){const{seed:s,timeFilterId:r,runId:n=null,pageSize:i=200}=t,o=a.useMemo(()=>Bs(r),[r]),c=a.useMemo(()=>Ir(r),[r]),l=a.useMemo(()=>Mr(s,o,n),[s,o,n]),[y,m]=a.useState(l),[x,p]=a.useState(()=>en(l)),[d,h]=a.useState(!1),[N,w]=a.useState(null),[F,g]=a.useState(null),f=a.useRef(null);a.useEffect(()=>{m(l),p(en(l)),w(null),g(null)},[l,r,n]),a.useEffect(()=>{m(T=>tn(T,l))},[l]);const k=a.useCallback(async()=>{if(!x)return;if(f.current)return f.current;h(!0);const T=(async()=>{try{const D=new URLSearchParams;D.set("limit",String(Math.max(1,Math.min(500,i)))),D.set("cursor",x),c&&D.set("since",c),n&&n.trim().length>0&&D.set("run",n.trim());const A=await fetch(`/orgx/api/live/activity/page?${D.toString()}`),ee=await A.json().catch(()=>null);if(!A.ok||!ee)throw new Error(`Activity paging failed (${A.status})`);const ie=Array.isArray(ee.activities)?ee.activities:[];m(ne=>tn(ne,ie)),p(ee.nextCursor??null),g(ee.storeUpdatedAt??null),w(null)}catch(D){w(D instanceof Error?D.message:"Activity paging failed")}finally{h(!1),f.current=null}})();return f.current=T,T},[x,i,n,c]);return{items:y,hasMore:x!==null,isLoadingMore:d,error:N,storeUpdatedAt:F,loadMore:k,cutoffEpoch:o,sinceIso:c}}const _r="https://orgx.mintlify.site/guides/openclaw-plugin-setup",$r=1500,gs="orgx.onboarding.skip",Tr=680,Lr=`<!doctype html>
3
- <html lang="en">
4
- <head>
5
- <meta charset="utf-8" />
6
- <meta name="viewport" content="width=device-width, initial-scale=1" />
7
- <title>Connecting to OrgX</title>
8
- <style>
9
- :root {
10
- --bg: #02040a;
11
- --surface: #0c0e14;
12
- --surface-soft: #0f121a;
13
- --line: rgba(255, 255, 255, 0.1);
14
- --text: #f2f7ff;
15
- --muted: rgba(242, 247, 255, 0.62);
16
- --lime: #bfff00;
17
- --teal: #14b8a6;
18
- --iris: #7c7cff;
19
- }
20
-
21
- * { box-sizing: border-box; }
22
-
23
- body {
24
- margin: 0;
25
- min-height: 100vh;
26
- background:
27
- radial-gradient(920px 460px at 14% 14%, rgba(124, 124, 255, 0.12), transparent 68%),
28
- radial-gradient(840px 420px at 84% 88%, rgba(20, 184, 166, 0.12), transparent 72%),
29
- var(--bg);
30
- color: var(--text);
31
- font-family: "SF Pro Text", "SF Pro Display", Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
32
- display: grid;
33
- place-items: center;
34
- padding: 24px;
35
- }
36
-
37
- .shell {
38
- width: min(640px, 100%);
39
- border-radius: 22px;
40
- border: 1px solid var(--line);
41
- background:
42
- linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.015)),
43
- var(--surface);
44
- box-shadow:
45
- 0 28px 80px rgba(0, 0, 0, 0.58),
46
- inset 0 1px 0 rgba(255, 255, 255, 0.05);
47
- overflow: hidden;
48
- }
49
-
50
- .header {
51
- display: flex;
52
- align-items: center;
53
- justify-content: space-between;
54
- gap: 12px;
55
- padding: 16px 18px;
56
- border-bottom: 1px solid rgba(255, 255, 255, 0.08);
57
- background: rgba(0, 0, 0, 0.16);
58
- }
59
-
60
- .brand {
61
- display: inline-flex;
62
- align-items: center;
63
- gap: 10px;
64
- }
65
-
66
- .brand-mark {
67
- width: 22px;
68
- height: 22px;
69
- color: var(--lime);
70
- opacity: 0.95;
71
- }
72
-
73
- .brand-name {
74
- font-size: 14px;
75
- font-weight: 700;
76
- letter-spacing: 0.01em;
77
- color: rgba(242, 247, 255, 0.92);
78
- }
79
-
80
- .chip {
81
- display: inline-flex;
82
- align-items: center;
83
- gap: 6px;
84
- border: 1px solid rgba(191, 255, 0, 0.3);
85
- background: rgba(191, 255, 0, 0.12);
86
- color: #d8ffa1;
87
- border-radius: 999px;
88
- padding: 4px 10px;
89
- font-size: 11px;
90
- font-weight: 600;
91
- letter-spacing: 0.06em;
92
- text-transform: uppercase;
93
- }
94
-
95
- .dot {
96
- width: 7px;
97
- height: 7px;
98
- border-radius: 50%;
99
- background: var(--lime);
100
- box-shadow: 0 0 0 0 rgba(191, 255, 0, 0.56);
101
- animation: pulse 1.6s infinite ease-out;
102
- }
103
-
104
- .content {
105
- padding: 20px 20px 18px;
106
- }
107
-
108
- h1 {
109
- margin: 0;
110
- font-size: 24px;
111
- line-height: 1.18;
112
- letter-spacing: -0.02em;
113
- }
114
-
115
- .subtitle {
116
- margin: 8px 0 0;
117
- color: var(--muted);
118
- font-size: 14px;
119
- line-height: 1.5;
120
- }
121
-
122
- .steps {
123
- margin-top: 16px;
124
- display: grid;
125
- gap: 8px;
126
- }
127
-
128
- .step {
129
- display: flex;
130
- align-items: center;
131
- gap: 9px;
132
- border: 1px solid rgba(255, 255, 255, 0.08);
133
- background: var(--surface-soft);
134
- border-radius: 12px;
135
- padding: 10px 12px;
136
- font-size: 12px;
137
- }
138
-
139
- .step svg {
140
- flex-shrink: 0;
141
- width: 14px;
142
- height: 14px;
143
- }
144
-
145
- .meta {
146
- margin-top: 12px;
147
- padding-top: 12px;
148
- border-top: 1px solid rgba(255, 255, 255, 0.08);
149
- color: rgba(242, 247, 255, 0.42);
150
- font-size: 11px;
151
- }
152
-
153
- @keyframes pulse {
154
- 0% { box-shadow: 0 0 0 0 rgba(191, 255, 0, 0.56); }
155
- 100% { box-shadow: 0 0 0 12px rgba(191, 255, 0, 0); }
156
- }
157
- </style>
158
- </head>
159
- <body>
160
- <main class="shell">
161
- <header class="header">
162
- <div class="brand">
163
- <svg class="brand-mark" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
164
- <path d="M5.5 7h5.8l6.7 6"></path>
165
- <path d="M5.5 17h5.8l6.7-6"></path>
166
- <path d="M5.5 12h12.5"></path>
167
- <path d="m15.3 9.3 2.7 2.7-2.7 2.7"></path>
168
- </svg>
169
- <span class="brand-name">OrgX</span>
170
- </div>
171
- <div class="chip"><span class="dot"></span>Pairing</div>
172
- </header>
173
- <section class="content">
174
- <h1>Connecting to OrgX</h1>
175
- <p class="subtitle">Preparing a secure workspace session. This window will continue automatically.</p>
176
- <div class="steps">
177
- <div class="step">
178
- <svg viewBox="0 0 24 24" fill="none" stroke="#7C7CFF" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
179
- <circle cx="12" cy="12" r="9"></circle>
180
- <circle cx="12" cy="12" r="4.5"></circle>
181
- </svg>
182
- <span>Initializing plugin handshake</span>
183
- </div>
184
- <div class="step">
185
- <svg viewBox="0 0 24 24" fill="none" stroke="#14B8A6" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
186
- <path d="M5 3v18"></path>
187
- <path d="m5 4 12 1-2 4 2 4-12-1z"></path>
188
- </svg>
189
- <span>Opening browser approval for this workspace</span>
190
- </div>
191
- <div class="step">
192
- <svg viewBox="0 0 24 24" fill="none" stroke="#BFFF00" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
193
- <rect x="4" y="4" width="16" height="16" rx="4"></rect>
194
- <path d="M9 12.2 11 14.2 15.2 10"></path>
195
- </svg>
196
- <span>Syncing initiatives, tasks, and decisions</span>
197
- </div>
198
- </div>
199
- <div class="meta">If redirect does not start, return to OpenClaw and click “Approve in browser”.</div>
200
- </section>
201
- </main>
202
- </body>
203
- </html>`,bs={status:"idle",hasApiKey:!1,connectionVerified:!1,workspaceName:null,lastError:null,nextAction:"connect",docsUrl:_r,keySource:"none",installationId:null,connectUrl:null,pairingId:null,expiresAt:null,pollIntervalMs:null};function Pr(t){if(typeof t=="string")return t;if(t&&typeof t=="object")return JSON.stringify(t)}async function Pt(t){const s=await t,r=await s.json().catch(()=>null);return s.ok?r??{}:{ok:!1,error:Pr(r==null?void 0:r.error)??`Request failed (${s.status})`}}function Ht(t){if(t)try{An.identify(t)}catch{}}function Dr(){const[t,s]=a.useState(bs),[r,n]=a.useState(!0),[i,o]=a.useState(!1),[c,l]=a.useState(!1),y=a.useRef(null),[m,x]=a.useState(()=>typeof window>"u"?!1:window.localStorage.getItem(gs)==="1"),p=a.useCallback(async()=>{const f=await Pt(fetch("/orgx/api/onboarding/status",{method:"GET"}));if(!f.ok||!f.data){const k=f.error??"Failed to load onboarding state",v={...bs,status:"error",lastError:k,nextAction:"retry"};return s(v),v}return Ht(f.data.installationId??null),s(f.data),f.data},[]);a.useEffect(()=>{let f=!1;return(async()=>{n(!0);const k=await p();f||(s(k),n(!1))})(),()=>{f=!0}},[p]),a.useEffect(()=>{if(!(t.status==="awaiting_browser_auth"||t.status==="pairing"))return;const k=Math.max(900,t.pollIntervalMs??$r),v=window.setInterval(async()=>{const T=await Pt(fetch("/orgx/api/onboarding/status",{method:"GET"}));T.ok&&T.data&&(Ht(T.data.installationId??null),s(T.data))},k);return()=>{window.clearInterval(v)}},[t.pollIntervalMs,t.status]),a.useEffect(()=>{if(!(typeof window>"u")){if(m){window.localStorage.setItem(gs,"1");return}window.localStorage.removeItem(gs)}},[m]);const d=a.useCallback(()=>{if(typeof window>"u")return null;try{const f=window.open("","_blank");return f?(f.opener=null,f.document.title="Connecting to OrgX…",f.document.open(),f.document.write(Lr),f.document.close(),f):null}catch{return null}},[]),h=a.useCallback(async()=>{const f=d();y.current=f,o(!0);try{const k=await Pt(fetch("/orgx/api/onboarding/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({deviceName:navigator.platform||"OpenClaw Device",platform:navigator.platform})})),v=k.data;if(!k.ok||!(v!=null&&v.state)){f&&!f.closed&&f.close();const D=k.error??"Could not start pairing";s(A=>({...A,status:"error",lastError:D,nextAction:"enter_manual_key"}));return}s(v.state);const T=v.connectUrl;if(T){const D=y.current;let A=!1;if(D&&!D.closed)try{window.setTimeout(()=>{if(!D.closed)try{D.location.href=T}catch{}},Tr),A=!0}catch{A=!1}A||(A=!!window.open(T,"_blank","noopener,noreferrer")),A||s(ee=>({...ee,lastError:'Popup was blocked. Use "Approve in browser" below.',nextAction:"open_browser"}))}}finally{y.current=null,o(!1)}},[d]),N=a.useCallback(async f=>{l(!0);try{const k=f.trim(),v=k.replace(/^[a-z]+_/i,""),T=Array.from(new Set([k,v?`oxk_${v}`:"",v?`orgx_${v}`:""].map(A=>A.trim()).filter(A=>A.length>0)));let D="Manual key validation failed";for(const A of T){const ee={"Content-Type":"application/json","X-OrgX-Api-Key":A,Authorization:`Bearer ${A}`},ie=await Pt(fetch("/orgx/api/onboarding/manual-key",{method:"POST",headers:ee,body:JSON.stringify({apiKey:A})}));if(ie.ok&&ie.data)return Ht(ie.data.installationId??null),s(ie.data),ie.data;D=ie.error??D}throw s(A=>({...A,status:"manual_key",lastError:D,nextAction:"enter_manual_key"})),new Error(D)}finally{l(!1)}},[]),w=a.useCallback(async()=>{const f=await Pt(fetch("/orgx/api/onboarding/disconnect",{method:"POST"}));if(f.ok&&f.data)return Ht(f.data.installationId??null),s(f.data),f.data;const k={...bs,status:"idle"};return s(k),k},[]),F=a.useCallback(()=>{s(f=>({...f,status:"idle",lastError:null,nextAction:"connect",connectUrl:null,pairingId:null,expiresAt:null,pollIntervalMs:null}))},[]),g=a.useMemo(()=>m?!1:!(t.hasApiKey&&t.connectionVerified&&t.status==="connected"),[m,t.connectionVerified,t.hasApiKey,t.status]);return{state:t,showGate:g,isLoading:r,isStarting:i,isSubmittingManual:c,refreshStatus:p,startPairing:h,submitManualKey:N,disconnect:w,skipGate:()=>x(!0),resumeGate:()=>x(!1),backToPairing:F,setManualMode:()=>s(f=>({...f,status:"manual_key",nextAction:"enter_manual_key"}))}}function we(...t){return t.filter(Boolean).join(" ")}const C={lime:"#BFFF00",teal:"#14B8A6",cyan:"#0AD4C4",iris:"#7C7CFF",amber:"#F5B700",red:"#FF6B88",background:"#02040A",cardBg:"#08090D",cardBgElevated:"#0C0E14",cardBorderStrong:"rgba(255, 255, 255, 0.12)",textMuted:"#8F9AB7"},Br={Pace:"#7C7CFF",Eli:"#BFFF00",Dana:"#FF00D4",Mark:"#F5B700",System:"#14B8A6",Sage:"#0AD4C4",Orion:"#14B8A6",Xandy:"#FF6B88",Nova:"#A78BFA"},Or={Pace:"Engineering",Eli:"Engineering",Dana:"Product Design",Mark:"Marketing",System:"System",Sage:"Strategy",Orion:"Operations",Xandy:"Orchestrator",Nova:"Research"};function Rr(t){return Br[t]??"rgba(255, 255, 255, 0.4)"}function Ls(t){return Or[t]??null}function qr(t){return t.split(" ").map(s=>s[0]).join("").toUpperCase().slice(0,2)}function rt(t){return t.trim().toLowerCase().replace(/[\s-]+/g,"_")}const cs="/orgx/live/assets/Fm0FhtnV.png";function Ln({size:t=14,className:s="",stroke:r="currentColor",strokeWidth:n=1.8,withBackground:i=!1,backgroundColor:o="transparent"}){return e.jsxs("svg",{className:s,width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:r,strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:n,children:[i?e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"4.5",fill:o,stroke:"none"}):null,e.jsx("path",{d:"M5.5 7h5.8l6.7 6"}),e.jsx("path",{d:"M5.5 17h5.8l6.7-6"}),e.jsx("path",{d:"M5.5 12h12.5"}),e.jsx("path",{d:"m15.3 9.3 2.7 2.7-2.7 2.7"})]})}function Ne({type:t,className:s="",size:r=14,accent:n}){const i={className:s,width:r,height:r,viewBox:"0 0 24 24",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.8};if(t==="initiative"){const c=n??C.iris;return e.jsxs("svg",{...i,stroke:c,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9",fill:`${c}1A`}),e.jsx("circle",{cx:"12",cy:"12",r:"5"}),e.jsx("circle",{cx:"12",cy:"12",r:"1.5",fill:c,stroke:"none"})]})}if(t==="workstream"){const c=n??C.lime;return e.jsx(Ln,{size:r,className:s,stroke:c,strokeWidth:i.strokeWidth,withBackground:!0,backgroundColor:`${c}1A`})}if(t==="milestone"){const c=n??C.teal;return e.jsxs("svg",{...i,stroke:c,children:[e.jsx("path",{d:"M5 3v18"}),e.jsx("path",{d:"m5 4 12 1-2 4 2 4-12-1z",fill:`${c}1A`})]})}if(t==="task")return e.jsxs("svg",{...i,stroke:"rgba(255,255,255,0.76)",children:[e.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"4",fill:"rgba(255,255,255,0.12)"}),e.jsx("path",{d:"M9 12.2 11 14.2 15.2 10"})]});if(t==="decision"){const c=n??C.amber;return e.jsxs("svg",{...i,stroke:c,children:[e.jsx("path",{d:"M12 3 5.2 6.1v5.7c0 4.8 3.2 7.5 6.8 9 3.6-1.5 6.8-4.2 6.8-9V6.1z",fill:`${c}1A`}),e.jsx("path",{d:"m9.3 12.1 1.8 1.9 3.6-3.6"})]})}if(t==="session"){const c=n??C.teal;return e.jsxs("svg",{...i,stroke:c,children:[e.jsx("rect",{x:"4",y:"5",width:"16",height:"14",rx:"4",fill:`${c}14`}),e.jsx("path",{d:"M8 9h8"}),e.jsx("path",{d:"M8 13h5"}),e.jsx("path",{d:"M8 17h3"})]})}if(t==="active"){const c=n??C.lime;return e.jsxs("svg",{...i,stroke:c,children:[e.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"6",fill:`${c}12`}),e.jsx("path",{d:"M7 13h2l1.6-6 3.1 12 1.6-6H17"})]})}if(t==="blocked"){const c=n??C.red;return e.jsxs("svg",{...i,stroke:c,children:[e.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"6",fill:`${c}12`}),e.jsx("rect",{x:"7.5",y:"11",width:"9",height:"7",rx:"2",fill:"rgba(255,255,255,0.03)"}),e.jsx("path",{d:"M9 11V9.2a3 3 0 0 1 6 0V11"})]})}if(t==="failed"){const c=n??C.red;return e.jsxs("svg",{...i,stroke:c,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9",fill:`${c}12`}),e.jsx("path",{d:"M9 9l6 6"}),e.jsx("path",{d:"M15 9l-6 6"})]})}if(t==="handoff"){const c=n??C.iris;return e.jsxs("svg",{...i,stroke:c,children:[e.jsx("path",{d:"M7 12h10"}),e.jsx("path",{d:"m13 8 4 4-4 4"}),e.jsx("path",{d:"M7 8v8",opacity:"0.55"})]})}if(t==="outbox"){const c=n??C.amber;return e.jsxs("svg",{...i,stroke:c,children:[e.jsx("path",{d:"M4 12h16"}),e.jsx("path",{d:"M6 7h12l2 5v7a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-7z",fill:`${c}12`}),e.jsx("path",{d:"M9 14h6"})]})}const o=n??C.cyan;return e.jsxs("svg",{...i,stroke:o,children:[e.jsx("path",{d:"M12 3a6 6 0 0 0-6 6v2.9c0 .7-.3 1.4-.8 1.9L4 15.2h16l-1.2-1.4a2.8 2.8 0 0 1-.8-1.9V9a6 6 0 0 0-6-6z",fill:`${o}1A`}),e.jsx("path",{d:"M9.2 18a2.8 2.8 0 0 0 5.6 0"})]})}const zr=[{label:"Model Routing",desc:"Right model, right cost, every prompt",iconType:"initiative"},{label:"Live Operations",desc:"Decisions, handoffs, sessions in real time",iconType:"workstream"},{label:"Quality Gates",desc:"Automated checkpoints before shipping",iconType:"milestone"}],ts=[{id:"hierarchy",kicker:"Mission Control",title:"Map the full execution ladder in one place",description:"Trace initiatives through workstreams, milestones, and tasks with sticky context, dependency mapping, and inline edits.",highlights:[{type:"initiative",label:"Initiative",detail:"Top-level outcomes with owner and status."},{type:"workstream",label:"Workstream",detail:"Operational lanes and runner context."},{type:"milestone",label:"Milestone",detail:"Checkpoints that gate readiness."},{type:"task",label:"Task",detail:"Priority, ETA, budget, and dependencies."}],footnote:"Use the hierarchy filters to isolate open, blocked, or done work instantly."},{id:"activity",kicker:"Activity + Decisions",title:"Stay in flow while execution evolves",description:"Track agent output as it happens, review decision payloads, and keep operational context attached from plan to completion.",highlights:[{type:"notification",label:"Live feed",detail:"Messages, failures, and progress in one stream."},{type:"decision",label:"Decision queue",detail:"Approve or reject with full execution context."},{type:"workstream",label:"Handoffs",detail:"Runner transitions across domains and tasks."},{type:"task",label:"Artifacts",detail:"Completion evidence attached where it belongs."}],footnote:"Focus a session to pin a run while the rest of the org remains visible."},{id:"dispatch",kicker:"Autopilot + Next Up",title:"Dispatch work confidently with clear guardrails",description:"Queue the next workstream, open the owning initiative instantly, and escalate from manual play to controlled auto-continue.",highlights:[{type:"workstream",label:"Next Up",detail:"Queued workstreams with resolved runner and next task."},{type:"initiative",label:"Open target",detail:"Jump to the owning initiative and sticky hierarchy."},{type:"milestone",label:"Guardrails",detail:"Blocked states are surfaced before dispatch."},{type:"notification",label:"System notices",detail:"Inline success and failure feedback loops."}],footnote:"Start with Play, then enable auto-continue when queue health is stable."}],Ur=[{type:"initiative",label:"Live Initiative Sync",detail:"Initiatives and ownership stay aligned with OpenClaw execution."},{type:"decision",label:"Decision Control",detail:"Review approvals in-app without losing mission context."},{type:"workstream",label:"Queue Visibility",detail:"Understand what runs next, who runs it, and why."}],sn="openclaw plugins install @useorgx/openclaw-plugin",nn="orgx.demo_mode",Wr=6500;function Kr(t){switch(t){case"config":return"Plugin config";case"environment":return"Environment variable";case"persisted":return"Saved local credential";case"openclaw-config-file":return"OpenClaw config file";case"legacy-dev":return"Legacy dev fallback";default:return"Not detected"}}const Vr={hidden:{},visible:{transition:{staggerChildren:.07}}},xt={hidden:{opacity:0,y:14},visible:{opacity:1,y:0,transition:{duration:.45,ease:[.16,1,.3,1]}}},Hr={initiative:"text-[#A8A0FF]",workstream:"text-[#BFFF00]",milestone:"text-[#43E7D8]",task:"text-primary",session:"text-[#43E7D8]",active:"text-[#BFFF00]",blocked:"text-[#FF6B88]",failed:"text-[#FF6B88]",handoff:"text-[#A8A0FF]",outbox:"text-[#F5D37A]",decision:"text-[#F5D37A]",notification:"text-[#7EEDE1]"};function ys(t){const s=ts.length;return(t+s)%s}function Jr({state:t,isStarting:s,onConnect:r,onUseManualKey:n,onContinueWithoutOrgX:i}){const o=!!t.lastError,[c,l]=a.useState("idle"),[y,m]=a.useState("idle"),[x,p]=a.useState(0),[d,h]=a.useState(!1),N=t.hasApiKey&&t.keySource&&t.keySource!=="none",w=ts[x];a.useEffect(()=>{if(c==="idle")return;const f=window.setTimeout(()=>l("idle"),2e3);return()=>window.clearTimeout(f)},[c]),a.useEffect(()=>{if(y==="idle")return;const f=window.setTimeout(()=>m("idle"),2e3);return()=>window.clearTimeout(f)},[y]),a.useEffect(()=>{if(d)return;const f=window.setInterval(()=>{p(k=>ys(k+1))},Wr);return()=>window.clearInterval(f)},[d]);const F=async()=>{try{await navigator.clipboard.writeText(sn),l("ok")}catch{l("error")}},g=async()=>{try{const f={at:new Date().toISOString(),onboarding:{status:t.status,nextAction:t.nextAction,hasApiKey:t.hasApiKey,keySource:t.keySource,installationId:t.installationId,lastError:t.lastError},page:typeof window<"u"?window.location.href:null,userAgent:typeof navigator<"u"?navigator.userAgent:null};await navigator.clipboard.writeText(JSON.stringify(f,null,2)),m("ok")}catch{m("error")}};return e.jsxs(ue.section,{variants:Vr,initial:"hidden",animate:"visible",className:"bg-[--orgx-surface-elevated] border border-[--orgx-border] soft-shadow rounded-2xl",children:[e.jsxs("div",{className:"px-6 pt-4 sm:px-8 sm:pt-5",children:[e.jsxs(ue.div,{variants:xt,className:"flex items-center gap-2.5",children:[e.jsx("img",{src:cs,alt:"OrgX",className:"h-7 w-7 rounded-lg object-contain"}),e.jsx("span",{className:"text-body font-semibold text-primary",children:"OrgX"})]}),e.jsxs(ue.h2,{variants:xt,className:"mt-3 flex items-center gap-2.5 text-[24px] font-semibold leading-[1.2] tracking-[-0.02em] text-white sm:text-[28px]",children:[e.jsx(Ne,{type:"workstream",size:19,className:"opacity-95"}),"Connect your workspace"]}),e.jsx(ue.p,{variants:xt,className:"mt-2 max-w-2xl text-heading leading-relaxed text-secondary",children:"Orchestrate agents, approve decisions, and track progress from a single live dashboard."})]}),e.jsxs("div",{className:"mt-3 grid gap-3 px-6 sm:px-8 lg:grid-cols-[1.24fr_0.86fr]",children:[e.jsxs(ue.div,{variants:xt,className:"space-y-2.5",children:[e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.02] p-3.5",onMouseEnter:()=>h(!0),onMouseLeave:()=>h(!1),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Ne,{type:"workstream",size:14,className:"text-[#BFFF00]"}),e.jsx("p",{className:"text-micro uppercase tracking-[0.1em] text-secondary",children:"Guided Tour"})]}),e.jsxs("span",{className:"chip text-micro",children:[x+1,"/",ts.length]})]}),e.jsx(qe,{initial:!1,mode:"wait",children:e.jsxs(ue.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},exit:{opacity:0,y:-8},transition:{duration:.24,ease:[.22,1,.36,1]},className:"mt-2.5 min-h-[214px] space-y-2.5",children:[e.jsx("p",{className:"text-micro font-semibold uppercase tracking-[0.09em] text-muted",children:w.kicker}),e.jsx("h3",{className:"text-title font-semibold leading-snug text-white/94",children:w.title}),e.jsx("p",{className:"text-body leading-relaxed text-secondary",children:w.description}),e.jsx("div",{className:"grid gap-1.5 sm:grid-cols-2",children:w.highlights.map(f=>e.jsxs("div",{className:"rounded-lg border border-white/[0.08] bg-white/[0.02] px-2.5 py-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Ne,{type:f.type,size:12,className:"flex-shrink-0 opacity-92"}),e.jsx("p",{className:"text-caption font-semibold text-bright",children:f.label})]}),e.jsx("p",{className:"mt-0.5 text-micro leading-relaxed text-secondary",children:f.detail})]},`${w.id}-${f.label}`))}),e.jsx("p",{className:"text-micro leading-relaxed text-muted",children:w.footnote})]},w.id)}),e.jsxs("div",{className:"mt-1.5 flex items-center justify-between",children:[e.jsx("div",{className:"flex items-center gap-1.5",children:ts.map((f,k)=>{const v=k===x;return e.jsx("button",{type:"button",onClick:()=>p(k),"aria-label":`View slide ${k+1}`,className:`h-1.5 rounded-full transition-all ${v?"w-6 bg-[#BFFF00]":"w-2 bg-white/24 hover:bg-white/38"}`},f.id)})}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>p(f=>ys(f-1)),className:"rounded-full border border-strong bg-white/[0.03] px-2.5 py-1 text-caption text-primary transition hover:bg-white/[0.08] hover:text-white",children:"Prev"}),e.jsx("button",{type:"button",onClick:()=>p(f=>ys(f+1)),className:"rounded-full border border-strong bg-white/[0.03] px-2.5 py-1 text-caption text-primary transition hover:bg-white/[0.08] hover:text-white",children:"Next"})]})]})]}),e.jsx("div",{className:"grid grid-cols-1 gap-2.5 sm:grid-cols-3",children:zr.map(f=>e.jsxs("div",{className:"rounded-xl border border-subtle bg-white/[0.025] px-3 py-2.5",children:[e.jsx("div",{className:`mb-1.5 ${Hr[f.iconType]}`,children:e.jsx(Ne,{type:f.iconType,size:15})}),e.jsx("p",{className:"text-caption font-semibold text-white",children:f.label}),e.jsx("p",{className:"mt-0.5 text-micro leading-snug text-white/44",children:f.desc})]},f.label))}),e.jsxs(ue.div,{variants:xt,className:"flex flex-wrap items-center gap-2.5",children:[e.jsx("button",{type:"button",onClick:r,disabled:s,className:"inline-flex items-center gap-2 rounded-full bg-[#BFFF00] px-5 py-2.5 text-body font-semibold text-black shadow-[0_0_24px_rgba(191,255,0,0.12)] transition-all hover:bg-[#d3ff42] hover:shadow-[0_0_32px_rgba(191,255,0,0.22)] disabled:cursor-not-allowed disabled:opacity-50",children:s?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"h-3.5 w-3.5 animate-spin",viewBox:"0 0 16 16",fill:"none",children:[e.jsx("circle",{cx:"8",cy:"8",r:"6",stroke:"currentColor",strokeWidth:"2",opacity:"0.2"}),e.jsx("path",{d:"M14 8a6 6 0 00-6-6",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]}),"Connecting..."]}):"Connect OrgX"}),e.jsx("button",{type:"button",onClick:n,className:"rounded-full border border-white/[0.1] px-4 py-2 text-body text-secondary transition hover:border-white/[0.18] hover:text-bright",children:"Use API key"})]})]}),e.jsxs(ue.div,{variants:xt,className:"space-y-2.5",children:[e.jsxs("div",{className:"rounded-xl border border-[#14B8A6]/20 bg-[#14B8A6]/[0.06] px-3.5 py-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Ne,{type:"workstream",size:12,className:"text-[#7EEDE1]"}),e.jsx("p",{className:"text-caption uppercase tracking-[0.08em] text-[#7EEDE1]",children:"OpenClaw Integration"})]}),e.jsx("p",{className:"mt-1 text-caption leading-relaxed text-[#CFF8F3]",children:"OrgX syncs with OpenClaw so initiatives, workstreams, milestones, and tasks stay aligned with live execution."})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.02] px-3.5 py-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Ne,{type:"task",size:12,className:"opacity-90"}),e.jsx("p",{className:"text-caption uppercase tracking-[0.08em] text-muted",children:"Quick Setup"})]}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[e.jsx("code",{className:"rounded-md border border-white/[0.08] bg-black/30 px-2 py-1 font-mono text-caption text-primary",children:sn}),e.jsx("button",{type:"button",onClick:()=>{F()},className:"rounded-full border border-strong px-3 py-1 text-caption text-secondary transition hover:border-white/[0.2] hover:text-bright",children:c==="ok"?"Copied":c==="error"?"Copy failed":"Copy command"})]}),N&&e.jsxs("p",{className:"mt-2 text-caption text-secondary",children:["API key source detected: ",Kr(t.keySource)]})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.02] px-3.5 py-3",children:[e.jsx("p",{className:"text-caption uppercase tracking-[0.08em] text-muted",children:"What Unlocks After Connect"}),e.jsx("div",{className:"mt-2 space-y-1.5",children:Ur.map(f=>e.jsxs("div",{className:"rounded-lg border border-white/[0.08] bg-white/[0.02] px-2.5 py-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Ne,{type:f.type,size:12,className:"flex-shrink-0 opacity-90"}),e.jsx("p",{className:"text-caption font-semibold text-bright",children:f.label})]}),e.jsx("p",{className:"mt-0.5 text-micro leading-relaxed text-secondary",children:f.detail})]},f.label))})]})]})]}),e.jsx(ue.div,{variants:xt,className:"mx-6 mt-2 sm:mx-8",children:o?e.jsxs("div",{className:"flex items-center gap-3 rounded-xl border border-red-500/15 bg-red-500/[0.04] px-4 py-3",children:[e.jsx("span",{className:"flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-red-500/15",children:e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",children:e.jsx("path",{d:"M5 2.5v3M5 7.5h.004",stroke:"#FF6B88",strokeWidth:"1.4",strokeLinecap:"round"})})}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx("p",{className:"text-body text-red-300/80",children:t.lastError})}),e.jsxs("div",{className:"flex flex-shrink-0 items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>void g(),className:"rounded-full border border-strong bg-white/[0.04] px-3 py-1 text-caption font-medium text-primary transition hover:bg-white/[0.08] hover:text-white",title:"Copy debug details for support",children:y==="ok"?"Copied":y==="error"?"Copy failed":"Copy debug"}),e.jsx("button",{type:"button",onClick:n,className:"rounded-full border border-strong bg-white/[0.04] px-3 py-1 text-caption font-medium text-primary transition hover:bg-white/[0.08] hover:text-white",children:"Use API key"}),e.jsx("button",{type:"button",onClick:r,disabled:s,className:"rounded-full border border-red-500/20 bg-red-500/[0.06] px-3 py-1 text-caption font-semibold text-red-200/85 transition hover:bg-red-500/[0.09] hover:text-red-100 disabled:opacity-50",children:"Retry"})]})]}):e.jsxs("div",{className:"flex items-center gap-2 rounded-xl border border-subtle bg-white/[0.02] px-3.5 py-2",children:[e.jsx("span",{className:"relative flex h-1.5 w-1.5",children:e.jsx("span",{className:"relative inline-flex h-1.5 w-1.5 rounded-full bg-white/40"})}),e.jsx("span",{className:"text-body text-muted",children:"Ready to connect"})]})}),e.jsxs(ue.div,{variants:xt,className:"mt-2 flex flex-wrap items-center justify-between gap-2 border-t border-subtle px-6 py-2 sm:px-8",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx("button",{type:"button",onClick:()=>{try{window.localStorage.setItem(nn,"1")}catch{}i()},className:"text-left text-caption text-muted transition hover:text-secondary",children:"Explore demo dashboard"}),e.jsx("button",{type:"button",onClick:()=>{try{window.localStorage.removeItem(nn)}catch{}i()},className:"text-left text-caption text-faint transition hover:text-secondary",children:"Continue offline"})]}),e.jsxs("a",{href:t.docsUrl,target:"_blank",rel:"noopener noreferrer",className:"group inline-flex items-center gap-1 text-caption text-muted transition hover:text-secondary",children:["Setup guide",e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",className:"transition-transform group-hover:translate-x-0.5",children:e.jsx("path",{d:"M3.5 2.5l3 2.5-3 2.5",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round"})})]})]})]})}const Qr={hidden:{},visible:{transition:{staggerChildren:.06}}},gt={hidden:{opacity:0,y:10},visible:{opacity:1,y:0,transition:{duration:.35,ease:[.16,1,.3,1]}}};function Pn({isSubmitting:t,onSubmit:s,onBack:r}){const[n,i]=a.useState(""),[o,c]=a.useState(null),l="https://www.useorgx.com/settings#security",y=async()=>{c(null);const x=n.trim();if(!x){c("API key is required.");return}const p=/^[a-z]+_/i.test(x)?x:`oxk_${x}`;try{await s(p),i("")}catch(d){c(d instanceof Error?d.message:"Failed to validate API key.")}},m=o!==null;return e.jsxs(ue.section,{variants:Qr,initial:"hidden",animate:"visible",className:"bg-[--orgx-surface-elevated] border border-[--orgx-border] soft-shadow rounded-2xl",children:[e.jsxs("div",{className:"px-6 pt-6 sm:px-8 sm:pt-8",children:[e.jsxs(ue.div,{variants:gt,className:"flex items-center gap-2.5",children:[e.jsx("img",{src:cs,alt:"OrgX",className:"h-7 w-7 rounded-lg object-contain"}),e.jsx("span",{className:"text-body font-semibold text-primary",children:"OrgX"})]}),e.jsx(ue.h3,{variants:gt,className:"mt-5 text-[22px] font-semibold tracking-[-0.02em] text-white",children:"Manual API key"}),e.jsxs(ue.p,{variants:gt,className:"mt-1.5 text-heading leading-relaxed text-secondary",children:["Paste a key from your ",e.jsx("span",{className:"text-secondary",children:"useorgx.com"})," dashboard. Browser pairing is recommended."]}),e.jsxs(ue.p,{variants:gt,className:"mt-1 text-body text-muted",children:["Paste full key or only the part after ",e.jsx("span",{className:"font-mono text-secondary",children:"oxk_"}),"."]}),e.jsx(ue.div,{variants:gt,className:"mt-3",children:e.jsxs("a",{href:l,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-2 rounded-full border border-white/[0.10] bg-white/[0.03] px-3 py-1.5 text-body font-semibold text-secondary transition hover:bg-white/[0.06] hover:text-primary",title:"Open OrgX settings to generate an API key",children:["Generate an API key",e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none","aria-hidden":"true",children:[e.jsx("path",{d:"M4.5 2.5h5v5",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round"}),e.jsx("path",{d:"M9.5 2.5L5 7",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round"}),e.jsx("path",{d:"M2.75 3.5H2.5c-.55 0-1 .45-1 1v5c0 .55.45 1 1 1h5c.55 0 1-.45 1-1V9.5",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round"})]})]})})]}),e.jsxs(ue.div,{variants:gt,className:"mt-6 space-y-4 px-6 sm:px-8",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"mb-1.5 block text-caption font-medium uppercase tracking-[0.14em] text-muted",children:"API key"}),e.jsxs("div",{className:`flex items-stretch overflow-hidden rounded-xl border transition-colors focus-within:border-[#BFFF00]/40 ${m?"border-red-500/30":"border-white/[0.08]"}`,children:[e.jsx("span",{className:"flex items-center border-r border-subtle bg-white/[0.03] px-3 font-mono text-body text-faint select-none",children:"oxk_"}),e.jsx("input",{value:n,onChange:x=>{i(x.target.value),o&&c(null)},placeholder:"paste your key",className:"w-full bg-transparent px-3 py-2.5 font-mono text-body text-white outline-none placeholder:text-faint"})]}),m&&e.jsx(ue.p,{initial:{opacity:0,y:-3},animate:{opacity:1,y:0},className:"mt-1.5 text-body text-red-400/70",children:o})]}),e.jsxs("p",{className:"text-body text-muted",children:["User-scoped keys (",e.jsx("span",{className:"font-mono text-secondary",children:"oxk_..."}),") do not require a separate user ID header."]})]}),e.jsxs(ue.div,{variants:gt,className:"mt-6 flex flex-wrap items-center gap-3 px-6 sm:px-8",children:[e.jsx("button",{type:"button",onClick:()=>{y()},disabled:t,className:"inline-flex items-center gap-2 rounded-full bg-[#BFFF00] px-5 py-2.5 text-body font-semibold text-black shadow-[0_0_24px_rgba(191,255,0,0.12)] transition-all hover:bg-[#d3ff42] hover:shadow-[0_0_32px_rgba(191,255,0,0.22)] disabled:cursor-not-allowed disabled:opacity-50",children:t?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"h-3.5 w-3.5 animate-spin",viewBox:"0 0 16 16",fill:"none",children:[e.jsx("circle",{cx:"8",cy:"8",r:"6",stroke:"currentColor",strokeWidth:"2",opacity:"0.2"}),e.jsx("path",{d:"M14 8a6 6 0 00-6-6",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]}),"Validating..."]}):"Validate & Connect"}),e.jsx("button",{type:"button",onClick:r,className:"rounded-full border border-white/[0.1] px-4 py-2 text-body text-secondary transition hover:border-white/[0.18] hover:text-bright",children:"Back to pairing"})]}),e.jsx("div",{className:"mt-6 border-t border-subtle px-6 py-4 sm:px-8",children:e.jsx("p",{className:"text-body text-faint",children:"Keys are stored locally and never leave your device."})})]})}const Xr=[{label:"Terms",href:"https://www.useorgx.com/terms"},{label:"Privacy",href:"https://www.useorgx.com/privacy"},{label:"IP notice",href:"https://www.useorgx.com/legal"}];function Dn({className:t,compact:s=!1}){return e.jsxs("div",{className:we("flex flex-wrap items-center gap-x-3 gap-y-1 text-muted",s?"text-micro":"text-caption",t),children:[e.jsxs("span",{className:"text-faint",children:["© ",new Date().getFullYear()," OrgX"]}),Xr.map(r=>e.jsx("a",{href:r.href,target:"_blank",rel:"noopener noreferrer nofollow",className:"transition-colors hover:text-secondary",children:r.label},r.label))]})}function Gr(t){switch(t){case"starting":return"Starting secure session...";case"awaiting_browser_auth":return"Waiting for browser approval...";case"pairing":return"Confirming connection...";case"manual_key":return"Manual key entry";case"connected":return"Connected";case"error":return"Connection issue";default:return"Ready to connect"}}function Yr(t){switch(t){case"config":return"Config key";case"environment":return"Env key";case"persisted":return"Saved key";case"openclaw-config-file":return"OpenClaw key";case"legacy-dev":return"Legacy key";default:return"No key"}}function Zr(t){return t==="awaiting_browser_auth"||t==="pairing"||t==="starting"?"active":t==="error"?"error":t==="connected"?"active":"idle"}const rn={idle:"bg-white/40",active:"bg-[#BFFF00]",error:"bg-red-400"},ws="orgx.onboarding.mc_hint.dismissed",an={initial:{opacity:0,y:14,scale:.985},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-8,scale:.985},transition:{duration:.32,ease:[.16,1,.3,1]}};function ei({state:t,isLoading:s,isStarting:r,isSubmittingManual:n,onRefresh:i,onStartPairing:o,onSubmitManualKey:c,onBackToPairing:l,onUseManualKey:y,onSkip:m}){const[x,p]=a.useState(()=>typeof window>"u"?!1:window.localStorage.getItem(ws)==="1");a.useEffect(()=>{typeof window>"u"||(x?window.localStorage.setItem(ws,"1"):window.localStorage.removeItem(ws))},[x]);const d=t.status==="manual_key",h=t.status==="awaiting_browser_auth"||t.status==="pairing",N=Zr(t.status),w=N==="active"&&t.status!=="connected",F=t.status==="connected"&&!x;return e.jsx("div",{className:"relative flex min-h-screen items-start justify-center px-4 pb-6 pt-0 sm:pt-2",style:{backgroundColor:"#02040A"},children:e.jsxs(ue.div,{initial:{opacity:0},animate:{opacity:1},transition:{duration:.45},className:`relative z-10 w-full ${d?"max-w-lg":"max-w-[1120px]"}`,children:[s?e.jsxs("div",{className:"bg-[--orgx-surface-elevated] border border-[--orgx-border] rounded-2xl p-6 sm:p-8",children:[e.jsx("div",{className:"shimmer-skeleton h-7 w-28 rounded-lg"}),e.jsx("div",{className:"shimmer-skeleton mt-5 h-8 w-3/4 rounded-lg"}),e.jsx("div",{className:"shimmer-skeleton mt-3 h-4 w-2/3 rounded-lg"}),e.jsxs("div",{className:"mt-7 grid grid-cols-3 gap-2.5",children:[e.jsx("div",{className:"shimmer-skeleton h-24 rounded-xl"}),e.jsx("div",{className:"shimmer-skeleton h-24 rounded-xl"}),e.jsx("div",{className:"shimmer-skeleton h-24 rounded-xl"})]}),e.jsx("div",{className:"shimmer-skeleton mt-7 h-10 w-36 rounded-full"})]}):e.jsx(qe,{mode:"wait",children:d?e.jsx(ue.div,{...an,children:e.jsx(Pn,{isSubmitting:n,onSubmit:c,onBack:l})},"manual"):e.jsx(ue.div,{...an,children:e.jsx(Jr,{state:t,isStarting:r,onConnect:()=>{o()},onUseManualKey:y,onContinueWithoutOrgX:m})},"explainer")}),!s&&(h||t.status==="connected")&&e.jsxs(ue.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},exit:{opacity:0,y:6},transition:{delay:.15,duration:.35,ease:[.16,1,.3,1]},className:"mt-4 flex items-center justify-between rounded-xl border border-subtle bg-white/[0.025] px-4 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsxs("span",{className:"relative flex h-2 w-2",children:[w&&e.jsx("span",{className:`absolute inline-flex h-full w-full animate-ping rounded-full ${rn[N]} opacity-40`}),e.jsx("span",{className:`relative inline-flex h-2 w-2 rounded-full ${rn[N]}`})]}),e.jsx("span",{className:"text-body text-secondary",children:Gr(t.status)}),t.workspaceName&&e.jsx("span",{className:"chip",children:t.workspaceName}),t.keySource&&t.keySource!=="none"&&e.jsx("span",{className:"chip",children:Yr(t.keySource)})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[t.expiresAt&&e.jsx("span",{className:"text-caption text-muted",children:new Date(t.expiresAt).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}),t.connectUrl&&h&&e.jsx("a",{href:t.connectUrl,target:"_blank",rel:"noopener noreferrer",className:"rounded-full border border-[#BFFF00]/25 bg-[#BFFF00]/[0.05] px-3 py-1 text-caption font-medium text-[#D8FFA1] transition hover:bg-[#BFFF00]/[0.1]",children:"Approve in browser"}),e.jsx("button",{type:"button",onClick:()=>{i()},className:"rounded-full border border-white/[0.08] px-2.5 py-1 text-caption text-muted transition hover:bg-white/[0.04] hover:text-secondary",children:"Refresh"})]})]}),F&&e.jsxs(ue.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},transition:{delay:.2,duration:.3},className:"mt-3 rounded-xl border border-[#7C7CFF]/25 bg-[#7C7CFF]/10 px-4 py-3",children:[e.jsx("p",{className:"text-caption uppercase tracking-[0.08em] text-[#CFCBFF]",children:"Mission Control Tip"}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-[#E6E4FF]",children:"Open Mission Control to see initiative → workstream → milestone → task flow with dependencies and recent todos in one expandable view."}),e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("a",{href:"/orgx/live?view=mission-control",className:"rounded-full border border-[#BFFF00]/30 bg-[#BFFF00]/15 px-3 py-1 text-caption font-medium text-[#D8FFA1]",children:"Open Mission Control"}),e.jsx("button",{type:"button",onClick:()=>p(!0),className:"text-caption text-secondary underline underline-offset-2",children:"Dismiss"})]})]}),!s&&e.jsx("div",{className:"mt-3 flex justify-center",children:e.jsx(Dn,{compact:!0})})]})})}function Ge({open:t,onClose:s,children:r,maxWidth:n="max-w-2xl",fitContent:i=!1}){const o=a.useRef(null),c=a.useRef(null);a.useEffect(()=>{if(!t)return;c.current=document.activeElement instanceof HTMLElement?document.activeElement:null,(()=>{const p=o.current;if(!p)return;const d=p.querySelector('[data-modal-autofocus="true"]');if(d){d.focus();return}const h=p.querySelectorAll('a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])');h.length>0?h[0].focus():p.focus()})();const m=p=>{if(p.key==="Escape"){p.preventDefault(),s();return}if(p.key!=="Tab")return;const d=o.current;if(!d)return;const h=d.querySelectorAll('a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])');if(h.length===0){p.preventDefault(),d.focus();return}const N=h[0],w=h[h.length-1],F=document.activeElement;!p.shiftKey&&F===w?(p.preventDefault(),N.focus()):p.shiftKey&&F===N&&(p.preventDefault(),w.focus())},x=document.body.style.overflow;return document.body.style.overflow="hidden",document.addEventListener("keydown",m),()=>{var p;document.body.style.overflow=x,document.removeEventListener("keydown",m),(p=c.current)==null||p.focus()}},[t,s]);const l=e.jsx(qe,{children:t&&e.jsxs(ue.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-[120] flex items-stretch justify-center p-0 sm:items-center sm:p-6",onClick:s,"aria-hidden":!t,children:[e.jsx("div",{className:"absolute inset-0 bg-black/80 backdrop-blur-md"}),e.jsxs(ue.div,{initial:{opacity:0,scale:.95,y:20},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:20},transition:{duration:.24,ease:[.16,1,.3,1]},className:`glass-panel soft-shadow relative flex flex-col w-full ${n} overflow-hidden ${i?"h-auto max-h-[100dvh] rounded-none sm:max-h-[88vh] sm:rounded-2xl":"h-[100dvh] max-h-[100dvh] rounded-none sm:h-[88vh] sm:max-h-[88vh] sm:rounded-2xl"}`,style:{backgroundColor:C.cardBgElevated,borderColor:C.cardBorderStrong},onClick:y=>y.stopPropagation(),role:"dialog","aria-modal":"true",tabIndex:-1,ref:o,children:[e.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 h-px bg-gradient-to-r from-transparent via-white/50 to-transparent"}),r]})]})});return typeof document>"u"?l:nr.createPortal(l,document.body)}function Be(t){const s={};return t.contentTypeJson&&(s["Content-Type"]="application/json"),t.embedMode&&(s["X-Orgx-Embed"]="true"),t.authToken&&(s.Authorization=`Bearer ${t.authToken}`),s}function Bn({authToken:t=null,embedMode:s=!1,enabled:r=!0}={}){var m,x;const n=ls(),i=a.useMemo(()=>["byok-settings",{authToken:t,embedMode:s}],[t,s]),o=a.useMemo(()=>["byok-health",{authToken:t,embedMode:s}],[t,s]),c=it({queryKey:i,enabled:r,queryFn:async()=>{const p=await fetch("/orgx/api/settings/byok",{headers:Be({authToken:t,embedMode:s})}),d=await p.json().catch(()=>null);return p.ok?d:{ok:!1,updatedAt:null,providers:{openai:{configured:!1,source:"none",masked:null},anthropic:{configured:!1,source:"none",masked:null},openrouter:{configured:!1,source:"none",masked:null}},error:(d==null?void 0:d.error)??`Failed to load settings (${p.status})`}},staleTime:15e3}),l=it({queryKey:o,enabled:!1,queryFn:async()=>{const p=await fetch("/orgx/api/settings/byok/health",{headers:Be({authToken:t,embedMode:s})}),d=await p.json().catch(()=>null);return p.ok?d:{ok:!1,agentId:"main",providers:{openai:{ok:!1,error:(d==null?void 0:d.error)??`Probe failed (${p.status})`},anthropic:{ok:!1,error:(d==null?void 0:d.error)??`Probe failed (${p.status})`},openrouter:{ok:!1,error:(d==null?void 0:d.error)??`Probe failed (${p.status})`}},error:(d==null?void 0:d.error)??`Probe failed (${p.status})`}}}),y=ht({mutationFn:async p=>{const d=await fetch("/orgx/api/settings/byok",{method:"POST",headers:Be({authToken:t,embedMode:s,contentTypeJson:!0}),body:JSON.stringify(p??{})}),h=await d.json().catch(()=>null);if(!d.ok)throw new Error((h==null?void 0:h.error)??`Failed to save settings (${d.status})`);return h},onSuccess:async()=>{await n.invalidateQueries({queryKey:i})}});return{status:c.data??null,isLoading:c.isLoading,error:((m=c.data)==null?void 0:m.error)??((x=c.error)==null?void 0:x.message)??null,refetchStatus:c.refetch,update:y.mutateAsync,isSaving:y.isPending,health:l.data??null,probe:l.refetch,isProbing:l.isFetching}}const On="orgx.first_run_guide.dismissed";function ti(t){return e.jsx("span",{className:we("inline-flex h-2 w-2 rounded-full",t?"bg-emerald-400":"bg-white/35")})}function si(){try{return typeof window<"u"&&window.localStorage.getItem(On)==="1"}catch{return!1}}function ni(t){try{if(typeof window>"u")return;t&&window.localStorage.setItem(On,"1")}catch{}}function ri({open:t,onClose:s,onOpenSettings:r,onOpenOrgxSettings:n,onOpenMissionControl:i,demoMode:o,connectionVerified:c,hasSessions:l}){const y=Bn({enabled:t}),x=a.useMemo(()=>{var w;return(w=y.status)!=null&&w.ok?Number(y.status.providers.openai.configured)+Number(y.status.providers.anthropic.configured)+Number(y.status.providers.openrouter.configured):0},[y.status])>0,p=x?"mission-control":"settings",d=[{label:o?"Exit demo (optional)":"Connect OrgX",done:o?!1:c,detail:o?"Demo mode shows sample data. Connect OrgX to sync initiatives/tasks.":"Approve the pairing flow so your initiatives, tasks, and activity can sync.",action:!o&&!c&&n?{label:"Connect",onClick:n}:null},{label:"Add provider key(s)",done:x,detail:"Set OpenAI / Anthropic / OpenRouter keys for agent launches, or rely on env vars.",action:x?null:{label:"Open settings",onClick:r}},{label:"Launch your first agent",done:l,detail:"Use the “Launch” button in Agents / Chats to start a scoped run."},{label:"Open Mission Control",done:!1,detail:"Track dependency-ready next-up tasks and start auto-continue for execution.",action:{label:"Open",onClick:i}}],h=d.filter(w=>w.done).length,N=Math.round(h/d.length*100);return e.jsx(Ge,{open:t,onClose:s,maxWidth:"max-w-2xl",children:e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[e.jsx("div",{className:"border-b border-subtle px-5 py-4 sm:px-6",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-heading font-semibold text-white",children:"First run checklist"}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:"A fast path to seeing OrgX value inside OpenClaw."}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsxs("span",{className:"chip",children:[h," / ",d.length," complete"]}),e.jsxs("span",{className:"text-caption text-muted",children:[N,"% done"]})]}),e.jsx("div",{className:"mt-2 h-1.5 w-full max-w-[340px] overflow-hidden rounded-full bg-white/[0.08]",children:e.jsx("div",{className:"h-full rounded-full bg-[#BFFF00]/80",style:{width:`${N}%`}})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>{ni(!0),s()},className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.08]",title:"Don't show automatically again",children:"Don't show again"}),e.jsx("button",{type:"button",onClick:s,"aria-label":"Close checklist",className:"inline-flex h-9 w-9 items-center justify-center rounded-full border border-strong bg-white/[0.03] text-primary transition-colors hover:bg-white/[0.08] hover:text-white",children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 6L6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})})]})]})}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-5 py-4 sm:px-6",children:e.jsxs("div",{className:"rounded-2xl border border-white/[0.07] bg-white/[0.02] p-4",children:[e.jsx("div",{className:"space-y-3",children:d.map(w=>e.jsxs("div",{className:we("flex items-start justify-between gap-3 rounded-xl border p-3",w.done?"border-subtle bg-white/[0.02]":"border-white/[0.10] bg-white/[0.03]"),children:[e.jsxs("div",{className:"flex min-w-0 items-start gap-3",children:[e.jsx("div",{className:"pt-1",children:ti(w.done)}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:we("text-body font-semibold",w.done?"text-primary":"text-white"),children:w.label}),e.jsx("p",{className:"mt-0.5 text-body leading-relaxed text-secondary",children:w.detail})]})]}),w.action&&!w.done?e.jsx("button",{type:"button",onClick:w.action.onClick,"data-modal-autofocus":p==="settings"&&w.label==="Add provider key(s)"||p==="mission-control"&&w.label==="Open Mission Control"?"true":void 0,className:"shrink-0 rounded-full border border-[#BFFF00]/30 bg-[#BFFF00]/15 px-3 py-1.5 text-caption font-semibold text-[#D8FFA1]",children:w.action.label}):null]},w.label))}),e.jsxs("div",{className:"mt-4 flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",onClick:r,"data-modal-autofocus":p==="settings"?"true":void 0,className:"rounded-full border border-[#BFFF00]/30 bg-[#BFFF00]/15 px-3 py-1.5 text-caption font-semibold text-[#D8FFA1]",children:"Open settings"}),e.jsx("button",{type:"button",onClick:i,"data-modal-autofocus":p==="mission-control"?"true":void 0,className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.08]",children:"Open Mission Control"}),e.jsx("button",{type:"button",onClick:s,className:"rounded-full border border-strong px-3 py-1.5 text-caption text-secondary transition-colors hover:bg-white/[0.05] hover:text-primary",title:"Hide for now",children:"Not now"})]})]})}),e.jsx("div",{className:"border-t border-subtle px-5 py-3 sm:px-6",children:e.jsx("p",{className:"text-caption text-muted",children:"Tip: auto-continue is available per initiative from Mission Control quick actions."})})]})})}function on({children:t,color:s,pulse:r,title:n}){const i=s??C.lime;return e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full px-2.5 py-1 text-micro font-semibold uppercase tracking-[0.14em]",title:n,style:{backgroundColor:`${i}22`,border:`1px solid ${i}5a`,color:i},children:[e.jsxs("span",{className:"relative flex h-1.5 w-1.5",children:[r&&e.jsx("span",{className:"absolute inline-flex h-full w-full animate-ping rounded-full opacity-75",style:{backgroundColor:i}}),e.jsx("span",{className:"relative inline-flex h-1.5 w-1.5 rounded-full",style:{backgroundColor:i}})]}),t]})}const ii=[{id:"agents",label:"Agents",icon:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"}),e.jsx("circle",{cx:"12",cy:"7",r:"4"})]})},{id:"activity",label:"Activity",icon:e.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("polyline",{points:"22 12 18 12 15 21 9 3 6 12 2 12"})})},{id:"decisions",label:"Decisions",icon:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M12 22c5.523 0 10-4.477 10-10S17.523 2 12 2 2 6.477 2 12s4.477 10 10 10z"}),e.jsx("path",{d:"m9 12 2 2 4-4"})]})},{id:"initiatives",label:"Next Up",icon:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M4 15s1-1 4-1 5 2 8 2 4-1 4-1V3s-1 1-4 1-5-2-8-2-4 1-4 1z"}),e.jsx("line",{x1:"4",x2:"4",y1:"22",y2:"15"})]})}];function ai({activeTab:t,onTabChange:s,pendingDecisionCount:r=0}){return e.jsx("nav",{className:"pointer-events-none fixed inset-x-0 z-40 flex justify-center px-3 lg:hidden",style:{bottom:"max(10px, env(safe-area-inset-bottom))"},"aria-label":"Mobile sections",children:e.jsx("div",{className:"pointer-events-auto relative flex items-stretch gap-1 rounded-[24px] border border-strong bg-[#090d16]/90 p-1.5 shadow-[0_20px_50px_rgba(0,0,0,0.52)] backdrop-blur-xl",children:ii.map(n=>{const i=t===n.id;return e.jsxs("button",{type:"button",onClick:()=>s(n.id),"aria-current":i?"page":void 0,className:we("relative flex min-w-[76px] flex-1 flex-col items-center gap-1 overflow-hidden rounded-[18px] px-2 pb-1.5 pt-2.5 transition-colors",i?"text-lime":"text-secondary hover:text-white/72"),children:[i&&e.jsxs(e.Fragment,{children:[e.jsx(ue.span,{layoutId:"mobile-tab-active-pill",className:"absolute inset-0 rounded-[18px] border border-[#BFFF00]/28 bg-[#BFFF00]/[0.1]",transition:{type:"spring",stiffness:420,damping:34,mass:.8}}),e.jsx(ue.span,{layoutId:"mobile-tab-active-line",className:"absolute inset-x-3 top-0.5 h-[2px] rounded-full",style:{backgroundColor:C.lime},transition:{type:"spring",stiffness:440,damping:36,mass:.75}})]}),e.jsxs("span",{className:we("relative inline-flex h-8 w-8 items-center justify-center rounded-full border transition-colors",i?"border-[#BFFF00]/35 bg-[#BFFF00]/[0.12] text-[#D8FFA1]":"border-white/[0.1] bg-white/[0.03]"),children:[e.jsx("span",{className:"relative z-[1]",children:n.icon}),n.id==="decisions"&&r>0&&e.jsx("span",{className:"absolute -right-1.5 -top-1 flex h-3.5 min-w-[14px] items-center justify-center rounded-full border border-black/35 px-1 text-[8px] font-bold text-black shadow-[0_2px_8px_rgba(0,0,0,0.35)]",style:{backgroundColor:C.amber},children:r>99?"99+":r})]}),e.jsx("span",{className:we("relative z-[1] text-micro font-medium",i?"text-[#D8FFA1]":"text-secondary"),children:n.label})]},n.id)})})})}const Mo={active:"text-[#BFFF00] bg-[#BFFF00]/10 border-[#BFFF00]/20",paused:"text-[#F5B700] bg-[#F5B700]/10 border-[#F5B700]/20",blocked:"text-[#FF6B88] bg-[#FF6B88]/10 border-[#FF6B88]/20",completed:"text-[#14B8A6] bg-[#14B8A6]/10 border-[#14B8A6]/20"},oi={done:"text-[#14B8A6] bg-[#14B8A6]/10 border-[#14B8A6]/20",completed:"text-[#14B8A6] bg-[#14B8A6]/10 border-[#14B8A6]/20",in_progress:"text-[#BFFF00] bg-[#BFFF00]/10 border-[#BFFF00]/20",active:"text-[#BFFF00] bg-[#BFFF00]/10 border-[#BFFF00]/20",blocked:"text-[#FF6B88] bg-[#FF6B88]/10 border-[#FF6B88]/20",todo:"text-white/60 bg-white/5 border-white/10"},Fo=t=>oi[rt(t)]??"text-white/60 bg-white/5 border-white/10",_o=t=>{const s=rt(t);return s==="active"||s==="in_progress"?"text-[#BFFF00] bg-[#BFFF00]/10 border-[#BFFF00]/20":s==="blocked"?"text-[#FF6B88] bg-[#FF6B88]/10 border-[#FF6B88]/20":s==="completed"||s==="done"?"text-[#14B8A6] bg-[#14B8A6]/10 border-[#14B8A6]/20":"text-white/60 bg-white/5 border-white/10"},$o=t=>{const s=rt(t);return s==="done"||s==="completed"?"text-[#14B8A6] bg-[#14B8A6]/10 border-[#14B8A6]/20":s==="active"||s==="in_progress"?"text-[#BFFF00] bg-[#BFFF00]/10 border-[#BFFF00]/20":"text-white/60 bg-white/5 border-white/10"},To=t=>t.replace(/[_-]+/g," ").replace(/\s+/g," ").trim().replace(/\b\w/g,s=>s.toUpperCase()),Lo=t=>{const s=rt(t);return s==="blocked"?0:s==="in_progress"||s==="active"?1:s==="todo"||s==="planned"?2:s==="done"||s==="completed"?3:4},Et=t=>{const s=rt(t);return s==="blocked"||s==="failed"||s==="cancelled"?C.red:s==="active"||s==="in_progress"||s==="running"?C.lime:s==="done"||s==="completed"?C.teal:s==="paused"||s==="queued"||s==="pending"||s==="working"||s==="planning"?C.amber:s==="archived"||s==="draft"?"rgba(255,255,255,0.5)":"rgba(255,255,255,0.35)"},os={codex:{id:"codex",label:"Codex",accent:"#9F7AEA",tint:"rgba(159, 122, 234, 0.2)"},openai:{id:"openai",label:"OpenAI",accent:"#10B981",tint:"rgba(16, 185, 129, 0.18)"},anthropic:{id:"anthropic",label:"Anthropic",accent:"#F5B700",tint:"rgba(245, 183, 0, 0.18)"},openclaw:{id:"openclaw",label:"OpenClaw",accent:"#FF4D4D",tint:"rgba(255, 77, 77, 0.18)"},orgx:{id:"orgx",label:"OrgX",accent:C.lime,tint:"rgba(191, 255, 0, 0.18)"},unknown:{id:"unknown",label:"Agent",accent:C.teal,tint:"rgba(20, 184, 166, 0.18)"}},li=["provider","vendor","model","runtime","engine","agent","name","title","label","summary","description","source"];function ss(t,s,r,n){if(!(t==null||r>2)){if(typeof t=="string"){const i=t.trim();i.length>0&&s.push(i);return}if(Array.isArray(t)){for(const i of t)ss(i,s,r+1,n);return}if(typeof t=="object"){if(n.has(t))return;n.add(t);for(const[i,o]of Object.entries(t)){const c=i.toLowerCase();typeof o=="string"?(li.some(l=>c.includes(l))||c.startsWith("meta")||c.endsWith("id"))&&ss(o,s,r+1,n):typeof o=="object"&&o!==null&&ss(o,s,r+1,n)}}}}function ci(t){const s=t.toLowerCase();return/\bcodex\b/.test(s)||/\bcursor\b/.test(s)||s.includes("openai/codex")?"codex":s.includes("openclaw")||s.includes("clawdbot")||s.includes("moltbot")?"openclaw":s.includes("anthropic")||s.includes("claude")||s.includes("sonnet")||s.includes("opus")?"anthropic":s.includes("openai")||s.includes("chatgpt")||/\bgpt[-\s]?\d/.test(s)||/\bo[134]/.test(s)?"openai":s.includes("orgx")?"orgx":null}function ln(...t){const s=[],r=new Set;for(const n of t)ss(n,s,0,r);for(const n of s){const i=ci(n);if(i)return os[i]}return os.unknown}function di(t){return os[t]??os.unknown}function vt({children:t,className:s=""}){return e.jsx("section",{className:we("surface-tier-1 relative overflow-hidden rounded-2xl",s),children:t})}const ui={xs:18,sm:24,md:30};function pi({provider:t}){switch(t){case"openai":return e.jsx("svg",{viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{fill:"currentColor",d:"M22.2819 9.8211a5.9847 5.9847 0 0 0-.5157-4.9108 6.0462 6.0462 0 0 0-6.5098-2.9A6.0651 6.0651 0 0 0 4.9807 4.1818a5.9847 5.9847 0 0 0-3.9977 2.9 6.0462 6.0462 0 0 0 .7427 7.0966 5.98 5.98 0 0 0 .511 4.9107 6.051 6.051 0 0 0 6.5146 2.9001A5.9847 5.9847 0 0 0 13.2599 24a6.0557 6.0557 0 0 0 5.7718-4.2058 5.9894 5.9894 0 0 0 3.9977-2.9001 6.0557 6.0557 0 0 0-.7475-7.0729zm-9.022 12.6081a4.4755 4.4755 0 0 1-2.8764-1.0408l.1419-.0804 4.7783-2.7582a.7948.7948 0 0 0 .3927-.6813v-6.7369l2.02 1.1686a.071.071 0 0 1 .038.052v5.5826a4.504 4.504 0 0 1-4.4945 4.4944zm-9.6607-4.1254a4.4708 4.4708 0 0 1-.5346-3.0137l.142.0852 4.783 2.7582a.7712.7712 0 0 0 .7806 0l5.8428-3.3685v2.3324a.0804.0804 0 0 1-.0332.0615L9.74 19.9502a4.4992 4.4992 0 0 1-6.1408-1.6464zM2.3408 7.8956a4.485 4.485 0 0 1 2.3655-1.9728V11.6a.7664.7664 0 0 0 .3879.6765l5.8144 3.3543-2.0201 1.1685a.0757.0757 0 0 1-.071 0l-4.8303-2.7865A4.504 4.504 0 0 1 2.3408 7.872zm16.5963 3.8558L13.1038 8.364 15.1192 7.2a.0757.0757 0 0 1 .071 0l4.8303 2.7913a4.4944 4.4944 0 0 1-.6765 8.1042v-5.6772a.79.79 0 0 0-.407-.667zm2.0107-3.0231l-.142-.0852-4.7735-2.7818a.7759.7759 0 0 0-.7854 0L9.409 9.2297V6.8974a.0662.0662 0 0 1 .0284-.0615l4.8303-2.7866a4.4992 4.4992 0 0 1 6.6802 4.66zM8.3065 12.863l-2.02-1.1638a.0804.0804 0 0 1-.038-.0567V6.0742a4.4992 4.4992 0 0 1 7.3757-3.4537l-.142.0805L8.704 5.459a.7948.7948 0 0 0-.3927.6813zm1.0976-2.3654l2.602-1.4998 2.6069 1.4998v2.9994l-2.5974 1.4997-2.6067-1.4997Z"})});case"anthropic":return e.jsx("svg",{viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{fill:"currentColor",d:"M17.3041 3.541h-3.6718l6.696 16.918H24Zm-10.6082 0L0 20.459h3.7442l1.3693-3.5527h7.0052l1.3693 3.5528h3.7442L10.5363 3.5409Zm-.3712 10.2232 2.2914-5.9456 2.2914 5.9456Z"})});case"codex":return e.jsx("svg",{viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{fill:"currentColor",d:"M11.503.131 1.891 5.678a.84.84 0 0 0-.42.726v11.188c0 .3.162.575.42.724l9.609 5.55a1 1 0 0 0 .998 0l9.61-5.55a.84.84 0 0 0 .42-.724V6.404a.84.84 0 0 0-.42-.726L12.497.131a1.01 1.01 0 0 0-.996 0M2.657 6.338h18.55c.263 0 .43.287.297.515L12.23 22.918c-.062.107-.229.064-.229-.06V12.335a.59.59 0 0 0-.295-.51l-9.11-5.257c-.109-.063-.064-.23.061-.23"})});case"openclaw":return e.jsxs("svg",{viewBox:"0 0 120 120","aria-hidden":"true",children:[e.jsx("path",{d:"M60 10C30 10 15 35 15 55C15 75 30 95 45 100V110H55V100C55 100 60 102 65 100V110H75V100C90 95 105 75 105 55C105 35 90 10 60 10Z",fill:"currentColor"}),e.jsx("path",{d:"M20 45C5 40 0 50 5 60C10 70 20 65 25 55C28 48 25 45 20 45Z",fill:"currentColor"}),e.jsx("path",{d:"M100 45C115 40 120 50 115 60C110 70 100 65 95 55C92 48 95 45 100 45Z",fill:"currentColor"}),e.jsx("circle",{cx:"45",cy:"35",r:"6",fill:"rgba(2,4,10,0.92)"}),e.jsx("circle",{cx:"75",cy:"35",r:"6",fill:"rgba(2,4,10,0.92)"})]});case"orgx":return e.jsx("img",{src:cs,alt:"","aria-hidden":"true",className:"h-full w-full rounded-[4px] object-contain"});default:return e.jsxs("svg",{viewBox:"0 0 24 24","aria-hidden":"true",children:[e.jsx("circle",{cx:"12",cy:"12",r:"8",stroke:"currentColor",strokeWidth:"1.8",fill:"none"}),e.jsx("path",{d:"m12 6-2 7h3l-1 5 4-8h-3l1-4Z",fill:"currentColor"})]})}}function vs({provider:t,size:s="sm",className:r,showRing:n=!0}){const i=di(t),o=ui[s];return e.jsx("span",{className:we("inline-flex items-center justify-center rounded-md",r),style:{width:o,height:o,color:i.accent,backgroundColor:i.tint,border:n?`1px solid ${i.accent}55`:"none"},title:i.label,"aria-label":i.label,children:e.jsx("span",{style:{width:Math.round(o*.66),height:Math.round(o*.66),display:"inline-flex",alignItems:"center",justifyContent:"center"},children:e.jsx(pi,{provider:t})})})}const mi={xs:"w-6 h-6 text-micro",sm:"w-8 h-8 text-micro",md:"w-10 h-10 text-body"},xi="/orgx/live/",Ke=t=>`${xi.replace(/\/+$/,"/")}${t}`,hi={pace:Ke("brand/product-orchestrator.png"),eli:Ke("brand/engineering-autopilot.png"),mark:Ke("brand/launch-captain.png"),sage:Ke("brand/pipeline-intelligence.png"),orion:Ke("brand/control-tower.png"),dana:Ke("brand/design-codex.png"),xandy:Ke("brand/product-orchestrator.png"),nova:Ke("brand/product-orchestrator.png"),openclaw:Ke("brand/openclaw-mark.svg"),openai:Ke("brand/openai-mark.svg"),anthropic:Ke("brand/anthropic-mark.svg"),orgx:Ke("brand/orgx-logo.png")},fi=[{test:/\bpace\b|product|nova|strategist/i,key:"pace"},{test:/\beli\b|engineering|dev-delivery|executor/i,key:"eli"},{test:/\bmark\b|marketing|launch-captain/i,key:"mark"},{test:/\bsage\b|sales|pipeline-intelligence|sales-sage/i,key:"sage"},{test:/\borion\b|operations|ops-orbit|control-tower/i,key:"orion"},{test:/\bdana\b|design|codex/i,key:"dana"},{test:/\bxandy\b|orchestrator|router-all-agents/i,key:"xandy"},{test:/\bholt\b|openclaw/i,key:"openclaw"},{test:/openai|gpt|o[1345]-|codex/i,key:"openai"},{test:/anthropic|claude/i,key:"anthropic"},{test:/\borgx\b/i,key:"orgx"}];function gi(...t){const s=t.map(r=>typeof r=="string"?r.trim():"").filter(Boolean).join(" ").toLowerCase();if(!s)return null;for(const r of fi)if(r.test.test(s))return hi[r.key];return null}function nt({name:t,size:s="xs",hint:r,src:n}){const i=Rr(t),[o,c]=a.useState(!1),l=a.useMemo(()=>n&&n.trim()?n:gi(t,r),[r,t,n]),y=!!(l&&!o);return e.jsx("div",{className:`${mi[s]} overflow-hidden rounded-full flex items-center justify-center font-semibold flex-shrink-0`,style:{backgroundColor:`${i}20`,color:i,border:`1px solid ${i}30`},children:y?e.jsx("img",{src:l??void 0,alt:t,className:"h-full w-full rounded-full object-cover",onError:()=>c(!0),loading:"lazy"}):qr(t)})}const wt={liveData:t=>["live-data",{authToken:t.authToken??null,embedMode:t.embedMode??!1,useMock:t.useMock??!1}],sessions:t=>["sessions",{activeMinutes:t.activeMinutes??null,limit:t.limit??null,authToken:t.authToken??null,embedMode:t.embedMode??!1}],initiativeDetails:t=>["initiative-details",{initiativeId:t.initiativeId,authToken:t.authToken??null,embedMode:t.embedMode??!1}],entities:t=>["entities",{type:t.type,authToken:t.authToken??null,embedMode:t.embedMode??!1}],missionControlGraph:t=>["mission-control-graph",{initiativeId:t.initiativeId,authToken:t.authToken??null,embedMode:t.embedMode??!1}],nextUpQueue:t=>["mission-control-next-up",{initiativeId:t.initiativeId??null,authToken:t.authToken??null,embedMode:t.embedMode??!1}],autoContinueStatus:t=>["auto-continue-status",{initiativeId:t.initiativeId,authToken:t.authToken??null,embedMode:t.embedMode??!1}],liveInitiatives:t=>["live-initiatives",{limit:(t==null?void 0:t.limit)??300}]};function bi(t){const s=t.toLowerCase();return s==="completed"||s==="done"?"completed":s==="blocked"||s==="at_risk"?"blocked":s==="paused"||s==="hold"?"paused":"active"}function yi(t){if(!t)return 0;const s=new Date(t),r=new Date;return Math.max(0,Math.ceil((s.getTime()-r.getTime())/864e5))}function wi(t){return{id:t.id,name:t.title,status:bi(t.status),rawStatus:t.status??null,priority:t.priority??null,health:t.progress_pct??0,daysRemaining:yi(t.target_date),targetDate:t.target_date??null,createdAt:t.created_at??null,updatedAt:t.updated_at??t.created_at??null,activeAgents:0,totalAgents:0,description:t.summary??void 0}}function vi(t){const s=t.toLowerCase();return!["deleted","archived","cancelled"].includes(s)}function Rn(t){return it({queryKey:wt.entities({type:"initiative"}),queryFn:async()=>{const s=await fetch("/orgx/api/entities?type=initiative&limit=300");return s.ok?((await s.json()).data??[]).filter(n=>vi(n.status??"")).sort((n,i)=>{const o=Date.parse(n.updated_at??n.created_at??"")||0;return(Date.parse(i.updated_at??i.created_at??"")||0)-o}).map(wi):[]},enabled:t,staleTime:6e4})}const ji=new Set(["ungrouped","unscoped","unknown"]);function ki(t){const s=(t??"").trim().toLowerCase();return!!(!s||ji.has(s)||/^init-\d+$/.test(s)||s.startsWith("mock-"))}function Ni(){if(typeof window>"u")return!1;try{if(new URLSearchParams(window.location.search).get("demo")==="1")return!0}catch{}try{return window.localStorage.getItem("orgx.demo_mode")==="1"}catch{return!1}}function Si(t){return Ni()?!0:!ki(t)}const Jt={initiativeId:"",workstreams:[],milestones:[],tasks:[]},Ci=(t,s)=>({id:t.id,name:t.name??"Untitled workstream",summary:t.summary??null,status:t.status??"planned",progress:typeof t.progress=="number"&&!Number.isNaN(t.progress)?Math.max(0,Math.min(100,t.progress<=1?t.progress*100:t.progress)):null,initiativeId:t.initiative_id??s,createdAt:t.created_at??null}),Ai=(t,s)=>({id:t.id,title:t.title??"Untitled milestone",description:t.description??null,status:t.status??"planned",dueDate:t.due_date??null,initiativeId:t.initiative_id??s,workstreamId:t.workstream_id??null,createdAt:t.created_at??null}),Ii=(t,s)=>({id:t.id,title:t.title??"Untitled task",description:t.description??null,status:t.status??"todo",priority:t.priority??null,dueDate:t.due_date??null,initiativeId:t.initiative_id??s,milestoneId:t.milestone_id??null,workstreamId:t.workstream_id??null,createdAt:t.created_at??null});function Ei({initiativeId:t,authToken:s=null,embedMode:r=!1,enabled:n=!0}){var l;const i=Si(t),o=a.useMemo(()=>wt.initiativeDetails({initiativeId:t,authToken:s,embedMode:r}),[t,s,r]),c=it({queryKey:o,enabled:n&&!!t&&i,queryFn:async()=>{if(!t)return Jt;if(!i)return{...Jt,initiativeId:t};const y={};r&&(y["X-Orgx-Embed"]="true"),s&&(y.Authorization=`Bearer ${s}`);const m=Object.keys(y).length?y:void 0,x=async g=>{try{const f=new URLSearchParams({type:g,initiative_id:t,limit:"100"}),k=await fetch(`/orgx/api/entities?${f.toString()}`,{headers:m});return k.ok?await k.json():{data:[]}}catch{return{data:[]}}},[p,d,h]=await Promise.all([x("workstream"),x("milestone"),x("task")]),N=Array.isArray(p.data)?p.data.map(g=>Ci(g,t)):[],w=Array.isArray(d.data)?d.data.map(g=>Ai(g,t)):[],F=Array.isArray(h.data)?h.data.map(g=>Ii(g,t)):[];return{initiativeId:t,workstreams:N,milestones:w,tasks:F}}});return{details:(i?c.data:null)??(t?{...Jt,initiativeId:t}:Jt),isLoading:i?c.isLoading:!1,error:i?((l=c.error)==null?void 0:l.message)??null:null,refetch:c.refetch}}function Dt(t){const s=(t??"").toLowerCase();return s==="active"?{label:"Active",color:C.lime,bg:"rgba(191,255,0,0.12)"}:s==="blocked"?{label:"Blocked",color:"#fb7185",bg:"rgba(244, 63, 94, 0.12)"}:s==="idle"?{label:"Idle",color:"rgba(255,255,255,0.55)",bg:"rgba(255,255,255,0.06)"}:{label:t||"Unknown",color:C.iris,bg:"rgba(124,124,255,0.10)"}}function Mi(t){return[...t.workstreams].sort((s,r)=>s.name.localeCompare(r.name))}function Fi(t,s){return[...s?t.tasks.filter(n=>n.workstreamId===s):t.tasks].sort((n,i)=>n.title.localeCompare(i.title))}function _i({open:t,onClose:s,onLaunched:r}){var Ae,le,Ie,P,ce,$;const n=it({queryKey:["openclaw-agent-catalog"],queryFn:async()=>{const S=await fetch("/orgx/api/agents/catalog");if(!S.ok){const V=await S.text().catch(()=>"");throw new Error(V||`Agent catalog failed (${S.status})`)}return await S.json()},enabled:t,staleTime:2e3,refetchInterval:t?3e3:!1}),{data:i}=Rn(t),[o,c]=a.useState(""),[l,y]=a.useState(""),[m,x]=a.useState(""),[p,d]=a.useState(""),[h,N]=a.useState("auto"),[w,F]=a.useState(""),[g,f]=a.useState(null),[k,v]=a.useState(null),[T,D]=a.useState("starter"),[A,ee]=a.useState(!1),[ie,ne]=a.useState(1),G=a.useMemo(()=>{const S=l.trim();return S?(i==null?void 0:i.find(V=>V.id===S))??null:null},[i,l]),{details:te}=Ei({initiativeId:G?G.id:null,enabled:t&&!!G}),pe=a.useMemo(()=>Mi(te),[te]),j=a.useMemo(()=>Fi(te,m||null),[te,m]),E=((Ae=n.data)==null?void 0:Ae.agents)??[],u=a.useMemo(()=>{const S=o.trim();return S?E.find(V=>V.id===S)??null:null},[E,o]);a.useEffect(()=>{var V,Y;if(!t)return;const S=((V=E.find(W=>W.isDefault))==null?void 0:V.id)??((Y=E[0])==null?void 0:Y.id)??"";!o&&S&&c(S)},[E,t,o]),a.useEffect(()=>{if(!t||l.trim())return;const S=i??[],V=S.length===1?S[0]:null;V&&y(V.id)},[i,t,l]),a.useEffect(()=>{if(!t)return;const S=(u==null?void 0:u.model)??"",V=S.includes("openrouter")?"openrouter":S.includes("anthropic")?"anthropic":S.includes("openai")?"openai":"auto";N(V)},[t,u==null?void 0:u.model,o]),a.useEffect(()=>{t&&(f(null),v(null),D("starter"),ne(1))},[t]),a.useEffect(()=>{x(""),d("")},[l]),a.useEffect(()=>{d("")},[m]),a.useEffect(()=>{t&&(w.trim().length>0||G&&F(`Kick off: ${G.name}`))},[w,t,G]);const I=!!o.trim()&&!!l.trim(),L=ie===1?!!o.trim():ie===2?!!l.trim():I,z=async()=>{var Se;const S=(k==null?void 0:k.checkout)??"/orgx/api/billing/checkout",V=T&&T.trim().length>0?T.trim():"starter",W=await(await fetch(S,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({planId:V,billingCycle:"monthly"})})).json().catch(()=>null),ke=((Se=W==null?void 0:W.data)==null?void 0:Se.url)??(W==null?void 0:W.url)??null;if(!ke)throw new Error((W==null?void 0:W.error)??"Checkout unavailable");window.open(ke,"_blank","noopener,noreferrer")},R=async()=>{var ke;const S=(k==null?void 0:k.portal)??"/orgx/api/billing/portal",Y=await(await fetch(S,{method:"POST"})).json().catch(()=>null),W=((ke=Y==null?void 0:Y.data)==null?void 0:ke.url)??(Y==null?void 0:Y.url)??null;if(!W)throw new Error((Y==null?void 0:Y.error)??"Billing portal unavailable");window.open(W,"_blank","noopener,noreferrer")},me=async()=>{if(!(!I||A)){f(null),v(null),ee(!0);try{const S={agentId:o.trim(),message:w.trim()?w.trim():void 0,initiativeId:l.trim(),initiativeTitle:(G==null?void 0:G.name)??null,workstreamId:m.trim()?m.trim():null,taskId:p.trim()?p.trim():null,provider:h!=="auto"?h:null},V=new URLSearchParams;V.set("agentId",S.agentId),V.set("initiativeId",S.initiativeId),S.initiativeTitle&&V.set("initiativeTitle",S.initiativeTitle),S.workstreamId&&V.set("workstreamId",S.workstreamId),S.taskId&&V.set("taskId",S.taskId),S.message&&V.set("message",S.message),S.provider&&V.set("provider",S.provider);const Y=await fetch(`/orgx/api/agents/launch?${V.toString()}`,{method:"POST"}),W=await Y.json().catch(()=>null);if(!Y.ok||!(W!=null&&W.ok))throw(W==null?void 0:W.code)==="upgrade_required"&&(v(W.actions??null),D(W.requiredPlan??"starter")),new Error((W==null?void 0:W.error)??`Launch failed (${Y.status})`);s(),r==null||r()}catch(S){f(S instanceof Error?S.message:"Launch failed")}finally{ee(!1)}}},re=!!((le=u==null?void 0:u.run)!=null&&le.runId)&&!!((Ie=u==null?void 0:u.run)!=null&&Ie.pid),X=async()=>{var S;if(!(!((S=u==null?void 0:u.run)!=null&&S.runId)||!re||A)){f(null),ee(!0);try{const V=await fetch(`/orgx/api/agents/stop?runId=${encodeURIComponent(u.run.runId)}`,{method:"POST"}),Y=await V.json().catch(()=>null);if(!V.ok||!(Y!=null&&Y.ok))throw new Error((Y==null?void 0:Y.error)??`Stop failed (${V.status})`);await n.refetch()}catch(V){f(V instanceof Error?V.message:"Stop failed")}finally{ee(!1)}}},K=async()=>{var S;if(!(!((S=u==null?void 0:u.run)!=null&&S.runId)||A)){f(null),ee(!0);try{const V=new URLSearchParams;V.set("runId",u.run.runId),w.trim()&&V.set("message",w.trim()),h&&h!=="auto"&&V.set("provider",h);const Y=await fetch(`/orgx/api/agents/restart?${V.toString()}`,{method:"POST"}),W=await Y.json().catch(()=>null);if(!Y.ok||!(W!=null&&W.ok))throw new Error((W==null?void 0:W.error)??`Restart failed (${Y.status})`);s(),r==null||r()}catch(V){f(V instanceof Error?V.message:"Restart failed")}finally{ee(!1)}}};return t?e.jsx(Ge,{open:t,onClose:s,maxWidth:"max-w-2xl",children:e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[e.jsx("div",{className:"border-b border-subtle px-5 py-4 sm:px-6",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-heading font-semibold text-white",children:"Launch OpenClaw Agent"}),e.jsx("p",{className:"mt-1 text-body text-secondary",children:"Starts a background agent turn and scopes the resulting sessions/activity to the selected OrgX initiative."}),e.jsx("div",{className:"mt-3 inline-flex items-center gap-1 rounded-full border border-strong bg-white/[0.03] p-1 text-micro uppercase tracking-[0.12em] text-secondary",children:[[1,"Agent"],[2,"Scope"],[3,"Message"]].map(([S,V])=>e.jsxs("button",{type:"button",onClick:()=>ne(S),className:we("rounded-full px-3 py-1 transition-colors",ie===S?"bg-white/[0.12] text-white":"hover:bg-white/[0.06]"),children:[S,". ",V]},S))})]}),e.jsx("button",{type:"button",onClick:s,className:"rounded-lg border border-strong bg-white/[0.03] px-3 py-1.5 text-body text-secondary hover:bg-white/[0.08] hover:text-white",children:"Close"})]})}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto px-5 py-4 sm:px-6",children:[n.isLoading&&e.jsx("div",{className:"rounded-xl border border-subtle bg-white/[0.02] p-4 text-body text-secondary",children:"Loading agent catalog…"}),n.error&&e.jsx("div",{className:"rounded-xl border border-rose-300/20 bg-rose-400/10 p-4 text-body text-rose-100",children:n.error.message}),e.jsx(qe,{mode:"wait",children:e.jsxs(ue.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,y:-8},transition:{duration:.22,ease:[.16,1,.3,1]},className:"mt-3 space-y-4",children:[ie===1&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-caption uppercase tracking-[0.1em] text-muted",children:"Agent"}),e.jsx("select",{value:o,onChange:S=>c(S.target.value),className:"mt-1 w-full rounded-xl border border-white/[0.1] bg-black/30 px-3 py-2 text-body text-primary focus:outline-none focus:ring-1 focus:ring-[#BFFF00]/30",children:E.map(S=>{const V=Dt(S.status);return e.jsxs("option",{value:S.id,children:[S.name," (",S.id,") · ",V.label]},S.id)})})]}),u&&e.jsxs("div",{className:"rounded-xl border border-subtle bg-white/[0.02] p-3 text-body text-secondary",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"font-medium text-primary",children:u.name}),e.jsx("span",{className:"rounded-full border px-2 py-0.5 text-micro uppercase tracking-[0.12em]",style:{borderColor:`${Dt(u.status).color}55`,color:Dt(u.status).color,backgroundColor:Dt(u.status).bg},children:Dt(u.status).label})]}),e.jsxs("div",{className:"mt-2 space-y-2",children:[e.jsxs("p",{className:"truncate",children:[e.jsx("span",{className:"text-muted",children:"Model:"})," ",u.model??"unknown"]}),e.jsxs("p",{className:"truncate",children:[e.jsx("span",{className:"text-muted",children:"Workspace:"})," ",u.workspace??"unknown"]}),((P=u.context)==null?void 0:P.initiativeId)&&e.jsxs("p",{className:"truncate",children:[e.jsx("span",{className:"text-muted",children:"Scoped:"})," ",u.context.initiativeTitle??u.context.initiativeId]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Provider"}),e.jsxs("select",{value:h,onChange:S=>N(S.target.value),className:"mt-1 w-full rounded-xl border border-white/[0.1] bg-black/30 px-3 py-2 text-body text-primary focus:outline-none focus:ring-1 focus:ring-[#BFFF00]/30",children:[e.jsx("option",{value:"auto",children:"Auto (keep agent model)"}),e.jsx("option",{value:"anthropic",children:"Anthropic"}),e.jsx("option",{value:"openrouter",children:"OpenRouter"}),e.jsx("option",{value:"openai",children:"OpenAI"})]}),e.jsx("p",{className:"mt-1 text-micro text-muted",children:"Selecting a provider updates the agent's default model before launch."})]}),u.run&&e.jsxs("p",{className:"truncate",children:[e.jsx("span",{className:"text-muted",children:"Tracked run:"})," ",u.run.runId.slice(0,8),"…"," ",e.jsxs("span",{className:"text-muted",children:["(",u.run.status,")"]})]}),u.run&&e.jsxs("div",{className:"grid grid-cols-2 gap-2 pt-1",children:[e.jsx("button",{type:"button",onClick:X,disabled:!re||A,className:"rounded-lg border border-rose-300/25 bg-rose-400/10 px-3 py-2 text-caption font-semibold text-rose-100 transition-colors hover:bg-rose-400/20 disabled:opacity-45",children:"Stop Run"}),e.jsx("button",{type:"button",onClick:K,disabled:A,className:"rounded-lg border border-strong bg-white/[0.03] px-3 py-2 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:"Restart"})]})]})]})]}),ie===2&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-caption uppercase tracking-[0.1em] text-muted",children:"Initiative Scope"}),e.jsxs("select",{value:l,onChange:S=>y(S.target.value),className:"mt-1 w-full rounded-xl border border-white/[0.1] bg-black/30 px-3 py-2 text-body text-primary focus:outline-none focus:ring-1 focus:ring-[#BFFF00]/30",children:[e.jsx("option",{value:"",children:"Select an initiative…"}),(i??[]).map(S=>e.jsx("option",{value:S.id,children:S.name},S.id))]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Workstream (optional)"}),e.jsxs("select",{value:m,onChange:S=>x(S.target.value),disabled:!G,className:we("mt-1 w-full rounded-xl border border-white/[0.1] bg-black/30 px-3 py-2 text-body text-primary focus:outline-none focus:ring-1 focus:ring-[#BFFF00]/30",!G&&"opacity-50"),children:[e.jsx("option",{value:"",children:"Any workstream"}),pe.map(S=>e.jsx("option",{value:S.id,children:S.name},S.id))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Task (optional)"}),e.jsxs("select",{value:p,onChange:S=>d(S.target.value),disabled:!G,className:we("mt-1 w-full rounded-xl border border-white/[0.1] bg-black/30 px-3 py-2 text-body text-primary focus:outline-none focus:ring-1 focus:ring-[#BFFF00]/30",!G&&"opacity-50"),children:[e.jsx("option",{value:"",children:"Any task"}),j.slice(0,80).map(S=>e.jsx("option",{value:S.id,children:S.title},S.id))]}),j.length>80&&e.jsx("p",{className:"mt-1 text-micro text-muted",children:"Showing first 80 tasks to keep the menu usable."})]})]})]}),ie===3&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-caption uppercase tracking-[0.1em] text-muted",children:"Kickoff Message"}),e.jsx("textarea",{value:w,onChange:S=>F(S.target.value),rows:4,className:"mt-1 w-full resize-none rounded-xl border border-white/[0.1] bg-black/30 px-3 py-2 text-body text-primary focus:outline-none focus:ring-1 focus:ring-[#BFFF00]/30",placeholder:"Optional. If left blank, a default kickoff message is used."})]}),e.jsxs("div",{className:"rounded-xl border border-subtle bg-white/[0.02] p-3 text-body text-secondary",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Review"}),e.jsxs("div",{className:"mt-2 grid grid-cols-1 gap-2 sm:grid-cols-2",children:[e.jsxs("div",{className:"rounded-lg border border-white/[0.08] bg-black/20 px-3 py-2",children:[e.jsx("div",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Agent"}),e.jsx("div",{className:"mt-0.5 truncate text-body text-primary",children:((u==null?void 0:u.name)??o.trim())||"—"})]}),e.jsxs("div",{className:"rounded-lg border border-white/[0.08] bg-black/20 px-3 py-2",children:[e.jsx("div",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Initiative"}),e.jsx("div",{className:"mt-0.5 truncate text-body text-primary",children:((G==null?void 0:G.name)??l.trim())||"—"})]}),e.jsxs("div",{className:"rounded-lg border border-white/[0.08] bg-black/20 px-3 py-2",children:[e.jsx("div",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Workstream"}),e.jsx("div",{className:"mt-0.5 truncate text-body text-primary",children:m.trim()?((ce=pe.find(S=>S.id===m))==null?void 0:ce.name)??m:"Any"})]}),e.jsxs("div",{className:"rounded-lg border border-white/[0.08] bg-black/20 px-3 py-2",children:[e.jsx("div",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Task"}),e.jsx("div",{className:"mt-0.5 truncate text-body text-primary",children:p.trim()?(($=j.find(S=>S.id===p))==null?void 0:$.title)??p:"Any"})]})]})]})]})]},ie)}),g&&e.jsx("div",{className:"mt-3 rounded-xl border border-rose-300/20 bg-rose-400/10 px-3 py-2 text-body text-rose-100",children:e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("div",{children:g}),k&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>void z().catch(S=>f(S instanceof Error?S.message:"Checkout failed")),className:"rounded-full border border-amber-200/25 bg-amber-200/10 px-3 py-1.5 text-caption font-semibold text-amber-100 transition-colors hover:bg-amber-200/15",children:"Upgrade"}),e.jsx("button",{type:"button",onClick:()=>void R().catch(S=>f(S instanceof Error?S.message:"Portal failed")),className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.08]",children:"Billing portal"}),k.pricing&&e.jsx("a",{href:k.pricing,target:"_blank",rel:"noopener noreferrer",className:"text-caption text-secondary underline decoration-white/20 hover:text-primary",children:"View pricing"})]})]})})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 border-t border-subtle px-5 py-3.5 sm:px-6",children:[e.jsx("div",{className:"text-caption text-secondary",children:ie===1?"Pick an agent to configure.":ie===2?"Select an initiative scope (required).":I?"Launch will update sessions/activity under the selected initiative.":"Select an agent and initiative to launch."}),e.jsxs("div",{className:"flex items-center gap-2",children:[ie>1&&e.jsx("button",{type:"button",onClick:()=>ne(S=>S>1?S-1:S),disabled:A,className:"rounded-xl border border-strong bg-white/[0.03] px-4 py-2 text-body font-semibold text-primary transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:"Back"}),ie<3?e.jsx("button",{type:"button",onClick:()=>ne(S=>S<3?S+1:S),disabled:!L||A,className:we("rounded-xl px-4 py-2 text-body font-semibold transition-colors",L&&!A?"text-black":"cursor-not-allowed border border-strong bg-white/[0.05] text-muted"),style:L&&!A?{backgroundColor:C.lime}:void 0,children:"Next"}):e.jsx("button",{type:"button",onClick:me,disabled:!I||A,className:we("rounded-xl px-4 py-2 text-body font-semibold transition-colors",I&&!A?"text-black":"cursor-not-allowed border border-strong bg-white/[0.05] text-muted"),style:I&&!A?{backgroundColor:C.lime}:void 0,children:A?"Launching…":"Launch"})]})]})]})}):null}const js=10,$i=20;function Ti(t){const s=(t??"").toLowerCase();return s==="active"?{label:"Active",color:C.lime,bg:"rgba(191,255,0,0.12)"}:s==="blocked"?{label:"Blocked",color:"#fb7185",bg:"rgba(244, 63, 94, 0.12)"}:s==="idle"?{label:"Idle",color:"rgba(255,255,255,0.55)",bg:"rgba(255,255,255,0.06)"}:{label:t||"Unknown",color:C.iris,bg:"rgba(124,124,255,0.10)"}}function Li(t){return t?t.includes("error")||t.includes("fail")?C.red:t.includes("decision")||t.includes("block")?C.amber:t.includes("complete")||t.includes("success")?C.teal:t.includes("start")||t.includes("launch")?C.lime:C.iris:C.iris}function Pi({open:t,onClose:s,agentName:r,catalogAgent:n,sessions:i,activity:o,onSelectSession:c,onRefresh:l}){var ee,ie,ne,G,te,pe;const[y,m]=a.useState(!1),[x,p]=a.useState(!1),[d,h]=a.useState(null),N=Ls(r),w=Ti((n==null?void 0:n.status)??null),F=a.useMemo(()=>{let j=0,E=0,u=0,I=0;for(const L of i)L.status==="running"||L.status==="queued"||L.status==="pending"?j++:L.status==="blocked"?E++:L.status==="failed"||L.status==="cancelled"?u++:(L.status==="completed"||L.status==="archived")&&I++;return{running:j,blocked:E,failed:u,completed:I}},[i]),g=a.useMemo(()=>[...i].sort((j,E)=>Date.parse(E.updatedAt??E.lastEventAt??E.startedAt??"")-Date.parse(j.updatedAt??j.lastEventAt??j.startedAt??"")),[i]),f=y?g:g.slice(0,js),k=g.length>js,v=a.useMemo(()=>[...o].sort((j,E)=>Date.parse(E.timestamp)-Date.parse(j.timestamp)).slice(0,$i),[o]),T=!!((ee=n==null?void 0:n.run)!=null&&ee.runId)&&!!((ie=n==null?void 0:n.run)!=null&&ie.pid),D=async()=>{var j;if(!(!((j=n==null?void 0:n.run)!=null&&j.runId)||!T||x)){h(null),p(!0);try{const E=await fetch(`/orgx/api/agents/stop?runId=${encodeURIComponent(n.run.runId)}`,{method:"POST"}),u=await E.json().catch(()=>null);if(!E.ok||!(u!=null&&u.ok))throw new Error((u==null?void 0:u.error)??`Stop failed (${E.status})`);l==null||l()}catch(E){h(E instanceof Error?E.message:"Stop failed")}finally{p(!1)}}},A=async()=>{var j;if(!(!((j=n==null?void 0:n.run)!=null&&j.runId)||x)){h(null),p(!0);try{const E=new URLSearchParams;E.set("runId",n.run.runId);const u=await fetch(`/orgx/api/agents/restart?${E.toString()}`,{method:"POST"}),I=await u.json().catch(()=>null);if(!u.ok||!(I!=null&&I.ok))throw new Error((I==null?void 0:I.error)??`Restart failed (${u.status})`);l==null||l()}catch(E){h(E instanceof Error?E.message:"Restart failed")}finally{p(!1)}}};return t?e.jsx(Ge,{open:t,onClose:s,maxWidth:"max-w-3xl",children:e.jsxs("div",{className:"flex h-full min-h-0 w-full flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-subtle px-5 py-3 sm:px-6",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0 text-body text-secondary",children:[e.jsx("span",{children:"Agents"}),e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:"flex-shrink-0 text-faint",children:e.jsx("path",{d:"m9 18 6-6-6-6"})}),e.jsx("span",{className:"truncate text-primary font-medium",children:r}),e.jsx("span",{className:"ml-1 rounded-full border border-white/[0.1] bg-white/[0.04] px-2 py-0.5 text-micro uppercase tracking-[0.06em] text-muted",children:"agent"})]}),e.jsx("button",{type:"button",onClick:s,"aria-label":"Close detail",className:"inline-flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-full border border-strong bg-white/[0.03] text-primary transition-colors hover:bg-white/[0.08] hover:text-white",children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 6L6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})})]}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto px-5 py-4 sm:px-6 space-y-5",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(nt,{name:r,size:"md",hint:r}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"text-heading font-semibold text-white truncate",children:r}),e.jsx("span",{className:"rounded-full border px-2 py-0.5 text-micro uppercase tracking-[0.12em]",style:{borderColor:`${w.color}55`,color:w.color,backgroundColor:w.bg},children:w.label})]}),N&&e.jsx("p",{className:"text-body text-secondary mt-0.5",children:N}),n&&e.jsxs("div",{className:"flex flex-wrap items-center gap-3 mt-1 text-caption text-muted",children:[n.model&&e.jsxs("span",{children:[e.jsx("span",{className:"text-muted",children:"Model:"})," ",n.model]}),n.workspace&&e.jsxs("span",{children:[e.jsx("span",{className:"text-muted",children:"Workspace:"})," ",n.workspace]})]})]})]}),e.jsx("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-4",children:[{label:"Running",value:F.running,color:C.lime},{label:"Blocked",value:F.blocked,color:C.red},{label:"Failed",value:F.failed,color:C.amber},{label:"Completed",value:F.completed,color:C.teal}].map(j=>e.jsxs("div",{className:"rounded-xl border border-subtle bg-white/[0.02] px-3 py-2.5",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.1em] text-muted",children:j.label}),e.jsx("p",{className:"mt-0.5 text-title font-semibold",style:{color:j.value>0?j.color:"rgba(255,255,255,0.3)",fontVariantNumeric:"tabular-nums"},children:j.value})]},j.label))}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-micro uppercase tracking-[0.1em] text-muted mb-2",children:["Sessions (",i.length,")"]}),i.length===0?e.jsx("div",{className:"rounded-xl border border-subtle bg-white/[0.02] px-3 py-4 text-center text-body text-muted",children:"No sessions recorded for this agent."}):e.jsxs("div",{className:"space-y-1.5",children:[f.map(j=>e.jsxs("button",{onClick:()=>{c(j.id),s()},className:"w-full rounded-lg border border-subtle bg-white/[0.02] px-3 py-2 text-left transition-colors hover:bg-white/[0.05]",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"h-2 w-2 flex-shrink-0 rounded-full",style:{backgroundColor:Et(j.status)}}),e.jsx("p",{className:"min-w-0 flex-1 truncate text-body text-primary",children:j.title}),e.jsx("span",{className:"text-micro text-muted",style:{fontVariantNumeric:"tabular-nums"},title:jt(j.updatedAt??j.lastEventAt??j.startedAt??Date.now()),children:Ce(j.updatedAt??j.lastEventAt??j.startedAt??Date.now())})]}),e.jsxs("div",{className:"mt-1 flex items-center gap-2 text-micro text-muted",children:[e.jsx("span",{className:"uppercase tracking-[0.08em]",children:j.status}),j.progress!==null&&e.jsxs("span",{children:[Math.round(j.progress),"%"]})]})]},j.id)),k&&e.jsx("button",{type:"button",onClick:()=>m(j=>!j),className:"w-full rounded-lg border border-white/[0.08] bg-white/[0.02] px-3 py-1.5 text-micro text-secondary transition-colors hover:bg-white/[0.05]",children:y?"Show fewer":`Show ${g.length-js} more`})]})]}),v.length>0&&e.jsxs("div",{children:[e.jsxs("p",{className:"text-micro uppercase tracking-[0.1em] text-muted mb-2",children:["Recent Activity (",v.length,")"]}),e.jsx("div",{className:"space-y-1",children:v.map((j,E)=>e.jsxs("div",{className:"flex items-start gap-2 rounded-lg px-2 py-1.5 text-caption",children:[e.jsx("span",{className:"mt-1.5 h-1.5 w-1.5 flex-shrink-0 rounded-full",style:{backgroundColor:Li(j.type)}}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx("p",{className:"truncate text-primary",children:j.title??j.summary??j.description??"Activity"})}),e.jsx("span",{className:"flex-shrink-0 text-micro text-muted",style:{fontVariantNumeric:"tabular-nums"},title:jt(j.timestamp),children:Ce(j.timestamp)})]},j.id??E))})]}),(n==null?void 0:n.run)&&e.jsxs("div",{children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.1em] text-muted mb-2",children:"Controls"}),e.jsxs("div",{className:"rounded-xl border border-subtle bg-white/[0.02] p-3",children:[e.jsxs("p",{className:"text-caption text-secondary mb-2",children:[e.jsx("span",{className:"text-muted",children:"Tracked run:"})," ",n.run.runId.slice(0,8),"…"," ",e.jsxs("span",{className:"text-muted",children:["(",n.run.status,")"]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("button",{type:"button",onClick:D,disabled:!T||x,className:"rounded-lg border border-rose-300/25 bg-rose-400/10 px-3 py-2 text-caption font-semibold text-rose-100 transition-colors hover:bg-rose-400/20 disabled:opacity-45",children:x?"Stopping…":"Stop Run"}),e.jsx("button",{type:"button",onClick:A,disabled:x,className:"rounded-lg border border-strong bg-white/[0.03] px-3 py-2 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:x?"Restarting…":"Restart"})]}),d&&e.jsx("p",{className:"mt-2 text-caption text-rose-200",children:d})]})]}),n&&e.jsxs("div",{children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.1em] text-muted mb-2",children:"Settings"}),e.jsxs("div",{className:"rounded-xl border border-subtle bg-white/[0.02] p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between text-body",children:[e.jsx("span",{className:"text-muted",children:"Provider"}),e.jsx("span",{className:"text-primary",children:(ne=n.model)!=null&&ne.includes("openrouter")?"OpenRouter":(G=n.model)!=null&&G.includes("anthropic")?"Anthropic":(te=n.model)!=null&&te.includes("openai")?"OpenAI":"Auto"})]}),e.jsxs("div",{className:"flex items-center justify-between text-body",children:[e.jsx("span",{className:"text-muted",children:"Model"}),e.jsx("span",{className:we("truncate max-w-[200px] text-right",n.model?"text-primary":"text-muted"),children:n.model??"Not configured"})]}),n.workspace&&e.jsxs("div",{className:"flex items-center justify-between text-body",children:[e.jsx("span",{className:"text-muted",children:"Workspace"}),e.jsx("span",{className:"truncate max-w-[200px] text-right text-primary",children:n.workspace})]}),((pe=n.context)==null?void 0:pe.initiativeTitle)&&e.jsxs("div",{className:"flex items-center justify-between text-body",children:[e.jsx("span",{className:"text-muted",children:"Initiative"}),e.jsx("span",{className:"truncate max-w-[200px] text-right text-primary",children:n.context.initiativeTitle})]})]})]})]})]})}):null}function Di({enabled:t=!0}={}){return it({queryKey:["openclaw-agent-catalog"],queryFn:async()=>{const s=await fetch("/orgx/api/agents/catalog");if(!s.ok){const r=await s.text().catch(()=>"");throw new Error(r||`Agent catalog failed (${s.status})`)}return await s.json()},enabled:t,staleTime:5e3,refetchInterval:t?8e3:!1})}const Qt=120,Bi=10,qn=new Set(["running","active","queued","pending","in_progress","working","planning"]),Oi=new Set(["blocked","failed"]),Ri=10,qi=[{id:"orchestrator",name:"Orchestrator",role:"Coordinates cross-team execution"},{id:"engineering",name:"Engineering",role:"Builds and ships technical work"},{id:"product",name:"Product",role:"Defines features and requirements"},{id:"marketing",name:"Marketing",role:"Drives campaigns and content"},{id:"design",name:"Design",role:"Creates interfaces and experiences"},{id:"operations",name:"Operations",role:"Manages reliability and processes"}];function Te(t){const s=t==null?void 0:t.trim().toLowerCase();return s&&s.length>0?s:null}function zi(t){const s=Te(t.agentId);if(s)return`id:${s}`;const r=Te(t.agentName);return r?`name:${r}`:"unassigned"}function Ps(t){const s=Te(t);return s?qn.has(s)||Oi.has(s):!1}function cn(t){const s=Te(t);return s?qn.has(s):!1}function Xt(t){return t?!!(Ps(t.status)||t.runId&&t.runId.trim().length>0||t.currentTask&&t.currentTask.trim().length>0):!1}function Ui(t){return t?t.state==="active":!1}function zn(t){return t==="codex"?"codex":t==="openai"?"openai":t==="anthropic"?"anthropic":t==="openclaw"?"openclaw":t==="orgx"?"orgx":"unknown"}function Wi(t){return zn((t==null?void 0:t.providerLogo)??null)}function Xe(t){if(!t)return 0;const s=Date.parse(t);return Number.isFinite(s)?s:0}function ks(t,s){return Xe(s.updatedAt??s.lastEventAt??s.startedAt)-Xe(t.updatedAt??t.lastEventAt??t.startedAt)}const Ki=a.memo(function({sessions:s,activity:r,selectedSessionId:n,onSelectSession:i,timeFilterId:o,onTimeFilterChange:c,onAgentFilter:l,agentFilter:y,onReconnect:m,connectionStatus:x,runtimeInstances:p=[]}){var Ie;const[d,h]=a.useState(new Set),[N,w]=a.useState(!1),[F,g]=a.useState(!1),[f,k]=a.useState(0),[v,T]=a.useState(null),D=Di({enabled:!0}),A=((Ie=D.data)==null?void 0:Ie.agents)??[],ee=a.useMemo(()=>Bs(o),[o]),ie=a.useMemo(()=>ee===null?r:r.filter(P=>Xe(P.timestamp)>=ee),[r,ee]);a.useMemo(()=>{var $,S,V;const P=new Map,ce=[...ie].sort((Y,W)=>Xe(W.timestamp)-Xe(Y.timestamp));for(const Y of ce){const W=Y.runId;if(!W||P.has(W))continue;const ke=(($=Y.summary)==null?void 0:$.trim())??((S=Y.description)==null?void 0:S.trim())??((V=Y.title)==null?void 0:V.trim())??"";ke.length>0&&P.set(W,ke)}return P},[ie]);const{agents:ne,hiddenGroupCount:G,filteredOutGroupsByDate:te,filteredOutSessionsByDate:pe,visibleSessionCount:j,archivedGroups:E}=a.useMemo(()=>{var Ze;const P=new Map,ce=new Map,$=[...p].sort((q,H)=>Xe(H.lastEventAt??H.lastHeartbeatAt)-Xe(q.lastEventAt??q.lastHeartbeatAt));for(const q of $){q.runId&&!P.has(q.runId)&&P.set(q.runId,q);const H=Te(q.agentId);if(H){const he=ce.get(H)??[];he.push(q),ce.set(H,he)}}const S=new Map;for(const q of s.nodes){const H=zi(q),he=Te(q.agentId),ge=Te(q.agentName);let se=S.get(H)??null;if(!se&&he&&ge){const xe=`name:${ge}`,ae=S.get(xe);ae&&(S.delete(xe),ae.groupKey=H,S.set(H,ae),se=ae)}if(!se&&ge){const xe=Array.from(S.values()).find(ae=>Te(ae.agentName)===ge);xe&&(se=xe)}se?(se.nodes.push(q),!se.agentId&&q.agentId&&(se.agentId=q.agentId),(se.agentName==="Unassigned"||!se.agentName)&&q.agentName&&(se.agentName=q.agentName)):S.set(H,{groupKey:H,agentId:q.agentId,agentName:q.agentName??q.agentId??"Unassigned",nodes:[q],latest:q,runtime:null,runtimeActiveCount:0})}for(const q of A){const H=Te(q.id),he=Te(q.name),ge=H?`id:${H}`:null,se=he?`name:${he}`:null;let xe=null;if(ge&&S.has(ge))xe=ge;else if(se&&S.has(se))xe=se;else{const ae=Array.from(S.entries()).find(([,De])=>H&&Te(De.agentId)===H||he&&Te(De.agentName)===he);xe=(ae==null?void 0:ae[0])??null}if(xe){const ae=S.get(xe);ae.catalogAgent=q,!ae.agentId&&q.id&&(ae.agentId=q.id),(ae.agentName==="Unassigned"||!ae.agentName)&&q.name&&(ae.agentName=q.name),ge&&ae.groupKey!==ge&&!S.has(ge)&&(S.delete(ae.groupKey),ae.groupKey=ge,S.set(ge,ae))}else{const ae=ge??se??`catalog:${q.name.toLowerCase()}`;S.set(ae,{groupKey:ae,agentId:q.id,agentName:q.name,nodes:[],latest:null,catalogAgent:q,runtime:null,runtimeActiveCount:0})}}for(const q of S.values()){q.nodes.length>0&&(q.nodes.sort(ks),q.latest=q.nodes[0]);const H=[],he=new Set;if((Ze=q.latest)!=null&&Ze.runId){const se=P.get(q.latest.runId);se&&!he.has(se.id)&&(H.push(se),he.add(se.id))}for(const se of q.nodes){if(!se.runId)continue;const xe=P.get(se.runId);xe&&!he.has(xe.id)&&(H.push(xe),he.add(xe.id))}const ge=Te(q.agentId);if(ge)for(const se of ce.get(ge)??[])he.has(se.id)||(H.push(se),he.add(se.id));H.sort((se,xe)=>Xe(xe.lastEventAt??xe.lastHeartbeatAt)-Xe(se.lastEventAt??se.lastHeartbeatAt)),q.runtime=H[0]??null,q.runtimeActiveCount=H.filter(se=>Ui(se)).length}const V=Array.from(S.values()).sort((q,H)=>q.latest&&H.latest?ks(q.latest,H.latest):q.latest&&!H.latest?-1:!q.latest&&H.latest?1:q.agentName.localeCompare(H.agentName)),Y=$n(o),W=Y.id==="live",ke=Y.minutes===null||W?null:Date.now()-Y.minutes*6e4,Se=[],ye=[];let Ye=0,Me=0;for(const q of V){const H=(q.runtimeActiveCount??0)>0;if(q.nodes.length===0){const xe=Xt(q.catalogAgent);(!W||xe||H)&&Se.push(q);continue}if(W){const xe=q.nodes.filter(ze=>Ps(ze.status)),ae=q.nodes.filter(ze=>!Ps(ze.status)),De=Xt(q.catalogAgent);if(xe.length===0){De||H?Se.push({...q,nodes:[],latest:null}):(Ye+=1,Me+=q.nodes.length,ye.push(q));continue}Me+=ae.length,ae.length>0&&ye.push({...q,nodes:ae,latest:ae[0]??null}),Se.push({...q,nodes:xe,latest:xe[0]??null});continue}if(ke===null){Se.push(q);continue}const he=q.nodes.filter(xe=>cn(xe.status)?!0:Xe(xe.updatedAt??xe.lastEventAt??xe.startedAt)>=ke),ge=Xt(q.catalogAgent);if(he.length===0){ge||H?Se.push({...q,nodes:[],latest:null}):(Ye+=1,Me+=q.nodes.length,ye.push(q));continue}const se=q.nodes.filter(xe=>cn(xe.status)?!1:Xe(xe.updatedAt??xe.lastEventAt??xe.startedAt)<ke);Me+=se.length,se.length>0&&ye.push({...q,nodes:se,latest:se[0]}),Se.push({...q,nodes:he,latest:he[0]})}return{agents:Se.slice(0,Qt),hiddenGroupCount:Math.max(0,Se.length-Qt),filteredOutGroupsByDate:Ye,filteredOutSessionsByDate:Me,visibleSessionCount:Se.slice(0,Qt).reduce((q,H)=>q+H.nodes.length,0),archivedGroups:ye}},[o,s.nodes,A,p]);a.useEffect(()=>{g(!1),k(0)},[o]);const u=a.useMemo(()=>E.reduce((P,ce)=>P+ce.nodes.length,0),[E]),I=a.useMemo(()=>ne.filter(P=>P.nodes.length>0).map(P=>P.groupKey),[ne]),L=a.useMemo(()=>{if(I.length===0)return{allCollapsed:!1,allExpanded:!0};let P=0;for(const ce of I)d.has(ce)&&(P+=1);return{allCollapsed:P===I.length,allExpanded:P===0}},[d,I]),z=a.useMemo(()=>{const P=[];for(const ce of E)for(const $ of ce.nodes)P.push({node:$,agentName:ce.agentName});return P.sort((ce,$)=>ks(ce.node,$.node)),P.slice(0,(f+1)*Ri)},[E,f]),R=P=>{h(ce=>{const $=new Set(ce);return $.has(P)?$.delete(P):$.add(P),$})},me=()=>{h(()=>L.allCollapsed?new Set:new Set(I))},re=a.useMemo(()=>v?ne.find(P=>P.groupKey===v)??null:null,[ne,v]),X=a.useMemo(()=>(re==null?void 0:re.nodes)??[],[re]),K=a.useMemo(()=>{if(!re)return[];const P=Te(re.agentName),ce=Te(re.agentId);return ie.filter($=>{const S=Te($.agentName),V=Te($.agentId);return P!==null&&S===P||ce!==null&&V===ce})},[ie,re]),Ae=s.nodes.length===0,le=A.length>0;return e.jsxs(vt,{className:"flex h-full min-h-0 flex-col card-enter",children:[e.jsx(_i,{open:N,onClose:()=>w(!1),onLaunched:()=>m==null?void 0:m()}),e.jsx(Pi,{open:v!==null,onClose:()=>T(null),agentName:(re==null?void 0:re.agentName)??"",catalogAgent:(re==null?void 0:re.catalogAgent)??null,sessions:X,activity:K,onSelectSession:i,onRefresh:()=>D.refetch()}),e.jsxs("div",{className:"border-b border-subtle px-4 py-3.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("h2",{className:"min-w-0 truncate text-heading font-semibold text-white",children:"Agents"}),e.jsxs("span",{className:"chip flex-shrink-0 text-caption tabular-nums",children:[j,"/",s.nodes.length]})]}),e.jsxs("div",{className:"flex flex-shrink-0 items-center gap-2",children:[e.jsx("button",{type:"button",onClick:me,disabled:I.length===0,className:"control-pill hidden flex-shrink-0 px-3 text-caption font-semibold sm:inline-flex",title:L.allCollapsed?"Expand all agent groups":"Collapse all agent groups",children:L.allCollapsed?"Expand":"Collapse"}),e.jsx("button",{type:"button",onClick:()=>w(!0),className:"control-pill flex-shrink-0 px-3 text-caption font-semibold",children:"Launch"})]})]}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"text-caption text-secondary",children:"History"}),e.jsx("div",{className:"hidden items-center gap-1 rounded-full border border-white/[0.08] bg-black/30 p-0.5 sm:inline-flex",role:"group","aria-label":"Session history filter",children:Ot.map(P=>{const ce=o===P.id;return e.jsx("button",{type:"button",onClick:()=>c(P.id),"aria-pressed":ce,className:we("rounded-full px-2.5 py-1 text-micro font-semibold tracking-[-0.01em] transition-colors",ce?"border border-lime/25 bg-lime/[0.12] text-lime":"border border-transparent text-secondary hover:bg-white/[0.06] hover:text-primary"),children:P.label},P.id)})}),e.jsx("label",{htmlFor:"offline-date-filter",className:"sr-only",children:"Session history filter"}),e.jsx("select",{id:"offline-date-filter",value:o,onChange:P=>c(P.target.value),className:"rounded-lg border border-white/[0.1] bg-black/30 px-2 py-1 text-caption text-primary focus:outline-none focus:ring-1 focus:ring-[#BFFF00]/30 sm:hidden",children:Ot.map(P=>e.jsx("option",{value:P.id,children:P.label},P.id))})]})]}),e.jsxs("div",{className:"flex-1 space-y-2 overflow-y-auto p-3",children:[ne.length===0&&!Ae&&e.jsxs("div",{className:"flex flex-col items-center gap-2.5 rounded-xl border border-subtle bg-white/[0.02] px-3 py-6 text-center",children:[e.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-faint",children:e.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})}),e.jsx("p",{className:"text-body text-secondary",children:"No sessions match the selected history filter."})]}),ne.length===0&&Ae&&!m&&e.jsxs("div",{className:"flex flex-col items-center gap-2.5 rounded-xl border border-subtle bg-white/[0.02] px-3 py-6 text-center",children:[e.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-faint",children:e.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})}),e.jsx("p",{className:"text-body text-secondary",children:"No active chats yet. Start a session to see agents here."})]}),y&&l&&e.jsxs("div",{className:"flex items-center justify-between rounded-lg bg-[#0AD4C4]/[0.08] px-3 py-1.5 text-caption text-[#0AD4C4]",children:[e.jsxs("span",{children:["Filtered: ",y]}),e.jsx("button",{type:"button",onClick:()=>l(null),className:"text-micro underline underline-offset-2",children:"Clear"})]}),ne.map(P=>{var q;const ce=P.groupKey,$=d.has(ce),S=P.latest,V=P.nodes.length>0,Y=Xt(P.catalogAgent),W=P.runtime??null,ke=(P.runtimeActiveCount??0)>0,Se=S?n===S.id:!1,ye=P.agentName||((q=P.catalogAgent)==null?void 0:q.name)||P.agentId||"Unassigned",Ye=$?[]:P.nodes.slice(0,Bi),Me=Math.max(0,P.nodes.length-Ye.length),Ze=Te(y)===Te(ye);return e.jsxs(ue.div,{layout:!0,transition:{type:"spring",stiffness:260,damping:30,mass:.75},className:we("overflow-hidden rounded-xl border border-subtle bg-white/[0.02] transition-all",Se&&"border-white/20 bg-white/[0.05]",Ze&&"border-[#0AD4C4]/30",!V&&!Y&&!ke&&"opacity-55"),children:[e.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-2.5",children:[e.jsxs("button",{type:"button",onClick:()=>{l?l(Ze?null:ye):S&&i(S.id)},className:"flex flex-1 items-center gap-2.5 text-left transition-colors hover:opacity-80",children:[e.jsxs("div",{className:"relative flex-shrink-0",children:[e.jsx(nt,{name:ye,size:"sm",hint:ye}),S&&e.jsx("span",{className:"absolute -bottom-0.5 -right-0.5 h-2.5 w-2.5 rounded-full border-2",style:{backgroundColor:Et(S.status),borderColor:C.cardBg}}),!S&&e.jsx("span",{className:"absolute -bottom-0.5 -right-0.5 h-2.5 w-2.5 rounded-full border-2",style:{backgroundColor:Y?Et("running"):"rgba(255,255,255,0.2)",borderColor:C.cardBg}})]}),e.jsxs("span",{className:"min-w-0 truncate",children:[e.jsx("span",{className:"text-body font-semibold text-white",children:ye}),Ls(ye)&&e.jsxs("span",{className:"ml-1 text-caption text-muted",children:["— ",Ls(ye)]})]}),W&&e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full border border-strong bg-white/[0.04] px-1.5 py-0.5 text-micro uppercase tracking-[0.08em] text-primary",title:W.currentTask?`${W.displayName}: ${W.currentTask}`:W.lastMessage??W.displayName,children:[e.jsx(vs,{provider:Wi(W),size:"xs",showRing:!1,className:"h-4 w-4"}),e.jsx("span",{children:W.displayName}),W.progressPct!==null&&e.jsxs("span",{style:{fontVariantNumeric:"tabular-nums"},children:[Math.round(W.progressPct),"%"]}),ke&&e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-lime status-breathe"})]}),V?e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{className:"flex h-1.5 w-12 overflow-hidden rounded-full",children:(()=>{const H={};for(const ge of P.nodes)H[ge.status]=(H[ge.status]??0)+1;const he=P.nodes.length;return Object.entries(H).map(([ge,se])=>e.jsx("span",{style:{width:`${se/he*100}%`,backgroundColor:Et(ge)}},ge))})()}),e.jsx("span",{className:"text-micro text-secondary",style:{fontVariantNumeric:"tabular-nums"},children:P.nodes.length})]}):Y||ke?e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{className:"flex h-1.5 w-12 overflow-hidden rounded-full bg-white/[0.06]",children:e.jsx("span",{className:"h-1.5 w-full",style:{backgroundColor:Et("running")}})}),e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-lime/80",children:"live"})]}):e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{className:"flex h-1.5 w-12 overflow-hidden rounded-full bg-white/[0.06]"}),e.jsx("span",{className:"text-micro text-muted",style:{fontVariantNumeric:"tabular-nums"},children:"0"})]})]}),e.jsx("button",{type:"button",onClick:()=>T(ce),"aria-label":`View ${ye} details`,className:"flex h-7 w-7 items-center justify-center rounded-md text-muted transition-colors hover:bg-white/[0.05] hover:text-primary",children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("path",{d:"M12 16v-4"}),e.jsx("path",{d:"M12 8h.01"})]})}),V&&e.jsx("button",{type:"button",onClick:()=>R(ce),"aria-label":$?"Expand sessions":"Collapse sessions",className:"flex h-7 w-7 items-center justify-center rounded-md text-muted transition-colors hover:bg-white/[0.05] hover:text-primary",children:e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:we("transition-transform",$?"-rotate-90":"rotate-0"),children:e.jsx("path",{d:"m6 9 6 6 6-6"})})})]}),e.jsx(qe,{initial:!1,children:V&&!$&&e.jsx(ue.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.2,ease:[.22,1,.36,1]},className:"overflow-hidden border-t border-subtle",children:e.jsxs("div",{className:"max-h-[500px] space-y-1.5 overflow-y-auto p-2",children:[Ye.map((H,he)=>{const ge=n===H.id,se=ln(H.agentName,H.title,H.lastEventSummary,H);return e.jsx(ue.button,{onClick:()=>i(H.id),initial:{opacity:0,y:4},animate:{opacity:1,y:0},transition:{duration:.16,delay:Math.min(he*.015,.12)},className:we("w-full rounded-lg px-2.5 py-2 text-left transition-colors",ge?"bg-white/[0.09]":"bg-white/[0.02] hover:bg-white/[0.05]"),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(vs,{provider:se.id,size:"xs"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-body text-bright",children:H.title}),e.jsxs("div",{className:"flex items-center gap-1.5 text-micro text-secondary",children:[e.jsx("span",{className:"rounded-full border px-1.5 py-0.5 uppercase tracking-[0.08em]",style:{borderColor:`${se.accent}66`,color:se.accent,backgroundColor:se.tint},children:se.label}),e.jsx("span",{className:"uppercase tracking-[0.08em]",children:H.status}),e.jsx("span",{title:jt(H.updatedAt??H.lastEventAt??H.startedAt??Date.now()),children:Ce(H.updatedAt??H.lastEventAt??H.startedAt??Date.now())})]}),H.progress!==null&&e.jsx("div",{className:"mt-1 h-0.5 rounded-full bg-white/[0.08]",children:e.jsx("div",{className:"h-0.5 rounded-full",style:{width:`${Math.round(H.progress)}%`,background:`linear-gradient(90deg, ${C.lime}, ${C.teal})`}})})]}),e.jsx("span",{className:"h-2 w-2 flex-shrink-0 rounded-full",style:{backgroundColor:Et(H.status)},"aria-label":H.status,title:H.status})]})},H.id)}),Me>0&&e.jsxs("p",{className:"px-1 text-micro text-muted",children:["+",Me," older sessions hidden"]})]})})})]},ce)}),G>0&&e.jsxs("div",{className:"rounded-xl border border-subtle bg-white/[0.02] px-3 py-2 text-caption text-secondary",children:["Showing ",Qt," most recent agent groups (",G," older groups omitted)."]}),m&&x!=="connected"&&!le&&e.jsxs("div",{className:"rounded-xl border border-subtle bg-white/[0.02] text-caption text-secondary",children:[e.jsx("p",{className:"px-3 pt-2 pb-1.5 text-micro uppercase tracking-[0.1em] text-muted",children:"OrgX Agent Roster"}),e.jsx("div",{className:"space-y-1 px-2 pb-2",children:qi.map(P=>e.jsxs("div",{className:"flex items-center gap-2.5 rounded-lg px-2 py-1.5 opacity-55",children:[e.jsx("div",{className:"flex h-6 w-6 flex-shrink-0 items-center justify-center rounded-md border border-white/[0.08] bg-white/[0.03]",children:e.jsx("span",{className:"text-micro font-semibold text-secondary",children:P.name.charAt(0)})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-caption font-medium text-secondary",children:P.name}),e.jsx("p",{className:"text-micro text-muted",children:P.role})]}),e.jsx("button",{onClick:m,className:"rounded-md border border-lime/25 bg-lime/10 px-2 py-0.5 text-micro font-semibold text-lime transition-colors hover:bg-lime/20",children:"Connect"})]},P.id))})]}),pe>0&&e.jsxs("div",{className:"rounded-xl border border-subtle bg-white/[0.02] text-caption text-secondary",children:[e.jsxs("button",{onClick:()=>{g(P=>!P),F&&k(0)},className:"flex w-full items-center gap-2 px-3 py-2 text-left transition-colors hover:bg-white/[0.03]",children:[e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:we("transition-transform",F?"rotate-0":"-rotate-90"),children:e.jsx("path",{d:"m6 9 6 6 6-6"})}),e.jsxs("span",{children:[u," archived session",u===1?"":"s",te>0?` across ${te} agent${te===1?"":"s"}`:""]})]}),e.jsx(qe,{initial:!1,children:F&&e.jsx(ue.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.2,ease:[.22,1,.36,1]},className:"overflow-hidden",children:e.jsxs("div",{className:"space-y-1.5 border-t border-subtle p-2",children:[z.map(({node:P,agentName:ce})=>{const $=P.runtimeProvider?{id:zn(P.runtimeProvider)}:ln(P.agentName,P.title,P.lastEventSummary,P);return e.jsxs("button",{onClick:()=>i(P.id),className:"flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left opacity-60 transition-colors hover:bg-white/[0.05] hover:opacity-80",children:[e.jsx(vs,{provider:$.id,size:"xs"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"truncate text-caption font-medium text-primary",children:ce}),e.jsx("span",{className:"text-micro text-muted",title:jt(P.updatedAt??P.lastEventAt??P.startedAt??Date.now()),children:Ce(P.updatedAt??P.lastEventAt??P.startedAt??Date.now())})]}),e.jsx("p",{className:"truncate text-micro text-secondary",children:P.title}),e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:P.status})]})]},P.id)}),z.length<u&&e.jsxs("button",{onClick:()=>k(P=>P+1),className:"w-full rounded-lg border border-white/[0.08] bg-white/[0.02] px-3 py-1.5 text-micro text-secondary transition-colors hover:bg-white/[0.05]",children:["Load more (",u-z.length," remaining)"]})]})})})]})]})]})}),Vi=[[/opus/i,"Opus"],[/sonnet/i,"Sonnet"],[/haiku/i,"Haiku"],[/kimi/i,"Kimi"],[/gemini/i,"Gemini"],[/gpt-4o/i,"GPT-4o"],[/gpt-4/i,"GPT-4"],[/qwen/i,"Qwen"],[/deepseek/i,"DeepSeek"],[/llama/i,"Llama"]];function Rt(t){if(!t)return"";for(const[r,n]of Vi)if(r.test(t))return n;const s=t.split("/");return s[s.length-1]??t}function Hi(t,s=4){let r=t.replace(/^\/Users\/[^/]+\//,"~/").replace(/^~\/Code\//,"").replace(/^~\//,"");const n=r.split("/");return n.length>s&&(r=n.slice(-s).join("/")),r}function _e(t){let s=t;return s=s.replace(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi,r=>`#${r.slice(0,4)}`),s=s.replace(/(?:anthropic|openrouter|openai)\/[a-z0-9._/-]+/gi,r=>Rt(r)),s=s.replace(/\/Users\/[a-zA-Z0-9_-]+\/[^\s"']+/g,r=>Hi(r)),s}const Ns=/\[([^\]]+)\]\(([^)\s]+)\)|`([^`]+)`|\*\*([^*]+)\*\*|__([^_]+)__|\*([^*\n]+)\*|_([^_\n]+)_/g;function Ji(t){try{const s=new URL(t);return s.protocol==="http:"||s.protocol==="https:"}catch{return!1}}function yt(t,s){const r=[];let n=0,i=0;Ns.lastIndex=0;for(let o=Ns.exec(t);o;o=Ns.exec(t)){const[c]=o,l=o.index;l>n&&r.push(t.slice(n,l));const y=`${s}-${i++}`,m=o[1],x=o[2],p=o[3],d=o[4],h=o[5],N=o[6],w=o[7];m&&x&&Ji(x)?r.push(e.jsx("a",{href:x,target:"_blank",rel:"noopener noreferrer",className:"text-[#D8FFA1] underline decoration-white/35 underline-offset-2 transition hover:text-[#ECFFC6]",children:m},y)):p?r.push(e.jsx("code",{className:"rounded bg-white/[0.08] px-1 py-0.5 font-mono text-[0.93em] text-bright",children:p},y)):d||h?r.push(e.jsx("strong",{className:"font-semibold text-white",children:d??h},y)):N||w?r.push(e.jsx("em",{className:"italic text-bright",children:N??w},y)):r.push(c),n=l+c.length}return n<t.length&&r.push(t.slice(n)),r}function Qi(t,s){const r=t.split(`
204
- `),n=[];return r.forEach((i,o)=>{n.push(...yt(i,`${s}-line-${o}`)),o<r.length-1&&n.push(e.jsx("br",{},`${s}-br-${o}`))}),n}function ns(t){return t.trim().replace(/^\|/,"").replace(/\|$/,"").split("|").map(r=>r.trim())}function Xi(t){const s=ns(t);return s.length===0?!1:s.every(r=>/^:?-{3,}:?$/.test(r))}function Gi(t){const s=t.trim(),r=s.startsWith(":"),n=s.endsWith(":");return r&&n?"center":n?"right":"left"}function Yi(t){const s=t.replace(/\r\n/g,`
205
- `).split(`
206
- `),r=[];let n=0;for(;n<s.length;){const i=s[n]??"",o=i.trim();if(!o){n+=1;continue}const c=i.includes("|"),l=s[n+1]??"";if(c&&l.includes("|")&&Xi(l)){const d=ns(i),N=ns(l).map(F=>Gi(F));n+=2;const w=[];for(;n<s.length;){const F=s[n]??"";if(!F.trim()||!F.includes("|"))break;w.push(ns(F)),n+=1}r.push(e.jsx("div",{className:"overflow-x-auto rounded-xl border border-white/[0.1] bg-black/25",children:e.jsxs("table",{className:"min-w-full border-collapse text-left",children:[e.jsx("thead",{children:e.jsx("tr",{className:"border-b border-white/[0.08] bg-white/[0.03]",children:d.map((F,g)=>e.jsx("th",{className:"px-3 py-2 text-caption font-semibold uppercase tracking-[0.08em] text-primary",style:{textAlign:N[g]??"left"},children:yt(F,`tbl-h-${n}-${g}`)},`tbl-h-${g}`))})}),e.jsx("tbody",{children:w.map((F,g)=>e.jsx("tr",{className:g<w.length-1?"border-b border-subtle":void 0,children:d.map((f,k)=>e.jsx("td",{className:"px-3 py-2 text-body leading-relaxed text-primary align-top",style:{textAlign:N[k]??"left"},children:yt(F[k]??"",`tbl-r-${n}-${g}-${k}`)},`tbl-r-${g}-c-${k}`))},`tbl-r-${g}`))})]})},`tbl-${n}`));continue}if(o.startsWith("```")){const d=o.slice(3).trim(),h=[];for(n+=1;n<s.length&&!(s[n]??"").trim().startsWith("```");)h.push(s[n]??""),n+=1;n<s.length&&(n+=1),r.push(e.jsxs("div",{className:"rounded-xl border border-white/[0.1] bg-black/40 p-3",children:[d&&e.jsx("p",{className:"mb-1 text-micro uppercase tracking-[0.12em] text-muted",children:d}),e.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap font-mono text-caption leading-relaxed text-primary",children:e.jsx("code",{children:h.join(`
207
- `)})})]},`code-${n}`));continue}const y=o.match(/^(#{1,3})\s+(.+)$/);if(y){const d=y[1].length,h=y[2],N=d===1?"text-title font-semibold":d===2?"text-heading font-semibold":"text-body font-medium";r.push(e.jsx("p",{className:we("tracking-[-0.01em] text-white",N),children:yt(h,`h-${n}`)},`h-${n}`)),n+=1;continue}if(i.match(/^\s*[-*]\s+(.+)$/)){const d=[];for(;n<s.length;){const N=(s[n]??"").match(/^\s*[-*]\s+(.+)$/);if(!N)break;d.push(N[1]),n+=1}r.push(e.jsx("ul",{className:"space-y-1.5 pl-4",children:d.map((h,N)=>e.jsx("li",{className:"list-disc text-body leading-relaxed text-primary",children:yt(h,`ul-${n}-${N}`)},`ul-${n}-${N}`))},`ul-${n}`));continue}if(i.match(/^\s*\d+\.\s+(.+)$/)){const d=[];for(;n<s.length;){const N=(s[n]??"").match(/^\s*\d+\.\s+(.+)$/);if(!N)break;d.push(N[1]),n+=1}r.push(e.jsx("ol",{className:"space-y-1.5 pl-4",children:d.map((h,N)=>e.jsx("li",{className:"list-decimal text-body leading-relaxed text-primary",children:yt(h,`ol-${n}-${N}`)},`ol-${n}-${N}`))},`ol-${n}`));continue}const p=[];for(;n<s.length;){const d=s[n]??"",h=d.trim();if(!h||/^(#{1,3})\s+/.test(h)||/^\s*[-*]\s+/.test(d)||/^\s*\d+\.\s+/.test(d)||h.startsWith("```"))break;p.push(d),n+=1}r.push(e.jsx("p",{className:"text-body leading-relaxed text-primary",children:Qi(p.join(`
208
- `),`p-${n}`)},`p-${n}`))}return r}function Bt({text:t,mode:s="inline",className:r}){const n=t.replace(/\r\n/g,`
209
- `);return n.trim()?s==="inline"?e.jsx("span",{className:r,children:yt(n,"inline")}):e.jsx("div",{className:we("space-y-2",r),children:Yi(n)}):null}const Un={run_started:{icon:"play",label:"Run started",color:C.teal},run_completed:{icon:"check_circle",label:"Run completed",color:C.lime},run_failed:{icon:"alert_triangle",label:"Run failed",color:C.red},artifact_created:{icon:"file",label:"Artifact",color:C.cyan},decision_requested:{icon:"shield",label:"Decision requested",color:C.amber},decision_resolved:{icon:"shield_check",label:"Decision resolved",color:C.lime},handoff_requested:{icon:"handoff",label:"Handoff requested",color:C.iris},handoff_claimed:{icon:"handoff_claimed",label:"Handoff claimed",color:C.teal},handoff_fulfilled:{icon:"sparkles",label:"Handoff fulfilled",color:C.lime},blocker_created:{icon:"octagon_x",label:"Blocker",color:C.red},milestone_completed:{icon:"flag",label:"Milestone",color:C.cyan},delegation:{icon:"workflow",label:"Delegation",color:C.iris}};function qt(t,s){if(!t)return null;for(const r of s){const n=t[r];if(typeof n=="string"&&n.trim().length>0)return n.trim()}return null}function Ds(t){return t?t.toLowerCase():""}function Zi(t,s){return[t.type,t.kind,t.phase,t.state,t.title,t.summary,t.description,qt(s,["source","event","eventType","artifact_type","action","kind"]),qt(s,["task","taskName","workstream","milestone","status"])].filter(r=>typeof r=="string"&&r.trim().length>0).join(" ").toLowerCase()}function ea(t,s){const r=Ds(qt(t,["artifact_type","artifactType"]));return r.includes("pr")||/pull request|merge request/.test(s)?{icon:"file_code",label:"Pull request",color:C.cyan}:r.includes("commit")||/commit|diff|patch/.test(s)?{icon:"git_commit",label:"Commit",color:C.cyan}:r.includes("config")?{icon:"checkpoint",label:"Config",color:C.cyan}:r.includes("design")?{icon:"compass",label:"Design output",color:C.cyan}:r.includes("report")||r.includes("document")||/memo|doc/.test(s)?{icon:"file",label:"Document",color:C.cyan}:Un.artifact_created}function ta(t){const s=t.metadata,r=Zi(t,s),n=Ds(qt(s,["source"])),i=Ds(qt(s,["action"]));if(/heartbeat|heart beat|alive signal/.test(r))return{icon:"heartbeat",label:"Heartbeat",color:C.teal};if(/soul/.test(r))return{icon:"compass",label:"Soul state",color:C.iris};if(/memory sync|sync memory|workspace state|sync completed|memory file/.test(r))return{icon:"memory_sync",label:"Memory sync",color:C.teal};if(/checkpoint|rollback|restore point/.test(r))return{icon:"checkpoint",label:"Checkpoint",color:C.amber};if(/quality gate|quality score|quality check/.test(r))return{icon:"quality_gate",label:"Quality gate",color:C.lime};if(/model routing|routed model|model tier/.test(r))return{icon:"route",label:"Model routing",color:C.iris};if(n==="local_openclaw")return{icon:"terminal",label:"Local OpenClaw",color:C.teal};if(t.type==="artifact_created")return ea(s,r);if(t.type==="decision_resolved")return i==="reject"||/rejected|declined/.test(r)?{icon:"shield_x",label:"Decision rejected",color:C.red}:{icon:"shield_check",label:"Decision approved",color:C.lime};if(t.type==="delegation"){if(/dispatch|spawn|launched|kickoff|started/.test(r))return{icon:"workflow",label:"Dispatch",color:C.iris};if(/message|chat|reply|summary/.test(r))return{icon:"message",label:"Message",color:C.teal}}return Un[t.type]??{icon:"message",label:"Activity",color:C.textMuted}}function sa({icon:t,size:s=14,className:r}){const n={width:s,height:s,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.8,strokeLinecap:"round",strokeLinejoin:"round",className:r};switch(t){case"play":return e.jsx("svg",{...n,children:e.jsx("path",{d:"m8 6 10 6-10 6z"})});case"check_circle":return e.jsxs("svg",{...n,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"m8.5 12 2.5 2.5 4.5-5"})]});case"alert_triangle":return e.jsxs("svg",{...n,children:[e.jsx("path",{d:"m12 3 9 16H3z"}),e.jsx("path",{d:"M12 9v4"}),e.jsx("path",{d:"M12 17h.01"})]});case"file":return e.jsxs("svg",{...n,children:[e.jsx("path",{d:"M14 2H7a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7z"}),e.jsx("path",{d:"M14 2v5h5"})]});case"file_code":return e.jsxs("svg",{...n,children:[e.jsx("path",{d:"M14 2H7a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7z"}),e.jsx("path",{d:"M14 2v5h5"}),e.jsx("path",{d:"m10 13-2 2 2 2"}),e.jsx("path",{d:"m14 13 2 2-2 2"})]});case"git_commit":return e.jsxs("svg",{...n,children:[e.jsx("circle",{cx:"12",cy:"12",r:"3"}),e.jsx("path",{d:"M3 12h6M15 12h6"})]});case"shield":return e.jsxs("svg",{...n,children:[e.jsx("path",{d:"M12 3 5 6v6c0 5 3.3 7.8 7 9 3.7-1.2 7-4 7-9V6z"}),e.jsx("path",{d:"M12 9v4"}),e.jsx("path",{d:"M12 16h.01"})]});case"shield_check":return e.jsxs("svg",{...n,children:[e.jsx("path",{d:"M12 3 5 6v6c0 5 3.3 7.8 7 9 3.7-1.2 7-4 7-9V6z"}),e.jsx("path",{d:"m9 12.5 2 2 4-4"})]});case"shield_x":return e.jsxs("svg",{...n,children:[e.jsx("path",{d:"M12 3 5 6v6c0 5 3.3 7.8 7 9 3.7-1.2 7-4 7-9V6z"}),e.jsx("path",{d:"m10 10 4 4M14 10l-4 4"})]});case"handoff":return e.jsxs("svg",{...n,children:[e.jsx("path",{d:"M7 8h6a3 3 0 1 1 0 6H8"}),e.jsx("path",{d:"m10 14-3 3-3-3"}),e.jsx("path",{d:"M17 10h-4"})]});case"handoff_claimed":return e.jsxs("svg",{...n,children:[e.jsx("path",{d:"M8.5 12.5 12 9l3.5 3.5"}),e.jsx("path",{d:"M6 14h12"}),e.jsx("path",{d:"M7 18h10"})]});case"sparkles":return e.jsxs("svg",{...n,children:[e.jsx("path",{d:"m12 3 1.5 3.5L17 8l-3.5 1.5L12 13l-1.5-3.5L7 8l3.5-1.5z"}),e.jsx("path",{d:"m5 14 .8 1.8L8 16.6l-2.2.8L5 19l-.8-1.6L2 16.6l2.2-.8z"}),e.jsx("path",{d:"m19 14 .8 1.8 2.2.8-2.2.8L19 19l-.8-1.6-2.2-.8 2.2-.8z"})]});case"octagon_x":return e.jsxs("svg",{...n,children:[e.jsx("path",{d:"m10.2 3-5.8 3.3v11.4L10.2 21h3.6l5.8-3.3V6.3L13.8 3z"}),e.jsx("path",{d:"m9 9 6 6M15 9l-6 6"})]});case"flag":return e.jsxs("svg",{...n,children:[e.jsx("path",{d:"M5 3v18"}),e.jsx("path",{d:"m5 4 12 1-2 4 2 4-12-1"})]});case"workflow":return e.jsx(Ln,{size:s,className:r,strokeWidth:1.8});case"memory_sync":return e.jsxs("svg",{...n,children:[e.jsx("ellipse",{cx:"12",cy:"5.5",rx:"6.5",ry:"2.5"}),e.jsx("path",{d:"M5.5 5.5v6c0 1.4 2.9 2.5 6.5 2.5s6.5-1.1 6.5-2.5v-6"}),e.jsx("path",{d:"m8 17-2 2 2 2"}),e.jsx("path",{d:"M16 17l2 2-2 2"})]});case"heartbeat":return e.jsx("svg",{...n,children:e.jsx("path",{d:"M3 12h4l2-4 3 8 2-4h7"})});case"checkpoint":return e.jsxs("svg",{...n,children:[e.jsx("path",{d:"M12 3v6"}),e.jsx("path",{d:"M8 5h8"}),e.jsx("path",{d:"M7 11h10v10H7z"}),e.jsx("path",{d:"M9 14h6"})]});case"quality_gate":return e.jsxs("svg",{...n,children:[e.jsx("path",{d:"M12 3 5 6v6c0 5 3.3 7.8 7 9 3.7-1.2 7-4 7-9V6z"}),e.jsx("path",{d:"m9 12.5 2 2 4-4"})]});case"route":return e.jsxs("svg",{...n,children:[e.jsx("circle",{cx:"6",cy:"6",r:"2"}),e.jsx("circle",{cx:"18",cy:"18",r:"2"}),e.jsx("path",{d:"M8 6h4a4 4 0 0 1 4 4v6"}),e.jsx("path",{d:"M16 6h2"})]});case"terminal":return e.jsxs("svg",{...n,children:[e.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2"}),e.jsx("path",{d:"m7 9 3 3-3 3"}),e.jsx("path",{d:"M13 15h4"})]});case"compass":return e.jsxs("svg",{...n,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"m10 10 6-2-2 6-6 2z"})]});case"message":default:return e.jsx("svg",{...n,children:e.jsx("path",{d:"M21 12a8 8 0 0 1-8 8H7l-4 2 1.5-4A8 8 0 1 1 21 12z"})})}}function na(t){try{return new Date(t).toLocaleTimeString([],{hour:"numeric",minute:"2-digit"})}catch{return""}}function ra(t){var r;let s=0;for(const n of t){const i=(r=n.metadata)==null?void 0:r.costTotal;typeof i=="number"&&(s+=i)}return s<=0?null:s<.01?"<$0.01":`$${s.toFixed(2)}`}const ia=a.memo(function({items:s,session:r,agentName:n,onBack:i}){const[o,c]=a.useState(!1),l=a.useMemo(()=>[...s].sort((d,h)=>Date.parse(d.timestamp)-Date.parse(h.timestamp)),[s]),y=a.useMemo(()=>ra(l),[l]),m=a.useMemo(()=>{if(l.length<2)return null;const d=Date.parse(l[0].timestamp),N=Date.parse(l[l.length-1].timestamp)-d;return N<6e4?`${Math.round(N/1e3)}s`:N<36e5?`${Math.round(N/6e4)}m`:`${(N/36e5).toFixed(1)}h`},[l]),x=a.useMemo(()=>{let d=null,h=null,N=null,w=null,F=null;for(const f of l){const k=f.metadata;if(k&&(!d&&typeof k.domain=="string"&&(d=k.domain),!h&&typeof k.provider=="string"&&(h=k.provider),!N&&typeof k.model=="string"&&(N=k.model),!w&&typeof k.spawn_guard_model_tier=="string"&&(w=k.spawn_guard_model_tier),!F&&typeof k.kickoff_context_hash=="string"&&(F=k.kickoff_context_hash),d&&(h||N)&&w&&F))break}return!(d||h||N||w||F)?null:{domain:d,provider:h,model:N,modelTier:w,kickoffContextHash:F}},[l]),p=(r==null?void 0:r.title)??n??"Session";return e.jsxs("div",{className:"flex h-full flex-col",children:[e.jsxs("div",{className:"border-b border-subtle px-4 py-3",children:[e.jsxs("button",{onClick:i,className:"mb-2 flex items-center gap-1.5 text-caption text-secondary transition-colors hover:text-primary",children:[e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"m15 18-6-6 6-6"})}),"Back to timeline"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"h-2.5 w-2.5 rounded-full",style:{backgroundColor:C.lime,boxShadow:`0 0 12px ${C.lime}55`}}),e.jsx("h3",{className:"text-heading font-semibold text-white",children:_e(p)})]}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2 text-micro text-secondary",children:[n&&e.jsxs("span",{className:"inline-flex items-center gap-1.5 rounded-full border border-subtle px-1 py-0.5",children:[e.jsx(nt,{name:n,hint:(r==null?void 0:r.id)??(r==null?void 0:r.runId)??null,size:"xs"}),e.jsx("span",{children:n})]}),e.jsxs("span",{children:[l.length," turn",l.length!==1?"s":""]}),m&&e.jsx("span",{children:m}),y&&e.jsx("span",{className:"text-muted",children:y}),(x==null?void 0:x.domain)&&e.jsx("span",{className:"rounded-full border border-strong bg-white/[0.03] px-2 py-0.5 text-secondary",children:_e(x.domain)}),(r==null?void 0:r.status)&&e.jsx("span",{className:"rounded-full px-1.5 py-0.5 text-micro uppercase tracking-wider",style:{backgroundColor:r.status==="running"?`${C.lime}20`:r.status==="failed"?`${C.red}20`:`${C.teal}20`,color:r.status==="running"?C.lime:r.status==="failed"?C.red:C.teal},children:r.status}),x&&(x.provider||x.model||x.modelTier||x.kickoffContextHash)&&e.jsxs("button",{type:"button",onClick:()=>c(d=>!d),className:"inline-flex items-center gap-1 text-micro text-muted transition-colors hover:text-secondary",children:[e.jsx("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:`transition-transform duration-150 ${o?"rotate-180":""}`,children:e.jsx("path",{d:"m6 9 6 6 6-6"})}),"Info"]})]}),o&&x&&e.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-1.5 text-micro",children:[(x.provider||x.model)&&e.jsxs("span",{className:"rounded-full border border-strong bg-white/[0.03] px-2 py-0.5 text-secondary",children:[x.provider?`${_e(x.provider)} · `:"",x.model?Rt(x.model):"—"]}),x.modelTier&&e.jsxs("span",{className:"rounded-full border border-strong bg-white/[0.03] px-2 py-0.5 text-secondary",children:["tier: ",_e(x.modelTier)]}),x.kickoffContextHash&&e.jsxs("span",{className:"rounded-full border border-strong bg-white/[0.03] px-2 py-0.5 font-mono text-secondary",children:["kickoff ",x.kickoffContextHash.slice(0,8),"…"]})]})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-4 py-3",children:[e.jsx(qe,{mode:"popLayout",children:e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute left-[7px] top-3 bottom-3 w-px",style:{backgroundColor:`${C.iris}25`}}),e.jsx("div",{className:"space-y-1",children:l.map((d,h)=>{var D;const N=ta(d),w=N.color,F=(D=d.metadata)==null?void 0:D.model,g=typeof F=="string"?Rt(F):null,f=_e(d.title??""),k=d.type==="run_failed",v=d.type==="artifact_created",T=d.type==="decision_requested"||d.type==="decision_resolved";return e.jsxs(ue.div,{initial:{opacity:0,x:-8},animate:{opacity:1,x:0},transition:{duration:.2,delay:h*.02},className:"group relative flex items-start gap-2.5 rounded-lg py-1.5 pl-0 pr-2 transition-colors hover:bg-white/[0.02]",children:[e.jsx("span",{className:"relative z-10 mt-1.5 flex h-[15px] w-[15px] flex-shrink-0 items-center justify-center rounded-full text-[8px]",style:{backgroundColor:`${w}20`,color:w,border:`1px solid ${w}40`},children:e.jsx(sa,{icon:N.icon,size:8,className:"opacity-95"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:`text-body leading-snug ${k?"text-red-400":T?"text-amber-300":v?"text-cyan-300":"text-bright"}`,children:f}),d.summary&&d.summary!==f&&e.jsx("p",{className:"mt-0.5 text-caption leading-relaxed text-muted",children:_e(d.summary)})]}),e.jsxs("div",{className:"flex flex-shrink-0 flex-col items-end gap-0.5 pt-0.5",children:[e.jsx("span",{className:"text-micro text-muted",title:jt(d.timestamp),children:na(d.timestamp)}),g&&e.jsx("span",{className:"text-micro text-faint",children:g})]})]},d.id)})})]})}),l.length===0&&e.jsxs("div",{className:"flex flex-col items-center gap-2 py-8 text-center",children:[e.jsx("p",{className:"text-body text-secondary",children:"No activity in this session yet."}),e.jsx("p",{className:"text-caption text-muted animate-pulse",children:"Activity may take a moment to appear."})]}),l.length>0&&e.jsxs("div",{className:"mt-4 rounded-lg border border-subtle bg-white/[0.02] px-3 py-2 text-micro text-muted",children:[l.length," turn",l.length!==1?"s":"",m?` over ${m}`:"",y?` · ${y}`:""," · ",e.jsx("span",{title:jt(l[l.length-1].timestamp),children:Ce(l[l.length-1].timestamp)})]})]})]})}),aa={initial:{opacity:0,y:8,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-4,scale:.98}},Ss=240,oa=240,dn=3600,un=12e3,Gt={all:"All",messages:"Messages",artifacts:"Artifacts",decisions:"Decisions"};function la(t){if(!t)return 0;const s=Date.parse(t);return Number.isFinite(s)?s:0}function Wn(t){if(!t)return"";const s=[];for(const[r,n]of Object.entries(t))typeof n=="string"&&(r.toLowerCase().includes("type")||r.toLowerCase().includes("kind")||r.toLowerCase().includes("summary")||r.toLowerCase().includes("message")||r.toLowerCase().includes("artifact")||r.toLowerCase().includes("decision")||r.toLowerCase().includes("run")||r.toLowerCase().includes("title")||r.toLowerCase().includes("task")||r.toLowerCase().includes("workstream")||r.toLowerCase().includes("milestone"))&&s.push(n);return s.join(" ")}function ca(t){if(t.runId)return t.runId;const s=t.metadata;if(!s)return null;const r=["runId","run_id","sessionId","session_id","agentRunId"];for(const n of r){const i=s[n];if(typeof i=="string"&&i.trim().length>0)return i.trim()}return null}function bt(t){const s=typeof t.agentId=="string"&&t.agentId.trim().length>0?t.agentId.trim():null,r=typeof t.agentName=="string"&&t.agentName.trim().length>0?t.agentName.trim():null;if(s||r)return{agentId:s,agentName:r};const n=t.metadata;if(!n)return{agentId:null,agentName:null};const i=(typeof n.agent_id=="string"&&n.agent_id.trim().length>0?n.agent_id.trim():null)??(typeof n.agentId=="string"&&n.agentId.trim().length>0?n.agentId.trim():null),o=(typeof n.agent_name=="string"&&n.agent_name.trim().length>0?n.agent_name.trim():null)??(typeof n.agentName=="string"&&n.agentName.trim().length>0?n.agentName.trim():null);return{agentId:i,agentName:o}}function pn(t){const s=t.metadata;if(!s)return null;const r=["workstreamId","workstream_id"];for(const i of r){const o=s[i];if(typeof o=="string"&&o.trim().length>0)return o.trim()}const n=s.orgx_context;if(n&&typeof n=="object"&&!Array.isArray(n)){const i=n,o=i.workstreamId??i.workstream_id;if(typeof o=="string"&&o.trim().length>0)return o.trim()}return null}function da(t){return t?["artifact","artifacts","artifact_type","artifactType","output","outputs","result","results","payload","toolOutput","toolOutputs","toolResult","toolResults"].some(r=>r in t):!1}function ua(t){const s=t.metadata,r=Wn(t.metadata),n=[t.type,t.kind,t.summary,t.title,t.description,r].filter(c=>typeof c=="string"&&c.trim().length>0).join(" ").toLowerCase();return t.type==="artifact_created"||da(s)||/artifact|deliverable|output payload/.test(n)?"artifact":t.type==="decision_requested"||t.type==="decision_resolved"||t.decisionRequired===!0||/decision|approve|approval|reject|review request|request changes/.test(n)?"decision":"message"}function Mt(t){return{run_started:"Run started",run_completed:"Run completed",run_failed:"Run failed",artifact_created:"Artifact created",decision_requested:"Decision requested",decision_resolved:"Decision resolved",handoff_requested:"Handoff requested",handoff_claimed:"Handoff claimed",handoff_fulfilled:"Handoff fulfilled",blocker_created:"Blocker created",milestone_completed:"Milestone completed",delegation:"Delegation"}[t]??_e(t.split("_").join(" "))}function pa(t){const s=new Date(t);if(Number.isNaN(s.getTime()))return"unknown";const r=new Date(s.getFullYear(),s.getMonth(),s.getDate());return String(r.getTime())}function ma(t){const s=Number(t);if(!Number.isFinite(s))return"Unknown day";const r=new Date(s),n=new Date,i=new Date(n.getFullYear(),n.getMonth(),n.getDate()),o=new Date(i);return o.setDate(i.getDate()-1),r.getTime()===i.getTime()?"Today":r.getTime()===o.getTime()?"Yesterday":r.toLocaleDateString(void 0,{month:"short",day:"numeric",year:r.getFullYear()===n.getFullYear()?void 0:"numeric"})}function Cs(t){return t==="artifact"?"Artifact":t==="decision"?"Decision":"Message"}function Yt(t){return t==="artifact"?C.cyan:t==="decision"?C.amber:C.teal}function xa(t){return t.type==="run_failed"||t.type==="blocker_created"?"critical":t.type==="decision_requested"?"warning":t.type==="run_completed"||t.type==="milestone_completed"||t.type==="decision_resolved"?"positive":"neutral"}function ha(t){return t==="critical"?C.red:t==="warning"?C.amber:t==="positive"?C.lime:C.teal}function fa(t){if(!t||Object.keys(t).length===0)return null;try{return JSON.stringify(t,null,2)}catch{return null}}function ga(t){if(!t)return null;const s=t.metadata;if(!s)return null;const r=typeof s.event=="string"&&s.event.trim().length>0?s.event.trim():null;if(!r||!r.startsWith("autopilot_slice"))return null;const n=bt(t),i=s.required_skills??s.requiredSkills,o=Array.isArray(i)?i.filter(A=>typeof A=="string"&&A.trim().length>0):[],c=s.task_ids??s.taskIds,l=Array.isArray(c)?c.filter(A=>typeof A=="string"&&A.trim().length>0):[],y=s.milestone_ids??s.milestoneIds,m=Array.isArray(y)?y.filter(A=>typeof A=="string"&&A.trim().length>0):[],x=typeof s.workstream_id=="string"?s.workstream_id:typeof s.workstreamId=="string"?s.workstreamId:null,p=typeof s.workstream_title=="string"?s.workstream_title:typeof s.workstreamTitle=="string"?s.workstreamTitle:null,d=typeof s.initiative_title=="string"?s.initiative_title:typeof s.initiativeTitle=="string"?s.initiativeTitle:null,h=typeof s.domain=="string"?s.domain:null,N=typeof s.parsed_status=="string"?s.parsed_status:typeof s.parsedStatus=="string"?s.parsedStatus:null,w=typeof s.has_output=="boolean"?s.has_output:null,F=typeof s.log_path=="string"?s.log_path:null,g=typeof s.output_path=="string"?s.output_path:null,f=typeof s.error=="string"?s.error:null,k=typeof s.artifacts=="number"?s.artifacts:null,v=typeof s.decisions=="number"?s.decisions:null,T=typeof s.status_updates_applied=="number"?s.status_updates_applied:null,D=typeof s.status_updates_buffered=="number"?s.status_updates_buffered:null;return{event:r,agentId:n.agentId,agentName:n.agentName,domain:h,requiredSkills:o,initiativeTitle:d,workstreamId:x,workstreamTitle:p,taskIds:l,milestoneIds:m,parsedStatus:N,hasOutput:w,artifacts:k,decisions:v,statusUpdatesApplied:T,statusUpdatesBuffered:D,logPath:F,outputPath:g,error:f}}function ba(t){if(!t)return null;const s=t.orgx_provenance,r=s&&typeof s=="object"&&!Array.isArray(s)?s:null,n=r!=null&&r.skill_pack&&typeof r.skill_pack=="object"&&!Array.isArray(r.skill_pack)?r.skill_pack:null,i=(typeof t.orgx_plugin_version=="string"?t.orgx_plugin_version:null)??(typeof(r==null?void 0:r.plugin_version)=="string"?r.plugin_version:null),o=(typeof t.skill_pack_name=="string"?t.skill_pack_name:null)??(typeof(n==null?void 0:n.name)=="string"?n.name:null),c=(typeof t.skill_pack_version=="string"?t.skill_pack_version:null)??(typeof(n==null?void 0:n.version)=="string"?n.version:null),l=(typeof t.skill_pack_checksum=="string"?t.skill_pack_checksum:null)??(typeof(n==null?void 0:n.checksum)=="string"?n.checksum:null),y=(typeof t.skill_pack_source=="string"?t.skill_pack_source:null)??(typeof(n==null?void 0:n.source)=="string"?n.source:null),m=typeof t.kickoff_context_hash=="string"?t.kickoff_context_hash:null,x=typeof t.kickoff_context_source=="string"?t.kickoff_context_source:null,p=typeof t.spawn_guard_model_tier=="string"?t.spawn_guard_model_tier:null,d=typeof t.provider=="string"?t.provider:null,h=typeof t.model=="string"?t.model:null,N=typeof t.domain=="string"?t.domain:null,w=t.required_skills??t.requiredSkills,F=Array.isArray(w)?w.filter(f=>typeof f=="string"&&f.trim().length>0):[];return!!i||!!(o||c||l)||!!m||!!(p||d||h||N)||F.length>0?{pluginVersion:i,skillPack:o||c||l||y?{name:o,version:c,checksum:l,source:y}:null,kickoffContextHash:m,kickoffContextSource:x,modelTier:p,provider:d,model:h,domain:N,requiredSkills:F}:null}function ya(t){if(!t)return null;const s=t.metadata;if(!s||typeof s!="object")return null;const r=["artifact","artifacts","output","outputs","result","results","payload","toolOutput","toolOutputs","toolResult","toolResults"];for(const n of r){const i=s[n];if(i!=null)return{source:n,value:i}}return t.type==="artifact_created"?{source:"metadata",value:s}:null}function Kn(t){if(typeof t=="string")return e.jsx(Bt,{mode:"block",text:t,className:"text-body leading-relaxed text-primary"});if(typeof t=="number"||typeof t=="boolean")return e.jsx("p",{className:"text-body text-primary",children:String(t)});if(Array.isArray(t))return e.jsx("div",{className:"space-y-1.5",children:t.map((s,r)=>e.jsx("div",{className:"rounded-lg border border-white/[0.08] bg-white/[0.02] px-2.5 py-2",children:Kn(s)},`artifact-list-${r}`))});if(t&&typeof t=="object"){const s=Object.entries(t);return e.jsx("dl",{className:"space-y-1.5",children:s.map(([r,n])=>e.jsxs("div",{className:"rounded-lg border border-white/[0.08] bg-white/[0.02] px-2.5 py-2",children:[e.jsx("dt",{className:"text-micro font-semibold tracking-[0.02em] text-secondary",children:_e(r)}),e.jsx("dd",{className:"mt-1 text-body text-primary",children:typeof n=="string"||typeof n=="number"||typeof n=="boolean"?String(n):Array.isArray(n)?`${n.length} item${n.length===1?"":"s"}`:n&&typeof n=="object"?`${Object.keys(n).length} field${Object.keys(n).length===1?"":"s"}`:"—"})]},r))})}return e.jsx("p",{className:"text-body text-secondary",children:"No artifact payload."})}function dt(t){if(!t)return null;const s=t.trim();if(!s)return null;const r=Rt(s);return r&&r!==s&&/^[a-z0-9._/-]+$/i.test(s)?r:_e(s)}const wa=[/^User:\s*System:/i,/Exec failed/i,/SIGKILL/i,/SIGTERM/i,/stack trace/i,/Traceback \(most recent/i,/^\s*\{[\s"]/,/Error: /,/execution policy/i,/outbox replay/i,/changeset replayed/i];function va(t){return wa.some(s=>s.test(t))}function ja(t){const s=t.title??"";return va(s)?/Exec failed|SIGKILL|SIGTERM|Error: /i.test(s)?{title:"Execution failed",isSystem:!0}:/outbox replay|changeset replayed/i.test(s)?{title:"Changes synced",isSystem:!0}:/execution policy/i.test(s)?{title:"System directive",isSystem:!0}:{title:"System event",isSystem:!0}:{title:_e(s)||_e(Mt(t.type)),isSystem:!1}}function ka(t){if(!t)return null;const s=t.metadata;if(!s||typeof s!="object")return null;const r=typeof s.source=="string"?s.source.trim():"",n=typeof s.turnId=="string"?s.turnId.trim():"";if(r!=="local_openclaw"||!n)return null;const i=typeof s.sessionKey=="string"&&s.sessionKey.trim().length>0?s.sessionKey.trim():null;return{turnId:n,sessionKey:i,runId:t.runId??null}}function mn(t){return t.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g,"$1").replace(/`([^`]+)`/g,"$1").replace(/\*\*([^*]+)\*\*/g,"$1").replace(/__([^_]+)__/g,"$1").replace(/\*([^*\n]+)\*/g,"$1").replace(/_([^_\n]+)_/g,"$1")}function Na(t,s){const n=(dt(s??t.summary)??dt(t.description)??_e(t.title||Mt(t.type))).replace(/\r\n/g,`
210
- `).replace(/```[\s\S]*?```/g," ").replace(/^\s{0,3}#{1,6}\s+/gm,"").replace(/^\s*[-*]\s+/gm,"").replace(/\s+/g," ").trim(),i=n.split(`
211
- `).map(c=>mn(c).trim()).filter(c=>c.length>0&&!/^\|?[:\-| ]+\|?$/.test(c));let o=i[0]??mn(n);return o.length<24&&i.length>1&&(o=`${o} ${i[1]}`.trim()),o.length>108?`${o.slice(0,107).trimEnd()}…`:o}const Sa=a.memo(function({activity:s,sessions:r,initiatives:n=[],selectedRunIds:i,selectedSessionLabel:o=null,selectedWorkstreamId:c=null,selectedWorkstreamLabel:l=null,agentFilter:y=null,timeFilterId:m="live",hasMore:x=!1,isLoadingMore:p=!1,onLoadMore:d,onClearSelection:h,onClearWorkstreamFilter:N,onClearAgentFilter:w,onFocusRunId:F}){var Ut;const g=In(),[f,k]=a.useState("all"),[v,T]=a.useState(!1),[D,A]=a.useState(""),[ee,ie]=a.useState(new Set),[ne,G]=a.useState("newest"),[te,pe]=a.useState(Ss),[j,E]=a.useState(null),[u,I]=a.useState(null),[L,z]=a.useState(!1),[R,me]=a.useState(1),[re,X]=a.useState("structured"),[K,Ae]=a.useState(null),[le,Ie]=a.useState("feed"),[P,ce]=a.useState(null),[$,S]=a.useState(null),[V,Y]=a.useState(!1),W=a.useRef(null),ke=a.useRef(null),Se=a.useMemo(()=>$n(m),[m]),ye=a.useMemo(()=>{const _=new Map;for(const J of r)_.set(J.runId,J.title),_.set(J.id,J.title);return _},[r]),Ye=a.useMemo(()=>{const _=new Map;for(const J of r)J.status&&(_.set(J.runId,J.status),_.set(J.id,J.status));return _},[r]),Me=a.useMemo(()=>{const _=new Map;for(const J of r){const B=J.workstreamId??null;_.set(J.runId,B),_.set(J.id,B)}return _},[r]),Ze=a.useMemo(()=>{const _=new Map;for(const J of n)_.set(J.id,J.name);return _},[n]),q=a.useMemo(()=>{const _=new Map;for(const J of n)for(const B of J.workstreams??[])_.set(B.id,B.name);return _},[n]),H=a.useMemo(()=>s.map(_=>{const J=ca(_),B=ua(_),Q=[_.title,_.description,_.summary,_.agentName,Wn(_.metadata)].filter(be=>typeof be=="string"&&be.length>0).join(" ").toLowerCase();return{item:_,bucket:B,runId:J,timestampEpoch:la(_.timestamp),searchText:Q}}),[s]),he=a.useMemo(()=>{let _=0;for(const J of H)_=Math.max(_,J.timestampEpoch);return _<=0?!1:Date.now()-_<6e4},[H]),ge=a.useMemo(()=>new Set(i.filter(_=>_&&_.trim().length>0)),[i]),se=ge.size>0,xe=a.useMemo(()=>{if(!se)return null;for(const _ of ge){const J=r.find(B=>B.runId===_||B.id===_);if(J)return J}return null},[se,ge,r]),{filtered:ae,filteredTotal:De,hiddenCount:ze}=a.useMemo(()=>{const _=[];let J=0;const B=D.trim().toLowerCase();for(const Le of H){const Re=Le.runId;if(se&&(!Re||!ge.has(Re)))continue;if(c){const ot=pn(Le.item),lt=Re?Me.get(Re)??null:null;if((ot??lt)!==c)continue}if(y&&Le.item.agentName!==y)continue;const We=Le.bucket;if(!(f==="messages"&&We!=="message")&&!(f==="artifacts"&&We!=="artifact")&&!(f==="decisions"&&We!=="decision")){if(B.length>0){const ot=Re?ye.get(Re)??Re:"";if(!`${Le.searchText} ${ot.toLowerCase()}`.includes(B))continue}_.length<un?_.push(Le):J+=1}}const Q=[..._].sort((Le,Re)=>{const We=Re.timestampEpoch-Le.timestampEpoch;return ne==="newest"?We:-We}),be=Math.min(Math.max(1,Math.min(dn,te)),Q.length),Fe=Q.slice(0,be),st=Q.length+J;return{filtered:Fe,filteredTotal:st,hiddenCount:Math.max(0,st-Fe.length)}},[f,y,H,se,D,ye,te,c,ge,Me,ne]),ft=a.useMemo(()=>{const _=new Map;for(const B of ae){const Q=pa(B.item.timestamp),be=_.get(Q);be?be.push(B):_.set(Q,[B])}return Array.from(_.keys()).sort((B,Q)=>{const be=Number(Q)-Number(B);return ne==="newest"?be:-be}).map(B=>({key:B,label:ma(B),items:_.get(B)??[]}))},[ae,ne]),ds=a.useMemo(()=>ft.map(_=>{const J=new Map;for(const B of _.items){const Q=`${B.item.type}::${B.item.title}`,be=J.get(Q);be?(be.count+=1,be.firstTimestamp=Math.min(be.firstTimestamp,B.timestampEpoch),be.allItems.push(B),B.timestampEpoch>be.representative.timestampEpoch&&(be.representative=B)):J.set(Q,{key:Q,representative:B,count:1,firstTimestamp:B.timestampEpoch,allItems:[B]})}return{..._,clusters:Array.from(J.values())}}),[ft]),zt=a.useCallback(_=>{ie(J=>{const B=new Set(J);return B.has(_)?B.delete(_):B.add(_),B})},[]),Ve=a.useMemo(()=>Math.min(dn,Math.min(un,De)),[De]);a.useEffect(()=>{pe(Ss)},[f,y,se,D,c,ne,m]),a.useEffect(()=>{const _=W.current,J=ke.current;if(!_||!J)return;const B=new IntersectionObserver(Q=>{if(Q.some(Fe=>Fe.isIntersecting)){if(ae.length<Ve){pe(Fe=>Math.min(Ve,Math.max(Fe,Ss)+oa));return}x&&!p&&(d==null||d())}},{root:_,rootMargin:"240px"});return B.observe(J),()=>B.disconnect()},[ae.length,x,p,d,Ve]);const He=a.useMemo(()=>j?ae.findIndex(_=>_.item.id===j):-1,[j,ae]),U=He>=0?ae[He]:null,at=a.useMemo(()=>ya((U==null?void 0:U.item)??null),[U]),de=a.useMemo(()=>ga((U==null?void 0:U.item)??null),[U]),je=a.useMemo(()=>ba((U==null?void 0:U.item.metadata)??void 0),[U]),kt=a.useMemo(()=>fa((U==null?void 0:U.item.metadata)??void 0),[U]),Nt=a.useMemo(()=>{const _=dt(K);return _||(dt(U==null?void 0:U.item.summary)??dt(U==null?void 0:U.item.description))},[K,U]),St=a.useCallback(()=>{E(null)},[]);a.useEffect(()=>{if(!u)return;const _=window.setTimeout(()=>I(null),2e3);return()=>window.clearTimeout(_)},[u]);const et=a.useCallback(async(_,J)=>{if(J)try{await navigator.clipboard.writeText(J),I(`${_} copied`)}catch{I("Copy failed")}},[]);a.useEffect(()=>{X("structured"),z(!1)},[j]),a.useEffect(()=>{Ae(null),Ie("feed");const _=ka((U==null?void 0:U.item)??null);if(!_)return;const J=new URLSearchParams({turnId:_.turnId});_.sessionKey&&J.set("sessionKey",_.sessionKey),_.runId&&J.set("run",_.runId);const B=new AbortController;return fetch(`/orgx/api/live/activity/detail?${J.toString()}`,{method:"GET",signal:B.signal}).then(async Q=>{var Fe;return Q.ok?((Fe=(await Q.json()).detail)==null?void 0:Fe.summary)??null:(Q.status===404&&Ie("missing"),null)}).then(Q=>{typeof Q=="string"&&Q.trim().length>0?(Ae(Q),Ie("local")):Ie("missing")}).catch(Q=>{Q instanceof DOMException&&Q.name==="AbortError"||Ie("missing")}),()=>B.abort()},[U]),a.useEffect(()=>{ce(null),S(null);const _=U==null?void 0:U.item;if(!_||V)return;const J=(K??_.summary??_.description??_.title??"").trim();if(!J)return;const B=new AbortController;return fetch("/orgx/api/live/activity/headline",{method:"POST",headers:{"Content-Type":"application/json"},signal:B.signal,body:JSON.stringify({text:J,title:_.title??null,type:_.type})}).then(async Q=>Q.ok?await Q.json():((Q.status===404||Q.status===405)&&Y(!0),null)).then(Q=>{const be=Q==null?void 0:Q.headline;typeof be=="string"&&be.trim().length>0&&(Y(!1),ce(be.trim()),S((Q==null?void 0:Q.source)??null))}).catch(Q=>{Q instanceof DOMException&&Q.name}),()=>B.abort()},[U,K,V]);const Ue=a.useCallback(_=>{var Q;if(ae.length===0)return;const B=((He>=0?He:0)+_+ae.length)%ae.length;me(_),E(((Q=ae[B])==null?void 0:Q.item.id)??null)},[He,ae]);a.useEffect(()=>{j&&(He>=0||E(null))},[He,j]),a.useEffect(()=>{if(!j)return;const _=J=>{J.key==="ArrowRight"||J.key.toLowerCase()==="l"?(J.preventDefault(),Ue(1)):(J.key==="ArrowLeft"||J.key.toLowerCase()==="h")&&(J.preventDefault(),Ue(-1))};return window.addEventListener("keydown",_),()=>window.removeEventListener("keydown",_)},[j,Ue]);const tt=ge.size===1,Ft=tt?[...ge][0]:null,us=Ft?r.find(_=>_.runId===Ft||_.id===Ft)??null:null,Oe=a.useMemo(()=>tt?H.filter(_=>_.runId&&ge.has(_.runId)).map(_=>_.item):[],[tt,H,ge]),Ct=!g&&ae.length<=160,pt=(_,J)=>{const B=_.item,Q=xa(B),be=ha(Q),Fe=ne==="newest"&&J<2,st=_.bucket,Le=_.runId,Re=Le?ye.get(Le)??_e(Le):"Workspace",We=Le?Ye.get(Le)??null:null,{title:ot,isSystem:lt}=ja(B),At=dt(B.summary),_t=dt(B.description),$t=B.initiativeId?Ze.get(B.initiativeId)??null:null,Tt=pn(B)??(Le?Me.get(Le)??null:null),b=Tt?q.get(Tt)??_e(Tt):null,O=Cs(st),Z=Q==="critical"?"Error":Q==="warning"?"Needs review":Q==="positive"?"Completed":"Update",M=new Date(B.timestamp).toLocaleTimeString([],{hour:"numeric",minute:"2-digit"}),oe="group w-full rounded-xl border border-white/[0.08] bg-white/[0.02] px-3.5 py-3 text-left transition-colors hover:border-strong hover:bg-white/[0.05] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#BFFF00]/45 cv-auto",fe=e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"mt-0.5",children:e.jsx(nt,{name:B.agentName??"OrgX",hint:`${B.agentId??""} ${Re} ${B.title??""}`,size:"xs"})}),e.jsxs("div",{className:"relative min-w-0 flex-1 pl-3",children:[e.jsx("span",{className:we("absolute inset-y-0 left-0 w-[2px] rounded-full",Fe&&"pulse-soft"),style:{backgroundColor:be,boxShadow:`0 0 14px ${be}66`}}),e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:`line-clamp-2 break-words text-body font-semibold leading-snug ${lt?"text-muted":"text-bright"}`,children:ot}),e.jsxs("p",{className:"mt-0.5 text-caption text-secondary",children:[lt?"System":B.agentName??"OrgX",We?` · ${_e(We)}`:""]})]}),e.jsxs("div",{className:"flex shrink-0 flex-col items-end gap-1",children:[e.jsx("span",{className:"text-micro font-semibold tracking-[0.02em] text-muted",children:O}),e.jsx("span",{className:"text-caption text-secondary",children:M})]})]}),(At||_t)&&e.jsx("div",{className:"mt-1.5 line-clamp-2 text-caption leading-relaxed text-secondary",children:e.jsx(Bt,{mode:"inline",text:At??_t??""})}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-1.5 text-micro",children:[e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full border px-2 py-0.5 font-semibold tracking-[0.01em]",style:{borderColor:`${be}55`,backgroundColor:`${be}1A`,color:be},children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full",style:{backgroundColor:be}}),Z]}),$t?e.jsxs("span",{className:"inline-flex max-w-[220px] items-center gap-1 rounded-full border border-strong bg-white/[0.03] px-2 py-0.5 text-secondary",title:$t,children:[e.jsx(Ne,{type:"initiative",size:10,className:"opacity-85"}),e.jsx("span",{className:"truncate",children:$t})]}):b?e.jsxs("span",{className:"inline-flex max-w-[220px] items-center gap-1 rounded-full border border-strong bg-white/[0.03] px-2 py-0.5 text-secondary",title:b,children:[e.jsx(Ne,{type:"workstream",size:10,className:"opacity-90"}),e.jsx("span",{className:"truncate",children:b})]}):null,e.jsx("span",{className:"text-secondary",children:Ce(B.timestamp)})]})]})]});return Ct?e.jsx(ue.button,{type:"button",variants:aa,initial:"initial",animate:"animate",exit:"exit",transition:{duration:.25,ease:[.4,0,.2,1]},whileHover:{y:-1.5},whileTap:{scale:.995},onClick:()=>{me(1),E(B.id)},className:oe,"aria-label":`Open activity details for ${ot||Mt(B.type)}`,children:fe},B.id):e.jsx("button",{type:"button",onClick:()=>{me(1),E(B.id)},className:we(oe,"transform-gpu transition-[transform,background-color,border-color,color] hover:-translate-y-[1px] active:scale-[0.995]"),"aria-label":`Open activity details for ${ot||Mt(B.type)}`,children:fe},B.id)};return e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[tt&&Oe.length>0?e.jsx(ia,{items:Oe,session:us,agentName:((Ut=Oe[0])==null?void 0:Ut.agentName)??null,onBack:h}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"border-b border-subtle px-4 py-3.5",children:e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("h2",{className:"text-heading font-semibold text-white",children:"Activity"}),e.jsx("span",{className:"rounded-full border border-strong bg-white/[0.05] px-2 py-0.5 text-micro text-primary tabular-nums",children:De}),ze>0&&e.jsxs("span",{className:"rounded-full border border-strong bg-white/[0.03] px-2 py-0.5 text-micro text-secondary tabular-nums",children:["+",ze," hidden"]}),Se.id!=="all"&&e.jsx("span",{className:"rounded-full border border-strong bg-white/[0.02] px-2 py-0.5 text-micro text-secondary",children:Se.label}),e.jsx("span",{className:we("h-1.5 w-1.5 flex-shrink-0 rounded-full",he&&"pulse-soft"),style:{backgroundColor:C.lime},"aria-label":"Live",title:he?"New activity within the last minute":"Live activity feed"})]}),e.jsxs("div",{className:"flex flex-shrink-0 items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>G(_=>_==="newest"?"oldest":"newest"),className:"control-pill px-3 text-caption font-medium","aria-label":ne==="newest"?"Sort oldest first":"Sort newest first",children:ne==="newest"?"Newest":"Oldest"}),e.jsx("button",{type:"button",onClick:()=>T(_=>!_),"data-state":v?"active":"idle",className:"control-pill px-3 text-caption font-medium","aria-pressed":v,children:v?"Expand":"Compact"})]})]}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-2.5",children:[e.jsx("div",{className:"flex flex-wrap items-center gap-1.5",children:(se||c||y)&&e.jsxs(e.Fragment,{children:[se&&e.jsxs("button",{onClick:h,className:"chip inline-flex min-w-0 items-center gap-2","aria-label":"Clear session filter",children:[e.jsx(nt,{name:(xe==null?void 0:xe.agentName)??"OrgX",hint:o??null,size:"xs"}),e.jsxs("span",{className:"min-w-0 truncate",children:["Session",o?`: ${o}`:""]}),e.jsx("span",{className:"ml-1 inline-flex h-4 w-4 items-center justify-center rounded-full border border-strong bg-white/[0.04] text-micro text-secondary",children:"×"})]}),c&&e.jsxs("button",{onClick:N,className:"chip inline-flex min-w-0 items-center gap-2",style:{borderColor:"rgba(191,255,0,0.28)",color:"#D8FFA1"},"aria-label":"Clear workstream filter",children:[e.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center rounded-full border border-strong bg-white/[0.04] text-micro",children:"↳"}),e.jsxs("span",{className:"min-w-0 truncate",children:["Workstream",l?`: ${l}`:""]}),e.jsx("span",{className:"ml-1 inline-flex h-4 w-4 items-center justify-center rounded-full border border-strong bg-white/[0.04] text-micro text-secondary",children:"×"})]}),y&&e.jsxs("button",{onClick:w,className:"chip inline-flex min-w-0 items-center gap-2",style:{borderColor:"rgba(10,212,196,0.3)",color:"#0AD4C4"},"aria-label":"Clear agent filter",children:[e.jsx(nt,{name:y,hint:y,size:"xs"}),e.jsxs("span",{className:"min-w-0 truncate",children:["Agent: ",y]}),e.jsx("span",{className:"ml-1 inline-flex h-4 w-4 items-center justify-center rounded-full border border-strong bg-white/[0.04] text-micro text-secondary",children:"×"})]})]})}),e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:justify-end",children:[e.jsxs("div",{className:"relative min-w-0 flex-1 sm:max-w-[340px]",children:[e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"pointer-events-none absolute left-2.5 top-1/2 -translate-y-1/2 text-muted",children:[e.jsx("circle",{cx:"11",cy:"11",r:"7"}),e.jsx("path",{d:"m20 20-3.5-3.5"})]}),e.jsx("input",{value:D,onChange:_=>A(_.target.value),placeholder:"Search activity...",className:"w-full rounded-lg border border-white/[0.08] bg-white/[0.03] py-2 pl-9 pr-2 text-body text-primary placeholder:text-muted transition-colors focus:border-[#BFFF00]/30 focus:outline-none","aria-label":"Search activity"})]}),e.jsx("div",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.08] bg-white/[0.02] p-0.5",role:"group","aria-label":"Activity filters",children:Object.keys(Gt).map(_=>{const J=f===_;return e.jsx("button",{type:"button",onClick:()=>k(_),"aria-pressed":J,className:we("rounded-full px-3 py-1.5 text-micro font-semibold transition-colors",J?"border border-lime/25 bg-lime/[0.10] text-[#E1FFB2]":"border border-transparent text-secondary hover:bg-white/[0.08] hover:text-bright"),children:Gt[_]},_)})})]})]})]})}),e.jsxs("div",{ref:W,className:"flex-1 overflow-y-auto px-4 py-3",children:[ae.length===0&&e.jsxs("div",{className:"flex flex-col items-center gap-2.5 rounded-xl border border-subtle bg-white/[0.02] px-3 py-6 text-center",children:[e.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-faint",children:e.jsx("polyline",{points:"22 12 18 12 15 21 9 3 6 12 2 12"})}),e.jsx("p",{className:"text-body text-secondary",children:se?`No ${Gt[f].toLowerCase()} for the selected session.`:c?`No ${Gt[f].toLowerCase()} for the selected workstream.`:"No matching activity right now."}),(se||c)&&e.jsx("button",{onClick:se?h:N,className:"rounded-md border border-strong bg-white/[0.04] px-3 py-1.5 text-caption text-primary transition-colors hover:bg-white/[0.08]",children:se?"Show all sessions":"Show all workstreams"})]}),ae.length>0&&e.jsxs("div",{className:"space-y-4",children:[ds.map(_=>{const J=v?_.clusters.slice(0,4):_.clusters;return e.jsxs("section",{children:[e.jsx("h3",{className:"mb-2.5 border-b border-subtle pb-1.5 text-caption font-semibold tracking-[0.01em] text-muted",children:_.label}),Ct?e.jsx(qe,{mode:"popLayout",children:e.jsx("div",{className:"space-y-2",children:J.map((B,Q)=>{const be=ee.has(B.key);return B.count===1?pt(B.representative,Q):e.jsxs("div",{children:[pt(B.representative,Q),e.jsxs("button",{type:"button",onClick:Fe=>{Fe.stopPropagation(),zt(B.key)},className:"mt-1 ml-8 inline-flex items-center gap-1.5 rounded-full border border-white/[0.1] bg-white/[0.03] px-2.5 py-1 text-micro text-secondary transition-colors hover:bg-white/[0.06] hover:text-primary",children:[e.jsxs("span",{className:"font-semibold",children:["×",B.count]}),e.jsx("span",{className:"text-muted",children:"·"}),e.jsxs("span",{children:["first seen ",Ce(B.firstTimestamp)]}),e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:we("transition-transform",be?"rotate-0":"-rotate-90"),children:e.jsx("path",{d:"m6 9 6 6 6-6"})})]}),be&&e.jsx("div",{className:"ml-8 mt-1 space-y-1.5 border-l border-subtle pl-3",children:B.allItems.slice(1).map((Fe,st)=>pt(Fe,Q+st+1))})]},B.key)})})}):e.jsx("div",{className:"space-y-2",children:J.map((B,Q)=>{const be=ee.has(B.key);return B.count===1?pt(B.representative,Q):e.jsxs("div",{children:[pt(B.representative,Q),e.jsxs("button",{type:"button",onClick:Fe=>{Fe.stopPropagation(),zt(B.key)},className:"mt-1 ml-8 inline-flex items-center gap-1.5 rounded-full border border-white/[0.1] bg-white/[0.03] px-2.5 py-1 text-micro text-secondary transition-colors hover:bg-white/[0.06] hover:text-primary",children:[e.jsxs("span",{className:"font-semibold",children:["×",B.count]}),e.jsx("span",{className:"text-muted",children:"·"}),e.jsxs("span",{children:["first seen ",Ce(B.firstTimestamp)]}),e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:we("transition-transform",be?"rotate-0":"-rotate-90"),children:e.jsx("path",{d:"m6 9 6 6 6-6"})})]}),be&&e.jsx("div",{className:"ml-8 mt-1 space-y-1.5 border-l border-subtle pl-3",children:B.allItems.slice(1).map((Fe,st)=>pt(Fe,Q+st+1))})]},B.key)})}),v&&_.clusters.length>J.length&&e.jsxs("p",{className:"mt-1.5 text-caption text-muted",children:["+",_.clusters.length-J.length," more"]})]},_.key)}),ze>0&&e.jsxs("p",{className:"rounded-xl border border-subtle bg-white/[0.02] px-3 py-2 text-caption text-secondary",children:["Showing ",ae.length,"/",De," matched events (load more to see older)."]}),e.jsx("div",{ref:ke,className:"h-6"}),(x||p)&&e.jsx("div",{className:"flex items-center justify-center",children:e.jsx("button",{type:"button",onClick:()=>d==null?void 0:d(),disabled:!x||p,className:"rounded-full border border-strong bg-white/[0.03] px-4 py-2 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:p?"Loading older…":"Load older"})})]})]})]}),e.jsx(Ge,{open:U!==null,onClose:St,maxWidth:"max-w-3xl",children:U&&e.jsxs("div",{className:"relative flex h-[100dvh] w-full min-h-0 flex-col sm:h-[86vh] sm:max-h-[86vh]",children:[e.jsx("div",{className:"absolute inset-x-0 top-0 h-20 bg-gradient-to-b from-lime/10 via-cyan/5 to-transparent"}),e.jsxs("div",{className:"relative z-10 flex items-center justify-between border-b border-subtle px-5 py-3 sm:px-6",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("span",{className:"h-2.5 w-2.5 flex-shrink-0 rounded-full",style:{backgroundColor:Yt(U.bucket),boxShadow:`0 0 12px ${Yt(U.bucket)}55`}}),e.jsxs("span",{className:"text-caption text-secondary",children:[Cs(U.bucket)," · ",He+1,"/",ae.length]}),u&&e.jsx("span",{className:"rounded-full border border-strong bg-white/[0.04] px-2 py-0.5 text-micro font-semibold tracking-[0.02em] text-secondary",children:u})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[U.runId&&F&&e.jsx("button",{type:"button",onClick:()=>{F(U.runId),St()},className:"rounded-full border border-lime/25 bg-lime/10 px-3 py-1 text-caption font-semibold text-lime transition hover:bg-lime/20",children:"Focus session"}),e.jsx("button",{type:"button",onClick:()=>Ue(-1),className:"inline-flex h-8 w-8 items-center justify-center rounded-full border border-strong bg-white/[0.04] text-primary transition hover:bg-white/[0.1]","aria-label":"Previous activity item",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"m15 18-6-6 6-6"})})}),e.jsx("button",{type:"button",onClick:()=>Ue(1),className:"inline-flex h-8 w-8 items-center justify-center rounded-full border border-strong bg-white/[0.04] text-primary transition hover:bg-white/[0.1]","aria-label":"Next activity item",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"m9 18 6-6-6-6"})})}),e.jsxs("div",{className:"relative",children:[e.jsx("button",{type:"button",onClick:()=>z(_=>!_),className:"inline-flex h-8 w-8 items-center justify-center rounded-full border border-strong bg-white/[0.04] text-secondary transition hover:bg-white/[0.1] hover:text-primary","aria-label":"More actions",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"currentColor",children:[e.jsx("circle",{cx:"12",cy:"5",r:"1.5"}),e.jsx("circle",{cx:"12",cy:"12",r:"1.5"}),e.jsx("circle",{cx:"12",cy:"19",r:"1.5"})]})}),L&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-30",onClick:()=>z(!1)}),e.jsxs("div",{className:"absolute right-0 top-full z-40 mt-1 min-w-[160px] rounded-lg border border-strong bg-[#0d0f16] py-1 shadow-xl",children:[U.runId&&e.jsx("button",{type:"button",onClick:()=>{et("Run id",U.runId??""),z(!1)},className:"flex w-full items-center gap-2 px-3 py-1.5 text-caption text-secondary transition-colors hover:bg-white/[0.06] hover:text-primary",children:"Copy run ID"}),bt(U.item).agentId&&e.jsx("button",{type:"button",onClick:()=>{et("Agent id",bt(U.item).agentId??""),z(!1)},className:"flex w-full items-center gap-2 px-3 py-1.5 text-caption text-secondary transition-colors hover:bg-white/[0.06] hover:text-primary",children:"Copy agent ID"}),e.jsx("button",{type:"button",onClick:()=>{et("Event id",U.item.id),z(!1)},className:"flex w-full items-center gap-2 px-3 py-1.5 text-caption text-secondary transition-colors hover:bg-white/[0.06] hover:text-primary",children:"Copy event ID"})]})]})]}),e.jsx("button",{type:"button",onClick:St,className:"inline-flex h-8 w-8 items-center justify-center rounded-full border border-strong bg-white/[0.04] text-secondary transition hover:bg-white/[0.1] hover:text-primary","aria-label":"Close activity detail",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 6L6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})})]})]}),e.jsx("div",{className:"relative min-h-0 flex-1 overflow-x-hidden overflow-y-auto px-5 pb-5 pt-4 sm:px-6",children:e.jsx(qe,{mode:"wait",custom:R,children:e.jsx(ue.section,{custom:R,initial:{opacity:0,x:R*44,scale:.985},animate:{opacity:1,x:0,scale:1},exit:{opacity:0,x:R*-32,scale:.985},transition:{duration:.28,ease:[.16,1,.3,1]},className:"min-h-full w-full overscroll-contain",children:e.jsxs("div",{className:"space-y-4 pb-1",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-title font-semibold tracking-[-0.02em] text-white whitespace-pre-wrap break-words",children:P||Na(U.item,K)||_e(U.item.title||Mt(U.item.type))}),e.jsxs("p",{className:"mt-1 flex flex-wrap items-center gap-x-2 text-body text-secondary",children:[new Date(U.item.timestamp).toLocaleString()," · ",Ce(U.item.timestamp),$==="llm"&&e.jsx("span",{className:"text-muted",children:"· AI title"})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-1.5 text-caption",children:[e.jsx("span",{className:"rounded-full border px-2 py-0.5 font-semibold tracking-[0.02em]",style:{borderColor:`${Yt(U.bucket)}55`,color:Yt(U.bucket)},children:Cs(U.bucket)}),e.jsx("span",{className:"rounded-full border border-strong px-2 py-0.5 text-secondary",children:Mt(U.item.type)}),bt(U.item).agentName&&e.jsxs("span",{className:"inline-flex items-center gap-1.5 rounded-full border border-strong px-1.5 py-0.5 text-secondary",children:[e.jsx(nt,{name:bt(U.item).agentName??"Agent",hint:`${bt(U.item).agentId??""} ${U.item.title??""}`,size:"xs"}),e.jsx("span",{children:bt(U.item).agentName})]}),U.runId&&e.jsx("span",{className:"rounded-full border border-strong px-2 py-0.5 text-secondary",children:ye.get(U.runId)??_e(U.runId)})]}),de&&e.jsxs("div",{className:"rounded-xl border border-lime/20 bg-lime/10 p-3",children:[e.jsx("p",{className:"text-caption font-semibold tracking-[0.02em] text-lime/80",children:"Autopilot slice"}),e.jsxs("div",{className:"mt-2 grid grid-cols-1 gap-2 sm:grid-cols-2",children:[e.jsxs("div",{className:"rounded-lg border border-white/[0.10] bg-black/20 px-3 py-2",children:[e.jsx("div",{className:"text-micro font-semibold tracking-[0.02em] text-secondary",children:"Dispatcher"}),e.jsx("div",{className:"mt-1 text-body text-primary",children:"OpenClaw"})]}),e.jsxs("div",{className:"rounded-lg border border-white/[0.10] bg-black/20 px-3 py-2",children:[e.jsx("div",{className:"text-micro font-semibold tracking-[0.02em] text-secondary",children:"Executor"}),e.jsxs("div",{className:"mt-1 text-body text-primary",children:[de.agentName??"Codex",de.agentId?` · ${de.agentId}`:""]})]}),e.jsxs("div",{className:"rounded-lg border border-white/[0.10] bg-black/20 px-3 py-2",children:[e.jsx("div",{className:"text-micro font-semibold tracking-[0.02em] text-secondary",children:"Workstream"}),e.jsx("div",{className:"mt-1 text-body text-primary",children:de.workstreamTitle??de.workstreamId??"—"})]}),e.jsxs("div",{className:"rounded-lg border border-white/[0.10] bg-black/20 px-3 py-2",children:[e.jsx("div",{className:"text-micro font-semibold tracking-[0.02em] text-secondary",children:"Policy"}),e.jsxs("div",{className:"mt-1 text-body text-primary",children:[de.domain??"—",de.requiredSkills.length>0?` · ${de.requiredSkills.join(", ")}`:""]})]})]}),e.jsxs("div",{className:"mt-2 flex flex-wrap gap-2 text-caption text-secondary",children:[e.jsx("span",{className:"rounded-full border border-strong bg-black/20 px-2 py-0.5",children:de.event}),de.parsedStatus&&e.jsxs("span",{className:"rounded-full border border-strong bg-black/20 px-2 py-0.5",children:["status: ",de.parsedStatus]}),typeof de.hasOutput=="boolean"&&e.jsxs("span",{className:"rounded-full border border-strong bg-black/20 px-2 py-0.5",children:["output: ",de.hasOutput?"yes":"no"]}),typeof de.artifacts=="number"&&e.jsxs("span",{className:"rounded-full border border-strong bg-black/20 px-2 py-0.5",children:["artifacts: ",de.artifacts]}),typeof de.decisions=="number"&&e.jsxs("span",{className:"rounded-full border border-strong bg-black/20 px-2 py-0.5",children:["decisions: ",de.decisions]}),typeof de.statusUpdatesApplied=="number"&&e.jsxs("span",{className:"rounded-full border border-strong bg-black/20 px-2 py-0.5",children:["status updates: ",de.statusUpdatesApplied]}),typeof de.statusUpdatesBuffered=="number"&&de.statusUpdatesBuffered>0&&e.jsxs("span",{className:"rounded-full border border-amber-400/25 bg-amber-500/10 px-2 py-0.5 text-amber-100/80",children:["buffered: ",de.statusUpdatesBuffered]})]}),(de.logPath||de.outputPath)&&e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[de.logPath&&e.jsx("button",{type:"button",onClick:()=>void et("Log path",de.logPath??""),className:"rounded-full border border-strong bg-white/[0.04] px-3 py-1 text-caption text-primary transition hover:bg-white/[0.1]",children:"Copy log path"}),de.outputPath&&e.jsx("button",{type:"button",onClick:()=>void et("Output path",de.outputPath??""),className:"rounded-full border border-strong bg-white/[0.04] px-3 py-1 text-caption text-primary transition hover:bg-white/[0.1]",children:"Copy output path"})]}),de.error&&e.jsx("div",{className:"mt-3 rounded-lg border border-red-400/20 bg-red-500/10 px-3 py-2 text-body text-red-100/80",children:de.error})]}),je&&e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.03] p-3",children:[e.jsx("p",{className:"text-caption font-semibold tracking-[0.02em] text-secondary",children:"Provenance"}),e.jsxs("div",{className:"mt-2 grid grid-cols-1 gap-2 sm:grid-cols-2",children:[je.domain&&e.jsxs("div",{className:"rounded-lg border border-white/[0.10] bg-black/20 px-3 py-2",children:[e.jsx("div",{className:"text-micro font-semibold tracking-[0.02em] text-secondary",children:"Domain"}),e.jsx("div",{className:"mt-1 text-body text-primary",children:_e(je.domain)})]}),(je.provider||je.model)&&e.jsxs("div",{className:"rounded-lg border border-white/[0.10] bg-black/20 px-3 py-2",children:[e.jsx("div",{className:"text-micro font-semibold tracking-[0.02em] text-secondary",children:"Model"}),e.jsxs("div",{className:"mt-1 text-body text-primary",children:[je.provider?`${_e(je.provider)} · `:"",je.model?Rt(je.model):"—"]})]}),je.modelTier&&e.jsxs("div",{className:"rounded-lg border border-white/[0.10] bg-black/20 px-3 py-2",children:[e.jsx("div",{className:"text-micro font-semibold tracking-[0.02em] text-secondary",children:"Model tier"}),e.jsx("div",{className:"mt-1 text-body text-primary",children:_e(je.modelTier)})]}),je.pluginVersion&&e.jsxs("div",{className:"rounded-lg border border-white/[0.10] bg-black/20 px-3 py-2",children:[e.jsx("div",{className:"text-micro font-semibold tracking-[0.02em] text-secondary",children:"Plugin"}),e.jsxs("div",{className:"mt-1 text-body text-primary",children:["v",je.pluginVersion]})]}),je.skillPack&&e.jsxs("div",{className:"rounded-lg border border-white/[0.10] bg-black/20 px-3 py-2 sm:col-span-2",children:[e.jsx("div",{className:"text-micro font-semibold tracking-[0.02em] text-secondary",children:"Skill pack"}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2 text-body text-primary",children:[e.jsxs("span",{children:[je.skillPack.name??"—",je.skillPack.version?`@${je.skillPack.version}`:"",je.skillPack.source?` · ${je.skillPack.source}`:""]}),je.skillPack.checksum&&e.jsxs("button",{type:"button",onClick:()=>{var _;return void et("Skill pack checksum",((_=je.skillPack)==null?void 0:_.checksum)??"")},className:"rounded-full border border-strong bg-white/[0.04] px-2.5 py-1 text-caption text-primary transition hover:bg-white/[0.1]",children:["sha ",je.skillPack.checksum.slice(0,12),"…"]})]})]}),je.kickoffContextHash&&e.jsxs("div",{className:"rounded-lg border border-white/[0.10] bg-black/20 px-3 py-2 sm:col-span-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"text-micro font-semibold tracking-[0.02em] text-secondary",children:"Kickoff context"}),e.jsx("button",{type:"button",onClick:()=>void et("Kickoff context hash",je.kickoffContextHash??""),className:"rounded-full border border-strong bg-white/[0.04] px-2.5 py-1 text-caption text-primary transition hover:bg-white/[0.1]",children:"Copy hash"})]}),e.jsxs("div",{className:"mt-1 text-body text-primary",children:[je.kickoffContextSource?`${je.kickoffContextSource} · `:"",e.jsx("span",{className:"font-mono text-body text-primary",children:je.kickoffContextHash})]})]}),je.requiredSkills.length>0&&e.jsxs("div",{className:"rounded-lg border border-white/[0.10] bg-black/20 px-3 py-2 sm:col-span-2",children:[e.jsx("div",{className:"text-micro font-semibold tracking-[0.02em] text-secondary",children:"Required skills"}),e.jsx("div",{className:"mt-1 flex flex-wrap gap-1.5",children:je.requiredSkills.map(_=>e.jsx("span",{className:"rounded-full border border-strong bg-white/[0.03] px-2 py-0.5 text-caption text-secondary",children:_},_))})]})]})]}),Nt&&e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.03] p-3",children:[e.jsx("p",{className:"text-caption font-semibold tracking-[0.02em] text-secondary",children:"Summary"}),le==="missing"&&e.jsx("p",{className:"mt-1 text-caption text-amber-200/75",children:"Full local turn transcript was unavailable; showing the event summary payload."}),e.jsx(Bt,{mode:"block",text:Nt,className:"mt-1.5 text-heading leading-relaxed text-primary"})]}),dt(U.item.description)&&e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-black/25 p-3",children:[e.jsx("p",{className:"text-caption font-semibold tracking-[0.02em] text-secondary",children:"Details"}),e.jsx(Bt,{mode:"block",text:dt(U.item.description)??"",className:"mt-1.5 text-body leading-relaxed text-primary"})]}),at&&e.jsxs("div",{className:"rounded-xl border border-cyan-400/20 bg-cyan-500/[0.06] p-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-caption font-semibold tracking-[0.02em] text-cyan-100/85",children:"Artifact output"}),e.jsxs("div",{className:"inline-flex rounded-full border border-strong bg-black/30 p-0.5 text-caption",children:[e.jsx("button",{type:"button",onClick:()=>X("structured"),"aria-pressed":re==="structured",className:`rounded-full px-2.5 py-0.5 transition-colors ${re==="structured"?"bg-white/[0.12] text-white":"text-secondary hover:text-primary"}`,children:"Structured"}),e.jsx("button",{type:"button",onClick:()=>X("json"),"aria-pressed":re==="json",className:`rounded-full px-2.5 py-0.5 transition-colors ${re==="json"?"bg-white/[0.12] text-white":"text-secondary hover:text-primary"}`,children:"JSON"})]})]}),e.jsxs("p",{className:"mt-1 text-micro text-cyan-100/55",children:["Source: ",at.source]}),e.jsx("div",{className:"mt-2",children:re==="structured"?Kn(at.value):e.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap font-mono text-caption leading-relaxed text-primary",children:JSON.stringify(at.value,null,2)})})]}),kt&&e.jsxs("details",{className:"rounded-xl border border-white/[0.08] bg-black/35 p-3",children:[e.jsx("summary",{className:"cursor-pointer select-none text-caption font-semibold tracking-[0.02em] text-secondary",children:"Raw metadata"}),e.jsx("pre",{className:"mt-2 overflow-x-auto whitespace-pre-wrap font-mono text-caption leading-relaxed text-secondary",children:kt})]})]})},U.item.id)})}),e.jsx("div",{className:"border-t border-subtle px-5 py-2.5 text-caption text-muted sm:px-6",children:"Keyboard: ← previous · → next · Esc close"})]})})]})});function Ca(t){const s=Date.parse(t);if(!Number.isFinite(s))return null;const r=Date.now()-s,n=r<0,i=Math.abs(r),o=Math.round(i/6e4);if(o<1)return n?"soon":"just now";if(o<60)return n?`in ${o}m`:`${o}m ago`;const c=Math.round(i/36e5);if(c<48)return n?`in ${c}h`:`${c}h ago`;const l=Math.round(i/864e5);return l<30?n?`in ${l}d`:`${l}d ago`:new Date(s).toLocaleDateString()}async function xn(t,s){const r=await fetch(t,s);if(!r.ok){const n=await r.json().catch(()=>null),i=typeof(n==null?void 0:n.error)=="string"&&n.error||typeof(n==null?void 0:n.message)=="string"&&n.message||`Request failed (${r.status})`;throw new Error(i)}return await r.json()}function Aa(t){const{entityType:s,entityId:r,authToken:n,embedMode:i,className:o}=t,[c,l]=a.useState(!0),[y,m]=a.useState(!1),[x,p]=a.useState(null),[d,h]=a.useState([]),[N,w]=a.useState(""),F=a.useMemo(()=>{const v=encodeURIComponent(s),T=encodeURIComponent(r);return`/orgx/api/entities/${v}/${T}/comments`},[s,r]),g=a.useCallback(async()=>{l(!0),p(null);try{const v=await xn(F,{method:"GET",headers:Be({authToken:n,embedMode:i})});h(Array.isArray(v.comments)?v.comments:[])}catch(v){p(v instanceof Error?v.message:String(v))}finally{l(!1)}},[n,i,F]);a.useEffect(()=>{g()},[g]);const f=a.useCallback(async()=>{const v=N.trim();if(v){m(!0),p(null);try{await xn(F,{method:"POST",headers:Be({authToken:n,embedMode:i,contentTypeJson:!0}),body:JSON.stringify({body:v,commentType:"note",severity:"info",tags:[]})}),w(""),await g()}catch(T){p(T instanceof Error?T.message:String(T))}finally{m(!1)}}},[n,N,i,F,g]),k=a.useCallback(v=>{v.key==="Enter"&&(!v.metaKey&&!v.ctrlKey||(v.preventDefault(),f()))},[f]);return e.jsxs("div",{className:o,children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("textarea",{value:N,onChange:v=>w(v.target.value),onKeyDown:k,placeholder:"Leave a note for humans or agents...",className:"min-h-[96px] w-full resize-y rounded-xl border border-white/[0.10] bg-white/[0.03] px-4 py-3 text-body text-bright outline-none placeholder:text-faint focus:border-white/20 focus:bg-white/[0.05] transition-colors"}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx("p",{className:"text-caption text-muted",children:"Visible to agents and collaborators. Tip: Cmd/Ctrl+Enter to post."}),e.jsx("button",{type:"button",onClick:f,disabled:y||N.trim().length===0,className:"inline-flex items-center justify-center rounded-full border border-strong bg-white/[0.05] px-3.5 py-1.5 text-caption font-semibold tracking-wide text-primary transition-colors hover:bg-white/[0.09] disabled:opacity-50 disabled:hover:bg-white/[0.05]",children:y?"Saving…":"Post note"})]})]}),x?e.jsx("div",{className:"mt-3 rounded-xl border border-red-500/20 bg-red-500/10 px-3.5 py-2 text-body text-red-200",children:x}):null,c?e.jsx("div",{className:"mt-3 text-body text-muted",children:"Loading notes…"}):d.length===0?e.jsx("div",{className:"mt-3 text-body text-muted",children:"No notes yet."}):e.jsx("div",{className:"mt-3 space-y-3",children:d.map(v=>{const T=v.created_at?Ca(v.created_at):null,D=v.author_name??(v.author_type==="agent"?v.author_id:"Unknown"),A=v.comment_type??"note",ee=typeof v.severity=="string"?v.severity:"info";return e.jsxs("div",{className:"rounded-2xl border border-white/[0.10] bg-white/[0.02] px-4 py-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"text-body font-semibold text-bright",children:D}),e.jsx("span",{className:"rounded-full border border-strong bg-white/[0.06] px-2 py-0.5 text-micro uppercase tracking-[0.08em] text-secondary",children:v.author_type}),e.jsx("span",{className:"rounded-full border border-strong px-2 py-0.5 text-micro uppercase tracking-[0.08em] text-secondary",children:A}),ee!=="info"?e.jsx("span",{className:"rounded-full border border-strong px-2 py-0.5 text-micro uppercase tracking-[0.08em] text-secondary",children:ee}):null]}),T?e.jsx("span",{className:"text-caption text-muted",title:jt(v.created_at),children:T}):null]}),e.jsx("p",{className:"mt-2 whitespace-pre-wrap text-body leading-relaxed text-primary",children:v.body})]},v.id)})})]})}function Ia(t){try{return JSON.stringify(t,null,2)}catch{return null}}function Ea({open:t,decision:s,onClose:r,onApprove:n}){const[i,o]=a.useState(!1),[c,l]=a.useState(null),[y,m]=a.useState(!0),x=(s==null?void 0:s.requestedAt)??null,p=(s==null?void 0:s.updatedAt)??null,d=(s==null?void 0:s.metadata)??{},h=a.useMemo(()=>{const k=d.options??d.option??d.actions??null;return Array.isArray(k)?k.map(T=>{if(typeof T=="string")return{label:T,action:T};if(!T||typeof T!="object")return null;const D=T,A=typeof D.label=="string"?D.label:null,ee=typeof D.action=="string"?D.action:null,ie=A??ee??null;return ie?{label:A??ie,action:ee??ie}:null}).filter(Boolean):[]},[d]),N=a.useMemo(()=>{const k=((s==null?void 0:s.context)??"").trim();if(k)return k;const v=(typeof d.summary=="string"?d.summary:null)??(typeof d.description=="string"?d.description:null)??"";return String(v??"").trim()},[s==null?void 0:s.context,d]),w=async()=>{if(!s)return;const k=Ia({decision:s,metadata:d});if(!k){l("Unable to copy details.");return}try{await navigator.clipboard.writeText(k),l("Copied decision JSON.")}catch{l("Copy failed.")}},F=async()=>{if(!(!s||!n||i)){l(null),o(!0);try{const k=await n(s.id);k.failed>0?l(`Approval failed for ${k.failed} item${k.failed===1?"":"s"}.`):l("Decision approved.")}catch(k){l(k instanceof Error?k.message:"Decision approval failed.")}finally{o(!1)}}};if(!t||!s)return null;const g=(s.status??"pending").toLowerCase(),f=g.includes("approved")||g.includes("resolved")?{border:`${C.teal}40`,bg:`${C.teal}14`,text:"#8ff7ec"}:g.includes("rejected")?{border:`${C.red}45`,bg:`${C.red}12`,text:"#fecaca"}:{border:`${C.amber}45`,bg:`${C.amber}12`,text:"#ffe3a1"};return e.jsx(Ge,{open:t,onClose:r,maxWidth:"max-w-3xl",children:e.jsxs("div",{className:"flex h-full min-h-0 w-full flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-subtle px-5 py-3 sm:px-6",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ne,{type:"decision",size:14}),e.jsx("h2",{className:"truncate text-heading font-semibold text-white",children:s.title||"Decision"}),e.jsx("span",{className:"rounded-full border px-2 py-0.5 text-micro uppercase tracking-[0.12em]",style:{borderColor:f.border,backgroundColor:f.bg,color:f.text},children:g})]}),e.jsxs("p",{className:"mt-0.5 text-body text-secondary",children:[s.agentName?`${s.agentName} · `:"","waiting ",s.waitingMinutes,"m",x?` · requested ${Ce(x)}`:"",p?` · updated ${Ce(p)}`:""]})]}),e.jsx("button",{type:"button",onClick:r,"aria-label":"Close decision detail",className:"inline-flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-full border border-strong bg-white/[0.03] text-primary transition-colors hover:bg-white/[0.08] hover:text-white",children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 6L6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})})]}),e.jsxs("div",{className:"min-h-0 flex-1 space-y-4 overflow-y-auto px-5 py-4 sm:px-6",children:[N?e.jsxs("div",{className:"rounded-2xl border border-white/[0.08] bg-white/[0.02] px-4 py-3",children:[e.jsx("p",{className:"mb-2 text-micro uppercase tracking-[0.12em] text-muted",children:"Context"}),e.jsx(Bt,{text:N,mode:"block"})]}):e.jsx("div",{className:"rounded-2xl border border-white/[0.08] bg-white/[0.02] px-4 py-3 text-body text-secondary",children:"No context provided for this decision."}),h.length>0&&e.jsxs("div",{className:"rounded-2xl border border-white/[0.08] bg-white/[0.02] px-4 py-3",children:[e.jsx("p",{className:"mb-2 text-micro uppercase tracking-[0.12em] text-muted",children:"Options"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:h.map(k=>e.jsx("span",{className:"inline-flex items-center rounded-full border border-strong bg-white/[0.03] px-3 py-1 text-caption text-primary",title:k.action,children:k.label},`${k.label}:${k.action}`))})]}),e.jsxs("div",{className:"rounded-2xl border border-white/[0.08] bg-white/[0.02] px-4 py-3",children:[e.jsx("p",{className:"mb-2 text-micro uppercase tracking-[0.12em] text-muted",children:"Actions"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",onClick:F,disabled:!n||i,"data-modal-autofocus":"true",className:"rounded-lg px-3 py-1.5 text-caption font-semibold transition-colors",style:{backgroundColor:!n||i?"rgba(255,255,255,0.08)":C.lime,color:!n||i?"rgba(255,255,255,0.45)":"#000"},children:i?"Approving…":"Approve"}),e.jsx("button",{type:"button",onClick:w,className:"rounded-lg border border-strong bg-white/[0.03] px-3 py-1.5 text-caption font-medium text-primary transition-colors hover:bg-white/[0.08] hover:text-white",children:"Copy JSON"}),c&&e.jsx("span",{className:"text-caption text-secondary",children:c})]})]}),e.jsxs("div",{className:"rounded-2xl border border-white/[0.08] bg-white/[0.02] px-4 py-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-micro font-semibold uppercase tracking-[0.14em] text-muted",children:"Notes"}),e.jsx("p",{className:"text-caption text-muted",children:"Commentary thread for humans and agents on this decision."})]}),e.jsx("button",{type:"button",onClick:()=>m(k=>!k),className:"inline-flex items-center justify-center rounded-full border border-strong bg-white/[0.05] px-3 py-1.5 text-caption font-semibold tracking-wide text-primary transition-colors hover:bg-white/[0.09]",children:y?"Hide":"Show"})]}),y?e.jsx("div",{className:"mt-3 border-t border-subtle pt-3",children:e.jsx(Aa,{entityType:"decision",entityId:s.id})}):null]})]})]})})}const As=40;function hn(t){return t>=15?{border:C.red,glow:`0 0 16px ${C.red}20`}:t>=5?{border:C.amber,glow:`0 0 12px ${C.amber}18`}:{border:C.teal,glow:"none"}}const Vn=a.memo(function({decisions:s,onApproveDecision:r,onApproveAll:n}){const i=In(),[o,c]=a.useState(!1),[l,y]=a.useState(new Set),[m,x]=a.useState(new Set),[p,d]=a.useState(null),[h,N]=a.useState(As),[w,F]=a.useState(null),g=a.useMemo(()=>[...s].sort((u,I)=>{if(u.waitingMinutes!==I.waitingMinutes)return I.waitingMinutes-u.waitingMinutes;const L=Date.parse(u.requestedAt??u.updatedAt??""),z=Date.parse(I.requestedAt??I.updatedAt??""),R=Number.isFinite(L)?L:0;return(Number.isFinite(z)?z:0)-R}),[s]);a.useEffect(()=>{x(u=>{const I=new Set(g.map(z=>z.id)),L=new Set;for(const z of u)I.has(z)&&L.add(z);return L})},[g]);const f=m.size,k=a.useMemo(()=>g.slice(0,h),[g,h]),v=a.useMemo(()=>{if(k.length===0)return!1;for(const u of k)if(!m.has(u.id))return!1;return!0},[m,k]),T=a.useMemo(()=>w?g.find(u=>u.id===w)??null:null,[w,g]),D=async u=>{const I=await r(u);return I.failed===0&&I.updated>0&&F(null),I};a.useEffect(()=>{N(u=>g.length===0?0:Math.min(Math.max(As,u),g.length))},[g.length]);const A=u=>{x(I=>{const L=new Set(I);return L.has(u)?L.delete(u):L.add(u),L})},ee=()=>{x(u=>{if(k.length===0)return u;const I=new Set(u),L=v;for(const z of k)L?I.delete(z.id):I.add(z.id);return I})},ie=async()=>{if(!(g.length===0||o)){d(null),c(!0);try{const u=await n();u.failed>0?d(`Approved ${u.updated}; ${u.failed} failed.`):u.updated>0?d(`Approved ${u.updated} decision${u.updated===1?"":"s"}.`):d("No decisions were updated."),x(new Set)}catch(u){d(u instanceof Error?u.message:"Bulk approval failed.")}finally{c(!1)}}},ne=async()=>{if(f===0||o)return;d(null),c(!0);let u=0,I=0;try{const L=g.map(z=>z.id).filter(z=>m.has(z));for(const z of L){y(R=>new Set(R).add(z));try{const R=await r(z);u+=R.updated,I+=R.failed}catch{I+=1}finally{y(R=>{const me=new Set(R);return me.delete(z),me})}}I>0?d(`Approved ${u}; ${I} failed.`):d(`Approved ${u} selected decision${u===1?"":"s"}.`),x(new Set)}finally{c(!1)}},G=async u=>{if(!(l.has(u)||o)){d(null),y(I=>{const L=new Set(I);return L.add(u),L});try{const I=await r(u);I.failed>0?d(`Approval failed for ${I.failed} decision.`):I.updated>0&&d("Decision approved.")}catch(I){d(I instanceof Error?I.message:"Decision approval failed.")}finally{y(I=>{const L=new Set(I);return L.delete(u),L}),x(I=>{if(!I.has(u))return I;const L=new Set(I);return L.delete(u),L})}}},te=p!==null&&!p.toLowerCase().includes("fail"),pe=!i&&k.length<=32,j=g.length>0&&!o,E=f>0&&!o;return e.jsxs(vt,{className:"flex h-full min-h-0 flex-col card-enter",children:[e.jsx(Ea,{open:w!==null,decision:T,onClose:()=>F(null),onApprove:D}),e.jsxs("div",{className:"space-y-2 border-b border-subtle px-4 py-3.5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("h2",{className:"inline-flex items-center gap-2 text-heading font-semibold text-white",children:[e.jsx(Ne,{type:"decision",size:14}),"Decisions"]}),e.jsx("p",{className:"hidden text-body text-secondary sm:block",children:"Select multiple items to bulk review and approve"})]}),e.jsx("button",{onClick:ie,disabled:!j,"data-state":j?"active":"idle",className:"control-pill flex-shrink-0 px-3 text-caption font-semibold disabled:opacity-45",children:o?"Approving…":e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"hidden sm:inline",children:"Approve all"}),e.jsx("span",{className:"sm:hidden",children:"Approve"}),e.jsx("span",{className:"inline-flex h-5 shrink-0 items-center rounded-full border border-strong bg-white/[0.04] px-2 text-micro text-primary tabular-nums",children:g.length})]})})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{onClick:ee,disabled:g.length===0||o,className:"control-pill px-3 text-caption font-semibold disabled:opacity-45",children:v?"Clear all":"Select all"}),e.jsx("button",{onClick:ne,disabled:!E,"data-state":E?"active":"idle",className:"control-pill px-3 text-caption font-semibold disabled:opacity-45",children:o?"Approving…":e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"hidden sm:inline",children:"Approve selected"}),e.jsx("span",{className:"sm:hidden",children:"Approve sel."}),e.jsx("span",{className:"inline-flex h-5 shrink-0 items-center rounded-full border border-strong bg-white/[0.04] px-2 text-micro text-primary tabular-nums",children:f})]})}),e.jsx("span",{className:"text-caption text-secondary",children:f>0?`${f} selected`:"No selection"})]})]}),e.jsxs("div",{className:"min-h-0 flex-1 space-y-2 overflow-y-auto p-3",children:[g.length===0&&e.jsxs("div",{className:"flex flex-col items-center gap-2.5 rounded-xl border border-subtle bg-white/[0.02] p-4 text-center",children:[e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-faint",children:[e.jsx("path",{d:"M22 11.08V12a10 10 0 1 1-5.93-9.14"}),e.jsx("polyline",{points:"22 4 12 14.01 9 11.01"})]}),e.jsx("p",{className:"text-body text-secondary",children:"No pending decisions. All clear."})]}),pe?e.jsx(qe,{mode:"popLayout",children:k.map(u=>{const I=l.has(u.id),L=hn(u.waitingMinutes),z=m.has(u.id);return e.jsx(ue.article,{role:"button",tabIndex:0,onClick:()=>F(u.id),onKeyDown:R=>{(R.key==="Enter"||R.key===" ")&&(R.preventDefault(),F(u.id))},initial:{opacity:0,y:8,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,scale:.95},transition:{duration:.25,ease:[.4,0,.2,1]},layout:!0,className:"rounded-xl border bg-white/[0.03] px-3 py-2.5 transition-[border-color,box-shadow] cv-auto",style:{borderColor:z?`${C.lime}50`:`${L.border}35`,borderLeftWidth:3,borderLeftColor:`${L.border}80`,boxShadow:L.glow},children:e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx("input",{type:"checkbox",checked:z,onChange:()=>A(u.id),disabled:I||o,onClick:R=>R.stopPropagation(),className:"mt-0.5 h-4 w-4 rounded border-white/20 bg-black/40 text-lime focus:ring-lime/40"}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"flex min-w-0 items-start gap-1.5 text-body font-medium text-white",title:u.title,children:[e.jsx(Ne,{type:"decision",size:12,className:"mt-[3px] flex-shrink-0 opacity-90"}),e.jsx("span",{className:"line-clamp-2",children:u.title})]}),u.context&&e.jsx("p",{className:"mt-1 line-clamp-2 text-caption text-secondary",title:u.context,children:u.context}),e.jsxs("div",{className:"mt-1.5 flex items-center justify-between gap-2",children:[e.jsxs("p",{className:"min-w-0 truncate text-micro text-muted",title:`${u.agentName??"System"} · Waiting ${u.waitingMinutes}m${u.requestedAt?` · ${Ce(u.requestedAt)}`:""}`,children:[u.agentName??"System"," · Waiting ",u.waitingMinutes,"m",u.requestedAt?` · ${Ce(u.requestedAt)}`:""]}),e.jsx("button",{onClick:R=>{R.stopPropagation(),G(u.id)},disabled:I||o,className:"flex-shrink-0 rounded-md border border-lime/25 bg-lime/10 px-2.5 py-1 text-micro font-semibold text-lime transition-colors hover:bg-lime/20 disabled:cursor-not-allowed disabled:border-white/10 disabled:bg-white/[0.08] disabled:text-secondary",children:I?"Approving…":"Approve"})]})]})})]})},u.id)})}):e.jsx(e.Fragment,{children:k.map(u=>{const I=l.has(u.id),L=hn(u.waitingMinutes),z=m.has(u.id);return e.jsx("article",{role:"button",tabIndex:0,onClick:()=>F(u.id),onKeyDown:R=>{(R.key==="Enter"||R.key===" ")&&(R.preventDefault(),F(u.id))},className:"rounded-xl border bg-white/[0.03] px-3 py-2.5 transition-[border-color,box-shadow] cv-auto",style:{borderColor:z?`${C.lime}50`:`${L.border}35`,borderLeftWidth:3,borderLeftColor:`${L.border}80`,boxShadow:L.glow},children:e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx("input",{type:"checkbox",checked:z,onChange:()=>A(u.id),disabled:I||o,onClick:R=>R.stopPropagation(),className:"mt-0.5 h-4 w-4 rounded border-white/20 bg-black/40 text-lime focus:ring-lime/40"}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"flex min-w-0 items-start gap-1.5 text-body font-medium text-white",title:u.title,children:[e.jsx(Ne,{type:"decision",size:12,className:"mt-[3px] flex-shrink-0 opacity-90"}),e.jsx("span",{className:"line-clamp-2",children:u.title})]}),u.context&&e.jsx("p",{className:"mt-1 line-clamp-2 text-caption text-secondary",title:u.context,children:u.context}),e.jsxs("div",{className:"mt-1.5 flex items-center justify-between gap-2",children:[e.jsxs("p",{className:"min-w-0 truncate text-micro text-muted",title:`${u.agentName??"System"} · Waiting ${u.waitingMinutes}m${u.requestedAt?` · ${Ce(u.requestedAt)}`:""}`,children:[u.agentName??"System"," · Waiting ",u.waitingMinutes,"m",u.requestedAt?` · ${Ce(u.requestedAt)}`:""]}),e.jsx("button",{onClick:R=>{R.stopPropagation(),G(u.id)},disabled:I||o,className:"flex-shrink-0 rounded-md border border-lime/25 bg-lime/10 px-2.5 py-1 text-micro font-semibold text-lime transition-colors hover:bg-lime/20 disabled:cursor-not-allowed disabled:border-white/10 disabled:bg-white/[0.08] disabled:text-secondary",children:I?"Approving…":"Approve"})]})]})})]})},u.id)})}),k.length<g.length&&e.jsxs("button",{onClick:()=>N(u=>Math.min(g.length,u+As)),className:"w-full rounded-xl border border-white/[0.08] bg-white/[0.02] px-3 py-2 text-caption text-secondary transition-colors hover:bg-white/[0.05]",children:["Load more (",g.length-k.length," remaining)"]})]}),p&&e.jsxs("div",{className:"flex items-center gap-2 border-t border-subtle px-4 py-2.5 text-body text-secondary",children:[e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:te?"text-lime":"text-amber-400",children:te?e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M22 11.08V12a10 10 0 1 1-5.93-9.14"}),e.jsx("polyline",{points:"22 4 12 14.01 9 11.01"})]}):e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z"}),e.jsx("line",{x1:"12",x2:"12",y1:"9",y2:"13"}),e.jsx("line",{x1:"12",x2:"12.01",y1:"17",y2:"17"})]})}),p]})]})}),Ma=new Set(["running","active","in_progress","working","planning","dispatching","blocked"]);function Fa(t){const s=rt(t.status??"");return Ma.has(s)?!0:s==="queued"||s==="pending"?!1:!!t.lastHeartbeatAt}function fn(t){return t.replace(/_/g," ")}const _a=a.memo(function({sessions:s,title:r="In Progress",className:n,onOpenSession:i,onFocusRunId:o}){const[c,l]=a.useState(null),y=a.useMemo(()=>{const p=s.filter(Fa);return p.sort((d,h)=>{const N=Date.parse(d.updatedAt??d.lastEventAt??d.startedAt??""),w=Date.parse(h.updatedAt??h.lastEventAt??h.startedAt??""),F=Number.isFinite(N)?N:0;return(Number.isFinite(w)?w:0)-F}),p},[s]),m=a.useMemo(()=>{const p=new Map;for(const d of y){const h=rt(d.status??"");p.set(h,(p.get(h)??0)+1)}return Array.from(p.entries()).sort((d,h)=>h[1]-d[1]).map(([d,h])=>({status:d,count:h}))},[y]),x=a.useMemo(()=>c?y.filter(p=>rt(p.status??"")===c):y,[y,c]);return e.jsxs(vt,{className:`flex h-full min-h-0 flex-col overflow-hidden ${n??""}`,children:[e.jsx("div",{className:"flex items-center justify-between gap-2 border-b border-subtle px-4 py-3",children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("h2",{className:"truncate text-heading font-semibold text-white",children:r}),e.jsx("span",{className:"chip text-micro",children:y.length})]})}),m.length>1&&e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 border-b border-subtle px-3 py-2",children:[e.jsxs("button",{type:"button",onClick:()=>l(null),className:`inline-flex h-6 items-center gap-1 rounded-full border px-2 text-micro font-semibold transition-colors ${c===null?"border-[#BFFF00]/30 bg-[#BFFF00]/12 text-[#E1FFB2]":"border-strong bg-white/[0.04] text-secondary hover:bg-white/[0.08]"}`,children:["All",e.jsx("span",{className:"tabular-nums opacity-70",children:y.length})]}),m.map(({status:p,count:d})=>e.jsxs("button",{type:"button",onClick:()=>l(h=>h===p?null:p),className:`inline-flex h-6 items-center gap-1 rounded-full border px-2 text-micro font-semibold capitalize transition-colors ${c===p?"border-[#BFFF00]/30 bg-[#BFFF00]/12 text-[#E1FFB2]":"border-strong bg-white/[0.04] text-secondary hover:bg-white/[0.08]"}`,children:[fn(p),e.jsx("span",{className:"tabular-nums opacity-70",children:d})]},p))]}),x.length===0?e.jsx("div",{className:"px-4 py-4 text-body text-secondary",children:y.length===0?"No runs in progress.":"No runs match this filter."}):e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-3 py-2",children:e.jsx("div",{className:"space-y-2",children:x.map(p=>{var w;const d=rt(p.status??""),h=p.lastEventAt??p.updatedAt??p.startedAt??null,N=(w=p.lastEventSummary)!=null&&w.trim()?p.lastEventSummary.trim():h?`Updated ${Ce(h)}`:null;return e.jsx("div",{className:"rounded-2xl border border-white/[0.08] bg-white/[0.02] px-3 py-2.5",children:e.jsxs("div",{className:"flex min-w-0 items-start gap-2.5",children:[e.jsx(nt,{name:p.agentName??"OrgX",hint:p.agentId??p.runId,size:"sm"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex min-w-0 items-start gap-1.5",children:[e.jsx(Ne,{type:"session",size:12,className:"mt-[3px] flex-shrink-0 opacity-80"}),e.jsx("p",{className:"min-w-0 line-clamp-2 text-body font-semibold leading-snug text-white",title:p.title,children:p.title}),e.jsx("span",{className:"ml-auto flex-shrink-0 rounded-full border border-white/[0.10] bg-white/[0.03] px-2 py-[1px] text-micro font-semibold uppercase tracking-[0.08em] text-secondary",children:fn(d)})]}),N?e.jsx("p",{className:"mt-1 line-clamp-2 text-caption leading-snug text-secondary",title:N,children:N}):null,e.jsxs("div",{className:"mt-1.5 flex items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>i==null?void 0:i(p.id),className:"control-pill h-7 px-2.5 text-micro font-semibold",title:"Open session",children:"Open"}),e.jsx("button",{type:"button",onClick:()=>o==null?void 0:o(p.runId),className:"control-pill h-7 px-2.5 text-micro font-semibold",title:"Focus in Activity",children:"Focus"})]})]})]})},p.id)})})})]})});function Qe({className:t=""}){return e.jsx("div",{className:we("shimmer-skeleton",t),"aria-hidden":"true"})}async function Hn(t,s){var o;const n=await(await fetch(t,s)).json().catch(()=>null),i=((o=n==null?void 0:n.data)==null?void 0:o.url)??(n==null?void 0:n.url)??null;if(typeof i=="string"&&i.trim())return i.trim();throw new Error((n==null?void 0:n.error)??"Billing link unavailable")}async function $a(t){var i;const s=((i=t==null?void 0:t.actions)==null?void 0:i.checkout)??"/orgx/api/billing/checkout",r=((t==null?void 0:t.requiredPlan)??"starter").trim().toLowerCase()||"starter",n=await Hn(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({planId:r})});window.open(n,"_blank","noopener,noreferrer")}async function Ta(t){var n;const s=((n=t==null?void 0:t.actions)==null?void 0:n.portal)??"/orgx/api/billing/portal",r=await Hn(s,{method:"POST"});window.open(r,"_blank","noopener,noreferrer")}class Jn extends Error{constructor(r,n){super(r);Lt(this,"code","upgrade_required");Lt(this,"currentPlan");Lt(this,"requiredPlan");Lt(this,"actions");this.name="UpgradeRequiredError",this.currentPlan=(n==null?void 0:n.currentPlan)??null,this.requiredPlan=((n==null?void 0:n.requiredPlan)??"starter").trim()||"starter",this.actions=(n==null?void 0:n.actions)??null}}function La(t){if(!t||typeof t!="object")return null;const s=t;if(s.code!=="upgrade_required")return null;const r=typeof s.error=="string"&&s.error.trim()?s.error.trim():"Upgrade required.";return new Jn(r,{currentPlan:typeof s.currentPlan=="string"&&s.currentPlan.trim()?s.currentPlan.trim():null,requiredPlan:typeof s.requiredPlan=="string"&&s.requiredPlan.trim()?s.requiredPlan.trim():null,actions:s.actions??null})}function gn(t){const s=(t??"").trim().toLowerCase();return s?s==="free"?"Free":s==="starter"?"Starter":s==="team"?"Team":s==="enterprise"?"Enterprise":s[0].toUpperCase()+s.slice(1):"Unknown"}async function Zt(t){return await t.json().catch(()=>null)}function es(t,s,r){return typeof(s==null?void 0:s.error)=="string"&&s.error.trim()||typeof(s==null?void 0:s.message)=="string"&&s.message.trim()||`${r} (${t.status})`}function Pa({initiativeId:t=null,authToken:s=null,embedMode:r=!1,enabled:n=!0}){var p,d,h,N;const i=ls(),o=a.useMemo(()=>wt.nextUpQueue({initiativeId:t,authToken:s,embedMode:r}),[t,s,r]),c=async()=>{await i.invalidateQueries({queryKey:o}),await i.invalidateQueries({queryKey:wt.autoContinueStatus({initiativeId:t,authToken:s,embedMode:r})}),await i.invalidateQueries({queryKey:wt.missionControlGraph({initiativeId:t,authToken:s,embedMode:r})}),await i.invalidateQueries({queryKey:wt.liveData({authToken:s,embedMode:r})})},l=it({queryKey:o,enabled:n,queryFn:async()=>{const w=new URLSearchParams;t&&w.set("initiative_id",t);const F=await fetch(`/orgx/api/mission-control/next-up?${w.toString()}`,{headers:Be({authToken:s,embedMode:r})}),g=await Zt(F);if(!F.ok){const k=es(F,g,"Failed to load next up queue");throw new Error(k)}const f=g??null;return!f||f.ok!==!0?{ok:!0,generatedAt:new Date().toISOString(),total:0,items:[],degraded:["next-up queue response missing expected payload"]}:f},refetchInterval:w=>{const F=w.state.data;return!F||!Array.isArray(F.items)||F.items.length===0?1e4:F.items.some(f=>f.queueState==="running")?2500:8e3}}),y=ht({mutationFn:async w=>{const F=await fetch("/orgx/api/mission-control/next-up/play",{method:"POST",headers:Be({authToken:s,embedMode:r,contentTypeJson:!0}),body:JSON.stringify({initiativeId:w.initiativeId,workstreamId:w.workstreamId,agentId:w.agentId??void 0,fastAck:!0})}),g=await Zt(F);if(!F.ok)throw new Error(es(F,g,"Failed to dispatch queued workstream"));return g},onMutate:async w=>{await i.cancelQueries({queryKey:o});const F=i.getQueryData(o);return F?(i.setQueryData(o,{...F,items:F.items.map(g=>g.initiativeId===w.initiativeId&&g.workstreamId===w.workstreamId?{...g,queueState:"running"}:g.queueState==="running"?{...g,queueState:"idle"}:g)}),{previous:F}):{previous:F}},onError:(w,F,g)=>{g!=null&&g.previous&&i.setQueryData(o,g.previous)},onSuccess:()=>{c()}}),m=ht({mutationFn:async w=>{const F=await fetch("/orgx/api/mission-control/auto-continue/start",{method:"POST",headers:Be({authToken:s,embedMode:r,contentTypeJson:!0}),body:JSON.stringify({initiativeId:w.initiativeId,agentId:w.agentId??void 0,tokenBudgetTokens:w.tokenBudgetTokens,workstreamIds:[w.workstreamId]})}),g=await Zt(F);if(!F.ok){const f=La(g);throw f||new Error(es(F,g,"Failed to start auto-continue"))}},onSuccess:()=>{c()}}),x=ht({mutationFn:async w=>{const F=await fetch("/orgx/api/mission-control/auto-continue/stop",{method:"POST",headers:Be({authToken:s,embedMode:r,contentTypeJson:!0}),body:JSON.stringify({initiativeId:w.initiativeId})}),g=await Zt(F);if(!F.ok)throw new Error(es(F,g,"Failed to stop auto-continue"))},onSuccess:()=>{c()}});return{items:((p=l.data)==null?void 0:p.items)??[],total:((d=l.data)==null?void 0:d.total)??0,degraded:((h=l.data)==null?void 0:h.degraded)??[],isLoading:l.isLoading,isFetching:l.isFetching,error:((N=l.error)==null?void 0:N.message)??null,refetch:l.refetch,playWorkstream:y.mutateAsync,startWorkstreamAutoContinue:m.mutateAsync,stopInitiativeAutoContinue:x.mutateAsync,isPlaying:y.isPending,isStartingAutoContinue:m.isPending,isStoppingAutoContinue:x.isPending}}async function Is(t){return await t.json().catch(()=>null)}function Es(t,s,r){return typeof(s==null?void 0:s.error)=="string"&&s.error.trim()||typeof(s==null?void 0:s.message)=="string"&&s.message.trim()||`${r} (${t.status})`}function Da(t){const s=t.authToken??null,r=t.embedMode??!1,n=ls(),i=async()=>{await n.invalidateQueries({queryKey:["mission-control-next-up"]}),await n.invalidateQueries({queryKey:["mission-control-graph"]}),await n.invalidateQueries({queryKey:["live-data"]})},o=ht({mutationFn:async y=>{const m=await fetch("/orgx/api/mission-control/next-up/pin",{method:"POST",headers:Be({authToken:s,embedMode:r,contentTypeJson:!0}),body:JSON.stringify(y)}),x=await Is(m);if(!m.ok)throw new Error(Es(m,x,"Failed to pin Next Up item"))},onSuccess:()=>{i()}}),c=ht({mutationFn:async y=>{const m=await fetch("/orgx/api/mission-control/next-up/unpin",{method:"POST",headers:Be({authToken:s,embedMode:r,contentTypeJson:!0}),body:JSON.stringify(y)}),x=await Is(m);if(!m.ok)throw new Error(Es(m,x,"Failed to unpin Next Up item"))},onSuccess:()=>{i()}}),l=ht({mutationFn:async y=>{const m=await fetch("/orgx/api/mission-control/next-up/reorder",{method:"POST",headers:Be({authToken:s,embedMode:r,contentTypeJson:!0}),body:JSON.stringify(y)}),x=await Is(m);if(!m.ok)throw new Error(Es(m,x,"Failed to reorder Next Up queue"))},onSuccess:()=>{i()}});return{pin:o.mutateAsync,unpin:c.mutateAsync,reorder:l.mutateAsync,isPinning:o.isPending,isUnpinning:c.isPending,isReordering:l.isPending}}function Qn({className:t=""}){return e.jsxs("svg",{viewBox:"0 0 20 20",fill:"none","aria-hidden":!0,className:t,children:[e.jsx("path",{d:"M2.5 10s2.6-4.2 7.5-4.2S17.5 10 17.5 10s-2.6 4.2-7.5 4.2S2.5 10 2.5 10Z",stroke:"currentColor",strokeWidth:"1.4"}),e.jsx("circle",{cx:"10",cy:"10",r:"2.2",stroke:"currentColor",strokeWidth:"1.4"})]})}function Xn({className:t=""}){return e.jsx("svg",{viewBox:"0 0 20 20",fill:"none","aria-hidden":!0,className:t,children:e.jsx("path",{d:"M7 5.4v9.2c0 .7.75 1.15 1.38.83l7.6-4.6a.95.95 0 0 0 0-1.62l-7.6-4.64A.95.95 0 0 0 7 5.4Z",fill:"currentColor"})})}function Gn({className:t=""}){return e.jsx("svg",{viewBox:"0 0 20 20",fill:"none","aria-hidden":!0,className:t,children:e.jsx("path",{d:"M6.1 13.25C4.25 13.25 2.8 11.8 2.8 10s1.45-3.25 3.3-3.25c3.15 0 4.35 6.5 8.05 6.5 1.85 0 3.3-1.45 3.3-3.25s-1.45-3.25-3.3-3.25c-3.7 0-4.9 6.5-8.05 6.5Z",stroke:"currentColor",strokeWidth:"2.1",strokeLinecap:"round",strokeLinejoin:"round"})})}function Ba({className:t=""}){return e.jsxs("svg",{viewBox:"0 0 20 20",fill:"none","aria-hidden":!0,className:t,children:[e.jsx("path",{d:"M6.2 9.4V6.7c0-.7.5-1.2 1.1-1.2s1.1.5 1.1 1.2v2.2",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"}),e.jsx("path",{d:"M8.4 8.9V5.8c0-.7.5-1.3 1.1-1.3s1.1.6 1.1 1.3v3",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"}),e.jsx("path",{d:"M10.6 8.9V6.2c0-.7.5-1.3 1.1-1.3s1.1.6 1.1 1.3v3.2",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"}),e.jsx("path",{d:"M12.8 9.6V7.2c0-.7.5-1.2 1.1-1.2s1.1.5 1.1 1.2v4.2c0 2.7-1.9 4.6-4.6 4.6H9.2c-2.1 0-3.7-1-4.6-2.8l-.9-1.7c-.3-.6 0-1.4.6-1.7.6-.3 1.3 0 1.6.6l.7 1.4",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round"})]})}function Oa({className:t=""}){return e.jsxs("svg",{viewBox:"0 0 20 20",fill:"none","aria-hidden":!0,className:t,children:[e.jsx("path",{d:"M6.4 9.2V7.4c0-.7.5-1.2 1.1-1.2s1.1.5 1.1 1.2v1.3",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"}),e.jsx("path",{d:"M8.6 8.9V7c0-.7.5-1.2 1.1-1.2s1.1.5 1.1 1.2v2",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"}),e.jsx("path",{d:"M10.8 9.2V7.3c0-.7.5-1.2 1.1-1.2s1.1.5 1.1 1.2v2.6",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"}),e.jsx("path",{d:"M13 9.8V8.2c0-.7.5-1.2 1.1-1.2s1.1.5 1.1 1.2v3.6c0 2.4-1.7 4-4.1 4H9.7c-2 0-3.4-.9-4.2-2.5l-.8-1.4c-.3-.6 0-1.3.5-1.6.6-.3 1.2-.1 1.6.5l.6 1",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round"})]})}function Yn(t){return t==="running"?"from-teal-300/0 via-teal-300/60 to-teal-300/0":t==="blocked"?"from-red-300/0 via-red-300/55 to-red-300/0":t==="idle"?"from-white/0 via-white/35 to-white/0":"from-[#BFFF00]/0 via-[#BFFF00]/70 to-[#BFFF00]/0"}function Ra({compact:t}){const s=t?3:6;return e.jsxs("div",{className:"space-y-2.5",children:[e.jsxs("div",{className:"flex items-center gap-2 px-1 pt-1 text-micro uppercase tracking-[0.12em] text-muted",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-[#BFFF00]/70 status-breathe"}),e.jsx("span",{children:"Calibrating queue"})]}),Array.from({length:s}).map((r,n)=>e.jsxs("div",{className:"nextup-skeleton-card rounded-2xl border border-white/[0.08] bg-white/[0.02] px-3 py-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2.5",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-start gap-2.5",children:[e.jsx(Qe,{className:"h-8 w-8 rounded-full"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx(Qe,{className:"h-3 w-40 rounded-md"}),e.jsx(Qe,{className:"mt-2 h-4 w-56 rounded-md"})]})]}),e.jsx(Qe,{className:"h-5 w-16 rounded-full"})]}),e.jsxs("div",{className:"mt-3 rounded-lg border border-white/[0.07] bg-black/[0.18] px-2.5 py-2",children:[e.jsx(Qe,{className:"h-3 w-14 rounded"}),e.jsx(Qe,{className:"mt-2 h-3 w-full rounded"}),e.jsx(Qe,{className:"mt-2 h-3 w-3/5 rounded"})]}),e.jsxs("div",{className:"mt-2.5 flex flex-wrap gap-1.5",children:[e.jsx(Qe,{className:"h-8 w-24 rounded-full"}),e.jsx(Qe,{className:"h-8 w-20 rounded-full"}),e.jsx(Qe,{className:"h-8 w-24 rounded-full"})]})]},`nextup-skeleton-${n}`))]})}function qa({initiativeId:t=null,authToken:s=null,embedMode:r=!1,title:n="Next Up",compact:i=!1,className:o,disableEnterAnimation:c=!1,allowCompactToggle:l=!1,onToggleCompact:y,onFollowWorkstream:m,onOpenInitiative:x,onOpenSettings:p,onUpgradeGate:d}){var ce;const[h,N]=a.useState(i);a.useEffect(()=>N(i),[i]);const w=l&&!y?h:i,F=$=>{y?y($):N($)},[g,f]=a.useState(null),[k,v]=a.useState(null),[T,D]=a.useState(null),{items:A,total:ee,degraded:ie,isLoading:ne,isFetching:G,error:te,playWorkstream:pe,startWorkstreamAutoContinue:j,stopInitiativeAutoContinue:E}=Pa({initiativeId:t,authToken:s,embedMode:r,enabled:!0}),u=Da({authToken:s,embedMode:r}),I=a.useMemo(()=>w?A.slice(0,5):A,[w,A]),L=$=>`${$.initiativeId}:${$.workstreamId}`,[z,R]=a.useState([]),me=a.useRef([]),re=a.useMemo(()=>{const $=new Map;for(const S of I)$.set(L(S),S);return $},[I]),X=a.useMemo(()=>I.map(L),[I]),K=a.useMemo(()=>X.join("|"),[X]);a.useEffect(()=>{R($=>{if(w)return[];const S=[],V=new Set(X);for(const Y of $)V.has(Y)&&S.push(Y);for(const Y of X)S.includes(Y)||S.push(Y);return S})},[w,K]),a.useEffect(()=>{me.current=z},[z]);const Ae=async()=>{const $=me.current.map(S=>re.get(S)).filter(Boolean).map(S=>({initiativeId:S.initiativeId,workstreamId:S.workstreamId}));$.length!==0&&await u.reorder({order:$})},le=async($,S,V)=>{f(null),v(null),d==null||d(null),D($);try{await S(),f(V)}catch(Y){Y instanceof Jn?(v(Y),d==null||d(Y)):f(Y instanceof Error?Y.message:"Action failed")}finally{D(null)}},Ie=k?"upgrade":te?"error":g?"notice":null,P=Ie!==null;return e.jsxs(vt,{className:`flex h-full min-h-0 flex-col overflow-hidden ${c?"":"card-enter"} ${o??""}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 border-b border-subtle px-4 py-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("h2",{className:"truncate text-heading font-semibold text-white",children:n}),ne?e.jsx(Qe,{className:"h-5 w-10 rounded-full"}):e.jsx("span",{className:"chip text-micro",children:ee}),G&&!ne&&e.jsx("span",{className:"text-micro text-muted",children:"refreshing…"})]}),l?e.jsx("button",{type:"button",onClick:()=>F(!w),className:"control-pill h-8 flex-shrink-0 whitespace-nowrap px-3 text-caption font-semibold",title:w?"Switch to expanded cards":"Switch to compact list","aria-label":w?"Expand Next Up queue":"Compact Next Up queue",children:w?"Expand":"Compact"}):null]}),P&&e.jsx("div",{className:"px-3 pt-2",children:e.jsx(qe,{initial:!1,mode:"wait",children:Ie==="upgrade"&&k?e.jsx(ue.div,{initial:{opacity:0,y:-4,scale:.99},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-4,scale:.99},transition:{duration:.18,ease:[.22,1,.36,1]},className:"rounded-xl border border-amber-200/25 bg-amber-200/10 px-3 py-2 text-caption text-amber-100",children:e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"rounded-full border border-amber-200/25 bg-amber-200/10 px-2 py-0.5 text-micro font-semibold uppercase tracking-[0.08em] text-amber-100/90",children:"Upgrade required"}),e.jsxs("span",{className:"truncate text-micro text-secondary",children:[gn(k.currentPlan)," →"," ",gn(k.requiredPlan)]})]}),e.jsx("div",{className:"mt-1 line-clamp-2 text-caption leading-snug text-amber-50/90",title:k.message,children:k.message}),g?e.jsx("div",{className:"mt-1 text-micro text-rose-50/85",children:g}):null]}),e.jsxs("div",{className:"flex flex-shrink-0 flex-col items-end gap-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>void $a({actions:k.actions,requiredPlan:k.requiredPlan}).catch($=>f($ instanceof Error?$.message:"Checkout failed")),className:"h-7 rounded-full border border-amber-200/25 bg-amber-200/15 px-3 text-micro font-semibold text-amber-50 transition-colors hover:bg-amber-200/20",children:"Upgrade"}),e.jsx("button",{type:"button",onClick:()=>void Ta({actions:k.actions}).catch($=>f($ instanceof Error?$.message:"Portal failed")),className:"h-7 rounded-full border border-strong bg-white/[0.04] px-3 text-micro font-semibold text-primary transition-colors hover:bg-white/[0.08]",children:"Billing"}),p&&e.jsx("button",{type:"button",onClick:p,className:"h-7 rounded-full border border-strong bg-white/[0.04] px-2.5 text-micro font-semibold text-primary transition-colors hover:bg-white/[0.08]",children:"Settings"})]}),(ce=k.actions)!=null&&ce.pricing?e.jsx("a",{href:k.actions.pricing,target:"_blank",rel:"noopener noreferrer",className:"text-micro text-secondary underline decoration-white/20 hover:text-primary",children:"View pricing"}):null]})]})},"upgrade"):Ie==="error"&&te?e.jsx(ue.div,{initial:{opacity:0,y:-4},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},transition:{duration:.18},className:"rounded-xl border border-red-400/25 bg-red-500/[0.08] px-3 py-2 text-caption text-red-100",children:te},"error"):Ie==="notice"&&g?e.jsx(ue.div,{initial:{opacity:0,y:-4},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},transition:{duration:.18},className:"rounded-xl border border-white/[0.1] bg-white/[0.03] px-3 py-2 text-caption text-primary",children:g},"notice"):null})}),e.jsxs("div",{className:"flex-1 space-y-2.5 overflow-y-auto overscroll-y-contain px-3 pb-3 pt-1",children:[ne?e.jsx(Ra,{compact:w}):null,!ne&&I.length===0&&!te&&e.jsx("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.02] px-3 py-4 text-center text-body text-secondary",children:"No queued workstreams right now."}),!ne&&w?e.jsx(qe,{initial:!1,children:I.map(($,S)=>{var Se,ye;const V=L($),Y=T===V,W=((Se=$.autoContinue)==null?void 0:Se.status)==="running"||((ye=$.autoContinue)==null?void 0:ye.status)==="stopping",ke=$.nextTaskDueAt?Ce($.nextTaskDueAt):null;return e.jsxs(ue.article,{layout:!0,initial:{opacity:0,y:6,scale:.99},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-4,scale:.99},transition:{duration:.22,delay:Math.min(S,7)*.018,ease:[.22,1,.36,1]},className:"group relative overflow-hidden rounded-2xl border border-white/[0.08] bg-white/[0.02] px-2.5 py-2",children:[e.jsx("div",{className:`pointer-events-none absolute inset-x-2.5 top-0 h-px bg-gradient-to-r ${Yn($.queueState)}`,"aria-hidden":!0}),e.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[e.jsx(nt,{name:$.runnerAgentName,hint:`${$.runnerAgentId} ${$.runnerSource}`,size:"xs"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[e.jsx(Ne,{type:"initiative",size:11,className:"flex-shrink-0 opacity-85"}),e.jsx("button",{type:"button",onClick:()=>x==null?void 0:x($.initiativeId,$.initiativeTitle),className:"block w-full truncate text-left text-micro uppercase tracking-[0.08em] text-muted transition-colors hover:text-white/72",title:$.initiativeTitle,children:$.initiativeTitle})]}),e.jsxs("p",{className:"mt-0.5 flex min-w-0 items-center gap-1.5 text-caption font-semibold leading-snug text-white",title:$.workstreamTitle,children:[e.jsx(Ne,{type:"workstream",size:12,className:"flex-shrink-0 opacity-95"}),e.jsx("span",{className:"line-clamp-2",children:$.workstreamTitle})]}),$.nextTaskTitle?e.jsxs("p",{className:"mt-0.5 line-clamp-2 text-micro leading-snug text-secondary",title:`Next: ${$.nextTaskTitle}${ke?` · ${ke}`:""}`,children:["Next: ",$.nextTaskTitle,ke?` · ${ke}`:""]}):null]})]}),$.blockReason&&e.jsxs("div",{className:"mt-1.5 rounded-lg border border-red-400/24 bg-red-500/[0.08] px-2.5 py-1 text-micro text-red-100/85",children:["Blocked: ",$.blockReason]}),e.jsxs("div",{className:"mt-1.5 flex items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>m==null?void 0:m($),className:"control-pill flex h-7 items-center justify-center px-2.5 text-micro font-semibold",title:"Follow in Activity",children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Qn,{className:"h-3 w-3 opacity-85"}),e.jsx("span",{children:"Follow"})]})}),e.jsx("button",{type:"button",disabled:Y,onClick:()=>void le(V,()=>pe({initiativeId:$.initiativeId,workstreamId:$.workstreamId,agentId:$.runnerAgentId}),`Dispatched ${$.workstreamTitle}.`),className:"control-pill flex h-7 items-center justify-center px-2.5 text-micro font-semibold disabled:opacity-40",title:"Dispatch now",children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Xn,{className:"h-3 w-3 opacity-85"}),e.jsx("span",{children:"Play"})]})}),e.jsx("button",{type:"button",disabled:Y,onClick:()=>void le(V,()=>W?E({initiativeId:$.initiativeId}):j({initiativeId:$.initiativeId,workstreamId:$.workstreamId,agentId:$.runnerAgentId}),W?`Stopped auto-continue for ${$.initiativeTitle}.`:`Auto-continue started for ${$.workstreamTitle}.`),className:"control-pill flex h-7 items-center justify-center px-2.5 text-micro font-semibold disabled:opacity-40","data-state":W?"active":"idle","data-tone":"teal",title:W?"Stop auto-continue":"Auto-continue",children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Gn,{className:"h-3 w-3 opacity-85"}),e.jsx("span",{children:W?"Stop auto":"Auto"})]})})]})]},V)})}):ne?null:e.jsx(or,{axis:"y",values:z,onReorder:$=>{me.current=$,R($)},className:"space-y-2.5",children:z.map($=>re.get($)).filter(Boolean).map(($,S)=>e.jsx(za,{item:$,index:S,actionKey:T,setNotice:f,setUpgradeGate:v,onUpgradeGate:d,onOpenInitiative:x,onFollowWorkstream:m,playWorkstream:pe,startWorkstreamAutoContinue:j,stopInitiativeAutoContinue:E,onCommitReorder:()=>void Ae().catch(()=>null),onPinToggle:async V=>{V?(await u.pin({initiativeId:$.initiativeId,workstreamId:$.workstreamId}),f(`Pinned ${$.workstreamTitle}. Drag to reorder.`)):(await u.unpin({initiativeId:$.initiativeId,workstreamId:$.workstreamId}),f(`Unpinned ${$.workstreamTitle}.`))},runAction:le},L($)))})]}),ie.length>0&&e.jsxs("div",{className:"border-t border-subtle px-3 py-2 text-micro text-muted",children:["Limited signal: ",ie[0]]})]})}function za({item:t,index:s,actionKey:r,setNotice:n,setUpgradeGate:i,onUpgradeGate:o,onFollowWorkstream:c,onOpenInitiative:l,playWorkstream:y,startWorkstreamAutoContinue:m,stopInitiativeAutoContinue:x,onCommitReorder:p,onPinToggle:d,runAction:h}){var D,A;const N=lr(),[w,F]=a.useState(!1),g=`${t.initiativeId}:${t.workstreamId}`,f=r===g,k=((D=t.autoContinue)==null?void 0:D.status)==="running"||((A=t.autoContinue)==null?void 0:A.status)==="stopping",v=t.nextTaskDueAt?Ce(t.nextTaskDueAt):null,T=t.isPinned===!0;return e.jsx(cr,{value:g,id:g,dragListener:!1,dragControls:N,onDragStart:()=>F(!0),onDragEnd:()=>{F(!1),p()},whileDrag:{scale:1.01,boxShadow:"0 18px 40px rgba(0,0,0,0.42)"},className:"relative",children:e.jsxs(ue.article,{layout:!0,initial:{opacity:0,y:6,scale:.99},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-4,scale:.99},transition:{duration:.22,delay:Math.min(s,7)*.018,ease:[.22,1,.36,1]},className:"group relative overflow-hidden rounded-2xl border border-white/[0.08] bg-white/[0.02] px-3 py-3",children:[e.jsx("div",{className:`absolute left-1/2 top-1 z-20 -translate-x-1/2 transition-opacity ${w?"opacity-100":"opacity-0 group-hover:opacity-100"}`,children:e.jsxs("button",{type:"button",onPointerDown:ee=>N.start(ee),"aria-label":"Drag to reorder",title:w?"Reordering":"Drag to reorder",className:`inline-flex h-7 items-center gap-1 rounded-full border px-2 text-micro font-semibold transition-colors ${w?"border-[#BFFF00]/35 bg-[#BFFF00]/14 text-[#E1FFB2] cursor-grabbing":"border-strong bg-white/[0.04] text-secondary cursor-grab hover:bg-white/[0.08] hover:text-bright"}`,children:[w?e.jsx(Oa,{className:"h-4 w-4 opacity-90"}):e.jsx(Ba,{className:"h-4 w-4 opacity-90"}),e.jsx("span",{children:w?"Grabbed":"Grab"})]})}),e.jsx("div",{className:`pointer-events-none absolute inset-x-3 top-0 h-px bg-gradient-to-r ${Yn(t.queueState)}`,"aria-hidden":!0}),e.jsxs("div",{className:"flex items-start justify-between gap-2.5",children:[e.jsxs("div",{className:"min-w-0 flex flex-1 items-start gap-2.5",children:[e.jsx(nt,{name:t.runnerAgentName,hint:`${t.runnerAgentId} ${t.runnerSource}`,size:"sm"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[e.jsx(Ne,{type:"initiative",size:11,className:"flex-shrink-0 opacity-85"}),e.jsx("button",{type:"button",onClick:()=>l==null?void 0:l(t.initiativeId,t.initiativeTitle),className:"block w-full truncate text-left text-micro uppercase tracking-[0.08em] text-muted transition-colors hover:text-white/72",title:t.initiativeTitle,children:t.initiativeTitle})]}),e.jsxs("div",{className:"mt-0.5 flex min-w-0 items-start gap-1.5",children:[e.jsx(Ne,{type:"workstream",size:12,className:"mt-[3px] flex-shrink-0 opacity-95"}),e.jsx("p",{className:"min-w-0 line-clamp-2 text-body font-semibold leading-snug text-white",title:t.workstreamTitle,children:t.workstreamTitle})]})]})]}),e.jsx("button",{type:"button",onClick:()=>{n(null),i(null),o==null||o(null),d(!T).catch(ee=>n(ee instanceof Error?ee.message:"Pin action failed"))},title:T?"Unpin from queue ordering":"Pin to queue ordering","aria-label":T?"Unpin":"Pin",className:`inline-flex h-6 w-6 flex-shrink-0 items-center justify-center rounded-full border transition-colors ${T?"border-[#BFFF00]/35 bg-[#BFFF00]/12 text-[#E1FFB2]":"border-strong bg-white/[0.04] text-secondary hover:bg-white/[0.08]"}`,children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2","aria-hidden":!0,children:[e.jsx("path",{d:"M12 17v5"}),e.jsx("path",{d:"M9 3h6l1 7-4 4v3H12v-3l-4-4 1-7Z"})]})})]}),e.jsx("div",{className:"mt-2 rounded-lg border border-white/[0.07] bg-black/[0.18] px-2.5 py-2 text-caption text-white/68",children:t.nextTaskTitle?e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-1 text-micro uppercase tracking-[0.08em] text-white/44",children:[e.jsx(Ne,{type:"task",size:10,className:"flex-shrink-0 opacity-80"}),e.jsx("span",{children:"Next"}),v?e.jsxs("span",{className:"truncate text-micro normal-case tracking-normal text-muted",children:["· ",v]}):null]}),e.jsx("p",{className:"line-clamp-2 break-words text-caption leading-snug text-white/84",title:t.nextTaskTitle,children:t.nextTaskTitle})]}):e.jsx("span",{className:"text-secondary",children:"No task currently queued."})}),e.jsxs("div",{className:"mt-1.5 flex items-center gap-2 text-micro text-secondary",children:[e.jsx("span",{className:"rounded-full border border-strong bg-white/[0.03] px-2 py-0.5 text-micro uppercase tracking-[0.08em] text-secondary",children:"Runner"}),e.jsxs("span",{className:"truncate text-white/68",children:[t.runnerAgentName,t.runnerSource!=="assigned"?` · ${t.runnerSource}`:""]})]}),t.blockReason&&e.jsxs("div",{className:"mt-1.5 rounded-lg border border-red-400/24 bg-red-500/[0.08] px-2.5 py-1 text-micro text-red-100/85",children:["Blocked: ",t.blockReason]}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>c==null?void 0:c(t),className:"control-pill flex h-7 items-center justify-center px-2.5 text-micro font-semibold",title:"Follow this workstream in Activity",children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Qn,{className:"h-3 w-3 opacity-85"}),e.jsx("span",{children:"Follow"})]})}),e.jsx("button",{type:"button",disabled:f,onClick:()=>void h(g,()=>y({initiativeId:t.initiativeId,workstreamId:t.workstreamId,agentId:t.runnerAgentId}),`Dispatched ${t.workstreamTitle}.`),className:"control-pill flex h-7 items-center justify-center px-2.5 text-micro font-semibold disabled:opacity-40",title:"Dispatch this workstream now (single run)",children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Xn,{className:"h-3 w-3 opacity-85"}),e.jsx("span",{children:"Play"})]})}),e.jsx("button",{type:"button",disabled:f,onClick:()=>void h(g,()=>k?x({initiativeId:t.initiativeId}):m({initiativeId:t.initiativeId,workstreamId:t.workstreamId,agentId:t.runnerAgentId}),k?`Stopped auto-continue for ${t.initiativeTitle}.`:`Auto-continue started for ${t.workstreamTitle}.`),className:"control-pill flex h-7 items-center justify-center px-2.5 text-micro font-semibold disabled:opacity-40","data-state":k?"active":"idle","data-tone":"teal",title:k?"Stop auto-continue for this initiative":"Auto-continue this workstream",children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Gn,{className:"h-3 w-3 opacity-85"}),e.jsx("span",{children:k?"Stop auto":"Auto"})]})})]})]})})}function Ua(t){const s=(t??"").toLowerCase();return s==="completed"||s==="done"?"completed":s==="blocked"||s==="at_risk"?"blocked":s==="paused"||s==="hold"?"paused":"active"}function Wa(t){const s=(t??"").toLowerCase();return!["deleted","archived","cancelled"].includes(s)}function Ka(t){return{id:t.id,name:t.title,status:Ua(t.status),rawStatus:t.status??null,priority:t.priority??null,category:void 0,health:Math.max(0,Math.min(100,Math.round(t.progress??0))),daysRemaining:0,targetDate:t.targetDate??t.dueDate??t.etaEndAt??null,createdAt:t.createdAt??null,updatedAt:t.updatedAt??null,activeAgents:0,totalAgents:0,description:void 0}}function Va(t){return it({queryKey:wt.liveInitiatives({limit:300}),queryFn:async()=>{const s=await fetch("/orgx/api/live/initiatives?limit=300");return s.ok?((await s.json()).initiatives??[]).filter(n=>Wa(n.status)).map(Ka):[]},enabled:t,staleTime:3e4})}function Ha(t){switch(t){case"starting":return"Starting secure session...";case"awaiting_browser_auth":return"Waiting for browser approval...";case"pairing":return"Confirming connection...";case"manual_key":return"Manual API key";case"connected":return"Connected";case"error":return"Connection issue";default:return"Ready to connect"}}function Ja(t){switch(t){case"config":return"Plugin config";case"environment":return"Env key";case"persisted":return"Saved key";case"openclaw-config-file":return"OpenClaw key";case"legacy-dev":return"Legacy key";default:return"No key"}}function Qa(t){return t==="awaiting_browser_auth"||t==="pairing"||t==="starting"?"active":t==="error"?"error":t==="connected"?"active":"idle"}const bn={idle:"bg-white/40",active:"bg-[#BFFF00]",error:"bg-red-400"};function Xa({state:t,isStarting:s,isSubmittingManual:r,onRefresh:n,onStartPairing:i,onSubmitManualKey:o,onBackToPairing:c,onUseManualKey:l,onDisconnect:y}){const m="https://www.useorgx.com/settings#security",x=t.status==="manual_key",p=t.status==="awaiting_browser_auth"||t.status==="pairing",d=Qa(t.status),h=d==="active"&&t.status!=="connected",N=!!t.lastError,w=a.useMemo(()=>t.status==="connected"&&t.connectionVerified?"Live sync active.":p?"Approve pairing in your browser to complete the connection.":t.status==="starting"?"Starting a secure pairing session.":t.status==="error"?"Trouble reaching OrgX. Reconnect or try a manual key.":t.hasApiKey?"API key detected. Verify connection to enable live features.":"Connect OrgX to sync initiatives, tasks, activity, and decisions.",[p,t.connectionVerified,t.hasApiKey,t.status]);return e.jsxs("div",{className:"flex min-h-0 flex-col",children:[e.jsxs("div",{className:"mb-4",children:[e.jsx("h3",{className:"text-heading font-semibold text-white",children:"OrgX connection"}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:w}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsxs("span",{className:"chip inline-flex items-center gap-2",children:[e.jsxs("span",{className:"relative flex h-2 w-2",children:[h&&e.jsx("span",{className:`absolute inline-flex h-full w-full animate-ping rounded-full ${bn[d]} opacity-40`}),e.jsx("span",{className:`relative inline-flex h-2 w-2 rounded-full ${bn[d]}`})]}),e.jsx("span",{className:"text-primary",children:Ha(t.status)})]}),t.workspaceName&&e.jsx("span",{className:"chip",children:t.workspaceName}),t.keySource&&t.keySource!=="none"&&e.jsx("span",{className:"chip",children:Ja(t.keySource)}),t.hasApiKey&&!t.connectionVerified&&e.jsx("span",{className:"chip text-amber-100/90",children:"key present, not verified"})]})]}),N&&e.jsx("div",{className:"mb-4 rounded-xl border border-rose-300/20 bg-rose-400/10 p-4 text-body text-rose-100",children:t.lastError}),x?e.jsx(Pn,{isSubmitting:r,onSubmit:o,onBack:c}):e.jsxs("div",{className:"rounded-2xl border border-white/[0.07] bg-white/[0.02] p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>{i()},disabled:s,"data-modal-autofocus":"true",className:"inline-flex items-center gap-2 rounded-full bg-[#BFFF00] px-4 py-2 text-body font-semibold text-black transition-colors hover:bg-[#d3ff42] disabled:cursor-not-allowed disabled:opacity-50",children:s?"Connecting...":"Connect in browser"}),e.jsx("button",{type:"button",onClick:l,className:"rounded-full border border-strong bg-white/[0.03] px-4 py-2 text-body font-semibold text-primary transition-colors hover:bg-white/[0.06]",children:"Use API key"}),t.hasApiKey&&e.jsx("button",{type:"button",onClick:()=>{y()},className:"rounded-full border border-rose-300/25 bg-rose-400/10 px-4 py-2 text-body font-semibold text-rose-100/90 transition-colors hover:bg-rose-400/15",children:"Disconnect"}),e.jsx("button",{type:"button",onClick:()=>{n()},className:we("rounded-full border border-strong bg-white/[0.03] px-4 py-2 text-body font-semibold text-primary transition-colors hover:bg-white/[0.06]",s&&"opacity-60"),children:"Refresh status"}),e.jsx("a",{href:m,target:"_blank",rel:"noreferrer",className:"rounded-full border border-strong bg-white/[0.03] px-4 py-2 text-body font-semibold text-primary transition-colors hover:bg-white/[0.06]",title:"Generate/revoke API keys at useorgx.com",children:"Open API keys"})]}),t.connectUrl&&(p||t.status==="starting")&&e.jsxs("div",{className:"mt-4 rounded-xl border border-[#BFFF00]/20 bg-[#BFFF00]/[0.06] px-4 py-3",children:[e.jsx("p",{className:"text-caption uppercase tracking-[0.1em] text-[#D8FFA1]",children:"Pairing pending"}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:"Approve the connection in your browser to finish pairing."}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsx("a",{href:t.connectUrl,target:"_blank",rel:"noopener noreferrer",className:"rounded-full border border-[#BFFF00]/30 bg-[#BFFF00]/15 px-3 py-1.5 text-caption font-semibold text-[#D8FFA1]",children:"Approve in browser"}),t.expiresAt&&e.jsxs("span",{className:"text-caption text-muted",children:["Expires ",new Date(t.expiresAt).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})]})]})]})]}),e.jsxs("div",{className:"mt-4 rounded-2xl border border-subtle bg-white/[0.02] p-4",children:[e.jsx("p",{className:"text-body font-semibold text-primary",children:"Key guidance"}),e.jsxs("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:["Use a user-scoped key (",e.jsx("code",{className:"rounded bg-black/40 px-1",children:"oxk_..."}),") whenever possible. User keys do not require a separate userId header."]})]})]})}function Ga({authToken:t=null,embedMode:s=!1,enabled:r=!0}={}){var l;const n=ls(),i=a.useMemo(()=>["agent-suite",{authToken:t,embedMode:s}],[t,s]),o=it({queryKey:i,enabled:r,queryFn:async()=>{const y=await fetch("/orgx/api/agent-suite/status",{headers:Be({authToken:t,embedMode:s})}),m=await y.json().catch(()=>null);return y.ok?m:{ok:!1,error:(m==null?void 0:m.error)??`Failed to load agent suite (${y.status})`}},staleTime:1e4}),c=ht({mutationFn:async({dryRun:y,forceSkillPack:m}={})=>{const x=await fetch("/orgx/api/agent-suite/install",{method:"POST",headers:Be({authToken:t,embedMode:s,contentTypeJson:!0}),body:JSON.stringify({dryRun:!!y,forceSkillPack:!!m})}),p=await x.json().catch(()=>null);if(!x.ok)throw new Error((p==null?void 0:p.error)??`Failed to install agent suite (${x.status})`);return p},onSuccess:async()=>{await n.invalidateQueries({queryKey:i})}});return{status:o.data??null,isLoading:o.isLoading,error:(o.data&&"error"in o.data?o.data.error:null)??((l=o.error)==null?void 0:l.message)??null,refetchStatus:o.refetch,install:c.mutateAsync,installResult:c.data??null,isInstalling:c.isPending}}function It(t,s){return t===1?`${t} ${s}`:`${t} ${s}s`}function ct({tone:t,children:s}){const r=a.useMemo(()=>t==="good"?"border-lime/25 bg-lime/[0.10] text-lime":t==="warn"?"border-amber-300/25 bg-amber-400/10 text-amber-100/90":"border-white/[0.10] bg-white/[0.02] text-primary",[t]);return e.jsx("span",{className:we("inline-flex items-center rounded-full border px-2.5 py-1 text-caption font-semibold",r),children:s})}function Ya({authToken:t=null,embedMode:s=!1,enabled:r=!0}){var f,k,v,T,D;const[n,i]=a.useState(!1),o=Ga({authToken:t,embedMode:s,enabled:r}),c=(f=o.status)!=null&&f.ok?o.status.data:null,l=((k=c==null?void 0:c.agents)==null?void 0:k.length)??0,y=((v=c==null?void 0:c.openclawConfigAddedAgents)==null?void 0:v.length)??0,m=a.useMemo(()=>{var A;return((A=c==null?void 0:c.workspaceFiles)==null?void 0:A.filter(ee=>ee.action!=="noop"))??[]},[c]),x=m.length,p=a.useMemo(()=>m.filter(A=>A.action==="create").length,[m]),d=a.useMemo(()=>m.filter(A=>A.action==="update").length,[m]),h=a.useMemo(()=>m.filter(A=>A.action==="conflict").length,[m]),N=a.useMemo(()=>{if(o.isLoading)return"Loading agent suite status...";if(o.error)return"Unable to read suite status.";if(!c)return"Suite status unavailable.";if(h>0)return`Conflicts detected: ${It(h,"file")} need attention.`;if(y===0&&x===0)return"Suite is installed and up to date.";const A=[];return y>0&&A.push(`will add ${It(y,"agent")}`),x>0&&A.push(`will update ${It(x,"file")}`),`Preview: ${A.join(", ")}.`},[x,h,y,c,o.error,o.isLoading]),w=(T=o.installResult)!=null&&T.ok?o.installResult:null,F=!!(w!=null&&w.dryRun),g=async A=>{await fetch("/orgx/api/skill-pack/policy",{method:"POST",headers:Be({authToken:t,embedMode:s,contentTypeJson:!0}),body:JSON.stringify(A)}).then(async ee=>{if(!ee.ok){const ie=await ee.json().catch(()=>null);throw new Error((ie==null?void 0:ie.error)??`Failed to update policy (${ee.status})`)}}),await o.refetchStatus()};return e.jsxs("div",{className:"rounded-2xl border border-white/[0.07] bg-white/[0.02] p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-heading font-semibold text-white",children:"OrgX agent suite"}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:"Installs the OrgX domain agents into OpenClaw (workspaces + guardrails + managed/local overlay)."})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>{o.refetchStatus()},className:"rounded-full border border-strong bg-white/[0.03] px-4 py-2 text-body font-semibold text-primary transition-colors hover:bg-white/[0.06]",children:"Refresh"}),e.jsx("button",{type:"button",onClick:()=>{i(!0),o.install({dryRun:!0})},disabled:o.isInstalling,className:"rounded-full border border-strong bg-white/[0.03] px-4 py-2 text-body font-semibold text-primary transition-colors hover:bg-white/[0.06] disabled:cursor-not-allowed disabled:opacity-50",title:"Computes the plan without writing any files",children:"Dry run"}),e.jsx("button",{type:"button",onClick:()=>{o.install({dryRun:!1,forceSkillPack:!0})},disabled:o.isInstalling,className:"rounded-full border border-strong bg-white/[0.03] px-4 py-2 text-body font-semibold text-primary transition-colors hover:bg-white/[0.06] disabled:cursor-not-allowed disabled:opacity-50",title:"Forces a check for the latest OrgX skill pack and applies it (managed/local overlay preserves local edits)",children:"Refresh skills"}),e.jsx("button",{type:"button",onClick:()=>{o.install({dryRun:!1})},disabled:o.isInstalling,className:"inline-flex items-center gap-2 rounded-full bg-[#BFFF00] px-4 py-2 text-body font-semibold text-black transition-colors hover:bg-[#d3ff42] disabled:cursor-not-allowed disabled:opacity-50",title:"Adds missing agents to openclaw.json and scaffolds managed workspace files",children:o.isInstalling?"Installing...":"Install / Update"})]})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsx(ct,{tone:o.error?"warn":"neutral",children:N}),c&&e.jsxs(e.Fragment,{children:[e.jsx(ct,{tone:y===0?"good":"warn",children:y===0?"agents configured":`${y} missing in openclaw.json`}),e.jsxs(ct,{tone:"neutral",children:[It(l,"agent")," total"]}),e.jsx(ct,{tone:x===0?"good":"neutral",children:x===0?"no file changes":`${x} file changes`}),h>0&&e.jsx(ct,{tone:"warn",children:It(h,"conflict")}),c.skillPackUpdateAvailable&&e.jsx(ct,{tone:"warn",children:"skill update available"}),((D=c.skillPackPolicy)==null?void 0:D.frozen)&&e.jsx(ct,{tone:"neutral",children:"skills frozen"})]})]}),w&&e.jsxs("div",{className:"mt-3 rounded-xl border border-lime/20 bg-lime/[0.06] px-4 py-3",children:[e.jsx("p",{className:"text-caption uppercase tracking-[0.1em] text-[#D8FFA1]",children:F?"Dry run":"Applied"}),e.jsxs("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:["Operation ",e.jsx("code",{className:"rounded bg-black/40 px-1",children:w.operationId})," ",F?"computed the plan without writing any files.":"wrote OpenClaw config and refreshed managed files."]})]}),c&&e.jsxs("div",{className:"mt-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:"text-body font-semibold text-primary",children:"Suite details"}),e.jsx("button",{type:"button",onClick:()=>i(A=>!A),className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.06]",children:n?"Hide":"Show"})]}),n&&e.jsxs("div",{className:"mt-3 grid gap-3",children:[e.jsx("div",{className:"rounded-xl border border-white/[0.07] bg-black/20 p-3",children:e.jsxs("div",{className:"grid gap-1 text-body text-secondary",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("span",{children:"OpenClaw config"}),e.jsx("code",{className:"rounded bg-black/40 px-1.5 py-0.5 text-caption text-primary",children:c.openclawConfigPath})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("span",{children:"Suite workspace root"}),e.jsx("code",{className:"rounded bg-black/40 px-1.5 py-0.5 text-caption text-primary",children:c.suiteWorkspaceRoot})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("span",{children:"Pack"}),e.jsxs("code",{className:"rounded bg-black/40 px-1.5 py-0.5 text-caption text-primary",children:[c.packId,"@",c.packVersion]})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("span",{children:"Skill pack"}),e.jsx("code",{className:"rounded bg-black/40 px-1.5 py-0.5 text-caption text-primary",children:c.skillPack?`${c.skillPack.name}@${c.skillPack.version} (${c.skillPack.source})`:"builtin"})]}),c.skillPackRemote&&e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("span",{children:"Skill pack remote"}),e.jsxs("code",{className:"rounded bg-black/40 px-1.5 py-0.5 text-caption text-primary",children:[c.skillPackRemote.name,"@",c.skillPackRemote.version]})]}),c.skillPackPolicy&&e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("span",{children:"Skill pack policy"}),e.jsxs("code",{className:"rounded bg-black/40 px-1.5 py-0.5 text-caption text-primary",children:[c.skillPackPolicy.frozen?"frozen":"live",c.skillPackPolicy.pinnedChecksum?`, pinned:${c.skillPackPolicy.pinnedChecksum.slice(0,8)}…`:""]})]}),c.skillPackPolicy&&e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>{var A;g({frozen:!((A=c.skillPackPolicy)!=null&&A.frozen)})},className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.06]",children:c.skillPackPolicy.frozen?"Unfreeze skills":"Freeze skills"}),e.jsx("button",{type:"button",onClick:()=>{var A;(A=c.skillPackPolicy)!=null&&A.pinnedChecksum?g({clearPin:!0}):g({pinToCurrent:!0})},className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.06]",children:c.skillPackPolicy.pinnedChecksum?"Unpin":"Pin current"}),e.jsx("p",{className:"text-caption text-muted",children:"Freeze prevents background checks; pin prevents applying a new checksum."})]})]})}),e.jsxs("div",{className:"rounded-xl border border-white/[0.07] bg-black/20 p-3",children:[e.jsx("p",{className:"text-body font-semibold text-primary",children:"Agents"}),e.jsx("div",{className:"mt-2 grid gap-2",children:c.agents.map(A=>e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 rounded-xl border border-subtle bg-white/[0.02] px-3 py-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-body font-semibold text-bright",children:A.name}),e.jsxs("p",{className:"mt-0.5 truncate text-caption text-secondary",children:[e.jsx("code",{className:"rounded bg-black/40 px-1",children:A.id}),e.jsx("span",{className:"px-1",children:"·"}),e.jsx("span",{children:A.domain})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(ct,{tone:A.configuredInOpenclaw?"good":"warn",children:A.configuredInOpenclaw?"configured":"not configured"}),e.jsx(ct,{tone:A.workspaceExists?"good":"neutral",children:A.workspaceExists?"workspace ok":"workspace missing"})]})]},A.id))})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.07] bg-black/20 p-3",children:[e.jsx("p",{className:"text-body font-semibold text-primary",children:"Planned file writes"}),e.jsxs("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:["Managed files are written to ",e.jsx("code",{className:"rounded bg-black/40 px-1",children:".orgx/managed"}),". Local overrides are read from ",e.jsx("code",{className:"rounded bg-black/40 px-1",children:".orgx/local"})," and appended into the composite files in the agent workspace root."]}),e.jsxs("div",{className:"mt-2 grid gap-1 text-caption text-secondary",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("span",{children:"Writes"}),e.jsx("span",{className:"text-primary",children:It(c.workspaceFiles.length,"file")})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("span",{children:"Creates/updates"}),e.jsx("span",{className:"text-primary",children:x})]}),(p>0||d>0)&&e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("span",{children:"Breakdown"}),e.jsxs("span",{className:"text-primary",children:[p>0?`${p} create`:"0 create",","," ",d>0?`${d} update`:"0 update"]})]})]}),y>0&&e.jsxs("div",{className:"mt-3 rounded-lg border border-white/[0.08] bg-white/[0.02] px-3 py-2",children:[e.jsx("p",{className:"text-caption font-semibold text-primary",children:"OpenClaw agents to add"}),e.jsx("div",{className:"mt-1 flex flex-wrap gap-2",children:c.openclawConfigAddedAgents.map(A=>e.jsx("code",{className:"rounded-full border border-strong bg-black/40 px-2 py-0.5 text-caption text-primary",children:A},A))})]}),m.length>0&&e.jsxs("div",{className:"mt-3 rounded-lg border border-white/[0.08] bg-white/[0.02] px-3 py-2",children:[e.jsx("p",{className:"text-caption font-semibold text-primary",children:"Files that will change"}),e.jsxs("div",{className:"mt-2 grid gap-1.5",children:[m.slice(0,24).map(A=>e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 text-caption",children:[e.jsxs("code",{className:"rounded bg-black/40 px-1.5 py-0.5 text-primary",children:[A.agentId,"/",A.file]}),e.jsx("span",{className:"text-secondary",children:A.action})]},`${A.agentId}:${A.file}`)),m.length>24&&e.jsxs("p",{className:"text-caption text-muted",children:["Showing 24 of ",m.length,". Install/Update to apply all."]})]})]})]})]})]})]})}const Zn=[{id:"openai",label:"OpenAI",hint:"Used for GPT models.",envVar:"OPENAI_API_KEY"},{id:"anthropic",label:"Anthropic",hint:"Used for Claude models.",envVar:"ANTHROPIC_API_KEY"},{id:"openrouter",label:"OpenRouter",hint:"Used for multi-vendor routing.",envVar:"OPENROUTER_API_KEY"}];function yn(t){return t==="openai"?"openaiApiKey":t==="anthropic"?"anthropicApiKey":"openrouterApiKey"}function Za(t){var s;return((s=Zn.find(r=>r.id===t))==null?void 0:s.label)??t}function eo({authToken:t=null,embedMode:s=!1,enabled:r=!0}){const n=Bn({authToken:t,embedMode:s,enabled:r}),i=n.status,o=n.health,[c,l]=a.useState({openai:"",anthropic:"",openrouter:""}),[y,m]=a.useState({openai:!1,anthropic:!1,openrouter:!1}),[x,p]=a.useState({openai:!1,anthropic:!1,openrouter:!1}),[d,h]=a.useState(null),[N,w]=a.useState(null);a.useEffect(()=>{r&&(l({openai:"",anthropic:"",openrouter:""}),m({openai:!1,anthropic:!1,openrouter:!1}),p({openai:!1,anthropic:!1,openrouter:!1}),h(null),w(null))},[r]);const F=a.useMemo(()=>i!=null&&i.ok?Number(i.providers.openai.configured)+Number(i.providers.anthropic.configured)+Number(i.providers.openrouter.configured):0,[i]),g=async v=>{if(!r)return;w(null);const T=c[v].trim();if(!y[v])return;if(!T){w(`Enter a ${Za(v)} API key or use "Clear" to remove the saved key.`);return}const D=yn(v);try{h(v),await n.update({[D]:T}),m(A=>({...A,[v]:!1})),l(A=>({...A,[v]:""})),p(A=>({...A,[v]:!1}))}finally{h(null)}},f=async v=>{w(null);const T=yn(v);try{h(v),await n.update({[T]:null}),m(D=>({...D,[v]:!1})),l(D=>({...D,[v]:""})),p(D=>({...D,[v]:!1}))}finally{h(null)}},k=async()=>{w(null),await n.probe()};return e.jsxs("div",{className:"flex min-h-0 flex-col",children:[e.jsxs("div",{className:"mb-4",children:[e.jsx("h3",{className:"text-heading font-semibold text-white",children:"Provider keys"}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:"Bring your own provider keys. Keys are stored locally and used for OpenClaw agent launches."}),F===0?e.jsxs("div",{className:"mt-3 inline-flex items-center gap-2 rounded-full border border-amber-200/20 bg-amber-200/10 px-3 py-1 text-caption text-amber-100/85",children:[e.jsx("span",{className:"inline-flex h-1.5 w-1.5 rounded-full bg-amber-200/80"}),"No keys detected yet. You can also use env vars."]}):e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsxs("span",{className:"chip",children:[F," / 3 configured"]}),(i==null?void 0:i.updatedAt)&&e.jsxs("span",{className:"text-caption text-muted",children:["Updated ",new Date(i.updatedAt).toLocaleString()]})]})]}),(N||n.error)&&e.jsx("div",{className:"mb-4 rounded-xl border border-rose-300/20 bg-rose-400/10 p-4 text-body text-rose-100",children:N??n.error}),e.jsxs("div",{className:"mb-4 rounded-2xl border border-subtle bg-white/[0.02] p-4",children:[e.jsx("p",{className:"text-body font-semibold text-primary",children:"Where keys come from"}),e.jsxs("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:["If you set an env var (e.g."," ",e.jsx("code",{className:"rounded bg-black/40 px-1",children:"OPENAI_API_KEY"}),"), it will be used unless a saved key overrides it."]})]}),e.jsx("div",{className:"grid grid-cols-1 gap-4",children:Zn.map(v=>{var j,E;const T=(j=i==null?void 0:i.providers)==null?void 0:j[v.id],D=(E=o==null?void 0:o.providers)==null?void 0:E[v.id],A=(T==null?void 0:T.masked)??null,ee=(T==null?void 0:T.source)??"none",ie=ee==="stored",ne=d===v.id,G=y[v.id]&&c[v.id].trim().length>0&&!n.isSaving&&!ne,te=ie&&!n.isSaving&&!ne,pe=ie?"Update":"Save";return e.jsxs("div",{className:"rounded-2xl border border-white/[0.07] bg-white/[0.02] p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("p",{className:"text-body font-semibold text-white",children:v.label}),e.jsx("span",{className:we("rounded-full border px-2 py-0.5 text-micro uppercase tracking-[0.12em]",T!=null&&T.configured?"border-emerald-300/25 bg-emerald-400/10 text-emerald-100":"border-strong bg-white/[0.03] text-secondary"),children:T!=null&&T.configured?"Configured":"Missing"})]}),e.jsxs("p",{className:"mt-1 text-body text-secondary",children:[v.hint," ",e.jsxs("span",{className:"text-muted",children:["Env: ",e.jsx("code",{className:"rounded bg-black/40 px-1",children:v.envVar})]})]}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[ee!=="none"&&e.jsxs("span",{className:"chip",children:["source: ",ee]}),A&&e.jsxs("span",{className:"chip",children:["key: ",A]}),D&&e.jsx("span",{className:we("chip",D.ok?"text-emerald-100":"text-rose-100"),children:D.ok?`ready (${D.modelCount??0} models)`:"not ready"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>p(u=>({...u,[v.id]:!u[v.id]})),className:"rounded-lg border border-strong bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.08]",title:x[v.id]?"Hide key":"Show key",children:x[v.id]?"Hide":"Show"}),e.jsx("button",{type:"button",onClick:()=>void k(),className:"rounded-lg border border-strong bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.08]",title:"Probe configured models",children:"Probe"})]})]}),e.jsxs("div",{className:"mt-3",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"mb-1.5 block text-caption font-medium uppercase tracking-[0.14em] text-muted",children:"API key (stored locally)"}),e.jsx("input",{value:c[v.id],onChange:u=>{l(I=>({...I,[v.id]:u.target.value})),m(I=>({...I,[v.id]:!0})),N&&w(null)},type:x[v.id]?"text":"password",placeholder:`Paste ${v.label} key`,className:"w-full rounded-xl border border-white/[0.08] bg-black/30 px-3 py-2.5 font-mono text-body text-primary placeholder:text-faint focus:border-[#BFFF00]/40 focus:outline-none"})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>void g(v.id),disabled:!G,className:"rounded-full bg-[#BFFF00] px-4 py-2 text-body font-semibold text-black transition-colors hover:bg-[#d3ff42] disabled:cursor-not-allowed disabled:opacity-40",children:ne?"Saving...":pe}),e.jsx("button",{type:"button",onClick:()=>void f(v.id),disabled:!te,className:"rounded-full border border-strong bg-white/[0.03] px-4 py-2 text-body font-semibold text-primary transition-colors hover:bg-white/[0.06] disabled:cursor-not-allowed disabled:opacity-35",children:"Clear stored"}),e.jsx("span",{className:"text-caption text-muted",children:y[v.id]?"Unsaved changes":" "})]})]})]},v.id)})})]})}function to({open:t,onClose:s,activeTab:r,onChangeTab:n,onboarding:i,authToken:o=null,embedMode:c=!1}){return e.jsx(Ge,{open:t,onClose:s,maxWidth:"max-w-4xl",children:e.jsxs("div",{className:"flex h-full min-h-0 w-full min-w-0 flex-1 flex-col",children:[e.jsxs("div",{className:"w-full border-b border-subtle px-5 py-4 sm:px-6",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-heading font-semibold text-white",children:"Settings"}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:"OrgX connection and provider keys for agent launches."})]}),e.jsx("button",{type:"button",onClick:s,"aria-label":"Close settings",className:"inline-flex h-9 w-9 items-center justify-center rounded-full border border-strong bg-white/[0.03] text-primary transition-colors hover:bg-white/[0.08] hover:text-white",children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 6L6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})})]}),e.jsx("div",{className:"mt-4 inline-flex rounded-full border border-white/[0.10] bg-white/[0.03] p-0.5",role:"tablist","aria-label":"Settings tabs",children:[{id:"orgx",label:"OrgX"},{id:"providers",label:"Provider keys"}].map(l=>{const y=r===l.id;return e.jsx("button",{type:"button",role:"tab","aria-selected":y,onClick:()=>n(l.id),className:we("rounded-full px-3 py-1.5 text-caption font-semibold transition-colors",y?"border border-lime/25 bg-lime/[0.14] text-lime shadow-[0_0_16px_rgba(191,255,0,0.08)]":"border border-transparent text-secondary hover:bg-white/[0.06] hover:text-white"),children:l.label},l.id)})})]}),e.jsx("div",{className:"min-h-0 w-full flex-1 overflow-y-auto px-5 py-4 sm:px-6",children:r==="orgx"?e.jsxs("div",{className:"grid gap-4",children:[e.jsx(Xa,{state:i.state,isStarting:i.isStarting,isSubmittingManual:i.isSubmittingManual,onRefresh:i.refreshStatus,onStartPairing:i.startPairing,onSubmitManualKey:i.submitManualKey,onBackToPairing:i.backToPairing,onUseManualKey:i.setManualMode,onDisconnect:i.disconnect}),e.jsx(Ya,{authToken:o,embedMode:c,enabled:t})]}):e.jsx(eo,{authToken:o,embedMode:c,enabled:t})}),e.jsx("div",{className:"w-full border-t border-subtle px-5 py-2.5 sm:px-6",children:e.jsx(Dn,{compact:!0})})]})})}const wn={blocked:0,failed:1,running:2,active:2,queued:3,in_progress:3,pending:4,paused:5,cancelled:6,completed:7,archived:8};function so(t){if(!t)return 0;const s=Date.parse(t);return Number.isFinite(s)?s:0}function vn(t){return so(t.updatedAt??t.lastEventAt??t.startedAt)}function no(t,s){const r=wn[(t.status??"").toLowerCase()]??99,n=wn[(s.status??"").toLowerCase()]??99;return r!==n?r-n:vn(s)-vn(t)}function ro(t,s){const r=t.trim().toLowerCase();return r==="failed"||r==="blocked"||s>0?C.red:r==="running"||r==="active"||r==="in_progress"?C.lime:r==="queued"||r==="pending"?C.amber:r==="completed"?C.teal:C.textMuted}function io(t){switch(t){case"active":return{title:"Active Sessions",subtitle:"Running and queued work across agents."};case"blocked":return{title:"Blocked Sessions",subtitle:"Work that needs attention before it can proceed."};case"failed":return{title:"Failed Sessions",subtitle:"Runs that exited with an error and may need a retry."};default:return{title:"Sessions",subtitle:"All sessions visible to this dashboard."}}}function ao(t,s){var i;const r=(s.status??"").toLowerCase(),n=((i=s.blockers)==null?void 0:i.length)??0;return t==="active"?["running","active","queued","pending","in_progress"].includes(r):t==="blocked"?r==="blocked"||n>0:t==="failed"?r==="failed":!0}function oo({open:t,onClose:s,mode:r,sessions:n,onOpenSession:i,onRunAction:o,onRefetch:c,onSetNotice:l}){const{title:y,subtitle:m}=io(r),[x,p]=a.useState(""),[d,h]=a.useState(new Set),[N,w]=a.useState(null),[F,g]=a.useState(null),[f,k]=a.useState(null);a.useEffect(()=>{t&&(g(null),k(null))},[t]);const v=a.useMemo(()=>n.filter(j=>ao(r,j)),[r,n]),T=a.useMemo(()=>{const j={};for(const L of v){const z=(L.status??"unknown").toLowerCase();j[z]=(j[z]??0)+1}const E=v.filter(L=>{var z;return(L.status??"").toLowerCase()==="blocked"||(((z=L.blockers)==null?void 0:z.length)??0)>0}).length,u=v.filter(L=>(L.status??"").toLowerCase()==="failed").length,I=v.filter(L=>["running","active","queued","pending","in_progress"].includes((L.status??"").toLowerCase())).length;return{total:v.length,active:I,blocked:E,failed:u,byStatus:j}},[v]),D=a.useMemo(()=>{const j=x.trim().toLowerCase(),E=[...v].sort(no);return j?E.filter(u=>[u.title,u.agentName,u.agentId,u.runId,u.lastEventSummary].filter(Boolean).join(" ").toLowerCase().includes(j)):E},[x,v]);a.useEffect(()=>{t&&h(j=>{const E=new Set(D.map(I=>I.id)),u=new Set;for(const I of j)E.has(I)&&u.add(I);return u})},[D,t]);const A=d.size,ee=D.length>0&&D.every(j=>d.has(j.id)),ie=()=>{N||h(j=>D.length===0?j:ee?new Set:new Set(D.map(E=>E.id)))},ne=j=>{N||h(E=>{const u=new Set(E);return u.has(j)?u.delete(j):u.add(j),u})},G=async()=>{if(A===0||N)return;const j=[];for(const u of D){if(!d.has(u.id))continue;const I=u.blockers??[];if(I.length!==0){j.push(`- ${u.title} (${I.length} blocker${I.length===1?"":"s"})`);for(const L of I)j.push(` - ${L}`)}}const E=j.length>0?j.join(`
212
- `):"No blockers found for selected sessions.";try{await navigator.clipboard.writeText(E),g("Copied blockers to clipboard.")}catch{g("Copy failed (clipboard unavailable).")}},te=async j=>{if(A===0||N)return;if(j==="cancel"){k({text:""});return}const E=D.filter(L=>d.has(L.id));g(null),w({action:j,processed:0,total:E.length});let u=0;for(const L of E)try{await o(L,j)}catch{u+=1}finally{w(z=>z&&{...z,processed:Math.min(z.total,z.processed+1)})}const I=E.length-u;w(null),u>0?g(`${j} finished: ${I} ok, ${u} failed.`):g(`${j} finished: ${I} session${I===1?"":"s"}.`);try{await c()}catch{}j==="resume"?l(`Bulk resume requested: ${I} ok${u?`, ${u} failed`:""}.`):j==="pause"&&l(`Bulk pause requested: ${I} ok${u?`, ${u} failed`:""}.`)},pe=async()=>{if(!f||N||f.text.trim().toUpperCase()!=="CANCEL")return;const j=D.filter(I=>d.has(I.id));g(null),w({action:"cancel",processed:0,total:j.length}),k(null);let E=0;for(const I of j)try{await o(I,"cancel")}catch{E+=1}finally{w(L=>L&&{...L,processed:Math.min(L.total,L.processed+1)})}const u=j.length-E;w(null),g(`cancel finished: ${u} ok${E?`, ${E} failed`:""}.`),l(`Bulk cancel requested: ${u} ok${E?`, ${E} failed`:""}.`);try{await c()}catch{}};return e.jsx(Ge,{open:t,onClose:s,maxWidth:"max-w-4xl",children:e.jsxs("div",{className:"flex h-full w-full flex-col",children:[e.jsxs("div",{className:"border-b border-subtle px-5 pt-5 pb-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("h3",{className:"inline-flex items-center gap-2 text-heading font-semibold text-white",children:[e.jsx(Ne,{type:"session",size:14}),e.jsx("span",{className:"truncate",children:y}),e.jsx("span",{className:"rounded-full border border-strong bg-white/[0.04] px-2 py-0.5 text-caption font-semibold text-primary",children:T.total})]}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:m}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-1.5",children:[e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.1] bg-white/[0.03] px-2 py-0.5 text-micro text-secondary",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full",style:{backgroundColor:C.teal}}),"Total ",e.jsx("span",{className:"font-semibold text-white",children:T.total})]}),e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.1] bg-white/[0.03] px-2 py-0.5 text-micro text-secondary",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full",style:{backgroundColor:T.active>0?C.lime:C.textMuted}}),"Active ",e.jsx("span",{className:"font-semibold text-white",children:T.active})]}),e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.1] bg-white/[0.03] px-2 py-0.5 text-micro text-secondary",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full",style:{backgroundColor:T.blocked>0?C.red:C.textMuted}}),"Blocked ",e.jsx("span",{className:"font-semibold text-white",children:T.blocked})]}),e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.1] bg-white/[0.03] px-2 py-0.5 text-micro text-secondary",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full",style:{backgroundColor:T.failed>0?C.red:C.textMuted}}),"Failed ",e.jsx("span",{className:"font-semibold text-white",children:T.failed})]})]})]}),e.jsx("button",{type:"button",onClick:s,className:"rounded-md border border-strong bg-white/[0.03] px-2.5 py-1.5 text-caption text-primary transition-colors hover:bg-white/[0.08]","aria-label":"Close bulk modal",children:"Close"})]}),e.jsxs("div",{className:"mt-4 flex flex-col gap-2 sm:flex-row sm:items-center",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("label",{className:"sr-only",htmlFor:"bulk-sessions-search",children:"Search sessions"}),e.jsx("input",{id:"bulk-sessions-search",value:x,onChange:j=>p(j.target.value),placeholder:"Search title, agent, run id…","data-modal-autofocus":"true",className:"w-full rounded-lg border border-strong bg-black/25 px-3 py-2 text-body text-white placeholder:text-muted focus:outline-none focus:ring-1 focus:ring-[#BFFF00]/35"})]}),e.jsx("button",{type:"button",onClick:ie,disabled:D.length===0||!!N,className:"rounded-lg border border-strong bg-white/[0.03] px-3 py-2 text-caption text-primary transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:ee?"Clear all":`Select all (${D.length})`})]}),F&&e.jsx("div",{className:"mt-3 rounded-xl border border-white/[0.08] bg-white/[0.02] px-3 py-2 text-body text-secondary",children:F}),f&&e.jsxs("div",{className:"mt-3 rounded-xl border border-red-400/25 bg-red-500/[0.06] px-3 py-2.5",children:[e.jsxs("p",{className:"text-body font-semibold text-red-200",children:["Cancel ",A," session",A===1?"":"s","?"]}),e.jsxs("p",{className:"mt-1 text-caption text-red-200/70",children:["This is destructive. Type ",e.jsx("span",{className:"font-semibold",children:"CANCEL"})," to confirm."]}),e.jsxs("div",{className:"mt-2 flex flex-col gap-2 sm:flex-row sm:items-center",children:[e.jsx("input",{value:f.text,onChange:j=>k({text:j.target.value}),placeholder:"CANCEL",className:"flex-1 rounded-lg border border-red-300/25 bg-black/30 px-3 py-2 text-body text-white placeholder:text-muted focus:outline-none focus:ring-1 focus:ring-red-300/40"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>k(null),className:"rounded-lg border border-strong bg-white/[0.03] px-3 py-2 text-caption text-primary transition-colors hover:bg-white/[0.08]",children:"Back"}),e.jsx("button",{type:"button",onClick:pe,disabled:f.text.trim().toUpperCase()!=="CANCEL",className:"rounded-lg border border-red-300/25 bg-red-500/15 px-3 py-2 text-caption font-semibold text-red-200 transition-colors hover:bg-red-500/20 disabled:opacity-45",children:"Confirm cancel"})]})]})]})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-5 py-4",children:D.length===0?e.jsx("div",{className:"rounded-xl border border-subtle bg-white/[0.02] p-4 text-body text-secondary",children:"No sessions match this view."}):e.jsx("div",{className:"space-y-2",children:D.map(j=>{const E=d.has(j.id),u=j.blockers??[],I=ro(j.status??"",u.length),L=j.updatedAt??j.lastEventAt??j.startedAt,z=[(j.agentName??j.agentId??"").trim()||"Unknown agent",(j.status??"unknown").toLowerCase(),L?Ce(L):null].filter(Boolean);return e.jsx("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.02] px-3 py-2.5 transition-colors hover:bg-white/[0.04]",style:{borderColor:E?`${C.lime}40`:"rgba(255,255,255,0.08)"},children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("input",{type:"checkbox",checked:E,onChange:()=>ne(j.id),disabled:!!N,className:"mt-0.5 h-4 w-4 rounded border-white/20 bg-black/40 text-lime focus:ring-lime/40","aria-label":`Select session ${j.title}`}),e.jsx("button",{type:"button",onClick:()=>i(j),disabled:!!N,className:"min-w-0 flex-1 text-left",title:"Open session inspector",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-body font-medium text-white",children:j.title}),e.jsx("p",{className:"mt-0.5 text-caption text-secondary",children:z.join(" · ")}),j.lastEventSummary&&e.jsx("p",{className:"mt-1 line-clamp-2 text-caption text-secondary",children:j.lastEventSummary}),u.length>0&&e.jsxs("p",{className:"mt-1 text-micro text-red-200/80",children:[u.length," blocker",u.length===1?"":"s"," · ",u[0]]})]}),e.jsx("span",{className:"shrink-0 rounded-full border px-2 py-0.5 text-micro font-semibold uppercase tracking-[0.08em]",style:{borderColor:`${I}30`,backgroundColor:`${I}14`,color:I},children:(j.status??"unknown").toUpperCase()})]})})]})},j.id)})})}),e.jsxs("div",{className:"flex flex-col gap-2 border-t border-subtle px-5 py-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2 text-caption text-secondary",children:[N?e.jsxs("span",{children:[N.action," ",N.processed,"/",N.total]}):e.jsx("span",{children:A>0?`${A} selected`:"No selection"}),r==="blocked"&&e.jsx("button",{type:"button",onClick:G,disabled:A===0||!!N,className:"rounded-md border border-strong bg-white/[0.03] px-2.5 py-1.5 text-caption text-secondary transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:"Copy blockers"})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:()=>{const j=D.find(E=>d.has(E.id))??null;j&&i(j)},disabled:A!==1||!!N,className:"rounded-md border border-strong bg-white/[0.03] px-3 py-1.5 text-caption text-primary transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:"Open inspector"}),e.jsx("button",{type:"button",onClick:()=>void te("resume"),disabled:A===0||!!N,className:"rounded-md border border-lime/25 bg-lime/10 px-3 py-1.5 text-caption font-semibold text-lime transition-colors hover:bg-lime/20 disabled:opacity-45",children:"Resume selected"}),e.jsx("button",{type:"button",onClick:()=>void te("pause"),disabled:A===0||!!N,className:"rounded-md border border-strong bg-white/[0.03] px-3 py-1.5 text-caption text-primary transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:"Pause selected"}),e.jsx("button",{type:"button",onClick:()=>void te("cancel"),disabled:A===0||!!N,className:"rounded-md border border-red-300/25 bg-red-500/10 px-3 py-1.5 text-caption font-semibold text-red-200 transition-colors hover:bg-red-500/15 disabled:opacity-45",children:"Cancel selected"})]})]})]})})}function lo({open:t,onClose:s,decisions:r,onApproveDecision:n,onApproveAll:i}){const o=a.useMemo(()=>r.length>0?Math.max(0,...r.map(l=>l.waitingMinutes)):0,[r]),c=a.useMemo(()=>r.length>=20||o>=15?C.red:r.length>0?C.amber:C.textMuted,[r.length,o]);return e.jsx(Ge,{open:t,onClose:s,maxWidth:"max-w-3xl",children:e.jsxs("div",{className:"flex h-full w-full flex-col",children:[e.jsx("div",{className:"border-b border-subtle px-5 pt-5 pb-4",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("h3",{className:"inline-flex items-center gap-2 text-heading font-semibold text-white",children:[e.jsx(Ne,{type:"decision",size:14}),e.jsx("span",{className:"truncate",children:"Decisions"}),e.jsx("span",{className:"rounded-full border px-2 py-0.5 text-caption font-semibold",style:{borderColor:`${c}30`,backgroundColor:`${c}14`,color:c},children:r.length})]}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:"Bulk review and resolve pending decisions."}),r.length>0&&e.jsxs("p",{className:"mt-2 text-caption text-secondary",children:["Longest waiting: ",e.jsxs("span",{className:"font-semibold text-white",children:[o,"m"]})]})]}),e.jsx("button",{type:"button",onClick:s,className:"rounded-md border border-strong bg-white/[0.03] px-2.5 py-1.5 text-caption text-primary transition-colors hover:bg-white/[0.08]","aria-label":"Close decisions modal",children:"Close"})]})}),e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden p-4",children:e.jsx(Vn,{decisions:r,onApproveDecision:n,onApproveAll:i})})]})})}function jn(t){if(!t)return"unknown";try{return Ce(t)}catch{return"unknown"}}function co({open:t,onClose:s,outbox:r,onOpenSettings:n,onRefresh:i}){const[o,c]=a.useState(!1),l=a.useMemo(()=>Object.entries(r.pendingByQueue??{}).filter(([,p])=>typeof p=="number"&&p>0).sort((p,d)=>d[1]-p[1]),[r.pendingByQueue]),y=a.useMemo(()=>r.replayStatus==="error"?C.red:r.pendingTotal>0?C.amber:C.textMuted,[r.pendingTotal,r.replayStatus]),m=async()=>{try{await navigator.clipboard.writeText(JSON.stringify(r,null,2)),c(!0),setTimeout(()=>c(!1),1200)}catch{}};return e.jsx(Ge,{open:t,onClose:s,maxWidth:"max-w-3xl",fitContent:!0,children:e.jsxs("div",{className:"flex w-full flex-col",children:[e.jsxs("div",{className:"border-b border-subtle px-5 pt-5 pb-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("h3",{className:"inline-flex items-center gap-2 text-heading font-semibold text-white",children:[e.jsx(Ne,{type:"outbox",size:14}),e.jsx("span",{className:"truncate",children:"Outbox"}),e.jsx("span",{className:"rounded-full border px-2 py-0.5 text-caption font-semibold",style:{borderColor:`${y}30`,backgroundColor:`${y}14`,color:y},children:r.pendingTotal})]}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:"Buffered updates queued for replay to OrgX when connectivity is healthy."})]}),e.jsx("button",{type:"button",onClick:s,className:"rounded-md border border-strong bg-white/[0.03] px-2.5 py-1.5 text-caption text-primary transition-colors hover:bg-white/[0.08]","aria-label":"Close outbox modal",children:"Close"})]}),e.jsxs("div",{className:"mt-3 grid grid-cols-1 gap-2 sm:grid-cols-2",children:[e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.02] px-3 py-2",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-secondary",children:"Replay status"}),e.jsx("p",{className:"mt-1 text-body font-semibold",style:{color:y},children:r.replayStatus}),r.lastReplayError&&r.replayStatus==="error"&&e.jsx("p",{className:"mt-1 line-clamp-2 text-caption text-red-200/75",children:r.lastReplayError})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.02] px-3 py-2",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-secondary",children:"Window"}),e.jsxs("p",{className:"mt-1 text-caption text-primary",children:["Oldest: ",e.jsx("span",{className:"font-semibold text-white",children:jn(r.oldestEventAt)})]}),e.jsxs("p",{className:"mt-0.5 text-caption text-primary",children:["Newest: ",e.jsx("span",{className:"font-semibold text-white",children:jn(r.newestEventAt)})]})]})]})]}),e.jsx("div",{className:"px-5 py-4",children:r.pendingTotal===0?e.jsx("div",{className:"rounded-xl border border-subtle bg-white/[0.02] p-4 text-body text-secondary",children:"Outbox is empty."}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-caption font-semibold uppercase tracking-[0.12em] text-secondary",children:"Queues"}),e.jsx("button",{type:"button",onClick:m,className:"rounded-md border border-strong bg-white/[0.03] px-2.5 py-1.5 text-caption text-secondary transition-colors hover:bg-white/[0.08]",children:o?"Copied":"Copy JSON"})]}),e.jsx("div",{className:"space-y-1.5",children:l.map(([x,p])=>e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-xl border border-white/[0.08] bg-white/[0.02] px-3 py-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-body font-medium text-white",children:x}),e.jsxs("p",{className:"mt-0.5 text-micro text-secondary",children:[p," event",p===1?"":"s"]})]}),e.jsx("span",{className:"rounded-full border px-2 py-0.5 text-caption font-semibold",style:{borderColor:`${C.amber}30`,backgroundColor:`${C.amber}14`,color:C.amber},children:p})]},x))}),e.jsx("div",{className:"rounded-xl border border-subtle bg-white/[0.02] px-3 py-2 text-caption text-secondary",children:"Replay is handled automatically by the OrgX sync service. If events stay queued, check Settings for API key and last replay errors."})]})}),e.jsxs("div",{className:"flex items-center justify-end gap-2 border-t border-subtle px-5 py-3",children:[e.jsx("button",{type:"button",onClick:i,className:"rounded-md border border-strong bg-white/[0.03] px-3 py-1.5 text-caption text-primary transition-colors hover:bg-white/[0.08]",children:"Refresh"}),e.jsx("button",{type:"button",onClick:n,className:"rounded-md border border-lime/25 bg-lime/10 px-3 py-1.5 text-caption font-semibold text-lime transition-colors hover:bg-lime/20",children:"Open settings"})]})]})})}function uo(t){const s=t.trim().toLowerCase();return s==="fulfilled"||s==="completed"?C.lime:s==="claimed"?C.teal:s==="blocked"?C.red:C.amber}function po({open:t,onClose:s,handoffs:r}){const[n,i]=a.useState(""),[o,c]=a.useState(new Set),[l,y]=a.useState(null);a.useEffect(()=>{t&&y(null)},[t]);const m=a.useMemo(()=>[...r].sort((g,f)=>Date.parse(f.updatedAt??"")-Date.parse(g.updatedAt??"")),[r]),x=a.useMemo(()=>{const g=n.trim().toLowerCase();return g?m.filter(f=>[f.title,f.summary,f.status,f.priority].filter(Boolean).join(" ").toLowerCase().includes(g)):m},[m,n]);a.useEffect(()=>{t&&c(g=>{const f=new Set(x.map(v=>v.id)),k=new Set;for(const v of g)f.has(v)&&k.add(v);return k})},[x,t]);const p=o.size,d=x.length>0&&x.every(g=>o.has(g.id)),h=()=>{c(g=>x.length===0?g:d?new Set:new Set(x.map(f=>f.id)))},N=g=>{c(f=>{const k=new Set(f);return k.has(g)?k.delete(g):k.add(g),k})},w=async()=>{const g=x.filter(v=>p===0||o.has(v.id)),f=[];f.push(`# Handoffs (${g.length})`),f.push("");for(const v of g)f.push(`- **${v.title}** — ${v.status}${v.priority?` (priority: ${v.priority})`:""}`),v.summary&&f.push(` - ${v.summary}`),f.push(` - Updated: ${v.updatedAt}`);const k=f.join(`
213
- `);try{await navigator.clipboard.writeText(k),y("Copied markdown."),setTimeout(()=>y(null),1200)}catch{y("Copy failed (clipboard unavailable).")}},F=async()=>{const g=x.filter(f=>p===0||o.has(f.id));try{await navigator.clipboard.writeText(JSON.stringify(g,null,2)),y("Copied JSON."),setTimeout(()=>y(null),1200)}catch{y("Copy failed (clipboard unavailable).")}};return e.jsx(Ge,{open:t,onClose:s,maxWidth:"max-w-3xl",children:e.jsxs("div",{className:"flex h-full w-full flex-col",children:[e.jsxs("div",{className:"border-b border-subtle px-5 pt-5 pb-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("h3",{className:"inline-flex items-center gap-2 text-heading font-semibold text-white",children:[e.jsx(Ne,{type:"handoff",size:14}),e.jsx("span",{className:"truncate",children:"Handoffs"}),e.jsx("span",{className:"rounded-full border border-strong bg-white/[0.04] px-2 py-0.5 text-caption font-semibold text-primary",children:r.length})]}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:"Review and export current handoffs. Select items for a tighter export."})]}),e.jsx("button",{type:"button",onClick:s,className:"rounded-md border border-strong bg-white/[0.03] px-2.5 py-1.5 text-caption text-primary transition-colors hover:bg-white/[0.08]","aria-label":"Close handoffs modal",children:"Close"})]}),e.jsxs("div",{className:"mt-4 flex flex-col gap-2 sm:flex-row sm:items-center",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("label",{className:"sr-only",htmlFor:"bulk-handoffs-search",children:"Search handoffs"}),e.jsx("input",{id:"bulk-handoffs-search",value:n,onChange:g=>i(g.target.value),placeholder:"Search title, summary, status…","data-modal-autofocus":"true",className:"w-full rounded-lg border border-strong bg-black/25 px-3 py-2 text-body text-white placeholder:text-muted focus:outline-none focus:ring-1 focus:ring-[#BFFF00]/35"})]}),e.jsx("button",{type:"button",onClick:h,disabled:x.length===0,className:"rounded-lg border border-strong bg-white/[0.03] px-3 py-2 text-caption text-primary transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:d?"Clear all":`Select all (${x.length})`})]}),l&&e.jsx("div",{className:"mt-3 rounded-xl border border-white/[0.08] bg-white/[0.02] px-3 py-2 text-body text-secondary",children:l})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-5 py-4",children:x.length===0?e.jsx("div",{className:"rounded-xl border border-subtle bg-white/[0.02] p-4 text-body text-secondary",children:"No handoffs match this view."}):e.jsx("div",{className:"space-y-2",children:x.map(g=>{const f=o.has(g.id),k=uo(g.status);return e.jsx("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.02] px-3 py-2.5",style:{borderColor:f?`${C.lime}40`:"rgba(255,255,255,0.08)"},children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("input",{type:"checkbox",checked:f,onChange:()=>N(g.id),className:"mt-0.5 h-4 w-4 rounded border-white/20 bg-black/40 text-lime focus:ring-lime/40","aria-label":`Select handoff ${g.title}`}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-body font-medium text-white",children:g.title}),g.summary&&e.jsx("p",{className:"mt-1 line-clamp-2 text-caption text-secondary",children:g.summary}),e.jsxs("p",{className:"mt-1 text-micro text-secondary",children:["Updated ",Ce(g.updatedAt)]})]}),e.jsx("span",{className:"shrink-0 rounded-full border px-2 py-0.5 text-micro font-semibold uppercase tracking-[0.08em]",style:{borderColor:`${k}30`,backgroundColor:`${k}14`,color:k},children:g.status})]})})]})},g.id)})})}),e.jsxs("div",{className:"flex flex-col gap-2 border-t border-subtle px-5 py-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx("div",{className:"text-caption text-secondary",children:p>0?`${p} selected`:"No selection (exporting will include all filtered handoffs)"}),e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:w,disabled:x.length===0,className:"rounded-md border border-strong bg-white/[0.03] px-3 py-1.5 text-caption text-primary transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:"Copy markdown"}),e.jsx("button",{type:"button",onClick:F,disabled:x.length===0,className:"rounded-md border border-strong bg-white/[0.03] px-3 py-1.5 text-caption text-primary transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:"Copy JSON"})]})]})]})})}const mo=a.lazy(async()=>({default:(await rs(()=>import("./CyxZio4Y.js"),__vite__mapDeps([0,1,2,3,4]))).MissionControlView})),xo=a.lazy(async()=>({default:(await rs(()=>import("./Bm8QnMJ_.js"),__vite__mapDeps([5,1,2,3,4]))).SessionInspector})),kn={connected:"Live",reconnecting:"Reconnecting",disconnected:"Offline"},ho={connected:C.lime,reconnecting:C.amber,disconnected:C.red},Ms="orgx.mission_control.welcome.dismissed",Fs="orgx.demo_mode",_s="orgx.first_run_guide.shown_session",$s="orgx.dashboard.sidebar.nextup.compact",Nn={blocked:0,pending:1,queued:2,running:3,failed:4,cancelled:5,completed:6,archived:7},fo=new Set(["running","active","queued","pending","in_progress","working","planning"]);function ut(t){if(!t)return 0;const s=Date.parse(t);return Number.isFinite(s)?s:0}function go(t){const s=ut(t);if(!s)return"unknown";try{return new Date(s).toLocaleString()}catch{return"unknown"}}function Ts(t,s){const r=Nn[t.status]??99,n=Nn[s.status]??99;return r!==n?r-n:ut(t.updatedAt??t.lastEventAt??t.startedAt)-ut(s.updatedAt??s.lastEventAt??s.startedAt)}function bo(t){const s=t.toLowerCase();return s==="blocked"||s==="failed"?"blocked":s==="running"||s==="active"||s==="in_progress"?"working":s==="pending"||s==="queued"?"waiting":s==="completed"||s==="done"?"done":"idle"}function yo(){const t=Dr();return t.showGate?e.jsx(ei,{state:t.state,isLoading:t.isLoading,isStarting:t.isStarting,isSubmittingManual:t.isSubmittingManual,onRefresh:t.refreshStatus,onStartPairing:t.startPairing,onSubmitManualKey:t.submitManualKey,onBackToPairing:t.backToPairing,onUseManualKey:t.setManualMode,onSkip:t.skipGate}):e.jsx(ko,{onboarding:t})}function wo(t){const s=t.toLowerCase();return/market|email|campaign|content|brand/.test(s)?"Marketing":/product|feature|ux|discovery/.test(s)?"Product":/engineer|infra|platform|api|backend|frontend|dev/.test(s)?"Engineering":"Program"}function vo(t){return t==="Marketing"?["Brief","Draft","Review","Ship"]:t==="Engineering"?["Spec","Dev","QA","Deploy"]:t==="Product"?["Brief","Define","Build","Ship"]:["Plan","Build","Review","Ship"]}function Sn(t){const s=(t??"").trim().toLowerCase();return s?s==="critical"||s==="p0"||s==="urgent"?0:s==="high"||s==="p1"?1:s==="medium"||s==="normal"||s==="p2"?2:s==="low"||s==="p3"?3:4:4}function Cn(t){const s=(t??"").trim().toLowerCase();return s?!["deleted","archived","cancelled"].includes(s):!0}function jo(){return e.jsx("span",{className:"inline-flex h-6 w-6 items-center justify-center rounded-lg border border-strong bg-white/[0.04] p-0.5",children:e.jsx("img",{src:cs,alt:"OrgX",className:"h-full w-full rounded-md object-contain"})})}function ko({onboarding:t}){const[s,r]=a.useState(()=>{if(typeof window>"u")return!1;if(new URLSearchParams(window.location.search).get("demo")==="1")return!0;try{return window.localStorage.getItem(Fs)==="1"}catch{return!1}}),n=s||t.state.hasApiKey&&t.state.connectionVerified,{data:i,isLoading:o,error:c,refetch:l,approveDecision:y,approveAllDecisions:m}=Ar({useMock:s,enabled:!0,enableDecisions:n}),x=n&&i.connection==="connected",[p,d]=a.useState(null),[h,N]=a.useState(!1),[w,F]=a.useState(null),[g,f]=a.useState(null),[k,v]=a.useState(null),[T,D]=a.useState("all"),[A,ee]=a.useState(null),[ie,ne]=a.useState(null),[G,te]=a.useState(!1),[pe,j]=a.useState([]),E=a.useRef(null),u=a.useRef(null),[I,L]=a.useState({open:!1,tab:"orgx"}),[z,R]=a.useState(null),[me,re]=a.useState(!1),[X,K]=a.useState("agents"),[Ae,le]=a.useState("decisions"),[Ie,P]=a.useState(()=>typeof window>"u"?!1:window.localStorage.getItem($s)==="1"),[ce,$]=a.useState("next_up"),[S,V]=a.useState(()=>typeof window>"u"?!1:window.localStorage.getItem(Ms)==="1"),Y=a.useMemo(()=>{const b=new Set(["running","active","in_progress","working","planning","dispatching","blocked"]);let O=0;for(const Z of i.sessions.nodes){const M=rt(Z.status??"");M==="queued"||M==="pending"||(b.has(M)||Z.lastHeartbeatAt)&&(O+=1)}return O},[i.sessions.nodes]);a.useEffect(()=>{ce==="in_progress"&&Y===0&&$("next_up")},[ce,Y]),a.useEffect(()=>{if(!(typeof window>"u"))try{Ie?window.localStorage.setItem($s,"1"):window.localStorage.removeItem($s)}catch{}},[Ie]),a.useEffect(()=>{typeof window>"u"||(S?window.localStorage.setItem(Ms,"1"):window.localStorage.removeItem(Ms))},[S]),a.useEffect(()=>{if(!(typeof window>"u"))try{s?window.localStorage.setItem(Fs,"1"):window.localStorage.removeItem(Fs)}catch{}},[s]),a.useEffect(()=>{if(!(typeof window>"u")&&!me&&!si()){try{if(window.sessionStorage.getItem(_s)==="1")return}catch{}if(s||t.state.connectionVerified){re(!0);try{window.sessionStorage.setItem(_s,"1")}catch{}}}},[s,me,t.state.connectionVerified]);const W=a.useCallback(b=>{L(O=>({open:!0,tab:b??O.tab}))},[]),ke=a.useCallback(()=>{W("orgx")},[W]),Se=a.useCallback(()=>{rs(()=>import("./CyxZio4Y.js"),__vite__mapDeps([0,1,2,3,4]))},[]),[ye,Ye]=a.useState(()=>{if(new URLSearchParams(window.location.search).get("view")==="mission-control")return"mission-control";try{if(localStorage.getItem("orgx-dashboard-view")==="mission-control")return"mission-control"}catch{}return"activity"}),Me=a.useCallback(b=>{Ye(b);try{localStorage.setItem("orgx-dashboard-view",b)}catch{}},[]),{data:Ze}=Rn(ye==="mission-control"),{data:q}=Va(ye==="mission-control"),{data:H=[]}=it({queryKey:["initiative-tombstones"],queryFn:async()=>[],initialData:[],staleTime:Number.POSITIVE_INFINITY}),[he,ge]=a.useState(null),[se,xe]=a.useState(""),[ae,De]=a.useState(!1),ze=a.useCallback((b,O)=>{ge({type:b,initiativeId:O}),xe(""),De(!1)},[]),ft=a.useCallback(()=>{ge(null),xe(""),De(!1)},[]),ds=a.useCallback(()=>{F(null)},[]),zt=a.useCallback(()=>{f(null),v(null)},[]);a.useEffect(()=>{var Z;const b=((Z=i.sessions.nodes[0])==null?void 0:Z.id)??null;if(!b){p!==null&&d(null);return}if(p===null){d(b);return}i.sessions.nodes.some(M=>M.id===p)||d(b)},[i.sessions.nodes,p]),a.useEffect(()=>{if(!w)return;i.sessions.nodes.some(O=>O.id===w)||F(null)},[w,i.sessions.nodes]);const Ve=a.useCallback(b=>{rs(()=>import("./Bm8QnMJ_.js"),__vite__mapDeps([5,1,2,3,4])),d(b),N(!0),F(b),f(null),v(null)},[]),He=a.useCallback(b=>{const O=b.trim();if(!O)return;const Z=i.sessions.nodes.find(M=>M.runId===O||M.id===O)??null;Z&&(Ve(Z.id),ne(`Focused session: ${Z.title}`))},[i.sessions.nodes,Ve]),U=a.useMemo(()=>i.sessions.nodes.find(b=>b.id===w)??null,[w,i.sessions.nodes]),at=Fr({seed:i.activity,timeFilterId:T,runId:(U==null?void 0:U.runId)??null,pageSize:200}),de=a.useMemo(()=>i.sessions.nodes.find(b=>b.id===p)??null,[i.sessions.nodes,p]),je=a.useMemo(()=>i.sessions.nodes.filter(b=>fo.has(b.status)).length,[i.sessions.nodes]),kt=a.useMemo(()=>i.sessions.nodes.filter(b=>b.status==="blocked"||b.blockers.length>0).length,[i.sessions.nodes]),Nt=a.useMemo(()=>i.sessions.nodes.filter(b=>b.status==="failed").length,[i.sessions.nodes]),St=a.useMemo(()=>{const b=[{id:"sessions",label:"Sessions",value:i.sessions.nodes.length,color:C.teal,icon:"session"},{id:"active",label:"Active",value:je,color:je>0?C.lime:C.textMuted,icon:"active"},{id:"blocked",label:"Blocked",value:kt,color:kt>0?C.red:C.textMuted,icon:"blocked"},{id:"failed",label:"Failed",value:Nt,color:Nt>0?C.red:C.textMuted,icon:"failed"},{id:"decisions",label:"Decisions",value:x?i.decisions.length:0,color:x&&i.decisions.length>0?C.amber:C.textMuted,icon:"decision"},{id:"outbox",label:"Outbox",value:i.outbox.pendingTotal,color:i.outbox.replayStatus==="error"?C.red:i.outbox.pendingTotal>0?C.amber:C.textMuted,icon:"outbox"}];return i.handoffs.length>0&&b.push({id:"handoffs",label:"Handoffs",value:i.handoffs.length,color:C.iris,icon:"handoff"}),b},[je,kt,Nt,i.decisions.length,i.handoffs.length,i.outbox.pendingTotal,i.outbox.replayStatus,i.sessions.nodes.length,x]),et=a.useMemo(()=>i.decisions.length>0?Math.max(0,...i.decisions.map(b=>b.waitingMinutes)):0,[i.decisions]),Ue=a.useMemo(()=>{const b=[];return c&&b.push({id:`stream-error:${c}`,kind:"error",icon:"notification",title:"Live stream degraded",message:c,actionLabel:"Settings",onAction:()=>W("orgx")}),i.connection!=="connected"&&b.push({id:`connection:${i.connection}`,kind:i.connection==="disconnected"?"error":"info",icon:"notification",title:i.connection==="disconnected"?"Connection lost":"Reconnecting",message:i.connection==="disconnected"?"Dashboard is offline. Some data may be stale.":"Live data is recovering. Some sections may be delayed.",actionLabel:"Reconnect",onAction:ke}),i.outbox.pendingTotal>0&&b.push({id:`outbox:pending:${i.outbox.pendingTotal}`,kind:"info",icon:"notification",title:"Buffered updates pending",message:`${i.outbox.pendingTotal} event(s) queued for replay.`}),i.outbox.replayStatus==="error"&&i.outbox.lastReplayError&&b.push({id:`outbox:error:${i.outbox.lastReplayError}`,kind:"error",icon:"notification",title:"Outbox replay failed",message:i.outbox.lastReplayError,actionLabel:"Settings",onAction:()=>W("orgx")}),ie&&b.push({id:`ops:${ie}`,kind:"info",icon:/decision/i.test(ie)?"decision":"workstream",title:"Update",message:ie}),b},[i.connection,i.outbox.lastReplayError,i.outbox.pendingTotal,i.outbox.replayStatus,c,ke,W,ie]);a.useEffect(()=>{const b=new Set(Ue.map(O=>O.id));j(O=>O.filter(Z=>b.has(Z)))},[Ue]);const tt=a.useMemo(()=>Ue.filter(b=>!pe.includes(b.id)),[pe,Ue]),Ft=a.useCallback(b=>{j(O=>O.includes(b)?O:O.concat(b))},[]),us=a.useCallback(()=>{j(Ue.map(b=>b.id))},[Ue]);a.useEffect(()=>{if(!G)return;const b=Z=>{var oe,fe;const M=Z.target;M&&((oe=u.current)!=null&&oe.contains(M)||(fe=E.current)!=null&&fe.contains(M)||te(!1))},O=Z=>{Z.key==="Escape"&&te(!1)};return document.addEventListener("mousedown",b),document.addEventListener("touchstart",b),document.addEventListener("keydown",O),()=>{document.removeEventListener("mousedown",b),document.removeEventListener("touchstart",b),document.removeEventListener("keydown",O)}},[G]);const Oe=a.useMemo(()=>{var Z;const b=new Map;for(const M of i.sessions.nodes){const oe=M.initiativeId??M.groupId??"unscoped",fe=M.groupLabel&&M.groupLabel.trim().length>0?M.groupLabel:M.initiativeId??"Unscoped Initiative",$e=wo(fe),ve=b.get(oe)??{id:oe,name:fe,category:$e,progressTotal:0,progressCount:0,statusCounts:{},activeAgents:new Set,allAgents:new Set,workstreams:new Map,latestEpoch:0};if(M.progress!==null&&(ve.progressTotal+=M.progress,ve.progressCount+=1),ve.statusCounts[M.status]=(ve.statusCounts[M.status]??0)+1,M.agentName&&(ve.allAgents.add(M.agentName),["running","queued","pending","blocked"].includes(M.status)&&ve.activeAgents.add(M.agentName)),M.workstreamId){const Pe=i.sessions.groups.find(mt=>mt.id===M.workstreamId),Je=((Z=Pe==null?void 0:Pe.label)==null?void 0:Z.trim())||M.workstreamId;ve.workstreams.set(M.workstreamId,Je)}ve.latestEpoch=Math.max(ve.latestEpoch,ut(M.updatedAt??M.lastEventAt??M.startedAt)),b.set(oe,ve)}const O=[];for(const M of b.values()){const oe=M.progressCount>0?Math.round(M.progressTotal/M.progressCount):M.statusCounts.completed?100:M.statusCounts.running?55:0,fe=M.category,$e=vo(fe),ve=Math.round(Math.max(0,Math.min(100,oe))/100*($e.length-1)),Pe=(M.statusCounts.blocked??0)>0,Je=(M.statusCounts.completed??0)>0&&(M.statusCounts.running??0)===0&&(M.statusCounts.queued??0)===0&&(M.statusCounts.pending??0)===0&&(M.statusCounts.blocked??0)===0&&(M.statusCounts.paused??0)===0,mt=!Je&&!Pe&&(M.statusCounts.paused??0)>0&&(M.statusCounts.running??0)===0&&(M.statusCounts.queued??0)===0&&(M.statusCounts.pending??0)===0,er=$e.map((ps,Wt)=>{let ms="upcoming";return(Je||Wt<ve)&&(ms="completed"),Wt===ve&&!Je&&(ms=Pe?"warning":"current"),{name:ps,status:ms}});O.push({id:M.id,name:M.name,status:Je?"completed":Pe?"blocked":mt?"paused":"active",rawStatus:Je?"completed":Pe?"blocked":mt?"paused":"active",category:fe,health:Math.max(0,Math.min(100,oe)),phases:er,currentPhase:Je?$e.length-1:ve,daysRemaining:0,targetDate:null,createdAt:M.latestEpoch>0?new Date(M.latestEpoch).toISOString():null,updatedAt:M.latestEpoch>0?new Date(M.latestEpoch).toISOString():null,activeAgents:M.activeAgents.size,totalAgents:M.allAgents.size,avatars:Array.from(M.activeAgents).slice(0,3),description:`${M.workstreams.size} workstreams are active right now.`,workstreams:Array.from(M.workstreams.entries()).map(([ps,Wt])=>({id:ps,name:Wt,status:"active"}))})}return O.sort((M,oe)=>{const fe=M.status==="blocked"?0:M.status==="active"?1:2,$e=oe.status==="blocked"?0:oe.status==="active"?1:2;return fe!==$e?fe-$e:oe.health-M.health})},[i.sessions.nodes,i.sessions.groups]),Ct=a.useMemo(()=>{const b=(M,oe)=>{var fe,$e;return{...M,...oe,health:oe.health>0?oe.health:M.health,activeAgents:Math.max(M.activeAgents,oe.activeAgents),totalAgents:Math.max(M.totalAgents,oe.totalAgents),avatars:(fe=M.avatars)!=null&&fe.length?M.avatars:oe.avatars,workstreams:($e=M.workstreams)!=null&&$e.length?M.workstreams:oe.workstreams,description:M.description??oe.description,rawStatus:oe.rawStatus??M.rawStatus??null,targetDate:oe.targetDate??M.targetDate??null,createdAt:oe.createdAt??M.createdAt??null,updatedAt:oe.updatedAt??M.updatedAt??null}},O=new Map;for(const M of Oe)O.set(M.id,M);for(const M of[...q??[],...Ze??[]]){const oe=M.rawStatus??M.status;if(!Cn(oe)){O.delete(M.id);continue}const fe=O.get(M.id);O.set(M.id,fe?b(fe,M):M)}const Z=new Set(H);return Array.from(O.values()).filter(M=>!Z.has(M.id)).filter(M=>Cn(M.rawStatus??M.status)).sort((M,oe)=>{const fe=mt=>mt==="blocked"?0:mt==="active"?1:mt==="paused"?2:3,$e=fe(M.status)-fe(oe.status);if($e!==0)return $e;const ve=Sn(M.priority)-Sn(oe.priority);if(ve!==0)return ve;const Pe=ut(oe.updatedAt)-ut(M.updatedAt);if(Pe!==0)return Pe;const Je=oe.health-M.health;return Je!==0?Je:M.name.localeCompare(oe.name)})},[Oe,Ze,q,H]),pt=a.useMemo(()=>{if(!U)return null;const b=U.agentName,O=U.title;if(b){const Z=i.activity.find(M=>{var oe;return M.runId===U.runId&&((oe=M.summary)==null?void 0:oe.trim())});if(Z!=null&&Z.summary){const M=Z.summary.trim().length>40?Z.summary.trim().slice(0,40)+"…":Z.summary.trim();return`${b}: ${M}`}return b}if(O){const Z=O.replace(/^(telegram|slack|discord|whatsapp|email|sms):/,"").trim();if(Z.length>0)return Z}return O??null},[i.activity,U]),Ut=a.useMemo(()=>{const b=new Map;for(const O of i.sessions.nodes){const Z=(O.agentId??"").trim()||`name:${(O.agentName??"").trim()}`,M=(O.agentName??"").trim()||(O.agentId??"").trim();if(!M)continue;const oe=O.updatedAt??O.lastEventAt??O.startedAt??new Date().toISOString(),fe=ut(oe),$e=fe?Math.max(0,Math.floor((Date.now()-fe)/6e4)):0,ve=b.get(Z),Pe={id:Z,name:M,role:"Agent",status:bo(O.status),task:O.title??null,progress:O.progress??null,lastActive:oe,lastActiveMinutes:$e};(!ve||ut(Pe.lastActive)>ut(ve.lastActive))&&b.set(Z,Pe)}return Array.from(b.values())},[i.sessions.nodes]),_=t.state.connectionVerified&&!S,J=a.useCallback(async()=>{if(i.sessions.nodes.length===0){ne("No sessions available to continue.");return}const b=[...i.sessions.nodes].sort(Ts)[0];if(d(b.id),F(b.id),f(null),v(null),["blocked","pending","queued"].includes(b.status))try{await fetch(`/orgx/api/runs/${encodeURIComponent(b.runId)}/actions/resume`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({reason:"continue_from_dashboard"})})}catch{}ne(`Focused highest priority session: ${b.title}`),await l()},[i.sessions.nodes,l]),B=a.useCallback(async b=>{if(d(b.id),F(b.id),f(null),v(null),!["running","completed","archived"].includes(b.status))try{await fetch(`/orgx/api/runs/${encodeURIComponent(b.runId)}/actions/resume`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({reason:"dispatch_from_dashboard"})})}catch{}ne(`Dispatch requested: ${b.title}`),await l()},[l]),Q=a.useCallback(async(b,O,Z={})=>{const M=await fetch(`/orgx/api/runs/${encodeURIComponent(b.runId)}/actions/${O}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Z)});if(!M.ok){const oe=await M.json().catch(()=>null);throw new Error((oe==null?void 0:oe.error)??`${O} failed (${M.status})`)}},[]),be=a.useCallback(async b=>{var oe;const O=await fetch(`/orgx/api/runs/${encodeURIComponent(b.runId)}/checkpoints`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({reason:"dashboard_manual_checkpoint"})});if(!O.ok){const fe=await O.json().catch(()=>null);throw new Error((fe==null?void 0:fe.error)??`Checkpoint creation failed (${O.status})`)}const Z=await O.json().catch(()=>null),M=Z&&"data"in Z&&((oe=Z.data)==null?void 0:oe.id)||Z&&"id"in Z&&Z.id||null;ne(M?`Checkpoint created: ${M.slice(0,8)}`:"Checkpoint created."),await l()},[l]),Fe=a.useCallback(async b=>{await Q(b,"pause",{reason:"pause_from_dashboard"}),ne(`Pause requested: ${b.title}`),await l()},[l,Q]),st=a.useCallback(async b=>{await Q(b,"resume",{reason:"resume_from_dashboard"}),ne(`Resume requested: ${b.title}`),await l()},[l,Q]),Le=a.useCallback(async b=>{await Q(b,"cancel",{reason:"cancel_from_dashboard"}),ne(`Cancel requested: ${b.title}`),await l()},[l,Q]),Re=a.useCallback(async b=>{var $e;const O=await fetch(`/orgx/api/runs/${encodeURIComponent(b.runId)}/checkpoints`,{method:"GET"});if(!O.ok){const ve=await O.json().catch(()=>null);throw new Error((ve==null?void 0:ve.error)??`Checkpoint list failed (${O.status})`)}const Z=await O.json().catch(()=>null),fe=($e=(Array.isArray(Z)?Z:Array.isArray(Z==null?void 0:Z.data)?Z.data:[]).map(ve=>({id:typeof ve.id=="string"?ve.id:"",createdAt:typeof ve.createdAt=="string"?ve.createdAt:typeof ve.created_at=="string"?ve.created_at:""})).filter(ve=>ve.id.length>0).sort((ve,Pe)=>Date.parse(Pe.createdAt)-Date.parse(ve.createdAt))[0])==null?void 0:$e.id;if(!fe)throw new Error("No checkpoint available for rollback.");await Q(b,"rollback",{checkpointId:fe,reason:"rollback_from_dashboard"}),ne(`Rollback requested for ${b.title}.`),await l()},[l,Q]),We=a.useCallback(async()=>{var Z;if(!he||se.trim().length===0||ae)return;De(!0);const b=he.type,O=se.trim();try{const M={type:b,title:O,status:"active"};if(b==="workstream"){const fe=he.initiativeId??(de==null?void 0:de.initiativeId)??((Z=Oe[0])==null?void 0:Z.id)??null;if(!fe){ne("Select an initiative first to start a workstream."),De(!1);return}M.initiative_id=fe,M.parentId=fe}const oe=await fetch("/orgx/api/entities",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(M)});if(!oe.ok){const fe=await oe.json().catch(()=>null);throw new Error((fe==null?void 0:fe.error)??`Failed to create ${b}.`)}ne(`Created ${b}: ${O}`),ft(),await l()}catch(M){ne(M instanceof Error?M.message:`Failed to create ${b}.`),De(!1)}},[ft,ae,he,se,Oe,l,de==null?void 0:de.initiativeId]),ot=a.useCallback(()=>{ze("initiative")},[ze]),lt=a.useCallback(b=>{ze("workstream",b)},[ze]);a.useCallback(()=>{var b;return lt((de==null?void 0:de.initiativeId)??((b=Oe[0])==null?void 0:b.id)??null)},[Oe,de==null?void 0:de.initiativeId,lt]);const At=a.useCallback(b=>{const O=[...i.sessions.nodes].filter(Z=>(Z.initiativeId??Z.groupId)===b.id).sort(Ts)[0];O&&(d(O.id),F(O.id),f(null),v(null),ne(`Focused initiative: ${b.name}`))},[i.sessions.nodes]),_t=a.useCallback(b=>{F(null),f(b.workstreamId),v(b.workstreamTitle),ee(null),Me("activity"),ne(`Following workstream: ${b.workstreamTitle}`)},[Me]),$t=a.useCallback(b=>{const O=Oe.find(Z=>Z.id===b)??Ct.find(Z=>Z.id===b)??null;O&&At(O)},[At,Oe,Ct]);a.useCallback(b=>{const O=new Set(b),Z=[...i.sessions.nodes].filter(M=>O.has(M.status)).sort(Ts)[0];if(!Z){ne("No matching sessions for that metric right now.");return}Ve(Z.id),K("activity")},[i.sessions.nodes,Ve]);const Tt=a.useCallback(b=>{ye==="activity"&&(b==="sessions"||b==="active"||b==="blocked"||b==="failed"||b==="decisions"||b==="outbox"||b==="handoffs")&&R(b)},[ye]);return o?e.jsxs("div",{className:"flex min-h-screen flex-col lg:h-screen",style:{backgroundColor:C.background},children:[e.jsxs("div",{className:"border-b border-subtle px-4 py-2.5 sm:px-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"shimmer-skeleton h-6 w-6 rounded-lg"}),e.jsx("div",{className:"shimmer-skeleton h-5 w-28 rounded-md"}),e.jsx("div",{className:"shimmer-skeleton h-5 w-14 rounded-full"})]}),e.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:Array.from({length:4}).map((b,O)=>e.jsx("div",{className:"shimmer-skeleton h-7 w-24 rounded-full"},O))})]}),e.jsxs("div",{className:"grid flex-1 grid-cols-1 gap-4 p-4 sm:p-5 lg:grid-cols-12",children:[e.jsx("div",{className:"shimmer-skeleton min-h-[240px] rounded-2xl lg:col-span-3"}),e.jsx("div",{className:"shimmer-skeleton min-h-[240px] rounded-2xl lg:col-span-6"}),e.jsxs("div",{className:"flex flex-col gap-4 lg:col-span-3",children:[e.jsx("div",{className:"shimmer-skeleton h-40 rounded-2xl"}),e.jsx("div",{className:"shimmer-skeleton h-48 rounded-2xl"}),e.jsx("div",{className:"shimmer-skeleton flex-1 rounded-2xl",style:{minHeight:160}})]})]})]}):e.jsxs("div",{className:"relative flex min-h-screen flex-col pb-[92px] lg:h-screen lg:min-h-0 lg:overflow-hidden lg:pb-0",style:{backgroundColor:C.background},children:[typeof window<"u"&&window.location.port==="5173"&&e.jsx("div",{className:"absolute left-1/2 top-4 z-30 -translate-x-1/2",children:e.jsxs("div",{className:"rounded-full border border-strong bg-white/[0.06] px-4 py-2 text-caption text-primary shadow-[0_10px_30px_rgba(0,0,0,0.35)] backdrop-blur",children:["Dev preview on 5173. Installed plugin runs on OpenClaw port"," ",e.jsx("a",{href:"http://127.0.0.1:18789/orgx/live/",className:"text-white underline underline-offset-4 hover:text-secondary",children:"18789"}),"."]})}),e.jsxs("header",{className:"relative z-[180] border-b border-subtle px-4 py-1.5 sm:px-6",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2.5 lg:grid lg:grid-cols-[1fr_auto_1fr]",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[e.jsx(jo,{}),e.jsxs("h1",{className:"text-title font-semibold tracking-tight text-white sm:text-[17px]",children:["OrgX",e.jsx("span",{className:"ml-1.5 text-secondary",children:"Live"})]}),e.jsx(on,{color:ho[i.connection],pulse:i.connection==="connected",title:[`Status: ${kn[i.connection]??i.connection}`,i.connection==="connected"?"Meaning: receiving live updates.":i.connection==="reconnecting"?"Meaning: retrying live stream (data may be stale).":"Meaning: offline (data is stale).",`Last snapshot: ${go(i.lastSnapshotAt)}`,c?`Error: ${c}`:null].filter(Boolean).join(`
214
- `),children:kn[i.connection]??"Unknown"}),(i.outbox.pendingTotal>0||i.outbox.replayStatus==="error")&&e.jsx("div",{className:"hidden sm:block",children:e.jsx("button",{type:"button",onClick:()=>R("outbox"),className:"transition-opacity hover:opacity-80",title:"Open outbox details",children:e.jsxs(on,{color:i.outbox.replayStatus==="error"?C.red:C.amber,pulse:i.outbox.pendingTotal>0&&i.outbox.replayStatus!=="error",children:["Outbox ",i.outbox.pendingTotal]})})})]}),e.jsx("div",{className:"hidden items-center justify-center lg:flex",children:e.jsxs("div",{className:"flex rounded-full border border-white/[0.1] bg-white/[0.03] p-0.5",role:"group","aria-label":"Dashboard view",children:[e.jsx("button",{type:"button",onClick:()=>Me("activity"),"aria-pressed":ye==="activity",className:`rounded-full px-3 py-1 text-body font-medium transition-all ${ye==="activity"?"bg-white/[0.1] text-white":"text-secondary hover:text-bright"}`,children:"Activity"}),e.jsx("button",{type:"button",onClick:()=>Me("mission-control"),onMouseEnter:Se,onFocus:Se,"aria-pressed":ye==="mission-control",className:`rounded-full px-3 py-1 text-body font-medium transition-all ${ye==="mission-control"?"bg-white/[0.1] text-white":"text-secondary hover:text-bright"}`,children:"Mission Control"})]})}),e.jsxs("div",{className:"relative isolate flex items-center justify-end gap-1.5 sm:gap-2",children:[i.lastActivity&&e.jsxs("span",{className:"hidden text-body text-secondary xl:inline",children:["Last activity: ",i.lastActivity]}),i.outbox.pendingTotal>0&&e.jsxs("span",{className:"hidden text-body text-secondary xl:inline",children:["Replay: ",i.outbox.replayStatus]}),s&&e.jsx("button",{type:"button",onClick:()=>{r(!1),ke()},className:"hidden rounded-full border border-amber-200/25 bg-amber-200/10 px-3 py-1.5 text-caption font-semibold text-amber-100 transition-colors hover:bg-amber-200/15 sm:inline",title:"Exit demo mode",children:"Exit demo"}),e.jsxs("button",{type:"button",ref:E,onClick:()=>te(b=>!b),title:"Notifications","aria-haspopup":"dialog","aria-expanded":G,"aria-controls":"header-notifications-panel",className:"relative inline-flex h-8 w-8 items-center justify-center rounded-full border border-white/[0.1] bg-white/[0.03] text-primary transition-colors hover:bg-white/[0.08]",children:[e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M15 17h5l-1.4-1.4a2 2 0 0 1-.6-1.4V11a6 6 0 1 0-12 0v3.2c0 .53-.21 1.04-.59 1.42L4 17h5"}),e.jsx("path",{d:"M9 17a3 3 0 0 0 6 0"})]}),tt.length>0&&e.jsx("span",{className:"absolute -right-1 -top-1 inline-flex min-h-[16px] min-w-[16px] items-center justify-center rounded-full bg-red-500 px-1 text-micro font-semibold text-white",children:tt.length})]}),e.jsx("button",{type:"button",onClick:()=>W("orgx"),title:"Settings",className:"relative inline-flex h-8 w-8 items-center justify-center rounded-full border border-white/[0.1] bg-white/[0.03] text-primary transition-colors hover:bg-white/[0.08]",children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M12 15.5a3.5 3.5 0 1 0 0-7 3.5 3.5 0 0 0 0 7z"}),e.jsx("path",{d:"M19.4 15a1.8 1.8 0 0 0 .36 2l.05.05a2.2 2.2 0 0 1-1.56 3.76 2.2 2.2 0 0 1-1.56-.64l-.05-.05a1.8 1.8 0 0 0-2-.36 1.8 1.8 0 0 0-1.1 1.63V22a2.2 2.2 0 0 1-4.4 0v-.07a1.8 1.8 0 0 0-1.1-1.63 1.8 1.8 0 0 0-2 .36l-.05.05a2.2 2.2 0 1 1-3.12-3.12l.05-.05a1.8 1.8 0 0 0 .36-2 1.8 1.8 0 0 0-1.63-1.1H2a2.2 2.2 0 0 1 0-4.4h.07a1.8 1.8 0 0 0 1.63-1.1 1.8 1.8 0 0 0-.36-2l-.05-.05a2.2 2.2 0 1 1 3.12-3.12l.05.05a1.8 1.8 0 0 0 2 .36 1.8 1.8 0 0 0 1.1-1.63V2a2.2 2.2 0 0 1 4.4 0v.07a1.8 1.8 0 0 0 1.1 1.63 1.8 1.8 0 0 0 2-.36l.05-.05a2.2 2.2 0 0 1 3.12 3.12l-.05.05a1.8 1.8 0 0 0-.36 2 1.8 1.8 0 0 0 1.63 1.1H22a2.2 2.2 0 0 1 0 4.4h-.07a1.8 1.8 0 0 0-1.63 1.1z"})]})}),e.jsx("button",{type:"button",onClick:()=>{re(!0);try{window.sessionStorage.setItem(_s,"1")}catch{}},title:"Help",className:"relative inline-flex h-8 w-8 items-center justify-center rounded-full border border-white/[0.1] bg-white/[0.03] text-primary transition-colors hover:bg-white/[0.08]",children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M9.1 9a3 3 0 0 1 5.8 1c0 2-3 2-3 4"}),e.jsx("path",{d:"M12 17h.01"}),e.jsx("circle",{cx:"12",cy:"12",r:"9"})]})}),e.jsxs("button",{type:"button",onClick:l,className:"group inline-flex h-8 w-8 items-center justify-center rounded-full border border-white/[0.1] bg-white/[0.03] text-body text-primary transition-colors hover:bg-white/[0.08] sm:w-auto sm:gap-1.5 sm:px-3",title:"Refresh data",children:[e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"transition-transform group-hover:rotate-45",children:[e.jsx("path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8"}),e.jsx("path",{d:"M21 3v5h-5"})]}),e.jsx("span",{className:"hidden sm:inline",children:"Refresh"})]}),G&&e.jsxs("div",{id:"header-notifications-panel",ref:u,role:"dialog","aria-label":"Notifications",className:"absolute right-0 top-[calc(100%+8px)] z-[320] w-[min(92vw,380px)] rounded-2xl border border-strong bg-[#070a11]/95 p-2 shadow-[0_20px_50px_rgba(0,0,0,0.45)] backdrop-blur",children:[e.jsxs("div",{className:"mb-1.5 flex items-center justify-between px-2 py-1",children:[e.jsx("p",{className:"text-body font-semibold uppercase tracking-[0.12em] text-secondary",children:"Notifications"}),e.jsxs("div",{className:"flex items-center gap-2",children:[tt.length>0&&e.jsx("button",{type:"button",onClick:us,className:"text-caption text-secondary transition-colors hover:text-primary",children:"Dismiss all"}),e.jsx("button",{type:"button",onClick:()=>te(!1),className:"rounded-md px-1.5 py-0.5 text-caption text-secondary transition-colors hover:bg-white/[0.08] hover:text-primary","aria-label":"Close notifications",children:"Close"})]})]}),e.jsx("div",{className:"mb-1.5 flex flex-wrap items-center gap-1.5 px-1.5",children:St.map(b=>e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.1] bg-white/[0.03] px-2 py-0.5 text-micro",children:[e.jsx(Ne,{type:b.icon,accent:b.color,size:12,className:"opacity-90"}),e.jsx("span",{className:"uppercase tracking-[0.08em] text-secondary",children:b.label}),e.jsx("span",{className:"font-semibold text-white",style:{fontVariantNumeric:"tabular-nums"},children:b.value})]},b.id))}),tt.length===0?e.jsx("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.02] px-3 py-3 text-body text-secondary",children:"Everything looks clear."}):e.jsx("div",{className:"space-y-1.5",children:tt.map(b=>e.jsx("div",{className:"rounded-xl border px-3 py-2",style:{borderColor:b.kind==="error"?"rgba(239,68,68,0.35)":"rgba(255,255,255,0.1)",backgroundColor:b.kind==="error"?"rgba(239,68,68,0.08)":"rgba(255,255,255,0.02)"},children:e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"inline-flex items-center gap-1.5 text-body font-semibold",style:{color:b.kind==="error"?"#fecaca":"#e2e8f0"},children:[e.jsx(Ne,{type:b.icon,size:12,className:"opacity-90"}),e.jsx("span",{className:"truncate",children:b.title})]}),e.jsx("p",{className:"mt-0.5 text-body leading-snug text-secondary",children:b.message}),b.onAction&&e.jsx("button",{type:"button",onClick:()=>{var O;(O=b.onAction)==null||O.call(b),te(!1)},className:"mt-1.5 rounded-md border border-strong bg-white/[0.05] px-2.5 py-1 text-caption font-medium text-primary transition-colors hover:bg-white/[0.1] hover:text-white",children:b.actionLabel??"View"})]}),e.jsx("button",{type:"button",onClick:()=>Ft(b.id),className:"shrink-0 rounded-md px-1.5 py-0.5 text-caption text-secondary transition-colors hover:bg-white/[0.08] hover:text-primary",title:"Dismiss",children:"Dismiss"})]})},b.id))})]})]})]}),e.jsx("div",{className:"mt-2 flex items-center justify-center lg:hidden",children:e.jsxs("div",{className:"flex w-full max-w-[340px] rounded-full border border-white/[0.1] bg-white/[0.03] p-0.5",role:"group","aria-label":"Dashboard view",children:[e.jsx("button",{type:"button",onClick:()=>Me("activity"),"aria-pressed":ye==="activity",className:`flex-1 rounded-full px-3 py-1.5 text-body font-medium transition-all ${ye==="activity"?"bg-white/[0.1] text-white":"text-secondary hover:text-bright"}`,children:"Activity"}),e.jsx("button",{type:"button",onClick:()=>Me("mission-control"),"aria-pressed":ye==="mission-control",className:`flex-1 rounded-full px-3 py-1.5 text-body font-medium transition-all ${ye==="mission-control"?"bg-white/[0.1] text-white":"text-secondary hover:text-bright"}`,children:"Mission Control"})]})}),_&&e.jsxs("div",{className:"mt-2 flex flex-wrap items-center justify-between gap-2 rounded-lg border border-[#7C7CFF]/30 bg-[#7C7CFF]/10 px-3 py-2 text-body text-[#E6E4FF]",children:[e.jsx("span",{children:"Mission Control now includes a dependency map plus expandable hierarchy rows for initiatives, workstreams, milestones, and tasks."}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>Me("mission-control"),onMouseEnter:Se,onFocus:Se,className:"rounded-full border border-[#BFFF00]/30 bg-[#BFFF00]/15 px-2.5 py-1 text-caption text-[#D8FFA1]",children:"Open"}),e.jsx("button",{type:"button",onClick:()=>V(!0),className:"text-caption text-secondary underline underline-offset-2",children:"Dismiss"})]})]})]}),ye==="activity"&&e.jsx("div",{className:"flex items-center gap-1.5 overflow-x-auto border-b border-subtle px-4 py-1.5 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden sm:px-6",children:St.map(b=>e.jsxs("button",{type:"button",onClick:()=>Tt(b.id),className:"inline-flex shrink-0 items-center gap-1.5 rounded-full border border-white/[0.1] bg-white/[0.03] px-2 py-0.5 text-micro transition-colors hover:bg-white/[0.08]",title:`Bulk actions: ${b.label.toLowerCase()}`,children:[e.jsx("span",{className:"inline-flex h-5 w-5 items-center justify-center rounded-full border border-strong bg-white/[0.02]",children:e.jsx(Ne,{type:b.icon,accent:b.color,size:12,className:"opacity-90"})}),e.jsx("span",{className:"font-semibold text-white",style:{fontVariantNumeric:"tabular-nums"},children:b.value}),e.jsx("span",{className:"uppercase tracking-[0.08em] text-secondary",children:b.label})]},b.id))}),ye==="mission-control"?e.jsx("div",{className:"relative z-0 flex-1 min-h-0 flex flex-col overflow-hidden",children:e.jsx(a.Suspense,{fallback:e.jsx("div",{className:"flex flex-1 items-center justify-center text-body text-secondary",children:"Loading Mission Control…"}),children:e.jsx(mo,{initiatives:Ct,activities:i.activity,agents:Ut,runtimeInstances:i.runtimeInstances??[],isLoading:o,authToken:null,embedMode:!1,connection:i.connection,lastSnapshotAt:i.lastSnapshotAt,error:c,hasApiKey:t.state.hasApiKey,onOpenSettings:()=>W("orgx"),onRefresh:l,onFollowWorkstream:_t})})}):e.jsxs("main",{className:"relative z-0 grid min-h-0 flex-1 grid-cols-1 gap-4 overflow-y-auto p-4 pb-20 sm:p-5 sm:pb-20 lg:grid-cols-12 lg:overflow-hidden lg:pb-5",children:[x&&i.decisions.length>0&&Ae!=="decisions"&&e.jsxs("button",{type:"button",onClick:()=>le("decisions"),className:we("col-span-full flex items-center gap-2 rounded-xl border px-4 py-2.5 text-left transition-colors hover:bg-white/[0.03]",i.decisions.length>=20?"border-red-400/30 bg-red-500/[0.08]":"border-amber-300/30 bg-amber-400/[0.08]"),children:[e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:i.decisions.length>=20?"text-red-300":"text-amber-300",children:[e.jsx("path",{d:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),e.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),e.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),e.jsxs("span",{className:`text-body font-medium ${i.decisions.length>=20?"text-red-200":"text-amber-200"}`,children:[i.decisions.length," decision",i.decisions.length===1?"":"s"," waiting",et>0?` · longest: ${et}m`:""]}),e.jsx("span",{className:`ml-auto text-caption ${i.decisions.length>=20?"text-red-300/70":"text-amber-300/70"}`,children:"Click to review →"})]}),e.jsx("section",{className:`min-h-0 lg:col-span-3 lg:flex lg:flex-col lg:[&>section]:h-full ${X!=="agents"?"hidden lg:flex":""}`,children:e.jsx(Ki,{sessions:i.sessions,activity:i.activity,runtimeInstances:i.runtimeInstances??[],selectedSessionId:p,onSelectSession:Ve,onAgentFilter:ee,agentFilter:A,timeFilterId:T,onTimeFilterChange:D,onReconnect:ke,connectionStatus:i.connection})}),e.jsx("section",{className:`min-h-0 lg:col-span-6 lg:flex lg:flex-col lg:[&>section]:h-full ${X!=="activity"?"hidden lg:flex":""}`,children:e.jsx(Sa,{activity:at.items,sessions:i.sessions.nodes,initiatives:Oe,selectedRunIds:U?[U.runId,U.id]:[],selectedSessionLabel:pt,selectedWorkstreamId:g,selectedWorkstreamLabel:k,agentFilter:A,timeFilterId:T,hasMore:at.hasMore,isLoadingMore:at.isLoadingMore,onLoadMore:at.loadMore,onClearSelection:ds,onClearWorkstreamFilter:zt,onClearAgentFilter:()=>ee(null),onFocusRunId:He})}),e.jsxs("section",{className:`flex min-h-0 flex-col gap-3 lg:col-span-3 lg:gap-3 ${X!=="decisions"&&X!=="initiatives"?"hidden lg:flex":""}`,children:[e.jsx("div",{className:`min-h-0 ${Ae==="initiatives"?"flex-1":"flex-shrink-0"} `,children:Ae==="initiatives"?e.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-2",children:[e.jsxs("div",{className:"inline-flex items-center gap-1 rounded-full border border-strong bg-black/20 p-0.5",role:"tablist","aria-label":"Initiatives sidebar",children:[e.jsxs("button",{type:"button",role:"tab","aria-selected":ce==="in_progress",onClick:()=>$("in_progress"),className:we("inline-flex items-center gap-2 rounded-full px-3 py-1.5 text-micro font-semibold transition-colors",ce==="in_progress"?"border border-lime/25 bg-lime/[0.10] text-[#E1FFB2]":"border border-transparent text-secondary hover:bg-white/[0.08] hover:text-bright"),children:[e.jsx("span",{children:"In Progress"}),e.jsx("span",{className:"rounded-full border border-strong bg-white/[0.04] px-2 py-0.5 text-micro tabular-nums text-primary",children:Y})]}),e.jsx("button",{type:"button",role:"tab","aria-selected":ce==="next_up",onClick:()=>$("next_up"),className:we("rounded-full px-3 py-1.5 text-micro font-semibold transition-colors",ce==="next_up"?"border border-lime/25 bg-lime/[0.10] text-[#E1FFB2]":"border border-transparent text-secondary hover:bg-white/[0.08] hover:text-bright"),children:"Next Up"})]}),e.jsx("div",{className:"min-h-0 flex-1",children:ce==="in_progress"?e.jsx(_a,{className:"h-full min-h-0",sessions:i.sessions.nodes,onOpenSession:Ve,onFocusRunId:He}):e.jsx(qa,{title:"Next Up",className:"h-full",compact:Ie,allowCompactToggle:!0,onToggleCompact:P,onFollowWorkstream:_t,onOpenInitiative:$t})})]}):e.jsx(vt,{className:"card-enter",children:e.jsxs("button",{onClick:()=>le("initiatives"),className:"flex w-full items-center justify-between px-4 py-3 text-left transition-colors hover:bg-white/[0.03]",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("h2",{className:"text-heading font-semibold text-white",children:"Initiatives"})}),e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"-rotate-90 text-muted",children:e.jsx("path",{d:"m6 9 6 6 6-6"})})]})})}),e.jsx("div",{className:`min-h-0 ${Ae==="decisions"?"flex-1":"flex-shrink-0"} ${X==="initiatives"?"hidden lg:block":""}`,children:Ae==="decisions"?x?e.jsx(Vn,{decisions:i.decisions,onApproveDecision:y,onApproveAll:m}):e.jsxs(vt,{className:"flex h-full min-h-[220px] flex-col card-enter",children:[e.jsxs("div",{className:"space-y-2 border-b border-subtle px-4 py-3.5",children:[e.jsx("h2",{className:"text-heading font-semibold text-white",children:"Decisions"}),e.jsx("p",{className:"text-body text-secondary",children:"OrgX is not connected. Pending decision data is hidden in local-only mode."})]}),e.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 p-4 text-center",children:[e.jsx("p",{className:"text-body text-secondary",children:"Connect OrgX to review and approve live decisions."}),e.jsx("button",{onClick:ke,className:"rounded-md border border-lime/25 bg-lime/10 px-3 py-1.5 text-caption font-semibold text-lime transition-colors hover:bg-lime/20",children:"Connect OrgX"})]})]}):e.jsx(vt,{className:"card-enter",children:e.jsxs("button",{onClick:()=>le("decisions"),className:"flex w-full items-center justify-between px-4 py-3 text-left transition-colors hover:bg-white/[0.03]",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"text-heading font-semibold text-white",children:"Decisions"}),x&&i.decisions.length>0&&e.jsx("span",{className:"chip text-micro",style:{borderColor:`${C.amber}44`,color:C.amber},children:i.decisions.length}),!x&&e.jsx("span",{className:"text-micro text-muted",children:"disconnected"})]}),e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"-rotate-90 text-muted",children:e.jsx("path",{d:"m6 9 6 6 6-6"})})]})})})]})]}),e.jsx(qe,{children:h&&de&&e.jsxs(e.Fragment,{children:[e.jsx(ue.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-[200] bg-black/40 backdrop-blur-sm hidden lg:block",onClick:()=>N(!1)},"session-drawer-backdrop"),e.jsxs(ue.div,{initial:{x:"100%"},animate:{x:0},exit:{x:"100%"},transition:{type:"spring",stiffness:400,damping:35},className:"fixed inset-y-0 right-0 z-[210] hidden w-[480px] flex-col lg:flex",style:{backgroundColor:C.cardBg},children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-subtle px-4 py-3",children:[e.jsx("h3",{className:"text-body font-semibold text-primary",children:"Session Detail"}),e.jsx("button",{type:"button",onClick:()=>N(!1),"aria-label":"Close session inspector",className:"inline-flex h-8 w-8 items-center justify-center rounded-full border border-strong bg-white/[0.03] text-primary transition-colors hover:bg-white/[0.08] hover:text-white",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 6L6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})})]}),e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto",children:e.jsx(a.Suspense,{fallback:e.jsx("div",{className:"p-4 text-body text-secondary",children:"Loading session detail…"}),children:e.jsx(xo,{session:de,activity:i.activity,initiatives:Oe,onContinueHighestPriority:J,onDispatchSession:B,onPauseSession:Fe,onResumeSession:st,onCancelSession:Le,onCreateCheckpoint:be,onRollbackSession:Re,onStartInitiative:ot,onStartWorkstream:lt})})})]},"session-drawer-panel")]})}),e.jsx(ai,{activeTab:X,onTabChange:K,pendingDecisionCount:x?i.decisions.length:0}),e.jsx(Ge,{open:he!==null,onClose:ft,maxWidth:"max-w-sm",fitContent:!0,children:e.jsxs("div",{className:"flex w-full flex-col",children:[e.jsxs("div",{className:"px-5 pt-5 pb-1",children:[e.jsx("h3",{className:"text-heading font-semibold text-white",children:(he==null?void 0:he.type)==="workstream"?"New Workstream":"New Initiative"}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:(he==null?void 0:he.type)==="workstream"?"Create a new workstream under the selected initiative.":"Create a new initiative to organize your work."})]}),e.jsxs("div",{className:"px-5 py-4",children:[e.jsx("label",{className:"mb-1.5 block text-caption uppercase tracking-[0.1em] text-secondary",children:"Name"}),e.jsx("input",{value:se,onChange:b=>xe(b.target.value),onKeyDown:b=>{b.key==="Enter"&&We()},autoFocus:!0,"data-modal-autofocus":"true",placeholder:(he==null?void 0:he.type)==="workstream"?"e.g. User Onboarding Flow":"e.g. Q1 Product Launch",className:"w-full rounded-lg border border-strong bg-black/30 px-3 py-2.5 text-body text-white placeholder:text-muted focus:outline-none focus:ring-1 focus:ring-[#BFFF00]/40"})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 border-t border-subtle px-5 py-3",children:[e.jsx("button",{onClick:ft,className:"rounded-md px-3 py-1.5 text-body text-secondary transition-colors hover:text-white",children:"Cancel"}),e.jsx("button",{onClick:We,disabled:se.trim().length===0||ae,className:"rounded-md border border-lime/25 bg-lime/10 px-4 py-1.5 text-body font-semibold text-lime transition-colors hover:bg-lime/20 disabled:opacity-45",children:ae?"Creating…":"Create"})]})]})}),e.jsx(to,{open:I.open,onClose:()=>L(b=>({...b,open:!1})),activeTab:I.tab,onChangeTab:b=>L(O=>({...O,tab:b})),onboarding:t,authToken:null,embedMode:!1}),e.jsx(oo,{open:z==="sessions"||z==="active"||z==="blocked"||z==="failed",onClose:()=>R(null),mode:z==="active"||z==="blocked"||z==="failed"?z:"sessions",sessions:i.sessions.nodes,onOpenSession:b=>{Ve(b.id),R(null)},onRunAction:async(b,O)=>{await Q(b,O,{reason:`bulk_${O}_from_header`})},onRefetch:async()=>l(),onSetNotice:b=>ne(b)}),e.jsx(lo,{open:z==="decisions",onClose:()=>R(null),decisions:x?i.decisions:[],onApproveDecision:y,onApproveAll:m}),e.jsx(co,{open:z==="outbox",onClose:()=>R(null),outbox:i.outbox,onOpenSettings:()=>{R(null),W("orgx")},onRefresh:()=>{l()}}),e.jsx(po,{open:z==="handoffs",onClose:()=>R(null),handoffs:i.handoffs}),e.jsx(ri,{open:me,onClose:()=>re(!1),onOpenSettings:()=>W("providers"),onOpenOrgxSettings:()=>W("orgx"),onOpenMissionControl:()=>{Me("mission-control"),re(!1)},demoMode:s,connectionVerified:t.state.connectionVerified,hasSessions:i.sessions.nodes.length>0})]})}An.init("phc_s4KPgkYEFZgvkMYw4zXG41H5FN6haVwbEWPYHfNjxOc",{api_host:"https://us.i.posthog.com",defaults:"2026-01-30",person_profiles:"identified_only"});const No=new ar({defaultOptions:{queries:{staleTime:3e4,retry:1,refetchOnWindowFocus:!1,refetchOnReconnect:!0}}});rr.createRoot(document.getElementById("root")).render(e.jsx(a.StrictMode,{children:e.jsx(ir,{client:No,children:e.jsx(yo,{})})}));export{nt as A,Ne as E,Bt as M,qa as N,vt as P,Qe as S,Jn as U,C as a,Be as b,Si as c,Ei as d,Et as e,To as f,_o as g,Aa as h,Mo as i,$o as j,Fo as k,Ge as l,Pa as m,rt as n,gn as o,La as p,wt as q,$a as r,Lo as s,ln as t,Da as u,we as v,Ce as w,vs as x};