@useorgx/openclaw-plugin 0.7.17 → 0.7.18

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 (95) hide show
  1. package/dashboard/dist/assets/{D8mvKY2h.js → 467jKHFJ.js} +1 -1
  2. package/dashboard/dist/assets/467jKHFJ.js.br +0 -0
  3. package/dashboard/dist/assets/467jKHFJ.js.gz +0 -0
  4. package/dashboard/dist/assets/{CWXk6UZl.js → 5Ihga-4X.js} +1 -1
  5. package/dashboard/dist/assets/5Ihga-4X.js.br +0 -0
  6. package/dashboard/dist/assets/5Ihga-4X.js.gz +0 -0
  7. package/dashboard/dist/assets/{CoDun8X6.js → B71dt9yu.js} +1 -1
  8. package/dashboard/dist/assets/B71dt9yu.js.br +0 -0
  9. package/dashboard/dist/assets/B71dt9yu.js.gz +0 -0
  10. package/dashboard/dist/assets/{DBct8HLW.js → BEnI6kNR.js} +1 -1
  11. package/dashboard/dist/assets/BEnI6kNR.js.br +0 -0
  12. package/dashboard/dist/assets/BEnI6kNR.js.gz +0 -0
  13. package/dashboard/dist/assets/{DvFumX8R.js → BcJmNILk.js} +1 -1
  14. package/dashboard/dist/assets/BcJmNILk.js.br +0 -0
  15. package/dashboard/dist/assets/BcJmNILk.js.gz +0 -0
  16. package/dashboard/dist/assets/{B8NuBCcY.js → C-XuWXGi.js} +1 -1
  17. package/dashboard/dist/assets/C-XuWXGi.js.br +0 -0
  18. package/dashboard/dist/assets/C-XuWXGi.js.gz +0 -0
  19. package/dashboard/dist/assets/{BDlKSbsp.js → C3_j_W9V.js} +1 -1
  20. package/dashboard/dist/assets/C3_j_W9V.js.br +0 -0
  21. package/dashboard/dist/assets/C3_j_W9V.js.gz +0 -0
  22. package/dashboard/dist/assets/{05zHA1Am.js → C9-UYhBb.js} +1 -1
  23. package/dashboard/dist/assets/C9-UYhBb.js.br +0 -0
  24. package/dashboard/dist/assets/C9-UYhBb.js.gz +0 -0
  25. package/dashboard/dist/assets/{8nr6IqT4.js → C9yV06GS.js} +1 -1
  26. package/dashboard/dist/assets/C9yV06GS.js.br +0 -0
  27. package/dashboard/dist/assets/C9yV06GS.js.gz +0 -0
  28. package/dashboard/dist/assets/{CMir7ekf.js → CReugbyT.js} +1 -1
  29. package/dashboard/dist/assets/CReugbyT.js.br +0 -0
  30. package/dashboard/dist/assets/CReugbyT.js.gz +0 -0
  31. package/dashboard/dist/assets/{0uYJrBLl.js → CSDhTbKy.js} +1 -1
  32. package/dashboard/dist/assets/CSDhTbKy.js.br +0 -0
  33. package/dashboard/dist/assets/CSDhTbKy.js.gz +0 -0
  34. package/dashboard/dist/assets/{CyUpNSKv.js → CfMS9yIf.js} +1 -1
  35. package/dashboard/dist/assets/CfMS9yIf.js.br +0 -0
  36. package/dashboard/dist/assets/CfMS9yIf.js.gz +0 -0
  37. package/dashboard/dist/assets/D2Kqcmv9.js +212 -0
  38. package/dashboard/dist/assets/D2Kqcmv9.js.br +0 -0
  39. package/dashboard/dist/assets/D2Kqcmv9.js.gz +0 -0
  40. package/dashboard/dist/assets/{DLNTxNX-.js → DS79hzMu.js} +1 -1
  41. package/dashboard/dist/assets/DS79hzMu.js.br +0 -0
  42. package/dashboard/dist/assets/DS79hzMu.js.gz +0 -0
  43. package/dashboard/dist/assets/{DBRLnKWw.js → PVi0vr9a.js} +1 -1
  44. package/dashboard/dist/assets/PVi0vr9a.js.br +0 -0
  45. package/dashboard/dist/assets/PVi0vr9a.js.gz +0 -0
  46. package/dashboard/dist/assets/{B7kFLPiD.js → a6qcPiWt.js} +1 -1
  47. package/dashboard/dist/assets/a6qcPiWt.js.br +0 -0
  48. package/dashboard/dist/assets/a6qcPiWt.js.gz +0 -0
  49. package/dashboard/dist/assets/{DdYkuATV.js → qDJ6rqcs.js} +1 -1
  50. package/dashboard/dist/assets/qDJ6rqcs.js.br +0 -0
  51. package/dashboard/dist/assets/qDJ6rqcs.js.gz +0 -0
  52. package/dashboard/dist/assets/{Crj3jKHE.js → sdoPH_Z1.js} +1 -1
  53. package/dashboard/dist/assets/sdoPH_Z1.js.br +0 -0
  54. package/dashboard/dist/assets/sdoPH_Z1.js.gz +0 -0
  55. package/dashboard/dist/index.html +1 -1
  56. package/dashboard/dist/index.html.br +0 -0
  57. package/dashboard/dist/index.html.gz +0 -0
  58. package/package.json +1 -1
  59. package/dashboard/dist/assets/05zHA1Am.js.br +0 -0
  60. package/dashboard/dist/assets/05zHA1Am.js.gz +0 -0
  61. package/dashboard/dist/assets/0uYJrBLl.js.br +0 -0
  62. package/dashboard/dist/assets/0uYJrBLl.js.gz +0 -0
  63. package/dashboard/dist/assets/8nr6IqT4.js.br +0 -0
  64. package/dashboard/dist/assets/8nr6IqT4.js.gz +0 -0
  65. package/dashboard/dist/assets/B7kFLPiD.js.br +0 -0
  66. package/dashboard/dist/assets/B7kFLPiD.js.gz +0 -0
  67. package/dashboard/dist/assets/B8NuBCcY.js.br +0 -0
  68. package/dashboard/dist/assets/B8NuBCcY.js.gz +0 -0
  69. package/dashboard/dist/assets/BDlKSbsp.js.br +0 -0
  70. package/dashboard/dist/assets/BDlKSbsp.js.gz +0 -0
  71. package/dashboard/dist/assets/C8AYbjlq.js +0 -212
  72. package/dashboard/dist/assets/C8AYbjlq.js.br +0 -0
  73. package/dashboard/dist/assets/C8AYbjlq.js.gz +0 -0
  74. package/dashboard/dist/assets/CMir7ekf.js.br +0 -0
  75. package/dashboard/dist/assets/CMir7ekf.js.gz +0 -0
  76. package/dashboard/dist/assets/CWXk6UZl.js.br +0 -0
  77. package/dashboard/dist/assets/CWXk6UZl.js.gz +0 -0
  78. package/dashboard/dist/assets/CoDun8X6.js.br +0 -0
  79. package/dashboard/dist/assets/CoDun8X6.js.gz +0 -0
  80. package/dashboard/dist/assets/Crj3jKHE.js.br +0 -0
  81. package/dashboard/dist/assets/Crj3jKHE.js.gz +0 -0
  82. package/dashboard/dist/assets/CyUpNSKv.js.br +0 -0
  83. package/dashboard/dist/assets/CyUpNSKv.js.gz +0 -0
  84. package/dashboard/dist/assets/D8mvKY2h.js.br +0 -0
  85. package/dashboard/dist/assets/D8mvKY2h.js.gz +0 -0
  86. package/dashboard/dist/assets/DBRLnKWw.js.br +0 -0
  87. package/dashboard/dist/assets/DBRLnKWw.js.gz +0 -0
  88. package/dashboard/dist/assets/DBct8HLW.js.br +0 -0
  89. package/dashboard/dist/assets/DBct8HLW.js.gz +0 -0
  90. package/dashboard/dist/assets/DLNTxNX-.js.br +0 -0
  91. package/dashboard/dist/assets/DLNTxNX-.js.gz +0 -0
  92. package/dashboard/dist/assets/DdYkuATV.js.br +0 -0
  93. package/dashboard/dist/assets/DdYkuATV.js.gz +0 -0
  94. package/dashboard/dist/assets/DvFumX8R.js.br +0 -0
  95. package/dashboard/dist/assets/DvFumX8R.js.gz +0 -0
@@ -1 +1 @@
1
- import{r as a,j as e}from"./Dj2k1r16.js";import{e as i}from"./C8AYbjlq.js";import{A as m,m as x}from"./eeHXe_OQ.js";function f({message:l,durationMs:s=5e3,onUndo:d,onExpire:r}){const[t,c]=a.useState(!0),o=a.useRef();a.useEffect(()=>(o.current=setTimeout(()=>{c(!1),r()},s),()=>clearTimeout(o.current)),[s,r]);const n=()=>{clearTimeout(o.current),c(!1),d()};return e.jsx(m,{children:t&&e.jsx(x.div,{initial:{opacity:0,y:20,scale:.95},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:10,scale:.95},transition:{duration:.22,ease:[.22,1,.36,1]},className:"fixed bottom-6 left-1/2 z-50 -translate-x-1/2",children:e.jsxs("div",{className:"flex items-center gap-3 rounded-xl px-4 py-2.5 shadow-lg",style:{backgroundColor:i.cardBgElevated,border:`1px solid ${i.cardBorderStrong}`},children:[e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:i.lime,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M20 6 9 17l-5-5"})}),e.jsx("span",{className:"text-body text-primary",children:l}),e.jsx("button",{onClick:n,className:"ml-1 rounded-md px-2.5 py-1 text-caption font-semibold transition-colors hover:bg-white/[0.08]",style:{color:i.lime},children:"Undo"}),e.jsx("div",{className:"absolute bottom-0 left-3 right-3 h-0.5 overflow-hidden rounded-full",children:e.jsx("div",{className:"h-full origin-left rounded-full",style:{backgroundColor:i.lime,opacity:.4,animation:`undoCountdown ${s}ms linear forwards`}})})]})})})}function y(){const[l,s]=a.useState([]),d=o=>{const n=`undo-${Date.now()}-${Math.random().toString(36).slice(2,6)}`;return s(u=>[...u,{...o,id:n}]),n},r=o=>{s(n=>n.filter(u=>u.id!==o))},t=l[0]??null;return{enqueue:d,ToastRenderer:()=>t?e.jsx(f,{message:t.message,onUndo:()=>{t.onUndo(),r(t.id)},onExpire:()=>{t.onCommit(),r(t.id)}},t.id):null}}export{y as u};
1
+ import{r as a,j as e}from"./Dj2k1r16.js";import{e as i}from"./D2Kqcmv9.js";import{A as m,m as x}from"./eeHXe_OQ.js";function f({message:l,durationMs:s=5e3,onUndo:d,onExpire:r}){const[t,c]=a.useState(!0),o=a.useRef();a.useEffect(()=>(o.current=setTimeout(()=>{c(!1),r()},s),()=>clearTimeout(o.current)),[s,r]);const n=()=>{clearTimeout(o.current),c(!1),d()};return e.jsx(m,{children:t&&e.jsx(x.div,{initial:{opacity:0,y:20,scale:.95},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:10,scale:.95},transition:{duration:.22,ease:[.22,1,.36,1]},className:"fixed bottom-6 left-1/2 z-50 -translate-x-1/2",children:e.jsxs("div",{className:"flex items-center gap-3 rounded-xl px-4 py-2.5 shadow-lg",style:{backgroundColor:i.cardBgElevated,border:`1px solid ${i.cardBorderStrong}`},children:[e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:i.lime,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M20 6 9 17l-5-5"})}),e.jsx("span",{className:"text-body text-primary",children:l}),e.jsx("button",{onClick:n,className:"ml-1 rounded-md px-2.5 py-1 text-caption font-semibold transition-colors hover:bg-white/[0.08]",style:{color:i.lime},children:"Undo"}),e.jsx("div",{className:"absolute bottom-0 left-3 right-3 h-0.5 overflow-hidden rounded-full",children:e.jsx("div",{className:"h-full origin-left rounded-full",style:{backgroundColor:i.lime,opacity:.4,animation:`undoCountdown ${s}ms linear forwards`}})})]})})})}function y(){const[l,s]=a.useState([]),d=o=>{const n=`undo-${Date.now()}-${Math.random().toString(36).slice(2,6)}`;return s(u=>[...u,{...o,id:n}]),n},r=o=>{s(n=>n.filter(u=>u.id!==o))},t=l[0]??null;return{enqueue:d,ToastRenderer:()=>t?e.jsx(f,{message:t.message,onUndo:()=>{t.onUndo(),r(t.id)},onExpire:()=>{t.onCommit(),r(t.id)}},t.id):null}}export{y as u};
@@ -1 +1 @@
1
- import{r as c}from"./Dj2k1r16.js";import{c as m}from"./DMKyYAtD.js";import{b as g,h as n}from"./C8AYbjlq.js";function h({authToken:s=null,embedMode:o=!1,enabled:i=!0}={}){var a;const u=c.useMemo(()=>["usage-control-plane",{authToken:s,embedMode:o}],[s,o]),e=m({queryKey:u,enabled:i,queryFn:async()=>{const t=await fetch("/orgx/api/usage/control-plane/summary",{headers:g({authToken:s,embedMode:o})}),r=await t.json().catch(()=>null);if(!t.ok){const l=(r&&typeof r=="object"&&"error"in r&&typeof r.error=="string"?r.error:null)??(r&&typeof r=="object"&&"message"in r&&typeof r.message=="string"?r.message:null)??`Failed to load usage summary (${t.status})`;throw new Error(n(l))}if(!r||typeof r!="object"||!("generatedAt"in r))throw new Error(n("Usage summary response is missing required fields."));return r},refetchInterval:6e4});return{summary:e.data??null,isLoading:e.isLoading,isFetching:e.isFetching,error:((a=e.error)==null?void 0:a.message)??null,refetch:e.refetch}}export{h as u};
1
+ import{r as c}from"./Dj2k1r16.js";import{c as m}from"./DMKyYAtD.js";import{b as g,h as n}from"./D2Kqcmv9.js";function h({authToken:s=null,embedMode:o=!1,enabled:i=!0}={}){var a;const u=c.useMemo(()=>["usage-control-plane",{authToken:s,embedMode:o}],[s,o]),e=m({queryKey:u,enabled:i,queryFn:async()=>{const t=await fetch("/orgx/api/usage/control-plane/summary",{headers:g({authToken:s,embedMode:o})}),r=await t.json().catch(()=>null);if(!t.ok){const l=(r&&typeof r=="object"&&"error"in r&&typeof r.error=="string"?r.error:null)??(r&&typeof r=="object"&&"message"in r&&typeof r.message=="string"?r.message:null)??`Failed to load usage summary (${t.status})`;throw new Error(n(l))}if(!r||typeof r!="object"||!("generatedAt"in r))throw new Error(n("Usage summary response is missing required fields."));return r},refetchInterval:6e4});return{summary:e.data??null,isLoading:e.isLoading,isFetching:e.isFetching,error:((a=e.error)==null?void 0:a.message)??null,refetch:e.refetch}}export{h as u};
@@ -1 +1 @@
1
- import{r as s,j as t}from"./Dj2k1r16.js";import{y as ke}from"./C8AYbjlq.js";import"./DMKyYAtD.js";import"./eeHXe_OQ.js";import"./cX2e-TLi.js";import"./BjK42gtU.js";import"./BV0BcV1u.js";const I={PREVIEW:"orgx_orchestrator_preview",APPLY:"orgx_orchestrator_apply",STATUS:"orgx_orchestrator_status"};function l(p){if(typeof p!="string")return null;const n=p.trim();return n.length?n:null}function Ce(p){if(!p.trim())return{};const n=JSON.parse(p);return!n||typeof n!="object"||Array.isArray(n)?{}:n}function Q(p){const n=l(p.transcript)??l(p.text)??l(p.delta??null);if(n)return n;const h=p.item&&typeof p.item=="object"?p.item:null,v=Array.isArray(h==null?void 0:h.content)?h==null?void 0:h.content:[];for(const y of v){if(!y||typeof y!="object")continue;const f=l(y.transcript)??l(y.text);if(f)return f}return null}function Se(p){const n=p.response&&typeof p.response=="object"?p.response:null,h=Array.isArray(n==null?void 0:n.output)?n==null?void 0:n.output:[],v=[];for(const y of h){if(!y||typeof y!="object")continue;const f=y;if(f.type!=="function_call")continue;const C=l(f.name),S=l(f.call_id)??l(f.id),A=typeof f.arguments=="string"?f.arguments:"{}";!C||!S||v.push({callId:S,name:C,arguments:A})}return v}function Ae(p){const n=Number.isFinite(p)?p*100:0;return`${Math.max(0,Math.min(100,Math.round(n)))}%`}const fe=[{type:"function",name:I.PREVIEW,description:"Preview orchestrator actions from a natural language command. Use this before apply.",parameters:{type:"object",additionalProperties:!1,properties:{input:{type:"string",description:"Natural language command from the operator."},workspace_id:{type:"string",description:"Optional OrgX workspace/command_center id."}},required:["input"]}},{type:"function",name:I.APPLY,description:"Apply selected action ids from a previewed command after user confirmation.",parameters:{type:"object",additionalProperties:!1,properties:{command_id:{type:"string",description:"Command id from preview response."},confirmed_action_ids:{type:"array",items:{type:"string"},description:"Optional subset of action ids to apply. Omit to apply all."},workspace_id:{type:"string",description:"Optional OrgX workspace/command_center id."}},required:["command_id"]}},{type:"function",name:I.STATUS,description:"Get latest status for a previously created command.",parameters:{type:"object",additionalProperties:!1,properties:{command_id:{type:"string",description:"Command id from preview/apply response."}},required:["command_id"]}}];function Me({open:p,selectedWorkspaceId:n,onClose:h}){var le,de,pe;const[v,y]=s.useState(!1),[f,C]=s.useState(!1),[S,A]=s.useState(!1),[xe,he]=s.useState("gpt-realtime-1.5"),[$,Z]=s.useState(""),[W,M]=s.useState(""),[o,P]=s.useState(null),[T,X]=s.useState([]),[ee,te]=s.useState(!1),[re,oe]=s.useState(!1),[se,b]=s.useState(null),[ne,z]=s.useState([]),G=s.useRef(null),D=s.useRef(null),O=s.useRef(null),H=s.useRef(null),E=s.useRef(""),J=s.useRef(new Set),R=s.useCallback(e=>{z(r=>[e,...r].slice(0,10))},[]),N=s.useCallback(()=>{A(!1),C(!1),J.current=new Set;const e=D.current;if(e)try{e.close()}catch{}D.current=null;const r=G.current;if(r)try{r.close()}catch{}G.current=null;const a=O.current;if(a)for(const m of a.getTracks())try{m.stop()}catch{}O.current=null;const d=H.current;if(d){try{const m=d.srcObject;m==null||m.getTracks().forEach(i=>i.stop())}catch{}try{d.pause()}catch{}d.srcObject=null}H.current=null},[]);s.useEffect(()=>{p||(N(),b(null),M(""),z([]),E.current="")},[N,p]),s.useEffect(()=>()=>N(),[N]);const g=s.useCallback(e=>{const r=D.current;!r||r.readyState!=="open"||r.send(JSON.stringify(e))},[]),ae=s.useCallback(async e=>{const r=await fetch(e),a=await r.json().catch(()=>({}));if(!r.ok)throw new Error(a&&typeof a=="object"&&"error"in a&&a.error||`Request failed: ${r.status}`);return a},[]),j=s.useCallback(async(e,r)=>{const a=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)}),d=await a.json().catch(()=>({}));if(!a.ok)throw new Error(d&&typeof d=="object"&&"error"in d&&d.error||`Request failed: ${a.status}`);return d},[]),L=s.useCallback(async e=>{if(!J.current.has(e.callId)){J.current.add(e.callId);try{const r=Ce(e.arguments);let a={ok:!1,error:"Unsupported tool call."};if(e.name===I.PREVIEW){const d=l(r.input);if(!d)throw new Error("Preview tool call requires input.");const m=await j("/orgx/api/orchestrator/commands/preview",{input:d,workspace_id:l(r.workspace_id)??n??void 0});if(!m.command)throw new Error(m.error??"Preview command failed.");P(m.command),X(m.command.proposedActions.map(i=>i.actionId)),a={ok:!0,command:m.command}}else if(e.name===I.APPLY){const d=l(r.command_id);if(!d)throw new Error("Apply tool call requires command_id.");const m=Array.isArray(r.confirmed_action_ids)?r.confirmed_action_ids.filter(F=>typeof F=="string"):void 0,i=await j("/orgx/api/orchestrator/commands/apply",{command_id:d,confirmed_action_ids:m,workspace_id:l(r.workspace_id)??n??void 0});if(!i.command)throw new Error(i.error??"Apply command failed.");P(i.command),a={ok:!0,command:i.command}}else if(e.name===I.STATUS){const d=l(r.command_id);if(!d)throw new Error("Status tool call requires command_id.");const m=await ae(`/orgx/api/orchestrator/commands/${encodeURIComponent(d)}`);if(!m.command)throw new Error(m.error??"Command status unavailable.");P(m.command),a={ok:!0,command:m.command}}g({type:"conversation.item.create",item:{type:"function_call_output",call_id:e.callId,output:JSON.stringify(a)}}),g({type:"response.create"}),R(`Tool executed: ${e.name}`)}catch(r){const a=r instanceof Error?r.message:"Tool execution failed.";b(a),g({type:"conversation.item.create",item:{type:"function_call_output",call_id:e.callId,output:JSON.stringify({ok:!1,error:a})}}),g({type:"response.create"}),R(`Tool failed: ${e.name}`)}}},[ae,R,j,n,g]),ye=s.useCallback(async()=>{var e,r,a,d,m;if(!((e=navigator.mediaDevices)!=null&&e.getUserMedia)){b("Microphone capture is unavailable in this browser/runtime.");return}b(null),y(!0),z([]);try{const i=await j("/orgx/api/realtime/session",{workspace_id:n??void 0,model:"gpt-realtime-1.5",voice:"alloy",tool_choice:"auto",tools:fe,instructions:"You are the OrgX realtime orchestrator copilot. Use tools for state-changing operations. Before applying actions, state the plan concisely."});if(!(i!=null&&i.session))throw new Error((i==null?void 0:i.error)??"Failed to create realtime session.");const F=l((r=i==null?void 0:i.session)==null?void 0:r.model)??l((a=i==null?void 0:i.defaults)==null?void 0:a.model)??"gpt-realtime-1.5";he(F);const me=l((m=(d=i==null?void 0:i.session)==null?void 0:d.client_secret)==null?void 0:m.value);if(!me)throw new Error("Realtime session is missing client_secret.");const U=await navigator.mediaDevices.getUserMedia({audio:!0});O.current=U;for(const _ of U.getAudioTracks())_.enabled=!1;const k=new RTCPeerConnection;G.current=k,U.getTracks().forEach(_=>k.addTrack(_,U));const q=document.createElement("audio");q.autoplay=!0,H.current=q,k.ontrack=_=>{const[u]=_.streams;u&&(q.srcObject=u,q.play().catch(()=>{}))};const V=k.createDataChannel("oai-events");D.current=V,V.onmessage=_=>{try{const u=JSON.parse(String(_.data)),x=l(u.type)??"";if(x==="error"){const c=u.error&&typeof u.error=="object"?u.error:null,w=l(c==null?void 0:c.message)??l(u.message)??"Realtime session error.";b(w),R(`Error: ${w}`);return}if(x==="conversation.item.input_audio_transcription.completed"){const c=Q(u);c&&Z(c)}if(x==="response.output_text.delta"||x==="response.text.delta"||x==="response.output_audio_transcript.delta"||x==="response.audio_transcript.delta"){const c=l(u.delta)??Q(u);c&&(E.current=`${E.current}${c}`,M(E.current))}if(x==="response.output_text.done"||x==="response.text.done"||x==="response.output_audio_transcript.done"||x==="response.audio_transcript.done"){const c=Q(u);c&&(E.current=c,M(c))}if(x==="response.function_call_arguments.done"){const c=l(u.call_id),w=l(u.name);if(c&&w){const B=typeof u.arguments=="string"?u.arguments:"{}";L({callId:c,name:w,arguments:B})}}if(x==="response.output_item.done"){const c=u.item&&typeof u.item=="object"?u.item:null;if((c==null?void 0:c.type)==="function_call"){const w=l(c.call_id)??l(c.id),B=l(c.name);if(w&&B){const Ne=typeof c.arguments=="string"?c.arguments:"{}";L({callId:w,name:B,arguments:Ne})}}}if(x==="response.done"){const c=Se(u);for(const w of c)L(w)}}catch{}},V.onopen=()=>{C(!0),g({type:"session.update",session:{tools:fe,tool_choice:"auto"}}),R("Realtime connected")},V.onclose=()=>{C(!1),A(!1)};const ue=await k.createOffer();await k.setLocalDescription(ue);const Y=await fetch(`https://api.openai.com/v1/realtime?model=${encodeURIComponent(F)}`,{method:"POST",headers:{Authorization:`Bearer ${me}`,"Content-Type":"application/sdp"},body:ue.sdp??""});if(!Y.ok){const _=await Y.text().catch(()=>Y.statusText);throw new Error(`Realtime SDP negotiation failed: ${_}`)}const ve=await Y.text();await k.setRemoteDescription({type:"answer",sdp:ve})}catch(i){N(),b(i instanceof Error?i.message:"Failed to connect realtime session.")}finally{y(!1)}},[N,L,R,j,n]),ie=s.useCallback(()=>{if(!f)return;const e=O.current;if(e){for(const r of e.getAudioTracks())r.enabled=!0;E.current="",M(""),A(!0),g({type:"input_audio_buffer.clear"})}},[f,g]),K=s.useCallback(()=>{const e=O.current;if(e)for(const r of e.getAudioTracks())r.enabled=!1;A(!1),g({type:"input_audio_buffer.commit"}),g({type:"response.create"})},[g]),ge=s.useCallback(async()=>{const e=$.trim();if(e){te(!0),b(null);try{const r=await j("/orgx/api/orchestrator/commands/preview",{input:e,workspace_id:n??void 0});if(!r.command)throw new Error(r.error??"Failed to preview command.");P(r.command),X(r.command.proposedActions.map(a=>a.actionId))}catch(r){b(r instanceof Error?r.message:"Failed to preview command.")}finally{te(!1)}}},[$,j,n]),be=s.useCallback(async()=>{if(o!=null&&o.id){oe(!0),b(null);try{const e=await j("/orgx/api/orchestrator/commands/apply",{command_id:o.id,confirmed_action_ids:T,workspace_id:n??void 0});if(!e.command)throw new Error(e.error??"Failed to apply command.");P(e.command)}catch(e){b(e instanceof Error?e.message:"Failed to apply command.")}finally{oe(!1)}}},[o==null?void 0:o.id,j,T,n]),ce=T.length,we=(((le=o==null?void 0:o.proposedActions)==null?void 0:le.length)??0)>0,je=!!(o!=null&&o.id)&&ce>0&&!re,_e=s.useMemo(()=>{const e=(o==null?void 0:o.status)??"draft";return e==="completed"?"text-lime":e==="completed_with_errors"||e==="failed"?"text-amber-300":e==="applying"?"text-teal":"text-secondary"},[o==null?void 0:o.status]);return t.jsxs(ke,{open:p,onClose:h,maxWidth:"max-w-5xl",fitContent:!0,closeOnEscapeWhenTyping:!1,children:[t.jsx("div",{className:"border-b border-strong px-4 py-3",children:t.jsxs("div",{className:"flex items-start justify-between gap-3",children:[t.jsxs("div",{children:[t.jsx("p",{className:"text-caption uppercase tracking-[0.14em] text-secondary",children:"Realtime Orchestrator"}),t.jsx("h2",{className:"text-heading font-semibold text-white",children:"GPT Realtime 1.5"}),t.jsx("p",{className:"text-micro text-secondary",children:"Voice + tool-calls for initiative launch, decision resolution, and Next Up control."})]}),t.jsx("button",{type:"button",onClick:h,className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption text-secondary transition-colors hover:bg-white/[0.08] hover:text-white",children:"Close"})]})}),t.jsxs("div",{className:"grid gap-4 px-4 pb-4 pt-3 lg:grid-cols-[1.12fr_1fr]",children:[t.jsxs("section",{className:"space-y-3",children:[t.jsxs("div",{className:"rounded-xl border border-strong bg-white/[0.02] p-3",children:[t.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[t.jsx("span",{className:"text-caption uppercase tracking-[0.12em] text-secondary",children:"Session"}),t.jsx("span",{className:"text-micro text-secondary",children:xe})]}),t.jsx("div",{className:"flex flex-wrap items-center gap-2",children:f?t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",onMouseDown:ie,onMouseUp:K,onMouseLeave:()=>{S&&K()},onTouchStart:e=>{e.preventDefault(),ie()},onTouchEnd:e=>{e.preventDefault(),K()},className:`rounded-full border px-3 py-1.5 text-caption font-semibold transition-colors ${S?"border-teal/45 bg-teal/[0.16] text-teal":"border-white/[0.2] bg-white/[0.04] text-primary hover:bg-white/[0.1]"}`,children:S?"Listening… release to send":"Hold to talk"}),t.jsx("button",{type:"button",onClick:N,className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption text-secondary transition-colors hover:bg-white/[0.08] hover:text-primary",children:"Disconnect"})]}):t.jsx("button",{type:"button",disabled:v,onClick:()=>void ye(),className:"rounded-full border border-lime/35 bg-lime/[0.12] px-3 py-1.5 text-caption font-semibold text-lime transition-colors hover:bg-lime/[0.2] disabled:cursor-not-allowed disabled:opacity-60",children:v?"Connecting…":"Connect Realtime"})}),ne.length>0?t.jsx("div",{className:"mt-3 rounded-lg border border-strong bg-black/20 p-2",children:ne.map((e,r)=>t.jsx("p",{className:"text-micro text-secondary",children:e},`${e}-${r}`))}):null]}),t.jsxs("div",{className:"rounded-xl border border-strong bg-white/[0.02] p-3",children:[t.jsx("label",{className:"mb-2 block text-caption uppercase tracking-[0.12em] text-secondary",children:"Command Input"}),t.jsx("textarea",{value:$,onChange:e=>Z(e.target.value),rows:4,"data-modal-autofocus":"true",placeholder:"Example: create initiative called AI Readiness Audit for this workspace",className:"w-full rounded-lg border border-strong bg-[#040912] px-3 py-2 text-body text-primary placeholder:text-secondary focus:border-lime/35 focus:outline-none"}),W?t.jsxs("p",{className:"mt-2 text-caption text-secondary",children:["Assistant: ",t.jsx("span",{className:"text-primary",children:W})]}):null,t.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[t.jsx("button",{type:"button",disabled:ee||$.trim().length===0,onClick:()=>void ge(),className:"rounded-full border border-teal/35 bg-teal/[0.12] px-3 py-1.5 text-caption font-semibold text-teal transition-colors hover:bg-teal/[0.2] disabled:cursor-not-allowed disabled:opacity-60",children:ee?"Previewing…":"Preview Actions"}),t.jsx("button",{type:"button",disabled:!je,onClick:()=>void be(),className:"rounded-full border border-lime/35 bg-lime/[0.12] px-3 py-1.5 text-caption font-semibold text-lime transition-colors hover:bg-lime/[0.2] disabled:cursor-not-allowed disabled:opacity-60",children:re?"Applying…":`Apply (${ce})`})]})]})]}),t.jsxs("section",{className:"space-y-3",children:[t.jsxs("div",{className:"rounded-xl border border-strong bg-white/[0.02] p-3",children:[t.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[t.jsx("span",{className:"text-caption uppercase tracking-[0.12em] text-secondary",children:"Command Status"}),t.jsx("span",{className:`text-caption font-semibold ${_e}`,children:(o==null?void 0:o.status)??"idle"})]}),t.jsx("p",{className:"text-body text-primary",children:(o==null?void 0:o.humanSummary)??"Preview a command or use voice to trigger tool calls."}),(de=o==null?void 0:o.riskFlags)!=null&&de.length?t.jsxs("p",{className:"mt-2 text-caption text-amber-200",children:["Risk flags: ",o.riskFlags.join(", ")]}):null]}),t.jsxs("div",{className:"max-h-[360px] space-y-2 overflow-y-auto rounded-xl border border-strong bg-white/[0.02] p-3",children:[t.jsx("p",{className:"text-caption uppercase tracking-[0.12em] text-secondary",children:"Proposed Actions"}),we?o.proposedActions.map(e=>{const r=T.includes(e.actionId);return t.jsx("label",{className:"block rounded-lg border border-strong bg-[#040912] p-2 text-body",children:t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsx("input",{type:"checkbox",checked:r,onChange:a=>{const d=a.target.checked?[...T,e.actionId]:T.filter(m=>m!==e.actionId);X(d)},className:"mt-1"}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:"font-semibold text-primary",children:e.type}),t.jsx("p",{className:"text-caption text-secondary",children:e.reason}),t.jsxs("p",{className:"text-micro text-secondary",children:["confidence ",Ae(e.confidence)," • impact ",e.blockingImpact]})]})]})},e.actionId)}):t.jsx("p",{className:"text-body text-secondary",children:"No actions inferred yet."})]}),(((pe=o==null?void 0:o.results)==null?void 0:pe.length)??0)>0?t.jsxs("div",{className:"max-h-[220px] space-y-2 overflow-y-auto rounded-xl border border-strong bg-white/[0.02] p-3",children:[t.jsx("p",{className:"text-caption uppercase tracking-[0.12em] text-secondary",children:"Apply Results"}),o.results.map(e=>t.jsxs("div",{className:`rounded-lg border p-2 text-body ${e.ok?"border-lime/30 bg-lime/[0.08] text-lime":"border-amber-400/35 bg-amber-500/[0.12] text-amber-100"}`,children:[t.jsx("p",{className:"font-semibold",children:e.type}),t.jsx("p",{className:"text-caption",children:e.message}),e.error?t.jsxs("p",{className:"text-micro text-amber-200",children:["error: ",e.error]}):null]},`${e.actionId}-${e.type}`))]}):null]})]}),se?t.jsx("div",{className:"border-t border-amber-500/30 bg-amber-500/[0.12] px-4 py-2 text-caption text-amber-100",children:se}):null]})}export{Me as RealtimeOrchestratorModal};
1
+ import{r as s,j as t}from"./Dj2k1r16.js";import{y as ke}from"./D2Kqcmv9.js";import"./DMKyYAtD.js";import"./eeHXe_OQ.js";import"./cX2e-TLi.js";import"./BjK42gtU.js";import"./BV0BcV1u.js";const I={PREVIEW:"orgx_orchestrator_preview",APPLY:"orgx_orchestrator_apply",STATUS:"orgx_orchestrator_status"};function l(p){if(typeof p!="string")return null;const n=p.trim();return n.length?n:null}function Ce(p){if(!p.trim())return{};const n=JSON.parse(p);return!n||typeof n!="object"||Array.isArray(n)?{}:n}function Q(p){const n=l(p.transcript)??l(p.text)??l(p.delta??null);if(n)return n;const h=p.item&&typeof p.item=="object"?p.item:null,v=Array.isArray(h==null?void 0:h.content)?h==null?void 0:h.content:[];for(const y of v){if(!y||typeof y!="object")continue;const f=l(y.transcript)??l(y.text);if(f)return f}return null}function Se(p){const n=p.response&&typeof p.response=="object"?p.response:null,h=Array.isArray(n==null?void 0:n.output)?n==null?void 0:n.output:[],v=[];for(const y of h){if(!y||typeof y!="object")continue;const f=y;if(f.type!=="function_call")continue;const C=l(f.name),S=l(f.call_id)??l(f.id),A=typeof f.arguments=="string"?f.arguments:"{}";!C||!S||v.push({callId:S,name:C,arguments:A})}return v}function Ae(p){const n=Number.isFinite(p)?p*100:0;return`${Math.max(0,Math.min(100,Math.round(n)))}%`}const fe=[{type:"function",name:I.PREVIEW,description:"Preview orchestrator actions from a natural language command. Use this before apply.",parameters:{type:"object",additionalProperties:!1,properties:{input:{type:"string",description:"Natural language command from the operator."},workspace_id:{type:"string",description:"Optional OrgX workspace/command_center id."}},required:["input"]}},{type:"function",name:I.APPLY,description:"Apply selected action ids from a previewed command after user confirmation.",parameters:{type:"object",additionalProperties:!1,properties:{command_id:{type:"string",description:"Command id from preview response."},confirmed_action_ids:{type:"array",items:{type:"string"},description:"Optional subset of action ids to apply. Omit to apply all."},workspace_id:{type:"string",description:"Optional OrgX workspace/command_center id."}},required:["command_id"]}},{type:"function",name:I.STATUS,description:"Get latest status for a previously created command.",parameters:{type:"object",additionalProperties:!1,properties:{command_id:{type:"string",description:"Command id from preview/apply response."}},required:["command_id"]}}];function Me({open:p,selectedWorkspaceId:n,onClose:h}){var le,de,pe;const[v,y]=s.useState(!1),[f,C]=s.useState(!1),[S,A]=s.useState(!1),[xe,he]=s.useState("gpt-realtime-1.5"),[$,Z]=s.useState(""),[W,M]=s.useState(""),[o,P]=s.useState(null),[T,X]=s.useState([]),[ee,te]=s.useState(!1),[re,oe]=s.useState(!1),[se,b]=s.useState(null),[ne,z]=s.useState([]),G=s.useRef(null),D=s.useRef(null),O=s.useRef(null),H=s.useRef(null),E=s.useRef(""),J=s.useRef(new Set),R=s.useCallback(e=>{z(r=>[e,...r].slice(0,10))},[]),N=s.useCallback(()=>{A(!1),C(!1),J.current=new Set;const e=D.current;if(e)try{e.close()}catch{}D.current=null;const r=G.current;if(r)try{r.close()}catch{}G.current=null;const a=O.current;if(a)for(const m of a.getTracks())try{m.stop()}catch{}O.current=null;const d=H.current;if(d){try{const m=d.srcObject;m==null||m.getTracks().forEach(i=>i.stop())}catch{}try{d.pause()}catch{}d.srcObject=null}H.current=null},[]);s.useEffect(()=>{p||(N(),b(null),M(""),z([]),E.current="")},[N,p]),s.useEffect(()=>()=>N(),[N]);const g=s.useCallback(e=>{const r=D.current;!r||r.readyState!=="open"||r.send(JSON.stringify(e))},[]),ae=s.useCallback(async e=>{const r=await fetch(e),a=await r.json().catch(()=>({}));if(!r.ok)throw new Error(a&&typeof a=="object"&&"error"in a&&a.error||`Request failed: ${r.status}`);return a},[]),j=s.useCallback(async(e,r)=>{const a=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)}),d=await a.json().catch(()=>({}));if(!a.ok)throw new Error(d&&typeof d=="object"&&"error"in d&&d.error||`Request failed: ${a.status}`);return d},[]),L=s.useCallback(async e=>{if(!J.current.has(e.callId)){J.current.add(e.callId);try{const r=Ce(e.arguments);let a={ok:!1,error:"Unsupported tool call."};if(e.name===I.PREVIEW){const d=l(r.input);if(!d)throw new Error("Preview tool call requires input.");const m=await j("/orgx/api/orchestrator/commands/preview",{input:d,workspace_id:l(r.workspace_id)??n??void 0});if(!m.command)throw new Error(m.error??"Preview command failed.");P(m.command),X(m.command.proposedActions.map(i=>i.actionId)),a={ok:!0,command:m.command}}else if(e.name===I.APPLY){const d=l(r.command_id);if(!d)throw new Error("Apply tool call requires command_id.");const m=Array.isArray(r.confirmed_action_ids)?r.confirmed_action_ids.filter(F=>typeof F=="string"):void 0,i=await j("/orgx/api/orchestrator/commands/apply",{command_id:d,confirmed_action_ids:m,workspace_id:l(r.workspace_id)??n??void 0});if(!i.command)throw new Error(i.error??"Apply command failed.");P(i.command),a={ok:!0,command:i.command}}else if(e.name===I.STATUS){const d=l(r.command_id);if(!d)throw new Error("Status tool call requires command_id.");const m=await ae(`/orgx/api/orchestrator/commands/${encodeURIComponent(d)}`);if(!m.command)throw new Error(m.error??"Command status unavailable.");P(m.command),a={ok:!0,command:m.command}}g({type:"conversation.item.create",item:{type:"function_call_output",call_id:e.callId,output:JSON.stringify(a)}}),g({type:"response.create"}),R(`Tool executed: ${e.name}`)}catch(r){const a=r instanceof Error?r.message:"Tool execution failed.";b(a),g({type:"conversation.item.create",item:{type:"function_call_output",call_id:e.callId,output:JSON.stringify({ok:!1,error:a})}}),g({type:"response.create"}),R(`Tool failed: ${e.name}`)}}},[ae,R,j,n,g]),ye=s.useCallback(async()=>{var e,r,a,d,m;if(!((e=navigator.mediaDevices)!=null&&e.getUserMedia)){b("Microphone capture is unavailable in this browser/runtime.");return}b(null),y(!0),z([]);try{const i=await j("/orgx/api/realtime/session",{workspace_id:n??void 0,model:"gpt-realtime-1.5",voice:"alloy",tool_choice:"auto",tools:fe,instructions:"You are the OrgX realtime orchestrator copilot. Use tools for state-changing operations. Before applying actions, state the plan concisely."});if(!(i!=null&&i.session))throw new Error((i==null?void 0:i.error)??"Failed to create realtime session.");const F=l((r=i==null?void 0:i.session)==null?void 0:r.model)??l((a=i==null?void 0:i.defaults)==null?void 0:a.model)??"gpt-realtime-1.5";he(F);const me=l((m=(d=i==null?void 0:i.session)==null?void 0:d.client_secret)==null?void 0:m.value);if(!me)throw new Error("Realtime session is missing client_secret.");const U=await navigator.mediaDevices.getUserMedia({audio:!0});O.current=U;for(const _ of U.getAudioTracks())_.enabled=!1;const k=new RTCPeerConnection;G.current=k,U.getTracks().forEach(_=>k.addTrack(_,U));const q=document.createElement("audio");q.autoplay=!0,H.current=q,k.ontrack=_=>{const[u]=_.streams;u&&(q.srcObject=u,q.play().catch(()=>{}))};const V=k.createDataChannel("oai-events");D.current=V,V.onmessage=_=>{try{const u=JSON.parse(String(_.data)),x=l(u.type)??"";if(x==="error"){const c=u.error&&typeof u.error=="object"?u.error:null,w=l(c==null?void 0:c.message)??l(u.message)??"Realtime session error.";b(w),R(`Error: ${w}`);return}if(x==="conversation.item.input_audio_transcription.completed"){const c=Q(u);c&&Z(c)}if(x==="response.output_text.delta"||x==="response.text.delta"||x==="response.output_audio_transcript.delta"||x==="response.audio_transcript.delta"){const c=l(u.delta)??Q(u);c&&(E.current=`${E.current}${c}`,M(E.current))}if(x==="response.output_text.done"||x==="response.text.done"||x==="response.output_audio_transcript.done"||x==="response.audio_transcript.done"){const c=Q(u);c&&(E.current=c,M(c))}if(x==="response.function_call_arguments.done"){const c=l(u.call_id),w=l(u.name);if(c&&w){const B=typeof u.arguments=="string"?u.arguments:"{}";L({callId:c,name:w,arguments:B})}}if(x==="response.output_item.done"){const c=u.item&&typeof u.item=="object"?u.item:null;if((c==null?void 0:c.type)==="function_call"){const w=l(c.call_id)??l(c.id),B=l(c.name);if(w&&B){const Ne=typeof c.arguments=="string"?c.arguments:"{}";L({callId:w,name:B,arguments:Ne})}}}if(x==="response.done"){const c=Se(u);for(const w of c)L(w)}}catch{}},V.onopen=()=>{C(!0),g({type:"session.update",session:{tools:fe,tool_choice:"auto"}}),R("Realtime connected")},V.onclose=()=>{C(!1),A(!1)};const ue=await k.createOffer();await k.setLocalDescription(ue);const Y=await fetch(`https://api.openai.com/v1/realtime?model=${encodeURIComponent(F)}`,{method:"POST",headers:{Authorization:`Bearer ${me}`,"Content-Type":"application/sdp"},body:ue.sdp??""});if(!Y.ok){const _=await Y.text().catch(()=>Y.statusText);throw new Error(`Realtime SDP negotiation failed: ${_}`)}const ve=await Y.text();await k.setRemoteDescription({type:"answer",sdp:ve})}catch(i){N(),b(i instanceof Error?i.message:"Failed to connect realtime session.")}finally{y(!1)}},[N,L,R,j,n]),ie=s.useCallback(()=>{if(!f)return;const e=O.current;if(e){for(const r of e.getAudioTracks())r.enabled=!0;E.current="",M(""),A(!0),g({type:"input_audio_buffer.clear"})}},[f,g]),K=s.useCallback(()=>{const e=O.current;if(e)for(const r of e.getAudioTracks())r.enabled=!1;A(!1),g({type:"input_audio_buffer.commit"}),g({type:"response.create"})},[g]),ge=s.useCallback(async()=>{const e=$.trim();if(e){te(!0),b(null);try{const r=await j("/orgx/api/orchestrator/commands/preview",{input:e,workspace_id:n??void 0});if(!r.command)throw new Error(r.error??"Failed to preview command.");P(r.command),X(r.command.proposedActions.map(a=>a.actionId))}catch(r){b(r instanceof Error?r.message:"Failed to preview command.")}finally{te(!1)}}},[$,j,n]),be=s.useCallback(async()=>{if(o!=null&&o.id){oe(!0),b(null);try{const e=await j("/orgx/api/orchestrator/commands/apply",{command_id:o.id,confirmed_action_ids:T,workspace_id:n??void 0});if(!e.command)throw new Error(e.error??"Failed to apply command.");P(e.command)}catch(e){b(e instanceof Error?e.message:"Failed to apply command.")}finally{oe(!1)}}},[o==null?void 0:o.id,j,T,n]),ce=T.length,we=(((le=o==null?void 0:o.proposedActions)==null?void 0:le.length)??0)>0,je=!!(o!=null&&o.id)&&ce>0&&!re,_e=s.useMemo(()=>{const e=(o==null?void 0:o.status)??"draft";return e==="completed"?"text-lime":e==="completed_with_errors"||e==="failed"?"text-amber-300":e==="applying"?"text-teal":"text-secondary"},[o==null?void 0:o.status]);return t.jsxs(ke,{open:p,onClose:h,maxWidth:"max-w-5xl",fitContent:!0,closeOnEscapeWhenTyping:!1,children:[t.jsx("div",{className:"border-b border-strong px-4 py-3",children:t.jsxs("div",{className:"flex items-start justify-between gap-3",children:[t.jsxs("div",{children:[t.jsx("p",{className:"text-caption uppercase tracking-[0.14em] text-secondary",children:"Realtime Orchestrator"}),t.jsx("h2",{className:"text-heading font-semibold text-white",children:"GPT Realtime 1.5"}),t.jsx("p",{className:"text-micro text-secondary",children:"Voice + tool-calls for initiative launch, decision resolution, and Next Up control."})]}),t.jsx("button",{type:"button",onClick:h,className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption text-secondary transition-colors hover:bg-white/[0.08] hover:text-white",children:"Close"})]})}),t.jsxs("div",{className:"grid gap-4 px-4 pb-4 pt-3 lg:grid-cols-[1.12fr_1fr]",children:[t.jsxs("section",{className:"space-y-3",children:[t.jsxs("div",{className:"rounded-xl border border-strong bg-white/[0.02] p-3",children:[t.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[t.jsx("span",{className:"text-caption uppercase tracking-[0.12em] text-secondary",children:"Session"}),t.jsx("span",{className:"text-micro text-secondary",children:xe})]}),t.jsx("div",{className:"flex flex-wrap items-center gap-2",children:f?t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",onMouseDown:ie,onMouseUp:K,onMouseLeave:()=>{S&&K()},onTouchStart:e=>{e.preventDefault(),ie()},onTouchEnd:e=>{e.preventDefault(),K()},className:`rounded-full border px-3 py-1.5 text-caption font-semibold transition-colors ${S?"border-teal/45 bg-teal/[0.16] text-teal":"border-white/[0.2] bg-white/[0.04] text-primary hover:bg-white/[0.1]"}`,children:S?"Listening… release to send":"Hold to talk"}),t.jsx("button",{type:"button",onClick:N,className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption text-secondary transition-colors hover:bg-white/[0.08] hover:text-primary",children:"Disconnect"})]}):t.jsx("button",{type:"button",disabled:v,onClick:()=>void ye(),className:"rounded-full border border-lime/35 bg-lime/[0.12] px-3 py-1.5 text-caption font-semibold text-lime transition-colors hover:bg-lime/[0.2] disabled:cursor-not-allowed disabled:opacity-60",children:v?"Connecting…":"Connect Realtime"})}),ne.length>0?t.jsx("div",{className:"mt-3 rounded-lg border border-strong bg-black/20 p-2",children:ne.map((e,r)=>t.jsx("p",{className:"text-micro text-secondary",children:e},`${e}-${r}`))}):null]}),t.jsxs("div",{className:"rounded-xl border border-strong bg-white/[0.02] p-3",children:[t.jsx("label",{className:"mb-2 block text-caption uppercase tracking-[0.12em] text-secondary",children:"Command Input"}),t.jsx("textarea",{value:$,onChange:e=>Z(e.target.value),rows:4,"data-modal-autofocus":"true",placeholder:"Example: create initiative called AI Readiness Audit for this workspace",className:"w-full rounded-lg border border-strong bg-[#040912] px-3 py-2 text-body text-primary placeholder:text-secondary focus:border-lime/35 focus:outline-none"}),W?t.jsxs("p",{className:"mt-2 text-caption text-secondary",children:["Assistant: ",t.jsx("span",{className:"text-primary",children:W})]}):null,t.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[t.jsx("button",{type:"button",disabled:ee||$.trim().length===0,onClick:()=>void ge(),className:"rounded-full border border-teal/35 bg-teal/[0.12] px-3 py-1.5 text-caption font-semibold text-teal transition-colors hover:bg-teal/[0.2] disabled:cursor-not-allowed disabled:opacity-60",children:ee?"Previewing…":"Preview Actions"}),t.jsx("button",{type:"button",disabled:!je,onClick:()=>void be(),className:"rounded-full border border-lime/35 bg-lime/[0.12] px-3 py-1.5 text-caption font-semibold text-lime transition-colors hover:bg-lime/[0.2] disabled:cursor-not-allowed disabled:opacity-60",children:re?"Applying…":`Apply (${ce})`})]})]})]}),t.jsxs("section",{className:"space-y-3",children:[t.jsxs("div",{className:"rounded-xl border border-strong bg-white/[0.02] p-3",children:[t.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[t.jsx("span",{className:"text-caption uppercase tracking-[0.12em] text-secondary",children:"Command Status"}),t.jsx("span",{className:`text-caption font-semibold ${_e}`,children:(o==null?void 0:o.status)??"idle"})]}),t.jsx("p",{className:"text-body text-primary",children:(o==null?void 0:o.humanSummary)??"Preview a command or use voice to trigger tool calls."}),(de=o==null?void 0:o.riskFlags)!=null&&de.length?t.jsxs("p",{className:"mt-2 text-caption text-amber-200",children:["Risk flags: ",o.riskFlags.join(", ")]}):null]}),t.jsxs("div",{className:"max-h-[360px] space-y-2 overflow-y-auto rounded-xl border border-strong bg-white/[0.02] p-3",children:[t.jsx("p",{className:"text-caption uppercase tracking-[0.12em] text-secondary",children:"Proposed Actions"}),we?o.proposedActions.map(e=>{const r=T.includes(e.actionId);return t.jsx("label",{className:"block rounded-lg border border-strong bg-[#040912] p-2 text-body",children:t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsx("input",{type:"checkbox",checked:r,onChange:a=>{const d=a.target.checked?[...T,e.actionId]:T.filter(m=>m!==e.actionId);X(d)},className:"mt-1"}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:"font-semibold text-primary",children:e.type}),t.jsx("p",{className:"text-caption text-secondary",children:e.reason}),t.jsxs("p",{className:"text-micro text-secondary",children:["confidence ",Ae(e.confidence)," • impact ",e.blockingImpact]})]})]})},e.actionId)}):t.jsx("p",{className:"text-body text-secondary",children:"No actions inferred yet."})]}),(((pe=o==null?void 0:o.results)==null?void 0:pe.length)??0)>0?t.jsxs("div",{className:"max-h-[220px] space-y-2 overflow-y-auto rounded-xl border border-strong bg-white/[0.02] p-3",children:[t.jsx("p",{className:"text-caption uppercase tracking-[0.12em] text-secondary",children:"Apply Results"}),o.results.map(e=>t.jsxs("div",{className:`rounded-lg border p-2 text-body ${e.ok?"border-lime/30 bg-lime/[0.08] text-lime":"border-amber-400/35 bg-amber-500/[0.12] text-amber-100"}`,children:[t.jsx("p",{className:"font-semibold",children:e.type}),t.jsx("p",{className:"text-caption",children:e.message}),e.error?t.jsxs("p",{className:"text-micro text-amber-200",children:["error: ",e.error]}):null]},`${e.actionId}-${e.type}`))]}):null]})]}),se?t.jsx("div",{className:"border-t border-amber-500/30 bg-amber-500/[0.12] px-4 py-2 text-caption text-amber-100",children:se}):null]})}export{Me as RealtimeOrchestratorModal};
@@ -1 +1 @@
1
- import{r as l,j as e}from"./Dj2k1r16.js";import{G as Jt,u as Xt,K as b,P as Yt,B as ie,H as ft,T as Ot,C as I,v as Nt,A as kt,E as je,e as bt,h as Ye,D as gt,F as es,U as ts}from"./C8AYbjlq.js";import{S as A}from"./DvFumX8R.js";import{A as ke,m as z,u as jt,R as ss,b as ns,a as is}from"./eeHXe_OQ.js";import{Q as m,d as rs,q as Ue,a as wt,b as yt,c as St,e as Ze}from"./B7kFLPiD.js";async function Ct(s,a){var f;const o=await(await fetch(s,a)).json().catch(()=>null),p=((f=o==null?void 0:o.data)==null?void 0:f.url)??(o==null?void 0:o.url)??null;if(typeof p=="string"&&p.trim())return p.trim();throw new Error((o==null?void 0:o.error)??"Billing link unavailable")}async function as(s){var p;const a=((p=s==null?void 0:s.actions)==null?void 0:p.checkout)??"/orgx/api/billing/checkout",c=((s==null?void 0:s.requiredPlan)??"starter").trim().toLowerCase()||"starter",o=await Ct(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({planId:c})});window.open(o,"_blank","noopener,noreferrer")}async function os(s){var o;const a=((o=s==null?void 0:s.actions)==null?void 0:o.portal)??"/orgx/api/billing/portal",c=await Ct(a,{method:"POST"});window.open(c,"_blank","noopener,noreferrer")}function ls(s){return s==="success"?"border-emerald-400/30 bg-[#0A1210]/95 text-emerald-100":s==="warning"?"border-amber-300/30 bg-[#12100A]/95 text-amber-100":s==="error"?"border-red-400/32 bg-[#120A0A]/95 text-red-100":s==="info"?"border-cyan-300/28 bg-[#0A1012]/95 text-cyan-100":"border-strong bg-[#0B0F16]/95 text-primary"}function cs({open:s,tone:a="neutral",title:c,message:o=null,className:p,primaryAction:f=null,secondaryAction:k=null,onDismiss:S=null,autoDismissMs:q=null}){return l.useEffect(()=>{if(!s||!S||!q)return;const K=window.setTimeout(()=>S(),q);return()=>window.clearTimeout(K)},[q,S,s,c,o]),e.jsx(ke,{initial:!1,children:s?e.jsx(z.div,{initial:{opacity:0,y:-8,scale:.985},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-8,scale:.985},transition:{duration:.2,ease:[.22,1,.36,1]},className:`pointer-events-none ${p??""}`,children:e.jsxs("div",{className:`pointer-events-none min-w-[220px] max-w-[420px] rounded-xl border px-3 py-2 shadow-[0_16px_36px_rgba(0,0,0,0.42)] backdrop-blur ${ls(a)}`,children:[e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-caption font-semibold",children:c}),o?e.jsx("p",{className:"mt-0.5 text-caption opacity-85",children:o}):null]}),S?e.jsx("button",{type:"button",onClick:S,className:"pointer-events-auto inline-flex h-6 w-6 items-center justify-center rounded-md text-current/70 transition-colors hover:bg-white/[0.08] hover:text-current","aria-label":"Dismiss toast",title:"Dismiss",children:e.jsxs("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:"M18 6 6 18"}),e.jsx("path",{d:"m6 6 12 12"})]})}):null]}),f||k?e.jsxs("div",{className:"mt-2 flex items-center gap-1.5",children:[k?e.jsx("button",{type:"button",onClick:k.onClick,className:"pointer-events-auto h-7 rounded-md border border-strong bg-white/[0.06] px-2.5 text-micro font-semibold text-current transition-colors hover:bg-white/[0.12]",children:k.label}):null,f?e.jsx("button",{type:"button",onClick:f.onClick,className:"pointer-events-auto h-7 rounded-md border border-white/25 bg-white/[0.14] px-2.5 text-micro font-semibold text-current transition-colors hover:bg-white/[0.2]",children:f.label}):null]}):null]})}):null})}function It({className:s=""}){return e.jsx("svg",{viewBox:"0 0 20 20",fill:"none","aria-hidden":!0,className:s,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 ds({className:s=""}){return e.jsxs("svg",{viewBox:"0 0 20 20",fill:"none","aria-hidden":!0,className:s,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 us({className:s=""}){return e.jsxs("svg",{viewBox:"0 0 20 20",fill:"none","aria-hidden":!0,className:s,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 Je(s){const a=typeof s.sliceTaskCount=="number"&&Number.isFinite(s.sliceTaskCount)?Math.max(0,Math.floor(s.sliceTaskCount)):null,c=s.sliceScope==="task"?"task":s.sliceScope==="milestone"?"milestone slice":"workstream slice",o=a&&a>0?`${a} ${a===1?"task":"tasks"}`:null;return s.queueState===m.RUNNING?o?`Executing ${o} in ${c}.`:"Execution in progress. Task detail will appear as the scheduler advances.":s.queueState===m.BLOCKED?s.blockReason?"Blocked while waiting for dependency resolution.":"Blocked. Waiting for dependency or review.":s.queueState===m.QUEUED?o?`Queued with ${o} in ${c}.`:"Queued at workstream scope. Task detail will populate after dispatch.":s.queueState===m.COMPLETED?"Completed. No queued tasks remain.":"Idle. Ready to dispatch when started."}function qt(s){const a=typeof s.initiativePriority=="string"?s.initiativePriority.trim().toLowerCase():"",c=typeof s.initiativePriorityNum=="number"&&Number.isFinite(s.initiativePriorityNum)?Math.max(1,Math.min(100,Math.round(s.initiativePriorityNum))):null,o=a==="urgent"||a==="high"||a==="medium"||a==="low"?a:c!==null?c<=12?"urgent":c<=30?"high":c<=60?"medium":"low":null;if(!o)return null;const p=o==="urgent"?"P1":o==="high"?"P2":o==="medium"?"P3":"P4",f=o==="urgent"?"Urgent":o==="high"?"High":o==="medium"?"Medium":"Low",k=o==="urgent"?"border-red-300/35 bg-red-500/[0.14] text-red-100":o==="high"?"border-amber-300/35 bg-amber-500/[0.14] text-amber-100":o==="medium"?"border-[#BFFF00]/35 bg-[#BFFF00]/14 text-[#E1FFB2]":"border-white/[0.2] bg-white/[0.08] text-white/70";return{shortLabel:`${p} ${f}`,longLabel:`Initiative priority ${f} (${p})`,toneClass:k}}function ms(s){const a=s.trim().toLowerCase();if(a.includes("timed out")||a.includes("timeout")||a.includes("request cancelled")||a.includes("signal is aborted"))return"Next Up is still syncing. Keep this panel open and it will repopulate automatically.";if(a.includes("unauthorized")||a.includes("forbidden")||a.includes("api key")||a.includes("auth"))return"Next Up is unavailable until OrgX authentication is reconnected in Settings.";if(a.includes("unknown api endpoint")||a.includes("route is unavailable"))return"This runtime is missing queue routes. Restart and update the plugin build.";const c=s.split("|").map(o=>o.trim()).filter(Boolean).map(o=>o.replace(/^[^:]+:\s*/,"").trim()).filter(Boolean).slice(0,2).join(" ");return Ye(c||s)||"Next Up is temporarily unavailable."}function xs(s){const a=s.trim().toLowerCase();return a.includes("circular")||a.includes("timeline estimate")||a.includes("adjusted accordingly")?null:a.includes("timed out")||a.includes("timeout")||a.includes("request cancelled")||a.includes("signal is aborted")?"Signal is delayed right now. Queue data will appear as soon as sync catches up.":a.includes("fallback")?"Showing fallback queue data while full signal refreshes.":a.includes("unknown api endpoint")||a.includes("route is unavailable")?"Some queue controls are unavailable in this plugin build. Update and restart to restore full controls.":Ye(s.trim())}function Se(s,a,c){const o=typeof s=="string"?s.trim():"";if(o&&!gt(o))return I(o);const p=typeof a=="string"?a.trim():"";return p?gt(p)?`${c} ${es(p)}`:I(p):c}function $t(s){const a=typeof s.runnerAgentName=="string"?s.runnerAgentName.trim():"";if(!a)return"Unassigned";const c=a.toLowerCase();return c==="undefined"||c==="null"||c==="main"&&(s.runnerAgentId==="unassigned"||s.runnerSource==="fallback")?"Unassigned":a}function Tt(s){return s.runnerSource==="inferred"?"inferred":null}function Mt(s,a){const c=s.runnerSource==="assigned"?"assigned":s.runnerSource==="inferred"?"inferred":"fallback";return a==="Unassigned"?`Runner ${c}`:`${a} · ${c}`}function pe(s,a){return!s||s.trim().length===0?a:Ye(s.trim())||a}function vt(s){return!s||typeof s!="object"||Array.isArray(s)?null:s}function Xe(s,a){const c=I(s.workstreamTitle),o=vt(a),p=o&&typeof o.dispatchMode=="string"?o.dispatchMode:null,f=vt(o==null?void 0:o.run);return(f&&typeof f.stopReason=="string"?f.stopReason:f&&typeof f.stop_reason=="string"?f.stop_reason:null)==="budget_exhausted"?`Dispatch acknowledged for ${c}, but autopilot stopped: budget exhausted.`:p==="pending"?`Dispatching ${c}; waiting for slice start…`:p==="fallback"?`Dispatched ${c} using fallback runner.`:`Dispatched ${c}.`}function Rt({className:s=""}){return e.jsxs("svg",{viewBox:"0 0 20 20",fill:"none","aria-hidden":!0,className:s,children:[e.jsx("circle",{cx:"4.5",cy:"10",r:"1.4",fill:"currentColor"}),e.jsx("circle",{cx:"10",cy:"10",r:"1.4",fill:"currentColor"}),e.jsx("circle",{cx:"15.5",cy:"10",r:"1.4",fill:"currentColor"})]})}function ps({compact:s}){const a=s?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:a}).map((c,o)=>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(A,{className:"h-8 w-8 rounded-full"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx(A,{className:"h-3 w-40 rounded-md"}),e.jsx(A,{className:"mt-2 h-4 w-56 rounded-md"})]})]}),e.jsx(A,{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(A,{className:"h-3 w-14 rounded"}),e.jsx(A,{className:"mt-2 h-3 w-full rounded"}),e.jsx(A,{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(A,{className:"h-8 w-24 rounded-full"}),e.jsx(A,{className:"h-8 w-20 rounded-full"}),e.jsx(A,{className:"h-8 w-24 rounded-full"})]})]},`nextup-skeleton-${o}`))]})}function hs({initiativeId:s=null,projectId:a=null,authToken:c=null,embedMode:o=!1,title:p="Next Up",showHeader:f=!0,compact:k=!1,className:S,disableEnterAnimation:q=!1,allowCompactToggle:K=!1,onToggleCompact:he,onOpenInitiative:$,onOpenSettings:L,onUpgradeGate:D,onOpenSliceDetail:_,selectionEnabled:Q=!0,panelStyle:Ce="card",showQueueSettings:Ie=!0,queueModel:qe,queueActions:Ae,onPlayWorkstream:W,snapshotVersion:$e=null,excludeRunning:T=!1}){var ht;const[re,fe]=l.useState(k);l.useEffect(()=>fe(k),[k]);const d=K&&!he?re:k,ae=t=>{he?he(t):fe(t)},[B,y]=l.useState(null),[w,J]=l.useState("workstream"),oe="bottom",[j,le]=l.useState(null),[F,X]=l.useState(null),[x,Y]=l.useState(null),[V,ce]=l.useState(new Set),[Te,de]=l.useState(null),[be,ge]=l.useState(!1),[Et,Me]=l.useState(!1),G=jt(),Oe=l.useRef(null),et=l.useRef(null),tt=l.useRef(null),Lt=Jt({initiativeId:s,projectId:a,limit:40,authToken:c,embedMode:o,enabled:!qe,snapshotVersion:$e,zoomLevel:w}),Bt=qe??Lt,{items:ue,degraded:O,isLoading:M,isFetching:st,isFetchingNextPage:Re,hasNextPage:ze,error:Ee,refetch:Ft,fetchNextPage:nt,playWorkstream:Pt,startWorkstreamAutoContinue:it,initiativeGroups:De,milestoneGroups:_e}=Bt,Ut=Xt({authToken:c,embedMode:o}),H=Ae??Ut,P=t=>`${t.initiativeId}:${t.workstreamId}`,ee=w==="workstream",Ge=l.useMemo(()=>G?{duration:.01}:b.surfaceSwitch,[G]),U=l.useMemo(()=>{if(T)return ue.filter(i=>i.queueState!==m.RUNNING);const t=ue.filter(i=>i.queueState!==m.RUNNING);return t.length>0?t:ue},[T,ue]),rt=l.useMemo(()=>U.length===0?"empty":U.some(t=>t.queueState!==m.RUNNING&&t.queueState!==m.BLOCKED)?m.QUEUED:U.some(t=>t.queueState===m.BLOCKED)?m.BLOCKED:U.some(t=>t.queueState===m.RUNNING)?m.RUNNING:m.QUEUED,[U]),at=l.useMemo(()=>{if(!T)return De;const t=[];for(const i of De){const r=i.items.filter(n=>n.queueState!==m.RUNNING);r.length!==0&&t.push({...i,items:r,queueState:rs(r)})}return t},[T,De]),we=l.useMemo(()=>[...at].sort((t,i)=>{const r=Ue(t.queueState)-Ue(i.queueState);return r!==0?r:t.initiativeTitle.localeCompare(i.initiativeTitle)}),[at]),ot=l.useMemo(()=>T?_e.filter(t=>t.item.queueState!==m.RUNNING):_e,[T,_e]),ye=l.useMemo(()=>[...ot].sort((t,i)=>{const r=Ue(t.queueState)-Ue(i.queueState);if(r!==0)return r;const n=t.initiativeTitle.localeCompare(i.initiativeTitle);if(n!==0)return n;const u=t.workstreamTitle.localeCompare(i.workstreamTitle);return u!==0?u:t.milestoneTitle.localeCompare(i.milestoneTitle)}),[ot]),Ke=l.useMemo(()=>d?we.slice(0,5):we,[d,we]),Qe=l.useMemo(()=>d?ye.slice(0,5):ye,[d,ye]),lt=l.useMemo(()=>w==="initiative"?we.length:w==="milestone"?ye.length:U.length,[U.length,we.length,ye.length,w]),At=[{value:"initiative",label:"Initiative"},{value:"workstream",label:"Workstream"},{value:"milestone",label:"Milestone"}],C=l.useMemo(()=>ee?d?U.slice(0,5):U:[],[d,ee,U]),zt=l.useMemo(()=>C.filter(t=>V.has(P(t))),[V,C]),[me,ct]=l.useState([]),We=l.useRef([]),dt=l.useMemo(()=>{const t=new Map;for(const i of C)t.set(P(i),i);return t},[C]),R=l.useMemo(()=>C.map(P),[C]),Dt=l.useMemo(()=>R.join("|"),[R]);l.useEffect(()=>{ct(t=>{if(d)return[];const i=[],r=new Set(R);for(const n of t)r.has(n)&&i.push(n);for(const n of R)i.includes(n)||i.push(n);return i})},[d,Dt]),l.useEffect(()=>{We.current=me},[me]),l.useEffect(()=>{Te&&(R.includes(Te)||de(null))},[Te,R]),l.useEffect(()=>{ce(t=>{if(t.size===0)return t;const i=new Set(C.map(P)),r=new Set;for(const n of t)i.has(n)&&r.add(n);return r.size===t.size?t:r})},[C]),l.useEffect(()=>{if(!x)return;C.some(i=>P(i)===x)||Y(null)},[x,C]),l.useEffect(()=>{if(O.length===0){Me(!1);return}Me(!1)},[O]),l.useEffect(()=>{Q&&!d&&V.size>0&&ge(!1)},[d,V.size,Q]),l.useEffect(()=>{if(!be)return;const t=r=>{var u;const n=r.target;n&&((u=Oe.current)!=null&&u.contains(n)||ge(!1))},i=r=>{r.key==="Escape"&&ge(!1)};return document.addEventListener("mousedown",t),document.addEventListener("touchstart",t),document.addEventListener("keydown",i),()=>{document.removeEventListener("mousedown",t),document.removeEventListener("touchstart",t),document.removeEventListener("keydown",i)}},[be]),l.useEffect(()=>{if(!ze)return;const t=et.current,i=tt.current;if(!t||!i)return;const r=new IntersectionObserver(n=>{n.some(u=>u.isIntersecting)&&(M||Re||nt().catch(()=>null))},{root:t,rootMargin:"220px 0px 220px 0px",threshold:0});return r.observe(i),()=>r.disconnect()},[nt,ze,Re,M]);const ut=async t=>{const i=P(t),r=I(t.workstreamTitle);try{await H.remove({initiativeId:t.initiativeId,workstreamId:t.workstreamId}),ce(n=>{if(!n.has(i))return n;const u=new Set(n);return u.delete(i),u}),de(n=>n===i?null:n),y(`Removed ${r} from queue.`)}catch(n){const u=n instanceof Error?n.message:"";y(pe(u,"Failed to remove from queue"))}},_t=(t,i,r)=>{const n=d?R:me.length>0?me:R;ce(u=>{const h=new Set(u),E=Te;if(r&&E&&n.includes(E)){const g=n.indexOf(t),Z=n.indexOf(E);if(g>=0&&Z>=0){const[Fe,Pe]=g<Z?[g,Z]:[Z,g];for(const Ne of n.slice(Fe,Pe+1))i?h.add(Ne):h.delete(Ne)}else i?h.add(t):h.delete(t)}else i?h.add(t):h.delete(t);return h}),de(t)},Gt=()=>{ce(new Set(R)),de(R.length>0?R[R.length-1]:null)},Kt=()=>{ce(new Set),de(null)},Ve=async t=>{if(V.size===0){y("Select one or more queue items first.");return}const i=C.map(r=>({key:P(r),item:r})).filter(r=>V.has(r.key));if(i.length===0){y("Selected queue items are no longer visible.");return}X(`bulk:${t}`),y(null);try{const r=i.map(({item:g})=>({initiativeId:g.initiativeId,workstreamId:g.workstreamId})),n=await H.bulk({action:t,items:r}),u=typeof(n==null?void 0:n.updated)=="number"?n.updated??0:0,h=typeof(n==null?void 0:n.failed)=="number"?n.failed??0:0,E=Array.isArray(n==null?void 0:n.errors)?n.errors.filter(g=>typeof g=="string").map(g=>g.trim()).filter(Boolean):[],v=t==="remove"?"removed":t==="move_top"?"moved to top":"moved to bottom";u===0&&h>0&&E.length>0?y(pe(E[0],`${h} queue action${h===1?"":"s"} failed.`)):y(h>0?`${u} item${u===1?"":"s"} ${v}; ${h} failed.`:`${u} item${u===1?"":"s"} ${v}.`),ce(new Set),de(null)}catch(r){const n=r instanceof Error?r.message:"";y(pe(n,"Bulk queue action failed"))}finally{X(null)}},Qt=async()=>{const t=We.current.map(i=>dt.get(i)).filter(Boolean).map(i=>({initiativeId:i.initiativeId,workstreamId:i.workstreamId}));t.length!==0&&await H.reorder({order:t})},te=async(t,i,r)=>{y(null),le(null),D==null||D(null),X(t);try{const n=await i();y(typeof r=="function"?r(n):r)}catch(n){if(n instanceof ts)le(n),D==null||D(n);else{const u=n instanceof Error?n.message:"";y(pe(u,"Action failed"))}}finally{X(null)}},Le=async t=>W?await W(t):await Pt({initiativeId:t.initiativeId,workstreamId:t.workstreamId,agentId:t.runnerAgentId}),Be=j?"upgrade":Ee?"error":B?"notice":null,mt=Ee?ms(Ee):null,ve=O.length>0?xs(O[0]):null,Wt=Be!==null,Vt=O.length>0&&ve!==null&&!Et&&x===null&&!be,se=zt.length,Ht=l.useMemo(()=>w==="initiative"?Ke.length>0:w==="milestone"?Qe.length>0:C.length>0,[Ke.length,C.length,Qe.length,w]),xt=Q&&ee&&!d&&se>0,He=l.useMemo(()=>{if(!T)return 0;let t=0;for(const i of ue)i.queueState===m.RUNNING&&t++;return t},[T,ue]),Zt=w==="initiative"?"No initiatives in the queue right now.":w==="milestone"?"No milestone slices in the queue right now.":He>0?`All queued work is in progress (${He} running).`:O.length>0&&ve?"Queue signal is delayed right now.":"No queued workstreams right now.",pt=e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:Gt,className:"control-pill h-8 px-2.5 text-caption font-semibold",children:"Select all"}),e.jsx("button",{type:"button",onClick:Kt,disabled:V.size===0,className:"control-pill h-8 px-2.5 text-caption font-semibold disabled:opacity-45",children:"Clear"}),e.jsx("button",{type:"button",disabled:se===0||F==="bulk:move_top",onClick:()=>void Ve("move_top"),className:"control-pill h-8 px-2.5 text-caption font-semibold disabled:opacity-45",children:"Move top"}),e.jsx("button",{type:"button",disabled:se===0||F==="bulk:move_bottom",onClick:()=>void Ve("move_bottom"),className:"control-pill h-8 px-2.5 text-caption font-semibold disabled:opacity-45",children:"Move bottom"}),e.jsx("button",{type:"button",disabled:se===0||F==="bulk:remove",onClick:()=>void Ve("remove"),className:"control-pill h-8 px-2.5 text-caption font-semibold disabled:opacity-45",children:"Remove"})]});return e.jsxs(Yt,{surface:Ce==="card",className:`flex h-full min-h-0 flex-col overflow-hidden ${q?"":"card-enter"} ${Ce==="flat"?"!rounded-none !border-none !bg-transparent !shadow-none":""} ${S??""}`,children:[f?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:p}),e.jsx("span",{className:"chip inline-flex min-w-[52px] justify-center text-micro tabular-nums",children:M?e.jsx("span",{"aria-hidden":!0,className:"h-2.5 w-5 rounded bg-white/15 animate-pulse"}):lt}),e.jsx("span",{className:ie("inline-flex min-w-[92px] justify-end text-micro text-muted transition-opacity",st&&!M?"opacity-100":"opacity-0"),"aria-live":"polite",children:"refreshing…"})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"inline-flex items-center rounded-xl border border-white/[0.1] bg-white/[0.03] p-1",role:"tablist","aria-label":"Next Up scope",children:At.map(t=>{const i=w===t.value;return e.jsxs(z.button,{type:"button",role:"tab","aria-selected":i,onClick:()=>J(t.value),...b.segmentedTap,className:ie("relative h-7 rounded-lg px-2.5 text-caption font-semibold transition-colors",i?"text-[#E8FFD0]":"text-secondary hover:text-white"),title:`Show ${t.label.toLowerCase()} queue`,children:[i?e.jsx(z.span,{layoutId:"next-up-scope-indicator",transition:G?{duration:.01}:b.railMorphSpring,className:"pointer-events-none absolute inset-0 rounded-lg border border-[#BFFF00]/35 bg-[#BFFF00]/16","aria-hidden":!0}):null,e.jsx("span",{className:"relative z-[1]",children:t.label})]},t.value)})}),K?e.jsx("button",{type:"button",onClick:()=>ae(!d),className:"control-pill h-8 flex-shrink-0 whitespace-nowrap px-3 text-caption font-semibold",title:d?"Switch to expanded cards":"Switch to compact list","aria-label":d?"Expand Next Up queue":"Compact Next Up queue",children:d?"Expand":"Compact"}):null]})]}):null,Wt&&e.jsx("div",{className:"px-3 pt-2",children:e.jsx(ke,{initial:!1,mode:"wait",children:Be==="upgrade"&&j?e.jsx(z.div,{initial:{opacity:0,y:-4,scale:.99},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-4,scale:.99},transition:Ge,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:[ft(j.currentPlan)," →"," ",ft(j.requiredPlan)]})]}),e.jsx("div",{className:"mt-1 line-clamp-2 text-caption leading-snug text-amber-50/90",title:j.message,children:j.message}),B?e.jsx("div",{className:"mt-1 text-micro text-rose-50/85",children:B}):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 as({actions:j.actions,requiredPlan:j.requiredPlan}).catch(t=>y(pe(t instanceof Error?t.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 os({actions:j.actions}).catch(t=>y(pe(t instanceof Error?t.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"}),L&&e.jsx("button",{type:"button",onClick:L,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"})]}),(ht=j.actions)!=null&&ht.pricing?e.jsx("a",{href:j.actions.pricing,target:"_blank",rel:"noopener noreferrer",className:"text-micro text-secondary underline decoration-white/20 hover:text-primary",children:"View pricing"}):null]})]})},"upgrade"):Be==="error"&&mt?e.jsx(z.div,{initial:{opacity:0,y:-4},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},transition:Ge,className:"rounded-xl border border-red-400/25 bg-red-500/[0.08] px-3 py-2 text-caption text-red-100",children:mt},"error"):Be==="notice"&&B?e.jsx(z.div,{initial:{opacity:0,y:-4},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},transition:Ge,className:"rounded-xl border border-white/[0.1] bg-white/[0.03] px-3 py-2 text-caption text-primary",children:B},"notice"):null})}),e.jsxs("div",{ref:et,className:`flex-1 space-y-2.5 overflow-y-auto overscroll-y-contain scroll-smooth px-3 pb-3 ${f?"pt-1":"pt-2.5"}`,children:[!M&&lt>0?e.jsxs("div",{className:"flex flex-col gap-2.5 px-0.5 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-micro uppercase tracking-[0.08em] text-muted",children:w==="initiative"?"Initiatives":w==="milestone"?"Milestone slices":rt===m.BLOCKED?"Needs attention":rt===m.RUNNING?"Running now":"Queue"}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-1.5",children:[se>0?e.jsxs("span",{className:"chip text-micro",children:[se," selected"]}):null,e.jsx("span",{className:ie("inline-flex min-w-[92px] text-micro text-muted transition-opacity",st&&!M?"opacity-100":"opacity-0"),"aria-live":"polite",children:"refreshing…"}),Q&&ee&&!d&&se===0?e.jsx("span",{className:"text-micro text-muted",children:"Shift+select to pick ranges."}):null]})]}),e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-1.5 sm:justify-end",children:[K?e.jsx("button",{type:"button",onClick:()=>ae(!d),className:"control-pill h-8 px-2.5 text-caption font-semibold",title:d?"Switch to expanded cards":"Switch to compact list","aria-label":d?"Expand Next Up queue":"Compact Next Up queue",children:d?"Expand":"Compact"}):null,xt?e.jsx("div",{className:"flex flex-wrap justify-end gap-1.5",children:pt}):null,!xt&&Ie&&ee?e.jsxs("div",{ref:Oe,className:"relative",children:[e.jsxs("button",{type:"button",onClick:()=>ge(t=>!t),className:"control-pill h-8 px-2.5 text-caption font-semibold","aria-haspopup":"menu","aria-expanded":be,title:"Queue settings",children:[e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"opacity-85","aria-hidden":!0,children:[e.jsx("path",{d:"M4 6h16"}),e.jsx("path",{d:"M7 12h10"}),e.jsx("path",{d:"M10 18h4"})]}),e.jsx("span",{children:"Queue"})]}),be?e.jsx("div",{className:"surface-tier-2 absolute right-0 top-[calc(100%+8px)] z-[280] w-[320px] max-w-[86vw] rounded-xl p-3 shadow-[0_18px_42px_rgba(0,0,0,0.46)] backdrop-blur-xl",children:e.jsxs("div",{className:"space-y-2.5",children:[Q&&!d?e.jsxs("div",{children:[e.jsx("p",{className:"section-kicker",children:"Bulk actions"}),e.jsx("div",{className:"mt-1.5 flex flex-wrap items-center gap-1.5",children:pt})]}):null,L?e.jsx("button",{type:"button",onClick:()=>{ge(!1),L()},className:"control-pill h-7 px-2.5 text-micro font-semibold",children:"Open settings"}):null]})}):null]}):null]})]}):null,M?e.jsx(ps,{compact:d}):null,!M&&!Ht&&!Ee&&e.jsx(Ot,{icon:"queue",headline:Zt,description:He>0?"Check the In Progress tab to see active work.":ve??"Create an initiative or add workstreams to populate the queue.",primaryAction:O.length>0&&ve?{label:"Retry now",onClick:()=>{Me(!1),Ft()}}:void 0}),!M&&w==="initiative"?e.jsx(ke,{initial:!1,children:Ke.map((t,i)=>{const r=t.items.find(v=>v.queueState!==m.RUNNING&&v.queueState!=="completed")??t.items[0]??null,n=Se(t.initiativeTitle,t.initiativeId,"Initiative"),u=wt(t.queueState),h=yt(t.queueState),E=t.items.reduce((v,g)=>v+(g.sliceTaskCount??0),0);return e.jsxs(z.article,{layout:!0,initial:{opacity:0,y:8,scale:.99},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-4,scale:.99},transition:{duration:G?.01:b.surfaceSwitch.duration,delay:G?0:Math.min(i,b.listStaggerMaxItems)*b.listStaggerStep,ease:b.surfaceSwitch.ease},className:"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",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Initiative"}),e.jsx("p",{className:"mt-0.5 truncate text-body font-semibold text-white",title:n,children:n})]}),e.jsx("span",{className:ie("inline-flex items-center rounded-full border px-2 py-0.5 text-[10px] font-semibold uppercase tracking-[0.08em]",h),children:u})]}),e.jsxs("p",{className:"mt-1 text-micro text-secondary",children:[t.workstreamCount," workstreams · ",E," tasks"]}),e.jsx("div",{className:"mt-2 space-y-1",children:t.items.slice(0,3).map((v,g)=>e.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-lg border border-white/[0.06] bg-black/[0.18] px-2.5 py-1.5 text-caption",children:[e.jsx("span",{className:"truncate text-white/84",children:I(v.workstreamTitle)}),e.jsxs("span",{className:"text-micro text-secondary",children:[v.sliceTaskCount??0," tasks"]})]},`${v.workstreamId}:${g}`))}),e.jsxs("div",{className:"mt-2.5 flex items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>$==null?void 0:$(t.initiativeId,t.initiativeTitle),className:"control-pill h-7 px-2.5 text-micro font-semibold",children:"Open"}),e.jsx("button",{type:"button",disabled:!r||F===`initiative:${t.initiativeId}`,onClick:()=>{r&&te(`initiative:${t.initiativeId}`,()=>Le(r),`Dispatched ${I(r.workstreamTitle)}.`)},className:"control-pill h-7 px-2.5 text-micro font-semibold disabled:opacity-45",children:"Dispatch"})]})]},`initiative-group:${t.initiativeId}`)})}):null,!M&&w==="milestone"?e.jsx(ke,{initial:!1,children:Qe.map((t,i)=>{const r=t.item,n=`milestone:${t.workstreamId}:${t.milestoneId??"none"}`;return e.jsxs(z.article,{layout:!0,initial:{opacity:0,y:8,scale:.99},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-4,scale:.99},transition:{duration:G?.01:b.surfaceSwitch.duration,delay:G?0:Math.min(i,b.listStaggerMaxItems)*b.listStaggerStep,ease:b.surfaceSwitch.ease},className:"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",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:[I(t.initiativeTitle)," · ",I(t.workstreamTitle)]}),e.jsx("p",{className:"mt-0.5 truncate text-body font-semibold text-white",title:t.milestoneTitle,children:I(t.milestoneTitle)})]}),e.jsx("span",{className:ie("inline-flex items-center rounded-full border px-2 py-0.5 text-[10px] font-semibold uppercase tracking-[0.08em]",yt(t.queueState)),children:wt(t.queueState)})]}),e.jsxs("p",{className:"mt-1 text-micro text-secondary",children:[t.taskCount," tasks in slice"]}),e.jsxs("div",{className:"mt-2.5 flex items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>$==null?void 0:$(t.initiativeId,t.initiativeTitle),className:"control-pill h-7 px-2.5 text-micro font-semibold",children:"Open"}),e.jsx("button",{type:"button",disabled:F===n||t.queueState===m.RUNNING,onClick:()=>void te(n,()=>Le(r),u=>Xe(r,u)),className:"control-pill h-7 px-2.5 text-micro font-semibold disabled:opacity-45",children:t.queueState===m.RUNNING?"Running":"Start"})]})]},`${t.initiativeId}:${t.workstreamId}:${t.milestoneId??"none"}`)})}):null,!M&&ee&&d?e.jsx(ke,{initial:!1,children:C.map((t,i)=>{const r=P(t),n=F===r,u=t.queueState===m.RUNNING,h=t.nextTaskDueAt?Nt(t.nextTaskDueAt):null,E=Se(t.initiativeTitle,t.initiativeId,"Initiative"),v=Se(t.workstreamTitle,t.workstreamId,"Workstream"),g=qt(t),Z=t.nextTaskTitle?I(t.nextTaskTitle):null,Fe=t.blockReason?I(t.blockReason):null,Pe=$t(t),Ne=Tt(t);return e.jsxs(z.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:G?.01:b.surfaceSwitch.duration,delay:G?0:Math.min(i,b.listStaggerMaxItems)*b.listStaggerStep,ease:b.surfaceSwitch.ease},className:"group relative overflow-visible rounded-2xl border border-white/[0.08] bg-white/[0.02] px-2.5 py-2 cursor-pointer transition-colors hover:border-white/[0.14]",onClick:()=>_==null?void 0:_(t),role:"button",tabIndex:0,onKeyDown:N=>{(N.key==="Enter"||N.key===" ")&&(N.preventDefault(),_==null||_(t))},children:[e.jsx("div",{className:`pointer-events-none absolute inset-x-2.5 top-0 h-px bg-gradient-to-r ${St(t.queueState)}`,"aria-hidden":!0}),e.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[e.jsx(kt,{name:Pe,hint:Mt(t,Pe),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(je,{type:"initiative",size:11,className:"flex-shrink-0 opacity-85"}),e.jsx("button",{type:"button",onClick:()=>$==null?void 0:$(t.initiativeId,t.initiativeTitle),className:"block min-w-0 flex-1 truncate text-left text-micro uppercase tracking-[0.08em] text-muted transition-colors hover:text-white/72",title:E,children:E}),g?e.jsx("span",{className:ie("inline-flex flex-shrink-0 items-center rounded-full border px-2 py-0.5 text-[9px] font-semibold uppercase tracking-[0.08em]",g.toneClass),title:g.longLabel,children:g.shortLabel}):null]}),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:v,children:[e.jsx(je,{type:"workstream",size:12,className:"flex-shrink-0 opacity-95"}),e.jsx("span",{className:"line-clamp-2",children:v})]}),Z?e.jsxs("p",{className:"mt-0.5 line-clamp-2 text-micro leading-snug text-secondary",title:`${Ze(t.queueState)}: ${Z}${h?` · ${h}`:""}`,children:[Ze(t.queueState),": ",Z,h?` · ${h}`:""]}):e.jsx("p",{className:"mt-0.5 line-clamp-2 text-micro leading-snug text-secondary",title:Je(t),children:Je(t)}),Ne?e.jsxs("p",{className:"mt-0.5 text-micro text-muted",children:["Runner ",Ne]}):null,e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-1.5",children:[(()=>{const N=t.objectiveScore??t.compositeScore??null;if(N==null)return null;const xe=N>=80?"S":N>=60?"A":"B",ne=xe==="S"?"border-[#BFFF00]/30 bg-[#BFFF00]/[0.12] text-[#d8ffa1]":xe==="A"?"border-[#14B8A6]/30 bg-[#14B8A6]/[0.12] text-[#87FFE9]":"border-white/[0.12] bg-white/[0.05] text-white/60";return e.jsxs("span",{className:`chip text-[9px] font-semibold ${ne}`,children:[xe,"-tier"]})})(),(()=>{const N=t.expectedValueUsd,xe=t.sliceTaskCount??0,ne=[];return xe>0&&ne.push(`${xe} tasks`),typeof N=="number"&&N>0&&ne.push(`$${N.toFixed(2)}`),h&&ne.push(h),ne.length===0?null:e.jsx("span",{className:"text-micro text-muted",children:ne.join(" · ")})})()]})]})]}),(t.sliceTaskCount??0)>0&&e.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 h-[2px] rounded-b-2xl overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full",style:{width:`${Math.max(t.queueState===m.COMPLETED?100:t.queueState===m.RUNNING?50:15,4)}%`,background:`linear-gradient(90deg, ${bt.lime}, ${bt.teal})`,opacity:.6}})}),Fe&&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: ",Fe]}),e.jsxs("div",{className:"mt-1.5 flex items-center gap-1.5",onClick:N=>N.stopPropagation(),children:[e.jsx("button",{type:"button",disabled:n||u,onClick:()=>void te(r,()=>Le(t),N=>Xe(t,N)),className:"control-pill flex h-7 items-center justify-center px-2.5 text-micro font-semibold disabled:opacity-40",title:u?"Already running":"Start now",children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(It,{className:"h-3 w-3 opacity-85"}),e.jsx("span",{children:u?"Running":"Start"})]})}),e.jsxs("div",{className:"relative ml-auto",children:[e.jsx("button",{type:"button",disabled:n,onClick:()=>Y(N=>N===r?null:r),className:"control-pill flex h-7 items-center justify-center px-2.5 text-micro font-semibold disabled:opacity-40",title:"Queue actions",children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Rt,{className:"h-3 w-3 opacity-85"}),e.jsx("span",{children:"More"})]})}),x===r&&e.jsxs("div",{className:"absolute right-0 top-[calc(100%+6px)] z-[320] min-w-[178px] rounded-xl border border-white/[0.1] bg-[#080d14]/95 p-1.5 shadow-[0_16px_36px_rgba(0,0,0,0.42)] backdrop-blur",children:[e.jsx("button",{type:"button",onClick:()=>{Y(null),te(`${r}:top`,()=>H.move({initiativeId:t.initiativeId,workstreamId:t.workstreamId,placement:"top"}),`Moved ${v} to top of queue.`)},className:"flex h-8 w-full items-center rounded-md px-2.5 text-left text-caption text-primary transition-colors hover:bg-white/[0.08]",children:"Move to top"}),e.jsx("button",{type:"button",onClick:()=>{Y(null),te(`${r}:bottom`,()=>H.move({initiativeId:t.initiativeId,workstreamId:t.workstreamId,placement:"bottom"}),`Moved ${v} to bottom of queue.`)},className:"flex h-8 w-full items-center rounded-md px-2.5 text-left text-caption text-primary transition-colors hover:bg-white/[0.08]",children:"Move to bottom"}),e.jsx("button",{type:"button",onClick:()=>{Y(null),te(`${r}:auto`,()=>it({initiativeId:t.initiativeId,workstreamId:t.workstreamId,agentId:t.runnerAgentId,scope:"initiative"}),`Auto enabled for ${E}.`)},className:"flex h-8 w-full items-center rounded-md px-2.5 text-left text-caption text-primary transition-colors hover:bg-white/[0.08]",children:"Auto on"}),e.jsx("button",{type:"button",disabled:H.isRemoving,onClick:()=>{Y(null),ut(t)},className:"mt-1 flex h-8 w-full items-center rounded-md px-2.5 text-left text-caption text-red-100 transition-colors hover:bg-red-500/[0.12] disabled:opacity-45",children:"Remove from queue"})]})]})]})]},r)})}):!M&&ee?e.jsx(ss,{axis:"y",values:me,onReorder:t=>{We.current=t,ct(t)},className:"space-y-2.5",children:me.map(t=>dt.get(t)).filter(Boolean).map((t,i)=>e.jsx(fs,{item:t,index:i,actionKey:F,setNotice:y,setUpgradeGate:le,onUpgradeGate:D,onOpenInitiative:$,onOpenSliceDetail:_,selected:V.has(P(t)),selectionEnabled:Q,onToggleSelection:_t,menuKey:x,setMenuKey:Y,onPlayWorkstream:Le,startWorkstreamAutoContinue:it,triagePlacement:oe,onPauseWorkstream:(r,n)=>H.stopTriage({initiativeId:r.initiativeId,workstreamId:r.workstreamId,placement:n,resetToTodo:!1}),onMoveWorkstream:(r,n)=>H.move({initiativeId:r.initiativeId,workstreamId:r.workstreamId,placement:n}),onCommitReorder:()=>void Qt().catch(()=>null),onDismiss:ut,runAction:te},P(t)))}):null,(ze||Re)&&e.jsx("div",{ref:tt,className:"flex h-10 items-center justify-center",children:e.jsx("span",{className:"text-micro text-muted",children:Re?"Loading more queue items…":"Scroll for more"})})]}),e.jsx("div",{className:"pointer-events-none absolute bottom-3 right-3 z-[250]",children:e.jsx(cs,{open:Vt,tone:"warning",title:"Limited signal",message:ve,autoDismissMs:6e3,onDismiss:()=>Me(!0)})})]})}function fs({item:s,index:a,actionKey:c,setNotice:o,setUpgradeGate:p,onUpgradeGate:f,onOpenInitiative:k,onOpenSliceDetail:S,selected:q,selectionEnabled:K,onToggleSelection:he,menuKey:$,setMenuKey:L,onPlayWorkstream:D,startWorkstreamAutoContinue:_,triagePlacement:Q,onPauseWorkstream:Ce,onMoveWorkstream:Ie,onCommitReorder:qe,onDismiss:Ae,runAction:W}){const $e=ns(),T=jt(),[re,fe]=l.useState(!1),d=`${s.initiativeId}:${s.workstreamId}`,ae=c===d,B=s.queueState===m.RUNNING,y=s.nextTaskDueAt?Nt(s.nextTaskDueAt):null,w=Se(s.initiativeTitle,s.initiativeId,"Initiative"),J=Se(s.workstreamTitle,s.workstreamId,"Workstream"),oe=qt(s),j=s.nextTaskTitle?I(s.nextTaskTitle):null,le=s.blockReason?I(s.blockReason):null,F=$t(s),X=Tt(s);return e.jsx(is,{value:d,id:d,dragListener:!1,dragControls:$e,onDragStart:()=>fe(!0),onDragEnd:()=>{fe(!1),qe()},whileDrag:{scale:1.02,boxShadow:"0 20px 48px rgba(0,0,0,0.5), 0 0 0 1px rgba(191,255,0,0.15)",zIndex:50,cursor:"grabbing"},className:"relative",children:e.jsxs(z.article,{layout:!0,initial:{opacity:0,y:12,scale:.97},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-8,scale:.98},transition:{duration:T?.01:b.surfaceSwitch.duration,ease:b.surfaceSwitch.ease,delay:T?0:Math.min(a,b.listStaggerMaxItems)*b.listStaggerStep,opacity:{duration:T?.01:b.surfaceSwitch.duration,ease:b.surfaceSwitch.ease}},className:"group relative overflow-visible rounded-2xl border border-white/[0.08] bg-white/[0.02] px-3 py-3 cursor-pointer transition-colors hover:border-white/[0.14]",onClick:()=>S==null?void 0:S(s),role:"button",tabIndex:0,onKeyDown:x=>{(x.key==="Enter"||x.key===" ")&&(x.preventDefault(),S==null||S(s))},children:[e.jsx("div",{className:`pointer-events-none absolute inset-x-3 top-0 h-px bg-gradient-to-r ${St(s.queueState)}`,"aria-hidden":!0}),e.jsx("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.jsxs("div",{className:"relative h-8 w-8 flex-shrink-0",children:[e.jsx("div",{className:`absolute inset-0 transition-[opacity,transform] duration-200 ease-out ${K?q?"opacity-0 scale-90":"opacity-100 scale-100 group-hover:opacity-0 group-hover:scale-90 group-focus-within:opacity-0 group-focus-within:scale-90":"opacity-100 scale-100"}`,children:e.jsx(kt,{name:F,hint:Mt(s,F),size:"sm"})}),K?e.jsx("button",{type:"button",role:"checkbox","aria-checked":q,"aria-label":"Select queue row",title:q?"Selected (Shift+click for range)":"Select (Shift+click for range)",onClick:x=>{x.stopPropagation(),he(d,!q,x.shiftKey)},onMouseDown:x=>x.stopPropagation(),onKeyDown:x=>x.stopPropagation(),className:`absolute inset-0 flex items-center justify-center rounded-full border transition-[opacity,transform,background-color,border-color,color] duration-200 ease-out ${q?"opacity-100 scale-100 border-[#BFFF00]/40 bg-[#BFFF00]/18 text-[#E1FFB2]":"opacity-0 scale-90 border-white/[0.24] bg-black/55 text-white/78 group-hover:opacity-100 group-hover:scale-100 group-focus-within:opacity-100 group-focus-within:scale-100 hover:bg-black/62"}`,children:e.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center rounded-full border border-current/45 bg-black/30",children:q?e.jsx("svg",{viewBox:"0 0 16 16",className:"h-2.5 w-2.5",fill:"none","aria-hidden":!0,children:e.jsx("path",{d:"M3.2 8.3 6.2 11l6.6-6.1",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}):null})}):null]}),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(je,{type:"initiative",size:11,className:"flex-shrink-0 opacity-85"}),e.jsx("button",{type:"button",onClick:()=>k==null?void 0:k(s.initiativeId,s.initiativeTitle),className:"block min-w-0 flex-1 truncate text-left text-micro uppercase tracking-[0.08em] text-muted transition-colors hover:text-white/72",title:w,children:w}),oe?e.jsx("span",{className:ie("inline-flex flex-shrink-0 items-center rounded-full border px-2 py-0.5 text-[9px] font-semibold uppercase tracking-[0.08em]",oe.toneClass),title:oe.longLabel,children:oe.shortLabel}):null]}),e.jsxs("div",{className:"mt-0.5 flex min-w-0 items-start gap-1.5",children:[e.jsx(je,{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:J,children:J})]}),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:[F,X?` · ${X}`:""]})]})]})]})}),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:j?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(je,{type:"task",size:10,className:"flex-shrink-0 opacity-80"}),e.jsx("span",{children:Ze(s.queueState)}),y?e.jsxs("span",{className:"truncate text-micro normal-case tracking-normal text-muted",children:["· ",y]}):null]}),e.jsx("p",{className:"line-clamp-2 break-words text-caption leading-snug text-white/84",title:j,children:j})]}):e.jsx("span",{className:"text-secondary",children:Je(s)})}),le&&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: ",le]}),e.jsxs("div",{className:"mt-2 flex items-center gap-1.5",onClick:x=>x.stopPropagation(),children:[e.jsx("button",{type:"button",disabled:ae||B,onClick:()=>void W(d,()=>D(s),x=>Xe(s,x)),className:"control-pill flex h-7 items-center justify-center px-2.5 text-micro font-semibold disabled:opacity-40",title:B?"Already running":"Start this workstream now",children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(It,{className:"h-3 w-3 opacity-85"}),e.jsx("span",{children:B?"Running":"Start"})]})}),e.jsxs("button",{type:"button",onPointerDown:x=>$e.start(x),"aria-label":"Drag to reorder",title:re?"Reordering":"Drag to reorder",className:`control-pill flex h-7 items-center justify-center gap-1 px-2 text-micro font-semibold transition-colors ${re?"border-[#BFFF00]/35 bg-[#BFFF00]/14 text-[#E1FFB2] cursor-grabbing":"cursor-grab hover:bg-white/[0.08] hover:text-bright"}`,children:[re?e.jsx(us,{className:"h-3.5 w-3.5 opacity-90"}):e.jsx(ds,{className:"h-3.5 w-3.5 opacity-90"}),e.jsx("span",{children:re?"Reordering":"Drag"})]}),e.jsxs("div",{className:"relative ml-auto",children:[e.jsx("button",{type:"button",disabled:ae,onClick:()=>L(x=>x===d?null:d),className:"control-pill flex h-7 items-center justify-center px-2.5 text-micro font-semibold disabled:opacity-40",title:"Queue actions",children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Rt,{className:"h-3 w-3 opacity-85"}),e.jsx("span",{children:"More"})]})}),$===d&&e.jsxs("div",{className:"absolute right-0 top-[calc(100%+6px)] z-[320] min-w-[198px] rounded-xl border border-white/[0.1] bg-[#080d14]/95 p-1.5 shadow-[0_16px_36px_rgba(0,0,0,0.42)] backdrop-blur",children:[e.jsx("button",{type:"button",onClick:()=>{L(null),W(`${d}:top`,()=>Ie(s,"top"),`Moved ${J} to top of queue.`)},className:"flex h-8 w-full items-center rounded-md px-2.5 text-left text-caption text-primary transition-colors hover:bg-white/[0.08]",children:"Move to top"}),e.jsx("button",{type:"button",onClick:()=>{L(null),W(`${d}:bottom`,()=>Ie(s,"bottom"),`Moved ${J} to bottom of queue.`)},className:"flex h-8 w-full items-center rounded-md px-2.5 text-left text-caption text-primary transition-colors hover:bg-white/[0.08]",children:"Move to bottom"}),e.jsx("button",{type:"button",onClick:()=>{L(null),W(`${d}:auto`,()=>_({initiativeId:s.initiativeId,workstreamId:s.workstreamId,agentId:s.runnerAgentId,scope:"initiative"}),`Auto enabled for ${w}.`)},className:"flex h-8 w-full items-center rounded-md px-2.5 text-left text-caption text-primary transition-colors hover:bg-white/[0.08]",children:"Auto on"}),B?e.jsx("button",{type:"button",onClick:()=>{L(null),W(`${d}:pause`,()=>Ce(s,Q),`Paused ${J}.`)},className:"mt-1 flex h-8 w-full items-center rounded-md px-2.5 text-left text-caption text-primary transition-colors hover:bg-white/[0.08]",children:"Pause run"}):null,e.jsx("button",{type:"button",disabled:ae||B,onClick:()=>{L(null),Ae(s)},className:"mt-1 flex h-8 w-full items-center rounded-md px-2.5 text-left text-caption text-red-100 transition-colors hover:bg-red-500/[0.12] disabled:opacity-45",children:"Remove from queue"})]})]})]})]})})}const Ns=Object.freeze(Object.defineProperty({__proto__:null,NextUpPanel:hs},Symbol.toStringTag,{value:"Module"}));export{cs as I,hs as N,Ns as a,as as o};
1
+ import{r as l,j as e}from"./Dj2k1r16.js";import{G as Jt,u as Xt,K as b,P as Yt,B as ie,H as ft,T as Ot,C as I,v as Nt,A as kt,E as je,e as bt,h as Ye,D as gt,F as es,U as ts}from"./D2Kqcmv9.js";import{S as A}from"./BcJmNILk.js";import{A as ke,m as z,u as jt,R as ss,b as ns,a as is}from"./eeHXe_OQ.js";import{Q as m,d as rs,q as Ue,a as wt,b as yt,c as St,e as Ze}from"./a6qcPiWt.js";async function Ct(s,a){var f;const o=await(await fetch(s,a)).json().catch(()=>null),p=((f=o==null?void 0:o.data)==null?void 0:f.url)??(o==null?void 0:o.url)??null;if(typeof p=="string"&&p.trim())return p.trim();throw new Error((o==null?void 0:o.error)??"Billing link unavailable")}async function as(s){var p;const a=((p=s==null?void 0:s.actions)==null?void 0:p.checkout)??"/orgx/api/billing/checkout",c=((s==null?void 0:s.requiredPlan)??"starter").trim().toLowerCase()||"starter",o=await Ct(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({planId:c})});window.open(o,"_blank","noopener,noreferrer")}async function os(s){var o;const a=((o=s==null?void 0:s.actions)==null?void 0:o.portal)??"/orgx/api/billing/portal",c=await Ct(a,{method:"POST"});window.open(c,"_blank","noopener,noreferrer")}function ls(s){return s==="success"?"border-emerald-400/30 bg-[#0A1210]/95 text-emerald-100":s==="warning"?"border-amber-300/30 bg-[#12100A]/95 text-amber-100":s==="error"?"border-red-400/32 bg-[#120A0A]/95 text-red-100":s==="info"?"border-cyan-300/28 bg-[#0A1012]/95 text-cyan-100":"border-strong bg-[#0B0F16]/95 text-primary"}function cs({open:s,tone:a="neutral",title:c,message:o=null,className:p,primaryAction:f=null,secondaryAction:k=null,onDismiss:S=null,autoDismissMs:q=null}){return l.useEffect(()=>{if(!s||!S||!q)return;const K=window.setTimeout(()=>S(),q);return()=>window.clearTimeout(K)},[q,S,s,c,o]),e.jsx(ke,{initial:!1,children:s?e.jsx(z.div,{initial:{opacity:0,y:-8,scale:.985},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-8,scale:.985},transition:{duration:.2,ease:[.22,1,.36,1]},className:`pointer-events-none ${p??""}`,children:e.jsxs("div",{className:`pointer-events-none min-w-[220px] max-w-[420px] rounded-xl border px-3 py-2 shadow-[0_16px_36px_rgba(0,0,0,0.42)] backdrop-blur ${ls(a)}`,children:[e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-caption font-semibold",children:c}),o?e.jsx("p",{className:"mt-0.5 text-caption opacity-85",children:o}):null]}),S?e.jsx("button",{type:"button",onClick:S,className:"pointer-events-auto inline-flex h-6 w-6 items-center justify-center rounded-md text-current/70 transition-colors hover:bg-white/[0.08] hover:text-current","aria-label":"Dismiss toast",title:"Dismiss",children:e.jsxs("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:"M18 6 6 18"}),e.jsx("path",{d:"m6 6 12 12"})]})}):null]}),f||k?e.jsxs("div",{className:"mt-2 flex items-center gap-1.5",children:[k?e.jsx("button",{type:"button",onClick:k.onClick,className:"pointer-events-auto h-7 rounded-md border border-strong bg-white/[0.06] px-2.5 text-micro font-semibold text-current transition-colors hover:bg-white/[0.12]",children:k.label}):null,f?e.jsx("button",{type:"button",onClick:f.onClick,className:"pointer-events-auto h-7 rounded-md border border-white/25 bg-white/[0.14] px-2.5 text-micro font-semibold text-current transition-colors hover:bg-white/[0.2]",children:f.label}):null]}):null]})}):null})}function It({className:s=""}){return e.jsx("svg",{viewBox:"0 0 20 20",fill:"none","aria-hidden":!0,className:s,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 ds({className:s=""}){return e.jsxs("svg",{viewBox:"0 0 20 20",fill:"none","aria-hidden":!0,className:s,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 us({className:s=""}){return e.jsxs("svg",{viewBox:"0 0 20 20",fill:"none","aria-hidden":!0,className:s,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 Je(s){const a=typeof s.sliceTaskCount=="number"&&Number.isFinite(s.sliceTaskCount)?Math.max(0,Math.floor(s.sliceTaskCount)):null,c=s.sliceScope==="task"?"task":s.sliceScope==="milestone"?"milestone slice":"workstream slice",o=a&&a>0?`${a} ${a===1?"task":"tasks"}`:null;return s.queueState===m.RUNNING?o?`Executing ${o} in ${c}.`:"Execution in progress. Task detail will appear as the scheduler advances.":s.queueState===m.BLOCKED?s.blockReason?"Blocked while waiting for dependency resolution.":"Blocked. Waiting for dependency or review.":s.queueState===m.QUEUED?o?`Queued with ${o} in ${c}.`:"Queued at workstream scope. Task detail will populate after dispatch.":s.queueState===m.COMPLETED?"Completed. No queued tasks remain.":"Idle. Ready to dispatch when started."}function qt(s){const a=typeof s.initiativePriority=="string"?s.initiativePriority.trim().toLowerCase():"",c=typeof s.initiativePriorityNum=="number"&&Number.isFinite(s.initiativePriorityNum)?Math.max(1,Math.min(100,Math.round(s.initiativePriorityNum))):null,o=a==="urgent"||a==="high"||a==="medium"||a==="low"?a:c!==null?c<=12?"urgent":c<=30?"high":c<=60?"medium":"low":null;if(!o)return null;const p=o==="urgent"?"P1":o==="high"?"P2":o==="medium"?"P3":"P4",f=o==="urgent"?"Urgent":o==="high"?"High":o==="medium"?"Medium":"Low",k=o==="urgent"?"border-red-300/35 bg-red-500/[0.14] text-red-100":o==="high"?"border-amber-300/35 bg-amber-500/[0.14] text-amber-100":o==="medium"?"border-[#BFFF00]/35 bg-[#BFFF00]/14 text-[#E1FFB2]":"border-white/[0.2] bg-white/[0.08] text-white/70";return{shortLabel:`${p} ${f}`,longLabel:`Initiative priority ${f} (${p})`,toneClass:k}}function ms(s){const a=s.trim().toLowerCase();if(a.includes("timed out")||a.includes("timeout")||a.includes("request cancelled")||a.includes("signal is aborted"))return"Next Up is still syncing. Keep this panel open and it will repopulate automatically.";if(a.includes("unauthorized")||a.includes("forbidden")||a.includes("api key")||a.includes("auth"))return"Next Up is unavailable until OrgX authentication is reconnected in Settings.";if(a.includes("unknown api endpoint")||a.includes("route is unavailable"))return"This runtime is missing queue routes. Restart and update the plugin build.";const c=s.split("|").map(o=>o.trim()).filter(Boolean).map(o=>o.replace(/^[^:]+:\s*/,"").trim()).filter(Boolean).slice(0,2).join(" ");return Ye(c||s)||"Next Up is temporarily unavailable."}function xs(s){const a=s.trim().toLowerCase();return a.includes("circular")||a.includes("timeline estimate")||a.includes("adjusted accordingly")?null:a.includes("timed out")||a.includes("timeout")||a.includes("request cancelled")||a.includes("signal is aborted")?"Signal is delayed right now. Queue data will appear as soon as sync catches up.":a.includes("fallback")?"Showing fallback queue data while full signal refreshes.":a.includes("unknown api endpoint")||a.includes("route is unavailable")?"Some queue controls are unavailable in this plugin build. Update and restart to restore full controls.":Ye(s.trim())}function Se(s,a,c){const o=typeof s=="string"?s.trim():"";if(o&&!gt(o))return I(o);const p=typeof a=="string"?a.trim():"";return p?gt(p)?`${c} ${es(p)}`:I(p):c}function $t(s){const a=typeof s.runnerAgentName=="string"?s.runnerAgentName.trim():"";if(!a)return"Unassigned";const c=a.toLowerCase();return c==="undefined"||c==="null"||c==="main"&&(s.runnerAgentId==="unassigned"||s.runnerSource==="fallback")?"Unassigned":a}function Tt(s){return s.runnerSource==="inferred"?"inferred":null}function Mt(s,a){const c=s.runnerSource==="assigned"?"assigned":s.runnerSource==="inferred"?"inferred":"fallback";return a==="Unassigned"?`Runner ${c}`:`${a} · ${c}`}function pe(s,a){return!s||s.trim().length===0?a:Ye(s.trim())||a}function vt(s){return!s||typeof s!="object"||Array.isArray(s)?null:s}function Xe(s,a){const c=I(s.workstreamTitle),o=vt(a),p=o&&typeof o.dispatchMode=="string"?o.dispatchMode:null,f=vt(o==null?void 0:o.run);return(f&&typeof f.stopReason=="string"?f.stopReason:f&&typeof f.stop_reason=="string"?f.stop_reason:null)==="budget_exhausted"?`Dispatch acknowledged for ${c}, but autopilot stopped: budget exhausted.`:p==="pending"?`Dispatching ${c}; waiting for slice start…`:p==="fallback"?`Dispatched ${c} using fallback runner.`:`Dispatched ${c}.`}function Rt({className:s=""}){return e.jsxs("svg",{viewBox:"0 0 20 20",fill:"none","aria-hidden":!0,className:s,children:[e.jsx("circle",{cx:"4.5",cy:"10",r:"1.4",fill:"currentColor"}),e.jsx("circle",{cx:"10",cy:"10",r:"1.4",fill:"currentColor"}),e.jsx("circle",{cx:"15.5",cy:"10",r:"1.4",fill:"currentColor"})]})}function ps({compact:s}){const a=s?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:a}).map((c,o)=>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(A,{className:"h-8 w-8 rounded-full"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx(A,{className:"h-3 w-40 rounded-md"}),e.jsx(A,{className:"mt-2 h-4 w-56 rounded-md"})]})]}),e.jsx(A,{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(A,{className:"h-3 w-14 rounded"}),e.jsx(A,{className:"mt-2 h-3 w-full rounded"}),e.jsx(A,{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(A,{className:"h-8 w-24 rounded-full"}),e.jsx(A,{className:"h-8 w-20 rounded-full"}),e.jsx(A,{className:"h-8 w-24 rounded-full"})]})]},`nextup-skeleton-${o}`))]})}function hs({initiativeId:s=null,projectId:a=null,authToken:c=null,embedMode:o=!1,title:p="Next Up",showHeader:f=!0,compact:k=!1,className:S,disableEnterAnimation:q=!1,allowCompactToggle:K=!1,onToggleCompact:he,onOpenInitiative:$,onOpenSettings:L,onUpgradeGate:D,onOpenSliceDetail:_,selectionEnabled:Q=!0,panelStyle:Ce="card",showQueueSettings:Ie=!0,queueModel:qe,queueActions:Ae,onPlayWorkstream:W,snapshotVersion:$e=null,excludeRunning:T=!1}){var ht;const[re,fe]=l.useState(k);l.useEffect(()=>fe(k),[k]);const d=K&&!he?re:k,ae=t=>{he?he(t):fe(t)},[B,y]=l.useState(null),[w,J]=l.useState("workstream"),oe="bottom",[j,le]=l.useState(null),[F,X]=l.useState(null),[x,Y]=l.useState(null),[V,ce]=l.useState(new Set),[Te,de]=l.useState(null),[be,ge]=l.useState(!1),[Et,Me]=l.useState(!1),G=jt(),Oe=l.useRef(null),et=l.useRef(null),tt=l.useRef(null),Lt=Jt({initiativeId:s,projectId:a,limit:40,authToken:c,embedMode:o,enabled:!qe,snapshotVersion:$e,zoomLevel:w}),Bt=qe??Lt,{items:ue,degraded:O,isLoading:M,isFetching:st,isFetchingNextPage:Re,hasNextPage:ze,error:Ee,refetch:Ft,fetchNextPage:nt,playWorkstream:Pt,startWorkstreamAutoContinue:it,initiativeGroups:De,milestoneGroups:_e}=Bt,Ut=Xt({authToken:c,embedMode:o}),H=Ae??Ut,P=t=>`${t.initiativeId}:${t.workstreamId}`,ee=w==="workstream",Ge=l.useMemo(()=>G?{duration:.01}:b.surfaceSwitch,[G]),U=l.useMemo(()=>{if(T)return ue.filter(i=>i.queueState!==m.RUNNING);const t=ue.filter(i=>i.queueState!==m.RUNNING);return t.length>0?t:ue},[T,ue]),rt=l.useMemo(()=>U.length===0?"empty":U.some(t=>t.queueState!==m.RUNNING&&t.queueState!==m.BLOCKED)?m.QUEUED:U.some(t=>t.queueState===m.BLOCKED)?m.BLOCKED:U.some(t=>t.queueState===m.RUNNING)?m.RUNNING:m.QUEUED,[U]),at=l.useMemo(()=>{if(!T)return De;const t=[];for(const i of De){const r=i.items.filter(n=>n.queueState!==m.RUNNING);r.length!==0&&t.push({...i,items:r,queueState:rs(r)})}return t},[T,De]),we=l.useMemo(()=>[...at].sort((t,i)=>{const r=Ue(t.queueState)-Ue(i.queueState);return r!==0?r:t.initiativeTitle.localeCompare(i.initiativeTitle)}),[at]),ot=l.useMemo(()=>T?_e.filter(t=>t.item.queueState!==m.RUNNING):_e,[T,_e]),ye=l.useMemo(()=>[...ot].sort((t,i)=>{const r=Ue(t.queueState)-Ue(i.queueState);if(r!==0)return r;const n=t.initiativeTitle.localeCompare(i.initiativeTitle);if(n!==0)return n;const u=t.workstreamTitle.localeCompare(i.workstreamTitle);return u!==0?u:t.milestoneTitle.localeCompare(i.milestoneTitle)}),[ot]),Ke=l.useMemo(()=>d?we.slice(0,5):we,[d,we]),Qe=l.useMemo(()=>d?ye.slice(0,5):ye,[d,ye]),lt=l.useMemo(()=>w==="initiative"?we.length:w==="milestone"?ye.length:U.length,[U.length,we.length,ye.length,w]),At=[{value:"initiative",label:"Initiative"},{value:"workstream",label:"Workstream"},{value:"milestone",label:"Milestone"}],C=l.useMemo(()=>ee?d?U.slice(0,5):U:[],[d,ee,U]),zt=l.useMemo(()=>C.filter(t=>V.has(P(t))),[V,C]),[me,ct]=l.useState([]),We=l.useRef([]),dt=l.useMemo(()=>{const t=new Map;for(const i of C)t.set(P(i),i);return t},[C]),R=l.useMemo(()=>C.map(P),[C]),Dt=l.useMemo(()=>R.join("|"),[R]);l.useEffect(()=>{ct(t=>{if(d)return[];const i=[],r=new Set(R);for(const n of t)r.has(n)&&i.push(n);for(const n of R)i.includes(n)||i.push(n);return i})},[d,Dt]),l.useEffect(()=>{We.current=me},[me]),l.useEffect(()=>{Te&&(R.includes(Te)||de(null))},[Te,R]),l.useEffect(()=>{ce(t=>{if(t.size===0)return t;const i=new Set(C.map(P)),r=new Set;for(const n of t)i.has(n)&&r.add(n);return r.size===t.size?t:r})},[C]),l.useEffect(()=>{if(!x)return;C.some(i=>P(i)===x)||Y(null)},[x,C]),l.useEffect(()=>{if(O.length===0){Me(!1);return}Me(!1)},[O]),l.useEffect(()=>{Q&&!d&&V.size>0&&ge(!1)},[d,V.size,Q]),l.useEffect(()=>{if(!be)return;const t=r=>{var u;const n=r.target;n&&((u=Oe.current)!=null&&u.contains(n)||ge(!1))},i=r=>{r.key==="Escape"&&ge(!1)};return document.addEventListener("mousedown",t),document.addEventListener("touchstart",t),document.addEventListener("keydown",i),()=>{document.removeEventListener("mousedown",t),document.removeEventListener("touchstart",t),document.removeEventListener("keydown",i)}},[be]),l.useEffect(()=>{if(!ze)return;const t=et.current,i=tt.current;if(!t||!i)return;const r=new IntersectionObserver(n=>{n.some(u=>u.isIntersecting)&&(M||Re||nt().catch(()=>null))},{root:t,rootMargin:"220px 0px 220px 0px",threshold:0});return r.observe(i),()=>r.disconnect()},[nt,ze,Re,M]);const ut=async t=>{const i=P(t),r=I(t.workstreamTitle);try{await H.remove({initiativeId:t.initiativeId,workstreamId:t.workstreamId}),ce(n=>{if(!n.has(i))return n;const u=new Set(n);return u.delete(i),u}),de(n=>n===i?null:n),y(`Removed ${r} from queue.`)}catch(n){const u=n instanceof Error?n.message:"";y(pe(u,"Failed to remove from queue"))}},_t=(t,i,r)=>{const n=d?R:me.length>0?me:R;ce(u=>{const h=new Set(u),E=Te;if(r&&E&&n.includes(E)){const g=n.indexOf(t),Z=n.indexOf(E);if(g>=0&&Z>=0){const[Fe,Pe]=g<Z?[g,Z]:[Z,g];for(const Ne of n.slice(Fe,Pe+1))i?h.add(Ne):h.delete(Ne)}else i?h.add(t):h.delete(t)}else i?h.add(t):h.delete(t);return h}),de(t)},Gt=()=>{ce(new Set(R)),de(R.length>0?R[R.length-1]:null)},Kt=()=>{ce(new Set),de(null)},Ve=async t=>{if(V.size===0){y("Select one or more queue items first.");return}const i=C.map(r=>({key:P(r),item:r})).filter(r=>V.has(r.key));if(i.length===0){y("Selected queue items are no longer visible.");return}X(`bulk:${t}`),y(null);try{const r=i.map(({item:g})=>({initiativeId:g.initiativeId,workstreamId:g.workstreamId})),n=await H.bulk({action:t,items:r}),u=typeof(n==null?void 0:n.updated)=="number"?n.updated??0:0,h=typeof(n==null?void 0:n.failed)=="number"?n.failed??0:0,E=Array.isArray(n==null?void 0:n.errors)?n.errors.filter(g=>typeof g=="string").map(g=>g.trim()).filter(Boolean):[],v=t==="remove"?"removed":t==="move_top"?"moved to top":"moved to bottom";u===0&&h>0&&E.length>0?y(pe(E[0],`${h} queue action${h===1?"":"s"} failed.`)):y(h>0?`${u} item${u===1?"":"s"} ${v}; ${h} failed.`:`${u} item${u===1?"":"s"} ${v}.`),ce(new Set),de(null)}catch(r){const n=r instanceof Error?r.message:"";y(pe(n,"Bulk queue action failed"))}finally{X(null)}},Qt=async()=>{const t=We.current.map(i=>dt.get(i)).filter(Boolean).map(i=>({initiativeId:i.initiativeId,workstreamId:i.workstreamId}));t.length!==0&&await H.reorder({order:t})},te=async(t,i,r)=>{y(null),le(null),D==null||D(null),X(t);try{const n=await i();y(typeof r=="function"?r(n):r)}catch(n){if(n instanceof ts)le(n),D==null||D(n);else{const u=n instanceof Error?n.message:"";y(pe(u,"Action failed"))}}finally{X(null)}},Le=async t=>W?await W(t):await Pt({initiativeId:t.initiativeId,workstreamId:t.workstreamId,agentId:t.runnerAgentId}),Be=j?"upgrade":Ee?"error":B?"notice":null,mt=Ee?ms(Ee):null,ve=O.length>0?xs(O[0]):null,Wt=Be!==null,Vt=O.length>0&&ve!==null&&!Et&&x===null&&!be,se=zt.length,Ht=l.useMemo(()=>w==="initiative"?Ke.length>0:w==="milestone"?Qe.length>0:C.length>0,[Ke.length,C.length,Qe.length,w]),xt=Q&&ee&&!d&&se>0,He=l.useMemo(()=>{if(!T)return 0;let t=0;for(const i of ue)i.queueState===m.RUNNING&&t++;return t},[T,ue]),Zt=w==="initiative"?"No initiatives in the queue right now.":w==="milestone"?"No milestone slices in the queue right now.":He>0?`All queued work is in progress (${He} running).`:O.length>0&&ve?"Queue signal is delayed right now.":"No queued workstreams right now.",pt=e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:Gt,className:"control-pill h-8 px-2.5 text-caption font-semibold",children:"Select all"}),e.jsx("button",{type:"button",onClick:Kt,disabled:V.size===0,className:"control-pill h-8 px-2.5 text-caption font-semibold disabled:opacity-45",children:"Clear"}),e.jsx("button",{type:"button",disabled:se===0||F==="bulk:move_top",onClick:()=>void Ve("move_top"),className:"control-pill h-8 px-2.5 text-caption font-semibold disabled:opacity-45",children:"Move top"}),e.jsx("button",{type:"button",disabled:se===0||F==="bulk:move_bottom",onClick:()=>void Ve("move_bottom"),className:"control-pill h-8 px-2.5 text-caption font-semibold disabled:opacity-45",children:"Move bottom"}),e.jsx("button",{type:"button",disabled:se===0||F==="bulk:remove",onClick:()=>void Ve("remove"),className:"control-pill h-8 px-2.5 text-caption font-semibold disabled:opacity-45",children:"Remove"})]});return e.jsxs(Yt,{surface:Ce==="card",className:`flex h-full min-h-0 flex-col overflow-hidden ${q?"":"card-enter"} ${Ce==="flat"?"!rounded-none !border-none !bg-transparent !shadow-none":""} ${S??""}`,children:[f?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:p}),e.jsx("span",{className:"chip inline-flex min-w-[52px] justify-center text-micro tabular-nums",children:M?e.jsx("span",{"aria-hidden":!0,className:"h-2.5 w-5 rounded bg-white/15 animate-pulse"}):lt}),e.jsx("span",{className:ie("inline-flex min-w-[92px] justify-end text-micro text-muted transition-opacity",st&&!M?"opacity-100":"opacity-0"),"aria-live":"polite",children:"refreshing…"})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"inline-flex items-center rounded-xl border border-white/[0.1] bg-white/[0.03] p-1",role:"tablist","aria-label":"Next Up scope",children:At.map(t=>{const i=w===t.value;return e.jsxs(z.button,{type:"button",role:"tab","aria-selected":i,onClick:()=>J(t.value),...b.segmentedTap,className:ie("relative h-7 rounded-lg px-2.5 text-caption font-semibold transition-colors",i?"text-[#E8FFD0]":"text-secondary hover:text-white"),title:`Show ${t.label.toLowerCase()} queue`,children:[i?e.jsx(z.span,{layoutId:"next-up-scope-indicator",transition:G?{duration:.01}:b.railMorphSpring,className:"pointer-events-none absolute inset-0 rounded-lg border border-[#BFFF00]/35 bg-[#BFFF00]/16","aria-hidden":!0}):null,e.jsx("span",{className:"relative z-[1]",children:t.label})]},t.value)})}),K?e.jsx("button",{type:"button",onClick:()=>ae(!d),className:"control-pill h-8 flex-shrink-0 whitespace-nowrap px-3 text-caption font-semibold",title:d?"Switch to expanded cards":"Switch to compact list","aria-label":d?"Expand Next Up queue":"Compact Next Up queue",children:d?"Expand":"Compact"}):null]})]}):null,Wt&&e.jsx("div",{className:"px-3 pt-2",children:e.jsx(ke,{initial:!1,mode:"wait",children:Be==="upgrade"&&j?e.jsx(z.div,{initial:{opacity:0,y:-4,scale:.99},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-4,scale:.99},transition:Ge,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:[ft(j.currentPlan)," →"," ",ft(j.requiredPlan)]})]}),e.jsx("div",{className:"mt-1 line-clamp-2 text-caption leading-snug text-amber-50/90",title:j.message,children:j.message}),B?e.jsx("div",{className:"mt-1 text-micro text-rose-50/85",children:B}):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 as({actions:j.actions,requiredPlan:j.requiredPlan}).catch(t=>y(pe(t instanceof Error?t.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 os({actions:j.actions}).catch(t=>y(pe(t instanceof Error?t.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"}),L&&e.jsx("button",{type:"button",onClick:L,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"})]}),(ht=j.actions)!=null&&ht.pricing?e.jsx("a",{href:j.actions.pricing,target:"_blank",rel:"noopener noreferrer",className:"text-micro text-secondary underline decoration-white/20 hover:text-primary",children:"View pricing"}):null]})]})},"upgrade"):Be==="error"&&mt?e.jsx(z.div,{initial:{opacity:0,y:-4},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},transition:Ge,className:"rounded-xl border border-red-400/25 bg-red-500/[0.08] px-3 py-2 text-caption text-red-100",children:mt},"error"):Be==="notice"&&B?e.jsx(z.div,{initial:{opacity:0,y:-4},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},transition:Ge,className:"rounded-xl border border-white/[0.1] bg-white/[0.03] px-3 py-2 text-caption text-primary",children:B},"notice"):null})}),e.jsxs("div",{ref:et,className:`flex-1 space-y-2.5 overflow-y-auto overscroll-y-contain scroll-smooth px-3 pb-3 ${f?"pt-1":"pt-2.5"}`,children:[!M&&lt>0?e.jsxs("div",{className:"flex flex-col gap-2.5 px-0.5 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-micro uppercase tracking-[0.08em] text-muted",children:w==="initiative"?"Initiatives":w==="milestone"?"Milestone slices":rt===m.BLOCKED?"Needs attention":rt===m.RUNNING?"Running now":"Queue"}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-1.5",children:[se>0?e.jsxs("span",{className:"chip text-micro",children:[se," selected"]}):null,e.jsx("span",{className:ie("inline-flex min-w-[92px] text-micro text-muted transition-opacity",st&&!M?"opacity-100":"opacity-0"),"aria-live":"polite",children:"refreshing…"}),Q&&ee&&!d&&se===0?e.jsx("span",{className:"text-micro text-muted",children:"Shift+select to pick ranges."}):null]})]}),e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-1.5 sm:justify-end",children:[K?e.jsx("button",{type:"button",onClick:()=>ae(!d),className:"control-pill h-8 px-2.5 text-caption font-semibold",title:d?"Switch to expanded cards":"Switch to compact list","aria-label":d?"Expand Next Up queue":"Compact Next Up queue",children:d?"Expand":"Compact"}):null,xt?e.jsx("div",{className:"flex flex-wrap justify-end gap-1.5",children:pt}):null,!xt&&Ie&&ee?e.jsxs("div",{ref:Oe,className:"relative",children:[e.jsxs("button",{type:"button",onClick:()=>ge(t=>!t),className:"control-pill h-8 px-2.5 text-caption font-semibold","aria-haspopup":"menu","aria-expanded":be,title:"Queue settings",children:[e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"opacity-85","aria-hidden":!0,children:[e.jsx("path",{d:"M4 6h16"}),e.jsx("path",{d:"M7 12h10"}),e.jsx("path",{d:"M10 18h4"})]}),e.jsx("span",{children:"Queue"})]}),be?e.jsx("div",{className:"surface-tier-2 absolute right-0 top-[calc(100%+8px)] z-[280] w-[320px] max-w-[86vw] rounded-xl p-3 shadow-[0_18px_42px_rgba(0,0,0,0.46)] backdrop-blur-xl",children:e.jsxs("div",{className:"space-y-2.5",children:[Q&&!d?e.jsxs("div",{children:[e.jsx("p",{className:"section-kicker",children:"Bulk actions"}),e.jsx("div",{className:"mt-1.5 flex flex-wrap items-center gap-1.5",children:pt})]}):null,L?e.jsx("button",{type:"button",onClick:()=>{ge(!1),L()},className:"control-pill h-7 px-2.5 text-micro font-semibold",children:"Open settings"}):null]})}):null]}):null]})]}):null,M?e.jsx(ps,{compact:d}):null,!M&&!Ht&&!Ee&&e.jsx(Ot,{icon:"queue",headline:Zt,description:He>0?"Check the In Progress tab to see active work.":ve??"Create an initiative or add workstreams to populate the queue.",primaryAction:O.length>0&&ve?{label:"Retry now",onClick:()=>{Me(!1),Ft()}}:void 0}),!M&&w==="initiative"?e.jsx(ke,{initial:!1,children:Ke.map((t,i)=>{const r=t.items.find(v=>v.queueState!==m.RUNNING&&v.queueState!=="completed")??t.items[0]??null,n=Se(t.initiativeTitle,t.initiativeId,"Initiative"),u=wt(t.queueState),h=yt(t.queueState),E=t.items.reduce((v,g)=>v+(g.sliceTaskCount??0),0);return e.jsxs(z.article,{layout:!0,initial:{opacity:0,y:8,scale:.99},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-4,scale:.99},transition:{duration:G?.01:b.surfaceSwitch.duration,delay:G?0:Math.min(i,b.listStaggerMaxItems)*b.listStaggerStep,ease:b.surfaceSwitch.ease},className:"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",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Initiative"}),e.jsx("p",{className:"mt-0.5 truncate text-body font-semibold text-white",title:n,children:n})]}),e.jsx("span",{className:ie("inline-flex items-center rounded-full border px-2 py-0.5 text-[10px] font-semibold uppercase tracking-[0.08em]",h),children:u})]}),e.jsxs("p",{className:"mt-1 text-micro text-secondary",children:[t.workstreamCount," workstreams · ",E," tasks"]}),e.jsx("div",{className:"mt-2 space-y-1",children:t.items.slice(0,3).map((v,g)=>e.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-lg border border-white/[0.06] bg-black/[0.18] px-2.5 py-1.5 text-caption",children:[e.jsx("span",{className:"truncate text-white/84",children:I(v.workstreamTitle)}),e.jsxs("span",{className:"text-micro text-secondary",children:[v.sliceTaskCount??0," tasks"]})]},`${v.workstreamId}:${g}`))}),e.jsxs("div",{className:"mt-2.5 flex items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>$==null?void 0:$(t.initiativeId,t.initiativeTitle),className:"control-pill h-7 px-2.5 text-micro font-semibold",children:"Open"}),e.jsx("button",{type:"button",disabled:!r||F===`initiative:${t.initiativeId}`,onClick:()=>{r&&te(`initiative:${t.initiativeId}`,()=>Le(r),`Dispatched ${I(r.workstreamTitle)}.`)},className:"control-pill h-7 px-2.5 text-micro font-semibold disabled:opacity-45",children:"Dispatch"})]})]},`initiative-group:${t.initiativeId}`)})}):null,!M&&w==="milestone"?e.jsx(ke,{initial:!1,children:Qe.map((t,i)=>{const r=t.item,n=`milestone:${t.workstreamId}:${t.milestoneId??"none"}`;return e.jsxs(z.article,{layout:!0,initial:{opacity:0,y:8,scale:.99},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-4,scale:.99},transition:{duration:G?.01:b.surfaceSwitch.duration,delay:G?0:Math.min(i,b.listStaggerMaxItems)*b.listStaggerStep,ease:b.surfaceSwitch.ease},className:"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",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:[I(t.initiativeTitle)," · ",I(t.workstreamTitle)]}),e.jsx("p",{className:"mt-0.5 truncate text-body font-semibold text-white",title:t.milestoneTitle,children:I(t.milestoneTitle)})]}),e.jsx("span",{className:ie("inline-flex items-center rounded-full border px-2 py-0.5 text-[10px] font-semibold uppercase tracking-[0.08em]",yt(t.queueState)),children:wt(t.queueState)})]}),e.jsxs("p",{className:"mt-1 text-micro text-secondary",children:[t.taskCount," tasks in slice"]}),e.jsxs("div",{className:"mt-2.5 flex items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>$==null?void 0:$(t.initiativeId,t.initiativeTitle),className:"control-pill h-7 px-2.5 text-micro font-semibold",children:"Open"}),e.jsx("button",{type:"button",disabled:F===n||t.queueState===m.RUNNING,onClick:()=>void te(n,()=>Le(r),u=>Xe(r,u)),className:"control-pill h-7 px-2.5 text-micro font-semibold disabled:opacity-45",children:t.queueState===m.RUNNING?"Running":"Start"})]})]},`${t.initiativeId}:${t.workstreamId}:${t.milestoneId??"none"}`)})}):null,!M&&ee&&d?e.jsx(ke,{initial:!1,children:C.map((t,i)=>{const r=P(t),n=F===r,u=t.queueState===m.RUNNING,h=t.nextTaskDueAt?Nt(t.nextTaskDueAt):null,E=Se(t.initiativeTitle,t.initiativeId,"Initiative"),v=Se(t.workstreamTitle,t.workstreamId,"Workstream"),g=qt(t),Z=t.nextTaskTitle?I(t.nextTaskTitle):null,Fe=t.blockReason?I(t.blockReason):null,Pe=$t(t),Ne=Tt(t);return e.jsxs(z.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:G?.01:b.surfaceSwitch.duration,delay:G?0:Math.min(i,b.listStaggerMaxItems)*b.listStaggerStep,ease:b.surfaceSwitch.ease},className:"group relative overflow-visible rounded-2xl border border-white/[0.08] bg-white/[0.02] px-2.5 py-2 cursor-pointer transition-colors hover:border-white/[0.14]",onClick:()=>_==null?void 0:_(t),role:"button",tabIndex:0,onKeyDown:N=>{(N.key==="Enter"||N.key===" ")&&(N.preventDefault(),_==null||_(t))},children:[e.jsx("div",{className:`pointer-events-none absolute inset-x-2.5 top-0 h-px bg-gradient-to-r ${St(t.queueState)}`,"aria-hidden":!0}),e.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[e.jsx(kt,{name:Pe,hint:Mt(t,Pe),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(je,{type:"initiative",size:11,className:"flex-shrink-0 opacity-85"}),e.jsx("button",{type:"button",onClick:()=>$==null?void 0:$(t.initiativeId,t.initiativeTitle),className:"block min-w-0 flex-1 truncate text-left text-micro uppercase tracking-[0.08em] text-muted transition-colors hover:text-white/72",title:E,children:E}),g?e.jsx("span",{className:ie("inline-flex flex-shrink-0 items-center rounded-full border px-2 py-0.5 text-[9px] font-semibold uppercase tracking-[0.08em]",g.toneClass),title:g.longLabel,children:g.shortLabel}):null]}),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:v,children:[e.jsx(je,{type:"workstream",size:12,className:"flex-shrink-0 opacity-95"}),e.jsx("span",{className:"line-clamp-2",children:v})]}),Z?e.jsxs("p",{className:"mt-0.5 line-clamp-2 text-micro leading-snug text-secondary",title:`${Ze(t.queueState)}: ${Z}${h?` · ${h}`:""}`,children:[Ze(t.queueState),": ",Z,h?` · ${h}`:""]}):e.jsx("p",{className:"mt-0.5 line-clamp-2 text-micro leading-snug text-secondary",title:Je(t),children:Je(t)}),Ne?e.jsxs("p",{className:"mt-0.5 text-micro text-muted",children:["Runner ",Ne]}):null,e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-1.5",children:[(()=>{const N=t.objectiveScore??t.compositeScore??null;if(N==null)return null;const xe=N>=80?"S":N>=60?"A":"B",ne=xe==="S"?"border-[#BFFF00]/30 bg-[#BFFF00]/[0.12] text-[#d8ffa1]":xe==="A"?"border-[#14B8A6]/30 bg-[#14B8A6]/[0.12] text-[#87FFE9]":"border-white/[0.12] bg-white/[0.05] text-white/60";return e.jsxs("span",{className:`chip text-[9px] font-semibold ${ne}`,children:[xe,"-tier"]})})(),(()=>{const N=t.expectedValueUsd,xe=t.sliceTaskCount??0,ne=[];return xe>0&&ne.push(`${xe} tasks`),typeof N=="number"&&N>0&&ne.push(`$${N.toFixed(2)}`),h&&ne.push(h),ne.length===0?null:e.jsx("span",{className:"text-micro text-muted",children:ne.join(" · ")})})()]})]})]}),(t.sliceTaskCount??0)>0&&e.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 h-[2px] rounded-b-2xl overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full",style:{width:`${Math.max(t.queueState===m.COMPLETED?100:t.queueState===m.RUNNING?50:15,4)}%`,background:`linear-gradient(90deg, ${bt.lime}, ${bt.teal})`,opacity:.6}})}),Fe&&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: ",Fe]}),e.jsxs("div",{className:"mt-1.5 flex items-center gap-1.5",onClick:N=>N.stopPropagation(),children:[e.jsx("button",{type:"button",disabled:n||u,onClick:()=>void te(r,()=>Le(t),N=>Xe(t,N)),className:"control-pill flex h-7 items-center justify-center px-2.5 text-micro font-semibold disabled:opacity-40",title:u?"Already running":"Start now",children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(It,{className:"h-3 w-3 opacity-85"}),e.jsx("span",{children:u?"Running":"Start"})]})}),e.jsxs("div",{className:"relative ml-auto",children:[e.jsx("button",{type:"button",disabled:n,onClick:()=>Y(N=>N===r?null:r),className:"control-pill flex h-7 items-center justify-center px-2.5 text-micro font-semibold disabled:opacity-40",title:"Queue actions",children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Rt,{className:"h-3 w-3 opacity-85"}),e.jsx("span",{children:"More"})]})}),x===r&&e.jsxs("div",{className:"absolute right-0 top-[calc(100%+6px)] z-[320] min-w-[178px] rounded-xl border border-white/[0.1] bg-[#080d14]/95 p-1.5 shadow-[0_16px_36px_rgba(0,0,0,0.42)] backdrop-blur",children:[e.jsx("button",{type:"button",onClick:()=>{Y(null),te(`${r}:top`,()=>H.move({initiativeId:t.initiativeId,workstreamId:t.workstreamId,placement:"top"}),`Moved ${v} to top of queue.`)},className:"flex h-8 w-full items-center rounded-md px-2.5 text-left text-caption text-primary transition-colors hover:bg-white/[0.08]",children:"Move to top"}),e.jsx("button",{type:"button",onClick:()=>{Y(null),te(`${r}:bottom`,()=>H.move({initiativeId:t.initiativeId,workstreamId:t.workstreamId,placement:"bottom"}),`Moved ${v} to bottom of queue.`)},className:"flex h-8 w-full items-center rounded-md px-2.5 text-left text-caption text-primary transition-colors hover:bg-white/[0.08]",children:"Move to bottom"}),e.jsx("button",{type:"button",onClick:()=>{Y(null),te(`${r}:auto`,()=>it({initiativeId:t.initiativeId,workstreamId:t.workstreamId,agentId:t.runnerAgentId,scope:"initiative"}),`Auto enabled for ${E}.`)},className:"flex h-8 w-full items-center rounded-md px-2.5 text-left text-caption text-primary transition-colors hover:bg-white/[0.08]",children:"Auto on"}),e.jsx("button",{type:"button",disabled:H.isRemoving,onClick:()=>{Y(null),ut(t)},className:"mt-1 flex h-8 w-full items-center rounded-md px-2.5 text-left text-caption text-red-100 transition-colors hover:bg-red-500/[0.12] disabled:opacity-45",children:"Remove from queue"})]})]})]})]},r)})}):!M&&ee?e.jsx(ss,{axis:"y",values:me,onReorder:t=>{We.current=t,ct(t)},className:"space-y-2.5",children:me.map(t=>dt.get(t)).filter(Boolean).map((t,i)=>e.jsx(fs,{item:t,index:i,actionKey:F,setNotice:y,setUpgradeGate:le,onUpgradeGate:D,onOpenInitiative:$,onOpenSliceDetail:_,selected:V.has(P(t)),selectionEnabled:Q,onToggleSelection:_t,menuKey:x,setMenuKey:Y,onPlayWorkstream:Le,startWorkstreamAutoContinue:it,triagePlacement:oe,onPauseWorkstream:(r,n)=>H.stopTriage({initiativeId:r.initiativeId,workstreamId:r.workstreamId,placement:n,resetToTodo:!1}),onMoveWorkstream:(r,n)=>H.move({initiativeId:r.initiativeId,workstreamId:r.workstreamId,placement:n}),onCommitReorder:()=>void Qt().catch(()=>null),onDismiss:ut,runAction:te},P(t)))}):null,(ze||Re)&&e.jsx("div",{ref:tt,className:"flex h-10 items-center justify-center",children:e.jsx("span",{className:"text-micro text-muted",children:Re?"Loading more queue items…":"Scroll for more"})})]}),e.jsx("div",{className:"pointer-events-none absolute bottom-3 right-3 z-[250]",children:e.jsx(cs,{open:Vt,tone:"warning",title:"Limited signal",message:ve,autoDismissMs:6e3,onDismiss:()=>Me(!0)})})]})}function fs({item:s,index:a,actionKey:c,setNotice:o,setUpgradeGate:p,onUpgradeGate:f,onOpenInitiative:k,onOpenSliceDetail:S,selected:q,selectionEnabled:K,onToggleSelection:he,menuKey:$,setMenuKey:L,onPlayWorkstream:D,startWorkstreamAutoContinue:_,triagePlacement:Q,onPauseWorkstream:Ce,onMoveWorkstream:Ie,onCommitReorder:qe,onDismiss:Ae,runAction:W}){const $e=ns(),T=jt(),[re,fe]=l.useState(!1),d=`${s.initiativeId}:${s.workstreamId}`,ae=c===d,B=s.queueState===m.RUNNING,y=s.nextTaskDueAt?Nt(s.nextTaskDueAt):null,w=Se(s.initiativeTitle,s.initiativeId,"Initiative"),J=Se(s.workstreamTitle,s.workstreamId,"Workstream"),oe=qt(s),j=s.nextTaskTitle?I(s.nextTaskTitle):null,le=s.blockReason?I(s.blockReason):null,F=$t(s),X=Tt(s);return e.jsx(is,{value:d,id:d,dragListener:!1,dragControls:$e,onDragStart:()=>fe(!0),onDragEnd:()=>{fe(!1),qe()},whileDrag:{scale:1.02,boxShadow:"0 20px 48px rgba(0,0,0,0.5), 0 0 0 1px rgba(191,255,0,0.15)",zIndex:50,cursor:"grabbing"},className:"relative",children:e.jsxs(z.article,{layout:!0,initial:{opacity:0,y:12,scale:.97},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-8,scale:.98},transition:{duration:T?.01:b.surfaceSwitch.duration,ease:b.surfaceSwitch.ease,delay:T?0:Math.min(a,b.listStaggerMaxItems)*b.listStaggerStep,opacity:{duration:T?.01:b.surfaceSwitch.duration,ease:b.surfaceSwitch.ease}},className:"group relative overflow-visible rounded-2xl border border-white/[0.08] bg-white/[0.02] px-3 py-3 cursor-pointer transition-colors hover:border-white/[0.14]",onClick:()=>S==null?void 0:S(s),role:"button",tabIndex:0,onKeyDown:x=>{(x.key==="Enter"||x.key===" ")&&(x.preventDefault(),S==null||S(s))},children:[e.jsx("div",{className:`pointer-events-none absolute inset-x-3 top-0 h-px bg-gradient-to-r ${St(s.queueState)}`,"aria-hidden":!0}),e.jsx("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.jsxs("div",{className:"relative h-8 w-8 flex-shrink-0",children:[e.jsx("div",{className:`absolute inset-0 transition-[opacity,transform] duration-200 ease-out ${K?q?"opacity-0 scale-90":"opacity-100 scale-100 group-hover:opacity-0 group-hover:scale-90 group-focus-within:opacity-0 group-focus-within:scale-90":"opacity-100 scale-100"}`,children:e.jsx(kt,{name:F,hint:Mt(s,F),size:"sm"})}),K?e.jsx("button",{type:"button",role:"checkbox","aria-checked":q,"aria-label":"Select queue row",title:q?"Selected (Shift+click for range)":"Select (Shift+click for range)",onClick:x=>{x.stopPropagation(),he(d,!q,x.shiftKey)},onMouseDown:x=>x.stopPropagation(),onKeyDown:x=>x.stopPropagation(),className:`absolute inset-0 flex items-center justify-center rounded-full border transition-[opacity,transform,background-color,border-color,color] duration-200 ease-out ${q?"opacity-100 scale-100 border-[#BFFF00]/40 bg-[#BFFF00]/18 text-[#E1FFB2]":"opacity-0 scale-90 border-white/[0.24] bg-black/55 text-white/78 group-hover:opacity-100 group-hover:scale-100 group-focus-within:opacity-100 group-focus-within:scale-100 hover:bg-black/62"}`,children:e.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center rounded-full border border-current/45 bg-black/30",children:q?e.jsx("svg",{viewBox:"0 0 16 16",className:"h-2.5 w-2.5",fill:"none","aria-hidden":!0,children:e.jsx("path",{d:"M3.2 8.3 6.2 11l6.6-6.1",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}):null})}):null]}),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(je,{type:"initiative",size:11,className:"flex-shrink-0 opacity-85"}),e.jsx("button",{type:"button",onClick:()=>k==null?void 0:k(s.initiativeId,s.initiativeTitle),className:"block min-w-0 flex-1 truncate text-left text-micro uppercase tracking-[0.08em] text-muted transition-colors hover:text-white/72",title:w,children:w}),oe?e.jsx("span",{className:ie("inline-flex flex-shrink-0 items-center rounded-full border px-2 py-0.5 text-[9px] font-semibold uppercase tracking-[0.08em]",oe.toneClass),title:oe.longLabel,children:oe.shortLabel}):null]}),e.jsxs("div",{className:"mt-0.5 flex min-w-0 items-start gap-1.5",children:[e.jsx(je,{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:J,children:J})]}),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:[F,X?` · ${X}`:""]})]})]})]})}),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:j?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(je,{type:"task",size:10,className:"flex-shrink-0 opacity-80"}),e.jsx("span",{children:Ze(s.queueState)}),y?e.jsxs("span",{className:"truncate text-micro normal-case tracking-normal text-muted",children:["· ",y]}):null]}),e.jsx("p",{className:"line-clamp-2 break-words text-caption leading-snug text-white/84",title:j,children:j})]}):e.jsx("span",{className:"text-secondary",children:Je(s)})}),le&&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: ",le]}),e.jsxs("div",{className:"mt-2 flex items-center gap-1.5",onClick:x=>x.stopPropagation(),children:[e.jsx("button",{type:"button",disabled:ae||B,onClick:()=>void W(d,()=>D(s),x=>Xe(s,x)),className:"control-pill flex h-7 items-center justify-center px-2.5 text-micro font-semibold disabled:opacity-40",title:B?"Already running":"Start this workstream now",children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(It,{className:"h-3 w-3 opacity-85"}),e.jsx("span",{children:B?"Running":"Start"})]})}),e.jsxs("button",{type:"button",onPointerDown:x=>$e.start(x),"aria-label":"Drag to reorder",title:re?"Reordering":"Drag to reorder",className:`control-pill flex h-7 items-center justify-center gap-1 px-2 text-micro font-semibold transition-colors ${re?"border-[#BFFF00]/35 bg-[#BFFF00]/14 text-[#E1FFB2] cursor-grabbing":"cursor-grab hover:bg-white/[0.08] hover:text-bright"}`,children:[re?e.jsx(us,{className:"h-3.5 w-3.5 opacity-90"}):e.jsx(ds,{className:"h-3.5 w-3.5 opacity-90"}),e.jsx("span",{children:re?"Reordering":"Drag"})]}),e.jsxs("div",{className:"relative ml-auto",children:[e.jsx("button",{type:"button",disabled:ae,onClick:()=>L(x=>x===d?null:d),className:"control-pill flex h-7 items-center justify-center px-2.5 text-micro font-semibold disabled:opacity-40",title:"Queue actions",children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Rt,{className:"h-3 w-3 opacity-85"}),e.jsx("span",{children:"More"})]})}),$===d&&e.jsxs("div",{className:"absolute right-0 top-[calc(100%+6px)] z-[320] min-w-[198px] rounded-xl border border-white/[0.1] bg-[#080d14]/95 p-1.5 shadow-[0_16px_36px_rgba(0,0,0,0.42)] backdrop-blur",children:[e.jsx("button",{type:"button",onClick:()=>{L(null),W(`${d}:top`,()=>Ie(s,"top"),`Moved ${J} to top of queue.`)},className:"flex h-8 w-full items-center rounded-md px-2.5 text-left text-caption text-primary transition-colors hover:bg-white/[0.08]",children:"Move to top"}),e.jsx("button",{type:"button",onClick:()=>{L(null),W(`${d}:bottom`,()=>Ie(s,"bottom"),`Moved ${J} to bottom of queue.`)},className:"flex h-8 w-full items-center rounded-md px-2.5 text-left text-caption text-primary transition-colors hover:bg-white/[0.08]",children:"Move to bottom"}),e.jsx("button",{type:"button",onClick:()=>{L(null),W(`${d}:auto`,()=>_({initiativeId:s.initiativeId,workstreamId:s.workstreamId,agentId:s.runnerAgentId,scope:"initiative"}),`Auto enabled for ${w}.`)},className:"flex h-8 w-full items-center rounded-md px-2.5 text-left text-caption text-primary transition-colors hover:bg-white/[0.08]",children:"Auto on"}),B?e.jsx("button",{type:"button",onClick:()=>{L(null),W(`${d}:pause`,()=>Ce(s,Q),`Paused ${J}.`)},className:"mt-1 flex h-8 w-full items-center rounded-md px-2.5 text-left text-caption text-primary transition-colors hover:bg-white/[0.08]",children:"Pause run"}):null,e.jsx("button",{type:"button",disabled:ae||B,onClick:()=>{L(null),Ae(s)},className:"mt-1 flex h-8 w-full items-center rounded-md px-2.5 text-left text-caption text-red-100 transition-colors hover:bg-red-500/[0.12] disabled:opacity-45",children:"Remove from queue"})]})]})]})]})})}const Ns=Object.freeze(Object.defineProperty({__proto__:null,NextUpPanel:hs},Symbol.toStringTag,{value:"Module"}));export{cs as I,hs as N,Ns as a,as as o};
@@ -1 +1 @@
1
- import{j as r}from"./Dj2k1r16.js";import{B as s}from"./C8AYbjlq.js";function i({className:e=""}){return r.jsx("div",{className:s("shimmer-skeleton",e),"aria-hidden":"true"})}export{i as S};
1
+ import{j as r}from"./Dj2k1r16.js";import{B as s}from"./D2Kqcmv9.js";function i({className:e=""}){return r.jsx("div",{className:s("shimmer-skeleton",e),"aria-hidden":"true"})}export{i as S};
@@ -1 +1 @@
1
- import{r as j,j as e}from"./Dj2k1r16.js";import{D as B,F as N,N as ke,e as x,B as M,O as Ve,Q as Ge,R as Ne,v as O,j as Ie,A as Xe,C as Ke,S as Qe,M as He,m as Je}from"./C8AYbjlq.js";import{u as Ye}from"./D8mvKY2h.js";import{A as Ze,m as I}from"./eeHXe_OQ.js";import"./DMKyYAtD.js";import"./cX2e-TLi.js";import"./BjK42gtU.js";import"./BV0BcV1u.js";const De=/^[0-9a-f-]{20,}$/i,et=new Set(["running","active","queued","pending","in_progress","working","planning","handoff","review"]),tt=new Set(["agent execution failed","execution failed","run failed","failed"]);function v(i){return typeof i=="string"&&i.trim().length>0}function ce(i){return(i??"").trim().toLowerCase()}function rt(i){return(i??"").trim().replace(/\s+/g," ").toLowerCase()}function st(i){return tt.has(rt(i))}function V(i,t=3){return i.length<=t?i.join(", "):`${i.slice(0,t).join(", ")} +${i.length-t} more`}function G(i,t){const f=[],c=h=>{if(typeof h!="string")return;const w=h.trim();w&&(f.some(W=>W.toLowerCase()===w.toLowerCase())||f.push(w))};if(Array.isArray(i))for(const h of i)c(h);return c(t??null),f}function it(i){if(i.runId&&i.runId.trim().length>0)return i.runId.trim();const t=i.metadata;if(!t)return null;const f=["slice_run_id","sliceRunId","runId","run_id","correlation_id","correlationId","sessionId","session_id","agentRunId"];for(const c of f){const h=t[c];if(typeof h=="string"&&h.trim().length>0)return h.trim()}return null}function at(i){const t=ce(i.status);if(t==="blocked"||t==="failed"||t==="completed"||t==="cancelled")return t;const f=ce(i.phase);if(f==="blocked")return"blocked";if(f==="handoff")return"handoff";if(f==="completed")return"completed";if(f==="review")return"review";const c=ce(i.state);return c==="error"?"failed":c==="stopped"?"paused":c==="stale"?"queued":et.has(t)?t:i.blockers.length>0?"blocked":t||"unknown"}function nt(i,t,f){var h;const c=[((h=i.blockerDiagnostics)==null?void 0:h.reason)??null,i.blockerReason??null,...i.blockers,t==="blocked"||t==="failed"||t==="handoff"?f:null].map(w=>typeof w=="string"?w.trim():"").filter(w=>w.length>0);return c.length>0?c.find(W=>!st(W))??c[0]:t==="handoff"?"Waiting for handoff acceptance by the next agent.":t==="blocked"?"Blocked without an explicit reason from runtime.":t==="failed"?"Run failed without explicit error details.":null}function lt(i){return i==="completed"?"border-lime/25 bg-lime/[0.08] text-lime":i==="needs_attention"?"border-amber-400/30 bg-amber-400/10 text-amber-200":i==="failed"?"border-red-400/30 bg-red-500/10 text-red-200":i==="in_progress"?"border-teal-400/30 bg-teal-400/10 text-teal-200":"border-strong bg-white/[0.04] text-secondary"}const dt={hidden:{opacity:0,y:-4},visible:i=>({opacity:1,y:0,transition:{duration:.28,delay:i*.04,ease:[.16,1,.3,1]}}),exit:{opacity:0,transition:{duration:.18}}},R={hidden:{opacity:0,y:8},visible:i=>({opacity:1,y:0,transition:{duration:.22,delay:i*.04,ease:[.22,1,.36,1]}}),exit:{opacity:0,transition:{duration:.18}}};function ue(){return e.jsx("div",{className:"h-px bg-gradient-to-r from-transparent via-white/[0.06] to-transparent"})}function ot(i){return i==="in_progress"?{background:`linear-gradient(90deg, ${x.lime}, ${x.teal})`}:i==="needs_attention"?{background:`linear-gradient(90deg, ${x.red}, ${x.amber})`}:i==="completed"?{background:`linear-gradient(90deg, ${x.teal}, ${x.cyan})`}:i==="failed"?{background:`linear-gradient(90deg, ${x.red}, ${x.red}80)`}:{background:`linear-gradient(90deg, ${x.iris}, ${x.iris}80)`}}const vt=j.memo(function({session:t,activity:f,initiatives:c=[],sliceRuns:h=[],onOpenActivityItem:w,onContinueHighestPriority:W,onDispatchSession:X,onPauseSession:K,onResumeSession:Q,onCancelSession:H,onCreateCheckpoint:J,onRollbackSession:Y,onStartInitiative:ct,onStartWorkstream:ut,initialInterventionDraft:C=null,onSubmitIntervention:te,onClose:me}){var ye,ve,je;const[u,xe]=j.useState(null),[L,T]=j.useState(null),[U,he]=j.useState(!1),[re,z]=j.useState(""),{enqueue:pe,ToastRenderer:Ce}=Ye();j.useEffect(()=>{if(!t){z("");return}if(C!=null&&C.text){z(C.text);return}z("")},[C==null?void 0:C.text,t==null?void 0:t.id]);const q=j.useMemo(()=>{var l,g,y,d,m;if(!t)return new Set;const r=new Set;return(l=t.runId)!=null&&l.trim()&&r.add(t.runId.trim()),(g=t.id)!=null&&g.trim()&&r.add(t.id.trim()),(m=(d=(y=t.blockerDiagnostics)==null?void 0:y.context)==null?void 0:d.sliceRunId)!=null&&m.trim()&&r.add(t.blockerDiagnostics.context.sliceRunId.trim()),r},[t]),$=j.useMemo(()=>t?q.size===0?[]:f.filter(r=>{const l=it(r);return!!(l&&q.has(l))}).sort((r,l)=>Date.parse(l.timestamp)-Date.parse(r.timestamp)).slice(0,12):[],[f,t,q]),s=j.useMemo(()=>{var y,d;if(!t||!Array.isArray(h)||h.length===0)return null;const r=((y=t.initiativeId)==null?void 0:y.trim())??"",l=((d=t.workstreamId)==null?void 0:d.trim())??"",g=h.filter(m=>{var oe,we;const A=((oe=m.sliceRunId)==null?void 0:oe.trim())??"",E=((we=m.runId)==null?void 0:we.trim())??"";if(A&&q.has(A)||E&&q.has(E))return!0;if(!l||!G(m.workstreamIds,m.workstreamId).includes(l))return!1;if(!r)return!0;const ee=G(m.initiativeIds,m.initiativeId);return!(ee.length>0&&!ee.includes(r))});return g.length===0?null:[...g].sort((m,A)=>{const E=Date.parse(m.updatedAt??m.lastEventAt??m.startedAt??""),de=Date.parse(A.updatedAt??A.lastEventAt??A.startedAt??""),ee=Number.isFinite(E)?E:0;return(Number.isFinite(de)?de:0)-ee})[0]},[t,q,h]),se=j.useMemo(()=>{var y;if(!t)return[];const r=[],l=t.initiativeId??t.groupId;if(l){const d=c.find(m=>m.id===l);d?r.push({label:"Initiative",value:d.name}):t.groupLabel&&t.groupLabel.trim().length>0?r.push({label:"Initiative",value:t.groupLabel}):B(l)&&r.push({label:"Initiative",value:N(l)})}if(t.workstreamId){let d=null;for(const m of c){const A=(y=m.workstreams)==null?void 0:y.find(E=>E.id===t.workstreamId);if(A){d=A.name;break}}!d&&B(t.workstreamId)?d=N(t.workstreamId):!d&&!De.test(t.workstreamId)&&(d=t.workstreamId),d&&r.push({label:"Workstream",value:d})}const g=t.phase??null;if(g){const d=String(g);r.push({label:"Milestone",value:B(d)?N(d):d})}return t.title&&r.push({label:"Task",value:t.title}),r},[c,t]),S=j.useMemo(()=>{var y,d;if(!t)return null;const r=((y=$[0])==null?void 0:y.summary)??((d=$[0])==null?void 0:d.description)??null,g=t.lastEventSummary??r??null;return g&&g.trim().length>0?g.trim():null},[$,t]),Ae=j.useMemo(()=>{var r;return t?ke(t.agentName,t.title,t.lastEventSummary,S,(r=$[0])==null?void 0:r.metadata):ke()},[$,t,S]),_=async(r,l,g)=>{if(!(!g||u)){xe(r),T(null);try{await g(),T(`${l} requested.`)}catch(y){T(y instanceof Error?y.message:`${l} failed.`)}finally{xe(null)}}};if(!t)return e.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[e.jsx("div",{className:"h-[2px] flex-shrink-0",style:{background:`linear-gradient(90deg, ${x.iris}, ${x.iris}80)`}}),e.jsxs("div",{className:"flex items-center justify-between px-5 py-3",children:[e.jsx("p",{className:"section-kicker",children:"Session Detail"}),e.jsx("button",{onClick:()=>he(r=>!r),className:"text-muted transition-colors hover:text-primary","aria-label":U?"Expand session detail":"Collapse session detail",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:M("transition-transform",U?"-rotate-90":"rotate-0"),children:e.jsx("path",{d:"m6 9 6 6 6-6"})})})]}),e.jsx("div",{className:M("transition-all",U?"max-h-0 overflow-hidden":"min-h-0 flex-1"),children:e.jsxs("div",{className:"flex h-full min-h-0 flex-col items-center justify-center gap-4 px-5 py-8",children:[e.jsx("div",{className:"flex h-14 w-14 items-center justify-center rounded-2xl border border-white/[0.08] bg-white/[0.03]",children:e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"text-muted",children:[e.jsx("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2"}),e.jsx("path",{d:"M8 21h8M12 17v4"})]})}),e.jsx("p",{className:"text-body text-secondary text-center",children:"No session selected"}),e.jsx("p",{className:"text-caption text-muted text-center max-w-[240px]",children:"Select a session to inspect summary, breadcrumbs, blockers, and recent messages."}),e.jsx("button",{onClick:()=>_("continue-priority","Continue highest priority",W),disabled:!W||!!u,className:"mt-2 h-8 rounded-lg border border-lime/25 bg-lime/10 px-4 text-caption font-semibold text-lime transition-colors hover:bg-lime/20 disabled:opacity-45",children:u==="continue-priority"?"Dispatching...":"Continue highest priority"}),L&&e.jsx("p",{className:"text-caption text-secondary",children:L})]})})]});const P=t.progress===null?null:Math.round(t.progress),k=at(t),p=$[0]??null,ie=(s==null?void 0:s.blockingDecisionCount)??0,Re=Math.max(0,((s==null?void 0:s.decisionCount)??0)-ie),o=Ve({sessionStatus:t.status,sessionPhase:t.phase??null,sessionState:t.state??null,sliceStatus:(s==null?void 0:s.status)??null,activityType:(p==null?void 0:p.type)??null,activityStatus:(typeof(p==null?void 0:p.state)=="string"&&p.state.trim().length>0?p.state:null)??(typeof(p==null?void 0:p.phase)=="string"&&p.phase.trim().length>0?p.phase:null)??(s==null?void 0:s.runtimeState)??null,stopReason:t.blockerReason??((ye=t.blockerDiagnostics)==null?void 0:ye.reason)??((s==null?void 0:s.status)==="failed"?"error":null),decisionRequired:((p==null?void 0:p.decisionRequired)??!1)||ie>0,blockingDecisionCount:ie,nonBlockingDecisionCount:Re,blockerCount:t.blockers.length,blockerReason:t.blockerReason??((ve=t.blockerDiagnostics)==null?void 0:ve.reason)??null}),ae=nt(t,k,S),Te=k==="handoff"?"Handoff":k==="blocked"?"Blocker reason":k==="failed"?"Failure reason":"Status note",$e=o.status==="in_progress"&&["running","active","queued","pending","working","in_progress","planning","review"].includes(k),Se=o.status==="needs_attention"&&["paused","blocked","queued","pending"].includes(k),Be=!["completed","archived","cancelled"].includes(k),Me=!["archived","cancelled"].includes(k),Le=o.label,_e=lt(o.status),ne=["running","active","working","in_progress","planning","review"].includes(k),Ee=o.status!=="in_progress"&&!ne,We=o.tone==="critical"?x.red:o.tone==="warning"?x.amber:o.tone==="positive"?x.lime:x.teal,Ue=P!==null&&P>=100&&o.status!=="completed"?"Terminal state":"Progress",qe=o.tone==="critical"?"border-red-400/25 bg-red-500/10":o.tone==="warning"?"border-amber-400/25 bg-amber-500/10":o.tone==="positive"?"border-lime/22 bg-lime/[0.08]":"border-subtle bg-white/[0.02]",a=t.blockerDiagnostics??null,n=(a==null?void 0:a.context)??null,le=[v(a==null?void 0:a.source)?`Source: ${a.source.trim()}`:null,v(a==null?void 0:a.errorCode)?`Code: ${a.errorCode.trim()}`:null,v(a==null?void 0:a.errorCategory)?`Category: ${a.errorCategory.trim()}`:null,(a==null?void 0:a.retryable)===!0?"Retryable: yes":(a==null?void 0:a.retryable)===!1?"Retryable: no":null].filter(r=>!!r),b=[];n&&(Array.isArray(n.initiativeIds)&&n.initiativeIds.length>0?b.push({label:"Initiatives",value:V(n.initiativeIds.map(r=>B(r)?N(r):r),4)}):v(n.initiativeId)&&b.push({label:"Initiative",value:Ge("Initiative",n.initiativeId.trim())}),v(n.workstreamTitle)?b.push({label:"Workstream",value:n.workstreamTitle.trim()}):Array.isArray(n.workstreamIds)&&n.workstreamIds.length>0?b.push({label:"Workstreams",value:V(n.workstreamIds,4)}):v(n.workstreamId)&&b.push({label:"Workstream",value:n.workstreamId.trim()}),v(n.sliceRunId)&&b.push({label:"Slice run",value:N(n.sliceRunId.trim())}),v(n.parallelMode)&&b.push({label:"Mode",value:n.parallelMode.trim().toUpperCase()}),Array.isArray(n.taskIds)&&n.taskIds.length>0&&b.push({label:"Tasks",value:V(n.taskIds.map(r=>B(r)?N(r):r))}),Array.isArray(n.milestoneIds)&&n.milestoneIds.length>0&&b.push({label:"Milestones",value:V(n.milestoneIds.map(r=>B(r)?N(r):r))}),Array.isArray(n.iwmtIds)&&n.iwmtIds.length>0?b.push({label:"Scope IDs",value:V(n.iwmtIds.map(r=>B(r)?N(r):r),4)}):v(n.iwmtId)&&b.push({label:"Scope ID",value:B(n.iwmtId.trim())?N(n.iwmtId.trim()):n.iwmtId.trim()}),v(n.logPath)&&b.push({label:"Log path",value:Ne(n.logPath.trim())}),v(n.outputPath)&&b.push({label:"Output path",value:Ne(n.outputPath.trim())}));const be=(k==="blocked"||k==="failed")&&!!(a&&(v(a.reason)||le.length>0||b.length>0||Array.isArray(a.suggestedActions)&&a.suggestedActions.length>0)),Z=v(ae)?ae:null,ze=Z!==null&&!(S&&(Z===S||S.includes(Z)))&&!be,Pe=j.useCallback(()=>{!H||!t||(T("Session will be cancelled..."),pe({message:`Cancelled "${t.title}"`,onCommit:async()=>{try{await H(t),T("Session cancelled.")}catch(r){T(r instanceof Error?r.message:"Cancel failed.")}},onUndo:()=>{T(null)}}))},[H,t,pe]),Fe=[{label:"Started",value:t.startedAt?O(t.startedAt):"—"},{label:"Updated",value:t.updatedAt?O(t.updatedAt):"—"},...t.eta?[{label:"ETA",value:t.eta}]:[],...t.checkpointCount?[{label:"Checkpoints",value:String(t.checkpointCount)}]:[]],fe=s?s.status.replace(/_/g," "):null,F=G(s==null?void 0:s.initiativeIds,(s==null?void 0:s.initiativeId)??null),D=G(s==null?void 0:s.workstreamIds,(s==null?void 0:s.workstreamId)??null);G(s==null?void 0:s.iwmtIds,(s==null?void 0:s.iwmtId)??null);const Oe=F[0]?((je=c.find(r=>r.id===F[0]))==null?void 0:je.name)??F[0]:null,ge=L?L.toLowerCase().includes("fail")||L.toLowerCase().includes("error")?"error":u?"pending":"success":null;return e.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[e.jsx("div",{className:"h-[2px] flex-shrink-0",style:ot(o.status)}),e.jsxs("div",{className:"flex items-center justify-between px-5 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("p",{className:"section-kicker",children:"Session Detail"}),e.jsxs("span",{className:M("inline-flex items-center gap-1.5 rounded-full border px-2 py-[1px] text-micro font-semibold uppercase tracking-widest",_e),children:[ne&&e.jsx("span",{className:"h-1.5 w-1.5 rounded-full pulse-soft",style:{backgroundColor:Ie(k)}}),Le]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{onClick:()=>he(r=>!r),className:"text-muted transition-colors hover:text-primary","aria-label":U?"Expand session detail":"Collapse session detail",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:M("transition-transform",U?"-rotate-90":"rotate-0"),children:e.jsx("path",{d:"m6 9 6 6 6-6"})})}),me&&e.jsx("button",{type:"button",onClick:me,"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.jsxs("div",{className:M("transition-all flex flex-col min-h-0",U?"max-h-0 overflow-hidden":"flex-1"),children:[e.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto px-5 py-5 space-y-5",children:[e.jsx(Ze,{mode:"wait",children:e.jsxs(I.div,{variants:dt,initial:"hidden",animate:"visible",exit:"exit",custom:0,children:[e.jsxs("div",{className:"flex items-start gap-3.5",children:[e.jsx(Xe,{name:t.agentName??"OrgX",size:"md",hint:t.agentName}),e.jsxs("div",{className:"min-w-0 flex-1 pt-0.5",children:[e.jsx("h2",{className:"text-[28px] font-medium leading-tight text-white truncate",children:Ke(t.title)}),e.jsxs("p",{className:"mt-1 text-micro uppercase tracking-[0.12em] text-muted",children:[t.agentName??"OrgX"," · ",Ae.label]})]})]}),se.length>0&&e.jsx("div",{className:"mt-3 flex flex-wrap items-center gap-1.5",children:se.map((r,l)=>e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(Qe,{tone:"muted",children:r.value}),l<se.length-1&&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"})})]},`${r.label}-${r.value}`))})]},t.id)}),e.jsx(ue,{}),S&&e.jsxs(I.div,{variants:R,initial:"hidden",animate:"visible",custom:1,children:[e.jsx("p",{className:"section-kicker mb-2",children:"Summary"}),e.jsx(He,{text:S,mode:"block"})]}),e.jsx(I.div,{variants:R,initial:"hidden",animate:"visible",custom:2,children:e.jsxs("div",{className:M("rounded-xl border px-4 py-3",qe),children:[e.jsx("p",{className:"section-kicker mb-1.5",children:o.label}),e.jsx("p",{className:"text-body text-secondary",children:o.sentence}),o.nextAction&&e.jsxs("p",{className:"mt-1.5 flex items-center gap-1 text-caption text-secondary",children:[e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:x.lime,strokeWidth:"2.5",className:"flex-shrink-0",children:e.jsx("path",{d:"m9 18 6-6-6-6"})}),"Next: ",o.nextAction]})]})}),ze&&e.jsx(I.div,{variants:R,initial:"hidden",animate:"visible",custom:3,children:e.jsxs("div",{className:"rounded-xl border border-subtle bg-white/[0.02] px-4 py-3",children:[e.jsx("p",{className:"section-kicker mb-1.5",children:Te}),e.jsx("p",{className:"text-body text-secondary",children:Z})]})}),be&&e.jsx(I.div,{variants:R,initial:"hidden",animate:"visible",custom:3,children:e.jsxs("div",{className:"rounded-xl border border-red-500/25 bg-red-500/10 px-4 py-3",children:[e.jsx("p",{className:"section-kicker mb-1.5 text-red-200/75",children:"Why blocked"}),e.jsx("p",{className:"text-body text-red-100/90",children:(a==null?void 0:a.reason)??ae??"Runtime marked this run as blocked without details."}),le.length>0&&e.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:le.map(r=>e.jsx("span",{className:"rounded-full border border-red-300/25 bg-red-500/10 px-2 py-0.5 text-micro text-red-100/85",children:r},r))}),b.length>0&&e.jsxs("div",{className:"mt-2 rounded-md border border-red-300/20 bg-black/15 p-2.5",children:[e.jsx("p",{className:"mb-1 text-micro uppercase tracking-[0.14em] text-red-200/65",children:"Associated context"}),e.jsx("dl",{className:"grid grid-cols-1 gap-1.5 text-caption text-red-100/85",children:b.map(r=>e.jsxs("div",{className:"grid grid-cols-[86px_1fr] gap-2",children:[e.jsx("dt",{className:"text-red-200/70",children:r.label}),e.jsx("dd",{className:"break-all text-red-50/95",children:r.value})]},r.label))})]}),Array.isArray(a==null?void 0:a.suggestedActions)&&a.suggestedActions.length>0&&e.jsxs("div",{className:"mt-2",children:[e.jsx("p",{className:"mb-1 text-micro uppercase tracking-[0.14em] text-red-200/65",children:"Suggested actions"}),e.jsx("ul",{className:"space-y-1 text-caption text-red-100/85",children:a.suggestedActions.map(r=>e.jsxs("li",{children:["• ",r]},r))})]}),v(a==null?void 0:a.eventTimestamp)&&e.jsxs("p",{className:"mt-2 text-micro text-red-200/60",children:["Last blocker event: ",new Date(a.eventTimestamp).toLocaleString()," ·"," ",O(a.eventTimestamp)]})]})}),e.jsx(ue,{}),e.jsxs(I.div,{variants:R,initial:"hidden",animate:"visible",custom:4,children:[P!==null&&e.jsxs("div",{className:"mb-3",children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between text-caption text-secondary",children:[e.jsx("span",{children:Ue}),e.jsxs("span",{className:"text-primary",children:[P,"%"]})]}),e.jsx("div",{className:"h-[3px] rounded-full bg-white/[0.08]",children:e.jsx(I.div,{className:M("h-[3px] rounded-full",ne&&"live-pulse"),style:{background:We},initial:{width:0},animate:{width:`${P}%`},transition:{duration:.5,ease:Je.easingStandard}})})]}),e.jsx("dl",{className:"grid grid-cols-2 gap-3 text-caption text-secondary",children:Fe.map(r=>e.jsxs("div",{children:[e.jsx("dt",{className:"text-muted",children:r.label}),e.jsx("dd",{className:"text-body font-semibold text-white",children:r.value})]},r.label))})]}),s&&e.jsx(I.div,{variants:R,initial:"hidden",animate:"visible",custom:5,children:e.jsxs("div",{className:"rounded-xl border border-subtle bg-white/[0.02] px-4 py-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"section-kicker",children:"Slice scope"}),fe?e.jsx("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-2 py-0.5 text-micro font-semibold uppercase tracking-[0.08em] text-secondary",children:fe}):null]}),s.statusExplainer?e.jsx("p",{className:"mt-2 text-caption text-secondary",children:s.statusExplainer}):null,e.jsxs("dl",{className:"mt-2 grid grid-cols-2 gap-2 text-caption text-secondary",children:[e.jsxs("div",{children:[e.jsx("dt",{className:"text-muted",children:"Initiative"}),e.jsx("dd",{className:"text-body font-semibold text-white",children:Oe??"—"})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-muted",children:"Workstream"}),e.jsx("dd",{className:"text-body font-semibold text-white",children:s.workstreamTitle??(D[0]?N(D[0]):"—")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-muted",children:"Run"}),e.jsx("dd",{className:"break-all text-body font-semibold text-white",children:N(s.runId??s.sliceRunId)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-muted",children:"Updated"}),e.jsx("dd",{className:"text-body font-semibold text-white",children:s.updatedAt?O(s.updatedAt):"—"})]})]}),e.jsxs("div",{className:"mt-2 flex flex-wrap gap-1.5 text-micro",children:[e.jsxs("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-2 py-0.5 text-secondary",children:["Tasks ",s.taskIds.length]}),e.jsxs("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-2 py-0.5 text-secondary",children:["Milestones ",s.milestoneIds.length]}),e.jsxs("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-2 py-0.5 text-secondary",children:["Artifacts ",s.artifactCount]}),e.jsxs("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-2 py-0.5 text-secondary",children:["Needs input ",s.blockingDecisionCount]}),F.length>1?e.jsxs("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-2 py-0.5 text-secondary",children:["+",F.length-1," initiatives"]}):null,D.length>1?e.jsxs("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-2 py-0.5 text-secondary",children:["+",D.length-1," workstreams"]}):null]}),s.taskIds.length>0?e.jsxs("p",{className:"mt-2 text-micro text-secondary",children:["Tasks: ",s.taskIds.length]}):null]})}),t.blockers.length>0&&e.jsx(I.div,{variants:R,initial:"hidden",animate:"visible",custom:6,children:e.jsxs("div",{className:"rounded-xl border border-red-500/30 bg-red-500/10 px-4 py-3",children:[e.jsx("p",{className:"section-kicker mb-2 text-red-200/70",children:"Blockers"}),e.jsx("ul",{className:"space-y-1 text-body text-red-100/90",children:t.blockers.map(r=>e.jsxs("li",{children:["• ",r]},r))})]})}),e.jsx(ue,{}),e.jsxs(I.div,{variants:R,initial:"hidden",animate:"visible",custom:7,children:[e.jsx("p",{className:"section-kicker mb-4",children:"Recent Messages"}),$.length===0&&e.jsx("p",{className:"text-body text-secondary",children:"No recent messages for this run."}),e.jsx("div",{className:"relative border-l border-white/[0.06] pl-6 ml-1 space-y-3",children:$.map((r,l)=>e.jsxs(I.div,{className:"relative group",variants:R,initial:"hidden",animate:"visible",custom:l,children:[e.jsx("div",{className:"absolute -left-[27px] top-1.5 h-2 w-2 rounded-full border border-black ring-4 ring-black",style:{backgroundColor:Ie(r.type??r.state??"unknown")}}),e.jsxs("article",{className:"rounded-lg border border-subtle bg-white/[0.02] px-3 py-2.5 transition-colors hover:bg-white/[0.04]",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsx("p",{className:"min-w-0 flex-1 text-caption text-bright",children:r.title}),w&&e.jsx("button",{type:"button",onClick:()=>w(r),className:"flex-shrink-0 rounded-full border border-strong bg-white/[0.03] px-2.5 py-0.5 text-micro font-semibold text-secondary opacity-0 transition-all group-hover:opacity-100 hover:bg-white/[0.08] hover:text-primary",children:"Open"})]}),(r.summary||r.description)&&e.jsx("p",{className:"mt-0.5 line-clamp-2 text-caption text-secondary",children:r.summary??r.description}),e.jsxs("p",{className:"mt-1 text-micro text-muted",children:[new Date(r.timestamp).toLocaleString()," · ",O(r.timestamp)]})]})]},r.id))})]})]}),e.jsxs("div",{className:"flex-shrink-0 border-t border-subtle px-5 py-3 space-y-3",children:[L&&e.jsx("p",{className:M("rounded-md border px-2.5 py-1.5 text-caption",ge==="error"?"border-red-400/30 bg-red-500/10 text-red-200":ge==="pending"?"border-white/[0.08] bg-white/[0.02] text-secondary pulse-soft":"border-lime/25 bg-lime/[0.08] text-lime"),children:L}),te&&e.jsx("div",{children:e.jsx("textarea",{value:re,onChange:r=>z(r.target.value),placeholder:"Share guidance for this run...",rows:2,className:"w-full resize-none rounded-lg border border-white/[0.10] bg-white/[0.03] px-3 py-2 text-body text-bright outline-none placeholder:text-faint focus:border-white/20"})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[$e&&e.jsx("button",{onClick:()=>_("pause-session","Session paused",()=>K==null?void 0:K(t)),disabled:!K||!!u,className:"rounded-md px-2.5 py-1.5 text-caption font-medium text-secondary hover:bg-white/[0.04] hover:text-white disabled:opacity-45 transition-colors",children:u==="pause-session"?"Pausing...":"Pause"}),Se&&e.jsx("button",{onClick:()=>_("resume-session","Session resumed",()=>Q==null?void 0:Q(t)),disabled:!Q||!!u,className:"rounded-md px-2.5 py-1.5 text-caption font-medium text-secondary hover:bg-white/[0.04] hover:text-white disabled:opacity-45 transition-colors",children:u==="resume-session"?"Resuming...":"Resume"}),e.jsx("button",{onClick:()=>_("checkpoint-session","Progress saved",()=>J==null?void 0:J(t)),disabled:!J||!!u,className:"rounded-md px-2.5 py-1.5 text-caption font-medium text-secondary hover:bg-white/[0.04] hover:text-white disabled:opacity-45 transition-colors",children:u==="checkpoint-session"?"Saving...":"Save"}),Me&&e.jsx("button",{onClick:()=>_("rollback-session","Undo requested",()=>Y==null?void 0:Y(t)),disabled:!Y||!!u,className:"rounded-md px-2.5 py-1.5 text-caption font-medium text-secondary hover:bg-white/[0.04] hover:text-white disabled:opacity-45 transition-colors",children:u==="rollback-session"?"Undoing...":"Undo"}),Be&&H&&e.jsx("button",{onClick:Pe,disabled:!!u,className:"rounded-md px-2.5 py-1.5 text-caption font-medium text-red-400/70 hover:bg-red-500/[0.08] hover:text-red-300 disabled:opacity-45 transition-colors",children:"Cancel"})]}),e.jsx("div",{className:"flex-1"}),te&&e.jsx("button",{type:"button",onClick:()=>{const r=re.trim();if(!r){T("Intervention note cannot be empty.");return}_("intervene-note","Intervention sent",async()=>{await te({session:t,workstreamId:(C==null?void 0:C.workstreamId)??t.workstreamId??null,text:r}),z("")})},disabled:!!u||re.trim().length===0,className:"rounded-md 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] disabled:opacity-45",children:u==="intervene-note"?"Sending...":"Intervene"}),e.jsxs("button",{onClick:()=>_("dispatch-session","Session started",()=>X==null?void 0:X(t)),disabled:!X||!!u||!Ee,className:"inline-flex h-8 items-center gap-1.5 rounded-lg border border-lime/25 bg-lime/10 px-4 text-caption font-semibold text-lime transition-colors hover:bg-lime/20 disabled:opacity-45",children:[e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",className:"flex-shrink-0",children:e.jsx("path",{d:"M8 5v14l11-7z"})}),u==="dispatch-session"?"Starting...":o.status==="completed"?"Restart":"Start"]})]})]})]}),e.jsx(Ce,{})]})});export{vt as SessionInspector};
1
+ import{r as j,j as e}from"./Dj2k1r16.js";import{D as B,F as N,N as ke,e as x,B as M,O as Ve,Q as Ge,R as Ne,v as O,j as Ie,A as Xe,C as Ke,S as Qe,M as He,m as Je}from"./D2Kqcmv9.js";import{u as Ye}from"./467jKHFJ.js";import{A as Ze,m as I}from"./eeHXe_OQ.js";import"./DMKyYAtD.js";import"./cX2e-TLi.js";import"./BjK42gtU.js";import"./BV0BcV1u.js";const De=/^[0-9a-f-]{20,}$/i,et=new Set(["running","active","queued","pending","in_progress","working","planning","handoff","review"]),tt=new Set(["agent execution failed","execution failed","run failed","failed"]);function v(i){return typeof i=="string"&&i.trim().length>0}function ce(i){return(i??"").trim().toLowerCase()}function rt(i){return(i??"").trim().replace(/\s+/g," ").toLowerCase()}function st(i){return tt.has(rt(i))}function V(i,t=3){return i.length<=t?i.join(", "):`${i.slice(0,t).join(", ")} +${i.length-t} more`}function G(i,t){const f=[],c=h=>{if(typeof h!="string")return;const w=h.trim();w&&(f.some(W=>W.toLowerCase()===w.toLowerCase())||f.push(w))};if(Array.isArray(i))for(const h of i)c(h);return c(t??null),f}function it(i){if(i.runId&&i.runId.trim().length>0)return i.runId.trim();const t=i.metadata;if(!t)return null;const f=["slice_run_id","sliceRunId","runId","run_id","correlation_id","correlationId","sessionId","session_id","agentRunId"];for(const c of f){const h=t[c];if(typeof h=="string"&&h.trim().length>0)return h.trim()}return null}function at(i){const t=ce(i.status);if(t==="blocked"||t==="failed"||t==="completed"||t==="cancelled")return t;const f=ce(i.phase);if(f==="blocked")return"blocked";if(f==="handoff")return"handoff";if(f==="completed")return"completed";if(f==="review")return"review";const c=ce(i.state);return c==="error"?"failed":c==="stopped"?"paused":c==="stale"?"queued":et.has(t)?t:i.blockers.length>0?"blocked":t||"unknown"}function nt(i,t,f){var h;const c=[((h=i.blockerDiagnostics)==null?void 0:h.reason)??null,i.blockerReason??null,...i.blockers,t==="blocked"||t==="failed"||t==="handoff"?f:null].map(w=>typeof w=="string"?w.trim():"").filter(w=>w.length>0);return c.length>0?c.find(W=>!st(W))??c[0]:t==="handoff"?"Waiting for handoff acceptance by the next agent.":t==="blocked"?"Blocked without an explicit reason from runtime.":t==="failed"?"Run failed without explicit error details.":null}function lt(i){return i==="completed"?"border-lime/25 bg-lime/[0.08] text-lime":i==="needs_attention"?"border-amber-400/30 bg-amber-400/10 text-amber-200":i==="failed"?"border-red-400/30 bg-red-500/10 text-red-200":i==="in_progress"?"border-teal-400/30 bg-teal-400/10 text-teal-200":"border-strong bg-white/[0.04] text-secondary"}const dt={hidden:{opacity:0,y:-4},visible:i=>({opacity:1,y:0,transition:{duration:.28,delay:i*.04,ease:[.16,1,.3,1]}}),exit:{opacity:0,transition:{duration:.18}}},R={hidden:{opacity:0,y:8},visible:i=>({opacity:1,y:0,transition:{duration:.22,delay:i*.04,ease:[.22,1,.36,1]}}),exit:{opacity:0,transition:{duration:.18}}};function ue(){return e.jsx("div",{className:"h-px bg-gradient-to-r from-transparent via-white/[0.06] to-transparent"})}function ot(i){return i==="in_progress"?{background:`linear-gradient(90deg, ${x.lime}, ${x.teal})`}:i==="needs_attention"?{background:`linear-gradient(90deg, ${x.red}, ${x.amber})`}:i==="completed"?{background:`linear-gradient(90deg, ${x.teal}, ${x.cyan})`}:i==="failed"?{background:`linear-gradient(90deg, ${x.red}, ${x.red}80)`}:{background:`linear-gradient(90deg, ${x.iris}, ${x.iris}80)`}}const vt=j.memo(function({session:t,activity:f,initiatives:c=[],sliceRuns:h=[],onOpenActivityItem:w,onContinueHighestPriority:W,onDispatchSession:X,onPauseSession:K,onResumeSession:Q,onCancelSession:H,onCreateCheckpoint:J,onRollbackSession:Y,onStartInitiative:ct,onStartWorkstream:ut,initialInterventionDraft:C=null,onSubmitIntervention:te,onClose:me}){var ye,ve,je;const[u,xe]=j.useState(null),[L,T]=j.useState(null),[U,he]=j.useState(!1),[re,z]=j.useState(""),{enqueue:pe,ToastRenderer:Ce}=Ye();j.useEffect(()=>{if(!t){z("");return}if(C!=null&&C.text){z(C.text);return}z("")},[C==null?void 0:C.text,t==null?void 0:t.id]);const q=j.useMemo(()=>{var l,g,y,d,m;if(!t)return new Set;const r=new Set;return(l=t.runId)!=null&&l.trim()&&r.add(t.runId.trim()),(g=t.id)!=null&&g.trim()&&r.add(t.id.trim()),(m=(d=(y=t.blockerDiagnostics)==null?void 0:y.context)==null?void 0:d.sliceRunId)!=null&&m.trim()&&r.add(t.blockerDiagnostics.context.sliceRunId.trim()),r},[t]),$=j.useMemo(()=>t?q.size===0?[]:f.filter(r=>{const l=it(r);return!!(l&&q.has(l))}).sort((r,l)=>Date.parse(l.timestamp)-Date.parse(r.timestamp)).slice(0,12):[],[f,t,q]),s=j.useMemo(()=>{var y,d;if(!t||!Array.isArray(h)||h.length===0)return null;const r=((y=t.initiativeId)==null?void 0:y.trim())??"",l=((d=t.workstreamId)==null?void 0:d.trim())??"",g=h.filter(m=>{var oe,we;const A=((oe=m.sliceRunId)==null?void 0:oe.trim())??"",E=((we=m.runId)==null?void 0:we.trim())??"";if(A&&q.has(A)||E&&q.has(E))return!0;if(!l||!G(m.workstreamIds,m.workstreamId).includes(l))return!1;if(!r)return!0;const ee=G(m.initiativeIds,m.initiativeId);return!(ee.length>0&&!ee.includes(r))});return g.length===0?null:[...g].sort((m,A)=>{const E=Date.parse(m.updatedAt??m.lastEventAt??m.startedAt??""),de=Date.parse(A.updatedAt??A.lastEventAt??A.startedAt??""),ee=Number.isFinite(E)?E:0;return(Number.isFinite(de)?de:0)-ee})[0]},[t,q,h]),se=j.useMemo(()=>{var y;if(!t)return[];const r=[],l=t.initiativeId??t.groupId;if(l){const d=c.find(m=>m.id===l);d?r.push({label:"Initiative",value:d.name}):t.groupLabel&&t.groupLabel.trim().length>0?r.push({label:"Initiative",value:t.groupLabel}):B(l)&&r.push({label:"Initiative",value:N(l)})}if(t.workstreamId){let d=null;for(const m of c){const A=(y=m.workstreams)==null?void 0:y.find(E=>E.id===t.workstreamId);if(A){d=A.name;break}}!d&&B(t.workstreamId)?d=N(t.workstreamId):!d&&!De.test(t.workstreamId)&&(d=t.workstreamId),d&&r.push({label:"Workstream",value:d})}const g=t.phase??null;if(g){const d=String(g);r.push({label:"Milestone",value:B(d)?N(d):d})}return t.title&&r.push({label:"Task",value:t.title}),r},[c,t]),S=j.useMemo(()=>{var y,d;if(!t)return null;const r=((y=$[0])==null?void 0:y.summary)??((d=$[0])==null?void 0:d.description)??null,g=t.lastEventSummary??r??null;return g&&g.trim().length>0?g.trim():null},[$,t]),Ae=j.useMemo(()=>{var r;return t?ke(t.agentName,t.title,t.lastEventSummary,S,(r=$[0])==null?void 0:r.metadata):ke()},[$,t,S]),_=async(r,l,g)=>{if(!(!g||u)){xe(r),T(null);try{await g(),T(`${l} requested.`)}catch(y){T(y instanceof Error?y.message:`${l} failed.`)}finally{xe(null)}}};if(!t)return e.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[e.jsx("div",{className:"h-[2px] flex-shrink-0",style:{background:`linear-gradient(90deg, ${x.iris}, ${x.iris}80)`}}),e.jsxs("div",{className:"flex items-center justify-between px-5 py-3",children:[e.jsx("p",{className:"section-kicker",children:"Session Detail"}),e.jsx("button",{onClick:()=>he(r=>!r),className:"text-muted transition-colors hover:text-primary","aria-label":U?"Expand session detail":"Collapse session detail",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:M("transition-transform",U?"-rotate-90":"rotate-0"),children:e.jsx("path",{d:"m6 9 6 6 6-6"})})})]}),e.jsx("div",{className:M("transition-all",U?"max-h-0 overflow-hidden":"min-h-0 flex-1"),children:e.jsxs("div",{className:"flex h-full min-h-0 flex-col items-center justify-center gap-4 px-5 py-8",children:[e.jsx("div",{className:"flex h-14 w-14 items-center justify-center rounded-2xl border border-white/[0.08] bg-white/[0.03]",children:e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"text-muted",children:[e.jsx("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2"}),e.jsx("path",{d:"M8 21h8M12 17v4"})]})}),e.jsx("p",{className:"text-body text-secondary text-center",children:"No session selected"}),e.jsx("p",{className:"text-caption text-muted text-center max-w-[240px]",children:"Select a session to inspect summary, breadcrumbs, blockers, and recent messages."}),e.jsx("button",{onClick:()=>_("continue-priority","Continue highest priority",W),disabled:!W||!!u,className:"mt-2 h-8 rounded-lg border border-lime/25 bg-lime/10 px-4 text-caption font-semibold text-lime transition-colors hover:bg-lime/20 disabled:opacity-45",children:u==="continue-priority"?"Dispatching...":"Continue highest priority"}),L&&e.jsx("p",{className:"text-caption text-secondary",children:L})]})})]});const P=t.progress===null?null:Math.round(t.progress),k=at(t),p=$[0]??null,ie=(s==null?void 0:s.blockingDecisionCount)??0,Re=Math.max(0,((s==null?void 0:s.decisionCount)??0)-ie),o=Ve({sessionStatus:t.status,sessionPhase:t.phase??null,sessionState:t.state??null,sliceStatus:(s==null?void 0:s.status)??null,activityType:(p==null?void 0:p.type)??null,activityStatus:(typeof(p==null?void 0:p.state)=="string"&&p.state.trim().length>0?p.state:null)??(typeof(p==null?void 0:p.phase)=="string"&&p.phase.trim().length>0?p.phase:null)??(s==null?void 0:s.runtimeState)??null,stopReason:t.blockerReason??((ye=t.blockerDiagnostics)==null?void 0:ye.reason)??((s==null?void 0:s.status)==="failed"?"error":null),decisionRequired:((p==null?void 0:p.decisionRequired)??!1)||ie>0,blockingDecisionCount:ie,nonBlockingDecisionCount:Re,blockerCount:t.blockers.length,blockerReason:t.blockerReason??((ve=t.blockerDiagnostics)==null?void 0:ve.reason)??null}),ae=nt(t,k,S),Te=k==="handoff"?"Handoff":k==="blocked"?"Blocker reason":k==="failed"?"Failure reason":"Status note",$e=o.status==="in_progress"&&["running","active","queued","pending","working","in_progress","planning","review"].includes(k),Se=o.status==="needs_attention"&&["paused","blocked","queued","pending"].includes(k),Be=!["completed","archived","cancelled"].includes(k),Me=!["archived","cancelled"].includes(k),Le=o.label,_e=lt(o.status),ne=["running","active","working","in_progress","planning","review"].includes(k),Ee=o.status!=="in_progress"&&!ne,We=o.tone==="critical"?x.red:o.tone==="warning"?x.amber:o.tone==="positive"?x.lime:x.teal,Ue=P!==null&&P>=100&&o.status!=="completed"?"Terminal state":"Progress",qe=o.tone==="critical"?"border-red-400/25 bg-red-500/10":o.tone==="warning"?"border-amber-400/25 bg-amber-500/10":o.tone==="positive"?"border-lime/22 bg-lime/[0.08]":"border-subtle bg-white/[0.02]",a=t.blockerDiagnostics??null,n=(a==null?void 0:a.context)??null,le=[v(a==null?void 0:a.source)?`Source: ${a.source.trim()}`:null,v(a==null?void 0:a.errorCode)?`Code: ${a.errorCode.trim()}`:null,v(a==null?void 0:a.errorCategory)?`Category: ${a.errorCategory.trim()}`:null,(a==null?void 0:a.retryable)===!0?"Retryable: yes":(a==null?void 0:a.retryable)===!1?"Retryable: no":null].filter(r=>!!r),b=[];n&&(Array.isArray(n.initiativeIds)&&n.initiativeIds.length>0?b.push({label:"Initiatives",value:V(n.initiativeIds.map(r=>B(r)?N(r):r),4)}):v(n.initiativeId)&&b.push({label:"Initiative",value:Ge("Initiative",n.initiativeId.trim())}),v(n.workstreamTitle)?b.push({label:"Workstream",value:n.workstreamTitle.trim()}):Array.isArray(n.workstreamIds)&&n.workstreamIds.length>0?b.push({label:"Workstreams",value:V(n.workstreamIds,4)}):v(n.workstreamId)&&b.push({label:"Workstream",value:n.workstreamId.trim()}),v(n.sliceRunId)&&b.push({label:"Slice run",value:N(n.sliceRunId.trim())}),v(n.parallelMode)&&b.push({label:"Mode",value:n.parallelMode.trim().toUpperCase()}),Array.isArray(n.taskIds)&&n.taskIds.length>0&&b.push({label:"Tasks",value:V(n.taskIds.map(r=>B(r)?N(r):r))}),Array.isArray(n.milestoneIds)&&n.milestoneIds.length>0&&b.push({label:"Milestones",value:V(n.milestoneIds.map(r=>B(r)?N(r):r))}),Array.isArray(n.iwmtIds)&&n.iwmtIds.length>0?b.push({label:"Scope IDs",value:V(n.iwmtIds.map(r=>B(r)?N(r):r),4)}):v(n.iwmtId)&&b.push({label:"Scope ID",value:B(n.iwmtId.trim())?N(n.iwmtId.trim()):n.iwmtId.trim()}),v(n.logPath)&&b.push({label:"Log path",value:Ne(n.logPath.trim())}),v(n.outputPath)&&b.push({label:"Output path",value:Ne(n.outputPath.trim())}));const be=(k==="blocked"||k==="failed")&&!!(a&&(v(a.reason)||le.length>0||b.length>0||Array.isArray(a.suggestedActions)&&a.suggestedActions.length>0)),Z=v(ae)?ae:null,ze=Z!==null&&!(S&&(Z===S||S.includes(Z)))&&!be,Pe=j.useCallback(()=>{!H||!t||(T("Session will be cancelled..."),pe({message:`Cancelled "${t.title}"`,onCommit:async()=>{try{await H(t),T("Session cancelled.")}catch(r){T(r instanceof Error?r.message:"Cancel failed.")}},onUndo:()=>{T(null)}}))},[H,t,pe]),Fe=[{label:"Started",value:t.startedAt?O(t.startedAt):"—"},{label:"Updated",value:t.updatedAt?O(t.updatedAt):"—"},...t.eta?[{label:"ETA",value:t.eta}]:[],...t.checkpointCount?[{label:"Checkpoints",value:String(t.checkpointCount)}]:[]],fe=s?s.status.replace(/_/g," "):null,F=G(s==null?void 0:s.initiativeIds,(s==null?void 0:s.initiativeId)??null),D=G(s==null?void 0:s.workstreamIds,(s==null?void 0:s.workstreamId)??null);G(s==null?void 0:s.iwmtIds,(s==null?void 0:s.iwmtId)??null);const Oe=F[0]?((je=c.find(r=>r.id===F[0]))==null?void 0:je.name)??F[0]:null,ge=L?L.toLowerCase().includes("fail")||L.toLowerCase().includes("error")?"error":u?"pending":"success":null;return e.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[e.jsx("div",{className:"h-[2px] flex-shrink-0",style:ot(o.status)}),e.jsxs("div",{className:"flex items-center justify-between px-5 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("p",{className:"section-kicker",children:"Session Detail"}),e.jsxs("span",{className:M("inline-flex items-center gap-1.5 rounded-full border px-2 py-[1px] text-micro font-semibold uppercase tracking-widest",_e),children:[ne&&e.jsx("span",{className:"h-1.5 w-1.5 rounded-full pulse-soft",style:{backgroundColor:Ie(k)}}),Le]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{onClick:()=>he(r=>!r),className:"text-muted transition-colors hover:text-primary","aria-label":U?"Expand session detail":"Collapse session detail",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:M("transition-transform",U?"-rotate-90":"rotate-0"),children:e.jsx("path",{d:"m6 9 6 6 6-6"})})}),me&&e.jsx("button",{type:"button",onClick:me,"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.jsxs("div",{className:M("transition-all flex flex-col min-h-0",U?"max-h-0 overflow-hidden":"flex-1"),children:[e.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto px-5 py-5 space-y-5",children:[e.jsx(Ze,{mode:"wait",children:e.jsxs(I.div,{variants:dt,initial:"hidden",animate:"visible",exit:"exit",custom:0,children:[e.jsxs("div",{className:"flex items-start gap-3.5",children:[e.jsx(Xe,{name:t.agentName??"OrgX",size:"md",hint:t.agentName}),e.jsxs("div",{className:"min-w-0 flex-1 pt-0.5",children:[e.jsx("h2",{className:"text-[28px] font-medium leading-tight text-white truncate",children:Ke(t.title)}),e.jsxs("p",{className:"mt-1 text-micro uppercase tracking-[0.12em] text-muted",children:[t.agentName??"OrgX"," · ",Ae.label]})]})]}),se.length>0&&e.jsx("div",{className:"mt-3 flex flex-wrap items-center gap-1.5",children:se.map((r,l)=>e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(Qe,{tone:"muted",children:r.value}),l<se.length-1&&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"})})]},`${r.label}-${r.value}`))})]},t.id)}),e.jsx(ue,{}),S&&e.jsxs(I.div,{variants:R,initial:"hidden",animate:"visible",custom:1,children:[e.jsx("p",{className:"section-kicker mb-2",children:"Summary"}),e.jsx(He,{text:S,mode:"block"})]}),e.jsx(I.div,{variants:R,initial:"hidden",animate:"visible",custom:2,children:e.jsxs("div",{className:M("rounded-xl border px-4 py-3",qe),children:[e.jsx("p",{className:"section-kicker mb-1.5",children:o.label}),e.jsx("p",{className:"text-body text-secondary",children:o.sentence}),o.nextAction&&e.jsxs("p",{className:"mt-1.5 flex items-center gap-1 text-caption text-secondary",children:[e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:x.lime,strokeWidth:"2.5",className:"flex-shrink-0",children:e.jsx("path",{d:"m9 18 6-6-6-6"})}),"Next: ",o.nextAction]})]})}),ze&&e.jsx(I.div,{variants:R,initial:"hidden",animate:"visible",custom:3,children:e.jsxs("div",{className:"rounded-xl border border-subtle bg-white/[0.02] px-4 py-3",children:[e.jsx("p",{className:"section-kicker mb-1.5",children:Te}),e.jsx("p",{className:"text-body text-secondary",children:Z})]})}),be&&e.jsx(I.div,{variants:R,initial:"hidden",animate:"visible",custom:3,children:e.jsxs("div",{className:"rounded-xl border border-red-500/25 bg-red-500/10 px-4 py-3",children:[e.jsx("p",{className:"section-kicker mb-1.5 text-red-200/75",children:"Why blocked"}),e.jsx("p",{className:"text-body text-red-100/90",children:(a==null?void 0:a.reason)??ae??"Runtime marked this run as blocked without details."}),le.length>0&&e.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:le.map(r=>e.jsx("span",{className:"rounded-full border border-red-300/25 bg-red-500/10 px-2 py-0.5 text-micro text-red-100/85",children:r},r))}),b.length>0&&e.jsxs("div",{className:"mt-2 rounded-md border border-red-300/20 bg-black/15 p-2.5",children:[e.jsx("p",{className:"mb-1 text-micro uppercase tracking-[0.14em] text-red-200/65",children:"Associated context"}),e.jsx("dl",{className:"grid grid-cols-1 gap-1.5 text-caption text-red-100/85",children:b.map(r=>e.jsxs("div",{className:"grid grid-cols-[86px_1fr] gap-2",children:[e.jsx("dt",{className:"text-red-200/70",children:r.label}),e.jsx("dd",{className:"break-all text-red-50/95",children:r.value})]},r.label))})]}),Array.isArray(a==null?void 0:a.suggestedActions)&&a.suggestedActions.length>0&&e.jsxs("div",{className:"mt-2",children:[e.jsx("p",{className:"mb-1 text-micro uppercase tracking-[0.14em] text-red-200/65",children:"Suggested actions"}),e.jsx("ul",{className:"space-y-1 text-caption text-red-100/85",children:a.suggestedActions.map(r=>e.jsxs("li",{children:["• ",r]},r))})]}),v(a==null?void 0:a.eventTimestamp)&&e.jsxs("p",{className:"mt-2 text-micro text-red-200/60",children:["Last blocker event: ",new Date(a.eventTimestamp).toLocaleString()," ·"," ",O(a.eventTimestamp)]})]})}),e.jsx(ue,{}),e.jsxs(I.div,{variants:R,initial:"hidden",animate:"visible",custom:4,children:[P!==null&&e.jsxs("div",{className:"mb-3",children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between text-caption text-secondary",children:[e.jsx("span",{children:Ue}),e.jsxs("span",{className:"text-primary",children:[P,"%"]})]}),e.jsx("div",{className:"h-[3px] rounded-full bg-white/[0.08]",children:e.jsx(I.div,{className:M("h-[3px] rounded-full",ne&&"live-pulse"),style:{background:We},initial:{width:0},animate:{width:`${P}%`},transition:{duration:.5,ease:Je.easingStandard}})})]}),e.jsx("dl",{className:"grid grid-cols-2 gap-3 text-caption text-secondary",children:Fe.map(r=>e.jsxs("div",{children:[e.jsx("dt",{className:"text-muted",children:r.label}),e.jsx("dd",{className:"text-body font-semibold text-white",children:r.value})]},r.label))})]}),s&&e.jsx(I.div,{variants:R,initial:"hidden",animate:"visible",custom:5,children:e.jsxs("div",{className:"rounded-xl border border-subtle bg-white/[0.02] px-4 py-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"section-kicker",children:"Slice scope"}),fe?e.jsx("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-2 py-0.5 text-micro font-semibold uppercase tracking-[0.08em] text-secondary",children:fe}):null]}),s.statusExplainer?e.jsx("p",{className:"mt-2 text-caption text-secondary",children:s.statusExplainer}):null,e.jsxs("dl",{className:"mt-2 grid grid-cols-2 gap-2 text-caption text-secondary",children:[e.jsxs("div",{children:[e.jsx("dt",{className:"text-muted",children:"Initiative"}),e.jsx("dd",{className:"text-body font-semibold text-white",children:Oe??"—"})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-muted",children:"Workstream"}),e.jsx("dd",{className:"text-body font-semibold text-white",children:s.workstreamTitle??(D[0]?N(D[0]):"—")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-muted",children:"Run"}),e.jsx("dd",{className:"break-all text-body font-semibold text-white",children:N(s.runId??s.sliceRunId)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-muted",children:"Updated"}),e.jsx("dd",{className:"text-body font-semibold text-white",children:s.updatedAt?O(s.updatedAt):"—"})]})]}),e.jsxs("div",{className:"mt-2 flex flex-wrap gap-1.5 text-micro",children:[e.jsxs("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-2 py-0.5 text-secondary",children:["Tasks ",s.taskIds.length]}),e.jsxs("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-2 py-0.5 text-secondary",children:["Milestones ",s.milestoneIds.length]}),e.jsxs("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-2 py-0.5 text-secondary",children:["Artifacts ",s.artifactCount]}),e.jsxs("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-2 py-0.5 text-secondary",children:["Needs input ",s.blockingDecisionCount]}),F.length>1?e.jsxs("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-2 py-0.5 text-secondary",children:["+",F.length-1," initiatives"]}):null,D.length>1?e.jsxs("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-2 py-0.5 text-secondary",children:["+",D.length-1," workstreams"]}):null]}),s.taskIds.length>0?e.jsxs("p",{className:"mt-2 text-micro text-secondary",children:["Tasks: ",s.taskIds.length]}):null]})}),t.blockers.length>0&&e.jsx(I.div,{variants:R,initial:"hidden",animate:"visible",custom:6,children:e.jsxs("div",{className:"rounded-xl border border-red-500/30 bg-red-500/10 px-4 py-3",children:[e.jsx("p",{className:"section-kicker mb-2 text-red-200/70",children:"Blockers"}),e.jsx("ul",{className:"space-y-1 text-body text-red-100/90",children:t.blockers.map(r=>e.jsxs("li",{children:["• ",r]},r))})]})}),e.jsx(ue,{}),e.jsxs(I.div,{variants:R,initial:"hidden",animate:"visible",custom:7,children:[e.jsx("p",{className:"section-kicker mb-4",children:"Recent Messages"}),$.length===0&&e.jsx("p",{className:"text-body text-secondary",children:"No recent messages for this run."}),e.jsx("div",{className:"relative border-l border-white/[0.06] pl-6 ml-1 space-y-3",children:$.map((r,l)=>e.jsxs(I.div,{className:"relative group",variants:R,initial:"hidden",animate:"visible",custom:l,children:[e.jsx("div",{className:"absolute -left-[27px] top-1.5 h-2 w-2 rounded-full border border-black ring-4 ring-black",style:{backgroundColor:Ie(r.type??r.state??"unknown")}}),e.jsxs("article",{className:"rounded-lg border border-subtle bg-white/[0.02] px-3 py-2.5 transition-colors hover:bg-white/[0.04]",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsx("p",{className:"min-w-0 flex-1 text-caption text-bright",children:r.title}),w&&e.jsx("button",{type:"button",onClick:()=>w(r),className:"flex-shrink-0 rounded-full border border-strong bg-white/[0.03] px-2.5 py-0.5 text-micro font-semibold text-secondary opacity-0 transition-all group-hover:opacity-100 hover:bg-white/[0.08] hover:text-primary",children:"Open"})]}),(r.summary||r.description)&&e.jsx("p",{className:"mt-0.5 line-clamp-2 text-caption text-secondary",children:r.summary??r.description}),e.jsxs("p",{className:"mt-1 text-micro text-muted",children:[new Date(r.timestamp).toLocaleString()," · ",O(r.timestamp)]})]})]},r.id))})]})]}),e.jsxs("div",{className:"flex-shrink-0 border-t border-subtle px-5 py-3 space-y-3",children:[L&&e.jsx("p",{className:M("rounded-md border px-2.5 py-1.5 text-caption",ge==="error"?"border-red-400/30 bg-red-500/10 text-red-200":ge==="pending"?"border-white/[0.08] bg-white/[0.02] text-secondary pulse-soft":"border-lime/25 bg-lime/[0.08] text-lime"),children:L}),te&&e.jsx("div",{children:e.jsx("textarea",{value:re,onChange:r=>z(r.target.value),placeholder:"Share guidance for this run...",rows:2,className:"w-full resize-none rounded-lg border border-white/[0.10] bg-white/[0.03] px-3 py-2 text-body text-bright outline-none placeholder:text-faint focus:border-white/20"})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[$e&&e.jsx("button",{onClick:()=>_("pause-session","Session paused",()=>K==null?void 0:K(t)),disabled:!K||!!u,className:"rounded-md px-2.5 py-1.5 text-caption font-medium text-secondary hover:bg-white/[0.04] hover:text-white disabled:opacity-45 transition-colors",children:u==="pause-session"?"Pausing...":"Pause"}),Se&&e.jsx("button",{onClick:()=>_("resume-session","Session resumed",()=>Q==null?void 0:Q(t)),disabled:!Q||!!u,className:"rounded-md px-2.5 py-1.5 text-caption font-medium text-secondary hover:bg-white/[0.04] hover:text-white disabled:opacity-45 transition-colors",children:u==="resume-session"?"Resuming...":"Resume"}),e.jsx("button",{onClick:()=>_("checkpoint-session","Progress saved",()=>J==null?void 0:J(t)),disabled:!J||!!u,className:"rounded-md px-2.5 py-1.5 text-caption font-medium text-secondary hover:bg-white/[0.04] hover:text-white disabled:opacity-45 transition-colors",children:u==="checkpoint-session"?"Saving...":"Save"}),Me&&e.jsx("button",{onClick:()=>_("rollback-session","Undo requested",()=>Y==null?void 0:Y(t)),disabled:!Y||!!u,className:"rounded-md px-2.5 py-1.5 text-caption font-medium text-secondary hover:bg-white/[0.04] hover:text-white disabled:opacity-45 transition-colors",children:u==="rollback-session"?"Undoing...":"Undo"}),Be&&H&&e.jsx("button",{onClick:Pe,disabled:!!u,className:"rounded-md px-2.5 py-1.5 text-caption font-medium text-red-400/70 hover:bg-red-500/[0.08] hover:text-red-300 disabled:opacity-45 transition-colors",children:"Cancel"})]}),e.jsx("div",{className:"flex-1"}),te&&e.jsx("button",{type:"button",onClick:()=>{const r=re.trim();if(!r){T("Intervention note cannot be empty.");return}_("intervene-note","Intervention sent",async()=>{await te({session:t,workstreamId:(C==null?void 0:C.workstreamId)??t.workstreamId??null,text:r}),z("")})},disabled:!!u||re.trim().length===0,className:"rounded-md 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] disabled:opacity-45",children:u==="intervene-note"?"Sending...":"Intervene"}),e.jsxs("button",{onClick:()=>_("dispatch-session","Session started",()=>X==null?void 0:X(t)),disabled:!X||!!u||!Ee,className:"inline-flex h-8 items-center gap-1.5 rounded-lg border border-lime/25 bg-lime/10 px-4 text-caption font-semibold text-lime transition-colors hover:bg-lime/20 disabled:opacity-45",children:[e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",className:"flex-shrink-0",children:e.jsx("path",{d:"M8 5v14l11-7z"})}),u==="dispatch-session"?"Starting...":o.status==="completed"?"Restart":"Start"]})]})]})]}),e.jsx(Ce,{})]})});export{vt as SessionInspector};