@useorgx/openclaw-plugin 0.7.4 → 0.7.6
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/{DHoYGJ9i.js → 77gGFBt6.js} +1 -1
- package/dashboard/dist/assets/77gGFBt6.js.br +0 -0
- package/dashboard/dist/assets/77gGFBt6.js.gz +0 -0
- package/dashboard/dist/assets/BBpTN_SR.js +1 -0
- package/dashboard/dist/assets/BBpTN_SR.js.br +0 -0
- package/dashboard/dist/assets/BBpTN_SR.js.gz +0 -0
- package/dashboard/dist/assets/BVShoyjA.js +1 -0
- package/dashboard/dist/assets/BVShoyjA.js.br +0 -0
- package/dashboard/dist/assets/BVShoyjA.js.gz +0 -0
- package/dashboard/dist/assets/{E8q3xNGK.js → BgcAY5rE.js} +1 -1
- package/dashboard/dist/assets/BgcAY5rE.js.br +0 -0
- package/dashboard/dist/assets/BgcAY5rE.js.gz +0 -0
- package/dashboard/dist/assets/{BdusVDcP.js → C-PAoJF-.js} +1 -1
- package/dashboard/dist/assets/C-PAoJF-.js.br +0 -0
- package/dashboard/dist/assets/C-PAoJF-.js.gz +0 -0
- package/dashboard/dist/assets/C0nA-iUG.js +1 -0
- package/dashboard/dist/assets/C0nA-iUG.js.br +0 -0
- package/dashboard/dist/assets/C0nA-iUG.js.gz +0 -0
- package/dashboard/dist/assets/C6GO-FKy.js +1 -0
- package/dashboard/dist/assets/C6GO-FKy.js.br +0 -0
- package/dashboard/dist/assets/C6GO-FKy.js.gz +0 -0
- package/dashboard/dist/assets/CFwPph5U.js +1 -0
- package/dashboard/dist/assets/CFwPph5U.js.br +0 -0
- package/dashboard/dist/assets/CFwPph5U.js.gz +0 -0
- package/dashboard/dist/assets/CPjsbbgZ.js +212 -0
- package/dashboard/dist/assets/CPjsbbgZ.js.br +0 -0
- package/dashboard/dist/assets/CPjsbbgZ.js.gz +0 -0
- package/dashboard/dist/assets/{Dlz0Cm_E.js → CSr2ZnTV.js} +1 -1
- package/dashboard/dist/assets/CSr2ZnTV.js.br +0 -0
- package/dashboard/dist/assets/CSr2ZnTV.js.gz +0 -0
- package/dashboard/dist/assets/CgQDT6yL.js +1 -0
- package/dashboard/dist/assets/CgQDT6yL.js.br +0 -0
- package/dashboard/dist/assets/CgQDT6yL.js.gz +0 -0
- package/dashboard/dist/assets/{CYchPSem.js → CnitK1MX.js} +1 -1
- package/dashboard/dist/assets/CnitK1MX.js.br +0 -0
- package/dashboard/dist/assets/CnitK1MX.js.gz +0 -0
- package/dashboard/dist/assets/{B1mDqDdy.js → D7DHFX0D.js} +1 -1
- package/dashboard/dist/assets/D7DHFX0D.js.br +0 -0
- package/dashboard/dist/assets/D7DHFX0D.js.gz +0 -0
- package/dashboard/dist/assets/DEip7uko.js +1 -0
- package/dashboard/dist/assets/DEip7uko.js.br +0 -0
- package/dashboard/dist/assets/DEip7uko.js.gz +0 -0
- package/dashboard/dist/assets/DHUSLc01.css +1 -0
- package/dashboard/dist/assets/DHUSLc01.css.br +0 -0
- package/dashboard/dist/assets/DHUSLc01.css.gz +0 -0
- package/dashboard/dist/assets/{DUaqjbT7.js → DOFL9l8s.js} +1 -1
- package/dashboard/dist/assets/DOFL9l8s.js.br +0 -0
- package/dashboard/dist/assets/DOFL9l8s.js.gz +0 -0
- package/dashboard/dist/assets/{BXapfumA.js → DpuQm1oF.js} +1 -1
- package/dashboard/dist/assets/DpuQm1oF.js.br +0 -0
- package/dashboard/dist/assets/DpuQm1oF.js.gz +0 -0
- package/dashboard/dist/assets/{BwkNYH6r.js → DxKG5zy8.js} +2 -2
- package/dashboard/dist/assets/DxKG5zy8.js.br +0 -0
- package/dashboard/dist/assets/DxKG5zy8.js.gz +0 -0
- package/dashboard/dist/assets/tcEHYcbW.js +1 -0
- package/dashboard/dist/assets/tcEHYcbW.js.br +0 -0
- package/dashboard/dist/assets/tcEHYcbW.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/index.js +1 -0
- package/dist/http/routes/live-legacy.js +89 -3
- package/dist/http/routes/live-misc.d.ts +1 -0
- package/dist/http/routes/live-misc.js +76 -0
- package/dist/http/routes/mission-control-read.d.ts +4 -0
- package/dist/http/routes/mission-control-read.js +8 -0
- package/dist/http/routes/usage.js +15 -3
- package/dist/json-utils.js +5 -1
- package/package.json +6 -1
- package/dashboard/dist/assets/B1mDqDdy.js.br +0 -0
- package/dashboard/dist/assets/B1mDqDdy.js.gz +0 -0
- package/dashboard/dist/assets/BDMstdfu.js +0 -1
- package/dashboard/dist/assets/BDMstdfu.js.br +0 -0
- package/dashboard/dist/assets/BDMstdfu.js.gz +0 -0
- package/dashboard/dist/assets/BXapfumA.js.br +0 -0
- package/dashboard/dist/assets/BXapfumA.js.gz +0 -0
- package/dashboard/dist/assets/BZZKPNDb.css +0 -1
- package/dashboard/dist/assets/BZZKPNDb.css.br +0 -0
- package/dashboard/dist/assets/BZZKPNDb.css.gz +0 -0
- package/dashboard/dist/assets/BdusVDcP.js.br +0 -0
- package/dashboard/dist/assets/BdusVDcP.js.gz +0 -0
- package/dashboard/dist/assets/BwkNYH6r.js.br +0 -0
- package/dashboard/dist/assets/BwkNYH6r.js.gz +0 -0
- package/dashboard/dist/assets/CRhvoVeH.js +0 -1
- package/dashboard/dist/assets/CRhvoVeH.js.br +0 -0
- package/dashboard/dist/assets/CRhvoVeH.js.gz +0 -0
- package/dashboard/dist/assets/CYchPSem.js.br +0 -0
- package/dashboard/dist/assets/CYchPSem.js.gz +0 -0
- package/dashboard/dist/assets/Cn07669c.js +0 -212
- package/dashboard/dist/assets/Cn07669c.js.br +0 -0
- package/dashboard/dist/assets/Cn07669c.js.gz +0 -0
- package/dashboard/dist/assets/DBG89Wsz.js +0 -1
- package/dashboard/dist/assets/DBG89Wsz.js.br +0 -0
- package/dashboard/dist/assets/DBG89Wsz.js.gz +0 -0
- package/dashboard/dist/assets/DHoYGJ9i.js.br +0 -0
- package/dashboard/dist/assets/DHoYGJ9i.js.gz +0 -0
- package/dashboard/dist/assets/DHtZPEKd.js +0 -1
- package/dashboard/dist/assets/DHtZPEKd.js.br +0 -0
- package/dashboard/dist/assets/DHtZPEKd.js.gz +0 -0
- package/dashboard/dist/assets/DUaqjbT7.js.br +0 -0
- package/dashboard/dist/assets/DUaqjbT7.js.gz +0 -0
- package/dashboard/dist/assets/Dlz0Cm_E.js.br +0 -0
- package/dashboard/dist/assets/Dlz0Cm_E.js.gz +0 -0
- package/dashboard/dist/assets/E8q3xNGK.js.br +0 -0
- package/dashboard/dist/assets/E8q3xNGK.js.gz +0 -0
- package/dashboard/dist/assets/VH0fzk6I.js +0 -1
- package/dashboard/dist/assets/VH0fzk6I.js.br +0 -0
- package/dashboard/dist/assets/VH0fzk6I.js.gz +0 -0
- package/dashboard/dist/assets/bxgRC96y.js +0 -1
- package/dashboard/dist/assets/bxgRC96y.js.br +0 -0
- package/dashboard/dist/assets/bxgRC96y.js.gz +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as r}from"./cNrhgGc1.js";import{
|
|
1
|
+
import{j as r}from"./cNrhgGc1.js";import{y as s}from"./CPjsbbgZ.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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as l,a as c}from"./cNrhgGc1.js";import{b as g}from"./CPjsbbgZ.js";function f({authToken:s=null,embedMode:o=!1,enabled:n=!0}={}){var a;const i=l.useMemo(()=>["usage-control-plane",{authToken:s,embedMode:o}],[s,o]),e=c({queryKey:i,enabled:n,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 u=(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(u)}if(!r||typeof r!="object"||!("generatedAt"in r))throw new Error("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{f as u};
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{u as Jt,r as d,a as Zt,b as Ve,j as e}from"./cNrhgGc1.js";import{i as Xt,q as He,b as Ee,Q as ht,D as Yt,u as Ot,G as k,P as en,y as ne,F as ft,R as tn,z as P,o as kt,A as jt,E as $e,d as bt,h as Ye,B as gt,C as nn,U as sn}from"./CPjsbbgZ.js";import{S as G}from"./77gGFBt6.js";import{A as qe,m as V,u as Nt,R as rn,b as an,a as on}from"./CxQ08qFN.js";function ln({initiativeId:n=null,authToken:s=null,embedMode:l=!1,enabled:i=!0}){var se,Y,re;const b=Jt(),g=Xt(),C=d.useMemo(()=>He.autoContinueStatus({initiativeId:n??"__global__",authToken:s,embedMode:l}),[n,s,l]),y=Zt({queryKey:C,enabled:i&&(!!n||n===null),queryFn:async()=>{if(g)return{ok:!0,initiativeId:n,run:null,defaults:{tokenBudget:null,tickMs:0}};const p=new URLSearchParams;n&&p.set("initiative_id",n);const m=await fetch(`/orgx/api/mission-control/auto-continue/status?${p.toString()}`,{headers:Ee({authToken:s,embedMode:l})}),c=await m.json().catch(()=>null);if(!m.ok){const u=typeof(c==null?void 0:c.error)=="string"&&c.error||typeof(c==null?void 0:c.message)=="string"&&c.message||`Failed to load auto-continue status (${m.status})`;return{ok:!1,initiativeId:n,run:null,defaults:{tokenBudget:null,tickMs:0},error:u}}return c},refetchInterval:p=>{var x,j;const m=p.state.data;if((m==null?void 0:m.ok)===!1)return!1;const c=((x=m==null?void 0:m.error)==null?void 0:x.toLowerCase())??"";if(c.includes("404")||c.includes("400")||c.includes("not found")||c.includes("bad request"))return!1;const f=((j=m==null?void 0:m.run)==null?void 0:j.status)??null;return f==="running"||f==="stopping"?2500:12e3}}),F=async()=>{await b.invalidateQueries({queryKey:C}),await b.invalidateQueries({queryKey:He.missionControlGraph({initiativeId:n,authToken:s,embedMode:l})}),await b.invalidateQueries({queryKey:He.liveData({authToken:s,embedMode:l})})},_=Ve({mutationFn:async p=>{if(g){const f=y.data??null;return{ok:!0,initiativeId:n,run:(f==null?void 0:f.run)??null,defaults:(f==null?void 0:f.defaults)??{tokenBudget:null,tickMs:0}}}const m={};n&&(m.initiativeId=n),m.ignoreSpawnGuardRateLimit=!0,p&&typeof p=="object"&&(typeof p.tokenBudgetTokens=="number"&&(m.tokenBudgetTokens=p.tokenBudgetTokens),typeof p.agentId=="string"&&p.agentId.trim().length>0&&(m.agentId=p.agentId.trim()),typeof p.maxParallelSlices=="number"&&Number.isFinite(p.maxParallelSlices)&&(m.maxParallelSlices=p.maxParallelSlices),p.parallelMode==="iwmt"&&(m.parallelMode=p.parallelMode));const c=await fetch("/orgx/api/mission-control/auto-continue/start",{method:"POST",headers:Ee({authToken:s,embedMode:l,contentTypeJson:!0}),body:JSON.stringify(m)}),u=await c.json().catch(()=>null);if(!c.ok){const f=ht(u);if(f)throw f;const x=typeof(u==null?void 0:u.error)=="string"&&u.error||typeof(u==null?void 0:u.message)=="string"&&u.message||`Failed to start auto-continue (${c.status})`;throw new Error(x)}if(u&&typeof u=="object"&&"run"in u){const f=y.data??null;return{ok:!0,initiativeId:n,run:u.run??null,defaults:(f==null?void 0:f.defaults)??{tokenBudget:null,tickMs:0}}}return u},onSuccess:()=>{F()}}),H=Ve({mutationFn:async()=>{if(g){const u=y.data??null;return{ok:!0,initiativeId:n,run:null,defaults:(u==null?void 0:u.defaults)??{tokenBudget:null,tickMs:0}}}const p={};n&&(p.initiativeId=n);const m=await fetch("/orgx/api/mission-control/auto-continue/stop",{method:"POST",headers:Ee({authToken:s,embedMode:l,contentTypeJson:!0}),body:JSON.stringify(p)}),c=await m.json().catch(()=>null);if(!m.ok){const u=typeof(c==null?void 0:c.error)=="string"&&c.error||typeof(c==null?void 0:c.message)=="string"&&c.message||`Failed to stop auto-continue (${m.status})`;throw new Error(u)}if(c&&typeof c=="object"&&"run"in c){const u=y.data??null;return{ok:!0,initiativeId:n,run:c.run??null,defaults:(u==null?void 0:u.defaults)??{tokenBudget:null,tickMs:0}}}return c},onSuccess:()=>{F()}}),T=Ve({mutationFn:async p=>{var f;if(g)return{ok:!0,dispatched:((f=p.workstreamIds)==null?void 0:f.length)??1};const m={initiativeId:p.initiativeId};p.workstreamIds&&p.workstreamIds.length>0&&(m.workstreamIds=p.workstreamIds),p.agentId&&(m.agentId=p.agentId),p.scope&&(m.scope=p.scope),m.ignoreSpawnGuardRateLimit=!0;const c=await fetch("/orgx/api/mission-control/next-up/launch",{method:"POST",headers:Ee({authToken:s,embedMode:l,contentTypeJson:!0}),body:JSON.stringify(m)}),u=await c.json().catch(()=>null);if(!c.ok){const x=ht(u);if(x)throw x;const j=typeof(u==null?void 0:u.error)=="string"&&u.error||typeof(u==null?void 0:u.message)=="string"&&u.message||`Failed to launch (${c.status})`;throw new Error(j)}return u??{ok:!0,dispatched:0}},onSuccess:()=>{F()}}),M=((se=y.data)==null?void 0:se.run)??null,L=(M==null?void 0:M.status)??null,z=L==="running"||L==="stopping",U=L==="stopping"||H.isPending;return{status:y.data??null,run:M,isRunning:z,isGracefullyStopping:U,isLoading:y.isLoading,error:((Y=y.data)==null?void 0:Y.error)??((re=y.error)==null?void 0:re.message)??null,start:_.mutateAsync,stop:H.mutateAsync,launchSingle:T.mutateAsync,isStarting:_.isPending,isStopping:H.isPending,isLaunching:T.isPending,refetch:y.refetch}}async function St(n,s){var g;const i=await(await fetch(n,s)).json().catch(()=>null),b=((g=i==null?void 0:i.data)==null?void 0:g.url)??(i==null?void 0:i.url)??null;if(typeof b=="string"&&b.trim())return b.trim();throw new Error((i==null?void 0:i.error)??"Billing link unavailable")}async function cn(n){var b;const s=((b=n==null?void 0:n.actions)==null?void 0:b.checkout)??"/orgx/api/billing/checkout",l=((n==null?void 0:n.requiredPlan)??"starter").trim().toLowerCase()||"starter",i=await St(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({planId:l})});window.open(i,"_blank","noopener,noreferrer")}async function un(n){var i;const s=((i=n==null?void 0:n.actions)==null?void 0:i.portal)??"/orgx/api/billing/portal",l=await St(s,{method:"POST"});window.open(l,"_blank","noopener,noreferrer")}function dn(n){return n==="success"?"border-emerald-400/30 bg-[#0A1210]/95 text-emerald-100":n==="warning"?"border-amber-300/30 bg-[#12100A]/95 text-amber-100":n==="error"?"border-red-400/32 bg-[#120A0A]/95 text-red-100":n==="info"?"border-cyan-300/28 bg-[#0A1012]/95 text-cyan-100":"border-strong bg-[#0B0F16]/95 text-primary"}function mn({open:n,tone:s="neutral",title:l,message:i=null,className:b,primaryAction:g=null,secondaryAction:C=null,onDismiss:y=null,autoDismissMs:F=null}){return d.useEffect(()=>{if(!n||!y||!F)return;const _=window.setTimeout(()=>y(),F);return()=>window.clearTimeout(_)},[F,y,n,l,i]),e.jsx(qe,{initial:!1,children:n?e.jsx(V.div,{initial:{opacity:0,y:-8,scale:.985},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-8,scale:.985},transition:{duration:.2,ease:[.22,1,.36,1]},className:`pointer-events-none ${b??""}`,children:e.jsxs("div",{className:`pointer-events-none min-w-[220px] max-w-[420px] rounded-xl border px-3 py-2 shadow-[0_16px_36px_rgba(0,0,0,0.42)] backdrop-blur ${dn(s)}`,children:[e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-caption font-semibold",children:l}),i?e.jsx("p",{className:"mt-0.5 text-caption opacity-85",children:i}):null]}),y?e.jsx("button",{type:"button",onClick:y,className:"pointer-events-auto inline-flex h-6 w-6 items-center justify-center rounded-md text-current/70 transition-colors hover:bg-white/[0.08] hover:text-current","aria-label":"Dismiss toast",title:"Dismiss",children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 6 6 18"}),e.jsx("path",{d:"m6 6 12 12"})]})}):null]}),g||C?e.jsxs("div",{className:"mt-2 flex items-center gap-1.5",children:[C?e.jsx("button",{type:"button",onClick:C.onClick,className:"pointer-events-auto h-7 rounded-md border border-strong bg-white/[0.06] px-2.5 text-micro font-semibold text-current transition-colors hover:bg-white/[0.12]",children:C.label}):null,g?e.jsx("button",{type:"button",onClick:g.onClick,className:"pointer-events-auto h-7 rounded-md border border-white/25 bg-white/[0.14] px-2.5 text-micro font-semibold text-current transition-colors hover:bg-white/[0.2]",children:g.label}):null]}):null]})}):null})}function Ct({className:n=""}){return e.jsx("svg",{viewBox:"0 0 20 20",fill:"none","aria-hidden":!0,className:n,children:e.jsx("path",{d:"M7 5.4v9.2c0 .7.75 1.15 1.38.83l7.6-4.6a.95.95 0 0 0 0-1.62l-7.6-4.64A.95.95 0 0 0 7 5.4Z",fill:"currentColor"})})}function xn({className:n=""}){return e.jsxs("svg",{viewBox:"0 0 20 20",fill:"none","aria-hidden":!0,className:n,children:[e.jsx("path",{d:"M6.2 9.4V6.7c0-.7.5-1.2 1.1-1.2s1.1.5 1.1 1.2v2.2",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"}),e.jsx("path",{d:"M8.4 8.9V5.8c0-.7.5-1.3 1.1-1.3s1.1.6 1.1 1.3v3",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"}),e.jsx("path",{d:"M10.6 8.9V6.2c0-.7.5-1.3 1.1-1.3s1.1.6 1.1 1.3v3.2",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"}),e.jsx("path",{d:"M12.8 9.6V7.2c0-.7.5-1.2 1.1-1.2s1.1.5 1.1 1.2v4.2c0 2.7-1.9 4.6-4.6 4.6H9.2c-2.1 0-3.7-1-4.6-2.8l-.9-1.7c-.3-.6 0-1.4.6-1.7.6-.3 1.3 0 1.6.6l.7 1.4",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round"})]})}function pn({className:n=""}){return e.jsxs("svg",{viewBox:"0 0 20 20",fill:"none","aria-hidden":!0,className:n,children:[e.jsx("path",{d:"M6.4 9.2V7.4c0-.7.5-1.2 1.1-1.2s1.1.5 1.1 1.2v1.3",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"}),e.jsx("path",{d:"M8.6 8.9V7c0-.7.5-1.2 1.1-1.2s1.1.5 1.1 1.2v2",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"}),e.jsx("path",{d:"M10.8 9.2V7.3c0-.7.5-1.2 1.1-1.2s1.1.5 1.1 1.2v2.6",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"}),e.jsx("path",{d:"M13 9.8V8.2c0-.7.5-1.2 1.1-1.2s1.1.5 1.1 1.2v3.6c0 2.4-1.7 4-4.1 4H9.7c-2 0-3.4-.9-4.2-2.5l-.8-1.4c-.3-.6 0-1.3.5-1.6.6-.3 1.2-.1 1.6.5l.6 1",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round"})]})}function yt(n){return n==="running"?"border-teal-300/35 bg-teal-400/[0.12] text-teal-100":n==="blocked"?"border-amber-300/35 bg-amber-400/[0.12] text-amber-100":n==="idle"?"border-strong bg-white/[0.05] text-secondary":"border-[#BFFF00]/30 bg-[#BFFF00]/12 text-[#E1FFB2]"}function wt(n){return n==="running"?"Running":n==="blocked"?"Needs input":n==="idle"?"Idle":"Queued"}function Ae(n){return n==="queued"||n==="idle"?0:n==="blocked"?1:n==="running"?2:n==="completed"?3:4}function hn(n){return n.some(s=>s.queueState==="running")?"running":n.some(s=>s.queueState==="blocked")?"blocked":n.some(s=>s.queueState==="queued")?"queued":n.some(s=>s.queueState==="idle")?"idle":"completed"}function It(n){return n==="running"?"from-teal-300/0 via-teal-300/60 to-teal-300/0":n==="blocked"?"from-amber-300/0 via-amber-300/55 to-amber-300/0":n==="idle"?"from-white/0 via-white/35 to-white/0":"from-[#BFFF00]/0 via-[#BFFF00]/70 to-[#BFFF00]/0"}function Je(n){return n==="running"?"Current":n==="blocked"?"Blocked on":"Next"}function Ze(n){const s=typeof n.sliceTaskCount=="number"&&Number.isFinite(n.sliceTaskCount)?Math.max(0,Math.floor(n.sliceTaskCount)):null,l=n.sliceScope==="task"?"task":n.sliceScope==="milestone"?"milestone slice":"workstream slice",i=s&&s>0?`${s} ${s===1?"task":"tasks"}`:null;return n.queueState==="running"?i?`Executing ${i} in ${l}.`:"Execution in progress. Task detail will appear as the scheduler advances.":n.queueState==="blocked"?n.blockReason?"Blocked while waiting for dependency resolution.":"Blocked. Waiting for dependency or review.":n.queueState==="queued"?i?`Queued with ${i} in ${l}.`:"Queued at workstream scope. Task detail will populate after dispatch.":n.queueState==="completed"?"Completed. No queued tasks remain.":"Idle. Ready to dispatch when started."}function qt(n){const s=typeof n.initiativePriority=="string"?n.initiativePriority.trim().toLowerCase():"",l=typeof n.initiativePriorityNum=="number"&&Number.isFinite(n.initiativePriorityNum)?Math.max(1,Math.min(100,Math.round(n.initiativePriorityNum))):null,i=s==="urgent"||s==="high"||s==="medium"||s==="low"?s:l!==null?l<=12?"urgent":l<=30?"high":l<=60?"medium":"low":null;if(!i)return null;const b=i==="urgent"?"P1":i==="high"?"P2":i==="medium"?"P3":"P4",g=i==="urgent"?"Urgent":i==="high"?"High":i==="medium"?"Medium":"Low",C=i==="urgent"?"border-red-300/35 bg-red-500/[0.14] text-red-100":i==="high"?"border-amber-300/35 bg-amber-500/[0.14] text-amber-100":i==="medium"?"border-[#BFFF00]/35 bg-[#BFFF00]/14 text-[#E1FFB2]":"border-white/[0.2] bg-white/[0.08] text-white/70";return{shortLabel:`${b} ${g}`,longLabel:`Initiative priority ${g} (${b})`,toneClass:C}}function fn(n){const s=n.trim().toLowerCase();if(s.includes("timed out")||s.includes("timeout")||s.includes("request cancelled")||s.includes("signal is aborted"))return"Next Up is still syncing. Keep this panel open and it will repopulate automatically.";if(s.includes("unauthorized")||s.includes("forbidden")||s.includes("api key")||s.includes("auth"))return"Next Up is unavailable until OrgX authentication is reconnected in Settings.";if(s.includes("unknown api endpoint")||s.includes("route is unavailable"))return"This runtime is missing queue routes. Restart and update the plugin build.";const l=n.split("|").map(i=>i.trim()).filter(Boolean).map(i=>i.replace(/^[^:]+:\s*/,"").trim()).filter(Boolean).slice(0,2).join(" ");return Ye(l||n)||"Next Up is temporarily unavailable."}function bn(n){const s=n.trim().toLowerCase();return s.includes("timed out")||s.includes("timeout")||s.includes("request cancelled")||s.includes("signal is aborted")?"Signal is delayed right now. Queue data will appear as soon as sync catches up.":s.includes("fallback")?"Showing fallback queue data while full signal refreshes.":s.includes("unknown api endpoint")||s.includes("route is unavailable")?"Some queue controls are unavailable in this plugin build. Update and restart to restore full controls.":Ye(n.trim())}function Fe(n,s,l){const i=typeof n=="string"?n.trim():"";if(i&&!gt(i))return P(i);const b=typeof s=="string"?s.trim():"";return b?gt(b)?`${l} ${nn(b)}`:P(b):l}function $t(n){const s=typeof n.runnerAgentName=="string"?n.runnerAgentName.trim():"";if(!s)return"Unassigned";const l=s.toLowerCase();return l==="undefined"||l==="null"||l==="main"&&(n.runnerAgentId==="unassigned"||n.runnerSource==="fallback")?"Unassigned":s}function Ft(n){return n.runnerSource==="inferred"?"inferred":null}function Mt(n,s){const l=n.runnerSource==="assigned"?"assigned":n.runnerSource==="inferred"?"inferred":"fallback";return s==="Unassigned"?`Runner ${l}`:`${s} · ${l}`}function ge(n,s){return!n||n.trim().length===0?s:Ye(n.trim())||s}function vt(n){return!n||typeof n!="object"||Array.isArray(n)?null:n}function Xe(n,s){const l=P(n.workstreamTitle),i=vt(s),b=i&&typeof i.dispatchMode=="string"?i.dispatchMode:null,g=vt(i==null?void 0:i.run);return(g&&typeof g.stopReason=="string"?g.stopReason:g&&typeof g.stop_reason=="string"?g.stop_reason:null)==="budget_exhausted"?`Dispatch acknowledged for ${l}, but autopilot stopped: budget exhausted.`:b==="pending"?`Dispatching ${l}; waiting for slice start…`:b==="fallback"?`Dispatched ${l} using fallback runner.`:`Dispatched ${l}.`}function Tt({className:n=""}){return e.jsxs("svg",{viewBox:"0 0 20 20",fill:"none","aria-hidden":!0,className:n,children:[e.jsx("circle",{cx:"4.5",cy:"10",r:"1.4",fill:"currentColor"}),e.jsx("circle",{cx:"10",cy:"10",r:"1.4",fill:"currentColor"}),e.jsx("circle",{cx:"15.5",cy:"10",r:"1.4",fill:"currentColor"})]})}function gn({compact:n}){const s=n?3:6;return e.jsxs("div",{className:"space-y-2.5",children:[e.jsxs("div",{className:"flex items-center gap-2 px-1 pt-1 text-micro uppercase tracking-[0.12em] text-muted",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-[#BFFF00]/70 status-breathe"}),e.jsx("span",{children:"Calibrating queue"})]}),Array.from({length:s}).map((l,i)=>e.jsxs("div",{className:"nextup-skeleton-card rounded-2xl border border-white/[0.08] bg-white/[0.02] px-3 py-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2.5",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-start gap-2.5",children:[e.jsx(G,{className:"h-8 w-8 rounded-full"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx(G,{className:"h-3 w-40 rounded-md"}),e.jsx(G,{className:"mt-2 h-4 w-56 rounded-md"})]})]}),e.jsx(G,{className:"h-5 w-16 rounded-full"})]}),e.jsxs("div",{className:"mt-3 rounded-lg border border-white/[0.07] bg-black/[0.18] px-2.5 py-2",children:[e.jsx(G,{className:"h-3 w-14 rounded"}),e.jsx(G,{className:"mt-2 h-3 w-full rounded"}),e.jsx(G,{className:"mt-2 h-3 w-3/5 rounded"})]}),e.jsxs("div",{className:"mt-2.5 flex flex-wrap gap-1.5",children:[e.jsx(G,{className:"h-8 w-24 rounded-full"}),e.jsx(G,{className:"h-8 w-20 rounded-full"}),e.jsx(G,{className:"h-8 w-24 rounded-full"})]})]},`nextup-skeleton-${i}`))]})}function yn({initiativeId:n=null,projectId:s=null,authToken:l=null,embedMode:i=!1,title:b="Next Up",showHeader:g=!0,compact:C=!1,className:y,disableEnterAnimation:F=!1,allowCompactToggle:_=!1,onToggleCompact:H,onOpenInitiative:T,onOpenSettings:M,onUpgradeGate:L,onOpenSliceDetail:z,selectionEnabled:U=!0,panelStyle:se="card",showQueueSettings:Y=!0,queueModel:re,queueActions:p,snapshotVersion:m=null,excludeRunning:c=!1}){var pt;const[u,f]=d.useState(C);d.useEffect(()=>f(C),[C]);const x=_&&!H?u:C,j=t=>{H?H(t):f(t)},[J,N]=d.useState(null),[I,ye]=d.useState("workstream"),[de,we]=d.useState(null),ve="bottom",[B,ie]=d.useState(null),[K,w]=d.useState(null),[me,ae]=d.useState(null),[O,xe]=d.useState(new Set),[Me,pe]=d.useState(null),[ke,je]=d.useState(!1),[Bt,Te]=d.useState(!1),Z=Nt(),Oe=d.useRef(null),Rt=Yt({initiativeId:n,projectId:s,authToken:l,embedMode:i,enabled:!re,snapshotVersion:m,zoomLevel:I}),Lt=re??Rt,{items:he,degraded:oe,isLoading:Q,isFetching:et,error:Be,refetch:Pt,playWorkstream:_e,startWorkstreamAutoContinue:tt,initiativeGroups:ze,milestoneGroups:Qe}=Lt;ln({initiativeId:n,authToken:l,embedMode:i});const Et=Ot({authToken:l,embedMode:i}),X=p??Et,D=t=>`${t.initiativeId}:${t.workstreamId}`,ee=I==="workstream",Ne=d.useMemo(()=>he.filter(t=>t.queueState==="running").length,[he]),Ue=d.useMemo(()=>Z?{duration:.01}:k.surfaceSwitch,[Z]),W=d.useMemo(()=>{if(c)return he.filter(a=>a.queueState!=="running");const t=he.filter(a=>a.queueState!=="running");return t.length>0?t:he},[c,he]),nt=d.useMemo(()=>W.length===0?"empty":W.some(t=>t.queueState!=="running"&&t.queueState!=="blocked")?"queued":W.some(t=>t.queueState==="blocked")?"blocked":W.some(t=>t.queueState==="running")?"running":"queued",[W]),st=d.useMemo(()=>c?ze.map(t=>({...t,items:t.items.filter(a=>a.queueState!=="running")})).filter(t=>t.items.length>0).map(t=>({...t,queueState:hn(t.items)})):ze,[c,ze]),Se=d.useMemo(()=>[...st].sort((t,a)=>{const o=Ae(t.queueState)-Ae(a.queueState);return o!==0?o:t.initiativeTitle.localeCompare(a.initiativeTitle)}),[st]),rt=d.useMemo(()=>c?Qe.filter(t=>t.item.queueState!=="running"):Qe,[c,Qe]),Ce=d.useMemo(()=>[...rt].sort((t,a)=>{const o=Ae(t.queueState)-Ae(a.queueState);if(o!==0)return o;const r=t.initiativeTitle.localeCompare(a.initiativeTitle);if(r!==0)return r;const h=t.workstreamTitle.localeCompare(a.workstreamTitle);return h!==0?h:t.milestoneTitle.localeCompare(a.milestoneTitle)}),[rt]),Ke=d.useMemo(()=>x?Se.slice(0,5):Se,[x,Se]),De=d.useMemo(()=>x?Ce.slice(0,5):Ce,[x,Ce]),it=d.useMemo(()=>I==="initiative"?Se.length:I==="milestone"?Ce.length:W.length,[W.length,Se.length,Ce.length,I]),At=[{value:"initiative",label:"Initiative"},{value:"workstream",label:"Workstream"},{value:"milestone",label:"Milestone"}],R=d.useMemo(()=>ee?x?W.slice(0,5):W:[],[x,ee,W]),_t=d.useMemo(()=>R.filter(t=>O.has(D(t))),[O,R]),[fe,at]=d.useState([]),We=d.useRef([]),ot=d.useMemo(()=>{const t=new Map;for(const a of R)t.set(D(a),a);return t},[R]),E=d.useMemo(()=>R.map(D),[R]),zt=d.useMemo(()=>E.join("|"),[E]);d.useEffect(()=>{at(t=>{if(x)return[];const a=[],o=new Set(E);for(const r of t)o.has(r)&&a.push(r);for(const r of E)a.includes(r)||a.push(r);return a})},[x,zt]),d.useEffect(()=>{We.current=fe},[fe]),d.useEffect(()=>{Me&&(E.includes(Me)||pe(null))},[Me,E]),d.useEffect(()=>{xe(t=>{if(t.size===0)return t;const a=new Set(R.map(D)),o=new Set;for(const r of t)a.has(r)&&o.add(r);return o.size===t.size?t:o})},[R]),d.useEffect(()=>{if(!me)return;R.some(a=>D(a)===me)||ae(null)},[me,R]),d.useEffect(()=>{if(oe.length===0){Te(!1);return}Te(!1)},[oe]),d.useEffect(()=>{U&&!x&&O.size>0&&je(!1)},[x,O.size,U]),d.useEffect(()=>{if(!ke)return;const t=o=>{var h;const r=o.target;r&&((h=Oe.current)!=null&&h.contains(r)||je(!1))},a=o=>{o.key==="Escape"&&je(!1)};return document.addEventListener("mousedown",t),document.addEventListener("touchstart",t),document.addEventListener("keydown",a),()=>{document.removeEventListener("mousedown",t),document.removeEventListener("touchstart",t),document.removeEventListener("keydown",a)}},[ke]);const lt=async t=>{const a=D(t),o=P(t.workstreamTitle);try{await X.remove({initiativeId:t.initiativeId,workstreamId:t.workstreamId}),xe(r=>{if(!r.has(a))return r;const h=new Set(r);return h.delete(a),h}),pe(r=>r===a?null:r),N(`Removed ${o} from queue.`)}catch(r){const h=r instanceof Error?r.message:"";N(ge(h,"Failed to remove from queue"))}},Qt=(t,a,o)=>{const r=x?E:fe.length>0?fe:E;xe(h=>{const v=new Set(h),A=Me;if(o&&A&&r.includes(A)){const S=r.indexOf(t),te=r.indexOf(A);if(S>=0&&te>=0){const[Le,Pe]=S<te?[S,te]:[te,S];for(const Ie of r.slice(Le,Pe+1))a?v.add(Ie):v.delete(Ie)}else a?v.add(t):v.delete(t)}else a?v.add(t):v.delete(t);return v}),pe(t)},Ut=()=>{xe(new Set(E)),pe(E.length>0?E[E.length-1]:null)},Kt=()=>{xe(new Set),pe(null)},Ge=async t=>{if(O.size===0){N("Select one or more queue items first.");return}const a=R.map(o=>({key:D(o),item:o})).filter(o=>O.has(o.key));if(a.length===0){N("Selected queue items are no longer visible.");return}w(`bulk:${t}`),N(null);try{const o=a.map(({item:S})=>({initiativeId:S.initiativeId,workstreamId:S.workstreamId})),r=await X.bulk({action:t,items:o}),h=typeof(r==null?void 0:r.updated)=="number"?r.updated??0:0,v=typeof(r==null?void 0:r.failed)=="number"?r.failed??0:0,A=Array.isArray(r==null?void 0:r.errors)?r.errors.filter(S=>typeof S=="string").map(S=>S.trim()).filter(Boolean):[],q=t==="remove"?"removed":t==="move_top"?"moved to top":"moved to bottom";h===0&&v>0&&A.length>0?N(ge(A[0],`${v} queue action${v===1?"":"s"} failed.`)):N(v>0?`${h} item${h===1?"":"s"} ${q}; ${v} failed.`:`${h} item${h===1?"":"s"} ${q}.`),xe(new Set),pe(null)}catch(o){const r=o instanceof Error?o.message:"";N(ge(r,"Bulk queue action failed"))}finally{w(null)}},Dt=async()=>{const t=We.current.map(a=>ot.get(a)).filter(Boolean).map(a=>({initiativeId:a.initiativeId,workstreamId:a.workstreamId}));t.length!==0&&await X.reorder({order:t})},le=async(t,a,o)=>{N(null),ie(null),L==null||L(null),w(t);try{const r=await a();N(typeof o=="function"?o(r):o)}catch(r){if(r instanceof sn)ie(r),L==null||L(r);else{const h=r instanceof Error?r.message:"";N(ge(h,"Action failed"))}}finally{w(null)}},ct=async t=>await _e({initiativeId:t.initiativeId,workstreamId:t.workstreamId,agentId:t.runnerAgentId}),Re=B?"upgrade":Be?"error":J?"notice":null,ut=Be?fn(Be):null,dt=oe.length>0?bn(oe[0]):null,Wt=Re!==null,Gt=oe.length>0&&!Bt&&me===null&&!ke,ce=_t.length,Vt=d.useMemo(()=>I==="initiative"?Ke.length>0:I==="milestone"?De.length>0:R.length>0,[Ke.length,R.length,De.length,I]),mt=U&&ee&&!x&&ce>0,Ht=I==="initiative"?"No initiatives in the queue right now.":I==="milestone"?"No milestone slices in the queue right now.":Ne>0?`No queued workstreams yet. ${Ne} running item${Ne===1?"":"s"} still in-flight.`:oe.length>0?"Queue signal is delayed right now.":"No queued workstreams right now.",xt=e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:Ut,className:"control-pill h-8 px-2.5 text-caption font-semibold",children:"Select all"}),e.jsx("button",{type:"button",onClick:Kt,disabled:O.size===0,className:"control-pill h-8 px-2.5 text-caption font-semibold disabled:opacity-45",children:"Clear"}),e.jsx("button",{type:"button",disabled:ce===0||K==="bulk:move_top",onClick:()=>void Ge("move_top"),className:"control-pill h-8 px-2.5 text-caption font-semibold disabled:opacity-45",children:"Move top"}),e.jsx("button",{type:"button",disabled:ce===0||K==="bulk:move_bottom",onClick:()=>void Ge("move_bottom"),className:"control-pill h-8 px-2.5 text-caption font-semibold disabled:opacity-45",children:"Move bottom"}),e.jsx("button",{type:"button",disabled:ce===0||K==="bulk:remove",onClick:()=>void Ge("remove"),className:"control-pill h-8 px-2.5 text-caption font-semibold disabled:opacity-45",children:"Remove"})]});return e.jsxs(en,{surface:se==="card",className:`flex h-full min-h-0 flex-col overflow-hidden ${F?"":"card-enter"} ${se==="flat"?"!rounded-none !border-none !bg-transparent !shadow-none":""} ${y??""}`,children:[g?e.jsxs("div",{className:"flex items-center justify-between gap-2 border-b border-subtle px-4 py-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("h2",{className:"truncate text-heading font-semibold text-white",children:b}),e.jsx("span",{className:"chip inline-flex min-w-[52px] justify-center text-micro tabular-nums",children:Q?e.jsx("span",{"aria-hidden":!0,className:"h-2.5 w-5 rounded bg-white/15 animate-pulse"}):it}),e.jsx("span",{className:ne("chip inline-flex min-w-[148px] justify-center text-micro tabular-nums transition-opacity",!Q&&Ne>0&&ee?"text-secondary opacity-100":"pointer-events-none opacity-0"),children:`${Ne} active elsewhere`}),e.jsx("span",{className:ne("inline-flex min-w-[92px] justify-end text-micro text-muted transition-opacity",et&&!Q?"opacity-100":"opacity-0"),"aria-live":"polite",children:"refreshing…"})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"inline-flex items-center rounded-xl border border-white/[0.1] bg-white/[0.03] p-1",role:"tablist","aria-label":"Next Up scope",children:At.map(t=>{const a=I===t.value;return e.jsxs(V.button,{type:"button",role:"tab","aria-selected":a,onClick:()=>ye(t.value),...k.segmentedTap,className:ne("relative h-7 rounded-lg px-2.5 text-caption font-semibold transition-colors",a?"text-[#E8FFD0]":"text-secondary hover:text-white"),title:`Show ${t.label.toLowerCase()} queue`,children:[a?e.jsx(V.span,{layoutId:"next-up-scope-indicator",transition:Z?{duration:.01}:k.railMorphSpring,className:"pointer-events-none absolute inset-0 rounded-lg border border-[#BFFF00]/35 bg-[#BFFF00]/16","aria-hidden":!0}):null,e.jsx("span",{className:"relative z-[1]",children:t.label})]},t.value)})}),_?e.jsx("button",{type:"button",onClick:()=>j(!x),className:"control-pill h-8 flex-shrink-0 whitespace-nowrap px-3 text-caption font-semibold",title:x?"Switch to expanded cards":"Switch to compact list","aria-label":x?"Expand Next Up queue":"Compact Next Up queue",children:x?"Expand":"Compact"}):null]})]}):null,Wt&&e.jsx("div",{className:"px-3 pt-2",children:e.jsx(qe,{initial:!1,mode:"wait",children:Re==="upgrade"&&B?e.jsx(V.div,{initial:{opacity:0,y:-4,scale:.99},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-4,scale:.99},transition:Ue,className:"rounded-xl border border-amber-200/25 bg-amber-200/10 px-3 py-2 text-caption text-amber-100",children:e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"rounded-full border border-amber-200/25 bg-amber-200/10 px-2 py-0.5 text-micro font-semibold uppercase tracking-[0.08em] text-amber-100/90",children:"Upgrade required"}),e.jsxs("span",{className:"truncate text-micro text-secondary",children:[ft(B.currentPlan)," →"," ",ft(B.requiredPlan)]})]}),e.jsx("div",{className:"mt-1 line-clamp-2 text-caption leading-snug text-amber-50/90",title:B.message,children:B.message}),J?e.jsx("div",{className:"mt-1 text-micro text-rose-50/85",children:J}):null]}),e.jsxs("div",{className:"flex flex-shrink-0 flex-col items-end gap-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>void cn({actions:B.actions,requiredPlan:B.requiredPlan}).catch(t=>N(ge(t instanceof Error?t.message:"","Checkout failed"))),className:"h-7 rounded-full border border-amber-200/25 bg-amber-200/15 px-3 text-micro font-semibold text-amber-50 transition-colors hover:bg-amber-200/20",children:"Upgrade"}),e.jsx("button",{type:"button",onClick:()=>void un({actions:B.actions}).catch(t=>N(ge(t instanceof Error?t.message:"","Portal failed"))),className:"h-7 rounded-full border border-strong bg-white/[0.04] px-3 text-micro font-semibold text-primary transition-colors hover:bg-white/[0.08]",children:"Billing"}),M&&e.jsx("button",{type:"button",onClick:M,className:"h-7 rounded-full border border-strong bg-white/[0.04] px-2.5 text-micro font-semibold text-primary transition-colors hover:bg-white/[0.08]",children:"Settings"})]}),(pt=B.actions)!=null&&pt.pricing?e.jsx("a",{href:B.actions.pricing,target:"_blank",rel:"noopener noreferrer",className:"text-micro text-secondary underline decoration-white/20 hover:text-primary",children:"View pricing"}):null]})]})},"upgrade"):Re==="error"&&ut?e.jsx(V.div,{initial:{opacity:0,y:-4},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},transition:Ue,className:"rounded-xl border border-red-400/25 bg-red-500/[0.08] px-3 py-2 text-caption text-red-100",children:ut},"error"):Re==="notice"&&J?e.jsx(V.div,{initial:{opacity:0,y:-4},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},transition:Ue,className:"rounded-xl border border-white/[0.1] bg-white/[0.03] px-3 py-2 text-caption text-primary",children:J},"notice"):null})}),e.jsxs("div",{className:`flex-1 space-y-2.5 overflow-y-auto overscroll-y-contain px-3 pb-3 ${g?"pt-1":"pt-2.5"}`,children:[!Q&&it>0?e.jsxs("div",{className:"flex flex-col gap-2.5 px-0.5 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-micro uppercase tracking-[0.08em] text-muted",children:I==="initiative"?"Initiatives":I==="milestone"?"Milestone slices":nt==="blocked"?"Needs attention":nt==="running"?"Running now":"Queue"}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-1.5",children:[ce>0?e.jsxs("span",{className:"chip text-micro",children:[ce," selected"]}):null,e.jsx("span",{className:ne("inline-flex min-w-[92px] text-micro text-muted transition-opacity",et&&!Q?"opacity-100":"opacity-0"),"aria-live":"polite",children:"refreshing…"}),U&&ee&&!x&&ce===0?e.jsx("span",{className:"text-micro text-muted",children:"Shift+select to pick ranges."}):null]})]}),e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-1.5 sm:justify-end",children:[_?e.jsx("button",{type:"button",onClick:()=>j(!x),className:"control-pill h-8 px-2.5 text-caption font-semibold",title:x?"Switch to expanded cards":"Switch to compact list","aria-label":x?"Expand Next Up queue":"Compact Next Up queue",children:x?"Expand":"Compact"}):null,mt?e.jsx("div",{className:"flex flex-wrap justify-end gap-1.5",children:xt}):null,!mt&&Y&&ee?e.jsxs("div",{ref:Oe,className:"relative",children:[e.jsxs("button",{type:"button",onClick:()=>je(t=>!t),className:"control-pill h-8 px-2.5 text-caption font-semibold","aria-haspopup":"menu","aria-expanded":ke,title:"Queue settings",children:[e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"opacity-85","aria-hidden":!0,children:[e.jsx("path",{d:"M4 6h16"}),e.jsx("path",{d:"M7 12h10"}),e.jsx("path",{d:"M10 18h4"})]}),e.jsx("span",{children:"Queue"})]}),ke?e.jsx("div",{className:"surface-tier-2 absolute right-0 top-[calc(100%+8px)] z-[280] w-[320px] max-w-[86vw] rounded-xl p-3 shadow-[0_18px_42px_rgba(0,0,0,0.46)] backdrop-blur-xl",children:e.jsxs("div",{className:"space-y-2.5",children:[U&&!x?e.jsxs("div",{children:[e.jsx("p",{className:"section-kicker",children:"Bulk actions"}),e.jsx("div",{className:"mt-1.5 flex flex-wrap items-center gap-1.5",children:xt})]}):null,M?e.jsx("button",{type:"button",onClick:()=>{je(!1),M()},className:"control-pill h-7 px-2.5 text-micro font-semibold",children:"Open settings"}):null]})}):null]}):null]})]}):null,Q?e.jsx(gn,{compact:x}):null,!Q&&!Vt&&!Be&&e.jsx(tn,{icon:"queue",headline:Ht,description:dt??"Create an initiative or add workstreams to populate the queue.",primaryAction:oe.length>0?{label:"Retry now",onClick:()=>{Te(!1),Pt()}}:void 0}),!Q&&I==="initiative"?e.jsx(qe,{initial:!1,children:Ke.map((t,a)=>{const o=t.items.find(q=>q.queueState!=="running"&&q.queueState!=="completed")??t.items[0]??null,r=Fe(t.initiativeTitle,t.initiativeId,"Initiative"),h=wt(t.queueState),v=yt(t.queueState),A=t.items.reduce((q,S)=>q+(S.sliceTaskCount??0),0);return e.jsxs(V.article,{layout:!0,initial:{opacity:0,y:8,scale:.99},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-4,scale:.99},transition:{duration:Z?.01:k.surfaceSwitch.duration,delay:Z?0:Math.min(a,k.listStaggerMaxItems)*k.listStaggerStep,ease:k.surfaceSwitch.ease},className:"rounded-2xl border border-white/[0.08] bg-white/[0.02] px-3 py-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Initiative"}),e.jsx("p",{className:"mt-0.5 truncate text-body font-semibold text-white",title:r,children:r})]}),e.jsx("span",{className:ne("inline-flex items-center rounded-full border px-2 py-0.5 text-[10px] font-semibold uppercase tracking-[0.08em]",v),children:h})]}),e.jsxs("p",{className:"mt-1 text-micro text-secondary",children:[t.workstreamCount," workstreams · ",A," tasks"]}),e.jsx("div",{className:"mt-2 space-y-1",children:t.items.slice(0,3).map((q,S)=>e.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-lg border border-white/[0.06] bg-black/[0.18] px-2.5 py-1.5 text-caption",children:[e.jsx("span",{className:"truncate text-white/84",children:P(q.workstreamTitle)}),e.jsxs("span",{className:"text-micro text-secondary",children:[q.sliceTaskCount??0," tasks"]})]},`${q.workstreamId}:${S}`))}),e.jsxs("div",{className:"mt-2.5 flex items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>T==null?void 0:T(t.initiativeId,t.initiativeTitle),className:"control-pill h-7 px-2.5 text-micro font-semibold",children:"Open"}),e.jsx("button",{type:"button",disabled:!o||K===`initiative:${t.initiativeId}`,onClick:()=>{o&&le(`initiative:${t.initiativeId}`,()=>ct(o),`Dispatched ${P(o.workstreamTitle)}.`)},className:"control-pill h-7 px-2.5 text-micro font-semibold disabled:opacity-45",children:"Dispatch"})]})]},`initiative-group:${t.initiativeId}`)})}):null,!Q&&I==="milestone"?e.jsx(qe,{initial:!1,children:De.map((t,a)=>{const o=t.item,r=`milestone:${t.workstreamId}:${t.milestoneId??"none"}`;return e.jsxs(V.article,{layout:!0,initial:{opacity:0,y:8,scale:.99},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-4,scale:.99},transition:{duration:Z?.01:k.surfaceSwitch.duration,delay:Z?0:Math.min(a,k.listStaggerMaxItems)*k.listStaggerStep,ease:k.surfaceSwitch.ease},className:"rounded-2xl border border-white/[0.08] bg-white/[0.02] px-3 py-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:[P(t.initiativeTitle)," · ",P(t.workstreamTitle)]}),e.jsx("p",{className:"mt-0.5 truncate text-body font-semibold text-white",title:t.milestoneTitle,children:P(t.milestoneTitle)})]}),e.jsx("span",{className:ne("inline-flex items-center rounded-full border px-2 py-0.5 text-[10px] font-semibold uppercase tracking-[0.08em]",yt(t.queueState)),children:wt(t.queueState)})]}),e.jsxs("p",{className:"mt-1 text-micro text-secondary",children:[t.taskCount," tasks in slice"]}),e.jsxs("div",{className:"mt-2.5 flex items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>T==null?void 0:T(t.initiativeId,t.initiativeTitle),className:"control-pill h-7 px-2.5 text-micro font-semibold",children:"Open"}),e.jsx("button",{type:"button",disabled:K===r||t.queueState==="running",onClick:()=>void le(r,()=>ct(o),h=>Xe(o,h)),className:"control-pill h-7 px-2.5 text-micro font-semibold disabled:opacity-45",children:t.queueState==="running"?"Running":"Start"})]})]},`${t.initiativeId}:${t.workstreamId}:${t.milestoneId??"none"}`)})}):null,!Q&&ee&&x?e.jsx(qe,{initial:!1,children:R.map((t,a)=>{const o=D(t),r=K===o,h=t.queueState==="running",v=t.nextTaskDueAt?kt(t.nextTaskDueAt):null,A=Fe(t.initiativeTitle,t.initiativeId,"Initiative"),q=Fe(t.workstreamTitle,t.workstreamId,"Workstream"),S=qt(t),te=t.nextTaskTitle?P(t.nextTaskTitle):null,Le=t.blockReason?P(t.blockReason):null,Pe=$t(t),Ie=Ft(t);return e.jsxs(V.article,{layout:!0,initial:{opacity:0,y:6,scale:.99},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-4,scale:.99},transition:{duration:Z?.01:k.surfaceSwitch.duration,delay:Z?0:Math.min(a,k.listStaggerMaxItems)*k.listStaggerStep,ease:k.surfaceSwitch.ease},className:"group relative overflow-visible rounded-2xl border border-white/[0.08] bg-white/[0.02] px-2.5 py-2 cursor-pointer transition-colors hover:border-white/[0.14]",onClick:()=>z==null?void 0:z(t),role:"button",tabIndex:0,onKeyDown:$=>{($.key==="Enter"||$.key===" ")&&($.preventDefault(),z==null||z(t))},children:[e.jsx("div",{className:`pointer-events-none absolute inset-x-2.5 top-0 h-px bg-gradient-to-r ${It(t.queueState)}`,"aria-hidden":!0}),e.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[e.jsx(jt,{name:Pe,hint:Mt(t,Pe),size:"xs"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[e.jsx($e,{type:"initiative",size:11,className:"flex-shrink-0 opacity-85"}),e.jsx("button",{type:"button",onClick:()=>T==null?void 0:T(t.initiativeId,t.initiativeTitle),className:"block min-w-0 flex-1 truncate text-left text-micro uppercase tracking-[0.08em] text-muted transition-colors hover:text-white/72",title:A,children:A}),S?e.jsx("span",{className:ne("inline-flex flex-shrink-0 items-center rounded-full border px-2 py-0.5 text-[9px] font-semibold uppercase tracking-[0.08em]",S.toneClass),title:S.longLabel,children:S.shortLabel}):null]}),e.jsxs("p",{className:"mt-0.5 flex min-w-0 items-center gap-1.5 text-caption font-semibold leading-snug text-white",title:q,children:[e.jsx($e,{type:"workstream",size:12,className:"flex-shrink-0 opacity-95"}),e.jsx("span",{className:"line-clamp-2",children:q})]}),te?e.jsxs("p",{className:"mt-0.5 line-clamp-2 text-micro leading-snug text-secondary",title:`${Je(t.queueState)}: ${te}${v?` · ${v}`:""}`,children:[Je(t.queueState),": ",te,v?` · ${v}`:""]}):e.jsx("p",{className:"mt-0.5 line-clamp-2 text-micro leading-snug text-secondary",title:Ze(t),children:Ze(t)}),Ie?e.jsxs("p",{className:"mt-0.5 text-micro text-muted",children:["Runner ",Ie]}):null,e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-1.5",children:[(()=>{const $=t.objectiveScore??t.compositeScore??null;if($==null)return null;const be=$>=80?"S":$>=60?"A":"B",ue=be==="S"?"border-[#BFFF00]/30 bg-[#BFFF00]/[0.12] text-[#d8ffa1]":be==="A"?"border-[#14B8A6]/30 bg-[#14B8A6]/[0.12] text-[#87FFE9]":"border-white/[0.12] bg-white/[0.05] text-white/60";return e.jsxs("span",{className:`chip text-[9px] font-semibold ${ue}`,children:[be,"-tier"]})})(),(()=>{const $=t.expectedValueUsd,be=t.sliceTaskCount??0,ue=[];return be>0&&ue.push(`${be} tasks`),typeof $=="number"&&$>0&&ue.push(`$${$.toFixed(2)}`),v&&ue.push(v),ue.length===0?null:e.jsx("span",{className:"text-micro text-muted",children:ue.join(" · ")})})()]})]})]}),(t.sliceTaskCount??0)>0&&e.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 h-[2px] rounded-b-2xl overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full",style:{width:`${Math.max(t.queueState==="completed"?100:t.queueState==="running"?50:15,4)}%`,background:`linear-gradient(90deg, ${bt.lime}, ${bt.teal})`,opacity:.6}})}),Le&&e.jsxs("div",{className:"mt-1.5 rounded-lg border border-red-400/24 bg-red-500/[0.08] px-2.5 py-1 text-micro text-red-100/85",children:["Blocked: ",Le]}),e.jsxs("div",{className:"mt-1.5 flex items-center gap-1.5",onClick:$=>$.stopPropagation(),children:[e.jsx("button",{type:"button",disabled:r||h,onClick:()=>void le(o,()=>_e({initiativeId:t.initiativeId,workstreamId:t.workstreamId,agentId:t.runnerAgentId}),$=>Xe(t,$)),className:"control-pill flex h-7 items-center justify-center px-2.5 text-micro font-semibold disabled:opacity-40",title:h?"Already running":"Start now",children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Ct,{className:"h-3 w-3 opacity-85"}),e.jsx("span",{children:h?"Running":"Start"})]})}),e.jsxs("div",{className:"relative ml-auto",children:[e.jsx("button",{type:"button",disabled:r,onClick:()=>ae($=>$===o?null:o),className:"control-pill flex h-7 items-center justify-center px-2.5 text-micro font-semibold disabled:opacity-40",title:"Queue actions",children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Tt,{className:"h-3 w-3 opacity-85"}),e.jsx("span",{children:"More"})]})}),me===o&&e.jsxs("div",{className:"absolute right-0 top-[calc(100%+6px)] z-[320] min-w-[178px] rounded-xl border border-white/[0.1] bg-[#080d14]/95 p-1.5 shadow-[0_16px_36px_rgba(0,0,0,0.42)] backdrop-blur",children:[e.jsx("button",{type:"button",onClick:()=>{ae(null),le(`${o}:top`,()=>X.move({initiativeId:t.initiativeId,workstreamId:t.workstreamId,placement:"top"}),`Moved ${q} to top of queue.`)},className:"flex h-8 w-full items-center rounded-md px-2.5 text-left text-caption text-primary transition-colors hover:bg-white/[0.08]",children:"Move to top"}),e.jsx("button",{type:"button",onClick:()=>{ae(null),le(`${o}:bottom`,()=>X.move({initiativeId:t.initiativeId,workstreamId:t.workstreamId,placement:"bottom"}),`Moved ${q} to bottom of queue.`)},className:"flex h-8 w-full items-center rounded-md px-2.5 text-left text-caption text-primary transition-colors hover:bg-white/[0.08]",children:"Move to bottom"}),e.jsx("button",{type:"button",onClick:()=>{ae(null),le(`${o}:auto`,async()=>(await X.move({initiativeId:t.initiativeId,workstreamId:t.workstreamId,placement:"top"}),tt({initiativeId:t.initiativeId,workstreamId:t.workstreamId,agentId:t.runnerAgentId,scope:"initiative"})),`Start+Auto enabled for ${A}.`)},className:"flex h-8 w-full items-center rounded-md px-2.5 text-left text-caption text-primary transition-colors hover:bg-white/[0.08]",children:"Start with auto"}),e.jsx("button",{type:"button",disabled:X.isRemoving,onClick:()=>{ae(null),lt(t)},className:"mt-1 flex h-8 w-full items-center rounded-md px-2.5 text-left text-caption text-red-100 transition-colors hover:bg-red-500/[0.12] disabled:opacity-45",children:"Remove from queue"})]})]})]})]},o)})}):!Q&&ee?e.jsx(rn,{axis:"y",values:fe,onReorder:t=>{We.current=t,at(t)},className:"space-y-2.5",children:fe.map(t=>ot.get(t)).filter(Boolean).map((t,a)=>e.jsx(wn,{item:t,index:a,actionKey:K,setNotice:N,setUpgradeGate:ie,onUpgradeGate:L,onOpenInitiative:T,onOpenSliceDetail:z,selected:O.has(D(t)),selectionEnabled:U,onToggleSelection:Qt,menuKey:me,setMenuKey:ae,playWorkstream:_e,startWorkstreamAutoContinue:tt,triagePlacement:ve,onPauseWorkstream:(o,r)=>X.stopTriage({initiativeId:o.initiativeId,workstreamId:o.workstreamId,placement:r,resetToTodo:!1}),onMoveWorkstream:(o,r)=>X.move({initiativeId:o.initiativeId,workstreamId:o.workstreamId,placement:r}),onCommitReorder:()=>void Dt().catch(()=>null),onDismiss:lt,runAction:le},D(t)))}):null]}),e.jsx("div",{className:"pointer-events-none absolute bottom-3 right-3 z-[250]",children:e.jsx(mn,{open:Gt,tone:"warning",title:"Limited signal",message:dt,autoDismissMs:6e3,onDismiss:()=>Te(!0)})})]})}function wn({item:n,index:s,actionKey:l,setNotice:i,setUpgradeGate:b,onUpgradeGate:g,onOpenInitiative:C,onOpenSliceDetail:y,selected:F,selectionEnabled:_,onToggleSelection:H,menuKey:T,setMenuKey:M,playWorkstream:L,startWorkstreamAutoContinue:z,triagePlacement:U,onPauseWorkstream:se,onMoveWorkstream:Y,onCommitReorder:re,onDismiss:p,runAction:m}){const c=an(),u=Nt(),[f,x]=d.useState(!1),j=`${n.initiativeId}:${n.workstreamId}`,J=l===j,N=n.queueState==="running",I=n.nextTaskDueAt?kt(n.nextTaskDueAt):null,ye=Fe(n.initiativeTitle,n.initiativeId,"Initiative"),de=Fe(n.workstreamTitle,n.workstreamId,"Workstream"),we=qt(n),ve=n.nextTaskTitle?P(n.nextTaskTitle):null,B=n.blockReason?P(n.blockReason):null,ie=$t(n),K=Ft(n);return e.jsx(on,{value:j,id:j,dragListener:!1,dragControls:c,onDragStart:()=>x(!0),onDragEnd:()=>{x(!1),re()},whileDrag:{scale:1.02,boxShadow:"0 20px 48px rgba(0,0,0,0.5), 0 0 0 1px rgba(191,255,0,0.15)",zIndex:50,cursor:"grabbing"},className:"relative",children:e.jsxs(V.article,{layout:!0,initial:{opacity:0,y:12,scale:.97},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-8,scale:.98},transition:{duration:u?.01:k.surfaceSwitch.duration,ease:k.surfaceSwitch.ease,delay:u?0:Math.min(s,k.listStaggerMaxItems)*k.listStaggerStep,opacity:{duration:u?.01:k.surfaceSwitch.duration,ease:k.surfaceSwitch.ease}},className:"group relative overflow-visible rounded-2xl border border-white/[0.08] bg-white/[0.02] px-3 py-3 cursor-pointer transition-colors hover:border-white/[0.14]",onClick:()=>y==null?void 0:y(n),role:"button",tabIndex:0,onKeyDown:w=>{(w.key==="Enter"||w.key===" ")&&(w.preventDefault(),y==null||y(n))},children:[e.jsx("div",{className:`pointer-events-none absolute inset-x-3 top-0 h-px bg-gradient-to-r ${It(n.queueState)}`,"aria-hidden":!0}),e.jsx("div",{className:"flex items-start justify-between gap-2.5",children:e.jsxs("div",{className:"min-w-0 flex flex-1 items-start gap-2.5",children:[e.jsxs("div",{className:"relative h-8 w-8 flex-shrink-0",children:[e.jsx("div",{className:`absolute inset-0 transition-[opacity,transform] duration-200 ease-out ${_?F?"opacity-0 scale-90":"opacity-100 scale-100 group-hover:opacity-0 group-hover:scale-90 group-focus-within:opacity-0 group-focus-within:scale-90":"opacity-100 scale-100"}`,children:e.jsx(jt,{name:ie,hint:Mt(n,ie),size:"sm"})}),_?e.jsx("button",{type:"button",role:"checkbox","aria-checked":F,"aria-label":"Select queue row",title:F?"Selected (Shift+click for range)":"Select (Shift+click for range)",onClick:w=>{w.stopPropagation(),H(j,!F,w.shiftKey)},onMouseDown:w=>w.stopPropagation(),onKeyDown:w=>w.stopPropagation(),className:`absolute inset-0 flex items-center justify-center rounded-full border transition-[opacity,transform,background-color,border-color,color] duration-200 ease-out ${F?"opacity-100 scale-100 border-[#BFFF00]/40 bg-[#BFFF00]/18 text-[#E1FFB2]":"opacity-0 scale-90 border-white/[0.24] bg-black/55 text-white/78 group-hover:opacity-100 group-hover:scale-100 group-focus-within:opacity-100 group-focus-within:scale-100 hover:bg-black/62"}`,children:e.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center rounded-full border border-current/45 bg-black/30",children:F?e.jsx("svg",{viewBox:"0 0 16 16",className:"h-2.5 w-2.5",fill:"none","aria-hidden":!0,children:e.jsx("path",{d:"M3.2 8.3 6.2 11l6.6-6.1",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}):null})}):null]}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[e.jsx($e,{type:"initiative",size:11,className:"flex-shrink-0 opacity-85"}),e.jsx("button",{type:"button",onClick:()=>C==null?void 0:C(n.initiativeId,n.initiativeTitle),className:"block min-w-0 flex-1 truncate text-left text-micro uppercase tracking-[0.08em] text-muted transition-colors hover:text-white/72",title:ye,children:ye}),we?e.jsx("span",{className:ne("inline-flex flex-shrink-0 items-center rounded-full border px-2 py-0.5 text-[9px] font-semibold uppercase tracking-[0.08em]",we.toneClass),title:we.longLabel,children:we.shortLabel}):null]}),e.jsxs("div",{className:"mt-0.5 flex min-w-0 items-start gap-1.5",children:[e.jsx($e,{type:"workstream",size:12,className:"mt-[3px] flex-shrink-0 opacity-95"}),e.jsx("p",{className:"min-w-0 line-clamp-2 text-body font-semibold leading-snug text-white",title:de,children:de})]}),e.jsxs("div",{className:"mt-1.5 flex items-center gap-2 text-micro text-secondary",children:[e.jsx("span",{className:"rounded-full border border-strong bg-white/[0.03] px-2 py-0.5 text-micro uppercase tracking-[0.08em] text-secondary",children:"Runner"}),e.jsxs("span",{className:"truncate text-white/68",children:[ie,K?` · ${K}`:""]})]})]})]})}),e.jsx("div",{className:"mt-2 rounded-lg border border-white/[0.07] bg-black/[0.18] px-2.5 py-2 text-caption text-white/68",children:ve?e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-1 text-micro uppercase tracking-[0.08em] text-white/44",children:[e.jsx($e,{type:"task",size:10,className:"flex-shrink-0 opacity-80"}),e.jsx("span",{children:Je(n.queueState)}),I?e.jsxs("span",{className:"truncate text-micro normal-case tracking-normal text-muted",children:["· ",I]}):null]}),e.jsx("p",{className:"line-clamp-2 break-words text-caption leading-snug text-white/84",title:ve,children:ve})]}):e.jsx("span",{className:"text-secondary",children:Ze(n)})}),B&&e.jsxs("div",{className:"mt-1.5 rounded-lg border border-red-400/24 bg-red-500/[0.08] px-2.5 py-1 text-micro text-red-100/85",children:["Blocked: ",B]}),e.jsxs("div",{className:"mt-2 flex items-center gap-1.5",onClick:w=>w.stopPropagation(),children:[e.jsx("button",{type:"button",disabled:J||N,onClick:()=>void m(j,()=>L({initiativeId:n.initiativeId,workstreamId:n.workstreamId,agentId:n.runnerAgentId}),w=>Xe(n,w)),className:"control-pill flex h-7 items-center justify-center px-2.5 text-micro font-semibold disabled:opacity-40",title:N?"Already running":"Start this workstream now",children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Ct,{className:"h-3 w-3 opacity-85"}),e.jsx("span",{children:N?"Running":"Start"})]})}),e.jsxs("button",{type:"button",onPointerDown:w=>c.start(w),"aria-label":"Drag to reorder",title:f?"Reordering":"Drag to reorder",className:`control-pill flex h-7 items-center justify-center gap-1 px-2 text-micro font-semibold transition-colors ${f?"border-[#BFFF00]/35 bg-[#BFFF00]/14 text-[#E1FFB2] cursor-grabbing":"cursor-grab hover:bg-white/[0.08] hover:text-bright"}`,children:[f?e.jsx(pn,{className:"h-3.5 w-3.5 opacity-90"}):e.jsx(xn,{className:"h-3.5 w-3.5 opacity-90"}),e.jsx("span",{children:f?"Reordering":"Drag"})]}),e.jsxs("div",{className:"relative ml-auto",children:[e.jsx("button",{type:"button",disabled:J,onClick:()=>M(w=>w===j?null:j),className:"control-pill flex h-7 items-center justify-center px-2.5 text-micro font-semibold disabled:opacity-40",title:"Queue actions",children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Tt,{className:"h-3 w-3 opacity-85"}),e.jsx("span",{children:"More"})]})}),T===j&&e.jsxs("div",{className:"absolute right-0 top-[calc(100%+6px)] z-[320] min-w-[198px] rounded-xl border border-white/[0.1] bg-[#080d14]/95 p-1.5 shadow-[0_16px_36px_rgba(0,0,0,0.42)] backdrop-blur",children:[e.jsx("button",{type:"button",onClick:()=>{M(null),m(`${j}:top`,()=>Y(n,"top"),`Moved ${de} to top of queue.`)},className:"flex h-8 w-full items-center rounded-md px-2.5 text-left text-caption text-primary transition-colors hover:bg-white/[0.08]",children:"Move to top"}),e.jsx("button",{type:"button",onClick:()=>{M(null),m(`${j}:bottom`,()=>Y(n,"bottom"),`Moved ${de} to bottom of queue.`)},className:"flex h-8 w-full items-center rounded-md px-2.5 text-left text-caption text-primary transition-colors hover:bg-white/[0.08]",children:"Move to bottom"}),e.jsx("button",{type:"button",onClick:()=>{M(null),m(`${j}:auto`,async()=>(await Y(n,"top"),z({initiativeId:n.initiativeId,workstreamId:n.workstreamId,agentId:n.runnerAgentId,scope:"initiative"})),`Start+Auto enabled for ${ye}.`)},className:"flex h-8 w-full items-center rounded-md px-2.5 text-left text-caption text-primary transition-colors hover:bg-white/[0.08]",children:"Start with auto"}),N?e.jsx("button",{type:"button",onClick:()=>{M(null),m(`${j}:pause`,()=>se(n,U),`Paused ${de}.`)},className:"mt-1 flex h-8 w-full items-center rounded-md px-2.5 text-left text-caption text-primary transition-colors hover:bg-white/[0.08]",children:"Pause run"}):null,e.jsx("button",{type:"button",disabled:J||N,onClick:()=>{M(null),p(n)},className:"mt-1 flex h-8 w-full items-center rounded-md px-2.5 text-left text-caption text-red-100 transition-colors hover:bg-red-500/[0.12] disabled:opacity-45",children:"Remove from queue"})]})]})]})]})})}const Sn=Object.freeze(Object.defineProperty({__proto__:null,NextUpPanel:yn},Symbol.toStringTag,{value:"Module"}));export{mn as I,yn as N,Sn as a,cn as o,ln as u};
|
|
Binary file
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as s,j as t}from"./cNrhgGc1.js";import{r as ke}from"./Cn07669c.js";import"./C-KIc3Wc.js";import"./BJgZIVUQ.js";import"./CxQ08qFN.js";const I={PREVIEW:"orgx_orchestrator_preview",APPLY:"orgx_orchestrator_apply",STATUS:"orgx_orchestrator_status"};function l(p){if(typeof p!="string")return null;const n=p.trim();return n.length?n:null}function Ce(p){if(!p.trim())return{};const n=JSON.parse(p);return!n||typeof n!="object"||Array.isArray(n)?{}:n}function Q(p){const n=l(p.transcript)??l(p.text)??l(p.delta??null);if(n)return n;const h=p.item&&typeof p.item=="object"?p.item:null,v=Array.isArray(h==null?void 0:h.content)?h==null?void 0:h.content:[];for(const y of v){if(!y||typeof y!="object")continue;const f=l(y.transcript)??l(y.text);if(f)return f}return null}function Se(p){const n=p.response&&typeof p.response=="object"?p.response:null,h=Array.isArray(n==null?void 0:n.output)?n==null?void 0:n.output:[],v=[];for(const y of h){if(!y||typeof y!="object")continue;const f=y;if(f.type!=="function_call")continue;const C=l(f.name),S=l(f.call_id)??l(f.id),A=typeof f.arguments=="string"?f.arguments:"{}";!C||!S||v.push({callId:S,name:C,arguments:A})}return v}function Ae(p){const n=Number.isFinite(p)?p*100:0;return`${Math.max(0,Math.min(100,Math.round(n)))}%`}const fe=[{type:"function",name:I.PREVIEW,description:"Preview orchestrator actions from a natural language command. Use this before apply.",parameters:{type:"object",additionalProperties:!1,properties:{input:{type:"string",description:"Natural language command from the operator."},workspace_id:{type:"string",description:"Optional OrgX workspace/command_center id."}},required:["input"]}},{type:"function",name:I.APPLY,description:"Apply selected action ids from a previewed command after user confirmation.",parameters:{type:"object",additionalProperties:!1,properties:{command_id:{type:"string",description:"Command id from preview response."},confirmed_action_ids:{type:"array",items:{type:"string"},description:"Optional subset of action ids to apply. Omit to apply all."},workspace_id:{type:"string",description:"Optional OrgX workspace/command_center id."}},required:["command_id"]}},{type:"function",name:I.STATUS,description:"Get latest status for a previously created command.",parameters:{type:"object",additionalProperties:!1,properties:{command_id:{type:"string",description:"Command id from preview/apply response."}},required:["command_id"]}}];function Oe({open:p,selectedWorkspaceId:n,onClose:h}){var le,de,pe;const[v,y]=s.useState(!1),[f,C]=s.useState(!1),[S,A]=s.useState(!1),[xe,he]=s.useState("gpt-realtime-1.5"),[$,Z]=s.useState(""),[W,M]=s.useState(""),[o,P]=s.useState(null),[T,X]=s.useState([]),[ee,te]=s.useState(!1),[re,oe]=s.useState(!1),[se,b]=s.useState(null),[ne,z]=s.useState([]),G=s.useRef(null),D=s.useRef(null),O=s.useRef(null),H=s.useRef(null),E=s.useRef(""),J=s.useRef(new Set),R=s.useCallback(e=>{z(r=>[e,...r].slice(0,10))},[]),N=s.useCallback(()=>{A(!1),C(!1),J.current=new Set;const e=D.current;if(e)try{e.close()}catch{}D.current=null;const r=G.current;if(r)try{r.close()}catch{}G.current=null;const a=O.current;if(a)for(const m of a.getTracks())try{m.stop()}catch{}O.current=null;const d=H.current;if(d){try{const m=d.srcObject;m==null||m.getTracks().forEach(i=>i.stop())}catch{}try{d.pause()}catch{}d.srcObject=null}H.current=null},[]);s.useEffect(()=>{p||(N(),b(null),M(""),z([]),E.current="")},[N,p]),s.useEffect(()=>()=>N(),[N]);const g=s.useCallback(e=>{const r=D.current;!r||r.readyState!=="open"||r.send(JSON.stringify(e))},[]),ae=s.useCallback(async e=>{const r=await fetch(e),a=await r.json().catch(()=>({}));if(!r.ok)throw new Error(a&&typeof a=="object"&&"error"in a&&a.error||`Request failed: ${r.status}`);return a},[]),j=s.useCallback(async(e,r)=>{const a=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)}),d=await a.json().catch(()=>({}));if(!a.ok)throw new Error(d&&typeof d=="object"&&"error"in d&&d.error||`Request failed: ${a.status}`);return d},[]),L=s.useCallback(async e=>{if(!J.current.has(e.callId)){J.current.add(e.callId);try{const r=Ce(e.arguments);let a={ok:!1,error:"Unsupported tool call."};if(e.name===I.PREVIEW){const d=l(r.input);if(!d)throw new Error("Preview tool call requires input.");const m=await j("/orgx/api/orchestrator/commands/preview",{input:d,workspace_id:l(r.workspace_id)??n??void 0});if(!m.command)throw new Error(m.error??"Preview command failed.");P(m.command),X(m.command.proposedActions.map(i=>i.actionId)),a={ok:!0,command:m.command}}else if(e.name===I.APPLY){const d=l(r.command_id);if(!d)throw new Error("Apply tool call requires command_id.");const m=Array.isArray(r.confirmed_action_ids)?r.confirmed_action_ids.filter(F=>typeof F=="string"):void 0,i=await j("/orgx/api/orchestrator/commands/apply",{command_id:d,confirmed_action_ids:m,workspace_id:l(r.workspace_id)??n??void 0});if(!i.command)throw new Error(i.error??"Apply command failed.");P(i.command),a={ok:!0,command:i.command}}else if(e.name===I.STATUS){const d=l(r.command_id);if(!d)throw new Error("Status tool call requires command_id.");const m=await ae(`/orgx/api/orchestrator/commands/${encodeURIComponent(d)}`);if(!m.command)throw new Error(m.error??"Command status unavailable.");P(m.command),a={ok:!0,command:m.command}}g({type:"conversation.item.create",item:{type:"function_call_output",call_id:e.callId,output:JSON.stringify(a)}}),g({type:"response.create"}),R(`Tool executed: ${e.name}`)}catch(r){const a=r instanceof Error?r.message:"Tool execution failed.";b(a),g({type:"conversation.item.create",item:{type:"function_call_output",call_id:e.callId,output:JSON.stringify({ok:!1,error:a})}}),g({type:"response.create"}),R(`Tool failed: ${e.name}`)}}},[ae,R,j,n,g]),ye=s.useCallback(async()=>{var e,r,a,d,m;if(!((e=navigator.mediaDevices)!=null&&e.getUserMedia)){b("Microphone capture is unavailable in this browser/runtime.");return}b(null),y(!0),z([]);try{const i=await j("/orgx/api/realtime/session",{workspace_id:n??void 0,model:"gpt-realtime-1.5",voice:"alloy",tool_choice:"auto",tools:fe,instructions:"You are the OrgX realtime orchestrator copilot. Use tools for state-changing operations. Before applying actions, state the plan concisely."});if(!(i!=null&&i.session))throw new Error((i==null?void 0:i.error)??"Failed to create realtime session.");const F=l((r=i==null?void 0:i.session)==null?void 0:r.model)??l((a=i==null?void 0:i.defaults)==null?void 0:a.model)??"gpt-realtime-1.5";he(F);const me=l((m=(d=i==null?void 0:i.session)==null?void 0:d.client_secret)==null?void 0:m.value);if(!me)throw new Error("Realtime session is missing client_secret.");const U=await navigator.mediaDevices.getUserMedia({audio:!0});O.current=U;for(const _ of U.getAudioTracks())_.enabled=!1;const k=new RTCPeerConnection;G.current=k,U.getTracks().forEach(_=>k.addTrack(_,U));const q=document.createElement("audio");q.autoplay=!0,H.current=q,k.ontrack=_=>{const[u]=_.streams;u&&(q.srcObject=u,q.play().catch(()=>{}))};const V=k.createDataChannel("oai-events");D.current=V,V.onmessage=_=>{try{const u=JSON.parse(String(_.data)),x=l(u.type)??"";if(x==="error"){const c=u.error&&typeof u.error=="object"?u.error:null,w=l(c==null?void 0:c.message)??l(u.message)??"Realtime session error.";b(w),R(`Error: ${w}`);return}if(x==="conversation.item.input_audio_transcription.completed"){const c=Q(u);c&&Z(c)}if(x==="response.output_text.delta"||x==="response.text.delta"||x==="response.output_audio_transcript.delta"||x==="response.audio_transcript.delta"){const c=l(u.delta)??Q(u);c&&(E.current=`${E.current}${c}`,M(E.current))}if(x==="response.output_text.done"||x==="response.text.done"||x==="response.output_audio_transcript.done"||x==="response.audio_transcript.done"){const c=Q(u);c&&(E.current=c,M(c))}if(x==="response.function_call_arguments.done"){const c=l(u.call_id),w=l(u.name);if(c&&w){const B=typeof u.arguments=="string"?u.arguments:"{}";L({callId:c,name:w,arguments:B})}}if(x==="response.output_item.done"){const c=u.item&&typeof u.item=="object"?u.item:null;if((c==null?void 0:c.type)==="function_call"){const w=l(c.call_id)??l(c.id),B=l(c.name);if(w&&B){const Ne=typeof c.arguments=="string"?c.arguments:"{}";L({callId:w,name:B,arguments:Ne})}}}if(x==="response.done"){const c=Se(u);for(const w of c)L(w)}}catch{}},V.onopen=()=>{C(!0),g({type:"session.update",session:{tools:fe,tool_choice:"auto"}}),R("Realtime connected")},V.onclose=()=>{C(!1),A(!1)};const ue=await k.createOffer();await k.setLocalDescription(ue);const Y=await fetch(`https://api.openai.com/v1/realtime?model=${encodeURIComponent(F)}`,{method:"POST",headers:{Authorization:`Bearer ${me}`,"Content-Type":"application/sdp"},body:ue.sdp??""});if(!Y.ok){const _=await Y.text().catch(()=>Y.statusText);throw new Error(`Realtime SDP negotiation failed: ${_}`)}const ve=await Y.text();await k.setRemoteDescription({type:"answer",sdp:ve})}catch(i){N(),b(i instanceof Error?i.message:"Failed to connect realtime session.")}finally{y(!1)}},[N,L,R,j,n]),ie=s.useCallback(()=>{if(!f)return;const e=O.current;if(e){for(const r of e.getAudioTracks())r.enabled=!0;E.current="",M(""),A(!0),g({type:"input_audio_buffer.clear"})}},[f,g]),K=s.useCallback(()=>{const e=O.current;if(e)for(const r of e.getAudioTracks())r.enabled=!1;A(!1),g({type:"input_audio_buffer.commit"}),g({type:"response.create"})},[g]),ge=s.useCallback(async()=>{const e=$.trim();if(e){te(!0),b(null);try{const r=await j("/orgx/api/orchestrator/commands/preview",{input:e,workspace_id:n??void 0});if(!r.command)throw new Error(r.error??"Failed to preview command.");P(r.command),X(r.command.proposedActions.map(a=>a.actionId))}catch(r){b(r instanceof Error?r.message:"Failed to preview command.")}finally{te(!1)}}},[$,j,n]),be=s.useCallback(async()=>{if(o!=null&&o.id){oe(!0),b(null);try{const e=await j("/orgx/api/orchestrator/commands/apply",{command_id:o.id,confirmed_action_ids:T,workspace_id:n??void 0});if(!e.command)throw new Error(e.error??"Failed to apply command.");P(e.command)}catch(e){b(e instanceof Error?e.message:"Failed to apply command.")}finally{oe(!1)}}},[o==null?void 0:o.id,j,T,n]),ce=T.length,we=(((le=o==null?void 0:o.proposedActions)==null?void 0:le.length)??0)>0,je=!!(o!=null&&o.id)&&ce>0&&!re,_e=s.useMemo(()=>{const e=(o==null?void 0:o.status)??"draft";return e==="completed"?"text-lime":e==="completed_with_errors"||e==="failed"?"text-amber-300":e==="applying"?"text-teal":"text-secondary"},[o==null?void 0:o.status]);return t.jsxs(ke,{open:p,onClose:h,maxWidth:"max-w-5xl",fitContent:!0,closeOnEscapeWhenTyping:!1,children:[t.jsx("div",{className:"border-b border-strong px-4 py-3",children:t.jsxs("div",{className:"flex items-start justify-between gap-3",children:[t.jsxs("div",{children:[t.jsx("p",{className:"text-caption uppercase tracking-[0.14em] text-secondary",children:"Realtime Orchestrator"}),t.jsx("h2",{className:"text-heading font-semibold text-white",children:"GPT Realtime 1.5"}),t.jsx("p",{className:"text-micro text-secondary",children:"Voice + tool-calls for initiative launch, decision resolution, and Next Up control."})]}),t.jsx("button",{type:"button",onClick:h,className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption text-secondary transition-colors hover:bg-white/[0.08] hover:text-white",children:"Close"})]})}),t.jsxs("div",{className:"grid gap-4 px-4 pb-4 pt-3 lg:grid-cols-[1.12fr_1fr]",children:[t.jsxs("section",{className:"space-y-3",children:[t.jsxs("div",{className:"rounded-xl border border-strong bg-white/[0.02] p-3",children:[t.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[t.jsx("span",{className:"text-caption uppercase tracking-[0.12em] text-secondary",children:"Session"}),t.jsx("span",{className:"text-micro text-secondary",children:xe})]}),t.jsx("div",{className:"flex flex-wrap items-center gap-2",children:f?t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",onMouseDown:ie,onMouseUp:K,onMouseLeave:()=>{S&&K()},onTouchStart:e=>{e.preventDefault(),ie()},onTouchEnd:e=>{e.preventDefault(),K()},className:`rounded-full border px-3 py-1.5 text-caption font-semibold transition-colors ${S?"border-teal/45 bg-teal/[0.16] text-teal":"border-white/[0.2] bg-white/[0.04] text-primary hover:bg-white/[0.1]"}`,children:S?"Listening… release to send":"Hold to talk"}),t.jsx("button",{type:"button",onClick:N,className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption text-secondary transition-colors hover:bg-white/[0.08] hover:text-primary",children:"Disconnect"})]}):t.jsx("button",{type:"button",disabled:v,onClick:()=>void ye(),className:"rounded-full border border-lime/35 bg-lime/[0.12] px-3 py-1.5 text-caption font-semibold text-lime transition-colors hover:bg-lime/[0.2] disabled:cursor-not-allowed disabled:opacity-60",children:v?"Connecting…":"Connect Realtime"})}),ne.length>0?t.jsx("div",{className:"mt-3 rounded-lg border border-strong bg-black/20 p-2",children:ne.map((e,r)=>t.jsx("p",{className:"text-micro text-secondary",children:e},`${e}-${r}`))}):null]}),t.jsxs("div",{className:"rounded-xl border border-strong bg-white/[0.02] p-3",children:[t.jsx("label",{className:"mb-2 block text-caption uppercase tracking-[0.12em] text-secondary",children:"Command Input"}),t.jsx("textarea",{value:$,onChange:e=>Z(e.target.value),rows:4,"data-modal-autofocus":"true",placeholder:"Example: create initiative called AI Readiness Audit for this workspace",className:"w-full rounded-lg border border-strong bg-[#040912] px-3 py-2 text-body text-primary placeholder:text-secondary focus:border-lime/35 focus:outline-none"}),W?t.jsxs("p",{className:"mt-2 text-caption text-secondary",children:["Assistant: ",t.jsx("span",{className:"text-primary",children:W})]}):null,t.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[t.jsx("button",{type:"button",disabled:ee||$.trim().length===0,onClick:()=>void ge(),className:"rounded-full border border-teal/35 bg-teal/[0.12] px-3 py-1.5 text-caption font-semibold text-teal transition-colors hover:bg-teal/[0.2] disabled:cursor-not-allowed disabled:opacity-60",children:ee?"Previewing…":"Preview Actions"}),t.jsx("button",{type:"button",disabled:!je,onClick:()=>void be(),className:"rounded-full border border-lime/35 bg-lime/[0.12] px-3 py-1.5 text-caption font-semibold text-lime transition-colors hover:bg-lime/[0.2] disabled:cursor-not-allowed disabled:opacity-60",children:re?"Applying…":`Apply (${ce})`})]})]})]}),t.jsxs("section",{className:"space-y-3",children:[t.jsxs("div",{className:"rounded-xl border border-strong bg-white/[0.02] p-3",children:[t.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[t.jsx("span",{className:"text-caption uppercase tracking-[0.12em] text-secondary",children:"Command Status"}),t.jsx("span",{className:`text-caption font-semibold ${_e}`,children:(o==null?void 0:o.status)??"idle"})]}),t.jsx("p",{className:"text-body text-primary",children:(o==null?void 0:o.humanSummary)??"Preview a command or use voice to trigger tool calls."}),(de=o==null?void 0:o.riskFlags)!=null&&de.length?t.jsxs("p",{className:"mt-2 text-caption text-amber-200",children:["Risk flags: ",o.riskFlags.join(", ")]}):null]}),t.jsxs("div",{className:"max-h-[360px] space-y-2 overflow-y-auto rounded-xl border border-strong bg-white/[0.02] p-3",children:[t.jsx("p",{className:"text-caption uppercase tracking-[0.12em] text-secondary",children:"Proposed Actions"}),we?o.proposedActions.map(e=>{const r=T.includes(e.actionId);return t.jsx("label",{className:"block rounded-lg border border-strong bg-[#040912] p-2 text-body",children:t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsx("input",{type:"checkbox",checked:r,onChange:a=>{const d=a.target.checked?[...T,e.actionId]:T.filter(m=>m!==e.actionId);X(d)},className:"mt-1"}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:"font-semibold text-primary",children:e.type}),t.jsx("p",{className:"text-caption text-secondary",children:e.reason}),t.jsxs("p",{className:"text-micro text-secondary",children:["confidence ",Ae(e.confidence)," • impact ",e.blockingImpact]})]})]})},e.actionId)}):t.jsx("p",{className:"text-body text-secondary",children:"No actions inferred yet."})]}),(((pe=o==null?void 0:o.results)==null?void 0:pe.length)??0)>0?t.jsxs("div",{className:"max-h-[220px] space-y-2 overflow-y-auto rounded-xl border border-strong bg-white/[0.02] p-3",children:[t.jsx("p",{className:"text-caption uppercase tracking-[0.12em] text-secondary",children:"Apply Results"}),o.results.map(e=>t.jsxs("div",{className:`rounded-lg border p-2 text-body ${e.ok?"border-lime/30 bg-lime/[0.08] text-lime":"border-amber-400/35 bg-amber-500/[0.12] text-amber-100"}`,children:[t.jsx("p",{className:"font-semibold",children:e.type}),t.jsx("p",{className:"text-caption",children:e.message}),e.error?t.jsxs("p",{className:"text-micro text-amber-200",children:["error: ",e.error]}):null]},`${e.actionId}-${e.type}`))]}):null]})]}),se?t.jsx("div",{className:"border-t border-amber-500/30 bg-amber-500/[0.12] px-4 py-2 text-caption text-amber-100",children:se}):null]})}export{Oe as RealtimeOrchestratorModal};
|
|
1
|
+
import{r as s,j as t}from"./cNrhgGc1.js";import{w as ke}from"./CPjsbbgZ.js";import"./C-KIc3Wc.js";import"./BJgZIVUQ.js";import"./CxQ08qFN.js";const I={PREVIEW:"orgx_orchestrator_preview",APPLY:"orgx_orchestrator_apply",STATUS:"orgx_orchestrator_status"};function l(p){if(typeof p!="string")return null;const n=p.trim();return n.length?n:null}function Ce(p){if(!p.trim())return{};const n=JSON.parse(p);return!n||typeof n!="object"||Array.isArray(n)?{}:n}function Q(p){const n=l(p.transcript)??l(p.text)??l(p.delta??null);if(n)return n;const h=p.item&&typeof p.item=="object"?p.item:null,v=Array.isArray(h==null?void 0:h.content)?h==null?void 0:h.content:[];for(const y of v){if(!y||typeof y!="object")continue;const f=l(y.transcript)??l(y.text);if(f)return f}return null}function Se(p){const n=p.response&&typeof p.response=="object"?p.response:null,h=Array.isArray(n==null?void 0:n.output)?n==null?void 0:n.output:[],v=[];for(const y of h){if(!y||typeof y!="object")continue;const f=y;if(f.type!=="function_call")continue;const C=l(f.name),S=l(f.call_id)??l(f.id),A=typeof f.arguments=="string"?f.arguments:"{}";!C||!S||v.push({callId:S,name:C,arguments:A})}return v}function Ae(p){const n=Number.isFinite(p)?p*100:0;return`${Math.max(0,Math.min(100,Math.round(n)))}%`}const fe=[{type:"function",name:I.PREVIEW,description:"Preview orchestrator actions from a natural language command. Use this before apply.",parameters:{type:"object",additionalProperties:!1,properties:{input:{type:"string",description:"Natural language command from the operator."},workspace_id:{type:"string",description:"Optional OrgX workspace/command_center id."}},required:["input"]}},{type:"function",name:I.APPLY,description:"Apply selected action ids from a previewed command after user confirmation.",parameters:{type:"object",additionalProperties:!1,properties:{command_id:{type:"string",description:"Command id from preview response."},confirmed_action_ids:{type:"array",items:{type:"string"},description:"Optional subset of action ids to apply. Omit to apply all."},workspace_id:{type:"string",description:"Optional OrgX workspace/command_center id."}},required:["command_id"]}},{type:"function",name:I.STATUS,description:"Get latest status for a previously created command.",parameters:{type:"object",additionalProperties:!1,properties:{command_id:{type:"string",description:"Command id from preview/apply response."}},required:["command_id"]}}];function Oe({open:p,selectedWorkspaceId:n,onClose:h}){var le,de,pe;const[v,y]=s.useState(!1),[f,C]=s.useState(!1),[S,A]=s.useState(!1),[xe,he]=s.useState("gpt-realtime-1.5"),[$,Z]=s.useState(""),[W,M]=s.useState(""),[o,P]=s.useState(null),[T,X]=s.useState([]),[ee,te]=s.useState(!1),[re,oe]=s.useState(!1),[se,b]=s.useState(null),[ne,z]=s.useState([]),G=s.useRef(null),D=s.useRef(null),O=s.useRef(null),H=s.useRef(null),E=s.useRef(""),J=s.useRef(new Set),R=s.useCallback(e=>{z(r=>[e,...r].slice(0,10))},[]),N=s.useCallback(()=>{A(!1),C(!1),J.current=new Set;const e=D.current;if(e)try{e.close()}catch{}D.current=null;const r=G.current;if(r)try{r.close()}catch{}G.current=null;const a=O.current;if(a)for(const m of a.getTracks())try{m.stop()}catch{}O.current=null;const d=H.current;if(d){try{const m=d.srcObject;m==null||m.getTracks().forEach(i=>i.stop())}catch{}try{d.pause()}catch{}d.srcObject=null}H.current=null},[]);s.useEffect(()=>{p||(N(),b(null),M(""),z([]),E.current="")},[N,p]),s.useEffect(()=>()=>N(),[N]);const g=s.useCallback(e=>{const r=D.current;!r||r.readyState!=="open"||r.send(JSON.stringify(e))},[]),ae=s.useCallback(async e=>{const r=await fetch(e),a=await r.json().catch(()=>({}));if(!r.ok)throw new Error(a&&typeof a=="object"&&"error"in a&&a.error||`Request failed: ${r.status}`);return a},[]),j=s.useCallback(async(e,r)=>{const a=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)}),d=await a.json().catch(()=>({}));if(!a.ok)throw new Error(d&&typeof d=="object"&&"error"in d&&d.error||`Request failed: ${a.status}`);return d},[]),L=s.useCallback(async e=>{if(!J.current.has(e.callId)){J.current.add(e.callId);try{const r=Ce(e.arguments);let a={ok:!1,error:"Unsupported tool call."};if(e.name===I.PREVIEW){const d=l(r.input);if(!d)throw new Error("Preview tool call requires input.");const m=await j("/orgx/api/orchestrator/commands/preview",{input:d,workspace_id:l(r.workspace_id)??n??void 0});if(!m.command)throw new Error(m.error??"Preview command failed.");P(m.command),X(m.command.proposedActions.map(i=>i.actionId)),a={ok:!0,command:m.command}}else if(e.name===I.APPLY){const d=l(r.command_id);if(!d)throw new Error("Apply tool call requires command_id.");const m=Array.isArray(r.confirmed_action_ids)?r.confirmed_action_ids.filter(F=>typeof F=="string"):void 0,i=await j("/orgx/api/orchestrator/commands/apply",{command_id:d,confirmed_action_ids:m,workspace_id:l(r.workspace_id)??n??void 0});if(!i.command)throw new Error(i.error??"Apply command failed.");P(i.command),a={ok:!0,command:i.command}}else if(e.name===I.STATUS){const d=l(r.command_id);if(!d)throw new Error("Status tool call requires command_id.");const m=await ae(`/orgx/api/orchestrator/commands/${encodeURIComponent(d)}`);if(!m.command)throw new Error(m.error??"Command status unavailable.");P(m.command),a={ok:!0,command:m.command}}g({type:"conversation.item.create",item:{type:"function_call_output",call_id:e.callId,output:JSON.stringify(a)}}),g({type:"response.create"}),R(`Tool executed: ${e.name}`)}catch(r){const a=r instanceof Error?r.message:"Tool execution failed.";b(a),g({type:"conversation.item.create",item:{type:"function_call_output",call_id:e.callId,output:JSON.stringify({ok:!1,error:a})}}),g({type:"response.create"}),R(`Tool failed: ${e.name}`)}}},[ae,R,j,n,g]),ye=s.useCallback(async()=>{var e,r,a,d,m;if(!((e=navigator.mediaDevices)!=null&&e.getUserMedia)){b("Microphone capture is unavailable in this browser/runtime.");return}b(null),y(!0),z([]);try{const i=await j("/orgx/api/realtime/session",{workspace_id:n??void 0,model:"gpt-realtime-1.5",voice:"alloy",tool_choice:"auto",tools:fe,instructions:"You are the OrgX realtime orchestrator copilot. Use tools for state-changing operations. Before applying actions, state the plan concisely."});if(!(i!=null&&i.session))throw new Error((i==null?void 0:i.error)??"Failed to create realtime session.");const F=l((r=i==null?void 0:i.session)==null?void 0:r.model)??l((a=i==null?void 0:i.defaults)==null?void 0:a.model)??"gpt-realtime-1.5";he(F);const me=l((m=(d=i==null?void 0:i.session)==null?void 0:d.client_secret)==null?void 0:m.value);if(!me)throw new Error("Realtime session is missing client_secret.");const U=await navigator.mediaDevices.getUserMedia({audio:!0});O.current=U;for(const _ of U.getAudioTracks())_.enabled=!1;const k=new RTCPeerConnection;G.current=k,U.getTracks().forEach(_=>k.addTrack(_,U));const q=document.createElement("audio");q.autoplay=!0,H.current=q,k.ontrack=_=>{const[u]=_.streams;u&&(q.srcObject=u,q.play().catch(()=>{}))};const V=k.createDataChannel("oai-events");D.current=V,V.onmessage=_=>{try{const u=JSON.parse(String(_.data)),x=l(u.type)??"";if(x==="error"){const c=u.error&&typeof u.error=="object"?u.error:null,w=l(c==null?void 0:c.message)??l(u.message)??"Realtime session error.";b(w),R(`Error: ${w}`);return}if(x==="conversation.item.input_audio_transcription.completed"){const c=Q(u);c&&Z(c)}if(x==="response.output_text.delta"||x==="response.text.delta"||x==="response.output_audio_transcript.delta"||x==="response.audio_transcript.delta"){const c=l(u.delta)??Q(u);c&&(E.current=`${E.current}${c}`,M(E.current))}if(x==="response.output_text.done"||x==="response.text.done"||x==="response.output_audio_transcript.done"||x==="response.audio_transcript.done"){const c=Q(u);c&&(E.current=c,M(c))}if(x==="response.function_call_arguments.done"){const c=l(u.call_id),w=l(u.name);if(c&&w){const B=typeof u.arguments=="string"?u.arguments:"{}";L({callId:c,name:w,arguments:B})}}if(x==="response.output_item.done"){const c=u.item&&typeof u.item=="object"?u.item:null;if((c==null?void 0:c.type)==="function_call"){const w=l(c.call_id)??l(c.id),B=l(c.name);if(w&&B){const Ne=typeof c.arguments=="string"?c.arguments:"{}";L({callId:w,name:B,arguments:Ne})}}}if(x==="response.done"){const c=Se(u);for(const w of c)L(w)}}catch{}},V.onopen=()=>{C(!0),g({type:"session.update",session:{tools:fe,tool_choice:"auto"}}),R("Realtime connected")},V.onclose=()=>{C(!1),A(!1)};const ue=await k.createOffer();await k.setLocalDescription(ue);const Y=await fetch(`https://api.openai.com/v1/realtime?model=${encodeURIComponent(F)}`,{method:"POST",headers:{Authorization:`Bearer ${me}`,"Content-Type":"application/sdp"},body:ue.sdp??""});if(!Y.ok){const _=await Y.text().catch(()=>Y.statusText);throw new Error(`Realtime SDP negotiation failed: ${_}`)}const ve=await Y.text();await k.setRemoteDescription({type:"answer",sdp:ve})}catch(i){N(),b(i instanceof Error?i.message:"Failed to connect realtime session.")}finally{y(!1)}},[N,L,R,j,n]),ie=s.useCallback(()=>{if(!f)return;const e=O.current;if(e){for(const r of e.getAudioTracks())r.enabled=!0;E.current="",M(""),A(!0),g({type:"input_audio_buffer.clear"})}},[f,g]),K=s.useCallback(()=>{const e=O.current;if(e)for(const r of e.getAudioTracks())r.enabled=!1;A(!1),g({type:"input_audio_buffer.commit"}),g({type:"response.create"})},[g]),ge=s.useCallback(async()=>{const e=$.trim();if(e){te(!0),b(null);try{const r=await j("/orgx/api/orchestrator/commands/preview",{input:e,workspace_id:n??void 0});if(!r.command)throw new Error(r.error??"Failed to preview command.");P(r.command),X(r.command.proposedActions.map(a=>a.actionId))}catch(r){b(r instanceof Error?r.message:"Failed to preview command.")}finally{te(!1)}}},[$,j,n]),be=s.useCallback(async()=>{if(o!=null&&o.id){oe(!0),b(null);try{const e=await j("/orgx/api/orchestrator/commands/apply",{command_id:o.id,confirmed_action_ids:T,workspace_id:n??void 0});if(!e.command)throw new Error(e.error??"Failed to apply command.");P(e.command)}catch(e){b(e instanceof Error?e.message:"Failed to apply command.")}finally{oe(!1)}}},[o==null?void 0:o.id,j,T,n]),ce=T.length,we=(((le=o==null?void 0:o.proposedActions)==null?void 0:le.length)??0)>0,je=!!(o!=null&&o.id)&&ce>0&&!re,_e=s.useMemo(()=>{const e=(o==null?void 0:o.status)??"draft";return e==="completed"?"text-lime":e==="completed_with_errors"||e==="failed"?"text-amber-300":e==="applying"?"text-teal":"text-secondary"},[o==null?void 0:o.status]);return t.jsxs(ke,{open:p,onClose:h,maxWidth:"max-w-5xl",fitContent:!0,closeOnEscapeWhenTyping:!1,children:[t.jsx("div",{className:"border-b border-strong px-4 py-3",children:t.jsxs("div",{className:"flex items-start justify-between gap-3",children:[t.jsxs("div",{children:[t.jsx("p",{className:"text-caption uppercase tracking-[0.14em] text-secondary",children:"Realtime Orchestrator"}),t.jsx("h2",{className:"text-heading font-semibold text-white",children:"GPT Realtime 1.5"}),t.jsx("p",{className:"text-micro text-secondary",children:"Voice + tool-calls for initiative launch, decision resolution, and Next Up control."})]}),t.jsx("button",{type:"button",onClick:h,className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption text-secondary transition-colors hover:bg-white/[0.08] hover:text-white",children:"Close"})]})}),t.jsxs("div",{className:"grid gap-4 px-4 pb-4 pt-3 lg:grid-cols-[1.12fr_1fr]",children:[t.jsxs("section",{className:"space-y-3",children:[t.jsxs("div",{className:"rounded-xl border border-strong bg-white/[0.02] p-3",children:[t.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[t.jsx("span",{className:"text-caption uppercase tracking-[0.12em] text-secondary",children:"Session"}),t.jsx("span",{className:"text-micro text-secondary",children:xe})]}),t.jsx("div",{className:"flex flex-wrap items-center gap-2",children:f?t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",onMouseDown:ie,onMouseUp:K,onMouseLeave:()=>{S&&K()},onTouchStart:e=>{e.preventDefault(),ie()},onTouchEnd:e=>{e.preventDefault(),K()},className:`rounded-full border px-3 py-1.5 text-caption font-semibold transition-colors ${S?"border-teal/45 bg-teal/[0.16] text-teal":"border-white/[0.2] bg-white/[0.04] text-primary hover:bg-white/[0.1]"}`,children:S?"Listening… release to send":"Hold to talk"}),t.jsx("button",{type:"button",onClick:N,className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption text-secondary transition-colors hover:bg-white/[0.08] hover:text-primary",children:"Disconnect"})]}):t.jsx("button",{type:"button",disabled:v,onClick:()=>void ye(),className:"rounded-full border border-lime/35 bg-lime/[0.12] px-3 py-1.5 text-caption font-semibold text-lime transition-colors hover:bg-lime/[0.2] disabled:cursor-not-allowed disabled:opacity-60",children:v?"Connecting…":"Connect Realtime"})}),ne.length>0?t.jsx("div",{className:"mt-3 rounded-lg border border-strong bg-black/20 p-2",children:ne.map((e,r)=>t.jsx("p",{className:"text-micro text-secondary",children:e},`${e}-${r}`))}):null]}),t.jsxs("div",{className:"rounded-xl border border-strong bg-white/[0.02] p-3",children:[t.jsx("label",{className:"mb-2 block text-caption uppercase tracking-[0.12em] text-secondary",children:"Command Input"}),t.jsx("textarea",{value:$,onChange:e=>Z(e.target.value),rows:4,"data-modal-autofocus":"true",placeholder:"Example: create initiative called AI Readiness Audit for this workspace",className:"w-full rounded-lg border border-strong bg-[#040912] px-3 py-2 text-body text-primary placeholder:text-secondary focus:border-lime/35 focus:outline-none"}),W?t.jsxs("p",{className:"mt-2 text-caption text-secondary",children:["Assistant: ",t.jsx("span",{className:"text-primary",children:W})]}):null,t.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[t.jsx("button",{type:"button",disabled:ee||$.trim().length===0,onClick:()=>void ge(),className:"rounded-full border border-teal/35 bg-teal/[0.12] px-3 py-1.5 text-caption font-semibold text-teal transition-colors hover:bg-teal/[0.2] disabled:cursor-not-allowed disabled:opacity-60",children:ee?"Previewing…":"Preview Actions"}),t.jsx("button",{type:"button",disabled:!je,onClick:()=>void be(),className:"rounded-full border border-lime/35 bg-lime/[0.12] px-3 py-1.5 text-caption font-semibold text-lime transition-colors hover:bg-lime/[0.2] disabled:cursor-not-allowed disabled:opacity-60",children:re?"Applying…":`Apply (${ce})`})]})]})]}),t.jsxs("section",{className:"space-y-3",children:[t.jsxs("div",{className:"rounded-xl border border-strong bg-white/[0.02] p-3",children:[t.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[t.jsx("span",{className:"text-caption uppercase tracking-[0.12em] text-secondary",children:"Command Status"}),t.jsx("span",{className:`text-caption font-semibold ${_e}`,children:(o==null?void 0:o.status)??"idle"})]}),t.jsx("p",{className:"text-body text-primary",children:(o==null?void 0:o.humanSummary)??"Preview a command or use voice to trigger tool calls."}),(de=o==null?void 0:o.riskFlags)!=null&&de.length?t.jsxs("p",{className:"mt-2 text-caption text-amber-200",children:["Risk flags: ",o.riskFlags.join(", ")]}):null]}),t.jsxs("div",{className:"max-h-[360px] space-y-2 overflow-y-auto rounded-xl border border-strong bg-white/[0.02] p-3",children:[t.jsx("p",{className:"text-caption uppercase tracking-[0.12em] text-secondary",children:"Proposed Actions"}),we?o.proposedActions.map(e=>{const r=T.includes(e.actionId);return t.jsx("label",{className:"block rounded-lg border border-strong bg-[#040912] p-2 text-body",children:t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsx("input",{type:"checkbox",checked:r,onChange:a=>{const d=a.target.checked?[...T,e.actionId]:T.filter(m=>m!==e.actionId);X(d)},className:"mt-1"}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:"font-semibold text-primary",children:e.type}),t.jsx("p",{className:"text-caption text-secondary",children:e.reason}),t.jsxs("p",{className:"text-micro text-secondary",children:["confidence ",Ae(e.confidence)," • impact ",e.blockingImpact]})]})]})},e.actionId)}):t.jsx("p",{className:"text-body text-secondary",children:"No actions inferred yet."})]}),(((pe=o==null?void 0:o.results)==null?void 0:pe.length)??0)>0?t.jsxs("div",{className:"max-h-[220px] space-y-2 overflow-y-auto rounded-xl border border-strong bg-white/[0.02] p-3",children:[t.jsx("p",{className:"text-caption uppercase tracking-[0.12em] text-secondary",children:"Apply Results"}),o.results.map(e=>t.jsxs("div",{className:`rounded-lg border p-2 text-body ${e.ok?"border-lime/30 bg-lime/[0.08] text-lime":"border-amber-400/35 bg-amber-500/[0.12] text-amber-100"}`,children:[t.jsx("p",{className:"font-semibold",children:e.type}),t.jsx("p",{className:"text-caption",children:e.message}),e.error?t.jsxs("p",{className:"text-micro text-amber-200",children:["error: ",e.error]}):null]},`${e.actionId}-${e.type}`))]}):null]})]}),se?t.jsx("div",{className:"border-t border-amber-500/30 bg-amber-500/[0.12] px-4 py-2 text-caption text-amber-100",children:se}):null]})}export{Oe as RealtimeOrchestratorModal};
|
|
Binary file
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as l,j as e}from"./cNrhgGc1.js";import{E as Q,d as M,r as $e,X as G,K as Ie,Y as Fe,Z as Pe,M as Le,h as Te,P as Be,w as ve}from"./Cn07669c.js";import{E as De}from"./DBG89Wsz.js";import{A as Ee,m as se,u as Re}from"./CxQ08qFN.js";import{u as We}from"./CYchPSem.js";import"./C-KIc3Wc.js";import"./BJgZIVUQ.js";const ze={pr:"⎋",file:"◇",artifact:"▪",log:"▸",decision:"◈"};function Ue(c){return c>=.8?"#BFFF00":c>=.5?"#F5B700":"#FF6B88"}function Oe(c){const t=c.match(/https?:\/\/\S+/);return t?t[0]:null}function Xe({evidenceType:c,title:t,summary:h,sourceUrl:y,confidence:C,payload:b,icon:_,label:f,onOpenTerminal:Y}){const[R,X]=l.useState(!1),E=t??f??null,$=c??(_?_.toUpperCase():null),w=_?ze[_]:null,v=_==="pr"&&f?Oe(f):null;return e.jsxs("div",{className:"rounded-xl border border-white/[0.06] bg-white/[0.02] px-3 py-2.5",children:[e.jsxs("div",{className:"flex items-start gap-2.5 cursor-pointer",onClick:()=>X(g=>!g),children:[($||w)&&e.jsxs("span",{className:"mt-0.5 flex-shrink-0 rounded bg-white/[0.06] px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wider text-secondary",children:[w?e.jsx("span",{className:"mr-1",children:w}):null,$]}),e.jsxs("div",{className:"min-w-0 flex-1",children:[E&&e.jsx("p",{className:"text-body font-medium text-primary",children:y?e.jsx("a",{href:y,target:"_blank",rel:"noopener noreferrer",className:"text-[#D8FFA1] hover:underline",onClick:g=>g.stopPropagation(),children:E}):v?e.jsx("a",{href:v,target:"_blank",rel:"noopener noreferrer",className:"text-[#D8FFA1] hover:underline",onClick:g=>g.stopPropagation(),children:E}):E}),h&&e.jsx("p",{className:`mt-0.5 text-caption text-secondary ${R?"":"line-clamp-2"}`,children:h})]}),e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:`mt-1 flex-shrink-0 text-muted transition-transform ${R?"rotate-180":""}`,children:e.jsx("path",{d:"m6 9 6 6 6-6"})})]}),C!=null&&e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("div",{className:"h-1 flex-1 overflow-hidden rounded-full bg-white/[0.06]",children:e.jsx("div",{className:"h-full rounded-full transition-all",style:{width:`${Math.round(C*100)}%`,backgroundColor:Ue(C)}})}),e.jsxs("span",{className:"text-micro text-muted tabular-nums",children:[Math.round(C*100),"%"]})]}),e.jsx(Ee,{children:R&&e.jsx(se.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.2},className:"overflow-hidden",children:e.jsxs("div",{className:"mt-2 space-y-2",children:[_==="log"&&Y&&e.jsxs("button",{type:"button",onClick:g=>{g.stopPropagation(),Y()},className:"inline-flex items-center gap-1.5 rounded-lg border border-white/[0.12] bg-white/[0.04] px-3 py-1.5 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.08]",children:[e.jsx("span",{className:"font-mono text-micro",children:">_"}),"Open in terminal"]}),b&&Object.keys(b).length>0&&e.jsx("pre",{className:"max-h-40 overflow-auto rounded-lg bg-black/40 p-2.5 text-micro text-secondary font-mono",children:JSON.stringify(b,null,2)})]})})})]})}function Ke({segments:c}){return c.length===0?null:e.jsx("nav",{className:"flex items-center gap-1.5 min-w-0 text-caption text-secondary",children:c.map((t,h)=>e.jsxs("span",{className:"flex items-center gap-1.5 min-w-0",children:[h>0&&e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"flex-shrink-0 text-faint",children:e.jsx("path",{d:"m9 18 6-6-6-6"})}),t.icon&&e.jsx(Q,{type:t.icon,size:11,className:"flex-shrink-0 opacity-80"}),t.onClick?e.jsx("button",{type:"button",onClick:t.onClick,className:"truncate transition-colors hover:text-primary",children:t.label}):e.jsx("span",{className:"truncate",children:t.label})]},h))})}const _e=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent);function Je(c){try{return JSON.stringify(c,null,2)}catch{return null}}function qe(c){if(typeof c!="string")return null;const t=c.trim().toLowerCase();return t==="rejected"?"declined":t==="approved"||t==="declined"||t==="cancelled"?t:null}function Ne(c,t){return!c||c.trim().length===0?t:Te(c.trim())||t}function Ve(c){switch(c){case"spawn_guard_blocked":return"Spawn Guard";case"autopilot_failure":return"Autopilot Failure";case"budget_exceeded":return"Budget Exceeded";case"scope_change":return"Scope Change";case"conflict_resolution":return"Conflict Resolution";case"approval_required":return"Approval Required";case"review_required":return"Review Required";case"permission_request":return"Permission Request";default:return c.replace(/[_-]/g," ").replace(/\b\w/g,t=>t.toUpperCase())}}function Ze(c){const t=c.toLowerCase();return t==="critical"||t==="p0"?M.red:t==="high"||t==="p1"?M.amber:t==="medium"||t==="p2"?M.iris:"rgba(255,255,255,0.5)"}function Ge({open:c,decision:t,onClose:h,onApprove:y,onReject:C,initiativeTitle:b,workstreamTitle:_,onNavigate:f,currentIndex:Y,totalCount:R,onFocusRunId:X}){const[E,$]=l.useState("idle"),[w,v]=l.useState(null),[g,F]=l.useState(null),[N,W]=l.useState(""),[z,P]=l.useState(!1),[xe,ne]=l.useState(!1),[ie,me]=l.useState(!1),K=l.useRef(null),ae=l.useRef(),L=l.useRef(h);L.current=h,l.useEffect(()=>{if(c){$("idle"),v(null);const i=(t==null?void 0:t.selectedOptionId)??(t!=null&&t.options&&t.options.length===1?t.options[0].id:null);F(i),W(""),P(!1),ne(!1),me(!1)}return()=>{ae.current&&clearTimeout(ae.current)}},[c,t==null?void 0:t.id]);const m=t==null?void 0:t.metadata,le=l.useMemo(()=>{if(!m)return[];const i=m,n=i.decision_options??i.options??i.actions??null;if(!Array.isArray(n))return[];const I=[],B=new Set;for(let A=0;A<n.length;A+=1){const Z=n[A];if(typeof Z=="string"){const pe=Z.trim();if(!pe)continue;const r=`option-${A+1}`;if(B.has(r))continue;B.add(r),I.push({id:r,label:pe,description:null,impliedStatus:null,actionType:null,requiresNote:!1});continue}if(!Z||typeof Z!="object")continue;const x=Z,ue=typeof x.id=="string"&&x.id.trim()||typeof x.option_id=="string"&&x.option_id.trim()||typeof x.action_id=="string"&&x.action_id.trim()||`option-${A+1}`;if(B.has(ue))continue;const ye=typeof x.label=="string"&&x.label.trim()||typeof x.title=="string"&&x.title.trim()||typeof x.name=="string"&&x.name.trim()||typeof x.action=="string"&&x.action.trim()||null;ye&&(B.add(ue),I.push({id:ue,label:ye,description:typeof x.description=="string"?x.description:null,impliedStatus:qe(x.implied_status)??qe(x.status),actionType:typeof x.action_type=="string"&&x.action_type||typeof x.type=="string"&&x.type||null,requiresNote:x.requires_note===!0||x.requiresNote===!0||x.note_required===!0}))}return I.slice(0,12)},[m]),q=l.useMemo(()=>t!=null&&t.options&&t.options.length>0?t.options:le,[t==null?void 0:t.options,le]),u=l.useMemo(()=>q.find(i=>i.id===g)??null,[q,g]),T=l.useMemo(()=>{const i=((t==null?void 0:t.context)??"").trim();if(i)return i;if(!m)return"";const n=m,I=(typeof n.summary=="string"?n.summary:null)??(typeof n.description=="string"?n.description:null)??"";return String(I??"").trim()},[t==null?void 0:t.context,m]),U=l.useMemo(()=>{const i=(t==null?void 0:t.waitingMinutes)??0;return i>=15?M.red:i>=5?M.amber:M.teal},[t==null?void 0:t.waitingMinutes]),p=l.useCallback(async()=>{if(!t)return;const i=Je({decision:t,metadata:m});if(i)try{await navigator.clipboard.writeText(i),ne(!0),setTimeout(()=>ne(!1),2e3)}catch{}},[t,m]),O=l.useCallback(()=>{const i=N.trim(),n=u==null?void 0:u.id;if(!(!i&&!n))return{note:i.length>0?i:void 0,optionId:n??void 0}},[N,u]),k=l.useCallback(async()=>{if(!t||!y)return;if(q.length>0&&!u){v("Select an option before approving this decision.");return}if(u!=null&&u.requiresNote&&N.trim().length===0){v("A note is required for the selected option."),P(!0),requestAnimationFrame(()=>{var n;return(n=K.current)==null?void 0:n.focus()});return}let i=!1;if($(n=>n==="approving"||n==="rejecting"?n:(i=!0,"approving")),!!i){v(null);try{const n=await y(t.id,O());n.failed>0?($("error"),v(Ne(n.firstError,"Approval failed. Please try again."))):($("success"),ae.current=setTimeout(()=>L.current(),800))}catch(n){$("error");const I=n instanceof Error?n.message:"";v(Ne(I,"Approval failed."))}}},[O,t,N,y,q.length,u]),H=l.useCallback(async()=>{if(!t||!C)return;if(q.length>0&&!u){v("Select an option before rejecting this decision.");return}if(u!=null&&u.requiresNote&&N.trim().length===0){v("A note is required for the selected option."),P(!0),requestAnimationFrame(()=>{var n;return(n=K.current)==null?void 0:n.focus()});return}let i=!1;if($(n=>n==="approving"||n==="rejecting"?n:(i=!0,"rejecting")),!!i){v(null);try{const n=await C(t.id,O());n.failed>0?($("error"),v(Ne(n.firstError,"Rejection failed. Please try again."))):($("rejected"),ae.current=setTimeout(()=>L.current(),800))}catch(n){$("error");const I=n instanceof Error?n.message:"";v(Ne(I,"Rejection failed."))}}},[O,t,N,C,q.length,u]);if(l.useEffect(()=>{if(!c)return;const i=n=>{var B;if((n.metaKey||n.ctrlKey)&&n.key==="Enter"){n.preventDefault(),k();return}const I=(B=n.target)==null?void 0:B.tagName;if(!(I==="INPUT"||I==="TEXTAREA"))switch(n.key){case"j":n.preventDefault(),f==null||f(1);break;case"k":n.preventDefault(),f==null||f(-1);break;case"a":n.preventDefault(),k();break;case"r":n.preventDefault(),H();break;case"n":n.preventDefault(),P(A=>!A),z||requestAnimationFrame(()=>{var A;return(A=K.current)==null?void 0:A.focus()});break}};return document.addEventListener("keydown",i),()=>document.removeEventListener("keydown",i)},[c,k,H,f,z]),!c||!t)return null;const oe=E==="approving"||E==="rejecting",ee=E==="success"||E==="rejected",J=(t.status??"pending").toLowerCase(),he=!J.includes("approved")&&!J.includes("resolved")&&!J.includes("rejected")&&!J.includes("declined")&&!J.includes("cancelled"),Ce=q.length>0&&!u,fe=(u==null?void 0:u.requiresNote)===!0&&N.trim().length===0,V=oe||Ce||fe,te=t.evidenceRefs??[],S=te.length>0,ge=t.recommendedAction??null,be=t.decisionType??null,re=t.priority??null,ce=t.occurrenceCount??null,je=t.sourceRunId??null,j=[];b&&j.push({label:b,icon:"initiative"}),_&&j.push({label:_,icon:"workstream"});const de=[["ID",t.id],["Type",t.decisionType],["Dedupe key",t.dedupeKey],["Source system",t.sourceSystem],["Conflict source",t.conflictSource],["Agent ID",t.agentId],["Source run",t.sourceRunId],["Source session",t.sourceSessionId],["Source stream",t.sourceStreamId]].filter(([,i])=>i!=null);if(ee){const i=E==="success",n=i?M.lime:M.red;return e.jsx($e,{open:c,onClose:h,maxWidth:"max-w-xl",fitContent:!0,children:e.jsxs("div",{className:"flex flex-col items-center justify-center px-8 py-12",children:[e.jsx("div",{className:"mb-4 flex h-16 w-16 items-center justify-center rounded-full",style:{backgroundColor:`${n}18`,border:`1.5px solid ${n}40`},children:i?e.jsx("svg",{width:"28",height:"28",viewBox:"0 0 24 24",fill:"none",stroke:n,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):e.jsxs("svg",{width:"28",height:"28",viewBox:"0 0 24 24",fill:"none",stroke:n,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 6L6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})}),e.jsx("p",{className:"text-heading font-semibold text-white",children:i?"Approved":"Rejected"}),e.jsx("p",{className:"mt-1 text-body text-secondary",children:t.title})]})})}return e.jsx($e,{open:c,onClose:h,maxWidth:"max-w-xl",children:e.jsxs("div",{className:"flex h-full min-h-0 w-full flex-col",children:[e.jsx("div",{className:"h-[2px] w-full flex-shrink-0",style:{background:`linear-gradient(90deg, ${U}60, ${U}20, transparent)`}}),f&&e.jsxs("div",{className:"flex items-center justify-between px-6 pt-3 pb-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>f(-1),className:"rounded p-1 text-muted hover:text-secondary hover:bg-white/[0.06] transition-colors",title:"Previous (k)",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"m15 18-6-6 6-6"})})}),e.jsx("button",{type:"button",onClick:()=>f(1),className:"rounded p-1 text-muted hover:text-secondary hover:bg-white/[0.06] transition-colors",title:"Next (j)",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"m9 18 6-6-6-6"})})}),Y!=null&&R!=null&&e.jsxs("span",{className:"text-micro text-muted tabular-nums",children:[Y+1," of ",R]})]}),e.jsx("button",{type:"button",onClick:h,"aria-label":"Close",className:"rounded p-1 text-muted hover:text-secondary hover:bg-white/[0.06] transition-colors",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M18 6 6 18M6 6l12 12"})})})]}),j.length>0&&e.jsx("div",{className:"px-6 pt-2",children:e.jsx(Ke,{segments:j})}),e.jsxs("div",{className:"flex items-start justify-between gap-3 px-6 pt-4 pb-4",children:[e.jsx("div",{className:"min-w-0 flex-1",children:e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-lg",style:{backgroundColor:`${U}14`,border:`1px solid ${U}30`},children:e.jsx(Q,{type:"decision",size:14})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h2",{className:"text-title font-medium leading-tight text-white mb-2",children:t.title||"Decision Required"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-body text-secondary",children:[e.jsx("span",{children:t.agentName||"OrgX Autopilot"}),e.jsx("span",{className:"text-white/[0.15]",children:"|"}),e.jsx("span",{children:G(t.waitingMinutes).text}),be&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-white/[0.15]",children:"|"}),e.jsx("span",{className:"text-primary",children:Ve(be)})]}),re&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-white/[0.15]",children:"|"}),e.jsx("span",{className:"font-medium",style:{color:Ze(re)},children:re})]})]}),ce!=null&&ce>1&&e.jsxs("p",{className:"mt-2 text-caption text-muted",children:["Seen ",ce," times",t.firstSeenAt&&e.jsxs(e.Fragment,{children:[" · first ",Ie(t.firstSeenAt)]}),t.lastSeenAt&&e.jsxs(e.Fragment,{children:[" · last ",Ie(t.lastSeenAt)]})]})]})]})}),!f&&e.jsx("button",{type:"button",onClick:h,"aria-label":"Close",className:"mt-0.5 flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-lg text-muted transition-colors hover:bg-white/[0.06] hover:text-white",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 6L6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto px-6 pb-4",children:[(t.initiativeId||t.workstreamId)&&e.jsx("div",{className:"mb-4",children:e.jsx(Fe,{nodes:Pe({initiativeId:t.initiativeId,initiativeTitle:b,workstreamId:t.workstreamId,workstreamTitle:_,agentName:t.agentName,agentId:t.agentId}),activeId:t.workstreamId,compact:!0})}),ge&&e.jsxs("div",{className:"mb-4 rounded-xl border border-cyan-300/[0.28] bg-cyan-500/[0.12] px-4 py-3",children:[e.jsx("p",{className:"text-micro font-semibold uppercase tracking-wider text-cyan-200 mb-1",children:"Recommended"}),e.jsx("p",{className:"text-body text-cyan-100",children:ge})]}),S&&e.jsxs("div",{className:"mb-4",children:[e.jsx("p",{className:"mb-2 px-1 text-micro font-semibold uppercase tracking-wider text-muted",children:"Evidence"}),e.jsx("div",{className:"space-y-1.5",children:te.map((i,n)=>e.jsx(Xe,{evidenceType:i.evidenceType,title:i.title,summary:i.summary,sourceUrl:i.sourceUrl,confidence:i.confidence,payload:i.payload},n))})]}),T?e.jsx("div",{className:"rounded-xl border border-white/[0.06] bg-white/[0.02] px-4 py-3",children:e.jsx(Le,{text:T,mode:"block"})}):e.jsx("p",{className:"px-1 text-body text-muted italic",children:"No additional context provided."}),q.length>0&&e.jsxs("div",{className:"mt-8",children:[e.jsx("p",{className:"mb-3 px-1 text-[11px] font-semibold uppercase tracking-widest text-muted",children:"Options"}),e.jsx("div",{className:"space-y-1 relative",children:q.map(i=>{const n=g===i.id;return e.jsxs("button",{type:"button",onClick:()=>{F(n?null:i.id),i.requiresNote&&P(!0)},disabled:oe,className:"group relative flex w-full items-start gap-4 px-4 py-4 text-left focus:outline-none",children:[n&&e.jsx(se.div,{layoutId:"decision-option-bg",className:"absolute inset-0 rounded-xl",style:{backgroundColor:`${M.lime}12`},transition:{type:"spring",stiffness:400,damping:25}}),!n&&e.jsx("div",{className:"absolute inset-0 rounded-xl opacity-0 transition-opacity group-hover:bg-white/[0.03]"}),e.jsx("div",{className:"relative mt-0.5 flex h-5 w-5 flex-shrink-0 items-center justify-center rounded-full border-[1.5px] transition-colors",style:{borderColor:n?M.lime:"rgba(255,255,255,0.2)"},children:e.jsx(Ee,{children:n&&e.jsx(se.div,{initial:{scale:0},animate:{scale:1},exit:{scale:0},transition:{type:"spring",stiffness:500,damping:30},className:"h-2.5 w-2.5 rounded-full",style:{backgroundColor:M.lime}})})}),e.jsxs("div",{className:"relative min-w-0 flex-1",children:[e.jsx("span",{className:`block text-[15px] ${n?"font-medium text-white":"text-primary"}`,children:i.label}),i.description&&e.jsx("p",{className:"mt-1 text-[13px] leading-relaxed text-secondary",children:i.description}),i.requiresNote&&e.jsx("p",{className:"mt-1.5 text-[11px] font-medium uppercase tracking-wider text-amber-400",children:"Note required"})]})]},i.id)})})]}),he&&e.jsxs("div",{className:"mt-4",children:[e.jsxs("button",{type:"button",onClick:()=>{P(i=>!i),z||requestAnimationFrame(()=>{var i;return(i=K.current)==null?void 0:i.focus()})},className:"flex w-full items-center gap-2 px-1 text-caption text-secondary transition-colors hover:text-white",children:[e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"transition-transform",style:{transform:z?"rotate(90deg)":"rotate(0deg)"},children:e.jsx("polyline",{points:"9 18 15 12 9 6"})}),"Add a note"]}),z&&e.jsxs("div",{className:"mt-2",children:[e.jsx("textarea",{ref:K,value:N,onChange:i=>W(i.target.value),disabled:oe,placeholder:"Optional context for this decision...",rows:3,className:"w-full resize-none rounded-xl border border-white/[0.08] bg-white/[0.03] px-4 py-3 text-body text-primary placeholder-white/30 outline-none transition-colors focus:border-white/[0.16] focus:bg-white/[0.04]"}),(u==null?void 0:u.requiresNote)&&N.trim().length===0&&e.jsx("p",{className:"mt-2 text-caption text-amber-300",children:"This option requires a note before submission."})]})]}),je&&X&&e.jsx("div",{className:"mt-4",children:e.jsxs("button",{type:"button",onClick:()=>X(je),className:"inline-flex items-center gap-1.5 text-caption text-[#D8FFA1] transition-colors hover:text-white",children:[e.jsx(Q,{type:"session",size:12}),"View source run"]})}),e.jsx("div",{className:"mt-4 border-t border-white/[0.06] pt-4",children:e.jsx(De,{entityType:"decision",entityId:t.id})}),de.length>0&&e.jsxs("div",{className:"mt-4 border-t border-white/[0.06] pt-2",children:[e.jsxs("button",{type:"button",onClick:()=>me(i=>!i),className:"flex w-full items-center justify-between text-micro font-semibold uppercase tracking-wider text-muted hover:text-secondary transition-colors",children:[e.jsx("span",{children:"Technical details"}),e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:`transition-transform ${ie?"rotate-180":""}`,children:e.jsx("path",{d:"m6 9 6 6 6-6"})})]}),ie&&e.jsx("div",{className:"mt-2 space-y-0.5",children:de.map(([i,n])=>e.jsxs("div",{className:"flex gap-2 text-micro",children:[e.jsx("span",{className:"text-muted w-28 flex-shrink-0",children:i}),e.jsx("span",{className:"text-secondary truncate",children:n})]},i))})]}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-x-3 gap-y-1 text-micro text-muted opacity-60",children:[f&&e.jsx("span",{children:"j/k nav"}),e.jsx("span",{children:"a approve"}),e.jsx("span",{children:"r reject"}),e.jsx("span",{children:"n note"}),e.jsxs("span",{children:[_e?"⌘":"Ctrl","+Enter approve"]}),e.jsx("span",{children:"esc close"})]})]}),w&&e.jsxs("div",{className:"flex items-center gap-2 border-t border-white/[0.06] px-6 py-3",children:[e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:M.red,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",x2:"12",y1:"8",y2:"12"}),e.jsx("line",{x1:"12",x2:"12.01",y1:"16",y2:"16"})]}),e.jsx("p",{className:"text-caption text-red-300",children:w})]}),he&&e.jsx("div",{className:"relative mt-auto border-t border-white/[0.04] bg-black/60 px-6 py-5 backdrop-blur-xl",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[C&&e.jsx(se.button,{whileTap:{scale:.97},type:"button",onClick:H,disabled:V,className:"rounded-lg px-4 py-2 text-[14px] font-medium text-secondary transition-colors hover:text-red-400 disabled:opacity-40 focus:outline-none",children:E==="rejecting"?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"inline-block h-3 w-3 animate-spin rounded-full border-[1.5px] border-current border-t-transparent"}),"Rejecting"]}):"Reject"}),e.jsx("button",{type:"button",onClick:p,className:"rounded-lg px-2 py-2 text-[13px] text-muted transition-colors hover:text-secondary focus:outline-none",title:"Copy decision as JSON",children:xe?"Copied":"Copy JSON"})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("span",{className:"hidden text-[13px] text-muted sm:block",children:[_e?"⌘":"Ctrl","+Enter"]}),e.jsx(se.button,{whileTap:!y||V?void 0:{scale:.97},type:"button",onClick:k,disabled:!y||V,"data-modal-autofocus":"true",className:"rounded-lg px-6 py-2.5 text-[14px] font-semibold transition-all focus:outline-none",style:{backgroundColor:!y||V?"rgba(255,255,255,0.06)":M.lime,color:!y||V?"rgba(255,255,255,0.4)":"#000"},children:E==="approving"?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"inline-block h-3 w-3 animate-spin rounded-full border-[1.5px] border-black/40 border-t-black"}),"Approving"]}):"Approve"})]})]})})]})})}const Ae=40;function ke(c,t){return!c||c.trim().length===0?t:Te(c.trim())||t}function Me(c,t,h){const y=c==="approve"?`Approval failed for ${t} decision${t===1?"":"s"}.`:`Rejection failed for ${t} decision${t===1?"":"s"}.`;return ke(h,y)}function Qe(c,t){return`${c}_${t}`}const it=l.memo(function({decisions:t,focusDecisionId:h=null,onFocusDecisionHandled:y,onApproveDecision:C,onRejectDecision:b,onApproveAll:_,onBulkDecisionAction:f,mutationState:Y,showHeader:R=!0,panelStyle:X="card",className:E}){var pe;const $=Re(),[w,v]=l.useState(!1),[g,F]=l.useState(new Set),[N,W]=l.useState(new Set),[z,P]=l.useState(new Set),{enqueue:xe,ToastRenderer:ne}=We(),[ie,me]=l.useState("approve_selected"),[K,ae]=l.useState(""),[L,m]=l.useState(null),[le,q]=l.useState(Ae),[u,T]=l.useState(null),U=l.useRef(null),p=l.useMemo(()=>{const r=new Set;return[...t].filter(a=>r.has(a.id)?!1:(r.add(a.id),!0)).sort((a,s)=>{if(a.waitingMinutes!==s.waitingMinutes)return s.waitingMinutes-a.waitingMinutes;const o=Date.parse(a.requestedAt??a.updatedAt??""),d=Date.parse(s.requestedAt??s.updatedAt??""),D=Number.isFinite(o)?o:0;return(Number.isFinite(d)?d:0)-D})},[t]);l.useEffect(()=>{W(r=>{const a=new Set(p.map(o=>o.id)),s=new Set;for(const o of r)a.has(o)&&s.add(o);return s})},[p]);const O=N.size,k=l.useMemo(()=>p.filter(r=>!z.has(r.id)).slice(0,le),[p,le,z]),H=l.useMemo(()=>{if(k.length===0)return!1;for(const r of k)if(!N.has(r.id))return!1;return!0},[N,k]),oe=l.useMemo(()=>u?p.find(r=>r.id===u)??null:null,[u,p]),ee=l.useMemo(()=>u?p.findIndex(r=>r.id===u):-1,[u,p]),J=l.useCallback(r=>{const a=ee+r;a>=0&&a<p.length&&T(p[a].id)},[ee,p]),he=async(r,a)=>{m(null),F(o=>{const d=new Set(o);return d.add(r),d});const s=await C(r,a);return s.failed>0?m(Me("approve",s.failed,s.firstError)):s.updated>0&&m("Decision approved. Changes synced."),F(o=>{const d=new Set(o);return d.delete(r),d}),s},Ce=b?async(r,a)=>{m(null),F(o=>{const d=new Set(o);return d.add(r),d});const s=await b(r,a);return s.failed>0?m(Me("reject",s.failed,s.firstError)):s.updated>0&&m("Decision rejected. Changes synced."),F(o=>{const d=new Set(o);return d.delete(r),d}),s}:void 0;l.useEffect(()=>{q(r=>p.length===0?0:Math.min(Math.max(Ae,r),p.length))},[p.length]),l.useEffect(()=>{const r=(h??"").trim();if(!r){U.current=null;return}U.current===r||!p.some(s=>s.id===r)||(U.current=r,T(r),y==null||y(r))},[h,y,p]);const fe=r=>{W(a=>{const s=new Set(a);return s.has(r)?s.delete(r):s.add(r),s})},V=()=>{W(r=>{if(k.length===0)return r;const a=new Set(r),s=H;for(const o of k)s?a.delete(o.id):a.add(o.id);return a})},te=l.useMemo(()=>{const r=p.map(s=>s.id).filter(s=>N.has(s)),a=k.map(s=>s.id);return[{id:"approve_selected",label:`Approve selected (${r.length})`,action:"approve",ids:r},{id:"reject_selected",label:`Reject selected (${r.length})`,action:"reject",ids:r,hidden:!b},{id:"approve_visible",label:`Approve visible (${a.length})`,action:"approve",ids:a},{id:"reject_visible",label:`Reject visible (${a.length})`,action:"reject",ids:a,hidden:!b}].filter(s=>!s.hidden)},[b,N,p,k]),S=l.useMemo(()=>te.find(r=>r.id===ie)??te[0]??null,[ie,te]),ge=async(r,a,s)=>{if(r.length===0)return{updated:0,failed:0};if(a==="approve"&&r.length===p.length&&!s)return _();let o=0,d=0,D;for(const Se of r)try{const we=a==="approve"?await C(Se,s?{note:s}:void 0):b?await b(Se,s?{note:s}:void 0):{updated:0,failed:1};o+=we.updated,d+=we.failed,!D&&we.firstError&&(D=we.firstError)}catch{d+=1}return{updated:o,failed:d,firstError:D}},be=async()=>{if(!S||w)return;const r=S.ids;if(r.length===0){m("No decisions selected for this action.");return}m(null),v(!0),F(new Set(r));const a=K.trim();try{const s=f?await f(r,S.action,a.length>0?a:void 0):await ge(r,S.action,a.length>0?a:void 0),o=S.action==="approve"?"Approved":"Rejected";if(s.failed>0){const d=`${o} ${s.updated}; ${s.failed} failed.`,D=ke(s.firstError,d);m(D===d?d:`${d} ${D}`)}else s.updated>0?m(`${o} ${s.updated} decision${s.updated===1?"":"s"}.`):m("No decisions were updated.");W(new Set)}catch(s){const o=s instanceof Error?s.message:"";m(ke(o,"Bulk decision action failed."))}finally{v(!1),F(new Set)}},re=async r=>{if(!(g.has(r)||w)){m(null),F(a=>{const s=new Set(a);return s.add(r),s});try{const a=await C(r);a.failed>0?m(Me("approve",a.failed,a.firstError)):a.updated>0&&m("Decision approved.")}catch(a){const s=a instanceof Error?a.message:"";m(ke(s,"Decision approval failed."))}finally{F(a=>{const s=new Set(a);return s.delete(r),s}),W(a=>{if(!a.has(r))return a;const s=new Set(a);return s.delete(r),s})}}},ce=l.useCallback(r=>{g.has(r.id)||w||(P(a=>new Set(a).add(r.id)),xe({message:`Approved '${r.title.length>40?r.title.slice(0,40)+"…":r.title}'`,onUndo:()=>{P(a=>{const s=new Set(a);return s.delete(r.id),s})},onCommit:()=>{P(a=>{const s=new Set(a);return s.delete(r.id),s}),C(r.id).catch(()=>{m("Approval failed. Try again from the decision panel.")})}}))},[g,w,xe,C]);l.useEffect(()=>{if(!L)return;const r=window.setTimeout(()=>m(null),5200);return()=>window.clearTimeout(r)},[L]);const je=L!==null&&!L.toLowerCase().includes("fail"),j=w||g.size>0,de=Math.max(g.size,w?O:0),i=j?`Applying ${de} decision action${de===1?"":"s"}…`:L??null,n=j?"processing":L?je?"success":"warning":"idle",I=!$&&k.length<=32,B=S!==null&&S.ids.length>0&&!w,A=p.length;(pe=p[0])==null||pe.waitingMinutes;const Z=S!=null&&S.id.includes("visible")?"visible":"selected",x=(S==null?void 0:S.action)??"approve",ue=i!==null||n!=="idle",ye=X==="card"?Be:"div";return e.jsxs(ye,{className:ve("flex h-full min-h-0 flex-col",X==="card"&&"card-enter",E),children:[e.jsx(Ge,{open:u!==null,decision:oe,onClose:()=>T(null),onApprove:he,onReject:Ce,onNavigate:J,currentIndex:ee>=0?ee:void 0,totalCount:p.length}),R?e.jsxs("div",{className:"space-y-2.5 border-b border-subtle px-4 py-3.5",children:[e.jsx("div",{className:"flex items-start justify-between gap-3",children:e.jsxs("div",{className:"min-w-0",children:[e.jsxs("h2",{className:"inline-flex items-center gap-2 text-heading font-semibold text-white",children:[e.jsx(Q,{type:"decision",size:14}),"Decisions"]}),e.jsx("p",{className:"mt-0.5 text-caption text-secondary",children:A>0?`${A} decision${A===1?"":"s"} need${A===1?"s":""} your input`:"All clear — no decisions pending"})]})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[p.length>0&&e.jsx("button",{onClick:V,disabled:j,className:"control-pill h-8 flex-shrink-0 px-3 text-caption font-semibold disabled:opacity-45",children:H?"Clear all":"Select all"}),O>0&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:be,disabled:!B||j,"data-state":B?"active":"idle",className:"control-pill h-8 flex-shrink-0 px-3 text-caption font-semibold disabled:opacity-45",children:w?"Approving…":`Approve ${O} selected`}),b&&e.jsx("button",{type:"button",onClick:()=>me(Qe("reject",Z)),disabled:j,"data-state":x==="reject"?"active":"idle",className:ve("control-pill h-8 px-2.5 text-caption font-semibold disabled:opacity-45",x==="reject"&&"border-amber-300/35 bg-amber-400/[0.12] text-amber-100"),children:"Reject"})]})]}),ue?e.jsxs("div",{"aria-live":"polite",className:ve("flex min-h-[32px] items-center gap-2 rounded-lg border px-2.5 py-1.5 text-caption transition-colors",n==="processing"?"border-amber-300/25 bg-amber-400/[0.08] text-amber-100":n==="success"?"border-lime/30 bg-lime/10 text-lime":n==="warning"?"border-red-400/25 bg-red-500/[0.08] text-red-100":"border-strong bg-white/[0.02] text-secondary"),children:[n==="processing"?e.jsx("span",{"aria-hidden":!0,className:"h-3.5 w-3.5 rounded-full border-2 border-amber-200/45 border-t-transparent animate-spin"}):n==="success"?e.jsx(Q,{type:"decision",size:12,className:"opacity-90"}):n==="warning"?e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"opacity-90",children:[e.jsx("path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z"}),e.jsx("line",{x1:"12",x2:"12",y1:"9",y2:"13"}),e.jsx("line",{x1:"12",x2:"12.01",y1:"17",y2:"17"})]}):e.jsx("span",{"aria-hidden":!0,className:"h-1.5 w-1.5 rounded-full bg-white/35"}),e.jsx("span",{className:"min-w-0 truncate",children:i})]}):null]}):null,e.jsxs("div",{className:ve("min-h-0 flex-1 space-y-2 overflow-y-auto",R?"p-3":"p-0"),children:[p.length===0&&e.jsx("div",{className:"flex flex-col items-center gap-2.5 rounded-xl border border-subtle bg-white/[0.02] p-4 text-center",children:j?e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":!0,className:"h-5 w-5 rounded-full border-2 border-amber-200/45 border-t-transparent animate-spin"}),e.jsx("p",{className:"text-body text-secondary",children:"Finalizing decision updates…"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-faint",children:[e.jsx("path",{d:"M22 11.08V12a10 10 0 1 1-5.93-9.14"}),e.jsx("polyline",{points:"22 4 12 14.01 9 11.01"})]}),e.jsx("p",{className:"text-body text-secondary",children:"No pending decisions. All clear."})]})}),I?e.jsx(Ee,{mode:"popLayout",children:k.map((r,a)=>{const s=g.has(r.id),o=N.has(r.id);return e.jsx(se.article,{role:"button",tabIndex:0,onClick:()=>T(r.id),onKeyDown:d=>{(d.key==="Enter"||d.key===" ")&&(d.preventDefault(),T(r.id))},drag:!j&&!s?"x":!1,dragConstraints:{left:0,right:0},dragElastic:.3,onDragEnd:(d,D)=>{D.offset.x>120&&ce(r)},initial:w?{opacity:0,x:300}:{opacity:0,y:8,scale:.98},animate:{opacity:1,y:0,x:0,scale:1},exit:{opacity:0,x:300,scale:.95},transition:{duration:.25,ease:[.22,1,.36,1],...w?{delay:a*.04}:{}},layout:!0,className:"rounded-xl border bg-white/[0.03] px-3 py-2.5 transition-[border-color,box-shadow] cv-auto",style:{borderColor:o?`${M.lime}50`:"rgba(255, 255, 255, 0.1)",boxShadow:o?"0 0 0 1px rgba(191, 255, 0, 0.14)":"none"},children:e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx("input",{type:"checkbox",checked:o,onChange:()=>fe(r.id),disabled:s||j,onClick:d=>d.stopPropagation(),className:"mt-0.5 h-4 w-4 rounded border-white/20 bg-black/40 text-lime focus:ring-lime/40"}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"flex min-w-0 items-start gap-1.5 text-body font-medium text-white",title:r.title,children:[e.jsx(Q,{type:"decision",size:12,className:"mt-[3px] flex-shrink-0 opacity-90"}),e.jsx("span",{className:"line-clamp-2",children:r.title})]}),r.context&&e.jsx("p",{className:"mt-1 line-clamp-2 text-caption text-secondary",title:r.context,children:r.context}),e.jsxs("div",{className:"mt-1.5 flex items-center justify-between gap-2",children:[e.jsxs("p",{className:`min-w-0 truncate text-micro ${(()=>{const d=G(r.waitingMinutes);return d.tone==="urgent"?"text-red-400":d.tone==="attention"?"text-amber-400":"text-muted"})()}`,title:`${r.agentName??"OrgX Autopilot"} · ${G(r.waitingMinutes).text}`,children:[r.agentName??"OrgX Autopilot"," · ",G(r.waitingMinutes).text]}),e.jsx("button",{onClick:d=>{d.stopPropagation(),re(r.id)},disabled:s||j,className:"flex-shrink-0 rounded-md border border-lime/25 bg-lime/10 px-2.5 py-1 text-micro font-semibold text-lime transition-colors hover:bg-lime/20 disabled:cursor-not-allowed disabled:border-white/10 disabled:bg-white/[0.08] disabled:text-secondary",children:s?"Approving…":"Approve"}),b&&e.jsx("button",{onClick:d=>{d.stopPropagation(),T(r.id)},disabled:s||j,className:"flex-shrink-0 rounded-md border border-white/[0.08] bg-white/[0.03] px-2.5 py-1 text-micro font-semibold text-secondary transition-colors hover:border-red-400/30 hover:bg-red-400/[0.08] hover:text-red-300 disabled:cursor-not-allowed disabled:opacity-40",children:"Reject"})]})]})})]})},r.id)})}):e.jsx(e.Fragment,{children:k.map(r=>{const a=g.has(r.id),s=N.has(r.id);return e.jsx("article",{role:"button",tabIndex:0,onClick:()=>T(r.id),onKeyDown:o=>{(o.key==="Enter"||o.key===" ")&&(o.preventDefault(),T(r.id))},className:"rounded-xl border bg-white/[0.03] px-3 py-2.5 transition-[border-color,box-shadow] cv-auto",style:{borderColor:s?`${M.lime}50`:"rgba(255, 255, 255, 0.1)",boxShadow:s?"0 0 0 1px rgba(191, 255, 0, 0.14)":"none"},children:e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx("input",{type:"checkbox",checked:s,onChange:()=>fe(r.id),disabled:a||j,onClick:o=>o.stopPropagation(),className:"mt-0.5 h-4 w-4 rounded border-white/20 bg-black/40 text-lime focus:ring-lime/40"}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"flex min-w-0 items-start gap-1.5 text-body font-medium text-white",title:r.title,children:[e.jsx(Q,{type:"decision",size:12,className:"mt-[3px] flex-shrink-0 opacity-90"}),e.jsx("span",{className:"line-clamp-2",children:r.title})]}),r.context&&e.jsx("p",{className:"mt-1 line-clamp-2 text-caption text-secondary",title:r.context,children:r.context}),e.jsxs("div",{className:"mt-1.5 flex items-center justify-between gap-2",children:[e.jsxs("p",{className:`min-w-0 truncate text-micro ${(()=>{const o=G(r.waitingMinutes);return o.tone==="urgent"?"text-red-400":o.tone==="attention"?"text-amber-400":"text-muted"})()}`,title:`${r.agentName??"OrgX Autopilot"} · ${G(r.waitingMinutes).text}`,children:[r.agentName??"OrgX Autopilot"," · ",G(r.waitingMinutes).text]}),e.jsx("button",{onClick:o=>{o.stopPropagation(),re(r.id)},disabled:a||j,className:"flex-shrink-0 rounded-md border border-lime/25 bg-lime/10 px-2.5 py-1 text-micro font-semibold text-lime transition-colors hover:bg-lime/20 disabled:cursor-not-allowed disabled:border-white/10 disabled:bg-white/[0.08] disabled:text-secondary",children:a?"Approving…":"Approve"}),b&&e.jsx("button",{onClick:o=>{o.stopPropagation(),T(r.id)},disabled:a||j,className:"flex-shrink-0 rounded-md border border-white/[0.08] bg-white/[0.03] px-2.5 py-1 text-micro font-semibold text-secondary transition-colors hover:border-red-400/30 hover:bg-red-400/[0.08] hover:text-red-300 disabled:cursor-not-allowed disabled:opacity-40",children:"Reject"})]})]})})]})},r.id)})}),k.length<p.length&&e.jsxs("button",{onClick:()=>q(r=>Math.min(p.length,r+Ae)),className:"w-full rounded-xl border border-white/[0.08] bg-white/[0.02] px-3 py-2 text-caption text-secondary transition-colors hover:bg-white/[0.05]",children:["Load more (",p.length-k.length," remaining)"]})]}),e.jsx(ne,{})]})});export{it as DecisionQueue};
|
|
1
|
+
import{r as l,j as e}from"./cNrhgGc1.js";import{E as Q,d as M,w as $e,Z as G,o as _e,_ as Fe,$ as Pe,M as Le,h as Te,P as Be,y as ve}from"./CPjsbbgZ.js";import{E as De}from"./CgQDT6yL.js";import{A as Ee,m as se,u as Re}from"./CxQ08qFN.js";import{u as We}from"./CnitK1MX.js";import"./C-KIc3Wc.js";import"./BJgZIVUQ.js";const ze={pr:"⎋",file:"◇",artifact:"▪",log:"▸",decision:"◈"};function Ue(c){return c>=.8?"#BFFF00":c>=.5?"#F5B700":"#FF6B88"}function Oe(c){const t=c.match(/https?:\/\/\S+/);return t?t[0]:null}function Xe({evidenceType:c,title:t,summary:h,sourceUrl:y,confidence:C,payload:b,icon:I,label:f,onOpenTerminal:Y}){const[R,X]=l.useState(!1),E=t??f??null,$=c??(I?I.toUpperCase():null),w=I?ze[I]:null,v=I==="pr"&&f?Oe(f):null;return e.jsxs("div",{className:"rounded-xl border border-white/[0.06] bg-white/[0.02] px-3 py-2.5",children:[e.jsxs("div",{className:"flex items-start gap-2.5 cursor-pointer",onClick:()=>X(g=>!g),children:[($||w)&&e.jsxs("span",{className:"mt-0.5 flex-shrink-0 rounded bg-white/[0.06] px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wider text-secondary",children:[w?e.jsx("span",{className:"mr-1",children:w}):null,$]}),e.jsxs("div",{className:"min-w-0 flex-1",children:[E&&e.jsx("p",{className:"text-body font-medium text-primary",children:y?e.jsx("a",{href:y,target:"_blank",rel:"noopener noreferrer",className:"text-[#D8FFA1] hover:underline",onClick:g=>g.stopPropagation(),children:E}):v?e.jsx("a",{href:v,target:"_blank",rel:"noopener noreferrer",className:"text-[#D8FFA1] hover:underline",onClick:g=>g.stopPropagation(),children:E}):E}),h&&e.jsx("p",{className:`mt-0.5 text-caption text-secondary ${R?"":"line-clamp-2"}`,children:h})]}),e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:`mt-1 flex-shrink-0 text-muted transition-transform ${R?"rotate-180":""}`,children:e.jsx("path",{d:"m6 9 6 6 6-6"})})]}),C!=null&&e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("div",{className:"h-1 flex-1 overflow-hidden rounded-full bg-white/[0.06]",children:e.jsx("div",{className:"h-full rounded-full transition-all",style:{width:`${Math.round(C*100)}%`,backgroundColor:Ue(C)}})}),e.jsxs("span",{className:"text-micro text-muted tabular-nums",children:[Math.round(C*100),"%"]})]}),e.jsx(Ee,{children:R&&e.jsx(se.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.2},className:"overflow-hidden",children:e.jsxs("div",{className:"mt-2 space-y-2",children:[I==="log"&&Y&&e.jsxs("button",{type:"button",onClick:g=>{g.stopPropagation(),Y()},className:"inline-flex items-center gap-1.5 rounded-lg border border-white/[0.12] bg-white/[0.04] px-3 py-1.5 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.08]",children:[e.jsx("span",{className:"font-mono text-micro",children:">_"}),"Open in terminal"]}),b&&Object.keys(b).length>0&&e.jsx("pre",{className:"max-h-40 overflow-auto rounded-lg bg-black/40 p-2.5 text-micro text-secondary font-mono",children:JSON.stringify(b,null,2)})]})})})]})}function Je({segments:c}){return c.length===0?null:e.jsx("nav",{className:"flex items-center gap-1.5 min-w-0 text-caption text-secondary",children:c.map((t,h)=>e.jsxs("span",{className:"flex items-center gap-1.5 min-w-0",children:[h>0&&e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"flex-shrink-0 text-faint",children:e.jsx("path",{d:"m9 18 6-6-6-6"})}),t.icon&&e.jsx(Q,{type:t.icon,size:11,className:"flex-shrink-0 opacity-80"}),t.onClick?e.jsx("button",{type:"button",onClick:t.onClick,className:"truncate transition-colors hover:text-primary",children:t.label}):e.jsx("span",{className:"truncate",children:t.label})]},h))})}const Ie=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent);function Ke(c){try{return JSON.stringify(c,null,2)}catch{return null}}function qe(c){if(typeof c!="string")return null;const t=c.trim().toLowerCase();return t==="rejected"?"declined":t==="approved"||t==="declined"||t==="cancelled"?t:null}function Ne(c,t){return!c||c.trim().length===0?t:Te(c.trim())||t}function Ve(c){switch(c){case"spawn_guard_blocked":return"Spawn Guard";case"autopilot_failure":return"Autopilot Failure";case"budget_exceeded":return"Budget Exceeded";case"scope_change":return"Scope Change";case"conflict_resolution":return"Conflict Resolution";case"approval_required":return"Approval Required";case"review_required":return"Review Required";case"permission_request":return"Permission Request";default:return c.replace(/[_-]/g," ").replace(/\b\w/g,t=>t.toUpperCase())}}function Ze(c){const t=c.toLowerCase();return t==="critical"||t==="p0"?M.red:t==="high"||t==="p1"?M.amber:t==="medium"||t==="p2"?M.iris:"rgba(255,255,255,0.5)"}function Ge({open:c,decision:t,onClose:h,onApprove:y,onReject:C,initiativeTitle:b,workstreamTitle:I,onNavigate:f,currentIndex:Y,totalCount:R,onFocusRunId:X}){const[E,$]=l.useState("idle"),[w,v]=l.useState(null),[g,F]=l.useState(null),[N,W]=l.useState(""),[z,P]=l.useState(!1),[xe,ne]=l.useState(!1),[ie,me]=l.useState(!1),J=l.useRef(null),ae=l.useRef(),L=l.useRef(h);L.current=h,l.useEffect(()=>{if(c){$("idle"),v(null);const i=(t==null?void 0:t.selectedOptionId)??(t!=null&&t.options&&t.options.length===1?t.options[0].id:null);F(i),W(""),P(!1),ne(!1),me(!1)}return()=>{ae.current&&clearTimeout(ae.current)}},[c,t==null?void 0:t.id]);const m=t==null?void 0:t.metadata,le=l.useMemo(()=>{if(!m)return[];const i=m,n=i.decision_options??i.options??i.actions??null;if(!Array.isArray(n))return[];const _=[],B=new Set;for(let A=0;A<n.length;A+=1){const Z=n[A];if(typeof Z=="string"){const pe=Z.trim();if(!pe)continue;const r=`option-${A+1}`;if(B.has(r))continue;B.add(r),_.push({id:r,label:pe,description:null,impliedStatus:null,actionType:null,requiresNote:!1});continue}if(!Z||typeof Z!="object")continue;const x=Z,ue=typeof x.id=="string"&&x.id.trim()||typeof x.option_id=="string"&&x.option_id.trim()||typeof x.action_id=="string"&&x.action_id.trim()||`option-${A+1}`;if(B.has(ue))continue;const ye=typeof x.label=="string"&&x.label.trim()||typeof x.title=="string"&&x.title.trim()||typeof x.name=="string"&&x.name.trim()||typeof x.action=="string"&&x.action.trim()||null;ye&&(B.add(ue),_.push({id:ue,label:ye,description:typeof x.description=="string"?x.description:null,impliedStatus:qe(x.implied_status)??qe(x.status),actionType:typeof x.action_type=="string"&&x.action_type||typeof x.type=="string"&&x.type||null,requiresNote:x.requires_note===!0||x.requiresNote===!0||x.note_required===!0}))}return _.slice(0,12)},[m]),q=l.useMemo(()=>t!=null&&t.options&&t.options.length>0?t.options:le,[t==null?void 0:t.options,le]),u=l.useMemo(()=>q.find(i=>i.id===g)??null,[q,g]),T=l.useMemo(()=>{const i=((t==null?void 0:t.context)??"").trim();if(i)return i;if(!m)return"";const n=m,_=(typeof n.summary=="string"?n.summary:null)??(typeof n.description=="string"?n.description:null)??"";return String(_??"").trim()},[t==null?void 0:t.context,m]),U=l.useMemo(()=>{const i=(t==null?void 0:t.waitingMinutes)??0;return i>=15?M.red:i>=5?M.amber:M.teal},[t==null?void 0:t.waitingMinutes]),p=l.useCallback(async()=>{if(!t)return;const i=Ke({decision:t,metadata:m});if(i)try{await navigator.clipboard.writeText(i),ne(!0),setTimeout(()=>ne(!1),2e3)}catch{}},[t,m]),O=l.useCallback(()=>{const i=N.trim(),n=u==null?void 0:u.id;if(!(!i&&!n))return{note:i.length>0?i:void 0,optionId:n??void 0}},[N,u]),k=l.useCallback(async()=>{if(!t||!y)return;if(q.length>0&&!u){v("Select an option before approving this decision.");return}if(u!=null&&u.requiresNote&&N.trim().length===0){v("A note is required for the selected option."),P(!0),requestAnimationFrame(()=>{var n;return(n=J.current)==null?void 0:n.focus()});return}let i=!1;if($(n=>n==="approving"||n==="rejecting"?n:(i=!0,"approving")),!!i){v(null);try{const n=await y(t.id,O());n.failed>0?($("error"),v(Ne(n.firstError,"Approval failed. Please try again."))):($("success"),ae.current=setTimeout(()=>L.current(),800))}catch(n){$("error");const _=n instanceof Error?n.message:"";v(Ne(_,"Approval failed."))}}},[O,t,N,y,q.length,u]),H=l.useCallback(async()=>{if(!t||!C)return;if(q.length>0&&!u){v("Select an option before rejecting this decision.");return}if(u!=null&&u.requiresNote&&N.trim().length===0){v("A note is required for the selected option."),P(!0),requestAnimationFrame(()=>{var n;return(n=J.current)==null?void 0:n.focus()});return}let i=!1;if($(n=>n==="approving"||n==="rejecting"?n:(i=!0,"rejecting")),!!i){v(null);try{const n=await C(t.id,O());n.failed>0?($("error"),v(Ne(n.firstError,"Rejection failed. Please try again."))):($("rejected"),ae.current=setTimeout(()=>L.current(),800))}catch(n){$("error");const _=n instanceof Error?n.message:"";v(Ne(_,"Rejection failed."))}}},[O,t,N,C,q.length,u]);if(l.useEffect(()=>{if(!c)return;const i=n=>{var B;if((n.metaKey||n.ctrlKey)&&n.key==="Enter"){n.preventDefault(),k();return}const _=(B=n.target)==null?void 0:B.tagName;if(!(_==="INPUT"||_==="TEXTAREA"))switch(n.key){case"j":n.preventDefault(),f==null||f(1);break;case"k":n.preventDefault(),f==null||f(-1);break;case"a":n.preventDefault(),k();break;case"r":n.preventDefault(),H();break;case"n":n.preventDefault(),P(A=>!A),z||requestAnimationFrame(()=>{var A;return(A=J.current)==null?void 0:A.focus()});break}};return document.addEventListener("keydown",i),()=>document.removeEventListener("keydown",i)},[c,k,H,f,z]),!c||!t)return null;const oe=E==="approving"||E==="rejecting",ee=E==="success"||E==="rejected",K=(t.status??"pending").toLowerCase(),he=!K.includes("approved")&&!K.includes("resolved")&&!K.includes("rejected")&&!K.includes("declined")&&!K.includes("cancelled"),Ce=q.length>0&&!u,fe=(u==null?void 0:u.requiresNote)===!0&&N.trim().length===0,V=oe||Ce||fe,te=t.evidenceRefs??[],S=te.length>0,ge=t.recommendedAction??null,be=t.decisionType??null,re=t.priority??null,ce=t.occurrenceCount??null,je=t.sourceRunId??null,j=[];b&&j.push({label:b,icon:"initiative"}),I&&j.push({label:I,icon:"workstream"});const de=[["ID",t.id],["Type",t.decisionType],["Dedupe key",t.dedupeKey],["Source system",t.sourceSystem],["Conflict source",t.conflictSource],["Agent ID",t.agentId],["Source run",t.sourceRunId],["Source session",t.sourceSessionId],["Source stream",t.sourceStreamId]].filter(([,i])=>i!=null);if(ee){const i=E==="success",n=i?M.lime:M.red;return e.jsx($e,{open:c,onClose:h,maxWidth:"max-w-xl",fitContent:!0,children:e.jsxs("div",{className:"flex flex-col items-center justify-center px-8 py-12",children:[e.jsx("div",{className:"mb-4 flex h-16 w-16 items-center justify-center rounded-full",style:{backgroundColor:`${n}18`,border:`1.5px solid ${n}40`},children:i?e.jsx("svg",{width:"28",height:"28",viewBox:"0 0 24 24",fill:"none",stroke:n,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):e.jsxs("svg",{width:"28",height:"28",viewBox:"0 0 24 24",fill:"none",stroke:n,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 6L6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})}),e.jsx("p",{className:"text-heading font-semibold text-white",children:i?"Approved":"Rejected"}),e.jsx("p",{className:"mt-1 text-body text-secondary",children:t.title})]})})}return e.jsx($e,{open:c,onClose:h,maxWidth:"max-w-xl",children:e.jsxs("div",{className:"flex h-full min-h-0 w-full flex-col",children:[e.jsx("div",{className:"h-[2px] w-full flex-shrink-0",style:{background:`linear-gradient(90deg, ${U}60, ${U}20, transparent)`}}),f&&e.jsxs("div",{className:"flex items-center justify-between px-6 pt-3 pb-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>f(-1),className:"rounded p-1 text-muted hover:text-secondary hover:bg-white/[0.06] transition-colors",title:"Previous (k)",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"m15 18-6-6 6-6"})})}),e.jsx("button",{type:"button",onClick:()=>f(1),className:"rounded p-1 text-muted hover:text-secondary hover:bg-white/[0.06] transition-colors",title:"Next (j)",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"m9 18 6-6-6-6"})})}),Y!=null&&R!=null&&e.jsxs("span",{className:"text-micro text-muted tabular-nums",children:[Y+1," of ",R]})]}),e.jsx("button",{type:"button",onClick:h,"aria-label":"Close",className:"rounded p-1 text-muted hover:text-secondary hover:bg-white/[0.06] transition-colors",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M18 6 6 18M6 6l12 12"})})})]}),j.length>0&&e.jsx("div",{className:"px-6 pt-2",children:e.jsx(Je,{segments:j})}),e.jsxs("div",{className:"flex items-start justify-between gap-3 px-6 pt-4 pb-4",children:[e.jsx("div",{className:"min-w-0 flex-1",children:e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-lg",style:{backgroundColor:`${U}14`,border:`1px solid ${U}30`},children:e.jsx(Q,{type:"decision",size:14})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h2",{className:"text-title font-medium leading-tight text-white mb-2",children:t.title||"Decision Required"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-body text-secondary",children:[e.jsx("span",{children:t.agentName||"OrgX Autopilot"}),e.jsx("span",{className:"text-white/[0.15]",children:"|"}),e.jsx("span",{children:G(t.waitingMinutes).text}),be&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-white/[0.15]",children:"|"}),e.jsx("span",{className:"text-primary",children:Ve(be)})]}),re&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-white/[0.15]",children:"|"}),e.jsx("span",{className:"font-medium",style:{color:Ze(re)},children:re})]})]}),ce!=null&&ce>1&&e.jsxs("p",{className:"mt-2 text-caption text-muted",children:["Seen ",ce," times",t.firstSeenAt&&e.jsxs(e.Fragment,{children:[" · first ",_e(t.firstSeenAt)]}),t.lastSeenAt&&e.jsxs(e.Fragment,{children:[" · last ",_e(t.lastSeenAt)]})]})]})]})}),!f&&e.jsx("button",{type:"button",onClick:h,"aria-label":"Close",className:"mt-0.5 flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-lg text-muted transition-colors hover:bg-white/[0.06] hover:text-white",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 6L6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto px-6 pb-4",children:[(t.initiativeId||t.workstreamId)&&e.jsx("div",{className:"mb-4",children:e.jsx(Fe,{nodes:Pe({initiativeId:t.initiativeId,initiativeTitle:b,workstreamId:t.workstreamId,workstreamTitle:I,agentName:t.agentName,agentId:t.agentId}),activeId:t.workstreamId,compact:!0})}),ge&&e.jsxs("div",{className:"mb-4 rounded-xl border border-cyan-300/[0.28] bg-cyan-500/[0.12] px-4 py-3",children:[e.jsx("p",{className:"text-micro font-semibold uppercase tracking-wider text-cyan-200 mb-1",children:"Recommended"}),e.jsx("p",{className:"text-body text-cyan-100",children:ge})]}),S&&e.jsxs("div",{className:"mb-4",children:[e.jsx("p",{className:"mb-2 px-1 text-micro font-semibold uppercase tracking-wider text-muted",children:"Evidence"}),e.jsx("div",{className:"space-y-1.5",children:te.map((i,n)=>e.jsx(Xe,{evidenceType:i.evidenceType,title:i.title,summary:i.summary,sourceUrl:i.sourceUrl,confidence:i.confidence,payload:i.payload},n))})]}),T?e.jsx("div",{className:"rounded-xl border border-white/[0.06] bg-white/[0.02] px-4 py-3",children:e.jsx(Le,{text:T,mode:"block"})}):e.jsx("p",{className:"px-1 text-body text-muted italic",children:"No additional context provided."}),q.length>0&&e.jsxs("div",{className:"mt-8",children:[e.jsx("p",{className:"mb-3 px-1 text-[11px] font-semibold uppercase tracking-widest text-muted",children:"Options"}),e.jsx("div",{className:"space-y-1 relative",children:q.map(i=>{const n=g===i.id;return e.jsxs("button",{type:"button",onClick:()=>{F(n?null:i.id),i.requiresNote&&P(!0)},disabled:oe,className:"group relative flex w-full items-start gap-4 px-4 py-4 text-left focus:outline-none",children:[n&&e.jsx(se.div,{layoutId:"decision-option-bg",className:"absolute inset-0 rounded-xl",style:{backgroundColor:`${M.lime}12`},transition:{type:"spring",stiffness:400,damping:25}}),!n&&e.jsx("div",{className:"absolute inset-0 rounded-xl opacity-0 transition-opacity group-hover:bg-white/[0.03]"}),e.jsx("div",{className:"relative mt-0.5 flex h-5 w-5 flex-shrink-0 items-center justify-center rounded-full border-[1.5px] transition-colors",style:{borderColor:n?M.lime:"rgba(255,255,255,0.2)"},children:e.jsx(Ee,{children:n&&e.jsx(se.div,{initial:{scale:0},animate:{scale:1},exit:{scale:0},transition:{type:"spring",stiffness:500,damping:30},className:"h-2.5 w-2.5 rounded-full",style:{backgroundColor:M.lime}})})}),e.jsxs("div",{className:"relative min-w-0 flex-1",children:[e.jsx("span",{className:`block text-[15px] ${n?"font-medium text-white":"text-primary"}`,children:i.label}),i.description&&e.jsx("p",{className:"mt-1 text-[13px] leading-relaxed text-secondary",children:i.description}),i.requiresNote&&e.jsx("p",{className:"mt-1.5 text-[11px] font-medium uppercase tracking-wider text-amber-400",children:"Note required"})]})]},i.id)})})]}),he&&e.jsxs("div",{className:"mt-4",children:[e.jsxs("button",{type:"button",onClick:()=>{P(i=>!i),z||requestAnimationFrame(()=>{var i;return(i=J.current)==null?void 0:i.focus()})},className:"flex w-full items-center gap-2 px-1 text-caption text-secondary transition-colors hover:text-white",children:[e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"transition-transform",style:{transform:z?"rotate(90deg)":"rotate(0deg)"},children:e.jsx("polyline",{points:"9 18 15 12 9 6"})}),"Add a note"]}),z&&e.jsxs("div",{className:"mt-2",children:[e.jsx("textarea",{ref:J,value:N,onChange:i=>W(i.target.value),disabled:oe,placeholder:"Optional context for this decision...",rows:3,className:"w-full resize-none rounded-xl border border-white/[0.08] bg-white/[0.03] px-4 py-3 text-body text-primary placeholder-white/30 outline-none transition-colors focus:border-white/[0.16] focus:bg-white/[0.04]"}),(u==null?void 0:u.requiresNote)&&N.trim().length===0&&e.jsx("p",{className:"mt-2 text-caption text-amber-300",children:"This option requires a note before submission."})]})]}),je&&X&&e.jsx("div",{className:"mt-4",children:e.jsxs("button",{type:"button",onClick:()=>X(je),className:"inline-flex items-center gap-1.5 text-caption text-[#D8FFA1] transition-colors hover:text-white",children:[e.jsx(Q,{type:"session",size:12}),"View source run"]})}),e.jsx("div",{className:"mt-4 border-t border-white/[0.06] pt-4",children:e.jsx(De,{entityType:"decision",entityId:t.id})}),de.length>0&&e.jsxs("div",{className:"mt-4 border-t border-white/[0.06] pt-2",children:[e.jsxs("button",{type:"button",onClick:()=>me(i=>!i),className:"flex w-full items-center justify-between text-micro font-semibold uppercase tracking-wider text-muted hover:text-secondary transition-colors",children:[e.jsx("span",{children:"Technical details"}),e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:`transition-transform ${ie?"rotate-180":""}`,children:e.jsx("path",{d:"m6 9 6 6 6-6"})})]}),ie&&e.jsx("div",{className:"mt-2 space-y-0.5",children:de.map(([i,n])=>e.jsxs("div",{className:"flex gap-2 text-micro",children:[e.jsx("span",{className:"text-muted w-28 flex-shrink-0",children:i}),e.jsx("span",{className:"text-secondary truncate",children:n})]},i))})]}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-x-3 gap-y-1 text-micro text-muted opacity-60",children:[f&&e.jsx("span",{children:"j/k nav"}),e.jsx("span",{children:"a approve"}),e.jsx("span",{children:"r reject"}),e.jsx("span",{children:"n note"}),e.jsxs("span",{children:[Ie?"⌘":"Ctrl","+Enter approve"]}),e.jsx("span",{children:"esc close"})]})]}),w&&e.jsxs("div",{className:"flex items-center gap-2 border-t border-white/[0.06] px-6 py-3",children:[e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:M.red,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",x2:"12",y1:"8",y2:"12"}),e.jsx("line",{x1:"12",x2:"12.01",y1:"16",y2:"16"})]}),e.jsx("p",{className:"text-caption text-red-300",children:w})]}),he&&e.jsx("div",{className:"relative mt-auto border-t border-white/[0.04] bg-black/60 px-6 py-5 backdrop-blur-xl",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[C&&e.jsx(se.button,{whileTap:{scale:.97},type:"button",onClick:H,disabled:V,className:"rounded-lg px-4 py-2 text-[14px] font-medium text-secondary transition-colors hover:text-red-400 disabled:opacity-40 focus:outline-none",children:E==="rejecting"?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"inline-block h-3 w-3 animate-spin rounded-full border-[1.5px] border-current border-t-transparent"}),"Rejecting"]}):"Reject"}),e.jsx("button",{type:"button",onClick:p,className:"rounded-lg px-2 py-2 text-[13px] text-muted transition-colors hover:text-secondary focus:outline-none",title:"Copy decision as JSON",children:xe?"Copied":"Copy JSON"})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("span",{className:"hidden text-[13px] text-muted sm:block",children:[Ie?"⌘":"Ctrl","+Enter"]}),e.jsx(se.button,{whileTap:!y||V?void 0:{scale:.97},type:"button",onClick:k,disabled:!y||V,"data-modal-autofocus":"true",className:"rounded-lg px-6 py-2.5 text-[14px] font-semibold transition-all focus:outline-none",style:{backgroundColor:!y||V?"rgba(255,255,255,0.06)":M.lime,color:!y||V?"rgba(255,255,255,0.4)":"#000"},children:E==="approving"?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"inline-block h-3 w-3 animate-spin rounded-full border-[1.5px] border-black/40 border-t-black"}),"Approving"]}):"Approve"})]})]})})]})})}const Ae=40;function ke(c,t){return!c||c.trim().length===0?t:Te(c.trim())||t}function Me(c,t,h){const y=c==="approve"?`Approval failed for ${t} decision${t===1?"":"s"}.`:`Rejection failed for ${t} decision${t===1?"":"s"}.`;return ke(h,y)}function Qe(c,t){return`${c}_${t}`}const it=l.memo(function({decisions:t,focusDecisionId:h=null,onFocusDecisionHandled:y,onApproveDecision:C,onRejectDecision:b,onApproveAll:I,onBulkDecisionAction:f,mutationState:Y,showHeader:R=!0,panelStyle:X="card",className:E}){var pe;const $=Re(),[w,v]=l.useState(!1),[g,F]=l.useState(new Set),[N,W]=l.useState(new Set),[z,P]=l.useState(new Set),{enqueue:xe,ToastRenderer:ne}=We(),[ie,me]=l.useState("approve_selected"),[J,ae]=l.useState(""),[L,m]=l.useState(null),[le,q]=l.useState(Ae),[u,T]=l.useState(null),U=l.useRef(null),p=l.useMemo(()=>{const r=new Set;return[...t].filter(a=>r.has(a.id)?!1:(r.add(a.id),!0)).sort((a,s)=>{if(a.waitingMinutes!==s.waitingMinutes)return s.waitingMinutes-a.waitingMinutes;const o=Date.parse(a.requestedAt??a.updatedAt??""),d=Date.parse(s.requestedAt??s.updatedAt??""),D=Number.isFinite(o)?o:0;return(Number.isFinite(d)?d:0)-D})},[t]);l.useEffect(()=>{W(r=>{const a=new Set(p.map(o=>o.id)),s=new Set;for(const o of r)a.has(o)&&s.add(o);return s})},[p]);const O=N.size,k=l.useMemo(()=>p.filter(r=>!z.has(r.id)).slice(0,le),[p,le,z]),H=l.useMemo(()=>{if(k.length===0)return!1;for(const r of k)if(!N.has(r.id))return!1;return!0},[N,k]),oe=l.useMemo(()=>u?p.find(r=>r.id===u)??null:null,[u,p]),ee=l.useMemo(()=>u?p.findIndex(r=>r.id===u):-1,[u,p]),K=l.useCallback(r=>{const a=ee+r;a>=0&&a<p.length&&T(p[a].id)},[ee,p]),he=async(r,a)=>{m(null),F(o=>{const d=new Set(o);return d.add(r),d});const s=await C(r,a);return s.failed>0?m(Me("approve",s.failed,s.firstError)):s.updated>0&&m("Decision approved. Changes synced."),F(o=>{const d=new Set(o);return d.delete(r),d}),s},Ce=b?async(r,a)=>{m(null),F(o=>{const d=new Set(o);return d.add(r),d});const s=await b(r,a);return s.failed>0?m(Me("reject",s.failed,s.firstError)):s.updated>0&&m("Decision rejected. Changes synced."),F(o=>{const d=new Set(o);return d.delete(r),d}),s}:void 0;l.useEffect(()=>{q(r=>p.length===0?0:Math.min(Math.max(Ae,r),p.length))},[p.length]),l.useEffect(()=>{const r=(h??"").trim();if(!r){U.current=null;return}U.current===r||!p.some(s=>s.id===r)||(U.current=r,T(r),y==null||y(r))},[h,y,p]);const fe=r=>{W(a=>{const s=new Set(a);return s.has(r)?s.delete(r):s.add(r),s})},V=()=>{W(r=>{if(k.length===0)return r;const a=new Set(r),s=H;for(const o of k)s?a.delete(o.id):a.add(o.id);return a})},te=l.useMemo(()=>{const r=p.map(s=>s.id).filter(s=>N.has(s)),a=k.map(s=>s.id);return[{id:"approve_selected",label:`Approve selected (${r.length})`,action:"approve",ids:r},{id:"reject_selected",label:`Reject selected (${r.length})`,action:"reject",ids:r,hidden:!b},{id:"approve_visible",label:`Approve visible (${a.length})`,action:"approve",ids:a},{id:"reject_visible",label:`Reject visible (${a.length})`,action:"reject",ids:a,hidden:!b}].filter(s=>!s.hidden)},[b,N,p,k]),S=l.useMemo(()=>te.find(r=>r.id===ie)??te[0]??null,[ie,te]),ge=async(r,a,s)=>{if(r.length===0)return{updated:0,failed:0};if(a==="approve"&&r.length===p.length&&!s)return I();let o=0,d=0,D;for(const Se of r)try{const we=a==="approve"?await C(Se,s?{note:s}:void 0):b?await b(Se,s?{note:s}:void 0):{updated:0,failed:1};o+=we.updated,d+=we.failed,!D&&we.firstError&&(D=we.firstError)}catch{d+=1}return{updated:o,failed:d,firstError:D}},be=async()=>{if(!S||w)return;const r=S.ids;if(r.length===0){m("No decisions selected for this action.");return}m(null),v(!0),F(new Set(r));const a=J.trim();try{const s=f?await f(r,S.action,a.length>0?a:void 0):await ge(r,S.action,a.length>0?a:void 0),o=S.action==="approve"?"Approved":"Rejected";if(s.failed>0){const d=`${o} ${s.updated}; ${s.failed} failed.`,D=ke(s.firstError,d);m(D===d?d:`${d} ${D}`)}else s.updated>0?m(`${o} ${s.updated} decision${s.updated===1?"":"s"}.`):m("No decisions were updated.");W(new Set)}catch(s){const o=s instanceof Error?s.message:"";m(ke(o,"Bulk decision action failed."))}finally{v(!1),F(new Set)}},re=async r=>{if(!(g.has(r)||w)){m(null),F(a=>{const s=new Set(a);return s.add(r),s});try{const a=await C(r);a.failed>0?m(Me("approve",a.failed,a.firstError)):a.updated>0&&m("Decision approved.")}catch(a){const s=a instanceof Error?a.message:"";m(ke(s,"Decision approval failed."))}finally{F(a=>{const s=new Set(a);return s.delete(r),s}),W(a=>{if(!a.has(r))return a;const s=new Set(a);return s.delete(r),s})}}},ce=l.useCallback(r=>{g.has(r.id)||w||(P(a=>new Set(a).add(r.id)),xe({message:`Approved '${r.title.length>40?r.title.slice(0,40)+"…":r.title}'`,onUndo:()=>{P(a=>{const s=new Set(a);return s.delete(r.id),s})},onCommit:()=>{P(a=>{const s=new Set(a);return s.delete(r.id),s}),C(r.id).catch(()=>{m("Approval failed. Try again from the decision panel.")})}}))},[g,w,xe,C]);l.useEffect(()=>{if(!L)return;const r=window.setTimeout(()=>m(null),5200);return()=>window.clearTimeout(r)},[L]);const je=L!==null&&!L.toLowerCase().includes("fail"),j=w||g.size>0,de=Math.max(g.size,w?O:0),i=j?`Applying ${de} decision action${de===1?"":"s"}…`:L??null,n=j?"processing":L?je?"success":"warning":"idle",_=!$&&k.length<=32,B=S!==null&&S.ids.length>0&&!w,A=p.length;(pe=p[0])==null||pe.waitingMinutes;const Z=S!=null&&S.id.includes("visible")?"visible":"selected",x=(S==null?void 0:S.action)??"approve",ue=i!==null||n!=="idle",ye=X==="card"?Be:"div";return e.jsxs(ye,{className:ve("flex h-full min-h-0 flex-col",X==="card"&&"card-enter",E),children:[e.jsx(Ge,{open:u!==null,decision:oe,onClose:()=>T(null),onApprove:he,onReject:Ce,onNavigate:K,currentIndex:ee>=0?ee:void 0,totalCount:p.length}),R?e.jsxs("div",{className:"space-y-2.5 border-b border-subtle px-4 py-3.5",children:[e.jsx("div",{className:"flex items-start justify-between gap-3",children:e.jsxs("div",{className:"min-w-0",children:[e.jsxs("h2",{className:"inline-flex items-center gap-2 text-heading font-semibold text-white",children:[e.jsx(Q,{type:"decision",size:14}),"Decisions"]}),e.jsx("p",{className:"mt-0.5 text-caption text-secondary",children:A>0?`${A} decision${A===1?"":"s"} need${A===1?"s":""} your input`:"All clear — no decisions pending"})]})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[p.length>0&&e.jsx("button",{onClick:V,disabled:j,className:"control-pill h-8 flex-shrink-0 px-3 text-caption font-semibold disabled:opacity-45",children:H?"Clear all":"Select all"}),O>0&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:be,disabled:!B||j,"data-state":B?"active":"idle",className:"control-pill h-8 flex-shrink-0 px-3 text-caption font-semibold disabled:opacity-45",children:w?"Approving…":`Approve ${O} selected`}),b&&e.jsx("button",{type:"button",onClick:()=>me(Qe("reject",Z)),disabled:j,"data-state":x==="reject"?"active":"idle",className:ve("control-pill h-8 px-2.5 text-caption font-semibold disabled:opacity-45",x==="reject"&&"border-amber-300/35 bg-amber-400/[0.12] text-amber-100"),children:"Reject"})]})]}),ue?e.jsxs("div",{"aria-live":"polite",className:ve("flex min-h-[32px] items-center gap-2 rounded-lg border px-2.5 py-1.5 text-caption transition-colors",n==="processing"?"border-amber-300/25 bg-amber-400/[0.08] text-amber-100":n==="success"?"border-lime/30 bg-lime/10 text-lime":n==="warning"?"border-red-400/25 bg-red-500/[0.08] text-red-100":"border-strong bg-white/[0.02] text-secondary"),children:[n==="processing"?e.jsx("span",{"aria-hidden":!0,className:"h-3.5 w-3.5 rounded-full border-2 border-amber-200/45 border-t-transparent animate-spin"}):n==="success"?e.jsx(Q,{type:"decision",size:12,className:"opacity-90"}):n==="warning"?e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"opacity-90",children:[e.jsx("path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z"}),e.jsx("line",{x1:"12",x2:"12",y1:"9",y2:"13"}),e.jsx("line",{x1:"12",x2:"12.01",y1:"17",y2:"17"})]}):e.jsx("span",{"aria-hidden":!0,className:"h-1.5 w-1.5 rounded-full bg-white/35"}),e.jsx("span",{className:"min-w-0 truncate",children:i})]}):null]}):null,e.jsxs("div",{className:ve("min-h-0 flex-1 space-y-2 overflow-y-auto",R?"p-3":"p-0"),children:[p.length===0&&e.jsx("div",{className:"flex flex-col items-center gap-2.5 rounded-xl border border-subtle bg-white/[0.02] p-4 text-center",children:j?e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":!0,className:"h-5 w-5 rounded-full border-2 border-amber-200/45 border-t-transparent animate-spin"}),e.jsx("p",{className:"text-body text-secondary",children:"Finalizing decision updates…"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-faint",children:[e.jsx("path",{d:"M22 11.08V12a10 10 0 1 1-5.93-9.14"}),e.jsx("polyline",{points:"22 4 12 14.01 9 11.01"})]}),e.jsx("p",{className:"text-body text-secondary",children:"No pending decisions. All clear."})]})}),_?e.jsx(Ee,{mode:"popLayout",children:k.map((r,a)=>{const s=g.has(r.id),o=N.has(r.id);return e.jsx(se.article,{role:"button",tabIndex:0,onClick:()=>T(r.id),onKeyDown:d=>{(d.key==="Enter"||d.key===" ")&&(d.preventDefault(),T(r.id))},drag:!j&&!s?"x":!1,dragConstraints:{left:0,right:0},dragElastic:.3,onDragEnd:(d,D)=>{D.offset.x>120&&ce(r)},initial:w?{opacity:0,x:300}:{opacity:0,y:8,scale:.98},animate:{opacity:1,y:0,x:0,scale:1},exit:{opacity:0,x:300,scale:.95},transition:{duration:.25,ease:[.22,1,.36,1],...w?{delay:a*.04}:{}},layout:!0,className:"rounded-xl border bg-white/[0.03] px-3 py-2.5 transition-[border-color,box-shadow] cv-auto",style:{borderColor:o?`${M.lime}50`:"rgba(255, 255, 255, 0.1)",boxShadow:o?"0 0 0 1px rgba(191, 255, 0, 0.14)":"none"},children:e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx("input",{type:"checkbox",checked:o,onChange:()=>fe(r.id),disabled:s||j,onClick:d=>d.stopPropagation(),className:"mt-0.5 h-4 w-4 rounded border-white/20 bg-black/40 text-lime focus:ring-lime/40"}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"flex min-w-0 items-start gap-1.5 text-body font-medium text-white",title:r.title,children:[e.jsx(Q,{type:"decision",size:12,className:"mt-[3px] flex-shrink-0 opacity-90"}),e.jsx("span",{className:"line-clamp-2",children:r.title})]}),r.context&&e.jsx("p",{className:"mt-1 line-clamp-2 text-caption text-secondary",title:r.context,children:r.context}),e.jsxs("div",{className:"mt-1.5 flex items-center justify-between gap-2",children:[e.jsxs("p",{className:`min-w-0 truncate text-micro ${(()=>{const d=G(r.waitingMinutes);return d.tone==="urgent"?"text-red-400":d.tone==="attention"?"text-amber-400":"text-muted"})()}`,title:`${r.agentName??"OrgX Autopilot"} · ${G(r.waitingMinutes).text}`,children:[r.agentName??"OrgX Autopilot"," · ",G(r.waitingMinutes).text]}),e.jsx("button",{onClick:d=>{d.stopPropagation(),re(r.id)},disabled:s||j,className:"flex-shrink-0 rounded-md border border-lime/25 bg-lime/10 px-2.5 py-1 text-micro font-semibold text-lime transition-colors hover:bg-lime/20 disabled:cursor-not-allowed disabled:border-white/10 disabled:bg-white/[0.08] disabled:text-secondary",children:s?"Approving…":"Approve"}),b&&e.jsx("button",{onClick:d=>{d.stopPropagation(),T(r.id)},disabled:s||j,className:"flex-shrink-0 rounded-md border border-white/[0.08] bg-white/[0.03] px-2.5 py-1 text-micro font-semibold text-secondary transition-colors hover:border-red-400/30 hover:bg-red-400/[0.08] hover:text-red-300 disabled:cursor-not-allowed disabled:opacity-40",children:"Reject"})]})]})})]})},r.id)})}):e.jsx(e.Fragment,{children:k.map(r=>{const a=g.has(r.id),s=N.has(r.id);return e.jsx("article",{role:"button",tabIndex:0,onClick:()=>T(r.id),onKeyDown:o=>{(o.key==="Enter"||o.key===" ")&&(o.preventDefault(),T(r.id))},className:"rounded-xl border bg-white/[0.03] px-3 py-2.5 transition-[border-color,box-shadow] cv-auto",style:{borderColor:s?`${M.lime}50`:"rgba(255, 255, 255, 0.1)",boxShadow:s?"0 0 0 1px rgba(191, 255, 0, 0.14)":"none"},children:e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx("input",{type:"checkbox",checked:s,onChange:()=>fe(r.id),disabled:a||j,onClick:o=>o.stopPropagation(),className:"mt-0.5 h-4 w-4 rounded border-white/20 bg-black/40 text-lime focus:ring-lime/40"}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"flex min-w-0 items-start gap-1.5 text-body font-medium text-white",title:r.title,children:[e.jsx(Q,{type:"decision",size:12,className:"mt-[3px] flex-shrink-0 opacity-90"}),e.jsx("span",{className:"line-clamp-2",children:r.title})]}),r.context&&e.jsx("p",{className:"mt-1 line-clamp-2 text-caption text-secondary",title:r.context,children:r.context}),e.jsxs("div",{className:"mt-1.5 flex items-center justify-between gap-2",children:[e.jsxs("p",{className:`min-w-0 truncate text-micro ${(()=>{const o=G(r.waitingMinutes);return o.tone==="urgent"?"text-red-400":o.tone==="attention"?"text-amber-400":"text-muted"})()}`,title:`${r.agentName??"OrgX Autopilot"} · ${G(r.waitingMinutes).text}`,children:[r.agentName??"OrgX Autopilot"," · ",G(r.waitingMinutes).text]}),e.jsx("button",{onClick:o=>{o.stopPropagation(),re(r.id)},disabled:a||j,className:"flex-shrink-0 rounded-md border border-lime/25 bg-lime/10 px-2.5 py-1 text-micro font-semibold text-lime transition-colors hover:bg-lime/20 disabled:cursor-not-allowed disabled:border-white/10 disabled:bg-white/[0.08] disabled:text-secondary",children:a?"Approving…":"Approve"}),b&&e.jsx("button",{onClick:o=>{o.stopPropagation(),T(r.id)},disabled:a||j,className:"flex-shrink-0 rounded-md border border-white/[0.08] bg-white/[0.03] px-2.5 py-1 text-micro font-semibold text-secondary transition-colors hover:border-red-400/30 hover:bg-red-400/[0.08] hover:text-red-300 disabled:cursor-not-allowed disabled:opacity-40",children:"Reject"})]})]})})]})},r.id)})}),k.length<p.length&&e.jsxs("button",{onClick:()=>q(r=>Math.min(p.length,r+Ae)),className:"w-full rounded-xl border border-white/[0.08] bg-white/[0.02] px-3 py-2 text-caption text-secondary transition-colors hover:bg-white/[0.05]",children:["Load more (",p.length-k.length," remaining)"]})]}),e.jsx(ne,{})]})});export{it as DecisionQueue};
|
|
Binary file
|
|
Binary file
|