@useorgx/openclaw-plugin 0.7.18 → 0.7.20
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.
- package/dashboard/dist/assets/{sdoPH_Z1.js → B014hrCe.js} +1 -1
- package/dashboard/dist/assets/B014hrCe.js.br +0 -0
- package/dashboard/dist/assets/B014hrCe.js.gz +0 -0
- package/dashboard/dist/assets/{PVi0vr9a.js → BGY6oI8h.js} +1 -1
- package/dashboard/dist/assets/BGY6oI8h.js.br +0 -0
- package/dashboard/dist/assets/BGY6oI8h.js.gz +0 -0
- package/dashboard/dist/assets/BJI1Iy5v.css +1 -0
- package/dashboard/dist/assets/BJI1Iy5v.css.br +0 -0
- package/dashboard/dist/assets/BJI1Iy5v.css.gz +0 -0
- package/dashboard/dist/assets/BUvcp_7V.js +1 -0
- package/dashboard/dist/assets/BUvcp_7V.js.br +0 -0
- package/dashboard/dist/assets/BUvcp_7V.js.gz +0 -0
- package/dashboard/dist/assets/BV2Tf8S2.js +212 -0
- package/dashboard/dist/assets/BV2Tf8S2.js.br +0 -0
- package/dashboard/dist/assets/BV2Tf8S2.js.gz +0 -0
- package/dashboard/dist/assets/{B71dt9yu.js → BYb6DARX.js} +1 -1
- package/dashboard/dist/assets/BYb6DARX.js.br +0 -0
- package/dashboard/dist/assets/BYb6DARX.js.gz +0 -0
- package/dashboard/dist/assets/{DS79hzMu.js → BoDhb8_y.js} +1 -1
- package/dashboard/dist/assets/BoDhb8_y.js.br +0 -0
- package/dashboard/dist/assets/BoDhb8_y.js.gz +0 -0
- package/dashboard/dist/assets/Bqk_l0k6.js +1 -0
- package/dashboard/dist/assets/Bqk_l0k6.js.br +0 -0
- package/dashboard/dist/assets/Bqk_l0k6.js.gz +0 -0
- package/dashboard/dist/assets/{C3_j_W9V.js → CV0sWMbv.js} +1 -1
- package/dashboard/dist/assets/CV0sWMbv.js.br +0 -0
- package/dashboard/dist/assets/CV0sWMbv.js.gz +0 -0
- package/dashboard/dist/assets/CaAkScfa.js +1 -0
- package/dashboard/dist/assets/CaAkScfa.js.br +0 -0
- package/dashboard/dist/assets/CaAkScfa.js.gz +0 -0
- package/dashboard/dist/assets/{CfMS9yIf.js → Ck5KlsPN.js} +1 -1
- package/dashboard/dist/assets/Ck5KlsPN.js.br +0 -0
- package/dashboard/dist/assets/Ck5KlsPN.js.gz +0 -0
- package/dashboard/dist/assets/{CReugbyT.js → D2G51wQm.js} +1 -1
- package/dashboard/dist/assets/D2G51wQm.js.br +0 -0
- package/dashboard/dist/assets/D2G51wQm.js.gz +0 -0
- package/dashboard/dist/assets/{467jKHFJ.js → DAr4MfFk.js} +1 -1
- package/dashboard/dist/assets/DAr4MfFk.js.br +0 -0
- package/dashboard/dist/assets/DAr4MfFk.js.gz +0 -0
- package/dashboard/dist/assets/{BcJmNILk.js → DXVs61e1.js} +1 -1
- package/dashboard/dist/assets/DXVs61e1.js.br +0 -0
- package/dashboard/dist/assets/DXVs61e1.js.gz +0 -0
- package/dashboard/dist/assets/{5Ihga-4X.js → DibzNd0I.js} +1 -1
- package/dashboard/dist/assets/DibzNd0I.js.br +0 -0
- package/dashboard/dist/assets/DibzNd0I.js.gz +0 -0
- package/dashboard/dist/assets/{qDJ6rqcs.js → Dm0CfDGr.js} +1 -1
- package/dashboard/dist/assets/Dm0CfDGr.js.br +0 -0
- package/dashboard/dist/assets/Dm0CfDGr.js.gz +0 -0
- package/dashboard/dist/assets/_zpQCpjm.js +1 -0
- package/dashboard/dist/assets/_zpQCpjm.js.br +0 -0
- package/dashboard/dist/assets/_zpQCpjm.js.gz +0 -0
- package/dashboard/dist/assets/{C-XuWXGi.js → uNGpYMSH.js} +1 -1
- package/dashboard/dist/assets/uNGpYMSH.js.br +0 -0
- package/dashboard/dist/assets/uNGpYMSH.js.gz +0 -0
- package/dashboard/dist/assets/{a6qcPiWt.js → wa4jJQK9.js} +1 -1
- package/dashboard/dist/assets/wa4jJQK9.js.br +0 -0
- package/dashboard/dist/assets/wa4jJQK9.js.gz +0 -0
- package/dashboard/dist/index.html +2 -2
- package/dashboard/dist/index.html.br +0 -0
- package/dashboard/dist/index.html.gz +0 -0
- package/dist/http/helpers/auto-continue-engine.d.ts +39 -0
- package/dist/http/helpers/auto-continue-engine.js +96 -0
- package/dist/http/index.js +2 -1
- package/dist/http/routes/mission-control-read.d.ts +14 -0
- package/dist/http/routes/mission-control-read.js +69 -5
- package/dist/outbox.js +9 -2
- package/package.json +2 -1
- package/dashboard/dist/assets/467jKHFJ.js.br +0 -0
- package/dashboard/dist/assets/467jKHFJ.js.gz +0 -0
- package/dashboard/dist/assets/5Ihga-4X.js.br +0 -0
- package/dashboard/dist/assets/5Ihga-4X.js.gz +0 -0
- package/dashboard/dist/assets/B71dt9yu.js.br +0 -0
- package/dashboard/dist/assets/B71dt9yu.js.gz +0 -0
- package/dashboard/dist/assets/BEnI6kNR.js +0 -1
- package/dashboard/dist/assets/BEnI6kNR.js.br +0 -0
- package/dashboard/dist/assets/BEnI6kNR.js.gz +0 -0
- package/dashboard/dist/assets/BcJmNILk.js.br +0 -0
- package/dashboard/dist/assets/BcJmNILk.js.gz +0 -0
- package/dashboard/dist/assets/C-XuWXGi.js.br +0 -0
- package/dashboard/dist/assets/C-XuWXGi.js.gz +0 -0
- package/dashboard/dist/assets/C3_j_W9V.js.br +0 -0
- package/dashboard/dist/assets/C3_j_W9V.js.gz +0 -0
- package/dashboard/dist/assets/C9-UYhBb.js +0 -1
- package/dashboard/dist/assets/C9-UYhBb.js.br +0 -0
- package/dashboard/dist/assets/C9-UYhBb.js.gz +0 -0
- package/dashboard/dist/assets/C9yV06GS.js +0 -1
- package/dashboard/dist/assets/C9yV06GS.js.br +0 -0
- package/dashboard/dist/assets/C9yV06GS.js.gz +0 -0
- package/dashboard/dist/assets/CReugbyT.js.br +0 -0
- package/dashboard/dist/assets/CReugbyT.js.gz +0 -0
- package/dashboard/dist/assets/CSDhTbKy.js +0 -1
- package/dashboard/dist/assets/CSDhTbKy.js.br +0 -0
- package/dashboard/dist/assets/CSDhTbKy.js.gz +0 -0
- package/dashboard/dist/assets/CfMS9yIf.js.br +0 -0
- package/dashboard/dist/assets/CfMS9yIf.js.gz +0 -0
- package/dashboard/dist/assets/D2Kqcmv9.js +0 -212
- package/dashboard/dist/assets/D2Kqcmv9.js.br +0 -0
- package/dashboard/dist/assets/D2Kqcmv9.js.gz +0 -0
- package/dashboard/dist/assets/DS79hzMu.js.br +0 -0
- package/dashboard/dist/assets/DS79hzMu.js.gz +0 -0
- package/dashboard/dist/assets/PVi0vr9a.js.br +0 -0
- package/dashboard/dist/assets/PVi0vr9a.js.gz +0 -0
- package/dashboard/dist/assets/RZkbqlJk.css +0 -1
- package/dashboard/dist/assets/RZkbqlJk.css.br +0 -0
- package/dashboard/dist/assets/RZkbqlJk.css.gz +0 -0
- package/dashboard/dist/assets/a6qcPiWt.js.br +0 -0
- package/dashboard/dist/assets/a6qcPiWt.js.gz +0 -0
- package/dashboard/dist/assets/qDJ6rqcs.js.br +0 -0
- package/dashboard/dist/assets/qDJ6rqcs.js.gz +0 -0
- package/dashboard/dist/assets/sdoPH_Z1.js.br +0 -0
- package/dashboard/dist/assets/sdoPH_Z1.js.gz +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as o,j as e}from"./Dj2k1r16.js";import{E as ie,e as T,y as qe,a0 as H,v as De,a1 as Be,a2 as Oe,M as ze,h as Le,P as Ue,B as oe}from"./D2Kqcmv9.js";import{E as Ge}from"./PVi0vr9a.js";import{A as Re,m as ce,u as Ke}from"./eeHXe_OQ.js";import{u as Xe}from"./467jKHFJ.js";import"./DMKyYAtD.js";import"./cX2e-TLi.js";import"./BjK42gtU.js";import"./BV0BcV1u.js";const Je={pr:"⎋",file:"◇",artifact:"▪",log:"▸",decision:"◈"};function Ve(a){return a>=.8?"#BFFF00":a>=.5?"#F5B700":"#FF6B88"}function Ze(a){const t=a.match(/https?:\/\/\S+/);return t?t[0]:null}function Qe({evidenceType:a,title:t,summary:u,sourceUrl:p,confidence:b,payload:v,icon:R,label:w,onOpenTerminal:k}){const[N,B]=o.useState(!1),O=t??w??null,E=a??(R?R.toUpperCase():null),_=R?Je[R]:null,M=R==="pr"&&w?Ze(w):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:()=>B(y=>!y),children:[(E||_)&&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:[_?e.jsx("span",{className:"mr-1",children:_}):null,E]}),e.jsxs("div",{className:"min-w-0 flex-1",children:[O&&e.jsx("p",{className:"text-body font-medium text-primary",children:p?e.jsx("a",{href:p,target:"_blank",rel:"noopener noreferrer",className:"text-[#D8FFA1] hover:underline",onClick:y=>y.stopPropagation(),children:O}):M?e.jsx("a",{href:M,target:"_blank",rel:"noopener noreferrer",className:"text-[#D8FFA1] hover:underline",onClick:y=>y.stopPropagation(),children:O}):O}),u&&e.jsx("p",{className:`mt-0.5 text-caption text-secondary ${N?"":"line-clamp-2"}`,children:u})]}),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 ${N?"rotate-180":""}`,children:e.jsx("path",{d:"m6 9 6 6 6-6"})})]}),b!=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(b*100)}%`,backgroundColor:Ve(b)}})}),e.jsxs("span",{className:"text-micro text-muted tabular-nums",children:[Math.round(b*100),"%"]})]}),e.jsx(Re,{children:N&&e.jsx(ce.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:[R==="log"&&k&&e.jsxs("button",{type:"button",onClick:y=>{y.stopPropagation(),k()},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"]}),v&&Object.keys(v).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(v,null,2)})]})})})]})}function Ye({segments:a}){return a.length===0?null:e.jsx("nav",{className:"flex items-center gap-1.5 min-w-0 text-caption text-secondary",children:a.map((t,u)=>e.jsxs("span",{className:"flex items-center gap-1.5 min-w-0",children:[u>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(ie,{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})]},u))})}const ye={label:"Retry this workstream",description:"Re-run with the same configuration. Recommended if this was a transient issue.",impliedStatus:"approved"},K={label:"Skip and continue",description:"Mark as accepted and move to the next workstream.",impliedStatus:"approved"},He=[{test:/Worker exited without structured output.*?code=(\S+?),\s*signal=(\S+?)\)/i,headline:"Agent work stopped unexpectedly",explain:(a,t)=>{const u=t[1]==="null"?"none":t[1],p=t[2]==="null"?"none":t[2];return`The agent process exited before producing results. Exit code: ${u}. Signal: ${p}. This usually means the worker was terminated externally or ran out of resources.`},severity:"critical",options:[ye,{label:"Retry with more resources",description:"Increase token budget before re-running.",impliedStatus:"approved"},K],extractDetails:(a,t)=>({exitCode:t[1]==="null"?void 0:t[1],signal:t[2]==="null"?void 0:t[2]})},{test:/MCP handshake failed(?:\s+for\s+(\S+))?/i,headline:"Agent couldn't connect to tools",explain:(a,t)=>`The agent failed to connect to its tool server${t[1]?` (${t[1]})`:""}. This typically means the MCP server is unreachable or took too long to respond.`,severity:"critical",options:[ye,{label:"Check MCP server",description:"Investigate the tool server connection before retrying.",impliedStatus:"approved"},K],extractDetails:(a,t)=>({server:t[1]||void 0})},{test:/(?:Slice|Autopilot slice) timed out after (\d+)/i,headline:"Agent ran out of time",explain:(a,t)=>{const u=Math.round(parseInt(t[1],10)/6e4);return`The agent exceeded its ${u>0?`${u}-minute`:`${t[1]}ms`} time limit. Consider breaking the work into smaller steps or increasing the time budget.`},severity:"warning",options:[{label:"Retry with more time",description:"Increase the timeout before re-running.",impliedStatus:"approved"},{label:"Break into smaller tasks",description:"Split the workstream into smaller pieces that fit the time budget.",impliedStatus:"approved"},K],extractDetails:(a,t)=>({elapsedMs:t[1]})},{test:/(?:Slice|Autopilot slice) stalled/i,headline:"Agent stopped making progress",explain:()=>"The agent stopped producing output. It may be stuck in a loop, waiting on an unresponsive resource, or unable to proceed with the current approach.",severity:"warning",options:[ye,{label:"Review logs",description:"Check the session logs to understand why the agent stalled.",impliedStatus:"approved"},K]},{test:/blocked.*?(?:needs|requires?) intervention/i,headline:"Agent needs your help to continue",explain:()=>"The agent reached a point where it cannot proceed without human guidance. This may be a question about requirements, a permission needed, or an ambiguity.",severity:"warning",options:[{label:"Review blocker",description:"Look at what the agent needs and provide guidance.",impliedStatus:"approved"},{label:"Provide guidance",description:"Add a note with instructions for the agent.",impliedStatus:"approved"},K]},{test:/completed.*?(?:without|no) (?:verifiable )?(?:outcomes?|artifacts?)/i,headline:"Agent finished but produced no outputs",explain:()=>"The agent reported completion but produced no artifacts or status updates. The work may have been done informally, or the agent could not find actionable work.",severity:"info",options:[{label:"Accept as-is",description:"The work was done informally or no output was needed.",impliedStatus:"approved"},{label:"Retry with stronger output requirements",description:"Re-run and require the agent to produce structured artifacts.",impliedStatus:"approved"},K]},{test:/Spawn guard denied/i,headline:"Agent dispatch was blocked by safety check",explain:()=>"The system's safety checks prevented this agent from starting. This is typically due to capacity limits or quality gate requirements.",severity:"warning",options:[{label:"Approve exception",description:"Override the safety check and allow dispatch.",impliedStatus:"approved"},{label:"Investigate quality gate",description:"Review what safety check failed before proceeding.",impliedStatus:"approved"},K]},{test:/code=(\d+)/i,headline:"Agent encountered an error",explain:(a,t)=>`The agent process exited with error code ${t[1]}. Reviewing the session logs will show what operation failed.`,severity:"critical",options:[ye,{label:"Review error logs",description:"Check session logs to understand the error before retrying.",impliedStatus:"approved"},K],extractDetails:(a,t)=>({exitCode:t[1]})}];function et(a){var u;const t=a.context||a.title||"";for(const p of He){const b=t.match(p.test);if(b)return{headline:p.headline,explanation:p.explain(t,b),structuredDetails:((u=p.extractDetails)==null?void 0:u.call(p,t,b))??{},suggestedOptions:p.options,severity:p.severity}}return a.decisionType==="autopilot_failure"?{headline:"Agent work needs attention",explanation:t||"An issue occurred during autopilot execution that requires review.",structuredDetails:{},suggestedOptions:[ye,K],severity:"warning"}:{headline:a.title||"Decision needed",explanation:t||"Review the details and choose an action.",structuredDetails:{},suggestedOptions:[],severity:"info"}}function tt(a){return a.map((t,u)=>({id:`suggested-${u}`,label:t.label,description:t.description,impliedStatus:t.impliedStatus,actionType:null,requiresNote:!1}))}function rt(a,t){var w;if(!t||!a.workstreamId||!t.nodes.find(k=>k.id===a.workstreamId&&k.entityType==="workstream"))return null;const p=new Set(t.edges.filter(k=>k.source===a.workstreamId).map(k=>k.target)),b=[];for(const k of p){const N=t.nodes.find(B=>B.id===k);N&&b.push({id:N.id,title:N.title,taskCount:((w=N.children)==null?void 0:w.length)??0,status:N.status})}if(b.length===0)return null;const v=b.reduce((k,N)=>k+N.taskCount,0),R=b.some(k=>t.edges.some(N=>N.source===k.id));return{blockedWorkstreams:b,totalBlockedTasks:v,criticalPath:R}}function st(a){const t=a.blockedWorkstreams.length,u=a.blockedWorkstreams.map(p=>p.title);return t===1?`Resolving this unblocks 1 downstream workstream: ${u[0]}.`:t<=3?`Resolving this unblocks ${t} downstream workstreams: ${u.join(", ")}.`:`Resolving this unblocks ${t} downstream workstreams including ${u[0]} and ${u[1]}.`}const Pe=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent);function nt(a){try{return JSON.stringify(a,null,2)}catch{return null}}function Fe(a){if(typeof a!="string")return null;const t=a.trim().toLowerCase();return t==="rejected"?"declined":t==="approved"||t==="declined"||t==="cancelled"?t:null}function Ce(a,t){return!a||a.trim().length===0?t:Le(a.trim())||t}function it(a){switch(a){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 a.replace(/[_-]/g," ").replace(/\b\w/g,t=>t.toUpperCase())}}function at(a){const t=a.toLowerCase();return t==="critical"||t==="p0"?T.red:t==="high"||t==="p1"?T.amber:t==="medium"||t==="p2"?T.iris:"rgba(255,255,255,0.5)"}function lt({open:a,decision:t,onClose:u,onApprove:p,onReject:b,initiativeTitle:v,workstreamTitle:R,onNavigate:w,currentIndex:k,totalCount:N,onFocusRunId:B,graph:O}){const[E,_]=o.useState("idle"),[M,y]=o.useState(null),[P,F]=o.useState(null),[C,X]=o.useState(""),[ve,ee]=o.useState(!1),[de,je]=o.useState(!1),J=o.useRef(null),ae=o.useRef(),ue=o.useRef(u);ue.current=u,o.useEffect(()=>{if(a){_("idle"),y(null);const i=(t==null?void 0:t.selectedOptionId)??(t!=null&&t.options&&t.options.length===1?t.options[0].id:null);F(i),X(""),ee(!1),je(!1)}return()=>{ae.current&&clearTimeout(ae.current)}},[a,t==null?void 0:t.id]);const z=t==null?void 0:t.metadata,W=o.useMemo(()=>{if(!z)return[];const i=z,l=i.decision_options??i.options??i.actions??null;if(!Array.isArray(l))return[];const j=[],D=new Set;for(let L=0;L<l.length;L+=1){const Q=l[L];if(typeof Q=="string"){const s=Q.trim();if(!s)continue;const r=`option-${L+1}`;if(D.has(r))continue;D.add(r),j.push({id:r,label:s,description:null,impliedStatus:null,actionType:null,requiresNote:!1});continue}if(!Q||typeof Q!="object")continue;const g=Q,be=typeof g.id=="string"&&g.id.trim()||typeof g.option_id=="string"&&g.option_id.trim()||typeof g.action_id=="string"&&g.action_id.trim()||`option-${L+1}`;if(D.has(be))continue;const we=typeof g.label=="string"&&g.label.trim()||typeof g.title=="string"&&g.title.trim()||typeof g.name=="string"&&g.name.trim()||typeof g.action=="string"&&g.action.trim()||null;we&&(D.add(be),j.push({id:be,label:we,description:typeof g.description=="string"?g.description:null,impliedStatus:Fe(g.implied_status)??Fe(g.status),actionType:typeof g.action_type=="string"&&g.action_type||typeof g.type=="string"&&g.type||null,requiresNote:g.requires_note===!0||g.requiresNote===!0||g.note_required===!0}))}return j.slice(0,12)},[z]),f=o.useMemo(()=>t?et(t):null,[t==null?void 0:t.context,t==null?void 0:t.title,t==null?void 0:t.decisionType]),te=o.useMemo(()=>t?rt(t,O??null):null,[t==null?void 0:t.workstreamId,t==null?void 0:t.initiativeId,O]),le=((t==null?void 0:t.waitingMinutes)??0)>1440,A=o.useMemo(()=>t!=null&&t.options&&t.options.length>0?t.options:W.length>0?W:f&&f.suggestedOptions.length>0?tt(f.suggestedOptions):[],[t==null?void 0:t.options,W,f]),x=o.useMemo(()=>A.find(i=>i.id===P)??null,[A,P]),pe=(x==null?void 0:x.requiresNote)===!0,h=o.useMemo(()=>{const i=((t==null?void 0:t.context)??"").trim();if(i)return i;if(!z)return"";const l=z,j=(typeof l.summary=="string"?l.summary:null)??(typeof l.description=="string"?l.description:null)??"";return String(j??"").trim()},[t==null?void 0:t.context,z]),V=o.useMemo(()=>{const i=(t==null?void 0:t.waitingMinutes)??0;return i>=15?T.red:i>=5?T.amber:T.teal},[t==null?void 0:t.waitingMinutes]),q=o.useCallback(async()=>{if(!t)return;const i=nt({decision:t,metadata:z});if(i)try{await navigator.clipboard.writeText(i),ee(!0),setTimeout(()=>ee(!1),2e3)}catch{}},[t,z]),U=o.useCallback(()=>{const i=C.trim(),l=x==null?void 0:x.id;if(!(!i&&!l))return{note:i.length>0?i:void 0,optionId:l??void 0}},[C,x]),re=o.useCallback(async()=>{if(!t||!p)return;if(A.length>0&&!x){y("Select an option before approving this decision.");return}if(x!=null&&x.requiresNote&&C.trim().length===0){y("A note is required for the selected option."),requestAnimationFrame(()=>{var l;return(l=J.current)==null?void 0:l.focus()});return}let i=!1;if(_(l=>l==="approving"||l==="rejecting"?l:(i=!0,"approving")),!!i){y(null);try{const l=await p(t.id,U());l.failed>0?(_("error"),y(Ce(l.firstError,"Approval failed. Please try again."))):(_("success"),ae.current=setTimeout(()=>ue.current(),800))}catch(l){_("error");const j=l instanceof Error?l.message:"";y(Ce(j,"Approval failed."))}}},[U,t,C,p,A.length,x]),me=o.useCallback(async()=>{if(!t||!b)return;if(A.length>0&&!x){y("Select an option before rejecting this decision.");return}if(x!=null&&x.requiresNote&&C.trim().length===0){y("A note is required for the selected option."),requestAnimationFrame(()=>{var l;return(l=J.current)==null?void 0:l.focus()});return}let i=!1;if(_(l=>l==="approving"||l==="rejecting"?l:(i=!0,"rejecting")),!!i){y(null);try{const l=await b(t.id,U());l.failed>0?(_("error"),y(Ce(l.firstError,"Rejection failed. Please try again."))):(_("rejected"),ae.current=setTimeout(()=>ue.current(),800))}catch(l){_("error");const j=l instanceof Error?l.message:"";y(Ce(j,"Rejection failed."))}}},[U,t,C,b,A.length,x]);if(o.useEffect(()=>{if(!a)return;const i=l=>{var D,L;if((l.metaKey||l.ctrlKey)&&l.key==="Enter"){l.preventDefault(),re();return}const j=(D=l.target)==null?void 0:D.tagName;if(!(j==="INPUT"||j==="TEXTAREA"))switch(l.key){case"j":l.preventDefault(),w==null||w(1);break;case"k":l.preventDefault(),w==null||w(-1);break;case"a":l.preventDefault(),re();break;case"r":l.preventDefault(),me();break;case"n":l.preventDefault(),(L=J.current)==null||L.focus();break}};return document.addEventListener("keydown",i),()=>document.removeEventListener("keydown",i)},[a,re,me,w]),!a||!t)return null;const Z=E==="approving"||E==="rejecting",Me=E==="success"||E==="rejected",se=(t.status??"pending").toLowerCase(),ke=!se.includes("approved")&&!se.includes("resolved")&&!se.includes("rejected")&&!se.includes("declined")&&!se.includes("cancelled"),Ne=A.length>0&&!x,$e=(x==null?void 0:x.requiresNote)===!0&&C.trim().length===0,G=Z||Ne||$e,$=t.evidenceRefs??[],Ie=$.length>0,Se=t.recommendedAction??null,xe=t.decisionType??null,he=t.priority??null,fe=t.occurrenceCount??null,I=t.sourceRunId??null,ne=[];v&&ne.push({label:v,icon:"initiative"}),R&&ne.push({label:R,icon:"workstream"});const ge=[["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(Me){const i=E==="success",l=i?T.lime:T.red;return e.jsx(qe,{open:a,onClose:u,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:`${l}18`,border:`1.5px solid ${l}40`},children:i?e.jsx("svg",{width:"28",height:"28",viewBox:"0 0 24 24",fill:"none",stroke:l,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:l,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(qe,{open:a,onClose:u,maxWidth:"max-w-xl",children:e.jsxs("div",{className:"flex h-full min-h-0 w-full flex-col",style:le?{boxShadow:`inset 0 0 0 1px ${T.amber}30`,borderRadius:"inherit"}:void 0,children:[e.jsx("div",{className:"h-[2px] w-full flex-shrink-0",style:{background:`linear-gradient(90deg, ${V}60, ${V}20, transparent)`}}),w&&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:()=>w(-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:()=>w(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"})})}),k!=null&&N!=null&&e.jsxs("span",{className:"text-micro text-muted tabular-nums",children:[k+1," of ",N,e.jsx("span",{className:"ml-1 hidden sm:inline",children:"· Longest waiting first"})]})]}),e.jsx("button",{type:"button",onClick:u,"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"})})})]}),ne.length>0&&e.jsx("div",{className:"px-6 pt-2",children:e.jsx(Ye,{segments:ne})}),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:`${V}14`,border:`1px solid ${V}30`},children:e.jsx(ie,{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",{className:le?"font-semibold text-red-300":"",children:H(t.waitingMinutes).text}),xe&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-white/[0.15]",children:"|"}),e.jsx("span",{className:"text-primary",children:it(xe)})]}),he&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-white/[0.15]",children:"|"}),e.jsx("span",{className:"font-medium",style:{color:at(he)},children:he})]})]}),fe!=null&&fe>1&&e.jsxs("p",{className:"mt-2 text-caption text-muted",children:["Seen ",fe," times",t.firstSeenAt&&e.jsxs(e.Fragment,{children:[" · first ",De(t.firstSeenAt)]}),t.lastSeenAt&&e.jsxs(e.Fragment,{children:[" · last ",De(t.lastSeenAt)]})]})]})]})}),!w&&e.jsx("button",{type:"button",onClick:u,"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(Be,{nodes:Oe({initiativeId:t.initiativeId,initiativeTitle:v,workstreamId:t.workstreamId,workstreamTitle:R,agentName:t.agentName,agentId:t.agentId}),activeId:t.workstreamId,compact:!0})}),Se&&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:Se})]}),Ie&&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:$.map((i,l)=>e.jsx(Qe,{evidenceType:i.evidenceType,title:i.title,summary:i.summary,sourceUrl:i.sourceUrl,confidence:i.confidence,payload:i.payload},l))})]}),le&&e.jsx("div",{className:"mb-4 rounded-xl border border-amber-400/[0.3] bg-amber-500/[0.08] px-4 py-3",children:e.jsxs("p",{className:"text-body text-amber-200",children:["This decision has been waiting"," ",e.jsx("span",{className:"font-semibold text-amber-100",children:H(t.waitingMinutes).text}),". Downstream work is paused."]})}),f&&f.headline!==t.title?e.jsxs("div",{className:"rounded-xl border border-white/[0.06] bg-white/[0.02] px-4 py-3",children:[e.jsx("p",{className:"text-micro font-semibold uppercase tracking-wider text-muted mb-2",children:"What happened"}),e.jsx("p",{className:"text-body text-primary leading-relaxed",children:f.explanation}),Object.keys(f.structuredDetails).length>0&&e.jsx("div",{className:"mt-3 flex flex-wrap gap-x-4 gap-y-1 text-caption text-secondary",children:Object.entries(f.structuredDetails).filter(([,i])=>i!=null).map(([i,l])=>e.jsxs("span",{children:[i.replace(/([A-Z])/g," $1").replace(/^./,j=>j.toUpperCase()),": ",l]},i))})]}):h?e.jsx("div",{className:"rounded-xl border border-white/[0.06] bg-white/[0.02] px-4 py-3",children:e.jsx(ze,{text:h,mode:"block"})}):e.jsx("p",{className:"px-1 text-body text-muted italic",children:"No additional context provided."}),A.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:A.map(i=>{const l=P===i.id;return e.jsxs("button",{type:"button",onClick:()=>{F(l?null:i.id),i.requiresNote&&requestAnimationFrame(()=>{var j;return(j=J.current)==null?void 0:j.focus()})},disabled:Z,className:"group relative flex w-full items-start gap-4 px-4 py-4 text-left focus:outline-none",children:[l&&e.jsx(ce.div,{layoutId:"decision-option-bg",className:"absolute inset-0 rounded-xl",style:{backgroundColor:`${T.lime}12`},transition:{type:"spring",stiffness:400,damping:25}}),!l&&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:l?T.lime:"rgba(255,255,255,0.2)"},children:e.jsx(Re,{children:l&&e.jsx(ce.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:T.lime}})})}),e.jsxs("div",{className:"relative min-w-0 flex-1",children:[e.jsx("span",{className:`block text-[15px] ${l?"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)})})]}),ke&&pe&&e.jsxs("div",{className:"mt-4",children:[e.jsx("textarea",{ref:J,value:C,onChange:i=>X(i.target.value),disabled:Z,placeholder:"Required: add 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]"}),C.trim().length===0&&e.jsx("p",{className:"mt-2 text-caption text-amber-300",children:"This option requires a note before submission."})]}),te&&e.jsxs("div",{className:"mt-6 rounded-xl border border-white/[0.06] bg-white/[0.02] px-4 py-3",children:[e.jsx("p",{className:"text-micro font-semibold uppercase tracking-wider text-muted mb-2",children:"Impact"}),e.jsx("p",{className:"text-body text-primary leading-relaxed",children:st(te)}),te.blockedWorkstreams.length>0&&e.jsx("ul",{className:"mt-2 space-y-1 text-caption text-secondary",children:te.blockedWorkstreams.map(i=>e.jsxs("li",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"inline-block h-1 w-1 rounded-full bg-amber-400 flex-shrink-0"}),i.title,i.status==="blocked"&&e.jsx("span",{className:"text-amber-400 text-micro",children:"(blocked)"})]},i.id))})]}),I&&B&&e.jsx("div",{className:"mt-4",children:e.jsxs("button",{type:"button",onClick:()=>B(I),className:"inline-flex items-center gap-1.5 text-caption text-[#D8FFA1] transition-colors hover:text-white",children:[e.jsx(ie,{type:"session",size:12}),"View source run"]})}),e.jsx("div",{className:"mt-4 border-t border-white/[0.06] pt-4",children:e.jsx(Ge,{entityType:"decision",entityId:t.id})}),ge.length>0&&e.jsxs("div",{className:"mt-4 border-t border-white/[0.06] pt-2",children:[e.jsxs("button",{type:"button",onClick:()=>je(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 ${de?"rotate-180":""}`,children:e.jsx("path",{d:"m6 9 6 6 6-6"})})]}),de&&e.jsx("div",{className:"mt-2 space-y-0.5",children:ge.map(([i,l])=>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:l})]},i))})]}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-x-3 gap-y-1 text-micro text-muted opacity-60",children:[w&&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:[Pe?"⌘":"Ctrl","+Enter approve"]}),e.jsx("span",{children:"esc close"})]})]}),M&&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:T.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:M})]}),ke&&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:[b&&e.jsx(ce.button,{whileTap:{scale:.97},type:"button",onClick:me,disabled:G,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:q,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:ve?"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:[Pe?"⌘":"Ctrl","+Enter"]}),e.jsx(ce.button,{whileTap:!p||G?void 0:{scale:.97},type:"button",onClick:re,disabled:!p||G,"data-modal-autofocus":"true",className:"rounded-lg px-6 py-2.5 text-[14px] font-semibold transition-all focus:outline-none",style:{backgroundColor:!p||G?"rgba(255,255,255,0.06)":T.lime,color:!p||G?"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 Te=40;function Ae(a,t){return!a||a.trim().length===0?t:Le(a.trim())||t}function Ee(a,t,u){const p=a==="approve"?`Approval failed for ${t} decision${t===1?"":"s"}.`:`Rejection failed for ${t} decision${t===1?"":"s"}.`;return Ae(u,p)}function _e(a){return a>=1440?"overdue":a>=60?"urgent":"normal"}function ot(a){return a.length>=32?a.slice(0,8):a}function We({group:a}){const t=_e(a.worstWaitingMinutes),u=a.decisions.length;return e.jsxs("div",{className:"flex items-center gap-2 px-1 pb-1 pt-2.5 first:pt-0",children:[e.jsx("span",{className:"text-caption font-semibold text-white/70 truncate",children:a.label}),e.jsxs("span",{className:"text-micro text-muted whitespace-nowrap",children:["(",u," decision",u===1?"":"s",")"]}),t==="overdue"&&e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-red-500/[0.12] px-1.5 py-0.5 text-micro font-medium text-red-400",children:[e.jsx("span",{"aria-hidden":!0,className:"h-1.5 w-1.5 rounded-full bg-red-400"}),"overdue"]}),t==="urgent"&&e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-amber-400/[0.12] px-1.5 py-0.5 text-micro font-medium text-amber-400",children:[e.jsx("span",{"aria-hidden":!0,className:"h-1.5 w-1.5 rounded-full bg-amber-400"}),"urgent"]})]})}function ct(a,t){return`${a}_${t}`}const wt=o.memo(function({decisions:t,focusDecisionId:u=null,onFocusDecisionHandled:p,onApproveDecision:b,onRejectDecision:v,onApproveAll:R,onBulkDecisionAction:w,mutationState:k,showHeader:N=!0,panelStyle:B="card",className:O,initiativeNames:E}){var we;const _=Ke(),[M,y]=o.useState(!1),[P,F]=o.useState(new Set),[C,X]=o.useState(new Set),[ve,ee]=o.useState(new Set),{enqueue:de,ToastRenderer:je}=Xe(),[J,ae]=o.useState("approve_selected"),[ue,z]=o.useState(""),[W,f]=o.useState(null),[te,le]=o.useState(Te),[A,x]=o.useState(null),pe=o.useRef(null),h=o.useMemo(()=>{const s=new Set;return[...t].filter(r=>s.has(r.id)?!1:(s.add(r.id),!0)).sort((r,n)=>{if(r.waitingMinutes!==n.waitingMinutes)return n.waitingMinutes-r.waitingMinutes;const c=Date.parse(r.requestedAt??r.updatedAt??""),d=Date.parse(n.requestedAt??n.updatedAt??""),m=Number.isFinite(c)?c:0;return(Number.isFinite(d)?d:0)-m})},[t]);o.useEffect(()=>{X(s=>{const r=new Set(h.map(c=>c.id)),n=new Set;for(const c of s)r.has(c)&&n.add(c);return n})},[h]);const V=C.size,q=o.useMemo(()=>h.filter(s=>!ve.has(s.id)).slice(0,te),[h,te,ve]),U=o.useMemo(()=>{const s=new Map,r=[];for(const c of q){const d=c.initiativeId??"_unscoped";let m=s.get(d);m||(m=[],s.set(d,m),r.push(d)),m.push(c)}const n=r.map(c=>{const d=s.get(c),m=Math.max(0,...d.map(Y=>Y.waitingMinutes)),S=c==="_unscoped"?"General":(E==null?void 0:E[c])??ot(c);return{initiativeId:c,label:S,decisions:d,worstWaitingMinutes:m}});return n.sort((c,d)=>d.worstWaitingMinutes-c.worstWaitingMinutes),n},[q,E]),re=o.useMemo(()=>{if(q.length===0)return!1;for(const s of q)if(!C.has(s.id))return!1;return!0},[C,q]),me=o.useMemo(()=>A?h.find(s=>s.id===A)??null:null,[A,h]),Z=o.useMemo(()=>A?h.findIndex(s=>s.id===A):-1,[A,h]),Me=o.useCallback(s=>{const r=Z+s;r>=0&&r<h.length&&x(h[r].id)},[Z,h]),se=async(s,r)=>{f(null),F(c=>{const d=new Set(c);return d.add(s),d});const n=await b(s,r);return n.failed>0?f(Ee("approve",n.failed,n.firstError)):n.updated>0&&f("Decision approved. Changes synced."),F(c=>{const d=new Set(c);return d.delete(s),d}),n},ke=v?async(s,r)=>{f(null),F(c=>{const d=new Set(c);return d.add(s),d});const n=await v(s,r);return n.failed>0?f(Ee("reject",n.failed,n.firstError)):n.updated>0&&f("Decision rejected. Changes synced."),F(c=>{const d=new Set(c);return d.delete(s),d}),n}:void 0;o.useEffect(()=>{le(s=>h.length===0?0:Math.min(Math.max(Te,s),h.length))},[h.length]),o.useEffect(()=>{const s=(u??"").trim();if(!s){pe.current=null;return}pe.current===s||!h.some(n=>n.id===s)||(pe.current=s,x(s),p==null||p(s))},[u,p,h]);const Ne=s=>{X(r=>{const n=new Set(r);return n.has(s)?n.delete(s):n.add(s),n})},$e=()=>{X(s=>{if(q.length===0)return s;const r=new Set(s),n=re;for(const c of q)n?r.delete(c.id):r.add(c.id);return r})},G=o.useMemo(()=>{const s=h.map(n=>n.id).filter(n=>C.has(n)),r=q.map(n=>n.id);return[{id:"approve_selected",label:`Approve selected (${s.length})`,action:"approve",ids:s},{id:"reject_selected",label:`Reject selected (${s.length})`,action:"reject",ids:s,hidden:!v},{id:"approve_visible",label:`Approve visible (${r.length})`,action:"approve",ids:r},{id:"reject_visible",label:`Reject visible (${r.length})`,action:"reject",ids:r,hidden:!v}].filter(n=>!n.hidden)},[v,C,h,q]),$=o.useMemo(()=>G.find(s=>s.id===J)??G[0]??null,[J,G]),Ie=async(s,r,n)=>{if(s.length===0)return{updated:0,failed:0};if(r==="approve"&&s.length===h.length&&!n)return R();let c=0,d=0,m;for(const S of s)try{const Y=r==="approve"?await b(S,n?{note:n}:void 0):v?await v(S,n?{note:n}:void 0):{updated:0,failed:1};c+=Y.updated,d+=Y.failed,!m&&Y.firstError&&(m=Y.firstError)}catch{d+=1}return{updated:c,failed:d,firstError:m}},Se=async()=>{if(!$||M)return;const s=$.ids;if(s.length===0){f("No decisions selected for this action.");return}f(null),y(!0),F(new Set(s));const r=ue.trim();try{const n=w?await w(s,$.action,r.length>0?r:void 0):await Ie(s,$.action,r.length>0?r:void 0),c=$.action==="approve"?"Approved":"Rejected";if(n.failed>0){const d=`${c} ${n.updated}; ${n.failed} failed.`,m=Ae(n.firstError,d);f(m===d?d:`${d} ${m}`)}else n.updated>0?f(`${c} ${n.updated} decision${n.updated===1?"":"s"}.`):f("No decisions were updated.");X(new Set)}catch(n){const c=n instanceof Error?n.message:"";f(Ae(c,"Bulk decision action failed."))}finally{y(!1),F(new Set)}},xe=async s=>{if(!(P.has(s)||M)){f(null),F(r=>{const n=new Set(r);return n.add(s),n});try{const r=await b(s);r.failed>0?f(Ee("approve",r.failed,r.firstError)):r.updated>0&&f("Decision approved.")}catch(r){const n=r instanceof Error?r.message:"";f(Ae(n,"Decision approval failed."))}finally{F(r=>{const n=new Set(r);return n.delete(s),n}),X(r=>{if(!r.has(s))return r;const n=new Set(r);return n.delete(s),n})}}},he=o.useCallback(s=>{P.has(s.id)||M||(ee(r=>new Set(r).add(s.id)),de({message:`Approved '${s.title.length>40?s.title.slice(0,40)+"…":s.title}'`,onUndo:()=>{ee(r=>{const n=new Set(r);return n.delete(s.id),n})},onCommit:()=>{ee(r=>{const n=new Set(r);return n.delete(s.id),n}),b(s.id).catch(()=>{f("Approval failed. Try again from the decision panel.")})}}))},[P,M,de,b]);o.useEffect(()=>{if(!W)return;const s=window.setTimeout(()=>f(null),5200);return()=>window.clearTimeout(s)},[W]);const fe=W!==null&&!W.toLowerCase().includes("fail"),I=M||P.size>0,ne=Math.max(P.size,M?V:0),ge=I?`Applying ${ne} decision action${ne===1?"":"s"}…`:W??null,i=I?"processing":W?fe?"success":"warning":"idle",l=!_&&q.length<=32,j=$!==null&&$.ids.length>0&&!M,D=h.length;(we=h[0])==null||we.waitingMinutes;const L=$!=null&&$.id.includes("visible")?"visible":"selected",Q=($==null?void 0:$.action)??"approve",g=ge!==null||i!=="idle",be=B==="card"?Ue:"div";return e.jsxs(be,{className:oe("flex h-full min-h-0 flex-col",B==="card"&&"card-enter",O),children:[e.jsx(lt,{open:A!==null,decision:me,onClose:()=>x(null),onApprove:se,onReject:ke,onNavigate:Me,currentIndex:Z>=0?Z:void 0,totalCount:h.length}),N?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(ie,{type:"decision",size:14}),"Decisions"]}),e.jsx("p",{className:"mt-0.5 text-caption text-secondary",children:D>0?`${D} decision${D===1?"":"s"} need${D===1?"s":""} your input`:"All clear — no decisions pending"})]})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[h.length>0&&e.jsx("button",{onClick:$e,disabled:I,className:"control-pill h-8 flex-shrink-0 px-3 text-caption font-semibold disabled:opacity-45",children:re?"Clear all":"Select all"}),V>0&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:Se,disabled:!j||I,"data-state":j?"active":"idle",className:"control-pill h-8 flex-shrink-0 px-3 text-caption font-semibold disabled:opacity-45",children:M?"Approving…":`Approve ${V} selected`}),v&&e.jsx("button",{type:"button",onClick:()=>ae(ct("reject",L)),disabled:I,"data-state":Q==="reject"?"active":"idle",className:oe("control-pill h-8 px-2.5 text-caption font-semibold disabled:opacity-45",Q==="reject"&&"border-amber-300/35 bg-amber-400/[0.12] text-amber-100"),children:"Reject"})]})]}),g?e.jsxs("div",{"aria-live":"polite",className:oe("flex min-h-[32px] items-center gap-2 rounded-lg border px-2.5 py-1.5 text-caption transition-colors",i==="processing"?"border-amber-300/25 bg-amber-400/[0.08] text-amber-100":i==="success"?"border-lime/30 bg-lime/10 text-lime":i==="warning"?"border-red-400/25 bg-red-500/[0.08] text-red-100":"border-strong bg-white/[0.02] text-secondary"),children:[i==="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"}):i==="success"?e.jsx(ie,{type:"decision",size:12,className:"opacity-90"}):i==="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:ge})]}):null]}):null,e.jsxs("div",{className:oe("min-h-0 flex-1 space-y-2 overflow-y-auto",N?"p-3":"p-0"),children:[h.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:I?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."})]})}),l?e.jsx(Re,{mode:"popLayout",children:U.map(s=>e.jsxs("div",{children:[U.length>1&&e.jsx(We,{group:s}),s.decisions.map((r,n)=>{const c=P.has(r.id),d=C.has(r.id),m=_e(r.waitingMinutes);return e.jsx(ce.article,{role:"button",tabIndex:0,onClick:()=>x(r.id),onKeyDown:S=>{(S.key==="Enter"||S.key===" ")&&(S.preventDefault(),x(r.id))},drag:!I&&!c?"x":!1,dragConstraints:{left:0,right:0},dragElastic:.3,onDragEnd:(S,Y)=>{Y.offset.x>120&&he(r)},initial:M?{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],...M?{delay:n*.04}:{}},layout:!0,className:"mt-1.5 rounded-xl border bg-white/[0.03] px-3 py-2.5 transition-[border-color,box-shadow] cv-auto",style:{borderColor:d?`${T.lime}50`:"rgba(255, 255, 255, 0.1)",boxShadow:d?"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:d,onChange:()=>Ne(r.id),disabled:c||I,onClick:S=>S.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("div",{className:"flex min-w-0 items-start gap-1.5",children:[m!=="normal"&&e.jsx("span",{"aria-label":m==="overdue"?"Overdue":"Urgent",className:oe("mt-[5px] h-2 w-2 flex-shrink-0 rounded-full",m==="overdue"?"bg-red-400":"bg-amber-400")}),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(ie,{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 S=H(r.waitingMinutes);return S.tone==="urgent"?"text-red-400":S.tone==="attention"?"text-amber-400":"text-muted"})()}`,title:`${r.agentName??"OrgX Autopilot"} · ${H(r.waitingMinutes).text}`,children:[r.agentName??"OrgX Autopilot"," · ",H(r.waitingMinutes).text]}),e.jsx("button",{onClick:S=>{S.stopPropagation(),xe(r.id)},disabled:c||I,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:c?"Approving…":"Approve"}),v&&e.jsx("button",{onClick:S=>{S.stopPropagation(),x(r.id)},disabled:c||I,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)})]},s.initiativeId))}):e.jsx(e.Fragment,{children:U.map(s=>e.jsxs("div",{children:[U.length>1&&e.jsx(We,{group:s}),s.decisions.map(r=>{const n=P.has(r.id),c=C.has(r.id),d=_e(r.waitingMinutes);return e.jsx("article",{role:"button",tabIndex:0,onClick:()=>x(r.id),onKeyDown:m=>{(m.key==="Enter"||m.key===" ")&&(m.preventDefault(),x(r.id))},className:"mt-1.5 rounded-xl border bg-white/[0.03] px-3 py-2.5 transition-[border-color,box-shadow] cv-auto",style:{borderColor:c?`${T.lime}50`:"rgba(255, 255, 255, 0.1)",boxShadow:c?"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:c,onChange:()=>Ne(r.id),disabled:n||I,onClick:m=>m.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("div",{className:"flex min-w-0 items-start gap-1.5",children:[d!=="normal"&&e.jsx("span",{"aria-label":d==="overdue"?"Overdue":"Urgent",className:oe("mt-[5px] h-2 w-2 flex-shrink-0 rounded-full",d==="overdue"?"bg-red-400":"bg-amber-400")}),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(ie,{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 m=H(r.waitingMinutes);return m.tone==="urgent"?"text-red-400":m.tone==="attention"?"text-amber-400":"text-muted"})()}`,title:`${r.agentName??"OrgX Autopilot"} · ${H(r.waitingMinutes).text}`,children:[r.agentName??"OrgX Autopilot"," · ",H(r.waitingMinutes).text]}),e.jsx("button",{onClick:m=>{m.stopPropagation(),xe(r.id)},disabled:n||I,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:n?"Approving…":"Approve"}),v&&e.jsx("button",{onClick:m=>{m.stopPropagation(),x(r.id)},disabled:n||I,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)})]},s.initiativeId))}),q.length<h.length&&e.jsxs("button",{onClick:()=>le(s=>Math.min(h.length,s+Te)),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 (",h.length-q.length," remaining)"]})]}),e.jsx(je,{})]})});export{wt as DecisionQueue};
|
|
1
|
+
import{r as o,j as e}from"./Dj2k1r16.js";import{E as ie,e as T,y as qe,a1 as H,v as De,a2 as Be,a3 as Oe,M as ze,h as Le,P as Ue,B as oe}from"./BV2Tf8S2.js";import{E as Ge}from"./BGY6oI8h.js";import{A as Re,m as ce,u as Ke}from"./eeHXe_OQ.js";import{u as Xe}from"./DAr4MfFk.js";import"./DMKyYAtD.js";import"./cX2e-TLi.js";import"./BjK42gtU.js";import"./BV0BcV1u.js";const Je={pr:"⎋",file:"◇",artifact:"▪",log:"▸",decision:"◈"};function Ve(a){return a>=.8?"#BFFF00":a>=.5?"#F5B700":"#FF6B88"}function Ze(a){const t=a.match(/https?:\/\/\S+/);return t?t[0]:null}function Qe({evidenceType:a,title:t,summary:u,sourceUrl:p,confidence:b,payload:v,icon:R,label:w,onOpenTerminal:k}){const[N,B]=o.useState(!1),O=t??w??null,E=a??(R?R.toUpperCase():null),_=R?Je[R]:null,M=R==="pr"&&w?Ze(w):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:()=>B(y=>!y),children:[(E||_)&&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:[_?e.jsx("span",{className:"mr-1",children:_}):null,E]}),e.jsxs("div",{className:"min-w-0 flex-1",children:[O&&e.jsx("p",{className:"text-body font-medium text-primary",children:p?e.jsx("a",{href:p,target:"_blank",rel:"noopener noreferrer",className:"text-[#D8FFA1] hover:underline",onClick:y=>y.stopPropagation(),children:O}):M?e.jsx("a",{href:M,target:"_blank",rel:"noopener noreferrer",className:"text-[#D8FFA1] hover:underline",onClick:y=>y.stopPropagation(),children:O}):O}),u&&e.jsx("p",{className:`mt-0.5 text-caption text-secondary ${N?"":"line-clamp-2"}`,children:u})]}),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 ${N?"rotate-180":""}`,children:e.jsx("path",{d:"m6 9 6 6 6-6"})})]}),b!=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(b*100)}%`,backgroundColor:Ve(b)}})}),e.jsxs("span",{className:"text-micro text-muted tabular-nums",children:[Math.round(b*100),"%"]})]}),e.jsx(Re,{children:N&&e.jsx(ce.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:[R==="log"&&k&&e.jsxs("button",{type:"button",onClick:y=>{y.stopPropagation(),k()},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"]}),v&&Object.keys(v).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(v,null,2)})]})})})]})}function Ye({segments:a}){return a.length===0?null:e.jsx("nav",{className:"flex items-center gap-1.5 min-w-0 text-caption text-secondary",children:a.map((t,u)=>e.jsxs("span",{className:"flex items-center gap-1.5 min-w-0",children:[u>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(ie,{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})]},u))})}const ye={label:"Retry this workstream",description:"Re-run with the same configuration. Recommended if this was a transient issue.",impliedStatus:"approved"},K={label:"Skip and continue",description:"Mark as accepted and move to the next workstream.",impliedStatus:"approved"},He=[{test:/Worker exited without structured output.*?code=(\S+?),\s*signal=(\S+?)\)/i,headline:"Agent work stopped unexpectedly",explain:(a,t)=>{const u=t[1]==="null"?"none":t[1],p=t[2]==="null"?"none":t[2];return`The agent process exited before producing results. Exit code: ${u}. Signal: ${p}. This usually means the worker was terminated externally or ran out of resources.`},severity:"critical",options:[ye,{label:"Retry with more resources",description:"Increase token budget before re-running.",impliedStatus:"approved"},K],extractDetails:(a,t)=>({exitCode:t[1]==="null"?void 0:t[1],signal:t[2]==="null"?void 0:t[2]})},{test:/MCP handshake failed(?:\s+for\s+(\S+))?/i,headline:"Agent couldn't connect to tools",explain:(a,t)=>`The agent failed to connect to its tool server${t[1]?` (${t[1]})`:""}. This typically means the MCP server is unreachable or took too long to respond.`,severity:"critical",options:[ye,{label:"Check MCP server",description:"Investigate the tool server connection before retrying.",impliedStatus:"approved"},K],extractDetails:(a,t)=>({server:t[1]||void 0})},{test:/(?:Slice|Autopilot slice) timed out after (\d+)/i,headline:"Agent ran out of time",explain:(a,t)=>{const u=Math.round(parseInt(t[1],10)/6e4);return`The agent exceeded its ${u>0?`${u}-minute`:`${t[1]}ms`} time limit. Consider breaking the work into smaller steps or increasing the time budget.`},severity:"warning",options:[{label:"Retry with more time",description:"Increase the timeout before re-running.",impliedStatus:"approved"},{label:"Break into smaller tasks",description:"Split the workstream into smaller pieces that fit the time budget.",impliedStatus:"approved"},K],extractDetails:(a,t)=>({elapsedMs:t[1]})},{test:/(?:Slice|Autopilot slice) stalled/i,headline:"Agent stopped making progress",explain:()=>"The agent stopped producing output. It may be stuck in a loop, waiting on an unresponsive resource, or unable to proceed with the current approach.",severity:"warning",options:[ye,{label:"Review logs",description:"Check the session logs to understand why the agent stalled.",impliedStatus:"approved"},K]},{test:/blocked.*?(?:needs|requires?) intervention/i,headline:"Agent needs your help to continue",explain:()=>"The agent reached a point where it cannot proceed without human guidance. This may be a question about requirements, a permission needed, or an ambiguity.",severity:"warning",options:[{label:"Review blocker",description:"Look at what the agent needs and provide guidance.",impliedStatus:"approved"},{label:"Provide guidance",description:"Add a note with instructions for the agent.",impliedStatus:"approved"},K]},{test:/completed.*?(?:without|no) (?:verifiable )?(?:outcomes?|artifacts?)/i,headline:"Agent finished but produced no outputs",explain:()=>"The agent reported completion but produced no artifacts or status updates. The work may have been done informally, or the agent could not find actionable work.",severity:"info",options:[{label:"Accept as-is",description:"The work was done informally or no output was needed.",impliedStatus:"approved"},{label:"Retry with stronger output requirements",description:"Re-run and require the agent to produce structured artifacts.",impliedStatus:"approved"},K]},{test:/Spawn guard denied/i,headline:"Agent dispatch was blocked by safety check",explain:()=>"The system's safety checks prevented this agent from starting. This is typically due to capacity limits or quality gate requirements.",severity:"warning",options:[{label:"Approve exception",description:"Override the safety check and allow dispatch.",impliedStatus:"approved"},{label:"Investigate quality gate",description:"Review what safety check failed before proceeding.",impliedStatus:"approved"},K]},{test:/code=(\d+)/i,headline:"Agent encountered an error",explain:(a,t)=>`The agent process exited with error code ${t[1]}. Reviewing the session logs will show what operation failed.`,severity:"critical",options:[ye,{label:"Review error logs",description:"Check session logs to understand the error before retrying.",impliedStatus:"approved"},K],extractDetails:(a,t)=>({exitCode:t[1]})}];function et(a){var u;const t=a.context||a.title||"";for(const p of He){const b=t.match(p.test);if(b)return{headline:p.headline,explanation:p.explain(t,b),structuredDetails:((u=p.extractDetails)==null?void 0:u.call(p,t,b))??{},suggestedOptions:p.options,severity:p.severity}}return a.decisionType==="autopilot_failure"?{headline:"Agent work needs attention",explanation:t||"An issue occurred during autopilot execution that requires review.",structuredDetails:{},suggestedOptions:[ye,K],severity:"warning"}:{headline:a.title||"Decision needed",explanation:t||"Review the details and choose an action.",structuredDetails:{},suggestedOptions:[],severity:"info"}}function tt(a){return a.map((t,u)=>({id:`suggested-${u}`,label:t.label,description:t.description,impliedStatus:t.impliedStatus,actionType:null,requiresNote:!1}))}function rt(a,t){var w;if(!t||!a.workstreamId||!t.nodes.find(k=>k.id===a.workstreamId&&k.entityType==="workstream"))return null;const p=new Set(t.edges.filter(k=>k.source===a.workstreamId).map(k=>k.target)),b=[];for(const k of p){const N=t.nodes.find(B=>B.id===k);N&&b.push({id:N.id,title:N.title,taskCount:((w=N.children)==null?void 0:w.length)??0,status:N.status})}if(b.length===0)return null;const v=b.reduce((k,N)=>k+N.taskCount,0),R=b.some(k=>t.edges.some(N=>N.source===k.id));return{blockedWorkstreams:b,totalBlockedTasks:v,criticalPath:R}}function st(a){const t=a.blockedWorkstreams.length,u=a.blockedWorkstreams.map(p=>p.title);return t===1?`Resolving this unblocks 1 downstream workstream: ${u[0]}.`:t<=3?`Resolving this unblocks ${t} downstream workstreams: ${u.join(", ")}.`:`Resolving this unblocks ${t} downstream workstreams including ${u[0]} and ${u[1]}.`}const Pe=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent);function nt(a){try{return JSON.stringify(a,null,2)}catch{return null}}function Fe(a){if(typeof a!="string")return null;const t=a.trim().toLowerCase();return t==="rejected"?"declined":t==="approved"||t==="declined"||t==="cancelled"?t:null}function Ce(a,t){return!a||a.trim().length===0?t:Le(a.trim())||t}function it(a){switch(a){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 a.replace(/[_-]/g," ").replace(/\b\w/g,t=>t.toUpperCase())}}function at(a){const t=a.toLowerCase();return t==="critical"||t==="p0"?T.red:t==="high"||t==="p1"?T.amber:t==="medium"||t==="p2"?T.iris:"rgba(255,255,255,0.5)"}function lt({open:a,decision:t,onClose:u,onApprove:p,onReject:b,initiativeTitle:v,workstreamTitle:R,onNavigate:w,currentIndex:k,totalCount:N,onFocusRunId:B,graph:O}){const[E,_]=o.useState("idle"),[M,y]=o.useState(null),[P,F]=o.useState(null),[C,X]=o.useState(""),[ve,ee]=o.useState(!1),[de,je]=o.useState(!1),J=o.useRef(null),ae=o.useRef(),ue=o.useRef(u);ue.current=u,o.useEffect(()=>{if(a){_("idle"),y(null);const i=(t==null?void 0:t.selectedOptionId)??(t!=null&&t.options&&t.options.length===1?t.options[0].id:null);F(i),X(""),ee(!1),je(!1)}return()=>{ae.current&&clearTimeout(ae.current)}},[a,t==null?void 0:t.id]);const z=t==null?void 0:t.metadata,W=o.useMemo(()=>{if(!z)return[];const i=z,l=i.decision_options??i.options??i.actions??null;if(!Array.isArray(l))return[];const j=[],D=new Set;for(let L=0;L<l.length;L+=1){const Q=l[L];if(typeof Q=="string"){const s=Q.trim();if(!s)continue;const r=`option-${L+1}`;if(D.has(r))continue;D.add(r),j.push({id:r,label:s,description:null,impliedStatus:null,actionType:null,requiresNote:!1});continue}if(!Q||typeof Q!="object")continue;const g=Q,be=typeof g.id=="string"&&g.id.trim()||typeof g.option_id=="string"&&g.option_id.trim()||typeof g.action_id=="string"&&g.action_id.trim()||`option-${L+1}`;if(D.has(be))continue;const we=typeof g.label=="string"&&g.label.trim()||typeof g.title=="string"&&g.title.trim()||typeof g.name=="string"&&g.name.trim()||typeof g.action=="string"&&g.action.trim()||null;we&&(D.add(be),j.push({id:be,label:we,description:typeof g.description=="string"?g.description:null,impliedStatus:Fe(g.implied_status)??Fe(g.status),actionType:typeof g.action_type=="string"&&g.action_type||typeof g.type=="string"&&g.type||null,requiresNote:g.requires_note===!0||g.requiresNote===!0||g.note_required===!0}))}return j.slice(0,12)},[z]),f=o.useMemo(()=>t?et(t):null,[t==null?void 0:t.context,t==null?void 0:t.title,t==null?void 0:t.decisionType]),te=o.useMemo(()=>t?rt(t,O??null):null,[t==null?void 0:t.workstreamId,t==null?void 0:t.initiativeId,O]),le=((t==null?void 0:t.waitingMinutes)??0)>1440,A=o.useMemo(()=>t!=null&&t.options&&t.options.length>0?t.options:W.length>0?W:f&&f.suggestedOptions.length>0?tt(f.suggestedOptions):[],[t==null?void 0:t.options,W,f]),x=o.useMemo(()=>A.find(i=>i.id===P)??null,[A,P]),pe=(x==null?void 0:x.requiresNote)===!0,h=o.useMemo(()=>{const i=((t==null?void 0:t.context)??"").trim();if(i)return i;if(!z)return"";const l=z,j=(typeof l.summary=="string"?l.summary:null)??(typeof l.description=="string"?l.description:null)??"";return String(j??"").trim()},[t==null?void 0:t.context,z]),V=o.useMemo(()=>{const i=(t==null?void 0:t.waitingMinutes)??0;return i>=15?T.red:i>=5?T.amber:T.teal},[t==null?void 0:t.waitingMinutes]),q=o.useCallback(async()=>{if(!t)return;const i=nt({decision:t,metadata:z});if(i)try{await navigator.clipboard.writeText(i),ee(!0),setTimeout(()=>ee(!1),2e3)}catch{}},[t,z]),U=o.useCallback(()=>{const i=C.trim(),l=x==null?void 0:x.id;if(!(!i&&!l))return{note:i.length>0?i:void 0,optionId:l??void 0}},[C,x]),re=o.useCallback(async()=>{if(!t||!p)return;if(A.length>0&&!x){y("Select an option before approving this decision.");return}if(x!=null&&x.requiresNote&&C.trim().length===0){y("A note is required for the selected option."),requestAnimationFrame(()=>{var l;return(l=J.current)==null?void 0:l.focus()});return}let i=!1;if(_(l=>l==="approving"||l==="rejecting"?l:(i=!0,"approving")),!!i){y(null);try{const l=await p(t.id,U());l.failed>0?(_("error"),y(Ce(l.firstError,"Approval failed. Please try again."))):(_("success"),ae.current=setTimeout(()=>ue.current(),800))}catch(l){_("error");const j=l instanceof Error?l.message:"";y(Ce(j,"Approval failed."))}}},[U,t,C,p,A.length,x]),me=o.useCallback(async()=>{if(!t||!b)return;if(A.length>0&&!x){y("Select an option before rejecting this decision.");return}if(x!=null&&x.requiresNote&&C.trim().length===0){y("A note is required for the selected option."),requestAnimationFrame(()=>{var l;return(l=J.current)==null?void 0:l.focus()});return}let i=!1;if(_(l=>l==="approving"||l==="rejecting"?l:(i=!0,"rejecting")),!!i){y(null);try{const l=await b(t.id,U());l.failed>0?(_("error"),y(Ce(l.firstError,"Rejection failed. Please try again."))):(_("rejected"),ae.current=setTimeout(()=>ue.current(),800))}catch(l){_("error");const j=l instanceof Error?l.message:"";y(Ce(j,"Rejection failed."))}}},[U,t,C,b,A.length,x]);if(o.useEffect(()=>{if(!a)return;const i=l=>{var D,L;if((l.metaKey||l.ctrlKey)&&l.key==="Enter"){l.preventDefault(),re();return}const j=(D=l.target)==null?void 0:D.tagName;if(!(j==="INPUT"||j==="TEXTAREA"))switch(l.key){case"j":l.preventDefault(),w==null||w(1);break;case"k":l.preventDefault(),w==null||w(-1);break;case"a":l.preventDefault(),re();break;case"r":l.preventDefault(),me();break;case"n":l.preventDefault(),(L=J.current)==null||L.focus();break}};return document.addEventListener("keydown",i),()=>document.removeEventListener("keydown",i)},[a,re,me,w]),!a||!t)return null;const Z=E==="approving"||E==="rejecting",Me=E==="success"||E==="rejected",se=(t.status??"pending").toLowerCase(),ke=!se.includes("approved")&&!se.includes("resolved")&&!se.includes("rejected")&&!se.includes("declined")&&!se.includes("cancelled"),Ne=A.length>0&&!x,$e=(x==null?void 0:x.requiresNote)===!0&&C.trim().length===0,G=Z||Ne||$e,$=t.evidenceRefs??[],Ie=$.length>0,Se=t.recommendedAction??null,xe=t.decisionType??null,he=t.priority??null,fe=t.occurrenceCount??null,I=t.sourceRunId??null,ne=[];v&&ne.push({label:v,icon:"initiative"}),R&&ne.push({label:R,icon:"workstream"});const ge=[["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(Me){const i=E==="success",l=i?T.lime:T.red;return e.jsx(qe,{open:a,onClose:u,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:`${l}18`,border:`1.5px solid ${l}40`},children:i?e.jsx("svg",{width:"28",height:"28",viewBox:"0 0 24 24",fill:"none",stroke:l,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:l,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(qe,{open:a,onClose:u,maxWidth:"max-w-xl",children:e.jsxs("div",{className:"flex h-full min-h-0 w-full flex-col",style:le?{boxShadow:`inset 0 0 0 1px ${T.amber}30`,borderRadius:"inherit"}:void 0,children:[e.jsx("div",{className:"h-[2px] w-full flex-shrink-0",style:{background:`linear-gradient(90deg, ${V}60, ${V}20, transparent)`}}),w&&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:()=>w(-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:()=>w(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"})})}),k!=null&&N!=null&&e.jsxs("span",{className:"text-micro text-muted tabular-nums",children:[k+1," of ",N,e.jsx("span",{className:"ml-1 hidden sm:inline",children:"· Longest waiting first"})]})]}),e.jsx("button",{type:"button",onClick:u,"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"})})})]}),ne.length>0&&e.jsx("div",{className:"px-6 pt-2",children:e.jsx(Ye,{segments:ne})}),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:`${V}14`,border:`1px solid ${V}30`},children:e.jsx(ie,{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",{className:le?"font-semibold text-red-300":"",children:H(t.waitingMinutes).text}),xe&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-white/[0.15]",children:"|"}),e.jsx("span",{className:"text-primary",children:it(xe)})]}),he&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-white/[0.15]",children:"|"}),e.jsx("span",{className:"font-medium",style:{color:at(he)},children:he})]})]}),fe!=null&&fe>1&&e.jsxs("p",{className:"mt-2 text-caption text-muted",children:["Seen ",fe," times",t.firstSeenAt&&e.jsxs(e.Fragment,{children:[" · first ",De(t.firstSeenAt)]}),t.lastSeenAt&&e.jsxs(e.Fragment,{children:[" · last ",De(t.lastSeenAt)]})]})]})]})}),!w&&e.jsx("button",{type:"button",onClick:u,"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(Be,{nodes:Oe({initiativeId:t.initiativeId,initiativeTitle:v,workstreamId:t.workstreamId,workstreamTitle:R,agentName:t.agentName,agentId:t.agentId}),activeId:t.workstreamId,compact:!0})}),Se&&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:Se})]}),Ie&&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:$.map((i,l)=>e.jsx(Qe,{evidenceType:i.evidenceType,title:i.title,summary:i.summary,sourceUrl:i.sourceUrl,confidence:i.confidence,payload:i.payload},l))})]}),le&&e.jsx("div",{className:"mb-4 rounded-xl border border-amber-400/[0.3] bg-amber-500/[0.08] px-4 py-3",children:e.jsxs("p",{className:"text-body text-amber-200",children:["This decision has been waiting"," ",e.jsx("span",{className:"font-semibold text-amber-100",children:H(t.waitingMinutes).text}),". Downstream work is paused."]})}),f&&f.headline!==t.title?e.jsxs("div",{className:"rounded-xl border border-white/[0.06] bg-white/[0.02] px-4 py-3",children:[e.jsx("p",{className:"text-micro font-semibold uppercase tracking-wider text-muted mb-2",children:"What happened"}),e.jsx("p",{className:"text-body text-primary leading-relaxed",children:f.explanation}),Object.keys(f.structuredDetails).length>0&&e.jsx("div",{className:"mt-3 flex flex-wrap gap-x-4 gap-y-1 text-caption text-secondary",children:Object.entries(f.structuredDetails).filter(([,i])=>i!=null).map(([i,l])=>e.jsxs("span",{children:[i.replace(/([A-Z])/g," $1").replace(/^./,j=>j.toUpperCase()),": ",l]},i))})]}):h?e.jsx("div",{className:"rounded-xl border border-white/[0.06] bg-white/[0.02] px-4 py-3",children:e.jsx(ze,{text:h,mode:"block"})}):e.jsx("p",{className:"px-1 text-body text-muted italic",children:"No additional context provided."}),A.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:A.map(i=>{const l=P===i.id;return e.jsxs("button",{type:"button",onClick:()=>{F(l?null:i.id),i.requiresNote&&requestAnimationFrame(()=>{var j;return(j=J.current)==null?void 0:j.focus()})},disabled:Z,className:"group relative flex w-full items-start gap-4 px-4 py-4 text-left focus:outline-none",children:[l&&e.jsx(ce.div,{layoutId:"decision-option-bg",className:"absolute inset-0 rounded-xl",style:{backgroundColor:`${T.lime}12`},transition:{type:"spring",stiffness:400,damping:25}}),!l&&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:l?T.lime:"rgba(255,255,255,0.2)"},children:e.jsx(Re,{children:l&&e.jsx(ce.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:T.lime}})})}),e.jsxs("div",{className:"relative min-w-0 flex-1",children:[e.jsx("span",{className:`block text-[15px] ${l?"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)})})]}),ke&&pe&&e.jsxs("div",{className:"mt-4",children:[e.jsx("textarea",{ref:J,value:C,onChange:i=>X(i.target.value),disabled:Z,placeholder:"Required: add 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]"}),C.trim().length===0&&e.jsx("p",{className:"mt-2 text-caption text-amber-300",children:"This option requires a note before submission."})]}),te&&e.jsxs("div",{className:"mt-6 rounded-xl border border-white/[0.06] bg-white/[0.02] px-4 py-3",children:[e.jsx("p",{className:"text-micro font-semibold uppercase tracking-wider text-muted mb-2",children:"Impact"}),e.jsx("p",{className:"text-body text-primary leading-relaxed",children:st(te)}),te.blockedWorkstreams.length>0&&e.jsx("ul",{className:"mt-2 space-y-1 text-caption text-secondary",children:te.blockedWorkstreams.map(i=>e.jsxs("li",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"inline-block h-1 w-1 rounded-full bg-amber-400 flex-shrink-0"}),i.title,i.status==="blocked"&&e.jsx("span",{className:"text-amber-400 text-micro",children:"(blocked)"})]},i.id))})]}),I&&B&&e.jsx("div",{className:"mt-4",children:e.jsxs("button",{type:"button",onClick:()=>B(I),className:"inline-flex items-center gap-1.5 text-caption text-[#D8FFA1] transition-colors hover:text-white",children:[e.jsx(ie,{type:"session",size:12}),"View source run"]})}),e.jsx("div",{className:"mt-4 border-t border-white/[0.06] pt-4",children:e.jsx(Ge,{entityType:"decision",entityId:t.id})}),ge.length>0&&e.jsxs("div",{className:"mt-4 border-t border-white/[0.06] pt-2",children:[e.jsxs("button",{type:"button",onClick:()=>je(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 ${de?"rotate-180":""}`,children:e.jsx("path",{d:"m6 9 6 6 6-6"})})]}),de&&e.jsx("div",{className:"mt-2 space-y-0.5",children:ge.map(([i,l])=>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:l})]},i))})]}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-x-3 gap-y-1 text-micro text-muted opacity-60",children:[w&&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:[Pe?"⌘":"Ctrl","+Enter approve"]}),e.jsx("span",{children:"esc close"})]})]}),M&&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:T.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:M})]}),ke&&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:[b&&e.jsx(ce.button,{whileTap:{scale:.97},type:"button",onClick:me,disabled:G,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:q,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:ve?"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:[Pe?"⌘":"Ctrl","+Enter"]}),e.jsx(ce.button,{whileTap:!p||G?void 0:{scale:.97},type:"button",onClick:re,disabled:!p||G,"data-modal-autofocus":"true",className:"rounded-lg px-6 py-2.5 text-[14px] font-semibold transition-all focus:outline-none",style:{backgroundColor:!p||G?"rgba(255,255,255,0.06)":T.lime,color:!p||G?"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 Te=40;function Ae(a,t){return!a||a.trim().length===0?t:Le(a.trim())||t}function Ee(a,t,u){const p=a==="approve"?`Approval failed for ${t} decision${t===1?"":"s"}.`:`Rejection failed for ${t} decision${t===1?"":"s"}.`;return Ae(u,p)}function _e(a){return a>=1440?"overdue":a>=60?"urgent":"normal"}function ot(a){return a.length>=32?a.slice(0,8):a}function We({group:a}){const t=_e(a.worstWaitingMinutes),u=a.decisions.length;return e.jsxs("div",{className:"flex items-center gap-2 px-1 pb-1 pt-2.5 first:pt-0",children:[e.jsx("span",{className:"text-caption font-semibold text-white/70 truncate",children:a.label}),e.jsxs("span",{className:"text-micro text-muted whitespace-nowrap",children:["(",u," decision",u===1?"":"s",")"]}),t==="overdue"&&e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-red-500/[0.12] px-1.5 py-0.5 text-micro font-medium text-red-400",children:[e.jsx("span",{"aria-hidden":!0,className:"h-1.5 w-1.5 rounded-full bg-red-400"}),"overdue"]}),t==="urgent"&&e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-amber-400/[0.12] px-1.5 py-0.5 text-micro font-medium text-amber-400",children:[e.jsx("span",{"aria-hidden":!0,className:"h-1.5 w-1.5 rounded-full bg-amber-400"}),"urgent"]})]})}function ct(a,t){return`${a}_${t}`}const wt=o.memo(function({decisions:t,focusDecisionId:u=null,onFocusDecisionHandled:p,onApproveDecision:b,onRejectDecision:v,onApproveAll:R,onBulkDecisionAction:w,mutationState:k,showHeader:N=!0,panelStyle:B="card",className:O,initiativeNames:E}){var we;const _=Ke(),[M,y]=o.useState(!1),[P,F]=o.useState(new Set),[C,X]=o.useState(new Set),[ve,ee]=o.useState(new Set),{enqueue:de,ToastRenderer:je}=Xe(),[J,ae]=o.useState("approve_selected"),[ue,z]=o.useState(""),[W,f]=o.useState(null),[te,le]=o.useState(Te),[A,x]=o.useState(null),pe=o.useRef(null),h=o.useMemo(()=>{const s=new Set;return[...t].filter(r=>s.has(r.id)?!1:(s.add(r.id),!0)).sort((r,n)=>{if(r.waitingMinutes!==n.waitingMinutes)return n.waitingMinutes-r.waitingMinutes;const c=Date.parse(r.requestedAt??r.updatedAt??""),d=Date.parse(n.requestedAt??n.updatedAt??""),m=Number.isFinite(c)?c:0;return(Number.isFinite(d)?d:0)-m})},[t]);o.useEffect(()=>{X(s=>{const r=new Set(h.map(c=>c.id)),n=new Set;for(const c of s)r.has(c)&&n.add(c);return n})},[h]);const V=C.size,q=o.useMemo(()=>h.filter(s=>!ve.has(s.id)).slice(0,te),[h,te,ve]),U=o.useMemo(()=>{const s=new Map,r=[];for(const c of q){const d=c.initiativeId??"_unscoped";let m=s.get(d);m||(m=[],s.set(d,m),r.push(d)),m.push(c)}const n=r.map(c=>{const d=s.get(c),m=Math.max(0,...d.map(Y=>Y.waitingMinutes)),S=c==="_unscoped"?"General":(E==null?void 0:E[c])??ot(c);return{initiativeId:c,label:S,decisions:d,worstWaitingMinutes:m}});return n.sort((c,d)=>d.worstWaitingMinutes-c.worstWaitingMinutes),n},[q,E]),re=o.useMemo(()=>{if(q.length===0)return!1;for(const s of q)if(!C.has(s.id))return!1;return!0},[C,q]),me=o.useMemo(()=>A?h.find(s=>s.id===A)??null:null,[A,h]),Z=o.useMemo(()=>A?h.findIndex(s=>s.id===A):-1,[A,h]),Me=o.useCallback(s=>{const r=Z+s;r>=0&&r<h.length&&x(h[r].id)},[Z,h]),se=async(s,r)=>{f(null),F(c=>{const d=new Set(c);return d.add(s),d});const n=await b(s,r);return n.failed>0?f(Ee("approve",n.failed,n.firstError)):n.updated>0&&f("Decision approved. Changes synced."),F(c=>{const d=new Set(c);return d.delete(s),d}),n},ke=v?async(s,r)=>{f(null),F(c=>{const d=new Set(c);return d.add(s),d});const n=await v(s,r);return n.failed>0?f(Ee("reject",n.failed,n.firstError)):n.updated>0&&f("Decision rejected. Changes synced."),F(c=>{const d=new Set(c);return d.delete(s),d}),n}:void 0;o.useEffect(()=>{le(s=>h.length===0?0:Math.min(Math.max(Te,s),h.length))},[h.length]),o.useEffect(()=>{const s=(u??"").trim();if(!s){pe.current=null;return}pe.current===s||!h.some(n=>n.id===s)||(pe.current=s,x(s),p==null||p(s))},[u,p,h]);const Ne=s=>{X(r=>{const n=new Set(r);return n.has(s)?n.delete(s):n.add(s),n})},$e=()=>{X(s=>{if(q.length===0)return s;const r=new Set(s),n=re;for(const c of q)n?r.delete(c.id):r.add(c.id);return r})},G=o.useMemo(()=>{const s=h.map(n=>n.id).filter(n=>C.has(n)),r=q.map(n=>n.id);return[{id:"approve_selected",label:`Approve selected (${s.length})`,action:"approve",ids:s},{id:"reject_selected",label:`Reject selected (${s.length})`,action:"reject",ids:s,hidden:!v},{id:"approve_visible",label:`Approve visible (${r.length})`,action:"approve",ids:r},{id:"reject_visible",label:`Reject visible (${r.length})`,action:"reject",ids:r,hidden:!v}].filter(n=>!n.hidden)},[v,C,h,q]),$=o.useMemo(()=>G.find(s=>s.id===J)??G[0]??null,[J,G]),Ie=async(s,r,n)=>{if(s.length===0)return{updated:0,failed:0};if(r==="approve"&&s.length===h.length&&!n)return R();let c=0,d=0,m;for(const S of s)try{const Y=r==="approve"?await b(S,n?{note:n}:void 0):v?await v(S,n?{note:n}:void 0):{updated:0,failed:1};c+=Y.updated,d+=Y.failed,!m&&Y.firstError&&(m=Y.firstError)}catch{d+=1}return{updated:c,failed:d,firstError:m}},Se=async()=>{if(!$||M)return;const s=$.ids;if(s.length===0){f("No decisions selected for this action.");return}f(null),y(!0),F(new Set(s));const r=ue.trim();try{const n=w?await w(s,$.action,r.length>0?r:void 0):await Ie(s,$.action,r.length>0?r:void 0),c=$.action==="approve"?"Approved":"Rejected";if(n.failed>0){const d=`${c} ${n.updated}; ${n.failed} failed.`,m=Ae(n.firstError,d);f(m===d?d:`${d} ${m}`)}else n.updated>0?f(`${c} ${n.updated} decision${n.updated===1?"":"s"}.`):f("No decisions were updated.");X(new Set)}catch(n){const c=n instanceof Error?n.message:"";f(Ae(c,"Bulk decision action failed."))}finally{y(!1),F(new Set)}},xe=async s=>{if(!(P.has(s)||M)){f(null),F(r=>{const n=new Set(r);return n.add(s),n});try{const r=await b(s);r.failed>0?f(Ee("approve",r.failed,r.firstError)):r.updated>0&&f("Decision approved.")}catch(r){const n=r instanceof Error?r.message:"";f(Ae(n,"Decision approval failed."))}finally{F(r=>{const n=new Set(r);return n.delete(s),n}),X(r=>{if(!r.has(s))return r;const n=new Set(r);return n.delete(s),n})}}},he=o.useCallback(s=>{P.has(s.id)||M||(ee(r=>new Set(r).add(s.id)),de({message:`Approved '${s.title.length>40?s.title.slice(0,40)+"…":s.title}'`,onUndo:()=>{ee(r=>{const n=new Set(r);return n.delete(s.id),n})},onCommit:()=>{ee(r=>{const n=new Set(r);return n.delete(s.id),n}),b(s.id).catch(()=>{f("Approval failed. Try again from the decision panel.")})}}))},[P,M,de,b]);o.useEffect(()=>{if(!W)return;const s=window.setTimeout(()=>f(null),5200);return()=>window.clearTimeout(s)},[W]);const fe=W!==null&&!W.toLowerCase().includes("fail"),I=M||P.size>0,ne=Math.max(P.size,M?V:0),ge=I?`Applying ${ne} decision action${ne===1?"":"s"}…`:W??null,i=I?"processing":W?fe?"success":"warning":"idle",l=!_&&q.length<=32,j=$!==null&&$.ids.length>0&&!M,D=h.length;(we=h[0])==null||we.waitingMinutes;const L=$!=null&&$.id.includes("visible")?"visible":"selected",Q=($==null?void 0:$.action)??"approve",g=ge!==null||i!=="idle",be=B==="card"?Ue:"div";return e.jsxs(be,{className:oe("flex h-full min-h-0 flex-col",B==="card"&&"card-enter",O),children:[e.jsx(lt,{open:A!==null,decision:me,onClose:()=>x(null),onApprove:se,onReject:ke,onNavigate:Me,currentIndex:Z>=0?Z:void 0,totalCount:h.length}),N?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(ie,{type:"decision",size:14}),"Decisions"]}),e.jsx("p",{className:"mt-0.5 text-caption text-secondary",children:D>0?`${D} decision${D===1?"":"s"} need${D===1?"s":""} your input`:"All clear — no decisions pending"})]})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[h.length>0&&e.jsx("button",{onClick:$e,disabled:I,className:"control-pill h-8 flex-shrink-0 px-3 text-caption font-semibold disabled:opacity-45",children:re?"Clear all":"Select all"}),V>0&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:Se,disabled:!j||I,"data-state":j?"active":"idle",className:"control-pill h-8 flex-shrink-0 px-3 text-caption font-semibold disabled:opacity-45",children:M?"Approving…":`Approve ${V} selected`}),v&&e.jsx("button",{type:"button",onClick:()=>ae(ct("reject",L)),disabled:I,"data-state":Q==="reject"?"active":"idle",className:oe("control-pill h-8 px-2.5 text-caption font-semibold disabled:opacity-45",Q==="reject"&&"border-amber-300/35 bg-amber-400/[0.12] text-amber-100"),children:"Reject"})]})]}),g?e.jsxs("div",{"aria-live":"polite",className:oe("flex min-h-[32px] items-center gap-2 rounded-lg border px-2.5 py-1.5 text-caption transition-colors",i==="processing"?"border-amber-300/25 bg-amber-400/[0.08] text-amber-100":i==="success"?"border-lime/30 bg-lime/10 text-lime":i==="warning"?"border-red-400/25 bg-red-500/[0.08] text-red-100":"border-strong bg-white/[0.02] text-secondary"),children:[i==="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"}):i==="success"?e.jsx(ie,{type:"decision",size:12,className:"opacity-90"}):i==="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:ge})]}):null]}):null,e.jsxs("div",{className:oe("min-h-0 flex-1 space-y-2 overflow-y-auto",N?"p-3":"p-0"),children:[h.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:I?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."})]})}),l?e.jsx(Re,{mode:"popLayout",children:U.map(s=>e.jsxs("div",{children:[U.length>1&&e.jsx(We,{group:s}),s.decisions.map((r,n)=>{const c=P.has(r.id),d=C.has(r.id),m=_e(r.waitingMinutes);return e.jsx(ce.article,{role:"button",tabIndex:0,onClick:()=>x(r.id),onKeyDown:S=>{(S.key==="Enter"||S.key===" ")&&(S.preventDefault(),x(r.id))},drag:!I&&!c?"x":!1,dragConstraints:{left:0,right:0},dragElastic:.3,onDragEnd:(S,Y)=>{Y.offset.x>120&&he(r)},initial:M?{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],...M?{delay:n*.04}:{}},layout:!0,className:"mt-1.5 rounded-xl border bg-white/[0.03] px-3 py-2.5 transition-[border-color,box-shadow] cv-auto",style:{borderColor:d?`${T.lime}50`:"rgba(255, 255, 255, 0.1)",boxShadow:d?"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:d,onChange:()=>Ne(r.id),disabled:c||I,onClick:S=>S.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("div",{className:"flex min-w-0 items-start gap-1.5",children:[m!=="normal"&&e.jsx("span",{"aria-label":m==="overdue"?"Overdue":"Urgent",className:oe("mt-[5px] h-2 w-2 flex-shrink-0 rounded-full",m==="overdue"?"bg-red-400":"bg-amber-400")}),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(ie,{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 S=H(r.waitingMinutes);return S.tone==="urgent"?"text-red-400":S.tone==="attention"?"text-amber-400":"text-muted"})()}`,title:`${r.agentName??"OrgX Autopilot"} · ${H(r.waitingMinutes).text}`,children:[r.agentName??"OrgX Autopilot"," · ",H(r.waitingMinutes).text]}),e.jsx("button",{onClick:S=>{S.stopPropagation(),xe(r.id)},disabled:c||I,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:c?"Approving…":"Approve"}),v&&e.jsx("button",{onClick:S=>{S.stopPropagation(),x(r.id)},disabled:c||I,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)})]},s.initiativeId))}):e.jsx(e.Fragment,{children:U.map(s=>e.jsxs("div",{children:[U.length>1&&e.jsx(We,{group:s}),s.decisions.map(r=>{const n=P.has(r.id),c=C.has(r.id),d=_e(r.waitingMinutes);return e.jsx("article",{role:"button",tabIndex:0,onClick:()=>x(r.id),onKeyDown:m=>{(m.key==="Enter"||m.key===" ")&&(m.preventDefault(),x(r.id))},className:"mt-1.5 rounded-xl border bg-white/[0.03] px-3 py-2.5 transition-[border-color,box-shadow] cv-auto",style:{borderColor:c?`${T.lime}50`:"rgba(255, 255, 255, 0.1)",boxShadow:c?"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:c,onChange:()=>Ne(r.id),disabled:n||I,onClick:m=>m.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("div",{className:"flex min-w-0 items-start gap-1.5",children:[d!=="normal"&&e.jsx("span",{"aria-label":d==="overdue"?"Overdue":"Urgent",className:oe("mt-[5px] h-2 w-2 flex-shrink-0 rounded-full",d==="overdue"?"bg-red-400":"bg-amber-400")}),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(ie,{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 m=H(r.waitingMinutes);return m.tone==="urgent"?"text-red-400":m.tone==="attention"?"text-amber-400":"text-muted"})()}`,title:`${r.agentName??"OrgX Autopilot"} · ${H(r.waitingMinutes).text}`,children:[r.agentName??"OrgX Autopilot"," · ",H(r.waitingMinutes).text]}),e.jsx("button",{onClick:m=>{m.stopPropagation(),xe(r.id)},disabled:n||I,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:n?"Approving…":"Approve"}),v&&e.jsx("button",{onClick:m=>{m.stopPropagation(),x(r.id)},disabled:n||I,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)})]},s.initiativeId))}),q.length<h.length&&e.jsxs("button",{onClick:()=>le(s=>Math.min(h.length,s+Te)),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 (",h.length-q.length," remaining)"]})]}),e.jsx(je,{})]})});export{wt as DecisionQueue};
|
|
Binary file
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as a,j as e}from"./Dj2k1r16.js";import{e as i}from"./
|
|
1
|
+
import{r as a,j as e}from"./Dj2k1r16.js";import{e as i}from"./BV2Tf8S2.js";import{A as m,m as x}from"./eeHXe_OQ.js";function f({message:l,durationMs:s=5e3,onUndo:d,onExpire:r}){const[t,c]=a.useState(!0),o=a.useRef();a.useEffect(()=>(o.current=setTimeout(()=>{c(!1),r()},s),()=>clearTimeout(o.current)),[s,r]);const n=()=>{clearTimeout(o.current),c(!1),d()};return e.jsx(m,{children:t&&e.jsx(x.div,{initial:{opacity:0,y:20,scale:.95},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:10,scale:.95},transition:{duration:.22,ease:[.22,1,.36,1]},className:"fixed bottom-6 left-1/2 z-50 -translate-x-1/2",children:e.jsxs("div",{className:"flex items-center gap-3 rounded-xl px-4 py-2.5 shadow-lg",style:{backgroundColor:i.cardBgElevated,border:`1px solid ${i.cardBorderStrong}`},children:[e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:i.lime,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M20 6 9 17l-5-5"})}),e.jsx("span",{className:"text-body text-primary",children:l}),e.jsx("button",{onClick:n,className:"ml-1 rounded-md px-2.5 py-1 text-caption font-semibold transition-colors hover:bg-white/[0.08]",style:{color:i.lime},children:"Undo"}),e.jsx("div",{className:"absolute bottom-0 left-3 right-3 h-0.5 overflow-hidden rounded-full",children:e.jsx("div",{className:"h-full origin-left rounded-full",style:{backgroundColor:i.lime,opacity:.4,animation:`undoCountdown ${s}ms linear forwards`}})})]})})})}function y(){const[l,s]=a.useState([]),d=o=>{const n=`undo-${Date.now()}-${Math.random().toString(36).slice(2,6)}`;return s(u=>[...u,{...o,id:n}]),n},r=o=>{s(n=>n.filter(u=>u.id!==o))},t=l[0]??null;return{enqueue:d,ToastRenderer:()=>t?e.jsx(f,{message:t.message,onUndo:()=>{t.onUndo(),r(t.id)},onExpire:()=>{t.onCommit(),r(t.id)}},t.id):null}}export{y as u};
|
|
Binary file
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as r}from"./Dj2k1r16.js";import{B as s}from"./
|
|
1
|
+
import{j as r}from"./Dj2k1r16.js";import{B as s}from"./BV2Tf8S2.js";function i({className:e=""}){return r.jsx("div",{className:s("shimmer-skeleton",e),"aria-hidden":"true"})}export{i as S};
|
|
Binary file
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as c}from"./Dj2k1r16.js";import{c as m}from"./DMKyYAtD.js";import{b as g,h as n}from"./
|
|
1
|
+
import{r as c}from"./Dj2k1r16.js";import{c as m}from"./DMKyYAtD.js";import{b as g,h as n}from"./BV2Tf8S2.js";function h({authToken:s=null,embedMode:o=!1,enabled:i=!0}={}){var a;const u=c.useMemo(()=>["usage-control-plane",{authToken:s,embedMode:o}],[s,o]),e=m({queryKey:u,enabled:i,queryFn:async()=>{const t=await fetch("/orgx/api/usage/control-plane/summary",{headers:g({authToken:s,embedMode:o})}),r=await t.json().catch(()=>null);if(!t.ok){const l=(r&&typeof r=="object"&&"error"in r&&typeof r.error=="string"?r.error:null)??(r&&typeof r=="object"&&"message"in r&&typeof r.message=="string"?r.message:null)??`Failed to load usage summary (${t.status})`;throw new Error(n(l))}if(!r||typeof r!="object"||!("generatedAt"in r))throw new Error(n("Usage summary response is missing required fields."));return r},refetchInterval:6e4});return{summary:e.data??null,isLoading:e.isLoading,isFetching:e.isFetching,error:((a=e.error)==null?void 0:a.message)??null,refetch:e.refetch}}export{h as u};
|
|
Binary file
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as x,j as e}from"./Dj2k1r16.js";import{c as R}from"./DMKyYAtD.js";import{l as T,q as V,y as W,S as u,e as o,M as $,b as E}from"./
|
|
1
|
+
import{r as x,j as e}from"./Dj2k1r16.js";import{c as R}from"./DMKyYAtD.js";import{l as T,q as V,y as W,S as u,e as o,M as $,b as E}from"./BV2Tf8S2.js";import{S as b}from"./DXVs61e1.js";import"./eeHXe_OQ.js";import"./cX2e-TLi.js";import"./BjK42gtU.js";import"./BV0BcV1u.js";const f={draft:o.textMuted,in_review:o.amber,approved:o.lime,changes_requested:o.red,superseded:o.textMuted,archived:o.textMuted},U={draft:"Draft",in_review:"In Review",approved:"Approved",changes_requested:"Changes Requested",superseded:"Superseded",archived:"Archived"};function D(){return e.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:o.cyan,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"}),e.jsx("path",{d:"M14 2v4a2 2 0 0 0 2 2h4"}),e.jsx("path",{d:"M10 9H8"}),e.jsx("path",{d:"M16 13H8"}),e.jsx("path",{d:"M16 17H8"})]})}function J(){var M,_,C,L,I,q;const{state:l,close:m}=T(),g=null,j=!1,[c,p]=x.useState(null),{data:a,isLoading:F,isFetching:v,error:y,refetch:H}=R({queryKey:V.artifactDetail({artifactId:l.artifactId??"",authToken:g,embedMode:j}),enabled:!!l.artifactId,queryFn:async()=>{const i=E({authToken:g,embedMode:j}),s=await fetch(`/orgx/api/artifacts/${encodeURIComponent(l.artifactId)}`,{headers:i});if(!s.ok){const r=await s.json().catch(()=>null),d=(typeof(r==null?void 0:r.error)=="string"?r.error:null)??(r!=null&&r.error&&typeof r.error=="object"&&typeof r.error.message=="string"?r.error.message:null)??(typeof(r==null?void 0:r.message)=="string"?r.message:null),B=s.status===401?"Authentication required to view this artifact.":`Failed to fetch artifact (${s.status}).`;throw new Error(d!=null&&d.trim().length?d.trim():B)}return s.json()}}),t=a==null?void 0:a.artifact,S=(a==null?void 0:a.localFallback)===!0||((M=t==null?void 0:t.metadata)==null?void 0:M.local_fallback)===!0,w=(typeof(a==null?void 0:a.warning)=="string"&&a.warning.trim().length>0?a.warning:(_=t==null?void 0:t.metadata)==null?void 0:_.local_warning)??null,h=((C=t==null?void 0:t.metadata)==null?void 0:C.preview_markdown)??null,n=x.useMemo(()=>{if(!(t!=null&&t.metadata))return null;const i=[t.metadata.local_source_path,t.metadata.url,t.metadata.path,t.metadata.file_path,t.metadata.filepath,t.metadata.artifact_path,t.metadata.output_path];for(const s of i)if(typeof s=="string"&&s.trim().length>0)return s.trim();return null},[t==null?void 0:t.metadata]),k=x.useMemo(()=>n?/^https?:\/\//i.test(n)?n:`/orgx/api/live/filesystem/open?path=${encodeURIComponent(n)}`:null,[n]),N=((L=t==null?void 0:t.metadata)==null?void 0:L.external_url)??(t==null?void 0:t.artifact_url);x.useEffect(()=>{if(!c)return;const i=window.setTimeout(()=>p(null),2e3);return()=>window.clearTimeout(i)},[c]);const A=async(i,s)=>{try{await navigator.clipboard.writeText(i),p(`${s} copied`)}catch{p("Copy failed")}};return e.jsxs(W,{open:!!l.artifactId,onClose:m,maxWidth:"max-w-3xl",children:[F&&e.jsxs("div",{className:"p-6 space-y-4",children:[e.jsx(b,{className:"h-6 w-2/3"}),e.jsx(b,{className:"h-4 w-1/3"}),e.jsx(b,{className:"h-32 w-full"})]}),y&&e.jsxs("div",{className:"space-y-4 p-6",children:[e.jsxs("div",{className:"rounded-xl border border-red-300/22 bg-red-500/[0.08] p-4",children:[e.jsx("p",{className:"text-body font-semibold text-red-200",children:"Failed to load artifact"}),e.jsx("p",{className:"mt-1 text-caption leading-relaxed text-red-100/80",children:y.message})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",onClick:m,className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.08]",children:"Back to activity"}),e.jsx("button",{type:"button",onClick:()=>void H(),disabled:v,className:"rounded-full border border-red-300/22 bg-red-500/[0.08] px-3 py-1.5 text-caption font-semibold text-red-100 transition-colors hover:bg-red-500/[0.14] disabled:opacity-45",children:v?"Retrying…":"Retry"})]})]}),t&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-subtle px-5 py-4 sm:px-6",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx(D,{}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"truncate text-sm font-medium text-white",children:t.name}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[e.jsx(u,{tone:"muted",className:"text-micro uppercase tracking-[0.06em]",children:((I=t.catalog)==null?void 0:I.label)??t.artifact_type}),e.jsx(u,{tone:"neutral",className:"text-micro font-semibold uppercase tracking-[0.06em]",style:{color:f[t.status]??o.textMuted,backgroundColor:`${f[t.status]??o.textMuted}20`,borderColor:`${f[t.status]??o.textMuted}44`},children:U[t.status]??t.status}),((q=t.catalog)==null?void 0:q.domain)&&e.jsxs("span",{className:"text-micro text-faint",children:[t.catalog.domain," / ",t.catalog.stage]}),c&&e.jsx(u,{tone:"neutral",className:"text-micro text-secondary",children:c})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[N&&e.jsx("a",{href:N,target:"_blank",rel:"noopener noreferrer",className:"rounded-lg p-2 text-secondary transition-colors hover:bg-white/[0.08] hover:text-white",title:"Open source",children:e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M15 3h6v6"}),e.jsx("path",{d:"M10 14 21 3"}),e.jsx("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"})]})}),e.jsx("button",{onClick:m,className:"p-2 rounded-lg hover:bg-white/[0.06] text-secondary hover:text-white transition-colors",children:e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 6 6 18"}),e.jsx("path",{d:"m6 6 12 12"})]})})]})]}),e.jsxs("div",{className:"max-h-[65vh] overflow-y-auto px-5 py-4 sm:px-6 space-y-4",children:[S&&e.jsxs("div",{className:"rounded-xl border border-amber-300/25 bg-amber-500/[0.09] p-4",children:[e.jsx("p",{className:"text-caption font-semibold uppercase tracking-[0.08em] text-amber-100/90",children:"Local fallback artifact"}),e.jsx("p",{className:"mt-1 text-body text-amber-50/90",children:"This artifact is buffered locally because OrgX registration is currently unavailable."}),w&&e.jsxs("p",{className:"mt-1.5 text-caption text-amber-100/70",children:["Upstream error: ",w]}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[k&&e.jsx("a",{href:k,target:"_blank",rel:"noopener noreferrer",className:"rounded-full border border-amber-200/25 bg-black/25 px-3 py-1 text-caption font-semibold text-amber-100 transition-colors hover:bg-black/35",children:"Open local artifact"}),n&&e.jsx("button",{type:"button",onClick:()=>void A(n,"Artifact path"),className:"rounded-full border border-amber-200/25 bg-black/20 px-3 py-1 text-caption font-semibold text-amber-100 transition-colors hover:bg-black/35",children:"Copy path"})]})]}),t.description&&e.jsx("div",{children:e.jsx("p",{className:"text-body leading-relaxed text-primary",children:t.description})}),h&&e.jsx("div",{className:"rounded-xl border border-white/[0.06] bg-white/[0.02] p-4",children:e.jsx($,{mode:"block",text:h,className:"text-body leading-relaxed text-primary"})}),!t.description&&!h&&e.jsxs("div",{className:"py-12 text-center text-muted",children:[e.jsxs("svg",{className:"mx-auto mb-3 opacity-50",width:"32",height:"32",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"}),e.jsx("path",{d:"M14 2v4a2 2 0 0 0 2 2h4"})]}),e.jsx("p",{className:"text-sm",children:"No preview available"})]}),e.jsxs("div",{className:"flex flex-wrap gap-x-6 gap-y-1.5 text-micro text-faint",children:[e.jsxs("span",{children:["Entity: ",t.entity_type,"/",t.entity_id.slice(0,8)]}),e.jsxs("span",{children:["Version: ",t.version]}),e.jsxs("span",{children:["Updated:"," ",new Date(t.updated_at).toLocaleDateString(void 0,{month:"short",day:"numeric",year:"numeric"})]})]})]})]})]})}export{J as ArtifactViewerModal};
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as a,j as e}from"./Dj2k1r16.js";import{e as l,y as p,E as h,a0 as u}from"./BV2Tf8S2.js";import{DecisionQueue as b}from"./D2G51wQm.js";import"./DMKyYAtD.js";import"./eeHXe_OQ.js";import"./cX2e-TLi.js";import"./BjK42gtU.js";import"./BV0BcV1u.js";import"./BGY6oI8h.js";import"./DAr4MfFk.js";function D({open:n,onClose:o,decisions:t,onApproveDecision:i,onRejectDecision:m,onApproveAll:d,onBulkDecisionAction:x}){const r=a.useMemo(()=>t.length>0?Math.max(0,...t.map(c=>c.waitingMinutes)):0,[t]),s=a.useMemo(()=>t.length>=20||r>=15?l.red:t.length>0?l.amber:l.textMuted,[t.length,r]);return e.jsx(p,{open:n,onClose:o,maxWidth:"max-w-3xl",children:e.jsxs("div",{className:"flex h-full w-full flex-col",children:[e.jsx("div",{className:"border-b border-subtle px-5 pt-5 pb-4",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("h3",{className:"inline-flex items-center gap-2 text-heading font-semibold text-white",children:[e.jsx(h,{type:"decision",size:14}),e.jsx("span",{className:"truncate",children:"Decisions"}),e.jsx("span",{className:"rounded-full border px-2 py-0.5 text-caption font-semibold",style:{borderColor:`${s}30`,backgroundColor:`${s}14`,color:s},children:t.length})]}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:"Bulk review and resolve pending decisions."}),t.length>0&&e.jsxs("p",{className:"mt-2 text-caption text-secondary",children:["Oldest: ",e.jsxs("span",{className:"font-semibold text-white",children:[u(r)," ago"]})]})]}),e.jsx("button",{type:"button",onClick:o,className:"rounded-md border border-strong bg-white/[0.03] px-2.5 py-1.5 text-caption text-primary transition-colors hover:bg-white/[0.08]","aria-label":"Close decisions modal",children:"Close"})]})}),e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden p-4",children:e.jsx(b,{decisions:t,onApproveDecision:i,onRejectDecision:m,onApproveAll:d,onBulkDecisionAction:x})})]})})}export{D as BulkDecisionsModal};
|
|
Binary file
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as j,j as e}from"./Dj2k1r16.js";import{D as B,F as N,N as ke,e as x,B as M,O as Ve,Q as Ge,R as Ne,v as O,j as Ie,A as Xe,C as Ke,S as Qe,M as He,m as Je}from"./D2Kqcmv9.js";import{u as Ye}from"./467jKHFJ.js";import{A as Ze,m as I}from"./eeHXe_OQ.js";import"./DMKyYAtD.js";import"./cX2e-TLi.js";import"./BjK42gtU.js";import"./BV0BcV1u.js";const De=/^[0-9a-f-]{20,}$/i,et=new Set(["running","active","queued","pending","in_progress","working","planning","handoff","review"]),tt=new Set(["agent execution failed","execution failed","run failed","failed"]);function v(i){return typeof i=="string"&&i.trim().length>0}function ce(i){return(i??"").trim().toLowerCase()}function rt(i){return(i??"").trim().replace(/\s+/g," ").toLowerCase()}function st(i){return tt.has(rt(i))}function V(i,t=3){return i.length<=t?i.join(", "):`${i.slice(0,t).join(", ")} +${i.length-t} more`}function G(i,t){const f=[],c=h=>{if(typeof h!="string")return;const w=h.trim();w&&(f.some(W=>W.toLowerCase()===w.toLowerCase())||f.push(w))};if(Array.isArray(i))for(const h of i)c(h);return c(t??null),f}function it(i){if(i.runId&&i.runId.trim().length>0)return i.runId.trim();const t=i.metadata;if(!t)return null;const f=["slice_run_id","sliceRunId","runId","run_id","correlation_id","correlationId","sessionId","session_id","agentRunId"];for(const c of f){const h=t[c];if(typeof h=="string"&&h.trim().length>0)return h.trim()}return null}function at(i){const t=ce(i.status);if(t==="blocked"||t==="failed"||t==="completed"||t==="cancelled")return t;const f=ce(i.phase);if(f==="blocked")return"blocked";if(f==="handoff")return"handoff";if(f==="completed")return"completed";if(f==="review")return"review";const c=ce(i.state);return c==="error"?"failed":c==="stopped"?"paused":c==="stale"?"queued":et.has(t)?t:i.blockers.length>0?"blocked":t||"unknown"}function nt(i,t,f){var h;const c=[((h=i.blockerDiagnostics)==null?void 0:h.reason)??null,i.blockerReason??null,...i.blockers,t==="blocked"||t==="failed"||t==="handoff"?f:null].map(w=>typeof w=="string"?w.trim():"").filter(w=>w.length>0);return c.length>0?c.find(W=>!st(W))??c[0]:t==="handoff"?"Waiting for handoff acceptance by the next agent.":t==="blocked"?"Blocked without an explicit reason from runtime.":t==="failed"?"Run failed without explicit error details.":null}function lt(i){return i==="completed"?"border-lime/25 bg-lime/[0.08] text-lime":i==="needs_attention"?"border-amber-400/30 bg-amber-400/10 text-amber-200":i==="failed"?"border-red-400/30 bg-red-500/10 text-red-200":i==="in_progress"?"border-teal-400/30 bg-teal-400/10 text-teal-200":"border-strong bg-white/[0.04] text-secondary"}const dt={hidden:{opacity:0,y:-4},visible:i=>({opacity:1,y:0,transition:{duration:.28,delay:i*.04,ease:[.16,1,.3,1]}}),exit:{opacity:0,transition:{duration:.18}}},R={hidden:{opacity:0,y:8},visible:i=>({opacity:1,y:0,transition:{duration:.22,delay:i*.04,ease:[.22,1,.36,1]}}),exit:{opacity:0,transition:{duration:.18}}};function ue(){return e.jsx("div",{className:"h-px bg-gradient-to-r from-transparent via-white/[0.06] to-transparent"})}function ot(i){return i==="in_progress"?{background:`linear-gradient(90deg, ${x.lime}, ${x.teal})`}:i==="needs_attention"?{background:`linear-gradient(90deg, ${x.red}, ${x.amber})`}:i==="completed"?{background:`linear-gradient(90deg, ${x.teal}, ${x.cyan})`}:i==="failed"?{background:`linear-gradient(90deg, ${x.red}, ${x.red}80)`}:{background:`linear-gradient(90deg, ${x.iris}, ${x.iris}80)`}}const vt=j.memo(function({session:t,activity:f,initiatives:c=[],sliceRuns:h=[],onOpenActivityItem:w,onContinueHighestPriority:W,onDispatchSession:X,onPauseSession:K,onResumeSession:Q,onCancelSession:H,onCreateCheckpoint:J,onRollbackSession:Y,onStartInitiative:ct,onStartWorkstream:ut,initialInterventionDraft:C=null,onSubmitIntervention:te,onClose:me}){var ye,ve,je;const[u,xe]=j.useState(null),[L,T]=j.useState(null),[U,he]=j.useState(!1),[re,z]=j.useState(""),{enqueue:pe,ToastRenderer:Ce}=Ye();j.useEffect(()=>{if(!t){z("");return}if(C!=null&&C.text){z(C.text);return}z("")},[C==null?void 0:C.text,t==null?void 0:t.id]);const q=j.useMemo(()=>{var l,g,y,d,m;if(!t)return new Set;const r=new Set;return(l=t.runId)!=null&&l.trim()&&r.add(t.runId.trim()),(g=t.id)!=null&&g.trim()&&r.add(t.id.trim()),(m=(d=(y=t.blockerDiagnostics)==null?void 0:y.context)==null?void 0:d.sliceRunId)!=null&&m.trim()&&r.add(t.blockerDiagnostics.context.sliceRunId.trim()),r},[t]),$=j.useMemo(()=>t?q.size===0?[]:f.filter(r=>{const l=it(r);return!!(l&&q.has(l))}).sort((r,l)=>Date.parse(l.timestamp)-Date.parse(r.timestamp)).slice(0,12):[],[f,t,q]),s=j.useMemo(()=>{var y,d;if(!t||!Array.isArray(h)||h.length===0)return null;const r=((y=t.initiativeId)==null?void 0:y.trim())??"",l=((d=t.workstreamId)==null?void 0:d.trim())??"",g=h.filter(m=>{var oe,we;const A=((oe=m.sliceRunId)==null?void 0:oe.trim())??"",E=((we=m.runId)==null?void 0:we.trim())??"";if(A&&q.has(A)||E&&q.has(E))return!0;if(!l||!G(m.workstreamIds,m.workstreamId).includes(l))return!1;if(!r)return!0;const ee=G(m.initiativeIds,m.initiativeId);return!(ee.length>0&&!ee.includes(r))});return g.length===0?null:[...g].sort((m,A)=>{const E=Date.parse(m.updatedAt??m.lastEventAt??m.startedAt??""),de=Date.parse(A.updatedAt??A.lastEventAt??A.startedAt??""),ee=Number.isFinite(E)?E:0;return(Number.isFinite(de)?de:0)-ee})[0]},[t,q,h]),se=j.useMemo(()=>{var y;if(!t)return[];const r=[],l=t.initiativeId??t.groupId;if(l){const d=c.find(m=>m.id===l);d?r.push({label:"Initiative",value:d.name}):t.groupLabel&&t.groupLabel.trim().length>0?r.push({label:"Initiative",value:t.groupLabel}):B(l)&&r.push({label:"Initiative",value:N(l)})}if(t.workstreamId){let d=null;for(const m of c){const A=(y=m.workstreams)==null?void 0:y.find(E=>E.id===t.workstreamId);if(A){d=A.name;break}}!d&&B(t.workstreamId)?d=N(t.workstreamId):!d&&!De.test(t.workstreamId)&&(d=t.workstreamId),d&&r.push({label:"Workstream",value:d})}const g=t.phase??null;if(g){const d=String(g);r.push({label:"Milestone",value:B(d)?N(d):d})}return t.title&&r.push({label:"Task",value:t.title}),r},[c,t]),S=j.useMemo(()=>{var y,d;if(!t)return null;const r=((y=$[0])==null?void 0:y.summary)??((d=$[0])==null?void 0:d.description)??null,g=t.lastEventSummary??r??null;return g&&g.trim().length>0?g.trim():null},[$,t]),Ae=j.useMemo(()=>{var r;return t?ke(t.agentName,t.title,t.lastEventSummary,S,(r=$[0])==null?void 0:r.metadata):ke()},[$,t,S]),_=async(r,l,g)=>{if(!(!g||u)){xe(r),T(null);try{await g(),T(`${l} requested.`)}catch(y){T(y instanceof Error?y.message:`${l} failed.`)}finally{xe(null)}}};if(!t)return e.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[e.jsx("div",{className:"h-[2px] flex-shrink-0",style:{background:`linear-gradient(90deg, ${x.iris}, ${x.iris}80)`}}),e.jsxs("div",{className:"flex items-center justify-between px-5 py-3",children:[e.jsx("p",{className:"section-kicker",children:"Session Detail"}),e.jsx("button",{onClick:()=>he(r=>!r),className:"text-muted transition-colors hover:text-primary","aria-label":U?"Expand session detail":"Collapse session detail",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:M("transition-transform",U?"-rotate-90":"rotate-0"),children:e.jsx("path",{d:"m6 9 6 6 6-6"})})})]}),e.jsx("div",{className:M("transition-all",U?"max-h-0 overflow-hidden":"min-h-0 flex-1"),children:e.jsxs("div",{className:"flex h-full min-h-0 flex-col items-center justify-center gap-4 px-5 py-8",children:[e.jsx("div",{className:"flex h-14 w-14 items-center justify-center rounded-2xl border border-white/[0.08] bg-white/[0.03]",children:e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"text-muted",children:[e.jsx("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2"}),e.jsx("path",{d:"M8 21h8M12 17v4"})]})}),e.jsx("p",{className:"text-body text-secondary text-center",children:"No session selected"}),e.jsx("p",{className:"text-caption text-muted text-center max-w-[240px]",children:"Select a session to inspect summary, breadcrumbs, blockers, and recent messages."}),e.jsx("button",{onClick:()=>_("continue-priority","Continue highest priority",W),disabled:!W||!!u,className:"mt-2 h-8 rounded-lg border border-lime/25 bg-lime/10 px-4 text-caption font-semibold text-lime transition-colors hover:bg-lime/20 disabled:opacity-45",children:u==="continue-priority"?"Dispatching...":"Continue highest priority"}),L&&e.jsx("p",{className:"text-caption text-secondary",children:L})]})})]});const P=t.progress===null?null:Math.round(t.progress),k=at(t),p=$[0]??null,ie=(s==null?void 0:s.blockingDecisionCount)??0,Re=Math.max(0,((s==null?void 0:s.decisionCount)??0)-ie),o=Ve({sessionStatus:t.status,sessionPhase:t.phase??null,sessionState:t.state??null,sliceStatus:(s==null?void 0:s.status)??null,activityType:(p==null?void 0:p.type)??null,activityStatus:(typeof(p==null?void 0:p.state)=="string"&&p.state.trim().length>0?p.state:null)??(typeof(p==null?void 0:p.phase)=="string"&&p.phase.trim().length>0?p.phase:null)??(s==null?void 0:s.runtimeState)??null,stopReason:t.blockerReason??((ye=t.blockerDiagnostics)==null?void 0:ye.reason)??((s==null?void 0:s.status)==="failed"?"error":null),decisionRequired:((p==null?void 0:p.decisionRequired)??!1)||ie>0,blockingDecisionCount:ie,nonBlockingDecisionCount:Re,blockerCount:t.blockers.length,blockerReason:t.blockerReason??((ve=t.blockerDiagnostics)==null?void 0:ve.reason)??null}),ae=nt(t,k,S),Te=k==="handoff"?"Handoff":k==="blocked"?"Blocker reason":k==="failed"?"Failure reason":"Status note",$e=o.status==="in_progress"&&["running","active","queued","pending","working","in_progress","planning","review"].includes(k),Se=o.status==="needs_attention"&&["paused","blocked","queued","pending"].includes(k),Be=!["completed","archived","cancelled"].includes(k),Me=!["archived","cancelled"].includes(k),Le=o.label,_e=lt(o.status),ne=["running","active","working","in_progress","planning","review"].includes(k),Ee=o.status!=="in_progress"&&!ne,We=o.tone==="critical"?x.red:o.tone==="warning"?x.amber:o.tone==="positive"?x.lime:x.teal,Ue=P!==null&&P>=100&&o.status!=="completed"?"Terminal state":"Progress",qe=o.tone==="critical"?"border-red-400/25 bg-red-500/10":o.tone==="warning"?"border-amber-400/25 bg-amber-500/10":o.tone==="positive"?"border-lime/22 bg-lime/[0.08]":"border-subtle bg-white/[0.02]",a=t.blockerDiagnostics??null,n=(a==null?void 0:a.context)??null,le=[v(a==null?void 0:a.source)?`Source: ${a.source.trim()}`:null,v(a==null?void 0:a.errorCode)?`Code: ${a.errorCode.trim()}`:null,v(a==null?void 0:a.errorCategory)?`Category: ${a.errorCategory.trim()}`:null,(a==null?void 0:a.retryable)===!0?"Retryable: yes":(a==null?void 0:a.retryable)===!1?"Retryable: no":null].filter(r=>!!r),b=[];n&&(Array.isArray(n.initiativeIds)&&n.initiativeIds.length>0?b.push({label:"Initiatives",value:V(n.initiativeIds.map(r=>B(r)?N(r):r),4)}):v(n.initiativeId)&&b.push({label:"Initiative",value:Ge("Initiative",n.initiativeId.trim())}),v(n.workstreamTitle)?b.push({label:"Workstream",value:n.workstreamTitle.trim()}):Array.isArray(n.workstreamIds)&&n.workstreamIds.length>0?b.push({label:"Workstreams",value:V(n.workstreamIds,4)}):v(n.workstreamId)&&b.push({label:"Workstream",value:n.workstreamId.trim()}),v(n.sliceRunId)&&b.push({label:"Slice run",value:N(n.sliceRunId.trim())}),v(n.parallelMode)&&b.push({label:"Mode",value:n.parallelMode.trim().toUpperCase()}),Array.isArray(n.taskIds)&&n.taskIds.length>0&&b.push({label:"Tasks",value:V(n.taskIds.map(r=>B(r)?N(r):r))}),Array.isArray(n.milestoneIds)&&n.milestoneIds.length>0&&b.push({label:"Milestones",value:V(n.milestoneIds.map(r=>B(r)?N(r):r))}),Array.isArray(n.iwmtIds)&&n.iwmtIds.length>0?b.push({label:"Scope IDs",value:V(n.iwmtIds.map(r=>B(r)?N(r):r),4)}):v(n.iwmtId)&&b.push({label:"Scope ID",value:B(n.iwmtId.trim())?N(n.iwmtId.trim()):n.iwmtId.trim()}),v(n.logPath)&&b.push({label:"Log path",value:Ne(n.logPath.trim())}),v(n.outputPath)&&b.push({label:"Output path",value:Ne(n.outputPath.trim())}));const be=(k==="blocked"||k==="failed")&&!!(a&&(v(a.reason)||le.length>0||b.length>0||Array.isArray(a.suggestedActions)&&a.suggestedActions.length>0)),Z=v(ae)?ae:null,ze=Z!==null&&!(S&&(Z===S||S.includes(Z)))&&!be,Pe=j.useCallback(()=>{!H||!t||(T("Session will be cancelled..."),pe({message:`Cancelled "${t.title}"`,onCommit:async()=>{try{await H(t),T("Session cancelled.")}catch(r){T(r instanceof Error?r.message:"Cancel failed.")}},onUndo:()=>{T(null)}}))},[H,t,pe]),Fe=[{label:"Started",value:t.startedAt?O(t.startedAt):"—"},{label:"Updated",value:t.updatedAt?O(t.updatedAt):"—"},...t.eta?[{label:"ETA",value:t.eta}]:[],...t.checkpointCount?[{label:"Checkpoints",value:String(t.checkpointCount)}]:[]],fe=s?s.status.replace(/_/g," "):null,F=G(s==null?void 0:s.initiativeIds,(s==null?void 0:s.initiativeId)??null),D=G(s==null?void 0:s.workstreamIds,(s==null?void 0:s.workstreamId)??null);G(s==null?void 0:s.iwmtIds,(s==null?void 0:s.iwmtId)??null);const Oe=F[0]?((je=c.find(r=>r.id===F[0]))==null?void 0:je.name)??F[0]:null,ge=L?L.toLowerCase().includes("fail")||L.toLowerCase().includes("error")?"error":u?"pending":"success":null;return e.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[e.jsx("div",{className:"h-[2px] flex-shrink-0",style:ot(o.status)}),e.jsxs("div",{className:"flex items-center justify-between px-5 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("p",{className:"section-kicker",children:"Session Detail"}),e.jsxs("span",{className:M("inline-flex items-center gap-1.5 rounded-full border px-2 py-[1px] text-micro font-semibold uppercase tracking-widest",_e),children:[ne&&e.jsx("span",{className:"h-1.5 w-1.5 rounded-full pulse-soft",style:{backgroundColor:Ie(k)}}),Le]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{onClick:()=>he(r=>!r),className:"text-muted transition-colors hover:text-primary","aria-label":U?"Expand session detail":"Collapse session detail",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:M("transition-transform",U?"-rotate-90":"rotate-0"),children:e.jsx("path",{d:"m6 9 6 6 6-6"})})}),me&&e.jsx("button",{type:"button",onClick:me,"aria-label":"Close session inspector",className:"inline-flex h-8 w-8 items-center justify-center rounded-full border border-strong bg-white/[0.03] text-primary transition-colors hover:bg-white/[0.08] hover:text-white",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 6L6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})})]})]}),e.jsxs("div",{className:M("transition-all flex flex-col min-h-0",U?"max-h-0 overflow-hidden":"flex-1"),children:[e.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto px-5 py-5 space-y-5",children:[e.jsx(Ze,{mode:"wait",children:e.jsxs(I.div,{variants:dt,initial:"hidden",animate:"visible",exit:"exit",custom:0,children:[e.jsxs("div",{className:"flex items-start gap-3.5",children:[e.jsx(Xe,{name:t.agentName??"OrgX",size:"md",hint:t.agentName}),e.jsxs("div",{className:"min-w-0 flex-1 pt-0.5",children:[e.jsx("h2",{className:"text-[28px] font-medium leading-tight text-white truncate",children:Ke(t.title)}),e.jsxs("p",{className:"mt-1 text-micro uppercase tracking-[0.12em] text-muted",children:[t.agentName??"OrgX"," · ",Ae.label]})]})]}),se.length>0&&e.jsx("div",{className:"mt-3 flex flex-wrap items-center gap-1.5",children:se.map((r,l)=>e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(Qe,{tone:"muted",children:r.value}),l<se.length-1&&e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:"flex-shrink-0 text-faint",children:e.jsx("path",{d:"m9 18 6-6-6-6"})})]},`${r.label}-${r.value}`))})]},t.id)}),e.jsx(ue,{}),S&&e.jsxs(I.div,{variants:R,initial:"hidden",animate:"visible",custom:1,children:[e.jsx("p",{className:"section-kicker mb-2",children:"Summary"}),e.jsx(He,{text:S,mode:"block"})]}),e.jsx(I.div,{variants:R,initial:"hidden",animate:"visible",custom:2,children:e.jsxs("div",{className:M("rounded-xl border px-4 py-3",qe),children:[e.jsx("p",{className:"section-kicker mb-1.5",children:o.label}),e.jsx("p",{className:"text-body text-secondary",children:o.sentence}),o.nextAction&&e.jsxs("p",{className:"mt-1.5 flex items-center gap-1 text-caption text-secondary",children:[e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:x.lime,strokeWidth:"2.5",className:"flex-shrink-0",children:e.jsx("path",{d:"m9 18 6-6-6-6"})}),"Next: ",o.nextAction]})]})}),ze&&e.jsx(I.div,{variants:R,initial:"hidden",animate:"visible",custom:3,children:e.jsxs("div",{className:"rounded-xl border border-subtle bg-white/[0.02] px-4 py-3",children:[e.jsx("p",{className:"section-kicker mb-1.5",children:Te}),e.jsx("p",{className:"text-body text-secondary",children:Z})]})}),be&&e.jsx(I.div,{variants:R,initial:"hidden",animate:"visible",custom:3,children:e.jsxs("div",{className:"rounded-xl border border-red-500/25 bg-red-500/10 px-4 py-3",children:[e.jsx("p",{className:"section-kicker mb-1.5 text-red-200/75",children:"Why blocked"}),e.jsx("p",{className:"text-body text-red-100/90",children:(a==null?void 0:a.reason)??ae??"Runtime marked this run as blocked without details."}),le.length>0&&e.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:le.map(r=>e.jsx("span",{className:"rounded-full border border-red-300/25 bg-red-500/10 px-2 py-0.5 text-micro text-red-100/85",children:r},r))}),b.length>0&&e.jsxs("div",{className:"mt-2 rounded-md border border-red-300/20 bg-black/15 p-2.5",children:[e.jsx("p",{className:"mb-1 text-micro uppercase tracking-[0.14em] text-red-200/65",children:"Associated context"}),e.jsx("dl",{className:"grid grid-cols-1 gap-1.5 text-caption text-red-100/85",children:b.map(r=>e.jsxs("div",{className:"grid grid-cols-[86px_1fr] gap-2",children:[e.jsx("dt",{className:"text-red-200/70",children:r.label}),e.jsx("dd",{className:"break-all text-red-50/95",children:r.value})]},r.label))})]}),Array.isArray(a==null?void 0:a.suggestedActions)&&a.suggestedActions.length>0&&e.jsxs("div",{className:"mt-2",children:[e.jsx("p",{className:"mb-1 text-micro uppercase tracking-[0.14em] text-red-200/65",children:"Suggested actions"}),e.jsx("ul",{className:"space-y-1 text-caption text-red-100/85",children:a.suggestedActions.map(r=>e.jsxs("li",{children:["• ",r]},r))})]}),v(a==null?void 0:a.eventTimestamp)&&e.jsxs("p",{className:"mt-2 text-micro text-red-200/60",children:["Last blocker event: ",new Date(a.eventTimestamp).toLocaleString()," ·"," ",O(a.eventTimestamp)]})]})}),e.jsx(ue,{}),e.jsxs(I.div,{variants:R,initial:"hidden",animate:"visible",custom:4,children:[P!==null&&e.jsxs("div",{className:"mb-3",children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between text-caption text-secondary",children:[e.jsx("span",{children:Ue}),e.jsxs("span",{className:"text-primary",children:[P,"%"]})]}),e.jsx("div",{className:"h-[3px] rounded-full bg-white/[0.08]",children:e.jsx(I.div,{className:M("h-[3px] rounded-full",ne&&"live-pulse"),style:{background:We},initial:{width:0},animate:{width:`${P}%`},transition:{duration:.5,ease:Je.easingStandard}})})]}),e.jsx("dl",{className:"grid grid-cols-2 gap-3 text-caption text-secondary",children:Fe.map(r=>e.jsxs("div",{children:[e.jsx("dt",{className:"text-muted",children:r.label}),e.jsx("dd",{className:"text-body font-semibold text-white",children:r.value})]},r.label))})]}),s&&e.jsx(I.div,{variants:R,initial:"hidden",animate:"visible",custom:5,children:e.jsxs("div",{className:"rounded-xl border border-subtle bg-white/[0.02] px-4 py-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"section-kicker",children:"Slice scope"}),fe?e.jsx("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-2 py-0.5 text-micro font-semibold uppercase tracking-[0.08em] text-secondary",children:fe}):null]}),s.statusExplainer?e.jsx("p",{className:"mt-2 text-caption text-secondary",children:s.statusExplainer}):null,e.jsxs("dl",{className:"mt-2 grid grid-cols-2 gap-2 text-caption text-secondary",children:[e.jsxs("div",{children:[e.jsx("dt",{className:"text-muted",children:"Initiative"}),e.jsx("dd",{className:"text-body font-semibold text-white",children:Oe??"—"})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-muted",children:"Workstream"}),e.jsx("dd",{className:"text-body font-semibold text-white",children:s.workstreamTitle??(D[0]?N(D[0]):"—")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-muted",children:"Run"}),e.jsx("dd",{className:"break-all text-body font-semibold text-white",children:N(s.runId??s.sliceRunId)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-muted",children:"Updated"}),e.jsx("dd",{className:"text-body font-semibold text-white",children:s.updatedAt?O(s.updatedAt):"—"})]})]}),e.jsxs("div",{className:"mt-2 flex flex-wrap gap-1.5 text-micro",children:[e.jsxs("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-2 py-0.5 text-secondary",children:["Tasks ",s.taskIds.length]}),e.jsxs("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-2 py-0.5 text-secondary",children:["Milestones ",s.milestoneIds.length]}),e.jsxs("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-2 py-0.5 text-secondary",children:["Artifacts ",s.artifactCount]}),e.jsxs("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-2 py-0.5 text-secondary",children:["Needs input ",s.blockingDecisionCount]}),F.length>1?e.jsxs("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-2 py-0.5 text-secondary",children:["+",F.length-1," initiatives"]}):null,D.length>1?e.jsxs("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-2 py-0.5 text-secondary",children:["+",D.length-1," workstreams"]}):null]}),s.taskIds.length>0?e.jsxs("p",{className:"mt-2 text-micro text-secondary",children:["Tasks: ",s.taskIds.length]}):null]})}),t.blockers.length>0&&e.jsx(I.div,{variants:R,initial:"hidden",animate:"visible",custom:6,children:e.jsxs("div",{className:"rounded-xl border border-red-500/30 bg-red-500/10 px-4 py-3",children:[e.jsx("p",{className:"section-kicker mb-2 text-red-200/70",children:"Blockers"}),e.jsx("ul",{className:"space-y-1 text-body text-red-100/90",children:t.blockers.map(r=>e.jsxs("li",{children:["• ",r]},r))})]})}),e.jsx(ue,{}),e.jsxs(I.div,{variants:R,initial:"hidden",animate:"visible",custom:7,children:[e.jsx("p",{className:"section-kicker mb-4",children:"Recent Messages"}),$.length===0&&e.jsx("p",{className:"text-body text-secondary",children:"No recent messages for this run."}),e.jsx("div",{className:"relative border-l border-white/[0.06] pl-6 ml-1 space-y-3",children:$.map((r,l)=>e.jsxs(I.div,{className:"relative group",variants:R,initial:"hidden",animate:"visible",custom:l,children:[e.jsx("div",{className:"absolute -left-[27px] top-1.5 h-2 w-2 rounded-full border border-black ring-4 ring-black",style:{backgroundColor:Ie(r.type??r.state??"unknown")}}),e.jsxs("article",{className:"rounded-lg border border-subtle bg-white/[0.02] px-3 py-2.5 transition-colors hover:bg-white/[0.04]",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsx("p",{className:"min-w-0 flex-1 text-caption text-bright",children:r.title}),w&&e.jsx("button",{type:"button",onClick:()=>w(r),className:"flex-shrink-0 rounded-full border border-strong bg-white/[0.03] px-2.5 py-0.5 text-micro font-semibold text-secondary opacity-0 transition-all group-hover:opacity-100 hover:bg-white/[0.08] hover:text-primary",children:"Open"})]}),(r.summary||r.description)&&e.jsx("p",{className:"mt-0.5 line-clamp-2 text-caption text-secondary",children:r.summary??r.description}),e.jsxs("p",{className:"mt-1 text-micro text-muted",children:[new Date(r.timestamp).toLocaleString()," · ",O(r.timestamp)]})]})]},r.id))})]})]}),e.jsxs("div",{className:"flex-shrink-0 border-t border-subtle px-5 py-3 space-y-3",children:[L&&e.jsx("p",{className:M("rounded-md border px-2.5 py-1.5 text-caption",ge==="error"?"border-red-400/30 bg-red-500/10 text-red-200":ge==="pending"?"border-white/[0.08] bg-white/[0.02] text-secondary pulse-soft":"border-lime/25 bg-lime/[0.08] text-lime"),children:L}),te&&e.jsx("div",{children:e.jsx("textarea",{value:re,onChange:r=>z(r.target.value),placeholder:"Share guidance for this run...",rows:2,className:"w-full resize-none rounded-lg border border-white/[0.10] bg-white/[0.03] px-3 py-2 text-body text-bright outline-none placeholder:text-faint focus:border-white/20"})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[$e&&e.jsx("button",{onClick:()=>_("pause-session","Session paused",()=>K==null?void 0:K(t)),disabled:!K||!!u,className:"rounded-md px-2.5 py-1.5 text-caption font-medium text-secondary hover:bg-white/[0.04] hover:text-white disabled:opacity-45 transition-colors",children:u==="pause-session"?"Pausing...":"Pause"}),Se&&e.jsx("button",{onClick:()=>_("resume-session","Session resumed",()=>Q==null?void 0:Q(t)),disabled:!Q||!!u,className:"rounded-md px-2.5 py-1.5 text-caption font-medium text-secondary hover:bg-white/[0.04] hover:text-white disabled:opacity-45 transition-colors",children:u==="resume-session"?"Resuming...":"Resume"}),e.jsx("button",{onClick:()=>_("checkpoint-session","Progress saved",()=>J==null?void 0:J(t)),disabled:!J||!!u,className:"rounded-md px-2.5 py-1.5 text-caption font-medium text-secondary hover:bg-white/[0.04] hover:text-white disabled:opacity-45 transition-colors",children:u==="checkpoint-session"?"Saving...":"Save"}),Me&&e.jsx("button",{onClick:()=>_("rollback-session","Undo requested",()=>Y==null?void 0:Y(t)),disabled:!Y||!!u,className:"rounded-md px-2.5 py-1.5 text-caption font-medium text-secondary hover:bg-white/[0.04] hover:text-white disabled:opacity-45 transition-colors",children:u==="rollback-session"?"Undoing...":"Undo"}),Be&&H&&e.jsx("button",{onClick:Pe,disabled:!!u,className:"rounded-md px-2.5 py-1.5 text-caption font-medium text-red-400/70 hover:bg-red-500/[0.08] hover:text-red-300 disabled:opacity-45 transition-colors",children:"Cancel"})]}),e.jsx("div",{className:"flex-1"}),te&&e.jsx("button",{type:"button",onClick:()=>{const r=re.trim();if(!r){T("Intervention note cannot be empty.");return}_("intervene-note","Intervention sent",async()=>{await te({session:t,workstreamId:(C==null?void 0:C.workstreamId)??t.workstreamId??null,text:r}),z("")})},disabled:!!u||re.trim().length===0,className:"rounded-md border border-strong bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:u==="intervene-note"?"Sending...":"Intervene"}),e.jsxs("button",{onClick:()=>_("dispatch-session","Session started",()=>X==null?void 0:X(t)),disabled:!X||!!u||!Ee,className:"inline-flex h-8 items-center gap-1.5 rounded-lg border border-lime/25 bg-lime/10 px-4 text-caption font-semibold text-lime transition-colors hover:bg-lime/20 disabled:opacity-45",children:[e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",className:"flex-shrink-0",children:e.jsx("path",{d:"M8 5v14l11-7z"})}),u==="dispatch-session"?"Starting...":o.status==="completed"?"Restart":"Start"]})]})]})]}),e.jsx(Ce,{})]})});export{vt as SessionInspector};
|
|
1
|
+
import{r as j,j as e}from"./Dj2k1r16.js";import{D as B,F as N,N as ke,e as x,B as M,O as Ve,Q as Ge,R as Ne,v as O,j as Ie,A as Xe,C as Ke,S as Qe,M as He,m as Je}from"./BV2Tf8S2.js";import{u as Ye}from"./DAr4MfFk.js";import{A as Ze,m as I}from"./eeHXe_OQ.js";import"./DMKyYAtD.js";import"./cX2e-TLi.js";import"./BjK42gtU.js";import"./BV0BcV1u.js";const De=/^[0-9a-f-]{20,}$/i,et=new Set(["running","active","queued","pending","in_progress","working","planning","handoff","review"]),tt=new Set(["agent execution failed","execution failed","run failed","failed"]);function v(i){return typeof i=="string"&&i.trim().length>0}function ce(i){return(i??"").trim().toLowerCase()}function rt(i){return(i??"").trim().replace(/\s+/g," ").toLowerCase()}function st(i){return tt.has(rt(i))}function V(i,t=3){return i.length<=t?i.join(", "):`${i.slice(0,t).join(", ")} +${i.length-t} more`}function G(i,t){const f=[],c=h=>{if(typeof h!="string")return;const w=h.trim();w&&(f.some(W=>W.toLowerCase()===w.toLowerCase())||f.push(w))};if(Array.isArray(i))for(const h of i)c(h);return c(t??null),f}function it(i){if(i.runId&&i.runId.trim().length>0)return i.runId.trim();const t=i.metadata;if(!t)return null;const f=["slice_run_id","sliceRunId","runId","run_id","correlation_id","correlationId","sessionId","session_id","agentRunId"];for(const c of f){const h=t[c];if(typeof h=="string"&&h.trim().length>0)return h.trim()}return null}function at(i){const t=ce(i.status);if(t==="blocked"||t==="failed"||t==="completed"||t==="cancelled")return t;const f=ce(i.phase);if(f==="blocked")return"blocked";if(f==="handoff")return"handoff";if(f==="completed")return"completed";if(f==="review")return"review";const c=ce(i.state);return c==="error"?"failed":c==="stopped"?"paused":c==="stale"?"queued":et.has(t)?t:i.blockers.length>0?"blocked":t||"unknown"}function nt(i,t,f){var h;const c=[((h=i.blockerDiagnostics)==null?void 0:h.reason)??null,i.blockerReason??null,...i.blockers,t==="blocked"||t==="failed"||t==="handoff"?f:null].map(w=>typeof w=="string"?w.trim():"").filter(w=>w.length>0);return c.length>0?c.find(W=>!st(W))??c[0]:t==="handoff"?"Waiting for handoff acceptance by the next agent.":t==="blocked"?"Blocked without an explicit reason from runtime.":t==="failed"?"Run failed without explicit error details.":null}function lt(i){return i==="completed"?"border-lime/25 bg-lime/[0.08] text-lime":i==="needs_attention"?"border-amber-400/30 bg-amber-400/10 text-amber-200":i==="failed"?"border-red-400/30 bg-red-500/10 text-red-200":i==="in_progress"?"border-teal-400/30 bg-teal-400/10 text-teal-200":"border-strong bg-white/[0.04] text-secondary"}const dt={hidden:{opacity:0,y:-4},visible:i=>({opacity:1,y:0,transition:{duration:.28,delay:i*.04,ease:[.16,1,.3,1]}}),exit:{opacity:0,transition:{duration:.18}}},R={hidden:{opacity:0,y:8},visible:i=>({opacity:1,y:0,transition:{duration:.22,delay:i*.04,ease:[.22,1,.36,1]}}),exit:{opacity:0,transition:{duration:.18}}};function ue(){return e.jsx("div",{className:"h-px bg-gradient-to-r from-transparent via-white/[0.06] to-transparent"})}function ot(i){return i==="in_progress"?{background:`linear-gradient(90deg, ${x.lime}, ${x.teal})`}:i==="needs_attention"?{background:`linear-gradient(90deg, ${x.red}, ${x.amber})`}:i==="completed"?{background:`linear-gradient(90deg, ${x.teal}, ${x.cyan})`}:i==="failed"?{background:`linear-gradient(90deg, ${x.red}, ${x.red}80)`}:{background:`linear-gradient(90deg, ${x.iris}, ${x.iris}80)`}}const vt=j.memo(function({session:t,activity:f,initiatives:c=[],sliceRuns:h=[],onOpenActivityItem:w,onContinueHighestPriority:W,onDispatchSession:X,onPauseSession:K,onResumeSession:Q,onCancelSession:H,onCreateCheckpoint:J,onRollbackSession:Y,onStartInitiative:ct,onStartWorkstream:ut,initialInterventionDraft:C=null,onSubmitIntervention:te,onClose:me}){var ye,ve,je;const[u,xe]=j.useState(null),[L,T]=j.useState(null),[U,he]=j.useState(!1),[re,z]=j.useState(""),{enqueue:pe,ToastRenderer:Ce}=Ye();j.useEffect(()=>{if(!t){z("");return}if(C!=null&&C.text){z(C.text);return}z("")},[C==null?void 0:C.text,t==null?void 0:t.id]);const q=j.useMemo(()=>{var l,g,y,d,m;if(!t)return new Set;const r=new Set;return(l=t.runId)!=null&&l.trim()&&r.add(t.runId.trim()),(g=t.id)!=null&&g.trim()&&r.add(t.id.trim()),(m=(d=(y=t.blockerDiagnostics)==null?void 0:y.context)==null?void 0:d.sliceRunId)!=null&&m.trim()&&r.add(t.blockerDiagnostics.context.sliceRunId.trim()),r},[t]),$=j.useMemo(()=>t?q.size===0?[]:f.filter(r=>{const l=it(r);return!!(l&&q.has(l))}).sort((r,l)=>Date.parse(l.timestamp)-Date.parse(r.timestamp)).slice(0,12):[],[f,t,q]),s=j.useMemo(()=>{var y,d;if(!t||!Array.isArray(h)||h.length===0)return null;const r=((y=t.initiativeId)==null?void 0:y.trim())??"",l=((d=t.workstreamId)==null?void 0:d.trim())??"",g=h.filter(m=>{var oe,we;const A=((oe=m.sliceRunId)==null?void 0:oe.trim())??"",E=((we=m.runId)==null?void 0:we.trim())??"";if(A&&q.has(A)||E&&q.has(E))return!0;if(!l||!G(m.workstreamIds,m.workstreamId).includes(l))return!1;if(!r)return!0;const ee=G(m.initiativeIds,m.initiativeId);return!(ee.length>0&&!ee.includes(r))});return g.length===0?null:[...g].sort((m,A)=>{const E=Date.parse(m.updatedAt??m.lastEventAt??m.startedAt??""),de=Date.parse(A.updatedAt??A.lastEventAt??A.startedAt??""),ee=Number.isFinite(E)?E:0;return(Number.isFinite(de)?de:0)-ee})[0]},[t,q,h]),se=j.useMemo(()=>{var y;if(!t)return[];const r=[],l=t.initiativeId??t.groupId;if(l){const d=c.find(m=>m.id===l);d?r.push({label:"Initiative",value:d.name}):t.groupLabel&&t.groupLabel.trim().length>0?r.push({label:"Initiative",value:t.groupLabel}):B(l)&&r.push({label:"Initiative",value:N(l)})}if(t.workstreamId){let d=null;for(const m of c){const A=(y=m.workstreams)==null?void 0:y.find(E=>E.id===t.workstreamId);if(A){d=A.name;break}}!d&&B(t.workstreamId)?d=N(t.workstreamId):!d&&!De.test(t.workstreamId)&&(d=t.workstreamId),d&&r.push({label:"Workstream",value:d})}const g=t.phase??null;if(g){const d=String(g);r.push({label:"Milestone",value:B(d)?N(d):d})}return t.title&&r.push({label:"Task",value:t.title}),r},[c,t]),S=j.useMemo(()=>{var y,d;if(!t)return null;const r=((y=$[0])==null?void 0:y.summary)??((d=$[0])==null?void 0:d.description)??null,g=t.lastEventSummary??r??null;return g&&g.trim().length>0?g.trim():null},[$,t]),Ae=j.useMemo(()=>{var r;return t?ke(t.agentName,t.title,t.lastEventSummary,S,(r=$[0])==null?void 0:r.metadata):ke()},[$,t,S]),_=async(r,l,g)=>{if(!(!g||u)){xe(r),T(null);try{await g(),T(`${l} requested.`)}catch(y){T(y instanceof Error?y.message:`${l} failed.`)}finally{xe(null)}}};if(!t)return e.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[e.jsx("div",{className:"h-[2px] flex-shrink-0",style:{background:`linear-gradient(90deg, ${x.iris}, ${x.iris}80)`}}),e.jsxs("div",{className:"flex items-center justify-between px-5 py-3",children:[e.jsx("p",{className:"section-kicker",children:"Session Detail"}),e.jsx("button",{onClick:()=>he(r=>!r),className:"text-muted transition-colors hover:text-primary","aria-label":U?"Expand session detail":"Collapse session detail",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:M("transition-transform",U?"-rotate-90":"rotate-0"),children:e.jsx("path",{d:"m6 9 6 6 6-6"})})})]}),e.jsx("div",{className:M("transition-all",U?"max-h-0 overflow-hidden":"min-h-0 flex-1"),children:e.jsxs("div",{className:"flex h-full min-h-0 flex-col items-center justify-center gap-4 px-5 py-8",children:[e.jsx("div",{className:"flex h-14 w-14 items-center justify-center rounded-2xl border border-white/[0.08] bg-white/[0.03]",children:e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"text-muted",children:[e.jsx("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2"}),e.jsx("path",{d:"M8 21h8M12 17v4"})]})}),e.jsx("p",{className:"text-body text-secondary text-center",children:"No session selected"}),e.jsx("p",{className:"text-caption text-muted text-center max-w-[240px]",children:"Select a session to inspect summary, breadcrumbs, blockers, and recent messages."}),e.jsx("button",{onClick:()=>_("continue-priority","Continue highest priority",W),disabled:!W||!!u,className:"mt-2 h-8 rounded-lg border border-lime/25 bg-lime/10 px-4 text-caption font-semibold text-lime transition-colors hover:bg-lime/20 disabled:opacity-45",children:u==="continue-priority"?"Dispatching...":"Continue highest priority"}),L&&e.jsx("p",{className:"text-caption text-secondary",children:L})]})})]});const P=t.progress===null?null:Math.round(t.progress),k=at(t),p=$[0]??null,ie=(s==null?void 0:s.blockingDecisionCount)??0,Re=Math.max(0,((s==null?void 0:s.decisionCount)??0)-ie),o=Ve({sessionStatus:t.status,sessionPhase:t.phase??null,sessionState:t.state??null,sliceStatus:(s==null?void 0:s.status)??null,activityType:(p==null?void 0:p.type)??null,activityStatus:(typeof(p==null?void 0:p.state)=="string"&&p.state.trim().length>0?p.state:null)??(typeof(p==null?void 0:p.phase)=="string"&&p.phase.trim().length>0?p.phase:null)??(s==null?void 0:s.runtimeState)??null,stopReason:t.blockerReason??((ye=t.blockerDiagnostics)==null?void 0:ye.reason)??((s==null?void 0:s.status)==="failed"?"error":null),decisionRequired:((p==null?void 0:p.decisionRequired)??!1)||ie>0,blockingDecisionCount:ie,nonBlockingDecisionCount:Re,blockerCount:t.blockers.length,blockerReason:t.blockerReason??((ve=t.blockerDiagnostics)==null?void 0:ve.reason)??null}),ae=nt(t,k,S),Te=k==="handoff"?"Handoff":k==="blocked"?"Blocker reason":k==="failed"?"Failure reason":"Status note",$e=o.status==="in_progress"&&["running","active","queued","pending","working","in_progress","planning","review"].includes(k),Se=o.status==="needs_attention"&&["paused","blocked","queued","pending"].includes(k),Be=!["completed","archived","cancelled"].includes(k),Me=!["archived","cancelled"].includes(k),Le=o.label,_e=lt(o.status),ne=["running","active","working","in_progress","planning","review"].includes(k),Ee=o.status!=="in_progress"&&!ne,We=o.tone==="critical"?x.red:o.tone==="warning"?x.amber:o.tone==="positive"?x.lime:x.teal,Ue=P!==null&&P>=100&&o.status!=="completed"?"Terminal state":"Progress",qe=o.tone==="critical"?"border-red-400/25 bg-red-500/10":o.tone==="warning"?"border-amber-400/25 bg-amber-500/10":o.tone==="positive"?"border-lime/22 bg-lime/[0.08]":"border-subtle bg-white/[0.02]",a=t.blockerDiagnostics??null,n=(a==null?void 0:a.context)??null,le=[v(a==null?void 0:a.source)?`Source: ${a.source.trim()}`:null,v(a==null?void 0:a.errorCode)?`Code: ${a.errorCode.trim()}`:null,v(a==null?void 0:a.errorCategory)?`Category: ${a.errorCategory.trim()}`:null,(a==null?void 0:a.retryable)===!0?"Retryable: yes":(a==null?void 0:a.retryable)===!1?"Retryable: no":null].filter(r=>!!r),b=[];n&&(Array.isArray(n.initiativeIds)&&n.initiativeIds.length>0?b.push({label:"Initiatives",value:V(n.initiativeIds.map(r=>B(r)?N(r):r),4)}):v(n.initiativeId)&&b.push({label:"Initiative",value:Ge("Initiative",n.initiativeId.trim())}),v(n.workstreamTitle)?b.push({label:"Workstream",value:n.workstreamTitle.trim()}):Array.isArray(n.workstreamIds)&&n.workstreamIds.length>0?b.push({label:"Workstreams",value:V(n.workstreamIds,4)}):v(n.workstreamId)&&b.push({label:"Workstream",value:n.workstreamId.trim()}),v(n.sliceRunId)&&b.push({label:"Slice run",value:N(n.sliceRunId.trim())}),v(n.parallelMode)&&b.push({label:"Mode",value:n.parallelMode.trim().toUpperCase()}),Array.isArray(n.taskIds)&&n.taskIds.length>0&&b.push({label:"Tasks",value:V(n.taskIds.map(r=>B(r)?N(r):r))}),Array.isArray(n.milestoneIds)&&n.milestoneIds.length>0&&b.push({label:"Milestones",value:V(n.milestoneIds.map(r=>B(r)?N(r):r))}),Array.isArray(n.iwmtIds)&&n.iwmtIds.length>0?b.push({label:"Scope IDs",value:V(n.iwmtIds.map(r=>B(r)?N(r):r),4)}):v(n.iwmtId)&&b.push({label:"Scope ID",value:B(n.iwmtId.trim())?N(n.iwmtId.trim()):n.iwmtId.trim()}),v(n.logPath)&&b.push({label:"Log path",value:Ne(n.logPath.trim())}),v(n.outputPath)&&b.push({label:"Output path",value:Ne(n.outputPath.trim())}));const be=(k==="blocked"||k==="failed")&&!!(a&&(v(a.reason)||le.length>0||b.length>0||Array.isArray(a.suggestedActions)&&a.suggestedActions.length>0)),Z=v(ae)?ae:null,ze=Z!==null&&!(S&&(Z===S||S.includes(Z)))&&!be,Pe=j.useCallback(()=>{!H||!t||(T("Session will be cancelled..."),pe({message:`Cancelled "${t.title}"`,onCommit:async()=>{try{await H(t),T("Session cancelled.")}catch(r){T(r instanceof Error?r.message:"Cancel failed.")}},onUndo:()=>{T(null)}}))},[H,t,pe]),Fe=[{label:"Started",value:t.startedAt?O(t.startedAt):"—"},{label:"Updated",value:t.updatedAt?O(t.updatedAt):"—"},...t.eta?[{label:"ETA",value:t.eta}]:[],...t.checkpointCount?[{label:"Checkpoints",value:String(t.checkpointCount)}]:[]],fe=s?s.status.replace(/_/g," "):null,F=G(s==null?void 0:s.initiativeIds,(s==null?void 0:s.initiativeId)??null),D=G(s==null?void 0:s.workstreamIds,(s==null?void 0:s.workstreamId)??null);G(s==null?void 0:s.iwmtIds,(s==null?void 0:s.iwmtId)??null);const Oe=F[0]?((je=c.find(r=>r.id===F[0]))==null?void 0:je.name)??F[0]:null,ge=L?L.toLowerCase().includes("fail")||L.toLowerCase().includes("error")?"error":u?"pending":"success":null;return e.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[e.jsx("div",{className:"h-[2px] flex-shrink-0",style:ot(o.status)}),e.jsxs("div",{className:"flex items-center justify-between px-5 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("p",{className:"section-kicker",children:"Session Detail"}),e.jsxs("span",{className:M("inline-flex items-center gap-1.5 rounded-full border px-2 py-[1px] text-micro font-semibold uppercase tracking-widest",_e),children:[ne&&e.jsx("span",{className:"h-1.5 w-1.5 rounded-full pulse-soft",style:{backgroundColor:Ie(k)}}),Le]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{onClick:()=>he(r=>!r),className:"text-muted transition-colors hover:text-primary","aria-label":U?"Expand session detail":"Collapse session detail",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:M("transition-transform",U?"-rotate-90":"rotate-0"),children:e.jsx("path",{d:"m6 9 6 6 6-6"})})}),me&&e.jsx("button",{type:"button",onClick:me,"aria-label":"Close session inspector",className:"inline-flex h-8 w-8 items-center justify-center rounded-full border border-strong bg-white/[0.03] text-primary transition-colors hover:bg-white/[0.08] hover:text-white",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 6L6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})})]})]}),e.jsxs("div",{className:M("transition-all flex flex-col min-h-0",U?"max-h-0 overflow-hidden":"flex-1"),children:[e.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto px-5 py-5 space-y-5",children:[e.jsx(Ze,{mode:"wait",children:e.jsxs(I.div,{variants:dt,initial:"hidden",animate:"visible",exit:"exit",custom:0,children:[e.jsxs("div",{className:"flex items-start gap-3.5",children:[e.jsx(Xe,{name:t.agentName??"OrgX",size:"md",hint:t.agentName}),e.jsxs("div",{className:"min-w-0 flex-1 pt-0.5",children:[e.jsx("h2",{className:"text-[28px] font-medium leading-tight text-white truncate",children:Ke(t.title)}),e.jsxs("p",{className:"mt-1 text-micro uppercase tracking-[0.12em] text-muted",children:[t.agentName??"OrgX"," · ",Ae.label]})]})]}),se.length>0&&e.jsx("div",{className:"mt-3 flex flex-wrap items-center gap-1.5",children:se.map((r,l)=>e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(Qe,{tone:"muted",children:r.value}),l<se.length-1&&e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:"flex-shrink-0 text-faint",children:e.jsx("path",{d:"m9 18 6-6-6-6"})})]},`${r.label}-${r.value}`))})]},t.id)}),e.jsx(ue,{}),S&&e.jsxs(I.div,{variants:R,initial:"hidden",animate:"visible",custom:1,children:[e.jsx("p",{className:"section-kicker mb-2",children:"Summary"}),e.jsx(He,{text:S,mode:"block"})]}),e.jsx(I.div,{variants:R,initial:"hidden",animate:"visible",custom:2,children:e.jsxs("div",{className:M("rounded-xl border px-4 py-3",qe),children:[e.jsx("p",{className:"section-kicker mb-1.5",children:o.label}),e.jsx("p",{className:"text-body text-secondary",children:o.sentence}),o.nextAction&&e.jsxs("p",{className:"mt-1.5 flex items-center gap-1 text-caption text-secondary",children:[e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:x.lime,strokeWidth:"2.5",className:"flex-shrink-0",children:e.jsx("path",{d:"m9 18 6-6-6-6"})}),"Next: ",o.nextAction]})]})}),ze&&e.jsx(I.div,{variants:R,initial:"hidden",animate:"visible",custom:3,children:e.jsxs("div",{className:"rounded-xl border border-subtle bg-white/[0.02] px-4 py-3",children:[e.jsx("p",{className:"section-kicker mb-1.5",children:Te}),e.jsx("p",{className:"text-body text-secondary",children:Z})]})}),be&&e.jsx(I.div,{variants:R,initial:"hidden",animate:"visible",custom:3,children:e.jsxs("div",{className:"rounded-xl border border-red-500/25 bg-red-500/10 px-4 py-3",children:[e.jsx("p",{className:"section-kicker mb-1.5 text-red-200/75",children:"Why blocked"}),e.jsx("p",{className:"text-body text-red-100/90",children:(a==null?void 0:a.reason)??ae??"Runtime marked this run as blocked without details."}),le.length>0&&e.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:le.map(r=>e.jsx("span",{className:"rounded-full border border-red-300/25 bg-red-500/10 px-2 py-0.5 text-micro text-red-100/85",children:r},r))}),b.length>0&&e.jsxs("div",{className:"mt-2 rounded-md border border-red-300/20 bg-black/15 p-2.5",children:[e.jsx("p",{className:"mb-1 text-micro uppercase tracking-[0.14em] text-red-200/65",children:"Associated context"}),e.jsx("dl",{className:"grid grid-cols-1 gap-1.5 text-caption text-red-100/85",children:b.map(r=>e.jsxs("div",{className:"grid grid-cols-[86px_1fr] gap-2",children:[e.jsx("dt",{className:"text-red-200/70",children:r.label}),e.jsx("dd",{className:"break-all text-red-50/95",children:r.value})]},r.label))})]}),Array.isArray(a==null?void 0:a.suggestedActions)&&a.suggestedActions.length>0&&e.jsxs("div",{className:"mt-2",children:[e.jsx("p",{className:"mb-1 text-micro uppercase tracking-[0.14em] text-red-200/65",children:"Suggested actions"}),e.jsx("ul",{className:"space-y-1 text-caption text-red-100/85",children:a.suggestedActions.map(r=>e.jsxs("li",{children:["• ",r]},r))})]}),v(a==null?void 0:a.eventTimestamp)&&e.jsxs("p",{className:"mt-2 text-micro text-red-200/60",children:["Last blocker event: ",new Date(a.eventTimestamp).toLocaleString()," ·"," ",O(a.eventTimestamp)]})]})}),e.jsx(ue,{}),e.jsxs(I.div,{variants:R,initial:"hidden",animate:"visible",custom:4,children:[P!==null&&e.jsxs("div",{className:"mb-3",children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between text-caption text-secondary",children:[e.jsx("span",{children:Ue}),e.jsxs("span",{className:"text-primary",children:[P,"%"]})]}),e.jsx("div",{className:"h-[3px] rounded-full bg-white/[0.08]",children:e.jsx(I.div,{className:M("h-[3px] rounded-full",ne&&"live-pulse"),style:{background:We},initial:{width:0},animate:{width:`${P}%`},transition:{duration:.5,ease:Je.easingStandard}})})]}),e.jsx("dl",{className:"grid grid-cols-2 gap-3 text-caption text-secondary",children:Fe.map(r=>e.jsxs("div",{children:[e.jsx("dt",{className:"text-muted",children:r.label}),e.jsx("dd",{className:"text-body font-semibold text-white",children:r.value})]},r.label))})]}),s&&e.jsx(I.div,{variants:R,initial:"hidden",animate:"visible",custom:5,children:e.jsxs("div",{className:"rounded-xl border border-subtle bg-white/[0.02] px-4 py-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"section-kicker",children:"Slice scope"}),fe?e.jsx("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-2 py-0.5 text-micro font-semibold uppercase tracking-[0.08em] text-secondary",children:fe}):null]}),s.statusExplainer?e.jsx("p",{className:"mt-2 text-caption text-secondary",children:s.statusExplainer}):null,e.jsxs("dl",{className:"mt-2 grid grid-cols-2 gap-2 text-caption text-secondary",children:[e.jsxs("div",{children:[e.jsx("dt",{className:"text-muted",children:"Initiative"}),e.jsx("dd",{className:"text-body font-semibold text-white",children:Oe??"—"})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-muted",children:"Workstream"}),e.jsx("dd",{className:"text-body font-semibold text-white",children:s.workstreamTitle??(D[0]?N(D[0]):"—")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-muted",children:"Run"}),e.jsx("dd",{className:"break-all text-body font-semibold text-white",children:N(s.runId??s.sliceRunId)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-muted",children:"Updated"}),e.jsx("dd",{className:"text-body font-semibold text-white",children:s.updatedAt?O(s.updatedAt):"—"})]})]}),e.jsxs("div",{className:"mt-2 flex flex-wrap gap-1.5 text-micro",children:[e.jsxs("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-2 py-0.5 text-secondary",children:["Tasks ",s.taskIds.length]}),e.jsxs("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-2 py-0.5 text-secondary",children:["Milestones ",s.milestoneIds.length]}),e.jsxs("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-2 py-0.5 text-secondary",children:["Artifacts ",s.artifactCount]}),e.jsxs("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-2 py-0.5 text-secondary",children:["Needs input ",s.blockingDecisionCount]}),F.length>1?e.jsxs("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-2 py-0.5 text-secondary",children:["+",F.length-1," initiatives"]}):null,D.length>1?e.jsxs("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-2 py-0.5 text-secondary",children:["+",D.length-1," workstreams"]}):null]}),s.taskIds.length>0?e.jsxs("p",{className:"mt-2 text-micro text-secondary",children:["Tasks: ",s.taskIds.length]}):null]})}),t.blockers.length>0&&e.jsx(I.div,{variants:R,initial:"hidden",animate:"visible",custom:6,children:e.jsxs("div",{className:"rounded-xl border border-red-500/30 bg-red-500/10 px-4 py-3",children:[e.jsx("p",{className:"section-kicker mb-2 text-red-200/70",children:"Blockers"}),e.jsx("ul",{className:"space-y-1 text-body text-red-100/90",children:t.blockers.map(r=>e.jsxs("li",{children:["• ",r]},r))})]})}),e.jsx(ue,{}),e.jsxs(I.div,{variants:R,initial:"hidden",animate:"visible",custom:7,children:[e.jsx("p",{className:"section-kicker mb-4",children:"Recent Messages"}),$.length===0&&e.jsx("p",{className:"text-body text-secondary",children:"No recent messages for this run."}),e.jsx("div",{className:"relative border-l border-white/[0.06] pl-6 ml-1 space-y-3",children:$.map((r,l)=>e.jsxs(I.div,{className:"relative group",variants:R,initial:"hidden",animate:"visible",custom:l,children:[e.jsx("div",{className:"absolute -left-[27px] top-1.5 h-2 w-2 rounded-full border border-black ring-4 ring-black",style:{backgroundColor:Ie(r.type??r.state??"unknown")}}),e.jsxs("article",{className:"rounded-lg border border-subtle bg-white/[0.02] px-3 py-2.5 transition-colors hover:bg-white/[0.04]",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsx("p",{className:"min-w-0 flex-1 text-caption text-bright",children:r.title}),w&&e.jsx("button",{type:"button",onClick:()=>w(r),className:"flex-shrink-0 rounded-full border border-strong bg-white/[0.03] px-2.5 py-0.5 text-micro font-semibold text-secondary opacity-0 transition-all group-hover:opacity-100 hover:bg-white/[0.08] hover:text-primary",children:"Open"})]}),(r.summary||r.description)&&e.jsx("p",{className:"mt-0.5 line-clamp-2 text-caption text-secondary",children:r.summary??r.description}),e.jsxs("p",{className:"mt-1 text-micro text-muted",children:[new Date(r.timestamp).toLocaleString()," · ",O(r.timestamp)]})]})]},r.id))})]})]}),e.jsxs("div",{className:"flex-shrink-0 border-t border-subtle px-5 py-3 space-y-3",children:[L&&e.jsx("p",{className:M("rounded-md border px-2.5 py-1.5 text-caption",ge==="error"?"border-red-400/30 bg-red-500/10 text-red-200":ge==="pending"?"border-white/[0.08] bg-white/[0.02] text-secondary pulse-soft":"border-lime/25 bg-lime/[0.08] text-lime"),children:L}),te&&e.jsx("div",{children:e.jsx("textarea",{value:re,onChange:r=>z(r.target.value),placeholder:"Share guidance for this run...",rows:2,className:"w-full resize-none rounded-lg border border-white/[0.10] bg-white/[0.03] px-3 py-2 text-body text-bright outline-none placeholder:text-faint focus:border-white/20"})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[$e&&e.jsx("button",{onClick:()=>_("pause-session","Session paused",()=>K==null?void 0:K(t)),disabled:!K||!!u,className:"rounded-md px-2.5 py-1.5 text-caption font-medium text-secondary hover:bg-white/[0.04] hover:text-white disabled:opacity-45 transition-colors",children:u==="pause-session"?"Pausing...":"Pause"}),Se&&e.jsx("button",{onClick:()=>_("resume-session","Session resumed",()=>Q==null?void 0:Q(t)),disabled:!Q||!!u,className:"rounded-md px-2.5 py-1.5 text-caption font-medium text-secondary hover:bg-white/[0.04] hover:text-white disabled:opacity-45 transition-colors",children:u==="resume-session"?"Resuming...":"Resume"}),e.jsx("button",{onClick:()=>_("checkpoint-session","Progress saved",()=>J==null?void 0:J(t)),disabled:!J||!!u,className:"rounded-md px-2.5 py-1.5 text-caption font-medium text-secondary hover:bg-white/[0.04] hover:text-white disabled:opacity-45 transition-colors",children:u==="checkpoint-session"?"Saving...":"Save"}),Me&&e.jsx("button",{onClick:()=>_("rollback-session","Undo requested",()=>Y==null?void 0:Y(t)),disabled:!Y||!!u,className:"rounded-md px-2.5 py-1.5 text-caption font-medium text-secondary hover:bg-white/[0.04] hover:text-white disabled:opacity-45 transition-colors",children:u==="rollback-session"?"Undoing...":"Undo"}),Be&&H&&e.jsx("button",{onClick:Pe,disabled:!!u,className:"rounded-md px-2.5 py-1.5 text-caption font-medium text-red-400/70 hover:bg-red-500/[0.08] hover:text-red-300 disabled:opacity-45 transition-colors",children:"Cancel"})]}),e.jsx("div",{className:"flex-1"}),te&&e.jsx("button",{type:"button",onClick:()=>{const r=re.trim();if(!r){T("Intervention note cannot be empty.");return}_("intervene-note","Intervention sent",async()=>{await te({session:t,workstreamId:(C==null?void 0:C.workstreamId)??t.workstreamId??null,text:r}),z("")})},disabled:!!u||re.trim().length===0,className:"rounded-md border border-strong bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:u==="intervene-note"?"Sending...":"Intervene"}),e.jsxs("button",{onClick:()=>_("dispatch-session","Session started",()=>X==null?void 0:X(t)),disabled:!X||!!u||!Ee,className:"inline-flex h-8 items-center gap-1.5 rounded-lg border border-lime/25 bg-lime/10 px-4 text-caption font-semibold text-lime transition-colors hover:bg-lime/20 disabled:opacity-45",children:[e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",className:"flex-shrink-0",children:e.jsx("path",{d:"M8 5v14l11-7z"})}),u==="dispatch-session"?"Starting...":o.status==="completed"?"Restart":"Start"]})]})]})]}),e.jsx(Ce,{})]})});export{vt as SessionInspector};
|
|
Binary file
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{e as t}from"./
|
|
1
|
+
import{e as t}from"./BV2Tf8S2.js";const e={QUEUED:"queued",RUNNING:"running",BLOCKED:"blocked",IDLE:"idle",COMPLETED:"completed"};function n(r){switch(r){case e.RUNNING:return"border-teal-300/35 bg-teal-400/[0.12] text-teal-100";case e.BLOCKED:return"border-amber-300/35 bg-amber-400/[0.12] text-amber-100";case e.IDLE:return"border-strong bg-white/[0.05] text-secondary";default:return"border-[#BFFF00]/30 bg-[#BFFF00]/12 text-[#E1FFB2]"}}function c(r){switch(r){case e.RUNNING:return"Running";case e.BLOCKED:return"Needs input";case e.IDLE:return"Idle";case e.COMPLETED:return"Completed";case e.QUEUED:return"Queued";default:return r.replace(/_/g," ")}}function o(r){switch(r){case e.QUEUED:case e.IDLE:return 0;case e.BLOCKED:return 1;case e.RUNNING:return 2;case e.COMPLETED:return 3;default:return 4}}function i(r){switch(r){case e.RUNNING:return"from-teal-300/0 via-teal-300/60 to-teal-300/0";case e.BLOCKED:return"from-amber-300/0 via-amber-300/55 to-amber-300/0";case e.IDLE:return"from-white/0 via-white/35 to-white/0";default:return"from-[#BFFF00]/0 via-[#BFFF00]/70 to-[#BFFF00]/0"}}function s(r){switch(r){case e.RUNNING:return"Current";case e.BLOCKED:return"Blocked on";default:return"Next"}}function E(r){switch(r){case e.RUNNING:return t.lime;case e.BLOCKED:return t.red;case e.IDLE:return t.iris;case e.QUEUED:return t.teal;default:return t.amber}}function d(r){switch(r){case e.RUNNING:return{background:`linear-gradient(to right, ${t.lime}, ${t.teal})`};case e.BLOCKED:return{background:`linear-gradient(to right, ${t.red}, ${t.amber})`};case e.IDLE:return{background:`linear-gradient(to right, ${t.iris}99, transparent)`};default:return{background:`linear-gradient(to right, ${t.lime}B3, ${t.teal}66)`}}}function l(r,a){if(a)return"Scope Under Review";switch(r){case e.COMPLETED:return"Completed Scope";case e.RUNNING:return"Current Work";case e.BLOCKED:return"Blocked Work";default:return"Next Work"}}function N(r){return r.some(a=>a.queueState===e.RUNNING)?e.RUNNING:r.some(a=>a.queueState===e.BLOCKED)?e.BLOCKED:r.some(a=>a.queueState===e.QUEUED)?e.QUEUED:r.some(a=>a.queueState===e.IDLE)?e.IDLE:e.COMPLETED}export{e as Q,c as a,n as b,i as c,N as d,s as e,d as f,E as g,o as q,l as w};
|
|
Binary file
|
|
Binary file
|