@useorgx/openclaw-plugin 0.4.9 → 0.7.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 (224) hide show
  1. package/README.md +77 -11
  2. package/dashboard/dist/assets/6mILZQ2a.js +1 -0
  3. package/dashboard/dist/assets/6mILZQ2a.js.br +0 -0
  4. package/dashboard/dist/assets/6mILZQ2a.js.gz +0 -0
  5. package/dashboard/dist/assets/8dksYiq4.js +2 -0
  6. package/dashboard/dist/assets/8dksYiq4.js.br +0 -0
  7. package/dashboard/dist/assets/8dksYiq4.js.gz +0 -0
  8. package/dashboard/dist/assets/B5zYRHc3.js +1 -0
  9. package/dashboard/dist/assets/B5zYRHc3.js.br +0 -0
  10. package/dashboard/dist/assets/B5zYRHc3.js.gz +0 -0
  11. package/dashboard/dist/assets/B6wPWJ35.js +1 -0
  12. package/dashboard/dist/assets/B6wPWJ35.js.br +0 -0
  13. package/dashboard/dist/assets/B6wPWJ35.js.gz +0 -0
  14. package/dashboard/dist/assets/BJgZIVUQ.js +53 -0
  15. package/dashboard/dist/assets/BJgZIVUQ.js.br +0 -0
  16. package/dashboard/dist/assets/BJgZIVUQ.js.gz +0 -0
  17. package/dashboard/dist/assets/BWEwjt1W.js +1 -0
  18. package/dashboard/dist/assets/BWEwjt1W.js.br +0 -0
  19. package/dashboard/dist/assets/BWEwjt1W.js.gz +0 -0
  20. package/dashboard/dist/assets/BgOYB78t.js +4 -0
  21. package/dashboard/dist/assets/BgOYB78t.js.br +0 -0
  22. package/dashboard/dist/assets/BgOYB78t.js.gz +0 -0
  23. package/dashboard/dist/assets/BzRbDCAD.css +1 -0
  24. package/dashboard/dist/assets/BzRbDCAD.css.br +0 -0
  25. package/dashboard/dist/assets/BzRbDCAD.css.gz +0 -0
  26. package/dashboard/dist/assets/C-KIc3Wc.js.br +0 -0
  27. package/dashboard/dist/assets/C-KIc3Wc.js.gz +0 -0
  28. package/dashboard/dist/assets/C8uM3AX8.js +1 -0
  29. package/dashboard/dist/assets/C8uM3AX8.js.br +0 -0
  30. package/dashboard/dist/assets/C8uM3AX8.js.gz +0 -0
  31. package/dashboard/dist/assets/C9jy61eu.js +212 -0
  32. package/dashboard/dist/assets/C9jy61eu.js.br +0 -0
  33. package/dashboard/dist/assets/C9jy61eu.js.gz +0 -0
  34. package/dashboard/dist/assets/CC63EwFD.js +1 -0
  35. package/dashboard/dist/assets/CC63EwFD.js.br +0 -0
  36. package/dashboard/dist/assets/CC63EwFD.js.gz +0 -0
  37. package/dashboard/dist/assets/CL_wXqR7.js +1 -0
  38. package/dashboard/dist/assets/CL_wXqR7.js.br +0 -0
  39. package/dashboard/dist/assets/CL_wXqR7.js.gz +0 -0
  40. package/dashboard/dist/assets/CZaT3ob_.js +1 -0
  41. package/dashboard/dist/assets/CZaT3ob_.js.br +0 -0
  42. package/dashboard/dist/assets/CZaT3ob_.js.gz +0 -0
  43. package/dashboard/dist/assets/CgaottFX.js +1 -0
  44. package/dashboard/dist/assets/CgaottFX.js.br +0 -0
  45. package/dashboard/dist/assets/CgaottFX.js.gz +0 -0
  46. package/dashboard/dist/assets/{CpJsfbXo.js → CxQ08qFN.js} +2 -2
  47. package/dashboard/dist/assets/CxQ08qFN.js.br +0 -0
  48. package/dashboard/dist/assets/CxQ08qFN.js.gz +0 -0
  49. package/dashboard/dist/assets/CzCxAZlW.js +1 -0
  50. package/dashboard/dist/assets/CzCxAZlW.js.br +0 -0
  51. package/dashboard/dist/assets/CzCxAZlW.js.gz +0 -0
  52. package/dashboard/dist/assets/D3iMTYEj.js +1 -0
  53. package/dashboard/dist/assets/D3iMTYEj.js.br +0 -0
  54. package/dashboard/dist/assets/D3iMTYEj.js.gz +0 -0
  55. package/dashboard/dist/assets/D8JNX8kq.js +2 -0
  56. package/dashboard/dist/assets/D8JNX8kq.js.br +0 -0
  57. package/dashboard/dist/assets/D8JNX8kq.js.gz +0 -0
  58. package/dashboard/dist/assets/DnA8dpj6.js +1 -0
  59. package/dashboard/dist/assets/DnA8dpj6.js.br +0 -0
  60. package/dashboard/dist/assets/DnA8dpj6.js.gz +0 -0
  61. package/dashboard/dist/assets/IUexzymk.js +1 -0
  62. package/dashboard/dist/assets/IUexzymk.js.br +0 -0
  63. package/dashboard/dist/assets/IUexzymk.js.gz +0 -0
  64. package/dashboard/dist/assets/cNrhgGc1.js +8 -0
  65. package/dashboard/dist/assets/cNrhgGc1.js.br +0 -0
  66. package/dashboard/dist/assets/cNrhgGc1.js.gz +0 -0
  67. package/dashboard/dist/assets/ic2FaMnh.js +1 -0
  68. package/dashboard/dist/assets/ic2FaMnh.js.br +0 -0
  69. package/dashboard/dist/assets/ic2FaMnh.js.gz +0 -0
  70. package/dashboard/dist/assets/qm8xLgv-.css +1 -0
  71. package/dashboard/dist/assets/qm8xLgv-.css.br +0 -0
  72. package/dashboard/dist/assets/qm8xLgv-.css.gz +0 -0
  73. package/dashboard/dist/assets/rttbDbEx.js +1 -0
  74. package/dashboard/dist/assets/rttbDbEx.js.br +0 -0
  75. package/dashboard/dist/assets/rttbDbEx.js.gz +0 -0
  76. package/dashboard/dist/brand/anthropic-mark.svg.br +0 -0
  77. package/dashboard/dist/brand/anthropic-mark.svg.gz +0 -0
  78. package/dashboard/dist/brand/openai-mark.svg.br +0 -0
  79. package/dashboard/dist/brand/openai-mark.svg.gz +0 -0
  80. package/dashboard/dist/brand/openclaw-mark.svg.br +0 -0
  81. package/dashboard/dist/brand/openclaw-mark.svg.gz +0 -0
  82. package/dashboard/dist/brand/xandy-orchestrator.png +0 -0
  83. package/dashboard/dist/index.html +7 -5
  84. package/dashboard/dist/index.html.br +0 -0
  85. package/dashboard/dist/index.html.gz +0 -0
  86. package/dist/activity-actor-fields.js +26 -4
  87. package/dist/activity-store.js +34 -8
  88. package/dist/agent-context-store.js +79 -17
  89. package/dist/agent-run-store.js +44 -3
  90. package/dist/agent-suite.d.ts +9 -0
  91. package/dist/agent-suite.js +149 -9
  92. package/dist/artifacts/artifact-domain-schemas.d.ts +66 -0
  93. package/dist/artifacts/artifact-domain-schemas.js +357 -0
  94. package/dist/artifacts/register-artifact.d.ts +4 -3
  95. package/dist/artifacts/register-artifact.js +170 -57
  96. package/dist/chat-store.d.ts +157 -0
  97. package/dist/chat-store.js +586 -0
  98. package/dist/cli/orgx.js +11 -0
  99. package/dist/contracts/client.d.ts +43 -3
  100. package/dist/contracts/client.js +159 -30
  101. package/dist/contracts/practice-exercise-schema.d.ts +216 -0
  102. package/dist/contracts/practice-exercise-schema.js +314 -0
  103. package/dist/contracts/retro-schema.d.ts +81 -0
  104. package/dist/contracts/retro-schema.js +80 -0
  105. package/dist/contracts/shared-types.d.ts +159 -0
  106. package/dist/contracts/shared-types.js +199 -1
  107. package/dist/contracts/skill-pack-schema.d.ts +192 -0
  108. package/dist/contracts/skill-pack-schema.js +180 -0
  109. package/dist/contracts/types.d.ts +247 -2
  110. package/dist/entities/auto-assignment.js +43 -17
  111. package/dist/event-sanitization.d.ts +11 -0
  112. package/dist/event-sanitization.js +113 -0
  113. package/dist/gateway-watchdog.d.ts +5 -0
  114. package/dist/gateway-watchdog.js +50 -0
  115. package/dist/hooks/post-reporting-event.mjs +1 -5
  116. package/dist/http/helpers/activity-headline.js +13 -132
  117. package/dist/http/helpers/auto-continue-engine.d.ts +198 -10
  118. package/dist/http/helpers/auto-continue-engine.js +3145 -186
  119. package/dist/http/helpers/autopilot-operations.d.ts +19 -0
  120. package/dist/http/helpers/autopilot-operations.js +182 -31
  121. package/dist/http/helpers/autopilot-runtime.d.ts +1 -0
  122. package/dist/http/helpers/autopilot-runtime.js +328 -25
  123. package/dist/http/helpers/autopilot-slice-utils.d.ts +18 -0
  124. package/dist/http/helpers/autopilot-slice-utils.js +514 -93
  125. package/dist/http/helpers/decision-mapper.d.ts +40 -0
  126. package/dist/http/helpers/decision-mapper.js +223 -7
  127. package/dist/http/helpers/dispatch-lifecycle.d.ts +19 -2
  128. package/dist/http/helpers/dispatch-lifecycle.js +242 -37
  129. package/dist/http/helpers/kickoff-context.js +104 -0
  130. package/dist/http/helpers/llm-client.d.ts +47 -0
  131. package/dist/http/helpers/llm-client.js +256 -0
  132. package/dist/http/helpers/mission-control.d.ts +102 -3
  133. package/dist/http/helpers/mission-control.js +498 -9
  134. package/dist/http/helpers/sentinel-catalog.d.ts +23 -0
  135. package/dist/http/helpers/sentinel-catalog.js +193 -0
  136. package/dist/http/helpers/session-classification.d.ts +9 -0
  137. package/dist/http/helpers/session-classification.js +564 -0
  138. package/dist/http/helpers/slice-experience-v2.d.ts +137 -0
  139. package/dist/http/helpers/slice-experience-v2.js +677 -0
  140. package/dist/http/helpers/slice-run-projections.d.ts +72 -0
  141. package/dist/http/helpers/slice-run-projections.js +877 -0
  142. package/dist/http/helpers/triage-mapper.d.ts +43 -0
  143. package/dist/http/helpers/triage-mapper.js +549 -0
  144. package/dist/http/helpers/value-utils.js +7 -2
  145. package/dist/http/helpers/workspace-scope.d.ts +15 -0
  146. package/dist/http/helpers/workspace-scope.js +170 -0
  147. package/dist/http/index.js +1420 -105
  148. package/dist/http/routes/agent-suite.d.ts +9 -0
  149. package/dist/http/routes/agent-suite.js +294 -8
  150. package/dist/http/routes/agents-catalog.js +64 -19
  151. package/dist/http/routes/chat.d.ts +19 -0
  152. package/dist/http/routes/chat.js +522 -0
  153. package/dist/http/routes/decision-actions.d.ts +8 -1
  154. package/dist/http/routes/decision-actions.js +42 -5
  155. package/dist/http/routes/dispatch-gateway-envelope.d.ts +25 -0
  156. package/dist/http/routes/dispatch-gateway-envelope.js +26 -0
  157. package/dist/http/routes/entities.d.ts +16 -0
  158. package/dist/http/routes/entities.js +232 -6
  159. package/dist/http/routes/live-legacy.d.ts +5 -0
  160. package/dist/http/routes/live-legacy.js +23 -509
  161. package/dist/http/routes/live-misc.d.ts +12 -0
  162. package/dist/http/routes/live-misc.js +251 -31
  163. package/dist/http/routes/live-snapshot.d.ts +49 -2
  164. package/dist/http/routes/live-snapshot.js +653 -23
  165. package/dist/http/routes/live-terminal.d.ts +11 -0
  166. package/dist/http/routes/live-terminal.js +154 -0
  167. package/dist/http/routes/live-triage.d.ts +61 -0
  168. package/dist/http/routes/live-triage.js +192 -0
  169. package/dist/http/routes/mission-control-actions.d.ts +49 -1
  170. package/dist/http/routes/mission-control-actions.js +1246 -84
  171. package/dist/http/routes/mission-control-read.d.ts +48 -3
  172. package/dist/http/routes/mission-control-read.js +1658 -20
  173. package/dist/http/routes/realtime-orchestrator.d.ts +10 -0
  174. package/dist/http/routes/realtime-orchestrator.js +74 -0
  175. package/dist/http/routes/run-control.d.ts +5 -2
  176. package/dist/http/routes/run-control.js +10 -0
  177. package/dist/http/routes/sentinels-catalog.d.ts +7 -0
  178. package/dist/http/routes/sentinels-catalog.js +24 -0
  179. package/dist/http/routes/summary.js +10 -3
  180. package/dist/http/routes/usage.d.ts +24 -0
  181. package/dist/http/routes/usage.js +362 -0
  182. package/dist/http/routes/work-artifacts.js +28 -9
  183. package/dist/index.js +165 -27
  184. package/dist/local-openclaw.js +29 -6
  185. package/dist/mcp-client-setup.js +3 -3
  186. package/dist/mcp-http-handler.d.ts +3 -0
  187. package/dist/mcp-http-handler.js +34 -60
  188. package/dist/next-up-queue-store.d.ts +16 -1
  189. package/dist/next-up-queue-store.js +89 -7
  190. package/dist/outbox.d.ts +5 -0
  191. package/dist/outbox.js +113 -9
  192. package/dist/paths.js +36 -5
  193. package/dist/reporting/rollups.d.ts +41 -0
  194. package/dist/reporting/rollups.js +113 -0
  195. package/dist/retro/domain-templates.d.ts +45 -0
  196. package/dist/retro/domain-templates.js +297 -0
  197. package/dist/retro/quality-rubric.d.ts +33 -0
  198. package/dist/retro/quality-rubric.js +213 -0
  199. package/dist/runtime-cleanup.d.ts +18 -0
  200. package/dist/runtime-cleanup.js +87 -0
  201. package/dist/services/background.d.ts +11 -0
  202. package/dist/services/background.js +22 -0
  203. package/dist/services/experiment-randomization.d.ts +21 -0
  204. package/dist/services/experiment-randomization.js +63 -0
  205. package/dist/skill-pack-state.d.ts +36 -5
  206. package/dist/skill-pack-state.js +273 -29
  207. package/dist/sync/local-agent-telemetry.d.ts +13 -0
  208. package/dist/sync/local-agent-telemetry.js +128 -0
  209. package/dist/sync/outbox-replay.js +131 -24
  210. package/dist/team-context-store.d.ts +23 -0
  211. package/dist/team-context-store.js +116 -0
  212. package/dist/telemetry/posthog.js +4 -2
  213. package/dist/tools/core-tools.d.ts +10 -14
  214. package/dist/tools/core-tools.js +1289 -24
  215. package/dist/types.d.ts +2 -0
  216. package/dist/types.js +2 -0
  217. package/dist/worker-supervisor.js +23 -0
  218. package/package.json +20 -6
  219. package/dashboard/dist/assets/B3ziCA02.js +0 -8
  220. package/dashboard/dist/assets/B5NEElEI.css +0 -1
  221. package/dashboard/dist/assets/BhapSNAs.js +0 -215
  222. package/dashboard/dist/assets/iFdvE7lx.js +0 -1
  223. package/dashboard/dist/assets/jRJsmpYM.js +0 -1
  224. package/dashboard/dist/assets/sAhvFnpk.js +0 -4
@@ -1,215 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/iFdvE7lx.js","assets/B3ziCA02.js","assets/C-KIc3Wc.js","assets/sAhvFnpk.js","assets/CpJsfbXo.js","assets/jRJsmpYM.js"])))=>i.map(i=>d[i]);
2
- var Ui=Object.defineProperty;var Wi=(t,n,s)=>n in t?Ui(t,n,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[n]=s;var bn=(t,n,s)=>Wi(t,typeof n!="symbol"?n+"":n,s);import{r as a,j as e,a as Ki,u as is,b as Et,c as Ut,d as Vi,Q as Hi}from"./B3ziCA02.js";import{b as Gi}from"./C-KIc3Wc.js";import{v as ii}from"./sAhvFnpk.js";import{m as we,A as yt,u as ai,R as Xi,a as Ji,b as Qi}from"./CpJsfbXo.js";(function(){const n=document.createElement("link").relList;if(n&&n.supports&&n.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))r(i);new MutationObserver(i=>{for(const o of i)if(o.type==="childList")for(const l of o.addedNodes)l.tagName==="LINK"&&l.rel==="modulepreload"&&r(l)}).observe(document,{childList:!0,subtree:!0});function s(i){const o={};return i.integrity&&(o.integrity=i.integrity),i.referrerPolicy&&(o.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?o.credentials="include":i.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function r(i){if(i.ep)return;i.ep=!0;const o=s(i);fetch(i.href,o)}})();const Yi="modulepreload",Zi=function(t){return"/orgx/live/"+t},lr={},Jn=function(n,s,r){let i=Promise.resolve();if(s&&s.length>0){let l=function(x){return Promise.all(x.map(d=>Promise.resolve(d).then(u=>({status:"fulfilled",value:u}),u=>({status:"rejected",reason:u}))))};document.getElementsByTagName("link");const c=document.querySelector("meta[property=csp-nonce]"),h=(c==null?void 0:c.nonce)||(c==null?void 0:c.getAttribute("nonce"));i=l(s.map(x=>{if(x=Zi(x),x in lr)return;lr[x]=!0;const d=x.endsWith(".css"),u=d?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${x}"]${u}`))return;const p=document.createElement("link");if(p.rel=d?"stylesheet":Yi,d||(p.as="script"),p.crossOrigin="",p.href=x,h&&p.setAttribute("nonce",h),document.head.appendChild(p),d)return new Promise((m,j)=>{p.addEventListener("load",m),p.addEventListener("error",()=>j(new Error(`Unable to preload CSS for ${x}`)))})}))}function o(l){const c=new Event("vite:preloadError",{cancelable:!0});if(c.payload=l,window.dispatchEvent(c),!c.defaultPrevented)throw l}return i.then(l=>{for(const c of l||[])c.status==="rejected"&&o(c.reason);return n().catch(o)})},cr=()=>{const t=new Date,n=s=>new Date(t.getTime()-s*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:n(120),updatedAt:n(2),lastEventAt:n(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:n(80),updatedAt:n(5),lastEventAt:n(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:n(30),updatedAt:n(12),lastEventAt:n(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:n(90),updatedAt:n(8),lastEventAt:n(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",requesterAgentId:"dana",requesterAgentName:"Dana",executorAgentId:"dana",executorAgentName:"Dana",runId:"run-2",initiativeId:"init-1",timestamp:n(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",requesterAgentId:"mark",requesterAgentName:"Mark",executorAgentId:"mark",executorAgentName:"Mark",runId:"run-4",initiativeId:"init-2",timestamp:n(8)},{id:"activity-3",type:"delegation",title:"Task delegated",description:"Spin up data agent for instrumentation plan.",agentId:"eli",agentName:"Eli",requesterAgentId:"eli",requesterAgentName:"Eli",executorAgentId:"eli",executorAgentName:"Eli",runId:"run-1",initiativeId:"init-1",timestamp:n(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:n(12),updatedAt:n(2),events:[{id:"handoff-event-1",handoffId:"handoff-1",eventType:"created",actorType:"agent",actorId:"dana",payload:{summary:"Draft layout ready for review."},createdAt:n(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:n(22),updatedAt:n(2),waitingMinutes:22}],outbox:{pendingTotal:0,pendingByQueue:{},oldestEventAt:null,newestEventAt:null,replayStatus:"idle",lastReplayAttemptAt:null,lastReplaySuccessAt:null,lastReplayFailureAt:null,lastReplayError:null}}};function Yt(t){const n=t instanceof Date?t:new Date(t);return Number.isNaN(n.getTime())?"":n.toLocaleString()}function Ge(t){const s=(t instanceof Date?t:new Date(t)).getTime()-Date.now();if(Number.isNaN(s))return"unknown";const r=Math.floor(Math.abs(s)/1e3),i=s<0?"past":"future";if(r<10)return i==="past"?"just now":"soon";if(r<60)return i==="past"?`${r}s ago`:`in ${r}s`;const o=Math.floor(r/60);if(o<60)return i==="past"?`${o}m ago`:`in ${o}m`;const l=Math.floor(o/60);if(l<24)return i==="past"?`${l}h ago`:`in ${l}h`;const c=Math.floor(l/24);return i==="past"?`${c}d ago`:`in ${c}d`}const ea=8e3,ta=320,na=300,sa=80,ra=80,ia=120,dr=6e4,oi={pendingTotal:0,pendingByQueue:{},oldestEventAt:null,newestEventAt:null,replayStatus:"idle",lastReplayAttemptAt:null,lastReplaySuccessAt:null,lastReplayFailureAt:null,lastReplayError:null},ur={running:0,active:0,queued:1,in_progress:1,working:1,planning:1,handoff:1,review:2,pending:2,blocked:3,failed:4,cancelled:5,paused:6,completed:6,archived:7},li=new Set(["running","active","queued","in_progress","working","planning","handoff","review","pending","blocked"]),mr=45*6e4;function Je(t){if(!t)return 0;const n=Date.parse(t);return Number.isFinite(n)?n:0}function Qn(t,n){const s=ur[t.status]??99,r=ur[n.status]??99;if(s!==r)return s-r;const i=Je(t.updatedAt??t.lastEventAt??t.startedAt),o=Je(n.updatedAt??n.lastEventAt??n.startedAt);return i!==o?o-i:t.id.localeCompare(n.id)}function aa(t){return(t??"").trim().toLowerCase()}function pr(t){return li.has(aa(t.status))}function hs(t){const n=[];return t.id&&n.push(`id:${t.id}`),t.runId&&n.push(`run:${t.runId}`),n}function xr(t,n){if(!t.nodes.length)return n;if(!n.nodes.length){const m=Date.now(),j=t.nodes.filter(v=>{const y=Je(v.updatedAt??v.lastEventAt??v.startedAt);return pr(v)||m-y<=mr});if(!j.length)return n;const w=new Set(j.map(v=>v.id)),E=new Set(j.map(v=>v.groupId));return{nodes:j.sort(Qn),edges:t.edges.filter(v=>w.has(v.parentId)&&w.has(v.childId)),groups:t.groups.filter(v=>E.has(v.id))}}const s=new Set,r=[...n.nodes];for(const m of n.nodes)for(const j of hs(m))s.add(j);const i=Date.now(),o=[];for(const m of t.nodes){if(hs(m).some(v=>s.has(v)))continue;const w=Je(m.updatedAt??m.lastEventAt??m.startedAt),E=i-w<=mr;if(pr(m)||E){o.push(m),r.push(m);for(const v of hs(m))s.add(v)}}if(!o.length)return n;const l=new Set(r.map(m=>m.id)),c=new Map(t.groups.map(m=>[m.id,m])),h=new Map(n.groups.map(m=>[m.id,m])),x=[...n.groups];for(const m of o){if(h.has(m.groupId))continue;const j=c.get(m.groupId)??{id:m.groupId,label:m.groupLabel||m.agentName||"Ungrouped",status:null};h.set(m.groupId,j),x.push(j)}const d=m=>`${m.parentId}->${m.childId}`,u=new Set,p=[];for(const m of n.edges){if(!l.has(m.parentId)||!l.has(m.childId))continue;const j=d(m);u.has(j)||(u.add(j),p.push(m))}for(const m of t.edges){if(!l.has(m.parentId)||!l.has(m.childId))continue;const j=d(m);u.has(j)||(u.add(j),p.push(m))}return{nodes:r.sort(Qn),edges:p,groups:x}}function Ln(t,n){if(t.nodes.length<=n)return t;const s=[...t.nodes].sort(Qn).slice(0,n),r=new Set(s.map(o=>o.id)),i=new Set(s.map(o=>o.groupId));return{nodes:s,edges:t.edges.filter(o=>r.has(o.parentId)&&r.has(o.childId)),groups:t.groups.filter(o=>i.has(o.id))}}function hr(t,n){return t.length<=n?t:[...t].sort((s,r)=>Je(r.updatedAt)-Je(s.updatedAt)).slice(0,n)}function oa(t){const n=t.requestedAt??t.updatedAt??null,s=t.updatedAt??n,r=Number.isFinite(t.waitingMinutes)?Math.max(0,Math.floor(t.waitingMinutes)):n?Math.max(0,Math.floor((Date.now()-Je(n))/6e4)):0;return{id:t.id,title:t.title,context:t.context??null,status:t.status??"pending",agentName:t.agentName??null,requestedAt:n,updatedAt:s,waitingMinutes:r,metadata:t.metadata}}function ci(t,n){if(t.length!==n.length)return!1;for(let s=0;s<t.length;s+=1)if(t[s].id!==n[s].id||t[s].timestamp!==n[s].timestamp||t[s].type!==n[s].type||t[s].title!==n[s].title||t[s].requesterAgentId!==n[s].requesterAgentId||t[s].requesterAgentName!==n[s].requesterAgentName||t[s].executorAgentId!==n[s].executorAgentId||t[s].executorAgentName!==n[s].executorAgentName)return!1;return!0}function fr(t,n){if(t.nodes.length!==n.nodes.length||t.edges.length!==n.edges.length||t.groups.length!==n.groups.length)return!1;for(let s=0;s<t.nodes.length;s+=1){const r=t.nodes[s],i=n.nodes[s];if(r.id!==i.id||r.status!==i.status||r.title!==i.title||r.progress!==i.progress||r.updatedAt!==i.updatedAt||r.lastEventAt!==i.lastEventAt)return!1}for(let s=0;s<t.edges.length;s+=1){const r=t.edges[s],i=n.edges[s];if(r.parentId!==i.parentId||r.childId!==i.childId)return!1}for(let s=0;s<t.groups.length;s+=1){const r=t.groups[s],i=n.groups[s];if(r.id!==i.id||r.label!==i.label||r.status!==i.status)return!1}return!0}function gr(t,n){if(t.length!==n.length)return!1;for(let s=0;s<t.length;s+=1)if(t[s].id!==n[s].id||t[s].updatedAt!==n[s].updatedAt||t[s].status!==n[s].status||t[s].title!==n[s].title)return!1;return!0}function br(t,n){if(t.length!==n.length)return!1;for(let s=0;s<t.length;s+=1)if(t[s].id!==n[s].id||t[s].status!==n[s].status||t[s].updatedAt!==n[s].updatedAt||t[s].waitingMinutes!==n[s].waitingMinutes)return!1;return!0}function di(t){if(!t||typeof t!="object")return oi;const n=t.pendingByQueue&&typeof t.pendingByQueue=="object"?Object.fromEntries(Object.entries(t.pendingByQueue).filter(([r])=>typeof r=="string"&&r.length>0).map(([r,i])=>[r,Number.isFinite(Number(i))?Math.max(0,Math.floor(Number(i))):0])):{},s=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(n).reduce((r,i)=>r+i,0),pendingByQueue:n,oldestEventAt:t.oldestEventAt??null,newestEventAt:t.newestEventAt??null,replayStatus:s,lastReplayAttemptAt:t.lastReplayAttemptAt??null,lastReplaySuccessAt:t.lastReplaySuccessAt??null,lastReplayFailureAt:t.lastReplayFailureAt??null,lastReplayError:t.lastReplayError??null}}function la(t,n){if(t.pendingTotal!==n.pendingTotal||t.oldestEventAt!==n.oldestEventAt||t.newestEventAt!==n.newestEventAt||t.replayStatus!==n.replayStatus||t.lastReplayAttemptAt!==n.lastReplayAttemptAt||t.lastReplaySuccessAt!==n.lastReplaySuccessAt||t.lastReplayFailureAt!==n.lastReplayFailureAt||t.lastReplayError!==n.lastReplayError)return!1;const s=Object.keys(t.pendingByQueue),r=Object.keys(n.pendingByQueue);if(s.length!==r.length)return!1;for(const i of s)if(t.pendingByQueue[i]!==n.pendingByQueue[i])return!1;return!0}function ca(t,n,s){if(n.length===0)return t;const r=new Map;for(const l of t)r.set(l.id,l);let i=!1;for(const l of n){const c=r.get(l.id);if(!c){r.set(l.id,l),i=!0;continue}(c.timestamp!==l.timestamp||c.type!==l.type||c.title!==l.title||c.description!==l.description||c.summary!==l.summary||c.kind!==l.kind||c.agentId!==l.agentId||c.agentName!==l.agentName||c.requesterAgentId!==l.requesterAgentId||c.requesterAgentName!==l.requesterAgentName||c.executorAgentId!==l.executorAgentId||c.executorAgentName!==l.executorAgentName||c.runId!==l.runId||c.initiativeId!==l.initiativeId||c.decisionRequired!==l.decisionRequired||JSON.stringify(c.metadata??null)!==JSON.stringify(l.metadata??null))&&(r.set(l.id,l),i=!0)}if(!i)return t;const o=Array.from(r.values()).sort((l,c)=>{const h=Je(c.timestamp)-Je(l.timestamp);return h!==0?h:c.id.localeCompare(l.id)}).slice(0,s);return ci(t,o)?t:o}function fs(t,n){const s=[...t].sort((o,l)=>{const c=Je(l.timestamp)-Je(o.timestamp);return c!==0?c:l.id.localeCompare(o.id)}).slice(0,n),r=new Set,i=[];for(const o of s)r.has(o.id)||(r.add(o.id),i.push(o));return i}function yr(t,n){const s=t.filter(o=>!!o&&typeof o.id=="string"&&o.id.length>0).map(oa).sort((o,l)=>o.waitingMinutes!==l.waitingMinutes?l.waitingMinutes-o.waitingMinutes:Je(l.requestedAt??l.updatedAt)-Je(o.requestedAt??o.updatedAt)).slice(0,n),r=new Set,i=[];for(const o of s)r.has(o.id)||(r.add(o.id),i.push(o));return i}function wr(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 da(t){const n=t.toLowerCase();return n==="running"||n==="active"?"running":n==="queued"||n==="pending"?"queued":n==="blocked"?"blocked":n==="failed"?"failed":n==="completed"||n==="done"?"completed":"archived"}function ua(t,n){return!!(li.has(n)||t.runId&&t.runId.trim().length>0||t.currentTask&&t.currentTask.trim().length>0)}function Pn(t){return t?`Initiative ${t.length>16?`${t.slice(0,8)}…`:t}`:"Unscoped"}function gs(t){if(!Array.isArray(t))return[];const n=[];for(const s of t)typeof s=="string"&&s.trim().length>0&&n.push(s.trim());return n}function ma(t,n,s){const r=new Map,i=[...t].sort((c,h)=>Je(h.timestamp)-Je(c.timestamp));for(const c of i){if(!c.runId)continue;const h=c.runId,x=r.get(h),d=c.timestamp;if(!x){const u=c.initiativeId??null;r.set(h,{id:h,parentId:null,runId:h,title:c.title,agentId:c.agentId??null,agentName:c.agentName??null,status:wr(c.type),progress:null,initiativeId:u,workstreamId:null,groupId:u??"unscoped",groupLabel:Pn(u),startedAt:d,updatedAt:d,lastEventAt:d,lastEventSummary:c.title,blockers:c.type==="blocker_created"&&c.description?[c.description]:[]});continue}(!x.startedAt||Je(d)<Je(x.startedAt))&&(x.startedAt=d),Je(d)>=Je(x.updatedAt??x.lastEventAt)&&(x.updatedAt=d,x.lastEventAt=d,x.lastEventSummary=c.title,x.status=wr(c.type),c.agentName&&(x.agentName=c.agentName),c.agentId&&(x.agentId=c.agentId),c.initiativeId&&(x.initiativeId=c.initiativeId,x.groupId=c.initiativeId,x.groupLabel=Pn(c.initiativeId)),(!x.title||x.title.length<4)&&(x.title=c.title)),c.type==="blocker_created"&&c.description&&(x.blockers.includes(c.description)||x.blockers.push(c.description))}for(const c of n??[]){const h=c.runId??`agent:${c.id}`,x=r.get(h),d=da(c.status),u=new Date().toISOString(),p=ua(c,d),m=c.startedAt??(p?u:null),j=c.initiativeId??null,w=c.currentTask&&c.currentTask.trim().length>0?c.currentTask.trim():`${c.name??c.id} ${d==="archived"?"idle":d}`;if(!x){r.set(h,{id:h,parentId:null,runId:h,title:w,agentId:c.id,agentName:c.name??c.id,status:d,progress:null,initiativeId:j,workstreamId:null,groupId:j??"unscoped",groupLabel:Pn(j),startedAt:m,updatedAt:m,lastEventAt:m,lastEventSummary:c.currentTask,blockers:gs(c.blockers)});continue}!x.agentName&&c.name&&(x.agentName=c.name),x.agentId||(x.agentId=c.id),(!x.title||x.title===x.runId)&&(x.title=w),p&&(x.updatedAt=m??x.updatedAt??u,x.lastEventAt=m??x.lastEventAt??u),x.status==="archived"&&d!=="archived"&&(x.status=d),gs(c.blockers).length>0&&(x.blockers=gs(c.blockers)),j&&!x.initiativeId&&(x.initiativeId=j,x.groupId=j,x.groupLabel=Pn(j))}const o=Array.from(r.values()).sort(Qn).slice(0,s),l=new Map;for(const c of o)l.has(c.groupId)||l.set(c.groupId,{id:c.groupId,label:c.groupLabel,status:c.status});return{nodes:o,edges:[],groups:Array.from(l.values())}}async function pa(t,n){var s;try{const r=await fetch(t,n),o=(((s=r.headers.get("content-type"))==null?void 0:s.toLowerCase())??"").includes("application/json");if(!r.ok){let l=`${r.status} ${r.statusText}`;if(o){const c=await r.json().catch(()=>null);c!=null&&c.error&&(l=`${r.status} ${c.error}`)}else{const c=(await r.text().catch(()=>"")).replace(/\s+/g," ").slice(0,80);c.length>0&&(l=`${r.status} ${c}`)}return{ok:!1,status:r.status,data:null,error:l}}if(!o){const l=(await r.text().catch(()=>"")).replace(/\s+/g," ").slice(0,80);return{ok:!1,status:r.status,data:null,error:`Unexpected content type for ${t}${l?`: ${l}`:""}`}}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 xa(t,n,s,r,i=oi,o=null,l=[]){var d,u,p;const c=((d=n[0])==null?void 0:d.timestamp)??null,h=((u=r[0])==null?void 0:u.requestedAt)??((p=r[0])==null?void 0:p.updatedAt)??null,x=Je(c)>=Je(h)?c:h;return{connection:"connected",lastActivity:x?Ge(x):null,lastSnapshotAt:o,sessions:t,activity:n,handoffs:s,decisions:r,outbox:di(i),runtimeInstances:l}}function vr(t){if(!Array.isArray(t)||t.length===0)return[];const n=new Map;for(const s of t){if(!s||typeof s!="object"||typeof s.id!="string")continue;const r=s.id.trim();r&&n.set(r,s)}return Array.from(n.values()).sort((s,r)=>Je(r.lastEventAt??r.lastHeartbeatAt)-Je(s.lastEventAt??s.lastHeartbeatAt))}function jr(t,n){const s=t??[],r=n??[];if(s.length!==r.length)return!1;for(let i=0;i<s.length;i+=1)if(s[i].id!==r[i].id||s[i].state!==r[i].state||s[i].lastEventAt!==r[i].lastEventAt||s[i].runId!==r[i].runId||s[i].progressPct!==r[i].progressPct)return!1;return!0}function ha(t={}){const{enabled:n=!0,pollInterval:s=ea,useMock:r=!1,enableDecisions:i=!0,maxSessions:o=ta,maxActivityItems:l=na,maxHandoffs:c=sa,maxDecisions:h=ra,batchWindowMs:x=ia}=t,[d,u]=a.useState(cr()),[p,m]=a.useState(!r),[j,w]=a.useState(null),E=a.useRef(),v=a.useRef(null),[y,A]=a.useState(!1),k=a.useRef(0),D=a.useRef(!1),O=a.useCallback((ne,te,M,L=null,C=null,S=null,f=null)=>{k.current=Date.now(),D.current=!1;const R=fs(te,l),V=hr(M,c);u(H=>{const G=Ln(xr(H.sessions,Ln(ne,o)),o),Y=L===null?H.decisions:yr(L,h),ie=C===null?H.outbox:di(C),J=f===null?H.runtimeInstances??[]:vr(f);return fr(H.sessions,G)&&ci(H.activity,R)&&gr(H.handoffs,V)&&br(H.decisions,Y)&&la(H.outbox,ie)&&jr(H.runtimeInstances,J)&&H.lastSnapshotAt===S&&H.connection==="connected"?H:xa(G,R,V,Y,ie,S,J)}),m(!1)},[l,h,c,o]),I=a.useCallback(async()=>{if(!n){u(te=>te.connection==="disconnected"?te:{...te,connection:"disconnected"}),m(!1),w(null);return}if(v.current)return v.current;if(r){u(cr()),m(!1);return}const ne=(async()=>{try{const te=new URLSearchParams({sessionsLimit:String(o),activityLimit:String(l),decisionsLimit:String(h),include_idle:"true"}),M=[{label:"dashboard-bundle",url:`/orgx/api/dashboard-bundle?${te.toString()}`},{label:"live/snapshot",url:`/orgx/api/live/snapshot?${te.toString()}`}],L=[];let C=null,S=!1;for(const Y of M){const ie=await pa(Y.url);if(ie.ok&&ie.data){C=ie.data;break}(ie.status===401||ie.status===403)&&(S=!0),L.push(`${Y.label}: ${ie.error??"unavailable"}`)}if(!C){if(S){const Y=new Error("Unauthorized. Update your OrgX API key in Settings (use a user-scoped oxk_... key; userId should be blank).");throw Y.code="ORGX_AUTH",Y}throw new Error(L.length>0?L.join(" | "):"Snapshot endpoint unavailable")}const f=Array.isArray(C.activity)?C.activity:[],R=Array.isArray(C.handoffs)?C.handoffs:[],V=i&&Array.isArray(C.decisions)?C.decisions:[],H=C.sessions&&Array.isArray(C.sessions.nodes)&&Array.isArray(C.sessions.edges)&&Array.isArray(C.sessions.groups)?C.sessions:ma(f,C.agents,o);O(H,f,R,V,C.outbox??null,C.generatedAt??null,C.runtimeInstances??null);const G=Array.isArray(C.degraded)?C.degraded:[];G.length>0?(w(`Partial live data: ${G.join("; ")}`),u(Y=>Y.connection==="connected"?Y:{...Y,connection:"connected"}),A(!1)):(w(null),u(Y=>Y.connection==="connected"?Y:{...Y,connection:"connected"}))}catch(te){const M=te instanceof Error?te.message:"Unknown error",L=!!(te&&typeof te=="object"&&"code"in te&&te.code==="ORGX_AUTH");L&&(D.current=!0);const C=k.current>0&&Date.now()-k.current>dr;w(M),u(S=>{const f=L||C?"disconnected":"reconnecting";return S.connection===f?S:{...S,connection:f}}),A(!L),m(!1)}finally{v.current=null}})();return v.current=ne,ne},[O,n,i,l,h,c,o,r]),ee=a.useCallback(async(ne,te,M)=>{if(!i)throw new Error("OrgX decisions are unavailable while disconnected.");const L=Array.from(new Set(ne.filter(Boolean)));if(L.length===0)return{updated:0,failed:0};if(r){const G=new Set(L);return u(Y=>{const ie=Y.decisions.filter(fe=>G.has(fe.id));if(ie.length===0)return Y;const J=new Date().toISOString(),Fe=ie.map(fe=>({id:`decision:${te}:${fe.id}:${Date.now()}`,type:"decision_resolved",title:te==="approve"?`Approved: ${fe.title}`:`Rejected: ${fe.title}`,description:fe.context,agentId:null,agentName:fe.agentName,requesterAgentId:null,requesterAgentName:fe.agentName??null,executorAgentId:null,executorAgentName:fe.agentName??null,runId:null,initiativeId:null,timestamp:J,metadata:{decisionId:fe.id,action:te}})),he=fs(Fe.concat(Y.activity),l);return{...Y,decisions:Y.decisions.filter(fe=>!G.has(fe.id)),activity:he,lastActivity:Ge(J)}}),{updated:G.size,failed:0}}const C=await fetch("/orgx/api/live/decisions/approve",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({ids:L,action:te,...M?{note:M}:{}})}),S=await C.json().catch(()=>null),f=Array.isArray(S==null?void 0:S.results)?S.results:[],R=new Set(f.filter(G=>G.ok).map(G=>G.id));if(!C.ok&&C.status!==207){const G=typeof(S==null?void 0:S.error)=="string"?S.error:`Decision action failed (${C.status})`;throw new Error(G)}if(R.size===0&&C.ok&&((S==null?void 0:S.failed)??0)===0)for(const G of L)R.add(G);R.size>0?u(G=>{const Y=G.decisions.filter(fe=>R.has(fe.id));if(Y.length===0)return G;const ie=new Date().toISOString(),J=Y.map(fe=>({id:`decision:${te}:${fe.id}:${Date.now()}`,type:"decision_resolved",title:te==="approve"?`Approved: ${fe.title}`:`Rejected: ${fe.title}`,description:fe.context,agentId:null,agentName:fe.agentName,requesterAgentId:null,requesterAgentName:fe.agentName??null,executorAgentId:null,executorAgentName:fe.agentName??null,runId:null,initiativeId:null,timestamp:ie,metadata:{decisionId:fe.id,action:te}})),Fe=fs(J.concat(G.activity),l);return{...G,decisions:G.decisions.filter(fe=>!R.has(fe.id)),activity:Fe,lastActivity:Ge(ie)}}):C.ok&&L.length>0&&u(G=>({...G,decisions:G.decisions.filter(Y=>!L.includes(Y.id))})),I();const V=(S==null?void 0:S.updated)??R.size,H=(S==null?void 0:S.failed)??Math.max(0,L.length-R.size);return{updated:V,failed:H}},[i,I,l,r]),X=a.useCallback(async(ne,te)=>ee([ne],"approve",te),[ee]),le=a.useCallback(async(ne,te)=>ee([ne],"reject",te),[ee]),Q=a.useCallback(async()=>{let ne=[];return u(te=>(ne=te.decisions.map(M=>M.id),te)),ne.length===0?{updated:0,failed:0}:ee(ne,"approve")},[ee]);return a.useEffect(()=>{i||u(ne=>ne.decisions.length===0?ne:{...ne,decisions:[]})},[i]),a.useEffect(()=>{if(!n){A(!1),m(!1),w(null);return}if(r){I();return}I();const ne=new EventSource("/orgx/api/live/stream"),te=new EventSource("/orgx/api/hooks/runtime/stream");let M=null,L=null,C=null,S=null,f=[],R=null,V;const H=()=>{if(V=void 0,M){k.current=Date.now(),D.current=!1;const ie=M;M=null,C=null,S=null,f=[],R=null,L=null,O(ie.sessions,ie.activity,ie.handoffs,ie.decisions,ie.outbox,ie.generatedAt,ie.runtimeInstances);return}!C&&!S&&!R&&!L&&f.length===0||(k.current=Date.now(),D.current=!1,u(ie=>{var Fe;let J=ie;if(C){const he=Ln(C,o),fe=Ln(xr(J.sessions,he),o);C=null,fr(J.sessions,fe)||(J={...J,sessions:fe})}if(S){const he=hr(S,c);S=null,gr(J.handoffs,he)||(J={...J,handoffs:he})}if(R){const he=yr(R,h);R=null,br(J.decisions,he)||(J={...J,decisions:he})}if(L){const he=vr(L);L=null,jr(J.runtimeInstances,he)||(J={...J,runtimeInstances:he})}if(f.length>0){const he=ca(J.activity,f,l);f=[],he!==J.activity&&(J={...J,activity:he,lastActivity:(Fe=he[0])!=null&&Fe.timestamp?Ge(he[0].timestamp):J.lastActivity})}return J===ie?ie:J.connection==="connected"?J:{...J,connection:"connected"}}),w(null),m(!1))},G=()=>{V||(V=setTimeout(H,x))};ne.onopen=()=>{k.current=Date.now(),D.current=!1,A(!1),u(ie=>ie.connection==="connected"?ie:{...ie,connection:"connected"}),w(null)},ne.onerror=()=>{if(D.current){u(J=>J.connection==="disconnected"?J:{...J,connection:"disconnected"}),A(!1);return}const ie=k.current>0&&Date.now()-k.current>dr;u(J=>J.connection===(ie?"disconnected":"reconnecting")?J:{...J,connection:ie?"disconnected":"reconnecting"}),A(!0)},ne.addEventListener("snapshot",ie=>{try{const J=JSON.parse(ie.data),Fe=typeof J.generatedAt=="string"&&J.generatedAt.length>0?J.generatedAt:new Date().toISOString();M={sessions:J.sessions,activity:J.activity??[],handoffs:J.handoffs??[],decisions:i?J.decisions??null:[],outbox:J.outbox??null,generatedAt:Fe,runtimeInstances:Array.isArray(J.runtimeInstances)?J.runtimeInstances:null},G()}catch(J){w(J instanceof Error?J.message:"Invalid snapshot")}}),ne.addEventListener("activity.appended",ie=>{try{const J=JSON.parse(ie.data);if(J.length===0)return;f=f.concat(J),G()}catch{}}),ne.addEventListener("session.updated",ie=>{try{C=JSON.parse(ie.data),G()}catch{}});const Y=ie=>{try{const J=JSON.parse(ie.data);L=Array.isArray(J)?J:[J],G()}catch{}};return ne.addEventListener("runtime.updated",Y),te.addEventListener("runtime.updated",Y),ne.addEventListener("handoff.updated",ie=>{try{S=JSON.parse(ie.data),G()}catch{}}),ne.addEventListener("decision.updated",ie=>{if(i)try{R=JSON.parse(ie.data),G()}catch{}}),()=>{V&&clearTimeout(V),ne.close(),te.close()}},[O,x,n,i,I,l,h,c,o,r]),a.useEffect(()=>{if(n&&!r&&(E.current&&clearInterval(E.current),!!y))return E.current=setInterval(I,s),()=>{E.current&&clearInterval(E.current)}},[n,I,s,y,r]),{data:d,isLoading:p,error:j,refetch:I,approveDecision:X,rejectDecision:le,approveAllDecisions:Q}}const Sn=[{id:"30m",label:"30m",minutes:30},{id:"live",label:"Live",minutes:null},{id:"all",label:"All",minutes:null},{id:"24h",label:"24h",minutes:1440},{id:"3d",label:"3d",minutes:4320},{id:"7d",label:"7d",minutes:10080},{id:"30d",label:"30d",minutes:720*60}];function ui(t){return Sn.find(n=>n.id===t)??Sn[0]}function Gs(t,n=Date.now()){if(t==="all")return null;if(t==="live")return n-60*6e4;const s=Sn.find(r=>r.id===t);return!s||s.minutes===null?null:n-s.minutes*6e4}function fa(t,n=Date.now()){const s=Gs(t,n);return s?new Date(s).toISOString():null}function Yn(t){if(!t)return 0;const n=Date.parse(t);return Number.isFinite(n)?n:0}function mi(t,n){const s=Yn(n.timestamp)-Yn(t.timestamp);return s!==0?s:String(n.id).localeCompare(String(t.id))}function ga(t,n){const s=JSON.stringify({beforeEpoch:t,beforeId:n});return btoa(unescape(encodeURIComponent(s))).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+/g,"")}function kr(t){if(!t||t.length===0)return null;const n=t[t.length-1],s=Yn(n.timestamp);return s?ga(s,String(n.id)):null}function ba(t,n,s){const r=new Map;for(const i of t??[]){if(!i||typeof i.id!="string"||s&&i.runId!==s)continue;const o=Yn(i.timestamp);o&&(n!==null&&o<n||r.set(i.id,i))}return Array.from(r.values()).sort(mi)}function Nr(t,n){if(n.length===0)return t;const s=new Map;for(const i of t)s.set(i.id,i);let r=!1;for(const i of n){const o=s.get(i.id);if(!o){s.set(i.id,i),r=!0;continue}(o.timestamp!==i.timestamp||o.type!==i.type||o.title!==i.title||o.description!==i.description||o.summary!==i.summary||JSON.stringify(o.metadata??null)!==JSON.stringify(i.metadata??null))&&(s.set(i.id,i),r=!0)}return r?Array.from(s.values()).sort(mi):t}function ya(t){const{seed:n,timeFilterId:s,runId:r=null,pageSize:i=50}=t,o=a.useMemo(()=>Gs(s),[s]),l=a.useMemo(()=>fa(s),[s]),c=a.useMemo(()=>ba(n,o,r),[n,o,r]),[h,x]=a.useState(c),[d,u]=a.useState(()=>kr(c)),[p,m]=a.useState(!1),[j,w]=a.useState(null),[E,v]=a.useState(null),y=a.useRef(null);a.useEffect(()=>{x(c),u(kr(c)),w(null),v(null)},[c,s,r]),a.useEffect(()=>{x(D=>Nr(D,c))},[c]);const A=a.useCallback(async()=>{if(!d)return;if(y.current)return y.current;m(!0);const D=(async()=>{try{const O=new URLSearchParams;O.set("limit",String(Math.max(1,Math.min(500,i)))),O.set("cursor",d),l&&O.set("since",l),r&&r.trim().length>0&&O.set("run",r.trim());const I=await fetch(`/orgx/api/live/activity/page?${O.toString()}`),ee=await I.json().catch(()=>null);if(!I.ok||!ee)throw new Error(`Activity paging failed (${I.status})`);const X=Array.isArray(ee.activities)?ee.activities:[];x(le=>Nr(le,X)),u(ee.nextCursor??null),v(ee.storeUpdatedAt??null),w(null)}catch(O){w(O instanceof Error?O.message:"Activity paging failed")}finally{m(!1),y.current=null}})();return y.current=D,D},[d,i,r,l]);return{items:h,hasMore:d!==null,isLoadingMore:p,error:j,storeUpdatedAt:E,loadMore:A,cutoffEpoch:o,sinceIso:l}}const wa="https://orgx.mintlify.site/guides/openclaw-plugin-setup",va=1500,bs="orgx.onboarding.skip",ja=680,ka=`<!doctype html>
3
- <html lang="en">
4
- <head>
5
- <meta charset="utf-8" />
6
- <meta name="viewport" content="width=device-width, initial-scale=1" />
7
- <title>Connecting to OrgX</title>
8
- <style>
9
- :root {
10
- --bg: #02040a;
11
- --surface: #0c0e14;
12
- --surface-soft: #0f121a;
13
- --line: rgba(255, 255, 255, 0.1);
14
- --text: #f2f7ff;
15
- --muted: rgba(242, 247, 255, 0.62);
16
- --lime: #bfff00;
17
- --teal: #14b8a6;
18
- --iris: #7c7cff;
19
- }
20
-
21
- * { box-sizing: border-box; }
22
-
23
- body {
24
- margin: 0;
25
- min-height: 100vh;
26
- background:
27
- radial-gradient(920px 460px at 14% 14%, rgba(124, 124, 255, 0.12), transparent 68%),
28
- radial-gradient(840px 420px at 84% 88%, rgba(20, 184, 166, 0.12), transparent 72%),
29
- var(--bg);
30
- color: var(--text);
31
- font-family: "SF Pro Text", "SF Pro Display", Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
32
- display: grid;
33
- place-items: center;
34
- padding: 24px;
35
- }
36
-
37
- .shell {
38
- width: min(640px, 100%);
39
- border-radius: 22px;
40
- border: 1px solid var(--line);
41
- background:
42
- linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.015)),
43
- var(--surface);
44
- box-shadow:
45
- 0 28px 80px rgba(0, 0, 0, 0.58),
46
- inset 0 1px 0 rgba(255, 255, 255, 0.05);
47
- overflow: hidden;
48
- }
49
-
50
- .header {
51
- display: flex;
52
- align-items: center;
53
- justify-content: space-between;
54
- gap: 12px;
55
- padding: 16px 18px;
56
- border-bottom: 1px solid rgba(255, 255, 255, 0.08);
57
- background: rgba(0, 0, 0, 0.16);
58
- }
59
-
60
- .brand {
61
- display: inline-flex;
62
- align-items: center;
63
- gap: 10px;
64
- }
65
-
66
- .brand-mark {
67
- width: 22px;
68
- height: 22px;
69
- color: var(--lime);
70
- opacity: 0.95;
71
- }
72
-
73
- .brand-name {
74
- font-size: 14px;
75
- font-weight: 700;
76
- letter-spacing: 0.01em;
77
- color: rgba(242, 247, 255, 0.92);
78
- }
79
-
80
- .chip {
81
- display: inline-flex;
82
- align-items: center;
83
- gap: 6px;
84
- border: 1px solid rgba(191, 255, 0, 0.3);
85
- background: rgba(191, 255, 0, 0.12);
86
- color: #d8ffa1;
87
- border-radius: 999px;
88
- padding: 4px 10px;
89
- font-size: 11px;
90
- font-weight: 600;
91
- letter-spacing: 0.06em;
92
- text-transform: uppercase;
93
- }
94
-
95
- .dot {
96
- width: 7px;
97
- height: 7px;
98
- border-radius: 50%;
99
- background: var(--lime);
100
- box-shadow: 0 0 0 0 rgba(191, 255, 0, 0.56);
101
- animation: pulse 1.6s infinite ease-out;
102
- }
103
-
104
- .content {
105
- padding: 20px 20px 18px;
106
- }
107
-
108
- h1 {
109
- margin: 0;
110
- font-size: 24px;
111
- line-height: 1.18;
112
- letter-spacing: -0.02em;
113
- }
114
-
115
- .subtitle {
116
- margin: 8px 0 0;
117
- color: var(--muted);
118
- font-size: 14px;
119
- line-height: 1.5;
120
- }
121
-
122
- .steps {
123
- margin-top: 16px;
124
- display: grid;
125
- gap: 8px;
126
- }
127
-
128
- .step {
129
- display: flex;
130
- align-items: center;
131
- gap: 9px;
132
- border: 1px solid rgba(255, 255, 255, 0.08);
133
- background: var(--surface-soft);
134
- border-radius: 12px;
135
- padding: 10px 12px;
136
- font-size: 12px;
137
- }
138
-
139
- .step svg {
140
- flex-shrink: 0;
141
- width: 14px;
142
- height: 14px;
143
- }
144
-
145
- .meta {
146
- margin-top: 12px;
147
- padding-top: 12px;
148
- border-top: 1px solid rgba(255, 255, 255, 0.08);
149
- color: rgba(242, 247, 255, 0.42);
150
- font-size: 11px;
151
- }
152
-
153
- @keyframes pulse {
154
- 0% { box-shadow: 0 0 0 0 rgba(191, 255, 0, 0.56); }
155
- 100% { box-shadow: 0 0 0 12px rgba(191, 255, 0, 0); }
156
- }
157
- </style>
158
- </head>
159
- <body>
160
- <main class="shell">
161
- <header class="header">
162
- <div class="brand">
163
- <svg class="brand-mark" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
164
- <path d="M5.5 7h5.8l6.7 6"></path>
165
- <path d="M5.5 17h5.8l6.7-6"></path>
166
- <path d="M5.5 12h12.5"></path>
167
- <path d="m15.3 9.3 2.7 2.7-2.7 2.7"></path>
168
- </svg>
169
- <span class="brand-name">OrgX</span>
170
- </div>
171
- <div class="chip"><span class="dot"></span>Pairing</div>
172
- </header>
173
- <section class="content">
174
- <h1>Connecting to OrgX</h1>
175
- <p class="subtitle">Preparing a secure workspace session. This window will continue automatically.</p>
176
- <div class="steps">
177
- <div class="step">
178
- <svg viewBox="0 0 24 24" fill="none" stroke="#7C7CFF" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
179
- <circle cx="12" cy="12" r="9"></circle>
180
- <circle cx="12" cy="12" r="4.5"></circle>
181
- </svg>
182
- <span>Initializing plugin handshake</span>
183
- </div>
184
- <div class="step">
185
- <svg viewBox="0 0 24 24" fill="none" stroke="#14B8A6" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
186
- <path d="M5 3v18"></path>
187
- <path d="m5 4 12 1-2 4 2 4-12-1z"></path>
188
- </svg>
189
- <span>Opening browser approval for this workspace</span>
190
- </div>
191
- <div class="step">
192
- <svg viewBox="0 0 24 24" fill="none" stroke="#BFFF00" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
193
- <rect x="4" y="4" width="16" height="16" rx="4"></rect>
194
- <path d="M9 12.2 11 14.2 15.2 10"></path>
195
- </svg>
196
- <span>Syncing initiatives, tasks, and decisions</span>
197
- </div>
198
- </div>
199
- <div class="meta">If redirect does not start, return to OpenClaw and click “Approve in browser”.</div>
200
- </section>
201
- </main>
202
- </body>
203
- </html>`,ys={status:"idle",hasApiKey:!1,connectionVerified:!1,workspaceName:null,lastError:null,nextAction:"connect",docsUrl:wa,keySource:"none",installationId:null,connectUrl:null,pairingId:null,expiresAt:null,pollIntervalMs:null};function Na(t){if(typeof t=="string")return t;if(t&&typeof t=="object")return JSON.stringify(t)}async function yn(t){const n=await t,s=await n.json().catch(()=>null);return n.ok?s??{}:{ok:!1,error:Na(s==null?void 0:s.error)??`Request failed (${n.status})`}}function Dn(t){if(t)try{ii.identify(t)}catch{}}function Sa(){const[t,n]=a.useState(ys),[s,r]=a.useState(!0),[i,o]=a.useState(!1),[l,c]=a.useState(!1),h=a.useRef(null),[x,d]=a.useState(()=>typeof window>"u"?!1:window.localStorage.getItem(bs)==="1"),u=a.useCallback(async()=>{const y=await yn(fetch("/orgx/api/onboarding/status",{method:"GET"}));if(!y.ok||!y.data){const A=y.error??"Failed to load onboarding state",k={...ys,status:"error",lastError:A,nextAction:"retry"};return n(k),k}return Dn(y.data.installationId??null),n(y.data),y.data},[]);a.useEffect(()=>{let y=!1;return(async()=>{r(!0);const A=await u();y||(n(A),r(!1))})(),()=>{y=!0}},[u]),a.useEffect(()=>{if(!(t.status==="awaiting_browser_auth"||t.status==="pairing"))return;const A=Math.max(900,t.pollIntervalMs??va),k=window.setInterval(async()=>{const D=await yn(fetch("/orgx/api/onboarding/status",{method:"GET"}));D.ok&&D.data&&(Dn(D.data.installationId??null),n(D.data))},A);return()=>{window.clearInterval(k)}},[t.pollIntervalMs,t.status]),a.useEffect(()=>{if(!(typeof window>"u")){if(x){window.localStorage.setItem(bs,"1");return}window.localStorage.removeItem(bs)}},[x]);const p=a.useCallback(()=>{if(typeof window>"u")return null;try{const y=window.open("","_blank");return y?(y.opener=null,y.document.title="Connecting to OrgX…",y.document.open(),y.document.write(ka),y.document.close(),y):null}catch{return null}},[]),m=a.useCallback(async()=>{const y=p();h.current=y,o(!0);try{const A=await yn(fetch("/orgx/api/onboarding/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({deviceName:navigator.platform||"OpenClaw Device",platform:navigator.platform})})),k=A.data;if(!A.ok||!(k!=null&&k.state)){y&&!y.closed&&y.close();const O=A.error??"Could not start pairing";n(I=>({...I,status:"error",lastError:O,nextAction:"enter_manual_key"}));return}n(k.state);const D=k.connectUrl;if(D){const O=h.current;let I=!1;if(O&&!O.closed)try{window.setTimeout(()=>{if(!O.closed)try{O.location.href=D}catch{}},ja),I=!0}catch{I=!1}I||(I=!!window.open(D,"_blank","noopener,noreferrer")),I||n(ee=>({...ee,lastError:'Popup was blocked. Use "Approve in browser" below.',nextAction:"open_browser"}))}}finally{h.current=null,o(!1)}},[p]),j=a.useCallback(async y=>{c(!0);try{const A=y.trim(),k=A.replace(/^[a-z]+_/i,""),D=Array.from(new Set([A,k?`oxk_${k}`:"",k?`orgx_${k}`:""].map(I=>I.trim()).filter(I=>I.length>0)));let O="Manual key validation failed";for(const I of D){const ee={"Content-Type":"application/json","X-OrgX-Api-Key":I,Authorization:`Bearer ${I}`},X=await yn(fetch("/orgx/api/onboarding/manual-key",{method:"POST",headers:ee,body:JSON.stringify({apiKey:I})}));if(X.ok&&X.data)return Dn(X.data.installationId??null),n(X.data),X.data;O=X.error??O}throw n(I=>({...I,status:"manual_key",lastError:O,nextAction:"enter_manual_key"})),new Error(O)}finally{c(!1)}},[]),w=a.useCallback(async()=>{const y=await yn(fetch("/orgx/api/onboarding/disconnect",{method:"POST"}));if(y.ok&&y.data)return Dn(y.data.installationId??null),n(y.data),y.data;const A={...ys,status:"idle"};return n(A),A},[]),E=a.useCallback(()=>{n(y=>({...y,status:"idle",lastError:null,nextAction:"connect",connectUrl:null,pairingId:null,expiresAt:null,pollIntervalMs:null}))},[]),v=a.useMemo(()=>x?!1:!(t.hasApiKey&&t.connectionVerified&&t.status==="connected"),[x,t.connectionVerified,t.hasApiKey,t.status]);return{state:t,showGate:v,isLoading:s,isStarting:i,isSubmittingManual:l,refreshStatus:u,startPairing:m,submitManualKey:j,disconnect:w,skipGate:()=>d(!0),resumeGate:()=>d(!1),backToPairing:E,setManualMode:()=>n(y=>({...y,status:"manual_key",nextAction:"enter_manual_key"}))}}function de(...t){return t.filter(Boolean).join(" ")}const N={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"},Ca={Pace:"#7C7CFF",Eli:"#BFFF00",Dana:"#FF00D4",Mark:"#F5B700",System:"#14B8A6",Sage:"#0AD4C4",Orion:"#14B8A6",Xandy:"#FF6B88",Nova:"#A78BFA"},Aa={Pace:"Engineering",Eli:"Engineering",Dana:"Product Design",Mark:"Marketing",System:"System",Sage:"Strategy",Orion:"Operations",Xandy:"Orchestrator",Nova:"Research"};function Ia(t){return Ca[t]??"rgba(255, 255, 255, 0.4)"}function pi(t){return Aa[t]??null}function _a(t){return t.split(" ").map(n=>n[0]).join("").toUpperCase().slice(0,2)}function bt(t){return t.trim().toLowerCase().replace(/[\s-]+/g,"_")}const as="/orgx/live/assets/Fm0FhtnV.png";function xi({size:t=14,className:n="",stroke:s="currentColor",strokeWidth:r=1.8,withBackground:i=!1,backgroundColor:o="transparent"}){return e.jsxs("svg",{className:n,width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:s,strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:r,children:[i?e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"4.5",fill:o,stroke:"none"}):null,e.jsx("path",{d:"M5.5 7h5.8l6.7 6"}),e.jsx("path",{d:"M5.5 17h5.8l6.7-6"}),e.jsx("path",{d:"M5.5 12h12.5"}),e.jsx("path",{d:"m15.3 9.3 2.7 2.7-2.7 2.7"})]})}function Oe({type:t,className:n="",size:s=14,accent:r}){const i={className:n,width:s,height:s,viewBox:"0 0 24 24",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.8};if(t==="initiative"){const l=r??N.iris;return e.jsxs("svg",{...i,stroke:l,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9",fill:`${l}1A`}),e.jsx("circle",{cx:"12",cy:"12",r:"5"}),e.jsx("circle",{cx:"12",cy:"12",r:"1.5",fill:l,stroke:"none"})]})}if(t==="workstream"){const l=r??N.lime;return e.jsx(xi,{size:s,className:n,stroke:l,strokeWidth:i.strokeWidth,withBackground:!0,backgroundColor:`${l}1A`})}if(t==="milestone"){const l=r??N.teal;return e.jsxs("svg",{...i,stroke:l,children:[e.jsx("path",{d:"M5 3v18"}),e.jsx("path",{d:"m5 4 12 1-2 4 2 4-12-1z",fill:`${l}1A`})]})}if(t==="task")return e.jsxs("svg",{...i,stroke:"rgba(255,255,255,0.76)",children:[e.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"4",fill:"rgba(255,255,255,0.12)"}),e.jsx("path",{d:"M9 12.2 11 14.2 15.2 10"})]});if(t==="decision"){const l=r??N.amber;return e.jsxs("svg",{...i,stroke:l,children:[e.jsx("path",{d:"M12 3 5.2 6.1v5.7c0 4.8 3.2 7.5 6.8 9 3.6-1.5 6.8-4.2 6.8-9V6.1z",fill:`${l}1A`}),e.jsx("path",{d:"m9.3 12.1 1.8 1.9 3.6-3.6"})]})}if(t==="session"){const l=r??N.teal;return e.jsxs("svg",{...i,stroke:l,children:[e.jsx("rect",{x:"4",y:"5",width:"16",height:"14",rx:"4",fill:`${l}14`}),e.jsx("path",{d:"M8 9h8"}),e.jsx("path",{d:"M8 13h5"}),e.jsx("path",{d:"M8 17h3"})]})}if(t==="active"){const l=r??N.lime;return e.jsxs("svg",{...i,stroke:l,children:[e.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"6",fill:`${l}12`}),e.jsx("path",{d:"M7 13h2l1.6-6 3.1 12 1.6-6H17"})]})}if(t==="blocked"){const l=r??N.red;return e.jsxs("svg",{...i,stroke:l,children:[e.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"6",fill:`${l}12`}),e.jsx("rect",{x:"7.5",y:"11",width:"9",height:"7",rx:"2",fill:"rgba(255,255,255,0.03)"}),e.jsx("path",{d:"M9 11V9.2a3 3 0 0 1 6 0V11"})]})}if(t==="failed"){const l=r??N.red;return e.jsxs("svg",{...i,stroke:l,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9",fill:`${l}12`}),e.jsx("path",{d:"M9 9l6 6"}),e.jsx("path",{d:"M15 9l-6 6"})]})}if(t==="handoff"){const l=r??N.iris;return e.jsxs("svg",{...i,stroke:l,children:[e.jsx("path",{d:"M7 12h10"}),e.jsx("path",{d:"m13 8 4 4-4 4"}),e.jsx("path",{d:"M7 8v8",opacity:"0.55"})]})}if(t==="outbox"){const l=r??N.amber;return e.jsxs("svg",{...i,stroke:l,children:[e.jsx("path",{d:"M4 12h16"}),e.jsx("path",{d:"M6 7h12l2 5v7a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-7z",fill:`${l}12`}),e.jsx("path",{d:"M9 14h6"})]})}const o=r??N.cyan;return e.jsxs("svg",{...i,stroke:o,children:[e.jsx("path",{d:"M12 3a6 6 0 0 0-6 6v2.9c0 .7-.3 1.4-.8 1.9L4 15.2h16l-1.2-1.4a2.8 2.8 0 0 1-.8-1.9V9a6 6 0 0 0-6-6z",fill:`${o}1A`}),e.jsx("path",{d:"M9.2 18a2.8 2.8 0 0 0 5.6 0"})]})}const Ma=[{label:"Model Routing",desc:"Right model, right cost, every prompt",iconType:"initiative"},{label:"Live Operations",desc:"Decisions, handoffs, sessions in real time",iconType:"workstream"},{label:"Quality Gates",desc:"Automated checkpoints before shipping",iconType:"milestone"}],Hn=[{id:"hierarchy",kicker:"Mission Control",title:"Map the full execution ladder in one place",description:"Trace initiatives through workstreams, milestones, and tasks with sticky context, dependency mapping, and inline edits.",highlights:[{type:"initiative",label:"Initiative",detail:"Top-level outcomes with owner and status."},{type:"workstream",label:"Workstream",detail:"Operational lanes and runner context."},{type:"milestone",label:"Milestone",detail:"Checkpoints that gate readiness."},{type:"task",label:"Task",detail:"Priority, ETA, budget, and dependencies."}],footnote:"Use the hierarchy filters to isolate open, blocked, or done work instantly."},{id:"activity",kicker:"Activity + Decisions",title:"Stay in flow while execution evolves",description:"Track agent output as it happens, review decision payloads, and keep operational context attached from plan to completion.",highlights:[{type:"notification",label:"Live feed",detail:"Messages, failures, and progress in one stream."},{type:"decision",label:"Decision queue",detail:"Approve or reject with full execution context."},{type:"workstream",label:"Handoffs",detail:"Runner transitions across domains and tasks."},{type:"task",label:"Artifacts",detail:"Completion evidence attached where it belongs."}],footnote:"Focus a session to pin a run while the rest of the org remains visible."},{id:"dispatch",kicker:"Autopilot + Next Up",title:"Dispatch work confidently with clear guardrails",description:"Queue the next workstream, open the owning initiative instantly, and escalate from manual play to controlled auto-continue.",highlights:[{type:"workstream",label:"Next Up",detail:"Queued workstreams with resolved runner and next task."},{type:"initiative",label:"Open target",detail:"Jump to the owning initiative and sticky hierarchy."},{type:"milestone",label:"Guardrails",detail:"Blocked states are surfaced before dispatch."},{type:"notification",label:"System notices",detail:"Inline success and failure feedback loops."}],footnote:"Start with Play, then enable auto-continue when queue health is stable."}],Ea=[{type:"initiative",label:"Live Initiative Sync",detail:"Initiatives and ownership stay aligned with OpenClaw execution."},{type:"decision",label:"Decision Control",detail:"Review approvals in-app without losing mission context."},{type:"workstream",label:"Queue Visibility",detail:"Understand what runs next, who runs it, and why."}],Sr="openclaw plugins install @useorgx/openclaw-plugin",Cr="orgx.demo_mode",Fa=6500;function $a(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 Ta={hidden:{},visible:{transition:{staggerChildren:.07}}},Rt={hidden:{opacity:0,y:14},visible:{opacity:1,y:0,transition:{duration:.45,ease:[.16,1,.3,1]}}},La={initiative:"text-[#A8A0FF]",workstream:"text-[#BFFF00]",milestone:"text-[#43E7D8]",task:"text-primary",session:"text-[#43E7D8]",active:"text-[#BFFF00]",blocked:"text-[#FF6B88]",failed:"text-[#FF6B88]",handoff:"text-[#A8A0FF]",outbox:"text-[#F5D37A]",decision:"text-[#F5D37A]",notification:"text-[#7EEDE1]"};function ws(t){const n=Hn.length;return(t+n)%n}function Pa({state:t,isStarting:n,onConnect:s,onUseManualKey:r,onContinueWithoutOrgX:i}){const o=!!t.lastError,[l,c]=a.useState("idle"),[h,x]=a.useState("idle"),[d,u]=a.useState(0),[p,m]=a.useState(!1),j=t.hasApiKey&&t.keySource&&t.keySource!=="none",w=Hn[d];a.useEffect(()=>{if(l==="idle")return;const y=window.setTimeout(()=>c("idle"),2e3);return()=>window.clearTimeout(y)},[l]),a.useEffect(()=>{if(h==="idle")return;const y=window.setTimeout(()=>x("idle"),2e3);return()=>window.clearTimeout(y)},[h]),a.useEffect(()=>{if(p)return;const y=window.setInterval(()=>{u(A=>ws(A+1))},Fa);return()=>window.clearInterval(y)},[p]);const E=async()=>{try{await navigator.clipboard.writeText(Sr),c("ok")}catch{c("error")}},v=async()=>{try{const y={at:new Date().toISOString(),onboarding:{status:t.status,nextAction:t.nextAction,hasApiKey:t.hasApiKey,keySource:t.keySource,installationId:t.installationId,lastError:t.lastError},page:typeof window<"u"?window.location.href:null,userAgent:typeof navigator<"u"?navigator.userAgent:null};await navigator.clipboard.writeText(JSON.stringify(y,null,2)),x("ok")}catch{x("error")}};return e.jsxs(we.section,{variants:Ta,initial:"hidden",animate:"visible",className:"bg-[--orgx-surface-elevated] border border-[--orgx-border] soft-shadow rounded-2xl",children:[e.jsxs("div",{className:"px-6 pt-4 sm:px-8 sm:pt-5",children:[e.jsxs(we.div,{variants:Rt,className:"flex items-center gap-2.5",children:[e.jsx("img",{src:as,alt:"OrgX",className:"h-7 w-7 rounded-lg object-contain"}),e.jsx("span",{className:"text-body font-semibold text-primary",children:"OrgX"})]}),e.jsxs(we.h2,{variants:Rt,className:"mt-3 flex items-center gap-2.5 text-[24px] font-semibold leading-[1.2] tracking-[-0.02em] text-white sm:text-[28px]",children:[e.jsx(Oe,{type:"workstream",size:19,className:"opacity-95"}),"Connect your workspace"]}),e.jsx(we.p,{variants:Rt,className:"mt-2 max-w-2xl text-heading leading-relaxed text-secondary",children:"Orchestrate agents, approve decisions, and track progress from a single live dashboard."})]}),e.jsxs("div",{className:"mt-3 grid gap-3 px-6 sm:px-8 lg:grid-cols-[1.24fr_0.86fr]",children:[e.jsxs(we.div,{variants:Rt,className:"space-y-2.5",children:[e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.02] p-3.5",onMouseEnter:()=>m(!0),onMouseLeave:()=>m(!1),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Oe,{type:"workstream",size:14,className:"text-[#BFFF00]"}),e.jsx("p",{className:"text-micro uppercase tracking-[0.1em] text-secondary",children:"Guided Tour"})]}),e.jsxs("span",{className:"chip text-micro",children:[d+1,"/",Hn.length]})]}),e.jsx(yt,{initial:!1,mode:"wait",children:e.jsxs(we.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},exit:{opacity:0,y:-8},transition:{duration:.24,ease:[.22,1,.36,1]},className:"mt-2.5 min-h-[214px] space-y-2.5",children:[e.jsx("p",{className:"text-micro font-semibold uppercase tracking-[0.09em] text-muted",children:w.kicker}),e.jsx("h3",{className:"text-title font-semibold leading-snug text-white/94",children:w.title}),e.jsx("p",{className:"text-body leading-relaxed text-secondary",children:w.description}),e.jsx("div",{className:"grid gap-1.5 sm:grid-cols-2",children:w.highlights.map(y=>e.jsxs("div",{className:"rounded-lg border border-white/[0.08] bg-white/[0.02] px-2.5 py-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Oe,{type:y.type,size:12,className:"flex-shrink-0 opacity-92"}),e.jsx("p",{className:"text-caption font-semibold text-bright",children:y.label})]}),e.jsx("p",{className:"mt-0.5 text-micro leading-relaxed text-secondary",children:y.detail})]},`${w.id}-${y.label}`))}),e.jsx("p",{className:"text-micro leading-relaxed text-muted",children:w.footnote})]},w.id)}),e.jsxs("div",{className:"mt-1.5 flex items-center justify-between",children:[e.jsx("div",{className:"flex items-center gap-1.5",children:Hn.map((y,A)=>{const k=A===d;return e.jsx("button",{type:"button",onClick:()=>u(A),"aria-label":`View slide ${A+1}`,className:`h-1.5 rounded-full transition-all ${k?"w-6 bg-[#BFFF00]":"w-2 bg-white/24 hover:bg-white/38"}`},y.id)})}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>u(y=>ws(y-1)),className:"rounded-full border border-strong bg-white/[0.03] px-2.5 py-1 text-caption text-primary transition hover:bg-white/[0.08] hover:text-white",children:"Prev"}),e.jsx("button",{type:"button",onClick:()=>u(y=>ws(y+1)),className:"rounded-full border border-strong bg-white/[0.03] px-2.5 py-1 text-caption text-primary transition hover:bg-white/[0.08] hover:text-white",children:"Next"})]})]})]}),e.jsx("div",{className:"grid grid-cols-1 gap-2.5 sm:grid-cols-3",children:Ma.map(y=>e.jsxs("div",{className:"rounded-xl border border-subtle bg-white/[0.025] px-3 py-2.5",children:[e.jsx("div",{className:`mb-1.5 ${La[y.iconType]}`,children:e.jsx(Oe,{type:y.iconType,size:15})}),e.jsx("p",{className:"text-caption font-semibold text-white",children:y.label}),e.jsx("p",{className:"mt-0.5 text-micro leading-snug text-white/44",children:y.desc})]},y.label))}),e.jsxs(we.div,{variants:Rt,className:"flex flex-wrap items-center gap-2.5",children:[e.jsx("button",{type:"button",onClick:s,disabled:n,className:"inline-flex items-center gap-2 rounded-full bg-[#BFFF00] px-5 py-2.5 text-body font-semibold text-black shadow-[0_0_24px_rgba(191,255,0,0.12)] transition-all hover:bg-[#d3ff42] hover:shadow-[0_0_32px_rgba(191,255,0,0.22)] disabled:cursor-not-allowed disabled:opacity-50",children:n?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-body text-secondary transition hover:border-white/[0.18] hover:text-bright",children:"Use API key"})]})]}),e.jsxs(we.div,{variants:Rt,className:"space-y-2.5",children:[e.jsxs("div",{className:"rounded-xl border border-[#14B8A6]/20 bg-[#14B8A6]/[0.06] px-3.5 py-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Oe,{type:"workstream",size:12,className:"text-[#7EEDE1]"}),e.jsx("p",{className:"text-caption uppercase tracking-[0.08em] text-[#7EEDE1]",children:"OpenClaw Integration"})]}),e.jsx("p",{className:"mt-1 text-caption leading-relaxed text-[#CFF8F3]",children:"OrgX syncs with OpenClaw so initiatives, workstreams, milestones, and tasks stay aligned with live execution."})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.02] px-3.5 py-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Oe,{type:"task",size:12,className:"opacity-90"}),e.jsx("p",{className:"text-caption uppercase tracking-[0.08em] text-muted",children:"Quick Setup"})]}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[e.jsx("code",{className:"rounded-md border border-white/[0.08] bg-black/30 px-2 py-1 font-mono text-caption text-primary",children:Sr}),e.jsx("button",{type:"button",onClick:()=>{E()},className:"rounded-full border border-strong px-3 py-1 text-caption text-secondary transition hover:border-white/[0.2] hover:text-bright",children:l==="ok"?"Copied":l==="error"?"Copy failed":"Copy command"})]}),j&&e.jsxs("p",{className:"mt-2 text-caption text-secondary",children:["API key source detected: ",$a(t.keySource)]})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.02] px-3.5 py-3",children:[e.jsx("p",{className:"text-caption uppercase tracking-[0.08em] text-muted",children:"What Unlocks After Connect"}),e.jsx("div",{className:"mt-2 space-y-1.5",children:Ea.map(y=>e.jsxs("div",{className:"rounded-lg border border-white/[0.08] bg-white/[0.02] px-2.5 py-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Oe,{type:y.type,size:12,className:"flex-shrink-0 opacity-90"}),e.jsx("p",{className:"text-caption font-semibold text-bright",children:y.label})]}),e.jsx("p",{className:"mt-0.5 text-micro leading-relaxed text-secondary",children:y.detail})]},y.label))})]})]})]}),e.jsx(we.div,{variants:Rt,className:"mx-6 mt-2 sm:mx-8",children:o?e.jsxs("div",{className:"flex items-center gap-3 rounded-xl border border-red-500/15 bg-red-500/[0.04] px-4 py-3",children:[e.jsx("span",{className:"flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-red-500/15",children:e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",children:e.jsx("path",{d:"M5 2.5v3M5 7.5h.004",stroke:"#FF6B88",strokeWidth:"1.4",strokeLinecap:"round"})})}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx("p",{className:"text-body text-red-300/80",children:t.lastError})}),e.jsxs("div",{className:"flex flex-shrink-0 items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>void v(),className:"rounded-full border border-strong bg-white/[0.04] px-3 py-1 text-caption font-medium text-primary transition hover:bg-white/[0.08] hover:text-white",title:"Copy debug details for support",children:h==="ok"?"Copied":h==="error"?"Copy failed":"Copy debug"}),e.jsx("button",{type:"button",onClick:r,className:"rounded-full border border-strong bg-white/[0.04] px-3 py-1 text-caption font-medium text-primary transition hover:bg-white/[0.08] hover:text-white",children:"Use API key"}),e.jsx("button",{type:"button",onClick:s,disabled:n,className:"rounded-full border border-red-500/20 bg-red-500/[0.06] px-3 py-1 text-caption font-semibold text-red-200/85 transition hover:bg-red-500/[0.09] hover:text-red-100 disabled:opacity-50",children:"Retry"})]})]}):e.jsxs("div",{className:"flex items-center gap-2 rounded-xl border border-subtle bg-white/[0.02] px-3.5 py-2",children:[e.jsx("span",{className:"relative flex h-1.5 w-1.5",children:e.jsx("span",{className:"relative inline-flex h-1.5 w-1.5 rounded-full bg-white/40"})}),e.jsx("span",{className:"text-body text-muted",children:"Ready to connect"})]})}),e.jsxs(we.div,{variants:Rt,className:"mt-2 flex flex-wrap items-center justify-between gap-2 border-t border-subtle px-6 py-2 sm:px-8",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx("button",{type:"button",onClick:()=>{try{window.localStorage.setItem(Cr,"1")}catch{}i()},className:"text-left text-caption text-muted transition hover:text-secondary",children:"Explore demo dashboard"}),e.jsx("button",{type:"button",onClick:()=>{try{window.localStorage.removeItem(Cr)}catch{}i()},className:"text-left text-caption text-faint transition hover:text-secondary",children:"Continue offline"})]}),e.jsxs("a",{href:t.docsUrl,target:"_blank",rel:"noopener noreferrer",className:"group inline-flex items-center gap-1 text-caption text-muted transition hover:text-secondary",children:["Setup guide",e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",className:"transition-transform group-hover:translate-x-0.5",children:e.jsx("path",{d:"M3.5 2.5l3 2.5-3 2.5",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round"})})]})]})]})}const Da={hidden:{},visible:{transition:{staggerChildren:.06}}},Gt={hidden:{opacity:0,y:10},visible:{opacity:1,y:0,transition:{duration:.35,ease:[.16,1,.3,1]}}};function hi({isSubmitting:t,onSubmit:n,onBack:s}){const[r,i]=a.useState(""),[o,l]=a.useState(null),c="https://www.useorgx.com/settings#security",h=async()=>{l(null);const d=r.trim();if(!d){l("API key is required.");return}const u=/^[a-z]+_/i.test(d)?d:`oxk_${d}`;try{await n(u),i("")}catch(p){l(p instanceof Error?p.message:"Failed to validate API key.")}},x=o!==null;return e.jsxs(we.section,{variants:Da,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(we.div,{variants:Gt,className:"flex items-center gap-2.5",children:[e.jsx("img",{src:as,alt:"OrgX",className:"h-7 w-7 rounded-lg object-contain"}),e.jsx("span",{className:"text-body font-semibold text-primary",children:"OrgX"})]}),e.jsx(we.h3,{variants:Gt,className:"mt-5 text-[22px] font-semibold tracking-[-0.02em] text-white",children:"Manual API key"}),e.jsxs(we.p,{variants:Gt,className:"mt-1.5 text-heading leading-relaxed text-secondary",children:["Paste a key from your ",e.jsx("span",{className:"text-secondary",children:"useorgx.com"})," dashboard. Browser pairing is recommended."]}),e.jsxs(we.p,{variants:Gt,className:"mt-1 text-body text-muted",children:["Paste full key or only the part after ",e.jsx("span",{className:"font-mono text-secondary",children:"oxk_"}),"."]}),e.jsx(we.div,{variants:Gt,className:"mt-3",children:e.jsxs("a",{href:c,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-2 rounded-full border border-white/[0.10] bg-white/[0.03] px-3 py-1.5 text-body font-semibold text-secondary transition hover:bg-white/[0.06] hover:text-primary",title:"Open OrgX settings to generate an API key",children:["Generate an API key",e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none","aria-hidden":"true",children:[e.jsx("path",{d:"M4.5 2.5h5v5",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round"}),e.jsx("path",{d:"M9.5 2.5L5 7",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round"}),e.jsx("path",{d:"M2.75 3.5H2.5c-.55 0-1 .45-1 1v5c0 .55.45 1 1 1h5c.55 0 1-.45 1-1V9.5",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round"})]})]})})]}),e.jsxs(we.div,{variants:Gt,className:"mt-6 space-y-4 px-6 sm:px-8",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"mb-1.5 block text-caption font-medium uppercase tracking-[0.14em] text-muted",children:"API key"}),e.jsxs("div",{className:`flex items-stretch overflow-hidden rounded-xl border transition-colors focus-within:border-[#BFFF00]/40 ${x?"border-red-500/30":"border-white/[0.08]"}`,children:[e.jsx("span",{className:"flex items-center border-r border-subtle bg-white/[0.03] px-3 font-mono text-body text-faint select-none",children:"oxk_"}),e.jsx("input",{value:r,onChange:d=>{i(d.target.value),o&&l(null)},placeholder:"paste your key",className:"w-full bg-transparent px-3 py-2.5 font-mono text-body text-white outline-none placeholder:text-faint"})]}),x&&e.jsx(we.p,{initial:{opacity:0,y:-3},animate:{opacity:1,y:0},className:"mt-1.5 text-body text-red-400/70",children:o})]}),e.jsxs("p",{className:"text-body text-muted",children:["User-scoped keys (",e.jsx("span",{className:"font-mono text-secondary",children:"oxk_..."}),") do not require a separate user ID header."]})]}),e.jsxs(we.div,{variants:Gt,className:"mt-6 flex flex-wrap items-center gap-3 px-6 sm:px-8",children:[e.jsx("button",{type:"button",onClick:()=>{h()},disabled:t,className:"inline-flex items-center gap-2 rounded-full bg-[#BFFF00] px-5 py-2.5 text-body font-semibold text-black shadow-[0_0_24px_rgba(191,255,0,0.12)] transition-all hover:bg-[#d3ff42] hover:shadow-[0_0_32px_rgba(191,255,0,0.22)] disabled:cursor-not-allowed disabled:opacity-50",children:t?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"h-3.5 w-3.5 animate-spin",viewBox:"0 0 16 16",fill:"none",children:[e.jsx("circle",{cx:"8",cy:"8",r:"6",stroke:"currentColor",strokeWidth:"2",opacity:"0.2"}),e.jsx("path",{d:"M14 8a6 6 0 00-6-6",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]}),"Validating..."]}):"Validate & Connect"}),e.jsx("button",{type:"button",onClick:s,className:"rounded-full border border-white/[0.1] px-4 py-2 text-body text-secondary transition hover:border-white/[0.18] hover:text-bright",children:"Back to pairing"})]}),e.jsx("div",{className:"mt-6 border-t border-subtle px-6 py-4 sm:px-8",children:e.jsx("p",{className:"text-body text-faint",children:"Keys are stored locally and never leave your device."})})]})}const Ba=[{label:"Terms",href:"https://www.useorgx.com/terms"},{label:"Privacy",href:"https://www.useorgx.com/privacy"},{label:"IP notice",href:"https://www.useorgx.com/legal"}];function fi({className:t,compact:n=!1}){return e.jsxs("div",{className:de("flex flex-wrap items-center gap-x-3 gap-y-1 text-muted",n?"text-micro":"text-caption",t),children:[e.jsxs("span",{className:"text-faint",children:["© ",new Date().getFullYear()," OrgX"]}),Ba.map(s=>e.jsx("a",{href:s.href,target:"_blank",rel:"noopener noreferrer nofollow",className:"transition-colors hover:text-secondary",children:s.label},s.label))]})}function Ra(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 Oa(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 qa(t){return t==="awaiting_browser_auth"||t==="pairing"||t==="starting"?"active":t==="error"?"error":t==="connected"?"active":"idle"}const Ar={idle:"bg-white/40",active:"bg-[#BFFF00]",error:"bg-red-400"},vs="orgx.onboarding.mc_hint.dismissed",Ir={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 za({state:t,isLoading:n,isStarting:s,isSubmittingManual:r,onRefresh:i,onStartPairing:o,onSubmitManualKey:l,onBackToPairing:c,onUseManualKey:h,onSkip:x}){const[d,u]=a.useState(()=>typeof window>"u"?!1:window.localStorage.getItem(vs)==="1");a.useEffect(()=>{typeof window>"u"||(d?window.localStorage.setItem(vs,"1"):window.localStorage.removeItem(vs))},[d]);const p=t.status==="manual_key",m=t.status==="awaiting_browser_auth"||t.status==="pairing",j=qa(t.status),w=j==="active"&&t.status!=="connected",E=t.status==="connected"&&!d;return e.jsx("div",{className:"relative flex min-h-screen items-start justify-center px-4 pb-6 pt-0 sm:pt-2",style:{backgroundColor:"#02040A"},children:e.jsxs(we.div,{initial:{opacity:0},animate:{opacity:1},transition:{duration:.45},className:`relative z-10 w-full ${p?"max-w-lg":"max-w-[1120px]"}`,children:[n?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(yt,{mode:"wait",children:p?e.jsx(we.div,{...Ir,children:e.jsx(hi,{isSubmitting:r,onSubmit:l,onBack:c})},"manual"):e.jsx(we.div,{...Ir,children:e.jsx(Pa,{state:t,isStarting:s,onConnect:()=>{o()},onUseManualKey:h,onContinueWithoutOrgX:x})},"explainer")}),!n&&(m||t.status==="connected")&&e.jsxs(we.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},exit:{opacity:0,y:6},transition:{delay:.15,duration:.35,ease:[.16,1,.3,1]},className:"mt-4 flex items-center justify-between rounded-xl border border-subtle bg-white/[0.025] px-4 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsxs("span",{className:"relative flex h-2 w-2",children:[w&&e.jsx("span",{className:`absolute inline-flex h-full w-full animate-ping rounded-full ${Ar[j]} opacity-40`}),e.jsx("span",{className:`relative inline-flex h-2 w-2 rounded-full ${Ar[j]}`})]}),e.jsx("span",{className:"text-body text-secondary",children:Ra(t.status)}),t.workspaceName&&e.jsx("span",{className:"chip",children:t.workspaceName}),t.keySource&&t.keySource!=="none"&&e.jsx("span",{className:"chip",children:Oa(t.keySource)})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[t.expiresAt&&e.jsx("span",{className:"text-caption text-muted",children:new Date(t.expiresAt).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}),t.connectUrl&&m&&e.jsx("a",{href:t.connectUrl,target:"_blank",rel:"noopener noreferrer",className:"rounded-full border border-[#BFFF00]/25 bg-[#BFFF00]/[0.05] px-3 py-1 text-caption font-medium text-[#D8FFA1] transition hover:bg-[#BFFF00]/[0.1]",children:"Approve in browser"}),e.jsx("button",{type:"button",onClick:()=>{i()},className:"rounded-full border border-white/[0.08] px-2.5 py-1 text-caption text-muted transition hover:bg-white/[0.04] hover:text-secondary",children:"Refresh"})]})]}),E&&e.jsxs(we.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},transition:{delay:.2,duration:.3},className:"mt-3 rounded-xl border border-[#7C7CFF]/25 bg-[#7C7CFF]/10 px-4 py-3",children:[e.jsx("p",{className:"text-caption uppercase tracking-[0.08em] text-[#CFCBFF]",children:"Mission Control Tip"}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-[#E6E4FF]",children:"Open Mission Control to see initiative → workstream → milestone → task flow with dependencies and recent todos in one expandable view."}),e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("a",{href:"/orgx/live?view=mission-control",className:"rounded-full border border-[#BFFF00]/30 bg-[#BFFF00]/15 px-3 py-1 text-caption font-medium text-[#D8FFA1]",children:"Open Mission Control"}),e.jsx("button",{type:"button",onClick:()=>u(!0),className:"text-caption text-secondary underline underline-offset-2",children:"Dismiss"})]})]}),!n&&e.jsx("div",{className:"mt-3 flex justify-center",children:e.jsx(fi,{compact:!0})})]})})}function kt({open:t,onClose:n,children:s,maxWidth:r="max-w-2xl",fitContent:i=!1}){const o=a.useRef(null),l=a.useRef(null);a.useEffect(()=>{if(!t)return;l.current=document.activeElement instanceof HTMLElement?document.activeElement:null,(()=>{const u=o.current;if(!u)return;const p=u.querySelector('[data-modal-autofocus="true"]');if(p){p.focus();return}const m=u.querySelectorAll('a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])');m.length>0?m[0].focus():u.focus()})();const x=u=>{if(u.key==="Escape"){u.preventDefault(),n();return}if(u.key!=="Tab")return;const p=o.current;if(!p)return;const m=p.querySelectorAll('a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])');if(m.length===0){u.preventDefault(),p.focus();return}const j=m[0],w=m[m.length-1],E=document.activeElement;!u.shiftKey&&E===w?(u.preventDefault(),j.focus()):u.shiftKey&&E===j&&(u.preventDefault(),w.focus())},d=document.body.style.overflow;return document.body.style.overflow="hidden",document.addEventListener("keydown",x),()=>{var u;document.body.style.overflow=d,document.removeEventListener("keydown",x),(u=l.current)==null||u.focus()}},[t,n]);const c=e.jsx(yt,{children:t&&e.jsxs(we.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:n,"aria-hidden":!t,children:[e.jsx("div",{className:"absolute inset-0 bg-black/80 backdrop-blur-md"}),e.jsxs(we.div,{initial:{opacity:0,scale:.95,y:20},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:20},transition:{duration:.24,ease:[.16,1,.3,1]},className:`glass-panel soft-shadow relative flex flex-col w-full ${r} overflow-hidden ${i?"h-auto max-h-[100dvh] rounded-none sm:max-h-[88vh] sm:rounded-2xl":"h-[100dvh] max-h-[100dvh] rounded-none sm:h-[88vh] sm:max-h-[88vh] sm:rounded-2xl"}`,style:{backgroundColor:N.cardBgElevated,borderColor:N.cardBorderStrong},onClick:h=>h.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"}),s]})]})});return typeof document>"u"?c:Ki.createPortal(c,document.body)}function ut(t){const n={};return t.contentTypeJson&&(n["Content-Type"]="application/json"),t.embedMode&&(n["X-Orgx-Embed"]="true"),t.authToken&&(n.Authorization=`Bearer ${t.authToken}`),n}function gi({authToken:t=null,embedMode:n=!1,enabled:s=!0}={}){var x,d;const r=is(),i=a.useMemo(()=>["byok-settings",{authToken:t,embedMode:n}],[t,n]),o=a.useMemo(()=>["byok-health",{authToken:t,embedMode:n}],[t,n]),l=Et({queryKey:i,enabled:s,queryFn:async()=>{const u=await fetch("/orgx/api/settings/byok",{headers:ut({authToken:t,embedMode:n})}),p=await u.json().catch(()=>null);return u.ok?p:{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:(p==null?void 0:p.error)??`Failed to load settings (${u.status})`}},staleTime:15e3}),c=Et({queryKey:o,enabled:!1,queryFn:async()=>{const u=await fetch("/orgx/api/settings/byok/health",{headers:ut({authToken:t,embedMode:n})}),p=await u.json().catch(()=>null);return u.ok?p:{ok:!1,agentId:"main",providers:{openai:{ok:!1,error:(p==null?void 0:p.error)??`Probe failed (${u.status})`},anthropic:{ok:!1,error:(p==null?void 0:p.error)??`Probe failed (${u.status})`},openrouter:{ok:!1,error:(p==null?void 0:p.error)??`Probe failed (${u.status})`}},error:(p==null?void 0:p.error)??`Probe failed (${u.status})`}}}),h=Ut({mutationFn:async u=>{const p=await fetch("/orgx/api/settings/byok",{method:"POST",headers:ut({authToken:t,embedMode:n,contentTypeJson:!0}),body:JSON.stringify(u??{})}),m=await p.json().catch(()=>null);if(!p.ok)throw new Error((m==null?void 0:m.error)??`Failed to save settings (${p.status})`);return m},onSuccess:async()=>{await r.invalidateQueries({queryKey:i})}});return{status:l.data??null,isLoading:l.isLoading,error:((x=l.data)==null?void 0:x.error)??((d=l.error)==null?void 0:d.message)??null,refetchStatus:l.refetch,update:h.mutateAsync,isSaving:h.isPending,health:c.data??null,probe:c.refetch,isProbing:c.isFetching}}const bi="orgx.first_run_guide.dismissed";function Ua(t){return e.jsx("span",{className:de("inline-flex h-2 w-2 rounded-full",t?"bg-emerald-400":"bg-white/35")})}function Wa(){try{return typeof window<"u"&&window.localStorage.getItem(bi)==="1"}catch{return!1}}function Ka(t){try{if(typeof window>"u")return;t&&window.localStorage.setItem(bi,"1")}catch{}}function Va({open:t,onClose:n,onOpenSettings:s,onOpenOrgxSettings:r,onOpenMissionControl:i,demoMode:o,connectionVerified:l,hasSessions:c}){const h=gi({enabled:t}),d=a.useMemo(()=>{var w;return(w=h.status)!=null&&w.ok?Number(h.status.providers.openai.configured)+Number(h.status.providers.anthropic.configured)+Number(h.status.providers.openrouter.configured):0},[h.status])>0,u=d?"mission-control":"settings",p=[{label:o?"Exit demo (optional)":"Connect OrgX",done:o?!1:l,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&&!l&&r?{label:"Connect",onClick:r}:null},{label:"Add provider key(s)",done:d,detail:"Set OpenAI / Anthropic / OpenRouter keys for agent launches, or rely on env vars.",action:d?null:{label:"Open settings",onClick:s}},{label:"Launch your first agent",done:c,detail:"Use the “Launch” button in Agents / Chats to start a scoped run."},{label:"Open Mission Control",done:!1,detail:"Track dependency-ready next-up tasks and start auto-continue for execution.",action:{label:"Open",onClick:i}}],m=p.filter(w=>w.done).length,j=Math.round(m/p.length*100);return e.jsx(kt,{open:t,onClose:n,maxWidth:"max-w-2xl",children:e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[e.jsx("div",{className:"border-b border-subtle px-5 py-4 sm:px-6",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-heading font-semibold text-white",children:"First run checklist"}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:"A fast path to seeing OrgX value inside OpenClaw."}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsxs("span",{className:"chip",children:[m," / ",p.length," complete"]}),e.jsxs("span",{className:"text-caption text-muted",children:[j,"% done"]})]}),e.jsx("div",{className:"mt-2 h-1.5 w-full max-w-[340px] overflow-hidden rounded-full bg-white/[0.08]",children:e.jsx("div",{className:"h-full rounded-full bg-[#BFFF00]/80",style:{width:`${j}%`}})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>{Ka(!0),n()},className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.08]",title:"Don't show automatically again",children:"Don't show again"}),e.jsx("button",{type:"button",onClick:n,"aria-label":"Close checklist",className:"inline-flex h-9 w-9 items-center justify-center rounded-full border border-strong bg-white/[0.03] text-primary transition-colors hover:bg-white/[0.08] hover:text-white",children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 6L6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})})]})]})}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-5 py-4 sm:px-6",children:e.jsxs("div",{className:"rounded-2xl border border-white/[0.07] bg-white/[0.02] p-4",children:[e.jsx("div",{className:"space-y-3",children:p.map(w=>e.jsxs("div",{className:de("flex items-start justify-between gap-3 rounded-xl border p-3",w.done?"border-subtle bg-white/[0.02]":"border-white/[0.10] bg-white/[0.03]"),children:[e.jsxs("div",{className:"flex min-w-0 items-start gap-3",children:[e.jsx("div",{className:"pt-1",children:Ua(w.done)}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:de("text-body font-semibold",w.done?"text-primary":"text-white"),children:w.label}),e.jsx("p",{className:"mt-0.5 text-body leading-relaxed text-secondary",children:w.detail})]})]}),w.action&&!w.done?e.jsx("button",{type:"button",onClick:w.action.onClick,"data-modal-autofocus":u==="settings"&&w.label==="Add provider key(s)"||u==="mission-control"&&w.label==="Open Mission Control"?"true":void 0,className:"shrink-0 rounded-full border border-[#BFFF00]/30 bg-[#BFFF00]/15 px-3 py-1.5 text-caption font-semibold text-[#D8FFA1]",children:w.action.label}):null]},w.label))}),e.jsxs("div",{className:"mt-4 flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",onClick:s,"data-modal-autofocus":u==="settings"?"true":void 0,className:"rounded-full border border-[#BFFF00]/30 bg-[#BFFF00]/15 px-3 py-1.5 text-caption font-semibold text-[#D8FFA1]",children:"Open settings"}),e.jsx("button",{type:"button",onClick:i,"data-modal-autofocus":u==="mission-control"?"true":void 0,className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.08]",children:"Open Mission Control"}),e.jsx("button",{type:"button",onClick:n,className:"rounded-full border border-strong px-3 py-1.5 text-caption text-secondary transition-colors hover:bg-white/[0.05] hover:text-primary",title:"Hide for now",children:"Not now"})]})]})}),e.jsx("div",{className:"border-t border-subtle px-5 py-3 sm:px-6",children:e.jsx("p",{className:"text-caption text-muted",children:"Tip: auto-continue is available per initiative from Mission Control quick actions."})})]})})}function _r({children:t,color:n,pulse:s,title:r}){const i=n??N.lime;return e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full px-2.5 py-1 text-micro font-semibold uppercase tracking-[0.14em]",title:r,style:{backgroundColor:`${i}22`,border:`1px solid ${i}5a`,color:i},children:[e.jsxs("span",{className:"relative flex h-1.5 w-1.5",children:[s&&e.jsx("span",{className:"absolute inline-flex h-full w-full animate-ping rounded-full opacity-75",style:{backgroundColor:i}}),e.jsx("span",{className:"relative inline-flex h-1.5 w-1.5 rounded-full",style:{backgroundColor:i}})]}),t]})}const Ha=[{id:"agents",label:"Agents",icon:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"}),e.jsx("circle",{cx:"12",cy:"7",r:"4"})]})},{id:"activity",label:"Activity",icon:e.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("polyline",{points:"22 12 18 12 15 21 9 3 6 12 2 12"})})},{id:"decisions",label:"Decisions",icon:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M12 22c5.523 0 10-4.477 10-10S17.523 2 12 2 2 6.477 2 12s4.477 10 10 10z"}),e.jsx("path",{d:"m9 12 2 2 4-4"})]})},{id:"initiatives",label:"Next Up",icon:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M4 15s1-1 4-1 5 2 8 2 4-1 4-1V3s-1 1-4 1-5-2-8-2-4 1-4 1z"}),e.jsx("line",{x1:"4",x2:"4",y1:"22",y2:"15"})]})}];function Ga({activeTab:t,onTabChange:n,pendingDecisionCount:s=0}){return e.jsx("nav",{className:"pointer-events-none fixed inset-x-0 z-40 flex justify-center px-3 lg:hidden",style:{bottom:"max(10px, env(safe-area-inset-bottom))"},"aria-label":"Mobile sections",children:e.jsx("div",{className:"pointer-events-auto relative flex items-stretch gap-1 rounded-[24px] border border-strong bg-[#090d16]/90 p-1.5 shadow-[0_20px_50px_rgba(0,0,0,0.52)] backdrop-blur-xl",children:Ha.map(r=>{const i=t===r.id;return e.jsxs("button",{type:"button",onClick:()=>n(r.id),"aria-current":i?"page":void 0,className:de("relative flex min-w-[76px] flex-1 flex-col items-center gap-1 overflow-hidden rounded-[18px] px-2 pb-1.5 pt-2.5 transition-colors",i?"text-lime":"text-secondary hover:text-white/72"),children:[i&&e.jsxs(e.Fragment,{children:[e.jsx(we.span,{layoutId:"mobile-tab-active-pill",className:"absolute inset-0 rounded-[18px] border border-[#BFFF00]/28 bg-[#BFFF00]/[0.1]",transition:{type:"spring",stiffness:420,damping:34,mass:.8}}),e.jsx(we.span,{layoutId:"mobile-tab-active-line",className:"absolute inset-x-3 top-0.5 h-[2px] rounded-full",style:{backgroundColor:N.lime},transition:{type:"spring",stiffness:440,damping:36,mass:.75}})]}),e.jsxs("span",{className:de("relative inline-flex h-8 w-8 items-center justify-center rounded-full border transition-colors",i?"border-[#BFFF00]/35 bg-[#BFFF00]/[0.12] text-[#D8FFA1]":"border-white/[0.1] bg-white/[0.03]"),children:[e.jsx("span",{className:"relative z-[1]",children:r.icon}),r.id==="decisions"&&s>0&&e.jsx("span",{className:"absolute -right-1.5 -top-1 flex h-3.5 min-w-[14px] items-center justify-center rounded-full border border-black/35 px-1 text-[8px] font-bold text-black shadow-[0_2px_8px_rgba(0,0,0,0.35)]",style:{backgroundColor:N.amber},children:s>99?"99+":s})]}),e.jsx("span",{className:de("relative z-[1] text-micro font-medium",i?"text-[#D8FFA1]":"text-secondary"),children:r.label})]},r.id)})})})}const Kc={active:"text-[#BFFF00] bg-[#BFFF00]/10 border-[#BFFF00]/20",paused:"text-[#F5B700] bg-[#F5B700]/10 border-[#F5B700]/20",blocked:"text-[#FF6B88] bg-[#FF6B88]/10 border-[#FF6B88]/20",completed:"text-[#14B8A6] bg-[#14B8A6]/10 border-[#14B8A6]/20"},Xa={done:"text-[#14B8A6] bg-[#14B8A6]/10 border-[#14B8A6]/20",completed:"text-[#14B8A6] bg-[#14B8A6]/10 border-[#14B8A6]/20",in_progress:"text-[#BFFF00] bg-[#BFFF00]/10 border-[#BFFF00]/20",active:"text-[#BFFF00] bg-[#BFFF00]/10 border-[#BFFF00]/20",blocked:"text-[#FF6B88] bg-[#FF6B88]/10 border-[#FF6B88]/20",todo:"text-white/60 bg-white/5 border-white/10"},Vc=t=>Xa[bt(t)]??"text-white/60 bg-white/5 border-white/10",Hc=t=>{const n=bt(t);return n==="active"||n==="in_progress"?"text-[#BFFF00] bg-[#BFFF00]/10 border-[#BFFF00]/20":n==="blocked"?"text-[#FF6B88] bg-[#FF6B88]/10 border-[#FF6B88]/20":n==="completed"||n==="done"?"text-[#14B8A6] bg-[#14B8A6]/10 border-[#14B8A6]/20":"text-white/60 bg-white/5 border-white/10"},Gc=t=>{const n=bt(t);return n==="done"||n==="completed"?"text-[#14B8A6] bg-[#14B8A6]/10 border-[#14B8A6]/20":n==="active"||n==="in_progress"?"text-[#BFFF00] bg-[#BFFF00]/10 border-[#BFFF00]/20":"text-white/60 bg-white/5 border-white/10"},Xc=t=>t.replace(/[_-]+/g," ").replace(/\s+/g," ").trim().replace(/\b\w/g,n=>n.toUpperCase()),Jc=t=>{const n=bt(t);return n==="blocked"?0:n==="in_progress"||n==="active"?1:n==="todo"||n==="planned"?2:n==="done"||n==="completed"?3:4},on=t=>{const n=bt(t);return n==="blocked"||n==="failed"||n==="cancelled"?N.red:n==="active"||n==="in_progress"||n==="running"?N.lime:n==="handoff"||n==="review"||n==="done"||n==="completed"?N.teal:n==="paused"||n==="queued"||n==="pending"||n==="working"||n==="planning"?N.amber:n==="archived"||n==="draft"?"rgba(255,255,255,0.5)":"rgba(255,255,255,0.35)"},Zn={codex:{id:"codex",label:"Codex",accent:"#10B981",tint:"rgba(16, 185, 129, 0.18)"},openai:{id:"openai",label:"OpenAI",accent:"#10B981",tint:"rgba(16, 185, 129, 0.18)"},anthropic:{id:"anthropic",label:"Anthropic",accent:"#F5B700",tint:"rgba(245, 183, 0, 0.18)"},openclaw:{id:"openclaw",label:"OpenClaw",accent:"#FF4D4D",tint:"rgba(255, 77, 77, 0.18)"},orgx:{id:"orgx",label:"OrgX",accent:N.lime,tint:"rgba(191, 255, 0, 0.18)"},unknown:{id:"unknown",label:"Agent",accent:N.teal,tint:"rgba(20, 184, 166, 0.18)"}},Ja=["provider","vendor","model","runtime","engine","agent","name","title","label","summary","description","source"];function Gn(t,n,s,r){if(!(t==null||s>2)){if(typeof t=="string"){const i=t.trim();i.length>0&&n.push(i);return}if(Array.isArray(t)){for(const i of t)Gn(i,n,s+1,r);return}if(typeof t=="object"){if(r.has(t))return;r.add(t);for(const[i,o]of Object.entries(t)){const l=i.toLowerCase();typeof o=="string"?(Ja.some(c=>l.includes(c))||l.startsWith("meta")||l.endsWith("id"))&&Gn(o,n,s+1,r):typeof o=="object"&&o!==null&&Gn(o,n,s+1,r)}}}}function Qa(t){const n=t.toLowerCase();return/\bcodex\b/.test(n)||/\bcursor\b/.test(n)||n.includes("openai/codex")?"codex":n.includes("openclaw")||n.includes("clawdbot")||n.includes("moltbot")?"openclaw":n.includes("anthropic")||n.includes("claude")||n.includes("sonnet")||n.includes("opus")?"anthropic":n.includes("openai")||n.includes("chatgpt")||/\bgpt[-\s]?\d/.test(n)||/\bo[134]/.test(n)?"openai":n.includes("orgx")?"orgx":null}function js(...t){const n=[],s=new Set;for(const r of t)Gn(r,n,0,s);for(const r of n){const i=Qa(r);if(i)return Zn[i]}return Zn.unknown}function Ya(t){return Zn[t]??Zn.unknown}const Za=new Set(["ungrouped","unscoped","unknown"]);function yi(t){const n=(t??"").trim().toLowerCase();return!!(!n||Za.has(n)||/^init-\d+$/.test(n)||n.startsWith("mock-"))}function eo(){if(typeof window>"u")return!1;try{if(new URLSearchParams(window.location.search).get("demo")==="1")return!0}catch{}try{return window.localStorage.getItem("orgx.demo_mode")==="1"}catch{return!1}}function to(t){return eo()?!0:!yi(t)}function Jt({children:t,className:n=""}){return e.jsx("section",{className:de("surface-tier-1 relative overflow-hidden rounded-2xl",n),children:t})}const no={xs:18,sm:24,md:30};function so({provider:t}){switch(t){case"openai":case"codex":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"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:as,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 ks({provider:t,size:n="sm",className:s,showRing:r=!0}){const i=Ya(t),o=no[n];return e.jsx("span",{className:de("inline-flex items-center justify-center rounded-md",s),style:{width:o,height:o,color:i.accent,backgroundColor:i.tint,border:r?`1px solid ${i.accent}55`:"none"},title:i.label,"aria-label":i.label,children:e.jsx("span",{style:{width:Math.round(o*.66),height:Math.round(o*.66),display:"inline-flex",alignItems:"center",justifyContent:"center"},children:e.jsx(so,{provider:t})})})}const ro={xs:"w-6 h-6 text-micro",sm:"w-8 h-8 text-micro",md:"w-10 h-10 text-body"},io="/orgx/live/",jt=t=>`${io.replace(/\/+$/,"/")}${t}`,ao={pace:jt("brand/product-orchestrator.png"),eli:jt("brand/engineering-autopilot.png"),mark:jt("brand/launch-captain.png"),sage:jt("brand/pipeline-intelligence.png"),orion:jt("brand/control-tower.png"),dana:jt("brand/design-codex.png"),xandy:jt("brand/product-orchestrator.png"),nova:jt("brand/product-orchestrator.png"),openclaw:jt("brand/openclaw-mark.svg"),codex:jt("brand/openai-mark.svg"),openai:jt("brand/openai-mark.svg"),anthropic:jt("brand/anthropic-mark.svg"),orgx:jt("brand/orgx-logo.png")},oo=[{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/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:"codex"},{test:/anthropic|claude/i,key:"anthropic"},{test:/\borgx\b/i,key:"orgx"}];function lo(...t){const n=t.map(s=>typeof s=="string"?s.trim():"").filter(Boolean).join(" ").toLowerCase();if(!n)return null;for(const s of oo)if(s.test.test(n))return ao[s.key];return null}function dt({name:t,size:n="xs",hint:s,src:r}){const i=Ia(t),[o,l]=a.useState(!1),c=a.useMemo(()=>r&&r.trim()?r:lo(t,s),[s,t,r]),h=!!(c&&!o);return e.jsx("div",{className:`${ro[n]} overflow-hidden rounded-full flex items-center justify-center font-semibold flex-shrink-0`,style:{backgroundColor:`${i}20`,color:i,border:`1px solid ${i}30`},children:h?e.jsx("img",{src:c??void 0,alt:t,className:"h-full w-full rounded-full object-cover",onError:()=>l(!0),loading:"lazy"}):_a(t)})}const zt={liveData:t=>["live-data",{authToken:t.authToken??null,embedMode:t.embedMode??!1,useMock:t.useMock??!1}],sessions:t=>["sessions",{activeMinutes:t.activeMinutes??null,limit:t.limit??null,authToken:t.authToken??null,embedMode:t.embedMode??!1}],initiativeDetails:t=>["initiative-details",{initiativeId:t.initiativeId,authToken:t.authToken??null,embedMode:t.embedMode??!1}],entities:t=>["entities",{type:t.type,authToken:t.authToken??null,embedMode:t.embedMode??!1}],missionControlGraph:t=>["mission-control-graph",{initiativeId:t.initiativeId,authToken:t.authToken??null,embedMode:t.embedMode??!1}],nextUpQueue:t=>["mission-control-next-up",{initiativeId:t.initiativeId??null,authToken:t.authToken??null,embedMode:t.embedMode??!1}],autoContinueStatus:t=>["auto-continue-status",{initiativeId:t.initiativeId,authToken:t.authToken??null,embedMode:t.embedMode??!1}],liveInitiatives:t=>["live-initiatives",{limit:(t==null?void 0:t.limit)??300}],artifactsByEntity:t=>["artifacts-by-entity",{entityType:t.entityType,entityId:t.entityId,authToken:t.authToken??null,embedMode:t.embedMode??!1}],artifactDetail:t=>["artifact-detail",{artifactId:t.artifactId,authToken:t.authToken??null,embedMode:t.embedMode??!1}]};function co(t){const n=t.toLowerCase();return n==="completed"||n==="done"?"completed":n==="blocked"||n==="at_risk"?"blocked":n==="paused"||n==="hold"?"paused":"active"}function uo(t){if(!t)return 0;const n=new Date(t),s=new Date;return Math.max(0,Math.ceil((n.getTime()-s.getTime())/864e5))}function mo(t){return{id:t.id,name:t.title,status:co(t.status),rawStatus:t.status??null,priority:t.priority??null,health:t.progress_pct??0,daysRemaining:uo(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 po(t){const n=t.toLowerCase();return!["deleted","archived","cancelled"].includes(n)}function wi(t){return Et({queryKey:zt.entities({type:"initiative"}),queryFn:async()=>{const n=await fetch("/orgx/api/entities?type=initiative&limit=300");return n.ok?((await n.json()).data??[]).filter(r=>po(r.status??"")).sort((r,i)=>{const o=Date.parse(r.updated_at??r.created_at??"")||0;return(Date.parse(i.updated_at??i.created_at??"")||0)-o}).map(mo):[]},enabled:t,staleTime:6e4})}const Bn={initiativeId:"",workstreams:[],milestones:[],tasks:[]},xo=(t,n)=>({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??n,createdAt:t.created_at??null}),ho=(t,n)=>({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??n,workstreamId:t.workstream_id??null,createdAt:t.created_at??null}),fo=(t,n)=>({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??n,milestoneId:t.milestone_id??null,workstreamId:t.workstream_id??null,createdAt:t.created_at??null});function go({initiativeId:t,authToken:n=null,embedMode:s=!1,enabled:r=!0}){var c;const i=to(t),o=a.useMemo(()=>zt.initiativeDetails({initiativeId:t,authToken:n,embedMode:s}),[t,n,s]),l=Et({queryKey:o,enabled:r&&!!t&&i,queryFn:async()=>{if(!t)return Bn;if(!i)return{...Bn,initiativeId:t};const h={};s&&(h["X-Orgx-Embed"]="true"),n&&(h.Authorization=`Bearer ${n}`);const x=Object.keys(h).length?h:void 0,d=async v=>{try{const y=new URLSearchParams({type:v,initiative_id:t,limit:"100"}),A=await fetch(`/orgx/api/entities?${y.toString()}`,{headers:x});return A.ok?await A.json():{data:[]}}catch{return{data:[]}}},[u,p,m]=await Promise.all([d("workstream"),d("milestone"),d("task")]),j=Array.isArray(u.data)?u.data.map(v=>xo(v,t)):[],w=Array.isArray(p.data)?p.data.map(v=>ho(v,t)):[],E=Array.isArray(m.data)?m.data.map(v=>fo(v,t)):[];return{initiativeId:t,workstreams:j,milestones:w,tasks:E}}});return{details:(i?l.data:null)??(t?{...Bn,initiativeId:t}:Bn),isLoading:i?l.isLoading:!1,error:i?((c=l.error)==null?void 0:c.message)??null:null,refetch:l.refetch}}function wn(t){const n=(t??"").toLowerCase();return n==="active"?{label:"Active",color:N.lime,bg:"rgba(191,255,0,0.12)"}:n==="blocked"?{label:"Blocked",color:"#fb7185",bg:"rgba(244, 63, 94, 0.12)"}:n==="idle"?{label:"Idle",color:"rgba(255,255,255,0.55)",bg:"rgba(255,255,255,0.06)"}:{label:t||"Unknown",color:N.iris,bg:"rgba(124,124,255,0.10)"}}function bo(t){return[...t.workstreams].sort((n,s)=>n.name.localeCompare(s.name))}function yo(t,n){return[...n?t.tasks.filter(r=>r.workstreamId===n):t.tasks].sort((r,i)=>r.title.localeCompare(i.title))}function wo({open:t,onClose:n,onLaunched:s}){var J,Fe,he,fe,et,W;const r=Et({queryKey:["openclaw-agent-catalog"],queryFn:async()=>{const F=await fetch("/orgx/api/agents/catalog");if(!F.ok){const Z=await F.text().catch(()=>"");throw new Error(Z||`Agent catalog failed (${F.status})`)}return await F.json()},enabled:t,staleTime:2e3,refetchInterval:t?3e3:!1}),{data:i}=wi(t),[o,l]=a.useState(""),[c,h]=a.useState(""),[x,d]=a.useState(""),[u,p]=a.useState(""),[m,j]=a.useState("auto"),[w,E]=a.useState(""),[v,y]=a.useState(null),[A,k]=a.useState(null),[D,O]=a.useState("starter"),[I,ee]=a.useState(!1),[X,le]=a.useState(1),Q=a.useMemo(()=>{const F=c.trim();return F?(i==null?void 0:i.find(Z=>Z.id===F))??null:null},[i,c]),{details:ne}=go({initiativeId:Q?Q.id:null,enabled:t&&!!Q}),te=a.useMemo(()=>bo(ne),[ne]),M=a.useMemo(()=>yo(ne,x||null),[ne,x]),L=((J=r.data)==null?void 0:J.agents)??[],C=a.useMemo(()=>{const F=o.trim();return F?L.find(Z=>Z.id===F)??null:null},[L,o]);a.useEffect(()=>{var Z,ae;if(!t)return;const F=((Z=L.find(xe=>xe.isDefault))==null?void 0:Z.id)??((ae=L[0])==null?void 0:ae.id)??"";!o&&F&&l(F)},[L,t,o]),a.useEffect(()=>{if(!t||c.trim())return;const F=i??[],Z=F.length===1?F[0]:null;Z&&h(Z.id)},[i,t,c]),a.useEffect(()=>{if(!t)return;const F=(C==null?void 0:C.model)??"",Z=F.includes("openrouter")?"openrouter":F.includes("anthropic")?"anthropic":F.includes("openai")?"openai":"auto";j(Z)},[t,C==null?void 0:C.model,o]),a.useEffect(()=>{t&&(y(null),k(null),O("starter"),le(1))},[t]),a.useEffect(()=>{d(""),p("")},[c]),a.useEffect(()=>{p("")},[x]),a.useEffect(()=>{t&&(w.trim().length>0||Q&&E(`Kick off: ${Q.name}`))},[w,t,Q]);const S=!!o.trim()&&!!c.trim(),f=X===1?!!o.trim():X===2?!!c.trim():S,R=async()=>{var Qe;const F=(A==null?void 0:A.checkout)??"/orgx/api/billing/checkout",Z=D&&D.trim().length>0?D.trim():"starter",xe=await(await fetch(F,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({planId:Z,billingCycle:"monthly"})})).json().catch(()=>null),_e=((Qe=xe==null?void 0:xe.data)==null?void 0:Qe.url)??(xe==null?void 0:xe.url)??null;if(!_e)throw new Error((xe==null?void 0:xe.error)??"Checkout unavailable");window.open(_e,"_blank","noopener,noreferrer")},V=async()=>{var _e;const F=(A==null?void 0:A.portal)??"/orgx/api/billing/portal",ae=await(await fetch(F,{method:"POST"})).json().catch(()=>null),xe=((_e=ae==null?void 0:ae.data)==null?void 0:_e.url)??(ae==null?void 0:ae.url)??null;if(!xe)throw new Error((ae==null?void 0:ae.error)??"Billing portal unavailable");window.open(xe,"_blank","noopener,noreferrer")},H=async()=>{if(!(!S||I)){y(null),k(null),ee(!0);try{const F={agentId:o.trim(),message:w.trim()?w.trim():void 0,initiativeId:c.trim(),initiativeTitle:(Q==null?void 0:Q.name)??null,workstreamId:x.trim()?x.trim():null,taskId:u.trim()?u.trim():null,provider:m!=="auto"?m:null},Z=new URLSearchParams;Z.set("agentId",F.agentId),Z.set("initiativeId",F.initiativeId),F.initiativeTitle&&Z.set("initiativeTitle",F.initiativeTitle),F.workstreamId&&Z.set("workstreamId",F.workstreamId),F.taskId&&Z.set("taskId",F.taskId),F.message&&Z.set("message",F.message),F.provider&&Z.set("provider",F.provider);const ae=await fetch(`/orgx/api/agents/launch?${Z.toString()}`,{method:"POST"}),xe=await ae.json().catch(()=>null);if(!ae.ok||!(xe!=null&&xe.ok))throw(xe==null?void 0:xe.code)==="upgrade_required"&&(k(xe.actions??null),O(xe.requiredPlan??"starter")),new Error((xe==null?void 0:xe.error)??`Launch failed (${ae.status})`);n(),s==null||s()}catch(F){y(F instanceof Error?F.message:"Launch failed")}finally{ee(!1)}}},G=!!((Fe=C==null?void 0:C.run)!=null&&Fe.runId)&&!!((he=C==null?void 0:C.run)!=null&&he.pid),Y=async()=>{var F;if(!(!((F=C==null?void 0:C.run)!=null&&F.runId)||!G||I)){y(null),ee(!0);try{const Z=await fetch(`/orgx/api/agents/stop?runId=${encodeURIComponent(C.run.runId)}`,{method:"POST"}),ae=await Z.json().catch(()=>null);if(!Z.ok||!(ae!=null&&ae.ok))throw new Error((ae==null?void 0:ae.error)??`Stop failed (${Z.status})`);await r.refetch()}catch(Z){y(Z instanceof Error?Z.message:"Stop failed")}finally{ee(!1)}}},ie=async()=>{var F;if(!(!((F=C==null?void 0:C.run)!=null&&F.runId)||I)){y(null),ee(!0);try{const Z=new URLSearchParams;Z.set("runId",C.run.runId),w.trim()&&Z.set("message",w.trim()),m&&m!=="auto"&&Z.set("provider",m);const ae=await fetch(`/orgx/api/agents/restart?${Z.toString()}`,{method:"POST"}),xe=await ae.json().catch(()=>null);if(!ae.ok||!(xe!=null&&xe.ok))throw new Error((xe==null?void 0:xe.error)??`Restart failed (${ae.status})`);n(),s==null||s()}catch(Z){y(Z instanceof Error?Z.message:"Restart failed")}finally{ee(!1)}}};return t?e.jsx(kt,{open:t,onClose:n,maxWidth:"max-w-2xl",children:e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[e.jsx("div",{className:"border-b border-subtle px-5 py-4 sm:px-6",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-heading font-semibold text-white",children:"Launch OpenClaw Agent"}),e.jsx("p",{className:"mt-1 text-body text-secondary",children:"Starts a background agent turn and scopes the resulting sessions/activity to the selected OrgX initiative."}),e.jsx("div",{className:"mt-3 inline-flex items-center gap-1 rounded-full border border-strong bg-white/[0.03] p-1 text-micro uppercase tracking-[0.12em] text-secondary",children:[[1,"Agent"],[2,"Scope"],[3,"Message"]].map(([F,Z])=>e.jsxs("button",{type:"button",onClick:()=>le(F),className:de("rounded-full px-3 py-1 transition-colors",X===F?"bg-white/[0.12] text-white":"hover:bg-white/[0.06]"),children:[F,". ",Z]},F))})]}),e.jsx("button",{type:"button",onClick:n,className:"rounded-lg border border-strong bg-white/[0.03] px-3 py-1.5 text-body text-secondary hover:bg-white/[0.08] hover:text-white",children:"Close"})]})}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto px-5 py-4 sm:px-6",children:[r.isLoading&&e.jsx("div",{className:"rounded-xl border border-subtle bg-white/[0.02] p-4 text-body text-secondary",children:"Loading agent catalog…"}),r.error&&e.jsx("div",{className:"rounded-xl border border-rose-300/20 bg-rose-400/10 p-4 text-body text-rose-100",children:r.error.message}),e.jsx(yt,{mode:"wait",children:e.jsxs(we.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:[X===1&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-caption uppercase tracking-[0.1em] text-muted",children:"Agent"}),e.jsx("select",{value:o,onChange:F=>l(F.target.value),className:"mt-1 w-full rounded-xl border border-white/[0.1] bg-black/30 px-3 py-2 text-body text-primary focus:outline-none focus:ring-1 focus:ring-[#BFFF00]/30",children:L.map(F=>{const Z=wn(F.status);return e.jsxs("option",{value:F.id,children:[F.name," (",F.id,") · ",Z.label]},F.id)})})]}),C&&e.jsxs("div",{className:"rounded-xl border border-subtle bg-white/[0.02] p-3 text-body text-secondary",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"font-medium text-primary",children:C.name}),e.jsx("span",{className:"rounded-full border px-2 py-0.5 text-micro uppercase tracking-[0.12em]",style:{borderColor:`${wn(C.status).color}55`,color:wn(C.status).color,backgroundColor:wn(C.status).bg},children:wn(C.status).label})]}),e.jsxs("div",{className:"mt-2 space-y-2",children:[e.jsxs("p",{className:"truncate",children:[e.jsx("span",{className:"text-muted",children:"Model:"})," ",C.model??"unknown"]}),e.jsxs("p",{className:"truncate",children:[e.jsx("span",{className:"text-muted",children:"Workspace:"})," ",C.workspace??"unknown"]}),((fe=C.context)==null?void 0:fe.initiativeId)&&e.jsxs("p",{className:"truncate",children:[e.jsx("span",{className:"text-muted",children:"Scoped:"})," ",C.context.initiativeTitle??C.context.initiativeId]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Provider"}),e.jsxs("select",{value:m,onChange:F=>j(F.target.value),className:"mt-1 w-full rounded-xl border border-white/[0.1] bg-black/30 px-3 py-2 text-body text-primary focus:outline-none focus:ring-1 focus:ring-[#BFFF00]/30",children:[e.jsx("option",{value:"auto",children:"Auto (keep agent model)"}),e.jsx("option",{value:"anthropic",children:"Anthropic"}),e.jsx("option",{value:"openrouter",children:"OpenRouter"}),e.jsx("option",{value:"openai",children:"OpenAI"})]}),e.jsx("p",{className:"mt-1 text-micro text-muted",children:"Selecting a provider updates the agent's default model before launch."})]}),C.run&&e.jsxs("p",{className:"truncate",children:[e.jsx("span",{className:"text-muted",children:"Tracked run:"})," ",C.run.runId.slice(0,8),"…"," ",e.jsxs("span",{className:"text-muted",children:["(",C.run.status,")"]})]}),C.run&&e.jsxs("div",{className:"grid grid-cols-2 gap-2 pt-1",children:[e.jsx("button",{type:"button",onClick:Y,disabled:!G||I,className:"rounded-lg border border-rose-300/25 bg-rose-400/10 px-3 py-2 text-caption font-semibold text-rose-100 transition-colors hover:bg-rose-400/20 disabled:opacity-45",children:"Stop Run"}),e.jsx("button",{type:"button",onClick:ie,disabled:I,className:"rounded-lg border border-strong bg-white/[0.03] px-3 py-2 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:"Restart"})]})]})]})]}),X===2&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-caption uppercase tracking-[0.1em] text-muted",children:"Initiative Scope"}),e.jsxs("select",{value:c,onChange:F=>h(F.target.value),className:"mt-1 w-full rounded-xl border border-white/[0.1] bg-black/30 px-3 py-2 text-body text-primary focus:outline-none focus:ring-1 focus:ring-[#BFFF00]/30",children:[e.jsx("option",{value:"",children:"Select an initiative…"}),(i??[]).map(F=>e.jsx("option",{value:F.id,children:F.name},F.id))]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Workstream (optional)"}),e.jsxs("select",{value:x,onChange:F=>d(F.target.value),disabled:!Q,className:de("mt-1 w-full rounded-xl border border-white/[0.1] bg-black/30 px-3 py-2 text-body text-primary focus:outline-none focus:ring-1 focus:ring-[#BFFF00]/30",!Q&&"opacity-50"),children:[e.jsx("option",{value:"",children:"Any workstream"}),te.map(F=>e.jsx("option",{value:F.id,children:F.name},F.id))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Task (optional)"}),e.jsxs("select",{value:u,onChange:F=>p(F.target.value),disabled:!Q,className:de("mt-1 w-full rounded-xl border border-white/[0.1] bg-black/30 px-3 py-2 text-body text-primary focus:outline-none focus:ring-1 focus:ring-[#BFFF00]/30",!Q&&"opacity-50"),children:[e.jsx("option",{value:"",children:"Any task"}),M.slice(0,80).map(F=>e.jsx("option",{value:F.id,children:F.title},F.id))]}),M.length>80&&e.jsx("p",{className:"mt-1 text-micro text-muted",children:"Showing first 80 tasks to keep the menu usable."})]})]})]}),X===3&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-caption uppercase tracking-[0.1em] text-muted",children:"Kickoff Message"}),e.jsx("textarea",{value:w,onChange:F=>E(F.target.value),rows:4,className:"mt-1 w-full resize-none rounded-xl border border-white/[0.1] bg-black/30 px-3 py-2 text-body text-primary focus:outline-none focus:ring-1 focus:ring-[#BFFF00]/30",placeholder:"Optional. If left blank, a default kickoff message is used."})]}),e.jsxs("div",{className:"rounded-xl border border-subtle bg-white/[0.02] p-3 text-body text-secondary",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Review"}),e.jsxs("div",{className:"mt-2 grid grid-cols-1 gap-2 sm:grid-cols-2",children:[e.jsxs("div",{className:"rounded-lg border border-white/[0.08] bg-black/20 px-3 py-2",children:[e.jsx("div",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Agent"}),e.jsx("div",{className:"mt-0.5 truncate text-body text-primary",children:((C==null?void 0:C.name)??o.trim())||"—"})]}),e.jsxs("div",{className:"rounded-lg border border-white/[0.08] bg-black/20 px-3 py-2",children:[e.jsx("div",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Initiative"}),e.jsx("div",{className:"mt-0.5 truncate text-body text-primary",children:((Q==null?void 0:Q.name)??c.trim())||"—"})]}),e.jsxs("div",{className:"rounded-lg border border-white/[0.08] bg-black/20 px-3 py-2",children:[e.jsx("div",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Workstream"}),e.jsx("div",{className:"mt-0.5 truncate text-body text-primary",children:x.trim()?((et=te.find(F=>F.id===x))==null?void 0:et.name)??x:"Any"})]}),e.jsxs("div",{className:"rounded-lg border border-white/[0.08] bg-black/20 px-3 py-2",children:[e.jsx("div",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Task"}),e.jsx("div",{className:"mt-0.5 truncate text-body text-primary",children:u.trim()?((W=M.find(F=>F.id===u))==null?void 0:W.title)??u:"Any"})]})]})]})]})]},X)}),v&&e.jsx("div",{className:"mt-3 rounded-xl border border-rose-300/20 bg-rose-400/10 px-3 py-2 text-body text-rose-100",children:e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("div",{children:v}),A&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>void R().catch(F=>y(F instanceof Error?F.message:"Checkout failed")),className:"rounded-full border border-amber-200/25 bg-amber-200/10 px-3 py-1.5 text-caption font-semibold text-amber-100 transition-colors hover:bg-amber-200/15",children:"Upgrade"}),e.jsx("button",{type:"button",onClick:()=>void V().catch(F=>y(F instanceof Error?F.message:"Portal failed")),className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.08]",children:"Billing portal"}),A.pricing&&e.jsx("a",{href:A.pricing,target:"_blank",rel:"noopener noreferrer",className:"text-caption text-secondary underline decoration-white/20 hover:text-primary",children:"View pricing"})]})]})})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 border-t border-subtle px-5 py-3.5 sm:px-6",children:[e.jsx("div",{className:"text-caption text-secondary",children:X===1?"Pick an agent to configure.":X===2?"Select an initiative scope (required).":S?"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:[X>1&&e.jsx("button",{type:"button",onClick:()=>le(F=>F>1?F-1:F),disabled:I,className:"rounded-xl border border-strong bg-white/[0.03] px-4 py-2 text-body font-semibold text-primary transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:"Back"}),X<3?e.jsx("button",{type:"button",onClick:()=>le(F=>F<3?F+1:F),disabled:!f||I,className:de("rounded-xl px-4 py-2 text-body font-semibold transition-colors",f&&!I?"text-black":"cursor-not-allowed border border-strong bg-white/[0.05] text-muted"),style:f&&!I?{backgroundColor:N.lime}:void 0,children:"Next"}):e.jsx("button",{type:"button",onClick:H,disabled:!S||I,className:de("rounded-xl px-4 py-2 text-body font-semibold transition-colors",S&&!I?"text-black":"cursor-not-allowed border border-strong bg-white/[0.05] text-muted"),style:S&&!I?{backgroundColor:N.lime}:void 0,children:I?"Launching…":"Launch"})]})]})]})}):null}const Ns=10,vo=20;function jo(t){const n=(t??"").toLowerCase();return n==="active"?{label:"Active",color:N.lime,bg:"rgba(191,255,0,0.12)"}:n==="blocked"?{label:"Blocked",color:"#fb7185",bg:"rgba(244, 63, 94, 0.12)"}:n==="idle"?{label:"Idle",color:"rgba(255,255,255,0.55)",bg:"rgba(255,255,255,0.06)"}:{label:t||"Unknown",color:N.iris,bg:"rgba(124,124,255,0.10)"}}function ko(t){return t?t.includes("error")||t.includes("fail")?N.red:t.includes("decision")||t.includes("block")?N.amber:t.includes("complete")||t.includes("success")?N.teal:t.includes("start")||t.includes("launch")?N.lime:N.iris:N.iris}function No({open:t,onClose:n,agentName:s,catalogAgent:r,sessions:i,activity:o,onSelectSession:l,onRefresh:c}){var ee,X,le,Q,ne,te;const[h,x]=a.useState(!1),[d,u]=a.useState(!1),[p,m]=a.useState(null),j=pi(s),w=jo((r==null?void 0:r.status)??null),E=a.useMemo(()=>{let M=0,L=0,C=0,S=0;for(const f of i)f.status==="running"||f.status==="queued"||f.status==="pending"?M++:f.status==="blocked"?L++:f.status==="failed"||f.status==="cancelled"?C++:(f.status==="completed"||f.status==="archived")&&S++;return{running:M,blocked:L,failed:C,completed:S}},[i]),v=a.useMemo(()=>[...i].sort((M,L)=>Date.parse(L.updatedAt??L.lastEventAt??L.startedAt??"")-Date.parse(M.updatedAt??M.lastEventAt??M.startedAt??"")),[i]),y=h?v:v.slice(0,Ns),A=v.length>Ns,k=a.useMemo(()=>[...o].sort((M,L)=>Date.parse(L.timestamp)-Date.parse(M.timestamp)).slice(0,vo),[o]),D=!!((ee=r==null?void 0:r.run)!=null&&ee.runId)&&!!((X=r==null?void 0:r.run)!=null&&X.pid),O=async()=>{var M;if(!(!((M=r==null?void 0:r.run)!=null&&M.runId)||!D||d)){m(null),u(!0);try{const L=await fetch(`/orgx/api/agents/stop?runId=${encodeURIComponent(r.run.runId)}`,{method:"POST"}),C=await L.json().catch(()=>null);if(!L.ok||!(C!=null&&C.ok))throw new Error((C==null?void 0:C.error)??`Stop failed (${L.status})`);c==null||c()}catch(L){m(L instanceof Error?L.message:"Stop failed")}finally{u(!1)}}},I=async()=>{var M;if(!(!((M=r==null?void 0:r.run)!=null&&M.runId)||d)){m(null),u(!0);try{const L=new URLSearchParams;L.set("runId",r.run.runId);const C=await fetch(`/orgx/api/agents/restart?${L.toString()}`,{method:"POST"}),S=await C.json().catch(()=>null);if(!C.ok||!(S!=null&&S.ok))throw new Error((S==null?void 0:S.error)??`Restart failed (${C.status})`);c==null||c()}catch(L){m(L instanceof Error?L.message:"Restart failed")}finally{u(!1)}}};return t?e.jsx(kt,{open:t,onClose:n,maxWidth:"max-w-3xl",children:e.jsxs("div",{className:"flex h-full min-h-0 w-full flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-subtle px-5 py-3 sm:px-6",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0 text-body text-secondary",children:[e.jsx("span",{children:"Agents"}),e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:"flex-shrink-0 text-faint",children:e.jsx("path",{d:"m9 18 6-6-6-6"})}),e.jsx("span",{className:"truncate text-primary font-medium",children:s}),e.jsx("span",{className:"ml-1 rounded-full border border-white/[0.1] bg-white/[0.04] px-2 py-0.5 text-micro uppercase tracking-[0.06em] text-muted",children:"agent"})]}),e.jsx("button",{type:"button",onClick:n,"aria-label":"Close detail",className:"inline-flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-full border border-strong bg-white/[0.03] text-primary transition-colors hover:bg-white/[0.08] hover:text-white",children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 6L6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})})]}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto px-5 py-4 sm:px-6 space-y-5",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(dt,{name:s,size:"md",hint:s}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"text-heading font-semibold text-white truncate",children:s}),e.jsx("span",{className:"rounded-full border px-2 py-0.5 text-micro uppercase tracking-[0.12em]",style:{borderColor:`${w.color}55`,color:w.color,backgroundColor:w.bg},children:w.label})]}),j&&e.jsx("p",{className:"text-body text-secondary mt-0.5",children:j}),r&&e.jsxs("div",{className:"flex flex-wrap items-center gap-3 mt-1 text-caption text-muted",children:[r.model&&e.jsxs("span",{children:[e.jsx("span",{className:"text-muted",children:"Model:"})," ",r.model]}),r.workspace&&e.jsxs("span",{children:[e.jsx("span",{className:"text-muted",children:"Workspace:"})," ",r.workspace]})]})]})]}),e.jsx("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-4",children:[{label:"Running",value:E.running,color:N.lime},{label:"Blocked",value:E.blocked,color:N.red},{label:"Failed",value:E.failed,color:N.amber},{label:"Completed",value:E.completed,color:N.teal}].map(M=>e.jsxs("div",{className:"rounded-xl border border-subtle bg-white/[0.02] px-3 py-2.5",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.1em] text-muted",children:M.label}),e.jsx("p",{className:"mt-0.5 text-title font-semibold",style:{color:M.value>0?M.color:"rgba(255,255,255,0.3)",fontVariantNumeric:"tabular-nums"},children:M.value})]},M.label))}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-micro uppercase tracking-[0.1em] text-muted mb-2",children:["Sessions (",i.length,")"]}),i.length===0?e.jsx("div",{className:"rounded-xl border border-subtle bg-white/[0.02] px-3 py-4 text-center text-body text-muted",children:"No sessions recorded for this agent."}):e.jsxs("div",{className:"space-y-1.5",children:[y.map(M=>e.jsxs("button",{onClick:()=>{l(M.id),n()},className:"w-full rounded-lg border border-subtle bg-white/[0.02] px-3 py-2 text-left transition-colors hover:bg-white/[0.05]",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"h-2 w-2 flex-shrink-0 rounded-full",style:{backgroundColor:on(M.status)}}),e.jsx("p",{className:"min-w-0 flex-1 truncate text-body text-primary",children:M.title}),e.jsx("span",{className:"text-micro text-muted",style:{fontVariantNumeric:"tabular-nums"},title:Yt(M.updatedAt??M.lastEventAt??M.startedAt??Date.now()),children:Ge(M.updatedAt??M.lastEventAt??M.startedAt??Date.now())})]}),e.jsxs("div",{className:"mt-1 flex items-center gap-2 text-micro text-muted",children:[e.jsx("span",{className:"uppercase tracking-[0.08em]",children:M.status}),M.progress!==null&&e.jsxs("span",{children:[Math.round(M.progress),"%"]})]})]},M.id)),A&&e.jsx("button",{type:"button",onClick:()=>x(M=>!M),className:"w-full rounded-lg border border-white/[0.08] bg-white/[0.02] px-3 py-1.5 text-micro text-secondary transition-colors hover:bg-white/[0.05]",children:h?"Show fewer":`Show ${v.length-Ns} more`})]})]}),k.length>0&&e.jsxs("div",{children:[e.jsxs("p",{className:"text-micro uppercase tracking-[0.1em] text-muted mb-2",children:["Recent Activity (",k.length,")"]}),e.jsx("div",{className:"space-y-1",children:k.map((M,L)=>e.jsxs("div",{className:"flex items-start gap-2 rounded-lg px-2 py-1.5 text-caption",children:[e.jsx("span",{className:"mt-1.5 h-1.5 w-1.5 flex-shrink-0 rounded-full",style:{backgroundColor:ko(M.type)}}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx("p",{className:"truncate text-primary",children:M.title??M.summary??M.description??"Activity"})}),e.jsx("span",{className:"flex-shrink-0 text-micro text-muted",style:{fontVariantNumeric:"tabular-nums"},title:Yt(M.timestamp),children:Ge(M.timestamp)})]},M.id??L))})]}),(r==null?void 0:r.run)&&e.jsxs("div",{children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.1em] text-muted mb-2",children:"Controls"}),e.jsxs("div",{className:"rounded-xl border border-subtle bg-white/[0.02] p-3",children:[e.jsxs("p",{className:"text-caption text-secondary mb-2",children:[e.jsx("span",{className:"text-muted",children:"Tracked run:"})," ",r.run.runId.slice(0,8),"…"," ",e.jsxs("span",{className:"text-muted",children:["(",r.run.status,")"]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("button",{type:"button",onClick:O,disabled:!D||d,className:"rounded-lg border border-rose-300/25 bg-rose-400/10 px-3 py-2 text-caption font-semibold text-rose-100 transition-colors hover:bg-rose-400/20 disabled:opacity-45",children:d?"Stopping…":"Stop Run"}),e.jsx("button",{type:"button",onClick:I,disabled:d,className:"rounded-lg border border-strong bg-white/[0.03] px-3 py-2 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:d?"Restarting…":"Restart"})]}),p&&e.jsx("p",{className:"mt-2 text-caption text-rose-200",children:p})]})]}),r&&e.jsxs("div",{children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.1em] text-muted mb-2",children:"Settings"}),e.jsxs("div",{className:"rounded-xl border border-subtle bg-white/[0.02] p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between text-body",children:[e.jsx("span",{className:"text-muted",children:"Provider"}),e.jsx("span",{className:"text-primary",children:(le=r.model)!=null&&le.includes("openrouter")?"OpenRouter":(Q=r.model)!=null&&Q.includes("anthropic")?"Anthropic":(ne=r.model)!=null&&ne.includes("openai")?"OpenAI":"Auto"})]}),e.jsxs("div",{className:"flex items-center justify-between text-body",children:[e.jsx("span",{className:"text-muted",children:"Model"}),e.jsx("span",{className:de("truncate max-w-[200px] text-right",r.model?"text-primary":"text-muted"),children:r.model??"Not configured"})]}),r.workspace&&e.jsxs("div",{className:"flex items-center justify-between text-body",children:[e.jsx("span",{className:"text-muted",children:"Workspace"}),e.jsx("span",{className:"truncate max-w-[200px] text-right text-primary",children:r.workspace})]}),((te=r.context)==null?void 0:te.initiativeTitle)&&e.jsxs("div",{className:"flex items-center justify-between text-body",children:[e.jsx("span",{className:"text-muted",children:"Initiative"}),e.jsx("span",{className:"truncate max-w-[200px] text-right text-primary",children:r.context.initiativeTitle})]})]})]})]})]})}):null}function So({enabled:t=!0}={}){return Et({queryKey:["openclaw-agent-catalog"],queryFn:async()=>{const n=await fetch("/orgx/api/agents/catalog");if(!n.ok){const s=await n.text().catch(()=>"");throw new Error(s||`Agent catalog failed (${n.status})`)}return await n.json()},enabled:t,staleTime:5e3,refetchInterval:t?8e3:!1})}const Rn=120,Mr=10,Co=24,Er=520,Ao=58,Io=56,_o=20,Mo=8,Xs=new Set(["running","active","in_progress","working","planning","handoff","review"]),Eo=new Set(["blocked","failed"]),Fo=10,$o=[{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"}],To=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,Us=[{id:"eli",name:"Eli",role:"Engineering",aliases:[/\beli\b/i,/\borgx[\s_-]*engineering\b/i,/^\s*engineering\s*$/i]},{id:"dana",name:"Dana",role:"Product Design",aliases:[/\bdana\b/i,/\borgx[\s_-]*design\b/i,/\borgx[\s_-]*product\b/i,/\bproduct[\s_-]*design\b/i]},{id:"mark",name:"Mark",role:"Marketing",aliases:[/\bmark\b/i,/\borgx[\s_-]*marketing\b/i,/^\s*marketing\s*$/i]},{id:"sage",name:"Sage",role:"Sales",aliases:[/\bsage\b/i,/\borgx[\s_-]*sales\b/i,/^\s*sales\s*$/i]},{id:"orion",name:"Orion",role:"Operations",aliases:[/\borion\b/i,/\borgx[\s_-]*operations\b/i,/^\s*operations\s*$/i]},{id:"xandy",name:"Xandy",role:"Orchestrator",aliases:[/\bxandy\b/i,/\borgx[\s_-]*orchestrator\b/i,/^\s*orchestrator\s*$/i]},{id:"pace",name:"Pace",role:"Engineering",aliases:[/\bpace\b/i,/\borgx[\s_-]*pace\b/i]}];function Ie(t){const n=t==null?void 0:t.trim().toLowerCase();return n&&n.length>0?n:null}function It(t,n){const s=Ie(t),r=Ie(n);if(!s&&!r)return null;const i=[s,r].filter(Boolean).join(" ");if(!i)return null;for(const o of Us)if(o.aliases.some(l=>l.test(i)))return{agentId:`orgx:${o.id}`,agentName:o.name,role:o.role};return null}function Lo(t){const n=It(t.agentId,t.agentName);if(n)return n;const s=[t.groupLabel,t.title,t.runtimeLabel,t.lastEventSummary];for(const r of s){const i=It(null,r);if(i)return i}return null}function Po(t){const n=Ie(t.runtimeClient);if(n==="codex")return"codex";if(n==="claude-code")return"claude-code";if(n==="openclaw")return"openclaw";if(n==="api")return"api";const s=[t.title,t.lastEventSummary,t.runtimeLabel,t.runtimeProvider,t.groupLabel].filter(r=>typeof r=="string"&&r.trim().length>0).join(" ").toLowerCase();return s.includes("claude-code")||s.includes("anthropic")||s.includes("claude")?"claude-code":s.includes("openclaw")?"openclaw":s.includes("codex")||s.includes("openai")?"codex":s.includes("orgx api")||s.includes("source_client=api")?"api":null}function vi(t){const n=Lo(t);if(n)return{agentId:n.agentId,agentName:n.agentName};const s=Ie(t.agentId),r=Ie(t.agentName);if(s||r)return{agentId:t.agentId??null,agentName:t.agentName??null};const i=Po(t);return i==="codex"?{agentId:"runtime:codex",agentName:"Codex"}:i==="claude-code"?{agentId:"runtime:claude-code",agentName:"Claude Code"}:i==="openclaw"?{agentId:"runtime:openclaw",agentName:"OpenClaw"}:i==="api"?{agentId:"runtime:api",agentName:"OrgX API"}:{agentId:null,agentName:null}}function Do(t){const n=vi(t),s=Ie(n.agentId);if(s)return`id:${s}`;const r=Ie(n.agentName);return r?`name:${r}`:"unassigned"}function Bo(t){const n=t.trim();return n?To.test(n)?`${n.slice(0,8)}…${n.slice(-4)}`:!n.includes(" ")&&n.length>36?`${n.slice(0,24)}…`:n:"Unassigned"}function es(t){const n=(t??"").trim();return n?yi(n):!1}function Ro(t){var n,s;return!!(es((n=t.context)==null?void 0:n.initiativeId)||es(((s=t.run)==null?void 0:s.initiativeId)??null))}function Ss(t){if(It(t.agentId,t.agentName))return!0;const s=Ie(t.agentId);return!!(s!=null&&s.startsWith("orgx"))}function Ot(t){const n=Ie(t.status)??"archived";if(n==="blocked"||n==="failed"||n==="completed"||n==="cancelled")return n;const s=Ie(t.phase);if(s==="blocked")return"blocked";if(s==="handoff")return"handoff";if(s==="completed")return"completed";if(s==="review")return"review";const r=Ie(t.state);return r==="error"?"failed":r==="stopped"?"paused":r==="stale"?"queued":Xs.has(n)?n:Array.isArray(t.blockers)&&t.blockers.length>0?"blocked":n}function Ws(t){const n=Ie(t);return n?Xs.has(n)||Eo.has(n):!1}function Fr(t){const n=Ie(t);return n?Xs.has(n):!1}function On(t){return t?!!(Ws(t.status)||t.runId&&t.runId.trim().length>0||t.currentTask&&t.currentTask.trim().length>0):!1}function Oo(t){return t?t.state==="active":!1}function qo(t){return t==="codex"?"codex":t==="openai"?"openai":t==="anthropic"?"anthropic":t==="openclaw"?"openclaw":t==="orgx"?"orgx":"unknown"}function Mt(t){if(!t)return 0;const n=Date.parse(t);return Number.isFinite(n)?n:0}function Cs(t,n){return Mt(n.updatedAt??n.lastEventAt??n.startedAt)-Mt(t.updatedAt??t.lastEventAt??t.startedAt)}const zo=a.memo(function({sessions:n,activity:s,selectedSessionId:r,onSelectSession:i,timeFilterId:o,onAgentFilter:l,agentFilter:c,onReconnect:h,connectionStatus:x,runtimeInstances:d=[],showSyntheticEntities:u=!1}){var Nt;const[p,m]=a.useState(new Set),[j,w]=a.useState(!1),[E,v]=a.useState(!1),[y,A]=a.useState(0),[k,D]=a.useState(null),O=So({enabled:!0}),I=((Nt=O.data)==null?void 0:Nt.agents)??[],ee=a.useMemo(()=>Gs(o),[o]),X=a.useMemo(()=>ee===null?s:s.filter(q=>Mt(q.timestamp)>=ee),[s,ee]);a.useMemo(()=>{var ue,je,Re;const q=new Map,ve=[...X].sort((qe,ge)=>Mt(ge.timestamp)-Mt(qe.timestamp));for(const qe of ve){const ge=qe.runId;if(!ge||q.has(ge))continue;const Xe=((ue=qe.summary)==null?void 0:ue.trim())??((je=qe.description)==null?void 0:je.trim())??((Re=qe.title)==null?void 0:Re.trim())??"";Xe.length>0&&q.set(ge,Xe)}return q},[X]);const{agents:le,hiddenGroupCount:Q,filteredOutGroupsByDate:ne,filteredOutSessionsByDate:te,visibleSessionCount:M,archivedGroups:L,sessionCountInScope:C}=a.useMemo(()=>{var St;const q=u?n.nodes:n.nodes.filter(z=>!es(z.initiativeId)),ve=u?I:I.filter(z=>!Ro(z)),ue=u?d:d.filter(z=>!es(z.initiativeId)),je=new Map,Re=new Map,qe=[...ue].sort((z,ce)=>Mt(ce.lastEventAt??ce.lastHeartbeatAt)-Mt(z.lastEventAt??z.lastHeartbeatAt));for(const z of qe){z.runId&&!je.has(z.runId)&&je.set(z.runId,z);const ce=It(z.agentId,z.agentName??z.displayName),ke=Ie((ce==null?void 0:ce.agentId)??z.agentId);if(ke){const ye=Re.get(ke)??[];ye.push(z),Re.set(ke,ye)}}const ge=new Map;for(const z of q){const ce=vi(z),ke=Do(z),ye=Ie(ce.agentId),se=Ie(ce.agentName);let oe=ge.get(ke)??null;if(!oe&&ye&&se){const pe=`name:${se}`,Ce=ge.get(pe);Ce&&(ge.delete(pe),Ce.groupKey=ke,ge.set(ke,Ce),oe=Ce)}if(!oe&&se){const pe=Array.from(ge.values()).find(Ce=>Ie(Ce.agentName)===se);pe&&(oe=pe)}oe?(oe.nodes.push(z),!oe.agentId&&ce.agentId&&(oe.agentId=ce.agentId),(oe.agentName==="Unassigned"||!oe.agentName)&&ce.agentName&&(oe.agentName=ce.agentName)):ge.set(ke,{groupKey:ke,agentId:ce.agentId,agentName:ce.agentName??ce.agentId??"Unassigned",nodes:[z],latest:z,runtime:null,runtimeActiveCount:0})}for(const z of ve){const ce=It(z.id,z.name),ke=(ce==null?void 0:ce.agentId)??z.id,ye=(ce==null?void 0:ce.agentName)??z.name,se=Ie(ke),oe=Ie(ye),pe=se?`id:${se}`:null,Ce=oe?`name:${oe}`:null;let Te=null;if(pe&&ge.has(pe))Te=pe;else if(Ce&&ge.has(Ce))Te=Ce;else{const Be=Array.from(ge.entries()).find(([,lt])=>se&&Ie(lt.agentId)===se||oe&&Ie(lt.agentName)===oe);Te=(Be==null?void 0:Be[0])??null}if(Te){const Be=ge.get(Te);Be.catalogAgent=z,!Be.agentId&&ke&&(Be.agentId=ke),(Be.agentName==="Unassigned"||!Be.agentName)&&ye&&(Be.agentName=ye),pe&&Be.groupKey!==pe&&!ge.has(pe)&&(ge.delete(Be.groupKey),Be.groupKey=pe,ge.set(pe,Be))}else{const Be=pe??Ce??`catalog:${ye.toLowerCase()}`;ge.set(Be,{groupKey:Be,agentId:ke,agentName:ye,nodes:[],latest:null,catalogAgent:z,runtime:null,runtimeActiveCount:0})}}for(const z of Us){const ce=`orgx:${z.id}`,ke=`id:${ce}`;let ye=ge.get(ke)??null;if(!ye){const se=Array.from(ge.entries()).find(([,oe])=>{const pe=It(oe.agentId,oe.agentName);return Ie(pe==null?void 0:pe.agentId)===Ie(ce)});se&&(ge.delete(se[0]),ye=se[1],ye.groupKey=ke,ge.set(ke,ye))}if(ye||(ye={groupKey:ke,agentId:ce,agentName:z.name,nodes:[],latest:null,runtime:null,runtimeActiveCount:0},ge.set(ke,ye)),ye.agentId=ce,ye.agentName=z.name,!ye.catalogAgent){const se=ve.find(oe=>{const pe=It(oe.id,oe.name);return Ie(pe==null?void 0:pe.agentId)===Ie(ce)});se&&(ye.catalogAgent=se)}}const Xe=new Map(Us.map((z,ce)=>[Ie(`orgx:${z.id}`),ce]));for(const z of ge.values()){z.nodes.length>0&&(z.nodes.sort(Cs),z.latest=z.nodes[0]);const ce=[],ke=new Set;if((St=z.latest)!=null&&St.runId){const se=je.get(z.latest.runId);se&&!ke.has(se.id)&&(ce.push(se),ke.add(se.id))}for(const se of z.nodes){if(!se.runId)continue;const oe=je.get(se.runId);oe&&!ke.has(oe.id)&&(ce.push(oe),ke.add(oe.id))}const ye=Ie(z.agentId);if(ye)for(const se of Re.get(ye)??[])ke.has(se.id)||(ce.push(se),ke.add(se.id));ce.sort((se,oe)=>Mt(oe.lastEventAt??oe.lastHeartbeatAt)-Mt(se.lastEventAt??se.lastHeartbeatAt)),z.runtime=ce[0]??null,z.runtimeActiveCount=ce.filter(se=>Oo(se)).length}const nt=Array.from(ge.values()).sort((z,ce)=>{const ke=Ss(z),ye=Ss(ce);if(ke!==ye)return ke?-1:1;if(ke&&ye){const se=It(z.agentId,z.agentName),oe=It(ce.agentId,ce.agentName),pe=Xe.get(Ie((se==null?void 0:se.agentId)??z.agentId))??999,Ce=Xe.get(Ie((oe==null?void 0:oe.agentId)??ce.agentId))??999;if(pe!==Ce)return pe-Ce}return z.latest&&ce.latest?Cs(z.latest,ce.latest):z.latest&&!ce.latest?-1:!z.latest&&ce.latest?1:z.agentName.localeCompare(ce.agentName)}),Ve=ui(o),tt=Ve.id==="live",ze=Ve.minutes===null||tt?null:Date.now()-Ve.minutes*6e4,Ue=[],st=[];let ot=0,pt=0;for(const z of nt){const ce=(z.runtimeActiveCount??0)>0,ke=Ss(z);if(z.nodes.length===0){const pe=On(z.catalogAgent);(ke||tt&&(pe||ce))&&Ue.push(z);continue}if(tt){const pe=z.nodes.filter(Be=>Ws(Ot(Be))),Ce=z.nodes.filter(Be=>!Ws(Ot(Be))),Te=On(z.catalogAgent);if(pe.length===0){ke||Te||ce?Ue.push({...z,nodes:[],latest:null}):(ot+=1,pt+=z.nodes.length,st.push(z));continue}pt+=Ce.length,Ce.length>0&&st.push({...z,nodes:Ce,latest:Ce[0]??null}),Ue.push({...z,nodes:pe,latest:pe[0]??null});continue}if(ze===null){Ue.push(z);continue}const ye=z.nodes.filter(pe=>Fr(Ot(pe))?!0:Mt(pe.updatedAt??pe.lastEventAt??pe.startedAt)>=ze),se=On(z.catalogAgent);if(ye.length===0){ke||se||ce?Ue.push({...z,nodes:[],latest:null}):(ot+=1,pt+=z.nodes.length,st.push(z));continue}const oe=z.nodes.filter(pe=>Fr(Ot(pe))?!1:Mt(pe.updatedAt??pe.lastEventAt??pe.startedAt)<ze);pt+=oe.length,oe.length>0&&st.push({...z,nodes:oe,latest:oe[0]}),Ue.push({...z,nodes:ye,latest:ye[0]})}return{agents:Ue.slice(0,Rn),hiddenGroupCount:Math.max(0,Ue.length-Rn),filteredOutGroupsByDate:ot,filteredOutSessionsByDate:pt,visibleSessionCount:Ue.slice(0,Rn).reduce((z,ce)=>z+ce.nodes.length,0),archivedGroups:st,sessionCountInScope:q.length}},[o,n.nodes,I,d,u]);a.useEffect(()=>{v(!1),A(0)},[o]);const S=a.useMemo(()=>L.reduce((q,ve)=>q+ve.nodes.length,0),[L]),f=a.useMemo(()=>le.filter(q=>q.nodes.length>0).map(q=>q.groupKey),[le]),R=a.useMemo(()=>{if(f.length===0)return{allCollapsed:!1,allExpanded:!0};let q=0;for(const ve of f)p.has(ve)&&(q+=1);return{allCollapsed:q===f.length,allExpanded:q===0}},[p,f]),V=a.useMemo(()=>{const q=[];for(const ve of L)for(const ue of ve.nodes)q.push({node:ue,agentName:ve.agentName});return q.sort((ve,ue)=>Cs(ve.node,ue.node)),q.slice(0,(y+1)*Fo)},[L,y]),H=q=>{m(ve=>{const ue=new Set(ve);return ue.has(q)?ue.delete(q):ue.add(q),ue})},G=()=>{m(()=>R.allCollapsed?new Set:new Set(f))},Y=a.useMemo(()=>k?le.find(q=>q.groupKey===k)??null:null,[le,k]),ie=a.useMemo(()=>(Y==null?void 0:Y.nodes)??[],[Y]),J=a.useMemo(()=>{if(!Y)return[];const q=Ie(Y.agentName),ve=Ie(Y.agentId),ue=It(Y.agentId,Y.agentName);return X.filter(je=>{const Re=Ie(je.agentName),qe=Ie(je.agentId),ge=It(je.agentId,je.agentName);return q!==null&&Re===q||ve!==null&&qe===ve||ue!==null&&ge!==null&&Ie(ue.agentId)===Ie(ge.agentId)})},[X,Y]),Fe=C===0,he=I.length>0,fe=a.useRef(null),[et,W]=a.useState(0),[F,Z]=a.useState(0),ae=a.useCallback(q=>{const ve=q.currentTarget.scrollTop;W(ue=>Math.abs(ue-ve)<1?ue:ve)},[]);a.useEffect(()=>{const q=fe.current;if(!q)return;const ve=()=>{const ue=q.clientHeight,je=q.scrollTop;Z(Re=>Re===ue?Re:ue),W(Re=>Math.abs(Re-je)<1?Re:je)};if(ve(),typeof ResizeObserver<"u"){const ue=new ResizeObserver(()=>ve());return ue.observe(q),()=>ue.disconnect()}return window.addEventListener("resize",ve),()=>window.removeEventListener("resize",ve)},[le.length]);const{visibleAgentGroups:xe,topVirtualSpacerPx:_e,bottomVirtualSpacerPx:Qe,virtualizationEnabled:mt}=a.useMemo(()=>{if(!(le.length>Co&&F>0))return{visibleAgentGroups:le,topVirtualSpacerPx:0,bottomVirtualSpacerPx:0,virtualizationEnabled:!1};const ve=le.map(nt=>{const tt=p.has(nt.groupKey)?0:Math.min(nt.nodes.length,Mr);let ze=Ao;return tt>0&&(ze+=_o+tt*Io,nt.nodes.length>tt&&(ze+=20)),ze+Mo}),ue=new Array(ve.length+1).fill(0);for(let nt=0;nt<ve.length;nt+=1)ue[nt+1]=ue[nt]+ve[nt];const je=ue[ue.length-1],Re=Math.max(0,et-Er),qe=et+F+Er;let ge=0;for(;ge<le.length&&ue[ge+1]<Re;)ge+=1;let Xe=ge;for(;Xe<le.length&&ue[Xe]<qe;)Xe+=1;return Xe<=ge&&(Xe=Math.min(le.length,ge+1)),{visibleAgentGroups:le.slice(ge,Xe),topVirtualSpacerPx:ue[ge],bottomVirtualSpacerPx:Math.max(0,je-ue[Xe]),virtualizationEnabled:!0}},[le,p,et,F]);return e.jsxs(Jt,{className:"flex h-full min-h-0 flex-col card-enter",children:[e.jsx(wo,{open:j,onClose:()=>w(!1),onLaunched:()=>h==null?void 0:h()}),e.jsx(No,{open:k!==null,onClose:()=>D(null),agentName:(Y==null?void 0:Y.agentName)??"",catalogAgent:(Y==null?void 0:Y.catalogAgent)??null,sessions:ie,activity:J,onSelectSession:i,onRefresh:()=>O.refetch()}),e.jsx("div",{className:"border-b border-subtle px-4 py-3.5",children:e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("h2",{className:"min-w-0 truncate text-heading font-semibold text-white",children:"Agents"}),e.jsxs("span",{className:"chip flex-shrink-0 text-caption tabular-nums",children:[M,"/",C]})]}),e.jsxs("div",{className:"flex flex-shrink-0 items-center gap-2",children:[e.jsx("button",{type:"button",onClick:G,disabled:f.length===0,className:"control-pill hidden flex-shrink-0 px-3 text-caption font-semibold sm:inline-flex",title:R.allCollapsed?"Expand all agent groups":"Collapse all agent groups",children:R.allCollapsed?"Expand":"Collapse"}),e.jsx("button",{type:"button",onClick:()=>w(!0),className:"control-pill flex-shrink-0 px-3 text-caption font-semibold",children:"Launch"})]})]})}),e.jsxs("div",{ref:fe,onScroll:ae,className:"flex-1 space-y-2 overflow-y-auto p-3",children:[le.length===0&&!Fe&&e.jsxs("div",{className:"flex flex-col items-center gap-2.5 rounded-xl border border-subtle bg-white/[0.02] px-3 py-6 text-center",children:[e.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-faint",children:e.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})}),e.jsx("p",{className:"text-body text-secondary",children:"No sessions match the selected activity window."})]}),le.length===0&&Fe&&!h&&e.jsxs("div",{className:"flex flex-col items-center gap-2.5 rounded-xl border border-subtle bg-white/[0.02] px-3 py-6 text-center",children:[e.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-faint",children:e.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})}),e.jsx("p",{className:"text-body text-secondary",children:"No active chats yet. Start a session to see agents here."})]}),c&&l&&e.jsxs("div",{className:"flex items-center justify-between rounded-lg bg-[#0AD4C4]/[0.08] px-3 py-1.5 text-caption text-[#0AD4C4]",children:[e.jsxs("span",{children:["Filtered: ",c]}),e.jsx("button",{type:"button",onClick:()=>l(null),className:"text-micro underline underline-offset-2",children:"Clear"})]}),e.jsxs("div",{className:"space-y-2",children:[mt&&_e>0&&e.jsx("div",{"aria-hidden":"true",style:{height:_e}}),xe.map(q=>{var ye;const ve=q.groupKey,ue=p.has(ve),je=q.latest,Re=je?Ot(je):null,qe=q.nodes.length>0,ge=On(q.catalogAgent),Xe=q.runtime??null,nt=(q.runtimeActiveCount??0)>0,Ve=je?r===je.id:!1,tt=q.agentName||((ye=q.catalogAgent)==null?void 0:ye.name)||q.agentId||"Unassigned",ze=It(q.agentId,tt),Ue=(ze==null?void 0:ze.agentName)??Bo(tt),st=(ze==null?void 0:ze.role)??pi(Ue),ot=js(q.agentId,Ue,Xe==null?void 0:Xe.displayName,je==null?void 0:je.runtimeProvider,je==null?void 0:je.runtimeClient),pt=ze===null&&(ot.id==="codex"||ot.id==="openai"||ot.id==="anthropic"||ot.id==="openclaw"),St=st?`${tt} — ${st}`:tt,z=ue?[]:q.nodes.slice(0,Mr),ce=Math.max(0,q.nodes.length-z.length),ke=Ie(c)===Ie(Ue)||Ie(c)===Ie(St);return e.jsxs(we.div,{layout:!0,transition:{type:"spring",stiffness:260,damping:30,mass:.75},className:de("overflow-hidden rounded-xl border border-subtle bg-white/[0.02] transition-all",Ve&&"border-white/20 bg-white/[0.05]",ke&&"border-[#0AD4C4]/30",!qe&&!ge&&!nt&&"opacity-55"),children:[e.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-2.5",children:[e.jsxs("button",{type:"button",onClick:()=>{l?l(ke?null:Ue):je&&i(je.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:[pt?e.jsx("span",{className:"inline-flex h-8 w-8 items-center justify-center rounded-lg border border-strong bg-white/[0.03]",children:e.jsx(ks,{provider:ot.id,size:"sm",showRing:!1})}):e.jsx(dt,{name:Ue,size:"sm",hint:`${q.agentId??""} ${Ue}`}),ze&&e.jsx("span",{className:"absolute -bottom-0.5 -left-0.5 inline-flex h-3 w-3 items-center justify-center rounded-full border border-[#08090D] bg-[#08090D]",children:e.jsx("img",{src:"/orgx/live/brand/orgx-logo.png",alt:"","aria-hidden":"true",className:"h-2.5 w-2.5 rounded-full object-contain",loading:"lazy"})}),je&&e.jsx("span",{className:"absolute -bottom-0.5 -right-0.5 h-2.5 w-2.5 rounded-full border-2",style:{backgroundColor:on(Re??je.status),borderColor:N.cardBg}}),!je&&e.jsx("span",{className:"absolute -bottom-0.5 -right-0.5 h-2.5 w-2.5 rounded-full border-2",style:{backgroundColor:ge?on("running"):"rgba(255,255,255,0.2)",borderColor:N.cardBg}})]}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsxs("div",{className:"flex min-w-0 items-baseline gap-1",children:[e.jsx("span",{className:"truncate text-body font-semibold text-white",title:tt,children:Ue}),st&&e.jsxs("span",{className:"max-w-[44%] truncate text-caption font-normal text-muted",title:st,children:["— ",st]})]})}),qe?e.jsxs("span",{className:"inline-flex min-w-[76px] items-center justify-end gap-1.5",children:[e.jsx("span",{className:"flex h-1.5 w-12 overflow-hidden rounded-full",children:(()=>{const se={};for(const pe of q.nodes){const Ce=Ot(pe);se[Ce]=(se[Ce]??0)+1}const oe=q.nodes.length;return Object.entries(se).map(([pe,Ce])=>e.jsx("span",{style:{width:`${Ce/oe*100}%`,backgroundColor:on(pe)}},pe))})()}),e.jsx("span",{className:"text-micro text-secondary",style:{fontVariantNumeric:"tabular-nums"},children:q.nodes.length})]}):ge||nt?e.jsxs("span",{className:"inline-flex min-w-[76px] items-center justify-end 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:on("running")}})}),e.jsx("span",{className:"text-micro text-secondary",style:{fontVariantNumeric:"tabular-nums"},children:Math.max(1,q.runtimeActiveCount??0)})]}):e.jsxs("span",{className:"inline-flex min-w-[76px] items-center justify-end gap-1.5",children:[e.jsx("span",{className:"flex h-1.5 w-12 overflow-hidden rounded-full bg-white/[0.06]"}),e.jsx("span",{className:"text-micro text-muted",style:{fontVariantNumeric:"tabular-nums"},children:"0"})]})]}),e.jsx("button",{type:"button",onClick:()=>D(ve),"aria-label":`View ${Ue} details`,className:"flex h-7 w-7 items-center justify-center rounded-md text-muted transition-colors hover:bg-white/[0.05] hover:text-primary",children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("path",{d:"M12 16v-4"}),e.jsx("path",{d:"M12 8h.01"})]})}),qe&&e.jsx("button",{type:"button",onClick:()=>H(ve),"aria-label":ue?"Expand sessions":"Collapse sessions",className:"flex h-7 w-7 items-center justify-center rounded-md text-muted transition-colors hover:bg-white/[0.05] hover:text-primary",children:e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:de("transition-transform",ue?"-rotate-90":"rotate-0"),children:e.jsx("path",{d:"m6 9 6 6 6-6"})})})]}),e.jsx(yt,{initial:!1,children:qe&&!ue&&e.jsx(we.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.2,ease:[.22,1,.36,1]},className:"overflow-hidden border-t border-subtle",children:e.jsxs("div",{className:"max-h-[500px] space-y-1.5 overflow-y-auto p-2",children:[z.map((se,oe)=>{const pe=r===se.id,Ce=Ot(se),Te=js(se.agentName,se.title,se.lastEventSummary,se);return e.jsx(we.button,{onClick:()=>i(se.id),initial:{opacity:0,y:4},animate:{opacity:1,y:0},transition:{duration:.16,delay:Math.min(oe*.015,.12)},className:de("w-full rounded-lg px-2.5 py-2 text-left transition-colors",pe?"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(ks,{provider:Te.id,size:"xs"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-body text-bright",title:se.title,children:se.title}),e.jsxs("div",{className:"flex items-center gap-1.5 text-micro text-secondary",children:[e.jsx("span",{className:"font-semibold uppercase tracking-[0.08em]",style:{color:Te.accent},children:Te.label}),e.jsx("span",{className:"uppercase tracking-[0.08em]",children:Ce}),e.jsx("span",{title:Yt(se.updatedAt??se.lastEventAt??se.startedAt??Date.now()),children:Ge(se.updatedAt??se.lastEventAt??se.startedAt??Date.now())})]}),se.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(se.progress)}%`,background:`linear-gradient(90deg, ${N.lime}, ${N.teal})`}})})]}),e.jsx("span",{className:"h-2 w-2 flex-shrink-0 rounded-full",style:{backgroundColor:on(Ce)},"aria-label":Ce,title:Ce})]})},se.id)}),ce>0&&e.jsxs("p",{className:"px-1 text-micro text-muted",children:["+",ce," older sessions hidden"]})]})})})]},ve)}),mt&&Qe>0&&e.jsx("div",{"aria-hidden":"true",style:{height:Qe}})]}),Q>0&&e.jsxs("div",{className:"rounded-xl border border-subtle bg-white/[0.02] px-3 py-2 text-caption text-secondary",children:["Showing ",Rn," most recent agent groups (",Q," older groups omitted)."]}),h&&x!=="connected"&&!he&&e.jsxs("div",{className:"rounded-xl border border-subtle bg-white/[0.02] text-caption text-secondary",children:[e.jsx("p",{className:"px-3 pt-2 pb-1.5 text-micro uppercase tracking-[0.1em] text-muted",children:"OrgX Agent Roster"}),e.jsx("div",{className:"space-y-1 px-2 pb-2",children:$o.map(q=>e.jsxs("div",{className:"flex items-center gap-2.5 rounded-lg px-2 py-1.5 opacity-55",children:[e.jsx("div",{className:"flex h-6 w-6 flex-shrink-0 items-center justify-center rounded-md border border-white/[0.08] bg-white/[0.03]",children:e.jsx("span",{className:"text-micro font-semibold text-secondary",children:q.name.charAt(0)})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-caption font-medium text-secondary",children:q.name}),e.jsx("p",{className:"text-micro text-muted",children:q.role})]}),e.jsx("button",{onClick:h,className:"rounded-md border border-lime/25 bg-lime/10 px-2 py-0.5 text-micro font-semibold text-lime transition-colors hover:bg-lime/20",children:"Connect"})]},q.id))})]}),te>0&&e.jsxs("div",{className:"rounded-xl border border-subtle bg-white/[0.02] text-caption text-secondary",children:[e.jsxs("button",{onClick:()=>{v(q=>!q),E&&A(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:de("transition-transform",E?"rotate-0":"-rotate-90"),children:e.jsx("path",{d:"m6 9 6 6 6-6"})}),e.jsxs("span",{children:[S," archived session",S===1?"":"s",ne>0?` across ${ne} agent${ne===1?"":"s"}`:""]})]}),e.jsx(yt,{initial:!1,children:E&&e.jsx(we.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.2,ease:[.22,1,.36,1]},className:"overflow-hidden",children:e.jsxs("div",{className:"space-y-1.5 border-t border-subtle p-2",children:[V.map(({node:q,agentName:ve})=>{const ue=Ot(q),je=q.runtimeProvider?{id:qo(q.runtimeProvider)}:js(q.agentName,q.title,q.lastEventSummary,q);return e.jsxs("button",{onClick:()=>i(q.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(ks,{provider:je.id,size:"xs"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"truncate text-caption font-medium text-primary",children:ve}),e.jsx("span",{className:"text-micro text-muted",title:Yt(q.updatedAt??q.lastEventAt??q.startedAt??Date.now()),children:Ge(q.updatedAt??q.lastEventAt??q.startedAt??Date.now())})]}),e.jsx("p",{className:"truncate text-micro text-secondary",children:q.title}),e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:ue})]})]},q.id)}),V.length<S&&e.jsxs("button",{onClick:()=>A(q=>q+1),className:"w-full rounded-lg border border-white/[0.08] bg-white/[0.02] px-3 py-1.5 text-micro text-secondary transition-colors hover:bg-white/[0.05]",children:["Load more (",S-V.length," remaining)"]})]})})})]})]})]})}),Uo=[[/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 Cn(t){if(!t)return"";for(const[s,r]of Uo)if(s.test(t))return r;const n=t.split("/");return n[n.length-1]??t}function Wo(t,n=4){let s=t.replace(/^\/Users\/[^/]+\//,"~/").replace(/^~\/Code\//,"").replace(/^~\//,"");const r=s.split("/");return r.length>n&&(s=r.slice(-n).join("/")),s}function De(t){let n=t;return n=n.replace(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi,s=>`#${s.slice(0,4)}`),n=n.replace(/(?:anthropic|openrouter|openai)\/[a-z0-9._/-]+/gi,s=>Cn(s)),n=n.replace(/\/Users\/[a-zA-Z0-9_-]+\/[^\s"']+/g,s=>Wo(s)),n}const As=/\[([^\]]+)\]\(([^)\s]+)\)|`([^`]+)`|\*\*([^*]+)\*\*|__([^_]+)__|\*([^*\n]+)\*|_([^_\n]+)_/g;function Ko(t){try{const n=new URL(t);return n.protocol==="http:"||n.protocol==="https:"}catch{return!1}}function Xt(t,n){const s=[];let r=0,i=0;As.lastIndex=0;for(let o=As.exec(t);o;o=As.exec(t)){const[l]=o,c=o.index;c>r&&s.push(t.slice(r,c));const h=`${n}-${i++}`,x=o[1],d=o[2],u=o[3],p=o[4],m=o[5],j=o[6],w=o[7];x&&d&&Ko(d)?s.push(e.jsx("a",{href:d,target:"_blank",rel:"noopener noreferrer",className:"text-[#D8FFA1] underline decoration-white/35 underline-offset-2 transition hover:text-[#ECFFC6]",children:x},h)):u?s.push(e.jsx("code",{className:"rounded bg-white/[0.08] px-1 py-0.5 font-mono text-[0.93em] text-bright",children:u},h)):p||m?s.push(e.jsx("strong",{className:"font-semibold text-white",children:p??m},h)):j||w?s.push(e.jsx("em",{className:"italic text-bright",children:j??w},h)):s.push(l),r=c+l.length}return r<t.length&&s.push(t.slice(r)),s}function Vo(t,n){const s=t.split(`
204
- `),r=[];return s.forEach((i,o)=>{r.push(...Xt(i,`${n}-line-${o}`)),o<s.length-1&&r.push(e.jsx("br",{},`${n}-br-${o}`))}),r}function Xn(t){return t.trim().replace(/^\|/,"").replace(/\|$/,"").split("|").map(s=>s.trim())}function Ho(t){const n=Xn(t);return n.length===0?!1:n.every(s=>/^:?-{3,}:?$/.test(s))}function Go(t){const n=t.trim(),s=n.startsWith(":"),r=n.endsWith(":");return s&&r?"center":r?"right":"left"}function Xo(t){const n=t.replace(/\r\n/g,`
205
- `).split(`
206
- `),s=[];let r=0;for(;r<n.length;){const i=n[r]??"",o=i.trim();if(!o){r+=1;continue}const l=i.includes("|"),c=n[r+1]??"";if(l&&c.includes("|")&&Ho(c)){const p=Xn(i),j=Xn(c).map(E=>Go(E));r+=2;const w=[];for(;r<n.length;){const E=n[r]??"";if(!E.trim()||!E.includes("|"))break;w.push(Xn(E)),r+=1}s.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:p.map((E,v)=>e.jsx("th",{className:"px-3 py-2 text-caption font-semibold uppercase tracking-[0.08em] text-primary",style:{textAlign:j[v]??"left"},children:Xt(E,`tbl-h-${r}-${v}`)},`tbl-h-${v}`))})}),e.jsx("tbody",{children:w.map((E,v)=>e.jsx("tr",{className:v<w.length-1?"border-b border-subtle":void 0,children:p.map((y,A)=>e.jsx("td",{className:"px-3 py-2 text-body leading-relaxed text-primary align-top",style:{textAlign:j[A]??"left"},children:Xt(E[A]??"",`tbl-r-${r}-${v}-${A}`)},`tbl-r-${v}-c-${A}`))},`tbl-r-${v}`))})]})},`tbl-${r}`));continue}if(o.startsWith("```")){const p=o.slice(3).trim(),m=[];for(r+=1;r<n.length&&!(n[r]??"").trim().startsWith("```");)m.push(n[r]??""),r+=1;r<n.length&&(r+=1),s.push(e.jsxs("div",{className:"rounded-xl border border-white/[0.1] bg-black/40 p-3",children:[p&&e.jsx("p",{className:"mb-1 text-micro uppercase tracking-[0.12em] text-muted",children:p}),e.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap font-mono text-caption leading-relaxed text-primary",children:e.jsx("code",{children:m.join(`
207
- `)})})]},`code-${r}`));continue}const h=o.match(/^(#{1,3})\s+(.+)$/);if(h){const p=h[1].length,m=h[2],j=p===1?"text-title font-semibold":p===2?"text-heading font-semibold":"text-body font-medium";s.push(e.jsx("p",{className:de("tracking-[-0.01em] text-white",j),children:Xt(m,`h-${r}`)},`h-${r}`)),r+=1;continue}if(i.match(/^\s*[-*]\s+(.+)$/)){const p=[];for(;r<n.length;){const j=(n[r]??"").match(/^\s*[-*]\s+(.+)$/);if(!j)break;p.push(j[1]),r+=1}s.push(e.jsx("ul",{className:"space-y-1.5 pl-4",children:p.map((m,j)=>e.jsx("li",{className:"list-disc text-body leading-relaxed text-primary",children:Xt(m,`ul-${r}-${j}`)},`ul-${r}-${j}`))},`ul-${r}`));continue}if(i.match(/^\s*\d+\.\s+(.+)$/)){const p=[];for(;r<n.length;){const j=(n[r]??"").match(/^\s*\d+\.\s+(.+)$/);if(!j)break;p.push(j[1]),r+=1}s.push(e.jsx("ol",{className:"space-y-1.5 pl-4",children:p.map((m,j)=>e.jsx("li",{className:"list-decimal text-body leading-relaxed text-primary",children:Xt(m,`ol-${r}-${j}`)},`ol-${r}-${j}`))},`ol-${r}`));continue}const u=[];for(;r<n.length;){const p=n[r]??"",m=p.trim();if(!m||/^(#{1,3})\s+/.test(m)||/^\s*[-*]\s+/.test(p)||/^\s*\d+\.\s+/.test(p)||m.startsWith("```"))break;u.push(p),r+=1}s.push(e.jsx("p",{className:"text-body leading-relaxed text-primary",children:Vo(u.join(`
208
- `),`p-${r}`)},`p-${r}`))}return s}function cn({text:t,mode:n="inline",className:s}){const r=t.replace(/\r\n/g,`
209
- `);return r.trim()?n==="inline"?e.jsx("span",{className:s,children:Xt(r,"inline")}):e.jsx("div",{className:de("space-y-2",s),children:Xo(r)}):null}const Jo={neutral:"border-strong bg-white/[0.04] text-primary",muted:"border-strong bg-white/[0.03] text-secondary",lime:"border-lime/28 bg-lime/[0.12] text-[#D8FFA1]",cyan:"border-cyan-300/28 bg-cyan-500/[0.12] text-cyan-100",red:"border-red-300/28 bg-red-500/[0.12] text-red-100"};function Tt({children:t,tone:n="muted",className:s,...r}){return e.jsx("span",{className:de("inline-flex min-h-7 items-center gap-1.5 rounded-full border px-2.5 py-1 text-caption font-medium leading-none",Jo[n],s),...r,children:t})}function ji(t){if(!(!t||typeof t!="object"||Array.isArray(t)))return t}function Qo(t){if(!t)return;const n=ji(t.metadata);return n?{...t,...n}:t}const ki={run_started:{icon:"play",label:"Run started",color:N.teal},run_completed:{icon:"check_circle",label:"Run completed",color:N.lime},run_failed:{icon:"alert_triangle",label:"Run failed",color:N.red},artifact_created:{icon:"file",label:"Artifact",color:N.cyan},decision_requested:{icon:"shield",label:"Decision requested",color:N.amber},decision_resolved:{icon:"shield_check",label:"Decision resolved",color:N.lime},handoff_requested:{icon:"handoff",label:"Handoff requested",color:N.iris},handoff_claimed:{icon:"handoff_claimed",label:"Handoff claimed",color:N.teal},handoff_fulfilled:{icon:"sparkles",label:"Handoff fulfilled",color:N.lime},blocker_created:{icon:"octagon_x",label:"Blocker",color:N.red},milestone_completed:{icon:"flag",label:"Milestone",color:N.cyan},delegation:{icon:"workflow",label:"Delegation",color:N.iris}};function An(t,n){if(!t)return null;for(const s of n){const r=t[s];if(typeof r=="string"&&r.trim().length>0)return r.trim()}return null}function Ks(t){return t?t.toLowerCase():""}function Yo(t,n){return[t.type,t.kind,t.phase,t.state,t.title,t.summary,t.description,An(n,["source","event","eventType","artifact_type","action","kind"]),An(n,["task","taskName","workstream","milestone","status"])].filter(s=>typeof s=="string"&&s.trim().length>0).join(" ").toLowerCase()}function Zo(t,n){const s=Ks(An(t,["artifact_type","artifactType"]));return s.includes("pr")||/pull request|merge request/.test(n)?{icon:"file_code",label:"Pull request",color:N.cyan}:s.includes("commit")||/commit|diff|patch/.test(n)?{icon:"git_commit",label:"Commit",color:N.cyan}:s.includes("config")?{icon:"checkpoint",label:"Config",color:N.cyan}:s.includes("design")?{icon:"compass",label:"Design output",color:N.cyan}:s.includes("report")||s.includes("document")||/memo|doc/.test(n)?{icon:"file",label:"Document",color:N.cyan}:ki.artifact_created}function el(t){const n=Qo(ji(t.metadata)),s=Yo(t,n),r=Ks(An(n,["source"])),i=Ks(An(n,["action"]));if(/heartbeat|heart beat|alive signal/.test(s))return{icon:"heartbeat",label:"Heartbeat",color:N.teal};if(/soul/.test(s))return{icon:"compass",label:"Soul state",color:N.iris};if(/memory sync|sync memory|workspace state|sync completed|memory file/.test(s))return{icon:"memory_sync",label:"Memory sync",color:N.teal};if(/checkpoint|rollback|restore point/.test(s))return{icon:"checkpoint",label:"Checkpoint",color:N.amber};if(/quality gate|quality score|quality check/.test(s))return{icon:"quality_gate",label:"Quality gate",color:N.lime};if(/model routing|routed model|model tier/.test(s))return{icon:"route",label:"Model routing",color:N.iris};if(r==="local_openclaw")return{icon:"terminal",label:"Local OpenClaw",color:N.teal};if(t.type==="artifact_created")return Zo(n,s);if(t.type==="decision_resolved")return i==="reject"||/rejected|declined/.test(s)?{icon:"shield_x",label:"Decision rejected",color:N.red}:{icon:"shield_check",label:"Decision approved",color:N.lime};if(t.type==="delegation"){if(/dispatch|spawn|launched|kickoff|started/.test(s))return{icon:"workflow",label:"Dispatch",color:N.iris};if(/message|chat|reply|summary/.test(s))return{icon:"message",label:"Message",color:N.teal}}return ki[t.type]??{icon:"message",label:"Activity",color:N.textMuted}}function tl({icon:t,size:n=14,className:s}){const r={width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.8,strokeLinecap:"round",strokeLinejoin:"round",className:s};switch(t){case"play":return e.jsx("svg",{...r,children:e.jsx("path",{d:"m8 6 10 6-10 6z"})});case"check_circle":return e.jsxs("svg",{...r,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"m8.5 12 2.5 2.5 4.5-5"})]});case"alert_triangle":return e.jsxs("svg",{...r,children:[e.jsx("path",{d:"m12 3 9 16H3z"}),e.jsx("path",{d:"M12 9v4"}),e.jsx("path",{d:"M12 17h.01"})]});case"file":return e.jsxs("svg",{...r,children:[e.jsx("path",{d:"M14 2H7a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7z"}),e.jsx("path",{d:"M14 2v5h5"})]});case"file_code":return e.jsxs("svg",{...r,children:[e.jsx("path",{d:"M14 2H7a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7z"}),e.jsx("path",{d:"M14 2v5h5"}),e.jsx("path",{d:"m10 13-2 2 2 2"}),e.jsx("path",{d:"m14 13 2 2-2 2"})]});case"git_commit":return e.jsxs("svg",{...r,children:[e.jsx("circle",{cx:"12",cy:"12",r:"3"}),e.jsx("path",{d:"M3 12h6M15 12h6"})]});case"shield":return e.jsxs("svg",{...r,children:[e.jsx("path",{d:"M12 3 5 6v6c0 5 3.3 7.8 7 9 3.7-1.2 7-4 7-9V6z"}),e.jsx("path",{d:"M12 9v4"}),e.jsx("path",{d:"M12 16h.01"})]});case"shield_check":return e.jsxs("svg",{...r,children:[e.jsx("path",{d:"M12 3 5 6v6c0 5 3.3 7.8 7 9 3.7-1.2 7-4 7-9V6z"}),e.jsx("path",{d:"m9 12.5 2 2 4-4"})]});case"shield_x":return e.jsxs("svg",{...r,children:[e.jsx("path",{d:"M12 3 5 6v6c0 5 3.3 7.8 7 9 3.7-1.2 7-4 7-9V6z"}),e.jsx("path",{d:"m10 10 4 4M14 10l-4 4"})]});case"handoff":return e.jsxs("svg",{...r,children:[e.jsx("path",{d:"M7 8h6a3 3 0 1 1 0 6H8"}),e.jsx("path",{d:"m10 14-3 3-3-3"}),e.jsx("path",{d:"M17 10h-4"})]});case"handoff_claimed":return e.jsxs("svg",{...r,children:[e.jsx("path",{d:"M8.5 12.5 12 9l3.5 3.5"}),e.jsx("path",{d:"M6 14h12"}),e.jsx("path",{d:"M7 18h10"})]});case"sparkles":return e.jsxs("svg",{...r,children:[e.jsx("path",{d:"m12 3 1.5 3.5L17 8l-3.5 1.5L12 13l-1.5-3.5L7 8l3.5-1.5z"}),e.jsx("path",{d:"m5 14 .8 1.8L8 16.6l-2.2.8L5 19l-.8-1.6L2 16.6l2.2-.8z"}),e.jsx("path",{d:"m19 14 .8 1.8 2.2.8-2.2.8L19 19l-.8-1.6-2.2-.8 2.2-.8z"})]});case"octagon_x":return e.jsxs("svg",{...r,children:[e.jsx("path",{d:"m10.2 3-5.8 3.3v11.4L10.2 21h3.6l5.8-3.3V6.3L13.8 3z"}),e.jsx("path",{d:"m9 9 6 6M15 9l-6 6"})]});case"flag":return e.jsxs("svg",{...r,children:[e.jsx("path",{d:"M5 3v18"}),e.jsx("path",{d:"m5 4 12 1-2 4 2 4-12-1"})]});case"workflow":return e.jsx(xi,{size:n,className:s,strokeWidth:1.8});case"memory_sync":return e.jsxs("svg",{...r,children:[e.jsx("ellipse",{cx:"12",cy:"5.5",rx:"6.5",ry:"2.5"}),e.jsx("path",{d:"M5.5 5.5v6c0 1.4 2.9 2.5 6.5 2.5s6.5-1.1 6.5-2.5v-6"}),e.jsx("path",{d:"m8 17-2 2 2 2"}),e.jsx("path",{d:"M16 17l2 2-2 2"})]});case"heartbeat":return e.jsx("svg",{...r,children:e.jsx("path",{d:"M3 12h4l2-4 3 8 2-4h7"})});case"checkpoint":return e.jsxs("svg",{...r,children:[e.jsx("path",{d:"M12 3v6"}),e.jsx("path",{d:"M8 5h8"}),e.jsx("path",{d:"M7 11h10v10H7z"}),e.jsx("path",{d:"M9 14h6"})]});case"quality_gate":return e.jsxs("svg",{...r,children:[e.jsx("path",{d:"M12 3 5 6v6c0 5 3.3 7.8 7 9 3.7-1.2 7-4 7-9V6z"}),e.jsx("path",{d:"m9 12.5 2 2 4-4"})]});case"route":return e.jsxs("svg",{...r,children:[e.jsx("circle",{cx:"6",cy:"6",r:"2"}),e.jsx("circle",{cx:"18",cy:"18",r:"2"}),e.jsx("path",{d:"M8 6h4a4 4 0 0 1 4 4v6"}),e.jsx("path",{d:"M16 6h2"})]});case"terminal":return e.jsxs("svg",{...r,children:[e.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2"}),e.jsx("path",{d:"m7 9 3 3-3 3"}),e.jsx("path",{d:"M13 15h4"})]});case"compass":return e.jsxs("svg",{...r,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"m10 10 6-2-2 6-6 2z"})]});case"message":default:return e.jsx("svg",{...r,children:e.jsx("path",{d:"M21 12a8 8 0 0 1-8 8H7l-4 2 1.5-4A8 8 0 1 1 21 12z"})})}}function ts(t){if(!(!t||typeof t!="object"||Array.isArray(t)))return t}function Vs(t){if(!t)return;const n=ts(t.metadata);return n?{...t,...n}:t}function nl(t){try{return new Date(t).toLocaleTimeString([],{hour:"numeric",minute:"2-digit"})}catch{return""}}function sl(t){let n=0;for(const s of t){const r=Vs(ts(s.metadata)),i=r==null?void 0:r.costTotal;typeof i=="number"&&(n+=i)}return n<=0?null:n<.01?"<$0.01":`$${n.toFixed(2)}`}const rl=a.memo(function({items:n,session:s,agentName:r,onBack:i}){const[o,l]=a.useState(!1),c=a.useMemo(()=>[...n].sort((p,m)=>Date.parse(p.timestamp)-Date.parse(m.timestamp)),[n]),h=a.useMemo(()=>sl(c),[c]),x=a.useMemo(()=>{if(c.length<2)return null;const p=Date.parse(c[0].timestamp),j=Date.parse(c[c.length-1].timestamp)-p;return j<6e4?`${Math.round(j/1e3)}s`:j<36e5?`${Math.round(j/6e4)}m`:`${(j/36e5).toFixed(1)}h`},[c]),d=a.useMemo(()=>{let p=null,m=null,j=null,w=null,E=null;for(const y of c){const A=Vs(ts(y.metadata));if(A&&(!p&&typeof A.domain=="string"&&(p=A.domain),!m&&typeof A.provider=="string"&&(m=A.provider),!j&&typeof A.model=="string"&&(j=A.model),!w&&typeof A.spawn_guard_model_tier=="string"&&(w=A.spawn_guard_model_tier),!E&&typeof A.kickoff_context_hash=="string"&&(E=A.kickoff_context_hash),p&&(m||j)&&w&&E))break}return!(p||m||j||w||E)?null:{domain:p,provider:m,model:j,modelTier:w,kickoffContextHash:E}},[c]),u=(s==null?void 0:s.title)??r??"Session";return e.jsxs("div",{className:"flex h-full flex-col",children:[e.jsxs("div",{className:"border-b border-subtle px-4 py-3",children:[e.jsxs("button",{onClick:i,className:"mb-2 flex items-center gap-1.5 text-caption text-secondary transition-colors hover:text-primary",children:[e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"m15 18-6-6 6-6"})}),"Back to timeline"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"h-2.5 w-2.5 rounded-full",style:{backgroundColor:N.lime,boxShadow:`0 0 12px ${N.lime}55`}}),e.jsx("h3",{className:"text-heading font-semibold text-white",children:De(u)})]}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2 text-micro text-secondary",children:[r&&e.jsxs("span",{className:"inline-flex items-center gap-1.5 rounded-full border border-subtle px-1 py-0.5",children:[e.jsx(dt,{name:r,hint:(s==null?void 0:s.id)??(s==null?void 0:s.runId)??null,size:"xs"}),e.jsx("span",{children:r})]}),e.jsxs("span",{children:[c.length," turn",c.length!==1?"s":""]}),x&&e.jsx("span",{children:x}),h&&e.jsx("span",{className:"text-muted",children:h}),(d==null?void 0:d.domain)&&e.jsx("span",{className:"rounded-full border border-strong bg-white/[0.03] px-2 py-0.5 text-secondary",children:De(d.domain)}),(s==null?void 0:s.status)&&e.jsx("span",{className:"rounded-full px-1.5 py-0.5 text-micro uppercase tracking-wider",style:{backgroundColor:s.status==="running"?`${N.lime}20`:s.status==="failed"?`${N.red}20`:`${N.teal}20`,color:s.status==="running"?N.lime:s.status==="failed"?N.red:N.teal},children:s.status}),d&&(d.provider||d.model||d.modelTier||d.kickoffContextHash)&&e.jsxs("button",{type:"button",onClick:()=>l(p=>!p),className:"inline-flex items-center gap-1 text-micro text-muted transition-colors hover:text-secondary",children:[e.jsx("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:`transition-transform duration-150 ${o?"rotate-180":""}`,children:e.jsx("path",{d:"m6 9 6 6 6-6"})}),"Info"]})]}),o&&d&&e.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-1.5 text-micro",children:[(d.provider||d.model)&&e.jsxs("span",{className:"rounded-full border border-strong bg-white/[0.03] px-2 py-0.5 text-secondary",children:[d.provider?`${De(d.provider)} · `:"",d.model?Cn(d.model):"—"]}),d.modelTier&&e.jsxs("span",{className:"rounded-full border border-strong bg-white/[0.03] px-2 py-0.5 text-secondary",children:["tier: ",De(d.modelTier)]}),d.kickoffContextHash&&e.jsxs("span",{className:"rounded-full border border-strong bg-white/[0.03] px-2 py-0.5 font-mono text-secondary",children:["kickoff ",d.kickoffContextHash.slice(0,8),"…"]})]})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-4 py-3",children:[e.jsx(yt,{mode:"popLayout",children:e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute left-[7px] top-3 bottom-3 w-px",style:{backgroundColor:`${N.iris}25`}}),e.jsx("div",{className:"space-y-1",children:c.map((p,m)=>{var O;const j=el(p),w=j.color,E=(O=Vs(ts(p.metadata)))==null?void 0:O.model,v=typeof E=="string"?Cn(E):null,y=De(p.title??""),A=p.type==="run_failed",k=p.type==="artifact_created",D=p.type==="decision_requested"||p.type==="decision_resolved";return e.jsxs(we.div,{initial:{opacity:0,x:-8},animate:{opacity:1,x:0},transition:{duration:.2,delay:m*.02},className:"group relative flex items-start gap-2.5 rounded-lg py-1.5 pl-0 pr-2 transition-colors hover:bg-white/[0.02]",children:[e.jsx("span",{className:"relative z-10 mt-1.5 flex h-[15px] w-[15px] flex-shrink-0 items-center justify-center rounded-full text-[8px]",style:{backgroundColor:`${w}20`,color:w,border:`1px solid ${w}40`},children:e.jsx(tl,{icon:j.icon,size:8,className:"opacity-95"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:`text-body leading-snug ${A?"text-red-400":D?"text-amber-300":k?"text-cyan-300":"text-bright"}`,children:y}),p.summary&&p.summary!==y&&e.jsx("p",{className:"mt-0.5 text-caption leading-relaxed text-muted",children:De(p.summary)})]}),e.jsxs("div",{className:"flex flex-shrink-0 flex-col items-end gap-0.5 pt-0.5",children:[e.jsx("span",{className:"text-micro text-muted",title:Yt(p.timestamp),children:nl(p.timestamp)}),v&&e.jsx("span",{className:"text-micro text-faint",children:v})]})]},p.id)})})]})}),c.length===0&&e.jsxs("div",{className:"flex flex-col items-center gap-2 py-8 text-center",children:[e.jsx("p",{className:"text-body text-secondary",children:"No activity in this session yet."}),e.jsx("p",{className:"text-caption text-muted animate-pulse",children:"Activity may take a moment to appear."})]}),c.length>0&&e.jsxs("div",{className:"mt-4 rounded-lg border border-subtle bg-white/[0.02] px-3 py-2 text-micro text-muted",children:[c.length," turn",c.length!==1?"s":"",x?` over ${x}`:"",h?` · ${h}`:""," · ",e.jsx("span",{title:Yt(c[c.length-1].timestamp),children:Ge(c[c.length-1].timestamp)})]})]})]})}),Ni=a.createContext(null);function il({children:t}){const[n,s]=a.useState({artifactId:null}),r=a.useCallback((o,l)=>{s({artifactId:o,context:l})},[]),i=a.useCallback(()=>{s({artifactId:null})},[]);return e.jsx(Ni.Provider,{value:{state:n,open:r,close:i},children:t})}function Si(){const t=a.useContext(Ni);if(!t)throw new Error("useArtifactViewer must be used within ArtifactViewerProvider");return t}const al={initial:{opacity:0,y:8,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-4,scale:.98}},Is=50,ol=50,vn=20,$r=3600,Tr=12e3,qn={all:"All",messages:"Messages",artifacts:"Artifacts",decisions:"Decisions"};function In(t){if(!t)return 0;const n=Date.parse(t);return Number.isFinite(n)?n:0}function ns(t){if(!(!t||typeof t!="object"||Array.isArray(t)))return t}function Js(t){if(!t)return;let n={...t},s=ns(n.metadata),r=0;for(;s&&r<4;)n={...n,...s},s=ns(s.metadata),r+=1;return n}function Ze(t){const n=ns(t==null?void 0:t.metadata);return Js(n)}function ll(t){const n=Js(t);if(!n)return"";const s=[];for(const[r,i]of Object.entries(n))typeof i=="string"&&(r.toLowerCase().includes("type")||r.toLowerCase().includes("kind")||r.toLowerCase().includes("summary")||r.toLowerCase().includes("message")||r.toLowerCase().includes("artifact")||r.toLowerCase().includes("decision")||r.toLowerCase().includes("run")||r.toLowerCase().includes("title")||r.toLowerCase().includes("task")||r.toLowerCase().includes("workstream")||r.toLowerCase().includes("milestone"))&&s.push(i);return s.join(" ")}function Ci(t){if(t.runId)return t.runId;const n=Ze(t);if(!n)return null;const s=["runId","run_id","sessionId","session_id","agentRunId"];for(const r of s){const i=n[r];if(typeof i=="string"&&i.trim().length>0)return i.trim()}return null}function kn(t){const n=Ze(t);if(!n)return{agentId:null,agentName:null};const s=(typeof n.agent_id=="string"&&n.agent_id.trim().length>0?n.agent_id.trim():null)??(typeof n.agentId=="string"&&n.agentId.trim().length>0?n.agentId.trim():null)??(typeof t.agentId=="string"&&t.agentId.trim().length>0?t.agentId.trim():null),r=(typeof n.agent_name=="string"&&n.agent_name.trim().length>0?n.agent_name.trim():null)??(typeof n.agentName=="string"&&n.agentName.trim().length>0?n.agentName.trim():null)??(typeof t.agentName=="string"&&t.agentName.trim().length>0?t.agentName.trim():null);return{agentId:s,agentName:r}}function Lr(t){if(typeof t!="string")return null;const n=t.trim();return n.length>0?n:null}function Pr(t,n,s){if(!t)return null;let r=null;for(const o of n){const l=Lr(t[o]);if(l){r=l;break}}let i=null;for(const o of s){const l=Lr(t[o]);if(l){i=l;break}}return!r&&!i?null:{id:r,name:i,label:i??r??"System"}}function cl(t,n){var s,r;if(!t||!n)return!1;if(t.id&&n.id){const i=t.id.trim().toLowerCase(),o=n.id.trim().toLowerCase();if(i===o){const l=((s=t.name)==null?void 0:s.trim().toLowerCase())??null,c=((r=n.name)==null?void 0:r.trim().toLowerCase())??null;return l&&c&&l!==c?!1:["unknown","system","agent","none","null","undefined"].includes(i)?!!(l&&c&&l===c):!0}}return!t.name||!n.name?!1:t.name.trim().toLowerCase()===n.name.trim().toLowerCase()}function Dr(t){const n=Ze(t),s=kn(t),r=rs(t),o=(t.requesterAgentId||t.requesterAgentName?{id:t.requesterAgentId??null,name:t.requesterAgentName??null,label:t.requesterAgentName??t.requesterAgentId??"System"}:null)??Pr(n,["requested_by_agent_id","requestedByAgentId","requester_agent_id","requesterAgentId","requester_id","requesterId","runner_agent_id","runnerAgentId"],["requested_by_agent_name","requestedByAgentName","requester_agent_name","requesterAgentName","requester_name","requesterName","runner_agent_name","runnerAgentName"])??null,c=(t.executorAgentId||t.executorAgentName?{id:t.executorAgentId??null,name:t.executorAgentName??null,label:t.executorAgentName??t.executorAgentId??"Agent"}:null)??Pr(n,["executed_by_agent_id","executedByAgentId","executor_agent_id","executorAgentId","delegated_to_agent_id","delegatedToAgentId","handoff_to_agent_id","handoffToAgentId","agent_id","agentId"],["executed_by_agent_name","executedByAgentName","executor_agent_name","executorAgentName","delegated_to_agent_name","delegatedToAgentName","handoff_to_agent_name","handoffToAgentName","agent_name","agentName"])??(s.agentId||s.agentName?{id:s.agentId,name:s.agentName,label:s.agentName??s.agentId??"Agent"}:null);return o&&c?cl(o,c)?{requester:o,executor:c,mode:"single",primaryLabel:c.label,subtitle:c.label}:{requester:o,executor:c,mode:"handoff",primaryLabel:c.label,subtitle:`${o.label} -> ${c.label}`}:o&&!c?{requester:o,executor:null,mode:"requested",primaryLabel:o.label,subtitle:`${o.label} requested dispatch`}:!o&&c?{requester:null,executor:c,mode:"single",primaryLabel:c.label,subtitle:c.label}:r.isSystem?{requester:null,executor:null,mode:"system",primaryLabel:"System",subtitle:"System"}:{requester:null,executor:null,mode:"system",primaryLabel:t.agentName??t.agentId??"OrgX",subtitle:t.agentName??t.agentId??"System"}}function qt(t){return t?[t.id,t.name,t.label].filter(Boolean).join(" "):""}function Hs(t){const n=Ze(t);if(!n)return null;const s=["workstreamId","workstream_id"];for(const i of s){const o=n[i];if(typeof o=="string"&&o.trim().length>0)return o.trim()}const r=n.orgx_context;if(r&&typeof r=="object"&&!Array.isArray(r)){const i=r,o=i.workstreamId??i.workstream_id;if(typeof o=="string"&&o.trim().length>0)return o.trim()}return null}function _s(t){const n=Ze(t);if(!n)return null;const s=["artifact_id","artifactId","work_artifact_id"];for(const r of s){const i=n[r];if(typeof i=="string"&&i.length>0)return i}return null}const Br=new Map([["autopilot_slice_artifact_buffered","artifact"],["decision_buffered","decision"],["auto_continue_spawn_guard_blocked","decision"],["autopilot_slice_mcp_handshake_failed","decision"],["autopilot_slice_timeout","decision"],["autopilot_slice_log_stall","decision"]]);function zn(t){if(typeof t!="string")return null;const n=t.trim().toLowerCase();return n==="artifact"?"artifact":n==="decision"?"decision":n==="message"?"message":null}function dl(t,n){if(!t)return null;for(const s of n){const r=t[s];if(typeof r=="boolean")return r;if(typeof r=="string"){const i=r.trim().toLowerCase();if(i==="true")return!0;if(i==="false")return!1}}return null}function Un(t,n){if(!t)return null;for(const s of n){const r=t[s];if(typeof r=="number"&&Number.isFinite(r))return Math.max(0,r);if(typeof r=="string"){const i=Number(r);if(Number.isFinite(i))return Math.max(0,i)}}return null}function ul(t){if(!t)return null;const n=t.event;if(typeof n!="string")return null;const s=n.trim().toLowerCase();return s.length>0?s:null}function ml(t){const n=Ze(t),s=zn(t.kind)??zn(n==null?void 0:n.activity_bucket)??zn(n==null?void 0:n.activityBucket)??zn(n==null?void 0:n.bucket);if(s)return s;if(t.type==="artifact_created")return"artifact";if(t.type==="decision_requested"||t.type==="decision_resolved")return"decision";const r=ul(n),i=t.decisionRequired===!0||dl(n,["decision_required","decisionRequired"])===!0,o=Un(n,["artifacts","artifact_count","artifactCount"])??0,l=Un(n,["decisions","decision_count","decisionCount"])??0,c=Un(n,["blocking_decisions","blockingDecisions","blocking_decision_count","blockingDecisionCount"])??0,h=Un(n,["non_blocking_decisions","nonBlockingDecisions","non_blocking_decision_count","nonBlockingDecisionCount"])??0;return r==="autopilot_slice_result"?i||c>0?"decision":o>0?"artifact":l>0||h>0?"decision":"message":r&&Br.has(r)?Br.get(r):typeof(n==null?void 0:n.artifact_id)=="string"||typeof(n==null?void 0:n.artifactId)=="string"||typeof(n==null?void 0:n.work_artifact_id)=="string"||o>0?"artifact":i||l>0||c>0||h>0?"decision":"message"}function ln(t){return{run_started:"Run started",run_completed:"Run completed",run_failed:"Run failed",artifact_created:"Artifact created",decision_requested:"Decision requested",decision_resolved:"Decision resolved",handoff_requested:"Handoff requested",handoff_claimed:"Handoff claimed",handoff_fulfilled:"Handoff fulfilled",blocker_created:"Blocker created",milestone_completed:"Milestone completed",delegation:"Delegation"}[t]??De(t.split("_").join(" "))}function pl(t){const n=new Date(t);if(Number.isNaN(n.getTime()))return"unknown";const s=new Date(n.getFullYear(),n.getMonth(),n.getDate());return String(s.getTime())}function xl(t){const n=Number(t);if(!Number.isFinite(n))return"Unknown day";const s=new Date(n),r=new Date,i=new Date(r.getFullYear(),r.getMonth(),r.getDate()),o=new Date(i);return o.setDate(i.getDate()-1),s.getTime()===i.getTime()?"Today":s.getTime()===o.getTime()?"Yesterday":s.toLocaleDateString(void 0,{month:"short",day:"numeric",year:s.getFullYear()===r.getFullYear()?void 0:"numeric"})}function Ms(t){return t==="artifact"?"Artifact":t==="decision"?"Decision":"Message"}function jn(t){return t==="artifact"?N.cyan:t==="decision"?N.amber:N.teal}function hl(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 fl(t){return t==="critical"?N.red:t==="warning"?N.amber:t==="positive"?N.lime:N.teal}function Rr(t){if(!t||Object.keys(t).length===0)return null;try{return JSON.stringify(t,null,2)}catch{return null}}function _n(t){if(typeof t=="number"&&Number.isFinite(t))return t;if(typeof t=="string"){const n=Number(t);if(Number.isFinite(n))return n}return null}function Dt(t){const n=_n(t);if(n!==null)return Math.max(0,Math.round(n));if(Array.isArray(t))return t.length;if(t&&typeof t=="object"&&!Array.isArray(t)){const s=t,r=_n(s.count??s.total??s.size);if(r!==null)return Math.max(0,Math.round(r))}return null}function gl(t){const n=_n(t);if(n===null)return null;const s=n>0&&n<=1?n*100:n;return Math.max(0,Math.min(100,Math.round(s)))}function bl(t,n){for(const s of n){const r=gl(t[s]);if(r!==null)return r}return null}function Ai(t){if(!t)return null;const n=Ze(t);if(!n)return null;const s=typeof n.event=="string"&&n.event.trim().length>0?n.event.trim():null,r=s??"",i=r.startsWith("autopilot_slice")&&!r.includes("artifact");if(!s||!i&&s!=="auto_continue_stopped"&&s!=="next_up_manual_dispatch_started")return null;const o=kn(t),l=(typeof n.requested_by_agent_id=="string"&&n.requested_by_agent_id.trim().length>0?n.requested_by_agent_id.trim():null)??(typeof n.requestedByAgentId=="string"&&n.requestedByAgentId.trim().length>0?n.requestedByAgentId.trim():null)??(typeof n.runner_agent_id=="string"&&n.runner_agent_id.trim().length>0?n.runner_agent_id.trim():null)??(typeof n.runnerAgentId=="string"&&n.runnerAgentId.trim().length>0?n.runnerAgentId.trim():null)??o.agentId,c=(typeof n.requested_by_agent_name=="string"&&n.requested_by_agent_name.trim().length>0?n.requested_by_agent_name.trim():null)??(typeof n.requestedByAgentName=="string"&&n.requestedByAgentName.trim().length>0?n.requestedByAgentName.trim():null)??(typeof n.runner_agent_name=="string"&&n.runner_agent_name.trim().length>0?n.runner_agent_name.trim():null)??(typeof n.runnerAgentName=="string"&&n.runnerAgentName.trim().length>0?n.runnerAgentName.trim():null)??o.agentName,h=(typeof n.source_client=="string"&&n.source_client.trim().length>0?n.source_client.trim():null)??(typeof n.sourceClient=="string"&&n.sourceClient.trim().length>0?n.sourceClient.trim():null)??(typeof t.runtimeClient=="string"&&t.runtimeClient.trim().length>0?t.runtimeClient.trim():null),x=n.required_skills??n.requiredSkills,d=Array.isArray(x)?x.filter(ae=>typeof ae=="string"&&ae.trim().length>0):[],u=jl(d),p=n.task_ids??n.taskIds,m=Array.isArray(p)?p.filter(ae=>typeof ae=="string"&&ae.trim().length>0):[],j=n.milestone_ids??n.milestoneIds,w=Array.isArray(j)?j.filter(ae=>typeof ae=="string"&&ae.trim().length>0):[],E=Ke(n,["initiative_id","initiativeId"])??(typeof t.initiativeId=="string"&&t.initiativeId.trim().length>0?t.initiativeId.trim():null),v=Ke(n,["initiative_title","initiativeTitle"]),y=Ke(n,["initiative_status","initiativeStatus"]),A=Hs(t),k=Ke(n,["workstream_title","workstreamTitle"]),D=Ke(n,["workstream_status","workstreamStatus"]),O=Ke(n,["task_title","taskTitle"]),I=Ke(n,["milestone_title","milestoneTitle"]),ee=Ke(n,["domain"]),X=Ke(n,["phase","slice_phase","slicePhase"]),le=Ke(n,["next_step","nextStep"]),Q=bl(n,["progress_pct","progressPct","progress_percent","progressPercent","completion_pct","completionPct","slice_progress_pct","sliceProgressPct"]),ne=typeof n.parsed_status=="string"?n.parsed_status:typeof n.parsedStatus=="string"?n.parsedStatus:null,te=typeof n.has_output=="boolean"?n.has_output:typeof n.hasOutput=="boolean"?n.hasOutput:null,M=typeof n.log_path=="string"?n.log_path:typeof n.logPath=="string"?n.logPath:null,L=typeof n.output_path=="string"?n.output_path:typeof n.outputPath=="string"?n.outputPath:null,C=typeof n.error=="string"?n.error:null,S=Dt(n.artifacts??n.artifact_count??n.artifactCount),f=Dt(n.decisions??n.decision_count??n.decisionCount),R=n.decisions_needed??n.decisionsNeeded;let V=Dt(n.blocking_decisions??n.blockingDecisions??n.blocking_decision_count??n.blockingDecisionCount),H=Dt(n.non_blocking_decisions??n.nonBlockingDecisions??n.non_blocking_decision_count??n.nonBlockingDecisionCount);if((V===null||H===null)&&Array.isArray(R)){let ae=0,xe=0;for(const _e of R){if(!_e||typeof _e!="object"||Array.isArray(_e))continue;_e.blocking===!1?xe+=1:ae+=1}V===null&&(V=ae),H===null&&(H=xe)}V===null&&f!==null&&t.decisionRequired===!0&&(V=f>0?f:1),H===null&&f!==null&&V!==null&&(H=Math.max(0,f-V)),V===null&&f!==null&&H!==null&&(V=Math.max(0,f-H));const G=Dt(n.status_updates_applied??n.statusUpdatesApplied),Y=Dt(n.task_updates??n.taskUpdates),ie=Dt(n.milestone_updates??n.milestoneUpdates),J=G??(Y!==null||ie!==null?(Y??0)+(ie??0):null),Fe=Dt(n.status_updates_buffered??n.statusUpdatesBuffered),he=typeof n.stop_reason=="string"?n.stop_reason:typeof n.stopReason=="string"?n.stopReason:null,fe=_n(n.token_budget??n.tokenBudget),et=_n(n.tokens_used??n.tokensUsed),W=o.agentId??(typeof n.runner_agent_id=="string"&&n.runner_agent_id.trim().length>0?n.runner_agent_id.trim():null)??(typeof n.runnerAgentId=="string"&&n.runnerAgentId.trim().length>0?n.runnerAgentId.trim():null),F=o.agentName??(typeof n.runner_agent_name=="string"&&n.runner_agent_name.trim().length>0?n.runner_agent_name.trim():null)??(typeof n.runnerAgentName=="string"&&n.runnerAgentName.trim().length>0?n.runnerAgentName.trim():null)??u,Z=u&&!o.agentName?null:W;return{event:s,agentId:Z,agentName:F,requesterAgentId:l,requesterAgentName:c,dispatcherClient:h,initiativeId:E,domain:ee,phase:X,progressPct:Q,nextStep:le,requiredSkills:d,initiativeStatus:y,initiativeTitle:v,workstreamId:A,workstreamStatus:D,workstreamTitle:k,taskTitle:O,milestoneTitle:I,taskIds:m,milestoneIds:w,parsedStatus:ne,hasOutput:te,artifacts:S,decisions:f,blockingDecisions:V,nonBlockingDecisions:H,statusUpdatesApplied:J,statusUpdatesBuffered:Fe,stopReason:he,tokenBudget:fe,tokensUsed:et,logPath:M,outputPath:L,error:C}}function Or(t){const n=t.trim();return n?/^https?:\/\//i.test(n)?n:`/orgx/api/live/filesystem/open?path=${encodeURIComponent(n)}`:""}function yl(t){const n=Js(t);if(!n)return null;const s=n,r=s.orgx_provenance,i=r&&typeof r=="object"&&!Array.isArray(r)?r:null,o=i!=null&&i.skill_pack&&typeof i.skill_pack=="object"&&!Array.isArray(i.skill_pack)?i.skill_pack:null,l=(typeof s.orgx_plugin_version=="string"?s.orgx_plugin_version:null)??(typeof(i==null?void 0:i.plugin_version)=="string"?i.plugin_version:null),c=(typeof s.skill_pack_name=="string"?s.skill_pack_name:null)??(typeof(o==null?void 0:o.name)=="string"?o.name:null),h=(typeof s.skill_pack_version=="string"?s.skill_pack_version:null)??(typeof(o==null?void 0:o.version)=="string"?o.version:null),x=(typeof s.skill_pack_checksum=="string"?s.skill_pack_checksum:null)??(typeof(o==null?void 0:o.checksum)=="string"?o.checksum:null),d=(typeof s.skill_pack_source=="string"?s.skill_pack_source:null)??(typeof(o==null?void 0:o.source)=="string"?o.source:null),u=typeof s.kickoff_context_hash=="string"?s.kickoff_context_hash:null,p=typeof s.kickoff_context_source=="string"?s.kickoff_context_source:null,m=typeof s.spawn_guard_model_tier=="string"?s.spawn_guard_model_tier:null,j=typeof s.provider=="string"?s.provider:null,w=typeof s.model=="string"?s.model:null,E=typeof s.domain=="string"?s.domain:null,v=s.required_skills??s.requiredSkills,y=Array.isArray(v)?v.filter(k=>typeof k=="string"&&k.trim().length>0):[];return!!l||!!(c||h||x)||!!u||!!(m||j||w||E)||y.length>0?{pluginVersion:l,skillPack:c||h||x||d?{name:c,version:h,checksum:x,source:d}:null,kickoffContextHash:u,kickoffContextSource:p,modelTier:m,provider:j,model:w,domain:E,requiredSkills:y}:null}function wl(t){if(!t)return null;const n=Ze(t);if(!n||typeof n!="object")return null;const s=["artifact","artifacts","output","outputs","result","results","payload","toolOutput","toolOutputs","toolResult","toolResults"];for(const r of s){const i=n[r];if(i!=null)return{source:r,value:i}}return t.type==="artifact_created"?{source:"metadata",value:n}:null}function vl(t){const n=t.trim();return!n||/^[a-z]+:\/\//i.test(n)||/^data:/i.test(n)?!1:n.startsWith("/")||n.startsWith("~/")||/^[A-Za-z]:[\\/]/.test(n)||/^[.]{1,2}\//.test(n)?!0:n.includes("/")&&!/\s{2,}/.test(n)}function Ii(t){const n=Ze(t);if(!n)return[];const s=[],r=new Set,i=(l,c)=>{if(typeof c!="string")return;const h=c.trim();if(!h||!vl(h))return;const x=`${l}:${h}`;r.has(x)||(r.add(x),s.push({key:l,path:h}))},o=(l,c="",h=0)=>{if(!(h>2))for(const[x,d]of Object.entries(l)){const u=c?`${c}.${x}`:x,p=x.toLowerCase();if(p.includes("path")||p==="url"||p==="uri"||p.endsWith("url")||p.endsWith("_file")||p.endsWith("file")||p.includes("artifact"))if(Array.isArray(d))for(const j of d)i(u,j);else i(u,d);d&&typeof d=="object"&&!Array.isArray(d)&&o(d,u,h+1)}};return o(n),s}function Ke(t,n){if(!t)return null;for(const s of n){const r=t[s];if(typeof r=="string"&&r.trim().length>0)return r.trim()}return null}function jl(t){var r;if(t.length!==1)return null;const n=(r=t[0])==null?void 0:r.trim();if(!n)return null;const s={"orgx-marketing-agent":"OrgX Marketing","orgx-engineering-agent":"OrgX Engineering","orgx-design-agent":"OrgX Design","orgx-product-agent":"OrgX Product","orgx-sales-agent":"OrgX Sales","orgx-operations-agent":"OrgX Operations","orgx-orchestrator-agent":"OrgX Orchestrator"};if(s[n])return s[n];if(n.endsWith("-agent")){const i=n.replace(/^orgx-/,"").replace(/-agent$/,"").trim();return i.length===0?null:`OrgX ${De(i)}`}return null}function qr(t,n,s){const r=typeof t=="string"&&t.trim().length>0?t.trim():null,i=typeof n=="string"&&n.trim().length>0?n.trim():null,o={main:"Holt"},l=i?(s==null?void 0:s.get(i))??o[i]??null:null,c=r??l;return c&&i&&i!==c?`${c} · ${i}`:c||(i??"—")}const Wn=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,kl=/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi;function ss(t){const n=new Set;if(!t)return n;for(const o of[t.title,t.summary,t.description])if(typeof o=="string")for(const l of o.match(kl)??[]){const c=l.trim().toLowerCase();Wn.test(c)&&n.add(c)}typeof t.runId=="string"&&Wn.test(t.runId.trim())&&n.add(t.runId.trim().toLowerCase());const s=Ze(t);if(!s)return n;const r=["run_id","runId","last_run_id","lastRunId","active_run_id","activeRunId","slice_id","sliceId","worker_run_id","workerRunId","correlation_id","correlationId","initiative_id","initiativeId","workstream_id","workstreamId","task_id","taskId","milestone_id","milestoneId","outbox_event_id","outboxEventId","requester_id","requesterId"],i=["task_ids","taskIds","milestone_ids","milestoneIds","allowed_workstream_ids","allowedWorkstreamIds"];for(const o of r){const l=s[o];if(typeof l=="string"){const c=l.trim().toLowerCase();Wn.test(c)&&n.add(c)}}for(const o of i){const l=s[o];if(Array.isArray(l))for(const c of l){if(typeof c!="string")continue;const h=c.trim().toLowerCase();Wn.test(h)&&n.add(h)}}return n}function Nl(t,n,s){if(!t)return[];const r=Ze(t),i=Ke(r,["workstream_id","workstreamId"]),o=Ke(r,["initiative_id","initiativeId"]),l=ss(t);if(!i&&!o&&l.size===0)return[];const c=In(t.timestamp),h=[];for(const p of n){if(p.id===t.id)continue;const m=Ze(p);if(!m)continue;const j=Ke(m,["workstream_id","workstreamId"]),w=Ke(m,["initiative_id","initiativeId"]),E=ss(p),v=l.size>0&&Array.from(l).some(I=>E.has(I)),y=!!i&&!!j&&i===j;if(!v&&!y&&!(!!o&&!!w&&o===w))continue;const k=Ii(p).filter(I=>!s.has(I.path));if(k.length===0)continue;const D=Math.abs(In(p.timestamp)-c);if(!v&&D>7200*1e3)continue;const O=v?0:y?1:2;!v&&D>1200*1e3||h.push({priority:O,delta:D,evidence:k})}if(h.length===0)return[];h.sort((p,m)=>p.priority!==m.priority?p.priority-m.priority:p.delta-m.delta);const x=[],d=new Set(s),u=h[0].priority;for(const p of h){if(p.priority!==u)break;for(const m of p.evidence)if(!d.has(m.path)&&(d.add(m.path),x.push({key:`related.${m.key}`,path:m.path}),x.length>=8))return x}return x}function Sl(t,n){if(!t)return null;const s=Ze(t),r=Ke(s,["workstream_id","workstreamId"]),i=Ke(s,["initiative_id","initiativeId"]),o=ss(t);if(!r&&!i&&o.size===0)return null;const l=In(t.timestamp),c=[];for(const x of n){if(x.id===t.id)continue;const d=Ai(x);if(!d)continue;const u=Ze(x);if(!u)continue;const p=Ke(u,["workstream_id","workstreamId"]),m=Ke(u,["initiative_id","initiativeId"]),j=ss(x),w=o.size>0&&Array.from(o).some(D=>j.has(D)),E=!!r&&!!p&&r===p;if(!w&&!E&&!(!!i&&!!m&&i===m))continue;const y=Math.abs(In(x.timestamp)-l);if(!w&&y>1200*1e3)continue;const A=w?"shared_id":E?"workstream":"initiative",k=A==="shared_id"?0:A==="workstream"?1:2;c.push({priority:k,delta:y,relation:A,detail:d})}if(c.length===0)return null;c.sort((x,d)=>x.priority!==d.priority?x.priority-d.priority:x.delta-d.delta);const h=c[0];return{detail:h.detail,relation:h.relation}}function Qt(t){return t?t.trim().toLowerCase().replace(/[\s-]+/g,"_"):""}function os(t){const n=Qt(t);return["done","complete","completed","stopped","success"].includes(n)}function Es(t){const n=Qt(t.parsedStatus),s=Qt(t.event);return n==="failed"||n==="error"||n==="timed_out"||n==="timeout"||n==="aborted"||s.includes("error")||s.includes("timeout")?"critical":n==="blocked"||t.stopReason==="blocked"?"warning":os(n)||t.stopReason==="completed"?"positive":"neutral"}function Cl(t){if(os(t.parsedStatus)||t.stopReason==="completed")return 100;const n=Qt(t.parsedStatus);if(n==="blocked"||n==="error"||n==="failed")return 100;const s=t.event;return s==="next_up_manual_dispatch_started"?8:s==="autopilot_slice_dispatched"?14:s==="autopilot_slice_status_updates_buffered"?72:s==="autopilot_slice_result"?92:s==="auto_continue_stopped"?100:s.startsWith("autopilot_slice")?56:null}function _i(t){return typeof t!="number"||!Number.isFinite(t)?null:Math.max(0,Math.min(100,Math.round(t)))}function Al(t,n){if(!t&&n===null)return null;if((t==null?void 0:t.progressPct)!==null&&(t==null?void 0:t.progressPct)!==void 0)return{pct:_i(t.progressPct)??0,source:"metadata",label:"Reported by slice metadata",tone:t?Es(t):"neutral"};if(n!==null)return{pct:n,source:"session",label:"Derived from runtime session",tone:t?Es(t):"neutral"};if(!t)return null;const s=Cl(t);return s===null?null:{pct:s,source:"lifecycle",label:"Estimated from dispatch lifecycle",tone:Es(t)}}function Il(t,n,s){const r=Ze(t),i=Qt(t.state??t.phase??t.kind??t.type),o=Qt((s==null?void 0:s.parsedStatus)??(n==null?void 0:n.parsedStatus)??i),l=Qt((s==null?void 0:s.stopReason)??(n==null?void 0:n.stopReason)),c=Ke(r,["blocked_reason","blockedReason","error","message"])??(n==null?void 0:n.error)??t.description??null,h=Math.max(0,(s==null?void 0:s.decisions)??(n==null?void 0:n.decisions)??0),x=Math.max(0,(s==null?void 0:s.blockingDecisions)??(n==null?void 0:n.blockingDecisions)??(t.decisionRequired===!0?Math.max(1,h):0)),d=Math.max(0,(s==null?void 0:s.nonBlockingDecisions)??(n==null?void 0:n.nonBlockingDecisions)??Math.max(0,h-x)),u=t.decisionRequired===!0||t.type==="decision_requested"||x>0||o==="needs_decision",p=t.type==="run_completed"||t.type==="milestone_completed"||os(o)||l==="completed";return t.type==="run_failed"||t.type==="blocker_created"||o==="blocked"||o==="failed"||o==="error"||l==="blocked"||l==="error"?{label:"Blocked",summary:c?Lt(c)??"Execution is blocked.":"Execution is blocked and needs intervention.",hint:u?"Resolve the pending decision, then resume the session.":"Open the session and retry after fixing the blocker.",tone:"critical"}:u?{label:"Needs decision",summary:"Execution paused pending approval or a human choice.",hint:"Review the Decisions panel and approve the pending item to continue.",tone:"warning"}:p&&d>0?{label:"Completed + follow-up",summary:`Execution completed. ${d} non-blocking decision${d===1?"":"s"} were logged for optional follow-up.`,hint:"Review the decision for optimization, but no approval is required to mark this slice complete.",tone:"positive"}:t.type==="decision_resolved"?{label:"Decision resolved",summary:"A pending decision was completed.",hint:null,tone:"positive"}:p?{label:"Completed",summary:"Execution completed successfully.",hint:null,tone:"positive"}:t.type==="run_started"||i==="running"||i==="in_progress"?{label:"In progress",summary:"Execution is actively running.",hint:null,tone:"neutral"}:null}function Mi(t){if(typeof t=="string")return e.jsx(cn,{mode:"block",text:t,className:"text-body leading-relaxed text-primary"});if(typeof t=="number"||typeof t=="boolean")return e.jsx("p",{className:"text-body text-primary",children:String(t)});if(Array.isArray(t))return e.jsx("div",{className:"space-y-1.5",children:t.map((n,s)=>e.jsx("div",{className:"rounded-lg border border-white/[0.08] bg-white/[0.02] px-2.5 py-2",children:Mi(n)},`artifact-list-${s}`))});if(t&&typeof t=="object"){const n=Object.entries(t);return e.jsx("dl",{className:"space-y-1.5",children:n.map(([s,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-micro font-semibold tracking-[0.02em] text-secondary",children:De(s)}),e.jsx("dd",{className:"mt-1 text-body text-primary",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"}`:"—"})]},s))})}return e.jsx("p",{className:"text-body text-secondary",children:"No artifact payload."})}function Lt(t){if(!t)return null;const n=t.trim();if(!n)return null;const s=Cn(n);return s&&s!==n&&/^[a-z0-9._/-]+$/i.test(n)?s:De(n)}const _l=[/^User:\s*System:/i,/Exec failed/i,/SIGKILL/i,/SIGTERM/i,/stack trace/i,/Traceback \(most recent/i,/^\s*\{[\s"]/,/Error: /,/execution policy/i,/outbox replay/i,/changeset replayed/i];function Ml(t){return _l.some(n=>n.test(t))}function rs(t){const n=t.title??"";return Ml(n)?/Exec failed|SIGKILL|SIGTERM|Error: /i.test(n)?{title:"Execution failed",isSystem:!0}:/outbox replay|changeset replayed/i.test(n)?{title:"Changes synced",isSystem:!0}:/execution policy/i.test(n)?{title:"System directive",isSystem:!0}:{title:"System event",isSystem:!0}:{title:De(n)||De(ln(t.type)),isSystem:!1}}const El=new Set(["changeset_replayed","changeset_applied","changeset.replayed","changeset.applied","outbox_replay_applied","outbox_replayed","sync_applied","sync.applied","sentinel_changeset_applied","sentinel_decision_applied","sentinel.changeset.applied","sentinel.decision.applied"]);function Nn(t){const n=Ze(t);if(!n)return!1;const s=(typeof n.event=="string"&&n.event.trim().length>0?n.event.trim().toLowerCase():null)??(typeof n.event_name=="string"&&n.event_name.trim().length>0?n.event_name.trim().toLowerCase():null)??(typeof n.eventName=="string"&&n.eventName.trim().length>0?n.eventName.trim().toLowerCase():null),r=(typeof n.source_client=="string"?n.source_client:null)??(typeof n.sourceClient=="string"?n.sourceClient:null),i=(r==null?void 0:r.toLowerCase())??"",o=(typeof t.kind=="string"&&t.kind.trim().length>0?t.kind.trim().toLowerCase():null)??(typeof n.kind=="string"&&n.kind.trim().length>0?n.kind.trim().toLowerCase():null)??(typeof n.event_kind=="string"&&n.event_kind.trim().length>0?n.event_kind.trim().toLowerCase():null)??(typeof n.eventKind=="string"&&n.eventKind.trim().length>0?n.eventKind.trim().toLowerCase():null)??"",l=/(changeset[\._ ]?(applied|replayed)|sync[\._ ]?applied|sentinel[\._ ]?(changeset|decision)[\._ ]?applied)/i.test(o),c=n.replayed===!0,h=typeof n.changeset_id=="string"&&n.changeset_id.trim().length>0||typeof n.changesetId=="string"&&n.changesetId.trim().length>0,x=/changes synced|changeset replayed|changeset applied|outbox replay/i.test(`${t.title??""} ${t.summary??""} ${t.description??""}`);return!!(s&&El.has(s)||l||c&&(h||x)||h&&(x||i.includes("outbox")||i.includes("replay"))||i.includes("outbox_replay")&&x)}function zr(t){var h;if(!t||!Nn(t))return null;const n=Ze(t),s=Dt((n==null?void 0:n.applied_count)??(n==null?void 0:n.appliedCount)??(n==null?void 0:n.applied)??null),r=(typeof(n==null?void 0:n.idempotency_key)=="string"?n.idempotency_key:null)??(typeof(n==null?void 0:n.idempotencyKey)=="string"?n.idempotencyKey:null),i=((h=r==null?void 0:r.match(/sentinel:([a-z_]+):/i))==null?void 0:h[1])??null,o=Ke(n,["entity_type","entityType"])??i??(t.type==="milestone_completed"?"milestone":null),l=s!==null?`${s} change${s===1?"":"s"}`:"Queued changes",c=o?` for ${De(o).toLowerCase()}`:"";return`${l}${c} were synced from local replay.`}function Fs(t){if(!Nn(t))return null;const n=Ze(t);if(!n)return null;const s=Ke(n,["idempotency_key","idempotencyKey"]);if(s)return`idem:${s.toLowerCase()}`;const r=Ke(n,["event","event_name","eventName"])??"",i=Ke(n,["changeset_id","changesetId"])??"",o=Ke(n,["entity_type","entityType"])??"",l=Ke(n,["entity_id","entityId"])??"",c=Ci(t)??"",h=rs(t).title.trim().toLowerCase();return`fallback:${r.toLowerCase()}:${i.toLowerCase()}:${o.toLowerCase()}:${l.toLowerCase()}:${c.toLowerCase()}:${h}`}function Fl(t){if(!t)return null;const n=Ze(t);if(!n||typeof n!="object")return null;const s=typeof n.source=="string"?n.source.trim():"",r=typeof n.turnId=="string"?n.turnId.trim():"";if(s!=="local_openclaw"||!r)return null;const i=typeof n.sessionKey=="string"&&n.sessionKey.trim().length>0?n.sessionKey.trim():null;return{turnId:r,sessionKey:i,runId:t.runId??null}}function Ur(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 $l(t,n){const r=(Lt(n??t.summary)??Lt(t.description)??De(t.title||ln(t.type))).replace(/\r\n/g,`
210
- `).replace(/```[\s\S]*?```/g," ").replace(/^\s{0,3}#{1,6}\s+/gm,"").replace(/^\s*[-*]\s+/gm,"").replace(/\s+/g," ").trim(),i=r.split(`
211
- `).map(l=>Ur(l).trim()).filter(l=>l.length>0&&!/^\|?[:\-| ]+\|?$/.test(l));let o=i[0]??Ur(r);return o.length<24&&i.length>1&&(o=`${o} ${i[1]}`.trim()),o.length>108?`${o.slice(0,107).trimEnd()}…`:o}const Tl=a.memo(function({activity:n,sessions:s,initiatives:r=[],selectedRunIds:i,selectedSessionLabel:o=null,selectedWorkstreamId:l=null,selectedWorkstreamLabel:c=null,agentFilter:h=null,timeFilterId:x="30m",onTimeFilterChange:d,hasMore:u=!1,isLoadingMore:p=!1,onLoadMore:m,onClearSelection:j,onClearWorkstreamFilter:w,onClearAgentFilter:E,onFocusRunId:v,onPlayNextUp:y,onStartAutopilot:A,onCreateInitiative:k,onOpenMissionControl:D,isLoading:O=!1}){var Ys;const I=ai(),{open:ee}=Si(),[X,le]=a.useState("all"),[Q,ne]=a.useState(!1),[te,M]=a.useState(!1),[L,C]=a.useState(""),[S,f]=a.useState(new Set),[R,V]=a.useState({}),[H,G]=a.useState("newest"),[Y,ie]=a.useState(!1),[J,Fe]=a.useState(Is),[he,fe]=a.useState(null),[et,W]=a.useState(null),[F,Z]=a.useState(!1),[ae,xe]=a.useState(1),[_e,Qe]=a.useState("overview"),[mt,Nt]=a.useState("structured"),[q,ve]=a.useState(null),[ue,je]=a.useState("feed"),[Re,qe]=a.useState(null),[ge,Xe]=a.useState(null),[nt,Ve]=a.useState(!1),[tt,ze]=a.useState(null),[Ue,st]=a.useState(null),ot=a.useRef(null),pt=a.useRef(null),St=a.useRef(null),z=a.useMemo(()=>ui(x),[x]),ce=a.useMemo(()=>{const b=new Map;for(const P of s)b.set(P.runId,P.title),b.set(P.id,P.title);return b},[s]),ke=a.useMemo(()=>{const b=new Map;for(const P of s)P.status&&(b.set(P.runId,P.status),b.set(P.id,P.status));return b},[s]),ye=a.useMemo(()=>{const b=new Map;for(const P of s){const T=_i(P.progress);T!==null&&(b.set(P.runId,T),b.set(P.id,T))}return b},[s]),se=a.useMemo(()=>{const b=new Map;for(const P of s)!P.agentId||!P.agentName||b.set(P.agentId,P.agentName);return b},[s]),oe=a.useMemo(()=>{const b=new Map;for(const P of s){const T=P.workstreamId??null;b.set(P.runId,T),b.set(P.id,T)}return b},[s]),pe=a.useMemo(()=>{const b=new Map;for(const P of r)b.set(P.id,P.name);return b},[r]),Ce=a.useMemo(()=>{const b=new Map;for(const P of r)for(const T of P.workstreams??[])b.set(T.id,T.name);return b},[r]),Te=a.useMemo(()=>n.map(b=>{const P=Ci(b),T=ml(b),K=[b.title,b.description,b.summary,b.agentName,ll(Ze(b))].filter(Me=>typeof Me=="string"&&Me.length>0).join(" ").toLowerCase();return{item:b,bucket:T,runId:P,timestampEpoch:In(b.timestamp),searchText:K}}),[n]),Be=a.useMemo(()=>{let b=0;for(const P of Te)b=Math.max(b,P.timestampEpoch);return b<=0?!1:Date.now()-b<6e4},[Te]),lt=a.useMemo(()=>new Set(i.filter(b=>b&&b.trim().length>0)),[i]),xt=lt.size>0,Mn=a.useMemo(()=>Sn.filter(b=>["30m","live","24h","7d","all"].includes(b.id)),[]),Zt=a.useMemo(()=>{if(!xt)return null;for(const b of lt){const P=s.find(T=>T.runId===b||T.id===b);if(P)return P}return null},[xt,lt,s]),{filtered:He,filteredTotal:Ft,hiddenCount:dn,hiddenSyncCount:En}=a.useMemo(()=>{const b=[];let P=0,T=0;const K=new Set,Me=L.trim().toLowerCase();for(const We of Te){const $e=We.runId;if(xt&&(!$e||!lt.has($e)))continue;if(l){const rn=Hs(We.item),gn=$e?oe.get($e)??null:null;if((rn??gn)!==l)continue}const At=kn(We.item);if(h&&At.agentName!==h)continue;const Ht=Fs(We.item);if(Ht){if(K.has(Ht)){T+=1;continue}if(K.add(Ht),!Q){T+=1;continue}}else if(!Q&&Nn(We.item)){T+=1;continue}const ft=We.bucket;if(!(X==="messages"&&ft!=="message")&&!(X==="artifacts"&&ft!=="artifact")&&!(X==="decisions"&&ft!=="decision")){if(Me.length>0){const rn=$e?ce.get($e)??$e:"";if(!`${We.searchText} ${rn.toLowerCase()}`.includes(Me))continue}b.length<Tr?b.push(We):P+=1}}const Pe=[...b].sort((We,$e)=>{const At=$e.timestampEpoch-We.timestampEpoch;return H==="newest"?At:-At}),Ee=Math.min(Math.max(1,Math.min($r,J)),Pe.length),at=Pe.slice(0,Ee),_t=Pe.length+P;return{filtered:at,filteredTotal:_t,hiddenCount:Math.max(0,_t-at.length),hiddenSyncCount:T}},[X,h,Te,xt,L,ce,J,l,lt,oe,Q,H]),wt=a.useMemo(()=>{const b=new Map;for(const T of He){const K=pl(T.item.timestamp),Me=b.get(K);Me?Me.push(T):b.set(K,[T])}return Array.from(b.keys()).sort((T,K)=>{const Me=Number(K)-Number(T);return H==="newest"?Me:-Me}).map(T=>({key:T,label:xl(T),items:b.get(T)??[]}))},[He,H]),un=a.useMemo(()=>wt.map(b=>{const P=new Map;for(const T of b.items){const K=rs(T.item).title.trim().toLowerCase(),Me=Fs(T.item),Pe=Me?`${T.item.type}::sync::${Me}`:`${T.item.type}::${K}`,Ee=P.get(Pe);Ee?(Ee.count+=1,Ee.firstTimestamp=Math.min(Ee.firstTimestamp,T.timestampEpoch),Ee.allItems.push(T),T.timestampEpoch>Ee.representative.timestampEpoch&&(Ee.representative=T)):P.set(Pe,{key:Pe,representative:T,count:1,firstTimestamp:T.timestampEpoch,allItems:[T]})}return{...b,clusters:Array.from(P.values())}}),[wt]),Fn=a.useCallback(b=>{f(P=>{const T=new Set(P);return T.has(b)?T.delete(b):T.add(b),T}),V(P=>{if(Object.prototype.hasOwnProperty.call(P,b)){const T={...P};return delete T[b],T}return{...P,[b]:vn}})},[]),$n=a.useCallback((b,P)=>{V(T=>{const K=T[b]??vn,Me=Math.min(P,K+vn);return Me===K?T:{...T,[b]:Me}})},[]),mn=a.useMemo(()=>Math.min($r,Math.min(Tr,Ft)),[Ft]);a.useEffect(()=>{Fe(Is),f(new Set),V({})},[X,h,xt,L,l,Q,H,x]),a.useEffect(()=>{if(!Y)return;const b=T=>{var Me;const K=T.target;K instanceof Node&&((Me=ot.current)!=null&&Me.contains(K)||ie(!1))},P=T=>{T.key==="Escape"&&ie(!1)};return window.addEventListener("pointerdown",b),window.addEventListener("keydown",P),()=>{window.removeEventListener("pointerdown",b),window.removeEventListener("keydown",P)}},[Y]),a.useEffect(()=>{const b=pt.current,P=St.current;if(!b||!P)return;const T=new IntersectionObserver(K=>{if(K.some(Pe=>Pe.isIntersecting)){if(He.length<mn){Fe(Pe=>Math.min(mn,Math.max(Pe,Is)+ol));return}u&&!p&&(m==null||m())}},{root:b,rootMargin:"240px"});return T.observe(P),()=>T.disconnect()},[He.length,u,p,m,mn]);const $t=a.useMemo(()=>he?He.findIndex(b=>b.item.id===he):-1,[he,He]),B=$t>=0?He[$t]:null,Wt=a.useMemo(()=>wl((B==null?void 0:B.item)??null),[B]),pn=a.useMemo(()=>_s((B==null?void 0:B.item)??null),[B]),xn=a.useMemo(()=>Ai((B==null?void 0:B.item)??null),[B]),ct=a.useMemo(()=>xn?null:Sl((B==null?void 0:B.item)??null,n),[xn,B,n]),be=a.useMemo(()=>B?Dr(B.item):null,[B]),en=a.useMemo(()=>be?be.executor??be.requester:null,[be]),Ne=xn??(ct==null?void 0:ct.detail)??null,ls=a.useMemo(()=>{var b,P;return qr((Ne==null?void 0:Ne.requesterAgentName)??((b=be==null?void 0:be.requester)==null?void 0:b.name)??null,(Ne==null?void 0:Ne.requesterAgentId)??((P=be==null?void 0:be.requester)==null?void 0:P.id)??null,se)},[Ne,be,se]),cs=a.useMemo(()=>{var P,T;const b=qr((Ne==null?void 0:Ne.agentName)??((P=be==null?void 0:be.executor)==null?void 0:P.name)??null,(Ne==null?void 0:Ne.agentId)??((T=be==null?void 0:be.executor)==null?void 0:T.id)??null,se);return b==="—"?(be==null?void 0:be.primaryLabel)??"Codex":b},[Ne,be,se]),hn=a.useMemo(()=>B!=null&&B.runId?ye.get(B.runId)??null:null,[B,ye]),vt=a.useMemo(()=>Al(Ne,hn),[Ne,hn]),re=a.useMemo(()=>{const b=Ne;if(!b)return null;const P=b.initiativeId??(B==null?void 0:B.item.initiativeId)??null,T=P?r.find(ft=>ft.id===P)??null:null,K=b.initiativeTitle??(T==null?void 0:T.name)??null,Me=b.initiativeStatus??(T==null?void 0:T.status)??null,Pe=(T==null?void 0:T.workstreams)??[],Ee=Pe.length>0?Pe.length:null,at=Ee!==null?Pe.filter(ft=>os(ft.status)).length:null,_t=Ee&&at!==null?Math.round(at/Ee*100):null,We=b.workstreamId??null,$e=We&&Pe.length>0?Pe.find(ft=>ft.id===We)??null:null,At=b.workstreamTitle??($e==null?void 0:$e.name)??(We?Ce.get(We)??null:null),Ht=b.workstreamStatus??($e==null?void 0:$e.status)??null;return{initiativeId:P,initiativeTitle:K,initiativeStatus:Me,totalInitiativeWorkstreams:Ee,doneInitiativeWorkstreams:at,initiativeWorkstreamPct:_t,workstreamId:We,workstreamTitle:At,workstreamStatus:Ht,taskTitle:b.taskTitle,milestoneTitle:b.milestoneTitle,scopedTaskCount:b.taskIds.length,scopedMilestoneCount:b.milestoneIds.length,statusUpdatesApplied:b.statusUpdatesApplied,statusUpdatesBuffered:b.statusUpdatesBuffered,artifacts:b.artifacts,decisions:b.decisions,blockingDecisions:b.blockingDecisions,nonBlockingDecisions:b.nonBlockingDecisions,tokensUsed:b.tokensUsed,tokenBudget:b.tokenBudget,nextStep:b.nextStep,phase:b.phase,stopReason:b.stopReason,parsedStatus:b.parsedStatus}},[Ne,B,r,Ce]),Ct=a.useMemo(()=>B?Il(B.item,Ne,re?{decisions:re.decisions,blockingDecisions:re.blockingDecisions,nonBlockingDecisions:re.nonBlockingDecisions,stopReason:re.stopReason,parsedStatus:re.parsedStatus}:null):null,[Ne,B,re]),fn=a.useMemo(()=>vt?vt.tone==="positive"?N.lime:vt.tone==="warning"?N.amber:vt.tone==="critical"?N.red:N.teal:N.teal,[vt]),Le=a.useMemo(()=>yl(Ze((B==null?void 0:B.item)??null)),[B]),Tn=a.useMemo(()=>Ze((B==null?void 0:B.item)??null),[B]),g=a.useMemo(()=>B?kn(B.item):{agentId:null,agentName:null},[B]),$=a.useMemo(()=>Rr(ns(B==null?void 0:B.item.metadata)??void 0),[B]),U=a.useMemo(()=>Rr(Tn),[Tn]),_=a.useMemo(()=>{const b=Ii((B==null?void 0:B.item)??null);return b.length>0?b:Nl((B==null?void 0:B.item)??null,n,new Set)},[B,n]),me=a.useMemo(()=>{if(_.length===0)return null;const b=_[0];return b?Or(b.path):null},[_]),Se=a.useMemo(()=>{const b=Lt(q);if(b)return b;const P=zr((B==null?void 0:B.item)??null);return P||(Lt(B==null?void 0:B.item.summary)??Lt(B==null?void 0:B.item.description))},[q,B]),Ye=a.useMemo(()=>B?Nn(B.item):!1,[B]),Ae=a.useCallback(()=>{fe(null)},[]),it=a.useCallback(async(b,P)=>{if(P){st(null),ze(b);try{await P()}catch(T){st(T instanceof Error?T.message:"Action failed")}finally{ze(T=>T===b?null:T)}}},[]);a.useEffect(()=>{if(!et)return;const b=window.setTimeout(()=>W(null),2e3);return()=>window.clearTimeout(b)},[et]),a.useEffect(()=>{st(null)},[X,L,x]);const rt=a.useCallback(async(b,P)=>{if(P)try{await navigator.clipboard.writeText(P),W(`${b} copied`)}catch{W("Copy failed")}},[]);a.useEffect(()=>{Nt("structured"),Z(!1),Qe("overview")},[he]),a.useEffect(()=>{ve(null),je("feed");const b=Fl((B==null?void 0:B.item)??null);if(!b)return;const P=new URLSearchParams({turnId:b.turnId});b.sessionKey&&P.set("sessionKey",b.sessionKey),b.runId&&P.set("run",b.runId);const T=new AbortController;return fetch(`/orgx/api/live/activity/detail?${P.toString()}`,{method:"GET",signal:T.signal}).then(async K=>{var Pe;return K.ok?((Pe=(await K.json()).detail)==null?void 0:Pe.summary)??null:(K.status===404&&je("missing"),null)}).then(K=>{typeof K=="string"&&K.trim().length>0?(ve(K),je("local")):je("missing")}).catch(K=>{K instanceof DOMException&&K.name==="AbortError"||je("missing")}),()=>T.abort()},[B]),a.useEffect(()=>{qe(null),Xe(null);const b=B==null?void 0:B.item;if(!b||nt)return;const P=(q??b.summary??b.description??b.title??"").trim();if(!P)return;const T=new AbortController;return fetch("/orgx/api/live/activity/headline",{method:"POST",headers:{"Content-Type":"application/json"},signal:T.signal,body:JSON.stringify({text:P,title:b.title??null,type:b.type})}).then(async K=>K.ok?await K.json():((K.status===404||K.status===405)&&Ve(!0),null)).then(K=>{const Me=K==null?void 0:K.headline;typeof Me=="string"&&Me.trim().length>0&&(Ve(!1),qe(Me.trim()),Xe((K==null?void 0:K.source)??null))}).catch(K=>{K instanceof DOMException&&K.name}),()=>T.abort()},[B,q,nt]);const ht=a.useCallback(b=>{var K;if(He.length===0)return;const T=(($t>=0?$t:0)+b+He.length)%He.length;xe(b),fe(((K=He[T])==null?void 0:K.item.id)??null)},[$t,He]);a.useEffect(()=>{he&&($t>=0||fe(null))},[$t,he]),a.useEffect(()=>{if(!he)return;const b=P=>{P.key==="ArrowRight"||P.key.toLowerCase()==="l"?(P.preventDefault(),ht(1)):(P.key==="ArrowLeft"||P.key.toLowerCase()==="h")&&(P.preventDefault(),ht(-1))};return window.addEventListener("keydown",b),()=>window.removeEventListener("keydown",b)},[he,ht]);const tn=lt.size===1,Kt=tn?[...lt][0]:null,nn=Kt?s.find(b=>b.runId===Kt||b.id===Kt)??null:null,Vt=a.useMemo(()=>{if(!tn)return[];const b=[],P=new Set;for(const T of Te){if(!T.runId||!lt.has(T.runId))continue;const K=Fs(T.item);if(K){if(P.has(K)||(P.add(K),!Q))continue}else if(!Q&&Nn(T.item))continue;b.push(T.item)}return b},[tn,Te,lt,Q]),Qs=!I&&He.length<=160,sn=(b,P,T)=>{var ar,or;const K=b.item,Me=T??K.id,Pe=kn(K),Ee=Dr(K),at=Ee.executor??Ee.requester,_t=(at==null?void 0:at.label)||Ee.primaryLabel||Pe.agentName||Pe.agentId||K.agentName||"OrgX",We=hl(K),$e=fl(We),At=H==="newest"&&P<2,Ht=b.bucket,ft=b.runId,rn=ft?ke.get(ft)??null:null,gn=zr(K),ds=gn!==null,{title:us,isSystem:Zs}=rs(K),er=Zs?"System":Ee.subtitle,tr=Ee.mode==="handoff"&&Ee.requester!==null&&Ee.executor!==null,nr=gn??Lt(K.summary),sr=Lt(K.description),ms=K.initiativeId?pe.get(K.initiativeId)??null:null,ps=Hs(K)??(ft?oe.get(ft)??null:null),xs=ps?Ce.get(ps)??De(ps):null,Oi=ds?"Sync":Ms(Ht),qi=ds?"Synced":We==="critical"?"Error":We==="warning"?"Needs review":We==="positive"?"Completed":"Update",zi=new Date(K.timestamp).toLocaleTimeString([],{hour:"numeric",minute:"2-digit"}),rr="group w-full rounded-xl border border-white/[0.08] bg-white/[0.02] px-3.5 py-3 text-left transition-colors hover:border-strong hover:bg-white/[0.05] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#BFFF00]/45 cv-auto",ir=e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"mt-0.5",children:tr?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsxs("div",{className:"inline-flex -space-x-2",children:[e.jsx("span",{className:"rounded-full bg-[#080808] p-[1px]",children:e.jsx(dt,{name:((ar=Ee.requester)==null?void 0:ar.label)??"Requester",hint:qt(Ee.requester),size:"xs"})}),e.jsx("span",{className:"rounded-full bg-[#080808] p-[1px]",children:e.jsx(dt,{name:((or=Ee.executor)==null?void 0:or.label)??"Executor",hint:qt(Ee.executor),size:"xs"})})]}),e.jsx("span",{className:"text-micro text-muted",children:"→"})]}):e.jsx(dt,{name:_t,hint:qt(at)||[Pe.agentId,Pe.agentName,_t].filter(Boolean).join(" "),size:"xs"})}),e.jsxs("div",{className:"relative min-w-0 flex-1 pl-3",children:[e.jsx("span",{className:de("absolute inset-y-0 left-0 w-[2px] rounded-full",At&&"pulse-soft"),style:{backgroundColor:$e,boxShadow:`0 0 14px ${$e}66`}}),e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:`line-clamp-2 break-words text-body font-semibold leading-snug ${Zs?"text-muted":"text-bright"}`,children:us}),e.jsxs("p",{className:"mt-0.5 truncate text-caption text-secondary",title:er,children:[er,rn?` · ${De(rn)}`:""]})]}),e.jsxs("div",{className:"flex shrink-0 flex-col items-end gap-1",children:[e.jsx("span",{className:"text-micro font-semibold tracking-[0.02em] text-muted",children:Oi}),e.jsx("span",{className:"text-caption text-secondary",children:zi})]})]}),(nr||sr)&&e.jsx("div",{className:"mt-1.5 line-clamp-2 text-caption leading-relaxed text-secondary",children:e.jsx(cn,{mode:"inline",text:nr??sr??""})}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-1.5 text-micro",children:[e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full border px-2 py-0.5 font-semibold tracking-[0.01em]",style:{borderColor:`${$e}55`,backgroundColor:`${$e}1A`,color:$e},children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full",style:{backgroundColor:$e}}),qi]}),tr&&e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full border border-cyan-300/25 bg-cyan-500/[0.10] px-2 py-0.5 text-cyan-100",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-cyan-200"}),"Handoff"]}),ms?e.jsxs("span",{className:"inline-flex max-w-[220px] items-center gap-1 rounded-full border border-strong bg-white/[0.03] px-2 py-0.5 text-secondary",title:ms,children:[e.jsx(Oe,{type:"initiative",size:10,className:"opacity-85"}),e.jsx("span",{className:"truncate",children:ms})]}):xs?e.jsxs("span",{className:"inline-flex max-w-[220px] items-center gap-1 rounded-full border border-strong bg-white/[0.03] px-2 py-0.5 text-secondary",title:xs,children:[e.jsx(Oe,{type:"workstream",size:10,className:"opacity-90"}),e.jsx("span",{className:"truncate",children:xs})]}):null,e.jsx("span",{className:"text-secondary",children:Ge(K.timestamp)})]})]})]});return Qs?e.jsx(we.button,{type:"button",variants:al,initial:"initial",animate:"animate",exit:"exit",transition:{duration:.25,ease:[.4,0,.2,1]},whileHover:{y:-1.5},whileTap:{scale:.995},onClick:()=>{xe(1),fe(K.id)},className:rr,"aria-label":`Open activity details for ${us||ln(K.type)}`,children:ir},Me):e.jsx("button",{type:"button",onClick:()=>{xe(1),fe(K.id)},className:de(rr,"transform-gpu transition-[transform,background-color,border-color,color] hover:-translate-y-[1px] active:scale-[0.995]"),"aria-label":`Open activity details for ${us||ln(K.type)}`,children:ir},Me)};return e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[tn&&Vt.length>0?e.jsx(rl,{items:Vt,session:nn,agentName:((Ys=Vt[0])==null?void 0:Ys.agentName)??null,onBack:j}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"border-b border-subtle px-4 py-3.5",children:e.jsxs("div",{className:"flex flex-col gap-2.5",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-2.5",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[e.jsx("h2",{className:"text-heading font-semibold text-white",children:"Activity"}),e.jsx("span",{className:"rounded-full border border-strong bg-white/[0.05] px-2 py-0.5 text-micro text-primary tabular-nums",children:Ft}),dn>0&&e.jsxs("span",{className:"rounded-full border border-strong bg-white/[0.03] px-2 py-0.5 text-micro text-secondary tabular-nums",children:["+",dn," hidden"]}),En>0&&!Q&&e.jsxs("button",{type:"button",onClick:()=>ne(!0),className:"rounded-full border border-white/[0.14] bg-white/[0.03] px-2 py-0.5 text-micro text-secondary tabular-nums transition-colors hover:bg-white/[0.08] hover:text-primary",title:"Show low-signal sync replay events",children:[En," sync hidden"]}),Q&&e.jsx("button",{type:"button",onClick:()=>ne(!1),className:"rounded-full border border-lime/30 bg-lime/[0.10] px-2 py-0.5 text-micro text-[#E1FFB2] transition-colors hover:bg-lime/[0.16]",title:"Hide low-signal sync replay events",children:"Sync visible"}),z.id!=="all"&&e.jsx("span",{className:"rounded-full border border-strong bg-white/[0.02] px-2 py-0.5 text-micro text-secondary",children:z.label}),e.jsx("span",{className:de("h-1.5 w-1.5 flex-shrink-0 rounded-full",Be&&"pulse-soft"),style:{backgroundColor:N.lime},"aria-label":"Live",title:Be?"New activity within the last minute":"Live activity feed"})]}),e.jsxs("div",{className:"ml-auto flex flex-wrap items-center justify-end gap-1.5",children:[e.jsx("div",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.08] bg-white/[0.02] p-0.5",role:"group","aria-label":"Activity type filters",children:Object.keys(qn).map(b=>{const P=X===b;return e.jsx("button",{type:"button",onClick:()=>le(b),"aria-pressed":P,className:de("rounded-full px-3 py-1.5 text-micro font-semibold transition-colors",P?"border border-lime/25 bg-lime/[0.10] text-[#E1FFB2]":"border border-transparent text-secondary hover:bg-white/[0.08] hover:text-bright"),children:qn[b]},b)})}),e.jsx("button",{type:"button",onClick:()=>M(b=>!b),className:de("inline-flex h-8 w-8 items-center justify-center rounded-full border bg-white/[0.03] text-muted transition-colors hover:bg-white/[0.08] hover:text-primary",te?"border-lime/30 text-lime":"border-white/[0.1]"),"aria-pressed":te,"aria-label":te?"Expand activity density":"Compact activity density",title:te?"Expand activity density":"Compact activity density",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",children:[e.jsx("path",{d:"M4 7h16"}),e.jsx("path",{d:te?"M4 12h16":"M4 12h10"}),e.jsx("path",{d:"M4 17h16"})]})}),e.jsxs("div",{className:"relative",ref:ot,children:[e.jsxs("button",{type:"button",onClick:()=>ie(b=>!b),"aria-haspopup":"menu","aria-expanded":Y,className:de("inline-flex h-8 items-center gap-1.5 rounded-full border px-2.5 text-caption font-semibold transition-colors",Y?"border-lime/30 bg-lime/[0.10] text-[#E1FFB2]":"border-white/[0.1] bg-white/[0.03] text-primary hover:bg-white/[0.08]"),children:[e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M4 6h16"}),e.jsx("path",{d:"M7 12h10"}),e.jsx("path",{d:"M10 18h4"})]}),e.jsx("span",{className:"hidden sm:inline",children:"Filters"}),e.jsx("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",className:de("transition-transform duration-200",Y&&"rotate-180"),children:e.jsx("path",{d:"m6 9 6 6 6-6"})})]}),e.jsx(yt,{children:Y&&e.jsx(we.div,{initial:{opacity:0,y:-6,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-4,scale:.98},transition:{duration:.18,ease:[.22,1,.36,1]},className:"absolute right-0 z-20 mt-2 w-[290px] rounded-xl border border-white/[0.12] bg-[#0A0D14]/95 p-3 shadow-[0_12px_40px_rgba(0,0,0,0.45)] backdrop-blur-xl",role:"menu","aria-label":"Activity view controls",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"mb-1 text-micro font-semibold uppercase tracking-[0.08em] text-muted",children:"Sort"}),e.jsx("div",{className:"grid grid-cols-2 gap-1",children:[{id:"newest",label:"Newest"},{id:"oldest",label:"Oldest"}].map(b=>e.jsx("button",{type:"button",onClick:()=>{G(b.id),ie(!1)},className:de("rounded-lg border px-2 py-1.5 text-caption font-medium transition-colors",H===b.id?"border-lime/30 bg-lime/[0.12] text-[#E1FFB2]":"border-white/[0.08] bg-white/[0.02] text-secondary hover:bg-white/[0.06] hover:text-primary"),children:b.label},b.id))})]}),e.jsxs("div",{children:[e.jsx("p",{className:"mb-1 text-micro font-semibold uppercase tracking-[0.08em] text-muted",children:"Date range"}),e.jsx("div",{className:"flex flex-wrap gap-1",children:Sn.map(b=>{const P=x===b.id;return e.jsx("button",{type:"button",onClick:()=>{d==null||d(b.id),ie(!1)},className:de("rounded-full border px-2.5 py-1 text-micro font-semibold transition-colors",P?"border-lime/30 bg-lime/[0.12] text-[#E1FFB2]":"border-white/[0.08] bg-white/[0.02] text-secondary hover:bg-white/[0.06] hover:text-primary"),children:b.label},b.id)})})]}),e.jsxs("div",{children:[e.jsx("p",{className:"mb-1 text-micro font-semibold uppercase tracking-[0.08em] text-muted",children:"Type"}),e.jsx("div",{className:"grid grid-cols-2 gap-1",children:Object.keys(qn).map(b=>{const P=X===b;return e.jsx("button",{type:"button",onClick:()=>{le(b),ie(!1)},className:de("rounded-lg border px-2 py-1.5 text-caption font-medium transition-colors",P?"border-lime/30 bg-lime/[0.12] text-[#E1FFB2]":"border-white/[0.08] bg-white/[0.02] text-secondary hover:bg-white/[0.06] hover:text-primary"),children:qn[b]},b)})})]}),e.jsxs("div",{children:[e.jsx("p",{className:"mb-1 text-micro font-semibold uppercase tracking-[0.08em] text-muted",children:"Signal"}),e.jsx("button",{type:"button",onClick:()=>{ne(b=>!b)},className:de("w-full rounded-lg border px-2.5 py-2 text-left text-caption transition-colors",Q?"border-lime/30 bg-lime/[0.12] text-[#E1FFB2]":"border-white/[0.08] bg-white/[0.02] text-secondary hover:bg-white/[0.06] hover:text-primary"),children:Q?"Hide sync replay events":"Show sync replay events"}),e.jsx("p",{className:"mt-1 text-micro leading-relaxed text-muted",children:"Changeset replay and outbox sync events are low-signal operational noise for most users."})]})]})})})]})]})]}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-2.5",children:[e.jsx("div",{className:"flex flex-wrap items-center gap-1.5",children:(xt||l||h)&&e.jsxs(e.Fragment,{children:[xt&&e.jsxs("button",{onClick:j,className:"chip inline-flex min-w-0 items-center gap-2","aria-label":"Clear session filter",children:[e.jsx(dt,{name:(Zt==null?void 0:Zt.agentName)??"OrgX",hint:o??null,size:"xs"}),e.jsxs("span",{className:"min-w-0 truncate",children:["Session",o?`: ${o}`:""]}),e.jsx("span",{className:"ml-1 inline-flex h-4 w-4 items-center justify-center rounded-full border border-strong bg-white/[0.04] text-micro text-secondary",children:"×"})]}),l&&e.jsxs("button",{onClick:w,className:"chip inline-flex min-w-0 items-center gap-2",style:{borderColor:"rgba(191,255,0,0.28)",color:"#D8FFA1"},"aria-label":"Clear workstream filter",children:[e.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center rounded-full border border-strong bg-white/[0.04] text-micro",children:"↳"}),e.jsxs("span",{className:"min-w-0 truncate",children:["Workstream",c?`: ${c}`:""]}),e.jsx("span",{className:"ml-1 inline-flex h-4 w-4 items-center justify-center rounded-full border border-strong bg-white/[0.04] text-micro text-secondary",children:"×"})]}),h&&e.jsxs("button",{onClick:E,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(dt,{name:h,hint:h,size:"xs"}),e.jsxs("span",{className:"min-w-0 truncate",children:["Agent: ",h]}),e.jsx("span",{className:"ml-1 inline-flex h-4 w-4 items-center justify-center rounded-full border border-strong bg-white/[0.04] text-micro text-secondary",children:"×"})]})]})}),e.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:justify-end",children:e.jsxs("div",{className:"relative min-w-0 flex-1 sm:max-w-[360px]",children:[e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"pointer-events-none absolute left-2.5 top-1/2 -translate-y-1/2 text-muted",children:[e.jsx("circle",{cx:"11",cy:"11",r:"7"}),e.jsx("path",{d:"m20 20-3.5-3.5"})]}),e.jsx("input",{value:L,onChange:b=>C(b.target.value),placeholder:"Search activity...",className:"w-full rounded-lg border border-white/[0.08] bg-white/[0.03] py-2 pl-9 pr-2 text-body text-primary placeholder:text-muted transition-colors focus:border-[#BFFF00]/30 focus:outline-none","aria-label":"Search activity"})]})})]})]})}),e.jsxs("div",{ref:pt,className:"flex-1 overflow-y-auto scroll-smooth px-4 py-3",children:[He.length===0&&e.jsx("div",{className:"rounded-xl border border-subtle bg-white/[0.02] px-4 py-5",children:e.jsxs("div",{className:"mx-auto max-w-2xl",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"mt-0.5 inline-flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-full border border-white/[0.1] bg-white/[0.04] text-secondary",children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("polyline",{points:"22 12 18 12 15 21 9 3 6 12 2 12"})})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-body font-semibold text-primary",children:O?"Syncing activity feed...":xt?"No activity yet for this session":l?"No activity yet for this workstream":"No matching activity right now."}),e.jsx("p",{className:"mt-1 text-caption leading-relaxed text-secondary",children:O?"Live updates usually appear within a few seconds after dispatch.":`Try widening the time window (${z.label}), changing filters, or launch the next workstream.`})]})]}),e.jsx("div",{className:"mt-3 flex flex-wrap items-center gap-1.5",children:Mn.map(b=>{const P=x===b.id;return e.jsx("button",{type:"button",onClick:()=>d==null?void 0:d(b.id),className:de("rounded-full border px-2.5 py-1 text-caption font-semibold transition-colors",P?"border-lime/30 bg-lime/[0.12] text-[#E1FFB2]":"border-white/[0.1] bg-white/[0.03] text-secondary hover:bg-white/[0.08] hover:text-primary"),children:b.label},`empty-time-${b.id}`)})}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[(xt||l||h)&&e.jsx("button",{type:"button",onClick:()=>{xt&&j(),l&&(w==null||w()),h&&(E==null||E())},className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-primary transition hover:bg-white/[0.08]",children:"Clear filters"}),y&&e.jsx("button",{type:"button",onClick:()=>void it("play",y),disabled:tt!==null,className:"rounded-full border border-[#BFFF00]/28 bg-[#BFFF00]/12 px-3 py-1.5 text-caption font-semibold text-[#D8FFA1] transition hover:bg-[#BFFF00]/18 disabled:opacity-45",children:tt==="play"?"Dispatching...":"Play Next Up"}),A&&e.jsx("button",{type:"button",onClick:()=>void it("autopilot",A),disabled:tt!==null,className:"rounded-full border border-[#0AD4C4]/30 bg-[#0AD4C4]/10 px-3 py-1.5 text-caption font-semibold text-[#98FFF5] transition hover:bg-[#0AD4C4]/16 disabled:opacity-45",children:tt==="autopilot"?"Starting...":"Start Autopilot"}),k&&e.jsx("button",{type:"button",onClick:k,className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-primary transition hover:bg-white/[0.08]",children:"Create initiative"}),D&&e.jsx("button",{type:"button",onClick:D,className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-secondary transition hover:bg-white/[0.08] hover:text-primary",children:"Open Mission Control"})]}),Ue&&e.jsx("p",{className:"mt-2 text-caption text-amber-200/80",children:Ue})]})}),He.length>0&&e.jsxs("div",{className:"space-y-4",children:[un.map(b=>{const P=te?b.clusters.slice(0,4):b.clusters;return e.jsxs("section",{children:[e.jsx("h3",{className:"mb-2.5 border-b border-subtle pb-1.5 text-caption font-semibold tracking-[0.01em] text-muted",children:b.label}),Qs?e.jsx(yt,{mode:"popLayout",children:e.jsx("div",{className:"space-y-2",children:P.map((T,K)=>{const Me=S.has(T.key),Pe=T.allItems.slice(1),Ee=Pe.length,at=Math.min(Ee,R[T.key]??vn),_t=Pe.slice(0,at);if(T.count===1)return sn(T.representative,K);const We=`cluster:${T.key}`;return e.jsxs("div",{children:[sn(T.representative,K,We),e.jsxs("button",{type:"button",onClick:$e=>{$e.stopPropagation(),Fn(T.key)},className:"mt-1 ml-8 inline-flex items-center gap-1.5 rounded-full border border-white/[0.1] bg-white/[0.03] px-2.5 py-1 text-micro text-secondary transition-colors hover:bg-white/[0.06] hover:text-primary",children:[e.jsxs("span",{className:"font-semibold",children:["×",T.count]}),e.jsx("span",{className:"text-muted",children:"·"}),e.jsxs("span",{children:["first seen ",Ge(T.firstTimestamp)]}),e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:de("transition-transform",Me?"rotate-0":"-rotate-90"),children:e.jsx("path",{d:"m6 9 6 6 6-6"})})]}),Me&&e.jsxs("div",{className:"ml-8 mt-1 space-y-1.5 border-l border-subtle pl-3",children:[_t.map(($e,At)=>sn($e,K+At+1)),at<Ee&&e.jsxs("button",{type:"button",onClick:$e=>{$e.stopPropagation(),$n(T.key,Ee)},className:"rounded-full border border-strong bg-white/[0.03] px-2.5 py-1 text-micro text-secondary transition-colors hover:bg-white/[0.06] hover:text-primary",children:["Load more (",Ee-at," remaining)"]})]})]},T.key)})})}):e.jsx("div",{className:"space-y-2",children:P.map((T,K)=>{const Me=S.has(T.key),Pe=T.allItems.slice(1),Ee=Pe.length,at=Math.min(Ee,R[T.key]??vn),_t=Pe.slice(0,at);if(T.count===1)return sn(T.representative,K);const We=`cluster:${T.key}`;return e.jsxs("div",{children:[sn(T.representative,K,We),e.jsxs("button",{type:"button",onClick:$e=>{$e.stopPropagation(),Fn(T.key)},className:"mt-1 ml-8 inline-flex items-center gap-1.5 rounded-full border border-white/[0.1] bg-white/[0.03] px-2.5 py-1 text-micro text-secondary transition-colors hover:bg-white/[0.06] hover:text-primary",children:[e.jsxs("span",{className:"font-semibold",children:["×",T.count]}),e.jsx("span",{className:"text-muted",children:"·"}),e.jsxs("span",{children:["first seen ",Ge(T.firstTimestamp)]}),e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:de("transition-transform",Me?"rotate-0":"-rotate-90"),children:e.jsx("path",{d:"m6 9 6 6 6-6"})})]}),Me&&e.jsxs("div",{className:"ml-8 mt-1 space-y-1.5 border-l border-subtle pl-3",children:[_t.map(($e,At)=>sn($e,K+At+1)),at<Ee&&e.jsxs("button",{type:"button",onClick:$e=>{$e.stopPropagation(),$n(T.key,Ee)},className:"rounded-full border border-strong bg-white/[0.03] px-2.5 py-1 text-micro text-secondary transition-colors hover:bg-white/[0.06] hover:text-primary",children:["Load more (",Ee-at," remaining)"]})]})]},T.key)})}),te&&b.clusters.length>P.length&&e.jsxs("p",{className:"mt-1.5 text-caption text-muted",children:["+",b.clusters.length-P.length," more"]})]},b.key)}),dn>0&&e.jsxs("p",{className:"rounded-xl border border-subtle bg-white/[0.02] px-3 py-2 text-caption text-secondary",children:["Showing ",He.length,"/",Ft," matched events (load more to see older)."]}),e.jsx("div",{ref:St,className:"h-6"}),(u||p)&&e.jsx("div",{className:"flex items-center justify-center",children:e.jsx("button",{type:"button",onClick:()=>m==null?void 0:m(),disabled:!u||p,className:"rounded-full border border-strong bg-white/[0.03] px-4 py-2 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:p?"Loading older…":"Load older"})})]})]})]}),e.jsx(kt,{open:B!==null,onClose:Ae,maxWidth:"max-w-3xl",children:B&&e.jsxs("div",{className:"relative flex h-[100dvh] w-full min-h-0 flex-col sm:h-[86vh] sm:max-h-[86vh]",children:[e.jsx("div",{className:"absolute inset-x-0 top-0 h-20 bg-gradient-to-b from-lime/10 via-cyan/5 to-transparent"}),e.jsxs("div",{className:"relative z-10 flex items-center justify-between border-b border-subtle px-5 py-3 sm:px-6",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("span",{className:"h-2.5 w-2.5 flex-shrink-0 rounded-full",style:{backgroundColor:jn(B.bucket),boxShadow:`0 0 12px ${jn(B.bucket)}55`}}),e.jsxs("span",{className:"text-caption text-secondary",children:[Ms(B.bucket)," · ",$t+1,"/",He.length]}),et&&e.jsx(Tt,{tone:"neutral",className:"text-micro font-semibold tracking-[0.02em]",children:et})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[B.runId&&v&&e.jsx("button",{type:"button",onClick:()=>{v(B.runId),Ae()},className:"rounded-full border border-lime/25 bg-lime/10 px-3 py-1 text-caption font-semibold text-lime transition hover:bg-lime/20",children:"Focus session"}),e.jsx("button",{type:"button",onClick:()=>ht(-1),className:"inline-flex h-8 w-8 items-center justify-center rounded-full border border-strong bg-white/[0.04] text-primary transition hover:bg-white/[0.1]","aria-label":"Previous activity item",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"m15 18-6-6 6-6"})})}),e.jsx("button",{type:"button",onClick:()=>ht(1),className:"inline-flex h-8 w-8 items-center justify-center rounded-full border border-strong bg-white/[0.04] text-primary transition hover:bg-white/[0.1]","aria-label":"Next activity item",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"m9 18 6-6-6-6"})})}),e.jsxs("div",{className:"relative",children:[e.jsx("button",{type:"button",onClick:()=>Z(b=>!b),className:"inline-flex h-8 w-8 items-center justify-center rounded-full border border-strong bg-white/[0.04] text-secondary transition hover:bg-white/[0.1] hover:text-primary","aria-label":"More actions",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"currentColor",children:[e.jsx("circle",{cx:"12",cy:"5",r:"1.5"}),e.jsx("circle",{cx:"12",cy:"12",r:"1.5"}),e.jsx("circle",{cx:"12",cy:"19",r:"1.5"})]})}),F&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-30",onClick:()=>Z(!1)}),e.jsxs("div",{className:"absolute right-0 top-full z-40 mt-1 min-w-[160px] rounded-lg border border-strong bg-[#0d0f16] py-1 shadow-xl",children:[B.runId&&e.jsx("button",{type:"button",onClick:()=>{rt("Run id",B.runId??""),Z(!1)},className:"flex w-full items-center gap-2 px-3 py-1.5 text-caption text-secondary transition-colors hover:bg-white/[0.06] hover:text-primary",children:"Copy run ID"}),g.agentId&&e.jsx("button",{type:"button",onClick:()=>{rt("Agent id",g.agentId??""),Z(!1)},className:"flex w-full items-center gap-2 px-3 py-1.5 text-caption text-secondary transition-colors hover:bg-white/[0.06] hover:text-primary",children:"Copy agent ID"}),e.jsx("button",{type:"button",onClick:()=>{rt("Event id",B.item.id),Z(!1)},className:"flex w-full items-center gap-2 px-3 py-1.5 text-caption text-secondary transition-colors hover:bg-white/[0.06] hover:text-primary",children:"Copy event ID"})]})]})]}),e.jsx("button",{type:"button",onClick:Ae,className:"inline-flex h-8 w-8 items-center justify-center rounded-full border border-strong bg-white/[0.04] text-secondary transition hover:bg-white/[0.1] hover:text-primary","aria-label":"Close activity detail",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 6L6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})})]})]}),e.jsx("div",{className:"relative min-h-0 flex-1 overflow-x-hidden overflow-y-auto px-5 pb-5 pt-4 sm:px-6",children:e.jsx(yt,{mode:"wait",custom:ae,children:e.jsx(we.section,{custom:ae,initial:{opacity:0,x:ae*44,scale:.985},animate:{opacity:1,x:0,scale:1},exit:{opacity:0,x:ae*-32,scale:.985},transition:{duration:.28,ease:[.16,1,.3,1]},className:"min-h-full w-full overscroll-contain",children:e.jsxs("div",{className:"space-y-4 pb-1",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-title font-semibold tracking-[-0.02em] text-white whitespace-pre-wrap break-words",children:Re||$l(B.item,q)||De(B.item.title||ln(B.item.type))}),e.jsxs("p",{className:"mt-1 flex flex-wrap items-center gap-x-2 text-body text-secondary",children:[new Date(B.item.timestamp).toLocaleString()," · ",Ge(B.item.timestamp),ge==="llm"&&e.jsx("span",{className:"text-muted",children:"· AI title"})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-caption",children:[e.jsx(Tt,{tone:"neutral",className:"font-semibold tracking-[0.02em]",style:{borderColor:`${jn(B.bucket)}55`,color:jn(B.bucket),backgroundColor:`${jn(B.bucket)}12`},children:Ms(B.bucket)}),e.jsx(Tt,{tone:"muted",children:ln(B.item.type)}),Ye&&e.jsx(Tt,{tone:"lime",children:"Sync replay"}),(be==null?void 0:be.mode)==="handoff"&&be.requester&&be.executor&&e.jsxs(Tt,{tone:"cyan",children:[e.jsx(dt,{name:be.requester.label,hint:qt(be.requester),size:"xs"}),e.jsx("span",{className:"text-micro text-cyan-100/80",children:"→"}),e.jsx(dt,{name:be.executor.label,hint:qt(be.executor),size:"xs"})]}),(be==null?void 0:be.mode)!=="handoff"&&en&&e.jsxs(Tt,{tone:"muted",children:[e.jsx(dt,{name:en.label,hint:qt(en),size:"xs"}),e.jsx("span",{children:en.label})]}),B.runId&&e.jsx(Tt,{tone:"muted",children:ce.get(B.runId)??De(B.runId)})]}),e.jsxs("div",{className:"inline-flex rounded-full border border-white/[0.12] bg-white/[0.03] p-1 text-caption",children:[e.jsx("button",{type:"button",onClick:()=>Qe("overview"),"aria-pressed":_e==="overview",className:de("rounded-full px-2.5 py-1 font-semibold transition-colors",_e==="overview"?"bg-white/[0.14] text-primary":"text-secondary hover:text-primary"),children:"Overview"}),e.jsx("button",{type:"button",onClick:()=>Qe("flow"),"aria-pressed":_e==="flow",className:de("rounded-full px-2.5 py-1 font-semibold transition-colors",_e==="flow"?"bg-cyan-500/[0.16] text-cyan-100":"text-secondary hover:text-primary"),children:"Flow"}),e.jsx("button",{type:"button",onClick:()=>Qe("technical"),"aria-pressed":_e==="technical",className:de("rounded-full px-2.5 py-1 font-semibold transition-colors",_e==="technical"?"bg-lime/[0.16] text-[#E1FFB2]":"text-secondary hover:text-primary"),children:"Technical"})]}),_e==="overview"&&Ct&&e.jsxs("div",{className:de("rounded-xl border px-3.5 py-3",Ct.tone==="critical"&&"border-red-400/28 bg-red-500/[0.09]",Ct.tone==="warning"&&"border-amber-400/28 bg-amber-500/[0.09]",Ct.tone==="positive"&&"border-lime/28 bg-lime/[0.08]",Ct.tone==="neutral"&&"border-cyan-400/22 bg-cyan-500/[0.07]"),children:[e.jsx("p",{className:"text-micro font-semibold uppercase tracking-[0.08em] text-white/78",children:Ct.label}),e.jsx("p",{className:"mt-1 text-body text-primary",children:Ct.summary}),Ct.hint&&e.jsx("p",{className:"mt-1 text-caption text-secondary",children:Ct.hint}),e.jsxs("div",{className:"mt-2 flex flex-wrap gap-2",children:[B.runId&&v&&e.jsx("button",{type:"button",onClick:()=>{v(B.runId),Ae()},className:"rounded-full border border-strong bg-white/[0.04] px-3 py-1 text-caption font-semibold text-primary transition hover:bg-white/[0.1]",children:"Open session"}),pn&&e.jsx("button",{type:"button",onClick:()=>ee(pn),className:"rounded-full border border-cyan-300/25 bg-cyan-500/[0.1] px-3 py-1 text-caption font-semibold text-cyan-100 transition hover:bg-cyan-500/[0.16]",children:"View artifact"}),me&&e.jsx("a",{href:me,target:"_blank",rel:"noopener noreferrer",className:"rounded-full border border-strong bg-white/[0.04] px-3 py-1 text-caption font-semibold text-primary transition hover:bg-white/[0.1]",children:"Open evidence"})]})]}),_e==="flow"&&be&&e.jsxs("div",{className:"rounded-xl border border-cyan-300/24 bg-cyan-500/[0.07] p-3",children:[e.jsx("p",{className:"text-caption font-semibold tracking-[0.02em] text-cyan-100/85",children:"Delegation flow"}),e.jsxs("div",{className:"mt-2 grid grid-cols-1 gap-2 sm:grid-cols-3",children:[e.jsxs("div",{className:"rounded-lg border border-white/[0.10] bg-black/20 px-3 py-2",children:[e.jsx("div",{className:"text-micro font-semibold tracking-[0.02em] text-secondary",children:"Requester"}),e.jsx("div",{className:"mt-1 flex items-center gap-2 text-body text-primary",children:be.requester?e.jsxs(e.Fragment,{children:[e.jsx(dt,{name:be.requester.label,hint:qt(be.requester),size:"xs"}),e.jsx("span",{children:be.requester.label})]}):e.jsx("span",{className:"text-secondary",children:"System / unknown"})})]}),e.jsxs("div",{className:"rounded-lg border border-white/[0.10] bg-black/20 px-3 py-2",children:[e.jsx("div",{className:"text-micro font-semibold tracking-[0.02em] text-secondary",children:"Flow"}),e.jsx("p",{className:"mt-1 text-body text-primary",children:be.mode==="handoff"?"Delegated handoff":be.mode==="requested"?"Dispatch requested":be.mode==="single"?"Direct execution":"System event"}),e.jsx("p",{className:"mt-1 text-caption text-secondary",children:be.subtitle})]}),e.jsxs("div",{className:"rounded-lg border border-white/[0.10] bg-black/20 px-3 py-2",children:[e.jsx("div",{className:"text-micro font-semibold tracking-[0.02em] text-secondary",children:"Executor"}),e.jsx("div",{className:"mt-1 flex items-center gap-2 text-body text-primary",children:be.executor?e.jsxs(e.Fragment,{children:[e.jsx(dt,{name:be.executor.label,hint:qt(be.executor),size:"xs"}),e.jsx("span",{children:be.executor.label})]}):e.jsx("span",{className:"text-secondary",children:"Not assigned"})})]})]})]}),_e==="flow"&&Ne&&e.jsxs("div",{className:"rounded-xl border border-lime/20 bg-lime/[0.08] p-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("p",{className:"text-caption font-semibold tracking-[0.02em] text-lime/80",children:ct?"Related execution context":"Execution context"}),e.jsx("span",{className:"rounded-full border border-lime/30 bg-black/20 px-2 py-0.5 text-micro font-semibold text-lime/85",children:De(Ne.event)})]}),ct&&e.jsxs("p",{className:"mt-1 text-micro text-lime/70",children:["Derived from nearest related slice event (",De(ct.relation),")."]}),vt&&e.jsxs("div",{className:"mt-3 rounded-lg border border-white/[0.10] bg-black/20 px-3 py-2.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-micro font-semibold tracking-[0.02em] text-secondary",children:"Slice progress"}),e.jsxs("p",{className:"text-body font-semibold tabular-nums",style:{color:fn},children:[vt.pct,"%"]})]}),e.jsx("div",{className:"mt-2 h-1.5 overflow-hidden rounded-full bg-white/[0.10]",children:e.jsx("div",{className:"h-full rounded-full transition-[width] duration-300",style:{width:`${Math.max(4,vt.pct)}%`,backgroundColor:fn}})}),e.jsx("p",{className:"mt-1 text-micro text-secondary",children:vt.label})]}),e.jsxs("div",{className:"mt-3 grid grid-cols-1 gap-2 sm:grid-cols-2",children:[e.jsxs("div",{className:"rounded-lg border border-white/[0.10] bg-black/20 px-3 py-2",children:[e.jsx("div",{className:"text-micro font-semibold tracking-[0.02em] text-secondary",children:"Requested by"}),e.jsx("div",{className:"mt-1 text-body text-primary",children:ls})]}),e.jsxs("div",{className:"rounded-lg border border-white/[0.10] bg-black/20 px-3 py-2",children:[e.jsx("div",{className:"text-micro font-semibold tracking-[0.02em] text-secondary",children:"Executed by"}),e.jsx("div",{className:"mt-1 text-body text-primary",children:cs})]}),e.jsxs("div",{className:"rounded-lg border border-white/[0.10] bg-black/20 px-3 py-2",children:[e.jsx("div",{className:"text-micro font-semibold tracking-[0.02em] text-secondary",children:"Dispatched by"}),e.jsx("div",{className:"mt-1 text-body text-primary",children:Ne.dispatcherClient?De(Ne.dispatcherClient):"OpenClaw"})]}),e.jsxs("div",{className:"rounded-lg border border-white/[0.10] bg-black/20 px-3 py-2",children:[e.jsx("div",{className:"text-micro font-semibold tracking-[0.02em] text-secondary",children:"Policy"}),e.jsxs("div",{className:"mt-1 text-body text-primary",children:[Ne.domain??"—",Ne.requiredSkills.length>0?` · ${Ne.requiredSkills.join(", ")}`:""]})]})]}),re&&e.jsxs("div",{className:"mt-3 grid grid-cols-1 gap-2 sm:grid-cols-2",children:[e.jsxs("div",{className:"rounded-lg border border-white/[0.10] bg-black/20 px-3 py-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"text-micro font-semibold tracking-[0.02em] text-secondary",children:"Initiative"}),re.initiativeStatus&&e.jsx("span",{className:"rounded-full border border-strong bg-white/[0.03] px-2 py-0.5 text-micro text-secondary",children:De(re.initiativeStatus)})]}),e.jsx("p",{className:"mt-1 text-body text-primary",children:re.initiativeTitle??re.initiativeId??"—"}),re.initiativeId&&e.jsx("p",{className:"mt-1 break-all font-mono text-micro text-secondary",children:re.initiativeId}),re.initiativeWorkstreamPct!==null&&e.jsxs("div",{className:"mt-2",children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between text-micro text-secondary",children:[e.jsx("span",{children:"Workstreams complete"}),e.jsxs("span",{className:"tabular-nums",children:[re.doneInitiativeWorkstreams??0,"/",re.totalInitiativeWorkstreams??0]})]}),e.jsx("div",{className:"h-1.5 overflow-hidden rounded-full bg-white/[0.10]",children:e.jsx("div",{className:"h-full rounded-full bg-[#BFFF00]/80",style:{width:`${Math.max(4,re.initiativeWorkstreamPct)}%`}})})]})]}),e.jsxs("div",{className:"rounded-lg border border-white/[0.10] bg-black/20 px-3 py-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"text-micro font-semibold tracking-[0.02em] text-secondary",children:"Workstream"}),re.workstreamStatus&&e.jsx("span",{className:"rounded-full border border-strong bg-white/[0.03] px-2 py-0.5 text-micro text-secondary",children:De(re.workstreamStatus)})]}),e.jsx("p",{className:"mt-1 text-body text-primary",children:re.workstreamTitle??re.workstreamId??"—"}),re.workstreamId&&e.jsx("p",{className:"mt-1 break-all font-mono text-micro text-secondary",children:re.workstreamId})]}),e.jsxs("div",{className:"rounded-lg border border-white/[0.10] bg-black/20 px-3 py-2",children:[e.jsx("div",{className:"text-micro font-semibold tracking-[0.02em] text-secondary",children:"Completion breakdown"}),e.jsxs("div",{className:"mt-2 grid grid-cols-2 gap-2 text-caption text-primary",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-micro text-secondary",children:"Tasks in slice"}),e.jsx("div",{className:"mt-0.5 tabular-nums",children:re.scopedTaskCount})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-micro text-secondary",children:"Milestones in slice"}),e.jsx("div",{className:"mt-0.5 tabular-nums",children:re.scopedMilestoneCount})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-micro text-secondary",children:"Status updates"}),e.jsx("div",{className:"mt-0.5 tabular-nums",children:re.statusUpdatesApplied??"—"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-micro text-secondary",children:"Buffered updates"}),e.jsx("div",{className:"mt-0.5 tabular-nums",children:re.statusUpdatesBuffered??0})]})]})]}),e.jsxs("div",{className:"rounded-lg border border-white/[0.10] bg-black/20 px-3 py-2",children:[e.jsx("div",{className:"text-micro font-semibold tracking-[0.02em] text-secondary",children:"Outputs"}),e.jsxs("div",{className:"mt-2 grid grid-cols-2 gap-2 text-caption text-primary",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-micro text-secondary",children:"Artifacts"}),e.jsx("div",{className:"mt-0.5 tabular-nums",children:re.artifacts??0})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-micro text-secondary",children:"Decisions"}),e.jsx("div",{className:"mt-0.5 tabular-nums",children:re.decisions??0})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-micro text-secondary",children:"Blocking decisions"}),e.jsx("div",{className:"mt-0.5 tabular-nums",children:re.blockingDecisions??0})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-micro text-secondary",children:"Non-blocking decisions"}),e.jsx("div",{className:"mt-0.5 tabular-nums",children:re.nonBlockingDecisions??0})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx("div",{className:"text-micro text-secondary",children:"Token usage"}),e.jsx("div",{className:"mt-0.5 tabular-nums",children:re.tokensUsed!==null&&re.tokenBudget!==null?`${Math.round(re.tokensUsed)}/${Math.round(re.tokenBudget)}`:"—"})]})]})]})]}),((re==null?void 0:re.taskTitle)||(re==null?void 0:re.milestoneTitle)||(re==null?void 0:re.phase)||(re==null?void 0:re.nextStep)||(re==null?void 0:re.parsedStatus)||(re==null?void 0:re.stopReason))&&e.jsxs("div",{className:"mt-3 rounded-lg border border-white/[0.10] bg-black/20 px-3 py-2",children:[e.jsx("div",{className:"text-micro font-semibold tracking-[0.02em] text-secondary",children:"Current scope"}),e.jsxs("div",{className:"mt-1.5 space-y-1 text-caption text-primary",children:[re.taskTitle&&e.jsxs("p",{children:[e.jsx("span",{className:"text-secondary",children:"Task:"})," ",re.taskTitle]}),re.milestoneTitle&&e.jsxs("p",{children:[e.jsx("span",{className:"text-secondary",children:"Milestone:"})," ",re.milestoneTitle]}),re.phase&&e.jsxs("p",{children:[e.jsx("span",{className:"text-secondary",children:"Phase:"})," ",De(re.phase)]}),re.nextStep&&e.jsxs("p",{children:[e.jsx("span",{className:"text-secondary",children:"Next step:"})," ",re.nextStep]}),re.parsedStatus&&e.jsxs("p",{children:[e.jsx("span",{className:"text-secondary",children:"Slice status:"})," ",De(re.parsedStatus)]}),re.stopReason&&e.jsxs("p",{children:[e.jsx("span",{className:"text-secondary",children:"Stop reason:"})," ",De(re.stopReason)]})]})]}),(Ne.logPath||Ne.outputPath)&&e.jsxs("div",{className:"mt-3 space-y-2 rounded-lg border border-white/[0.10] bg-black/20 px-3 py-2",children:[Ne.logPath&&e.jsxs("p",{className:"break-all font-mono text-caption text-secondary",children:["log: ",Ne.logPath]}),Ne.outputPath&&e.jsxs("p",{className:"break-all font-mono text-caption text-secondary",children:["output: ",Ne.outputPath]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[Ne.logPath&&e.jsx("button",{type:"button",onClick:()=>void rt("Log path",Ne.logPath??""),className:"rounded-full border border-strong bg-white/[0.04] px-3 py-1 text-caption text-primary transition hover:bg-white/[0.1]",children:"Copy log path"}),Ne.outputPath&&e.jsx("button",{type:"button",onClick:()=>void rt("Output path",Ne.outputPath??""),className:"rounded-full border border-strong bg-white/[0.04] px-3 py-1 text-caption text-primary transition hover:bg-white/[0.1]",children:"Copy output path"})]})]}),Ne.error&&e.jsx("div",{className:"mt-3 rounded-lg border border-red-400/20 bg-red-500/10 px-3 py-2 text-body text-red-100/80",children:Ne.error})]}),_e==="technical"&&Le&&e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.03] p-3",children:[e.jsx("p",{className:"text-caption font-semibold tracking-[0.02em] text-secondary",children:"Provenance"}),e.jsxs("div",{className:"mt-2 grid grid-cols-1 gap-2 sm:grid-cols-2",children:[Le.domain&&e.jsxs("div",{className:"rounded-lg border border-white/[0.10] bg-black/20 px-3 py-2",children:[e.jsx("div",{className:"text-micro font-semibold tracking-[0.02em] text-secondary",children:"Domain"}),e.jsx("div",{className:"mt-1 text-body text-primary",children:De(Le.domain)})]}),(Le.provider||Le.model)&&e.jsxs("div",{className:"rounded-lg border border-white/[0.10] bg-black/20 px-3 py-2",children:[e.jsx("div",{className:"text-micro font-semibold tracking-[0.02em] text-secondary",children:"Model"}),e.jsxs("div",{className:"mt-1 text-body text-primary",children:[Le.provider?`${De(Le.provider)} · `:"",Le.model?Cn(Le.model):"—"]})]}),Le.modelTier&&e.jsxs("div",{className:"rounded-lg border border-white/[0.10] bg-black/20 px-3 py-2",children:[e.jsx("div",{className:"text-micro font-semibold tracking-[0.02em] text-secondary",children:"Model tier"}),e.jsx("div",{className:"mt-1 text-body text-primary",children:De(Le.modelTier)})]}),Le.pluginVersion&&e.jsxs("div",{className:"rounded-lg border border-white/[0.10] bg-black/20 px-3 py-2",children:[e.jsx("div",{className:"text-micro font-semibold tracking-[0.02em] text-secondary",children:"Plugin"}),e.jsxs("div",{className:"mt-1 text-body text-primary",children:["v",Le.pluginVersion]})]}),Le.skillPack&&e.jsxs("div",{className:"rounded-lg border border-white/[0.10] bg-black/20 px-3 py-2 sm:col-span-2",children:[e.jsx("div",{className:"text-micro font-semibold tracking-[0.02em] text-secondary",children:"Skill pack"}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2 text-body text-primary",children:[e.jsxs("span",{children:[Le.skillPack.name??"—",Le.skillPack.version?`@${Le.skillPack.version}`:"",Le.skillPack.source?` · ${Le.skillPack.source}`:""]}),Le.skillPack.checksum&&e.jsxs("button",{type:"button",onClick:()=>{var b;return void rt("Skill pack checksum",((b=Le.skillPack)==null?void 0:b.checksum)??"")},className:"rounded-full border border-strong bg-white/[0.04] px-2.5 py-1 text-caption text-primary transition hover:bg-white/[0.1]",children:["sha ",Le.skillPack.checksum.slice(0,12),"…"]})]})]}),Le.kickoffContextHash&&e.jsxs("div",{className:"rounded-lg border border-white/[0.10] bg-black/20 px-3 py-2 sm:col-span-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"text-micro font-semibold tracking-[0.02em] text-secondary",children:"Kickoff context"}),e.jsx("button",{type:"button",onClick:()=>void rt("Kickoff context hash",Le.kickoffContextHash??""),className:"rounded-full border border-strong bg-white/[0.04] px-2.5 py-1 text-caption text-primary transition hover:bg-white/[0.1]",children:"Copy hash"})]}),e.jsxs("div",{className:"mt-1 text-body text-primary",children:[Le.kickoffContextSource?`${Le.kickoffContextSource} · `:"",e.jsx("span",{className:"font-mono text-body text-primary",children:Le.kickoffContextHash})]})]}),Le.requiredSkills.length>0&&e.jsxs("div",{className:"rounded-lg border border-white/[0.10] bg-black/20 px-3 py-2 sm:col-span-2",children:[e.jsx("div",{className:"text-micro font-semibold tracking-[0.02em] text-secondary",children:"Required skills"}),e.jsx("div",{className:"mt-1 flex flex-wrap gap-1.5",children:Le.requiredSkills.map(b=>e.jsx("span",{className:"rounded-full border border-strong bg-white/[0.03] px-2 py-0.5 text-caption text-secondary",children:b},b))})]})]})]}),_e==="overview"&&Se&&e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-black/20 p-3",children:[e.jsx("p",{className:"text-micro font-semibold tracking-[0.02em] text-secondary",children:"Summary"}),ue==="missing"&&!Ye&&e.jsx("p",{className:"mt-1 text-caption text-amber-200/75",children:"Full local turn transcript was unavailable; showing the event summary payload."}),e.jsx(cn,{mode:"block",text:Se,className:"mt-1.5 text-body leading-relaxed text-primary"})]}),_e==="overview"&&Lt(B.item.description)&&e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-black/15 p-3",children:[e.jsx("p",{className:"text-micro font-semibold tracking-[0.02em] text-secondary",children:"Details"}),e.jsx(cn,{mode:"block",text:Lt(B.item.description)??"",className:"mt-1.5 text-body leading-relaxed text-secondary"})]}),_e==="technical"&&_.length>0&&e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.03] p-3",children:[e.jsx("p",{className:"text-caption font-semibold tracking-[0.02em] text-secondary",children:"Filesystem evidence"}),e.jsx("div",{className:"mt-2 space-y-2",children:_.map((b,P)=>{const T=Or(b.path);return e.jsxs("div",{className:"rounded-lg border border-white/[0.10] bg-black/20 px-3 py-2",children:[e.jsx("p",{className:"text-micro font-semibold tracking-[0.02em] text-secondary",children:De(b.key)}),e.jsx("p",{className:"mt-1 break-all font-mono text-caption text-primary",children:b.path}),e.jsxs("div",{className:"mt-2 flex flex-wrap gap-2",children:[T?e.jsx("a",{href:T,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center rounded-full border border-[#BFFF00]/25 bg-[#BFFF00]/10 px-2.5 py-1 text-caption font-semibold text-[#D8FFA1] transition hover:bg-[#BFFF00]/18",children:"Open in tab"}):null,e.jsx("button",{type:"button",onClick:()=>void rt(`${De(b.key)} path`,b.path),className:"rounded-full border border-strong bg-white/[0.04] px-2.5 py-1 text-caption text-primary transition hover:bg-white/[0.1]",children:"Copy path"})]})]},`${b.key}:${b.path}:${P}`)})})]}),_e==="overview"&&B&&_s(B.item)&&e.jsxs("button",{type:"button",onClick:()=>{const b=_s(B.item);b&&ee(b)},className:"flex w-full items-center gap-2.5 rounded-xl border border-cyan-400/25 bg-cyan-500/[0.08] px-3.5 py-2.5 text-left transition-colors hover:bg-cyan-500/[0.14]",children:[e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:N.cyan,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"flex-shrink-0",children:[e.jsx("path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"}),e.jsx("path",{d:"M14 2v4a2 2 0 0 0 2 2h4"})]}),e.jsx("span",{className:"text-body font-medium",style:{color:N.cyan},children:"View registered artifact"})]}),_e==="technical"&&Wt&&e.jsxs("div",{className:"rounded-xl border border-cyan-400/20 bg-cyan-500/[0.06] p-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-caption font-semibold tracking-[0.02em] text-cyan-100/85",children:"Artifact output"}),e.jsxs("div",{className:"inline-flex rounded-full border border-strong bg-black/30 p-0.5 text-caption",children:[e.jsx("button",{type:"button",onClick:()=>Nt("structured"),"aria-pressed":mt==="structured",className:`rounded-full px-2.5 py-0.5 transition-colors ${mt==="structured"?"bg-white/[0.12] text-white":"text-secondary hover:text-primary"}`,children:"Structured"}),e.jsx("button",{type:"button",onClick:()=>Nt("json"),"aria-pressed":mt==="json",className:`rounded-full px-2.5 py-0.5 transition-colors ${mt==="json"?"bg-white/[0.12] text-white":"text-secondary hover:text-primary"}`,children:"JSON"})]})]}),e.jsxs("p",{className:"mt-1 text-micro text-cyan-100/55",children:["Source: ",Wt.source]}),e.jsx("div",{className:"mt-2",children:mt==="structured"?Mi(Wt.value):e.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap font-mono text-caption leading-relaxed text-primary",children:JSON.stringify(Wt.value,null,2)})})]}),_e==="technical"&&U&&U!==$&&e.jsxs("details",{className:"rounded-xl border border-white/[0.08] bg-black/35 p-3",children:[e.jsx("summary",{className:"cursor-pointer select-none text-caption font-semibold tracking-[0.02em] text-secondary",children:"Parsed metadata"}),e.jsx("pre",{className:"mt-2 overflow-x-auto whitespace-pre-wrap font-mono text-caption leading-relaxed text-secondary",children:U})]}),_e==="technical"&&$&&e.jsxs("details",{className:"rounded-xl border border-white/[0.08] bg-black/35 p-3",children:[e.jsx("summary",{className:"cursor-pointer select-none text-caption font-semibold tracking-[0.02em] text-secondary",children:"Raw metadata"}),e.jsx("pre",{className:"mt-2 overflow-x-auto whitespace-pre-wrap font-mono text-caption leading-relaxed text-secondary",children:$})]})]})},B.item.id)})}),e.jsx("div",{className:"border-t border-subtle px-5 py-2.5 text-caption text-muted sm:px-6",children:"Keyboard: ← previous · → next · Esc close"})]})})]})});function Ll(t){const n=Date.parse(t);if(!Number.isFinite(n))return null;const s=Date.now()-n,r=s<0,i=Math.abs(s),o=Math.round(i/6e4);if(o<1)return r?"soon":"just now";if(o<60)return r?`in ${o}m`:`${o}m ago`;const l=Math.round(i/36e5);if(l<48)return r?`in ${l}h`:`${l}h ago`;const c=Math.round(i/864e5);return c<30?r?`in ${c}d`:`${c}d ago`:new Date(n).toLocaleDateString()}async function Wr(t,n){const s=await fetch(t,n);if(!s.ok){const r=await s.json().catch(()=>null),i=typeof(r==null?void 0:r.error)=="string"&&r.error||typeof(r==null?void 0:r.message)=="string"&&r.message||`Request failed (${s.status})`;throw new Error(i)}return await s.json()}function Pl(t){const{entityType:n,entityId:s,authToken:r,embedMode:i,className:o}=t,[l,c]=a.useState(!0),[h,x]=a.useState(!1),[d,u]=a.useState(null),[p,m]=a.useState([]),[j,w]=a.useState(""),E=a.useMemo(()=>{const k=encodeURIComponent(n),D=encodeURIComponent(s);return`/orgx/api/entities/${k}/${D}/comments`},[n,s]),v=a.useCallback(async()=>{c(!0),u(null);try{const k=await Wr(E,{method:"GET",headers:ut({authToken:r,embedMode:i})});m(Array.isArray(k.comments)?k.comments:[])}catch(k){u(k instanceof Error?k.message:String(k))}finally{c(!1)}},[r,i,E]);a.useEffect(()=>{v()},[v]);const y=a.useCallback(async()=>{const k=j.trim();if(k){x(!0),u(null);try{await Wr(E,{method:"POST",headers:ut({authToken:r,embedMode:i,contentTypeJson:!0}),body:JSON.stringify({body:k,commentType:"note",severity:"info",tags:[]})}),w(""),await v()}catch(D){u(D instanceof Error?D.message:String(D))}finally{x(!1)}}},[r,j,i,E,v]),A=a.useCallback(k=>{k.key==="Enter"&&(!k.metaKey&&!k.ctrlKey||(k.preventDefault(),y()))},[y]);return e.jsxs("div",{className:o,children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("textarea",{value:j,onChange:k=>w(k.target.value),onKeyDown:A,placeholder:"Leave a note for humans or agents...",className:"min-h-[96px] w-full resize-y rounded-xl border border-white/[0.10] bg-white/[0.03] px-4 py-3 text-body text-bright outline-none placeholder:text-faint focus:border-white/20 focus:bg-white/[0.05] transition-colors"}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx("p",{className:"text-caption text-muted",children:"Visible to agents and collaborators. Tip: Cmd/Ctrl+Enter to post."}),e.jsx("button",{type:"button",onClick:y,disabled:h||j.trim().length===0,className:"inline-flex items-center justify-center rounded-full border border-strong bg-white/[0.05] px-3.5 py-1.5 text-caption font-semibold tracking-wide text-primary transition-colors hover:bg-white/[0.09] disabled:opacity-50 disabled:hover:bg-white/[0.05]",children:h?"Saving…":"Post note"})]})]}),d?e.jsx("div",{className:"mt-3 rounded-xl border border-red-500/20 bg-red-500/10 px-3.5 py-2 text-body text-red-200",children:d}):null,l?e.jsx("div",{className:"mt-3 text-body text-muted",children:"Loading notes…"}):p.length===0?e.jsx("div",{className:"mt-3 text-body text-muted",children:"No notes yet."}):e.jsx("div",{className:"mt-3 space-y-3",children:p.map(k=>{const D=k.created_at?Ll(k.created_at):null,O=k.author_name??(k.author_type==="agent"?k.author_id:"Unknown"),I=k.comment_type??"note",ee=typeof k.severity=="string"?k.severity:"info";return e.jsxs("div",{className:"rounded-2xl border border-white/[0.10] bg-white/[0.02] px-4 py-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"text-body font-semibold text-bright",children:O}),e.jsx("span",{className:"rounded-full border border-strong bg-white/[0.06] px-2 py-0.5 text-micro uppercase tracking-[0.08em] text-secondary",children:k.author_type}),e.jsx("span",{className:"rounded-full border border-strong px-2 py-0.5 text-micro uppercase tracking-[0.08em] text-secondary",children:I}),ee!=="info"?e.jsx("span",{className:"rounded-full border border-strong px-2 py-0.5 text-micro uppercase tracking-[0.08em] text-secondary",children:ee}):null]}),D?e.jsx("span",{className:"text-caption text-muted",title:Yt(k.created_at),children:D}):null]}),e.jsx("p",{className:"mt-2 whitespace-pre-wrap text-body leading-relaxed text-primary",children:k.body})]},k.id)})})]})}const Dl=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent);function Bl(t){try{return JSON.stringify(t,null,2)}catch{return null}}function Rl({open:t,decision:n,onClose:s,onApprove:r,onReject:i}){const[o,l]=a.useState("idle"),[c,h]=a.useState(null),[x,d]=a.useState(null),[u,p]=a.useState(""),[m,j]=a.useState(!1),[w,E]=a.useState(!1),v=a.useRef(null),y=a.useRef(),A=a.useRef(s);A.current=s,a.useEffect(()=>(t&&(l("idle"),h(null),d(null),p(""),j(!1),E(!1)),()=>{y.current&&clearTimeout(y.current)}),[t,n==null?void 0:n.id]);const k=(n==null?void 0:n.requestedAt)??null,D=n==null?void 0:n.metadata,O=a.useMemo(()=>{if(!D)return[];const S=D,f=S.options??S.option??S.actions??null;return Array.isArray(f)?f.map(V=>{if(typeof V=="string")return{label:V,action:V};if(!V||typeof V!="object")return null;const H=V,G=typeof H.label=="string"?H.label:null,Y=typeof H.action=="string"?H.action:null,ie=G??Y??null;return ie?{label:G??ie,action:Y??ie}:null}).filter(Boolean):[]},[D]),I=a.useMemo(()=>{const S=((n==null?void 0:n.context)??"").trim();if(S)return S;if(!D)return"";const f=D,R=(typeof f.summary=="string"?f.summary:null)??(typeof f.description=="string"?f.description:null)??"";return String(R??"").trim()},[n==null?void 0:n.context,D]),ee=a.useMemo(()=>{const S=(n==null?void 0:n.waitingMinutes)??0;return S>=15?N.red:S>=5?N.amber:N.teal},[n==null?void 0:n.waitingMinutes]),X=a.useCallback(async()=>{if(!n)return;const S=Bl({decision:n,metadata:D});if(S)try{await navigator.clipboard.writeText(S),E(!0),setTimeout(()=>E(!1),2e3)}catch{}},[n,D]),le=a.useCallback(()=>{const S=[];return x&&S.push(`Selected: ${x}`),u.trim()&&S.push(u.trim()),S.length>0?S.join(`
212
- `):void 0},[x,u]),Q=a.useCallback(async()=>{if(!n||!r)return;let S=!1;if(l(f=>f==="approving"||f==="rejecting"?f:(S=!0,"approving")),!!S){h(null);try{(await r(n.id,le())).failed>0?(l("error"),h("Approval failed. Please try again.")):(l("success"),y.current=setTimeout(()=>A.current(),800))}catch(f){l("error"),h(f instanceof Error?f.message:"Approval failed.")}}},[n,r,le]),ne=a.useCallback(async()=>{if(!n||!i)return;let S=!1;if(l(f=>f==="approving"||f==="rejecting"?f:(S=!0,"rejecting")),!!S){h(null);try{(await i(n.id,le())).failed>0?(l("error"),h("Rejection failed. Please try again.")):(l("rejected"),y.current=setTimeout(()=>A.current(),800))}catch(f){l("error"),h(f instanceof Error?f.message:"Rejection failed.")}}},[n,i,le]);if(a.useEffect(()=>{if(!t)return;const S=f=>{(f.metaKey||f.ctrlKey)&&f.key==="Enter"&&(f.preventDefault(),Q())};return document.addEventListener("keydown",S),()=>document.removeEventListener("keydown",S)},[t,Q]),!t||!n)return null;const te=o==="approving"||o==="rejecting",M=o==="success"||o==="rejected",L=(n.status??"pending").toLowerCase(),C=!L.includes("approved")&&!L.includes("resolved")&&!L.includes("rejected");if(M){const S=o==="success",f=S?N.lime:N.red;return e.jsx(kt,{open:t,onClose:s,maxWidth:"max-w-xl",fitContent:!0,children:e.jsxs("div",{className:"flex flex-col items-center justify-center px-8 py-12",children:[e.jsx("div",{className:"mb-4 flex h-16 w-16 items-center justify-center rounded-full",style:{backgroundColor:`${f}18`,border:`1.5px solid ${f}40`},children:S?e.jsx("svg",{width:"28",height:"28",viewBox:"0 0 24 24",fill:"none",stroke:f,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):e.jsxs("svg",{width:"28",height:"28",viewBox:"0 0 24 24",fill:"none",stroke:f,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 6L6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})}),e.jsx("p",{className:"text-heading font-semibold text-white",children:S?"Approved":"Rejected"}),e.jsx("p",{className:"mt-1 text-body text-secondary",children:n.title})]})})}return e.jsx(kt,{open:t,onClose:s,maxWidth:"max-w-xl",children:e.jsxs("div",{className:"flex h-full min-h-0 w-full flex-col",children:[e.jsx("div",{className:"h-[2px] w-full flex-shrink-0",style:{background:`linear-gradient(90deg, ${ee}60, ${ee}20, transparent)`}}),e.jsxs("div",{className:"flex items-start justify-between gap-3 px-6 pt-5 pb-4",children:[e.jsx("div",{className:"min-w-0 flex-1",children:e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-lg",style:{backgroundColor:`${ee}14`,border:`1px solid ${ee}30`},children:e.jsx(Oe,{type:"decision",size:14})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h2",{className:"text-heading font-semibold leading-tight text-white",children:n.title||"Decision"}),e.jsxs("p",{className:"mt-0.5 text-caption text-secondary",children:[n.agentName||"System"," · ",n.waitingMinutes,"m waiting",k?` · ${Ge(k)}`:""]})]})]})}),e.jsx("button",{type:"button",onClick:s,"aria-label":"Close",className:"mt-0.5 flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-lg text-muted transition-colors hover:bg-white/[0.06] 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.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto px-6 pb-4",children:[I?e.jsx("div",{className:"rounded-xl border border-white/[0.06] bg-white/[0.02] px-4 py-3",children:e.jsx(cn,{text:I,mode:"block"})}):e.jsx("p",{className:"px-1 text-body text-muted italic",children:"No additional context provided."}),O.length>0&&e.jsxs("div",{className:"mt-4",children:[e.jsx("p",{className:"mb-2 px-1 text-micro font-medium uppercase tracking-[0.1em] text-muted",children:"Options"}),e.jsx("div",{className:"space-y-1.5",children:O.map(S=>{const f=x===S.action;return e.jsxs("button",{type:"button",onClick:()=>d(f?null:S.action),disabled:te,className:"flex w-full items-center gap-3 rounded-xl border px-4 py-3 text-left transition-all",style:{borderColor:f?`${N.lime}50`:"rgba(255,255,255,0.06)",backgroundColor:f?`${N.lime}08`:"rgba(255,255,255,0.02)"},children:[e.jsx("div",{className:"flex h-[18px] w-[18px] flex-shrink-0 items-center justify-center rounded-full border-2 transition-colors",style:{borderColor:f?N.lime:"rgba(255,255,255,0.2)"},children:f&&e.jsx("div",{className:"h-2 w-2 rounded-full",style:{backgroundColor:N.lime}})}),e.jsx("span",{className:`text-body ${f?"font-medium text-white":"text-primary"}`,children:S.label})]},`${S.label}:${S.action}`)})})]}),C&&e.jsxs("div",{className:"mt-4",children:[e.jsxs("button",{type:"button",onClick:()=>{j(S=>!S),m||requestAnimationFrame(()=>{var S;return(S=v.current)==null?void 0:S.focus()})},className:"flex w-full items-center gap-2 px-1 text-caption text-secondary transition-colors hover:text-white",children:[e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"transition-transform",style:{transform:m?"rotate(90deg)":"rotate(0deg)"},children:e.jsx("polyline",{points:"9 18 15 12 9 6"})}),"Add a note"]}),m&&e.jsx("div",{className:"mt-2",children:e.jsx("textarea",{ref:v,value:u,onChange:S=>p(S.target.value),disabled:te,placeholder:"Optional context for this decision...",rows:3,className:"w-full resize-none rounded-xl border border-white/[0.08] bg-white/[0.03] px-4 py-3 text-body text-primary placeholder-white/30 outline-none transition-colors focus:border-white/[0.16] focus:bg-white/[0.04]"})})]}),e.jsx("div",{className:"mt-4 border-t border-white/[0.06] pt-4",children:e.jsx(Pl,{entityType:"decision",entityId:n.id})})]}),c&&e.jsxs("div",{className:"flex items-center gap-2 border-t border-white/[0.06] px-6 py-3",children:[e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:N.red,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",x2:"12",y1:"8",y2:"12"}),e.jsx("line",{x1:"12",x2:"12.01",y1:"16",y2:"16"})]}),e.jsx("p",{className:"text-caption text-red-300",children:c})]}),C&&e.jsxs("div",{className:"flex items-center justify-between border-t border-white/[0.06] px-6 py-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[i&&e.jsx("button",{type:"button",onClick:ne,disabled:te,className:"rounded-lg border border-white/[0.08] bg-white/[0.03] px-4 py-2 text-body font-medium text-secondary transition-all hover:border-red-400/30 hover:bg-red-400/[0.08] hover:text-red-300 disabled:opacity-40",children:o==="rejecting"?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"inline-block h-3 w-3 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Rejecting"]}):"Reject"}),e.jsx("button",{type:"button",onClick:X,className:"rounded-lg px-3 py-2 text-caption text-muted transition-colors hover:text-white",title:"Copy decision as JSON",children:w?"Copied":"Copy"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("span",{className:"hidden text-micro text-muted sm:block",children:[Dl?"⌘":"Ctrl","+Enter"]}),e.jsx("button",{type:"button",onClick:Q,disabled:!r||te,"data-modal-autofocus":"true",className:"rounded-lg px-5 py-2 text-body font-semibold transition-all",style:{backgroundColor:!r||te?"rgba(255,255,255,0.08)":N.lime,color:!r||te?"rgba(255,255,255,0.4)":"#000",boxShadow:!r||te?"none":`0 0 20px ${N.lime}20`},children:o==="approving"?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"inline-block h-3 w-3 animate-spin rounded-full border-2 border-black/40 border-t-black"}),"Approving"]}):"Approve"})]})]})]})})}const $s=40;function Kr(t){return t>=15?{border:N.red,glow:`0 0 16px ${N.red}20`}:t>=5?{border:N.amber,glow:`0 0 12px ${N.amber}18`}:{border:N.teal,glow:"none"}}const Ei=a.memo(function({decisions:n,onApproveDecision:s,onRejectDecision:r,onApproveAll:i}){const o=ai(),[l,c]=a.useState(!1),[h,x]=a.useState(new Set),[d,u]=a.useState(new Set),[p,m]=a.useState(null),[j,w]=a.useState($s),[E,v]=a.useState(null),y=a.useMemo(()=>[...n].sort((f,R)=>{if(f.waitingMinutes!==R.waitingMinutes)return R.waitingMinutes-f.waitingMinutes;const V=Date.parse(f.requestedAt??f.updatedAt??""),H=Date.parse(R.requestedAt??R.updatedAt??""),G=Number.isFinite(V)?V:0;return(Number.isFinite(H)?H:0)-G}),[n]);a.useEffect(()=>{u(f=>{const R=new Set(y.map(H=>H.id)),V=new Set;for(const H of f)R.has(H)&&V.add(H);return V})},[y]);const A=d.size,k=a.useMemo(()=>y.slice(0,j),[y,j]),D=a.useMemo(()=>{if(k.length===0)return!1;for(const f of k)if(!d.has(f.id))return!1;return!0},[d,k]),O=a.useMemo(()=>E?y.find(f=>f.id===E)??null:null,[E,y]),I=async(f,R)=>await s(f,R),ee=r?async(f,R)=>await r(f,R):void 0;a.useEffect(()=>{w(f=>y.length===0?0:Math.min(Math.max($s,f),y.length))},[y.length]);const X=f=>{u(R=>{const V=new Set(R);return V.has(f)?V.delete(f):V.add(f),V})},le=()=>{u(f=>{if(k.length===0)return f;const R=new Set(f),V=D;for(const H of k)V?R.delete(H.id):R.add(H.id);return R})},Q=async()=>{if(!(y.length===0||l)){m(null),c(!0);try{const f=await i();f.failed>0?m(`Approved ${f.updated}; ${f.failed} failed.`):f.updated>0?m(`Approved ${f.updated} decision${f.updated===1?"":"s"}.`):m("No decisions were updated."),u(new Set)}catch(f){m(f instanceof Error?f.message:"Bulk approval failed.")}finally{c(!1)}}},ne=async()=>{if(A===0||l)return;m(null),c(!0);let f=0,R=0;try{const V=y.map(H=>H.id).filter(H=>d.has(H));for(const H of V){x(G=>new Set(G).add(H));try{const G=await s(H);f+=G.updated,R+=G.failed}catch{R+=1}finally{x(G=>{const Y=new Set(G);return Y.delete(H),Y})}}R>0?m(`Approved ${f}; ${R} failed.`):m(`Approved ${f} selected decision${f===1?"":"s"}.`),u(new Set)}finally{c(!1)}},te=async f=>{if(!(h.has(f)||l)){m(null),x(R=>{const V=new Set(R);return V.add(f),V});try{const R=await s(f);R.failed>0?m(`Approval failed for ${R.failed} decision.`):R.updated>0&&m("Decision approved.")}catch(R){m(R instanceof Error?R.message:"Decision approval failed.")}finally{x(R=>{const V=new Set(R);return V.delete(f),V}),u(R=>{if(!R.has(f))return R;const V=new Set(R);return V.delete(f),V})}}},M=p!==null&&!p.toLowerCase().includes("fail"),L=!o&&k.length<=32,C=y.length>0&&!l,S=A>0&&!l;return e.jsxs(Jt,{className:"flex h-full min-h-0 flex-col card-enter",children:[e.jsx(Rl,{open:E!==null,decision:O,onClose:()=>v(null),onApprove:I,onReject:ee}),e.jsxs("div",{className:"space-y-2 border-b border-subtle px-4 py-3.5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("h2",{className:"inline-flex items-center gap-2 text-heading font-semibold text-white",children:[e.jsx(Oe,{type:"decision",size:14}),"Decisions"]}),e.jsx("p",{className:"hidden text-body text-secondary sm:block",children:"Select multiple items to bulk review and approve"})]}),e.jsx("button",{onClick:Q,disabled:!C,"data-state":C?"active":"idle",className:"control-pill flex-shrink-0 px-3 text-caption font-semibold disabled:opacity-45",children:l?"Approving…":e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"hidden sm:inline",children:"Approve all"}),e.jsx("span",{className:"sm:hidden",children:"Approve"}),e.jsx("span",{className:"inline-flex h-5 shrink-0 items-center rounded-full border border-strong bg-white/[0.04] px-2 text-micro text-primary tabular-nums",children:y.length})]})})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{onClick:le,disabled:y.length===0||l,className:"control-pill px-3 text-caption font-semibold disabled:opacity-45",children:D?"Clear all":"Select all"}),e.jsx("button",{onClick:ne,disabled:!S,"data-state":S?"active":"idle",className:"control-pill px-3 text-caption font-semibold disabled:opacity-45",children:l?"Approving…":e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"hidden sm:inline",children:"Approve selected"}),e.jsx("span",{className:"sm:hidden",children:"Approve sel."}),e.jsx("span",{className:"inline-flex h-5 shrink-0 items-center rounded-full border border-strong bg-white/[0.04] px-2 text-micro text-primary tabular-nums",children:A})]})}),e.jsx("span",{className:"text-caption text-secondary",children:A>0?`${A} selected`:"No selection"})]})]}),e.jsxs("div",{className:"min-h-0 flex-1 space-y-2 overflow-y-auto p-3",children:[y.length===0&&e.jsxs("div",{className:"flex flex-col items-center gap-2.5 rounded-xl border border-subtle bg-white/[0.02] p-4 text-center",children:[e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-faint",children:[e.jsx("path",{d:"M22 11.08V12a10 10 0 1 1-5.93-9.14"}),e.jsx("polyline",{points:"22 4 12 14.01 9 11.01"})]}),e.jsx("p",{className:"text-body text-secondary",children:"No pending decisions. All clear."})]}),L?e.jsx(yt,{mode:"popLayout",children:k.map(f=>{const R=h.has(f.id),V=Kr(f.waitingMinutes),H=d.has(f.id);return e.jsx(we.article,{role:"button",tabIndex:0,onClick:()=>v(f.id),onKeyDown:G=>{(G.key==="Enter"||G.key===" ")&&(G.preventDefault(),v(f.id))},initial:{opacity:0,y:8,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,scale:.95},transition:{duration:.25,ease:[.4,0,.2,1]},layout:!0,className:"rounded-xl border bg-white/[0.03] px-3 py-2.5 transition-[border-color,box-shadow] cv-auto",style:{borderColor:H?`${N.lime}50`:`${V.border}35`,borderLeftWidth:3,borderLeftColor:`${V.border}80`,boxShadow:V.glow},children:e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx("input",{type:"checkbox",checked:H,onChange:()=>X(f.id),disabled:R||l,onClick:G=>G.stopPropagation(),className:"mt-0.5 h-4 w-4 rounded border-white/20 bg-black/40 text-lime focus:ring-lime/40"}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"flex min-w-0 items-start gap-1.5 text-body font-medium text-white",title:f.title,children:[e.jsx(Oe,{type:"decision",size:12,className:"mt-[3px] flex-shrink-0 opacity-90"}),e.jsx("span",{className:"line-clamp-2",children:f.title})]}),f.context&&e.jsx("p",{className:"mt-1 line-clamp-2 text-caption text-secondary",title:f.context,children:f.context}),e.jsxs("div",{className:"mt-1.5 flex items-center justify-between gap-2",children:[e.jsxs("p",{className:"min-w-0 truncate text-micro text-muted",title:`${f.agentName??"System"} · Waiting ${f.waitingMinutes}m${f.requestedAt?` · ${Ge(f.requestedAt)}`:""}`,children:[f.agentName??"System"," · Waiting ",f.waitingMinutes,"m",f.requestedAt?` · ${Ge(f.requestedAt)}`:""]}),e.jsx("button",{onClick:G=>{G.stopPropagation(),te(f.id)},disabled:R||l,className:"flex-shrink-0 rounded-md border border-lime/25 bg-lime/10 px-2.5 py-1 text-micro font-semibold text-lime transition-colors hover:bg-lime/20 disabled:cursor-not-allowed disabled:border-white/10 disabled:bg-white/[0.08] disabled:text-secondary",children:R?"Approving…":"Approve"})]})]})})]})},f.id)})}):e.jsx(e.Fragment,{children:k.map(f=>{const R=h.has(f.id),V=Kr(f.waitingMinutes),H=d.has(f.id);return e.jsx("article",{role:"button",tabIndex:0,onClick:()=>v(f.id),onKeyDown:G=>{(G.key==="Enter"||G.key===" ")&&(G.preventDefault(),v(f.id))},className:"rounded-xl border bg-white/[0.03] px-3 py-2.5 transition-[border-color,box-shadow] cv-auto",style:{borderColor:H?`${N.lime}50`:`${V.border}35`,borderLeftWidth:3,borderLeftColor:`${V.border}80`,boxShadow:V.glow},children:e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx("input",{type:"checkbox",checked:H,onChange:()=>X(f.id),disabled:R||l,onClick:G=>G.stopPropagation(),className:"mt-0.5 h-4 w-4 rounded border-white/20 bg-black/40 text-lime focus:ring-lime/40"}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"flex min-w-0 items-start gap-1.5 text-body font-medium text-white",title:f.title,children:[e.jsx(Oe,{type:"decision",size:12,className:"mt-[3px] flex-shrink-0 opacity-90"}),e.jsx("span",{className:"line-clamp-2",children:f.title})]}),f.context&&e.jsx("p",{className:"mt-1 line-clamp-2 text-caption text-secondary",title:f.context,children:f.context}),e.jsxs("div",{className:"mt-1.5 flex items-center justify-between gap-2",children:[e.jsxs("p",{className:"min-w-0 truncate text-micro text-muted",title:`${f.agentName??"System"} · Waiting ${f.waitingMinutes}m${f.requestedAt?` · ${Ge(f.requestedAt)}`:""}`,children:[f.agentName??"System"," · Waiting ",f.waitingMinutes,"m",f.requestedAt?` · ${Ge(f.requestedAt)}`:""]}),e.jsx("button",{onClick:G=>{G.stopPropagation(),te(f.id)},disabled:R||l,className:"flex-shrink-0 rounded-md border border-lime/25 bg-lime/10 px-2.5 py-1 text-micro font-semibold text-lime transition-colors hover:bg-lime/20 disabled:cursor-not-allowed disabled:border-white/10 disabled:bg-white/[0.08] disabled:text-secondary",children:R?"Approving…":"Approve"})]})]})})]})},f.id)})}),k.length<y.length&&e.jsxs("button",{onClick:()=>w(f=>Math.min(y.length,f+$s)),className:"w-full rounded-xl border border-white/[0.08] bg-white/[0.02] px-3 py-2 text-caption text-secondary transition-colors hover:bg-white/[0.05]",children:["Load more (",y.length-k.length," remaining)"]})]}),p&&e.jsxs("div",{className:"flex items-center gap-2 border-t border-subtle px-4 py-2.5 text-body text-secondary",children:[e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:M?"text-lime":"text-amber-400",children:M?e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M22 11.08V12a10 10 0 1 1-5.93-9.14"}),e.jsx("polyline",{points:"22 4 12 14.01 9 11.01"})]}):e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z"}),e.jsx("line",{x1:"12",x2:"12",y1:"9",y2:"13"}),e.jsx("line",{x1:"12",x2:"12.01",y1:"17",y2:"17"})]})}),p]})]})}),Ol=new Set(["running","active","in_progress","working","planning","dispatching","blocked"]),ql=3*6e4;function zl(t){if(!t)return!1;const n=Date.parse(t);return Number.isFinite(n)?Date.now()-n<=ql:!1}function Ul(t){const n=bt(t.status??""),s=bt(t.state??"");return s==="stale"||n==="stale"||s==="stopped"&&n!=="blocked"?!1:Ol.has(n)?!0:n==="queued"||n==="pending"||n==="paused"||n==="completed"?!1:t.lastHeartbeatAt?zl(t.lastHeartbeatAt):!1}function Vr(t){return t.replace(/_/g," ")}function Wl(t){return typeof t!="number"||!Number.isFinite(t)?null:Math.max(0,Math.min(100,Math.round(t)))}const Kl=a.memo(function({sessions:n,title:s="In Progress",className:r,onOpenSession:i,onFocusRunId:o}){const[l,c]=a.useState(null),h=a.useMemo(()=>{const u=n.filter(Ul);u.sort((j,w)=>{const E=Date.parse(j.updatedAt??j.lastEventAt??j.startedAt??""),v=Date.parse(w.updatedAt??w.lastEventAt??w.startedAt??""),y=Number.isFinite(E)?E:0;return(Number.isFinite(v)?v:0)-y});const p=[],m=new Set;for(const j of u){const w=j.workstreamId&&j.workstreamId.trim().length>0?`${j.initiativeId??"none"}:${j.workstreamId}`:j.runId;m.has(w)||(m.add(w),p.push(j))}return p},[n]),x=a.useMemo(()=>{const u=new Map;for(const p of h){const m=bt(p.status??"");u.set(m,(u.get(m)??0)+1)}return Array.from(u.entries()).sort((p,m)=>m[1]-p[1]).map(([p,m])=>({status:p,count:m}))},[h]),d=a.useMemo(()=>l?h.filter(u=>bt(u.status??"")===l):h,[h,l]);return e.jsxs(Jt,{className:`flex h-full min-h-0 flex-col overflow-hidden ${r??""}`,children:[e.jsx("div",{className:"flex items-center justify-between gap-2 border-b border-subtle px-4 py-3",children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("h2",{className:"truncate text-heading font-semibold text-white",children:s}),e.jsx("span",{className:"chip text-micro",children:h.length})]})}),x.length>1&&e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 border-b border-subtle px-3 py-2",children:[e.jsxs("button",{type:"button",onClick:()=>c(null),className:`inline-flex h-6 items-center gap-1 rounded-full border px-2 text-micro font-semibold transition-colors ${l===null?"border-[#BFFF00]/30 bg-[#BFFF00]/12 text-[#E1FFB2]":"border-strong bg-white/[0.04] text-secondary hover:bg-white/[0.08]"}`,children:["All",e.jsx("span",{className:"tabular-nums opacity-70",children:h.length})]}),x.map(({status:u,count:p})=>e.jsxs("button",{type:"button",onClick:()=>c(m=>m===u?null:u),className:`inline-flex h-6 items-center gap-1 rounded-full border px-2 text-micro font-semibold capitalize transition-colors ${l===u?"border-[#BFFF00]/30 bg-[#BFFF00]/12 text-[#E1FFB2]":"border-strong bg-white/[0.04] text-secondary hover:bg-white/[0.08]"}`,children:[Vr(u),e.jsx("span",{className:"tabular-nums opacity-70",children:p})]},u))]}),d.length===0?e.jsx("div",{className:"px-4 py-4 text-body text-secondary",children:h.length===0?"No runs in progress.":"No runs match this filter."}):e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-3 py-2",children:e.jsx("div",{className:"space-y-2",children:d.map(u=>{var v;const p=bt(u.status??""),m=u.lastEventAt??u.updatedAt??u.startedAt??null,j=(v=u.lastEventSummary)!=null&&v.trim()?u.lastEventSummary.trim():m?`Updated ${Ge(m)}`:null,w=Wl(u.progress),E=w===null&&["running","active","in_progress","working","planning","dispatching"].includes(p);return e.jsx("div",{className:"rounded-2xl border border-white/[0.08] bg-white/[0.02] px-3 py-2.5",children:e.jsxs("div",{className:"flex min-w-0 items-start gap-2.5",children:[e.jsx(dt,{name:u.agentName??"OrgX",hint:u.agentId??u.runId,size:"sm"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex min-w-0 items-start gap-1.5",children:[e.jsx(Oe,{type:"session",size:12,className:"mt-[3px] flex-shrink-0 opacity-80"}),e.jsx("p",{className:"min-w-0 line-clamp-2 text-body font-semibold leading-snug text-white",title:u.title,children:u.title}),e.jsx("span",{className:"ml-auto flex-shrink-0 rounded-full border border-white/[0.10] bg-white/[0.03] px-2 py-[1px] text-micro font-semibold uppercase tracking-[0.08em] text-secondary",children:Vr(p)})]}),j?e.jsx("p",{className:"mt-1 line-clamp-2 text-caption leading-snug text-secondary",title:j,children:j}):null,(w!==null||E)&&e.jsxs("div",{className:"mt-2",children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between text-micro",children:[e.jsx("span",{className:"text-secondary",children:"Slice progress"}),e.jsx("span",{className:"font-semibold text-primary tabular-nums",children:w===null?"Tracking…":`${w}%`})]}),e.jsx("div",{className:"h-1.5 overflow-hidden rounded-full bg-white/[0.09]",children:w===null?e.jsx("div",{className:"h-full w-1/3 rounded-full bg-[#7dd3c0]/70 animate-pulse"}):e.jsx("div",{className:"h-full rounded-full bg-gradient-to-r from-[#BFFF00]/80 to-[#7dd3c0]",style:{width:`${Math.max(3,w)}%`}})})]}),e.jsxs("div",{className:"mt-1.5 flex items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>i==null?void 0:i(u.id),className:"control-pill h-7 px-2.5 text-micro font-semibold",title:"Open session",children:"Open"}),e.jsx("button",{type:"button",onClick:()=>o==null?void 0:o(u.runId),className:"control-pill h-7 px-2.5 text-micro font-semibold",title:"Focus in Activity",children:"Focus"})]})]})]})},u.id)})})})]})});function gt({className:t=""}){return e.jsx("div",{className:de("shimmer-skeleton",t),"aria-hidden":"true"})}async function Fi(t,n){var o;const r=await(await fetch(t,n)).json().catch(()=>null),i=((o=r==null?void 0:r.data)==null?void 0:o.url)??(r==null?void 0:r.url)??null;if(typeof i=="string"&&i.trim())return i.trim();throw new Error((r==null?void 0:r.error)??"Billing link unavailable")}async function Vl(t){var i;const n=((i=t==null?void 0:t.actions)==null?void 0:i.checkout)??"/orgx/api/billing/checkout",s=((t==null?void 0:t.requiredPlan)??"starter").trim().toLowerCase()||"starter",r=await Fi(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({planId:s})});window.open(r,"_blank","noopener,noreferrer")}async function Hl(t){var r;const n=((r=t==null?void 0:t.actions)==null?void 0:r.portal)??"/orgx/api/billing/portal",s=await Fi(n,{method:"POST"});window.open(s,"_blank","noopener,noreferrer")}class $i extends Error{constructor(s,r){super(s);bn(this,"code","upgrade_required");bn(this,"currentPlan");bn(this,"requiredPlan");bn(this,"actions");this.name="UpgradeRequiredError",this.currentPlan=(r==null?void 0:r.currentPlan)??null,this.requiredPlan=((r==null?void 0:r.requiredPlan)??"starter").trim()||"starter",this.actions=(r==null?void 0:r.actions)??null}}function Gl(t){if(!t||typeof t!="object")return null;const n=t;if(n.code!=="upgrade_required")return null;const s=typeof n.error=="string"&&n.error.trim()?n.error.trim():"Upgrade required.";return new $i(s,{currentPlan:typeof n.currentPlan=="string"&&n.currentPlan.trim()?n.currentPlan.trim():null,requiredPlan:typeof n.requiredPlan=="string"&&n.requiredPlan.trim()?n.requiredPlan.trim():null,actions:n.actions??null})}function Hr(t){const n=(t??"").trim().toLowerCase();return n?n==="free"?"Free":n==="starter"?"Starter":n==="team"?"Team":n==="enterprise"?"Enterprise":n[0].toUpperCase()+n.slice(1):"Unknown"}async function Kn(t){return await t.json().catch(()=>null)}function Vn(t,n,s){return typeof(n==null?void 0:n.error)=="string"&&n.error.trim()||typeof(n==null?void 0:n.message)=="string"&&n.message.trim()||`${s} (${t.status})`}function Xl({initiativeId:t=null,authToken:n=null,embedMode:s=!1,enabled:r=!0}){var u,p,m,j;const i=is(),o=a.useMemo(()=>zt.nextUpQueue({initiativeId:t,authToken:n,embedMode:s}),[t,n,s]),l=async()=>{await i.invalidateQueries({queryKey:o}),await i.invalidateQueries({queryKey:zt.autoContinueStatus({initiativeId:t,authToken:n,embedMode:s})}),await i.invalidateQueries({queryKey:zt.missionControlGraph({initiativeId:t,authToken:n,embedMode:s})}),await i.invalidateQueries({queryKey:zt.liveData({authToken:n,embedMode:s})})},c=Et({queryKey:o,enabled:r,queryFn:async()=>{const w=new URLSearchParams;t&&w.set("initiative_id",t);const E=await fetch(`/orgx/api/mission-control/next-up?${w.toString()}`,{headers:ut({authToken:n,embedMode:s})}),v=await Kn(E);if(!E.ok){const A=Vn(E,v,"Failed to load next up queue");throw new Error(A)}const y=v??null;return!y||y.ok!==!0?{ok:!0,generatedAt:new Date().toISOString(),total:0,items:[],degraded:["next-up queue response missing expected payload"]}:y},refetchInterval:w=>{const E=w.state.data;return!E||!Array.isArray(E.items)||E.items.length===0?1e4:E.items.some(y=>y.queueState==="running")?2500:8e3}}),h=Ut({mutationFn:async w=>{const E=await fetch("/orgx/api/mission-control/next-up/play",{method:"POST",headers:ut({authToken:n,embedMode:s,contentTypeJson:!0}),body:JSON.stringify({initiativeId:w.initiativeId,workstreamId:w.workstreamId,agentId:w.agentId??void 0,fastAck:!0})}),v=await Kn(E);if(!E.ok)throw new Error(Vn(E,v,"Failed to dispatch queued workstream"));return v},onMutate:async w=>{await i.cancelQueries({queryKey:o});const E=i.getQueryData(o);return E?(i.setQueryData(o,{...E,items:E.items.map(v=>v.initiativeId===w.initiativeId&&v.workstreamId===w.workstreamId?{...v,queueState:"running"}:v.queueState==="running"?{...v,queueState:"idle"}:v)}),{previous:E}):{previous:E}},onError:(w,E,v)=>{v!=null&&v.previous&&i.setQueryData(o,v.previous)},onSuccess:()=>{l()}}),x=Ut({mutationFn:async w=>{const E=await fetch("/orgx/api/mission-control/auto-continue/start",{method:"POST",headers:ut({authToken:n,embedMode:s,contentTypeJson:!0}),body:JSON.stringify({initiativeId:w.initiativeId,agentId:w.agentId??void 0,tokenBudgetTokens:w.tokenBudgetTokens,workstreamIds:[w.workstreamId]})}),v=await Kn(E);if(!E.ok){const y=Gl(v);throw y||new Error(Vn(E,v,"Failed to start auto-continue"))}},onSuccess:()=>{l()}}),d=Ut({mutationFn:async w=>{const E=await fetch("/orgx/api/mission-control/auto-continue/stop",{method:"POST",headers:ut({authToken:n,embedMode:s,contentTypeJson:!0}),body:JSON.stringify({initiativeId:w.initiativeId})}),v=await Kn(E);if(!E.ok)throw new Error(Vn(E,v,"Failed to stop auto-continue"))},onSuccess:()=>{l()}});return{items:((u=c.data)==null?void 0:u.items)??[],total:((p=c.data)==null?void 0:p.total)??0,degraded:((m=c.data)==null?void 0:m.degraded)??[],isLoading:c.isLoading,isFetching:c.isFetching,error:((j=c.error)==null?void 0:j.message)??null,refetch:c.refetch,playWorkstream:h.mutateAsync,startWorkstreamAutoContinue:x.mutateAsync,stopInitiativeAutoContinue:d.mutateAsync,isPlaying:h.isPending,isStartingAutoContinue:x.isPending,isStoppingAutoContinue:d.isPending}}async function Ts(t){return await t.json().catch(()=>null)}function Ls(t,n,s){return typeof(n==null?void 0:n.error)=="string"&&n.error.trim()||typeof(n==null?void 0:n.message)=="string"&&n.message.trim()||`${s} (${t.status})`}function Jl(t){const n=t.authToken??null,s=t.embedMode??!1,r=is(),i=async()=>{await r.invalidateQueries({queryKey:["mission-control-next-up"]}),await r.invalidateQueries({queryKey:["mission-control-graph"]}),await r.invalidateQueries({queryKey:["live-data"]})},o=Ut({mutationFn:async h=>{const x=await fetch("/orgx/api/mission-control/next-up/pin",{method:"POST",headers:ut({authToken:n,embedMode:s,contentTypeJson:!0}),body:JSON.stringify(h)}),d=await Ts(x);if(!x.ok)throw new Error(Ls(x,d,"Failed to pin Next Up item"))},onSuccess:()=>{i()}}),l=Ut({mutationFn:async h=>{const x=await fetch("/orgx/api/mission-control/next-up/unpin",{method:"POST",headers:ut({authToken:n,embedMode:s,contentTypeJson:!0}),body:JSON.stringify(h)}),d=await Ts(x);if(!x.ok)throw new Error(Ls(x,d,"Failed to unpin Next Up item"))},onSuccess:()=>{i()}}),c=Ut({mutationFn:async h=>{const x=await fetch("/orgx/api/mission-control/next-up/reorder",{method:"POST",headers:ut({authToken:n,embedMode:s,contentTypeJson:!0}),body:JSON.stringify(h)}),d=await Ts(x);if(!x.ok)throw new Error(Ls(x,d,"Failed to reorder Next Up queue"))},onSuccess:()=>{i()}});return{pin:o.mutateAsync,unpin:l.mutateAsync,reorder:c.mutateAsync,isPinning:o.isPending,isUnpinning:l.isPending,isReordering:c.isPending}}function Ti({className:t=""}){return e.jsxs("svg",{viewBox:"0 0 20 20",fill:"none","aria-hidden":!0,className:t,children:[e.jsx("path",{d:"M2.5 10s2.6-4.2 7.5-4.2S17.5 10 17.5 10s-2.6 4.2-7.5 4.2S2.5 10 2.5 10Z",stroke:"currentColor",strokeWidth:"1.4"}),e.jsx("circle",{cx:"10",cy:"10",r:"2.2",stroke:"currentColor",strokeWidth:"1.4"})]})}function Li({className:t=""}){return e.jsx("svg",{viewBox:"0 0 20 20",fill:"none","aria-hidden":!0,className:t,children:e.jsx("path",{d:"M7 5.4v9.2c0 .7.75 1.15 1.38.83l7.6-4.6a.95.95 0 0 0 0-1.62l-7.6-4.64A.95.95 0 0 0 7 5.4Z",fill:"currentColor"})})}function Pi({className:t=""}){return e.jsx("svg",{viewBox:"0 0 20 20",fill:"none","aria-hidden":!0,className:t,children:e.jsx("path",{d:"M6.1 13.25C4.25 13.25 2.8 11.8 2.8 10s1.45-3.25 3.3-3.25c3.15 0 4.35 6.5 8.05 6.5 1.85 0 3.3-1.45 3.3-3.25s-1.45-3.25-3.3-3.25c-3.7 0-4.9 6.5-8.05 6.5Z",stroke:"currentColor",strokeWidth:"2.1",strokeLinecap:"round",strokeLinejoin:"round"})})}function Ql({className:t=""}){return e.jsxs("svg",{viewBox:"0 0 20 20",fill:"none","aria-hidden":!0,className:t,children:[e.jsx("path",{d:"M6.2 9.4V6.7c0-.7.5-1.2 1.1-1.2s1.1.5 1.1 1.2v2.2",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"}),e.jsx("path",{d:"M8.4 8.9V5.8c0-.7.5-1.3 1.1-1.3s1.1.6 1.1 1.3v3",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"}),e.jsx("path",{d:"M10.6 8.9V6.2c0-.7.5-1.3 1.1-1.3s1.1.6 1.1 1.3v3.2",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"}),e.jsx("path",{d:"M12.8 9.6V7.2c0-.7.5-1.2 1.1-1.2s1.1.5 1.1 1.2v4.2c0 2.7-1.9 4.6-4.6 4.6H9.2c-2.1 0-3.7-1-4.6-2.8l-.9-1.7c-.3-.6 0-1.4.6-1.7.6-.3 1.3 0 1.6.6l.7 1.4",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round"})]})}function Yl({className:t=""}){return e.jsxs("svg",{viewBox:"0 0 20 20",fill:"none","aria-hidden":!0,className:t,children:[e.jsx("path",{d:"M6.4 9.2V7.4c0-.7.5-1.2 1.1-1.2s1.1.5 1.1 1.2v1.3",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"}),e.jsx("path",{d:"M8.6 8.9V7c0-.7.5-1.2 1.1-1.2s1.1.5 1.1 1.2v2",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"}),e.jsx("path",{d:"M10.8 9.2V7.3c0-.7.5-1.2 1.1-1.2s1.1.5 1.1 1.2v2.6",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"}),e.jsx("path",{d:"M13 9.8V8.2c0-.7.5-1.2 1.1-1.2s1.1.5 1.1 1.2v3.6c0 2.4-1.7 4-4.1 4H9.7c-2 0-3.4-.9-4.2-2.5l-.8-1.4c-.3-.6 0-1.3.5-1.6.6-.3 1.2-.1 1.6.5l.6 1",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round"})]})}function Di(t){return t==="running"?"from-teal-300/0 via-teal-300/60 to-teal-300/0":t==="blocked"?"from-red-300/0 via-red-300/55 to-red-300/0":t==="idle"?"from-white/0 via-white/35 to-white/0":"from-[#BFFF00]/0 via-[#BFFF00]/70 to-[#BFFF00]/0"}function Gr(t){return!t||typeof t!="object"||Array.isArray(t)?null:t}function Bi(t,n){const s=Gr(n),r=s&&typeof s.dispatchMode=="string"?s.dispatchMode:null,i=Gr(s==null?void 0:s.run);return(i&&typeof i.stopReason=="string"?i.stopReason:i&&typeof i.stop_reason=="string"?i.stop_reason:null)==="budget_exhausted"?`Dispatch acknowledged for ${t.workstreamTitle}, but autopilot stopped: budget exhausted.`:r==="pending"?`Dispatching ${t.workstreamTitle}; waiting for slice start…`:r==="fallback"?`Dispatched ${t.workstreamTitle} using fallback runner.`:`Dispatched ${t.workstreamTitle}.`}function Zl({compact:t}){const n=t?3:6;return e.jsxs("div",{className:"space-y-2.5",children:[e.jsxs("div",{className:"flex items-center gap-2 px-1 pt-1 text-micro uppercase tracking-[0.12em] text-muted",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-[#BFFF00]/70 status-breathe"}),e.jsx("span",{children:"Calibrating queue"})]}),Array.from({length:n}).map((s,r)=>e.jsxs("div",{className:"nextup-skeleton-card rounded-2xl border border-white/[0.08] bg-white/[0.02] px-3 py-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2.5",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-start gap-2.5",children:[e.jsx(gt,{className:"h-8 w-8 rounded-full"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx(gt,{className:"h-3 w-40 rounded-md"}),e.jsx(gt,{className:"mt-2 h-4 w-56 rounded-md"})]})]}),e.jsx(gt,{className:"h-5 w-16 rounded-full"})]}),e.jsxs("div",{className:"mt-3 rounded-lg border border-white/[0.07] bg-black/[0.18] px-2.5 py-2",children:[e.jsx(gt,{className:"h-3 w-14 rounded"}),e.jsx(gt,{className:"mt-2 h-3 w-full rounded"}),e.jsx(gt,{className:"mt-2 h-3 w-3/5 rounded"})]}),e.jsxs("div",{className:"mt-2.5 flex flex-wrap gap-1.5",children:[e.jsx(gt,{className:"h-8 w-24 rounded-full"}),e.jsx(gt,{className:"h-8 w-20 rounded-full"}),e.jsx(gt,{className:"h-8 w-24 rounded-full"})]})]},`nextup-skeleton-${r}`))]})}function ec({initiativeId:t=null,authToken:n=null,embedMode:s=!1,title:r="Next Up",compact:i=!1,className:o,disableEnterAnimation:l=!1,allowCompactToggle:c=!1,onToggleCompact:h,onFollowWorkstream:x,onOpenInitiative:d,onOpenSettings:u,onUpgradeGate:p}){var et;const[m,j]=a.useState(i);a.useEffect(()=>j(i),[i]);const w=c&&!h?m:i,E=W=>{h?h(W):j(W)},[v,y]=a.useState(null),[A,k]=a.useState(null),[D,O]=a.useState(null),{items:I,total:ee,degraded:X,isLoading:le,isFetching:Q,error:ne,playWorkstream:te,startWorkstreamAutoContinue:M,stopInitiativeAutoContinue:L}=Xl({initiativeId:t,authToken:n,embedMode:s,enabled:!0}),C=Jl({authToken:n,embedMode:s}),S=a.useMemo(()=>w?I.slice(0,5):I,[w,I]),f=W=>`${W.initiativeId}:${W.workstreamId}`,[R,V]=a.useState([]),H=a.useRef([]),G=a.useMemo(()=>{const W=new Map;for(const F of S)W.set(f(F),F);return W},[S]),Y=a.useMemo(()=>S.map(f),[S]),ie=a.useMemo(()=>Y.join("|"),[Y]);a.useEffect(()=>{V(W=>{if(w)return[];const F=[],Z=new Set(Y);for(const ae of W)Z.has(ae)&&F.push(ae);for(const ae of Y)F.includes(ae)||F.push(ae);return F})},[w,ie]),a.useEffect(()=>{H.current=R},[R]);const J=async()=>{const W=H.current.map(F=>G.get(F)).filter(Boolean).map(F=>({initiativeId:F.initiativeId,workstreamId:F.workstreamId}));W.length!==0&&await C.reorder({order:W})},Fe=async(W,F,Z)=>{y(null),k(null),p==null||p(null),O(W);try{const ae=await F();y(typeof Z=="function"?Z(ae):Z)}catch(ae){ae instanceof $i?(k(ae),p==null||p(ae)):y(ae instanceof Error?ae.message:"Action failed")}finally{O(null)}},he=A?"upgrade":ne?"error":v?"notice":null,fe=he!==null;return e.jsxs(Jt,{className:`flex h-full min-h-0 flex-col overflow-hidden ${l?"":"card-enter"} ${o??""}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 border-b border-subtle px-4 py-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("h2",{className:"truncate text-heading font-semibold text-white",children:r}),le?e.jsx(gt,{className:"h-5 w-10 rounded-full"}):e.jsx("span",{className:"chip text-micro",children:ee}),Q&&!le&&e.jsx("span",{className:"text-micro text-muted",children:"refreshing…"})]}),c?e.jsx("button",{type:"button",onClick:()=>E(!w),className:"control-pill h-8 flex-shrink-0 whitespace-nowrap px-3 text-caption font-semibold",title:w?"Switch to expanded cards":"Switch to compact list","aria-label":w?"Expand Next Up queue":"Compact Next Up queue",children:w?"Expand":"Compact"}):null]}),fe&&e.jsx("div",{className:"px-3 pt-2",children:e.jsx(yt,{initial:!1,mode:"wait",children:he==="upgrade"&&A?e.jsx(we.div,{initial:{opacity:0,y:-4,scale:.99},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-4,scale:.99},transition:{duration:.18,ease:[.22,1,.36,1]},className:"rounded-xl border border-amber-200/25 bg-amber-200/10 px-3 py-2 text-caption text-amber-100",children:e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"rounded-full border border-amber-200/25 bg-amber-200/10 px-2 py-0.5 text-micro font-semibold uppercase tracking-[0.08em] text-amber-100/90",children:"Upgrade required"}),e.jsxs("span",{className:"truncate text-micro text-secondary",children:[Hr(A.currentPlan)," →"," ",Hr(A.requiredPlan)]})]}),e.jsx("div",{className:"mt-1 line-clamp-2 text-caption leading-snug text-amber-50/90",title:A.message,children:A.message}),v?e.jsx("div",{className:"mt-1 text-micro text-rose-50/85",children:v}):null]}),e.jsxs("div",{className:"flex flex-shrink-0 flex-col items-end gap-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>void Vl({actions:A.actions,requiredPlan:A.requiredPlan}).catch(W=>y(W instanceof Error?W.message:"Checkout failed")),className:"h-7 rounded-full border border-amber-200/25 bg-amber-200/15 px-3 text-micro font-semibold text-amber-50 transition-colors hover:bg-amber-200/20",children:"Upgrade"}),e.jsx("button",{type:"button",onClick:()=>void Hl({actions:A.actions}).catch(W=>y(W instanceof Error?W.message:"Portal failed")),className:"h-7 rounded-full border border-strong bg-white/[0.04] px-3 text-micro font-semibold text-primary transition-colors hover:bg-white/[0.08]",children:"Billing"}),u&&e.jsx("button",{type:"button",onClick:u,className:"h-7 rounded-full border border-strong bg-white/[0.04] px-2.5 text-micro font-semibold text-primary transition-colors hover:bg-white/[0.08]",children:"Settings"})]}),(et=A.actions)!=null&&et.pricing?e.jsx("a",{href:A.actions.pricing,target:"_blank",rel:"noopener noreferrer",className:"text-micro text-secondary underline decoration-white/20 hover:text-primary",children:"View pricing"}):null]})]})},"upgrade"):he==="error"&&ne?e.jsx(we.div,{initial:{opacity:0,y:-4},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},transition:{duration:.18},className:"rounded-xl border border-red-400/25 bg-red-500/[0.08] px-3 py-2 text-caption text-red-100",children:ne},"error"):he==="notice"&&v?e.jsx(we.div,{initial:{opacity:0,y:-4},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},transition:{duration:.18},className:"rounded-xl border border-white/[0.1] bg-white/[0.03] px-3 py-2 text-caption text-primary",children:v},"notice"):null})}),e.jsxs("div",{className:"flex-1 space-y-2.5 overflow-y-auto overscroll-y-contain px-3 pb-3 pt-1",children:[le?e.jsx(Zl,{compact:w}):null,!le&&S.length===0&&!ne&&e.jsx("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.02] px-3 py-4 text-center text-body text-secondary",children:"No queued workstreams right now."}),!le&&w?e.jsx(yt,{initial:!1,children:S.map((W,F)=>{var Qe,mt;const Z=f(W),ae=D===Z,xe=((Qe=W.autoContinue)==null?void 0:Qe.status)==="running"||((mt=W.autoContinue)==null?void 0:mt.status)==="stopping",_e=W.nextTaskDueAt?Ge(W.nextTaskDueAt):null;return e.jsxs(we.article,{layout:!0,initial:{opacity:0,y:6,scale:.99},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-4,scale:.99},transition:{duration:.22,delay:Math.min(F,7)*.018,ease:[.22,1,.36,1]},className:"group relative overflow-hidden rounded-2xl border border-white/[0.08] bg-white/[0.02] px-2.5 py-2",children:[e.jsx("div",{className:`pointer-events-none absolute inset-x-2.5 top-0 h-px bg-gradient-to-r ${Di(W.queueState)}`,"aria-hidden":!0}),e.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[e.jsx(dt,{name:W.runnerAgentName,hint:`${W.runnerAgentId} ${W.runnerSource}`,size:"xs"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[e.jsx(Oe,{type:"initiative",size:11,className:"flex-shrink-0 opacity-85"}),e.jsx("button",{type:"button",onClick:()=>d==null?void 0:d(W.initiativeId,W.initiativeTitle),className:"block w-full truncate text-left text-micro uppercase tracking-[0.08em] text-muted transition-colors hover:text-white/72",title:W.initiativeTitle,children:W.initiativeTitle})]}),e.jsxs("p",{className:"mt-0.5 flex min-w-0 items-center gap-1.5 text-caption font-semibold leading-snug text-white",title:W.workstreamTitle,children:[e.jsx(Oe,{type:"workstream",size:12,className:"flex-shrink-0 opacity-95"}),e.jsx("span",{className:"line-clamp-2",children:W.workstreamTitle})]}),W.nextTaskTitle?e.jsxs("p",{className:"mt-0.5 line-clamp-2 text-micro leading-snug text-secondary",title:`Next: ${W.nextTaskTitle}${_e?` · ${_e}`:""}`,children:["Next: ",W.nextTaskTitle,_e?` · ${_e}`:""]}):null]})]}),W.blockReason&&e.jsxs("div",{className:"mt-1.5 rounded-lg border border-red-400/24 bg-red-500/[0.08] px-2.5 py-1 text-micro text-red-100/85",children:["Blocked: ",W.blockReason]}),e.jsxs("div",{className:"mt-1.5 flex items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>x==null?void 0:x(W),className:"control-pill flex h-7 items-center justify-center px-2.5 text-micro font-semibold",title:"Follow in Activity",children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Ti,{className:"h-3 w-3 opacity-85"}),e.jsx("span",{children:"Follow"})]})}),e.jsx("button",{type:"button",disabled:ae,onClick:()=>void Fe(Z,()=>te({initiativeId:W.initiativeId,workstreamId:W.workstreamId,agentId:W.runnerAgentId}),Nt=>Bi(W,Nt)),className:"control-pill flex h-7 items-center justify-center px-2.5 text-micro font-semibold disabled:opacity-40",title:"Dispatch now",children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Li,{className:"h-3 w-3 opacity-85"}),e.jsx("span",{children:"Play"})]})}),e.jsx("button",{type:"button",disabled:ae,onClick:()=>void Fe(Z,()=>xe?L({initiativeId:W.initiativeId}):M({initiativeId:W.initiativeId,workstreamId:W.workstreamId,agentId:W.runnerAgentId}),xe?`Stopped auto-continue for ${W.initiativeTitle}.`:`Auto-continue started for ${W.workstreamTitle}.`),className:"control-pill flex h-7 items-center justify-center px-2.5 text-micro font-semibold disabled:opacity-40","data-state":xe?"active":"idle","data-tone":"teal",title:xe?"Stop auto-continue":"Auto-continue",children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Pi,{className:"h-3 w-3 opacity-85"}),e.jsx("span",{children:xe?"Stop auto":"Auto"})]})})]})]},Z)})}):le?null:e.jsx(Xi,{axis:"y",values:R,onReorder:W=>{H.current=W,V(W)},className:"space-y-2.5",children:R.map(W=>G.get(W)).filter(Boolean).map((W,F)=>e.jsx(tc,{item:W,index:F,actionKey:D,setNotice:y,setUpgradeGate:k,onUpgradeGate:p,onOpenInitiative:d,onFollowWorkstream:x,playWorkstream:te,startWorkstreamAutoContinue:M,stopInitiativeAutoContinue:L,onCommitReorder:()=>void J().catch(()=>null),onPinToggle:async Z=>{Z?(await C.pin({initiativeId:W.initiativeId,workstreamId:W.workstreamId}),y(`Pinned ${W.workstreamTitle}. Drag to reorder.`)):(await C.unpin({initiativeId:W.initiativeId,workstreamId:W.workstreamId}),y(`Unpinned ${W.workstreamTitle}.`))},runAction:Fe},f(W)))})]}),X.length>0&&e.jsxs("div",{className:"border-t border-subtle px-3 py-2 text-micro text-muted",children:["Limited signal: ",X[0]]})]})}function tc({item:t,index:n,actionKey:s,setNotice:r,setUpgradeGate:i,onUpgradeGate:o,onFollowWorkstream:l,onOpenInitiative:c,playWorkstream:h,startWorkstreamAutoContinue:x,stopInitiativeAutoContinue:d,onCommitReorder:u,onPinToggle:p,runAction:m}){var O,I;const j=Ji(),[w,E]=a.useState(!1),v=`${t.initiativeId}:${t.workstreamId}`,y=s===v,A=((O=t.autoContinue)==null?void 0:O.status)==="running"||((I=t.autoContinue)==null?void 0:I.status)==="stopping",k=t.nextTaskDueAt?Ge(t.nextTaskDueAt):null,D=t.isPinned===!0;return e.jsx(Qi,{value:v,id:v,dragListener:!1,dragControls:j,onDragStart:()=>E(!0),onDragEnd:()=>{E(!1),u()},whileDrag:{scale:1.01,boxShadow:"0 18px 40px rgba(0,0,0,0.42)"},className:"relative",children:e.jsxs(we.article,{layout:!0,initial:{opacity:0,y:6,scale:.99},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-4,scale:.99},transition:{duration:.22,delay:Math.min(n,7)*.018,ease:[.22,1,.36,1]},className:"group relative overflow-hidden rounded-2xl border border-white/[0.08] bg-white/[0.02] px-3 py-3",children:[e.jsx("div",{className:`absolute left-1/2 top-1 z-20 -translate-x-1/2 transition-opacity ${w?"opacity-100":"opacity-0 group-hover:opacity-100"}`,children:e.jsxs("button",{type:"button",onPointerDown:ee=>j.start(ee),"aria-label":"Drag to reorder",title:w?"Reordering":"Drag to reorder",className:`inline-flex h-7 items-center gap-1 rounded-full border px-2 text-micro font-semibold transition-colors ${w?"border-[#BFFF00]/35 bg-[#BFFF00]/14 text-[#E1FFB2] cursor-grabbing":"border-strong bg-white/[0.04] text-secondary cursor-grab hover:bg-white/[0.08] hover:text-bright"}`,children:[w?e.jsx(Yl,{className:"h-4 w-4 opacity-90"}):e.jsx(Ql,{className:"h-4 w-4 opacity-90"}),e.jsx("span",{children:w?"Grabbed":"Grab"})]})}),e.jsx("div",{className:`pointer-events-none absolute inset-x-3 top-0 h-px bg-gradient-to-r ${Di(t.queueState)}`,"aria-hidden":!0}),e.jsxs("div",{className:"flex items-start justify-between gap-2.5",children:[e.jsxs("div",{className:"min-w-0 flex flex-1 items-start gap-2.5",children:[e.jsx(dt,{name:t.runnerAgentName,hint:`${t.runnerAgentId} ${t.runnerSource}`,size:"sm"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[e.jsx(Oe,{type:"initiative",size:11,className:"flex-shrink-0 opacity-85"}),e.jsx("button",{type:"button",onClick:()=>c==null?void 0:c(t.initiativeId,t.initiativeTitle),className:"block w-full truncate text-left text-micro uppercase tracking-[0.08em] text-muted transition-colors hover:text-white/72",title:t.initiativeTitle,children:t.initiativeTitle})]}),e.jsxs("div",{className:"mt-0.5 flex min-w-0 items-start gap-1.5",children:[e.jsx(Oe,{type:"workstream",size:12,className:"mt-[3px] flex-shrink-0 opacity-95"}),e.jsx("p",{className:"min-w-0 line-clamp-2 text-body font-semibold leading-snug text-white",title:t.workstreamTitle,children:t.workstreamTitle})]})]})]}),e.jsx("button",{type:"button",onClick:()=>{r(null),i(null),o==null||o(null),p(!D).catch(ee=>r(ee instanceof Error?ee.message:"Pin action failed"))},title:D?"Unpin from queue ordering":"Pin to queue ordering","aria-label":D?"Unpin":"Pin",className:`inline-flex h-6 w-6 flex-shrink-0 items-center justify-center rounded-full border transition-colors ${D?"border-[#BFFF00]/35 bg-[#BFFF00]/12 text-[#E1FFB2]":"border-strong bg-white/[0.04] text-secondary hover:bg-white/[0.08]"}`,children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2","aria-hidden":!0,children:[e.jsx("path",{d:"M12 17v5"}),e.jsx("path",{d:"M9 3h6l1 7-4 4v3H12v-3l-4-4 1-7Z"})]})})]}),e.jsx("div",{className:"mt-2 rounded-lg border border-white/[0.07] bg-black/[0.18] px-2.5 py-2 text-caption text-white/68",children:t.nextTaskTitle?e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-1 text-micro uppercase tracking-[0.08em] text-white/44",children:[e.jsx(Oe,{type:"task",size:10,className:"flex-shrink-0 opacity-80"}),e.jsx("span",{children:"Next"}),k?e.jsxs("span",{className:"truncate text-micro normal-case tracking-normal text-muted",children:["· ",k]}):null]}),e.jsx("p",{className:"line-clamp-2 break-words text-caption leading-snug text-white/84",title:t.nextTaskTitle,children:t.nextTaskTitle})]}):e.jsx("span",{className:"text-secondary",children:"No task currently queued."})}),e.jsxs("div",{className:"mt-1.5 flex items-center gap-2 text-micro text-secondary",children:[e.jsx("span",{className:"rounded-full border border-strong bg-white/[0.03] px-2 py-0.5 text-micro uppercase tracking-[0.08em] text-secondary",children:"Runner"}),e.jsxs("span",{className:"truncate text-white/68",children:[t.runnerAgentName,t.runnerSource!=="assigned"?` · ${t.runnerSource}`:""]})]}),t.blockReason&&e.jsxs("div",{className:"mt-1.5 rounded-lg border border-red-400/24 bg-red-500/[0.08] px-2.5 py-1 text-micro text-red-100/85",children:["Blocked: ",t.blockReason]}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>l==null?void 0:l(t),className:"control-pill flex h-7 items-center justify-center px-2.5 text-micro font-semibold",title:"Follow this workstream in Activity",children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Ti,{className:"h-3 w-3 opacity-85"}),e.jsx("span",{children:"Follow"})]})}),e.jsx("button",{type:"button",disabled:y,onClick:()=>void m(v,()=>h({initiativeId:t.initiativeId,workstreamId:t.workstreamId,agentId:t.runnerAgentId}),ee=>Bi(t,ee)),className:"control-pill flex h-7 items-center justify-center px-2.5 text-micro font-semibold disabled:opacity-40",title:"Dispatch this workstream now (single run)",children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Li,{className:"h-3 w-3 opacity-85"}),e.jsx("span",{children:"Play"})]})}),e.jsx("button",{type:"button",disabled:y,onClick:()=>void m(v,()=>A?d({initiativeId:t.initiativeId}):x({initiativeId:t.initiativeId,workstreamId:t.workstreamId,agentId:t.runnerAgentId}),A?`Stopped auto-continue for ${t.initiativeTitle}.`:`Auto-continue started for ${t.workstreamTitle}.`),className:"control-pill flex h-7 items-center justify-center px-2.5 text-micro font-semibold disabled:opacity-40","data-state":A?"active":"idle","data-tone":"teal",title:A?"Stop auto-continue for this initiative":"Auto-continue this workstream",children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Pi,{className:"h-3 w-3 opacity-85"}),e.jsx("span",{children:A?"Stop auto":"Auto"})]})})]})]})})}function nc(t){const n=(t??"").toLowerCase();return n==="completed"||n==="done"?"completed":n==="blocked"||n==="at_risk"?"blocked":n==="paused"||n==="hold"?"paused":"active"}function sc(t){const n=(t??"").toLowerCase();return!["deleted","archived","cancelled"].includes(n)}function rc(t){return{id:t.id,name:t.title,status:nc(t.status),rawStatus:t.status??null,priority:t.priority??null,category:void 0,health:Math.max(0,Math.min(100,Math.round(t.progress??0))),daysRemaining:0,targetDate:t.targetDate??t.dueDate??t.etaEndAt??null,createdAt:t.createdAt??null,updatedAt:t.updatedAt??null,activeAgents:0,totalAgents:0,description:void 0}}function ic(t){return Et({queryKey:zt.liveInitiatives({limit:300}),queryFn:async()=>{const n=await fetch("/orgx/api/live/initiatives?limit=300");return n.ok?((await n.json()).initiatives??[]).filter(r=>sc(r.status)).map(rc):[]},enabled:t,staleTime:3e4})}function ac(t){switch(t){case"config":return"plugin configuration";case"environment":return"environment variable";case"persisted":return"saved credentials";case"openclaw-config-file":return"OpenClaw config";case"legacy-dev":return"legacy key";default:return""}}function oc(t,n){return t==="connected"&&n?"connected":t==="awaiting_browser_auth"||t==="pairing"||t==="starting"?"connecting":t==="error"?"error":"idle"}function lc({phase:t}){const n=t==="connected"||t==="connecting"?"bg-[#BFFF00]":t==="error"?"bg-red-400":"bg-white/30",s=t==="connecting";return e.jsxs("span",{className:"relative flex h-2.5 w-2.5 shrink-0",children:[s&&e.jsx("span",{className:de("absolute inline-flex h-full w-full animate-ping rounded-full opacity-40",n)}),e.jsx("span",{className:de("relative inline-flex h-2.5 w-2.5 rounded-full",n)})]})}function cc({phase:t}){const n=t==="connected"?"Connected":t==="connecting"?"Connecting...":t==="error"?"Connection issue":"Not connected",s=t==="connected"?"text-[#BFFF00]":t==="error"?"text-red-400":"text-primary";return e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(lc,{phase:t}),e.jsx("span",{className:de("text-body font-semibold",s),children:n})]})}function dc({state:t,isStarting:n,isSubmittingManual:s,onRefresh:r,onStartPairing:i,onSubmitManualKey:o,onBackToPairing:l,onUseManualKey:c,onDisconnect:h}){const x="https://www.useorgx.com/settings#security",d=oc(t.status,t.connectionVerified),u=t.status==="manual_key",p=t.status==="awaiting_browser_auth"||t.status==="pairing"||t.status==="starting",m=!!t.lastError,j=ac(t.keySource),w=a.useMemo(()=>d==="connected"?"Live sync is active. Initiatives, tasks, and activity flow in real time.":d==="connecting"?"Approve the pairing in your browser to finish connecting.":d==="error"?"Trouble reaching OrgX. Try reconnecting or use a manual API key.":t.hasApiKey?"An API key is present but the connection has not been verified yet.":"Connect to OrgX to sync initiatives, tasks, activity, and decisions.",[d,t.hasApiKey]),E=d==="connected"?"border-[#BFFF00]/15":d==="error"?"border-rose-400/20":"border-white/[0.07]";return e.jsxs("div",{className:"flex min-h-0 flex-col gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-heading font-semibold text-white",children:"OrgX connection"}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:w})]}),m&&e.jsx("div",{className:"rounded-xl border border-rose-300/20 bg-rose-400/10 px-4 py-3 text-body text-rose-100",children:t.lastError}),u?e.jsx(hi,{isSubmitting:s,onSubmit:o,onBack:l}):e.jsxs("div",{className:de("rounded-2xl border bg-white/[0.02] p-5",E),children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx(cc,{phase:d}),e.jsx("button",{type:"button",onClick:()=>{r()},className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-secondary transition-colors hover:bg-white/[0.06] hover:text-white",children:"Refresh"})]}),d==="connected"&&e.jsxs("div",{className:"mt-4 grid gap-1.5 text-body text-secondary",children:[t.workspaceName&&e.jsxs("div",{className:"flex items-baseline gap-1.5",children:[e.jsx("span",{className:"text-muted",children:"Workspace"}),e.jsx("span",{className:"text-primary",children:t.workspaceName})]}),j&&e.jsxs("div",{className:"flex items-baseline gap-1.5",children:[e.jsx("span",{className:"text-muted",children:"Authenticated via"}),e.jsx("span",{className:"text-primary",children:j})]})]}),d==="idle"&&t.hasApiKey&&!t.connectionVerified&&e.jsxs("p",{className:"mt-3 text-caption text-amber-200/70",children:["Key detected",j?` from ${j}`:""," but not yet verified. Refresh or reconnect to activate live sync."]}),p&&t.connectUrl&&e.jsxs("div",{className:"mt-4 rounded-xl border border-[#BFFF00]/20 bg-[#BFFF00]/[0.06] px-4 py-3",children:[e.jsx("p",{className:"text-caption uppercase tracking-[0.1em] text-[#D8FFA1]",children:"Pairing pending"}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:"A browser tab should have opened. Approve the connection to finish."}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsx("a",{href:t.connectUrl,target:"_blank",rel:"noopener noreferrer",className:"rounded-full border border-[#BFFF00]/30 bg-[#BFFF00]/15 px-3 py-1.5 text-caption font-semibold text-[#D8FFA1] transition-colors hover:bg-[#BFFF00]/25",children:"Open approval page"}),t.expiresAt&&e.jsxs("span",{className:"text-caption text-muted",children:["Expires ",new Date(t.expiresAt).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})]})]})]}),e.jsx("div",{className:de("flex flex-wrap items-center gap-2",d==="connected"?"mt-5":"mt-4"),children:d==="connected"?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>{i()},disabled:n,className:"rounded-full border border-strong bg-white/[0.03] px-4 py-2 text-body font-semibold text-primary transition-colors hover:bg-white/[0.06] disabled:cursor-not-allowed disabled:opacity-50",children:"Reconnect"}),e.jsx("button",{type:"button",onClick:()=>{h()},className:"rounded-full border border-rose-300/20 bg-transparent px-4 py-2 text-body font-semibold text-rose-200/70 transition-colors hover:bg-rose-400/10",children:"Disconnect"}),e.jsx("a",{href:x,target:"_blank",rel:"noreferrer",className:"rounded-full border border-strong bg-white/[0.03] px-4 py-2 text-body font-semibold text-primary transition-colors hover:bg-white/[0.06]",children:"Manage API keys"})]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>{i()},disabled:n,"data-modal-autofocus":"true",className:"inline-flex items-center gap-2 rounded-full bg-[#BFFF00] px-4 py-2 text-body font-semibold text-black transition-colors hover:bg-[#d3ff42] disabled:cursor-not-allowed disabled:opacity-50",children:n?"Connecting...":"Connect in browser"}),e.jsx("button",{type:"button",onClick:c,className:"rounded-full border border-strong bg-white/[0.03] px-4 py-2 text-body font-semibold text-primary transition-colors hover:bg-white/[0.06]",children:"Use API key"}),t.hasApiKey&&e.jsx("button",{type:"button",onClick:()=>{h()},className:"rounded-full border border-rose-300/20 bg-transparent px-4 py-2 text-body font-semibold text-rose-200/70 transition-colors hover:bg-rose-400/10",children:"Disconnect"})]})})]}),d!=="connected"&&e.jsxs("p",{className:"text-caption leading-relaxed text-muted",children:["Prefer user-scoped keys (",e.jsx("code",{className:"rounded bg-black/40 px-1",children:"oxk_..."}),"). They don't require a separate userId header."]})]})}function uc({authToken:t=null,embedMode:n=!1,enabled:s=!0}={}){var c,h;const r=is(),i=a.useMemo(()=>["agent-suite",{authToken:t,embedMode:n}],[t,n]),o=Et({queryKey:i,enabled:s,queryFn:async()=>{const x=await fetch("/orgx/api/agent-suite/status",{headers:ut({authToken:t,embedMode:n})}),d=await x.json().catch(()=>null);return x.ok?d:{ok:!1,error:(d==null?void 0:d.error)??`Failed to load agent suite (${x.status})`}},staleTime:1e4}),l=Ut({mutationFn:async({dryRun:x,forceSkillPack:d}={})=>{const u=await fetch("/orgx/api/agent-suite/install",{method:"POST",headers:ut({authToken:t,embedMode:n,contentTypeJson:!0}),body:JSON.stringify({dryRun:!!x,forceSkillPack:!!d})}),p=await u.json().catch(()=>null);if(!u.ok)throw new Error((p==null?void 0:p.error)??`Failed to install agent suite (${u.status})`);return p},onSuccess:async()=>{await r.invalidateQueries({queryKey:i})}});return{status:o.data??null,isLoading:o.isLoading,isRefetching:o.isRefetching,error:(o.data&&"error"in o.data?o.data.error:null)??((c=o.error)==null?void 0:c.message)??null,installError:((h=l.error)==null?void 0:h.message)??null,refetchStatus:o.refetch,install:l.mutate,resetInstall:l.reset,installResult:l.data??null,isInstalling:l.isPending}}function an(t,n){return t===1?`${t} ${n}`:`${t} ${n}s`}function Pt({tone:t,children:n}){const s=a.useMemo(()=>t==="good"?"border-lime/25 bg-lime/[0.10] text-lime":t==="warn"?"border-amber-300/25 bg-amber-400/10 text-amber-100/90":"border-white/[0.10] bg-white/[0.02] text-primary",[t]);return e.jsx("span",{className:de("inline-flex items-center rounded-full border px-2.5 py-1 text-caption font-semibold",s),children:n})}function mc({authToken:t=null,embedMode:n=!1,enabled:s=!0}){var y,A,k,D,O;const[r,i]=a.useState(!1),o=uc({authToken:t,embedMode:n,enabled:s}),l=(y=o.status)!=null&&y.ok?o.status.data:null,c=((A=l==null?void 0:l.agents)==null?void 0:A.length)??0,h=((k=l==null?void 0:l.openclawConfigAddedAgents)==null?void 0:k.length)??0,x=a.useMemo(()=>{var I;return((I=l==null?void 0:l.workspaceFiles)==null?void 0:I.filter(ee=>ee.action!=="noop"))??[]},[l]),d=x.length,u=a.useMemo(()=>x.filter(I=>I.action==="create").length,[x]),p=a.useMemo(()=>x.filter(I=>I.action==="update").length,[x]),m=a.useMemo(()=>x.filter(I=>I.action==="conflict").length,[x]),j=a.useMemo(()=>{if(o.isLoading)return"Loading agent suite status...";if(o.error)return`Unable to read suite status: ${o.error}`;if(!l)return"Suite status unavailable.";if(m>0)return`Conflicts detected: ${an(m,"file")} need attention.`;if(h===0&&d===0)return"Suite is installed and up to date.";const I=[];return h>0&&I.push(`will add ${an(h,"agent")}`),d>0&&I.push(`will update ${an(d,"file")}`),`Preview: ${I.join(", ")}.`},[d,m,h,l,o.error,o.isLoading]),w=(D=o.installResult)!=null&&D.ok?o.installResult:null,E=!!(w!=null&&w.dryRun),v=async I=>{await fetch("/orgx/api/skill-pack/policy",{method:"POST",headers:ut({authToken:t,embedMode:n,contentTypeJson:!0}),body:JSON.stringify(I)}).then(async ee=>{if(!ee.ok){const X=await ee.json().catch(()=>null);throw new Error((X==null?void 0:X.error)??`Failed to update policy (${ee.status})`)}}),await o.refetchStatus()};return e.jsxs("div",{className:"rounded-2xl border border-white/[0.07] bg-white/[0.02] p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-heading font-semibold text-white",children:"OrgX agent suite"}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:"Installs the OrgX domain agents into OpenClaw (workspaces + guardrails + managed/local overlay)."})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>{o.resetInstall(),o.refetchStatus()},disabled:o.isRefetching,className:"rounded-full border border-strong bg-white/[0.03] px-4 py-2 text-body font-semibold text-primary transition-colors hover:bg-white/[0.06] disabled:cursor-not-allowed disabled:opacity-50",children:o.isRefetching?"Refreshing...":"Refresh"}),e.jsx("button",{type:"button",onClick:()=>{i(!0),o.install({dryRun:!0})},disabled:o.isInstalling,className:"rounded-full border border-strong bg-white/[0.03] px-4 py-2 text-body font-semibold text-primary transition-colors hover:bg-white/[0.06] disabled:cursor-not-allowed disabled:opacity-50",title:"Computes the plan without writing any files",children:"Dry run"}),e.jsx("button",{type:"button",onClick:()=>{o.install({dryRun:!1,forceSkillPack:!0})},disabled:o.isInstalling,className:"rounded-full border border-strong bg-white/[0.03] px-4 py-2 text-body font-semibold text-primary transition-colors hover:bg-white/[0.06] disabled:cursor-not-allowed disabled:opacity-50",title:"Forces a check for the latest OrgX skill pack and applies it (managed/local overlay preserves local edits)",children:"Refresh skills"}),e.jsx("button",{type:"button",onClick:()=>{o.install({dryRun:!1})},disabled:o.isInstalling,className:"inline-flex items-center gap-2 rounded-full bg-[#BFFF00] px-4 py-2 text-body font-semibold text-black transition-colors hover:bg-[#d3ff42] disabled:cursor-not-allowed disabled:opacity-50",title:"Adds missing agents to openclaw.json and scaffolds managed workspace files",children:o.isInstalling?"Installing...":"Install / Update"})]})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsx(Pt,{tone:o.error?"warn":"neutral",children:j}),l&&e.jsxs(e.Fragment,{children:[e.jsx(Pt,{tone:h===0?"good":"warn",children:h===0?"agents configured":`${h} missing in openclaw.json`}),e.jsxs(Pt,{tone:"neutral",children:[an(c,"agent")," total"]}),e.jsx(Pt,{tone:d===0?"good":"neutral",children:d===0?"no file changes":`${d} file changes`}),m>0&&e.jsx(Pt,{tone:"warn",children:an(m,"conflict")}),l.skillPackUpdateAvailable&&e.jsx(Pt,{tone:"warn",children:"skill update available"}),((O=l.skillPackPolicy)==null?void 0:O.frozen)&&e.jsx(Pt,{tone:"neutral",children:"skills frozen"})]})]}),o.installError&&e.jsx("div",{className:"mt-3 rounded-xl border border-rose-300/20 bg-rose-400/10 px-4 py-3 text-body text-rose-100",children:o.installError}),w&&e.jsxs("div",{className:"mt-3 rounded-xl border border-lime/20 bg-lime/[0.06] px-4 py-3",children:[e.jsx("p",{className:"text-caption uppercase tracking-[0.1em] text-[#D8FFA1]",children:E?"Dry run":"Applied"}),e.jsxs("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:["Operation ",e.jsx("code",{className:"rounded bg-black/40 px-1",children:w.operationId})," ",E?"computed the plan without writing any files.":"wrote OpenClaw config and refreshed managed files."]})]}),l&&e.jsxs("div",{className:"mt-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:"text-body font-semibold text-primary",children:"Suite details"}),e.jsx("button",{type:"button",onClick:()=>i(I=>!I),className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.06]",children:r?"Hide":"Show"})]}),r&&e.jsxs("div",{className:"mt-3 grid gap-3",children:[e.jsx("div",{className:"rounded-xl border border-white/[0.07] bg-black/20 p-3",children:e.jsxs("div",{className:"grid gap-1 text-body text-secondary",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("span",{children:"OpenClaw config"}),e.jsx("code",{className:"rounded bg-black/40 px-1.5 py-0.5 text-caption text-primary",children:l.openclawConfigPath})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("span",{children:"Agent workspaces"}),e.jsxs("code",{className:"rounded bg-black/40 px-1.5 py-0.5 text-caption text-primary",children:[l.suiteWorkspaceRoot,"/","{agent-id}"]})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("span",{children:"Pack"}),e.jsxs("code",{className:"rounded bg-black/40 px-1.5 py-0.5 text-caption text-primary",children:[l.packId,"@",l.packVersion]})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("span",{children:"Skill pack"}),e.jsx("code",{className:"rounded bg-black/40 px-1.5 py-0.5 text-caption text-primary",children:l.skillPack?`${l.skillPack.name}@${l.skillPack.version} (${l.skillPack.source})`:"builtin"})]}),l.skillPackRemote&&e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("span",{children:"Skill pack remote"}),e.jsxs("code",{className:"rounded bg-black/40 px-1.5 py-0.5 text-caption text-primary",children:[l.skillPackRemote.name,"@",l.skillPackRemote.version]})]}),l.skillPackPolicy&&e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("span",{children:"Skill pack policy"}),e.jsxs("code",{className:"rounded bg-black/40 px-1.5 py-0.5 text-caption text-primary",children:[l.skillPackPolicy.frozen?"frozen":"live",l.skillPackPolicy.pinnedChecksum?`, pinned:${l.skillPackPolicy.pinnedChecksum.slice(0,8)}…`:""]})]}),l.skillPackPolicy&&e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>{var I;v({frozen:!((I=l.skillPackPolicy)!=null&&I.frozen)})},className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.06]",children:l.skillPackPolicy.frozen?"Unfreeze skills":"Freeze skills"}),e.jsx("button",{type:"button",onClick:()=>{var I;(I=l.skillPackPolicy)!=null&&I.pinnedChecksum?v({clearPin:!0}):v({pinToCurrent:!0})},className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.06]",children:l.skillPackPolicy.pinnedChecksum?"Unpin":"Pin current"}),e.jsx("p",{className:"text-caption text-muted",children:"Freeze prevents background checks; pin prevents applying a new checksum."})]})]})}),e.jsxs("div",{className:"rounded-xl border border-white/[0.07] bg-black/20 p-3",children:[e.jsxs("p",{className:"text-body font-semibold text-primary",children:["Agents (",c,")"]}),e.jsx("div",{className:"mt-2 grid gap-2",children:l.agents.map(I=>e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 rounded-xl border border-subtle bg-white/[0.02] px-3 py-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-body font-semibold text-bright",children:I.name}),e.jsxs("p",{className:"mt-0.5 truncate text-caption text-secondary",children:[e.jsx("code",{className:"rounded bg-black/40 px-1",children:I.id}),e.jsx("span",{className:"px-1",children:"·"}),e.jsx("span",{children:I.domain})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(Pt,{tone:I.configuredInOpenclaw?"good":"warn",children:I.configuredInOpenclaw?"configured":"not configured"}),e.jsx(Pt,{tone:I.workspaceExists?"good":"neutral",children:I.workspaceExists?"workspace ok":"workspace missing"})]})]},I.id))})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.07] bg-black/20 p-3",children:[e.jsx("p",{className:"text-body font-semibold text-primary",children:"Planned file writes"}),e.jsxs("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:["Managed files are written to ",e.jsx("code",{className:"rounded bg-black/40 px-1",children:".orgx/managed"}),". Local overrides are read from ",e.jsx("code",{className:"rounded bg-black/40 px-1",children:".orgx/local"})," and appended into the composite files in the agent workspace root."]}),e.jsxs("div",{className:"mt-2 grid gap-1 text-caption text-secondary",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("span",{children:"Writes"}),e.jsx("span",{className:"text-primary",children:an(l.workspaceFiles.length,"file")})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("span",{children:"Creates/updates"}),e.jsx("span",{className:"text-primary",children:d})]}),(u>0||p>0)&&e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("span",{children:"Breakdown"}),e.jsxs("span",{className:"text-primary",children:[u>0?`${u} create`:"0 create",","," ",p>0?`${p} update`:"0 update"]})]})]}),h>0&&e.jsxs("div",{className:"mt-3 rounded-lg border border-white/[0.08] bg-white/[0.02] px-3 py-2",children:[e.jsx("p",{className:"text-caption font-semibold text-primary",children:"OpenClaw agents to add"}),e.jsx("div",{className:"mt-1 flex flex-wrap gap-2",children:l.openclawConfigAddedAgents.map(I=>e.jsx("code",{className:"rounded-full border border-strong bg-black/40 px-2 py-0.5 text-caption text-primary",children:I},I))})]}),x.length>0&&e.jsxs("div",{className:"mt-3 rounded-lg border border-white/[0.08] bg-white/[0.02] px-3 py-2",children:[e.jsx("p",{className:"text-caption font-semibold text-primary",children:"Files that will change"}),e.jsxs("div",{className:"mt-2 grid gap-1.5",children:[x.slice(0,24).map(I=>e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 text-caption",children:[e.jsxs("code",{className:"rounded bg-black/40 px-1.5 py-0.5 text-primary",children:[I.agentId,"/",I.file]}),e.jsx("span",{className:"text-secondary",children:I.action})]},`${I.agentId}:${I.file}`)),x.length>24&&e.jsxs("p",{className:"text-caption text-muted",children:["Showing 24 of ",x.length,". Install/Update to apply all."]})]})]})]})]})]})]})}const Ri=[{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 Xr(t){return t==="openai"?"openaiApiKey":t==="anthropic"?"anthropicApiKey":"openrouterApiKey"}function pc(t){var n;return((n=Ri.find(s=>s.id===t))==null?void 0:n.label)??t}function xc({authToken:t=null,embedMode:n=!1,enabled:s=!0}){const r=gi({authToken:t,embedMode:n,enabled:s}),i=r.status,o=r.health,[l,c]=a.useState({openai:"",anthropic:"",openrouter:""}),[h,x]=a.useState({openai:!1,anthropic:!1,openrouter:!1}),[d,u]=a.useState({openai:!1,anthropic:!1,openrouter:!1}),[p,m]=a.useState(null),[j,w]=a.useState(null);a.useEffect(()=>{s&&(c({openai:"",anthropic:"",openrouter:""}),x({openai:!1,anthropic:!1,openrouter:!1}),u({openai:!1,anthropic:!1,openrouter:!1}),m(null),w(null))},[s]);const E=a.useMemo(()=>i!=null&&i.ok?Number(i.providers.openai.configured)+Number(i.providers.anthropic.configured)+Number(i.providers.openrouter.configured):0,[i]),v=async k=>{if(!s)return;w(null);const D=l[k].trim();if(!h[k])return;if(!D){w(`Enter a ${pc(k)} API key or use "Clear" to remove the saved key.`);return}const O=Xr(k);try{m(k),await r.update({[O]:D}),x(I=>({...I,[k]:!1})),c(I=>({...I,[k]:""})),u(I=>({...I,[k]:!1}))}finally{m(null)}},y=async k=>{w(null);const D=Xr(k);try{m(k),await r.update({[D]:null}),x(O=>({...O,[k]:!1})),c(O=>({...O,[k]:""})),u(O=>({...O,[k]:!1}))}finally{m(null)}},A=async()=>{w(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-heading font-semibold text-white",children:"Provider keys"}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:"Bring your own provider keys. Keys are stored locally and used for OpenClaw agent launches."}),E===0?e.jsxs("div",{className:"mt-3 inline-flex items-center gap-2 rounded-full border border-amber-200/20 bg-amber-200/10 px-3 py-1 text-caption text-amber-100/85",children:[e.jsx("span",{className:"inline-flex h-1.5 w-1.5 rounded-full bg-amber-200/80"}),"No keys detected yet. You can also use env vars."]}):e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsxs("span",{className:"chip",children:[E," / 3 configured"]}),(i==null?void 0:i.updatedAt)&&e.jsxs("span",{className:"text-caption text-muted",children:["Updated ",new Date(i.updatedAt).toLocaleString()]})]})]}),(j||r.error)&&e.jsx("div",{className:"mb-4 rounded-xl border border-rose-300/20 bg-rose-400/10 p-4 text-body text-rose-100",children:j??r.error}),e.jsxs("div",{className:"mb-4 rounded-2xl border border-subtle bg-white/[0.02] p-4",children:[e.jsx("p",{className:"text-body font-semibold text-primary",children:"Where keys come from"}),e.jsxs("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:["If you set an env var (e.g."," ",e.jsx("code",{className:"rounded bg-black/40 px-1",children:"OPENAI_API_KEY"}),"), it will be used unless a saved key overrides it."]})]}),e.jsx("div",{className:"grid grid-cols-1 gap-4",children:Ri.map(k=>{var M,L;const D=(M=i==null?void 0:i.providers)==null?void 0:M[k.id],O=(L=o==null?void 0:o.providers)==null?void 0:L[k.id],I=(D==null?void 0:D.masked)??null,ee=(D==null?void 0:D.source)??"none",X=ee==="stored",le=p===k.id,Q=h[k.id]&&l[k.id].trim().length>0&&!r.isSaving&&!le,ne=X&&!r.isSaving&&!le,te=X?"Update":"Save";return e.jsxs("div",{className:"rounded-2xl border border-white/[0.07] bg-white/[0.02] p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("p",{className:"text-body font-semibold text-white",children:k.label}),e.jsx("span",{className:de("rounded-full border px-2 py-0.5 text-micro uppercase tracking-[0.12em]",D!=null&&D.configured?"border-emerald-300/25 bg-emerald-400/10 text-emerald-100":"border-strong bg-white/[0.03] text-secondary"),children:D!=null&&D.configured?"Configured":"Missing"})]}),e.jsxs("p",{className:"mt-1 text-body text-secondary",children:[k.hint," ",e.jsxs("span",{className:"text-muted",children:["Env: ",e.jsx("code",{className:"rounded bg-black/40 px-1",children:k.envVar})]})]}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[ee!=="none"&&e.jsxs("span",{className:"chip",children:["source: ",ee]}),I&&e.jsxs("span",{className:"chip",children:["key: ",I]}),O&&e.jsx("span",{className:de("chip",O.ok?"text-emerald-100":"text-rose-100"),children:O.ok?`ready (${O.modelCount??0} models)`:"not ready"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>u(C=>({...C,[k.id]:!C[k.id]})),className:"rounded-lg border border-strong bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.08]",title:d[k.id]?"Hide key":"Show key",children:d[k.id]?"Hide":"Show"}),e.jsx("button",{type:"button",onClick:()=>void A(),className:"rounded-lg border border-strong bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.08]",title:"Probe configured models",children:"Probe"})]})]}),e.jsxs("div",{className:"mt-3",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"mb-1.5 block text-caption font-medium uppercase tracking-[0.14em] text-muted",children:"API key (stored locally)"}),e.jsx("input",{value:l[k.id],onChange:C=>{c(S=>({...S,[k.id]:C.target.value})),x(S=>({...S,[k.id]:!0})),j&&w(null)},type:d[k.id]?"text":"password",placeholder:`Paste ${k.label} key`,className:"w-full rounded-xl border border-white/[0.08] bg-black/30 px-3 py-2.5 font-mono text-body text-primary placeholder:text-faint focus:border-[#BFFF00]/40 focus:outline-none"})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>void v(k.id),disabled:!Q,className:"rounded-full bg-[#BFFF00] px-4 py-2 text-body font-semibold text-black transition-colors hover:bg-[#d3ff42] disabled:cursor-not-allowed disabled:opacity-40",children:le?"Saving...":te}),e.jsx("button",{type:"button",onClick:()=>void y(k.id),disabled:!ne,className:"rounded-full border border-strong bg-white/[0.03] px-4 py-2 text-body font-semibold text-primary transition-colors hover:bg-white/[0.06] disabled:cursor-not-allowed disabled:opacity-35",children:"Clear stored"}),e.jsx("span",{className:"text-caption text-muted",children:h[k.id]?"Unsaved changes":" "})]})]})]},k.id)})})]})}function Jr({label:t,description:n,enabled:s,onToggle:r}){return e.jsxs("div",{className:"flex items-start justify-between gap-4 rounded-xl border border-white/[0.08] bg-black/20 px-3 py-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-body font-semibold text-primary",children:t}),e.jsx("p",{className:"mt-1 text-caption leading-relaxed text-secondary",children:n})]}),e.jsx("button",{type:"button",role:"switch","aria-checked":s,onClick:()=>r(!s),className:de("relative inline-flex h-6 w-11 flex-shrink-0 rounded-full border transition-colors",s?"border-lime/35 bg-lime/[0.20]":"border-white/[0.12] bg-white/[0.06]"),children:e.jsx("span",{"aria-hidden":"true",className:de("absolute top-0.5 h-5 w-5 rounded-full transition-all",s?"left-[20px] bg-lime":"left-0.5 bg-white/70")})})]})}function hc({open:t,onClose:n,activeTab:s,onChangeTab:r,demoMode:i,onToggleDemoMode:o,showSyntheticEntities:l,onToggleShowSyntheticEntities:c,onboarding:h,authToken:x=null,embedMode:d=!1}){return e.jsx(kt,{open:t,onClose:n,maxWidth:"max-w-4xl",children:e.jsxs("div",{className:"flex h-full min-h-0 w-full min-w-0 flex-1 flex-col",children:[e.jsxs("div",{className:"w-full border-b border-subtle px-5 py-4 sm:px-6",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-heading font-semibold text-white",children:"Settings"}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:"OrgX connection and provider keys for agent launches."})]}),e.jsx("button",{type:"button",onClick:n,"aria-label":"Close settings",className:"inline-flex h-9 w-9 items-center justify-center rounded-full border border-strong bg-white/[0.03] text-primary transition-colors hover:bg-white/[0.08] hover:text-white",children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 6L6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})})]}),e.jsx("div",{className:"mt-4 inline-flex rounded-full border border-white/[0.10] bg-white/[0.03] p-0.5",role:"tablist","aria-label":"Settings tabs",children:[{id:"orgx",label:"OrgX"},{id:"providers",label:"Provider keys"}].map(u=>{const p=s===u.id;return e.jsx("button",{type:"button",role:"tab","aria-selected":p,onClick:()=>r(u.id),className:de("rounded-full px-3 py-1.5 text-caption font-semibold transition-colors",p?"border border-lime/25 bg-lime/[0.14] text-lime shadow-[0_0_16px_rgba(191,255,0,0.08)]":"border border-transparent text-secondary hover:bg-white/[0.06] hover:text-white"),children:u.label},u.id)})})]}),e.jsx("div",{className:"min-h-0 w-full flex-1 overflow-y-auto px-5 py-4 sm:px-6",children:s==="orgx"?e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"rounded-2xl border border-white/[0.07] bg-white/[0.02] p-4",children:[e.jsx("h3",{className:"text-heading font-semibold text-white",children:"Dashboard visibility"}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:"Control demo data and synthetic entities in the activity and agent surfaces."}),e.jsxs("div",{className:"mt-3 grid gap-3",children:[e.jsx(Jr,{label:"Demo mode",description:"Use local demo initiatives and sessions for walkthroughs.",enabled:i,onToggle:o}),e.jsx(Jr,{label:"Show demo/synthetic entities",description:"Include synthetic initiative IDs (for QA/demo data) in the agent column.",enabled:l,onToggle:c})]})]}),e.jsx(dc,{state:h.state,isStarting:h.isStarting,isSubmittingManual:h.isSubmittingManual,onRefresh:h.refreshStatus,onStartPairing:h.startPairing,onSubmitManualKey:h.submitManualKey,onBackToPairing:h.backToPairing,onUseManualKey:h.setManualMode,onDisconnect:h.disconnect}),e.jsx(mc,{authToken:x,embedMode:d,enabled:t})]}):e.jsx(xc,{authToken:x,embedMode:d,enabled:t})}),e.jsx("div",{className:"w-full border-t border-subtle px-5 py-2.5 sm:px-6",children:e.jsx(fi,{compact:!0})})]})})}const Qr={blocked:0,failed:1,running:2,active:2,queued:3,in_progress:3,pending:4,paused:5,cancelled:6,completed:7,archived:8};function fc(t){if(!t)return 0;const n=Date.parse(t);return Number.isFinite(n)?n:0}function Yr(t){return fc(t.updatedAt??t.lastEventAt??t.startedAt)}function gc(t,n){const s=Qr[(t.status??"").toLowerCase()]??99,r=Qr[(n.status??"").toLowerCase()]??99;return s!==r?s-r:Yr(n)-Yr(t)}function bc(t,n){const s=t.trim().toLowerCase();return s==="failed"||s==="blocked"||n>0?N.red:s==="running"||s==="active"||s==="in_progress"?N.lime:s==="queued"||s==="pending"?N.amber:s==="completed"?N.teal:N.textMuted}function yc(t){switch(t){case"active":return{title:"Active Sessions",subtitle:"Running and queued work across agents."};case"blocked":return{title:"Blocked Sessions",subtitle:"Work that needs attention before it can proceed."};case"failed":return{title:"Failed Sessions",subtitle:"Runs that exited with an error and may need a retry."};default:return{title:"Sessions",subtitle:"All sessions visible to this dashboard."}}}function wc(t,n){var i;const s=(n.status??"").toLowerCase(),r=((i=n.blockers)==null?void 0:i.length)??0;return t==="active"?["running","active","queued","pending","in_progress"].includes(s):t==="blocked"?s==="blocked"||r>0:t==="failed"?s==="failed":!0}function vc({open:t,onClose:n,mode:s,sessions:r,onOpenSession:i,onRunAction:o,onRefetch:l,onSetNotice:c}){const{title:h,subtitle:x}=yc(s),[d,u]=a.useState(""),[p,m]=a.useState(new Set),[j,w]=a.useState(null),[E,v]=a.useState(null),[y,A]=a.useState(null);a.useEffect(()=>{t&&(v(null),A(null))},[t]);const k=a.useMemo(()=>r.filter(M=>wc(s,M)),[s,r]),D=a.useMemo(()=>{const M={};for(const f of k){const R=(f.status??"unknown").toLowerCase();M[R]=(M[R]??0)+1}const L=k.filter(f=>{var R;return(f.status??"").toLowerCase()==="blocked"||(((R=f.blockers)==null?void 0:R.length)??0)>0}).length,C=k.filter(f=>(f.status??"").toLowerCase()==="failed").length,S=k.filter(f=>["running","active","queued","pending","in_progress"].includes((f.status??"").toLowerCase())).length;return{total:k.length,active:S,blocked:L,failed:C,byStatus:M}},[k]),O=a.useMemo(()=>{const M=d.trim().toLowerCase(),L=[...k].sort(gc);return M?L.filter(C=>[C.title,C.agentName,C.agentId,C.runId,C.lastEventSummary].filter(Boolean).join(" ").toLowerCase().includes(M)):L},[d,k]);a.useEffect(()=>{t&&m(M=>{const L=new Set(O.map(S=>S.id)),C=new Set;for(const S of M)L.has(S)&&C.add(S);return C})},[O,t]);const I=p.size,ee=O.length>0&&O.every(M=>p.has(M.id)),X=()=>{j||m(M=>O.length===0?M:ee?new Set:new Set(O.map(L=>L.id)))},le=M=>{j||m(L=>{const C=new Set(L);return C.has(M)?C.delete(M):C.add(M),C})},Q=async()=>{if(I===0||j)return;const M=[];for(const C of O){if(!p.has(C.id))continue;const S=C.blockers??[];if(S.length!==0){M.push(`- ${C.title} (${S.length} blocker${S.length===1?"":"s"})`);for(const f of S)M.push(` - ${f}`)}}const L=M.length>0?M.join(`
213
- `):"No blockers found for selected sessions.";try{await navigator.clipboard.writeText(L),v("Copied blockers to clipboard.")}catch{v("Copy failed (clipboard unavailable).")}},ne=async M=>{if(I===0||j)return;if(M==="cancel"){A({text:""});return}const L=O.filter(f=>p.has(f.id));v(null),w({action:M,processed:0,total:L.length});let C=0;for(const f of L)try{await o(f,M)}catch{C+=1}finally{w(R=>R&&{...R,processed:Math.min(R.total,R.processed+1)})}const S=L.length-C;w(null),C>0?v(`${M} finished: ${S} ok, ${C} failed.`):v(`${M} finished: ${S} session${S===1?"":"s"}.`);try{await l()}catch{}M==="resume"?c(`Bulk resume requested: ${S} ok${C?`, ${C} failed`:""}.`):M==="pause"&&c(`Bulk pause requested: ${S} ok${C?`, ${C} failed`:""}.`)},te=async()=>{if(!y||j||y.text.trim().toUpperCase()!=="CANCEL")return;const M=O.filter(S=>p.has(S.id));v(null),w({action:"cancel",processed:0,total:M.length}),A(null);let L=0;for(const S of M)try{await o(S,"cancel")}catch{L+=1}finally{w(f=>f&&{...f,processed:Math.min(f.total,f.processed+1)})}const C=M.length-L;w(null),v(`cancel finished: ${C} ok${L?`, ${L} failed`:""}.`),c(`Bulk cancel requested: ${C} ok${L?`, ${L} failed`:""}.`);try{await l()}catch{}};return e.jsx(kt,{open:t,onClose:n,maxWidth:"max-w-4xl",children:e.jsxs("div",{className:"flex h-full w-full flex-col",children:[e.jsxs("div",{className:"border-b border-subtle px-5 pt-5 pb-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("h3",{className:"inline-flex items-center gap-2 text-heading font-semibold text-white",children:[e.jsx(Oe,{type:"session",size:14}),e.jsx("span",{className:"truncate",children:h}),e.jsx("span",{className:"rounded-full border border-strong bg-white/[0.04] px-2 py-0.5 text-caption font-semibold text-primary",children:D.total})]}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:x}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-1.5",children:[e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.1] bg-white/[0.03] px-2 py-0.5 text-micro text-secondary",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full",style:{backgroundColor:N.teal}}),"Total ",e.jsx("span",{className:"font-semibold text-white",children:D.total})]}),e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.1] bg-white/[0.03] px-2 py-0.5 text-micro text-secondary",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full",style:{backgroundColor:D.active>0?N.lime:N.textMuted}}),"Active ",e.jsx("span",{className:"font-semibold text-white",children:D.active})]}),e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.1] bg-white/[0.03] px-2 py-0.5 text-micro text-secondary",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full",style:{backgroundColor:D.blocked>0?N.red:N.textMuted}}),"Blocked ",e.jsx("span",{className:"font-semibold text-white",children:D.blocked})]}),e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.1] bg-white/[0.03] px-2 py-0.5 text-micro text-secondary",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full",style:{backgroundColor:D.failed>0?N.red:N.textMuted}}),"Failed ",e.jsx("span",{className:"font-semibold text-white",children:D.failed})]})]})]}),e.jsx("button",{type:"button",onClick:n,className:"rounded-md border border-strong bg-white/[0.03] px-2.5 py-1.5 text-caption text-primary transition-colors hover:bg-white/[0.08]","aria-label":"Close bulk modal",children:"Close"})]}),e.jsxs("div",{className:"mt-4 flex flex-col gap-2 sm:flex-row sm:items-center",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("label",{className:"sr-only",htmlFor:"bulk-sessions-search",children:"Search sessions"}),e.jsx("input",{id:"bulk-sessions-search",value:d,onChange:M=>u(M.target.value),placeholder:"Search title, agent, run id…","data-modal-autofocus":"true",className:"w-full rounded-lg border border-strong bg-black/25 px-3 py-2 text-body text-white placeholder:text-muted focus:outline-none focus:ring-1 focus:ring-[#BFFF00]/35"})]}),e.jsx("button",{type:"button",onClick:X,disabled:O.length===0||!!j,className:"rounded-lg border border-strong bg-white/[0.03] px-3 py-2 text-caption text-primary transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:ee?"Clear all":`Select all (${O.length})`})]}),E&&e.jsx("div",{className:"mt-3 rounded-xl border border-white/[0.08] bg-white/[0.02] px-3 py-2 text-body text-secondary",children:E}),y&&e.jsxs("div",{className:"mt-3 rounded-xl border border-red-400/25 bg-red-500/[0.06] px-3 py-2.5",children:[e.jsxs("p",{className:"text-body font-semibold text-red-200",children:["Cancel ",I," session",I===1?"":"s","?"]}),e.jsxs("p",{className:"mt-1 text-caption text-red-200/70",children:["This is destructive. Type ",e.jsx("span",{className:"font-semibold",children:"CANCEL"})," to confirm."]}),e.jsxs("div",{className:"mt-2 flex flex-col gap-2 sm:flex-row sm:items-center",children:[e.jsx("input",{value:y.text,onChange:M=>A({text:M.target.value}),placeholder:"CANCEL",className:"flex-1 rounded-lg border border-red-300/25 bg-black/30 px-3 py-2 text-body text-white placeholder:text-muted focus:outline-none focus:ring-1 focus:ring-red-300/40"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>A(null),className:"rounded-lg border border-strong bg-white/[0.03] px-3 py-2 text-caption text-primary transition-colors hover:bg-white/[0.08]",children:"Back"}),e.jsx("button",{type:"button",onClick:te,disabled:y.text.trim().toUpperCase()!=="CANCEL",className:"rounded-lg border border-red-300/25 bg-red-500/15 px-3 py-2 text-caption font-semibold text-red-200 transition-colors hover:bg-red-500/20 disabled:opacity-45",children:"Confirm cancel"})]})]})]})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-5 py-4",children:O.length===0?e.jsx("div",{className:"rounded-xl border border-subtle bg-white/[0.02] p-4 text-body text-secondary",children:"No sessions match this view."}):e.jsx("div",{className:"space-y-2",children:O.map(M=>{const L=p.has(M.id),C=M.blockers??[],S=bc(M.status??"",C.length),f=M.updatedAt??M.lastEventAt??M.startedAt,R=[(M.agentName??M.agentId??"").trim()||"Unknown agent",(M.status??"unknown").toLowerCase(),f?Ge(f):null].filter(Boolean);return e.jsx("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.02] px-3 py-2.5 transition-colors hover:bg-white/[0.04]",style:{borderColor:L?`${N.lime}40`:"rgba(255,255,255,0.08)"},children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("input",{type:"checkbox",checked:L,onChange:()=>le(M.id),disabled:!!j,className:"mt-0.5 h-4 w-4 rounded border-white/20 bg-black/40 text-lime focus:ring-lime/40","aria-label":`Select session ${M.title}`}),e.jsx("button",{type:"button",onClick:()=>i(M),disabled:!!j,className:"min-w-0 flex-1 text-left",title:"Open session inspector",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-body font-medium text-white",children:M.title}),e.jsx("p",{className:"mt-0.5 text-caption text-secondary",children:R.join(" · ")}),M.lastEventSummary&&e.jsx("p",{className:"mt-1 line-clamp-2 text-caption text-secondary",children:M.lastEventSummary}),C.length>0&&e.jsxs("p",{className:"mt-1 text-micro text-red-200/80",children:[C.length," blocker",C.length===1?"":"s"," · ",C[0]]})]}),e.jsx("span",{className:"shrink-0 rounded-full border px-2 py-0.5 text-micro font-semibold uppercase tracking-[0.08em]",style:{borderColor:`${S}30`,backgroundColor:`${S}14`,color:S},children:(M.status??"unknown").toUpperCase()})]})})]})},M.id)})})}),e.jsxs("div",{className:"flex flex-col gap-2 border-t border-subtle px-5 py-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2 text-caption text-secondary",children:[j?e.jsxs("span",{children:[j.action," ",j.processed,"/",j.total]}):e.jsx("span",{children:I>0?`${I} selected`:"No selection"}),s==="blocked"&&e.jsx("button",{type:"button",onClick:Q,disabled:I===0||!!j,className:"rounded-md border border-strong bg-white/[0.03] px-2.5 py-1.5 text-caption text-secondary transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:"Copy blockers"})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:()=>{const M=O.find(L=>p.has(L.id))??null;M&&i(M)},disabled:I!==1||!!j,className:"rounded-md border border-strong bg-white/[0.03] px-3 py-1.5 text-caption text-primary transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:"Open inspector"}),e.jsx("button",{type:"button",onClick:()=>void ne("resume"),disabled:I===0||!!j,className:"rounded-md border border-lime/25 bg-lime/10 px-3 py-1.5 text-caption font-semibold text-lime transition-colors hover:bg-lime/20 disabled:opacity-45",children:"Resume selected"}),e.jsx("button",{type:"button",onClick:()=>void ne("pause"),disabled:I===0||!!j,className:"rounded-md border border-strong bg-white/[0.03] px-3 py-1.5 text-caption text-primary transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:"Pause selected"}),e.jsx("button",{type:"button",onClick:()=>void ne("cancel"),disabled:I===0||!!j,className:"rounded-md border border-red-300/25 bg-red-500/10 px-3 py-1.5 text-caption font-semibold text-red-200 transition-colors hover:bg-red-500/15 disabled:opacity-45",children:"Cancel selected"})]})]})]})})}function jc({open:t,onClose:n,decisions:s,onApproveDecision:r,onRejectDecision:i,onApproveAll:o}){const l=a.useMemo(()=>s.length>0?Math.max(0,...s.map(h=>h.waitingMinutes)):0,[s]),c=a.useMemo(()=>s.length>=20||l>=15?N.red:s.length>0?N.amber:N.textMuted,[s.length,l]);return e.jsx(kt,{open:t,onClose:n,maxWidth:"max-w-3xl",children:e.jsxs("div",{className:"flex h-full w-full flex-col",children:[e.jsx("div",{className:"border-b border-subtle px-5 pt-5 pb-4",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("h3",{className:"inline-flex items-center gap-2 text-heading font-semibold text-white",children:[e.jsx(Oe,{type:"decision",size:14}),e.jsx("span",{className:"truncate",children:"Decisions"}),e.jsx("span",{className:"rounded-full border px-2 py-0.5 text-caption font-semibold",style:{borderColor:`${c}30`,backgroundColor:`${c}14`,color:c},children:s.length})]}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:"Bulk review and resolve pending decisions."}),s.length>0&&e.jsxs("p",{className:"mt-2 text-caption text-secondary",children:["Longest waiting: ",e.jsxs("span",{className:"font-semibold text-white",children:[l,"m"]})]})]}),e.jsx("button",{type:"button",onClick:n,className:"rounded-md border border-strong bg-white/[0.03] px-2.5 py-1.5 text-caption text-primary transition-colors hover:bg-white/[0.08]","aria-label":"Close decisions modal",children:"Close"})]})}),e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden p-4",children:e.jsx(Ei,{decisions:s,onApproveDecision:r,onRejectDecision:i,onApproveAll:o})})]})})}function Zr(t){if(!t)return"unknown";try{return Ge(t)}catch{return"unknown"}}function kc({open:t,onClose:n,outbox:s,onOpenSettings:r,onRefresh:i}){const[o,l]=a.useState(!1),c=a.useMemo(()=>Object.entries(s.pendingByQueue??{}).filter(([,u])=>typeof u=="number"&&u>0).sort((u,p)=>p[1]-u[1]),[s.pendingByQueue]),h=a.useMemo(()=>s.replayStatus==="error"?N.red:s.pendingTotal>0?N.amber:N.textMuted,[s.pendingTotal,s.replayStatus]),x=async()=>{try{await navigator.clipboard.writeText(JSON.stringify(s,null,2)),l(!0),setTimeout(()=>l(!1),1200)}catch{}};return e.jsx(kt,{open:t,onClose:n,maxWidth:"max-w-3xl",fitContent:!0,children:e.jsxs("div",{className:"flex w-full flex-col",children:[e.jsxs("div",{className:"border-b border-subtle px-5 pt-5 pb-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("h3",{className:"inline-flex items-center gap-2 text-heading font-semibold text-white",children:[e.jsx(Oe,{type:"outbox",size:14}),e.jsx("span",{className:"truncate",children:"Outbox"}),e.jsx("span",{className:"rounded-full border px-2 py-0.5 text-caption font-semibold",style:{borderColor:`${h}30`,backgroundColor:`${h}14`,color:h},children:s.pendingTotal})]}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:"Buffered updates queued for replay to OrgX when connectivity is healthy."})]}),e.jsx("button",{type:"button",onClick:n,className:"rounded-md border border-strong bg-white/[0.03] px-2.5 py-1.5 text-caption text-primary transition-colors hover:bg-white/[0.08]","aria-label":"Close outbox modal",children:"Close"})]}),e.jsxs("div",{className:"mt-3 grid grid-cols-1 gap-2 sm:grid-cols-2",children:[e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.02] px-3 py-2",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-secondary",children:"Replay status"}),e.jsx("p",{className:"mt-1 text-body font-semibold",style:{color:h},children:s.replayStatus}),s.lastReplayError&&s.replayStatus==="error"&&e.jsx("p",{className:"mt-1 line-clamp-2 text-caption text-red-200/75",children:s.lastReplayError})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.02] px-3 py-2",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-secondary",children:"Window"}),e.jsxs("p",{className:"mt-1 text-caption text-primary",children:["Oldest: ",e.jsx("span",{className:"font-semibold text-white",children:Zr(s.oldestEventAt)})]}),e.jsxs("p",{className:"mt-0.5 text-caption text-primary",children:["Newest: ",e.jsx("span",{className:"font-semibold text-white",children:Zr(s.newestEventAt)})]})]})]})]}),e.jsx("div",{className:"px-5 py-4",children:s.pendingTotal===0?e.jsx("div",{className:"rounded-xl border border-subtle bg-white/[0.02] p-4 text-body text-secondary",children:"Outbox is empty."}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-caption font-semibold uppercase tracking-[0.12em] text-secondary",children:"Queues"}),e.jsx("button",{type:"button",onClick:x,className:"rounded-md border border-strong bg-white/[0.03] px-2.5 py-1.5 text-caption text-secondary transition-colors hover:bg-white/[0.08]",children:o?"Copied":"Copy JSON"})]}),e.jsx("div",{className:"space-y-1.5",children:c.map(([d,u])=>e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-xl border border-white/[0.08] bg-white/[0.02] px-3 py-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-body font-medium text-white",children:d}),e.jsxs("p",{className:"mt-0.5 text-micro text-secondary",children:[u," event",u===1?"":"s"]})]}),e.jsx("span",{className:"rounded-full border px-2 py-0.5 text-caption font-semibold",style:{borderColor:`${N.amber}30`,backgroundColor:`${N.amber}14`,color:N.amber},children:u})]},d))}),e.jsx("div",{className:"rounded-xl border border-subtle bg-white/[0.02] px-3 py-2 text-caption text-secondary",children:"Replay is handled automatically by the OrgX sync service. If events stay queued, check Settings for API key and last replay errors."})]})}),e.jsxs("div",{className:"flex items-center justify-end gap-2 border-t border-subtle px-5 py-3",children:[e.jsx("button",{type:"button",onClick:i,className:"rounded-md border border-strong bg-white/[0.03] px-3 py-1.5 text-caption text-primary transition-colors hover:bg-white/[0.08]",children:"Refresh"}),e.jsx("button",{type:"button",onClick:r,className:"rounded-md border border-lime/25 bg-lime/10 px-3 py-1.5 text-caption font-semibold text-lime transition-colors hover:bg-lime/20",children:"Open settings"})]})]})})}function Nc(t){const n=t.trim().toLowerCase();return n==="fulfilled"||n==="completed"?N.lime:n==="claimed"?N.teal:n==="blocked"?N.red:N.amber}function Sc({open:t,onClose:n,handoffs:s}){const[r,i]=a.useState(""),[o,l]=a.useState(new Set),[c,h]=a.useState(null);a.useEffect(()=>{t&&h(null)},[t]);const x=a.useMemo(()=>[...s].sort((v,y)=>Date.parse(y.updatedAt??"")-Date.parse(v.updatedAt??"")),[s]),d=a.useMemo(()=>{const v=r.trim().toLowerCase();return v?x.filter(y=>[y.title,y.summary,y.status,y.priority].filter(Boolean).join(" ").toLowerCase().includes(v)):x},[x,r]);a.useEffect(()=>{t&&l(v=>{const y=new Set(d.map(k=>k.id)),A=new Set;for(const k of v)y.has(k)&&A.add(k);return A})},[d,t]);const u=o.size,p=d.length>0&&d.every(v=>o.has(v.id)),m=()=>{l(v=>d.length===0?v:p?new Set:new Set(d.map(y=>y.id)))},j=v=>{l(y=>{const A=new Set(y);return A.has(v)?A.delete(v):A.add(v),A})},w=async()=>{const v=d.filter(k=>u===0||o.has(k.id)),y=[];y.push(`# Handoffs (${v.length})`),y.push("");for(const k of v)y.push(`- **${k.title}** — ${k.status}${k.priority?` (priority: ${k.priority})`:""}`),k.summary&&y.push(` - ${k.summary}`),y.push(` - Updated: ${k.updatedAt}`);const A=y.join(`
214
- `);try{await navigator.clipboard.writeText(A),h("Copied markdown."),setTimeout(()=>h(null),1200)}catch{h("Copy failed (clipboard unavailable).")}},E=async()=>{const v=d.filter(y=>u===0||o.has(y.id));try{await navigator.clipboard.writeText(JSON.stringify(v,null,2)),h("Copied JSON."),setTimeout(()=>h(null),1200)}catch{h("Copy failed (clipboard unavailable).")}};return e.jsx(kt,{open:t,onClose:n,maxWidth:"max-w-3xl",children:e.jsxs("div",{className:"flex h-full w-full flex-col",children:[e.jsxs("div",{className:"border-b border-subtle px-5 pt-5 pb-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("h3",{className:"inline-flex items-center gap-2 text-heading font-semibold text-white",children:[e.jsx(Oe,{type:"handoff",size:14}),e.jsx("span",{className:"truncate",children:"Handoffs"}),e.jsx("span",{className:"rounded-full border border-strong bg-white/[0.04] px-2 py-0.5 text-caption font-semibold text-primary",children:s.length})]}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:"Review and export current handoffs. Select items for a tighter export."})]}),e.jsx("button",{type:"button",onClick:n,className:"rounded-md border border-strong bg-white/[0.03] px-2.5 py-1.5 text-caption text-primary transition-colors hover:bg-white/[0.08]","aria-label":"Close handoffs modal",children:"Close"})]}),e.jsxs("div",{className:"mt-4 flex flex-col gap-2 sm:flex-row sm:items-center",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("label",{className:"sr-only",htmlFor:"bulk-handoffs-search",children:"Search handoffs"}),e.jsx("input",{id:"bulk-handoffs-search",value:r,onChange:v=>i(v.target.value),placeholder:"Search title, summary, status…","data-modal-autofocus":"true",className:"w-full rounded-lg border border-strong bg-black/25 px-3 py-2 text-body text-white placeholder:text-muted focus:outline-none focus:ring-1 focus:ring-[#BFFF00]/35"})]}),e.jsx("button",{type:"button",onClick:m,disabled:d.length===0,className:"rounded-lg border border-strong bg-white/[0.03] px-3 py-2 text-caption text-primary transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:p?"Clear all":`Select all (${d.length})`})]}),c&&e.jsx("div",{className:"mt-3 rounded-xl border border-white/[0.08] bg-white/[0.02] px-3 py-2 text-body text-secondary",children:c})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-5 py-4",children:d.length===0?e.jsx("div",{className:"rounded-xl border border-subtle bg-white/[0.02] p-4 text-body text-secondary",children:"No handoffs match this view."}):e.jsx("div",{className:"space-y-2",children:d.map(v=>{const y=o.has(v.id),A=Nc(v.status);return e.jsx("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.02] px-3 py-2.5",style:{borderColor:y?`${N.lime}40`:"rgba(255,255,255,0.08)"},children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("input",{type:"checkbox",checked:y,onChange:()=>j(v.id),className:"mt-0.5 h-4 w-4 rounded border-white/20 bg-black/40 text-lime focus:ring-lime/40","aria-label":`Select handoff ${v.title}`}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-body font-medium text-white",children:v.title}),v.summary&&e.jsx("p",{className:"mt-1 line-clamp-2 text-caption text-secondary",children:v.summary}),e.jsxs("p",{className:"mt-1 text-micro text-secondary",children:["Updated ",Ge(v.updatedAt)]})]}),e.jsx("span",{className:"shrink-0 rounded-full border px-2 py-0.5 text-micro font-semibold uppercase tracking-[0.08em]",style:{borderColor:`${A}30`,backgroundColor:`${A}14`,color:A},children:v.status})]})})]})},v.id)})})}),e.jsxs("div",{className:"flex flex-col gap-2 border-t border-subtle px-5 py-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx("div",{className:"text-caption text-secondary",children:u>0?`${u} selected`:"No selection (exporting will include all filtered handoffs)"}),e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:w,disabled:d.length===0,className:"rounded-md border border-strong bg-white/[0.03] px-3 py-1.5 text-caption text-primary transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:"Copy markdown"}),e.jsx("button",{type:"button",onClick:E,disabled:d.length===0,className:"rounded-md border border-strong bg-white/[0.03] px-3 py-1.5 text-caption text-primary transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:"Copy JSON"})]})]})]})})}const Ps={draft:N.textMuted,in_review:N.amber,approved:N.lime,changes_requested:N.red,superseded:N.textMuted,archived:N.textMuted},Cc={draft:"Draft",in_review:"In Review",approved:"Approved",changes_requested:"Changes Requested",superseded:"Superseded",archived:"Archived"};function Ac(){return e.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:N.cyan,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"}),e.jsx("path",{d:"M14 2v4a2 2 0 0 0 2 2h4"}),e.jsx("path",{d:"M10 9H8"}),e.jsx("path",{d:"M16 13H8"}),e.jsx("path",{d:"M16 17H8"})]})}function Ic(){var A,k,D,O,I,ee;const{state:t,close:n}=Si(),s=null,r=!1,[i,o]=a.useState(null),{data:l,isLoading:c,isFetching:h,error:x,refetch:d}=Et({queryKey:zt.artifactDetail({artifactId:t.artifactId??"",authToken:s,embedMode:r}),enabled:!!t.artifactId,queryFn:async()=>{const X=ut({authToken:s,embedMode:r}),le=await fetch(`/orgx/api/artifacts/${encodeURIComponent(t.artifactId)}`,{headers:X});if(!le.ok){const Q=await le.json().catch(()=>null),ne=(typeof(Q==null?void 0:Q.error)=="string"?Q.error:null)??(Q!=null&&Q.error&&typeof Q.error=="object"&&typeof Q.error.message=="string"?Q.error.message:null)??(typeof(Q==null?void 0:Q.message)=="string"?Q.message:null),te=le.status===401?"Authentication required to view this artifact.":`Failed to fetch artifact (${le.status}).`;throw new Error(ne!=null&&ne.trim().length?ne.trim():te)}return le.json()}}),u=l==null?void 0:l.artifact,p=(l==null?void 0:l.localFallback)===!0||((A=u==null?void 0:u.metadata)==null?void 0:A.local_fallback)===!0,m=(typeof(l==null?void 0:l.warning)=="string"&&l.warning.trim().length>0?l.warning:(k=u==null?void 0:u.metadata)==null?void 0:k.local_warning)??null,j=((D=u==null?void 0:u.metadata)==null?void 0:D.preview_markdown)??null,w=a.useMemo(()=>{if(!(u!=null&&u.metadata))return null;const X=[u.metadata.local_source_path,u.metadata.url,u.metadata.path,u.metadata.file_path,u.metadata.filepath,u.metadata.artifact_path,u.metadata.output_path];for(const le of X)if(typeof le=="string"&&le.trim().length>0)return le.trim();return null},[u==null?void 0:u.metadata]),E=a.useMemo(()=>w?/^https?:\/\//i.test(w)?w:`/orgx/api/live/filesystem/open?path=${encodeURIComponent(w)}`:null,[w]),v=((O=u==null?void 0:u.metadata)==null?void 0:O.external_url)??(u==null?void 0:u.artifact_url);a.useEffect(()=>{if(!i)return;const X=window.setTimeout(()=>o(null),2e3);return()=>window.clearTimeout(X)},[i]);const y=async(X,le)=>{try{await navigator.clipboard.writeText(X),o(`${le} copied`)}catch{o("Copy failed")}};return e.jsxs(kt,{open:!!t.artifactId,onClose:n,maxWidth:"max-w-3xl",children:[c&&e.jsxs("div",{className:"p-6 space-y-4",children:[e.jsx(gt,{className:"h-6 w-2/3"}),e.jsx(gt,{className:"h-4 w-1/3"}),e.jsx(gt,{className:"h-32 w-full"})]}),x&&e.jsxs("div",{className:"space-y-4 p-6",children:[e.jsxs("div",{className:"rounded-xl border border-red-300/22 bg-red-500/[0.08] p-4",children:[e.jsx("p",{className:"text-body font-semibold text-red-200",children:"Failed to load artifact"}),e.jsx("p",{className:"mt-1 text-caption leading-relaxed text-red-100/80",children:x.message})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",onClick:n,className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.08]",children:"Back to activity"}),e.jsx("button",{type:"button",onClick:()=>void d(),disabled:h,className:"rounded-full border border-red-300/22 bg-red-500/[0.08] px-3 py-1.5 text-caption font-semibold text-red-100 transition-colors hover:bg-red-500/[0.14] disabled:opacity-45",children:h?"Retrying…":"Retry"})]})]}),u&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-subtle px-5 py-4 sm:px-6",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx(Ac,{}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"truncate text-sm font-medium text-white",children:u.name}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[e.jsx(Tt,{tone:"muted",className:"text-micro uppercase tracking-[0.06em]",children:((I=u.catalog)==null?void 0:I.label)??u.artifact_type}),e.jsx(Tt,{tone:"neutral",className:"text-micro font-semibold uppercase tracking-[0.06em]",style:{color:Ps[u.status]??N.textMuted,backgroundColor:`${Ps[u.status]??N.textMuted}20`,borderColor:`${Ps[u.status]??N.textMuted}44`},children:Cc[u.status]??u.status}),((ee=u.catalog)==null?void 0:ee.domain)&&e.jsxs("span",{className:"text-micro text-faint",children:[u.catalog.domain," / ",u.catalog.stage]}),i&&e.jsx(Tt,{tone:"neutral",className:"text-micro text-secondary",children:i})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[v&&e.jsx("a",{href:v,target:"_blank",rel:"noopener noreferrer",className:"rounded-lg p-2 text-secondary transition-colors hover:bg-white/[0.08] hover:text-white",title:"Open source",children:e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M15 3h6v6"}),e.jsx("path",{d:"M10 14 21 3"}),e.jsx("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"})]})}),e.jsx("button",{onClick:n,className:"p-2 rounded-lg hover:bg-white/[0.06] text-secondary hover:text-white transition-colors",children:e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 6 6 18"}),e.jsx("path",{d:"m6 6 12 12"})]})})]})]}),e.jsxs("div",{className:"max-h-[65vh] overflow-y-auto px-5 py-4 sm:px-6 space-y-4",children:[p&&e.jsxs("div",{className:"rounded-xl border border-amber-300/25 bg-amber-500/[0.09] p-4",children:[e.jsx("p",{className:"text-caption font-semibold uppercase tracking-[0.08em] text-amber-100/90",children:"Local fallback artifact"}),e.jsx("p",{className:"mt-1 text-body text-amber-50/90",children:"This artifact is buffered locally because OrgX registration is currently unavailable."}),m&&e.jsxs("p",{className:"mt-1.5 text-caption text-amber-100/70",children:["Upstream error: ",m]}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[E&&e.jsx("a",{href:E,target:"_blank",rel:"noopener noreferrer",className:"rounded-full border border-amber-200/25 bg-black/25 px-3 py-1 text-caption font-semibold text-amber-100 transition-colors hover:bg-black/35",children:"Open local artifact"}),w&&e.jsx("button",{type:"button",onClick:()=>void y(w,"Artifact path"),className:"rounded-full border border-amber-200/25 bg-black/20 px-3 py-1 text-caption font-semibold text-amber-100 transition-colors hover:bg-black/35",children:"Copy path"})]})]}),u.description&&e.jsx("div",{children:e.jsx("p",{className:"text-body leading-relaxed text-primary",children:u.description})}),j&&e.jsx("div",{className:"rounded-xl border border-white/[0.06] bg-white/[0.02] p-4",children:e.jsx(cn,{mode:"block",text:j,className:"text-body leading-relaxed text-primary"})}),!u.description&&!j&&e.jsxs("div",{className:"py-12 text-center text-muted",children:[e.jsxs("svg",{className:"mx-auto mb-3 opacity-50",width:"32",height:"32",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"}),e.jsx("path",{d:"M14 2v4a2 2 0 0 0 2 2h4"})]}),e.jsx("p",{className:"text-sm",children:"No preview available"})]}),e.jsxs("div",{className:"flex flex-wrap gap-x-6 gap-y-1.5 text-micro text-faint",children:[e.jsxs("span",{children:["Entity: ",u.entity_type,"/",u.entity_id.slice(0,8)]}),e.jsxs("span",{children:["Version: ",u.version]}),e.jsxs("span",{children:["Updated:"," ",new Date(u.updated_at).toLocaleDateString(void 0,{month:"short",day:"numeric",year:"numeric"})]})]})]})]})]})}const _c=a.lazy(async()=>({default:(await Jn(()=>import("./iFdvE7lx.js"),__vite__mapDeps([0,1,2,3,4]))).MissionControlView})),Mc=a.lazy(async()=>({default:(await Jn(()=>import("./jRJsmpYM.js"),__vite__mapDeps([5,1,2,3,4]))).SessionInspector})),ei={connected:"Live",reconnecting:"Reconnecting",disconnected:"Offline"},Ec={connected:N.lime,reconnecting:N.amber,disconnected:N.red},Ds="orgx.mission_control.welcome.dismissed",Bs="orgx.demo_mode",Rs="orgx.show_synthetic_entities",Os="orgx.first_run_guide.shown_session",qs="orgx.dashboard.sidebar.nextup.compact",ti={blocked:0,pending:1,queued:2,running:3,failed:4,cancelled:5,completed:6,archived:7},ni=new Set(["running","active","queued","pending","in_progress","working","planning"]);function Bt(t){if(!t)return 0;const n=Date.parse(t);return Number.isFinite(n)?n:0}function Fc(t){const n=Bt(t);if(!n)return"unknown";try{return new Date(n).toLocaleString()}catch{return"unknown"}}function zs(t,n){const s=ti[t.status]??99,r=ti[n.status]??99;return s!==r?s-r:Bt(t.updatedAt??t.lastEventAt??t.startedAt)-Bt(n.updatedAt??n.lastEventAt??n.startedAt)}function $c(t){const n=t.toLowerCase();return n==="blocked"||n==="failed"?"blocked":n==="running"||n==="active"||n==="in_progress"?"working":n==="pending"||n==="queued"?"waiting":n==="completed"||n==="done"?"done":"idle"}function Tc(){const t=Sa();return t.showGate?e.jsx(za,{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(il,{children:e.jsx(Bc,{onboarding:t})})}function Lc(t){const n=t.toLowerCase();return/market|email|campaign|content|brand/.test(n)?"Marketing":/product|feature|ux|discovery/.test(n)?"Product":/engineer|infra|platform|api|backend|frontend|dev/.test(n)?"Engineering":"Program"}function Pc(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 si(t){const n=(t??"").trim().toLowerCase();return n?n==="critical"||n==="p0"||n==="urgent"?0:n==="high"||n==="p1"?1:n==="medium"||n==="normal"||n==="p2"?2:n==="low"||n==="p3"?3:4:4}function ri(t){const n=(t??"").trim().toLowerCase();return n?!["deleted","archived","cancelled"].includes(n):!0}function Dc(){return e.jsx("span",{className:"inline-flex h-6 w-6 items-center justify-center rounded-lg border border-strong bg-white/[0.04] p-0.5",children:e.jsx("img",{src:as,alt:"OrgX",className:"h-full w-full rounded-md object-contain"})})}function Bc({onboarding:t}){const[n,s]=a.useState(()=>{if(typeof window>"u")return!1;if(new URLSearchParams(window.location.search).get("demo")==="1")return!0;try{return window.localStorage.getItem(Bs)==="1"}catch{return!1}}),[r,i]=a.useState(()=>{if(typeof window>"u")return!1;try{return window.localStorage.getItem(Rs)==="1"}catch{return!1}}),[o,l]=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"}),c=a.useCallback(g=>{l(g);try{localStorage.setItem("orgx-dashboard-view",g)}catch{}},[]),h=n||t.state.hasApiKey&&t.state.connectionVerified,x=a.useMemo(()=>o==="mission-control"?{maxSessions:240,maxActivityItems:120,maxHandoffs:60,maxDecisions:80,batchWindowMs:140}:{maxSessions:320,maxActivityItems:80,maxHandoffs:80,maxDecisions:80,batchWindowMs:120},[o]),{data:d,isLoading:u,error:p,refetch:m,approveDecision:j,rejectDecision:w,approveAllDecisions:E}=ha({useMock:n,enabled:!0,enableDecisions:h,...x}),v=h&&d.connection==="connected",[y,A]=a.useState(null),[k,D]=a.useState(!1),[O,I]=a.useState(null),[ee,X]=a.useState(null),[le,Q]=a.useState(null),[ne,te]=a.useState("30m"),[M,L]=a.useState(null),[C,S]=a.useState(null),[f,R]=a.useState(!1),[V,H]=a.useState([]),G=a.useRef(null),Y=a.useRef(null),[ie,J]=a.useState({open:!1,tab:"orgx"}),[Fe,he]=a.useState(null),[fe,et]=a.useState(!1),[W,F]=a.useState("agents"),[Z,ae]=a.useState("decisions"),[xe,_e]=a.useState(()=>typeof window>"u"?!1:window.localStorage.getItem(qs)==="1"),[Qe,mt]=a.useState("next_up"),[Nt,q]=a.useState(()=>typeof window>"u"?!1:window.localStorage.getItem(Ds)==="1"),ve=a.useMemo(()=>{const g=new Set(["running","active","in_progress","working","planning","dispatching","blocked"]);let $=0;for(const U of d.sessions.nodes){const _=bt(U.status??"");_==="queued"||_==="pending"||(g.has(_)||U.lastHeartbeatAt)&&($+=1)}return $},[d.sessions.nodes]);a.useEffect(()=>{Qe==="in_progress"&&ve===0&&mt("next_up")},[Qe,ve]),a.useEffect(()=>{if(!(typeof window>"u"))try{xe?window.localStorage.setItem(qs,"1"):window.localStorage.removeItem(qs)}catch{}},[xe]),a.useEffect(()=>{typeof window>"u"||(Nt?window.localStorage.setItem(Ds,"1"):window.localStorage.removeItem(Ds))},[Nt]),a.useEffect(()=>{if(!(typeof window>"u"))try{n?window.localStorage.setItem(Bs,"1"):window.localStorage.removeItem(Bs)}catch{}},[n]),a.useEffect(()=>{if(!(typeof window>"u"))try{r?window.localStorage.setItem(Rs,"1"):window.localStorage.removeItem(Rs)}catch{}},[r]),a.useEffect(()=>{if(!(typeof window>"u")&&!fe&&!Wa()){try{if(window.sessionStorage.getItem(Os)==="1")return}catch{}if(n||t.state.connectionVerified){et(!0);try{window.sessionStorage.setItem(Os,"1")}catch{}}}},[n,fe,t.state.connectionVerified]);const ue=a.useCallback(g=>{J($=>({open:!0,tab:g??$.tab}))},[]),je=a.useCallback(g=>{if(s(g),!(typeof window>"u"))try{const $=new URL(window.location.href);g?$.searchParams.set("demo","1"):$.searchParams.delete("demo"),window.history.replaceState(null,"",`${$.pathname}${$.search}${$.hash}`)}catch{}},[]),Re=a.useCallback(()=>{ue("orgx")},[ue]),qe=a.useCallback(()=>{Jn(()=>import("./iFdvE7lx.js"),__vite__mapDeps([0,1,2,3,4]))},[]),{data:ge}=wi(o==="mission-control"),{data:Xe}=ic(o==="mission-control"),{data:nt=[]}=Et({queryKey:["initiative-tombstones"],queryFn:async()=>[],initialData:[],staleTime:Number.POSITIVE_INFINITY}),[Ve,tt]=a.useState(null),[ze,Ue]=a.useState(""),[st,ot]=a.useState(!1),pt=a.useCallback((g,$)=>{tt({type:g,initiativeId:$}),Ue(""),ot(!1)},[]),St=a.useCallback(()=>{tt(null),Ue(""),ot(!1)},[]),z=a.useCallback(()=>{I(null)},[]),ce=a.useCallback(()=>{X(null),Q(null)},[]),ke=a.useCallback(()=>{L(null)},[]);a.useEffect(()=>{var U;const g=((U=d.sessions.nodes[0])==null?void 0:U.id)??null;if(!g){y!==null&&A(null);return}if(y===null){A(g);return}d.sessions.nodes.some(_=>_.id===y)||A(g)},[d.sessions.nodes,y]),a.useEffect(()=>{if(!O)return;d.sessions.nodes.some($=>$.id===O)||I(null)},[O,d.sessions.nodes]);const ye=a.useCallback(g=>{Jn(()=>import("./jRJsmpYM.js"),__vite__mapDeps([5,1,2,3,4])),A(g),D(!0),I(g),X(null),Q(null)},[]),se=a.useCallback(g=>{const $=g.trim();if(!$)return;const U=d.sessions.nodes.find(_=>_.runId===$||_.id===$)??null;U&&(ye(U.id),S(`Focused session: ${U.title}`))},[d.sessions.nodes,ye]),oe=a.useMemo(()=>d.sessions.nodes.find(g=>g.id===O)??null,[O,d.sessions.nodes]),pe=a.useMemo(()=>{var U,_;const g=((U=oe==null?void 0:oe.runId)==null?void 0:U.trim())??"",$=((_=oe==null?void 0:oe.id)==null?void 0:_.trim())??"";return!g||!$?[]:g===$?[g]:[g,$]},[oe==null?void 0:oe.id,oe==null?void 0:oe.runId]),Ce=ya({seed:d.activity,timeFilterId:ne,runId:(oe==null?void 0:oe.runId)??null,pageSize:50}),Te=a.useMemo(()=>d.sessions.nodes.find(g=>g.id===y)??null,[d.sessions.nodes,y]),Be=a.useMemo(()=>d.sessions.nodes.filter(g=>ni.has(g.status)).length,[d.sessions.nodes]),lt=a.useMemo(()=>d.sessions.nodes.filter(g=>{const $=bt(g.status),U=bt(g.phase??""),_=bt(g.state??"");return $==="blocked"||$==="failed"||U==="blocked"||_==="error"?!0:ni.has($)||$==="handoff"||$==="review"?!1:g.blockers.length>0}).length,[d.sessions.nodes]),xt=a.useMemo(()=>d.sessions.nodes.filter(g=>g.status==="failed").length,[d.sessions.nodes]),Mn=a.useMemo(()=>{const g=[{id:"sessions",label:"Sessions",value:d.sessions.nodes.length,color:N.teal,icon:"session"},{id:"active",label:"Active",value:Be,color:Be>0?N.lime:N.textMuted,icon:"active"},{id:"blocked",label:"Blocked",value:lt,color:lt>0?N.red:N.textMuted,icon:"blocked"},{id:"failed",label:"Failed",value:xt,color:xt>0?N.red:N.textMuted,icon:"failed"},{id:"decisions",label:"Decisions",value:v?d.decisions.length:0,color:v&&d.decisions.length>0?N.amber:N.textMuted,icon:"decision"},{id:"outbox",label:"Outbox",value:d.outbox.pendingTotal,color:d.outbox.replayStatus==="error"?N.red:d.outbox.pendingTotal>0?N.amber:N.textMuted,icon:"outbox"}];return d.handoffs.length>0&&g.push({id:"handoffs",label:"Handoffs",value:d.handoffs.length,color:N.iris,icon:"handoff"}),g},[Be,lt,xt,d.decisions.length,d.handoffs.length,d.outbox.pendingTotal,d.outbox.replayStatus,d.sessions.nodes.length,v]),Zt=a.useMemo(()=>d.decisions.length>0?Math.max(0,...d.decisions.map(g=>g.waitingMinutes)):0,[d.decisions]),He=a.useMemo(()=>{const g=[];return p&&g.push({id:`stream-error:${p}`,kind:"error",icon:"notification",title:"Live stream degraded",message:p,actionLabel:"Settings",onAction:()=>ue("orgx")}),d.connection!=="connected"&&g.push({id:`connection:${d.connection}`,kind:d.connection==="disconnected"?"error":"info",icon:"notification",title:d.connection==="disconnected"?"Connection lost":"Reconnecting",message:d.connection==="disconnected"?"Dashboard is offline. Some data may be stale.":"Live data is recovering. Some sections may be delayed.",actionLabel:"Reconnect",onAction:Re}),d.outbox.pendingTotal>0&&g.push({id:`outbox:pending:${d.outbox.pendingTotal}`,kind:"info",icon:"notification",title:"Buffered updates pending",message:`${d.outbox.pendingTotal} event(s) queued for replay.`}),d.outbox.replayStatus==="error"&&d.outbox.lastReplayError&&g.push({id:`outbox:error:${d.outbox.lastReplayError}`,kind:"error",icon:"notification",title:"Outbox replay failed",message:d.outbox.lastReplayError,actionLabel:"Settings",onAction:()=>ue("orgx")}),C&&g.push({id:`ops:${C}`,kind:"info",icon:/decision/i.test(C)?"decision":"workstream",title:"Update",message:C}),g},[d.connection,d.outbox.lastReplayError,d.outbox.pendingTotal,d.outbox.replayStatus,p,Re,ue,C]);a.useEffect(()=>{const g=new Set(He.map($=>$.id));H($=>$.filter(U=>g.has(U)))},[He]);const Ft=a.useMemo(()=>He.filter(g=>!V.includes(g.id)),[V,He]),dn=a.useCallback(g=>{H($=>$.includes(g)?$:$.concat(g))},[]),En=a.useCallback(()=>{H(He.map(g=>g.id))},[He]);a.useEffect(()=>{if(!f)return;const g=U=>{var me,Se;const _=U.target;_&&((me=Y.current)!=null&&me.contains(_)||(Se=G.current)!=null&&Se.contains(_)||R(!1))},$=U=>{U.key==="Escape"&&R(!1)};return document.addEventListener("mousedown",g),document.addEventListener("touchstart",g),document.addEventListener("keydown",$),()=>{document.removeEventListener("mousedown",g),document.removeEventListener("touchstart",g),document.removeEventListener("keydown",$)}},[f]);const wt=a.useMemo(()=>{var U;const g=new Map;for(const _ of d.sessions.nodes){const me=_.initiativeId??_.groupId??"unscoped",Se=_.groupLabel&&_.groupLabel.trim().length>0?_.groupLabel:_.initiativeId??"Unscoped Initiative",Ye=Lc(Se),Ae=g.get(me)??{id:me,name:Se,category:Ye,progressTotal:0,progressCount:0,statusCounts:{},activeAgents:new Set,allAgents:new Set,workstreams:new Map,latestEpoch:0};if(_.progress!==null&&(Ae.progressTotal+=_.progress,Ae.progressCount+=1),Ae.statusCounts[_.status]=(Ae.statusCounts[_.status]??0)+1,_.agentName&&(Ae.allAgents.add(_.agentName),["running","queued","pending","blocked"].includes(_.status)&&Ae.activeAgents.add(_.agentName)),_.workstreamId){const it=d.sessions.groups.find(ht=>ht.id===_.workstreamId),rt=((U=it==null?void 0:it.label)==null?void 0:U.trim())||_.workstreamId;Ae.workstreams.set(_.workstreamId,rt)}Ae.latestEpoch=Math.max(Ae.latestEpoch,Bt(_.updatedAt??_.lastEventAt??_.startedAt)),g.set(me,Ae)}const $=[];for(const _ of g.values()){const me=_.progressCount>0?Math.round(_.progressTotal/_.progressCount):_.statusCounts.completed?100:_.statusCounts.running?55:0,Se=_.category,Ye=Pc(Se),Ae=Math.round(Math.max(0,Math.min(100,me))/100*(Ye.length-1)),it=(_.statusCounts.blocked??0)>0,rt=(_.statusCounts.completed??0)>0&&(_.statusCounts.running??0)===0&&(_.statusCounts.queued??0)===0&&(_.statusCounts.pending??0)===0&&(_.statusCounts.blocked??0)===0&&(_.statusCounts.paused??0)===0,ht=!rt&&!it&&(_.statusCounts.paused??0)>0&&(_.statusCounts.running??0)===0&&(_.statusCounts.queued??0)===0&&(_.statusCounts.pending??0)===0,tn=Ye.map((Kt,nn)=>{let Vt="upcoming";return(rt||nn<Ae)&&(Vt="completed"),nn===Ae&&!rt&&(Vt=it?"warning":"current"),{name:Kt,status:Vt}});$.push({id:_.id,name:_.name,status:rt?"completed":it?"blocked":ht?"paused":"active",rawStatus:rt?"completed":it?"blocked":ht?"paused":"active",category:Se,health:Math.max(0,Math.min(100,me)),phases:tn,currentPhase:rt?Ye.length-1:Ae,daysRemaining:0,targetDate:null,createdAt:_.latestEpoch>0?new Date(_.latestEpoch).toISOString():null,updatedAt:_.latestEpoch>0?new Date(_.latestEpoch).toISOString():null,activeAgents:_.activeAgents.size,totalAgents:_.allAgents.size,avatars:Array.from(_.activeAgents).slice(0,3),description:`${_.workstreams.size} workstreams are active right now.`,workstreams:Array.from(_.workstreams.entries()).map(([Kt,nn])=>({id:Kt,name:nn,status:"active"}))})}return $.sort((_,me)=>{const Se=_.status==="blocked"?0:_.status==="active"?1:2,Ye=me.status==="blocked"?0:me.status==="active"?1:2;return Se!==Ye?Se-Ye:me.health-_.health})},[d.sessions.nodes,d.sessions.groups]),un=a.useMemo(()=>{const g=(_,me)=>{var Se,Ye;return{..._,...me,health:me.health>0?me.health:_.health,activeAgents:Math.max(_.activeAgents,me.activeAgents),totalAgents:Math.max(_.totalAgents,me.totalAgents),avatars:(Se=_.avatars)!=null&&Se.length?_.avatars:me.avatars,workstreams:(Ye=_.workstreams)!=null&&Ye.length?_.workstreams:me.workstreams,description:_.description??me.description,rawStatus:me.rawStatus??_.rawStatus??null,targetDate:me.targetDate??_.targetDate??null,createdAt:me.createdAt??_.createdAt??null,updatedAt:me.updatedAt??_.updatedAt??null}},$=new Map;for(const _ of wt)$.set(_.id,_);for(const _ of[...Xe??[],...ge??[]]){const me=_.rawStatus??_.status;if(!ri(me)){$.delete(_.id);continue}const Se=$.get(_.id);$.set(_.id,Se?g(Se,_):_)}const U=new Set(nt);return Array.from($.values()).filter(_=>!U.has(_.id)).filter(_=>ri(_.rawStatus??_.status)).sort((_,me)=>{const Se=ht=>ht==="blocked"?0:ht==="active"?1:ht==="paused"?2:3,Ye=Se(_.status)-Se(me.status);if(Ye!==0)return Ye;const Ae=si(_.priority)-si(me.priority);if(Ae!==0)return Ae;const it=Bt(me.updatedAt)-Bt(_.updatedAt);if(it!==0)return it;const rt=me.health-_.health;return rt!==0?rt:_.name.localeCompare(me.name)})},[wt,ge,Xe,nt]),Fn=a.useMemo(()=>{if(!oe)return null;const g=oe.agentName,$=oe.title;if(g){const U=d.activity.find(_=>{var me;return _.runId===oe.runId&&((me=_.summary)==null?void 0:me.trim())});if(U!=null&&U.summary){const _=U.summary.trim().length>40?U.summary.trim().slice(0,40)+"…":U.summary.trim();return`${g}: ${_}`}return g}if($){const U=$.replace(/^(telegram|slack|discord|whatsapp|email|sms):/,"").trim();if(U.length>0)return U}return $??null},[d.activity,oe]),$n=a.useMemo(()=>{const g=new Map;for(const $ of d.sessions.nodes){const U=($.agentId??"").trim()||`name:${($.agentName??"").trim()}`,_=($.agentName??"").trim()||($.agentId??"").trim();if(!_)continue;const me=$.updatedAt??$.lastEventAt??$.startedAt??new Date().toISOString(),Se=Bt(me),Ye=Se?Math.max(0,Math.floor((Date.now()-Se)/6e4)):0,Ae=g.get(U),it={id:U,name:_,role:"Agent",status:$c($.status),task:$.title??null,progress:$.progress??null,lastActive:me,lastActiveMinutes:Ye};(!Ae||Bt(it.lastActive)>Bt(Ae.lastActive))&&g.set(U,it)}return Array.from(g.values())},[d.sessions.nodes]),mn=t.state.connectionVerified&&!Nt,$t=a.useCallback(async()=>{if(d.sessions.nodes.length===0){S("No sessions available to continue.");return}const g=[...d.sessions.nodes].sort(zs)[0];if(A(g.id),I(g.id),X(null),Q(null),["blocked","pending","queued"].includes(g.status))try{await fetch(`/orgx/api/runs/${encodeURIComponent(g.runId)}/actions/resume`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({reason:"continue_from_dashboard"})})}catch{}S(`Focused highest priority session: ${g.title}`),await m()},[d.sessions.nodes,m]),B=a.useCallback(async()=>{const g=await fetch("/orgx/api/mission-control/next-up"),$=await g.json().catch(()=>null);if(!g.ok){const _=typeof($==null?void 0:$.error)=="string"&&$.error.trim().length>0?$.error:typeof($==null?void 0:$.message)=="string"&&$.message.trim().length>0?$.message:`Failed to load Next Up queue (${g.status})`;throw new Error(_)}const U=Array.isArray($==null?void 0:$.items)?$.items:[];return U.length===0?null:U.find(_=>_.queueState!=="blocked"&&_.queueState!=="running")??U.find(_=>_.queueState!=="blocked")??null},[]),Wt=a.useCallback(async()=>{const g=await B();if(!g){S("No startable Next Up workstream is available."),c("mission-control");return}const $=await fetch("/orgx/api/mission-control/next-up/play",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({initiativeId:g.initiativeId,workstreamId:g.workstreamId,agentId:g.runnerAgentId,fastAck:!0})}),U=await $.json().catch(()=>null);if(!$.ok)throw new Error((U==null?void 0:U.error)??(U==null?void 0:U.message)??`Failed to dispatch Next Up (${$.status})`);I(null),X(g.workstreamId),Q(g.workstreamTitle),L(null),S(`Dispatched Next Up: ${g.workstreamTitle}`),await m()},[B,m,c]),pn=a.useCallback(async()=>{const g=await B();if(!g){S("No startable initiative is ready for Autopilot yet."),c("mission-control");return}const $=await fetch("/orgx/api/mission-control/auto-continue/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({initiativeId:g.initiativeId,workstreamIds:[g.workstreamId],agentId:g.runnerAgentId})}),U=await $.json().catch(()=>null);if(!$.ok)throw new Error((U==null?void 0:U.error)??(U==null?void 0:U.message)??`Failed to start Autopilot (${$.status})`);I(null),X(g.workstreamId),Q(g.workstreamTitle),L(null),S(`Autopilot started for ${g.initiativeTitle}.`),await m()},[B,m,c]),xn=a.useCallback(async g=>{if(A(g.id),I(g.id),X(null),Q(null),!["running","completed","archived"].includes(g.status))try{await fetch(`/orgx/api/runs/${encodeURIComponent(g.runId)}/actions/resume`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({reason:"dispatch_from_dashboard"})})}catch{}S(`Dispatch requested: ${g.title}`),await m()},[m]),ct=a.useCallback(async(g,$,U={})=>{const _=await fetch(`/orgx/api/runs/${encodeURIComponent(g.runId)}/actions/${$}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(U)});if(!_.ok){const me=await _.json().catch(()=>null);throw new Error((me==null?void 0:me.error)??`${$} failed (${_.status})`)}},[]),be=a.useCallback(async g=>{var me;const $=await fetch(`/orgx/api/runs/${encodeURIComponent(g.runId)}/checkpoints`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({reason:"dashboard_manual_checkpoint"})});if(!$.ok){const Se=await $.json().catch(()=>null);throw new Error((Se==null?void 0:Se.error)??`Checkpoint creation failed (${$.status})`)}const U=await $.json().catch(()=>null),_=U&&"data"in U&&((me=U.data)==null?void 0:me.id)||U&&"id"in U&&U.id||null;S(_?`Checkpoint created: ${_.slice(0,8)}`:"Checkpoint created."),await m()},[m]),en=a.useCallback(async g=>{await ct(g,"pause",{reason:"pause_from_dashboard"}),S(`Pause requested: ${g.title}`),await m()},[m,ct]),Ne=a.useCallback(async g=>{await ct(g,"resume",{reason:"resume_from_dashboard"}),S(`Resume requested: ${g.title}`),await m()},[m,ct]),ls=a.useCallback(async g=>{await ct(g,"cancel",{reason:"cancel_from_dashboard"}),S(`Cancel requested: ${g.title}`),await m()},[m,ct]),cs=a.useCallback(async g=>{var Ye;const $=await fetch(`/orgx/api/runs/${encodeURIComponent(g.runId)}/checkpoints`,{method:"GET"});if(!$.ok){const Ae=await $.json().catch(()=>null);throw new Error((Ae==null?void 0:Ae.error)??`Checkpoint list failed (${$.status})`)}const U=await $.json().catch(()=>null),Se=(Ye=(Array.isArray(U)?U:Array.isArray(U==null?void 0:U.data)?U.data:[]).map(Ae=>({id:typeof Ae.id=="string"?Ae.id:"",createdAt:typeof Ae.createdAt=="string"?Ae.createdAt:typeof Ae.created_at=="string"?Ae.created_at:""})).filter(Ae=>Ae.id.length>0).sort((Ae,it)=>Date.parse(it.createdAt)-Date.parse(Ae.createdAt))[0])==null?void 0:Ye.id;if(!Se)throw new Error("No checkpoint available for rollback.");await ct(g,"rollback",{checkpointId:Se,reason:"rollback_from_dashboard"}),S(`Rollback requested for ${g.title}.`),await m()},[m,ct]),hn=a.useCallback(async()=>{var U;if(!Ve||ze.trim().length===0||st)return;ot(!0);const g=Ve.type,$=ze.trim();try{const _={type:g,title:$,status:"active"};if(g==="workstream"){const Se=Ve.initiativeId??(Te==null?void 0:Te.initiativeId)??((U=wt[0])==null?void 0:U.id)??null;if(!Se){S("Select an initiative first to start a workstream."),ot(!1);return}_.initiative_id=Se,_.parentId=Se}const me=await fetch("/orgx/api/entities",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(_)});if(!me.ok){const Se=await me.json().catch(()=>null);throw new Error((Se==null?void 0:Se.error)??`Failed to create ${g}.`)}S(`Created ${g}: ${$}`),St(),await m()}catch(_){S(_ instanceof Error?_.message:`Failed to create ${g}.`),ot(!1)}},[St,st,Ve,ze,wt,m,Te==null?void 0:Te.initiativeId]),vt=a.useCallback(()=>{pt("initiative")},[pt]),re=a.useCallback(g=>{pt("workstream",g)},[pt]);a.useCallback(()=>{var g;return re((Te==null?void 0:Te.initiativeId)??((g=wt[0])==null?void 0:g.id)??null)},[wt,Te==null?void 0:Te.initiativeId,re]);const Ct=a.useCallback(g=>{const $=[...d.sessions.nodes].filter(U=>(U.initiativeId??U.groupId)===g.id).sort(zs)[0];$&&(A($.id),I($.id),X(null),Q(null),S(`Focused initiative: ${g.name}`))},[d.sessions.nodes]),fn=a.useCallback(g=>{I(null),X(g.workstreamId),Q(g.workstreamTitle),L(null),c("activity"),S(`Following workstream: ${g.workstreamTitle}`)},[c]),Le=a.useCallback(g=>{const $=wt.find(U=>U.id===g)??un.find(U=>U.id===g)??null;$&&Ct($)},[Ct,wt,un]);a.useCallback(g=>{const $=new Set(g),U=[...d.sessions.nodes].filter(_=>$.has(_.status)).sort(zs)[0];if(!U){S("No matching sessions for that metric right now.");return}ye(U.id),F("activity")},[d.sessions.nodes,ye]);const Tn=a.useCallback(g=>{o==="activity"&&(g==="sessions"||g==="active"||g==="blocked"||g==="failed"||g==="decisions"||g==="outbox"||g==="handoffs")&&he(g)},[o]);return u?e.jsxs("div",{className:"flex min-h-screen flex-col lg:h-screen",style:{backgroundColor:N.background},children:[e.jsxs("div",{className:"border-b border-subtle px-4 py-2.5 sm:px-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"shimmer-skeleton h-6 w-6 rounded-lg"}),e.jsx("div",{className:"shimmer-skeleton h-5 w-28 rounded-md"}),e.jsx("div",{className:"shimmer-skeleton h-5 w-14 rounded-full"})]}),e.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:Array.from({length:4}).map((g,$)=>e.jsx("div",{className:"shimmer-skeleton h-7 w-24 rounded-full"},$))})]}),e.jsxs("div",{className:"grid flex-1 grid-cols-1 gap-4 p-4 sm:p-5 lg:grid-cols-12",children:[e.jsx("div",{className:"shimmer-skeleton min-h-[240px] rounded-2xl lg:col-span-3"}),e.jsx("div",{className:"shimmer-skeleton min-h-[240px] rounded-2xl lg:col-span-6"}),e.jsxs("div",{className:"flex flex-col gap-4 lg:col-span-3",children:[e.jsx("div",{className:"shimmer-skeleton h-40 rounded-2xl"}),e.jsx("div",{className:"shimmer-skeleton h-48 rounded-2xl"}),e.jsx("div",{className:"shimmer-skeleton flex-1 rounded-2xl",style:{minHeight:160}})]})]})]}):e.jsxs("div",{className:"relative flex min-h-screen flex-col pb-[92px] lg:h-screen lg:min-h-0 lg:overflow-hidden lg:pb-0",style:{backgroundColor:N.background},children:[typeof window<"u"&&window.location.port==="5173"&&e.jsx("div",{className:"absolute left-1/2 top-4 z-30 -translate-x-1/2",children:e.jsxs("div",{className:"rounded-full border border-strong bg-white/[0.06] px-4 py-2 text-caption text-primary shadow-[0_10px_30px_rgba(0,0,0,0.35)] backdrop-blur",children:["Dev preview on 5173. Installed plugin runs on OpenClaw port"," ",e.jsx("a",{href:"http://127.0.0.1:18789/orgx/live/",className:"text-white underline underline-offset-4 hover:text-secondary",children:"18789"}),"."]})}),e.jsxs("header",{className:"relative z-[180] border-b border-subtle px-4 py-1.5 sm:px-6",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2.5 lg:grid lg:grid-cols-[1fr_auto_1fr]",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[e.jsx(Dc,{}),e.jsxs("h1",{className:"text-title font-semibold tracking-tight text-white sm:text-[17px]",children:["OrgX",e.jsx("span",{className:"ml-1.5 text-secondary",children:"Live"})]}),e.jsx(_r,{color:Ec[d.connection],pulse:d.connection==="connected",title:[`Status: ${ei[d.connection]??d.connection}`,d.connection==="connected"?"Meaning: receiving live updates.":d.connection==="reconnecting"?"Meaning: retrying live stream (data may be stale).":"Meaning: offline (data is stale).",`Last snapshot: ${Fc(d.lastSnapshotAt)}`,p?`Error: ${p}`:null].filter(Boolean).join(`
215
- `),children:ei[d.connection]??"Unknown"}),(d.outbox.pendingTotal>0||d.outbox.replayStatus==="error")&&e.jsx("div",{className:"hidden sm:block",children:e.jsx("button",{type:"button",onClick:()=>he("outbox"),className:"transition-opacity hover:opacity-80",title:"Open outbox details",children:e.jsxs(_r,{color:d.outbox.replayStatus==="error"?N.red:N.amber,pulse:d.outbox.pendingTotal>0&&d.outbox.replayStatus!=="error",children:["Outbox ",d.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:()=>c("activity"),"aria-pressed":o==="activity",className:`rounded-full px-3 py-1 text-body font-medium transition-all ${o==="activity"?"bg-white/[0.1] text-white":"text-secondary hover:text-bright"}`,children:"Activity"}),e.jsx("button",{type:"button",onClick:()=>c("mission-control"),onMouseEnter:qe,onFocus:qe,"aria-pressed":o==="mission-control",className:`rounded-full px-3 py-1 text-body font-medium transition-all ${o==="mission-control"?"bg-white/[0.1] text-white":"text-secondary hover:text-bright"}`,children:"Mission Control"})]})}),e.jsxs("div",{className:"relative isolate flex items-center justify-end gap-1.5 sm:gap-2",children:[d.lastActivity&&e.jsxs("span",{className:"hidden text-body text-secondary xl:inline",children:["Last activity: ",d.lastActivity]}),d.outbox.pendingTotal>0&&e.jsxs("span",{className:"hidden text-body text-secondary xl:inline",children:["Replay: ",d.outbox.replayStatus]}),n&&e.jsx("button",{type:"button",onClick:()=>{je(!1),Re()},className:"hidden rounded-full border border-amber-200/25 bg-amber-200/10 px-3 py-1.5 text-caption font-semibold text-amber-100 transition-colors hover:bg-amber-200/15 sm:inline",title:"Exit demo mode",children:"Exit demo"}),e.jsxs("button",{type:"button",ref:G,onClick:()=>R(g=>!g),title:"Notifications","aria-haspopup":"dialog","aria-expanded":f,"aria-controls":"header-notifications-panel",className:"relative inline-flex h-8 w-8 items-center justify-center rounded-full border border-white/[0.1] bg-white/[0.03] text-primary transition-colors hover:bg-white/[0.08]",children:[e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M15 17h5l-1.4-1.4a2 2 0 0 1-.6-1.4V11a6 6 0 1 0-12 0v3.2c0 .53-.21 1.04-.59 1.42L4 17h5"}),e.jsx("path",{d:"M9 17a3 3 0 0 0 6 0"})]}),Ft.length>0&&e.jsx("span",{className:"absolute -right-1 -top-1 inline-flex min-h-[16px] min-w-[16px] items-center justify-center rounded-full bg-red-500 px-1 text-micro font-semibold text-white",children:Ft.length})]}),e.jsx("button",{type:"button",onClick:()=>ue("orgx"),title:"Settings",className:"relative inline-flex h-8 w-8 items-center justify-center rounded-full border border-white/[0.1] bg-white/[0.03] text-primary transition-colors hover:bg-white/[0.08]",children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M12 15.5a3.5 3.5 0 1 0 0-7 3.5 3.5 0 0 0 0 7z"}),e.jsx("path",{d:"M19.4 15a1.8 1.8 0 0 0 .36 2l.05.05a2.2 2.2 0 0 1-1.56 3.76 2.2 2.2 0 0 1-1.56-.64l-.05-.05a1.8 1.8 0 0 0-2-.36 1.8 1.8 0 0 0-1.1 1.63V22a2.2 2.2 0 0 1-4.4 0v-.07a1.8 1.8 0 0 0-1.1-1.63 1.8 1.8 0 0 0-2 .36l-.05.05a2.2 2.2 0 1 1-3.12-3.12l.05-.05a1.8 1.8 0 0 0 .36-2 1.8 1.8 0 0 0-1.63-1.1H2a2.2 2.2 0 0 1 0-4.4h.07a1.8 1.8 0 0 0 1.63-1.1 1.8 1.8 0 0 0-.36-2l-.05-.05a2.2 2.2 0 1 1 3.12-3.12l.05.05a1.8 1.8 0 0 0 2 .36 1.8 1.8 0 0 0 1.1-1.63V2a2.2 2.2 0 0 1 4.4 0v.07a1.8 1.8 0 0 0 1.1 1.63 1.8 1.8 0 0 0 2-.36l.05-.05a2.2 2.2 0 0 1 3.12 3.12l-.05.05a1.8 1.8 0 0 0-.36 2 1.8 1.8 0 0 0 1.63 1.1H22a2.2 2.2 0 0 1 0 4.4h-.07a1.8 1.8 0 0 0-1.63 1.1z"})]})}),e.jsx("button",{type:"button",onClick:()=>{et(!0);try{window.sessionStorage.setItem(Os,"1")}catch{}},title:"Help",className:"relative inline-flex h-8 w-8 items-center justify-center rounded-full border border-white/[0.1] bg-white/[0.03] text-primary transition-colors hover:bg-white/[0.08]",children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M9.1 9a3 3 0 0 1 5.8 1c0 2-3 2-3 4"}),e.jsx("path",{d:"M12 17h.01"}),e.jsx("circle",{cx:"12",cy:"12",r:"9"})]})}),e.jsxs("button",{type:"button",onClick:m,className:"group inline-flex h-8 w-8 items-center justify-center rounded-full border border-white/[0.1] bg-white/[0.03] text-body text-primary transition-colors hover:bg-white/[0.08] sm:w-auto sm:gap-1.5 sm:px-3",title:"Refresh data",children:[e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"transition-transform group-hover:rotate-45",children:[e.jsx("path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8"}),e.jsx("path",{d:"M21 3v5h-5"})]}),e.jsx("span",{className:"hidden sm:inline",children:"Refresh"})]}),f&&e.jsxs("div",{id:"header-notifications-panel",ref:Y,role:"dialog","aria-label":"Notifications",className:"absolute right-0 top-[calc(100%+8px)] z-[320] w-[min(92vw,380px)] rounded-2xl border border-strong bg-[#070a11]/95 p-2 shadow-[0_20px_50px_rgba(0,0,0,0.45)] backdrop-blur",children:[e.jsxs("div",{className:"mb-1.5 flex items-center justify-between px-2 py-1",children:[e.jsx("p",{className:"text-body font-semibold uppercase tracking-[0.12em] text-secondary",children:"Notifications"}),e.jsxs("div",{className:"flex items-center gap-2",children:[Ft.length>0&&e.jsx("button",{type:"button",onClick:En,className:"text-caption text-secondary transition-colors hover:text-primary",children:"Dismiss all"}),e.jsx("button",{type:"button",onClick:()=>R(!1),className:"rounded-md px-1.5 py-0.5 text-caption text-secondary transition-colors hover:bg-white/[0.08] hover:text-primary","aria-label":"Close notifications",children:"Close"})]})]}),e.jsx("div",{className:"mb-1.5 flex flex-wrap items-center gap-1.5 px-1.5",children:Mn.map(g=>e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.1] bg-white/[0.03] px-2 py-0.5 text-micro",children:[e.jsx(Oe,{type:g.icon,accent:g.color,size:12,className:"opacity-90"}),e.jsx("span",{className:"uppercase tracking-[0.08em] text-secondary",children:g.label}),e.jsx("span",{className:"font-semibold text-white",style:{fontVariantNumeric:"tabular-nums"},children:g.value})]},g.id))}),Ft.length===0?e.jsx("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.02] px-3 py-3 text-body text-secondary",children:"Everything looks clear."}):e.jsx("div",{className:"space-y-1.5",children:Ft.map(g=>e.jsx("div",{className:"rounded-xl border px-3 py-2",style:{borderColor:g.kind==="error"?"rgba(239,68,68,0.35)":"rgba(255,255,255,0.1)",backgroundColor:g.kind==="error"?"rgba(239,68,68,0.08)":"rgba(255,255,255,0.02)"},children:e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"inline-flex items-center gap-1.5 text-body font-semibold",style:{color:g.kind==="error"?"#fecaca":"#e2e8f0"},children:[e.jsx(Oe,{type:g.icon,size:12,className:"opacity-90"}),e.jsx("span",{className:"truncate",children:g.title})]}),e.jsx("p",{className:"mt-0.5 text-body leading-snug text-secondary",children:g.message}),g.onAction&&e.jsx("button",{type:"button",onClick:()=>{var $;($=g.onAction)==null||$.call(g),R(!1)},className:"mt-1.5 rounded-md border border-strong bg-white/[0.05] px-2.5 py-1 text-caption font-medium text-primary transition-colors hover:bg-white/[0.1] hover:text-white",children:g.actionLabel??"View"})]}),e.jsx("button",{type:"button",onClick:()=>dn(g.id),className:"shrink-0 rounded-md px-1.5 py-0.5 text-caption text-secondary transition-colors hover:bg-white/[0.08] hover:text-primary",title:"Dismiss",children:"Dismiss"})]})},g.id))})]})]})]}),e.jsx("div",{className:"mt-2 flex items-center justify-center lg:hidden",children:e.jsxs("div",{className:"flex w-full max-w-[340px] rounded-full border border-white/[0.1] bg-white/[0.03] p-0.5",role:"group","aria-label":"Dashboard view",children:[e.jsx("button",{type:"button",onClick:()=>c("activity"),"aria-pressed":o==="activity",className:`flex-1 rounded-full px-3 py-1.5 text-body font-medium transition-all ${o==="activity"?"bg-white/[0.1] text-white":"text-secondary hover:text-bright"}`,children:"Activity"}),e.jsx("button",{type:"button",onClick:()=>c("mission-control"),"aria-pressed":o==="mission-control",className:`flex-1 rounded-full px-3 py-1.5 text-body font-medium transition-all ${o==="mission-control"?"bg-white/[0.1] text-white":"text-secondary hover:text-bright"}`,children:"Mission Control"})]})}),mn&&e.jsxs("div",{className:"mt-2 flex flex-wrap items-center justify-between gap-2 rounded-lg border border-[#7C7CFF]/30 bg-[#7C7CFF]/10 px-3 py-2 text-body text-[#E6E4FF]",children:[e.jsx("span",{children:"Mission Control now includes a dependency map plus expandable hierarchy rows for initiatives, workstreams, milestones, and tasks."}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>c("mission-control"),onMouseEnter:qe,onFocus:qe,className:"rounded-full border border-[#BFFF00]/30 bg-[#BFFF00]/15 px-2.5 py-1 text-caption text-[#D8FFA1]",children:"Open"}),e.jsx("button",{type:"button",onClick:()=>q(!0),className:"text-caption text-secondary underline underline-offset-2",children:"Dismiss"})]})]})]}),o==="activity"&&e.jsx("div",{className:"flex items-center gap-1.5 overflow-x-auto border-b border-subtle px-4 py-1.5 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden sm:px-6",children:Mn.map(g=>e.jsxs("button",{type:"button",onClick:()=>Tn(g.id),className:"inline-flex shrink-0 items-center gap-1.5 rounded-full border border-white/[0.1] bg-white/[0.03] px-2 py-0.5 text-micro transition-colors hover:bg-white/[0.08]",title:`Bulk actions: ${g.label.toLowerCase()}`,children:[e.jsx("span",{className:"inline-flex h-5 w-5 items-center justify-center rounded-full border border-strong bg-white/[0.02]",children:e.jsx(Oe,{type:g.icon,accent:g.color,size:12,className:"opacity-90"})}),e.jsx("span",{className:"font-semibold text-white",style:{fontVariantNumeric:"tabular-nums"},children:g.value}),e.jsx("span",{className:"uppercase tracking-[0.08em] text-secondary",children:g.label})]},g.id))}),o==="mission-control"?e.jsx("div",{className:"relative z-0 flex-1 min-h-0 flex flex-col overflow-hidden",children:e.jsx(a.Suspense,{fallback:e.jsx("div",{className:"flex flex-1 items-center justify-center text-body text-secondary",children:"Loading Mission Control…"}),children:e.jsx(_c,{initiatives:un,activities:d.activity,agents:$n,runtimeInstances:d.runtimeInstances??[],isLoading:u,authToken:null,embedMode:!1,connection:d.connection,lastSnapshotAt:d.lastSnapshotAt,error:p,hasApiKey:t.state.hasApiKey,onOpenSettings:()=>ue("orgx"),onRefresh:m,onCreateInitiative:vt,onPlayNextUp:Wt,onStartAutopilot:pn,onFollowWorkstream:fn})})}):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:[v&&d.decisions.length>0&&Z!=="decisions"&&e.jsxs("button",{type:"button",onClick:()=>ae("decisions"),className:de("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]",d.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:d.decisions.length>=20?"text-red-300":"text-amber-300",children:[e.jsx("path",{d:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),e.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),e.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),e.jsxs("span",{className:`text-body font-medium ${d.decisions.length>=20?"text-red-200":"text-amber-200"}`,children:[d.decisions.length," decision",d.decisions.length===1?"":"s"," waiting",Zt>0?` · longest: ${Zt}m`:""]}),e.jsx("span",{className:`ml-auto text-caption ${d.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 ${W!=="agents"?"hidden lg:flex":""}`,children:e.jsx(zo,{sessions:d.sessions,activity:d.activity,runtimeInstances:d.runtimeInstances??[],showSyntheticEntities:n||r,selectedSessionId:y,onSelectSession:ye,onAgentFilter:L,agentFilter:M,timeFilterId:ne,onReconnect:Re,connectionStatus:d.connection})}),e.jsx("section",{className:`min-h-0 lg:col-span-6 lg:flex lg:flex-col lg:[&>section]:h-full ${W!=="activity"?"hidden lg:flex":""}`,children:e.jsx(Tl,{activity:Ce.items,sessions:d.sessions.nodes,initiatives:wt,selectedRunIds:pe,selectedSessionLabel:Fn,selectedWorkstreamId:ee,selectedWorkstreamLabel:le,agentFilter:M,timeFilterId:ne,onTimeFilterChange:te,hasMore:Ce.hasMore,isLoadingMore:Ce.isLoadingMore,onLoadMore:Ce.loadMore,onClearSelection:z,onClearWorkstreamFilter:ce,onClearAgentFilter:ke,onFocusRunId:se,onPlayNextUp:Wt,onStartAutopilot:pn,onCreateInitiative:vt,onOpenMissionControl:()=>c("mission-control"),isLoading:u})}),e.jsxs("section",{className:`flex min-h-0 flex-col gap-3 lg:col-span-3 lg:gap-3 ${W!=="decisions"&&W!=="initiatives"?"hidden lg:flex":""}`,children:[e.jsx("div",{className:`min-h-0 ${Z==="initiatives"?"flex-1":"flex-shrink-0"} `,children:Z==="initiatives"?e.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-2",children:[e.jsxs("div",{className:"inline-flex items-center gap-1 rounded-full border border-strong bg-black/20 p-0.5",role:"tablist","aria-label":"Initiatives sidebar",children:[e.jsxs("button",{type:"button",role:"tab","aria-selected":Qe==="in_progress",onClick:()=>mt("in_progress"),className:de("inline-flex items-center gap-2 rounded-full px-3 py-1.5 text-micro font-semibold transition-colors",Qe==="in_progress"?"border border-lime/25 bg-lime/[0.10] text-[#E1FFB2]":"border border-transparent text-secondary hover:bg-white/[0.08] hover:text-bright"),children:[e.jsx("span",{children:"In Progress"}),e.jsx("span",{className:"rounded-full border border-strong bg-white/[0.04] px-2 py-0.5 text-micro tabular-nums text-primary",children:ve})]}),e.jsx("button",{type:"button",role:"tab","aria-selected":Qe==="next_up",onClick:()=>mt("next_up"),className:de("rounded-full px-3 py-1.5 text-micro font-semibold transition-colors",Qe==="next_up"?"border border-lime/25 bg-lime/[0.10] text-[#E1FFB2]":"border border-transparent text-secondary hover:bg-white/[0.08] hover:text-bright"),children:"Next Up"})]}),e.jsx("div",{className:"min-h-0 flex-1",children:Qe==="in_progress"?e.jsx(Kl,{className:"h-full min-h-0",sessions:d.sessions.nodes,onOpenSession:ye,onFocusRunId:se}):e.jsx(ec,{title:"Next Up",className:"h-full",compact:xe,allowCompactToggle:!0,onToggleCompact:_e,onFollowWorkstream:fn,onOpenInitiative:Le})})]}):e.jsx(Jt,{className:"card-enter",children:e.jsxs("button",{onClick:()=>ae("initiatives"),className:"flex w-full items-center justify-between px-4 py-3 text-left transition-colors hover:bg-white/[0.03]",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("h2",{className:"text-heading font-semibold text-white",children:"Initiatives"})}),e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"-rotate-90 text-muted",children:e.jsx("path",{d:"m6 9 6 6 6-6"})})]})})}),e.jsx("div",{className:`min-h-0 ${Z==="decisions"?"flex-1":"flex-shrink-0"} ${W==="initiatives"?"hidden lg:block":""}`,children:Z==="decisions"?v?e.jsx(Ei,{decisions:d.decisions,onApproveDecision:j,onRejectDecision:w,onApproveAll:E}):e.jsxs(Jt,{className:"flex h-full min-h-[220px] flex-col card-enter",children:[e.jsxs("div",{className:"space-y-2 border-b border-subtle px-4 py-3.5",children:[e.jsx("h2",{className:"text-heading font-semibold text-white",children:"Decisions"}),e.jsx("p",{className:"text-body text-secondary",children:"OrgX is not connected. Pending decision data is hidden in local-only mode."})]}),e.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 p-4 text-center",children:[e.jsx("p",{className:"text-body text-secondary",children:"Connect OrgX to review and approve live decisions."}),e.jsx("button",{onClick:Re,className:"rounded-md border border-lime/25 bg-lime/10 px-3 py-1.5 text-caption font-semibold text-lime transition-colors hover:bg-lime/20",children:"Connect OrgX"})]})]}):e.jsx(Jt,{className:"card-enter",children:e.jsxs("button",{onClick:()=>ae("decisions"),className:"flex w-full items-center justify-between px-4 py-3 text-left transition-colors hover:bg-white/[0.03]",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"text-heading font-semibold text-white",children:"Decisions"}),v&&d.decisions.length>0&&e.jsx("span",{className:"chip text-micro",style:{borderColor:`${N.amber}44`,color:N.amber},children:d.decisions.length}),!v&&e.jsx("span",{className:"text-micro text-muted",children:"disconnected"})]}),e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"-rotate-90 text-muted",children:e.jsx("path",{d:"m6 9 6 6 6-6"})})]})})})]})]}),e.jsx(yt,{children:k&&Te&&e.jsxs(e.Fragment,{children:[e.jsx(we.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:()=>D(!1)},"session-drawer-backdrop"),e.jsxs(we.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:N.cardBg},children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-subtle px-4 py-3",children:[e.jsx("h3",{className:"text-body font-semibold text-primary",children:"Session Detail"}),e.jsx("button",{type:"button",onClick:()=>D(!1),"aria-label":"Close session inspector",className:"inline-flex h-8 w-8 items-center justify-center rounded-full border border-strong bg-white/[0.03] text-primary transition-colors hover:bg-white/[0.08] hover:text-white",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 6L6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})})]}),e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto",children:e.jsx(a.Suspense,{fallback:e.jsx("div",{className:"p-4 text-body text-secondary",children:"Loading session detail…"}),children:e.jsx(Mc,{session:Te,activity:d.activity,initiatives:wt,onContinueHighestPriority:$t,onDispatchSession:xn,onPauseSession:en,onResumeSession:Ne,onCancelSession:ls,onCreateCheckpoint:be,onRollbackSession:cs,onStartInitiative:vt,onStartWorkstream:re})})})]},"session-drawer-panel")]})}),e.jsx(Ga,{activeTab:W,onTabChange:F,pendingDecisionCount:v?d.decisions.length:0}),e.jsx(kt,{open:Ve!==null,onClose:St,maxWidth:"max-w-sm",fitContent:!0,children:e.jsxs("div",{className:"flex w-full flex-col",children:[e.jsxs("div",{className:"px-5 pt-5 pb-1",children:[e.jsx("h3",{className:"text-heading font-semibold text-white",children:(Ve==null?void 0:Ve.type)==="workstream"?"New Workstream":"New Initiative"}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:(Ve==null?void 0:Ve.type)==="workstream"?"Create a new workstream under the selected initiative.":"Create a new initiative to organize your work."})]}),e.jsxs("div",{className:"px-5 py-4",children:[e.jsx("label",{className:"mb-1.5 block text-caption uppercase tracking-[0.1em] text-secondary",children:"Name"}),e.jsx("input",{value:ze,onChange:g=>Ue(g.target.value),onKeyDown:g=>{g.key==="Enter"&&hn()},autoFocus:!0,"data-modal-autofocus":"true",placeholder:(Ve==null?void 0:Ve.type)==="workstream"?"e.g. User Onboarding Flow":"e.g. Q1 Product Launch",className:"w-full rounded-lg border border-strong bg-black/30 px-3 py-2.5 text-body text-white placeholder:text-muted focus:outline-none focus:ring-1 focus:ring-[#BFFF00]/40"})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 border-t border-subtle px-5 py-3",children:[e.jsx("button",{onClick:St,className:"rounded-md px-3 py-1.5 text-body text-secondary transition-colors hover:text-white",children:"Cancel"}),e.jsx("button",{onClick:hn,disabled:ze.trim().length===0||st,className:"rounded-md border border-lime/25 bg-lime/10 px-4 py-1.5 text-body font-semibold text-lime transition-colors hover:bg-lime/20 disabled:opacity-45",children:st?"Creating…":"Create"})]})]})}),e.jsx(hc,{open:ie.open,onClose:()=>J(g=>({...g,open:!1})),activeTab:ie.tab,onChangeTab:g=>J($=>({...$,tab:g})),demoMode:n,onToggleDemoMode:g=>{je(g),g||Re()},showSyntheticEntities:r,onToggleShowSyntheticEntities:i,onboarding:t,authToken:null,embedMode:!1}),e.jsx(vc,{open:Fe==="sessions"||Fe==="active"||Fe==="blocked"||Fe==="failed",onClose:()=>he(null),mode:Fe==="active"||Fe==="blocked"||Fe==="failed"?Fe:"sessions",sessions:d.sessions.nodes,onOpenSession:g=>{ye(g.id),he(null)},onRunAction:async(g,$)=>{await ct(g,$,{reason:`bulk_${$}_from_header`})},onRefetch:async()=>m(),onSetNotice:g=>S(g)}),e.jsx(jc,{open:Fe==="decisions",onClose:()=>he(null),decisions:v?d.decisions:[],onApproveDecision:j,onRejectDecision:w,onApproveAll:E}),e.jsx(kc,{open:Fe==="outbox",onClose:()=>he(null),outbox:d.outbox,onOpenSettings:()=>{he(null),ue("orgx")},onRefresh:()=>{m()}}),e.jsx(Sc,{open:Fe==="handoffs",onClose:()=>he(null),handoffs:d.handoffs}),e.jsx(Va,{open:fe,onClose:()=>et(!1),onOpenSettings:()=>ue("providers"),onOpenOrgxSettings:()=>ue("orgx"),onOpenMissionControl:()=>{c("mission-control"),et(!1)},demoMode:n,connectionVerified:t.state.connectionVerified,hasSessions:d.sessions.nodes.length>0}),e.jsx(Ic,{})]})}ii.init("phc_s4KPgkYEFZgvkMYw4zXG41H5FN6haVwbEWPYHfNjxOc",{api_host:"https://us.i.posthog.com",defaults:"2026-01-30",person_profiles:"identified_only"});const Rc=new Gi({defaultOptions:{queries:{staleTime:3e4,retry:1,refetchOnWindowFocus:!1,refetchOnReconnect:!0}}});Vi.createRoot(document.getElementById("root")).render(e.jsx(a.StrictMode,{children:e.jsx(Hi,{client:Rc,children:e.jsx(Tc,{})})}));export{dt as A,Oe as E,cn as M,ec as N,Jt as P,gt as S,$i as U,N as a,ut as b,to as c,go as d,on as e,Xc as f,Si as g,Hc as h,Kc as i,Pl as j,Gc as k,Vc as l,kt as m,bt as n,Xl as o,Gl as p,zt as q,Hr as r,Jc as s,Vl as t,Jl as u,js as v,de as w,Ge as x,ks as y};