@useorgx/openclaw-plugin 0.7.3 → 0.7.4

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 (110) hide show
  1. package/dashboard/dist/assets/{CgaottFX.js → B1mDqDdy.js} +1 -1
  2. package/dashboard/dist/assets/B1mDqDdy.js.br +0 -0
  3. package/dashboard/dist/assets/B1mDqDdy.js.gz +0 -0
  4. package/dashboard/dist/assets/BDMstdfu.js +1 -0
  5. package/dashboard/dist/assets/BDMstdfu.js.br +0 -0
  6. package/dashboard/dist/assets/BDMstdfu.js.gz +0 -0
  7. package/dashboard/dist/assets/BTAEErUY.js +1 -0
  8. package/dashboard/dist/assets/BTAEErUY.js.br +0 -0
  9. package/dashboard/dist/assets/BTAEErUY.js.gz +0 -0
  10. package/dashboard/dist/assets/{8dksYiq4.js → BXapfumA.js} +1 -1
  11. package/dashboard/dist/assets/BXapfumA.js.br +0 -0
  12. package/dashboard/dist/assets/BXapfumA.js.gz +0 -0
  13. package/dashboard/dist/assets/BZZKPNDb.css +1 -0
  14. package/dashboard/dist/assets/BZZKPNDb.css.br +0 -0
  15. package/dashboard/dist/assets/BZZKPNDb.css.gz +0 -0
  16. package/dashboard/dist/assets/{rttbDbEx.js → BdusVDcP.js} +1 -1
  17. package/dashboard/dist/assets/BdusVDcP.js.br +0 -0
  18. package/dashboard/dist/assets/BdusVDcP.js.gz +0 -0
  19. package/dashboard/dist/assets/{D8JNX8kq.js → BwkNYH6r.js} +1 -1
  20. package/dashboard/dist/assets/BwkNYH6r.js.br +0 -0
  21. package/dashboard/dist/assets/BwkNYH6r.js.gz +0 -0
  22. package/dashboard/dist/assets/{CzCxAZlW.js → CRhvoVeH.js} +1 -1
  23. package/dashboard/dist/assets/CRhvoVeH.js.br +0 -0
  24. package/dashboard/dist/assets/CRhvoVeH.js.gz +0 -0
  25. package/dashboard/dist/assets/{B6wPWJ35.js → CYchPSem.js} +1 -1
  26. package/dashboard/dist/assets/CYchPSem.js.br +0 -0
  27. package/dashboard/dist/assets/CYchPSem.js.gz +0 -0
  28. package/dashboard/dist/assets/Cn07669c.js +212 -0
  29. package/dashboard/dist/assets/Cn07669c.js.br +0 -0
  30. package/dashboard/dist/assets/Cn07669c.js.gz +0 -0
  31. package/dashboard/dist/assets/{C8uM3AX8.js → DBG89Wsz.js} +1 -1
  32. package/dashboard/dist/assets/DBG89Wsz.js.br +0 -0
  33. package/dashboard/dist/assets/DBG89Wsz.js.gz +0 -0
  34. package/dashboard/dist/assets/{CZaT3ob_.js → DHoYGJ9i.js} +1 -1
  35. package/dashboard/dist/assets/DHoYGJ9i.js.br +0 -0
  36. package/dashboard/dist/assets/DHoYGJ9i.js.gz +0 -0
  37. package/dashboard/dist/assets/DHtZPEKd.js +1 -0
  38. package/dashboard/dist/assets/DHtZPEKd.js.br +0 -0
  39. package/dashboard/dist/assets/DHtZPEKd.js.gz +0 -0
  40. package/dashboard/dist/assets/{B5zYRHc3.js → DUaqjbT7.js} +1 -1
  41. package/dashboard/dist/assets/DUaqjbT7.js.br +0 -0
  42. package/dashboard/dist/assets/DUaqjbT7.js.gz +0 -0
  43. package/dashboard/dist/assets/{IUexzymk.js → Dlz0Cm_E.js} +1 -1
  44. package/dashboard/dist/assets/Dlz0Cm_E.js.br +0 -0
  45. package/dashboard/dist/assets/Dlz0Cm_E.js.gz +0 -0
  46. package/dashboard/dist/assets/{CC63EwFD.js → E8q3xNGK.js} +1 -1
  47. package/dashboard/dist/assets/E8q3xNGK.js.br +0 -0
  48. package/dashboard/dist/assets/E8q3xNGK.js.gz +0 -0
  49. package/dashboard/dist/assets/VH0fzk6I.js +1 -0
  50. package/dashboard/dist/assets/VH0fzk6I.js.br +0 -0
  51. package/dashboard/dist/assets/VH0fzk6I.js.gz +0 -0
  52. package/dashboard/dist/assets/bxgRC96y.js +1 -0
  53. package/dashboard/dist/assets/bxgRC96y.js.br +0 -0
  54. package/dashboard/dist/assets/bxgRC96y.js.gz +0 -0
  55. package/dashboard/dist/index.html +2 -2
  56. package/dashboard/dist/index.html.br +0 -0
  57. package/dashboard/dist/index.html.gz +0 -0
  58. package/dist/http/helpers/auto-continue-engine.js +29 -11
  59. package/dist/http/helpers/autopilot-slice-utils.js +7 -10
  60. package/dist/http/helpers/openclaw-cli.js +2 -2
  61. package/dist/http/index.js +160 -4
  62. package/dist/http/routes/live-legacy.d.ts +2 -0
  63. package/dist/http/routes/live-legacy.js +97 -0
  64. package/dist/http/routes/mission-control-read.js +106 -63
  65. package/dist/openclaw-settings.js +3 -2
  66. package/dist/sync/outbox-replay.js +17 -8
  67. package/package.json +1 -1
  68. package/dashboard/dist/assets/6mILZQ2a.js +0 -1
  69. package/dashboard/dist/assets/6mILZQ2a.js.br +0 -0
  70. package/dashboard/dist/assets/6mILZQ2a.js.gz +0 -0
  71. package/dashboard/dist/assets/8dksYiq4.js.br +0 -0
  72. package/dashboard/dist/assets/8dksYiq4.js.gz +0 -0
  73. package/dashboard/dist/assets/B5zYRHc3.js.br +0 -0
  74. package/dashboard/dist/assets/B5zYRHc3.js.gz +0 -0
  75. package/dashboard/dist/assets/B6wPWJ35.js.br +0 -0
  76. package/dashboard/dist/assets/B6wPWJ35.js.gz +0 -0
  77. package/dashboard/dist/assets/BWEwjt1W.js +0 -1
  78. package/dashboard/dist/assets/BWEwjt1W.js.br +0 -0
  79. package/dashboard/dist/assets/BWEwjt1W.js.gz +0 -0
  80. package/dashboard/dist/assets/BzRbDCAD.css +0 -1
  81. package/dashboard/dist/assets/BzRbDCAD.css.br +0 -0
  82. package/dashboard/dist/assets/BzRbDCAD.css.gz +0 -0
  83. package/dashboard/dist/assets/C8uM3AX8.js.br +0 -0
  84. package/dashboard/dist/assets/C8uM3AX8.js.gz +0 -0
  85. package/dashboard/dist/assets/C9jy61eu.js +0 -212
  86. package/dashboard/dist/assets/C9jy61eu.js.br +0 -0
  87. package/dashboard/dist/assets/C9jy61eu.js.gz +0 -0
  88. package/dashboard/dist/assets/CC63EwFD.js.br +0 -0
  89. package/dashboard/dist/assets/CC63EwFD.js.gz +0 -0
  90. package/dashboard/dist/assets/CZaT3ob_.js.br +0 -0
  91. package/dashboard/dist/assets/CZaT3ob_.js.gz +0 -0
  92. package/dashboard/dist/assets/CgaottFX.js.br +0 -0
  93. package/dashboard/dist/assets/CgaottFX.js.gz +0 -0
  94. package/dashboard/dist/assets/CzCxAZlW.js.br +0 -0
  95. package/dashboard/dist/assets/CzCxAZlW.js.gz +0 -0
  96. package/dashboard/dist/assets/D3iMTYEj.js +0 -1
  97. package/dashboard/dist/assets/D3iMTYEj.js.br +0 -0
  98. package/dashboard/dist/assets/D3iMTYEj.js.gz +0 -0
  99. package/dashboard/dist/assets/D8JNX8kq.js.br +0 -0
  100. package/dashboard/dist/assets/D8JNX8kq.js.gz +0 -0
  101. package/dashboard/dist/assets/DnA8dpj6.js +0 -1
  102. package/dashboard/dist/assets/DnA8dpj6.js.br +0 -0
  103. package/dashboard/dist/assets/DnA8dpj6.js.gz +0 -0
  104. package/dashboard/dist/assets/IUexzymk.js.br +0 -0
  105. package/dashboard/dist/assets/IUexzymk.js.gz +0 -0
  106. package/dashboard/dist/assets/ic2FaMnh.js +0 -1
  107. package/dashboard/dist/assets/ic2FaMnh.js.br +0 -0
  108. package/dashboard/dist/assets/ic2FaMnh.js.gz +0 -0
  109. package/dashboard/dist/assets/rttbDbEx.js.br +0 -0
  110. package/dashboard/dist/assets/rttbDbEx.js.gz +0 -0
@@ -1 +1 @@
1
- import{r as o,j as t}from"./cNrhgGc1.js";import{i as L,b as C,a1 as M}from"./C9jy61eu.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
+ 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 +1 @@
1
- import{j as r}from"./cNrhgGc1.js";import{w as s}from"./C9jy61eu.js";function i({className:e=""}){return r.jsx("div",{className:s("shimmer-skeleton",e),"aria-hidden":"true"})}export{i as S};
1
+ import{j as r}from"./cNrhgGc1.js";import{w as s}from"./Cn07669c.js";function i({className:e=""}){return r.jsx("div",{className:s("shimmer-skeleton",e),"aria-hidden":"true"})}export{i as S};
@@ -0,0 +1 @@
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 +1 @@
1
- import{r as o,j as e}from"./cNrhgGc1.js";import{d as l,r as p,E as h,V as u}from"./C9jy61eu.js";import{DecisionQueue as b}from"./rttbDbEx.js";import"./C-KIc3Wc.js";import"./BJgZIVUQ.js";import"./CxQ08qFN.js";import"./C8uM3AX8.js";import"./B6wPWJ35.js";function C({open:n,onClose:a,decisions:t,onApproveDecision:i,onRejectDecision:d,onApproveAll:m,onBulkDecisionAction:x}){const r=o.useMemo(()=>t.length>0?Math.max(0,...t.map(c=>c.waitingMinutes)):0,[t]),s=o.useMemo(()=>t.length>=20||r>=15?l.red:t.length>0?l.amber:l.textMuted,[t.length,r]);return e.jsx(p,{open:n,onClose:a,maxWidth:"max-w-3xl",children:e.jsxs("div",{className:"flex h-full w-full flex-col",children:[e.jsx("div",{className:"border-b border-subtle px-5 pt-5 pb-4",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("h3",{className:"inline-flex items-center gap-2 text-heading font-semibold text-white",children:[e.jsx(h,{type:"decision",size:14}),e.jsx("span",{className:"truncate",children:"Decisions"}),e.jsx("span",{className:"rounded-full border px-2 py-0.5 text-caption font-semibold",style:{borderColor:`${s}30`,backgroundColor:`${s}14`,color:s},children:t.length})]}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:"Bulk review and resolve pending decisions."}),t.length>0&&e.jsxs("p",{className:"mt-2 text-caption text-secondary",children:["Oldest: ",e.jsxs("span",{className:"font-semibold text-white",children:[u(r)," ago"]})]})]}),e.jsx("button",{type:"button",onClick:a,className:"rounded-md border border-strong bg-white/[0.03] px-2.5 py-1.5 text-caption text-primary transition-colors hover:bg-white/[0.08]","aria-label":"Close decisions modal",children:"Close"})]})}),e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden p-4",children:e.jsx(b,{decisions:t,onApproveDecision:i,onRejectDecision:d,onApproveAll:m,onBulkDecisionAction:x})})]})})}export{C as BulkDecisionsModal};
1
+ import{r as o,j as e}from"./cNrhgGc1.js";import{d as l,r as p,E as h,W as u}from"./Cn07669c.js";import{DecisionQueue as b}from"./BdusVDcP.js";import"./C-KIc3Wc.js";import"./BJgZIVUQ.js";import"./CxQ08qFN.js";import"./DBG89Wsz.js";import"./CYchPSem.js";function C({open:n,onClose:a,decisions:t,onApproveDecision:i,onRejectDecision:d,onApproveAll:m,onBulkDecisionAction:x}){const r=o.useMemo(()=>t.length>0?Math.max(0,...t.map(c=>c.waitingMinutes)):0,[t]),s=o.useMemo(()=>t.length>=20||r>=15?l.red:t.length>0?l.amber:l.textMuted,[t.length,r]);return e.jsx(p,{open:n,onClose:a,maxWidth:"max-w-3xl",children:e.jsxs("div",{className:"flex h-full w-full flex-col",children:[e.jsx("div",{className:"border-b border-subtle px-5 pt-5 pb-4",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("h3",{className:"inline-flex items-center gap-2 text-heading font-semibold text-white",children:[e.jsx(h,{type:"decision",size:14}),e.jsx("span",{className:"truncate",children:"Decisions"}),e.jsx("span",{className:"rounded-full border px-2 py-0.5 text-caption font-semibold",style:{borderColor:`${s}30`,backgroundColor:`${s}14`,color:s},children:t.length})]}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:"Bulk review and resolve pending decisions."}),t.length>0&&e.jsxs("p",{className:"mt-2 text-caption text-secondary",children:["Oldest: ",e.jsxs("span",{className:"font-semibold text-white",children:[u(r)," ago"]})]})]}),e.jsx("button",{type:"button",onClick:a,className:"rounded-md border border-strong bg-white/[0.03] px-2.5 py-1.5 text-caption text-primary transition-colors hover:bg-white/[0.08]","aria-label":"Close decisions modal",children:"Close"})]})}),e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden p-4",children:e.jsx(b,{decisions:t,onApproveDecision:i,onRejectDecision:d,onApproveAll:m,onBulkDecisionAction:x})})]})})}export{C as BulkDecisionsModal};
@@ -1 +1 @@
1
- import{r as w,j as e}from"./cNrhgGc1.js";import{y as T,z as N,F as ye,P as we,w as S,G as qe,d as Z,H as ze,J as je,K as q,L as Pe,x as Fe,M as Oe}from"./C9jy61eu.js";import{u as Ve}from"./B6wPWJ35.js";import"./C-KIc3Wc.js";import"./BJgZIVUQ.js";import"./CxQ08qFN.js";const Ge=/^[0-9a-f-]{20,}$/i,Ke=new Set(["running","active","queued","pending","in_progress","working","planning","handoff","review"]),He=new Set(["agent execution failed","execution failed","run failed","failed"]);function y(n){return typeof n=="string"&&n.trim().length>0}function le(n){return(n??"").trim().toLowerCase()}function Je(n){return(n??"").trim().replace(/\s+/g," ").toLowerCase()}function Xe(n){return He.has(Je(n))}function z(n,t=3){return n.length<=t?n.join(", "):`${n.slice(0,t).join(", ")} +${n.length-t} more`}function P(n,t){const b=[],o=m=>{if(typeof m!="string")return;const j=m.trim();j&&(b.some(L=>L.toLowerCase()===j.toLowerCase())||b.push(j))};if(Array.isArray(n))for(const m of n)o(m);return o(t??null),b}function Qe(n){if(n.runId&&n.runId.trim().length>0)return n.runId.trim();const t=n.metadata;if(!t)return null;const b=["slice_run_id","sliceRunId","runId","run_id","correlation_id","correlationId","sessionId","session_id","agentRunId"];for(const o of b){const m=t[o];if(typeof m=="string"&&m.trim().length>0)return m.trim()}return null}function Ye(n){const t=le(n.status);if(t==="blocked"||t==="failed"||t==="completed"||t==="cancelled")return t;const b=le(n.phase);if(b==="blocked")return"blocked";if(b==="handoff")return"handoff";if(b==="completed")return"completed";if(b==="review")return"review";const o=le(n.state);return o==="error"?"failed":o==="stopped"?"paused":o==="stale"?"queued":Ke.has(t)?t:n.blockers.length>0?"blocked":t||"unknown"}function Ze(n,t,b){var m;const o=[((m=n.blockerDiagnostics)==null?void 0:m.reason)??null,n.blockerReason??null,...n.blockers,t==="blocked"||t==="failed"||t==="handoff"?b:null].map(j=>typeof j=="string"?j.trim():"").filter(j=>j.length>0);return o.length>0?o.find(L=>!Xe(L))??o[0]:t==="handoff"?"Waiting for handoff acceptance by the next agent.":t==="blocked"?"Blocked without an explicit reason from runtime.":t==="failed"?"Run failed without explicit error details.":null}function De(n){return n==="completed"?"border-lime/25 bg-lime/[0.08] text-lime":n==="needs_attention"?"border-amber-400/30 bg-amber-400/10 text-amber-200":n==="failed"?"border-red-400/30 bg-red-500/10 text-red-200":n==="in_progress"?"border-teal-400/30 bg-teal-400/10 text-teal-200":"border-strong bg-white/[0.04] text-secondary"}const dt=w.memo(function({session:t,activity:b,initiatives:o=[],sliceRuns:m=[],onOpenActivityItem:j,onContinueHighestPriority:L,onDispatchSession:F,onPauseSession:O,onResumeSession:V,onCancelSession:G,onCreateCheckpoint:K,onRollbackSession:H,onStartInitiative:et,onStartWorkstream:tt,initialInterventionDraft:k=null,onSubmitIntervention:ie}){var he,be,ge;const[x,de]=w.useState(null),[J,A]=w.useState(null),[M,oe]=w.useState(!1),[D,W]=w.useState(""),{enqueue:ce,ToastRenderer:ve}=Ve();w.useEffect(()=>{if(!t){W("");return}if(k!=null&&k.text){W(k.text);return}W("")},[k==null?void 0:k.text,t==null?void 0:t.id]);const B=w.useMemo(()=>{var d,g,f,i,u;if(!t)return new Set;const r=new Set;return(d=t.runId)!=null&&d.trim()&&r.add(t.runId.trim()),(g=t.id)!=null&&g.trim()&&r.add(t.id.trim()),(u=(i=(f=t.blockerDiagnostics)==null?void 0:f.context)==null?void 0:i.sliceRunId)!=null&&u.trim()&&r.add(t.blockerDiagnostics.context.sliceRunId.trim()),r},[t]),C=w.useMemo(()=>t?B.size===0?[]:b.filter(r=>{const d=Qe(r);return!!(d&&B.has(d))}).sort((r,d)=>Date.parse(d.timestamp)-Date.parse(r.timestamp)).slice(0,12):[],[b,t,B]),s=w.useMemo(()=>{var f,i;if(!t||!Array.isArray(m)||m.length===0)return null;const r=((f=t.initiativeId)==null?void 0:f.trim())??"",d=((i=t.workstreamId)==null?void 0:i.trim())??"",g=m.filter(u=>{var ne,fe;const I=((ne=u.sliceRunId)==null?void 0:ne.trim())??"",E=((fe=u.runId)==null?void 0:fe.trim())??"";if(I&&B.has(I)||E&&B.has(E))return!0;if(!d||!P(u.workstreamIds,u.workstreamId).includes(d))return!1;if(!r)return!0;const Y=P(u.initiativeIds,u.initiativeId);return!(Y.length>0&&!Y.includes(r))});return g.length===0?null:[...g].sort((u,I)=>{const E=Date.parse(u.updatedAt??u.lastEventAt??u.startedAt??""),ae=Date.parse(I.updatedAt??I.lastEventAt??I.startedAt??""),Y=Number.isFinite(E)?E:0;return(Number.isFinite(ae)?ae:0)-Y})[0]},[t,B,m]),ee=w.useMemo(()=>{var f;if(!t)return[];const r=[],d=t.initiativeId??t.groupId;if(d){const i=o.find(u=>u.id===d);i?r.push({label:"Initiative",value:i.name}):t.groupLabel&&t.groupLabel.trim().length>0?r.push({label:"Initiative",value:t.groupLabel}):T(d)&&r.push({label:"Initiative",value:N(d)})}if(t.workstreamId){let i=null;for(const u of o){const I=(f=u.workstreams)==null?void 0:f.find(E=>E.id===t.workstreamId);if(I){i=I.name;break}}!i&&T(t.workstreamId)?i=N(t.workstreamId):!i&&!Ge.test(t.workstreamId)&&(i=t.workstreamId),i&&r.push({label:"Workstream",value:i})}const g=t.phase??null;if(g){const i=String(g);r.push({label:"Milestone",value:T(i)?N(i):i})}return t.title&&r.push({label:"Task",value:t.title}),r},[o,t]),R=w.useMemo(()=>{var f,i;if(!t)return null;const r=((f=C[0])==null?void 0:f.summary)??((i=C[0])==null?void 0:i.description)??null,g=t.lastEventSummary??r??null;return g&&g.trim().length>0?g.trim():null},[C,t]),ue=w.useMemo(()=>{var r;return t?ye(t.agentName,t.title,t.lastEventSummary,R,(r=C[0])==null?void 0:r.metadata):ye()},[C,t,R]),_=async(r,d,g)=>{if(!(!g||x)){de(r),A(null);try{await g(),A(`${d} requested.`)}catch(f){A(f instanceof Error?f.message:`${d} failed.`)}finally{de(null)}}};if(!t)return e.jsxs(we,{className:"flex h-full min-h-0 flex-col overflow-hidden card-enter",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-subtle px-4 py-3.5",children:[e.jsx("h2",{className:"text-heading font-semibold text-white",children:"Session Detail"}),e.jsx("button",{onClick:()=>oe(r=>!r),className:"text-muted transition-colors hover:text-primary","aria-label":M?"Expand session detail":"Collapse session detail",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:S("transition-transform",M?"-rotate-90":"rotate-0"),children:e.jsx("path",{d:"m6 9 6 6 6-6"})})})]}),e.jsx("div",{className:S("transition-all",M?"max-h-0 overflow-hidden":"min-h-0 flex-1"),children:e.jsxs("div",{className:"h-full min-h-0 space-y-2 overflow-y-auto p-4 text-body text-secondary",children:[e.jsx("p",{children:"Select a session to inspect summary, breadcrumbs, blockers, and recent messages."}),e.jsx("button",{onClick:()=>_("continue-priority","Continue highest priority",L),disabled:!L||!!x,className:"rounded-md border border-strong bg-white/[0.04] px-3 py-1.5 text-caption text-primary transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:x==="continue-priority"?"Dispatching…":"Continue highest priority"}),J&&e.jsx("p",{className:"text-caption text-secondary",children:J})]})})]});const U=t.progress===null?null:Math.round(t.progress),v=Ye(t),p=C[0]??null,te=(s==null?void 0:s.blockingDecisionCount)??0,Ne=Math.max(0,((s==null?void 0:s.decisionCount)??0)-te),c=qe({sessionStatus:t.status,sessionPhase:t.phase??null,sessionState:t.state??null,sliceStatus:(s==null?void 0:s.status)??null,activityType:(p==null?void 0:p.type)??null,activityStatus:(typeof(p==null?void 0:p.state)=="string"&&p.state.trim().length>0?p.state:null)??(typeof(p==null?void 0:p.phase)=="string"&&p.phase.trim().length>0?p.phase:null)??(s==null?void 0:s.runtimeState)??null,stopReason:t.blockerReason??((he=t.blockerDiagnostics)==null?void 0:he.reason)??((s==null?void 0:s.status)==="failed"?"error":null),decisionRequired:((p==null?void 0:p.decisionRequired)??!1)||te>0,blockingDecisionCount:te,nonBlockingDecisionCount:Ne,blockerCount:t.blockers.length,blockerReason:t.blockerReason??((be=t.blockerDiagnostics)==null?void 0:be.reason)??null}),re=Ze(t,v,R),ke=v==="handoff"?"Handoff":v==="blocked"?"Blocker reason":v==="failed"?"Failure reason":"Status note",Ie=c.status==="in_progress"&&["running","active","queued","pending","working","in_progress","planning","review"].includes(v),Ae=c.status==="needs_attention"&&["paused","blocked","queued","pending"].includes(v),Ce=!["completed","archived","cancelled"].includes(v),Re=!["archived","cancelled"].includes(v),Te=c.label,Se=De(c.status),me=["running","active","working","in_progress","planning","review"].includes(v),_e=c.status!=="in_progress"&&!me,Ee=c.tone==="critical"?Z.red:c.tone==="warning"?Z.amber:c.tone==="positive"?Z.lime:Z.teal,Le=U!==null&&U>=100&&c.status!=="completed"?"Terminal state":"Progress",Me=c.tone==="critical"?"border-red-400/25 bg-red-500/10":c.tone==="warning"?"border-amber-400/25 bg-amber-500/10":c.tone==="positive"?"border-lime/22 bg-lime/[0.08]":"border-subtle bg-white/[0.02]",a=t.blockerDiagnostics??null,l=(a==null?void 0:a.context)??null,se=[y(a==null?void 0:a.source)?`Source: ${a.source.trim()}`:null,y(a==null?void 0:a.errorCode)?`Code: ${a.errorCode.trim()}`:null,y(a==null?void 0:a.errorCategory)?`Category: ${a.errorCategory.trim()}`:null,(a==null?void 0:a.retryable)===!0?"Retryable: yes":(a==null?void 0:a.retryable)===!1?"Retryable: no":null].filter(r=>!!r),h=[];l&&(Array.isArray(l.initiativeIds)&&l.initiativeIds.length>0?h.push({label:"Initiatives",value:z(l.initiativeIds.map(r=>T(r)?N(r):r),4)}):y(l.initiativeId)&&h.push({label:"Initiative",value:ze("Initiative",l.initiativeId.trim())}),y(l.workstreamTitle)?h.push({label:"Workstream",value:l.workstreamTitle.trim()}):Array.isArray(l.workstreamIds)&&l.workstreamIds.length>0?h.push({label:"Workstreams",value:z(l.workstreamIds,4)}):y(l.workstreamId)&&h.push({label:"Workstream",value:l.workstreamId.trim()}),y(l.sliceRunId)&&h.push({label:"Slice run",value:N(l.sliceRunId.trim())}),y(l.parallelMode)&&h.push({label:"Mode",value:l.parallelMode.trim().toUpperCase()}),Array.isArray(l.taskIds)&&l.taskIds.length>0&&h.push({label:"Tasks",value:z(l.taskIds.map(r=>T(r)?N(r):r))}),Array.isArray(l.milestoneIds)&&l.milestoneIds.length>0&&h.push({label:"Milestones",value:z(l.milestoneIds.map(r=>T(r)?N(r):r))}),Array.isArray(l.iwmtIds)&&l.iwmtIds.length>0?h.push({label:"Scope IDs",value:z(l.iwmtIds.map(r=>T(r)?N(r):r),4)}):y(l.iwmtId)&&h.push({label:"Scope ID",value:T(l.iwmtId.trim())?N(l.iwmtId.trim()):l.iwmtId.trim()}),y(l.logPath)&&h.push({label:"Log path",value:je(l.logPath.trim())}),y(l.outputPath)&&h.push({label:"Output path",value:je(l.outputPath.trim())}));const xe=(v==="blocked"||v==="failed")&&!!(a&&(y(a.reason)||se.length>0||h.length>0||Array.isArray(a.suggestedActions)&&a.suggestedActions.length>0)),X=y(re)?re:null,Be=X!==null&&!(R&&(X===R||R.includes(X)))&&!xe,Ue=w.useCallback(()=>{!G||!t||(A("Session will be cancelled…"),ce({message:`Cancelled "${t.title}"`,onCommit:async()=>{try{await G(t),A("Session cancelled.")}catch(r){A(r instanceof Error?r.message:"Cancel failed.")}},onUndo:()=>{A(null)}}))},[G,t,ce]),We=[{label:"Started",value:t.startedAt?q(t.startedAt):"—"},{label:"Updated",value:t.updatedAt?q(t.updatedAt):"—"},...t.eta?[{label:"ETA",value:t.eta}]:[],...t.checkpointCount?[{label:"Checkpoints",value:String(t.checkpointCount)}]:[]],pe=s?s.status.replace(/_/g," "):null,$=P(s==null?void 0:s.initiativeIds,(s==null?void 0:s.initiativeId)??null),Q=P(s==null?void 0:s.workstreamIds,(s==null?void 0:s.workstreamId)??null);P(s==null?void 0:s.iwmtIds,(s==null?void 0:s.iwmtId)??null);const $e=$[0]?((ge=o.find(r=>r.id===$[0]))==null?void 0:ge.name)??$[0]:null;return e.jsxs(we,{className:"flex h-full min-h-0 flex-col overflow-hidden card-enter",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-subtle px-4 py-3.5",children:[e.jsx("h2",{className:"text-heading font-semibold text-white",children:"Session Detail"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:S("chip text-caption uppercase tracking-[0.14em]",Se),children:Te}),e.jsx("button",{onClick:()=>oe(r=>!r),className:"text-muted transition-colors hover:text-primary","aria-label":M?"Expand session detail":"Collapse session detail",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:S("transition-transform",M?"-rotate-90":"rotate-0"),children:e.jsx("path",{d:"m6 9 6 6 6-6"})})})]})]}),e.jsx("div",{className:S("transition-all",M?"max-h-0 overflow-hidden":"min-h-0 flex-1"),children:e.jsxs("div",{className:"h-full min-h-0 space-y-4 overflow-y-auto p-4",children:[e.jsxs("div",{className:"rounded-xl border border-subtle bg-white/[0.02] p-3",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Pe,{provider:ue.id,size:"sm"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-body font-semibold text-white",children:Fe(t.title)}),e.jsxs("p",{className:"mt-1 text-caption text-secondary",children:[t.agentName??"OrgX"," · ",ue.label]})]})]}),ee.length>0&&e.jsxs("div",{className:"mt-3",children:[e.jsx("p",{className:"mb-1 text-micro uppercase tracking-[0.16em] text-muted",children:"Context"}),e.jsx("div",{className:"flex flex-wrap items-center gap-1.5 text-caption",children:ee.map((r,d)=>e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{className:"rounded-full border border-strong bg-white/[0.02] px-2 py-0.5 text-secondary",children:r.value}),d<ee.length-1&&e.jsx("span",{className:"text-caption text-muted",children:"›"})]},`${r.label}-${r.value}`))})]}),R&&e.jsxs("div",{className:"mt-3 rounded-lg border border-subtle bg-white/[0.02] px-3 py-2",children:[e.jsx("p",{className:"mb-1 text-micro uppercase tracking-[0.16em] text-muted",children:"Summary"}),e.jsx(Oe,{text:R,mode:"block"})]}),e.jsxs("div",{className:S("mt-3 rounded-lg border px-3 py-2",Me),children:[e.jsx("p",{className:"mb-1 text-micro uppercase tracking-[0.16em] text-muted",children:c.label}),e.jsx("p",{className:"text-body text-secondary",children:c.sentence}),c.nextAction&&e.jsxs("p",{className:"mt-1 text-caption text-secondary",children:["Next: ",c.nextAction]})]}),Be&&e.jsxs("div",{className:"mt-3 rounded-lg border border-subtle bg-white/[0.02] px-3 py-2",children:[e.jsx("p",{className:"mb-1 text-micro uppercase tracking-[0.16em] text-muted",children:ke}),e.jsx("p",{className:"text-body text-secondary",children:X})]}),xe&&e.jsxs("div",{className:"mt-3 rounded-lg border border-red-500/25 bg-red-500/10 px-3 py-2.5",children:[e.jsx("p",{className:"mb-1 text-micro uppercase tracking-[0.16em] text-red-200/75",children:"Why blocked"}),e.jsx("p",{className:"text-body text-red-100/90",children:(a==null?void 0:a.reason)??re??"Runtime marked this run as blocked without details."}),se.length>0&&e.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:se.map(r=>e.jsx("span",{className:"rounded-full border border-red-300/25 bg-red-500/10 px-2 py-0.5 text-micro text-red-100/85",children:r},r))}),h.length>0&&e.jsxs("div",{className:"mt-2 rounded-md border border-red-300/20 bg-black/15 p-2.5",children:[e.jsx("p",{className:"mb-1 text-micro uppercase tracking-[0.14em] text-red-200/65",children:"Associated context"}),e.jsx("dl",{className:"grid grid-cols-1 gap-1.5 text-caption text-red-100/85",children:h.map(r=>e.jsxs("div",{className:"grid grid-cols-[86px_1fr] gap-2",children:[e.jsx("dt",{className:"text-red-200/70",children:r.label}),e.jsx("dd",{className:"break-all text-red-50/95",children:r.value})]},r.label))})]}),Array.isArray(a==null?void 0:a.suggestedActions)&&a.suggestedActions.length>0&&e.jsxs("div",{className:"mt-2",children:[e.jsx("p",{className:"mb-1 text-micro uppercase tracking-[0.14em] text-red-200/65",children:"Suggested actions"}),e.jsx("ul",{className:"space-y-1 text-caption text-red-100/85",children:a.suggestedActions.map(r=>e.jsxs("li",{children:["• ",r]},r))})]}),y(a==null?void 0:a.eventTimestamp)&&e.jsxs("p",{className:"mt-2 text-micro text-red-200/60",children:["Last blocker event: ",new Date(a.eventTimestamp).toLocaleString()," ·"," ",q(a.eventTimestamp)]})]})]}),s&&e.jsxs("div",{className:"rounded-xl border border-subtle bg-white/[0.02] p-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("h3",{className:"text-caption uppercase tracking-[0.12em] text-secondary",children:"Slice scope"}),pe?e.jsx("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-2 py-0.5 text-micro font-semibold uppercase tracking-[0.08em] text-secondary",children:pe}):null]}),s.statusExplainer?e.jsx("p",{className:"mt-2 text-caption text-secondary",children:s.statusExplainer}):null,e.jsxs("dl",{className:"mt-2 grid grid-cols-2 gap-2 text-caption text-secondary",children:[e.jsxs("div",{children:[e.jsx("dt",{className:"text-muted",children:"Initiative"}),e.jsx("dd",{className:"text-body font-semibold text-white",children:$e??"—"})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-muted",children:"Workstream"}),e.jsx("dd",{className:"text-body font-semibold text-white",children:s.workstreamTitle??(Q[0]?N(Q[0]):"—")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-muted",children:"Run"}),e.jsx("dd",{className:"break-all text-body font-semibold text-white",children:N(s.runId??s.sliceRunId)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-muted",children:"Updated"}),e.jsx("dd",{className:"text-body font-semibold text-white",children:s.updatedAt?q(s.updatedAt):"—"})]})]}),e.jsxs("div",{className:"mt-2 flex flex-wrap gap-1.5 text-micro",children:[e.jsxs("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-2 py-0.5 text-secondary",children:["Tasks ",s.taskIds.length]}),e.jsxs("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-2 py-0.5 text-secondary",children:["Milestones ",s.milestoneIds.length]}),e.jsxs("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-2 py-0.5 text-secondary",children:["Artifacts ",s.artifactCount]}),e.jsxs("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-2 py-0.5 text-secondary",children:["Needs input ",s.blockingDecisionCount]}),$.length>1?e.jsxs("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-2 py-0.5 text-secondary",children:["+",$.length-1," initiatives"]}):null,Q.length>1?e.jsxs("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-2 py-0.5 text-secondary",children:["+",Q.length-1," workstreams"]}):null]}),s.taskIds.length>0?e.jsxs("p",{className:"mt-2 text-micro text-secondary",children:["Tasks: ",s.taskIds.length]}):null]}),e.jsxs("div",{className:"rounded-xl border border-subtle bg-white/[0.02] p-3",children:[U!==null&&e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between text-caption text-secondary",children:[e.jsx("span",{children:Le}),e.jsxs("span",{className:"text-primary",children:[U,"%"]})]}),e.jsx("div",{className:"h-2 rounded-full bg-white/[0.08]",children:e.jsx("div",{className:S("h-2 rounded-full transition-all duration-500",me&&"live-pulse"),style:{width:`${U}%`,background:Ee}})})]}),e.jsx("dl",{className:S("grid grid-cols-2 gap-3 text-caption text-secondary",U!==null?"mt-3":""),children:We.map(r=>e.jsxs("div",{children:[e.jsx("dt",{className:"text-muted",children:r.label}),e.jsx("dd",{className:"text-body font-semibold text-white",children:r.value})]},r.label))})]}),e.jsxs("div",{className:"rounded-xl border border-subtle bg-white/[0.02] p-3",children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{onClick:()=>_("dispatch-session","Session started",()=>F==null?void 0:F(t)),disabled:!F||!!x||!_e,className:"rounded-md border border-lime/25 bg-lime/10 px-3 py-2 text-caption font-semibold text-lime transition-colors hover:bg-lime/20 disabled:opacity-45",children:x==="dispatch-session"?"Starting…":c.status==="completed"?"Restart":"Start"}),Ie&&e.jsx("button",{onClick:()=>_("pause-session","Session paused",()=>O==null?void 0:O(t)),disabled:!O||!!x,className:"rounded-md border border-strong bg-white/[0.02] px-3 py-2 text-caption text-secondary transition-colors hover:bg-white/[0.06] hover:text-white disabled:opacity-45",children:x==="pause-session"?"Pausing…":"Pause"}),Ae&&e.jsx("button",{onClick:()=>_("resume-session","Session resumed",()=>V==null?void 0:V(t)),disabled:!V||!!x,className:"rounded-md border border-strong bg-white/[0.02] px-3 py-2 text-caption text-secondary transition-colors hover:bg-white/[0.06] hover:text-white disabled:opacity-45",children:x==="resume-session"?"Resuming…":"Resume"}),e.jsx("button",{onClick:()=>_("checkpoint-session","Progress saved",()=>K==null?void 0:K(t)),disabled:!K||!!x,className:"rounded-md border border-strong bg-white/[0.02] px-3 py-2 text-caption text-secondary transition-colors hover:bg-white/[0.06] hover:text-white disabled:opacity-45",children:x==="checkpoint-session"?"Saving…":"Save progress"}),Re&&e.jsx("button",{onClick:()=>_("rollback-session","Undo requested",()=>H==null?void 0:H(t)),disabled:!H||!!x,className:"rounded-md border border-strong bg-white/[0.02] px-3 py-2 text-caption text-secondary transition-colors hover:bg-white/[0.06] hover:text-white disabled:opacity-45",children:x==="rollback-session"?"Undoing…":"Undo last step"})]}),ie&&e.jsxs("div",{className:"mt-3 rounded-lg border border-white/[0.08] bg-black/[0.18] px-3 py-2.5",children:[e.jsx("p",{className:"mb-2 text-micro uppercase tracking-[0.16em] text-muted",children:"Intervene"}),e.jsx("textarea",{value:D,onChange:r=>W(r.target.value),placeholder:"Share guidance for this run...",className:"min-h-[84px] w-full resize-y rounded-lg border border-white/[0.10] bg-white/[0.03] px-3 py-2 text-body text-bright outline-none placeholder:text-faint focus:border-white/20"}),e.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-micro text-secondary",children:"Visible to agents and collaborators."}),e.jsx("button",{type:"button",onClick:()=>{const r=D.trim();if(!r){A("Intervention note cannot be empty.");return}_("intervene-note","Intervention sent",async()=>{await ie({session:t,workstreamId:(k==null?void 0:k.workstreamId)??t.workstreamId??null,text:r}),W("")})},disabled:!!x||D.trim().length===0,className:"rounded-md border border-strong bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:x==="intervene-note"?"Sending…":"Send intervention"})]})]}),Ce&&G&&e.jsx("div",{className:"mt-3 border-t border-subtle pt-3",children:e.jsx("button",{onClick:Ue,disabled:!!x,className:"text-caption text-secondary transition-colors hover:text-red-300 disabled:opacity-45",children:"Cancel session…"})})]}),J&&e.jsx("p",{className:"rounded-md border border-white/[0.08] bg-white/[0.02] px-2.5 py-1.5 text-caption text-secondary",children:J}),t.blockers.length>0&&e.jsxs("div",{className:"rounded-xl border border-red-500/30 bg-red-500/10 p-3",children:[e.jsx("h3",{className:"mb-1 text-caption uppercase tracking-[0.12em] text-red-200/70",children:"Blockers"}),e.jsx("ul",{className:"space-y-1 text-body text-red-100/90",children:t.blockers.map(r=>e.jsxs("li",{children:["• ",r]},r))})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"mb-2 text-caption uppercase tracking-[0.16em] text-secondary",children:"Recent Messages"}),C.length===0&&e.jsx("p",{className:"text-body text-secondary",children:"No recent messages for this run."}),e.jsx("div",{className:"space-y-2",children:C.map(r=>e.jsxs("article",{className:"rounded-lg border border-subtle bg-white/[0.02] px-2.5 py-2",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsx("p",{className:"min-w-0 flex-1 text-caption text-bright",children:r.title}),j&&e.jsx("button",{type:"button",onClick:()=>j(r),className:"flex-shrink-0 rounded-full border border-strong bg-white/[0.03] px-2.5 py-0.5 text-micro font-semibold text-secondary transition-colors hover:bg-white/[0.08] hover:text-primary",children:"Open"})]}),(r.summary||r.description)&&e.jsx("p",{className:"mt-0.5 line-clamp-2 text-caption text-secondary",children:r.summary??r.description}),e.jsxs("p",{className:"mt-1 text-micro text-muted",children:[new Date(r.timestamp).toLocaleString()," · ",q(r.timestamp)]})]},r.id))})]})]})}),e.jsx(ve,{})]})});export{dt as SessionInspector};
1
+ import{r as w,j as e}from"./cNrhgGc1.js";import{y as T,z as N,F as ye,P as we,w as S,G as qe,d as Z,H as ze,J as je,K as q,L as Pe,x as Fe,M as Oe}from"./Cn07669c.js";import{u as Ve}from"./CYchPSem.js";import"./C-KIc3Wc.js";import"./BJgZIVUQ.js";import"./CxQ08qFN.js";const Ge=/^[0-9a-f-]{20,}$/i,Ke=new Set(["running","active","queued","pending","in_progress","working","planning","handoff","review"]),He=new Set(["agent execution failed","execution failed","run failed","failed"]);function y(n){return typeof n=="string"&&n.trim().length>0}function le(n){return(n??"").trim().toLowerCase()}function Je(n){return(n??"").trim().replace(/\s+/g," ").toLowerCase()}function Xe(n){return He.has(Je(n))}function z(n,t=3){return n.length<=t?n.join(", "):`${n.slice(0,t).join(", ")} +${n.length-t} more`}function P(n,t){const b=[],o=m=>{if(typeof m!="string")return;const j=m.trim();j&&(b.some(L=>L.toLowerCase()===j.toLowerCase())||b.push(j))};if(Array.isArray(n))for(const m of n)o(m);return o(t??null),b}function Qe(n){if(n.runId&&n.runId.trim().length>0)return n.runId.trim();const t=n.metadata;if(!t)return null;const b=["slice_run_id","sliceRunId","runId","run_id","correlation_id","correlationId","sessionId","session_id","agentRunId"];for(const o of b){const m=t[o];if(typeof m=="string"&&m.trim().length>0)return m.trim()}return null}function Ye(n){const t=le(n.status);if(t==="blocked"||t==="failed"||t==="completed"||t==="cancelled")return t;const b=le(n.phase);if(b==="blocked")return"blocked";if(b==="handoff")return"handoff";if(b==="completed")return"completed";if(b==="review")return"review";const o=le(n.state);return o==="error"?"failed":o==="stopped"?"paused":o==="stale"?"queued":Ke.has(t)?t:n.blockers.length>0?"blocked":t||"unknown"}function Ze(n,t,b){var m;const o=[((m=n.blockerDiagnostics)==null?void 0:m.reason)??null,n.blockerReason??null,...n.blockers,t==="blocked"||t==="failed"||t==="handoff"?b:null].map(j=>typeof j=="string"?j.trim():"").filter(j=>j.length>0);return o.length>0?o.find(L=>!Xe(L))??o[0]:t==="handoff"?"Waiting for handoff acceptance by the next agent.":t==="blocked"?"Blocked without an explicit reason from runtime.":t==="failed"?"Run failed without explicit error details.":null}function De(n){return n==="completed"?"border-lime/25 bg-lime/[0.08] text-lime":n==="needs_attention"?"border-amber-400/30 bg-amber-400/10 text-amber-200":n==="failed"?"border-red-400/30 bg-red-500/10 text-red-200":n==="in_progress"?"border-teal-400/30 bg-teal-400/10 text-teal-200":"border-strong bg-white/[0.04] text-secondary"}const dt=w.memo(function({session:t,activity:b,initiatives:o=[],sliceRuns:m=[],onOpenActivityItem:j,onContinueHighestPriority:L,onDispatchSession:F,onPauseSession:O,onResumeSession:V,onCancelSession:G,onCreateCheckpoint:K,onRollbackSession:H,onStartInitiative:et,onStartWorkstream:tt,initialInterventionDraft:k=null,onSubmitIntervention:ie}){var he,be,ge;const[x,de]=w.useState(null),[J,A]=w.useState(null),[M,oe]=w.useState(!1),[D,W]=w.useState(""),{enqueue:ce,ToastRenderer:ve}=Ve();w.useEffect(()=>{if(!t){W("");return}if(k!=null&&k.text){W(k.text);return}W("")},[k==null?void 0:k.text,t==null?void 0:t.id]);const B=w.useMemo(()=>{var d,g,f,i,u;if(!t)return new Set;const r=new Set;return(d=t.runId)!=null&&d.trim()&&r.add(t.runId.trim()),(g=t.id)!=null&&g.trim()&&r.add(t.id.trim()),(u=(i=(f=t.blockerDiagnostics)==null?void 0:f.context)==null?void 0:i.sliceRunId)!=null&&u.trim()&&r.add(t.blockerDiagnostics.context.sliceRunId.trim()),r},[t]),C=w.useMemo(()=>t?B.size===0?[]:b.filter(r=>{const d=Qe(r);return!!(d&&B.has(d))}).sort((r,d)=>Date.parse(d.timestamp)-Date.parse(r.timestamp)).slice(0,12):[],[b,t,B]),s=w.useMemo(()=>{var f,i;if(!t||!Array.isArray(m)||m.length===0)return null;const r=((f=t.initiativeId)==null?void 0:f.trim())??"",d=((i=t.workstreamId)==null?void 0:i.trim())??"",g=m.filter(u=>{var ne,fe;const I=((ne=u.sliceRunId)==null?void 0:ne.trim())??"",E=((fe=u.runId)==null?void 0:fe.trim())??"";if(I&&B.has(I)||E&&B.has(E))return!0;if(!d||!P(u.workstreamIds,u.workstreamId).includes(d))return!1;if(!r)return!0;const Y=P(u.initiativeIds,u.initiativeId);return!(Y.length>0&&!Y.includes(r))});return g.length===0?null:[...g].sort((u,I)=>{const E=Date.parse(u.updatedAt??u.lastEventAt??u.startedAt??""),ae=Date.parse(I.updatedAt??I.lastEventAt??I.startedAt??""),Y=Number.isFinite(E)?E:0;return(Number.isFinite(ae)?ae:0)-Y})[0]},[t,B,m]),ee=w.useMemo(()=>{var f;if(!t)return[];const r=[],d=t.initiativeId??t.groupId;if(d){const i=o.find(u=>u.id===d);i?r.push({label:"Initiative",value:i.name}):t.groupLabel&&t.groupLabel.trim().length>0?r.push({label:"Initiative",value:t.groupLabel}):T(d)&&r.push({label:"Initiative",value:N(d)})}if(t.workstreamId){let i=null;for(const u of o){const I=(f=u.workstreams)==null?void 0:f.find(E=>E.id===t.workstreamId);if(I){i=I.name;break}}!i&&T(t.workstreamId)?i=N(t.workstreamId):!i&&!Ge.test(t.workstreamId)&&(i=t.workstreamId),i&&r.push({label:"Workstream",value:i})}const g=t.phase??null;if(g){const i=String(g);r.push({label:"Milestone",value:T(i)?N(i):i})}return t.title&&r.push({label:"Task",value:t.title}),r},[o,t]),R=w.useMemo(()=>{var f,i;if(!t)return null;const r=((f=C[0])==null?void 0:f.summary)??((i=C[0])==null?void 0:i.description)??null,g=t.lastEventSummary??r??null;return g&&g.trim().length>0?g.trim():null},[C,t]),ue=w.useMemo(()=>{var r;return t?ye(t.agentName,t.title,t.lastEventSummary,R,(r=C[0])==null?void 0:r.metadata):ye()},[C,t,R]),_=async(r,d,g)=>{if(!(!g||x)){de(r),A(null);try{await g(),A(`${d} requested.`)}catch(f){A(f instanceof Error?f.message:`${d} failed.`)}finally{de(null)}}};if(!t)return e.jsxs(we,{className:"flex h-full min-h-0 flex-col overflow-hidden card-enter",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-subtle px-4 py-3.5",children:[e.jsx("h2",{className:"text-heading font-semibold text-white",children:"Session Detail"}),e.jsx("button",{onClick:()=>oe(r=>!r),className:"text-muted transition-colors hover:text-primary","aria-label":M?"Expand session detail":"Collapse session detail",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:S("transition-transform",M?"-rotate-90":"rotate-0"),children:e.jsx("path",{d:"m6 9 6 6 6-6"})})})]}),e.jsx("div",{className:S("transition-all",M?"max-h-0 overflow-hidden":"min-h-0 flex-1"),children:e.jsxs("div",{className:"h-full min-h-0 space-y-2 overflow-y-auto p-4 text-body text-secondary",children:[e.jsx("p",{children:"Select a session to inspect summary, breadcrumbs, blockers, and recent messages."}),e.jsx("button",{onClick:()=>_("continue-priority","Continue highest priority",L),disabled:!L||!!x,className:"rounded-md border border-strong bg-white/[0.04] px-3 py-1.5 text-caption text-primary transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:x==="continue-priority"?"Dispatching…":"Continue highest priority"}),J&&e.jsx("p",{className:"text-caption text-secondary",children:J})]})})]});const U=t.progress===null?null:Math.round(t.progress),v=Ye(t),p=C[0]??null,te=(s==null?void 0:s.blockingDecisionCount)??0,Ne=Math.max(0,((s==null?void 0:s.decisionCount)??0)-te),c=qe({sessionStatus:t.status,sessionPhase:t.phase??null,sessionState:t.state??null,sliceStatus:(s==null?void 0:s.status)??null,activityType:(p==null?void 0:p.type)??null,activityStatus:(typeof(p==null?void 0:p.state)=="string"&&p.state.trim().length>0?p.state:null)??(typeof(p==null?void 0:p.phase)=="string"&&p.phase.trim().length>0?p.phase:null)??(s==null?void 0:s.runtimeState)??null,stopReason:t.blockerReason??((he=t.blockerDiagnostics)==null?void 0:he.reason)??((s==null?void 0:s.status)==="failed"?"error":null),decisionRequired:((p==null?void 0:p.decisionRequired)??!1)||te>0,blockingDecisionCount:te,nonBlockingDecisionCount:Ne,blockerCount:t.blockers.length,blockerReason:t.blockerReason??((be=t.blockerDiagnostics)==null?void 0:be.reason)??null}),re=Ze(t,v,R),ke=v==="handoff"?"Handoff":v==="blocked"?"Blocker reason":v==="failed"?"Failure reason":"Status note",Ie=c.status==="in_progress"&&["running","active","queued","pending","working","in_progress","planning","review"].includes(v),Ae=c.status==="needs_attention"&&["paused","blocked","queued","pending"].includes(v),Ce=!["completed","archived","cancelled"].includes(v),Re=!["archived","cancelled"].includes(v),Te=c.label,Se=De(c.status),me=["running","active","working","in_progress","planning","review"].includes(v),_e=c.status!=="in_progress"&&!me,Ee=c.tone==="critical"?Z.red:c.tone==="warning"?Z.amber:c.tone==="positive"?Z.lime:Z.teal,Le=U!==null&&U>=100&&c.status!=="completed"?"Terminal state":"Progress",Me=c.tone==="critical"?"border-red-400/25 bg-red-500/10":c.tone==="warning"?"border-amber-400/25 bg-amber-500/10":c.tone==="positive"?"border-lime/22 bg-lime/[0.08]":"border-subtle bg-white/[0.02]",a=t.blockerDiagnostics??null,l=(a==null?void 0:a.context)??null,se=[y(a==null?void 0:a.source)?`Source: ${a.source.trim()}`:null,y(a==null?void 0:a.errorCode)?`Code: ${a.errorCode.trim()}`:null,y(a==null?void 0:a.errorCategory)?`Category: ${a.errorCategory.trim()}`:null,(a==null?void 0:a.retryable)===!0?"Retryable: yes":(a==null?void 0:a.retryable)===!1?"Retryable: no":null].filter(r=>!!r),h=[];l&&(Array.isArray(l.initiativeIds)&&l.initiativeIds.length>0?h.push({label:"Initiatives",value:z(l.initiativeIds.map(r=>T(r)?N(r):r),4)}):y(l.initiativeId)&&h.push({label:"Initiative",value:ze("Initiative",l.initiativeId.trim())}),y(l.workstreamTitle)?h.push({label:"Workstream",value:l.workstreamTitle.trim()}):Array.isArray(l.workstreamIds)&&l.workstreamIds.length>0?h.push({label:"Workstreams",value:z(l.workstreamIds,4)}):y(l.workstreamId)&&h.push({label:"Workstream",value:l.workstreamId.trim()}),y(l.sliceRunId)&&h.push({label:"Slice run",value:N(l.sliceRunId.trim())}),y(l.parallelMode)&&h.push({label:"Mode",value:l.parallelMode.trim().toUpperCase()}),Array.isArray(l.taskIds)&&l.taskIds.length>0&&h.push({label:"Tasks",value:z(l.taskIds.map(r=>T(r)?N(r):r))}),Array.isArray(l.milestoneIds)&&l.milestoneIds.length>0&&h.push({label:"Milestones",value:z(l.milestoneIds.map(r=>T(r)?N(r):r))}),Array.isArray(l.iwmtIds)&&l.iwmtIds.length>0?h.push({label:"Scope IDs",value:z(l.iwmtIds.map(r=>T(r)?N(r):r),4)}):y(l.iwmtId)&&h.push({label:"Scope ID",value:T(l.iwmtId.trim())?N(l.iwmtId.trim()):l.iwmtId.trim()}),y(l.logPath)&&h.push({label:"Log path",value:je(l.logPath.trim())}),y(l.outputPath)&&h.push({label:"Output path",value:je(l.outputPath.trim())}));const xe=(v==="blocked"||v==="failed")&&!!(a&&(y(a.reason)||se.length>0||h.length>0||Array.isArray(a.suggestedActions)&&a.suggestedActions.length>0)),X=y(re)?re:null,Be=X!==null&&!(R&&(X===R||R.includes(X)))&&!xe,Ue=w.useCallback(()=>{!G||!t||(A("Session will be cancelled…"),ce({message:`Cancelled "${t.title}"`,onCommit:async()=>{try{await G(t),A("Session cancelled.")}catch(r){A(r instanceof Error?r.message:"Cancel failed.")}},onUndo:()=>{A(null)}}))},[G,t,ce]),We=[{label:"Started",value:t.startedAt?q(t.startedAt):"—"},{label:"Updated",value:t.updatedAt?q(t.updatedAt):"—"},...t.eta?[{label:"ETA",value:t.eta}]:[],...t.checkpointCount?[{label:"Checkpoints",value:String(t.checkpointCount)}]:[]],pe=s?s.status.replace(/_/g," "):null,$=P(s==null?void 0:s.initiativeIds,(s==null?void 0:s.initiativeId)??null),Q=P(s==null?void 0:s.workstreamIds,(s==null?void 0:s.workstreamId)??null);P(s==null?void 0:s.iwmtIds,(s==null?void 0:s.iwmtId)??null);const $e=$[0]?((ge=o.find(r=>r.id===$[0]))==null?void 0:ge.name)??$[0]:null;return e.jsxs(we,{className:"flex h-full min-h-0 flex-col overflow-hidden card-enter",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-subtle px-4 py-3.5",children:[e.jsx("h2",{className:"text-heading font-semibold text-white",children:"Session Detail"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:S("chip text-caption uppercase tracking-[0.14em]",Se),children:Te}),e.jsx("button",{onClick:()=>oe(r=>!r),className:"text-muted transition-colors hover:text-primary","aria-label":M?"Expand session detail":"Collapse session detail",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:S("transition-transform",M?"-rotate-90":"rotate-0"),children:e.jsx("path",{d:"m6 9 6 6 6-6"})})})]})]}),e.jsx("div",{className:S("transition-all",M?"max-h-0 overflow-hidden":"min-h-0 flex-1"),children:e.jsxs("div",{className:"h-full min-h-0 space-y-4 overflow-y-auto p-4",children:[e.jsxs("div",{className:"rounded-xl border border-subtle bg-white/[0.02] p-3",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Pe,{provider:ue.id,size:"sm"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-body font-semibold text-white",children:Fe(t.title)}),e.jsxs("p",{className:"mt-1 text-caption text-secondary",children:[t.agentName??"OrgX"," · ",ue.label]})]})]}),ee.length>0&&e.jsxs("div",{className:"mt-3",children:[e.jsx("p",{className:"mb-1 text-micro uppercase tracking-[0.16em] text-muted",children:"Context"}),e.jsx("div",{className:"flex flex-wrap items-center gap-1.5 text-caption",children:ee.map((r,d)=>e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{className:"rounded-full border border-strong bg-white/[0.02] px-2 py-0.5 text-secondary",children:r.value}),d<ee.length-1&&e.jsx("span",{className:"text-caption text-muted",children:"›"})]},`${r.label}-${r.value}`))})]}),R&&e.jsxs("div",{className:"mt-3 rounded-lg border border-subtle bg-white/[0.02] px-3 py-2",children:[e.jsx("p",{className:"mb-1 text-micro uppercase tracking-[0.16em] text-muted",children:"Summary"}),e.jsx(Oe,{text:R,mode:"block"})]}),e.jsxs("div",{className:S("mt-3 rounded-lg border px-3 py-2",Me),children:[e.jsx("p",{className:"mb-1 text-micro uppercase tracking-[0.16em] text-muted",children:c.label}),e.jsx("p",{className:"text-body text-secondary",children:c.sentence}),c.nextAction&&e.jsxs("p",{className:"mt-1 text-caption text-secondary",children:["Next: ",c.nextAction]})]}),Be&&e.jsxs("div",{className:"mt-3 rounded-lg border border-subtle bg-white/[0.02] px-3 py-2",children:[e.jsx("p",{className:"mb-1 text-micro uppercase tracking-[0.16em] text-muted",children:ke}),e.jsx("p",{className:"text-body text-secondary",children:X})]}),xe&&e.jsxs("div",{className:"mt-3 rounded-lg border border-red-500/25 bg-red-500/10 px-3 py-2.5",children:[e.jsx("p",{className:"mb-1 text-micro uppercase tracking-[0.16em] text-red-200/75",children:"Why blocked"}),e.jsx("p",{className:"text-body text-red-100/90",children:(a==null?void 0:a.reason)??re??"Runtime marked this run as blocked without details."}),se.length>0&&e.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:se.map(r=>e.jsx("span",{className:"rounded-full border border-red-300/25 bg-red-500/10 px-2 py-0.5 text-micro text-red-100/85",children:r},r))}),h.length>0&&e.jsxs("div",{className:"mt-2 rounded-md border border-red-300/20 bg-black/15 p-2.5",children:[e.jsx("p",{className:"mb-1 text-micro uppercase tracking-[0.14em] text-red-200/65",children:"Associated context"}),e.jsx("dl",{className:"grid grid-cols-1 gap-1.5 text-caption text-red-100/85",children:h.map(r=>e.jsxs("div",{className:"grid grid-cols-[86px_1fr] gap-2",children:[e.jsx("dt",{className:"text-red-200/70",children:r.label}),e.jsx("dd",{className:"break-all text-red-50/95",children:r.value})]},r.label))})]}),Array.isArray(a==null?void 0:a.suggestedActions)&&a.suggestedActions.length>0&&e.jsxs("div",{className:"mt-2",children:[e.jsx("p",{className:"mb-1 text-micro uppercase tracking-[0.14em] text-red-200/65",children:"Suggested actions"}),e.jsx("ul",{className:"space-y-1 text-caption text-red-100/85",children:a.suggestedActions.map(r=>e.jsxs("li",{children:["• ",r]},r))})]}),y(a==null?void 0:a.eventTimestamp)&&e.jsxs("p",{className:"mt-2 text-micro text-red-200/60",children:["Last blocker event: ",new Date(a.eventTimestamp).toLocaleString()," ·"," ",q(a.eventTimestamp)]})]})]}),s&&e.jsxs("div",{className:"rounded-xl border border-subtle bg-white/[0.02] p-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("h3",{className:"text-caption uppercase tracking-[0.12em] text-secondary",children:"Slice scope"}),pe?e.jsx("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-2 py-0.5 text-micro font-semibold uppercase tracking-[0.08em] text-secondary",children:pe}):null]}),s.statusExplainer?e.jsx("p",{className:"mt-2 text-caption text-secondary",children:s.statusExplainer}):null,e.jsxs("dl",{className:"mt-2 grid grid-cols-2 gap-2 text-caption text-secondary",children:[e.jsxs("div",{children:[e.jsx("dt",{className:"text-muted",children:"Initiative"}),e.jsx("dd",{className:"text-body font-semibold text-white",children:$e??"—"})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-muted",children:"Workstream"}),e.jsx("dd",{className:"text-body font-semibold text-white",children:s.workstreamTitle??(Q[0]?N(Q[0]):"—")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-muted",children:"Run"}),e.jsx("dd",{className:"break-all text-body font-semibold text-white",children:N(s.runId??s.sliceRunId)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-muted",children:"Updated"}),e.jsx("dd",{className:"text-body font-semibold text-white",children:s.updatedAt?q(s.updatedAt):"—"})]})]}),e.jsxs("div",{className:"mt-2 flex flex-wrap gap-1.5 text-micro",children:[e.jsxs("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-2 py-0.5 text-secondary",children:["Tasks ",s.taskIds.length]}),e.jsxs("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-2 py-0.5 text-secondary",children:["Milestones ",s.milestoneIds.length]}),e.jsxs("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-2 py-0.5 text-secondary",children:["Artifacts ",s.artifactCount]}),e.jsxs("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-2 py-0.5 text-secondary",children:["Needs input ",s.blockingDecisionCount]}),$.length>1?e.jsxs("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-2 py-0.5 text-secondary",children:["+",$.length-1," initiatives"]}):null,Q.length>1?e.jsxs("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-2 py-0.5 text-secondary",children:["+",Q.length-1," workstreams"]}):null]}),s.taskIds.length>0?e.jsxs("p",{className:"mt-2 text-micro text-secondary",children:["Tasks: ",s.taskIds.length]}):null]}),e.jsxs("div",{className:"rounded-xl border border-subtle bg-white/[0.02] p-3",children:[U!==null&&e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between text-caption text-secondary",children:[e.jsx("span",{children:Le}),e.jsxs("span",{className:"text-primary",children:[U,"%"]})]}),e.jsx("div",{className:"h-2 rounded-full bg-white/[0.08]",children:e.jsx("div",{className:S("h-2 rounded-full transition-all duration-500",me&&"live-pulse"),style:{width:`${U}%`,background:Ee}})})]}),e.jsx("dl",{className:S("grid grid-cols-2 gap-3 text-caption text-secondary",U!==null?"mt-3":""),children:We.map(r=>e.jsxs("div",{children:[e.jsx("dt",{className:"text-muted",children:r.label}),e.jsx("dd",{className:"text-body font-semibold text-white",children:r.value})]},r.label))})]}),e.jsxs("div",{className:"rounded-xl border border-subtle bg-white/[0.02] p-3",children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{onClick:()=>_("dispatch-session","Session started",()=>F==null?void 0:F(t)),disabled:!F||!!x||!_e,className:"rounded-md border border-lime/25 bg-lime/10 px-3 py-2 text-caption font-semibold text-lime transition-colors hover:bg-lime/20 disabled:opacity-45",children:x==="dispatch-session"?"Starting…":c.status==="completed"?"Restart":"Start"}),Ie&&e.jsx("button",{onClick:()=>_("pause-session","Session paused",()=>O==null?void 0:O(t)),disabled:!O||!!x,className:"rounded-md border border-strong bg-white/[0.02] px-3 py-2 text-caption text-secondary transition-colors hover:bg-white/[0.06] hover:text-white disabled:opacity-45",children:x==="pause-session"?"Pausing…":"Pause"}),Ae&&e.jsx("button",{onClick:()=>_("resume-session","Session resumed",()=>V==null?void 0:V(t)),disabled:!V||!!x,className:"rounded-md border border-strong bg-white/[0.02] px-3 py-2 text-caption text-secondary transition-colors hover:bg-white/[0.06] hover:text-white disabled:opacity-45",children:x==="resume-session"?"Resuming…":"Resume"}),e.jsx("button",{onClick:()=>_("checkpoint-session","Progress saved",()=>K==null?void 0:K(t)),disabled:!K||!!x,className:"rounded-md border border-strong bg-white/[0.02] px-3 py-2 text-caption text-secondary transition-colors hover:bg-white/[0.06] hover:text-white disabled:opacity-45",children:x==="checkpoint-session"?"Saving…":"Save progress"}),Re&&e.jsx("button",{onClick:()=>_("rollback-session","Undo requested",()=>H==null?void 0:H(t)),disabled:!H||!!x,className:"rounded-md border border-strong bg-white/[0.02] px-3 py-2 text-caption text-secondary transition-colors hover:bg-white/[0.06] hover:text-white disabled:opacity-45",children:x==="rollback-session"?"Undoing…":"Undo last step"})]}),ie&&e.jsxs("div",{className:"mt-3 rounded-lg border border-white/[0.08] bg-black/[0.18] px-3 py-2.5",children:[e.jsx("p",{className:"mb-2 text-micro uppercase tracking-[0.16em] text-muted",children:"Intervene"}),e.jsx("textarea",{value:D,onChange:r=>W(r.target.value),placeholder:"Share guidance for this run...",className:"min-h-[84px] w-full resize-y rounded-lg border border-white/[0.10] bg-white/[0.03] px-3 py-2 text-body text-bright outline-none placeholder:text-faint focus:border-white/20"}),e.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-micro text-secondary",children:"Visible to agents and collaborators."}),e.jsx("button",{type:"button",onClick:()=>{const r=D.trim();if(!r){A("Intervention note cannot be empty.");return}_("intervene-note","Intervention sent",async()=>{await ie({session:t,workstreamId:(k==null?void 0:k.workstreamId)??t.workstreamId??null,text:r}),W("")})},disabled:!!x||D.trim().length===0,className:"rounded-md border border-strong bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:x==="intervene-note"?"Sending…":"Send intervention"})]})]}),Ce&&G&&e.jsx("div",{className:"mt-3 border-t border-subtle pt-3",children:e.jsx("button",{onClick:Ue,disabled:!!x,className:"text-caption text-secondary transition-colors hover:text-red-300 disabled:opacity-45",children:"Cancel session…"})})]}),J&&e.jsx("p",{className:"rounded-md border border-white/[0.08] bg-white/[0.02] px-2.5 py-1.5 text-caption text-secondary",children:J}),t.blockers.length>0&&e.jsxs("div",{className:"rounded-xl border border-red-500/30 bg-red-500/10 p-3",children:[e.jsx("h3",{className:"mb-1 text-caption uppercase tracking-[0.12em] text-red-200/70",children:"Blockers"}),e.jsx("ul",{className:"space-y-1 text-body text-red-100/90",children:t.blockers.map(r=>e.jsxs("li",{children:["• ",r]},r))})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"mb-2 text-caption uppercase tracking-[0.16em] text-secondary",children:"Recent Messages"}),C.length===0&&e.jsx("p",{className:"text-body text-secondary",children:"No recent messages for this run."}),e.jsx("div",{className:"space-y-2",children:C.map(r=>e.jsxs("article",{className:"rounded-lg border border-subtle bg-white/[0.02] px-2.5 py-2",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsx("p",{className:"min-w-0 flex-1 text-caption text-bright",children:r.title}),j&&e.jsx("button",{type:"button",onClick:()=>j(r),className:"flex-shrink-0 rounded-full border border-strong bg-white/[0.03] px-2.5 py-0.5 text-micro font-semibold text-secondary transition-colors hover:bg-white/[0.08] hover:text-primary",children:"Open"})]}),(r.summary||r.description)&&e.jsx("p",{className:"mt-0.5 line-clamp-2 text-caption text-secondary",children:r.summary??r.description}),e.jsxs("p",{className:"mt-1 text-micro text-muted",children:[new Date(r.timestamp).toLocaleString()," · ",q(r.timestamp)]})]},r.id))})]})]})}),e.jsx(ve,{})]})});export{dt as SessionInspector};
@@ -1 +1 @@
1
- import{r as s,j as t}from"./cNrhgGc1.js";import{r as ke}from"./C9jy61eu.js";import"./C-KIc3Wc.js";import"./BJgZIVUQ.js";import"./CxQ08qFN.js";const I={PREVIEW:"orgx_orchestrator_preview",APPLY:"orgx_orchestrator_apply",STATUS:"orgx_orchestrator_status"};function l(p){if(typeof p!="string")return null;const n=p.trim();return n.length?n:null}function Ce(p){if(!p.trim())return{};const n=JSON.parse(p);return!n||typeof n!="object"||Array.isArray(n)?{}:n}function Q(p){const n=l(p.transcript)??l(p.text)??l(p.delta??null);if(n)return n;const h=p.item&&typeof p.item=="object"?p.item:null,v=Array.isArray(h==null?void 0:h.content)?h==null?void 0:h.content:[];for(const y of v){if(!y||typeof y!="object")continue;const f=l(y.transcript)??l(y.text);if(f)return f}return null}function Se(p){const n=p.response&&typeof p.response=="object"?p.response:null,h=Array.isArray(n==null?void 0:n.output)?n==null?void 0:n.output:[],v=[];for(const y of h){if(!y||typeof y!="object")continue;const f=y;if(f.type!=="function_call")continue;const C=l(f.name),S=l(f.call_id)??l(f.id),A=typeof f.arguments=="string"?f.arguments:"{}";!C||!S||v.push({callId:S,name:C,arguments:A})}return v}function Ae(p){const n=Number.isFinite(p)?p*100:0;return`${Math.max(0,Math.min(100,Math.round(n)))}%`}const fe=[{type:"function",name:I.PREVIEW,description:"Preview orchestrator actions from a natural language command. Use this before apply.",parameters:{type:"object",additionalProperties:!1,properties:{input:{type:"string",description:"Natural language command from the operator."},workspace_id:{type:"string",description:"Optional OrgX workspace/command_center id."}},required:["input"]}},{type:"function",name:I.APPLY,description:"Apply selected action ids from a previewed command after user confirmation.",parameters:{type:"object",additionalProperties:!1,properties:{command_id:{type:"string",description:"Command id from preview response."},confirmed_action_ids:{type:"array",items:{type:"string"},description:"Optional subset of action ids to apply. Omit to apply all."},workspace_id:{type:"string",description:"Optional OrgX workspace/command_center id."}},required:["command_id"]}},{type:"function",name:I.STATUS,description:"Get latest status for a previously created command.",parameters:{type:"object",additionalProperties:!1,properties:{command_id:{type:"string",description:"Command id from preview/apply response."}},required:["command_id"]}}];function Oe({open:p,selectedWorkspaceId:n,onClose:h}){var le,de,pe;const[v,y]=s.useState(!1),[f,C]=s.useState(!1),[S,A]=s.useState(!1),[xe,he]=s.useState("gpt-realtime-1.5"),[$,Z]=s.useState(""),[W,M]=s.useState(""),[o,P]=s.useState(null),[T,X]=s.useState([]),[ee,te]=s.useState(!1),[re,oe]=s.useState(!1),[se,b]=s.useState(null),[ne,z]=s.useState([]),G=s.useRef(null),D=s.useRef(null),O=s.useRef(null),H=s.useRef(null),E=s.useRef(""),J=s.useRef(new Set),R=s.useCallback(e=>{z(r=>[e,...r].slice(0,10))},[]),N=s.useCallback(()=>{A(!1),C(!1),J.current=new Set;const e=D.current;if(e)try{e.close()}catch{}D.current=null;const r=G.current;if(r)try{r.close()}catch{}G.current=null;const a=O.current;if(a)for(const m of a.getTracks())try{m.stop()}catch{}O.current=null;const d=H.current;if(d){try{const m=d.srcObject;m==null||m.getTracks().forEach(i=>i.stop())}catch{}try{d.pause()}catch{}d.srcObject=null}H.current=null},[]);s.useEffect(()=>{p||(N(),b(null),M(""),z([]),E.current="")},[N,p]),s.useEffect(()=>()=>N(),[N]);const g=s.useCallback(e=>{const r=D.current;!r||r.readyState!=="open"||r.send(JSON.stringify(e))},[]),ae=s.useCallback(async e=>{const r=await fetch(e),a=await r.json().catch(()=>({}));if(!r.ok)throw new Error(a&&typeof a=="object"&&"error"in a&&a.error||`Request failed: ${r.status}`);return a},[]),j=s.useCallback(async(e,r)=>{const a=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)}),d=await a.json().catch(()=>({}));if(!a.ok)throw new Error(d&&typeof d=="object"&&"error"in d&&d.error||`Request failed: ${a.status}`);return d},[]),L=s.useCallback(async e=>{if(!J.current.has(e.callId)){J.current.add(e.callId);try{const r=Ce(e.arguments);let a={ok:!1,error:"Unsupported tool call."};if(e.name===I.PREVIEW){const d=l(r.input);if(!d)throw new Error("Preview tool call requires input.");const m=await j("/orgx/api/orchestrator/commands/preview",{input:d,workspace_id:l(r.workspace_id)??n??void 0});if(!m.command)throw new Error(m.error??"Preview command failed.");P(m.command),X(m.command.proposedActions.map(i=>i.actionId)),a={ok:!0,command:m.command}}else if(e.name===I.APPLY){const d=l(r.command_id);if(!d)throw new Error("Apply tool call requires command_id.");const m=Array.isArray(r.confirmed_action_ids)?r.confirmed_action_ids.filter(F=>typeof F=="string"):void 0,i=await j("/orgx/api/orchestrator/commands/apply",{command_id:d,confirmed_action_ids:m,workspace_id:l(r.workspace_id)??n??void 0});if(!i.command)throw new Error(i.error??"Apply command failed.");P(i.command),a={ok:!0,command:i.command}}else if(e.name===I.STATUS){const d=l(r.command_id);if(!d)throw new Error("Status tool call requires command_id.");const m=await ae(`/orgx/api/orchestrator/commands/${encodeURIComponent(d)}`);if(!m.command)throw new Error(m.error??"Command status unavailable.");P(m.command),a={ok:!0,command:m.command}}g({type:"conversation.item.create",item:{type:"function_call_output",call_id:e.callId,output:JSON.stringify(a)}}),g({type:"response.create"}),R(`Tool executed: ${e.name}`)}catch(r){const a=r instanceof Error?r.message:"Tool execution failed.";b(a),g({type:"conversation.item.create",item:{type:"function_call_output",call_id:e.callId,output:JSON.stringify({ok:!1,error:a})}}),g({type:"response.create"}),R(`Tool failed: ${e.name}`)}}},[ae,R,j,n,g]),ye=s.useCallback(async()=>{var e,r,a,d,m;if(!((e=navigator.mediaDevices)!=null&&e.getUserMedia)){b("Microphone capture is unavailable in this browser/runtime.");return}b(null),y(!0),z([]);try{const i=await j("/orgx/api/realtime/session",{workspace_id:n??void 0,model:"gpt-realtime-1.5",voice:"alloy",tool_choice:"auto",tools:fe,instructions:"You are the OrgX realtime orchestrator copilot. Use tools for state-changing operations. Before applying actions, state the plan concisely."});if(!(i!=null&&i.session))throw new Error((i==null?void 0:i.error)??"Failed to create realtime session.");const F=l((r=i==null?void 0:i.session)==null?void 0:r.model)??l((a=i==null?void 0:i.defaults)==null?void 0:a.model)??"gpt-realtime-1.5";he(F);const me=l((m=(d=i==null?void 0:i.session)==null?void 0:d.client_secret)==null?void 0:m.value);if(!me)throw new Error("Realtime session is missing client_secret.");const U=await navigator.mediaDevices.getUserMedia({audio:!0});O.current=U;for(const _ of U.getAudioTracks())_.enabled=!1;const k=new RTCPeerConnection;G.current=k,U.getTracks().forEach(_=>k.addTrack(_,U));const q=document.createElement("audio");q.autoplay=!0,H.current=q,k.ontrack=_=>{const[u]=_.streams;u&&(q.srcObject=u,q.play().catch(()=>{}))};const V=k.createDataChannel("oai-events");D.current=V,V.onmessage=_=>{try{const u=JSON.parse(String(_.data)),x=l(u.type)??"";if(x==="error"){const c=u.error&&typeof u.error=="object"?u.error:null,w=l(c==null?void 0:c.message)??l(u.message)??"Realtime session error.";b(w),R(`Error: ${w}`);return}if(x==="conversation.item.input_audio_transcription.completed"){const c=Q(u);c&&Z(c)}if(x==="response.output_text.delta"||x==="response.text.delta"||x==="response.output_audio_transcript.delta"||x==="response.audio_transcript.delta"){const c=l(u.delta)??Q(u);c&&(E.current=`${E.current}${c}`,M(E.current))}if(x==="response.output_text.done"||x==="response.text.done"||x==="response.output_audio_transcript.done"||x==="response.audio_transcript.done"){const c=Q(u);c&&(E.current=c,M(c))}if(x==="response.function_call_arguments.done"){const c=l(u.call_id),w=l(u.name);if(c&&w){const B=typeof u.arguments=="string"?u.arguments:"{}";L({callId:c,name:w,arguments:B})}}if(x==="response.output_item.done"){const c=u.item&&typeof u.item=="object"?u.item:null;if((c==null?void 0:c.type)==="function_call"){const w=l(c.call_id)??l(c.id),B=l(c.name);if(w&&B){const Ne=typeof c.arguments=="string"?c.arguments:"{}";L({callId:w,name:B,arguments:Ne})}}}if(x==="response.done"){const c=Se(u);for(const w of c)L(w)}}catch{}},V.onopen=()=>{C(!0),g({type:"session.update",session:{tools:fe,tool_choice:"auto"}}),R("Realtime connected")},V.onclose=()=>{C(!1),A(!1)};const ue=await k.createOffer();await k.setLocalDescription(ue);const Y=await fetch(`https://api.openai.com/v1/realtime?model=${encodeURIComponent(F)}`,{method:"POST",headers:{Authorization:`Bearer ${me}`,"Content-Type":"application/sdp"},body:ue.sdp??""});if(!Y.ok){const _=await Y.text().catch(()=>Y.statusText);throw new Error(`Realtime SDP negotiation failed: ${_}`)}const ve=await Y.text();await k.setRemoteDescription({type:"answer",sdp:ve})}catch(i){N(),b(i instanceof Error?i.message:"Failed to connect realtime session.")}finally{y(!1)}},[N,L,R,j,n]),ie=s.useCallback(()=>{if(!f)return;const e=O.current;if(e){for(const r of e.getAudioTracks())r.enabled=!0;E.current="",M(""),A(!0),g({type:"input_audio_buffer.clear"})}},[f,g]),K=s.useCallback(()=>{const e=O.current;if(e)for(const r of e.getAudioTracks())r.enabled=!1;A(!1),g({type:"input_audio_buffer.commit"}),g({type:"response.create"})},[g]),ge=s.useCallback(async()=>{const e=$.trim();if(e){te(!0),b(null);try{const r=await j("/orgx/api/orchestrator/commands/preview",{input:e,workspace_id:n??void 0});if(!r.command)throw new Error(r.error??"Failed to preview command.");P(r.command),X(r.command.proposedActions.map(a=>a.actionId))}catch(r){b(r instanceof Error?r.message:"Failed to preview command.")}finally{te(!1)}}},[$,j,n]),be=s.useCallback(async()=>{if(o!=null&&o.id){oe(!0),b(null);try{const e=await j("/orgx/api/orchestrator/commands/apply",{command_id:o.id,confirmed_action_ids:T,workspace_id:n??void 0});if(!e.command)throw new Error(e.error??"Failed to apply command.");P(e.command)}catch(e){b(e instanceof Error?e.message:"Failed to apply command.")}finally{oe(!1)}}},[o==null?void 0:o.id,j,T,n]),ce=T.length,we=(((le=o==null?void 0:o.proposedActions)==null?void 0:le.length)??0)>0,je=!!(o!=null&&o.id)&&ce>0&&!re,_e=s.useMemo(()=>{const e=(o==null?void 0:o.status)??"draft";return e==="completed"?"text-lime":e==="completed_with_errors"||e==="failed"?"text-amber-300":e==="applying"?"text-teal":"text-secondary"},[o==null?void 0:o.status]);return t.jsxs(ke,{open:p,onClose:h,maxWidth:"max-w-5xl",fitContent:!0,closeOnEscapeWhenTyping:!1,children:[t.jsx("div",{className:"border-b border-strong px-4 py-3",children:t.jsxs("div",{className:"flex items-start justify-between gap-3",children:[t.jsxs("div",{children:[t.jsx("p",{className:"text-caption uppercase tracking-[0.14em] text-secondary",children:"Realtime Orchestrator"}),t.jsx("h2",{className:"text-heading font-semibold text-white",children:"GPT Realtime 1.5"}),t.jsx("p",{className:"text-micro text-secondary",children:"Voice + tool-calls for initiative launch, decision resolution, and Next Up control."})]}),t.jsx("button",{type:"button",onClick:h,className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption text-secondary transition-colors hover:bg-white/[0.08] hover:text-white",children:"Close"})]})}),t.jsxs("div",{className:"grid gap-4 px-4 pb-4 pt-3 lg:grid-cols-[1.12fr_1fr]",children:[t.jsxs("section",{className:"space-y-3",children:[t.jsxs("div",{className:"rounded-xl border border-strong bg-white/[0.02] p-3",children:[t.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[t.jsx("span",{className:"text-caption uppercase tracking-[0.12em] text-secondary",children:"Session"}),t.jsx("span",{className:"text-micro text-secondary",children:xe})]}),t.jsx("div",{className:"flex flex-wrap items-center gap-2",children:f?t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",onMouseDown:ie,onMouseUp:K,onMouseLeave:()=>{S&&K()},onTouchStart:e=>{e.preventDefault(),ie()},onTouchEnd:e=>{e.preventDefault(),K()},className:`rounded-full border px-3 py-1.5 text-caption font-semibold transition-colors ${S?"border-teal/45 bg-teal/[0.16] text-teal":"border-white/[0.2] bg-white/[0.04] text-primary hover:bg-white/[0.1]"}`,children:S?"Listening… release to send":"Hold to talk"}),t.jsx("button",{type:"button",onClick:N,className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption text-secondary transition-colors hover:bg-white/[0.08] hover:text-primary",children:"Disconnect"})]}):t.jsx("button",{type:"button",disabled:v,onClick:()=>void ye(),className:"rounded-full border border-lime/35 bg-lime/[0.12] px-3 py-1.5 text-caption font-semibold text-lime transition-colors hover:bg-lime/[0.2] disabled:cursor-not-allowed disabled:opacity-60",children:v?"Connecting…":"Connect Realtime"})}),ne.length>0?t.jsx("div",{className:"mt-3 rounded-lg border border-strong bg-black/20 p-2",children:ne.map((e,r)=>t.jsx("p",{className:"text-micro text-secondary",children:e},`${e}-${r}`))}):null]}),t.jsxs("div",{className:"rounded-xl border border-strong bg-white/[0.02] p-3",children:[t.jsx("label",{className:"mb-2 block text-caption uppercase tracking-[0.12em] text-secondary",children:"Command Input"}),t.jsx("textarea",{value:$,onChange:e=>Z(e.target.value),rows:4,"data-modal-autofocus":"true",placeholder:"Example: create initiative called AI Readiness Audit for this workspace",className:"w-full rounded-lg border border-strong bg-[#040912] px-3 py-2 text-body text-primary placeholder:text-secondary focus:border-lime/35 focus:outline-none"}),W?t.jsxs("p",{className:"mt-2 text-caption text-secondary",children:["Assistant: ",t.jsx("span",{className:"text-primary",children:W})]}):null,t.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[t.jsx("button",{type:"button",disabled:ee||$.trim().length===0,onClick:()=>void ge(),className:"rounded-full border border-teal/35 bg-teal/[0.12] px-3 py-1.5 text-caption font-semibold text-teal transition-colors hover:bg-teal/[0.2] disabled:cursor-not-allowed disabled:opacity-60",children:ee?"Previewing…":"Preview Actions"}),t.jsx("button",{type:"button",disabled:!je,onClick:()=>void be(),className:"rounded-full border border-lime/35 bg-lime/[0.12] px-3 py-1.5 text-caption font-semibold text-lime transition-colors hover:bg-lime/[0.2] disabled:cursor-not-allowed disabled:opacity-60",children:re?"Applying…":`Apply (${ce})`})]})]})]}),t.jsxs("section",{className:"space-y-3",children:[t.jsxs("div",{className:"rounded-xl border border-strong bg-white/[0.02] p-3",children:[t.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[t.jsx("span",{className:"text-caption uppercase tracking-[0.12em] text-secondary",children:"Command Status"}),t.jsx("span",{className:`text-caption font-semibold ${_e}`,children:(o==null?void 0:o.status)??"idle"})]}),t.jsx("p",{className:"text-body text-primary",children:(o==null?void 0:o.humanSummary)??"Preview a command or use voice to trigger tool calls."}),(de=o==null?void 0:o.riskFlags)!=null&&de.length?t.jsxs("p",{className:"mt-2 text-caption text-amber-200",children:["Risk flags: ",o.riskFlags.join(", ")]}):null]}),t.jsxs("div",{className:"max-h-[360px] space-y-2 overflow-y-auto rounded-xl border border-strong bg-white/[0.02] p-3",children:[t.jsx("p",{className:"text-caption uppercase tracking-[0.12em] text-secondary",children:"Proposed Actions"}),we?o.proposedActions.map(e=>{const r=T.includes(e.actionId);return t.jsx("label",{className:"block rounded-lg border border-strong bg-[#040912] p-2 text-body",children:t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsx("input",{type:"checkbox",checked:r,onChange:a=>{const d=a.target.checked?[...T,e.actionId]:T.filter(m=>m!==e.actionId);X(d)},className:"mt-1"}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:"font-semibold text-primary",children:e.type}),t.jsx("p",{className:"text-caption text-secondary",children:e.reason}),t.jsxs("p",{className:"text-micro text-secondary",children:["confidence ",Ae(e.confidence)," • impact ",e.blockingImpact]})]})]})},e.actionId)}):t.jsx("p",{className:"text-body text-secondary",children:"No actions inferred yet."})]}),(((pe=o==null?void 0:o.results)==null?void 0:pe.length)??0)>0?t.jsxs("div",{className:"max-h-[220px] space-y-2 overflow-y-auto rounded-xl border border-strong bg-white/[0.02] p-3",children:[t.jsx("p",{className:"text-caption uppercase tracking-[0.12em] text-secondary",children:"Apply Results"}),o.results.map(e=>t.jsxs("div",{className:`rounded-lg border p-2 text-body ${e.ok?"border-lime/30 bg-lime/[0.08] text-lime":"border-amber-400/35 bg-amber-500/[0.12] text-amber-100"}`,children:[t.jsx("p",{className:"font-semibold",children:e.type}),t.jsx("p",{className:"text-caption",children:e.message}),e.error?t.jsxs("p",{className:"text-micro text-amber-200",children:["error: ",e.error]}):null]},`${e.actionId}-${e.type}`))]}):null]})]}),se?t.jsx("div",{className:"border-t border-amber-500/30 bg-amber-500/[0.12] px-4 py-2 text-caption text-amber-100",children:se}):null]})}export{Oe as RealtimeOrchestratorModal};
1
+ import{r as s,j as t}from"./cNrhgGc1.js";import{r as ke}from"./Cn07669c.js";import"./C-KIc3Wc.js";import"./BJgZIVUQ.js";import"./CxQ08qFN.js";const I={PREVIEW:"orgx_orchestrator_preview",APPLY:"orgx_orchestrator_apply",STATUS:"orgx_orchestrator_status"};function l(p){if(typeof p!="string")return null;const n=p.trim();return n.length?n:null}function Ce(p){if(!p.trim())return{};const n=JSON.parse(p);return!n||typeof n!="object"||Array.isArray(n)?{}:n}function Q(p){const n=l(p.transcript)??l(p.text)??l(p.delta??null);if(n)return n;const h=p.item&&typeof p.item=="object"?p.item:null,v=Array.isArray(h==null?void 0:h.content)?h==null?void 0:h.content:[];for(const y of v){if(!y||typeof y!="object")continue;const f=l(y.transcript)??l(y.text);if(f)return f}return null}function Se(p){const n=p.response&&typeof p.response=="object"?p.response:null,h=Array.isArray(n==null?void 0:n.output)?n==null?void 0:n.output:[],v=[];for(const y of h){if(!y||typeof y!="object")continue;const f=y;if(f.type!=="function_call")continue;const C=l(f.name),S=l(f.call_id)??l(f.id),A=typeof f.arguments=="string"?f.arguments:"{}";!C||!S||v.push({callId:S,name:C,arguments:A})}return v}function Ae(p){const n=Number.isFinite(p)?p*100:0;return`${Math.max(0,Math.min(100,Math.round(n)))}%`}const fe=[{type:"function",name:I.PREVIEW,description:"Preview orchestrator actions from a natural language command. Use this before apply.",parameters:{type:"object",additionalProperties:!1,properties:{input:{type:"string",description:"Natural language command from the operator."},workspace_id:{type:"string",description:"Optional OrgX workspace/command_center id."}},required:["input"]}},{type:"function",name:I.APPLY,description:"Apply selected action ids from a previewed command after user confirmation.",parameters:{type:"object",additionalProperties:!1,properties:{command_id:{type:"string",description:"Command id from preview response."},confirmed_action_ids:{type:"array",items:{type:"string"},description:"Optional subset of action ids to apply. Omit to apply all."},workspace_id:{type:"string",description:"Optional OrgX workspace/command_center id."}},required:["command_id"]}},{type:"function",name:I.STATUS,description:"Get latest status for a previously created command.",parameters:{type:"object",additionalProperties:!1,properties:{command_id:{type:"string",description:"Command id from preview/apply response."}},required:["command_id"]}}];function Oe({open:p,selectedWorkspaceId:n,onClose:h}){var le,de,pe;const[v,y]=s.useState(!1),[f,C]=s.useState(!1),[S,A]=s.useState(!1),[xe,he]=s.useState("gpt-realtime-1.5"),[$,Z]=s.useState(""),[W,M]=s.useState(""),[o,P]=s.useState(null),[T,X]=s.useState([]),[ee,te]=s.useState(!1),[re,oe]=s.useState(!1),[se,b]=s.useState(null),[ne,z]=s.useState([]),G=s.useRef(null),D=s.useRef(null),O=s.useRef(null),H=s.useRef(null),E=s.useRef(""),J=s.useRef(new Set),R=s.useCallback(e=>{z(r=>[e,...r].slice(0,10))},[]),N=s.useCallback(()=>{A(!1),C(!1),J.current=new Set;const e=D.current;if(e)try{e.close()}catch{}D.current=null;const r=G.current;if(r)try{r.close()}catch{}G.current=null;const a=O.current;if(a)for(const m of a.getTracks())try{m.stop()}catch{}O.current=null;const d=H.current;if(d){try{const m=d.srcObject;m==null||m.getTracks().forEach(i=>i.stop())}catch{}try{d.pause()}catch{}d.srcObject=null}H.current=null},[]);s.useEffect(()=>{p||(N(),b(null),M(""),z([]),E.current="")},[N,p]),s.useEffect(()=>()=>N(),[N]);const g=s.useCallback(e=>{const r=D.current;!r||r.readyState!=="open"||r.send(JSON.stringify(e))},[]),ae=s.useCallback(async e=>{const r=await fetch(e),a=await r.json().catch(()=>({}));if(!r.ok)throw new Error(a&&typeof a=="object"&&"error"in a&&a.error||`Request failed: ${r.status}`);return a},[]),j=s.useCallback(async(e,r)=>{const a=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)}),d=await a.json().catch(()=>({}));if(!a.ok)throw new Error(d&&typeof d=="object"&&"error"in d&&d.error||`Request failed: ${a.status}`);return d},[]),L=s.useCallback(async e=>{if(!J.current.has(e.callId)){J.current.add(e.callId);try{const r=Ce(e.arguments);let a={ok:!1,error:"Unsupported tool call."};if(e.name===I.PREVIEW){const d=l(r.input);if(!d)throw new Error("Preview tool call requires input.");const m=await j("/orgx/api/orchestrator/commands/preview",{input:d,workspace_id:l(r.workspace_id)??n??void 0});if(!m.command)throw new Error(m.error??"Preview command failed.");P(m.command),X(m.command.proposedActions.map(i=>i.actionId)),a={ok:!0,command:m.command}}else if(e.name===I.APPLY){const d=l(r.command_id);if(!d)throw new Error("Apply tool call requires command_id.");const m=Array.isArray(r.confirmed_action_ids)?r.confirmed_action_ids.filter(F=>typeof F=="string"):void 0,i=await j("/orgx/api/orchestrator/commands/apply",{command_id:d,confirmed_action_ids:m,workspace_id:l(r.workspace_id)??n??void 0});if(!i.command)throw new Error(i.error??"Apply command failed.");P(i.command),a={ok:!0,command:i.command}}else if(e.name===I.STATUS){const d=l(r.command_id);if(!d)throw new Error("Status tool call requires command_id.");const m=await ae(`/orgx/api/orchestrator/commands/${encodeURIComponent(d)}`);if(!m.command)throw new Error(m.error??"Command status unavailable.");P(m.command),a={ok:!0,command:m.command}}g({type:"conversation.item.create",item:{type:"function_call_output",call_id:e.callId,output:JSON.stringify(a)}}),g({type:"response.create"}),R(`Tool executed: ${e.name}`)}catch(r){const a=r instanceof Error?r.message:"Tool execution failed.";b(a),g({type:"conversation.item.create",item:{type:"function_call_output",call_id:e.callId,output:JSON.stringify({ok:!1,error:a})}}),g({type:"response.create"}),R(`Tool failed: ${e.name}`)}}},[ae,R,j,n,g]),ye=s.useCallback(async()=>{var e,r,a,d,m;if(!((e=navigator.mediaDevices)!=null&&e.getUserMedia)){b("Microphone capture is unavailable in this browser/runtime.");return}b(null),y(!0),z([]);try{const i=await j("/orgx/api/realtime/session",{workspace_id:n??void 0,model:"gpt-realtime-1.5",voice:"alloy",tool_choice:"auto",tools:fe,instructions:"You are the OrgX realtime orchestrator copilot. Use tools for state-changing operations. Before applying actions, state the plan concisely."});if(!(i!=null&&i.session))throw new Error((i==null?void 0:i.error)??"Failed to create realtime session.");const F=l((r=i==null?void 0:i.session)==null?void 0:r.model)??l((a=i==null?void 0:i.defaults)==null?void 0:a.model)??"gpt-realtime-1.5";he(F);const me=l((m=(d=i==null?void 0:i.session)==null?void 0:d.client_secret)==null?void 0:m.value);if(!me)throw new Error("Realtime session is missing client_secret.");const U=await navigator.mediaDevices.getUserMedia({audio:!0});O.current=U;for(const _ of U.getAudioTracks())_.enabled=!1;const k=new RTCPeerConnection;G.current=k,U.getTracks().forEach(_=>k.addTrack(_,U));const q=document.createElement("audio");q.autoplay=!0,H.current=q,k.ontrack=_=>{const[u]=_.streams;u&&(q.srcObject=u,q.play().catch(()=>{}))};const V=k.createDataChannel("oai-events");D.current=V,V.onmessage=_=>{try{const u=JSON.parse(String(_.data)),x=l(u.type)??"";if(x==="error"){const c=u.error&&typeof u.error=="object"?u.error:null,w=l(c==null?void 0:c.message)??l(u.message)??"Realtime session error.";b(w),R(`Error: ${w}`);return}if(x==="conversation.item.input_audio_transcription.completed"){const c=Q(u);c&&Z(c)}if(x==="response.output_text.delta"||x==="response.text.delta"||x==="response.output_audio_transcript.delta"||x==="response.audio_transcript.delta"){const c=l(u.delta)??Q(u);c&&(E.current=`${E.current}${c}`,M(E.current))}if(x==="response.output_text.done"||x==="response.text.done"||x==="response.output_audio_transcript.done"||x==="response.audio_transcript.done"){const c=Q(u);c&&(E.current=c,M(c))}if(x==="response.function_call_arguments.done"){const c=l(u.call_id),w=l(u.name);if(c&&w){const B=typeof u.arguments=="string"?u.arguments:"{}";L({callId:c,name:w,arguments:B})}}if(x==="response.output_item.done"){const c=u.item&&typeof u.item=="object"?u.item:null;if((c==null?void 0:c.type)==="function_call"){const w=l(c.call_id)??l(c.id),B=l(c.name);if(w&&B){const Ne=typeof c.arguments=="string"?c.arguments:"{}";L({callId:w,name:B,arguments:Ne})}}}if(x==="response.done"){const c=Se(u);for(const w of c)L(w)}}catch{}},V.onopen=()=>{C(!0),g({type:"session.update",session:{tools:fe,tool_choice:"auto"}}),R("Realtime connected")},V.onclose=()=>{C(!1),A(!1)};const ue=await k.createOffer();await k.setLocalDescription(ue);const Y=await fetch(`https://api.openai.com/v1/realtime?model=${encodeURIComponent(F)}`,{method:"POST",headers:{Authorization:`Bearer ${me}`,"Content-Type":"application/sdp"},body:ue.sdp??""});if(!Y.ok){const _=await Y.text().catch(()=>Y.statusText);throw new Error(`Realtime SDP negotiation failed: ${_}`)}const ve=await Y.text();await k.setRemoteDescription({type:"answer",sdp:ve})}catch(i){N(),b(i instanceof Error?i.message:"Failed to connect realtime session.")}finally{y(!1)}},[N,L,R,j,n]),ie=s.useCallback(()=>{if(!f)return;const e=O.current;if(e){for(const r of e.getAudioTracks())r.enabled=!0;E.current="",M(""),A(!0),g({type:"input_audio_buffer.clear"})}},[f,g]),K=s.useCallback(()=>{const e=O.current;if(e)for(const r of e.getAudioTracks())r.enabled=!1;A(!1),g({type:"input_audio_buffer.commit"}),g({type:"response.create"})},[g]),ge=s.useCallback(async()=>{const e=$.trim();if(e){te(!0),b(null);try{const r=await j("/orgx/api/orchestrator/commands/preview",{input:e,workspace_id:n??void 0});if(!r.command)throw new Error(r.error??"Failed to preview command.");P(r.command),X(r.command.proposedActions.map(a=>a.actionId))}catch(r){b(r instanceof Error?r.message:"Failed to preview command.")}finally{te(!1)}}},[$,j,n]),be=s.useCallback(async()=>{if(o!=null&&o.id){oe(!0),b(null);try{const e=await j("/orgx/api/orchestrator/commands/apply",{command_id:o.id,confirmed_action_ids:T,workspace_id:n??void 0});if(!e.command)throw new Error(e.error??"Failed to apply command.");P(e.command)}catch(e){b(e instanceof Error?e.message:"Failed to apply command.")}finally{oe(!1)}}},[o==null?void 0:o.id,j,T,n]),ce=T.length,we=(((le=o==null?void 0:o.proposedActions)==null?void 0:le.length)??0)>0,je=!!(o!=null&&o.id)&&ce>0&&!re,_e=s.useMemo(()=>{const e=(o==null?void 0:o.status)??"draft";return e==="completed"?"text-lime":e==="completed_with_errors"||e==="failed"?"text-amber-300":e==="applying"?"text-teal":"text-secondary"},[o==null?void 0:o.status]);return t.jsxs(ke,{open:p,onClose:h,maxWidth:"max-w-5xl",fitContent:!0,closeOnEscapeWhenTyping:!1,children:[t.jsx("div",{className:"border-b border-strong px-4 py-3",children:t.jsxs("div",{className:"flex items-start justify-between gap-3",children:[t.jsxs("div",{children:[t.jsx("p",{className:"text-caption uppercase tracking-[0.14em] text-secondary",children:"Realtime Orchestrator"}),t.jsx("h2",{className:"text-heading font-semibold text-white",children:"GPT Realtime 1.5"}),t.jsx("p",{className:"text-micro text-secondary",children:"Voice + tool-calls for initiative launch, decision resolution, and Next Up control."})]}),t.jsx("button",{type:"button",onClick:h,className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption text-secondary transition-colors hover:bg-white/[0.08] hover:text-white",children:"Close"})]})}),t.jsxs("div",{className:"grid gap-4 px-4 pb-4 pt-3 lg:grid-cols-[1.12fr_1fr]",children:[t.jsxs("section",{className:"space-y-3",children:[t.jsxs("div",{className:"rounded-xl border border-strong bg-white/[0.02] p-3",children:[t.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[t.jsx("span",{className:"text-caption uppercase tracking-[0.12em] text-secondary",children:"Session"}),t.jsx("span",{className:"text-micro text-secondary",children:xe})]}),t.jsx("div",{className:"flex flex-wrap items-center gap-2",children:f?t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",onMouseDown:ie,onMouseUp:K,onMouseLeave:()=>{S&&K()},onTouchStart:e=>{e.preventDefault(),ie()},onTouchEnd:e=>{e.preventDefault(),K()},className:`rounded-full border px-3 py-1.5 text-caption font-semibold transition-colors ${S?"border-teal/45 bg-teal/[0.16] text-teal":"border-white/[0.2] bg-white/[0.04] text-primary hover:bg-white/[0.1]"}`,children:S?"Listening… release to send":"Hold to talk"}),t.jsx("button",{type:"button",onClick:N,className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption text-secondary transition-colors hover:bg-white/[0.08] hover:text-primary",children:"Disconnect"})]}):t.jsx("button",{type:"button",disabled:v,onClick:()=>void ye(),className:"rounded-full border border-lime/35 bg-lime/[0.12] px-3 py-1.5 text-caption font-semibold text-lime transition-colors hover:bg-lime/[0.2] disabled:cursor-not-allowed disabled:opacity-60",children:v?"Connecting…":"Connect Realtime"})}),ne.length>0?t.jsx("div",{className:"mt-3 rounded-lg border border-strong bg-black/20 p-2",children:ne.map((e,r)=>t.jsx("p",{className:"text-micro text-secondary",children:e},`${e}-${r}`))}):null]}),t.jsxs("div",{className:"rounded-xl border border-strong bg-white/[0.02] p-3",children:[t.jsx("label",{className:"mb-2 block text-caption uppercase tracking-[0.12em] text-secondary",children:"Command Input"}),t.jsx("textarea",{value:$,onChange:e=>Z(e.target.value),rows:4,"data-modal-autofocus":"true",placeholder:"Example: create initiative called AI Readiness Audit for this workspace",className:"w-full rounded-lg border border-strong bg-[#040912] px-3 py-2 text-body text-primary placeholder:text-secondary focus:border-lime/35 focus:outline-none"}),W?t.jsxs("p",{className:"mt-2 text-caption text-secondary",children:["Assistant: ",t.jsx("span",{className:"text-primary",children:W})]}):null,t.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[t.jsx("button",{type:"button",disabled:ee||$.trim().length===0,onClick:()=>void ge(),className:"rounded-full border border-teal/35 bg-teal/[0.12] px-3 py-1.5 text-caption font-semibold text-teal transition-colors hover:bg-teal/[0.2] disabled:cursor-not-allowed disabled:opacity-60",children:ee?"Previewing…":"Preview Actions"}),t.jsx("button",{type:"button",disabled:!je,onClick:()=>void be(),className:"rounded-full border border-lime/35 bg-lime/[0.12] px-3 py-1.5 text-caption font-semibold text-lime transition-colors hover:bg-lime/[0.2] disabled:cursor-not-allowed disabled:opacity-60",children:re?"Applying…":`Apply (${ce})`})]})]})]}),t.jsxs("section",{className:"space-y-3",children:[t.jsxs("div",{className:"rounded-xl border border-strong bg-white/[0.02] p-3",children:[t.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[t.jsx("span",{className:"text-caption uppercase tracking-[0.12em] text-secondary",children:"Command Status"}),t.jsx("span",{className:`text-caption font-semibold ${_e}`,children:(o==null?void 0:o.status)??"idle"})]}),t.jsx("p",{className:"text-body text-primary",children:(o==null?void 0:o.humanSummary)??"Preview a command or use voice to trigger tool calls."}),(de=o==null?void 0:o.riskFlags)!=null&&de.length?t.jsxs("p",{className:"mt-2 text-caption text-amber-200",children:["Risk flags: ",o.riskFlags.join(", ")]}):null]}),t.jsxs("div",{className:"max-h-[360px] space-y-2 overflow-y-auto rounded-xl border border-strong bg-white/[0.02] p-3",children:[t.jsx("p",{className:"text-caption uppercase tracking-[0.12em] text-secondary",children:"Proposed Actions"}),we?o.proposedActions.map(e=>{const r=T.includes(e.actionId);return t.jsx("label",{className:"block rounded-lg border border-strong bg-[#040912] p-2 text-body",children:t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsx("input",{type:"checkbox",checked:r,onChange:a=>{const d=a.target.checked?[...T,e.actionId]:T.filter(m=>m!==e.actionId);X(d)},className:"mt-1"}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:"font-semibold text-primary",children:e.type}),t.jsx("p",{className:"text-caption text-secondary",children:e.reason}),t.jsxs("p",{className:"text-micro text-secondary",children:["confidence ",Ae(e.confidence)," • impact ",e.blockingImpact]})]})]})},e.actionId)}):t.jsx("p",{className:"text-body text-secondary",children:"No actions inferred yet."})]}),(((pe=o==null?void 0:o.results)==null?void 0:pe.length)??0)>0?t.jsxs("div",{className:"max-h-[220px] space-y-2 overflow-y-auto rounded-xl border border-strong bg-white/[0.02] p-3",children:[t.jsx("p",{className:"text-caption uppercase tracking-[0.12em] text-secondary",children:"Apply Results"}),o.results.map(e=>t.jsxs("div",{className:`rounded-lg border p-2 text-body ${e.ok?"border-lime/30 bg-lime/[0.08] text-lime":"border-amber-400/35 bg-amber-500/[0.12] text-amber-100"}`,children:[t.jsx("p",{className:"font-semibold",children:e.type}),t.jsx("p",{className:"text-caption",children:e.message}),e.error?t.jsxs("p",{className:"text-micro text-amber-200",children:["error: ",e.error]}):null]},`${e.actionId}-${e.type}`))]}):null]})]}),se?t.jsx("div",{className:"border-t border-amber-500/30 bg-amber-500/[0.12] px-4 py-2 text-caption text-amber-100",children:se}):null]})}export{Oe as RealtimeOrchestratorModal};