@useorgx/openclaw-plugin 0.7.4 → 0.7.5

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 (111) hide show
  1. package/dashboard/dist/assets/{DHoYGJ9i.js → 77gGFBt6.js} +1 -1
  2. package/dashboard/dist/assets/77gGFBt6.js.br +0 -0
  3. package/dashboard/dist/assets/77gGFBt6.js.gz +0 -0
  4. package/dashboard/dist/assets/BBpTN_SR.js +1 -0
  5. package/dashboard/dist/assets/BBpTN_SR.js.br +0 -0
  6. package/dashboard/dist/assets/BBpTN_SR.js.gz +0 -0
  7. package/dashboard/dist/assets/BVShoyjA.js +1 -0
  8. package/dashboard/dist/assets/BVShoyjA.js.br +0 -0
  9. package/dashboard/dist/assets/BVShoyjA.js.gz +0 -0
  10. package/dashboard/dist/assets/{E8q3xNGK.js → BgcAY5rE.js} +1 -1
  11. package/dashboard/dist/assets/BgcAY5rE.js.br +0 -0
  12. package/dashboard/dist/assets/BgcAY5rE.js.gz +0 -0
  13. package/dashboard/dist/assets/{BdusVDcP.js → C-PAoJF-.js} +1 -1
  14. package/dashboard/dist/assets/C-PAoJF-.js.br +0 -0
  15. package/dashboard/dist/assets/C-PAoJF-.js.gz +0 -0
  16. package/dashboard/dist/assets/C0nA-iUG.js +1 -0
  17. package/dashboard/dist/assets/C0nA-iUG.js.br +0 -0
  18. package/dashboard/dist/assets/C0nA-iUG.js.gz +0 -0
  19. package/dashboard/dist/assets/C6GO-FKy.js +1 -0
  20. package/dashboard/dist/assets/C6GO-FKy.js.br +0 -0
  21. package/dashboard/dist/assets/C6GO-FKy.js.gz +0 -0
  22. package/dashboard/dist/assets/CFwPph5U.js +1 -0
  23. package/dashboard/dist/assets/CFwPph5U.js.br +0 -0
  24. package/dashboard/dist/assets/CFwPph5U.js.gz +0 -0
  25. package/dashboard/dist/assets/CPjsbbgZ.js +212 -0
  26. package/dashboard/dist/assets/CPjsbbgZ.js.br +0 -0
  27. package/dashboard/dist/assets/CPjsbbgZ.js.gz +0 -0
  28. package/dashboard/dist/assets/{Dlz0Cm_E.js → CSr2ZnTV.js} +1 -1
  29. package/dashboard/dist/assets/CSr2ZnTV.js.br +0 -0
  30. package/dashboard/dist/assets/CSr2ZnTV.js.gz +0 -0
  31. package/dashboard/dist/assets/CgQDT6yL.js +1 -0
  32. package/dashboard/dist/assets/CgQDT6yL.js.br +0 -0
  33. package/dashboard/dist/assets/CgQDT6yL.js.gz +0 -0
  34. package/dashboard/dist/assets/{CYchPSem.js → CnitK1MX.js} +1 -1
  35. package/dashboard/dist/assets/CnitK1MX.js.br +0 -0
  36. package/dashboard/dist/assets/CnitK1MX.js.gz +0 -0
  37. package/dashboard/dist/assets/{B1mDqDdy.js → D7DHFX0D.js} +1 -1
  38. package/dashboard/dist/assets/D7DHFX0D.js.br +0 -0
  39. package/dashboard/dist/assets/D7DHFX0D.js.gz +0 -0
  40. package/dashboard/dist/assets/DEip7uko.js +1 -0
  41. package/dashboard/dist/assets/DEip7uko.js.br +0 -0
  42. package/dashboard/dist/assets/DEip7uko.js.gz +0 -0
  43. package/dashboard/dist/assets/DHUSLc01.css +1 -0
  44. package/dashboard/dist/assets/DHUSLc01.css.br +0 -0
  45. package/dashboard/dist/assets/DHUSLc01.css.gz +0 -0
  46. package/dashboard/dist/assets/{DUaqjbT7.js → DOFL9l8s.js} +1 -1
  47. package/dashboard/dist/assets/DOFL9l8s.js.br +0 -0
  48. package/dashboard/dist/assets/DOFL9l8s.js.gz +0 -0
  49. package/dashboard/dist/assets/{BXapfumA.js → DpuQm1oF.js} +1 -1
  50. package/dashboard/dist/assets/DpuQm1oF.js.br +0 -0
  51. package/dashboard/dist/assets/DpuQm1oF.js.gz +0 -0
  52. package/dashboard/dist/assets/{BwkNYH6r.js → DxKG5zy8.js} +2 -2
  53. package/dashboard/dist/assets/DxKG5zy8.js.br +0 -0
  54. package/dashboard/dist/assets/DxKG5zy8.js.gz +0 -0
  55. package/dashboard/dist/assets/tcEHYcbW.js +1 -0
  56. package/dashboard/dist/assets/tcEHYcbW.js.br +0 -0
  57. package/dashboard/dist/assets/tcEHYcbW.js.gz +0 -0
  58. package/dashboard/dist/index.html +2 -2
  59. package/dashboard/dist/index.html.br +0 -0
  60. package/dashboard/dist/index.html.gz +0 -0
  61. package/dist/http/index.js +1 -0
  62. package/dist/http/routes/live-legacy.js +89 -3
  63. package/dist/http/routes/live-misc.d.ts +1 -0
  64. package/dist/http/routes/live-misc.js +76 -0
  65. package/dist/http/routes/mission-control-read.d.ts +4 -0
  66. package/dist/http/routes/mission-control-read.js +8 -0
  67. package/dist/http/routes/usage.js +15 -3
  68. package/dist/json-utils.js +5 -1
  69. package/package.json +6 -1
  70. package/dashboard/dist/assets/B1mDqDdy.js.br +0 -0
  71. package/dashboard/dist/assets/B1mDqDdy.js.gz +0 -0
  72. package/dashboard/dist/assets/BDMstdfu.js +0 -1
  73. package/dashboard/dist/assets/BDMstdfu.js.br +0 -0
  74. package/dashboard/dist/assets/BDMstdfu.js.gz +0 -0
  75. package/dashboard/dist/assets/BXapfumA.js.br +0 -0
  76. package/dashboard/dist/assets/BXapfumA.js.gz +0 -0
  77. package/dashboard/dist/assets/BZZKPNDb.css +0 -1
  78. package/dashboard/dist/assets/BZZKPNDb.css.br +0 -0
  79. package/dashboard/dist/assets/BZZKPNDb.css.gz +0 -0
  80. package/dashboard/dist/assets/BdusVDcP.js.br +0 -0
  81. package/dashboard/dist/assets/BdusVDcP.js.gz +0 -0
  82. package/dashboard/dist/assets/BwkNYH6r.js.br +0 -0
  83. package/dashboard/dist/assets/BwkNYH6r.js.gz +0 -0
  84. package/dashboard/dist/assets/CRhvoVeH.js +0 -1
  85. package/dashboard/dist/assets/CRhvoVeH.js.br +0 -0
  86. package/dashboard/dist/assets/CRhvoVeH.js.gz +0 -0
  87. package/dashboard/dist/assets/CYchPSem.js.br +0 -0
  88. package/dashboard/dist/assets/CYchPSem.js.gz +0 -0
  89. package/dashboard/dist/assets/Cn07669c.js +0 -212
  90. package/dashboard/dist/assets/Cn07669c.js.br +0 -0
  91. package/dashboard/dist/assets/Cn07669c.js.gz +0 -0
  92. package/dashboard/dist/assets/DBG89Wsz.js +0 -1
  93. package/dashboard/dist/assets/DBG89Wsz.js.br +0 -0
  94. package/dashboard/dist/assets/DBG89Wsz.js.gz +0 -0
  95. package/dashboard/dist/assets/DHoYGJ9i.js.br +0 -0
  96. package/dashboard/dist/assets/DHoYGJ9i.js.gz +0 -0
  97. package/dashboard/dist/assets/DHtZPEKd.js +0 -1
  98. package/dashboard/dist/assets/DHtZPEKd.js.br +0 -0
  99. package/dashboard/dist/assets/DHtZPEKd.js.gz +0 -0
  100. package/dashboard/dist/assets/DUaqjbT7.js.br +0 -0
  101. package/dashboard/dist/assets/DUaqjbT7.js.gz +0 -0
  102. package/dashboard/dist/assets/Dlz0Cm_E.js.br +0 -0
  103. package/dashboard/dist/assets/Dlz0Cm_E.js.gz +0 -0
  104. package/dashboard/dist/assets/E8q3xNGK.js.br +0 -0
  105. package/dashboard/dist/assets/E8q3xNGK.js.gz +0 -0
  106. package/dashboard/dist/assets/VH0fzk6I.js +0 -1
  107. package/dashboard/dist/assets/VH0fzk6I.js.br +0 -0
  108. package/dashboard/dist/assets/VH0fzk6I.js.gz +0 -0
  109. package/dashboard/dist/assets/bxgRC96y.js +0 -1
  110. package/dashboard/dist/assets/bxgRC96y.js.br +0 -0
  111. package/dashboard/dist/assets/bxgRC96y.js.gz +0 -0
@@ -1 +0,0 @@
1
- import{r as o,j as t}from"./cNrhgGc1.js";import{i as L,b as C,a2 as M}from"./Cn07669c.js";function R(c){const i=Date.parse(c);if(!Number.isFinite(i))return null;const s=Date.now()-i,r=s<0,a=Math.abs(s),d=Math.round(a/6e4);if(d<1)return r?"soon":"just now";if(d<60)return r?`in ${d}m`:`${d}m ago`;const u=Math.round(a/36e5);if(u<48)return r?`in ${u}h`:`${u}h ago`;const p=Math.round(a/864e5);return p<30?r?`in ${p}d`:`${p}d ago`:new Date(i).toLocaleDateString()}async function T(c,i){const s=await fetch(c,i);if(!s.ok){const r=await s.json().catch(()=>null),a=typeof(r==null?void 0:r.error)=="string"&&r.error||typeof(r==null?void 0:r.message)=="string"&&r.message||`Request failed (${s.status})`;throw new Error(a)}return await s.json()}function K(c){const{entityType:i,entityId:s,authToken:r,embedMode:a,className:d,variant:u="default"}=c,[p,b]=o.useState(!0),[j,v]=o.useState(!1),[N,x]=o.useState(null),[E,S]=o.useState([]),[h,g]=o.useState(""),m=L(),y=o.useMemo(()=>{const e=encodeURIComponent(i),n=encodeURIComponent(s);return`/orgx/api/entities/${e}/${n}/comments`},[i,s]),f=o.useCallback(async()=>{if(m){S([]),x(null),b(!1);return}b(!0),x(null);try{const e=await T(y,{method:"GET",headers:C({authToken:r,embedMode:a})});S(Array.isArray(e.comments)?e.comments:[])}catch(e){x(e instanceof Error?e.message:String(e))}finally{b(!1)}},[r,m,a,y]);o.useEffect(()=>{f()},[f]);const w=o.useCallback(async()=>{if(m){g("");return}const e=h.trim();if(e){v(!0),x(null);try{await T(y,{method:"POST",headers:C({authToken:r,embedMode:a,contentTypeJson:!0}),body:JSON.stringify({body:e,commentType:"note",severity:"info",tags:[]})}),g(""),await f()}catch(n){x(n instanceof Error?n.message:String(n))}finally{v(!1)}}},[r,h,m,a,y,f]),_=o.useCallback(e=>{e.key==="Enter"&&(!e.metaKey&&!e.ctrlKey||(e.preventDefault(),w()))},[w]),l=u==="inline";return t.jsxs("div",{className:d,children:[t.jsxs("div",{className:l?"space-y-1":"space-y-2",children:[t.jsx("textarea",{value:h,onChange:e=>g(e.target.value),onKeyDown:_,placeholder:"Leave a note for humans or agents...",className:l?"min-h-[60px] w-full resize-y border-b border-white/[0.06] bg-transparent px-0 py-2 text-body text-bright outline-none placeholder:text-faint focus:border-white/15 transition-colors":"min-h-[96px] w-full resize-y rounded-xl border border-white/[0.10] bg-white/[0.03] px-4 py-3 text-body text-bright outline-none placeholder:text-faint focus:border-white/20 focus:bg-white/[0.05] transition-colors"}),t.jsxs("div",{className:`flex flex-wrap items-center justify-between gap-3 ${l?"opacity-70":""}`,children:[t.jsx("p",{className:"text-caption text-muted",children:"Cmd/Ctrl+Enter to post. Visible to agents and collaborators."}),t.jsx("button",{type:"button",onClick:w,disabled:j||h.trim().length===0,className:l?"text-caption font-semibold text-primary hover:text-white transition-colors disabled:opacity-50":"inline-flex items-center justify-center rounded-full border border-strong bg-white/[0.05] px-3.5 py-1.5 text-caption font-semibold tracking-wide text-primary transition-colors hover:bg-white/[0.09] disabled:opacity-50 disabled:hover:bg-white/[0.05]",children:j?"Saving…":"Post note"})]})]}),N?t.jsx("div",{className:`mt-2 text-caption text-red-200 ${l?"":"rounded-xl border border-red-500/20 bg-red-500/10 px-3.5 py-2"}`,children:N}):null,p?t.jsx("div",{className:"mt-2 text-body text-muted",children:"Loading notes…"}):E.length===0?t.jsx("div",{className:"mt-2 text-body text-muted",children:m?"Notes are unavailable in demo mode.":"No notes yet."}):t.jsx("div",{className:`mt-2 space-y-2 ${l?"divide-y divide-white/[0.06]":"space-y-3"}`,children:E.map(e=>{const n=e.created_at?R(e.created_at):null,k=e.author_name??(e.author_type==="agent"?e.author_id:"Unknown");if(l)return t.jsxs("div",{className:"pt-2 first:pt-0",children:[t.jsxs("div",{className:"flex items-center gap-2 text-micro text-muted",children:[t.jsx("span",{className:"font-medium text-secondary",children:k}),n?t.jsx("span",{title:M(e.created_at),children:n}):null]}),t.jsx("p",{className:"mt-0.5 whitespace-pre-wrap text-body leading-relaxed text-primary",children:e.body})]},e.id);const D=e.comment_type??"note",$=typeof e.severity=="string"?e.severity:"info";return t.jsxs("div",{className:"rounded-2xl border border-white/[0.10] bg-white/[0.02] px-4 py-3",children:[t.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx("span",{className:"text-body font-semibold text-bright",children:k}),t.jsx("span",{className:"rounded-full border border-strong bg-white/[0.06] px-2 py-0.5 text-micro uppercase tracking-[0.08em] text-secondary",children:e.author_type}),t.jsx("span",{className:"rounded-full border border-strong px-2 py-0.5 text-micro uppercase tracking-[0.08em] text-secondary",children:D}),$!=="info"?t.jsx("span",{className:"rounded-full border border-strong px-2 py-0.5 text-micro uppercase tracking-[0.08em] text-secondary",children:$}):null]}),n?t.jsx("span",{className:"text-caption text-muted",title:M(e.created_at),children:n}):null]}),t.jsx("p",{className:"mt-2 whitespace-pre-wrap text-body leading-relaxed text-primary",children:e.body})]},e.id)})})]})}export{K as E};
@@ -1 +0,0 @@
1
- import{r as b,j as e,u as Ne,a as ie,b as xe}from"./cNrhgGc1.js";import{O as Se,w as F,i as ae,b as J,Q as Pe,R as ve,S as Fe,r as qe,T as Re,V as oe}from"./Cn07669c.js";import{m as Q,A as ke}from"./CxQ08qFN.js";import"./C-KIc3Wc.js";import"./BJgZIVUQ.js";function Ee(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 Ce(t,s){return t==="connected"&&s?"connected":t==="awaiting_browser_auth"||t==="pairing"||t==="starting"?"connecting":t==="error"?"error":"idle"}function Ie({phase:t}){const s=t==="connected"||t==="connecting"?"bg-[#BFFF00]":t==="error"?"bg-red-400":"bg-white/30",o=t==="connecting";return e.jsxs("span",{className:"relative flex h-2.5 w-2.5 shrink-0",children:[o&&e.jsx("span",{className:F("absolute inline-flex h-full w-full animate-ping rounded-full opacity-40",s)}),e.jsx("span",{className:F("relative inline-flex h-2.5 w-2.5 rounded-full",s)})]})}function Be({phase:t}){const s=t==="connected"?"Connected":t==="connecting"?"Connecting...":t==="error"?"Connection issue":"Not connected",o=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(Ie,{phase:t}),e.jsx("span",{className:F("text-body font-semibold",o),children:s})]})}function De({phase:t,hasApiKey:s,verified:o,workspaceName:p}){const n=[{id:"connect",label:"Connect",detail:"Provide credentials",done:s||o},{id:"verify",label:"Verify",detail:"Confirm live sync",done:o},{id:"scope",label:"Scope",detail:p||"Select workspace",done:t==="connected"}],y=t==="connecting"?"verify":t==="connected"?"scope":s?"verify":"connect";return e.jsx("ol",{className:"mt-4 grid gap-2 rounded-xl border border-white/[0.08] bg-black/20 p-3 md:grid-cols-3",children:n.map((h,l)=>{const u=h.id===y;return e.jsxs("li",{className:"relative min-w-0",children:[l>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:F("rounded-lg border px-2.5 py-2",h.done?"border-lime/26 bg-lime/[0.08]":u?"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:F("inline-flex h-4 w-4 items-center justify-center rounded-full border text-[10px] font-semibold",h.done?"border-lime/35 bg-lime/[0.18] text-[#D8FFA1]":u?"border-teal/35 bg-teal/[0.16] text-teal-100":"border-white/[0.14] bg-white/[0.03] text-secondary"),children:l+1}),e.jsx("p",{className:"truncate text-caption font-semibold text-primary",children:h.label})]}),e.jsx("p",{className:"mt-1 truncate text-micro text-secondary",children:h.detail})]})]},h.id)})})}function $e({state:t,isStarting:s,isSubmittingManual:o,workspaceOptions:p,selectedWorkspaceId:n,onSelectWorkspace:y,onRefresh:h,onStartPairing:l,onSubmitManualKey:u,onBackToPairing:A,onUseManualKey:v,onDisconnect:f}){const w="https://www.useorgx.com/settings#security",m=Ce(t.status,t.connectionVerified),E=t.status==="manual_key",g=t.status==="awaiting_browser_auth"||t.status==="pairing"||t.status==="starting",_=!!t.lastError,N=Ee(t.keySource),j=b.useMemo(()=>m==="connected"?"Live sync is active. Initiatives, tasks, and activity flow in real time.":m==="connecting"?"Approve the pairing in your browser to finish connecting.":m==="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.",[m,t.hasApiKey]),S=m==="connected"?"border-[#BFFF00]/15":m==="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:j})]}),_&&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}),E?e.jsx(Se,{isSubmitting:o,onSubmit:u,onBack:A}):e.jsxs("div",{className:F("rounded-2xl border bg-white/[0.02] p-5",S),children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx(Be,{phase:m}),e.jsx("button",{type:"button",onClick:()=>{h()},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.jsx(De,{phase:m,hasApiKey:t.hasApiKey,verified:t.connectionVerified,workspaceName:t.workspaceName}),m==="connected"&&e.jsxs("div",{className:"mt-4 grid gap-3 text-body text-secondary",children:[e.jsxs("div",{className:"max-w-sm",children:[e.jsx("label",{htmlFor:"settings-workspace-scope",className:"mb-1.5 block text-caption uppercase tracking-[0.08em] text-muted",children:"Workspace scope"}),e.jsxs("div",{className:"relative",children:[e.jsxs("select",{id:"settings-workspace-scope",value:n??"__all__",onChange:k=>{const D=k.target.value;y(D==="__all__"?null:D)},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"}),p.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"})})]})]}),t.workspaceName&&e.jsxs("p",{className:"text-caption text-muted",children:["Connected account: ",e.jsx("span",{className:"text-secondary",children:t.workspaceName})]}),N&&e.jsxs("div",{className:"flex items-baseline gap-1.5",children:[e.jsx("span",{className:"text-muted",children:"Authenticated via"}),e.jsx("span",{className:"text-primary",children:N})]})]}),m==="idle"&&t.hasApiKey&&!t.connectionVerified&&e.jsxs("p",{className:"mt-3 text-caption text-amber-200/70",children:["Key detected",N?` from ${N}`:""," but not yet verified. Refresh or reconnect to activate live sync."]}),g&&t.connectUrl&&e.jsxs("div",{className:"mt-4 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"})]})]})]}),e.jsx("div",{className:F("flex flex-wrap items-center gap-2",m==="connected"?"mt-5":"mt-4"),children:m==="connected"?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>{l()},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:()=>{f()},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:w,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:()=>{l()},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:v,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:()=>{f()},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"})]})})]}),m!=="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 Me=/^[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 Ae(t){if(typeof t!="string")return null;const s=t.trim();return Me.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 Te(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 Ue(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:Te(t.runtime_settings)}}function ge(t){if(!t||t.ok!==!0||!t.data||t.data.ok!==!0)return{projectId:null,agents:[]};const s=t.data,o=Array.isArray(s.agents)?s.agents:s.agent?[s.agent]:[];return{projectId:Ae(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:o.map(Ue)}}function _e({authToken:t=null,embedMode:s=!1,enabled:o=!0}={}){var f,w,m,E;const p=Ne(),n=ae(),y=b.useMemo(()=>["agent-suite",{authToken:t,embedMode:s}],[t,s]),h=b.useMemo(()=>["agent-suite-runtime-settings",{authToken:t,embedMode:s}],[t,s]),l=ie({queryKey:y,enabled:o,queryFn:async()=>{if(n)return{ok:!1,error:"Agent suite controls are unavailable in demo mode."};const g=await fetch("/orgx/api/agent-suite/status",{headers:J({authToken:t,embedMode:s})}),_=await g.json().catch(()=>null);return g.ok?_:{ok:!1,error:(_==null?void 0:_.error)??`Failed to load agent suite (${g.status})`}},staleTime:1e4}),u=ie({queryKey:h,enabled:o,queryFn:async()=>{if(n)return{projectId:null,agents:[]};const g=await fetch("/orgx/api/agent-suite/runtime-settings",{headers:J({authToken:t,embedMode:s})}),_=await g.json().catch(()=>null);if(!g.ok){const N=_==null?void 0:_.error,j=typeof N=="string"?N.trim():"",S=j.includes("<!DOCTYPE")||j.includes("<html"),k=g.status===404?"Agent runtime settings endpoint is not available in this plugin build.":j.length>0&&!S?j:`Failed to load agent runtime settings (${g.status})`;throw new Error(k)}return ge(_??null)},staleTime:1e4}),A=xe({mutationFn:async({dryRun:g,forceSkillPack:_}={})=>{if(n)return{ok:!1,error:"Agent suite install is unavailable in demo mode."};const N=await fetch("/orgx/api/agent-suite/install",{method:"POST",headers:J({authToken:t,embedMode:s,contentTypeJson:!0}),body:JSON.stringify({dryRun:!!g,forceSkillPack:!!_})}),j=await N.json().catch(()=>null);if(!N.ok)throw new Error((j==null?void 0:j.error)??`Failed to install agent suite (${N.status})`);return j},onSuccess:async()=>{await p.invalidateQueries({queryKey:y})}}),v=xe({mutationFn:async g=>{if(n)return{projectId:null,agents:[]};const _=Ae(g.projectId??null),N=await fetch("/orgx/api/agent-suite/runtime-settings",{method:"PATCH",headers:J({authToken:t,embedMode:s,contentTypeJson:!0}),body:JSON.stringify({..._?{workspace_id:_}:{},agent_id:g.agentId,runtime_settings:{decision_v2_enabled:g.runtimeSettings.decisionV2Enabled,decision_dedupe_enabled:g.runtimeSettings.decisionDedupeEnabled,decision_evidence_required_for_blocking:g.runtimeSettings.decisionEvidenceRequiredForBlocking,decision_auto_resolve_guarded_enabled:g.runtimeSettings.decisionAutoResolveGuardedEnabled,question_auto_answer_enabled:g.runtimeSettings.questionAutoAnswerEnabled,question_auto_answer_timeout_sec:g.runtimeSettings.questionAutoAnswerTimeoutSec,question_auto_answer_policy:g.runtimeSettings.questionAutoAnswerPolicy,question_blocking_behavior:g.runtimeSettings.questionBlockingBehavior,question_policy_version:g.runtimeSettings.questionPolicyVersion,question_auto_answer_delay_seconds:g.runtimeSettings.questionAutoAnswerDelaySeconds,question_auto_answer_action:g.runtimeSettings.questionAutoAnswerAction,custom_run_instructions:g.runtimeSettings.customRunInstructions}})}),j=await N.json().catch(()=>null);if(!N.ok)throw new Error((j==null?void 0:j.error)??`Failed to save agent runtime settings (${N.status})`);return ge(j??null)},onSuccess:async()=>{await p.invalidateQueries({queryKey:h})}});return{status:l.data??null,isLoading:l.isLoading,isRefetching:l.isRefetching,error:(l.data&&"error"in l.data?l.data.error:null)??((f=l.error)==null?void 0:f.message)??null,installError:((w=A.error)==null?void 0:w.message)??null,runtimeSettings:u.data??{projectId:null,agents:[]},runtimeSettingsError:((m=u.error)==null?void 0:m.message)??null,isRuntimeSettingsLoading:u.isLoading,isRuntimeSettingsRefetching:u.isRefetching,refetchRuntimeSettings:u.refetch,saveRuntimeSettings:v.mutate,saveRuntimeSettingsAsync:v.mutateAsync,saveRuntimeSettingsError:((E=v.error)==null?void 0:E.message)??null,isSavingRuntimeSettings:v.isPending,refetchStatus:l.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 H({tone:t,children:s}){const o=b.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:F("inline-flex items-center rounded-full border px-2.5 py-1 text-caption font-semibold",o),children:s})}const le={conservative:"Conservative",balanced:"Balanced",autonomous:"Autonomous"},Le={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 Oe(t){return t?t.frozen&&t.pinnedChecksum?"conservative":!t.frozen&&t.pinnedChecksum?"balanced":!t.frozen&&!t.pinnedChecksum?"autonomous":null:null}function Ke(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 ze({plan:t,agentId:s,sampleTaskId:o}){var v;const p=t.workspaceFiles.filter(f=>f.action!=="noop"),n=p.filter(f=>f.action==="conflict").length,y=p.filter(f=>f.action==="create").length,h=p.filter(f=>f.action==="update").length,l=[];n>0&&l.push(`${W(n,"managed file")} needs review before apply.`),t.skillPackUpdateAvailable&&l.push("Remote skill update is available; behavior could drift after refresh."),(v=t.skillPackPolicy)!=null&&v.frozen&&l.push("Skill pack is frozen; preview reflects pinned behavior only.");const u=[`Load draft simulation for ${s}.`,`Run sample task "${o}" 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(p.length,"workspace file")} changed (${y} create, ${h} update).`,`Progress stream expected at start and completion for sample "${o}".`];return{outcome:l.length>0?"warning":"ready",executionTrace:u,riskFlags:l,expectedOutputs:A,confidence:l.length>0?"Medium confidence: preview is deterministic but includes review-dependent flags.":"High confidence: preview is deterministic with no active risk flags."}}function Ve({authToken:t=null,embedMode:s=!1,enabled:o=!0,devMode:p=!1}){var M,Y,te,pe,he;const[n,y]=b.useState(!1),[h,l]=b.useState(""),[u,A]=b.useState("triage-sample"),[v,f]=b.useState(null),[w,m]=b.useState(null),[E,g]=b.useState(!1),[_,N]=b.useState(null),[j,S]=b.useState(null),[k,D]=b.useState(null),[c,P]=b.useState(null),x=_e({authToken:t,embedMode:s,enabled:o}),a=(M=x.status)!=null&&M.ok?x.status.data:null,I=((Y=a==null?void 0:a.agents)==null?void 0:Y.length)??0,C=((te=a==null?void 0:a.openclawConfigAddedAgents)==null?void 0:te.length)??0,R=b.useMemo(()=>{var r;return((r=a==null?void 0:a.workspaceFiles)==null?void 0:r.filter(T=>T.action!=="noop"))??[]},[a]),B=R.length,X=b.useMemo(()=>R.filter(r=>r.action==="create").length,[R]),U=b.useMemo(()=>R.filter(r=>r.action==="update").length,[R]),$=b.useMemo(()=>R.filter(r=>r.action==="conflict").length,[R]),Z=b.useMemo(()=>{if(x.isLoading)return"Loading agent suite status...";if(x.error)return`Unable to read suite status: ${x.error}`;if(!a)return"Suite status unavailable.";if($>0)return`${W($,"file")} to review.`;if(C===0&&B===0)return"Suite is installed and up to date.";const r=[];return C>0&&r.push(`will add ${W(C,"agent")}`),B>0&&r.push(`will update ${W(B,"file")}`),`Preview: ${r.join(", ")}.`},[B,$,C,a,x.error,x.isLoading]),z=(pe=x.installResult)!=null&&pe.ok?x.installResult:null,L=!!(z!=null&&z.dryRun),V=Oe((a==null?void 0:a.skillPackPolicy)??null),i=async()=>{var T;if(!a||x.isInstalling||E)return;const r=h||(((T=a.agents[0])==null?void 0:T.id)??"unassigned-agent");y(!0),g(!0),m(null);try{const O=await x.installAsync({dryRun:!0});if(!O.ok)throw new Error(O.error??"Dry-run failed.");f(ze({plan:O.data,agentId:r,sampleTaskId:u})),N(new Date().toISOString())}catch(O){m(O instanceof Error?O.message:"Dry-run failed.")}finally{g(!1)}},d=async r=>{await fetch("/orgx/api/skill-pack/policy",{method:"POST",headers:J({authToken:t,embedMode:s,contentTypeJson:!0}),body:JSON.stringify(r)}).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 x.refetchStatus()},q=async r=>{if(!(!(a!=null&&a.skillPackPolicy)||j)){P(null),D(null),S(r);try{await d(Ke(r)),D(`${le[r]} preset applied.`)}catch(T){P(T instanceof Error?T.message:"Failed to apply preset.")}finally{S(null)}}};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:"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.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>{x.resetInstall(),x.refetchStatus()},disabled:x.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:x.isRefetching?"Refreshing...":"Refresh"}),e.jsx("button",{type:"button",onClick:()=>{i()},disabled:x.isInstalling||E,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:E?"Testing config...":"Test This Config"}),e.jsx("button",{type:"button",onClick:()=>{x.install({dryRun:!1,forceSkillPack:!0})},disabled:x.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:()=>{x.install({dryRun:!1})},disabled:x.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:x.isInstalling?"Installing...":"Install / Update"})]})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsx(H,{tone:x.error?"warn":"neutral",children:Z}),a&&e.jsxs(e.Fragment,{children:[e.jsx(H,{tone:C===0?"good":"neutral",children:C===0?"agents configured":`${C} agents to install`}),e.jsxs(H,{tone:"neutral",children:[W(I,"agent")," total"]}),e.jsx(H,{tone:B===0?"good":"neutral",children:B===0?"no file changes":`${B} file changes`}),$>0&&e.jsx(H,{tone:"neutral",children:W($,"file to review")}),a.skillPackUpdateAvailable&&e.jsx(H,{tone:"warn",children:"skill update available"}),((he=a.skillPackPolicy)==null?void 0:he.frozen)&&e.jsx(H,{tone:"neutral",children:"skills frozen"})]})]}),x.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:x.installError}),z&&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:[p&&z.operationId&&e.jsxs(e.Fragment,{children:["Operation ",e.jsx("code",{className:"rounded bg-black/40 px-1",children:z.operationId})," "]}),L?"Computed the plan without writing any files.":"Installed config and refreshed managed files."]})]}),a&&e.jsxs("div",{className:"mt-4",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:h,onChange:r=>l(r.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"}),a.agents.map(r=>e.jsxs("option",{value:r.id,children:[r.name," (",r.id,")"]},r.id))]})]}),e.jsxs("label",{className:"grid gap-1.5 text-caption text-secondary",children:["Sample task",e.jsxs("select",{value:u,onChange:r=>A(r.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"})]})]})]}),w&&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:w}),v&&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(H,{tone:v.outcome==="ready"?"good":"warn",children:v.outcome==="ready"?"Ready to apply":"Review recommended"})]}),_&&e.jsx("p",{className:"mt-1 text-caption text-secondary",children:new Date(_).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:v.executionTrace.map((r,T)=>e.jsxs("li",{children:[T+1,". ",r]},r))})]}),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:v.riskFlags.length>0?v.riskFlags.map(r=>e.jsx("p",{children:r},r)):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:[v.expectedOutputs.map(r=>e.jsx("p",{children:r},r)),e.jsx("p",{className:"text-primary",children:v.confidence})]})]})]})]})]}),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:()=>y(r=>!r),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"}),p?e.jsx("code",{className:"rounded bg-black/40 px-1.5 py-0.5 text-caption text-primary",children:a.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:[a.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:[a.packId,"@",a.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:a.skillPack?`${a.skillPack.name}@${a.skillPack.version} (${a.skillPack.source})`:"builtin"})]}),a.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:[a.skillPackRemote.name,"@",a.skillPackRemote.version]})]}),a.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:[a.skillPackPolicy.frozen?"frozen":"live",a.skillPackPolicy.pinnedChecksum?`, pinned:${a.skillPackPolicy.pinnedChecksum.slice(0,8)}…`:""]})]}),a.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(H,{tone:V?"good":"neutral",children:V?`Active: ${le[V]}`:"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(r=>{const T=V===r,O=j===r;return e.jsxs("button",{type:"button",onClick:()=>{q(r)},disabled:!!j,className:F("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…":le[r]}),e.jsx("p",{className:"mt-1 text-caption text-secondary",children:Le[r]})]},r)})}),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})]}),a.skillPackPolicy&&e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>{var r;d({frozen:!((r=a.skillPackPolicy)!=null&&r.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:a.skillPackPolicy.frozen?"Unfreeze skills":"Freeze skills"}),e.jsx("button",{type:"button",onClick:()=>{var r;(r=a.skillPackPolicy)!=null&&r.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:a.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:a.agents.map(r=>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:r.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:r.id}),e.jsx("span",{className:"px-1",children:"·"}),e.jsx("span",{children:r.domain})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(H,{tone:r.configuredInOpenclaw?"good":"neutral",children:r.configuredInOpenclaw?"configured":"to install"}),e.jsx(H,{tone:r.workspaceExists?"good":"neutral",children:r.workspaceExists?"workspace ok":"workspace missing"})]})]},r.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(a.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:B})]}),(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"]})]})]}),C>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:a.openclawConfigAddedAgents.map(r=>e.jsx("code",{className:"rounded-full border border-strong bg-black/40 px-2 py-0.5 text-caption text-primary",children:r},r))})]}),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(r=>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:[r.agentId,"/",r.file]}),e.jsx("span",{className:"text-secondary",children:r.action})]},`${r.agentId}:${r.file}`)),R.length>24&&e.jsxs("p",{className:"text-caption text-muted",children:["Showing 24 of ",R.length,". Install/Update to apply all."]})]})]})]})]})]})]})}function be(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 He(){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 Ge({authToken:t=null,embedMode:s=!1,enabled:o=!0}={}){var A,v;const p=Ne(),n=b.useMemo(()=>["byok-settings",{authToken:t,embedMode:s}],[t,s]),y=b.useMemo(()=>["byok-health",{authToken:t,embedMode:s}],[t,s]),h=ie({queryKey:n,enabled:o,queryFn:async()=>{if(ae())return be();const f=await fetch("/orgx/api/settings/byok",{headers:J({authToken:t,embedMode:s})}),w=await f.json().catch(()=>null);return f.ok?w:{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:(w==null?void 0:w.error)??`Failed to load settings (${f.status})`}},staleTime:15e3}),l=ie({queryKey:y,enabled:!1,queryFn:async()=>{if(ae())return He();const f=await fetch("/orgx/api/settings/byok/health",{headers:J({authToken:t,embedMode:s})}),w=await f.json().catch(()=>null);return f.ok?w:{ok:!1,agentId:"main",providers:{openai:{ok:!1,error:(w==null?void 0:w.error)??`Probe failed (${f.status})`},anthropic:{ok:!1,error:(w==null?void 0:w.error)??`Probe failed (${f.status})`},openrouter:{ok:!1,error:(w==null?void 0:w.error)??`Probe failed (${f.status})`}},error:(w==null?void 0:w.error)??`Probe failed (${f.status})`}}}),u=xe({mutationFn:async f=>{if(ae())return be({openai:typeof f.openaiApiKey=="string"&&f.openaiApiKey.trim().length>0,anthropic:typeof f.anthropicApiKey=="string"&&f.anthropicApiKey.trim().length>0,openrouter:typeof f.openrouterApiKey=="string"&&f.openrouterApiKey.trim().length>0});const w=await fetch("/orgx/api/settings/byok",{method:"POST",headers:J({authToken:t,embedMode:s,contentTypeJson:!0}),body:JSON.stringify(f??{})}),m=await w.json().catch(()=>null);if(!w.ok)throw new Error((m==null?void 0:m.error)??`Failed to save settings (${w.status})`);return m},onSuccess:async()=>{await p.invalidateQueries({queryKey:n})}});return{status:h.data??null,isLoading:h.isLoading,error:((A=h.data)==null?void 0:A.error)??((v=h.error)==null?void 0:v.message)??null,refetchStatus:h.refetch,update:u.mutateAsync,isSaving:u.isPending,health:l.data??null,probe:l.refetch,isProbing:l.isFetching}}const ne=[{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 fe(t){return t==="openai"?"openaiApiKey":t==="anthropic"?"anthropicApiKey":"openrouterApiKey"}function Qe(t){var s;return((s=ne.find(o=>o.id===t))==null?void 0:s.label)??t}function We({authToken:t=null,embedMode:s=!1,enabled:o=!0}){const p=Ge({authToken:t,embedMode:s,enabled:o}),n=p.status,y=p.health,[h,l]=b.useState({openai:"",anthropic:"",openrouter:""}),[u,A]=b.useState({openai:!1,anthropic:!1,openrouter:!1}),[v,f]=b.useState({openai:!1,anthropic:!1,openrouter:!1}),[w,m]=b.useState(null),[E,g]=b.useState(null);b.useEffect(()=>{o&&(l({openai:"",anthropic:"",openrouter:""}),A({openai:!1,anthropic:!1,openrouter:!1}),f({openai:!1,anthropic:!1,openrouter:!1}),m(null),g(null))},[o]);const _=b.useMemo(()=>n!=null&&n.ok?Number(n.providers.openai.configured)+Number(n.providers.anthropic.configured)+Number(n.providers.openrouter.configured):0,[n]),N=b.useMemo(()=>{var a;const c=ne.map(I=>{var B;const C=(B=n==null?void 0:n.providers)==null?void 0:B[I.id],R=u[I.id]&&h[I.id].trim().length>0;return{id:I.id,label:I.label,configured:R||!!(C!=null&&C.configured),source:R?"pending stored key":(C==null?void 0:C.source)??"none",pending:R?"save":"none"}}),P=c.filter(I=>I.configured),x=P.length===0?"Run preview: launch blocked until at least one provider key is configured.":P.length===1?`Run preview: launches with ${(a=P[0])==null?void 0:a.label} as the only provider.`:`Run preview: launches with ${P.length} providers available for routing.`;return{providers:c,activeProviders:P,summary:x}},[u,n,h]),j=b.useMemo(()=>{const c=ne.filter(x=>{var I;const a=(I=y==null?void 0:y.providers)==null?void 0:I[x.id];return!!(a!=null&&a.ok)}).length,P=ne.filter(x=>u[x.id]&&h[x.id].trim().length>0).length;return{readyProviders:c,pendingSaves:P}},[u,y==null?void 0:y.providers,h]),S=async c=>{if(!o)return;g(null);const P=h[c].trim();if(!u[c])return;if(!P){g(`Enter a ${Qe(c)} API key or use "Clear" to remove the saved key.`);return}const x=fe(c);try{m(c),await p.update({[x]:P}),A(a=>({...a,[c]:!1})),l(a=>({...a,[c]:""})),f(a=>({...a,[c]:!1}))}finally{m(null)}},k=async c=>{g(null);const P=fe(c);try{m(c),await p.update({[P]:null}),A(x=>({...x,[c]:!1})),l(x=>({...x,[c]:""})),f(x=>({...x,[c]:!1}))}finally{m(null)}},D=async()=>{g(null),await p.probe()};return e.jsxs("div",{className:"flex min-h-0 flex-col",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."}),_===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:[_," / 3 configured"]}),(n==null?void 0:n.updatedAt)&&e.jsxs("span",{className:"text-caption text-muted",children:["Updated ",new Date(n.updatedAt).toLocaleString()]})]})]}),(E||p.error)&&e.jsx("div",{className:"mb-4 rounded-xl border border-rose-300/20 bg-rose-400/10 p-4 text-body text-rose-100",children:E??p.error}),e.jsxs("div",{className:"mb-4 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:"mb-4 rounded-2xl border border-lime/20 bg-lime/[0.05] p-4",children:[e.jsx("p",{className:"text-body font-semibold text-[#D8FFA1]",children:"Agent run preview"}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:N.summary}),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:[_," / 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:j.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:j.pendingSaves})]})]}),e.jsx("div",{className:"mt-3 grid gap-2 sm:grid-cols-3",children:N.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:F("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"?" (not saved yet)":""]})]},c.id))})]}),e.jsx("div",{className:"grid grid-cols-1 gap-4",children:ne.map((c,P)=>{var Z,z;const x=(Z=n==null?void 0:n.providers)==null?void 0:Z[c.id],a=(z=y==null?void 0:y.providers)==null?void 0:z[c.id],I=(x==null?void 0:x.masked)??null,C=(x==null?void 0:x.source)??"none",R=C==="stored",B=w===c.id,X=u[c.id]&&h[c.id].trim().length>0&&!p.isSaving&&!B,U=R&&!p.isSaving&&!B,$=R?"Update":"Save";return e.jsxs(Q.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},transition:{delay:Math.min(P,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",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"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:F("rounded-full border px-2 py-0.5 text-micro uppercase tracking-[0.12em]",x!=null&&x.configured?"border-emerald-300/25 bg-emerald-400/10 text-emerald-100":"border-strong bg-white/[0.03] text-secondary"),children:x!=null&&x.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:[C!=="none"&&e.jsxs("span",{className:"chip",children:["source: ",C]}),I&&e.jsxs("span",{className:"chip",children:["key: ",I]}),a&&e.jsx("span",{className:F("chip",a.ok?"text-emerald-100":"text-rose-100"),children:a.ok?`ready (${a.modelCount??0} models)`:"not ready"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>f(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:v[c.id]?"Hide key":"Show key",children:v[c.id]?"Hide":"Show"}),e.jsx("button",{type:"button",onClick:()=>void D(),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(),S(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:h[c.id],onChange:L=>{l(V=>({...V,[c.id]:L.target.value})),A(V=>({...V,[c.id]:!0})),E&&g(null)},type:v[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",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:B?"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:u[c.id]?"Unsaved changes":" "})]})]})]},c.id)})})]})}const ye={engineering:"Engineering",product:"Product",design:"Design",marketing:"Marketing",sales:"Sales",operations:"Operations",orchestration:"Orchestration"},ee={decisionV2Enabled:!0,decisionDedupeEnabled:!0,decisionEvidenceRequiredForBlocking:!1,decisionAutoResolveGuardedEnabled:!0,questionAutoAnswerEnabled:!0,questionAutoAnswerTimeoutSec:60,questionAutoAnswerPolicy:"contextual",questionBlockingBehavior:"require_human",questionPolicyVersion:1,questionAutoAnswerDelaySeconds:60,questionAutoAnswerAction:"approve",customRunInstructions:""},Je=/^[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 ce(t){return typeof t!="string"?!1:Je.test(t.trim())}function je(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 Xe(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 Ye({status:t}){return e.jsx("span",{className:F("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 se({label:t,description:s,enabled:o,onToggle:p}){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":o,onClick:()=>p(!o),className:F("relative inline-flex h-6 w-11 flex-shrink-0 rounded-full border transition-colors",o?"border-lime/35 bg-lime/[0.20]":"border-white/[0.12] bg-white/[0.06]"),children:e.jsx("span",{"aria-hidden":"true",className:F("absolute top-0.5 h-5 w-5 rounded-full transition-all",o?"left-[20px] bg-lime":"left-0.5 bg-white/70")})})]})}function Ze({authToken:t=null,embedMode:s=!1,enabled:o=!0,initialDomain:p=null}){var L,V;const n=_e({authToken:t,embedMode:s,enabled:o}),y=(L=n.status)!=null&&L.ok?n.status.data.agents:[],h=n.runtimeSettings.agents,l=b.useMemo(()=>{const i=new Map;for(const d of n.runtimeSettings.agents)i.set(d.id,d.runtimeSettings);return i},[n.runtimeSettings.agents]),u=b.useMemo(()=>{const i=new Map;for(const d of h){const q=je({name:d.name,id:d.id});!q||i.has(q)||i.set(q,{id:d.id,model:d.model,runtimeSettings:d.runtimeSettings})}return y.length>0?y.map(d=>{var q,M,Y,te;return{id:((q=i.get(d.domain))==null?void 0:q.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:((te=i.get(d.domain))==null?void 0:te.runtimeSettings)??l.get(d.id)??ee}}):h.map(d=>({id:d.id,name:d.name,domain:je({name:d.name,id:d.id}),model:d.model,configStatus:null,runtimeSettings:d.runtimeSettings}))},[h,y,l]),A=b.useMemo(()=>{const i={};for(const d of u)i[d.id]=d.runtimeSettings;return i},[u]),[v,f]=b.useState(null),[w,m]=b.useState({}),[E,g]=b.useState(null),[_,N]=b.useState(null);b.useEffect(()=>{if(u.length===0){f(null);return}(!v||!u.some(i=>i.id===v))&&f(u[0].id),m(i=>{let d=!1;const q={...i};for(const M of u)q[M.id]||(q[M.id]=A[M.id]??ee,d=!0);return d?q:i})},[v,u,A]),b.useEffect(()=>{if(!p||u.length===0)return;const i=u.find(d=>d.domain===p);i&&i.id!==v&&f(i.id)},[v,u,p]);const j=b.useMemo(()=>u.find(i=>i.id===v)??null,[v,u]),S=i=>w[i]??A[i]??ee,k=j?S(j.id):null,D=b.useMemo(()=>u.filter(i=>!Xe(S(i.id),A[i.id])).map(i=>i.id),[u,w,A]),c=b.useMemo(()=>new Set(D),[D]),P=i=>{j&&m(d=>{const q=d[j.id]??A[j.id]??ee;return{...d,[j.id]:{...q,...i}}})},x=()=>{j&&m(i=>({...i,[j.id]:A[j.id]??ee}))},a=()=>{if(!k||u.length===0)return;const i={...k,customRunInstructions:k.customRunInstructions.trim().slice(0,4e3)};m(d=>{const q={...d};for(const M of u)q[M.id]={...i};return q}),g("Applied active agent settings to all agents."),N(null)},I=()=>{const i={};for(const d of u)i[d.id]=A[d.id]??ee;m(i),g(null),N(null)},C=async()=>{var i;if(!(D.length===0||n.isSavingRuntimeSettings)){g(null),N(null);try{for(const d of D){if(!ce(d)){const M=((i=u.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 q=S(d);await n.saveRuntimeSettingsAsync({projectId:n.runtimeSettings.projectId,agentId:d,runtimeSettings:{...q,customRunInstructions:q.customRunInstructions.trim().slice(0,4e3)}})}g(`Saved runtime settings for ${D.length} ${D.length===1?"agent":"agents"}.`),N(null)}catch(d){N(d instanceof Error?d.message:"Failed to save agent settings.")}}},R=((V=n.runtimeSettingsError)==null?void 0:V.trim())??null,B=!!R,X=!!(R&&(R.toLowerCase().includes("endpoint is not available")||R.includes("(404)"))),U=B;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(u.length===0||!j||!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 $=D.length,Z=c.has(j.id),z=j.domain?ye[j.domain]:"Agent";return e.jsxs("section",{className:"space-y-4",children:[e.jsx("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:[u.length," agents"]}),!U&&e.jsxs("span",{className:F("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"]})]})]})}),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("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:u.map(i=>{const d=i.id===j.id,q=c.has(i.id),M=ce(i.id);return e.jsxs("button",{type:"button",onClick:()=>f(i.id),className:F("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(Ye,{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?ye[i.domain]:i.model??"Agent"}),q?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("div",{className:"space-y-3",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:z}),e.jsx("h4",{className:"mt-1 text-heading font-semibold text-white",children:j.name}),ce(j.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:a,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:x,disabled:!Z,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-2",children:[e.jsx(se,{label:"Decision envelope v2",description:"Emit richer context fields for diagnosis and replay.",enabled:k.decisionV2Enabled,onToggle:i=>P({decisionV2Enabled:i})}),e.jsx(se,{label:"Decision dedupe",description:"Collapse repeated blockers into the same pending decision.",enabled:k.decisionDedupeEnabled,onToggle:i=>P({decisionDedupeEnabled:i})}),e.jsx(se,{label:"Require evidence for blocking decisions",description:"Attach evidence before a blocking decision can be emitted.",enabled:k.decisionEvidenceRequiredForBlocking,onToggle:i=>P({decisionEvidenceRequiredForBlocking:i})}),e.jsx(se,{label:"Guarded auto-resolve",description:"Attempt deterministic remediation before escalating to humans.",enabled:k.decisionAutoResolveGuardedEnabled,onToggle:i=>P({decisionAutoResolveGuardedEnabled:i})}),e.jsx(se,{label:"Auto-answer unanswered questions",description:"If no human response arrives in time, auto-resolve questions sequentially.",enabled:k.questionAutoAnswerEnabled,onToggle:i=>P({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),q=Number.isFinite(d)?Math.max(10,Math.min(3600,d)):60;P({questionAutoAnswerTimeoutSec:q,questionAutoAnswerDelaySeconds:q})},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=>P({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=>P({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=>P({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:F("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:_?e.jsx("p",{className:"text-caption text-rose-100",children:_}):E?e.jsx("p",{className:"text-caption text-lime",children:E}):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:()=>{C()},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 et({authToken:t=null,embedMode:s=!1,enabled:o=!0}={}){var y;const p=b.useMemo(()=>["usage-control-plane",{authToken:t,embedMode:s}],[t,s]),n=ie({queryKey:p,enabled:o,queryFn:async()=>{const h=await fetch("/orgx/api/usage/control-plane/summary",{headers:J({authToken:t,embedMode:s})}),l=await h.json().catch(()=>null);if(!h.ok){const u=(l&&typeof l=="object"&&"error"in l&&typeof l.error=="string"?l.error:null)??(l&&typeof l=="object"&&"message"in l&&typeof l.message=="string"?l.message:null)??`Failed to load usage summary (${h.status})`;throw new Error(u)}if(!l||typeof l!="object"||!("generatedAt"in l))throw new Error("Usage summary response is missing required fields.");return l},refetchInterval:6e4});return{summary:n.data??null,isLoading:n.isLoading,isFetching:n.isFetching,error:((y=n.error)==null?void 0:y.message)??null,refetch:n.refetch}}function G(t){return new Intl.NumberFormat("en-US").format(Math.max(0,Math.round(t)))}function de(t){return`$${(Math.max(0,t)/100).toFixed(2)}`}function ue(t){return typeof t!="number"||!Number.isFinite(t)?"—":`${Math.max(0,Math.round(t))}%`}function tt(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 we(t,s=4){return!Array.isArray(t)||t.length===0?[]:[...t].sort((o,p)=>p.tokens-o.tokens).slice(0,s)}function st(t){const s=Date.parse(t.generatedAt);if(!Number.isFinite(s))return"Updated just now";const o=Math.max(0,Math.round((Date.now()-s)/6e4));return o<1?"Updated just now":o<60?`Updated ${o}m ago`:`Updated ${Math.round(o/60)}h ago`}function nt({authToken:t=null,embedMode:s=!1,enabled:o=!0}){const p=et({authToken:t,embedMode:s,enabled:o}),n=p.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 p.refetch(),disabled:p.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:p.isFetching?"Refreshing…":"Refresh"})]}),p.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:p.error}):null,!n&&p.isLoading?e.jsx("div",{className:"mt-3 grid gap-2 sm:grid-cols-2 lg:grid-cols-4",children:Array.from({length:4}).map((y,h)=>e.jsx("div",{className:"h-[92px] animate-pulse rounded-xl border border-white/[0.08] bg-white/[0.03]"},`usage-loading-${h}`))}):null,n?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsx(Q.span,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},className:F("rounded-full border px-2.5 py-1 text-caption font-semibold",tt(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:st(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/20 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:[G(n.actual.agentRuns),e.jsxs("span",{className:"ml-1 text-caption text-secondary",children:["/ ",n.plan.agentRunsLimit>0?G(n.plan.agentRunsLimit):"∞"]})]}),e.jsxs("p",{className:"mt-1 text-caption text-muted",children:["Forecast ",G(n.predicted.agentRuns)]})]}),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:"Agent minutes"}),e.jsxs("p",{className:"mt-1 text-heading font-semibold text-white",children:[G(n.actual.agentMinutes),e.jsxs("span",{className:"ml-1 text-caption text-secondary",children:["/ ",n.plan.agentMinutesLimit>0?G(n.plan.agentMinutesLimit):"∞"]})]}),e.jsxs("p",{className:"mt-1 text-caption text-muted",children:["Forecast ",G(n.predicted.agentMinutes)]})]}),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:"Tokens"}),e.jsx("p",{className:"mt-1 text-heading font-semibold text-white",children:G(n.actual.tokens)}),e.jsxs("p",{className:"mt-1 text-caption text-muted",children:["Forecast ",G(n.predicted.tokens)]})]}),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:"Spend"}),e.jsxs("p",{className:"mt-1 text-heading font-semibold text-white",children:[de(n.actual.costCents),e.jsxs("span",{className:"ml-1 text-caption text-secondary",children:["/ ",n.plan.includedBudgetCents>0?de(n.plan.includedBudgetCents):"—"]})]}),e.jsxs("p",{className:"mt-1 text-caption text-muted",children:["Forecast ",de(n.predicted.costCents)]})]})]}),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-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:ue(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:ue(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:ue(n.utilization.budgetPct)})]})]}),we(n.breakdown.sourceClient,4).length>0?e.jsxs("div",{className:"mt-3 rounded-xl border border-white/[0.08] bg-black/20 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:we(n.breakdown.sourceClient,4).map((y,h)=>{const l=n.actual.tokens>0?Math.max(0,Math.min(100,Math.round(y.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:y.label}),e.jsxs("span",{className:"text-caption text-primary",children:[G(y.tokens)," tokens · ",G(y.runs)," runs"]})]}),e.jsx("div",{className:"h-1.5 rounded-full bg-white/[0.08]",children:e.jsx(Q.div,{initial:{width:0},animate:{width:`${Math.max(6,l)}%`},transition:{duration:.36,delay:h*.04},className:"h-1.5 rounded-full bg-lime/80 transition-all"})})]},`usage-source-${y.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((y,h)=>e.jsxs("li",{className:"text-caption text-amber-100/90",children:["• ",y]},`usage-warning-${h}`))})]}):null]}):null]})}function it({connectionPhase:t,workspaceName:s}){const{displayName:o,avatarSeed:p,updateName:n,regenerateAvatar:y}=Pe(),[h,l]=b.useState(!1),[u,A]=b.useState(""),v=b.useRef(null),f=b.useCallback(()=>{A(o),l(!0),requestAnimationFrame(()=>{var N;return(N=v.current)==null?void 0:N.focus()})},[o]),w=b.useCallback(()=>{n(u),l(!1)},[u,n]),m=b.useCallback(()=>{l(!1)},[]),E=b.useCallback(N=>{N.key==="Enter"?w():N.key==="Escape"&&m()},[w,m]),g=t==="connected",_=g?`Connected${s?` to ${s}`:""}`:t==="connecting"?"Connecting...":t==="error"?"Connection error":"Not connected";return e.jsx("div",{className:"rounded-2xl border border-white/[0.07] bg-white/[0.02] p-5",children:e.jsxs("div",{className:"flex items-center gap-5",children:[e.jsx(ke,{mode:"wait",children:e.jsx(Q.div,{initial:{opacity:0,scale:.9},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.9},transition:{duration:.3,ease:ve.easingEntrance},children:e.jsx(Fe,{seed:p,size:80})},p)}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Your identity"}),h?e.jsxs("div",{className:"mt-1.5 flex items-center gap-2",children:[e.jsx("input",{ref:v,type:"text",value:u,onChange:N=>A(N.target.value),onKeyDown:E,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:w,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:m,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:o||"Anonymous"}),e.jsx("button",{type:"button",onClick:f,className:"rounded-md px-2 py-0.5 text-caption text-secondary transition hover:bg-white/[0.06] hover:text-white",children:o?"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:F("relative inline-flex h-2 w-2 rounded-full",g?"bg-lime":t==="error"?"bg-red-400":"bg-white/30")})}),e.jsx("span",{className:"text-caption text-secondary",children:_})]}),e.jsx("button",{type:"button",onClick:y,className:"mt-3 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 avatar"})]})]})})}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 rt({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 me({label:t,description:s,enabled:o,onToggle:p}){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(Q.button,{type:"button",role:"switch","aria-checked":o,onClick:()=>p(!o),whileTap:{scale:.965},className:F("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",o?"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:F("absolute top-[1px] h-[18px] w-[18px] rounded-full shadow-sm transition-all",o?"left-[17px] bg-lime shadow-[0_0_8px_rgba(191,255,0,0.4)]":"left-[1px] bg-secondary")})})]})}function ut({open:t,onClose:s,activeTab:o,onChangeTab:p,demoMode:n,onToggleDemoMode:y,devMode:h=!1,onToggleDevMode:l,showSyntheticEntities:u,onToggleShowSyntheticEntities:A,workspaceOptions:v,selectedWorkspaceId:f,onSelectWorkspace:w,onboarding:m,authToken:E=null,embedMode:g=!1,agentBehaviorInitialDomain:_=null}){const N=re.find(S=>S.id===o)??re[0],j=()=>o==="orgx"?e.jsxs(Q.div,{...oe,className:"grid gap-10",children:[e.jsx(it,{connectionPhase:m.state.status==="connected"?"connected":m.state.status==="error"?"error":m.state.status==="starting"||m.state.status==="awaiting_browser_auth"||m.state.status==="pairing"?"connecting":"idle",workspaceName:m.state.workspaceName}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-heading font-semibold text-white",children:"Developer tools"}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:"Toggle debug visibility and synthetic test entities used during rehearsal."}),e.jsxs("div",{className:"mt-4 grid gap-1 border-t border-white/[0.04] pt-2",children:[e.jsx(me,{label:"Developer mode",description:"Show technical details, config paths, and raw data in session inspectors.",enabled:h,onToggle:S=>l==null?void 0:l(S)}),e.jsx("div",{className:F("border-t border-white/[0.04]",h?"":"pointer-events-none opacity-40"),children:e.jsx(me,{label:"Demo mode",description:"Load local demo data for walkthroughs.",enabled:n,onToggle:y})}),e.jsx("div",{className:F("border-t border-white/[0.04]",h?"":"pointer-events-none opacity-40"),children:e.jsx(me,{label:"Show synthetic entities",description:"Include QA/test initiative IDs in the agent column.",enabled:u,onToggle:A})})]})]}),e.jsx($e,{state:m.state,isStarting:m.isStarting,isSubmittingManual:m.isSubmittingManual,workspaceOptions:v,selectedWorkspaceId:f,onSelectWorkspace:w,onRefresh:m.refreshStatus,onStartPairing:m.startPairing,onSubmitManualKey:m.submitManualKey,onBackToPairing:m.backToPairing,onUseManualKey:m.setManualMode,onDisconnect:m.disconnect}),e.jsx(Ve,{authToken:E,embedMode:g,enabled:t&&!n,devMode:h}),e.jsx(nt,{authToken:E,embedMode:g,enabled:t&&!n})]},"orgx"):o==="agents"?e.jsx(Q.div,{...oe,children:e.jsx(Ze,{authToken:E,embedMode:g,enabled:t&&!n,initialDomain:_})},"agents"):e.jsx(Q.div,{...oe,children:e.jsx(We,{authToken:E,embedMode:g,enabled:t&&!n})},"providers");return e.jsx(qe,{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(S=>{const k=o===S.id;return e.jsxs(Q.button,{type:"button",role:"tab","aria-selected":k,onClick:()=>p(S.id),whileHover:{x:1.5},whileTap:{scale:.985},transition:{duration:.16},className:F("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(Q.span,{layoutId:"settings-tab-surface",className:"absolute inset-0 rounded-xl border border-lime/24 bg-lime/[0.10]",transition:{duration:.24,ease:ve.easingStandard},"aria-hidden":!0}),e.jsx("span",{className:F("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(rt,{id:S.id})}),e.jsxs("span",{className:"relative z-[1] min-w-0",children:[e.jsx("span",{className:"block truncate text-caption font-semibold",children:S.label}),e.jsx("span",{className:"mt-0.5 block text-caption leading-relaxed text-secondary/85",children:S.subtitle})]})]},S.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:N.label}),e.jsx("p",{className:"mt-1 text-caption leading-relaxed text-secondary",children:N.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(S=>{const k=o===S.id;return e.jsx("button",{type:"button",role:"tab","aria-selected":k,onClick:()=>p(S.id),className:F("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:S.label},S.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:N.label}),e.jsx("p",{className:"mt-1 text-caption leading-relaxed text-secondary",children:N.subtitle})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-4 py-5 sm:px-6",children:e.jsx(ke,{mode:"wait",children:j()})})]})]})]}),e.jsx("div",{className:"mt-3 border-t border-subtle px-1 pt-2",children:e.jsx(Re,{compact:!0})})]})]})})}export{ut as SettingsModal};
@@ -1 +0,0 @@
1
- import{j as e,r as x}from"./cNrhgGc1.js";import{E as W,G as ce,$ as de,r as ue,A as xe,R as me,x as w,a0 as pe,a1 as he,Y as ke,K as D,_ as be,d as l}from"./Cn07669c.js";import{E as ge}from"./DBG89Wsz.js";import{A as fe,m as h}from"./CxQ08qFN.js";import"./C-KIc3Wc.js";import"./BJgZIVUQ.js";function je({breadcrumbs:s,typeBadge:n,onClose:d,footer:N,children:I}){return e.jsxs("div",{className:"flex h-full w-full min-h-0 flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-subtle px-5 py-3 sm:px-6",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0 text-body text-secondary",children:[s.map((b,g)=>e.jsxs("span",{className:"flex items-center gap-1.5 min-w-0",children:[g>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"})}),b.onClick?e.jsx("button",{type:"button",onClick:b.onClick,className:`truncate transition-colors hover:text-primary ${g===s.length-1?"text-primary font-medium":""}`,children:b.label}):e.jsx("span",{className:`truncate ${g===s.length-1?"text-primary font-medium":""}`,children:b.label})]},g)),n&&e.jsxs("span",{className:"ml-1 inline-flex items-center gap-1 rounded-full border border-white/[0.1] bg-white/[0.04] px-2 py-0.5 text-micro uppercase tracking-[0.06em] text-secondary",children:[n.icon&&e.jsx(W,{type:n.icon,size:11,className:"opacity-90"}),n.label]})]}),e.jsx("button",{type:"button",onClick:d,"aria-label":"Close detail",className:"inline-flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-full border border-strong bg-white/[0.03] text-primary transition-colors hover:bg-white/[0.08] hover:text-white",children:e.jsxs("svg",{width:"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.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto",children:I}),N&&e.jsx("div",{className:"flex-shrink-0 border-t border-subtle px-5 py-3 sm:px-6",children:N})]})}function ve(s){switch(s){case"running":return{background:`linear-gradient(to right, ${l.lime}, ${l.teal})`};case"blocked":return{background:`linear-gradient(to right, ${l.red}, ${l.amber})`};case"idle":return{background:`linear-gradient(to right, ${l.iris}99, transparent)`};default:return{background:`linear-gradient(to right, ${l.lime}B3, ${l.teal}66)`}}}function Y(s){switch(s){case"running":return l.lime;case"blocked":return l.red;case"idle":return l.iris;case"queued":return l.teal;default:return l.amber}}function Q(s,n){return n?"Scope Under Review":s==="completed"?"Completed Scope":s==="running"?"Current Work":s==="blocked"?"Blocked Work":"Next Work"}function B(s){return s===0?l.red:s===1?l.amber:s===2?l.iris:"rgba(255,255,255,0.5)"}function L(s){return s===0?"P0":s===1?"P1":s===2?"P2":s===3?"P3":""}function ye(s){switch(s){case"high":return{filled:5,color:l.lime};case"medium":return{filled:3,color:l.amber};case"low":return{filled:1,color:l.red};default:return{filled:0,color:l.iris}}}async function we(s){const n={};if(s.runId&&(n.runId=s.runId),s.sliceRunId&&(n.sliceRunId=s.sliceRunId),s.sessionId&&(n.sessionId=s.sessionId),Object.keys(n).length===0)throw new Error("No run identifier available for terminal open.");const d=await fetch("/orgx/api/live/terminal/open",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!d.ok){const N=await d.json().catch(()=>({}));throw new Error(N.error??`Terminal open failed (${d.status})`)}}const Ne={hidden:{opacity:0,y:-4},visible:s=>({opacity:1,y:0,transition:{duration:.28,delay:s*.04,ease:[.16,1,.3,1]}}),exit:{opacity:0,transition:{duration:.18}}},j={hidden:{opacity:0,y:8},visible:s=>({opacity:1,y:0,transition:{duration:.22,delay:s*.04,ease:me.easingStandard}}),exit:{opacity:0,transition:{duration:.18}}};function ee(s){var N,I,b,g,C,T,F,S;if(s.source==="queue"){const{item:a,linkedSliceRun:o}=s;return{initiativeId:a.initiativeId,initiativeTitle:w(a.initiativeTitle),initiativeStatus:a.initiativeStatus,workstreamId:a.workstreamId,workstreamTitle:w(a.workstreamTitle),workstreamStatus:a.workstreamStatus,nextTaskTitle:a.nextTaskTitle?w(a.nextTaskTitle):null,nextTaskPriority:a.nextTaskPriority,nextTaskDueAt:a.nextTaskDueAt,agentId:a.runnerAgentId,agentName:a.runnerAgentName,agentSource:a.runnerSource,queueState:a.queueState,blockReason:a.blockReason?w(a.blockReason):null,sliceScope:a.sliceScope??null,sliceTaskCount:typeof a.sliceTaskCount=="number"&&Number.isFinite(a.sliceTaskCount)?Math.max(0,Math.floor(a.sliceTaskCount)):((N=a.sliceTaskIds)==null?void 0:N.length)??null,autoContinue:a.autoContinue,sliceRun:o,sessionId:null,runId:(o==null?void 0:o.runId)??null}}if(s.source==="in_progress"){const{row:a,sliceRun:o}=s;return{initiativeId:a.initiativeId,initiativeTitle:a.initiativeTitle?w(a.initiativeTitle):null,initiativeStatus:null,workstreamId:a.workstreamId,workstreamTitle:a.workstreamTitle?w(a.workstreamTitle):a.title,workstreamStatus:a.status,nextTaskTitle:null,nextTaskPriority:null,nextTaskDueAt:null,agentId:((I=a.session)==null?void 0:I.agentId)??null,agentName:((b=a.session)==null?void 0:b.agentName)??"OrgX",agentSource:null,queueState:a.status==="running"?"running":"queued",blockReason:null,sliceScope:(o==null?void 0:o.scope)??null,sliceTaskCount:typeof((g=o==null?void 0:o.scopeProgress)==null?void 0:g.totalTasks)=="number"?Math.max(0,Math.floor(o.scopeProgress.totalTasks-o.scopeProgress.completedTasks)):((C=o==null?void 0:o.taskIds)==null?void 0:C.length)??null,autoContinue:null,sliceRun:o,sessionId:((T=a.session)==null?void 0:T.id)??null,runId:a.runId}}const{sliceRun:n}=s,d=n.sourceClient?n.sourceClient.charAt(0).toUpperCase()+n.sourceClient.slice(1):"OrgX";return{initiativeId:n.initiativeId,initiativeTitle:null,initiativeStatus:null,workstreamId:n.workstreamId,workstreamTitle:n.workstreamTitle?w(n.workstreamTitle):"Work slice",workstreamStatus:n.status,nextTaskTitle:null,nextTaskPriority:null,nextTaskDueAt:null,agentId:null,agentName:d,agentSource:n.sourceClient,queueState:n.status==="needs_review"?"completed":"blocked",blockReason:n.status==="failed"&&n.statusExplainer||null,sliceScope:n.scope??null,sliceTaskCount:typeof((F=n.scopeProgress)==null?void 0:F.totalTasks)=="number"?Math.max(0,Math.floor(n.scopeProgress.totalTasks-n.scopeProgress.completedTasks)):((S=n.taskIds)==null?void 0:S.length)??null,autoContinue:null,sliceRun:n,sessionId:null,runId:n.runId}}function y(){return e.jsx("div",{className:"h-px bg-gradient-to-r from-transparent via-white/[0.06] to-transparent"})}function De({target:s,onClose:n,onPlayWorkstream:d,onStartAutoContinue:N,onMoveWorkstream:I,onRemoveFromQueue:b,onOpenSession:g,onFocusRunId:C,onOpenInitiative:T,onReviewActivity:F,onOpenDecisions:S,onAcceptSlice:a,onRejectSlice:o}){var Z,G;const E=s!==null,[te,M]=x.useState(!1),[Ie,z]=x.useState(null),[u,A]=x.useState(null),[$,P]=x.useState(""),[q,v]=x.useState(null),J=x.useRef(null),O=x.useCallback(r=>{if(s&&(r.metaKey||r.ctrlKey)&&r.key==="Enter"){r.preventDefault();const c=ee(s);c.initiativeId&&c.workstreamId&&(d==null||d(c.initiativeId,c.workstreamId,c.agentId??void 0))}},[s,d]);if(x.useEffect(()=>{if(E)return document.addEventListener("keydown",O),()=>document.removeEventListener("keydown",O)},[E,O]),x.useEffect(()=>{E||(z(null),M(!1),A(null),P(""),v(null))},[E]),x.useEffect(()=>{u&&requestAnimationFrame(()=>{var r;(r=J.current)==null||r.focus()})},[u]),!s)return null;const i=ee(s),t=i.sliceRun,m=ce({sessionStatus:i.queueState,sessionPhase:i.workstreamStatus,sliceStatus:(t==null?void 0:t.status)??i.workstreamStatus,activityStatus:(t==null?void 0:t.runtimeState)??i.workstreamStatus??i.queueState,stopReason:i.queueState==="blocked"?"blocked":null,decisionRequired:((t==null?void 0:t.blockingDecisionCount)??0)>0,blockingDecisionCount:(t==null?void 0:t.blockingDecisionCount)??0,nonBlockingDecisionCount:Math.max(0,((t==null?void 0:t.decisionCount)??0)-((t==null?void 0:t.blockingDecisionCount)??0)),blockerCount:i.blockReason?1:0,blockerReason:i.blockReason}),ie=m.status==="completed"?"text-lime border-lime/30 bg-lime/[0.12]":m.status==="failed"?"text-red-200 border-red-400/30 bg-red-500/[0.12]":m.status==="needs_attention"?"text-amber-200 border-amber-400/30 bg-amber-500/[0.12]":m.status==="in_progress"?"text-teal-200 border-teal-400/30 bg-teal-500/[0.12]":"text-secondary border-white/[0.14] bg-white/[0.04]",se=m.tone==="critical"?"border-red-400/24 bg-red-500/[0.08]":m.tone==="warning"?"border-amber-400/24 bg-amber-500/[0.08]":m.tone==="positive"?"border-lime/24 bg-lime/[0.08]":"border-subtle bg-white/[0.02]",ne=[...i.initiativeTitle?[{label:i.initiativeTitle,onClick:i.initiativeId?()=>T==null?void 0:T(i.initiativeId):void 0}]:[],{label:i.workstreamTitle}],V=m.status==="in_progress",ae=!!(i.initiativeId&&i.workstreamId&&!V),X=m.nextAction??(s.source==="needs_input"&&t?t.primaryAction==="resolve_decision"?"Resolve decision":t.primaryAction==="open_artifact"?"Open result":"Review activity":null),re=x.useCallback(async r=>{try{z(null),M(!0),await we(r)}catch(c){z(c instanceof Error?c.message:"Unable to open terminal")}finally{M(!1)}},[]),H=x.useMemo(()=>i.sessionId?{sessionId:i.sessionId,runId:i.runId,sliceRunId:(t==null?void 0:t.sliceRunId)??null}:t!=null&&t.runId||t!=null&&t.sliceRunId?{runId:t.runId??null,sliceRunId:t.sliceRunId??null}:i.runId?{runId:i.runId,sliceRunId:(t==null?void 0:t.sliceRunId)??null}:null,[i.sessionId,i.runId,t]),oe=H!==null,K=x.useMemo(()=>de({initiativeId:i.initiativeId,initiativeTitle:i.initiativeTitle,workstreamId:i.workstreamId,workstreamTitle:i.workstreamTitle,taskIds:t==null?void 0:t.taskIds,milestoneIds:t==null?void 0:t.milestoneIds,scopeProgress:(t==null?void 0:t.scopeProgress)??null,status:(t==null?void 0:t.status)??i.queueState,agentName:i.agentName,agentId:i.agentId}),[i.initiativeId,i.initiativeTitle,i.workstreamId,i.workstreamTitle,t,i.queueState,i.agentName,i.agentId]),_=s.source==="needs_input"&&(t==null?void 0:t.status)==="needs_review",U=x.useCallback(async()=>{if(!t||!u)return;const r=$.trim(),c=t.runId??t.sliceRunId;if(u==="accept")try{v("Accepting…");const p=r?`Accepted: ${r}`:"Accepted from dashboard",k=await fetch(`/orgx/api/runs/${encodeURIComponent(c)}/actions/complete`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({reason:p})});if(!k.ok){const R=await k.json().catch(()=>null);v(`Error: ${(R==null?void 0:R.error)??(R==null?void 0:R.message)??k.status}`);return}v("Accepted!");try{a==null||a(t,r||void 0)}catch{}setTimeout(()=>n(),600)}catch(p){v(`Failed: ${p instanceof Error?p.message:"network error"}`)}else if(u==="reject"&&r)try{v("Sending feedback…");const p=await fetch(`/orgx/api/entities/run/${encodeURIComponent(c)}/comments`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({body:r,commentType:"review_feedback",severity:"warn",tags:["changes_requested"]})});if(!p.ok){const k=await p.json().catch(()=>null);v(`Error: ${(k==null?void 0:k.error)??(k==null?void 0:k.message)??p.status}`);return}v("Feedback sent!");try{o==null||o(t,r)}catch{}A(null),P("")}catch(p){v(`Failed: ${p instanceof Error?p.message:"network error"}`)}},[t,u,$,a,o,n]),le=e.jsxs("div",{className:"space-y-2",children:[q&&e.jsx("div",{className:`flex items-center gap-1.5 rounded-lg px-3 py-1.5 text-[11px] font-medium ${q.startsWith("Error")||q.startsWith("Failed")?"bg-[#FF6B88]/10 text-[#FF6B88]":q.includes("…")?"bg-white/[0.04] text-white/60 animate-pulse":"bg-[#BFFF00]/10 text-[#BFFF00]"}`,children:q}),e.jsx(fe,{children:u&&e.jsx(h.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.15},className:"overflow-hidden",children:e.jsxs("div",{className:"pb-2",children:[e.jsx("textarea",{ref:J,value:$,onChange:r=>P(r.target.value),onKeyDown:r=>{(r.metaKey||r.ctrlKey)&&r.key==="Enter"&&(r.preventDefault(),U()),r.key==="Escape"&&(r.preventDefault(),A(null),P(""))},placeholder:u==="accept"?"Optional note...":"What needs to change?",className:"w-full resize-none rounded-lg border border-white/[0.08] bg-white/[0.03] px-3 py-2 text-[13px] text-white/80 outline-none placeholder:text-white/25 focus:border-white/15 transition-colors",rows:2}),e.jsxs("div",{className:"mt-1.5 flex items-center justify-between",children:[e.jsx("button",{type:"button",onClick:()=>{A(null),P("")},className:"text-[11px] text-white/30 transition-colors hover:text-white/50",children:"Cancel"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[10px] text-white/20",children:u==="reject"&&!$.trim()?"Note required":"⌘Enter to confirm"}),e.jsx("button",{type:"button",onClick:U,disabled:u==="reject"&&!$.trim(),className:`inline-flex h-7 items-center gap-1 rounded-md px-3 text-[11px] font-semibold transition-colors disabled:opacity-30 ${u==="accept"?"bg-[#BFFF00]/12 text-[#BFFF00] hover:bg-[#BFFF00]/20":"bg-[#FF6B88]/12 text-[#FF6B88] hover:bg-[#FF6B88]/20"}`,children:u==="accept"?"Confirm accept":"Request changes"})]})]})]})})}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[s.source==="queue"&&i.initiativeId&&i.workstreamId&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>{b==null||b(i.initiativeId,i.workstreamId),n()},className:"rounded-md px-2.5 py-1.5 text-[12px] font-medium text-[#FF6B88]/70 transition-colors hover:bg-[#FF6B88]/[0.08] hover:text-[#FF6B88]",children:"Remove"}),e.jsx("button",{type:"button",onClick:()=>I==null?void 0:I(i.initiativeId,i.workstreamId,"top"),className:"rounded-md px-2.5 py-1.5 text-[12px] font-medium text-white/35 transition-colors hover:bg-white/[0.04] hover:text-white/60",children:"Move top"})]}),s.source==="in_progress"&&i.sessionId&&e.jsx("button",{type:"button",onClick:()=>{g==null||g(i.sessionId),n()},className:"rounded-md px-2.5 py-1.5 text-[12px] font-medium text-white/35 transition-colors hover:bg-white/[0.04] hover:text-white/60",children:"Open session"}),s.source==="needs_input"&&t&&t.primaryAction==="resolve_decision"&&e.jsx("button",{type:"button",onClick:()=>{S==null||S(),n()},className:"rounded-md px-2.5 py-1.5 text-[12px] font-medium text-[#0AD4C4]/70 transition-colors hover:bg-[#0AD4C4]/[0.08] hover:text-[#0AD4C4]",children:"Resolve decision"}),s.source==="needs_input"&&t&&e.jsx("button",{type:"button",onClick:()=>{F==null||F(t),n()},className:"rounded-md px-2.5 py-1.5 text-[12px] font-medium text-white/35 transition-colors hover:bg-white/[0.04] hover:text-white/60",children:"Review"}),i.runId&&e.jsx("button",{type:"button",onClick:()=>{C==null||C(i.runId),n()},className:"rounded-md px-2.5 py-1.5 text-[12px] font-medium text-white/35 transition-colors hover:bg-white/[0.04] hover:text-white/60",children:"Timeline"})]}),e.jsx("div",{className:"flex-1"}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[_&&o&&e.jsx("button",{type:"button",onClick:()=>A(u==="reject"?null:"reject"),className:`rounded-md px-2.5 py-1.5 text-[12px] font-medium transition-colors ${u==="reject"?"bg-[#FF6B88]/12 text-[#FF6B88]":"text-white/35 hover:bg-white/[0.04] hover:text-white/60"}`,children:"Request changes"}),_&&a&&e.jsxs("button",{type:"button",onClick:()=>{u==="accept"?U():A("accept")},className:"inline-flex h-8 items-center gap-1.5 rounded-lg bg-[#BFFF00]/12 px-4 text-[12px] font-semibold text-[#BFFF00] transition-colors hover:bg-[#BFFF00]/20",children:[e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}),"Accept"]}),ae&&e.jsxs("button",{type:"button","data-modal-autofocus":"true",onClick:()=>{d==null||d(i.initiativeId,i.workstreamId,i.agentId??void 0),n()},className:"inline-flex h-8 items-center gap-1.5 rounded-lg border border-[#BFFF00]/25 bg-[#BFFF00]/10 px-4 text-[12px] font-semibold text-[#E1FFB2] transition-colors hover:bg-[#BFFF00]/20",title:"Start (⌘ Enter)",children:[e.jsx("svg",{viewBox:"0 0 20 20",fill:"none","aria-hidden":!0,className:"h-3.5 w-3.5",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"})}),m.status==="completed"?"Restart":m.status==="needs_attention"?"Retry":"Start"]}),oe&&e.jsx("button",{type:"button",onClick:()=>void re(H),disabled:te,className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-white/30 transition-colors hover:bg-white/[0.04] hover:text-white/50 disabled:opacity-40",title:"Open in terminal",children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("polyline",{points:"4 17 10 11 4 5"}),e.jsx("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]})})]})]})]});let f=0;return e.jsx(ue,{open:E,onClose:n,maxWidth:"max-w-xl",children:e.jsxs("div",{className:"relative flex h-full min-h-0 flex-col",children:[e.jsx("div",{className:"h-[2px] flex-shrink-0 rounded-t-2xl",style:ve(i.queueState),"aria-hidden":!0}),e.jsx(je,{breadcrumbs:ne,onClose:n,footer:le,children:e.jsxs("div",{className:"px-6 py-5 space-y-5",children:[e.jsxs(h.div,{variants:Ne,initial:"hidden",animate:"visible",exit:"exit",custom:f++,className:"flex items-start gap-3",children:[e.jsx(xe,{name:i.agentName??"OrgX",hint:i.agentSource??i.agentId,size:"md"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-[20px] font-semibold leading-snug text-white",children:i.workstreamTitle}),i.initiativeTitle&&e.jsx("p",{className:"mt-0.5 text-[10px] uppercase tracking-[0.1em] text-muted",children:i.initiativeTitle}),e.jsx("div",{className:"mt-1.5 flex flex-wrap items-center gap-1.5",children:e.jsxs("span",{className:`inline-flex items-center rounded-full border px-2 py-[1px] text-micro font-semibold uppercase tracking-[0.06em] ${ie}`,children:[e.jsxs("span",{className:"relative mr-1.5 inline-block h-1.5 w-1.5",children:[e.jsx("span",{className:"absolute inset-0 rounded-full",style:{backgroundColor:Y(i.queueState)}}),V&&e.jsx(h.span,{className:"absolute inset-0 rounded-full",style:{backgroundColor:Y(i.queueState)},animate:{opacity:[1,.3,1],scale:[1,1.6,1]},transition:{duration:2,repeat:1/0,ease:"easeInOut"}})]}),m.label]})})]})]}),e.jsx(y,{}),s.source==="needs_input"&&t?e.jsxs(e.Fragment,{children:[e.jsxs(h.div,{variants:j,initial:"hidden",animate:"visible",exit:"exit",custom:f++,className:`rounded-xl border px-4 py-3 ${se}`,children:[e.jsx("p",{className:"section-kicker",children:"What to do now"}),e.jsx("p",{className:"mt-1 text-body text-primary",children:m.sentence}),t.artifactCount>0?e.jsxs("p",{className:"mt-1 text-caption text-secondary",children:[t.artifactCount," artifact",t.artifactCount===1?"":"s"," ready for review."]}):null,t.blockingDecisionCount>0?e.jsxs("p",{className:"mt-1 text-caption text-secondary",children:[t.blockingDecisionCount," blocking decision",t.blockingDecisionCount===1?"":"s"," waiting."]}):null,X?e.jsxs("p",{className:"mt-1 text-caption text-secondary",children:["Recommended action: ",X]}):null]}),t.statusExplainer&&t.statusExplainer!==i.blockReason&&e.jsxs(h.div,{variants:j,initial:"hidden",animate:"visible",exit:"exit",custom:f++,children:[e.jsx("p",{className:"section-kicker",children:"What happened"}),e.jsx("p",{className:"mt-1 text-body text-secondary leading-relaxed",children:w(t.statusExplainer)})]}),t.lastEventSummary&&e.jsxs(h.div,{variants:j,initial:"hidden",animate:"visible",exit:"exit",custom:f++,children:[e.jsx("p",{className:"section-kicker",children:"Last activity"}),e.jsx("p",{className:"mt-1 text-caption text-white/50 leading-relaxed",children:w(t.lastEventSummary)})]}),e.jsx(y,{})]}):null,(i.blockReason||i.autoContinue||i.agentSource&&i.agentSource!=="assigned")&&e.jsxs(h.div,{variants:j,initial:"hidden",animate:"visible",exit:"exit",custom:f++,className:"space-y-2",children:[i.blockReason&&e.jsxs("div",{className:"rounded-lg border border-red-400/24 bg-red-500/[0.08] px-2.5 py-1.5 text-caption text-red-100/85",children:[e.jsx("p",{className:"mb-0.5 text-micro font-semibold uppercase tracking-[0.08em] text-red-200/70",children:"Why blocked"}),i.blockReason]}),i.autoContinue&&e.jsxs("div",{className:"flex items-center gap-2 text-caption text-secondary",children:[e.jsx("svg",{viewBox:"0 0 20 20",fill:"none","aria-hidden":!0,className:"h-3.5 w-3.5 flex-shrink-0 text-[#0AD4C4]",children:e.jsx("path",{d:"M6.1 13.25C4.25 13.25 2.8 11.8 2.8 10s1.45-3.25 3.3-3.25c3.15 0 4.35 6.5 8.05 6.5 1.85 0 3.3-1.45 3.3-3.25s-1.45-3.25-3.3-3.25c-3.7 0-4.9 6.5-8.05 6.5Z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),e.jsxs("span",{children:["Auto-continue: ",e.jsx("span",{className:"text-primary capitalize",children:i.autoContinue.status}),i.autoContinue.laneState&&e.jsxs("span",{className:"text-muted",children:[" · ",pe(i.autoContinue.laneState)]})]})]}),((Z=i.autoContinue)==null?void 0:Z.laneBlockedReason)&&e.jsx("p",{className:"text-micro text-red-100/75",children:i.autoContinue.laneBlockedReason}),((G=i.autoContinue)==null?void 0:G.stopReason)&&e.jsx("p",{className:"text-micro text-amber-100/75",children:he(i.autoContinue.stopReason)})]}),K.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(y,{}),e.jsxs(h.div,{variants:j,initial:"hidden",animate:"visible",exit:"exit",custom:f++,className:"space-y-2",children:[e.jsx("p",{className:"section-kicker",children:Q(i.queueState,_)}),e.jsx(ke,{nodes:K,activeId:i.workstreamId}),e.jsxs("div",{className:"flex items-center gap-2",children:[i.nextTaskPriority!==null&&L(i.nextTaskPriority)&&e.jsx("span",{className:"inline-flex rounded-full border px-2 py-[1px] text-micro font-semibold",style:{color:B(i.nextTaskPriority),borderColor:`${B(i.nextTaskPriority)}33`,backgroundColor:`${B(i.nextTaskPriority)}14`},children:L(i.nextTaskPriority)}),i.nextTaskDueAt&&e.jsxs("span",{className:"text-micro text-secondary",children:["Due ",D(i.nextTaskDueAt)]})]})]})]}),K.length===0&&(i.nextTaskTitle||i.sliceTaskCount!==null||i.sliceScope)&&e.jsxs(e.Fragment,{children:[e.jsx(y,{}),e.jsxs(h.div,{variants:j,initial:"hidden",animate:"visible",exit:"exit",custom:f++,className:"space-y-2",children:[e.jsx("p",{className:"section-kicker",children:Q(i.queueState,_)}),i.nextTaskTitle&&e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(W,{type:"task",size:14,className:"mt-[2px] flex-shrink-0 opacity-80"}),e.jsx("p",{className:"text-body font-semibold leading-snug text-white",children:i.nextTaskTitle})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[i.sliceScope?e.jsxs("span",{className:"inline-flex rounded-full border border-strong bg-white/[0.03] px-2 py-[1px] text-micro uppercase tracking-[0.08em] text-secondary",children:[i.sliceScope," slice"]}):null,typeof i.sliceTaskCount=="number"?e.jsxs("span",{className:"inline-flex rounded-full border border-strong bg-white/[0.03] px-2 py-[1px] text-micro text-secondary",children:[i.sliceTaskCount," ",i.sliceTaskCount===1?"task":"tasks"," in scope"]}):null,i.nextTaskPriority!==null&&L(i.nextTaskPriority)&&e.jsx("span",{className:"inline-flex rounded-full border px-2 py-[1px] text-micro font-semibold",style:{color:B(i.nextTaskPriority),borderColor:`${B(i.nextTaskPriority)}33`,backgroundColor:`${B(i.nextTaskPriority)}14`},children:L(i.nextTaskPriority)}),i.nextTaskDueAt&&e.jsxs("span",{className:"text-micro text-secondary",children:["Due ",D(i.nextTaskDueAt)]})]})]})]}),t&&(t.startedAt||t.updatedAt||t.completedAt||t.failedAt)&&e.jsxs(e.Fragment,{children:[e.jsx(y,{}),e.jsxs(h.div,{variants:j,initial:"hidden",animate:"visible",exit:"exit",custom:f++,className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"section-kicker",children:"Timeline"}),t.scope&&t.scope!=="task"&&e.jsx(be,{tone:t.scope==="milestone"?"cyan":"lime",children:t.scope}),t.confidence&&e.jsx("div",{className:"flex items-center gap-1 ml-auto",title:`Confidence: ${t.confidence}`,children:Array.from({length:5},(r,c)=>{const{filled:p,color:k}=ye(t.confidence);return e.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full",style:{backgroundColor:c<p?k:"rgba(255,255,255,0.1)"}},c)})})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[t.startedAt&&e.jsxs("div",{children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Started"}),e.jsx("p",{className:"mt-0.5 text-caption text-primary",children:D(t.startedAt)})]}),t.completedAt?e.jsxs("div",{children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Completed"}),e.jsx("p",{className:"mt-0.5 text-caption text-primary",children:D(t.completedAt)})]}):t.failedAt?e.jsxs("div",{children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Failed"}),e.jsx("p",{className:"mt-0.5 text-caption text-red-100",children:D(t.failedAt)})]}):t.updatedAt&&t.updatedAt!==t.startedAt?e.jsxs("div",{children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Updated"}),e.jsx("p",{className:"mt-0.5 text-caption text-primary",children:D(t.updatedAt)})]}):null]})]})]}),t&&t.artifactCount>0&&t.artifacts.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(y,{}),e.jsxs(h.div,{variants:j,initial:"hidden",animate:"visible",exit:"exit",custom:f++,className:"space-y-2",children:[e.jsxs("p",{className:"section-kicker",children:["Artifacts ",e.jsx("span",{className:"text-muted tabular-nums",children:t.artifactCount})]}),e.jsx("div",{className:"space-y-1",children:t.artifacts.map((r,c)=>e.jsxs("div",{className:"flex items-center gap-2 rounded-lg px-2 py-1.5 transition-colors hover:bg-white/[0.04]",children:[e.jsx(W,{type:r.type==="pull_request"?"session":"workstream",size:13,className:"flex-shrink-0 opacity-75"}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-caption text-primary",children:r.title}),r.url&&e.jsx("a",{href:r.url,target:"_blank",rel:"noopener noreferrer",className:"flex-shrink-0 text-micro text-secondary transition-colors hover:text-white",title:"Open artifact",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 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"}),e.jsx("polyline",{points:"15 3 21 3 21 9"}),e.jsx("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]})})]},r.id??c))})]})]}),t&&t.decisionCount>0&&e.jsxs(e.Fragment,{children:[e.jsx(y,{}),e.jsxs(h.div,{variants:j,initial:"hidden",animate:"visible",exit:"exit",custom:f++,className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("p",{className:"section-kicker",children:["Decisions ",e.jsx("span",{className:"text-muted tabular-nums",children:t.decisionCount})]}),t.blockingDecisionCount>0&&e.jsxs("span",{className:"inline-flex rounded-full border px-1.5 py-[0.5px] text-micro font-semibold tabular-nums",style:{color:l.red,borderColor:`${l.red}33`,backgroundColor:`${l.red}14`},children:[t.blockingDecisionCount," blocking"]})]}),t.decisionOptions.length>0&&e.jsx("div",{className:"space-y-1.5",children:t.decisionOptions.slice(0,4).map(r=>e.jsxs("div",{className:"rounded-lg border border-white/[0.06] bg-white/[0.02] px-3 py-2",children:[e.jsx("p",{className:"text-caption font-semibold text-primary",children:r.label}),r.description&&e.jsx("p",{className:"mt-0.5 text-micro leading-snug text-secondary",children:r.description})]},r.id))})]})]}),t&&(t.sliceRunId||t.runId)&&e.jsxs(e.Fragment,{children:[e.jsx(y,{}),e.jsxs(h.div,{variants:j,initial:"hidden",animate:"visible",exit:"exit",custom:f++,children:[e.jsx("p",{className:"section-kicker mb-2",children:"Notes"}),e.jsx(ge,{entityType:"run",entityId:t.runId??t.sliceRunId,variant:"inline"})]})]}),t&&(t.sourceClient||t.runtimeState||t.correlationId||t.runId)&&e.jsxs(e.Fragment,{children:[e.jsx(y,{}),e.jsxs("details",{className:"group",children:[e.jsxs("summary",{className:"flex cursor-pointer select-none items-center gap-1.5 py-1 text-micro uppercase tracking-[0.08em] text-muted transition-colors hover:text-secondary",children:[e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"transition-transform group-open:rotate-90",children:e.jsx("path",{d:"m9 18 6-6-6-6"})}),"Technical details"]}),e.jsxs("div",{className:"mt-2 grid grid-cols-2 gap-x-4 gap-y-2",children:[t.sourceClient&&e.jsxs("div",{children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Source"}),e.jsx("p",{className:"mt-0.5 font-mono text-caption text-primary",children:t.sourceClient})]}),t.runtimeState&&e.jsxs("div",{children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Runtime State"}),e.jsx("p",{className:"mt-0.5 font-mono text-caption text-primary",children:t.runtimeState})]}),t.runId&&e.jsxs("div",{className:"col-span-2",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Run ID"}),e.jsx("button",{type:"button",onClick:()=>{navigator.clipboard.writeText(t.runId)},className:"mt-0.5 font-mono text-caption text-primary transition-colors hover:text-white",title:"Click to copy",children:t.runId})]}),t.correlationId&&t.correlationId!==t.runId&&e.jsxs("div",{className:"col-span-2",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Correlation ID"}),e.jsx("button",{type:"button",onClick:()=>{navigator.clipboard.writeText(t.correlationId)},className:"mt-0.5 font-mono text-caption text-primary transition-colors hover:text-white",title:"Click to copy",children:t.correlationId})]})]})]})]})]})})]})})}export{De as SliceDetailModal};
@@ -1 +0,0 @@
1
- import{u as _t,r as d,a as zt,b as ze,j as e}from"./cNrhgGc1.js";import{i as Kt,q as Ke,b as Me,N as ot,B as Qt,u as Ut,P as Dt,w as O,C as lt,x as R,K as xt,A as pt,E as Ne,h as We,y as ct,z as Wt,U as Vt}from"./Cn07669c.js";import{S as W}from"./DHoYGJ9i.js";import{A as je,m as ee,R as Ht,b as Gt,a as Jt}from"./CxQ08qFN.js";function Zt({initiativeId:n=null,authToken:s=null,embedMode:l=!1,enabled:i=!0}){var L,z,te;const f=_t(),b=Kt(),N=d.useMemo(()=>Ke.autoContinueStatus({initiativeId:n??"__global__",authToken:s,embedMode:l}),[n,s,l]),g=zt({queryKey:N,enabled:i&&(!!n||n===null),queryFn:async()=>{if(b)return{ok:!0,initiativeId:n,run:null,defaults:{tokenBudget:null,tickMs:0}};const m=new URLSearchParams;n&&m.set("initiative_id",n);const x=await fetch(`/orgx/api/mission-control/auto-continue/status?${m.toString()}`,{headers:Me({authToken:s,embedMode:l})}),u=await x.json().catch(()=>null);if(!x.ok){const c=typeof(u==null?void 0:u.error)=="string"&&u.error||typeof(u==null?void 0:u.message)=="string"&&u.message||`Failed to load auto-continue status (${x.status})`;return{ok:!1,initiativeId:n,run:null,defaults:{tokenBudget:null,tickMs:0},error:c}}return u},refetchInterval:m=>{var T,p;const x=m.state.data;if((x==null?void 0:x.ok)===!1)return!1;const u=((T=x==null?void 0:x.error)==null?void 0:T.toLowerCase())??"";if(u.includes("404")||u.includes("400")||u.includes("not found")||u.includes("bad request"))return!1;const y=((p=x==null?void 0:x.run)==null?void 0:p.status)??null;return y==="running"||y==="stopping"?2500:12e3}}),$=async()=>{await f.invalidateQueries({queryKey:N}),await f.invalidateQueries({queryKey:Ke.missionControlGraph({initiativeId:n,authToken:s,embedMode:l})}),await f.invalidateQueries({queryKey:Ke.liveData({authToken:s,embedMode:l})})},A=ze({mutationFn:async m=>{if(b){const y=g.data??null;return{ok:!0,initiativeId:n,run:(y==null?void 0:y.run)??null,defaults:(y==null?void 0:y.defaults)??{tokenBudget:null,tickMs:0}}}const x={};n&&(x.initiativeId=n),x.ignoreSpawnGuardRateLimit=!0,m&&typeof m=="object"&&(typeof m.tokenBudgetTokens=="number"&&(x.tokenBudgetTokens=m.tokenBudgetTokens),typeof m.agentId=="string"&&m.agentId.trim().length>0&&(x.agentId=m.agentId.trim()),typeof m.maxParallelSlices=="number"&&Number.isFinite(m.maxParallelSlices)&&(x.maxParallelSlices=m.maxParallelSlices),m.parallelMode==="iwmt"&&(x.parallelMode=m.parallelMode));const u=await fetch("/orgx/api/mission-control/auto-continue/start",{method:"POST",headers:Me({authToken:s,embedMode:l,contentTypeJson:!0}),body:JSON.stringify(x)}),c=await u.json().catch(()=>null);if(!u.ok){const y=ot(c);if(y)throw y;const T=typeof(c==null?void 0:c.error)=="string"&&c.error||typeof(c==null?void 0:c.message)=="string"&&c.message||`Failed to start auto-continue (${u.status})`;throw new Error(T)}if(c&&typeof c=="object"&&"run"in c){const y=g.data??null;return{ok:!0,initiativeId:n,run:c.run??null,defaults:(y==null?void 0:y.defaults)??{tokenBudget:null,tickMs:0}}}return c},onSuccess:()=>{$()}}),J=ze({mutationFn:async()=>{if(b){const c=g.data??null;return{ok:!0,initiativeId:n,run:null,defaults:(c==null?void 0:c.defaults)??{tokenBudget:null,tickMs:0}}}const m={};n&&(m.initiativeId=n);const x=await fetch("/orgx/api/mission-control/auto-continue/stop",{method:"POST",headers:Me({authToken:s,embedMode:l,contentTypeJson:!0}),body:JSON.stringify(m)}),u=await x.json().catch(()=>null);if(!x.ok){const c=typeof(u==null?void 0:u.error)=="string"&&u.error||typeof(u==null?void 0:u.message)=="string"&&u.message||`Failed to stop auto-continue (${x.status})`;throw new Error(c)}if(u&&typeof u=="object"&&"run"in u){const c=g.data??null;return{ok:!0,initiativeId:n,run:u.run??null,defaults:(c==null?void 0:c.defaults)??{tokenBudget:null,tickMs:0}}}return u},onSuccess:()=>{$()}}),q=ze({mutationFn:async m=>{var y;if(b)return{ok:!0,dispatched:((y=m.workstreamIds)==null?void 0:y.length)??1};const x={initiativeId:m.initiativeId};m.workstreamIds&&m.workstreamIds.length>0&&(x.workstreamIds=m.workstreamIds),m.agentId&&(x.agentId=m.agentId),m.scope&&(x.scope=m.scope),x.ignoreSpawnGuardRateLimit=!0;const u=await fetch("/orgx/api/mission-control/next-up/launch",{method:"POST",headers:Me({authToken:s,embedMode:l,contentTypeJson:!0}),body:JSON.stringify(x)}),c=await u.json().catch(()=>null);if(!u.ok){const T=ot(c);if(T)throw T;const p=typeof(c==null?void 0:c.error)=="string"&&c.error||typeof(c==null?void 0:c.message)=="string"&&c.message||`Failed to launch (${u.status})`;throw new Error(p)}return c??{ok:!0,dispatched:0}},onSuccess:()=>{$()}}),C=((L=g.data)==null?void 0:L.run)??null,_=(C==null?void 0:C.status)==="running"||(C==null?void 0:C.status)==="stopping";return{status:g.data??null,run:C,isRunning:_,isLoading:g.isLoading,error:((z=g.data)==null?void 0:z.error)??((te=g.error)==null?void 0:te.message)??null,start:A.mutateAsync,stop:J.mutateAsync,launchSingle:q.mutateAsync,isStarting:A.isPending,isStopping:J.isPending,isLaunching:q.isPending,refetch:g.refetch}}async function ht(n,s){var b;const i=await(await fetch(n,s)).json().catch(()=>null),f=((b=i==null?void 0:i.data)==null?void 0:b.url)??(i==null?void 0:i.url)??null;if(typeof f=="string"&&f.trim())return f.trim();throw new Error((i==null?void 0:i.error)??"Billing link unavailable")}async function Xt(n){var f;const s=((f=n==null?void 0:n.actions)==null?void 0:f.checkout)??"/orgx/api/billing/checkout",l=((n==null?void 0:n.requiredPlan)??"starter").trim().toLowerCase()||"starter",i=await ht(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({planId:l})});window.open(i,"_blank","noopener,noreferrer")}async function Yt(n){var i;const s=((i=n==null?void 0:n.actions)==null?void 0:i.portal)??"/orgx/api/billing/portal",l=await ht(s,{method:"POST"});window.open(l,"_blank","noopener,noreferrer")}function Ot(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 en({open:n,tone:s="neutral",title:l,message:i=null,className:f,primaryAction:b=null,secondaryAction:N=null,onDismiss:g=null,autoDismissMs:$=null}){return d.useEffect(()=>{if(!n||!g||!$)return;const A=window.setTimeout(()=>g(),$);return()=>window.clearTimeout(A)},[$,g,n,l,i]),e.jsx(je,{initial:!1,children:n?e.jsx(ee.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 ${f??""}`,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 ${Ot(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]}),g?e.jsx("button",{type:"button",onClick:g,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]}),b||N?e.jsxs("div",{className:"mt-2 flex items-center gap-1.5",children:[N?e.jsx("button",{type:"button",onClick:N.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:N.label}):null,b?e.jsx("button",{type:"button",onClick:b.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:b.label}):null]}):null]})}):null})}function ft({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 tn({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 nn({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 ut(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 dt(n){return n==="running"?"Running":n==="blocked"?"Needs input":n==="idle"?"Idle":"Queued"}function Be(n){return n==="queued"||n==="idle"?0:n==="blocked"?1:n==="running"?2:n==="completed"?3:4}function bt(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 Qe(n){return n==="running"?"Current":n==="blocked"?"Blocked on":"Next"}function Ue(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 gt(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 f=i==="urgent"?"P1":i==="high"?"P2":i==="medium"?"P3":"P4",b=i==="urgent"?"Urgent":i==="high"?"High":i==="medium"?"Medium":"Low",N=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:`${f} ${b}`,longLabel:`Initiative priority ${b} (${f})`,toneClass:N}}function sn(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 We(l||n)||"Next Up is temporarily unavailable."}function rn(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.":We(n.trim())}function Ce(n,s,l){const i=typeof n=="string"?n.trim():"";if(i&&!ct(i))return R(i);const f=typeof s=="string"?s.trim():"";return f?ct(f)?`${l} ${Wt(f)}`:R(f):l}function yt(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 wt(n){return n.runnerSource==="inferred"?"inferred":null}function kt(n,s){const l=n.runnerSource==="assigned"?"assigned":n.runnerSource==="inferred"?"inferred":"fallback";return s==="Unassigned"?`Runner ${l}`:`${s} · ${l}`}function me(n,s){return!n||n.trim().length===0?s:We(n.trim())||s}function mt(n){return!n||typeof n!="object"||Array.isArray(n)?null:n}function De(n,s){const l=R(n.workstreamTitle),i=mt(s),f=i&&typeof i.dispatchMode=="string"?i.dispatchMode:null,b=mt(i==null?void 0:i.run);return(b&&typeof b.stopReason=="string"?b.stopReason:b&&typeof b.stop_reason=="string"?b.stop_reason:null)==="budget_exhausted"?`Dispatch acknowledged for ${l}, but autopilot stopped: budget exhausted.`:f==="pending"?`Dispatching ${l}; waiting for slice start…`:f==="fallback"?`Dispatched ${l} using fallback runner.`:`Dispatched ${l}.`}function vt({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 an({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(W,{className:"h-8 w-8 rounded-full"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx(W,{className:"h-3 w-40 rounded-md"}),e.jsx(W,{className:"mt-2 h-4 w-56 rounded-md"})]})]}),e.jsx(W,{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(W,{className:"h-3 w-14 rounded"}),e.jsx(W,{className:"mt-2 h-3 w-full rounded"}),e.jsx(W,{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(W,{className:"h-8 w-24 rounded-full"}),e.jsx(W,{className:"h-8 w-20 rounded-full"}),e.jsx(W,{className:"h-8 w-24 rounded-full"})]})]},`nextup-skeleton-${i}`))]})}function on({initiativeId:n=null,projectId:s=null,authToken:l=null,embedMode:i=!1,title:f="Next Up",showHeader:b=!0,compact:N=!1,className:g,disableEnterAnimation:$=!1,allowCompactToggle:A=!1,onToggleCompact:J,onOpenInitiative:q,onOpenSettings:C,onUpgradeGate:_,onOpenSliceDetail:L,selectionEnabled:z=!0,panelStyle:te="card",showQueueSettings:m=!0,queueModel:x,queueActions:u,snapshotVersion:c=null}){var at;const[y,T]=d.useState(N);d.useEffect(()=>T(N),[N]);const p=A&&!J?y:N,F=t=>{J?J(t):T(t)},[V,k]=d.useState(null),[S,xe]=d.useState("workstream"),[oe,pe]=d.useState(null),he="bottom",[M,ne]=d.useState(null),[Q,w]=d.useState(null),[le,se]=d.useState(null),[Z,ce]=d.useState(new Set),[Se,ue]=d.useState(null),[fe,be]=d.useState(!1),[jt,Ie]=d.useState(!1),Ve=d.useRef(null),Nt=Qt({initiativeId:n,projectId:s,authToken:l,embedMode:i,enabled:!x,snapshotVersion:c,zoomLevel:S}),Ct=x??Nt,{items:ge,degraded:re,isLoading:K,isFetching:He,error:$e,refetch:St,playWorkstream:Re,startWorkstreamAutoContinue:Ge,initiativeGroups:Je,milestoneGroups:Ze}=Ct;Zt({initiativeId:n,authToken:l,embedMode:i});const It=Ut({authToken:l,embedMode:i}),H=u??It,U=t=>`${t.initiativeId}:${t.workstreamId}`,X=S==="workstream",ye=d.useMemo(()=>ge.filter(t=>t.queueState==="running").length,[ge]),D=d.useMemo(()=>{const t=ge.filter(o=>o.queueState!=="running");return t.length>0?t:ge},[ge]),Xe=d.useMemo(()=>D.length===0?"empty":D.some(t=>t.queueState!=="running"&&t.queueState!=="blocked")?"queued":D.some(t=>t.queueState==="blocked")?"blocked":D.some(t=>t.queueState==="running")?"running":"queued",[D]),we=d.useMemo(()=>[...Je].sort((t,o)=>{const a=Be(t.queueState)-Be(o.queueState);return a!==0?a:t.initiativeTitle.localeCompare(o.initiativeTitle)}),[Je]),ke=d.useMemo(()=>[...Ze].sort((t,o)=>{const a=Be(t.queueState)-Be(o.queueState);if(a!==0)return a;const r=t.initiativeTitle.localeCompare(o.initiativeTitle);if(r!==0)return r;const h=t.workstreamTitle.localeCompare(o.workstreamTitle);return h!==0?h:t.milestoneTitle.localeCompare(o.milestoneTitle)}),[Ze]),Le=d.useMemo(()=>p?we.slice(0,5):we,[p,we]),Pe=d.useMemo(()=>p?ke.slice(0,5):ke,[p,ke]),Ye=d.useMemo(()=>S==="initiative"?we.length:S==="milestone"?ke.length:D.length,[D.length,we.length,ke.length,S]),$t=[{value:"initiative",label:"Initiative"},{value:"workstream",label:"Workstream"},{value:"milestone",label:"Milestone"}],B=d.useMemo(()=>X?p?D.slice(0,5):D:[],[p,X,D]),qt=d.useMemo(()=>B.filter(t=>Z.has(U(t))),[Z,B]),[de,Oe]=d.useState([]),Ee=d.useRef([]),et=d.useMemo(()=>{const t=new Map;for(const o of B)t.set(U(o),o);return t},[B]),P=d.useMemo(()=>B.map(U),[B]),Tt=d.useMemo(()=>P.join("|"),[P]);d.useEffect(()=>{Oe(t=>{if(p)return[];const o=[],a=new Set(P);for(const r of t)a.has(r)&&o.push(r);for(const r of P)o.includes(r)||o.push(r);return o})},[p,Tt]),d.useEffect(()=>{Ee.current=de},[de]),d.useEffect(()=>{Se&&(P.includes(Se)||ue(null))},[Se,P]),d.useEffect(()=>{ce(t=>{if(t.size===0)return t;const o=new Set(B.map(U)),a=new Set;for(const r of t)o.has(r)&&a.add(r);return a.size===t.size?t:a})},[B]),d.useEffect(()=>{if(!le)return;B.some(o=>U(o)===le)||se(null)},[le,B]),d.useEffect(()=>{if(re.length===0){Ie(!1);return}Ie(!1)},[re]),d.useEffect(()=>{z&&!p&&Z.size>0&&be(!1)},[p,Z.size,z]),d.useEffect(()=>{if(!fe)return;const t=a=>{var h;const r=a.target;r&&((h=Ve.current)!=null&&h.contains(r)||be(!1))},o=a=>{a.key==="Escape"&&be(!1)};return document.addEventListener("mousedown",t),document.addEventListener("touchstart",t),document.addEventListener("keydown",o),()=>{document.removeEventListener("mousedown",t),document.removeEventListener("touchstart",t),document.removeEventListener("keydown",o)}},[fe]);const tt=async t=>{const o=U(t),a=R(t.workstreamTitle);try{await H.remove({initiativeId:t.initiativeId,workstreamId:t.workstreamId}),ce(r=>{if(!r.has(o))return r;const h=new Set(r);return h.delete(o),h}),ue(r=>r===o?null:r),k(`Removed ${a} from queue.`)}catch(r){const h=r instanceof Error?r.message:"";k(me(h,"Failed to remove from queue"))}},Ft=(t,o,a)=>{const r=p?P:de.length>0?de:P;ce(h=>{const v=new Set(h),E=Se;if(a&&E&&r.includes(E)){const j=r.indexOf(t),Y=r.indexOf(E);if(j>=0&&Y>=0){const[Te,Fe]=j<Y?[j,Y]:[Y,j];for(const ve of r.slice(Te,Fe+1))o?v.add(ve):v.delete(ve)}else o?v.add(t):v.delete(t)}else o?v.add(t):v.delete(t);return v}),ue(t)},Mt=()=>{ce(new Set(P)),ue(P.length>0?P[P.length-1]:null)},Bt=()=>{ce(new Set),ue(null)},Ae=async t=>{if(Z.size===0){k("Select one or more queue items first.");return}const o=B.map(a=>({key:U(a),item:a})).filter(a=>Z.has(a.key));if(o.length===0){k("Selected queue items are no longer visible.");return}w(`bulk:${t}`),k(null);try{const a=o.map(({item:j})=>({initiativeId:j.initiativeId,workstreamId:j.workstreamId})),r=await H.bulk({action:t,items:a}),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,E=Array.isArray(r==null?void 0:r.errors)?r.errors.filter(j=>typeof j=="string").map(j=>j.trim()).filter(Boolean):[],I=t==="remove"?"removed":t==="move_top"?"moved to top":"moved to bottom";h===0&&v>0&&E.length>0?k(me(E[0],`${v} queue action${v===1?"":"s"} failed.`)):k(v>0?`${h} item${h===1?"":"s"} ${I}; ${v} failed.`:`${h} item${h===1?"":"s"} ${I}.`),ce(new Set),ue(null)}catch(a){const r=a instanceof Error?a.message:"";k(me(r,"Bulk queue action failed"))}finally{w(null)}},Rt=async()=>{const t=Ee.current.map(o=>et.get(o)).filter(Boolean).map(o=>({initiativeId:o.initiativeId,workstreamId:o.workstreamId}));t.length!==0&&await H.reorder({order:t})},ie=async(t,o,a)=>{k(null),ne(null),_==null||_(null),w(t);try{const r=await o();k(typeof a=="function"?a(r):a)}catch(r){if(r instanceof Vt)ne(r),_==null||_(r);else{const h=r instanceof Error?r.message:"";k(me(h,"Action failed"))}}finally{w(null)}},nt=async t=>await Re({initiativeId:t.initiativeId,workstreamId:t.workstreamId,agentId:t.runnerAgentId}),qe=M?"upgrade":$e?"error":V?"notice":null,st=$e?sn($e):null,_e=re.length>0?rn(re[0]):null,Lt=qe!==null,Pt=re.length>0&&!jt&&le===null&&!fe,ae=qt.length,Et=d.useMemo(()=>S==="initiative"?Le.length>0:S==="milestone"?Pe.length>0:B.length>0,[Le.length,B.length,Pe.length,S]),rt=z&&X&&!p&&ae>0,At=S==="initiative"?"No initiatives in the queue right now.":S==="milestone"?"No milestone slices in the queue right now.":ye>0?`No queued workstreams yet. ${ye} running item${ye===1?"":"s"} still in-flight.`:re.length>0?"Queue signal is delayed right now.":"No queued workstreams right now.",it=e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:Mt,className:"control-pill h-8 px-2.5 text-caption font-semibold",children:"Select all"}),e.jsx("button",{type:"button",onClick:Bt,disabled:Z.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:ae===0||Q==="bulk:move_top",onClick:()=>void Ae("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:ae===0||Q==="bulk:move_bottom",onClick:()=>void Ae("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:ae===0||Q==="bulk:remove",onClick:()=>void Ae("remove"),className:"control-pill h-8 px-2.5 text-caption font-semibold disabled:opacity-45",children:"Remove"})]});return e.jsxs(Dt,{surface:te==="card",className:`flex h-full min-h-0 flex-col overflow-hidden ${$?"":"card-enter"} ${te==="flat"?"!rounded-none !border-none !bg-transparent !shadow-none":""} ${g??""}`,children:[b?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:f}),e.jsx("span",{className:"chip inline-flex min-w-[52px] justify-center text-micro tabular-nums",children:K?e.jsx("span",{"aria-hidden":!0,className:"h-2.5 w-5 rounded bg-white/15 animate-pulse"}):Ye}),e.jsx("span",{className:O("chip inline-flex min-w-[148px] justify-center text-micro tabular-nums transition-opacity",!K&&ye>0&&X?"text-secondary opacity-100":"pointer-events-none opacity-0"),children:`${ye} active elsewhere`}),e.jsx("span",{className:O("inline-flex min-w-[92px] justify-end text-micro text-muted transition-opacity",He&&!K?"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:$t.map(t=>{const o=S===t.value;return e.jsx("button",{type:"button",role:"tab","aria-selected":o,onClick:()=>xe(t.value),className:O("h-7 rounded-lg px-2.5 text-caption font-semibold transition-colors",o?"border border-[#BFFF00]/35 bg-[#BFFF00]/16 text-[#E8FFD0]":"text-secondary hover:text-white"),title:`Show ${t.label.toLowerCase()} queue`,children:t.label},t.value)})}),A?e.jsx("button",{type:"button",onClick:()=>F(!p),className:"control-pill h-8 flex-shrink-0 whitespace-nowrap px-3 text-caption font-semibold",title:p?"Switch to expanded cards":"Switch to compact list","aria-label":p?"Expand Next Up queue":"Compact Next Up queue",children:p?"Expand":"Compact"}):null]})]}):null,Lt&&e.jsx("div",{className:"px-3 pt-2",children:e.jsx(je,{initial:!1,mode:"wait",children:qe==="upgrade"&&M?e.jsx(ee.div,{initial:{opacity:0,y:-4,scale:.99},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-4,scale:.99},transition:{duration:.18,ease:[.22,1,.36,1]},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:[lt(M.currentPlan)," →"," ",lt(M.requiredPlan)]})]}),e.jsx("div",{className:"mt-1 line-clamp-2 text-caption leading-snug text-amber-50/90",title:M.message,children:M.message}),V?e.jsx("div",{className:"mt-1 text-micro text-rose-50/85",children:V}):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 Xt({actions:M.actions,requiredPlan:M.requiredPlan}).catch(t=>k(me(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 Yt({actions:M.actions}).catch(t=>k(me(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"}),C&&e.jsx("button",{type:"button",onClick:C,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"})]}),(at=M.actions)!=null&&at.pricing?e.jsx("a",{href:M.actions.pricing,target:"_blank",rel:"noopener noreferrer",className:"text-micro text-secondary underline decoration-white/20 hover:text-primary",children:"View pricing"}):null]})]})},"upgrade"):qe==="error"&&st?e.jsx(ee.div,{initial:{opacity:0,y:-4},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},transition:{duration:.18},className:"rounded-xl border border-red-400/25 bg-red-500/[0.08] px-3 py-2 text-caption text-red-100",children:st},"error"):qe==="notice"&&V?e.jsx(ee.div,{initial:{opacity:0,y:-4},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},transition:{duration:.18},className:"rounded-xl border border-white/[0.1] bg-white/[0.03] px-3 py-2 text-caption text-primary",children:V},"notice"):null})}),e.jsxs("div",{className:`flex-1 space-y-2.5 overflow-y-auto overscroll-y-contain px-3 pb-3 ${b?"pt-1":"pt-2.5"}`,children:[!K&&Ye>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:S==="initiative"?"Initiatives":S==="milestone"?"Milestone slices":Xe==="blocked"?"Needs attention":Xe==="running"?"Running now":"Queue"}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-1.5",children:[ae>0?e.jsxs("span",{className:"chip text-micro",children:[ae," selected"]}):null,e.jsx("span",{className:O("inline-flex min-w-[92px] text-micro text-muted transition-opacity",He&&!K?"opacity-100":"opacity-0"),"aria-live":"polite",children:"refreshing…"}),z&&X&&!p&&ae===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:[A?e.jsx("button",{type:"button",onClick:()=>F(!p),className:"control-pill h-8 px-2.5 text-caption font-semibold",title:p?"Switch to expanded cards":"Switch to compact list","aria-label":p?"Expand Next Up queue":"Compact Next Up queue",children:p?"Expand":"Compact"}):null,rt?e.jsx("div",{className:"flex flex-wrap justify-end gap-1.5",children:it}):null,!rt&&m&&X?e.jsxs("div",{ref:Ve,className:"relative",children:[e.jsxs("button",{type:"button",onClick:()=>be(t=>!t),className:"control-pill h-8 px-2.5 text-caption font-semibold","aria-haspopup":"menu","aria-expanded":fe,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"})]}),fe?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:[z&&!p?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:it})]}):null,C?e.jsx("button",{type:"button",onClick:()=>{be(!1),C()},className:"control-pill h-7 px-2.5 text-micro font-semibold",children:"Open settings"}):null]})}):null]}):null]})]}):null,K?e.jsx(an,{compact:p}):null,!K&&!Et&&!$e&&e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.02] px-3 py-4 text-center",children:[e.jsx("p",{className:"text-body text-secondary",children:At}),_e?e.jsx("p",{className:"mt-1 text-micro text-muted",children:_e}):null,re.length>0?e.jsx("div",{className:"mt-2.5 flex items-center justify-center gap-1.5",children:e.jsx("button",{type:"button",onClick:()=>{Ie(!1),St()},className:"control-pill h-7 px-2.5 text-micro font-semibold",children:"Retry now"})}):null]}),!K&&S==="initiative"?e.jsx(je,{initial:!1,children:Le.map((t,o)=>{const a=t.items.find(I=>I.queueState!=="running"&&I.queueState!=="completed")??t.items[0]??null,r=Ce(t.initiativeTitle,t.initiativeId,"Initiative"),h=dt(t.queueState),v=ut(t.queueState),E=t.items.reduce((I,j)=>I+(j.sliceTaskCount??0),0);return e.jsxs(ee.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:.2,delay:Math.min(o,7)*.02,ease:[.22,1,.36,1]},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:O("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 · ",E," tasks"]}),e.jsx("div",{className:"mt-2 space-y-1",children:t.items.slice(0,3).map((I,j)=>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:R(I.workstreamTitle)}),e.jsxs("span",{className:"text-micro text-secondary",children:[I.sliceTaskCount??0," tasks"]})]},`${I.workstreamId}:${j}`))}),e.jsxs("div",{className:"mt-2.5 flex items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>q==null?void 0:q(t.initiativeId,t.initiativeTitle),className:"control-pill h-7 px-2.5 text-micro font-semibold",children:"Open"}),e.jsx("button",{type:"button",disabled:!a||Q===`initiative:${t.initiativeId}`,onClick:()=>{a&&ie(`initiative:${t.initiativeId}`,()=>nt(a),`Dispatched ${R(a.workstreamTitle)}.`)},className:"control-pill h-7 px-2.5 text-micro font-semibold disabled:opacity-45",children:"Dispatch"})]})]},`initiative-group:${t.initiativeId}`)})}):null,!K&&S==="milestone"?e.jsx(je,{initial:!1,children:Pe.map((t,o)=>{const a=t.item,r=`milestone:${t.workstreamId}:${t.milestoneId??"none"}`;return e.jsxs(ee.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:.2,delay:Math.min(o,7)*.02,ease:[.22,1,.36,1]},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:[R(t.initiativeTitle)," · ",R(t.workstreamTitle)]}),e.jsx("p",{className:"mt-0.5 truncate text-body font-semibold text-white",title:t.milestoneTitle,children:R(t.milestoneTitle)})]}),e.jsx("span",{className:O("inline-flex items-center rounded-full border px-2 py-0.5 text-[10px] font-semibold uppercase tracking-[0.08em]",ut(t.queueState)),children:dt(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:()=>q==null?void 0:q(t.initiativeId,t.initiativeTitle),className:"control-pill h-7 px-2.5 text-micro font-semibold",children:"Open"}),e.jsx("button",{type:"button",disabled:Q===r||t.queueState==="running",onClick:()=>void ie(r,()=>nt(a),h=>De(a,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,!K&&X&&p?e.jsx(je,{initial:!1,children:B.map((t,o)=>{const a=U(t),r=Q===a,h=t.queueState==="running",v=t.nextTaskDueAt?xt(t.nextTaskDueAt):null,E=Ce(t.initiativeTitle,t.initiativeId,"Initiative"),I=Ce(t.workstreamTitle,t.workstreamId,"Workstream"),j=gt(t),Y=t.nextTaskTitle?R(t.nextTaskTitle):null,Te=t.blockReason?R(t.blockReason):null,Fe=yt(t),ve=wt(t);return e.jsxs(ee.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:.22,delay:Math.min(o,7)*.018,ease:[.22,1,.36,1]},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:()=>L==null?void 0:L(t),role:"button",tabIndex:0,onKeyDown:G=>{(G.key==="Enter"||G.key===" ")&&(G.preventDefault(),L==null||L(t))},children:[e.jsx("div",{className:`pointer-events-none absolute inset-x-2.5 top-0 h-px bg-gradient-to-r ${bt(t.queueState)}`,"aria-hidden":!0}),e.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[e.jsx(pt,{name:Fe,hint:kt(t,Fe),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(Ne,{type:"initiative",size:11,className:"flex-shrink-0 opacity-85"}),e.jsx("button",{type:"button",onClick:()=>q==null?void 0:q(t.initiativeId,t.initiativeTitle),className:"block min-w-0 flex-1 truncate text-left text-micro uppercase tracking-[0.08em] text-muted transition-colors hover:text-white/72",title:E,children:E}),j?e.jsx("span",{className:O("inline-flex flex-shrink-0 items-center rounded-full border px-2 py-0.5 text-[9px] font-semibold uppercase tracking-[0.08em]",j.toneClass),title:j.longLabel,children:j.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:I,children:[e.jsx(Ne,{type:"workstream",size:12,className:"flex-shrink-0 opacity-95"}),e.jsx("span",{className:"line-clamp-2",children:I})]}),Y?e.jsxs("p",{className:"mt-0.5 line-clamp-2 text-micro leading-snug text-secondary",title:`${Qe(t.queueState)}: ${Y}${v?` · ${v}`:""}`,children:[Qe(t.queueState),": ",Y,v?` · ${v}`:""]}):e.jsx("p",{className:"mt-0.5 line-clamp-2 text-micro leading-snug text-secondary",title:Ue(t),children:Ue(t)}),ve?e.jsxs("p",{className:"mt-0.5 text-micro text-muted",children:["Runner ",ve]}):null]})]}),Te&&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: ",Te]}),e.jsxs("div",{className:"mt-1.5 flex items-center gap-1.5",onClick:G=>G.stopPropagation(),children:[e.jsx("button",{type:"button",disabled:r||h,onClick:()=>void ie(a,()=>Re({initiativeId:t.initiativeId,workstreamId:t.workstreamId,agentId:t.runnerAgentId}),G=>De(t,G)),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(ft,{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:()=>se(G=>G===a?null:a),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(vt,{className:"h-3 w-3 opacity-85"}),e.jsx("span",{children:"More"})]})}),le===a&&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:()=>{se(null),ie(`${a}:top`,()=>H.move({initiativeId:t.initiativeId,workstreamId:t.workstreamId,placement:"top"}),`Moved ${I} 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:()=>{se(null),ie(`${a}:bottom`,()=>H.move({initiativeId:t.initiativeId,workstreamId:t.workstreamId,placement:"bottom"}),`Moved ${I} 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:()=>{se(null),ie(`${a}:auto`,async()=>(await H.move({initiativeId:t.initiativeId,workstreamId:t.workstreamId,placement:"top"}),Ge({initiativeId:t.initiativeId,workstreamId:t.workstreamId,agentId:t.runnerAgentId,scope:"initiative"})),`Start+Auto enabled for ${E}.`)},className:"flex h-8 w-full items-center rounded-md px-2.5 text-left text-caption text-primary transition-colors hover:bg-white/[0.08]",children:"Start with auto"}),e.jsx("button",{type:"button",disabled:H.isRemoving,onClick:()=>{se(null),tt(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"})]})]})]})]},a)})}):!K&&X?e.jsx(Ht,{axis:"y",values:de,onReorder:t=>{Ee.current=t,Oe(t)},className:"space-y-2.5",children:de.map(t=>et.get(t)).filter(Boolean).map((t,o)=>e.jsx(ln,{item:t,index:o,actionKey:Q,setNotice:k,setUpgradeGate:ne,onUpgradeGate:_,onOpenInitiative:q,onOpenSliceDetail:L,selected:Z.has(U(t)),selectionEnabled:z,onToggleSelection:Ft,menuKey:le,setMenuKey:se,playWorkstream:Re,startWorkstreamAutoContinue:Ge,triagePlacement:he,onPauseWorkstream:(a,r)=>H.stopTriage({initiativeId:a.initiativeId,workstreamId:a.workstreamId,placement:r,resetToTodo:!1}),onMoveWorkstream:(a,r)=>H.move({initiativeId:a.initiativeId,workstreamId:a.workstreamId,placement:r}),onCommitReorder:()=>void Rt().catch(()=>null),onDismiss:tt,runAction:ie},U(t)))}):null]}),e.jsx("div",{className:"pointer-events-none absolute bottom-3 right-3 z-[250]",children:e.jsx(en,{open:Pt,tone:"warning",title:"Limited signal",message:_e,autoDismissMs:6e3,onDismiss:()=>Ie(!0)})})]})}function ln({item:n,index:s,actionKey:l,setNotice:i,setUpgradeGate:f,onUpgradeGate:b,onOpenInitiative:N,onOpenSliceDetail:g,selected:$,selectionEnabled:A,onToggleSelection:J,menuKey:q,setMenuKey:C,playWorkstream:_,startWorkstreamAutoContinue:L,triagePlacement:z,onPauseWorkstream:te,onMoveWorkstream:m,onCommitReorder:x,onDismiss:u,runAction:c}){const y=Gt(),[T,p]=d.useState(!1),F=`${n.initiativeId}:${n.workstreamId}`,V=l===F,k=n.queueState==="running",S=n.nextTaskDueAt?xt(n.nextTaskDueAt):null,xe=Ce(n.initiativeTitle,n.initiativeId,"Initiative"),oe=Ce(n.workstreamTitle,n.workstreamId,"Workstream"),pe=gt(n),he=n.nextTaskTitle?R(n.nextTaskTitle):null,M=n.blockReason?R(n.blockReason):null,ne=yt(n),Q=wt(n);return e.jsx(Jt,{value:F,id:F,dragListener:!1,dragControls:y,onDragStart:()=>p(!0),onDragEnd:()=>{p(!1),x()},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(ee.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:.4,ease:[.25,.1,.25,1],delay:Math.min(s,7)*.05,opacity:{duration:.32,ease:[.25,.1,.25,1]}},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:()=>g==null?void 0:g(n),role:"button",tabIndex:0,onKeyDown:w=>{(w.key==="Enter"||w.key===" ")&&(w.preventDefault(),g==null||g(n))},children:[e.jsx("div",{className:`pointer-events-none absolute inset-x-3 top-0 h-px bg-gradient-to-r ${bt(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 ${A?$?"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(pt,{name:ne,hint:kt(n,ne),size:"sm"})}),A?e.jsx("button",{type:"button",role:"checkbox","aria-checked":$,"aria-label":"Select queue row",title:$?"Selected (Shift+click for range)":"Select (Shift+click for range)",onClick:w=>{w.stopPropagation(),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 ${$?"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:$?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(Ne,{type:"initiative",size:11,className:"flex-shrink-0 opacity-85"}),e.jsx("button",{type:"button",onClick:()=>N==null?void 0:N(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:xe,children:xe}),pe?e.jsx("span",{className:O("inline-flex flex-shrink-0 items-center rounded-full border px-2 py-0.5 text-[9px] font-semibold uppercase tracking-[0.08em]",pe.toneClass),title:pe.longLabel,children:pe.shortLabel}):null]}),e.jsxs("div",{className:"mt-0.5 flex min-w-0 items-start gap-1.5",children:[e.jsx(Ne,{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:oe,children:oe})]}),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:[ne,Q?` · ${Q}`:""]})]})]})]})}),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:he?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(Ne,{type:"task",size:10,className:"flex-shrink-0 opacity-80"}),e.jsx("span",{children:Qe(n.queueState)}),S?e.jsxs("span",{className:"truncate text-micro normal-case tracking-normal text-muted",children:["· ",S]}):null]}),e.jsx("p",{className:"line-clamp-2 break-words text-caption leading-snug text-white/84",title:he,children:he})]}):e.jsx("span",{className:"text-secondary",children:Ue(n)})}),M&&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: ",M]}),e.jsxs("div",{className:"mt-2 flex items-center gap-1.5",onClick:w=>w.stopPropagation(),children:[e.jsx("button",{type:"button",disabled:V||k,onClick:()=>void c(F,()=>_({initiativeId:n.initiativeId,workstreamId:n.workstreamId,agentId:n.runnerAgentId}),w=>De(n,w)),className:"control-pill flex h-7 items-center justify-center px-2.5 text-micro font-semibold disabled:opacity-40",title:k?"Already running":"Start this workstream now",children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(ft,{className:"h-3 w-3 opacity-85"}),e.jsx("span",{children:k?"Running":"Start"})]})}),e.jsxs("button",{type:"button",onPointerDown:w=>y.start(w),"aria-label":"Drag to reorder",title:T?"Reordering":"Drag to reorder",className:`control-pill flex h-7 items-center justify-center gap-1 px-2 text-micro font-semibold transition-colors ${T?"border-[#BFFF00]/35 bg-[#BFFF00]/14 text-[#E1FFB2] cursor-grabbing":"cursor-grab hover:bg-white/[0.08] hover:text-bright"}`,children:[T?e.jsx(nn,{className:"h-3.5 w-3.5 opacity-90"}):e.jsx(tn,{className:"h-3.5 w-3.5 opacity-90"}),e.jsx("span",{children:T?"Reordering":"Drag"})]}),e.jsxs("div",{className:"relative ml-auto",children:[e.jsx("button",{type:"button",disabled:V,onClick:()=>C(w=>w===F?null:F),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(vt,{className:"h-3 w-3 opacity-85"}),e.jsx("span",{children:"More"})]})}),q===F&&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:()=>{C(null),c(`${F}:top`,()=>m(n,"top"),`Moved ${oe} 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:()=>{C(null),c(`${F}:bottom`,()=>m(n,"bottom"),`Moved ${oe} 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:()=>{C(null),c(`${F}:auto`,async()=>(await m(n,"top"),L({initiativeId:n.initiativeId,workstreamId:n.workstreamId,agentId:n.runnerAgentId,scope:"initiative"})),`Start+Auto enabled for ${xe}.`)},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"}),k?e.jsx("button",{type:"button",onClick:()=>{C(null),c(`${F}:pause`,()=>te(n,z),`Paused ${oe}.`)},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:V||k,onClick:()=>{C(null),u(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 xn=Object.freeze(Object.defineProperty({__proto__:null,NextUpPanel:on},Symbol.toStringTag,{value:"Module"}));export{en as I,on as N,xn as a,Xt as o,Zt as u};