@useorgx/openclaw-plugin 0.3.1 → 0.3.2

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.
Files changed (56) hide show
  1. package/dashboard/dist/assets/MissionControlView-CthHdl6R.js +1 -0
  2. package/dashboard/dist/assets/SessionInspector-Dq0Z5WMo.js +1 -0
  3. package/dashboard/dist/assets/index-CoLgC4zE.js +11 -0
  4. package/dashboard/dist/assets/index-jfEYE0kO.css +1 -0
  5. package/dashboard/dist/assets/motion-CVDprFZg.js +9 -0
  6. package/dashboard/dist/assets/orgx-logo-Fm0FhtnV.png +0 -0
  7. package/dashboard/dist/assets/react-vendor-C2t2w4r2.js +32 -0
  8. package/dashboard/dist/assets/tanstack-C-KIc3Wc.js +1 -0
  9. package/dashboard/dist/assets/vendor-C-AHK0Ly.js +9 -0
  10. package/dashboard/dist/index.html +6 -2
  11. package/dist/agent-context-store.d.ts.map +1 -1
  12. package/dist/agent-context-store.js +21 -20
  13. package/dist/agent-context-store.js.map +1 -1
  14. package/dist/agent-run-store.d.ts.map +1 -1
  15. package/dist/agent-run-store.js +21 -20
  16. package/dist/agent-run-store.js.map +1 -1
  17. package/dist/auth-store.d.ts.map +1 -1
  18. package/dist/auth-store.js +39 -44
  19. package/dist/auth-store.js.map +1 -1
  20. package/dist/byok-store.d.ts.map +1 -1
  21. package/dist/byok-store.js +24 -20
  22. package/dist/byok-store.js.map +1 -1
  23. package/dist/fs-utils.d.ts +7 -0
  24. package/dist/fs-utils.d.ts.map +1 -0
  25. package/dist/fs-utils.js +63 -0
  26. package/dist/fs-utils.js.map +1 -0
  27. package/dist/http-handler.d.ts +17 -0
  28. package/dist/http-handler.d.ts.map +1 -1
  29. package/dist/http-handler.js +281 -11
  30. package/dist/http-handler.js.map +1 -1
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +4 -3
  33. package/dist/index.js.map +1 -1
  34. package/dist/mcp-apps/orgx-live.html +690 -0
  35. package/dist/outbox.d.ts.map +1 -1
  36. package/dist/outbox.js +74 -29
  37. package/dist/outbox.js.map +1 -1
  38. package/dist/paths.d.ts +23 -0
  39. package/dist/paths.d.ts.map +1 -0
  40. package/dist/paths.js +50 -0
  41. package/dist/paths.js.map +1 -0
  42. package/dist/reporting/outbox-replay.d.ts +2 -0
  43. package/dist/reporting/outbox-replay.d.ts.map +1 -0
  44. package/dist/reporting/outbox-replay.js +17 -0
  45. package/dist/reporting/outbox-replay.js.map +1 -0
  46. package/dist/reporting/rollups.d.ts +21 -0
  47. package/dist/reporting/rollups.d.ts.map +1 -0
  48. package/dist/reporting/rollups.js +85 -0
  49. package/dist/reporting/rollups.js.map +1 -0
  50. package/dist/snapshot-store.d.ts.map +1 -1
  51. package/dist/snapshot-store.js +24 -20
  52. package/dist/snapshot-store.js.map +1 -1
  53. package/package.json +2 -2
  54. package/dashboard/dist/assets/index-BjqNjHpY.css +0 -1
  55. package/dashboard/dist/assets/index-DCLkU4AM.js +0 -57
  56. package/dashboard/dist/assets/orgx-logo-QSE5QWy4.png +0 -0
@@ -0,0 +1,11 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/MissionControlView-CthHdl6R.js","assets/react-vendor-C2t2w4r2.js","assets/tanstack-C-KIc3Wc.js","assets/vendor-C-AHK0Ly.js","assets/motion-CVDprFZg.js","assets/SessionInspector-Dq0Z5WMo.js"])))=>i.map(i=>d[i]);
2
+ import{r as a,j as e,a as $s,u as Ls,b as He,c as Fs,d as Ds,Q as Ts}from"./react-vendor-C2t2w4r2.js";import{b as Os}from"./tanstack-C-KIc3Wc.js";import{m as de,A as Be,u as vs}from"./motion-CVDprFZg.js";import"./vendor-C-AHK0Ly.js";(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const n of document.querySelectorAll('link[rel="modulepreload"]'))r(n);new MutationObserver(n=>{for(const o of n)if(o.type==="childList")for(const c of o.addedNodes)c.tagName==="LINK"&&c.rel==="modulepreload"&&r(c)}).observe(document,{childList:!0,subtree:!0});function i(n){const o={};return n.integrity&&(o.integrity=n.integrity),n.referrerPolicy&&(o.referrerPolicy=n.referrerPolicy),n.crossOrigin==="use-credentials"?o.credentials="include":n.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function r(n){if(n.ep)return;n.ep=!0;const o=i(n);fetch(n.href,o)}})();const Bs="modulepreload",Ps=function(t){return"/orgx/live/"+t},Xt={},jt=function(s,i,r){let n=Promise.resolve();if(i&&i.length>0){let c=function(u){return Promise.all(u.map(w=>Promise.resolve(w).then(d=>({status:"fulfilled",value:d}),d=>({status:"rejected",reason:d}))))};document.getElementsByTagName("link");const l=document.querySelector("meta[property=csp-nonce]"),j=(l==null?void 0:l.nonce)||(l==null?void 0:l.getAttribute("nonce"));n=c(i.map(u=>{if(u=Ps(u),u in Xt)return;Xt[u]=!0;const w=u.endsWith(".css"),d=w?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${u}"]${d}`))return;const m=document.createElement("link");if(m.rel=w?"stylesheet":Bs,w||(m.as="script"),m.crossOrigin="",m.href=u,j&&m.setAttribute("nonce",j),document.head.appendChild(m),w)return new Promise((p,$)=>{m.addEventListener("load",p),m.addEventListener("error",()=>$(new Error(`Unable to preload CSS for ${u}`)))})}))}function o(c){const l=new Event("vite:preloadError",{cancelable:!0});if(l.payload=c,window.dispatchEvent(l),!l.defaultPrevented)throw c}return n.then(c=>{for(const l of c||[])l.status==="rejected"&&o(l.reason);return s().catch(o)})},Gt=()=>{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 Se(t){const s=t instanceof Date?t:new Date(t),i=Date.now()-s.getTime();if(Number.isNaN(i))return"unknown";const r=Math.floor(i/1e3);if(r<60)return`${r}s ago`;const n=Math.floor(r/60);if(n<60)return`${n}m ago`;const o=Math.floor(n/60);return o<24?`${o}h ago`:`${Math.floor(o/24)}d ago`}const Rs=8e3,Us=320,Ws=600,zs=120,Ks=120,qs=90,Qt=6e4,js={pendingTotal:0,pendingByQueue:{},oldestEventAt:null,newestEventAt:null,replayStatus:"idle",lastReplayAttemptAt:null,lastReplaySuccessAt:null,lastReplayFailureAt:null,lastReplayError:null},Yt={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},Vs=new Set(["running","active","queued","in_progress","working","planning","pending","blocked"]),Jt=45*6e4;function je(t){if(!t)return 0;const s=Date.parse(t);return Number.isFinite(s)?s:0}function kt(t,s){const i=Yt[t.status]??99,r=Yt[s.status]??99;if(i!==r)return i-r;const n=je(t.updatedAt??t.lastEventAt??t.startedAt),o=je(s.updatedAt??s.lastEventAt??s.startedAt);return n!==o?o-n:t.id.localeCompare(s.id)}function Hs(t){return(t??"").trim().toLowerCase()}function Zt(t){return Vs.has(Hs(t.status))}function Et(t){const s=[];return t.id&&s.push(`id:${t.id}`),t.runId&&s.push(`run:${t.runId}`),s}function es(t,s){if(!t.nodes.length)return s;if(!s.nodes.length){const p=Date.now(),$=t.nodes.filter(L=>{const P=je(L.updatedAt??L.lastEventAt??L.startedAt);return Zt(L)||p-P<=Jt});if(!$.length)return s;const v=new Set($.map(L=>L.id)),O=new Set($.map(L=>L.groupId));return{nodes:$.sort(kt),edges:t.edges.filter(L=>v.has(L.parentId)&&v.has(L.childId)),groups:t.groups.filter(L=>O.has(L.id))}}const i=new Set,r=[...s.nodes];for(const p of s.nodes)for(const $ of Et(p))i.add($);const n=Date.now(),o=[];for(const p of t.nodes){if(Et(p).some(L=>i.has(L)))continue;const v=je(p.updatedAt??p.lastEventAt??p.startedAt),O=n-v<=Jt;if(Zt(p)||O){o.push(p),r.push(p);for(const L of Et(p))i.add(L)}}if(!o.length)return s;const c=new Set(r.map(p=>p.id)),l=new Map(t.groups.map(p=>[p.id,p])),j=new Map(s.groups.map(p=>[p.id,p])),u=[...s.groups];for(const p of o){if(j.has(p.groupId))continue;const $=l.get(p.groupId)??{id:p.groupId,label:p.groupLabel||p.agentName||"Ungrouped",status:null};j.set(p.groupId,$),u.push($)}const w=p=>`${p.parentId}->${p.childId}`,d=new Set,m=[];for(const p of s.edges){if(!c.has(p.parentId)||!c.has(p.childId))continue;const $=w(p);d.has($)||(d.add($),m.push(p))}for(const p of t.edges){if(!c.has(p.parentId)||!c.has(p.childId))continue;const $=w(p);d.has($)||(d.add($),m.push(p))}return{nodes:r.sort(kt),edges:m,groups:u}}function xt(t,s){if(t.nodes.length<=s)return t;const i=[...t.nodes].sort(kt).slice(0,s),r=new Set(i.map(o=>o.id)),n=new Set(i.map(o=>o.groupId));return{nodes:i,edges:t.edges.filter(o=>r.has(o.parentId)&&r.has(o.childId)),groups:t.groups.filter(o=>n.has(o.id))}}function ts(t,s){return t.length<=s?t:[...t].sort((i,r)=>je(r.updatedAt)-je(i.updatedAt)).slice(0,s)}function Xs(t){const s=t.requestedAt??t.updatedAt??null,i=t.updatedAt??s,r=Number.isFinite(t.waitingMinutes)?Math.max(0,Math.floor(t.waitingMinutes)):s?Math.max(0,Math.floor((Date.now()-je(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:r,metadata:t.metadata}}function ks(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 ss(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 r=t.nodes[i],n=s.nodes[i];if(r.id!==n.id||r.status!==n.status||r.title!==n.title||r.progress!==n.progress||r.updatedAt!==n.updatedAt||r.lastEventAt!==n.lastEventAt)return!1}for(let i=0;i<t.edges.length;i+=1){const r=t.edges[i],n=s.edges[i];if(r.parentId!==n.parentId||r.childId!==n.childId)return!1}for(let i=0;i<t.groups.length;i+=1){const r=t.groups[i],n=s.groups[i];if(r.id!==n.id||r.label!==n.label||r.status!==n.status)return!1}return!0}function ns(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 rs(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 Ns(t){if(!t||typeof t!="object")return js;const s=t.pendingByQueue&&typeof t.pendingByQueue=="object"?Object.fromEntries(Object.entries(t.pendingByQueue).filter(([r])=>typeof r=="string"&&r.length>0).map(([r,n])=>[r,Number.isFinite(Number(n))?Math.max(0,Math.floor(Number(n))):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((r,n)=>r+n,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 Gs(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),r=Object.keys(s.pendingByQueue);if(i.length!==r.length)return!1;for(const n of i)if(t.pendingByQueue[n]!==s.pendingByQueue[n])return!1;return!0}function Qs(t,s,i){if(s.length===0)return t;const r=new Map;for(const c of t)r.set(c.id,c);let n=!1;for(const c of s){const l=r.get(c.id);if(!l){r.set(c.id,c),n=!0;continue}(l.timestamp!==c.timestamp||l.type!==c.type||l.title!==c.title||l.description!==c.description)&&(r.set(c.id,c),n=!0)}if(!n)return t;const o=Array.from(r.values()).sort((c,l)=>je(l.timestamp)-je(c.timestamp)).slice(0,i);return ks(t,o)?t:o}function Mt(t,s){const i=[...t].sort((o,c)=>je(c.timestamp)-je(o.timestamp)).slice(0,s),r=new Set,n=[];for(const o of i)r.has(o.id)||(r.add(o.id),n.push(o));return n}function is(t,s){const i=t.filter(o=>!!o&&typeof o.id=="string"&&o.id.length>0).map(Xs).sort((o,c)=>o.waitingMinutes!==c.waitingMinutes?c.waitingMinutes-o.waitingMinutes:je(c.requestedAt??c.updatedAt)-je(o.requestedAt??o.updatedAt)).slice(0,s),r=new Set,n=[];for(const o of i)r.has(o.id)||(r.add(o.id),n.push(o));return n}function as(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 Ys(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 mt(t){return t?`Initiative ${t.length>16?`${t.slice(0,8)}…`:t}`:"Unscoped"}function _t(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 Js(t,s,i){const r=new Map,n=[...t].sort((l,j)=>je(j.timestamp)-je(l.timestamp));for(const l of n){if(!l.runId)continue;const j=l.runId,u=r.get(j),w=l.timestamp;if(!u){const d=l.initiativeId??null;r.set(j,{id:j,parentId:null,runId:j,title:l.title,agentId:l.agentId??null,agentName:l.agentName??null,status:as(l.type),progress:null,initiativeId:d,workstreamId:null,groupId:d??"unscoped",groupLabel:mt(d),startedAt:w,updatedAt:w,lastEventAt:w,lastEventSummary:l.title,blockers:l.type==="blocker_created"&&l.description?[l.description]:[]});continue}(!u.startedAt||je(w)<je(u.startedAt))&&(u.startedAt=w),je(w)>=je(u.updatedAt??u.lastEventAt)&&(u.updatedAt=w,u.lastEventAt=w,u.lastEventSummary=l.title,u.status=as(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=mt(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 j=l.runId??`agent:${l.id}`,u=r.get(j),w=Ys(l.status),d=l.initiativeId??null,m=l.currentTask&&l.currentTask.trim().length>0?l.currentTask.trim():`${l.name??l.id} ${w==="archived"?"idle":w}`;if(!u){r.set(j,{id:j,parentId:null,runId:j,title:m,agentId:l.id,agentName:l.name??l.id,status:w,progress:null,initiativeId:d,workstreamId:null,groupId:d??"unscoped",groupLabel:mt(d),startedAt:l.startedAt??null,updatedAt:l.startedAt??null,lastEventAt:l.startedAt??null,lastEventSummary:l.currentTask,blockers:_t(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=m),u.status==="archived"&&w!=="archived"&&(u.status=w),_t(l.blockers).length>0&&(u.blockers=_t(l.blockers)),d&&!u.initiativeId&&(u.initiativeId=d,u.groupId=d,u.groupLabel=mt(d))}const o=Array.from(r.values()).sort(kt).slice(0,i),c=new Map;for(const l of o)c.has(l.groupId)||c.set(l.groupId,{id:l.groupId,label:l.groupLabel,status:l.status});return{nodes:o,edges:[],groups:Array.from(c.values())}}async function Zs(t,s){var i;try{const r=await fetch(t,s),o=(((i=r.headers.get("content-type"))==null?void 0:i.toLowerCase())??"").includes("application/json");if(!r.ok){let c=`${r.status} ${r.statusText}`;if(o){const l=await r.json().catch(()=>null);l!=null&&l.error&&(c=`${r.status} ${l.error}`)}else{const l=(await r.text().catch(()=>"")).replace(/\s+/g," ").slice(0,80);l.length>0&&(c=`${r.status} ${l}`)}return{ok:!1,status:r.status,data:null,error:c}}if(!o){const c=(await r.text().catch(()=>"")).replace(/\s+/g," ").slice(0,80);return{ok:!1,status:r.status,data:null,error:`Unexpected content type for ${t}${c?`: ${c}`:""}`}}return{ok:!0,status:r.status,data:await r.json(),error:null}}catch(r){return{ok:!1,status:0,data:null,error:r instanceof Error?r.message:"Network error"}}}function en(t,s,i,r,n=js,o=null){var u,w,d;const c=((u=s[0])==null?void 0:u.timestamp)??null,l=((w=r[0])==null?void 0:w.requestedAt)??((d=r[0])==null?void 0:d.updatedAt)??null,j=je(c)>=je(l)?c:l;return{connection:"connected",lastActivity:j?Se(j):null,lastSnapshotAt:o,sessions:t,activity:s,handoffs:i,decisions:r,outbox:Ns(n)}}function tn(t={}){const{enabled:s=!0,pollInterval:i=Rs,useMock:r=!1,enableDecisions:n=!0,maxSessions:o=Us,maxActivityItems:c=Ws,maxHandoffs:l=zs,maxDecisions:j=Ks,batchWindowMs:u=qs}=t,[w,d]=a.useState(Gt()),[m,p]=a.useState(!r),[$,v]=a.useState(null),O=a.useRef(),L=a.useRef(null),[P,U]=a.useState(!1),I=a.useRef(0),z=a.useRef(!1),J=a.useCallback((C,_,B,A=null,N=null,S=null)=>{I.current=Date.now(),z.current=!1;const Z=Mt(_,c),me=ts(B,l);d(he=>{const K=xt(es(he.sessions,xt(C,o)),o),F=A===null?he.decisions:is(A,j),f=N===null?he.outbox:Ns(N);return ss(he.sessions,K)&&ks(he.activity,Z)&&ns(he.handoffs,me)&&rs(he.decisions,F)&&Gs(he.outbox,f)&&he.lastSnapshotAt===S&&he.connection==="connected"?he:en(K,Z,me,F,f,S)}),p(!1)},[c,j,l,o]),W=a.useCallback(async()=>{if(!s){d(_=>_.connection==="disconnected"?_:{..._,connection:"disconnected"}),p(!1),v(null);return}if(L.current)return L.current;if(r){d(Gt()),p(!1);return}const C=(async()=>{try{const _=new URLSearchParams({sessionsLimit:String(o),activityLimit:String(c),decisionsLimit:String(j),include_idle:"true"}),B=[{label:"dashboard-bundle",url:`/orgx/api/dashboard-bundle?${_.toString()}`},{label:"live/snapshot",url:`/orgx/api/live/snapshot?${_.toString()}`}],A=[];let N=null,S=!1;for(const f of B){const q=await Zs(f.url);if(q.ok&&q.data){N=q.data;break}(q.status===401||q.status===403)&&(S=!0),A.push(`${f.label}: ${q.error??"unavailable"}`)}if(!N){if(S){const f=new Error("Unauthorized. Update your OrgX API key in Settings (use a user-scoped oxk_... key; userId should be blank).");throw f.code="ORGX_AUTH",f}throw new Error(A.length>0?A.join(" | "):"Snapshot endpoint unavailable")}const Z=Array.isArray(N.activity)?N.activity:[],me=Array.isArray(N.handoffs)?N.handoffs:[],he=n&&Array.isArray(N.decisions)?N.decisions:[],K=N.sessions&&Array.isArray(N.sessions.nodes)&&Array.isArray(N.sessions.edges)&&Array.isArray(N.sessions.groups)?N.sessions:Js(Z,N.agents,o);J(K,Z,me,he,N.outbox??null,N.generatedAt??null);const F=Array.isArray(N.degraded)?N.degraded:[];F.length>0?(v(`Partial live data: ${F.join("; ")}`),d(f=>f.connection==="reconnecting"?f:{...f,connection:"reconnecting"}),U(!0)):(v(null),d(f=>f.connection==="connected"?f:{...f,connection:"connected"}))}catch(_){const B=_ instanceof Error?_.message:"Unknown error",A=!!(_&&typeof _=="object"&&"code"in _&&_.code==="ORGX_AUTH");A&&(z.current=!0);const N=I.current>0&&Date.now()-I.current>Qt;v(B),d(S=>{const Z=A||N?"disconnected":"reconnecting";return S.connection===Z?S:{...S,connection:Z}}),U(!A),p(!1)}finally{L.current=null}})();return L.current=C,C},[J,s,n,c,j,l,o,r]),ce=a.useCallback(async(C,_)=>{if(!n)throw new Error("OrgX decisions are unavailable while disconnected.");const B=Array.from(new Set(C.filter(Boolean)));if(B.length===0)return{updated:0,failed:0};if(r){const K=new Set(B);return d(F=>{const f=F.decisions.filter(te=>K.has(te.id));if(f.length===0)return F;const q=new Date().toISOString(),ee=f.map(te=>({id:`decision:${_}:${te.id}:${Date.now()}`,type:"decision_resolved",title:_==="approve"?`Approved: ${te.title}`:`Rejected: ${te.title}`,description:te.context,agentId:null,agentName:te.agentName,runId:null,initiativeId:null,timestamp:q,metadata:{decisionId:te.id,action:_}})),fe=Mt(ee.concat(F.activity),c);return{...F,decisions:F.decisions.filter(te=>!K.has(te.id)),activity:fe,lastActivity:Se(q)}}),{updated:K.size,failed:0}}const A=await fetch("/orgx/api/live/decisions/approve",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({ids:B,action:_})}),N=await A.json().catch(()=>null),S=Array.isArray(N==null?void 0:N.results)?N.results:[],Z=new Set(S.filter(K=>K.ok).map(K=>K.id));if(!A.ok&&A.status!==207){const K=typeof(N==null?void 0:N.error)=="string"?N.error:`Decision action failed (${A.status})`;throw new Error(K)}if(Z.size===0&&A.ok&&((N==null?void 0:N.failed)??0)===0)for(const K of B)Z.add(K);Z.size>0?d(K=>{const F=K.decisions.filter(te=>Z.has(te.id));if(F.length===0)return K;const f=new Date().toISOString(),q=F.map(te=>({id:`decision:${_}:${te.id}:${Date.now()}`,type:"decision_resolved",title:_==="approve"?`Approved: ${te.title}`:`Rejected: ${te.title}`,description:te.context,agentId:null,agentName:te.agentName,runId:null,initiativeId:null,timestamp:f,metadata:{decisionId:te.id,action:_}})),ee=Mt(q.concat(K.activity),c);return{...K,decisions:K.decisions.filter(te=>!Z.has(te.id)),activity:ee,lastActivity:Se(f)}}):A.ok&&B.length>0&&d(K=>({...K,decisions:K.decisions.filter(F=>!B.includes(F.id))})),W();const me=(N==null?void 0:N.updated)??Z.size,he=(N==null?void 0:N.failed)??Math.max(0,B.length-Z.size);return{updated:me,failed:he}},[n,W,c,r]),re=a.useCallback(async C=>ce([C],"approve"),[ce]),E=a.useCallback(async()=>{let C=[];return d(_=>(C=_.decisions.map(B=>B.id),_)),C.length===0?{updated:0,failed:0}:ce(C,"approve")},[ce]);return a.useEffect(()=>{n||d(C=>C.decisions.length===0?C:{...C,decisions:[]})},[n]),a.useEffect(()=>{if(!s){U(!1),p(!1),v(null);return}if(r){W();return}W();const C=new EventSource("/orgx/api/live/stream");let _=null,B=null,A=null,N=[],S=null,Z;const me=()=>{if(Z=void 0,_){I.current=Date.now(),z.current=!1;const K=_;_=null,B=null,A=null,N=[],S=null,J(K.sessions,K.activity,K.handoffs,K.decisions,K.outbox,K.generatedAt);return}!B&&!A&&!S&&N.length===0||(I.current=Date.now(),z.current=!1,d(K=>{var f;let F=K;if(B){const q=xt(B,o),ee=xt(es(F.sessions,q),o);B=null,ss(F.sessions,ee)||(F={...F,sessions:ee})}if(A){const q=ts(A,l);A=null,ns(F.handoffs,q)||(F={...F,handoffs:q})}if(S){const q=is(S,j);S=null,rs(F.decisions,q)||(F={...F,decisions:q})}if(N.length>0){const q=Qs(F.activity,N,c);N=[],q!==F.activity&&(F={...F,activity:q,lastActivity:(f=q[0])!=null&&f.timestamp?Se(q[0].timestamp):F.lastActivity})}return F===K?K:F.connection==="connected"?F:{...F,connection:"connected"}}),v(null),p(!1))},he=()=>{Z||(Z=setTimeout(me,u))};return C.onopen=()=>{I.current=Date.now(),z.current=!1,U(!1),d(K=>K.connection==="connected"?K:{...K,connection:"connected"}),v(null)},C.onerror=()=>{if(z.current){d(F=>F.connection==="disconnected"?F:{...F,connection:"disconnected"}),U(!1);return}const K=I.current>0&&Date.now()-I.current>Qt;d(F=>F.connection===(K?"disconnected":"reconnecting")?F:{...F,connection:K?"disconnected":"reconnecting"}),U(!0)},C.addEventListener("snapshot",K=>{try{const F=JSON.parse(K.data),f=typeof F.generatedAt=="string"&&F.generatedAt.length>0?F.generatedAt:new Date().toISOString();_={sessions:F.sessions,activity:F.activity??[],handoffs:F.handoffs??[],decisions:n?F.decisions??null:[],outbox:F.outbox??null,generatedAt:f},he()}catch(F){v(F instanceof Error?F.message:"Invalid snapshot")}}),C.addEventListener("activity.appended",K=>{try{const F=JSON.parse(K.data);if(F.length===0)return;N=N.concat(F),he()}catch{}}),C.addEventListener("session.updated",K=>{try{B=JSON.parse(K.data),he()}catch{}}),C.addEventListener("handoff.updated",K=>{try{A=JSON.parse(K.data),he()}catch{}}),C.addEventListener("decision.updated",K=>{if(n)try{S=JSON.parse(K.data),he()}catch{}}),()=>{Z&&clearTimeout(Z),C.close()}},[J,u,s,n,W,c,j,l,o,r]),a.useEffect(()=>{if(s&&!r&&(O.current&&clearInterval(O.current),!!P))return O.current=setInterval(W,i),()=>{O.current&&clearInterval(O.current)}},[s,W,i,P,r]),{data:w,isLoading:m,error:$,refetch:W,approveDecision:re,approveAllDecisions:E}}const sn="https://orgx.mintlify.site/guides/openclaw-plugin-setup",nn=1500,$t="orgx.onboarding.skip",Lt={status:"idle",hasApiKey:!1,connectionVerified:!1,workspaceName:null,lastError:null,nextAction:"connect",docsUrl:sn,keySource:"none",installationId:null,connectUrl:null,pairingId:null,expiresAt:null,pollIntervalMs:null};function rn(t){if(typeof t=="string")return t;if(t&&typeof t=="object")return JSON.stringify(t)}async function it(t){const s=await t,i=await s.json().catch(()=>null);return s.ok?i??{}:{ok:!1,error:rn(i==null?void 0:i.error)??`Request failed (${s.status})`}}function an(){const[t,s]=a.useState(Lt),[i,r]=a.useState(!0),[n,o]=a.useState(!1),[c,l]=a.useState(!1),j=a.useRef(null),[u,w]=a.useState(()=>typeof window>"u"?!1:window.localStorage.getItem($t)==="1"),d=a.useCallback(async()=>{const P=await it(fetch("/orgx/api/onboarding/status",{method:"GET"}));if(!P.ok||!P.data){const U=P.error??"Failed to load onboarding state",I={...Lt,status:"error",lastError:U,nextAction:"retry"};return s(I),I}return s(P.data),P.data},[]);a.useEffect(()=>{let P=!1;return(async()=>{r(!0);const U=await d();P||(s(U),r(!1))})(),()=>{P=!0}},[d]),a.useEffect(()=>{if(!(t.status==="awaiting_browser_auth"||t.status==="pairing"))return;const U=Math.max(900,t.pollIntervalMs??nn),I=window.setInterval(async()=>{const z=await it(fetch("/orgx/api/onboarding/status",{method:"GET"}));z.ok&&z.data&&s(z.data)},U);return()=>{window.clearInterval(I)}},[t.pollIntervalMs,t.status]),a.useEffect(()=>{if(!(typeof window>"u")){if(u){window.localStorage.setItem($t,"1");return}window.localStorage.removeItem($t)}},[u]);const m=a.useCallback(()=>{if(typeof window>"u")return null;try{const P=window.open("","_blank");return P?(P.opener=null,P.document.title="Connecting to OrgX…",P.document.body.innerHTML='<div style="font-family:system-ui,-apple-system,sans-serif;padding:20px;color:#111">Connecting to OrgX...</div>',P):null}catch{return null}},[]),p=a.useCallback(async()=>{var U;const P=m();j.current=P,o(!0);try{const I=await it(fetch("/orgx/api/onboarding/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({deviceName:navigator.platform||"OpenClaw Device",platform:navigator.platform})}));if(!I.ok||!((U=I.data)!=null&&U.state)){P&&!P.closed&&P.close();const z=I.error??"Could not start pairing";s(J=>({...J,status:"error",lastError:z,nextAction:"enter_manual_key"}));return}if(s(I.data.state),I.data.connectUrl){const z=j.current;let J=!1;if(z&&!z.closed)try{z.location.href=I.data.connectUrl,J=!0}catch{J=!1}J||(J=!!window.open(I.data.connectUrl,"_blank","noopener,noreferrer")),J||s(W=>({...W,lastError:'Popup was blocked. Use "Approve in browser" below.',nextAction:"open_browser"}))}}finally{j.current=null,o(!1)}},[m]),$=a.useCallback(async P=>{l(!0);try{const U=P.trim(),I=U.replace(/^[a-z]+_/i,""),z=Array.from(new Set([U,I?`oxk_${I}`:"",I?`orgx_${I}`:""].map(W=>W.trim()).filter(W=>W.length>0)));let J="Manual key validation failed";for(const W of z){const ce={"Content-Type":"application/json","X-OrgX-Api-Key":W,Authorization:`Bearer ${W}`},re=await it(fetch("/orgx/api/onboarding/manual-key",{method:"POST",headers:ce,body:JSON.stringify({apiKey:W})}));if(re.ok&&re.data)return s(re.data),re.data;J=re.error??J}throw s(W=>({...W,status:"manual_key",lastError:J,nextAction:"enter_manual_key"})),new Error(J)}finally{l(!1)}},[]),v=a.useCallback(async()=>{const P=await it(fetch("/orgx/api/onboarding/disconnect",{method:"POST"}));if(P.ok&&P.data)return s(P.data),P.data;const U={...Lt,status:"idle"};return s(U),U},[]),O=a.useCallback(()=>{s(P=>({...P,status:"idle",lastError:null,nextAction:"connect",connectUrl:null,pairingId:null,expiresAt:null,pollIntervalMs:null}))},[]),L=a.useMemo(()=>u?!1:!(t.hasApiKey&&t.connectionVerified&&t.status==="connected"),[u,t.connectionVerified,t.hasApiKey,t.status]);return{state:t,showGate:L,isLoading:i,isStarting:n,isSubmittingManual:c,refreshStatus:d,startPairing:p,submitManualKey:$,disconnect:v,skipGate:()=>w(!0),resumeGate:()=>w(!1),backToPairing:O,setManualMode:()=>s(P=>({...P,status:"manual_key",nextAction:"enter_manual_key"}))}}function ue(...t){return t.filter(Boolean).join(" ")}const b={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"},on={Pace:"#7C7CFF",Eli:"#BFFF00",Dana:"#FF00D4",Mark:"#F5B700",System:"#14B8A6",Sage:"#0AD4C4",Orion:"#14B8A6",Xandy:"#FF6B88",Nova:"#A78BFA"},ln={Pace:"Engineering",Eli:"Engineering",Dana:"Product Design",Mark:"Marketing",System:"System",Sage:"Strategy",Orion:"Operations",Xandy:"Orchestrator",Nova:"Research"};function cn(t){return on[t]??b.teal}function qt(t){return ln[t]??null}function dn(t){return t.split(" ").map(s=>s[0]).join("").toUpperCase().slice(0,2)}const Ct="/orgx/live/assets/orgx-logo-Fm0FhtnV.png",un=[{label:"Model Routing",desc:"Right model, right cost, every prompt",accent:"#BFFF00",icon:e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",children:[e.jsx("circle",{cx:"12",cy:"5",r:"2.5",stroke:"currentColor",strokeWidth:"1.4"}),e.jsx("circle",{cx:"5",cy:"19",r:"2.5",stroke:"currentColor",strokeWidth:"1.4"}),e.jsx("circle",{cx:"19",cy:"19",r:"2.5",stroke:"currentColor",strokeWidth:"1.4"}),e.jsx("path",{d:"M12 7.5v3m0 0l-5.5 6m5.5-6l5.5 6",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})]})},{label:"Live Operations",desc:"Decisions, handoffs, sessions — real-time",accent:"#14B8A6",icon:e.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",children:e.jsx("path",{d:"M3 12h3l2.5-5 3.5 10 2.5-5H21",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round"})})},{label:"Quality Gates",desc:"Automated checkpoints before shipping",accent:"#7C7CFF",icon:e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",children:[e.jsx("path",{d:"M12 2l8 4.5v5.5c0 4.7-3.4 9-8 10.3C7.4 21 4 16.7 4 12V6.5L12 2z",stroke:"currentColor",strokeWidth:"1.4",strokeLinejoin:"round"}),e.jsx("path",{d:"M9 12l2.5 2.5L15 10",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round"})]})}],hn=[{label:"Initiative",detail:"Top-level outcome and owner context"},{label:"Workstream",detail:"Major track that sequences execution"},{label:"Milestone",detail:"Checkpoint that gates readiness"},{label:"Task",detail:"Atomic action with dependencies and priority"}],os="openclaw plugins install @useorgx/openclaw-plugin",ls="orgx.demo_mode";function pn(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 xn={hidden:{},visible:{transition:{staggerChildren:.07}}},Le={hidden:{opacity:0,y:14},visible:{opacity:1,y:0,transition:{duration:.45,ease:[.16,1,.3,1]}}};function mn({state:t,isStarting:s,onConnect:i,onUseManualKey:r,onContinueWithoutOrgX:n}){const o=!!t.lastError,[c,l]=a.useState("idle"),j=t.hasApiKey&&t.keySource&&t.keySource!=="none";a.useEffect(()=>{if(c==="idle")return;const w=window.setTimeout(()=>l("idle"),2e3);return()=>window.clearTimeout(w)},[c]);const u=async()=>{try{await navigator.clipboard.writeText(os),l("ok")}catch{l("error")}};return e.jsxs(de.section,{variants:xn,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:Le,className:"flex items-center gap-2.5",children:[e.jsx("img",{src:Ct,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.h2,{variants:Le,className:"mt-5 text-[26px] font-semibold leading-[1.2] tracking-[-0.02em] text-white sm:text-[30px]",children:"Connect your workspace"}),e.jsx(de.p,{variants:Le,className:"mt-2 max-w-md text-[15px] leading-relaxed text-white/50",children:"Orchestrate agents, approve decisions, and track progress from a single live dashboard."})]}),e.jsx(de.div,{variants:Le,className:"mt-6 grid grid-cols-1 gap-2.5 px-6 sm:grid-cols-3 sm:px-8",children:un.map((w,d)=>e.jsxs(de.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:.18+d*.08,duration:.4,ease:[.16,1,.3,1]},className:"rounded-xl border border-white/[0.06] bg-white/[0.025] px-4 py-3.5",children:[e.jsx("div",{style:{color:w.accent},className:"mb-2.5 opacity-80",children:w.icon}),e.jsx("p",{className:"text-[13px] font-semibold text-white",children:w.label}),e.jsx("p",{className:"mt-0.5 text-[12px] leading-snug text-white/40",children:w.desc})]},w.label))}),e.jsxs(de.div,{variants:Le,className:"mt-4 mx-6 sm:mx-8 rounded-xl border border-white/[0.08] bg-white/[0.02] p-4",children:[e.jsx("p",{className:"text-[11px] uppercase tracking-[0.08em] text-white/38",children:"How Work Ladders Up"}),e.jsx("div",{className:"mt-2 grid gap-1.5 sm:grid-cols-2",children:hn.map(w=>e.jsxs("div",{className:"rounded-lg border border-white/[0.08] bg-white/[0.02] px-2.5 py-2",children:[e.jsx("p",{className:"text-[12px] font-semibold text-white/85",children:w.label}),e.jsx("p",{className:"text-[11px] leading-relaxed text-white/45",children:w.detail})]},w.label))}),e.jsx("p",{className:"mt-2 text-[11px] leading-relaxed text-white/45",children:"Mission Control maps dependencies between all four levels so you can stay high-level, then drill down instantly."})]}),e.jsxs(de.div,{variants:Le,className:"mt-3 mx-6 sm:mx-8 rounded-xl border border-[#14B8A6]/20 bg-[#14B8A6]/[0.06] px-4 py-3",children:[e.jsx("p",{className:"text-[11px] uppercase tracking-[0.08em] text-[#7EEDE1]",children:"OpenClaw Integration"}),e.jsx("p",{className:"mt-1 text-[12px] leading-relaxed text-[#CFF8F3]",children:"OrgX syncs with your OpenClaw sessions so initiatives, workstreams, milestones, tasks, and assignment context stay aligned with live agent execution."})]}),e.jsxs(de.div,{variants:Le,className:"mt-3 mx-6 sm:mx-8 rounded-xl border border-white/[0.08] bg-white/[0.02] px-4 py-3",children:[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:os}),e.jsx("button",{type:"button",onClick:()=>{u()},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:c==="ok"?"Copied":c==="error"?"Copy failed":"Copy command"})]}),j&&e.jsxs("p",{className:"mt-2 text-[11px] text-white/45",children:["API key source detected: ",pn(t.keySource)]})]}),e.jsxs(de.div,{variants:Le,className:"mt-6 flex flex-wrap items-center gap-3 px-6 sm:px-8",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:r,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.jsx(de.div,{variants:Le,className:"mx-6 mt-6 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.5 rounded-xl border border-white/[0.06] bg-white/[0.02] px-4 py-2.5",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-[13px] text-white/40",children:"Ready to connect"})]})}),e.jsxs(de.div,{variants:Le,className:"mt-4 flex items-center justify-between border-t border-white/[0.05] px-6 py-4 sm:px-8",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("button",{type:"button",onClick:()=>{try{window.localStorage.setItem(ls,"1")}catch{}n()},className:"text-left text-[12px] text-white/35 transition hover:text-white/60",children:"Explore demo dashboard"}),e.jsx("button",{type:"button",onClick:()=>{try{window.localStorage.removeItem(ls)}catch{}n()},className:"text-left text-[12px] 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-[12px] 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 fn={hidden:{},visible:{transition:{staggerChildren:.06}}},Ye={hidden:{opacity:0,y:10},visible:{opacity:1,y:0,transition:{duration:.35,ease:[.16,1,.3,1]}}};function Cs({isSubmitting:t,onSubmit:s,onBack:i}){const[r,n]=a.useState(""),[o,c]=a.useState(null),l=async()=>{c(null);const u=r.trim();if(!u){c("API key is required.");return}const w=/^[a-z]+_/i.test(u)?u:`oxk_${u}`;try{await s(w),n("")}catch(d){c(d instanceof Error?d.message:"Failed to validate API key.")}},j=o!==null;return e.jsxs(de.section,{variants:fn,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:Ye,className:"flex items-center gap-2.5",children:[e.jsx("img",{src:Ct,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:Ye,className:"mt-5 text-[22px] font-semibold tracking-[-0.02em] text-white",children:"Manual API key"}),e.jsxs(de.p,{variants:Ye,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:Ye,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:Ye,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 ${j?"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:r,onChange:u=>{n(u.target.value),o&&c(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"})]}),j&&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:Ye,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."})})]})}function gn(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 bn(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 wn(t){return t==="awaiting_browser_auth"||t==="pairing"||t==="starting"?"active":t==="error"?"error":t==="connected"?"active":"idle"}const cs={idle:"bg-white/40",active:"bg-[#BFFF00]",error:"bg-red-400"},Ft="orgx.onboarding.mc_hint.dismissed",ds={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 yn({state:t,isLoading:s,isStarting:i,isSubmittingManual:r,onRefresh:n,onStartPairing:o,onSubmitManualKey:c,onBackToPairing:l,onUseManualKey:j,onSkip:u}){const[w,d]=a.useState(()=>typeof window>"u"?!1:window.localStorage.getItem(Ft)==="1");a.useEffect(()=>{typeof window>"u"||(w?window.localStorage.setItem(Ft,"1"):window.localStorage.removeItem(Ft))},[w]);const m=t.status==="manual_key",p=t.status==="awaiting_browser_auth"||t.status==="pairing",$=wn(t.status),v=$==="active"&&t.status!=="connected",O=t.status==="connected"&&!w;return e.jsx("div",{className:"relative flex min-h-screen items-center justify-center px-4 py-10 sm:py-16",style:{backgroundColor:"#02040A"},children:e.jsxs(de.div,{initial:{opacity:0},animate:{opacity:1},transition:{duration:.45},className:"relative z-10 w-full max-w-lg",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(Be,{mode:"wait",children:m?e.jsx(de.div,{...ds,children:e.jsx(Cs,{isSubmitting:r,onSubmit:c,onBack:l})},"manual"):e.jsx(de.div,{...ds,children:e.jsx(mn,{state:t,isStarting:i,onConnect:()=>{o()},onUseManualKey:j,onContinueWithoutOrgX:u})},"explainer")}),!s&&(p||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:[v&&e.jsx("span",{className:`absolute inline-flex h-full w-full animate-ping rounded-full ${cs[$]} opacity-40`}),e.jsx("span",{className:`relative inline-flex h-2 w-2 rounded-full ${cs[$]}`})]}),e.jsx("span",{className:"text-[13px] text-white/60",children:gn(t.status)}),t.workspaceName&&e.jsx("span",{className:"chip",children:t.workspaceName}),t.keySource&&t.keySource!=="none"&&e.jsx("span",{className:"chip",children:bn(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&&p&&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:()=>{n()},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"})]})]}),O&&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:()=>d(!0),className:"text-[11px] text-white/60 underline underline-offset-2",children:"Dismiss"})]})]})]})})}function et({open:t,onClose:s,children:i,maxWidth:r="max-w-2xl",fitContent:n=!1}){const o=a.useRef(null),c=a.useRef(null);a.useEffect(()=>{if(!t)return;c.current=document.activeElement instanceof HTMLElement?document.activeElement:null,(()=>{const d=o.current;if(!d)return;const m=d.querySelector('[data-modal-autofocus="true"]');if(m){m.focus();return}const p=d.querySelectorAll('a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])');p.length>0?p[0].focus():d.focus()})();const u=d=>{if(d.key==="Escape"){d.preventDefault(),s();return}if(d.key!=="Tab")return;const m=o.current;if(!m)return;const p=m.querySelectorAll('a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])');if(p.length===0){d.preventDefault(),m.focus();return}const $=p[0],v=p[p.length-1],O=document.activeElement;!d.shiftKey&&O===v?(d.preventDefault(),$.focus()):d.shiftKey&&O===$&&(d.preventDefault(),v.focus())},w=document.body.style.overflow;return document.body.style.overflow="hidden",document.addEventListener("keydown",u),()=>{var d;document.body.style.overflow=w,document.removeEventListener("keydown",u),(d=c.current)==null||d.focus()}},[t,s]);const l=e.jsx(Be,{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 w-full ${r} overflow-hidden ${n?"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:b.cardBgElevated,borderColor:b.cardBorderStrong},onClick:j=>j.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:$s.createPortal(l,document.body)}function Dt(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 Ss({authToken:t=null,embedMode:s=!1,enabled:i=!0}={}){var u,w;const r=Ls(),n=a.useMemo(()=>["byok-settings",{authToken:t,embedMode:s}],[t,s]),o=a.useMemo(()=>["byok-health",{authToken:t,embedMode:s}],[t,s]),c=He({queryKey:n,enabled:i,queryFn:async()=>{const d=await fetch("/orgx/api/settings/byok",{headers:Dt({authToken:t,embedMode:s})}),m=await d.json().catch(()=>null);return d.ok?m:{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:(m==null?void 0:m.error)??`Failed to load settings (${d.status})`}},staleTime:15e3}),l=He({queryKey:o,enabled:!1,queryFn:async()=>{const d=await fetch("/orgx/api/settings/byok/health",{headers:Dt({authToken:t,embedMode:s})}),m=await d.json().catch(()=>null);return d.ok?m:{ok:!1,agentId:"main",providers:{openai:{ok:!1,error:(m==null?void 0:m.error)??`Probe failed (${d.status})`},anthropic:{ok:!1,error:(m==null?void 0:m.error)??`Probe failed (${d.status})`},openrouter:{ok:!1,error:(m==null?void 0:m.error)??`Probe failed (${d.status})`}},error:(m==null?void 0:m.error)??`Probe failed (${d.status})`}}}),j=Fs({mutationFn:async d=>{const m=await fetch("/orgx/api/settings/byok",{method:"POST",headers:Dt({authToken:t,embedMode:s,contentTypeJson:!0}),body:JSON.stringify(d??{})}),p=await m.json().catch(()=>null);if(!m.ok)throw new Error((p==null?void 0:p.error)??`Failed to save settings (${m.status})`);return p},onSuccess:async()=>{await r.invalidateQueries({queryKey:n})}});return{status:c.data??null,isLoading:c.isLoading,error:((u=c.data)==null?void 0:u.error)??((w=c.error)==null?void 0:w.message)??null,refetchStatus:c.refetch,update:j.mutateAsync,isSaving:j.isPending,health:l.data??null,probe:l.refetch,isProbing:l.isFetching}}const As="orgx.first_run_guide.dismissed";function vn(t){return e.jsx("span",{className:ue("inline-flex h-2 w-2 rounded-full",t?"bg-emerald-400":"bg-white/35")})}function jn(){try{return typeof window<"u"&&window.localStorage.getItem(As)==="1"}catch{return!1}}function kn(t){try{if(typeof window>"u")return;t&&window.localStorage.setItem(As,"1")}catch{}}function Nn({open:t,onClose:s,onOpenSettings:i,onOpenOrgxSettings:r,onOpenMissionControl:n,demoMode:o,connectionVerified:c,hasSessions:l}){const j=Ss({enabled:t}),w=a.useMemo(()=>{var v;return(v=j.status)!=null&&v.ok?Number(j.status.providers.openai.configured)+Number(j.status.providers.anthropic.configured)+Number(j.status.providers.openrouter.configured):0},[j.status])>0,d=w?"mission-control":"settings",m=[{label:o?"Exit demo (optional)":"Connect OrgX",done:o?!1:c,detail:o?"Demo mode shows sample data. Connect OrgX to sync initiatives/tasks.":"Approve the pairing flow so your initiatives, tasks, and activity can sync.",action:!o&&!c&&r?{label:"Connect",onClick:r}:null},{label:"Add provider key(s)",done:w,detail:"Set OpenAI / Anthropic / OpenRouter keys for agent launches, or rely on env vars.",action:w?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:n}}],p=m.filter(v=>v.done).length,$=Math.round(p/m.length*100);return e.jsx(et,{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:[p," / ",m.length," complete"]}),e.jsxs("span",{className:"text-[11px] text-white/35",children:[$,"% 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:`${$}%`}})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>{kn(!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:m.map(v=>e.jsxs("div",{className:ue("flex items-start justify-between gap-3 rounded-xl border p-3",v.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:vn(v.done)}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:ue("text-[13px] font-semibold",v.done?"text-white/80":"text-white"),children:v.label}),e.jsx("p",{className:"mt-0.5 text-[12px] leading-relaxed text-white/45",children:v.detail})]})]}),v.action&&!v.done?e.jsx("button",{type:"button",onClick:v.action.onClick,"data-modal-autofocus":d==="settings"&&v.label==="Add provider key(s)"||d==="mission-control"&&v.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:v.action.label}):null]},v.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":d==="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:n,"data-modal-autofocus":d==="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 us({children:t,color:s,pulse:i,title:r}){const n=s??b.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:r,style:{backgroundColor:`${n}22`,border:`1px solid ${n}5a`,color:n},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:n}}),e.jsx("span",{className:"relative inline-flex h-1.5 w-1.5 rounded-full",style:{backgroundColor:n}})]}),t]})}const Cn=[{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:"Initiatives",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 Sn({activeTab:t,onTabChange:s,pendingDecisionCount:i=0}){return e.jsxs("nav",{className:"fixed inset-x-0 bottom-0 z-40 border-t border-white/[0.08] bg-[#0a0a0f]/95 backdrop-blur-lg lg:hidden","aria-label":"Mobile sections",children:[e.jsx("div",{className:"flex items-stretch",children:Cn.map(r=>{const n=t===r.id;return e.jsxs("button",{type:"button",onClick:()=>s(r.id),"aria-current":n?"page":void 0,className:ue("relative flex flex-1 flex-col items-center gap-0.5 pb-1 pt-2 transition-colors",n?"text-lime":"text-white/40 hover:text-white/60"),children:[n&&e.jsx("span",{className:"absolute inset-x-3 top-0 h-[2px] rounded-full",style:{backgroundColor:b.lime}}),e.jsxs("span",{className:"relative",children:[r.icon,r.id==="decisions"&&i>0&&e.jsx("span",{className:"absolute -right-2 -top-1 flex h-3.5 min-w-[14px] items-center justify-center rounded-full px-1 text-[8px] font-bold text-black",style:{backgroundColor:b.amber},children:i>99?"99+":i})]}),e.jsx("span",{className:"text-[10px]",children:r.label})]},r.id)})}),e.jsx("div",{className:"h-[env(safe-area-inset-bottom)]"})]})}const Nt={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:b.lime,tint:"rgba(191, 255, 0, 0.18)"},unknown:{id:"unknown",label:"Agent",accent:b.teal,tint:"rgba(20, 184, 166, 0.18)"}},An=["provider","vendor","model","runtime","engine","agent","name","title","label","summary","description","source"];function wt(t,s,i,r){if(!(t==null||i>2)){if(typeof t=="string"){const n=t.trim();n.length>0&&s.push(n);return}if(Array.isArray(t)){for(const n of t)wt(n,s,i+1,r);return}if(typeof t=="object"){if(r.has(t))return;r.add(t);for(const[n,o]of Object.entries(t)){const c=n.toLowerCase();typeof o=="string"?(An.some(l=>c.includes(l))||c.startsWith("meta")||c.endsWith("id"))&&wt(o,s,i+1,r):typeof o=="object"&&o!==null&&wt(o,s,i+1,r)}}}}function In(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 hs(...t){const s=[],i=new Set;for(const r of t)wt(r,s,0,i);for(const r of s){const n=In(r);if(n)return Nt[n]}return Nt.unknown}function En(t){return Nt[t]??Nt.unknown}function Ve({children:t,className:s=""}){return e.jsx("section",{className:ue("surface-tier-1 relative overflow-hidden rounded-2xl",s),children:t})}const Mn={xs:18,sm:24,md:30};function _n({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:Ct,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 ps({provider:t,size:s="sm",className:i,showRing:r=!0}){const n=En(t),o=Mn[s];return e.jsx("span",{className:ue("inline-flex items-center justify-center rounded-md",i),style:{width:o,height:o,color:n.accent,backgroundColor:n.tint,border:r?`1px solid ${n.accent}55`:"none"},title:n.label,"aria-label":n.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(_n,{provider:t})})})}const $n={xs:"w-6 h-6 text-[9px]",sm:"w-8 h-8 text-[10px]",md:"w-10 h-10 text-[12px]"},Ln="/orgx/live/",_e=t=>`${Ln.replace(/\/+$/,"/")}${t}`,Fn={pace:_e("brand/product-orchestrator.png"),eli:_e("brand/engineering-autopilot.png"),mark:_e("brand/launch-captain.png"),sage:_e("brand/pipeline-intelligence.png"),orion:_e("brand/control-tower.png"),dana:_e("brand/design-codex.png"),xandy:_e("brand/product-orchestrator.png"),nova:_e("brand/product-orchestrator.png"),openclaw:_e("brand/openclaw-mark.svg"),openai:_e("brand/openai-mark.svg"),anthropic:_e("brand/anthropic-mark.svg"),orgx:_e("brand/orgx-logo.png")},Dn=[{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 Tn(...t){const s=t.map(i=>typeof i=="string"?i.trim():"").filter(Boolean).join(" ").toLowerCase();if(!s)return null;for(const i of Dn)if(i.test.test(s))return Fn[i.key];return null}function De({name:t,size:s="xs",hint:i,src:r}){const n=cn(t),[o,c]=a.useState(!1),l=a.useMemo(()=>r&&r.trim()?r:Tn(t,i),[i,t,r]),j=!!(l&&!o);return e.jsx("div",{className:`${$n[s]} overflow-hidden rounded-full flex items-center justify-center font-semibold flex-shrink-0`,style:{backgroundColor:`${n}20`,color:n,border:`1px solid ${n}30`},children:j?e.jsx("img",{src:l??void 0,alt:t,className:"h-full w-full rounded-full object-cover",onError:()=>c(!0),loading:"lazy"}):dn(t)})}const Vt={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}],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 On(t){const s=t.toLowerCase();return s==="completed"||s==="done"?"completed":s==="blocked"||s==="at_risk"?"blocked":s==="paused"||s==="hold"?"paused":"active"}function Bn(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 Pn(t){return{id:t.id,name:t.title,status:On(t.status),rawStatus:t.status??null,health:t.progress_pct??0,daysRemaining:Bn(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 Rn(t){const s=t.toLowerCase();return!["deleted","archived","cancelled"].includes(s)}function Is(t){return He({queryKey:Vt.entities({type:"initiative"}),queryFn:async()=>{const s=await fetch("/orgx/api/entities?type=initiative&limit=300");return s.ok?((await s.json()).data??[]).filter(r=>Rn(r.status??"")).sort((r,n)=>{const o=Date.parse(r.updated_at??r.created_at??"")||0;return(Date.parse(n.updated_at??n.created_at??"")||0)-o}).map(Pn):[]},enabled:t,staleTime:6e4})}const Un=new Set(["ungrouped","unscoped","unknown"]);function Wn(t){const s=(t??"").trim().toLowerCase();return!!(!s||Un.has(s)||/^init-\d+$/.test(s)||s.startsWith("mock-"))}function zn(t){return!Wn(t)}const ft={initiativeId:"",workstreams:[],milestones:[],tasks:[]},Kn=(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}),qn=(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}),Vn=(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 Hn({initiativeId:t,authToken:s=null,embedMode:i=!1,enabled:r=!0}){var l;const n=zn(t),o=a.useMemo(()=>Vt.initiativeDetails({initiativeId:t,authToken:s,embedMode:i}),[t,s,i]),c=He({queryKey:o,enabled:r&&!!t&&n,queryFn:async()=>{if(!t)return ft;if(!n)return{...ft,initiativeId:t};const j={};i&&(j["X-Orgx-Embed"]="true"),s&&(j.Authorization=`Bearer ${s}`);const u=Object.keys(j).length?j:void 0,w=async L=>{try{const P=new URLSearchParams({type:L,initiative_id:t,limit:"100"}),U=await fetch(`/orgx/api/entities?${P.toString()}`,{headers:u});return U.ok?await U.json():(console.warn(`[useInitiativeDetails] ${L} fetch returned ${U.status}, using empty list`),{data:[]})}catch(P){return console.warn(`[useInitiativeDetails] ${L} fetch failed:`,P),{data:[]}}},[d,m,p]=await Promise.all([w("workstream"),w("milestone"),w("task")]),$=Array.isArray(d.data)?d.data.map(L=>Kn(L,t)):[],v=Array.isArray(m.data)?m.data.map(L=>qn(L,t)):[],O=Array.isArray(p.data)?p.data.map(L=>Vn(L,t)):[];return{initiativeId:t,workstreams:$,milestones:v,tasks:O}}});return{details:(n?c.data:null)??(t?{...ft,initiativeId:t}:ft),isLoading:n?c.isLoading:!1,error:n?((l=c.error)==null?void 0:l.message)??null:null,refetch:c.refetch}}function at(t){const s=(t??"").toLowerCase();return s==="active"?{label:"Active",color:b.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:b.iris,bg:"rgba(124,124,255,0.10)"}}function Xn(t){return[...t.workstreams].sort((s,i)=>s.name.localeCompare(i.name))}function Gn(t,s){return[...s?t.tasks.filter(r=>r.workstreamId===s):t.tasks].sort((r,n)=>r.title.localeCompare(n.title))}function Qn({open:t,onClose:s,onLaunched:i}){var fe,te,le,ye,ie,be;const r=He({queryKey:["openclaw-agent-catalog"],queryFn:async()=>{const g=await fetch("/orgx/api/agents/catalog");if(!g.ok){const H=await g.text().catch(()=>"");throw new Error(H||`Agent catalog failed (${g.status})`)}return await g.json()},enabled:t,staleTime:2e3,refetchInterval:t?3e3:!1}),{data:n}=Is(t),[o,c]=a.useState(""),[l,j]=a.useState(""),[u,w]=a.useState(""),[d,m]=a.useState(""),[p,$]=a.useState("auto"),[v,O]=a.useState(""),[L,P]=a.useState(null),[U,I]=a.useState(null),[z,J]=a.useState("starter"),[W,ce]=a.useState(!1),[re,E]=a.useState(1),C=a.useMemo(()=>{const g=l.trim();return g?(n==null?void 0:n.find(H=>H.id===g))??null:null},[n,l]),{details:_}=Hn({initiativeId:C?C.id:null,enabled:t&&!!C}),B=a.useMemo(()=>Xn(_),[_]),A=a.useMemo(()=>Gn(_,u||null),[_,u]),N=((fe=r.data)==null?void 0:fe.agents)??[],S=a.useMemo(()=>{const g=o.trim();return g?N.find(H=>H.id===g)??null:null},[N,o]);a.useEffect(()=>{var H,Q;if(!t)return;const g=((H=N.find(y=>y.isDefault))==null?void 0:H.id)??((Q=N[0])==null?void 0:Q.id)??"";!o&&g&&c(g)},[N,t,o]),a.useEffect(()=>{if(!t||l.trim())return;const g=n??[],H=g.length===1?g[0]:null;H&&j(H.id)},[n,t,l]),a.useEffect(()=>{if(!t)return;const g=(S==null?void 0:S.model)??"",H=g.includes("openrouter")?"openrouter":g.includes("anthropic")?"anthropic":g.includes("openai")?"openai":"auto";$(H)},[t,S==null?void 0:S.model,o]),a.useEffect(()=>{t&&(P(null),I(null),J("starter"),E(1))},[t]),a.useEffect(()=>{w(""),m("")},[l]),a.useEffect(()=>{m("")},[u]),a.useEffect(()=>{t&&(v.trim().length>0||C&&O(`Kick off: ${C.name}`))},[v,t,C]);const Z=!!o.trim()&&!!l.trim(),me=re===1?!!o.trim():re===2?!!l.trim():Z,he=async()=>{var ve;const g=(U==null?void 0:U.checkout)??"/orgx/api/billing/checkout",H=z&&z.trim().length>0?z.trim():"starter",y=await(await fetch(g,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({planId:H,billingCycle:"monthly"})})).json().catch(()=>null),X=((ve=y==null?void 0:y.data)==null?void 0:ve.url)??(y==null?void 0:y.url)??null;if(!X)throw new Error((y==null?void 0:y.error)??"Checkout unavailable");window.open(X,"_blank","noopener,noreferrer")},K=async()=>{var X;const g=(U==null?void 0:U.portal)??"/orgx/api/billing/portal",Q=await(await fetch(g,{method:"POST"})).json().catch(()=>null),y=((X=Q==null?void 0:Q.data)==null?void 0:X.url)??(Q==null?void 0:Q.url)??null;if(!y)throw new Error((Q==null?void 0:Q.error)??"Billing portal unavailable");window.open(y,"_blank","noopener,noreferrer")},F=async()=>{if(!(!Z||W)){P(null),I(null),ce(!0);try{const g={agentId:o.trim(),message:v.trim()?v.trim():void 0,initiativeId:l.trim(),initiativeTitle:(C==null?void 0:C.name)??null,workstreamId:u.trim()?u.trim():null,taskId:d.trim()?d.trim():null,provider:p!=="auto"?p:null},H=new URLSearchParams;H.set("agentId",g.agentId),H.set("initiativeId",g.initiativeId),g.initiativeTitle&&H.set("initiativeTitle",g.initiativeTitle),g.workstreamId&&H.set("workstreamId",g.workstreamId),g.taskId&&H.set("taskId",g.taskId),g.message&&H.set("message",g.message),g.provider&&H.set("provider",g.provider);const Q=await fetch(`/orgx/api/agents/launch?${H.toString()}`,{method:"POST"}),y=await Q.json().catch(()=>null);if(!Q.ok||!(y!=null&&y.ok))throw(y==null?void 0:y.code)==="upgrade_required"&&(I(y.actions??null),J(y.requiredPlan??"starter")),new Error((y==null?void 0:y.error)??`Launch failed (${Q.status})`);s(),i==null||i()}catch(g){P(g instanceof Error?g.message:"Launch failed")}finally{ce(!1)}}},f=!!((te=S==null?void 0:S.run)!=null&&te.runId)&&!!((le=S==null?void 0:S.run)!=null&&le.pid),q=async()=>{var g;if(!(!((g=S==null?void 0:S.run)!=null&&g.runId)||!f||W)){P(null),ce(!0);try{const H=await fetch(`/orgx/api/agents/stop?runId=${encodeURIComponent(S.run.runId)}`,{method:"POST"}),Q=await H.json().catch(()=>null);if(!H.ok||!(Q!=null&&Q.ok))throw new Error((Q==null?void 0:Q.error)??`Stop failed (${H.status})`);await r.refetch()}catch(H){P(H instanceof Error?H.message:"Stop failed")}finally{ce(!1)}}},ee=async()=>{var g;if(!(!((g=S==null?void 0:S.run)!=null&&g.runId)||W)){P(null),ce(!0);try{const H=new URLSearchParams;H.set("runId",S.run.runId),v.trim()&&H.set("message",v.trim()),p&&p!=="auto"&&H.set("provider",p);const Q=await fetch(`/orgx/api/agents/restart?${H.toString()}`,{method:"POST"}),y=await Q.json().catch(()=>null);if(!Q.ok||!(y!=null&&y.ok))throw new Error((y==null?void 0:y.error)??`Restart failed (${Q.status})`);s(),i==null||i()}catch(H){P(H instanceof Error?H.message:"Restart failed")}finally{ce(!1)}}};return t?e.jsx(et,{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(([g,H])=>e.jsxs("button",{type:"button",onClick:()=>E(g),className:ue("rounded-full px-3 py-1 transition-colors",re===g?"bg-white/[0.12] text-white":"hover:bg-white/[0.06]"),children:[g,". ",H]},g))})]}),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:[r.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…"}),r.error&&e.jsx("div",{className:"rounded-xl border border-rose-300/20 bg-rose-400/10 p-4 text-[12px] text-rose-100",children:r.error.message}),e.jsx(Be,{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:[re===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:g=>c(g.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:N.map(g=>{const H=at(g.status);return e.jsxs("option",{value:g.id,children:[g.name," (",g.id,") · ",H.label]},g.id)})})]}),S&&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:S.name}),e.jsx("span",{className:"rounded-full border px-2 py-0.5 text-[10px] uppercase tracking-[0.12em]",style:{borderColor:`${at(S.status).color}55`,color:at(S.status).color,backgroundColor:at(S.status).bg},children:at(S.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:"})," ",S.model??"unknown"]}),e.jsxs("p",{className:"truncate",children:[e.jsx("span",{className:"text-white/40",children:"Workspace:"})," ",S.workspace??"unknown"]}),((ye=S.context)==null?void 0:ye.initiativeId)&&e.jsxs("p",{className:"truncate",children:[e.jsx("span",{className:"text-white/40",children:"Scoped:"})," ",S.context.initiativeTitle??S.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:p,onChange:g=>$(g.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."})]}),S.run&&e.jsxs("p",{className:"truncate",children:[e.jsx("span",{className:"text-white/40",children:"Tracked run:"})," ",S.run.runId.slice(0,8),"…"," ",e.jsxs("span",{className:"text-white/35",children:["(",S.run.status,")"]})]}),S.run&&e.jsxs("div",{className:"grid grid-cols-2 gap-2 pt-1",children:[e.jsx("button",{type:"button",onClick:q,disabled:!f||W,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:ee,disabled:W,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"})]})]})]})]}),re===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:g=>j(g.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…"}),(n??[]).map(g=>e.jsx("option",{value:g.id,children:g.name},g.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:g=>w(g.target.value),disabled:!C,className:ue("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",!C&&"opacity-50"),children:[e.jsx("option",{value:"",children:"Any workstream"}),B.map(g=>e.jsx("option",{value:g.id,children:g.name},g.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:d,onChange:g=>m(g.target.value),disabled:!C,className:ue("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",!C&&"opacity-50"),children:[e.jsx("option",{value:"",children:"Any task"}),A.slice(0,80).map(g=>e.jsx("option",{value:g.id,children:g.title},g.id))]}),A.length>80&&e.jsx("p",{className:"mt-1 text-[10px] text-white/35",children:"Showing first 80 tasks to keep the menu usable."})]})]})]}),re===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:v,onChange:g=>O(g.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:((S==null?void 0:S.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:((C==null?void 0:C.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()?((ie=B.find(g=>g.id===u))==null?void 0:ie.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:d.trim()?((be=A.find(g=>g.id===d))==null?void 0:be.title)??d:"Any"})]})]})]})]})]},re)}),L&&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:L}),U&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>void he().catch(g=>P(g instanceof Error?g.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 K().catch(g=>P(g instanceof Error?g.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"}),U.pricing&&e.jsx("a",{href:U.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:re===1?"Pick an agent to configure.":re===2?"Select an initiative scope (required).":Z?"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:[re>1&&e.jsx("button",{type:"button",onClick:()=>E(g=>g>1?g-1:g),disabled:W,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"}),re<3?e.jsx("button",{type:"button",onClick:()=>E(g=>g<3?g+1:g),disabled:!me||W,className:ue("rounded-xl px-4 py-2 text-[12px] font-semibold transition-colors",me&&!W?"text-black":"cursor-not-allowed border border-white/[0.12] bg-white/[0.05] text-white/40"),style:me&&!W?{backgroundColor:b.lime}:void 0,children:"Next"}):e.jsx("button",{type:"button",onClick:F,disabled:!Z||W,className:ue("rounded-xl px-4 py-2 text-[12px] font-semibold transition-colors",Z&&!W?"text-black":"cursor-not-allowed border border-white/[0.12] bg-white/[0.05] text-white/40"),style:Z&&!W?{backgroundColor:b.lime}:void 0,children:W?"Launching…":"Launch"})]})]})]})}):null}const Tt=10,Yn=20,Jn={running:b.lime,queued:b.amber,pending:b.amber,blocked:b.red,failed:b.red,cancelled:b.red,completed:b.teal,archived:"rgba(255,255,255,0.5)"};function Zn(t){return Jn[t]??b.iris}function er(t){const s=(t??"").toLowerCase();return s==="active"?{label:"Active",color:b.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:b.iris,bg:"rgba(124,124,255,0.10)"}}function tr(t){return t?t.includes("error")||t.includes("fail")?b.red:t.includes("decision")||t.includes("block")?b.amber:t.includes("complete")||t.includes("success")?b.teal:t.includes("start")||t.includes("launch")?b.lime:b.iris:b.iris}function sr({open:t,onClose:s,agentName:i,catalogAgent:r,sessions:n,activity:o,onSelectSession:c,onRefresh:l}){var ce,re,E,C,_,B;const[j,u]=a.useState(!1),[w,d]=a.useState(!1),[m,p]=a.useState(null),$=qt(i),v=er((r==null?void 0:r.status)??null),O=a.useMemo(()=>{let A=0,N=0,S=0,Z=0;for(const me of n)me.status==="running"||me.status==="queued"||me.status==="pending"?A++:me.status==="blocked"?N++:me.status==="failed"||me.status==="cancelled"?S++:(me.status==="completed"||me.status==="archived")&&Z++;return{running:A,blocked:N,failed:S,completed:Z}},[n]),L=a.useMemo(()=>[...n].sort((A,N)=>Date.parse(N.updatedAt??N.lastEventAt??N.startedAt??"")-Date.parse(A.updatedAt??A.lastEventAt??A.startedAt??"")),[n]),P=j?L:L.slice(0,Tt),U=L.length>Tt,I=a.useMemo(()=>[...o].sort((A,N)=>Date.parse(N.timestamp)-Date.parse(A.timestamp)).slice(0,Yn),[o]),z=!!((ce=r==null?void 0:r.run)!=null&&ce.runId)&&!!((re=r==null?void 0:r.run)!=null&&re.pid),J=async()=>{var A;if(!(!((A=r==null?void 0:r.run)!=null&&A.runId)||!z||w)){p(null),d(!0);try{const N=await fetch(`/orgx/api/agents/stop?runId=${encodeURIComponent(r.run.runId)}`,{method:"POST"}),S=await N.json().catch(()=>null);if(!N.ok||!(S!=null&&S.ok))throw new Error((S==null?void 0:S.error)??`Stop failed (${N.status})`);l==null||l()}catch(N){p(N instanceof Error?N.message:"Stop failed")}finally{d(!1)}}},W=async()=>{var A;if(!(!((A=r==null?void 0:r.run)!=null&&A.runId)||w)){p(null),d(!0);try{const N=new URLSearchParams;N.set("runId",r.run.runId);const S=await fetch(`/orgx/api/agents/restart?${N.toString()}`,{method:"POST"}),Z=await S.json().catch(()=>null);if(!S.ok||!(Z!=null&&Z.ok))throw new Error((Z==null?void 0:Z.error)??`Restart failed (${S.status})`);l==null||l()}catch(N){p(N instanceof Error?N.message:"Restart failed")}finally{d(!1)}}};return t?e.jsx(et,{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(De,{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:`${v.color}55`,color:v.color,backgroundColor:v.bg},children:v.label})]}),$&&e.jsx("p",{className:"text-[12px] text-white/45 mt-0.5",children:$}),r&&e.jsxs("div",{className:"flex flex-wrap items-center gap-3 mt-1 text-[11px] text-white/40",children:[r.model&&e.jsxs("span",{children:[e.jsx("span",{className:"text-white/30",children:"Model:"})," ",r.model]}),r.workspace&&e.jsxs("span",{children:[e.jsx("span",{className:"text-white/30",children:"Workspace:"})," ",r.workspace]})]})]})]}),e.jsx("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-4",children:[{label:"Running",value:O.running,color:b.lime},{label:"Blocked",value:O.blocked,color:b.red},{label:"Failed",value:O.failed,color:b.amber},{label:"Completed",value:O.completed,color:b.teal}].map(A=>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:A.label}),e.jsx("p",{className:"mt-0.5 text-[18px] font-semibold",style:{color:A.value>0?A.color:"rgba(255,255,255,0.3)",fontVariantNumeric:"tabular-nums"},children:A.value})]},A.label))}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-[10px] uppercase tracking-[0.1em] text-white/35 mb-2",children:["Sessions (",n.length,")"]}),n.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:[P.map(A=>e.jsxs("button",{onClick:()=>{c(A.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:Zn(A.status)}}),e.jsx("p",{className:"min-w-0 flex-1 truncate text-[12px] text-white/80",children:A.title}),e.jsx("span",{className:"text-[10px] text-white/35",style:{fontVariantNumeric:"tabular-nums"},children:Se(A.updatedAt??A.lastEventAt??A.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:A.status}),A.progress!==null&&e.jsxs("span",{children:[Math.round(A.progress),"%"]})]})]},A.id)),U&&e.jsx("button",{type:"button",onClick:()=>u(A=>!A),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:j?"Show fewer":`Show ${L.length-Tt} more`})]})]}),I.length>0&&e.jsxs("div",{children:[e.jsxs("p",{className:"text-[10px] uppercase tracking-[0.1em] text-white/35 mb-2",children:["Recent Activity (",I.length,")"]}),e.jsx("div",{className:"space-y-1",children:I.map((A,N)=>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:tr(A.type)}}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx("p",{className:"truncate text-white/70",children:A.title??A.summary??A.description??"Activity"})}),e.jsx("span",{className:"flex-shrink-0 text-[10px] text-white/30",style:{fontVariantNumeric:"tabular-nums"},children:Se(A.timestamp)})]},A.id??N))})]}),(r==null?void 0:r.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:"})," ",r.run.runId.slice(0,8),"…"," ",e.jsxs("span",{className:"text-white/35",children:["(",r.run.status,")"]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("button",{type:"button",onClick:J,disabled:!z||w,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:w?"Stopping…":"Stop Run"}),e.jsx("button",{type:"button",onClick:W,disabled:w,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:w?"Restarting…":"Restart"})]}),m&&e.jsx("p",{className:"mt-2 text-[11px] text-rose-200",children:m})]})]}),r&&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:(E=r.model)!=null&&E.includes("openrouter")?"OpenRouter":(C=r.model)!=null&&C.includes("anthropic")?"Anthropic":(_=r.model)!=null&&_.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:ue("truncate max-w-[200px] text-right",r.model?"text-white/70":"text-white/30"),children:r.model??"Not configured"})]}),r.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:r.workspace})]}),((B=r.context)==null?void 0:B.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:r.context.initiativeTitle})]})]})]})]})]})}):null}function nr({enabled:t=!0}={}){return He({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 gt=120,rr=10,ir=new Set(["running","active","queued","pending","blocked","in_progress","working","planning"]),bt=[{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}],ar=10,or=[{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"}],lr={running:b.lime,active:b.lime,queued:b.amber,pending:b.amber,in_progress:b.amber,working:b.amber,planning:b.amber,blocked:b.red,failed:b.red,cancelled:b.red,paused:"rgba(255,255,255,0.5)",draft:"rgba(255,255,255,0.5)",completed:b.teal,archived:"rgba(255,255,255,0.5)"};function ot(t){return lr[t]??b.iris}function Ce(t){const s=t==null?void 0:t.trim().toLowerCase();return s&&s.length>0?s:null}function cr(t){const s=Ce(t.agentId);if(s)return`id:${s}`;const i=Ce(t.agentName);return i?`name:${i}`:"unassigned"}function Oe(t){const s=Ce(t);return s?ir.has(s):!1}function Je(t){if(!t)return 0;const s=Date.parse(t);return Number.isFinite(s)?s:0}function Ot(t,s){return Je(s.updatedAt??s.lastEventAt??s.startedAt)-Je(t.updatedAt??t.lastEventAt??t.startedAt)}const dr=a.memo(function({sessions:s,activity:i,selectedSessionId:r,onSelectSession:n,onAgentFilter:o,agentFilter:c,onReconnect:l,connectionStatus:j}){var F;const[u,w]=a.useState(new Set),[d,m]=a.useState(!1),[p,$]=a.useState("all"),[v,O]=a.useState(!1),[L,P]=a.useState(0),[U,I]=a.useState(null),z=nr({enabled:!0}),J=((F=z.data)==null?void 0:F.agents)??[];a.useMemo(()=>{var ee,fe,te;const f=new Map,q=[...i].sort((le,ye)=>Je(ye.timestamp)-Je(le.timestamp));for(const le of q){const ye=le.runId;if(!ye||f.has(ye))continue;const ie=((ee=le.summary)==null?void 0:ee.trim())??((fe=le.description)==null?void 0:fe.trim())??((te=le.title)==null?void 0:te.trim())??"";ie.length>0&&f.set(ye,ie)}return f},[i]);const{agents:W,hiddenGroupCount:ce,filteredOutGroupsByDate:re,filteredOutSessionsByDate:E,visibleSessionCount:C,archivedGroups:_}=a.useMemo(()=>{var g,H,Q;const f=new Map;for(const y of s.nodes){const X=cr(y),ve=Ce(y.agentId),ae=Ce(y.agentName);let se=f.get(X)??null;if(!se&&ve&&ae){const D=`name:${ae}`,ne=f.get(D);ne&&(f.delete(D),ne.groupKey=X,f.set(X,ne),se=ne)}if(!se&&ae){const D=Array.from(f.values()).find(ne=>Ce(ne.agentName)===ae);D&&(se=D)}se?(se.nodes.push(y),!se.agentId&&y.agentId&&(se.agentId=y.agentId),(se.agentName==="Unassigned"||!se.agentName)&&y.agentName&&(se.agentName=y.agentName)):f.set(X,{groupKey:X,agentId:y.agentId,agentName:y.agentName??y.agentId??"Unassigned",nodes:[y],latest:y})}for(const y of J){const X=Ce(y.id),ve=Ce(y.name),ae=X?`id:${X}`:null,se=ve?`name:${ve}`:null;let D=null;if(ae&&f.has(ae))D=ae;else if(se&&f.has(se))D=se;else{const ne=Array.from(f.entries()).find(([,we])=>X&&Ce(we.agentId)===X||ve&&Ce(we.agentName)===ve);D=(ne==null?void 0:ne[0])??null}if(D){const ne=f.get(D);ne.catalogAgent=y,!ne.agentId&&y.id&&(ne.agentId=y.id),(ne.agentName==="Unassigned"||!ne.agentName)&&y.name&&(ne.agentName=y.name),ae&&ne.groupKey!==ae&&!f.has(ae)&&(f.delete(ne.groupKey),ne.groupKey=ae,f.set(ae,ne))}else{const ne=ae??se??`catalog:${y.name.toLowerCase()}`;f.set(ne,{groupKey:ne,agentId:y.id,agentName:y.name,nodes:[],latest:null,catalogAgent:y})}}for(const y of f.values())y.nodes.length>0&&(y.nodes.sort(Ot),y.latest=y.nodes[0]);const q=Array.from(f.values()).sort((y,X)=>y.latest&&X.latest?Ot(y.latest,X.latest):y.latest&&!X.latest?-1:!y.latest&&X.latest?1:y.agentName.localeCompare(X.agentName)),ee=bt.find(y=>y.id===p)??bt[0],fe=ee.id==="live",te=ee.minutes===null||fe?null:Date.now()-ee.minutes*6e4,le=[],ye=[];let ie=0,be=0;for(const y of q){if(y.nodes.length===0){const se=Oe(((g=y.catalogAgent)==null?void 0:g.status)??null);(!fe||se)&&le.push(y);continue}if(fe){const se=y.nodes.filter(we=>Oe(we.status)),D=y.nodes.filter(we=>!Oe(we.status)),ne=Oe(((H=y.catalogAgent)==null?void 0:H.status)??null);if(se.length===0){ne?le.push({...y,nodes:[],latest:null}):(ie+=1,be+=y.nodes.length,ye.push(y));continue}be+=D.length,D.length>0&&ye.push({...y,nodes:D,latest:D[0]??null}),le.push({...y,nodes:se,latest:se[0]??null});continue}if(te===null){le.push(y);continue}const X=y.nodes.filter(se=>Oe(se.status)?!0:Je(se.updatedAt??se.lastEventAt??se.startedAt)>=te),ve=Oe(((Q=y.catalogAgent)==null?void 0:Q.status)??null);if(X.length===0){ve?le.push({...y,nodes:[],latest:null}):(ie+=1,be+=y.nodes.length,ye.push(y));continue}const ae=y.nodes.filter(se=>Oe(se.status)?!1:Je(se.updatedAt??se.lastEventAt??se.startedAt)<te);be+=ae.length,ae.length>0&&ye.push({...y,nodes:ae,latest:ae[0]}),le.push({...y,nodes:X,latest:X[0]})}return{agents:le.slice(0,gt),hiddenGroupCount:Math.max(0,le.length-gt),filteredOutGroupsByDate:ie,filteredOutSessionsByDate:be,visibleSessionCount:le.slice(0,gt).reduce((y,X)=>y+X.nodes.length,0),archivedGroups:ye}},[p,s.nodes,J]);a.useEffect(()=>{O(!1),P(0)},[p]);const B=a.useMemo(()=>_.reduce((f,q)=>f+q.nodes.length,0),[_]),A=a.useMemo(()=>{const f=[];for(const q of _)for(const ee of q.nodes)f.push({node:ee,agentName:q.agentName});return f.sort((q,ee)=>Ot(q.node,ee.node)),f.slice(0,(L+1)*ar)},[_,L]),N=f=>{w(q=>{const ee=new Set(q);return ee.has(f)?ee.delete(f):ee.add(f),ee})},S=a.useMemo(()=>U?W.find(f=>f.groupKey===U)??null:null,[W,U]),Z=a.useMemo(()=>(S==null?void 0:S.nodes)??[],[S]),me=a.useMemo(()=>{if(!S)return[];const f=Ce(S.agentName),q=Ce(S.agentId);return i.filter(ee=>{const fe=Ce(ee.agentName),te=Ce(ee.agentId);return f!==null&&fe===f||q!==null&&te===q})},[i,S]),he=s.nodes.length===0,K=J.length>0;return e.jsxs(Ve,{className:"flex h-full min-h-0 flex-col card-enter",children:[e.jsx(Qn,{open:d,onClose:()=>m(!1),onLaunched:()=>l==null?void 0:l()}),e.jsx(sr,{open:U!==null,onClose:()=>I(null),agentName:(S==null?void 0:S.agentName)??"",catalogAgent:(S==null?void 0:S.catalogAgent)??null,sessions:Z,activity:me,onSelectSession:n,onRefresh:()=>z.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:[C,"/",s.nodes.length]})]}),e.jsx("button",{type:"button",onClick:()=>m(!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:bt.map(f=>{const q=p===f.id;return e.jsx("button",{type:"button",onClick:()=>$(f.id),"aria-pressed":q,className:ue("rounded-full px-2.5 py-1 text-[10px] font-semibold tracking-[-0.01em] transition-colors",q?"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:f.label},f.id)})}),e.jsx("label",{htmlFor:"offline-date-filter",className:"sr-only",children:"Session history filter"}),e.jsx("select",{id:"offline-date-filter",value:p,onChange:f=>$(f.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:bt.map(f=>e.jsx("option",{value:f.id,children:f.label},f.id))})]})]}),e.jsxs("div",{className:"flex-1 space-y-2 overflow-y-auto p-3",children:[W.length===0&&!he&&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."})]}),W.length===0&&he&&!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."})]}),c&&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: ",c]}),e.jsx("button",{type:"button",onClick:()=>o(null),className:"text-[10px] underline underline-offset-2",children:"Clear"})]}),W.map(f=>{var Q,y;const q=f.groupKey,ee=u.has(q),fe=f.latest,te=f.nodes.length>0,le=Oe(((Q=f.catalogAgent)==null?void 0:Q.status)??null),ye=fe?r===fe.id:!1,ie=f.agentName||((y=f.catalogAgent)==null?void 0:y.name)||f.agentId||"Unassigned",be=ee?[]:f.nodes.slice(0,rr),g=Math.max(0,f.nodes.length-be.length),H=Ce(c)===Ce(ie);return e.jsxs("div",{className:ue("overflow-hidden rounded-xl border border-white/[0.06] bg-white/[0.02] transition-all",ye&&"border-white/20 bg-white/[0.05]",H&&"border-[#0AD4C4]/30",!te&&!le&&"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(H?null:ie):fe&&n(fe.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(De,{name:ie,size:"sm",hint:ie}),fe&&e.jsx("span",{className:"absolute -bottom-0.5 -right-0.5 h-2.5 w-2.5 rounded-full border-2",style:{backgroundColor:ot(fe.status),borderColor:b.cardBg}}),!fe&&e.jsx("span",{className:"absolute -bottom-0.5 -right-0.5 h-2.5 w-2.5 rounded-full border-2",style:{backgroundColor:le?ot("running"):"rgba(255,255,255,0.2)",borderColor:b.cardBg}})]}),e.jsxs("span",{className:"min-w-0 truncate",children:[e.jsx("span",{className:"text-[13px] font-semibold text-white",children:ie}),qt(ie)&&e.jsxs("span",{className:"ml-1 text-[11px] text-white/40",children:["— ",qt(ie)]})]}),te?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 X={};for(const ae of f.nodes)X[ae.status]=(X[ae.status]??0)+1;const ve=f.nodes.length;return Object.entries(X).map(([ae,se])=>e.jsx("span",{style:{width:`${se/ve*100}%`,backgroundColor:ot(ae)}},ae))})()}),e.jsx("span",{className:"text-[10px] text-white/55",style:{fontVariantNumeric:"tabular-nums"},children:f.nodes.length})]}):le?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:ot("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:()=>I(q),"aria-label":`View ${ie} 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"})]})}),te&&e.jsx("button",{type:"button",onClick:()=>N(q),"aria-label":ee?"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:ue("transition-transform",ee?"-rotate-90":"rotate-0"),children:e.jsx("path",{d:"m6 9 6 6 6-6"})})})]}),te&&e.jsx("div",{className:ue("overflow-hidden border-t border-white/[0.06] transition-all",ee?"max-h-0 opacity-0":"max-h-[500px] opacity-100 overflow-y-auto"),children:e.jsxs("div",{className:"space-y-1.5 p-2",children:[be.map(X=>{const ve=r===X.id,ae=hs(X.agentName,X.title,X.lastEventSummary,X);return e.jsx("button",{onClick:()=>n(X.id),className:ue("w-full rounded-lg px-2.5 py-2 text-left transition-colors",ve?"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(ps,{provider:ae.id,size:"xs"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-[12px] text-white/90",children:X.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:`${ae.accent}66`,color:ae.accent,backgroundColor:ae.tint},children:ae.label}),e.jsx("span",{className:"uppercase tracking-[0.08em]",children:X.status}),e.jsx("span",{children:Se(X.updatedAt??X.lastEventAt??X.startedAt??Date.now())})]}),X.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(X.progress)}%`,background:`linear-gradient(90deg, ${b.lime}, ${b.teal})`}})})]}),e.jsx("span",{className:"h-2 w-2 flex-shrink-0 rounded-full",style:{backgroundColor:ot(X.status)},"aria-label":X.status,title:X.status})]})},X.id)}),g>0&&!ee&&e.jsxs("p",{className:"px-1 text-[10px] text-white/40",children:["+",g," older sessions hidden"]})]})})]},q)}),ce>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 ",gt," most recent agent groups (",ce," older groups omitted)."]}),l&&j!=="connected"&&!K&&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:or.map(f=>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:f.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:f.name}),e.jsx("p",{className:"text-[9px] text-white/35",children:f.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"})]},f.id))})]}),E>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:()=>{O(f=>!f),v&&P(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:ue("transition-transform",v?"rotate-0":"-rotate-90"),children:e.jsx("path",{d:"m6 9 6 6 6-6"})}),e.jsxs("span",{children:[B," archived session",B===1?"":"s",re>0?` across ${re} agent${re===1?"":"s"}`:""]})]}),v&&e.jsxs("div",{className:"space-y-1.5 border-t border-white/[0.06] p-2",children:[A.map(({node:f,agentName:q})=>{const ee=hs(f.agentName,f.title,f.lastEventSummary,f);return e.jsxs("button",{onClick:()=>n(f.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(ps,{provider:ee.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:q}),e.jsx("span",{className:"text-[10px] text-white/35",children:Se(f.updatedAt??f.lastEventAt??f.startedAt??Date.now())})]}),e.jsx("p",{className:"truncate text-[10px] text-white/50",children:f.title}),e.jsx("span",{className:"text-[9px] uppercase tracking-[0.08em] text-white/35",children:f.status})]})]},f.id)}),A.length<B&&e.jsxs("button",{onClick:()=>P(f=>f+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 (",B-A.length," remaining)"]})]})]})]})]})}),ur=[[/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 Ht(t){if(!t)return"";for(const[i,r]of ur)if(i.test(t))return r;const s=t.split("/");return s[s.length-1]??t}function hr(t,s=4){let i=t.replace(/^\/Users\/[^/]+\//,"~/").replace(/^~\/Code\//,"").replace(/^~\//,"");const r=i.split("/");return r.length>s&&(i=r.slice(-s).join("/")),i}function Ee(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=>Ht(i)),s=s.replace(/\/Users\/[a-zA-Z0-9_-]+\/[^\s"']+/g,i=>hr(i)),s}const Bt=/\[([^\]]+)\]\(([^)\s]+)\)|`([^`]+)`|\*\*([^*]+)\*\*|__([^_]+)__|\*([^*\n]+)\*|_([^_\n]+)_/g;function pr(t){try{const s=new URL(t);return s.protocol==="http:"||s.protocol==="https:"}catch{return!1}}function qe(t,s){const i=[];let r=0,n=0;Bt.lastIndex=0;for(let o=Bt.exec(t);o;o=Bt.exec(t)){const[c]=o,l=o.index;l>r&&i.push(t.slice(r,l));const j=`${s}-${n++}`,u=o[1],w=o[2],d=o[3],m=o[4],p=o[5],$=o[6],v=o[7];u&&w&&pr(w)?i.push(e.jsx("a",{href:w,target:"_blank",rel:"noopener noreferrer",className:"text-[#D8FFA1] underline decoration-white/35 underline-offset-2 transition hover:text-[#ECFFC6]",children:u},j)):d?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:d},j)):m||p?i.push(e.jsx("strong",{className:"font-semibold text-white",children:m??p},j)):$||v?i.push(e.jsx("em",{className:"italic text-white/90",children:$??v},j)):i.push(c),r=l+c.length}return r<t.length&&i.push(t.slice(r)),i}function xr(t,s){const i=t.split(`
3
+ `),r=[];return i.forEach((n,o)=>{r.push(...qe(n,`${s}-line-${o}`)),o<i.length-1&&r.push(e.jsx("br",{},`${s}-br-${o}`))}),r}function yt(t){return t.trim().replace(/^\|/,"").replace(/\|$/,"").split("|").map(i=>i.trim())}function mr(t){const s=yt(t);return s.length===0?!1:s.every(i=>/^:?-{3,}:?$/.test(i))}function fr(t){const s=t.trim(),i=s.startsWith(":"),r=s.endsWith(":");return i&&r?"center":r?"right":"left"}function gr(t){const s=t.replace(/\r\n/g,`
4
+ `).split(`
5
+ `),i=[];let r=0;for(;r<s.length;){const n=s[r]??"",o=n.trim();if(!o){r+=1;continue}const c=n.includes("|"),l=s[r+1]??"";if(c&&l.includes("|")&&mr(l)){const m=yt(n),$=yt(l).map(O=>fr(O));r+=2;const v=[];for(;r<s.length;){const O=s[r]??"";if(!O.trim()||!O.includes("|"))break;v.push(yt(O)),r+=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:m.map((O,L)=>e.jsx("th",{className:"px-3 py-2 text-[11px] font-semibold uppercase tracking-[0.08em] text-white/70",style:{textAlign:$[L]??"left"},children:qe(O,`tbl-h-${r}-${L}`)},`tbl-h-${L}`))})}),e.jsx("tbody",{children:v.map((O,L)=>e.jsx("tr",{className:L<v.length-1?"border-b border-white/[0.06]":void 0,children:m.map((P,U)=>e.jsx("td",{className:"px-3 py-2 text-[13px] leading-relaxed text-white/80 align-top",style:{textAlign:$[U]??"left"},children:qe(O[U]??"",`tbl-r-${r}-${L}-${U}`)},`tbl-r-${L}-c-${U}`))},`tbl-r-${L}`))})]})},`tbl-${r}`));continue}if(o.startsWith("```")){const m=o.slice(3).trim(),p=[];for(r+=1;r<s.length&&!(s[r]??"").trim().startsWith("```");)p.push(s[r]??""),r+=1;r<s.length&&(r+=1),i.push(e.jsxs("div",{className:"rounded-xl border border-white/[0.1] bg-black/40 p-3",children:[m&&e.jsx("p",{className:"mb-1 text-[10px] uppercase tracking-[0.12em] text-white/35",children:m}),e.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap font-mono text-[11px] leading-relaxed text-white/78",children:e.jsx("code",{children:p.join(`
6
+ `)})})]},`code-${r}`));continue}const j=o.match(/^(#{1,3})\s+(.+)$/);if(j){const m=j[1].length,p=j[2],$=m===1?"text-[16px] font-semibold":m===2?"text-[14px] font-semibold":"text-[13px] font-medium";i.push(e.jsx("p",{className:ue("tracking-[-0.01em] text-white",$),children:qe(p,`h-${r}`)},`h-${r}`)),r+=1;continue}if(n.match(/^\s*[-*]\s+(.+)$/)){const m=[];for(;r<s.length;){const $=(s[r]??"").match(/^\s*[-*]\s+(.+)$/);if(!$)break;m.push($[1]),r+=1}i.push(e.jsx("ul",{className:"space-y-1.5 pl-4",children:m.map((p,$)=>e.jsx("li",{className:"list-disc text-[13px] leading-relaxed text-white/78",children:qe(p,`ul-${r}-${$}`)},`ul-${r}-${$}`))},`ul-${r}`));continue}if(n.match(/^\s*\d+\.\s+(.+)$/)){const m=[];for(;r<s.length;){const $=(s[r]??"").match(/^\s*\d+\.\s+(.+)$/);if(!$)break;m.push($[1]),r+=1}i.push(e.jsx("ol",{className:"space-y-1.5 pl-4",children:m.map((p,$)=>e.jsx("li",{className:"list-decimal text-[13px] leading-relaxed text-white/78",children:qe(p,`ol-${r}-${$}`)},`ol-${r}-${$}`))},`ol-${r}`));continue}const d=[];for(;r<s.length;){const m=s[r]??"",p=m.trim();if(!p||/^(#{1,3})\s+/.test(p)||/^\s*[-*]\s+/.test(m)||/^\s*\d+\.\s+/.test(m)||p.startsWith("```"))break;d.push(m),r+=1}i.push(e.jsx("p",{className:"text-[13px] leading-relaxed text-white/78",children:xr(d.join(`
7
+ `),`p-${r}`)},`p-${r}`))}return i}function vt({text:t,mode:s="inline",className:i}){const r=t.replace(/\r\n/g,`
8
+ `);return r.trim()?s==="inline"?e.jsx("span",{className:i,children:qe(r,"inline")}):e.jsx("div",{className:ue("space-y-2",i),children:gr(r)}):null}const br={artifact_created:"⬦",run_failed:"✗",run_started:"▶",run_completed:"✓",decision_requested:"❓",decision_resolved:"✓",delegation:"→",blocker_created:"⚠",milestone_completed:"★"},wr={run_started:b.teal,run_completed:b.lime,run_failed:b.red,artifact_created:b.cyan,decision_requested:b.amber,decision_resolved:b.lime,handoff_requested:b.iris,handoff_claimed:b.teal,handoff_fulfilled:b.lime,blocker_created:b.red,milestone_completed:b.cyan,delegation:b.iris};function yr(t){try{return new Date(t).toLocaleTimeString([],{hour:"numeric",minute:"2-digit"})}catch{return""}}function vr(t){var i;let s=0;for(const r of t){const n=(i=r.metadata)==null?void 0:i.costTotal;typeof n=="number"&&(s+=n)}return s<=0?null:s<.01?`$${s.toFixed(4)}`:`$${s.toFixed(2)}`}const jr=a.memo(function({items:s,session:i,agentName:r,onBack:n}){const o=a.useMemo(()=>[...s].sort((u,w)=>Date.parse(u.timestamp)-Date.parse(w.timestamp)),[s]),c=a.useMemo(()=>vr(o),[o]),l=a.useMemo(()=>{if(o.length<2)return null;const u=Date.parse(o[0].timestamp),d=Date.parse(o[o.length-1].timestamp)-u;return d<6e4?`${Math.round(d/1e3)}s`:d<36e5?`${Math.round(d/6e4)}m`:`${(d/36e5).toFixed(1)}h`},[o]),j=(i==null?void 0:i.title)??r??"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:n,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:b.lime,boxShadow:`0 0 12px ${b.lime}55`}}),e.jsx("h3",{className:"text-[14px] font-semibold text-white",children:Ee(j)})]}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2 text-[10px] text-white/45",children:[r&&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(De,{name:r,hint:(i==null?void 0:i.id)??(i==null?void 0:i.runId)??null,size:"xs"}),e.jsx("span",{children:r})]}),e.jsxs("span",{children:[o.length," turn",o.length!==1?"s":""]}),l&&e.jsx("span",{children:l}),c&&e.jsx("span",{className:"text-white/35",children:c}),(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"?`${b.lime}20`:i.status==="failed"?`${b.red}20`:`${b.teal}20`,color:i.status==="running"?b.lime:i.status==="failed"?b.red:b.teal},children:i.status})]})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-4 py-3",children:[e.jsx(Be,{mode:"popLayout",children:e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute left-[7px] top-3 bottom-3 w-px",style:{backgroundColor:`${b.iris}25`}}),e.jsx("div",{className:"space-y-1",children:o.map((u,w)=>{const d=wr[u.type]??b.iris,m=br[u.type]??"→",p=Ht(u.description),$=Ee(u.title??""),v=u.type==="run_failed",O=u.type==="artifact_created",L=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:w*.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:`${d}20`,color:d,border:`1px solid ${d}40`},children:m}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:`text-[12px] leading-snug ${v?"text-red-400":L?"text-amber-300":O?"text-cyan-300":"text-white/85"}`,children:$}),u.summary&&u.summary!==$&&e.jsx("p",{className:"mt-0.5 text-[11px] leading-relaxed text-white/40",children:Ee(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:yr(u.timestamp)}),p&&e.jsx("span",{className:"text-[9px] text-white/25",children:p})]})]},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}`:"",c?` · ${c}`:""," · ",Se(o[o.length-1].timestamp)]})]})]})}),kr={initial:{opacity:0,y:8,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-4,scale:.98}},Nr=480,Pt={all:"All",messages:"Messages",artifacts:"Artifacts",decisions:"Decisions"};function Cr(t){if(!t)return 0;const s=Date.parse(t);return Number.isFinite(s)?s:0}function Es(t){if(!t)return"";const s=[];for(const[i,r]of Object.entries(t))typeof r=="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(r);return s.join(" ")}function Sr(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 r of i){const n=s[r];if(typeof n=="string"&&n.trim().length>0)return n.trim()}return null}function Ar(t){return t?["artifact","artifacts","artifact_type","artifactType","output","outputs","result","results","payload","toolOutput","toolOutputs","toolResult","toolResults"].some(i=>i in t):!1}function Ir(t){const s=t.metadata,i=Es(t.metadata),r=[t.type,t.kind,t.summary,t.title,t.description,i].filter(c=>typeof c=="string"&&c.trim().length>0).join(" ").toLowerCase();return t.type==="artifact_created"||Ar(s)||/artifact|deliverable|output payload/.test(r)?"artifact":t.type==="decision_requested"||t.type==="decision_resolved"||t.decisionRequired===!0||/decision|approve|approval|reject|review request|request changes/.test(r)?"decision":"message"}function Ke(t){return t.split("_").join(" ")}function Er(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 Mr(t){const s=Number(t);if(!Number.isFinite(s))return"Unknown day";const i=new Date(s),r=new Date,n=new Date(r.getFullYear(),r.getMonth(),r.getDate()),o=new Date(n);return o.setDate(n.getDate()-1),i.getTime()===n.getTime()?"Today":i.getTime()===o.getTime()?"Yesterday":i.toLocaleDateString(void 0,{month:"short",day:"numeric",year:i.getFullYear()===r.getFullYear()?void 0:"numeric"})}function Rt(t){return t==="artifact"?"artifact":t==="decision"?"decision":"message"}function lt(t){return t==="artifact"?b.cyan:t==="decision"?b.amber:b.teal}function _r(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 $r(t){return t==="critical"?b.red:t==="warning"?b.amber:t==="positive"?b.lime:b.teal}function Lr(t){if(!t||Object.keys(t).length===0)return null;try{return JSON.stringify(t,null,2)}catch{return null}}function Fr(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 r of i){const n=s[r];if(n!=null)return{source:r,value:n}}return t.type==="artifact_created"?{source:"metadata",value:s}:null}function Ms(t){if(typeof t=="string")return e.jsx(vt,{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:Ms(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,r])=>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:Ee(i)}),e.jsx("dd",{className:"mt-1 text-[13px] text-white/82",children:typeof r=="string"||typeof r=="number"||typeof r=="boolean"?String(r):Array.isArray(r)?`${r.length} item${r.length===1?"":"s"}`:r&&typeof r=="object"?`${Object.keys(r).length} field${Object.keys(r).length===1?"":"s"}`:"—"})]},i))})}return e.jsx("p",{className:"text-[13px] text-white/55",children:"No artifact payload."})}function Fe(t){if(!t)return null;const s=t.trim();if(!s)return null;const i=Ht(s);return i&&i!==s&&/^[a-z0-9._/-]+$/i.test(s)?i:Ee(s)}function Dr(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():"",r=typeof s.turnId=="string"?s.turnId.trim():"";if(i!=="local_openclaw"||!r)return null;const n=typeof s.sessionKey=="string"&&s.sessionKey.trim().length>0?s.sessionKey.trim():null;return{turnId:r,sessionKey:n,runId:t.runId??null}}function xs(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 Tr(t,s){const r=(Fe(s??t.summary)??Fe(t.description)??Ee(t.title||Ke(t.type))).replace(/\r\n/g,`
9
+ `).replace(/```[\s\S]*?```/g," ").replace(/^\s{0,3}#{1,6}\s+/gm,"").replace(/^\s*[-*]\s+/gm,"").replace(/\s+/g," ").trim(),n=r.split(`
10
+ `).map(c=>xs(c).trim()).filter(c=>c.length>0&&!/^\|?[:\-| ]+\|?$/.test(c));let o=n[0]??xs(r);return o.length<24&&n.length>1&&(o=`${o} ${n[1]}`.trim()),o.length>108?`${o.slice(0,107).trimEnd()}…`:o}const Or=a.memo(function({activity:s,sessions:i,initiatives:r=[],selectedRunIds:n,selectedSessionLabel:o=null,agentFilter:c=null,onClearSelection:l,onClearAgentFilter:j,onFocusRunId:u}){var dt;const w=vs(),[d,m]=a.useState("all"),[p,$]=a.useState(!1),[v,O]=a.useState(""),[L,P]=a.useState(new Set),[U,I]=a.useState("newest"),[z,J]=a.useState(null),[W,ce]=a.useState(null),[re,E]=a.useState(1),[C,_]=a.useState("structured"),[B,A]=a.useState(null),[N,S]=a.useState("feed"),[Z,me]=a.useState(null),[he,K]=a.useState(null),[F,f]=a.useState(!1),q=a.useMemo(()=>{const x=new Map;for(const R of i)x.set(R.runId,R.title),x.set(R.id,R.title);return x},[i]),ee=a.useMemo(()=>{const x=new Map;for(const R of i)R.status&&(x.set(R.runId,R.status),x.set(R.id,R.status));return x},[i]),fe=a.useMemo(()=>{const x=new Map;for(const R of r)x.set(R.id,R.name);return x},[r]),te=a.useMemo(()=>i.filter(x=>x.status==="running"),[i]),le=a.useMemo(()=>s.map(x=>{const R=Sr(x),M=Ir(x),G=[x.title,x.description,x.summary,x.agentName,Es(x.metadata)].filter(Y=>typeof Y=="string"&&Y.length>0).join(" ").toLowerCase();return{item:x,bucket:M,runId:R,timestampEpoch:Cr(x.timestamp),searchText:G}}),[s]),ye=a.useMemo(()=>{let x=0;for(const R of le)x=Math.max(x,R.timestampEpoch);return x<=0?!1:Date.now()-x<6e4},[le]),ie=a.useMemo(()=>{const x={};for(const Me of le)x[Me.item.type]=(x[Me.item.type]??0)+1;const R=[],M=(x.run_failed??0)+(x.blocker_created??0);M>0&&R.push({id:"errors",label:"errors",count:M,color:b.red,types:["run_failed","blocker_created"]});const G=(x.run_completed??0)+(x.milestone_completed??0);G>0&&R.push({id:"completions",label:"completions",count:G,color:b.lime,types:["run_completed","milestone_completed"]});const Y=x.artifact_created??0;Y>0&&R.push({id:"artifacts",label:"artifacts",count:Y,color:b.cyan,types:["artifact_created"]});const ge=(x.decision_requested??0)+(x.decision_resolved??0);ge>0&&R.push({id:"decisions",label:"decisions",count:ge,color:b.amber,types:["decision_requested","decision_resolved"]});const Ne=(x.handoff_requested??0)+(x.handoff_claimed??0)+(x.handoff_fulfilled??0);return Ne>0&&R.push({id:"handoffs",label:"handoffs",count:Ne,color:b.iris,types:["handoff_requested","handoff_claimed","handoff_fulfilled"]}),R},[le]),be=a.useMemo(()=>new Set(n.filter(x=>x&&x.trim().length>0)),[n]),g=be.size>0,H=a.useMemo(()=>{if(!g)return null;for(const x of be){const R=i.find(M=>M.runId===x||M.id===x);if(R)return R}return null},[g,be,i]),{filtered:Q,truncatedCount:y}=a.useMemo(()=>{const x=[];let R=0;const M=v.trim().toLowerCase();for(const Y of le){const ge=Y.runId;if(g&&(!ge||!be.has(ge))||c&&Y.item.agentName!==c)continue;const Ne=Y.bucket;if(!(d==="messages"&&Ne!=="message")&&!(d==="artifacts"&&Ne!=="artifact")&&!(d==="decisions"&&Ne!=="decision")){if(M.length>0){const Me=ge?q.get(ge)??ge:"";if(!`${Y.searchText} ${Me.toLowerCase()}`.includes(M))continue}x.length<Nr?x.push(Y):R+=1}}return{filtered:[...x].sort((Y,ge)=>{const Ne=ge.timestampEpoch-Y.timestampEpoch;return U==="newest"?Ne:-Ne}),truncatedCount:R}},[d,c,le,g,v,q,be,U]),X=a.useMemo(()=>{const x=new Map;for(const M of Q){const G=Er(M.item.timestamp),Y=x.get(G);Y?Y.push(M):x.set(G,[M])}return Array.from(x.keys()).sort((M,G)=>{const Y=Number(G)-Number(M);return U==="newest"?Y:-Y}).map(M=>({key:M,label:Mr(M),items:x.get(M)??[]}))},[Q,U]),ve=a.useMemo(()=>X.map(x=>{const R=new Map;for(const M of x.items){const G=`${M.item.type}::${M.item.title}`,Y=R.get(G);Y?(Y.count+=1,Y.firstTimestamp=Math.min(Y.firstTimestamp,M.timestampEpoch),Y.allItems.push(M),M.timestampEpoch>Y.representative.timestampEpoch&&(Y.representative=M)):R.set(G,{key:G,representative:M,count:1,firstTimestamp:M.timestampEpoch,allItems:[M]})}return{...x,clusters:Array.from(R.values())}}),[X]),ae=a.useCallback(x=>{P(R=>{const M=new Set(R);return M.has(x)?M.delete(x):M.add(x),M})},[]),se=a.useMemo(()=>z?Q.findIndex(x=>x.item.id===z):-1,[z,Q]),D=se>=0?Q[se]:null,ne=a.useMemo(()=>Fr((D==null?void 0:D.item)??null),[D]),we=a.useMemo(()=>Lr((D==null?void 0:D.item.metadata)??void 0),[D]),Xe=a.useMemo(()=>{const x=Fe(B);return x||(Fe(D==null?void 0:D.item.summary)??Fe(D==null?void 0:D.item.description))},[B,D]),Pe=a.useCallback(()=>{J(null)},[]);a.useEffect(()=>{if(!W)return;const x=window.setTimeout(()=>ce(null),2e3);return()=>window.clearTimeout(x)},[W]);const Re=a.useCallback(async(x,R)=>{if(R)try{await navigator.clipboard.writeText(R),ce(`${x} copied`)}catch{ce("Copy failed")}},[]);a.useEffect(()=>{_("structured")},[z]),a.useEffect(()=>{A(null),S("feed");const x=Dr((D==null?void 0:D.item)??null);if(!x)return;const R=new URLSearchParams({turnId:x.turnId});x.sessionKey&&R.set("sessionKey",x.sessionKey),x.runId&&R.set("run",x.runId);const M=new AbortController;return fetch(`/orgx/api/live/activity/detail?${R.toString()}`,{method:"GET",signal:M.signal}).then(async G=>{var ge;return G.ok?((ge=(await G.json()).detail)==null?void 0:ge.summary)??null:(G.status===404&&S("missing"),null)}).then(G=>{typeof G=="string"&&G.trim().length>0?(A(G),S("local")):S("missing")}).catch(G=>{G instanceof DOMException&&G.name==="AbortError"||S("missing")}),()=>M.abort()},[D]),a.useEffect(()=>{me(null),K(null);const x=D==null?void 0:D.item;if(!x||F)return;const R=(B??x.summary??x.description??x.title??"").trim();if(!R)return;const M=new AbortController;return fetch("/orgx/api/live/activity/headline",{method:"POST",headers:{"Content-Type":"application/json"},signal:M.signal,body:JSON.stringify({text:R,title:x.title??null,type:x.type})}).then(async G=>G.ok?await G.json():((G.status===404||G.status===405)&&f(!0),null)).then(G=>{const Y=G==null?void 0:G.headline;typeof Y=="string"&&Y.trim().length>0&&(f(!1),me(Y.trim()),K((G==null?void 0:G.source)??null))}).catch(G=>{G instanceof DOMException&&G.name}),()=>M.abort()},[D,B,F]);const Te=a.useCallback(x=>{var G;if(Q.length===0)return;const M=((se>=0?se:0)+x+Q.length)%Q.length;E(x),J(((G=Q[M])==null?void 0:G.item.id)??null)},[se,Q]);a.useEffect(()=>{z&&(se>=0||J(null))},[se,z]),a.useEffect(()=>{if(!z)return;const x=R=>{R.key==="ArrowRight"||R.key.toLowerCase()==="l"?(R.preventDefault(),Te(1)):(R.key==="ArrowLeft"||R.key.toLowerCase()==="h")&&(R.preventDefault(),Te(-1))};return window.addEventListener("keydown",x),()=>window.removeEventListener("keydown",x)},[z,Te]);const Ue=be.size===1,$e=Ue?[...be][0]:null,We=$e?i.find(x=>x.runId===$e||x.id===$e)??null:null,tt=a.useMemo(()=>Ue?le.filter(x=>x.runId&&be.has(x.runId)).map(x=>x.item):[],[Ue,le,be]),ct=!w&&Q.length<=160,ke=(x,R)=>{const M=x.item,G=_r(M),Y=$r(G),ge=U==="newest"&&R<2,Ne=x.bucket,Me=x.runId,st=Me?q.get(Me)??Ee(Me):"Workspace",ut=Me?ee.get(Me)??null:null,Ge=Ee(M.title??""),nt=Fe(M.summary),Qe=Fe(M.description),rt=M.initiativeId?fe.get(M.initiativeId)??null:null,ht=lt(Ne),h=Rt(Ne),V=G==="critical"?"Error":G==="warning"?"Needs review":G==="positive"?"Completed":"Update",T=new Date(M.timestamp).toLocaleTimeString([],{hour:"numeric",minute:"2-digit"}),k="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",oe=e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"mt-0.5",children:e.jsx(De,{name:M.agentName??"OrgX",hint:`${M.agentId??""} ${st} ${M.title??""}`,size:"xs"})}),e.jsxs("div",{className:"relative min-w-0 flex-1 pl-3",children:[e.jsx("span",{className:ue("absolute inset-y-0 left-0 w-[2px] rounded-full",ge&&"pulse-soft"),style:{backgroundColor:Y,boxShadow:`0 0 14px ${Y}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:Ge||Ee(M.title||Ke(M.type))}),e.jsxs("p",{className:"mt-0.5 text-[11px] text-white/48",children:[M.agentName??"OrgX",ut?` · ${Ee(ut)}`:""]})]}),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:h}),e.jsx("span",{className:"text-[11px] text-white/55",children:T})]})]}),(nt||Qe)&&e.jsx("div",{className:"mt-1.5 line-clamp-2 text-[11px] leading-relaxed text-white/62",children:e.jsx(vt,{mode:"inline",text:nt??Qe??""})}),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:`${Y}55`,backgroundColor:`${Y}1A`,color:Y},children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full",style:{backgroundColor:Y}}),V]}),e.jsx("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.02] px-2 py-0.5 text-white/60",children:st}),e.jsx("span",{className:"rounded-full border px-2 py-0.5 text-white/62",style:{borderColor:`${ht}44`,color:ht},children:Ee(Ke(M.type))}),e.jsx("span",{className:"text-white/55",children:Se(M.timestamp)}),rt&&e.jsxs("span",{className:"truncate text-white/42",title:rt,children:["· ",rt]})]})]})]});return ct?e.jsx(de.button,{type:"button",variants:kr,initial:"initial",animate:"animate",exit:"exit",transition:{duration:.25,ease:[.4,0,.2,1]},whileHover:{y:-1.5},whileTap:{scale:.995},onClick:()=>{E(1),J(M.id)},className:k,"aria-label":`Open activity details for ${Ge||Ke(M.type)}`,children:oe},M.id):e.jsx("button",{type:"button",onClick:()=>{E(1),J(M.id)},className:ue(k,"transform-gpu transition-[transform,background-color,border-color,color] hover:-translate-y-[1px] active:scale-[0.995]"),"aria-label":`Open activity details for ${Ge||Ke(M.type)}`,children:oe},M.id)};return e.jsxs(Ve,{className:"flex h-full min-h-0 flex-col card-enter",children:[Ue&&tt.length>0?e.jsx(jr,{items:tt,session:We,agentName:((dt=tt[0])==null?void 0:dt.agentName)??null,onBack:l}):e.jsxs(e.Fragment,{children:[te.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"}),te.map(x=>e.jsxs("button",{type:"button",onClick:()=>u==null?void 0:u(x.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(De,{name:x.agentName??"OrgX",size:"xs",hint:x.agentName}),e.jsx("span",{className:"max-w-[140px] truncate text-[11px] text-white/70",children:x.title})]},x.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:Q.length}),y>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:["+",y," hidden"]}),e.jsx("span",{className:ue("h-1.5 w-1.5 rounded-full",ye&&"pulse-soft"),style:{backgroundColor:b.lime},"aria-label":"Live",title:ye?"New activity within the last minute":"Live activity feed"}),g&&e.jsxs("button",{onClick:l,className:"chip inline-flex min-w-0 items-center gap-2","aria-label":"Clear session filter",children:[e.jsx(De,{name:(H==null?void 0:H.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:"×"})]}),c&&e.jsxs("button",{onClick:j,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(De,{name:c,hint:c,size:"xs"}),e.jsxs("span",{className:"min-w-0 truncate",children:["Agent: ",c]}),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:()=>I(x=>x==="newest"?"oldest":"newest"),className:"control-pill px-3 text-[11px] font-medium","aria-label":U==="newest"?"Sort oldest first":"Sort newest first",children:U==="newest"?"Newest":"Oldest"}),e.jsx("button",{type:"button",onClick:()=>$(x=>!x),"data-state":p?"active":"idle",className:"control-pill px-3 text-[11px] font-medium","aria-pressed":p,children:p?"Expand":"Compact"})]})]}),ie.length>0&&e.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-1.5",children:ie.map(x=>e.jsxs("button",{type:"button",onClick:()=>{x.id==="errors"||x.id==="completions"?m("messages"):x.id==="artifacts"?m("artifacts"):x.id==="decisions"?m("decisions"):m("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:x.color}}),e.jsx("span",{className:"font-semibold text-white",style:{fontVariantNumeric:"tabular-nums"},children:x.count}),e.jsx("span",{className:"text-white/45",children:x.label})]},x.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:v,onChange:x=>O(x.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(Pt).map(x=>{const R=d===x;return e.jsx("button",{type:"button",onClick:()=>m(x),"aria-pressed":R,className:ue("rounded-full px-3 py-1.5 text-[10px] font-semibold transition-colors",R?"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:Pt[x]},x)})})]})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-4 py-3",children:[Q.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:g?`No ${Pt[d].toLowerCase()} for the selected session.`:"No matching activity right now."}),g&&e.jsx("button",{onClick:l,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:"Show all sessions"})]}),Q.length>0&&e.jsxs("div",{className:"space-y-4",children:[ve.map(x=>{const R=p?x.clusters.slice(0,4):x.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:x.label}),ct?e.jsx(Be,{mode:"popLayout",children:e.jsx("div",{className:"space-y-2",children:R.map((M,G)=>{const Y=L.has(M.key);return M.count===1?ke(M.representative,G):e.jsxs("div",{children:[ke(M.representative,G),e.jsxs("button",{type:"button",onClick:ge=>{ge.stopPropagation(),ae(M.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:["×",M.count]}),e.jsx("span",{className:"text-white/35",children:"·"}),e.jsxs("span",{children:["first seen ",Se(M.firstTimestamp)]}),e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:ue("transition-transform",Y?"rotate-0":"-rotate-90"),children:e.jsx("path",{d:"m6 9 6 6 6-6"})})]}),Y&&e.jsx("div",{className:"ml-8 mt-1 space-y-1.5 border-l border-white/[0.06] pl-3",children:M.allItems.slice(1).map((ge,Ne)=>ke(ge,G+Ne+1))})]},M.key)})})}):e.jsx("div",{className:"space-y-2",children:R.map((M,G)=>{const Y=L.has(M.key);return M.count===1?ke(M.representative,G):e.jsxs("div",{children:[ke(M.representative,G),e.jsxs("button",{type:"button",onClick:ge=>{ge.stopPropagation(),ae(M.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:["×",M.count]}),e.jsx("span",{className:"text-white/35",children:"·"}),e.jsxs("span",{children:["first seen ",Se(M.firstTimestamp)]}),e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:ue("transition-transform",Y?"rotate-0":"-rotate-90"),children:e.jsx("path",{d:"m6 9 6 6 6-6"})})]}),Y&&e.jsx("div",{className:"ml-8 mt-1 space-y-1.5 border-l border-white/[0.06] pl-3",children:M.allItems.slice(1).map((ge,Ne)=>ke(ge,G+Ne+1))})]},M.key)})}),p&&x.clusters.length>R.length&&e.jsxs("p",{className:"mt-1.5 text-[11px] text-white/35",children:["+",x.clusters.length-R.length," more"]})]},x.key)}),y>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 ",Q.length," events (",y," older events omitted for smooth rendering)."]})]})]})]}),e.jsx(et,{open:D!==null,onClose:Pe,maxWidth:"max-w-3xl",children:D&&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:lt(D.bucket),boxShadow:`0 0 16px ${lt(D.bucket)}77`}}),e.jsxs("span",{className:"text-[12px] text-white/70",children:[Rt(D.bucket)," · ",se+1,"/",Q.length]}),W&&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:W})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[D.runId&&u&&e.jsx("button",{type:"button",onClick:()=>{u(D.runId),Pe()},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"}),D.runId&&e.jsx("button",{type:"button",onClick:()=>void Re("Run id",D.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"}),D.item.agentId&&e.jsx("button",{type:"button",onClick:()=>void Re("Agent id",D.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 Re("Event id",D.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:()=>Te(-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:()=>Te(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:Pe,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(Be,{mode:"wait",custom:re,children:e.jsx(de.section,{custom:re,initial:{opacity:0,x:re*44,scale:.985},animate:{opacity:1,x:0,scale:1},exit:{opacity:0,x:re*-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||Tr(D.item,B)||Ee(D.item.title||Ke(D.item.type))}),e.jsxs("p",{className:"mt-1 flex flex-wrap items-center gap-x-2 text-[12px] text-white/45",children:[new Date(D.item.timestamp).toLocaleString()," · ",Se(D.item.timestamp),he==="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:`${lt(D.bucket)}55`,color:lt(D.bucket)},children:Rt(D.bucket)}),e.jsx("span",{className:"rounded-full border border-white/[0.12] px-2 py-0.5 text-white/65",children:Ke(D.item.type)}),D.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(De,{name:D.item.agentName,hint:`${D.item.agentId??""} ${D.item.title??""}`,size:"xs"}),e.jsx("span",{children:D.item.agentName})]}),D.runId&&e.jsx("span",{className:"rounded-full border border-white/[0.12] px-2 py-0.5 text-white/65",children:q.get(D.runId)??Ee(D.runId)})]}),Xe&&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"}),N==="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(vt,{mode:"block",text:Xe,className:"mt-1.5 text-[14px] leading-relaxed text-white/82"})]}),Fe(D.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(vt,{mode:"block",text:Fe(D.item.description)??"",className:"mt-1.5 text-[13px] leading-relaxed text-white/75"})]}),ne&&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:()=>_("structured"),"aria-pressed":C==="structured",className:`rounded-full px-2.5 py-0.5 transition-colors ${C==="structured"?"bg-white/[0.12] text-white":"text-white/55 hover:text-white/80"}`,children:"Structured"}),e.jsx("button",{type:"button",onClick:()=>_("json"),"aria-pressed":C==="json",className:`rounded-full px-2.5 py-0.5 transition-colors ${C==="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: ",ne.source]}),e.jsx("div",{className:"mt-2",children:C==="structured"?Ms(ne.value):e.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap font-mono text-[11px] leading-relaxed text-white/70",children:JSON.stringify(ne.value,null,2)})})]}),we&&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:we})]})]})},D.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"})]})})]})}),Ut=40;function ms(t){return t>=15?{border:b.red,glow:`0 0 16px ${b.red}20`}:t>=5?{border:b.amber,glow:`0 0 12px ${b.amber}18`}:{border:b.teal,glow:"none"}}const Br=a.memo(function({decisions:s,onApproveDecision:i,onApproveAll:r}){const n=vs(),[o,c]=a.useState(!1),[l,j]=a.useState(new Set),[u,w]=a.useState(new Set),[d,m]=a.useState(null),[p,$]=a.useState(Ut),v=a.useMemo(()=>[...s].sort((E,C)=>{if(E.waitingMinutes!==C.waitingMinutes)return C.waitingMinutes-E.waitingMinutes;const _=Date.parse(E.requestedAt??E.updatedAt??""),B=Date.parse(C.requestedAt??C.updatedAt??""),A=Number.isFinite(_)?_:0;return(Number.isFinite(B)?B:0)-A}),[s]);a.useEffect(()=>{w(E=>{const C=new Set(v.map(B=>B.id)),_=new Set;for(const B of E)C.has(B)&&_.add(B);return _})},[v]);const O=u.size,L=a.useMemo(()=>v.slice(0,p),[v,p]),P=a.useMemo(()=>{if(L.length===0)return!1;for(const E of L)if(!u.has(E.id))return!1;return!0},[u,L]);a.useEffect(()=>{$(E=>v.length===0?0:Math.min(Math.max(Ut,E),v.length))},[v.length]);const U=E=>{w(C=>{const _=new Set(C);return _.has(E)?_.delete(E):_.add(E),_})},I=()=>{w(E=>{if(L.length===0)return E;const C=new Set(E),_=P;for(const B of L)_?C.delete(B.id):C.add(B.id);return C})},z=async()=>{if(!(v.length===0||o)){m(null),c(!0);try{const E=await r();E.failed>0?m(`Approved ${E.updated}; ${E.failed} failed.`):E.updated>0?m(`Approved ${E.updated} decision${E.updated===1?"":"s"}.`):m("No decisions were updated."),w(new Set)}catch(E){m(E instanceof Error?E.message:"Bulk approval failed.")}finally{c(!1)}}},J=async()=>{if(O===0||o)return;m(null),c(!0);let E=0,C=0;try{const _=v.map(B=>B.id).filter(B=>u.has(B));for(const B of _){j(A=>new Set(A).add(B));try{const A=await i(B);E+=A.updated,C+=A.failed}catch{C+=1}finally{j(A=>{const N=new Set(A);return N.delete(B),N})}}C>0?m(`Approved ${E}; ${C} failed.`):m(`Approved ${E} selected decision${E===1?"":"s"}.`),w(new Set)}finally{c(!1)}},W=async E=>{if(!(l.has(E)||o)){m(null),j(C=>{const _=new Set(C);return _.add(E),_});try{const C=await i(E);C.failed>0?m(`Approval failed for ${C.failed} decision.`):C.updated>0&&m("Decision approved.")}catch(C){m(C instanceof Error?C.message:"Decision approval failed.")}finally{j(C=>{const _=new Set(C);return _.delete(E),_}),w(C=>{if(!C.has(E))return C;const _=new Set(C);return _.delete(E),_})}}},ce=d!==null&&!d.toLowerCase().includes("fail"),re=!n&&L.length<=32;return e.jsxs(Ve,{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.jsx("h2",{className:"text-[14px] font-semibold text-white",children:"Decisions"}),e.jsx("p",{className:"text-[12px] text-white/45",children:"Select multiple items to bulk review and approve"})]}),e.jsx("button",{onClick:z,disabled:v.length===0||o,className:"rounded-lg px-3 py-1.5 text-[11px] font-semibold transition-colors",style:{backgroundColor:v.length===0||o?"rgba(255,255,255,0.08)":b.lime,color:v.length===0||o?"rgba(255,255,255,0.45)":"#000"},children:o?"Approving…":`Approve all (${v.length})`})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{onClick:I,disabled:v.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:P?"Clear all":"Select all"}),e.jsx("button",{onClick:J,disabled:O===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 (${O})`}),e.jsx("span",{className:"text-[11px] text-white/45",children:O>0?`${O} selected`:"No selection"})]})]}),e.jsxs("div",{className:"min-h-0 flex-1 space-y-2 overflow-y-auto p-3",children:[v.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."})]}),re?e.jsx(Be,{mode:"popLayout",children:L.map(E=>{const C=l.has(E.id),_=ms(E.waitingMinutes),B=u.has(E.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:B?`${b.lime}50`:`${_.border}35`,borderLeftWidth:3,borderLeftColor:`${_.border}80`,boxShadow:_.glow},children:e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx("input",{type:"checkbox",checked:B,onChange:()=>U(E.id),disabled:C||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.jsx("p",{className:"text-[13px] font-medium text-white",children:E.title}),E.context&&e.jsx("p",{className:"mt-1 line-clamp-2 text-[11px] text-white/55",children:E.context}),e.jsxs("p",{className:"mt-1.5 text-[10px] text-white/40",children:[E.agentName??"System"," · Waiting ",E.waitingMinutes,"m",E.requestedAt?` · ${Se(E.requestedAt)}`:""]})]}),e.jsx("button",{onClick:()=>W(E.id),disabled:C||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:C?"Approving…":"Approve"})]})})]})},E.id)})}):e.jsx(e.Fragment,{children:L.map(E=>{const C=l.has(E.id),_=ms(E.waitingMinutes),B=u.has(E.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:B?`${b.lime}50`:`${_.border}35`,borderLeftWidth:3,borderLeftColor:`${_.border}80`,boxShadow:_.glow},children:e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx("input",{type:"checkbox",checked:B,onChange:()=>U(E.id),disabled:C||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.jsx("p",{className:"text-[13px] font-medium text-white",children:E.title}),E.context&&e.jsx("p",{className:"mt-1 line-clamp-2 text-[11px] text-white/55",children:E.context}),e.jsxs("p",{className:"mt-1.5 text-[10px] text-white/40",children:[E.agentName??"System"," · Waiting ",E.waitingMinutes,"m",E.requestedAt?` · ${Se(E.requestedAt)}`:""]})]}),e.jsx("button",{onClick:()=>W(E.id),disabled:C||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:C?"Approving…":"Approve"})]})})]})},E.id)})}),L.length<v.length&&e.jsxs("button",{onClick:()=>$(E=>Math.min(v.length,E+Ut)),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 (",v.length-L.length," remaining)"]})]}),d&&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:ce?"text-lime":"text-amber-400",children:ce?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"})]})}),d]})]})});function Pr({value:t,onChange:s,placeholder:i}){return e.jsxs("label",{className:"relative block",children:[e.jsx("span",{className:"sr-only",children:i}),e.jsxs("svg",{className:"pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-white/35",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"11",cy:"11",r:"8"}),e.jsx("path",{d:"m21 21-4.3-4.3"})]}),e.jsx("input",{type:"text",value:t,onChange:r=>s(r.target.value),placeholder:i,className:"w-full rounded-xl border border-white/[0.08] bg-white/[0.03] py-2.5 pl-10 pr-8 text-[13px] text-white placeholder:text-white/35 transition-all focus:border-[#BFFF00]/30 focus:bg-white/[0.05] focus:outline-none"}),t.length>0&&e.jsx("button",{type:"button",onClick:()=>s(""),className:"absolute right-2.5 top-1/2 -translate-y-1/2 rounded-full p-0.5 text-white/40 transition-colors hover:text-white/70","aria-label":"Clear search",children:e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:e.jsx("path",{d:"M18 6 6 18M6 6l12 12"})})})]})}function Rr(t,s){if(t.length===0)return 0;if(s>=t.length-1&&t.every(n=>n.status==="completed"))return 100;const i=s/Math.max(1,t.length-1)*100,r=t[s];return r?r.status==="completed"?Math.min(100,i+100/t.length):r.status==="current"||r.status==="warning"?Math.min(100,i+50/t.length):i:i}function Ur({phases:t,currentPhase:s,health:i}){const r=Rr(t,s);return e.jsxs("div",{className:"space-y-2.5",children:[e.jsxs("div",{className:"flex items-center justify-between text-[9px] uppercase tracking-[0.1em] text-white/38",children:[e.jsx("span",{children:"Momentum"}),e.jsxs("span",{children:[Math.round(i??r),"%"]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"h-2 rounded-full bg-white/[0.08]"}),e.jsx("div",{className:"absolute inset-y-0 left-0 rounded-full",style:{width:`${Math.max(0,Math.min(100,r))}%`,background:`linear-gradient(90deg, ${b.lime}, ${b.teal})`,boxShadow:`0 0 18px ${b.teal}45`}}),t.map((n,o)=>{const c=o/Math.max(1,t.length-1)*100,l=n.status==="completed",j=n.status==="current",u=n.status==="warning";return e.jsx("div",{className:"absolute top-1/2 z-10 -translate-y-1/2",style:{left:`${c}%`,transform:"translate(-50%, -50%)"},children:e.jsx("div",{className:ue("flex h-4 w-4 items-center justify-center rounded-full border text-[9px] font-semibold",l&&"border-lime/80 bg-lime text-black",j&&"border-lime/60 bg-lime/30 text-lime",u&&"border-amber-300/70 bg-amber-300 text-black",!l&&!j&&!u&&"border-white/20 bg-black/60 text-white/45"),children:l?"✓":u?"!":""})},n.name)})]}),e.jsx("div",{className:"grid gap-1",style:{gridTemplateColumns:`repeat(${Math.max(t.length,1)}, minmax(0, 1fr))`},children:t.map(n=>e.jsx("span",{className:ue("truncate text-[8px] uppercase tracking-[0.12em]",n.status==="completed"||n.status==="current"?"text-white/60":"text-white/30"),children:n.name},n.name))})]})}function Wr({names:t}){return e.jsx("div",{className:"flex -space-x-1.5",children:t.slice(0,3).map((s,i)=>e.jsx("div",{className:"relative",style:{zIndex:t.length-i},children:e.jsx(De,{name:s,size:"xs"})},`${s}-${i}`))})}function zr(t){return t==="blocked"?{text:"Watch",className:"border-amber-300/45 bg-amber-300/10 text-amber-200"}:t==="completed"?{text:"Done",className:"border-lime/45 bg-lime/15 text-lime"}:t==="paused"?{text:"Paused",className:"border-white/20 bg-white/[0.04] text-white/60"}:{text:"In Motion",className:"border-teal/45 bg-teal/10 text-teal"}}function Kr({initiative:t,onClick:s}){var l;const i=t.phases??[],r=t.currentPhase??0,n=t.avatars??[],o=zr(t.status),c=((l=t.workstreams)==null?void 0:l.length)??0;return e.jsxs("button",{onClick:s,className:"w-full rounded-xl border border-white/[0.08] bg-[linear-gradient(150deg,rgba(20,184,166,0.15),rgba(2,4,10,0.7)_42%,rgba(2,4,10,0.95))] p-3 text-left transition-all duration-200 hover:border-white/[0.16] hover:bg-[linear-gradient(150deg,rgba(20,184,166,0.22),rgba(2,4,10,0.72)_42%,rgba(2,4,10,0.95))]",children:[e.jsxs("div",{className:"mb-2 flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[n.length>0&&e.jsx(Wr,{names:n}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("span",{className:`rounded-full border px-1.5 py-0.5 text-[10px] uppercase tracking-[0.1em] ${o.className}`,children:o.text}),e.jsx("span",{className:"rounded-full border border-white/[0.16] bg-white/[0.03] px-1.5 py-0.5 text-[10px] uppercase tracking-[0.1em] text-white/60",children:t.category??"Program"})]}),e.jsx("h4",{className:"mt-1 text-[13px] font-semibold text-white",children:t.name})]})]}),e.jsx("span",{className:"text-[12px] text-white/45",style:{fontVariantNumeric:"tabular-nums"},children:t.health===0&&c===0?"Awaiting setup":`${t.health}%`})]}),t.description&&e.jsx("p",{className:"mb-2 line-clamp-2 text-[11px] text-white/65",children:t.description}),i.length>0&&e.jsx(Ur,{phases:i,currentPhase:r,health:t.health}),t.health===0&&c===0&&t.activeAgents===0&&e.jsx("p",{className:"mt-1.5 text-[10px] text-white/30",children:"No workstreams started. Create a workstream to begin."}),e.jsxs("div",{className:"mt-2.5 grid grid-cols-3 gap-1.5 text-[10px] uppercase tracking-[0.08em]",children:[e.jsxs("div",{className:"rounded-md border border-white/[0.1] bg-black/25 px-2 py-1.5",children:[e.jsx("p",{className:"text-white/35",children:"Live Streams"}),e.jsx("p",{className:"text-[12px] font-semibold text-white",children:t.activeAgents})]}),e.jsxs("div",{className:"rounded-md border border-white/[0.1] bg-black/25 px-2 py-1.5",children:[e.jsx("p",{className:"text-white/35",children:"Total Streams"}),e.jsx("p",{className:"text-[12px] font-semibold text-white",children:t.totalAgents})]}),e.jsxs("div",{className:"rounded-md border border-white/[0.1] bg-black/25 px-2 py-1.5",children:[e.jsx("p",{className:"text-white/35",children:"Workstreams"}),e.jsx("p",{className:`text-[12px] font-semibold ${c===0?"text-white/35":"text-white"}`,children:c===0?"None yet":c})]})]})]})}function qr({initiatives:t,onInitiativeClick:s,onCreateInitiative:i,onCreateWorkstream:r}){const[n,o]=a.useState(""),[c,l]=a.useState(0),[j,u]=a.useState(null),w=3,d=a.useMemo(()=>t.filter(O=>O.name.toLowerCase().includes(n.toLowerCase())),[t,n]),m=Math.max(1,Math.ceil(d.length/w)),p=Math.min(c,Math.max(0,m-1)),$=d.slice(p*w,(p+1)*w),v=async(O,L)=>{if(!(!L||j)){u(O);try{await L()}finally{u(null)}}};return e.jsxs(Ve,{className:"flex h-full min-h-0 flex-1 flex-col card-enter",children:[e.jsxs("div",{className:"flex-shrink-0 space-y-2 border-b border-white/[0.06] px-4 py-3.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-[14px] font-semibold text-white",children:"Initiatives"}),e.jsx("span",{className:"text-[12px] text-white/35",children:t.length})]}),e.jsx(Pr,{value:n,onChange:O=>{o(O),l(0)},placeholder:"Search initiatives..."}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("button",{onClick:()=>v("initiative",i),disabled:!i||j!==null,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:j==="initiative"?"Creating…":"Start initiative"}),e.jsx("button",{onClick:()=>v("workstream",r),disabled:!r||j!==null,className:"rounded-md border border-white/[0.12] bg-white/[0.03] px-2.5 py-1.5 text-[11px] text-white/75 transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:j==="workstream"?"Creating…":"Start workstream"})]})]}),e.jsxs("div",{className:"flex-1 space-y-2 overflow-y-auto p-3",children:[$.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:"M2 3h6a4 4 0 0 1 4 4v14a3 3 0 0 0-3-3H2z"}),e.jsx("path",{d:"M22 3h-6a4 4 0 0 0-4 4v14a3 3 0 0 1 3-3h7z"})]}),e.jsx("p",{className:"text-[12px] text-white/45",children:t.length===0?"No active initiatives yet. Start one above.":"No initiatives match this search."})]}),$.map(O=>e.jsx(Kr,{initiative:O,onClick:()=>s(O)},O.id))]}),m>1&&e.jsx("div",{className:"flex-shrink-0 overflow-visible border-t border-white/[0.06] px-4 py-2.5",children:e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("button",{onClick:()=>l(Math.max(0,p-1)),disabled:p===0,className:"flex-shrink-0 rounded p-1.5 text-white/45 transition-colors hover:text-white disabled:opacity-30",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"m15 18-6-6 6-6"})})}),e.jsx("div",{className:"flex min-w-0 flex-1 items-center justify-center gap-1.5 overflow-x-auto",children:Array.from({length:m}).map((O,L)=>e.jsx("button",{type:"button",onClick:()=>l(L),"aria-label":`Page ${L+1}`,className:"rounded-full p-1 transition-colors",children:e.jsx("span",{className:"block h-2.5 w-2.5 rounded-full transition-colors",style:{backgroundColor:L===p?b.lime:"rgba(255,255,255,0.25)"}})},L))}),e.jsx("button",{onClick:()=>l(Math.min(m-1,p+1)),disabled:p>=m-1,className:"flex-shrink-0 rounded p-1.5 text-white/45 transition-colors hover:text-white disabled:opacity-30",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"m9 18 6-6-6-6"})})})]})})]})}function Vr(t){const s=(t??"").toLowerCase();return s==="completed"||s==="done"?"completed":s==="blocked"||s==="at_risk"?"blocked":s==="paused"||s==="hold"?"paused":"active"}function Hr(t){const s=(t??"").toLowerCase();return!["deleted","archived","cancelled"].includes(s)}function Xr(t){return{id:t.id,name:t.title,status:Vr(t.status),rawStatus:t.status??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 Gr(t){return He({queryKey:Vt.liveInitiatives({limit:300}),queryFn:async()=>{const s=await fetch("/orgx/api/live/initiatives?limit=300");return s.ok?((await s.json()).initiatives??[]).filter(r=>Hr(r.status)).map(Xr):[]},enabled:t,staleTime:3e4})}function Qr(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 Yr(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 Jr(t){return t==="awaiting_browser_auth"||t==="pairing"||t==="starting"?"active":t==="error"?"error":t==="connected"?"active":"idle"}const fs={idle:"bg-white/40",active:"bg-[#BFFF00]",error:"bg-red-400"};function Zr({state:t,isStarting:s,isSubmittingManual:i,onRefresh:r,onStartPairing:n,onSubmitManualKey:o,onBackToPairing:c,onUseManualKey:l,onDisconnect:j}){const u=t.status==="manual_key",w=t.status==="awaiting_browser_auth"||t.status==="pairing",d=Jr(t.status),m=d==="active"&&t.status!=="connected",p=!!t.lastError,$=a.useMemo(()=>t.status==="connected"&&t.connectionVerified?"Live sync active.":w?"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.",[w,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:$}),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:[m&&e.jsx("span",{className:`absolute inline-flex h-full w-full animate-ping rounded-full ${fs[d]} opacity-40`}),e.jsx("span",{className:`relative inline-flex h-2 w-2 rounded-full ${fs[d]}`})]}),e.jsx("span",{className:"text-white/80",children:Qr(t.status)})]}),t.workspaceName&&e.jsx("span",{className:"chip",children:t.workspaceName}),t.keySource&&t.keySource!=="none"&&e.jsx("span",{className:"chip",children:Yr(t.keySource)}),t.hasApiKey&&!t.connectionVerified&&e.jsx("span",{className:"chip text-amber-100/90",children:"key present, not verified"})]})]}),p&&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(Cs,{isSubmitting:i,onSubmit:o,onBack:c}):e.jsxs("div",{className:"rounded-2xl border border-white/[0.07] bg-white/[0.02] p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>{n()},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:()=>{j()},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:()=>{r()},className:ue("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&&(w||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 _s=[{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 gs(t){return t==="openai"?"openaiApiKey":t==="anthropic"?"anthropicApiKey":"openrouterApiKey"}function ei(t){var s;return((s=_s.find(i=>i.id===t))==null?void 0:s.label)??t}function ti({authToken:t=null,embedMode:s=!1,enabled:i=!0}){const r=Ss({authToken:t,embedMode:s,enabled:i}),n=r.status,o=r.health,[c,l]=a.useState({openai:"",anthropic:"",openrouter:""}),[j,u]=a.useState({openai:!1,anthropic:!1,openrouter:!1}),[w,d]=a.useState({openai:!1,anthropic:!1,openrouter:!1}),[m,p]=a.useState(null),[$,v]=a.useState(null);a.useEffect(()=>{i&&(l({openai:"",anthropic:"",openrouter:""}),u({openai:!1,anthropic:!1,openrouter:!1}),d({openai:!1,anthropic:!1,openrouter:!1}),p(null),v(null))},[i]);const O=a.useMemo(()=>n!=null&&n.ok?Number(n.providers.openai.configured)+Number(n.providers.anthropic.configured)+Number(n.providers.openrouter.configured):0,[n]),L=async I=>{if(!i)return;v(null);const z=c[I].trim();if(!j[I])return;if(!z){v(`Enter a ${ei(I)} API key or use "Clear" to remove the saved key.`);return}const J=gs(I);try{p(I),await r.update({[J]:z}),u(W=>({...W,[I]:!1})),l(W=>({...W,[I]:""})),d(W=>({...W,[I]:!1}))}finally{p(null)}},P=async I=>{v(null);const z=gs(I);try{p(I),await r.update({[z]:null}),u(J=>({...J,[I]:!1})),l(J=>({...J,[I]:""})),d(J=>({...J,[I]:!1}))}finally{p(null)}},U=async()=>{v(null),await r.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."}),O===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:[O," / 3 configured"]}),(n==null?void 0:n.updatedAt)&&e.jsxs("span",{className:"text-[11px] text-white/35",children:["Updated ",new Date(n.updatedAt).toLocaleString()]})]})]}),($||r.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:$??r.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:_s.map(I=>{var A,N;const z=(A=n==null?void 0:n.providers)==null?void 0:A[I.id],J=(N=o==null?void 0:o.providers)==null?void 0:N[I.id],W=(z==null?void 0:z.masked)??null,ce=(z==null?void 0:z.source)??"none",re=ce==="stored",E=m===I.id,C=j[I.id]&&c[I.id].trim().length>0&&!r.isSaving&&!E,_=re&&!r.isSaving&&!E,B=re?"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:I.label}),e.jsx("span",{className:ue("rounded-full border px-2 py-0.5 text-[10px] uppercase tracking-[0.12em]",z!=null&&z.configured?"border-emerald-300/25 bg-emerald-400/10 text-emerald-100":"border-white/[0.12] bg-white/[0.03] text-white/55"),children:z!=null&&z.configured?"Configured":"Missing"})]}),e.jsxs("p",{className:"mt-1 text-[12px] text-white/45",children:[I.hint," ",e.jsxs("span",{className:"text-white/30",children:["Env: ",e.jsx("code",{className:"rounded bg-black/40 px-1",children:I.envVar})]})]}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[ce!=="none"&&e.jsxs("span",{className:"chip",children:["source: ",ce]}),W&&e.jsxs("span",{className:"chip",children:["key: ",W]}),J&&e.jsx("span",{className:ue("chip",J.ok?"text-emerald-100":"text-rose-100"),children:J.ok?`ready (${J.modelCount??0} models)`:"not ready"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>d(S=>({...S,[I.id]:!S[I.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:w[I.id]?"Hide key":"Show key",children:w[I.id]?"Hide":"Show"}),e.jsx("button",{type:"button",onClick:()=>void U(),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:c[I.id],onChange:S=>{l(Z=>({...Z,[I.id]:S.target.value})),u(Z=>({...Z,[I.id]:!0})),$&&v(null)},type:w[I.id]?"text":"password",placeholder:`Paste ${I.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 L(I.id),disabled:!C,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:E?"Saving...":B}),e.jsx("button",{type:"button",onClick:()=>void P(I.id),disabled:!_,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:j[I.id]?"Unsaved changes":" "})]})]})]},I.id)})})]})}function si({open:t,onClose:s,activeTab:i,onChangeTab:r,onboarding:n,authToken:o=null,embedMode:c=!1}){return e.jsx(et,{open:t,onClose:s,maxWidth:"max-w-4xl",children:e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[e.jsxs("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:"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 j=i===l.id;return e.jsx("button",{type:"button",role:"tab","aria-selected":j,onClick:()=>r(l.id),className:ue("rounded-full px-3 py-1.5 text-[11px] font-semibold transition-colors",j?"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 flex-1 overflow-y-auto px-5 py-4 sm:px-6",children:i==="orgx"?e.jsx(Zr,{state:n.state,isStarting:n.isStarting,isSubmittingManual:n.isSubmittingManual,onRefresh:n.refreshStatus,onStartPairing:n.startPairing,onSubmitManualKey:n.submitManualKey,onBackToPairing:n.backToPairing,onUseManualKey:n.setManualMode,onDisconnect:n.disconnect}):e.jsx(ti,{authToken:o,embedMode:c,enabled:t})})]})})}const ni=a.lazy(async()=>({default:(await jt(()=>import("./MissionControlView-CthHdl6R.js"),__vite__mapDeps([0,1,2,3,4]))).MissionControlView})),ri=a.lazy(async()=>({default:(await jt(()=>import("./SessionInspector-Dq0Z5WMo.js"),__vite__mapDeps([5,1,2,3,4]))).SessionInspector})),bs={connected:"Live",reconnecting:"Reconnecting",disconnected:"Offline"},ii={connected:b.lime,reconnecting:b.amber,disconnected:b.red},Wt="orgx.mission_control.welcome.dismissed",zt="orgx.demo_mode",Kt="orgx.first_run_guide.shown_session",ws={blocked:0,pending:1,queued:2,running:3,failed:4,cancelled:5,completed:6,archived:7};function Ze(t){if(!t)return 0;const s=Date.parse(t);return Number.isFinite(s)?s:0}function ai(t){const s=Ze(t);if(!s)return"unknown";try{return new Date(s).toLocaleString()}catch{return"unknown"}}function ys(t,s){const i=ws[t.status]??99,r=ws[s.status]??99;return i!==r?i-r:Ze(t.updatedAt??t.lastEventAt??t.startedAt)-Ze(s.updatedAt??s.lastEventAt??s.startedAt)}function oi(){const t=an();return t.showGate?e.jsx(yn,{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(ui,{onboarding:t})}function li(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 ci(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 di(){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:Ct,alt:"OrgX",className:"h-full w-full rounded-md object-contain"})})}function ui({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(zt)==="1"}catch{return!1}}),r=s||t.state.hasApiKey&&t.state.connectionVerified,{data:n,isLoading:o,error:c,refetch:l,approveDecision:j,approveAllDecisions:u}=tn({useMock:s,enabled:!0,enableDecisions:r}),w=r&&n.connection==="connected",[d,m]=a.useState(null),[p,$]=a.useState(!1),[v,O]=a.useState(null),[L,P]=a.useState(null),[U,I]=a.useState(null),[z,J]=a.useState(!1),[W,ce]=a.useState([]),re=a.useRef(null),E=a.useRef(null),[C,_]=a.useState({open:!1,tab:"orgx"}),[B,A]=a.useState(!1),[N,S]=a.useState("agents"),[Z,me]=a.useState("decisions"),[he,K]=a.useState(()=>typeof window>"u"?!1:window.localStorage.getItem(Wt)==="1");a.useEffect(()=>{typeof window>"u"||(he?window.localStorage.setItem(Wt,"1"):window.localStorage.removeItem(Wt))},[he]),a.useEffect(()=>{if(!(typeof window>"u"))try{s?window.localStorage.setItem(zt,"1"):window.localStorage.removeItem(zt)}catch{}},[s]),a.useEffect(()=>{if(!(typeof window>"u")&&!B&&!jn()){try{if(window.sessionStorage.getItem(Kt)==="1")return}catch{}if(s||t.state.connectionVerified){A(!0);try{window.sessionStorage.setItem(Kt,"1")}catch{}}}},[s,B,t.state.connectionVerified]);const F=a.useCallback(h=>{_(V=>({open:!0,tab:h??V.tab}))},[]),f=a.useCallback(()=>{F("orgx")},[F]),q=a.useCallback(()=>{jt(()=>import("./MissionControlView-CthHdl6R.js"),__vite__mapDeps([0,1,2,3,4]))},[]),[ee,fe]=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"}),te=a.useCallback(h=>{fe(h);try{localStorage.setItem("orgx-dashboard-view",h)}catch{}},[]),{data:le}=Is(ee==="mission-control"),{data:ye}=Gr(ee==="mission-control"),[ie,be]=a.useState(null),[g,H]=a.useState(""),[Q,y]=a.useState(!1),X=a.useCallback((h,V)=>{be({type:h,initiativeId:V}),H(""),y(!1)},[]),ve=a.useCallback(()=>{be(null),H(""),y(!1)},[]),ae=a.useCallback(()=>{O(null)},[]);a.useEffect(()=>{var T;const h=((T=n.sessions.nodes[0])==null?void 0:T.id)??null;if(!h){d!==null&&m(null);return}if(d===null){m(h);return}n.sessions.nodes.some(k=>k.id===d)||m(h)},[n.sessions.nodes,d]),a.useEffect(()=>{if(!v)return;n.sessions.nodes.some(V=>V.id===v)||O(null)},[v,n.sessions.nodes]);const se=a.useCallback(h=>{jt(()=>import("./SessionInspector-Dq0Z5WMo.js"),__vite__mapDeps([5,1,2,3,4])),m(h),$(!0),O(h)},[]),D=a.useCallback(h=>{const V=h.trim();if(!V)return;const T=n.sessions.nodes.find(k=>k.runId===V||k.id===V)??null;T&&(se(T.id),I(`Focused session: ${T.title}`))},[n.sessions.nodes,se]),ne=a.useMemo(()=>n.sessions.nodes.find(h=>h.id===v)??null,[v,n.sessions.nodes]),we=a.useMemo(()=>n.sessions.nodes.find(h=>h.id===d)??null,[n.sessions.nodes,d]),Xe=a.useMemo(()=>n.sessions.nodes.filter(h=>["running","queued","pending"].includes(h.status)).length,[n.sessions.nodes]),Pe=a.useMemo(()=>n.sessions.nodes.filter(h=>h.status==="blocked"||h.blockers.length>0).length,[n.sessions.nodes]),Re=a.useMemo(()=>n.sessions.nodes.filter(h=>h.status==="failed").length,[n.sessions.nodes]),Te=a.useMemo(()=>{const h=[{id:"sessions",label:"Sessions",value:n.sessions.nodes.length,color:b.teal},{id:"active",label:"Active",value:Xe,color:Xe>0?b.lime:b.textMuted},{id:"blocked",label:"Blocked",value:Pe,color:Pe>0?b.red:b.textMuted},{id:"failed",label:"Failed",value:Re,color:Re>0?b.red:b.textMuted},{id:"decisions",label:"Decisions",value:w?n.decisions.length:0,color:w&&n.decisions.length>0?b.amber:b.textMuted},{id:"outbox",label:"Outbox",value:n.outbox.pendingTotal,color:n.outbox.replayStatus==="error"?b.red:n.outbox.pendingTotal>0?b.amber:b.textMuted}];return n.handoffs.length>0&&h.push({id:"handoffs",label:"Handoffs",value:n.handoffs.length,color:b.iris}),h},[Xe,Pe,Re,n.decisions.length,n.handoffs.length,n.outbox.pendingTotal,n.outbox.replayStatus,n.sessions.nodes.length,w]),Ue=a.useMemo(()=>n.decisions.length>0?Math.max(0,...n.decisions.map(h=>h.waitingMinutes)):0,[n.decisions]),$e=a.useMemo(()=>{const h=[];return c&&h.push({id:`stream-error:${c}`,kind:"error",title:"Live stream degraded",message:c,actionLabel:"Settings",onAction:()=>F("orgx")}),n.connection!=="connected"&&h.push({id:`connection:${n.connection}`,kind:n.connection==="disconnected"?"error":"info",title:n.connection==="disconnected"?"Connection lost":"Reconnecting",message:n.connection==="disconnected"?"Dashboard is offline. Some data may be stale.":"Live data is recovering. Some sections may be delayed.",actionLabel:"Reconnect",onAction:f}),n.outbox.pendingTotal>0&&h.push({id:`outbox:pending:${n.outbox.pendingTotal}`,kind:"info",title:"Buffered updates pending",message:`${n.outbox.pendingTotal} event(s) queued for replay.`}),n.outbox.replayStatus==="error"&&n.outbox.lastReplayError&&h.push({id:`outbox:error:${n.outbox.lastReplayError}`,kind:"error",title:"Outbox replay failed",message:n.outbox.lastReplayError,actionLabel:"Settings",onAction:()=>F("orgx")}),U&&h.push({id:`ops:${U}`,kind:"info",title:"Update",message:U}),h},[n.connection,n.outbox.lastReplayError,n.outbox.pendingTotal,n.outbox.replayStatus,c,f,F,U]);a.useEffect(()=>{const h=new Set($e.map(V=>V.id));ce(V=>V.filter(T=>h.has(T)))},[$e]);const We=a.useMemo(()=>$e.filter(h=>!W.includes(h.id)),[W,$e]),tt=a.useCallback(h=>{ce(V=>V.includes(h)?V:V.concat(h))},[]),ct=a.useCallback(()=>{ce($e.map(h=>h.id))},[$e]);a.useEffect(()=>{if(!z)return;const h=T=>{var oe,pe;const k=T.target;k&&((oe=E.current)!=null&&oe.contains(k)||(pe=re.current)!=null&&pe.contains(k)||J(!1))},V=T=>{T.key==="Escape"&&J(!1)};return document.addEventListener("mousedown",h),document.addEventListener("touchstart",h),document.addEventListener("keydown",V),()=>{document.removeEventListener("mousedown",h),document.removeEventListener("touchstart",h),document.removeEventListener("keydown",V)}},[z]);const ke=a.useMemo(()=>{var T;const h=new Map;for(const k of n.sessions.nodes){const oe=k.initiativeId??k.groupId??"unscoped",pe=k.groupLabel&&k.groupLabel.trim().length>0?k.groupLabel:k.initiativeId??"Unscoped Initiative",Ae=li(pe),xe=h.get(oe)??{id:oe,name:pe,category:Ae,progressTotal:0,progressCount:0,statusCounts:{},activeAgents:new Set,allAgents:new Set,workstreams:new Map,latestEpoch:0};if(k.progress!==null&&(xe.progressTotal+=k.progress,xe.progressCount+=1),xe.statusCounts[k.status]=(xe.statusCounts[k.status]??0)+1,k.agentName&&(xe.allAgents.add(k.agentName),["running","queued","pending","blocked"].includes(k.status)&&xe.activeAgents.add(k.agentName)),k.workstreamId){const Ie=n.sessions.groups.find(St=>St.id===k.workstreamId),ze=((T=Ie==null?void 0:Ie.label)==null?void 0:T.trim())||k.workstreamId;xe.workstreams.set(k.workstreamId,ze)}xe.latestEpoch=Math.max(xe.latestEpoch,Ze(k.updatedAt??k.lastEventAt??k.startedAt)),h.set(oe,xe)}const V=[];for(const k of h.values()){const oe=k.progressCount>0?Math.round(k.progressTotal/k.progressCount):k.statusCounts.completed?100:k.statusCounts.running?55:0,pe=k.category,Ae=ci(pe),xe=Math.round(Math.max(0,Math.min(100,oe))/100*(Ae.length-1)),Ie=(k.statusCounts.blocked??0)>0,ze=(k.statusCounts.completed??0)>0&&(k.statusCounts.running??0)===0&&(k.statusCounts.queued??0)===0&&(k.statusCounts.pending??0)===0&&(k.statusCounts.blocked??0)===0,St=Ae.map((At,pt)=>{let It="upcoming";return(ze||pt<xe)&&(It="completed"),pt===xe&&!ze&&(It=Ie?"warning":"current"),{name:At,status:It}});V.push({id:k.id,name:k.name,status:ze?"completed":Ie?"blocked":"active",rawStatus:ze?"completed":Ie?"blocked":"active",category:pe,health:Math.max(0,Math.min(100,oe)),phases:St,currentPhase:ze?Ae.length-1:xe,daysRemaining:0,targetDate:null,createdAt:k.latestEpoch>0?new Date(k.latestEpoch).toISOString():null,updatedAt:k.latestEpoch>0?new Date(k.latestEpoch).toISOString():null,activeAgents:k.activeAgents.size,totalAgents:k.allAgents.size,avatars:Array.from(k.activeAgents).slice(0,3),description:`${k.workstreams.size} workstreams are active right now.`,workstreams:Array.from(k.workstreams.entries()).map(([At,pt])=>({id:At,name:pt,status:"active"}))})}return V.sort((k,oe)=>{const pe=k.status==="blocked"?0:k.status==="active"?1:2,Ae=oe.status==="blocked"?0:oe.status==="active"?1:2;return pe!==Ae?pe-Ae:oe.health-k.health})},[n.sessions.nodes,n.sessions.groups]),dt=a.useMemo(()=>{const h=(T,k)=>{var oe,pe;return{...T,...k,health:k.health>0?k.health:T.health,activeAgents:Math.max(T.activeAgents,k.activeAgents),totalAgents:Math.max(T.totalAgents,k.totalAgents),avatars:(oe=T.avatars)!=null&&oe.length?T.avatars:k.avatars,workstreams:(pe=T.workstreams)!=null&&pe.length?T.workstreams:k.workstreams,description:T.description??k.description,rawStatus:k.rawStatus??T.rawStatus??null,targetDate:k.targetDate??T.targetDate??null,createdAt:k.createdAt??T.createdAt??null,updatedAt:k.updatedAt??T.updatedAt??null}},V=new Map;for(const T of ke)V.set(T.id,T);for(const T of[...le??[],...ye??[]]){const k=V.get(T.id);V.set(T.id,k?h(k,T):T)}return Array.from(V.values()).sort((T,k)=>{const oe=Ie=>Ie==="blocked"?0:Ie==="active"?1:Ie==="paused"?2:3,pe=oe(T.status)-oe(k.status);if(pe!==0)return pe;const Ae=Ze(k.updatedAt)-Ze(T.updatedAt);if(Ae!==0)return Ae;const xe=k.health-T.health;return xe!==0?xe:T.name.localeCompare(k.name)})},[ke,le,ye]),x=a.useMemo(()=>{if(!ne)return null;const h=ne.agentName,V=ne.title;if(h){const T=n.activity.find(k=>{var oe;return k.runId===ne.runId&&((oe=k.summary)==null?void 0:oe.trim())});if(T!=null&&T.summary){const k=T.summary.trim().length>40?T.summary.trim().slice(0,40)+"…":T.summary.trim();return`${h}: ${k}`}return h}if(V){const T=V.replace(/^(telegram|slack|discord|whatsapp|email|sms):/,"").trim();if(T.length>0)return T}return V??null},[n.activity,ne]),R=t.state.connectionVerified&&!he,M=a.useCallback(async()=>{if(n.sessions.nodes.length===0){I("No sessions available to continue.");return}const h=[...n.sessions.nodes].sort(ys)[0];if(m(h.id),O(h.id),["blocked","pending","queued"].includes(h.status))try{await fetch(`/orgx/api/runs/${encodeURIComponent(h.runId)}/actions/resume`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({reason:"continue_from_dashboard"})})}catch{}I(`Focused highest priority session: ${h.title}`),await l()},[n.sessions.nodes,l]),G=a.useCallback(async h=>{if(m(h.id),O(h.id),!["running","completed","archived"].includes(h.status))try{await fetch(`/orgx/api/runs/${encodeURIComponent(h.runId)}/actions/resume`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({reason:"dispatch_from_dashboard"})})}catch{}I(`Dispatch requested: ${h.title}`),await l()},[l]),Y=a.useCallback(async(h,V,T={})=>{const k=await fetch(`/orgx/api/runs/${encodeURIComponent(h.runId)}/actions/${V}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(T)});if(!k.ok){const oe=await k.json().catch(()=>null);throw new Error((oe==null?void 0:oe.error)??`${V} failed (${k.status})`)}},[]),ge=a.useCallback(async h=>{var oe;const V=await fetch(`/orgx/api/runs/${encodeURIComponent(h.runId)}/checkpoints`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({reason:"dashboard_manual_checkpoint"})});if(!V.ok){const pe=await V.json().catch(()=>null);throw new Error((pe==null?void 0:pe.error)??`Checkpoint creation failed (${V.status})`)}const T=await V.json().catch(()=>null),k=T&&"data"in T&&((oe=T.data)==null?void 0:oe.id)||T&&"id"in T&&T.id||null;I(k?`Checkpoint created: ${k.slice(0,8)}`:"Checkpoint created."),await l()},[l]),Ne=a.useCallback(async h=>{await Y(h,"pause",{reason:"pause_from_dashboard"}),I(`Pause requested: ${h.title}`),await l()},[l,Y]),Me=a.useCallback(async h=>{await Y(h,"resume",{reason:"resume_from_dashboard"}),I(`Resume requested: ${h.title}`),await l()},[l,Y]),st=a.useCallback(async h=>{await Y(h,"cancel",{reason:"cancel_from_dashboard"}),I(`Cancel requested: ${h.title}`),await l()},[l,Y]),ut=a.useCallback(async h=>{var Ae;const V=await fetch(`/orgx/api/runs/${encodeURIComponent(h.runId)}/checkpoints`,{method:"GET"});if(!V.ok){const xe=await V.json().catch(()=>null);throw new Error((xe==null?void 0:xe.error)??`Checkpoint list failed (${V.status})`)}const T=await V.json().catch(()=>null),pe=(Ae=(Array.isArray(T)?T:Array.isArray(T==null?void 0:T.data)?T.data:[]).map(xe=>({id:typeof xe.id=="string"?xe.id:"",createdAt:typeof xe.createdAt=="string"?xe.createdAt:typeof xe.created_at=="string"?xe.created_at:""})).filter(xe=>xe.id.length>0).sort((xe,Ie)=>Date.parse(Ie.createdAt)-Date.parse(xe.createdAt))[0])==null?void 0:Ae.id;if(!pe)throw new Error("No checkpoint available for rollback.");await Y(h,"rollback",{checkpointId:pe,reason:"rollback_from_dashboard"}),I(`Rollback requested for ${h.title}.`),await l()},[l,Y]),Ge=a.useCallback(async()=>{var T;if(!ie||g.trim().length===0||Q)return;y(!0);const h=ie.type,V=g.trim();try{const k={type:h,title:V,status:"active"};if(h==="workstream"){const pe=ie.initiativeId??(we==null?void 0:we.initiativeId)??((T=ke[0])==null?void 0:T.id)??null;if(!pe){I("Select an initiative first to start a workstream."),y(!1);return}k.initiative_id=pe,k.parentId=pe}const oe=await fetch("/orgx/api/entities",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(k)});if(!oe.ok){const pe=await oe.json().catch(()=>null);throw new Error((pe==null?void 0:pe.error)??`Failed to create ${h}.`)}I(`Created ${h}: ${V}`),ve(),await l()}catch(k){I(k instanceof Error?k.message:`Failed to create ${h}.`),y(!1)}},[ve,Q,ie,g,ke,l,we==null?void 0:we.initiativeId]),nt=a.useCallback(()=>{X("initiative")},[X]),Qe=a.useCallback(h=>{X("workstream",h)},[X]),rt=a.useCallback(()=>{var h;return Qe((we==null?void 0:we.initiativeId)??((h=ke[0])==null?void 0:h.id)??null)},[ke,we==null?void 0:we.initiativeId,Qe]),ht=a.useCallback(h=>{const V=[...n.sessions.nodes].filter(T=>(T.initiativeId??T.groupId)===h.id).sort(ys)[0];V&&(m(V.id),O(V.id),I(`Focused initiative: ${h.name}`))},[n.sessions.nodes]);return o?e.jsxs("div",{className:"flex min-h-screen flex-col lg:h-screen",style:{backgroundColor:b.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((h,V)=>e.jsx("div",{className:"shimmer-skeleton h-7 w-24 rounded-full"},V))})]}),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 lg:h-screen lg:min-h-0 lg:overflow-hidden",style:{backgroundColor:b.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:"grid items-center gap-2.5 lg:grid-cols-[1fr_auto_1fr]",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[e.jsx(di,{}),e.jsxs("h1",{className:"text-[17px] font-semibold tracking-tight text-white",children:["OrgX",e.jsx("span",{className:"ml-1.5 text-white/50",children:"Live"})]}),e.jsx(us,{color:ii[n.connection],pulse:n.connection==="connected",title:[`Status: ${bs[n.connection]??n.connection}`,n.connection==="connected"?"Meaning: receiving live updates.":n.connection==="reconnecting"?"Meaning: retrying live stream (data may be stale).":"Meaning: offline (data is stale).",`Last snapshot: ${ai(n.lastSnapshotAt)}`,c?`Error: ${c}`:null].filter(Boolean).join(`
11
+ `),children:bs[n.connection]??"Unknown"}),(n.outbox.pendingTotal>0||n.outbox.replayStatus==="error")&&e.jsxs(us,{color:n.outbox.replayStatus==="error"?b.red:b.amber,pulse:n.outbox.pendingTotal>0&&n.outbox.replayStatus!=="error",children:["Outbox ",n.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:()=>te("activity"),"aria-pressed":ee==="activity",className:`rounded-full px-3 py-1 text-[12px] font-medium transition-all ${ee==="activity"?"bg-white/[0.1] text-white":"text-white/55 hover:text-white/85"}`,children:"Activity"}),e.jsx("button",{type:"button",onClick:()=>te("mission-control"),onMouseEnter:q,onFocus:q,"aria-pressed":ee==="mission-control",className:`rounded-full px-3 py-1 text-[12px] font-medium transition-all ${ee==="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-2",children:[n.lastActivity&&e.jsxs("span",{className:"hidden text-[12px] text-white/45 xl:inline",children:["Last activity: ",n.lastActivity]}),n.outbox.pendingTotal>0&&e.jsxs("span",{className:"hidden text-[12px] text-white/45 xl:inline",children:["Replay: ",n.outbox.replayStatus]}),s&&e.jsx("button",{type:"button",onClick:()=>{i(!1),f()},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:re,onClick:()=>J(h=>!h),title:"Notifications","aria-haspopup":"dialog","aria-expanded":z,"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"})]}),We.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:We.length})]}),e.jsx("button",{type:"button",onClick:()=>F("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:()=>{A(!0);try{window.sessionStorage.setItem(Kt,"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 items-center gap-1.5 rounded-full border border-white/[0.1] bg-white/[0.03] px-3 text-[12px] text-white/80 transition-colors hover:bg-white/[0.08]",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"})]}),z&&e.jsxs("div",{id:"header-notifications-panel",ref:E,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:[We.length>0&&e.jsx("button",{type:"button",onClick:ct,className:"text-[11px] text-white/45 transition-colors hover:text-white/80",children:"Dismiss all"}),e.jsx("button",{type:"button",onClick:()=>J(!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:Te.map(h=>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:h.color}}),e.jsx("span",{className:"uppercase tracking-[0.08em] text-white/45",children:h.label}),e.jsx("span",{className:"font-semibold text-white",style:{fontVariantNumeric:"tabular-nums"},children:h.value})]},h.id))}),We.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:We.map(h=>e.jsx("div",{className:"rounded-xl border px-3 py-2",style:{borderColor:h.kind==="error"?"rgba(239,68,68,0.35)":"rgba(255,255,255,0.1)",backgroundColor:h.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.jsx("p",{className:"text-[12px] font-semibold",style:{color:h.kind==="error"?"#fecaca":"#e2e8f0"},children:h.title}),e.jsx("p",{className:"mt-0.5 text-[12px] leading-snug text-white/65",children:h.message}),h.onAction&&e.jsx("button",{type:"button",onClick:()=>{var V;(V=h.onAction)==null||V.call(h),J(!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:h.actionLabel??"View"})]}),e.jsx("button",{type:"button",onClick:()=>tt(h.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"})]})},h.id))})]})]})]}),e.jsx("div",{className:"mt-1.5 flex items-center justify-center lg:hidden",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:()=>te("activity"),"aria-pressed":ee==="activity",className:`rounded-full px-3 py-1 text-[12px] font-medium transition-all ${ee==="activity"?"bg-white/[0.1] text-white":"text-white/55 hover:text-white/85"}`,children:"Activity"}),e.jsx("button",{type:"button",onClick:()=>te("mission-control"),"aria-pressed":ee==="mission-control",className:`rounded-full px-3 py-1 text-[12px] font-medium transition-all ${ee==="mission-control"?"bg-white/[0.1] text-white":"text-white/55 hover:text-white/85"}`,children:"Mission Control"})]})}),R&&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:()=>te("mission-control"),onMouseEnter:q,onFocus:q,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:()=>K(!0),className:"text-[11px] text-white/65 underline underline-offset-2",children:"Dismiss"})]})]})]}),e.jsx("div",{className:"flex flex-wrap items-center gap-1.5 border-b border-white/[0.06] px-4 py-1.5 sm:px-6",children:Te.map(h=>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:h.color}}),e.jsx("span",{className:"font-semibold text-white",style:{fontVariantNumeric:"tabular-nums"},children:h.value}),e.jsx("span",{className:"uppercase tracking-[0.08em] text-white/45",children:h.label})]},h.id))}),ee==="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(ni,{initiatives:dt,activities:[],agents:[],isLoading:o,authToken:null,embedMode:!1,connection:n.connection,lastSnapshotAt:n.lastSnapshotAt,error:c,hasApiKey:t.state.hasApiKey,onOpenSettings:()=>F("orgx"),onRefresh:l})})}):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:[w&&n.decisions.length>0&&Z!=="decisions"&&e.jsxs("button",{type:"button",onClick:()=>me("decisions"),className:ue("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]",n.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:n.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 ${n.decisions.length>=20?"text-red-200":"text-amber-200"}`,children:[n.decisions.length," decision",n.decisions.length===1?"":"s"," waiting",Ue>0?` · longest: ${Ue}m`:""]}),e.jsx("span",{className:`ml-auto text-[11px] ${n.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 ${N!=="agents"?"hidden lg:flex":""}`,children:e.jsx(dr,{sessions:n.sessions,activity:n.activity,selectedSessionId:d,onSelectSession:se,onAgentFilter:P,agentFilter:L,onReconnect:f,connectionStatus:n.connection})}),e.jsx("section",{className:`min-h-0 lg:col-span-6 lg:flex lg:flex-col lg:[&>section]:h-full ${N!=="activity"?"hidden lg:flex":""}`,children:e.jsx(Or,{activity:n.activity,sessions:n.sessions.nodes,initiatives:ke,selectedRunIds:ne?[ne.runId,ne.id]:[],selectedSessionLabel:x,agentFilter:L,onClearSelection:ae,onClearAgentFilter:()=>P(null),onFocusRunId:D})}),e.jsxs("section",{className:`flex min-h-0 flex-col gap-2 lg:col-span-3 lg:gap-2 ${N!=="decisions"&&N!=="initiatives"?"hidden lg:flex":""}`,children:[e.jsx("div",{className:`min-h-0 ${Z==="initiatives"?"flex-1":"flex-shrink-0"} `,children:Z==="initiatives"?e.jsx(qr,{initiatives:ke,onInitiativeClick:ht,onCreateInitiative:nt,onCreateWorkstream:rt}):e.jsx(Ve,{className:"card-enter",children:e.jsxs("button",{onClick:()=>me("initiatives"),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:"Initiatives"}),ke.length>0&&e.jsx("span",{className:"chip text-[10px]",children:ke.length})]}),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 ${Z==="decisions"?"flex-1":"flex-shrink-0"} ${N==="initiatives"?"hidden lg:block":""}`,children:Z==="decisions"?w?e.jsx(Br,{decisions:n.decisions,onApproveDecision:j,onApproveAll:u}):e.jsxs(Ve,{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:f,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(Ve,{className:"card-enter",children:e.jsxs("button",{onClick:()=>me("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"}),w&&n.decisions.length>0&&e.jsx("span",{className:"chip text-[10px]",style:{borderColor:`${b.amber}44`,color:b.amber},children:n.decisions.length}),!w&&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(Be,{children:p&&we&&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:()=>$(!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:b.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:()=>$(!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(ri,{session:we,activity:n.activity,initiatives:ke,onContinueHighestPriority:M,onDispatchSession:G,onPauseSession:Ne,onResumeSession:Me,onCancelSession:st,onCreateCheckpoint:ge,onRollbackSession:ut,onStartInitiative:nt,onStartWorkstream:Qe})})})]},"session-drawer-panel")]})}),e.jsx(Sn,{activeTab:N,onTabChange:S,pendingDecisionCount:w?n.decisions.length:0}),e.jsx(et,{open:ie!==null,onClose:ve,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:(ie==null?void 0:ie.type)==="workstream"?"New Workstream":"New Initiative"}),e.jsx("p",{className:"mt-1 text-[12px] leading-relaxed text-white/45",children:(ie==null?void 0:ie.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:g,onChange:h=>H(h.target.value),onKeyDown:h=>{h.key==="Enter"&&Ge()},autoFocus:!0,"data-modal-autofocus":"true",placeholder:(ie==null?void 0:ie.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:ve,className:"rounded-md px-3 py-1.5 text-[12px] text-white/60 transition-colors hover:text-white",children:"Cancel"}),e.jsx("button",{onClick:Ge,disabled:g.trim().length===0||Q,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:Q?"Creating…":"Create"})]})]})}),e.jsx(si,{open:C.open,onClose:()=>_(h=>({...h,open:!1})),activeTab:C.tab,onChangeTab:h=>_(V=>({...V,tab:h})),onboarding:t,authToken:null,embedMode:!1}),e.jsx(Nn,{open:B,onClose:()=>A(!1),onOpenSettings:()=>F("providers"),onOpenOrgxSettings:()=>F("orgx"),onOpenMissionControl:()=>{te("mission-control"),A(!1)},demoMode:s,connectionVerified:t.state.connectionVerified,hasSessions:n.sessions.nodes.length>0})]})}const hi=new Os({defaultOptions:{queries:{staleTime:3e4,retry:1,refetchOnWindowFocus:!1,refetchOnReconnect:!0}}});Ds.createRoot(document.getElementById("root")).render(e.jsx(a.StrictMode,{children:e.jsx(Ts,{client:hi,children:e.jsx(oi,{})})}));export{De as A,vt as M,Ve as P,Pr as S,b as a,Dt as b,ue as c,zn as d,et as e,Se as f,ps as g,Vt as q,hs as r,Hn as u};