@useorgx/openclaw-plugin 0.4.1 → 0.4.4

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.
@@ -0,0 +1,212 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/BgsfM2lz.js","assets/B3ziCA02.js","assets/C-KIc3Wc.js","assets/sAhvFnpk.js","assets/4hvaB0UC.js","assets/DEuY_RBN.js"])))=>i.map(i=>d[i]);
2
+ import{r as a,j as e,a as pn,u as Vs,b as Ve,c as Ot,d as hn,Q as xn}from"./B3ziCA02.js";import{b as mn}from"./C-KIc3Wc.js";import{v as Hs}from"./sAhvFnpk.js";import{m as de,A as Te,u as Gs}from"./4hvaB0UC.js";(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const r of document.querySelectorAll('link[rel="modulepreload"]'))n(r);new MutationObserver(r=>{for(const o of r)if(o.type==="childList")for(const d of o.addedNodes)d.tagName==="LINK"&&d.rel==="modulepreload"&&n(d)}).observe(document,{childList:!0,subtree:!0});function i(r){const o={};return r.integrity&&(o.integrity=r.integrity),r.referrerPolicy&&(o.referrerPolicy=r.referrerPolicy),r.crossOrigin==="use-credentials"?o.credentials="include":r.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function n(r){if(r.ep)return;r.ep=!0;const o=i(r);fetch(r.href,o)}})();const fn="modulepreload",gn=function(t){return"/orgx/live/"+t},fs={},qt=function(s,i,n){let r=Promise.resolve();if(i&&i.length>0){let d=function(u){return Promise.all(u.map(y=>Promise.resolve(y).then(m=>({status:"fulfilled",value:m}),m=>({status:"rejected",reason:m}))))};document.getElementsByTagName("link");const l=document.querySelector("meta[property=csp-nonce]"),v=(l==null?void 0:l.nonce)||(l==null?void 0:l.getAttribute("nonce"));r=d(i.map(u=>{if(u=gn(u),u in fs)return;fs[u]=!0;const y=u.endsWith(".css"),m=y?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${u}"]${m}`))return;const g=document.createElement("link");if(g.rel=y?"stylesheet":fn,y||(g.as="script"),g.crossOrigin="",g.href=u,v&&g.setAttribute("nonce",v),document.head.appendChild(g),y)return new Promise((x,j)=>{g.addEventListener("load",x),g.addEventListener("error",()=>j(new Error(`Unable to preload CSS for ${u}`)))})}))}function o(d){const l=new Event("vite:preloadError",{cancelable:!0});if(l.payload=d,window.dispatchEvent(l),!l.defaultPrevented)throw d}return r.then(d=>{for(const l of d||[])l.status==="rejected"&&o(l.reason);return s().catch(o)})},gs=()=>{const t=new Date,s=i=>new Date(t.getTime()-i*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 Fe(t){const i=(t instanceof Date?t:new Date(t)).getTime()-Date.now();if(Number.isNaN(i))return"unknown";const n=Math.floor(Math.abs(i)/1e3),r=i<0?"past":"future";if(n<10)return r==="past"?"just now":"soon";if(n<60)return r==="past"?`${n}s ago`:`in ${n}s`;const o=Math.floor(n/60);if(o<60)return r==="past"?`${o}m ago`:`in ${o}m`;const d=Math.floor(o/60);if(d<24)return r==="past"?`${d}h ago`:`in ${d}h`;const l=Math.floor(d/24);return r==="past"?`${l}d ago`:`in ${l}d`}const bn=8e3,wn=320,yn=600,vn=120,jn=120,kn=90,bs=6e4,Xs={pendingTotal:0,pendingByQueue:{},oldestEventAt:null,newestEventAt:null,replayStatus:"idle",lastReplayAttemptAt:null,lastReplaySuccessAt:null,lastReplayFailureAt:null,lastReplayError:null},ws={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},Qs=new Set(["running","active","queued","in_progress","working","planning","pending","blocked"]),ys=45*6e4;function Ne(t){if(!t)return 0;const s=Date.parse(t);return Number.isFinite(s)?s:0}function Ut(t,s){const i=ws[t.status]??99,n=ws[s.status]??99;if(i!==n)return i-n;const r=Ne(t.updatedAt??t.lastEventAt??t.startedAt),o=Ne(s.updatedAt??s.lastEventAt??s.startedAt);return r!==o?o-r:t.id.localeCompare(s.id)}function Nn(t){return(t??"").trim().toLowerCase()}function vs(t){return Qs.has(Nn(t.status))}function Qt(t){const s=[];return t.id&&s.push(`id:${t.id}`),t.runId&&s.push(`run:${t.runId}`),s}function js(t,s){if(!t.nodes.length)return s;if(!s.nodes.length){const x=Date.now(),j=t.nodes.filter(D=>{const O=Ne(D.updatedAt??D.lastEventAt??D.startedAt);return vs(D)||x-O<=ys});if(!j.length)return s;const p=new Set(j.map(D=>D.id)),M=new Set(j.map(D=>D.groupId));return{nodes:j.sort(Ut),edges:t.edges.filter(D=>p.has(D.parentId)&&p.has(D.childId)),groups:t.groups.filter(D=>M.has(D.id))}}const i=new Set,n=[...s.nodes];for(const x of s.nodes)for(const j of Qt(x))i.add(j);const r=Date.now(),o=[];for(const x of t.nodes){if(Qt(x).some(D=>i.has(D)))continue;const p=Ne(x.updatedAt??x.lastEventAt??x.startedAt),M=r-p<=ys;if(vs(x)||M){o.push(x),n.push(x);for(const D of Qt(x))i.add(D)}}if(!o.length)return s;const d=new Set(n.map(x=>x.id)),l=new Map(t.groups.map(x=>[x.id,x])),v=new Map(s.groups.map(x=>[x.id,x])),u=[...s.groups];for(const x of o){if(v.has(x.groupId))continue;const j=l.get(x.groupId)??{id:x.groupId,label:x.groupLabel||x.agentName||"Ungrouped",status:null};v.set(x.groupId,j),u.push(j)}const y=x=>`${x.parentId}->${x.childId}`,m=new Set,g=[];for(const x of s.edges){if(!d.has(x.parentId)||!d.has(x.childId))continue;const j=y(x);m.has(j)||(m.add(j),g.push(x))}for(const x of t.edges){if(!d.has(x.parentId)||!d.has(x.childId))continue;const j=y(x);m.has(j)||(m.add(j),g.push(x))}return{nodes:n.sort(Ut),edges:g,groups:u}}function At(t,s){if(t.nodes.length<=s)return t;const i=[...t.nodes].sort(Ut).slice(0,s),n=new Set(i.map(o=>o.id)),r=new Set(i.map(o=>o.groupId));return{nodes:i,edges:t.edges.filter(o=>n.has(o.parentId)&&n.has(o.childId)),groups:t.groups.filter(o=>r.has(o.id))}}function ks(t,s){return t.length<=s?t:[...t].sort((i,n)=>Ne(n.updatedAt)-Ne(i.updatedAt)).slice(0,s)}function Sn(t){const s=t.requestedAt??t.updatedAt??null,i=t.updatedAt??s,n=Number.isFinite(t.waitingMinutes)?Math.max(0,Math.floor(t.waitingMinutes)):s?Math.max(0,Math.floor((Date.now()-Ne(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:i,waitingMinutes:n,metadata:t.metadata}}function Js(t,s){if(t.length!==s.length)return!1;for(let i=0;i<t.length;i+=1)if(t[i].id!==s[i].id||t[i].timestamp!==s[i].timestamp||t[i].type!==s[i].type||t[i].title!==s[i].title)return!1;return!0}function Ns(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 i=0;i<t.nodes.length;i+=1){const n=t.nodes[i],r=s.nodes[i];if(n.id!==r.id||n.status!==r.status||n.title!==r.title||n.progress!==r.progress||n.updatedAt!==r.updatedAt||n.lastEventAt!==r.lastEventAt)return!1}for(let i=0;i<t.edges.length;i+=1){const n=t.edges[i],r=s.edges[i];if(n.parentId!==r.parentId||n.childId!==r.childId)return!1}for(let i=0;i<t.groups.length;i+=1){const n=t.groups[i],r=s.groups[i];if(n.id!==r.id||n.label!==r.label||n.status!==r.status)return!1}return!0}function Ss(t,s){if(t.length!==s.length)return!1;for(let i=0;i<t.length;i+=1)if(t[i].id!==s[i].id||t[i].updatedAt!==s[i].updatedAt||t[i].status!==s[i].status||t[i].title!==s[i].title)return!1;return!0}function Cs(t,s){if(t.length!==s.length)return!1;for(let i=0;i<t.length;i+=1)if(t[i].id!==s[i].id||t[i].status!==s[i].status||t[i].updatedAt!==s[i].updatedAt||t[i].waitingMinutes!==s[i].waitingMinutes)return!1;return!0}function Ys(t){if(!t||typeof t!="object")return Xs;const s=t.pendingByQueue&&typeof t.pendingByQueue=="object"?Object.fromEntries(Object.entries(t.pendingByQueue).filter(([n])=>typeof n=="string"&&n.length>0).map(([n,r])=>[n,Number.isFinite(Number(r))?Math.max(0,Math.floor(Number(r))):0])):{},i=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,r)=>n+r,0),pendingByQueue:s,oldestEventAt:t.oldestEventAt??null,newestEventAt:t.newestEventAt??null,replayStatus:i,lastReplayAttemptAt:t.lastReplayAttemptAt??null,lastReplaySuccessAt:t.lastReplaySuccessAt??null,lastReplayFailureAt:t.lastReplayFailureAt??null,lastReplayError:t.lastReplayError??null}}function Cn(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 i=Object.keys(t.pendingByQueue),n=Object.keys(s.pendingByQueue);if(i.length!==n.length)return!1;for(const r of i)if(t.pendingByQueue[r]!==s.pendingByQueue[r])return!1;return!0}function An(t,s,i){if(s.length===0)return t;const n=new Map;for(const d of t)n.set(d.id,d);let r=!1;for(const d of s){const l=n.get(d.id);if(!l){n.set(d.id,d),r=!0;continue}(l.timestamp!==d.timestamp||l.type!==d.type||l.title!==d.title||l.description!==d.description)&&(n.set(d.id,d),r=!0)}if(!r)return t;const o=Array.from(n.values()).sort((d,l)=>Ne(l.timestamp)-Ne(d.timestamp)).slice(0,i);return Js(t,o)?t:o}function Jt(t,s){const i=[...t].sort((o,d)=>Ne(d.timestamp)-Ne(o.timestamp)).slice(0,s),n=new Set,r=[];for(const o of i)n.has(o.id)||(n.add(o.id),r.push(o));return r}function As(t,s){const i=t.filter(o=>!!o&&typeof o.id=="string"&&o.id.length>0).map(Sn).sort((o,d)=>o.waitingMinutes!==d.waitingMinutes?d.waitingMinutes-o.waitingMinutes:Ne(d.requestedAt??d.updatedAt)-Ne(o.requestedAt??o.updatedAt)).slice(0,s),n=new Set,r=[];for(const o of i)n.has(o.id)||(n.add(o.id),r.push(o));return r}function Is(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 In(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 Mn(t,s){return!!(Qs.has(s)||t.runId&&t.runId.trim().length>0||t.currentTask&&t.currentTask.trim().length>0)}function It(t){return t?`Initiative ${t.length>16?`${t.slice(0,8)}…`:t}`:"Unscoped"}function Yt(t){if(!Array.isArray(t))return[];const s=[];for(const i of t)typeof i=="string"&&i.trim().length>0&&s.push(i.trim());return s}function En(t,s,i){const n=new Map,r=[...t].sort((l,v)=>Ne(v.timestamp)-Ne(l.timestamp));for(const l of r){if(!l.runId)continue;const v=l.runId,u=n.get(v),y=l.timestamp;if(!u){const m=l.initiativeId??null;n.set(v,{id:v,parentId:null,runId:v,title:l.title,agentId:l.agentId??null,agentName:l.agentName??null,status:Is(l.type),progress:null,initiativeId:m,workstreamId:null,groupId:m??"unscoped",groupLabel:It(m),startedAt:y,updatedAt:y,lastEventAt:y,lastEventSummary:l.title,blockers:l.type==="blocker_created"&&l.description?[l.description]:[]});continue}(!u.startedAt||Ne(y)<Ne(u.startedAt))&&(u.startedAt=y),Ne(y)>=Ne(u.updatedAt??u.lastEventAt)&&(u.updatedAt=y,u.lastEventAt=y,u.lastEventSummary=l.title,u.status=Is(l.type),l.agentName&&(u.agentName=l.agentName),l.agentId&&(u.agentId=l.agentId),l.initiativeId&&(u.initiativeId=l.initiativeId,u.groupId=l.initiativeId,u.groupLabel=It(l.initiativeId)),(!u.title||u.title.length<4)&&(u.title=l.title)),l.type==="blocker_created"&&l.description&&(u.blockers.includes(l.description)||u.blockers.push(l.description))}for(const l of s??[]){const v=l.runId??`agent:${l.id}`,u=n.get(v),y=In(l.status),m=new Date().toISOString(),g=Mn(l,y),x=l.startedAt??(g?m:null),j=l.initiativeId??null,p=l.currentTask&&l.currentTask.trim().length>0?l.currentTask.trim():`${l.name??l.id} ${y==="archived"?"idle":y}`;if(!u){n.set(v,{id:v,parentId:null,runId:v,title:p,agentId:l.id,agentName:l.name??l.id,status:y,progress:null,initiativeId:j,workstreamId:null,groupId:j??"unscoped",groupLabel:It(j),startedAt:x,updatedAt:x,lastEventAt:x,lastEventSummary:l.currentTask,blockers:Yt(l.blockers)});continue}!u.agentName&&l.name&&(u.agentName=l.name),u.agentId||(u.agentId=l.id),(!u.title||u.title===u.runId)&&(u.title=p),g&&(u.updatedAt=x??u.updatedAt??m,u.lastEventAt=x??u.lastEventAt??m),u.status==="archived"&&y!=="archived"&&(u.status=y),Yt(l.blockers).length>0&&(u.blockers=Yt(l.blockers)),j&&!u.initiativeId&&(u.initiativeId=j,u.groupId=j,u.groupLabel=It(j))}const o=Array.from(n.values()).sort(Ut).slice(0,i),d=new Map;for(const l of o)d.has(l.groupId)||d.set(l.groupId,{id:l.groupId,label:l.groupLabel,status:l.status});return{nodes:o,edges:[],groups:Array.from(d.values())}}async function _n(t,s){var i;try{const n=await fetch(t,s),o=(((i=n.headers.get("content-type"))==null?void 0:i.toLowerCase())??"").includes("application/json");if(!n.ok){let d=`${n.status} ${n.statusText}`;if(o){const l=await n.json().catch(()=>null);l!=null&&l.error&&(d=`${n.status} ${l.error}`)}else{const l=(await n.text().catch(()=>"")).replace(/\s+/g," ").slice(0,80);l.length>0&&(d=`${n.status} ${l}`)}return{ok:!1,status:n.status,data:null,error:d}}if(!o){const d=(await n.text().catch(()=>"")).replace(/\s+/g," ").slice(0,80);return{ok:!1,status:n.status,data:null,error:`Unexpected content type for ${t}${d?`: ${d}`:""}`}}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 Fn(t,s,i,n,r=Xs,o=null,d=[]){var y,m,g;const l=((y=s[0])==null?void 0:y.timestamp)??null,v=((m=n[0])==null?void 0:m.requestedAt)??((g=n[0])==null?void 0:g.updatedAt)??null,u=Ne(l)>=Ne(v)?l:v;return{connection:"connected",lastActivity:u?Fe(u):null,lastSnapshotAt:o,sessions:t,activity:s,handoffs:i,decisions:n,outbox:Ys(r),runtimeInstances:d}}function Ms(t){if(!Array.isArray(t)||t.length===0)return[];const s=new Map;for(const i of t){if(!i||typeof i!="object"||typeof i.id!="string")continue;const n=i.id.trim();n&&s.set(n,i)}return Array.from(s.values()).sort((i,n)=>Ne(n.lastEventAt??n.lastHeartbeatAt)-Ne(i.lastEventAt??i.lastHeartbeatAt))}function Es(t,s){const i=t??[],n=s??[];if(i.length!==n.length)return!1;for(let r=0;r<i.length;r+=1)if(i[r].id!==n[r].id||i[r].state!==n[r].state||i[r].lastEventAt!==n[r].lastEventAt||i[r].runId!==n[r].runId||i[r].progressPct!==n[r].progressPct)return!1;return!0}function Ln(t={}){const{enabled:s=!0,pollInterval:i=bn,useMock:n=!1,enableDecisions:r=!0,maxSessions:o=wn,maxActivityItems:d=yn,maxHandoffs:l=vn,maxDecisions:v=jn,batchWindowMs:u=kn}=t,[y,m]=a.useState(gs()),[g,x]=a.useState(!n),[j,p]=a.useState(null),M=a.useRef(),D=a.useRef(null),[O,H]=a.useState(!1),L=a.useRef(0),te=a.useRef(!1),ee=a.useCallback((N,F,z,I=null,S=null,$=null,U=null)=>{L.current=Date.now(),te.current=!1;const fe=Jt(F,d),be=ks(z,l);m(Z=>{const G=At(js(Z.sessions,At(N,o)),o),T=I===null?Z.decisions:As(I,v),C=S===null?Z.outbox:Ys(S),Y=U===null?Z.runtimeInstances??[]:Ms(U);return Ns(Z.sessions,G)&&Js(Z.activity,fe)&&Ss(Z.handoffs,be)&&Cs(Z.decisions,T)&&Cn(Z.outbox,C)&&Es(Z.runtimeInstances,Y)&&Z.lastSnapshotAt===$&&Z.connection==="connected"?Z:Fn(G,fe,be,T,C,$,Y)}),x(!1)},[d,v,l,o]),q=a.useCallback(async()=>{if(!s){m(F=>F.connection==="disconnected"?F:{...F,connection:"disconnected"}),x(!1),p(null);return}if(D.current)return D.current;if(n){m(gs()),x(!1);return}const N=(async()=>{try{const F=new URLSearchParams({sessionsLimit:String(o),activityLimit:String(d),decisionsLimit:String(v),include_idle:"true"}),z=[{label:"dashboard-bundle",url:`/orgx/api/dashboard-bundle?${F.toString()}`},{label:"live/snapshot",url:`/orgx/api/live/snapshot?${F.toString()}`}],I=[];let S=null,$=!1;for(const T of z){const C=await _n(T.url);if(C.ok&&C.data){S=C.data;break}(C.status===401||C.status===403)&&($=!0),I.push(`${T.label}: ${C.error??"unavailable"}`)}if(!S){if($){const T=new Error("Unauthorized. Update your OrgX API key in Settings (use a user-scoped oxk_... key; userId should be blank).");throw T.code="ORGX_AUTH",T}throw new Error(I.length>0?I.join(" | "):"Snapshot endpoint unavailable")}const U=Array.isArray(S.activity)?S.activity:[],fe=Array.isArray(S.handoffs)?S.handoffs:[],be=r&&Array.isArray(S.decisions)?S.decisions:[],Z=S.sessions&&Array.isArray(S.sessions.nodes)&&Array.isArray(S.sessions.edges)&&Array.isArray(S.sessions.groups)?S.sessions:En(U,S.agents,o);ee(Z,U,fe,be,S.outbox??null,S.generatedAt??null,S.runtimeInstances??null);const G=Array.isArray(S.degraded)?S.degraded:[];G.length>0?(p(`Partial live data: ${G.join("; ")}`),m(T=>T.connection==="reconnecting"?T:{...T,connection:"reconnecting"}),H(!0)):(p(null),m(T=>T.connection==="connected"?T:{...T,connection:"connected"}))}catch(F){const z=F instanceof Error?F.message:"Unknown error",I=!!(F&&typeof F=="object"&&"code"in F&&F.code==="ORGX_AUTH");I&&(te.current=!0);const S=L.current>0&&Date.now()-L.current>bs;p(z),m($=>{const U=I||S?"disconnected":"reconnecting";return $.connection===U?$:{...$,connection:U}}),H(!I),x(!1)}finally{D.current=null}})();return D.current=N,N},[ee,s,r,d,v,l,o,n]),E=a.useCallback(async(N,F)=>{if(!r)throw new Error("OrgX decisions are unavailable while disconnected.");const z=Array.from(new Set(N.filter(Boolean)));if(z.length===0)return{updated:0,failed:0};if(n){const Z=new Set(z);return m(G=>{const T=G.decisions.filter(K=>Z.has(K.id));if(T.length===0)return G;const C=new Date().toISOString(),Y=T.map(K=>({id:`decision:${F}:${K.id}:${Date.now()}`,type:"decision_resolved",title:F==="approve"?`Approved: ${K.title}`:`Rejected: ${K.title}`,description:K.context,agentId:null,agentName:K.agentName,runId:null,initiativeId:null,timestamp:C,metadata:{decisionId:K.id,action:F}})),re=Jt(Y.concat(G.activity),d);return{...G,decisions:G.decisions.filter(K=>!Z.has(K.id)),activity:re,lastActivity:Fe(C)}}),{updated:Z.size,failed:0}}const I=await fetch("/orgx/api/live/decisions/approve",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({ids:z,action:F})}),S=await I.json().catch(()=>null),$=Array.isArray(S==null?void 0:S.results)?S.results:[],U=new Set($.filter(Z=>Z.ok).map(Z=>Z.id));if(!I.ok&&I.status!==207){const Z=typeof(S==null?void 0:S.error)=="string"?S.error:`Decision action failed (${I.status})`;throw new Error(Z)}if(U.size===0&&I.ok&&((S==null?void 0:S.failed)??0)===0)for(const Z of z)U.add(Z);U.size>0?m(Z=>{const G=Z.decisions.filter(K=>U.has(K.id));if(G.length===0)return Z;const T=new Date().toISOString(),C=G.map(K=>({id:`decision:${F}:${K.id}:${Date.now()}`,type:"decision_resolved",title:F==="approve"?`Approved: ${K.title}`:`Rejected: ${K.title}`,description:K.context,agentId:null,agentName:K.agentName,runId:null,initiativeId:null,timestamp:T,metadata:{decisionId:K.id,action:F}})),Y=Jt(C.concat(Z.activity),d);return{...Z,decisions:Z.decisions.filter(K=>!U.has(K.id)),activity:Y,lastActivity:Fe(T)}}):I.ok&&z.length>0&&m(Z=>({...Z,decisions:Z.decisions.filter(G=>!z.includes(G.id))})),q();const fe=(S==null?void 0:S.updated)??U.size,be=(S==null?void 0:S.failed)??Math.max(0,z.length-U.size);return{updated:fe,failed:be}},[r,q,d,n]),ae=a.useCallback(async N=>E([N],"approve"),[E]),k=a.useCallback(async()=>{let N=[];return m(F=>(N=F.decisions.map(z=>z.id),F)),N.length===0?{updated:0,failed:0}:E(N,"approve")},[E]);return a.useEffect(()=>{r||m(N=>N.decisions.length===0?N:{...N,decisions:[]})},[r]),a.useEffect(()=>{if(!s){H(!1),x(!1),p(null);return}if(n){q();return}q();const N=new EventSource("/orgx/api/live/stream");let F=null,z=null,I=null,S=null,$=[],U=null,fe;const be=()=>{if(fe=void 0,F){L.current=Date.now(),te.current=!1;const G=F;F=null,I=null,S=null,$=[],U=null,z=null,ee(G.sessions,G.activity,G.handoffs,G.decisions,G.outbox,G.generatedAt,G.runtimeInstances);return}!I&&!S&&!U&&!z&&$.length===0||(L.current=Date.now(),te.current=!1,m(G=>{var C;let T=G;if(I){const Y=At(I,o),re=At(js(T.sessions,Y),o);I=null,Ns(T.sessions,re)||(T={...T,sessions:re})}if(S){const Y=ks(S,l);S=null,Ss(T.handoffs,Y)||(T={...T,handoffs:Y})}if(U){const Y=As(U,v);U=null,Cs(T.decisions,Y)||(T={...T,decisions:Y})}if(z){const Y=Ms(z);z=null,Es(T.runtimeInstances,Y)||(T={...T,runtimeInstances:Y})}if($.length>0){const Y=An(T.activity,$,d);$=[],Y!==T.activity&&(T={...T,activity:Y,lastActivity:(C=Y[0])!=null&&C.timestamp?Fe(Y[0].timestamp):T.lastActivity})}return T===G?G:T.connection==="connected"?T:{...T,connection:"connected"}}),p(null),x(!1))},Z=()=>{fe||(fe=setTimeout(be,u))};return N.onopen=()=>{L.current=Date.now(),te.current=!1,H(!1),m(G=>G.connection==="connected"?G:{...G,connection:"connected"}),p(null)},N.onerror=()=>{if(te.current){m(T=>T.connection==="disconnected"?T:{...T,connection:"disconnected"}),H(!1);return}const G=L.current>0&&Date.now()-L.current>bs;m(T=>T.connection===(G?"disconnected":"reconnecting")?T:{...T,connection:G?"disconnected":"reconnecting"}),H(!0)},N.addEventListener("snapshot",G=>{try{const T=JSON.parse(G.data),C=typeof T.generatedAt=="string"&&T.generatedAt.length>0?T.generatedAt:new Date().toISOString();F={sessions:T.sessions,activity:T.activity??[],handoffs:T.handoffs??[],decisions:r?T.decisions??null:[],outbox:T.outbox??null,generatedAt:C,runtimeInstances:Array.isArray(T.runtimeInstances)?T.runtimeInstances:null},Z()}catch(T){p(T instanceof Error?T.message:"Invalid snapshot")}}),N.addEventListener("activity.appended",G=>{try{const T=JSON.parse(G.data);if(T.length===0)return;$=$.concat(T),Z()}catch{}}),N.addEventListener("session.updated",G=>{try{I=JSON.parse(G.data),Z()}catch{}}),N.addEventListener("runtime.updated",G=>{try{const T=JSON.parse(G.data);z=Array.isArray(T)?T:[T],Z()}catch{}}),N.addEventListener("handoff.updated",G=>{try{S=JSON.parse(G.data),Z()}catch{}}),N.addEventListener("decision.updated",G=>{if(r)try{U=JSON.parse(G.data),Z()}catch{}}),()=>{fe&&clearTimeout(fe),N.close()}},[ee,u,s,r,q,d,v,l,o,n]),a.useEffect(()=>{if(s&&!n&&(M.current&&clearInterval(M.current),!!O))return M.current=setInterval(q,i),()=>{M.current&&clearInterval(M.current)}},[s,q,i,O,n]),{data:y,isLoading:g,error:j,refetch:q,approveDecision:ae,approveAllDecisions:k}}const $n="https://orgx.mintlify.site/guides/openclaw-plugin-setup",Tn=1500,Zt="orgx.onboarding.skip",Dn=680,On=`<!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>`,es={status:"idle",hasApiKey:!1,connectionVerified:!1,workspaceName:null,lastError:null,nextAction:"connect",docsUrl:$n,keySource:"none",installationId:null,connectUrl:null,pairingId:null,expiresAt:null,pollIntervalMs:null};function Bn(t){if(typeof t=="string")return t;if(t&&typeof t=="object")return JSON.stringify(t)}async function bt(t){const s=await t,i=await s.json().catch(()=>null);return s.ok?i??{}:{ok:!1,error:Bn(i==null?void 0:i.error)??`Request failed (${s.status})`}}function Mt(t){if(t)try{Hs.identify(t)}catch{}}function Pn(){const[t,s]=a.useState(es),[i,n]=a.useState(!0),[r,o]=a.useState(!1),[d,l]=a.useState(!1),v=a.useRef(null),[u,y]=a.useState(()=>typeof window>"u"?!1:window.localStorage.getItem(Zt)==="1"),m=a.useCallback(async()=>{const O=await bt(fetch("/orgx/api/onboarding/status",{method:"GET"}));if(!O.ok||!O.data){const H=O.error??"Failed to load onboarding state",L={...es,status:"error",lastError:H,nextAction:"retry"};return s(L),L}return Mt(O.data.installationId??null),s(O.data),O.data},[]);a.useEffect(()=>{let O=!1;return(async()=>{n(!0);const H=await m();O||(s(H),n(!1))})(),()=>{O=!0}},[m]),a.useEffect(()=>{if(!(t.status==="awaiting_browser_auth"||t.status==="pairing"))return;const H=Math.max(900,t.pollIntervalMs??Tn),L=window.setInterval(async()=>{const te=await bt(fetch("/orgx/api/onboarding/status",{method:"GET"}));te.ok&&te.data&&(Mt(te.data.installationId??null),s(te.data))},H);return()=>{window.clearInterval(L)}},[t.pollIntervalMs,t.status]),a.useEffect(()=>{if(!(typeof window>"u")){if(u){window.localStorage.setItem(Zt,"1");return}window.localStorage.removeItem(Zt)}},[u]);const g=a.useCallback(()=>{if(typeof window>"u")return null;try{const O=window.open("","_blank");return O?(O.opener=null,O.document.title="Connecting to OrgX…",O.document.open(),O.document.write(On),O.document.close(),O):null}catch{return null}},[]),x=a.useCallback(async()=>{const O=g();v.current=O,o(!0);try{const H=await bt(fetch("/orgx/api/onboarding/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({deviceName:navigator.platform||"OpenClaw Device",platform:navigator.platform})})),L=H.data;if(!H.ok||!(L!=null&&L.state)){O&&!O.closed&&O.close();const ee=H.error??"Could not start pairing";s(q=>({...q,status:"error",lastError:ee,nextAction:"enter_manual_key"}));return}s(L.state);const te=L.connectUrl;if(te){const ee=v.current;let q=!1;if(ee&&!ee.closed)try{window.setTimeout(()=>{if(!ee.closed)try{ee.location.href=te}catch{}},Dn),q=!0}catch{q=!1}q||(q=!!window.open(te,"_blank","noopener,noreferrer")),q||s(E=>({...E,lastError:'Popup was blocked. Use "Approve in browser" below.',nextAction:"open_browser"}))}}finally{v.current=null,o(!1)}},[g]),j=a.useCallback(async O=>{l(!0);try{const H=O.trim(),L=H.replace(/^[a-z]+_/i,""),te=Array.from(new Set([H,L?`oxk_${L}`:"",L?`orgx_${L}`:""].map(q=>q.trim()).filter(q=>q.length>0)));let ee="Manual key validation failed";for(const q of te){const E={"Content-Type":"application/json","X-OrgX-Api-Key":q,Authorization:`Bearer ${q}`},ae=await bt(fetch("/orgx/api/onboarding/manual-key",{method:"POST",headers:E,body:JSON.stringify({apiKey:q})}));if(ae.ok&&ae.data)return Mt(ae.data.installationId??null),s(ae.data),ae.data;ee=ae.error??ee}throw s(q=>({...q,status:"manual_key",lastError:ee,nextAction:"enter_manual_key"})),new Error(ee)}finally{l(!1)}},[]),p=a.useCallback(async()=>{const O=await bt(fetch("/orgx/api/onboarding/disconnect",{method:"POST"}));if(O.ok&&O.data)return Mt(O.data.installationId??null),s(O.data),O.data;const H={...es,status:"idle"};return s(H),H},[]),M=a.useCallback(()=>{s(O=>({...O,status:"idle",lastError:null,nextAction:"connect",connectUrl:null,pairingId:null,expiresAt:null,pollIntervalMs:null}))},[]),D=a.useMemo(()=>u?!1:!(t.hasApiKey&&t.connectionVerified&&t.status==="connected"),[u,t.connectionVerified,t.hasApiKey,t.status]);return{state:t,showGate:D,isLoading:i,isStarting:r,isSubmittingManual:d,refreshStatus:m,startPairing:x,submitManualKey:j,disconnect:p,skipGate:()=>y(!0),resumeGate:()=>y(!1),backToPairing:M,setManualMode:()=>s(O=>({...O,status:"manual_key",nextAction:"enter_manual_key"}))}}function ge(...t){return t.filter(Boolean).join(" ")}const f={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"},Rn={Pace:"#7C7CFF",Eli:"#BFFF00",Dana:"#FF00D4",Mark:"#F5B700",System:"#14B8A6",Sage:"#0AD4C4",Orion:"#14B8A6",Xandy:"#FF6B88",Nova:"#A78BFA"},zn={Pace:"Engineering",Eli:"Engineering",Dana:"Product Design",Mark:"Marketing",System:"System",Sage:"Strategy",Orion:"Operations",Xandy:"Orchestrator",Nova:"Research"};function qn(t){return Rn[t]??f.teal}function hs(t){return zn[t]??null}function Un(t){return t.split(" ").map(s=>s[0]).join("").toUpperCase().slice(0,2)}const Kt="/orgx/live/assets/Fm0FhtnV.png";function Zs({size:t=14,className:s="",stroke:i="currentColor",strokeWidth:n=1.8,withBackground:r=!1,backgroundColor:o="transparent"}){return e.jsxs("svg",{className:s,width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:i,strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:n,children:[r?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 Me({type:t,className:s="",size:i=14}){const n={className:s,width:i,height:i,viewBox:"0 0 24 24",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.8};return t==="initiative"?e.jsxs("svg",{...n,stroke:f.iris,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9",fill:`${f.iris}1A`}),e.jsx("circle",{cx:"12",cy:"12",r:"5"}),e.jsx("circle",{cx:"12",cy:"12",r:"1.5",fill:f.iris,stroke:"none"})]}):t==="workstream"?e.jsx(Zs,{size:i,className:s,stroke:f.lime,strokeWidth:n.strokeWidth,withBackground:!0,backgroundColor:`${f.lime}1A`}):t==="milestone"?e.jsxs("svg",{...n,stroke:f.teal,children:[e.jsx("path",{d:"M5 3v18"}),e.jsx("path",{d:"m5 4 12 1-2 4 2 4-12-1z",fill:`${f.teal}1A`})]}):t==="task"?e.jsxs("svg",{...n,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"})]}):t==="decision"?e.jsxs("svg",{...n,stroke:f.amber,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:`${f.amber}1A`}),e.jsx("path",{d:"m9.3 12.1 1.8 1.9 3.6-3.6"})]}):e.jsxs("svg",{...n,stroke:f.cyan,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:`${f.cyan}1A`}),e.jsx("path",{d:"M9.2 18a2.8 2.8 0 0 0 5.6 0"})]})}const Wn=[{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"}],Bt=[{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."}],Kn=[{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."}],_s="openclaw plugins install @useorgx/openclaw-plugin",Fs="orgx.demo_mode",Vn=6500;function Hn(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 Gn={hidden:{},visible:{transition:{staggerChildren:.07}}},Qe={hidden:{opacity:0,y:14},visible:{opacity:1,y:0,transition:{duration:.45,ease:[.16,1,.3,1]}}},Xn={initiative:"text-[#A8A0FF]",workstream:"text-[#BFFF00]",milestone:"text-[#43E7D8]",task:"text-white/80",decision:"text-[#F5D37A]",notification:"text-[#7EEDE1]"};function ts(t){const s=Bt.length;return(t+s)%s}function Qn({state:t,isStarting:s,onConnect:i,onUseManualKey:n,onContinueWithoutOrgX:r}){const o=!!t.lastError,[d,l]=a.useState("idle"),[v,u]=a.useState(0),[y,m]=a.useState(!1),g=t.hasApiKey&&t.keySource&&t.keySource!=="none",x=Bt[v];a.useEffect(()=>{if(d==="idle")return;const p=window.setTimeout(()=>l("idle"),2e3);return()=>window.clearTimeout(p)},[d]),a.useEffect(()=>{if(y)return;const p=window.setInterval(()=>{u(M=>ts(M+1))},Vn);return()=>window.clearInterval(p)},[y]);const j=async()=>{try{await navigator.clipboard.writeText(_s),l("ok")}catch{l("error")}};return e.jsxs(de.section,{variants:Gn,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(de.div,{variants:Qe,className:"flex items-center gap-2.5",children:[e.jsx("img",{src:Kt,alt:"OrgX",className:"h-7 w-7 rounded-lg object-contain"}),e.jsx("span",{className:"text-[13px] font-semibold text-white/70",children:"OrgX"})]}),e.jsxs(de.h2,{variants:Qe,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(Me,{type:"workstream",size:19,className:"opacity-95"}),"Connect your workspace"]}),e.jsx(de.p,{variants:Qe,className:"mt-2 max-w-2xl text-[14px] leading-relaxed text-white/50",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(de.div,{variants:Qe,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:()=>m(!0),onMouseLeave:()=>m(!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(Me,{type:"workstream",size:14,className:"text-[#BFFF00]"}),e.jsx("p",{className:"text-[10px] uppercase tracking-[0.1em] text-white/45",children:"Guided Tour"})]}),e.jsxs("span",{className:"chip text-[10px]",children:[v+1,"/",Bt.length]})]}),e.jsx(Te,{initial:!1,mode:"wait",children:e.jsxs(de.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-[10px] font-semibold uppercase tracking-[0.09em] text-white/40",children:x.kicker}),e.jsx("h3",{className:"text-[16px] font-semibold leading-snug text-white/94",children:x.title}),e.jsx("p",{className:"text-[12px] leading-relaxed text-white/55",children:x.description}),e.jsx("div",{className:"grid gap-1.5 sm:grid-cols-2",children:x.highlights.map(p=>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(Me,{type:p.type,size:12,className:"flex-shrink-0 opacity-92"}),e.jsx("p",{className:"text-[11px] font-semibold text-white/88",children:p.label})]}),e.jsx("p",{className:"mt-0.5 text-[10px] leading-relaxed text-white/50",children:p.detail})]},`${x.id}-${p.label}`))}),e.jsx("p",{className:"text-[10px] leading-relaxed text-white/42",children:x.footnote})]},x.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:Bt.map((p,M)=>{const D=M===v;return e.jsx("button",{type:"button",onClick:()=>u(M),"aria-label":`View slide ${M+1}`,className:`h-1.5 rounded-full transition-all ${D?"w-6 bg-[#BFFF00]":"w-2 bg-white/24 hover:bg-white/38"}`},p.id)})}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>u(p=>ts(p-1)),className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-2.5 py-1 text-[11px] text-white/70 transition hover:bg-white/[0.08] hover:text-white",children:"Prev"}),e.jsx("button",{type:"button",onClick:()=>u(p=>ts(p+1)),className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-2.5 py-1 text-[11px] text-white/70 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:Wn.map(p=>e.jsxs("div",{className:"rounded-xl border border-white/[0.06] bg-white/[0.025] px-3 py-2.5",children:[e.jsx("div",{className:`mb-1.5 ${Xn[p.iconType]}`,children:e.jsx(Me,{type:p.iconType,size:15})}),e.jsx("p",{className:"text-[11px] font-semibold text-white",children:p.label}),e.jsx("p",{className:"mt-0.5 text-[10px] leading-snug text-white/44",children:p.desc})]},p.label))}),e.jsxs(de.div,{variants:Qe,className:"flex flex-wrap items-center gap-2.5",children:[e.jsx("button",{type:"button",onClick:i,disabled:s,className:"inline-flex items-center gap-2 rounded-full bg-[#BFFF00] px-5 py-2.5 text-[13px] 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-[13px] text-white/60 transition hover:border-white/[0.18] hover:text-white/85",children:"Use API key"})]})]}),e.jsxs(de.div,{variants:Qe,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(Me,{type:"workstream",size:12,className:"text-[#7EEDE1]"}),e.jsx("p",{className:"text-[11px] uppercase tracking-[0.08em] text-[#7EEDE1]",children:"OpenClaw Integration"})]}),e.jsx("p",{className:"mt-1 text-[11px] 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(Me,{type:"task",size:12,className:"opacity-90"}),e.jsx("p",{className:"text-[11px] uppercase tracking-[0.08em] text-white/38",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-[11px] text-white/75",children:_s}),e.jsx("button",{type:"button",onClick:()=>{j()},className:"rounded-full border border-white/[0.12] px-3 py-1 text-[11px] text-white/65 transition hover:border-white/[0.2] hover:text-white/90",children:d==="ok"?"Copied":d==="error"?"Copy failed":"Copy command"})]}),g&&e.jsxs("p",{className:"mt-2 text-[11px] text-white/45",children:["API key source detected: ",Hn(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-[11px] uppercase tracking-[0.08em] text-white/38",children:"What Unlocks After Connect"}),e.jsx("div",{className:"mt-2 space-y-1.5",children:Kn.map(p=>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(Me,{type:p.type,size:12,className:"flex-shrink-0 opacity-90"}),e.jsx("p",{className:"text-[11px] font-semibold text-white/88",children:p.label})]}),e.jsx("p",{className:"mt-0.5 text-[10px] leading-relaxed text-white/48",children:p.detail})]},p.label))})]})]})]}),e.jsx(de.div,{variants:Qe,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-[13px] text-red-300/80",children:t.lastError})}),e.jsx("button",{type:"button",onClick:i,disabled:s,className:"shrink-0 text-[12px] font-medium text-red-300/70 transition hover:text-red-200",children:"Retry"})]}):e.jsxs("div",{className:"flex items-center gap-2 rounded-xl border border-white/[0.06] 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-[12px] text-white/40",children:"Ready to connect"})]})}),e.jsxs(de.div,{variants:Qe,className:"mt-2 flex flex-wrap items-center justify-between gap-2 border-t border-white/[0.05] 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(Fs,"1")}catch{}r()},className:"text-left text-[11px] text-white/35 transition hover:text-white/60",children:"Explore demo dashboard"}),e.jsx("button",{type:"button",onClick:()=>{try{window.localStorage.removeItem(Fs)}catch{}r()},className:"text-left text-[11px] text-white/25 transition hover:text-white/55",children:"Continue offline"})]}),e.jsxs("a",{href:t.docsUrl,target:"_blank",rel:"noopener noreferrer",className:"group inline-flex items-center gap-1 text-[11px] text-white/35 transition hover:text-white/60",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 Jn={hidden:{},visible:{transition:{staggerChildren:.06}}},ut={hidden:{opacity:0,y:10},visible:{opacity:1,y:0,transition:{duration:.35,ease:[.16,1,.3,1]}}};function en({isSubmitting:t,onSubmit:s,onBack:i}){const[n,r]=a.useState(""),[o,d]=a.useState(null),l=async()=>{d(null);const u=n.trim();if(!u){d("API key is required.");return}const y=/^[a-z]+_/i.test(u)?u:`oxk_${u}`;try{await s(y),r("")}catch(m){d(m instanceof Error?m.message:"Failed to validate API key.")}},v=o!==null;return e.jsxs(de.section,{variants:Jn,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(de.div,{variants:ut,className:"flex items-center gap-2.5",children:[e.jsx("img",{src:Kt,alt:"OrgX",className:"h-7 w-7 rounded-lg object-contain"}),e.jsx("span",{className:"text-[13px] font-semibold text-white/70",children:"OrgX"})]}),e.jsx(de.h3,{variants:ut,className:"mt-5 text-[22px] font-semibold tracking-[-0.02em] text-white",children:"Manual API key"}),e.jsxs(de.p,{variants:ut,className:"mt-1.5 text-[14px] leading-relaxed text-white/45",children:["Paste a key from your ",e.jsx("span",{className:"text-white/60",children:"useorgx.com"})," dashboard. Browser pairing is recommended."]}),e.jsxs(de.p,{variants:ut,className:"mt-1 text-[12px] text-white/35",children:["Paste full key or only the part after ",e.jsx("span",{className:"font-mono text-white/50",children:"oxk_"}),"."]})]}),e.jsxs(de.div,{variants:ut,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-[11px] font-medium uppercase tracking-[0.14em] text-white/40",children:"API key"}),e.jsxs("div",{className:`flex items-stretch overflow-hidden rounded-xl border transition-colors focus-within:border-[#BFFF00]/40 ${v?"border-red-500/30":"border-white/[0.08]"}`,children:[e.jsx("span",{className:"flex items-center border-r border-white/[0.06] bg-white/[0.03] px-3 font-mono text-[13px] text-white/25 select-none",children:"oxk_"}),e.jsx("input",{value:n,onChange:u=>{r(u.target.value),o&&d(null)},placeholder:"paste your key",className:"w-full bg-transparent px-3 py-2.5 font-mono text-[13px] text-white outline-none placeholder:text-white/15"})]}),v&&e.jsx(de.p,{initial:{opacity:0,y:-3},animate:{opacity:1,y:0},className:"mt-1.5 text-[12px] text-red-400/70",children:o})]}),e.jsxs("p",{className:"text-[12px] text-white/35",children:["User-scoped keys (",e.jsx("span",{className:"font-mono text-white/50",children:"oxk_..."}),") do not require a separate user ID header."]})]}),e.jsxs(de.div,{variants:ut,className:"mt-6 flex flex-wrap items-center gap-3 px-6 sm:px-8",children:[e.jsx("button",{type:"button",onClick:()=>{l()},disabled:t,className:"inline-flex items-center gap-2 rounded-full bg-[#BFFF00] px-5 py-2.5 text-[13px] 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:i,className:"rounded-full border border-white/[0.1] px-4 py-2 text-[13px] text-white/60 transition hover:border-white/[0.18] hover:text-white/85",children:"Back to pairing"})]}),e.jsx("div",{className:"mt-6 border-t border-white/[0.05] px-6 py-4 sm:px-8",children:e.jsx("p",{className:"text-[12px] text-white/25",children:"Keys are stored locally and never leave your device."})})]})}const Yn=[{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 tn({className:t,compact:s=!1}){return e.jsxs("div",{className:ge("flex flex-wrap items-center gap-x-3 gap-y-1 text-white/35",s?"text-[10px]":"text-[11px]",t),children:[e.jsxs("span",{className:"text-white/25",children:["© ",new Date().getFullYear()," OrgX"]}),Yn.map(i=>e.jsx("a",{href:i.href,target:"_blank",rel:"noopener noreferrer nofollow",className:"transition-colors hover:text-white/65",children:i.label},i.label))]})}function Zn(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 ei(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 ti(t){return t==="awaiting_browser_auth"||t==="pairing"||t==="starting"?"active":t==="error"?"error":t==="connected"?"active":"idle"}const Ls={idle:"bg-white/40",active:"bg-[#BFFF00]",error:"bg-red-400"},ss="orgx.onboarding.mc_hint.dismissed",$s={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 si({state:t,isLoading:s,isStarting:i,isSubmittingManual:n,onRefresh:r,onStartPairing:o,onSubmitManualKey:d,onBackToPairing:l,onUseManualKey:v,onSkip:u}){const[y,m]=a.useState(()=>typeof window>"u"?!1:window.localStorage.getItem(ss)==="1");a.useEffect(()=>{typeof window>"u"||(y?window.localStorage.setItem(ss,"1"):window.localStorage.removeItem(ss))},[y]);const g=t.status==="manual_key",x=t.status==="awaiting_browser_auth"||t.status==="pairing",j=ti(t.status),p=j==="active"&&t.status!=="connected",M=t.status==="connected"&&!y;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(de.div,{initial:{opacity:0},animate:{opacity:1},transition:{duration:.45},className:`relative z-10 w-full ${g?"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(Te,{mode:"wait",children:g?e.jsx(de.div,{...$s,children:e.jsx(en,{isSubmitting:n,onSubmit:d,onBack:l})},"manual"):e.jsx(de.div,{...$s,children:e.jsx(Qn,{state:t,isStarting:i,onConnect:()=>{o()},onUseManualKey:v,onContinueWithoutOrgX:u})},"explainer")}),!s&&(x||t.status==="connected")&&e.jsxs(de.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-white/[0.06] 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:[p&&e.jsx("span",{className:`absolute inline-flex h-full w-full animate-ping rounded-full ${Ls[j]} opacity-40`}),e.jsx("span",{className:`relative inline-flex h-2 w-2 rounded-full ${Ls[j]}`})]}),e.jsx("span",{className:"text-[13px] text-white/60",children:Zn(t.status)}),t.workspaceName&&e.jsx("span",{className:"chip",children:t.workspaceName}),t.keySource&&t.keySource!=="none"&&e.jsx("span",{className:"chip",children:ei(t.keySource)})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[t.expiresAt&&e.jsx("span",{className:"text-[11px] text-white/30",children:new Date(t.expiresAt).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}),t.connectUrl&&x&&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-[11px] font-medium text-[#D8FFA1] transition hover:bg-[#BFFF00]/[0.1]",children:"Approve in browser"}),e.jsx("button",{type:"button",onClick:()=>{r()},className:"rounded-full border border-white/[0.08] px-2.5 py-1 text-[11px] text-white/40 transition hover:bg-white/[0.04] hover:text-white/60",children:"Refresh"})]})]}),M&&e.jsxs(de.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-[11px] uppercase tracking-[0.08em] text-[#CFCBFF]",children:"Mission Control Tip"}),e.jsx("p",{className:"mt-1 text-[12px] 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-[11px] font-medium text-[#D8FFA1]",children:"Open Mission Control"}),e.jsx("button",{type:"button",onClick:()=>m(!0),className:"text-[11px] text-white/60 underline underline-offset-2",children:"Dismiss"})]})]}),!s&&e.jsx("div",{className:"mt-3 flex justify-center",children:e.jsx(tn,{compact:!0})})]})})}function pt({open:t,onClose:s,children:i,maxWidth:n="max-w-2xl",fitContent:r=!1}){const o=a.useRef(null),d=a.useRef(null);a.useEffect(()=>{if(!t)return;d.current=document.activeElement instanceof HTMLElement?document.activeElement:null,(()=>{const m=o.current;if(!m)return;const g=m.querySelector('[data-modal-autofocus="true"]');if(g){g.focus();return}const x=m.querySelectorAll('a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])');x.length>0?x[0].focus():m.focus()})();const u=m=>{if(m.key==="Escape"){m.preventDefault(),s();return}if(m.key!=="Tab")return;const g=o.current;if(!g)return;const x=g.querySelectorAll('a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])');if(x.length===0){m.preventDefault(),g.focus();return}const j=x[0],p=x[x.length-1],M=document.activeElement;!m.shiftKey&&M===p?(m.preventDefault(),j.focus()):m.shiftKey&&M===j&&(m.preventDefault(),p.focus())},y=document.body.style.overflow;return document.body.style.overflow="hidden",document.addEventListener("keydown",u),()=>{var m;document.body.style.overflow=y,document.removeEventListener("keydown",u),(m=d.current)==null||m.focus()}},[t,s]);const l=e.jsx(Te,{children:t&&e.jsxs(de.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(de.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 ${r?"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:f.cardBgElevated,borderColor:f.cardBorderStrong},onClick:v=>v.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"}),i]})]})});return typeof document>"u"?l:pn.createPortal(l,document.body)}function it(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 sn({authToken:t=null,embedMode:s=!1,enabled:i=!0}={}){var u,y;const n=Vs(),r=a.useMemo(()=>["byok-settings",{authToken:t,embedMode:s}],[t,s]),o=a.useMemo(()=>["byok-health",{authToken:t,embedMode:s}],[t,s]),d=Ve({queryKey:r,enabled:i,queryFn:async()=>{const m=await fetch("/orgx/api/settings/byok",{headers:it({authToken:t,embedMode:s})}),g=await m.json().catch(()=>null);return m.ok?g:{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:(g==null?void 0:g.error)??`Failed to load settings (${m.status})`}},staleTime:15e3}),l=Ve({queryKey:o,enabled:!1,queryFn:async()=>{const m=await fetch("/orgx/api/settings/byok/health",{headers:it({authToken:t,embedMode:s})}),g=await m.json().catch(()=>null);return m.ok?g:{ok:!1,agentId:"main",providers:{openai:{ok:!1,error:(g==null?void 0:g.error)??`Probe failed (${m.status})`},anthropic:{ok:!1,error:(g==null?void 0:g.error)??`Probe failed (${m.status})`},openrouter:{ok:!1,error:(g==null?void 0:g.error)??`Probe failed (${m.status})`}},error:(g==null?void 0:g.error)??`Probe failed (${m.status})`}}}),v=Ot({mutationFn:async m=>{const g=await fetch("/orgx/api/settings/byok",{method:"POST",headers:it({authToken:t,embedMode:s,contentTypeJson:!0}),body:JSON.stringify(m??{})}),x=await g.json().catch(()=>null);if(!g.ok)throw new Error((x==null?void 0:x.error)??`Failed to save settings (${g.status})`);return x},onSuccess:async()=>{await n.invalidateQueries({queryKey:r})}});return{status:d.data??null,isLoading:d.isLoading,error:((u=d.data)==null?void 0:u.error)??((y=d.error)==null?void 0:y.message)??null,refetchStatus:d.refetch,update:v.mutateAsync,isSaving:v.isPending,health:l.data??null,probe:l.refetch,isProbing:l.isFetching}}const nn="orgx.first_run_guide.dismissed";function ni(t){return e.jsx("span",{className:ge("inline-flex h-2 w-2 rounded-full",t?"bg-emerald-400":"bg-white/35")})}function ii(){try{return typeof window<"u"&&window.localStorage.getItem(nn)==="1"}catch{return!1}}function ri(t){try{if(typeof window>"u")return;t&&window.localStorage.setItem(nn,"1")}catch{}}function ai({open:t,onClose:s,onOpenSettings:i,onOpenOrgxSettings:n,onOpenMissionControl:r,demoMode:o,connectionVerified:d,hasSessions:l}){const v=sn({enabled:t}),y=a.useMemo(()=>{var p;return(p=v.status)!=null&&p.ok?Number(v.status.providers.openai.configured)+Number(v.status.providers.anthropic.configured)+Number(v.status.providers.openrouter.configured):0},[v.status])>0,m=y?"mission-control":"settings",g=[{label:o?"Exit demo (optional)":"Connect OrgX",done:o?!1:d,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&&!d&&n?{label:"Connect",onClick:n}:null},{label:"Add provider key(s)",done:y,detail:"Set OpenAI / Anthropic / OpenRouter keys for agent launches, or rely on env vars.",action:y?null:{label:"Open settings",onClick:i}},{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:r}}],x=g.filter(p=>p.done).length,j=Math.round(x/g.length*100);return e.jsx(pt,{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-white/[0.06] 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-[15px] font-semibold text-white",children:"First run checklist"}),e.jsx("p",{className:"mt-1 text-[12px] leading-relaxed text-white/55",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:[x," / ",g.length," complete"]}),e.jsxs("span",{className:"text-[11px] text-white/35",children:[j,"% 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:`${j}%`}})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>{ri(!0),s()},className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-3 py-1.5 text-[11px] font-semibold text-white/70 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-white/[0.12] bg-white/[0.03] text-white/70 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:g.map(p=>e.jsxs("div",{className:ge("flex items-start justify-between gap-3 rounded-xl border p-3",p.done?"border-white/[0.06] 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:ni(p.done)}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:ge("text-[13px] font-semibold",p.done?"text-white/80":"text-white"),children:p.label}),e.jsx("p",{className:"mt-0.5 text-[12px] leading-relaxed text-white/45",children:p.detail})]})]}),p.action&&!p.done?e.jsx("button",{type:"button",onClick:p.action.onClick,"data-modal-autofocus":m==="settings"&&p.label==="Add provider key(s)"||m==="mission-control"&&p.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-[11px] font-semibold text-[#D8FFA1]",children:p.action.label}):null]},p.label))}),e.jsxs("div",{className:"mt-4 flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",onClick:i,"data-modal-autofocus":m==="settings"?"true":void 0,className:"rounded-full border border-[#BFFF00]/30 bg-[#BFFF00]/15 px-3 py-1.5 text-[11px] font-semibold text-[#D8FFA1]",children:"Open settings"}),e.jsx("button",{type:"button",onClick:r,"data-modal-autofocus":m==="mission-control"?"true":void 0,className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-3 py-1.5 text-[11px] font-semibold text-white/70 transition-colors hover:bg-white/[0.08]",children:"Open Mission Control"}),e.jsx("button",{type:"button",onClick:s,className:"rounded-full border border-white/[0.12] px-3 py-1.5 text-[11px] text-white/55 transition-colors hover:bg-white/[0.05] hover:text-white/80",title:"Hide for now",children:"Not now"})]})]})}),e.jsx("div",{className:"border-t border-white/[0.06] px-5 py-3 sm:px-6",children:e.jsx("p",{className:"text-[11px] text-white/40",children:"Tip: auto-continue is available per initiative from Mission Control quick actions."})})]})})}function Ts({children:t,color:s,pulse:i,title:n}){const r=s??f.lime;return e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full px-2.5 py-1 text-[10px] font-semibold uppercase tracking-[0.14em]",title:n,style:{backgroundColor:`${r}22`,border:`1px solid ${r}5a`,color:r},children:[e.jsxs("span",{className:"relative flex h-1.5 w-1.5",children:[i&&e.jsx("span",{className:"absolute inline-flex h-full w-full animate-ping rounded-full opacity-75",style:{backgroundColor:r}}),e.jsx("span",{className:"relative inline-flex h-1.5 w-1.5 rounded-full",style:{backgroundColor:r}})]}),t]})}const oi=[{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 li({activeTab:t,onTabChange:s,pendingDecisionCount:i=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-white/[0.12] bg-[#090d16]/90 p-1.5 shadow-[0_20px_50px_rgba(0,0,0,0.52)] backdrop-blur-xl",children:oi.map(n=>{const r=t===n.id;return e.jsxs("button",{type:"button",onClick:()=>s(n.id),"aria-current":r?"page":void 0,className:ge("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",r?"text-lime":"text-white/45 hover:text-white/72"),children:[r&&e.jsxs(e.Fragment,{children:[e.jsx(de.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(de.span,{layoutId:"mobile-tab-active-line",className:"absolute inset-x-3 top-0.5 h-[2px] rounded-full",style:{backgroundColor:f.lime},transition:{type:"spring",stiffness:440,damping:36,mass:.75}})]}),e.jsxs("span",{className:ge("relative inline-flex h-8 w-8 items-center justify-center rounded-full border transition-colors",r?"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"&&i>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:f.amber},children:i>99?"99+":i})]}),e.jsx("span",{className:ge("relative z-[1] text-[10px] font-medium",r?"text-[#D8FFA1]":"text-white/55"),children:n.label})]},n.id)})})})}const Wt={codex:{id:"codex",label:"Codex",accent:"#10B981",tint:"rgba(16, 185, 129, 0.18)"},openai:{id:"openai",label:"OpenAI",accent:"#9F7AEA",tint:"rgba(159, 122, 234, 0.2)"},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:f.lime,tint:"rgba(191, 255, 0, 0.18)"},unknown:{id:"unknown",label:"Agent",accent:f.teal,tint:"rgba(20, 184, 166, 0.18)"}},ci=["provider","vendor","model","runtime","engine","agent","name","title","label","summary","description","source"];function Pt(t,s,i,n){if(!(t==null||i>2)){if(typeof t=="string"){const r=t.trim();r.length>0&&s.push(r);return}if(Array.isArray(t)){for(const r of t)Pt(r,s,i+1,n);return}if(typeof t=="object"){if(n.has(t))return;n.add(t);for(const[r,o]of Object.entries(t)){const d=r.toLowerCase();typeof o=="string"?(ci.some(l=>d.includes(l))||d.startsWith("meta")||d.endsWith("id"))&&Pt(o,s,i+1,n):typeof o=="object"&&o!==null&&Pt(o,s,i+1,n)}}}}function di(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 Ds(...t){const s=[],i=new Set;for(const n of t)Pt(n,s,0,i);for(const n of s){const r=di(n);if(r)return Wt[r]}return Wt.unknown}function ui(t){return Wt[t]??Wt.unknown}function at({children:t,className:s=""}){return e.jsx("section",{className:ge("surface-tier-1 relative overflow-hidden rounded-2xl",s),children:t})}const pi={xs:18,sm:24,md:30};function hi({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:Kt,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 ns({provider:t,size:s="sm",className:i,showRing:n=!0}){const r=ui(t),o=pi[s];return e.jsx("span",{className:ge("inline-flex items-center justify-center rounded-md",i),style:{width:o,height:o,color:r.accent,backgroundColor:r.tint,border:n?`1px solid ${r.accent}55`:"none"},title:r.label,"aria-label":r.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(hi,{provider:t})})})}const xi={xs:"w-6 h-6 text-[9px]",sm:"w-8 h-8 text-[10px]",md:"w-10 h-10 text-[12px]"},mi="/orgx/live/",Oe=t=>`${mi.replace(/\/+$/,"/")}${t}`,fi={pace:Oe("brand/product-orchestrator.png"),eli:Oe("brand/engineering-autopilot.png"),mark:Oe("brand/launch-captain.png"),sage:Oe("brand/pipeline-intelligence.png"),orion:Oe("brand/control-tower.png"),dana:Oe("brand/design-codex.png"),xandy:Oe("brand/product-orchestrator.png"),nova:Oe("brand/product-orchestrator.png"),openclaw:Oe("brand/openclaw-mark.svg"),openai:Oe("brand/openai-mark.svg"),anthropic:Oe("brand/anthropic-mark.svg"),orgx:Oe("brand/orgx-logo.png")},gi=[{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 bi(...t){const s=t.map(i=>typeof i=="string"?i.trim():"").filter(Boolean).join(" ").toLowerCase();if(!s)return null;for(const i of gi)if(i.test.test(s))return fi[i.key];return null}function Ke({name:t,size:s="xs",hint:i,src:n}){const r=qn(t),[o,d]=a.useState(!1),l=a.useMemo(()=>n&&n.trim()?n:bi(t,i),[i,t,n]),v=!!(l&&!o);return e.jsx("div",{className:`${xi[s]} overflow-hidden rounded-full flex items-center justify-center font-semibold flex-shrink-0`,style:{backgroundColor:`${r}20`,color:r,border:`1px solid ${r}30`},children:v?e.jsx("img",{src:l??void 0,alt:t,className:"h-full w-full rounded-full object-cover",onError:()=>d(!0),loading:"lazy"}):Un(t)})}const rt={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 wi(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),i=new Date;return Math.max(0,Math.ceil((s.getTime()-i.getTime())/864e5))}function vi(t){return{id:t.id,name:t.title,status:wi(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 ji(t){const s=t.toLowerCase();return!["deleted","archived","cancelled"].includes(s)}function rn(t){return Ve({queryKey:rt.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=>ji(n.status??"")).sort((n,r)=>{const o=Date.parse(n.updated_at??n.created_at??"")||0;return(Date.parse(r.updated_at??r.created_at??"")||0)-o}).map(vi):[]},enabled:t,staleTime:6e4})}const ki=new Set(["ungrouped","unscoped","unknown"]);function Ni(t){const s=(t??"").trim().toLowerCase();return!!(!s||ki.has(s)||/^init-\d+$/.test(s)||s.startsWith("mock-"))}function Si(t){return!Ni(t)}const Et={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 Mi({initiativeId:t,authToken:s=null,embedMode:i=!1,enabled:n=!0}){var l;const r=Si(t),o=a.useMemo(()=>rt.initiativeDetails({initiativeId:t,authToken:s,embedMode:i}),[t,s,i]),d=Ve({queryKey:o,enabled:n&&!!t&&r,queryFn:async()=>{if(!t)return Et;if(!r)return{...Et,initiativeId:t};const v={};i&&(v["X-Orgx-Embed"]="true"),s&&(v.Authorization=`Bearer ${s}`);const u=Object.keys(v).length?v:void 0,y=async D=>{try{const O=new URLSearchParams({type:D,initiative_id:t,limit:"100"}),H=await fetch(`/orgx/api/entities?${O.toString()}`,{headers:u});return H.ok?await H.json():{data:[]}}catch{return{data:[]}}},[m,g,x]=await Promise.all([y("workstream"),y("milestone"),y("task")]),j=Array.isArray(m.data)?m.data.map(D=>Ci(D,t)):[],p=Array.isArray(g.data)?g.data.map(D=>Ai(D,t)):[],M=Array.isArray(x.data)?x.data.map(D=>Ii(D,t)):[];return{initiativeId:t,workstreams:j,milestones:p,tasks:M}}});return{details:(r?d.data:null)??(t?{...Et,initiativeId:t}:Et),isLoading:r?d.isLoading:!1,error:r?((l=d.error)==null?void 0:l.message)??null:null,refetch:d.refetch}}function wt(t){const s=(t??"").toLowerCase();return s==="active"?{label:"Active",color:f.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:f.iris,bg:"rgba(124,124,255,0.10)"}}function Ei(t){return[...t.workstreams].sort((s,i)=>s.name.localeCompare(i.name))}function _i(t,s){return[...s?t.tasks.filter(n=>n.workstreamId===s):t.tasks].sort((n,r)=>n.title.localeCompare(r.title))}function Fi({open:t,onClose:s,onLaunched:i}){var re,K,Se,he,we,je;const n=Ve({queryKey:["openclaw-agent-catalog"],queryFn:async()=>{const w=await fetch("/orgx/api/agents/catalog");if(!w.ok){const R=await w.text().catch(()=>"");throw new Error(R||`Agent catalog failed (${w.status})`)}return await w.json()},enabled:t,staleTime:2e3,refetchInterval:t?3e3:!1}),{data:r}=rn(t),[o,d]=a.useState(""),[l,v]=a.useState(""),[u,y]=a.useState(""),[m,g]=a.useState(""),[x,j]=a.useState("auto"),[p,M]=a.useState(""),[D,O]=a.useState(null),[H,L]=a.useState(null),[te,ee]=a.useState("starter"),[q,E]=a.useState(!1),[ae,k]=a.useState(1),N=a.useMemo(()=>{const w=l.trim();return w?(r==null?void 0:r.find(R=>R.id===w))??null:null},[r,l]),{details:F}=Mi({initiativeId:N?N.id:null,enabled:t&&!!N}),z=a.useMemo(()=>Ei(F),[F]),I=a.useMemo(()=>_i(F,u||null),[F,u]),S=((re=n.data)==null?void 0:re.agents)??[],$=a.useMemo(()=>{const w=o.trim();return w?S.find(R=>R.id===w)??null:null},[S,o]);a.useEffect(()=>{var R,ce;if(!t)return;const w=((R=S.find(X=>X.isDefault))==null?void 0:R.id)??((ce=S[0])==null?void 0:ce.id)??"";!o&&w&&d(w)},[S,t,o]),a.useEffect(()=>{if(!t||l.trim())return;const w=r??[],R=w.length===1?w[0]:null;R&&v(R.id)},[r,t,l]),a.useEffect(()=>{if(!t)return;const w=($==null?void 0:$.model)??"",R=w.includes("openrouter")?"openrouter":w.includes("anthropic")?"anthropic":w.includes("openai")?"openai":"auto";j(R)},[t,$==null?void 0:$.model,o]),a.useEffect(()=>{t&&(O(null),L(null),ee("starter"),k(1))},[t]),a.useEffect(()=>{y(""),g("")},[l]),a.useEffect(()=>{g("")},[u]),a.useEffect(()=>{t&&(p.trim().length>0||N&&M(`Kick off: ${N.name}`))},[p,t,N]);const U=!!o.trim()&&!!l.trim(),fe=ae===1?!!o.trim():ae===2?!!l.trim():U,be=async()=>{var A;const w=(H==null?void 0:H.checkout)??"/orgx/api/billing/checkout",R=te&&te.trim().length>0?te.trim():"starter",X=await(await fetch(w,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({planId:R,billingCycle:"monthly"})})).json().catch(()=>null),ke=((A=X==null?void 0:X.data)==null?void 0:A.url)??(X==null?void 0:X.url)??null;if(!ke)throw new Error((X==null?void 0:X.error)??"Checkout unavailable");window.open(ke,"_blank","noopener,noreferrer")},Z=async()=>{var ke;const w=(H==null?void 0:H.portal)??"/orgx/api/billing/portal",ce=await(await fetch(w,{method:"POST"})).json().catch(()=>null),X=((ke=ce==null?void 0:ce.data)==null?void 0:ke.url)??(ce==null?void 0:ce.url)??null;if(!X)throw new Error((ce==null?void 0:ce.error)??"Billing portal unavailable");window.open(X,"_blank","noopener,noreferrer")},G=async()=>{if(!(!U||q)){O(null),L(null),E(!0);try{const w={agentId:o.trim(),message:p.trim()?p.trim():void 0,initiativeId:l.trim(),initiativeTitle:(N==null?void 0:N.name)??null,workstreamId:u.trim()?u.trim():null,taskId:m.trim()?m.trim():null,provider:x!=="auto"?x:null},R=new URLSearchParams;R.set("agentId",w.agentId),R.set("initiativeId",w.initiativeId),w.initiativeTitle&&R.set("initiativeTitle",w.initiativeTitle),w.workstreamId&&R.set("workstreamId",w.workstreamId),w.taskId&&R.set("taskId",w.taskId),w.message&&R.set("message",w.message),w.provider&&R.set("provider",w.provider);const ce=await fetch(`/orgx/api/agents/launch?${R.toString()}`,{method:"POST"}),X=await ce.json().catch(()=>null);if(!ce.ok||!(X!=null&&X.ok))throw(X==null?void 0:X.code)==="upgrade_required"&&(L(X.actions??null),ee(X.requiredPlan??"starter")),new Error((X==null?void 0:X.error)??`Launch failed (${ce.status})`);s(),i==null||i()}catch(w){O(w instanceof Error?w.message:"Launch failed")}finally{E(!1)}}},T=!!((K=$==null?void 0:$.run)!=null&&K.runId)&&!!((Se=$==null?void 0:$.run)!=null&&Se.pid),C=async()=>{var w;if(!(!((w=$==null?void 0:$.run)!=null&&w.runId)||!T||q)){O(null),E(!0);try{const R=await fetch(`/orgx/api/agents/stop?runId=${encodeURIComponent($.run.runId)}`,{method:"POST"}),ce=await R.json().catch(()=>null);if(!R.ok||!(ce!=null&&ce.ok))throw new Error((ce==null?void 0:ce.error)??`Stop failed (${R.status})`);await n.refetch()}catch(R){O(R instanceof Error?R.message:"Stop failed")}finally{E(!1)}}},Y=async()=>{var w;if(!(!((w=$==null?void 0:$.run)!=null&&w.runId)||q)){O(null),E(!0);try{const R=new URLSearchParams;R.set("runId",$.run.runId),p.trim()&&R.set("message",p.trim()),x&&x!=="auto"&&R.set("provider",x);const ce=await fetch(`/orgx/api/agents/restart?${R.toString()}`,{method:"POST"}),X=await ce.json().catch(()=>null);if(!ce.ok||!(X!=null&&X.ok))throw new Error((X==null?void 0:X.error)??`Restart failed (${ce.status})`);s(),i==null||i()}catch(R){O(R instanceof Error?R.message:"Restart failed")}finally{E(!1)}}};return t?e.jsx(pt,{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-white/[0.06] 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-[14px] font-semibold text-white",children:"Launch OpenClaw Agent"}),e.jsx("p",{className:"mt-1 text-[12px] text-white/55",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-white/[0.12] bg-white/[0.03] p-1 text-[10px] uppercase tracking-[0.12em] text-white/55",children:[[1,"Agent"],[2,"Scope"],[3,"Message"]].map(([w,R])=>e.jsxs("button",{type:"button",onClick:()=>k(w),className:ge("rounded-full px-3 py-1 transition-colors",ae===w?"bg-white/[0.12] text-white":"hover:bg-white/[0.06]"),children:[w,". ",R]},w))})]}),e.jsx("button",{type:"button",onClick:s,className:"rounded-lg border border-white/[0.12] bg-white/[0.03] px-3 py-1.5 text-[12px] text-white/60 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-white/[0.06] bg-white/[0.02] p-4 text-[12px] text-white/55",children:"Loading agent catalog…"}),n.error&&e.jsx("div",{className:"rounded-xl border border-rose-300/20 bg-rose-400/10 p-4 text-[12px] text-rose-100",children:n.error.message}),e.jsx(Te,{mode:"wait",children:e.jsxs(de.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:[ae===1&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] uppercase tracking-[0.1em] text-white/35",children:"Agent"}),e.jsx("select",{value:o,onChange:w=>d(w.target.value),className:"mt-1 w-full rounded-xl border border-white/[0.1] bg-black/30 px-3 py-2 text-[12px] text-white/80 focus:outline-none focus:ring-1 focus:ring-[#BFFF00]/30",children:S.map(w=>{const R=wt(w.status);return e.jsxs("option",{value:w.id,children:[w.name," (",w.id,") · ",R.label]},w.id)})})]}),$&&e.jsxs("div",{className:"rounded-xl border border-white/[0.06] bg-white/[0.02] p-3 text-[12px] text-white/60",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"font-medium text-white/80",children:$.name}),e.jsx("span",{className:"rounded-full border px-2 py-0.5 text-[10px] uppercase tracking-[0.12em]",style:{borderColor:`${wt($.status).color}55`,color:wt($.status).color,backgroundColor:wt($.status).bg},children:wt($.status).label})]}),e.jsxs("div",{className:"mt-2 space-y-2",children:[e.jsxs("p",{className:"truncate",children:[e.jsx("span",{className:"text-white/40",children:"Model:"})," ",$.model??"unknown"]}),e.jsxs("p",{className:"truncate",children:[e.jsx("span",{className:"text-white/40",children:"Workspace:"})," ",$.workspace??"unknown"]}),((he=$.context)==null?void 0:he.initiativeId)&&e.jsxs("p",{className:"truncate",children:[e.jsx("span",{className:"text-white/40",children:"Scoped:"})," ",$.context.initiativeTitle??$.context.initiativeId]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] uppercase tracking-[0.12em] text-white/30",children:"Provider"}),e.jsxs("select",{value:x,onChange:w=>j(w.target.value),className:"mt-1 w-full rounded-xl border border-white/[0.1] bg-black/30 px-3 py-2 text-[12px] text-white/80 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-[10px] text-white/35",children:"Selecting a provider updates the agent's default model before launch."})]}),$.run&&e.jsxs("p",{className:"truncate",children:[e.jsx("span",{className:"text-white/40",children:"Tracked run:"})," ",$.run.runId.slice(0,8),"…"," ",e.jsxs("span",{className:"text-white/35",children:["(",$.run.status,")"]})]}),$.run&&e.jsxs("div",{className:"grid grid-cols-2 gap-2 pt-1",children:[e.jsx("button",{type:"button",onClick:C,disabled:!T||q,className:"rounded-lg border border-rose-300/25 bg-rose-400/10 px-3 py-2 text-[11px] font-semibold text-rose-100 transition-colors hover:bg-rose-400/20 disabled:opacity-45",children:"Stop Run"}),e.jsx("button",{type:"button",onClick:Y,disabled:q,className:"rounded-lg border border-white/[0.12] bg-white/[0.03] px-3 py-2 text-[11px] font-semibold text-white/70 transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:"Restart"})]})]})]})]}),ae===2&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] uppercase tracking-[0.1em] text-white/35",children:"Initiative Scope"}),e.jsxs("select",{value:l,onChange:w=>v(w.target.value),className:"mt-1 w-full rounded-xl border border-white/[0.1] bg-black/30 px-3 py-2 text-[12px] text-white/80 focus:outline-none focus:ring-1 focus:ring-[#BFFF00]/30",children:[e.jsx("option",{value:"",children:"Select an initiative…"}),(r??[]).map(w=>e.jsx("option",{value:w.id,children:w.name},w.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-[10px] uppercase tracking-[0.12em] text-white/30",children:"Workstream (optional)"}),e.jsxs("select",{value:u,onChange:w=>y(w.target.value),disabled:!N,className:ge("mt-1 w-full rounded-xl border border-white/[0.1] bg-black/30 px-3 py-2 text-[12px] text-white/80 focus:outline-none focus:ring-1 focus:ring-[#BFFF00]/30",!N&&"opacity-50"),children:[e.jsx("option",{value:"",children:"Any workstream"}),z.map(w=>e.jsx("option",{value:w.id,children:w.name},w.id))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] uppercase tracking-[0.12em] text-white/30",children:"Task (optional)"}),e.jsxs("select",{value:m,onChange:w=>g(w.target.value),disabled:!N,className:ge("mt-1 w-full rounded-xl border border-white/[0.1] bg-black/30 px-3 py-2 text-[12px] text-white/80 focus:outline-none focus:ring-1 focus:ring-[#BFFF00]/30",!N&&"opacity-50"),children:[e.jsx("option",{value:"",children:"Any task"}),I.slice(0,80).map(w=>e.jsx("option",{value:w.id,children:w.title},w.id))]}),I.length>80&&e.jsx("p",{className:"mt-1 text-[10px] text-white/35",children:"Showing first 80 tasks to keep the menu usable."})]})]})]}),ae===3&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] uppercase tracking-[0.1em] text-white/35",children:"Kickoff Message"}),e.jsx("textarea",{value:p,onChange:w=>M(w.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-[12px] text-white/80 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-white/[0.06] bg-white/[0.02] p-3 text-[12px] text-white/60",children:[e.jsx("p",{className:"text-[10px] uppercase tracking-[0.12em] text-white/35",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-[10px] uppercase tracking-[0.12em] text-white/35",children:"Agent"}),e.jsx("div",{className:"mt-0.5 truncate text-[12px] text-white/80",children:(($==null?void 0:$.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-[10px] uppercase tracking-[0.12em] text-white/35",children:"Initiative"}),e.jsx("div",{className:"mt-0.5 truncate text-[12px] text-white/80",children:((N==null?void 0:N.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-[10px] uppercase tracking-[0.12em] text-white/35",children:"Workstream"}),e.jsx("div",{className:"mt-0.5 truncate text-[12px] text-white/80",children:u.trim()?((we=z.find(w=>w.id===u))==null?void 0:we.name)??u:"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-[10px] uppercase tracking-[0.12em] text-white/35",children:"Task"}),e.jsx("div",{className:"mt-0.5 truncate text-[12px] text-white/80",children:m.trim()?((je=I.find(w=>w.id===m))==null?void 0:je.title)??m:"Any"})]})]})]})]})]},ae)}),D&&e.jsx("div",{className:"mt-3 rounded-xl border border-rose-300/20 bg-rose-400/10 px-3 py-2 text-[12px] text-rose-100",children:e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("div",{children:D}),H&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>void be().catch(w=>O(w instanceof Error?w.message:"Checkout failed")),className:"rounded-full border border-amber-200/25 bg-amber-200/10 px-3 py-1.5 text-[11px] font-semibold text-amber-100 transition-colors hover:bg-amber-200/15",children:"Upgrade"}),e.jsx("button",{type:"button",onClick:()=>void Z().catch(w=>O(w instanceof Error?w.message:"Portal failed")),className:"rounded-full border border-white/[0.14] bg-white/[0.03] px-3 py-1.5 text-[11px] font-semibold text-white/70 transition-colors hover:bg-white/[0.08]",children:"Billing portal"}),H.pricing&&e.jsx("a",{href:H.pricing,target:"_blank",rel:"noopener noreferrer",className:"text-[11px] text-white/60 underline decoration-white/20 hover:text-white/80",children:"View pricing"})]})]})})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 border-t border-white/[0.06] px-5 py-3.5 sm:px-6",children:[e.jsx("div",{className:"text-[11px] text-white/45",children:ae===1?"Pick an agent to configure.":ae===2?"Select an initiative scope (required).":U?"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:[ae>1&&e.jsx("button",{type:"button",onClick:()=>k(w=>w>1?w-1:w),disabled:q,className:"rounded-xl border border-white/[0.12] bg-white/[0.03] px-4 py-2 text-[12px] font-semibold text-white/70 transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:"Back"}),ae<3?e.jsx("button",{type:"button",onClick:()=>k(w=>w<3?w+1:w),disabled:!fe||q,className:ge("rounded-xl px-4 py-2 text-[12px] font-semibold transition-colors",fe&&!q?"text-black":"cursor-not-allowed border border-white/[0.12] bg-white/[0.05] text-white/40"),style:fe&&!q?{backgroundColor:f.lime}:void 0,children:"Next"}):e.jsx("button",{type:"button",onClick:G,disabled:!U||q,className:ge("rounded-xl px-4 py-2 text-[12px] font-semibold transition-colors",U&&!q?"text-black":"cursor-not-allowed border border-white/[0.12] bg-white/[0.05] text-white/40"),style:U&&!q?{backgroundColor:f.lime}:void 0,children:q?"Launching…":"Launch"})]})]})]})}):null}const is=10,Li=20,$i={running:f.lime,queued:f.amber,pending:f.amber,blocked:f.red,failed:f.red,cancelled:f.red,completed:f.teal,archived:"rgba(255,255,255,0.5)"};function Ti(t){return $i[t]??f.iris}function Di(t){const s=(t??"").toLowerCase();return s==="active"?{label:"Active",color:f.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:f.iris,bg:"rgba(124,124,255,0.10)"}}function Oi(t){return t?t.includes("error")||t.includes("fail")?f.red:t.includes("decision")||t.includes("block")?f.amber:t.includes("complete")||t.includes("success")?f.teal:t.includes("start")||t.includes("launch")?f.lime:f.iris:f.iris}function Bi({open:t,onClose:s,agentName:i,catalogAgent:n,sessions:r,activity:o,onSelectSession:d,onRefresh:l}){var E,ae,k,N,F,z;const[v,u]=a.useState(!1),[y,m]=a.useState(!1),[g,x]=a.useState(null),j=hs(i),p=Di((n==null?void 0:n.status)??null),M=a.useMemo(()=>{let I=0,S=0,$=0,U=0;for(const fe of r)fe.status==="running"||fe.status==="queued"||fe.status==="pending"?I++:fe.status==="blocked"?S++:fe.status==="failed"||fe.status==="cancelled"?$++:(fe.status==="completed"||fe.status==="archived")&&U++;return{running:I,blocked:S,failed:$,completed:U}},[r]),D=a.useMemo(()=>[...r].sort((I,S)=>Date.parse(S.updatedAt??S.lastEventAt??S.startedAt??"")-Date.parse(I.updatedAt??I.lastEventAt??I.startedAt??"")),[r]),O=v?D:D.slice(0,is),H=D.length>is,L=a.useMemo(()=>[...o].sort((I,S)=>Date.parse(S.timestamp)-Date.parse(I.timestamp)).slice(0,Li),[o]),te=!!((E=n==null?void 0:n.run)!=null&&E.runId)&&!!((ae=n==null?void 0:n.run)!=null&&ae.pid),ee=async()=>{var I;if(!(!((I=n==null?void 0:n.run)!=null&&I.runId)||!te||y)){x(null),m(!0);try{const S=await fetch(`/orgx/api/agents/stop?runId=${encodeURIComponent(n.run.runId)}`,{method:"POST"}),$=await S.json().catch(()=>null);if(!S.ok||!($!=null&&$.ok))throw new Error(($==null?void 0:$.error)??`Stop failed (${S.status})`);l==null||l()}catch(S){x(S instanceof Error?S.message:"Stop failed")}finally{m(!1)}}},q=async()=>{var I;if(!(!((I=n==null?void 0:n.run)!=null&&I.runId)||y)){x(null),m(!0);try{const S=new URLSearchParams;S.set("runId",n.run.runId);const $=await fetch(`/orgx/api/agents/restart?${S.toString()}`,{method:"POST"}),U=await $.json().catch(()=>null);if(!$.ok||!(U!=null&&U.ok))throw new Error((U==null?void 0:U.error)??`Restart failed (${$.status})`);l==null||l()}catch(S){x(S instanceof Error?S.message:"Restart failed")}finally{m(!1)}}};return t?e.jsx(pt,{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-white/[0.06] px-5 py-3 sm:px-6",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0 text-[12px] text-white/50",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-white/25",children:e.jsx("path",{d:"m9 18 6-6-6-6"})}),e.jsx("span",{className:"truncate text-white/80 font-medium",children:i}),e.jsx("span",{className:"ml-1 rounded-full border border-white/[0.1] bg-white/[0.04] px-2 py-0.5 text-[10px] uppercase tracking-[0.06em] text-white/40",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-white/[0.12] bg-white/[0.03] text-white/70 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(Ke,{name:i,size:"md",hint:i}),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-[15px] font-semibold text-white truncate",children:i}),e.jsx("span",{className:"rounded-full border px-2 py-0.5 text-[10px] uppercase tracking-[0.12em]",style:{borderColor:`${p.color}55`,color:p.color,backgroundColor:p.bg},children:p.label})]}),j&&e.jsx("p",{className:"text-[12px] text-white/45 mt-0.5",children:j}),n&&e.jsxs("div",{className:"flex flex-wrap items-center gap-3 mt-1 text-[11px] text-white/40",children:[n.model&&e.jsxs("span",{children:[e.jsx("span",{className:"text-white/30",children:"Model:"})," ",n.model]}),n.workspace&&e.jsxs("span",{children:[e.jsx("span",{className:"text-white/30",children:"Workspace:"})," ",n.workspace]})]})]})]}),e.jsx("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-4",children:[{label:"Running",value:M.running,color:f.lime},{label:"Blocked",value:M.blocked,color:f.red},{label:"Failed",value:M.failed,color:f.amber},{label:"Completed",value:M.completed,color:f.teal}].map(I=>e.jsxs("div",{className:"rounded-xl border border-white/[0.06] bg-white/[0.02] px-3 py-2.5",children:[e.jsx("p",{className:"text-[10px] uppercase tracking-[0.1em] text-white/35",children:I.label}),e.jsx("p",{className:"mt-0.5 text-[18px] font-semibold",style:{color:I.value>0?I.color:"rgba(255,255,255,0.3)",fontVariantNumeric:"tabular-nums"},children:I.value})]},I.label))}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-[10px] uppercase tracking-[0.1em] text-white/35 mb-2",children:["Sessions (",r.length,")"]}),r.length===0?e.jsx("div",{className:"rounded-xl border border-white/[0.06] bg-white/[0.02] px-3 py-4 text-center text-[12px] text-white/35",children:"No sessions recorded for this agent."}):e.jsxs("div",{className:"space-y-1.5",children:[O.map(I=>e.jsxs("button",{onClick:()=>{d(I.id),s()},className:"w-full rounded-lg border border-white/[0.06] 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:Ti(I.status)}}),e.jsx("p",{className:"min-w-0 flex-1 truncate text-[12px] text-white/80",children:I.title}),e.jsx("span",{className:"text-[10px] text-white/35",style:{fontVariantNumeric:"tabular-nums"},children:Fe(I.updatedAt??I.lastEventAt??I.startedAt??Date.now())})]}),e.jsxs("div",{className:"mt-1 flex items-center gap-2 text-[10px] text-white/40",children:[e.jsx("span",{className:"uppercase tracking-[0.08em]",children:I.status}),I.progress!==null&&e.jsxs("span",{children:[Math.round(I.progress),"%"]})]})]},I.id)),H&&e.jsx("button",{type:"button",onClick:()=>u(I=>!I),className:"w-full rounded-lg border border-white/[0.08] bg-white/[0.02] px-3 py-1.5 text-[10px] text-white/50 transition-colors hover:bg-white/[0.05]",children:v?"Show fewer":`Show ${D.length-is} more`})]})]}),L.length>0&&e.jsxs("div",{children:[e.jsxs("p",{className:"text-[10px] uppercase tracking-[0.1em] text-white/35 mb-2",children:["Recent Activity (",L.length,")"]}),e.jsx("div",{className:"space-y-1",children:L.map((I,S)=>e.jsxs("div",{className:"flex items-start gap-2 rounded-lg px-2 py-1.5 text-[11px]",children:[e.jsx("span",{className:"mt-1.5 h-1.5 w-1.5 flex-shrink-0 rounded-full",style:{backgroundColor:Oi(I.type)}}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx("p",{className:"truncate text-white/70",children:I.title??I.summary??I.description??"Activity"})}),e.jsx("span",{className:"flex-shrink-0 text-[10px] text-white/30",style:{fontVariantNumeric:"tabular-nums"},children:Fe(I.timestamp)})]},I.id??S))})]}),(n==null?void 0:n.run)&&e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] uppercase tracking-[0.1em] text-white/35 mb-2",children:"Controls"}),e.jsxs("div",{className:"rounded-xl border border-white/[0.06] bg-white/[0.02] p-3",children:[e.jsxs("p",{className:"text-[11px] text-white/50 mb-2",children:[e.jsx("span",{className:"text-white/30",children:"Tracked run:"})," ",n.run.runId.slice(0,8),"…"," ",e.jsxs("span",{className:"text-white/35",children:["(",n.run.status,")"]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("button",{type:"button",onClick:ee,disabled:!te||y,className:"rounded-lg border border-rose-300/25 bg-rose-400/10 px-3 py-2 text-[11px] font-semibold text-rose-100 transition-colors hover:bg-rose-400/20 disabled:opacity-45",children:y?"Stopping…":"Stop Run"}),e.jsx("button",{type:"button",onClick:q,disabled:y,className:"rounded-lg border border-white/[0.12] bg-white/[0.03] px-3 py-2 text-[11px] font-semibold text-white/70 transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:y?"Restarting…":"Restart"})]}),g&&e.jsx("p",{className:"mt-2 text-[11px] text-rose-200",children:g})]})]}),n&&e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] uppercase tracking-[0.1em] text-white/35 mb-2",children:"Settings"}),e.jsxs("div",{className:"rounded-xl border border-white/[0.06] bg-white/[0.02] p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between text-[12px]",children:[e.jsx("span",{className:"text-white/40",children:"Provider"}),e.jsx("span",{className:"text-white/70",children:(k=n.model)!=null&&k.includes("openrouter")?"OpenRouter":(N=n.model)!=null&&N.includes("anthropic")?"Anthropic":(F=n.model)!=null&&F.includes("openai")?"OpenAI":"Auto"})]}),e.jsxs("div",{className:"flex items-center justify-between text-[12px]",children:[e.jsx("span",{className:"text-white/40",children:"Model"}),e.jsx("span",{className:ge("truncate max-w-[200px] text-right",n.model?"text-white/70":"text-white/30"),children:n.model??"Not configured"})]}),n.workspace&&e.jsxs("div",{className:"flex items-center justify-between text-[12px]",children:[e.jsx("span",{className:"text-white/40",children:"Workspace"}),e.jsx("span",{className:"truncate max-w-[200px] text-right text-white/70",children:n.workspace})]}),((z=n.context)==null?void 0:z.initiativeTitle)&&e.jsxs("div",{className:"flex items-center justify-between text-[12px]",children:[e.jsx("span",{className:"text-white/40",children:"Initiative"}),e.jsx("span",{className:"truncate max-w-[200px] text-right text-white/70",children:n.context.initiativeTitle})]})]})]})]})]})}):null}function Pi({enabled:t=!0}={}){return Ve({queryKey:["openclaw-agent-catalog"],queryFn:async()=>{const s=await fetch("/orgx/api/agents/catalog");if(!s.ok){const i=await s.text().catch(()=>"");throw new Error(i||`Agent catalog failed (${s.status})`)}return await s.json()},enabled:t,staleTime:5e3,refetchInterval:t?8e3:!1})}const _t=120,Ri=10,zi=new Set(["running","active","queued","pending","blocked","in_progress","working","planning"]),Ft=[{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}],qi=10,Ui=[{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"}],Wi={running:f.lime,active:f.lime,queued:f.amber,pending:f.amber,in_progress:f.amber,working:f.amber,planning:f.amber,blocked:f.red,failed:f.red,cancelled:f.red,paused:"rgba(255,255,255,0.5)",draft:"rgba(255,255,255,0.5)",completed:f.teal,archived:"rgba(255,255,255,0.5)"};function yt(t){return Wi[t]??f.iris}function Ae(t){const s=t==null?void 0:t.trim().toLowerCase();return s&&s.length>0?s:null}function Ki(t){const s=Ae(t.agentId);if(s)return`id:${s}`;const i=Ae(t.agentName);return i?`name:${i}`:"unassigned"}function jt(t){const s=Ae(t);return s?zi.has(s):!1}function Lt(t){return t?!!(jt(t.status)||t.runId&&t.runId.trim().length>0||t.currentTask&&t.currentTask.trim().length>0):!1}function Vi(t){return t?t.state==="active":!1}function an(t){return t==="openai"?"openai":t==="anthropic"?"anthropic":t==="openclaw"?"openclaw":t==="orgx"?"orgx":"unknown"}function Hi(t){return an((t==null?void 0:t.providerLogo)??null)}function Re(t){if(!t)return 0;const s=Date.parse(t);return Number.isFinite(s)?s:0}function rs(t,s){return Re(s.updatedAt??s.lastEventAt??s.startedAt)-Re(t.updatedAt??t.lastEventAt??t.startedAt)}const Gi=a.memo(function({sessions:s,activity:i,selectedSessionId:n,onSelectSession:r,onAgentFilter:o,agentFilter:d,onReconnect:l,connectionStatus:v,runtimeInstances:u=[]}){var T;const[y,m]=a.useState(new Set),[g,x]=a.useState(!1),[j,p]=a.useState("all"),[M,D]=a.useState(!1),[O,H]=a.useState(0),[L,te]=a.useState(null),ee=Pi({enabled:!0}),q=((T=ee.data)==null?void 0:T.agents)??[];a.useMemo(()=>{var re,K,Se;const C=new Map,Y=[...i].sort((he,we)=>Re(we.timestamp)-Re(he.timestamp));for(const he of Y){const we=he.runId;if(!we||C.has(we))continue;const je=((re=he.summary)==null?void 0:re.trim())??((K=he.description)==null?void 0:K.trim())??((Se=he.title)==null?void 0:Se.trim())??"";je.length>0&&C.set(we,je)}return C},[i]);const{agents:E,hiddenGroupCount:ae,filteredOutGroupsByDate:k,filteredOutSessionsByDate:N,visibleSessionCount:F,archivedGroups:z}=a.useMemo(()=>{var ke;const C=new Map,Y=new Map,re=[...u].sort((A,W)=>Re(W.lastEventAt??W.lastHeartbeatAt)-Re(A.lastEventAt??A.lastHeartbeatAt));for(const A of re){A.runId&&!C.has(A.runId)&&C.set(A.runId,A);const W=Ae(A.agentId);if(W){const oe=Y.get(W)??[];oe.push(A),Y.set(W,oe)}}const K=new Map;for(const A of s.nodes){const W=Ki(A),oe=Ae(A.agentId),ue=Ae(A.agentName);let se=K.get(W)??null;if(!se&&oe&&ue){const le=`name:${ue}`,xe=K.get(le);xe&&(K.delete(le),xe.groupKey=W,K.set(W,xe),se=xe)}if(!se&&ue){const le=Array.from(K.values()).find(xe=>Ae(xe.agentName)===ue);le&&(se=le)}se?(se.nodes.push(A),!se.agentId&&A.agentId&&(se.agentId=A.agentId),(se.agentName==="Unassigned"||!se.agentName)&&A.agentName&&(se.agentName=A.agentName)):K.set(W,{groupKey:W,agentId:A.agentId,agentName:A.agentName??A.agentId??"Unassigned",nodes:[A],latest:A,runtime:null,runtimeActiveCount:0})}for(const A of q){const W=Ae(A.id),oe=Ae(A.name),ue=W?`id:${W}`:null,se=oe?`name:${oe}`:null;let le=null;if(ue&&K.has(ue))le=ue;else if(se&&K.has(se))le=se;else{const xe=Array.from(K.entries()).find(([,Le])=>W&&Ae(Le.agentId)===W||oe&&Ae(Le.agentName)===oe);le=(xe==null?void 0:xe[0])??null}if(le){const xe=K.get(le);xe.catalogAgent=A,!xe.agentId&&A.id&&(xe.agentId=A.id),(xe.agentName==="Unassigned"||!xe.agentName)&&A.name&&(xe.agentName=A.name),ue&&xe.groupKey!==ue&&!K.has(ue)&&(K.delete(xe.groupKey),xe.groupKey=ue,K.set(ue,xe))}else{const xe=ue??se??`catalog:${A.name.toLowerCase()}`;K.set(xe,{groupKey:xe,agentId:A.id,agentName:A.name,nodes:[],latest:null,catalogAgent:A,runtime:null,runtimeActiveCount:0})}}for(const A of K.values()){A.nodes.length>0&&(A.nodes.sort(rs),A.latest=A.nodes[0]);const W=[],oe=new Set;if((ke=A.latest)!=null&&ke.runId){const se=C.get(A.latest.runId);se&&!oe.has(se.id)&&(W.push(se),oe.add(se.id))}for(const se of A.nodes){if(!se.runId)continue;const le=C.get(se.runId);le&&!oe.has(le.id)&&(W.push(le),oe.add(le.id))}const ue=Ae(A.agentId);if(ue)for(const se of Y.get(ue)??[])oe.has(se.id)||(W.push(se),oe.add(se.id));W.sort((se,le)=>Re(le.lastEventAt??le.lastHeartbeatAt)-Re(se.lastEventAt??se.lastHeartbeatAt)),A.runtime=W[0]??null,A.runtimeActiveCount=W.filter(se=>Vi(se)).length}const Se=Array.from(K.values()).sort((A,W)=>A.latest&&W.latest?rs(A.latest,W.latest):A.latest&&!W.latest?-1:!A.latest&&W.latest?1:A.agentName.localeCompare(W.agentName)),he=Ft.find(A=>A.id===j)??Ft[0],we=he.id==="live",je=he.minutes===null||we?null:Date.now()-he.minutes*6e4,w=[],R=[];let ce=0,X=0;for(const A of Se){const W=(A.runtimeActiveCount??0)>0;if(A.nodes.length===0){const le=Lt(A.catalogAgent);(!we||le||W)&&w.push(A);continue}if(we){const le=A.nodes.filter(V=>jt(V.status)),xe=A.nodes.filter(V=>!jt(V.status)),Le=Lt(A.catalogAgent);if(le.length===0){Le||W?w.push({...A,nodes:[],latest:null}):(ce+=1,X+=A.nodes.length,R.push(A));continue}X+=xe.length,xe.length>0&&R.push({...A,nodes:xe,latest:xe[0]??null}),w.push({...A,nodes:le,latest:le[0]??null});continue}if(je===null){w.push(A);continue}const oe=A.nodes.filter(le=>jt(le.status)?!0:Re(le.updatedAt??le.lastEventAt??le.startedAt)>=je),ue=Lt(A.catalogAgent);if(oe.length===0){ue||W?w.push({...A,nodes:[],latest:null}):(ce+=1,X+=A.nodes.length,R.push(A));continue}const se=A.nodes.filter(le=>jt(le.status)?!1:Re(le.updatedAt??le.lastEventAt??le.startedAt)<je);X+=se.length,se.length>0&&R.push({...A,nodes:se,latest:se[0]}),w.push({...A,nodes:oe,latest:oe[0]})}return{agents:w.slice(0,_t),hiddenGroupCount:Math.max(0,w.length-_t),filteredOutGroupsByDate:ce,filteredOutSessionsByDate:X,visibleSessionCount:w.slice(0,_t).reduce((A,W)=>A+W.nodes.length,0),archivedGroups:R}},[j,s.nodes,q,u]);a.useEffect(()=>{D(!1),H(0)},[j]);const I=a.useMemo(()=>z.reduce((C,Y)=>C+Y.nodes.length,0),[z]),S=a.useMemo(()=>{const C=[];for(const Y of z)for(const re of Y.nodes)C.push({node:re,agentName:Y.agentName});return C.sort((Y,re)=>rs(Y.node,re.node)),C.slice(0,(O+1)*qi)},[z,O]),$=C=>{m(Y=>{const re=new Set(Y);return re.has(C)?re.delete(C):re.add(C),re})},U=a.useMemo(()=>L?E.find(C=>C.groupKey===L)??null:null,[E,L]),fe=a.useMemo(()=>(U==null?void 0:U.nodes)??[],[U]),be=a.useMemo(()=>{if(!U)return[];const C=Ae(U.agentName),Y=Ae(U.agentId);return i.filter(re=>{const K=Ae(re.agentName),Se=Ae(re.agentId);return C!==null&&K===C||Y!==null&&Se===Y})},[i,U]),Z=s.nodes.length===0,G=q.length>0;return e.jsxs(at,{className:"flex h-full min-h-0 flex-col card-enter",children:[e.jsx(Fi,{open:g,onClose:()=>x(!1),onLaunched:()=>l==null?void 0:l()}),e.jsx(Bi,{open:L!==null,onClose:()=>te(null),agentName:(U==null?void 0:U.agentName)??"",catalogAgent:(U==null?void 0:U.catalogAgent)??null,sessions:fe,activity:be,onSelectSession:r,onRefresh:()=>ee.refetch()}),e.jsxs("div",{className:"border-b border-white/[0.06] px-4 py-3.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"text-[14px] font-semibold text-white",children:"Agents / Chats"}),e.jsxs("span",{className:"chip text-[11px]",children:[F,"/",s.nodes.length]})]}),e.jsx("button",{type:"button",onClick:()=>x(!0),className:"rounded-lg border border-white/[0.12] bg-white/[0.03] px-3 py-1.5 text-[12px] font-medium text-white/65 transition-colors hover:bg-white/[0.08] hover:text-white",children:"Launch"})]}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"text-[11px] text-white/45",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:Ft.map(C=>{const Y=j===C.id;return e.jsx("button",{type:"button",onClick:()=>p(C.id),"aria-pressed":Y,className:ge("rounded-full px-2.5 py-1 text-[10px] font-semibold tracking-[-0.01em] transition-colors",Y?"border border-lime/25 bg-lime/[0.12] text-lime":"border border-transparent text-white/55 hover:bg-white/[0.06] hover:text-white/80"),children:C.label},C.id)})}),e.jsx("label",{htmlFor:"offline-date-filter",className:"sr-only",children:"Session history filter"}),e.jsx("select",{id:"offline-date-filter",value:j,onChange:C=>p(C.target.value),className:"rounded-lg border border-white/[0.1] bg-black/30 px-2 py-1 text-[11px] text-white/75 focus:outline-none focus:ring-1 focus:ring-[#BFFF00]/30 sm:hidden",children:Ft.map(C=>e.jsx("option",{value:C.id,children:C.label},C.id))})]})]}),e.jsxs("div",{className:"flex-1 space-y-2 overflow-y-auto p-3",children:[E.length===0&&!Z&&e.jsxs("div",{className:"flex flex-col items-center gap-2.5 rounded-xl border border-white/[0.06] 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-white/25",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-[12px] text-white/45",children:"No sessions match the selected history filter."})]}),E.length===0&&Z&&!l&&e.jsxs("div",{className:"flex flex-col items-center gap-2.5 rounded-xl border border-white/[0.06] 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-white/25",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-[12px] text-white/45",children:"No active chats yet. Start a session to see agents here."})]}),d&&o&&e.jsxs("div",{className:"flex items-center justify-between rounded-lg bg-[#0AD4C4]/[0.08] px-3 py-1.5 text-[11px] text-[#0AD4C4]",children:[e.jsxs("span",{children:["Filtered: ",d]}),e.jsx("button",{type:"button",onClick:()=>o(null),className:"text-[10px] underline underline-offset-2",children:"Clear"})]}),E.map(C=>{var A;const Y=C.groupKey,re=y.has(Y),K=C.latest,Se=C.nodes.length>0,he=Lt(C.catalogAgent),we=C.runtime??null,je=(C.runtimeActiveCount??0)>0,w=K?n===K.id:!1,R=C.agentName||((A=C.catalogAgent)==null?void 0:A.name)||C.agentId||"Unassigned",ce=re?[]:C.nodes.slice(0,Ri),X=Math.max(0,C.nodes.length-ce.length),ke=Ae(d)===Ae(R);return e.jsxs(de.div,{layout:!0,transition:{type:"spring",stiffness:260,damping:30,mass:.75},className:ge("overflow-hidden rounded-xl border border-white/[0.06] bg-white/[0.02] transition-all",w&&"border-white/20 bg-white/[0.05]",ke&&"border-[#0AD4C4]/30",!Se&&!he&&!je&&"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:()=>{o?o(ke?null:R):K&&r(K.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(Ke,{name:R,size:"sm",hint:R}),K&&e.jsx("span",{className:"absolute -bottom-0.5 -right-0.5 h-2.5 w-2.5 rounded-full border-2",style:{backgroundColor:yt(K.status),borderColor:f.cardBg}}),!K&&e.jsx("span",{className:"absolute -bottom-0.5 -right-0.5 h-2.5 w-2.5 rounded-full border-2",style:{backgroundColor:he?yt("running"):"rgba(255,255,255,0.2)",borderColor:f.cardBg}})]}),e.jsxs("span",{className:"min-w-0 truncate",children:[e.jsx("span",{className:"text-[13px] font-semibold text-white",children:R}),hs(R)&&e.jsxs("span",{className:"ml-1 text-[11px] text-white/40",children:["— ",hs(R)]})]}),we&&e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.14] bg-white/[0.04] px-1.5 py-0.5 text-[9px] uppercase tracking-[0.08em] text-white/70",title:we.currentTask?`${we.displayName}: ${we.currentTask}`:we.lastMessage??we.displayName,children:[e.jsx(ns,{provider:Hi(we),size:"xs",showRing:!1,className:"h-4 w-4"}),e.jsx("span",{children:we.displayName}),we.progressPct!==null&&e.jsxs("span",{style:{fontVariantNumeric:"tabular-nums"},children:[Math.round(we.progressPct),"%"]}),je&&e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-lime status-breathe"})]}),Se?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 W={};for(const ue of C.nodes)W[ue.status]=(W[ue.status]??0)+1;const oe=C.nodes.length;return Object.entries(W).map(([ue,se])=>e.jsx("span",{style:{width:`${se/oe*100}%`,backgroundColor:yt(ue)}},ue))})()}),e.jsx("span",{className:"text-[10px] text-white/55",style:{fontVariantNumeric:"tabular-nums"},children:C.nodes.length})]}):he||je?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:yt("running")}})}),e.jsx("span",{className:"text-[10px] 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-[10px] text-white/35",style:{fontVariantNumeric:"tabular-nums"},children:"0"})]})]}),e.jsx("button",{type:"button",onClick:()=>te(Y),"aria-label":`View ${R} details`,className:"flex h-7 w-7 items-center justify-center rounded-md text-white/40 transition-colors hover:bg-white/[0.05] hover:text-white/70",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"})]})}),Se&&e.jsx("button",{type:"button",onClick:()=>$(Y),"aria-label":re?"Expand sessions":"Collapse sessions",className:"flex h-7 w-7 items-center justify-center rounded-md text-white/40 transition-colors hover:bg-white/[0.05] hover:text-white/70",children:e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:ge("transition-transform",re?"-rotate-90":"rotate-0"),children:e.jsx("path",{d:"m6 9 6 6 6-6"})})})]}),e.jsx(Te,{initial:!1,children:Se&&!re&&e.jsx(de.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-white/[0.06]",children:e.jsxs("div",{className:"max-h-[500px] space-y-1.5 overflow-y-auto p-2",children:[ce.map((W,oe)=>{const ue=n===W.id,se=Ds(W.agentName,W.title,W.lastEventSummary,W);return e.jsx(de.button,{onClick:()=>r(W.id),initial:{opacity:0,y:4},animate:{opacity:1,y:0},transition:{duration:.16,delay:Math.min(oe*.015,.12)},className:ge("w-full rounded-lg px-2.5 py-2 text-left transition-colors",ue?"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(ns,{provider:se.id,size:"xs"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-[12px] text-white/90",children:W.title}),e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-white/45",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:W.status}),e.jsx("span",{children:Fe(W.updatedAt??W.lastEventAt??W.startedAt??Date.now())})]}),W.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(W.progress)}%`,background:`linear-gradient(90deg, ${f.lime}, ${f.teal})`}})})]}),e.jsx("span",{className:"h-2 w-2 flex-shrink-0 rounded-full",style:{backgroundColor:yt(W.status)},"aria-label":W.status,title:W.status})]})},W.id)}),X>0&&e.jsxs("p",{className:"px-1 text-[10px] text-white/40",children:["+",X," older sessions hidden"]})]})})})]},Y)}),ae>0&&e.jsxs("div",{className:"rounded-xl border border-white/[0.06] bg-white/[0.02] px-3 py-2 text-[11px] text-white/45",children:["Showing ",_t," most recent agent groups (",ae," older groups omitted)."]}),l&&v!=="connected"&&!G&&e.jsxs("div",{className:"rounded-xl border border-white/[0.06] bg-white/[0.02] text-[11px] text-white/45",children:[e.jsx("p",{className:"px-3 pt-2 pb-1.5 text-[10px] uppercase tracking-[0.1em] text-white/30",children:"OrgX Agent Roster"}),e.jsx("div",{className:"space-y-1 px-2 pb-2",children:Ui.map(C=>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-[9px] font-semibold text-white/50",children:C.name.charAt(0)})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-[11px] font-medium text-white/60",children:C.name}),e.jsx("p",{className:"text-[9px] text-white/35",children:C.role})]}),e.jsx("button",{onClick:l,className:"rounded-md border border-lime/25 bg-lime/10 px-2 py-0.5 text-[9px] font-semibold text-lime transition-colors hover:bg-lime/20",children:"Connect"})]},C.id))})]}),N>0&&e.jsxs("div",{className:"rounded-xl border border-white/[0.06] bg-white/[0.02] text-[11px] text-white/45",children:[e.jsxs("button",{onClick:()=>{D(C=>!C),M&&H(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:ge("transition-transform",M?"rotate-0":"-rotate-90"),children:e.jsx("path",{d:"m6 9 6 6 6-6"})}),e.jsxs("span",{children:[I," archived session",I===1?"":"s",k>0?` across ${k} agent${k===1?"":"s"}`:""]})]}),e.jsx(Te,{initial:!1,children:M&&e.jsx(de.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-white/[0.06] p-2",children:[S.map(({node:C,agentName:Y})=>{const re=C.runtimeProvider?{id:an(C.runtimeProvider)}:Ds(C.agentName,C.title,C.lastEventSummary,C);return e.jsxs("button",{onClick:()=>r(C.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(ns,{provider:re.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-[11px] font-medium text-white/70",children:Y}),e.jsx("span",{className:"text-[10px] text-white/35",children:Fe(C.updatedAt??C.lastEventAt??C.startedAt??Date.now())})]}),e.jsx("p",{className:"truncate text-[10px] text-white/50",children:C.title}),e.jsx("span",{className:"text-[9px] uppercase tracking-[0.08em] text-white/35",children:C.status})]})]},C.id)}),S.length<I&&e.jsxs("button",{onClick:()=>H(C=>C+1),className:"w-full rounded-lg border border-white/[0.08] bg-white/[0.02] px-3 py-1.5 text-[10px] text-white/50 transition-colors hover:bg-white/[0.05]",children:["Load more (",I-S.length," remaining)"]})]})})})]})]})]})}),Xi=[[/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 ms(t){if(!t)return"";for(const[i,n]of Xi)if(i.test(t))return n;const s=t.split("/");return s[s.length-1]??t}function Qi(t,s=4){let i=t.replace(/^\/Users\/[^/]+\//,"~/").replace(/^~\/Code\//,"").replace(/^~\//,"");const n=i.split("/");return n.length>s&&(i=n.slice(-s).join("/")),i}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,i=>`#${i.slice(0,4)}`),s=s.replace(/(?:anthropic|openrouter|openai)\/[a-z0-9._/-]+/gi,i=>ms(i)),s=s.replace(/\/Users\/[a-zA-Z0-9_-]+\/[^\s"']+/g,i=>Qi(i)),s}const as=/\[([^\]]+)\]\(([^)\s]+)\)|`([^`]+)`|\*\*([^*]+)\*\*|__([^_]+)__|\*([^*\n]+)\*|_([^_\n]+)_/g;function Ji(t){try{const s=new URL(t);return s.protocol==="http:"||s.protocol==="https:"}catch{return!1}}function nt(t,s){const i=[];let n=0,r=0;as.lastIndex=0;for(let o=as.exec(t);o;o=as.exec(t)){const[d]=o,l=o.index;l>n&&i.push(t.slice(n,l));const v=`${s}-${r++}`,u=o[1],y=o[2],m=o[3],g=o[4],x=o[5],j=o[6],p=o[7];u&&y&&Ji(y)?i.push(e.jsx("a",{href:y,target:"_blank",rel:"noopener noreferrer",className:"text-[#D8FFA1] underline decoration-white/35 underline-offset-2 transition hover:text-[#ECFFC6]",children:u},v)):m?i.push(e.jsx("code",{className:"rounded bg-white/[0.08] px-1 py-0.5 font-mono text-[0.93em] text-white/95",children:m},v)):g||x?i.push(e.jsx("strong",{className:"font-semibold text-white",children:g??x},v)):j||p?i.push(e.jsx("em",{className:"italic text-white/90",children:j??p},v)):i.push(d),n=l+d.length}return n<t.length&&i.push(t.slice(n)),i}function Yi(t,s){const i=t.split(`
204
+ `),n=[];return i.forEach((r,o)=>{n.push(...nt(r,`${s}-line-${o}`)),o<i.length-1&&n.push(e.jsx("br",{},`${s}-br-${o}`))}),n}function Rt(t){return t.trim().replace(/^\|/,"").replace(/\|$/,"").split("|").map(i=>i.trim())}function Zi(t){const s=Rt(t);return s.length===0?!1:s.every(i=>/^:?-{3,}:?$/.test(i))}function er(t){const s=t.trim(),i=s.startsWith(":"),n=s.endsWith(":");return i&&n?"center":n?"right":"left"}function tr(t){const s=t.replace(/\r\n/g,`
205
+ `).split(`
206
+ `),i=[];let n=0;for(;n<s.length;){const r=s[n]??"",o=r.trim();if(!o){n+=1;continue}const d=r.includes("|"),l=s[n+1]??"";if(d&&l.includes("|")&&Zi(l)){const g=Rt(r),j=Rt(l).map(M=>er(M));n+=2;const p=[];for(;n<s.length;){const M=s[n]??"";if(!M.trim()||!M.includes("|"))break;p.push(Rt(M)),n+=1}i.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:g.map((M,D)=>e.jsx("th",{className:"px-3 py-2 text-[11px] font-semibold uppercase tracking-[0.08em] text-white/70",style:{textAlign:j[D]??"left"},children:nt(M,`tbl-h-${n}-${D}`)},`tbl-h-${D}`))})}),e.jsx("tbody",{children:p.map((M,D)=>e.jsx("tr",{className:D<p.length-1?"border-b border-white/[0.06]":void 0,children:g.map((O,H)=>e.jsx("td",{className:"px-3 py-2 text-[13px] leading-relaxed text-white/80 align-top",style:{textAlign:j[H]??"left"},children:nt(M[H]??"",`tbl-r-${n}-${D}-${H}`)},`tbl-r-${D}-c-${H}`))},`tbl-r-${D}`))})]})},`tbl-${n}`));continue}if(o.startsWith("```")){const g=o.slice(3).trim(),x=[];for(n+=1;n<s.length&&!(s[n]??"").trim().startsWith("```");)x.push(s[n]??""),n+=1;n<s.length&&(n+=1),i.push(e.jsxs("div",{className:"rounded-xl border border-white/[0.1] bg-black/40 p-3",children:[g&&e.jsx("p",{className:"mb-1 text-[10px] uppercase tracking-[0.12em] text-white/35",children:g}),e.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap font-mono text-[11px] leading-relaxed text-white/78",children:e.jsx("code",{children:x.join(`
207
+ `)})})]},`code-${n}`));continue}const v=o.match(/^(#{1,3})\s+(.+)$/);if(v){const g=v[1].length,x=v[2],j=g===1?"text-[16px] font-semibold":g===2?"text-[14px] font-semibold":"text-[13px] font-medium";i.push(e.jsx("p",{className:ge("tracking-[-0.01em] text-white",j),children:nt(x,`h-${n}`)},`h-${n}`)),n+=1;continue}if(r.match(/^\s*[-*]\s+(.+)$/)){const g=[];for(;n<s.length;){const j=(s[n]??"").match(/^\s*[-*]\s+(.+)$/);if(!j)break;g.push(j[1]),n+=1}i.push(e.jsx("ul",{className:"space-y-1.5 pl-4",children:g.map((x,j)=>e.jsx("li",{className:"list-disc text-[13px] leading-relaxed text-white/78",children:nt(x,`ul-${n}-${j}`)},`ul-${n}-${j}`))},`ul-${n}`));continue}if(r.match(/^\s*\d+\.\s+(.+)$/)){const g=[];for(;n<s.length;){const j=(s[n]??"").match(/^\s*\d+\.\s+(.+)$/);if(!j)break;g.push(j[1]),n+=1}i.push(e.jsx("ol",{className:"space-y-1.5 pl-4",children:g.map((x,j)=>e.jsx("li",{className:"list-decimal text-[13px] leading-relaxed text-white/78",children:nt(x,`ol-${n}-${j}`)},`ol-${n}-${j}`))},`ol-${n}`));continue}const m=[];for(;n<s.length;){const g=s[n]??"",x=g.trim();if(!x||/^(#{1,3})\s+/.test(x)||/^\s*[-*]\s+/.test(g)||/^\s*\d+\.\s+/.test(g)||x.startsWith("```"))break;m.push(g),n+=1}i.push(e.jsx("p",{className:"text-[13px] leading-relaxed text-white/78",children:Yi(m.join(`
208
+ `),`p-${n}`)},`p-${n}`))}return i}function zt({text:t,mode:s="inline",className:i}){const n=t.replace(/\r\n/g,`
209
+ `);return n.trim()?s==="inline"?e.jsx("span",{className:i,children:nt(n,"inline")}):e.jsx("div",{className:ge("space-y-2",i),children:tr(n)}):null}const on={run_started:{icon:"play",label:"Run started",color:f.teal},run_completed:{icon:"check_circle",label:"Run completed",color:f.lime},run_failed:{icon:"alert_triangle",label:"Run failed",color:f.red},artifact_created:{icon:"file",label:"Artifact",color:f.cyan},decision_requested:{icon:"shield",label:"Decision requested",color:f.amber},decision_resolved:{icon:"shield_check",label:"Decision resolved",color:f.lime},handoff_requested:{icon:"handoff",label:"Handoff requested",color:f.iris},handoff_claimed:{icon:"handoff_claimed",label:"Handoff claimed",color:f.teal},handoff_fulfilled:{icon:"sparkles",label:"Handoff fulfilled",color:f.lime},blocker_created:{icon:"octagon_x",label:"Blocker",color:f.red},milestone_completed:{icon:"flag",label:"Milestone",color:f.cyan},delegation:{icon:"workflow",label:"Delegation",color:f.iris}};function kt(t,s){if(!t)return null;for(const i of s){const n=t[i];if(typeof n=="string"&&n.trim().length>0)return n.trim()}return null}function xs(t){return t?t.toLowerCase():""}function sr(t,s){return[t.type,t.kind,t.phase,t.state,t.title,t.summary,t.description,kt(s,["source","event","eventType","artifact_type","action","kind"]),kt(s,["task","taskName","workstream","milestone","status"])].filter(i=>typeof i=="string"&&i.trim().length>0).join(" ").toLowerCase()}function nr(t,s){const i=xs(kt(t,["artifact_type","artifactType"]));return i.includes("pr")||/pull request|merge request/.test(s)?{icon:"file_code",label:"Pull request",color:f.cyan}:i.includes("commit")||/commit|diff|patch/.test(s)?{icon:"git_commit",label:"Commit",color:f.cyan}:i.includes("config")?{icon:"checkpoint",label:"Config",color:f.cyan}:i.includes("design")?{icon:"compass",label:"Design output",color:f.cyan}:i.includes("report")||i.includes("document")||/memo|doc/.test(s)?{icon:"file",label:"Document",color:f.cyan}:on.artifact_created}function ir(t){const s=t.metadata,i=sr(t,s),n=xs(kt(s,["source"])),r=xs(kt(s,["action"]));if(/heartbeat|heart beat|alive signal/.test(i))return{icon:"heartbeat",label:"Heartbeat",color:f.teal};if(/soul/.test(i))return{icon:"compass",label:"Soul state",color:f.iris};if(/memory sync|sync memory|workspace state|sync completed|memory file/.test(i))return{icon:"memory_sync",label:"Memory sync",color:f.teal};if(/checkpoint|rollback|restore point/.test(i))return{icon:"checkpoint",label:"Checkpoint",color:f.amber};if(/quality gate|quality score|quality check/.test(i))return{icon:"quality_gate",label:"Quality gate",color:f.lime};if(/model routing|routed model|model tier/.test(i))return{icon:"route",label:"Model routing",color:f.iris};if(n==="local_openclaw")return{icon:"terminal",label:"Local OpenClaw",color:f.teal};if(t.type==="artifact_created")return nr(s,i);if(t.type==="decision_resolved")return r==="reject"||/rejected|declined/.test(i)?{icon:"shield_x",label:"Decision rejected",color:f.red}:{icon:"shield_check",label:"Decision approved",color:f.lime};if(t.type==="delegation"){if(/dispatch|spawn|launched|kickoff|started/.test(i))return{icon:"workflow",label:"Dispatch",color:f.iris};if(/message|chat|reply|summary/.test(i))return{icon:"message",label:"Message",color:f.teal}}return on[t.type]??{icon:"message",label:"Activity",color:f.textMuted}}function rr({icon:t,size:s=14,className:i}){const n={width:s,height:s,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.8,strokeLinecap:"round",strokeLinejoin:"round",className:i};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(Zs,{size:s,className:i,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 ar(t){try{return new Date(t).toLocaleTimeString([],{hour:"numeric",minute:"2-digit"})}catch{return""}}function or(t){var i;let s=0;for(const n of t){const r=(i=n.metadata)==null?void 0:i.costTotal;typeof r=="number"&&(s+=r)}return s<=0?null:s<.01?`$${s.toFixed(4)}`:`$${s.toFixed(2)}`}const lr=a.memo(function({items:s,session:i,agentName:n,onBack:r}){const o=a.useMemo(()=>[...s].sort((u,y)=>Date.parse(u.timestamp)-Date.parse(y.timestamp)),[s]),d=a.useMemo(()=>or(o),[o]),l=a.useMemo(()=>{if(o.length<2)return null;const u=Date.parse(o[0].timestamp),m=Date.parse(o[o.length-1].timestamp)-u;return m<6e4?`${Math.round(m/1e3)}s`:m<36e5?`${Math.round(m/6e4)}m`:`${(m/36e5).toFixed(1)}h`},[o]),v=(i==null?void 0:i.title)??n??"Session";return e.jsxs("div",{className:"flex h-full flex-col",children:[e.jsxs("div",{className:"border-b border-white/[0.06] px-4 py-3",children:[e.jsxs("button",{onClick:r,className:"mb-2 flex items-center gap-1.5 text-[11px] text-white/50 transition-colors hover:text-white/80",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:f.lime,boxShadow:`0 0 12px ${f.lime}55`}}),e.jsx("h3",{className:"text-[14px] font-semibold text-white",children:$e(v)})]}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2 text-[10px] text-white/45",children:[n&&e.jsxs("span",{className:"inline-flex items-center gap-1.5 rounded-full border border-white/[0.1] px-1 py-0.5",children:[e.jsx(Ke,{name:n,hint:(i==null?void 0:i.id)??(i==null?void 0:i.runId)??null,size:"xs"}),e.jsx("span",{children:n})]}),e.jsxs("span",{children:[o.length," turn",o.length!==1?"s":""]}),l&&e.jsx("span",{children:l}),d&&e.jsx("span",{className:"text-white/35",children:d}),(i==null?void 0:i.status)&&e.jsx("span",{className:"rounded-full px-1.5 py-0.5 text-[9px] uppercase tracking-wider",style:{backgroundColor:i.status==="running"?`${f.lime}20`:i.status==="failed"?`${f.red}20`:`${f.teal}20`,color:i.status==="running"?f.lime:i.status==="failed"?f.red:f.teal},children:i.status})]})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-4 py-3",children:[e.jsx(Te,{mode:"popLayout",children:e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute left-[7px] top-3 bottom-3 w-px",style:{backgroundColor:`${f.iris}25`}}),e.jsx("div",{className:"space-y-1",children:o.map((u,y)=>{const m=ir(u),g=m.color,x=ms(u.description),j=$e(u.title??""),p=u.type==="run_failed",M=u.type==="artifact_created",D=u.type==="decision_requested"||u.type==="decision_resolved";return e.jsxs(de.div,{initial:{opacity:0,x:-8},animate:{opacity:1,x:0},transition:{duration:.2,delay:y*.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:`${g}20`,color:g,border:`1px solid ${g}40`},children:e.jsx(rr,{icon:m.icon,size:8,className:"opacity-95"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:`text-[12px] leading-snug ${p?"text-red-400":D?"text-amber-300":M?"text-cyan-300":"text-white/85"}`,children:j}),u.summary&&u.summary!==j&&e.jsx("p",{className:"mt-0.5 text-[11px] leading-relaxed text-white/40",children:$e(u.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-[10px] text-white/35",children:ar(u.timestamp)}),x&&e.jsx("span",{className:"text-[9px] text-white/25",children:x})]})]},u.id)})})]})}),o.length===0&&e.jsx("div",{className:"flex flex-col items-center gap-2 py-8 text-center",children:e.jsx("p",{className:"text-[12px] text-white/40",children:"No activity in this session yet."})}),o.length>0&&e.jsxs("div",{className:"mt-4 rounded-lg border border-white/[0.06] bg-white/[0.02] px-3 py-2 text-[10px] text-white/35",children:[o.length," turn",o.length!==1?"s":"",l?` over ${l}`:"",d?` · ${d}`:""," · ",Fe(o[o.length-1].timestamp)]})]})]})}),cr={initial:{opacity:0,y:8,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-4,scale:.98}},dr=480,$t={all:"All",messages:"Messages",artifacts:"Artifacts",decisions:"Decisions"};function ur(t){if(!t)return 0;const s=Date.parse(t);return Number.isFinite(s)?s:0}function ln(t){if(!t)return"";const s=[];for(const[i,n]of Object.entries(t))typeof n=="string"&&(i.toLowerCase().includes("type")||i.toLowerCase().includes("kind")||i.toLowerCase().includes("summary")||i.toLowerCase().includes("message")||i.toLowerCase().includes("artifact")||i.toLowerCase().includes("decision")||i.toLowerCase().includes("run")||i.toLowerCase().includes("title")||i.toLowerCase().includes("task")||i.toLowerCase().includes("workstream")||i.toLowerCase().includes("milestone"))&&s.push(n);return s.join(" ")}function pr(t){if(t.runId)return t.runId;const s=t.metadata;if(!s)return null;const i=["runId","run_id","sessionId","session_id","agentRunId"];for(const n of i){const r=s[n];if(typeof r=="string"&&r.trim().length>0)return r.trim()}return null}function Os(t){const s=t.metadata;if(!s)return null;const i=["workstreamId","workstream_id"];for(const r of i){const o=s[r];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 r=n,o=r.workstreamId??r.workstream_id;if(typeof o=="string"&&o.trim().length>0)return o.trim()}return null}function hr(t){return t?["artifact","artifacts","artifact_type","artifactType","output","outputs","result","results","payload","toolOutput","toolOutputs","toolResult","toolResults"].some(i=>i in t):!1}function xr(t){const s=t.metadata,i=ln(t.metadata),n=[t.type,t.kind,t.summary,t.title,t.description,i].filter(d=>typeof d=="string"&&d.trim().length>0).join(" ").toLowerCase();return t.type==="artifact_created"||hr(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 st(t){return t.split("_").join(" ")}function mr(t){const s=new Date(t);if(Number.isNaN(s.getTime()))return"unknown";const i=new Date(s.getFullYear(),s.getMonth(),s.getDate());return String(i.getTime())}function fr(t){const s=Number(t);if(!Number.isFinite(s))return"Unknown day";const i=new Date(s),n=new Date,r=new Date(n.getFullYear(),n.getMonth(),n.getDate()),o=new Date(r);return o.setDate(r.getDate()-1),i.getTime()===r.getTime()?"Today":i.getTime()===o.getTime()?"Yesterday":i.toLocaleDateString(void 0,{month:"short",day:"numeric",year:i.getFullYear()===n.getFullYear()?void 0:"numeric"})}function os(t){return t==="artifact"?"artifact":t==="decision"?"decision":"message"}function vt(t){return t==="artifact"?f.cyan:t==="decision"?f.amber:f.teal}function gr(t){return t.type==="milestone_completed"?"milestone":t.type==="decision_requested"||t.type==="decision_resolved"?"decision":t.type==="handoff_requested"||t.type==="handoff_claimed"||t.type==="handoff_fulfilled"||t.type==="delegation"?"workstream":t.type==="artifact_created"?"task":t.initiativeId?"initiative":"notification"}function br(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 wr(t){return t==="critical"?f.red:t==="warning"?f.amber:t==="positive"?f.lime:f.teal}function yr(t){if(!t||Object.keys(t).length===0)return null;try{return JSON.stringify(t,null,2)}catch{return null}}function vr(t){if(!t)return null;const s=t.metadata;if(!s||typeof s!="object")return null;const i=["artifact","artifacts","output","outputs","result","results","payload","toolOutput","toolOutputs","toolResult","toolResults"];for(const n of i){const r=s[n];if(r!=null)return{source:n,value:r}}return t.type==="artifact_created"?{source:"metadata",value:s}:null}function cn(t){if(typeof t=="string")return e.jsx(zt,{mode:"block",text:t,className:"text-[13px] leading-relaxed text-white/82"});if(typeof t=="number"||typeof t=="boolean")return e.jsx("p",{className:"text-[13px] text-white/82",children:String(t)});if(Array.isArray(t))return e.jsx("div",{className:"space-y-1.5",children:t.map((s,i)=>e.jsx("div",{className:"rounded-lg border border-white/[0.08] bg-white/[0.02] px-2.5 py-2",children:cn(s)},`artifact-list-${i}`))});if(t&&typeof t=="object"){const s=Object.entries(t);return e.jsx("dl",{className:"space-y-1.5",children:s.map(([i,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-[10px] uppercase tracking-[0.1em] text-white/45",children:$e(i)}),e.jsx("dd",{className:"mt-1 text-[13px] text-white/82",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"}`:"—"})]},i))})}return e.jsx("p",{className:"text-[13px] text-white/55",children:"No artifact payload."})}function Ue(t){if(!t)return null;const s=t.trim();if(!s)return null;const i=ms(s);return i&&i!==s&&/^[a-z0-9._/-]+$/i.test(s)?i:$e(s)}function jr(t){if(!t)return null;const s=t.metadata;if(!s||typeof s!="object")return null;const i=typeof s.source=="string"?s.source.trim():"",n=typeof s.turnId=="string"?s.turnId.trim():"";if(i!=="local_openclaw"||!n)return null;const r=typeof s.sessionKey=="string"&&s.sessionKey.trim().length>0?s.sessionKey.trim():null;return{turnId:n,sessionKey:r,runId:t.runId??null}}function Bs(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 kr(t,s){const n=(Ue(s??t.summary)??Ue(t.description)??$e(t.title||st(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(),r=n.split(`
211
+ `).map(d=>Bs(d).trim()).filter(d=>d.length>0&&!/^\|?[:\-| ]+\|?$/.test(d));let o=r[0]??Bs(n);return o.length<24&&r.length>1&&(o=`${o} ${r[1]}`.trim()),o.length>108?`${o.slice(0,107).trimEnd()}…`:o}const Nr=a.memo(function({activity:s,sessions:i,initiatives:n=[],selectedRunIds:r,selectedSessionLabel:o=null,selectedWorkstreamId:d=null,selectedWorkstreamLabel:l=null,agentFilter:v=null,onClearSelection:u,onClearWorkstreamFilter:y,onClearAgentFilter:m,onFocusRunId:g}){var De;const x=Gs(),[j,p]=a.useState("all"),[M,D]=a.useState(!1),[O,H]=a.useState(""),[L,te]=a.useState(new Set),[ee,q]=a.useState("newest"),[E,ae]=a.useState(null),[k,N]=a.useState(null),[F,z]=a.useState(1),[I,S]=a.useState("structured"),[$,U]=a.useState(null),[fe,be]=a.useState("feed"),[Z,G]=a.useState(null),[T,C]=a.useState(null),[Y,re]=a.useState(!1),K=a.useMemo(()=>{const h=new Map;for(const P of i)h.set(P.runId,P.title),h.set(P.id,P.title);return h},[i]),Se=a.useMemo(()=>{const h=new Map;for(const P of i)P.status&&(h.set(P.runId,P.status),h.set(P.id,P.status));return h},[i]),he=a.useMemo(()=>{const h=new Map;for(const P of i){const _=P.workstreamId??null;h.set(P.runId,_),h.set(P.id,_)}return h},[i]),we=a.useMemo(()=>{const h=new Map;for(const P of n)h.set(P.id,P.name);return h},[n]),je=a.useMemo(()=>{const h=new Map;for(const P of n)for(const _ of P.workstreams??[])h.set(_.id,_.name);return h},[n]),w=a.useMemo(()=>i.filter(h=>h.status==="running"),[i]),R=a.useMemo(()=>s.map(h=>{const P=pr(h),_=xr(h),J=[h.title,h.description,h.summary,h.agentName,ln(h.metadata)].filter(ie=>typeof ie=="string"&&ie.length>0).join(" ").toLowerCase();return{item:h,bucket:_,runId:P,timestampEpoch:ur(h.timestamp),searchText:J}}),[s]),ce=a.useMemo(()=>{let h=0;for(const P of R)h=Math.max(h,P.timestampEpoch);return h<=0?!1:Date.now()-h<6e4},[R]),X=a.useMemo(()=>{const h={};for(const Ee of R)h[Ee.item.type]=(h[Ee.item.type]??0)+1;const P=[],_=(h.run_failed??0)+(h.blocker_created??0);_>0&&P.push({id:"errors",label:"errors",count:_,color:f.red,types:["run_failed","blocker_created"]});const J=(h.run_completed??0)+(h.milestone_completed??0);J>0&&P.push({id:"completions",label:"completions",count:J,color:f.lime,types:["run_completed","milestone_completed"]});const ie=h.artifact_created??0;ie>0&&P.push({id:"artifacts",label:"artifacts",count:ie,color:f.cyan,types:["artifact_created"]});const ye=(h.decision_requested??0)+(h.decision_resolved??0);ye>0&&P.push({id:"decisions",label:"decisions",count:ye,color:f.amber,types:["decision_requested","decision_resolved"]});const ve=(h.handoff_requested??0)+(h.handoff_claimed??0)+(h.handoff_fulfilled??0);return ve>0&&P.push({id:"handoffs",label:"handoffs",count:ve,color:f.iris,types:["handoff_requested","handoff_claimed","handoff_fulfilled"]}),P},[R]),ke=a.useMemo(()=>new Set(r.filter(h=>h&&h.trim().length>0)),[r]),A=ke.size>0,W=a.useMemo(()=>{if(!A)return null;for(const h of ke){const P=i.find(_=>_.runId===h||_.id===h);if(P)return P}return null},[A,ke,i]),{filtered:oe,truncatedCount:ue}=a.useMemo(()=>{const h=[];let P=0;const _=O.trim().toLowerCase();for(const ie of R){const ye=ie.runId;if(A&&(!ye||!ke.has(ye)))continue;if(d){const Ee=Os(ie.item),et=ye?he.get(ye)??null:null;if((Ee??et)!==d)continue}if(v&&ie.item.agentName!==v)continue;const ve=ie.bucket;if(!(j==="messages"&&ve!=="message")&&!(j==="artifacts"&&ve!=="artifact")&&!(j==="decisions"&&ve!=="decision")){if(_.length>0){const Ee=ye?K.get(ye)??ye:"";if(!`${ie.searchText} ${Ee.toLowerCase()}`.includes(_))continue}h.length<dr?h.push(ie):P+=1}}return{filtered:[...h].sort((ie,ye)=>{const ve=ye.timestampEpoch-ie.timestampEpoch;return ee==="newest"?ve:-ve}),truncatedCount:P}},[j,v,R,A,O,K,d,ke,he,ee]),se=a.useMemo(()=>{const h=new Map;for(const _ of oe){const J=mr(_.item.timestamp),ie=h.get(J);ie?ie.push(_):h.set(J,[_])}return Array.from(h.keys()).sort((_,J)=>{const ie=Number(J)-Number(_);return ee==="newest"?ie:-ie}).map(_=>({key:_,label:fr(_),items:h.get(_)??[]}))},[oe,ee]),le=a.useMemo(()=>se.map(h=>{const P=new Map;for(const _ of h.items){const J=`${_.item.type}::${_.item.title}`,ie=P.get(J);ie?(ie.count+=1,ie.firstTimestamp=Math.min(ie.firstTimestamp,_.timestampEpoch),ie.allItems.push(_),_.timestampEpoch>ie.representative.timestampEpoch&&(ie.representative=_)):P.set(J,{key:J,representative:_,count:1,firstTimestamp:_.timestampEpoch,allItems:[_]})}return{...h,clusters:Array.from(P.values())}}),[se]),xe=a.useCallback(h=>{te(P=>{const _=new Set(P);return _.has(h)?_.delete(h):_.add(h),_})},[]),Le=a.useMemo(()=>E?oe.findIndex(h=>h.item.id===E):-1,[E,oe]),V=Le>=0?oe[Le]:null,ot=a.useMemo(()=>vr((V==null?void 0:V.item)??null),[V]),Be=a.useMemo(()=>yr((V==null?void 0:V.item.metadata)??void 0),[V]),Ie=a.useMemo(()=>{const h=Ue($);return h||(Ue(V==null?void 0:V.item.summary)??Ue(V==null?void 0:V.item.description))},[$,V]),Je=a.useCallback(()=>{ae(null)},[]);a.useEffect(()=>{if(!k)return;const h=window.setTimeout(()=>N(null),2e3);return()=>window.clearTimeout(h)},[k]);const Ye=a.useCallback(async(h,P)=>{if(P)try{await navigator.clipboard.writeText(P),N(`${h} copied`)}catch{N("Copy failed")}},[]);a.useEffect(()=>{S("structured")},[E]),a.useEffect(()=>{U(null),be("feed");const h=jr((V==null?void 0:V.item)??null);if(!h)return;const P=new URLSearchParams({turnId:h.turnId});h.sessionKey&&P.set("sessionKey",h.sessionKey),h.runId&&P.set("run",h.runId);const _=new AbortController;return fetch(`/orgx/api/live/activity/detail?${P.toString()}`,{method:"GET",signal:_.signal}).then(async J=>{var ye;return J.ok?((ye=(await J.json()).detail)==null?void 0:ye.summary)??null:(J.status===404&&be("missing"),null)}).then(J=>{typeof J=="string"&&J.trim().length>0?(U(J),be("local")):be("missing")}).catch(J=>{J instanceof DOMException&&J.name==="AbortError"||be("missing")}),()=>_.abort()},[V]),a.useEffect(()=>{G(null),C(null);const h=V==null?void 0:V.item;if(!h||Y)return;const P=($??h.summary??h.description??h.title??"").trim();if(!P)return;const _=new AbortController;return fetch("/orgx/api/live/activity/headline",{method:"POST",headers:{"Content-Type":"application/json"},signal:_.signal,body:JSON.stringify({text:P,title:h.title??null,type:h.type})}).then(async J=>J.ok?await J.json():((J.status===404||J.status===405)&&re(!0),null)).then(J=>{const ie=J==null?void 0:J.headline;typeof ie=="string"&&ie.trim().length>0&&(re(!1),G(ie.trim()),C((J==null?void 0:J.source)??null))}).catch(J=>{J instanceof DOMException&&J.name}),()=>_.abort()},[V,$,Y]);const ze=a.useCallback(h=>{var J;if(oe.length===0)return;const _=((Le>=0?Le:0)+h+oe.length)%oe.length;z(h),ae(((J=oe[_])==null?void 0:J.item.id)??null)},[Le,oe]);a.useEffect(()=>{E&&(Le>=0||ae(null))},[Le,E]),a.useEffect(()=>{if(!E)return;const h=P=>{P.key==="ArrowRight"||P.key.toLowerCase()==="l"?(P.preventDefault(),ze(1)):(P.key==="ArrowLeft"||P.key.toLowerCase()==="h")&&(P.preventDefault(),ze(-1))};return window.addEventListener("keydown",h),()=>window.removeEventListener("keydown",h)},[E,ze]);const Ze=ke.size===1,lt=Ze?[...ke][0]:null,He=lt?i.find(h=>h.runId===lt||h.id===lt)??null:null,qe=a.useMemo(()=>Ze?R.filter(h=>h.runId&&ke.has(h.runId)).map(h=>h.item):[],[Ze,R,ke]),Nt=!x&&oe.length<=160,Ge=(h,P)=>{const _=h.item,J=br(_),ie=wr(J),ye=ee==="newest"&&P<2,ve=h.bucket,Ee=h.runId,et=Ee?K.get(Ee)??$e(Ee):"Workspace",ht=Ee?Se.get(Ee)??null:null,xt=$e(_.title??""),St=Ue(_.summary),mt=Ue(_.description),ft=_.initiativeId?we.get(_.initiativeId)??null:null,tt=Os(_)??(Ee?he.get(Ee)??null:null),ct=tt?je.get(tt)??$e(tt):null,gt=vt(ve),Vt=os(ve),dt=J==="critical"?"Error":J==="warning"?"Needs review":J==="positive"?"Completed":"Update",Ht=new Date(_.timestamp).toLocaleTimeString([],{hour:"numeric",minute:"2-digit"}),c="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-white/[0.16] hover:bg-white/[0.05] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#BFFF00]/45 cv-auto",B=e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"mt-0.5",children:e.jsx(Ke,{name:_.agentName??"OrgX",hint:`${_.agentId??""} ${et} ${_.title??""}`,size:"xs"})}),e.jsxs("div",{className:"relative min-w-0 flex-1 pl-3",children:[e.jsx("span",{className:ge("absolute inset-y-0 left-0 w-[2px] rounded-full",ye&&"pulse-soft"),style:{backgroundColor:ie,boxShadow:`0 0 14px ${ie}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-[13px] font-semibold leading-snug text-white/92",children:xt||$e(_.title||st(_.type))}),e.jsxs("p",{className:"mt-0.5 text-[11px] text-white/48",children:[_.agentName??"OrgX",ht?` · ${$e(ht)}`:""]})]}),e.jsxs("div",{className:"flex shrink-0 flex-col items-end gap-1",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-[0.09em] text-white/42",children:Vt}),e.jsx("span",{className:"text-[11px] text-white/55",children:Ht})]})]}),(St||mt)&&e.jsx("div",{className:"mt-1.5 line-clamp-2 text-[11px] leading-relaxed text-white/62",children:e.jsx(zt,{mode:"inline",text:St??mt??""})}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-1.5 text-[10px]",children:[e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full border px-2 py-0.5 uppercase tracking-[0.08em]",style:{borderColor:`${ie}55`,backgroundColor:`${ie}1A`,color:ie},children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full",style:{backgroundColor:ie}}),dt]}),e.jsx("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.02] px-2 py-0.5 text-white/60",children:et}),e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-white/62",style:{borderColor:`${gt}44`,color:gt},children:[e.jsx(Me,{type:gr(_),size:10,className:"opacity-90"}),$e(st(_.type))]}),e.jsx("span",{className:"text-white/55",children:Fe(_.timestamp)}),ft&&e.jsxs("span",{className:"inline-flex max-w-[220px] items-center gap-1 rounded-full border border-white/[0.12] bg-white/[0.03] px-2 py-0.5 text-white/54",title:ft,children:[e.jsx(Me,{type:"initiative",size:10,className:"opacity-85"}),e.jsx("span",{className:"truncate",children:ft})]}),ct&&e.jsxs("span",{className:"inline-flex max-w-[220px] items-center gap-1 rounded-full border border-white/[0.12] bg-white/[0.03] px-2 py-0.5 text-white/54",title:ct,children:[e.jsx(Me,{type:"workstream",size:10,className:"opacity-90"}),e.jsx("span",{className:"truncate",children:ct})]})]})]})]});return Nt?e.jsx(de.button,{type:"button",variants:cr,initial:"initial",animate:"animate",exit:"exit",transition:{duration:.25,ease:[.4,0,.2,1]},whileHover:{y:-1.5},whileTap:{scale:.995},onClick:()=>{z(1),ae(_.id)},className:c,"aria-label":`Open activity details for ${xt||st(_.type)}`,children:B},_.id):e.jsx("button",{type:"button",onClick:()=>{z(1),ae(_.id)},className:ge(c,"transform-gpu transition-[transform,background-color,border-color,color] hover:-translate-y-[1px] active:scale-[0.995]"),"aria-label":`Open activity details for ${xt||st(_.type)}`,children:B},_.id)};return e.jsxs(at,{className:"flex h-full min-h-0 flex-col card-enter",children:[Ze&&qe.length>0?e.jsx(lr,{items:qe,session:He,agentName:((De=qe[0])==null?void 0:De.agentName)??null,onBack:u}):e.jsxs(e.Fragment,{children:[w.length>0&&e.jsxs("div",{className:"flex items-center gap-2 overflow-x-auto border-b border-white/[0.06] px-4 py-2 scrollbar-none",children:[e.jsx("span",{className:"flex-shrink-0 text-[10px] uppercase tracking-[0.08em] text-white/35",children:"In Progress"}),w.map(h=>e.jsxs("button",{type:"button",onClick:()=>g==null?void 0:g(h.runId),className:"flex flex-shrink-0 items-center gap-1.5 rounded-full border border-white/[0.08] bg-white/[0.03] px-2.5 py-1 transition-colors hover:bg-white/[0.06]",children:[e.jsx(Ke,{name:h.agentName??"OrgX",size:"xs",hint:h.agentName}),e.jsx("span",{className:"max-w-[140px] truncate text-[11px] text-white/70",children:h.title})]},h.id))]}),e.jsxs("div",{className:"border-b border-white/[0.06] px-4 py-3.5",children:[e.jsxs("div",{className:"toolbar-shell flex flex-wrap 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-[14px] font-semibold text-white",children:"Activity"}),e.jsx("span",{className:"rounded-full border border-white/[0.14] bg-white/[0.05] px-2 py-0.5 text-[10px] text-white/75",children:oe.length}),ue>0&&e.jsxs("span",{className:"rounded-full border border-white/[0.14] bg-white/[0.03] px-2 py-0.5 text-[10px] text-white/55",children:["+",ue," hidden"]}),e.jsx("span",{className:ge("h-1.5 w-1.5 rounded-full",ce&&"pulse-soft"),style:{backgroundColor:f.lime},"aria-label":"Live",title:ce?"New activity within the last minute":"Live activity feed"}),A&&e.jsxs("button",{onClick:u,className:"chip inline-flex min-w-0 items-center gap-2","aria-label":"Clear session filter",children:[e.jsx(Ke,{name:(W==null?void 0:W.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-white/[0.12] bg-white/[0.04] text-[10px] text-white/60",children:"×"})]}),d&&e.jsxs("button",{onClick:y,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-white/[0.12] bg-white/[0.04] text-[10px]",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-white/[0.12] bg-white/[0.04] text-[10px] text-white/60",children:"×"})]}),v&&e.jsxs("button",{onClick:m,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(Ke,{name:v,hint:v,size:"xs"}),e.jsxs("span",{className:"min-w-0 truncate",children:["Agent: ",v]}),e.jsx("span",{className:"ml-1 inline-flex h-4 w-4 items-center justify-center rounded-full border border-white/[0.12] bg-white/[0.04] text-[10px] text-white/60",children:"×"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>q(h=>h==="newest"?"oldest":"newest"),className:"control-pill px-3 text-[11px] font-medium","aria-label":ee==="newest"?"Sort oldest first":"Sort newest first",children:ee==="newest"?"Newest":"Oldest"}),e.jsx("button",{type:"button",onClick:()=>D(h=>!h),"data-state":M?"active":"idle",className:"control-pill px-3 text-[11px] font-medium","aria-pressed":M,children:M?"Expand":"Compact"})]})]}),X.length>0&&e.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-1.5",children:X.map(h=>e.jsxs("button",{type:"button",onClick:()=>{h.id==="errors"||h.id==="completions"?p("messages"):h.id==="artifacts"?p("artifacts"):h.id==="decisions"?p("decisions"):p("all")},className:"inline-flex items-center gap-1 rounded-full border border-white/[0.12] bg-white/[0.03] px-2 py-0.5 text-[10px] transition-colors hover:bg-white/[0.08]",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full",style:{backgroundColor:h.color}}),e.jsx("span",{className:"font-semibold text-white",style:{fontVariantNumeric:"tabular-nums"},children:h.count}),e.jsx("span",{className:"text-white/45",children:h.label})]},h.id))}),e.jsxs("div",{className:"mt-2 flex flex-col gap-2 sm:flex-row sm:items-center",children:[e.jsxs("div",{className:"relative min-w-0 flex-1",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-white/35",children:[e.jsx("circle",{cx:"11",cy:"11",r:"7"}),e.jsx("path",{d:"m20 20-3.5-3.5"})]}),e.jsx("input",{value:O,onChange:h=>H(h.target.value),placeholder:"Search activity...",className:"w-full rounded-lg border border-white/[0.12] bg-black/25 py-2 pl-9 pr-2 text-[12px] text-white/82 placeholder:text-white/35 transition-colors focus:border-[#BFFF00]/35 focus:outline-none","aria-label":"Search activity"})]}),e.jsx("div",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.12] bg-black/20 p-0.5",role:"group","aria-label":"Activity filters",children:Object.keys($t).map(h=>{const P=j===h;return e.jsx("button",{type:"button",onClick:()=>p(h),"aria-pressed":P,className:ge("rounded-full px-3 py-1.5 text-[10px] font-semibold transition-colors",P?"border border-lime/25 bg-lime/[0.13] text-lime":"border border-transparent text-white/60 hover:bg-white/[0.08] hover:text-white/85"),children:$t[h]},h)})})]})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-4 py-3",children:[oe.length===0&&e.jsxs("div",{className:"flex flex-col items-center gap-2.5 rounded-xl border border-white/[0.06] 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-white/25",children:e.jsx("polyline",{points:"22 12 18 12 15 21 9 3 6 12 2 12"})}),e.jsx("p",{className:"text-[12px] text-white/45",children:A?`No ${$t[j].toLowerCase()} for the selected session.`:d?`No ${$t[j].toLowerCase()} for the selected workstream.`:"No matching activity right now."}),(A||d)&&e.jsx("button",{onClick:A?u:y,className:"rounded-md border border-white/[0.12] bg-white/[0.04] px-3 py-1.5 text-[11px] text-white/70 transition-colors hover:bg-white/[0.08]",children:A?"Show all sessions":"Show all workstreams"})]}),oe.length>0&&e.jsxs("div",{className:"space-y-4",children:[le.map(h=>{const P=M?h.clusters.slice(0,4):h.clusters;return e.jsxs("section",{children:[e.jsx("h3",{className:"mb-2.5 border-b border-white/[0.06] pb-1.5 text-[11px] uppercase tracking-[0.12em] text-white/35",children:h.label}),Nt?e.jsx(Te,{mode:"popLayout",children:e.jsx("div",{className:"space-y-2",children:P.map((_,J)=>{const ie=L.has(_.key);return _.count===1?Ge(_.representative,J):e.jsxs("div",{children:[Ge(_.representative,J),e.jsxs("button",{type:"button",onClick:ye=>{ye.stopPropagation(),xe(_.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-[10px] text-white/55 transition-colors hover:bg-white/[0.06] hover:text-white/75",children:[e.jsxs("span",{className:"font-semibold",children:["×",_.count]}),e.jsx("span",{className:"text-white/35",children:"·"}),e.jsxs("span",{children:["first seen ",Fe(_.firstTimestamp)]}),e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:ge("transition-transform",ie?"rotate-0":"-rotate-90"),children:e.jsx("path",{d:"m6 9 6 6 6-6"})})]}),ie&&e.jsx("div",{className:"ml-8 mt-1 space-y-1.5 border-l border-white/[0.06] pl-3",children:_.allItems.slice(1).map((ye,ve)=>Ge(ye,J+ve+1))})]},_.key)})})}):e.jsx("div",{className:"space-y-2",children:P.map((_,J)=>{const ie=L.has(_.key);return _.count===1?Ge(_.representative,J):e.jsxs("div",{children:[Ge(_.representative,J),e.jsxs("button",{type:"button",onClick:ye=>{ye.stopPropagation(),xe(_.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-[10px] text-white/55 transition-colors hover:bg-white/[0.06] hover:text-white/75",children:[e.jsxs("span",{className:"font-semibold",children:["×",_.count]}),e.jsx("span",{className:"text-white/35",children:"·"}),e.jsxs("span",{children:["first seen ",Fe(_.firstTimestamp)]}),e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:ge("transition-transform",ie?"rotate-0":"-rotate-90"),children:e.jsx("path",{d:"m6 9 6 6 6-6"})})]}),ie&&e.jsx("div",{className:"ml-8 mt-1 space-y-1.5 border-l border-white/[0.06] pl-3",children:_.allItems.slice(1).map((ye,ve)=>Ge(ye,J+ve+1))})]},_.key)})}),M&&h.clusters.length>P.length&&e.jsxs("p",{className:"mt-1.5 text-[11px] text-white/35",children:["+",h.clusters.length-P.length," more"]})]},h.key)}),ue>0&&e.jsxs("p",{className:"rounded-xl border border-white/[0.06] bg-white/[0.02] px-3 py-2 text-[11px] text-white/45",children:["Showing latest ",oe.length," events (",ue," older events omitted for smooth rendering)."]})]})]})]}),e.jsx(pt,{open:V!==null,onClose:Je,maxWidth:"max-w-3xl",children:V&&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-white/[0.06] px-5 py-4 sm:px-6",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[11px] uppercase tracking-[0.12em] text-white/40",children:"Activity Detail"}),e.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[e.jsx("span",{className:"h-2.5 w-2.5 rounded-full",style:{backgroundColor:vt(V.bucket),boxShadow:`0 0 16px ${vt(V.bucket)}77`}}),e.jsxs("span",{className:"text-[12px] text-white/70",children:[os(V.bucket)," · ",Le+1,"/",oe.length]}),k&&e.jsx("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.04] px-2 py-0.5 text-[10px] uppercase tracking-[0.12em] text-white/60",children:k})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[V.runId&&g&&e.jsx("button",{type:"button",onClick:()=>{g(V.runId),Je()},className:"rounded-full border border-lime/25 bg-lime/10 px-3 py-1 text-[11px] font-semibold text-lime transition hover:bg-lime/20",children:"Focus session"}),V.runId&&e.jsx("button",{type:"button",onClick:()=>void Ye("Run id",V.runId??""),className:"rounded-full border border-white/[0.12] bg-white/[0.04] px-2.5 py-1 text-[11px] text-white/70 transition hover:bg-white/[0.1]","aria-label":"Copy run id",children:"Copy run"}),V.item.agentId&&e.jsx("button",{type:"button",onClick:()=>void Ye("Agent id",V.item.agentId??""),className:"rounded-full border border-white/[0.12] bg-white/[0.04] px-2.5 py-1 text-[11px] text-white/70 transition hover:bg-white/[0.1]","aria-label":"Copy agent id",children:"Copy agent"}),e.jsx("button",{type:"button",onClick:()=>void Ye("Event id",V.item.id),className:"rounded-full border border-white/[0.12] bg-white/[0.04] px-2.5 py-1 text-[11px] text-white/70 transition hover:bg-white/[0.1]","aria-label":"Copy event id",children:"Copy event"}),e.jsx("button",{type:"button",onClick:()=>ze(-1),className:"rounded-full border border-white/[0.12] bg-white/[0.04] px-2.5 py-1 text-[11px] text-white/70 transition hover:bg-white/[0.1]","aria-label":"Previous activity item",children:"← Prev"}),e.jsx("button",{type:"button",onClick:()=>ze(1),className:"rounded-full border border-white/[0.12] bg-white/[0.04] px-2.5 py-1 text-[11px] text-white/70 transition hover:bg-white/[0.1]","aria-label":"Next activity item",children:"Next →"}),e.jsx("button",{type:"button",onClick:Je,className:"rounded-full border border-white/[0.12] bg-white/[0.04] px-2 py-1 text-[11px] text-white/60 transition hover:bg-white/[0.1] hover:text-white/90","aria-label":"Close activity detail",children:"Esc"})]})]}),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(Te,{mode:"wait",custom:F,children:e.jsx(de.section,{custom:F,initial:{opacity:0,x:F*44,scale:.985},animate:{opacity:1,x:0,scale:1},exit:{opacity:0,x:F*-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-[20px] font-semibold tracking-[-0.02em] text-white whitespace-pre-wrap break-words",children:Z||kr(V.item,$)||$e(V.item.title||st(V.item.type))}),e.jsxs("p",{className:"mt-1 flex flex-wrap items-center gap-x-2 text-[12px] text-white/45",children:[new Date(V.item.timestamp).toLocaleString()," · ",Fe(V.item.timestamp),T==="llm"&&e.jsx("span",{className:"text-white/35",children:"· AI title"})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-1.5 text-[11px]",children:[e.jsx("span",{className:"rounded-full border px-2 py-0.5 uppercase tracking-[0.1em]",style:{borderColor:`${vt(V.bucket)}55`,color:vt(V.bucket)},children:os(V.bucket)}),e.jsx("span",{className:"rounded-full border border-white/[0.12] px-2 py-0.5 text-white/65",children:st(V.item.type)}),V.item.agentName&&e.jsxs("span",{className:"inline-flex items-center gap-1.5 rounded-full border border-white/[0.12] px-1.5 py-0.5 text-white/65",children:[e.jsx(Ke,{name:V.item.agentName,hint:`${V.item.agentId??""} ${V.item.title??""}`,size:"xs"}),e.jsx("span",{children:V.item.agentName})]}),V.runId&&e.jsx("span",{className:"rounded-full border border-white/[0.12] px-2 py-0.5 text-white/65",children:K.get(V.runId)??$e(V.runId)})]}),Ie&&e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.03] p-3",children:[e.jsx("p",{className:"text-[11px] uppercase tracking-[0.11em] text-white/45",children:"Summary"}),fe==="missing"&&e.jsx("p",{className:"mt-1 text-[11px] text-amber-200/75",children:"Full local turn transcript was unavailable; showing the event summary payload."}),e.jsx(zt,{mode:"block",text:Ie,className:"mt-1.5 text-[14px] leading-relaxed text-white/82"})]}),Ue(V.item.description)&&e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-black/25 p-3",children:[e.jsx("p",{className:"text-[11px] uppercase tracking-[0.11em] text-white/45",children:"Details"}),e.jsx(zt,{mode:"block",text:Ue(V.item.description)??"",className:"mt-1.5 text-[13px] leading-relaxed text-white/75"})]}),ot&&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-[11px] uppercase tracking-[0.11em] text-cyan-100/85",children:"Artifact Output"}),e.jsxs("div",{className:"inline-flex rounded-full border border-white/[0.12] bg-black/30 p-0.5 text-[11px]",children:[e.jsx("button",{type:"button",onClick:()=>S("structured"),"aria-pressed":I==="structured",className:`rounded-full px-2.5 py-0.5 transition-colors ${I==="structured"?"bg-white/[0.12] text-white":"text-white/55 hover:text-white/80"}`,children:"Structured"}),e.jsx("button",{type:"button",onClick:()=>S("json"),"aria-pressed":I==="json",className:`rounded-full px-2.5 py-0.5 transition-colors ${I==="json"?"bg-white/[0.12] text-white":"text-white/55 hover:text-white/80"}`,children:"JSON"})]})]}),e.jsxs("p",{className:"mt-1 text-[10px] text-cyan-100/55",children:["Source: ",ot.source]}),e.jsx("div",{className:"mt-2",children:I==="structured"?cn(ot.value):e.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap font-mono text-[11px] leading-relaxed text-white/70",children:JSON.stringify(ot.value,null,2)})})]}),Be&&e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-black/35 p-3",children:[e.jsx("p",{className:"text-[11px] uppercase tracking-[0.11em] text-white/45",children:"Metadata"}),e.jsx("pre",{className:"mt-1.5 overflow-x-auto whitespace-pre-wrap font-mono text-[11px] leading-relaxed text-white/65",children:Be})]})]})},V.item.id)})}),e.jsx("div",{className:"border-t border-white/[0.06] px-5 py-2.5 text-[11px] text-white/40 sm:px-6",children:"Keyboard: ← previous · → next · Esc close"})]})})]})}),ls=40;function Ps(t){return t>=15?{border:f.red,glow:`0 0 16px ${f.red}20`}:t>=5?{border:f.amber,glow:`0 0 12px ${f.amber}18`}:{border:f.teal,glow:"none"}}const Sr=a.memo(function({decisions:s,onApproveDecision:i,onApproveAll:n}){const r=Gs(),[o,d]=a.useState(!1),[l,v]=a.useState(new Set),[u,y]=a.useState(new Set),[m,g]=a.useState(null),[x,j]=a.useState(ls),p=a.useMemo(()=>[...s].sort((k,N)=>{if(k.waitingMinutes!==N.waitingMinutes)return N.waitingMinutes-k.waitingMinutes;const F=Date.parse(k.requestedAt??k.updatedAt??""),z=Date.parse(N.requestedAt??N.updatedAt??""),I=Number.isFinite(F)?F:0;return(Number.isFinite(z)?z:0)-I}),[s]);a.useEffect(()=>{y(k=>{const N=new Set(p.map(z=>z.id)),F=new Set;for(const z of k)N.has(z)&&F.add(z);return F})},[p]);const M=u.size,D=a.useMemo(()=>p.slice(0,x),[p,x]),O=a.useMemo(()=>{if(D.length===0)return!1;for(const k of D)if(!u.has(k.id))return!1;return!0},[u,D]);a.useEffect(()=>{j(k=>p.length===0?0:Math.min(Math.max(ls,k),p.length))},[p.length]);const H=k=>{y(N=>{const F=new Set(N);return F.has(k)?F.delete(k):F.add(k),F})},L=()=>{y(k=>{if(D.length===0)return k;const N=new Set(k),F=O;for(const z of D)F?N.delete(z.id):N.add(z.id);return N})},te=async()=>{if(!(p.length===0||o)){g(null),d(!0);try{const k=await n();k.failed>0?g(`Approved ${k.updated}; ${k.failed} failed.`):k.updated>0?g(`Approved ${k.updated} decision${k.updated===1?"":"s"}.`):g("No decisions were updated."),y(new Set)}catch(k){g(k instanceof Error?k.message:"Bulk approval failed.")}finally{d(!1)}}},ee=async()=>{if(M===0||o)return;g(null),d(!0);let k=0,N=0;try{const F=p.map(z=>z.id).filter(z=>u.has(z));for(const z of F){v(I=>new Set(I).add(z));try{const I=await i(z);k+=I.updated,N+=I.failed}catch{N+=1}finally{v(I=>{const S=new Set(I);return S.delete(z),S})}}N>0?g(`Approved ${k}; ${N} failed.`):g(`Approved ${k} selected decision${k===1?"":"s"}.`),y(new Set)}finally{d(!1)}},q=async k=>{if(!(l.has(k)||o)){g(null),v(N=>{const F=new Set(N);return F.add(k),F});try{const N=await i(k);N.failed>0?g(`Approval failed for ${N.failed} decision.`):N.updated>0&&g("Decision approved.")}catch(N){g(N instanceof Error?N.message:"Decision approval failed.")}finally{v(N=>{const F=new Set(N);return F.delete(k),F}),y(N=>{if(!N.has(k))return N;const F=new Set(N);return F.delete(k),F})}}},E=m!==null&&!m.toLowerCase().includes("fail"),ae=!r&&D.length<=32;return e.jsxs(at,{className:"flex h-full min-h-0 flex-col card-enter",children:[e.jsxs("div",{className:"space-y-2 border-b border-white/[0.06] px-4 py-3.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"inline-flex items-center gap-2 text-[14px] font-semibold text-white",children:[e.jsx(Me,{type:"decision",size:14}),"Decisions"]}),e.jsx("p",{className:"text-[12px] text-white/45",children:"Select multiple items to bulk review and approve"})]}),e.jsx("button",{onClick:te,disabled:p.length===0||o,className:"rounded-lg px-3 py-1.5 text-[11px] font-semibold transition-colors",style:{backgroundColor:p.length===0||o?"rgba(255,255,255,0.08)":f.lime,color:p.length===0||o?"rgba(255,255,255,0.45)":"#000"},children:o?"Approving…":`Approve all (${p.length})`})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{onClick:L,disabled:p.length===0||o,className:"rounded-md border border-white/[0.12] bg-white/[0.03] px-2.5 py-1.5 text-[11px] text-white/70 transition-colors hover:bg-white/[0.07] disabled:opacity-45",children:O?"Clear all":"Select all"}),e.jsx("button",{onClick:ee,disabled:M===0||o,className:"rounded-md border border-lime/25 bg-lime/10 px-2.5 py-1.5 text-[11px] font-semibold text-lime transition-colors hover:bg-lime/20 disabled:opacity-45",children:o?"Approving…":`Approve selected (${M})`}),e.jsx("span",{className:"text-[11px] text-white/45",children:M>0?`${M} selected`:"No selection"})]})]}),e.jsxs("div",{className:"min-h-0 flex-1 space-y-2 overflow-y-auto p-3",children:[p.length===0&&e.jsxs("div",{className:"flex flex-col items-center gap-2.5 rounded-xl border border-white/[0.06] 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-white/25",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-[12px] text-white/45",children:"No pending decisions. All clear."})]}),ae?e.jsx(Te,{mode:"popLayout",children:D.map(k=>{const N=l.has(k.id),F=Ps(k.waitingMinutes),z=u.has(k.id);return e.jsx(de.article,{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?`${f.lime}50`:`${F.border}35`,borderLeftWidth:3,borderLeftColor:`${F.border}80`,boxShadow:F.glow},children:e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx("input",{type:"checkbox",checked:z,onChange:()=>H(k.id),disabled:N||o,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:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("p",{className:"inline-flex min-w-0 items-center gap-1.5 text-[13px] font-medium text-white",children:[e.jsx(Me,{type:"decision",size:12,className:"flex-shrink-0 opacity-90"}),e.jsx("span",{className:"truncate",children:k.title})]}),k.context&&e.jsx("p",{className:"mt-1 line-clamp-2 text-[11px] text-white/55",children:k.context}),e.jsxs("p",{className:"mt-1.5 text-[10px] text-white/40",children:[k.agentName??"System"," · Waiting ",k.waitingMinutes,"m",k.requestedAt?` · ${Fe(k.requestedAt)}`:""]})]}),e.jsx("button",{onClick:()=>q(k.id),disabled:N||o,className:"rounded-md border border-lime/25 bg-lime/10 px-3 py-1.5 text-[11px] 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-white/45",children:N?"Approving…":"Approve"})]})})]})},k.id)})}):e.jsx(e.Fragment,{children:D.map(k=>{const N=l.has(k.id),F=Ps(k.waitingMinutes),z=u.has(k.id);return e.jsx("article",{className:"rounded-xl border bg-white/[0.03] px-3 py-2.5 transition-[border-color,box-shadow] cv-auto",style:{borderColor:z?`${f.lime}50`:`${F.border}35`,borderLeftWidth:3,borderLeftColor:`${F.border}80`,boxShadow:F.glow},children:e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx("input",{type:"checkbox",checked:z,onChange:()=>H(k.id),disabled:N||o,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:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("p",{className:"inline-flex min-w-0 items-center gap-1.5 text-[13px] font-medium text-white",children:[e.jsx(Me,{type:"decision",size:12,className:"flex-shrink-0 opacity-90"}),e.jsx("span",{className:"truncate",children:k.title})]}),k.context&&e.jsx("p",{className:"mt-1 line-clamp-2 text-[11px] text-white/55",children:k.context}),e.jsxs("p",{className:"mt-1.5 text-[10px] text-white/40",children:[k.agentName??"System"," · Waiting ",k.waitingMinutes,"m",k.requestedAt?` · ${Fe(k.requestedAt)}`:""]})]}),e.jsx("button",{onClick:()=>q(k.id),disabled:N||o,className:"rounded-md border border-lime/25 bg-lime/10 px-3 py-1.5 text-[11px] 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-white/45",children:N?"Approving…":"Approve"})]})})]})},k.id)})}),D.length<p.length&&e.jsxs("button",{onClick:()=>j(k=>Math.min(p.length,k+ls)),className:"w-full rounded-xl border border-white/[0.08] bg-white/[0.02] px-3 py-2 text-[11px] text-white/55 transition-colors hover:bg-white/[0.05]",children:["Load more (",p.length-D.length," remaining)"]})]}),m&&e.jsxs("div",{className:"flex items-center gap-2 border-t border-white/[0.06] px-4 py-2.5 text-[12px] text-white/55",children:[e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:E?"text-lime":"text-amber-400",children:E?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"})]})}),m]})]})});async function Tt(t){return await t.json().catch(()=>null)}function Dt(t,s,i){return typeof(s==null?void 0:s.error)=="string"&&s.error.trim()||typeof(s==null?void 0:s.message)=="string"&&s.message.trim()||`${i} (${t.status})`}function Cr({initiativeId:t=null,authToken:s=null,embedMode:i=!1,enabled:n=!0}){var m,g,x,j;const r=Vs(),o=a.useMemo(()=>rt.nextUpQueue({initiativeId:t,authToken:s,embedMode:i}),[t,s,i]),d=async()=>{await r.invalidateQueries({queryKey:o}),await r.invalidateQueries({queryKey:rt.autoContinueStatus({initiativeId:t,authToken:s,embedMode:i})}),await r.invalidateQueries({queryKey:rt.missionControlGraph({initiativeId:t,authToken:s,embedMode:i})}),await r.invalidateQueries({queryKey:rt.liveData({authToken:s,embedMode:i})})},l=Ve({queryKey:o,enabled:n,queryFn:async()=>{const p=new URLSearchParams;t&&p.set("initiative_id",t);const M=await fetch(`/orgx/api/mission-control/next-up?${p.toString()}`,{headers:it({authToken:s,embedMode:i})}),D=await Tt(M);if(!M.ok){const H=Dt(M,D,"Failed to load next up queue");throw new Error(H)}const O=D??null;return!O||O.ok!==!0?{ok:!0,generatedAt:new Date().toISOString(),total:0,items:[],degraded:["next-up queue response missing expected payload"]}:O},refetchInterval:p=>{const M=p.state.data;return!M||!Array.isArray(M.items)||M.items.length===0?1e4:M.items.some(O=>O.queueState==="running")?2500:8e3}}),v=Ot({mutationFn:async p=>{const M=await fetch("/orgx/api/mission-control/next-up/play",{method:"POST",headers:it({authToken:s,embedMode:i,contentTypeJson:!0}),body:JSON.stringify({initiativeId:p.initiativeId,workstreamId:p.workstreamId,agentId:p.agentId??void 0})}),D=await Tt(M);if(!M.ok)throw new Error(Dt(M,D,"Failed to dispatch queued workstream"))},onSuccess:()=>{d()}}),u=Ot({mutationFn:async p=>{const M=await fetch("/orgx/api/mission-control/auto-continue/start",{method:"POST",headers:it({authToken:s,embedMode:i,contentTypeJson:!0}),body:JSON.stringify({initiativeId:p.initiativeId,agentId:p.agentId??void 0,tokenBudgetTokens:p.tokenBudgetTokens,workstreamIds:[p.workstreamId]})}),D=await Tt(M);if(!M.ok)throw new Error(Dt(M,D,"Failed to start auto-continue"))},onSuccess:()=>{d()}}),y=Ot({mutationFn:async p=>{const M=await fetch("/orgx/api/mission-control/auto-continue/stop",{method:"POST",headers:it({authToken:s,embedMode:i,contentTypeJson:!0}),body:JSON.stringify({initiativeId:p.initiativeId})}),D=await Tt(M);if(!M.ok)throw new Error(Dt(M,D,"Failed to stop auto-continue"))},onSuccess:()=>{d()}});return{items:((m=l.data)==null?void 0:m.items)??[],total:((g=l.data)==null?void 0:g.total)??0,degraded:((x=l.data)==null?void 0:x.degraded)??[],isLoading:l.isLoading,isFetching:l.isFetching,error:((j=l.error)==null?void 0:j.message)??null,refetch:l.refetch,playWorkstream:v.mutateAsync,startWorkstreamAutoContinue:u.mutateAsync,stopInitiativeAutoContinue:y.mutateAsync,isPlaying:v.isPending,isStartingAutoContinue:u.isPending,isStoppingAutoContinue:y.isPending}}function Ar({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 Ir({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 Mr({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 11.2c0-2.1 1.3-3.7 3.3-3.7 2.5 0 4.2 5 6.7 5 1.9 0 3-1.4 3-3.1 0-1.7-1.1-3.1-3-3.1-1.1 0-2.2.6-3.4 1.9",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"}),e.jsx("path",{d:"M8.3 8.2l.8 1.8-2 .1",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]})}function Er(t){return t==="running"?"border-teal-300/35 bg-teal-400/[0.12] text-teal-100":t==="blocked"?"border-red-400/35 bg-red-500/[0.12] text-red-100":t==="idle"?"border-white/[0.16] bg-white/[0.05] text-white/65":"border-[#BFFF00]/30 bg-[#BFFF00]/12 text-[#E1FFB2]"}function _r(t){return t==="running"?"Running":t==="blocked"?"Blocked":t==="idle"?"Idle":"Queued"}function Fr(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 Lr({initiativeId:t=null,authToken:s=null,embedMode:i=!1,title:n="Next Up",compact:r=!1,className:o,disableEnterAnimation:d=!1,onFollowWorkstream:l,onOpenInitiative:v}){const[u,y]=a.useState(null),[m,g]=a.useState(null),{items:x,total:j,degraded:p,isLoading:M,isFetching:D,error:O,playWorkstream:H,startWorkstreamAutoContinue:L,stopInitiativeAutoContinue:te}=Cr({initiativeId:t,authToken:s,embedMode:i,enabled:!0}),ee=a.useMemo(()=>r?x.slice(0,7):x,[r,x]),q=async(E,ae,k)=>{y(null),g(E);try{await ae(),y(k)}catch(N){y(N instanceof Error?N.message:"Action failed")}finally{g(null)}};return e.jsxs(at,{className:`flex h-full min-h-0 flex-col overflow-hidden ${d?"":"card-enter"} ${o??""}`,children:[e.jsx("div",{className:"flex items-center justify-between gap-2 border-b border-white/[0.06] px-4 py-3",children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("h2",{className:"truncate text-[14px] font-semibold text-white",children:n}),e.jsx("span",{className:"chip text-[10px]",children:j}),D&&!M&&e.jsx("span",{className:"text-[10px] text-white/38",children:"refreshing…"})]})}),e.jsx(Te,{initial:!1,children:u&&e.jsx(de.div,{initial:{opacity:0,y:-4},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},transition:{duration:.2},className:"mx-3 mt-2 rounded-lg border border-white/[0.1] bg-white/[0.03] px-3 py-2 text-[11px] text-white/75",children:u})}),e.jsx(Te,{initial:!1,children:O&&e.jsx(de.div,{initial:{opacity:0,y:-4},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},transition:{duration:.2},className:"mx-3 mt-2 rounded-lg border border-red-400/25 bg-red-500/[0.08] px-3 py-2 text-[11px] text-red-100",children:O})}),e.jsxs("div",{className:"flex-1 space-y-2.5 overflow-y-auto px-3 py-3",children:[!M&&ee.length===0&&!O&&e.jsx("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.02] px-3 py-4 text-center text-[12px] text-white/50",children:"No queued workstreams right now."}),e.jsx(Te,{initial:!1,children:ee.map((E,ae)=>{var I,S;const k=`${E.initiativeId}:${E.workstreamId}`,N=m===k,F=((I=E.autoContinue)==null?void 0:I.status)==="running"||((S=E.autoContinue)==null?void 0:S.status)==="stopping",z=E.nextTaskDueAt?Fe(E.nextTaskDueAt):null;return e.jsxs(de.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(ae,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:`pointer-events-none absolute inset-x-3 top-0 h-px bg-gradient-to-r ${Fr(E.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(Ke,{name:E.runnerAgentName,hint:`${E.runnerAgentId} ${E.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(Me,{type:"initiative",size:11,className:"flex-shrink-0 opacity-85"}),e.jsx("button",{type:"button",onClick:()=>v==null?void 0:v(E.initiativeId,E.initiativeTitle),className:"block w-full truncate text-left text-[10px] uppercase tracking-[0.08em] text-white/42 transition-colors hover:text-white/72",title:E.initiativeTitle,children:E.initiativeTitle})]}),e.jsxs("p",{className:"mt-0.5 flex min-w-0 items-center gap-1.5 line-clamp-1 text-[13px] font-semibold text-white",children:[e.jsx(Me,{type:"workstream",size:12,className:"flex-shrink-0 opacity-95"}),e.jsx("span",{className:"truncate",children:E.workstreamTitle})]})]})]}),e.jsx("span",{className:`flex-shrink-0 rounded-full border px-2 py-0.5 text-[10px] ${Er(E.queueState)}`,children:_r(E.queueState)})]}),e.jsx("div",{className:"mt-2 rounded-lg border border-white/[0.07] bg-black/[0.18] px-2.5 py-2 text-[11px] text-white/68",children:E.nextTaskTitle?e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-1 text-[9px] uppercase tracking-[0.08em] text-white/44",children:[e.jsx(Me,{type:"task",size:10,className:"flex-shrink-0 opacity-80"}),e.jsx("span",{children:"Next"}),z?e.jsxs("span",{className:"truncate text-[9px] normal-case tracking-normal text-white/38",children:["· ",z]}):null]}),e.jsx("p",{className:"line-clamp-2 break-words text-[11px] leading-snug text-white/84",children:E.nextTaskTitle})]}):e.jsx("span",{className:"text-white/45",children:"No task currently queued."})}),e.jsxs("div",{className:"mt-1.5 flex items-center gap-2 text-[10px] text-white/48",children:[e.jsx("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-2 py-0.5 text-[9px] uppercase tracking-[0.08em] text-white/52",children:"Runner"}),e.jsxs("span",{className:"truncate text-white/68",children:[E.runnerAgentName,E.runnerSource!=="assigned"?` · ${E.runnerSource}`:""]})]}),E.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-[10px] text-red-100/85",children:["Blocked: ",E.blockReason]}),e.jsxs("div",{className:"mt-2.5 grid grid-cols-2 gap-1.5 sm:grid-cols-3",children:[e.jsx("button",{type:"button",onClick:()=>l==null?void 0:l(E),className:"control-pill flex h-8 w-full items-center justify-center px-2 text-[10px] font-semibold",title:"Follow this workstream in Activity",children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(Ar,{className:"h-3.5 w-3.5 opacity-85"}),e.jsx("span",{children:"Follow"})]})}),e.jsx("button",{type:"button",disabled:N,onClick:()=>void q(k,()=>H({initiativeId:E.initiativeId,workstreamId:E.workstreamId,agentId:E.runnerAgentId}),`Dispatched ${E.workstreamTitle}.`),className:"control-pill flex h-8 w-full items-center justify-center px-2 text-[10px] font-semibold disabled:opacity-40",title:"Dispatch this workstream now (single run)",children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(Ir,{className:"h-3.5 w-3.5 opacity-85"}),e.jsx("span",{children:"Play"})]})}),e.jsx("button",{type:"button",disabled:N,onClick:()=>void q(k,()=>F?te({initiativeId:E.initiativeId}):L({initiativeId:E.initiativeId,workstreamId:E.workstreamId,agentId:E.runnerAgentId}),F?`Stopped auto-continue for ${E.initiativeTitle}.`:`Auto-continue started for ${E.workstreamTitle}.`),className:"control-pill col-span-2 flex h-8 w-full items-center justify-center px-2 text-[10px] font-semibold disabled:opacity-40 sm:col-span-1","data-state":F?"active":"idle","data-tone":"teal",title:F?"Stop auto-continue for this initiative":"Auto-continue this workstream",children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(Mr,{className:"h-3.5 w-3.5 opacity-85"}),e.jsx("span",{children:F?"Stop auto":"Auto"})]})})]})]},k)})})]}),p.length>0&&e.jsxs("div",{className:"border-t border-white/[0.06] px-3 py-2 text-[10px] text-white/42",children:["Limited signal: ",p[0]]})]})}function $r(t){const s=(t??"").toLowerCase();return s==="completed"||s==="done"?"completed":s==="blocked"||s==="at_risk"?"blocked":s==="paused"||s==="hold"?"paused":"active"}function Tr(t){const s=(t??"").toLowerCase();return!["deleted","archived","cancelled"].includes(s)}function Dr(t){return{id:t.id,name:t.title,status:$r(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 Or(t){return Ve({queryKey:rt.liveInitiatives({limit:300}),queryFn:async()=>{const s=await fetch("/orgx/api/live/initiatives?limit=300");return s.ok?((await s.json()).initiatives??[]).filter(n=>Tr(n.status)).map(Dr):[]},enabled:t,staleTime:3e4})}function Br(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 Pr(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 Rr(t){return t==="awaiting_browser_auth"||t==="pairing"||t==="starting"?"active":t==="error"?"error":t==="connected"?"active":"idle"}const Rs={idle:"bg-white/40",active:"bg-[#BFFF00]",error:"bg-red-400"};function zr({state:t,isStarting:s,isSubmittingManual:i,onRefresh:n,onStartPairing:r,onSubmitManualKey:o,onBackToPairing:d,onUseManualKey:l,onDisconnect:v}){const u=t.status==="manual_key",y=t.status==="awaiting_browser_auth"||t.status==="pairing",m=Rr(t.status),g=m==="active"&&t.status!=="connected",x=!!t.lastError,j=a.useMemo(()=>t.status==="connected"&&t.connectionVerified?"Live sync active.":y?"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.",[y,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-[15px] font-semibold text-white",children:"OrgX connection"}),e.jsx("p",{className:"mt-1 text-[12px] leading-relaxed text-white/55",children:j}),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:[g&&e.jsx("span",{className:`absolute inline-flex h-full w-full animate-ping rounded-full ${Rs[m]} opacity-40`}),e.jsx("span",{className:`relative inline-flex h-2 w-2 rounded-full ${Rs[m]}`})]}),e.jsx("span",{className:"text-white/80",children:Br(t.status)})]}),t.workspaceName&&e.jsx("span",{className:"chip",children:t.workspaceName}),t.keySource&&t.keySource!=="none"&&e.jsx("span",{className:"chip",children:Pr(t.keySource)}),t.hasApiKey&&!t.connectionVerified&&e.jsx("span",{className:"chip text-amber-100/90",children:"key present, not verified"})]})]}),x&&e.jsx("div",{className:"mb-4 rounded-xl border border-rose-300/20 bg-rose-400/10 p-4 text-[12px] text-rose-100",children:t.lastError}),u?e.jsx(en,{isSubmitting:i,onSubmit:o,onBack:d}):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:()=>{r()},disabled:s,"data-modal-autofocus":"true",className:"inline-flex items-center gap-2 rounded-full bg-[#BFFF00] px-4 py-2 text-[12px] 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-white/[0.12] bg-white/[0.03] px-4 py-2 text-[12px] font-semibold text-white/70 transition-colors hover:bg-white/[0.06]",children:"Use API key"}),t.hasApiKey&&e.jsx("button",{type:"button",onClick:()=>{v()},className:"rounded-full border border-rose-300/25 bg-rose-400/10 px-4 py-2 text-[12px] font-semibold text-rose-100/90 transition-colors hover:bg-rose-400/15",children:"Disconnect"}),e.jsx("button",{type:"button",onClick:()=>{n()},className:ge("rounded-full border border-white/[0.12] bg-white/[0.03] px-4 py-2 text-[12px] font-semibold text-white/70 transition-colors hover:bg-white/[0.06]",s&&"opacity-60"),children:"Refresh status"}),e.jsx("a",{href:"https://www.useorgx.com/settings",target:"_blank",rel:"noreferrer",className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-4 py-2 text-[12px] font-semibold text-white/70 transition-colors hover:bg-white/[0.06]",title:"Manage keys and workspace settings at useorgx.com",children:"Open OrgX settings"})]}),t.connectUrl&&(y||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-[11px] uppercase tracking-[0.1em] text-[#D8FFA1]",children:"Pairing pending"}),e.jsx("p",{className:"mt-1 text-[12px] leading-relaxed text-white/65",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-[11px] font-semibold text-[#D8FFA1]",children:"Approve in browser"}),t.expiresAt&&e.jsxs("span",{className:"text-[11px] text-white/40",children:["Expires ",new Date(t.expiresAt).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})]})]})]})]}),e.jsxs("div",{className:"mt-4 rounded-2xl border border-white/[0.06] bg-white/[0.02] p-4",children:[e.jsx("p",{className:"text-[12px] font-semibold text-white/80",children:"Key guidance"}),e.jsxs("p",{className:"mt-1 text-[12px] leading-relaxed text-white/45",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."]})]})]})}const dn=[{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 zs(t){return t==="openai"?"openaiApiKey":t==="anthropic"?"anthropicApiKey":"openrouterApiKey"}function qr(t){var s;return((s=dn.find(i=>i.id===t))==null?void 0:s.label)??t}function Ur({authToken:t=null,embedMode:s=!1,enabled:i=!0}){const n=sn({authToken:t,embedMode:s,enabled:i}),r=n.status,o=n.health,[d,l]=a.useState({openai:"",anthropic:"",openrouter:""}),[v,u]=a.useState({openai:!1,anthropic:!1,openrouter:!1}),[y,m]=a.useState({openai:!1,anthropic:!1,openrouter:!1}),[g,x]=a.useState(null),[j,p]=a.useState(null);a.useEffect(()=>{i&&(l({openai:"",anthropic:"",openrouter:""}),u({openai:!1,anthropic:!1,openrouter:!1}),m({openai:!1,anthropic:!1,openrouter:!1}),x(null),p(null))},[i]);const M=a.useMemo(()=>r!=null&&r.ok?Number(r.providers.openai.configured)+Number(r.providers.anthropic.configured)+Number(r.providers.openrouter.configured):0,[r]),D=async L=>{if(!i)return;p(null);const te=d[L].trim();if(!v[L])return;if(!te){p(`Enter a ${qr(L)} API key or use "Clear" to remove the saved key.`);return}const ee=zs(L);try{x(L),await n.update({[ee]:te}),u(q=>({...q,[L]:!1})),l(q=>({...q,[L]:""})),m(q=>({...q,[L]:!1}))}finally{x(null)}},O=async L=>{p(null);const te=zs(L);try{x(L),await n.update({[te]:null}),u(ee=>({...ee,[L]:!1})),l(ee=>({...ee,[L]:""})),m(ee=>({...ee,[L]:!1}))}finally{x(null)}},H=async()=>{p(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-[15px] font-semibold text-white",children:"Provider keys"}),e.jsx("p",{className:"mt-1 text-[12px] leading-relaxed text-white/55",children:"Bring your own provider keys. Keys are stored locally and used for OpenClaw agent launches."}),M===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-[11px] 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:[M," / 3 configured"]}),(r==null?void 0:r.updatedAt)&&e.jsxs("span",{className:"text-[11px] text-white/35",children:["Updated ",new Date(r.updatedAt).toLocaleString()]})]})]}),(j||n.error)&&e.jsx("div",{className:"mb-4 rounded-xl border border-rose-300/20 bg-rose-400/10 p-4 text-[12px] text-rose-100",children:j??n.error}),e.jsxs("div",{className:"mb-4 rounded-2xl border border-white/[0.06] bg-white/[0.02] p-4",children:[e.jsx("p",{className:"text-[12px] font-semibold text-white/80",children:"Where keys come from"}),e.jsxs("p",{className:"mt-1 text-[12px] leading-relaxed text-white/45",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:dn.map(L=>{var I,S;const te=(I=r==null?void 0:r.providers)==null?void 0:I[L.id],ee=(S=o==null?void 0:o.providers)==null?void 0:S[L.id],q=(te==null?void 0:te.masked)??null,E=(te==null?void 0:te.source)??"none",ae=E==="stored",k=g===L.id,N=v[L.id]&&d[L.id].trim().length>0&&!n.isSaving&&!k,F=ae&&!n.isSaving&&!k,z=ae?"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-[13px] font-semibold text-white",children:L.label}),e.jsx("span",{className:ge("rounded-full border px-2 py-0.5 text-[10px] uppercase tracking-[0.12em]",te!=null&&te.configured?"border-emerald-300/25 bg-emerald-400/10 text-emerald-100":"border-white/[0.12] bg-white/[0.03] text-white/55"),children:te!=null&&te.configured?"Configured":"Missing"})]}),e.jsxs("p",{className:"mt-1 text-[12px] text-white/45",children:[L.hint," ",e.jsxs("span",{className:"text-white/30",children:["Env: ",e.jsx("code",{className:"rounded bg-black/40 px-1",children:L.envVar})]})]}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[E!=="none"&&e.jsxs("span",{className:"chip",children:["source: ",E]}),q&&e.jsxs("span",{className:"chip",children:["key: ",q]}),ee&&e.jsx("span",{className:ge("chip",ee.ok?"text-emerald-100":"text-rose-100"),children:ee.ok?`ready (${ee.modelCount??0} models)`:"not ready"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>m($=>({...$,[L.id]:!$[L.id]})),className:"rounded-lg border border-white/[0.12] bg-white/[0.03] px-3 py-1.5 text-[11px] font-semibold text-white/70 transition-colors hover:bg-white/[0.08]",title:y[L.id]?"Hide key":"Show key",children:y[L.id]?"Hide":"Show"}),e.jsx("button",{type:"button",onClick:()=>void H(),className:"rounded-lg border border-white/[0.12] bg-white/[0.03] px-3 py-1.5 text-[11px] font-semibold text-white/70 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-[11px] font-medium uppercase tracking-[0.14em] text-white/40",children:"API key (stored locally)"}),e.jsx("input",{value:d[L.id],onChange:$=>{l(U=>({...U,[L.id]:$.target.value})),u(U=>({...U,[L.id]:!0})),j&&p(null)},type:y[L.id]?"text":"password",placeholder:`Paste ${L.label} key`,className:"w-full rounded-xl border border-white/[0.08] bg-black/30 px-3 py-2.5 font-mono text-[12px] text-white/80 placeholder:text-white/20 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 D(L.id),disabled:!N,className:"rounded-full bg-[#BFFF00] px-4 py-2 text-[12px] font-semibold text-black transition-colors hover:bg-[#d3ff42] disabled:cursor-not-allowed disabled:opacity-40",children:k?"Saving...":z}),e.jsx("button",{type:"button",onClick:()=>void O(L.id),disabled:!F,className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-4 py-2 text-[12px] font-semibold text-white/70 transition-colors hover:bg-white/[0.06] disabled:cursor-not-allowed disabled:opacity-35",children:"Clear stored"}),e.jsx("span",{className:"text-[11px] text-white/40",children:v[L.id]?"Unsaved changes":" "})]})]})]},L.id)})})]})}function Wr({open:t,onClose:s,activeTab:i,onChangeTab:n,onboarding:r,authToken:o=null,embedMode:d=!1}){return e.jsx(pt,{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-white/[0.06] 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-[15px] font-semibold text-white",children:"Settings"}),e.jsx("p",{className:"mt-1 text-[12px] leading-relaxed text-white/55",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-white/[0.12] bg-white/[0.03] text-white/70 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 v=i===l.id;return e.jsx("button",{type:"button",role:"tab","aria-selected":v,onClick:()=>n(l.id),className:ge("rounded-full px-3 py-1.5 text-[11px] font-semibold transition-colors",v?"border border-lime/25 bg-lime/[0.14] text-lime shadow-[0_0_16px_rgba(191,255,0,0.08)]":"border border-transparent text-white/60 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:i==="orgx"?e.jsx(zr,{state:r.state,isStarting:r.isStarting,isSubmittingManual:r.isSubmittingManual,onRefresh:r.refreshStatus,onStartPairing:r.startPairing,onSubmitManualKey:r.submitManualKey,onBackToPairing:r.backToPairing,onUseManualKey:r.setManualMode,onDisconnect:r.disconnect}):e.jsx(Ur,{authToken:o,embedMode:d,enabled:t})}),e.jsx("div",{className:"w-full border-t border-white/[0.06] px-5 py-2.5 sm:px-6",children:e.jsx(tn,{compact:!0})})]})})}const Kr=a.lazy(async()=>({default:(await qt(()=>import("./BgsfM2lz.js"),__vite__mapDeps([0,1,2,3,4]))).MissionControlView})),Vr=a.lazy(async()=>({default:(await qt(()=>import("./DEuY_RBN.js"),__vite__mapDeps([5,1,2,3,4]))).SessionInspector})),qs={connected:"Live",reconnecting:"Reconnecting",disconnected:"Offline"},Hr={connected:f.lime,reconnecting:f.amber,disconnected:f.red},cs="orgx.mission_control.welcome.dismissed",ds="orgx.demo_mode",us="orgx.first_run_guide.shown_session",Us={blocked:0,pending:1,queued:2,running:3,failed:4,cancelled:5,completed:6,archived:7};function We(t){if(!t)return 0;const s=Date.parse(t);return Number.isFinite(s)?s:0}function Gr(t){const s=We(t);if(!s)return"unknown";try{return new Date(s).toLocaleString()}catch{return"unknown"}}function ps(t,s){const i=Us[t.status]??99,n=Us[s.status]??99;return i!==n?i-n:We(t.updatedAt??t.lastEventAt??t.startedAt)-We(s.updatedAt??s.lastEventAt??s.startedAt)}function Xr(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 Qr(){const t=Pn();return t.showGate?e.jsx(si,{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(ea,{onboarding:t})}function Jr(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 Yr(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 Ws(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 Ks(t){const s=(t??"").trim().toLowerCase();return s?!["deleted","archived","cancelled"].includes(s):!0}function Zr(){return e.jsx("span",{className:"inline-flex h-6 w-6 items-center justify-center rounded-lg border border-white/[0.12] bg-white/[0.04] p-0.5",children:e.jsx("img",{src:Kt,alt:"OrgX",className:"h-full w-full rounded-md object-contain"})})}function ea({onboarding:t}){const[s,i]=a.useState(()=>{if(typeof window>"u")return!1;if(new URLSearchParams(window.location.search).get("demo")==="1")return!0;try{return window.localStorage.getItem(ds)==="1"}catch{return!1}}),n=s||t.state.hasApiKey&&t.state.connectionVerified,{data:r,isLoading:o,error:d,refetch:l,approveDecision:v,approveAllDecisions:u}=Ln({useMock:s,enabled:!0,enableDecisions:n}),y=n&&r.connection==="connected",[m,g]=a.useState(null),[x,j]=a.useState(!1),[p,M]=a.useState(null),[D,O]=a.useState(null),[H,L]=a.useState(null),[te,ee]=a.useState(null),[q,E]=a.useState(null),[ae,k]=a.useState(!1),[N,F]=a.useState([]),z=a.useRef(null),I=a.useRef(null),[S,$]=a.useState({open:!1,tab:"orgx"}),[U,fe]=a.useState(!1),[be,Z]=a.useState("agents"),[G,T]=a.useState("decisions"),[C,Y]=a.useState(()=>typeof window>"u"?!1:window.localStorage.getItem(cs)==="1");a.useEffect(()=>{typeof window>"u"||(C?window.localStorage.setItem(cs,"1"):window.localStorage.removeItem(cs))},[C]),a.useEffect(()=>{if(!(typeof window>"u"))try{s?window.localStorage.setItem(ds,"1"):window.localStorage.removeItem(ds)}catch{}},[s]),a.useEffect(()=>{if(!(typeof window>"u")&&!U&&!ii()){try{if(window.sessionStorage.getItem(us)==="1")return}catch{}if(s||t.state.connectionVerified){fe(!0);try{window.sessionStorage.setItem(us,"1")}catch{}}}},[s,U,t.state.connectionVerified]);const re=a.useCallback(c=>{$(B=>({open:!0,tab:c??B.tab}))},[]),K=a.useCallback(()=>{re("orgx")},[re]),Se=a.useCallback(()=>{qt(()=>import("./BgsfM2lz.js"),__vite__mapDeps([0,1,2,3,4]))},[]),[he,we]=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"}),je=a.useCallback(c=>{we(c);try{localStorage.setItem("orgx-dashboard-view",c)}catch{}},[]),{data:w}=rn(he==="mission-control"),{data:R}=Or(he==="mission-control"),{data:ce=[]}=Ve({queryKey:["initiative-tombstones"],queryFn:async()=>[],initialData:[],staleTime:Number.POSITIVE_INFINITY}),[X,ke]=a.useState(null),[A,W]=a.useState(""),[oe,ue]=a.useState(!1),se=a.useCallback((c,B)=>{ke({type:c,initiativeId:B}),W(""),ue(!1)},[]),le=a.useCallback(()=>{ke(null),W(""),ue(!1)},[]),xe=a.useCallback(()=>{M(null)},[]),Le=a.useCallback(()=>{O(null),L(null)},[]);a.useEffect(()=>{var Q;const c=((Q=r.sessions.nodes[0])==null?void 0:Q.id)??null;if(!c){m!==null&&g(null);return}if(m===null){g(c);return}r.sessions.nodes.some(b=>b.id===m)||g(c)},[r.sessions.nodes,m]),a.useEffect(()=>{if(!p)return;r.sessions.nodes.some(B=>B.id===p)||M(null)},[p,r.sessions.nodes]);const V=a.useCallback(c=>{qt(()=>import("./DEuY_RBN.js"),__vite__mapDeps([5,1,2,3,4])),g(c),j(!0),M(c),O(null),L(null)},[]),ot=a.useCallback(c=>{const B=c.trim();if(!B)return;const Q=r.sessions.nodes.find(b=>b.runId===B||b.id===B)??null;Q&&(V(Q.id),E(`Focused session: ${Q.title}`))},[r.sessions.nodes,V]),Be=a.useMemo(()=>r.sessions.nodes.find(c=>c.id===p)??null,[p,r.sessions.nodes]),Ie=a.useMemo(()=>r.sessions.nodes.find(c=>c.id===m)??null,[r.sessions.nodes,m]),Je=a.useMemo(()=>r.sessions.nodes.filter(c=>["running","queued","pending"].includes(c.status)).length,[r.sessions.nodes]),Ye=a.useMemo(()=>r.sessions.nodes.filter(c=>c.status==="blocked"||c.blockers.length>0).length,[r.sessions.nodes]),ze=a.useMemo(()=>r.sessions.nodes.filter(c=>c.status==="failed").length,[r.sessions.nodes]),Ze=a.useMemo(()=>{const c=[{id:"sessions",label:"Sessions",value:r.sessions.nodes.length,color:f.teal},{id:"active",label:"Active",value:Je,color:Je>0?f.lime:f.textMuted},{id:"blocked",label:"Blocked",value:Ye,color:Ye>0?f.red:f.textMuted},{id:"failed",label:"Failed",value:ze,color:ze>0?f.red:f.textMuted},{id:"decisions",label:"Decisions",value:y?r.decisions.length:0,color:y&&r.decisions.length>0?f.amber:f.textMuted},{id:"outbox",label:"Outbox",value:r.outbox.pendingTotal,color:r.outbox.replayStatus==="error"?f.red:r.outbox.pendingTotal>0?f.amber:f.textMuted}];return r.handoffs.length>0&&c.push({id:"handoffs",label:"Handoffs",value:r.handoffs.length,color:f.iris}),c},[Je,Ye,ze,r.decisions.length,r.handoffs.length,r.outbox.pendingTotal,r.outbox.replayStatus,r.sessions.nodes.length,y]),lt=a.useMemo(()=>r.decisions.length>0?Math.max(0,...r.decisions.map(c=>c.waitingMinutes)):0,[r.decisions]),He=a.useMemo(()=>{const c=[];return d&&c.push({id:`stream-error:${d}`,kind:"error",icon:"notification",title:"Live stream degraded",message:d,actionLabel:"Settings",onAction:()=>re("orgx")}),r.connection!=="connected"&&c.push({id:`connection:${r.connection}`,kind:r.connection==="disconnected"?"error":"info",icon:"notification",title:r.connection==="disconnected"?"Connection lost":"Reconnecting",message:r.connection==="disconnected"?"Dashboard is offline. Some data may be stale.":"Live data is recovering. Some sections may be delayed.",actionLabel:"Reconnect",onAction:K}),r.outbox.pendingTotal>0&&c.push({id:`outbox:pending:${r.outbox.pendingTotal}`,kind:"info",icon:"notification",title:"Buffered updates pending",message:`${r.outbox.pendingTotal} event(s) queued for replay.`}),r.outbox.replayStatus==="error"&&r.outbox.lastReplayError&&c.push({id:`outbox:error:${r.outbox.lastReplayError}`,kind:"error",icon:"notification",title:"Outbox replay failed",message:r.outbox.lastReplayError,actionLabel:"Settings",onAction:()=>re("orgx")}),q&&c.push({id:`ops:${q}`,kind:"info",icon:/decision/i.test(q)?"decision":"workstream",title:"Update",message:q}),c},[r.connection,r.outbox.lastReplayError,r.outbox.pendingTotal,r.outbox.replayStatus,d,K,re,q]);a.useEffect(()=>{const c=new Set(He.map(B=>B.id));F(B=>B.filter(Q=>c.has(Q)))},[He]);const qe=a.useMemo(()=>He.filter(c=>!N.includes(c.id)),[N,He]),Nt=a.useCallback(c=>{F(B=>B.includes(c)?B:B.concat(c))},[]),Ge=a.useCallback(()=>{F(He.map(c=>c.id))},[He]);a.useEffect(()=>{if(!ae)return;const c=Q=>{var ne,pe;const b=Q.target;b&&((ne=I.current)!=null&&ne.contains(b)||(pe=z.current)!=null&&pe.contains(b)||k(!1))},B=Q=>{Q.key==="Escape"&&k(!1)};return document.addEventListener("mousedown",c),document.addEventListener("touchstart",c),document.addEventListener("keydown",B),()=>{document.removeEventListener("mousedown",c),document.removeEventListener("touchstart",c),document.removeEventListener("keydown",B)}},[ae]);const De=a.useMemo(()=>{var Q;const c=new Map;for(const b of r.sessions.nodes){const ne=b.initiativeId??b.groupId??"unscoped",pe=b.groupLabel&&b.groupLabel.trim().length>0?b.groupLabel:b.initiativeId??"Unscoped Initiative",Ce=Jr(pe),me=c.get(ne)??{id:ne,name:pe,category:Ce,progressTotal:0,progressCount:0,statusCounts:{},activeAgents:new Set,allAgents:new Set,workstreams:new Map,latestEpoch:0};if(b.progress!==null&&(me.progressTotal+=b.progress,me.progressCount+=1),me.statusCounts[b.status]=(me.statusCounts[b.status]??0)+1,b.agentName&&(me.allAgents.add(b.agentName),["running","queued","pending","blocked"].includes(b.status)&&me.activeAgents.add(b.agentName)),b.workstreamId){const _e=r.sessions.groups.find(Xe=>Xe.id===b.workstreamId),Pe=((Q=_e==null?void 0:_e.label)==null?void 0:Q.trim())||b.workstreamId;me.workstreams.set(b.workstreamId,Pe)}me.latestEpoch=Math.max(me.latestEpoch,We(b.updatedAt??b.lastEventAt??b.startedAt)),c.set(ne,me)}const B=[];for(const b of c.values()){const ne=b.progressCount>0?Math.round(b.progressTotal/b.progressCount):b.statusCounts.completed?100:b.statusCounts.running?55:0,pe=b.category,Ce=Yr(pe),me=Math.round(Math.max(0,Math.min(100,ne))/100*(Ce.length-1)),_e=(b.statusCounts.blocked??0)>0,Pe=(b.statusCounts.completed??0)>0&&(b.statusCounts.running??0)===0&&(b.statusCounts.queued??0)===0&&(b.statusCounts.pending??0)===0&&(b.statusCounts.blocked??0)===0&&(b.statusCounts.paused??0)===0,Xe=!Pe&&!_e&&(b.statusCounts.paused??0)>0&&(b.statusCounts.running??0)===0&&(b.statusCounts.queued??0)===0&&(b.statusCounts.pending??0)===0,un=Ce.map((Gt,Ct)=>{let Xt="upcoming";return(Pe||Ct<me)&&(Xt="completed"),Ct===me&&!Pe&&(Xt=_e?"warning":"current"),{name:Gt,status:Xt}});B.push({id:b.id,name:b.name,status:Pe?"completed":_e?"blocked":Xe?"paused":"active",rawStatus:Pe?"completed":_e?"blocked":Xe?"paused":"active",category:pe,health:Math.max(0,Math.min(100,ne)),phases:un,currentPhase:Pe?Ce.length-1:me,daysRemaining:0,targetDate:null,createdAt:b.latestEpoch>0?new Date(b.latestEpoch).toISOString():null,updatedAt:b.latestEpoch>0?new Date(b.latestEpoch).toISOString():null,activeAgents:b.activeAgents.size,totalAgents:b.allAgents.size,avatars:Array.from(b.activeAgents).slice(0,3),description:`${b.workstreams.size} workstreams are active right now.`,workstreams:Array.from(b.workstreams.entries()).map(([Gt,Ct])=>({id:Gt,name:Ct,status:"active"}))})}return B.sort((b,ne)=>{const pe=b.status==="blocked"?0:b.status==="active"?1:2,Ce=ne.status==="blocked"?0:ne.status==="active"?1:2;return pe!==Ce?pe-Ce:ne.health-b.health})},[r.sessions.nodes,r.sessions.groups]),h=a.useMemo(()=>{const c=(b,ne)=>{var pe,Ce;return{...b,...ne,health:ne.health>0?ne.health:b.health,activeAgents:Math.max(b.activeAgents,ne.activeAgents),totalAgents:Math.max(b.totalAgents,ne.totalAgents),avatars:(pe=b.avatars)!=null&&pe.length?b.avatars:ne.avatars,workstreams:(Ce=b.workstreams)!=null&&Ce.length?b.workstreams:ne.workstreams,description:b.description??ne.description,rawStatus:ne.rawStatus??b.rawStatus??null,targetDate:ne.targetDate??b.targetDate??null,createdAt:ne.createdAt??b.createdAt??null,updatedAt:ne.updatedAt??b.updatedAt??null}},B=new Map;for(const b of De)B.set(b.id,b);for(const b of[...R??[],...w??[]]){const ne=b.rawStatus??b.status;if(!Ks(ne)){B.delete(b.id);continue}const pe=B.get(b.id);B.set(b.id,pe?c(pe,b):b)}const Q=new Set(ce);return Array.from(B.values()).filter(b=>!Q.has(b.id)).filter(b=>Ks(b.rawStatus??b.status)).sort((b,ne)=>{const pe=Xe=>Xe==="blocked"?0:Xe==="active"?1:Xe==="paused"?2:3,Ce=pe(b.status)-pe(ne.status);if(Ce!==0)return Ce;const me=Ws(b.priority)-Ws(ne.priority);if(me!==0)return me;const _e=We(ne.updatedAt)-We(b.updatedAt);if(_e!==0)return _e;const Pe=ne.health-b.health;return Pe!==0?Pe:b.name.localeCompare(ne.name)})},[De,w,R,ce]),P=a.useMemo(()=>{if(!Be)return null;const c=Be.agentName,B=Be.title;if(c){const Q=r.activity.find(b=>{var ne;return b.runId===Be.runId&&((ne=b.summary)==null?void 0:ne.trim())});if(Q!=null&&Q.summary){const b=Q.summary.trim().length>40?Q.summary.trim().slice(0,40)+"…":Q.summary.trim();return`${c}: ${b}`}return c}if(B){const Q=B.replace(/^(telegram|slack|discord|whatsapp|email|sms):/,"").trim();if(Q.length>0)return Q}return B??null},[r.activity,Be]),_=a.useMemo(()=>{const c=new Map;for(const B of r.sessions.nodes){const Q=(B.agentId??"").trim()||`name:${(B.agentName??"").trim()}`,b=(B.agentName??"").trim()||(B.agentId??"").trim();if(!b)continue;const ne=B.updatedAt??B.lastEventAt??B.startedAt??new Date().toISOString(),pe=We(ne),Ce=pe?Math.max(0,Math.floor((Date.now()-pe)/6e4)):0,me=c.get(Q),_e={id:Q,name:b,role:"Agent",status:Xr(B.status),task:B.title??null,progress:B.progress??null,lastActive:ne,lastActiveMinutes:Ce};(!me||We(_e.lastActive)>We(me.lastActive))&&c.set(Q,_e)}return Array.from(c.values())},[r.sessions.nodes]),J=t.state.connectionVerified&&!C,ie=a.useCallback(async()=>{if(r.sessions.nodes.length===0){E("No sessions available to continue.");return}const c=[...r.sessions.nodes].sort(ps)[0];if(g(c.id),M(c.id),O(null),L(null),["blocked","pending","queued"].includes(c.status))try{await fetch(`/orgx/api/runs/${encodeURIComponent(c.runId)}/actions/resume`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({reason:"continue_from_dashboard"})})}catch{}E(`Focused highest priority session: ${c.title}`),await l()},[r.sessions.nodes,l]),ye=a.useCallback(async c=>{if(g(c.id),M(c.id),O(null),L(null),!["running","completed","archived"].includes(c.status))try{await fetch(`/orgx/api/runs/${encodeURIComponent(c.runId)}/actions/resume`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({reason:"dispatch_from_dashboard"})})}catch{}E(`Dispatch requested: ${c.title}`),await l()},[l]),ve=a.useCallback(async(c,B,Q={})=>{const b=await fetch(`/orgx/api/runs/${encodeURIComponent(c.runId)}/actions/${B}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Q)});if(!b.ok){const ne=await b.json().catch(()=>null);throw new Error((ne==null?void 0:ne.error)??`${B} failed (${b.status})`)}},[]),Ee=a.useCallback(async c=>{var ne;const B=await fetch(`/orgx/api/runs/${encodeURIComponent(c.runId)}/checkpoints`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({reason:"dashboard_manual_checkpoint"})});if(!B.ok){const pe=await B.json().catch(()=>null);throw new Error((pe==null?void 0:pe.error)??`Checkpoint creation failed (${B.status})`)}const Q=await B.json().catch(()=>null),b=Q&&"data"in Q&&((ne=Q.data)==null?void 0:ne.id)||Q&&"id"in Q&&Q.id||null;E(b?`Checkpoint created: ${b.slice(0,8)}`:"Checkpoint created."),await l()},[l]),et=a.useCallback(async c=>{await ve(c,"pause",{reason:"pause_from_dashboard"}),E(`Pause requested: ${c.title}`),await l()},[l,ve]),ht=a.useCallback(async c=>{await ve(c,"resume",{reason:"resume_from_dashboard"}),E(`Resume requested: ${c.title}`),await l()},[l,ve]),xt=a.useCallback(async c=>{await ve(c,"cancel",{reason:"cancel_from_dashboard"}),E(`Cancel requested: ${c.title}`),await l()},[l,ve]),St=a.useCallback(async c=>{var Ce;const B=await fetch(`/orgx/api/runs/${encodeURIComponent(c.runId)}/checkpoints`,{method:"GET"});if(!B.ok){const me=await B.json().catch(()=>null);throw new Error((me==null?void 0:me.error)??`Checkpoint list failed (${B.status})`)}const Q=await B.json().catch(()=>null),pe=(Ce=(Array.isArray(Q)?Q:Array.isArray(Q==null?void 0:Q.data)?Q.data:[]).map(me=>({id:typeof me.id=="string"?me.id:"",createdAt:typeof me.createdAt=="string"?me.createdAt:typeof me.created_at=="string"?me.created_at:""})).filter(me=>me.id.length>0).sort((me,_e)=>Date.parse(_e.createdAt)-Date.parse(me.createdAt))[0])==null?void 0:Ce.id;if(!pe)throw new Error("No checkpoint available for rollback.");await ve(c,"rollback",{checkpointId:pe,reason:"rollback_from_dashboard"}),E(`Rollback requested for ${c.title}.`),await l()},[l,ve]),mt=a.useCallback(async()=>{var Q;if(!X||A.trim().length===0||oe)return;ue(!0);const c=X.type,B=A.trim();try{const b={type:c,title:B,status:"active"};if(c==="workstream"){const pe=X.initiativeId??(Ie==null?void 0:Ie.initiativeId)??((Q=De[0])==null?void 0:Q.id)??null;if(!pe){E("Select an initiative first to start a workstream."),ue(!1);return}b.initiative_id=pe,b.parentId=pe}const ne=await fetch("/orgx/api/entities",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(b)});if(!ne.ok){const pe=await ne.json().catch(()=>null);throw new Error((pe==null?void 0:pe.error)??`Failed to create ${c}.`)}E(`Created ${c}: ${B}`),le(),await l()}catch(b){E(b instanceof Error?b.message:`Failed to create ${c}.`),ue(!1)}},[le,oe,X,A,De,l,Ie==null?void 0:Ie.initiativeId]),ft=a.useCallback(()=>{se("initiative")},[se]),tt=a.useCallback(c=>{se("workstream",c)},[se]);a.useCallback(()=>{var c;return tt((Ie==null?void 0:Ie.initiativeId)??((c=De[0])==null?void 0:c.id)??null)},[De,Ie==null?void 0:Ie.initiativeId,tt]);const ct=a.useCallback(c=>{const B=[...r.sessions.nodes].filter(Q=>(Q.initiativeId??Q.groupId)===c.id).sort(ps)[0];B&&(g(B.id),M(B.id),O(null),L(null),E(`Focused initiative: ${c.name}`))},[r.sessions.nodes]),gt=a.useCallback(c=>{M(null),O(c.workstreamId),L(c.workstreamTitle),ee(null),je("activity"),E(`Following workstream: ${c.workstreamTitle}`)},[je]),Vt=a.useCallback(c=>{const B=De.find(Q=>Q.id===c)??h.find(Q=>Q.id===c)??null;B&&ct(B)},[ct,De,h]),dt=a.useCallback(c=>{const B=new Set(c),Q=[...r.sessions.nodes].filter(b=>B.has(b.status)).sort(ps)[0];if(!Q){E("No matching sessions for that metric right now.");return}V(Q.id),Z("activity")},[r.sessions.nodes,V]),Ht=a.useCallback(c=>{if(he==="activity"){if(c==="sessions"){ee(null),M(null),O(null),L(null),Z("agents");return}if(c==="active"){dt(["running","active","queued","pending","in_progress"]);return}if(c==="blocked"){dt(["blocked"]);return}if(c==="failed"){dt(["failed"]);return}if(c==="decisions"){T("decisions"),Z("decisions");return}if(c==="outbox"){re("orgx");return}c==="handoffs"&&Z("agents")}},[he,dt,re]);return o?e.jsxs("div",{className:"flex min-h-screen flex-col lg:h-screen",style:{backgroundColor:f.background},children:[e.jsxs("div",{className:"border-b border-white/[0.06] 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((c,B)=>e.jsx("div",{className:"shimmer-skeleton h-7 w-24 rounded-full"},B))})]}),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:f.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-white/[0.12] bg-white/[0.06] px-4 py-2 text-[11px] text-white/80 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-white/60",children:"18789"}),"."]})}),e.jsxs("header",{className:"relative z-[180] border-b border-white/[0.06] 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(Zr,{}),e.jsxs("h1",{className:"text-[16px] font-semibold tracking-tight text-white sm:text-[17px]",children:["OrgX",e.jsx("span",{className:"ml-1.5 text-white/50",children:"Live"})]}),e.jsx(Ts,{color:Hr[r.connection],pulse:r.connection==="connected",title:[`Status: ${qs[r.connection]??r.connection}`,r.connection==="connected"?"Meaning: receiving live updates.":r.connection==="reconnecting"?"Meaning: retrying live stream (data may be stale).":"Meaning: offline (data is stale).",`Last snapshot: ${Gr(r.lastSnapshotAt)}`,d?`Error: ${d}`:null].filter(Boolean).join(`
212
+ `),children:qs[r.connection]??"Unknown"}),(r.outbox.pendingTotal>0||r.outbox.replayStatus==="error")&&e.jsx("div",{className:"hidden sm:block",children:e.jsxs(Ts,{color:r.outbox.replayStatus==="error"?f.red:f.amber,pulse:r.outbox.pendingTotal>0&&r.outbox.replayStatus!=="error",children:["Outbox ",r.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:()=>je("activity"),"aria-pressed":he==="activity",className:`rounded-full px-3 py-1 text-[12px] font-medium transition-all ${he==="activity"?"bg-white/[0.1] text-white":"text-white/55 hover:text-white/85"}`,children:"Activity"}),e.jsx("button",{type:"button",onClick:()=>je("mission-control"),onMouseEnter:Se,onFocus:Se,"aria-pressed":he==="mission-control",className:`rounded-full px-3 py-1 text-[12px] font-medium transition-all ${he==="mission-control"?"bg-white/[0.1] text-white":"text-white/55 hover:text-white/85"}`,children:"Mission Control"})]})}),e.jsxs("div",{className:"relative isolate flex items-center justify-end gap-1.5 sm:gap-2",children:[r.lastActivity&&e.jsxs("span",{className:"hidden text-[12px] text-white/45 xl:inline",children:["Last activity: ",r.lastActivity]}),r.outbox.pendingTotal>0&&e.jsxs("span",{className:"hidden text-[12px] text-white/45 xl:inline",children:["Replay: ",r.outbox.replayStatus]}),s&&e.jsx("button",{type:"button",onClick:()=>{i(!1),K()},className:"hidden rounded-full border border-amber-200/25 bg-amber-200/10 px-3 py-1.5 text-[11px] 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:z,onClick:()=>k(c=>!c),title:"Notifications","aria-haspopup":"dialog","aria-expanded":ae,"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-white/80 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"})]}),qe.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-[10px] font-semibold text-white",children:qe.length})]}),e.jsx("button",{type:"button",onClick:()=>re("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-white/80 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:()=>{fe(!0);try{window.sessionStorage.setItem(us,"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-white/80 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-[12px] text-white/80 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"})]}),ae&&e.jsxs("div",{id:"header-notifications-panel",ref:I,role:"dialog","aria-label":"Notifications",className:"absolute right-0 top-[calc(100%+8px)] z-[320] w-[min(92vw,380px)] rounded-2xl border border-white/[0.12] 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-[12px] font-semibold uppercase tracking-[0.12em] text-white/55",children:"Notifications"}),e.jsxs("div",{className:"flex items-center gap-2",children:[qe.length>0&&e.jsx("button",{type:"button",onClick:Ge,className:"text-[11px] text-white/45 transition-colors hover:text-white/80",children:"Dismiss all"}),e.jsx("button",{type:"button",onClick:()=>k(!1),className:"rounded-md px-1.5 py-0.5 text-[11px] text-white/45 transition-colors hover:bg-white/[0.08] hover:text-white/80","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:Ze.map(c=>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-[10px]",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full",style:{backgroundColor:c.color}}),e.jsx("span",{className:"uppercase tracking-[0.08em] text-white/45",children:c.label}),e.jsx("span",{className:"font-semibold text-white",style:{fontVariantNumeric:"tabular-nums"},children:c.value})]},c.id))}),qe.length===0?e.jsx("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.02] px-3 py-3 text-[12px] text-white/45",children:"Everything looks clear."}):e.jsx("div",{className:"space-y-1.5",children:qe.map(c=>e.jsx("div",{className:"rounded-xl border px-3 py-2",style:{borderColor:c.kind==="error"?"rgba(239,68,68,0.35)":"rgba(255,255,255,0.1)",backgroundColor:c.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-[12px] font-semibold",style:{color:c.kind==="error"?"#fecaca":"#e2e8f0"},children:[e.jsx(Me,{type:c.icon,size:12,className:"opacity-90"}),e.jsx("span",{className:"truncate",children:c.title})]}),e.jsx("p",{className:"mt-0.5 text-[12px] leading-snug text-white/65",children:c.message}),c.onAction&&e.jsx("button",{type:"button",onClick:()=>{var B;(B=c.onAction)==null||B.call(c),k(!1)},className:"mt-1.5 rounded-md border border-white/[0.12] bg-white/[0.05] px-2.5 py-1 text-[11px] font-medium text-white/75 transition-colors hover:bg-white/[0.1] hover:text-white",children:c.actionLabel??"View"})]}),e.jsx("button",{type:"button",onClick:()=>Nt(c.id),className:"shrink-0 rounded-md px-1.5 py-0.5 text-[11px] text-white/45 transition-colors hover:bg-white/[0.08] hover:text-white/80",title:"Dismiss",children:"Dismiss"})]})},c.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:()=>je("activity"),"aria-pressed":he==="activity",className:`flex-1 rounded-full px-3 py-1.5 text-[12px] font-medium transition-all ${he==="activity"?"bg-white/[0.1] text-white":"text-white/55 hover:text-white/85"}`,children:"Activity"}),e.jsx("button",{type:"button",onClick:()=>je("mission-control"),"aria-pressed":he==="mission-control",className:`flex-1 rounded-full px-3 py-1.5 text-[12px] font-medium transition-all ${he==="mission-control"?"bg-white/[0.1] text-white":"text-white/55 hover:text-white/85"}`,children:"Mission Control"})]})}),J&&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-[12px] 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:()=>je("mission-control"),onMouseEnter:Se,onFocus:Se,className:"rounded-full border border-[#BFFF00]/30 bg-[#BFFF00]/15 px-2.5 py-1 text-[11px] text-[#D8FFA1]",children:"Open"}),e.jsx("button",{type:"button",onClick:()=>Y(!0),className:"text-[11px] text-white/65 underline underline-offset-2",children:"Dismiss"})]})]})]}),he==="activity"&&e.jsx("div",{className:"flex items-center gap-1.5 overflow-x-auto border-b border-white/[0.06] px-4 py-1.5 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden sm:px-6",children:Ze.map(c=>e.jsxs("button",{type:"button",onClick:()=>Ht(c.id),className:"inline-flex shrink-0 items-center gap-1 rounded-full border border-white/[0.1] bg-white/[0.03] px-2 py-0.5 text-[10px] transition-colors hover:bg-white/[0.08]",title:`Focus ${c.label.toLowerCase()}`,children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full",style:{backgroundColor:c.color}}),e.jsx("span",{className:"font-semibold text-white",style:{fontVariantNumeric:"tabular-nums"},children:c.value}),e.jsx("span",{className:"uppercase tracking-[0.08em] text-white/45",children:c.label})]},c.id))}),he==="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-[12px] text-white/50",children:"Loading Mission Control…"}),children:e.jsx(Kr,{initiatives:h,activities:r.activity,agents:_,runtimeInstances:r.runtimeInstances??[],isLoading:o,authToken:null,embedMode:!1,connection:r.connection,lastSnapshotAt:r.lastSnapshotAt,error:d,hasApiKey:t.state.hasApiKey,onOpenSettings:()=>re("orgx"),onRefresh:l,onFollowWorkstream:gt})})}):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:[y&&r.decisions.length>0&&G!=="decisions"&&e.jsxs("button",{type:"button",onClick:()=>T("decisions"),className:ge("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]",r.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:r.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-[12px] font-medium ${r.decisions.length>=20?"text-red-200":"text-amber-200"}`,children:[r.decisions.length," decision",r.decisions.length===1?"":"s"," waiting",lt>0?` · longest: ${lt}m`:""]}),e.jsx("span",{className:`ml-auto text-[11px] ${r.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 ${be!=="agents"?"hidden lg:flex":""}`,children:e.jsx(Gi,{sessions:r.sessions,activity:r.activity,runtimeInstances:r.runtimeInstances??[],selectedSessionId:m,onSelectSession:V,onAgentFilter:ee,agentFilter:te,onReconnect:K,connectionStatus:r.connection})}),e.jsx("section",{className:`min-h-0 lg:col-span-6 lg:flex lg:flex-col lg:[&>section]:h-full ${be!=="activity"?"hidden lg:flex":""}`,children:e.jsx(Nr,{activity:r.activity,sessions:r.sessions.nodes,initiatives:De,selectedRunIds:Be?[Be.runId,Be.id]:[],selectedSessionLabel:P,selectedWorkstreamId:D,selectedWorkstreamLabel:H,agentFilter:te,onClearSelection:xe,onClearWorkstreamFilter:Le,onClearAgentFilter:()=>ee(null),onFocusRunId:ot})}),e.jsxs("section",{className:`flex min-h-0 flex-col gap-2 lg:col-span-3 lg:gap-2 ${be!=="decisions"&&be!=="initiatives"?"hidden lg:flex":""}`,children:[e.jsx("div",{className:`min-h-0 ${G==="initiatives"?"flex-1":"flex-shrink-0"} `,children:G==="initiatives"?e.jsx(Lr,{title:"Next Up",onFollowWorkstream:gt,onOpenInitiative:Vt}):e.jsx(at,{className:"card-enter",children:e.jsxs("button",{onClick:()=>T("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-[14px] font-semibold text-white",children:"Next Up"})}),e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"-rotate-90 text-white/40",children:e.jsx("path",{d:"m6 9 6 6 6-6"})})]})})}),e.jsx("div",{className:`min-h-0 ${G==="decisions"?"flex-1":"flex-shrink-0"} ${be==="initiatives"?"hidden lg:block":""}`,children:G==="decisions"?y?e.jsx(Sr,{decisions:r.decisions,onApproveDecision:v,onApproveAll:u}):e.jsxs(at,{className:"flex h-full min-h-[220px] flex-col card-enter",children:[e.jsxs("div",{className:"space-y-2 border-b border-white/[0.06] px-4 py-3.5",children:[e.jsx("h2",{className:"text-[14px] font-semibold text-white",children:"Decisions"}),e.jsx("p",{className:"text-[12px] text-white/45",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-[12px] text-white/45",children:"Connect OrgX to review and approve live decisions."}),e.jsx("button",{onClick:K,className:"rounded-md border border-lime/25 bg-lime/10 px-3 py-1.5 text-[11px] font-semibold text-lime transition-colors hover:bg-lime/20",children:"Connect OrgX"})]})]}):e.jsx(at,{className:"card-enter",children:e.jsxs("button",{onClick:()=>T("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-[14px] font-semibold text-white",children:"Decisions"}),y&&r.decisions.length>0&&e.jsx("span",{className:"chip text-[10px]",style:{borderColor:`${f.amber}44`,color:f.amber},children:r.decisions.length}),!y&&e.jsx("span",{className:"text-[10px] text-white/30",children:"disconnected"})]}),e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"-rotate-90 text-white/40",children:e.jsx("path",{d:"m6 9 6 6 6-6"})})]})})})]})]}),e.jsx(Te,{children:x&&Ie&&e.jsxs(e.Fragment,{children:[e.jsx(de.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:()=>j(!1)},"session-drawer-backdrop"),e.jsxs(de.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:f.cardBg},children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-white/[0.06] px-4 py-3",children:[e.jsx("h3",{className:"text-[13px] font-semibold text-white/70",children:"Session Detail"}),e.jsx("button",{type:"button",onClick:()=>j(!1),"aria-label":"Close session inspector",className:"inline-flex h-8 w-8 items-center justify-center rounded-full border border-white/[0.12] bg-white/[0.03] text-white/70 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-[12px] text-white/50",children:"Loading session detail…"}),children:e.jsx(Vr,{session:Ie,activity:r.activity,initiatives:De,onContinueHighestPriority:ie,onDispatchSession:ye,onPauseSession:et,onResumeSession:ht,onCancelSession:xt,onCreateCheckpoint:Ee,onRollbackSession:St,onStartInitiative:ft,onStartWorkstream:tt})})})]},"session-drawer-panel")]})}),e.jsx(li,{activeTab:be,onTabChange:Z,pendingDecisionCount:y?r.decisions.length:0}),e.jsx(pt,{open:X!==null,onClose:le,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-[15px] font-semibold text-white",children:(X==null?void 0:X.type)==="workstream"?"New Workstream":"New Initiative"}),e.jsx("p",{className:"mt-1 text-[12px] leading-relaxed text-white/45",children:(X==null?void 0:X.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-[11px] uppercase tracking-[0.1em] text-white/45",children:"Name"}),e.jsx("input",{value:A,onChange:c=>W(c.target.value),onKeyDown:c=>{c.key==="Enter"&&mt()},autoFocus:!0,"data-modal-autofocus":"true",placeholder:(X==null?void 0:X.type)==="workstream"?"e.g. User Onboarding Flow":"e.g. Q1 Product Launch",className:"w-full rounded-lg border border-white/[0.12] bg-black/30 px-3 py-2.5 text-[13px] text-white placeholder:text-white/30 focus:outline-none focus:ring-1 focus:ring-[#BFFF00]/40"})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 border-t border-white/[0.06] px-5 py-3",children:[e.jsx("button",{onClick:le,className:"rounded-md px-3 py-1.5 text-[12px] text-white/60 transition-colors hover:text-white",children:"Cancel"}),e.jsx("button",{onClick:mt,disabled:A.trim().length===0||oe,className:"rounded-md border border-lime/25 bg-lime/10 px-4 py-1.5 text-[12px] font-semibold text-lime transition-colors hover:bg-lime/20 disabled:opacity-45",children:oe?"Creating…":"Create"})]})]})}),e.jsx(Wr,{open:S.open,onClose:()=>$(c=>({...c,open:!1})),activeTab:S.tab,onChangeTab:c=>$(B=>({...B,tab:c})),onboarding:t,authToken:null,embedMode:!1}),e.jsx(ai,{open:U,onClose:()=>fe(!1),onOpenSettings:()=>re("providers"),onOpenOrgxSettings:()=>re("orgx"),onOpenMissionControl:()=>{je("mission-control"),fe(!1)},demoMode:s,connectionVerified:t.state.connectionVerified,hasSessions:r.sessions.nodes.length>0})]})}Hs.init("phc_s4KPgkYEFZgvkMYw4zXG41H5FN6haVwbEWPYHfNjxOc",{api_host:"https://us.i.posthog.com",defaults:"2026-01-30",person_profiles:"identified_only"});const ta=new mn({defaultOptions:{queries:{staleTime:3e4,retry:1,refetchOnWindowFocus:!1,refetchOnReconnect:!0}}});hn.createRoot(document.getElementById("root")).render(e.jsx(a.StrictMode,{children:e.jsx(xn,{client:ta,children:e.jsx(Qr,{})})}));export{Ke as A,Me as E,zt as M,Lr as N,at as P,f as a,it as b,ge as c,Si as d,pt as e,Cr as f,Fe as g,ns as h,rt as q,Ds as r,Mi as u};