@useorgx/openclaw-plugin 0.7.20 → 0.7.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dashboard/dist/assets/B6VftyY6.js +1 -0
- package/dashboard/dist/assets/B6VftyY6.js.br +0 -0
- package/dashboard/dist/assets/B6VftyY6.js.gz +0 -0
- package/dashboard/dist/assets/{Dm0CfDGr.js → BANQdlC4.js} +1 -1
- package/dashboard/dist/assets/BANQdlC4.js.br +0 -0
- package/dashboard/dist/assets/BANQdlC4.js.gz +0 -0
- package/dashboard/dist/assets/{_zpQCpjm.js → BPL4CL3c.js} +1 -1
- package/dashboard/dist/assets/BPL4CL3c.js.br +0 -0
- package/dashboard/dist/assets/BPL4CL3c.js.gz +0 -0
- package/dashboard/dist/assets/{DXVs61e1.js → BZCkOZ20.js} +1 -1
- package/dashboard/dist/assets/BZCkOZ20.js.br +0 -0
- package/dashboard/dist/assets/BZCkOZ20.js.gz +0 -0
- package/dashboard/dist/assets/{BYb6DARX.js → B_LdOJUa.js} +1 -1
- package/dashboard/dist/assets/B_LdOJUa.js.br +0 -0
- package/dashboard/dist/assets/B_LdOJUa.js.gz +0 -0
- package/dashboard/dist/assets/Bfp-wdwb.css +1 -0
- package/dashboard/dist/assets/Bfp-wdwb.css.br +0 -0
- package/dashboard/dist/assets/Bfp-wdwb.css.gz +0 -0
- package/dashboard/dist/assets/{DibzNd0I.js → BvFcH_Iy.js} +1 -1
- package/dashboard/dist/assets/BvFcH_Iy.js.br +0 -0
- package/dashboard/dist/assets/BvFcH_Iy.js.gz +0 -0
- package/dashboard/dist/assets/By0MIBj_.js +1 -0
- package/dashboard/dist/assets/By0MIBj_.js.br +0 -0
- package/dashboard/dist/assets/By0MIBj_.js.gz +0 -0
- package/dashboard/dist/assets/C0i7ABUU.js +212 -0
- package/dashboard/dist/assets/C0i7ABUU.js.br +0 -0
- package/dashboard/dist/assets/C0i7ABUU.js.gz +0 -0
- package/dashboard/dist/assets/CFB0MM7j.js +1 -0
- package/dashboard/dist/assets/CFB0MM7j.js.br +0 -0
- package/dashboard/dist/assets/CFB0MM7j.js.gz +0 -0
- package/dashboard/dist/assets/CQSRb1yu.js +1 -0
- package/dashboard/dist/assets/CQSRb1yu.js.br +0 -0
- package/dashboard/dist/assets/CQSRb1yu.js.gz +0 -0
- package/dashboard/dist/assets/{wa4jJQK9.js → CUoQoSm-.js} +1 -1
- package/dashboard/dist/assets/CUoQoSm-.js.br +0 -0
- package/dashboard/dist/assets/CUoQoSm-.js.gz +0 -0
- package/dashboard/dist/assets/Ckd1R1iE.js +1 -0
- package/dashboard/dist/assets/Ckd1R1iE.js.br +0 -0
- package/dashboard/dist/assets/Ckd1R1iE.js.gz +0 -0
- package/dashboard/dist/assets/{BGY6oI8h.js → CqRNb2EL.js} +1 -1
- package/dashboard/dist/assets/CqRNb2EL.js.br +0 -0
- package/dashboard/dist/assets/CqRNb2EL.js.gz +0 -0
- package/dashboard/dist/assets/{DAr4MfFk.js → DClUc9rw.js} +1 -1
- package/dashboard/dist/assets/DClUc9rw.js.br +0 -0
- package/dashboard/dist/assets/DClUc9rw.js.gz +0 -0
- package/dashboard/dist/assets/DF2PMTwT.js +1 -0
- package/dashboard/dist/assets/DF2PMTwT.js.br +0 -0
- package/dashboard/dist/assets/DF2PMTwT.js.gz +0 -0
- package/dashboard/dist/assets/{B014hrCe.js → DJYl7gyA.js} +2 -2
- package/dashboard/dist/assets/DJYl7gyA.js.br +0 -0
- package/dashboard/dist/assets/DJYl7gyA.js.gz +0 -0
- package/dashboard/dist/assets/{BoDhb8_y.js → DZtNMX0t.js} +2 -2
- package/dashboard/dist/assets/DZtNMX0t.js.br +0 -0
- package/dashboard/dist/assets/DZtNMX0t.js.gz +0 -0
- package/dashboard/dist/assets/DlEa8PI0.js +1 -0
- package/dashboard/dist/assets/DlEa8PI0.js.br +0 -0
- package/dashboard/dist/assets/DlEa8PI0.js.gz +0 -0
- package/dashboard/dist/assets/M4QxcXjh.js +1 -0
- package/dashboard/dist/assets/M4QxcXjh.js.br +0 -0
- package/dashboard/dist/assets/M4QxcXjh.js.gz +0 -0
- package/dashboard/dist/assets/{CV0sWMbv.js → MrW1ixGx.js} +1 -1
- package/dashboard/dist/assets/MrW1ixGx.js.br +0 -0
- package/dashboard/dist/assets/MrW1ixGx.js.gz +0 -0
- package/dashboard/dist/index.html +2 -2
- package/dashboard/dist/index.html.br +0 -0
- package/dashboard/dist/index.html.gz +0 -0
- package/dist/activity-store.js +68 -8
- package/dist/agent-run-store.js +162 -24
- package/dist/cli/orgx.d.ts +3 -0
- package/dist/config/resolution.d.ts +7 -0
- package/dist/config/resolution.js +13 -5
- package/dist/contracts/onboarding-state.d.ts +2 -0
- package/dist/contracts/onboarding-state.js +23 -0
- package/dist/contracts/shared-types.d.ts +45 -0
- package/dist/http/helpers/auto-continue-engine.d.ts +23 -0
- package/dist/http/helpers/auto-continue-engine.js +468 -85
- package/dist/http/helpers/autopilot-runtime.js +5 -1
- package/dist/http/helpers/autopilot-slice-utils.js +25 -1
- package/dist/http/helpers/decision-mapper.d.ts +1 -0
- package/dist/http/helpers/decision-mapper.js +19 -2
- package/dist/http/helpers/dispatch-lifecycle.js +3 -0
- package/dist/http/helpers/mission-control.d.ts +1 -0
- package/dist/http/helpers/mission-control.js +5 -2
- package/dist/http/helpers/slice-run-projections.d.ts +27 -0
- package/dist/http/helpers/slice-run-projections.js +198 -10
- package/dist/http/helpers/triage-mapper.js +499 -6
- package/dist/http/helpers/value-utils.d.ts +1 -0
- package/dist/http/helpers/value-utils.js +17 -0
- package/dist/http/index.d.ts +1 -0
- package/dist/http/index.js +179 -46
- package/dist/http/router.js +64 -9
- package/dist/http/routes/live-legacy.d.ts +19 -2
- package/dist/http/routes/live-legacy.js +110 -27
- package/dist/http/routes/live-snapshot.d.ts +16 -2
- package/dist/http/routes/live-snapshot.js +169 -25
- package/dist/http/routes/live-triage.js +6 -1
- package/dist/http/routes/mission-control-actions.d.ts +9 -0
- package/dist/http/routes/mission-control-actions.js +185 -7
- package/dist/http/routes/mission-control-read.d.ts +13 -0
- package/dist/http/routes/mission-control-read.js +100 -219
- package/dist/http/routes/onboarding.d.ts +1 -0
- package/dist/http/routes/onboarding.js +17 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +199 -123
- package/dist/outbox.d.ts +0 -2
- package/dist/outbox.js +259 -148
- package/dist/reporting/rollups.js +18 -11
- package/dist/runtime-instance-store.js +212 -58
- package/dist/stores/materialized-snapshot-store.d.ts +18 -0
- package/dist/stores/materialized-snapshot-store.js +91 -0
- package/dist/stores/sqlite-state.d.ts +6 -0
- package/dist/stores/sqlite-state.js +330 -0
- package/package.json +5 -1
- package/dashboard/dist/assets/B014hrCe.js.br +0 -0
- package/dashboard/dist/assets/B014hrCe.js.gz +0 -0
- package/dashboard/dist/assets/BCudUvwg.js +0 -1
- package/dashboard/dist/assets/BCudUvwg.js.br +0 -0
- package/dashboard/dist/assets/BCudUvwg.js.gz +0 -0
- package/dashboard/dist/assets/BGY6oI8h.js.br +0 -0
- package/dashboard/dist/assets/BGY6oI8h.js.gz +0 -0
- package/dashboard/dist/assets/BJI1Iy5v.css +0 -1
- package/dashboard/dist/assets/BJI1Iy5v.css.br +0 -0
- package/dashboard/dist/assets/BJI1Iy5v.css.gz +0 -0
- package/dashboard/dist/assets/BUvcp_7V.js +0 -1
- package/dashboard/dist/assets/BUvcp_7V.js.br +0 -0
- package/dashboard/dist/assets/BUvcp_7V.js.gz +0 -0
- package/dashboard/dist/assets/BV2Tf8S2.js +0 -212
- package/dashboard/dist/assets/BV2Tf8S2.js.br +0 -0
- package/dashboard/dist/assets/BV2Tf8S2.js.gz +0 -0
- package/dashboard/dist/assets/BYb6DARX.js.br +0 -0
- package/dashboard/dist/assets/BYb6DARX.js.gz +0 -0
- package/dashboard/dist/assets/BoDhb8_y.js.br +0 -0
- package/dashboard/dist/assets/BoDhb8_y.js.gz +0 -0
- package/dashboard/dist/assets/Bqk_l0k6.js +0 -1
- package/dashboard/dist/assets/Bqk_l0k6.js.br +0 -0
- package/dashboard/dist/assets/Bqk_l0k6.js.gz +0 -0
- package/dashboard/dist/assets/C-MOJWHs.js +0 -1
- package/dashboard/dist/assets/C-MOJWHs.js.br +0 -0
- package/dashboard/dist/assets/C-MOJWHs.js.gz +0 -0
- package/dashboard/dist/assets/CV0sWMbv.js.br +0 -0
- package/dashboard/dist/assets/CV0sWMbv.js.gz +0 -0
- package/dashboard/dist/assets/CaAkScfa.js +0 -1
- package/dashboard/dist/assets/CaAkScfa.js.br +0 -0
- package/dashboard/dist/assets/CaAkScfa.js.gz +0 -0
- package/dashboard/dist/assets/Ck5KlsPN.js +0 -1
- package/dashboard/dist/assets/Ck5KlsPN.js.br +0 -0
- package/dashboard/dist/assets/Ck5KlsPN.js.gz +0 -0
- package/dashboard/dist/assets/D2G51wQm.js +0 -1
- package/dashboard/dist/assets/D2G51wQm.js.br +0 -0
- package/dashboard/dist/assets/D2G51wQm.js.gz +0 -0
- package/dashboard/dist/assets/DAr4MfFk.js.br +0 -0
- package/dashboard/dist/assets/DAr4MfFk.js.gz +0 -0
- package/dashboard/dist/assets/DXVs61e1.js.br +0 -0
- package/dashboard/dist/assets/DXVs61e1.js.gz +0 -0
- package/dashboard/dist/assets/DibzNd0I.js.br +0 -0
- package/dashboard/dist/assets/DibzNd0I.js.gz +0 -0
- package/dashboard/dist/assets/Dm0CfDGr.js.br +0 -0
- package/dashboard/dist/assets/Dm0CfDGr.js.gz +0 -0
- package/dashboard/dist/assets/_zpQCpjm.js.br +0 -0
- package/dashboard/dist/assets/_zpQCpjm.js.gz +0 -0
- package/dashboard/dist/assets/uNGpYMSH.js +0 -1
- package/dashboard/dist/assets/uNGpYMSH.js.br +0 -0
- package/dashboard/dist/assets/uNGpYMSH.js.gz +0 -0
- package/dashboard/dist/assets/wa4jJQK9.js.br +0 -0
- package/dashboard/dist/assets/wa4jJQK9.js.gz +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as x,j as e}from"./Dj2k1r16.js";import{h as D,_ as Te,C as R,i as ce,b as Z,$ as Ue,n as De,a0 as Oe,z as Le,a1 as ze,a2 as ue}from"./C0i7ABUU.js";import{u as Be,c as de,b as we}from"./DMKyYAtD.js";import{m as J,A as Fe}from"./eeHXe_OQ.js";import{u as Ke}from"./BvFcH_Iy.js";import"./cX2e-TLi.js";import"./BjK42gtU.js";import"./BV0BcV1u.js";function Ve(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 He(t,s){return t==="connected"&&s?"connected":t==="awaiting_browser_auth"||t==="pairing"||t==="starting"?"connecting":t==="error"?"error":"idle"}function Ge({phase:t}){const s=t==="connected"||t==="connecting"?"bg-lime":t==="error"?"bg-red-400":"bg-white/30",a=t==="connecting";return e.jsxs("span",{className:"relative flex h-2.5 w-2.5 shrink-0",children:[a&&e.jsx("span",{className:R("absolute inline-flex h-full w-full animate-ping rounded-full opacity-40",s)}),e.jsx("span",{className:R("relative inline-flex h-2.5 w-2.5 rounded-full",s)})]})}function Qe({phase:t}){const s=t==="connected"?"Connected":t==="connecting"?"Connecting...":t==="error"?"Connection issue":"Not connected",a=t==="connected"?"text-lime":t==="error"?"text-red-400":"text-primary";return e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(Ge,{phase:t}),e.jsx("span",{className:R("text-body font-semibold",a),children:s})]})}function We({phase:t,hasApiKey:s,verified:a,workspaceName:c}){const i=[{id:"connect",label:"Connect",detail:"Provide credentials",done:s||a},{id:"verify",label:"Verify",detail:"Confirm live sync",done:a},{id:"scope",label:"Scope",detail:c||"Select workspace",done:t==="connected"}],h=t==="connecting"?"verify":t==="connected"?"scope":s?"verify":"connect";return e.jsx("ol",{className:"grid gap-2 rounded-xl border border-white/[0.08] bg-black/20 p-3 md:grid-cols-3",children:i.map((m,u)=>{const N=m.id===h;return e.jsxs("li",{className:"relative min-w-0",children:[u>0?e.jsx("span",{className:"pointer-events-none absolute -left-2 top-3 hidden h-px w-2 bg-white/[0.14] md:block","aria-hidden":!0}):null,e.jsxs("div",{className:R("rounded-lg border px-2.5 py-2",m.done?"border-lime/26 bg-lime/[0.08]":N?"border-teal/28 bg-teal/[0.10]":"border-white/[0.10] bg-white/[0.02]"),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:R("inline-flex h-4 w-4 items-center justify-center rounded-full border text-[10px] font-semibold",m.done?"border-lime/35 bg-lime/[0.18] text-lime":N?"border-teal/35 bg-teal/[0.16] text-teal-100":"border-white/[0.14] bg-white/[0.03] text-secondary"),children:u+1}),e.jsx("p",{className:"truncate text-caption font-semibold text-primary",children:m.label})]}),e.jsx("p",{className:"mt-1 truncate text-micro text-secondary",children:m.detail})]})]},m.id)})})}function pe({label:t,value:s}){return e.jsxs("div",{className:"flex items-center justify-between gap-2 text-caption",children:[e.jsx("span",{className:"text-secondary",children:t}),e.jsx("span",{className:"text-primary",children:s})]})}function Xe({state:t,isStarting:s,isSubmittingManual:a,workspaceOptions:c,selectedWorkspaceId:i,onSelectWorkspace:h,onRefresh:m,onStartPairing:u,onCancelPairing:N,onSubmitManualKey:g,onBackToPairing:w,onUseManualKey:b,onDisconnect:k}){const f="https://www.useorgx.com/settings#security",y=He(t.status,t.connectionVerified),p=t.status==="manual_key",v=t.status==="awaiting_browser_auth"||t.status==="pairing"||t.status==="starting"||y==="connected"&&typeof t.pairingId=="string"&&t.pairingId.trim().length>0&&typeof t.connectUrl=="string"&&t.connectUrl.trim().length>0,A=!!t.lastError,S=t.lastError?D(t.lastError):null,j=Ve(t.keySource),B=x.useMemo(()=>y==="connected"&&v?"A reconnect is pending in the browser. Your current OrgX session stays live until approval completes.":y==="connected"?"Live sync is active. Initiatives, tasks, and activity flow in real time.":y==="connecting"?"Approve the pairing in your browser to finish connecting.":y==="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.",[y,v,t.hasApiKey]),I=y==="connected"?"border-lime/15":y==="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:"Connection state"}),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:S}),p?e.jsx(Te,{isSubmitting:a,onSubmit:g,onBack:w}):e.jsxs("div",{className:R("rounded-2xl border bg-white/[0.02] p-5",I),children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 border-b border-white/[0.06] pb-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-lime/80",children:"Live state"}),e.jsx("div",{className:"mt-1",children:e.jsx(Qe,{phase:y})})]}),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-secondary transition-colors hover:bg-white/[0.06] hover:text-white",children:"Refresh"})]}),e.jsxs("div",{className:"mt-4 grid gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"mb-2 text-micro uppercase tracking-[0.12em] text-secondary",children:"Lifecycle"}),e.jsx(We,{phase:y,hasApiKey:t.hasApiKey,verified:t.connectionVerified,workspaceName:t.workspaceName})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-black/20 px-3.5 py-3",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Credentials"}),e.jsxs("div",{className:"mt-2.5 grid gap-1.5",children:[e.jsx(pe,{label:"API key",value:t.hasApiKey?"Detected":"Missing"}),e.jsx(pe,{label:"Verification",value:t.connectionVerified?"Verified":"Not verified"}),e.jsx(pe,{label:"Source",value:j||"none"})]})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-black/20 px-3.5 py-3",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Scope"}),y==="connected"?e.jsxs("div",{className:"mt-2",children:[e.jsx("label",{htmlFor:"settings-workspace-scope",className:"sr-only",children:"Workspace scope"}),e.jsxs("div",{className:"relative",children:[e.jsxs("select",{id:"settings-workspace-scope",value:i??"__all__",onChange:F=>{const W=F.target.value;h(W==="__all__"?null:W)},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"}),c.map(F=>e.jsx("option",{value:F.id,children:F.title},F.id))]}),e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"pointer-events-none absolute right-3 top-1/2 -translate-y-1/2 text-secondary",children:e.jsx("path",{d:"m6 9 6 6 6-6"})})]}),e.jsxs("p",{className:"mt-1.5 text-caption text-muted",children:["Connected account: ",e.jsx("span",{className:"text-secondary",children:t.workspaceName??"Unknown"})]})]}):e.jsx("p",{className:"mt-2 text-caption leading-relaxed text-secondary",children:"Selectable after verification completes."})]})]}),v&&t.connectUrl&&e.jsxs("div",{className:"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-lime",children:"Pairing pending"}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:y==="connected"?"Approve the reconnect in your browser. Your current connection remains active until approval completes.":"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-lime/30 bg-lime/15 px-3 py-1.5 text-caption font-semibold text-lime transition-colors hover:bg-lime/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("button",{type:"button",onClick:()=>{N()},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:"Cancel pairing"})]})]})]}),y==="idle"&&t.hasApiKey&&!t.connectionVerified&&e.jsxs("p",{className:"mt-3 text-caption text-amber-200/70",children:["Key detected",j?` from ${j}`:""," but not yet verified. Refresh or reconnect to activate live sync."]}),e.jsx("div",{className:R("mt-4 flex flex-wrap items-center gap-2 border-t border-white/[0.06] pt-4"),children:y==="connected"?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>{u()},disabled:s||v,className:"rounded-full border border-strong bg-white/[0.03] px-4 py-2 text-body font-semibold text-primary transition-colors hover:bg-white/[0.06] disabled:cursor-not-allowed disabled:opacity-50",children:v?"Reconnect pending":"Reconnect"}),e.jsx("button",{type:"button",onClick:()=>{k()},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:f,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:()=>{u()},disabled:s,"data-modal-autofocus":"true",className:"inline-flex items-center gap-2 rounded-full bg-lime 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:b,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:()=>{k()},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"})]})})]}),y!=="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 activate cleanly without requiring a separate userId header."]})]})}const Je=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;function $e(t){if(typeof t!="string")return null;const s=t.trim();return Je.test(s)?s:null}const H={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 Ye(t){return{decisionV2Enabled:typeof(t==null?void 0:t.decision_v2_enabled)=="boolean"?t.decision_v2_enabled:H.decisionV2Enabled,decisionDedupeEnabled:typeof(t==null?void 0:t.decision_dedupe_enabled)=="boolean"?t.decision_dedupe_enabled:H.decisionDedupeEnabled,decisionEvidenceRequiredForBlocking:typeof(t==null?void 0:t.decision_evidence_required_for_blocking)=="boolean"?t.decision_evidence_required_for_blocking:H.decisionEvidenceRequiredForBlocking,decisionAutoResolveGuardedEnabled:typeof(t==null?void 0:t.decision_auto_resolve_guarded_enabled)=="boolean"?t.decision_auto_resolve_guarded_enabled:H.decisionAutoResolveGuardedEnabled,questionAutoAnswerEnabled:typeof(t==null?void 0:t.question_auto_answer_enabled)=="boolean"?t.question_auto_answer_enabled:H.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))):H.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:H.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:H.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))):H.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))):H.questionAutoAnswerDelaySeconds,questionAutoAnswerAction:(t==null?void 0:t.question_auto_answer_action)==="reject"?"reject":H.questionAutoAnswerAction,customRunInstructions:typeof(t==null?void 0:t.custom_run_instructions)=="string"?t.custom_run_instructions:H.customRunInstructions}}function Ze(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:Ye(t.runtime_settings)}}function _e(t){if(!t||t.ok!==!0||!t.data||t.data.ok!==!0)return{projectId:null,agents:[]};const s=t.data,a=Array.isArray(s.agents)?s.agents:s.agent?[s.agent]:[];return{projectId:$e(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:a.map(Ze)}}function Me({authToken:t=null,embedMode:s=!1,enabled:a=!0}={}){var b,k,f,y;const c=Be(),i=ce(),h=x.useMemo(()=>["agent-suite",{authToken:t,embedMode:s}],[t,s]),m=x.useMemo(()=>["agent-suite-runtime-settings",{authToken:t,embedMode:s}],[t,s]),u=de({queryKey:h,enabled:a,queryFn:async()=>{if(i)return{ok:!1,error:"Agent suite controls are unavailable in demo mode."};const p=await fetch("/orgx/api/agent-suite/status",{headers:Z({authToken:t,embedMode:s})}),v=await p.json().catch(()=>null);if(!p.ok){const A=(v==null?void 0:v.error)??`Failed to load agent suite (${p.status})`;return{ok:!1,error:D(String(A))}}return v},staleTime:1e4}),N=de({queryKey:m,enabled:a,queryFn:async()=>{if(i)return{projectId:null,agents:[]};const p=await fetch("/orgx/api/agent-suite/runtime-settings",{headers:Z({authToken:t,embedMode:s})}),v=await p.json().catch(()=>null);if(!p.ok){const A=v==null?void 0:v.error,S=typeof A=="string"?A.trim():"",j=S.includes("<!DOCTYPE")||S.includes("<html"),B=p.status===404?"Agent runtime settings endpoint is not available in this plugin build.":S.length>0&&!j?S:`Failed to load agent runtime settings (${p.status})`;throw new Error(D(B))}return _e(v??null)},staleTime:1e4}),g=we({mutationFn:async({dryRun:p,forceSkillPack:v}={})=>{if(i)return{ok:!1,error:"Agent suite install is unavailable in demo mode."};const A=await fetch("/orgx/api/agent-suite/install",{method:"POST",headers:Z({authToken:t,embedMode:s,contentTypeJson:!0}),body:JSON.stringify({dryRun:!!p,forceSkillPack:!!v})}),S=await A.json().catch(()=>null);if(!A.ok){const j=(S==null?void 0:S.error)??`Failed to install agent suite (${A.status})`;throw new Error(D(String(j)))}return S},onSuccess:async()=>{await c.invalidateQueries({queryKey:h})}}),w=we({mutationFn:async p=>{if(i)return{projectId:null,agents:[]};const v=$e(p.projectId??null),A=await fetch("/orgx/api/agent-suite/runtime-settings",{method:"PATCH",headers:Z({authToken:t,embedMode:s,contentTypeJson:!0}),body:JSON.stringify({...v?{workspace_id:v}:{},agent_id:p.agentId,runtime_settings:{decision_v2_enabled:p.runtimeSettings.decisionV2Enabled,decision_dedupe_enabled:p.runtimeSettings.decisionDedupeEnabled,decision_evidence_required_for_blocking:p.runtimeSettings.decisionEvidenceRequiredForBlocking,decision_auto_resolve_guarded_enabled:p.runtimeSettings.decisionAutoResolveGuardedEnabled,question_auto_answer_enabled:p.runtimeSettings.questionAutoAnswerEnabled,question_auto_answer_timeout_sec:p.runtimeSettings.questionAutoAnswerTimeoutSec,question_auto_answer_policy:p.runtimeSettings.questionAutoAnswerPolicy,question_blocking_behavior:p.runtimeSettings.questionBlockingBehavior,question_policy_version:p.runtimeSettings.questionPolicyVersion,question_auto_answer_delay_seconds:p.runtimeSettings.questionAutoAnswerDelaySeconds,question_auto_answer_action:p.runtimeSettings.questionAutoAnswerAction,custom_run_instructions:p.runtimeSettings.customRunInstructions}})}),S=await A.json().catch(()=>null);if(!A.ok){const j=(S==null?void 0:S.error)??`Failed to save agent runtime settings (${A.status})`;throw new Error(D(String(j)))}return _e(S??null)},onSuccess:async()=>{await c.invalidateQueries({queryKey:m})}});return{status:u.data??null,isLoading:u.isLoading,isRefetching:u.isRefetching,error:(u.data&&"error"in u.data?u.data.error:null)??((b=u.error)==null?void 0:b.message)??null,installError:((k=g.error)==null?void 0:k.message)??null,runtimeSettings:N.data??{projectId:null,agents:[]},runtimeSettingsError:((f=N.error)==null?void 0:f.message)??null,isRuntimeSettingsLoading:N.isLoading,isRuntimeSettingsRefetching:N.isRefetching,refetchRuntimeSettings:N.refetch,saveRuntimeSettings:w.mutate,saveRuntimeSettingsAsync:w.mutateAsync,saveRuntimeSettingsError:((y=w.error)==null?void 0:y.message)??null,isSavingRuntimeSettings:w.isPending,refetchStatus:u.refetch,install:g.mutate,installAsync:g.mutateAsync,resetInstall:g.reset,installResult:g.data??null,isInstalling:g.isPending}}function Y(t,s){return t===1?`${t} ${s}`:`${t} ${s}s`}function Q({tone:t,children:s}){const a=x.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:R("inline-flex items-center rounded-full border px-2.5 py-1 text-caption font-semibold",a),children:s})}function xe({step:t,title:s,description:a,children:c}){return e.jsxs("section",{className:"grid gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-lime/80",children:t}),e.jsx("h4",{className:"mt-1 text-heading font-semibold text-white",children:s}),e.jsx("p",{className:"mt-1 text-caption leading-relaxed text-secondary",children:a})]}),c]})}const he={conservative:"Conservative",balanced:"Balanced",autonomous:"Autonomous"},et={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 tt(t){return t?t.frozen&&t.pinnedChecksum?"conservative":!t.frozen&&t.pinnedChecksum?"balanced":!t.frozen&&!t.pinnedChecksum?"autonomous":null:null}function st(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 nt({plan:t,agentId:s,sampleTaskId:a}){var w;const c=t.workspaceFiles.filter(b=>b.action!=="noop"),i=c.filter(b=>b.action==="conflict").length,h=c.filter(b=>b.action==="create").length,m=c.filter(b=>b.action==="update").length,u=[];i>0&&u.push(`${Y(i,"managed file")} needs review before apply.`),t.skillPackUpdateAvailable&&u.push("Remote skill update is available; behavior could drift after refresh."),(w=t.skillPackPolicy)!=null&&w.frozen&&u.push("Skill pack is frozen; preview reflects pinned behavior only.");const N=[`Load draft simulation for ${s}.`,`Run sample task "${a}" through current suite guardrails.`,"Assemble managed/local overlay and compute write plan.",i>0?"Stop before apply because conflicts require operator review.":"Proceed to apply path if operator confirms."],g=[`${Y(t.openclawConfigAddedAgents.length,"agent")} added to OpenClaw config.`,`${Y(c.length,"workspace file")} changed (${h} create, ${m} update).`,`Progress stream expected at start and completion for sample "${a}".`];return{outcome:u.length>0?"warning":"ready",executionTrace:N,riskFlags:u,expectedOutputs:g,confidence:u.length>0?"Medium confidence: preview is deterministic but includes review-dependent flags.":"High confidence: preview is deterministic with no active risk flags."}}function it({authToken:t=null,embedMode:s=!1,enabled:a=!0,devMode:c=!1}){var re,Ne,ve,ke,Ae;const[i,h]=x.useState(!1),[m,u]=x.useState(""),[N,g]=x.useState("triage-sample"),[w,b]=x.useState(null),[k,f]=x.useState(null),[y,p]=x.useState(!1),[v,A]=x.useState(null),[S,j]=x.useState(null),[B,I]=x.useState(null),[F,W]=x.useState(null),n=Me({authToken:t,embedMode:s,enabled:a}),l=(re=n.status)!=null&&re.ok?n.status.data:null,_=((Ne=l==null?void 0:l.agents)==null?void 0:Ne.length)??0,P=((ve=l==null?void 0:l.openclawConfigAddedAgents)==null?void 0:ve.length)??0,E=x.useMemo(()=>{var o;return((o=l==null?void 0:l.workspaceFiles)==null?void 0:o.filter(M=>M.action!=="noop"))??[]},[l]),C=E.length,T=x.useMemo(()=>E.filter(o=>o.action==="create").length,[E]),O=x.useMemo(()=>E.filter(o=>o.action==="update").length,[E]),z=x.useMemo(()=>E.filter(o=>o.action==="conflict").length,[E]),K=n.error?D(n.error):null,V=n.installError?D(n.installError):null,ee=k?D(k):null,te=F?D(F):null,G=x.useMemo(()=>{if(n.isLoading)return"Loading agent suite status...";if(K)return`Unable to read suite status: ${K}`;if(!l)return"Suite status unavailable.";if(z>0)return`${Y(z,"file")} to review.`;if(P===0&&C===0)return"Suite is installed and up to date.";const o=[];return P>0&&o.push(`will add ${Y(P,"agent")}`),C>0&&o.push(`will update ${Y(C,"file")}`),`Preview: ${o.join(", ")}.`},[C,z,K,P,l,n.isLoading]),L=(ke=n.installResult)!=null&&ke.ok?n.installResult:null,r=!!(L!=null&&L.dryRun),d=tt((l==null?void 0:l.skillPackPolicy)??null),q=async()=>{var M;if(!l||n.isInstalling||y)return;const o=m||(((M=l.agents[0])==null?void 0:M.id)??"unassigned-agent");h(!0),p(!0),f(null);try{const U=await n.installAsync({dryRun:!0});if(!U.ok)throw new Error(U.error??"Dry-run failed.");b(nt({plan:U.data,agentId:o,sampleTaskId:N})),A(new Date().toISOString())}catch(U){const me=U instanceof Error?U.message:"Dry-run failed.";f(D(me))}finally{p(!1)}},$=async o=>{await fetch("/orgx/api/skill-pack/policy",{method:"POST",headers:Z({authToken:t,embedMode:s,contentTypeJson:!0}),body:JSON.stringify(o)}).then(async M=>{if(!M.ok){const U=await M.json().catch(()=>null),me=(U==null?void 0:U.error)??`Failed to update policy (${M.status})`;throw new Error(D(String(me)))}}),await n.refetchStatus()},ne=async o=>{if(!(!(l!=null&&l.skillPackPolicy)||S)){W(null),I(null),j(o);try{await $(st(o)),I(`${he[o]} preset applied.`)}catch(M){const U=M instanceof Error?M.message:"Failed to apply preset.";W(D(U))}finally{j(null)}}};return e.jsxs("div",{className:"rounded-2xl border border-white/[0.07] bg-white/[0.02] p-4",children:[e.jsx("div",{className:"flex flex-wrap items-start justify-between gap-3 border-b border-white/[0.06] pb-4",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-heading font-semibold text-white",children:"Suite operations"}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:"Install domain agents, validate the write plan, and manage the shared behavior policy."})]})}),e.jsx("div",{className:"mt-4 grid gap-6",children:e.jsx(xe,{step:"Operations",title:"Execution controls",description:"Refresh status, run a deterministic dry-run, then apply suite updates.",children:e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-black/20 p-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>{n.resetInstall(),n.refetchStatus()},disabled:n.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:n.isRefetching?"Refreshing...":"Refresh"}),e.jsx("button",{type:"button",onClick:()=>{q()},disabled:n.isInstalling||y,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:y?"Testing config...":"Test This Config"}),e.jsx("button",{type:"button",onClick:()=>{n.install({dryRun:!1,forceSkillPack:!0})},disabled:n.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:()=>{n.install({dryRun:!1})},disabled:n.isInstalling,className:"inline-flex items-center gap-2 rounded-full bg-lime 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:n.isInstalling?"Installing...":"Install / Update"})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsx(Q,{tone:n.error?"warn":"neutral",children:G}),l&&e.jsxs(e.Fragment,{children:[e.jsx(Q,{tone:P===0?"good":"neutral",children:P===0?"agents configured":`${P} agents to install`}),e.jsxs(Q,{tone:"neutral",children:[Y(_,"agent")," total"]}),e.jsx(Q,{tone:C===0?"good":"neutral",children:C===0?"no file changes":`${C} file changes`}),z>0&&e.jsx(Q,{tone:"neutral",children:Y(z,"file to review")}),l.skillPackUpdateAvailable&&e.jsx(Q,{tone:"warn",children:"skill update available"}),((Ae=l.skillPackPolicy)==null?void 0:Ae.frozen)&&e.jsx(Q,{tone:"neutral",children:"skills frozen"})]})]}),e.jsxs("div",{className:"mt-3 grid gap-2 sm:grid-cols-3",children:[e.jsxs("div",{className:"rounded-lg border border-white/[0.08] bg-black/30 px-3 py-2.5",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Agents"}),e.jsx("p",{className:"mt-1 text-[18px] font-semibold leading-tight text-white",children:_}),e.jsx("p",{className:"mt-1 text-caption text-secondary",children:P===0?"All configured in OpenClaw.":`${P} pending install.`})]}),e.jsxs("div",{className:"rounded-lg border border-white/[0.08] bg-black/30 px-3 py-2.5",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Managed writes"}),e.jsx("p",{className:"mt-1 text-[18px] font-semibold leading-tight text-white",children:C}),e.jsx("p",{className:"mt-1 text-caption text-secondary",children:C===0?"No file updates queued.":`${T} create · ${O} update`})]}),e.jsxs("div",{className:"rounded-lg border border-white/[0.08] bg-black/30 px-3 py-2.5",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Review status"}),e.jsx("p",{className:"mt-1 text-[18px] font-semibold leading-tight text-white",children:z}),e.jsx("p",{className:"mt-1 text-caption text-secondary",children:z===0?"No file conflicts detected.":"Conflicts require operator review."})]})]})]})})}),V&&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:V}),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-lime",children:r?"Dry run":"Applied"}),e.jsxs("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:[c&&L.operationId&&e.jsxs(e.Fragment,{children:["Operation ",e.jsx("code",{className:"rounded bg-black/40 px-1",children:L.operationId})," "]}),r?"Computed the plan without writing any files.":"Installed config and refreshed managed files."]})]}),l&&e.jsxs("div",{className:"mt-4 grid gap-6",children:[e.jsx(xe,{step:"Simulation",title:"Draft simulation",description:"Inspect expected execution trace, risk flags, and outputs before applying.",children:e.jsxs("div",{className:"rounded-xl border border-white/[0.07] bg-black/20 p-3",children:[e.jsx("p",{className:"text-body font-semibold text-primary",children:"Dry-run sample"}),e.jsx("p",{className:"mt-1 text-caption leading-relaxed text-secondary",children:"Validate expected behavior with draft settings before applying changes."}),e.jsxs("div",{className:"mt-3 grid gap-3 md:grid-cols-2",children:[e.jsxs("label",{className:"grid gap-1.5 text-caption text-secondary",children:["Agent",e.jsxs("select",{value:m,onChange:o=>u(o.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"}),l.agents.map(o=>e.jsxs("option",{value:o.id,children:[o.name," (",o.id,")"]},o.id))]})]}),e.jsxs("label",{className:"grid gap-1.5 text-caption text-secondary",children:["Sample task",e.jsxs("select",{value:N,onChange:o=>g(o.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"})]})]})]}),ee&&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:ee}),w&&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(Q,{tone:w.outcome==="ready"?"good":"warn",children:w.outcome==="ready"?"Ready to apply":"Review recommended"})]}),v&&e.jsx("p",{className:"mt-1 text-caption text-secondary",children:new Date(v).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:w.executionTrace.map((o,M)=>e.jsxs("li",{children:[M+1,". ",o]},o))})]}),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:w.riskFlags.length>0?w.riskFlags.map(o=>e.jsx("p",{children:o},o)):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:[w.expectedOutputs.map(o=>e.jsx("p",{children:o},o)),e.jsx("p",{className:"text-primary",children:w.confidence})]})]})]})]})]})}),e.jsxs(xe,{step:"Internals",title:"Suite internals",description:"Inspect policy state, agent roster, and managed/local file write plan.",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:"text-body font-semibold text-primary",children:"Suite details"}),e.jsx("button",{type:"button",onClick:()=>h(o=>!o),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:i?"Hide":"Show"})]}),i&&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"}),c?e.jsx("code",{className:"rounded bg-black/40 px-1.5 py-0.5 text-caption text-primary",children:l.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:[l.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:[l.packId,"@",l.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:l.skillPack?`${l.skillPack.name}@${l.skillPack.version} (${l.skillPack.source})`:"builtin"})]}),l.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:[l.skillPackRemote.name,"@",l.skillPackRemote.version]})]}),l.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:[l.skillPackPolicy.frozen?"frozen":"live",l.skillPackPolicy.pinnedChecksum?`, pinned:${l.skillPackPolicy.pinnedChecksum.slice(0,8)}…`:""]})]}),l.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(Q,{tone:d?"good":"neutral",children:d?`Active: ${he[d]}`:"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(o=>{const M=d===o,U=S===o;return e.jsxs("button",{type:"button",onClick:()=>{ne(o)},disabled:!!S,className:R("min-h-[44px] rounded-lg border px-3 py-2 text-left transition-colors disabled:cursor-not-allowed disabled:opacity-50",M?"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:U?"Applying…":he[o]}),e.jsx("p",{className:"mt-1 text-caption text-secondary",children:et[o]})]},o)})}),B&&e.jsx("p",{className:"mt-2 rounded-lg border border-lime/20 bg-lime/[0.07] px-2.5 py-2 text-caption text-lime",children:B}),te&&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:te})]}),l.skillPackPolicy&&e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>{var o;$({frozen:!((o=l.skillPackPolicy)!=null&&o.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:l.skillPackPolicy.frozen?"Unfreeze skills":"Freeze skills"}),e.jsx("button",{type:"button",onClick:()=>{var o;(o=l.skillPackPolicy)!=null&&o.pinnedChecksum?$({clearPin:!0}):$({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:l.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:l.agents.map(o=>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:o.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:o.id}),e.jsx("span",{className:"px-1",children:"·"}),e.jsx("span",{children:o.domain})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(Q,{tone:o.configuredInOpenclaw?"good":"neutral",children:o.configuredInOpenclaw?"configured":"to install"}),e.jsx(Q,{tone:o.workspaceExists?"good":"neutral",children:o.workspaceExists?"workspace ok":"workspace missing"})]})]},o.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:Y(l.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:C})]}),(T>0||O>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:[T>0?`${T} create`:"0 create",","," ",O>0?`${O} update`:"0 update"]})]})]}),P>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:l.openclawConfigAddedAgents.map(o=>e.jsx("code",{className:"rounded-full border border-strong bg-black/40 px-2 py-0.5 text-caption text-primary",children:o},o))})]}),E.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:[E.slice(0,24).map(o=>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:[o.agentId,"/",o.file]}),e.jsx("span",{className:"text-secondary",children:o.action})]},`${o.agentId}:${o.file}`)),E.length>24&&e.jsxs("p",{className:"text-caption text-muted",children:["Showing 24 of ",E.length,". Install/Update to apply all."]})]})]})]})]})]})]})]})}function Se(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 rt(){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 at({authToken:t=null,embedMode:s=!1,enabled:a=!0}={}){var g,w;const c=Be(),i=x.useMemo(()=>["byok-settings",{authToken:t,embedMode:s}],[t,s]),h=x.useMemo(()=>["byok-health",{authToken:t,embedMode:s}],[t,s]),m=de({queryKey:i,enabled:a,queryFn:async()=>{if(ce())return Se();const b=await fetch("/orgx/api/settings/byok",{headers:Z({authToken:t,embedMode:s})}),k=await b.json().catch(()=>null);if(!b.ok){const f=(k==null?void 0:k.error)??`Failed to load settings (${b.status})`;return{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:D(String(f))}}return k},staleTime:15e3}),u=de({queryKey:h,enabled:!1,queryFn:async()=>{if(ce())return rt();const b=await fetch("/orgx/api/settings/byok/health",{headers:Z({authToken:t,embedMode:s})}),k=await b.json().catch(()=>null);if(!b.ok){const f=(k==null?void 0:k.error)??`Probe failed (${b.status})`,y=D(String(f));return{ok:!1,agentId:"main",providers:{openai:{ok:!1,error:y},anthropic:{ok:!1,error:y},openrouter:{ok:!1,error:y}},error:y}}return k}}),N=we({mutationFn:async b=>{if(ce())return Se({openai:typeof b.openaiApiKey=="string"&&b.openaiApiKey.trim().length>0,anthropic:typeof b.anthropicApiKey=="string"&&b.anthropicApiKey.trim().length>0,openrouter:typeof b.openrouterApiKey=="string"&&b.openrouterApiKey.trim().length>0});const k=await fetch("/orgx/api/settings/byok",{method:"POST",headers:Z({authToken:t,embedMode:s,contentTypeJson:!0}),body:JSON.stringify(b??{})}),f=await k.json().catch(()=>null);if(!k.ok){const y=(f==null?void 0:f.error)??`Failed to save settings (${k.status})`;throw new Error(D(String(y)))}return f},onSuccess:async()=>{await c.invalidateQueries({queryKey:i})}});return{status:m.data??null,isLoading:m.isLoading,error:((g=m.data)==null?void 0:g.error)??((w=m.error)==null?void 0:w.message)??null,refetchStatus:m.refetch,update:N.mutateAsync,isSaving:N.isPending,health:u.data??null,probe:u.refetch,isProbing:u.isFetching}}const oe=[{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 Pe(t){return t==="openai"?"openaiApiKey":t==="anthropic"?"anthropicApiKey":"openrouterApiKey"}function ot(t){var s;return((s=oe.find(a=>a.id===t))==null?void 0:s.label)??t}function ge({step:t,title:s,description:a,children:c}){return e.jsxs("section",{className:"grid gap-4 border-t border-white/[0.06] pt-5 first:border-t-0 first:pt-0",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.16em] text-lime/72",children:t}),e.jsx("h4",{className:"mt-2 text-[18px] font-semibold leading-tight text-white",children:s}),e.jsx("p",{className:"mt-1.5 text-body leading-relaxed text-secondary",children:a})]}),c]})}function lt({authToken:t=null,embedMode:s=!1,enabled:a=!0}){const c=at({authToken:t,embedMode:s,enabled:a}),i=c.status,h=c.health,[m,u]=x.useState({openai:"",anthropic:"",openrouter:""}),[N,g]=x.useState({openai:!1,anthropic:!1,openrouter:!1}),[w,b]=x.useState({openai:!1,anthropic:!1,openrouter:!1}),[k,f]=x.useState(null),[y,p]=x.useState(null);x.useEffect(()=>{a&&(u({openai:"",anthropic:"",openrouter:""}),g({openai:!1,anthropic:!1,openrouter:!1}),b({openai:!1,anthropic:!1,openrouter:!1}),f(null),p(null))},[a]);const v=x.useMemo(()=>i!=null&&i.ok?Number(i.providers.openai.configured)+Number(i.providers.anthropic.configured)+Number(i.providers.openrouter.configured):0,[i]),A=x.useMemo(()=>{var P;const n=oe.map(E=>{var O;const C=(O=i==null?void 0:i.providers)==null?void 0:O[E.id],T=N[E.id]&&m[E.id].trim().length>0;return{id:E.id,label:E.label,configured:T||!!(C!=null&&C.configured),source:T?"pending stored key":(C==null?void 0:C.source)??"none",pending:T?"save":"none"}}),l=n.filter(E=>E.configured),_=l.length===0?"Run preview: launch blocked until at least one provider key is configured.":l.length===1?`Run preview: launches with ${(P=l[0])==null?void 0:P.label} as the only provider.`:`Run preview: launches with ${l.length} providers available for routing.`;return{providers:n,activeProviders:l,summary:_}},[N,i,m]),S=x.useMemo(()=>{const n=oe.filter(_=>{var E;const P=(E=h==null?void 0:h.providers)==null?void 0:E[_.id];return!!(P!=null&&P.ok)}).length,l=oe.filter(_=>N[_.id]&&m[_.id].trim().length>0).length;return{readyProviders:n,pendingSaves:l}},[N,h==null?void 0:h.providers,m]),j=async n=>{if(!a)return;p(null);const l=m[n].trim();if(!N[n])return;if(!l){p(`Enter a ${ot(n)} API key or use "Clear" to remove the saved key.`);return}const _=Pe(n);try{f(n),await c.update({[_]:l}),g(P=>({...P,[n]:!1})),u(P=>({...P,[n]:""})),b(P=>({...P,[n]:!1}))}finally{f(null)}},B=async n=>{p(null);const l=Pe(n);try{f(n),await c.update({[l]:null}),g(_=>({..._,[n]:!1})),u(_=>({..._,[n]:""})),b(_=>({..._,[n]:!1}))}finally{f(null)}},I=async()=>{p(null),await c.probe()},F=y??c.error??null,W=F?D(F):null;return e.jsxs("div",{className:"flex min-h-0 flex-col gap-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-[22px] font-semibold leading-tight text-white",children:"Provider keys"}),e.jsx("p",{className:"mt-2 max-w-2xl text-body leading-relaxed text-secondary",children:"Bring your own provider credentials, keep the source policy obvious, and make launch readiness legible before anyone starts a run."}),v===0?e.jsxs("div",{className:"mt-4 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-4 flex flex-wrap items-center gap-2",children:[e.jsxs("span",{className:"chip",children:[v," / 3 configured"]}),(i==null?void 0:i.updatedAt)&&e.jsxs("span",{className:"text-caption text-muted",children:["Updated ",new Date(i.updatedAt).toLocaleString()]})]})]}),(y||c.error)&&e.jsx("div",{className:"rounded-xl border border-rose-300/20 bg-rose-400/10 p-4 text-body text-rose-100",children:W}),e.jsx(ge,{step:"Overview",title:"Source policy + readiness",description:"Environment variables remain fallback defaults. Saved keys override env values per provider.",children:e.jsxs("div",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.1fr)_minmax(320px,0.9fr)]",children:[e.jsxs("div",{className:"rounded-xl border border-white/[0.08] 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.5 text-body leading-relaxed text-secondary",children:["If you set an env var (for example"," ",e.jsx("code",{className:"rounded bg-black/40 px-1",children:"OPENAI_API_KEY"}),"), it remains the fallback until a saved key overrides it for that provider."]})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-3 xl:grid-cols-1",children:[e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-black/20 px-3.5 py-3",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.14em] text-muted",children:"Configured keys"}),e.jsxs("p",{className:"mt-2 text-[22px] font-semibold leading-none text-white",children:[v," / 3"]})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-black/20 px-3.5 py-3",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.14em] text-muted",children:"Ready providers"}),e.jsx("p",{className:"mt-2 text-[22px] font-semibold leading-none text-white",children:S.readyProviders})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-black/20 px-3.5 py-3",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.14em] text-muted",children:"Pending saves"}),e.jsx("p",{className:"mt-2 text-[22px] font-semibold leading-none text-white",children:S.pendingSaves})]})]})]})}),e.jsx(ge,{step:"Readiness",title:"Agent run preview",description:"A dry operational read on launch viability based on current + pending credentials.",children:e.jsxs("div",{className:"rounded-xl border border-lime/20 bg-lime/[0.05] p-4",children:[e.jsx("p",{className:"text-body font-semibold text-lime",children:A.summary}),e.jsx("div",{className:"mt-3 grid gap-2 sm:grid-cols-3",children:A.providers.map(n=>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:n.label}),e.jsx("span",{className:R("rounded-full border px-2 py-0.5 text-micro uppercase tracking-[0.12em]",n.configured?"border-lime/30 bg-lime/[0.14] text-lime":"border-white/[0.14] bg-white/[0.04] text-secondary"),children:n.configured?"Available":"Missing"})]}),e.jsxs("p",{className:"mt-1 text-caption text-muted",children:["Source: ",n.source,n.pending==="save"?" (pending save)":""]})]},n.id))})]})}),e.jsx(ge,{step:"Providers",title:"Providers",description:"Manage each provider independently: save, clear, then probe readiness.",children:e.jsx("div",{className:"grid grid-cols-1 gap-4",children:oe.map((n,l)=>{var ee,te;const _=(ee=i==null?void 0:i.providers)==null?void 0:ee[n.id],P=(te=h==null?void 0:h.providers)==null?void 0:te[n.id],E=(_==null?void 0:_.masked)??null,C=(_==null?void 0:_.source)??"none",T=C==="stored",O=k===n.id,z=N[n.id]&&m[n.id].trim().length>0&&!c.isSaving&&!O,K=T&&!c.isSaving&&!O,V=T?"Update":"Save";return e.jsxs(J.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},transition:{delay:Math.min(l,5)*.03,duration:.2},className:"rounded-xl border border-white/[0.08] 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-[18px] font-semibold text-white",children:n.label}),e.jsx("span",{className:R("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"}),C!=="none"?e.jsxs("span",{className:"chip",children:["source: ",C]}):null,P?e.jsx("span",{className:R("chip",P.ok?"text-emerald-100":"text-rose-100"),children:P.ok?`ready (${P.modelCount??0} models)`:"not ready"}):null]}),e.jsx("p",{className:"mt-1.5 text-body leading-relaxed text-secondary",children:n.hint}),e.jsxs("p",{className:"mt-2 text-caption text-muted",children:["Fallback env: ",e.jsx("code",{className:"rounded bg-black/40 px-1",children:n.envVar}),E?e.jsxs("span",{className:"ml-2 text-secondary",children:["Stored key ",E]}):null]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>b(G=>({...G,[n.id]:!G[n.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:w[n.id]?"Hide key":"Show key",children:w[n.id]?"Hide":"Show"}),e.jsx("button",{type:"button",onClick:()=>void I(),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-4 border-t border-white/[0.06] pt-4",onSubmit:G=>{G.preventDefault(),j(n.id)},children:[e.jsx("input",{type:"text",name:`provider-user-${n.id}`,autoComplete:"username",value:`${n.id}-key`,readOnly:!0,tabIndex:-1,"aria-hidden":"true",className:"sr-only"}),e.jsxs("label",{className:"block",htmlFor:`provider-key-${n.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-${n.id}`,name:`provider-key-${n.id}`,value:m[n.id],onChange:G=>{u(L=>({...L,[n.id]:G.target.value})),g(L=>({...L,[n.id]:!0})),y&&p(null)},type:w[n.id]?"text":"password",autoComplete:"new-password",spellCheck:!1,placeholder:`Paste ${n.label} key`,className:"w-full rounded-xl border border-white/[0.08] bg-black/30 px-3 py-3 font-mono text-body text-primary placeholder:text-faint focus:border-lime/40 focus:outline-none"})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center justify-between gap-3 border-t border-white/[0.06] pt-3",children:[e.jsx("span",{className:"text-caption text-muted",children:N[n.id]?"Unsaved changes":T?"Stored locally":"No local key saved"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"submit",disabled:!z,className:"rounded-full bg-lime px-4 py-2 text-body font-semibold text-black transition-colors hover:bg-[#d3ff42] disabled:cursor-not-allowed disabled:opacity-40",children:O?"Saving...":V}),e.jsx("button",{type:"button",onClick:()=>void B(n.id),disabled:!K,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"})]})]})]})]},n.id)})})})]})}const Ce={engineering:"Engineering",product:"Product",design:"Design",marketing:"Marketing",sales:"Sales",operations:"Operations",orchestration:"Orchestration"},ie={decisionV2Enabled:!0,decisionDedupeEnabled:!0,decisionEvidenceRequiredForBlocking:!1,decisionAutoResolveGuardedEnabled:!0,questionAutoAnswerEnabled:!0,questionAutoAnswerTimeoutSec:60,questionAutoAnswerPolicy:"contextual",questionBlockingBehavior:"require_human",questionPolicyVersion:1,questionAutoAnswerDelaySeconds:60,questionAutoAnswerAction:"approve",customRunInstructions:""},ct=/^[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 be(t){return typeof t!="string"?!1:ct.test(t.trim())}function Re(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 dt(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 mt({status:t}){return e.jsx("span",{className:R("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 ae({label:t,description:s,enabled:a,onToggle:c}){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":a,onClick:()=>c(!a),className:R("relative inline-flex h-6 w-11 flex-shrink-0 rounded-full border transition-colors",a?"border-lime/35 bg-lime/[0.20]":"border-white/[0.12] bg-white/[0.06]"),children:e.jsx("span",{"aria-hidden":"true",className:R("absolute top-0.5 h-5 w-5 rounded-full transition-all",a?"left-[20px] bg-lime":"left-0.5 bg-white/70")})})]})}function Ee({step:t,title:s,description:a,children:c}){return e.jsxs("section",{className:"grid gap-4 border-t border-white/[0.06] pt-5 first:border-t-0 first:pt-0",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.16em] text-lime/72",children:t}),e.jsx("h4",{className:"mt-2 text-[18px] font-semibold leading-tight text-white",children:s}),e.jsx("p",{className:"mt-1.5 text-body leading-relaxed text-secondary",children:a})]}),c]})}function ut({authToken:t=null,embedMode:s=!1,enabled:a=!0,initialDomain:c=null,onOpenSuiteOps:i}){var G,L;const h=Me({authToken:t,embedMode:s,enabled:a}),m=(G=h.status)!=null&&G.ok?h.status.data.agents:[],u=h.runtimeSettings.agents,N=x.useMemo(()=>{const r=new Map;for(const d of h.runtimeSettings.agents)r.set(d.id,d.runtimeSettings);return r},[h.runtimeSettings.agents]),g=x.useMemo(()=>{const r=new Map;for(const d of u){const q=Re({name:d.name,id:d.id});!q||r.has(q)||r.set(q,{id:d.id,model:d.model,runtimeSettings:d.runtimeSettings})}return m.length>0?m.map(d=>{var q,$,ne,re;return{id:((q=r.get(d.domain))==null?void 0:q.id)??d.id,name:d.name,domain:d.domain,model:(($=r.get(d.domain))==null?void 0:$.model)??null,configStatus:((ne=d.configHealth)==null?void 0:ne.status)??null,runtimeSettings:((re=r.get(d.domain))==null?void 0:re.runtimeSettings)??N.get(d.id)??ie}}):u.map(d=>({id:d.id,name:d.name,domain:Re({name:d.name,id:d.id}),model:d.model,configStatus:null,runtimeSettings:d.runtimeSettings}))},[u,m,N]),w=x.useMemo(()=>{const r={};for(const d of g)r[d.id]=d.runtimeSettings;return r},[g]),[b,k]=x.useState(null),[f,y]=x.useState({}),[p,v]=x.useState(null),[A,S]=x.useState(null);x.useEffect(()=>{if(g.length===0){k(null);return}(!b||!g.some(r=>r.id===b))&&k(g[0].id),y(r=>{let d=!1;const q={...r};for(const $ of g)q[$.id]||(q[$.id]=w[$.id]??ie,d=!0);return d?q:r})},[b,g,w]),x.useEffect(()=>{if(!c||g.length===0)return;const r=g.find(d=>d.domain===c);r&&r.id!==b&&k(r.id)},[b,g,c]);const j=x.useMemo(()=>g.find(r=>r.id===b)??null,[b,g]),B=r=>f[r]??w[r]??ie,I=j?B(j.id):null,F=x.useMemo(()=>g.filter(r=>!dt(B(r.id),w[r.id])).map(r=>r.id),[g,f,w]),W=x.useMemo(()=>new Set(F),[F]),n=r=>{j&&y(d=>{const q=d[j.id]??w[j.id]??ie;return{...d,[j.id]:{...q,...r}}})},l=()=>{j&&y(r=>({...r,[j.id]:w[j.id]??ie}))},_=()=>{if(!I||g.length===0)return;const r={...I,customRunInstructions:I.customRunInstructions.trim().slice(0,4e3)};y(d=>{const q={...d};for(const $ of g)q[$.id]={...r};return q}),v("Applied active agent settings to all agents."),S(null)},P=()=>{const r={};for(const d of g)r[d.id]=w[d.id]??ie;y(r),v(null),S(null)},E=async()=>{var r;if(!(F.length===0||h.isSavingRuntimeSettings)){v(null),S(null);try{for(const d of F){if(!be(d)){const $=((r=g.find(ne=>ne.id===d))==null?void 0:r.name)??d;throw new Error(`Cannot save "${$}" because it is not linked to a valid OrgX agent UUID yet. Re-sync Agent Suite and try again.`)}const q=B(d);await h.saveRuntimeSettingsAsync({projectId:h.runtimeSettings.projectId,agentId:d,runtimeSettings:{...q,customRunInstructions:q.customRunInstructions.trim().slice(0,4e3)}})}v(`Saved runtime settings for ${F.length} ${F.length===1?"agent":"agents"}.`),S(null)}catch(d){const q=d instanceof Error?d.message:"Failed to save agent settings.";S(D(q))}}},C=((L=h.runtimeSettingsError)==null?void 0:L.trim())??null,T=C?D(C):null,O=!!C,z=!!(C&&(C.toLowerCase().includes("endpoint is not available")||C.includes("(404)"))),K=O;if(h.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(h.error&&!h.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:D(h.error)})]});if(g.length===0||!j||!I)return e.jsxs("section",{className:"rounded-xl border border-white/[0.08] bg-white/[0.02] p-5",children:[e.jsxs("div",{className:"max-w-2xl",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.16em] text-lime/72",children:"Runtime policy"}),e.jsx("h3",{className:"mt-2 text-[22px] font-semibold leading-tight text-white",children:"No agent suite is installed yet."}),e.jsx("p",{className:"mt-2 text-body leading-relaxed text-secondary",children:"Per-agent controls only become useful after the local suite is installed and linked to OrgX agent IDs. Set up the suite first, then come back here to tune decision policy and run behavior."})]}),e.jsxs("div",{className:"mt-5 grid gap-3 sm:grid-cols-3",children:[e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-black/20 px-3.5 py-3",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.14em] text-muted",children:"1"}),e.jsx("p",{className:"mt-2 text-body font-semibold text-primary",children:"Install the suite"}),e.jsx("p",{className:"mt-1 text-caption leading-relaxed text-secondary",children:"Scaffold domain agents and managed workspace files."})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-black/20 px-3.5 py-3",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.14em] text-muted",children:"2"}),e.jsx("p",{className:"mt-2 text-body font-semibold text-primary",children:"Link live identities"}),e.jsx("p",{className:"mt-1 text-caption leading-relaxed text-secondary",children:"Confirm each runtime maps cleanly to its OrgX agent record."})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-black/20 px-3.5 py-3",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.14em] text-muted",children:"3"}),e.jsx("p",{className:"mt-2 text-body font-semibold text-primary",children:"Tune policy"}),e.jsx("p",{className:"mt-1 text-caption leading-relaxed text-secondary",children:"Apply guardrails, question policy, and custom run instructions per agent."})]})]}),i?e.jsx("div",{className:"mt-5 flex flex-wrap gap-2",children:e.jsx("button",{type:"button",onClick:i,className:"inline-flex min-h-[44px] items-center rounded-full bg-lime px-4 py-2 text-body font-semibold text-black transition-colors hover:bg-[#d3ff42]",children:"Open suite setup"})}):null]});const V=F.length,ee=W.has(j.id),te=j.domain?Ce[j.domain]:"Agent";return e.jsxs("section",{className:"space-y-4",children:[e.jsxs("header",{className:"rounded-xl border border-subtle bg-white/[0.02] p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-heading font-semibold text-white",children:"Agent runtime settings"}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:K?z?"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:[g.length," agents"]}),!K&&e.jsxs("span",{className:R("rounded-full border px-3 py-1 text-caption",V>0?"border-lime/25 bg-lime/[0.12] text-lime":"border-white/[0.10] bg-white/[0.03] text-secondary"),children:[V," unsaved"]})]})]}),e.jsxs("div",{className:"mt-4 grid gap-3 sm:grid-cols-3",children:[e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-black/20 px-3.5 py-3",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.14em] text-muted",children:"Roster"}),e.jsx("p",{className:"mt-2 text-body font-semibold text-primary",children:"Choose the agent you’re shaping."})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-black/20 px-3.5 py-3",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.14em] text-muted",children:"Guardrails"}),e.jsx("p",{className:"mt-2 text-body font-semibold text-primary",children:"Tune approvals, evidence, and questions."})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-black/20 px-3.5 py-3",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.14em] text-muted",children:"Commit"}),e.jsx("p",{className:"mt-2 text-body font-semibold text-primary",children:"Save every draft change in one pass."})]})]})]}),K&&e.jsx("div",{className:"rounded-xl border border-amber-300/20 bg-[#12100A]/95 px-4 py-3",children:z?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:T})]})}),e.jsxs("div",{className:"grid gap-4 lg:grid-cols-[280px_minmax(0,1fr)]",children:[e.jsx(Ee,{step:"Roster",title:"Agent roster",description:"Select the runtime identity to edit. Draft state is scoped per agent.",children:e.jsx("aside",{className:"rounded-xl border border-subtle bg-white/[0.02] p-2",children:e.jsx("div",{className:"max-h-[520px] space-y-1 overflow-y-auto pr-1",children:g.map(r=>{const d=r.id===j.id,q=W.has(r.id),$=be(r.id);return e.jsxs("button",{type:"button",onClick:()=>k(r.id),className:R("w-full rounded-lg border px-3 py-2 text-left transition-colors",d?"border-lime/25 bg-lime/[0.12]":"border-white/[0.08] bg-black/20 hover:bg-white/[0.04]"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"truncate text-body font-semibold text-primary",children:r.name}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[$?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"}),r.configStatus?e.jsx(mt,{status:r.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:r.domain?Ce[r.domain]:r.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]})]},r.id)})})})}),e.jsxs(Ee,{step:"Policy",title:"Policy surfaces",description:"Tune decision pipeline and persistent instructions for the selected agent.",children:[e.jsx("article",{className:"rounded-xl border border-subtle bg-white/[0.02] p-4",children:e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-caption uppercase tracking-[0.08em] text-secondary",children:te}),e.jsx("h4",{className:"mt-1 text-heading font-semibold text-white",children:j.name}),be(j.id)?null:e.jsx("p",{className:"mt-1 text-caption text-amber-100/85",children:"This agent is not linked to a runtime UUID yet. Apply Agent Suite sync before saving."})]}),!K&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",onClick:_,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:l,disabled:!ee,className:"min-h-[44px] rounded-full border border-white/[0.14] bg-white/[0.03] px-3 py-2 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.06] disabled:cursor-not-allowed disabled:opacity-50",children:"Reset active"})]})]})}),e.jsxs("div",{className:K?"pointer-events-none opacity-40":"",children:[e.jsxs("article",{className:"rounded-xl border border-subtle bg-white/[0.02] p-4",children:[e.jsx("h4",{className:"text-body font-semibold text-primary",children:"Decision pipeline"}),e.jsx("p",{className:"mt-1 text-caption leading-relaxed text-secondary",children:"These controls are injected into dispatch and decision flows for this agent."}),e.jsxs("div",{className:"mt-3 space-y-3",children:[e.jsxs("div",{className:"space-y-2 rounded-xl border border-white/[0.08] bg-black/20 p-3",children:[e.jsx("p",{className:"text-caption font-semibold uppercase tracking-[0.08em] text-secondary",children:"Decision envelope"}),e.jsx(ae,{label:"Decision envelope v2",description:"Emit richer context fields for diagnosis and replay.",enabled:I.decisionV2Enabled,onToggle:r=>n({decisionV2Enabled:r})}),e.jsx(ae,{label:"Decision dedupe",description:"Collapse repeated blockers into the same pending decision.",enabled:I.decisionDedupeEnabled,onToggle:r=>n({decisionDedupeEnabled:r})}),e.jsx(ae,{label:"Require evidence for blocking decisions",description:"Attach evidence before a blocking decision can be emitted.",enabled:I.decisionEvidenceRequiredForBlocking,onToggle:r=>n({decisionEvidenceRequiredForBlocking:r})}),e.jsx(ae,{label:"Guarded auto-resolve",description:"Attempt deterministic remediation before escalating to humans.",enabled:I.decisionAutoResolveGuardedEnabled,onToggle:r=>n({decisionAutoResolveGuardedEnabled:r})})]}),e.jsxs("div",{className:"space-y-2 rounded-xl border border-white/[0.08] bg-black/20 p-3",children:[e.jsx("p",{className:"text-caption font-semibold uppercase tracking-[0.08em] text-secondary",children:"Question automation"}),e.jsx(ae,{label:"Auto-answer unanswered questions",description:"If no human response arrives in time, auto-resolve questions sequentially.",enabled:I.questionAutoAnswerEnabled,onToggle:r=>n({questionAutoAnswerEnabled:r})}),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:I.questionAutoAnswerTimeoutSec,onChange:r=>{const d=Number.parseInt(r.target.value,10),q=Number.isFinite(d)?Math.max(10,Math.min(3600,d)):60;n({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:I.questionAutoAnswerPolicy,onChange:r=>n({questionAutoAnswerPolicy:r.target.value==="approve_non_blocking"||r.target.value==="defer_non_blocking"?r.target.value:"contextual",questionAutoAnswerAction:r.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:I.questionBlockingBehavior,onChange:r=>n({questionBlockingBehavior:r.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:I.customRunInstructions,onChange:r=>n({customRunInstructions:r.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:[I.customRunInstructions.trim().length,"/4000"]})]})]})]})]})]}),e.jsx("div",{className:R("sticky bottom-0 z-10 rounded-xl border border-subtle bg-[#08090d]/90 p-3 backdrop-blur",K&&"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:D(A)}):p?e.jsx("p",{className:"text-caption text-lime",children:p}):e.jsx("p",{className:"text-caption text-secondary",children:V>0?`${V} ${V===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:P,disabled:V===0||h.isSavingRuntimeSettings,className:"min-h-[44px] rounded-lg border border-white/[0.14] px-3 py-2 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.06] disabled:cursor-not-allowed disabled:opacity-50",children:"Discard all"}),e.jsx("button",{type:"button",onClick:()=>{E()},disabled:V===0||h.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:h.isSavingRuntimeSettings?"Saving...":"Save changes"})]})]})})]})}function X(t){return new Intl.NumberFormat("en-US").format(Math.max(0,Math.round(t)))}function fe(t){return`$${(Math.max(0,t)/100).toFixed(2)}`}function ye(t){return typeof t!="number"||!Number.isFinite(t)?"—":`${Math.max(0,Math.round(t))}%`}function pt(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-lime"}function qe(t,s=4){return!Array.isArray(t)||t.length===0?[]:[...t].sort((a,c)=>c.tokens-a.tokens).slice(0,s)}function xt(t){const s=Date.parse(t.generatedAt);if(!Number.isFinite(s))return"Updated just now";const a=Math.max(0,Math.round((Date.now()-s)/6e4));return a<1?"Updated just now":a<60?`Updated ${a}m ago`:`Updated ${Math.round(a/60)}h ago`}function Ie({step:t,title:s,description:a,children:c}){return e.jsxs("section",{className:"grid gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-lime/80",children:t}),e.jsx("h4",{className:"mt-1 text-heading font-semibold text-white",children:s}),e.jsx("p",{className:"mt-1 text-caption leading-relaxed text-secondary",children:a})]}),c]})}function ht({authToken:t=null,embedMode:s=!1,enabled:a=!0}){const c=Ke({authToken:t,embedMode:s,enabled:a}),i=c.summary,h=c.error?D(c.error):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:"Usage telemetry"}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:"Actual versus predicted token, runtime, and cost usage for the active billing window."})]}),e.jsx("button",{type:"button",onClick:()=>void c.refetch(),disabled:c.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:c.isFetching?"Refreshing…":"Refresh"})]}),h?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:h}):null,!i&&c.isLoading?e.jsx("div",{className:"mt-3 grid gap-2 sm:grid-cols-2 lg:grid-cols-4",children:Array.from({length:4}).map((m,u)=>e.jsx("div",{className:"h-[92px] animate-pulse rounded-xl border border-white/[0.08] bg-white/[0.03]"},`usage-loading-${u}`))}):null,i?e.jsx(e.Fragment,{children:e.jsxs("div",{className:"mt-4 grid gap-6",children:[e.jsx(Ie,{step:"Overview",title:"Risk + volume overview",description:"Current period usage against plan limits with forecast deltas.",children:e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-black/20 p-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(J.span,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},className:R("rounded-full border px-2.5 py-1 text-caption font-semibold",pt(i.risk)),children:i.risk.replace("_"," ")}),e.jsx("span",{className:"chip",children:i.plan.name}),i.source?e.jsxs("span",{className:"chip",children:["source: ",i.source]}):null,e.jsx("span",{className:"text-caption text-muted",children:xt(i)})]}),e.jsxs("div",{className:"mt-3 grid gap-2 sm:grid-cols-2 lg:grid-cols-4",children:[e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-black/30 px-3 py-2.5",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Agent runs"}),e.jsxs("p",{className:"mt-1 text-heading font-semibold text-white",children:[X(i.actual.agentRuns),e.jsxs("span",{className:"ml-1 text-caption text-secondary",children:["/ ",i.plan.agentRunsLimit>0?X(i.plan.agentRunsLimit):"∞"]})]}),e.jsxs("p",{className:"mt-1 text-caption text-muted",children:["Forecast ",X(i.predicted.agentRuns)]})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-black/30 px-3 py-2.5",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Agent minutes"}),e.jsxs("p",{className:"mt-1 text-heading font-semibold text-white",children:[X(i.actual.agentMinutes),e.jsxs("span",{className:"ml-1 text-caption text-secondary",children:["/ ",i.plan.agentMinutesLimit>0?X(i.plan.agentMinutesLimit):"∞"]})]}),e.jsxs("p",{className:"mt-1 text-caption text-muted",children:["Forecast ",X(i.predicted.agentMinutes)]})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-black/30 px-3 py-2.5",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Tokens"}),e.jsx("p",{className:"mt-1 text-heading font-semibold text-white",children:X(i.actual.tokens)}),e.jsxs("p",{className:"mt-1 text-caption text-muted",children:["Forecast ",X(i.predicted.tokens)]})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-black/30 px-3 py-2.5",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Spend"}),e.jsxs("p",{className:"mt-1 text-heading font-semibold text-white",children:[fe(i.actual.costCents),e.jsxs("span",{className:"ml-1 text-caption text-secondary",children:["/ ",i.plan.includedBudgetCents>0?fe(i.plan.includedBudgetCents):"—"]})]}),e.jsxs("p",{className:"mt-1 text-caption text-muted",children:["Forecast ",fe(i.predicted.costCents)]})]})]})]})}),e.jsx(Ie,{step:"Diagnostics",title:"Utilization diagnostics",description:"Percent utilization plus source-client composition and warnings.",children:e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-black/20 p-3",children:[e.jsxs("div",{className:"grid gap-2 sm:grid-cols-3",children:[e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.02] px-3 py-2",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Run utilization"}),e.jsx("p",{className:"mt-1 text-caption font-semibold text-primary",children:ye(i.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:ye(i.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:ye(i.utilization.budgetPct)})]})]}),qe(i.breakdown.sourceClient,4).length>0?e.jsxs("div",{className:"mt-3 rounded-xl border border-white/[0.08] bg-black/30 p-3",children:[e.jsx("p",{className:"text-caption font-semibold text-primary",children:"Runtime client mix"}),e.jsx("div",{className:"mt-2 space-y-2",children:qe(i.breakdown.sourceClient,4).map((m,u)=>{const N=i.actual.tokens>0?Math.max(0,Math.min(100,Math.round(m.tokens/i.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:m.label}),e.jsxs("span",{className:"text-caption text-primary",children:[X(m.tokens)," tokens · ",X(m.runs)," runs"]})]}),e.jsx("div",{className:"h-1.5 rounded-full bg-white/[0.08]",children:e.jsx(J.div,{initial:{width:0},animate:{width:`${Math.max(6,N)}%`},transition:{duration:.36,delay:u*.04},className:"h-1.5 rounded-full bg-lime/80 transition-all"})})]},`usage-source-${m.key}`)})})]}):null,Array.isArray(i.warnings)&&i.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:i.warnings.slice(0,3).map((m,u)=>e.jsxs("li",{className:"text-caption text-amber-100/90",children:["• ",m]},`usage-warning-${u}`))})]}):null]})})]})}):null]})}function gt({connectionPhase:t,workspaceName:s}){const{displayName:a,avatarSeed:c,updateName:i,regenerateAvatar:h}=Ue(),[m,u]=x.useState(!1),[N,g]=x.useState(""),w=x.useRef(null),b=x.useCallback(()=>{g(a),u(!0),requestAnimationFrame(()=>{var A;return(A=w.current)==null?void 0:A.focus()})},[a]),k=x.useCallback(()=>{i(N),u(!1)},[N,i]),f=x.useCallback(()=>{u(!1)},[]),y=x.useCallback(A=>{A.key==="Enter"?k():A.key==="Escape"&&f()},[k,f]),p=t==="connected",v=p?`Connected${s?` to ${s}`:""}`:t==="connecting"?"Connecting...":t==="error"?"Connection error":"Not connected";return e.jsxs("div",{className:"grid gap-4 lg:grid-cols-[220px_minmax(0,1fr)]",children:[e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-black/20 p-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.14em] text-lime/78",children:"Visual signature"}),e.jsx("span",{className:R("rounded-full border px-2 py-0.5 text-micro uppercase tracking-[0.08em]",p?"border-lime/28 bg-lime/[0.10] text-lime":t==="error"?"border-rose-300/25 bg-rose-500/[0.12] text-rose-100":"border-white/[0.14] bg-white/[0.04] text-secondary"),children:p?"Connected":t==="connecting"?"Connecting":t==="error"?"Attention":"Idle"})]}),e.jsxs("div",{className:"mt-4 flex flex-col items-center gap-3 rounded-xl border border-white/[0.08] bg-white/[0.02] px-4 py-4",children:[e.jsx(Fe,{mode:"wait",children:e.jsx(J.div,{initial:{opacity:0,scale:.9},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.9},transition:{duration:.3,ease:De.easingEntrance},children:e.jsx(Oe,{seed:c,size:88})},c)}),e.jsx("button",{type:"button",onClick:h,className:"min-h-[44px] rounded-full border border-white/[0.12] bg-white/[0.03] px-4 py-2 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.07]",children:"Regenerate signature"})]})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.02] p-4 sm:p-5",children:[e.jsx("div",{className:"flex flex-wrap items-start justify-between gap-3 border-b border-white/[0.06] pb-4",children:e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.14em] text-lime/78",children:"Operator profile"}),m?e.jsxs("div",{className:"mt-2 flex flex-col gap-2 sm:flex-row sm:items-center",children:[e.jsx("input",{ref:w,type:"text",value:N,onChange:A=>g(A.target.value),onKeyDown:y,maxLength:64,placeholder:"Enter your name",className:"h-11 min-w-0 flex-1 rounded-xl border border-white/[0.12] bg-black/25 px-3 text-body font-semibold text-white placeholder:text-muted focus:border-lime/30 focus:outline-none"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:k,className:"min-h-[44px] rounded-full bg-lime/[0.12] px-4 py-2 text-caption font-semibold text-lime transition-colors hover:bg-lime/[0.2]",children:"Save"}),e.jsx("button",{type:"button",onClick:f,className:"min-h-[44px] rounded-full border border-white/[0.12] bg-white/[0.03] px-4 py-2 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.07]",children:"Cancel"})]})]}):e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[e.jsx("h4",{className:"truncate text-[24px] font-semibold leading-tight tracking-[-0.02em] text-white",children:a||"Anonymous"}),e.jsx("button",{type:"button",onClick:b,className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-3 py-1 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.07]",children:a?"Edit name":"Add name"})]}),e.jsx("p",{className:"mt-2 text-body leading-relaxed text-secondary",children:"This name and signature appear across mission control, approvals, and local operator context."})]})}),e.jsxs("div",{className:"mt-4 grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-black/20 px-4 py-3",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Connection"}),e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("span",{className:"relative flex h-2.5 w-2.5",children:e.jsx("span",{className:R("relative inline-flex h-2.5 w-2.5 rounded-full",p?"bg-lime":t==="error"?"bg-red-400":"bg-white/30")})}),e.jsx("span",{className:"text-body font-semibold text-primary",children:v})]})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-black/20 px-4 py-3",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Workspace"}),e.jsx("p",{className:"mt-2 text-body font-semibold text-primary",children:s??"No workspace selected yet"}),e.jsx("p",{className:"mt-1 text-caption text-secondary",children:s?"Current live scope for synced operations.":"Connection scope appears here after verification."})]})]})]})]})}const le=[{id:"orgx",label:"Workspace",subtitle:"Identity, OrgX connection, and environment controls."},{id:"agents",label:"Agents",subtitle:"Runtime behavior, decision policy, and execution guidance."},{id:"providers",label:"Provider keys",subtitle:"Model provider credentials and launch readiness."}];function bt({id:t}){return t==="orgx"?e.jsxs("svg",{viewBox:"0 0 24 24",className:"h-4 w-4",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:[e.jsx("path",{d:"M4 8h16"}),e.jsx("path",{d:"M4 16h16"}),e.jsx("rect",{x:"4",y:"5",width:"16",height:"14",rx:"3"})]}):t==="agents"?e.jsxs("svg",{viewBox:"0 0 24 24",className:"h-4 w-4",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:[e.jsx("circle",{cx:"8",cy:"8",r:"3"}),e.jsx("circle",{cx:"16",cy:"16",r:"3"}),e.jsx("path",{d:"M10.6 10.6 13.4 13.4"}),e.jsx("path",{d:"M12 5h6v6"})]}):e.jsxs("svg",{viewBox:"0 0 24 24",className:"h-4 w-4",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:[e.jsx("path",{d:"M12 3v18"}),e.jsx("path",{d:"M5 7.5h5.5v4H5z"}),e.jsx("path",{d:"M13.5 12.5H19v4h-5.5z"})]})}function je({label:t,description:s,enabled:a,onToggle:c}){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(J.button,{type:"button",role:"switch","aria-checked":a,onClick:()=>c(!a),whileTap:{scale:.965},className:R("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",a?"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:R("absolute top-[1px] h-[18px] w-[18px] rounded-full shadow-sm transition-all",a?"left-[17px] bg-lime shadow-[0_0_8px_rgba(191,255,0,0.4)]":"left-[1px] bg-secondary")})})]})}function se({step:t,title:s,description:a,children:c}){return e.jsxs("section",{className:"grid gap-4 border-t border-white/[0.06] pt-6 first:border-t-0 first:pt-0",children:[e.jsxs("div",{className:"max-w-3xl",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.16em] text-lime/72",children:t}),e.jsx("h4",{className:"mt-2 text-[18px] font-semibold leading-tight text-white",children:s}),e.jsx("p",{className:"mt-1.5 text-body leading-relaxed text-secondary",children:a})]}),c]})}function _t({open:t,onClose:s,activeTab:a,onChangeTab:c,demoMode:i,onToggleDemoMode:h,devMode:m=!1,onToggleDevMode:u,showSyntheticEntities:N,onToggleShowSyntheticEntities:g,workspaceOptions:w,selectedWorkspaceId:b,onSelectWorkspace:k,onboarding:f,authToken:y=null,embedMode:p=!1,agentBehaviorInitialDomain:v=null}){const A=le.find(j=>j.id===a)??le[0],S=()=>a==="orgx"?e.jsxs(J.div,{...ue,className:"grid gap-8",children:[e.jsx(se,{step:"Identity",title:"Operator identity",description:"Name, avatar signature, and live workspace connection context.",children:e.jsx(gt,{connectionPhase:f.state.status==="connected"?"connected":f.state.status==="error"?"error":f.state.status==="starting"||f.state.status==="awaiting_browser_auth"||f.state.status==="pairing"?"connecting":"idle",workspaceName:f.state.workspaceName})}),e.jsx(se,{step:"Controls",title:"Environment controls",description:"Debug and rehearsal switches that shape what appears in mission control.",children:e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.02] p-4 sm:p-5",children:[m?null:e.jsxs("div",{className:"mb-4 rounded-xl border border-white/[0.08] bg-black/20 px-3.5 py-3",children:[e.jsx("p",{className:"text-caption font-semibold text-primary",children:"Developer mode unlocks rehearsal controls."}),e.jsx("p",{className:"mt-1 text-caption leading-relaxed text-secondary",children:"Keep runtime details hidden during normal operation. Enable Developer mode when you need demo data or synthetic entities for QA and walkthroughs."})]}),e.jsxs("div",{className:"grid gap-1",children:[e.jsx(je,{label:"Developer mode",description:"Show technical details, config paths, and raw data in session inspectors.",enabled:m,onToggle:j=>u==null?void 0:u(j)}),e.jsx("div",{className:R("border-t border-white/[0.06]",m?"":"pointer-events-none opacity-45"),children:e.jsx(je,{label:"Guided sandbox",description:"Load local sandbox data for walkthroughs without touching a real workspace.",enabled:i,onToggle:h})}),e.jsx("div",{className:R("border-t border-white/[0.06]",m?"":"pointer-events-none opacity-45"),children:e.jsx(je,{label:"Show synthetic entities",description:"Include QA/test initiative IDs in the agent column.",enabled:N,onToggle:g})})]})]})}),e.jsx(se,{step:"Connection",title:"OrgX connection lifecycle",description:"Credentialing, verification, and workspace scope selection.",children:e.jsx(Xe,{state:f.state,isStarting:f.isStarting,isSubmittingManual:f.isSubmittingManual,workspaceOptions:w,selectedWorkspaceId:b,onSelectWorkspace:k,onRefresh:f.refreshStatus,onStartPairing:f.startPairing,onCancelPairing:f.cancelPairing,onSubmitManualKey:f.submitManualKey,onBackToPairing:f.backToPairing,onUseManualKey:f.setManualMode,onDisconnect:f.disconnect})}),e.jsx(se,{step:"Suite",title:"Agent suite operations",description:"Install, validate, and tune default execution policy across the local suite.",children:e.jsx(it,{authToken:y,embedMode:p,enabled:t&&!i,devMode:m})}),e.jsx(se,{step:"Usage",title:"Usage telemetry",description:"Budget, token, and runtime risk visibility for the active billing window.",children:e.jsx(ht,{authToken:y,embedMode:p,enabled:t&&!i})})]},"orgx"):a==="agents"?e.jsx(J.div,{...ue,className:"grid gap-3",children:e.jsx(se,{step:"Runtime policy",title:"Per-agent runtime policy",description:"Select an agent, tune guardrails, then persist all draft behavior changes.",children:e.jsx(ut,{authToken:y,embedMode:p,enabled:t&&!i,initialDomain:v,onOpenSuiteOps:()=>c("orgx")})})},"agents"):e.jsx(J.div,{...ue,className:"grid gap-3",children:e.jsx(se,{step:"Credentials",title:"Provider credentials",description:"Provision keys, validate provider readiness, and lock in routing confidence.",children:e.jsx(lt,{authToken:y,embedMode:p,enabled:t&&!i})})},"providers");return e.jsx(Le,{open:t,onClose:s,maxWidth:"max-w-6xl",closeOnBackdropClick:!1,closeOnEscapeWhenTyping:!1,children:e.jsxs("div",{className:"relative flex h-full min-h-0 w-full min-w-0 flex-1 flex-col",children:[e.jsx("div",{className:"pointer-events-none absolute inset-0 opacity-60",style:{background:"radial-gradient(1200px 280px at 20% -10%, rgba(191,255,0,0.08), transparent 65%), radial-gradient(900px 240px at 95% -20%, rgba(10,212,196,0.07), transparent 68%)"},"aria-hidden":!0}),e.jsxs("div",{className:"relative z-[1] flex h-full min-h-0 flex-1 flex-col px-5 pb-3 pt-5 sm:px-7 sm:pt-6",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4 border-b border-white/[0.06] pb-5",children:[e.jsxs("div",{className:"min-w-0 max-w-3xl",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.08em] text-lime/75",children:"Control Surfaces"}),e.jsx("h3",{className:"mt-2 text-display font-semibold leading-none tracking-[-0.02em] text-white sm:text-[36px]",children:"Settings"}),e.jsx("p",{className:"mt-3 max-w-2xl text-body leading-relaxed text-secondary",children:"A single surface for identity, connection, execution policy, and provider readiness. The chrome stays quiet so the control you need is always the first thing you see."})]}),e.jsx("button",{type:"button",onClick:s,"aria-label":"Close settings",className:"inline-flex h-9 w-9 items-center justify-center rounded-full border border-strong bg-transparent text-secondary transition-colors hover:bg-white/10 hover:text-white focus:outline-none focus-visible:ring-2 focus-visible:ring-lime/45",children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 6L6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})})]}),e.jsxs("div",{className:"mt-5 min-h-0 flex-1 gap-5 lg:grid lg:grid-cols-[220px_minmax(0,1fr)]",children:[e.jsx("aside",{className:"hidden min-h-0 lg:block",children:e.jsx("nav",{className:"sticky top-0 rounded-2xl border border-white/[0.08] bg-white/[0.02] p-2.5",role:"tablist","aria-label":"Settings tabs",children:le.map(j=>{const B=a===j.id;return e.jsxs(J.button,{type:"button",role:"tab","aria-selected":B,onClick:()=>c(j.id),whileHover:{x:1.5},whileTap:{scale:.985},transition:{duration:.16},className:R("relative mt-1.5 flex w-full items-center gap-3 rounded-xl px-3.5 py-3 text-left first:mt-0",B?"text-white":"text-secondary hover:text-primary"),children:[B&&e.jsx(J.span,{layoutId:"settings-tab-surface",className:"absolute inset-0 rounded-xl border border-lime/24 bg-lime/[0.10]",transition:{duration:.24,ease:De.easingStandard},"aria-hidden":!0}),e.jsx("span",{className:R("relative z-[1] mt-[1px] inline-flex h-7 w-7 flex-shrink-0 items-center justify-center rounded-lg border text-[11px]",B?"border-lime/30 bg-lime/[0.14] text-lime":"border-white/[0.12] bg-white/[0.03] text-secondary"),children:e.jsx(bt,{id:j.id})}),e.jsx("span",{className:"relative z-[1] min-w-0",children:e.jsx("span",{className:"block truncate text-body font-semibold",children:j.label})})]},j.id)})})}),e.jsxs("section",{className:"mt-4 min-h-0 lg:mt-0",children:[e.jsx("div",{className:"mb-4 flex items-center gap-2 overflow-x-auto border-b border-white/[0.07] pb-3 lg:hidden",role:"tablist","aria-label":"Settings tabs",children:le.map(j=>{const B=a===j.id;return e.jsx("button",{type:"button",role:"tab","aria-selected":B,onClick:()=>c(j.id),className:R("relative whitespace-nowrap rounded-full border px-3 py-1.5 text-caption font-semibold transition-colors",B?"border-lime/32 bg-lime/[0.12] text-lime":"border-white/[0.12] bg-white/[0.02] text-secondary"),children:j.label},j.id)})}),e.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden rounded-2xl border border-white/[0.08] bg-[#05070d]/75",children:[e.jsx("div",{className:"border-b border-white/[0.08] px-4 py-4 sm:px-6 sm:py-5",children:e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"max-w-2xl",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.16em] text-lime/72",children:"Control area"}),e.jsx("h4",{className:"mt-2 text-[24px] font-semibold leading-tight tracking-[-0.02em] text-white",children:A.label}),e.jsx("p",{className:"mt-2 text-body leading-relaxed text-secondary",children:A.subtitle})]}),e.jsxs("div",{className:"inline-flex items-center gap-2 rounded-full border border-lime/15 bg-lime/[0.08] px-3 py-1.5 text-caption font-medium text-lime",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-lime/80"}),"Live configuration surface"]})]})}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-4 py-5 sm:px-6 sm:py-6",children:e.jsx(Fe,{mode:"wait",children:S()})})]})]})]}),e.jsx("div",{className:"mt-3 border-t border-subtle px-1 pt-2",children:e.jsx(ze,{compact:!0})})]})]})})}export{_t as SettingsModal};
|
|
Binary file
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as x,j as e}from"./Dj2k1r16.js";import{c as
|
|
1
|
+
import{r as x,j as e}from"./Dj2k1r16.js";import{c as S}from"./DMKyYAtD.js";import{o as T,q as V,z as W,T as u,f as o,M as $,b as E}from"./C0i7ABUU.js";import{S as b}from"./BZCkOZ20.js";import"./eeHXe_OQ.js";import"./cX2e-TLi.js";import"./BjK42gtU.js";import"./BV0BcV1u.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 J(){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{J as ArtifactViewerModal};
|
|
Binary file
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as a,j as e}from"./Dj2k1r16.js";import{
|
|
1
|
+
import{r as a,j as e}from"./Dj2k1r16.js";import{f as l,z as p,E as h,a3 as u}from"./C0i7ABUU.js";import{DecisionQueue as b}from"./M4QxcXjh.js";import"./DMKyYAtD.js";import"./eeHXe_OQ.js";import"./cX2e-TLi.js";import"./BjK42gtU.js";import"./BV0BcV1u.js";import"./CqRNb2EL.js";import"./DClUc9rw.js";function D({open:n,onClose:o,decisions:t,onApproveDecision:i,onRejectDecision:m,onApproveAll:d,onBulkDecisionAction:x}){const r=a.useMemo(()=>t.length>0?Math.max(0,...t.map(c=>c.waitingMinutes)):0,[t]),s=a.useMemo(()=>t.length>=20||r>=15?l.red:t.length>0?l.amber:l.textMuted,[t.length,r]);return e.jsx(p,{open:n,onClose:o,maxWidth:"max-w-3xl",children:e.jsxs("div",{className:"flex h-full w-full flex-col",children:[e.jsx("div",{className:"border-b border-subtle px-5 pt-5 pb-4",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("h3",{className:"inline-flex items-center gap-2 text-heading font-semibold text-white",children:[e.jsx(h,{type:"decision",size:14}),e.jsx("span",{className:"truncate",children:"Decisions"}),e.jsx("span",{className:"rounded-full border px-2 py-0.5 text-caption font-semibold",style:{borderColor:`${s}30`,backgroundColor:`${s}14`,color:s},children:t.length})]}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:"Bulk review and resolve pending decisions."}),t.length>0&&e.jsxs("p",{className:"mt-2 text-caption text-secondary",children:["Oldest: ",e.jsxs("span",{className:"font-semibold text-white",children:[u(r)," ago"]})]})]}),e.jsx("button",{type:"button",onClick: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 decisions modal",children:"Close"})]})}),e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden p-4",children:e.jsx(b,{decisions:t,onApproveDecision:i,onRejectDecision:m,onApproveAll:d,onBulkDecisionAction:x})})]})})}export{D as BulkDecisionsModal};
|
|
Binary file
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as r}from"./Dj2k1r16.js";import{
|
|
1
|
+
import{j as r}from"./Dj2k1r16.js";import{C as s}from"./C0i7ABUU.js";function i({className:e=""}){return r.jsx("div",{className:s("shimmer-skeleton",e),"aria-hidden":"true"})}export{i as S};
|
|
Binary file
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as s,j as t}from"./Dj2k1r16.js";import{y as ke}from"./BV2Tf8S2.js";import"./DMKyYAtD.js";import"./eeHXe_OQ.js";import"./cX2e-TLi.js";import"./BjK42gtU.js";import"./BV0BcV1u.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 Me({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{Me as RealtimeOrchestratorModal};
|
|
1
|
+
import{r as s,j as t}from"./Dj2k1r16.js";import{z as ke}from"./C0i7ABUU.js";import"./DMKyYAtD.js";import"./eeHXe_OQ.js";import"./cX2e-TLi.js";import"./BjK42gtU.js";import"./BV0BcV1u.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 Me({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,B]=s.useState([]),[ee,te]=s.useState(!1),[re,oe]=s.useState(!1),[se,b]=s.useState(null),[ne,X]=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=>{X(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(""),X([]),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),B(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),X([]);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 z=typeof u.arguments=="string"?u.arguments:"{}";L({callId:c,name:w,arguments:z})}}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),z=l(c.name);if(w&&z){const Ne=typeof c.arguments=="string"?c.arguments:"{}";L({callId:w,name:z,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),B(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);B(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{Me as RealtimeOrchestratorModal};
|
|
Binary file
|
|
Binary file
|