@useorgx/openclaw-plugin 0.7.0 → 0.7.3

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 (124) hide show
  1. package/README.md +42 -11
  2. package/dashboard/dist/assets/6mILZQ2a.js +1 -0
  3. package/dashboard/dist/assets/6mILZQ2a.js.br +0 -0
  4. package/dashboard/dist/assets/6mILZQ2a.js.gz +0 -0
  5. package/dashboard/dist/assets/{DG6y9wJI.js → 8dksYiq4.js} +1 -1
  6. package/dashboard/dist/assets/8dksYiq4.js.br +0 -0
  7. package/dashboard/dist/assets/8dksYiq4.js.gz +0 -0
  8. package/dashboard/dist/assets/{PAUiij_z.js → B5zYRHc3.js} +1 -1
  9. package/dashboard/dist/assets/B5zYRHc3.js.br +0 -0
  10. package/dashboard/dist/assets/B5zYRHc3.js.gz +0 -0
  11. package/dashboard/dist/assets/{CFGKRAzG.js → B6wPWJ35.js} +1 -1
  12. package/dashboard/dist/assets/B6wPWJ35.js.br +0 -0
  13. package/dashboard/dist/assets/B6wPWJ35.js.gz +0 -0
  14. package/dashboard/dist/assets/BWEwjt1W.js +1 -0
  15. package/dashboard/dist/assets/BWEwjt1W.js.br +0 -0
  16. package/dashboard/dist/assets/BWEwjt1W.js.gz +0 -0
  17. package/dashboard/dist/assets/BzRbDCAD.css +1 -0
  18. package/dashboard/dist/assets/BzRbDCAD.css.br +0 -0
  19. package/dashboard/dist/assets/BzRbDCAD.css.gz +0 -0
  20. package/dashboard/dist/assets/{DNxKz-GV.js → C8uM3AX8.js} +1 -1
  21. package/dashboard/dist/assets/C8uM3AX8.js.br +0 -0
  22. package/dashboard/dist/assets/C8uM3AX8.js.gz +0 -0
  23. package/dashboard/dist/assets/C9jy61eu.js +212 -0
  24. package/dashboard/dist/assets/C9jy61eu.js.br +0 -0
  25. package/dashboard/dist/assets/C9jy61eu.js.gz +0 -0
  26. package/dashboard/dist/assets/{CE38zU4U.js → CC63EwFD.js} +1 -1
  27. package/dashboard/dist/assets/CC63EwFD.js.br +0 -0
  28. package/dashboard/dist/assets/CC63EwFD.js.gz +0 -0
  29. package/dashboard/dist/assets/{nByHNHoW.js → CZaT3ob_.js} +1 -1
  30. package/dashboard/dist/assets/CZaT3ob_.js.br +0 -0
  31. package/dashboard/dist/assets/CZaT3ob_.js.gz +0 -0
  32. package/dashboard/dist/assets/{tS9mbYZi.js → CgaottFX.js} +1 -1
  33. package/dashboard/dist/assets/CgaottFX.js.br +0 -0
  34. package/dashboard/dist/assets/CgaottFX.js.gz +0 -0
  35. package/dashboard/dist/assets/CzCxAZlW.js +1 -0
  36. package/dashboard/dist/assets/CzCxAZlW.js.br +0 -0
  37. package/dashboard/dist/assets/CzCxAZlW.js.gz +0 -0
  38. package/dashboard/dist/assets/D3iMTYEj.js +1 -0
  39. package/dashboard/dist/assets/D3iMTYEj.js.br +0 -0
  40. package/dashboard/dist/assets/D3iMTYEj.js.gz +0 -0
  41. package/dashboard/dist/assets/{DjcdE6jC.js → D8JNX8kq.js} +1 -1
  42. package/dashboard/dist/assets/D8JNX8kq.js.br +0 -0
  43. package/dashboard/dist/assets/D8JNX8kq.js.gz +0 -0
  44. package/dashboard/dist/assets/DnA8dpj6.js +1 -0
  45. package/dashboard/dist/assets/DnA8dpj6.js.br +0 -0
  46. package/dashboard/dist/assets/DnA8dpj6.js.gz +0 -0
  47. package/dashboard/dist/assets/{DbNoijHm.js → IUexzymk.js} +1 -1
  48. package/dashboard/dist/assets/IUexzymk.js.br +0 -0
  49. package/dashboard/dist/assets/IUexzymk.js.gz +0 -0
  50. package/dashboard/dist/assets/{CZZTvkQZ.js → rttbDbEx.js} +1 -1
  51. package/dashboard/dist/assets/rttbDbEx.js.br +0 -0
  52. package/dashboard/dist/assets/rttbDbEx.js.gz +0 -0
  53. package/dashboard/dist/index.html +2 -2
  54. package/dashboard/dist/index.html.br +0 -0
  55. package/dashboard/dist/index.html.gz +0 -0
  56. package/dist/contracts/practice-exercise-schema.d.ts +216 -0
  57. package/dist/contracts/practice-exercise-schema.js +314 -0
  58. package/dist/contracts/shared-types.d.ts +2 -2
  59. package/dist/contracts/shared-types.js +22 -0
  60. package/dist/contracts/types.d.ts +20 -0
  61. package/dist/fs-utils.js +1 -13
  62. package/dist/http/helpers/auto-continue-engine.js +638 -24
  63. package/dist/http/helpers/autopilot-runtime.js +22 -7
  64. package/dist/http/helpers/autopilot-slice-utils.js +0 -2
  65. package/dist/http/helpers/kickoff-context.js +30 -0
  66. package/dist/http/helpers/slice-run-projections.js +19 -2
  67. package/dist/http/index.js +151 -93
  68. package/dist/http/routes/agent-suite.js +87 -0
  69. package/dist/http/routes/entities.js +1 -63
  70. package/dist/http/routes/live-snapshot.d.ts +1 -0
  71. package/dist/http/routes/live-snapshot.js +15 -4
  72. package/dist/http/routes/live-terminal.js +1 -108
  73. package/dist/http/routes/live-triage.js +1 -57
  74. package/dist/http/routes/mission-control-actions.js +0 -88
  75. package/dist/http/routes/mission-control-read.js +73 -8
  76. package/dist/mcp-http-handler.d.ts +3 -0
  77. package/dist/mcp-http-handler.js +2 -2
  78. package/dist/openclaw.plugin.json +1 -1
  79. package/dist/paths.js +14 -2
  80. package/dist/reporting/rollups.d.ts +0 -12
  81. package/dist/reporting/rollups.js +0 -35
  82. package/openclaw.plugin.json +1 -1
  83. package/package.json +7 -3
  84. package/dashboard/dist/assets/BXWDRGm-.js +0 -1
  85. package/dashboard/dist/assets/BXWDRGm-.js.br +0 -0
  86. package/dashboard/dist/assets/BXWDRGm-.js.gz +0 -0
  87. package/dashboard/dist/assets/CE38zU4U.js.br +0 -0
  88. package/dashboard/dist/assets/CE38zU4U.js.gz +0 -0
  89. package/dashboard/dist/assets/CFGKRAzG.js.br +0 -0
  90. package/dashboard/dist/assets/CFGKRAzG.js.gz +0 -0
  91. package/dashboard/dist/assets/CGGR2GZh.js +0 -1
  92. package/dashboard/dist/assets/CGGR2GZh.js.br +0 -0
  93. package/dashboard/dist/assets/CGGR2GZh.js.gz +0 -0
  94. package/dashboard/dist/assets/CPFiTmlw.js +0 -8
  95. package/dashboard/dist/assets/CPFiTmlw.js.br +0 -0
  96. package/dashboard/dist/assets/CPFiTmlw.js.gz +0 -0
  97. package/dashboard/dist/assets/CZZTvkQZ.js.br +0 -0
  98. package/dashboard/dist/assets/CZZTvkQZ.js.gz +0 -0
  99. package/dashboard/dist/assets/D-bf6hEI.js +0 -213
  100. package/dashboard/dist/assets/D-bf6hEI.js.br +0 -0
  101. package/dashboard/dist/assets/D-bf6hEI.js.gz +0 -0
  102. package/dashboard/dist/assets/DG6y9wJI.js.br +0 -0
  103. package/dashboard/dist/assets/DG6y9wJI.js.gz +0 -0
  104. package/dashboard/dist/assets/DNxKz-GV.js.br +0 -0
  105. package/dashboard/dist/assets/DNxKz-GV.js.gz +0 -0
  106. package/dashboard/dist/assets/DW_rKUic.js +0 -11
  107. package/dashboard/dist/assets/DW_rKUic.js.br +0 -0
  108. package/dashboard/dist/assets/DW_rKUic.js.gz +0 -0
  109. package/dashboard/dist/assets/DbNoijHm.js.br +0 -0
  110. package/dashboard/dist/assets/DbNoijHm.js.gz +0 -0
  111. package/dashboard/dist/assets/DjcdE6jC.js.br +0 -0
  112. package/dashboard/dist/assets/DjcdE6jC.js.gz +0 -0
  113. package/dashboard/dist/assets/FZYuCDnt.js +0 -1
  114. package/dashboard/dist/assets/FZYuCDnt.js.br +0 -0
  115. package/dashboard/dist/assets/FZYuCDnt.js.gz +0 -0
  116. package/dashboard/dist/assets/PAUiij_z.js.br +0 -0
  117. package/dashboard/dist/assets/PAUiij_z.js.gz +0 -0
  118. package/dashboard/dist/assets/h5biQs2I.css +0 -1
  119. package/dashboard/dist/assets/h5biQs2I.css.br +0 -0
  120. package/dashboard/dist/assets/h5biQs2I.css.gz +0 -0
  121. package/dashboard/dist/assets/nByHNHoW.js.br +0 -0
  122. package/dashboard/dist/assets/nByHNHoW.js.gz +0 -0
  123. package/dashboard/dist/assets/tS9mbYZi.js.br +0 -0
  124. package/dashboard/dist/assets/tS9mbYZi.js.gz +0 -0
@@ -1 +1 @@
1
- import{r as s,j as t}from"./cNrhgGc1.js";import{r as ke}from"./D-bf6hEI.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"./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 +1 @@
1
- import{j as r}from"./cNrhgGc1.js";import{w as s}from"./D-bf6hEI.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"./C9jy61eu.js";function i({className:e=""}){return r.jsx("div",{className:s("shimmer-skeleton",e),"aria-hidden":"true"})}export{i as S};
@@ -1 +1 @@
1
- import{r as l,j as e}from"./cNrhgGc1.js";import{d as r,r as u,E as j,K as f}from"./D-bf6hEI.js";import"./C-KIc3Wc.js";import"./BJgZIVUQ.js";import"./CxQ08qFN.js";function c(a){if(!a)return"unknown";try{return f(a)}catch{return"unknown"}}function k({open:a,onClose:o,outbox:t,onOpenSettings:p,onRefresh:m}){const[x,d]=l.useState(!1),h=l.useMemo(()=>Object.entries(t.pendingByQueue??{}).filter(([,s])=>typeof s=="number"&&s>0).sort((s,y)=>y[1]-s[1]),[t.pendingByQueue]),n=l.useMemo(()=>t.replayStatus==="error"?r.red:t.pendingTotal>0?r.amber:r.textMuted,[t.pendingTotal,t.replayStatus]),b=async()=>{try{await navigator.clipboard.writeText(JSON.stringify(t,null,2)),d(!0),setTimeout(()=>d(!1),1200)}catch{}};return e.jsx(u,{open:a,onClose:o,maxWidth:"max-w-3xl",fitContent:!0,children:e.jsxs("div",{className:"flex w-full flex-col",children:[e.jsxs("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(j,{type:"outbox",size:14}),e.jsx("span",{className:"truncate",children:"Outbox"}),e.jsx("span",{className:"rounded-full border px-2 py-0.5 text-caption font-semibold",style:{borderColor:`${n}30`,backgroundColor:`${n}14`,color:n},children:t.pendingTotal})]}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:"Buffered updates queued for replay to OrgX when connectivity is healthy."})]}),e.jsx("button",{type:"button",onClick:o,className:"rounded-md border border-strong bg-white/[0.03] px-2.5 py-1.5 text-caption text-primary transition-colors hover:bg-white/[0.08]","aria-label":"Close outbox modal",children:"Close"})]}),e.jsxs("div",{className:"mt-3 grid grid-cols-1 gap-2 sm:grid-cols-2",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-secondary",children:"Replay status"}),e.jsx("p",{className:"mt-1 text-body font-semibold",style:{color:n},children:t.replayStatus}),t.lastReplayError&&t.replayStatus==="error"&&e.jsx("p",{className:"mt-1 line-clamp-2 text-caption text-red-200/75",children:t.lastReplayError})]}),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-secondary",children:"Window"}),e.jsxs("p",{className:"mt-1 text-caption text-primary",children:["Oldest: ",e.jsx("span",{className:"font-semibold text-white",children:c(t.oldestEventAt)})]}),e.jsxs("p",{className:"mt-0.5 text-caption text-primary",children:["Newest: ",e.jsx("span",{className:"font-semibold text-white",children:c(t.newestEventAt)})]})]})]})]}),e.jsx("div",{className:"px-5 py-4",children:t.pendingTotal===0?e.jsx("div",{className:"rounded-xl border border-subtle bg-white/[0.02] p-4 text-body text-secondary",children:"Outbox is empty."}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-caption font-semibold uppercase tracking-[0.12em] text-secondary",children:"Queues"}),e.jsx("button",{type:"button",onClick:b,className:"rounded-md border border-strong bg-white/[0.03] px-2.5 py-1.5 text-caption text-secondary transition-colors hover:bg-white/[0.08]",children:x?"Copied":"Copy JSON"})]}),e.jsx("div",{className:"space-y-1.5",children:h.map(([i,s])=>e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-xl border border-white/[0.08] 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-medium text-white",children:i}),e.jsxs("p",{className:"mt-0.5 text-micro text-secondary",children:[s," event",s===1?"":"s"]})]}),e.jsx("span",{className:"rounded-full border px-2 py-0.5 text-caption font-semibold",style:{borderColor:`${r.amber}30`,backgroundColor:`${r.amber}14`,color:r.amber},children:s})]},i))}),e.jsx("div",{className:"rounded-xl border border-subtle bg-white/[0.02] px-3 py-2 text-caption text-secondary",children:"Replay is handled automatically by the OrgX sync service. If events stay queued, check Settings for API key and last replay errors."})]})}),e.jsxs("div",{className:"flex items-center justify-end gap-2 border-t border-subtle px-5 py-3",children:[e.jsx("button",{type:"button",onClick:m,className:"rounded-md border border-strong bg-white/[0.03] px-3 py-1.5 text-caption text-primary transition-colors hover:bg-white/[0.08]",children:"Refresh"}),e.jsx("button",{type:"button",onClick:p,className:"rounded-md border border-lime/25 bg-lime/10 px-3 py-1.5 text-caption font-semibold text-lime transition-colors hover:bg-lime/20",children:"Open settings"})]})]})})}export{k as BulkOutboxModal};
1
+ import{r as l,j as e}from"./cNrhgGc1.js";import{d as r,r as u,E as j,K as f}from"./C9jy61eu.js";import"./C-KIc3Wc.js";import"./BJgZIVUQ.js";import"./CxQ08qFN.js";function c(a){if(!a)return"unknown";try{return f(a)}catch{return"unknown"}}function k({open:a,onClose:o,outbox:t,onOpenSettings:p,onRefresh:m}){const[x,d]=l.useState(!1),h=l.useMemo(()=>Object.entries(t.pendingByQueue??{}).filter(([,s])=>typeof s=="number"&&s>0).sort((s,y)=>y[1]-s[1]),[t.pendingByQueue]),n=l.useMemo(()=>t.replayStatus==="error"?r.red:t.pendingTotal>0?r.amber:r.textMuted,[t.pendingTotal,t.replayStatus]),b=async()=>{try{await navigator.clipboard.writeText(JSON.stringify(t,null,2)),d(!0),setTimeout(()=>d(!1),1200)}catch{}};return e.jsx(u,{open:a,onClose:o,maxWidth:"max-w-3xl",fitContent:!0,children:e.jsxs("div",{className:"flex w-full flex-col",children:[e.jsxs("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(j,{type:"outbox",size:14}),e.jsx("span",{className:"truncate",children:"Outbox"}),e.jsx("span",{className:"rounded-full border px-2 py-0.5 text-caption font-semibold",style:{borderColor:`${n}30`,backgroundColor:`${n}14`,color:n},children:t.pendingTotal})]}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:"Buffered updates queued for replay to OrgX when connectivity is healthy."})]}),e.jsx("button",{type:"button",onClick:o,className:"rounded-md border border-strong bg-white/[0.03] px-2.5 py-1.5 text-caption text-primary transition-colors hover:bg-white/[0.08]","aria-label":"Close outbox modal",children:"Close"})]}),e.jsxs("div",{className:"mt-3 grid grid-cols-1 gap-2 sm:grid-cols-2",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-secondary",children:"Replay status"}),e.jsx("p",{className:"mt-1 text-body font-semibold",style:{color:n},children:t.replayStatus}),t.lastReplayError&&t.replayStatus==="error"&&e.jsx("p",{className:"mt-1 line-clamp-2 text-caption text-red-200/75",children:t.lastReplayError})]}),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-secondary",children:"Window"}),e.jsxs("p",{className:"mt-1 text-caption text-primary",children:["Oldest: ",e.jsx("span",{className:"font-semibold text-white",children:c(t.oldestEventAt)})]}),e.jsxs("p",{className:"mt-0.5 text-caption text-primary",children:["Newest: ",e.jsx("span",{className:"font-semibold text-white",children:c(t.newestEventAt)})]})]})]})]}),e.jsx("div",{className:"px-5 py-4",children:t.pendingTotal===0?e.jsx("div",{className:"rounded-xl border border-subtle bg-white/[0.02] p-4 text-body text-secondary",children:"Outbox is empty."}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-caption font-semibold uppercase tracking-[0.12em] text-secondary",children:"Queues"}),e.jsx("button",{type:"button",onClick:b,className:"rounded-md border border-strong bg-white/[0.03] px-2.5 py-1.5 text-caption text-secondary transition-colors hover:bg-white/[0.08]",children:x?"Copied":"Copy JSON"})]}),e.jsx("div",{className:"space-y-1.5",children:h.map(([i,s])=>e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-xl border border-white/[0.08] 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-medium text-white",children:i}),e.jsxs("p",{className:"mt-0.5 text-micro text-secondary",children:[s," event",s===1?"":"s"]})]}),e.jsx("span",{className:"rounded-full border px-2 py-0.5 text-caption font-semibold",style:{borderColor:`${r.amber}30`,backgroundColor:`${r.amber}14`,color:r.amber},children:s})]},i))}),e.jsx("div",{className:"rounded-xl border border-subtle bg-white/[0.02] px-3 py-2 text-caption text-secondary",children:"Replay is handled automatically by the OrgX sync service. If events stay queued, check Settings for API key and last replay errors."})]})}),e.jsxs("div",{className:"flex items-center justify-end gap-2 border-t border-subtle px-5 py-3",children:[e.jsx("button",{type:"button",onClick:m,className:"rounded-md border border-strong bg-white/[0.03] px-3 py-1.5 text-caption text-primary transition-colors hover:bg-white/[0.08]",children:"Refresh"}),e.jsx("button",{type:"button",onClick:p,className:"rounded-md border border-lime/25 bg-lime/10 px-3 py-1.5 text-caption font-semibold text-lime transition-colors hover:bg-lime/20",children:"Open settings"})]})]})})}export{k as BulkOutboxModal};
@@ -0,0 +1 @@
1
+ import{r as x,a as S,j as e}from"./cNrhgGc1.js";import{k as T,q as V,r as W,Z as u,d as o,M as $,b as E}from"./C9jy61eu.js";import{S as b}from"./CZaT3ob_.js";import"./C-KIc3Wc.js";import"./BJgZIVUQ.js";import"./CxQ08qFN.js";const f={draft:o.textMuted,in_review:o.amber,approved:o.lime,changes_requested:o.red,superseded:o.textMuted,archived:o.textMuted},U={draft:"Draft",in_review:"In Review",approved:"Approved",changes_requested:"Changes Requested",superseded:"Superseded",archived:"Archived"};function D(){return e.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:o.cyan,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"}),e.jsx("path",{d:"M14 2v4a2 2 0 0 0 2 2h4"}),e.jsx("path",{d:"M10 9H8"}),e.jsx("path",{d:"M16 13H8"}),e.jsx("path",{d:"M16 17H8"})]})}function z(){var M,_,C,L,I,q;const{state:l,close:m}=T(),g=null,j=!1,[c,p]=x.useState(null),{data:a,isLoading:F,isFetching:v,error:y,refetch:H}=S({queryKey:V.artifactDetail({artifactId:l.artifactId??"",authToken:g,embedMode:j}),enabled:!!l.artifactId,queryFn:async()=>{const i=E({authToken:g,embedMode:j}),s=await fetch(`/orgx/api/artifacts/${encodeURIComponent(l.artifactId)}`,{headers:i});if(!s.ok){const r=await s.json().catch(()=>null),d=(typeof(r==null?void 0:r.error)=="string"?r.error:null)??(r!=null&&r.error&&typeof r.error=="object"&&typeof r.error.message=="string"?r.error.message:null)??(typeof(r==null?void 0:r.message)=="string"?r.message:null),R=s.status===401?"Authentication required to view this artifact.":`Failed to fetch artifact (${s.status}).`;throw new Error(d!=null&&d.trim().length?d.trim():R)}return s.json()}}),t=a==null?void 0:a.artifact,A=(a==null?void 0:a.localFallback)===!0||((M=t==null?void 0:t.metadata)==null?void 0:M.local_fallback)===!0,w=(typeof(a==null?void 0:a.warning)=="string"&&a.warning.trim().length>0?a.warning:(_=t==null?void 0:t.metadata)==null?void 0:_.local_warning)??null,h=((C=t==null?void 0:t.metadata)==null?void 0:C.preview_markdown)??null,n=x.useMemo(()=>{if(!(t!=null&&t.metadata))return null;const i=[t.metadata.local_source_path,t.metadata.url,t.metadata.path,t.metadata.file_path,t.metadata.filepath,t.metadata.artifact_path,t.metadata.output_path];for(const s of i)if(typeof s=="string"&&s.trim().length>0)return s.trim();return null},[t==null?void 0:t.metadata]),k=x.useMemo(()=>n?/^https?:\/\//i.test(n)?n:`/orgx/api/live/filesystem/open?path=${encodeURIComponent(n)}`:null,[n]),N=((L=t==null?void 0:t.metadata)==null?void 0:L.external_url)??(t==null?void 0:t.artifact_url);x.useEffect(()=>{if(!c)return;const i=window.setTimeout(()=>p(null),2e3);return()=>window.clearTimeout(i)},[c]);const B=async(i,s)=>{try{await navigator.clipboard.writeText(i),p(`${s} copied`)}catch{p("Copy failed")}};return e.jsxs(W,{open:!!l.artifactId,onClose:m,maxWidth:"max-w-3xl",children:[F&&e.jsxs("div",{className:"p-6 space-y-4",children:[e.jsx(b,{className:"h-6 w-2/3"}),e.jsx(b,{className:"h-4 w-1/3"}),e.jsx(b,{className:"h-32 w-full"})]}),y&&e.jsxs("div",{className:"space-y-4 p-6",children:[e.jsxs("div",{className:"rounded-xl border border-red-300/22 bg-red-500/[0.08] p-4",children:[e.jsx("p",{className:"text-body font-semibold text-red-200",children:"Failed to load artifact"}),e.jsx("p",{className:"mt-1 text-caption leading-relaxed text-red-100/80",children:y.message})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",onClick:m,className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.08]",children:"Back to activity"}),e.jsx("button",{type:"button",onClick:()=>void H(),disabled:v,className:"rounded-full border border-red-300/22 bg-red-500/[0.08] px-3 py-1.5 text-caption font-semibold text-red-100 transition-colors hover:bg-red-500/[0.14] disabled:opacity-45",children:v?"Retrying…":"Retry"})]})]}),t&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-subtle px-5 py-4 sm:px-6",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx(D,{}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"truncate text-sm font-medium text-white",children:t.name}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[e.jsx(u,{tone:"muted",className:"text-micro uppercase tracking-[0.06em]",children:((I=t.catalog)==null?void 0:I.label)??t.artifact_type}),e.jsx(u,{tone:"neutral",className:"text-micro font-semibold uppercase tracking-[0.06em]",style:{color:f[t.status]??o.textMuted,backgroundColor:`${f[t.status]??o.textMuted}20`,borderColor:`${f[t.status]??o.textMuted}44`},children:U[t.status]??t.status}),((q=t.catalog)==null?void 0:q.domain)&&e.jsxs("span",{className:"text-micro text-faint",children:[t.catalog.domain," / ",t.catalog.stage]}),c&&e.jsx(u,{tone:"neutral",className:"text-micro text-secondary",children:c})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[N&&e.jsx("a",{href:N,target:"_blank",rel:"noopener noreferrer",className:"rounded-lg p-2 text-secondary transition-colors hover:bg-white/[0.08] hover:text-white",title:"Open source",children:e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M15 3h6v6"}),e.jsx("path",{d:"M10 14 21 3"}),e.jsx("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"})]})}),e.jsx("button",{onClick:m,className:"p-2 rounded-lg hover:bg-white/[0.06] text-secondary hover:text-white transition-colors",children:e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 6 6 18"}),e.jsx("path",{d:"m6 6 12 12"})]})})]})]}),e.jsxs("div",{className:"max-h-[65vh] overflow-y-auto px-5 py-4 sm:px-6 space-y-4",children:[A&&e.jsxs("div",{className:"rounded-xl border border-amber-300/25 bg-amber-500/[0.09] p-4",children:[e.jsx("p",{className:"text-caption font-semibold uppercase tracking-[0.08em] text-amber-100/90",children:"Local fallback artifact"}),e.jsx("p",{className:"mt-1 text-body text-amber-50/90",children:"This artifact is buffered locally because OrgX registration is currently unavailable."}),w&&e.jsxs("p",{className:"mt-1.5 text-caption text-amber-100/70",children:["Upstream error: ",w]}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[k&&e.jsx("a",{href:k,target:"_blank",rel:"noopener noreferrer",className:"rounded-full border border-amber-200/25 bg-black/25 px-3 py-1 text-caption font-semibold text-amber-100 transition-colors hover:bg-black/35",children:"Open local artifact"}),n&&e.jsx("button",{type:"button",onClick:()=>void B(n,"Artifact path"),className:"rounded-full border border-amber-200/25 bg-black/20 px-3 py-1 text-caption font-semibold text-amber-100 transition-colors hover:bg-black/35",children:"Copy path"})]})]}),t.description&&e.jsx("div",{children:e.jsx("p",{className:"text-body leading-relaxed text-primary",children:t.description})}),h&&e.jsx("div",{className:"rounded-xl border border-white/[0.06] bg-white/[0.02] p-4",children:e.jsx($,{mode:"block",text:h,className:"text-body leading-relaxed text-primary"})}),!t.description&&!h&&e.jsxs("div",{className:"py-12 text-center text-muted",children:[e.jsxs("svg",{className:"mx-auto mb-3 opacity-50",width:"32",height:"32",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"}),e.jsx("path",{d:"M14 2v4a2 2 0 0 0 2 2h4"})]}),e.jsx("p",{className:"text-sm",children:"No preview available"})]}),e.jsxs("div",{className:"flex flex-wrap gap-x-6 gap-y-1.5 text-micro text-faint",children:[e.jsxs("span",{children:["Entity: ",t.entity_type,"/",t.entity_id.slice(0,8)]}),e.jsxs("span",{children:["Version: ",t.version]}),e.jsxs("span",{children:["Updated:"," ",new Date(t.updated_at).toLocaleDateString(void 0,{month:"short",day:"numeric",year:"numeric"})]})]})]})]})]})}export{z as ArtifactViewerModal};
@@ -0,0 +1 @@
1
+ import{r as h,j as e,u as je,a as ne,b as ue}from"./cNrhgGc1.js";import{N as _e,w as F,i as ie,b as G,O as Se,Q as Ne,R as Pe,r as qe,S as re,T as Fe}from"./C9jy61eu.js";import{A as ke,m as se}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 Re(t,s){return t==="connected"&&s?"connected":t==="awaiting_browser_auth"||t==="pairing"||t==="starting"?"connecting":t==="error"?"error":"idle"}function Ce({phase:t}){const s=t==="connected"||t==="connecting"?"bg-[#BFFF00]":t==="error"?"bg-red-400":"bg-white/30",c=t==="connecting";return e.jsxs("span",{className:"relative flex h-2.5 w-2.5 shrink-0",children:[c&&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 Ie({phase:t}){const s=t==="connected"?"Connected":t==="connecting"?"Connecting...":t==="error"?"Connection issue":"Not connected",c=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(Ce,{phase:t}),e.jsx("span",{className:F("text-body font-semibold",c),children:s})]})}function Be({state:t,isStarting:s,isSubmittingManual:c,workspaceOptions:p,selectedWorkspaceId:n,onSelectWorkspace:k,onRefresh:f,onStartPairing:d,onSubmitManualKey:m,onBackToPairing:v,onUseManualKey:N,onDisconnect:g}){const y="https://www.useorgx.com/settings#security",u=Re(t.status,t.connectionVerified),E=t.status==="manual_key",x=t.status==="awaiting_browser_auth"||t.status==="pairing"||t.status==="starting",A=!!t.lastError,w=Ee(t.keySource),b=h.useMemo(()=>u==="connected"?"Live sync is active. Initiatives, tasks, and activity flow in real time.":u==="connecting"?"Approve the pairing in your browser to finish connecting.":u==="error"?"Trouble reaching OrgX. Try reconnecting or use a manual API key.":t.hasApiKey?"An API key is present but the connection has not been verified yet.":"Connect to OrgX to sync initiatives, tasks, activity, and decisions.",[u,t.hasApiKey]),T=u==="connected"?"border-[#BFFF00]/15":u==="error"?"border-rose-400/20":"border-white/[0.07]";return e.jsxs("div",{className:"flex min-h-0 flex-col gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-heading font-semibold text-white",children:"OrgX connection"}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:b})]}),A&&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(_e,{isSubmitting:c,onSubmit:m,onBack:v}):e.jsxs("div",{className:F("rounded-2xl border bg-white/[0.02] p-5",T),children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx(Ie,{phase:u}),e.jsx("button",{type:"button",onClick:()=>{f()},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"})]}),u==="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:S=>{const o=S.target.value;k(o==="__all__"?null:o)},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(S=>e.jsx("option",{value:S.id,children:S.title},S.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})]}),w&&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:w})]})]}),u==="idle"&&t.hasApiKey&&!t.connectionVerified&&e.jsxs("p",{className:"mt-3 text-caption text-amber-200/70",children:["Key detected",w?` from ${w}`:""," but not yet verified. Refresh or reconnect to activate live sync."]}),x&&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",u==="connected"?"mt-5":"mt-4"),children:u==="connected"?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>{d()},disabled:s,className:"rounded-full border border-strong bg-white/[0.03] px-4 py-2 text-body font-semibold text-primary transition-colors hover:bg-white/[0.06] disabled:cursor-not-allowed disabled:opacity-50",children:"Reconnect"}),e.jsx("button",{type:"button",onClick:()=>{g()},className:"rounded-full border border-rose-300/20 bg-transparent px-4 py-2 text-body font-semibold text-rose-200/70 transition-colors hover:bg-rose-400/10",children:"Disconnect"}),e.jsx("a",{href:y,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:()=>{d()},disabled:s,"data-modal-autofocus":"true",className:"inline-flex items-center gap-2 rounded-full bg-[#BFFF00] px-4 py-2 text-body font-semibold text-black transition-colors hover:bg-[#d3ff42] disabled:cursor-not-allowed disabled:opacity-50",children:s?"Connecting...":"Connect in browser"}),e.jsx("button",{type:"button",onClick:N,className:"rounded-full border border-strong bg-white/[0.03] px-4 py-2 text-body font-semibold text-primary transition-colors hover:bg-white/[0.06]",children:"Use API key"}),t.hasApiKey&&e.jsx("button",{type:"button",onClick:()=>{g()},className:"rounded-full border border-rose-300/20 bg-transparent px-4 py-2 text-body font-semibold text-rose-200/70 transition-colors hover:bg-rose-400/10",children:"Disconnect"})]})})]}),u!=="connected"&&e.jsxs("p",{className:"text-caption leading-relaxed text-muted",children:["Prefer user-scoped keys (",e.jsx("code",{className:"rounded bg-black/40 px-1",children:"oxk_..."}),"). They don't require a separate userId header."]})]})}const De=/^[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 ve(t){if(typeof t!="string")return null;const s=t.trim();return De.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 $e(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 Me(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:$e(t.runtime_settings)}}function he(t){if(!t||t.ok!==!0||!t.data||t.data.ok!==!0)return{projectId:null,agents:[]};const s=t.data,c=Array.isArray(s.agents)?s.agents:s.agent?[s.agent]:[];return{projectId:ve(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:c.map(Me)}}function Ae({authToken:t=null,embedMode:s=!1,enabled:c=!0}={}){var g,y,u,E;const p=je(),n=ie(),k=h.useMemo(()=>["agent-suite",{authToken:t,embedMode:s}],[t,s]),f=h.useMemo(()=>["agent-suite-runtime-settings",{authToken:t,embedMode:s}],[t,s]),d=ne({queryKey:k,enabled:c,queryFn:async()=>{if(n)return{ok:!1,error:"Agent suite controls are unavailable in demo mode."};const x=await fetch("/orgx/api/agent-suite/status",{headers:G({authToken:t,embedMode:s})}),A=await x.json().catch(()=>null);return x.ok?A:{ok:!1,error:(A==null?void 0:A.error)??`Failed to load agent suite (${x.status})`}},staleTime:1e4}),m=ne({queryKey:f,enabled:c,queryFn:async()=>{if(n)return{projectId:null,agents:[]};const x=await fetch("/orgx/api/agent-suite/runtime-settings",{headers:G({authToken:t,embedMode:s})}),A=await x.json().catch(()=>null);if(!x.ok){const w=A==null?void 0:A.error,b=typeof w=="string"?w.trim():"",T=b.includes("<!DOCTYPE")||b.includes("<html"),S=x.status===404?"Agent runtime settings endpoint is not available in this plugin build.":b.length>0&&!T?b:`Failed to load agent runtime settings (${x.status})`;throw new Error(S)}return he(A??null)},staleTime:1e4}),v=ue({mutationFn:async({dryRun:x,forceSkillPack:A}={})=>{if(n)return{ok:!1,error:"Agent suite install is unavailable in demo mode."};const w=await fetch("/orgx/api/agent-suite/install",{method:"POST",headers:G({authToken:t,embedMode:s,contentTypeJson:!0}),body:JSON.stringify({dryRun:!!x,forceSkillPack:!!A})}),b=await w.json().catch(()=>null);if(!w.ok)throw new Error((b==null?void 0:b.error)??`Failed to install agent suite (${w.status})`);return b},onSuccess:async()=>{await p.invalidateQueries({queryKey:k})}}),N=ue({mutationFn:async x=>{if(n)return{projectId:null,agents:[]};const A=ve(x.projectId??null),w=await fetch("/orgx/api/agent-suite/runtime-settings",{method:"PATCH",headers:G({authToken:t,embedMode:s,contentTypeJson:!0}),body:JSON.stringify({...A?{workspace_id:A}:{},agent_id:x.agentId,runtime_settings:{decision_v2_enabled:x.runtimeSettings.decisionV2Enabled,decision_dedupe_enabled:x.runtimeSettings.decisionDedupeEnabled,decision_evidence_required_for_blocking:x.runtimeSettings.decisionEvidenceRequiredForBlocking,decision_auto_resolve_guarded_enabled:x.runtimeSettings.decisionAutoResolveGuardedEnabled,question_auto_answer_enabled:x.runtimeSettings.questionAutoAnswerEnabled,question_auto_answer_timeout_sec:x.runtimeSettings.questionAutoAnswerTimeoutSec,question_auto_answer_policy:x.runtimeSettings.questionAutoAnswerPolicy,question_blocking_behavior:x.runtimeSettings.questionBlockingBehavior,question_policy_version:x.runtimeSettings.questionPolicyVersion,question_auto_answer_delay_seconds:x.runtimeSettings.questionAutoAnswerDelaySeconds,question_auto_answer_action:x.runtimeSettings.questionAutoAnswerAction,custom_run_instructions:x.runtimeSettings.customRunInstructions}})}),b=await w.json().catch(()=>null);if(!w.ok)throw new Error((b==null?void 0:b.error)??`Failed to save agent runtime settings (${w.status})`);return he(b??null)},onSuccess:async()=>{await p.invalidateQueries({queryKey:f})}});return{status:d.data??null,isLoading:d.isLoading,isRefetching:d.isRefetching,error:(d.data&&"error"in d.data?d.data.error:null)??((g=d.error)==null?void 0:g.message)??null,installError:((y=v.error)==null?void 0:y.message)??null,runtimeSettings:m.data??{projectId:null,agents:[]},runtimeSettingsError:((u=m.error)==null?void 0:u.message)??null,isRuntimeSettingsLoading:m.isLoading,isRuntimeSettingsRefetching:m.isRefetching,refetchRuntimeSettings:m.refetch,saveRuntimeSettings:N.mutate,saveRuntimeSettingsAsync:N.mutateAsync,saveRuntimeSettingsError:((E=N.error)==null?void 0:E.message)??null,isSavingRuntimeSettings:N.isPending,refetchStatus:d.refetch,install:v.mutate,installAsync:v.mutateAsync,resetInstall:v.reset,installResult:v.data??null,isInstalling:v.isPending}}function Q(t,s){return t===1?`${t} ${s}`:`${t} ${s}s`}function z({tone:t,children:s}){const c=h.useMemo(()=>t==="good"?"border-lime/25 bg-lime/[0.10] text-lime":t==="warn"?"border-amber-300/25 bg-amber-400/10 text-amber-100/90":"border-white/[0.10] bg-white/[0.02] text-primary",[t]);return e.jsx("span",{className:F("inline-flex items-center rounded-full border px-2.5 py-1 text-caption font-semibold",c),children:s})}const oe={conservative:"Conservative",balanced:"Balanced",autonomous:"Autonomous"},Te={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 Ue(t){return t?t.frozen&&t.pinnedChecksum?"conservative":!t.frozen&&t.pinnedChecksum?"balanced":!t.frozen&&!t.pinnedChecksum?"autonomous":null:null}function Le(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 Oe({plan:t,agentId:s,sampleTaskId:c}){var N;const p=t.workspaceFiles.filter(g=>g.action!=="noop"),n=p.filter(g=>g.action==="conflict").length,k=p.filter(g=>g.action==="create").length,f=p.filter(g=>g.action==="update").length,d=[];n>0&&d.push(`${Q(n,"managed file")} needs review before apply.`),t.skillPackUpdateAvailable&&d.push("Remote skill update is available; behavior could drift after refresh."),(N=t.skillPackPolicy)!=null&&N.frozen&&d.push("Skill pack is frozen; preview reflects pinned behavior only.");const m=[`Load draft simulation for ${s}.`,`Run sample task "${c}" 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."],v=[`${Q(t.openclawConfigAddedAgents.length,"agent")} added to OpenClaw config.`,`${Q(p.length,"workspace file")} changed (${k} create, ${f} update).`,`Progress stream expected at start and completion for sample "${c}".`];return{outcome:d.length>0?"warning":"ready",executionTrace:m,riskFlags:d,expectedOutputs:v,confidence:d.length>0?"Medium confidence: preview is deterministic but includes review-dependent flags.":"High confidence: preview is deterministic with no active risk flags."}}function Ke({authToken:t=null,embedMode:s=!1,enabled:c=!0,devMode:p=!1}){var B,J,ee,pe,xe;const[n,k]=h.useState(!1),[f,d]=h.useState(""),[m,v]=h.useState("triage-sample"),[N,g]=h.useState(null),[y,u]=h.useState(null),[E,x]=h.useState(!1),[A,w]=h.useState(null),[b,T]=h.useState(null),[S,o]=h.useState(null),[_,P]=h.useState(null),j=Ae({authToken:t,embedMode:s,enabled:c}),a=(B=j.status)!=null&&B.ok?j.status.data:null,$=((J=a==null?void 0:a.agents)==null?void 0:J.length)??0,C=((ee=a==null?void 0:a.openclawConfigAddedAgents)==null?void 0:ee.length)??0,R=h.useMemo(()=>{var r;return((r=a==null?void 0:a.workspaceFiles)==null?void 0:r.filter(D=>D.action!=="noop"))??[]},[a]),U=R.length,W=h.useMemo(()=>R.filter(r=>r.action==="create").length,[R]),M=h.useMemo(()=>R.filter(r=>r.action==="update").length,[R]),I=h.useMemo(()=>R.filter(r=>r.action==="conflict").length,[R]),V=h.useMemo(()=>{if(j.isLoading)return"Loading agent suite status...";if(j.error)return`Unable to read suite status: ${j.error}`;if(!a)return"Suite status unavailable.";if(I>0)return`${Q(I,"file")} to review.`;if(C===0&&U===0)return"Suite is installed and up to date.";const r=[];return C>0&&r.push(`will add ${Q(C,"agent")}`),U>0&&r.push(`will update ${Q(U,"file")}`),`Preview: ${r.join(", ")}.`},[U,I,C,a,j.error,j.isLoading]),L=(pe=j.installResult)!=null&&pe.ok?j.installResult:null,Z=!!(L!=null&&L.dryRun),X=Ue((a==null?void 0:a.skillPackPolicy)??null),i=async()=>{var D;if(!a||j.isInstalling||E)return;const r=f||(((D=a.agents[0])==null?void 0:D.id)??"unassigned-agent");k(!0),x(!0),u(null);try{const O=await j.installAsync({dryRun:!0});if(!O.ok)throw new Error(O.error??"Dry-run failed.");g(Oe({plan:O.data,agentId:r,sampleTaskId:m})),w(new Date().toISOString())}catch(O){u(O instanceof Error?O.message:"Dry-run failed.")}finally{x(!1)}},l=async r=>{await fetch("/orgx/api/skill-pack/policy",{method:"POST",headers:G({authToken:t,embedMode:s,contentTypeJson:!0}),body:JSON.stringify(r)}).then(async D=>{if(!D.ok){const O=await D.json().catch(()=>null);throw new Error((O==null?void 0:O.error)??`Failed to update policy (${D.status})`)}}),await j.refetchStatus()},q=async r=>{if(!(!(a!=null&&a.skillPackPolicy)||b)){P(null),o(null),T(r);try{await l(Le(r)),o(`${oe[r]} preset applied.`)}catch(D){P(D instanceof Error?D.message:"Failed to apply preset.")}finally{T(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:()=>{j.resetInstall(),j.refetchStatus()},disabled:j.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:j.isRefetching?"Refreshing...":"Refresh"}),e.jsx("button",{type:"button",onClick:()=>{i()},disabled:j.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:()=>{j.install({dryRun:!1,forceSkillPack:!0})},disabled:j.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:()=>{j.install({dryRun:!1})},disabled:j.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:j.isInstalling?"Installing...":"Install / Update"})]})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsx(z,{tone:j.error?"warn":"neutral",children:V}),a&&e.jsxs(e.Fragment,{children:[e.jsx(z,{tone:C===0?"good":"neutral",children:C===0?"agents configured":`${C} agents to install`}),e.jsxs(z,{tone:"neutral",children:[Q($,"agent")," total"]}),e.jsx(z,{tone:U===0?"good":"neutral",children:U===0?"no file changes":`${U} file changes`}),I>0&&e.jsx(z,{tone:"neutral",children:Q(I,"file to review")}),a.skillPackUpdateAvailable&&e.jsx(z,{tone:"warn",children:"skill update available"}),((xe=a.skillPackPolicy)==null?void 0:xe.frozen)&&e.jsx(z,{tone:"neutral",children:"skills frozen"})]})]}),j.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:j.installError}),L&&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:Z?"Dry run":"Applied"}),e.jsxs("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:[p&&L.operationId&&e.jsxs(e.Fragment,{children:["Operation ",e.jsx("code",{className:"rounded bg-black/40 px-1",children:L.operationId})," "]}),Z?"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:f,onChange:r=>d(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:m,onChange:r=>v(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"})]})]})]}),y&&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:y}),N&&e.jsxs("div",{role:"region","aria-live":"polite",className:"mt-3 rounded-lg border border-teal/30 bg-teal/[0.08] px-3 py-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("p",{className:"text-caption font-semibold uppercase tracking-[0.08em] text-teal",children:"Draft simulation"}),e.jsx(z,{tone:N.outcome==="ready"?"good":"warn",children:N.outcome==="ready"?"Ready to apply":"Review recommended"})]}),A&&e.jsx("p",{className:"mt-1 text-caption text-secondary",children:new Date(A).toLocaleString()}),e.jsxs("div",{className:"mt-3 grid gap-3 lg:grid-cols-3",children:[e.jsxs("div",{className:"rounded-lg border border-white/[0.08] bg-black/20 p-2.5",children:[e.jsx("p",{className:"text-caption font-semibold text-primary",children:"Execution trace"}),e.jsx("ol",{className:"mt-1.5 grid gap-1 text-caption text-secondary",children:N.executionTrace.map((r,D)=>e.jsxs("li",{children:[D+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:N.riskFlags.length>0?N.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:[N.expectedOutputs.map(r=>e.jsx("p",{children:r},r)),e.jsx("p",{className:"text-primary",children:N.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:()=>k(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(z,{tone:X?"good":"neutral",children:X?`Active: ${oe[X]}`:"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 D=X===r,O=b===r;return e.jsxs("button",{type:"button",onClick:()=>{q(r)},disabled:!!b,className:F("min-h-[44px] rounded-lg border px-3 py-2 text-left transition-colors disabled:cursor-not-allowed disabled:opacity-50",D?"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…":oe[r]}),e.jsx("p",{className:"mt-1 text-caption text-secondary",children:Te[r]})]},r)})}),S&&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:S}),_&&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:_})]}),a.skillPackPolicy&&e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>{var r;l({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?l({clearPin:!0}):l({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 (",$,")"]}),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(z,{tone:r.configuredInOpenclaw?"good":"neutral",children:r.configuredInOpenclaw?"configured":"to install"}),e.jsx(z,{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:Q(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:U})]}),(W>0||M>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:[W>0?`${W} create`:"0 create",","," ",M>0?`${M} 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 ge(t){return{ok:!0,updatedAt:null,providers:{openai:{configured:!!(t!=null&&t.openai),source:"none",masked:null},anthropic:{configured:!!(t!=null&&t.anthropic),source:"none",masked:null},openrouter:{configured:!!(t!=null&&t.openrouter),source:"none",masked:null}}}}function ze(){return{ok:!0,agentId:"demo",providers:{openai:{ok:!1,error:"Demo mode does not run provider probes."},anthropic:{ok:!1,error:"Demo mode does not run provider probes."},openrouter:{ok:!1,error:"Demo mode does not run provider probes."}}}}function Ve({authToken:t=null,embedMode:s=!1,enabled:c=!0}={}){var v,N;const p=je(),n=h.useMemo(()=>["byok-settings",{authToken:t,embedMode:s}],[t,s]),k=h.useMemo(()=>["byok-health",{authToken:t,embedMode:s}],[t,s]),f=ne({queryKey:n,enabled:c,queryFn:async()=>{if(ie())return ge();const g=await fetch("/orgx/api/settings/byok",{headers:G({authToken:t,embedMode:s})}),y=await g.json().catch(()=>null);return g.ok?y:{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:(y==null?void 0:y.error)??`Failed to load settings (${g.status})`}},staleTime:15e3}),d=ne({queryKey:k,enabled:!1,queryFn:async()=>{if(ie())return ze();const g=await fetch("/orgx/api/settings/byok/health",{headers:G({authToken:t,embedMode:s})}),y=await g.json().catch(()=>null);return g.ok?y:{ok:!1,agentId:"main",providers:{openai:{ok:!1,error:(y==null?void 0:y.error)??`Probe failed (${g.status})`},anthropic:{ok:!1,error:(y==null?void 0:y.error)??`Probe failed (${g.status})`},openrouter:{ok:!1,error:(y==null?void 0:y.error)??`Probe failed (${g.status})`}},error:(y==null?void 0:y.error)??`Probe failed (${g.status})`}}}),m=ue({mutationFn:async g=>{if(ie())return ge({openai:typeof g.openaiApiKey=="string"&&g.openaiApiKey.trim().length>0,anthropic:typeof g.anthropicApiKey=="string"&&g.anthropicApiKey.trim().length>0,openrouter:typeof g.openrouterApiKey=="string"&&g.openrouterApiKey.trim().length>0});const y=await fetch("/orgx/api/settings/byok",{method:"POST",headers:G({authToken:t,embedMode:s,contentTypeJson:!0}),body:JSON.stringify(g??{})}),u=await y.json().catch(()=>null);if(!y.ok)throw new Error((u==null?void 0:u.error)??`Failed to save settings (${y.status})`);return u},onSuccess:async()=>{await p.invalidateQueries({queryKey:n})}});return{status:f.data??null,isLoading:f.isLoading,error:((v=f.data)==null?void 0:v.error)??((N=f.error)==null?void 0:N.message)??null,refetchStatus:f.refetch,update:m.mutateAsync,isSaving:m.isPending,health:d.data??null,probe:d.refetch,isProbing:d.isFetching}}const me=[{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 be(t){return t==="openai"?"openaiApiKey":t==="anthropic"?"anthropicApiKey":"openrouterApiKey"}function He(t){var s;return((s=me.find(c=>c.id===t))==null?void 0:s.label)??t}function Qe({authToken:t=null,embedMode:s=!1,enabled:c=!0}){const p=Ve({authToken:t,embedMode:s,enabled:c}),n=p.status,k=p.health,[f,d]=h.useState({openai:"",anthropic:"",openrouter:""}),[m,v]=h.useState({openai:!1,anthropic:!1,openrouter:!1}),[N,g]=h.useState({openai:!1,anthropic:!1,openrouter:!1}),[y,u]=h.useState(null),[E,x]=h.useState(null);h.useEffect(()=>{c&&(d({openai:"",anthropic:"",openrouter:""}),v({openai:!1,anthropic:!1,openrouter:!1}),g({openai:!1,anthropic:!1,openrouter:!1}),u(null),x(null))},[c]);const A=h.useMemo(()=>n!=null&&n.ok?Number(n.providers.openai.configured)+Number(n.providers.anthropic.configured)+Number(n.providers.openrouter.configured):0,[n]),w=h.useMemo(()=>{var j;const o=me.map(a=>{var R;const $=(R=n==null?void 0:n.providers)==null?void 0:R[a.id],C=m[a.id]&&f[a.id].trim().length>0;return{id:a.id,label:a.label,configured:C||!!($!=null&&$.configured),source:C?"pending stored key":($==null?void 0:$.source)??"none",pending:C?"save":"none"}}),_=o.filter(a=>a.configured),P=_.length===0?"Run preview: launch blocked until at least one provider key is configured.":_.length===1?`Run preview: launches with ${(j=_[0])==null?void 0:j.label} as the only provider.`:`Run preview: launches with ${_.length} providers available for routing.`;return{providers:o,activeProviders:_,summary:P}},[m,n,f]),b=async o=>{if(!c)return;x(null);const _=f[o].trim();if(!m[o])return;if(!_){x(`Enter a ${He(o)} API key or use "Clear" to remove the saved key.`);return}const P=be(o);try{u(o),await p.update({[P]:_}),v(j=>({...j,[o]:!1})),d(j=>({...j,[o]:""})),g(j=>({...j,[o]:!1}))}finally{u(null)}},T=async o=>{x(null);const _=be(o);try{u(o),await p.update({[_]:null}),v(P=>({...P,[o]:!1})),d(P=>({...P,[o]:""})),g(P=>({...P,[o]:!1}))}finally{u(null)}},S=async()=>{x(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."}),A===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:[A," / 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:w.summary}),e.jsx("div",{className:"mt-3 grid gap-2 sm:grid-cols-3",children:w.providers.map(o=>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:o.label}),e.jsx("span",{className:F("rounded-full border px-2 py-0.5 text-micro uppercase tracking-[0.12em]",o.configured?"border-lime/30 bg-lime/[0.14] text-[#D8FFA1]":"border-white/[0.14] bg-white/[0.04] text-secondary"),children:o.configured?"Available":"Missing"})]}),e.jsxs("p",{className:"mt-1 text-caption text-muted",children:["Source: ",o.source,o.pending==="save"?" (not saved yet)":""]})]},o.id))})]}),e.jsx("div",{className:"grid grid-cols-1 gap-4",children:me.map(o=>{var M,I;const _=(M=n==null?void 0:n.providers)==null?void 0:M[o.id],P=(I=k==null?void 0:k.providers)==null?void 0:I[o.id],j=(_==null?void 0:_.masked)??null,a=(_==null?void 0:_.source)??"none",$=a==="stored",C=y===o.id,R=m[o.id]&&f[o.id].trim().length>0&&!p.isSaving&&!C,U=$&&!p.isSaving&&!C,W=$?"Update":"Save";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.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("p",{className:"text-body font-semibold text-white",children:o.label}),e.jsx("span",{className:F("rounded-full border px-2 py-0.5 text-micro uppercase tracking-[0.12em]",_!=null&&_.configured?"border-emerald-300/25 bg-emerald-400/10 text-emerald-100":"border-strong bg-white/[0.03] text-secondary"),children:_!=null&&_.configured?"Configured":"Missing"})]}),e.jsxs("p",{className:"mt-1 text-body text-secondary",children:[o.hint," ",e.jsxs("span",{className:"text-muted",children:["Env: ",e.jsx("code",{className:"rounded bg-black/40 px-1",children:o.envVar})]})]}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[a!=="none"&&e.jsxs("span",{className:"chip",children:["source: ",a]}),j&&e.jsxs("span",{className:"chip",children:["key: ",j]}),P&&e.jsx("span",{className:F("chip",P.ok?"text-emerald-100":"text-rose-100"),children:P.ok?`ready (${P.modelCount??0} models)`:"not ready"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>g(V=>({...V,[o.id]:!V[o.id]})),className:"rounded-lg border border-strong bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.08]",title:N[o.id]?"Hide key":"Show key",children:N[o.id]?"Hide":"Show"}),e.jsx("button",{type:"button",onClick:()=>void S(),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:V=>{V.preventDefault(),b(o.id)},children:[e.jsx("input",{type:"text",name:`provider-user-${o.id}`,autoComplete:"username",value:`${o.id}-key`,readOnly:!0,tabIndex:-1,"aria-hidden":"true",className:"sr-only"}),e.jsxs("label",{className:"block",htmlFor:`provider-key-${o.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-${o.id}`,name:`provider-key-${o.id}`,value:f[o.id],onChange:V=>{d(L=>({...L,[o.id]:V.target.value})),v(L=>({...L,[o.id]:!0})),E&&x(null)},type:N[o.id]?"text":"password",autoComplete:"new-password",spellCheck:!1,placeholder:`Paste ${o.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:!R,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:C?"Saving...":W}),e.jsx("button",{type:"button",onClick:()=>void T(o.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:m[o.id]?"Unsaved changes":" "})]})]})]},o.id)})})]})}const fe={engineering:"Engineering",product:"Product",design:"Design",marketing:"Marketing",sales:"Sales",operations:"Operations",orchestration:"Orchestration"},Y={decisionV2Enabled:!0,decisionDedupeEnabled:!0,decisionEvidenceRequiredForBlocking:!1,decisionAutoResolveGuardedEnabled:!0,questionAutoAnswerEnabled:!0,questionAutoAnswerTimeoutSec:60,questionAutoAnswerPolicy:"contextual",questionBlockingBehavior:"require_human",questionPolicyVersion:1,questionAutoAnswerDelaySeconds:60,questionAutoAnswerAction:"approve",customRunInstructions:""},Ge=/^[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){return typeof t!="string"?!1:Ge.test(t.trim())}function ye(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 We(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 Xe({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 te({label:t,description:s,enabled:c,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":c,onClick:()=>p(!c),className:F("relative inline-flex h-6 w-11 flex-shrink-0 rounded-full border transition-colors",c?"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",c?"left-[20px] bg-lime":"left-0.5 bg-white/70")})})]})}function Je({authToken:t=null,embedMode:s=!1,enabled:c=!0,initialDomain:p=null}){var Z,X;const n=Ae({authToken:t,embedMode:s,enabled:c}),k=(Z=n.status)!=null&&Z.ok?n.status.data.agents:[],f=n.runtimeSettings.agents,d=h.useMemo(()=>{const i=new Map;for(const l of n.runtimeSettings.agents)i.set(l.id,l.runtimeSettings);return i},[n.runtimeSettings.agents]),m=h.useMemo(()=>{const i=new Map;for(const l of f){const q=ye({name:l.name,id:l.id});!q||i.has(q)||i.set(q,{id:l.id,model:l.model,runtimeSettings:l.runtimeSettings})}return k.length>0?k.map(l=>{var q,B,J,ee;return{id:((q=i.get(l.domain))==null?void 0:q.id)??l.id,name:l.name,domain:l.domain,model:((B=i.get(l.domain))==null?void 0:B.model)??null,configStatus:((J=l.configHealth)==null?void 0:J.status)??null,runtimeSettings:((ee=i.get(l.domain))==null?void 0:ee.runtimeSettings)??d.get(l.id)??Y}}):f.map(l=>({id:l.id,name:l.name,domain:ye({name:l.name,id:l.id}),model:l.model,configStatus:null,runtimeSettings:l.runtimeSettings}))},[f,k,d]),v=h.useMemo(()=>{const i={};for(const l of m)i[l.id]=l.runtimeSettings;return i},[m]),[N,g]=h.useState(null),[y,u]=h.useState({}),[E,x]=h.useState(null),[A,w]=h.useState(null);h.useEffect(()=>{if(m.length===0){g(null);return}(!N||!m.some(i=>i.id===N))&&g(m[0].id),u(i=>{let l=!1;const q={...i};for(const B of m)q[B.id]||(q[B.id]=v[B.id]??Y,l=!0);return l?q:i})},[N,m,v]),h.useEffect(()=>{if(!p||m.length===0)return;const i=m.find(l=>l.domain===p);i&&i.id!==N&&g(i.id)},[N,m,p]);const b=h.useMemo(()=>m.find(i=>i.id===N)??null,[N,m]),T=i=>y[i]??v[i]??Y,S=b?T(b.id):null,o=h.useMemo(()=>m.filter(i=>!We(T(i.id),v[i.id])).map(i=>i.id),[m,y,v]),_=h.useMemo(()=>new Set(o),[o]),P=i=>{b&&u(l=>{const q=l[b.id]??v[b.id]??Y;return{...l,[b.id]:{...q,...i}}})},j=()=>{b&&u(i=>({...i,[b.id]:v[b.id]??Y}))},a=()=>{if(!S||m.length===0)return;const i={...S,customRunInstructions:S.customRunInstructions.trim().slice(0,4e3)};u(l=>{const q={...l};for(const B of m)q[B.id]={...i};return q}),x("Applied active agent settings to all agents."),w(null)},$=()=>{const i={};for(const l of m)i[l.id]=v[l.id]??Y;u(i),x(null),w(null)},C=async()=>{var i;if(!(o.length===0||n.isSavingRuntimeSettings)){x(null),w(null);try{for(const l of o){if(!ae(l)){const B=((i=m.find(J=>J.id===l))==null?void 0:i.name)??l;throw new Error(`Cannot save "${B}" because it is not linked to a valid OrgX agent UUID yet. Re-sync Agent Suite and try again.`)}const q=T(l);await n.saveRuntimeSettingsAsync({projectId:n.runtimeSettings.projectId,agentId:l,runtimeSettings:{...q,customRunInstructions:q.customRunInstructions.trim().slice(0,4e3)}})}x(`Saved runtime settings for ${o.length} ${o.length===1?"agent":"agents"}.`),w(null)}catch(l){w(l instanceof Error?l.message:"Failed to save agent settings.")}}},R=((X=n.runtimeSettingsError)==null?void 0:X.trim())??null,U=!!R,W=!!(R&&(R.toLowerCase().includes("endpoint is not available")||R.includes("(404)"))),M=U;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(m.length===0||!b||!S)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 I=o.length,V=_.has(b.id),L=b.domain?fe[b.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:M?W?"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:[m.length," agents"]}),!M&&e.jsxs("span",{className:F("rounded-full border px-3 py-1 text-caption",I>0?"border-lime/25 bg-lime/[0.12] text-lime":"border-white/[0.10] bg-white/[0.03] text-secondary"),children:[I," unsaved"]})]})]})}),M&&e.jsx("div",{className:"rounded-xl border border-amber-300/20 bg-[#12100A]/95 px-4 py-3",children:W?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:m.map(i=>{const l=i.id===b.id,q=_.has(i.id),B=ae(i.id);return e.jsxs("button",{type:"button",onClick:()=>g(i.id),className:F("w-full rounded-lg border px-3 py-2 text-left transition-colors",l?"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:[B?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(Xe,{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?fe[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:L}),e.jsx("h4",{className:"mt-1 text-heading font-semibold text-white",children:b.name}),ae(b.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."})]}),!M&&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:j,disabled:!V,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:M?"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(te,{label:"Decision envelope v2",description:"Emit richer context fields for diagnosis and replay.",enabled:S.decisionV2Enabled,onToggle:i=>P({decisionV2Enabled:i})}),e.jsx(te,{label:"Decision dedupe",description:"Collapse repeated blockers into the same pending decision.",enabled:S.decisionDedupeEnabled,onToggle:i=>P({decisionDedupeEnabled:i})}),e.jsx(te,{label:"Require evidence for blocking decisions",description:"Attach evidence before a blocking decision can be emitted.",enabled:S.decisionEvidenceRequiredForBlocking,onToggle:i=>P({decisionEvidenceRequiredForBlocking:i})}),e.jsx(te,{label:"Guarded auto-resolve",description:"Attempt deterministic remediation before escalating to humans.",enabled:S.decisionAutoResolveGuardedEnabled,onToggle:i=>P({decisionAutoResolveGuardedEnabled:i})}),e.jsx(te,{label:"Auto-answer unanswered questions",description:"If no human response arrives in time, auto-resolve questions sequentially.",enabled:S.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:S.questionAutoAnswerTimeoutSec,onChange:i=>{const l=Number.parseInt(i.target.value,10),q=Number.isFinite(l)?Math.max(10,Math.min(3600,l)):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:S.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:S.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:S.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:[S.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",M&&"hidden"),children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("div",{className:"min-h-[20px]",children:A?e.jsx("p",{className:"text-caption text-rose-100",children:A}):E?e.jsx("p",{className:"text-caption text-lime",children:E}):e.jsx("p",{className:"text-caption text-secondary",children:I>0?`${I} ${I===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:$,disabled:I===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:I===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 Ye({authToken:t=null,embedMode:s=!1,enabled:c=!0}={}){var k;const p=h.useMemo(()=>["usage-control-plane",{authToken:t,embedMode:s}],[t,s]),n=ne({queryKey:p,enabled:c,queryFn:async()=>{const f=await fetch("/orgx/api/usage/control-plane/summary",{headers:G({authToken:t,embedMode:s})}),d=await f.json().catch(()=>null);if(!f.ok){const m=(d&&typeof d=="object"&&"error"in d&&typeof d.error=="string"?d.error:null)??(d&&typeof d=="object"&&"message"in d&&typeof d.message=="string"?d.message:null)??`Failed to load usage summary (${f.status})`;throw new Error(m)}if(!d||typeof d!="object"||!("generatedAt"in d))throw new Error("Usage summary response is missing required fields.");return d},refetchInterval:6e4});return{summary:n.data??null,isLoading:n.isLoading,isFetching:n.isFetching,error:((k=n.error)==null?void 0:k.message)??null,refetch:n.refetch}}function H(t){return new Intl.NumberFormat("en-US").format(Math.max(0,Math.round(t)))}function le(t){return`$${(Math.max(0,t)/100).toFixed(2)}`}function ce(t){return typeof t!="number"||!Number.isFinite(t)?"—":`${Math.max(0,Math.round(t))}%`}function Ze(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((c,p)=>p.tokens-c.tokens).slice(0,s)}function et(t){const s=Date.parse(t.generatedAt);if(!Number.isFinite(s))return"Updated just now";const c=Math.max(0,Math.round((Date.now()-s)/6e4));return c<1?"Updated just now":c<60?`Updated ${c}m ago`:`Updated ${Math.round(c/60)}h ago`}function tt({authToken:t=null,embedMode:s=!1,enabled:c=!0}){const p=Ye({authToken:t,embedMode:s,enabled:c}),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((k,f)=>e.jsx("div",{className:"h-[92px] animate-pulse rounded-xl border border-white/[0.08] bg-white/[0.03]"},`usage-loading-${f}`))}):null,n?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:F("rounded-full border px-2.5 py-1 text-caption font-semibold",Ze(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:et(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:[H(n.actual.agentRuns),e.jsxs("span",{className:"ml-1 text-caption text-secondary",children:["/ ",n.plan.agentRunsLimit>0?H(n.plan.agentRunsLimit):"∞"]})]}),e.jsxs("p",{className:"mt-1 text-caption text-muted",children:["Forecast ",H(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:[H(n.actual.agentMinutes),e.jsxs("span",{className:"ml-1 text-caption text-secondary",children:["/ ",n.plan.agentMinutesLimit>0?H(n.plan.agentMinutesLimit):"∞"]})]}),e.jsxs("p",{className:"mt-1 text-caption text-muted",children:["Forecast ",H(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:H(n.actual.tokens)}),e.jsxs("p",{className:"mt-1 text-caption text-muted",children:["Forecast ",H(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:[le(n.actual.costCents),e.jsxs("span",{className:"ml-1 text-caption text-secondary",children:["/ ",n.plan.includedBudgetCents>0?le(n.plan.includedBudgetCents):"—"]})]}),e.jsxs("p",{className:"mt-1 text-caption text-muted",children:["Forecast ",le(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:ce(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:ce(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:ce(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(k=>{const f=n.actual.tokens>0?Math.max(0,Math.min(100,Math.round(k.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:k.label}),e.jsxs("span",{className:"text-caption text-primary",children:[H(k.tokens)," tokens · ",H(k.runs)," runs"]})]}),e.jsx("div",{className:"h-1.5 rounded-full bg-white/[0.08]",children:e.jsx("div",{className:"h-1.5 rounded-full bg-lime/80 transition-all",style:{width:`${Math.max(6,f)}%`}})})]},`usage-source-${k.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((k,f)=>e.jsxs("li",{className:"text-caption text-amber-100/90",children:["• ",k]},`usage-warning-${f}`))})]}):null]}):null]})}function st({connectionPhase:t,workspaceName:s}){const{displayName:c,avatarSeed:p,updateName:n,regenerateAvatar:k}=Se(),[f,d]=h.useState(!1),[m,v]=h.useState(""),N=h.useRef(null),g=h.useCallback(()=>{v(c),d(!0),requestAnimationFrame(()=>{var w;return(w=N.current)==null?void 0:w.focus()})},[c]),y=h.useCallback(()=>{n(m),d(!1)},[m,n]),u=h.useCallback(()=>{d(!1)},[]),E=h.useCallback(w=>{w.key==="Enter"?y():w.key==="Escape"&&u()},[y,u]),x=t==="connected",A=x?`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(se.div,{initial:{opacity:0,scale:.9},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.9},transition:{duration:.3,ease:Ne.easingEntrance},children:e.jsx(Pe,{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"}),f?e.jsxs("div",{className:"mt-1.5 flex items-center gap-2",children:[e.jsx("input",{ref:N,type:"text",value:m,onChange:w=>v(w.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:y,className:"rounded-lg bg-lime/[0.12] px-3 py-1.5 text-caption font-medium text-lime transition hover:bg-lime/[0.2]",children:"Save"}),e.jsx("button",{type:"button",onClick:u,className:"rounded-lg px-3 py-1.5 text-caption text-secondary transition hover:bg-white/[0.04]",children:"Cancel"})]}):e.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[e.jsx("h4",{className:"text-heading font-semibold text-white",children:c||"Anonymous"}),e.jsx("button",{type:"button",onClick:g,className:"rounded-md px-2 py-0.5 text-caption text-secondary transition hover:bg-white/[0.06] hover:text-white",children:c?"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",x?"bg-lime":t==="error"?"bg-red-400":"bg-white/30")})}),e.jsx("span",{className:"text-caption text-secondary",children:A})]}),e.jsx("button",{type:"button",onClick:k,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"})]})]})})}function de({label:t,description:s,enabled:c,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("button",{type:"button",role:"switch","aria-checked":c,onClick:()=>p(!c),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",c?"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",c?"left-[17px] bg-lime shadow-[0_0_8px_rgba(191,255,0,0.4)]":"left-[1px] bg-secondary")})})]})}function lt({open:t,onClose:s,activeTab:c,onChangeTab:p,demoMode:n,onToggleDemoMode:k,devMode:f=!1,onToggleDevMode:d,showSyntheticEntities:m,onToggleShowSyntheticEntities:v,workspaceOptions:N,selectedWorkspaceId:g,onSelectWorkspace:y,onboarding:u,authToken:E=null,embedMode:x=!1,agentBehaviorInitialDomain:A=null}){return e.jsx(qe,{open:t,onClose:s,maxWidth:"max-w-4xl",closeOnBackdropClick:!1,closeOnEscapeWhenTyping:!1,children:e.jsxs("div",{className:"flex h-full min-h-0 w-full min-w-0 flex-1 flex-col",children:[e.jsxs("div",{className:"w-full pt-6 px-5 sm:px-8",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-title font-medium text-white",children:"Settings"}),e.jsx("p",{className:"mt-1.5 text-body text-secondary",children:"Profile, OrgX connection, agent behavior, and provider keys."})]}),e.jsx("button",{type:"button",onClick:s,"aria-label":"Close settings",className:"inline-flex h-8 w-8 items-center justify-center rounded-full text-secondary transition-colors hover:bg-white/[0.06] hover:text-white focus:outline-none focus-visible:bg-white/[0.06]",children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 6L6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})})]}),e.jsx("div",{className:"mt-6 flex items-center gap-6 border-b border-white/[0.06]",role:"tablist","aria-label":"Settings tabs",children:[{id:"orgx",label:"OrgX"},{id:"agents",label:"Agents"},{id:"providers",label:"Provider keys"}].map(w=>{const b=c===w.id;return e.jsxs("button",{type:"button",role:"tab","aria-selected":b,onClick:()=>p(w.id),className:F("relative pb-3 text-caption font-medium transition-colors focus:outline-none",b?"text-white":"text-secondary hover:text-primary"),children:[w.label,b&&e.jsx(se.span,{layoutId:"settings-tab-indicator",className:"absolute bottom-0 left-0 right-0 h-px bg-white shadow-[0_0_8px_rgba(255,255,255,0.4)]","aria-hidden":"true",transition:{duration:.22,ease:Ne.easingStandard}})]},w.id)})})]}),e.jsx("div",{className:"min-h-0 w-full flex-1 overflow-y-auto px-5 py-6 sm:px-8",children:e.jsx(ke,{mode:"wait",children:c==="orgx"?e.jsxs(se.div,{...re,className:"grid gap-12",children:[e.jsx(st,{connectionPhase:u.state.status==="connected"?"connected":u.state.status==="error"?"error":u.state.status==="starting"||u.state.status==="awaiting_browser_auth"||u.state.status==="pairing"?"connecting":"idle",workspaceName:u.state.workspaceName}),e.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 features and synthetic data."}),e.jsxs("div",{className:"mt-4 grid gap-1 border-t border-white/[0.04] pt-2",children:[e.jsx(de,{label:"Developer mode",description:"Show technical details, config paths, and raw data in session inspectors.",enabled:f,onToggle:w=>d==null?void 0:d(w)}),e.jsx("div",{className:F("border-t border-white/[0.04]",f?"":"pointer-events-none opacity-40"),children:e.jsx(de,{label:"Demo mode",description:"Load local demo data for walkthroughs.",enabled:n,onToggle:k})}),e.jsx("div",{className:F("border-t border-white/[0.04]",f?"":"pointer-events-none opacity-40"),children:e.jsx(de,{label:"Show synthetic entities",description:"Include QA/test initiative IDs in the agent column.",enabled:m,onToggle:v})})]})]}),e.jsx(Be,{state:u.state,isStarting:u.isStarting,isSubmittingManual:u.isSubmittingManual,workspaceOptions:N,selectedWorkspaceId:g,onSelectWorkspace:y,onRefresh:u.refreshStatus,onStartPairing:u.startPairing,onSubmitManualKey:u.submitManualKey,onBackToPairing:u.backToPairing,onUseManualKey:u.setManualMode,onDisconnect:u.disconnect}),e.jsx(Ke,{authToken:E,embedMode:x,enabled:t&&!n,devMode:f}),e.jsx(tt,{authToken:E,embedMode:x,enabled:t&&!n})]},"orgx"):c==="agents"?e.jsx(se.div,{...re,children:e.jsx(Je,{authToken:E,embedMode:x,enabled:t&&!n,initialDomain:A})},"agents"):e.jsx(se.div,{...re,children:e.jsx(Qe,{authToken:E,embedMode:x,enabled:t&&!n})},"providers")})}),e.jsx("div",{className:"w-full border-t border-subtle px-5 py-2.5 sm:px-6",children:e.jsx(Fe,{compact:!0})})]})})}export{lt as SettingsModal};
@@ -1,2 +1,2 @@
1
- import{r as p,j as e}from"./cNrhgGc1.js";import{r as D,E as W,d as x,K}from"./D-bf6hEI.js";import"./C-KIc3Wc.js";import"./BJgZIVUQ.js";import"./CxQ08qFN.js";const q={blocked:0,failed:1,running:2,active:2,queued:3,in_progress:3,pending:4,paused:5,cancelled:6,completed:7,archived:8};function Q(n){if(!n)return 0;const b=Date.parse(n);return Number.isFinite(b)?b:0}function F(n){return Q(n.updatedAt??n.lastEventAt??n.startedAt)}function Y(n,b){const i=q[(n.status??"").toLowerCase()]??99,y=q[(b.status??"").toLowerCase()]??99;return i!==y?i-y:F(b)-F(n)}function G(n,b){const i=n.trim().toLowerCase();return i==="failed"?x.red:i==="blocked"||b>0?x.red:i==="running"||i==="active"||i==="in_progress"?x.lime:i==="queued"||i==="pending"?x.amber:i==="completed"?x.teal:x.textMuted}function H(n){switch(n){case"active":return{title:"Active Sessions",subtitle:"Running and queued work across agents."};case"blocked":return{title:"Blocked Sessions",subtitle:"Work that needs attention before it can proceed."};case"failed":return{title:"Failed Sessions",subtitle:"Runs that exited with an error and may need a retry."};default:return{title:"Sessions",subtitle:"All sessions visible to this dashboard."}}}function J(n,b){var j;const i=(b.status??"").toLowerCase(),y=((j=b.blockers)==null?void 0:j.length)??0;return n==="active"?["running","active","queued","pending","in_progress"].includes(i):n==="blocked"?i==="blocked"||y>0:n==="failed"?i==="failed":!0}function se({open:n,onClose:b,mode:i,sessions:y,onOpenSession:j,onRunAction:A,onRefetch:L,onSetNotice:v}){const{title:I,subtitle:P}=H(i),[S,_]=p.useState(""),[w,B]=p.useState(new Set),[d,k]=p.useState(null),[M,h]=p.useState(null),[N,C]=p.useState(null);p.useEffect(()=>{n&&(h(null),C(null))},[n]);const f=p.useMemo(()=>y.filter(t=>J(i,t)),[i,y]),g=p.useMemo(()=>{const t={};for(const o of f){const a=(o.status??"unknown").toLowerCase();t[a]=(t[a]??0)+1}const r=f.filter(o=>{var a;return(o.status??"").toLowerCase()==="blocked"||(((a=o.blockers)==null?void 0:a.length)??0)>0}).length,s=f.filter(o=>(o.status??"").toLowerCase()==="failed").length,l=f.filter(o=>["running","active","queued","pending","in_progress"].includes((o.status??"").toLowerCase())).length;return{total:f.length,active:l,blocked:r,failed:s,byStatus:t}},[f]),u=p.useMemo(()=>{const t=S.trim().toLowerCase(),r=[...f].sort(Y);return t?r.filter(s=>[s.title,s.agentName,s.agentId,s.runId,s.lastEventSummary].filter(Boolean).join(" ").toLowerCase().includes(t)):r},[S,f]);p.useEffect(()=>{n&&B(t=>{const r=new Set(u.map(l=>l.id)),s=new Set;for(const l of t)r.has(l)&&s.add(l);return s})},[u,n]);const m=w.size,T=u.length>0&&u.every(t=>w.has(t.id)),R=()=>{d||B(t=>u.length===0?t:T?new Set:new Set(u.map(r=>r.id)))},U=t=>{d||B(r=>{const s=new Set(r);return s.has(t)?s.delete(t):s.add(t),s})},O=async()=>{if(m===0||d)return;const t=[];for(const s of u){if(!w.has(s.id))continue;const l=s.blockers??[];if(l.length!==0){t.push(`- ${s.title} (${l.length} blocker${l.length===1?"":"s"})`);for(const o of l)t.push(` - ${o}`)}}const r=t.length>0?t.join(`
1
+ import{r as p,j as e}from"./cNrhgGc1.js";import{r as D,E as W,d as x,K}from"./C9jy61eu.js";import"./C-KIc3Wc.js";import"./BJgZIVUQ.js";import"./CxQ08qFN.js";const q={blocked:0,failed:1,running:2,active:2,queued:3,in_progress:3,pending:4,paused:5,cancelled:6,completed:7,archived:8};function Q(n){if(!n)return 0;const b=Date.parse(n);return Number.isFinite(b)?b:0}function F(n){return Q(n.updatedAt??n.lastEventAt??n.startedAt)}function Y(n,b){const i=q[(n.status??"").toLowerCase()]??99,y=q[(b.status??"").toLowerCase()]??99;return i!==y?i-y:F(b)-F(n)}function G(n,b){const i=n.trim().toLowerCase();return i==="failed"?x.red:i==="blocked"||b>0?x.red:i==="running"||i==="active"||i==="in_progress"?x.lime:i==="queued"||i==="pending"?x.amber:i==="completed"?x.teal:x.textMuted}function H(n){switch(n){case"active":return{title:"Active Sessions",subtitle:"Running and queued work across agents."};case"blocked":return{title:"Blocked Sessions",subtitle:"Work that needs attention before it can proceed."};case"failed":return{title:"Failed Sessions",subtitle:"Runs that exited with an error and may need a retry."};default:return{title:"Sessions",subtitle:"All sessions visible to this dashboard."}}}function J(n,b){var j;const i=(b.status??"").toLowerCase(),y=((j=b.blockers)==null?void 0:j.length)??0;return n==="active"?["running","active","queued","pending","in_progress"].includes(i):n==="blocked"?i==="blocked"||y>0:n==="failed"?i==="failed":!0}function se({open:n,onClose:b,mode:i,sessions:y,onOpenSession:j,onRunAction:A,onRefetch:L,onSetNotice:v}){const{title:I,subtitle:P}=H(i),[S,_]=p.useState(""),[w,B]=p.useState(new Set),[d,k]=p.useState(null),[M,h]=p.useState(null),[N,C]=p.useState(null);p.useEffect(()=>{n&&(h(null),C(null))},[n]);const f=p.useMemo(()=>y.filter(t=>J(i,t)),[i,y]),g=p.useMemo(()=>{const t={};for(const o of f){const a=(o.status??"unknown").toLowerCase();t[a]=(t[a]??0)+1}const r=f.filter(o=>{var a;return(o.status??"").toLowerCase()==="blocked"||(((a=o.blockers)==null?void 0:a.length)??0)>0}).length,s=f.filter(o=>(o.status??"").toLowerCase()==="failed").length,l=f.filter(o=>["running","active","queued","pending","in_progress"].includes((o.status??"").toLowerCase())).length;return{total:f.length,active:l,blocked:r,failed:s,byStatus:t}},[f]),u=p.useMemo(()=>{const t=S.trim().toLowerCase(),r=[...f].sort(Y);return t?r.filter(s=>[s.title,s.agentName,s.agentId,s.runId,s.lastEventSummary].filter(Boolean).join(" ").toLowerCase().includes(t)):r},[S,f]);p.useEffect(()=>{n&&B(t=>{const r=new Set(u.map(l=>l.id)),s=new Set;for(const l of t)r.has(l)&&s.add(l);return s})},[u,n]);const m=w.size,T=u.length>0&&u.every(t=>w.has(t.id)),R=()=>{d||B(t=>u.length===0?t:T?new Set:new Set(u.map(r=>r.id)))},U=t=>{d||B(r=>{const s=new Set(r);return s.has(t)?s.delete(t):s.add(t),s})},O=async()=>{if(m===0||d)return;const t=[];for(const s of u){if(!w.has(s.id))continue;const l=s.blockers??[];if(l.length!==0){t.push(`- ${s.title} (${l.length} blocker${l.length===1?"":"s"})`);for(const o of l)t.push(` - ${o}`)}}const r=t.length>0?t.join(`
2
2
  `):"No blockers found for selected sessions.";try{await navigator.clipboard.writeText(r),h("Copied blockers to clipboard.")}catch{h("Copy failed (clipboard unavailable).")}},$=async t=>{if(m===0||d)return;if(t==="cancel"){C({text:""});return}const r=u.filter(a=>w.has(a.id));h(null),k({action:t,processed:0,total:r.length});let s=0;const l=[];for(const a of r)try{await A(a,t)}catch(c){s+=1;const E=c instanceof Error?c.message:"unknown error";l.push(`${a.title||a.runId}: ${E}`)}finally{k(c=>c&&{...c,processed:Math.min(c.total,c.processed+1)})}const o=r.length-s;if(k(null),s>0){const a=l.length>0?` — ${l[0]}${l.length>1?` (+${l.length-1} more)`:""}`:"";h(`${t} finished: ${o} ok, ${s} failed.${a}`)}else h(`${t} finished: ${o} session${o===1?"":"s"}.`);try{await L()}catch{}t==="resume"?v(`Bulk resume requested: ${o} ok${s?`, ${s} failed`:""}.`):t==="pause"?v(`Bulk pause requested: ${o} ok${s?`, ${s} failed`:""}.`):t==="complete"&&v(`Bulk mark completed requested: ${o} ok${s?`, ${s} failed`:""}.`)},z=async()=>{if(!N||d||N.text.trim().toUpperCase()!=="CANCEL")return;const t=u.filter(a=>w.has(a.id));h(null),k({action:"cancel",processed:0,total:t.length}),C(null);let r=0;const s=[];for(const a of t)try{await A(a,"cancel")}catch(c){r+=1;const E=c instanceof Error?c.message:"unknown error";s.push(`${a.title||a.runId}: ${E}`)}finally{k(c=>c&&{...c,processed:Math.min(c.total,c.processed+1)})}const l=t.length-r;k(null);const o=s.length>0?` — ${s[0]}${s.length>1?` (+${s.length-1} more)`:""}`:"";h(`cancel finished: ${l} ok${r?`, ${r} failed`:""}.${o}`),v(`Bulk cancel requested: ${l} ok${r?`, ${r} failed`:""}.`);try{await L()}catch{}};return e.jsx(D,{open:n,onClose:b,maxWidth:"max-w-4xl",children:e.jsxs("div",{className:"flex h-full w-full flex-col",children:[e.jsxs("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(W,{type:"session",size:14}),e.jsx("span",{className:"truncate",children:I}),e.jsx("span",{className:"rounded-full border border-strong bg-white/[0.04] px-2 py-0.5 text-caption font-semibold text-primary",children:g.total})]}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:P}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-1.5",children:[e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.1] bg-white/[0.03] px-2 py-0.5 text-micro text-secondary",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full",style:{backgroundColor:x.teal}}),"Total ",e.jsx("span",{className:"font-semibold text-white",children:g.total})]}),e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.1] bg-white/[0.03] px-2 py-0.5 text-micro text-secondary",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full",style:{backgroundColor:g.active>0?x.lime:x.textMuted}}),"Active ",e.jsx("span",{className:"font-semibold text-white",children:g.active})]}),e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.1] bg-white/[0.03] px-2 py-0.5 text-micro text-secondary",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full",style:{backgroundColor:g.blocked>0?x.red:x.textMuted}}),"Blocked ",e.jsx("span",{className:"font-semibold text-white",children:g.blocked})]}),e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.1] bg-white/[0.03] px-2 py-0.5 text-micro text-secondary",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full",style:{backgroundColor:g.failed>0?x.red:x.textMuted}}),"Failed ",e.jsx("span",{className:"font-semibold text-white",children:g.failed})]})]})]}),e.jsx("button",{type:"button",onClick:b,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 bulk modal",children:"Close"})]}),e.jsxs("div",{className:"mt-4 flex flex-col gap-2 sm:flex-row sm:items-center",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("label",{className:"sr-only",htmlFor:"bulk-sessions-search",children:"Search sessions"}),e.jsx("input",{id:"bulk-sessions-search",value:S,onChange:t=>_(t.target.value),placeholder:"Search title, agent, run id…","data-modal-autofocus":"true",className:"w-full rounded-lg border border-strong bg-black/25 px-3 py-2 text-body text-white placeholder:text-muted focus:outline-none focus:ring-1 focus:ring-[#BFFF00]/35"})]}),e.jsx("button",{type:"button",onClick:R,disabled:u.length===0||!!d,className:"rounded-lg border border-strong bg-white/[0.03] px-3 py-2 text-caption text-primary transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:T?"Clear all":`Select all (${u.length})`})]}),M&&e.jsx("div",{className:"mt-3 rounded-xl border border-white/[0.08] bg-white/[0.02] px-3 py-2 text-body text-secondary",children:M}),N&&e.jsxs("div",{className:"mt-3 rounded-xl border border-red-400/25 bg-red-500/[0.06] px-3 py-2.5",children:[e.jsxs("p",{className:"text-body font-semibold text-red-200",children:["Cancel ",m," session",m===1?"":"s","?"]}),e.jsxs("p",{className:"mt-1 text-caption text-red-200/70",children:["This is destructive. Type ",e.jsx("span",{className:"font-semibold",children:"CANCEL"})," to confirm."]}),e.jsxs("div",{className:"mt-2 flex flex-col gap-2 sm:flex-row sm:items-center",children:[e.jsx("input",{value:N.text,onChange:t=>C({text:t.target.value}),placeholder:"CANCEL",className:"flex-1 rounded-lg border border-red-300/25 bg-black/30 px-3 py-2 text-body text-white placeholder:text-muted focus:outline-none focus:ring-1 focus:ring-red-300/40"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>C(null),className:"rounded-lg border border-strong bg-white/[0.03] px-3 py-2 text-caption text-primary transition-colors hover:bg-white/[0.08]",children:"Back"}),e.jsx("button",{type:"button",onClick:z,disabled:N.text.trim().toUpperCase()!=="CANCEL",className:"rounded-lg border border-red-300/25 bg-red-500/15 px-3 py-2 text-caption font-semibold text-red-200 transition-colors hover:bg-red-500/20 disabled:opacity-45",children:"Confirm cancel"})]})]})]})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-5 py-4",children:u.length===0?e.jsx("div",{className:"rounded-xl border border-subtle bg-white/[0.02] p-4 text-body text-secondary",children:"No sessions match this view."}):e.jsx("div",{className:"space-y-2",children:u.map(t=>{const r=w.has(t.id),s=t.blockers??[],l=G(t.status??"",s.length),o=t.updatedAt??t.lastEventAt??t.startedAt,a=[(t.agentName??t.agentId??"").trim()||"Unknown agent",(t.status??"unknown").toLowerCase(),o?K(o):null].filter(Boolean);return e.jsx("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.02] px-3 py-2.5 transition-colors hover:bg-white/[0.04]",style:{borderColor:r?`${x.lime}40`:"rgba(255,255,255,0.08)"},children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("input",{type:"checkbox",checked:r,onChange:()=>U(t.id),disabled:!!d,className:"mt-0.5 h-4 w-4 rounded border-white/20 bg-black/40 text-lime focus:ring-lime/40","aria-label":`Select session ${t.title}`}),e.jsx("button",{type:"button",onClick:()=>j(t),disabled:!!d,className:"min-w-0 flex-1 text-left",title:"Open session inspector",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-body font-medium text-white",children:t.title}),e.jsx("p",{className:"mt-0.5 text-caption text-secondary",children:a.join(" · ")}),t.lastEventSummary&&e.jsx("p",{className:"mt-1 line-clamp-2 text-caption text-secondary",children:t.lastEventSummary}),s.length>0&&e.jsxs("p",{className:"mt-1 text-micro text-red-200/80",children:[s.length," blocker",s.length===1?"":"s"," · ",s[0]]})]}),e.jsx("span",{className:"shrink-0 rounded-full border px-2 py-0.5 text-micro font-semibold uppercase tracking-[0.08em]",style:{borderColor:`${l}30`,backgroundColor:`${l}14`,color:l},children:(t.status??"unknown").toUpperCase()})]})})]})},t.id)})})}),e.jsxs("div",{className:"flex flex-col gap-2 border-t border-subtle px-5 py-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2 text-caption text-secondary",children:[d?e.jsxs("span",{children:[d.action," ",d.processed,"/",d.total]}):e.jsx("span",{children:m>0?`${m} selected`:"No selection"}),i==="blocked"&&e.jsx("button",{type:"button",onClick:O,disabled:m===0||!!d,className:"rounded-md border border-strong bg-white/[0.03] px-2.5 py-1.5 text-caption text-secondary transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:"Copy blockers"})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:()=>{const t=u.find(r=>w.has(r.id))??null;t&&j(t)},disabled:m!==1||!!d,className:"rounded-md border border-strong bg-white/[0.03] px-3 py-1.5 text-caption text-primary transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:"Open inspector"}),e.jsx("button",{type:"button",onClick:()=>void $("resume"),disabled:m===0||!!d,className:"rounded-md border border-lime/25 bg-lime/10 px-3 py-1.5 text-caption font-semibold text-lime transition-colors hover:bg-lime/20 disabled:opacity-45",children:"Resume selected"}),e.jsx("button",{type:"button",onClick:()=>void $("complete"),disabled:m===0||!!d,className:"rounded-md border border-teal/25 bg-teal/10 px-3 py-1.5 text-caption font-semibold text-teal transition-colors hover:bg-teal/20 disabled:opacity-45",children:"Mark completed"}),e.jsx("button",{type:"button",onClick:()=>void $("pause"),disabled:m===0||!!d,className:"rounded-md border border-strong bg-white/[0.03] px-3 py-1.5 text-caption text-primary transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:"Pause selected"}),e.jsx("button",{type:"button",onClick:()=>void $("cancel"),disabled:m===0||!!d,className:"rounded-md border border-red-300/25 bg-red-500/10 px-3 py-1.5 text-caption font-semibold text-red-200 transition-colors hover:bg-red-500/15 disabled:opacity-45",children:"Cancel selected"})]})]})]})})}export{se as BulkSessionsModal};
@@ -0,0 +1 @@
1
+ import{j as e,r as x}from"./cNrhgGc1.js";import{E as te,G as de,_ as ue,r as xe,A as me,Q as pe,x as w,$ as he,a0 as ke,X as be,K as P,Z as ge,d as l}from"./C9jy61eu.js";import{E as fe}from"./C8uM3AX8.js";import{A as je,m as h}from"./CxQ08qFN.js";import"./C-KIc3Wc.js";import"./BJgZIVUQ.js";function ve({breadcrumbs:s,typeBadge:n,onClose:c,footer:N,children:I}){return e.jsxs("div",{className:"flex h-full w-full min-h-0 flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-subtle px-5 py-3 sm:px-6",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0 text-body text-secondary",children:[s.map((b,g)=>e.jsxs("span",{className:"flex items-center gap-1.5 min-w-0",children:[g>0&&e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"flex-shrink-0 text-faint",children:e.jsx("path",{d:"m9 18 6-6-6-6"})}),b.onClick?e.jsx("button",{type:"button",onClick:b.onClick,className:`truncate transition-colors hover:text-primary ${g===s.length-1?"text-primary font-medium":""}`,children:b.label}):e.jsx("span",{className:`truncate ${g===s.length-1?"text-primary font-medium":""}`,children:b.label})]},g)),n&&e.jsxs("span",{className:"ml-1 inline-flex items-center gap-1 rounded-full border border-white/[0.1] bg-white/[0.04] px-2 py-0.5 text-micro uppercase tracking-[0.06em] text-secondary",children:[n.icon&&e.jsx(te,{type:n.icon,size:11,className:"opacity-90"}),n.label]})]}),e.jsx("button",{type:"button",onClick:c,"aria-label":"Close detail",className:"inline-flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-full border border-strong bg-white/[0.03] text-primary transition-colors hover:bg-white/[0.08] hover:text-white",children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 6L6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})})]}),e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto",children:I}),N&&e.jsx("div",{className:"flex-shrink-0 border-t border-subtle px-5 py-3 sm:px-6",children:N})]})}function ye(s){switch(s){case"running":return{background:`linear-gradient(to right, ${l.lime}, ${l.teal})`};case"blocked":return{background:`linear-gradient(to right, ${l.red}, ${l.amber})`};case"idle":return{background:`linear-gradient(to right, ${l.iris}99, transparent)`};default:return{background:`linear-gradient(to right, ${l.lime}B3, ${l.teal}66)`}}}function G(s){switch(s){case"running":return l.lime;case"blocked":return l.red;case"idle":return l.iris;case"queued":return l.teal;default:return l.amber}}function Y(s,n){return n?"Scope Under Review":s==="completed"?"Completed Scope":s==="running"?"Current Work":s==="blocked"?"Blocked Work":"Next Work"}function we(s){const n=s.sliceScope==="task"?"task":s.sliceScope==="milestone"?"milestone slice":"workstream slice",c=typeof s.sliceTaskCount=="number"&&s.sliceTaskCount>0?`${s.sliceTaskCount} ${s.sliceTaskCount===1?"task":"tasks"}`:null;return s.queueState==="running"?c?`Execution is in progress across ${c} in this ${n}.`:"Execution is in progress. Task detail will appear when scheduler state updates.":s.queueState==="blocked"?s.blockReason?s.blockReason:"Work is blocked pending a dependency or decision.":s.queueState==="queued"?c?`Queued with ${c} ready in this ${n}.`:"Queued at workstream scope. Task detail appears after dispatch.":s.queueState==="completed"?"Work is completed. No pending queued tasks.":"Work is idle and ready to start."}function K(s){return s===0?l.red:s===1?l.amber:s===2?l.iris:"rgba(255,255,255,0.5)"}function Q(s){return s===0?"P0":s===1?"P1":s===2?"P2":s===3?"P3":""}function Ne(s){switch(s){case"high":return{filled:5,color:l.lime};case"medium":return{filled:3,color:l.amber};case"low":return{filled:1,color:l.red};default:return{filled:0,color:l.iris}}}async function Ie(s){const n={};if(s.runId&&(n.runId=s.runId),s.sliceRunId&&(n.sliceRunId=s.sliceRunId),s.sessionId&&(n.sessionId=s.sessionId),Object.keys(n).length===0)throw new Error("No run identifier available for terminal open.");const c=await fetch("/orgx/api/live/terminal/open",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!c.ok){const N=await c.json().catch(()=>({}));throw new Error(N.error??`Terminal open failed (${c.status})`)}}const Ce={hidden:{opacity:0,y:-4},visible:s=>({opacity:1,y:0,transition:{duration:.28,delay:s*.04,ease:[.16,1,.3,1]}}),exit:{opacity:0,transition:{duration:.18}}},j={hidden:{opacity:0,y:8},visible:s=>({opacity:1,y:0,transition:{duration:.22,delay:s*.04,ease:pe.easingStandard}}),exit:{opacity:0,transition:{duration:.18}}};function ee(s){var N,I,b,g,C,T,S,F;if(s.source==="queue"){const{item:a,linkedSliceRun:o}=s;return{initiativeId:a.initiativeId,initiativeTitle:w(a.initiativeTitle),initiativeStatus:a.initiativeStatus,workstreamId:a.workstreamId,workstreamTitle:w(a.workstreamTitle),workstreamStatus:a.workstreamStatus,nextTaskTitle:a.nextTaskTitle?w(a.nextTaskTitle):null,nextTaskPriority:a.nextTaskPriority,nextTaskDueAt:a.nextTaskDueAt,agentId:a.runnerAgentId,agentName:a.runnerAgentName,agentSource:a.runnerSource,queueState:a.queueState,blockReason:a.blockReason?w(a.blockReason):null,sliceScope:a.sliceScope??null,sliceTaskCount:typeof a.sliceTaskCount=="number"&&Number.isFinite(a.sliceTaskCount)?Math.max(0,Math.floor(a.sliceTaskCount)):((N=a.sliceTaskIds)==null?void 0:N.length)??null,autoContinue:a.autoContinue,sliceRun:o,sessionId:null,runId:(o==null?void 0:o.runId)??null}}if(s.source==="in_progress"){const{row:a,sliceRun:o}=s;return{initiativeId:a.initiativeId,initiativeTitle:a.initiativeTitle?w(a.initiativeTitle):null,initiativeStatus:null,workstreamId:a.workstreamId,workstreamTitle:a.workstreamTitle?w(a.workstreamTitle):a.title,workstreamStatus:a.status,nextTaskTitle:null,nextTaskPriority:null,nextTaskDueAt:null,agentId:((I=a.session)==null?void 0:I.agentId)??null,agentName:((b=a.session)==null?void 0:b.agentName)??"OrgX",agentSource:null,queueState:a.status==="running"?"running":"queued",blockReason:null,sliceScope:(o==null?void 0:o.scope)??null,sliceTaskCount:typeof((g=o==null?void 0:o.scopeProgress)==null?void 0:g.totalTasks)=="number"?Math.max(0,Math.floor(o.scopeProgress.totalTasks-o.scopeProgress.completedTasks)):((C=o==null?void 0:o.taskIds)==null?void 0:C.length)??null,autoContinue:null,sliceRun:o,sessionId:((T=a.session)==null?void 0:T.id)??null,runId:a.runId}}const{sliceRun:n}=s,c=n.sourceClient?n.sourceClient.charAt(0).toUpperCase()+n.sourceClient.slice(1):"OrgX";return{initiativeId:n.initiativeId,initiativeTitle:null,initiativeStatus:null,workstreamId:n.workstreamId,workstreamTitle:n.workstreamTitle?w(n.workstreamTitle):"Work slice",workstreamStatus:n.status,nextTaskTitle:null,nextTaskPriority:null,nextTaskDueAt:null,agentId:null,agentName:c,agentSource:n.sourceClient,queueState:n.status==="needs_review"?"completed":"blocked",blockReason:n.status==="failed"&&n.statusExplainer||null,sliceScope:n.scope??null,sliceTaskCount:typeof((S=n.scopeProgress)==null?void 0:S.totalTasks)=="number"?Math.max(0,Math.floor(n.scopeProgress.totalTasks-n.scopeProgress.completedTasks)):((F=n.taskIds)==null?void 0:F.length)??null,autoContinue:null,sliceRun:n,sessionId:null,runId:n.runId}}function v(){return e.jsx("div",{className:"h-px bg-gradient-to-r from-transparent via-white/[0.06] to-transparent"})}function Ee({target:s,onClose:n,onPlayWorkstream:c,onStartAutoContinue:N,onMoveWorkstream:I,onRemoveFromQueue:b,onOpenSession:g,onFocusRunId:C,onOpenInitiative:T,onReviewActivity:S,onOpenDecisions:F,onAcceptSlice:a,onRejectSlice:o}){var Z,H;const $=s!==null,[ie,_]=x.useState(!1),[W,L]=x.useState(null),[u,A]=x.useState(null),[E,q]=x.useState(""),[B,y]=x.useState(null),U=x.useRef(null),M=x.useCallback(r=>{if(s&&(r.metaKey||r.ctrlKey)&&r.key==="Enter"){r.preventDefault();const d=ee(s);d.initiativeId&&d.workstreamId&&(c==null||c(d.initiativeId,d.workstreamId,d.agentId??void 0))}},[s,c]);if(x.useEffect(()=>{if($)return document.addEventListener("keydown",M),()=>document.removeEventListener("keydown",M)},[$,M]),x.useEffect(()=>{$||(L(null),_(!1),A(null),q(""),y(null))},[$]),x.useEffect(()=>{u&&requestAnimationFrame(()=>{var r;(r=U.current)==null||r.focus()})},[u]),!s)return null;const i=ee(s),t=i.sliceRun,m=de({sessionStatus:i.queueState,sessionPhase:i.workstreamStatus,sliceStatus:(t==null?void 0:t.status)??i.workstreamStatus,activityStatus:(t==null?void 0:t.runtimeState)??i.workstreamStatus??i.queueState,stopReason:i.queueState==="blocked"?"blocked":null,decisionRequired:((t==null?void 0:t.blockingDecisionCount)??0)>0,blockingDecisionCount:(t==null?void 0:t.blockingDecisionCount)??0,nonBlockingDecisionCount:Math.max(0,((t==null?void 0:t.decisionCount)??0)-((t==null?void 0:t.blockingDecisionCount)??0)),blockerCount:i.blockReason?1:0,blockerReason:i.blockReason}),se=m.status==="completed"?"text-lime border-lime/30 bg-lime/[0.12]":m.status==="failed"?"text-red-200 border-red-400/30 bg-red-500/[0.12]":m.status==="needs_attention"?"text-amber-200 border-amber-400/30 bg-amber-500/[0.12]":m.status==="in_progress"?"text-teal-200 border-teal-400/30 bg-teal-500/[0.12]":"text-secondary border-white/[0.14] bg-white/[0.04]",ne=m.tone==="critical"?"border-red-400/24 bg-red-500/[0.08]":m.tone==="warning"?"border-amber-400/24 bg-amber-500/[0.08]":m.tone==="positive"?"border-lime/24 bg-lime/[0.08]":"border-subtle bg-white/[0.02]",ae=[...i.initiativeTitle?[{label:i.initiativeTitle,onClick:i.initiativeId?()=>T==null?void 0:T(i.initiativeId):void 0}]:[],{label:i.workstreamTitle}],X=m.status==="in_progress",re=!!(i.initiativeId&&i.workstreamId&&!X),J=m.nextAction??(s.source==="needs_input"&&t?t.primaryAction==="resolve_decision"?"Resolve decision":t.primaryAction==="open_artifact"?"Open result":"Review activity":null),oe=x.useCallback(async r=>{try{L(null),_(!0),await Ie(r)}catch(d){L(d instanceof Error?d.message:"Unable to open terminal")}finally{_(!1)}},[]),V=x.useMemo(()=>i.sessionId?{sessionId:i.sessionId,runId:i.runId,sliceRunId:(t==null?void 0:t.sliceRunId)??null}:t!=null&&t.runId||t!=null&&t.sliceRunId?{runId:t.runId??null,sliceRunId:t.sliceRunId??null}:i.runId?{runId:i.runId,sliceRunId:(t==null?void 0:t.sliceRunId)??null}:null,[i.sessionId,i.runId,t]),le=V!==null,O=x.useMemo(()=>ue({initiativeId:i.initiativeId,initiativeTitle:i.initiativeTitle,workstreamId:i.workstreamId,workstreamTitle:i.workstreamTitle,taskIds:t==null?void 0:t.taskIds,milestoneIds:t==null?void 0:t.milestoneIds,scopeProgress:(t==null?void 0:t.scopeProgress)??null,status:(t==null?void 0:t.status)??i.queueState,agentName:i.agentName,agentId:i.agentId}),[i.initiativeId,i.initiativeTitle,i.workstreamId,i.workstreamTitle,t,i.queueState,i.agentName,i.agentId]),D=s.source==="needs_input"&&(t==null?void 0:t.status)==="needs_review",z=x.useCallback(async()=>{if(!t||!u)return;const r=E.trim(),d=t.runId??t.sliceRunId;if(u==="accept")try{y("Accepting…");const p=r?`Accepted: ${r}`:"Accepted from dashboard",k=await fetch(`/orgx/api/runs/${encodeURIComponent(d)}/actions/complete`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({reason:p})});if(!k.ok){const R=await k.json().catch(()=>null);y(`Error: ${(R==null?void 0:R.error)??(R==null?void 0:R.message)??k.status}`);return}y("Accepted!");try{a==null||a(t,r||void 0)}catch{}setTimeout(()=>n(),600)}catch(p){y(`Failed: ${p instanceof Error?p.message:"network error"}`)}else if(u==="reject"&&r)try{y("Sending feedback…");const p=await fetch(`/orgx/api/entities/run/${encodeURIComponent(d)}/comments`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({body:r,commentType:"review_feedback",severity:"warn",tags:["changes_requested"]})});if(!p.ok){const k=await p.json().catch(()=>null);y(`Error: ${(k==null?void 0:k.error)??(k==null?void 0:k.message)??p.status}`);return}y("Feedback sent!");try{o==null||o(t,r)}catch{}A(null),q("")}catch(p){y(`Failed: ${p instanceof Error?p.message:"network error"}`)}},[t,u,E,a,o,n]),ce=e.jsxs("div",{className:"space-y-2",children:[B&&e.jsx("div",{className:`flex items-center gap-1.5 rounded-lg px-3 py-1.5 text-[11px] font-medium ${B.startsWith("Error")||B.startsWith("Failed")?"bg-[#FF6B88]/10 text-[#FF6B88]":B.includes("…")?"bg-white/[0.04] text-white/60 animate-pulse":"bg-[#BFFF00]/10 text-[#BFFF00]"}`,children:B}),e.jsx(je,{children:u&&e.jsx(h.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.15},className:"overflow-hidden",children:e.jsxs("div",{className:"pb-2",children:[e.jsx("textarea",{ref:U,value:E,onChange:r=>q(r.target.value),onKeyDown:r=>{(r.metaKey||r.ctrlKey)&&r.key==="Enter"&&(r.preventDefault(),z()),r.key==="Escape"&&(r.preventDefault(),A(null),q(""))},placeholder:u==="accept"?"Optional note...":"What needs to change?",className:"w-full resize-none rounded-lg border border-white/[0.08] bg-white/[0.03] px-3 py-2 text-[13px] text-white/80 outline-none placeholder:text-white/25 focus:border-white/15 transition-colors",rows:2}),e.jsxs("div",{className:"mt-1.5 flex items-center justify-between",children:[e.jsx("button",{type:"button",onClick:()=>{A(null),q("")},className:"text-[11px] text-white/30 transition-colors hover:text-white/50",children:"Cancel"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[10px] text-white/20",children:u==="reject"&&!E.trim()?"Note required":"⌘Enter to confirm"}),e.jsx("button",{type:"button",onClick:z,disabled:u==="reject"&&!E.trim(),className:`inline-flex h-7 items-center gap-1 rounded-md px-3 text-[11px] font-semibold transition-colors disabled:opacity-30 ${u==="accept"?"bg-[#BFFF00]/12 text-[#BFFF00] hover:bg-[#BFFF00]/20":"bg-[#FF6B88]/12 text-[#FF6B88] hover:bg-[#FF6B88]/20"}`,children:u==="accept"?"Confirm accept":"Request changes"})]})]})]})})}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[s.source==="queue"&&i.initiativeId&&i.workstreamId&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>{b==null||b(i.initiativeId,i.workstreamId),n()},className:"rounded-md px-2.5 py-1.5 text-[12px] font-medium text-[#FF6B88]/70 transition-colors hover:bg-[#FF6B88]/[0.08] hover:text-[#FF6B88]",children:"Remove"}),e.jsx("button",{type:"button",onClick:()=>I==null?void 0:I(i.initiativeId,i.workstreamId,"top"),className:"rounded-md px-2.5 py-1.5 text-[12px] font-medium text-white/35 transition-colors hover:bg-white/[0.04] hover:text-white/60",children:"Move top"})]}),s.source==="in_progress"&&i.sessionId&&e.jsx("button",{type:"button",onClick:()=>{g==null||g(i.sessionId),n()},className:"rounded-md px-2.5 py-1.5 text-[12px] font-medium text-white/35 transition-colors hover:bg-white/[0.04] hover:text-white/60",children:"Open session"}),s.source==="needs_input"&&t&&t.primaryAction==="resolve_decision"&&e.jsx("button",{type:"button",onClick:()=>{F==null||F(),n()},className:"rounded-md px-2.5 py-1.5 text-[12px] font-medium text-[#0AD4C4]/70 transition-colors hover:bg-[#0AD4C4]/[0.08] hover:text-[#0AD4C4]",children:"Resolve decision"}),s.source==="needs_input"&&t&&e.jsx("button",{type:"button",onClick:()=>{S==null||S(t),n()},className:"rounded-md px-2.5 py-1.5 text-[12px] font-medium text-white/35 transition-colors hover:bg-white/[0.04] hover:text-white/60",children:"Review"}),i.runId&&e.jsx("button",{type:"button",onClick:()=>{C==null||C(i.runId),n()},className:"rounded-md px-2.5 py-1.5 text-[12px] font-medium text-white/35 transition-colors hover:bg-white/[0.04] hover:text-white/60",children:"Timeline"}),le&&e.jsx("button",{type:"button",onClick:()=>void oe(V),disabled:ie,className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-white/30 transition-colors hover:bg-white/[0.04] hover:text-white/50 disabled:opacity-40",title:"Open in terminal",children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("polyline",{points:"4 17 10 11 4 5"}),e.jsx("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]})})]}),e.jsx("div",{className:"flex-1"}),D&&o&&e.jsx("button",{type:"button",onClick:()=>A(u==="reject"?null:"reject"),className:`rounded-md px-2.5 py-1.5 text-[12px] font-medium transition-colors ${u==="reject"?"bg-[#FF6B88]/12 text-[#FF6B88]":"text-white/35 hover:bg-white/[0.04] hover:text-white/60"}`,children:"Request changes"}),D&&a&&e.jsxs("button",{type:"button",onClick:()=>{u==="accept"?z():A("accept")},className:"inline-flex h-8 items-center gap-1.5 rounded-lg bg-[#BFFF00]/12 px-4 text-[12px] font-semibold text-[#BFFF00] transition-colors hover:bg-[#BFFF00]/20",children:[e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}),"Accept"]}),re&&e.jsxs("button",{type:"button","data-modal-autofocus":"true",onClick:()=>{c==null||c(i.initiativeId,i.workstreamId,i.agentId??void 0),n()},className:"inline-flex h-8 items-center gap-1.5 rounded-lg bg-[#BFFF00]/12 px-4 text-[12px] font-semibold text-[#BFFF00] transition-colors hover:bg-[#BFFF00]/20",title:"Start (\\u2318 Enter)",children:[e.jsx("svg",{viewBox:"0 0 20 20",fill:"none","aria-hidden":!0,className:"h-3.5 w-3.5",children:e.jsx("path",{d:"M7 5.4v9.2c0 .7.75 1.15 1.38.83l7.6-4.6a.95.95 0 0 0 0-1.62l-7.6-4.64A.95.95 0 0 0 7 5.4Z",fill:"currentColor"})}),m.status==="completed"?"Restart":m.status==="needs_attention"?"Retry":"Start"]})]})]});let f=0;return e.jsx(xe,{open:$,onClose:n,maxWidth:"max-w-xl",children:e.jsxs("div",{className:"relative flex h-full min-h-0 flex-col",children:[e.jsx("div",{className:"h-[2px] flex-shrink-0 rounded-t-2xl",style:ye(i.queueState),"aria-hidden":!0}),e.jsx(ve,{breadcrumbs:ae,onClose:n,footer:ce,children:e.jsxs("div",{className:"px-6 py-5 space-y-5",children:[e.jsxs(h.div,{variants:Ce,initial:"hidden",animate:"visible",exit:"exit",custom:f++,className:"flex items-start gap-3",children:[e.jsx(me,{name:i.agentName??"OrgX",hint:i.agentSource??i.agentId,size:"md"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-[20px] font-semibold leading-snug text-white",children:i.workstreamTitle}),i.initiativeTitle&&e.jsx("p",{className:"mt-0.5 text-[10px] uppercase tracking-[0.1em] text-muted",children:i.initiativeTitle}),e.jsx("div",{className:"mt-1.5 flex flex-wrap items-center gap-1.5",children:e.jsxs("span",{className:`inline-flex items-center rounded-full border px-2 py-[1px] text-micro font-semibold uppercase tracking-[0.06em] ${se}`,children:[e.jsxs("span",{className:"relative mr-1.5 inline-block h-1.5 w-1.5",children:[e.jsx("span",{className:"absolute inset-0 rounded-full",style:{backgroundColor:G(i.queueState)}}),X&&e.jsx(h.span,{className:"absolute inset-0 rounded-full",style:{backgroundColor:G(i.queueState)},animate:{opacity:[1,.3,1],scale:[1,1.6,1]},transition:{duration:2,repeat:1/0,ease:"easeInOut"}})]}),m.label]})})]})]}),e.jsx(v,{}),s.source==="needs_input"&&t?e.jsxs(e.Fragment,{children:[e.jsxs(h.div,{variants:j,initial:"hidden",animate:"visible",exit:"exit",custom:f++,className:`rounded-xl border px-4 py-3 ${ne}`,children:[e.jsx("p",{className:"section-kicker",children:"What to do now"}),e.jsx("p",{className:"mt-1 text-body text-primary",children:m.sentence}),t.artifactCount>0?e.jsxs("p",{className:"mt-1 text-caption text-secondary",children:[t.artifactCount," artifact",t.artifactCount===1?"":"s"," ready for review."]}):null,t.blockingDecisionCount>0?e.jsxs("p",{className:"mt-1 text-caption text-secondary",children:[t.blockingDecisionCount," blocking decision",t.blockingDecisionCount===1?"":"s"," waiting."]}):null,J?e.jsxs("p",{className:"mt-1 text-caption text-secondary",children:["Recommended action: ",J]}):null]}),t.statusExplainer&&t.statusExplainer!==i.blockReason&&e.jsxs(h.div,{variants:j,initial:"hidden",animate:"visible",exit:"exit",custom:f++,children:[e.jsx("p",{className:"section-kicker",children:"What happened"}),e.jsx("p",{className:"mt-1 text-body text-secondary leading-relaxed",children:w(t.statusExplainer)})]}),t.lastEventSummary&&e.jsxs(h.div,{variants:j,initial:"hidden",animate:"visible",exit:"exit",custom:f++,children:[e.jsx("p",{className:"section-kicker",children:"Last activity"}),e.jsx("p",{className:"mt-1 text-caption text-white/50 leading-relaxed",children:w(t.lastEventSummary)})]}),e.jsx(v,{})]}):null,(i.blockReason||i.autoContinue||i.agentSource&&i.agentSource!=="assigned")&&e.jsxs(h.div,{variants:j,initial:"hidden",animate:"visible",exit:"exit",custom:f++,className:"space-y-2",children:[i.blockReason&&e.jsxs("div",{className:"rounded-lg border border-red-400/24 bg-red-500/[0.08] px-2.5 py-1.5 text-caption text-red-100/85",children:[e.jsx("p",{className:"mb-0.5 text-micro font-semibold uppercase tracking-[0.08em] text-red-200/70",children:"Why blocked"}),i.blockReason]}),i.autoContinue&&e.jsxs("div",{className:"flex items-center gap-2 text-caption text-secondary",children:[e.jsx("svg",{viewBox:"0 0 20 20",fill:"none","aria-hidden":!0,className:"h-3.5 w-3.5 flex-shrink-0 text-[#0AD4C4]",children:e.jsx("path",{d:"M6.1 13.25C4.25 13.25 2.8 11.8 2.8 10s1.45-3.25 3.3-3.25c3.15 0 4.35 6.5 8.05 6.5 1.85 0 3.3-1.45 3.3-3.25s-1.45-3.25-3.3-3.25c-3.7 0-4.9 6.5-8.05 6.5Z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),e.jsxs("span",{children:["Auto-continue: ",e.jsx("span",{className:"text-primary capitalize",children:i.autoContinue.status}),i.autoContinue.laneState&&e.jsxs("span",{className:"text-muted",children:[" · ",he(i.autoContinue.laneState)]})]})]}),((Z=i.autoContinue)==null?void 0:Z.laneBlockedReason)&&e.jsx("p",{className:"text-micro text-red-100/75",children:i.autoContinue.laneBlockedReason}),((H=i.autoContinue)==null?void 0:H.stopReason)&&e.jsx("p",{className:"text-micro text-amber-100/75",children:ke(i.autoContinue.stopReason)})]}),O.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(v,{}),e.jsxs(h.div,{variants:j,initial:"hidden",animate:"visible",exit:"exit",custom:f++,className:"space-y-2",children:[e.jsx("p",{className:"section-kicker",children:Y(i.queueState,D)}),e.jsx(be,{nodes:O,activeId:i.workstreamId}),!D&&(i.nextTaskPriority!==null||i.nextTaskDueAt)&&e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[i.nextTaskPriority!==null&&Q(i.nextTaskPriority)&&e.jsx("span",{className:"inline-flex rounded-full border px-2 py-[1px] text-micro font-semibold",style:{color:K(i.nextTaskPriority),borderColor:`${K(i.nextTaskPriority)}33`,backgroundColor:`${K(i.nextTaskPriority)}14`},children:Q(i.nextTaskPriority)}),i.nextTaskDueAt&&e.jsxs("span",{className:"text-micro text-secondary",children:["Due ",P(i.nextTaskDueAt)]})]})]})]}),O.length===0&&(i.sliceTaskCount!==null||i.sliceScope)&&e.jsxs(e.Fragment,{children:[e.jsx(v,{}),e.jsxs(h.div,{variants:j,initial:"hidden",animate:"visible",exit:"exit",custom:f++,className:"space-y-2",children:[e.jsx("p",{className:"section-kicker",children:Y(i.queueState,D)}),e.jsx("p",{className:"text-body text-secondary",children:we({queueState:i.queueState,blockReason:i.blockReason,sliceScope:i.sliceScope,sliceTaskCount:i.sliceTaskCount})})]})]}),t&&(t.startedAt||t.updatedAt||t.completedAt||t.failedAt)&&e.jsxs(e.Fragment,{children:[e.jsx(v,{}),e.jsxs(h.div,{variants:j,initial:"hidden",animate:"visible",exit:"exit",custom:f++,className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"section-kicker",children:"Timeline"}),t.scope&&t.scope!=="task"&&e.jsx(ge,{tone:t.scope==="milestone"?"cyan":"lime",children:t.scope}),t.confidence&&e.jsx("div",{className:"flex items-center gap-1 ml-auto",title:`Confidence: ${t.confidence}`,children:Array.from({length:5},(r,d)=>{const{filled:p,color:k}=Ne(t.confidence);return e.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full",style:{backgroundColor:d<p?k:"rgba(255,255,255,0.1)"}},d)})})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[t.startedAt&&e.jsxs("div",{children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Started"}),e.jsx("p",{className:"mt-0.5 text-caption text-primary",children:P(t.startedAt)})]}),t.completedAt?e.jsxs("div",{children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Completed"}),e.jsx("p",{className:"mt-0.5 text-caption text-primary",children:P(t.completedAt)})]}):t.failedAt?e.jsxs("div",{children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Failed"}),e.jsx("p",{className:"mt-0.5 text-caption text-red-100",children:P(t.failedAt)})]}):t.updatedAt&&t.updatedAt!==t.startedAt?e.jsxs("div",{children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Updated"}),e.jsx("p",{className:"mt-0.5 text-caption text-primary",children:P(t.updatedAt)})]}):null]})]})]}),t&&t.artifactCount>0&&t.artifacts.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(v,{}),e.jsxs(h.div,{variants:j,initial:"hidden",animate:"visible",exit:"exit",custom:f++,className:"space-y-2",children:[e.jsxs("p",{className:"section-kicker",children:["Artifacts ",e.jsx("span",{className:"text-muted tabular-nums",children:t.artifactCount})]}),e.jsx("div",{className:"space-y-1",children:t.artifacts.map((r,d)=>e.jsxs("div",{className:"flex items-center gap-2 rounded-lg px-2 py-1.5 transition-colors hover:bg-white/[0.04]",children:[e.jsx(te,{type:r.type==="pull_request"?"session":"workstream",size:13,className:"flex-shrink-0 opacity-75"}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-caption text-primary",children:r.title}),r.url&&e.jsx("a",{href:r.url,target:"_blank",rel:"noopener noreferrer",className:"flex-shrink-0 text-micro text-secondary transition-colors hover:text-white",title:"Open artifact",children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"}),e.jsx("polyline",{points:"15 3 21 3 21 9"}),e.jsx("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]})})]},r.id??d))})]})]}),t&&t.decisionCount>0&&e.jsxs(e.Fragment,{children:[e.jsx(v,{}),e.jsxs(h.div,{variants:j,initial:"hidden",animate:"visible",exit:"exit",custom:f++,className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("p",{className:"section-kicker",children:["Decisions ",e.jsx("span",{className:"text-muted tabular-nums",children:t.decisionCount})]}),t.blockingDecisionCount>0&&e.jsxs("span",{className:"inline-flex rounded-full border px-1.5 py-[0.5px] text-micro font-semibold tabular-nums",style:{color:l.red,borderColor:`${l.red}33`,backgroundColor:`${l.red}14`},children:[t.blockingDecisionCount," blocking"]})]}),t.decisionOptions.length>0&&e.jsx("div",{className:"space-y-1.5",children:t.decisionOptions.slice(0,4).map(r=>e.jsxs("div",{className:"rounded-lg border border-white/[0.06] bg-white/[0.02] px-3 py-2",children:[e.jsx("p",{className:"text-caption font-semibold text-primary",children:r.label}),r.description&&e.jsx("p",{className:"mt-0.5 text-micro leading-snug text-secondary",children:r.description})]},r.id))})]})]}),t&&(t.sliceRunId||t.runId)&&e.jsxs(e.Fragment,{children:[e.jsx(v,{}),e.jsxs(h.div,{variants:j,initial:"hidden",animate:"visible",exit:"exit",custom:f++,children:[e.jsx("p",{className:"section-kicker mb-2",children:"Notes"}),e.jsx(fe,{entityType:"run",entityId:t.runId??t.sliceRunId,variant:"inline"})]})]}),t&&(t.sourceClient||t.runtimeState||t.correlationId||t.runId)&&e.jsxs(e.Fragment,{children:[e.jsx(v,{}),e.jsxs("details",{className:"group",children:[e.jsxs("summary",{className:"flex cursor-pointer select-none items-center gap-1.5 py-1 text-micro uppercase tracking-[0.08em] text-muted transition-colors hover:text-secondary",children:[e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"transition-transform group-open:rotate-90",children:e.jsx("path",{d:"m9 18 6-6-6-6"})}),"Technical details"]}),e.jsxs("div",{className:"mt-2 grid grid-cols-2 gap-x-4 gap-y-2",children:[t.sourceClient&&e.jsxs("div",{children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Source"}),e.jsx("p",{className:"mt-0.5 font-mono text-caption text-primary",children:t.sourceClient})]}),t.runtimeState&&e.jsxs("div",{children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Runtime State"}),e.jsx("p",{className:"mt-0.5 font-mono text-caption text-primary",children:t.runtimeState})]}),t.runId&&e.jsxs("div",{className:"col-span-2",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Run ID"}),e.jsx("button",{type:"button",onClick:()=>{navigator.clipboard.writeText(t.runId)},className:"mt-0.5 font-mono text-caption text-primary transition-colors hover:text-white",title:"Click to copy",children:t.runId})]}),t.correlationId&&t.correlationId!==t.runId&&e.jsxs("div",{className:"col-span-2",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Correlation ID"}),e.jsx("button",{type:"button",onClick:()=>{navigator.clipboard.writeText(t.correlationId)},className:"mt-0.5 font-mono text-caption text-primary transition-colors hover:text-white",title:"Click to copy",children:t.correlationId})]})]})]})]}),W?e.jsxs(e.Fragment,{children:[e.jsx(v,{}),e.jsx("p",{className:"text-caption text-red-200/80",children:W})]}):null]})})]})})}export{Ee as SliceDetailModal};