@useorgx/openclaw-plugin 0.7.6 → 0.7.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/dashboard/dist/assets/{CnitK1MX.js → AqVoI3SF.js} +1 -1
  2. package/dashboard/dist/assets/AqVoI3SF.js.br +0 -0
  3. package/dashboard/dist/assets/AqVoI3SF.js.gz +0 -0
  4. package/dashboard/dist/assets/BC4WvnHJ.js +1 -0
  5. package/dashboard/dist/assets/BC4WvnHJ.js.br +0 -0
  6. package/dashboard/dist/assets/BC4WvnHJ.js.gz +0 -0
  7. package/dashboard/dist/assets/{DOFL9l8s.js → BG5mwTkg.js} +1 -1
  8. package/dashboard/dist/assets/BG5mwTkg.js.br +0 -0
  9. package/dashboard/dist/assets/BG5mwTkg.js.gz +0 -0
  10. package/dashboard/dist/assets/BNh-XYPV.js +1 -0
  11. package/dashboard/dist/assets/BNh-XYPV.js.br +0 -0
  12. package/dashboard/dist/assets/BNh-XYPV.js.gz +0 -0
  13. package/dashboard/dist/assets/{CFwPph5U.js → BepW_590.js} +1 -1
  14. package/dashboard/dist/assets/BepW_590.js.br +0 -0
  15. package/dashboard/dist/assets/BepW_590.js.gz +0 -0
  16. package/dashboard/dist/assets/BerAfzjq.js +1 -0
  17. package/dashboard/dist/assets/BerAfzjq.js.br +0 -0
  18. package/dashboard/dist/assets/BerAfzjq.js.gz +0 -0
  19. package/dashboard/dist/assets/Bp3N-QL5.js +212 -0
  20. package/dashboard/dist/assets/Bp3N-QL5.js.br +0 -0
  21. package/dashboard/dist/assets/Bp3N-QL5.js.gz +0 -0
  22. package/dashboard/dist/assets/C3dZRz9P.css +1 -0
  23. package/dashboard/dist/assets/C3dZRz9P.css.br +0 -0
  24. package/dashboard/dist/assets/C3dZRz9P.css.gz +0 -0
  25. package/dashboard/dist/assets/CD-q5mdP.js +1 -0
  26. package/dashboard/dist/assets/CD-q5mdP.js.br +0 -0
  27. package/dashboard/dist/assets/CD-q5mdP.js.gz +0 -0
  28. package/dashboard/dist/assets/{BgcAY5rE.js → CdvjC9G9.js} +1 -1
  29. package/dashboard/dist/assets/CdvjC9G9.js.br +0 -0
  30. package/dashboard/dist/assets/CdvjC9G9.js.gz +0 -0
  31. package/dashboard/dist/assets/Ck2agw-s.js +1 -0
  32. package/dashboard/dist/assets/Ck2agw-s.js.br +0 -0
  33. package/dashboard/dist/assets/Ck2agw-s.js.gz +0 -0
  34. package/dashboard/dist/assets/{D7DHFX0D.js → D2CH1H6k.js} +1 -1
  35. package/dashboard/dist/assets/D2CH1H6k.js.br +0 -0
  36. package/dashboard/dist/assets/D2CH1H6k.js.gz +0 -0
  37. package/dashboard/dist/assets/D9esz7jd.js +1 -0
  38. package/dashboard/dist/assets/D9esz7jd.js.br +0 -0
  39. package/dashboard/dist/assets/D9esz7jd.js.gz +0 -0
  40. package/dashboard/dist/assets/{77gGFBt6.js → DCP-C7fn.js} +1 -1
  41. package/dashboard/dist/assets/DCP-C7fn.js.br +0 -0
  42. package/dashboard/dist/assets/DCP-C7fn.js.gz +0 -0
  43. package/dashboard/dist/assets/{CSr2ZnTV.js → DJASCd69.js} +1 -1
  44. package/dashboard/dist/assets/DJASCd69.js.br +0 -0
  45. package/dashboard/dist/assets/DJASCd69.js.gz +0 -0
  46. package/dashboard/dist/assets/Dm9AybAp.js +1 -0
  47. package/dashboard/dist/assets/Dm9AybAp.js.br +0 -0
  48. package/dashboard/dist/assets/Dm9AybAp.js.gz +0 -0
  49. package/dashboard/dist/assets/{DxKG5zy8.js → Du1wfrXa.js} +1 -1
  50. package/dashboard/dist/assets/Du1wfrXa.js.br +0 -0
  51. package/dashboard/dist/assets/Du1wfrXa.js.gz +0 -0
  52. package/dashboard/dist/assets/{DpuQm1oF.js → beHYBbh6.js} +1 -1
  53. package/dashboard/dist/assets/beHYBbh6.js.br +0 -0
  54. package/dashboard/dist/assets/beHYBbh6.js.gz +0 -0
  55. package/dashboard/dist/index.html +2 -2
  56. package/dashboard/dist/index.html.br +0 -0
  57. package/dashboard/dist/index.html.gz +0 -0
  58. package/dist/hash-utils.js +2 -1
  59. package/dist/http/helpers/auto-continue-engine.d.ts +36 -0
  60. package/dist/http/helpers/auto-continue-engine.js +83 -17
  61. package/dist/http/helpers/autopilot-runtime.d.ts +1 -0
  62. package/dist/http/helpers/autopilot-runtime.js +31 -3
  63. package/dist/http/helpers/autopilot-slice-utils.d.ts +10 -0
  64. package/dist/http/helpers/autopilot-slice-utils.js +58 -0
  65. package/dist/http/helpers/humanize-slice-failure.d.ts +35 -0
  66. package/dist/http/helpers/humanize-slice-failure.js +137 -0
  67. package/dist/http/helpers/mission-control.d.ts +1 -0
  68. package/dist/http/helpers/mission-control.js +72 -5
  69. package/dist/http/index.js +65 -3
  70. package/dist/http/routes/live-misc.js +12 -4
  71. package/dist/http/routes/live-snapshot.js +10 -4
  72. package/dist/http/routes/mission-control-actions.js +5 -0
  73. package/dist/http/routes/mission-control-read.d.ts +1 -0
  74. package/dist/http/routes/mission-control-read.js +65 -4
  75. package/dist/index.d.ts +8 -1
  76. package/dist/index.js +21 -1
  77. package/dist/mcp-http-handler.js +6 -0
  78. package/dist/openclaw.plugin.json +1 -1
  79. package/dist/tools/core-tools.d.ts +27 -0
  80. package/dist/tools/core-tools.js +89 -0
  81. package/openclaw.plugin.json +1 -1
  82. package/package.json +1 -1
  83. package/dashboard/dist/assets/77gGFBt6.js.br +0 -0
  84. package/dashboard/dist/assets/77gGFBt6.js.gz +0 -0
  85. package/dashboard/dist/assets/BBpTN_SR.js +0 -1
  86. package/dashboard/dist/assets/BBpTN_SR.js.br +0 -0
  87. package/dashboard/dist/assets/BBpTN_SR.js.gz +0 -0
  88. package/dashboard/dist/assets/BVShoyjA.js +0 -1
  89. package/dashboard/dist/assets/BVShoyjA.js.br +0 -0
  90. package/dashboard/dist/assets/BVShoyjA.js.gz +0 -0
  91. package/dashboard/dist/assets/BgcAY5rE.js.br +0 -0
  92. package/dashboard/dist/assets/BgcAY5rE.js.gz +0 -0
  93. package/dashboard/dist/assets/C-PAoJF-.js +0 -1
  94. package/dashboard/dist/assets/C-PAoJF-.js.br +0 -0
  95. package/dashboard/dist/assets/C-PAoJF-.js.gz +0 -0
  96. package/dashboard/dist/assets/C0nA-iUG.js +0 -1
  97. package/dashboard/dist/assets/C0nA-iUG.js.br +0 -0
  98. package/dashboard/dist/assets/C0nA-iUG.js.gz +0 -0
  99. package/dashboard/dist/assets/C6GO-FKy.js +0 -1
  100. package/dashboard/dist/assets/C6GO-FKy.js.br +0 -0
  101. package/dashboard/dist/assets/C6GO-FKy.js.gz +0 -0
  102. package/dashboard/dist/assets/CFwPph5U.js.br +0 -0
  103. package/dashboard/dist/assets/CFwPph5U.js.gz +0 -0
  104. package/dashboard/dist/assets/CPjsbbgZ.js +0 -212
  105. package/dashboard/dist/assets/CPjsbbgZ.js.br +0 -0
  106. package/dashboard/dist/assets/CPjsbbgZ.js.gz +0 -0
  107. package/dashboard/dist/assets/CSr2ZnTV.js.br +0 -0
  108. package/dashboard/dist/assets/CSr2ZnTV.js.gz +0 -0
  109. package/dashboard/dist/assets/CgQDT6yL.js +0 -1
  110. package/dashboard/dist/assets/CgQDT6yL.js.br +0 -0
  111. package/dashboard/dist/assets/CgQDT6yL.js.gz +0 -0
  112. package/dashboard/dist/assets/CnitK1MX.js.br +0 -0
  113. package/dashboard/dist/assets/CnitK1MX.js.gz +0 -0
  114. package/dashboard/dist/assets/D7DHFX0D.js.br +0 -0
  115. package/dashboard/dist/assets/D7DHFX0D.js.gz +0 -0
  116. package/dashboard/dist/assets/DEip7uko.js +0 -1
  117. package/dashboard/dist/assets/DEip7uko.js.br +0 -0
  118. package/dashboard/dist/assets/DEip7uko.js.gz +0 -0
  119. package/dashboard/dist/assets/DHUSLc01.css +0 -1
  120. package/dashboard/dist/assets/DHUSLc01.css.br +0 -0
  121. package/dashboard/dist/assets/DHUSLc01.css.gz +0 -0
  122. package/dashboard/dist/assets/DOFL9l8s.js.br +0 -0
  123. package/dashboard/dist/assets/DOFL9l8s.js.gz +0 -0
  124. package/dashboard/dist/assets/DpuQm1oF.js.br +0 -0
  125. package/dashboard/dist/assets/DpuQm1oF.js.gz +0 -0
  126. package/dashboard/dist/assets/DxKG5zy8.js.br +0 -0
  127. package/dashboard/dist/assets/DxKG5zy8.js.gz +0 -0
@@ -1 +0,0 @@
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};
@@ -1 +0,0 @@
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};
@@ -1 +0,0 @@
1
- import{r as h,j as e,u as Fe,a as oe,b as be}from"./cNrhgGc1.js";import{S as Ee,y as P,i as ae,b as J,T as Ie,m as Pe,V as De,w as Be,W as $e,X as le}from"./CPjsbbgZ.js";import{m as z,A as Ce}from"./CxQ08qFN.js";import{u as Me}from"./BBpTN_SR.js";import"./C-KIc3Wc.js";import"./BJgZIVUQ.js";function Te(t){switch(t){case"config":return"plugin configuration";case"environment":return"environment variable";case"persisted":return"saved credentials";case"openclaw-config-file":return"OpenClaw config";case"legacy-dev":return"legacy key";default:return""}}function Ue(t,s){return t==="connected"&&s?"connected":t==="awaiting_browser_auth"||t==="pairing"||t==="starting"?"connecting":t==="error"?"error":"idle"}function Le({phase:t}){const s=t==="connected"||t==="connecting"?"bg-[#BFFF00]":t==="error"?"bg-red-400":"bg-white/30",r=t==="connecting";return e.jsxs("span",{className:"relative flex h-2.5 w-2.5 shrink-0",children:[r&&e.jsx("span",{className:P("absolute inline-flex h-full w-full animate-ping rounded-full opacity-40",s)}),e.jsx("span",{className:P("relative inline-flex h-2.5 w-2.5 rounded-full",s)})]})}function Oe({phase:t}){const s=t==="connected"?"Connected":t==="connecting"?"Connecting...":t==="error"?"Connection issue":"Not connected",r=t==="connected"?"text-[#BFFF00]":t==="error"?"text-red-400":"text-primary";return e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(Le,{phase:t}),e.jsx("span",{className:P("text-body font-semibold",r),children:s})]})}function Ke({phase:t,hasApiKey:s,verified:r,workspaceName:l}){const n=[{id:"connect",label:"Connect",detail:"Provide credentials",done:s||r},{id:"verify",label:"Verify",detail:"Confirm live sync",done:r},{id:"scope",label:"Scope",detail:l||"Select workspace",done:t==="connected"}],w=t==="connecting"?"verify":t==="connected"?"scope":s?"verify":"connect";return e.jsx("ol",{className:"grid gap-2 rounded-xl border border-white/[0.08] bg-black/20 p-3 md:grid-cols-3",children:n.map((b,f)=>{const p=b.id===w;return e.jsxs("li",{className:"relative min-w-0",children:[f>0?e.jsx("span",{className:"pointer-events-none absolute -left-2 top-3 hidden h-px w-2 bg-white/[0.14] md:block","aria-hidden":!0}):null,e.jsxs("div",{className:P("rounded-lg border px-2.5 py-2",b.done?"border-lime/26 bg-lime/[0.08]":p?"border-teal/28 bg-teal/[0.10]":"border-white/[0.10] bg-white/[0.02]"),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:P("inline-flex h-4 w-4 items-center justify-center rounded-full border text-[10px] font-semibold",b.done?"border-lime/35 bg-lime/[0.18] text-[#D8FFA1]":p?"border-teal/35 bg-teal/[0.16] text-teal-100":"border-white/[0.14] bg-white/[0.03] text-secondary"),children:f+1}),e.jsx("p",{className:"truncate text-caption font-semibold text-primary",children:b.label})]}),e.jsx("p",{className:"mt-1 truncate text-micro text-secondary",children:b.detail})]})]},b.id)})})}function ce({label:t,value:s}){return e.jsxs("div",{className:"flex items-center justify-between gap-2 text-caption",children:[e.jsx("span",{className:"text-secondary",children:t}),e.jsx("span",{className:"text-primary",children:s})]})}function ze({state:t,isStarting:s,isSubmittingManual:r,workspaceOptions:l,selectedWorkspaceId:n,onSelectWorkspace:w,onRefresh:b,onStartPairing:f,onSubmitManualKey:p,onBackToPairing:A,onUseManualKey:N,onDisconnect:g}){const j="https://www.useorgx.com/settings#security",u=Ue(t.status,t.connectionVerified),q=t.status==="manual_key",x=t.status==="awaiting_browser_auth"||t.status==="pairing"||t.status==="starting",S=!!t.lastError,v=Te(t.keySource),y=h.useMemo(()=>u==="connected"?"Live sync is active. Initiatives, tasks, and activity flow in real time.":u==="connecting"?"Approve the pairing in your browser to finish connecting.":u==="error"?"Trouble reaching OrgX. Try reconnecting or use a manual API key.":t.hasApiKey?"An API key is present but the connection has not been verified yet.":"Connect to OrgX to sync initiatives, tasks, activity, and decisions.",[u,t.hasApiKey]),_=u==="connected"?"border-[#BFFF00]/15":u==="error"?"border-rose-400/20":"border-white/[0.07]";return e.jsxs("div",{className:"flex min-h-0 flex-col gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-heading font-semibold text-white",children:"OrgX connection"}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:y})]}),S&&e.jsx("div",{className:"rounded-xl border border-rose-300/20 bg-rose-400/10 px-4 py-3 text-body text-rose-100",children:t.lastError}),q?e.jsx(Ee,{isSubmitting:r,onSubmit:p,onBack:A}):e.jsxs("div",{className:P("rounded-2xl border bg-white/[0.02] p-5",_),children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 border-b border-white/[0.06] pb-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-[#D8FFA1]/80",children:"Connection status"}),e.jsx("div",{className:"mt-1",children:e.jsx(Oe,{phase:u})})]}),e.jsx("button",{type:"button",onClick:()=>{b()},className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-secondary transition-colors hover:bg-white/[0.06] hover:text-white",children:"Refresh"})]}),e.jsxs("div",{className:"mt-4 grid gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"mb-2 text-micro uppercase tracking-[0.12em] text-secondary",children:"Lifecycle"}),e.jsx(Ke,{phase:u,hasApiKey:t.hasApiKey,verified:t.connectionVerified,workspaceName:t.workspaceName})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-black/20 px-3.5 py-3",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Credential snapshot"}),e.jsxs("div",{className:"mt-2.5 grid gap-1.5",children:[e.jsx(ce,{label:"API key",value:t.hasApiKey?"Detected":"Missing"}),e.jsx(ce,{label:"Verification",value:t.connectionVerified?"Verified":"Not verified"}),e.jsx(ce,{label:"Source",value:v||"none"})]})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-black/20 px-3.5 py-3",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Workspace scope"}),u==="connected"?e.jsxs("div",{className:"mt-2",children:[e.jsx("label",{htmlFor:"settings-workspace-scope",className:"sr-only",children:"Workspace scope"}),e.jsxs("div",{className:"relative",children:[e.jsxs("select",{id:"settings-workspace-scope",value:n??"__all__",onChange:k=>{const B=k.target.value;w(B==="__all__"?null:B)},className:"h-9 w-full appearance-none rounded-full border border-strong bg-white/[0.03] pl-3 pr-9 text-body font-semibold text-primary focus:outline-none focus-visible:ring-2 focus-visible:ring-lime/40",title:"Select workspace scope",children:[e.jsx("option",{value:"__all__",children:"All workspaces"}),l.map(k=>e.jsx("option",{value:k.id,children:k.title},k.id))]}),e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"pointer-events-none absolute right-3 top-1/2 -translate-y-1/2 text-secondary",children:e.jsx("path",{d:"m6 9 6 6 6-6"})})]}),e.jsxs("p",{className:"mt-1.5 text-caption text-muted",children:["Connected account: ",e.jsx("span",{className:"text-secondary",children:t.workspaceName??"Unknown"})]})]}):e.jsx("p",{className:"mt-2 text-caption leading-relaxed text-secondary",children:"Selectable after verification completes."})]})]}),x&&t.connectUrl&&e.jsxs("div",{className:"rounded-xl border border-[#BFFF00]/20 bg-[#BFFF00]/[0.06] px-4 py-3",children:[e.jsx("p",{className:"text-caption uppercase tracking-[0.1em] text-[#D8FFA1]",children:"Pairing pending"}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:"A browser tab should have opened. Approve the connection to finish."}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsx("a",{href:t.connectUrl,target:"_blank",rel:"noopener noreferrer",className:"rounded-full border border-[#BFFF00]/30 bg-[#BFFF00]/15 px-3 py-1.5 text-caption font-semibold text-[#D8FFA1] transition-colors hover:bg-[#BFFF00]/25",children:"Open approval page"}),t.expiresAt&&e.jsxs("span",{className:"text-caption text-muted",children:["Expires ",new Date(t.expiresAt).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})]})]})]})]}),u==="idle"&&t.hasApiKey&&!t.connectionVerified&&e.jsxs("p",{className:"mt-3 text-caption text-amber-200/70",children:["Key detected",v?` from ${v}`:""," but not yet verified. Refresh or reconnect to activate live sync."]}),e.jsx("div",{className:P("mt-4 flex flex-wrap items-center gap-2 border-t border-white/[0.06] pt-4"),children:u==="connected"?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>{f()},disabled:s,className:"rounded-full border border-strong bg-white/[0.03] px-4 py-2 text-body font-semibold text-primary transition-colors hover:bg-white/[0.06] disabled:cursor-not-allowed disabled:opacity-50",children:"Reconnect"}),e.jsx("button",{type:"button",onClick:()=>{g()},className:"rounded-full border border-rose-300/20 bg-transparent px-4 py-2 text-body font-semibold text-rose-200/70 transition-colors hover:bg-rose-400/10",children:"Disconnect"}),e.jsx("a",{href:j,target:"_blank",rel:"noreferrer",className:"rounded-full border border-strong bg-white/[0.03] px-4 py-2 text-body font-semibold text-primary transition-colors hover:bg-white/[0.06]",children:"Manage API keys"})]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>{f()},disabled:s,"data-modal-autofocus":"true",className:"inline-flex items-center gap-2 rounded-full bg-[#BFFF00] px-4 py-2 text-body font-semibold text-black transition-colors hover:bg-[#d3ff42] disabled:cursor-not-allowed disabled:opacity-50",children:s?"Connecting...":"Connect in browser"}),e.jsx("button",{type:"button",onClick:N,className:"rounded-full border border-strong bg-white/[0.03] px-4 py-2 text-body font-semibold text-primary transition-colors hover:bg-white/[0.06]",children:"Use API key"}),t.hasApiKey&&e.jsx("button",{type:"button",onClick:()=>{g()},className:"rounded-full border border-rose-300/20 bg-transparent px-4 py-2 text-body font-semibold text-rose-200/70 transition-colors hover:bg-rose-400/10",children:"Disconnect"})]})})]}),u!=="connected"&&e.jsxs("p",{className:"text-caption leading-relaxed text-muted",children:["Prefer user-scoped keys (",e.jsx("code",{className:"rounded bg-black/40 px-1",children:"oxk_..."}),"). They don't require a separate userId header."]})]})}const Ve=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;function Re(t){if(typeof t!="string")return null;const s=t.trim();return Ve.test(s)?s:null}const K={decisionV2Enabled:!0,decisionDedupeEnabled:!0,decisionEvidenceRequiredForBlocking:!1,decisionAutoResolveGuardedEnabled:!0,questionAutoAnswerEnabled:!0,questionAutoAnswerTimeoutSec:60,questionAutoAnswerPolicy:"contextual",questionBlockingBehavior:"require_human",questionPolicyVersion:1,questionAutoAnswerDelaySeconds:60,questionAutoAnswerAction:"approve",customRunInstructions:""};function He(t){return{decisionV2Enabled:typeof(t==null?void 0:t.decision_v2_enabled)=="boolean"?t.decision_v2_enabled:K.decisionV2Enabled,decisionDedupeEnabled:typeof(t==null?void 0:t.decision_dedupe_enabled)=="boolean"?t.decision_dedupe_enabled:K.decisionDedupeEnabled,decisionEvidenceRequiredForBlocking:typeof(t==null?void 0:t.decision_evidence_required_for_blocking)=="boolean"?t.decision_evidence_required_for_blocking:K.decisionEvidenceRequiredForBlocking,decisionAutoResolveGuardedEnabled:typeof(t==null?void 0:t.decision_auto_resolve_guarded_enabled)=="boolean"?t.decision_auto_resolve_guarded_enabled:K.decisionAutoResolveGuardedEnabled,questionAutoAnswerEnabled:typeof(t==null?void 0:t.question_auto_answer_enabled)=="boolean"?t.question_auto_answer_enabled:K.questionAutoAnswerEnabled,questionAutoAnswerTimeoutSec:typeof(t==null?void 0:t.question_auto_answer_timeout_sec)=="number"&&Number.isFinite(t.question_auto_answer_timeout_sec)?Math.max(10,Math.min(3600,Math.floor(t.question_auto_answer_timeout_sec))):typeof(t==null?void 0:t.question_auto_answer_delay_seconds)=="number"&&Number.isFinite(t.question_auto_answer_delay_seconds)?Math.max(10,Math.min(3600,Math.floor(t.question_auto_answer_delay_seconds))):K.questionAutoAnswerTimeoutSec,questionAutoAnswerPolicy:(t==null?void 0:t.question_auto_answer_policy)==="approve_non_blocking"||(t==null?void 0:t.question_auto_answer_policy)==="defer_non_blocking"||(t==null?void 0:t.question_auto_answer_policy)==="contextual"?t.question_auto_answer_policy:K.questionAutoAnswerPolicy,questionBlockingBehavior:(t==null?void 0:t.question_blocking_behavior)==="guarded_auto_resolve_then_human"||(t==null?void 0:t.question_blocking_behavior)==="require_human"?t.question_blocking_behavior:K.questionBlockingBehavior,questionPolicyVersion:typeof(t==null?void 0:t.question_policy_version)=="number"&&Number.isFinite(t.question_policy_version)?Math.max(1,Math.min(10,Math.floor(t.question_policy_version))):K.questionPolicyVersion,questionAutoAnswerDelaySeconds:typeof(t==null?void 0:t.question_auto_answer_timeout_sec)=="number"&&Number.isFinite(t.question_auto_answer_timeout_sec)?Math.max(1,Math.min(900,Math.floor(t.question_auto_answer_timeout_sec))):typeof(t==null?void 0:t.question_auto_answer_delay_seconds)=="number"&&Number.isFinite(t.question_auto_answer_delay_seconds)?Math.max(1,Math.min(900,Math.floor(t.question_auto_answer_delay_seconds))):K.questionAutoAnswerDelaySeconds,questionAutoAnswerAction:(t==null?void 0:t.question_auto_answer_action)==="reject"?"reject":K.questionAutoAnswerAction,customRunInstructions:typeof(t==null?void 0:t.custom_run_instructions)=="string"?t.custom_run_instructions:K.customRunInstructions}}function Ge(t){return{id:t.id,name:typeof t.name=="string"&&t.name.trim().length>0?t.name:t.id,type:typeof t.type=="string"?t.type:"custom",status:typeof t.status=="string"?t.status:"active",model:typeof t.model=="string"?t.model:null,runtimeSettings:He(t.runtime_settings)}}function je(t){if(!t||t.ok!==!0||!t.data||t.data.ok!==!0)return{projectId:null,agents:[]};const s=t.data,r=Array.isArray(s.agents)?s.agents:s.agent?[s.agent]:[];return{projectId:Re(typeof s.workspace_id=="string"?s.workspace_id:typeof s.command_center_id=="string"?s.command_center_id:typeof s.project_id=="string"?s.project_id:null),agents:r.map(Ge)}}function qe({authToken:t=null,embedMode:s=!1,enabled:r=!0}={}){var g,j,u,q;const l=Fe(),n=ae(),w=h.useMemo(()=>["agent-suite",{authToken:t,embedMode:s}],[t,s]),b=h.useMemo(()=>["agent-suite-runtime-settings",{authToken:t,embedMode:s}],[t,s]),f=oe({queryKey:w,enabled:r,queryFn:async()=>{if(n)return{ok:!1,error:"Agent suite controls are unavailable in demo mode."};const x=await fetch("/orgx/api/agent-suite/status",{headers:J({authToken:t,embedMode:s})}),S=await x.json().catch(()=>null);return x.ok?S:{ok:!1,error:(S==null?void 0:S.error)??`Failed to load agent suite (${x.status})`}},staleTime:1e4}),p=oe({queryKey:b,enabled:r,queryFn:async()=>{if(n)return{projectId:null,agents:[]};const x=await fetch("/orgx/api/agent-suite/runtime-settings",{headers:J({authToken:t,embedMode:s})}),S=await x.json().catch(()=>null);if(!x.ok){const v=S==null?void 0:S.error,y=typeof v=="string"?v.trim():"",_=y.includes("<!DOCTYPE")||y.includes("<html"),k=x.status===404?"Agent runtime settings endpoint is not available in this plugin build.":y.length>0&&!_?y:`Failed to load agent runtime settings (${x.status})`;throw new Error(k)}return je(S??null)},staleTime:1e4}),A=be({mutationFn:async({dryRun:x,forceSkillPack:S}={})=>{if(n)return{ok:!1,error:"Agent suite install is unavailable in demo mode."};const v=await fetch("/orgx/api/agent-suite/install",{method:"POST",headers:J({authToken:t,embedMode:s,contentTypeJson:!0}),body:JSON.stringify({dryRun:!!x,forceSkillPack:!!S})}),y=await v.json().catch(()=>null);if(!v.ok)throw new Error((y==null?void 0:y.error)??`Failed to install agent suite (${v.status})`);return y},onSuccess:async()=>{await l.invalidateQueries({queryKey:w})}}),N=be({mutationFn:async x=>{if(n)return{projectId:null,agents:[]};const S=Re(x.projectId??null),v=await fetch("/orgx/api/agent-suite/runtime-settings",{method:"PATCH",headers:J({authToken:t,embedMode:s,contentTypeJson:!0}),body:JSON.stringify({...S?{workspace_id:S}:{},agent_id:x.agentId,runtime_settings:{decision_v2_enabled:x.runtimeSettings.decisionV2Enabled,decision_dedupe_enabled:x.runtimeSettings.decisionDedupeEnabled,decision_evidence_required_for_blocking:x.runtimeSettings.decisionEvidenceRequiredForBlocking,decision_auto_resolve_guarded_enabled:x.runtimeSettings.decisionAutoResolveGuardedEnabled,question_auto_answer_enabled:x.runtimeSettings.questionAutoAnswerEnabled,question_auto_answer_timeout_sec:x.runtimeSettings.questionAutoAnswerTimeoutSec,question_auto_answer_policy:x.runtimeSettings.questionAutoAnswerPolicy,question_blocking_behavior:x.runtimeSettings.questionBlockingBehavior,question_policy_version:x.runtimeSettings.questionPolicyVersion,question_auto_answer_delay_seconds:x.runtimeSettings.questionAutoAnswerDelaySeconds,question_auto_answer_action:x.runtimeSettings.questionAutoAnswerAction,custom_run_instructions:x.runtimeSettings.customRunInstructions}})}),y=await v.json().catch(()=>null);if(!v.ok)throw new Error((y==null?void 0:y.error)??`Failed to save agent runtime settings (${v.status})`);return je(y??null)},onSuccess:async()=>{await l.invalidateQueries({queryKey:b})}});return{status:f.data??null,isLoading:f.isLoading,isRefetching:f.isRefetching,error:(f.data&&"error"in f.data?f.data.error:null)??((g=f.error)==null?void 0:g.message)??null,installError:((j=A.error)==null?void 0:j.message)??null,runtimeSettings:p.data??{projectId:null,agents:[]},runtimeSettingsError:((u=p.error)==null?void 0:u.message)??null,isRuntimeSettingsLoading:p.isLoading,isRuntimeSettingsRefetching:p.isRefetching,refetchRuntimeSettings:p.refetch,saveRuntimeSettings:N.mutate,saveRuntimeSettingsAsync:N.mutateAsync,saveRuntimeSettingsError:((q=N.error)==null?void 0:q.message)??null,isSavingRuntimeSettings:N.isPending,refetchStatus:f.refetch,install:A.mutate,installAsync:A.mutateAsync,resetInstall:A.reset,installResult:A.data??null,isInstalling:A.isPending}}function W(t,s){return t===1?`${t} ${s}`:`${t} ${s}s`}function G({tone:t,children:s}){const r=h.useMemo(()=>t==="good"?"border-lime/25 bg-lime/[0.10] text-lime":t==="warn"?"border-amber-300/25 bg-amber-400/10 text-amber-100/90":"border-white/[0.10] bg-white/[0.02] text-primary",[t]);return e.jsx("span",{className:P("inline-flex items-center rounded-full border px-2.5 py-1 text-caption font-semibold",r),children:s})}function de({step:t,title:s,description:r,children:l}){return e.jsxs("section",{className:"grid gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-[#D8FFA1]/80",children:t}),e.jsx("h4",{className:"mt-1 text-heading font-semibold text-white",children:s}),e.jsx("p",{className:"mt-1 text-caption leading-relaxed text-secondary",children:r})]}),l]})}const ue={conservative:"Conservative",balanced:"Balanced",autonomous:"Autonomous"},Qe={conservative:"All approvals. Freeze and pin policy updates until manually reviewed.",balanced:"Smart defaults. Keep policy live but pinned to current checksum.",autonomous:"Max automation. Keep policy live and unpinned for newest updates."};function We(t){return t?t.frozen&&t.pinnedChecksum?"conservative":!t.frozen&&t.pinnedChecksum?"balanced":!t.frozen&&!t.pinnedChecksum?"autonomous":null:null}function Xe(t){return t==="conservative"?{frozen:!0,pinToCurrent:!0,reason:"Applied Conservative preset from Agent Settings UI"}:t==="balanced"?{frozen:!1,pinToCurrent:!0,reason:"Applied Balanced preset from Agent Settings UI"}:{frozen:!1,clearPin:!0,reason:"Applied Autonomous preset from Agent Settings UI"}}function Je({plan:t,agentId:s,sampleTaskId:r}){var N;const l=t.workspaceFiles.filter(g=>g.action!=="noop"),n=l.filter(g=>g.action==="conflict").length,w=l.filter(g=>g.action==="create").length,b=l.filter(g=>g.action==="update").length,f=[];n>0&&f.push(`${W(n,"managed file")} needs review before apply.`),t.skillPackUpdateAvailable&&f.push("Remote skill update is available; behavior could drift after refresh."),(N=t.skillPackPolicy)!=null&&N.frozen&&f.push("Skill pack is frozen; preview reflects pinned behavior only.");const p=[`Load draft simulation for ${s}.`,`Run sample task "${r}" through current suite guardrails.`,"Assemble managed/local overlay and compute write plan.",n>0?"Stop before apply because conflicts require operator review.":"Proceed to apply path if operator confirms."],A=[`${W(t.openclawConfigAddedAgents.length,"agent")} added to OpenClaw config.`,`${W(l.length,"workspace file")} changed (${w} create, ${b} update).`,`Progress stream expected at start and completion for sample "${r}".`];return{outcome:f.length>0?"warning":"ready",executionTrace:p,riskFlags:f,expectedOutputs:A,confidence:f.length>0?"Medium confidence: preview is deterministic but includes review-dependent flags.":"High confidence: preview is deterministic with no active risk flags."}}function Ye({authToken:t=null,embedMode:s=!1,enabled:r=!0,devMode:l=!1}){var M,Y,se,fe,ye;const[n,w]=h.useState(!1),[b,f]=h.useState(""),[p,A]=h.useState("triage-sample"),[N,g]=h.useState(null),[j,u]=h.useState(null),[q,x]=h.useState(!1),[S,v]=h.useState(null),[y,_]=h.useState(null),[k,B]=h.useState(null),[c,F]=h.useState(null),m=qe({authToken:t,embedMode:s,enabled:r}),o=(M=m.status)!=null&&M.ok?m.status.data:null,I=((Y=o==null?void 0:o.agents)==null?void 0:Y.length)??0,E=((se=o==null?void 0:o.openclawConfigAddedAgents)==null?void 0:se.length)??0,R=h.useMemo(()=>{var a;return((a=o==null?void 0:o.workspaceFiles)==null?void 0:a.filter(T=>T.action!=="noop"))??[]},[o]),D=R.length,X=h.useMemo(()=>R.filter(a=>a.action==="create").length,[R]),U=h.useMemo(()=>R.filter(a=>a.action==="update").length,[R]),$=h.useMemo(()=>R.filter(a=>a.action==="conflict").length,[R]),ee=h.useMemo(()=>{if(m.isLoading)return"Loading agent suite status...";if(m.error)return`Unable to read suite status: ${m.error}`;if(!o)return"Suite status unavailable.";if($>0)return`${W($,"file")} to review.`;if(E===0&&D===0)return"Suite is installed and up to date.";const a=[];return E>0&&a.push(`will add ${W(E,"agent")}`),D>0&&a.push(`will update ${W(D,"file")}`),`Preview: ${a.join(", ")}.`},[D,$,E,o,m.error,m.isLoading]),V=(fe=m.installResult)!=null&&fe.ok?m.installResult:null,L=!!(V!=null&&V.dryRun),H=We((o==null?void 0:o.skillPackPolicy)??null),i=async()=>{var T;if(!o||m.isInstalling||q)return;const a=b||(((T=o.agents[0])==null?void 0:T.id)??"unassigned-agent");w(!0),x(!0),u(null);try{const O=await m.installAsync({dryRun:!0});if(!O.ok)throw new Error(O.error??"Dry-run failed.");g(Je({plan:O.data,agentId:a,sampleTaskId:p})),v(new Date().toISOString())}catch(O){u(O instanceof Error?O.message:"Dry-run failed.")}finally{x(!1)}},d=async a=>{await fetch("/orgx/api/skill-pack/policy",{method:"POST",headers:J({authToken:t,embedMode:s,contentTypeJson:!0}),body:JSON.stringify(a)}).then(async T=>{if(!T.ok){const O=await T.json().catch(()=>null);throw new Error((O==null?void 0:O.error)??`Failed to update policy (${T.status})`)}}),await m.refetchStatus()},C=async a=>{if(!(!(o!=null&&o.skillPackPolicy)||y)){F(null),B(null),_(a);try{await d(Xe(a)),B(`${ue[a]} preset applied.`)}catch(T){F(T instanceof Error?T.message:"Failed to apply preset.")}finally{_(null)}}};return e.jsxs("div",{className:"rounded-2xl border border-white/[0.07] bg-white/[0.02] p-4",children:[e.jsx("div",{className:"flex flex-wrap items-start justify-between gap-3 border-b border-white/[0.06] pb-4",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-heading font-semibold text-white",children:"OrgX agent suite"}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:"Installs domain agents into your workspace (workspaces + guardrails + managed/local overlay)."})]})}),e.jsx("div",{className:"mt-4 grid gap-6",children:e.jsx(de,{step:"Subspace 01",title:"Execution controls",description:"Refresh status, run a deterministic dry-run, then apply suite updates.",children:e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-black/20 p-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>{m.resetInstall(),m.refetchStatus()},disabled:m.isRefetching,className:"rounded-full border border-strong bg-white/[0.03] px-4 py-2 text-body font-semibold text-primary transition-colors hover:bg-white/[0.06] disabled:cursor-not-allowed disabled:opacity-50",children:m.isRefetching?"Refreshing...":"Refresh"}),e.jsx("button",{type:"button",onClick:()=>{i()},disabled:m.isInstalling||q,className:"inline-flex min-h-[44px] items-center rounded-full border border-lime/30 bg-lime/[0.14] px-4 py-2 text-body font-semibold text-lime transition-colors hover:bg-lime/[0.2] disabled:cursor-not-allowed disabled:opacity-50",title:"Runs a sample dry-run against the current draft settings",children:q?"Testing config...":"Test This Config"}),e.jsx("button",{type:"button",onClick:()=>{m.install({dryRun:!1,forceSkillPack:!0})},disabled:m.isInstalling,className:"rounded-full border border-strong bg-white/[0.03] px-4 py-2 text-body font-semibold text-primary transition-colors hover:bg-white/[0.06] disabled:cursor-not-allowed disabled:opacity-50",title:"Forces a check for the latest OrgX skill pack and applies it (managed/local overlay preserves local edits)",children:"Refresh skills"}),e.jsx("button",{type:"button",onClick:()=>{m.install({dryRun:!1})},disabled:m.isInstalling,className:"inline-flex items-center gap-2 rounded-full bg-[#BFFF00] px-4 py-2 text-body font-semibold text-black transition-colors hover:bg-[#d3ff42] disabled:cursor-not-allowed disabled:opacity-50",title:"Install missing agents and scaffold managed workspace files",children:m.isInstalling?"Installing...":"Install / Update"})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsx(G,{tone:m.error?"warn":"neutral",children:ee}),o&&e.jsxs(e.Fragment,{children:[e.jsx(G,{tone:E===0?"good":"neutral",children:E===0?"agents configured":`${E} agents to install`}),e.jsxs(G,{tone:"neutral",children:[W(I,"agent")," total"]}),e.jsx(G,{tone:D===0?"good":"neutral",children:D===0?"no file changes":`${D} file changes`}),$>0&&e.jsx(G,{tone:"neutral",children:W($,"file to review")}),o.skillPackUpdateAvailable&&e.jsx(G,{tone:"warn",children:"skill update available"}),((ye=o.skillPackPolicy)==null?void 0:ye.frozen)&&e.jsx(G,{tone:"neutral",children:"skills frozen"})]})]}),e.jsxs("div",{className:"mt-3 grid gap-2 sm:grid-cols-3",children:[e.jsxs("div",{className:"rounded-lg border border-white/[0.08] bg-black/30 px-3 py-2",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Sequence 1"}),e.jsx("p",{className:"mt-1 text-caption font-semibold text-primary",children:"Run Test This Config"})]}),e.jsxs("div",{className:"rounded-lg border border-white/[0.08] bg-black/30 px-3 py-2",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Sequence 2"}),e.jsx("p",{className:"mt-1 text-caption font-semibold text-primary",children:"Apply preset or refresh skills"})]}),e.jsxs("div",{className:"rounded-lg border border-white/[0.08] bg-black/30 px-3 py-2",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Sequence 3"}),e.jsx("p",{className:"mt-1 text-caption font-semibold text-primary",children:"Install / Update with confidence"})]})]})]})})}),m.installError&&e.jsx("div",{className:"mt-3 rounded-xl border border-rose-300/20 bg-rose-400/10 px-4 py-3 text-body text-rose-100",children:m.installError}),V&&e.jsxs("div",{className:"mt-3 rounded-xl border border-lime/20 bg-lime/[0.06] px-4 py-3",children:[e.jsx("p",{className:"text-caption uppercase tracking-[0.1em] text-[#D8FFA1]",children:L?"Dry run":"Applied"}),e.jsxs("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:[l&&V.operationId&&e.jsxs(e.Fragment,{children:["Operation ",e.jsx("code",{className:"rounded bg-black/40 px-1",children:V.operationId})," "]}),L?"Computed the plan without writing any files.":"Installed config and refreshed managed files."]})]}),o&&e.jsxs("div",{className:"mt-4 grid gap-6",children:[e.jsx(de,{step:"Subspace 02",title:"Draft simulation",description:"Inspect expected execution trace, risk flags, and outputs before applying.",children:e.jsxs("div",{className:"rounded-xl border border-white/[0.07] bg-black/20 p-3",children:[e.jsx("p",{className:"text-body font-semibold text-primary",children:"Dry-run sample"}),e.jsx("p",{className:"mt-1 text-caption leading-relaxed text-secondary",children:"Validate expected behavior with draft settings before applying changes."}),e.jsxs("div",{className:"mt-3 grid gap-3 md:grid-cols-2",children:[e.jsxs("label",{className:"grid gap-1.5 text-caption text-secondary",children:["Agent",e.jsxs("select",{value:b,onChange:a=>f(a.target.value),className:"min-h-[44px] rounded-lg border border-white/[0.1] bg-white/[0.03] px-3 text-body text-primary outline-none transition-colors focus:border-lime/35",children:[e.jsx("option",{value:"",children:"Auto-select first pending agent"}),o.agents.map(a=>e.jsxs("option",{value:a.id,children:[a.name," (",a.id,")"]},a.id))]})]}),e.jsxs("label",{className:"grid gap-1.5 text-caption text-secondary",children:["Sample task",e.jsxs("select",{value:p,onChange:a=>A(a.target.value),className:"min-h-[44px] rounded-lg border border-white/[0.1] bg-white/[0.03] px-3 text-body text-primary outline-none transition-colors focus:border-lime/35",children:[e.jsx("option",{value:"triage-sample",children:"Triage sample"}),e.jsx("option",{value:"incident-template",children:"Incident template"}),e.jsx("option",{value:"handoff-summary",children:"Handoff summary"})]})]})]}),j&&e.jsx("p",{className:"mt-3 rounded-lg border border-rose-300/20 bg-rose-400/10 px-3 py-2 text-caption text-rose-100",children:j}),N&&e.jsxs("div",{role:"region","aria-live":"polite",className:"mt-3 rounded-lg border border-teal/30 bg-teal/[0.08] px-3 py-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("p",{className:"text-caption font-semibold uppercase tracking-[0.08em] text-teal",children:"Draft simulation"}),e.jsx(G,{tone:N.outcome==="ready"?"good":"warn",children:N.outcome==="ready"?"Ready to apply":"Review recommended"})]}),S&&e.jsx("p",{className:"mt-1 text-caption text-secondary",children:new Date(S).toLocaleString()}),e.jsxs("div",{className:"mt-3 grid gap-3 lg:grid-cols-3",children:[e.jsxs("div",{className:"rounded-lg border border-white/[0.08] bg-black/20 p-2.5",children:[e.jsx("p",{className:"text-caption font-semibold text-primary",children:"Execution trace"}),e.jsx("ol",{className:"mt-1.5 grid gap-1 text-caption text-secondary",children:N.executionTrace.map((a,T)=>e.jsxs("li",{children:[T+1,". ",a]},a))})]}),e.jsxs("div",{className:"rounded-lg border border-white/[0.08] bg-black/20 p-2.5",children:[e.jsx("p",{className:"text-caption font-semibold text-primary",children:"Risk flags"}),e.jsx("div",{className:"mt-1.5 grid gap-1 text-caption text-secondary",children:N.riskFlags.length>0?N.riskFlags.map(a=>e.jsx("p",{children:a},a)):e.jsx("p",{children:"No risk flags detected."})})]}),e.jsxs("div",{className:"rounded-lg border border-white/[0.08] bg-black/20 p-2.5",children:[e.jsx("p",{className:"text-caption font-semibold text-primary",children:"Expected outputs"}),e.jsxs("div",{className:"mt-1.5 grid gap-1 text-caption text-secondary",children:[N.expectedOutputs.map(a=>e.jsx("p",{children:a},a)),e.jsx("p",{className:"text-primary",children:N.confidence})]})]})]})]})]})}),e.jsxs(de,{step:"Subspace 03",title:"Suite internals",description:"Inspect policy state, agent roster, and managed/local file write plan.",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:"text-body font-semibold text-primary",children:"Suite details"}),e.jsx("button",{type:"button",onClick:()=>w(a=>!a),className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.06]",children:n?"Hide":"Show"})]}),n&&e.jsxs("div",{className:"mt-3 grid gap-3",children:[e.jsx("div",{className:"rounded-xl border border-white/[0.07] bg-black/20 p-3",children:e.jsxs("div",{className:"grid gap-1 text-body text-secondary",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("span",{children:"Workspace config"}),l?e.jsx("code",{className:"rounded bg-black/40 px-1.5 py-0.5 text-caption text-primary",children:o.openclawConfigPath}):e.jsx("span",{className:"text-caption text-primary",children:"Connected"})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("span",{children:"Agent workspaces"}),e.jsxs("code",{className:"rounded bg-black/40 px-1.5 py-0.5 text-caption text-primary",children:[o.suiteWorkspaceRoot,"/","{agent-id}"]})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("span",{children:"Pack"}),e.jsxs("code",{className:"rounded bg-black/40 px-1.5 py-0.5 text-caption text-primary",children:[o.packId,"@",o.packVersion]})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("span",{children:"Skill pack"}),e.jsx("code",{className:"rounded bg-black/40 px-1.5 py-0.5 text-caption text-primary",children:o.skillPack?`${o.skillPack.name}@${o.skillPack.version} (${o.skillPack.source})`:"builtin"})]}),o.skillPackRemote&&e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("span",{children:"Skill pack remote"}),e.jsxs("code",{className:"rounded bg-black/40 px-1.5 py-0.5 text-caption text-primary",children:[o.skillPackRemote.name,"@",o.skillPackRemote.version]})]}),o.skillPackPolicy&&e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("span",{children:"Skill pack policy"}),e.jsxs("code",{className:"rounded bg-black/40 px-1.5 py-0.5 text-caption text-primary",children:[o.skillPackPolicy.frozen?"frozen":"live",o.skillPackPolicy.pinnedChecksum?`, pinned:${o.skillPackPolicy.pinnedChecksum.slice(0,8)}…`:""]})]}),o.skillPackPolicy&&e.jsxs("div",{className:"mt-2 rounded-xl border border-white/[0.08] bg-white/[0.02] p-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("p",{className:"text-caption font-semibold uppercase tracking-[0.08em] text-secondary",children:"Execution presets"}),e.jsx(G,{tone:H?"good":"neutral",children:H?`Active: ${ue[H]}`:"Active: custom"})]}),e.jsx("p",{className:"mt-1 text-caption text-secondary",children:"Choose how much human approval vs automation your default behavior policy should use."}),e.jsx("div",{className:"mt-2 grid gap-2 sm:grid-cols-3",children:["conservative","balanced","autonomous"].map(a=>{const T=H===a,O=y===a;return e.jsxs("button",{type:"button",onClick:()=>{C(a)},disabled:!!y,className:P("min-h-[44px] rounded-lg border px-3 py-2 text-left transition-colors disabled:cursor-not-allowed disabled:opacity-50",T?"border-lime/35 bg-lime/[0.12] text-lime":"border-white/[0.12] bg-white/[0.03] text-primary hover:bg-white/[0.06]"),children:[e.jsx("p",{className:"text-body font-semibold",children:O?"Applying…":ue[a]}),e.jsx("p",{className:"mt-1 text-caption text-secondary",children:Qe[a]})]},a)})}),k&&e.jsx("p",{className:"mt-2 rounded-lg border border-lime/20 bg-lime/[0.07] px-2.5 py-2 text-caption text-[#D8FFA1]",children:k}),c&&e.jsx("p",{className:"mt-2 rounded-lg border border-rose-300/20 bg-rose-400/10 px-2.5 py-2 text-caption text-rose-100",children:c})]}),o.skillPackPolicy&&e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>{var a;d({frozen:!((a=o.skillPackPolicy)!=null&&a.frozen)})},className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.06]",children:o.skillPackPolicy.frozen?"Unfreeze skills":"Freeze skills"}),e.jsx("button",{type:"button",onClick:()=>{var a;(a=o.skillPackPolicy)!=null&&a.pinnedChecksum?d({clearPin:!0}):d({pinToCurrent:!0})},className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.06]",children:o.skillPackPolicy.pinnedChecksum?"Unpin":"Pin current"}),e.jsx("p",{className:"text-caption text-muted",children:"Freeze prevents background checks; pin prevents applying a new checksum."})]})]})}),e.jsxs("div",{className:"rounded-xl border border-white/[0.07] bg-black/20 p-3",children:[e.jsxs("p",{className:"text-body font-semibold text-primary",children:["Agents (",I,")"]}),e.jsx("div",{className:"mt-2 grid gap-2",children:o.agents.map(a=>e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 rounded-xl border border-subtle bg-white/[0.02] px-3 py-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-body font-semibold text-bright",children:a.name}),e.jsxs("p",{className:"mt-0.5 truncate text-caption text-secondary",children:[e.jsx("code",{className:"rounded bg-black/40 px-1",children:a.id}),e.jsx("span",{className:"px-1",children:"·"}),e.jsx("span",{children:a.domain})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(G,{tone:a.configuredInOpenclaw?"good":"neutral",children:a.configuredInOpenclaw?"configured":"to install"}),e.jsx(G,{tone:a.workspaceExists?"good":"neutral",children:a.workspaceExists?"workspace ok":"workspace missing"})]})]},a.id))})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.07] bg-black/20 p-3",children:[e.jsx("p",{className:"text-body font-semibold text-primary",children:"Planned file writes"}),e.jsxs("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:["Managed files are written to ",e.jsx("code",{className:"rounded bg-black/40 px-1",children:".orgx/managed"}),". Local overrides are read from ",e.jsx("code",{className:"rounded bg-black/40 px-1",children:".orgx/local"})," and appended into the composite files in the agent workspace root."]}),e.jsxs("div",{className:"mt-2 grid gap-1 text-caption text-secondary",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("span",{children:"Writes"}),e.jsx("span",{className:"text-primary",children:W(o.workspaceFiles.length,"file")})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("span",{children:"Creates/updates"}),e.jsx("span",{className:"text-primary",children:D})]}),(X>0||U>0)&&e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("span",{children:"Breakdown"}),e.jsxs("span",{className:"text-primary",children:[X>0?`${X} create`:"0 create",","," ",U>0?`${U} update`:"0 update"]})]})]}),E>0&&e.jsxs("div",{className:"mt-3 rounded-lg border border-white/[0.08] bg-white/[0.02] px-3 py-2",children:[e.jsx("p",{className:"text-caption font-semibold text-primary",children:"Agents to install"}),e.jsx("div",{className:"mt-1 flex flex-wrap gap-2",children:o.openclawConfigAddedAgents.map(a=>e.jsx("code",{className:"rounded-full border border-strong bg-black/40 px-2 py-0.5 text-caption text-primary",children:a},a))})]}),R.length>0&&e.jsxs("div",{className:"mt-3 rounded-lg border border-white/[0.08] bg-white/[0.02] px-3 py-2",children:[e.jsx("p",{className:"text-caption font-semibold text-primary",children:"Files that will change"}),e.jsxs("div",{className:"mt-2 grid gap-1.5",children:[R.slice(0,24).map(a=>e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 text-caption",children:[e.jsxs("code",{className:"rounded bg-black/40 px-1.5 py-0.5 text-primary",children:[a.agentId,"/",a.file]}),e.jsx("span",{className:"text-secondary",children:a.action})]},`${a.agentId}:${a.file}`)),R.length>24&&e.jsxs("p",{className:"text-caption text-muted",children:["Showing 24 of ",R.length,". Install/Update to apply all."]})]})]})]})]})]})]})]})}function we(t){return{ok:!0,updatedAt:null,providers:{openai:{configured:!!(t!=null&&t.openai),source:"none",masked:null},anthropic:{configured:!!(t!=null&&t.anthropic),source:"none",masked:null},openrouter:{configured:!!(t!=null&&t.openrouter),source:"none",masked:null}}}}function Ze(){return{ok:!0,agentId:"demo",providers:{openai:{ok:!1,error:"Demo mode does not run provider probes."},anthropic:{ok:!1,error:"Demo mode does not run provider probes."},openrouter:{ok:!1,error:"Demo mode does not run provider probes."}}}}function et({authToken:t=null,embedMode:s=!1,enabled:r=!0}={}){var A,N;const l=Fe(),n=h.useMemo(()=>["byok-settings",{authToken:t,embedMode:s}],[t,s]),w=h.useMemo(()=>["byok-health",{authToken:t,embedMode:s}],[t,s]),b=oe({queryKey:n,enabled:r,queryFn:async()=>{if(ae())return we();const g=await fetch("/orgx/api/settings/byok",{headers:J({authToken:t,embedMode:s})}),j=await g.json().catch(()=>null);return g.ok?j:{ok:!1,updatedAt:null,providers:{openai:{configured:!1,source:"none",masked:null},anthropic:{configured:!1,source:"none",masked:null},openrouter:{configured:!1,source:"none",masked:null}},error:(j==null?void 0:j.error)??`Failed to load settings (${g.status})`}},staleTime:15e3}),f=oe({queryKey:w,enabled:!1,queryFn:async()=>{if(ae())return Ze();const g=await fetch("/orgx/api/settings/byok/health",{headers:J({authToken:t,embedMode:s})}),j=await g.json().catch(()=>null);return g.ok?j:{ok:!1,agentId:"main",providers:{openai:{ok:!1,error:(j==null?void 0:j.error)??`Probe failed (${g.status})`},anthropic:{ok:!1,error:(j==null?void 0:j.error)??`Probe failed (${g.status})`},openrouter:{ok:!1,error:(j==null?void 0:j.error)??`Probe failed (${g.status})`}},error:(j==null?void 0:j.error)??`Probe failed (${g.status})`}}}),p=be({mutationFn:async g=>{if(ae())return we({openai:typeof g.openaiApiKey=="string"&&g.openaiApiKey.trim().length>0,anthropic:typeof g.anthropicApiKey=="string"&&g.anthropicApiKey.trim().length>0,openrouter:typeof g.openrouterApiKey=="string"&&g.openrouterApiKey.trim().length>0});const j=await fetch("/orgx/api/settings/byok",{method:"POST",headers:J({authToken:t,embedMode:s,contentTypeJson:!0}),body:JSON.stringify(g??{})}),u=await j.json().catch(()=>null);if(!j.ok)throw new Error((u==null?void 0:u.error)??`Failed to save settings (${j.status})`);return u},onSuccess:async()=>{await l.invalidateQueries({queryKey:n})}});return{status:b.data??null,isLoading:b.isLoading,error:((A=b.data)==null?void 0:A.error)??((N=b.error)==null?void 0:N.message)??null,refetchStatus:b.refetch,update:p.mutateAsync,isSaving:p.isPending,health:f.data??null,probe:f.refetch,isProbing:f.isFetching}}const ie=[{id:"openai",label:"OpenAI",hint:"Used for GPT models.",envVar:"OPENAI_API_KEY"},{id:"anthropic",label:"Anthropic",hint:"Used for Claude models.",envVar:"ANTHROPIC_API_KEY"},{id:"openrouter",label:"OpenRouter",hint:"Used for multi-vendor routing.",envVar:"OPENROUTER_API_KEY"}];function Ne(t){return t==="openai"?"openaiApiKey":t==="anthropic"?"anthropicApiKey":"openrouterApiKey"}function tt(t){var s;return((s=ie.find(r=>r.id===t))==null?void 0:s.label)??t}function me({step:t,title:s,description:r,children:l}){return e.jsxs("section",{className:"grid gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-[#D8FFA1]/80",children:t}),e.jsx("h4",{className:"mt-1 text-heading font-semibold text-white",children:s}),e.jsx("p",{className:"mt-1 text-caption leading-relaxed text-secondary",children:r})]}),l]})}function st({authToken:t=null,embedMode:s=!1,enabled:r=!0}){const l=et({authToken:t,embedMode:s,enabled:r}),n=l.status,w=l.health,[b,f]=h.useState({openai:"",anthropic:"",openrouter:""}),[p,A]=h.useState({openai:!1,anthropic:!1,openrouter:!1}),[N,g]=h.useState({openai:!1,anthropic:!1,openrouter:!1}),[j,u]=h.useState(null),[q,x]=h.useState(null);h.useEffect(()=>{r&&(f({openai:"",anthropic:"",openrouter:""}),A({openai:!1,anthropic:!1,openrouter:!1}),g({openai:!1,anthropic:!1,openrouter:!1}),u(null),x(null))},[r]);const S=h.useMemo(()=>n!=null&&n.ok?Number(n.providers.openai.configured)+Number(n.providers.anthropic.configured)+Number(n.providers.openrouter.configured):0,[n]),v=h.useMemo(()=>{var o;const c=ie.map(I=>{var D;const E=(D=n==null?void 0:n.providers)==null?void 0:D[I.id],R=p[I.id]&&b[I.id].trim().length>0;return{id:I.id,label:I.label,configured:R||!!(E!=null&&E.configured),source:R?"pending stored key":(E==null?void 0:E.source)??"none",pending:R?"save":"none"}}),F=c.filter(I=>I.configured),m=F.length===0?"Run preview: launch blocked until at least one provider key is configured.":F.length===1?`Run preview: launches with ${(o=F[0])==null?void 0:o.label} as the only provider.`:`Run preview: launches with ${F.length} providers available for routing.`;return{providers:c,activeProviders:F,summary:m}},[p,n,b]),y=h.useMemo(()=>{const c=ie.filter(m=>{var I;const o=(I=w==null?void 0:w.providers)==null?void 0:I[m.id];return!!(o!=null&&o.ok)}).length,F=ie.filter(m=>p[m.id]&&b[m.id].trim().length>0).length;return{readyProviders:c,pendingSaves:F}},[p,w==null?void 0:w.providers,b]),_=async c=>{if(!r)return;x(null);const F=b[c].trim();if(!p[c])return;if(!F){x(`Enter a ${tt(c)} API key or use "Clear" to remove the saved key.`);return}const m=Ne(c);try{u(c),await l.update({[m]:F}),A(o=>({...o,[c]:!1})),f(o=>({...o,[c]:""})),g(o=>({...o,[c]:!1}))}finally{u(null)}},k=async c=>{x(null);const F=Ne(c);try{u(c),await l.update({[F]:null}),A(m=>({...m,[c]:!1})),f(m=>({...m,[c]:""})),g(m=>({...m,[c]:!1}))}finally{u(null)}},B=async()=>{x(null),await l.probe()};return e.jsxs("div",{className:"flex min-h-0 flex-col gap-7",children:[e.jsxs("div",{className:"mb-4",children:[e.jsx("h3",{className:"text-heading font-semibold text-white",children:"Provider keys"}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:"Bring your own provider keys. Keys are stored locally and used for agent launches."}),S===0?e.jsxs("div",{className:"mt-3 inline-flex items-center gap-2 rounded-full border border-amber-200/20 bg-amber-200/10 px-3 py-1 text-caption text-amber-100/85",children:[e.jsx("span",{className:"inline-flex h-1.5 w-1.5 rounded-full bg-amber-200/80"}),"No keys detected yet. You can also use env vars."]}):e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsxs("span",{className:"chip",children:[S," / 3 configured"]}),(n==null?void 0:n.updatedAt)&&e.jsxs("span",{className:"text-caption text-muted",children:["Updated ",new Date(n.updatedAt).toLocaleString()]})]})]}),(q||l.error)&&e.jsx("div",{className:"rounded-xl border border-rose-300/20 bg-rose-400/10 p-4 text-body text-rose-100",children:q??l.error}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-3",children:[e.jsxs("div",{className:"rounded-lg border border-white/[0.08] bg-black/20 px-3 py-2",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Step 1"}),e.jsx("p",{className:"mt-1 text-caption font-semibold text-primary",children:"Review source policy"})]}),e.jsxs("div",{className:"rounded-lg border border-white/[0.08] bg-black/20 px-3 py-2",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Step 2"}),e.jsx("p",{className:"mt-1 text-caption font-semibold text-primary",children:"Save provider keys"})]}),e.jsxs("div",{className:"rounded-lg border border-white/[0.08] bg-black/20 px-3 py-2",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Step 3"}),e.jsx("p",{className:"mt-1 text-caption font-semibold text-primary",children:"Probe run readiness"})]})]}),e.jsx(me,{step:"Subspace 01",title:"Source policy + readiness",description:"Environment variables remain fallback defaults. Saved keys override env values per provider.",children:e.jsxs("div",{className:"rounded-2xl border border-subtle bg-white/[0.02] p-4",children:[e.jsx("p",{className:"text-body font-semibold text-primary",children:"Where keys come from"}),e.jsxs("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:["If you set an env var (e.g."," ",e.jsx("code",{className:"rounded bg-black/40 px-1",children:"OPENAI_API_KEY"}),"), it will be used unless a saved key overrides it."]}),e.jsxs("div",{className:"mt-3 grid gap-2 sm:grid-cols-3",children:[e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-black/20 px-3 py-2.5",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Configured keys"}),e.jsxs("p",{className:"mt-1 text-heading font-semibold text-white",children:[S," / 3"]})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-black/20 px-3 py-2.5",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Ready providers"}),e.jsx("p",{className:"mt-1 text-heading font-semibold text-white",children:y.readyProviders})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-black/20 px-3 py-2.5",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Pending saves"}),e.jsx("p",{className:"mt-1 text-heading font-semibold text-white",children:y.pendingSaves})]})]})]})}),e.jsx(me,{step:"Subspace 02",title:"Agent run preview",description:"A dry operational read on launch viability based on current + pending credentials.",children:e.jsxs("div",{className:"rounded-2xl border border-lime/20 bg-lime/[0.05] p-4",children:[e.jsx("p",{className:"text-body font-semibold text-[#D8FFA1]",children:v.summary}),e.jsx("div",{className:"mt-3 grid gap-2 sm:grid-cols-3",children:v.providers.map(c=>e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-black/20 px-3 py-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-caption font-semibold text-primary",children:c.label}),e.jsx("span",{className:P("rounded-full border px-2 py-0.5 text-micro uppercase tracking-[0.12em]",c.configured?"border-lime/30 bg-lime/[0.14] text-[#D8FFA1]":"border-white/[0.14] bg-white/[0.04] text-secondary"),children:c.configured?"Available":"Missing"})]}),e.jsxs("p",{className:"mt-1 text-caption text-muted",children:["Source: ",c.source,c.pending==="save"?" (pending save)":""]})]},c.id))})]})}),e.jsx(me,{step:"Subspace 03",title:"Provider slots",description:"Each slot is independent: enter key, save/clear, then probe readiness.",children:e.jsx("div",{className:"grid grid-cols-1 gap-4",children:ie.map((c,F)=>{var ee,V;const m=(ee=n==null?void 0:n.providers)==null?void 0:ee[c.id],o=(V=w==null?void 0:w.providers)==null?void 0:V[c.id],I=(m==null?void 0:m.masked)??null,E=(m==null?void 0:m.source)??"none",R=E==="stored",D=j===c.id,X=p[c.id]&&b[c.id].trim().length>0&&!l.isSaving&&!D,U=R&&!l.isSaving&&!D,$=R?"Update":"Save";return e.jsxs(z.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},transition:{delay:Math.min(F,5)*.03,duration:.2},className:"rounded-2xl border border-white/[0.07] bg-white/[0.02] p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3 border-b border-white/[0.06] pb-3",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"text-micro uppercase tracking-[0.12em] text-[#D8FFA1]/80",children:["Slot ",F+1]}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2",children:[e.jsx("p",{className:"text-body font-semibold text-white",children:c.label}),e.jsx("span",{className:P("rounded-full border px-2 py-0.5 text-micro uppercase tracking-[0.12em]",m!=null&&m.configured?"border-emerald-300/25 bg-emerald-400/10 text-emerald-100":"border-strong bg-white/[0.03] text-secondary"),children:m!=null&&m.configured?"Configured":"Missing"})]}),e.jsxs("p",{className:"mt-1 text-body text-secondary",children:[c.hint," ",e.jsxs("span",{className:"text-muted",children:["Env: ",e.jsx("code",{className:"rounded bg-black/40 px-1",children:c.envVar})]})]}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[E!=="none"&&e.jsxs("span",{className:"chip",children:["source: ",E]}),I&&e.jsxs("span",{className:"chip",children:["key: ",I]}),o&&e.jsx("span",{className:P("chip",o.ok?"text-emerald-100":"text-rose-100"),children:o.ok?`ready (${o.modelCount??0} models)`:"not ready"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>g(L=>({...L,[c.id]:!L[c.id]})),className:"rounded-lg border border-strong bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.08]",title:N[c.id]?"Hide key":"Show key",children:N[c.id]?"Hide":"Show"}),e.jsx("button",{type:"button",onClick:()=>void B(),className:"rounded-lg border border-strong bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.08]",title:"Probe configured models",children:"Probe"})]})]}),e.jsxs("form",{className:"mt-3",onSubmit:L=>{L.preventDefault(),_(c.id)},children:[e.jsx("input",{type:"text",name:`provider-user-${c.id}`,autoComplete:"username",value:`${c.id}-key`,readOnly:!0,tabIndex:-1,"aria-hidden":"true",className:"sr-only"}),e.jsxs("label",{className:"block",htmlFor:`provider-key-${c.id}`,children:[e.jsx("span",{className:"mb-1.5 block text-caption font-medium uppercase tracking-[0.14em] text-muted",children:"API key (stored locally)"}),e.jsx("input",{id:`provider-key-${c.id}`,name:`provider-key-${c.id}`,value:b[c.id],onChange:L=>{f(H=>({...H,[c.id]:L.target.value})),A(H=>({...H,[c.id]:!0})),q&&x(null)},type:N[c.id]?"text":"password",autoComplete:"new-password",spellCheck:!1,placeholder:`Paste ${c.label} key`,className:"w-full rounded-xl border border-white/[0.08] bg-black/30 px-3 py-2.5 font-mono text-body text-primary placeholder:text-faint focus:border-[#BFFF00]/40 focus:outline-none"})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2 border-t border-white/[0.06] pt-3",children:[e.jsx("button",{type:"submit",disabled:!X,className:"rounded-full bg-[#BFFF00] px-4 py-2 text-body font-semibold text-black transition-colors hover:bg-[#d3ff42] disabled:cursor-not-allowed disabled:opacity-40",children:D?"Saving...":$}),e.jsx("button",{type:"button",onClick:()=>void k(c.id),disabled:!U,className:"rounded-full border border-strong bg-white/[0.03] px-4 py-2 text-body font-semibold text-primary transition-colors hover:bg-white/[0.06] disabled:cursor-not-allowed disabled:opacity-35",children:"Clear stored"}),e.jsx("span",{className:"text-caption text-muted",children:p[c.id]?"Unsaved changes":"Saved"})]})]})]},c.id)})})})]})}const ve={engineering:"Engineering",product:"Product",design:"Design",marketing:"Marketing",sales:"Sales",operations:"Operations",orchestration:"Orchestration"},te={decisionV2Enabled:!0,decisionDedupeEnabled:!0,decisionEvidenceRequiredForBlocking:!1,decisionAutoResolveGuardedEnabled:!0,questionAutoAnswerEnabled:!0,questionAutoAnswerTimeoutSec:60,questionAutoAnswerPolicy:"contextual",questionBlockingBehavior:"require_human",questionPolicyVersion:1,questionAutoAnswerDelaySeconds:60,questionAutoAnswerAction:"approve",customRunInstructions:""},nt=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;function pe(t){return typeof t!="string"?!1:nt.test(t.trim())}function ke(t){const s=`${t.name??""} ${t.id??""}`.toLowerCase();return s.includes("orchestrat")?"orchestration":s.includes("engineer")||s.includes("dev delivery")?"engineering":s.includes("product")?"product":s.includes("design")?"design":s.includes("market")?"marketing":s.includes("sales")?"sales":s.includes("operations")||s.includes("ops ")?"operations":null}function it(t,s){return t.decisionV2Enabled===s.decisionV2Enabled&&t.decisionDedupeEnabled===s.decisionDedupeEnabled&&t.decisionEvidenceRequiredForBlocking===s.decisionEvidenceRequiredForBlocking&&t.decisionAutoResolveGuardedEnabled===s.decisionAutoResolveGuardedEnabled&&t.questionAutoAnswerEnabled===s.questionAutoAnswerEnabled&&t.questionAutoAnswerTimeoutSec===s.questionAutoAnswerTimeoutSec&&t.questionAutoAnswerPolicy===s.questionAutoAnswerPolicy&&t.questionBlockingBehavior===s.questionBlockingBehavior&&t.questionPolicyVersion===s.questionPolicyVersion&&t.questionAutoAnswerDelaySeconds===s.questionAutoAnswerDelaySeconds&&t.questionAutoAnswerAction===s.questionAutoAnswerAction&&t.customRunInstructions.trim()===s.customRunInstructions.trim()}function rt({status:t}){return e.jsx("span",{className:P("rounded-full border px-2 py-0.5 text-micro uppercase tracking-[0.08em]",t==="healthy"?"border-teal/25 bg-teal/[0.10] text-teal":t==="conflict"?"border-rose-300/30 bg-rose-500/[0.12] text-rose-100":"border-white/[0.14] bg-white/[0.04] text-secondary"),children:t==="healthy"?"Healthy":t==="conflict"?"Conflict":"Needs apply"})}function ne({label:t,description:s,enabled:r,onToggle:l}){return e.jsxs("div",{className:"flex min-h-[54px] items-start justify-between gap-3 rounded-xl border border-white/[0.08] bg-black/20 px-3 py-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-body font-semibold text-primary",children:t}),e.jsx("p",{className:"mt-1 text-caption leading-relaxed text-secondary",children:s})]}),e.jsx("button",{type:"button",role:"switch","aria-checked":r,onClick:()=>l(!r),className:P("relative inline-flex h-6 w-11 flex-shrink-0 rounded-full border transition-colors",r?"border-lime/35 bg-lime/[0.20]":"border-white/[0.12] bg-white/[0.06]"),children:e.jsx("span",{"aria-hidden":"true",className:P("absolute top-0.5 h-5 w-5 rounded-full transition-all",r?"left-[20px] bg-lime":"left-0.5 bg-white/70")})})]})}function Ae({step:t,title:s,description:r,children:l}){return e.jsxs("section",{className:"grid gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-[#D8FFA1]/80",children:t}),e.jsx("h4",{className:"mt-1 text-heading font-semibold text-white",children:s}),e.jsx("p",{className:"mt-1 text-caption leading-relaxed text-secondary",children:r})]}),l]})}function at({authToken:t=null,embedMode:s=!1,enabled:r=!0,initialDomain:l=null}){var L,H;const n=qe({authToken:t,embedMode:s,enabled:r}),w=(L=n.status)!=null&&L.ok?n.status.data.agents:[],b=n.runtimeSettings.agents,f=h.useMemo(()=>{const i=new Map;for(const d of n.runtimeSettings.agents)i.set(d.id,d.runtimeSettings);return i},[n.runtimeSettings.agents]),p=h.useMemo(()=>{const i=new Map;for(const d of b){const C=ke({name:d.name,id:d.id});!C||i.has(C)||i.set(C,{id:d.id,model:d.model,runtimeSettings:d.runtimeSettings})}return w.length>0?w.map(d=>{var C,M,Y,se;return{id:((C=i.get(d.domain))==null?void 0:C.id)??d.id,name:d.name,domain:d.domain,model:((M=i.get(d.domain))==null?void 0:M.model)??null,configStatus:((Y=d.configHealth)==null?void 0:Y.status)??null,runtimeSettings:((se=i.get(d.domain))==null?void 0:se.runtimeSettings)??f.get(d.id)??te}}):b.map(d=>({id:d.id,name:d.name,domain:ke({name:d.name,id:d.id}),model:d.model,configStatus:null,runtimeSettings:d.runtimeSettings}))},[b,w,f]),A=h.useMemo(()=>{const i={};for(const d of p)i[d.id]=d.runtimeSettings;return i},[p]),[N,g]=h.useState(null),[j,u]=h.useState({}),[q,x]=h.useState(null),[S,v]=h.useState(null);h.useEffect(()=>{if(p.length===0){g(null);return}(!N||!p.some(i=>i.id===N))&&g(p[0].id),u(i=>{let d=!1;const C={...i};for(const M of p)C[M.id]||(C[M.id]=A[M.id]??te,d=!0);return d?C:i})},[N,p,A]),h.useEffect(()=>{if(!l||p.length===0)return;const i=p.find(d=>d.domain===l);i&&i.id!==N&&g(i.id)},[N,p,l]);const y=h.useMemo(()=>p.find(i=>i.id===N)??null,[N,p]),_=i=>j[i]??A[i]??te,k=y?_(y.id):null,B=h.useMemo(()=>p.filter(i=>!it(_(i.id),A[i.id])).map(i=>i.id),[p,j,A]),c=h.useMemo(()=>new Set(B),[B]),F=i=>{y&&u(d=>{const C=d[y.id]??A[y.id]??te;return{...d,[y.id]:{...C,...i}}})},m=()=>{y&&u(i=>({...i,[y.id]:A[y.id]??te}))},o=()=>{if(!k||p.length===0)return;const i={...k,customRunInstructions:k.customRunInstructions.trim().slice(0,4e3)};u(d=>{const C={...d};for(const M of p)C[M.id]={...i};return C}),x("Applied active agent settings to all agents."),v(null)},I=()=>{const i={};for(const d of p)i[d.id]=A[d.id]??te;u(i),x(null),v(null)},E=async()=>{var i;if(!(B.length===0||n.isSavingRuntimeSettings)){x(null),v(null);try{for(const d of B){if(!pe(d)){const M=((i=p.find(Y=>Y.id===d))==null?void 0:i.name)??d;throw new Error(`Cannot save "${M}" because it is not linked to a valid OrgX agent UUID yet. Re-sync Agent Suite and try again.`)}const C=_(d);await n.saveRuntimeSettingsAsync({projectId:n.runtimeSettings.projectId,agentId:d,runtimeSettings:{...C,customRunInstructions:C.customRunInstructions.trim().slice(0,4e3)}})}x(`Saved runtime settings for ${B.length} ${B.length===1?"agent":"agents"}.`),v(null)}catch(d){v(d instanceof Error?d.message:"Failed to save agent settings.")}}},R=((H=n.runtimeSettingsError)==null?void 0:H.trim())??null,D=!!R,X=!!(R&&(R.toLowerCase().includes("endpoint is not available")||R.includes("(404)"))),U=D;if(n.isLoading)return e.jsx("section",{className:"rounded-xl border border-subtle bg-white/[0.02] p-4",children:e.jsx("p",{className:"text-body text-secondary",children:"Loading agent settings..."})});if(n.error&&!n.status)return e.jsxs("section",{className:"rounded-xl border border-rose-300/25 bg-rose-400/10 p-4",children:[e.jsx("h3",{className:"text-body font-semibold text-rose-100",children:"Unable to load agent settings"}),e.jsx("p",{className:"mt-1 text-caption leading-relaxed text-rose-100/85",children:n.error})]});if(p.length===0||!y||!k)return e.jsxs("section",{className:"rounded-xl border border-subtle bg-white/[0.02] p-4",children:[e.jsx("h3",{className:"text-body font-semibold text-primary",children:"No agents configured"}),e.jsx("p",{className:"mt-1 text-caption leading-relaxed text-secondary",children:"Install the agent suite first, then runtime settings will appear here."})]});const $=B.length,ee=c.has(y.id),V=y.domain?ve[y.domain]:"Agent";return e.jsxs("section",{className:"space-y-4",children:[e.jsxs("header",{className:"rounded-xl border border-subtle bg-white/[0.02] p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-heading font-semibold text-white",children:"Agent runtime settings"}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:U?X?"Viewing agent suite roster. Runtime configuration requires a plugin rebuild.":"Viewing agent suite roster. Runtime configuration is temporarily unavailable.":"Configure decision guardrails and persistent run instructions per agent."})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("span",{className:"rounded-full border border-white/[0.10] bg-white/[0.03] px-3 py-1 text-caption text-primary",children:[p.length," agents"]}),!U&&e.jsxs("span",{className:P("rounded-full border px-3 py-1 text-caption",$>0?"border-lime/25 bg-lime/[0.12] text-lime":"border-white/[0.10] bg-white/[0.03] text-secondary"),children:[$," unsaved"]})]})]}),e.jsxs("div",{className:"mt-3 grid gap-2 sm:grid-cols-3",children:[e.jsxs("div",{className:"rounded-lg border border-white/[0.08] bg-black/20 px-3 py-2",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Step 1"}),e.jsx("p",{className:"mt-1 text-caption font-semibold text-primary",children:"Select agent"})]}),e.jsxs("div",{className:"rounded-lg border border-white/[0.08] bg-black/20 px-3 py-2",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Step 2"}),e.jsx("p",{className:"mt-1 text-caption font-semibold text-primary",children:"Tune decision policy"})]}),e.jsxs("div",{className:"rounded-lg border border-white/[0.08] bg-black/20 px-3 py-2",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Step 3"}),e.jsx("p",{className:"mt-1 text-caption font-semibold text-primary",children:"Save all changes"})]})]})]}),U&&e.jsx("div",{className:"rounded-xl border border-amber-300/20 bg-[#12100A]/95 px-4 py-3",children:X?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-caption font-medium text-amber-100",children:"Runtime settings endpoint is not available in the running plugin build."}),e.jsx("p",{className:"mt-1 text-caption text-amber-100/70",children:"Rebuild the plugin server to enable per-agent configuration. Agent roster is shown below."})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-caption font-medium text-amber-100",children:"Runtime settings could not be loaded from the OrgX API."}),e.jsx("p",{className:"mt-1 text-caption text-amber-100/70",children:R})]})}),e.jsxs("div",{className:"grid gap-4 lg:grid-cols-[280px_minmax(0,1fr)]",children:[e.jsx(Ae,{step:"Subspace 01",title:"Agent roster",description:"Select the runtime identity to edit. Draft state is scoped per agent.",children:e.jsx("aside",{className:"rounded-xl border border-subtle bg-white/[0.02] p-2",children:e.jsx("div",{className:"max-h-[520px] space-y-1 overflow-y-auto pr-1",children:p.map(i=>{const d=i.id===y.id,C=c.has(i.id),M=pe(i.id);return e.jsxs("button",{type:"button",onClick:()=>g(i.id),className:P("w-full rounded-lg border px-3 py-2 text-left transition-colors",d?"border-lime/25 bg-lime/[0.12]":"border-white/[0.08] bg-black/20 hover:bg-white/[0.04]"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"truncate text-body font-semibold text-primary",children:i.name}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[M?null:e.jsx("span",{className:"rounded-full border border-amber-300/25 bg-amber-400/[0.16] px-1.5 py-0.5 text-micro uppercase tracking-[0.08em] text-amber-100",children:"Not linked"}),i.configStatus?e.jsx(rt,{status:i.configStatus}):null]})]}),e.jsxs("div",{className:"mt-1 flex items-center justify-between gap-2",children:[e.jsx("p",{className:"truncate text-caption text-secondary",children:i.domain?ve[i.domain]:i.model??"Agent"}),C?e.jsx("span",{className:"rounded-full border border-lime/25 bg-lime/[0.10] px-1.5 py-0.5 text-micro uppercase tracking-[0.08em] text-lime",children:"Draft"}):null]})]},i.id)})})})}),e.jsxs(Ae,{step:"Subspace 02",title:"Policy surfaces",description:"Tune decision pipeline and persistent instructions for the selected agent.",children:[e.jsx("article",{className:"rounded-xl border border-subtle bg-white/[0.02] p-4",children:e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-caption uppercase tracking-[0.08em] text-secondary",children:V}),e.jsx("h4",{className:"mt-1 text-heading font-semibold text-white",children:y.name}),pe(y.id)?null:e.jsx("p",{className:"mt-1 text-caption text-amber-100/85",children:"This agent is not linked to a runtime UUID yet. Apply Agent Suite sync before saving."})]}),!U&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",onClick:o,className:"min-h-[44px] rounded-full border border-white/[0.14] bg-white/[0.03] px-3 py-2 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.06]",children:"Apply to all"}),e.jsx("button",{type:"button",onClick:m,disabled:!ee,className:"min-h-[44px] rounded-full border border-white/[0.14] bg-white/[0.03] px-3 py-2 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.06] disabled:cursor-not-allowed disabled:opacity-50",children:"Reset active"})]})]})}),e.jsxs("div",{className:U?"pointer-events-none opacity-40":"",children:[e.jsxs("article",{className:"rounded-xl border border-subtle bg-white/[0.02] p-4",children:[e.jsx("h4",{className:"text-body font-semibold text-primary",children:"Decision pipeline"}),e.jsx("p",{className:"mt-1 text-caption leading-relaxed text-secondary",children:"These controls are injected into dispatch and decision flows for this agent."}),e.jsxs("div",{className:"mt-3 space-y-3",children:[e.jsxs("div",{className:"space-y-2 rounded-xl border border-white/[0.08] bg-black/20 p-3",children:[e.jsx("p",{className:"text-caption font-semibold uppercase tracking-[0.08em] text-secondary",children:"Decision envelope"}),e.jsx(ne,{label:"Decision envelope v2",description:"Emit richer context fields for diagnosis and replay.",enabled:k.decisionV2Enabled,onToggle:i=>F({decisionV2Enabled:i})}),e.jsx(ne,{label:"Decision dedupe",description:"Collapse repeated blockers into the same pending decision.",enabled:k.decisionDedupeEnabled,onToggle:i=>F({decisionDedupeEnabled:i})}),e.jsx(ne,{label:"Require evidence for blocking decisions",description:"Attach evidence before a blocking decision can be emitted.",enabled:k.decisionEvidenceRequiredForBlocking,onToggle:i=>F({decisionEvidenceRequiredForBlocking:i})}),e.jsx(ne,{label:"Guarded auto-resolve",description:"Attempt deterministic remediation before escalating to humans.",enabled:k.decisionAutoResolveGuardedEnabled,onToggle:i=>F({decisionAutoResolveGuardedEnabled:i})})]}),e.jsxs("div",{className:"space-y-2 rounded-xl border border-white/[0.08] bg-black/20 p-3",children:[e.jsx("p",{className:"text-caption font-semibold uppercase tracking-[0.08em] text-secondary",children:"Question automation"}),e.jsx(ne,{label:"Auto-answer unanswered questions",description:"If no human response arrives in time, auto-resolve questions sequentially.",enabled:k.questionAutoAnswerEnabled,onToggle:i=>F({questionAutoAnswerEnabled:i})}),e.jsxs("div",{className:"grid gap-2 rounded-xl border border-white/[0.08] bg-black/20 px-3 py-3 md:grid-cols-2",children:[e.jsxs("label",{className:"flex min-w-0 flex-col gap-1",children:[e.jsx("span",{className:"text-caption font-semibold text-primary",children:"Auto-answer timeout (seconds)"}),e.jsx("input",{type:"number",min:10,max:3600,step:1,value:k.questionAutoAnswerTimeoutSec,onChange:i=>{const d=Number.parseInt(i.target.value,10),C=Number.isFinite(d)?Math.max(10,Math.min(3600,d)):60;F({questionAutoAnswerTimeoutSec:C,questionAutoAnswerDelaySeconds:C})},className:"min-h-[40px] rounded-lg border border-white/[0.12] bg-black/25 px-3 text-body text-primary outline-none transition-colors focus:border-lime/35"})]}),e.jsxs("label",{className:"flex min-w-0 flex-col gap-1",children:[e.jsx("span",{className:"text-caption font-semibold text-primary",children:"Auto-answer policy"}),e.jsxs("select",{value:k.questionAutoAnswerPolicy,onChange:i=>F({questionAutoAnswerPolicy:i.target.value==="approve_non_blocking"||i.target.value==="defer_non_blocking"?i.target.value:"contextual",questionAutoAnswerAction:i.target.value==="defer_non_blocking"?"reject":"approve"}),className:"min-h-[40px] rounded-lg border border-white/[0.12] bg-black/25 px-3 text-body text-primary outline-none transition-colors focus:border-lime/35",children:[e.jsx("option",{value:"contextual",children:"Contextual (recommended)"}),e.jsx("option",{value:"approve_non_blocking",children:"Approve non-blocking"}),e.jsx("option",{value:"defer_non_blocking",children:"Defer non-blocking"})]})]}),e.jsxs("label",{className:"flex min-w-0 flex-col gap-1 md:col-span-2",children:[e.jsx("span",{className:"text-caption font-semibold text-primary",children:"Blocking question behavior"}),e.jsxs("select",{value:k.questionBlockingBehavior,onChange:i=>F({questionBlockingBehavior:i.target.value==="guarded_auto_resolve_then_human"?"guarded_auto_resolve_then_human":"require_human"}),className:"min-h-[40px] rounded-lg border border-white/[0.12] bg-black/25 px-3 text-body text-primary outline-none transition-colors focus:border-lime/35",children:[e.jsx("option",{value:"require_human",children:"Require human decision"}),e.jsx("option",{value:"guarded_auto_resolve_then_human",children:"Guarded auto-resolve, then human"})]})]})]})]})]})]}),e.jsxs("article",{className:"mt-3 rounded-xl border border-subtle bg-white/[0.02] p-4",children:[e.jsx("h4",{className:"text-body font-semibold text-primary",children:"Persistent run instructions"}),e.jsx("p",{className:"mt-1 text-caption leading-relaxed text-secondary",children:"Injected into every run for this agent as runtime guidance."}),e.jsx("textarea",{value:k.customRunInstructions,onChange:i=>F({customRunInstructions:i.target.value.slice(0,4e3)}),rows:7,placeholder:"Add concise constraints, workflow defaults, and handoff requirements.",className:"mt-3 w-full rounded-xl border border-white/[0.12] bg-black/25 px-3 py-2 text-body text-primary outline-none transition-colors placeholder:text-muted focus:border-lime/35"}),e.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-caption text-secondary",children:"Keep instructions explicit and operational, not aspirational."}),e.jsxs("p",{className:"text-micro uppercase tracking-[0.08em] text-secondary",children:[k.customRunInstructions.trim().length,"/4000"]})]})]})]})]})]}),e.jsx("div",{className:P("sticky bottom-0 z-10 rounded-xl border border-subtle bg-[#08090d]/90 p-3 backdrop-blur",U&&"hidden"),children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("div",{className:"min-h-[20px]",children:S?e.jsx("p",{className:"text-caption text-rose-100",children:S}):q?e.jsx("p",{className:"text-caption text-lime",children:q}):e.jsx("p",{className:"text-caption text-secondary",children:$>0?`${$} ${$===1?"agent has":"agents have"} unsaved changes.`:"All agent runtime settings are saved."})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:I,disabled:$===0||n.isSavingRuntimeSettings,className:"min-h-[44px] rounded-lg border border-white/[0.14] px-3 py-2 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.06] disabled:cursor-not-allowed disabled:opacity-50",children:"Discard all"}),e.jsx("button",{type:"button",onClick:()=>{E()},disabled:$===0||n.isSavingRuntimeSettings,className:"min-h-[44px] rounded-lg border border-lime/30 bg-lime/[0.14] px-3 py-2 text-caption font-semibold text-lime transition-colors hover:bg-lime/[0.2] disabled:cursor-not-allowed disabled:opacity-50",children:n.isSavingRuntimeSettings?"Saving...":"Save changes"})]})]})})]})}function Q(t){return new Intl.NumberFormat("en-US").format(Math.max(0,Math.round(t)))}function xe(t){return`$${(Math.max(0,t)/100).toFixed(2)}`}function he(t){return typeof t!="number"||!Number.isFinite(t)?"—":`${Math.max(0,Math.round(t))}%`}function ot(t){return t==="over_limit"?"border-rose-300/30 bg-rose-400/12 text-rose-100":t==="at_risk"?"border-amber-300/30 bg-amber-400/12 text-amber-100":t==="watch"?"border-teal-300/25 bg-teal-400/10 text-teal-100":"border-lime/30 bg-lime/[0.14] text-[#D8FFA1]"}function Se(t,s=4){return!Array.isArray(t)||t.length===0?[]:[...t].sort((r,l)=>l.tokens-r.tokens).slice(0,s)}function lt(t){const s=Date.parse(t.generatedAt);if(!Number.isFinite(s))return"Updated just now";const r=Math.max(0,Math.round((Date.now()-s)/6e4));return r<1?"Updated just now":r<60?`Updated ${r}m ago`:`Updated ${Math.round(r/60)}h ago`}function _e({step:t,title:s,description:r,children:l}){return e.jsxs("section",{className:"grid gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-[#D8FFA1]/80",children:t}),e.jsx("h4",{className:"mt-1 text-heading font-semibold text-white",children:s}),e.jsx("p",{className:"mt-1 text-caption leading-relaxed text-secondary",children:r})]}),l]})}function ct({authToken:t=null,embedMode:s=!1,enabled:r=!0}){const l=Me({authToken:t,embedMode:s,enabled:r}),n=l.summary;return e.jsxs("div",{className:"rounded-2xl border border-white/[0.07] bg-white/[0.02] p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-heading font-semibold text-white",children:"Usage control plane"}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:"Actual vs predicted token, runtime, and cost usage for this billing period."})]}),e.jsx("button",{type:"button",onClick:()=>void l.refetch(),disabled:l.isFetching,className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.07] disabled:cursor-not-allowed disabled:opacity-50",children:l.isFetching?"Refreshing…":"Refresh"})]}),l.error?e.jsx("div",{className:"mt-3 rounded-xl border border-rose-300/25 bg-rose-400/10 px-3 py-2.5 text-body text-rose-100",children:l.error}):null,!n&&l.isLoading?e.jsx("div",{className:"mt-3 grid gap-2 sm:grid-cols-2 lg:grid-cols-4",children:Array.from({length:4}).map((w,b)=>e.jsx("div",{className:"h-[92px] animate-pulse rounded-xl border border-white/[0.08] bg-white/[0.03]"},`usage-loading-${b}`))}):null,n?e.jsx(e.Fragment,{children:e.jsxs("div",{className:"mt-4 grid gap-6",children:[e.jsx(_e,{step:"Subspace 01",title:"Risk + volume overview",description:"Current period usage against plan limits with forecast deltas.",children:e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-black/20 p-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(z.span,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},className:P("rounded-full border px-2.5 py-1 text-caption font-semibold",ot(n.risk)),children:n.risk.replace("_"," ")}),e.jsx("span",{className:"chip",children:n.plan.name}),n.source?e.jsxs("span",{className:"chip",children:["source: ",n.source]}):null,e.jsx("span",{className:"text-caption text-muted",children:lt(n)})]}),e.jsxs("div",{className:"mt-3 grid gap-2 sm:grid-cols-2 lg:grid-cols-4",children:[e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-black/30 px-3 py-2.5",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Agent runs"}),e.jsxs("p",{className:"mt-1 text-heading font-semibold text-white",children:[Q(n.actual.agentRuns),e.jsxs("span",{className:"ml-1 text-caption text-secondary",children:["/ ",n.plan.agentRunsLimit>0?Q(n.plan.agentRunsLimit):"∞"]})]}),e.jsxs("p",{className:"mt-1 text-caption text-muted",children:["Forecast ",Q(n.predicted.agentRuns)]})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-black/30 px-3 py-2.5",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Agent minutes"}),e.jsxs("p",{className:"mt-1 text-heading font-semibold text-white",children:[Q(n.actual.agentMinutes),e.jsxs("span",{className:"ml-1 text-caption text-secondary",children:["/ ",n.plan.agentMinutesLimit>0?Q(n.plan.agentMinutesLimit):"∞"]})]}),e.jsxs("p",{className:"mt-1 text-caption text-muted",children:["Forecast ",Q(n.predicted.agentMinutes)]})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-black/30 px-3 py-2.5",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Tokens"}),e.jsx("p",{className:"mt-1 text-heading font-semibold text-white",children:Q(n.actual.tokens)}),e.jsxs("p",{className:"mt-1 text-caption text-muted",children:["Forecast ",Q(n.predicted.tokens)]})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-black/30 px-3 py-2.5",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Spend"}),e.jsxs("p",{className:"mt-1 text-heading font-semibold text-white",children:[xe(n.actual.costCents),e.jsxs("span",{className:"ml-1 text-caption text-secondary",children:["/ ",n.plan.includedBudgetCents>0?xe(n.plan.includedBudgetCents):"—"]})]}),e.jsxs("p",{className:"mt-1 text-caption text-muted",children:["Forecast ",xe(n.predicted.costCents)]})]})]})]})}),e.jsx(_e,{step:"Subspace 02",title:"Utilization diagnostics",description:"Percent utilization plus source-client composition and warnings.",children:e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-black/20 p-3",children:[e.jsxs("div",{className:"grid gap-2 sm:grid-cols-3",children:[e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.02] px-3 py-2",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Run utilization"}),e.jsx("p",{className:"mt-1 text-caption font-semibold text-primary",children:he(n.utilization.runsPct)})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.02] px-3 py-2",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Minute utilization"}),e.jsx("p",{className:"mt-1 text-caption font-semibold text-primary",children:he(n.utilization.minutesPct)})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.02] px-3 py-2",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Budget utilization"}),e.jsx("p",{className:"mt-1 text-caption font-semibold text-primary",children:he(n.utilization.budgetPct)})]})]}),Se(n.breakdown.sourceClient,4).length>0?e.jsxs("div",{className:"mt-3 rounded-xl border border-white/[0.08] bg-black/30 p-3",children:[e.jsx("p",{className:"text-caption font-semibold text-primary",children:"Runtime client mix"}),e.jsx("div",{className:"mt-2 space-y-2",children:Se(n.breakdown.sourceClient,4).map((w,b)=>{const f=n.actual.tokens>0?Math.max(0,Math.min(100,Math.round(w.tokens/n.actual.tokens*100))):0;return e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-caption text-secondary",children:w.label}),e.jsxs("span",{className:"text-caption text-primary",children:[Q(w.tokens)," tokens · ",Q(w.runs)," runs"]})]}),e.jsx("div",{className:"h-1.5 rounded-full bg-white/[0.08]",children:e.jsx(z.div,{initial:{width:0},animate:{width:`${Math.max(6,f)}%`},transition:{duration:.36,delay:b*.04},className:"h-1.5 rounded-full bg-lime/80 transition-all"})})]},`usage-source-${w.key}`)})})]}):null,Array.isArray(n.warnings)&&n.warnings.length>0?e.jsxs("div",{className:"mt-3 rounded-xl border border-amber-300/25 bg-amber-400/10 px-3 py-2.5",children:[e.jsx("p",{className:"text-caption font-semibold text-amber-100",children:"Usage warnings"}),e.jsx("ul",{className:"mt-1 space-y-1",children:n.warnings.slice(0,3).map((w,b)=>e.jsxs("li",{className:"text-caption text-amber-100/90",children:["• ",w]},`usage-warning-${b}`))})]}):null]})})]})}):null]})}function dt({connectionPhase:t,workspaceName:s}){const{displayName:r,avatarSeed:l,updateName:n,regenerateAvatar:w}=Ie(),[b,f]=h.useState(!1),[p,A]=h.useState(""),N=h.useRef(null),g=h.useCallback(()=>{A(r),f(!0),requestAnimationFrame(()=>{var v;return(v=N.current)==null?void 0:v.focus()})},[r]),j=h.useCallback(()=>{n(p),f(!1)},[p,n]),u=h.useCallback(()=>{f(!1)},[]),q=h.useCallback(v=>{v.key==="Enter"?j():v.key==="Escape"&&u()},[j,u]),x=t==="connected",S=x?`Connected${s?` to ${s}`:""}`:t==="connecting"?"Connecting...":t==="error"?"Connection error":"Not connected";return e.jsxs("div",{className:"rounded-2xl border border-white/[0.07] bg-white/[0.02] p-5",children:[e.jsxs("div",{className:"mb-4 flex items-center justify-between gap-3 border-b border-white/[0.06] pb-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-[#D8FFA1]/85",children:"Identity"}),e.jsx("p",{className:"mt-1 text-caption text-secondary",children:"Name, visual signature, and connection context shown across mission surfaces."})]}),e.jsx(z.span,{initial:{opacity:0,y:2},animate:{opacity:1,y:0},className:P("rounded-full border px-2.5 py-1 text-micro uppercase tracking-[0.09em]",x?"border-lime/28 bg-lime/[0.11] text-[#D8FFA1]":t==="error"?"border-rose-300/25 bg-rose-500/[0.12] text-rose-100":"border-white/[0.14] bg-white/[0.04] text-secondary"),children:x?"Connected":t==="connecting"?"Connecting":t==="error"?"Attention":"Idle"})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-[auto_minmax(0,1fr)]",children:[e.jsxs("div",{className:"flex flex-col items-center gap-2 rounded-xl border border-white/[0.08] bg-black/20 px-4 py-3",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Signature"}),e.jsx(Ce,{mode:"wait",children:e.jsx(z.div,{initial:{opacity:0,scale:.9},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.9},transition:{duration:.3,ease:Pe.easingEntrance},children:e.jsx(De,{seed:l,size:80})},l)}),e.jsx(z.button,{type:"button",onClick:w,whileHover:{y:-1},whileTap:{scale:.98},className:"rounded-lg border border-white/[0.08] bg-white/[0.02] px-3 py-1.5 text-caption text-secondary transition hover:bg-white/[0.06] hover:text-white",children:"Regenerate"})]}),e.jsxs("div",{className:"min-w-0 rounded-xl border border-white/[0.08] bg-black/20 px-4 py-3",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Identity + status"}),b?e.jsxs("div",{className:"mt-1.5 flex items-center gap-2",children:[e.jsx("input",{ref:N,type:"text",value:p,onChange:v=>A(v.target.value),onKeyDown:q,maxLength:64,placeholder:"Enter your name",className:"h-8 flex-1 rounded-lg border border-white/[0.12] bg-white/[0.04] px-2.5 text-heading font-semibold text-white placeholder:text-muted focus:border-lime/30 focus:outline-none"}),e.jsx("button",{type:"button",onClick:j,className:"rounded-lg bg-lime/[0.12] px-3 py-1.5 text-caption font-medium text-lime transition hover:bg-lime/[0.2]",children:"Save"}),e.jsx("button",{type:"button",onClick:u,className:"rounded-lg px-3 py-1.5 text-caption text-secondary transition hover:bg-white/[0.04]",children:"Cancel"})]}):e.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[e.jsx("h4",{className:"text-heading font-semibold text-white",children:r||"Anonymous"}),e.jsx("button",{type:"button",onClick:g,className:"rounded-md px-2 py-0.5 text-caption text-secondary transition hover:bg-white/[0.06] hover:text-white",children:r?"Edit":"Add name"})]}),e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("span",{className:"relative flex h-2 w-2",children:e.jsx("span",{className:P("relative inline-flex h-2 w-2 rounded-full",x?"bg-lime":t==="error"?"bg-red-400":"bg-white/30")})}),e.jsx("span",{className:"text-caption text-secondary",children:S})]})]})]})]})}const re=[{id:"orgx",label:"Workspace",subtitle:"Identity, OrgX connection, and environment controls."},{id:"agents",label:"Agents",subtitle:"Runtime behavior, decision policy, and execution guidance."},{id:"providers",label:"Provider keys",subtitle:"Model provider credentials and launch readiness."}];function ut({id:t}){return t==="orgx"?e.jsxs("svg",{viewBox:"0 0 24 24",className:"h-4 w-4",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:[e.jsx("path",{d:"M4 8h16"}),e.jsx("path",{d:"M4 16h16"}),e.jsx("rect",{x:"4",y:"5",width:"16",height:"14",rx:"3"})]}):t==="agents"?e.jsxs("svg",{viewBox:"0 0 24 24",className:"h-4 w-4",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:[e.jsx("circle",{cx:"8",cy:"8",r:"3"}),e.jsx("circle",{cx:"16",cy:"16",r:"3"}),e.jsx("path",{d:"M10.6 10.6 13.4 13.4"}),e.jsx("path",{d:"M12 5h6v6"})]}):e.jsxs("svg",{viewBox:"0 0 24 24",className:"h-4 w-4",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:[e.jsx("path",{d:"M12 3v18"}),e.jsx("path",{d:"M5 7.5h5.5v4H5z"}),e.jsx("path",{d:"M13.5 12.5H19v4h-5.5z"})]})}function ge({label:t,description:s,enabled:r,onToggle:l}){return e.jsxs("div",{className:"flex items-start justify-between gap-6 py-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-body font-medium text-white",children:t}),e.jsx("p",{className:"mt-0.5 text-caption leading-relaxed text-secondary",children:s})]}),e.jsx(z.button,{type:"button",role:"switch","aria-checked":r,onClick:()=>l(!r),whileTap:{scale:.965},className:P("relative inline-flex h-[22px] w-[38px] flex-shrink-0 rounded-full border transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-lime/50",r?"border-lime/30 bg-lime/[0.15]":"border-white/[0.12] bg-white/[0.04] hover:bg-white/[0.08]"),children:e.jsx("span",{"aria-hidden":"true",className:P("absolute top-[1px] h-[18px] w-[18px] rounded-full shadow-sm transition-all",r?"left-[17px] bg-lime shadow-[0_0_8px_rgba(191,255,0,0.4)]":"left-[1px] bg-secondary")})})]})}function Z({step:t,title:s,description:r,children:l}){return e.jsxs("section",{className:"grid gap-3",children:[e.jsx("div",{className:"flex items-start justify-between gap-3",children:e.jsxs("div",{children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-[#D8FFA1]/80",children:t}),e.jsx("h4",{className:"mt-1 text-heading font-semibold text-white",children:s}),e.jsx("p",{className:"mt-1 text-caption leading-relaxed text-secondary",children:r})]})}),l]})}function ft({open:t,onClose:s,activeTab:r,onChangeTab:l,demoMode:n,onToggleDemoMode:w,devMode:b=!1,onToggleDevMode:f,showSyntheticEntities:p,onToggleShowSyntheticEntities:A,workspaceOptions:N,selectedWorkspaceId:g,onSelectWorkspace:j,onboarding:u,authToken:q=null,embedMode:x=!1,agentBehaviorInitialDomain:S=null}){const v=re.find(_=>_.id===r)??re[0],y=()=>r==="orgx"?e.jsxs(z.div,{...le,className:"grid gap-8",children:[e.jsx(Z,{step:"Subspace 01",title:"Operator identity",description:"Name, avatar signature, and live workspace connection context.",children:e.jsx(dt,{connectionPhase:u.state.status==="connected"?"connected":u.state.status==="error"?"error":u.state.status==="starting"||u.state.status==="awaiting_browser_auth"||u.state.status==="pairing"?"connecting":"idle",workspaceName:u.state.workspaceName})}),e.jsx(Z,{step:"Subspace 02",title:"Environment controls",description:"Debug and rehearsal switches that shape what appears in mission control.",children:e.jsx("div",{className:"rounded-2xl border border-white/[0.07] bg-white/[0.02] p-4 sm:p-5",children:e.jsxs("div",{className:"grid gap-1 border-t border-white/[0.04] pt-1",children:[e.jsx(ge,{label:"Developer mode",description:"Show technical details, config paths, and raw data in session inspectors.",enabled:b,onToggle:_=>f==null?void 0:f(_)}),e.jsx("div",{className:P("border-t border-white/[0.04]",b?"":"pointer-events-none opacity-40"),children:e.jsx(ge,{label:"Demo mode",description:"Load local demo data for walkthroughs.",enabled:n,onToggle:w})}),e.jsx("div",{className:P("border-t border-white/[0.04]",b?"":"pointer-events-none opacity-40"),children:e.jsx(ge,{label:"Show synthetic entities",description:"Include QA/test initiative IDs in the agent column.",enabled:p,onToggle:A})})]})})}),e.jsx(Z,{step:"Subspace 03",title:"OrgX connection lifecycle",description:"Credentialing, verification, and workspace scope selection.",children:e.jsx(ze,{state:u.state,isStarting:u.isStarting,isSubmittingManual:u.isSubmittingManual,workspaceOptions:N,selectedWorkspaceId:g,onSelectWorkspace:j,onRefresh:u.refreshStatus,onStartPairing:u.startPairing,onSubmitManualKey:u.submitManualKey,onBackToPairing:u.backToPairing,onUseManualKey:u.setManualMode,onDisconnect:u.disconnect})}),e.jsx(Z,{step:"Subspace 04",title:"Agent suite operations",description:"Install, validate, and tune default execution policy across the local suite.",children:e.jsx(Ye,{authToken:q,embedMode:x,enabled:t&&!n,devMode:b})}),e.jsx(Z,{step:"Subspace 05",title:"Usage telemetry",description:"Budget, token, and runtime risk visibility for the active billing window.",children:e.jsx(ct,{authToken:q,embedMode:x,enabled:t&&!n})})]},"orgx"):r==="agents"?e.jsx(z.div,{...le,className:"grid gap-3",children:e.jsx(Z,{step:"Subspace 01",title:"Per-agent runtime policy",description:"Select an agent, tune guardrails, then persist all draft behavior changes.",children:e.jsx(at,{authToken:q,embedMode:x,enabled:t&&!n,initialDomain:S})})},"agents"):e.jsx(z.div,{...le,className:"grid gap-3",children:e.jsx(Z,{step:"Subspace 01",title:"Provider credentials",description:"Provision keys, validate provider readiness, and lock in routing confidence.",children:e.jsx(st,{authToken:q,embedMode:x,enabled:t&&!n})})},"providers");return e.jsx(Be,{open:t,onClose:s,maxWidth:"max-w-6xl",closeOnBackdropClick:!1,closeOnEscapeWhenTyping:!1,children:e.jsxs("div",{className:"relative flex h-full min-h-0 w-full min-w-0 flex-1 flex-col",children:[e.jsx("div",{className:"pointer-events-none absolute inset-0 opacity-60",style:{background:"radial-gradient(1200px 280px at 20% -10%, rgba(191,255,0,0.08), transparent 65%), radial-gradient(900px 240px at 95% -20%, rgba(10,212,196,0.07), transparent 68%)"},"aria-hidden":!0}),e.jsxs("div",{className:"relative z-[1] flex h-full min-h-0 flex-1 flex-col px-5 pb-3 pt-5 sm:px-7 sm:pt-6",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4 border-b border-white/[0.06] pb-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.14em] text-[#D8FFA1]/85",children:"Control Surfaces"}),e.jsx("h3",{className:"mt-1 text-title font-semibold text-white",children:"Settings"}),e.jsx("p",{className:"mt-1.5 text-body text-secondary",children:"Tuned for clarity: connection, execution policy, and provider readiness in one place."})]}),e.jsx("button",{type:"button",onClick:s,"aria-label":"Close settings",className:"inline-flex h-9 w-9 items-center justify-center rounded-full border border-white/[0.12] bg-white/[0.02] text-secondary transition-colors hover:bg-white/[0.07] hover:text-white focus:outline-none focus-visible:ring-2 focus-visible:ring-lime/45",children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 6L6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})})]}),e.jsxs("div",{className:"mt-4 min-h-0 flex-1 gap-4 lg:grid lg:grid-cols-[250px_minmax(0,1fr)]",children:[e.jsxs("aside",{className:"hidden min-h-0 flex-col gap-3 lg:flex",children:[e.jsx("nav",{className:"rounded-2xl border border-white/[0.08] bg-white/[0.02] p-2",role:"tablist","aria-label":"Settings tabs",children:re.map(_=>{const k=r===_.id;return e.jsxs(z.button,{type:"button",role:"tab","aria-selected":k,onClick:()=>l(_.id),whileHover:{x:1.5},whileTap:{scale:.985},transition:{duration:.16},className:P("relative mt-1.5 flex w-full items-start gap-2 rounded-xl px-3 py-2.5 text-left first:mt-0",k?"text-white":"text-secondary hover:text-primary"),children:[k&&e.jsx(z.span,{layoutId:"settings-tab-surface",className:"absolute inset-0 rounded-xl border border-lime/24 bg-lime/[0.10]",transition:{duration:.24,ease:Pe.easingStandard},"aria-hidden":!0}),e.jsx("span",{className:P("relative z-[1] mt-[1px] inline-flex h-7 w-7 flex-shrink-0 items-center justify-center rounded-lg border text-[11px]",k?"border-lime/30 bg-lime/[0.14] text-[#D8FFA1]":"border-white/[0.12] bg-white/[0.03] text-secondary"),children:e.jsx(ut,{id:_.id})}),e.jsxs("span",{className:"relative z-[1] min-w-0",children:[e.jsx("span",{className:"block truncate text-caption font-semibold",children:_.label}),e.jsx("span",{className:"mt-0.5 block text-caption leading-relaxed text-secondary/85",children:_.subtitle})]})]},_.id)})}),e.jsxs("div",{className:"rounded-2xl border border-white/[0.08] bg-black/25 px-4 py-3.5",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.14em] text-secondary",children:"Current focus"}),e.jsx("p",{className:"mt-1 text-body font-semibold text-white",children:v.label}),e.jsx("p",{className:"mt-1 text-caption leading-relaxed text-secondary",children:v.subtitle}),e.jsxs("div",{className:"mt-3 flex items-center gap-1.5 text-micro text-[#D8FFA1]/85",children:[e.jsx("span",{className:"h-1.5 w-1.5 animate-pulse rounded-full bg-lime/80"}),e.jsx("span",{children:"Live configuration surface"})]})]})]}),e.jsxs("section",{className:"mt-4 min-h-0 lg:mt-0",children:[e.jsx("div",{className:"mb-3 flex items-center gap-2 overflow-x-auto border-b border-white/[0.07] pb-2 lg:hidden",role:"tablist","aria-label":"Settings tabs",children:re.map(_=>{const k=r===_.id;return e.jsx("button",{type:"button",role:"tab","aria-selected":k,onClick:()=>l(_.id),className:P("relative whitespace-nowrap rounded-full border px-3 py-1.5 text-caption font-semibold transition-colors",k?"border-lime/32 bg-lime/[0.12] text-[#D8FFA1]":"border-white/[0.12] bg-white/[0.02] text-secondary"),children:_.label},_.id)})}),e.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden rounded-2xl border border-white/[0.08] bg-[#06080f]/70",children:[e.jsxs("div",{className:"border-b border-white/[0.08] px-4 py-3 sm:px-6",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-[#D8FFA1]/85",children:v.label}),e.jsx("p",{className:"mt-1 text-caption leading-relaxed text-secondary",children:v.subtitle})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-4 py-5 sm:px-6",children:e.jsx(Ce,{mode:"wait",children:y()})})]})]})]}),e.jsx("div",{className:"mt-3 border-t border-subtle px-1 pt-2",children:e.jsx($e,{compact:!0})})]})]})})}export{ft as SettingsModal};