@useorgx/openclaw-plugin 0.7.0 → 0.7.3

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 (124) hide show
  1. package/README.md +42 -11
  2. package/dashboard/dist/assets/6mILZQ2a.js +1 -0
  3. package/dashboard/dist/assets/6mILZQ2a.js.br +0 -0
  4. package/dashboard/dist/assets/6mILZQ2a.js.gz +0 -0
  5. package/dashboard/dist/assets/{DG6y9wJI.js → 8dksYiq4.js} +1 -1
  6. package/dashboard/dist/assets/8dksYiq4.js.br +0 -0
  7. package/dashboard/dist/assets/8dksYiq4.js.gz +0 -0
  8. package/dashboard/dist/assets/{PAUiij_z.js → B5zYRHc3.js} +1 -1
  9. package/dashboard/dist/assets/B5zYRHc3.js.br +0 -0
  10. package/dashboard/dist/assets/B5zYRHc3.js.gz +0 -0
  11. package/dashboard/dist/assets/{CFGKRAzG.js → B6wPWJ35.js} +1 -1
  12. package/dashboard/dist/assets/B6wPWJ35.js.br +0 -0
  13. package/dashboard/dist/assets/B6wPWJ35.js.gz +0 -0
  14. package/dashboard/dist/assets/BWEwjt1W.js +1 -0
  15. package/dashboard/dist/assets/BWEwjt1W.js.br +0 -0
  16. package/dashboard/dist/assets/BWEwjt1W.js.gz +0 -0
  17. package/dashboard/dist/assets/BzRbDCAD.css +1 -0
  18. package/dashboard/dist/assets/BzRbDCAD.css.br +0 -0
  19. package/dashboard/dist/assets/BzRbDCAD.css.gz +0 -0
  20. package/dashboard/dist/assets/{DNxKz-GV.js → C8uM3AX8.js} +1 -1
  21. package/dashboard/dist/assets/C8uM3AX8.js.br +0 -0
  22. package/dashboard/dist/assets/C8uM3AX8.js.gz +0 -0
  23. package/dashboard/dist/assets/C9jy61eu.js +212 -0
  24. package/dashboard/dist/assets/C9jy61eu.js.br +0 -0
  25. package/dashboard/dist/assets/C9jy61eu.js.gz +0 -0
  26. package/dashboard/dist/assets/{CE38zU4U.js → CC63EwFD.js} +1 -1
  27. package/dashboard/dist/assets/CC63EwFD.js.br +0 -0
  28. package/dashboard/dist/assets/CC63EwFD.js.gz +0 -0
  29. package/dashboard/dist/assets/{nByHNHoW.js → CZaT3ob_.js} +1 -1
  30. package/dashboard/dist/assets/CZaT3ob_.js.br +0 -0
  31. package/dashboard/dist/assets/CZaT3ob_.js.gz +0 -0
  32. package/dashboard/dist/assets/{tS9mbYZi.js → CgaottFX.js} +1 -1
  33. package/dashboard/dist/assets/CgaottFX.js.br +0 -0
  34. package/dashboard/dist/assets/CgaottFX.js.gz +0 -0
  35. package/dashboard/dist/assets/CzCxAZlW.js +1 -0
  36. package/dashboard/dist/assets/CzCxAZlW.js.br +0 -0
  37. package/dashboard/dist/assets/CzCxAZlW.js.gz +0 -0
  38. package/dashboard/dist/assets/D3iMTYEj.js +1 -0
  39. package/dashboard/dist/assets/D3iMTYEj.js.br +0 -0
  40. package/dashboard/dist/assets/D3iMTYEj.js.gz +0 -0
  41. package/dashboard/dist/assets/{DjcdE6jC.js → D8JNX8kq.js} +1 -1
  42. package/dashboard/dist/assets/D8JNX8kq.js.br +0 -0
  43. package/dashboard/dist/assets/D8JNX8kq.js.gz +0 -0
  44. package/dashboard/dist/assets/DnA8dpj6.js +1 -0
  45. package/dashboard/dist/assets/DnA8dpj6.js.br +0 -0
  46. package/dashboard/dist/assets/DnA8dpj6.js.gz +0 -0
  47. package/dashboard/dist/assets/{DbNoijHm.js → IUexzymk.js} +1 -1
  48. package/dashboard/dist/assets/IUexzymk.js.br +0 -0
  49. package/dashboard/dist/assets/IUexzymk.js.gz +0 -0
  50. package/dashboard/dist/assets/{CZZTvkQZ.js → rttbDbEx.js} +1 -1
  51. package/dashboard/dist/assets/rttbDbEx.js.br +0 -0
  52. package/dashboard/dist/assets/rttbDbEx.js.gz +0 -0
  53. package/dashboard/dist/index.html +2 -2
  54. package/dashboard/dist/index.html.br +0 -0
  55. package/dashboard/dist/index.html.gz +0 -0
  56. package/dist/contracts/practice-exercise-schema.d.ts +216 -0
  57. package/dist/contracts/practice-exercise-schema.js +314 -0
  58. package/dist/contracts/shared-types.d.ts +2 -2
  59. package/dist/contracts/shared-types.js +22 -0
  60. package/dist/contracts/types.d.ts +20 -0
  61. package/dist/fs-utils.js +1 -13
  62. package/dist/http/helpers/auto-continue-engine.js +638 -24
  63. package/dist/http/helpers/autopilot-runtime.js +22 -7
  64. package/dist/http/helpers/autopilot-slice-utils.js +0 -2
  65. package/dist/http/helpers/kickoff-context.js +30 -0
  66. package/dist/http/helpers/slice-run-projections.js +19 -2
  67. package/dist/http/index.js +151 -93
  68. package/dist/http/routes/agent-suite.js +87 -0
  69. package/dist/http/routes/entities.js +1 -63
  70. package/dist/http/routes/live-snapshot.d.ts +1 -0
  71. package/dist/http/routes/live-snapshot.js +15 -4
  72. package/dist/http/routes/live-terminal.js +1 -108
  73. package/dist/http/routes/live-triage.js +1 -57
  74. package/dist/http/routes/mission-control-actions.js +0 -88
  75. package/dist/http/routes/mission-control-read.js +73 -8
  76. package/dist/mcp-http-handler.d.ts +3 -0
  77. package/dist/mcp-http-handler.js +2 -2
  78. package/dist/openclaw.plugin.json +1 -1
  79. package/dist/paths.js +14 -2
  80. package/dist/reporting/rollups.d.ts +0 -12
  81. package/dist/reporting/rollups.js +0 -35
  82. package/openclaw.plugin.json +1 -1
  83. package/package.json +7 -3
  84. package/dashboard/dist/assets/BXWDRGm-.js +0 -1
  85. package/dashboard/dist/assets/BXWDRGm-.js.br +0 -0
  86. package/dashboard/dist/assets/BXWDRGm-.js.gz +0 -0
  87. package/dashboard/dist/assets/CE38zU4U.js.br +0 -0
  88. package/dashboard/dist/assets/CE38zU4U.js.gz +0 -0
  89. package/dashboard/dist/assets/CFGKRAzG.js.br +0 -0
  90. package/dashboard/dist/assets/CFGKRAzG.js.gz +0 -0
  91. package/dashboard/dist/assets/CGGR2GZh.js +0 -1
  92. package/dashboard/dist/assets/CGGR2GZh.js.br +0 -0
  93. package/dashboard/dist/assets/CGGR2GZh.js.gz +0 -0
  94. package/dashboard/dist/assets/CPFiTmlw.js +0 -8
  95. package/dashboard/dist/assets/CPFiTmlw.js.br +0 -0
  96. package/dashboard/dist/assets/CPFiTmlw.js.gz +0 -0
  97. package/dashboard/dist/assets/CZZTvkQZ.js.br +0 -0
  98. package/dashboard/dist/assets/CZZTvkQZ.js.gz +0 -0
  99. package/dashboard/dist/assets/D-bf6hEI.js +0 -213
  100. package/dashboard/dist/assets/D-bf6hEI.js.br +0 -0
  101. package/dashboard/dist/assets/D-bf6hEI.js.gz +0 -0
  102. package/dashboard/dist/assets/DG6y9wJI.js.br +0 -0
  103. package/dashboard/dist/assets/DG6y9wJI.js.gz +0 -0
  104. package/dashboard/dist/assets/DNxKz-GV.js.br +0 -0
  105. package/dashboard/dist/assets/DNxKz-GV.js.gz +0 -0
  106. package/dashboard/dist/assets/DW_rKUic.js +0 -11
  107. package/dashboard/dist/assets/DW_rKUic.js.br +0 -0
  108. package/dashboard/dist/assets/DW_rKUic.js.gz +0 -0
  109. package/dashboard/dist/assets/DbNoijHm.js.br +0 -0
  110. package/dashboard/dist/assets/DbNoijHm.js.gz +0 -0
  111. package/dashboard/dist/assets/DjcdE6jC.js.br +0 -0
  112. package/dashboard/dist/assets/DjcdE6jC.js.gz +0 -0
  113. package/dashboard/dist/assets/FZYuCDnt.js +0 -1
  114. package/dashboard/dist/assets/FZYuCDnt.js.br +0 -0
  115. package/dashboard/dist/assets/FZYuCDnt.js.gz +0 -0
  116. package/dashboard/dist/assets/PAUiij_z.js.br +0 -0
  117. package/dashboard/dist/assets/PAUiij_z.js.gz +0 -0
  118. package/dashboard/dist/assets/h5biQs2I.css +0 -1
  119. package/dashboard/dist/assets/h5biQs2I.css.br +0 -0
  120. package/dashboard/dist/assets/h5biQs2I.css.gz +0 -0
  121. package/dashboard/dist/assets/nByHNHoW.js.br +0 -0
  122. package/dashboard/dist/assets/nByHNHoW.js.gz +0 -0
  123. package/dashboard/dist/assets/tS9mbYZi.js.br +0 -0
  124. package/dashboard/dist/assets/tS9mbYZi.js.gz +0 -0
@@ -1 +1 @@
1
- import{r as w,j as e}from"./cNrhgGc1.js";import{y as T,z as N,F as ye,P as we,w as S,G as qe,d as Z,H as ze,J as je,K as q,L as Pe,x as Fe,M as Oe}from"./D-bf6hEI.js";import{u as Ve}from"./CFGKRAzG.js";import"./C-KIc3Wc.js";import"./BJgZIVUQ.js";import"./CxQ08qFN.js";const Ge=/^[0-9a-f-]{20,}$/i,Ke=new Set(["running","active","queued","pending","in_progress","working","planning","handoff","review"]),He=new Set(["agent execution failed","execution failed","run failed","failed"]);function y(n){return typeof n=="string"&&n.trim().length>0}function le(n){return(n??"").trim().toLowerCase()}function Je(n){return(n??"").trim().replace(/\s+/g," ").toLowerCase()}function Xe(n){return He.has(Je(n))}function z(n,t=3){return n.length<=t?n.join(", "):`${n.slice(0,t).join(", ")} +${n.length-t} more`}function P(n,t){const b=[],o=m=>{if(typeof m!="string")return;const j=m.trim();j&&(b.some(L=>L.toLowerCase()===j.toLowerCase())||b.push(j))};if(Array.isArray(n))for(const m of n)o(m);return o(t??null),b}function Qe(n){if(n.runId&&n.runId.trim().length>0)return n.runId.trim();const t=n.metadata;if(!t)return null;const b=["slice_run_id","sliceRunId","runId","run_id","correlation_id","correlationId","sessionId","session_id","agentRunId"];for(const o of b){const m=t[o];if(typeof m=="string"&&m.trim().length>0)return m.trim()}return null}function Ye(n){const t=le(n.status);if(t==="blocked"||t==="failed"||t==="completed"||t==="cancelled")return t;const b=le(n.phase);if(b==="blocked")return"blocked";if(b==="handoff")return"handoff";if(b==="completed")return"completed";if(b==="review")return"review";const o=le(n.state);return o==="error"?"failed":o==="stopped"?"paused":o==="stale"?"queued":Ke.has(t)?t:n.blockers.length>0?"blocked":t||"unknown"}function Ze(n,t,b){var m;const o=[((m=n.blockerDiagnostics)==null?void 0:m.reason)??null,n.blockerReason??null,...n.blockers,t==="blocked"||t==="failed"||t==="handoff"?b:null].map(j=>typeof j=="string"?j.trim():"").filter(j=>j.length>0);return o.length>0?o.find(L=>!Xe(L))??o[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 De(n){return n==="completed"?"border-lime/25 bg-lime/[0.08] text-lime":n==="needs_attention"?"border-amber-400/30 bg-amber-400/10 text-amber-200":n==="failed"?"border-red-400/30 bg-red-500/10 text-red-200":n==="in_progress"?"border-teal-400/30 bg-teal-400/10 text-teal-200":"border-strong bg-white/[0.04] text-secondary"}const dt=w.memo(function({session:t,activity:b,initiatives:o=[],sliceRuns:m=[],onOpenActivityItem:j,onContinueHighestPriority:L,onDispatchSession:F,onPauseSession:O,onResumeSession:V,onCancelSession:G,onCreateCheckpoint:K,onRollbackSession:H,onStartInitiative:et,onStartWorkstream:tt,initialInterventionDraft:k=null,onSubmitIntervention:ie}){var he,be,ge;const[x,de]=w.useState(null),[J,A]=w.useState(null),[M,oe]=w.useState(!1),[D,W]=w.useState(""),{enqueue:ce,ToastRenderer:ve}=Ve();w.useEffect(()=>{if(!t){W("");return}if(k!=null&&k.text){W(k.text);return}W("")},[k==null?void 0:k.text,t==null?void 0:t.id]);const B=w.useMemo(()=>{var d,g,f,i,u;if(!t)return new Set;const r=new Set;return(d=t.runId)!=null&&d.trim()&&r.add(t.runId.trim()),(g=t.id)!=null&&g.trim()&&r.add(t.id.trim()),(u=(i=(f=t.blockerDiagnostics)==null?void 0:f.context)==null?void 0:i.sliceRunId)!=null&&u.trim()&&r.add(t.blockerDiagnostics.context.sliceRunId.trim()),r},[t]),C=w.useMemo(()=>t?B.size===0?[]:b.filter(r=>{const d=Qe(r);return!!(d&&B.has(d))}).sort((r,d)=>Date.parse(d.timestamp)-Date.parse(r.timestamp)).slice(0,12):[],[b,t,B]),s=w.useMemo(()=>{var f,i;if(!t||!Array.isArray(m)||m.length===0)return null;const r=((f=t.initiativeId)==null?void 0:f.trim())??"",d=((i=t.workstreamId)==null?void 0:i.trim())??"",g=m.filter(u=>{var ne,fe;const I=((ne=u.sliceRunId)==null?void 0:ne.trim())??"",E=((fe=u.runId)==null?void 0:fe.trim())??"";if(I&&B.has(I)||E&&B.has(E))return!0;if(!d||!P(u.workstreamIds,u.workstreamId).includes(d))return!1;if(!r)return!0;const Y=P(u.initiativeIds,u.initiativeId);return!(Y.length>0&&!Y.includes(r))});return g.length===0?null:[...g].sort((u,I)=>{const E=Date.parse(u.updatedAt??u.lastEventAt??u.startedAt??""),ae=Date.parse(I.updatedAt??I.lastEventAt??I.startedAt??""),Y=Number.isFinite(E)?E:0;return(Number.isFinite(ae)?ae:0)-Y})[0]},[t,B,m]),ee=w.useMemo(()=>{var f;if(!t)return[];const r=[],d=t.initiativeId??t.groupId;if(d){const i=o.find(u=>u.id===d);i?r.push({label:"Initiative",value:i.name}):t.groupLabel&&t.groupLabel.trim().length>0?r.push({label:"Initiative",value:t.groupLabel}):T(d)&&r.push({label:"Initiative",value:N(d)})}if(t.workstreamId){let i=null;for(const u of o){const I=(f=u.workstreams)==null?void 0:f.find(E=>E.id===t.workstreamId);if(I){i=I.name;break}}!i&&T(t.workstreamId)?i=N(t.workstreamId):!i&&!Ge.test(t.workstreamId)&&(i=t.workstreamId),i&&r.push({label:"Workstream",value:i})}const g=t.phase??null;if(g){const i=String(g);r.push({label:"Milestone",value:T(i)?N(i):i})}return t.title&&r.push({label:"Task",value:t.title}),r},[o,t]),R=w.useMemo(()=>{var f,i;if(!t)return null;const r=((f=C[0])==null?void 0:f.summary)??((i=C[0])==null?void 0:i.description)??null,g=t.lastEventSummary??r??null;return g&&g.trim().length>0?g.trim():null},[C,t]),ue=w.useMemo(()=>{var r;return t?ye(t.agentName,t.title,t.lastEventSummary,R,(r=C[0])==null?void 0:r.metadata):ye()},[C,t,R]),_=async(r,d,g)=>{if(!(!g||x)){de(r),A(null);try{await g(),A(`${d} requested.`)}catch(f){A(f instanceof Error?f.message:`${d} failed.`)}finally{de(null)}}};if(!t)return e.jsxs(we,{className:"flex h-full min-h-0 flex-col overflow-hidden card-enter",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-subtle px-4 py-3.5",children:[e.jsx("h2",{className:"text-heading font-semibold text-white",children:"Session Detail"}),e.jsx("button",{onClick:()=>oe(r=>!r),className:"text-muted transition-colors hover:text-primary","aria-label":M?"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:S("transition-transform",M?"-rotate-90":"rotate-0"),children:e.jsx("path",{d:"m6 9 6 6 6-6"})})})]}),e.jsx("div",{className:S("transition-all",M?"max-h-0 overflow-hidden":"min-h-0 flex-1"),children:e.jsxs("div",{className:"h-full min-h-0 space-y-2 overflow-y-auto p-4 text-body text-secondary",children:[e.jsx("p",{children:"Select a session to inspect summary, breadcrumbs, blockers, and recent messages."}),e.jsx("button",{onClick:()=>_("continue-priority","Continue highest priority",L),disabled:!L||!!x,className:"rounded-md border border-strong bg-white/[0.04] px-3 py-1.5 text-caption text-primary transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:x==="continue-priority"?"Dispatching…":"Continue highest priority"}),J&&e.jsx("p",{className:"text-caption text-secondary",children:J})]})})]});const U=t.progress===null?null:Math.round(t.progress),v=Ye(t),p=C[0]??null,te=(s==null?void 0:s.blockingDecisionCount)??0,Ne=Math.max(0,((s==null?void 0:s.decisionCount)??0)-te),c=qe({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??((he=t.blockerDiagnostics)==null?void 0:he.reason)??((s==null?void 0:s.status)==="failed"?"error":null),decisionRequired:((p==null?void 0:p.decisionRequired)??!1)||te>0,blockingDecisionCount:te,nonBlockingDecisionCount:Ne,blockerCount:t.blockers.length,blockerReason:t.blockerReason??((be=t.blockerDiagnostics)==null?void 0:be.reason)??null}),re=Ze(t,v,R),ke=v==="handoff"?"Handoff":v==="blocked"?"Blocker reason":v==="failed"?"Failure reason":"Status note",Ie=c.status==="in_progress"&&["running","active","queued","pending","working","in_progress","planning","review"].includes(v),Ae=c.status==="needs_attention"&&["paused","blocked","queued","pending"].includes(v),Ce=!["completed","archived","cancelled"].includes(v),Re=!["archived","cancelled"].includes(v),Te=c.label,Se=De(c.status),me=["running","active","working","in_progress","planning","review"].includes(v),_e=c.status!=="in_progress"&&!me,Ee=c.tone==="critical"?Z.red:c.tone==="warning"?Z.amber:c.tone==="positive"?Z.lime:Z.teal,Le=U!==null&&U>=100&&c.status!=="completed"?"Terminal state":"Progress",Me=c.tone==="critical"?"border-red-400/25 bg-red-500/10":c.tone==="warning"?"border-amber-400/25 bg-amber-500/10":c.tone==="positive"?"border-lime/22 bg-lime/[0.08]":"border-subtle bg-white/[0.02]",a=t.blockerDiagnostics??null,l=(a==null?void 0:a.context)??null,se=[y(a==null?void 0:a.source)?`Source: ${a.source.trim()}`:null,y(a==null?void 0:a.errorCode)?`Code: ${a.errorCode.trim()}`:null,y(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),h=[];l&&(Array.isArray(l.initiativeIds)&&l.initiativeIds.length>0?h.push({label:"Initiatives",value:z(l.initiativeIds.map(r=>T(r)?N(r):r),4)}):y(l.initiativeId)&&h.push({label:"Initiative",value:ze("Initiative",l.initiativeId.trim())}),y(l.workstreamTitle)?h.push({label:"Workstream",value:l.workstreamTitle.trim()}):Array.isArray(l.workstreamIds)&&l.workstreamIds.length>0?h.push({label:"Workstreams",value:z(l.workstreamIds,4)}):y(l.workstreamId)&&h.push({label:"Workstream",value:l.workstreamId.trim()}),y(l.sliceRunId)&&h.push({label:"Slice run",value:N(l.sliceRunId.trim())}),y(l.parallelMode)&&h.push({label:"Mode",value:l.parallelMode.trim().toUpperCase()}),Array.isArray(l.taskIds)&&l.taskIds.length>0&&h.push({label:"Tasks",value:z(l.taskIds.map(r=>T(r)?N(r):r))}),Array.isArray(l.milestoneIds)&&l.milestoneIds.length>0&&h.push({label:"Milestones",value:z(l.milestoneIds.map(r=>T(r)?N(r):r))}),Array.isArray(l.iwmtIds)&&l.iwmtIds.length>0?h.push({label:"Scope IDs",value:z(l.iwmtIds.map(r=>T(r)?N(r):r),4)}):y(l.iwmtId)&&h.push({label:"Scope ID",value:T(l.iwmtId.trim())?N(l.iwmtId.trim()):l.iwmtId.trim()}),y(l.logPath)&&h.push({label:"Log path",value:je(l.logPath.trim())}),y(l.outputPath)&&h.push({label:"Output path",value:je(l.outputPath.trim())}));const xe=(v==="blocked"||v==="failed")&&!!(a&&(y(a.reason)||se.length>0||h.length>0||Array.isArray(a.suggestedActions)&&a.suggestedActions.length>0)),X=y(re)?re:null,Be=X!==null&&!(R&&(X===R||R.includes(X)))&&!xe,Ue=w.useCallback(()=>{!G||!t||(A("Session will be cancelled…"),ce({message:`Cancelled "${t.title}"`,onCommit:async()=>{try{await G(t),A("Session cancelled.")}catch(r){A(r instanceof Error?r.message:"Cancel failed.")}},onUndo:()=>{A(null)}}))},[G,t,ce]),We=[{label:"Started",value:t.startedAt?q(t.startedAt):"—"},{label:"Updated",value:t.updatedAt?q(t.updatedAt):"—"},...t.eta?[{label:"ETA",value:t.eta}]:[],...t.checkpointCount?[{label:"Checkpoints",value:String(t.checkpointCount)}]:[]],pe=s?s.status.replace(/_/g," "):null,$=P(s==null?void 0:s.initiativeIds,(s==null?void 0:s.initiativeId)??null),Q=P(s==null?void 0:s.workstreamIds,(s==null?void 0:s.workstreamId)??null);P(s==null?void 0:s.iwmtIds,(s==null?void 0:s.iwmtId)??null);const $e=$[0]?((ge=o.find(r=>r.id===$[0]))==null?void 0:ge.name)??$[0]:null;return e.jsxs(we,{className:"flex h-full min-h-0 flex-col overflow-hidden card-enter",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-subtle px-4 py-3.5",children:[e.jsx("h2",{className:"text-heading font-semibold text-white",children:"Session Detail"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:S("chip text-caption uppercase tracking-[0.14em]",Se),children:Te}),e.jsx("button",{onClick:()=>oe(r=>!r),className:"text-muted transition-colors hover:text-primary","aria-label":M?"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:S("transition-transform",M?"-rotate-90":"rotate-0"),children:e.jsx("path",{d:"m6 9 6 6 6-6"})})})]})]}),e.jsx("div",{className:S("transition-all",M?"max-h-0 overflow-hidden":"min-h-0 flex-1"),children:e.jsxs("div",{className:"h-full min-h-0 space-y-4 overflow-y-auto p-4",children:[e.jsxs("div",{className:"rounded-xl border border-subtle bg-white/[0.02] p-3",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Pe,{provider:ue.id,size:"sm"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-body font-semibold text-white",children:Fe(t.title)}),e.jsxs("p",{className:"mt-1 text-caption text-secondary",children:[t.agentName??"OrgX"," · ",ue.label]})]})]}),ee.length>0&&e.jsxs("div",{className:"mt-3",children:[e.jsx("p",{className:"mb-1 text-micro uppercase tracking-[0.16em] text-muted",children:"Context"}),e.jsx("div",{className:"flex flex-wrap items-center gap-1.5 text-caption",children:ee.map((r,d)=>e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{className:"rounded-full border border-strong bg-white/[0.02] px-2 py-0.5 text-secondary",children:r.value}),d<ee.length-1&&e.jsx("span",{className:"text-caption text-muted",children:"›"})]},`${r.label}-${r.value}`))})]}),R&&e.jsxs("div",{className:"mt-3 rounded-lg border border-subtle bg-white/[0.02] px-3 py-2",children:[e.jsx("p",{className:"mb-1 text-micro uppercase tracking-[0.16em] text-muted",children:"Summary"}),e.jsx(Oe,{text:R,mode:"block"})]}),e.jsxs("div",{className:S("mt-3 rounded-lg border px-3 py-2",Me),children:[e.jsx("p",{className:"mb-1 text-micro uppercase tracking-[0.16em] text-muted",children:c.label}),e.jsx("p",{className:"text-body text-secondary",children:c.sentence}),c.nextAction&&e.jsxs("p",{className:"mt-1 text-caption text-secondary",children:["Next: ",c.nextAction]})]}),Be&&e.jsxs("div",{className:"mt-3 rounded-lg border border-subtle bg-white/[0.02] px-3 py-2",children:[e.jsx("p",{className:"mb-1 text-micro uppercase tracking-[0.16em] text-muted",children:ke}),e.jsx("p",{className:"text-body text-secondary",children:X})]}),xe&&e.jsxs("div",{className:"mt-3 rounded-lg border border-red-500/25 bg-red-500/10 px-3 py-2.5",children:[e.jsx("p",{className:"mb-1 text-micro uppercase tracking-[0.16em] text-red-200/75",children:"Why blocked"}),e.jsx("p",{className:"text-body text-red-100/90",children:(a==null?void 0:a.reason)??re??"Runtime marked this run as blocked without details."}),se.length>0&&e.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:se.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))}),h.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:h.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))})]}),y(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()," ·"," ",q(a.eventTimestamp)]})]})]}),s&&e.jsxs("div",{className:"rounded-xl border border-subtle bg-white/[0.02] p-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("h3",{className:"text-caption uppercase tracking-[0.12em] text-secondary",children:"Slice scope"}),pe?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:pe}):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:$e??"—"})]}),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??(Q[0]?N(Q[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?q(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]}),$.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:["+",$.length-1," initiatives"]}):null,Q.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:["+",Q.length-1," workstreams"]}):null]}),s.taskIds.length>0?e.jsxs("p",{className:"mt-2 text-micro text-secondary",children:["Tasks: ",s.taskIds.length]}):null]}),e.jsxs("div",{className:"rounded-xl border border-subtle bg-white/[0.02] p-3",children:[U!==null&&e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between text-caption text-secondary",children:[e.jsx("span",{children:Le}),e.jsxs("span",{className:"text-primary",children:[U,"%"]})]}),e.jsx("div",{className:"h-2 rounded-full bg-white/[0.08]",children:e.jsx("div",{className:S("h-2 rounded-full transition-all duration-500",me&&"live-pulse"),style:{width:`${U}%`,background:Ee}})})]}),e.jsx("dl",{className:S("grid grid-cols-2 gap-3 text-caption text-secondary",U!==null?"mt-3":""),children:We.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))})]}),e.jsxs("div",{className:"rounded-xl border border-subtle bg-white/[0.02] p-3",children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{onClick:()=>_("dispatch-session","Session started",()=>F==null?void 0:F(t)),disabled:!F||!!x||!_e,className:"rounded-md border border-lime/25 bg-lime/10 px-3 py-2 text-caption font-semibold text-lime transition-colors hover:bg-lime/20 disabled:opacity-45",children:x==="dispatch-session"?"Starting…":c.status==="completed"?"Restart":"Start"}),Ie&&e.jsx("button",{onClick:()=>_("pause-session","Session paused",()=>O==null?void 0:O(t)),disabled:!O||!!x,className:"rounded-md border border-strong bg-white/[0.02] px-3 py-2 text-caption text-secondary transition-colors hover:bg-white/[0.06] hover:text-white disabled:opacity-45",children:x==="pause-session"?"Pausing…":"Pause"}),Ae&&e.jsx("button",{onClick:()=>_("resume-session","Session resumed",()=>V==null?void 0:V(t)),disabled:!V||!!x,className:"rounded-md border border-strong bg-white/[0.02] px-3 py-2 text-caption text-secondary transition-colors hover:bg-white/[0.06] hover:text-white disabled:opacity-45",children:x==="resume-session"?"Resuming…":"Resume"}),e.jsx("button",{onClick:()=>_("checkpoint-session","Progress saved",()=>K==null?void 0:K(t)),disabled:!K||!!x,className:"rounded-md border border-strong bg-white/[0.02] px-3 py-2 text-caption text-secondary transition-colors hover:bg-white/[0.06] hover:text-white disabled:opacity-45",children:x==="checkpoint-session"?"Saving…":"Save progress"}),Re&&e.jsx("button",{onClick:()=>_("rollback-session","Undo requested",()=>H==null?void 0:H(t)),disabled:!H||!!x,className:"rounded-md border border-strong bg-white/[0.02] px-3 py-2 text-caption text-secondary transition-colors hover:bg-white/[0.06] hover:text-white disabled:opacity-45",children:x==="rollback-session"?"Undoing…":"Undo last step"})]}),ie&&e.jsxs("div",{className:"mt-3 rounded-lg border border-white/[0.08] bg-black/[0.18] px-3 py-2.5",children:[e.jsx("p",{className:"mb-2 text-micro uppercase tracking-[0.16em] text-muted",children:"Intervene"}),e.jsx("textarea",{value:D,onChange:r=>W(r.target.value),placeholder:"Share guidance for this run...",className:"min-h-[84px] w-full resize-y 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:"mt-2 flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-micro text-secondary",children:"Visible to agents and collaborators."}),e.jsx("button",{type:"button",onClick:()=>{const r=D.trim();if(!r){A("Intervention note cannot be empty.");return}_("intervene-note","Intervention sent",async()=>{await ie({session:t,workstreamId:(k==null?void 0:k.workstreamId)??t.workstreamId??null,text:r}),W("")})},disabled:!!x||D.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:x==="intervene-note"?"Sending…":"Send intervention"})]})]}),Ce&&G&&e.jsx("div",{className:"mt-3 border-t border-subtle pt-3",children:e.jsx("button",{onClick:Ue,disabled:!!x,className:"text-caption text-secondary transition-colors hover:text-red-300 disabled:opacity-45",children:"Cancel session…"})})]}),J&&e.jsx("p",{className:"rounded-md border border-white/[0.08] bg-white/[0.02] px-2.5 py-1.5 text-caption text-secondary",children:J}),t.blockers.length>0&&e.jsxs("div",{className:"rounded-xl border border-red-500/30 bg-red-500/10 p-3",children:[e.jsx("h3",{className:"mb-1 text-caption uppercase tracking-[0.12em] 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.jsxs("div",{children:[e.jsx("h3",{className:"mb-2 text-caption uppercase tracking-[0.16em] text-secondary",children:"Recent Messages"}),C.length===0&&e.jsx("p",{className:"text-body text-secondary",children:"No recent messages for this run."}),e.jsx("div",{className:"space-y-2",children:C.map(r=>e.jsxs("article",{className:"rounded-lg border border-subtle bg-white/[0.02] px-2.5 py-2",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}),j&&e.jsx("button",{type:"button",onClick:()=>j(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 transition-colors 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()," · ",q(r.timestamp)]})]},r.id))})]})]})}),e.jsx(ve,{})]})});export{dt as SessionInspector};
1
+ import{r as w,j as e}from"./cNrhgGc1.js";import{y as T,z as N,F as ye,P as we,w as S,G as qe,d as Z,H as ze,J as je,K as q,L as Pe,x as Fe,M as Oe}from"./C9jy61eu.js";import{u as Ve}from"./B6wPWJ35.js";import"./C-KIc3Wc.js";import"./BJgZIVUQ.js";import"./CxQ08qFN.js";const Ge=/^[0-9a-f-]{20,}$/i,Ke=new Set(["running","active","queued","pending","in_progress","working","planning","handoff","review"]),He=new Set(["agent execution failed","execution failed","run failed","failed"]);function y(n){return typeof n=="string"&&n.trim().length>0}function le(n){return(n??"").trim().toLowerCase()}function Je(n){return(n??"").trim().replace(/\s+/g," ").toLowerCase()}function Xe(n){return He.has(Je(n))}function z(n,t=3){return n.length<=t?n.join(", "):`${n.slice(0,t).join(", ")} +${n.length-t} more`}function P(n,t){const b=[],o=m=>{if(typeof m!="string")return;const j=m.trim();j&&(b.some(L=>L.toLowerCase()===j.toLowerCase())||b.push(j))};if(Array.isArray(n))for(const m of n)o(m);return o(t??null),b}function Qe(n){if(n.runId&&n.runId.trim().length>0)return n.runId.trim();const t=n.metadata;if(!t)return null;const b=["slice_run_id","sliceRunId","runId","run_id","correlation_id","correlationId","sessionId","session_id","agentRunId"];for(const o of b){const m=t[o];if(typeof m=="string"&&m.trim().length>0)return m.trim()}return null}function Ye(n){const t=le(n.status);if(t==="blocked"||t==="failed"||t==="completed"||t==="cancelled")return t;const b=le(n.phase);if(b==="blocked")return"blocked";if(b==="handoff")return"handoff";if(b==="completed")return"completed";if(b==="review")return"review";const o=le(n.state);return o==="error"?"failed":o==="stopped"?"paused":o==="stale"?"queued":Ke.has(t)?t:n.blockers.length>0?"blocked":t||"unknown"}function Ze(n,t,b){var m;const o=[((m=n.blockerDiagnostics)==null?void 0:m.reason)??null,n.blockerReason??null,...n.blockers,t==="blocked"||t==="failed"||t==="handoff"?b:null].map(j=>typeof j=="string"?j.trim():"").filter(j=>j.length>0);return o.length>0?o.find(L=>!Xe(L))??o[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 De(n){return n==="completed"?"border-lime/25 bg-lime/[0.08] text-lime":n==="needs_attention"?"border-amber-400/30 bg-amber-400/10 text-amber-200":n==="failed"?"border-red-400/30 bg-red-500/10 text-red-200":n==="in_progress"?"border-teal-400/30 bg-teal-400/10 text-teal-200":"border-strong bg-white/[0.04] text-secondary"}const dt=w.memo(function({session:t,activity:b,initiatives:o=[],sliceRuns:m=[],onOpenActivityItem:j,onContinueHighestPriority:L,onDispatchSession:F,onPauseSession:O,onResumeSession:V,onCancelSession:G,onCreateCheckpoint:K,onRollbackSession:H,onStartInitiative:et,onStartWorkstream:tt,initialInterventionDraft:k=null,onSubmitIntervention:ie}){var he,be,ge;const[x,de]=w.useState(null),[J,A]=w.useState(null),[M,oe]=w.useState(!1),[D,W]=w.useState(""),{enqueue:ce,ToastRenderer:ve}=Ve();w.useEffect(()=>{if(!t){W("");return}if(k!=null&&k.text){W(k.text);return}W("")},[k==null?void 0:k.text,t==null?void 0:t.id]);const B=w.useMemo(()=>{var d,g,f,i,u;if(!t)return new Set;const r=new Set;return(d=t.runId)!=null&&d.trim()&&r.add(t.runId.trim()),(g=t.id)!=null&&g.trim()&&r.add(t.id.trim()),(u=(i=(f=t.blockerDiagnostics)==null?void 0:f.context)==null?void 0:i.sliceRunId)!=null&&u.trim()&&r.add(t.blockerDiagnostics.context.sliceRunId.trim()),r},[t]),C=w.useMemo(()=>t?B.size===0?[]:b.filter(r=>{const d=Qe(r);return!!(d&&B.has(d))}).sort((r,d)=>Date.parse(d.timestamp)-Date.parse(r.timestamp)).slice(0,12):[],[b,t,B]),s=w.useMemo(()=>{var f,i;if(!t||!Array.isArray(m)||m.length===0)return null;const r=((f=t.initiativeId)==null?void 0:f.trim())??"",d=((i=t.workstreamId)==null?void 0:i.trim())??"",g=m.filter(u=>{var ne,fe;const I=((ne=u.sliceRunId)==null?void 0:ne.trim())??"",E=((fe=u.runId)==null?void 0:fe.trim())??"";if(I&&B.has(I)||E&&B.has(E))return!0;if(!d||!P(u.workstreamIds,u.workstreamId).includes(d))return!1;if(!r)return!0;const Y=P(u.initiativeIds,u.initiativeId);return!(Y.length>0&&!Y.includes(r))});return g.length===0?null:[...g].sort((u,I)=>{const E=Date.parse(u.updatedAt??u.lastEventAt??u.startedAt??""),ae=Date.parse(I.updatedAt??I.lastEventAt??I.startedAt??""),Y=Number.isFinite(E)?E:0;return(Number.isFinite(ae)?ae:0)-Y})[0]},[t,B,m]),ee=w.useMemo(()=>{var f;if(!t)return[];const r=[],d=t.initiativeId??t.groupId;if(d){const i=o.find(u=>u.id===d);i?r.push({label:"Initiative",value:i.name}):t.groupLabel&&t.groupLabel.trim().length>0?r.push({label:"Initiative",value:t.groupLabel}):T(d)&&r.push({label:"Initiative",value:N(d)})}if(t.workstreamId){let i=null;for(const u of o){const I=(f=u.workstreams)==null?void 0:f.find(E=>E.id===t.workstreamId);if(I){i=I.name;break}}!i&&T(t.workstreamId)?i=N(t.workstreamId):!i&&!Ge.test(t.workstreamId)&&(i=t.workstreamId),i&&r.push({label:"Workstream",value:i})}const g=t.phase??null;if(g){const i=String(g);r.push({label:"Milestone",value:T(i)?N(i):i})}return t.title&&r.push({label:"Task",value:t.title}),r},[o,t]),R=w.useMemo(()=>{var f,i;if(!t)return null;const r=((f=C[0])==null?void 0:f.summary)??((i=C[0])==null?void 0:i.description)??null,g=t.lastEventSummary??r??null;return g&&g.trim().length>0?g.trim():null},[C,t]),ue=w.useMemo(()=>{var r;return t?ye(t.agentName,t.title,t.lastEventSummary,R,(r=C[0])==null?void 0:r.metadata):ye()},[C,t,R]),_=async(r,d,g)=>{if(!(!g||x)){de(r),A(null);try{await g(),A(`${d} requested.`)}catch(f){A(f instanceof Error?f.message:`${d} failed.`)}finally{de(null)}}};if(!t)return e.jsxs(we,{className:"flex h-full min-h-0 flex-col overflow-hidden card-enter",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-subtle px-4 py-3.5",children:[e.jsx("h2",{className:"text-heading font-semibold text-white",children:"Session Detail"}),e.jsx("button",{onClick:()=>oe(r=>!r),className:"text-muted transition-colors hover:text-primary","aria-label":M?"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:S("transition-transform",M?"-rotate-90":"rotate-0"),children:e.jsx("path",{d:"m6 9 6 6 6-6"})})})]}),e.jsx("div",{className:S("transition-all",M?"max-h-0 overflow-hidden":"min-h-0 flex-1"),children:e.jsxs("div",{className:"h-full min-h-0 space-y-2 overflow-y-auto p-4 text-body text-secondary",children:[e.jsx("p",{children:"Select a session to inspect summary, breadcrumbs, blockers, and recent messages."}),e.jsx("button",{onClick:()=>_("continue-priority","Continue highest priority",L),disabled:!L||!!x,className:"rounded-md border border-strong bg-white/[0.04] px-3 py-1.5 text-caption text-primary transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:x==="continue-priority"?"Dispatching…":"Continue highest priority"}),J&&e.jsx("p",{className:"text-caption text-secondary",children:J})]})})]});const U=t.progress===null?null:Math.round(t.progress),v=Ye(t),p=C[0]??null,te=(s==null?void 0:s.blockingDecisionCount)??0,Ne=Math.max(0,((s==null?void 0:s.decisionCount)??0)-te),c=qe({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??((he=t.blockerDiagnostics)==null?void 0:he.reason)??((s==null?void 0:s.status)==="failed"?"error":null),decisionRequired:((p==null?void 0:p.decisionRequired)??!1)||te>0,blockingDecisionCount:te,nonBlockingDecisionCount:Ne,blockerCount:t.blockers.length,blockerReason:t.blockerReason??((be=t.blockerDiagnostics)==null?void 0:be.reason)??null}),re=Ze(t,v,R),ke=v==="handoff"?"Handoff":v==="blocked"?"Blocker reason":v==="failed"?"Failure reason":"Status note",Ie=c.status==="in_progress"&&["running","active","queued","pending","working","in_progress","planning","review"].includes(v),Ae=c.status==="needs_attention"&&["paused","blocked","queued","pending"].includes(v),Ce=!["completed","archived","cancelled"].includes(v),Re=!["archived","cancelled"].includes(v),Te=c.label,Se=De(c.status),me=["running","active","working","in_progress","planning","review"].includes(v),_e=c.status!=="in_progress"&&!me,Ee=c.tone==="critical"?Z.red:c.tone==="warning"?Z.amber:c.tone==="positive"?Z.lime:Z.teal,Le=U!==null&&U>=100&&c.status!=="completed"?"Terminal state":"Progress",Me=c.tone==="critical"?"border-red-400/25 bg-red-500/10":c.tone==="warning"?"border-amber-400/25 bg-amber-500/10":c.tone==="positive"?"border-lime/22 bg-lime/[0.08]":"border-subtle bg-white/[0.02]",a=t.blockerDiagnostics??null,l=(a==null?void 0:a.context)??null,se=[y(a==null?void 0:a.source)?`Source: ${a.source.trim()}`:null,y(a==null?void 0:a.errorCode)?`Code: ${a.errorCode.trim()}`:null,y(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),h=[];l&&(Array.isArray(l.initiativeIds)&&l.initiativeIds.length>0?h.push({label:"Initiatives",value:z(l.initiativeIds.map(r=>T(r)?N(r):r),4)}):y(l.initiativeId)&&h.push({label:"Initiative",value:ze("Initiative",l.initiativeId.trim())}),y(l.workstreamTitle)?h.push({label:"Workstream",value:l.workstreamTitle.trim()}):Array.isArray(l.workstreamIds)&&l.workstreamIds.length>0?h.push({label:"Workstreams",value:z(l.workstreamIds,4)}):y(l.workstreamId)&&h.push({label:"Workstream",value:l.workstreamId.trim()}),y(l.sliceRunId)&&h.push({label:"Slice run",value:N(l.sliceRunId.trim())}),y(l.parallelMode)&&h.push({label:"Mode",value:l.parallelMode.trim().toUpperCase()}),Array.isArray(l.taskIds)&&l.taskIds.length>0&&h.push({label:"Tasks",value:z(l.taskIds.map(r=>T(r)?N(r):r))}),Array.isArray(l.milestoneIds)&&l.milestoneIds.length>0&&h.push({label:"Milestones",value:z(l.milestoneIds.map(r=>T(r)?N(r):r))}),Array.isArray(l.iwmtIds)&&l.iwmtIds.length>0?h.push({label:"Scope IDs",value:z(l.iwmtIds.map(r=>T(r)?N(r):r),4)}):y(l.iwmtId)&&h.push({label:"Scope ID",value:T(l.iwmtId.trim())?N(l.iwmtId.trim()):l.iwmtId.trim()}),y(l.logPath)&&h.push({label:"Log path",value:je(l.logPath.trim())}),y(l.outputPath)&&h.push({label:"Output path",value:je(l.outputPath.trim())}));const xe=(v==="blocked"||v==="failed")&&!!(a&&(y(a.reason)||se.length>0||h.length>0||Array.isArray(a.suggestedActions)&&a.suggestedActions.length>0)),X=y(re)?re:null,Be=X!==null&&!(R&&(X===R||R.includes(X)))&&!xe,Ue=w.useCallback(()=>{!G||!t||(A("Session will be cancelled…"),ce({message:`Cancelled "${t.title}"`,onCommit:async()=>{try{await G(t),A("Session cancelled.")}catch(r){A(r instanceof Error?r.message:"Cancel failed.")}},onUndo:()=>{A(null)}}))},[G,t,ce]),We=[{label:"Started",value:t.startedAt?q(t.startedAt):"—"},{label:"Updated",value:t.updatedAt?q(t.updatedAt):"—"},...t.eta?[{label:"ETA",value:t.eta}]:[],...t.checkpointCount?[{label:"Checkpoints",value:String(t.checkpointCount)}]:[]],pe=s?s.status.replace(/_/g," "):null,$=P(s==null?void 0:s.initiativeIds,(s==null?void 0:s.initiativeId)??null),Q=P(s==null?void 0:s.workstreamIds,(s==null?void 0:s.workstreamId)??null);P(s==null?void 0:s.iwmtIds,(s==null?void 0:s.iwmtId)??null);const $e=$[0]?((ge=o.find(r=>r.id===$[0]))==null?void 0:ge.name)??$[0]:null;return e.jsxs(we,{className:"flex h-full min-h-0 flex-col overflow-hidden card-enter",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-subtle px-4 py-3.5",children:[e.jsx("h2",{className:"text-heading font-semibold text-white",children:"Session Detail"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:S("chip text-caption uppercase tracking-[0.14em]",Se),children:Te}),e.jsx("button",{onClick:()=>oe(r=>!r),className:"text-muted transition-colors hover:text-primary","aria-label":M?"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:S("transition-transform",M?"-rotate-90":"rotate-0"),children:e.jsx("path",{d:"m6 9 6 6 6-6"})})})]})]}),e.jsx("div",{className:S("transition-all",M?"max-h-0 overflow-hidden":"min-h-0 flex-1"),children:e.jsxs("div",{className:"h-full min-h-0 space-y-4 overflow-y-auto p-4",children:[e.jsxs("div",{className:"rounded-xl border border-subtle bg-white/[0.02] p-3",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Pe,{provider:ue.id,size:"sm"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-body font-semibold text-white",children:Fe(t.title)}),e.jsxs("p",{className:"mt-1 text-caption text-secondary",children:[t.agentName??"OrgX"," · ",ue.label]})]})]}),ee.length>0&&e.jsxs("div",{className:"mt-3",children:[e.jsx("p",{className:"mb-1 text-micro uppercase tracking-[0.16em] text-muted",children:"Context"}),e.jsx("div",{className:"flex flex-wrap items-center gap-1.5 text-caption",children:ee.map((r,d)=>e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{className:"rounded-full border border-strong bg-white/[0.02] px-2 py-0.5 text-secondary",children:r.value}),d<ee.length-1&&e.jsx("span",{className:"text-caption text-muted",children:"›"})]},`${r.label}-${r.value}`))})]}),R&&e.jsxs("div",{className:"mt-3 rounded-lg border border-subtle bg-white/[0.02] px-3 py-2",children:[e.jsx("p",{className:"mb-1 text-micro uppercase tracking-[0.16em] text-muted",children:"Summary"}),e.jsx(Oe,{text:R,mode:"block"})]}),e.jsxs("div",{className:S("mt-3 rounded-lg border px-3 py-2",Me),children:[e.jsx("p",{className:"mb-1 text-micro uppercase tracking-[0.16em] text-muted",children:c.label}),e.jsx("p",{className:"text-body text-secondary",children:c.sentence}),c.nextAction&&e.jsxs("p",{className:"mt-1 text-caption text-secondary",children:["Next: ",c.nextAction]})]}),Be&&e.jsxs("div",{className:"mt-3 rounded-lg border border-subtle bg-white/[0.02] px-3 py-2",children:[e.jsx("p",{className:"mb-1 text-micro uppercase tracking-[0.16em] text-muted",children:ke}),e.jsx("p",{className:"text-body text-secondary",children:X})]}),xe&&e.jsxs("div",{className:"mt-3 rounded-lg border border-red-500/25 bg-red-500/10 px-3 py-2.5",children:[e.jsx("p",{className:"mb-1 text-micro uppercase tracking-[0.16em] text-red-200/75",children:"Why blocked"}),e.jsx("p",{className:"text-body text-red-100/90",children:(a==null?void 0:a.reason)??re??"Runtime marked this run as blocked without details."}),se.length>0&&e.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:se.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))}),h.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:h.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))})]}),y(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()," ·"," ",q(a.eventTimestamp)]})]})]}),s&&e.jsxs("div",{className:"rounded-xl border border-subtle bg-white/[0.02] p-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("h3",{className:"text-caption uppercase tracking-[0.12em] text-secondary",children:"Slice scope"}),pe?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:pe}):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:$e??"—"})]}),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??(Q[0]?N(Q[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?q(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]}),$.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:["+",$.length-1," initiatives"]}):null,Q.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:["+",Q.length-1," workstreams"]}):null]}),s.taskIds.length>0?e.jsxs("p",{className:"mt-2 text-micro text-secondary",children:["Tasks: ",s.taskIds.length]}):null]}),e.jsxs("div",{className:"rounded-xl border border-subtle bg-white/[0.02] p-3",children:[U!==null&&e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between text-caption text-secondary",children:[e.jsx("span",{children:Le}),e.jsxs("span",{className:"text-primary",children:[U,"%"]})]}),e.jsx("div",{className:"h-2 rounded-full bg-white/[0.08]",children:e.jsx("div",{className:S("h-2 rounded-full transition-all duration-500",me&&"live-pulse"),style:{width:`${U}%`,background:Ee}})})]}),e.jsx("dl",{className:S("grid grid-cols-2 gap-3 text-caption text-secondary",U!==null?"mt-3":""),children:We.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))})]}),e.jsxs("div",{className:"rounded-xl border border-subtle bg-white/[0.02] p-3",children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{onClick:()=>_("dispatch-session","Session started",()=>F==null?void 0:F(t)),disabled:!F||!!x||!_e,className:"rounded-md border border-lime/25 bg-lime/10 px-3 py-2 text-caption font-semibold text-lime transition-colors hover:bg-lime/20 disabled:opacity-45",children:x==="dispatch-session"?"Starting…":c.status==="completed"?"Restart":"Start"}),Ie&&e.jsx("button",{onClick:()=>_("pause-session","Session paused",()=>O==null?void 0:O(t)),disabled:!O||!!x,className:"rounded-md border border-strong bg-white/[0.02] px-3 py-2 text-caption text-secondary transition-colors hover:bg-white/[0.06] hover:text-white disabled:opacity-45",children:x==="pause-session"?"Pausing…":"Pause"}),Ae&&e.jsx("button",{onClick:()=>_("resume-session","Session resumed",()=>V==null?void 0:V(t)),disabled:!V||!!x,className:"rounded-md border border-strong bg-white/[0.02] px-3 py-2 text-caption text-secondary transition-colors hover:bg-white/[0.06] hover:text-white disabled:opacity-45",children:x==="resume-session"?"Resuming…":"Resume"}),e.jsx("button",{onClick:()=>_("checkpoint-session","Progress saved",()=>K==null?void 0:K(t)),disabled:!K||!!x,className:"rounded-md border border-strong bg-white/[0.02] px-3 py-2 text-caption text-secondary transition-colors hover:bg-white/[0.06] hover:text-white disabled:opacity-45",children:x==="checkpoint-session"?"Saving…":"Save progress"}),Re&&e.jsx("button",{onClick:()=>_("rollback-session","Undo requested",()=>H==null?void 0:H(t)),disabled:!H||!!x,className:"rounded-md border border-strong bg-white/[0.02] px-3 py-2 text-caption text-secondary transition-colors hover:bg-white/[0.06] hover:text-white disabled:opacity-45",children:x==="rollback-session"?"Undoing…":"Undo last step"})]}),ie&&e.jsxs("div",{className:"mt-3 rounded-lg border border-white/[0.08] bg-black/[0.18] px-3 py-2.5",children:[e.jsx("p",{className:"mb-2 text-micro uppercase tracking-[0.16em] text-muted",children:"Intervene"}),e.jsx("textarea",{value:D,onChange:r=>W(r.target.value),placeholder:"Share guidance for this run...",className:"min-h-[84px] w-full resize-y 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:"mt-2 flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-micro text-secondary",children:"Visible to agents and collaborators."}),e.jsx("button",{type:"button",onClick:()=>{const r=D.trim();if(!r){A("Intervention note cannot be empty.");return}_("intervene-note","Intervention sent",async()=>{await ie({session:t,workstreamId:(k==null?void 0:k.workstreamId)??t.workstreamId??null,text:r}),W("")})},disabled:!!x||D.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:x==="intervene-note"?"Sending…":"Send intervention"})]})]}),Ce&&G&&e.jsx("div",{className:"mt-3 border-t border-subtle pt-3",children:e.jsx("button",{onClick:Ue,disabled:!!x,className:"text-caption text-secondary transition-colors hover:text-red-300 disabled:opacity-45",children:"Cancel session…"})})]}),J&&e.jsx("p",{className:"rounded-md border border-white/[0.08] bg-white/[0.02] px-2.5 py-1.5 text-caption text-secondary",children:J}),t.blockers.length>0&&e.jsxs("div",{className:"rounded-xl border border-red-500/30 bg-red-500/10 p-3",children:[e.jsx("h3",{className:"mb-1 text-caption uppercase tracking-[0.12em] 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.jsxs("div",{children:[e.jsx("h3",{className:"mb-2 text-caption uppercase tracking-[0.16em] text-secondary",children:"Recent Messages"}),C.length===0&&e.jsx("p",{className:"text-body text-secondary",children:"No recent messages for this run."}),e.jsx("div",{className:"space-y-2",children:C.map(r=>e.jsxs("article",{className:"rounded-lg border border-subtle bg-white/[0.02] px-2.5 py-2",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}),j&&e.jsx("button",{type:"button",onClick:()=>j(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 transition-colors 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()," · ",q(r.timestamp)]})]},r.id))})]})]})}),e.jsx(ve,{})]})});export{dt as SessionInspector};
@@ -1 +1 @@
1
- import{r as l,j as e}from"./cNrhgGc1.js";import{E as Q,d as M,r as $e,X as G,K as Ie,Y as Fe,Z as Pe,M as Le,h as Te,P as Be,w as ve}from"./D-bf6hEI.js";import{E as De}from"./DNxKz-GV.js";import{A as Ee,m as se,u as Re}from"./CxQ08qFN.js";import{u as We}from"./CFGKRAzG.js";import"./C-KIc3Wc.js";import"./BJgZIVUQ.js";const ze={pr:"⎋",file:"◇",artifact:"▪",log:"▸",decision:"◈"};function Ue(c){return c>=.8?"#BFFF00":c>=.5?"#F5B700":"#FF6B88"}function Oe(c){const t=c.match(/https?:\/\/\S+/);return t?t[0]:null}function Xe({evidenceType:c,title:t,summary:h,sourceUrl:y,confidence:C,payload:b,icon:_,label:f,onOpenTerminal:Y}){const[R,X]=l.useState(!1),E=t??f??null,$=c??(_?_.toUpperCase():null),w=_?ze[_]:null,v=_==="pr"&&f?Oe(f):null;return e.jsxs("div",{className:"rounded-xl border border-white/[0.06] bg-white/[0.02] px-3 py-2.5",children:[e.jsxs("div",{className:"flex items-start gap-2.5 cursor-pointer",onClick:()=>X(g=>!g),children:[($||w)&&e.jsxs("span",{className:"mt-0.5 flex-shrink-0 rounded bg-white/[0.06] px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wider text-secondary",children:[w?e.jsx("span",{className:"mr-1",children:w}):null,$]}),e.jsxs("div",{className:"min-w-0 flex-1",children:[E&&e.jsx("p",{className:"text-body font-medium text-primary",children:y?e.jsx("a",{href:y,target:"_blank",rel:"noopener noreferrer",className:"text-[#D8FFA1] hover:underline",onClick:g=>g.stopPropagation(),children:E}):v?e.jsx("a",{href:v,target:"_blank",rel:"noopener noreferrer",className:"text-[#D8FFA1] hover:underline",onClick:g=>g.stopPropagation(),children:E}):E}),h&&e.jsx("p",{className:`mt-0.5 text-caption text-secondary ${R?"":"line-clamp-2"}`,children:h})]}),e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:`mt-1 flex-shrink-0 text-muted transition-transform ${R?"rotate-180":""}`,children:e.jsx("path",{d:"m6 9 6 6 6-6"})})]}),C!=null&&e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("div",{className:"h-1 flex-1 overflow-hidden rounded-full bg-white/[0.06]",children:e.jsx("div",{className:"h-full rounded-full transition-all",style:{width:`${Math.round(C*100)}%`,backgroundColor:Ue(C)}})}),e.jsxs("span",{className:"text-micro text-muted tabular-nums",children:[Math.round(C*100),"%"]})]}),e.jsx(Ee,{children:R&&e.jsx(se.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.2},className:"overflow-hidden",children:e.jsxs("div",{className:"mt-2 space-y-2",children:[_==="log"&&Y&&e.jsxs("button",{type:"button",onClick:g=>{g.stopPropagation(),Y()},className:"inline-flex items-center gap-1.5 rounded-lg border border-white/[0.12] bg-white/[0.04] px-3 py-1.5 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.08]",children:[e.jsx("span",{className:"font-mono text-micro",children:">_"}),"Open in terminal"]}),b&&Object.keys(b).length>0&&e.jsx("pre",{className:"max-h-40 overflow-auto rounded-lg bg-black/40 p-2.5 text-micro text-secondary font-mono",children:JSON.stringify(b,null,2)})]})})})]})}function Ke({segments:c}){return c.length===0?null:e.jsx("nav",{className:"flex items-center gap-1.5 min-w-0 text-caption text-secondary",children:c.map((t,h)=>e.jsxs("span",{className:"flex items-center gap-1.5 min-w-0",children:[h>0&&e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"flex-shrink-0 text-faint",children:e.jsx("path",{d:"m9 18 6-6-6-6"})}),t.icon&&e.jsx(Q,{type:t.icon,size:11,className:"flex-shrink-0 opacity-80"}),t.onClick?e.jsx("button",{type:"button",onClick:t.onClick,className:"truncate transition-colors hover:text-primary",children:t.label}):e.jsx("span",{className:"truncate",children:t.label})]},h))})}const _e=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent);function Je(c){try{return JSON.stringify(c,null,2)}catch{return null}}function qe(c){if(typeof c!="string")return null;const t=c.trim().toLowerCase();return t==="rejected"?"declined":t==="approved"||t==="declined"||t==="cancelled"?t:null}function Ne(c,t){return!c||c.trim().length===0?t:Te(c.trim())||t}function Ve(c){switch(c){case"spawn_guard_blocked":return"Spawn Guard";case"autopilot_failure":return"Autopilot Failure";case"budget_exceeded":return"Budget Exceeded";case"scope_change":return"Scope Change";case"conflict_resolution":return"Conflict Resolution";case"approval_required":return"Approval Required";case"review_required":return"Review Required";case"permission_request":return"Permission Request";default:return c.replace(/[_-]/g," ").replace(/\b\w/g,t=>t.toUpperCase())}}function Ze(c){const t=c.toLowerCase();return t==="critical"||t==="p0"?M.red:t==="high"||t==="p1"?M.amber:t==="medium"||t==="p2"?M.iris:"rgba(255,255,255,0.5)"}function Ge({open:c,decision:t,onClose:h,onApprove:y,onReject:C,initiativeTitle:b,workstreamTitle:_,onNavigate:f,currentIndex:Y,totalCount:R,onFocusRunId:X}){const[E,$]=l.useState("idle"),[w,v]=l.useState(null),[g,F]=l.useState(null),[N,W]=l.useState(""),[z,P]=l.useState(!1),[xe,ne]=l.useState(!1),[ie,me]=l.useState(!1),K=l.useRef(null),ae=l.useRef(),L=l.useRef(h);L.current=h,l.useEffect(()=>{if(c){$("idle"),v(null);const i=(t==null?void 0:t.selectedOptionId)??(t!=null&&t.options&&t.options.length===1?t.options[0].id:null);F(i),W(""),P(!1),ne(!1),me(!1)}return()=>{ae.current&&clearTimeout(ae.current)}},[c,t==null?void 0:t.id]);const m=t==null?void 0:t.metadata,le=l.useMemo(()=>{if(!m)return[];const i=m,n=i.decision_options??i.options??i.actions??null;if(!Array.isArray(n))return[];const I=[],B=new Set;for(let A=0;A<n.length;A+=1){const Z=n[A];if(typeof Z=="string"){const pe=Z.trim();if(!pe)continue;const r=`option-${A+1}`;if(B.has(r))continue;B.add(r),I.push({id:r,label:pe,description:null,impliedStatus:null,actionType:null,requiresNote:!1});continue}if(!Z||typeof Z!="object")continue;const x=Z,ue=typeof x.id=="string"&&x.id.trim()||typeof x.option_id=="string"&&x.option_id.trim()||typeof x.action_id=="string"&&x.action_id.trim()||`option-${A+1}`;if(B.has(ue))continue;const ye=typeof x.label=="string"&&x.label.trim()||typeof x.title=="string"&&x.title.trim()||typeof x.name=="string"&&x.name.trim()||typeof x.action=="string"&&x.action.trim()||null;ye&&(B.add(ue),I.push({id:ue,label:ye,description:typeof x.description=="string"?x.description:null,impliedStatus:qe(x.implied_status)??qe(x.status),actionType:typeof x.action_type=="string"&&x.action_type||typeof x.type=="string"&&x.type||null,requiresNote:x.requires_note===!0||x.requiresNote===!0||x.note_required===!0}))}return I.slice(0,12)},[m]),q=l.useMemo(()=>t!=null&&t.options&&t.options.length>0?t.options:le,[t==null?void 0:t.options,le]),u=l.useMemo(()=>q.find(i=>i.id===g)??null,[q,g]),T=l.useMemo(()=>{const i=((t==null?void 0:t.context)??"").trim();if(i)return i;if(!m)return"";const n=m,I=(typeof n.summary=="string"?n.summary:null)??(typeof n.description=="string"?n.description:null)??"";return String(I??"").trim()},[t==null?void 0:t.context,m]),U=l.useMemo(()=>{const i=(t==null?void 0:t.waitingMinutes)??0;return i>=15?M.red:i>=5?M.amber:M.teal},[t==null?void 0:t.waitingMinutes]),p=l.useCallback(async()=>{if(!t)return;const i=Je({decision:t,metadata:m});if(i)try{await navigator.clipboard.writeText(i),ne(!0),setTimeout(()=>ne(!1),2e3)}catch{}},[t,m]),O=l.useCallback(()=>{const i=N.trim(),n=u==null?void 0:u.id;if(!(!i&&!n))return{note:i.length>0?i:void 0,optionId:n??void 0}},[N,u]),k=l.useCallback(async()=>{if(!t||!y)return;if(q.length>0&&!u){v("Select an option before approving this decision.");return}if(u!=null&&u.requiresNote&&N.trim().length===0){v("A note is required for the selected option."),P(!0),requestAnimationFrame(()=>{var n;return(n=K.current)==null?void 0:n.focus()});return}let i=!1;if($(n=>n==="approving"||n==="rejecting"?n:(i=!0,"approving")),!!i){v(null);try{const n=await y(t.id,O());n.failed>0?($("error"),v(Ne(n.firstError,"Approval failed. Please try again."))):($("success"),ae.current=setTimeout(()=>L.current(),800))}catch(n){$("error");const I=n instanceof Error?n.message:"";v(Ne(I,"Approval failed."))}}},[O,t,N,y,q.length,u]),H=l.useCallback(async()=>{if(!t||!C)return;if(q.length>0&&!u){v("Select an option before rejecting this decision.");return}if(u!=null&&u.requiresNote&&N.trim().length===0){v("A note is required for the selected option."),P(!0),requestAnimationFrame(()=>{var n;return(n=K.current)==null?void 0:n.focus()});return}let i=!1;if($(n=>n==="approving"||n==="rejecting"?n:(i=!0,"rejecting")),!!i){v(null);try{const n=await C(t.id,O());n.failed>0?($("error"),v(Ne(n.firstError,"Rejection failed. Please try again."))):($("rejected"),ae.current=setTimeout(()=>L.current(),800))}catch(n){$("error");const I=n instanceof Error?n.message:"";v(Ne(I,"Rejection failed."))}}},[O,t,N,C,q.length,u]);if(l.useEffect(()=>{if(!c)return;const i=n=>{var B;if((n.metaKey||n.ctrlKey)&&n.key==="Enter"){n.preventDefault(),k();return}const I=(B=n.target)==null?void 0:B.tagName;if(!(I==="INPUT"||I==="TEXTAREA"))switch(n.key){case"j":n.preventDefault(),f==null||f(1);break;case"k":n.preventDefault(),f==null||f(-1);break;case"a":n.preventDefault(),k();break;case"r":n.preventDefault(),H();break;case"n":n.preventDefault(),P(A=>!A),z||requestAnimationFrame(()=>{var A;return(A=K.current)==null?void 0:A.focus()});break}};return document.addEventListener("keydown",i),()=>document.removeEventListener("keydown",i)},[c,k,H,f,z]),!c||!t)return null;const oe=E==="approving"||E==="rejecting",ee=E==="success"||E==="rejected",J=(t.status??"pending").toLowerCase(),he=!J.includes("approved")&&!J.includes("resolved")&&!J.includes("rejected")&&!J.includes("declined")&&!J.includes("cancelled"),Ce=q.length>0&&!u,fe=(u==null?void 0:u.requiresNote)===!0&&N.trim().length===0,V=oe||Ce||fe,te=t.evidenceRefs??[],S=te.length>0,ge=t.recommendedAction??null,be=t.decisionType??null,re=t.priority??null,ce=t.occurrenceCount??null,je=t.sourceRunId??null,j=[];b&&j.push({label:b,icon:"initiative"}),_&&j.push({label:_,icon:"workstream"});const de=[["ID",t.id],["Type",t.decisionType],["Dedupe key",t.dedupeKey],["Source system",t.sourceSystem],["Conflict source",t.conflictSource],["Agent ID",t.agentId],["Source run",t.sourceRunId],["Source session",t.sourceSessionId],["Source stream",t.sourceStreamId]].filter(([,i])=>i!=null);if(ee){const i=E==="success",n=i?M.lime:M.red;return e.jsx($e,{open:c,onClose:h,maxWidth:"max-w-xl",fitContent:!0,children:e.jsxs("div",{className:"flex flex-col items-center justify-center px-8 py-12",children:[e.jsx("div",{className:"mb-4 flex h-16 w-16 items-center justify-center rounded-full",style:{backgroundColor:`${n}18`,border:`1.5px solid ${n}40`},children:i?e.jsx("svg",{width:"28",height:"28",viewBox:"0 0 24 24",fill:"none",stroke:n,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):e.jsxs("svg",{width:"28",height:"28",viewBox:"0 0 24 24",fill:"none",stroke:n,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 6L6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})}),e.jsx("p",{className:"text-heading font-semibold text-white",children:i?"Approved":"Rejected"}),e.jsx("p",{className:"mt-1 text-body text-secondary",children:t.title})]})})}return e.jsx($e,{open:c,onClose:h,maxWidth:"max-w-xl",children:e.jsxs("div",{className:"flex h-full min-h-0 w-full flex-col",children:[e.jsx("div",{className:"h-[2px] w-full flex-shrink-0",style:{background:`linear-gradient(90deg, ${U}60, ${U}20, transparent)`}}),f&&e.jsxs("div",{className:"flex items-center justify-between px-6 pt-3 pb-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>f(-1),className:"rounded p-1 text-muted hover:text-secondary hover:bg-white/[0.06] transition-colors",title:"Previous (k)",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"m15 18-6-6 6-6"})})}),e.jsx("button",{type:"button",onClick:()=>f(1),className:"rounded p-1 text-muted hover:text-secondary hover:bg-white/[0.06] transition-colors",title:"Next (j)",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"m9 18 6-6-6-6"})})}),Y!=null&&R!=null&&e.jsxs("span",{className:"text-micro text-muted tabular-nums",children:[Y+1," of ",R]})]}),e.jsx("button",{type:"button",onClick:h,"aria-label":"Close",className:"rounded p-1 text-muted hover:text-secondary hover:bg-white/[0.06] transition-colors",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M18 6 6 18M6 6l12 12"})})})]}),j.length>0&&e.jsx("div",{className:"px-6 pt-2",children:e.jsx(Ke,{segments:j})}),e.jsxs("div",{className:"flex items-start justify-between gap-3 px-6 pt-4 pb-4",children:[e.jsx("div",{className:"min-w-0 flex-1",children:e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-lg",style:{backgroundColor:`${U}14`,border:`1px solid ${U}30`},children:e.jsx(Q,{type:"decision",size:14})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h2",{className:"text-title font-medium leading-tight text-white mb-2",children:t.title||"Decision Required"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-body text-secondary",children:[e.jsx("span",{children:t.agentName||"OrgX Autopilot"}),e.jsx("span",{className:"text-white/[0.15]",children:"|"}),e.jsx("span",{children:G(t.waitingMinutes).text}),be&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-white/[0.15]",children:"|"}),e.jsx("span",{className:"text-primary",children:Ve(be)})]}),re&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-white/[0.15]",children:"|"}),e.jsx("span",{className:"font-medium",style:{color:Ze(re)},children:re})]})]}),ce!=null&&ce>1&&e.jsxs("p",{className:"mt-2 text-caption text-muted",children:["Seen ",ce," times",t.firstSeenAt&&e.jsxs(e.Fragment,{children:[" · first ",Ie(t.firstSeenAt)]}),t.lastSeenAt&&e.jsxs(e.Fragment,{children:[" · last ",Ie(t.lastSeenAt)]})]})]})]})}),!f&&e.jsx("button",{type:"button",onClick:h,"aria-label":"Close",className:"mt-0.5 flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-lg text-muted transition-colors hover:bg-white/[0.06] hover:text-white",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 6L6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto px-6 pb-4",children:[(t.initiativeId||t.workstreamId)&&e.jsx("div",{className:"mb-4",children:e.jsx(Fe,{nodes:Pe({initiativeId:t.initiativeId,initiativeTitle:b,workstreamId:t.workstreamId,workstreamTitle:_,agentName:t.agentName,agentId:t.agentId}),activeId:t.workstreamId,compact:!0})}),ge&&e.jsxs("div",{className:"mb-4 rounded-xl border border-cyan-300/[0.28] bg-cyan-500/[0.12] px-4 py-3",children:[e.jsx("p",{className:"text-micro font-semibold uppercase tracking-wider text-cyan-200 mb-1",children:"Recommended"}),e.jsx("p",{className:"text-body text-cyan-100",children:ge})]}),S&&e.jsxs("div",{className:"mb-4",children:[e.jsx("p",{className:"mb-2 px-1 text-micro font-semibold uppercase tracking-wider text-muted",children:"Evidence"}),e.jsx("div",{className:"space-y-1.5",children:te.map((i,n)=>e.jsx(Xe,{evidenceType:i.evidenceType,title:i.title,summary:i.summary,sourceUrl:i.sourceUrl,confidence:i.confidence,payload:i.payload},n))})]}),T?e.jsx("div",{className:"rounded-xl border border-white/[0.06] bg-white/[0.02] px-4 py-3",children:e.jsx(Le,{text:T,mode:"block"})}):e.jsx("p",{className:"px-1 text-body text-muted italic",children:"No additional context provided."}),q.length>0&&e.jsxs("div",{className:"mt-8",children:[e.jsx("p",{className:"mb-3 px-1 text-[11px] font-semibold uppercase tracking-widest text-muted",children:"Options"}),e.jsx("div",{className:"space-y-1 relative",children:q.map(i=>{const n=g===i.id;return e.jsxs("button",{type:"button",onClick:()=>{F(n?null:i.id),i.requiresNote&&P(!0)},disabled:oe,className:"group relative flex w-full items-start gap-4 px-4 py-4 text-left focus:outline-none",children:[n&&e.jsx(se.div,{layoutId:"decision-option-bg",className:"absolute inset-0 rounded-xl",style:{backgroundColor:`${M.lime}12`},transition:{type:"spring",stiffness:400,damping:25}}),!n&&e.jsx("div",{className:"absolute inset-0 rounded-xl opacity-0 transition-opacity group-hover:bg-white/[0.03]"}),e.jsx("div",{className:"relative mt-0.5 flex h-5 w-5 flex-shrink-0 items-center justify-center rounded-full border-[1.5px] transition-colors",style:{borderColor:n?M.lime:"rgba(255,255,255,0.2)"},children:e.jsx(Ee,{children:n&&e.jsx(se.div,{initial:{scale:0},animate:{scale:1},exit:{scale:0},transition:{type:"spring",stiffness:500,damping:30},className:"h-2.5 w-2.5 rounded-full",style:{backgroundColor:M.lime}})})}),e.jsxs("div",{className:"relative min-w-0 flex-1",children:[e.jsx("span",{className:`block text-[15px] ${n?"font-medium text-white":"text-primary"}`,children:i.label}),i.description&&e.jsx("p",{className:"mt-1 text-[13px] leading-relaxed text-secondary",children:i.description}),i.requiresNote&&e.jsx("p",{className:"mt-1.5 text-[11px] font-medium uppercase tracking-wider text-amber-400",children:"Note required"})]})]},i.id)})})]}),he&&e.jsxs("div",{className:"mt-4",children:[e.jsxs("button",{type:"button",onClick:()=>{P(i=>!i),z||requestAnimationFrame(()=>{var i;return(i=K.current)==null?void 0:i.focus()})},className:"flex w-full items-center gap-2 px-1 text-caption text-secondary transition-colors hover:text-white",children:[e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"transition-transform",style:{transform:z?"rotate(90deg)":"rotate(0deg)"},children:e.jsx("polyline",{points:"9 18 15 12 9 6"})}),"Add a note"]}),z&&e.jsxs("div",{className:"mt-2",children:[e.jsx("textarea",{ref:K,value:N,onChange:i=>W(i.target.value),disabled:oe,placeholder:"Optional context for this decision...",rows:3,className:"w-full resize-none rounded-xl border border-white/[0.08] bg-white/[0.03] px-4 py-3 text-body text-primary placeholder-white/30 outline-none transition-colors focus:border-white/[0.16] focus:bg-white/[0.04]"}),(u==null?void 0:u.requiresNote)&&N.trim().length===0&&e.jsx("p",{className:"mt-2 text-caption text-amber-300",children:"This option requires a note before submission."})]})]}),je&&X&&e.jsx("div",{className:"mt-4",children:e.jsxs("button",{type:"button",onClick:()=>X(je),className:"inline-flex items-center gap-1.5 text-caption text-[#D8FFA1] transition-colors hover:text-white",children:[e.jsx(Q,{type:"session",size:12}),"View source run"]})}),e.jsx("div",{className:"mt-4 border-t border-white/[0.06] pt-4",children:e.jsx(De,{entityType:"decision",entityId:t.id})}),de.length>0&&e.jsxs("div",{className:"mt-4 border-t border-white/[0.06] pt-2",children:[e.jsxs("button",{type:"button",onClick:()=>me(i=>!i),className:"flex w-full items-center justify-between text-micro font-semibold uppercase tracking-wider text-muted hover:text-secondary transition-colors",children:[e.jsx("span",{children:"Technical details"}),e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:`transition-transform ${ie?"rotate-180":""}`,children:e.jsx("path",{d:"m6 9 6 6 6-6"})})]}),ie&&e.jsx("div",{className:"mt-2 space-y-0.5",children:de.map(([i,n])=>e.jsxs("div",{className:"flex gap-2 text-micro",children:[e.jsx("span",{className:"text-muted w-28 flex-shrink-0",children:i}),e.jsx("span",{className:"text-secondary truncate",children:n})]},i))})]}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-x-3 gap-y-1 text-micro text-muted opacity-60",children:[f&&e.jsx("span",{children:"j/k nav"}),e.jsx("span",{children:"a approve"}),e.jsx("span",{children:"r reject"}),e.jsx("span",{children:"n note"}),e.jsxs("span",{children:[_e?"⌘":"Ctrl","+Enter approve"]}),e.jsx("span",{children:"esc close"})]})]}),w&&e.jsxs("div",{className:"flex items-center gap-2 border-t border-white/[0.06] px-6 py-3",children:[e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:M.red,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",x2:"12",y1:"8",y2:"12"}),e.jsx("line",{x1:"12",x2:"12.01",y1:"16",y2:"16"})]}),e.jsx("p",{className:"text-caption text-red-300",children:w})]}),he&&e.jsx("div",{className:"relative mt-auto border-t border-white/[0.04] bg-black/60 px-6 py-5 backdrop-blur-xl",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[C&&e.jsx(se.button,{whileTap:{scale:.97},type:"button",onClick:H,disabled:V,className:"rounded-lg px-4 py-2 text-[14px] font-medium text-secondary transition-colors hover:text-red-400 disabled:opacity-40 focus:outline-none",children:E==="rejecting"?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"inline-block h-3 w-3 animate-spin rounded-full border-[1.5px] border-current border-t-transparent"}),"Rejecting"]}):"Reject"}),e.jsx("button",{type:"button",onClick:p,className:"rounded-lg px-2 py-2 text-[13px] text-muted transition-colors hover:text-secondary focus:outline-none",title:"Copy decision as JSON",children:xe?"Copied":"Copy JSON"})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("span",{className:"hidden text-[13px] text-muted sm:block",children:[_e?"⌘":"Ctrl","+Enter"]}),e.jsx(se.button,{whileTap:!y||V?void 0:{scale:.97},type:"button",onClick:k,disabled:!y||V,"data-modal-autofocus":"true",className:"rounded-lg px-6 py-2.5 text-[14px] font-semibold transition-all focus:outline-none",style:{backgroundColor:!y||V?"rgba(255,255,255,0.06)":M.lime,color:!y||V?"rgba(255,255,255,0.4)":"#000"},children:E==="approving"?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"inline-block h-3 w-3 animate-spin rounded-full border-[1.5px] border-black/40 border-t-black"}),"Approving"]}):"Approve"})]})]})})]})})}const Ae=40;function ke(c,t){return!c||c.trim().length===0?t:Te(c.trim())||t}function Me(c,t,h){const y=c==="approve"?`Approval failed for ${t} decision${t===1?"":"s"}.`:`Rejection failed for ${t} decision${t===1?"":"s"}.`;return ke(h,y)}function Qe(c,t){return`${c}_${t}`}const it=l.memo(function({decisions:t,focusDecisionId:h=null,onFocusDecisionHandled:y,onApproveDecision:C,onRejectDecision:b,onApproveAll:_,onBulkDecisionAction:f,mutationState:Y,showHeader:R=!0,panelStyle:X="card",className:E}){var pe;const $=Re(),[w,v]=l.useState(!1),[g,F]=l.useState(new Set),[N,W]=l.useState(new Set),[z,P]=l.useState(new Set),{enqueue:xe,ToastRenderer:ne}=We(),[ie,me]=l.useState("approve_selected"),[K,ae]=l.useState(""),[L,m]=l.useState(null),[le,q]=l.useState(Ae),[u,T]=l.useState(null),U=l.useRef(null),p=l.useMemo(()=>{const r=new Set;return[...t].filter(a=>r.has(a.id)?!1:(r.add(a.id),!0)).sort((a,s)=>{if(a.waitingMinutes!==s.waitingMinutes)return s.waitingMinutes-a.waitingMinutes;const o=Date.parse(a.requestedAt??a.updatedAt??""),d=Date.parse(s.requestedAt??s.updatedAt??""),D=Number.isFinite(o)?o:0;return(Number.isFinite(d)?d:0)-D})},[t]);l.useEffect(()=>{W(r=>{const a=new Set(p.map(o=>o.id)),s=new Set;for(const o of r)a.has(o)&&s.add(o);return s})},[p]);const O=N.size,k=l.useMemo(()=>p.filter(r=>!z.has(r.id)).slice(0,le),[p,le,z]),H=l.useMemo(()=>{if(k.length===0)return!1;for(const r of k)if(!N.has(r.id))return!1;return!0},[N,k]),oe=l.useMemo(()=>u?p.find(r=>r.id===u)??null:null,[u,p]),ee=l.useMemo(()=>u?p.findIndex(r=>r.id===u):-1,[u,p]),J=l.useCallback(r=>{const a=ee+r;a>=0&&a<p.length&&T(p[a].id)},[ee,p]),he=async(r,a)=>{m(null),F(o=>{const d=new Set(o);return d.add(r),d});const s=await C(r,a);return s.failed>0?m(Me("approve",s.failed,s.firstError)):s.updated>0&&m("Decision approved. Changes synced."),F(o=>{const d=new Set(o);return d.delete(r),d}),s},Ce=b?async(r,a)=>{m(null),F(o=>{const d=new Set(o);return d.add(r),d});const s=await b(r,a);return s.failed>0?m(Me("reject",s.failed,s.firstError)):s.updated>0&&m("Decision rejected. Changes synced."),F(o=>{const d=new Set(o);return d.delete(r),d}),s}:void 0;l.useEffect(()=>{q(r=>p.length===0?0:Math.min(Math.max(Ae,r),p.length))},[p.length]),l.useEffect(()=>{const r=(h??"").trim();if(!r){U.current=null;return}U.current===r||!p.some(s=>s.id===r)||(U.current=r,T(r),y==null||y(r))},[h,y,p]);const fe=r=>{W(a=>{const s=new Set(a);return s.has(r)?s.delete(r):s.add(r),s})},V=()=>{W(r=>{if(k.length===0)return r;const a=new Set(r),s=H;for(const o of k)s?a.delete(o.id):a.add(o.id);return a})},te=l.useMemo(()=>{const r=p.map(s=>s.id).filter(s=>N.has(s)),a=k.map(s=>s.id);return[{id:"approve_selected",label:`Approve selected (${r.length})`,action:"approve",ids:r},{id:"reject_selected",label:`Reject selected (${r.length})`,action:"reject",ids:r,hidden:!b},{id:"approve_visible",label:`Approve visible (${a.length})`,action:"approve",ids:a},{id:"reject_visible",label:`Reject visible (${a.length})`,action:"reject",ids:a,hidden:!b}].filter(s=>!s.hidden)},[b,N,p,k]),S=l.useMemo(()=>te.find(r=>r.id===ie)??te[0]??null,[ie,te]),ge=async(r,a,s)=>{if(r.length===0)return{updated:0,failed:0};if(a==="approve"&&r.length===p.length&&!s)return _();let o=0,d=0,D;for(const Se of r)try{const we=a==="approve"?await C(Se,s?{note:s}:void 0):b?await b(Se,s?{note:s}:void 0):{updated:0,failed:1};o+=we.updated,d+=we.failed,!D&&we.firstError&&(D=we.firstError)}catch{d+=1}return{updated:o,failed:d,firstError:D}},be=async()=>{if(!S||w)return;const r=S.ids;if(r.length===0){m("No decisions selected for this action.");return}m(null),v(!0),F(new Set(r));const a=K.trim();try{const s=f?await f(r,S.action,a.length>0?a:void 0):await ge(r,S.action,a.length>0?a:void 0),o=S.action==="approve"?"Approved":"Rejected";if(s.failed>0){const d=`${o} ${s.updated}; ${s.failed} failed.`,D=ke(s.firstError,d);m(D===d?d:`${d} ${D}`)}else s.updated>0?m(`${o} ${s.updated} decision${s.updated===1?"":"s"}.`):m("No decisions were updated.");W(new Set)}catch(s){const o=s instanceof Error?s.message:"";m(ke(o,"Bulk decision action failed."))}finally{v(!1),F(new Set)}},re=async r=>{if(!(g.has(r)||w)){m(null),F(a=>{const s=new Set(a);return s.add(r),s});try{const a=await C(r);a.failed>0?m(Me("approve",a.failed,a.firstError)):a.updated>0&&m("Decision approved.")}catch(a){const s=a instanceof Error?a.message:"";m(ke(s,"Decision approval failed."))}finally{F(a=>{const s=new Set(a);return s.delete(r),s}),W(a=>{if(!a.has(r))return a;const s=new Set(a);return s.delete(r),s})}}},ce=l.useCallback(r=>{g.has(r.id)||w||(P(a=>new Set(a).add(r.id)),xe({message:`Approved '${r.title.length>40?r.title.slice(0,40)+"…":r.title}'`,onUndo:()=>{P(a=>{const s=new Set(a);return s.delete(r.id),s})},onCommit:()=>{P(a=>{const s=new Set(a);return s.delete(r.id),s}),C(r.id).catch(()=>{m("Approval failed. Try again from the decision panel.")})}}))},[g,w,xe,C]);l.useEffect(()=>{if(!L)return;const r=window.setTimeout(()=>m(null),5200);return()=>window.clearTimeout(r)},[L]);const je=L!==null&&!L.toLowerCase().includes("fail"),j=w||g.size>0,de=Math.max(g.size,w?O:0),i=j?`Applying ${de} decision action${de===1?"":"s"}…`:L??null,n=j?"processing":L?je?"success":"warning":"idle",I=!$&&k.length<=32,B=S!==null&&S.ids.length>0&&!w,A=p.length;(pe=p[0])==null||pe.waitingMinutes;const Z=S!=null&&S.id.includes("visible")?"visible":"selected",x=(S==null?void 0:S.action)??"approve",ue=i!==null||n!=="idle",ye=X==="card"?Be:"div";return e.jsxs(ye,{className:ve("flex h-full min-h-0 flex-col",X==="card"&&"card-enter",E),children:[e.jsx(Ge,{open:u!==null,decision:oe,onClose:()=>T(null),onApprove:he,onReject:Ce,onNavigate:J,currentIndex:ee>=0?ee:void 0,totalCount:p.length}),R?e.jsxs("div",{className:"space-y-2.5 border-b border-subtle px-4 py-3.5",children:[e.jsx("div",{className:"flex items-start justify-between gap-3",children:e.jsxs("div",{className:"min-w-0",children:[e.jsxs("h2",{className:"inline-flex items-center gap-2 text-heading font-semibold text-white",children:[e.jsx(Q,{type:"decision",size:14}),"Decisions"]}),e.jsx("p",{className:"mt-0.5 text-caption text-secondary",children:A>0?`${A} decision${A===1?"":"s"} need${A===1?"s":""} your input`:"All clear — no decisions pending"})]})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[p.length>0&&e.jsx("button",{onClick:V,disabled:j,className:"control-pill h-8 flex-shrink-0 px-3 text-caption font-semibold disabled:opacity-45",children:H?"Clear all":"Select all"}),O>0&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:be,disabled:!B||j,"data-state":B?"active":"idle",className:"control-pill h-8 flex-shrink-0 px-3 text-caption font-semibold disabled:opacity-45",children:w?"Approving…":`Approve ${O} selected`}),b&&e.jsx("button",{type:"button",onClick:()=>me(Qe("reject",Z)),disabled:j,"data-state":x==="reject"?"active":"idle",className:ve("control-pill h-8 px-2.5 text-caption font-semibold disabled:opacity-45",x==="reject"&&"border-amber-300/35 bg-amber-400/[0.12] text-amber-100"),children:"Reject"})]})]}),ue?e.jsxs("div",{"aria-live":"polite",className:ve("flex min-h-[32px] items-center gap-2 rounded-lg border px-2.5 py-1.5 text-caption transition-colors",n==="processing"?"border-amber-300/25 bg-amber-400/[0.08] text-amber-100":n==="success"?"border-lime/30 bg-lime/10 text-lime":n==="warning"?"border-red-400/25 bg-red-500/[0.08] text-red-100":"border-strong bg-white/[0.02] text-secondary"),children:[n==="processing"?e.jsx("span",{"aria-hidden":!0,className:"h-3.5 w-3.5 rounded-full border-2 border-amber-200/45 border-t-transparent animate-spin"}):n==="success"?e.jsx(Q,{type:"decision",size:12,className:"opacity-90"}):n==="warning"?e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"opacity-90",children:[e.jsx("path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z"}),e.jsx("line",{x1:"12",x2:"12",y1:"9",y2:"13"}),e.jsx("line",{x1:"12",x2:"12.01",y1:"17",y2:"17"})]}):e.jsx("span",{"aria-hidden":!0,className:"h-1.5 w-1.5 rounded-full bg-white/35"}),e.jsx("span",{className:"min-w-0 truncate",children:i})]}):null]}):null,e.jsxs("div",{className:ve("min-h-0 flex-1 space-y-2 overflow-y-auto",R?"p-3":"p-0"),children:[p.length===0&&e.jsx("div",{className:"flex flex-col items-center gap-2.5 rounded-xl border border-subtle bg-white/[0.02] p-4 text-center",children:j?e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":!0,className:"h-5 w-5 rounded-full border-2 border-amber-200/45 border-t-transparent animate-spin"}),e.jsx("p",{className:"text-body text-secondary",children:"Finalizing decision updates…"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-faint",children:[e.jsx("path",{d:"M22 11.08V12a10 10 0 1 1-5.93-9.14"}),e.jsx("polyline",{points:"22 4 12 14.01 9 11.01"})]}),e.jsx("p",{className:"text-body text-secondary",children:"No pending decisions. All clear."})]})}),I?e.jsx(Ee,{mode:"popLayout",children:k.map((r,a)=>{const s=g.has(r.id),o=N.has(r.id);return e.jsx(se.article,{role:"button",tabIndex:0,onClick:()=>T(r.id),onKeyDown:d=>{(d.key==="Enter"||d.key===" ")&&(d.preventDefault(),T(r.id))},drag:!j&&!s?"x":!1,dragConstraints:{left:0,right:0},dragElastic:.3,onDragEnd:(d,D)=>{D.offset.x>120&&ce(r)},initial:w?{opacity:0,x:300}:{opacity:0,y:8,scale:.98},animate:{opacity:1,y:0,x:0,scale:1},exit:{opacity:0,x:300,scale:.95},transition:{duration:.25,ease:[.22,1,.36,1],...w?{delay:a*.04}:{}},layout:!0,className:"rounded-xl border bg-white/[0.03] px-3 py-2.5 transition-[border-color,box-shadow] cv-auto",style:{borderColor:o?`${M.lime}50`:"rgba(255, 255, 255, 0.1)",boxShadow:o?"0 0 0 1px rgba(191, 255, 0, 0.14)":"none"},children:e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx("input",{type:"checkbox",checked:o,onChange:()=>fe(r.id),disabled:s||j,onClick:d=>d.stopPropagation(),className:"mt-0.5 h-4 w-4 rounded border-white/20 bg-black/40 text-lime focus:ring-lime/40"}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"flex min-w-0 items-start gap-1.5 text-body font-medium text-white",title:r.title,children:[e.jsx(Q,{type:"decision",size:12,className:"mt-[3px] flex-shrink-0 opacity-90"}),e.jsx("span",{className:"line-clamp-2",children:r.title})]}),r.context&&e.jsx("p",{className:"mt-1 line-clamp-2 text-caption text-secondary",title:r.context,children:r.context}),e.jsxs("div",{className:"mt-1.5 flex items-center justify-between gap-2",children:[e.jsxs("p",{className:`min-w-0 truncate text-micro ${(()=>{const d=G(r.waitingMinutes);return d.tone==="urgent"?"text-red-400":d.tone==="attention"?"text-amber-400":"text-muted"})()}`,title:`${r.agentName??"OrgX Autopilot"} · ${G(r.waitingMinutes).text}`,children:[r.agentName??"OrgX Autopilot"," · ",G(r.waitingMinutes).text]}),e.jsx("button",{onClick:d=>{d.stopPropagation(),re(r.id)},disabled:s||j,className:"flex-shrink-0 rounded-md border border-lime/25 bg-lime/10 px-2.5 py-1 text-micro font-semibold text-lime transition-colors hover:bg-lime/20 disabled:cursor-not-allowed disabled:border-white/10 disabled:bg-white/[0.08] disabled:text-secondary",children:s?"Approving…":"Approve"}),b&&e.jsx("button",{onClick:d=>{d.stopPropagation(),T(r.id)},disabled:s||j,className:"flex-shrink-0 rounded-md border border-white/[0.08] bg-white/[0.03] px-2.5 py-1 text-micro font-semibold text-secondary transition-colors hover:border-red-400/30 hover:bg-red-400/[0.08] hover:text-red-300 disabled:cursor-not-allowed disabled:opacity-40",children:"Reject"})]})]})})]})},r.id)})}):e.jsx(e.Fragment,{children:k.map(r=>{const a=g.has(r.id),s=N.has(r.id);return e.jsx("article",{role:"button",tabIndex:0,onClick:()=>T(r.id),onKeyDown:o=>{(o.key==="Enter"||o.key===" ")&&(o.preventDefault(),T(r.id))},className:"rounded-xl border bg-white/[0.03] px-3 py-2.5 transition-[border-color,box-shadow] cv-auto",style:{borderColor:s?`${M.lime}50`:"rgba(255, 255, 255, 0.1)",boxShadow:s?"0 0 0 1px rgba(191, 255, 0, 0.14)":"none"},children:e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx("input",{type:"checkbox",checked:s,onChange:()=>fe(r.id),disabled:a||j,onClick:o=>o.stopPropagation(),className:"mt-0.5 h-4 w-4 rounded border-white/20 bg-black/40 text-lime focus:ring-lime/40"}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"flex min-w-0 items-start gap-1.5 text-body font-medium text-white",title:r.title,children:[e.jsx(Q,{type:"decision",size:12,className:"mt-[3px] flex-shrink-0 opacity-90"}),e.jsx("span",{className:"line-clamp-2",children:r.title})]}),r.context&&e.jsx("p",{className:"mt-1 line-clamp-2 text-caption text-secondary",title:r.context,children:r.context}),e.jsxs("div",{className:"mt-1.5 flex items-center justify-between gap-2",children:[e.jsxs("p",{className:`min-w-0 truncate text-micro ${(()=>{const o=G(r.waitingMinutes);return o.tone==="urgent"?"text-red-400":o.tone==="attention"?"text-amber-400":"text-muted"})()}`,title:`${r.agentName??"OrgX Autopilot"} · ${G(r.waitingMinutes).text}`,children:[r.agentName??"OrgX Autopilot"," · ",G(r.waitingMinutes).text]}),e.jsx("button",{onClick:o=>{o.stopPropagation(),re(r.id)},disabled:a||j,className:"flex-shrink-0 rounded-md border border-lime/25 bg-lime/10 px-2.5 py-1 text-micro font-semibold text-lime transition-colors hover:bg-lime/20 disabled:cursor-not-allowed disabled:border-white/10 disabled:bg-white/[0.08] disabled:text-secondary",children:a?"Approving…":"Approve"}),b&&e.jsx("button",{onClick:o=>{o.stopPropagation(),T(r.id)},disabled:a||j,className:"flex-shrink-0 rounded-md border border-white/[0.08] bg-white/[0.03] px-2.5 py-1 text-micro font-semibold text-secondary transition-colors hover:border-red-400/30 hover:bg-red-400/[0.08] hover:text-red-300 disabled:cursor-not-allowed disabled:opacity-40",children:"Reject"})]})]})})]})},r.id)})}),k.length<p.length&&e.jsxs("button",{onClick:()=>q(r=>Math.min(p.length,r+Ae)),className:"w-full rounded-xl border border-white/[0.08] bg-white/[0.02] px-3 py-2 text-caption text-secondary transition-colors hover:bg-white/[0.05]",children:["Load more (",p.length-k.length," remaining)"]})]}),e.jsx(ne,{})]})});export{it as DecisionQueue};
1
+ import{r as l,j as e}from"./cNrhgGc1.js";import{E as Z,d as M,r as $e,W as Q,K as Ie,X as Fe,Y as Pe,M as Le,h as Te,P as Be,w as ve}from"./C9jy61eu.js";import{E as De}from"./C8uM3AX8.js";import{A as Ee,m as se,u as Re}from"./CxQ08qFN.js";import{u as We}from"./B6wPWJ35.js";import"./C-KIc3Wc.js";import"./BJgZIVUQ.js";const ze={pr:"⎋",file:"◇",artifact:"▪",log:"▸",decision:"◈"};function Ue(c){return c>=.8?"#BFFF00":c>=.5?"#F5B700":"#FF6B88"}function Oe(c){const t=c.match(/https?:\/\/\S+/);return t?t[0]:null}function Xe({evidenceType:c,title:t,summary:h,sourceUrl:y,confidence:C,payload:b,icon:_,label:f,onOpenTerminal:Y}){const[R,X]=l.useState(!1),E=t??f??null,$=c??(_?_.toUpperCase():null),w=_?ze[_]:null,v=_==="pr"&&f?Oe(f):null;return e.jsxs("div",{className:"rounded-xl border border-white/[0.06] bg-white/[0.02] px-3 py-2.5",children:[e.jsxs("div",{className:"flex items-start gap-2.5 cursor-pointer",onClick:()=>X(g=>!g),children:[($||w)&&e.jsxs("span",{className:"mt-0.5 flex-shrink-0 rounded bg-white/[0.06] px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wider text-secondary",children:[w?e.jsx("span",{className:"mr-1",children:w}):null,$]}),e.jsxs("div",{className:"min-w-0 flex-1",children:[E&&e.jsx("p",{className:"text-body font-medium text-primary",children:y?e.jsx("a",{href:y,target:"_blank",rel:"noopener noreferrer",className:"text-[#D8FFA1] hover:underline",onClick:g=>g.stopPropagation(),children:E}):v?e.jsx("a",{href:v,target:"_blank",rel:"noopener noreferrer",className:"text-[#D8FFA1] hover:underline",onClick:g=>g.stopPropagation(),children:E}):E}),h&&e.jsx("p",{className:`mt-0.5 text-caption text-secondary ${R?"":"line-clamp-2"}`,children:h})]}),e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:`mt-1 flex-shrink-0 text-muted transition-transform ${R?"rotate-180":""}`,children:e.jsx("path",{d:"m6 9 6 6 6-6"})})]}),C!=null&&e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("div",{className:"h-1 flex-1 overflow-hidden rounded-full bg-white/[0.06]",children:e.jsx("div",{className:"h-full rounded-full transition-all",style:{width:`${Math.round(C*100)}%`,backgroundColor:Ue(C)}})}),e.jsxs("span",{className:"text-micro text-muted tabular-nums",children:[Math.round(C*100),"%"]})]}),e.jsx(Ee,{children:R&&e.jsx(se.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.2},className:"overflow-hidden",children:e.jsxs("div",{className:"mt-2 space-y-2",children:[_==="log"&&Y&&e.jsxs("button",{type:"button",onClick:g=>{g.stopPropagation(),Y()},className:"inline-flex items-center gap-1.5 rounded-lg border border-white/[0.12] bg-white/[0.04] px-3 py-1.5 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.08]",children:[e.jsx("span",{className:"font-mono text-micro",children:">_"}),"Open in terminal"]}),b&&Object.keys(b).length>0&&e.jsx("pre",{className:"max-h-40 overflow-auto rounded-lg bg-black/40 p-2.5 text-micro text-secondary font-mono",children:JSON.stringify(b,null,2)})]})})})]})}function Ke({segments:c}){return c.length===0?null:e.jsx("nav",{className:"flex items-center gap-1.5 min-w-0 text-caption text-secondary",children:c.map((t,h)=>e.jsxs("span",{className:"flex items-center gap-1.5 min-w-0",children:[h>0&&e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"flex-shrink-0 text-faint",children:e.jsx("path",{d:"m9 18 6-6-6-6"})}),t.icon&&e.jsx(Z,{type:t.icon,size:11,className:"flex-shrink-0 opacity-80"}),t.onClick?e.jsx("button",{type:"button",onClick:t.onClick,className:"truncate transition-colors hover:text-primary",children:t.label}):e.jsx("span",{className:"truncate",children:t.label})]},h))})}const _e=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent);function Je(c){try{return JSON.stringify(c,null,2)}catch{return null}}function qe(c){if(typeof c!="string")return null;const t=c.trim().toLowerCase();return t==="rejected"?"declined":t==="approved"||t==="declined"||t==="cancelled"?t:null}function Ne(c,t){return!c||c.trim().length===0?t:Te(c.trim())||t}function Ve(c){switch(c){case"spawn_guard_blocked":return"Spawn Guard";case"autopilot_failure":return"Autopilot Failure";case"budget_exceeded":return"Budget Exceeded";case"scope_change":return"Scope Change";case"conflict_resolution":return"Conflict Resolution";case"approval_required":return"Approval Required";case"review_required":return"Review Required";case"permission_request":return"Permission Request";default:return c.replace(/[_-]/g," ").replace(/\b\w/g,t=>t.toUpperCase())}}function Ge(c){const t=c.toLowerCase();return t==="critical"||t==="p0"?M.red:t==="high"||t==="p1"?M.amber:t==="medium"||t==="p2"?M.iris:"rgba(255,255,255,0.5)"}function Qe({open:c,decision:t,onClose:h,onApprove:y,onReject:C,initiativeTitle:b,workstreamTitle:_,onNavigate:f,currentIndex:Y,totalCount:R,onFocusRunId:X}){const[E,$]=l.useState("idle"),[w,v]=l.useState(null),[g,F]=l.useState(null),[N,W]=l.useState(""),[z,P]=l.useState(!1),[xe,ne]=l.useState(!1),[ie,me]=l.useState(!1),K=l.useRef(null),ae=l.useRef(),L=l.useRef(h);L.current=h,l.useEffect(()=>{if(c){$("idle"),v(null);const i=(t==null?void 0:t.selectedOptionId)??(t!=null&&t.options&&t.options.length===1?t.options[0].id:null);F(i),W(""),P(!1),ne(!1),me(!1)}return()=>{ae.current&&clearTimeout(ae.current)}},[c,t==null?void 0:t.id]);const m=t==null?void 0:t.metadata,le=l.useMemo(()=>{if(!m)return[];const i=m,n=i.decision_options??i.options??i.actions??null;if(!Array.isArray(n))return[];const I=[],B=new Set;for(let A=0;A<n.length;A+=1){const G=n[A];if(typeof G=="string"){const pe=G.trim();if(!pe)continue;const r=`option-${A+1}`;if(B.has(r))continue;B.add(r),I.push({id:r,label:pe,description:null,impliedStatus:null,actionType:null,requiresNote:!1});continue}if(!G||typeof G!="object")continue;const x=G,ue=typeof x.id=="string"&&x.id.trim()||typeof x.option_id=="string"&&x.option_id.trim()||typeof x.action_id=="string"&&x.action_id.trim()||`option-${A+1}`;if(B.has(ue))continue;const ye=typeof x.label=="string"&&x.label.trim()||typeof x.title=="string"&&x.title.trim()||typeof x.name=="string"&&x.name.trim()||typeof x.action=="string"&&x.action.trim()||null;ye&&(B.add(ue),I.push({id:ue,label:ye,description:typeof x.description=="string"?x.description:null,impliedStatus:qe(x.implied_status)??qe(x.status),actionType:typeof x.action_type=="string"&&x.action_type||typeof x.type=="string"&&x.type||null,requiresNote:x.requires_note===!0||x.requiresNote===!0||x.note_required===!0}))}return I.slice(0,12)},[m]),q=l.useMemo(()=>t!=null&&t.options&&t.options.length>0?t.options:le,[t==null?void 0:t.options,le]),u=l.useMemo(()=>q.find(i=>i.id===g)??null,[q,g]),T=l.useMemo(()=>{const i=((t==null?void 0:t.context)??"").trim();if(i)return i;if(!m)return"";const n=m,I=(typeof n.summary=="string"?n.summary:null)??(typeof n.description=="string"?n.description:null)??"";return String(I??"").trim()},[t==null?void 0:t.context,m]),U=l.useMemo(()=>{const i=(t==null?void 0:t.waitingMinutes)??0;return i>=15?M.red:i>=5?M.amber:M.teal},[t==null?void 0:t.waitingMinutes]),p=l.useCallback(async()=>{if(!t)return;const i=Je({decision:t,metadata:m});if(i)try{await navigator.clipboard.writeText(i),ne(!0),setTimeout(()=>ne(!1),2e3)}catch{}},[t,m]),O=l.useCallback(()=>{const i=N.trim(),n=u==null?void 0:u.id;if(!(!i&&!n))return{note:i.length>0?i:void 0,optionId:n??void 0}},[N,u]),k=l.useCallback(async()=>{if(!t||!y)return;if(q.length>0&&!u){v("Select an option before approving this decision.");return}if(u!=null&&u.requiresNote&&N.trim().length===0){v("A note is required for the selected option."),P(!0),requestAnimationFrame(()=>{var n;return(n=K.current)==null?void 0:n.focus()});return}let i=!1;if($(n=>n==="approving"||n==="rejecting"?n:(i=!0,"approving")),!!i){v(null);try{const n=await y(t.id,O());n.failed>0?($("error"),v(Ne(n.firstError,"Approval failed. Please try again."))):($("success"),ae.current=setTimeout(()=>L.current(),800))}catch(n){$("error");const I=n instanceof Error?n.message:"";v(Ne(I,"Approval failed."))}}},[O,t,N,y,q.length,u]),H=l.useCallback(async()=>{if(!t||!C)return;if(q.length>0&&!u){v("Select an option before rejecting this decision.");return}if(u!=null&&u.requiresNote&&N.trim().length===0){v("A note is required for the selected option."),P(!0),requestAnimationFrame(()=>{var n;return(n=K.current)==null?void 0:n.focus()});return}let i=!1;if($(n=>n==="approving"||n==="rejecting"?n:(i=!0,"rejecting")),!!i){v(null);try{const n=await C(t.id,O());n.failed>0?($("error"),v(Ne(n.firstError,"Rejection failed. Please try again."))):($("rejected"),ae.current=setTimeout(()=>L.current(),800))}catch(n){$("error");const I=n instanceof Error?n.message:"";v(Ne(I,"Rejection failed."))}}},[O,t,N,C,q.length,u]);if(l.useEffect(()=>{if(!c)return;const i=n=>{var B;if((n.metaKey||n.ctrlKey)&&n.key==="Enter"){n.preventDefault(),k();return}const I=(B=n.target)==null?void 0:B.tagName;if(!(I==="INPUT"||I==="TEXTAREA"))switch(n.key){case"j":n.preventDefault(),f==null||f(1);break;case"k":n.preventDefault(),f==null||f(-1);break;case"a":n.preventDefault(),k();break;case"r":n.preventDefault(),H();break;case"n":n.preventDefault(),P(A=>!A),z||requestAnimationFrame(()=>{var A;return(A=K.current)==null?void 0:A.focus()});break}};return document.addEventListener("keydown",i),()=>document.removeEventListener("keydown",i)},[c,k,H,f,z]),!c||!t)return null;const oe=E==="approving"||E==="rejecting",ee=E==="success"||E==="rejected",J=(t.status??"pending").toLowerCase(),he=!J.includes("approved")&&!J.includes("resolved")&&!J.includes("rejected")&&!J.includes("declined")&&!J.includes("cancelled"),Ce=q.length>0&&!u,fe=(u==null?void 0:u.requiresNote)===!0&&N.trim().length===0,V=oe||Ce||fe,te=t.evidenceRefs??[],S=te.length>0,ge=t.recommendedAction??null,be=t.decisionType??null,re=t.priority??null,ce=t.occurrenceCount??null,je=t.sourceRunId??null,j=[];b&&j.push({label:b,icon:"initiative"}),_&&j.push({label:_,icon:"workstream"});const de=[["ID",t.id],["Type",t.decisionType],["Dedupe key",t.dedupeKey],["Source system",t.sourceSystem],["Conflict source",t.conflictSource],["Agent ID",t.agentId],["Source run",t.sourceRunId],["Source session",t.sourceSessionId],["Source stream",t.sourceStreamId]].filter(([,i])=>i!=null);if(ee){const i=E==="success",n=i?M.lime:M.red;return e.jsx($e,{open:c,onClose:h,maxWidth:"max-w-xl",fitContent:!0,children:e.jsxs("div",{className:"flex flex-col items-center justify-center px-8 py-12",children:[e.jsx("div",{className:"mb-4 flex h-16 w-16 items-center justify-center rounded-full",style:{backgroundColor:`${n}18`,border:`1.5px solid ${n}40`},children:i?e.jsx("svg",{width:"28",height:"28",viewBox:"0 0 24 24",fill:"none",stroke:n,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):e.jsxs("svg",{width:"28",height:"28",viewBox:"0 0 24 24",fill:"none",stroke:n,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 6L6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})}),e.jsx("p",{className:"text-heading font-semibold text-white",children:i?"Approved":"Rejected"}),e.jsx("p",{className:"mt-1 text-body text-secondary",children:t.title})]})})}return e.jsx($e,{open:c,onClose:h,maxWidth:"max-w-xl",children:e.jsxs("div",{className:"flex h-full min-h-0 w-full flex-col",children:[e.jsx("div",{className:"h-[2px] w-full flex-shrink-0",style:{background:`linear-gradient(90deg, ${U}60, ${U}20, transparent)`}}),f&&e.jsxs("div",{className:"flex items-center justify-between px-6 pt-3 pb-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>f(-1),className:"rounded p-1 text-muted hover:text-secondary hover:bg-white/[0.06] transition-colors",title:"Previous (k)",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"m15 18-6-6 6-6"})})}),e.jsx("button",{type:"button",onClick:()=>f(1),className:"rounded p-1 text-muted hover:text-secondary hover:bg-white/[0.06] transition-colors",title:"Next (j)",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"m9 18 6-6-6-6"})})}),Y!=null&&R!=null&&e.jsxs("span",{className:"text-micro text-muted tabular-nums",children:[Y+1," of ",R]})]}),e.jsx("button",{type:"button",onClick:h,"aria-label":"Close",className:"rounded p-1 text-muted hover:text-secondary hover:bg-white/[0.06] transition-colors",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M18 6 6 18M6 6l12 12"})})})]}),j.length>0&&e.jsx("div",{className:"px-6 pt-2",children:e.jsx(Ke,{segments:j})}),e.jsxs("div",{className:"flex items-start justify-between gap-3 px-6 pt-4 pb-4",children:[e.jsx("div",{className:"min-w-0 flex-1",children:e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-lg",style:{backgroundColor:`${U}14`,border:`1px solid ${U}30`},children:e.jsx(Z,{type:"decision",size:14})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h2",{className:"text-title font-medium leading-tight text-white mb-2",children:t.title||"Decision Required"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-body text-secondary",children:[e.jsx("span",{children:t.agentName||"OrgX Autopilot"}),e.jsx("span",{className:"text-white/[0.15]",children:"|"}),e.jsx("span",{children:Q(t.waitingMinutes).text}),be&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-white/[0.15]",children:"|"}),e.jsx("span",{className:"text-primary",children:Ve(be)})]}),re&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-white/[0.15]",children:"|"}),e.jsx("span",{className:"font-medium",style:{color:Ge(re)},children:re})]})]}),ce!=null&&ce>1&&e.jsxs("p",{className:"mt-2 text-caption text-muted",children:["Seen ",ce," times",t.firstSeenAt&&e.jsxs(e.Fragment,{children:[" · first ",Ie(t.firstSeenAt)]}),t.lastSeenAt&&e.jsxs(e.Fragment,{children:[" · last ",Ie(t.lastSeenAt)]})]})]})]})}),!f&&e.jsx("button",{type:"button",onClick:h,"aria-label":"Close",className:"mt-0.5 flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-lg text-muted transition-colors hover:bg-white/[0.06] hover:text-white",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 6L6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto px-6 pb-4",children:[(t.initiativeId||t.workstreamId)&&e.jsx("div",{className:"mb-4",children:e.jsx(Fe,{nodes:Pe({initiativeId:t.initiativeId,initiativeTitle:b,workstreamId:t.workstreamId,workstreamTitle:_,agentName:t.agentName,agentId:t.agentId}),activeId:t.workstreamId,compact:!0})}),ge&&e.jsxs("div",{className:"mb-4 rounded-xl border border-cyan-300/[0.28] bg-cyan-500/[0.12] px-4 py-3",children:[e.jsx("p",{className:"text-micro font-semibold uppercase tracking-wider text-cyan-200 mb-1",children:"Recommended"}),e.jsx("p",{className:"text-body text-cyan-100",children:ge})]}),S&&e.jsxs("div",{className:"mb-4",children:[e.jsx("p",{className:"mb-2 px-1 text-micro font-semibold uppercase tracking-wider text-muted",children:"Evidence"}),e.jsx("div",{className:"space-y-1.5",children:te.map((i,n)=>e.jsx(Xe,{evidenceType:i.evidenceType,title:i.title,summary:i.summary,sourceUrl:i.sourceUrl,confidence:i.confidence,payload:i.payload},n))})]}),T?e.jsx("div",{className:"rounded-xl border border-white/[0.06] bg-white/[0.02] px-4 py-3",children:e.jsx(Le,{text:T,mode:"block"})}):e.jsx("p",{className:"px-1 text-body text-muted italic",children:"No additional context provided."}),q.length>0&&e.jsxs("div",{className:"mt-8",children:[e.jsx("p",{className:"mb-3 px-1 text-[11px] font-semibold uppercase tracking-widest text-muted",children:"Options"}),e.jsx("div",{className:"space-y-1 relative",children:q.map(i=>{const n=g===i.id;return e.jsxs("button",{type:"button",onClick:()=>{F(n?null:i.id),i.requiresNote&&P(!0)},disabled:oe,className:"group relative flex w-full items-start gap-4 px-4 py-4 text-left focus:outline-none",children:[n&&e.jsx(se.div,{layoutId:"decision-option-bg",className:"absolute inset-0 rounded-xl",style:{backgroundColor:`${M.lime}12`},transition:{type:"spring",stiffness:400,damping:25}}),!n&&e.jsx("div",{className:"absolute inset-0 rounded-xl opacity-0 transition-opacity group-hover:bg-white/[0.03]"}),e.jsx("div",{className:"relative mt-0.5 flex h-5 w-5 flex-shrink-0 items-center justify-center rounded-full border-[1.5px] transition-colors",style:{borderColor:n?M.lime:"rgba(255,255,255,0.2)"},children:e.jsx(Ee,{children:n&&e.jsx(se.div,{initial:{scale:0},animate:{scale:1},exit:{scale:0},transition:{type:"spring",stiffness:500,damping:30},className:"h-2.5 w-2.5 rounded-full",style:{backgroundColor:M.lime}})})}),e.jsxs("div",{className:"relative min-w-0 flex-1",children:[e.jsx("span",{className:`block text-[15px] ${n?"font-medium text-white":"text-primary"}`,children:i.label}),i.description&&e.jsx("p",{className:"mt-1 text-[13px] leading-relaxed text-secondary",children:i.description}),i.requiresNote&&e.jsx("p",{className:"mt-1.5 text-[11px] font-medium uppercase tracking-wider text-amber-400",children:"Note required"})]})]},i.id)})})]}),he&&e.jsxs("div",{className:"mt-4",children:[e.jsxs("button",{type:"button",onClick:()=>{P(i=>!i),z||requestAnimationFrame(()=>{var i;return(i=K.current)==null?void 0:i.focus()})},className:"flex w-full items-center gap-2 px-1 text-caption text-secondary transition-colors hover:text-white",children:[e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"transition-transform",style:{transform:z?"rotate(90deg)":"rotate(0deg)"},children:e.jsx("polyline",{points:"9 18 15 12 9 6"})}),"Add a note"]}),z&&e.jsxs("div",{className:"mt-2",children:[e.jsx("textarea",{ref:K,value:N,onChange:i=>W(i.target.value),disabled:oe,placeholder:"Optional context for this decision...",rows:3,className:"w-full resize-none rounded-xl border border-white/[0.08] bg-white/[0.03] px-4 py-3 text-body text-primary placeholder-white/30 outline-none transition-colors focus:border-white/[0.16] focus:bg-white/[0.04]"}),(u==null?void 0:u.requiresNote)&&N.trim().length===0&&e.jsx("p",{className:"mt-2 text-caption text-amber-300",children:"This option requires a note before submission."})]})]}),je&&X&&e.jsx("div",{className:"mt-4",children:e.jsxs("button",{type:"button",onClick:()=>X(je),className:"inline-flex items-center gap-1.5 text-caption text-[#D8FFA1] transition-colors hover:text-white",children:[e.jsx(Z,{type:"session",size:12}),"View source run"]})}),e.jsx("div",{className:"mt-4 border-t border-white/[0.06] pt-4",children:e.jsx(De,{entityType:"decision",entityId:t.id})}),de.length>0&&e.jsxs("div",{className:"mt-4 border-t border-white/[0.06] pt-2",children:[e.jsxs("button",{type:"button",onClick:()=>me(i=>!i),className:"flex w-full items-center justify-between text-micro font-semibold uppercase tracking-wider text-muted hover:text-secondary transition-colors",children:[e.jsx("span",{children:"Technical details"}),e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:`transition-transform ${ie?"rotate-180":""}`,children:e.jsx("path",{d:"m6 9 6 6 6-6"})})]}),ie&&e.jsx("div",{className:"mt-2 space-y-0.5",children:de.map(([i,n])=>e.jsxs("div",{className:"flex gap-2 text-micro",children:[e.jsx("span",{className:"text-muted w-28 flex-shrink-0",children:i}),e.jsx("span",{className:"text-secondary truncate",children:n})]},i))})]}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-x-3 gap-y-1 text-micro text-muted opacity-60",children:[f&&e.jsx("span",{children:"j/k nav"}),e.jsx("span",{children:"a approve"}),e.jsx("span",{children:"r reject"}),e.jsx("span",{children:"n note"}),e.jsxs("span",{children:[_e?"⌘":"Ctrl","+Enter approve"]}),e.jsx("span",{children:"esc close"})]})]}),w&&e.jsxs("div",{className:"flex items-center gap-2 border-t border-white/[0.06] px-6 py-3",children:[e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:M.red,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",x2:"12",y1:"8",y2:"12"}),e.jsx("line",{x1:"12",x2:"12.01",y1:"16",y2:"16"})]}),e.jsx("p",{className:"text-caption text-red-300",children:w})]}),he&&e.jsx("div",{className:"relative mt-auto border-t border-white/[0.04] bg-black/60 px-6 py-5 backdrop-blur-xl",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[C&&e.jsx(se.button,{whileTap:{scale:.97},type:"button",onClick:H,disabled:V,className:"rounded-lg px-4 py-2 text-[14px] font-medium text-secondary transition-colors hover:text-red-400 disabled:opacity-40 focus:outline-none",children:E==="rejecting"?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"inline-block h-3 w-3 animate-spin rounded-full border-[1.5px] border-current border-t-transparent"}),"Rejecting"]}):"Reject"}),e.jsx("button",{type:"button",onClick:p,className:"rounded-lg px-2 py-2 text-[13px] text-muted transition-colors hover:text-secondary focus:outline-none",title:"Copy decision as JSON",children:xe?"Copied":"Copy JSON"})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("span",{className:"hidden text-[13px] text-muted sm:block",children:[_e?"⌘":"Ctrl","+Enter"]}),e.jsx(se.button,{whileTap:!y||V?void 0:{scale:.97},type:"button",onClick:k,disabled:!y||V,"data-modal-autofocus":"true",className:"rounded-lg px-6 py-2.5 text-[14px] font-semibold transition-all focus:outline-none",style:{backgroundColor:!y||V?"rgba(255,255,255,0.06)":M.lime,color:!y||V?"rgba(255,255,255,0.4)":"#000"},children:E==="approving"?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"inline-block h-3 w-3 animate-spin rounded-full border-[1.5px] border-black/40 border-t-black"}),"Approving"]}):"Approve"})]})]})})]})})}const Ae=40;function ke(c,t){return!c||c.trim().length===0?t:Te(c.trim())||t}function Me(c,t,h){const y=c==="approve"?`Approval failed for ${t} decision${t===1?"":"s"}.`:`Rejection failed for ${t} decision${t===1?"":"s"}.`;return ke(h,y)}function Ze(c,t){return`${c}_${t}`}const it=l.memo(function({decisions:t,focusDecisionId:h=null,onFocusDecisionHandled:y,onApproveDecision:C,onRejectDecision:b,onApproveAll:_,onBulkDecisionAction:f,mutationState:Y,showHeader:R=!0,panelStyle:X="card",className:E}){var pe;const $=Re(),[w,v]=l.useState(!1),[g,F]=l.useState(new Set),[N,W]=l.useState(new Set),[z,P]=l.useState(new Set),{enqueue:xe,ToastRenderer:ne}=We(),[ie,me]=l.useState("approve_selected"),[K,ae]=l.useState(""),[L,m]=l.useState(null),[le,q]=l.useState(Ae),[u,T]=l.useState(null),U=l.useRef(null),p=l.useMemo(()=>{const r=new Set;return[...t].filter(a=>r.has(a.id)?!1:(r.add(a.id),!0)).sort((a,s)=>{if(a.waitingMinutes!==s.waitingMinutes)return s.waitingMinutes-a.waitingMinutes;const o=Date.parse(a.requestedAt??a.updatedAt??""),d=Date.parse(s.requestedAt??s.updatedAt??""),D=Number.isFinite(o)?o:0;return(Number.isFinite(d)?d:0)-D})},[t]);l.useEffect(()=>{W(r=>{const a=new Set(p.map(o=>o.id)),s=new Set;for(const o of r)a.has(o)&&s.add(o);return s})},[p]);const O=N.size,k=l.useMemo(()=>p.filter(r=>!z.has(r.id)).slice(0,le),[p,le,z]),H=l.useMemo(()=>{if(k.length===0)return!1;for(const r of k)if(!N.has(r.id))return!1;return!0},[N,k]),oe=l.useMemo(()=>u?p.find(r=>r.id===u)??null:null,[u,p]),ee=l.useMemo(()=>u?p.findIndex(r=>r.id===u):-1,[u,p]),J=l.useCallback(r=>{const a=ee+r;a>=0&&a<p.length&&T(p[a].id)},[ee,p]),he=async(r,a)=>{m(null),F(o=>{const d=new Set(o);return d.add(r),d});const s=await C(r,a);return s.failed>0?m(Me("approve",s.failed,s.firstError)):s.updated>0&&m("Decision approved. Changes synced."),F(o=>{const d=new Set(o);return d.delete(r),d}),s},Ce=b?async(r,a)=>{m(null),F(o=>{const d=new Set(o);return d.add(r),d});const s=await b(r,a);return s.failed>0?m(Me("reject",s.failed,s.firstError)):s.updated>0&&m("Decision rejected. Changes synced."),F(o=>{const d=new Set(o);return d.delete(r),d}),s}:void 0;l.useEffect(()=>{q(r=>p.length===0?0:Math.min(Math.max(Ae,r),p.length))},[p.length]),l.useEffect(()=>{const r=(h??"").trim();if(!r){U.current=null;return}U.current===r||!p.some(s=>s.id===r)||(U.current=r,T(r),y==null||y(r))},[h,y,p]);const fe=r=>{W(a=>{const s=new Set(a);return s.has(r)?s.delete(r):s.add(r),s})},V=()=>{W(r=>{if(k.length===0)return r;const a=new Set(r),s=H;for(const o of k)s?a.delete(o.id):a.add(o.id);return a})},te=l.useMemo(()=>{const r=p.map(s=>s.id).filter(s=>N.has(s)),a=k.map(s=>s.id);return[{id:"approve_selected",label:`Approve selected (${r.length})`,action:"approve",ids:r},{id:"reject_selected",label:`Reject selected (${r.length})`,action:"reject",ids:r,hidden:!b},{id:"approve_visible",label:`Approve visible (${a.length})`,action:"approve",ids:a},{id:"reject_visible",label:`Reject visible (${a.length})`,action:"reject",ids:a,hidden:!b}].filter(s=>!s.hidden)},[b,N,p,k]),S=l.useMemo(()=>te.find(r=>r.id===ie)??te[0]??null,[ie,te]),ge=async(r,a,s)=>{if(r.length===0)return{updated:0,failed:0};if(a==="approve"&&r.length===p.length&&!s)return _();let o=0,d=0,D;for(const Se of r)try{const we=a==="approve"?await C(Se,s?{note:s}:void 0):b?await b(Se,s?{note:s}:void 0):{updated:0,failed:1};o+=we.updated,d+=we.failed,!D&&we.firstError&&(D=we.firstError)}catch{d+=1}return{updated:o,failed:d,firstError:D}},be=async()=>{if(!S||w)return;const r=S.ids;if(r.length===0){m("No decisions selected for this action.");return}m(null),v(!0),F(new Set(r));const a=K.trim();try{const s=f?await f(r,S.action,a.length>0?a:void 0):await ge(r,S.action,a.length>0?a:void 0),o=S.action==="approve"?"Approved":"Rejected";if(s.failed>0){const d=`${o} ${s.updated}; ${s.failed} failed.`,D=ke(s.firstError,d);m(D===d?d:`${d} ${D}`)}else s.updated>0?m(`${o} ${s.updated} decision${s.updated===1?"":"s"}.`):m("No decisions were updated.");W(new Set)}catch(s){const o=s instanceof Error?s.message:"";m(ke(o,"Bulk decision action failed."))}finally{v(!1),F(new Set)}},re=async r=>{if(!(g.has(r)||w)){m(null),F(a=>{const s=new Set(a);return s.add(r),s});try{const a=await C(r);a.failed>0?m(Me("approve",a.failed,a.firstError)):a.updated>0&&m("Decision approved.")}catch(a){const s=a instanceof Error?a.message:"";m(ke(s,"Decision approval failed."))}finally{F(a=>{const s=new Set(a);return s.delete(r),s}),W(a=>{if(!a.has(r))return a;const s=new Set(a);return s.delete(r),s})}}},ce=l.useCallback(r=>{g.has(r.id)||w||(P(a=>new Set(a).add(r.id)),xe({message:`Approved '${r.title.length>40?r.title.slice(0,40)+"…":r.title}'`,onUndo:()=>{P(a=>{const s=new Set(a);return s.delete(r.id),s})},onCommit:()=>{P(a=>{const s=new Set(a);return s.delete(r.id),s}),C(r.id).catch(()=>{m("Approval failed. Try again from the decision panel.")})}}))},[g,w,xe,C]);l.useEffect(()=>{if(!L)return;const r=window.setTimeout(()=>m(null),5200);return()=>window.clearTimeout(r)},[L]);const je=L!==null&&!L.toLowerCase().includes("fail"),j=w||g.size>0,de=Math.max(g.size,w?O:0),i=j?`Applying ${de} decision action${de===1?"":"s"}…`:L??null,n=j?"processing":L?je?"success":"warning":"idle",I=!$&&k.length<=32,B=S!==null&&S.ids.length>0&&!w,A=p.length;(pe=p[0])==null||pe.waitingMinutes;const G=S!=null&&S.id.includes("visible")?"visible":"selected",x=(S==null?void 0:S.action)??"approve",ue=i!==null||n!=="idle",ye=X==="card"?Be:"div";return e.jsxs(ye,{className:ve("flex h-full min-h-0 flex-col",X==="card"&&"card-enter",E),children:[e.jsx(Qe,{open:u!==null,decision:oe,onClose:()=>T(null),onApprove:he,onReject:Ce,onNavigate:J,currentIndex:ee>=0?ee:void 0,totalCount:p.length}),R?e.jsxs("div",{className:"space-y-2.5 border-b border-subtle px-4 py-3.5",children:[e.jsx("div",{className:"flex items-start justify-between gap-3",children:e.jsxs("div",{className:"min-w-0",children:[e.jsxs("h2",{className:"inline-flex items-center gap-2 text-heading font-semibold text-white",children:[e.jsx(Z,{type:"decision",size:14}),"Decisions"]}),e.jsx("p",{className:"mt-0.5 text-caption text-secondary",children:A>0?`${A} decision${A===1?"":"s"} need${A===1?"s":""} your input`:"All clear — no decisions pending"})]})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[p.length>0&&e.jsx("button",{onClick:V,disabled:j,className:"control-pill h-8 flex-shrink-0 px-3 text-caption font-semibold disabled:opacity-45",children:H?"Clear all":"Select all"}),O>0&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:be,disabled:!B||j,"data-state":B?"active":"idle",className:"control-pill h-8 flex-shrink-0 px-3 text-caption font-semibold disabled:opacity-45",children:w?"Approving…":`Approve ${O} selected`}),b&&e.jsx("button",{type:"button",onClick:()=>me(Ze("reject",G)),disabled:j,"data-state":x==="reject"?"active":"idle",className:ve("control-pill h-8 px-2.5 text-caption font-semibold disabled:opacity-45",x==="reject"&&"border-amber-300/35 bg-amber-400/[0.12] text-amber-100"),children:"Reject"})]})]}),ue?e.jsxs("div",{"aria-live":"polite",className:ve("flex min-h-[32px] items-center gap-2 rounded-lg border px-2.5 py-1.5 text-caption transition-colors",n==="processing"?"border-amber-300/25 bg-amber-400/[0.08] text-amber-100":n==="success"?"border-lime/30 bg-lime/10 text-lime":n==="warning"?"border-red-400/25 bg-red-500/[0.08] text-red-100":"border-strong bg-white/[0.02] text-secondary"),children:[n==="processing"?e.jsx("span",{"aria-hidden":!0,className:"h-3.5 w-3.5 rounded-full border-2 border-amber-200/45 border-t-transparent animate-spin"}):n==="success"?e.jsx(Z,{type:"decision",size:12,className:"opacity-90"}):n==="warning"?e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"opacity-90",children:[e.jsx("path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z"}),e.jsx("line",{x1:"12",x2:"12",y1:"9",y2:"13"}),e.jsx("line",{x1:"12",x2:"12.01",y1:"17",y2:"17"})]}):e.jsx("span",{"aria-hidden":!0,className:"h-1.5 w-1.5 rounded-full bg-white/35"}),e.jsx("span",{className:"min-w-0 truncate",children:i})]}):null]}):null,e.jsxs("div",{className:ve("min-h-0 flex-1 space-y-2 overflow-y-auto",R?"p-3":"p-0"),children:[p.length===0&&e.jsx("div",{className:"flex flex-col items-center gap-2.5 rounded-xl border border-subtle bg-white/[0.02] p-4 text-center",children:j?e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":!0,className:"h-5 w-5 rounded-full border-2 border-amber-200/45 border-t-transparent animate-spin"}),e.jsx("p",{className:"text-body text-secondary",children:"Finalizing decision updates…"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-faint",children:[e.jsx("path",{d:"M22 11.08V12a10 10 0 1 1-5.93-9.14"}),e.jsx("polyline",{points:"22 4 12 14.01 9 11.01"})]}),e.jsx("p",{className:"text-body text-secondary",children:"No pending decisions. All clear."})]})}),I?e.jsx(Ee,{mode:"popLayout",children:k.map((r,a)=>{const s=g.has(r.id),o=N.has(r.id);return e.jsx(se.article,{role:"button",tabIndex:0,onClick:()=>T(r.id),onKeyDown:d=>{(d.key==="Enter"||d.key===" ")&&(d.preventDefault(),T(r.id))},drag:!j&&!s?"x":!1,dragConstraints:{left:0,right:0},dragElastic:.3,onDragEnd:(d,D)=>{D.offset.x>120&&ce(r)},initial:w?{opacity:0,x:300}:{opacity:0,y:8,scale:.98},animate:{opacity:1,y:0,x:0,scale:1},exit:{opacity:0,x:300,scale:.95},transition:{duration:.25,ease:[.22,1,.36,1],...w?{delay:a*.04}:{}},layout:!0,className:"rounded-xl border bg-white/[0.03] px-3 py-2.5 transition-[border-color,box-shadow] cv-auto",style:{borderColor:o?`${M.lime}50`:"rgba(255, 255, 255, 0.1)",boxShadow:o?"0 0 0 1px rgba(191, 255, 0, 0.14)":"none"},children:e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx("input",{type:"checkbox",checked:o,onChange:()=>fe(r.id),disabled:s||j,onClick:d=>d.stopPropagation(),className:"mt-0.5 h-4 w-4 rounded border-white/20 bg-black/40 text-lime focus:ring-lime/40"}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"flex min-w-0 items-start gap-1.5 text-body font-medium text-white",title:r.title,children:[e.jsx(Z,{type:"decision",size:12,className:"mt-[3px] flex-shrink-0 opacity-90"}),e.jsx("span",{className:"line-clamp-2",children:r.title})]}),r.context&&e.jsx("p",{className:"mt-1 line-clamp-2 text-caption text-secondary",title:r.context,children:r.context}),e.jsxs("div",{className:"mt-1.5 flex items-center justify-between gap-2",children:[e.jsxs("p",{className:`min-w-0 truncate text-micro ${(()=>{const d=Q(r.waitingMinutes);return d.tone==="urgent"?"text-red-400":d.tone==="attention"?"text-amber-400":"text-muted"})()}`,title:`${r.agentName??"OrgX Autopilot"} · ${Q(r.waitingMinutes).text}`,children:[r.agentName??"OrgX Autopilot"," · ",Q(r.waitingMinutes).text]}),e.jsx("button",{onClick:d=>{d.stopPropagation(),re(r.id)},disabled:s||j,className:"flex-shrink-0 rounded-md border border-lime/25 bg-lime/10 px-2.5 py-1 text-micro font-semibold text-lime transition-colors hover:bg-lime/20 disabled:cursor-not-allowed disabled:border-white/10 disabled:bg-white/[0.08] disabled:text-secondary",children:s?"Approving…":"Approve"}),b&&e.jsx("button",{onClick:d=>{d.stopPropagation(),T(r.id)},disabled:s||j,className:"flex-shrink-0 rounded-md border border-white/[0.08] bg-white/[0.03] px-2.5 py-1 text-micro font-semibold text-secondary transition-colors hover:border-red-400/30 hover:bg-red-400/[0.08] hover:text-red-300 disabled:cursor-not-allowed disabled:opacity-40",children:"Reject"})]})]})})]})},r.id)})}):e.jsx(e.Fragment,{children:k.map(r=>{const a=g.has(r.id),s=N.has(r.id);return e.jsx("article",{role:"button",tabIndex:0,onClick:()=>T(r.id),onKeyDown:o=>{(o.key==="Enter"||o.key===" ")&&(o.preventDefault(),T(r.id))},className:"rounded-xl border bg-white/[0.03] px-3 py-2.5 transition-[border-color,box-shadow] cv-auto",style:{borderColor:s?`${M.lime}50`:"rgba(255, 255, 255, 0.1)",boxShadow:s?"0 0 0 1px rgba(191, 255, 0, 0.14)":"none"},children:e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx("input",{type:"checkbox",checked:s,onChange:()=>fe(r.id),disabled:a||j,onClick:o=>o.stopPropagation(),className:"mt-0.5 h-4 w-4 rounded border-white/20 bg-black/40 text-lime focus:ring-lime/40"}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"flex min-w-0 items-start gap-1.5 text-body font-medium text-white",title:r.title,children:[e.jsx(Z,{type:"decision",size:12,className:"mt-[3px] flex-shrink-0 opacity-90"}),e.jsx("span",{className:"line-clamp-2",children:r.title})]}),r.context&&e.jsx("p",{className:"mt-1 line-clamp-2 text-caption text-secondary",title:r.context,children:r.context}),e.jsxs("div",{className:"mt-1.5 flex items-center justify-between gap-2",children:[e.jsxs("p",{className:`min-w-0 truncate text-micro ${(()=>{const o=Q(r.waitingMinutes);return o.tone==="urgent"?"text-red-400":o.tone==="attention"?"text-amber-400":"text-muted"})()}`,title:`${r.agentName??"OrgX Autopilot"} · ${Q(r.waitingMinutes).text}`,children:[r.agentName??"OrgX Autopilot"," · ",Q(r.waitingMinutes).text]}),e.jsx("button",{onClick:o=>{o.stopPropagation(),re(r.id)},disabled:a||j,className:"flex-shrink-0 rounded-md border border-lime/25 bg-lime/10 px-2.5 py-1 text-micro font-semibold text-lime transition-colors hover:bg-lime/20 disabled:cursor-not-allowed disabled:border-white/10 disabled:bg-white/[0.08] disabled:text-secondary",children:a?"Approving…":"Approve"}),b&&e.jsx("button",{onClick:o=>{o.stopPropagation(),T(r.id)},disabled:a||j,className:"flex-shrink-0 rounded-md border border-white/[0.08] bg-white/[0.03] px-2.5 py-1 text-micro font-semibold text-secondary transition-colors hover:border-red-400/30 hover:bg-red-400/[0.08] hover:text-red-300 disabled:cursor-not-allowed disabled:opacity-40",children:"Reject"})]})]})})]})},r.id)})}),k.length<p.length&&e.jsxs("button",{onClick:()=>q(r=>Math.min(p.length,r+Ae)),className:"w-full rounded-xl border border-white/[0.08] bg-white/[0.02] px-3 py-2 text-caption text-secondary transition-colors hover:bg-white/[0.05]",children:["Load more (",p.length-k.length," remaining)"]})]}),e.jsx(ne,{})]})});export{it as DecisionQueue};
@@ -10,13 +10,13 @@
10
10
  <meta name="googlebot" content="noindex, nofollow, noarchive, nosnippet, noimageindex" />
11
11
  <meta name="copyright" content="OrgX. All rights reserved." />
12
12
  <title>OrgX Live Dashboard</title>
13
- <script type="module" crossorigin src="/orgx/live/assets/D-bf6hEI.js"></script>
13
+ <script type="module" crossorigin src="/orgx/live/assets/C9jy61eu.js"></script>
14
14
  <link rel="modulepreload" crossorigin href="/orgx/live/assets/C-KIc3Wc.js">
15
15
  <link rel="modulepreload" crossorigin href="/orgx/live/assets/BJgZIVUQ.js">
16
16
  <link rel="modulepreload" crossorigin href="/orgx/live/assets/cNrhgGc1.js">
17
17
  <link rel="modulepreload" crossorigin href="/orgx/live/assets/CxQ08qFN.js">
18
18
  <link rel="stylesheet" crossorigin href="/orgx/live/assets/qm8xLgv-.css">
19
- <link rel="stylesheet" crossorigin href="/orgx/live/assets/h5biQs2I.css">
19
+ <link rel="stylesheet" crossorigin href="/orgx/live/assets/BzRbDCAD.css">
20
20
  </head>
21
21
  <body class="bg-[#080808] text-white antialiased">
22
22
  <div id="root"></div>
Binary file
Binary file
@@ -0,0 +1,216 @@
1
+ export declare const PRACTICE_EXERCISE_TEMPLATE_SCHEMA_VERSION: "practice-exercise-template.v1";
2
+ export type PracticeExerciseTemplateSchemaVersion = typeof PRACTICE_EXERCISE_TEMPLATE_SCHEMA_VERSION;
3
+ export type PracticeConstraintSeverity = "hard" | "soft";
4
+ export type PracticeTaskType = "analysis" | "implementation" | "review" | "debugging" | "planning";
5
+ export type PracticeOutputFormat = "json_object" | "markdown" | "text";
6
+ export interface PracticeConstraint {
7
+ id: string;
8
+ title: string;
9
+ description: string;
10
+ severity: PracticeConstraintSeverity;
11
+ rationale?: string;
12
+ }
13
+ export interface PracticeScenario {
14
+ id: string;
15
+ title: string;
16
+ input: Record<string, unknown>;
17
+ context?: string;
18
+ success_criteria: string[];
19
+ }
20
+ export interface PracticeExpectedOutputField {
21
+ path: string;
22
+ type: string;
23
+ required: boolean;
24
+ description: string;
25
+ }
26
+ export interface PracticeExpectedOutputShape {
27
+ format: PracticeOutputFormat;
28
+ fields: PracticeExpectedOutputField[];
29
+ example?: Record<string, unknown> | string;
30
+ }
31
+ export interface PracticeExerciseTemplate {
32
+ schema_version: PracticeExerciseTemplateSchemaVersion;
33
+ id: string;
34
+ title: string;
35
+ summary: string;
36
+ task_type: PracticeTaskType;
37
+ scenarios: PracticeScenario[];
38
+ constraints: PracticeConstraint[];
39
+ expected_output_shape: PracticeExpectedOutputShape;
40
+ tags?: string[];
41
+ }
42
+ export declare function validatePracticeExerciseTemplate(input: unknown): {
43
+ ok: boolean;
44
+ errors: string[];
45
+ template: PracticeExerciseTemplate | null;
46
+ };
47
+ export declare const PRACTICE_EXERCISE_TEMPLATE_JSON_SCHEMA: {
48
+ readonly $schema: "https://json-schema.org/draft/2020-12/schema";
49
+ readonly $id: "https://schemas.useorgx.com/practice-exercise-template/v1.json";
50
+ readonly title: "OrgX Practice Exercise Template v1";
51
+ readonly description: "Structured exercise template for practice loops with scenarios, constraints, and expected output shape.";
52
+ readonly type: "object";
53
+ readonly additionalProperties: false;
54
+ readonly required: readonly ["schema_version", "id", "title", "summary", "task_type", "scenarios", "constraints", "expected_output_shape"];
55
+ readonly properties: {
56
+ readonly schema_version: {
57
+ readonly type: "string";
58
+ readonly const: "practice-exercise-template.v1";
59
+ };
60
+ readonly id: {
61
+ readonly type: "string";
62
+ readonly minLength: 1;
63
+ readonly maxLength: 120;
64
+ };
65
+ readonly title: {
66
+ readonly type: "string";
67
+ readonly minLength: 1;
68
+ readonly maxLength: 300;
69
+ };
70
+ readonly summary: {
71
+ readonly type: "string";
72
+ readonly minLength: 1;
73
+ readonly maxLength: 3000;
74
+ };
75
+ readonly task_type: {
76
+ readonly type: "string";
77
+ readonly enum: readonly ["analysis", "implementation", "review", "debugging", "planning"];
78
+ };
79
+ readonly scenarios: {
80
+ readonly type: "array";
81
+ readonly minItems: 1;
82
+ readonly maxItems: 25;
83
+ readonly items: {
84
+ readonly type: "object";
85
+ readonly additionalProperties: false;
86
+ readonly required: readonly ["id", "title", "input", "success_criteria"];
87
+ readonly properties: {
88
+ readonly id: {
89
+ readonly type: "string";
90
+ readonly minLength: 1;
91
+ readonly maxLength: 120;
92
+ };
93
+ readonly title: {
94
+ readonly type: "string";
95
+ readonly minLength: 1;
96
+ readonly maxLength: 300;
97
+ };
98
+ readonly input: {
99
+ readonly type: "object";
100
+ readonly additionalProperties: true;
101
+ };
102
+ readonly context: {
103
+ readonly type: "string";
104
+ readonly minLength: 1;
105
+ readonly maxLength: 4000;
106
+ };
107
+ readonly success_criteria: {
108
+ readonly type: "array";
109
+ readonly minItems: 1;
110
+ readonly maxItems: 20;
111
+ readonly items: {
112
+ readonly type: "string";
113
+ readonly minLength: 1;
114
+ readonly maxLength: 1000;
115
+ };
116
+ };
117
+ };
118
+ };
119
+ };
120
+ readonly constraints: {
121
+ readonly type: "array";
122
+ readonly maxItems: 25;
123
+ readonly items: {
124
+ readonly type: "object";
125
+ readonly additionalProperties: false;
126
+ readonly required: readonly ["id", "title", "description", "severity"];
127
+ readonly properties: {
128
+ readonly id: {
129
+ readonly type: "string";
130
+ readonly minLength: 1;
131
+ readonly maxLength: 120;
132
+ };
133
+ readonly title: {
134
+ readonly type: "string";
135
+ readonly minLength: 1;
136
+ readonly maxLength: 300;
137
+ };
138
+ readonly description: {
139
+ readonly type: "string";
140
+ readonly minLength: 1;
141
+ readonly maxLength: 2000;
142
+ };
143
+ readonly severity: {
144
+ readonly type: "string";
145
+ readonly enum: readonly ["hard", "soft"];
146
+ };
147
+ readonly rationale: {
148
+ readonly type: "string";
149
+ readonly minLength: 1;
150
+ readonly maxLength: 2000;
151
+ };
152
+ };
153
+ };
154
+ };
155
+ readonly expected_output_shape: {
156
+ readonly type: "object";
157
+ readonly additionalProperties: false;
158
+ readonly required: readonly ["format", "fields"];
159
+ readonly properties: {
160
+ readonly format: {
161
+ readonly type: "string";
162
+ readonly enum: readonly ["json_object", "markdown", "text"];
163
+ };
164
+ readonly fields: {
165
+ readonly type: "array";
166
+ readonly minItems: 1;
167
+ readonly maxItems: 50;
168
+ readonly items: {
169
+ readonly type: "object";
170
+ readonly additionalProperties: false;
171
+ readonly required: readonly ["path", "type", "required", "description"];
172
+ readonly properties: {
173
+ readonly path: {
174
+ readonly type: "string";
175
+ readonly minLength: 1;
176
+ readonly maxLength: 400;
177
+ };
178
+ readonly type: {
179
+ readonly type: "string";
180
+ readonly minLength: 1;
181
+ readonly maxLength: 120;
182
+ };
183
+ readonly required: {
184
+ readonly type: "boolean";
185
+ };
186
+ readonly description: {
187
+ readonly type: "string";
188
+ readonly minLength: 1;
189
+ readonly maxLength: 2000;
190
+ };
191
+ };
192
+ };
193
+ };
194
+ readonly example: {
195
+ readonly oneOf: readonly [{
196
+ readonly type: "string";
197
+ readonly minLength: 1;
198
+ readonly maxLength: 20000;
199
+ }, {
200
+ readonly type: "object";
201
+ readonly additionalProperties: true;
202
+ }];
203
+ };
204
+ };
205
+ };
206
+ readonly tags: {
207
+ readonly type: "array";
208
+ readonly maxItems: 30;
209
+ readonly items: {
210
+ readonly type: "string";
211
+ readonly minLength: 1;
212
+ readonly maxLength: 80;
213
+ };
214
+ };
215
+ };
216
+ };